2 * Marvell Wireless LAN device driver: 802.11n Aggregation
4 * Copyright (C) 2011, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
30 * Creates an AMSDU subframe for aggregation into one AMSDU packet.
32 * The resultant AMSDU subframe format is -
34 * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+
35 * | DA | SA | Length | SNAP header | MSDU |
36 * | data[0..5] | data[6..11] | | | data[14..] |
37 * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+
38 * <--6-bytes--> <--6-bytes--> <--2-bytes--><--8-bytes--> <--n-bytes-->
40 * This function also computes the amount of padding required to make the
41 * buffer length multiple of 4 bytes.
43 * Data => |DA|SA|SNAP-TYPE|........ .|
44 * MSDU => |DA|SA|Length|SNAP|...... ..|
47 mwifiex_11n_form_amsdu_pkt(struct sk_buff *skb_aggr,
48 struct sk_buff *skb_src, int *pad)
52 struct rfc_1042_hdr snap = {
56 {0x00, 0x00, 0x00}, /* SNAP OUI */
57 0x0000 /* SNAP type */
59 * This field will be overwritten
60 * later with ethertype
63 struct tx_packet_hdr *tx_header;
65 tx_header = (void *)skb_put(skb_aggr, sizeof(*tx_header));
68 dt_offset = 2 * ETH_ALEN;
69 memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset);
71 /* Copy SNAP header */
72 snap.snap_type = *(u16 *) ((u8 *)skb_src->data + dt_offset);
73 dt_offset += sizeof(u16);
75 memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr));
77 skb_pull(skb_src, dt_offset);
79 /* Update Length field */
80 tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN);
83 memcpy(skb_put(skb_aggr, skb_src->len), skb_src->data, skb_src->len);
85 /* Add padding for new MSDU to start from 4 byte boundary */
86 *pad = (4 - ((unsigned long)skb_aggr->tail & 0x3)) % 4;
88 return skb_aggr->len + *pad;
92 * Adds TxPD to AMSDU header.
94 * Each AMSDU packet will contain one TxPD at the beginning,
95 * followed by multiple AMSDU subframes.
98 mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv,
101 struct txpd *local_tx_pd;
103 skb_push(skb, sizeof(*local_tx_pd));
105 local_tx_pd = (struct txpd *) skb->data;
106 memset(local_tx_pd, 0, sizeof(struct txpd));
108 /* Original priority has been overwritten */
109 local_tx_pd->priority = (u8) skb->priority;
110 local_tx_pd->pkt_delay_2ms =
111 mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
112 local_tx_pd->bss_num = priv->bss_num;
113 local_tx_pd->bss_type = priv->bss_type;
114 /* Always zero as the data is followed by struct txpd */
115 local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
116 local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
117 local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
118 sizeof(*local_tx_pd));
120 if (local_tx_pd->tx_control == 0)
121 /* TxCtrl set by user or default */
122 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
124 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
125 priv->adapter->pps_uapsd_mode) {
126 if (true == mwifiex_check_last_packet_indication(priv)) {
127 priv->adapter->tx_lock_flag = true;
129 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
135 * Create aggregated packet.
137 * This function creates an aggregated MSDU packet, by combining buffers
138 * from the RA list. Each individual buffer is encapsulated as an AMSDU
139 * subframe and all such subframes are concatenated together to form the
142 * A TxPD is also added to the front of the resultant AMSDU packets for
143 * transmission. The resultant packets format is -
145 * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
146 * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
147 * | | 1 | 2 | .. | n |
148 * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
151 mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
152 struct mwifiex_ra_list_tbl *pra_list,
153 int ptrindex, unsigned long ra_list_flags)
154 __releases(&priv->wmm.ra_list_spinlock)
156 struct mwifiex_adapter *adapter = priv->adapter;
157 struct sk_buff *skb_aggr, *skb_src;
158 struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
160 struct mwifiex_tx_param tx_param;
161 struct txpd *ptx_pd = NULL;
162 int headroom = adapter->iface_type == MWIFIEX_USB ? 0 : INTF_HEADER_LEN;
164 skb_src = skb_peek(&pra_list->skb_head);
166 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
171 tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
172 skb_aggr = dev_alloc_skb(adapter->tx_buf_size);
174 dev_err(adapter->dev, "%s: alloc skb_aggr\n", __func__);
175 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
179 skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
180 tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
182 tx_info_aggr->bss_type = tx_info_src->bss_type;
183 tx_info_aggr->bss_num = tx_info_src->bss_num;
184 skb_aggr->priority = skb_src->priority;
187 /* Check if AMSDU can accommodate this MSDU */
188 if (skb_tailroom(skb_aggr) < (skb_src->len + LLC_SNAP_LEN))
191 skb_src = skb_dequeue(&pra_list->skb_head);
193 pra_list->total_pkts_size -= skb_src->len;
195 atomic_dec(&priv->wmm.tx_pkts_queued);
197 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
199 mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
201 mwifiex_write_data_complete(adapter, skb_src, 0, 0);
203 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
205 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
206 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
211 if (skb_tailroom(skb_aggr) < pad) {
215 skb_put(skb_aggr, pad);
217 skb_src = skb_peek(&pra_list->skb_head);
221 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
223 /* Last AMSDU packet does not need padding */
224 skb_trim(skb_aggr, skb_aggr->len - pad);
227 mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
228 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
229 ptx_pd = (struct txpd *)skb_aggr->data;
231 skb_push(skb_aggr, headroom);
233 if (adapter->iface_type == MWIFIEX_USB) {
234 adapter->data_sent = true;
235 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA,
239 * Padding per MSDU will affect the length of next
240 * packet and hence the exact length of next packet
243 * Also, aggregation of transmission buffer, while
244 * downloading the data to the card, wont gain much
245 * on the AMSDU packets as the AMSDU packets utilizes
246 * the transmission buffer space to the maximum
247 * (adapter->tx_buf_size).
249 tx_param.next_pkt_len = 0;
251 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
252 skb_aggr, &tx_param);
256 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
257 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
258 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
260 mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
263 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
264 adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
265 priv->adapter->tx_lock_flag = false;
270 skb_queue_tail(&pra_list->skb_head, skb_aggr);
272 pra_list->total_pkts_size += skb_aggr->len;
274 atomic_inc(&priv->wmm.tx_pkts_queued);
276 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
277 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
279 dev_dbg(adapter->dev, "data: -EBUSY is returned\n");
282 if (adapter->iface_type != MWIFIEX_PCIE)
283 adapter->data_sent = false;
284 dev_err(adapter->dev, "%s: host_to_card failed: %#x\n",
286 adapter->dbg.num_tx_host_to_card_failure++;
287 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
290 if (adapter->iface_type != MWIFIEX_PCIE)
291 adapter->data_sent = false;
294 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
300 mwifiex_rotate_priolists(priv, pra_list, ptrindex);