Tue Jan 7 13:14:39 2014 UTC ()
 Insert completion barrier between register write and delay().
One exception is chip reset (to avoid hangup).


(msaitoh)
diff -r1.265 -r1.266 src/sys/dev/pci/if_wm.c

cvs diff -r1.265 -r1.266 src/sys/dev/pci/if_wm.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_wm.c 2013/12/29 21:28:41 1.265
+++ src/sys/dev/pci/if_wm.c 2014/01/07 13:14:39 1.266
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_wm.c,v 1.265 2013/12/29 21:28:41 msaitoh Exp $ */ 1/* $NetBSD: if_wm.c,v 1.266 2014/01/07 13:14:39 msaitoh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. 4 * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -66,27 +66,27 @@ @@ -66,27 +66,27 @@
66 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 66 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67 POSSIBILITY OF SUCH DAMAGE. 67 POSSIBILITY OF SUCH DAMAGE.
68 68
69*******************************************************************************/ 69*******************************************************************************/
70/* 70/*
71 * Device driver for the Intel i8254x family of Gigabit Ethernet chips. 71 * Device driver for the Intel i8254x family of Gigabit Ethernet chips.
72 * 72 *
73 * TODO (in order of importance): 73 * TODO (in order of importance):
74 * 74 *
75 * - Rework how parameters are loaded from the EEPROM. 75 * - Rework how parameters are loaded from the EEPROM.
76 */ 76 */
77 77
78#include <sys/cdefs.h> 78#include <sys/cdefs.h>
79__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.265 2013/12/29 21:28:41 msaitoh Exp $"); 79__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.266 2014/01/07 13:14:39 msaitoh Exp $");
80 80
81#include <sys/param.h> 81#include <sys/param.h>
82#include <sys/systm.h> 82#include <sys/systm.h>
83#include <sys/callout.h> 83#include <sys/callout.h>
84#include <sys/mbuf.h> 84#include <sys/mbuf.h>
85#include <sys/malloc.h> 85#include <sys/malloc.h>
86#include <sys/kernel.h> 86#include <sys/kernel.h>
87#include <sys/socket.h> 87#include <sys/socket.h>
88#include <sys/ioctl.h> 88#include <sys/ioctl.h>
89#include <sys/errno.h> 89#include <sys/errno.h>
90#include <sys/device.h> 90#include <sys/device.h>
91#include <sys/queue.h> 91#include <sys/queue.h>
92#include <sys/syslog.h> 92#include <sys/syslog.h>
@@ -4116,52 +4116,54 @@ wm_reset(struct wm_softc *sc) @@ -4116,52 +4116,54 @@ wm_reset(struct wm_softc *sc)
4116 } 4116 }
4117 } 4117 }
4118 4118
4119 /* Set the completion timeout for interface */ 4119 /* Set the completion timeout for interface */
4120 if ((sc->sc_type == WM_T_82575) || (sc->sc_type == WM_T_82576) 4120 if ((sc->sc_type == WM_T_82575) || (sc->sc_type == WM_T_82576)
4121 || (sc->sc_type == WM_T_I350) || (sc->sc_type == WM_T_I354)) 4121 || (sc->sc_type == WM_T_I350) || (sc->sc_type == WM_T_I354))
4122 wm_set_pcie_completion_timeout(sc); 4122 wm_set_pcie_completion_timeout(sc);
4123 4123
4124 /* Clear interrupt */ 4124 /* Clear interrupt */
4125 CSR_WRITE(sc, WMREG_IMC, 0xffffffffU); 4125 CSR_WRITE(sc, WMREG_IMC, 0xffffffffU);
4126 4126
4127 /* Stop the transmit and receive processes. */ 4127 /* Stop the transmit and receive processes. */
4128 CSR_WRITE(sc, WMREG_RCTL, 0); 4128 CSR_WRITE(sc, WMREG_RCTL, 0);
4129 CSR_WRITE(sc, WMREG_TCTL, TCTL_PSP); 
4130 sc->sc_rctl &= ~RCTL_EN; 4129 sc->sc_rctl &= ~RCTL_EN;
 4130 CSR_WRITE(sc, WMREG_TCTL, TCTL_PSP);
 4131 CSR_WRITE_FLUSH(sc);
4131 4132
4132 /* XXX set_tbi_sbp_82543() */ 4133 /* XXX set_tbi_sbp_82543() */
4133 4134
4134 delay(10*1000); 4135 delay(10*1000);
4135 4136
4136 /* Must acquire the MDIO ownership before MAC reset */ 4137 /* Must acquire the MDIO ownership before MAC reset */
4137 switch (sc->sc_type) { 4138 switch (sc->sc_type) {
4138 case WM_T_82573: 4139 case WM_T_82573:
4139 case WM_T_82574: 4140 case WM_T_82574:
4140 case WM_T_82583: 4141 case WM_T_82583:
4141 wm_get_hw_semaphore_82573(sc); 4142 wm_get_hw_semaphore_82573(sc);
4142 break; 4143 break;
4143 default: 4144 default:
4144 break; 4145 break;
4145 } 4146 }
4146 4147
4147 /* 4148 /*
4148 * 82541 Errata 29? & 82547 Errata 28? 4149 * 82541 Errata 29? & 82547 Errata 28?
4149 * See also the description about PHY_RST bit in CTRL register 4150 * See also the description about PHY_RST bit in CTRL register
4150 * in 8254x_GBe_SDM.pdf. 4151 * in 8254x_GBe_SDM.pdf.
4151 */ 4152 */
4152 if ((sc->sc_type == WM_T_82541) || (sc->sc_type == WM_T_82547)) { 4153 if ((sc->sc_type == WM_T_82541) || (sc->sc_type == WM_T_82547)) {
4153 CSR_WRITE(sc, WMREG_CTRL, 4154 CSR_WRITE(sc, WMREG_CTRL,
4154 CSR_READ(sc, WMREG_CTRL) | CTRL_PHY_RESET); 4155 CSR_READ(sc, WMREG_CTRL) | CTRL_PHY_RESET);
 4156 CSR_WRITE_FLUSH(sc);
4155 delay(5000); 4157 delay(5000);
4156 } 4158 }
4157 4159
4158 switch (sc->sc_type) { 4160 switch (sc->sc_type) {
4159 case WM_T_82544: /* XXX check whether WM_F_IOH_VALID is set */ 4161 case WM_T_82544: /* XXX check whether WM_F_IOH_VALID is set */
4160 case WM_T_82541: 4162 case WM_T_82541:
4161 case WM_T_82541_2: 4163 case WM_T_82541_2:
4162 case WM_T_82547: 4164 case WM_T_82547:
4163 case WM_T_82547_2: 4165 case WM_T_82547_2:
4164 /* 4166 /*
4165 * On some chipsets, a reset through a memory-mapped write 4167 * On some chipsets, a reset through a memory-mapped write
4166 * cycle can cause the chip to reset before completing the 4168 * cycle can cause the chip to reset before completing the
4167 * write cycle. This causes major headache that can be 4169 * write cycle. This causes major headache that can be
@@ -4202,26 +4204,27 @@ wm_reset(struct wm_softc *sc) @@ -4202,26 +4204,27 @@ wm_reset(struct wm_softc *sc)
4202 * non-managed 82579 4204 * non-managed 82579
4203 */ 4205 */
4204 if ((sc->sc_type == WM_T_PCH2) 4206 if ((sc->sc_type == WM_T_PCH2)
4205 && ((CSR_READ(sc, WMREG_FWSM) & FWSM_FW_VALID) 4207 && ((CSR_READ(sc, WMREG_FWSM) & FWSM_FW_VALID)
4206 != 0)) 4208 != 0))
4207 wm_gate_hw_phy_config_ich8lan(sc, 1); 4209 wm_gate_hw_phy_config_ich8lan(sc, 1);
4208 4210
4209 4211
4210 reg |= CTRL_PHY_RESET; 4212 reg |= CTRL_PHY_RESET;
4211 phy_reset = 1; 4213 phy_reset = 1;
4212 } 4214 }
4213 wm_get_swfwhw_semaphore(sc); 4215 wm_get_swfwhw_semaphore(sc);
4214 CSR_WRITE(sc, WMREG_CTRL, reg); 4216 CSR_WRITE(sc, WMREG_CTRL, reg);
 4217 /* Don't insert a completion barrier when reset */
