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 wlan_private structure
56 * @param skb A pointer to skb which includes TX packet
59 static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb)
61 wlan_adapter *adapter = priv->adapter;
63 struct txpd localtxpd;
64 struct txpd *plocaltxpd = &localtxpd;
66 struct tx_radiotap_hdr *pradiotap_hdr;
68 u8 *ptr = priv->adapter->tmptxbuf;
70 lbs_deb_enter(LBS_DEB_TX);
72 if (priv->adapter->surpriseremoved)
75 if ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
76 lbs_dbg_hex("TX packet: ", skb->data,
77 min_t(unsigned int, skb->len, 100));
79 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
80 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
81 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
86 memset(plocaltxpd, 0, sizeof(struct txpd));
88 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
90 /* offset of actual data */
91 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
93 /* TxCtrl set by user or default */
94 plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
96 p802x_hdr = skb->data;
97 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
99 /* locate radiotap header */
100 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);
105 /* use new tx_control[4:0] */
106 new_rate |= (adapter->pkttxctrl & ~0x1f);
107 plocaltxpd->tx_control = cpu_to_le32(new_rate);
110 /* skip the radiotap header */
111 p802x_hdr += sizeof(struct tx_radiotap_hdr);
112 plocaltxpd->tx_packet_length =
113 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
114 - sizeof(struct tx_radiotap_hdr));
117 /* copy destination address from 802.3 or 802.11 header */
118 if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
119 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
121 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
123 lbs_dbg_hex("txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
125 if (IS_MESH_FRAME(skb)) {
126 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
129 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
131 ptr += sizeof(struct txpd);
133 lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
134 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
135 ret = priv->hw_host_to_card(priv, MVMS_DAT,
136 priv->adapter->tmptxbuf,
137 le16_to_cpu(plocaltxpd->tx_packet_length) +
138 sizeof(struct txpd));
141 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
145 lbs_deb_tx("SendSinglePacket succeeds\n");
149 priv->stats.tx_packets++;
150 priv->stats.tx_bytes += skb->len;
152 priv->stats.tx_dropped++;
153 priv->stats.tx_errors++;
156 if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
157 /* Keep the skb to echo it back once Tx feedback is
160 /* stop processing outgoing pkts */
161 netif_stop_queue(priv->dev);
162 netif_stop_queue(priv->mesh_dev);
163 /* freeze any packets already in our queues */
164 priv->adapter->TxLockFlag = 1;
166 dev_kfree_skb_any(skb);
167 priv->adapter->currenttxskb = NULL;
170 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
175 void libertas_tx_runqueue(wlan_private *priv)
177 wlan_adapter *adapter = priv->adapter;
180 spin_lock(&adapter->txqueue_lock);
181 for (i = 0; i < adapter->tx_queue_idx; i++) {
182 struct sk_buff *skb = adapter->tx_queue_ps[i];
183 spin_unlock(&adapter->txqueue_lock);
184 SendSinglePacket(priv, skb);
185 spin_lock(&adapter->txqueue_lock);
187 adapter->tx_queue_idx = 0;
188 spin_unlock(&adapter->txqueue_lock);
191 static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
193 wlan_adapter *adapter = priv->adapter;
195 spin_lock(&adapter->txqueue_lock);
197 WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
198 adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
199 if (adapter->tx_queue_idx == NR_TX_QUEUE) {
200 netif_stop_queue(priv->dev);
201 netif_stop_queue(priv->mesh_dev);
203 netif_start_queue(priv->dev);
204 netif_start_queue(priv->mesh_dev);
207 spin_unlock(&adapter->txqueue_lock);
211 * @brief This function checks the conditions and sends packet to IF
212 * layer if everything is ok.
214 * @param priv A pointer to wlan_private structure
217 int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
221 lbs_deb_enter(LBS_DEB_TX);
222 lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100));
224 if (priv->dnld_sent) {
225 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
230 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
231 (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
232 wlan_tx_queue(priv, skb);
236 priv->adapter->currenttxskb = skb;
238 ret = SendSinglePacket(priv, skb);
240 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
245 * @brief This function sends to the host the last transmitted packet,
246 * filling the radiotap headers with transmission information.
248 * @param priv A pointer to wlan_private structure
249 * @param status A 32 bit value containing transmission status.
253 void libertas_send_tx_feedback(wlan_private * priv)
255 wlan_adapter *adapter = priv->adapter;
256 struct tx_radiotap_hdr *radiotap_hdr;
257 u32 status = adapter->eventcause;
261 if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP ||
262 adapter->currenttxskb == NULL)
265 radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
267 if ((adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
268 lbs_dbg_hex("TX feedback: ", (u8 *) radiotap_hdr,
269 min_t(unsigned int, adapter->currenttxskb->len, 100));
271 txfail = (status >> 24);
274 /* The version of roofnet that we've tested does not use this yet
275 * But it may be used in the future.
278 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
280 try_count = (status >> 16) & 0xff;
281 radiotap_hdr->data_retries = (try_count) ?
282 (1 + adapter->txretrycount - try_count) : 0;
283 libertas_upload_rx_packet(priv, adapter->currenttxskb);
284 adapter->currenttxskb = NULL;
285 priv->adapter->TxLockFlag = 0;
286 if (priv->adapter->connect_status == libertas_connected) {
287 netif_wake_queue(priv->dev);
288 netif_wake_queue(priv->mesh_dev);
291 EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);