Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: generic TX/RX data handling | |
3 | * | |
65da33f5 | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
5e6e3a92 BZ |
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 "util.h" | |
23 | #include "fw.h" | |
24 | #include "main.h" | |
25 | #include "wmm.h" | |
26 | ||
27 | /* | |
28 | * This function processes the received buffer. | |
29 | * | |
30 | * Main responsibility of this function is to parse the RxPD to | |
31 | * identify the correct interface this packet is headed for and | |
32 | * forwarding it to the associated handling function, where the | |
33 | * packet will be further processed and sent to kernel/upper layer | |
34 | * if required. | |
35 | */ | |
36 | int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter, | |
37 | struct sk_buff *skb) | |
38 | { | |
5e6e3a92 BZ |
39 | struct mwifiex_private *priv = |
40 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
41 | struct rxpd *local_rx_pd; | |
42 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); | |
ca8d6dfc | 43 | int ret; |
5e6e3a92 BZ |
44 | |
45 | local_rx_pd = (struct rxpd *) (skb->data); | |
46 | /* Get the BSS number from rxpd, get corresponding priv */ | |
47 | priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num & | |
48 | BSS_NUM_MASK, local_rx_pd->bss_type); | |
49 | if (!priv) | |
50 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); | |
51 | ||
f3b369e4 AP |
52 | if (!priv) { |
53 | dev_err(adapter->dev, "data: priv not found. Drop RX packet\n"); | |
54 | dev_kfree_skb_any(skb); | |
55 | return -1; | |
56 | } | |
57 | ||
701a9e61 | 58 | memset(rx_info, 0, sizeof(*rx_info)); |
9da9a3b2 YAP |
59 | rx_info->bss_num = priv->bss_num; |
60 | rx_info->bss_type = priv->bss_type; | |
5e6e3a92 | 61 | |
838e4f44 | 62 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
ca8d6dfc UR |
63 | ret = mwifiex_process_uap_rx_packet(priv, skb); |
64 | else | |
65 | ret = mwifiex_process_sta_rx_packet(priv, skb); | |
838e4f44 | 66 | |
ca8d6dfc | 67 | return ret; |
5e6e3a92 BZ |
68 | } |
69 | EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet); | |
70 | ||
71 | /* | |
72 | * This function sends a packet to device. | |
73 | * | |
74 | * It processes the packet to add the TxPD, checks condition and | |
75 | * sends the processed packet to firmware for transmission. | |
76 | * | |
77 | * On successful completion, the function calls the completion callback | |
78 | * and logs the time. | |
79 | */ | |
80 | int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb, | |
81 | struct mwifiex_tx_param *tx_param) | |
82 | { | |
83 | int ret = -1; | |
84 | struct mwifiex_adapter *adapter = priv->adapter; | |
270e58e8 | 85 | u8 *head_ptr; |
5e6e3a92 BZ |
86 | struct txpd *local_tx_pd = NULL; |
87 | ||
4ac8764a AP |
88 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
89 | head_ptr = mwifiex_process_uap_txpd(priv, skb); | |
90 | else | |
91 | head_ptr = mwifiex_process_sta_txpd(priv, skb); | |
92 | ||
5e6e3a92 BZ |
93 | if (head_ptr) { |
94 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) | |
95 | local_tx_pd = | |
96 | (struct txpd *) (head_ptr + INTF_HEADER_LEN); | |
4daffe35 AK |
97 | if (adapter->iface_type == MWIFIEX_USB) { |
98 | adapter->data_sent = true; | |
99 | skb_pull(skb, INTF_HEADER_LEN); | |
100 | ret = adapter->if_ops.host_to_card(adapter, | |
101 | MWIFIEX_USB_EP_DATA, | |
102 | skb, NULL); | |
103 | } else { | |
104 | ret = adapter->if_ops.host_to_card(adapter, | |
105 | MWIFIEX_TYPE_DATA, | |
106 | skb, tx_param); | |
107 | } | |
5e6e3a92 BZ |
108 | } |
109 | ||
110 | switch (ret) { | |
4daffe35 | 111 | case -ENOSR: |
bd2a864a | 112 | dev_dbg(adapter->dev, "data: -ENOSR is returned\n"); |
4daffe35 | 113 | break; |
5e6e3a92 BZ |
114 | case -EBUSY: |
115 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && | |
c65a30f3 | 116 | (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) { |
5e6e3a92 | 117 | priv->adapter->tx_lock_flag = false; |
3d82de0f YAP |
118 | if (local_tx_pd) |
119 | local_tx_pd->flags = 0; | |
5e6e3a92 BZ |
120 | } |
121 | dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); | |
122 | break; | |
123 | case -1: | |
e7f767a7 AP |
124 | if (adapter->iface_type != MWIFIEX_PCIE) |
125 | adapter->data_sent = false; | |
5e6e3a92 | 126 | dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n", |
c65a30f3 | 127 | ret); |
5e6e3a92 | 128 | adapter->dbg.num_tx_host_to_card_failure++; |
47411a06 | 129 | mwifiex_write_data_complete(adapter, skb, 0, ret); |
5e6e3a92 BZ |
130 | break; |
131 | case -EINPROGRESS: | |
e7f767a7 AP |
132 | if (adapter->iface_type != MWIFIEX_PCIE) |
133 | adapter->data_sent = false; | |
5e6e3a92 BZ |
134 | break; |
135 | case 0: | |
47411a06 | 136 | mwifiex_write_data_complete(adapter, skb, 0, ret); |
5e6e3a92 BZ |
137 | break; |
138 | default: | |
139 | break; | |
140 | } | |
141 | ||
142 | return ret; | |
143 | } | |
144 | ||
145 | /* | |
146 | * Packet send completion callback handler. | |
147 | * | |
148 | * It either frees the buffer directly or forwards it to another | |
149 | * completion callback which checks conditions, updates statistics, | |
150 | * wakes up stalled traffic queue if required, and then frees the buffer. | |
151 | */ | |
152 | int mwifiex_write_data_complete(struct mwifiex_adapter *adapter, | |
47411a06 | 153 | struct sk_buff *skb, int aggr, int status) |
5e6e3a92 | 154 | { |
47411a06 | 155 | struct mwifiex_private *priv; |
270e58e8 | 156 | struct mwifiex_txinfo *tx_info; |
47411a06 AP |
157 | struct netdev_queue *txq; |
158 | int index; | |
5e6e3a92 BZ |
159 | |
160 | if (!skb) | |
161 | return 0; | |
162 | ||
163 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
9da9a3b2 | 164 | priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num, |
c65a30f3 | 165 | tx_info->bss_type); |
5e6e3a92 BZ |
166 | if (!priv) |
167 | goto done; | |
168 | ||
4daffe35 AK |
169 | if (adapter->iface_type == MWIFIEX_USB) |
170 | adapter->data_sent = false; | |
171 | ||
bbea3bc4 | 172 | mwifiex_set_trans_start(priv->netdev); |
5e6e3a92 BZ |
173 | if (!status) { |
174 | priv->stats.tx_packets++; | |
a1ed4849 | 175 | priv->stats.tx_bytes += tx_info->pkt_len; |
8908c7d5 AN |
176 | if (priv->tx_timeout_cnt) |
177 | priv->tx_timeout_cnt = 0; | |
5e6e3a92 BZ |
178 | } else { |
179 | priv->stats.tx_errors++; | |
180 | } | |
62a5b7dc | 181 | |
838e4f44 AP |
182 | if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT) |
183 | atomic_dec_return(&adapter->pending_bridged_pkts); | |
47411a06 AP |
184 | |
185 | if (aggr) | |
186 | /* For skb_aggr, do not wake up tx queue */ | |
62a5b7dc | 187 | goto done; |
5e6e3a92 | 188 | |
47411a06 | 189 | atomic_dec(&adapter->tx_pending); |
5e6e3a92 | 190 | |
47411a06 AP |
191 | index = mwifiex_1d_to_wmm_queue[skb->priority]; |
192 | if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) { | |
193 | txq = netdev_get_tx_queue(priv->netdev, index); | |
194 | if (netif_tx_queue_stopped(txq)) { | |
195 | netif_tx_wake_queue(txq); | |
196 | dev_dbg(adapter->dev, "wake queue: %d\n", index); | |
197 | } | |
5e6e3a92 BZ |
198 | } |
199 | done: | |
200 | dev_kfree_skb_any(skb); | |
201 | ||
202 | return 0; | |
203 | } | |
4daffe35 | 204 | EXPORT_SYMBOL_GPL(mwifiex_write_data_complete); |
5e6e3a92 | 205 | |
808bbebc AK |
206 | void mwifiex_parse_tx_status_event(struct mwifiex_private *priv, |
207 | void *event_body) | |
208 | { | |
209 | struct tx_status_event *tx_status = (void *)priv->adapter->event_body; | |
210 | struct sk_buff *ack_skb; | |
211 | unsigned long flags; | |
18ca4382 | 212 | struct mwifiex_txinfo *tx_info; |
808bbebc AK |
213 | |
214 | if (!tx_status->tx_token_id) | |
215 | return; | |
216 | ||
217 | spin_lock_irqsave(&priv->ack_status_lock, flags); | |
218 | ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id); | |
219 | if (ack_skb) | |
220 | idr_remove(&priv->ack_status_frames, tx_status->tx_token_id); | |
221 | spin_unlock_irqrestore(&priv->ack_status_lock, flags); | |
222 | ||
18ca4382 AK |
223 | if (ack_skb) { |
224 | tx_info = MWIFIEX_SKB_TXCB(ack_skb); | |
225 | ||
226 | if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) { | |
227 | /* consumes ack_skb */ | |
228 | skb_complete_wifi_ack(ack_skb, !tx_status->status); | |
229 | } else { | |
4facc34a | 230 | cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie, |
18ca4382 AK |
231 | ack_skb->data, ack_skb->len, |
232 | !tx_status->status, GFP_ATOMIC); | |
233 | dev_kfree_skb_any(ack_skb); | |
234 | } | |
235 | } | |
808bbebc | 236 | } |