Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/dev/usb Do not require node pointers in every mbuf
details: https://anonhg.NetBSD.org/src-all/rev/a9b26797de83
branches: trunk
changeset: 371592:a9b26797de83
user: Martin Husemann <martin%NetBSD.org@localhost>
date: Sun Oct 24 13:24:14 2021 +0200
description:
Do not require node pointers in every mbuf
Broadcast/multicast and management frames should work without a concrete
VAP or nodeinfo.
diffstat:
sys/dev/usb/usbwifi.c | 156 ++++++++++++++++++++++++-------------------------
1 files changed, 75 insertions(+), 81 deletions(-)
diffs (truncated from 310 to 300 lines):
diff -r bcd021ee34bd -r a9b26797de83 sys/dev/usb/usbwifi.c
--- a/sys/dev/usb/usbwifi.c Sun Oct 24 13:22:24 2021 +0200
+++ b/sys/dev/usb/usbwifi.c Sun Oct 24 13:24:14 2021 +0200
@@ -775,7 +775,7 @@
USBWIFIHIST_FUNC();
struct mbuf *m = NULL;
struct ieee80211_node *ni;
- struct ieee80211vap *vap = NULL;
+ struct ieee80211vap *vap;
struct ieee80211_frame *wh;
struct usbwifi_cdata *cdata;
struct usbwifi_single_chain_data *s_chain;
@@ -798,13 +798,12 @@
break;
/* Encapsulate and send data frames. */
+ vap = NULL;
ni = M_GETCTX(m, struct ieee80211_node *);
- KASSERTMSG(ni != NULL, "wifi mbuf w/o node: %p", m);
- M_CLEARCTX(m);
- vap = ni->ni_vap;
- KASSERTMSG(vap != NULL, "wifi mbuf w/o VAP, mbuf: %p node: %p",
- m, ni);
-
+ if (ni != NULL) {
+ M_CLEARCTX(m);
+ vap = ni->ni_vap;
+ }
wh = mtod(m, struct ieee80211_frame *);
type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
qid = WME_AC_BE;
@@ -822,7 +821,8 @@
length = uwo_tx_prepare(uw, c, qid);
if (length == 0) {
DPRINTF("uwo_tx_prepare gave zero length", 0, 0, 0, 0);
- if_statinc(vap->iv_ifp, if_oerrors);
+ if (vap != NULL)
+ if_statinc(vap->iv_ifp, if_oerrors);
c->uwc_ni = NULL;
c->uwc_mbuf = NULL;
break;
@@ -830,7 +830,8 @@
if (__predict_false(c->uwc_xfer == NULL)) {
DPRINTF("uwc_xfer is NULL", 0, 0, 0, 0);
- if_statinc(vap->iv_ifp, if_oerrors);
+ if (vap != NULL)
+ if_statinc(vap->iv_ifp, if_oerrors);
c->uwc_ni = NULL;
c->uwc_mbuf = NULL;
break;
@@ -844,7 +845,8 @@
if (err != USBD_IN_PROGRESS) {
DPRINTF("usbd_transfer on %#jx for %ju bytes: %jd",
(uintptr_t)c->uwc_buf, length, err, 0);
- if_statinc(vap->iv_ifp, if_oerrors);
+ if (vap != NULL)
+ if_statinc(vap->iv_ifp, if_oerrors);
break;
}
done_transmit = true;
@@ -855,7 +857,8 @@
* If there's a BPF listener, bounce a copy of this frame
* to him.
*/
- bpf_mtap(vap->iv_ifp, m, BPF_D_OUT);
+ if (vap != NULL)
+ bpf_mtap(vap->iv_ifp, m, BPF_D_OUT);
m_freem(m);
idx = (idx + 1) % uw->uw_tx_list_cnt;
@@ -888,19 +891,10 @@
usbwifi_transmit(struct ieee80211com *ic, struct mbuf *m)
{
struct usbwifi *uw = (struct usbwifi*)ic->ic_softc;
- struct ieee80211_node *ni;
- struct ieee80211vap *vap;
struct ieee80211_frame *wh;
unsigned qid, type;
/* Which queue should this mbuf go on? */
- ni = M_GETCTX(m, struct ieee80211_node *);
- KASSERTMSG(ni != NULL, "wifi mbuf w/o node: %p", m);
- M_CLEARCTX(m);
- vap = ni->ni_vap;
- KASSERTMSG(vap != NULL, "wifi mbuf w/o VAP, mbuf: %p node: %p",
- m, ni);
-
wh = mtod(m, struct ieee80211_frame *);
type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
qid = WME_AC_BE;
@@ -944,24 +938,24 @@
}
void
-usbwifi_busy(struct usbwifi *un)
+usbwifi_busy(struct usbwifi *uw)
{
- struct usbwifi_private * const unp = un->uw_pri;
+ struct usbwifi_private * const uwp = uw->uw_pri;
- usbwifi_isowned_core(un);
+ usbwifi_isowned_core(uw);
- unp->uwp_refcnt++;
+ uwp->uwp_refcnt++;
}
void
-usbwifi_unbusy(struct usbwifi *un)
+usbwifi_unbusy(struct usbwifi *uw)
{
- struct usbwifi_private * const unp = un->uw_pri;
+ struct usbwifi_private * const uwp = uw->uw_pri;
- usbwifi_isowned_core(un);
+ usbwifi_isowned_core(uw);
- if (--unp->uwp_refcnt < 0)
- cv_broadcast(&unp->uwp_detachcv);
+ if (--uwp->uwp_refcnt < 0)
+ cv_broadcast(&uwp->uwp_detachcv);
}
/*
@@ -1123,78 +1117,78 @@
/* Various accessors. */
void
-usbwifi_set_dying(struct usbwifi *un, bool dying)
+usbwifi_set_dying(struct usbwifi *uw, bool dying)
{
- un->uw_pri->uwp_dying = dying;
+ uw->uw_pri->uwp_dying = dying;
}
void *
-usbwifi_softc(struct usbwifi *un)
+usbwifi_softc(struct usbwifi *uw)
{
- return un->uw_sc;
+ return uw->uw_sc;
}
bool
-usbwifi_isdying(struct usbwifi *un)
+usbwifi_isdying(struct usbwifi *uw)
{
- return un->uw_pri == NULL || un->uw_pri->uwp_dying;
+ return uw->uw_pri == NULL || uw->uw_pri->uwp_dying;
}
/* Locking. */
void
-usbwifi_lock_core(struct usbwifi *un)
+usbwifi_lock_core(struct usbwifi *uw)
{
- mutex_enter(&un->uw_pri->uwp_core_lock);
+ mutex_enter(&uw->uw_pri->uwp_core_lock);
}
void
-usbwifi_unlock_core(struct usbwifi *un)
+usbwifi_unlock_core(struct usbwifi *uw)
{
- mutex_exit(&un->uw_pri->uwp_core_lock);
+ mutex_exit(&uw->uw_pri->uwp_core_lock);
}
kmutex_t *
-usbwifi_mutex_core(struct usbwifi *un)
+usbwifi_mutex_core(struct usbwifi *uw)
{
- return &un->uw_pri->uwp_core_lock;
+ return &uw->uw_pri->uwp_core_lock;
}
void
-usbwifi_lock_rx(struct usbwifi *un)
+usbwifi_lock_rx(struct usbwifi *uw)
{
- mutex_enter(&un->uw_pri->uwp_rxlock);
+ mutex_enter(&uw->uw_pri->uwp_rxlock);
}
void
-usbwifi_unlock_rx(struct usbwifi *un)
+usbwifi_unlock_rx(struct usbwifi *uw)
{
- mutex_exit(&un->uw_pri->uwp_rxlock);
+ mutex_exit(&uw->uw_pri->uwp_rxlock);
}
kmutex_t *
-usbwifi_mutex_rx(struct usbwifi *un)
+usbwifi_mutex_rx(struct usbwifi *uw)
{
- return &un->uw_pri->uwp_rxlock;
+ return &uw->uw_pri->uwp_rxlock;
}
void
-usbwifi_lock_tx(struct usbwifi *un)
+usbwifi_lock_tx(struct usbwifi *uw)
{
- mutex_enter(&un->uw_pri->uwp_txlock);
+ mutex_enter(&uw->uw_pri->uwp_txlock);
}
void
-usbwifi_unlock_tx(struct usbwifi *un)
+usbwifi_unlock_tx(struct usbwifi *uw)
{
- mutex_exit(&un->uw_pri->uwp_txlock);
+ mutex_exit(&uw->uw_pri->uwp_txlock);
}
kmutex_t *
-usbwifi_mutex_tx(struct usbwifi *un)
+usbwifi_mutex_tx(struct usbwifi *uw)
{
- return &un->uw_pri->uwp_txlock;
+ return &uw->uw_pri->uwp_txlock;
}
/* Autoconf management. */
@@ -1309,53 +1303,53 @@
usbwifi_detach(device_t self, int flags)
{
USBWIFIHIST_FUNC(); USBWIFIHIST_CALLED();
- struct usbwifi * const un = device_private(self);
- struct usbwifi_private * const unp = un->uw_pri;
+ struct usbwifi * const uw = device_private(self);
+ struct usbwifi_private * const uwp = uw->uw_pri;
/* Detached before attached finished, so just bail out. */
- if (unp == NULL || !unp->uwp_attached)
+ if (uwp == NULL || !uwp->uwp_attached)
return 0;
- mutex_enter(&unp->uwp_core_lock);
- unp->uwp_dying = true;
- mutex_exit(&unp->uwp_core_lock);
+ mutex_enter(&uwp->uwp_core_lock);
+ uwp->uwp_dying = true;
+ mutex_exit(&uwp->uwp_core_lock);
- ieee80211_ifdetach(&un->uw_ic);
+ ieee80211_ifdetach(&uw->uw_ic);
- callout_halt(&unp->uwp_stat_ch, NULL);
- usb_rem_task_wait(un->uw_udev, &unp->uwp_ticktask, USB_TASKQ_DRIVER,
+ callout_halt(&uwp->uwp_stat_ch, NULL);
+ usb_rem_task_wait(uw->uw_udev, &uwp->uwp_ticktask, USB_TASKQ_DRIVER,
NULL);
- mutex_enter(&unp->uwp_core_lock);
- unp->uwp_refcnt--;
- while (unp->uwp_refcnt >= 0) {
+ mutex_enter(&uwp->uwp_core_lock);
+ uwp->uwp_refcnt--;
+ while (uwp->uwp_refcnt >= 0) {
/* Wait for processes to go away */
- cv_wait(&unp->uwp_detachcv, &unp->uwp_core_lock);
+ cv_wait(&uwp->uwp_detachcv, &uwp->uwp_core_lock);
}
- mutex_exit(&unp->uwp_core_lock);
+ mutex_exit(&uwp->uwp_core_lock);
- usbwifi_rx_list_free(un);
- usbwifi_tx_list_free(un);
+ usbwifi_rx_list_free(uw);
+ usbwifi_tx_list_free(uw);
- callout_destroy(&unp->uwp_stat_ch);
+ callout_destroy(&uwp->uwp_stat_ch);
- cv_destroy(&unp->uwp_detachcv);
- mutex_destroy(&unp->uwp_core_lock);
- mutex_destroy(&unp->uwp_rxlock);
- mutex_destroy(&unp->uwp_txlock);
+ cv_destroy(&uwp->uwp_detachcv);
+ mutex_destroy(&uwp->uwp_core_lock);
+ mutex_destroy(&uwp->uwp_rxlock);
+ mutex_destroy(&uwp->uwp_txlock);
/* sendq destroy */
- for (int i = 0; i < un->uw_ic.ic_txstream; i++) {
- IFQ_PURGE(&unp->uwp_sendq[i]);
- IFQ_LOCK_DESTROY(&unp->uwp_sendq[i]);
+ for (int i = 0; i < uw->uw_ic.ic_txstream; i++) {
+ IFQ_PURGE(&uwp->uwp_sendq[i]);
+ IFQ_LOCK_DESTROY(&uwp->uwp_sendq[i]);
}
- pmf_device_deregister(un->uw_dev);
+ pmf_device_deregister(uw->uw_dev);
Home |
Main Index |
Thread Index |
Old Index