4215 delay(20*1000); 4218 delay(20*1000);
4216 wm_put_swfwhw_semaphore(sc); 4219 wm_put_swfwhw_semaphore(sc);
4217 break; 4220 break;
4218 case WM_T_82542_2_0: 4221 case WM_T_82542_2_0:
4219 case WM_T_82542_2_1: 4222 case WM_T_82542_2_1:
4220 case WM_T_82543: 4223 case WM_T_82543:
4221 case WM_T_82540: 4224 case WM_T_82540:
4222 case WM_T_82545: 4225 case WM_T_82545:
4223 case WM_T_82546: 4226 case WM_T_82546:
4224 case WM_T_82571: 4227 case WM_T_82571:
4225 case WM_T_82572: 4228 case WM_T_82572:
4226 case WM_T_82573: 4229 case WM_T_82573:
4227 case WM_T_82574: 4230 case WM_T_82574:
@@ -4252,52 +4255,54 @@ wm_reset(struct wm_softc *sc) @@ -4252,52 +4255,54 @@ wm_reset(struct wm_softc *sc)
4252 4255
4253 if (phy_reset != 0) 4256 if (phy_reset != 0)
4254 wm_get_cfg_done(sc); 4257 wm_get_cfg_done(sc);
4255 4258
4256 /* reload EEPROM */ 4259 /* reload EEPROM */
4257 switch (sc->sc_type) { 4260 switch (sc->sc_type) {
4258 case WM_T_82542_2_0: 4261 case WM_T_82542_2_0:
4259 case WM_T_82542_2_1: 4262 case WM_T_82542_2_1:
4260 case WM_T_82543: 4263 case WM_T_82543:
4261 case WM_T_82544: 4264 case WM_T_82544:
4262 delay(10); 4265 delay(10);
4263 reg = CSR_READ(sc, WMREG_CTRL_EXT) | CTRL_EXT_EE_RST; 4266 reg = CSR_READ(sc, WMREG_CTRL_EXT) | CTRL_EXT_EE_RST;
4264 CSR_WRITE(sc, WMREG_CTRL_EXT, reg); 4267 CSR_WRITE(sc, WMREG_CTRL_EXT, reg);
 4268 CSR_WRITE_FLUSH(sc);
4265 delay(2000); 4269 delay(2000);
4266 break; 4270 break;
4267 case WM_T_82540: 4271 case WM_T_82540:
4268 case WM_T_82545: 4272 case WM_T_82545:
4269 case WM_T_82545_3: 4273 case WM_T_82545_3:
4270 case WM_T_82546: 4274 case WM_T_82546:
4271 case WM_T_82546_3: 4275 case WM_T_82546_3:
4272 delay(5*1000); 4276 delay(5*1000);
4273 /* XXX Disable HW ARPs on ASF enabled adapters */ 4277 /* XXX Disable HW ARPs on ASF enabled adapters */
4274 break; 4278 break;
4275 case WM_T_82541: 4279 case WM_T_82541:
4276 case WM_T_82541_2: 4280 case WM_T_82541_2:
4277 case WM_T_82547: 4281 case WM_T_82547:
4278 case WM_T_82547_2: 4282 case WM_T_82547_2:
4279 delay(20000); 4283 delay(20000);
4280 /* XXX Disable HW ARPs on ASF enabled adapters */ 4284 /* XXX Disable HW ARPs on ASF enabled adapters */
4281 break; 4285 break;
4282 case WM_T_82571: 4286 case WM_T_82571:
4283 case WM_T_82572: 4287 case WM_T_82572:
4284 case WM_T_82573: 4288 case WM_T_82573:
4285 case WM_T_82574: 4289 case WM_T_82574:
4286 case WM_T_82583: 4290 case WM_T_82583:
4287 if (sc->sc_flags & WM_F_EEPROM_FLASH) { 4291 if (sc->sc_flags & WM_F_EEPROM_FLASH) {
4288 delay(10); 4292 delay(10);
4289 reg = CSR_READ(sc, WMREG_CTRL_EXT) | CTRL_EXT_EE_RST; 4293 reg = CSR_READ(sc, WMREG_CTRL_EXT) | CTRL_EXT_EE_RST;
4290 CSR_WRITE(sc, WMREG_CTRL_EXT, reg); 4294 CSR_WRITE(sc, WMREG_CTRL_EXT, reg);
 4295 CSR_WRITE_FLUSH(sc);
4291 } 4296 }
4292 /* check EECD_EE_AUTORD */ 4297 /* check EECD_EE_AUTORD */
4293 wm_get_auto_rd_done(sc); 4298 wm_get_auto_rd_done(sc);
4294 /* 4299 /*
4295 * Phy configuration from NVM just starts after EECD_AUTO_RD 4300 * Phy configuration from NVM just starts after EECD_AUTO_RD
4296 * is set. 4301 * is set.
4297 */ 4302 */
4298 if ((sc->sc_type == WM_T_82573) || (sc->sc_type == WM_T_82574) 4303 if ((sc->sc_type == WM_T_82573) || (sc->sc_type == WM_T_82574)
4299 || (sc->sc_type == WM_T_82583)) 4304 || (sc->sc_type == WM_T_82583))
4300 delay(25*1000); 4305 delay(25*1000);
4301 break; 4306 break;
4302 case WM_T_82575: 4307 case WM_T_82575:
4303 case WM_T_82576: 4308 case WM_T_82576:
@@ -5199,54 +5204,59 @@ static void @@ -5199,54 +5204,59 @@ static void
5199wm_eeprom_sendbits(struct wm_softc *sc, uint32_t bits, int nbits) 5204wm_eeprom_sendbits(struct wm_softc *sc, uint32_t bits, int nbits)
5200{ 5205{
5201 uint32_t reg; 5206 uint32_t reg;
5202 int x; 5207 int x;
5203 5208
5204 reg = CSR_READ(sc, WMREG_EECD); 5209 reg = CSR_READ(sc, WMREG_EECD);
5205 5210
5206 for (x = nbits; x > 0; x--) { 5211 for (x = nbits; x > 0; x--) {
5207 if (bits & (1U << (x - 1))) 5212 if (bits & (1U << (x - 1)))
5208 reg |= EECD_DI; 5213 reg |= EECD_DI;
5209 else 5214 else
5210 reg &= ~EECD_DI; 5215 reg &= ~EECD_DI;
5211 CSR_WRITE(sc, WMREG_EECD, reg); 5216 CSR_WRITE(sc, WMREG_EECD, reg);
 5217 CSR_WRITE_FLUSH(sc);
5212 delay(2); 5218 delay(2);
5213 CSR_WRITE(sc, WMREG_EECD, reg | EECD_SK); 5219 CSR_WRITE(sc, WMREG_EECD, reg | EECD_SK);
 5220 CSR_WRITE_FLUSH(sc);
5214 delay(2); 5221 delay(2);
5215 CSR_WRITE(sc, WMREG_EECD, reg); 5222 CSR_WRITE(sc, WMREG_EECD, reg);
 5223 CSR_WRITE_FLUSH(sc);
5216 delay(2); 5224 delay(2);
5217 } 5225 }
5218} 5226}
5219 5227
5220/* 5228/*
5221 * wm_eeprom_recvbits: 5229 * wm_eeprom_recvbits:
5222 * 5230 *
5223 * Receive a series of bits from the EEPROM. 5231 * Receive a series of bits from the EEPROM.
5224 */ 5232 */
5225static void 5233static void
5226wm_eeprom_recvbits(struct wm_softc *sc, uint32_t *valp, int nbits) 5234wm_eeprom_recvbits(struct wm_softc *sc, uint32_t *valp, int nbits)
5227{ 5235{
5228 uint32_t reg, val; 5236 uint32_t reg, val;
5229 int x; 5237 int x;
5230 5238
5231 reg = CSR_READ(sc, WMREG_EECD) & ~EECD_DI; 5239 reg = CSR_READ(sc, WMREG_EECD) & ~EECD_DI;
5232 5240
5233 val = 0; 5241 val = 0;
5234 for (x = nbits; x > 0; x--) { 5242 for (x = nbits; x > 0; x--) {
5235 CSR_WRITE(sc, WMREG_EECD, reg | EECD_SK); 5243 CSR_WRITE(sc, WMREG_EECD, reg | EECD_SK);
 5244 CSR_WRITE_FLUSH(sc);
5236 delay(2); 5245 delay(2);
5237 if (CSR_READ(sc, WMREG_EECD) & EECD_DO) 5246 if (CSR_READ(sc, WMREG_EECD) & EECD_DO)
5238 val |= (1U << (x - 1)); 5247 val |= (1U << (x - 1));
5239 CSR_WRITE(sc, WMREG_EECD, reg); 5248 CSR_WRITE(sc, WMREG_EECD, reg);
 5249 CSR_WRITE_FLUSH(sc);
5240 delay(2); 5250 delay(2);
5241 } 5251 }
5242 *valp = val; 5252 *valp = val;
5243} 5253}
5244 5254
5245/* 5255/*
5246 * wm_read_eeprom_uwire: 5256 * wm_read_eeprom_uwire:
5247 * 5257 *
5248 * Read a word from the EEPROM using the MicroWire protocol. 5258 * Read a word from the EEPROM using the MicroWire protocol.
5249 */ 5259 */
5250static int 5260static int
5251wm_read_eeprom_uwire(struct wm_softc *sc, int word, int wordcnt, uint16_t *data) 5261wm_read_eeprom_uwire(struct wm_softc *sc, int word, int wordcnt, uint16_t *data)
5252{ 5262{
@@ -5260,48 +5270,51 @@ wm_read_eeprom_uwire(struct wm_softc *sc @@ -5260,48 +5270,51 @@ wm_read_eeprom_uwire(struct wm_softc *sc
5260 5270
5261 /* 5271 /*
5262 * XXX: workaround for a bug in qemu-0.12.x and prior 5272 * XXX: workaround for a bug in qemu-0.12.x and prior
5263 * and Xen. 5273 * and Xen.
5264 * 5274 *
5265 * We use this workaround only for 82540 because qemu's 5275 * We use this workaround only for 82540 because qemu's
5266 * e1000 act as 82540. 5276 * e1000 act as 82540.
5267 */ 5277 */
5268 if (sc->sc_type == WM_T_82540) { 5278 if (sc->sc_type == WM_T_82540) {
5269 reg |= EECD_SK; 5279 reg |= EECD_SK;
5270 CSR_WRITE(sc, WMREG_EECD, reg); 5280 CSR_WRITE(sc, WMREG_EECD, reg);
5271 reg &= ~EECD_SK; 5281 reg &= ~EECD_SK;
5272 CSR_WRITE(sc, WMREG_EECD, reg); 5282 CSR_WRITE(sc, WMREG_EECD, reg);
 5283 CSR_WRITE_FLUSH(sc);
5273 delay(2); 5284 delay(2);
5274 } 5285 }
5275 /* XXX: end of workaround */ 5286 /* XXX: end of workaround */
5276  5287
5277 /* Set CHIP SELECT. */ 5288 /* Set CHIP SELECT. */
5278 reg |= EECD_CS; 5289 reg |= EECD_CS;
5279 CSR_WRITE(sc, WMREG_EECD, reg); 5290 CSR_WRITE(sc, WMREG_EECD, reg);
 5291 CSR_WRITE_FLUSH(sc);
5280 delay(2); 5292 delay(2);
5281 5293
5282 /* Shift in the READ command. */ 5294 /* Shift in the READ command. */
5283 wm_eeprom_sendbits(sc, UWIRE_OPC_READ, 3); 5295 wm_eeprom_sendbits(sc, UWIRE_OPC_READ, 3);
5284 5296
5285 /* Shift in address. */ 5297 /* Shift in address. */
5286 wm_eeprom_sendbits(sc, word + i, sc->sc_ee_addrbits); 5298 wm_eeprom_sendbits(sc, word + i, sc->sc_ee_addrbits);
5287 5299
5288 /* Shift out the data. */ 5300 /* Shift out the data. */
5289 wm_eeprom_recvbits(sc, &val, 16); 5301 wm_eeprom_recvbits(sc, &val, 16);
5290 data[i] = val & 0xffff; 5302 data[i] = val & 0xffff;
5291 5303
5292 /* Clear CHIP SELECT. */ 5304 /* Clear CHIP SELECT. */
5293 reg = CSR_READ(sc, WMREG_EECD) & ~EECD_CS; 5305 reg = CSR_READ(sc, WMREG_EECD) & ~EECD_CS;
5294 CSR_WRITE(sc, WMREG_EECD, reg); 5306 CSR_WRITE(sc, WMREG_EECD, reg);
 5307 CSR_WRITE_FLUSH(sc);
5295 delay(2); 5308 delay(2);
5296 } 5309 }
5297 5310
5298 return 0; 5311 return 0;
5299} 5312}
5300 5313
5301/* 5314/*
5302 * wm_spi_eeprom_ready: 5315 * wm_spi_eeprom_ready:
5303 * 5316 *
5304 * Wait for a SPI EEPROM to be ready for commands. 5317 * Wait for a SPI EEPROM to be ready for commands.
5305 */ 5318 */
5306static int 5319static int
5307wm_spi_eeprom_ready(struct wm_softc *sc) 5320wm_spi_eeprom_ready(struct wm_softc *sc)
@@ -5327,52 +5340,56 @@ wm_spi_eeprom_ready(struct wm_softc *sc) @@ -5327,52 +5340,56 @@ wm_spi_eeprom_ready(struct wm_softc *sc)
5327 * 5340 *
5328 * Read a work from the EEPROM using the SPI protocol. 5341 * Read a work from the EEPROM using the SPI protocol.
5329 */ 5342 */
5330static int 5343static int
5331wm_read_eeprom_spi(struct wm_softc *sc, int word, int wordcnt, uint16_t *data) 5344wm_read_eeprom_spi(struct wm_softc *sc, int word, int wordcnt, uint16_t *data)
5332{ 5345{
5333 uint32_t reg, val; 5346 uint32_t reg, val;
5334 int i; 5347 int i;
5335 uint8_t opc; 5348 uint8_t opc;
5336 5349
5337 /* Clear SK and CS. */ 5350 /* Clear SK and CS. */
5338 reg = CSR_READ(sc, WMREG_EECD) & ~(EECD_SK | EECD_CS); 5351 reg = CSR_READ(sc, WMREG_EECD) & ~(EECD_SK | EECD_CS);
5339 CSR_WRITE(sc, WMREG_EECD, reg); 5352 CSR_WRITE(sc, WMREG_EECD, reg);
 5353 CSR_WRITE_FLUSH(sc);
5340 delay(2); 5354 delay(2);
5341 5355
5342 if (wm_spi_eeprom_ready(sc)) 5356 if (wm_spi_eeprom_ready(sc))
5343 return 1; 5357 return 1;
5344 5358
5345 /* Toggle CS to flush commands. */ 5359 /* Toggle CS to flush commands. */
5346 CSR_WRITE(sc, WMREG_EECD, reg | EECD_CS); 5360 CSR_WRITE(sc, WMREG_EECD, reg | EECD_CS);
 5361 CSR_WRITE_FLUSH(sc);
5347 delay(2); 5362 delay(2);
5348 CSR_WRITE(sc, WMREG_EECD, reg); 5363 CSR_WRITE(sc, WMREG_EECD, reg);
 5364 CSR_WRITE_FLUSH(sc);
5349 delay(2); 5365 delay(2);
5350 5366
5351 opc = SPI_OPC_READ; 5367 opc = SPI_OPC_READ;
5352 if (sc->sc_ee_addrbits == 8 && word >= 128) 5368 if (sc->sc_ee_addrbits == 8 && word >= 128)
5353 opc |= SPI_OPC_A8; 5369 opc |= SPI_OPC_A8;
5354 5370
5355 wm_eeprom_sendbits(sc, opc, 8); 5371 wm_eeprom_sendbits(sc, opc, 8);
5356 wm_eeprom_sendbits(sc, word << 1, sc->sc_ee_addrbits); 5372 wm_eeprom_sendbits(sc, word << 1, sc->sc_ee_addrbits);
5357 5373
5358 for (i = 0; i < wordcnt; i++) { 5374 for (i = 0; i < wordcnt; i++) {
5359 wm_eeprom_recvbits(sc, &val, 16); 5375 wm_eeprom_recvbits(sc, &val, 16);
5360 data[i] = ((val >> 8) & 0xff) | ((val & 0xff) << 8); 5376 data[i] = ((val >> 8) & 0xff) | ((val & 0xff) << 8);
5361 } 5377 }
5362 5378
5363 /* Raise CS and clear SK. */ 5379 /* Raise CS and clear SK. */
5364 reg = (CSR_READ(sc, WMREG_EECD) & ~EECD_SK) | EECD_CS; 5380 reg = (CSR_READ(sc, WMREG_EECD) & ~EECD_SK) | EECD_CS;
5365 CSR_WRITE(sc, WMREG_EECD, reg); 5381 CSR_WRITE(sc, WMREG_EECD, reg);
 5382 CSR_WRITE_FLUSH(sc);
5366 delay(2); 5383 delay(2);
5367 5384
5368 return 0; 5385 return 0;
5369} 5386}
5370 5387
5371#define NVM_CHECKSUM 0xBABA 5388#define NVM_CHECKSUM 0xBABA
5372#define EEPROM_SIZE 0x0040 5389#define EEPROM_SIZE 0x0040
5373#define NVM_COMPAT 0x0003 5390#define NVM_COMPAT 0x0003
5374#define NVM_COMPAT_VALID_CHECKSUM 0x0001 5391#define NVM_COMPAT_VALID_CHECKSUM 0x0001
5375#define NVM_FUTURE_INIT_WORD1 0x0019 5392#define NVM_FUTURE_INIT_WORD1 0x0019
5376#define NVM_FUTURE_INIT_WORD1_VALID_CHECKSUM 0x0040 5393#define NVM_FUTURE_INIT_WORD1_VALID_CHECKSUM 0x0040
5377 5394
5378/* 5395/*
@@ -5974,53 +5991,57 @@ wm_tbi_mediachange(struct ifnet *ifp) @@ -5974,53 +5991,57 @@ wm_tbi_mediachange(struct ifnet *ifp)
5974 (sc->sc_mii.mii_media.ifm_media & IFM_FLOW) != 0) 5991 (sc->sc_mii.mii_media.ifm_media & IFM_FLOW) != 0)
5975 sc->sc_txcw |= TXCW_SYM_PAUSE | TXCW_ASYM_PAUSE; 5992 sc->sc_txcw |= TXCW_SYM_PAUSE | TXCW_ASYM_PAUSE;
5976 if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) { 5993 if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
5977 sc->sc_txcw |= TXCW_ANE; 5994 sc->sc_txcw |= TXCW_ANE;
5978 } else { 5995 } else {
5979 /* 5996 /*
5980 * If autonegotiation is turned off, force link up and turn on 5997 * If autonegotiation is turned off, force link up and turn on
5981 * full duplex 5998 * full duplex
5982 */ 5999 */
5983 sc->sc_txcw &= ~TXCW_ANE; 6000 sc->sc_txcw &= ~TXCW_ANE;
5984 sc->sc_ctrl |= CTRL_SLU | CTRL_FD; 6001 sc->sc_ctrl |= CTRL_SLU | CTRL_FD;
5985 sc->sc_ctrl &= ~(CTRL_TFCE | CTRL_RFCE); 6002 sc->sc_ctrl &= ~(CTRL_TFCE | CTRL_RFCE);
5986 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6003 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6004 CSR_WRITE_FLUSH(sc);
5987 delay(1000); 6005 delay(1000);
5988 } 6006 }
5989 6007
5990 DPRINTF(WM_DEBUG_LINK,("%s: sc_txcw = 0x%x after autoneg check\n", 6008 DPRINTF(WM_DEBUG_LINK,("%s: sc_txcw = 0x%x after autoneg check\n",
5991 device_xname(sc->sc_dev),sc->sc_txcw)); 6009 device_xname(sc->sc_dev),sc->sc_txcw));
5992 CSR_WRITE(sc, WMREG_TXCW, sc->sc_txcw); 6010 CSR_WRITE(sc, WMREG_TXCW, sc->sc_txcw);
 6011 CSR_WRITE_FLUSH(sc);
