if_sm_nubus.c revision 1.5 1 /* $NetBSD: if_sm_nubus.c,v 1.5 2003/07/15 02:43:24 lukem Exp $ */
2
3 /*
4 * Copyright (c) 2000 Allen Briggs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: if_sm_nubus.c,v 1.5 2003/07/15 02:43:24 lukem Exp $");
32
33 #include "opt_inet.h"
34
35 #include <sys/param.h>
36 #include <sys/device.h>
37 #include <sys/errno.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <sys/syslog.h>
41 #include <sys/systm.h>
42
43 #include <net/if.h>
44 #include <net/if_ether.h>
45 #include <net/if_media.h>
46
47 #include <machine/bus.h>
48 #include <machine/viareg.h>
49
50 #include <dev/mii/mii.h>
51 #include <dev/mii/miivar.h>
52
53 #include <dev/ic/smc91cxxreg.h>
54 #include <dev/ic/smc91cxxvar.h>
55
56 #include <mac68k/nubus/nubus.h>
57
58 static int sm_nubus_match __P((struct device *, struct cfdata *, void *));
59 static void sm_nubus_attach __P((struct device *, struct device *, void *));
60
61 CFATTACH_DECL(sm_nubus, sizeof(struct smc91cxx_softc),
62 sm_nubus_match, sm_nubus_attach, NULL, NULL);
63
64 static int
65 sm_nubus_match(parent, cf, aux)
66 struct device *parent;
67 struct cfdata *cf;
68 void *aux;
69 {
70 struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
71 bus_space_handle_t bsh;
72 int rv;
73
74 if (bus_space_map(na->na_tag,
75 NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
76 return (0);
77
78 rv = 0;
79
80 if (na->category == NUBUS_CATEGORY_NETWORK &&
81 na->type == NUBUS_TYPE_ETHERNET) {
82 switch (na->drsw) {
83 case NUBUS_DRSW_FOCUS:
84 case NUBUS_DRSW_ASANTEF:
85 rv = 1;
86 break;
87 default:
88 rv = 0;
89 break;
90 }
91 }
92
93 bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
94
95 return rv;
96 }
97
98 /*
99 * Install interface into kernel networking data structures
100 */
101 static void
102 sm_nubus_attach(parent, self, aux)
103 struct device *parent, *self;
104 void *aux;
105 {
106 struct smc91cxx_softc *smc = (struct smc91cxx_softc *) self;
107 struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
108 bus_space_tag_t bst = na->na_tag;
109 bus_space_handle_t bsh, prom_bsh;
110 u_int8_t myaddr[ETHER_ADDR_LEN];
111 int i, success;
112 char *cardtype;
113
114 bst = na->na_tag;
115 if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
116 printf(": failed to map memory space.\n");
117 return;
118 }
119
120 mac68k_bus_space_handle_swapped(bst, &bsh);
121
122 smc->sc_bst = bst;
123 smc->sc_bsh = bsh;
124
125 cardtype = nubus_get_card_name(bst, bsh, na->fmt);
126
127 success = 0;
128
129 switch (na->drsw) {
130 case NUBUS_DRSW_FOCUS:
131 if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) {
132 printf(": failed to map EEPROM space.\n");
133 break;
134 }
135
136 success = 1;
137 break;
138 case NUBUS_DRSW_ASANTEF:
139 if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) {
140 printf(": failed to map EEPROM space.\n");
141 break;
142 }
143
144 success = 1;
145 break;
146 }
147
148 if (!success) {
149 bus_space_unmap(bst, bsh, NBMEMSIZE);
150 return;
151 }
152 for (i=0 ; i<6 ; i++) {
153 myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4);
154 }
155
156 smc->sc_flags |= SMC_FLAGS_ENABLED;
157
158 printf(": %s\n", cardtype);
159
160 smc91cxx_attach(smc, myaddr);
161
162 add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc);
163 }
164