PERFORCE change 130276 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Wed Dec 5 09:18:26 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=130276
Change 130276 by hselasky at hselasky_laptop001 on 2007/12/05 17:17:48
Code size reduction. Factor out code. Maybe more factorization and
simplification can be done? That needs to be checked by a
FreeBSD IEEE80211 expert.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/if_rum.c#19 edit
.. //depot/projects/usb/src/sys/dev/usb/if_ural.c#43 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/if_rum.c#19 (text+ko) ====
@@ -137,7 +137,7 @@
static uint8_t rum_cfg_bbp_init(struct rum_softc *sc);
static uint8_t rum_cfg_bbp_read(struct rum_softc *sc, uint8_t reg);
static uint8_t rum_plcp_signal(uint16_t rate);
-static void rum_bulk_write_callback_sub(struct usbd_xfer *xfer, struct mbuf *m, struct ieee80211_node *ni, uint32_t flags, uint16_t rate);
+static uint8_t rum_bulk_write_callback_sub(struct usbd_xfer *xfer, struct mbuf *m, struct ieee80211_node *ni, uint32_t flags, uint16_t rate);
static void rum_cfg_amrr_start(struct rum_softc *sc);
static void rum_cfg_bbp_write(struct rum_softc *sc, uint8_t reg, uint8_t val);
static void rum_cfg_do_request(struct rum_softc *sc, usb_device_request_t *req, void *data);
@@ -1310,16 +1310,79 @@
return;
}
-static void
+/*------------------------------------------------------------------------*
+ * rum_bulk_write_callback_sub
+ *
+ * Returns:
+ * 0: Success
+ * Else: Failure
+ *------------------------------------------------------------------------*/
+static uint8_t
rum_bulk_write_callback_sub(struct usbd_xfer *xfer, struct mbuf *m,
- struct ieee80211_node *ni, uint32_t flags,
- uint16_t rate)
+ struct ieee80211_node *ni, uint32_t flags, uint16_t rate)
{
struct rum_softc *sc = xfer->priv_sc;
struct ieee80211com *ic = &(sc->sc_ic);
+ struct ieee80211_frame *wh;
+ struct ieee80211_key *k;
uint32_t temp_len;
+ uint16_t dur;
uint8_t align;
+ uint8_t type;
+ uint8_t sub_type;
+
+ wh = mtod(m, struct ieee80211_frame *);
+ if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
+ k = ieee80211_crypto_encap(ic, ni, m);
+ if (k == NULL) {
+ return (1);
+ }
+ /*
+ * packet header may have moved, reset our
+ * local pointer
+ */
+ wh = mtod(m, struct ieee80211_frame *);
+ }
+ if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
+
+ type = (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
+ sub_type = (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
+
+ if (type == IEEE80211_FC0_TYPE_DATA) {
+
+ flags |= (RT2573_TX_NEED_ACK |
+ RT2573_TX_MORE_FRAG);
+
+ dur = rum_txtime(sc, RUM_ACK_SIZE, rum_ack_rate(ic, rate),
+ ic->ic_flags) + sc->sc_sifs;
+
+ USETW(wh->i_dur, dur);
+
+ } else if ((type == IEEE80211_FC0_TYPE_MGT) &&
+ (sub_type == IEEE80211_FC0_SUBTYPE_BEACON)) {
+
+ /* do nothing */
+
+ } else {
+
+ flags |= RT2573_TX_NEED_ACK;
+
+ dur = rum_txtime(sc, RUM_ACK_SIZE, rum_ack_rate(ic, rate),
+ ic->ic_flags) + sc->sc_sifs;
+
+ USETW(wh->i_dur, dur);
+
+ /*
+ * tell hardware to add timestamp for probe
+ * responses
+ */
+ if ((type == IEEE80211_FC0_TYPE_MGT) &&
+ (sub_type == IEEE80211_FC0_SUBTYPE_PROBE_RESP)) {
+ flags |= RT2573_TX_TIMESTAMP;
+ }
+ }
+ }
ic->ic_lastdata = ticks;
if (m->m_pkthdr.len > MCLBYTES) {
@@ -1375,7 +1438,7 @@
}
xfer->frlengths[0] = temp_len;
usbd_start_hardware(xfer);
- return;
+ return (0);
}
static void
@@ -1384,13 +1447,9 @@
struct rum_softc *sc = xfer->priv_sc;
struct ieee80211com *ic = &(sc->sc_ic);
struct ifnet *ifp = sc->sc_ic.ic_ifp;
- struct ieee80211_frame *wh;
struct ieee80211_node *ni = NULL;
- struct ieee80211_key *k;
struct ether_header *eh;
struct mbuf *m = NULL;
- uint32_t flags;
- uint16_t dur;
uint16_t rate;
switch (USBD_GET_STATE(xfer)) {
@@ -1411,8 +1470,6 @@
*/
goto done;
}
- flags = 0;
-
IF_DEQUEUE(&(ic->ic_mgtq), m);
if (m) {
@@ -1425,40 +1482,9 @@
}
rate = (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2);
- wh = mtod(m, struct ieee80211_frame *);
-
- if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
- k = ieee80211_crypto_encap(ic, ni, m);
- if (k == NULL) {
- goto error;
- }
- /*
- * packet header may have moved, reset our
- * local pointer
- */
- wh = mtod(m, struct ieee80211_frame *);
+ if (rum_bulk_write_callback_sub(xfer, m, ni, 0, rate)) {
+ goto error;
}
- if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
-
- flags |= RT2573_TX_NEED_ACK;
-
- dur = rum_txtime(sc, RUM_ACK_SIZE, rum_ack_rate(ic, rate),
- ic->ic_flags) + sc->sc_sifs;
- USETW(wh->i_dur, dur);
-
- /*
- * tell hardware to add timestamp for probe
- * responses
- */
- if ((wh->i_fc[0] &
- (IEEE80211_FC0_TYPE_MASK |
- IEEE80211_FC0_SUBTYPE_MASK)) ==
- (IEEE80211_FC0_TYPE_MGT |
- IEEE80211_FC0_SUBTYPE_PROBE_RESP)) {
- flags |= RT2573_TX_TIMESTAMP;
- }
- }
- rum_bulk_write_callback_sub(xfer, m, ni, flags, rate);
goto done;
}
if (ic->ic_state != IEEE80211_S_RUN) {
@@ -1496,8 +1522,6 @@
if (bpf_peers_present(ic->ic_rawbpf)) {
bpf_mtap(ic->ic_rawbpf, m);
}
- wh = mtod(m, struct ieee80211_frame *);
-
if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE)
rate = ic->ic_fixed_rate;
else
@@ -1505,27 +1529,9 @@
rate &= IEEE80211_RATE_VAL;
- if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
- k = ieee80211_crypto_encap(ic, ni, m);
- if (k == NULL) {
- goto error;
- }
- /*
- * packet header may have moved, reset our
- * local pointer
- */
- wh = mtod(m, struct ieee80211_frame *);
+ if (rum_bulk_write_callback_sub(xfer, m, ni, 0, rate)) {
+ goto error;
}
- if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
- flags |= (RT2573_TX_NEED_ACK |
- RT2573_TX_MORE_FRAG);
-
- dur = rum_txtime(sc, RUM_ACK_SIZE, rum_ack_rate(ic, rate),
- ic->ic_flags) + sc->sc_sifs;
-
- USETW(wh->i_dur, dur);
- }
- rum_bulk_write_callback_sub(xfer, m, ni, flags, rate);
goto done;
}
done:
==== //depot/projects/usb/src/sys/dev/usb/if_ural.c#43 (text+ko) ====
@@ -1394,16 +1394,75 @@
/*------------------------------------------------------------------------*
* ural_bulk_write_callback - data write "thread"
+ *
+ * Returns:
+ * 0: Success
+ * Else: Error
*------------------------------------------------------------------------*/
-static void
+static uint8_t
ural_bulk_write_callback_sub(struct usbd_xfer *xfer, struct mbuf *m,
- struct ieee80211_node *ni, uint32_t flags,
- uint16_t rate)
+ struct ieee80211_node *ni, uint32_t flags, uint16_t rate)
{
struct ural_softc *sc = xfer->priv_sc;
struct ieee80211com *ic = &(sc->sc_ic);
+ struct ieee80211_frame *wh;
+ struct ieee80211_key *k;
uint32_t temp_len;
+ uint16_t dur;
+ uint8_t type;
+ uint8_t sub_type;
+ wh = mtod(m, struct ieee80211_frame *);
+
+ if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
+ k = ieee80211_crypto_encap(ic, ni, m);
+ if (k == NULL) {
+ return (1);
+ }
+ /*
+ * packet header may have moved, reset our
+ * local pointer
+ */
+ wh = mtod(m, struct ieee80211_frame *);
+ }
+ if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
+
+ type = (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
+ sub_type = (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
+
+ if (type == IEEE80211_FC0_TYPE_DATA) {
+
+ flags |= RAL_TX_ACK;
+ flags |= RAL_TX_RETRY(7);
+
+ dur = ural_txtime(sc, RAL_ACK_SIZE, ural_ack_rate(ic, rate),
+ ic->ic_flags) + RAL_SIFS;
+ USETW(wh->i_dur, dur);
+
+ } else if ((type == IEEE80211_FC0_TYPE_MGT) &&
+ (sub_type == IEEE80211_FC0_SUBTYPE_BEACON)) {
+
+ /* do nothing */
+
+ } else {
+
+ flags |= RAL_TX_ACK;
+
+ dur = ural_txtime
+ (sc, RAL_ACK_SIZE, rate, ic->ic_flags) + RAL_SIFS;
+
+ USETW(wh->i_dur, dur);
+
+ /*
+ * tell hardware to add timestamp for probe
+ * responses
+ */
+ if ((type == IEEE80211_FC0_TYPE_MGT) &&
+ (sub_type == IEEE80211_FC0_SUBTYPE_PROBE_RESP)) {
+ flags |= RAL_TX_TIMESTAMP;
+ }
+ }
+ }
ic->ic_lastdata = ticks;
if (m->m_pkthdr.len > RAL_FRAME_SIZE) {
@@ -1459,7 +1518,7 @@
ieee80211_free_node(ni);
}
usbd_start_hardware(xfer);
- return;
+ return (0);
}
static void
@@ -1468,13 +1527,9 @@
struct ural_softc *sc = xfer->priv_sc;
struct ieee80211com *ic = &(sc->sc_ic);
struct ifnet *ifp = sc->sc_ic.ic_ifp;
- struct ieee80211_frame *wh;
struct ieee80211_node *ni = NULL;
- struct ieee80211_key *k;
struct ether_header *eh;
struct mbuf *m = NULL;
- uint32_t flags;
- uint16_t dur;
uint16_t rate;
switch (USBD_GET_STATE(xfer)) {
@@ -1511,12 +1566,12 @@
m = sc->sc_bcn_mbuf;
sc->sc_bcn_mbuf = NULL;
- ural_bulk_write_callback_sub
- (xfer, m, NULL, sc->sc_bcn_flags, sc->sc_bcn_rate);
+ if (ural_bulk_write_callback_sub
+ (xfer, m, NULL, sc->sc_bcn_flags, sc->sc_bcn_rate)) {
+ goto error;
+ }
goto done;
}
- flags = 0;
-
IF_DEQUEUE(&(ic->ic_mgtq), m);
if (m) {
@@ -1529,41 +1584,9 @@
}
rate = (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2);
- wh = mtod(m, struct ieee80211_frame *);
-
- if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
- k = ieee80211_crypto_encap(ic, ni, m);
- if (k == NULL) {
- goto error;
- }
- /*
- * packet header may have moved, reset our
- * local pointer
- */
- wh = mtod(m, struct ieee80211_frame *);
+ if (ural_bulk_write_callback_sub(xfer, m, ni, 0, rate)) {
+ goto error;
}
- if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
-
- flags |= RAL_TX_ACK;
-
- dur = ural_txtime
- (sc, RAL_ACK_SIZE, rate, ic->ic_flags) + RAL_SIFS;
-
- USETW(wh->i_dur, dur);
-
- /*
- * tell hardware to add timestamp for probe
- * responses
- */
- if ((wh->i_fc[0] &
- (IEEE80211_FC0_TYPE_MASK |
- IEEE80211_FC0_SUBTYPE_MASK)) ==
- (IEEE80211_FC0_TYPE_MGT |
- IEEE80211_FC0_SUBTYPE_PROBE_RESP)) {
- flags |= RAL_TX_TIMESTAMP;
- }
- }
- ural_bulk_write_callback_sub(xfer, m, ni, flags, rate);
goto done;
}
if (ic->ic_state != IEEE80211_S_RUN) {
@@ -1601,8 +1624,6 @@
if (bpf_peers_present(ic->ic_rawbpf)) {
bpf_mtap(ic->ic_rawbpf, m);
}
- wh = mtod(m, struct ieee80211_frame *);
-
if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE)
rate = ic->ic_fixed_rate;
else
@@ -1610,26 +1631,9 @@
rate &= IEEE80211_RATE_VAL;
- if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
- k = ieee80211_crypto_encap(ic, ni, m);
- if (k == NULL) {
- goto error;
- }
- /*
- * packet header may have moved, reset our
- * local pointer
- */
- wh = mtod(m, struct ieee80211_frame *);
+ if (ural_bulk_write_callback_sub(xfer, m, ni, 0, rate)) {
+ goto error;
}
- if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
- flags |= RAL_TX_ACK;
- flags |= RAL_TX_RETRY(7);
-
- dur = ural_txtime(sc, RAL_ACK_SIZE, ural_ack_rate(ic, rate),
- ic->ic_flags) + RAL_SIFS;
- USETW(wh->i_dur, dur);
- }
- ural_bulk_write_callback_sub(xfer, m, ni, flags, rate);
goto done;
}
done:
More information about the p4-projects
mailing list