diff options
author | Damien Bergamini <damien@cvs.openbsd.org> | 2009-06-01 08:51:23 +0000 |
---|---|---|
committer | Damien Bergamini <damien@cvs.openbsd.org> | 2009-06-01 08:51:23 +0000 |
commit | d972bdce914871c816c113441032f85a6059863c (patch) | |
tree | a6cafa7dcfa500906141c2e38d6db75094acea4e /sys/dev/usb | |
parent | 57ed4c986aa98917472cfac3de2c948e71d2ad60 (diff) |
- cleanup tx path
- nitemize
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/if_zyd.c | 179 |
1 files changed, 67 insertions, 112 deletions
diff --git a/sys/dev/usb/if_zyd.c b/sys/dev/usb/if_zyd.c index 93a5680ec21..0b4c9271526 100644 --- a/sys/dev/usb/if_zyd.c +++ b/sys/dev/usb/if_zyd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_zyd.c,v 1.77 2009/06/01 08:43:20 damien Exp $ */ +/* $OpenBSD: if_zyd.c,v 1.78 2009/06/01 08:51:22 damien Exp $ */ /*- * Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr> @@ -228,7 +228,7 @@ void zyd_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); void zyd_rx_data(struct zyd_softc *, const uint8_t *, uint16_t); void zyd_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status); void zyd_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status); -int zyd_tx_data(struct zyd_softc *, struct mbuf *, +int zyd_tx(struct zyd_softc *, struct mbuf *, struct ieee80211_node *); void zyd_start(struct ifnet *); void zyd_watchdog(struct ifnet *); @@ -702,7 +702,7 @@ zyd_task(void *arg) case IEEE80211_S_SCAN: zyd_set_chan(sc, ic->ic_bss->ni_chan); - timeout_add(&sc->scan_to, hz / 5); + timeout_add_msec(&sc->scan_to, 200); break; case IEEE80211_S_AUTH: @@ -909,26 +909,24 @@ zyd_unlock_phy(struct zyd_softc *sc) int zyd_rfmd_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_RFMD_PHY; static const uint32_t rfini[] = ZYD_RFMD_RF; int i, error; /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; } /* init RFMD radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } return 0; -#undef N } int @@ -962,7 +960,6 @@ zyd_rfmd_set_channel(struct zyd_rf *rf, uint8_t chan) int zyd_al2230_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY; static const struct zyd_phy_pair phy2230s[] = ZYD_AL2230S_PHY_INIT; @@ -970,53 +967,48 @@ zyd_al2230_init(struct zyd_rf *rf) int i, error; /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; } - if (sc->rf_rev == ZYD_RF_AL2230S) { - for (i = 0; i < N(phy2230s); i++) { + for (i = 0; i < nitems(phy2230s); i++) { error = zyd_write16(sc, phy2230s[i].reg, phy2230s[i].val); if (error != 0) return error; } } - /* init AL2230 radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } return 0; -#undef N } int zyd_al2230_init_b(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY_B; static const uint32_t rfini[] = ZYD_AL2230_RF_B; int i, error; /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; } /* init AL2230 radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } return 0; -#undef N } int @@ -1055,7 +1047,6 @@ zyd_al2230_set_channel(struct zyd_rf *rf, uint8_t chan) int zyd_al7230B_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini_1[] = ZYD_AL7230B_PHY_1; static const struct zyd_phy_pair phyini_2[] = ZYD_AL7230B_PHY_2; @@ -1067,36 +1058,35 @@ zyd_al7230B_init(struct zyd_rf *rf) /* for AL7230B, PHY and RF need to be initialized in "phases" */ /* init RF-dependent PHY registers, part one */ - for (i = 0; i < N(phyini_1); i++) { + for (i = 0; i < nitems(phyini_1); i++) { error = zyd_write16(sc, phyini_1[i].reg, phyini_1[i].val); if (error != 0) return error; } /* init AL7230B radio, part one */ - for (i = 0; i < N(rfini_1); i++) { + for (i = 0; i < nitems(rfini_1); i++) { if ((error = zyd_rfwrite(sc, rfini_1[i])) != 0) return error; } /* init RF-dependent PHY registers, part two */ - for (i = 0; i < N(phyini_2); i++) { + for (i = 0; i < nitems(phyini_2); i++) { error = zyd_write16(sc, phyini_2[i].reg, phyini_2[i].val); if (error != 0) return error; } /* init AL7230B radio, part two */ - for (i = 0; i < N(rfini_2); i++) { + for (i = 0; i < nitems(rfini_2); i++) { if ((error = zyd_rfwrite(sc, rfini_2[i])) != 0) return error; } /* init RF-dependent PHY registers, part three */ - for (i = 0; i < N(phyini_3); i++) { + for (i = 0; i < nitems(phyini_3); i++) { error = zyd_write16(sc, phyini_3[i].reg, phyini_3[i].val); if (error != 0) return error; } return 0; -#undef N } int @@ -1113,7 +1103,6 @@ zyd_al7230B_switch_radio(struct zyd_rf *rf, int on) int zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct { uint32_t r1, r2; @@ -1124,7 +1113,7 @@ zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan) (void)zyd_write16(sc, ZYD_CR240, 0x57); (void)zyd_write16(sc, ZYD_CR251, 0x2f); - for (i = 0; i < N(rfsc); i++) { + for (i = 0; i < nitems(rfsc); i++) { if ((error = zyd_rfwrite(sc, rfsc[i])) != 0) return error; } @@ -1144,7 +1133,6 @@ zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan) (void)zyd_write16(sc, ZYD_CR240, 0x08); return 0; -#undef N } /* @@ -1153,7 +1141,6 @@ zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan) int zyd_al2210_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_AL2210_PHY; static const uint32_t rfini[] = ZYD_AL2210_RF; @@ -1163,13 +1150,13 @@ zyd_al2210_init(struct zyd_rf *rf) (void)zyd_write32(sc, ZYD_CR18, 2); /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; } /* init AL2210 radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } @@ -1183,7 +1170,6 @@ zyd_al2210_init(struct zyd_rf *rf) (void)zyd_write32(sc, ZYD_CR18, 3); return 0; -#undef N } int @@ -1225,25 +1211,23 @@ zyd_al2210_set_channel(struct zyd_rf *rf, uint8_t chan) int zyd_gct_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_GCT_PHY; static const uint32_t rfini[] = ZYD_GCT_RF; int i, error; /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; } /* init cgt radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } return 0; -#undef N } int @@ -1273,7 +1257,6 @@ zyd_gct_set_channel(struct zyd_rf *rf, uint8_t chan) int zyd_maxim_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_MAXIM_PHY; static const uint32_t rfini[] = ZYD_MAXIM_RF; @@ -1281,7 +1264,7 @@ zyd_maxim_init(struct zyd_rf *rf) int i, error; /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; @@ -1290,7 +1273,7 @@ zyd_maxim_init(struct zyd_rf *rf) (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4)); /* init maxim radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } @@ -1298,7 +1281,6 @@ zyd_maxim_init(struct zyd_rf *rf) (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4)); return 0; -#undef N } int @@ -1312,7 +1294,6 @@ zyd_maxim_switch_radio(struct zyd_rf *rf, int on) int zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_MAXIM_PHY; static const uint32_t rfini[] = ZYD_MAXIM_RF; @@ -1328,7 +1309,7 @@ zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan) */ /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; @@ -1341,7 +1322,7 @@ zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan) (void)zyd_rfwrite(sc, rfprog[chan - 1].r2); /* init maxim radio - skipping the two first values */ - for (i = 2; i < N(rfini); i++) { + for (i = 2; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } @@ -1349,7 +1330,6 @@ zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan) (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4)); return 0; -#undef N } /* @@ -1358,7 +1338,6 @@ zyd_maxim_set_channel(struct zyd_rf *rf, uint8_t chan) int zyd_maxim2_init(struct zyd_rf *rf) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY; static const uint32_t rfini[] = ZYD_MAXIM2_RF; @@ -1366,7 +1345,7 @@ zyd_maxim2_init(struct zyd_rf *rf) int i, error; /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; @@ -1375,7 +1354,7 @@ zyd_maxim2_init(struct zyd_rf *rf) (void)zyd_write16(sc, ZYD_CR203, tmp & ~(1 << 4)); /* init maxim2 radio */ - for (i = 0; i < N(rfini); i++) { + for (i = 0; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } @@ -1383,7 +1362,6 @@ zyd_maxim2_init(struct zyd_rf *rf) (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4)); return 0; -#undef N } int @@ -1397,7 +1375,6 @@ zyd_maxim2_switch_radio(struct zyd_rf *rf, int on) int zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan) { -#define N(a) (sizeof (a) / sizeof ((a)[0])) struct zyd_softc *sc = rf->rf_sc; static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY; static const uint32_t rfini[] = ZYD_MAXIM2_RF; @@ -1413,7 +1390,7 @@ zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan) */ /* init RF-dependent PHY registers */ - for (i = 0; i < N(phyini); i++) { + for (i = 0; i < nitems(phyini); i++) { error = zyd_write16(sc, phyini[i].reg, phyini[i].val); if (error != 0) return error; @@ -1426,7 +1403,7 @@ zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan) (void)zyd_rfwrite(sc, rfprog[chan - 1].r2); /* init maxim2 radio - skipping the two first values */ - for (i = 2; i < N(rfini); i++) { + for (i = 2; i < nitems(rfini); i++) { if ((error = zyd_rfwrite(sc, rfini[i])) != 0) return error; } @@ -1434,7 +1411,6 @@ zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan) (void)zyd_write16(sc, ZYD_CR203, tmp | (1 << 4)); return 0; -#undef N } int @@ -1452,7 +1428,6 @@ zyd_rf_attach(struct zyd_softc *sc, uint8_t type) rf->width = 24; /* 24-bit RF values */ break; case ZYD_RF_AL2230: - case ZYD_RF_AL2230S: if (sc->mac_rev == ZYD_ZD1211B) rf->init = zyd_al2230_init_b; else @@ -1505,7 +1480,7 @@ zyd_rf_name(uint8_t type) static const char * const zyd_rfs[] = { "unknown", "unknown", "UW2451", "UCHIP", "AL2230", "AL7230B", "THETA", "AL2210", "MAXIM_NEW", "GCT", - "AL2230S", "RALINK", "INTERSIL", "RFMD", "MAXIM_NEW2", + "AL2230S", "RALINK", "INTERSIL", "RFMD", "MAXIM_NEW2", "PHILIPS" }; return zyd_rfs[(type > 15) ? 0 : type]; @@ -2105,7 +2080,7 @@ zyd_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) } int -zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) +zyd_tx(struct zyd_softc *sc, struct mbuf *m, struct ieee80211_node *ni) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; @@ -2117,16 +2092,13 @@ zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) uint16_t pktlen; usbd_status error; - wh = mtod(m0, struct ieee80211_frame *); + wh = mtod(m, struct ieee80211_frame *); if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { k = ieee80211_get_txkey(ic, wh, ni); - - if ((m0 = ieee80211_encrypt(ic, m0, k)) == NULL) + if ((m = ieee80211_encrypt(ic, m, k)) == NULL) return ENOBUFS; - - /* packet header may have moved, reset our local pointer */ - wh = mtod(m0, struct ieee80211_frame *); + wh = mtod(m, struct ieee80211_frame *); } /* pickup a rate */ @@ -2149,8 +2121,8 @@ zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) data->ni = ni; - xferlen = sizeof (struct zyd_tx_desc) + m0->m_pkthdr.len; - totlen = m0->m_pkthdr.len + IEEE80211_CRC_LEN; + xferlen = sizeof (struct zyd_tx_desc) + m->m_pkthdr.len; + totlen = m->m_pkthdr.len + IEEE80211_CRC_LEN; /* fill Tx descriptor */ desc->len = htole16(totlen); @@ -2209,7 +2181,7 @@ zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) mb.m_data = (caddr_t)tap; mb.m_len = sc->sc_txtap_len; - mb.m_next = m0; + mb.m_next = m; mb.m_nextpkt = NULL; mb.m_type = 0; mb.m_flags = 0; @@ -2217,13 +2189,13 @@ zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) } #endif - m_copydata(m0, 0, m0->m_pkthdr.len, + m_copydata(m, 0, m->m_pkthdr.len, data->buf + sizeof (struct zyd_tx_desc)); DPRINTFN(10, ("%s: sending data frame len=%u rate=%u xferlen=%u\n", - sc->sc_dev.dv_xname, m0->m_pkthdr.len, rate, xferlen)); + sc->sc_dev.dv_xname, m->m_pkthdr.len, rate, xferlen)); - m_freem(m0); /* mbuf no longer needed */ + m_freem(m); /* mbuf no longer needed */ usbd_setup_xfer(data->xfer, sc->zyd_ep[ZYD_ENDPT_BOUT], data, data->buf, xferlen, USBD_FORCE_SHORT_XFER | USBD_NO_COPY, @@ -2244,61 +2216,44 @@ zyd_start(struct ifnet *ifp) struct zyd_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_node *ni; - struct mbuf *m0; + struct mbuf *m; - /* - * net80211 may still try to send management frames even if the - * IFF_RUNNING flag is not set... - */ if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) return; for (;;) { - IF_POLL(&ic->ic_mgtq, m0); - if (m0 != NULL) { - if (sc->tx_queued >= ZYD_TX_LIST_CNT) { - ifp->if_flags |= IFF_OACTIVE; - break; - } - IF_DEQUEUE(&ic->ic_mgtq, m0); + if (sc->tx_queued >= ZYD_TX_LIST_CNT) { + ifp->if_flags |= IFF_OACTIVE; + break; + } + /* send pending management frames first */ + IF_DEQUEUE(&ic->ic_mgtq, m); + if (m != NULL) { + ni = (void *)m->m_pkthdr.rcvif; + goto sendit; + } + if (ic->ic_state != IEEE80211_S_RUN) + break; - ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif; - m0->m_pkthdr.rcvif = NULL; + /* encapsulate and send data frames */ + IFQ_DEQUEUE(&ifp->if_snd, m); + if (m == NULL) + break; #if NBPFILTER > 0 - if (ic->ic_rawbpf != NULL) - bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT); + if (ifp->if_bpf != NULL) + bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT); #endif - if (zyd_tx_data(sc, m0, ni) != 0) - break; - } else { - if (ic->ic_state != IEEE80211_S_RUN) - break; - IFQ_POLL(&ifp->if_snd, m0); - if (m0 == NULL) - break; - if (sc->tx_queued >= ZYD_TX_LIST_CNT) { - ifp->if_flags |= IFF_OACTIVE; - break; - } - IFQ_DEQUEUE(&ifp->if_snd, m0); + if ((m = ieee80211_encap(ifp, m, &ni)) == NULL) + continue; +sendit: #if NBPFILTER > 0 - if (ifp->if_bpf != NULL) - bpf_mtap(ifp->if_bpf, m0, BPF_DIRECTION_OUT); + if (ic->ic_rawbpf != NULL) + bpf_mtap(ic->ic_rawbpf, m, BPF_DIRECTION_OUT); #endif - if ((m0 = ieee80211_encap(ifp, m0, &ni)) == NULL) { - ifp->if_oerrors++; - continue; - } -#if NBPFILTER > 0 - if (ic->ic_rawbpf != NULL) - bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT); -#endif - if (zyd_tx_data(sc, m0, ni) != 0) { - if (ni != NULL) - ieee80211_release_node(ic, ni); - ifp->if_oerrors++; - break; - } + if (zyd_tx(sc, m, ni) != 0) { + ieee80211_release_node(ic, ni); + ifp->if_oerrors++; + continue; } sc->tx_timer = 5; |