summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsf <sf@openbsd.org>2018-04-29 08:42:16 +0000
committersf <sf@openbsd.org>2018-04-29 08:42:16 +0000
commit21ea712277317eb5a677d2285c48d30dfab0f593 (patch)
treefc4d11366218f55ba52c410f238fb76771a8c111
parentINIT->RUN transitions are valid in monitor mode, so don't (diff)
downloadwireguard-openbsd-21ea712277317eb5a677d2285c48d30dfab0f593.tar.xz
wireguard-openbsd-21ea712277317eb5a677d2285c48d30dfab0f593.zip
em: Improve access logic for software flag
Some em chips have a semaphore ("software flag") to synchronize access to certain registers between OS and firmware (ME/AMT). Make the logic to get the flag match the logic in freebsd. This includes higher timeouts and waiting for a previous unlock to complete before trying a lock again. ok mikeb@
-rw-r--r--sys/dev/pci/if_em_hw.c24
-rw-r--r--sys/dev/pci/if_em_hw.h4
2 files changed, 23 insertions, 5 deletions
diff --git a/sys/dev/pci/if_em_hw.c b/sys/dev/pci/if_em_hw.c
index 3815ca528db..a18214f270f 100644
--- a/sys/dev/pci/if_em_hw.c
+++ b/sys/dev/pci/if_em_hw.c
@@ -31,7 +31,7 @@
*******************************************************************************/
-/* $OpenBSD: if_em_hw.c,v 1.99 2018/04/07 11:55:14 sf Exp $ */
+/* $OpenBSD: if_em_hw.c,v 1.100 2018/04/29 08:42:16 sf Exp $ */
/*
* if_em_hw.c Shared functions for accessing and configuring the MAC
*/
@@ -9613,9 +9613,21 @@ em_get_software_flag(struct em_hw *hw)
if (IS_ICH8(hw->mac_type)) {
while (timeout) {
extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
- extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
- E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
+ if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
+ break;
+ msec_delay_irq(1);
+ timeout--;
+ }
+ if (!timeout) {
+ printf("%s: SW has already locked the resource?\n",
+ __func__);
+ return -E1000_ERR_CONFIG;
+ }
+ timeout = SW_FLAG_TIMEOUT;
+ extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
+ E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
+ while (timeout) {
extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
break;
@@ -9624,7 +9636,11 @@ em_get_software_flag(struct em_hw *hw)
}
if (!timeout) {
- DEBUGOUT("FW or HW locks the resource too long.\n");
+ printf("Failed to acquire the semaphore, FW or HW "
+ "has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
+ E1000_READ_REG(hw, FWSM), extcnf_ctrl);
+ extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
+ E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
return -E1000_ERR_CONFIG;
}
}
diff --git a/sys/dev/pci/if_em_hw.h b/sys/dev/pci/if_em_hw.h
index 469432c5eb1..bb0a5d4fdb2 100644
--- a/sys/dev/pci/if_em_hw.h
+++ b/sys/dev/pci/if_em_hw.h
@@ -31,7 +31,7 @@
*******************************************************************************/
-/* $OpenBSD: if_em_hw.h,v 1.74 2018/04/07 11:56:40 sf Exp $ */
+/* $OpenBSD: if_em_hw.h,v 1.75 2018/04/29 08:42:16 sf Exp $ */
/* $FreeBSD: if_em_hw.h,v 1.15 2005/05/26 23:32:02 tackerman Exp $ */
/* if_em_hw.h
@@ -2756,6 +2756,8 @@ struct em_host_command_info {
#define AUTO_READ_DONE_TIMEOUT 10
/* Number of milliseconds we wait for PHY configuration done after MAC reset */
#define PHY_CFG_TIMEOUT 100
+/* SW Semaphore flag timeout in ms */
+#define SW_FLAG_TIMEOUT 1000
#define E1000_TX_BUFFER_SIZE ((uint32_t)1514)