tx.c 6.1 KB

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