tx.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. * This file contains the handling of TX in wlan driver.
  3. */
  4. #include <linux/netdevice.h>
  5. #include "hostcmd.h"
  6. #include "radiotap.h"
  7. #include "decl.h"
  8. #include "defs.h"
  9. #include "dev.h"
  10. #include "wext.h"
  11. /**
  12. * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
  13. * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
  14. *
  15. * @param rate Input rate
  16. * @return Output Rate (0 if invalid)
  17. */
  18. static u32 convert_radiotap_rate_to_mv(u8 rate)
  19. {
  20. switch (rate) {
  21. case 2: /* 1 Mbps */
  22. return 0 | (1 << 4);
  23. case 4: /* 2 Mbps */
  24. return 1 | (1 << 4);
  25. case 11: /* 5.5 Mbps */
  26. return 2 | (1 << 4);
  27. case 22: /* 11 Mbps */
  28. return 3 | (1 << 4);
  29. case 12: /* 6 Mbps */
  30. return 4 | (1 << 4);
  31. case 18: /* 9 Mbps */
  32. return 5 | (1 << 4);
  33. case 24: /* 12 Mbps */
  34. return 6 | (1 << 4);
  35. case 36: /* 18 Mbps */
  36. return 7 | (1 << 4);
  37. case 48: /* 24 Mbps */
  38. return 8 | (1 << 4);
  39. case 72: /* 36 Mbps */
  40. return 9 | (1 << 4);
  41. case 96: /* 48 Mbps */
  42. return 10 | (1 << 4);
  43. case 108: /* 54 Mbps */
  44. return 11 | (1 << 4);
  45. }
  46. return 0;
  47. }
  48. /**
  49. * @brief This function processes a single packet and sends
  50. * to IF layer
  51. *
  52. * @param priv A pointer to wlan_private structure
  53. * @param skb A pointer to skb which includes TX packet
  54. * @return 0 or -1
  55. */
  56. static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb)
  57. {
  58. int ret = 0;
  59. struct txpd localtxpd;
  60. struct txpd *plocaltxpd = &localtxpd;
  61. u8 *p802x_hdr;
  62. struct tx_radiotap_hdr *pradiotap_hdr;
  63. u32 new_rate;
  64. u8 *ptr = priv->adapter->tmptxbuf;
  65. lbs_deb_enter(LBS_DEB_TX);
  66. if (priv->adapter->surpriseremoved)
  67. return -1;
  68. if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
  69. lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
  70. skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
  71. ret = -1;
  72. goto done;
  73. }
  74. memset(plocaltxpd, 0, sizeof(struct txpd));
  75. plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
  76. /* offset of actual data */
  77. plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
  78. p802x_hdr = skb->data;
  79. if (priv->adapter->monitormode != WLAN_MONITOR_OFF) {
  80. /* locate radiotap header */
  81. pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
  82. /* set txpd fields from the radiotap header */
  83. new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
  84. if (new_rate != 0) {
  85. /* use new tx_control[4:0] */
  86. plocaltxpd->tx_control = cpu_to_le32(new_rate);
  87. }
  88. /* skip the radiotap header */
  89. p802x_hdr += sizeof(struct tx_radiotap_hdr);
  90. plocaltxpd->tx_packet_length =
  91. cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
  92. - sizeof(struct tx_radiotap_hdr));
  93. }
  94. /* copy destination address from 802.3 or 802.11 header */
  95. if (priv->adapter->monitormode != WLAN_MONITOR_OFF)
  96. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
  97. else
  98. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
  99. lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
  100. if (IS_MESH_FRAME(skb)) {
  101. plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
  102. }
  103. memcpy(ptr, plocaltxpd, sizeof(struct txpd));
  104. ptr += sizeof(struct txpd);
  105. lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  106. memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  107. ret = priv->hw_host_to_card(priv, MVMS_DAT,
  108. priv->adapter->tmptxbuf,
  109. le16_to_cpu(plocaltxpd->tx_packet_length) +
  110. sizeof(struct txpd));
  111. if (ret) {
  112. lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
  113. goto done;
  114. }
  115. lbs_deb_tx("SendSinglePacket succeeds\n");
  116. done:
  117. if (!ret) {
  118. priv->stats.tx_packets++;
  119. priv->stats.tx_bytes += skb->len;
  120. } else {
  121. priv->stats.tx_dropped++;
  122. priv->stats.tx_errors++;
  123. }
  124. if (!ret && priv->adapter->monitormode != WLAN_MONITOR_OFF) {
  125. /* Keep the skb to echo it back once Tx feedback is
  126. received from FW */
  127. skb_orphan(skb);
  128. /* stop processing outgoing pkts */
  129. netif_stop_queue(priv->dev);
  130. if (priv->mesh_dev)
  131. netif_stop_queue(priv->mesh_dev);
  132. /* freeze any packets already in our queues */
  133. priv->adapter->TxLockFlag = 1;
  134. } else {
  135. dev_kfree_skb_any(skb);
  136. priv->adapter->currenttxskb = NULL;
  137. }
  138. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  139. return ret;
  140. }
  141. void libertas_tx_runqueue(wlan_private *priv)
  142. {
  143. wlan_adapter *adapter = priv->adapter;
  144. int i;
  145. spin_lock(&adapter->txqueue_lock);
  146. for (i = 0; i < adapter->tx_queue_idx; i++) {
  147. struct sk_buff *skb = adapter->tx_queue_ps[i];
  148. spin_unlock(&adapter->txqueue_lock);
  149. SendSinglePacket(priv, skb);
  150. spin_lock(&adapter->txqueue_lock);
  151. }
  152. adapter->tx_queue_idx = 0;
  153. spin_unlock(&adapter->txqueue_lock);
  154. }
  155. static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
  156. {
  157. wlan_adapter *adapter = priv->adapter;
  158. spin_lock(&adapter->txqueue_lock);
  159. WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
  160. adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
  161. if (adapter->tx_queue_idx == NR_TX_QUEUE) {
  162. netif_stop_queue(priv->dev);
  163. if (priv->mesh_dev)
  164. netif_stop_queue(priv->mesh_dev);
  165. } else {
  166. netif_start_queue(priv->dev);
  167. if (priv->mesh_dev)
  168. netif_start_queue(priv->mesh_dev);
  169. }
  170. spin_unlock(&adapter->txqueue_lock);
  171. }
  172. /**
  173. * @brief This function checks the conditions and sends packet to IF
  174. * layer if everything is ok.
  175. *
  176. * @param priv A pointer to wlan_private structure
  177. * @return n/a
  178. */
  179. int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
  180. {
  181. int ret = -1;
  182. lbs_deb_enter(LBS_DEB_TX);
  183. lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  184. if (priv->dnld_sent) {
  185. lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
  186. priv->dnld_sent);
  187. goto done;
  188. }
  189. if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
  190. (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
  191. wlan_tx_queue(priv, skb);
  192. return ret;
  193. }
  194. priv->adapter->currenttxskb = skb;
  195. ret = SendSinglePacket(priv, skb);
  196. done:
  197. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  198. return ret;
  199. }
  200. /**
  201. * @brief This function sends to the host the last transmitted packet,
  202. * filling the radiotap headers with transmission information.
  203. *
  204. * @param priv A pointer to wlan_private structure
  205. * @param status A 32 bit value containing transmission status.
  206. *
  207. * @returns void
  208. */
  209. void libertas_send_tx_feedback(wlan_private * priv)
  210. {
  211. wlan_adapter *adapter = priv->adapter;
  212. struct tx_radiotap_hdr *radiotap_hdr;
  213. u32 status = adapter->eventcause;
  214. int txfail;
  215. int try_count;
  216. if (adapter->monitormode == WLAN_MONITOR_OFF ||
  217. adapter->currenttxskb == NULL)
  218. return;
  219. radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
  220. txfail = (status >> 24);
  221. #if 0
  222. /* The version of roofnet that we've tested does not use this yet
  223. * But it may be used in the future.
  224. */
  225. if (txfail)
  226. radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
  227. #endif
  228. try_count = (status >> 16) & 0xff;
  229. radiotap_hdr->data_retries = (try_count) ?
  230. (1 + adapter->txretrycount - try_count) : 0;
  231. libertas_upload_rx_packet(priv, adapter->currenttxskb);
  232. adapter->currenttxskb = NULL;
  233. priv->adapter->TxLockFlag = 0;
  234. if (priv->adapter->connect_status == LIBERTAS_CONNECTED) {
  235. netif_wake_queue(priv->dev);
  236. if (priv->mesh_dev)
  237. netif_wake_queue(priv->mesh_dev);
  238. }
  239. }
  240. EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);