tx.c 5.9 KB

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