2 * Copyright (c) 2005, M. Warner Losh
3 * Copyright (c) 1995, David Greenman
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Notes for adding media support. Each chipset is somewhat different
33 * from the others. Linux has a table of OIDs that it uses to see what
34 * supports the misc register of the NS83903. But a sampling of datasheets
35 * I could dig up on cards I own paints a different picture.
37 * Chipset specific details:
38 * NS 83903/902A paired
40 * id register at 0x1000: 7-3 = 0, 2-0 = 1.
41 * (maybe this test is too week)
42 * misc register at 0x018:
43 * 6 WAIT_TOUTENABLE enable watchdog timeout
44 * 3 AUI/TPI 1 AUX, 0 TPI
46 * 1 gdlink (tpi mode only) 1 tp good, 0 tp bad
47 * 0 0-no mam, 1 mam connected
48 * NS83926 appears to be a NS pcmcia glue chip used on the IBM Ethernet II
49 * and the NEC PC9801N-J12 ccr base 0x2000!
54 * 0-1 PHY01 00 TPI, 01 10B2, 10 10B5, 11 TPI (reduced squ)
55 * 2 LNKEN 0 - enable link and auto switch, 1 disable
56 * 3 LNKSTS TPI + LNKEN=0 + link good == 1, else 0
58 * 88 00 88 00 88 00, etc
60 * TMI tc3299a (cr PHY01 == 0)
64 * 0-1 PHY01 00 auto, 01 res, 10 10B5, 11 TPI
65 * 2 GDLINK 1 disable checking of link
66 * 6 LINK 0 bad link, 1 good link
67 * TMI tc5299 10/100 chip, has a different MII interaction than
68 * dl100xx and ax88x90.
70 * EN5017A, EN5020 no data, but very popular
72 * NetBSD supports RTL8019, but none have surfaced that I can see
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/socket.h>
78 #include <sys/kernel.h>
82 #include <sys/module.h>
84 #include <machine/bus.h>
86 #include <machine/resource.h>
88 #include <net/ethernet.h>
90 #include <net/if_arp.h>
91 #include <net/if_mib.h>
92 #include <net/if_media.h>
94 #include <dev/ed/if_edreg.h>
95 #include <dev/ed/if_edvar.h>
96 #include <dev/ed/ax88x90reg.h>
97 #include <dev/ed/dl100xxreg.h>
98 #include <dev/ed/tc5299jreg.h>
99 #include <dev/pccard/pccardvar.h>
100 #include <dev/pccard/pccardreg.h>
101 #include <dev/pccard/pccard_cis.h>
102 #include <dev/mii/mii.h>
103 #include <dev/mii/miivar.h>
106 /* "device miibus" required. See GENERIC if you get errors here. */
107 #include "miibus_if.h"
108 #include "pccarddevs.h"
111 * NE-2000 based PC Cards have a number of ways to get the MAC address.
112 * Some cards encode this as a FUNCE. Others have this in the ROMs the
113 * same way that ISA cards do. Some have it encoded in the attribute
114 * memory somewhere that isn't in the CIS. Some new chipsets have it
115 * in special registers in the ASIC part of the chip.
117 * For those cards that have the MAC adress stored in attribute memory,
118 * nearly all of them have it at a fixed offset (0xff0). We use that
119 * offset as a source of last resource if other offsets have failed.
121 #define ED_DEFAULT_MAC_OFFSET 0xff0
123 static const struct ed_product {
124 struct pccard_product prod;
126 #define NE2000DVF_DL100XX 0x0001 /* chip is D-Link DL10019/22 */
127 #define NE2000DVF_AX88X90 0x0002 /* chip is ASIX AX88[17]90 */
128 #define NE2000DVF_TC5299J 0x0004 /* chip is Tamarack TC5299J */
129 #define NE2000DVF_ENADDR 0x0100 /* Get MAC from attr mem */
130 #define NE2000DVF_ANYFUNC 0x0200 /* Allow any function type */
131 #define NE2000DVF_MODEM 0x0400 /* Has a modem/serial */
133 } ed_pccard_products[] = {
134 { PCMCIA_CARD(ACCTON, EN2212), 0},
135 { PCMCIA_CARD(ACCTON, EN2216), 0},
136 { PCMCIA_CARD(ALLIEDTELESIS, LA_PCM), 0},
137 { PCMCIA_CARD(AMBICOM, AMB8002T), 0},
138 { PCMCIA_CARD(BILLIONTON, CFLT10N), 0},
139 { PCMCIA_CARD(BILLIONTON, LNA100B), NE2000DVF_AX88X90},
140 { PCMCIA_CARD(BILLIONTON, LNT10TN), 0},
141 { PCMCIA_CARD(BROMAX, IPORT), 0},
142 { PCMCIA_CARD(BROMAX, IPORT2), 0},
143 { PCMCIA_CARD(BUFFALO, LPC2_CLT), 0},
144 { PCMCIA_CARD(BUFFALO, LPC3_CLT), 0},
145 { PCMCIA_CARD(BUFFALO, LPC3_CLX), NE2000DVF_AX88X90},
146 { PCMCIA_CARD(BUFFALO, LPC4_TX), NE2000DVF_AX88X90},
147 { PCMCIA_CARD(BUFFALO, LPC4_CLX), NE2000DVF_AX88X90},
148 { PCMCIA_CARD(BUFFALO, LPC_CF_CLT), 0},
149 { PCMCIA_CARD(CNET, NE2000), 0},
150 { PCMCIA_CARD(COMPEX, AX88190), NE2000DVF_AX88X90},
151 { PCMCIA_CARD(COMPEX, LANMODEM), 0},
152 { PCMCIA_CARD(COMPEX, LINKPORT_ENET_B), 0},
153 { PCMCIA_CARD(COREGA, ETHER_II_PCC_T), 0},
154 { PCMCIA_CARD(COREGA, ETHER_II_PCC_TD), 0},
155 { PCMCIA_CARD(COREGA, ETHER_PCC_T), 0},
156 { PCMCIA_CARD(COREGA, ETHER_PCC_TD), 0},
157 { PCMCIA_CARD(COREGA, FAST_ETHER_PCC_TX), NE2000DVF_DL100XX},
158 { PCMCIA_CARD(COREGA, FETHER_PCC_TXD), NE2000DVF_AX88X90},
159 { PCMCIA_CARD(COREGA, FETHER_PCC_TXF), NE2000DVF_DL100XX},
160 { PCMCIA_CARD(DAYNA, COMMUNICARD_E_1), 0},
161 { PCMCIA_CARD(DAYNA, COMMUNICARD_E_2), 0},
162 { PCMCIA_CARD(DLINK, DE650), 0 },
163 { PCMCIA_CARD(DLINK, DE660), 0 },
164 { PCMCIA_CARD(DLINK, DE660PLUS), 0},
165 { PCMCIA_CARD(DYNALINK, L10C), 0},
166 { PCMCIA_CARD(EDIMAX, EP4000A), 0},
167 { PCMCIA_CARD(EPSON, EEN10B), NE2000DVF_ENADDR, 0xff0},
168 { PCMCIA_CARD(EXP, THINLANCOMBO), 0},
169 { PCMCIA_CARD(GLOBALVILLAGE, LANMODEM), 0},
170 { PCMCIA_CARD(GREY_CELL, TDK3000), 0},
171 { PCMCIA_CARD(GREY_CELL, DMF650TX),
172 NE2000DVF_ANYFUNC | NE2000DVF_DL100XX | NE2000DVF_MODEM},
173 { PCMCIA_CARD(IBM, HOME_AND_AWAY), 0},
174 { PCMCIA_CARD(IBM, INFOMOVER), NE2000DVF_ENADDR, 0xff0},
175 { PCMCIA_CARD(IODATA3, PCLAT), 0},
176 { PCMCIA_CARD(KINGSTON, CIO10T), 0},
177 { PCMCIA_CARD(KINGSTON, KNE2), 0},
178 { PCMCIA_CARD(LANTECH, FASTNETTX), NE2000DVF_AX88X90},
179 { PCMCIA_CARD(LINKSYS, COMBO_ECARD),
180 NE2000DVF_DL100XX | NE2000DVF_AX88X90},
181 { PCMCIA_CARD(LINKSYS, ECARD_1), 0},
182 { PCMCIA_CARD(LINKSYS, ECARD_2), 0},
183 { PCMCIA_CARD(LINKSYS, ETHERFAST), NE2000DVF_DL100XX},
184 { PCMCIA_CARD(LINKSYS, TRUST_COMBO_ECARD), 0},
185 { PCMCIA_CARD(MACNICA, ME1_JEIDA), 0},
186 { PCMCIA_CARD(MAGICRAM, ETHER), 0},
187 { PCMCIA_CARD(MELCO, LPC3_CLX), NE2000DVF_AX88X90},
188 { PCMCIA_CARD(MELCO, LPC3_TX), NE2000DVF_AX88X90},
189 { PCMCIA_CARD(NDC, ND5100_E), 0},
190 { PCMCIA_CARD(NETGEAR, FA410TXC), NE2000DVF_DL100XX},
191 /* Same ID as DLINK DFE-670TXD. 670 has DL10022, fa411 has ax88790 */
192 { PCMCIA_CARD(NETGEAR, FA411), NE2000DVF_AX88X90 | NE2000DVF_DL100XX},
193 { PCMCIA_CARD(NEXTCOM, NEXTHAWK), 0},
194 { PCMCIA_CARD(NEWMEDIA, LANSURFER), 0},
195 { PCMCIA_CARD(OEM2, ETHERNET), 0},
196 { PCMCIA_CARD(OEM2, FAST_ETHERNET), NE2000DVF_AX88X90 },
197 { PCMCIA_CARD(OEM2, NE2000), 0},
198 { PCMCIA_CARD(PLANET, SMARTCOM2000), 0 },
199 { PCMCIA_CARD(PREMAX, PE200), 0},
200 { PCMCIA_CARD(PSION, LANGLOBAL),
201 NE2000DVF_ANYFUNC | NE2000DVF_AX88X90 | NE2000DVF_MODEM},
202 { PCMCIA_CARD(RACORE, ETHERNET), 0},
203 { PCMCIA_CARD(RACORE, FASTENET), NE2000DVF_AX88X90},
204 { PCMCIA_CARD(RACORE, 8041TX), NE2000DVF_AX88X90 | NE2000DVF_TC5299J},
205 { PCMCIA_CARD(RELIA, COMBO), 0},
206 { PCMCIA_CARD(RPTI, EP400), 0},
207 { PCMCIA_CARD(RPTI, EP401), 0},
208 { PCMCIA_CARD(SMC, EZCARD), 0},
209 { PCMCIA_CARD(SOCKET, EA_ETHER), 0},
210 { PCMCIA_CARD(SOCKET, ES_1000), 0},
211 { PCMCIA_CARD(SOCKET, LP_ETHER), 0},
212 { PCMCIA_CARD(SOCKET, LP_ETHER_CF), 0},
213 { PCMCIA_CARD(SOCKET, LP_ETH_10_100_CF), NE2000DVF_DL100XX},
214 { PCMCIA_CARD(SVEC, COMBOCARD), 0},
215 { PCMCIA_CARD(SVEC, LANCARD), 0},
216 { PCMCIA_CARD(TAMARACK, ETHERNET), 0},
217 { PCMCIA_CARD(TDK, CFE_10), 0},
218 { PCMCIA_CARD(TDK, LAK_CD031), 0},
219 { PCMCIA_CARD(TDK, DFL5610WS), 0},
220 { PCMCIA_CARD(TELECOMDEVICE, LM5LT), 0 },
221 { PCMCIA_CARD(TELECOMDEVICE, TCD_HPC100), NE2000DVF_AX88X90},
222 { PCMCIA_CARD(ZONET, ZEN), 0},
227 * PC Card (PCMCIA) specific code.
229 static int ed_pccard_probe(device_t);
230 static int ed_pccard_attach(device_t);
232 static int ed_pccard_dl100xx(device_t dev, const struct ed_product *);
233 static void ed_pccard_dl100xx_mii_reset(struct ed_softc *sc);
234 static u_int ed_pccard_dl100xx_mii_readbits(struct ed_softc *sc, int nbits);
235 static void ed_pccard_dl100xx_mii_writebits(struct ed_softc *sc, u_int val,
238 static int ed_pccard_ax88x90(device_t dev, const struct ed_product *);
239 static void ed_pccard_ax88x90_mii_reset(struct ed_softc *sc);
240 static u_int ed_pccard_ax88x90_mii_readbits(struct ed_softc *sc, int nbits);
241 static void ed_pccard_ax88x90_mii_writebits(struct ed_softc *sc, u_int val,
244 static int ed_miibus_readreg(device_t dev, int phy, int reg);
245 static int ed_ifmedia_upd(struct ifnet *);
246 static void ed_ifmedia_sts(struct ifnet *, struct ifmediareq *);
248 static int ed_pccard_tc5299j(device_t dev, const struct ed_product *);
249 static void ed_pccard_tc5299j_mii_reset(struct ed_softc *sc);
250 static u_int ed_pccard_tc5299j_mii_readbits(struct ed_softc *sc, int nbits);
251 static void ed_pccard_tc5299j_mii_writebits(struct ed_softc *sc, u_int val,
255 ed_pccard_print_entry(const struct ed_product *pp)
259 printf("Product entry: ");
260 if (pp->prod.pp_name)
261 printf("name='%s',", pp->prod.pp_name);
262 printf("vendor=%#x,product=%#x", pp->prod.pp_vendor,
263 pp->prod.pp_product);
264 for (i = 0; i < 4; i++)
265 if (pp->prod.pp_cis[i])
266 printf(",CIS%d='%s'", i, pp->prod.pp_cis[i]);
271 ed_pccard_probe(device_t dev)
273 const struct ed_product *pp, *pp2;
274 int error, first = 1;
275 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
277 /* Make sure we're a network function */
278 error = pccard_get_function(dev, &fcn);
282 if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
283 (const struct pccard_product *) ed_pccard_products,
284 sizeof(ed_pccard_products[0]), NULL)) != NULL) {
285 if (pp->prod.pp_name != NULL)
286 device_set_desc(dev, pp->prod.pp_name);
288 * Some devices don't ID themselves as network, but
289 * that's OK if the flags say so.
291 if (!(pp->flags & NE2000DVF_ANYFUNC) &&
292 fcn != PCCARD_FUNCTION_NETWORK)
295 * Some devices match multiple entries. Report that
296 * as a warning to help cull the table
299 while ((pp2 = (const struct ed_product *)pccard_product_lookup(
300 dev, (const struct pccard_product *)(pp2 + 1),
301 sizeof(ed_pccard_products[0]), NULL)) != NULL) {
304 "Warning: card matches multiple entries. Report to imp@freebsd.org\n");
305 ed_pccard_print_entry(pp);
308 ed_pccard_print_entry(pp2);
317 ed_pccard_rom_mac(device_t dev, uint8_t *enaddr)
319 struct ed_softc *sc = device_get_softc(dev);
324 * Read in the rom data at location 0. Since there are no
325 * NE-1000 based PC Card devices, we'll assume we're 16-bit.
327 * In researching what format this takes, I've found that the
328 * following appears to be true for multiple cards based on
329 * observation as well as datasheet digging.
331 * Data is stored in some ROM and is copied out 8 bits at a time
332 * into 16-bit wide locations. This means that the odd locations
333 * of the ROM are not used (and can be either 0 or ff).
335 * The contents appears to be as follows:
344 * 6-13 12-26 Reserved (varies by manufacturer)
348 * Some manufacturers have another image of enetaddr from
349 * PROM offset 0x10 to 0x15 with 0x42 in 0x1e and 0x1f, but
350 * this doesn't appear to be universally documented in the
351 * datasheets. Some manufactuers have a card type, card config
352 * checksums, etc encoded into PROM offset 6-13, but deciphering it
353 * requires more knowledge about the exact underlying chipset than
354 * we possess (and maybe can possess).
356 ed_pio_readmem(sc, 0, romdata, 32);
358 printf("ROM DATA: %32D\n", romdata, " ");
359 if (romdata[28] != 0x57 || romdata[30] != 0x57)
361 for (i = 0; i < ETHER_ADDR_LEN; i++)
362 enaddr[i] = romdata[i * 2];
367 ed_pccard_add_modem(device_t dev)
369 struct ed_softc *sc = device_get_softc(dev);
371 device_printf(dev, "Need to write this code: modem rid is %d\n",
377 ed_pccard_media_ioctl(struct ed_softc *sc, struct ifreq *ifr, u_long command)
379 struct mii_data *mii;
381 if (sc->miibus == NULL)
383 mii = device_get_softc(sc->miibus);
384 return (ifmedia_ioctl(sc->ifp, ifr, &mii->mii_media, command));
389 ed_pccard_mediachg(struct ed_softc *sc)
391 struct mii_data *mii;
393 if (sc->miibus == NULL)
395 mii = device_get_softc(sc->miibus);
400 ed_pccard_tick(void *arg)
402 struct ed_softc *sc = arg;
403 struct mii_data *mii;
406 ED_ASSERT_LOCKED(sc);
407 if (sc->miibus != NULL) {
408 mii = device_get_softc(sc->miibus);
409 media = mii->mii_media_status;
411 if (mii->mii_media_status & IFM_ACTIVE &&
412 media != mii->mii_media_status && 0 &&
413 sc->chip_type == ED_CHIP_TYPE_DL10022) {
414 ed_asic_outb(sc, ED_DL100XX_DIAG,
415 (mii->mii_media_active & IFM_FDX) ?
416 ED_DL100XX_COLLISON_DIS : 0);
420 callout_reset(&sc->tick_ch, hz, ed_pccard_tick, sc);
424 ed_pccard_attach(device_t dev)
427 u_char enaddr[ETHER_ADDR_LEN];
428 const struct ed_product *pp;
430 struct ed_softc *sc = device_get_softc(dev);
433 if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
434 (const struct pccard_product *) ed_pccard_products,
435 sizeof(ed_pccard_products[0]), NULL)) == NULL)
438 if (pp->flags & NE2000DVF_MODEM) {
440 for (i = 0; i < 4; i++) {
441 size = bus_get_resource_count(dev, SYS_RES_IOPORT, i);
442 if (size == ED_NOVELL_IO_PORTS)
447 if (sc->port_rid == -1) {
448 device_printf(dev, "Cannot locate my ports!\n");
454 /* Allocate the port resource during setup. */
455 error = ed_alloc_port(dev, sc->port_rid, ED_NOVELL_IO_PORTS);
458 error = ed_alloc_irq(dev, 0, 0);
463 * Determine which chipset we are. All the PC Card chipsets have the
464 * ASIC and NIC offsets in the same place.
466 sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
467 sc->nic_offset = ED_NOVELL_NIC_OFFSET;
470 error = ed_pccard_dl100xx(dev, pp);
472 error = ed_pccard_ax88x90(dev, pp);
474 error = ed_pccard_tc5299j(dev, pp);
476 error = ed_probe_Novell_generic(dev, device_get_flags(dev));
480 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
481 NULL, edintr, sc, &sc->irq_handle);
483 device_printf(dev, "setup intr failed %d \n", error);
488 * For the older cards, we have to get the MAC address from
489 * the card in some way. Let's try the standard PCMCIA way
490 * first. If that fails, then check to see if we have valid
491 * data from the standard NE-2000 data roms. If that fails,
492 * check to see if the card has a hint about where to look in
493 * its CIS. If that fails, maybe we should look at some
494 * default value. In all fails, we should fail the attach,
495 * but don't right now.
497 if (sc->chip_type == ED_CHIP_TYPE_DP8390) {
498 pccard_get_ether(dev, enaddr);
500 device_printf(dev, "CIS MAC %6D\n", enaddr, ":");
501 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
503 if (sum == 0 && ed_pccard_rom_mac(dev, enaddr)) {
505 device_printf(dev, "ROM mac %6D\n", enaddr,
509 if (sum == 0 && pp->flags & NE2000DVF_ENADDR) {
510 for (i = 0; i < ETHER_ADDR_LEN; i++) {
511 pccard_attr_read_1(dev, pp->enoff + i * 2,
516 device_printf(dev, "Hint %x MAC %6D\n",
517 pp->enoff, enaddr, ":");
520 for (i = 0; i < ETHER_ADDR_LEN; i++) {
521 pccard_attr_read_1(dev, ED_DEFAULT_MAC_OFFSET +
526 device_printf(dev, "Fallback MAC %6D\n",
530 device_printf(dev, "Cannot extract MAC address.\n");
531 ed_release_resources(dev);
534 bcopy(enaddr, sc->enaddr, ETHER_ADDR_LEN);
537 error = ed_attach(dev);
540 if (sc->chip_type == ED_CHIP_TYPE_DL10019 ||
541 sc->chip_type == ED_CHIP_TYPE_DL10022) {
542 /* Probe for an MII bus, but ignore errors. */
543 ed_pccard_dl100xx_mii_reset(sc);
544 (void)mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
546 } else if (sc->chip_type == ED_CHIP_TYPE_AX88190) {
547 ed_pccard_ax88x90_mii_reset(sc);
548 if ((error = mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
549 ed_ifmedia_sts)) != 0) {
550 device_printf(dev, "Missing mii!\n");
554 } else if (sc->chip_type == ED_CHIP_TYPE_TC5299J) {
555 ed_pccard_tc5299j_mii_reset(sc);
556 if ((error = mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
557 ed_ifmedia_sts)) != 0) {
558 device_printf(dev, "Missing mii!\n");
563 if (sc->miibus != NULL) {
564 sc->sc_tick = ed_pccard_tick;
565 sc->sc_mediachg = ed_pccard_mediachg;
566 sc->sc_media_ioctl = ed_pccard_media_ioctl;
568 if (sc->modem_rid != -1)
569 ed_pccard_add_modem(dev);
572 ed_release_resources(dev);
577 * Probe the Ethernet MAC addrees for PCMCIA Linksys EtherFast 10/100
578 * and compatible cards (DL10019C Ethernet controller).
580 * Note: The PAO patches try to use more memory for the card, but that
581 * seems to fail for my card. A future optimization would add this back
585 ed_pccard_dl100xx(device_t dev, const struct ed_product *pp)
587 struct ed_softc *sc = device_get_softc(dev);
592 if (!(pp->flags & NE2000DVF_DL100XX))
595 device_printf(dev, "Trying DL100xx probing\n");
596 error = ed_probe_Novell_generic(dev, device_get_flags(dev));
597 if (bootverbose && error)
598 device_printf(dev, "Novell generic probe failed: %d\n", error);
603 * Linksys registers(offset from ASIC base)
605 * 0x04-0x09 : Physical Address Register 0-5 (PAR0-PAR5)
606 * 0x0A : Card ID Register (CIR)
607 * 0x0B : Check Sum Register (SR)
609 for (sum = 0, i = 0x04; i < 0x0c; i++)
610 sum += ed_asic_inb(sc, i);
613 device_printf(dev, "Bad checksum %#x\n", sum);
614 return (ENXIO); /* invalid DL10019C */
617 device_printf(dev, "CIR is %d\n", ed_asic_inb(sc, 0xa));
618 for (i = 0; i < ETHER_ADDR_LEN; i++)
619 sc->enaddr[i] = ed_asic_inb(sc, 0x04 + i);
620 ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
621 id = ed_asic_inb(sc, 0xf);
623 sc->vendor = ED_VENDOR_NOVELL;
624 sc->type = ED_TYPE_NE2000;
625 sc->chip_type = (id & 0x90) == 0x90 ?
626 ED_CHIP_TYPE_DL10022 : ED_CHIP_TYPE_DL10019;
627 sc->type_str = ((id & 0x90) == 0x90) ? "DL10022" : "DL10019";
628 sc->mii_readbits = ed_pccard_dl100xx_mii_readbits;
629 sc->mii_writebits = ed_pccard_dl100xx_mii_writebits;
633 /* MII bit-twiddling routines for cards using Dlink chipset */
634 #define DL100XX_MIISET(sc, x) ed_asic_outb(sc, ED_DL100XX_MIIBUS, \
635 ed_asic_inb(sc, ED_DL100XX_MIIBUS) | (x))
636 #define DL100XX_MIICLR(sc, x) ed_asic_outb(sc, ED_DL100XX_MIIBUS, \
637 ed_asic_inb(sc, ED_DL100XX_MIIBUS) & ~(x))
640 ed_pccard_dl100xx_mii_reset(struct ed_softc *sc)
642 if (sc->chip_type != ED_CHIP_TYPE_DL10022)
645 ed_asic_outb(sc, ED_DL100XX_MIIBUS, ED_DL100XX_MII_RESET2);
647 ed_asic_outb(sc, ED_DL100XX_MIIBUS,
648 ED_DL100XX_MII_RESET2 | ED_DL100XX_MII_RESET1);
650 ed_asic_outb(sc, ED_DL100XX_MIIBUS, ED_DL100XX_MII_RESET2);
652 ed_asic_outb(sc, ED_DL100XX_MIIBUS,
653 ED_DL100XX_MII_RESET2 | ED_DL100XX_MII_RESET1);
655 ed_asic_outb(sc, ED_DL100XX_MIIBUS, 0);
659 ed_pccard_dl100xx_mii_writebits(struct ed_softc *sc, u_int val, int nbits)
663 if (sc->chip_type == ED_CHIP_TYPE_DL10022)
664 DL100XX_MIISET(sc, ED_DL100XX_MII_DIROUT_22);
666 DL100XX_MIISET(sc, ED_DL100XX_MII_DIROUT_19);
668 for (i = nbits - 1; i >= 0; i--) {
670 DL100XX_MIISET(sc, ED_DL100XX_MII_DATAOUT);
672 DL100XX_MIICLR(sc, ED_DL100XX_MII_DATAOUT);
674 DL100XX_MIISET(sc, ED_DL100XX_MII_CLK);
676 DL100XX_MIICLR(sc, ED_DL100XX_MII_CLK);
682 ed_pccard_dl100xx_mii_readbits(struct ed_softc *sc, int nbits)
687 if (sc->chip_type == ED_CHIP_TYPE_DL10022)
688 DL100XX_MIICLR(sc, ED_DL100XX_MII_DIROUT_22);
690 DL100XX_MIICLR(sc, ED_DL100XX_MII_DIROUT_19);
692 for (i = nbits - 1; i >= 0; i--) {
693 DL100XX_MIISET(sc, ED_DL100XX_MII_CLK);
696 if (ed_asic_inb(sc, ED_DL100XX_MIIBUS) & ED_DL100XX_MII_DATAIN)
698 DL100XX_MIICLR(sc, ED_DL100XX_MII_CLK);
705 ed_pccard_ax88x90_geteprom(struct ed_softc *sc)
710 unsigned char offset, value;
713 {ED_P0_CR, ED_CR_RD2 | ED_CR_STP | ED_CR_PAGE_0},
715 {ED_P0_RBCR0, 0x00}, /* Clear the count regs. */
717 {ED_P0_IMR, 0x00}, /* Mask completion irq. */
719 {ED_P0_RCR, ED_RCR_MON | ED_RCR_INTT}, /* Set To Monitor */
720 {ED_P0_TCR, ED_TCR_LB0}, /* loopback mode. */
725 {ED_P0_CR, ED_CR_RD0 | ED_CR_STA | ED_CR_PAGE_0},
729 tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
730 ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
732 ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP | ED_CR_PAGE_0);
736 for (i = 0; i < sizeof(pg_seq) / sizeof(pg_seq[0]); i++)
737 ed_nic_outb(sc, pg_seq[i].offset, pg_seq[i].value);
740 for (i = 0; i < ETHER_ADDR_LEN / 2; i++)
741 prom[i] = ed_asic_inw(sc, 0);
742 for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
743 sc->enaddr[i] = prom[i / 2] & 0xff;
744 sc->enaddr[i + 1] = (prom[i / 2] >> 8) & 0xff;
750 * Special setup for AX88[17]90
753 ed_pccard_ax88x90(device_t dev, const struct ed_product *pp)
755 int error, iobase, i, id;
757 struct ed_softc *sc = device_get_softc(dev);
759 if (!(pp->flags & NE2000DVF_AX88X90))
763 device_printf(dev, "Checking AX88x90\n");
766 * Set the IOBASE Register. The AX88x90 cards are potentially
767 * multifunction cards, and thus requires a slight workaround.
768 * We write the address the card is at.
770 iobase = rman_get_start(sc->port_res);
771 pccard_ccr_write_1(dev, PCCARD_CCR_IOBASE0, iobase & 0xff);
772 pccard_ccr_write_1(dev, PCCARD_CCR_IOBASE1, (iobase >> 8) & 0xff);
775 if (ed_asic_inb(sc, ED_AX88X90_TEST) != 0) {
777 * AX88790 (and I think AX88190A) chips need to be
778 * powered down. There's an erratum that says we should
779 * power down the PHY for 2.5s, but this seems to power
780 * down the whole card. I'm unsure why this was done, but
781 * appears to be required for proper operation.
783 pccard_ccr_write_1(dev, PCCARD_CCR_STATUS,
784 PCCARD_CCR_STATUS_PWRDWN);
786 * Linux axnet driver selects the internal phy for the ax88790
788 ed_asic_outb(sc, ED_AX88X90_GPIO, ED_AX88X90_GPIO_INT_PHY);
793 * Check to see if we have a MII PHY ID at any of the first 17
794 * locations. All AX88x90 devices have MII and a PHY, so we use
795 * this to weed out chips that would otherwise make it through
796 * the tests we have after this point.
798 sc->mii_readbits = ed_pccard_ax88x90_mii_readbits;
799 sc->mii_writebits = ed_pccard_ax88x90_mii_writebits;
800 for (i = 0; i < 17; i++) {
801 id = ed_miibus_readreg(dev, i, MII_PHYIDR1);
802 if (id != 0 && id != 0xffff)
806 sc->mii_readbits = 0;
807 sc->mii_writebits = 0;
811 sc->chip_type = ED_CHIP_TYPE_AX88190;
812 error = ed_pccard_ax88x90_geteprom(sc);
815 error = ed_probe_Novell_generic(dev, device_get_flags(dev));
817 device_printf(dev, "probe novel returns %d\n", error);
819 sc->vendor = ED_VENDOR_NOVELL;
820 sc->type = ED_TYPE_NE2000;
821 sc->chip_type = ED_CHIP_TYPE_AX88190;
827 /* MII bit-twiddling routines for cards using AX88x90 chipset */
828 #define AX88X90_MIISET(sc, x) ed_asic_outb(sc, ED_AX88X90_MIIBUS, \
829 ed_asic_inb(sc, ED_AX88X90_MIIBUS) | (x))
830 #define AX88X90_MIICLR(sc, x) ed_asic_outb(sc, ED_AX88X90_MIIBUS, \
831 ed_asic_inb(sc, ED_AX88X90_MIIBUS) & ~(x))
834 ed_pccard_ax88x90_mii_reset(struct ed_softc *sc)
840 ed_pccard_ax88x90_mii_writebits(struct ed_softc *sc, u_int val, int nbits)
844 AX88X90_MIICLR(sc, ED_AX88X90_MII_DIROUT);
845 for (i = nbits - 1; i >= 0; i--) {
847 AX88X90_MIISET(sc, ED_AX88X90_MII_DATAOUT);
849 AX88X90_MIICLR(sc, ED_AX88X90_MII_DATAOUT);
851 AX88X90_MIISET(sc, ED_AX88X90_MII_CLK);
853 AX88X90_MIICLR(sc, ED_AX88X90_MII_CLK);
859 ed_pccard_ax88x90_mii_readbits(struct ed_softc *sc, int nbits)
864 AX88X90_MIISET(sc, ED_AX88X90_MII_DIROUT);
865 for (i = nbits - 1; i >= 0; i--) {
866 AX88X90_MIISET(sc, ED_AX88X90_MII_CLK);
869 if (ed_asic_inb(sc, ED_AX88X90_MIIBUS) & ED_AX88X90_MII_DATAIN)
871 AX88X90_MIICLR(sc, ED_AX88X90_MII_CLK);
878 * Special setup for TC5299J
881 ed_pccard_tc5299j(device_t dev, const struct ed_product *pp)
885 struct ed_softc *sc = device_get_softc(dev);
887 if (!(pp->flags & NE2000DVF_TC5299J))
891 device_printf(dev, "Checking Tc5299j\n");
894 * Check to see if we have a MII PHY ID at any of the first 32
895 * locations. All TC5299J devices have MII and a PHY, so we use
896 * this to weed out chips that would otherwise make it through
897 * the tests we have after this point.
899 sc->mii_readbits = ed_pccard_tc5299j_mii_readbits;
900 sc->mii_writebits = ed_pccard_tc5299j_mii_writebits;
901 for (i = 0; i < 32; i++) {
902 id = ed_miibus_readreg(dev, i, MII_PHYIDR1);
903 if (id != 0 && id != 0xffff)
907 sc->mii_readbits = 0;
908 sc->mii_writebits = 0;
913 error = ed_probe_Novell_generic(dev, device_get_flags(dev));
915 device_printf(dev, "probe novel returns %d\n", error);
917 sc->mii_readbits = 0;
918 sc->mii_writebits = 0;
921 if (ed_pccard_rom_mac(dev, sc->enaddr) == 0) {
922 sc->mii_readbits = 0;
923 sc->mii_writebits = 0;
926 sc->vendor = ED_VENDOR_NOVELL;
927 sc->type = ED_TYPE_NE2000;
928 sc->chip_type = ED_CHIP_TYPE_TC5299J;
933 /* MII bit-twiddling routines for cards using TC5299J chipset */
934 #define TC5299J_MIISET(sc, x) ed_nic_outb(sc, ED_TC5299J_MIIBUS, \
935 ed_nic_inb(sc, ED_TC5299J_MIIBUS) | (x))
936 #define TC5299J_MIICLR(sc, x) ed_nic_outb(sc, ED_TC5299J_MIIBUS, \
937 ed_nic_inb(sc, ED_TC5299J_MIIBUS) & ~(x))
940 ed_pccard_tc5299j_mii_reset(struct ed_softc *sc)
946 ed_pccard_tc5299j_mii_writebits(struct ed_softc *sc, u_int val, int nbits)
951 cr = ed_nic_inb(sc, ED_P0_CR);
952 ed_nic_outb(sc, ED_P0_CR, cr | ED_CR_PAGE_3);
954 TC5299J_MIICLR(sc, ED_TC5299J_MII_DIROUT);
955 for (i = nbits - 1; i >= 0; i--) {
957 TC5299J_MIISET(sc, ED_TC5299J_MII_DATAOUT);
959 TC5299J_MIICLR(sc, ED_TC5299J_MII_DATAOUT);
960 TC5299J_MIISET(sc, ED_TC5299J_MII_CLK);
961 TC5299J_MIICLR(sc, ED_TC5299J_MII_CLK);
963 ed_nic_outb(sc, ED_P0_CR, cr);
967 ed_pccard_tc5299j_mii_readbits(struct ed_softc *sc, int nbits)
973 cr = ed_nic_inb(sc, ED_P0_CR);
974 ed_nic_outb(sc, ED_P0_CR, cr | ED_CR_PAGE_3);
976 TC5299J_MIISET(sc, ED_TC5299J_MII_DIROUT);
977 for (i = nbits - 1; i >= 0; i--) {
978 TC5299J_MIISET(sc, ED_TC5299J_MII_CLK);
980 if (ed_nic_inb(sc, ED_TC5299J_MIIBUS) & ED_TC5299J_MII_DATAIN)
982 TC5299J_MIICLR(sc, ED_TC5299J_MII_CLK);
984 ed_nic_outb(sc, ED_P0_CR, cr);
989 * MII bus support routines.
992 ed_miibus_readreg(device_t dev, int phy, int reg)
998 * The AX88790 seem to have phy 0..f external, and 0x10 internal.
999 * but they also seem to have a bogus one that shows up at phy
1000 * 0x11 through 0x1f.
1005 sc = device_get_softc(dev);
1006 (*sc->mii_writebits)(sc, 0xffffffff, 32);
1007 (*sc->mii_writebits)(sc, ED_MII_STARTDELIM, ED_MII_STARTDELIM_BITS);
1008 (*sc->mii_writebits)(sc, ED_MII_READOP, ED_MII_OP_BITS);
1009 (*sc->mii_writebits)(sc, phy, ED_MII_PHY_BITS);
1010 (*sc->mii_writebits)(sc, reg, ED_MII_REG_BITS);
1011 failed = (*sc->mii_readbits)(sc, ED_MII_ACK_BITS);
1012 val = (*sc->mii_readbits)(sc, ED_MII_DATA_BITS);
1013 (*sc->mii_writebits)(sc, ED_MII_IDLE, ED_MII_IDLE_BITS);
1014 return (failed ? 0 : val);
1018 ed_miibus_writereg(device_t dev, int phy, int reg, int data)
1020 struct ed_softc *sc;
1023 * The AX88790 seem to have phy 0..f external, and 0x10 internal.
1024 * but they also seem to have a bogus one that shows up at phy
1025 * 0x11 through 0x1f.
1030 sc = device_get_softc(dev);
1031 (*sc->mii_writebits)(sc, 0xffffffff, 32);
1032 (*sc->mii_writebits)(sc, ED_MII_STARTDELIM, ED_MII_STARTDELIM_BITS);
1033 (*sc->mii_writebits)(sc, ED_MII_WRITEOP, ED_MII_OP_BITS);
1034 (*sc->mii_writebits)(sc, phy, ED_MII_PHY_BITS);
1035 (*sc->mii_writebits)(sc, reg, ED_MII_REG_BITS);
1036 (*sc->mii_writebits)(sc, ED_MII_TURNAROUND, ED_MII_TURNAROUND_BITS);
1037 (*sc->mii_writebits)(sc, data, ED_MII_DATA_BITS);
1038 (*sc->mii_writebits)(sc, ED_MII_IDLE, ED_MII_IDLE_BITS);
1042 ed_ifmedia_upd(struct ifnet *ifp)
1044 struct ed_softc *sc;
1045 struct mii_data *mii;
1048 if (sc->miibus == NULL)
1051 mii = device_get_softc(sc->miibus);
1052 return mii_mediachg(mii);
1056 ed_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1058 struct ed_softc *sc;
1059 struct mii_data *mii;
1062 if (sc->miibus == NULL)
1065 mii = device_get_softc(sc->miibus);
1067 ifmr->ifm_active = mii->mii_media_active;
1068 ifmr->ifm_status = mii->mii_media_status;
1072 ed_child_detached(device_t dev, device_t child)
1074 struct ed_softc *sc;
1076 sc = device_get_softc(dev);
1077 if (child == sc->miibus)
1081 static device_method_t ed_pccard_methods[] = {
1082 /* Device interface */
1083 DEVMETHOD(device_probe, ed_pccard_probe),
1084 DEVMETHOD(device_attach, ed_pccard_attach),
1085 DEVMETHOD(device_detach, ed_detach),
1088 DEVMETHOD(bus_child_detached, ed_child_detached),
1091 DEVMETHOD(miibus_readreg, ed_miibus_readreg),
1092 DEVMETHOD(miibus_writereg, ed_miibus_writereg),
1097 static driver_t ed_pccard_driver = {
1100 sizeof(struct ed_softc)
1103 DRIVER_MODULE(ed, pccard, ed_pccard_driver, ed_devclass, 0, 0);
1104 DRIVER_MODULE(miibus, ed, miibus_driver, miibus_devclass, 0, 0);
1105 MODULE_DEPEND(ed, miibus, 1, 1, 1);
1106 MODULE_DEPEND(ed, ether, 1, 1, 1);