PERFORCE change 138962 for review
Sam Leffler
sam at FreeBSD.org
Sat Mar 29 21:31:48 PDT 2008
http://perforce.freebsd.org/chv.cgi?CH=138962
Change 138962 by sam at sam_ebb on 2008/03/30 04:31:16
o remove NBPFILTER compat stuff
o don't waste effort supporting h/w WEP; at 11b rates and
even really old cpu's it's hardly worth not doing it in the host
o use m_getcl and m_gethdr
o use conversion tables instead of open code in mapping a tx rate
to a firmware code
o misc style cleanups
Affected files ...
.. //depot/projects/vap/sys/dev/wi/if_wi.c#20 edit
.. //depot/projects/vap/sys/dev/wi/if_wivar.h#14 edit
Differences ...
==== //depot/projects/vap/sys/dev/wi/if_wi.c#20 (text+ko) ====
@@ -64,8 +64,6 @@
#define WI_HERMES_STATS_WAR /* Work around stats counter bug. */
-#define NBPFILTER 1
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/endian.h>
@@ -135,9 +133,6 @@
static void wi_tx_ex_intr(struct wi_softc *);
static void wi_info_intr(struct wi_softc *);
-static int wi_key_alloc(struct ieee80211vap *, const struct ieee80211_key *,
- ieee80211_keyix *, ieee80211_keyix *);
-
static int wi_write_txrate(struct wi_softc *, struct ieee80211vap *);
static int wi_write_wep(struct wi_softc *, struct ieee80211vap *);
static int wi_write_multi(struct wi_softc *);
@@ -180,7 +175,6 @@
static int wi_debug = 0;
SYSCTL_INT(_hw_wi, OID_AUTO, debug, CTLFLAG_RW, &wi_debug,
0, "control debugging printfs");
-
#define DPRINTF(X) if (wi_debug) printf X
#else
#define DPRINTF(X)
@@ -332,7 +326,6 @@
ic->ic_opmode = IEEE80211_M_STA;
ic->ic_caps = IEEE80211_C_PMGT
| IEEE80211_C_MONITOR
- | IEEE80211_C_WEP /* everyone supports WEP */
;
/*
@@ -449,7 +442,6 @@
ic->ic_vap_delete = wi_vap_delete;
ic->ic_update_mcast = wi_update_mcast;
-#if NBPFILTER > 0
bpfattach(ifp, DLT_IEEE802_11_RADIO,
sizeof(struct ieee80211_frame) + sizeof(sc->sc_tx_th));
/*
@@ -468,7 +460,6 @@
sc->sc_rx_th_len = roundup(sizeof(sc->sc_rx_th), sizeof(u_int32_t));
sc->sc_rx_th.wr_ihdr.it_len = htole16(sc->sc_rx_th_len);
sc->sc_rx_th.wr_ihdr.it_present = htole32(WI_RX_RADIOTAP_PRESENT);
-#endif
if (bootverbose)
ieee80211_announce(ic);
@@ -489,9 +480,7 @@
wi_stop_locked(sc, 0);
WI_UNLOCK(sc);
-#if NBPFILTER > 0
bpfdetach(ifp);
-#endif
ieee80211_ifdetach(&sc->sc_ic);
bus_teardown_intr(dev, sc->irq, sc->wi_intrhand);
@@ -520,8 +509,6 @@
vap = &wvp->wv_vap;
ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac);
- wvp->wv_key_alloc = vap->iv_key_alloc;
- vap->iv_key_alloc = wi_key_alloc;
vap->iv_max_aid = WI_MAX_AID;
switch (opmode) {
@@ -742,12 +729,11 @@
WI_LOCK(sc);
wi_write_val(sc, WI_RID_OWN_CHNL,
ieee80211_chan2ieee(ic, ic->ic_curchan));
-#if NBPFILTER > 0
+
sc->sc_tx_th.wt_chan_freq = sc->sc_rx_th.wr_chan_freq =
htole16(ic->ic_curchan->ic_freq);
sc->sc_tx_th.wt_chan_flags = sc->sc_rx_th.wr_chan_flags =
htole16(ic->ic_curchan->ic_flags);
-#endif
WI_UNLOCK(sc);
}
@@ -948,6 +934,7 @@
struct ieee80211_node *ni;
struct ieee80211_frame *wh;
struct mbuf *m0;
+ struct ieee80211_key *k;
struct wi_frame frmhdr;
int cur;
@@ -978,13 +965,10 @@
ieee80211_free_node(ni);
continue;
}
+
wh = mtod(m0, struct ieee80211_frame *);
frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX);
- /* XXX check key for SWCRYPT instead of using operating mode */
- if ((wh->i_fc[1] & IEEE80211_FC1_WEP) &&
- (sc->sc_encryption & HOST_ENCRYPT)) {
- struct ieee80211_key *k;
-
+ if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
k = ieee80211_crypto_encap(ni, m0);
if (k == NULL) {
ieee80211_free_node(ni);
@@ -993,13 +977,13 @@
}
frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT);
}
-#if NBPFILTER > 0
+
if (bpf_peers_present(ifp->if_bpf)) {
sc->sc_tx_th.wt_rate = ni->ni_txrate;
bpf_mtap2(ifp->if_bpf,
&sc->sc_tx_th, sc->sc_tx_th_len, m0);
}
-#endif
+
m_copydata(m0, 0, sizeof(struct ieee80211_frame),
(caddr_t)&frmhdr.wi_whdr);
m_adj(m0, sizeof(struct ieee80211_frame));
@@ -1058,6 +1042,7 @@
struct ieee80211com *ic = ni->ni_ic;
struct ifnet *ifp = ic->ic_ifp;
struct wi_softc *sc = ifp->if_softc;
+ struct ieee80211_key *k;
struct ieee80211_frame *wh;
struct wi_frame frmhdr;
int cur;
@@ -1086,27 +1071,19 @@
frmhdr.wi_tx_ctl = htole16(WI_ENC_TX_802_11|WI_TXCNTL_TX_EX);
if (params && (params->ibp_flags & IEEE80211_BPF_NOACK))
frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_ALTRTRY);
- /* XXX check key for SWCRYPT instead of using operating mode */
if ((wh->i_fc[1] & IEEE80211_FC1_WEP) &&
- (sc->sc_encryption & HOST_ENCRYPT)) {
- if (!params ||
- (params && (params->ibp_flags & IEEE80211_BPF_CRYPTO))) {
- struct ieee80211_key *k;
-
- k = ieee80211_crypto_encap(ni, m0);
- if (k == NULL) {
- rc = ENOMEM;
- goto out;
- }
- frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT);
+ (!params || (params && (params->ibp_flags & IEEE80211_BPF_CRYPTO)))) {
+ k = ieee80211_crypto_encap(ni, m0);
+ if (k == NULL) {
+ rc = ENOMEM;
+ goto out;
}
+ frmhdr.wi_tx_ctl |= htole16(WI_TXCNTL_NOCRYPT);
}
-#if NBPFILTER > 0
if (bpf_peers_present(ifp->if_bpf)) {
sc->sc_tx_th.wt_rate = ni->ni_txrate;
bpf_mtap2(ifp->if_bpf, &sc->sc_tx_th, sc->sc_tx_th_len, m0);
}
-#endif
m_copydata(m0, 0, sizeof(struct ieee80211_frame),
(caddr_t)&frmhdr.wi_whdr);
m_adj(m0, sizeof(struct ieee80211_frame));
@@ -1343,24 +1320,16 @@
len = 0;
}
- MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (off + len > MHLEN)
+ m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
+ else
+ m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL) {
CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
ifp->if_ierrors++;
DPRINTF(("wi_rx_intr: MGET failed\n"));
return;
}
- if (off + len > MHLEN) {
- MCLGET(m, M_DONTWAIT);
- if ((m->m_flags & M_EXT) == 0) {
- CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
- m_freem(m);
- ifp->if_ierrors++;
- DPRINTF(("wi_rx_intr: MCLGET failed\n"));
- return;
- }
- }
-
m->m_data += off - sizeof(struct ieee80211_frame);
memcpy(m->m_data, &frmhdr.wi_whdr, sizeof(struct ieee80211_frame));
wi_read_bap(sc, fid, sizeof(frmhdr),
@@ -1370,7 +1339,6 @@
CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_RX);
-#if NBPFILTER > 0
if (bpf_peers_present(ifp->if_bpf)) {
/* XXX replace divide by table */
sc->sc_rx_th.wr_rate = frmhdr.wi_rx_rate / 5;
@@ -1383,7 +1351,7 @@
sc->sc_rx_th.wr_flags |= IEEE80211_RADIOTAP_F_WEP;
bpf_mtap2(ifp->if_bpf, &sc->sc_rx_th, sc->sc_rx_th_len, m);
}
-#endif
+
/* synchronize driver's BSSID with firmware's BSSID */
wh = mtod(m, struct ieee80211_frame *);
dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
@@ -1413,7 +1381,6 @@
/* Read in the frame header */
if (wi_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) == 0) {
u_int16_t status = le16toh(frmhdr.wi_status);
-
/*
* Spontaneous station disconnects appear as xmit
* errors. Don't announce them and/or count them
@@ -1686,78 +1653,32 @@
static int
wi_write_txrate(struct wi_softc *sc, struct ieee80211vap *vap)
{
+ static const uint16_t lucent_rates[12] = {
+ [ 0] = 3, /* auto */
+ [ 1] = 1, /* 1Mb/s */
+ [ 2] = 2, /* 2Mb/s */
+ [ 5] = 4, /* 5.5Mb/s */
+ [11] = 5 /* 11Mb/s */
+ };
+ static const uint16_t intersil_rates[12] = {
+ [ 0] = 0xf, /* auto */
+ [ 1] = 0, /* 1Mb/s */
+ [ 2] = 1, /* 2Mb/s */
+ [ 5] = 2, /* 5.5Mb/s */
+ [11] = 3, /* 11Mb/s */
+ };
+ const uint16_t *rates = sc->sc_firmware_type == WI_LUCENT ?
+ lucent_rates : intersil_rates;
+ struct ieee80211com *ic = vap->iv_ic;
const struct ieee80211_txparam *tp;
- struct ieee80211com *ic = vap->iv_ic;
- int i;
- u_int16_t rate;
tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_bsschan)];
- if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
- rate = 0; /* auto */
- else
- rate = tp->ucastrate / 2;
-
- /* rate: 0, 1, 2, 5, 11 */
-
- switch (sc->sc_firmware_type) {
- case WI_LUCENT:
- switch (rate) {
- case 0: /* auto == 11mbps auto */
- rate = 3;
- break;
- /* case 1, 2 map to 1, 2*/
- case 5: /* 5.5Mbps -> 4 */
- rate = 4;
- break;
- case 11: /* 11mbps -> 5 */
- rate = 5;
- break;
- default:
- break;
- }
- break;
- default:
- /* Choose a bit according to this table.
- *
- * bit | data rate
- * ----+-------------------
- * 0 | 1Mbps
- * 1 | 2Mbps
- * 2 | 5.5Mbps
- * 3 | 11Mbps
- */
- for (i = 8; i > 0; i >>= 1) {
- if (rate >= i)
- break;
- }
- if (i == 0)
- rate = 0xf; /* auto */
- else
- rate = i;
- break;
- }
- return wi_write_val(sc, WI_RID_TX_RATE, rate);
+ return wi_write_val(sc, WI_RID_TX_RATE,
+ (tp->ucastrate == IEEE80211_FIXED_RATE_NONE ?
+ rates[0] : rates[tp->ucastrate / 2]));
}
static int
-wi_key_alloc(struct ieee80211vap *vap, const struct ieee80211_key *k,
- ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
-{
- struct wi_softc *sc = vap->iv_ic->ic_ifp->if_softc;
-
- /*
- * When doing host encryption of outbound frames fail requests
- * for keys that are not marked w/ the SWCRYPT flag so the
- * net80211 layer falls back to s/w crypto. Note that we also
- * fixup existing keys below to handle mode changes.
- */
- if ((sc->sc_encryption & HOST_ENCRYPT) &&
- (k->wk_flags & IEEE80211_KEY_SWCRYPT) == 0)
- return 0;
- return WI_VAP(vap)->wv_key_alloc(vap, k, keyix, rxkeyix);
-}
-
-static int
wi_write_wep(struct wi_softc *sc, struct ieee80211vap *vap)
{
int error = 0;
@@ -1816,47 +1737,9 @@
sc->sc_encryption = val;
if ((val & PRIVACY_INVOKED) == 0)
break;
- error = wi_write_val(sc, WI_RID_P2_TX_CRYPT_KEY,
- vap->iv_def_txkey);
- if (error)
- break;
- if (val & HOST_DECRYPT)
- break;
- /*
- * It seems that the firmware accept 104bit key only if
- * all the keys have 104bit length. We get the length of
- * the transmit key and use it for all other keys.
- * Perhaps we should use software WEP for such situation.
- */
- if (vap->iv_def_txkey != IEEE80211_KEYIX_NONE)
- keylen = vap->iv_nw_keys[vap->iv_def_txkey].wk_keylen;
- else /* XXX should not hapen */
- keylen = IEEE80211_WEP_KEYLEN;
- if (keylen > IEEE80211_WEP_KEYLEN)
- keylen = 13; /* 104bit keys */
- else
- keylen = IEEE80211_WEP_KEYLEN;
- for (i = 0; i < IEEE80211_WEP_NKID; i++) {
- error = wi_write_rid(sc, WI_RID_P2_CRYPT_KEY0 + i,
- vap->iv_nw_keys[i].wk_key, keylen);
- if (error)
- break;
- }
+ error = wi_write_val(sc, WI_RID_P2_TX_CRYPT_KEY, vap->iv_def_txkey);
break;
}
- /*
- * XXX horrible hack; insure pre-existing keys are
- * setup properly to do s/w crypto.
- */
- for (i = 0; i < IEEE80211_WEP_NKID; i++) {
- struct ieee80211_key *k = &vap->iv_nw_keys[i];
- if (k->wk_flags & IEEE80211_KEY_XMIT) {
- if (sc->sc_encryption & HOST_ENCRYPT)
- k->wk_flags |= IEEE80211_KEY_SWCRYPT;
- else
- k->wk_flags &= ~IEEE80211_KEY_SWCRYPT;
- }
- }
return error;
}
@@ -2125,9 +2008,9 @@
sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT,
&sc->iobase_rid, 0, ~0, (1 << 6),
rman_make_alignment_flags(1 << 6) | RF_ACTIVE);
- if (!sc->iobase) {
+ if (sc->iobase == NULL) {
device_printf(dev, "No I/O space?!\n");
- return (ENXIO);
+ return ENXIO;
}
sc->wi_io_addr = rman_get_start(sc->iobase);
@@ -2137,10 +2020,9 @@
sc->mem_rid = rid;
sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
&sc->mem_rid, RF_ACTIVE);
-
- if (!sc->mem) {
+ if (sc->mem == NULL) {
device_printf(dev, "No Mem space on prism2.5?\n");
- return (ENXIO);
+ return ENXIO;
}
sc->wi_btag = rman_get_bustag(sc->mem);
@@ -2151,17 +2033,15 @@
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
RF_ACTIVE |
((sc->wi_bus_type == WI_BUS_PCCARD) ? 0 : RF_SHAREABLE));
-
- if (!sc->irq) {
+ if (sc->irq == NULL) {
wi_free(dev);
device_printf(dev, "No irq?!\n");
- return (ENXIO);
+ return ENXIO;
}
sc->sc_dev = dev;
sc->sc_unit = device_get_unit(dev);
-
- return (0);
+ return 0;
}
void
@@ -2181,6 +2061,4 @@
bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem);
sc->mem = NULL;
}
-
- return;
}
==== //depot/projects/vap/sys/dev/wi/if_wivar.h#14 (text+ko) ====
@@ -64,9 +64,6 @@
struct mbuf *, int, int, int, u_int32_t);
int (*wv_newstate)(struct ieee80211vap *,
enum ieee80211_state, int);
- int (*wv_key_alloc)(struct ieee80211vap *,
- const struct ieee80211_key *,
- ieee80211_keyix *, ieee80211_keyix *);
};
#define WI_VAP(vap) ((struct wi_vap *)(vap))
More information about the p4-projects
mailing list