tx.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 checks the conditions and sends packet to IF
  50. * layer if everything is ok.
  51. *
  52. * @param priv A pointer to struct lbs_private structure
  53. * @param skb A pointer to skb which includes TX packet
  54. * @return 0 or -1
  55. */
  56. static int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
  57. {
  58. int ret = -1;
  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->tmptxbuf;
  65. lbs_deb_enter(LBS_DEB_TX);
  66. lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  67. if (priv->dnld_sent) {
  68. lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
  69. priv->dnld_sent);
  70. goto done;
  71. }
  72. if ((priv->psstate == PS_STATE_SLEEP) ||
  73. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  74. lbs_pr_alert("TX error: packet xmit in %ssleep mode\n",
  75. priv->psstate == PS_STATE_SLEEP?"":"pre-");
  76. goto done;
  77. }
  78. if (priv->surpriseremoved)
  79. return -1;
  80. if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
  81. lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
  82. skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
  83. goto done_tx;
  84. }
  85. ret = 0;
  86. memset(plocaltxpd, 0, sizeof(struct txpd));
  87. plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
  88. /* offset of actual data */
  89. plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
  90. p802x_hdr = skb->data;
  91. if (priv->monitormode != LBS_MONITOR_OFF) {
  92. /* locate radiotap header */
  93. pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
  94. /* set txpd fields from the radiotap header */
  95. new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
  96. if (new_rate != 0) {
  97. /* use new tx_control[4:0] */
  98. plocaltxpd->tx_control = cpu_to_le32(new_rate);
  99. }
  100. /* skip the radiotap header */
  101. p802x_hdr += sizeof(struct tx_radiotap_hdr);
  102. plocaltxpd->tx_packet_length =
  103. cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
  104. - sizeof(struct tx_radiotap_hdr));
  105. }
  106. /* copy destination address from 802.3 or 802.11 header */
  107. if (priv->monitormode != LBS_MONITOR_OFF)
  108. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
  109. else
  110. memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
  111. lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
  112. if (IS_MESH_FRAME(skb)) {
  113. plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
  114. }
  115. memcpy(ptr, plocaltxpd, sizeof(struct txpd));
  116. ptr += sizeof(struct txpd);
  117. lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  118. memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
  119. ret = priv->hw_host_to_card(priv, MVMS_DAT,
  120. priv->tmptxbuf,
  121. le16_to_cpu(plocaltxpd->tx_packet_length) +
  122. sizeof(struct txpd));
  123. if (ret) {
  124. lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
  125. goto done_tx;
  126. }
  127. lbs_deb_tx("%s succeeds\n", __func__);
  128. done_tx:
  129. if (!ret) {
  130. priv->stats.tx_packets++;
  131. priv->stats.tx_bytes += skb->len;
  132. } else {
  133. priv->stats.tx_dropped++;
  134. priv->stats.tx_errors++;
  135. }
  136. if (!ret && priv->monitormode != LBS_MONITOR_OFF) {
  137. /* Keep the skb to echo it back once Tx feedback is
  138. received from FW */
  139. skb_orphan(skb);
  140. /* stop processing outgoing pkts */
  141. netif_stop_queue(priv->dev);
  142. if (priv->mesh_dev)
  143. netif_stop_queue(priv->mesh_dev);
  144. /* Keep the skb around for when we get feedback */
  145. priv->currenttxskb = skb;
  146. } else {
  147. dev_kfree_skb_any(skb);
  148. }
  149. done:
  150. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  151. return ret;
  152. }
  153. int lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  154. {
  155. int ret = 0;
  156. struct lbs_private *priv = dev->priv;
  157. lbs_deb_enter(LBS_DEB_TX);
  158. /* We could return NETDEV_TX_BUSY here, but I'd actually
  159. like to get the point where we can BUG() */
  160. if (priv->dnld_sent) {
  161. lbs_pr_err("%s while dnld_sent\n", __func__);
  162. priv->stats.tx_dropped++;
  163. goto done;
  164. }
  165. if (priv->currenttxskb) {
  166. lbs_pr_err("%s while TX skb pending\n", __func__);
  167. priv->stats.tx_dropped++;
  168. goto done;
  169. }
  170. netif_stop_queue(priv->dev);
  171. if (priv->mesh_dev)
  172. netif_stop_queue(priv->mesh_dev);
  173. if (lbs_process_tx(priv, skb) == 0)
  174. dev->trans_start = jiffies;
  175. done:
  176. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  177. return ret;
  178. }
  179. /**
  180. * @brief This function sends to the host the last transmitted packet,
  181. * filling the radiotap headers with transmission information.
  182. *
  183. * @param priv A pointer to struct lbs_private structure
  184. * @param status A 32 bit value containing transmission status.
  185. *
  186. * @returns void
  187. */
  188. void lbs_send_tx_feedback(struct lbs_private *priv)
  189. {
  190. struct tx_radiotap_hdr *radiotap_hdr;
  191. u32 status = priv->eventcause;
  192. int txfail;
  193. int try_count;
  194. if (priv->monitormode == LBS_MONITOR_OFF ||
  195. priv->currenttxskb == NULL)
  196. return;
  197. radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
  198. txfail = (status >> 24);
  199. #if 0
  200. /* The version of roofnet that we've tested does not use this yet
  201. * But it may be used in the future.
  202. */
  203. if (txfail)
  204. radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
  205. #endif
  206. try_count = (status >> 16) & 0xff;
  207. radiotap_hdr->data_retries = (try_count) ?
  208. (1 + priv->txretrycount - try_count) : 0;
  209. lbs_upload_rx_packet(priv, priv->currenttxskb);
  210. priv->currenttxskb = NULL;
  211. if (priv->connect_status == LBS_CONNECTED)
  212. netif_wake_queue(priv->dev);
  213. if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
  214. netif_wake_queue(priv->mesh_dev);
  215. }
  216. EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);