Deleted Added
sdiff udiff text old ( 148022 ) new ( 149558 )
full compact
1/*-
2 * Copyright (c) 1995, David Greenman
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 unmodified, this list of conditions, and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/dev/ed/if_ed_pccard.c 148022 2005-07-15 01:54:59Z imp $
28 */
29
30#include "opt_ed.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/socket.h>
35#include <sys/kernel.h>
36#include <sys/conf.h>
37#include <sys/uio.h>
38
39#include <sys/module.h>
40#include <sys/bus.h>
41#include <machine/bus.h>
42#include <sys/rman.h>
43#include <machine/resource.h>
44
45#include <net/ethernet.h>
46#include <net/if.h>
47#include <net/if_arp.h>
48#include <net/if_mib.h>
49#include <net/if_media.h>
50
51#include <dev/ed/if_edreg.h>
52#include <dev/ed/if_edvar.h>
53#include <dev/pccard/pccardvar.h>
54#include <dev/pccard/pccard_cis.h>
55#ifndef ED_NO_MIIBUS
56#include <dev/mii/mii.h>
57#include <dev/mii/miivar.h>
58#endif
59
60#include "card_if.h"
61#ifndef ED_NO_MIIBUS
62/* "device miibus" required. See GENERIC if you get errors here. */
63#include "miibus_if.h"
64#endif
65#include "pccarddevs.h"
66
67#ifndef ED_NO_MIIBUS
68MODULE_DEPEND(ed, miibus, 1, 1, 1);
69#endif
70MODULE_DEPEND(ed, ether, 1, 1, 1);
71
72/*
73 * PC Cards should be using a network specific FUNCE in the CIS to
74 * communicate their MAC address to the driver. However, there are a
75 * large number of NE-2000ish PC Cards that don't do this. Nearly all
76 * of them store the MAC address at a fixed offset into attribute
77 * memory, without any reference at all appearing in the CIS. And
78 * nearly all of those store it at the same location.
79 */
80#define ED_DEFAULT_MAC_OFFSET 0xff0
81
82/*
83 * PC-Card (PCMCIA) specific code.
84 */
85static int ed_pccard_match(device_t);
86static int ed_pccard_probe(device_t);
87static int ed_pccard_attach(device_t);
88
89static int ed_pccard_ax88x90(device_t dev);
90
91static void ax88x90_geteprom(struct ed_softc *);
92static int ed_pccard_memread(device_t dev, off_t offset, u_char *byte);
93static int ed_pccard_memwrite(device_t dev, off_t offset, u_char byte);
94#ifndef ED_NO_MIIBUS
95static void ed_pccard_dlink_mii_reset(struct ed_softc *sc);
96static u_int ed_pccard_dlink_mii_readbits(struct ed_softc *sc, int nbits);
97static void ed_pccard_dlink_mii_writebits(struct ed_softc *sc, u_int val,
98 int nbits);
99#endif
100static int ed_pccard_Linksys(device_t dev);
101
102static const struct ed_product {
103 struct pccard_product prod;
104 int flags;
105#define NE2000DVF_DL100XX 0x0001 /* chip is D-Link DL10019/22 */
106#define NE2000DVF_AX88X90 0x0002 /* chip is ASIX AX88[17]90 */
107#define NE2000DVF_ENADDR 0x0004 /* Get MAC from attr mem */
108#define NE2000DVF_ANYFUNC 0x0008 /* Allow any function type */
109#define NE2000DVF_MODEM 0x0010 /* Has a modem/serial */
110 int enoff;
111 int edrid;
112 int siorid;
113} ed_pccard_products[] = {
114 { PCMCIA_CARD(ACCTON, EN2212), 0},
115 { PCMCIA_CARD(ACCTON, EN2216), 0},
116 { PCMCIA_CARD(ALLIEDTELESIS, LA_PCM), 0},
117 { PCMCIA_CARD(AMBICOM, AMB8002T), 0},
118 { PCMCIA_CARD(BILLIONTON, LNT10TN), 0},
119 { PCMCIA_CARD(BILLIONTON, CFLT10N), 0},
120 { PCMCIA_CARD(BROMAX, IPORT), 0},
121 { PCMCIA_CARD(BROMAX, IPORT2), 0},
122 { PCMCIA_CARD(BUFFALO, LPC2_CLT), 0},
123 { PCMCIA_CARD(BUFFALO, LPC3_CLT), 0},
124 { PCMCIA_CARD(BUFFALO, LPC3_CLX), NE2000DVF_AX88X90},
125 { PCMCIA_CARD(BUFFALO, LPC4_TX), NE2000DVF_AX88X90},
126 { PCMCIA_CARD(BUFFALO, LPC_CF_CLT), 0},
127 { PCMCIA_CARD(CNET, NE2000), 0},
128 { PCMCIA_CARD(COMPEX, AX88190), NE2000DVF_AX88X90},
129 { PCMCIA_CARD(COMPEX, LANMODEM), 0},
130 { PCMCIA_CARD(COMPEX, LINKPORT_ENET_B), 0},
131 { PCMCIA_CARD(COREGA, ETHER_II_PCC_T), 0},
132 { PCMCIA_CARD(COREGA, ETHER_II_PCC_TD), 0},
133 { PCMCIA_CARD(COREGA, ETHER_PCC_T), 0},
134 { PCMCIA_CARD(COREGA, ETHER_PCC_TD), 0},
135 { PCMCIA_CARD(COREGA, FAST_ETHER_PCC_TX), NE2000DVF_DL100XX },
136 { PCMCIA_CARD(COREGA, FETHER_PCC_TXD), NE2000DVF_AX88X90 },
137 { PCMCIA_CARD(COREGA, FETHER_PCC_TXF), NE2000DVF_DL100XX },
138 { PCMCIA_CARD(DAYNA, COMMUNICARD_E_1), 0},
139 { PCMCIA_CARD(DAYNA, COMMUNICARD_E_2), 0},
140 { PCMCIA_CARD(DLINK, DE650), 0},
141 { PCMCIA_CARD(DLINK, DE660), 0 },
142 { PCMCIA_CARD(DLINK, DE660PLUS), 0},
143 { PCMCIA_CARD(DLINK, DFE670TXD), NE2000DVF_DL100XX },
144 { PCMCIA_CARD(DYNALINK, L10C), 0},
145 { PCMCIA_CARD(EDIMAX, EP4000A), 0},
146 { PCMCIA_CARD(EPSON, EEN10B), 0},
147 { PCMCIA_CARD(EXP, THINLANCOMBO), 0},
148 { PCMCIA_CARD(GREY_CELL, TDK3000), 0},
149 { PCMCIA_CARD(GREY_CELL, DMF650TX),
150 NE2000DVF_ANYFUNC | NE2000DVF_DL100XX | NE2000DVF_MODEM, -1, 1, 0},
151 { PCMCIA_CARD(IBM, HOME_AND_AWAY), 0},
152 { PCMCIA_CARD(IBM, INFOMOVER), NE2000DVF_ENADDR, 0xff0},
153 { PCMCIA_CARD(IODATA3, PCLAT), 0},
154 { PCMCIA_CARD(KINGSTON, CIO10T), 0},
155 { PCMCIA_CARD(KINGSTON, KNE2), 0},
156 { PCMCIA_CARD(LANTECH, FASTNETTX),NE2000DVF_AX88X90 },
157 { PCMCIA_CARD(LINKSYS, COMBO_ECARD),
158 NE2000DVF_DL100XX | NE2000DVF_AX88X90 },
159 { PCMCIA_CARD(LINKSYS, ECARD_1), 0},
160 { PCMCIA_CARD(LINKSYS, ECARD_2), 0},
161 { PCMCIA_CARD(LINKSYS, ETHERFAST), NE2000DVF_DL100XX },
162 { PCMCIA_CARD(LINKSYS, TRUST_COMBO_ECARD), 0},
163 { PCMCIA_CARD(MACNICA, ME1_JEIDA), 0},
164 { PCMCIA_CARD(MAGICRAM, ETHER), 0},
165 { PCMCIA_CARD(MELCO, LPC3_CLX), NE2000DVF_AX88X90 },
166 { PCMCIA_CARD(MELCO, LPC3_TX), NE2000DVF_AX88X90 },
167 { PCMCIA_CARD(NDC, ND5100_E), 0},
168 { PCMCIA_CARD(NETGEAR, FA410TXC), NE2000DVF_DL100XX},
169 { PCMCIA_CARD(NETGEAR, FA411), NE2000DVF_AX88X90},
170 { PCMCIA_CARD(NEXTCOM, NEXTHAWK), 0},
171 { PCMCIA_CARD(NEWMEDIA, LANSURFER), 0},
172 { PCMCIA_CARD(OEM2, ETHERNET), 0},
173 { PCMCIA_CARD(PLANET, SMARTCOM2000), 0 },
174 { PCMCIA_CARD(PREMAX, PE200), 0},
175 { PCMCIA_CARD(PSION, LANGLOBAL), 0},
176 { PCMCIA_CARD(RACORE, ETHERNET), 0},
177 { PCMCIA_CARD(RACORE, FASTENET), NE2000DVF_AX88X90},
178 { PCMCIA_CARD(RACORE, 8041TX), NE2000DVF_AX88X90},
179 { PCMCIA_CARD(RELIA, COMBO), 0},
180 { PCMCIA_CARD(RPTI, EP400), 0},
181 { PCMCIA_CARD(RPTI, EP401), 0},
182 { PCMCIA_CARD(SMC, EZCARD), 0},
183 { PCMCIA_CARD(SOCKET, EA_ETHER), 0},
184 { PCMCIA_CARD(SOCKET, ES_1000), 0},
185 { PCMCIA_CARD(SOCKET, LP_ETHER), 0},
186 { PCMCIA_CARD(SOCKET, LP_ETHER_CF), 0},
187 { PCMCIA_CARD(SOCKET, LP_ETH_10_100_CF), NE2000DVF_DL100XX},
188 { PCMCIA_CARD(SVEC, COMBOCARD), 0},
189 { PCMCIA_CARD(SVEC, LANCARD), 0},
190 { PCMCIA_CARD(TAMARACK, ETHERNET), 0},
191 { PCMCIA_CARD(TDK, LAK_CD031), 0},
192 { PCMCIA_CARD(TDK, DFL5610WS), 0},
193 { PCMCIA_CARD(TELECOMDEVICE, LM5LT), 0 },
194 { PCMCIA_CARD(TELECOMDEVICE, TCD_HPC100), NE2000DVF_AX88X90 },
195 { PCMCIA_CARD(XIRCOM, CFE_10), 0},
196 { PCMCIA_CARD(ZONET, ZEN), 0},
197 { { NULL } }
198};
199
200static int
201ed_pccard_match(device_t dev)
202{
203 const struct ed_product *pp;
204 int error;
205 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
206
207 /* Make sure we're a network function */
208 error = pccard_get_function(dev, &fcn);
209 if (error != 0)
210 return (error);
211
212 if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
213 (const struct pccard_product *) ed_pccard_products,
214 sizeof(ed_pccard_products[0]), NULL)) != NULL) {
215 if (pp->prod.pp_name != NULL)
216 device_set_desc(dev, pp->prod.pp_name);
217 /*
218 * Some devices don't ID themselves as network, but
219 * that's OK if the flags say so.
220 */
221 if (!(pp->flags & NE2000DVF_ANYFUNC) &&
222 fcn != PCCARD_FUNCTION_NETWORK)
223 return (ENXIO);
224 return (0);
225 }
226 return (ENXIO);
227}
228
229/*
230 * Probe framework for pccards. Replicates the standard framework,
231 * minus the pccard driver registration and ignores the ether address
232 * supplied (from the CIS), relying on the probe to find it instead.
233 */
234static int
235ed_pccard_probe(device_t dev)
236{
237 const struct ed_product *pp;
238 int error;
239 struct ed_softc *sc = device_get_softc(dev);
240
241 if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
242 (const struct pccard_product *) ed_pccard_products,
243 sizeof(ed_pccard_products[0]), NULL)) == NULL)
244 return (ENXIO);
245 sc->port_rid = pp->edrid;
246 if (pp->flags & NE2000DVF_DL100XX) {
247 error = ed_probe_Novell(dev, sc->port_rid, 0);
248 if (error == 0)
249 error = ed_pccard_Linksys(dev);
250 ed_release_resources(dev);
251 if (error == 0)
252 goto end2;
253 }
254 if (pp->flags & NE2000DVF_AX88X90) {
255 error = ed_pccard_ax88x90(dev);
256 if (error == 0)
257 goto end2;
258 }
259 error = ed_probe_Novell(dev, sc->port_rid, 0);
260end2:
261 if (error == 0)
262 error = ed_alloc_irq(dev, 0, 0);
263
264 ed_release_resources(dev);
265 return (error);
266}
267
268static int
269ed_pccard_rom_mac(device_t dev, uint8_t *enaddr)
270{
271 struct ed_softc *sc = device_get_softc(dev);
272 uint8_t romdata[16];
273 int i;
274
275 /*
276 * Read in the rom data at location 0. We should see one of
277 * two patterns. Either you'll see odd locations 0xff and
278 * even locations data, or you'll see odd and even locations
279 * mirror each other. In addition, the last two even locations
280 * should be 0. If they aren't 0, then we'll assume that
281 * there's no valid ROM data on this card and try another method
282 * to recover the MAC address. Since there are no NE-1000
283 * based PC Card devices, we'll assume we're 16-bit.
284 */
285 ed_pio_readmem(sc, 0, romdata, 16);
286 if (romdata[12] != 0 || romdata[14] != 0)
287 return 0;
288 for (i = 0; i < ETHER_ADDR_LEN; i++)
289 enaddr[i] = romdata[i * 2];
290 return 1;
291}
292
293static int
294ed_pccard_add_modem(device_t dev, int rid)
295{
296 device_printf(dev, "Need to write this code: modem rid is %d\n", rid);
297 return 0;
298}
299
300static int
301ed_pccard_attach(device_t dev)
302{
303 int error, i;
304 struct ed_softc *sc = device_get_softc(dev);
305 u_char sum;
306 u_char enaddr[ETHER_ADDR_LEN];
307 const struct ed_product *pp;
308
309 if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
310 (const struct pccard_product *) ed_pccard_products,
311 sizeof(ed_pccard_products[0]), NULL)) == NULL)
312 return (ENXIO);
313 sc->port_rid = pp->edrid;
314 if (sc->port_used > 0)
315 ed_alloc_port(dev, sc->port_rid, sc->port_used);
316 if (sc->mem_used)
317 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used);
318 ed_alloc_irq(dev, sc->irq_rid, 0);
319
320 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, edintr, sc,
321 &sc->irq_handle);
322 if (error) {
323 device_printf(dev, "setup intr failed %d \n", error);
324 ed_release_resources(dev);
325 return (error);
326 }
327
328 /*
329 * For the older cards, we have to get the MAC address from
330 * the card in some way. Let's try the standard PCMCIA way
331 * first. If that fails, then check to see if we have valid
332 * data from the standard NE-2000 data roms. If that fails,
333 * check to see if the card has a hint about where to look in
334 * its CIS. If that fails, maybe we should look at some
335 * default value. In all fails, we should fail the attach,
336 * but don't right now.
337 */
338 if (sc->chip_type == ED_CHIP_TYPE_DP8390) {
339 pccard_get_ether(dev, enaddr);
340 if (bootverbose)
341 device_printf(dev, "CIS MAC %6D\n", enaddr, ":");
342 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
343 sum |= enaddr[i];
344 if (sum == 0 && ed_pccard_rom_mac(dev, enaddr)) {
345 if (bootverbose)
346 device_printf(dev, "ROM mac %6D\n", enaddr,
347 ":");
348 sum++;
349 }
350 if (sum == 0 && pp->flags & NE2000DVF_ENADDR) {
351 for (i = 0; i < ETHER_ADDR_LEN; i++) {
352 ed_pccard_memread(dev, pp->enoff + i * 2,
353 enaddr + i);
354 sum |= enaddr[i];
355 }
356 if (bootverbose)
357 device_printf(dev, "Hint MAC %6D\n", enaddr,
358 ":");
359 }
360 if (sum == 0) {
361 for (i = 0; i < ETHER_ADDR_LEN; i++) {
362 ed_pccard_memread(dev, ED_DEFAULT_MAC_OFFSET +
363 i * 2, enaddr + i);
364 sum |= enaddr[i];
365 }
366 if (bootverbose)
367 device_printf(dev, "Fallback MAC %6D\n",
368 enaddr, ":");
369 }
370 if (sum == 0) {
371 device_printf(dev, "Cannot extract MAC address.\n");
372 ed_release_resources(dev);
373 return (ENXIO);
374 }
375 bcopy(enaddr, sc->enaddr, ETHER_ADDR_LEN);
376 }
377
378 error = ed_attach(dev);
379#ifndef ED_NO_MIIBUS
380 if (error == 0 && (sc->chip_type == ED_CHIP_TYPE_DL10019 ||
381 sc->chip_type == ED_CHIP_TYPE_DL10022)) {
382 /* Probe for an MII bus, but ignore errors. */
383 ed_pccard_dlink_mii_reset(sc);
384 sc->mii_readbits = ed_pccard_dlink_mii_readbits;
385 sc->mii_writebits = ed_pccard_dlink_mii_writebits;
386 mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
387 ed_ifmedia_sts);
388 }
389#endif
390 if (pp->flags & NE2000DVF_MODEM)
391 ed_pccard_add_modem(dev, pp->siorid);
392 return (error);
393}
394
395static void
396ax88x90_geteprom(struct ed_softc *sc)
397{
398 int prom[16],i;
399 u_char tmp;
400 struct {
401 unsigned char offset, value;
402 } pg_seq[] = {
403 {ED_P0_CR, ED_CR_RD2|ED_CR_STP},/* Select Page0 */
404 {ED_P0_DCR, 0x01},
405 {ED_P0_RBCR0, 0x00}, /* Clear the count regs. */
406 {ED_P0_RBCR1, 0x00},
407 {ED_P0_IMR, 0x00}, /* Mask completion irq. */
408 {ED_P0_ISR, 0xff},
409 {ED_P0_RCR, ED_RCR_MON | ED_RCR_INTT}, /* Set To Monitor */
410 {ED_P0_TCR, ED_TCR_LB0}, /* loopback mode. */
411 {ED_P0_RBCR0, 32},
412 {ED_P0_RBCR1, 0x00},
413 {ED_P0_RSAR0, 0x00},
414 {ED_P0_RSAR1, 0x04},
415 {ED_P0_CR ,ED_CR_RD0 | ED_CR_STA},
416 };
417
418 /* Reset Card */
419 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
420 ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
421 DELAY(5000);
422 ed_asic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP);
423 DELAY(5000);
424
425 /* Card Settings */
426 for (i = 0; i < sizeof(pg_seq) / sizeof(pg_seq[0]); i++)
427 ed_nic_outb(sc, pg_seq[i].offset, pg_seq[i].value);
428
429 /* Get Data */
430 for (i = 0; i < 16; i++)
431 prom[i] = ed_asic_inb(sc, 0);
432 sc->enaddr[0] = prom[0] & 0xff;
433 sc->enaddr[1] = prom[0] >> 8;
434 sc->enaddr[2] = prom[1] & 0xff;
435 sc->enaddr[3] = prom[1] >> 8;
436 sc->enaddr[4] = prom[2] & 0xff;
437 sc->enaddr[5] = prom[2] >> 8;
438}
439
440static int
441ed_pccard_memwrite(device_t dev, off_t offset, u_char byte)
442{
443 int cis_rid;
444 struct resource *cis;
445
446 cis_rid = 0;
447 cis = bus_alloc_resource(dev, SYS_RES_MEMORY, &cis_rid, 0, ~0,
448 4 << 10, RF_ACTIVE | RF_SHAREABLE);
449 if (cis == NULL)
450 return (ENXIO);
451 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY,
452 cis_rid, PCCARD_A_MEM_ATTR);
453
454 bus_space_write_1(rman_get_bustag(cis), rman_get_bushandle(cis),
455 offset, byte);
456
457 bus_deactivate_resource(dev, SYS_RES_MEMORY, cis_rid, cis);
458 bus_release_resource(dev, SYS_RES_MEMORY, cis_rid, cis);
459
460 return (0);
461}
462
463static int
464ed_pccard_memread(device_t dev, off_t offset, u_char *byte)
465{
466 int cis_rid;
467 struct resource *cis;
468
469 cis_rid = 0;
470 cis = bus_alloc_resource(dev, SYS_RES_MEMORY, &cis_rid, 0, ~0,
471 4 << 10, RF_ACTIVE | RF_SHAREABLE);
472 if (cis == NULL)
473 return (ENXIO);
474 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY,
475 cis_rid, PCCARD_A_MEM_ATTR);
476
477 *byte = bus_space_read_1(rman_get_bustag(cis), rman_get_bushandle(cis),
478 offset);
479
480 bus_deactivate_resource(dev, SYS_RES_MEMORY, cis_rid, cis);
481 bus_release_resource(dev, SYS_RES_MEMORY, cis_rid, cis);
482
483 return (0);
484}
485
486/*
487 * Probe the Ethernet MAC addrees for PCMCIA Linksys EtherFast 10/100
488 * and compatible cards (DL10019C Ethernet controller).
489 *
490 * Note: The PAO patches try to use more memory for the card, but that
491 * seems to fail for my card. A future optimization would add this back
492 * conditionally.
493 */
494static int
495ed_pccard_Linksys(device_t dev)
496{
497 struct ed_softc *sc = device_get_softc(dev);
498 u_char sum;
499 uint8_t id;
500 int i;
501
502 /*
503 * Linksys registers(offset from ASIC base)
504 *
505 * 0x04-0x09 : Physical Address Register 0-5 (PAR0-PAR5)
506 * 0x0A : Card ID Register (CIR)
507 * 0x0B : Check Sum Register (SR)
508 */
509 for (sum = 0, i = 0x04; i < 0x0c; i++)
510 sum += ed_asic_inb(sc, i);
511 if (sum != 0xff)
512 return (ENXIO); /* invalid DL10019C */
513 for (i = 0; i < ETHER_ADDR_LEN; i++)
514 sc->enaddr[i] = ed_asic_inb(sc, 0x04 + i);
515 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
516 id = ed_asic_inb(sc, 0xf);
517 sc->isa16bit = 1;
518 sc->vendor = ED_VENDOR_NOVELL;
519 sc->type = ED_TYPE_NE2000;
520 sc->chip_type = (id & 0x90) == 0x90 ?
521 ED_CHIP_TYPE_DL10022 : ED_CHIP_TYPE_DL10019;
522 sc->type_str = ((id & 0x90) == 0x90) ? "DL10022" : "DL10019";
523 return (0);
524}
525
526/*
527 * Special setup for AX88[17]90
528 */
529static int
530ed_pccard_ax88x90(device_t dev)
531{
532 int error;
533 int flags = device_get_flags(dev);
534 int iobase;
535 char *ts;
536 struct ed_softc *sc = device_get_softc(dev);
537
538 /* Allocate the port resource during setup. */
539 error = ed_alloc_port(dev, sc->port_rid, ED_NOVELL_IO_PORTS);
540 if (error)
541 return (error);
542
543 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
544 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
545 sc->chip_type = ED_CHIP_TYPE_AX88190;
546
547 /*
548 * Set Attribute Memory IOBASE Register. Is this a deficiency in
549 * the PC Card layer, or an ax88190 specific issue? xxx
550 */
551 iobase = rman_get_start(sc->port_res);
552 ed_pccard_memwrite(dev, ED_AX88190_IOBASE0, iobase & 0xff);
553 ed_pccard_memwrite(dev, ED_AX88190_IOBASE1, (iobase >> 8) & 0xff);
554 ts = "AX88190";
555 if (ed_asic_inb(sc, ED_ASIX_TEST) != 0) {
556 ed_pccard_memwrite(dev, ED_AX88790_CSR, ED_AX88790_CSR_PWRDWN);
557 ts = "AX88790";
558 }
559 ax88x90_geteprom(sc);
560 ed_release_resources(dev);
561 error = ed_probe_Novell(dev, 0, flags);
562 if (error == 0) {
563 sc->vendor = ED_VENDOR_NOVELL;
564 sc->type = ED_TYPE_NE2000;
565 sc->chip_type = ED_CHIP_TYPE_AX88190;
566 sc->type_str = ts;
567 }
568 return (error);
569}
570
571#ifndef ED_NO_MIIBUS
572/* MII bit-twiddling routines for cards using Dlink chipset */
573#define DLINK_MIISET(sc, x) ed_asic_outb(sc, ED_DLINK_MIIBUS, \
574 ed_asic_inb(sc, ED_DLINK_MIIBUS) | (x))
575#define DLINK_MIICLR(sc, x) ed_asic_outb(sc, ED_DLINK_MIIBUS, \
576 ed_asic_inb(sc, ED_DLINK_MIIBUS) & ~(x))
577
578static void
579ed_pccard_dlink_mii_reset(sc)
580 struct ed_softc *sc;
581{
582 if (sc->chip_type != ED_CHIP_TYPE_DL10022)
583 return;
584
585 ed_asic_outb(sc, ED_DLINK_MIIBUS, ED_DLINK_MII_RESET2);
586 DELAY(10);
587 ed_asic_outb(sc, ED_DLINK_MIIBUS,
588 ED_DLINK_MII_RESET2 | ED_DLINK_MII_RESET1);
589 DELAY(10);
590 ed_asic_outb(sc, ED_DLINK_MIIBUS, ED_DLINK_MII_RESET2);
591 DELAY(10);
592 ed_asic_outb(sc, ED_DLINK_MIIBUS,
593 ED_DLINK_MII_RESET2 | ED_DLINK_MII_RESET1);
594 DELAY(10);
595 ed_asic_outb(sc, ED_DLINK_MIIBUS, 0);
596}
597
598static void
599ed_pccard_dlink_mii_writebits(sc, val, nbits)
600 struct ed_softc *sc;
601 u_int val;
602 int nbits;
603{
604 int i;
605
606 if (sc->chip_type == ED_CHIP_TYPE_DL10022)
607 DLINK_MIISET(sc, ED_DLINK_MII_DIROUT_22);
608 else
609 DLINK_MIISET(sc, ED_DLINK_MII_DIROUT_19);
610
611 for (i = nbits - 1; i >= 0; i--) {
612 if ((val >> i) & 1)
613 DLINK_MIISET(sc, ED_DLINK_MII_DATAOUT);
614 else
615 DLINK_MIICLR(sc, ED_DLINK_MII_DATAOUT);
616 DELAY(10);
617 DLINK_MIISET(sc, ED_DLINK_MII_CLK);
618 DELAY(10);
619 DLINK_MIICLR(sc, ED_DLINK_MII_CLK);
620 DELAY(10);
621 }
622}
623
624static u_int
625ed_pccard_dlink_mii_readbits(sc, nbits)
626 struct ed_softc *sc;
627 int nbits;
628{
629 int i;
630 u_int val = 0;
631
632 if (sc->chip_type == ED_CHIP_TYPE_DL10022)
633 DLINK_MIICLR(sc, ED_DLINK_MII_DIROUT_22);
634 else
635 DLINK_MIICLR(sc, ED_DLINK_MII_DIROUT_19);
636
637 for (i = nbits - 1; i >= 0; i--) {
638 DLINK_MIISET(sc, ED_DLINK_MII_CLK);
639 DELAY(10);
640 val <<= 1;
641 if (ed_asic_inb(sc, ED_DLINK_MIIBUS) & ED_DLINK_MII_DATATIN)
642 val++;
643 DLINK_MIICLR(sc, ED_DLINK_MII_CLK);
644 DELAY(10);
645 }
646
647 return val;
648}
649#endif
650
651static device_method_t ed_pccard_methods[] = {
652 /* Device interface */
653 DEVMETHOD(device_probe, pccard_compat_probe),
654 DEVMETHOD(device_attach, pccard_compat_attach),
655 DEVMETHOD(device_detach, ed_detach),
656
657#ifndef ED_NO_MIIBUS
658 /* Bus interface */
659 DEVMETHOD(bus_child_detached, ed_child_detached),
660
661 /* MII interface */
662 DEVMETHOD(miibus_readreg, ed_miibus_readreg),
663 DEVMETHOD(miibus_writereg, ed_miibus_writereg),
664#endif
665
666 /* Card interface */
667 DEVMETHOD(card_compat_match, ed_pccard_match),
668 DEVMETHOD(card_compat_probe, ed_pccard_probe),
669 DEVMETHOD(card_compat_attach, ed_pccard_attach),
670 { 0, 0 }
671};
672
673static driver_t ed_pccard_driver = {
674 "ed",
675 ed_pccard_methods,
676 sizeof(struct ed_softc)
677};
678
679DRIVER_MODULE(ed, pccard, ed_pccard_driver, ed_devclass, 0, 0);
680#ifndef ED_NO_MIIBUS
681DRIVER_MODULE(miibus, ed, miibus_driver, miibus_devclass, 0, 0);
682#endif