tx.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. wlan_adapter *adapter = priv->adapter;
  59. int ret = 0;
  60. struct txpd localtxpd;
  61. struct txpd *plocaltxpd = &localtxpd;
  62. u8 *p802x_hdr;
  63. struct tx_radiotap_hdr *pradiotap_hdr;
  64. u32 new_rate;
  65. u8 *ptr = priv->adapter->tmptxbuf;
  66. lbs_deb_enter(LBS_DEB_TX);
  67. if (priv->adapter->surpriseremoved)
  68. return -1;
  69. if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
  70. lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
  71. skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
  72. ret = -1;
  73. goto done;
  74. }
  75. memset(plocaltxpd, 0, sizeof(struct txpd));
  76. plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
  77. /* offset of actual data */
  78. plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
  79. /* TxCtrl set by user or default */
  80. plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
  81. p802x_hdr = skb->data;
  82. if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
  83. /* locate radiotap header */
  84. pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
  85. /* set txpd fields from the radiotap header */
  86. new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
  87. if (new_rate != 0) {
  88. /* use new tx_control[4:0] */
  89. new_rate |= (adapter->pkttxctrl & ~0x1f);
  90. plocaltxpd->tx_control = cpu_to_le32(new_rate);
  91. }
  92. /* skip the radiotap header */
  93. p802x_hdr += sizeof(struct tx_radiotap_hdr);
  94. plocaltxpd->tx_packet_length =
  95. cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
  96. - sizeof(struct tx_radiotap_hdr));
  97. }
  98. /* copy destination address from 802.3 or 802.11 header */
  99. if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
  100. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
  101. else
  102. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
  103. lbs_dbg_hex("txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
  104. if (IS_MESH_FRAME(skb)) {
  105. plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
  106. }
  107. memcpy(ptr, plocaltxpd, sizeof(struct txpd));
  108. ptr += sizeof(struct txpd);
  109. lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  110. memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  111. ret = priv->hw_host_to_card(priv, MVMS_DAT,
  112. priv->adapter->tmptxbuf,
  113. le16_to_cpu(plocaltxpd->tx_packet_length) +
  114. sizeof(struct txpd));
  115. if (ret) {
  116. lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
  117. goto done;
  118. }
  119. lbs_deb_tx("SendSinglePacket succeeds\n");
  120. done:
  121. if (!ret) {
  122. priv->stats.tx_packets++;
  123. priv->stats.tx_bytes += skb->len;
  124. } else {
  125. priv->stats.tx_dropped++;
  126. priv->stats.tx_errors++;
  127. }
  128. if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
  129. /* Keep the skb to echo it back once Tx feedback is
  130. received from FW */
  131. skb_orphan(skb);
  132. /* stop processing outgoing pkts */
  133. netif_stop_queue(priv->dev);
  134. if (priv->mesh_dev)
  135. netif_stop_queue(priv->mesh_dev);
  136. /* freeze any packets already in our queues */
  137. priv->adapter->TxLockFlag = 1;
  138. } else {
  139. dev_kfree_skb_any(skb);
  140. priv->adapter->currenttxskb = NULL;
  141. }
  142. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  143. return ret;
  144. }
  145. void libertas_tx_runqueue(wlan_private *priv)
  146. {
  147. wlan_adapter *adapter = priv->adapter;
  148. int i;
  149. spin_lock(&adapter->txqueue_lock);
  150. for (i = 0; i < adapter->tx_queue_idx; i++) {
  151. struct sk_buff *skb = adapter->tx_queue_ps[i];
  152. spin_unlock(&adapter->txqueue_lock);
  153. SendSinglePacket(priv, skb);
  154. spin_lock(&adapter->txqueue_lock);
  155. }
  156. adapter->tx_queue_idx = 0;
  157. spin_unlock(&adapter->txqueue_lock);
  158. }
  159. static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
  160. {
  161. wlan_adapter *adapter = priv->adapter;
  162. spin_lock(&adapter->txqueue_lock);
  163. WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
  164. adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
  165. if (adapter->tx_queue_idx == NR_TX_QUEUE) {
  166. netif_stop_queue(priv->dev);
  167. if (priv->mesh_dev)
  168. netif_stop_queue(priv->mesh_dev);
  169. } else {
  170. netif_start_queue(priv->dev);
  171. if (priv->mesh_dev)
  172. netif_start_queue(priv->mesh_dev);
  173. }
  174. spin_unlock(&adapter->txqueue_lock);
  175. }
  176. /**
  177. * @brief This function checks the conditions and sends packet to IF
  178. * layer if everything is ok.
  179. *
  180. * @param priv A pointer to wlan_private structure
  181. * @return n/a
  182. */
  183. int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
  184. {
  185. int ret = -1;
  186. lbs_deb_enter(LBS_DEB_TX);
  187. lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  188. if (priv->dnld_sent) {
  189. lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
  190. priv->dnld_sent);
  191. goto done;
  192. }
  193. if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
  194. (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
  195. wlan_tx_queue(priv, skb);
  196. return ret;
  197. }
  198. priv->adapter->currenttxskb = skb;
  199. ret = SendSinglePacket(priv, skb);
  200. done:
  201. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  202. return ret;
  203. }
  204. /**
  205. * @brief This function sends to the host the last transmitted packet,
  206. * filling the radiotap headers with transmission information.
  207. *
  208. * @param priv A pointer to wlan_private structure
  209. * @param status A 32 bit value containing transmission status.
  210. *
  211. * @returns void
  212. */
  213. void libertas_send_tx_feedback(wlan_private * priv)
  214. {
  215. wlan_adapter *adapter = priv->adapter;
  216. struct tx_radiotap_hdr *radiotap_hdr;
  217. u32 status = adapter->eventcause;
  218. int txfail;
  219. int try_count;
  220. if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP ||
  221. adapter->currenttxskb == NULL)
  222. return;
  223. radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
  224. txfail = (status >> 24);
  225. #if 0
  226. /* The version of roofnet that we've tested does not use this yet
  227. * But it may be used in the future.
  228. */
  229. if (txfail)
  230. radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
  231. #endif
  232. try_count = (status >> 16) & 0xff;
  233. radiotap_hdr->data_retries = (try_count) ?
  234. (1 + adapter->txretrycount - try_count) : 0;
  235. libertas_upload_rx_packet(priv, adapter->currenttxskb);
  236. adapter->currenttxskb = NULL;
  237. priv->adapter->TxLockFlag = 0;
  238. if (priv->adapter->connect_status == LIBERTAS_CONNECTED) {
  239. netif_wake_queue(priv->dev);
  240. if (priv->mesh_dev)
  241. netif_wake_queue(priv->mesh_dev);
  242. }
  243. }
  244. EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);