tx.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
  70. lbs_dbg_hex("TX packet: ", skb->data,
  71. min_t(unsigned int, skb->len, 100));
  72. if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
  73. lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
  74. skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
  75. ret = -1;
  76. goto done;
  77. }
  78. memset(plocaltxpd, 0, sizeof(struct txpd));
  79. plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
  80. /* offset of actual data */
  81. plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
  82. /* TxCtrl set by user or default */
  83. plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
  84. p802x_hdr = skb->data;
  85. if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
  86. /* locate radiotap header */
  87. pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
  88. /* set txpd fields from the radiotap header */
  89. new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
  90. if (new_rate != 0) {
  91. /* use new tx_control[4:0] */
  92. new_rate |= (adapter->pkttxctrl & ~0x1f);
  93. plocaltxpd->tx_control = cpu_to_le32(new_rate);
  94. }
  95. /* skip the radiotap header */
  96. p802x_hdr += sizeof(struct tx_radiotap_hdr);
  97. plocaltxpd->tx_packet_length =
  98. cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
  99. - sizeof(struct tx_radiotap_hdr));
  100. }
  101. /* copy destination address from 802.3 or 802.11 header */
  102. if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
  103. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
  104. else
  105. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
  106. lbs_dbg_hex("txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
  107. if (IS_MESH_FRAME(skb)) {
  108. plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
  109. }
  110. memcpy(ptr, plocaltxpd, sizeof(struct txpd));
  111. ptr += sizeof(struct txpd);
  112. lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  113. memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  114. ret = priv->hw_host_to_card(priv, MVMS_DAT,
  115. priv->adapter->tmptxbuf,
  116. le16_to_cpu(plocaltxpd->tx_packet_length) +
  117. sizeof(struct txpd));
  118. if (ret) {
  119. lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
  120. goto done;
  121. }
  122. lbs_deb_tx("SendSinglePacket succeeds\n");
  123. done:
  124. if (!ret) {
  125. priv->stats.tx_packets++;
  126. priv->stats.tx_bytes += skb->len;
  127. } else {
  128. priv->stats.tx_dropped++;
  129. priv->stats.tx_errors++;
  130. }
  131. if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
  132. /* Keep the skb to echo it back once Tx feedback is
  133. received from FW */
  134. skb_orphan(skb);
  135. /* stop processing outgoing pkts */
  136. netif_stop_queue(priv->dev);
  137. netif_stop_queue(priv->mesh_dev);
  138. /* freeze any packets already in our queues */
  139. priv->adapter->TxLockFlag = 1;
  140. } else {
  141. dev_kfree_skb_any(skb);
  142. priv->adapter->currenttxskb = NULL;
  143. }
  144. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  145. return ret;
  146. }
  147. void libertas_tx_runqueue(wlan_private *priv)
  148. {
  149. wlan_adapter *adapter = priv->adapter;
  150. int i;
  151. spin_lock(&adapter->txqueue_lock);
  152. for (i = 0; i < adapter->tx_queue_idx; i++) {
  153. struct sk_buff *skb = adapter->tx_queue_ps[i];
  154. spin_unlock(&adapter->txqueue_lock);
  155. SendSinglePacket(priv, skb);
  156. spin_lock(&adapter->txqueue_lock);
  157. }
  158. adapter->tx_queue_idx = 0;
  159. spin_unlock(&adapter->txqueue_lock);
  160. }
  161. static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
  162. {
  163. wlan_adapter *adapter = priv->adapter;
  164. spin_lock(&adapter->txqueue_lock);
  165. WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
  166. adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
  167. if (adapter->tx_queue_idx == NR_TX_QUEUE) {
  168. netif_stop_queue(priv->dev);
  169. netif_stop_queue(priv->mesh_dev);
  170. } else {
  171. netif_start_queue(priv->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. if ((adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
  225. lbs_dbg_hex("TX feedback: ", (u8 *) radiotap_hdr,
  226. min_t(unsigned int, adapter->currenttxskb->len, 100));
  227. txfail = (status >> 24);
  228. #if 0
  229. /* The version of roofnet that we've tested does not use this yet
  230. * But it may be used in the future.
  231. */
  232. if (txfail)
  233. radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
  234. #endif
  235. try_count = (status >> 16) & 0xff;
  236. radiotap_hdr->data_retries = (try_count) ?
  237. (1 + adapter->txretrycount - try_count) : 0;
  238. libertas_upload_rx_packet(priv, adapter->currenttxskb);
  239. adapter->currenttxskb = NULL;
  240. priv->adapter->TxLockFlag = 0;
  241. if (priv->adapter->connect_status == libertas_connected) {
  242. netif_wake_queue(priv->dev);
  243. netif_wake_queue(priv->mesh_dev);
  244. }
  245. }
  246. EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);