24 #include <linux/kernel.h>
25 #include <linux/module.h>
40 #include "../wl12xx/reg.h"
42 static int wl1271_set_default_wep_key(
struct wl1271 *wl,
50 wlvif->
ap.bcast_hlid);
87 static void wl1271_tx_ap_update_inconnection_sta(
struct wl1271 *wl,
103 static void wl1271_tx_regulate_link(
struct wl1271 *wl,
107 bool fw_ps, single_sta;
114 tx_pkts = wl->
links[hlid].allocated_pkts;
148 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
149 return wlvif->
ap.bcast_hlid;
151 return wlvif->
ap.global_hlid;
164 return wl12xx_tx_get_hlid_ap(wl, wlvif, skb, sta);
170 return wlvif->
sta.hlid;
176 unsigned int packet_length)
188 u8 hlid,
bool is_gem)
199 spare_blocks = wlcore_hw_get_spare_blocks(wl, is_gem);
202 id = wl1271_alloc_tx_id(wl, skb);
206 total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks);
208 if (total_blocks <= wl->tx_blocks_available) {
210 skb, total_len - skb->
len);
212 wlcore_hw_set_tx_desc_blocks(wl, desc, total_blocks,
224 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
235 "tx_allocate: size: %d, blocks: %d, id: %d",
236 total_len, total_blocks,
id);
259 frame_start = (
u8 *)(desc + 1);
266 memmove(frame_start, hdr, hdrlen);
267 skb_set_network_header(skb, skb_network_offset(skb) + extra);
272 hosttime = (timespec_to_ns(&
ts) >> 10);
282 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
302 if (is_dummy || !wlvif)
311 rate_idx = wlvif->
sta.basic_rate_idx;
313 rate_idx = wlvif->
sta.p2p_rate_idx;
314 else if (ieee80211_is_data(frame_control))
315 rate_idx = wlvif->
sta.ap_rate_idx;
317 rate_idx = wlvif->
sta.basic_rate_idx;
319 if (hlid == wlvif->
ap.global_hlid)
320 rate_idx = wlvif->
ap.mgmt_rate_idx;
321 else if (hlid == wlvif->
ap.bcast_hlid ||
323 !ieee80211_is_data(frame_control))
328 rate_idx = wlvif->
ap.bcast_rate_idx;
330 rate_idx = wlvif->
ap.ucast_rate_idx[ac];
336 if (ieee80211_is_auth(frame_control) &&
337 ieee80211_has_protected(frame_control))
342 wlcore_hw_set_tx_desc_csum(wl, desc, skb);
343 wlcore_hw_set_tx_desc_data_len(wl, desc, skb);
347 static int wl1271_prepare_tx_frame(
struct wl1271 *wl,
struct wl12xx_vif *wlvif,
367 info = IEEE80211_SKB_CB(skb);
385 ret = wl1271_set_default_wep_key(wl, wlvif, idx);
394 ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid,
399 wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
402 wl1271_tx_ap_update_inconnection_sta(wl, skb);
403 wl1271_tx_regulate_link(wl, wlvif, hlid);
430 u32 enabled_rates = 0;
433 band = wl->
hw->wiphy->bands[rate_band];
434 for (bit = 0; bit < band->
n_bitrates; bit++) {
443 for (bit = 0; bit < 16; bit++) {
449 return enabled_rates;
471 u32 min_pkts = 0xffffffff;
481 ac = wl1271_tx_get_queue(i);
482 if (!skb_queue_empty(&queues[ac]) &&
495 static struct sk_buff *wl12xx_lnk_skb_dequeue(
struct wl1271 *wl,
502 queue = wl1271_select_queue(wl, lnk->
tx_queue);
508 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
512 spin_unlock_irqrestore(&wl->
wl_lock, flags);
518 static struct sk_buff *wl12xx_vif_skb_dequeue(
struct wl1271 *wl,
523 int i,
h, start_hlid;
530 h = (start_hlid +
i) % WL12XX_MAX_LINKS;
536 skb = wl12xx_lnk_skb_dequeue(wl, &wl->
links[h]);
560 skb = wl12xx_vif_skb_dequeue(wl, wlvif, hlid);
577 skb = wl12xx_vif_skb_dequeue(wl, wlvif, hlid);
598 q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
602 spin_unlock_irqrestore(&wl->
wl_lock, flags);
608 static void wl1271_skb_queue_head(
struct wl1271 *wl,
struct wl12xx_vif *wlvif,
612 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
626 spin_unlock_irqrestore(&wl->
wl_lock, flags);
629 static bool wl1271_tx_is_data_present(
struct sk_buff *skb)
642 if (!wl->
conf.rx_streaming.interval)
645 if (!wl->
conf.rx_streaming.always &&
649 timeout = wl->
conf.rx_streaming.duration;
687 u32 buf_offset = 0, last_len = 0;
688 bool sent_packets =
false;
689 unsigned long active_hlids[
BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
697 while ((skb = wl1271_skb_dequeue(wl, &hlid))) {
703 wlvif = wl12xx_vif_to_data(info->
control.vif);
707 has_data = wlvif && wl1271_tx_is_data_present(skb);
708 ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset,
715 wl1271_skb_queue_head(wl, wlvif, skb, hlid);
717 buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset,
727 }
else if (ret == -
EBUSY) {
732 wl1271_skb_queue_head(wl, wlvif, skb, hlid);
736 }
else if (ret < 0) {
742 wl1271_skb_queue_head(wl, wlvif, skb, hlid);
748 buf_offset += last_len;
758 buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset, last_len);
807 static u8 wl1271_tx_get_rate_flags(
u8 rate_class_index)
815 if (rate_class_index <= 8)
822 if (rate_class_index == 0)
828 static void wl1271_tx_complete_packet(
struct wl1271 *wl,
847 info = IEEE80211_SKB_CB(skb);
856 wlvif = wl12xx_vif_to_data(vif);
867 wl->
stats.excessive_retries++;
873 info->
status.rates[0].flags = rate_flags;
874 info->
status.ack_signal = -1;
940 tx_result_host_counter), fw_counter);
952 for (i = 0; i <
count; i++) {
958 wl1271_tx_complete_packet(wl, result);
982 info = IEEE80211_SKB_CB(skb);
983 info->
status.rates[0].idx = -1;
984 info->
status.rates[0].count = 0;
985 ieee80211_tx_status_ni(wl->
hw, skb);
995 spin_unlock_irqrestore(&wl->
wl_lock, flags);
1010 wlvif->
sta.ba_rx_bitmap = 0;
1012 wl->
links[
i].allocated_pkts = 0;
1013 wl->
links[
i].prev_freed_pkts = 0;
1026 if (
WARN_ON_ONCE(wl1271_tx_total_queue_count(wl) != 0)) {
1054 info = IEEE80211_SKB_CB(skb);
1058 info->
control.hw_key->cipher ==
1066 info->
status.rates[0].idx = -1;
1067 info->
status.rates[0].count = 0;
1069 ieee80211_tx_status_ni(wl->
hw, skb);
1074 #define WL1271_TX_FLUSH_TIMEOUT 500000
1088 if (wl->
tx_frames_cnt == 0 && wl1271_tx_total_queue_count(wl) == 0) {
1098 wl1271_tx_total_queue_count(wl));
1102 if (wl1271_tx_total_queue_count(wl))
1108 (wl1271_tx_total_queue_count(wl) == 0)) {
1116 "timed out (timeout %d ms",
1156 unsigned long flags;
1160 spin_unlock_irqrestore(&wl->
wl_lock, flags);
1166 unsigned long flags;
1179 spin_unlock_irqrestore(&wl->
wl_lock, flags);
1205 unsigned long flags;
1215 wl1271_tx_get_mac80211_queue(i));
1218 spin_unlock_irqrestore(&wl->
wl_lock, flags);