tx.c revision 8910cfa3ac022feebfe1c4ae021afc34a1c1af25
1f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho/* 2f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * This file is part of wl1271 3f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 4f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * Copyright (C) 2009 Nokia Corporation 5f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 6f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * Contact: Luciano Coelho <luciano.coelho@nokia.com> 7f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 8f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * This program is free software; you can redistribute it and/or 9f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * modify it under the terms of the GNU General Public License 10f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * version 2 as published by the Free Software Foundation. 11f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 12f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * This program is distributed in the hope that it will be useful, but 13f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * WITHOUT ANY WARRANTY; without even the implied warranty of 14f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * General Public License for more details. 16f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 17f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * You should have received a copy of the GNU General Public License 18f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * along with this program; if not, write to the Free Software 19f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 02110-1301 USA 21f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 22f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho */ 23f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 24f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho#include <linux/kernel.h> 25f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho#include <linux/module.h> 26c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov#include <linux/etherdevice.h> 278910cfa3ac022feebfe1c4ae021afc34a1c1af25Arik Nemtsov#include <linux/spinlock.h> 28f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 29c31be25a7144ebc9b7a22128909bac7654d4c46bLuciano Coelho#include "wlcore.h" 300f4e31222a2c0b93f25a87effd2033cb78c7a79cLuciano Coelho#include "debug.h" 3100d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "io.h" 3200d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "ps.h" 3300d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "tx.h" 3456d4f8f685c073c7ed7203b78c57f5d893d65102Arik Nemtsov#include "event.h" 35b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov#include "hw_ops.h" 36f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 3700782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho/* 3800782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho * TODO: this is here just for now, it must be removed when the data 3900782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho * operations are in place. 4000782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho */ 4100782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho#include "../wl12xx/reg.h" 4200782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho 43536129c8ad35de87ff2f864f205a54ac32bfebccEliad Pellerstatic int wl1271_set_default_wep_key(struct wl1271 *wl, 44536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct wl12xx_vif *wlvif, u8 id) 457f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov{ 467f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov int ret; 47536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); 487f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 497f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov if (is_ap) 50c690ec816f9fa2ab2b6200c5b79b6933acca49a4Eliad Peller ret = wl12xx_cmd_set_default_wep_key(wl, id, 51a8ab39a4b588e8523be2fa75671bdc9612d3467aEliad Peller wlvif->ap.bcast_hlid); 527f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov else 53154da67c7da14ffd8da292394f8cbc81cc5ea4e3Eliad Peller ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid); 547f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 557f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov if (ret < 0) 567f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov return ret; 577f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 587f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id); 597f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov return 0; 607f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov} 617f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 6225eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yarivstatic int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb) 63f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 6425eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv int id; 6525eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv 6672b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov id = find_first_zero_bit(wl->tx_frames_map, wl->num_tx_desc); 6772b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov if (id >= wl->num_tx_desc) 6825eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv return -EBUSY; 6925eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv 7025eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv __set_bit(id, wl->tx_frames_map); 7125eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames[id] = skb; 7225eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames_cnt++; 7325eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv return id; 7425eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv} 75f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 76872b345fbaef290f890d0bbd34b78ab50269980fArik Nemtsovvoid wl1271_free_tx_id(struct wl1271 *wl, int id) 7725eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv{ 7825eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv if (__test_and_clear_bit(id, wl->tx_frames_map)) { 7972b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov if (unlikely(wl->tx_frames_cnt == wl->num_tx_desc)) 80ef2e3004855e90d2919105e4a91d7df6ab9845a9Ido Yariv clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 81ef2e3004855e90d2919105e4a91d7df6ab9845a9Ido Yariv 8225eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames[id] = NULL; 8325eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames_cnt--; 8425eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv } 85f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 86872b345fbaef290f890d0bbd34b78ab50269980fArik NemtsovEXPORT_SYMBOL(wl1271_free_tx_id); 87f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 8899a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsovstatic void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl, 8999a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov struct sk_buff *skb) 9099a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov{ 9199a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov struct ieee80211_hdr *hdr; 9299a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov 9399a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov /* 9499a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov * add the station to the known list before transmitting the 9599a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov * authentication response. this way it won't get de-authed by FW 9699a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov * when transmitting too soon. 9799a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov */ 9899a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov hdr = (struct ieee80211_hdr *)(skb->data + 9999a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov sizeof(struct wl1271_tx_hw_descr)); 10099a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov if (ieee80211_is_auth(hdr->frame_control)) 10199a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov wl1271_acx_set_inconnection_sta(wl, hdr->addr1); 10299a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov} 10399a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov 104c7ffb902cca655e4d6bdda4156407008573bb214Eliad Pellerstatic void wl1271_tx_regulate_link(struct wl1271 *wl, 105c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller struct wl12xx_vif *wlvif, 106c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller u8 hlid) 107b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov{ 10837c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov bool fw_ps; 1099b17f1b371c5aa5179b3e5392bc22132a3371da4Arik Nemtsov u8 tx_pkts; 110b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 111c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller if (WARN_ON(!test_bit(hlid, wlvif->links_map))) 112b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov return; 113b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 114b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 1159b17f1b371c5aa5179b3e5392bc22132a3371da4Arik Nemtsov tx_pkts = wl->links[hlid].allocated_pkts; 116b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 117b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov /* 118b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov * if in FW PS and there is enough data in FW we can put the link 119b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov * into high-level PS and clean out its TX queues. 1209a1009684df5295883ba2eb85066a23ed3c3f6a6Arik Nemtsov * Make an exception if this is the only connected link. In this 1219a1009684df5295883ba2eb85066a23ed3c3f6a6Arik Nemtsov * case FW-memory congestion is less of a problem. 12237c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov * Note that a single connected STA means 3 active links, since we must 12337c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov * account for the global and broadcast AP links. The "fw_ps" check 12437c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov * assures us the third link is a STA connected to the AP. Otherwise 12537c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov * the FW would not set the PSM bit. 126b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov */ 12737c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov if (wl->active_link_count > 3 && fw_ps && 12837c68ea6997aac2faf21b83c28eda3b1659c4d45Arik Nemtsov tx_pkts >= WL1271_PS_STA_MAX_PACKETS) 1296e8cd3310491b10db20d0f7eaf5713b05fa7b753Eliad Peller wl12xx_ps_link_start(wl, wlvif, hlid, true); 130b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov} 131b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 132f8e0af6b8732b47c2531a280753d29a4ca2d114bArik Nemtsovbool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb) 133f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller{ 134f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller return wl->dummy_packet == skb; 135f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller} 136872b345fbaef290f890d0bbd34b78ab50269980fArik NemtsovEXPORT_SYMBOL(wl12xx_is_dummy_packet); 137f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 1382b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsovstatic u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1392b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov struct sk_buff *skb, struct ieee80211_sta *sta) 140a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 1412b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov if (sta) { 142a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct wl1271_station *wl_sta; 143a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1442b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov wl_sta = (struct wl1271_station *)sta->drv_priv; 145a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov return wl_sta->hlid; 146a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } else { 147a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct ieee80211_hdr *hdr; 148a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 14953d40d0b863e22b697f8d85e1f95cb6f9d2d95b1Eliad Peller if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) 150f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller return wl->system_hlid; 151f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 152a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov hdr = (struct ieee80211_hdr *)skb->data; 15345b60f7ddd05e38a6835fb93e8dbcc6ef9bf12faEliad Peller if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) 154a8ab39a4b588e8523be2fa75671bdc9612d3467aEliad Peller return wlvif->ap.bcast_hlid; 15545b60f7ddd05e38a6835fb93e8dbcc6ef9bf12faEliad Peller else 15645b60f7ddd05e38a6835fb93e8dbcc6ef9bf12faEliad Peller return wlvif->ap.global_hlid; 157a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 158a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 159a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 160d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Pelleru8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1612b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov struct sk_buff *skb, struct ieee80211_sta *sta) 162f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller{ 163dabf37dba405565ab46f4d1821c781730285b9edEliad Peller struct ieee80211_tx_info *control; 164dabf37dba405565ab46f4d1821c781730285b9edEliad Peller 165536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller if (wlvif->bss_type == BSS_TYPE_AP_BSS) 1662b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov return wl12xx_tx_get_hlid_ap(wl, wlvif, skb, sta); 167f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 168dabf37dba405565ab46f4d1821c781730285b9edEliad Peller control = IEEE80211_SKB_CB(skb); 169dabf37dba405565ab46f4d1821c781730285b9edEliad Peller if (control->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { 170dabf37dba405565ab46f4d1821c781730285b9edEliad Peller wl1271_debug(DEBUG_TX, "tx offchannel"); 171dabf37dba405565ab46f4d1821c781730285b9edEliad Peller return wlvif->dev_hlid; 172dabf37dba405565ab46f4d1821c781730285b9edEliad Peller } 173dabf37dba405565ab46f4d1821c781730285b9edEliad Peller 1743230f35e09f386ee604f55450dcd26098a3c4bc3Eliad Peller return wlvif->sta.hlid; 175f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller} 176f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 177b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsovunsigned int wlcore_calc_packet_alignment(struct wl1271 *wl, 178b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov unsigned int packet_length) 1790da13da767cd568c1fe2a7b5b936e86e521b5ae7Ido Yariv{ 1809fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis if ((wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME) || 1819fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis !(wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN)) 182f83985bb5f8f0f25d44ab7b108a709a52aa1c5e0Arik Nemtsov return ALIGN(packet_length, WL1271_TX_ALIGN_TO); 1839fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis else 1849fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE); 1850da13da767cd568c1fe2a7b5b936e86e521b5ae7Ido Yariv} 186b3b4b4b812018a06221b6d7b88a5540fccae2940Arik NemtsovEXPORT_SYMBOL(wlcore_calc_packet_alignment); 1870da13da767cd568c1fe2a7b5b936e86e521b5ae7Ido Yariv 188a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Pellerstatic int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif, 189536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct sk_buff *skb, u32 extra, u32 buf_offset, 19032bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov u8 hlid, bool is_gem) 191f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 192f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_descr *desc; 193f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; 1945c9417f1656b0f415f4be5a7cd7195ecadd7dd1aJuuso Oikarinen u32 total_blocks; 195742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov int id, ret = -EBUSY, ac; 19632bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov u32 spare_blocks; 197f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 19826a309c7586140afd40628a7031993afbaae0f07Igal Chernobelsky if (buf_offset + total_len > wl->aggr_buf_size) 1996c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv return -EAGAIN; 200a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv 20132bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov spare_blocks = wlcore_hw_get_spare_blocks(wl, is_gem); 20232bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov 203f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* allocate free identifier for the packet */ 20425eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv id = wl1271_alloc_tx_id(wl, skb); 205f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (id < 0) 206f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return id; 207f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 208b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks); 20948a61477bdc04896bd96d259388a0c42a7019943Shahar Levi 210f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (total_blocks <= wl->tx_blocks_available) { 211f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho desc = (struct wl1271_tx_hw_descr *)skb_push( 212f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho skb, total_len - skb->len); 213f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 2144a3b97eea216135cd37e6d3a4a6c551c201a6615Arik Nemtsov wlcore_hw_set_tx_desc_blocks(wl, desc, total_blocks, 2154a3b97eea216135cd37e6d3a4a6c551c201a6615Arik Nemtsov spare_blocks); 216ae77eccf04f8c36769bdba334e1bbcc7bb9d3644Shahar Levi 217f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho desc->id = id; 218f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 219f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl->tx_blocks_available -= total_blocks; 2207bb5d6ce9e6ebb3bb71915cb0224523d3c284b4fArik Nemtsov wl->tx_allocated_blocks += total_blocks; 221f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 22255df5afb13718cda49128fa5985556df91d07765Arik Nemtsov /* If the FW was empty before, arm the Tx watchdog */ 22355df5afb13718cda49128fa5985556df91d07765Arik Nemtsov if (wl->tx_allocated_blocks == total_blocks) 22455df5afb13718cda49128fa5985556df91d07765Arik Nemtsov wl12xx_rearm_tx_watchdog_locked(wl); 22555df5afb13718cda49128fa5985556df91d07765Arik Nemtsov 226742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 227742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov wl->tx_allocated_pkts[ac]++; 228bf54e301671a6ece6c94550294dc7faf14158cd3Arik Nemtsov 2299ebcb232158c737db21e22b7bfdc4fc6d661ea8cArik Nemtsov if (test_bit(hlid, wl->links_map)) 2309b17f1b371c5aa5179b3e5392bc22132a3371da4Arik Nemtsov wl->links[hlid].allocated_pkts++; 23109039f42a24084c10e7761ab28ef22932c62a46fArik Nemtsov 232f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho ret = 0; 233f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 234f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_debug(DEBUG_TX, 235f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho "tx_allocate: size: %d, blocks: %d, id: %d", 236f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho total_len, total_blocks, id); 237781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } else { 23825eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl1271_free_tx_id(wl, id); 239781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } 240f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 241f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return ret; 242f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 243f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 244a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Pellerstatic void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif, 245536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct sk_buff *skb, u32 extra, 246536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct ieee80211_tx_info *control, u8 hlid) 247f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 248ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen struct timespec ts; 249f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_descr *desc; 2506f266e912c0733e77f63e9ad245db3c966b75942Arik Nemtsov int ac, rate_idx; 251ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen s64 hosttime; 252cf00f379d82d170712150588accd2ebe316c2226John W. Linville u16 tx_attr = 0; 253f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller __le16 frame_control; 254f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller struct ieee80211_hdr *hdr; 255f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller u8 *frame_start; 256a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller bool is_dummy; 257f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 258f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho desc = (struct wl1271_tx_hw_descr *) skb->data; 259f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller frame_start = (u8 *)(desc + 1); 260f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller hdr = (struct ieee80211_hdr *)(frame_start + extra); 261f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller frame_control = hdr->frame_control; 262f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 2631e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen /* relocate space for security header */ 2641e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen if (extra) { 265f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller int hdrlen = ieee80211_hdrlen(frame_control); 266f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller memmove(frame_start, hdr, hdrlen); 2672fc28de5989e1c40fee4e92e2a8f3bdd47b1b34aArik Nemtsov skb_set_network_header(skb, skb_network_offset(skb) + extra); 2681e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen } 2691e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen 270f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* configure packet life time */ 271ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen getnstimeofday(&ts); 272ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen hosttime = (timespec_to_ns(&ts) >> 10); 273ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen desc->start_time = cpu_to_le32(hosttime - wl->time_offset); 274c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov 275a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller is_dummy = wl12xx_is_dummy_packet(wl, skb); 2760f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS) 277c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); 278c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov else 279c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU); 280f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 281db674d249c1fa20fd6731048f41646b3a2e8bdf5Eliad Peller /* queue */ 282c6999d831ab9ae5e368b20f3bc11b0ca9c17a7ecKalle Valo ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 283db674d249c1fa20fd6731048f41646b3a2e8bdf5Eliad Peller desc->tid = skb->priority; 284c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov 285a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller if (is_dummy) { 286ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi /* 287ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * FW expects the dummy packet to have an invalid session id - 288ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * any session id that is different than the one set in the join 289ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi */ 29098b8625301e55bd3e4340f704edc378e4707e577Eliad Peller tx_attr = (SESSION_COUNTER_INVALID << 291ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi TX_HW_ATTR_OFST_SESSION_COUNTER) & 292ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi TX_HW_ATTR_SESSION_COUNTER; 293ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi 294ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ; 2950f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller } else if (wlvif) { 2963ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov u8 session_id = wl->session_ids[hlid]; 2973ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov 2983ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_AP_ZERO_SESSION_ID) && 2993ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov (wlvif->bss_type == BSS_TYPE_AP_BSS)) 3003ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov session_id = 0; 3013ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov 302ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi /* configure the tx attributes */ 3033ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov tx_attr = session_id << TX_HW_ATTR_OFST_SESSION_COUNTER; 304ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 305ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi 30679b122dc51797b650201f21360481a0450e9b7e4Eliad Peller desc->hlid = hlid; 3070f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller if (is_dummy || !wlvif) 308a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller rate_idx = 0; 309a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller else if (wlvif->bss_type != BSS_TYPE_AP_BSS) { 3108f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira /* 3114340d1cf5f1a967074f5dabec09a06fc0ae52ac7Eliad Peller * if the packets are data packets 3128f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira * send them with AP rate policies (EAPOLs are an exception), 3138f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira * otherwise use default basic rates 3148f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira */ 315bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky if (skb->protocol == cpu_to_be16(ETH_P_PAE)) 3168f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira rate_idx = wlvif->sta.basic_rate_idx; 317bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky else if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE) 318bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky rate_idx = wlvif->sta.p2p_rate_idx; 3194340d1cf5f1a967074f5dabec09a06fc0ae52ac7Eliad Peller else if (ieee80211_is_data(frame_control)) 320e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->sta.ap_rate_idx; 321c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov else 322e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->sta.basic_rate_idx; 323c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov } else { 324a8ab39a4b588e8523be2fa75671bdc9612d3467aEliad Peller if (hlid == wlvif->ap.global_hlid) 325e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->ap.mgmt_rate_idx; 326bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky else if (hlid == wlvif->ap.bcast_hlid || 327c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov skb->protocol == cpu_to_be16(ETH_P_PAE) || 328c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov !ieee80211_is_data(frame_control)) 329c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov /* 330c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov * send non-data, bcast and EAPOLs using the 331c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov * min basic rate 332c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov */ 333e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->ap.bcast_rate_idx; 334e51ae9be2e313b63a43f1f93578d9a71d38a77eaArik Nemtsov else 335e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->ap.ucast_rate_idx[ac]; 336c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov } 337c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov 338c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY; 339d0f63b202146f3281800ee44823740c8bbf38f11Luciano Coelho 340f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller /* for WEP shared auth - no fw encryption is needed */ 341f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller if (ieee80211_is_auth(frame_control) && 342f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller ieee80211_has_protected(frame_control)) 343f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller tx_attr |= TX_HW_ATTR_HOST_ENCRYPT; 344f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller 345d0f63b202146f3281800ee44823740c8bbf38f11Luciano Coelho desc->tx_attr = cpu_to_le16(tx_attr); 3466f266e912c0733e77f63e9ad245db3c966b75942Arik Nemtsov 3472fc28de5989e1c40fee4e92e2a8f3bdd47b1b34aArik Nemtsov wlcore_hw_set_tx_desc_csum(wl, desc, skb); 3486f266e912c0733e77f63e9ad245db3c966b75942Arik Nemtsov wlcore_hw_set_tx_desc_data_len(wl, desc, skb); 349f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 350f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 351f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho/* caller must hold wl->mutex */ 352a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Pellerstatic int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif, 353930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov struct sk_buff *skb, u32 buf_offset, u8 hlid) 354f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 355f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct ieee80211_tx_info *info; 356f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u32 extra = 0; 357f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho int ret = 0; 358a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv u32 total_len; 359536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller bool is_dummy; 36032bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov bool is_gem = false; 361f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 3627a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (!skb) { 3637a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira wl1271_error("discarding null skb"); 364f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return -EINVAL; 3657a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira } 366f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 367930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov if (hlid == WL12XX_INVALID_LINK_ID) { 368930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_error("invalid hlid. dropping skb 0x%p", skb); 369930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov return -EINVAL; 370930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov } 371930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov 372f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho info = IEEE80211_SKB_CB(skb); 373f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 374536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller is_dummy = wl12xx_is_dummy_packet(wl, skb); 375536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller 3762c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) && 3772c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov info->control.hw_key && 37897359d1235eaf634fe706c9faa6e40181cc95fb8Johannes Berg info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) 3795ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller extra = WL1271_EXTRA_SPACE_TKIP; 380f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 381f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (info->control.hw_key) { 3827f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov bool is_wep; 3837f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov u8 idx = info->control.hw_key->hw_key_idx; 3847f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov u32 cipher = info->control.hw_key->cipher; 3857f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 3867f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || 3877f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov (cipher == WLAN_CIPHER_SUITE_WEP104); 388f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 389f75c753f3c77b758fa5ace90c15b2ea3b7a3d46dEliad Peller if (unlikely(is_wep && wlvif->default_key != idx)) { 390536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller ret = wl1271_set_default_wep_key(wl, wlvif, idx); 391f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (ret < 0) 392f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return ret; 393f75c753f3c77b758fa5ace90c15b2ea3b7a3d46dEliad Peller wlvif->default_key = idx; 394f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 39532bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov 39632bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov is_gem = (cipher == WL1271_CIPHER_SUITE_GEM); 397f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 39809039f42a24084c10e7761ab28ef22932c62a46fArik Nemtsov 39932bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid, 40032bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov is_gem); 401f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (ret < 0) 402f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return ret; 403f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 404a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid); 405fae2fd767e9d380ed0d05e4a5d6b1673e2c2d3dfArik Nemtsov 4060f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) { 40799a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov wl1271_tx_ap_update_inconnection_sta(wl, skb); 408c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller wl1271_tx_regulate_link(wl, wlvif, hlid); 409b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov } 41099a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov 411a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv /* 41248a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * The length of each packet is stored in terms of 41348a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * words. Thus, we must pad the skb data to make sure its 41448a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * length is aligned. The number of padding bytes is computed 41548a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * and set in wl1271_tx_fill_hdr. 41648a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * In special cases, we want to align to a specific block size 41748a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * (eg. for wl128x with SDIO we align to 256). 418a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv */ 419b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov total_len = wlcore_calc_packet_alignment(wl, skb->len); 42048a61477bdc04896bd96d259388a0c42a7019943Shahar Levi 421a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len); 422a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); 423f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 424990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv /* Revert side effects in the dummy packet skb, so it can be reused */ 425536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller if (is_dummy) 426990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 427990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv 428a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv return total_len; 429f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 430f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 431af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Pelleru32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set, 432af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller enum ieee80211_band rate_band) 433830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen{ 434830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen struct ieee80211_supported_band *band; 435830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen u32 enabled_rates = 0; 436830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen int bit; 437830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen 438af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller band = wl->hw->wiphy->bands[rate_band]; 439830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen for (bit = 0; bit < band->n_bitrates; bit++) { 440830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen if (rate_set & 0x1) 441830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen enabled_rates |= band->bitrates[bit].hw_value; 442830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen rate_set >>= 1; 443830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen } 444830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen 445b3a47ee0ec07b16f68c38052e8cd1b5cb417bdcaArik Nemtsov /* MCS rates indication are on bits 16 - 31 */ 44618357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates; 44718357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi 448b3a47ee0ec07b16f68c38052e8cd1b5cb417bdcaArik Nemtsov for (bit = 0; bit < 16; bit++) { 44918357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi if (rate_set & 0x1) 45018357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit); 45118357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi rate_set >>= 1; 45218357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi } 45318357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi 454830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen return enabled_rates; 455830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen} 456830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen 457a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsovvoid wl1271_handle_tx_low_watermark(struct wl1271 *wl) 4582fe33e8cff354a3f320549544bffebbbab680145Ido Yariv{ 459708bb3cf58a9bc90f3171ba64f30601f690e5aaaArik Nemtsov int i; 4601c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov struct wl12xx_vif *wlvif; 4612fe33e8cff354a3f320549544bffebbbab680145Ido Yariv 4621c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wl12xx_for_each_wlvif(wl, wlvif) { 4631c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 4641c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov if (wlcore_is_queue_stopped_by_reason(wl, wlvif, i, 4651c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WLCORE_QUEUE_STOP_REASON_WATERMARK) && 4661c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wlvif->tx_queue_count[i] <= 4671c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WL1271_TX_QUEUE_LOW_WATERMARK) 4681c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* firmware buffer has space, restart queues */ 4691c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wlcore_wake_queue(wl, wlvif, i, 4701c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WLCORE_QUEUE_STOP_REASON_WATERMARK); 471708bb3cf58a9bc90f3171ba64f30601f690e5aaaArik Nemtsov } 4722fe33e8cff354a3f320549544bffebbbab680145Ido Yariv } 4732fe33e8cff354a3f320549544bffebbbab680145Ido Yariv} 4742fe33e8cff354a3f320549544bffebbbab680145Ido Yariv 4750e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic int wlcore_select_ac(struct wl1271 *wl) 476742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov{ 477742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov int i, q = -1, ac; 478742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov u32 min_pkts = 0xffffffff; 479742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 480742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov /* 481742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * Find a non-empty ac where: 482742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * 1. There are packets to transmit 483742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * 2. The FW has the least allocated blocks 484742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * 485742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * We prioritize the ACs according to VO>VI>BE>BK 486742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov */ 487742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 488742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov ac = wl1271_tx_get_queue(i); 4890e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (wl->tx_queue_count[ac] && 4900e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->tx_allocated_pkts[ac] < min_pkts) { 491742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov q = ac; 492742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov min_pkts = wl->tx_allocated_pkts[q]; 493742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov } 494742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov } 495742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 4960e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov return q; 497742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov} 498742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 4990e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic struct sk_buff *wlcore_lnk_dequeue(struct wl1271 *wl, 5000e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl1271_link *lnk, u8 q) 5016742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen{ 502d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller struct sk_buff *skb; 5036742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen unsigned long flags; 5046742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 5050e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = skb_dequeue(&lnk->tx_queue[q]); 5066742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen if (skb) { 5076742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_lock_irqsave(&wl->wl_lock, flags); 5086246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov WARN_ON_ONCE(wl->tx_queue_count[q] <= 0); 509f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[q]--; 5108591d42452f16b1888419da4456142864b08ef9eArik Nemtsov if (lnk->wlvif) { 5118591d42452f16b1888419da4456142864b08ef9eArik Nemtsov WARN_ON_ONCE(lnk->wlvif->tx_queue_count[q] <= 0); 5128591d42452f16b1888419da4456142864b08ef9eArik Nemtsov lnk->wlvif->tx_queue_count[q]--; 5138591d42452f16b1888419da4456142864b08ef9eArik Nemtsov } 5146742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_unlock_irqrestore(&wl->wl_lock, flags); 5156742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen } 5166742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 5176742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen return skb; 5186742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen} 5196742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 5200e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic struct sk_buff *wlcore_lnk_dequeue_high_prio(struct wl1271 *wl, 5210e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 hlid, u8 ac, 5220e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 *low_prio_hlid) 5230e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov{ 5240e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl1271_link *lnk = &wl->links[hlid]; 5250e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 526f1626fd8983a5bc68ce2879865cce297eb96c0b4Arik Nemtsov if (!wlcore_hw_lnk_high_prio(wl, hlid, lnk)) { 5270e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (*low_prio_hlid == WL12XX_INVALID_LINK_ID && 528f1626fd8983a5bc68ce2879865cce297eb96c0b4Arik Nemtsov !skb_queue_empty(&lnk->tx_queue[ac]) && 529f1626fd8983a5bc68ce2879865cce297eb96c0b4Arik Nemtsov wlcore_hw_lnk_low_prio(wl, hlid, lnk)) 5300e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* we found the first non-empty low priority queue */ 5310e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov *low_prio_hlid = hlid; 5320e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5330e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov return NULL; 5340e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov } 5350e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5360e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov return wlcore_lnk_dequeue(wl, lnk, ac); 5370e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov} 5380e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5390e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic struct sk_buff *wlcore_vif_dequeue_high_prio(struct wl1271 *wl, 5400e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl12xx_vif *wlvif, 5410e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 ac, u8 *hlid, 5420e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 *low_prio_hlid) 543a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 544a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct sk_buff *skb = NULL; 545a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov int i, h, start_hlid; 546a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 547a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov /* start from the link after the last one */ 5484438aca9e16901d8d32a025ca27ad8284a117e09Eliad Peller start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS; 549a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 550a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov /* dequeue according to AC, round robin on each link */ 551c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller for (i = 0; i < WL12XX_MAX_LINKS; i++) { 552c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller h = (start_hlid + i) % WL12XX_MAX_LINKS; 553a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 554742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov /* only consider connected stations */ 555c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller if (!test_bit(h, wlvif->links_map)) 556742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov continue; 557742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 5580e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_lnk_dequeue_high_prio(wl, h, ac, 5590e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov low_prio_hlid); 560d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller if (!skb) 561742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov continue; 562742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 563d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller wlvif->last_tx_hlid = h; 564d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller break; 565a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 566a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 567d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller if (!skb) 5684438aca9e16901d8d32a025ca27ad8284a117e09Eliad Peller wlvif->last_tx_hlid = 0; 569a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 570930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov *hlid = wlvif->last_tx_hlid; 571a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov return skb; 572a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 573a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 574930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsovstatic struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl, u8 *hlid) 575a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 576990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv unsigned long flags; 577e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller struct wl12xx_vif *wlvif = wl->last_wlvif; 578990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv struct sk_buff *skb = NULL; 5790e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov int ac; 5800e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 low_prio_hlid = WL12XX_INVALID_LINK_ID; 5810e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5820e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov ac = wlcore_select_ac(wl); 5830e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (ac < 0) 5840e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov goto out; 585990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv 58649c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov /* continue from last wlvif (round robin) */ 587e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller if (wlvif) { 588e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller wl12xx_for_each_wlvif_continue(wl, wlvif) { 5890e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!wlvif->tx_queue_count[ac]) 5900e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov continue; 5910e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5920e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_vif_dequeue_high_prio(wl, wlvif, ac, hlid, 5930e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov &low_prio_hlid); 5940e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!skb) 5950e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov continue; 5960e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5970e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->last_wlvif = wlvif; 5980e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov break; 599e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 600e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 601e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller 60249c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov /* dequeue from the system HLID before the restarting wlvif list */ 603930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov if (!skb) { 6040e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_lnk_dequeue_high_prio(wl, wl->system_hlid, 6050e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov ac, &low_prio_hlid); 6060e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (skb) { 6070e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov *hlid = wl->system_hlid; 6080e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->last_wlvif = NULL; 6090e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov } 610930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov } 61149c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov 6120e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* Do a new pass over the wlvif list. But no need to continue 6130e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov * after last_wlvif. The previous pass should have found it. */ 614e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller if (!skb) { 615e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller wl12xx_for_each_wlvif(wl, wlvif) { 6160e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!wlvif->tx_queue_count[ac]) 6170e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov goto next; 6180e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6190e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_vif_dequeue_high_prio(wl, wlvif, ac, hlid, 6200e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov &low_prio_hlid); 621e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller if (skb) { 622e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller wl->last_wlvif = wlvif; 623e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller break; 624e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 62549c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov 6260e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovnext: 62749c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov if (wlvif == wl->last_wlvif) 62849c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov break; 629e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 630a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller } 631a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller 6320e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* no high priority skbs found - but maybe a low priority one? */ 6330e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!skb && low_prio_hlid != WL12XX_INVALID_LINK_ID) { 6340e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl1271_link *lnk = &wl->links[low_prio_hlid]; 6350e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_lnk_dequeue(wl, lnk, ac); 6360e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6370e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov WARN_ON(!skb); /* we checked this before */ 6380e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov *hlid = low_prio_hlid; 6390e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6400e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* ensure proper round robin in the vif/link levels */ 6410e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->last_wlvif = lnk->wlvif; 6420e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (lnk->wlvif) 6430e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov lnk->wlvif->last_tx_hlid = low_prio_hlid; 6440e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6450e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov } 6460e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 647990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (!skb && 648990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) { 649f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov int q; 650f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov 651990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv skb = wl->dummy_packet; 652930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov *hlid = wl->system_hlid; 653f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 654990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv spin_lock_irqsave(&wl->wl_lock, flags); 6556246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov WARN_ON_ONCE(wl->tx_queue_count[q] <= 0); 656f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[q]--; 657990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv spin_unlock_irqrestore(&wl->wl_lock, flags); 658990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv } 659990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv 6600e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovout: 661990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv return skb; 662a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 663a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 664d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Pellerstatic void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif, 665930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov struct sk_buff *skb, u8 hlid) 6666742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen{ 6676742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen unsigned long flags; 6686742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 6696742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 670990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (wl12xx_is_dummy_packet(wl, skb)) { 671990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); 672d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller } else { 673a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov skb_queue_head(&wl->links[hlid].tx_queue[q], skb); 674a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 675a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov /* make sure we dequeue the same packet next time */ 6764438aca9e16901d8d32a025ca27ad8284a117e09Eliad Peller wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) % 677d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller WL12XX_MAX_LINKS; 678a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 679a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 6806742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_lock_irqsave(&wl->wl_lock, flags); 681f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[q]++; 6828591d42452f16b1888419da4456142864b08ef9eArik Nemtsov if (wlvif) 6838591d42452f16b1888419da4456142864b08ef9eArik Nemtsov wlvif->tx_queue_count[q]++; 6846742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_unlock_irqrestore(&wl->wl_lock, flags); 6856742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen} 6866742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 68777ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Pellerstatic bool wl1271_tx_is_data_present(struct sk_buff *skb) 68877ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller{ 68977ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 69077ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller 69177ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller return ieee80211_is_data_present(hdr->frame_control); 69277ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller} 69377ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller 6949eb599e9c62dcfd4efece1936c385381b366b684Eliad Pellervoid wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids) 6959eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller{ 6969eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller struct wl12xx_vif *wlvif; 6979eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller u32 timeout; 6989eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller u8 hlid; 6999eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7009eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (!wl->conf.rx_streaming.interval) 7019eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller return; 7029eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7039eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (!wl->conf.rx_streaming.always && 7049eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)) 7059eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller return; 7069eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7079eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller timeout = wl->conf.rx_streaming.duration; 7089eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller wl12xx_for_each_wlvif_sta(wl, wlvif) { 7099eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller bool found = false; 7109eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) { 7119eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (test_bit(hlid, wlvif->links_map)) { 7129eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller found = true; 7139eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller break; 7149eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 7159eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 7169eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7179eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (!found) 7189eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller continue; 7199eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7209eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller /* enable rx streaming */ 7210744bdb60b51dce54553d5af9a6133f1fe419032Eliad Peller if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) 7229eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller ieee80211_queue_work(wl->hw, 7239eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller &wlvif->rx_streaming_enable_work); 7249eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7259eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller mod_timer(&wlvif->rx_streaming_timer, 7269eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller jiffies + msecs_to_jiffies(timeout)); 7279eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 7289eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller} 7299eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7307a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira/* 7317a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * Returns failure values only in case of failed bus ops within this function. 7327a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * wl1271_prepare_tx_frame retvals won't be returned in order to avoid 7337a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * triggering recovery by higher layers when not necessary. 7347a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * In case a FW command fails within wl1271_prepare_tx_frame fails a recovery 7357a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * will be queued in wl1271_cmd_send. -EAGAIN/-EBUSY from prepare_tx_frame 7367a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * can occur and are legitimate so don't propagate. -EINVAL will emit a WARNING 7377a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * within prepare_tx_frame code but there's nothing we should do about those 7387a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * as well. 7397a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira */ 740eb96f841b9563ba34969be25615548635728faf5Ido Yarivint wlcore_tx_work_locked(struct wl1271 *wl) 741f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 742a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller struct wl12xx_vif *wlvif; 743f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct sk_buff *skb; 7449eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller struct wl1271_tx_hw_descr *desc; 7459fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis u32 buf_offset = 0, last_len = 0; 7466c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv bool sent_packets = false; 7479eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0}; 748eb96f841b9563ba34969be25615548635728faf5Ido Yariv int ret = 0; 7497a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira int bus_ret = 0; 750930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov u8 hlid; 751f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 7524cc533830b7e6b309e8b73196c410951fc2bed91Ido Yariv if (unlikely(wl->state != WLCORE_STATE_ON)) 7537a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira return 0; 754f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 755930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov while ((skb = wl1271_skb_dequeue(wl, &hlid))) { 7560f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 7579eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller bool has_data = false; 7589eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 759a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller wlvif = NULL; 760f4d02007cdd56c59bdb9362c699875cb2d02c0feArik Nemtsov if (!wl12xx_is_dummy_packet(wl, skb)) 7610f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller wlvif = wl12xx_vif_to_data(info->control.vif); 762930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov else 763930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov hlid = wl->system_hlid; 764a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller 7659eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller has_data = wlvif && wl1271_tx_is_data_present(skb); 766930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset, 767930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov hlid); 7686c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv if (ret == -EAGAIN) { 769a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv /* 7706c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv * Aggregation buffer is full. 7716c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv * Flush buffer and try again. 7726c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv */ 773930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_skb_queue_head(wl, wlvif, skb, hlid); 7749fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis 7759fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset, 7769fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis last_len); 7777a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira bus_ret = wlcore_write_data(wl, REG_SLV_MEM_DATA, 7787a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira wl->aggr_buf, buf_offset, true); 7797a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (bus_ret < 0) 780eb96f841b9563ba34969be25615548635728faf5Ido Yariv goto out; 781eb96f841b9563ba34969be25615548635728faf5Ido Yariv 7826c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv sent_packets = true; 7836c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv buf_offset = 0; 7846c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv continue; 7856c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv } else if (ret == -EBUSY) { 7866c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv /* 7876c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv * Firmware buffer is full. 788a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv * Queue back last skb, and stop aggregating. 789a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv */ 790930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_skb_queue_head(wl, wlvif, skb, hlid); 791a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv /* No work left, avoid scheduling redundant tx work */ 792a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 793ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen goto out_ack; 794f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } else if (ret < 0) { 7955de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller if (wl12xx_is_dummy_packet(wl, skb)) 7965de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller /* 7975de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller * fw still expects dummy packet, 7985de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller * so re-enqueue it 7995de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller */ 800930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_skb_queue_head(wl, wlvif, skb, hlid); 8015de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller else 8025de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller ieee80211_free_txskb(wl->hw, skb); 803ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen goto out_ack; 804f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 8059fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis last_len = ret; 8069fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis buf_offset += last_len; 807a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv wl->tx_packets_count++; 8089eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (has_data) { 8099eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller desc = (struct wl1271_tx_hw_descr *) skb->data; 8109eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller __set_bit(desc->hlid, active_hlids); 8119eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 812f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 813f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 814ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinenout_ack: 815a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv if (buf_offset) { 8169fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset, last_len); 8177a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira bus_ret = wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf, 8187a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira buf_offset, true); 8197a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (bus_ret < 0) 820eb96f841b9563ba34969be25615548635728faf5Ido Yariv goto out; 821eb96f841b9563ba34969be25615548635728faf5Ido Yariv 8226c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv sent_packets = true; 8236c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv } 8246c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv if (sent_packets) { 825606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv /* 826606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv * Interrupt the firmware with the new packets. This is only 827606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv * required for older hardware revisions 828606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv */ 829b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv if (wl->quirks & WLCORE_QUIRK_END_OF_TRANSACTION) { 8307a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira bus_ret = wlcore_write32(wl, WL12XX_HOST_WR_ACCESS, 831b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv wl->tx_packets_count); 8327a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (bus_ret < 0) 833b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv goto out; 834b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv } 835606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv 836a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov wl1271_handle_tx_low_watermark(wl); 837a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv } 8389eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller wl12xx_rearm_rx_streaming(wl, active_hlids); 839eb96f841b9563ba34969be25615548635728faf5Ido Yariv 840eb96f841b9563ba34969be25615548635728faf5Ido Yarivout: 8417a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira return bus_ret; 842a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv} 843f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 844a522550a283de31c7cfc30c7a129ce584e38c582Ido Yarivvoid wl1271_tx_work(struct work_struct *work) 845a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv{ 846a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv struct wl1271 *wl = container_of(work, struct wl1271, tx_work); 847c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller int ret; 848a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv 849a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv mutex_lock(&wl->mutex); 850c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller ret = wl1271_ps_elp_wakeup(wl); 851c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller if (ret < 0) 852c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller goto out; 853c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller 854eb96f841b9563ba34969be25615548635728faf5Ido Yariv ret = wlcore_tx_work_locked(wl); 855eb96f841b9563ba34969be25615548635728faf5Ido Yariv if (ret < 0) { 856eb96f841b9563ba34969be25615548635728faf5Ido Yariv wl12xx_queue_recovery_work(wl); 857eb96f841b9563ba34969be25615548635728faf5Ido Yariv goto out; 858eb96f841b9563ba34969be25615548635728faf5Ido Yariv } 859c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller 860c75bbcdb200e2815c855e42a4685d170858af306Eliad Peller wl1271_ps_elp_sleep(wl); 861c1b193eb6557279d037ab18c00ab628c6c78847fEliad Pellerout: 862f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho mutex_unlock(&wl->mutex); 863f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 864f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 865d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchsstatic u8 wl1271_tx_get_rate_flags(u8 rate_class_index) 866d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs{ 867defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs u8 flags = 0; 868defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs 86943a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov /* 87043a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * TODO: use wl12xx constants when this code is moved to wl12xx, as 87143a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * only it uses Tx-completion. 87243a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov */ 87343a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov if (rate_class_index <= 8) 874defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs flags |= IEEE80211_TX_RC_MCS; 87543a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov 87643a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov /* 87743a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * TODO: use wl12xx constants when this code is moved to wl12xx, as 87843a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * only it uses Tx-completion. 87943a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov */ 88043a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov if (rate_class_index == 0) 881defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs flags |= IEEE80211_TX_RC_SHORT_GI; 88243a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov 883defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs return flags; 884d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs} 885d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs 886f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelhostatic void wl1271_tx_complete_packet(struct wl1271 *wl, 887f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_res_descr *result) 888f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 889f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct ieee80211_tx_info *info; 89048e93e402ad19f570bae323b07911bdf6562af8eEliad Peller struct ieee80211_vif *vif; 89148e93e402ad19f570bae323b07911bdf6562af8eEliad Peller struct wl12xx_vif *wlvif; 892f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct sk_buff *skb; 893f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho int id = result->id; 89431627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen int rate = -1; 895d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs u8 rate_flags = 0; 89631627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen u8 retries = 0; 897f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 898f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* check for id legality */ 89972b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) { 900f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_warning("TX result illegal id: %d", id); 901f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return; 902f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 903f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 904f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho skb = wl->tx_frames[id]; 905f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho info = IEEE80211_SKB_CB(skb); 906f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 907990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (wl12xx_is_dummy_packet(wl, skb)) { 908ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi wl1271_free_tx_id(wl, id); 909ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi return; 910ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 911ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi 91248e93e402ad19f570bae323b07911bdf6562af8eEliad Peller /* info->control is valid as long as we don't update info->status */ 91348e93e402ad19f570bae323b07911bdf6562af8eEliad Peller vif = info->control.vif; 91448e93e402ad19f570bae323b07911bdf6562af8eEliad Peller wlvif = wl12xx_vif_to_data(vif); 91548e93e402ad19f570bae323b07911bdf6562af8eEliad Peller 91631627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen /* update the TX status info */ 91731627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen if (result->status == TX_SUCCESS) { 91831627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 919f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho info->flags |= IEEE80211_TX_STAT_ACK; 92043a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov rate = wlcore_rate_to_idx(wl, result->rate_class_index, 9211b92f15ee0e0f06222d4fd36dc36960d217243b3Eliad Peller wlvif->band); 922d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs rate_flags = wl1271_tx_get_rate_flags(result->rate_class_index); 92331627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen retries = result->ack_failures; 92431627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen } else if (result->status == TX_RETRY_EXCEEDED) { 92531627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen wl->stats.excessive_retries++; 92631627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen retries = result->ack_failures; 927f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 928f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 92931627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen info->status.rates[0].idx = rate; 93031627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen info->status.rates[0].count = retries; 931d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs info->status.rates[0].flags = rate_flags; 93231627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen info->status.ack_signal = -1; 93331627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen 934f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl->stats.retry_count += result->ack_failures; 935f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 9361e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen /* remove private header from packet */ 9371e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 9381e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen 9391e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen /* remove TKIP header space if present */ 9402c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) && 9412c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov info->control.hw_key && 94297359d1235eaf634fe706c9faa6e40181cc95fb8Johannes Berg info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) { 9431e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 9445ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data, 9455ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller hdrlen); 9465ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller skb_pull(skb, WL1271_EXTRA_SPACE_TKIP); 9471e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen } 948f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 949f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" 950f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho " status 0x%x", 951f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho result->id, skb, result->ack_failures, 952f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho result->rate_class_index, result->status); 953f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 954f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* return the packet to the stack */ 955a620865edf62ea2d024bbfe62162244473badfcbIdo Yariv skb_queue_tail(&wl->deferred_tx_queue, skb); 95692ef8960aee2f840c6a54c968d40199843f015c0Eliad Peller queue_work(wl->freezable_wq, &wl->netstack_work); 95725eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl1271_free_tx_id(wl, result->id); 958f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 959f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 960f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho/* Called upon reception of a TX complete interrupt */ 961045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yarivint wlcore_tx_complete(struct wl1271 *wl) 962f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 9632c208890c6d4e16076c6664137703ec813e8fa6cJoe Perches struct wl1271_acx_mem_map *memmap = wl->target_mem_map; 964ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen u32 count, fw_counter; 965f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u32 i; 966045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv int ret; 967f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 968f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* read the tx results from the chipset */ 969045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv ret = wlcore_read(wl, le32_to_cpu(memmap->tx_result), 970045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv wl->tx_res_if, sizeof(*wl->tx_res_if), false); 971045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv if (ret < 0) 972045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv goto out; 973045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv 974ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); 975ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen 976ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen /* write host counter to chipset (to ack) */ 977b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv ret = wlcore_write32(wl, le32_to_cpu(memmap->tx_result) + 978b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv offsetof(struct wl1271_tx_hw_res_if, 979b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv tx_result_host_counter), fw_counter); 980b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv if (ret < 0) 981b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv goto out; 982ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen 983ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen count = fw_counter - wl->tx_results_count; 98406f7bc7db79fabe6b2ec16eff0f59e4acc21eb72Juuso Oikarinen wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); 985f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 986f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* verify that the result buffer is not getting overrun */ 987ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) 988f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_warning("TX result overflow from chipset: %d", count); 989f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 990f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* process the results */ 991f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho for (i = 0; i < count; i++) { 992f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_res_descr *result; 993f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; 994f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 995f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* process the packet */ 996f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho result = &(wl->tx_res_if->tx_results_queue[offset]); 997f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_tx_complete_packet(wl, result); 998f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 999f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl->tx_results_count++; 1000f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 1001045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv 1002045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yarivout: 1003045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv return ret; 1004f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 1005045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido YarivEXPORT_SYMBOL(wlcore_tx_complete); 1006f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1007a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsovvoid wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid) 1008a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 1009a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct sk_buff *skb; 1010f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov int i; 1011a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov unsigned long flags; 10121d36cd892c130a5a781acb282e083b94127f1c50Arik Nemtsov struct ieee80211_tx_info *info; 1013f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov int total[NUM_TX_QUEUES]; 10148591d42452f16b1888419da4456142864b08ef9eArik Nemtsov struct wl1271_link *lnk = &wl->links[hlid]; 1015a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1016a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 1017f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov total[i] = 0; 10188591d42452f16b1888419da4456142864b08ef9eArik Nemtsov while ((skb = skb_dequeue(&lnk->tx_queue[i]))) { 1019a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb); 102079ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov 102179ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov if (!wl12xx_is_dummy_packet(wl, skb)) { 102279ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov info = IEEE80211_SKB_CB(skb); 102379ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov info->status.rates[0].idx = -1; 102479ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov info->status.rates[0].count = 0; 102579ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov ieee80211_tx_status_ni(wl->hw, skb); 102679ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov } 102779ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov 1028f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov total[i]++; 1029a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 1030a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 1031a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1032a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 10338591d42452f16b1888419da4456142864b08ef9eArik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 1034f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[i] -= total[i]; 10358591d42452f16b1888419da4456142864b08ef9eArik Nemtsov if (lnk->wlvif) 10368591d42452f16b1888419da4456142864b08ef9eArik Nemtsov lnk->wlvif->tx_queue_count[i] -= total[i]; 10378591d42452f16b1888419da4456142864b08ef9eArik Nemtsov } 1038a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 1039a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1040a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov wl1271_handle_tx_low_watermark(wl); 1041a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 1042a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 10437dece1c8e1044287287d44ac183a946333b55fc3Arik Nemtsov/* caller must hold wl->mutex and TX must be stopped */ 1044d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Pellervoid wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1045f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 1046f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho int i; 1047f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1048f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* TX failure */ 1049d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) { 10506c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov if (wlvif->bss_type == BSS_TYPE_AP_BSS) { 10516c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov /* this calls wl12xx_free_link */ 1052c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller wl1271_free_sta(wl, wlvif, i); 10536c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov } else { 10546c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov u8 hlid = i; 10556c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov wl12xx_free_link(wl, wlvif, &hlid); 10566c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov } 1057f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 1058d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller wlvif->last_tx_hlid = 0; 1059d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller 10608591d42452f16b1888419da4456142864b08ef9eArik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) 10618591d42452f16b1888419da4456142864b08ef9eArik Nemtsov wlvif->tx_queue_count[i] = 0; 1062d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller} 1063d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller/* caller must hold wl->mutex and TX must be stopped */ 10646639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsovvoid wl12xx_tx_reset(struct wl1271 *wl) 1065d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller{ 1066d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller int i; 1067d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller struct sk_buff *skb; 1068d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller struct ieee80211_tx_info *info; 1069a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 10706246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov /* only reset the queues if something bad happened */ 10714c145185175dcca660265d2fcdd4feffc0249f8eVictor Goldenshtein if (wl1271_tx_total_queue_count(wl) != 0) { 10726246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov for (i = 0; i < WL12XX_MAX_LINKS; i++) 10736246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov wl1271_tx_reset_link_queues(wl, i); 10746246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov 10756246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) 10766246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov wl->tx_queue_count[i] = 0; 10776246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov } 1078f1acea9a9d48174f982e14a7a488b208d39d825fArik Nemtsov 10792fe33e8cff354a3f320549544bffebbbab680145Ido Yariv /* 10802fe33e8cff354a3f320549544bffebbbab680145Ido Yariv * Make sure the driver is at a consistent state, in case this 10812fe33e8cff354a3f320549544bffebbbab680145Ido Yariv * function is called from a context other than interface removal. 10827dece1c8e1044287287d44ac183a946333b55fc3Arik Nemtsov * This call will always wake the TX queues. 10832fe33e8cff354a3f320549544bffebbbab680145Ido Yariv */ 10846639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov wl1271_handle_tx_low_watermark(wl); 10852fe33e8cff354a3f320549544bffebbbab680145Ido Yariv 108672b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov for (i = 0; i < wl->num_tx_desc; i++) { 108750e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv if (wl->tx_frames[i] == NULL) 108850e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv continue; 108950e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 109050e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv skb = wl->tx_frames[i]; 109150e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv wl1271_free_tx_id(wl, i); 109250e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); 109350e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 1094990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (!wl12xx_is_dummy_packet(wl, skb)) { 1095ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi /* 1096ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * Remove private headers before passing the skb to 1097ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * mac80211 1098ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi */ 1099ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info = IEEE80211_SKB_CB(skb); 1100ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 11012c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) && 11022c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov info->control.hw_key && 1103ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info->control.hw_key->cipher == 1104ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi WLAN_CIPHER_SUITE_TKIP) { 1105ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 11065ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, 1107ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi skb->data, hdrlen); 11085ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller skb_pull(skb, WL1271_EXTRA_SPACE_TKIP); 1109ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 111050e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 1111ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info->status.rates[0].idx = -1; 1112ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info->status.rates[0].count = 0; 111350e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 1114c27d3accb6f06b0afedfe472dfe0c8e7d87ff0a6Eliad Peller ieee80211_tx_status_ni(wl->hw, skb); 1115ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 111650e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv } 1117781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen} 1118781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 1119781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen#define WL1271_TX_FLUSH_TIMEOUT 500000 1120781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 1121781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen/* caller must *NOT* hold wl->mutex */ 1122781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinenvoid wl1271_tx_flush(struct wl1271 *wl) 1123781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen{ 1124958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov unsigned long timeout, start_time; 112518aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov int i; 1126958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov start_time = jiffies; 1127958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov timeout = start_time + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); 1128781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 11292c38849f4a247673c8203a569444042e32d82410Arik Nemtsov /* only one flush should be in progress, for consistent queue state */ 11302c38849f4a247673c8203a569444042e32d82410Arik Nemtsov mutex_lock(&wl->flush_mutex); 11312c38849f4a247673c8203a569444042e32d82410Arik Nemtsov 1132f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_lock(&wl->mutex); 1133f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov if (wl->tx_frames_cnt == 0 && wl1271_tx_total_queue_count(wl) == 0) { 1134f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_unlock(&wl->mutex); 1135f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov goto out; 1136f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov } 1137f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov 11382c38849f4a247673c8203a569444042e32d82410Arik Nemtsov wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FLUSH); 11392c38849f4a247673c8203a569444042e32d82410Arik Nemtsov 1140781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen while (!time_after(jiffies, timeout)) { 1141958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov wl1271_debug(DEBUG_MAC80211, "flushing tx buffer: %d %d", 1142f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_frames_cnt, 1143f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl1271_tx_total_queue_count(wl)); 1144f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov 1145f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov /* force Tx and give the driver some time to flush data */ 1146f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_unlock(&wl->mutex); 1147f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov if (wl1271_tx_total_queue_count(wl)) 1148f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov wl1271_tx_work(&wl->tx_work); 1149f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov msleep(20); 1150f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_lock(&wl->mutex); 1151f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov 1152f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov if ((wl->tx_frames_cnt == 0) && 1153f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov (wl1271_tx_total_queue_count(wl) == 0)) { 1154958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov wl1271_debug(DEBUG_MAC80211, "tx flush took %d ms", 1155958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov jiffies_to_msecs(jiffies - start_time)); 1156f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov goto out_wake; 1157781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } 1158781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } 1159781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 1160958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov wl1271_warning("Unable to flush all TX buffers, " 1161958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov "timed out (timeout %d ms", 1162958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov WL1271_TX_FLUSH_TIMEOUT / 1000); 116318aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov 116418aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov /* forcibly flush all Tx buffers on our queues */ 116518aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov for (i = 0; i < WL12XX_MAX_LINKS; i++) 116618aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov wl1271_tx_reset_link_queues(wl, i); 11672c38849f4a247673c8203a569444042e32d82410Arik Nemtsov 1168f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsovout_wake: 11692c38849f4a247673c8203a569444042e32d82410Arik Nemtsov wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FLUSH); 1170f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_unlock(&wl->mutex); 1171f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsovout: 11722c38849f4a247673c8203a569444042e32d82410Arik Nemtsov mutex_unlock(&wl->flush_mutex); 1173f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 1174a1c597f2b22cdc228de3c58784b00e80b9b53e03Arik NemtsovEXPORT_SYMBOL_GPL(wl1271_tx_flush); 1175e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov 1176af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Pelleru32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set) 1177e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{ 1178af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller if (WARN_ON(!rate_set)) 1179af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller return 0; 1180e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov 1181af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller return BIT(__ffs(rate_set)); 1182e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov} 118378e28062fea51c62280cd17fe6143ed583f83ba0Eliad PellerEXPORT_SYMBOL_GPL(wl1271_tx_min_rate_get); 11846639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 11851c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_stop_queue_locked(struct wl1271 *wl, struct wl12xx_vif *wlvif, 11861c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov u8 queue, enum wlcore_queue_stop_reason reason) 11876639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 11881c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 11891c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov bool stopped = !!wl->queue_stop_reasons[hwq]; 11906639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 11916639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov /* queue should not be stopped for this reason */ 11921c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(test_and_set_bit(reason, &wl->queue_stop_reasons[hwq])); 11936639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 11946639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov if (stopped) 11956639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov return; 11966639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 11971c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_stop_queue(wl->hw, hwq); 11986639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 11996639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12001c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_stop_queue(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 queue, 12016639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov enum wlcore_queue_stop_reason reason) 12026639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12036639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov unsigned long flags; 12046639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12056639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12061c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wlcore_stop_queue_locked(wl, wlvif, queue, reason); 12076639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12086639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12096639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12101c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_wake_queue(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 queue, 12116639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov enum wlcore_queue_stop_reason reason) 12126639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12136639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov unsigned long flags; 12141c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 12156639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12166639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12176639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12186639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov /* queue should not be clear for this reason */ 12191c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(!test_and_clear_bit(reason, &wl->queue_stop_reasons[hwq])); 12206639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12211c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov if (wl->queue_stop_reasons[hwq]) 12226639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov goto out; 12236639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12241c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_wake_queue(wl->hw, hwq); 12256639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12266639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsovout: 12276639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12286639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12296639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12306639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsovvoid wlcore_stop_queues(struct wl1271 *wl, 12316639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov enum wlcore_queue_stop_reason reason) 12326639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12336639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov int i; 12341c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov unsigned long flags; 12356639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12361c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12376639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12381c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* mark all possible queues as stopped */ 12391c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov for (i = 0; i < WLCORE_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) 12401c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(test_and_set_bit(reason, 12411c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov &wl->queue_stop_reasons[i])); 12426639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12431c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* use the global version to make sure all vifs in mac80211 we don't 12441c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov * know are stopped. 12451c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov */ 12461c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_stop_queues(wl->hw); 12471c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov 12481c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12496639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12506639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12511c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_wake_queues(struct wl1271 *wl, 12521c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov enum wlcore_queue_stop_reason reason) 12536639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12546639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov int i; 12556639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov unsigned long flags; 12566639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12576639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12586639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12591c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* mark all possible queues as awake */ 12601c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov for (i = 0; i < WLCORE_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) 12611c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(!test_and_clear_bit(reason, 12621c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov &wl->queue_stop_reasons[i])); 12636639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12641c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* use the global version to make sure all vifs in mac80211 we don't 12651c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov * know are woken up. 12661c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov */ 12671c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_wake_queues(wl->hw); 12686639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12696639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12706639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12716639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12721c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovbool wlcore_is_queue_stopped_by_reason(struct wl1271 *wl, 12731c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov struct wl12xx_vif *wlvif, u8 queue, 12741c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov enum wlcore_queue_stop_reason reason) 12756639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 1276d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov unsigned long flags; 1277d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov bool stopped; 1278d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov 1279d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 1280d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov stopped = wlcore_is_queue_stopped_by_reason_locked(wl, wlvif, queue, 1281d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov reason); 1282d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 1283d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov 1284d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov return stopped; 1285d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov} 1286d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov 1287d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsovbool wlcore_is_queue_stopped_by_reason_locked(struct wl1271 *wl, 1288d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov struct wl12xx_vif *wlvif, u8 queue, 1289d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov enum wlcore_queue_stop_reason reason) 1290d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov{ 12911c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 1292d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov 12938910cfa3ac022feebfe1c4ae021afc34a1c1af25Arik Nemtsov assert_spin_locked(&wl->wl_lock); 12941c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov return test_bit(reason, &wl->queue_stop_reasons[hwq]); 12956639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12966639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 1297d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsovbool wlcore_is_queue_stopped_locked(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1298d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov u8 queue) 12996639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 13001c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 1301d6037d22f30738e942ddfd29e3fef17deb075420Arik Nemtsov 13028910cfa3ac022feebfe1c4ae021afc34a1c1af25Arik Nemtsov assert_spin_locked(&wl->wl_lock); 13031c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov return !!wl->queue_stop_reasons[hwq]; 13046639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 1305