Commit | Line | Data |
---|---|---|
838e4f44 AP |
1 | /* |
2 | * Marvell Wireless LAN device driver: AP TX and RX data handling | |
3 | * | |
4 | * Copyright (C) 2012, Marvell International Ltd. | |
5 | * | |
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. | |
13 | * | |
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. | |
18 | */ | |
19 | ||
20 | #include "decl.h" | |
21 | #include "ioctl.h" | |
22 | #include "main.h" | |
23 | #include "wmm.h" | |
d1cf3b95 AP |
24 | #include "11n_aggr.h" |
25 | #include "11n_rxreorder.h" | |
838e4f44 AP |
26 | |
27 | static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv, | |
28 | struct sk_buff *skb) | |
29 | { | |
30 | struct mwifiex_adapter *adapter = priv->adapter; | |
31 | struct uap_rxpd *uap_rx_pd; | |
32 | struct rx_packet_hdr *rx_pkt_hdr; | |
33 | struct sk_buff *new_skb; | |
34 | struct mwifiex_txinfo *tx_info; | |
35 | int hdr_chop; | |
36 | struct timeval tv; | |
37 | u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
38 | ||
39 | uap_rx_pd = (struct uap_rxpd *)(skb->data); | |
40 | rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset); | |
41 | ||
42 | if ((atomic_read(&adapter->pending_bridged_pkts) >= | |
43 | MWIFIEX_BRIDGED_PKTS_THRESHOLD)) { | |
44 | dev_err(priv->adapter->dev, | |
45 | "Tx: Bridge packet limit reached. Drop packet!\n"); | |
46 | kfree_skb(skb); | |
47 | return; | |
48 | } | |
49 | ||
50 | if (!memcmp(&rx_pkt_hdr->rfc1042_hdr, | |
51 | rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr))) | |
52 | /* Chop off the rxpd + the excess memory from | |
53 | * 802.2/llc/snap header that was removed. | |
54 | */ | |
55 | hdr_chop = (u8 *)eth_hdr - (u8 *)uap_rx_pd; | |
56 | else | |
57 | /* Chop off the rxpd */ | |
58 | hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd; | |
59 | ||
60 | /* Chop off the leading header bytes so the it points | |
61 | * to the start of either the reconstructed EthII frame | |
62 | * or the 802.2/llc/snap frame. | |
63 | */ | |
64 | skb_pull(skb, hdr_chop); | |
65 | ||
66 | if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) { | |
67 | dev_dbg(priv->adapter->dev, | |
68 | "data: Tx: insufficient skb headroom %d\n", | |
69 | skb_headroom(skb)); | |
70 | /* Insufficient skb headroom - allocate a new skb */ | |
71 | new_skb = | |
72 | skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN); | |
73 | if (unlikely(!new_skb)) { | |
74 | dev_err(priv->adapter->dev, | |
75 | "Tx: cannot allocate new_skb\n"); | |
76 | kfree_skb(skb); | |
77 | priv->stats.tx_dropped++; | |
78 | return; | |
79 | } | |
80 | ||
81 | kfree_skb(skb); | |
82 | skb = new_skb; | |
83 | dev_dbg(priv->adapter->dev, "info: new skb headroom %d\n", | |
84 | skb_headroom(skb)); | |
85 | } | |
86 | ||
87 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
88 | tx_info->bss_num = priv->bss_num; | |
89 | tx_info->bss_type = priv->bss_type; | |
90 | tx_info->flags |= MWIFIEX_BUF_FLAG_BRIDGED_PKT; | |
91 | ||
92 | do_gettimeofday(&tv); | |
93 | skb->tstamp = timeval_to_ktime(tv); | |
94 | mwifiex_wmm_add_buf_txqueue(priv, skb); | |
95 | atomic_inc(&adapter->tx_pending); | |
96 | atomic_inc(&adapter->pending_bridged_pkts); | |
97 | ||
98 | if ((atomic_read(&adapter->tx_pending) >= MAX_TX_PENDING)) { | |
99 | mwifiex_set_trans_start(priv->netdev); | |
100 | mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter); | |
101 | } | |
102 | return; | |
103 | } | |
104 | ||
105 | /* | |
106 | * This function contains logic for AP packet forwarding. | |
107 | * | |
108 | * If a packet is multicast/broadcast, it is sent to kernel/upper layer | |
109 | * as well as queued back to AP TX queue so that it can be sent to other | |
110 | * associated stations. | |
111 | * If a packet is unicast and RA is present in associated station list, | |
112 | * it is again requeued into AP TX queue. | |
113 | * If a packet is unicast and RA is not in associated station list, | |
114 | * packet is forwarded to kernel to handle routing logic. | |
115 | */ | |
116 | int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv, | |
117 | struct sk_buff *skb) | |
118 | { | |
119 | struct mwifiex_adapter *adapter = priv->adapter; | |
120 | struct uap_rxpd *uap_rx_pd; | |
121 | struct rx_packet_hdr *rx_pkt_hdr; | |
122 | u8 ra[ETH_ALEN]; | |
123 | struct sk_buff *skb_uap; | |
124 | ||
125 | uap_rx_pd = (struct uap_rxpd *)(skb->data); | |
126 | rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset); | |
127 | ||
128 | /* don't do packet forwarding in disconnected state */ | |
129 | if (!priv->media_connected) { | |
130 | dev_err(adapter->dev, "drop packet in disconnected state.\n"); | |
131 | dev_kfree_skb_any(skb); | |
132 | return 0; | |
133 | } | |
134 | ||
135 | memcpy(ra, rx_pkt_hdr->eth803_hdr.h_dest, ETH_ALEN); | |
136 | ||
137 | if (is_multicast_ether_addr(ra)) { | |
138 | skb_uap = skb_copy(skb, GFP_ATOMIC); | |
139 | mwifiex_uap_queue_bridged_pkt(priv, skb_uap); | |
140 | } else { | |
141 | if (mwifiex_get_sta_entry(priv, ra)) { | |
142 | /* Requeue Intra-BSS packet */ | |
143 | mwifiex_uap_queue_bridged_pkt(priv, skb); | |
144 | return 0; | |
145 | } | |
146 | } | |
147 | ||
148 | /* Forward unicat/Inter-BSS packets to kernel. */ | |
149 | return mwifiex_process_rx_packet(adapter, skb); | |
150 | } | |
151 | ||
152 | /* | |
153 | * This function processes the packet received on AP interface. | |
154 | * | |
155 | * The function looks into the RxPD and performs sanity tests on the | |
156 | * received buffer to ensure its a valid packet before processing it | |
157 | * further. If the packet is determined to be aggregated, it is | |
158 | * de-aggregated accordingly. Then skb is passed to AP packet forwarding logic. | |
159 | * | |
160 | * The completion callback is called after processing is complete. | |
161 | */ | |
162 | int mwifiex_process_uap_rx_packet(struct mwifiex_adapter *adapter, | |
163 | struct sk_buff *skb) | |
164 | { | |
165 | int ret; | |
166 | struct uap_rxpd *uap_rx_pd; | |
167 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); | |
168 | struct rx_packet_hdr *rx_pkt_hdr; | |
169 | u16 rx_pkt_type; | |
d1cf3b95 AP |
170 | u8 ta[ETH_ALEN], pkt_type; |
171 | struct mwifiex_sta_node *node; | |
172 | ||
838e4f44 AP |
173 | struct mwifiex_private *priv = |
174 | mwifiex_get_priv_by_id(adapter, rx_info->bss_num, | |
175 | rx_info->bss_type); | |
176 | ||
177 | if (!priv) | |
178 | return -1; | |
179 | ||
180 | uap_rx_pd = (struct uap_rxpd *)(skb->data); | |
181 | rx_pkt_type = le16_to_cpu(uap_rx_pd->rx_pkt_type); | |
182 | rx_pkt_hdr = (void *)uap_rx_pd + le16_to_cpu(uap_rx_pd->rx_pkt_offset); | |
183 | ||
184 | if ((le16_to_cpu(uap_rx_pd->rx_pkt_offset) + | |
185 | le16_to_cpu(uap_rx_pd->rx_pkt_length)) > (u16) skb->len) { | |
186 | dev_err(adapter->dev, | |
187 | "wrong rx packet: len=%d, offset=%d, length=%d\n", | |
188 | skb->len, le16_to_cpu(uap_rx_pd->rx_pkt_offset), | |
189 | le16_to_cpu(uap_rx_pd->rx_pkt_length)); | |
190 | priv->stats.rx_dropped++; | |
191 | ||
192 | if (adapter->if_ops.data_complete) | |
193 | adapter->if_ops.data_complete(adapter, skb); | |
194 | else | |
195 | dev_kfree_skb_any(skb); | |
196 | ||
197 | return 0; | |
198 | } | |
838e4f44 | 199 | |
d1cf3b95 AP |
200 | if (le16_to_cpu(uap_rx_pd->rx_pkt_type) == PKT_TYPE_AMSDU) { |
201 | struct sk_buff_head list; | |
202 | struct sk_buff *rx_skb; | |
203 | ||
204 | __skb_queue_head_init(&list); | |
205 | skb_pull(skb, le16_to_cpu(uap_rx_pd->rx_pkt_offset)); | |
206 | skb_trim(skb, le16_to_cpu(uap_rx_pd->rx_pkt_length)); | |
207 | ||
208 | ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr, | |
209 | priv->wdev->iftype, 0, false); | |
210 | ||
211 | while (!skb_queue_empty(&list)) { | |
212 | rx_skb = __skb_dequeue(&list); | |
213 | ret = mwifiex_recv_packet(adapter, rx_skb); | |
214 | if (ret) | |
215 | dev_err(adapter->dev, | |
216 | "AP:Rx A-MSDU failed"); | |
217 | } | |
218 | ||
219 | return 0; | |
2dbaf751 SP |
220 | } else if (rx_pkt_type == PKT_TYPE_MGMT) { |
221 | ret = mwifiex_process_mgmt_packet(adapter, skb); | |
222 | if (ret) | |
223 | dev_err(adapter->dev, "Rx of mgmt packet failed"); | |
224 | dev_kfree_skb_any(skb); | |
225 | return ret; | |
d1cf3b95 AP |
226 | } |
227 | ||
228 | memcpy(ta, rx_pkt_hdr->eth803_hdr.h_source, ETH_ALEN); | |
229 | ||
230 | if (rx_pkt_type != PKT_TYPE_BAR && uap_rx_pd->priority < MAX_NUM_TID) { | |
231 | node = mwifiex_get_sta_entry(priv, ta); | |
232 | if (node) | |
233 | node->rx_seq[uap_rx_pd->priority] = | |
234 | le16_to_cpu(uap_rx_pd->seq_num); | |
235 | } | |
236 | ||
237 | if (!priv->ap_11n_enabled || | |
238 | (!mwifiex_11n_get_rx_reorder_tbl(priv, uap_rx_pd->priority, ta) && | |
239 | (le16_to_cpu(uap_rx_pd->rx_pkt_type) != PKT_TYPE_AMSDU))) { | |
240 | ret = mwifiex_handle_uap_rx_forward(priv, skb); | |
241 | return ret; | |
242 | } | |
243 | ||
244 | /* Reorder and send to kernel */ | |
245 | pkt_type = (u8)le16_to_cpu(uap_rx_pd->rx_pkt_type); | |
246 | ret = mwifiex_11n_rx_reorder_pkt(priv, le16_to_cpu(uap_rx_pd->seq_num), | |
247 | uap_rx_pd->priority, ta, pkt_type, | |
248 | skb); | |
249 | ||
250 | if (ret || (rx_pkt_type == PKT_TYPE_BAR)) { | |
838e4f44 AP |
251 | if (adapter->if_ops.data_complete) |
252 | adapter->if_ops.data_complete(adapter, skb); | |
253 | else | |
254 | dev_kfree_skb_any(skb); | |
255 | } | |
256 | ||
d1cf3b95 AP |
257 | if (ret) |
258 | priv->stats.rx_dropped++; | |
259 | ||
838e4f44 AP |
260 | return ret; |
261 | } | |
4ac8764a AP |
262 | |
263 | /* | |
264 | * This function fills the TxPD for AP tx packets. | |
265 | * | |
266 | * The Tx buffer received by this function should already have the | |
267 | * header space allocated for TxPD. | |
268 | * | |
269 | * This function inserts the TxPD in between interface header and actual | |
270 | * data and adjusts the buffer pointers accordingly. | |
271 | * | |
272 | * The following TxPD fields are set by this function, as required - | |
273 | * - BSS number | |
274 | * - Tx packet length and offset | |
275 | * - Priority | |
276 | * - Packet delay | |
277 | * - Priority specific Tx control | |
278 | * - Flags | |
279 | */ | |
280 | void *mwifiex_process_uap_txpd(struct mwifiex_private *priv, | |
281 | struct sk_buff *skb) | |
282 | { | |
283 | struct mwifiex_adapter *adapter = priv->adapter; | |
284 | struct uap_txpd *txpd; | |
285 | struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb); | |
286 | int pad, len; | |
3215215a | 287 | u16 pkt_type; |
4ac8764a AP |
288 | |
289 | if (!skb->len) { | |
290 | dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len); | |
291 | tx_info->status_code = -1; | |
292 | return skb->data; | |
293 | } | |
294 | ||
3215215a SP |
295 | pkt_type = mwifiex_is_skb_mgmt_frame(skb) ? PKT_TYPE_MGMT : 0; |
296 | ||
4ac8764a AP |
297 | /* If skb->data is not aligned, add padding */ |
298 | pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4; | |
299 | ||
300 | len = sizeof(*txpd) + pad; | |
301 | ||
302 | BUG_ON(skb_headroom(skb) < len + INTF_HEADER_LEN); | |
303 | ||
304 | skb_push(skb, len); | |
305 | ||
306 | txpd = (struct uap_txpd *)skb->data; | |
307 | memset(txpd, 0, sizeof(*txpd)); | |
308 | txpd->bss_num = priv->bss_num; | |
309 | txpd->bss_type = priv->bss_type; | |
310 | txpd->tx_pkt_length = cpu_to_le16((u16)(skb->len - len)); | |
311 | ||
312 | txpd->priority = (u8)skb->priority; | |
313 | txpd->pkt_delay_2ms = mwifiex_wmm_compute_drv_pkt_delay(priv, skb); | |
314 | ||
315 | if (txpd->priority < ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl)) | |
316 | /* | |
317 | * Set the priority specific tx_control field, setting of 0 will | |
318 | * cause the default value to be used later in this function. | |
319 | */ | |
320 | txpd->tx_control = | |
321 | cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[txpd->priority]); | |
322 | ||
323 | /* Offset of actual data */ | |
3215215a SP |
324 | if (pkt_type == PKT_TYPE_MGMT) { |
325 | /* Set the packet type and add header for management frame */ | |
326 | txpd->tx_pkt_type = cpu_to_le16(pkt_type); | |
327 | len += MWIFIEX_MGMT_FRAME_HEADER_SIZE; | |
328 | } | |
329 | ||
4ac8764a AP |
330 | txpd->tx_pkt_offset = cpu_to_le16(len); |
331 | ||
332 | /* make space for INTF_HEADER_LEN */ | |
333 | skb_push(skb, INTF_HEADER_LEN); | |
334 | ||
335 | if (!txpd->tx_control) | |
336 | /* TxCtrl set by user or default */ | |
337 | txpd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
338 | ||
339 | return skb->data; | |
340 | } |