if_ed_pccard.c revision 189726
1/*-
2 * Copyright (c) 2005, M. Warner Losh
3 * Copyright (c) 1995, David Greenman
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice unmodified, this list of conditions, and the following
11 *    disclaimer.
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.
15 *
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
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/dev/ed/if_ed_pccard.c 189726 2009-03-12 06:35:00Z imp $
29 */
30
31/*
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.
36 *
37 * Chipset specific details:
38 * NS 83903/902A paired
39 *    ccr base 0x1020
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
45 *	2 loopback
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!
50 *
51 * winbond 289c926
52 *    ccr base 0xfd0
53 *    cfb (am 0xff2):
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
57 *    sr (am 0xff4)
58 *	88 00 88 00 88 00, etc
59 *
60 * TMI tc3299a (cr PHY01 == 0)
61 *    ccr base 0x3f8
62 *    cra (io 0xa)
63 *    crb (io 0xb)
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.
69 *
70 * EN5017A, EN5020	no data, but very popular
71 * Other chips?
72 * NetBSD supports RTL8019, but none have surfaced that I can see
73 */
74
75#include <sys/param.h>
76#include <sys/systm.h>
77#include <sys/socket.h>
78#include <sys/kernel.h>
79#include <sys/conf.h>
80#include <sys/uio.h>
81
82#include <sys/module.h>
83#include <sys/bus.h>
84#include <machine/bus.h>
85#include <sys/rman.h>
86#include <machine/resource.h>
87
88#include <net/ethernet.h>
89#include <net/if.h>
90#include <net/if_arp.h>
91#include <net/if_mib.h>
92#include <net/if_media.h>
93
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>
104
105#include "card_if.h"
106/* "device miibus" required.  See GENERIC if you get errors here. */
107#include "miibus_if.h"
108#include "pccarddevs.h"
109
110/*
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.
116 *
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.
120 */
121#define ED_DEFAULT_MAC_OFFSET	0xff0
122
123static const struct ed_product {
124	struct pccard_product	prod;
125	int flags;
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 */
132	int enoff;
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(COREGA, FETHER_II_PCC_TXD), NE2000DVF_AX88X90},
161	{ PCMCIA_CARD(COREGA, LAPCCTXD), 0},
162	{ PCMCIA_CARD(DAYNA, COMMUNICARD_E_1), 0},
163	{ PCMCIA_CARD(DAYNA, COMMUNICARD_E_2), 0},
164	{ PCMCIA_CARD(DLINK, DE650), 0 },
165	{ PCMCIA_CARD(DLINK, DE660), 0 },
166	{ PCMCIA_CARD(DLINK, DE660PLUS), 0},
167	{ PCMCIA_CARD(DYNALINK, L10C), 0},
168	{ PCMCIA_CARD(EDIMAX, EP4000A), 0},
169	{ PCMCIA_CARD(EPSON, EEN10B), NE2000DVF_ENADDR, 0xff0},
170	{ PCMCIA_CARD(EXP, THINLANCOMBO), 0},
171	{ PCMCIA_CARD(GLOBALVILLAGE, LANMODEM), 0},
172	{ PCMCIA_CARD(GREY_CELL, TDK3000), 0},
173	{ PCMCIA_CARD(GREY_CELL, DMF650TX),
174	    NE2000DVF_ANYFUNC | NE2000DVF_DL100XX | NE2000DVF_MODEM},
175	{ PCMCIA_CARD(IBM, HOME_AND_AWAY), 0},
176	{ PCMCIA_CARD(IBM, INFOMOVER), NE2000DVF_ENADDR, 0xff0},
177	{ PCMCIA_CARD(IODATA3, PCLAT), 0},
178	{ PCMCIA_CARD(KINGSTON, CIO10T), 0},
179	{ PCMCIA_CARD(KINGSTON, KNE2), 0},
180	{ PCMCIA_CARD(LANTECH, FASTNETTX), NE2000DVF_AX88X90},
181	{ PCMCIA_CARD(LINKSYS, COMBO_ECARD),
182	    NE2000DVF_DL100XX | NE2000DVF_AX88X90},
183	{ PCMCIA_CARD(LINKSYS, ECARD_1), 0},
184	{ PCMCIA_CARD(LINKSYS, ECARD_2), 0},
185	{ PCMCIA_CARD(LINKSYS, ETHERFAST), NE2000DVF_DL100XX},
186	{ PCMCIA_CARD(LINKSYS, TRUST_COMBO_ECARD), 0},
187	{ PCMCIA_CARD(MACNICA, ME1_JEIDA), 0},
188	{ PCMCIA_CARD(MAGICRAM, ETHER), 0},
189	{ PCMCIA_CARD(MELCO, LPC3_CLX), NE2000DVF_AX88X90},
190	{ PCMCIA_CARD(MELCO, LPC3_TX), NE2000DVF_AX88X90},
191	{ PCMCIA_CARD(MICRORESEARCH, MR10TPC), 0},
192	{ PCMCIA_CARD(NDC, ND5100_E), 0},
193	{ PCMCIA_CARD(NETGEAR, FA410TXC), NE2000DVF_DL100XX},
194	/* Same ID as DLINK DFE-670TXD.  670 has DL10022, fa411 has ax88790 */
195	{ PCMCIA_CARD(NETGEAR, FA411), NE2000DVF_AX88X90 | NE2000DVF_DL100XX},
196	{ PCMCIA_CARD(NEXTCOM, NEXTHAWK), 0},
197	{ PCMCIA_CARD(NEWMEDIA, LANSURFER), 0},
198	{ PCMCIA_CARD(OEM2, ETHERNET), 0},
199	{ PCMCIA_CARD(OEM2, FAST_ETHERNET), NE2000DVF_AX88X90 },
200	{ PCMCIA_CARD(OEM2, NE2000), 0},
201	{ PCMCIA_CARD(PLANET, SMARTCOM2000), 0 },
202	{ PCMCIA_CARD(PREMAX, PE200), 0},
203	{ PCMCIA_CARD(PSION, LANGLOBAL),
204	    NE2000DVF_ANYFUNC | NE2000DVF_AX88X90 | NE2000DVF_MODEM},
205	{ PCMCIA_CARD(RACORE, ETHERNET), 0},
206	{ PCMCIA_CARD(RACORE, FASTENET), NE2000DVF_AX88X90},
207	{ PCMCIA_CARD(RACORE, 8041TX), NE2000DVF_AX88X90 | NE2000DVF_TC5299J},
208	{ PCMCIA_CARD(RELIA, COMBO), 0},
209	{ PCMCIA_CARD(RPTI, EP400), 0},
210	{ PCMCIA_CARD(RPTI, EP401), 0},
211	{ PCMCIA_CARD(SMC, EZCARD), 0},
212	{ PCMCIA_CARD(SOCKET, EA_ETHER), 0},
213	{ PCMCIA_CARD(SOCKET, ES_1000), 0},
214	{ PCMCIA_CARD(SOCKET, LP_ETHER), 0},
215	{ PCMCIA_CARD(SOCKET, LP_ETHER_CF), 0},
216	{ PCMCIA_CARD(SOCKET, LP_ETH_10_100_CF), NE2000DVF_DL100XX},
217	{ PCMCIA_CARD(SVEC, COMBOCARD), 0},
218	{ PCMCIA_CARD(SVEC, LANCARD), 0},
219	{ PCMCIA_CARD(TAMARACK, ETHERNET), 0},
220	{ PCMCIA_CARD(TDK, CFE_10), 0},
221	{ PCMCIA_CARD(TDK, LAK_CD031), 0},
222	{ PCMCIA_CARD(TDK, DFL5610WS), 0},
223	{ PCMCIA_CARD(TELECOMDEVICE, LM5LT), 0 },
224	{ PCMCIA_CARD(TELECOMDEVICE, TCD_HPC100), NE2000DVF_AX88X90},
225	{ PCMCIA_CARD(TJ, PTJ_LAN_T), 0 },
226	{ PCMCIA_CARD(ZONET, ZEN), 0},
227	{ { NULL } }
228};
229
230/*
231 *      PC Card (PCMCIA) specific code.
232 */
233static int	ed_pccard_probe(device_t);
234static int	ed_pccard_attach(device_t);
235
236static int	ed_pccard_dl100xx(device_t dev, const struct ed_product *);
237static void	ed_pccard_dl100xx_mii_reset(struct ed_softc *sc);
238static u_int	ed_pccard_dl100xx_mii_readbits(struct ed_softc *sc, int nbits);
239static void	ed_pccard_dl100xx_mii_writebits(struct ed_softc *sc, u_int val,
240    int nbits);
241
242static int	ed_pccard_ax88x90(device_t dev, const struct ed_product *);
243static void	ed_pccard_ax88x90_mii_reset(struct ed_softc *sc);
244static u_int	ed_pccard_ax88x90_mii_readbits(struct ed_softc *sc, int nbits);
245static void	ed_pccard_ax88x90_mii_writebits(struct ed_softc *sc, u_int val,
246    int nbits);
247
248static int	ed_miibus_readreg(device_t dev, int phy, int reg);
249static int	ed_ifmedia_upd(struct ifnet *);
250static void	ed_ifmedia_sts(struct ifnet *, struct ifmediareq *);
251
252static int	ed_pccard_tc5299j(device_t dev, const struct ed_product *);
253static void	ed_pccard_tc5299j_mii_reset(struct ed_softc *sc);
254static u_int	ed_pccard_tc5299j_mii_readbits(struct ed_softc *sc, int nbits);
255static void	ed_pccard_tc5299j_mii_writebits(struct ed_softc *sc, u_int val,
256    int nbits);
257
258static void
259ed_pccard_print_entry(const struct ed_product *pp)
260{
261	int i;
262
263	printf("Product entry: ");
264	if (pp->prod.pp_name)
265		printf("name='%s',", pp->prod.pp_name);
266	printf("vendor=%#x,product=%#x", pp->prod.pp_vendor,
267	    pp->prod.pp_product);
268	for (i = 0; i < 4; i++)
269		if (pp->prod.pp_cis[i])
270			printf(",CIS%d='%s'", i, pp->prod.pp_cis[i]);
271	printf("\n");
272}
273
274static int
275ed_pccard_probe(device_t dev)
276{
277	const struct ed_product *pp, *pp2;
278	int		error, first = 1;
279	uint32_t	fcn = PCCARD_FUNCTION_UNSPEC;
280
281	/* Make sure we're a network function */
282	error = pccard_get_function(dev, &fcn);
283	if (error != 0)
284		return (error);
285
286	if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
287	    (const struct pccard_product *) ed_pccard_products,
288	    sizeof(ed_pccard_products[0]), NULL)) != NULL) {
289		if (pp->prod.pp_name != NULL)
290			device_set_desc(dev, pp->prod.pp_name);
291		/*
292		 * Some devices don't ID themselves as network, but
293		 * that's OK if the flags say so.
294		 */
295		if (!(pp->flags & NE2000DVF_ANYFUNC) &&
296		    fcn != PCCARD_FUNCTION_NETWORK)
297			return (ENXIO);
298		/*
299		 * Some devices match multiple entries.  Report that
300		 * as a warning to help cull the table
301		 */
302		pp2 = pp;
303		while ((pp2 = (const struct ed_product *)pccard_product_lookup(
304		    dev, (const struct pccard_product *)(pp2 + 1),
305		    sizeof(ed_pccard_products[0]), NULL)) != NULL) {
306			if (first) {
307				device_printf(dev,
308    "Warning: card matches multiple entries.  Report to imp@freebsd.org\n");
309				ed_pccard_print_entry(pp);
310				first = 0;
311			}
312			ed_pccard_print_entry(pp2);
313		}
314
315		return (0);
316	}
317	return (ENXIO);
318}
319
320static int
321ed_pccard_rom_mac(device_t dev, uint8_t *enaddr)
322{
323	struct ed_softc *sc = device_get_softc(dev);
324	uint8_t romdata[32];
325	int i;
326
327	/*
328	 * Read in the rom data at location 0.  Since there are no
329	 * NE-1000 based PC Card devices, we'll assume we're 16-bit.
330	 *
331	 * In researching what format this takes, I've found that the
332	 * following appears to be true for multiple cards based on
333	 * observation as well as datasheet digging.
334	 *
335	 * Data is stored in some ROM and is copied out 8 bits at a time
336	 * into 16-bit wide locations.  This means that the odd locations
337	 * of the ROM are not used (and can be either 0 or ff).
338	 *
339	 * The contents appears to be as follows:
340	 * PROM   RAM
341	 * Offset Offset	What
342	 *  0      0	ENETADDR 0
343	 *  1      2	ENETADDR 1
344	 *  2      4	ENETADDR 2
345	 *  3      6	ENETADDR 3
346	 *  4      8	ENETADDR 4
347	 *  5     10	ENETADDR 5
348	 *  6-13  12-26 Reserved (varies by manufacturer)
349	 * 14     28	0x57
350	 * 15     30    0x57
351	 *
352	 * Some manufacturers have another image of enetaddr from
353	 * PROM offset 0x10 to 0x15 with 0x42 in 0x1e and 0x1f, but
354	 * this doesn't appear to be universally documented in the
355	 * datasheets.  Some manufactuers have a card type, card config
356	 * checksums, etc encoded into PROM offset 6-13, but deciphering it
357	 * requires more knowledge about the exact underlying chipset than
358	 * we possess (and maybe can possess).
359	 */
360	ed_pio_readmem(sc, 0, romdata, 32);
361	if (bootverbose)
362		printf("ROM DATA: %32D\n", romdata, " ");
363	if (romdata[28] != 0x57 || romdata[30] != 0x57)
364		return (0);
365	for (i = 0; i < ETHER_ADDR_LEN; i++)
366		enaddr[i] = romdata[i * 2];
367	return (1);
368}
369
370static int
371ed_pccard_add_modem(device_t dev)
372{
373	struct ed_softc *sc = device_get_softc(dev);
374
375	device_printf(dev, "Need to write this code: modem rid is %d\n",
376	    sc->modem_rid);
377	return 0;
378}
379
380static int
381ed_pccard_media_ioctl(struct ed_softc *sc, struct ifreq *ifr, u_long command)
382{
383	struct mii_data *mii;
384
385	if (sc->miibus == NULL)
386		return (EINVAL);
387	mii = device_get_softc(sc->miibus);
388	return (ifmedia_ioctl(sc->ifp, ifr, &mii->mii_media, command));
389}
390
391
392static void
393ed_pccard_mediachg(struct ed_softc *sc)
394{
395	struct mii_data *mii;
396
397	if (sc->miibus == NULL)
398		return;
399	mii = device_get_softc(sc->miibus);
400	mii_mediachg(mii);
401}
402
403static void
404ed_pccard_tick(void *arg)
405{
406	struct ed_softc *sc = arg;
407	struct mii_data *mii;
408	int media = 0;
409
410	ED_ASSERT_LOCKED(sc);
411	if (sc->miibus != NULL) {
412		mii = device_get_softc(sc->miibus);
413		media = mii->mii_media_status;
414		mii_tick(mii);
415		if (mii->mii_media_status & IFM_ACTIVE &&
416		    media != mii->mii_media_status && 0 &&
417		    sc->chip_type == ED_CHIP_TYPE_DL10022) {
418			ed_asic_outb(sc, ED_DL100XX_DIAG,
419			    (mii->mii_media_active & IFM_FDX) ?
420			    ED_DL100XX_COLLISON_DIS : 0);
421		}
422
423	}
424	callout_reset(&sc->tick_ch, hz, ed_pccard_tick, sc);
425}
426
427static int
428ed_pccard_attach(device_t dev)
429{
430	u_char sum;
431	u_char enaddr[ETHER_ADDR_LEN];
432	const struct ed_product *pp;
433	int	error, i;
434	struct ed_softc *sc = device_get_softc(dev);
435	u_long size;
436
437	if ((pp = (const struct ed_product *) pccard_product_lookup(dev,
438	    (const struct pccard_product *) ed_pccard_products,
439	    sizeof(ed_pccard_products[0]), NULL)) == NULL)
440		return (ENXIO);
441	sc->modem_rid = -1;
442	if (pp->flags & NE2000DVF_MODEM) {
443		sc->port_rid = -1;
444		for (i = 0; i < 4; i++) {
445			size = bus_get_resource_count(dev, SYS_RES_IOPORT, i);
446			if (size == ED_NOVELL_IO_PORTS)
447				sc->port_rid = i;
448			else if (size == 8)
449				sc->modem_rid = i;
450		}
451		if (sc->port_rid == -1) {
452			device_printf(dev, "Cannot locate my ports!\n");
453			return (ENXIO);
454		}
455	} else {
456		sc->port_rid = 0;
457	}
458	/* Allocate the port resource during setup. */
459	error = ed_alloc_port(dev, sc->port_rid, ED_NOVELL_IO_PORTS);
460	if (error)
461		return (error);
462	error = ed_alloc_irq(dev, 0, 0);
463	if (error)
464		goto bad;
465
466	/*
467	 * Determine which chipset we are.  All the PC Card chipsets have the
468	 * ASIC and NIC offsets in the same place.
469	 */
470	sc->asic_offset = ED_NOVELL_ASIC_OFFSET;
471	sc->nic_offset  = ED_NOVELL_NIC_OFFSET;
472	error = ENXIO;
473	if (error != 0)
474		error = ed_pccard_dl100xx(dev, pp);
475	if (error != 0)
476		error = ed_pccard_ax88x90(dev, pp);
477	if (error != 0)
478		error = ed_pccard_tc5299j(dev, pp);
479	if (error != 0)
480		error = ed_probe_Novell_generic(dev, device_get_flags(dev));
481	if (error)
482		goto bad;
483
484	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
485	    NULL, edintr, sc, &sc->irq_handle);
486	if (error) {
487		device_printf(dev, "setup intr failed %d \n", error);
488		goto bad;
489	}
490
491	/*
492	 * For the older cards, we have to get the MAC address from
493	 * the card in some way.  Let's try the standard PCMCIA way
494	 * first.  If that fails, then check to see if we have valid
495	 * data from the standard NE-2000 data roms.  If that fails,
496	 * check to see if the card has a hint about where to look in
497	 * its CIS.  If that fails, maybe we should look at some
498	 * default value.  In all fails, we should fail the attach,
499	 * but don't right now.
500	 */
501	if (sc->chip_type == ED_CHIP_TYPE_DP8390) {
502		pccard_get_ether(dev, enaddr);
503		if (bootverbose)
504			device_printf(dev, "CIS MAC %6D\n", enaddr, ":");
505		for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
506			sum |= enaddr[i];
507		if (sum == 0 && ed_pccard_rom_mac(dev, enaddr)) {
508			if (bootverbose)
509				device_printf(dev, "ROM mac %6D\n", enaddr,
510				    ":");
511			sum++;
512		}
513		if (sum == 0 && pp->flags & NE2000DVF_ENADDR) {
514			for (i = 0; i < ETHER_ADDR_LEN; i++) {
515				pccard_attr_read_1(dev, pp->enoff + i * 2,
516				    enaddr + i);
517				sum |= enaddr[i];
518			}
519			if (bootverbose)
520				device_printf(dev, "Hint %x MAC %6D\n",
521				    pp->enoff, enaddr, ":");
522		}
523		if (sum == 0) {
524			for (i = 0; i < ETHER_ADDR_LEN; i++) {
525				pccard_attr_read_1(dev, ED_DEFAULT_MAC_OFFSET +
526				    i * 2, enaddr + i);
527				sum |= enaddr[i];
528			}
529			if (bootverbose)
530				device_printf(dev, "Fallback MAC %6D\n",
531				    enaddr, ":");
532		}
533		if (sum == 0) {
534			device_printf(dev, "Cannot extract MAC address.\n");
535			ed_release_resources(dev);
536			return (ENXIO);
537		}
538		bcopy(enaddr, sc->enaddr, ETHER_ADDR_LEN);
539	}
540
541	error = ed_attach(dev);
542	if (error)
543		goto bad;
544 	if (sc->chip_type == ED_CHIP_TYPE_DL10019 ||
545	    sc->chip_type == ED_CHIP_TYPE_DL10022) {
546		/* Probe for an MII bus, but ignore errors. */
547		ed_pccard_dl100xx_mii_reset(sc);
548		(void)mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
549		    ed_ifmedia_sts);
550	} else if (sc->chip_type == ED_CHIP_TYPE_AX88190) {
551		ed_pccard_ax88x90_mii_reset(sc);
552		if ((error = mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
553		     ed_ifmedia_sts)) != 0) {
554			device_printf(dev, "Missing mii!\n");
555			goto bad;
556		}
557
558	} else if (sc->chip_type == ED_CHIP_TYPE_TC5299J) {
559		ed_pccard_tc5299j_mii_reset(sc);
560		if ((error = mii_phy_probe(dev, &sc->miibus, ed_ifmedia_upd,
561		     ed_ifmedia_sts)) != 0) {
562			device_printf(dev, "Missing mii!\n");
563			goto bad;
564		}
565
566	}
567	if (sc->miibus != NULL) {
568		sc->sc_tick = ed_pccard_tick;
569		sc->sc_mediachg = ed_pccard_mediachg;
570		sc->sc_media_ioctl = ed_pccard_media_ioctl;
571	}
572	if (sc->modem_rid != -1)
573		ed_pccard_add_modem(dev);
574	return (0);
575bad:
576	ed_detach(dev);
577	return (error);
578}
579
580/*
581 * Probe the Ethernet MAC addrees for PCMCIA Linksys EtherFast 10/100
582 * and compatible cards (DL10019C Ethernet controller).
583 *
584 * Note: The PAO patches try to use more memory for the card, but that
585 * seems to fail for my card.  A future optimization would add this back
586 * conditionally.
587 */
588static int
589ed_pccard_dl100xx(device_t dev, const struct ed_product *pp)
590{
591	struct ed_softc *sc = device_get_softc(dev);
592	u_char sum;
593	uint8_t id;
594	int i, error;
595
596	if (!(pp->flags & NE2000DVF_DL100XX))
597		return (ENXIO);
598	if (bootverbose)
599		device_printf(dev, "Trying DL100xx probing\n");
600	error = ed_probe_Novell_generic(dev, device_get_flags(dev));
601	if (bootverbose && error)
602		device_printf(dev, "Novell generic probe failed: %d\n", error);
603	if (error != 0)
604		return (error);
605
606	/*
607	 * Linksys registers(offset from ASIC base)
608	 *
609	 * 0x04-0x09 : Physical Address Register 0-5 (PAR0-PAR5)
610	 * 0x0A      : Card ID Register (CIR)
611	 * 0x0B      : Check Sum Register (SR)
612	 */
613	for (sum = 0, i = 0x04; i < 0x0c; i++)
614		sum += ed_asic_inb(sc, i);
615	if (sum != 0xff) {
616		if (bootverbose)
617			device_printf(dev, "Bad checksum %#x\n", sum);
618		return (ENXIO);		/* invalid DL10019C */
619	}
620	if (bootverbose)
621		device_printf(dev, "CIR is %d\n", ed_asic_inb(sc, 0xa));
622	for (i = 0; i < ETHER_ADDR_LEN; i++)
623		sc->enaddr[i] = ed_asic_inb(sc, 0x04 + i);
624	ed_nic_outb(sc, ED_P0_DCR, ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
625	id = ed_asic_inb(sc, 0xf);
626	sc->isa16bit = 1;
627	sc->vendor = ED_VENDOR_NOVELL;
628	sc->type = ED_TYPE_NE2000;
629	sc->chip_type = (id & 0x90) == 0x90 ?
630	    ED_CHIP_TYPE_DL10022 : ED_CHIP_TYPE_DL10019;
631	sc->type_str = ((id & 0x90) == 0x90) ? "DL10022" : "DL10019";
632	sc->mii_readbits = ed_pccard_dl100xx_mii_readbits;
633	sc->mii_writebits = ed_pccard_dl100xx_mii_writebits;
634	return (0);
635}
636
637/* MII bit-twiddling routines for cards using Dlink chipset */
638#define DL100XX_MIISET(sc, x) ed_asic_outb(sc, ED_DL100XX_MIIBUS, \
639    ed_asic_inb(sc, ED_DL100XX_MIIBUS) | (x))
640#define DL100XX_MIICLR(sc, x) ed_asic_outb(sc, ED_DL100XX_MIIBUS, \
641    ed_asic_inb(sc, ED_DL100XX_MIIBUS) & ~(x))
642
643static void
644ed_pccard_dl100xx_mii_reset(struct ed_softc *sc)
645{
646	if (sc->chip_type != ED_CHIP_TYPE_DL10022)
647		return;
648
649	ed_asic_outb(sc, ED_DL100XX_MIIBUS, ED_DL100XX_MII_RESET2);
650	DELAY(10);
651	ed_asic_outb(sc, ED_DL100XX_MIIBUS,
652	    ED_DL100XX_MII_RESET2 | ED_DL100XX_MII_RESET1);
653	DELAY(10);
654	ed_asic_outb(sc, ED_DL100XX_MIIBUS, ED_DL100XX_MII_RESET2);
655	DELAY(10);
656	ed_asic_outb(sc, ED_DL100XX_MIIBUS,
657	    ED_DL100XX_MII_RESET2 | ED_DL100XX_MII_RESET1);
658	DELAY(10);
659	ed_asic_outb(sc, ED_DL100XX_MIIBUS, 0);
660}
661
662static void
663ed_pccard_dl100xx_mii_writebits(struct ed_softc *sc, u_int val, int nbits)
664{
665	int i;
666
667	if (sc->chip_type == ED_CHIP_TYPE_DL10022)
668		DL100XX_MIISET(sc, ED_DL100XX_MII_DIROUT_22);
669	else
670		DL100XX_MIISET(sc, ED_DL100XX_MII_DIROUT_19);
671
672	for (i = nbits - 1; i >= 0; i--) {
673		if ((val >> i) & 1)
674			DL100XX_MIISET(sc, ED_DL100XX_MII_DATAOUT);
675		else
676			DL100XX_MIICLR(sc, ED_DL100XX_MII_DATAOUT);
677		DELAY(10);
678		DL100XX_MIISET(sc, ED_DL100XX_MII_CLK);
679		DELAY(10);
680		DL100XX_MIICLR(sc, ED_DL100XX_MII_CLK);
681		DELAY(10);
682	}
683}
684
685static u_int
686ed_pccard_dl100xx_mii_readbits(struct ed_softc *sc, int nbits)
687{
688	int i;
689	u_int val = 0;
690
691	if (sc->chip_type == ED_CHIP_TYPE_DL10022)
692		DL100XX_MIICLR(sc, ED_DL100XX_MII_DIROUT_22);
693	else
694		DL100XX_MIICLR(sc, ED_DL100XX_MII_DIROUT_19);
695
696	for (i = nbits - 1; i >= 0; i--) {
697		DL100XX_MIISET(sc, ED_DL100XX_MII_CLK);
698		DELAY(10);
699		val <<= 1;
700		if (ed_asic_inb(sc, ED_DL100XX_MIIBUS) & ED_DL100XX_MII_DATAIN)
701			val++;
702		DL100XX_MIICLR(sc, ED_DL100XX_MII_CLK);
703		DELAY(10);
704	}
705	return val;
706}
707
708static int
709ed_pccard_ax88x90_geteprom(struct ed_softc *sc)
710{
711	int prom[16],i;
712	u_char tmp;
713	struct {
714		unsigned char offset, value;
715	} pg_seq[] = {
716						/* Select Page0 */
717		{ED_P0_CR, ED_CR_RD2 | ED_CR_STP | ED_CR_PAGE_0},
718		{ED_P0_DCR, 0x01},
719		{ED_P0_RBCR0, 0x00},		/* Clear the count regs. */
720		{ED_P0_RBCR1, 0x00},
721		{ED_P0_IMR, 0x00},		/* Mask completion irq. */
722		{ED_P0_ISR, 0xff},
723		{ED_P0_RCR, ED_RCR_MON | ED_RCR_INTT}, /* Set To Monitor */
724		{ED_P0_TCR, ED_TCR_LB0},	/* loopback mode. */
725		{ED_P0_RBCR0, 32},
726		{ED_P0_RBCR1, 0x00},
727		{ED_P0_RSAR0, 0x00},
728		{ED_P0_RSAR1, 0x04},
729		{ED_P0_CR, ED_CR_RD0 | ED_CR_STA | ED_CR_PAGE_0},
730	};
731
732	/* Reset Card */
733	tmp = ed_asic_inb(sc, ED_NOVELL_RESET);
734	ed_asic_outb(sc, ED_NOVELL_RESET, tmp);
735	DELAY(5000);
736	ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STP | ED_CR_PAGE_0);
737	DELAY(5000);
738
739	/* Card Settings */
740	for (i = 0; i < sizeof(pg_seq) / sizeof(pg_seq[0]); i++)
741		ed_nic_outb(sc, pg_seq[i].offset, pg_seq[i].value);
742
743	/* Get Data */
744	for (i = 0; i < ETHER_ADDR_LEN / 2; i++)
745		prom[i] = ed_asic_inw(sc, 0);
746	for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
747		sc->enaddr[i] = prom[i / 2] & 0xff;
748		sc->enaddr[i + 1] = (prom[i / 2] >> 8) & 0xff;
749	}
750	return (0);
751}
752
753/*
754 * Special setup for AX88[17]90
755 */
756static int
757ed_pccard_ax88x90(device_t dev, const struct ed_product *pp)
758{
759	int	error, iobase, i, id;
760	char *ts;
761	struct	ed_softc *sc = device_get_softc(dev);
762
763	if (!(pp->flags & NE2000DVF_AX88X90))
764		return (ENXIO);
765
766	if (bootverbose)
767		device_printf(dev, "Checking AX88x90\n");
768
769	/*
770	 * Set the IOBASE Register.  The AX88x90 cards are potentially
771	 * multifunction cards, and thus requires a slight workaround.
772	 * We write the address the card is at.
773	 */
774	iobase = rman_get_start(sc->port_res);
775	pccard_ccr_write_1(dev, PCCARD_CCR_IOBASE0, iobase & 0xff);
776	pccard_ccr_write_1(dev, PCCARD_CCR_IOBASE1, (iobase >> 8) & 0xff);
777
778	ts = "AX88190";
779	if (ed_asic_inb(sc, ED_AX88X90_TEST) != 0) {
780		/*
781		 * AX88790 (and I think AX88190A) chips need to be
782		 * powered down.  There's an erratum that says we should
783		 * power down the PHY for 2.5s, but this seems to power
784		 * down the whole card.  I'm unsure why this was done, but
785		 * appears to be required for proper operation.
786		 */
787		pccard_ccr_write_1(dev, PCCARD_CCR_STATUS,
788		    PCCARD_CCR_STATUS_PWRDWN);
789		/*
790		 * Linux axnet driver selects the internal phy for the ax88790
791		 */
792		ed_asic_outb(sc, ED_AX88X90_GPIO, ED_AX88X90_GPIO_INT_PHY);
793		ts = "AX88790";
794	}
795
796	/*
797	 * Check to see if we have a MII PHY ID at any of the first 17
798	 * locations.  All AX88x90 devices have MII and a PHY, so we use
799	 * this to weed out chips that would otherwise make it through
800	 * the tests we have after this point.
801	 */
802	sc->mii_readbits = ed_pccard_ax88x90_mii_readbits;
803	sc->mii_writebits = ed_pccard_ax88x90_mii_writebits;
804	for (i = 0; i < 17; i++) {
805		id = ed_miibus_readreg(dev, i, MII_PHYIDR1);
806		if (id != 0 && id != 0xffff)
807			break;
808	}
809	if (i == 17) {
810		sc->mii_readbits = 0;
811		sc->mii_writebits = 0;
812		return (ENXIO);
813	}
814
815	sc->chip_type = ED_CHIP_TYPE_AX88190;
816	error = ed_pccard_ax88x90_geteprom(sc);
817	if (error)
818		return (error);
819	error = ed_probe_Novell_generic(dev, device_get_flags(dev));
820	if (bootverbose)
821		device_printf(dev, "probe novel returns %d\n", error);
822	if (error == 0) {
823		sc->vendor = ED_VENDOR_NOVELL;
824		sc->type = ED_TYPE_NE2000;
825		sc->chip_type = ED_CHIP_TYPE_AX88190;
826		sc->type_str = ts;
827	}
828	return (error);
829}
830
831/* MII bit-twiddling routines for cards using AX88x90 chipset */
832#define AX88X90_MIISET(sc, x) ed_asic_outb(sc, ED_AX88X90_MIIBUS, \
833    ed_asic_inb(sc, ED_AX88X90_MIIBUS) | (x))
834#define AX88X90_MIICLR(sc, x) ed_asic_outb(sc, ED_AX88X90_MIIBUS, \
835    ed_asic_inb(sc, ED_AX88X90_MIIBUS) & ~(x))
836
837static void
838ed_pccard_ax88x90_mii_reset(struct ed_softc *sc)
839{
840	/* Do nothing! */
841}
842
843static void
844ed_pccard_ax88x90_mii_writebits(struct ed_softc *sc, u_int val, int nbits)
845{
846	int i;
847
848	AX88X90_MIICLR(sc, ED_AX88X90_MII_DIROUT);
849	for (i = nbits - 1; i >= 0; i--) {
850		if ((val >> i) & 1)
851			AX88X90_MIISET(sc, ED_AX88X90_MII_DATAOUT);
852		else
853			AX88X90_MIICLR(sc, ED_AX88X90_MII_DATAOUT);
854		DELAY(10);
855		AX88X90_MIISET(sc, ED_AX88X90_MII_CLK);
856		DELAY(10);
857		AX88X90_MIICLR(sc, ED_AX88X90_MII_CLK);
858		DELAY(10);
859	}
860}
861
862static u_int
863ed_pccard_ax88x90_mii_readbits(struct ed_softc *sc, int nbits)
864{
865	int i;
866	u_int val = 0;
867
868	AX88X90_MIISET(sc, ED_AX88X90_MII_DIROUT);
869	for (i = nbits - 1; i >= 0; i--) {
870		AX88X90_MIISET(sc, ED_AX88X90_MII_CLK);
871		DELAY(10);
872		val <<= 1;
873		if (ed_asic_inb(sc, ED_AX88X90_MIIBUS) & ED_AX88X90_MII_DATAIN)
874			val++;
875		AX88X90_MIICLR(sc, ED_AX88X90_MII_CLK);
876		DELAY(10);
877	}
878	return val;
879}
880
881/*
882 * Special setup for TC5299J
883 */
884static int
885ed_pccard_tc5299j(device_t dev, const struct ed_product *pp)
886{
887	int	error, i, id;
888	char *ts;
889	struct	ed_softc *sc = device_get_softc(dev);
890
891	if (!(pp->flags & NE2000DVF_TC5299J))
892		return (ENXIO);
893
894	if (bootverbose)
895		device_printf(dev, "Checking Tc5299j\n");
896
897	/*
898	 * Check to see if we have a MII PHY ID at any of the first 32
899	 * locations.  All TC5299J devices have MII and a PHY, so we use
900	 * this to weed out chips that would otherwise make it through
901	 * the tests we have after this point.
902	 */
903	sc->mii_readbits = ed_pccard_tc5299j_mii_readbits;
904	sc->mii_writebits = ed_pccard_tc5299j_mii_writebits;
905	for (i = 0; i < 32; i++) {
906		id = ed_miibus_readreg(dev, i, MII_PHYIDR1);
907		if (id != 0 && id != 0xffff)
908			break;
909	}
910	if (i == 32) {
911		sc->mii_readbits = 0;
912		sc->mii_writebits = 0;
913		return (ENXIO);
914	}
915
916	ts = "TC5299J";
917	error = ed_probe_Novell_generic(dev, device_get_flags(dev));
918	if (bootverbose)
919		device_printf(dev, "probe novel returns %d\n", error);
920	if (error != 0) {
921		sc->mii_readbits = 0;
922		sc->mii_writebits = 0;
923		return (error);
924	}
925	if (ed_pccard_rom_mac(dev, sc->enaddr) == 0) {
926		sc->mii_readbits = 0;
927		sc->mii_writebits = 0;
928		return (ENXIO);
929	}
930	sc->vendor = ED_VENDOR_NOVELL;
931	sc->type = ED_TYPE_NE2000;
932	sc->chip_type = ED_CHIP_TYPE_TC5299J;
933	sc->type_str = ts;
934	return (0);
935}
936
937/* MII bit-twiddling routines for cards using TC5299J chipset */
938#define TC5299J_MIISET(sc, x) ed_nic_outb(sc, ED_TC5299J_MIIBUS, \
939    ed_nic_inb(sc, ED_TC5299J_MIIBUS) | (x))
940#define TC5299J_MIICLR(sc, x) ed_nic_outb(sc, ED_TC5299J_MIIBUS, \
941    ed_nic_inb(sc, ED_TC5299J_MIIBUS) & ~(x))
942
943static void
944ed_pccard_tc5299j_mii_reset(struct ed_softc *sc)
945{
946	/* Do nothing! */
947}
948
949static void
950ed_pccard_tc5299j_mii_writebits(struct ed_softc *sc, u_int val, int nbits)
951{
952	int i;
953	uint8_t cr;
954
955	cr = ed_nic_inb(sc, ED_P0_CR);
956	ed_nic_outb(sc, ED_P0_CR, cr | ED_CR_PAGE_3);
957
958	TC5299J_MIICLR(sc, ED_TC5299J_MII_DIROUT);
959	for (i = nbits - 1; i >= 0; i--) {
960		if ((val >> i) & 1)
961			TC5299J_MIISET(sc, ED_TC5299J_MII_DATAOUT);
962		else
963			TC5299J_MIICLR(sc, ED_TC5299J_MII_DATAOUT);
964		TC5299J_MIISET(sc, ED_TC5299J_MII_CLK);
965		TC5299J_MIICLR(sc, ED_TC5299J_MII_CLK);
966	}
967	ed_nic_outb(sc, ED_P0_CR, cr);
968}
969
970static u_int
971ed_pccard_tc5299j_mii_readbits(struct ed_softc *sc, int nbits)
972{
973	int i;
974	u_int val = 0;
975	uint8_t cr;
976
977	cr = ed_nic_inb(sc, ED_P0_CR);
978	ed_nic_outb(sc, ED_P0_CR, cr | ED_CR_PAGE_3);
979
980	TC5299J_MIISET(sc, ED_TC5299J_MII_DIROUT);
981	for (i = nbits - 1; i >= 0; i--) {
982		TC5299J_MIISET(sc, ED_TC5299J_MII_CLK);
983		val <<= 1;
984		if (ed_nic_inb(sc, ED_TC5299J_MIIBUS) & ED_TC5299J_MII_DATAIN)
985			val++;
986		TC5299J_MIICLR(sc, ED_TC5299J_MII_CLK);
987	}
988	ed_nic_outb(sc, ED_P0_CR, cr);
989	return val;
990}
991
992/*
993 * MII bus support routines.
994 */
995static int
996ed_miibus_readreg(device_t dev, int phy, int reg)
997{
998	struct ed_softc *sc;
999	int failed, val;
1000
1001	/*
1002	 * The AX88790 seem to have phy 0..f external, and 0x10 internal.
1003	 * but they also seem to have a bogus one that shows up at phy
1004	 * 0x11 through 0x1f.
1005	 */
1006	if (phy >= 0x11)
1007		return (0);
1008
1009	sc = device_get_softc(dev);
1010	(*sc->mii_writebits)(sc, 0xffffffff, 32);
1011	(*sc->mii_writebits)(sc, ED_MII_STARTDELIM, ED_MII_STARTDELIM_BITS);
1012	(*sc->mii_writebits)(sc, ED_MII_READOP, ED_MII_OP_BITS);
1013	(*sc->mii_writebits)(sc, phy, ED_MII_PHY_BITS);
1014	(*sc->mii_writebits)(sc, reg, ED_MII_REG_BITS);
1015	failed = (*sc->mii_readbits)(sc, ED_MII_ACK_BITS);
1016	val = (*sc->mii_readbits)(sc, ED_MII_DATA_BITS);
1017	(*sc->mii_writebits)(sc, ED_MII_IDLE, ED_MII_IDLE_BITS);
1018	return (failed ? 0 : val);
1019}
1020
1021static int
1022ed_miibus_writereg(device_t dev, int phy, int reg, int data)
1023{
1024	struct ed_softc *sc;
1025
1026	/*
1027	 * The AX88790 seem to have phy 0..f external, and 0x10 internal.
1028	 * but they also seem to have a bogus one that shows up at phy
1029	 * 0x11 through 0x1f.
1030	 */
1031	if (phy >= 0x11)
1032		return (0);
1033
1034	sc = device_get_softc(dev);
1035	(*sc->mii_writebits)(sc, 0xffffffff, 32);
1036	(*sc->mii_writebits)(sc, ED_MII_STARTDELIM, ED_MII_STARTDELIM_BITS);
1037	(*sc->mii_writebits)(sc, ED_MII_WRITEOP, ED_MII_OP_BITS);
1038	(*sc->mii_writebits)(sc, phy, ED_MII_PHY_BITS);
1039	(*sc->mii_writebits)(sc, reg, ED_MII_REG_BITS);
1040	(*sc->mii_writebits)(sc, ED_MII_TURNAROUND, ED_MII_TURNAROUND_BITS);
1041	(*sc->mii_writebits)(sc, data, ED_MII_DATA_BITS);
1042	(*sc->mii_writebits)(sc, ED_MII_IDLE, ED_MII_IDLE_BITS);
1043	return (0);
1044}
1045
1046static int
1047ed_ifmedia_upd(struct ifnet *ifp)
1048{
1049	struct ed_softc *sc;
1050	struct mii_data *mii;
1051
1052	sc = ifp->if_softc;
1053	if (sc->miibus == NULL)
1054		return (ENXIO);
1055
1056	mii = device_get_softc(sc->miibus);
1057	return mii_mediachg(mii);
1058}
1059
1060static void
1061ed_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1062{
1063	struct ed_softc *sc;
1064	struct mii_data *mii;
1065
1066	sc = ifp->if_softc;
1067	if (sc->miibus == NULL)
1068		return;
1069
1070	mii = device_get_softc(sc->miibus);
1071	mii_pollstat(mii);
1072	ifmr->ifm_active = mii->mii_media_active;
1073	ifmr->ifm_status = mii->mii_media_status;
1074}
1075
1076static void
1077ed_child_detached(device_t dev, device_t child)
1078{
1079	struct ed_softc *sc;
1080
1081	sc = device_get_softc(dev);
1082	if (child == sc->miibus)
1083		sc->miibus = NULL;
1084}
1085
1086static device_method_t ed_pccard_methods[] = {
1087	/* Device interface */
1088	DEVMETHOD(device_probe,		ed_pccard_probe),
1089	DEVMETHOD(device_attach,	ed_pccard_attach),
1090	DEVMETHOD(device_detach,	ed_detach),
1091
1092	/* Bus interface */
1093	DEVMETHOD(bus_child_detached,	ed_child_detached),
1094
1095	/* MII interface */
1096	DEVMETHOD(miibus_readreg,	ed_miibus_readreg),
1097	DEVMETHOD(miibus_writereg,	ed_miibus_writereg),
1098
1099	{ 0, 0 }
1100};
1101
1102static driver_t ed_pccard_driver = {
1103	"ed",
1104	ed_pccard_methods,
1105	sizeof(struct ed_softc)
1106};
1107
1108DRIVER_MODULE(ed, pccard, ed_pccard_driver, ed_devclass, 0, 0);
1109DRIVER_MODULE(miibus, ed, miibus_driver, miibus_devclass, 0, 0);
1110MODULE_DEPEND(ed, miibus, 1, 1, 1);
1111MODULE_DEPEND(ed, ether, 1, 1, 1);
1112