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 (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
76 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
77 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
82 memset(plocaltxpd, 0, sizeof(struct txpd));
84 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
86 /* offset of actual data */
87 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
89 /* TxCtrl set by user or default */
90 plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
92 p802x_hdr = skb->data;
93 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
95 /* locate radiotap header */
96 pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
98 /* set txpd fields from the radiotap header */
99 new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
101 /* use new tx_control[4:0] */
102 new_rate |= (adapter->pkttxctrl & ~0x1f);
103 plocaltxpd->tx_control = cpu_to_le32(new_rate);
106 /* skip the radiotap header */
107 p802x_hdr += sizeof(struct tx_radiotap_hdr);
108 plocaltxpd->tx_packet_length =
109 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
110 - sizeof(struct tx_radiotap_hdr));
113 /* copy destination address from 802.3 or 802.11 header */
114 if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
115 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
117 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
119 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
121 if (IS_MESH_FRAME(skb)) {
122 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
125 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
127 ptr += sizeof(struct txpd);
129 lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
130 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
131 ret = priv->hw_host_to_card(priv, MVMS_DAT,
132 priv->adapter->tmptxbuf,
133 le16_to_cpu(plocaltxpd->tx_packet_length) +
134 sizeof(struct txpd));
137 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
141 lbs_deb_tx("SendSinglePacket succeeds\n");
145 priv->stats.tx_packets++;
146 priv->stats.tx_bytes += skb->len;
148 priv->stats.tx_dropped++;
149 priv->stats.tx_errors++;
152 if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
153 /* Keep the skb to echo it back once Tx feedback is
156 /* stop processing outgoing pkts */
157 netif_stop_queue(priv->dev);
159 netif_stop_queue(priv->mesh_dev);
160 /* freeze any packets already in our queues */
161 priv->adapter->TxLockFlag = 1;
163 dev_kfree_skb_any(skb);
164 priv->adapter->currenttxskb = NULL;
167 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
172 void libertas_tx_runqueue(wlan_private *priv)
174 wlan_adapter *adapter = priv->adapter;
177 spin_lock(&adapter->txqueue_lock);
178 for (i = 0; i < adapter->tx_queue_idx; i++) {
179 struct sk_buff *skb = adapter->tx_queue_ps[i];
180 spin_unlock(&adapter->txqueue_lock);
181 SendSinglePacket(priv, skb);
182 spin_lock(&adapter->txqueue_lock);
184 adapter->tx_queue_idx = 0;
185 spin_unlock(&adapter->txqueue_lock);
188 static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
190 wlan_adapter *adapter = priv->adapter;
192 spin_lock(&adapter->txqueue_lock);
194 WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
195 adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
196 if (adapter->tx_queue_idx == NR_TX_QUEUE) {
197 netif_stop_queue(priv->dev);
199 netif_stop_queue(priv->mesh_dev);
201 netif_start_queue(priv->dev);
203 netif_start_queue(priv->mesh_dev);
206 spin_unlock(&adapter->txqueue_lock);
210 * @brief This function checks the conditions and sends packet to IF
211 * layer if everything is ok.
213 * @param priv A pointer to wlan_private structure
216 int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
220 lbs_deb_enter(LBS_DEB_TX);
221 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
223 if (priv->dnld_sent) {
224 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
229 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
230 (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
231 wlan_tx_queue(priv, skb);
235 priv->adapter->currenttxskb = skb;
237 ret = SendSinglePacket(priv, skb);
239 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
244 * @brief This function sends to the host the last transmitted packet,
245 * filling the radiotap headers with transmission information.
247 * @param priv A pointer to wlan_private structure
248 * @param status A 32 bit value containing transmission status.
252 void libertas_send_tx_feedback(wlan_private * priv)
254 wlan_adapter *adapter = priv->adapter;
255 struct tx_radiotap_hdr *radiotap_hdr;
256 u32 status = adapter->eventcause;
260 if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP ||
261 adapter->currenttxskb == NULL)
264 radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
266 txfail = (status >> 24);
269 /* The version of roofnet that we've tested does not use this yet
270 * But it may be used in the future.
273 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
275 try_count = (status >> 16) & 0xff;
276 radiotap_hdr->data_retries = (try_count) ?
277 (1 + adapter->txretrycount - try_count) : 0;
278 libertas_upload_rx_packet(priv, adapter->currenttxskb);
279 adapter->currenttxskb = NULL;
280 priv->adapter->TxLockFlag = 0;
281 if (priv->adapter->connect_status == LIBERTAS_CONNECTED) {
282 netif_wake_queue(priv->dev);
284 netif_wake_queue(priv->mesh_dev);
287 EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);