5993 delay(10000); 6012 delay(10000);
5994 6013
5995 i = CSR_READ(sc, WMREG_CTRL) & CTRL_SWDPIN(1); 6014 i = CSR_READ(sc, WMREG_CTRL) & CTRL_SWDPIN(1);
5996 DPRINTF(WM_DEBUG_LINK,("%s: i = 0x%x\n", device_xname(sc->sc_dev),i)); 6015 DPRINTF(WM_DEBUG_LINK,("%s: i = 0x%x\n", device_xname(sc->sc_dev),i));
5997 6016
5998 /* 6017 /*
5999 * On 82544 chips and later, the CTRL_SWDPIN(1) bit will be set if the 6018 * On 82544 chips and later, the CTRL_SWDPIN(1) bit will be set if the
6000 * optics detect a signal, 0 if they don't. 6019 * optics detect a signal, 0 if they don't.
6001 */ 6020 */
6002 if (((i != 0) && (sc->sc_type > WM_T_82544)) || (i == 0)) { 6021 if (((i != 0) && (sc->sc_type > WM_T_82544)) || (i == 0)) {
6003 /* Have signal; wait for the link to come up. */ 6022 /* Have signal; wait for the link to come up. */
6004 6023
6005 if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) { 6024 if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
6006 /* 6025 /*
6007 * Reset the link, and let autonegotiation do its thing 6026 * Reset the link, and let autonegotiation do its thing
6008 */ 6027 */
6009 sc->sc_ctrl |= CTRL_LRST; 6028 sc->sc_ctrl |= CTRL_LRST;
6010 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6029 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6030 CSR_WRITE_FLUSH(sc);
6011 delay(1000); 6031 delay(1000);
6012 sc->sc_ctrl &= ~CTRL_LRST; 6032 sc->sc_ctrl &= ~CTRL_LRST;
6013 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6033 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6034 CSR_WRITE_FLUSH(sc);
6014 delay(1000); 6035 delay(1000);
6015 } 6036 }
6016 6037
6017 for (i = 0; i < WM_LINKUP_TIMEOUT; i++) { 6038 for (i = 0; i < WM_LINKUP_TIMEOUT; i++) {
6018 delay(10000); 6039 delay(10000);
6019 if (CSR_READ(sc, WMREG_STATUS) & STATUS_LU) 6040 if (CSR_READ(sc, WMREG_STATUS) & STATUS_LU)
6020 break; 6041 break;
6021 } 6042 }
6022 6043
6023 DPRINTF(WM_DEBUG_LINK,("%s: i = %d after waiting for link\n", 6044 DPRINTF(WM_DEBUG_LINK,("%s: i = %d after waiting for link\n",
6024 device_xname(sc->sc_dev),i)); 6045 device_xname(sc->sc_dev),i));
6025 6046
6026 status = CSR_READ(sc, WMREG_STATUS); 6047 status = CSR_READ(sc, WMREG_STATUS);
@@ -6134,29 +6155,31 @@ wm_tbi_check_link(struct wm_softc *sc) @@ -6134,29 +6155,31 @@ wm_tbi_check_link(struct wm_softc *sc)
6134 wm_init(ifp); 6155 wm_init(ifp);
6135 ifp->if_start(ifp); 6156 ifp->if_start(ifp);
6136 } else if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) { 6157 } else if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
6137 /* If the timer expired, retry autonegotiation */ 6158 /* If the timer expired, retry autonegotiation */
6138 if (++sc->sc_tbi_ticks >= sc->sc_tbi_anegticks) { 6159 if (++sc->sc_tbi_ticks >= sc->sc_tbi_anegticks) {
6139 DPRINTF(WM_DEBUG_LINK, ("EXPIRE\n")); 6160 DPRINTF(WM_DEBUG_LINK, ("EXPIRE\n"));
6140 sc->sc_tbi_ticks = 0; 6161 sc->sc_tbi_ticks = 0;
6141 /* 6162 /*
6142 * Reset the link, and let autonegotiation do 6163 * Reset the link, and let autonegotiation do
6143 * its thing 6164 * its thing
6144 */ 6165 */
6145 sc->sc_ctrl |= CTRL_LRST; 6166 sc->sc_ctrl |= CTRL_LRST;
6146 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6167 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6168 CSR_WRITE_FLUSH(sc);
6147 delay(1000); 6169 delay(1000);
6148 sc->sc_ctrl &= ~CTRL_LRST; 6170 sc->sc_ctrl &= ~CTRL_LRST;
6149 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6171 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6172 CSR_WRITE_FLUSH(sc);
6150 delay(1000); 6173 delay(1000);
6151 CSR_WRITE(sc, WMREG_TXCW, 6174 CSR_WRITE(sc, WMREG_TXCW,
6152 sc->sc_txcw & ~TXCW_ANE); 6175 sc->sc_txcw & ~TXCW_ANE);
6153 CSR_WRITE(sc, WMREG_TXCW, sc->sc_txcw); 6176 CSR_WRITE(sc, WMREG_TXCW, sc->sc_txcw);
6154 } 6177 }
6155 } 6178 }
6156 } 6179 }
6157 6180
6158 wm_tbi_set_linkled(sc); 6181 wm_tbi_set_linkled(sc);
6159} 6182}
6160 6183
6161/* 6184/*
6162 * wm_gmii_reset: 6185 * wm_gmii_reset:
@@ -6221,29 +6244,31 @@ wm_gmii_reset(struct wm_softc *sc) @@ -6221,29 +6244,31 @@ wm_gmii_reset(struct wm_softc *sc)
6221 * In addition, we need to perform a hardware reset on the PHY 6244 * In addition, we need to perform a hardware reset on the PHY
6222 * to take it out of reset. 6245 * to take it out of reset.
6223 */ 6246 */
6224 sc->sc_ctrl |= CTRL_FRCSPD | CTRL_FRCFDX; 6247 sc->sc_ctrl |= CTRL_FRCSPD | CTRL_FRCFDX;
6225 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6248 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
6226 6249
6227 /* The PHY reset pin is active-low. */ 6250 /* The PHY reset pin is active-low. */
6228 reg = CSR_READ(sc, WMREG_CTRL_EXT); 6251 reg = CSR_READ(sc, WMREG_CTRL_EXT);
6229 reg &= ~((CTRL_EXT_SWDPIO_MASK << CTRL_EXT_SWDPIO_SHIFT) | 6252 reg &= ~((CTRL_EXT_SWDPIO_MASK << CTRL_EXT_SWDPIO_SHIFT) |
6230 CTRL_EXT_SWDPIN(4)); 6253 CTRL_EXT_SWDPIN(4));
6231 reg |= CTRL_EXT_SWDPIO(4); 6254 reg |= CTRL_EXT_SWDPIO(4);
6232 6255
6233 CSR_WRITE(sc, WMREG_CTRL_EXT, reg); 6256 CSR_WRITE(sc, WMREG_CTRL_EXT, reg);
 6257 CSR_WRITE_FLUSH(sc);
