Index: head/sys/dev/usb/wlan/if_run.c =================================================================== --- head/sys/dev/usb/wlan/if_run.c +++ head/sys/dev/usb/wlan/if_run.c @@ -86,6 +86,35 @@ static SYSCTL_NODE(_hw_usb, OID_AUTO, run, CTLFLAG_RW, 0, "USB run"); SYSCTL_INT(_hw_usb_run, OID_AUTO, debug, CTLFLAG_RWTUN, &run_debug, 0, "run debug level"); + +enum { + RUN_DEBUG_XMIT = 0x00000001, /* basic xmit operation */ + RUN_DEBUG_XMIT_DESC = 0x00000002, /* xmit descriptors */ + RUN_DEBUG_RECV = 0x00000004, /* basic recv operation */ + RUN_DEBUG_RECV_DESC = 0x00000008, /* recv descriptors */ + RUN_DEBUG_STATE = 0x00000010, /* 802.11 state transitions */ + RUN_DEBUG_RATE = 0x00000020, /* rate adaptation */ + RUN_DEBUG_USB = 0x00000040, /* usb requests */ + RUN_DEBUG_FIRMWARE = 0x00000080, /* firmware(9) loading debug */ + RUN_DEBUG_BEACON = 0x00000100, /* beacon handling */ + RUN_DEBUG_INTR = 0x00000200, /* ISR */ + RUN_DEBUG_TEMP = 0x00000400, /* temperature calibration */ + RUN_DEBUG_ROM = 0x00000800, /* various ROM info */ + RUN_DEBUG_KEY = 0x00001000, /* crypto keys management */ + RUN_DEBUG_TXPWR = 0x00002000, /* dump Tx power values */ + RUN_DEBUG_RSSI = 0x00004000, /* dump RSSI lookups */ + RUN_DEBUG_RESET = 0x00008000, /* initialization progress */ + RUN_DEBUG_CALIB = 0x00010000, /* calibration progress */ + RUN_DEBUG_CMD = 0x00010000, /* command queue */ + RUN_DEBUG_ANY = 0xffffffff +}; + +#define RUN_DPRINTF(_sc, _m, ...) do { \ + if (run_debug & (_m)) \ + device_printf((_sc)->sc_dev, __VA_ARGS__); \ +} while(0) +#else +#define RUN_DPRINTF(_sc, _m, ...) do { (void) _sc; } while (0) #endif #define IEEE80211_HAS_ADDR4(wh) IEEE80211_IS_DSTODS(wh) @@ -980,7 +1009,7 @@ if (opmode == IEEE80211_M_HOSTAP) sc->cmdq_run = RUN_CMDQ_GO; - DPRINTF("rvp_id=%d bmap=%x rvp_cnt=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_STATE, "rvp_id=%d bmap=%x rvp_cnt=%d\n", rvp->rvp_id, sc->rvp_bmap, sc->rvp_cnt); return (vap); @@ -1012,7 +1041,8 @@ run_set_region_4(sc, RT2860_BCN_BASE(rvp_id), 0, 512); --sc->rvp_cnt; - DPRINTF("vap=%p rvp_id=%d bmap=%x rvp_cnt=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_STATE, + "vap=%p rvp_id=%d bmap=%x rvp_cnt=%d\n", vap, rvp_id, sc->rvp_bmap, sc->rvp_cnt); RUN_UNLOCK(sc); @@ -1040,7 +1070,8 @@ RUN_LOCK(sc); for (i = sc->cmdq_exec; sc->cmdq[i].func && pending; i = sc->cmdq_exec, pending--) { - DPRINTFN(6, "cmdq_exec=%d pending=%d\n", i, pending); + RUN_DPRINTF(sc, RUN_DEBUG_CMD, "cmdq_exec=%d pending=%d\n", + i, pending); if (sc->cmdq_run == RUN_CMDQ_GO) { /* * If arg0 is NULL, callback func needs more @@ -1226,7 +1257,8 @@ req, data, 0, NULL, 250 /* ms */); if (err == 0) break; - DPRINTFN(1, "Control request failed, %s (retrying)\n", + RUN_DPRINTF(sc, RUN_DEBUG_USB, + "Control request failed, %s (retrying)\n", usbd_errstr(err)); run_delay(sc, 10); } @@ -1702,7 +1734,8 @@ if (sc->txpow2[i] < 0 || sc->txpow2[i] > 31) sc->txpow2[i] = 5; } - DPRINTF("chan %d: power1=%d, power2=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_TXPWR, + "chan %d: power1=%d, power2=%d\n", rt2860_rf2850[i].chan, sc->txpow1[i], sc->txpow2[i]); } /* Read power settings for 5GHz channels. */ @@ -1723,7 +1756,8 @@ if (sc->txpow2[14 + i] < -7 || sc->txpow2[14 + i] > 15) sc->txpow2[14 + i] = 5; } - DPRINTF("chan %d: power1=%d, power2=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_TXPWR, + "chan %d: power1=%d, power2=%d\n", rt2860_rf2850[14 + i].chan, sc->txpow1[14 + i], sc->txpow2[14 + i]); } @@ -1742,14 +1776,15 @@ sc->sc_srom_read = run_eeprom_read_2; if (sc->mac_ver >= 0x3070) { run_read(sc, RT3070_EFUSE_CTRL, &tmp); - DPRINTF("EFUSE_CTRL=0x%08x\n", tmp); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "EFUSE_CTRL=0x%08x\n", tmp); if ((tmp & RT3070_SEL_EFUSE) || sc->mac_ver == 0x3593) sc->sc_srom_read = run_efuse_read_2; } /* read ROM version */ run_srom_read(sc, RT2860_EEPROM_VERSION, &val); - DPRINTF("EEPROM rev=%d, FAE=%d\n", val >> 8, val & 0xff); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, + "EEPROM rev=%d, FAE=%d\n", val >> 8, val & 0xff); /* read MAC address */ run_srom_read(sc, RT2860_EEPROM_MAC01, &val); @@ -1768,8 +1803,8 @@ run_srom_read(sc, RT2860_EEPROM_BBP_BASE + i, &val); sc->bbp[i].val = val & 0xff; sc->bbp[i].reg = val >> 8; - DPRINTF("BBP%d=0x%02x\n", sc->bbp[i].reg, - sc->bbp[i].val); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, + "BBP%d=0x%02x\n", sc->bbp[i].reg, sc->bbp[i].val); } if (sc->mac_ver >= 0x3071) { /* read vendor RF settings */ @@ -1778,8 +1813,8 @@ &val); sc->rf[i].val = val & 0xff; sc->rf[i].reg = val >> 8; - DPRINTF("RF%d=0x%02x\n", sc->rf[i].reg, - sc->rf[i].val); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "RF%d=0x%02x\n", + sc->rf[i].reg, sc->rf[i].val); } } } @@ -1788,7 +1823,8 @@ run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_FREQ_LEDS : RT3593_EEPROM_FREQ, &val); sc->freq = ((val & 0xff) != 0xff) ? val & 0xff : 0; - DPRINTF("EEPROM freq offset %d\n", sc->freq & 0xff); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "EEPROM freq offset %d\n", + sc->freq & 0xff); run_srom_read(sc, (sc->mac_ver != 0x3593) ? RT2860_EEPROM_FREQ_LEDS : RT3593_EEPROM_FREQ_LEDS, &val); @@ -1808,7 +1844,8 @@ sc->led[1] = 0x2221; sc->led[2] = 0x5627; /* differs from RT2860 */ } - DPRINTF("EEPROM LED mode=0x%02x, LEDs=0x%04x/0x%04x/0x%04x\n", + RUN_DPRINTF(sc, RUN_DEBUG_ROM, + "EEPROM LED mode=0x%02x, LEDs=0x%04x/0x%04x/0x%04x\n", sc->leds, sc->led[0], sc->led[1], sc->led[2]); /* read RF information */ @@ -1820,7 +1857,6 @@ if (val == 0xffff) { device_printf(sc->sc_dev, "invalid EEPROM antenna info, using default\n"); - DPRINTF("invalid EEPROM antenna info, using default\n"); if (sc->mac_ver == 0x3572) { /* default to RF3052 2T2R */ sc->rf_rev = RT3070_RF_3052; @@ -1846,12 +1882,12 @@ sc->ntxchains = (val >> 4) & 0xf; sc->nrxchains = val & 0xf; } - DPRINTF("EEPROM RF rev=0x%04x chains=%dT%dR\n", + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "EEPROM RF rev=0x%04x chains=%dT%dR\n", sc->rf_rev, sc->ntxchains, sc->nrxchains); /* check if RF supports automatic Tx access gain control */ run_srom_read(sc, RT2860_EEPROM_CONFIG, &val); - DPRINTF("EEPROM CFG 0x%04x\n", val); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "EEPROM CFG 0x%04x\n", val); /* check if driver should patch the DAC issue */ if ((val >> 8) != 0xff) sc->patch_dac = (val >> 15) & 1; @@ -1884,8 +1920,8 @@ if (!(val & 0x40)) /* negative number */ delta_5ghz = -delta_5ghz; } - DPRINTF("power compensation=%d (2GHz), %d (5GHz)\n", - delta_2ghz, delta_5ghz); + RUN_DPRINTF(sc, RUN_DEBUG_ROM | RUN_DEBUG_TXPWR, + "power compensation=%d (2GHz), %d (5GHz)\n", delta_2ghz, delta_5ghz); for (ridx = 0; ridx < 5; ridx++) { uint32_t reg; @@ -1899,7 +1935,8 @@ sc->txpow40mhz_2ghz[ridx] = b4inc(reg, delta_2ghz); sc->txpow40mhz_5ghz[ridx] = b4inc(reg, delta_5ghz); - DPRINTF("ridx %d: power 20MHz=0x%08x, 40MHz/2GHz=0x%08x, " + RUN_DPRINTF(sc, RUN_DEBUG_ROM | RUN_DEBUG_TXPWR, + "ridx %d: power 20MHz=0x%08x, 40MHz/2GHz=0x%08x, " "40MHz/5GHz=0x%08x\n", ridx, sc->txpow20mhz[ridx], sc->txpow40mhz_2ghz[ridx], sc->txpow40mhz_5ghz[ridx]); } @@ -1923,7 +1960,8 @@ if ((val & 0xff) != 0xff) sc->txmixgain_2ghz = val & 0x7; } - DPRINTF("tx mixer gain=%u (2GHz)\n", sc->txmixgain_2ghz); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "tx mixer gain=%u (2GHz)\n", + sc->txmixgain_2ghz); } else sc->rssi_2ghz[2] = val & 0xff; /* Ant C */ if (sc->mac_ver == 0x3593) @@ -1943,7 +1981,8 @@ */ if ((val & 0xff) != 0xff) sc->txmixgain_5ghz = val & 0x7; - DPRINTF("tx mixer gain=%u (5GHz)\n", sc->txmixgain_5ghz); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, "tx mixer gain=%u (5GHz)\n", + sc->txmixgain_5ghz); } else sc->rssi_5ghz[2] = val & 0xff; /* Ant C */ if (sc->mac_ver == 0x3593) { @@ -1959,23 +1998,27 @@ /* fix broken 5GHz LNA entries */ if (sc->lna[2] == 0 || sc->lna[2] == 0xff) { - DPRINTF("invalid LNA for channel group %d\n", 2); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, + "invalid LNA for channel group %d\n", 2); sc->lna[2] = sc->lna[1]; } if (sc->lna[3] == 0 || sc->lna[3] == 0xff) { - DPRINTF("invalid LNA for channel group %d\n", 3); + RUN_DPRINTF(sc, RUN_DEBUG_ROM, + "invalid LNA for channel group %d\n", 3); sc->lna[3] = sc->lna[1]; } /* fix broken RSSI offset entries */ for (ant = 0; ant < 3; ant++) { if (sc->rssi_2ghz[ant] < -10 || sc->rssi_2ghz[ant] > 10) { - DPRINTF("invalid RSSI%d offset: %d (2GHz)\n", + RUN_DPRINTF(sc, RUN_DEBUG_ROM | RUN_DEBUG_RSSI, + "invalid RSSI%d offset: %d (2GHz)\n", ant + 1, sc->rssi_2ghz[ant]); sc->rssi_2ghz[ant] = 0; } if (sc->rssi_5ghz[ant] < -10 || sc->rssi_5ghz[ant] > 10) { - DPRINTF("invalid RSSI%d offset: %d (5GHz)\n", + RUN_DPRINTF(sc, RUN_DEBUG_ROM | RUN_DEBUG_RSSI, + "invalid RSSI%d offset: %d (5GHz)\n", ant + 1, sc->rssi_5ghz[ant]); sc->rssi_5ghz[ant] = 0; } @@ -2020,7 +2063,8 @@ ni = ieee80211_ref_node(vap->iv_bss); rn = RUN_NODE(ni); rn->fix_ridx = ridx; - DPRINTF("rate=%d, fix_ridx=%d\n", rate, rn->fix_ridx); + RUN_DPRINTF(sc, RUN_DEBUG_RATE, "rate=%d, fix_ridx=%d\n", + rate, rn->fix_ridx); ieee80211_free_node(ni); } @@ -2051,7 +2095,7 @@ uint8_t bid = 1 << rvp->rvp_id; ostate = vap->iv_state; - DPRINTF("%s -> %s\n", + RUN_DPRINTF(sc, RUN_DEBUG_STATE, "%s -> %s\n", ieee80211_state_name[ostate], ieee80211_state_name[nstate]); @@ -2156,7 +2200,7 @@ break; default: - DPRINTFN(6, "undefined case\n"); + RUN_DPRINTF(sc, RUN_DEBUG_STATE, "undefined state\n"); break; } @@ -2219,7 +2263,7 @@ err: RUN_UNLOCK(sc); if (error) - DPRINTF("WME update failed\n"); + RUN_DPRINTF(sc, RUN_DEBUG_USB, "WME update failed\n"); return (error); } @@ -2261,11 +2305,12 @@ mode = RT2860_MODE_AES_CCMP; break; default: - DPRINTF("undefined case\n"); + RUN_DPRINTF(sc, RUN_DEBUG_KEY, "undefined case\n"); return; } - DPRINTFN(1, "associd=%x, keyix=%d, mode=%x, type=%s, tx=%s, rx=%s\n", + RUN_DPRINTF(sc, RUN_DEBUG_KEY, + "associd=%x, keyix=%d, mode=%x, type=%s, tx=%s, rx=%s\n", associd, k->wk_keyix, mode, (k->wk_flags & IEEE80211_KEY_GROUP) ? "group" : "pairwise", (k->wk_flags & IEEE80211_KEY_XMIT) ? "on" : "off", @@ -2357,7 +2402,7 @@ uint32_t i; i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_KEY, "cmdq_store=%d\n", i); sc->cmdq[i].func = run_key_set_cb; sc->cmdq[i].arg0 = NULL; sc->cmdq[i].arg1 = vap; @@ -2396,13 +2441,14 @@ if (k->wk_flags & IEEE80211_KEY_GROUP) { /* remove group key */ - DPRINTF("removing group key\n"); + RUN_DPRINTF(sc, RUN_DEBUG_KEY, "removing group key\n"); run_read(sc, RT2860_SKEY_MODE_0_7, &attr); attr &= ~(0xf << (k->wk_keyix * 4)); run_write(sc, RT2860_SKEY_MODE_0_7, attr); } else { /* remove pairwise key */ - DPRINTF("removing key for wcid %x\n", k->wk_pad); + RUN_DPRINTF(sc, RUN_DEBUG_KEY, + "removing key for wcid %x\n", k->wk_pad); /* matching wcid was written to wk_pad in run_key_set() */ wcid = k->wk_pad; run_read(sc, RT2860_WCID_ATTR(wcid), &attr); @@ -2432,7 +2478,7 @@ * So, use atomic instead. */ i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_KEY, "cmdq_store=%d\n", i); sc->cmdq[i].func = run_key_delete_cb; sc->cmdq[i].arg0 = NULL; sc->cmdq[i].arg1 = sc; @@ -2504,7 +2550,7 @@ for (;;) { /* drain Tx status FIFO (maxsize = 16) */ run_read(sc, RT2860_TX_STAT_FIFO, &stat); - DPRINTFN(4, "tx stat 0x%08x\n", stat); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "tx stat 0x%08x\n", stat); if (!(stat & RT2860_TXQ_VLD)) break; @@ -2543,7 +2589,7 @@ (*wstat)[RUN_RETRY] += retry; } } - DPRINTFN(3, "count=%d\n", sc->fifo_cnt); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "count=%d\n", sc->fifo_cnt); sc->fifo_cnt = 0; } @@ -2587,9 +2633,9 @@ txs->nframes = txs->nretries + txs->nsuccess + le16toh(sta[0].error.fail); - DPRINTFN(3, "retrycnt=%d success=%d failcnt=%d\n", - txs->nretries, txs->nsuccess, - le16toh(sta[0].error.fail)); + RUN_DPRINTF(sc, RUN_DEBUG_RATE, + "retrycnt=%d success=%d failcnt=%d\n", + txs->nretries, txs->nsuccess, le16toh(sta[0].error.fail)); } else { wstat = &(sc->wcid_stats[RUN_AID2WCID(ni->ni_associd)]); @@ -2600,7 +2646,8 @@ txs->nretries = (*wstat)[RUN_RETRY]; txs->nsuccess = (*wstat)[RUN_SUCCESS]; txs->nframes = (*wstat)[RUN_TXCNT]; - DPRINTFN(3, "retrycnt=%d txcnt=%d success=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_RATE, + "retrycnt=%d txcnt=%d success=%d\n", txs->nretries, txs->nframes, txs->nsuccess); memset(wstat, 0, sizeof(*wstat)); @@ -2612,7 +2659,7 @@ fail: RUN_UNLOCK(sc); - DPRINTFN(3, "ridx=%d\n", rn->amrr_ridx); + RUN_DPRINTF(sc, RUN_DEBUG_RATE, "ridx=%d\n", rn->amrr_ridx); } static void @@ -2660,7 +2707,7 @@ * Need to defer. */ uint32_t cnt = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", cnt); + RUN_DPRINTF(sc, RUN_DEBUG_STATE, "cmdq_store=%d\n", cnt); sc->cmdq[cnt].func = run_newassoc_cb; sc->cmdq[cnt].arg0 = NULL; sc->cmdq[cnt].arg1 = ni; @@ -2668,7 +2715,8 @@ ieee80211_runtask(ic, &sc->cmdq_task); } - DPRINTF("new assoc isnew=%d associd=%x addr=%s\n", + RUN_DPRINTF(sc, RUN_DEBUG_STATE, + "new assoc isnew=%d associd=%x addr=%s\n", isnew, ni->ni_associd, ether_sprintf(ni->ni_macaddr)); for (i = 0; i < rs->rs_nrates; i++) { @@ -2691,7 +2739,8 @@ /* no basic rate found, use mandatory one */ rn->ctl_ridx[i] = rt2860_rates[ridx].ctl_ridx; } - DPRINTF("rate=0x%02x ridx=%d ctl_ridx=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_STATE | RUN_DEBUG_RATE, + "rate=0x%02x ridx=%d ctl_ridx=%d\n", rs->rs_rates[i], rn->ridx[i], rn->ctl_ridx[i]); } rate = vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)].mgmtrate; @@ -2699,7 +2748,8 @@ if (rt2860_rates[ridx].rate == rate) break; rn->mgt_ridx = ridx; - DPRINTF("rate=%d, mgmt_ridx=%d\n", rate, rn->mgt_ridx); + RUN_DPRINTF(sc, RUN_DEBUG_STATE | RUN_DEBUG_RATE, + "rate=%d, mgmt_ridx=%d\n", rate, rn->mgt_ridx); RUN_LOCK(sc); if(sc->ratectl_run != RUN_RATECTL_OFF) @@ -2746,7 +2796,8 @@ rx_tstamp = le64toh(rx_tstamp); if (ni_tstamp >= rx_tstamp) { - DPRINTF("ibss merge, tsf %ju tstamp %ju\n", + RUN_DPRINTF(sc, RUN_DEBUG_RECV | RUN_DEBUG_BEACON, + "ibss merge, tsf %ju tstamp %ju\n", (uintmax_t)rx_tstamp, (uintmax_t)ni_tstamp); (void) ieee80211_ibss_merge(ni); } @@ -2776,7 +2827,8 @@ if (__predict_false(len > dmalen)) { m_freem(m); counter_u64_add(ic->ic_ierrors, 1); - DPRINTF("bad RXWI length %u > %u\n", len, dmalen); + RUN_DPRINTF(sc, RUN_DEBUG_RECV, + "bad RXWI length %u > %u\n", len, dmalen); return; } /* Rx descriptor is located at the end */ @@ -2786,7 +2838,8 @@ if (__predict_false(flags & (RT2860_RX_CRCERR | RT2860_RX_ICVERR))) { m_freem(m); counter_u64_add(ic->ic_ierrors, 1); - DPRINTF("%s error.\n", (flags & RT2860_RX_CRCERR)?"CRC":"ICV"); + RUN_DPRINTF(sc, RUN_DEBUG_RECV, "%s error.\n", + (flags & RT2860_RX_CRCERR)?"CRC":"ICV"); return; } @@ -2801,7 +2854,8 @@ } if (flags & RT2860_RX_L2PAD) { - DPRINTFN(8, "received RT2860_RX_L2PAD frame\n"); + RUN_DPRINTF(sc, RUN_DEBUG_RECV, + "received RT2860_RX_L2PAD frame\n"); len += 2; } @@ -2815,7 +2869,8 @@ rxwi->keyidx); m_freem(m); counter_u64_add(ic->ic_ierrors, 1); - DPRINTF("MIC error. Someone is lying.\n"); + RUN_DPRINTF(sc, RUN_DEBUG_RECV, + "MIC error. Someone is lying.\n"); return; } @@ -2896,11 +2951,13 @@ switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: - DPRINTFN(15, "rx done, actlen=%d\n", xferlen); + RUN_DPRINTF(sc, RUN_DEBUG_RECV, + "rx done, actlen=%d\n", xferlen); if (xferlen < (int)(sizeof(uint32_t) + rxwisize + sizeof(struct rt2870_rxd))) { - DPRINTF("xfer too short %d\n", xferlen); + RUN_DPRINTF(sc, RUN_DEBUG_RECV_DESC | RUN_DEBUG_USB, + "xfer too short %d\n", xferlen); goto tr_setup; } @@ -2915,7 +2972,8 @@ MJUMPAGESIZE /* xfer can be bigger than MCLBYTES */); } if (sc->rx_m == NULL) { - DPRINTF("could not allocate mbuf - idle with stall\n"); + RUN_DPRINTF(sc, RUN_DEBUG_RECV | RUN_DEBUG_RECV_DESC, + "could not allocate mbuf - idle with stall\n"); counter_u64_add(ic->ic_ierrors, 1); usbd_xfer_set_stall(xfer); usbd_xfer_set_frames(xfer, 0); @@ -2963,11 +3021,13 @@ if ((dmalen >= (uint32_t)-8) || (dmalen == 0) || ((dmalen & 3) != 0)) { - DPRINTF("bad DMA length %u\n", dmalen); + RUN_DPRINTF(sc, RUN_DEBUG_RECV_DESC | RUN_DEBUG_USB, + "bad DMA length %u\n", dmalen); break; } if ((dmalen + 8) > (uint32_t)xferlen) { - DPRINTF("bad DMA length %u > %d\n", + RUN_DPRINTF(sc, RUN_DEBUG_RECV_DESC | RUN_DEBUG_USB, + "bad DMA length %u > %d\n", dmalen + 8, xferlen); break; } @@ -2985,7 +3045,8 @@ /* copy aggregated frames to another mbuf */ m0 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); if (__predict_false(m0 == NULL)) { - DPRINTF("could not allocate mbuf\n"); + RUN_DPRINTF(sc, RUN_DEBUG_RECV_DESC, + "could not allocate mbuf\n"); counter_u64_add(ic->ic_ierrors, 1); break; } @@ -3038,8 +3099,8 @@ switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: - DPRINTFN(11, "transfer complete: %d " - "bytes @ index %d\n", actlen, index); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_USB, + "transfer complete: %d bytes @ index %d\n", actlen, index); data = usbd_xfer_get_priv(xfer); run_tx_free(pq, data, 0); @@ -3059,8 +3120,8 @@ sizeof(data->desc) + sizeof(uint32_t) : sizeof(data->desc); if ((m->m_pkthdr.len + size + 3 + 8) > RUN_MAX_TXSZ) { - DPRINTF("data overflow, %u bytes\n", - m->m_pkthdr.len); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT_DESC | RUN_DEBUG_USB, + "data overflow, %u bytes\n", m->m_pkthdr.len); run_tx_free(pq, data, 1); goto tr_setup; } @@ -3093,7 +3154,8 @@ ieee80211_radiotap_tx(vap, m); } - DPRINTFN(11, "sending frame len=%u/%u @ index %d\n", + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_USB, + "sending frame len=%u/%u @ index %d\n", m->m_pkthdr.len, size, index); usbd_xfer_set_frame_len(xfer, 0, size); @@ -3104,8 +3166,8 @@ break; default: - DPRINTF("USB transfer error, %s\n", - usbd_errstr(error)); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_USB, + "USB transfer error, %s\n", usbd_errstr(error)); data = usbd_xfer_get_priv(xfer); @@ -3123,7 +3185,8 @@ if (error == USB_ERR_TIMEOUT) { device_printf(sc->sc_dev, "device timeout\n"); uint32_t i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_USB, + "cmdq_store=%d\n", i); sc->cmdq[i].func = run_usb_timeout_cb; sc->cmdq[i].arg0 = vap; ieee80211_runtask(ic, &sc->cmdq_task); @@ -3294,7 +3357,7 @@ } qflags = (qid < 4) ? RT2860_TX_QSEL_EDCA : RT2860_TX_QSEL_HCCA; - DPRINTFN(8, "qos %d\tqid %d\ttid %d\tqflags %x\n", + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "qos %d\tqid %d\ttid %d\tqflags %x\n", qos, qid, tid, qflags); chan = (ni->ni_chan != IEEE80211_CHAN_ANYC)?ni->ni_chan:ic->ic_curchan; @@ -3327,7 +3390,7 @@ /* reserve slots for mgmt packets, just in case */ if (sc->sc_epq[qid].tx_nfree < 3) { - DPRINTFN(10, "tx ring %d is full\n", qid); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "tx ring %d is full\n", qid); return (-1); } @@ -3391,7 +3454,7 @@ * with a non-sleepable lock, tcpinp. So, need to defer. */ uint32_t i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTFN(6, "cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "cmdq_store=%d\n", i); sc->cmdq[i].func = run_drain_fifo; sc->cmdq[i].arg0 = sc; ieee80211_runtask(ic, &sc->cmdq_task); @@ -3402,7 +3465,8 @@ usbd_transfer_start(sc->sc_xfer[qid]); - DPRINTFN(8, "sending data frame len=%d rate=%d qid=%d\n", + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, + "sending data frame len=%d rate=%d qid=%d\n", m->m_pkthdr.len + (int)(sizeof(struct rt2870_txd) + sizeof(struct rt2860_txwi)), rt2860_rates[ridx].rate, qid); @@ -3464,9 +3528,9 @@ run_set_tx_desc(sc, data); - DPRINTFN(10, "sending mgt frame len=%d rate=%d\n", m->m_pkthdr.len + - (int)(sizeof(struct rt2870_txd) + sizeof(struct rt2860_txwi)), - rt2860_rates[ridx].rate); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "sending mgt frame len=%d rate=%d\n", + m->m_pkthdr.len + (int)(sizeof(struct rt2870_txd) + + sizeof(struct rt2860_txwi)), rt2860_rates[ridx].rate); STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); @@ -3527,7 +3591,7 @@ } if (mprot == NULL) { if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1); - DPRINTF("could not allocate mbuf\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "could not allocate mbuf\n"); return (ENOBUFS); } @@ -3553,7 +3617,7 @@ run_set_tx_desc(sc, data); - DPRINTFN(1, "sending prot len=%u rate=%u\n", + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "sending prot len=%u rate=%u\n", m->m_pkthdr.len, rate); STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); @@ -3608,7 +3672,8 @@ if (sc->sc_epq[0].tx_nfree == 0) { /* let caller free mbuf */ - DPRINTF("sending raw frame, but tx ring is full\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, + "sending raw frame, but tx ring is full\n"); return (EIO); } data = STAILQ_FIRST(&sc->sc_epq[0].tx_fh); @@ -3632,7 +3697,7 @@ run_set_tx_desc(sc, data); - DPRINTFN(10, "sending raw frame len=%u rate=%u\n", + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "sending raw frame len=%u rate=%u\n", m->m_pkthdr.len, rate); STAILQ_INSERT_TAIL(&sc->sc_epq[0].tx_qh, data, next); @@ -3660,13 +3725,13 @@ if (params == NULL) { /* tx mgt packet */ if ((error = run_tx_mgt(sc, m, ni)) != 0) { - DPRINTF("mgt tx failed\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "mgt tx failed\n"); goto done; } } else { /* tx raw packet with param */ if ((error = run_tx_param(sc, m, ni, params)) != 0) { - DPRINTF("tx with param failed\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT, "tx with param failed\n"); goto done; } } @@ -4882,7 +4947,7 @@ ieee80211_beacon_update(ni, rvp->beacon_mbuf, mcast); i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_BEACON, "cmdq_store=%d\n", i); sc->cmdq[i].func = run_update_beacon_cb; sc->cmdq[i].arg0 = vap; ieee80211_runtask(ic, &sc->cmdq_task); @@ -4948,7 +5013,7 @@ uint32_t i; i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_BEACON, "cmdq_store=%d\n", i); sc->cmdq[i].func = run_updateprot_cb; sc->cmdq[i].arg0 = ic; ieee80211_runtask(ic, &sc->cmdq_task); @@ -4990,11 +5055,13 @@ vap->iv_opmode != IEEE80211_M_STA) run_reset_livelock(sc); else if (vap->iv_state == IEEE80211_S_SCAN) { - DPRINTF("timeout caused by scan\n"); + RUN_DPRINTF(sc, RUN_DEBUG_USB | RUN_DEBUG_STATE, + "timeout caused by scan\n"); /* cancel bgscan */ ieee80211_cancel_scan(vap); } else - DPRINTF("timeout by unknown cause\n"); + RUN_DPRINTF(sc, RUN_DEBUG_USB | RUN_DEBUG_STATE, + "timeout by unknown cause\n"); } static void @@ -5010,9 +5077,10 @@ * crazy if protection is enabled. Reset MAC/BBP for a while */ run_read(sc, RT2860_DEBUG, &tmp); - DPRINTFN(3, "debug reg %08x\n", tmp); + RUN_DPRINTF(sc, RUN_DEBUG_RESET, "debug reg %08x\n", tmp); if ((tmp & (1 << 29)) && (tmp & (1 << 7 | 1 << 5))) { - DPRINTF("CTS-to-self livelock detected\n"); + RUN_DPRINTF(sc, RUN_DEBUG_RESET, + "CTS-to-self livelock detected\n"); run_write(sc, RT2860_MAC_SYS_CTRL, RT2860_MAC_SRST); run_delay(sc, 1); run_write(sc, RT2860_MAC_SYS_CTRL, @@ -5033,8 +5101,8 @@ run_write(sc, RT2860_RX_FILTR_CFG, tmp); - DPRINTF("%s promiscuous mode\n", (sc->sc_ic.ic_promisc > 0) ? - "entering" : "leaving"); + RUN_DPRINTF(sc, RUN_DEBUG_RECV, "%s promiscuous mode\n", + (sc->sc_ic.ic_promisc > 0) ? "entering" : "leaving"); } static void @@ -5057,8 +5125,8 @@ struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); uint32_t tmp; - DPRINTF("rvp_id=%d ic_opmode=%d\n", RUN_VAP(vap)->rvp_id, - ic->ic_opmode); + RUN_DPRINTF(sc, RUN_DEBUG_BEACON, "rvp_id=%d ic_opmode=%d\n", + RUN_VAP(vap)->rvp_id, ic->ic_opmode); run_read(sc, RT2860_BCN_TIME_CFG, &tmp); tmp &= ~0x1fffff; @@ -5084,7 +5152,8 @@ /* SYNC with nobody */ tmp |= 3 << RT2860_TSF_SYNC_MODE_SHIFT; } else { - DPRINTF("Enabling TSF failed. undefined opmode\n"); + RUN_DPRINTF(sc, RUN_DEBUG_BEACON, + "Enabling TSF failed. undefined opmode\n"); return; } @@ -5194,7 +5263,7 @@ uint32_t i; i = RUN_CMDQ_GET(&sc->cmdq_store); - DPRINTF("cmdq_store=%d\n", i); + RUN_DPRINTF(sc, RUN_DEBUG_BEACON, "cmdq_store=%d\n", i); sc->cmdq[i].func = run_updateslot_cb; sc->cmdq[i].arg0 = ic; ieee80211_runtask(ic, &sc->cmdq_task); @@ -6213,17 +6282,20 @@ /* wait for pending Tx to complete */ for (ntries = 0; ntries < 100; ntries++) { if (run_read(sc, RT2860_TXRXQ_PCNT, &tmp) != 0) { - DPRINTF("Cannot read Tx queue count\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_RESET, + "Cannot read Tx queue count\n"); break; } if ((tmp & RT2860_TX2Q_PCNT_MASK) == 0) { - DPRINTF("All Tx cleared\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_RESET, + "All Tx cleared\n"); break; } run_delay(sc, 10); } if (ntries >= 100) - DPRINTF("There are still pending Tx\n"); + RUN_DPRINTF(sc, RUN_DEBUG_XMIT | RUN_DEBUG_RESET, + "There are still pending Tx\n"); run_delay(sc, 10); run_write(sc, RT2860_USB_DMA_CFG, 0);