tx.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 struct lbs_private structure
  53. * @param skb A pointer to skb which includes TX packet
  54. * @return 0 or -1
  55. */
  56. static int SendSinglePacket(struct lbs_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->tmptxbuf;
  65. lbs_deb_enter(LBS_DEB_TX);
  66. if (priv->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->monitormode != LBS_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->monitormode != LBS_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->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->monitormode != LBS_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. /* Keep the skb around for when we get feedback */
  133. priv->currenttxskb = skb;
  134. } else {
  135. dev_kfree_skb_any(skb);
  136. }
  137. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  138. return ret;
  139. }
  140. /**
  141. * @brief This function checks the conditions and sends packet to IF
  142. * layer if everything is ok.
  143. *
  144. * @param priv A pointer to struct lbs_private structure
  145. * @return n/a
  146. */
  147. int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
  148. {
  149. int ret = -1;
  150. lbs_deb_enter(LBS_DEB_TX);
  151. lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
  152. if (priv->dnld_sent) {
  153. lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
  154. priv->dnld_sent);
  155. goto done;
  156. }
  157. if ((priv->psstate == PS_STATE_SLEEP) ||
  158. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  159. lbs_pr_alert("TX error: packet xmit in %ssleep mode\n",
  160. priv->psstate == PS_STATE_SLEEP?"":"pre-");
  161. goto done;
  162. }
  163. ret = SendSinglePacket(priv, skb);
  164. done:
  165. lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
  166. return ret;
  167. }
  168. /**
  169. * @brief This function sends to the host the last transmitted packet,
  170. * filling the radiotap headers with transmission information.
  171. *
  172. * @param priv A pointer to struct lbs_private structure
  173. * @param status A 32 bit value containing transmission status.
  174. *
  175. * @returns void
  176. */
  177. void lbs_send_tx_feedback(struct lbs_private *priv)
  178. {
  179. struct tx_radiotap_hdr *radiotap_hdr;
  180. u32 status = priv->eventcause;
  181. int txfail;
  182. int try_count;
  183. if (priv->monitormode == LBS_MONITOR_OFF ||
  184. priv->currenttxskb == NULL)
  185. return;
  186. radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
  187. txfail = (status >> 24);
  188. #if 0
  189. /* The version of roofnet that we've tested does not use this yet
  190. * But it may be used in the future.
  191. */
  192. if (txfail)
  193. radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
  194. #endif
  195. try_count = (status >> 16) & 0xff;
  196. radiotap_hdr->data_retries = (try_count) ?
  197. (1 + priv->txretrycount - try_count) : 0;
  198. lbs_upload_rx_packet(priv, priv->currenttxskb);
  199. priv->currenttxskb = NULL;
  200. if (priv->connect_status == LBS_CONNECTED)
  201. netif_wake_queue(priv->dev);
  202. if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
  203. netif_wake_queue(priv->mesh_dev);
  204. }
  205. EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);