6234 delay(10*1000); 6258 delay(10*1000);
6235 6259
6236 CSR_WRITE(sc, WMREG_CTRL_EXT, reg | CTRL_EXT_SWDPIN(4)); 6260 CSR_WRITE(sc, WMREG_CTRL_EXT, reg | CTRL_EXT_SWDPIN(4));
 6261 CSR_WRITE_FLUSH(sc);
6237 delay(150); 6262 delay(150);
6238#if 0 6263#if 0
6239 sc->sc_ctrl_ext = reg | CTRL_EXT_SWDPIN(4); 6264 sc->sc_ctrl_ext = reg | CTRL_EXT_SWDPIN(4);
6240#endif 6265#endif
6241 delay(20*1000); /* XXX extra delay to get PHY ID? */ 6266 delay(20*1000); /* XXX extra delay to get PHY ID? */
6242 break; 6267 break;
6243 case WM_T_82544: /* reset 10000us */ 6268 case WM_T_82544: /* reset 10000us */
6244 case WM_T_82540: 6269 case WM_T_82540:
6245 case WM_T_82545: 6270 case WM_T_82545:
6246 case WM_T_82545_3: 6271 case WM_T_82545_3:
6247 case WM_T_82546: 6272 case WM_T_82546:
6248 case WM_T_82546_3: 6273 case WM_T_82546_3:
6249 case WM_T_82541: 6274 case WM_T_82541:
@@ -6256,48 +6281,52 @@ wm_gmii_reset(struct wm_softc *sc) @@ -6256,48 +6281,52 @@ wm_gmii_reset(struct wm_softc *sc)
6256 case WM_T_82574: 6281 case WM_T_82574:
6257 case WM_T_82575: 6282 case WM_T_82575:
6258 case WM_T_82576: 6283 case WM_T_82576:
6259 case WM_T_82580: 6284 case WM_T_82580:
6260 case WM_T_82580ER: 6285 case WM_T_82580ER:
6261 case WM_T_I350: 6286 case WM_T_I350:
6262 case WM_T_I354: 6287 case WM_T_I354:
6263 case WM_T_I210: 6288 case WM_T_I210:
6264 case WM_T_I211: 6289 case WM_T_I211:
6265 case WM_T_82583: 6290 case WM_T_82583:
6266 case WM_T_80003: 6291 case WM_T_80003:
6267 /* generic reset */ 6292 /* generic reset */
6268 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl | CTRL_PHY_RESET); 6293 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl | CTRL_PHY_RESET);
 6294 CSR_WRITE_FLUSH(sc);
