2 * This file contains the handling of TX in wlan driver.
4 #include <linux/netdevice.h>
14 * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
15 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
17 * @param rate Input rate
18 * @return Output Rate (0 if invalid)
20 static u32 convert_radiotap_rate_to_mv(u8 rate)
27 case 11: /* 5.5 Mbps */
29 case 22: /* 11 Mbps */
35 case 24: /* 12 Mbps */
37 case 36: /* 18 Mbps */
39 case 48: /* 24 Mbps */
41 case 72: /* 36 Mbps */
43 case 96: /* 48 Mbps */
45 case 108: /* 54 Mbps */
52 * @brief This function processes a single packet and sends
55 * @param priv A pointer to struct lbs_private structure
56 * @param skb A pointer to skb which includes TX packet
59 static int SendSinglePacket(struct lbs_private *priv, struct sk_buff *skb)
62 struct txpd localtxpd;
63 struct txpd *plocaltxpd = &localtxpd;
65 struct tx_radiotap_hdr *pradiotap_hdr;
67 u8 *ptr = priv->tmptxbuf;
69 lbs_deb_enter(LBS_DEB_TX);
71 if (priv->surpriseremoved)
74 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
75 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
76 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
81 memset(plocaltxpd, 0, sizeof(struct txpd));
83 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
85 /* offset of actual data */
86 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
88 p802x_hdr = skb->data;
89 if (priv->monitormode != LBS_MONITOR_OFF) {
91 /* locate radiotap header */
92 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);
97 /* use new tx_control[4:0] */
98 plocaltxpd->tx_control = cpu_to_le32(new_rate);
101 /* skip the radiotap header */
102 p802x_hdr += sizeof(struct tx_radiotap_hdr);
103 plocaltxpd->tx_packet_length =
104 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
105 - sizeof(struct tx_radiotap_hdr));
108 /* copy destination address from 802.3 or 802.11 header */
109 if (priv->monitormode != LBS_MONITOR_OFF)
110 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
112 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
114 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
116 if (IS_MESH_FRAME(skb)) {
117 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
120 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
122 ptr += sizeof(struct txpd);
124 lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
125 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
126 ret = priv->hw_host_to_card(priv, MVMS_DAT,
128 le16_to_cpu(plocaltxpd->tx_packet_length) +
129 sizeof(struct txpd));
132 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
136 lbs_deb_tx("SendSinglePacket succeeds\n");
140 priv->stats.tx_packets++;
141 priv->stats.tx_bytes += skb->len;
143 priv->stats.tx_dropped++;
144 priv->stats.tx_errors++;
147 if (!ret && priv->monitormode != LBS_MONITOR_OFF) {
148 /* Keep the skb to echo it back once Tx feedback is
151 /* stop processing outgoing pkts */
152 netif_stop_queue(priv->dev);
154 netif_stop_queue(priv->mesh_dev);
156 /* Keep the skb around for when we get feedback */
157 priv->currenttxskb = skb;
159 dev_kfree_skb_any(skb);
162 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
168 * @brief This function checks the conditions and sends packet to IF
169 * layer if everything is ok.
171 * @param priv A pointer to struct lbs_private structure
174 int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
178 lbs_deb_enter(LBS_DEB_TX);
179 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
181 if (priv->dnld_sent) {
182 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
187 if ((priv->psstate == PS_STATE_SLEEP) ||
188 (priv->psstate == PS_STATE_PRE_SLEEP)) {
189 lbs_pr_alert("TX error: packet xmit in %ssleep mode\n",
190 priv->psstate == PS_STATE_SLEEP?"":"pre-");
194 ret = SendSinglePacket(priv, skb);
196 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
201 * @brief This function sends to the host the last transmitted packet,
202 * filling the radiotap headers with transmission information.
204 * @param priv A pointer to struct lbs_private structure
205 * @param status A 32 bit value containing transmission status.
209 void lbs_send_tx_feedback(struct lbs_private *priv)
211 struct tx_radiotap_hdr *radiotap_hdr;
212 u32 status = priv->eventcause;
216 if (priv->monitormode == LBS_MONITOR_OFF ||
217 priv->currenttxskb == NULL)
220 radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
222 txfail = (status >> 24);
225 /* The version of roofnet that we've tested does not use this yet
226 * But it may be used in the future.
229 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
231 try_count = (status >> 16) & 0xff;
232 radiotap_hdr->data_retries = (try_count) ?
233 (1 + priv->txretrycount - try_count) : 0;
234 lbs_upload_rx_packet(priv, priv->currenttxskb);
235 priv->currenttxskb = NULL;
237 if (priv->connect_status == LBS_CONNECTED)
238 netif_wake_queue(priv->dev);
240 if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
241 netif_wake_queue(priv->mesh_dev);
243 EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);