1 /*-
2 * Copyright (c) 1999 M. Warner Losh <imp@village.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
24 */
25 /*
26 * Modifications for Megahertz X-Jack Ethernet Card (XJ-10BT)
27 *
28 * Copyright (c) 1996 by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
29 * BSD-nomads, Tokyo, Japan.
30 */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD: src/sys/dev/sn/if_sn_pccard.c,v 1.25.2.1 2005/02/03 00:36:06 imp Exp $");
34
35 #include <sys/param.h>
36 #include <sys/bus.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/socket.h>
40 #include <sys/systm.h>
41
42 #include <net/ethernet.h>
43 #include <net/if.h>
44 #include <net/if_arp.h>
45
46 #include <machine/bus.h>
47
48 #include <dev/pccard/pccardvar.h>
49 #include <dev/pccard/pccard_cis.h>
50 #include <dev/sn/if_snvar.h>
51
52 #include "card_if.h"
53 #include "pccarddevs.h"
54
55 static const struct pccard_product sn_pccard_products[] = {
56 PCMCIA_CARD(DSPSI, XJACK, 0),
57 PCMCIA_CARD(NEWMEDIA, BASICS, 0),
58 #if 0
59 PCMCIA_CARD(SMC, 8020BT, 0),
60 #endif
61 { NULL }
62 };
63
64 static int
65 sn_pccard_match(device_t dev)
66 {
67 const struct pccard_product *pp;
68 int error;
69 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
70
71 /* Make sure we're a network function */
72 error = pccard_get_function(dev, &fcn);
73 if (error != 0)
74 return (error);
75 if (fcn != PCCARD_FUNCTION_NETWORK)
76 return (ENXIO);
77
78 if ((pp = pccard_product_lookup(dev, sn_pccard_products,
79 sizeof(sn_pccard_products[0]), NULL)) != NULL) {
80 if (pp->pp_name != NULL)
81 device_set_desc(dev, pp->pp_name);
82 return 0;
83 }
84 return EIO;
85 }
86
87 static int
88 sn_pccard_probe(device_t dev)
89 {
90 int err;
91
92 err = sn_probe(dev, 1);
93 return (err);
94 }
95
96 static int
97 sn_pccard_ascii_enaddr(const char *str, u_char *enet)
98 {
99 uint8_t digit;
100 int i;
101
102 memset(enet, 0, ETHER_ADDR_LEN);
103
104 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
105 if (str[i] >= '' && str[i] <= '9')
106 digit |= str[i] - '';
107 else if (str[i] >= 'a' && str[i] <= 'f')
108 digit |= (str[i] - 'a') + 10;
109 else if (str[i] >= 'A' && str[i] <= 'F')
110 digit |= (str[i] - 'A') + 10;
111 else {
112 /* Bogus digit!! */
113 return (0);
114 }
115
116 /* Compensate for ordering of digits. */
117 if (i & 1) {
118 enet[i >> 1] = digit;
119 digit = 0;
120 } else
121 digit <<= 4;
122 }
123
124 return (1);
125 }
126
127 static int
128 sn_pccard_attach(device_t dev)
129 {
130 struct sn_softc *sc = device_get_softc(dev);
131 int i;
132 u_char sum;
133 u_char ether_addr[ETHER_ADDR_LEN];
134 const char *cisstr;
135
136 sc->pccard_enaddr = 0;
137 pccard_get_ether(dev, ether_addr);
138 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
139 sum |= ether_addr[i];
140 if (sum == 0) {
141 pccard_get_cis3_str(dev, &cisstr);
142 if (strlen(cisstr) == ETHER_ADDR_LEN * 2)
143 sum = sn_pccard_ascii_enaddr(cisstr, ether_addr);
144 }
145 if (sum == 0) {
146 pccard_get_cis4_str(dev, &cisstr);
147 if (strlen(cisstr) == ETHER_ADDR_LEN * 2)
148 sum = sn_pccard_ascii_enaddr(cisstr, ether_addr);
149 }
150 if (sum) {
151 sc->pccard_enaddr = 1;
152 bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
153 }
154 return (sn_attach(dev));
155 }
156
157 static device_method_t sn_pccard_methods[] = {
158 /* Device interface */
159 DEVMETHOD(device_probe, pccard_compat_probe),
160 DEVMETHOD(device_attach, pccard_compat_attach),
161 DEVMETHOD(device_detach, sn_detach),
162
163 /* Card interface */
164 DEVMETHOD(card_compat_match, sn_pccard_match),
165 DEVMETHOD(card_compat_probe, sn_pccard_probe),
166 DEVMETHOD(card_compat_attach, sn_pccard_attach),
167
168 { 0, 0 }
169 };
170
171 static driver_t sn_pccard_driver = {
172 "sn",
173 sn_pccard_methods,
174 sizeof(struct sn_softc),
175 };
176
177 extern devclass_t sn_devclass;
178
179 DRIVER_MODULE(sn, pccard, sn_pccard_driver, sn_devclass, 0, 0);
180 MODULE_DEPEND(sn, ether, 1, 1, 1);
Cache object: 4d82de09fc5227bdbdc058b7ffd672d2
|