6269 delay(20000); 6295 delay(20000);
6270 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6296 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6297 CSR_WRITE_FLUSH(sc);
6271 delay(20000); 6298 delay(20000);
6272 6299
6273 if ((sc->sc_type == WM_T_82541) 6300 if ((sc->sc_type == WM_T_82541)
6274 || (sc->sc_type == WM_T_82541_2) 6301 || (sc->sc_type == WM_T_82541_2)
6275 || (sc->sc_type == WM_T_82547) 6302 || (sc->sc_type == WM_T_82547)
6276 || (sc->sc_type == WM_T_82547_2)) { 6303 || (sc->sc_type == WM_T_82547_2)) {
6277 /* workaround for igp are done in igp_reset() */ 6304 /* workaround for igp are done in igp_reset() */
6278 /* XXX add code to set LED after phy reset */ 6305 /* XXX add code to set LED after phy reset */
6279 } 6306 }
6280 break; 6307 break;
6281 case WM_T_ICH8: 6308 case WM_T_ICH8:
6282 case WM_T_ICH9: 6309 case WM_T_ICH9:
6283 case WM_T_ICH10: 6310 case WM_T_ICH10:
6284 case WM_T_PCH: 6311 case WM_T_PCH:
6285 case WM_T_PCH2: 6312 case WM_T_PCH2:
6286 case WM_T_PCH_LPT: 6313 case WM_T_PCH_LPT:
6287 /* generic reset */ 6314 /* generic reset */
6288 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl | CTRL_PHY_RESET); 6315 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl | CTRL_PHY_RESET);
 6316 CSR_WRITE_FLUSH(sc);
