2 * Copyright (c) 1999 M. Warner Losh <imp@village.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * Modifications for Megahertz X-Jack Ethernet Card (XJ-10BT)
28 * Copyright (c) 1996 by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
29 * BSD-nomads, Tokyo, Japan.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/socket.h>
40 #include <sys/systm.h>
42 #include <net/ethernet.h>
44 #include <net/if_arp.h>
46 #include <machine/bus.h>
47 #include <machine/resource.h>
50 #include <dev/pccard/pccardvar.h>
51 #include <dev/pccard/pccard_cis.h>
52 #include <dev/sn/if_snreg.h>
53 #include <dev/sn/if_snvar.h>
56 #include "pccarddevs.h"
58 typedef int sn_get_enaddr_t(device_t dev, u_char *eaddr);
59 typedef int sn_activate_t(device_t dev);
65 #define SN_MEGAHERTZ 2
68 #define SN_MOTO_MARINER 5
70 sn_get_enaddr_t *get_mac;
71 sn_activate_t *activate;
74 static sn_get_enaddr_t sn_pccard_normal_get_mac;
75 static sn_activate_t sn_pccard_normal_activate;
76 const static struct sn_sw sn_normal_sw = {
78 sn_pccard_normal_get_mac,
79 sn_pccard_normal_activate
82 static sn_get_enaddr_t sn_pccard_megahertz_get_mac;
83 static sn_activate_t sn_pccard_megahertz_activate;
84 const static struct sn_sw sn_mhz_sw = {
85 SN_MEGAHERTZ, "Megahertz",
86 sn_pccard_megahertz_get_mac,
87 sn_pccard_megahertz_activate
90 static const struct sn_product {
91 struct pccard_product prod;
92 const struct sn_sw *sw;
93 } sn_pccard_products[] = {
94 { PCMCIA_CARD(DSPSI, XJEM1144), &sn_mhz_sw },
95 { PCMCIA_CARD(DSPSI, XJACK), &sn_normal_sw },
96 /* { PCMCIA_CARD(MOTOROLA, MARINER), SN_MOTO_MARINER }, */
97 { PCMCIA_CARD(NEWMEDIA, BASICS), &sn_normal_sw },
98 { PCMCIA_CARD(MEGAHERTZ, VARIOUS), &sn_mhz_sw},
99 { PCMCIA_CARD(MEGAHERTZ, XJEM3336), &sn_mhz_sw},
100 /* { PCMCIA_CARD(OSITECH, TRUMP_SOD), SN_OSI_SOD }, */
101 /* { PCMCIA_CARD(OSITECH, TRUMP_JOH), SN_OSITECH }, */
102 /* { PCMCIA_CARD(PSION, GOLDCARD), SN_OSITECH }, */
103 /* { PCMCIA_CARD(PSION, NETGLOBAL), SNI_OSI_SOD }, */
104 /* { PCMCIA_CARD(PSION, NETGLOBAL2), SN_OSITECH }, */
105 { PCMCIA_CARD(SMC, 8020BT), &sn_normal_sw },
106 { PCMCIA_CARD(SMC, SMC91C96), &sn_normal_sw },
111 static const struct sn_product *
112 sn_pccard_lookup(device_t dev)
115 return ((const struct sn_product *)
116 pccard_product_lookup(dev,
117 (const struct pccard_product *)sn_pccard_products,
118 sizeof(sn_pccard_products[0]), NULL));
122 sn_pccard_probe(device_t dev)
124 const struct sn_product *pp;
126 if ((pp = sn_pccard_lookup(dev)) != NULL) {
127 if (pp->prod.pp_name != NULL)
128 device_set_desc(dev, pp->prod.pp_name);
135 sn_pccard_ascii_enaddr(const char *str, u_char *enet)
140 memset(enet, 0, ETHER_ADDR_LEN);
141 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
142 if (str[i] >= '0' && str[i] <= '9')
143 digit |= str[i] - '0';
144 else if (str[i] >= 'a' && str[i] <= 'f')
145 digit |= (str[i] - 'a') + 10;
146 else if (str[i] >= 'A' && str[i] <= 'F')
147 digit |= (str[i] - 'A') + 10;
149 return (0); /* Bogus digit!! */
151 /* Compensate for ordering of digits. */
153 enet[i >> 1] = digit;
163 sn_pccard_normal_get_mac(device_t dev, u_char *eaddr)
168 pccard_get_ether(dev, eaddr);
169 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
172 pccard_get_cis3_str(dev, &cisstr);
173 if (cisstr && strlen(cisstr) == ETHER_ADDR_LEN * 2)
174 sum = sn_pccard_ascii_enaddr(cisstr, eaddr);
177 pccard_get_cis4_str(dev, &cisstr);
178 if (cisstr && strlen(cisstr) == ETHER_ADDR_LEN * 2)
179 sum = sn_pccard_ascii_enaddr(cisstr, eaddr);
185 sn_pccard_normal_activate(device_t dev)
189 err = sn_activate(dev);
196 sn_pccard_megahertz_mac(const struct pccard_tuple *tuple, void *argp)
198 uint8_t *enaddr = argp;
200 uint8_t buffer[ETHER_ADDR_LEN * 2];
202 /* Code 0x81 is Megahertz' special cis node contianing the MAC */
203 if (tuple->code != 0x81)
206 /* Make sure this is a sane node, as ASCII digits */
207 if (tuple->length != ETHER_ADDR_LEN * 2 + 1)
210 /* Copy the MAC ADDR and return success if decoded */
211 for (i = 0; i < ETHER_ADDR_LEN * 2; i++)
212 buffer[i] = pccard_tuple_read_1(tuple, i);
213 return (sn_pccard_ascii_enaddr(buffer, enaddr));
217 sn_pccard_megahertz_get_mac(device_t dev, u_char *eaddr)
220 if (sn_pccard_normal_get_mac(dev, eaddr))
223 * If that fails, try the special CIS tuple 0x81 that the
224 * '3288 and '3336 cards have. That tuple specifies an ASCII
225 * string, ala CIS3 or CIS4 in the 'normal' cards.
227 return (pccard_cis_scan(dev, sn_pccard_megahertz_mac, eaddr));
231 sn_pccard_megahertz_activate(device_t dev)
234 struct sn_softc *sc = device_get_softc(dev);
237 err = sn_activate(dev);
243 * CIS resource is the modem one, so save it away.
245 sc->modem_rid = sc->port_rid;
246 sc->modem_res = sc->port_res;
249 * The MHz XJEM/CCEM series of cards just need to have any
250 * old resource allocated for the ethernet side of things,
251 * provided bit 0x80 isn't set in the address. That bit is
252 * evidentially reserved for modem function and is how the
253 * card steers the addresses internally.
260 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
261 &sc->port_rid, start, ~0, SMC_IO_EXTENT, RF_ACTIVE);
262 if (sc->port_res == NULL)
264 if (!(rman_get_start(sc->port_res) & 0x80))
266 start = rman_get_start(sc->port_res) + SMC_IO_EXTENT;
267 bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid,
269 } while (start < 0xff80);
270 if (sc->port_res == NULL) {
278 sn_pccard_attach(device_t dev)
280 struct sn_softc *sc = device_get_softc(dev);
281 u_char eaddr[ETHER_ADDR_LEN];
285 const struct sn_product *pp;
287 pp = sn_pccard_lookup(dev);
288 sum = pp->sw->get_mac(dev, eaddr);
290 /* Allocate resources so we can program the ether addr */
292 err = pp->sw->activate(dev);
297 printf("Programming sn card's addr\n");
298 SMC_SELECT_BANK(sc, 1);
299 for (i = 0; i < 3; i++) {
300 w = (uint16_t)eaddr[i * 2] |
301 (((uint16_t)eaddr[i * 2 + 1]) << 8);
302 CSR_WRITE_2(sc, IAR_ADDR0_REG_W + i * 2, w);
305 err = sn_attach(dev);
311 static device_method_t sn_pccard_methods[] = {
312 /* Device interface */
313 DEVMETHOD(device_probe, sn_pccard_probe),
314 DEVMETHOD(device_attach, sn_pccard_attach),
315 DEVMETHOD(device_detach, sn_detach),
320 static driver_t sn_pccard_driver = {
323 sizeof(struct sn_softc),
326 extern devclass_t sn_devclass;
328 DRIVER_MODULE(sn, pccard, sn_pccard_driver, sn_devclass, 0, 0);
329 MODULE_DEPEND(sn, ether, 1, 1, 1);