Deleted Added
full compact
if_ep_pccard.c (147607) if_ep_pccard.c (147649)
1/*-
2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
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

--- 21 unchanged lines hidden (view full) ---

30
31/*
32 * Pccard support for 3C589 by:
33 * HAMADA Naoki
34 * nao@tom-yam.or.jp
35 */
36
37#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
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

--- 21 unchanged lines hidden (view full) ---

30
31/*
32 * Pccard support for 3C589 by:
33 * HAMADA Naoki
34 * nao@tom-yam.or.jp
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 147607 2005-06-26 04:19:45Z imp $");
38__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 147649 2005-06-28 21:56:04Z imp $");
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/socket.h>
44#include <sys/module.h>
45#include <sys/bus.h>
46

--- 6 unchanged lines hidden (view full) ---

53#include <net/if_media.h>
54
55#include <dev/ep/if_epreg.h>
56#include <dev/ep/if_epvar.h>
57
58#include <dev/pccard/pccardvar.h>
59#include <dev/pccard/pccard_cis.h>
60
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/socket.h>
44#include <sys/module.h>
45#include <sys/bus.h>
46

--- 6 unchanged lines hidden (view full) ---

53#include <net/if_media.h>
54
55#include <dev/ep/if_epreg.h>
56#include <dev/ep/if_epvar.h>
57
58#include <dev/pccard/pccardvar.h>
59#include <dev/pccard/pccard_cis.h>
60
61#include "card_if.h"
62#include "pccarddevs.h"
63
61#include "pccarddevs.h"
62
64static const char *ep_pccard_identify(u_short id);
65
66/*
67 * Initialize the device - called from Slot manager.
68 */
69static int
70ep_pccard_probe(device_t dev)
63struct ep_pccard_product
71{
64{
72 struct ep_softc *sc = device_get_softc(dev);
73 struct ep_board *epb = &sc->epb;
74 const char *desc;
75 uint16_t result;
76 uint8_t enaddr[6];
77 int error;
65 struct pccard_product prod;
66 int chipset;
67};
78
68
79 error = ep_alloc(dev);
80 if (error)
81 return (error);
69#define EP_CHIP_589 1 /* Classic 3c5x9 chipset */
70#define EP_CHIP_574 2 /* Roadrunner */
82
71
83 /*
84 * It appears that the eeprom comes in two sizes. There's
85 * a 512 byte eeprom and a 2k eeprom. Bit 13 of the eeprom
86 * command register is supposed to contain the size of the
87 * eeprom.
88 */
89 /*
90 * XXX - Certain (newer?) 3Com cards need epb->cmd_off ==
91 * 2. Sadly, you need to have a correct cmd_off in order to
92 * identify the card. So we have to hit it with both and
93 * cross our virtual fingers. There's got to be a better way
94 * to do this. jyoung@accessus.net 09/11/1999
95 */
72static const struct ep_pccard_product ep_pccard_products[] = {
73 { PCMCIA_CARD(3COM, 3C1), EP_CHIP_589 },
74 { PCMCIA_CARD(3COM, 3C562), EP_CHIP_589 },
75 { PCMCIA_CARD(3COM, 3C589), EP_CHIP_589 },
76 { PCMCIA_CARD(3COM, 3CXEM556), EP_CHIP_589 },
77 { PCMCIA_CARD(3COM, 3CXEM556INT), EP_CHIP_589 },
78 { PCMCIA_CARD(3COM, 3C574), EP_CHIP_574 },
79 { PCMCIA_CARD(3COM, 3CCFEM556BI), EP_CHIP_574 },
80 { { NULL } }
81};
96
82
97 epb->cmd_off = 0;
98
99 /* XXX check return */
100 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
101 epb->prod_id = result;
102
103 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
104 if (bootverbose)
105 device_printf(dev, "Pass 1 of 2 detection "
106 "failed (nonfatal) id 0x%x\n", epb->prod_id);
107 epb->cmd_off = 2;
108 /* XXX check return */
109 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
110 epb->prod_id = result;
111 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
112 device_printf(dev, "Unit failed to come ready or "
113 "product ID unknown! (id 0x%x)\n", epb->prod_id);
114 ep_free(dev);
115 return (ENXIO);
116 }
117 }
118 /*
119 * For reasons unknown, getting the MAC address here makes the
120 * 3C574 and 3C556 families get the right MAC address later.
121 * otherwise, the ID field is used for each of the words of the
122 * MAC address instead of the proper one. It is unclear why
123 * ep_get_macaddr would have this side effect, or even what
124 * that side effect really is.
125 */
126 ep_get_macaddr(sc, enaddr);
127 device_set_desc(dev, desc);
128 ep_free(dev);
129 return (0);
130}
131
132static const char *
133ep_pccard_identify(u_short id)
83static const struct ep_pccard_product *
84ep_pccard_lookup(device_t dev)
134{
85{
135 /* Determine device type and associated MII capabilities */
136 switch (id) {
137 case 0x6055: /* 3C556 */
138 return ("3Com 3C556");
139 case 0x4057: /* 3C574 */
140 return ("3Com 3C574");
141 case 0x4b57: /* 3C574B */
142 return ("3Com 3C574B, Megahertz 3CCFE574BT or "
143 "Fast Etherlink 3C574-TX");
144 case 0x2b57: /* 3CXSH572BT */
145 return ("3Com OfficeConnect 572BT");
146 case 0x9058: /* 3C589 */
147 return ("3Com Etherlink III 3C589");
148 case 0x2056: /* 3C562/3C563 */
149 return ("3Com 3C562D/3C563D");
150 case 0x0010: /* 3C1 */
151 return ("3Com Megahertz C1");
152 case 0x0035:
153 return ("3Com 3CCEM556");
154 default:
155 return (NULL);
156 }
86 return ((const struct ep_pccard_product *)pccard_product_lookup(dev,
87 (const struct pccard_product *)ep_pccard_products,
88 sizeof(ep_pccard_products[0]), NULL));
157}
158
159static int
89}
90
91static int
160ep_pccard_card_attach(struct ep_board * epb)
92ep_pccard_probe(device_t dev)
161{
93{
162 /* Determine device type and associated MII capabilities */
163 switch (epb->prod_id) {
164 case 0x6055: /* 3C556 */
165 case 0x2b57: /* 3C572BT */
166 case 0x4057: /* 3C574, 3C574-TX */
167 case 0x4b57: /* 3C574B */
168 epb->mii_trans = 1;
169 return (1);
170 case 0x2056: /* 3C562D/3C563D */
171 case 0x9058: /* 3C589 */
172 case 0x0010: /* 3C1 */
173 case 0x0035: /* 3C[XC]EM556 */
174 epb->mii_trans = 0;
175 return (1);
176 default:
177 return (0);
178 }
94 const struct ep_pccard_product *pp;
95 int error;
96 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
97
98 /* Make sure we're a network function */
99 error = pccard_get_function(dev, &fcn);
100 if (error != 0)
101 return (error);
102 if (fcn != PCCARD_FUNCTION_NETWORK)
103 return (ENXIO);
104
105 /* Check to see if we know about this card */
106 if ((pp = ep_pccard_lookup(dev)) == NULL)
107 return EIO;
108 if (pp->prod.pp_name != NULL)
109 device_set_desc(dev, pp->prod.pp_name);
110
111 return 0;
179}
180
181static int
182ep_pccard_attach(device_t dev)
183{
184 struct ep_softc *sc = device_get_softc(dev);
185 uint16_t result;
186 int error = 0;
112}
113
114static int
115ep_pccard_attach(device_t dev)
116{
117 struct ep_softc *sc = device_get_softc(dev);
118 uint16_t result;
119 int error = 0;
120 const struct ep_pccard_product *pp;
187
121
122 if ((pp = ep_pccard_lookup(dev)) == NULL)
123 panic("ep_pccard_attach: can't find product in attach.");
124
188 if ((error = ep_alloc(dev))) {
189 device_printf(dev, "ep_alloc() failed! (%d)\n", error);
190 goto bad;
191 }
125 if ((error = ep_alloc(dev))) {
126 device_printf(dev, "ep_alloc() failed! (%d)\n", error);
127 goto bad;
128 }
192 sc->epb.cmd_off = 0;
193
129
194 /* XXX check return */
195 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
196 sc->epb.prod_id = result;
197
198 if (!ep_pccard_card_attach(&sc->epb)) {
130 if (pp->chipset == EP_CHIP_589) {
131 sc->epb.mii_trans = 0;
132 sc->epb.cmd_off = 0;
133 } else {
134 sc->epb.mii_trans = 1;
199 sc->epb.cmd_off = 2;
135 sc->epb.cmd_off = 2;
200 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
201 sc->epb.prod_id = result;
202 error = ep_get_e(sc, EEPROM_RESOURCE_CFG, &result);
203 sc->epb.res_cfg = result;
204 if (!ep_pccard_card_attach(&sc->epb)) {
205 device_printf(dev,
206 "Probe found ID, attach failed so ignore card!\n");
207 error = ENXIO;
208 goto bad;
209 }
210 }
136 }
211 error = ep_get_e(sc, EEPROM_ADDR_CFG, &result);
212
137
138 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
139 sc->epb.prod_id = result;
140
213 /* ROM size = 0, ROM base = 0 */
214 /* For now, ignore AUTO SELECT feature of 3C589B and later. */
141 /* ROM size = 0, ROM base = 0 */
142 /* For now, ignore AUTO SELECT feature of 3C589B and later. */
143 error = ep_get_e(sc, EEPROM_ADDR_CFG, &result);
215 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000);
216
217 /*
218 * Fake IRQ must be 3 for 3C589 and 3C589B. 3C589D and newer
219 * ignore this value. 3C589C is unknown, as are the other
220 * cards supported by this driver, but it appears to never hurt
221 * and always helps.
222 */

--- 15 unchanged lines hidden (view full) ---

238 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
239 } else
240 ep_get_media(sc);
241
242 if ((error = ep_attach(sc))) {
243 device_printf(dev, "ep_attach() failed! (%d)\n", error);
244 goto bad;
245 }
144 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000);
145
146 /*
147 * Fake IRQ must be 3 for 3C589 and 3C589B. 3C589D and newer
148 * ignore this value. 3C589C is unknown, as are the other
149 * cards supported by this driver, but it appears to never hurt
150 * and always helps.
151 */

