Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/dev/pci Start moving spl based locking to a mutex.
details: https://anonhg.NetBSD.org/src-all/rev/909276ea7114
branches: trunk
changeset: 371033:909276ea7114
user: Martin Husemann <martin%NetBSD.org@localhost>
date: Thu Jan 14 14:12:01 2021 +0100
description:
Start moving spl based locking to a mutex.
Sprinkle various locking asserts.
Make lockdebug frames readable by preventing inlining.
Disable (incomplete) rate adaption code for now.
Remove some unused and already disabled functions, add a few
missing new framework functions.
diffstat:
sys/dev/pci/if_iwm.c | 464 +++++++++++++++++++++++++++--------------------
sys/dev/pci/if_iwmvar.h | 12 +-
2 files changed, 275 insertions(+), 201 deletions(-)
diffs (truncated from 1497 to 300 lines):
diff -r bd2a2d2521e7 -r 909276ea7114 sys/dev/pci/if_iwm.c
--- a/sys/dev/pci/if_iwm.c Wed Jan 13 19:02:35 2021 +1100
+++ b/sys/dev/pci/if_iwm.c Thu Jan 14 14:12:01 2021 +0100
@@ -141,7 +141,6 @@
#include <netinet/ip.h>
#include <net80211/ieee80211_var.h>
-#include <net80211/ieee80211_amrr.h>
#include <net80211/ieee80211_radiotap.h>
#include <net80211/ieee80211_regdomain.h>
@@ -153,7 +152,8 @@
#ifdef IWM_DEBUG
#define DPRINTF(x) do { if (iwm_debug > 0) printf x; } while (0)
#define DPRINTFN(n, x) do { if (iwm_debug >= (n)) printf x; } while (0)
-int iwm_debug = 0;
+int iwm_debug = 255;
+#define static static __attribute__((noinline))
#else
#define DPRINTF(x) do { ; } while (0)
#define DPRINTFN(n, x) do { ; } while (0)
@@ -162,6 +162,11 @@
#include <dev/pci/if_iwmreg.h>
#include <dev/pci/if_iwmvar.h>
+#define IWM_LOCK(sc) mutex_enter(&(sc)->sc_lock)
+#define IWM_UNLOCK(sc) mutex_exit(&(sc)->sc_lock)
+#define IWM_ASSERT_LOCKED(sc) KASSERTMSG(mutex_owned((&(sc)->sc_lock)), \
+ "sc_lock %p not owned", &(sc)->sc_lock)
+
static const uint8_t iwm_nvm_channels[] = {
/* 2.4 GHz */
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
@@ -329,6 +334,7 @@
static int iwm_transmit(struct ieee80211com *, struct mbuf *);
static int iwm_raw_xmit(struct ieee80211_node *, struct mbuf *,
const struct ieee80211_bpf_params *);
+static void iwm_update_mcast(struct ieee80211com *);
#ifndef IEEE80211_NO_HT
static void iwm_setup_ht_rates(struct iwm_softc *);
static void iwm_htprot_task(void *);
@@ -483,7 +489,7 @@
static int iwm_send_update_mcc_cmd(struct iwm_softc *, const char *);
static void iwm_tt_tx_backoff(struct iwm_softc *, uint32_t);
static int iwm_init_hw(struct iwm_softc *);
-static int iwm_init(struct ifnet *ifp);
+static int iwm_init(struct iwm_softc *);
static void iwm_start(struct iwm_softc *);
static void iwm_stop(struct iwm_softc *);
#ifdef notyet
@@ -499,11 +505,12 @@
static void iwm_softintr(void *);
static int iwm_preinit(struct iwm_softc *);
static void iwm_attach_hook(device_t);
+static int iwm_detach(device_t, int);
+static int iwm_activate(device_t, enum devact);
static void iwm_attach(device_t, device_t, void *);
static int iwm_config_complete(struct iwm_softc *);
#if 0
static void iwm_init_task(void *);
-static int iwm_activate(device_t, enum devact);
static void iwm_wakeup(struct iwm_softc *);
#endif
static void iwm_radiotap_attach(struct iwm_softc *, struct ifnet *);
@@ -696,7 +703,7 @@
fw->fw_status = IWM_FW_STATUS_INPROGRESS;
} else {
while (fw->fw_status == IWM_FW_STATUS_INPROGRESS)
- tsleep(&sc->sc_fw, 0, "iwmfwp", 0);
+ mtsleep(&sc->sc_fw, 0, "iwmfwp", 0, &sc->sc_lock);
}
status = fw->fw_status;
@@ -1086,6 +1093,7 @@
if (sc->sc_cmd_hold_nic_awake)
return 1;
+ IWM_ASSERT_LOCKED(sc);
IWM_SETBITS(sc, IWM_CSR_GP_CNTRL,
IWM_CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
@@ -1112,6 +1120,7 @@
if (sc->sc_cmd_hold_nic_awake)
return;
+ IWM_ASSERT_LOCKED(sc);
IWM_CLRBITS(sc, IWM_CSR_GP_CNTRL,
IWM_CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
}
@@ -1487,10 +1496,9 @@
iwm_check_rfkill(struct iwm_softc *sc)
{
uint32_t v;
- int s;
int rv;
- s = splnet();
+ IWM_ASSERT_LOCKED(sc);
/*
* "documentation" is not really helpful here:
@@ -1507,7 +1515,6 @@
sc->sc_flags &= ~IWM_FLAG_RFKILL;
}
- splx(s);
return rv;
}
@@ -1527,20 +1534,22 @@
static void
iwm_disable_interrupts(struct iwm_softc *sc)
{
- int s = splnet();
+
+ IWM_ASSERT_LOCKED(sc);
IWM_WRITE(sc, IWM_CSR_INT_MASK, 0);
/* acknowledge all interrupts */
IWM_WRITE(sc, IWM_CSR_INT, ~0);
IWM_WRITE(sc, IWM_CSR_FH_INT_STATUS, ~0);
-
- splx(s);
}
static void
iwm_ict_reset(struct iwm_softc *sc)
{
+
+ IWM_ASSERT_LOCKED(sc);
+
iwm_disable_interrupts(sc);
memset(sc->ict_dma.vaddr, 0, IWM_ICT_SIZE);
@@ -1753,6 +1762,7 @@
{
int err;
+ IWM_ASSERT_LOCKED(sc);
err = iwm_prepare_card_hw(sc);
if (err)
return err;
@@ -1777,6 +1787,7 @@
int chnl, ntries;
int qid;
+ IWM_ASSERT_LOCKED(sc);
iwm_disable_interrupts(sc);
sc->sc_flags &= ~IWM_FLAG_USE_ICT;
@@ -1881,6 +1892,7 @@
static int
iwm_nic_rx_init(struct iwm_softc *sc)
{
+ IWM_ASSERT_LOCKED(sc);
if (!iwm_nic_lock(sc))
return EBUSY;
@@ -1934,16 +1946,14 @@
iwm_transmit(struct ieee80211com *ic, struct mbuf *m)
{
struct iwm_softc *sc = ic->ic_softc;
- int s;
DPRINTFN(5, ("%s: %s\n",ic->ic_name, __func__));
- s = splnet();
+ IWM_LOCK(sc);
IF_ENQUEUE(&sc->sc_sendq, m);
- splx(s);
-
if (!(sc->sc_flags & IWM_FLAG_TX_RUNNING))
iwm_start(sc);
+ IWM_UNLOCK(sc);
return 0;
}
@@ -1953,6 +1963,7 @@
{
int qid;
+ IWM_ASSERT_LOCKED(sc);
if (!iwm_nic_lock(sc))
return EBUSY;
@@ -2755,7 +2766,7 @@
struct ieee80211com *ic = &sc->sc_ic;
struct iwm_add_sta_cmd_v7 cmd;
struct iwm_node *in = (struct iwm_node *)ni;
- int err, s;
+ int err;
uint32_t status;
if (start && sc->sc_rx_ba_sessions >= IWM_MAX_RX_BA_SESSIONS) {
@@ -2780,10 +2791,11 @@
IWM_STA_MODIFY_REMOVE_BA_TID;
status = IWM_ADD_STA_SUCCESS;
+ IWM_LOCK(sc);
err = iwm_send_cmd_pdu_status(sc, IWM_ADD_STA, sizeof(cmd), &cmd,
&status);
-
- s = splnet();
+ IWM_UNLOCK(sc);
+
if (err == 0 && status == IWM_ADD_STA_SUCCESS) {
if (start) {
sc->sc_rx_ba_sessions++;
@@ -2792,7 +2804,6 @@
sc->sc_rx_ba_sessions--;
} else if (start)
ieee80211_addba_req_refuse(ic, ni, tid);
- splx(s);
}
#ifndef IEEE80211_NO_HT
@@ -2852,12 +2863,14 @@
struct ieee80211_rx_ba *ba = &ni->ni_rx_ba[tid];
struct iwm_softc *sc = ic->ic_softc;
+ IWM_LOCK(sc);
if (sc->sc_rx_ba_sessions >= IWM_MAX_RX_BA_SESSIONS)
return ENOSPC;
sc->ba_start = 1;
sc->ba_tid = tid;
sc->ba_ssn = htole16(ba->ba_winstart);
+ IWM_UNLOCK(sc);
task_add(systq, &sc->ba_task);
return EBUSY;
@@ -2873,8 +2886,10 @@
{
struct iwm_softc *sc = ic->ic_softc;
+ IWM_LOCK(sc);
sc->ba_start = 0;
sc->ba_tid = tid;
+ IWM_UNLOCK(sc);
task_add(systq, &sc->ba_task);
}
#endif
@@ -2885,6 +2900,8 @@
{
int i;
+ IWM_ASSERT_LOCKED(sc);
+
if (sc->fw_paging_db[0].fw_paging_block.vaddr == NULL)
return;
@@ -2901,6 +2918,8 @@
int sec_idx, idx;
uint32_t offset = 0;
+ IWM_ASSERT_LOCKED(sc);
+
/*
* find where is the paging image start point:
* if CPU2 exist and it's in paging format, then the image looks like:
@@ -2980,6 +2999,8 @@
int error, num_of_pages;
bus_dmamap_t dmap;
+ IWM_ASSERT_LOCKED(sc);
+
if (sc->fw_paging_db[0].fw_paging_block.vaddr != NULL) {
int i;
/* Device got reset, and we setup firmware paging again */
@@ -3050,6 +3071,8 @@
{
int err;
+ IWM_ASSERT_LOCKED(sc);
+
err = iwm_alloc_fw_paging_mem(sc, fws);
if (err)
return err;
@@ -3080,6 +3103,8 @@
int blk_idx;
bus_dmamap_t dmap;
+ IWM_ASSERT_LOCKED(sc);
+
if (!iwm_has_new_tx_api(sc))
size -= (sizeof(uint64_t) - sizeof(uint32_t)) *
IWM_NUM_OF_FW_PAGING_BLOCKS;
@@ -3379,6 +3404,8 @@
struct iwm_dma_info *dma = &sc->fw_dma;
int err;
+ IWM_ASSERT_LOCKED(sc);
+
/* Copy firmware chunk into pre-allocated DMA-safe memory. */
memcpy(dma->vaddr, section, byte_cnt);
bus_dmamap_sync(sc->sc_dmat, dma->map, 0, byte_cnt,
@@ -3412,7 +3439,8 @@
/* Wait for this segment to load. */
err = 0;
Home |
Main Index |
Thread Index |
Old Index