From fd411f94be6f205b10287b8acf67e3187ff982f9 Mon Sep 17 00:00:00 2001 From: msaitoh Date: Thu, 27 Jul 2017 03:21:42 +0000 Subject: [PATCH] Add WM_F_WA_I210_CLSEM flag for a workaround. FreeBSD/Linux drivers say "In rare circumstances, the SW semaphore may already be held unintentionally." on I21[01]. PXE boot is one of the case. XXX pullup-[678]. --- sys/dev/pci/if_wm.c | 17 +++++++++++++++-- sys/dev/pci/if_wmvar.h | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sys/dev/pci/if_wm.c b/sys/dev/pci/if_wm.c index 7eba79dd58ea..7ae50284f67b 100644 --- a/sys/dev/pci/if_wm.c +++ b/sys/dev/pci/if_wm.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_wm.c,v 1.532 2017/07/26 08:09:59 msaitoh Exp $ */ +/* $NetBSD: if_wm.c,v 1.533 2017/07/27 03:21:42 msaitoh Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. @@ -83,7 +83,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.532 2017/07/26 08:09:59 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.533 2017/07/27 03:21:42 msaitoh Exp $"); #ifdef _KERNEL_OPT #include "opt_net_mpsafe.h" @@ -2215,6 +2215,8 @@ alloc_retry: break; case WM_T_I210: case WM_T_I211: + /* Allow a single clear of the SW semaphore on I210 and newer*/ + sc->sc_flags |= WM_F_WA_I210_CLSEM; if (wm_nvm_get_flash_presence_i210(sc)) { sc->nvm.read = wm_nvm_read_eerd; /* Don't use WM_F_LOCK_EECD because we use EERD */ @@ -12704,6 +12706,7 @@ wm_get_swsm_semaphore(struct wm_softc *sc) device_xname(sc->sc_dev), __func__)); KASSERT(sc->sc_nvm_wordsize > 0); +retry: /* Get the SW semaphore. */ timeout = sc->sc_nvm_wordsize + 1; while (timeout) { @@ -12717,6 +12720,16 @@ wm_get_swsm_semaphore(struct wm_softc *sc) } if (timeout == 0) { + if ((sc->sc_flags & WM_F_WA_I210_CLSEM) != 0) { + /* + * In rare circumstances, the SW semaphore may already + * be held unintentionally. Clear the semaphore once + * before giving up. + */ + sc->sc_flags &= ~WM_F_WA_I210_CLSEM; + wm_put_swsm_semaphore(sc); + goto retry; + } aprint_error_dev(sc->sc_dev, "could not acquire SWSM SMBI\n"); return 1; diff --git a/sys/dev/pci/if_wmvar.h b/sys/dev/pci/if_wmvar.h index 1acdacc302ef..c82f39ee5c65 100644 --- a/sys/dev/pci/if_wmvar.h +++ b/sys/dev/pci/if_wmvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_wmvar.h,v 1.36 2017/07/26 06:48:49 msaitoh Exp $ */ +/* $NetBSD: if_wmvar.h,v 1.37 2017/07/27 03:21:42 msaitoh Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. @@ -96,6 +96,7 @@ #define WM_F_80003_MDIC_WA 0x01000000 /* 80003 MDIC workaround */ #define WM_F_PCS_DIS_AUTONEGO 0x02000000 /* PCS Disable Autonego */ #define WM_F_PLL_WA_I210 0x04000000 /* I21[01] PLL workaround */ +#define WM_F_WA_I210_CLSEM 0x08000000 /* I21[01] Semaphore workaround */ #define WM_FLAGS "\20" \ "\1" "HAS_MII" "\2" "LOCK_EECD" "\3" "_B02" "\4" "_B03" \