tx.c revision 1c33db782d1d0d9be83feacbb065cd4956f485e7
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> 27f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 28c31be25a7144ebc9b7a22128909bac7654d4c46bLuciano Coelho#include "wlcore.h" 290f4e31222a2c0b93f25a87effd2033cb78c7a79cLuciano Coelho#include "debug.h" 3000d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "io.h" 3100d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "ps.h" 3200d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "tx.h" 3356d4f8f685c073c7ed7203b78c57f5d893d65102Arik Nemtsov#include "event.h" 34b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov#include "hw_ops.h" 35f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 3600782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho/* 3700782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho * TODO: this is here just for now, it must be removed when the data 3800782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho * operations are in place. 3900782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho */ 4000782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho#include "../wl12xx/reg.h" 4100782136b4d6e2316e0a2a55f3b1fba160e9576eLuciano Coelho 42536129c8ad35de87ff2f864f205a54ac32bfebccEliad Pellerstatic int wl1271_set_default_wep_key(struct wl1271 *wl, 43536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct wl12xx_vif *wlvif, u8 id) 447f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov{ 457f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov int ret; 46536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); 477f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 487f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov if (is_ap) 49c690ec816f9fa2ab2b6200c5b79b6933acca49a4Eliad Peller ret = wl12xx_cmd_set_default_wep_key(wl, id, 50a8ab39a4b588e8523be2fa75671bdc9612d3467aEliad Peller wlvif->ap.bcast_hlid); 517f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov else 52154da67c7da14ffd8da292394f8cbc81cc5ea4e3Eliad Peller ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid); 537f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 547f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov if (ret < 0) 557f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov return ret; 567f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 577f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id); 587f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov return 0; 597f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov} 607f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 6125eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yarivstatic int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb) 62f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 6325eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv int id; 6425eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv 6572b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov id = find_first_zero_bit(wl->tx_frames_map, wl->num_tx_desc); 6672b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov if (id >= wl->num_tx_desc) 6725eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv return -EBUSY; 6825eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv 6925eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv __set_bit(id, wl->tx_frames_map); 7025eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames[id] = skb; 7125eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames_cnt++; 7225eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv return id; 7325eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv} 74f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 75872b345fbaef290f890d0bbd34b78ab50269980fArik Nemtsovvoid wl1271_free_tx_id(struct wl1271 *wl, int id) 7625eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv{ 7725eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv if (__test_and_clear_bit(id, wl->tx_frames_map)) { 7872b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov if (unlikely(wl->tx_frames_cnt == wl->num_tx_desc)) 79ef2e3004855e90d2919105e4a91d7df6ab9845a9Ido Yariv clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 80ef2e3004855e90d2919105e4a91d7df6ab9845a9Ido Yariv 8125eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames[id] = NULL; 8225eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl->tx_frames_cnt--; 8325eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv } 84f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 85872b345fbaef290f890d0bbd34b78ab50269980fArik NemtsovEXPORT_SYMBOL(wl1271_free_tx_id); 86f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 8799a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsovstatic void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl, 8899a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov struct sk_buff *skb) 8999a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov{ 9099a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov struct ieee80211_hdr *hdr; 9199a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov 9299a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov /* 9399a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov * add the station to the known list before transmitting the 9499a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov * authentication response. this way it won't get de-authed by FW 9599a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov * when transmitting too soon. 9699a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov */ 9799a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov hdr = (struct ieee80211_hdr *)(skb->data + 9899a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov sizeof(struct wl1271_tx_hw_descr)); 9999a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov if (ieee80211_is_auth(hdr->frame_control)) 10099a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov wl1271_acx_set_inconnection_sta(wl, hdr->addr1); 10199a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov} 10299a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov 103c7ffb902cca655e4d6bdda4156407008573bb214Eliad Pellerstatic void wl1271_tx_regulate_link(struct wl1271 *wl, 104c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller struct wl12xx_vif *wlvif, 105c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller u8 hlid) 106b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov{ 1079a1009684df5295883ba2eb85066a23ed3c3f6a6Arik Nemtsov bool fw_ps, single_link; 1089b17f1b371c5aa5179b3e5392bc22132a3371da4Arik Nemtsov u8 tx_pkts; 109b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 110c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller if (WARN_ON(!test_bit(hlid, wlvif->links_map))) 111b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov return; 112b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 113b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 1149b17f1b371c5aa5179b3e5392bc22132a3371da4Arik Nemtsov tx_pkts = wl->links[hlid].allocated_pkts; 1159a1009684df5295883ba2eb85066a23ed3c3f6a6Arik Nemtsov single_link = (wl->active_link_count == 1); 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. 122b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov */ 1239a1009684df5295883ba2eb85066a23ed3c3f6a6Arik Nemtsov if (!single_link && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) 1246e8cd3310491b10db20d0f7eaf5713b05fa7b753Eliad Peller wl12xx_ps_link_start(wl, wlvif, hlid, true); 125b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov} 126b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov 127f8e0af6b8732b47c2531a280753d29a4ca2d114bArik Nemtsovbool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb) 128f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller{ 129f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller return wl->dummy_packet == skb; 130f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller} 131872b345fbaef290f890d0bbd34b78ab50269980fArik NemtsovEXPORT_SYMBOL(wl12xx_is_dummy_packet); 132f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 1332b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsovstatic u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1342b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov struct sk_buff *skb, struct ieee80211_sta *sta) 135a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 1362b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov if (sta) { 137a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct wl1271_station *wl_sta; 138a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1392b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov wl_sta = (struct wl1271_station *)sta->drv_priv; 140a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov return wl_sta->hlid; 141a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } else { 142a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct ieee80211_hdr *hdr; 143a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 14453d40d0b863e22b697f8d85e1f95cb6f9d2d95b1Eliad Peller if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) 145f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller return wl->system_hlid; 146f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 147a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov hdr = (struct ieee80211_hdr *)skb->data; 14845b60f7ddd05e38a6835fb93e8dbcc6ef9bf12faEliad Peller if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) 149a8ab39a4b588e8523be2fa75671bdc9612d3467aEliad Peller return wlvif->ap.bcast_hlid; 15045b60f7ddd05e38a6835fb93e8dbcc6ef9bf12faEliad Peller else 15145b60f7ddd05e38a6835fb93e8dbcc6ef9bf12faEliad Peller return wlvif->ap.global_hlid; 152a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 153a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 154a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 155d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Pelleru8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1562b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov struct sk_buff *skb, struct ieee80211_sta *sta) 157f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller{ 158dabf37dba405565ab46f4d1821c781730285b9edEliad Peller struct ieee80211_tx_info *control; 159dabf37dba405565ab46f4d1821c781730285b9edEliad Peller 160536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller if (wlvif->bss_type == BSS_TYPE_AP_BSS) 1612b2b64380785bdcaaa9a123e7e5829acc749c4caArik Nemtsov return wl12xx_tx_get_hlid_ap(wl, wlvif, skb, sta); 162f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 163dabf37dba405565ab46f4d1821c781730285b9edEliad Peller control = IEEE80211_SKB_CB(skb); 164dabf37dba405565ab46f4d1821c781730285b9edEliad Peller if (control->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { 165dabf37dba405565ab46f4d1821c781730285b9edEliad Peller wl1271_debug(DEBUG_TX, "tx offchannel"); 166dabf37dba405565ab46f4d1821c781730285b9edEliad Peller return wlvif->dev_hlid; 167dabf37dba405565ab46f4d1821c781730285b9edEliad Peller } 168dabf37dba405565ab46f4d1821c781730285b9edEliad Peller 1693230f35e09f386ee604f55450dcd26098a3c4bc3Eliad Peller return wlvif->sta.hlid; 170f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller} 171f4df1bd525e027aa1975e00f87a420aec7bef4e0Eliad Peller 172b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsovunsigned int wlcore_calc_packet_alignment(struct wl1271 *wl, 173b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov unsigned int packet_length) 1740da13da767cd568c1fe2a7b5b936e86e521b5ae7Ido Yariv{ 1759fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis if ((wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME) || 1769fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis !(wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN)) 177f83985bb5f8f0f25d44ab7b108a709a52aa1c5e0Arik Nemtsov return ALIGN(packet_length, WL1271_TX_ALIGN_TO); 1789fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis else 1799fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE); 1800da13da767cd568c1fe2a7b5b936e86e521b5ae7Ido Yariv} 181b3b4b4b812018a06221b6d7b88a5540fccae2940Arik NemtsovEXPORT_SYMBOL(wlcore_calc_packet_alignment); 1820da13da767cd568c1fe2a7b5b936e86e521b5ae7Ido Yariv 183a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Pellerstatic int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif, 184536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct sk_buff *skb, u32 extra, u32 buf_offset, 18532bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov u8 hlid, bool is_gem) 186f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 187f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_descr *desc; 188f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; 1895c9417f1656b0f415f4be5a7cd7195ecadd7dd1aJuuso Oikarinen u32 total_blocks; 190742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov int id, ret = -EBUSY, ac; 19132bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov u32 spare_blocks; 192f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 19326a309c7586140afd40628a7031993afbaae0f07Igal Chernobelsky if (buf_offset + total_len > wl->aggr_buf_size) 1946c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv return -EAGAIN; 195a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv 19632bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov spare_blocks = wlcore_hw_get_spare_blocks(wl, is_gem); 19732bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov 198f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* allocate free identifier for the packet */ 19925eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv id = wl1271_alloc_tx_id(wl, skb); 200f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (id < 0) 201f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return id; 202f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 203b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks); 20448a61477bdc04896bd96d259388a0c42a7019943Shahar Levi 205f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (total_blocks <= wl->tx_blocks_available) { 206f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho desc = (struct wl1271_tx_hw_descr *)skb_push( 207f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho skb, total_len - skb->len); 208f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 2094a3b97eea216135cd37e6d3a4a6c551c201a6615Arik Nemtsov wlcore_hw_set_tx_desc_blocks(wl, desc, total_blocks, 2104a3b97eea216135cd37e6d3a4a6c551c201a6615Arik Nemtsov spare_blocks); 211ae77eccf04f8c36769bdba334e1bbcc7bb9d3644Shahar Levi 212f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho desc->id = id; 213f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 214f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl->tx_blocks_available -= total_blocks; 2157bb5d6ce9e6ebb3bb71915cb0224523d3c284b4fArik Nemtsov wl->tx_allocated_blocks += total_blocks; 216f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 21755df5afb13718cda49128fa5985556df91d07765Arik Nemtsov /* If the FW was empty before, arm the Tx watchdog */ 21855df5afb13718cda49128fa5985556df91d07765Arik Nemtsov if (wl->tx_allocated_blocks == total_blocks) 21955df5afb13718cda49128fa5985556df91d07765Arik Nemtsov wl12xx_rearm_tx_watchdog_locked(wl); 22055df5afb13718cda49128fa5985556df91d07765Arik Nemtsov 221742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 222742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov wl->tx_allocated_pkts[ac]++; 223bf54e301671a6ece6c94550294dc7faf14158cd3Arik Nemtsov 2249ebcb232158c737db21e22b7bfdc4fc6d661ea8cArik Nemtsov if (test_bit(hlid, wl->links_map)) 2259b17f1b371c5aa5179b3e5392bc22132a3371da4Arik Nemtsov wl->links[hlid].allocated_pkts++; 22609039f42a24084c10e7761ab28ef22932c62a46fArik Nemtsov 227f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho ret = 0; 228f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 229f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_debug(DEBUG_TX, 230f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho "tx_allocate: size: %d, blocks: %d, id: %d", 231f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho total_len, total_blocks, id); 232781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } else { 23325eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl1271_free_tx_id(wl, id); 234781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } 235f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 236f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return ret; 237f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 238f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 239a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Pellerstatic void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif, 240536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct sk_buff *skb, u32 extra, 241536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller struct ieee80211_tx_info *control, u8 hlid) 242f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 243ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen struct timespec ts; 244f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_descr *desc; 2456f266e912c0733e77f63e9ad245db3c966b75942Arik Nemtsov int ac, rate_idx; 246ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen s64 hosttime; 247cf00f379d82d170712150588accd2ebe316c2226John W. Linville u16 tx_attr = 0; 248f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller __le16 frame_control; 249f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller struct ieee80211_hdr *hdr; 250f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller u8 *frame_start; 251a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller bool is_dummy; 252f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 253f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho desc = (struct wl1271_tx_hw_descr *) skb->data; 254f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller frame_start = (u8 *)(desc + 1); 255f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller hdr = (struct ieee80211_hdr *)(frame_start + extra); 256f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller frame_control = hdr->frame_control; 257f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 2581e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen /* relocate space for security header */ 2591e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen if (extra) { 260f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller int hdrlen = ieee80211_hdrlen(frame_control); 261f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller memmove(frame_start, hdr, hdrlen); 2622fc28de5989e1c40fee4e92e2a8f3bdd47b1b34aArik Nemtsov skb_set_network_header(skb, skb_network_offset(skb) + extra); 2631e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen } 2641e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen 265f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* configure packet life time */ 266ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen getnstimeofday(&ts); 267ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen hosttime = (timespec_to_ns(&ts) >> 10); 268ac5e1e39c1eeaaff7e6f03bf7cf7a444b42fbc23Juuso Oikarinen desc->start_time = cpu_to_le32(hosttime - wl->time_offset); 269c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov 270a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller is_dummy = wl12xx_is_dummy_packet(wl, skb); 2710f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS) 272c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); 273c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov else 274c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU); 275f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 276db674d249c1fa20fd6731048f41646b3a2e8bdf5Eliad Peller /* queue */ 277c6999d831ab9ae5e368b20f3bc11b0ca9c17a7ecKalle Valo ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 278db674d249c1fa20fd6731048f41646b3a2e8bdf5Eliad Peller desc->tid = skb->priority; 279c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov 280a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller if (is_dummy) { 281ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi /* 282ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * FW expects the dummy packet to have an invalid session id - 283ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * any session id that is different than the one set in the join 284ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi */ 28598b8625301e55bd3e4340f704edc378e4707e577Eliad Peller tx_attr = (SESSION_COUNTER_INVALID << 286ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi TX_HW_ATTR_OFST_SESSION_COUNTER) & 287ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi TX_HW_ATTR_SESSION_COUNTER; 288ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi 289ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ; 2900f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller } else if (wlvif) { 2913ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov u8 session_id = wl->session_ids[hlid]; 2923ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov 2933ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_AP_ZERO_SESSION_ID) && 2943ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov (wlvif->bss_type == BSS_TYPE_AP_BSS)) 2953ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov session_id = 0; 2963ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov 297ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi /* configure the tx attributes */ 2983ea186d137f79da5e6af283e5803715da1eb6259Arik Nemtsov tx_attr = session_id << TX_HW_ATTR_OFST_SESSION_COUNTER; 299ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 300ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi 30179b122dc51797b650201f21360481a0450e9b7e4Eliad Peller desc->hlid = hlid; 3020f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller if (is_dummy || !wlvif) 303a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller rate_idx = 0; 304a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller else if (wlvif->bss_type != BSS_TYPE_AP_BSS) { 3058f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira /* 3064340d1cf5f1a967074f5dabec09a06fc0ae52ac7Eliad Peller * if the packets are data packets 3078f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira * send them with AP rate policies (EAPOLs are an exception), 3088f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira * otherwise use default basic rates 3098f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira */ 310bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky if (skb->protocol == cpu_to_be16(ETH_P_PAE)) 3118f1a8684a56b3640510c0610b5635f5a4fe366fdEyal Shapira rate_idx = wlvif->sta.basic_rate_idx; 312bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky else if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE) 313bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky rate_idx = wlvif->sta.p2p_rate_idx; 3144340d1cf5f1a967074f5dabec09a06fc0ae52ac7Eliad Peller else if (ieee80211_is_data(frame_control)) 315e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->sta.ap_rate_idx; 316c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov else 317e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->sta.basic_rate_idx; 318c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov } else { 319a8ab39a4b588e8523be2fa75671bdc9612d3467aEliad Peller if (hlid == wlvif->ap.global_hlid) 320e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->ap.mgmt_rate_idx; 321bed483f7b4c71d557777ee30d8dc46cbd5967fa6Igal Chernobelsky else if (hlid == wlvif->ap.bcast_hlid || 322c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov skb->protocol == cpu_to_be16(ETH_P_PAE) || 323c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov !ieee80211_is_data(frame_control)) 324c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov /* 325c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov * send non-data, bcast and EAPOLs using the 326c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov * min basic rate 327c3e06fc03b64c626e150c33b897ddd728c30a316Arik Nemtsov */ 328e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->ap.bcast_rate_idx; 329e51ae9be2e313b63a43f1f93578d9a71d38a77eaArik Nemtsov else 330e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller rate_idx = wlvif->ap.ucast_rate_idx[ac]; 331c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov } 332c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov 333c6c8a65de6d3aa8daa93beeac390f49a21d0be36Arik Nemtsov tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY; 334d0f63b202146f3281800ee44823740c8bbf38f11Luciano Coelho 335f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller /* for WEP shared auth - no fw encryption is needed */ 336f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller if (ieee80211_is_auth(frame_control) && 337f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller ieee80211_has_protected(frame_control)) 338f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller tx_attr |= TX_HW_ATTR_HOST_ENCRYPT; 339f4f57943f265d80fe5f0fedf6964f8056e753cf3Eliad Peller 340d0f63b202146f3281800ee44823740c8bbf38f11Luciano Coelho desc->tx_attr = cpu_to_le16(tx_attr); 3416f266e912c0733e77f63e9ad245db3c966b75942Arik Nemtsov 3422fc28de5989e1c40fee4e92e2a8f3bdd47b1b34aArik Nemtsov wlcore_hw_set_tx_desc_csum(wl, desc, skb); 3436f266e912c0733e77f63e9ad245db3c966b75942Arik Nemtsov wlcore_hw_set_tx_desc_data_len(wl, desc, skb); 344f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 345f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 346f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho/* caller must hold wl->mutex */ 347a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Pellerstatic int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif, 348930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov struct sk_buff *skb, u32 buf_offset, u8 hlid) 349f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 350f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct ieee80211_tx_info *info; 351f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u32 extra = 0; 352f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho int ret = 0; 353a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv u32 total_len; 354536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller bool is_dummy; 35532bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov bool is_gem = false; 356f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 3577a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (!skb) { 3587a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira wl1271_error("discarding null skb"); 359f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return -EINVAL; 3607a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira } 361f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 362930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov if (hlid == WL12XX_INVALID_LINK_ID) { 363930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_error("invalid hlid. dropping skb 0x%p", skb); 364930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov return -EINVAL; 365930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov } 366930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov 367f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho info = IEEE80211_SKB_CB(skb); 368f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 369536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller is_dummy = wl12xx_is_dummy_packet(wl, skb); 370536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller 3712c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) && 3722c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov info->control.hw_key && 37397359d1235eaf634fe706c9faa6e40181cc95fb8Johannes Berg info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) 3745ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller extra = WL1271_EXTRA_SPACE_TKIP; 375f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 376f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (info->control.hw_key) { 3777f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov bool is_wep; 3787f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov u8 idx = info->control.hw_key->hw_key_idx; 3797f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov u32 cipher = info->control.hw_key->cipher; 3807f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov 3817f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || 3827f179b468963564aa3faa5729fb3153c08b3d7c1Arik Nemtsov (cipher == WLAN_CIPHER_SUITE_WEP104); 383f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 384f75c753f3c77b758fa5ace90c15b2ea3b7a3d46dEliad Peller if (unlikely(is_wep && wlvif->default_key != idx)) { 385536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller ret = wl1271_set_default_wep_key(wl, wlvif, idx); 386f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (ret < 0) 387f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return ret; 388f75c753f3c77b758fa5ace90c15b2ea3b7a3d46dEliad Peller wlvif->default_key = idx; 389f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 39032bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov 39132bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov is_gem = (cipher == WL1271_CIPHER_SUITE_GEM); 392f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 39309039f42a24084c10e7761ab28ef22932c62a46fArik Nemtsov 39432bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid, 39532bb2c03f990d015c0fec67e9134ea8625aaf784Arik Nemtsov is_gem); 396f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho if (ret < 0) 397f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return ret; 398f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 399a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid); 400fae2fd767e9d380ed0d05e4a5d6b1673e2c2d3dfArik Nemtsov 4010f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) { 40299a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov wl1271_tx_ap_update_inconnection_sta(wl, skb); 403c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller wl1271_tx_regulate_link(wl, wlvif, hlid); 404b622d992c21a85ce590afe2c18977ed28b457e0eArik Nemtsov } 40599a2775d02a7accf4cc661a65c76fd7b379d1c7aArik Nemtsov 406a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv /* 40748a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * The length of each packet is stored in terms of 40848a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * words. Thus, we must pad the skb data to make sure its 40948a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * length is aligned. The number of padding bytes is computed 41048a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * and set in wl1271_tx_fill_hdr. 41148a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * In special cases, we want to align to a specific block size 41248a61477bdc04896bd96d259388a0c42a7019943Shahar Levi * (eg. for wl128x with SDIO we align to 256). 413a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv */ 414b3b4b4b812018a06221b6d7b88a5540fccae2940Arik Nemtsov total_len = wlcore_calc_packet_alignment(wl, skb->len); 41548a61477bdc04896bd96d259388a0c42a7019943Shahar Levi 416a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len); 417a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); 418f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 419990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv /* Revert side effects in the dummy packet skb, so it can be reused */ 420536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller if (is_dummy) 421990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 422990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv 423a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv return total_len; 424f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 425f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 426af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Pelleru32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set, 427af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller enum ieee80211_band rate_band) 428830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen{ 429830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen struct ieee80211_supported_band *band; 430830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen u32 enabled_rates = 0; 431830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen int bit; 432830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen 433af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller band = wl->hw->wiphy->bands[rate_band]; 434830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen for (bit = 0; bit < band->n_bitrates; bit++) { 435830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen if (rate_set & 0x1) 436830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen enabled_rates |= band->bitrates[bit].hw_value; 437830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen rate_set >>= 1; 438830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen } 439830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen 440b3a47ee0ec07b16f68c38052e8cd1b5cb417bdcaArik Nemtsov /* MCS rates indication are on bits 16 - 31 */ 44118357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates; 44218357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi 443b3a47ee0ec07b16f68c38052e8cd1b5cb417bdcaArik Nemtsov for (bit = 0; bit < 16; bit++) { 44418357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi if (rate_set & 0x1) 44518357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit); 44618357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi rate_set >>= 1; 44718357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi } 44818357850b694ba3fa29363c7d86ccd8783f4a065Shahar Levi 449830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen return enabled_rates; 450830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen} 451830fb67b8e37fb03cf703b4e1217fe30ce32d579Juuso Oikarinen 452a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsovvoid wl1271_handle_tx_low_watermark(struct wl1271 *wl) 4532fe33e8cff354a3f320549544bffebbbab680145Ido Yariv{ 454708bb3cf58a9bc90f3171ba64f30601f690e5aaaArik Nemtsov int i; 4551c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov struct wl12xx_vif *wlvif; 4562fe33e8cff354a3f320549544bffebbbab680145Ido Yariv 4571c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wl12xx_for_each_wlvif(wl, wlvif) { 4581c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 4591c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov if (wlcore_is_queue_stopped_by_reason(wl, wlvif, i, 4601c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WLCORE_QUEUE_STOP_REASON_WATERMARK) && 4611c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wlvif->tx_queue_count[i] <= 4621c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WL1271_TX_QUEUE_LOW_WATERMARK) 4631c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* firmware buffer has space, restart queues */ 4641c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wlcore_wake_queue(wl, wlvif, i, 4651c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WLCORE_QUEUE_STOP_REASON_WATERMARK); 466708bb3cf58a9bc90f3171ba64f30601f690e5aaaArik Nemtsov } 4672fe33e8cff354a3f320549544bffebbbab680145Ido Yariv } 4682fe33e8cff354a3f320549544bffebbbab680145Ido Yariv} 4692fe33e8cff354a3f320549544bffebbbab680145Ido Yariv 4700e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic int wlcore_select_ac(struct wl1271 *wl) 471742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov{ 472742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov int i, q = -1, ac; 473742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov u32 min_pkts = 0xffffffff; 474742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 475742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov /* 476742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * Find a non-empty ac where: 477742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * 1. There are packets to transmit 478742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * 2. The FW has the least allocated blocks 479742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * 480742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov * We prioritize the ACs according to VO>VI>BE>BK 481742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov */ 482742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 483742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov ac = wl1271_tx_get_queue(i); 4840e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (wl->tx_queue_count[ac] && 4850e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->tx_allocated_pkts[ac] < min_pkts) { 486742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov q = ac; 487742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov min_pkts = wl->tx_allocated_pkts[q]; 488742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov } 489742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov } 490742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 4910e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov return q; 492742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov} 493742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 4940e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic struct sk_buff *wlcore_lnk_dequeue(struct wl1271 *wl, 4950e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl1271_link *lnk, u8 q) 4966742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen{ 497d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller struct sk_buff *skb; 4986742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen unsigned long flags; 4996742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 5000e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = skb_dequeue(&lnk->tx_queue[q]); 5016742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen if (skb) { 5026742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_lock_irqsave(&wl->wl_lock, flags); 5036246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov WARN_ON_ONCE(wl->tx_queue_count[q] <= 0); 504f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[q]--; 5058591d42452f16b1888419da4456142864b08ef9eArik Nemtsov if (lnk->wlvif) { 5068591d42452f16b1888419da4456142864b08ef9eArik Nemtsov WARN_ON_ONCE(lnk->wlvif->tx_queue_count[q] <= 0); 5078591d42452f16b1888419da4456142864b08ef9eArik Nemtsov lnk->wlvif->tx_queue_count[q]--; 5088591d42452f16b1888419da4456142864b08ef9eArik Nemtsov } 5096742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_unlock_irqrestore(&wl->wl_lock, flags); 5106742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen } 5116742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 5126742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen return skb; 5136742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen} 5146742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 5150e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic struct sk_buff *wlcore_lnk_dequeue_high_prio(struct wl1271 *wl, 5160e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 hlid, u8 ac, 5170e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 *low_prio_hlid) 5180e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov{ 5190e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl1271_link *lnk = &wl->links[hlid]; 5200e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 521f1626fd8983a5bc68ce2879865cce297eb96c0b4Arik Nemtsov if (!wlcore_hw_lnk_high_prio(wl, hlid, lnk)) { 5220e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (*low_prio_hlid == WL12XX_INVALID_LINK_ID && 523f1626fd8983a5bc68ce2879865cce297eb96c0b4Arik Nemtsov !skb_queue_empty(&lnk->tx_queue[ac]) && 524f1626fd8983a5bc68ce2879865cce297eb96c0b4Arik Nemtsov wlcore_hw_lnk_low_prio(wl, hlid, lnk)) 5250e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* we found the first non-empty low priority queue */ 5260e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov *low_prio_hlid = hlid; 5270e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5280e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov return NULL; 5290e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov } 5300e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5310e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov return wlcore_lnk_dequeue(wl, lnk, ac); 5320e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov} 5330e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5340e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovstatic struct sk_buff *wlcore_vif_dequeue_high_prio(struct wl1271 *wl, 5350e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl12xx_vif *wlvif, 5360e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 ac, u8 *hlid, 5370e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 *low_prio_hlid) 538a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 539a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct sk_buff *skb = NULL; 540a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov int i, h, start_hlid; 541a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 542a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov /* start from the link after the last one */ 5434438aca9e16901d8d32a025ca27ad8284a117e09Eliad Peller start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS; 544a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 545a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov /* dequeue according to AC, round robin on each link */ 546c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller for (i = 0; i < WL12XX_MAX_LINKS; i++) { 547c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller h = (start_hlid + i) % WL12XX_MAX_LINKS; 548a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 549742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov /* only consider connected stations */ 550c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller if (!test_bit(h, wlvif->links_map)) 551742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov continue; 552742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 5530e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_lnk_dequeue_high_prio(wl, h, ac, 5540e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov low_prio_hlid); 555d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller if (!skb) 556742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov continue; 557742246f8bc16c3a1a556c68ca2fabca162d14c24Arik Nemtsov 558d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller wlvif->last_tx_hlid = h; 559d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller break; 560a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 561a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 562d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller if (!skb) 5634438aca9e16901d8d32a025ca27ad8284a117e09Eliad Peller wlvif->last_tx_hlid = 0; 564a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 565930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov *hlid = wlvif->last_tx_hlid; 566a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov return skb; 567a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 568a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 569930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsovstatic struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl, u8 *hlid) 570a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 571990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv unsigned long flags; 572e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller struct wl12xx_vif *wlvif = wl->last_wlvif; 573990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv struct sk_buff *skb = NULL; 5740e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov int ac; 5750e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov u8 low_prio_hlid = WL12XX_INVALID_LINK_ID; 5760e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5770e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov ac = wlcore_select_ac(wl); 5780e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (ac < 0) 5790e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov goto out; 580990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv 58149c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov /* continue from last wlvif (round robin) */ 582e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller if (wlvif) { 583e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller wl12xx_for_each_wlvif_continue(wl, wlvif) { 5840e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!wlvif->tx_queue_count[ac]) 5850e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov continue; 5860e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5870e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_vif_dequeue_high_prio(wl, wlvif, ac, hlid, 5880e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov &low_prio_hlid); 5890e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!skb) 5900e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov continue; 5910e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 5920e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->last_wlvif = wlvif; 5930e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov break; 594e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 595e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 596e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller 59749c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov /* dequeue from the system HLID before the restarting wlvif list */ 598930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov if (!skb) { 5990e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_lnk_dequeue_high_prio(wl, wl->system_hlid, 6000e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov ac, &low_prio_hlid); 6010e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (skb) { 6020e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov *hlid = wl->system_hlid; 6030e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->last_wlvif = NULL; 6040e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov } 605930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov } 60649c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov 6070e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* Do a new pass over the wlvif list. But no need to continue 6080e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov * after last_wlvif. The previous pass should have found it. */ 609e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller if (!skb) { 610e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller wl12xx_for_each_wlvif(wl, wlvif) { 6110e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!wlvif->tx_queue_count[ac]) 6120e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov goto next; 6130e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6140e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_vif_dequeue_high_prio(wl, wlvif, ac, hlid, 6150e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov &low_prio_hlid); 616e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller if (skb) { 617e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller wl->last_wlvif = wlvif; 618e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller break; 619e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 62049c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov 6210e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovnext: 62249c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov if (wlvif == wl->last_wlvif) 62349c9cd26445aa8bc8348c384c943b758c57c47a9Arik Nemtsov break; 624e4120df982c2051f3cfc02f6278798c5166a72f8Eliad Peller } 625a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller } 626a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller 6270e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* no high priority skbs found - but maybe a low priority one? */ 6280e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (!skb && low_prio_hlid != WL12XX_INVALID_LINK_ID) { 6290e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov struct wl1271_link *lnk = &wl->links[low_prio_hlid]; 6300e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov skb = wlcore_lnk_dequeue(wl, lnk, ac); 6310e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6320e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov WARN_ON(!skb); /* we checked this before */ 6330e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov *hlid = low_prio_hlid; 6340e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6350e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov /* ensure proper round robin in the vif/link levels */ 6360e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov wl->last_wlvif = lnk->wlvif; 6370e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov if (lnk->wlvif) 6380e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov lnk->wlvif->last_tx_hlid = low_prio_hlid; 6390e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 6400e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov } 6410e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsov 642990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (!skb && 643990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) { 644f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov int q; 645f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov 646990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv skb = wl->dummy_packet; 647930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov *hlid = wl->system_hlid; 648f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 649990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv spin_lock_irqsave(&wl->wl_lock, flags); 6506246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov WARN_ON_ONCE(wl->tx_queue_count[q] <= 0); 651f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[q]--; 652990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv spin_unlock_irqrestore(&wl->wl_lock, flags); 653990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv } 654990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv 6550e81047996fdde7fc9e8a1c01d532df1f53586faArik Nemtsovout: 656990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv return skb; 657a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 658a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 659d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Pellerstatic void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif, 660930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov struct sk_buff *skb, u8 hlid) 6616742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen{ 6626742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen unsigned long flags; 6636742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 6646742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 665990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (wl12xx_is_dummy_packet(wl, skb)) { 666990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); 667d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller } else { 668a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov skb_queue_head(&wl->links[hlid].tx_queue[q], skb); 669a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 670a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov /* make sure we dequeue the same packet next time */ 6714438aca9e16901d8d32a025ca27ad8284a117e09Eliad Peller wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) % 672d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller WL12XX_MAX_LINKS; 673a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 674a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 6756742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_lock_irqsave(&wl->wl_lock, flags); 676f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[q]++; 6778591d42452f16b1888419da4456142864b08ef9eArik Nemtsov if (wlvif) 6788591d42452f16b1888419da4456142864b08ef9eArik Nemtsov wlvif->tx_queue_count[q]++; 6796742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen spin_unlock_irqrestore(&wl->wl_lock, flags); 6806742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen} 6816742f554db14da94172da9eb1875a1aa944a827fJuuso Oikarinen 68277ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Pellerstatic bool wl1271_tx_is_data_present(struct sk_buff *skb) 68377ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller{ 68477ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 68577ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller 68677ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller return ieee80211_is_data_present(hdr->frame_control); 68777ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller} 68877ddaa108f727b5ef3be004b952d2c3d3ffc48e5Eliad Peller 6899eb599e9c62dcfd4efece1936c385381b366b684Eliad Pellervoid wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids) 6909eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller{ 6919eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller struct wl12xx_vif *wlvif; 6929eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller u32 timeout; 6939eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller u8 hlid; 6949eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 6959eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (!wl->conf.rx_streaming.interval) 6969eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller return; 6979eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 6989eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (!wl->conf.rx_streaming.always && 6999eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)) 7009eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller return; 7019eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7029eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller timeout = wl->conf.rx_streaming.duration; 7039eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller wl12xx_for_each_wlvif_sta(wl, wlvif) { 7049eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller bool found = false; 7059eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) { 7069eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (test_bit(hlid, wlvif->links_map)) { 7079eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller found = true; 7089eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller break; 7099eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 7109eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 7119eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7129eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (!found) 7139eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller continue; 7149eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7159eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller /* enable rx streaming */ 7160744bdb60b51dce54553d5af9a6133f1fe419032Eliad Peller if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) 7179eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller ieee80211_queue_work(wl->hw, 7189eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller &wlvif->rx_streaming_enable_work); 7199eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7209eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller mod_timer(&wlvif->rx_streaming_timer, 7219eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller jiffies + msecs_to_jiffies(timeout)); 7229eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 7239eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller} 7249eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 7257a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira/* 7267a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * Returns failure values only in case of failed bus ops within this function. 7277a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * wl1271_prepare_tx_frame retvals won't be returned in order to avoid 7287a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * triggering recovery by higher layers when not necessary. 7297a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * In case a FW command fails within wl1271_prepare_tx_frame fails a recovery 7307a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * will be queued in wl1271_cmd_send. -EAGAIN/-EBUSY from prepare_tx_frame 7317a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * can occur and are legitimate so don't propagate. -EINVAL will emit a WARNING 7327a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * within prepare_tx_frame code but there's nothing we should do about those 7337a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira * as well. 7347a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira */ 735eb96f841b9563ba34969be25615548635728faf5Ido Yarivint wlcore_tx_work_locked(struct wl1271 *wl) 736f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 737a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller struct wl12xx_vif *wlvif; 738f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct sk_buff *skb; 7399eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller struct wl1271_tx_hw_descr *desc; 7409fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis u32 buf_offset = 0, last_len = 0; 7416c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv bool sent_packets = false; 7429eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0}; 743eb96f841b9563ba34969be25615548635728faf5Ido Yariv int ret = 0; 7447a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira int bus_ret = 0; 745930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov u8 hlid; 746f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 7474cc533830b7e6b309e8b73196c410951fc2bed91Ido Yariv if (unlikely(wl->state != WLCORE_STATE_ON)) 7487a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira return 0; 749f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 750930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov while ((skb = wl1271_skb_dequeue(wl, &hlid))) { 7510f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 7529eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller bool has_data = false; 7539eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller 754a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller wlvif = NULL; 755f4d02007cdd56c59bdb9362c699875cb2d02c0feArik Nemtsov if (!wl12xx_is_dummy_packet(wl, skb)) 7560f1680147ce2509383e053fa843020e0e9f3c6ceEliad Peller wlvif = wl12xx_vif_to_data(info->control.vif); 757930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov else 758930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov hlid = wl->system_hlid; 759a32d0cdfcb7e5d41f210e13cbc78dc86a5a85a08Eliad Peller 7609eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller has_data = wlvif && wl1271_tx_is_data_present(skb); 761930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset, 762930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov hlid); 7636c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv if (ret == -EAGAIN) { 764a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv /* 7656c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv * Aggregation buffer is full. 7666c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv * Flush buffer and try again. 7676c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv */ 768930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_skb_queue_head(wl, wlvif, skb, hlid); 7699fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis 7709fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset, 7719fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis last_len); 7727a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira bus_ret = wlcore_write_data(wl, REG_SLV_MEM_DATA, 7737a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira wl->aggr_buf, buf_offset, true); 7747a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (bus_ret < 0) 775eb96f841b9563ba34969be25615548635728faf5Ido Yariv goto out; 776eb96f841b9563ba34969be25615548635728faf5Ido Yariv 7776c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv sent_packets = true; 7786c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv buf_offset = 0; 7796c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv continue; 7806c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv } else if (ret == -EBUSY) { 7816c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv /* 7826c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv * Firmware buffer is full. 783a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv * Queue back last skb, and stop aggregating. 784a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv */ 785930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_skb_queue_head(wl, wlvif, skb, hlid); 786a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv /* No work left, avoid scheduling redundant tx work */ 787a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 788ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen goto out_ack; 789f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } else if (ret < 0) { 7905de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller if (wl12xx_is_dummy_packet(wl, skb)) 7915de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller /* 7925de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller * fw still expects dummy packet, 7935de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller * so re-enqueue it 7945de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller */ 795930e1915e73dd12c5e3a0e6a5a4349bdb9ab0ab7Arik Nemtsov wl1271_skb_queue_head(wl, wlvif, skb, hlid); 7965de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller else 7975de8eef4fdd2044f6981ebf62330720bcdba8ee3Eliad Peller ieee80211_free_txskb(wl->hw, skb); 798ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen goto out_ack; 799f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 8009fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis last_len = ret; 8019fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis buf_offset += last_len; 802a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv wl->tx_packets_count++; 8039eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller if (has_data) { 8049eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller desc = (struct wl1271_tx_hw_descr *) skb->data; 8059eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller __set_bit(desc->hlid, active_hlids); 8069eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller } 807f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 808f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 809ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinenout_ack: 810a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv if (buf_offset) { 8119fccc82e19db0d63741cd6c3d2a8829fc8854406Ido Reis buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset, last_len); 8127a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira bus_ret = wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf, 8137a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira buf_offset, true); 8147a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (bus_ret < 0) 815eb96f841b9563ba34969be25615548635728faf5Ido Yariv goto out; 816eb96f841b9563ba34969be25615548635728faf5Ido Yariv 8176c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv sent_packets = true; 8186c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv } 8196c6e669ed6282788d6045397ce0f201edc400d9dIdo Yariv if (sent_packets) { 820606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv /* 821606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv * Interrupt the firmware with the new packets. This is only 822606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv * required for older hardware revisions 823606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv */ 824b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv if (wl->quirks & WLCORE_QUIRK_END_OF_TRANSACTION) { 8257a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira bus_ret = wlcore_write32(wl, WL12XX_HOST_WR_ACCESS, 826b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv wl->tx_packets_count); 8277a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira if (bus_ret < 0) 828b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv goto out; 829b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv } 830606ea9fa0b2c01ffafb6beae92ea8e2b1473520bIdo Yariv 831a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov wl1271_handle_tx_low_watermark(wl); 832a19606b4333ff34e9b2863f37c20fe86b42be14cIdo Yariv } 8339eb599e9c62dcfd4efece1936c385381b366b684Eliad Peller wl12xx_rearm_rx_streaming(wl, active_hlids); 834eb96f841b9563ba34969be25615548635728faf5Ido Yariv 835eb96f841b9563ba34969be25615548635728faf5Ido Yarivout: 8367a50bdfb81a6bff96100cd2a2c95f8b3cf05bc0cEyal Shapira return bus_ret; 837a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv} 838f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 839a522550a283de31c7cfc30c7a129ce584e38c582Ido Yarivvoid wl1271_tx_work(struct work_struct *work) 840a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv{ 841a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv struct wl1271 *wl = container_of(work, struct wl1271, tx_work); 842c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller int ret; 843a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv 844a522550a283de31c7cfc30c7a129ce584e38c582Ido Yariv mutex_lock(&wl->mutex); 845c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller ret = wl1271_ps_elp_wakeup(wl); 846c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller if (ret < 0) 847c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller goto out; 848c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller 849eb96f841b9563ba34969be25615548635728faf5Ido Yariv ret = wlcore_tx_work_locked(wl); 850eb96f841b9563ba34969be25615548635728faf5Ido Yariv if (ret < 0) { 851eb96f841b9563ba34969be25615548635728faf5Ido Yariv wl12xx_queue_recovery_work(wl); 852eb96f841b9563ba34969be25615548635728faf5Ido Yariv goto out; 853eb96f841b9563ba34969be25615548635728faf5Ido Yariv } 854c1b193eb6557279d037ab18c00ab628c6c78847fEliad Peller 855c75bbcdb200e2815c855e42a4685d170858af306Eliad Peller wl1271_ps_elp_sleep(wl); 856c1b193eb6557279d037ab18c00ab628c6c78847fEliad Pellerout: 857f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho mutex_unlock(&wl->mutex); 858f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 859f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 860d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchsstatic u8 wl1271_tx_get_rate_flags(u8 rate_class_index) 861d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs{ 862defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs u8 flags = 0; 863defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs 86443a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov /* 86543a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * TODO: use wl12xx constants when this code is moved to wl12xx, as 86643a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * only it uses Tx-completion. 86743a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov */ 86843a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov if (rate_class_index <= 8) 869defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs flags |= IEEE80211_TX_RC_MCS; 87043a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov 87143a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov /* 87243a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * TODO: use wl12xx constants when this code is moved to wl12xx, as 87343a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov * only it uses Tx-completion. 87443a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov */ 87543a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov if (rate_class_index == 0) 876defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs flags |= IEEE80211_TX_RC_SHORT_GI; 87743a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov 878defe02c720d54fc9bda3e5e625be70adac347a61Pontus Fuchs return flags; 879d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs} 880d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs 881f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelhostatic void wl1271_tx_complete_packet(struct wl1271 *wl, 882f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_res_descr *result) 883f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 884f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct ieee80211_tx_info *info; 88548e93e402ad19f570bae323b07911bdf6562af8eEliad Peller struct ieee80211_vif *vif; 88648e93e402ad19f570bae323b07911bdf6562af8eEliad Peller struct wl12xx_vif *wlvif; 887f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct sk_buff *skb; 888f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho int id = result->id; 88931627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen int rate = -1; 890d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs u8 rate_flags = 0; 89131627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen u8 retries = 0; 892f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 893f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* check for id legality */ 89472b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) { 895f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_warning("TX result illegal id: %d", id); 896f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho return; 897f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 898f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 899f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho skb = wl->tx_frames[id]; 900f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho info = IEEE80211_SKB_CB(skb); 901f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 902990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (wl12xx_is_dummy_packet(wl, skb)) { 903ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi wl1271_free_tx_id(wl, id); 904ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi return; 905ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 906ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi 90748e93e402ad19f570bae323b07911bdf6562af8eEliad Peller /* info->control is valid as long as we don't update info->status */ 90848e93e402ad19f570bae323b07911bdf6562af8eEliad Peller vif = info->control.vif; 90948e93e402ad19f570bae323b07911bdf6562af8eEliad Peller wlvif = wl12xx_vif_to_data(vif); 91048e93e402ad19f570bae323b07911bdf6562af8eEliad Peller 91131627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen /* update the TX status info */ 91231627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen if (result->status == TX_SUCCESS) { 91331627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 914f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho info->flags |= IEEE80211_TX_STAT_ACK; 91543a8bc5a53c78b69b99824c9f38c333cea024c8aArik Nemtsov rate = wlcore_rate_to_idx(wl, result->rate_class_index, 9161b92f15ee0e0f06222d4fd36dc36960d217243b3Eliad Peller wlvif->band); 917d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs rate_flags = wl1271_tx_get_rate_flags(result->rate_class_index); 91831627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen retries = result->ack_failures; 91931627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen } else if (result->status == TX_RETRY_EXCEEDED) { 92031627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen wl->stats.excessive_retries++; 92131627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen retries = result->ack_failures; 922f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 923f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 92431627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen info->status.rates[0].idx = rate; 92531627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen info->status.rates[0].count = retries; 926d2e2d769e3d328ba7cbf08e8ed85e3f817915843Pontus Fuchs info->status.rates[0].flags = rate_flags; 92731627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen info->status.ack_signal = -1; 92831627dc59b4a87c4198b4245a7de1b8ccf4424faJuuso Oikarinen 929f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl->stats.retry_count += result->ack_failures; 930f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 931b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski /* 932b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski * update sequence number only when relevant, i.e. only in 933b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski * sessions of TKIP, AES and GEM (not in open or WEP sessions) 934b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski */ 935b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski if (info->control.hw_key && 936b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP || 937b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP || 938b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) { 939b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski u8 fw_lsb = result->tx_security_sequence_number_lsb; 94048e93e402ad19f570bae323b07911bdf6562af8eEliad Peller u8 cur_lsb = wlvif->tx_security_last_seq_lsb; 941b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski 942b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski /* 943b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski * update security sequence number, taking care of potential 944b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski * wrap-around 945b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski */ 94648e93e402ad19f570bae323b07911bdf6562af8eEliad Peller wlvif->tx_security_seq += (fw_lsb - cur_lsb) & 0xff; 94748e93e402ad19f570bae323b07911bdf6562af8eEliad Peller wlvif->tx_security_last_seq_lsb = fw_lsb; 948b992c68228a3ccdf73ea4f57519e1663839a9cbeOz Krakowski } 949ac4e4ce54eb9cb4963a1d3d91fc65536d882ffb2Juuso Oikarinen 9501e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen /* remove private header from packet */ 9511e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 9521e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen 9531e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen /* remove TKIP header space if present */ 9542c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) && 9552c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov info->control.hw_key && 95697359d1235eaf634fe706c9faa6e40181cc95fb8Johannes Berg info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) { 9571e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 9585ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data, 9595ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller hdrlen); 9605ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller skb_pull(skb, WL1271_EXTRA_SPACE_TKIP); 9611e2b79761d551c545225e1fa6e7d144f7e804898Juuso Oikarinen } 962f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 963f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" 964f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho " status 0x%x", 965f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho result->id, skb, result->ack_failures, 966f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho result->rate_class_index, result->status); 967f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 968f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* return the packet to the stack */ 969a620865edf62ea2d024bbfe62162244473badfcbIdo Yariv skb_queue_tail(&wl->deferred_tx_queue, skb); 97092ef8960aee2f840c6a54c968d40199843f015c0Eliad Peller queue_work(wl->freezable_wq, &wl->netstack_work); 97125eeb9e3876a161e3afcc820c6cb72e13f9b7c7eIdo Yariv wl1271_free_tx_id(wl, result->id); 972f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 973f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 974f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho/* Called upon reception of a TX complete interrupt */ 975045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yarivint wlcore_tx_complete(struct wl1271 *wl) 976f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 9772c208890c6d4e16076c6664137703ec813e8fa6cJoe Perches struct wl1271_acx_mem_map *memmap = wl->target_mem_map; 978ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen u32 count, fw_counter; 979f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u32 i; 980045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv int ret; 981f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 982f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* read the tx results from the chipset */ 983045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv ret = wlcore_read(wl, le32_to_cpu(memmap->tx_result), 984045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv wl->tx_res_if, sizeof(*wl->tx_res_if), false); 985045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv if (ret < 0) 986045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv goto out; 987045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv 988ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); 989ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen 990ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen /* write host counter to chipset (to ack) */ 991b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv ret = wlcore_write32(wl, le32_to_cpu(memmap->tx_result) + 992b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv offsetof(struct wl1271_tx_hw_res_if, 993b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv tx_result_host_counter), fw_counter); 994b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv if (ret < 0) 995b0f0ad39e3d2716fe9ca6e50ce4cda87eb409ee0Ido Yariv goto out; 996ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen 997ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen count = fw_counter - wl->tx_results_count; 99806f7bc7db79fabe6b2ec16eff0f59e4acc21eb72Juuso Oikarinen wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); 999f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1000f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* verify that the result buffer is not getting overrun */ 1001ffb591cd0e32d817bdbd359dead3baa770b999f8Juuso Oikarinen if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) 1002f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_warning("TX result overflow from chipset: %d", count); 1003f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1004f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* process the results */ 1005f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho for (i = 0; i < count; i++) { 1006f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho struct wl1271_tx_hw_res_descr *result; 1007f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; 1008f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1009f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* process the packet */ 1010f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho result = &(wl->tx_res_if->tx_results_queue[offset]); 1011f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl1271_tx_complete_packet(wl, result); 1012f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1013f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho wl->tx_results_count++; 1014f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 1015045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv 1016045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yarivout: 1017045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido Yariv return ret; 1018f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 1019045b9b5f4172b2b21af0b9bf5e6dda51146d51a4Ido YarivEXPORT_SYMBOL(wlcore_tx_complete); 1020f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1021a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsovvoid wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid) 1022a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov{ 1023a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov struct sk_buff *skb; 1024f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov int i; 1025a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov unsigned long flags; 10261d36cd892c130a5a781acb282e083b94127f1c50Arik Nemtsov struct ieee80211_tx_info *info; 1027f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov int total[NUM_TX_QUEUES]; 10288591d42452f16b1888419da4456142864b08ef9eArik Nemtsov struct wl1271_link *lnk = &wl->links[hlid]; 1029a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1030a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 1031f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov total[i] = 0; 10328591d42452f16b1888419da4456142864b08ef9eArik Nemtsov while ((skb = skb_dequeue(&lnk->tx_queue[i]))) { 1033a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb); 103479ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov 103579ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov if (!wl12xx_is_dummy_packet(wl, skb)) { 103679ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov info = IEEE80211_SKB_CB(skb); 103779ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov info->status.rates[0].idx = -1; 103879ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov info->status.rates[0].count = 0; 103979ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov ieee80211_tx_status_ni(wl->hw, skb); 104079ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov } 104179ebec76be4e7c2ebed9fb0b9510d10d599ed63eArik Nemtsov 1042f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov total[i]++; 1043a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 1044a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov } 1045a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1046a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 10478591d42452f16b1888419da4456142864b08ef9eArik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) { 1048f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_queue_count[i] -= total[i]; 10498591d42452f16b1888419da4456142864b08ef9eArik Nemtsov if (lnk->wlvif) 10508591d42452f16b1888419da4456142864b08ef9eArik Nemtsov lnk->wlvif->tx_queue_count[i] -= total[i]; 10518591d42452f16b1888419da4456142864b08ef9eArik Nemtsov } 1052a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 1053a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 1054a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov wl1271_handle_tx_low_watermark(wl); 1055a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov} 1056a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 10577dece1c8e1044287287d44ac183a946333b55fc3Arik Nemtsov/* caller must hold wl->mutex and TX must be stopped */ 1058d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Pellervoid wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1059f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{ 1060f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho int i; 1061f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho 1062f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho /* TX failure */ 1063d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) { 10646c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov if (wlvif->bss_type == BSS_TYPE_AP_BSS) { 10656c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov /* this calls wl12xx_free_link */ 1066c7ffb902cca655e4d6bdda4156407008573bb214Eliad Peller wl1271_free_sta(wl, wlvif, i); 10676c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov } else { 10686c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov u8 hlid = i; 1069d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller wlvif->sta.ba_rx_bitmap = 0; 10706c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov wl12xx_free_link(wl, wlvif, &hlid); 10716c4c45346289ec1c8a6a204e2c81325a4cf96924Arik Nemtsov } 1072f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho } 1073d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller wlvif->last_tx_hlid = 0; 1074d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller 10758591d42452f16b1888419da4456142864b08ef9eArik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) 10768591d42452f16b1888419da4456142864b08ef9eArik Nemtsov wlvif->tx_queue_count[i] = 0; 1077d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller} 1078d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller/* caller must hold wl->mutex and TX must be stopped */ 10796639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsovvoid wl12xx_tx_reset(struct wl1271 *wl) 1080d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller{ 1081d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller int i; 1082d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller struct sk_buff *skb; 1083d6a3cc2ef962ad4392a2401cae513a18a6d35099Eliad Peller struct ieee80211_tx_info *info; 1084a8c0ddb5ba2889e1e11a033ccbadfc600f236a91Arik Nemtsov 10856246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov /* only reset the queues if something bad happened */ 10864c145185175dcca660265d2fcdd4feffc0249f8eVictor Goldenshtein if (wl1271_tx_total_queue_count(wl) != 0) { 10876246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov for (i = 0; i < WL12XX_MAX_LINKS; i++) 10886246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov wl1271_tx_reset_link_queues(wl, i); 10896246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov 10906246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov for (i = 0; i < NUM_TX_QUEUES; i++) 10916246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov wl->tx_queue_count[i] = 0; 10926246ca003f2560e30b9696757efc271284b809f6Arik Nemtsov } 1093f1acea9a9d48174f982e14a7a488b208d39d825fArik Nemtsov 10942fe33e8cff354a3f320549544bffebbbab680145Ido Yariv /* 10952fe33e8cff354a3f320549544bffebbbab680145Ido Yariv * Make sure the driver is at a consistent state, in case this 10962fe33e8cff354a3f320549544bffebbbab680145Ido Yariv * function is called from a context other than interface removal. 10977dece1c8e1044287287d44ac183a946333b55fc3Arik Nemtsov * This call will always wake the TX queues. 10982fe33e8cff354a3f320549544bffebbbab680145Ido Yariv */ 10996639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov wl1271_handle_tx_low_watermark(wl); 11002fe33e8cff354a3f320549544bffebbbab680145Ido Yariv 110172b0624fa5b766133fd0be9099724324b1f0d70eArik Nemtsov for (i = 0; i < wl->num_tx_desc; i++) { 110250e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv if (wl->tx_frames[i] == NULL) 110350e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv continue; 110450e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 110550e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv skb = wl->tx_frames[i]; 110650e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv wl1271_free_tx_id(wl, i); 110750e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); 110850e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 1109990f5de7384f9e5922e4c7c7572cbf4f29a9441eIdo Yariv if (!wl12xx_is_dummy_packet(wl, skb)) { 1110ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi /* 1111ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * Remove private headers before passing the skb to 1112ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi * mac80211 1113ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi */ 1114ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info = IEEE80211_SKB_CB(skb); 1115ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 11162c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) && 11172c0133a437905591cdaa39cf65a3f7188d20a094Arik Nemtsov info->control.hw_key && 1118ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info->control.hw_key->cipher == 1119ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi WLAN_CIPHER_SUITE_TKIP) { 1120ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 11215ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, 1122ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi skb->data, hdrlen); 11235ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller skb_pull(skb, WL1271_EXTRA_SPACE_TKIP); 1124ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 112550e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 1126ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info->status.rates[0].idx = -1; 1127ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi info->status.rates[0].count = 0; 112850e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv 1129c27d3accb6f06b0afedfe472dfe0c8e7d87ff0a6Eliad Peller ieee80211_tx_status_ni(wl->hw, skb); 1130ae47c45fd02fdf88d57adc370e78e7a01e2bfcbcShahar Levi } 113150e9f746f63c9b881f2ca4a35dbdfd34b1a8a215Ido Yariv } 1132781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen} 1133781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 1134781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen#define WL1271_TX_FLUSH_TIMEOUT 500000 1135781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 1136781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen/* caller must *NOT* hold wl->mutex */ 1137781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinenvoid wl1271_tx_flush(struct wl1271 *wl) 1138781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen{ 1139958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov unsigned long timeout, start_time; 114018aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov int i; 1141958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov start_time = jiffies; 1142958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov timeout = start_time + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); 1143781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 11442c38849f4a247673c8203a569444042e32d82410Arik Nemtsov /* only one flush should be in progress, for consistent queue state */ 11452c38849f4a247673c8203a569444042e32d82410Arik Nemtsov mutex_lock(&wl->flush_mutex); 11462c38849f4a247673c8203a569444042e32d82410Arik Nemtsov 1147f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_lock(&wl->mutex); 1148f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov if (wl->tx_frames_cnt == 0 && wl1271_tx_total_queue_count(wl) == 0) { 1149f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_unlock(&wl->mutex); 1150f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov goto out; 1151f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov } 1152f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov 11532c38849f4a247673c8203a569444042e32d82410Arik Nemtsov wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FLUSH); 11542c38849f4a247673c8203a569444042e32d82410Arik Nemtsov 1155781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen while (!time_after(jiffies, timeout)) { 1156958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov wl1271_debug(DEBUG_MAC80211, "flushing tx buffer: %d %d", 1157f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl->tx_frames_cnt, 1158f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov wl1271_tx_total_queue_count(wl)); 1159f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov 1160f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov /* force Tx and give the driver some time to flush data */ 1161f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_unlock(&wl->mutex); 1162f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov if (wl1271_tx_total_queue_count(wl)) 1163f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov wl1271_tx_work(&wl->tx_work); 1164f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov msleep(20); 1165f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_lock(&wl->mutex); 1166f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov 1167f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov if ((wl->tx_frames_cnt == 0) && 1168f1a46384ad568f72c11edbe2a3ec284bf32f2dbdArik Nemtsov (wl1271_tx_total_queue_count(wl) == 0)) { 1169958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov wl1271_debug(DEBUG_MAC80211, "tx flush took %d ms", 1170958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov jiffies_to_msecs(jiffies - start_time)); 1171f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov goto out_wake; 1172781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } 1173781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen } 1174781608c41386b560b501404233fc43d8ef100c71Juuso Oikarinen 1175958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov wl1271_warning("Unable to flush all TX buffers, " 1176958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov "timed out (timeout %d ms", 1177958e303abba61bad165a96e22e138c4763047df2Arik Nemtsov WL1271_TX_FLUSH_TIMEOUT / 1000); 117818aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov 117918aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov /* forcibly flush all Tx buffers on our queues */ 118018aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov for (i = 0; i < WL12XX_MAX_LINKS; i++) 118118aa755b84715f36e2811734f95cb822bcacfd89Arik Nemtsov wl1271_tx_reset_link_queues(wl, i); 11822c38849f4a247673c8203a569444042e32d82410Arik Nemtsov 1183f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsovout_wake: 11842c38849f4a247673c8203a569444042e32d82410Arik Nemtsov wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FLUSH); 1185f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsov mutex_unlock(&wl->mutex); 1186f83e54134a6d38437ddee0fda96692a6b0c33b0eArik Nemtsovout: 11872c38849f4a247673c8203a569444042e32d82410Arik Nemtsov mutex_unlock(&wl->flush_mutex); 1188f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho} 1189a1c597f2b22cdc228de3c58784b00e80b9b53e03Arik NemtsovEXPORT_SYMBOL_GPL(wl1271_tx_flush); 1190e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov 1191af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Pelleru32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set) 1192e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{ 1193af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller if (WARN_ON(!rate_set)) 1194af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller return 0; 1195e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov 1196af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller return BIT(__ffs(rate_set)); 1197e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov} 119878e28062fea51c62280cd17fe6143ed583f83ba0Eliad PellerEXPORT_SYMBOL_GPL(wl1271_tx_min_rate_get); 11996639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12001c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_stop_queue_locked(struct wl1271 *wl, struct wl12xx_vif *wlvif, 12011c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov u8 queue, enum wlcore_queue_stop_reason reason) 12026639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12031c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 12041c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov bool stopped = !!wl->queue_stop_reasons[hwq]; 12056639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12066639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov /* queue should not be stopped for this reason */ 12071c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(test_and_set_bit(reason, &wl->queue_stop_reasons[hwq])); 12086639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12096639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov if (stopped) 12106639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov return; 12116639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12121c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_stop_queue(wl->hw, hwq); 12136639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12146639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12151c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_stop_queue(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 queue, 12166639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov enum wlcore_queue_stop_reason reason) 12176639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12186639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov unsigned long flags; 12196639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12206639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12211c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov wlcore_stop_queue_locked(wl, wlvif, queue, reason); 12226639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12236639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12246639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12251c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_wake_queue(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 queue, 12266639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov enum wlcore_queue_stop_reason reason) 12276639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12286639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov unsigned long flags; 12291c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 12306639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12316639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12326639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12336639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov /* queue should not be clear for this reason */ 12341c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(!test_and_clear_bit(reason, &wl->queue_stop_reasons[hwq])); 12356639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12361c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov if (wl->queue_stop_reasons[hwq]) 12376639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov goto out; 12386639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12391c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_wake_queue(wl->hw, hwq); 12406639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12416639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsovout: 12426639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12436639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12446639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12456639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsovvoid wlcore_stop_queues(struct wl1271 *wl, 12466639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov enum wlcore_queue_stop_reason reason) 12476639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12486639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov int i; 12491c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov unsigned long flags; 12506639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12511c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12526639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12531c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* mark all possible queues as stopped */ 12541c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov for (i = 0; i < WLCORE_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) 12551c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(test_and_set_bit(reason, 12561c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov &wl->queue_stop_reasons[i])); 12576639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12581c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* use the global version to make sure all vifs in mac80211 we don't 12591c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov * know are stopped. 12601c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov */ 12611c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_stop_queues(wl->hw); 12621c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov 12631c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12646639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12656639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12661c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovvoid wlcore_wake_queues(struct wl1271 *wl, 12671c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov enum wlcore_queue_stop_reason reason) 12686639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12696639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov int i; 12706639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov unsigned long flags; 12716639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12726639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_lock_irqsave(&wl->wl_lock, flags); 12736639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12741c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* mark all possible queues as awake */ 12751c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov for (i = 0; i < WLCORE_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) 12761c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov WARN_ON_ONCE(!test_and_clear_bit(reason, 12771c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov &wl->queue_stop_reasons[i])); 12786639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12791c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov /* use the global version to make sure all vifs in mac80211 we don't 12801c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov * know are woken up. 12811c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov */ 12821c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov ieee80211_wake_queues(wl->hw); 12836639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12846639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov spin_unlock_irqrestore(&wl->wl_lock, flags); 12856639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12866639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12871c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovbool wlcore_is_queue_stopped_by_reason(struct wl1271 *wl, 12881c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov struct wl12xx_vif *wlvif, u8 queue, 12891c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov enum wlcore_queue_stop_reason reason) 12906639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12911c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 12921c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov return test_bit(reason, &wl->queue_stop_reasons[hwq]); 12936639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 12946639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov 12951c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsovbool wlcore_is_queue_stopped(struct wl1271 *wl, struct wl12xx_vif *wlvif, 12961c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov u8 queue) 12976639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov{ 12981c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov int hwq = wlcore_tx_get_mac80211_queue(wlvif, queue); 12991c33db782d1d0d9be83feacbb065cd4956f485e7Arik Nemtsov return !!wl->queue_stop_reasons[hwq]; 13006639611467f34038aa63c5cb9f8d9e48171d6022Arik Nemtsov} 1301