xref: /netbsd-src/sys/dev/pci/if_fxp_pci.c (revision 466a16a118933bd295a8a104f095714fadf9cf68)
1 /*	$NetBSD: if_fxp_pci.c,v 1.60 2008/07/09 17:07:28 joerg Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997, 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * PCI bus front-end for the Intel i82557 fast Ethernet controller
35  * driver.  Works with Intel Etherexpress Pro 10+, 100B, 100+ cards.
36  */
37 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: if_fxp_pci.c,v 1.60 2008/07/09 17:07:28 joerg Exp $");
40 
41 #include "rnd.h"
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/mbuf.h>
46 #include <sys/malloc.h>
47 #include <sys/kernel.h>
48 #include <sys/socket.h>
49 #include <sys/ioctl.h>
50 #include <sys/errno.h>
51 #include <sys/device.h>
52 
53 #if NRND > 0
54 #include <sys/rnd.h>
55 #endif
56 
57 #include <machine/endian.h>
58 
59 #include <net/if.h>
60 #include <net/if_dl.h>
61 #include <net/if_media.h>
62 #include <net/if_ether.h>
63 
64 #include <sys/bus.h>
65 #include <sys/intr.h>
66 
67 #include <dev/mii/miivar.h>
68 
69 #include <dev/ic/i82557reg.h>
70 #include <dev/ic/i82557var.h>
71 
72 #include <dev/pci/pcivar.h>
73 #include <dev/pci/pcireg.h>
74 #include <dev/pci/pcidevs.h>
75 
76 struct fxp_pci_softc {
77 	struct fxp_softc psc_fxp;
78 
79 	pci_chipset_tag_t psc_pc;	/* pci chipset tag */
80 	pcireg_t psc_regs[0x20>>2];	/* saved PCI config regs (sparse) */
81 	pcitag_t psc_tag;		/* pci register tag */
82 
83 	int psc_pwrmgmt_csr_reg;	/* ACPI power management register */
84 	pcireg_t psc_pwrmgmt_csr;	/* ...and the contents at D0 */
85 	struct pci_conf_state psc_pciconf; /* standard PCI configuration regs */
86 };
87 
88 static int	fxp_pci_match(device_t, cfdata_t, void *);
89 static void	fxp_pci_attach(device_t, device_t, void *);
90 
91 static int	fxp_pci_enable(struct fxp_softc *);
92 static void	fxp_pci_disable(struct fxp_softc *);
93 
94 static void fxp_pci_confreg_restore(struct fxp_pci_softc *psc);
95 static bool fxp_pci_resume(device_t dv PMF_FN_PROTO);
96 
97 CFATTACH_DECL_NEW(fxp_pci, sizeof(struct fxp_pci_softc),
98     fxp_pci_match, fxp_pci_attach, NULL, NULL);
99 
100 static const struct fxp_pci_product {
101 	u_int32_t	fpp_prodid;	/* PCI product ID */
102 	const char	*fpp_name;	/* device name */
103 } fxp_pci_products[] = {
104 	{ PCI_PRODUCT_INTEL_82557,
105 	  "Intel i82557 Ethernet" },
106 	{ PCI_PRODUCT_INTEL_82559ER,
107 	  "Intel i82559ER Ethernet" },
108 	{ PCI_PRODUCT_INTEL_IN_BUSINESS,
109 	  "Intel InBusiness Ethernet" },
110 	{ PCI_PRODUCT_INTEL_82801BA_LAN,
111 	  "Intel i82562 Ethernet" },
112 	{ PCI_PRODUCT_INTEL_82801E_LAN_1,
113 	  "Intel i82559 Ethernet" },
114 	{ PCI_PRODUCT_INTEL_82801E_LAN_2,
115 	  "Intel i82559 Ethernet" },
116 	{ PCI_PRODUCT_INTEL_PRO_100_VE_0,
117 	  "Intel PRO/100 VE Network Controller" },
118 	{ PCI_PRODUCT_INTEL_PRO_100_VE_1,
119 	  "Intel PRO/100 VE Network Controller" },
120 	{ PCI_PRODUCT_INTEL_PRO_100_VE_2,
121 	  "Intel PRO/100 VE Network Controller with 82562ET/EZ PHY" },
122 	{ PCI_PRODUCT_INTEL_PRO_100_VE_3,
123 	  "Intel PRO/100 VE Network Controller with 82562ET/EZ (CNR) PHY" },
124 	{ PCI_PRODUCT_INTEL_PRO_100_VE_4,
125 	  "Intel PRO/100 VE (MOB) Network Controller" },
126 	{ PCI_PRODUCT_INTEL_PRO_100_VE_5,
127 	  "Intel PRO/100 VE (LOM) Network Controller" },
128 	{ PCI_PRODUCT_INTEL_PRO_100_VE_6,
129 	  "Intel PRO/100 VE Network Controller" },
130 	{ PCI_PRODUCT_INTEL_PRO_100_VE_7,
131 	  "Intel PRO/100 VE Network Controller" },
132 	{ PCI_PRODUCT_INTEL_PRO_100_VE_8,
133 	  "Intel PRO/100 VE Network Controller" },
134 	{ PCI_PRODUCT_INTEL_PRO_100_VM_0,
135 	  "Intel PRO/100 VM Network Controller" },
136 	{ PCI_PRODUCT_INTEL_PRO_100_VM_1,
137 	  "Intel PRO/100 VM Network Controller" },
138 	{ PCI_PRODUCT_INTEL_PRO_100_VM_2,
139 	  "Intel PRO/100 VM Network Controller" },
140 	{ PCI_PRODUCT_INTEL_PRO_100_VM_3,
141 	  "Intel PRO/100 VM Network Controller with 82562EM/EX PHY" },
142 	{ PCI_PRODUCT_INTEL_PRO_100_VM_4,
143 	  "Intel PRO/100 VM Network Controller with 82562EM/EX (CNR) PHY" },
144 	{ PCI_PRODUCT_INTEL_PRO_100_VM_5,
145 	  "Intel PRO/100 VM (MOB) Network Controller" },
146 	{ PCI_PRODUCT_INTEL_PRO_100_VM_6,
147 	  "Intel PRO/100 VM Network Controller with 82562ET/EZ PHY" },
148 	{ PCI_PRODUCT_INTEL_PRO_100_M,
149 	  "Intel PRO/100 M Network Controller" },
150 	{ PCI_PRODUCT_INTEL_82801EB_LAN,
151 	  "Intel 82801EB/ER (ICH5) Network Controller" },
152 	{ PCI_PRODUCT_INTEL_82801FB_LAN,
153 	  "Intel 82562EZ (ICH6)" },
154 	{ PCI_PRODUCT_INTEL_82801G_LAN,
155 	  "Intel 82801GB/GR (ICH7) Network Controller" },
156 	{ PCI_PRODUCT_INTEL_82801GB_LAN,
157 	  "Intel 82801GB 10/100 Network Controller" },
158 	{ 0,
159 	  NULL },
160 };
161 
162 static const struct fxp_pci_product *
163 fxp_pci_lookup(const struct pci_attach_args *pa)
164 {
165 	const struct fxp_pci_product *fpp;
166 
167 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
168 		return (NULL);
169 
170 	for (fpp = fxp_pci_products; fpp->fpp_name != NULL; fpp++)
171 		if (PCI_PRODUCT(pa->pa_id) == fpp->fpp_prodid)
172 			return (fpp);
173 
174 	return (NULL);
175 }
176 
177 static int
178 fxp_pci_match(device_t parent, cfdata_t match, void *aux)
179 {
180 	struct pci_attach_args *pa = aux;
181 
182 	if (fxp_pci_lookup(pa) != NULL)
183 		return (1);
184 
185 	return (0);
186 }
187 
188 /*
189  * On resume : (XXX it is necessary with new pmf framework ?)
190  * Restore PCI configuration registers that may have been clobbered.
191  * This is necessary due to bugs on the Sony VAIO Z505-series on-board
192  * ethernet, after an APM suspend/resume, as well as after an ACPI
193  * D3->D0 transition.  We call this function from a power hook after
194  * APM resume events, as well as after the ACPI D3->D0 transition.
195  */
196 static void
197 fxp_pci_confreg_restore(struct fxp_pci_softc *psc)
198 {
199 	pcireg_t reg;
200 
201 #if 0
202 	/*
203 	 * Check to see if the command register is blank -- if so, then
204 	 * we'll assume that all the clobberable-registers have been
205 	 * clobbered.
206 	 */
207 
208 	/*
209 	 * In general, the above metric is accurate. Unfortunately,
210 	 * it is inaccurate across a hibernation. Ideally APM/ACPI
211 	 * code should take note of hibernation events and execute
212 	 * a hibernation wakeup hook, but at present a hibernation wake
213 	 * is indistinguishable from a suspend wake.
214 	 */
215 
216 	if (((reg = pci_conf_read(psc->psc_pc, psc->psc_tag,
217 	    PCI_COMMAND_STATUS_REG)) & 0xffff) != 0)
218 		return;
219 #else
220 	reg = pci_conf_read(psc->psc_pc, psc->psc_tag, PCI_COMMAND_STATUS_REG);
221 #endif
222 
223 	pci_conf_write(psc->psc_pc, psc->psc_tag,
224 	    PCI_COMMAND_STATUS_REG,
225 	    (reg & 0xffff0000) |
226 	    (psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] & 0xffff));
227 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_BHLC_REG,
228 	    psc->psc_regs[PCI_BHLC_REG>>2]);
229 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_MAPREG_START+0x0,
230 	    psc->psc_regs[(PCI_MAPREG_START+0x0)>>2]);
231 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_MAPREG_START+0x4,
232 	    psc->psc_regs[(PCI_MAPREG_START+0x4)>>2]);
233 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_MAPREG_START+0x8,
234 	    psc->psc_regs[(PCI_MAPREG_START+0x8)>>2]);
235 }
236 
237 static bool
238 fxp_pci_resume(device_t dv PMF_FN_ARGS)
239 {
240 	struct fxp_pci_softc *psc = device_private(dv);
241 	fxp_pci_confreg_restore(psc);
242 
243 	return true;
244 }
245 
246 static void
247 fxp_pci_attach(device_t parent, device_t self, void *aux)
248 {
249 	struct fxp_pci_softc *psc = device_private(self);
250 	struct fxp_softc *sc = &psc->psc_fxp;
251 	struct pci_attach_args *pa = aux;
252 	pci_chipset_tag_t pc = pa->pa_pc;
253 	pci_intr_handle_t ih;
254 	const struct fxp_pci_product *fpp;
255 	const char *intrstr = NULL;
256 	bus_space_tag_t iot, memt;
257 	bus_space_handle_t ioh, memh;
258 	int ioh_valid, memh_valid;
259 	bus_addr_t addr;
260 	bus_size_t size;
261 	int flags;
262 	int error;
263 
264 	sc->sc_dev = self;
265 
266 	aprint_naive(": Ethernet controller\n");
267 
268 	/*
269 	 * Map control/status registers.
270 	 */
271 	ioh_valid = (pci_mapreg_map(pa, FXP_PCI_IOBA,
272 	    PCI_MAPREG_TYPE_IO, 0,
273 	    &iot, &ioh, NULL, NULL) == 0);
274 
275 	/*
276 	 * Version 2.1 of the PCI spec, page 196, "Address Maps":
277 	 *
278 	 *	Prefetchable
279 	 *
280 	 *	Set to one if there are no side effects on reads, the
281 	 *	device returns all bytes regardless of the byte enables,
282 	 *	and host bridges can merge processor writes into this
283 	 *	range without causing errors.  Bit must be set to zero
284 	 *	otherwise.
285 	 *
286 	 * The 82557 incorrectly sets the "prefetchable" bit, resulting
287 	 * in errors on systems which will do merged reads and writes.
288 	 * These errors manifest themselves as all-bits-set when reading
289 	 * from the EEPROM or other < 4 byte registers.
290 	 *
291 	 * We must work around this problem by always forcing the mapping
292 	 * for memory space to be uncacheable.  On systems which cannot
293 	 * create an uncacheable mapping (because the firmware mapped it
294 	 * into only cacheable/prefetchable space due to the "prefetchable"
295 	 * bit), we can fall back onto i/o mapped access.
296 	 */
297 	memh_valid = 0;
298 	memt = pa->pa_memt;
299 	if (((pa->pa_flags & PCI_FLAGS_MEM_ENABLED) != 0) &&
300 	    pci_mapreg_info(pa->pa_pc, pa->pa_tag, FXP_PCI_MMBA,
301 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
302 	    &addr, &size, &flags) == 0) {
303 		flags &= ~BUS_SPACE_MAP_PREFETCHABLE;
304 		if (bus_space_map(memt, addr, size, flags, &memh) == 0)
305 			memh_valid = 1;
306 	}
307 
308 	if (memh_valid) {
309 		sc->sc_st = memt;
310 		sc->sc_sh = memh;
311 	} else if (ioh_valid) {
312 		sc->sc_st = iot;
313 		sc->sc_sh = ioh;
314 	} else {
315 		aprint_error(": unable to map device registers\n");
316 		return;
317 	}
318 
319 	sc->sc_dmat = pa->pa_dmat;
320 
321 	fpp = fxp_pci_lookup(pa);
322 	if (fpp == NULL) {
323 		printf("\n");
324 		panic("fxp_pci_attach: impossible");
325 	}
326 
327 	sc->sc_rev = PCI_REVISION(pa->pa_class);
328 
329 	switch (fpp->fpp_prodid) {
330 	case PCI_PRODUCT_INTEL_82557:
331 	case PCI_PRODUCT_INTEL_82559ER:
332 	case PCI_PRODUCT_INTEL_IN_BUSINESS:
333 	    {
334 		const char *chipname = NULL;
335 
336 		if (sc->sc_rev >= FXP_REV_82558_A4) {
337 			chipname = "i82558 Ethernet";
338 			/*
339 			 * Enable the MWI command for memory writes.
340 			 */
341 			if (pa->pa_flags & PCI_FLAGS_MWI_OKAY)
342 				sc->sc_flags |= FXPF_MWI;
343 		}
344 		if (sc->sc_rev >= FXP_REV_82559_A0)
345 			chipname = "i82559 Ethernet";
346 		if (sc->sc_rev >= FXP_REV_82559S_A)
347 			chipname = "i82559S Ethernet";
348 		if (sc->sc_rev >= FXP_REV_82550)
349 			chipname = "i82550 Ethernet";
350 
351 		/*
352 		 * Mark all i82559 and i82550 revisions as having
353 		 * the "resume bug".  See i82557.c for details.
354 		 */
355 		if (sc->sc_rev >= FXP_REV_82559_A0)
356 			sc->sc_flags |= FXPF_HAS_RESUME_BUG;
357 
358 		aprint_normal(": %s, rev %d\n", chipname != NULL ? chipname :
359 		    fpp->fpp_name, sc->sc_rev);
360 		break;
361 	    }
362 
363 	case PCI_PRODUCT_INTEL_82801BA_LAN:
364 		aprint_normal(": %s, rev %d\n", fpp->fpp_name, sc->sc_rev);
365 
366 		/*
367 		 * The 82801BA Ethernet has a bug which requires us to send a
368 		 * NOP before a CU_RESUME if we're in 10baseT mode.
369 		 */
370 		if (fpp->fpp_prodid == PCI_PRODUCT_INTEL_82801BA_LAN)
371 			sc->sc_flags |= FXPF_HAS_RESUME_BUG;
372 		break;
373 
374 	case PCI_PRODUCT_INTEL_PRO_100_VE_0:
375 	case PCI_PRODUCT_INTEL_PRO_100_VE_1:
376 	case PCI_PRODUCT_INTEL_PRO_100_VM_0:
377 	case PCI_PRODUCT_INTEL_PRO_100_VM_1:
378 	case PCI_PRODUCT_INTEL_82562EH_HPNA_0:
379 	case PCI_PRODUCT_INTEL_82562EH_HPNA_1:
380 	case PCI_PRODUCT_INTEL_82562EH_HPNA_2:
381 	case PCI_PRODUCT_INTEL_PRO_100_VM_2:
382 		aprint_normal(": %s, rev %d\n", fpp->fpp_name, sc->sc_rev);
383 
384 		/*
385 		 * ICH3 chips apparently have problems with the enhanced
386 		 * features, so just treat them as an i82557.  It also
387 		 * has the resume bug that the ICH2 has.
388 		 */
389 		sc->sc_rev = 1;
390 		sc->sc_flags |= FXPF_HAS_RESUME_BUG;
391 		break;
392 	case PCI_PRODUCT_INTEL_82801E_LAN_1:
393 	case PCI_PRODUCT_INTEL_82801E_LAN_2:
394 		aprint_normal(": %s, rev %d\n", fpp->fpp_name, sc->sc_rev);
395 
396 		/*
397 		 *  XXX We have to read the C-ICH's developer's manual
398 		 *  in detail
399 		 */
400 		break;
401 	case PCI_PRODUCT_INTEL_PRO_100_VE_2:
402 	case PCI_PRODUCT_INTEL_PRO_100_VE_3:
403 	case PCI_PRODUCT_INTEL_PRO_100_VE_4:
404 	case PCI_PRODUCT_INTEL_PRO_100_VE_5:
405 	case PCI_PRODUCT_INTEL_PRO_100_VM_3:
406 	case PCI_PRODUCT_INTEL_PRO_100_VM_4:
407 	case PCI_PRODUCT_INTEL_PRO_100_VM_5:
408 	case PCI_PRODUCT_INTEL_PRO_100_VM_6:
409 	case PCI_PRODUCT_INTEL_82801EB_LAN:
410 	case PCI_PRODUCT_INTEL_82801FB_LAN:
411 	case PCI_PRODUCT_INTEL_82801G_LAN:
412 	default:
413 		aprint_normal(": %s, rev %d\n", fpp->fpp_name, sc->sc_rev);
414 
415 		/*
416 		 * No particular quirks.
417 		 */
418 		break;
419 	}
420 
421 	/* Make sure bus-mastering is enabled. */
422 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
423 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
424 	    PCI_COMMAND_MASTER_ENABLE);
425 
426   	/*
427 	 * Under some circumstances (such as APM suspend/resume
428 	 * cycles, and across ACPI power state changes), the
429 	 * i82257-family can lose the contents of critical PCI
430 	 * configuration registers, causing the card to be
431 	 * non-responsive and useless.  This occurs on the Sony VAIO
432 	 * Z505-series, among others.  Preserve them here so they can
433 	 * be later restored (by fxp_pci_confreg_restore()).
434 	 */
435 	psc->psc_pc = pc;
436 	psc->psc_tag = pa->pa_tag;
437 	psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] =
438 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
439 	psc->psc_regs[PCI_BHLC_REG>>2] =
440 	    pci_conf_read(pc, pa->pa_tag, PCI_BHLC_REG);
441 	psc->psc_regs[(PCI_MAPREG_START+0x0)>>2] =
442 	    pci_conf_read(pc, pa->pa_tag, PCI_MAPREG_START+0x0);
443 	psc->psc_regs[(PCI_MAPREG_START+0x4)>>2] =
444 	    pci_conf_read(pc, pa->pa_tag, PCI_MAPREG_START+0x4);
445 	psc->psc_regs[(PCI_MAPREG_START+0x8)>>2] =
446 	    pci_conf_read(pc, pa->pa_tag, PCI_MAPREG_START+0x8);
447 
448 	/* power up chip */
449 	switch ((error = pci_activate(pa->pa_pc, pa->pa_tag, self,
450 	    pci_activate_null))) {
451 	case EOPNOTSUPP:
452 		break;
453 	case 0:
454 		sc->sc_enable = fxp_pci_enable;
455 		sc->sc_disable = fxp_pci_disable;
456 		break;
457 	default:
458 		aprint_error_dev(self, "cannot activate %d\n", error);
459 		return;
460 	}
461 
462 	/* Restore PCI configuration registers. */
463 	fxp_pci_confreg_restore(psc);
464 
465 	sc->sc_enabled = 1;
466 
467 	/*
468 	 * Map and establish our interrupt.
469 	 */
470 	if (pci_intr_map(pa, &ih)) {
471 		aprint_error_dev(self, "couldn't map interrupt\n");
472 		return;
473 	}
474 	intrstr = pci_intr_string(pc, ih);
475 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc);
476 	if (sc->sc_ih == NULL) {
477 		aprint_error_dev(self, "couldn't establish interrupt");
478 		if (intrstr != NULL)
479 			aprint_normal(" at %s", intrstr);
480 		aprint_normal("\n");
481 		return;
482 	}
483 	aprint_normal_dev(self, "interrupting at %s\n", intrstr);
484 
485 	/* Finish off the attach. */
486 	fxp_attach(sc);
487 	if (sc->sc_disable != NULL)
488 		fxp_disable(sc);
489 
490 	/* Add a suspend hook to restore PCI config state */
491 	if (!pmf_device_register(self, NULL, fxp_pci_resume))
492 		aprint_error_dev(self, "couldn't establish power handler\n");
493 	else
494 		pmf_class_network_register(self, &sc->sc_ethercom.ec_if);
495 }
496 
497 static int
498 fxp_pci_enable(struct fxp_softc *sc)
499 {
500 	struct fxp_pci_softc *psc = (void *) sc;
501 
502 #if 0
503 	printf("%s: going to power state D0\n", device_xname(self));
504 #endif
505 
506 	/* Bring the device into D0 power state. */
507 	pci_conf_write(psc->psc_pc, psc->psc_tag,
508 	    psc->psc_pwrmgmt_csr_reg, psc->psc_pwrmgmt_csr);
509 
510 	/* Now restore the configuration registers. */
511 	fxp_pci_confreg_restore(psc);
512 
513 	return (0);
514 }
515 
516 static void
517 fxp_pci_disable(struct fxp_softc *sc)
518 {
519 	struct fxp_pci_softc *psc = (void *) sc;
520 
521 	/*
522 	 * for some 82558_A4 and 82558_B0, entering D3 state makes
523 	 * media detection disordered.
524 	 */
525 	if (sc->sc_rev <= FXP_REV_82558_B0)
526 		return;
527 
528 #if 0
529 	printf("%s: going to power state D3\n", device_xname(self));
530 #endif
531 
532 	/* Put the device into D3 state. */
533 	pci_conf_write(psc->psc_pc, psc->psc_tag,
534 	    psc->psc_pwrmgmt_csr_reg, (psc->psc_pwrmgmt_csr &
535 	    ~PCI_PMCSR_STATE_MASK) | PCI_PMCSR_STATE_D3);
536 }
537