txrx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. ret = adapter->if_ops.host_to_card(adapter,
  105. priv->usb_port,
  106. skb, NULL);
  107. } else {
  108. ret = adapter->if_ops.host_to_card(adapter,
  109. MWIFIEX_TYPE_DATA,
  110. skb, tx_param);
  111. }
  112. }
  113. mwifiex_dbg_dump(adapter, DAT_D, "tx pkt:", skb->data,
  114. min_t(size_t, skb->len, DEBUG_DUMP_DATA_MAX_LEN));
  115. switch (ret) {
  116. case -ENOSR:
  117. mwifiex_dbg(adapter, DATA, "data: -ENOSR is returned\n");
  118. break;
  119. case -EBUSY:
  120. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  121. (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) {
  122. priv->adapter->tx_lock_flag = false;
  123. if (local_tx_pd)
  124. local_tx_pd->flags = 0;
  125. }
  126. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  127. break;
  128. case -1:
  129. mwifiex_dbg(adapter, ERROR,
  130. "mwifiex_write_data_async failed: 0x%X\n",
  131. ret);
  132. adapter->dbg.num_tx_host_to_card_failure++;
  133. mwifiex_write_data_complete(adapter, skb, 0, ret);
  134. break;
  135. case -EINPROGRESS:
  136. break;
  137. case 0:
  138. mwifiex_write_data_complete(adapter, skb, 0, ret);
  139. break;
  140. default:
  141. break;
  142. }
  143. return ret;
  144. }
  145. static int mwifiex_host_to_card(struct mwifiex_adapter *adapter,
  146. struct sk_buff *skb,
  147. struct mwifiex_tx_param *tx_param)
  148. {
  149. struct txpd *local_tx_pd = NULL;
  150. u8 *head_ptr = skb->data;
  151. int ret = 0;
  152. struct mwifiex_private *priv;
  153. struct mwifiex_txinfo *tx_info;
  154. tx_info = MWIFIEX_SKB_TXCB(skb);
  155. priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
  156. tx_info->bss_type);
  157. if (!priv) {
  158. mwifiex_dbg(adapter, ERROR,
  159. "data: priv not found. Drop TX packet\n");
  160. adapter->dbg.num_tx_host_to_card_failure++;
  161. mwifiex_write_data_complete(adapter, skb, 0, 0);
  162. return ret;
  163. }
  164. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) {
  165. if (adapter->iface_type == MWIFIEX_USB)
  166. local_tx_pd = (struct txpd *)head_ptr;
  167. else
  168. local_tx_pd = (struct txpd *) (head_ptr +
  169. INTF_HEADER_LEN);
  170. }
  171. if (adapter->iface_type == MWIFIEX_USB) {
  172. ret = adapter->if_ops.host_to_card(adapter,
  173. priv->usb_port,
  174. skb, NULL);
  175. } else {
  176. ret = adapter->if_ops.host_to_card(adapter,
  177. MWIFIEX_TYPE_DATA,
  178. skb, tx_param);
  179. }
  180. switch (ret) {
  181. case -ENOSR:
  182. mwifiex_dbg(adapter, ERROR, "data: -ENOSR is returned\n");
  183. break;
  184. case -EBUSY:
  185. if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) &&
  186. (adapter->pps_uapsd_mode) &&
  187. (adapter->tx_lock_flag)) {
  188. priv->adapter->tx_lock_flag = false;
  189. if (local_tx_pd)
  190. local_tx_pd->flags = 0;
  191. }
  192. skb_queue_head(&adapter->tx_data_q, skb);
  193. if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
  194. atomic_add(tx_info->aggr_num, &adapter->tx_queued);
  195. else
  196. atomic_inc(&adapter->tx_queued);
  197. mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
  198. break;
  199. case -1:
  200. mwifiex_dbg(adapter, ERROR,
  201. "mwifiex_write_data_async failed: 0x%X\n", ret);
  202. adapter->dbg.num_tx_host_to_card_failure++;
  203. mwifiex_write_data_complete(adapter, skb, 0, ret);
  204. break;
  205. case -EINPROGRESS:
  206. break;
  207. case 0:
  208. mwifiex_write_data_complete(adapter, skb, 0, ret);
  209. break;
  210. default:
  211. break;
  212. }
  213. return ret;
  214. }
  215. static int
  216. mwifiex_dequeue_tx_queue(struct mwifiex_adapter *adapter)
  217. {
  218. struct sk_buff *skb, *skb_next;
  219. struct mwifiex_txinfo *tx_info;
  220. struct mwifiex_tx_param tx_param;
  221. skb = skb_dequeue(&adapter->tx_data_q);
  222. if (!skb)
  223. return -1;
  224. tx_info = MWIFIEX_SKB_TXCB(skb);
  225. if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
  226. atomic_sub(tx_info->aggr_num, &adapter->tx_queued);
  227. else
  228. atomic_dec(&adapter->tx_queued);
  229. if (!skb_queue_empty(&adapter->tx_data_q))
  230. skb_next = skb_peek(&adapter->tx_data_q);
  231. else
  232. skb_next = NULL;
  233. tx_param.next_pkt_len = ((skb_next) ? skb_next->len : 0);
  234. if (!tx_param.next_pkt_len) {
  235. if (!mwifiex_wmm_lists_empty(adapter))
  236. tx_param.next_pkt_len = 1;
  237. }
  238. return mwifiex_host_to_card(adapter, skb, &tx_param);
  239. }
  240. void
  241. mwifiex_process_tx_queue(struct mwifiex_adapter *adapter)
  242. {
  243. do {
  244. if (adapter->data_sent || adapter->tx_lock_flag)
  245. break;
  246. if (mwifiex_dequeue_tx_queue(adapter))
  247. break;
  248. } while (!skb_queue_empty(&adapter->tx_data_q));
  249. }
  250. /*
  251. * Packet send completion callback handler.
  252. *
  253. * It either frees the buffer directly or forwards it to another
  254. * completion callback which checks conditions, updates statistics,
  255. * wakes up stalled traffic queue if required, and then frees the buffer.
  256. */
  257. int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
  258. struct sk_buff *skb, int aggr, int status)
  259. {
  260. struct mwifiex_private *priv;
  261. struct mwifiex_txinfo *tx_info;
  262. struct netdev_queue *txq;
  263. int index;
  264. if (!skb)
  265. return 0;
  266. tx_info = MWIFIEX_SKB_TXCB(skb);
  267. priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num,
  268. tx_info->bss_type);
  269. if (!priv)
  270. goto done;
  271. mwifiex_set_trans_start(priv->netdev);
  272. if (!status) {
  273. priv->stats.tx_packets++;
  274. priv->stats.tx_bytes += tx_info->pkt_len;
  275. if (priv->tx_timeout_cnt)
  276. priv->tx_timeout_cnt = 0;
  277. } else {
  278. priv->stats.tx_errors++;
  279. }
  280. if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT)
  281. atomic_dec_return(&adapter->pending_bridged_pkts);
  282. if (tx_info->flags & MWIFIEX_BUF_FLAG_AGGR_PKT)
  283. goto done;
  284. if (aggr)
  285. /* For skb_aggr, do not wake up tx queue */
  286. goto done;
  287. atomic_dec(&adapter->tx_pending);
  288. index = mwifiex_1d_to_wmm_queue[skb->priority];
  289. if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) {
  290. txq = netdev_get_tx_queue(priv->netdev, index);
  291. if (netif_tx_queue_stopped(txq)) {
  292. netif_tx_wake_queue(txq);
  293. mwifiex_dbg(adapter, DATA, "wake queue: %d\n", index);
  294. }
  295. }
  296. done:
  297. dev_kfree_skb_any(skb);
  298. return 0;
  299. }
  300. EXPORT_SYMBOL_GPL(mwifiex_write_data_complete);
  301. void mwifiex_parse_tx_status_event(struct mwifiex_private *priv,
  302. void *event_body)
  303. {
  304. struct tx_status_event *tx_status = (void *)priv->adapter->event_body;
  305. struct sk_buff *ack_skb;
  306. unsigned long flags;
  307. struct mwifiex_txinfo *tx_info;
  308. if (!tx_status->tx_token_id)
  309. return;
  310. spin_lock_irqsave(&priv->ack_status_lock, flags);
  311. ack_skb = idr_find(&priv->ack_status_frames, tx_status->tx_token_id);
  312. if (ack_skb)
  313. idr_remove(&priv->ack_status_frames, tx_status->tx_token_id);
  314. spin_unlock_irqrestore(&priv->ack_status_lock, flags);
  315. if (ack_skb) {
  316. tx_info = MWIFIEX_SKB_TXCB(ack_skb);
  317. if (tx_info->flags & MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS) {
  318. /* consumes ack_skb */
  319. skb_complete_wifi_ack(ack_skb, !tx_status->status);
  320. } else {
  321. /* Remove broadcast address which was added by driver */
  322. memmove(ack_skb->data +
  323. sizeof(struct ieee80211_hdr_3addr) +
  324. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16),
  325. ack_skb->data +
  326. sizeof(struct ieee80211_hdr_3addr) +
  327. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
  328. ETH_ALEN, ack_skb->len -
  329. (sizeof(struct ieee80211_hdr_3addr) +
  330. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(u16) +
  331. ETH_ALEN));
  332. ack_skb->len = ack_skb->len - ETH_ALEN;
  333. /* Remove driver's proprietary header including 2 bytes
  334. * of packet length and pass actual management frame buffer
  335. * to cfg80211.
  336. */
  337. cfg80211_mgmt_tx_status(&priv->wdev, tx_info->cookie,
  338. ack_skb->data +
  339. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  340. sizeof(u16), ack_skb->len -
  341. (MWIFIEX_MGMT_FRAME_HEADER_SIZE
  342. + sizeof(u16)),
  343. !tx_status->status, GFP_ATOMIC);
  344. dev_kfree_skb_any(ack_skb);
  345. }
  346. }
  347. }