2 * This file contains the handling of TX in wlan driver.
4 #include <linux/netdevice.h>
15 * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
16 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
18 * @param rate Input rate
19 * @return Output Rate (0 if invalid)
21 static u32
convert_radiotap_rate_to_mv(u8 rate
)
28 case 11: /* 5.5 Mbps */
30 case 22: /* 11 Mbps */
36 case 24: /* 12 Mbps */
38 case 36: /* 18 Mbps */
40 case 48: /* 24 Mbps */
42 case 72: /* 36 Mbps */
44 case 96: /* 48 Mbps */
46 case 108: /* 54 Mbps */
53 * @brief This function processes a single packet and sends
56 * @param priv A pointer to wlan_private structure
57 * @param skb A pointer to skb which includes TX packet
60 static int SendSinglePacket(wlan_private
* priv
, struct sk_buff
*skb
)
62 wlan_adapter
*adapter
= priv
->adapter
;
64 struct txpd localtxpd
;
65 struct txpd
*plocaltxpd
= &localtxpd
;
67 struct tx_radiotap_hdr
*pradiotap_hdr
;
69 u8
*ptr
= priv
->adapter
->tmptxbuf
;
73 if (priv
->adapter
->surpriseremoved
)
76 if ((priv
->adapter
->debugmode
& MRVDRV_DEBUG_TX_PATH
) != 0)
77 lbs_dbg_hex("TX packet: ", skb
->data
,
78 min_t(unsigned int, skb
->len
, 100));
80 if (!skb
->len
|| (skb
->len
> MRVDRV_ETH_TX_PACKET_BUFFER_SIZE
)) {
81 lbs_pr_debug(1, "Tx error: Bad skb length %d : %zd\n",
82 skb
->len
, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE
);
87 memset(plocaltxpd
, 0, sizeof(struct txpd
));
89 plocaltxpd
->tx_packet_length
= skb
->len
;
91 /* offset of actual data */
92 plocaltxpd
->tx_packet_location
= sizeof(struct txpd
);
94 /* TxCtrl set by user or default */
95 plocaltxpd
->tx_control
= adapter
->pkttxctrl
;
97 p802x_hdr
= skb
->data
;
98 if (priv
->adapter
->radiomode
== WLAN_RADIOMODE_RADIOTAP
) {
100 /* locate radiotap header */
101 pradiotap_hdr
= (struct tx_radiotap_hdr
*)skb
->data
;
103 /* set txpd fields from the radiotap header */
104 new_rate
= convert_radiotap_rate_to_mv(pradiotap_hdr
->rate
);
106 /* erase tx_control[4:0] */
107 plocaltxpd
->tx_control
&= ~0x1f;
108 /* write new tx_control[4:0] */
109 plocaltxpd
->tx_control
|= new_rate
;
112 /* skip the radiotap header */
113 p802x_hdr
+= sizeof(struct tx_radiotap_hdr
);
114 plocaltxpd
->tx_packet_length
-= 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
|= TxPD_MESH_FRAME
;
129 memcpy(ptr
, plocaltxpd
, sizeof(struct txpd
));
131 ptr
+= sizeof(struct txpd
);
133 lbs_dbg_hex("Tx Data", (u8
*) p802x_hdr
, plocaltxpd
->tx_packet_length
);
134 memcpy(ptr
, p802x_hdr
, plocaltxpd
->tx_packet_length
);
135 ret
= libertas_sbi_host_to_card(priv
, MVMS_DAT
,
136 priv
->adapter
->tmptxbuf
,
137 plocaltxpd
->tx_packet_length
+
138 sizeof(struct txpd
));
141 lbs_pr_debug(1, "Tx error: libertas_sbi_host_to_card failed: 0x%X\n", ret
);
145 lbs_pr_debug(1, "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
->wlan_dev
.netdev
);
162 /* freeze any packets already in our queues */
163 priv
->adapter
->TxLockFlag
= 1;
165 dev_kfree_skb_any(skb
);
166 priv
->adapter
->currenttxskb
= NULL
;
174 void libertas_tx_runqueue(wlan_private
*priv
)
176 wlan_adapter
*adapter
= priv
->adapter
;
179 spin_lock(&adapter
->txqueue_lock
);
180 for (i
= 0; i
< adapter
->tx_queue_idx
; i
++) {
181 struct sk_buff
*skb
= adapter
->tx_queue_ps
[i
];
182 spin_unlock(&adapter
->txqueue_lock
);
183 SendSinglePacket(priv
, skb
);
184 spin_lock(&adapter
->txqueue_lock
);
186 adapter
->tx_queue_idx
= 0;
187 spin_unlock(&adapter
->txqueue_lock
);
190 static void wlan_tx_queue(wlan_private
*priv
, struct sk_buff
*skb
)
192 wlan_adapter
*adapter
= priv
->adapter
;
194 spin_lock(&adapter
->txqueue_lock
);
196 WARN_ON(priv
->adapter
->tx_queue_idx
>= NR_TX_QUEUE
);
197 adapter
->tx_queue_ps
[adapter
->tx_queue_idx
++] = skb
;
198 if (adapter
->tx_queue_idx
== NR_TX_QUEUE
)
199 netif_stop_queue(priv
->wlan_dev
.netdev
);
201 netif_start_queue(priv
->wlan_dev
.netdev
);
203 spin_unlock(&adapter
->txqueue_lock
);
207 * @brief This function checks the conditions and sends packet to IF
208 * layer if everything is ok.
210 * @param priv A pointer to wlan_private structure
213 int libertas_process_tx(wlan_private
* priv
, struct sk_buff
*skb
)
219 lbs_dbg_hex("TX Data", skb
->data
, min_t(unsigned int, skb
->len
, 100));
221 if (priv
->wlan_dev
.dnld_sent
) {
222 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
223 priv
->wlan_dev
.dnld_sent
);
227 if ((priv
->adapter
->psstate
== PS_STATE_SLEEP
) ||
228 (priv
->adapter
->psstate
== PS_STATE_PRE_SLEEP
)) {
229 wlan_tx_queue(priv
, skb
);
233 priv
->adapter
->currenttxskb
= skb
;
235 ret
= SendSinglePacket(priv
, skb
);
242 * @brief This function sends to the host the last transmitted packet,
243 * filling the radiotap headers with transmission information.
245 * @param priv A pointer to wlan_private structure
246 * @param status A 32 bit value containing transmission status.
250 void libertas_send_tx_feedback(wlan_private
* priv
)
252 wlan_adapter
*adapter
= priv
->adapter
;
253 struct tx_radiotap_hdr
*radiotap_hdr
;
254 u32 status
= adapter
->eventcause
;
258 if (adapter
->radiomode
!= WLAN_RADIOMODE_RADIOTAP
||
259 adapter
->currenttxskb
== NULL
)
262 radiotap_hdr
= (struct tx_radiotap_hdr
*)adapter
->currenttxskb
->data
;
264 if ((adapter
->debugmode
& MRVDRV_DEBUG_TX_PATH
) != 0)
265 lbs_dbg_hex("TX feedback: ", (u8
*) radiotap_hdr
,
266 min_t(unsigned int, adapter
->currenttxskb
->len
, 100));
268 txfail
= (status
>> 24);
271 /* The version of roofnet that we've tested does not use this yet
272 * But it may be used in the future.
275 radiotap_hdr
->flags
&= IEEE80211_RADIOTAP_F_TX_FAIL
;
277 try_count
= (status
>> 16) & 0xff;
278 radiotap_hdr
->data_retries
= (try_count
) ?
279 (1 + adapter
->txretrycount
- try_count
) : 0;
280 libertas_upload_rx_packet(priv
, adapter
->currenttxskb
);
281 adapter
->currenttxskb
= NULL
;
282 priv
->adapter
->TxLockFlag
= 0;
283 if (priv
->adapter
->connect_status
== libertas_connected
)
284 netif_wake_queue(priv
->wlan_dev
.netdev
);