[PATCH 2/5] Extract common data-tx code into separate function
Max Filippov
jcmvbkbc at gmail.com
Fri Jan 9 17:15:18 EET 2009
Extract common data-tx code into separate function
Signed-off-by: Max Filippov <jcmvbkbc at gmail.com>
---
stlc45xx.c | 167 +++++++++++++++++++----------------------------------------
1 files changed, 54 insertions(+), 113 deletions(-)
diff --git a/stlc45xx.c b/stlc45xx.c
index cf33031..4d96732 100644
--- a/stlc45xx.c
+++ b/stlc45xx.c
@@ -1798,41 +1798,14 @@ static void stlc45xx_tx_scan(struct stlc45xx *stlc)
/*
* caller must hold mutex
*/
-static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
+static int stlc45xx_alloc_and_tx_frame(struct stlc45xx *stlc,
+ struct sk_buff *skb, struct txbuffer **tx_entry,
+ u16 flags, u8 queue, bool use_lifetime)
{
- struct ieee80211_hdr *pspoll;
int payload_len, padding, i;
struct s_lm_data_out *data;
struct txbuffer *entry;
- DECLARE_MAC_BUF(mac);
- struct sk_buff *skb;
char *payload;
- u16 fc;
-
- skb = dev_alloc_skb(stlc->hw->extra_tx_headroom + 16);
- if (!skb) {
- stlc45xx_warning("failed to allocate pspoll frame");
- return -ENOMEM;
- }
- skb_reserve(skb, stlc->hw->extra_tx_headroom);
-
- pspoll = (struct ieee80211_hdr *) skb_put(skb, 16);
- memset(pspoll, 0, 16);
- fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL;
- if (powersave)
- fc |= IEEE80211_FCTL_PM;
- pspoll->frame_control = cpu_to_le16(fc);
- pspoll->duration_id = cpu_to_le16(stlc->aid);
-
- /* aid in PS-Poll has its two MSBs each set to 1 */
- pspoll->duration_id |= cpu_to_le16(1 << 15) | cpu_to_le16(1 << 14);
-
- memcpy(pspoll->addr1, stlc->bssid, ETH_ALEN);
- memcpy(pspoll->addr2, stlc->mac_addr, ETH_ALEN);
-
- stlc45xx_debug(DEBUG_PSM, "sending PS-Poll frame to %s (powersave %d, "
- "fc 0x%x, aid %d)", print_mac(mac, pspoll->addr1),
- powersave, fc, stlc->aid);
spin_lock_bh(&stlc->tx_lock);
@@ -1849,11 +1822,13 @@ static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
* But I'm too lazy and omit it for now.
*/
if (net_ratelimit())
- stlc45xx_warning("firmware tx buffer full is full "
- "for null frame");
+ stlc45xx_warning("firmware tx buffer full is full");
return -ENOSPC;
}
+ if (tx_entry)
+ *tx_entry = entry;
+
payload = skb->data;
payload_len = skb->len;
padding = (int) (skb->data - sizeof(*data)) & 3;
@@ -1862,7 +1837,10 @@ static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
entry->skb = skb;
entry->status_needed = false;
entry->handle = (u32) skb;
- entry->lifetime = jiffies + msecs_to_jiffies(TX_FRAME_LIFETIME);
+ if (use_lifetime)
+ entry->lifetime = jiffies + msecs_to_jiffies(TX_FRAME_LIFETIME);
+ else
+ entry->lifetime = 0;
stlc45xx_debug(DEBUG_TX, "tx data 0x%x (0x%p payload %d B "
"padding %d header_len %d)",
@@ -1875,9 +1853,9 @@ static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
memset(data, 0, entry->header_len);
if (padding)
- data->flags = LM_FLAG_ALIGN;
+ flags |= LM_FLAG_ALIGN;
- data->flags = LM_OUT_BURST;
+ data->flags = flags;
data->length = payload_len;
data->handle = entry->handle;
data->aid = 1;
@@ -1887,7 +1865,7 @@ static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
data->crypt_offset = 58;
data->keytype = 0;
data->keylen = 0;
- data->queue = LM_QUEUE_DATA3;
+ data->queue = queue;
data->backlog = 32;
data->antenna = 2;
data->cts = 3;
@@ -1908,6 +1886,44 @@ static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
return 0;
}
+/*
+ * caller must hold mutex
+ */
+static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
+{
+ struct ieee80211_hdr *pspoll;
+ DECLARE_MAC_BUF(mac);
+ struct sk_buff *skb;
+ u16 fc;
+
+ skb = dev_alloc_skb(stlc->hw->extra_tx_headroom + 16);
+ if (!skb) {
+ stlc45xx_warning("failed to allocate pspoll frame");
+ return -ENOMEM;
+ }
+ skb_reserve(skb, stlc->hw->extra_tx_headroom);
+
+ pspoll = (struct ieee80211_hdr *) skb_put(skb, 16);
+ memset(pspoll, 0, 16);
+ fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL;
+ if (powersave)
+ fc |= IEEE80211_FCTL_PM;
+ pspoll->frame_control = cpu_to_le16(fc);
+ pspoll->duration_id = cpu_to_le16(stlc->aid);
+
+ /* aid in PS-Poll has its two MSBs each set to 1 */
+ pspoll->duration_id |= cpu_to_le16(1 << 15) | cpu_to_le16(1 << 14);
+
+ memcpy(pspoll->addr1, stlc->bssid, ETH_ALEN);
+ memcpy(pspoll->addr2, stlc->mac_addr, ETH_ALEN);
+
+ stlc45xx_debug(DEBUG_PSM, "sending PS-Poll frame to %s (powersave %d, "
+ "fc 0x%x, aid %d)", print_mac(mac, pspoll->addr1),
+ powersave, fc, stlc->aid);
+
+ return stlc45xx_alloc_and_tx_frame(stlc, skb, NULL,
+ LM_OUT_BURST, LM_QUEUE_DATA3, true);
+}
/*
* caller must hold mutex
@@ -1917,12 +1933,8 @@ static int stlc45xx_tx_pspoll(struct stlc45xx *stlc, bool powersave)
static int stlc45xx_tx_nullfunc(struct stlc45xx *stlc, bool powersave)
{
struct ieee80211_hdr *nullfunc;
- int payload_len, padding, i;
- struct s_lm_data_out *data;
- struct txbuffer *entry;
DECLARE_MAC_BUF(mac);
struct sk_buff *skb;
- char *payload;
u16 fc;
skb = dev_alloc_skb(stlc->hw->extra_tx_headroom + 24);
@@ -1949,79 +1961,8 @@ static int stlc45xx_tx_nullfunc(struct stlc45xx *stlc, bool powersave)
"fc 0x%x)",
print_mac(mac, nullfunc->addr1), powersave, fc);
- spin_lock_bh(&stlc->tx_lock);
-
- entry = stlc45xx_txbuffer_alloc(stlc, skb->len);
-
- spin_unlock_bh(&stlc->tx_lock);
-
- if (!entry) {
- /*
- * The queue should be stopped before the firmware buffer
- * is full, so firmware buffer should always have enough
- * space.
- *
- * But I'm too lazy and omit it for now.
- */
- if (net_ratelimit())
- stlc45xx_warning("firmware tx buffer full is full "
- "for null frame");
- return -ENOSPC;
- }
-
- payload = skb->data;
- payload_len = skb->len;
- padding = (int) (skb->data - sizeof(*data)) & 3;
- entry->header_len = sizeof(*data) + padding;
-
- entry->skb = skb;
- entry->status_needed = false;
- entry->handle = (u32) skb;
- entry->lifetime = jiffies + msecs_to_jiffies(TX_FRAME_LIFETIME);
-
- stlc45xx_debug(DEBUG_TX, "tx data 0x%x (0x%p payload %d B "
- "padding %d header_len %d)",
- entry->handle, payload, payload_len, padding,
- entry->header_len);
- stlc45xx_dump(DEBUG_TX_CONTENT, payload, payload_len);
-
- data = (struct s_lm_data_out *) skb_push(skb, entry->header_len);
-
- memset(data, 0, entry->header_len);
-
- if (padding)
- data->flags = LM_FLAG_ALIGN;
-
- data->flags = LM_OUT_BURST;
- data->length = payload_len;
- data->handle = entry->handle;
- data->aid = 1;
- data->rts_retries = 7;
- data->retries = 7;
- data->aloft_ctrl = 0;
- data->crypt_offset = 58;
- data->keytype = 0;
- data->keylen = 0;
- data->queue = LM_QUEUE_DATA3;
- data->backlog = 32;
- data->antenna = 2;
- data->cts = 3;
- data->power = 127;
-
- for (i = 0; i < 8; i++)
- data->aloft[i] = 0;
-
- /*
- * check if there's enough space in tx buffer
- *
- * FIXME: ignored for now
- */
-
- stlc45xx_tx_frame(stlc, entry->start, skb->data, skb->len);
-
- list_add(&entry->tx_list, &stlc->tx_sent);
-
- return 0;
+ return stlc45xx_alloc_and_tx_frame(stlc, skb, NULL,
+ LM_OUT_BURST, LM_QUEUE_DATA3, true);
}
/* caller must hold mutex */
--
1.5.4.3
More information about the stlc45xx-devel
mailing list