--- 15 unchanged lines hidden (view full) ---

167 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
168 } else
169 ep_get_media(sc);
170
171 if ((error = ep_attach(sc))) {
172 device_printf(dev, "ep_attach() failed! (%d)\n", error);
173 goto bad;
174 }
246 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, ep_intr,
247 sc, &sc->ep_intrhand))) {
175 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
176 ep_intr, sc, &sc->ep_intrhand))) {
248 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
249 goto bad;
250 }
251 return (0);
252bad:
253 ep_free(dev);
254 return (error);
255}
256
177 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
178 goto bad;
179 }
180 return (0);
181bad:
182 ep_free(dev);
183 return (error);
184}
185
257static const struct pccard_product ep_pccard_products[] = {
258 PCMCIA_CARD(3COM, 3C1),
259 PCMCIA_CARD(3COM, 3C562),
260 PCMCIA_CARD(3COM, 3C574), /* ROADRUNNER */
261 PCMCIA_CARD(3COM, 3C589),
262 PCMCIA_CARD(3COM, 3CCFEM556BI), /* ROADRUNNER */
263 PCMCIA_CARD(3COM, 3CXEM556),
264 PCMCIA_CARD(3COM, 3CXEM556INT),
265 {NULL}
266};
267
268static int
269ep_pccard_match(device_t dev)
270{
271 const struct pccard_product *pp;
272 int error;
273 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
274
275 /* Make sure we're a network function */
276 error = pccard_get_function(dev, &fcn);
277 if (error != 0)
278 return (error);
279 if (fcn != PCCARD_FUNCTION_NETWORK)
280 return (ENXIO);
281
282 if ((pp = pccard_product_lookup(dev, ep_pccard_products,
283 sizeof(ep_pccard_products[0]), NULL)) != NULL) {
284 if (pp->pp_name != NULL)
285 device_set_desc(dev, pp->pp_name);
286 return 0;
287 }
288 return EIO;
289}
290
291static device_method_t ep_pccard_methods[] = {
292 /* Device interface */
186static device_method_t ep_pccard_methods[] = {
187 /* Device interface */
293 DEVMETHOD(device_probe, pccard_compat_probe),
294 DEVMETHOD(device_attach, pccard_compat_attach),
188 DEVMETHOD(device_probe, ep_pccard_probe),
189 DEVMETHOD(device_attach, ep_pccard_attach),
295 DEVMETHOD(device_detach, ep_detach),
296
190 DEVMETHOD(device_detach, ep_detach),
191
297 /* Card interface */
298 DEVMETHOD(card_compat_match, ep_pccard_match),
299 DEVMETHOD(card_compat_probe, ep_pccard_probe),
300 DEVMETHOD(card_compat_attach, ep_pccard_attach),
301
302 {0, 0}
303};
304
305static driver_t ep_pccard_driver = {
306 "ep",
307 ep_pccard_methods,
308 sizeof(struct ep_softc),
309};
310
311extern devclass_t ep_devclass;
312
313DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0);
192 {0, 0}
193};
194
195static driver_t ep_pccard_driver = {
196 "ep",
197 ep_pccard_methods,
198 sizeof(struct ep_softc),
199};
200
201extern devclass_t ep_devclass;
202
203DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0);