Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / net / wireless / marvell / mwifiex / 11n_aggr.c
blob46f41dbcf30ddc0d66d3794bade8722ff8dbc17b
1 /*
2 * NXP Wireless LAN device driver: 802.11n Aggregation
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * 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.
20 #include "decl.h"
21 #include "ioctl.h"
22 #include "util.h"
23 #include "fw.h"
24 #include "main.h"
25 #include "wmm.h"
26 #include "11n.h"
27 #include "11n_aggr.h"
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|...... ..|
46 static int
47 mwifiex_11n_form_amsdu_pkt(struct sk_buff *skb_aggr,
48 struct sk_buff *skb_src, int *pad)
51 int dt_offset;
52 struct rfc_1042_hdr snap = {
53 0xaa, /* LLC DSAP */
54 0xaa, /* LLC SSAP */
55 0x03, /* LLC CTRL */
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 = skb_put(skb_aggr, sizeof(*tx_header));
67 /* Copy DA and SA */
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 = ((struct ethhdr *)skb_src->data)->h_proto;
74 dt_offset += sizeof(__be16);
76 memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr));
78 skb_pull(skb_src, dt_offset);
80 /* Update Length field */
81 tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN);
83 /* Add payload */
84 skb_put_data(skb_aggr, skb_src->data, skb_src->len);
86 /* Add padding for new MSDU to start from 4 byte boundary */
87 *pad = (4 - ((unsigned long)skb_aggr->tail & 0x3)) % 4;
89 return skb_aggr->len + *pad;
93 * Adds TxPD to AMSDU header.
95 * Each AMSDU packet will contain one TxPD at the beginning,
96 * followed by multiple AMSDU subframes.
98 static void
99 mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv,
100 struct sk_buff *skb)
102 struct txpd *local_tx_pd;
103 struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
105 skb_push(skb, sizeof(*local_tx_pd));
107 local_tx_pd = (struct txpd *) skb->data;
108 memset(local_tx_pd, 0, sizeof(struct txpd));
110 /* Original priority has been overwritten */
111 local_tx_pd->priority = (u8) skb->priority;
112 local_tx_pd->pkt_delay_2ms =
113 mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
114 local_tx_pd->bss_num = priv->bss_num;
115 local_tx_pd->bss_type = priv->bss_type;
116 /* Always zero as the data is followed by struct txpd */
117 local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd));
118 local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
119 local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
120 sizeof(*local_tx_pd));
122 if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
123 local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
125 if (local_tx_pd->tx_control == 0)
126 /* TxCtrl set by user or default */
127 local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
129 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
130 priv->adapter->pps_uapsd_mode) {
131 if (true == mwifiex_check_last_packet_indication(priv)) {
132 priv->adapter->tx_lock_flag = true;
133 local_tx_pd->flags =
134 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
140 * Create aggregated packet.
142 * This function creates an aggregated MSDU packet, by combining buffers
143 * from the RA list. Each individual buffer is encapsulated as an AMSDU
144 * subframe and all such subframes are concatenated together to form the
145 * AMSDU packet.
147 * A TxPD is also added to the front of the resultant AMSDU packets for
148 * transmission. The resultant packets format is -
150 * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
151 * | TxPD |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
152 * | | 1 | 2 | .. | n |
153 * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
156 mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
157 struct mwifiex_ra_list_tbl *pra_list,
158 int ptrindex)
159 __releases(&priv->wmm.ra_list_spinlock)
161 struct mwifiex_adapter *adapter = priv->adapter;
162 struct sk_buff *skb_aggr, *skb_src;
163 struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
164 int pad = 0, aggr_num = 0, ret;
165 struct mwifiex_tx_param tx_param;
166 struct txpd *ptx_pd = NULL;
167 int headroom = adapter->intf_hdr_len;
169 skb_src = skb_peek(&pra_list->skb_head);
170 if (!skb_src) {
171 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
172 return 0;
175 tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
176 skb_aggr = mwifiex_alloc_dma_align_buf(adapter->tx_buf_size,
177 GFP_ATOMIC);
178 if (!skb_aggr) {
179 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
180 return -1;
183 /* skb_aggr->data already 64 byte align, just reserve bus interface
184 * header and txpd.
186 skb_reserve(skb_aggr, headroom + sizeof(struct txpd));
187 tx_info_aggr = MWIFIEX_SKB_TXCB(skb_aggr);
189 memset(tx_info_aggr, 0, sizeof(*tx_info_aggr));
190 tx_info_aggr->bss_type = tx_info_src->bss_type;
191 tx_info_aggr->bss_num = tx_info_src->bss_num;
193 if (tx_info_src->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
194 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
195 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
196 skb_aggr->priority = skb_src->priority;
197 skb_aggr->tstamp = skb_src->tstamp;
199 do {
200 /* Check if AMSDU can accommodate this MSDU */
201 if ((skb_aggr->len + skb_src->len + LLC_SNAP_LEN) >
202 adapter->tx_buf_size)
203 break;
205 skb_src = skb_dequeue(&pra_list->skb_head);
206 pra_list->total_pkt_count--;
207 atomic_dec(&priv->wmm.tx_pkts_queued);
208 aggr_num++;
209 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
210 mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
212 mwifiex_write_data_complete(adapter, skb_src, 0, 0);
214 spin_lock_bh(&priv->wmm.ra_list_spinlock);
216 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
217 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
218 return -1;
221 if (skb_tailroom(skb_aggr) < pad) {
222 pad = 0;
223 break;
225 skb_put(skb_aggr, pad);
227 skb_src = skb_peek(&pra_list->skb_head);
229 } while (skb_src);
231 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
233 /* Last AMSDU packet does not need padding */
234 skb_trim(skb_aggr, skb_aggr->len - pad);
236 /* Form AMSDU */
237 mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
238 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
239 ptx_pd = (struct txpd *)skb_aggr->data;
241 skb_push(skb_aggr, headroom);
242 tx_info_aggr->aggr_num = aggr_num * 2;
243 if (adapter->data_sent || adapter->tx_lock_flag) {
244 atomic_add(aggr_num * 2, &adapter->tx_queued);
245 skb_queue_tail(&adapter->tx_data_q, skb_aggr);
246 return 0;
249 if (skb_src)
250 tx_param.next_pkt_len = skb_src->len + sizeof(struct txpd);
251 else
252 tx_param.next_pkt_len = 0;
254 if (adapter->iface_type == MWIFIEX_USB) {
255 ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
256 skb_aggr, &tx_param);
257 } else {
259 ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
260 skb_aggr, &tx_param);
262 switch (ret) {
263 case -EBUSY:
264 spin_lock_bh(&priv->wmm.ra_list_spinlock);
265 if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
266 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
267 mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
268 return -1;
270 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
271 adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
272 priv->adapter->tx_lock_flag = false;
273 if (ptx_pd)
274 ptx_pd->flags = 0;
277 skb_queue_tail(&pra_list->skb_head, skb_aggr);
279 pra_list->total_pkt_count++;
281 atomic_inc(&priv->wmm.tx_pkts_queued);
283 tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
284 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
285 mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
286 break;
287 case -1:
288 mwifiex_dbg(adapter, ERROR, "%s: host_to_card failed: %#x\n",
289 __func__, ret);
290 adapter->dbg.num_tx_host_to_card_failure++;
291 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
292 return 0;
293 case -EINPROGRESS:
294 break;
295 case 0:
296 mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
297 break;
298 default:
299 break;
301 if (ret != -EBUSY) {
302 mwifiex_rotate_priolists(priv, pra_list, ptrindex);
305 return 0;