6289 delay(100); 6317 delay(100);
6290 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 6318 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 6319 CSR_WRITE_FLUSH(sc);
6291 delay(150); 6320 delay(150);
6292 break; 6321 break;
6293 default: 6322 default:
6294 panic("%s: %s: unknown type\n", device_xname(sc->sc_dev), 6323 panic("%s: %s: unknown type\n", device_xname(sc->sc_dev),
6295 __func__); 6324 __func__);
6296 break; 6325 break;
6297 } 6326 }
6298 6327
6299 /* release PHY semaphore */ 6328 /* release PHY semaphore */
6300 switch (sc->sc_type) { 6329 switch (sc->sc_type) {
6301 case WM_T_82571: 6330 case WM_T_82571:
6302 case WM_T_82572: 6331 case WM_T_82572:
6303 case WM_T_82573: 6332 case WM_T_82573:
@@ -6734,63 +6763,73 @@ i82543_mii_sendbits(struct wm_softc *sc, @@ -6734,63 +6763,73 @@ i82543_mii_sendbits(struct wm_softc *sc,
6734{ 6763{
6735 uint32_t i, v; 6764 uint32_t i, v;
6736 6765
6737 v = CSR_READ(sc, WMREG_CTRL); 6766 v = CSR_READ(sc, WMREG_CTRL);
6738 v &= ~(MDI_IO|MDI_CLK|(CTRL_SWDPIO_MASK << CTRL_SWDPIO_SHIFT)); 6767 v &= ~(MDI_IO|MDI_CLK|(CTRL_SWDPIO_MASK << CTRL_SWDPIO_SHIFT));
6739 v |= MDI_DIR | CTRL_SWDPIO(3); 6768 v |= MDI_DIR | CTRL_SWDPIO(3);
6740 6769
6741 for (i = 1 << (nbits - 1); i != 0; i >>= 1) { 6770 for (i = 1 << (nbits - 1); i != 0; i >>= 1) {
6742 if (data & i) 6771 if (data & i)
6743 v |= MDI_IO; 6772 v |= MDI_IO;
6744 else 6773 else
6745 v &= ~MDI_IO; 6774 v &= ~MDI_IO;
6746 CSR_WRITE(sc, WMREG_CTRL, v); 6775 CSR_WRITE(sc, WMREG_CTRL, v);
 6776 CSR_WRITE_FLUSH(sc);
6747 delay(10); 6777 delay(10);
6748 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK); 6778 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK);
 6779 CSR_WRITE_FLUSH(sc);
6749 delay(10); 6780 delay(10);
6750 CSR_WRITE(sc, WMREG_CTRL, v); 6781 CSR_WRITE(sc, WMREG_CTRL, v);
 6782 CSR_WRITE_FLUSH(sc);
6751 delay(10); 6783 delay(10);
6752 } 6784 }
6753} 6785}
6754 6786
6755static uint32_t 6787static uint32_t
6756i82543_mii_recvbits(struct wm_softc *sc) 6788i82543_mii_recvbits(struct wm_softc *sc)
6757{ 6789{
6758 uint32_t v, i, data = 0; 6790 uint32_t v, i, data = 0;
6759 6791
6760 v = CSR_READ(sc, WMREG_CTRL); 6792 v = CSR_READ(sc, WMREG_CTRL);
6761 v &= ~(MDI_IO|MDI_CLK|(CTRL_SWDPIO_MASK << CTRL_SWDPIO_SHIFT)); 6793 v &= ~(MDI_IO|MDI_CLK|(CTRL_SWDPIO_MASK << CTRL_SWDPIO_SHIFT));
6762 v |= CTRL_SWDPIO(3); 6794 v |= CTRL_SWDPIO(3);
6763 6795
6764 CSR_WRITE(sc, WMREG_CTRL, v); 6796 CSR_WRITE(sc, WMREG_CTRL, v);
 6797 CSR_WRITE_FLUSH(sc);
6765 delay(10); 6798 delay(10);
6766 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK); 6799 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK);
 6800 CSR_WRITE_FLUSH(sc);
6767 delay(10); 6801 delay(10);
6768 CSR_WRITE(sc, WMREG_CTRL, v); 6802 CSR_WRITE(sc, WMREG_CTRL, v);
 6803 CSR_WRITE_FLUSH(sc);
6769 delay(10); 6804 delay(10);
6770 6805
6771 for (i = 0; i < 16; i++) { 6806 for (i = 0; i < 16; i++) {
6772 data <<= 1; 6807 data <<= 1;
6773 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK); 6808 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK);
 6809 CSR_WRITE_FLUSH(sc);
6774 delay(10); 6810 delay(10);
6775 if (CSR_READ(sc, WMREG_CTRL) & MDI_IO) 6811 if (CSR_READ(sc, WMREG_CTRL) & MDI_IO)
6776 data |= 1; 6812 data |= 1;
6777 CSR_WRITE(sc, WMREG_CTRL, v); 6813 CSR_WRITE(sc, WMREG_CTRL, v);
 6814 CSR_WRITE_FLUSH(sc);
6778 delay(10); 6815 delay(10);
6779 } 6816 }
6780 6817
6781 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK); 6818 CSR_WRITE(sc, WMREG_CTRL, v | MDI_CLK);
 6819 CSR_WRITE_FLUSH(sc);
