tx.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 "sbi.h"
  8. #include "decl.h"
  9. #include "defs.h"
  10. #include "dev.h"
  11. #include "wext.h"
  12. /**
  13. * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
  14. * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
  15. *
  16. * @param rate Input rate
  17. * @return Output Rate (0 if invalid)
  18. */
  19. static u32 convert_radiotap_rate_to_mv(u8 rate)
  20. {
  21. switch (rate) {
  22. case 2: /* 1 Mbps */
  23. return 0 | (1 << 4);
  24. case 4: /* 2 Mbps */
  25. return 1 | (1 << 4);
  26. case 11: /* 5.5 Mbps */
  27. return 2 | (1 << 4);
  28. case 22: /* 11 Mbps */
  29. return 3 | (1 << 4);
  30. case 12: /* 6 Mbps */
  31. return 4 | (1 << 4);
  32. case 18: /* 9 Mbps */
  33. return 5 | (1 << 4);
  34. case 24: /* 12 Mbps */
  35. return 6 | (1 << 4);
  36. case 36: /* 18 Mbps */
  37. return 7 | (1 << 4);
  38. case 48: /* 24 Mbps */
  39. return 8 | (1 << 4);
  40. case 72: /* 36 Mbps */
  41. return 9 | (1 << 4);
  42. case 96: /* 48 Mbps */
  43. return 10 | (1 << 4);
  44. case 108: /* 54 Mbps */
  45. return 11 | (1 << 4);
  46. }
  47. return 0;
  48. }
  49. /**
  50. * @brief This function processes a single packet and sends
  51. * to IF layer
  52. *
  53. * @param priv A pointer to wlan_private structure
  54. * @param skb A pointer to skb which includes TX packet
  55. * @return 0 or -1
  56. */
  57. static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb)
  58. {
  59. wlan_adapter *adapter = priv->adapter;
  60. int ret = 0;
  61. struct txpd localtxpd;
  62. struct txpd *plocaltxpd = &localtxpd;
  63. u8 *p802x_hdr;
  64. struct tx_radiotap_hdr *pradiotap_hdr;
  65. u32 new_rate;
  66. u8 *ptr = priv->adapter->tmptxbuf;
  67. ENTER();
  68. if (priv->adapter->surpriseremoved)
  69. return -1;
  70. if ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
  71. lbs_dbg_hex("TX packet: ", skb->data,
  72. min_t(unsigned int, skb->len, 100));
  73. if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
  74. lbs_pr_debug(1, "Tx error: Bad skb length %d : %zd\n",
  75. skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
  76. ret = -1;
  77. goto done;
  78. }
  79. memset(plocaltxpd, 0, sizeof(struct txpd));
  80. plocaltxpd->tx_packet_length = skb->len;
  81. /* offset of actual data */
  82. plocaltxpd->tx_packet_location = sizeof(struct txpd);
  83. /* TxCtrl set by user or default */
  84. plocaltxpd->tx_control = adapter->pkttxctrl;
  85. p802x_hdr = skb->data;
  86. if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
  87. /* locate radiotap header */
  88. pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
  89. /* set txpd fields from the radiotap header */
  90. new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
  91. if (new_rate != 0) {
  92. /* erase tx_control[4:0] */
  93. plocaltxpd->tx_control &= ~0x1f;
  94. /* write new tx_control[4:0] */
  95. plocaltxpd->tx_control |= new_rate;
  96. }
  97. /* skip the radiotap header */
  98. p802x_hdr += sizeof(struct tx_radiotap_hdr);
  99. plocaltxpd->tx_packet_length -= 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 |= 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, plocaltxpd->tx_packet_length);
  113. memcpy(ptr, p802x_hdr, plocaltxpd->tx_packet_length);
  114. ret = libertas_sbi_host_to_card(priv, MVMS_DAT,
  115. priv->adapter->tmptxbuf,
  116. plocaltxpd->tx_packet_length +
  117. sizeof(struct txpd));
  118. if (ret) {
  119. lbs_pr_debug(1, "Tx error: libertas_sbi_host_to_card failed: 0x%X\n", ret);
  120. goto done;
  121. }
  122. lbs_pr_debug(1, "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->wlan_dev.netdev);
  137. /* freeze any packets already in our queues */
  138. priv->adapter->TxLockFlag = 1;
  139. } else {
  140. dev_kfree_skb_any(skb);
  141. priv->adapter->currenttxskb = NULL;
  142. }
  143. LEAVE();
  144. return ret;
  145. }
  146. void libertas_tx_runqueue(wlan_private *priv)
  147. {
  148. wlan_adapter *adapter = priv->adapter;
  149. int i;
  150. spin_lock(&adapter->txqueue_lock);
  151. for (i = 0; i < adapter->tx_queue_idx; i++) {
  152. struct sk_buff *skb = adapter->tx_queue_ps[i];
  153. spin_unlock(&adapter->txqueue_lock);
  154. SendSinglePacket(priv, skb);
  155. spin_lock(&adapter->txqueue_lock);
  156. }
  157. adapter->tx_queue_idx = 0;
  158. spin_unlock(&adapter->txqueue_lock);
  159. }
  160. static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
  161. {
  162. wlan_adapter *adapter = priv->adapter;
  163. spin_lock(&adapter->txqueue_lock);
  164. WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
  165. adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
  166. if (adapter->tx_queue_idx == NR_TX_QUEUE)
  167. netif_stop_queue(priv->wlan_dev.netdev);
  168. else
  169. netif_start_queue(priv->wlan_dev.netdev);
  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. ENTER();
  183. lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  184. if (priv->wlan_dev.dnld_sent) {
  185. lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
  186. priv->wlan_dev.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. LEAVE();
  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->radiomode != WLAN_RADIOMODE_RADIOTAP ||
  217. adapter->currenttxskb == NULL)
  218. return;
  219. radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
  220. if ((adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
  221. lbs_dbg_hex("TX feedback: ", (u8 *) radiotap_hdr,
  222. min_t(unsigned int, adapter->currenttxskb->len, 100));
  223. txfail = (status >> 24);
  224. #if 0
  225. /* The version of roofnet that we've tested does not use this yet
  226. * But it may be used in the future.
  227. */
  228. if (txfail)
  229. radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
  230. #endif
  231. try_count = (status >> 16) & 0xff;
  232. radiotap_hdr->data_retries = (try_count) ?
  233. (1 + adapter->txretrycount - try_count) : 0;
  234. libertas_upload_rx_packet(priv, adapter->currenttxskb);
  235. adapter->currenttxskb = NULL;
  236. priv->adapter->TxLockFlag = 0;
  237. if (priv->adapter->connect_status == libertas_connected)
  238. netif_wake_queue(priv->wlan_dev.netdev);
  239. }