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