6782 delay(10); 6820 delay(10);
6783 CSR_WRITE(sc, WMREG_CTRL, v); 6821 CSR_WRITE(sc, WMREG_CTRL, v);
 6822 CSR_WRITE_FLUSH(sc);
6784 delay(10); 6823 delay(10);
6785 6824
6786 return data; 6825 return data;
6787} 6826}
6788 6827
6789#undef MDI_IO 6828#undef MDI_IO
6790#undef MDI_DIR 6829#undef MDI_DIR
6791#undef MDI_CLK 6830#undef MDI_CLK
6792 6831
6793/* 6832/*
6794 * wm_gmii_i82543_readreg: [mii interface function] 6833 * wm_gmii_i82543_readreg: [mii interface function]
6795 * 6834 *
6796 * Read a PHY register on the GMII (i82543 version). 6835 * Read a PHY register on the GMII (i82543 version).
@@ -7445,26 +7484,27 @@ wm_kmrn_readreg(struct wm_softc *sc, int @@ -7445,26 +7484,27 @@ wm_kmrn_readreg(struct wm_softc *sc, int
7445 return 0; 7484 return 0;
7446 } 7485 }
7447 } else if (sc->sc_flags == WM_F_SWFWHW_SYNC) { 7486 } else if (sc->sc_flags == WM_F_SWFWHW_SYNC) {
7448 if (wm_get_swfwhw_semaphore(sc)) { 7487 if (wm_get_swfwhw_semaphore(sc)) {
7449 aprint_error_dev(sc->sc_dev, 7488 aprint_error_dev(sc->sc_dev,
7450 "%s: failed to get semaphore\n", __func__); 7489 "%s: failed to get semaphore\n", __func__);
7451 return 0; 7490 return 0;
7452 } 7491 }
7453 } 7492 }
7454 7493
7455 CSR_WRITE(sc, WMREG_KUMCTRLSTA, 7494 CSR_WRITE(sc, WMREG_KUMCTRLSTA,
7456 ((reg << KUMCTRLSTA_OFFSET_SHIFT) & KUMCTRLSTA_OFFSET) | 7495 ((reg << KUMCTRLSTA_OFFSET_SHIFT) & KUMCTRLSTA_OFFSET) |
7457 KUMCTRLSTA_REN); 7496 KUMCTRLSTA_REN);
 7497 CSR_WRITE_FLUSH(sc);
7458 delay(2); 7498 delay(2);
7459 7499
7460 rv = CSR_READ(sc, WMREG_KUMCTRLSTA) & KUMCTRLSTA_MASK; 7500 rv = CSR_READ(sc, WMREG_KUMCTRLSTA) & KUMCTRLSTA_MASK;
7461 7501
7462 if (sc->sc_flags == WM_F_SWFW_SYNC) 7502 if (sc->sc_flags == WM_F_SWFW_SYNC)
7463 wm_put_swfw_semaphore(sc, SWFW_MAC_CSR_SM); 7503 wm_put_swfw_semaphore(sc, SWFW_MAC_CSR_SM);
7464 else if (sc->sc_flags == WM_F_SWFWHW_SYNC) 7504 else if (sc->sc_flags == WM_F_SWFWHW_SYNC)
7465 wm_put_swfwhw_semaphore(sc); 7505 wm_put_swfwhw_semaphore(sc);
7466 7506
7467 return rv; 7507 return rv;
7468} 7508}
7469 7509
7470/* 7510/*
@@ -8466,47 +8506,51 @@ wm_configure_k1_ich8lan(struct wm_softc  @@ -8466,47 +8506,51 @@ wm_configure_k1_ich8lan(struct wm_softc
8466 8506
8467 wm_kmrn_writereg(sc, KUMCTRLSTA_OFFSET_K1_CONFIG, kmrn_reg); 8507 wm_kmrn_writereg(sc, KUMCTRLSTA_OFFSET_K1_CONFIG, kmrn_reg);
8468 8508
8469 delay(20); 8509 delay(20);
8470 8510
8471 ctrl = CSR_READ(sc, WMREG_CTRL); 8511 ctrl = CSR_READ(sc, WMREG_CTRL);
8472 ctrl_ext = CSR_READ(sc, WMREG_CTRL_EXT); 8512 ctrl_ext = CSR_READ(sc, WMREG_CTRL_EXT);
8473 8513
8474 tmp = ctrl & ~(CTRL_SPEED_1000 | CTRL_SPEED_100); 8514 tmp = ctrl & ~(CTRL_SPEED_1000 | CTRL_SPEED_100);
8475 tmp |= CTRL_FRCSPD; 8515 tmp |= CTRL_FRCSPD;
8476 8516
8477 CSR_WRITE(sc, WMREG_CTRL, tmp); 8517 CSR_WRITE(sc, WMREG_CTRL, tmp);
8478 CSR_WRITE(sc, WMREG_CTRL_EXT, ctrl_ext | CTRL_EXT_SPD_BYPS); 8518 CSR_WRITE(sc, WMREG_CTRL_EXT, ctrl_ext | CTRL_EXT_SPD_BYPS);
 8519 CSR_WRITE_FLUSH(sc);
8479 delay(20); 8520 delay(20);
8480 8521
8481 CSR_WRITE(sc, WMREG_CTRL, ctrl); 8522 CSR_WRITE(sc, WMREG_CTRL, ctrl);
8482 CSR_WRITE(sc, WMREG_CTRL_EXT, ctrl_ext); 8523 CSR_WRITE(sc, WMREG_CTRL_EXT, ctrl_ext);
 8524 CSR_WRITE_FLUSH(sc);
8483 delay(20); 8525 delay(20);
8484} 8526}
8485 8527
8486static void 8528static void
8487wm_smbustopci(struct wm_softc *sc) 8529wm_smbustopci(struct wm_softc *sc)
8488{ 8530{
8489 uint32_t fwsm; 8531 uint32_t fwsm;
8490 8532
8491 fwsm = CSR_READ(sc, WMREG_FWSM); 8533 fwsm = CSR_READ(sc, WMREG_FWSM);
8492 if (((fwsm & FWSM_FW_VALID) == 0) 8534 if (((fwsm & FWSM_FW_VALID) == 0)
8493 && ((wm_check_reset_block(sc) == 0))) { 8535 && ((wm_check_reset_block(sc) == 0))) {
8494 sc->sc_ctrl |= CTRL_LANPHYPC_OVERRIDE; 8536 sc->sc_ctrl |= CTRL_LANPHYPC_OVERRIDE;
8495 sc->sc_ctrl &= ~CTRL_LANPHYPC_VALUE; 8537 sc->sc_ctrl &= ~CTRL_LANPHYPC_VALUE;
8496 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 8538 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 8539 CSR_WRITE_FLUSH(sc);
8497 delay(10); 8540 delay(10);
8498 sc->sc_ctrl &= ~CTRL_LANPHYPC_OVERRIDE; 8541 sc->sc_ctrl &= ~CTRL_LANPHYPC_OVERRIDE;
8499 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl); 8542 CSR_WRITE(sc, WMREG_CTRL, sc->sc_ctrl);
 8543 CSR_WRITE_FLUSH(sc);
8500 delay(50*1000); 8544 delay(50*1000);
8501 8545
8502 /* 8546 /*
8503 * Gate automatic PHY configuration by hardware on non-managed 8547 * Gate automatic PHY configuration by hardware on non-managed
8504 * 82579 8548 * 82579
8505 */ 8549 */
8506 if (sc->sc_type == WM_T_PCH2) 8550 if (sc->sc_type == WM_T_PCH2)
8507 wm_gate_hw_phy_config_ich8lan(sc, 1); 8551 wm_gate_hw_phy_config_ich8lan(sc, 1);
8508 } 8552 }
8509} 8553}
8510 8554
8511static void 8555static void
8512wm_set_pcie_completion_timeout(struct wm_softc *sc) 8556wm_set_pcie_completion_timeout(struct wm_softc *sc)