txrx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * Marvell Wireless LAN device driver: generic TX/RX data handling
  3. *
  4. * Copyright (C) 2011-2014, 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. #include "decl.h"
  20. #include "ioctl.h"
  21. #include "util.h"
  22. #include "fw.h"
  23. #include "main.h"
  24. #include "wmm.h"
  25. /*
  26. * This function processes the received buffer.
  27. *
  28. * Main responsibility of this function is to parse the RxPD to
  29. * identify the correct interface this packet is headed for and
  30. * forwarding it to the associated handling function, where the
  31. * packet will be further processed and sent to kernel/upper layer
  32. * if required.
  33. */
  34. int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
  35. struct sk_buff *skb)
  36. {
  37. struct mwifiex_private *priv =
  38. mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  39. struct rxpd *local_rx_pd;
  40. struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb);
  41. int ret;
  42. local_rx_pd = (struct rxpd *) (skb->data);
  43. /* Get the BSS number from rxpd, get corresponding priv */
  44. priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num &
  45. BSS_NUM_MASK, local_rx_pd->bss_type);
  46. if (!priv)
  47. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  48. if (!priv) {
  49. mwifiex_dbg(adapter, ERROR,
  50. "data: priv not found. Drop RX packet\n");
  51. dev_kfree_skb_any(skb);
  52. return -1;
  53. }
  54. mwifiex_dbg_dump(adapter, DAT_D, "rx pkt:", skb->data,
  55. min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
  56. memset(rx_info, 0, sizeof(*rx_info));
  57. rx_info->bss_num = priv->bss_num;
  58. rx_info->bss_type = priv->bss_type;
  59. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP)
  60. ret = mwifiex_process_uap_rx_packet(priv, skb);
  61. else
  62. ret = mwifiex_process_sta_rx_packet(priv, skb);
  63. return ret;
  64. }
  65. EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet);
  66. /*
  67. * This function sends a packet to device.
  68. *
  69. * It processes the packet to add the TxPD, checks condition and
  70. * sends the processed packet to firmware for transmission.
  71. *
  72. * On successful completion, the function calls the completion callback
  73. * and logs the time.
  74. */
  75. int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
  76. struct mwifiex_tx_param *tx_param)
  77. {
  78. int hroom, ret = -1;
  79. struct mwifiex_adapter *adapter = priv->adapter;
  80. u8 *head_ptr;
  81. struct txpd *local_tx_pd = NULL;
  82. struct mwifiex_sta_node *dest_node;
  83. struct ethhdr *hdr = (void *)skb->data;
  84. hroom = (adapter->iface_type == MWIFIEX_USB) ? 0 : INTF_HEADER_LEN;
  85. if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) {
  86. dest_node = mwifiex_get_sta_entry(priv, hdr->h_dest);
  87. if (dest_node) {
  88. dest_node->stats.tx_bytes += skb->len;
  89. dest_node->stats.tx_packets++;
  90. }
  91. head_ptr = mwifiex_process_uap_txpd(priv, skb);
  92. } else {
  93. head_ptr = mwifiex_process_sta_txpd(priv, skb);
  94. }
  95. if ((adapter->data_sent || adapter->tx_lock_flag) && head_ptr) {
  96. skb_queue_tail(&adapter->tx_data_q, skb);
  97. atomic_inc(&adapter->tx_queued);
  98. return 0;
  99. }
  100. if (head_ptr) {
  101. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
  102. local_tx_pd = (struct txpd *)(head_ptr + hroom);
  103. if (adapter->iface_type == MWIFIEX_USB) {
  104. adapter->data_sent = true;
  105. ret = adapter->if_ops.host_to_card(adapter,
  106. MWIFIEX_USB_EP_DATA,
  107. skb, NULL);
  108. } else {
  109. ret = adapter->if_ops.host_to_card(adapter,
  110. MWIFIEX_TYPE_DATA,
  111. skb, tx_param);
  112. }
  113. }
  114. mwifiex_dbg_dump(adapter, DAT_D, "tx pkt:", skb->data,
  115. min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
  116. switch (ret) {
  117. case -ENOSR:
  118. mwifiex_dbg(adapter, ERROR, "data: -ENOSR is returned\n");
  119. break;
  120. case -EBUSY:
  121. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  122. (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
  123. priv->adapter->tx_lock_flag = false;
  124. if (local_tx_pd)
  125. local_tx_pd->flags = 0;
  126. }
  127. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  128. break;
  129. case -1:
  130. if (adapter->iface_type != MWIFIEX_PCIE)
  131. adapter->data_sent = false;
  132. mwifiex_dbg(adapter, ERROR,
  133. "mwifiex_write_data_async failed: 0x%X\n",
  134. ret);
  135. adapter->dbg.num_tx_host_to_card_failure++;
  136. mwifiex_write_data_complete(adapter, skb, 0, ret);
  137. break;
  138. case -EINPROGRESS:
  139. if (adapter->iface_type != MWIFIEX_PCIE)
  140. adapter->data_sent = false;
  141. break;
  142. case 0:
  143. mwifiex_write_data_complete(adapter, skb, 0, ret);
  144. break;
  145. default:
  146. break;
  147. }
  148. return ret;
  149. }
  150. static int mwifiex_host_to_card(struct mwifiex_adapter *adapter,
  151. struct sk_buff *skb,
  152. struct mwifiex_tx_param *tx_param)
  153. {
  154. struct txpd *local_tx_pd = NULL;
  155. u8 *head_ptr = skb->data;
  156. int ret = 0;
  157. struct mwifiex_private *priv;
  158. struct mwifiex_txinfo *tx_info;
  159. tx_info = MWIFIEX_SKB_TXCB(skb);
  160. priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
  161. tx_info->bss_type);
  162. if (!priv) {
  163. mwifiex_dbg(adapter, ERROR,
  164. "data: priv not found. Drop TX packet\n");
  165. adapter->dbg.num_tx_host_to_card_failure++;
  166. mwifiex_write_data_complete(adapter, skb, 0, 0);
  167. return ret;
  168. }
  169. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
  170. if (adapter->iface_type == MWIFIEX_USB)
  171. local_tx_pd = (struct txpd *)head_ptr;
  172. else
  173. local_tx_pd = (struct txpd *) (head_ptr +
  174. INTF_HEADER_LEN);
  175. }
  176. if (adapter->iface_type == MWIFIEX_USB) {
  177. adapter->data_sent = true;
  178. ret = adapter->if_ops.host_to_card(adapter,
  179. MWIFIEX_USB_EP_DATA,
  180. skb, NULL);
  181. } else {
  182. ret = adapter->if_ops.host_to_card(adapter,
  183. MWIFIEX_TYPE_DATA,
  184. skb, tx_param);
  185. }
  186. switch (ret) {
  187. case -ENOSR:
  188. mwifiex_dbg(adapter, ERROR, "data: -ENOSR is returned\n");
  189. break;
  190. case -EBUSY:
  191. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  192. (adapter->pps_uapsd_mode) &&
  193. (adapter->tx_lock_flag)) {
  194. priv->adapter->tx_lock_flag = false;
  195. if (local_tx_pd)
  196. local_tx_pd->flags = 0;
  197. }
  198. skb_queue_head(&adapter->tx_data_q, skb);
  199. if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
  200. atomic_add(tx_info->aggr_num, &adapter->tx_queued);
  201. else
  202. atomic_inc(&adapter->tx_queued);
  203. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  204. break;
  205. case -1:
  206. if (adapter->iface_type != MWIFIEX_PCIE)
  207. adapter->data_sent = false;
  208. mwifiex_dbg(adapter, ERROR,
  209. "mwifiex_write_data_async failed: 0x%X\n", ret);
  210. adapter->dbg.num_tx_host_to_card_failure++;
  211. mwifiex_write_data_complete(adapter, skb, 0, ret);
  212. break;
  213. case -EINPROGRESS:
  214. if (adapter->iface_type != MWIFIEX_PCIE)
  215. adapter->data_sent = false;
  216. break;
  217. case 0:
  218. mwifiex_write_data_complete(adapter, skb, 0, ret);
  219. break;
  220. default:
  221. break;
  222. }
  223. return ret;
  224. }
  225. static int
  226. mwifiex_dequeue_tx_queue(struct mwifiex_adapter *adapter)
  227. {
  228. struct sk_buff *skb, *skb_next;
  229. struct mwifiex_txinfo *tx_info;
  230. struct mwifiex_tx_param tx_param;
  231. skb = skb_dequeue(&adapter->tx_data_q);
  232. if (!skb)
  233. return -1;
  234. tx_info = MWIFIEX_SKB_TXCB(skb);
  235. if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
  236. atomic_sub(tx_info->aggr_num, &adapter->tx_queued);
  237. else
  238. atomic_dec(&adapter->tx_queued);
  239. if (!skb_queue_empty(&adapter->tx_data_q))
  240. skb_next = skb_peek(&adapter->tx_data_q);
  241. else
  242. skb_next = NULL;
  243. tx_param.next_pkt_len = ((skb_next) ? skb_next->len : 0);
  244. if (!tx_param.next_pkt_len) {
  245. if (!mwifiex_wmm_lists_empty(adapter))
  246. tx_param.next_pkt_len = 1;
  247. }
  248. return mwifiex_host_to_card(adapter, skb, &tx_param);
  249. }
  250. void
  251. mwifiex_process_tx_queue(struct mwifiex_adapter *adapter)
  252. {
  253. do {
  254. if (adapter->data_sent || adapter->tx_lock_flag)
  255. break;
  256. if (mwifiex_dequeue_tx_queue(adapter))
  257. break;
  258. } while (!skb_queue_empty(&adapter->tx_data_q));
  259. }
  260. /*
  261. * Packet send completion callback handler.
  262. *
  263. * It either frees the buffer directly or forwards it to another
  264. * completion callback which checks conditions, updates statistics,
  265. * wakes up stalled traffic queue if required, and then frees the buffer.
  266. */
  267. int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
  268. struct sk_buff *skb, int aggr, int status)
  269. {
  270. struct mwifiex_private *priv;
  271. struct mwifiex_txinfo *tx_info;
  272. struct netdev_queue *txq;
  273. int index;
  274. if (!skb)
  275. return 0;
  276. tx_info = MWIFIEX_SKB_TXCB(skb);
  277. priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
  278. tx_info->bss_type);
  279. if (!priv)
  280. goto done;
  281. if (adapter->iface_type == MWIFIEX_USB)
  282. adapter->data_sent = false;
  283. mwifiex_set_trans_start(priv->netdev);
  284. if (!status) {
  285. priv->stats.tx_packets++;
  286. priv->stats.tx_bytes += tx_info->pkt_len;
  287. if (priv->tx_timeout_cnt)
  288. priv->tx_timeout_cnt = 0;
  289. } else {
  290. priv->stats.tx_errors++;
  291. }
  292. if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
  293. atomic_dec_return(&adapter->pending_bridged_pkts);
  294. if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
  295. goto done;
  296. if (aggr)
  297. /* For skb_aggr, do not wake up tx queue */
  298. goto done;
  299. atomic_dec(&adapter->tx_pending);
  300. index = mwifiex_1d_to_wmm_queue[skb->priority];
  301. if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
  302. txq = netdev_get_tx_queue(priv->netdev, index);
  303. if (netif_tx_queue_stopped(txq)) {
  304. netif_tx_wake_queue(txq);
  305. mwifiex_dbg(adapter, DATA, "wake queue: %d\n", index);
  306. }
  307. }
  308. done:
  309. dev_kfree_skb_any(skb);
  310. return 0;
  311. }
  312. EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
  313. void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
  314. void *event_body)
  315. {
  316. struct tx_status_event *tx_status = (void *)priv->adapter->event_body;
  317. struct sk_buff *ack_skb;
  318. unsigned long flags;
  319. struct mwifiex_txinfo *tx_info;
  320. if (!tx_status->tx_token_id)
  321. return;
  322. spin_lock_irqsave(&priv->ack_status_lock, flags);
  323. ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id);
  324. if (ack_skb)
  325. idr_remove(&priv->ack_status_frames, tx_status->tx_token_id);
  326. spin_unlock_irqrestore(&priv->ack_status_lock, flags);
  327. if (ack_skb) {
  328. tx_info = MWIFIEX_SKB_TXCB(ack_skb);
  329. if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
  330. /* consumes ack_skb */
  331. skb_complete_wifi_ack(ack_skb, !tx_status->status);
  332. } else {
  333. cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie,
  334. ack_skb->data, ack_skb->len,
  335. !tx_status->status, GFP_ATOMIC);
  336. dev_kfree_skb_any(ack_skb);
  337. }
  338. }
  339. }