18e84c258SEugene Krasnikov /* 28e84c258SEugene Krasnikov * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com> 38e84c258SEugene Krasnikov * 48e84c258SEugene Krasnikov * Permission to use, copy, modify, and/or distribute this software for any 58e84c258SEugene Krasnikov * purpose with or without fee is hereby granted, provided that the above 68e84c258SEugene Krasnikov * copyright notice and this permission notice appear in all copies. 78e84c258SEugene Krasnikov * 88e84c258SEugene Krasnikov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98e84c258SEugene Krasnikov * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108e84c258SEugene Krasnikov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 118e84c258SEugene Krasnikov * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128e84c258SEugene Krasnikov * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 138e84c258SEugene Krasnikov * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 148e84c258SEugene Krasnikov * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158e84c258SEugene Krasnikov */ 168e84c258SEugene Krasnikov 178e84c258SEugene Krasnikov #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 188e84c258SEugene Krasnikov 198e84c258SEugene Krasnikov #include "txrx.h" 208e84c258SEugene Krasnikov 218e84c258SEugene Krasnikov static inline int get_rssi0(struct wcn36xx_rx_bd *bd) 228e84c258SEugene Krasnikov { 238e84c258SEugene Krasnikov return 100 - ((bd->phy_stat0 >> 24) & 0xff); 248e84c258SEugene Krasnikov } 258e84c258SEugene Krasnikov 260aa90483SLoic Poulain struct wcn36xx_rate { 270aa90483SLoic Poulain u16 bitrate; 280aa90483SLoic Poulain u16 mcs_or_legacy_index; 290aa90483SLoic Poulain enum mac80211_rx_encoding encoding; 300aa90483SLoic Poulain enum mac80211_rx_encoding_flags encoding_flags; 310aa90483SLoic Poulain enum rate_info_bw bw; 320aa90483SLoic Poulain }; 330aa90483SLoic Poulain 348a27ca39SLoic Poulain /* Buffer descriptor rx_ch field is limited to 5-bit (4+1), a mapping is used 358a27ca39SLoic Poulain * for 11A Channels. 368a27ca39SLoic Poulain */ 378a27ca39SLoic Poulain static const u8 ab_rx_ch_map[] = { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 388a27ca39SLoic Poulain 108, 112, 116, 120, 124, 128, 132, 136, 140, 398a27ca39SLoic Poulain 149, 153, 157, 161, 165, 144 }; 408a27ca39SLoic Poulain 410aa90483SLoic Poulain static const struct wcn36xx_rate wcn36xx_rate_table[] = { 420aa90483SLoic Poulain /* 11b rates */ 430aa90483SLoic Poulain { 10, 0, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 440aa90483SLoic Poulain { 20, 1, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 450aa90483SLoic Poulain { 55, 2, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 460aa90483SLoic Poulain { 110, 3, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 470aa90483SLoic Poulain 480aa90483SLoic Poulain /* 11b SP (short preamble) */ 490aa90483SLoic Poulain { 10, 0, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 }, 500aa90483SLoic Poulain { 20, 1, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 }, 510aa90483SLoic Poulain { 55, 2, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 }, 520aa90483SLoic Poulain { 110, 3, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 }, 530aa90483SLoic Poulain 540aa90483SLoic Poulain /* 11ag */ 550aa90483SLoic Poulain { 60, 4, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 560aa90483SLoic Poulain { 90, 5, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 570aa90483SLoic Poulain { 120, 6, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 580aa90483SLoic Poulain { 180, 7, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 590aa90483SLoic Poulain { 240, 8, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 600aa90483SLoic Poulain { 360, 9, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 610aa90483SLoic Poulain { 480, 10, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 620aa90483SLoic Poulain { 540, 11, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 }, 630aa90483SLoic Poulain 640aa90483SLoic Poulain /* 11n */ 650aa90483SLoic Poulain { 65, 0, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 660aa90483SLoic Poulain { 130, 1, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 670aa90483SLoic Poulain { 195, 2, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 680aa90483SLoic Poulain { 260, 3, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 690aa90483SLoic Poulain { 390, 4, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 700aa90483SLoic Poulain { 520, 5, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 710aa90483SLoic Poulain { 585, 6, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 720aa90483SLoic Poulain { 650, 7, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 730aa90483SLoic Poulain 740aa90483SLoic Poulain /* 11n SGI */ 750aa90483SLoic Poulain { 72, 0, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 760aa90483SLoic Poulain { 144, 1, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 770aa90483SLoic Poulain { 217, 2, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 780aa90483SLoic Poulain { 289, 3, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 790aa90483SLoic Poulain { 434, 4, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 800aa90483SLoic Poulain { 578, 5, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 810aa90483SLoic Poulain { 650, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 820aa90483SLoic Poulain { 722, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 830aa90483SLoic Poulain 840aa90483SLoic Poulain /* 11n GF (greenfield) */ 850aa90483SLoic Poulain { 65, 0, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 860aa90483SLoic Poulain { 130, 1, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 870aa90483SLoic Poulain { 195, 2, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 880aa90483SLoic Poulain { 260, 3, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 890aa90483SLoic Poulain { 390, 4, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 900aa90483SLoic Poulain { 520, 5, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 910aa90483SLoic Poulain { 585, 6, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 920aa90483SLoic Poulain { 650, 7, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 }, 930aa90483SLoic Poulain 940aa90483SLoic Poulain /* 11n CB (channel bonding) */ 950aa90483SLoic Poulain { 135, 0, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 960aa90483SLoic Poulain { 270, 1, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 970aa90483SLoic Poulain { 405, 2, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 980aa90483SLoic Poulain { 540, 3, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 990aa90483SLoic Poulain { 810, 4, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 1000aa90483SLoic Poulain { 1080, 5, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 1010aa90483SLoic Poulain { 1215, 6, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 1020aa90483SLoic Poulain { 1350, 7, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 1030aa90483SLoic Poulain 1040aa90483SLoic Poulain /* 11n CB + SGI */ 1050aa90483SLoic Poulain { 150, 0, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1060aa90483SLoic Poulain { 300, 1, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1070aa90483SLoic Poulain { 450, 2, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1080aa90483SLoic Poulain { 600, 3, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1090aa90483SLoic Poulain { 900, 4, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1100aa90483SLoic Poulain { 1200, 5, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1110aa90483SLoic Poulain { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1120aa90483SLoic Poulain { 1500, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 1130aa90483SLoic Poulain 1140aa90483SLoic Poulain /* 11n GF + CB */ 1150aa90483SLoic Poulain { 135, 0, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1160aa90483SLoic Poulain { 270, 1, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1170aa90483SLoic Poulain { 405, 2, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1180aa90483SLoic Poulain { 540, 3, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1190aa90483SLoic Poulain { 810, 4, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1200aa90483SLoic Poulain { 1080, 5, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1210aa90483SLoic Poulain { 1215, 6, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1220aa90483SLoic Poulain { 1350, 7, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 }, 1230aa90483SLoic Poulain 12410630b15SBryan O'Donoghue /* 11ac reserved indices */ 12510630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 12610630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 12710630b15SBryan O'Donoghue 12810630b15SBryan O'Donoghue /* 11ac 20 MHz 800ns GI MCS 0-8 */ 12910630b15SBryan O'Donoghue { 65, 0, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13010630b15SBryan O'Donoghue { 130, 1, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13110630b15SBryan O'Donoghue { 195, 2, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13210630b15SBryan O'Donoghue { 260, 3, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13310630b15SBryan O'Donoghue { 390, 4, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13410630b15SBryan O'Donoghue { 520, 5, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13510630b15SBryan O'Donoghue { 585, 6, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13610630b15SBryan O'Donoghue { 650, 7, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13710630b15SBryan O'Donoghue { 780, 8, RX_ENC_HT, 0, RATE_INFO_BW_20 }, 13810630b15SBryan O'Donoghue 13910630b15SBryan O'Donoghue /* 11ac reserved indices */ 14010630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14110630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14210630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14310630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14410630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14510630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14610630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14810630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 14910630b15SBryan O'Donoghue 15010630b15SBryan O'Donoghue /* 11ac 20 MHz 400ns SGI MCS 6-8 */ 15110630b15SBryan O'Donoghue { 655, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 15210630b15SBryan O'Donoghue { 722, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 15310630b15SBryan O'Donoghue { 866, 8, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 }, 15410630b15SBryan O'Donoghue 15510630b15SBryan O'Donoghue /* 11ac reserved indices */ 15610630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 15710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 15810630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 15910630b15SBryan O'Donoghue 16010630b15SBryan O'Donoghue /* 11ac 40 MHz 800ns GI MCS 0-9 */ 16110630b15SBryan O'Donoghue { 135, 0, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16210630b15SBryan O'Donoghue { 270, 1, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16310630b15SBryan O'Donoghue { 405, 2, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16410630b15SBryan O'Donoghue { 540, 3, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16510630b15SBryan O'Donoghue { 810, 4, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16610630b15SBryan O'Donoghue { 1080, 5, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16710630b15SBryan O'Donoghue { 1215, 6, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16810630b15SBryan O'Donoghue { 1350, 7, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 16910630b15SBryan O'Donoghue { 1350, 7, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 17010630b15SBryan O'Donoghue { 1620, 8, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 17110630b15SBryan O'Donoghue { 1800, 9, RX_ENC_HT, 0, RATE_INFO_BW_40 }, 17210630b15SBryan O'Donoghue 17310630b15SBryan O'Donoghue /* 11ac reserved indices */ 17410630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 17510630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 17610630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 17710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 17810630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 17910630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 18010630b15SBryan O'Donoghue 18110630b15SBryan O'Donoghue /* 11ac 40 MHz 400ns SGI MCS 5-7 */ 18210630b15SBryan O'Donoghue { 1200, 5, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 18310630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 18410630b15SBryan O'Donoghue { 1500, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 18510630b15SBryan O'Donoghue 18610630b15SBryan O'Donoghue /* 11ac reserved index */ 18710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 18810630b15SBryan O'Donoghue 18910630b15SBryan O'Donoghue /* 11ac 40 MHz 400ns SGI MCS 5-7 */ 19010630b15SBryan O'Donoghue { 1800, 8, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 19110630b15SBryan O'Donoghue { 2000, 9, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 19210630b15SBryan O'Donoghue 19310630b15SBryan O'Donoghue /* 11ac reserved index */ 19410630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 19510630b15SBryan O'Donoghue 19610630b15SBryan O'Donoghue /* 11ac 80 MHz 800ns GI MCS 0-7 */ 19710630b15SBryan O'Donoghue { 292, 0, RX_ENC_HT, 0, RATE_INFO_BW_80}, 19810630b15SBryan O'Donoghue { 585, 1, RX_ENC_HT, 0, RATE_INFO_BW_80}, 19910630b15SBryan O'Donoghue { 877, 2, RX_ENC_HT, 0, RATE_INFO_BW_80}, 20010630b15SBryan O'Donoghue { 1170, 3, RX_ENC_HT, 0, RATE_INFO_BW_80}, 20110630b15SBryan O'Donoghue { 1755, 4, RX_ENC_HT, 0, RATE_INFO_BW_80}, 20210630b15SBryan O'Donoghue { 2340, 5, RX_ENC_HT, 0, RATE_INFO_BW_80}, 20310630b15SBryan O'Donoghue { 2632, 6, RX_ENC_HT, 0, RATE_INFO_BW_80}, 20410630b15SBryan O'Donoghue { 2925, 7, RX_ENC_HT, 0, RATE_INFO_BW_80}, 20510630b15SBryan O'Donoghue 20610630b15SBryan O'Donoghue /* 11 ac reserved index */ 20710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 20810630b15SBryan O'Donoghue 20910630b15SBryan O'Donoghue /* 11ac 80 MHz 800 ns GI MCS 8-9 */ 21010630b15SBryan O'Donoghue { 3510, 8, RX_ENC_HT, 0, RATE_INFO_BW_80}, 21110630b15SBryan O'Donoghue { 3900, 9, RX_ENC_HT, 0, RATE_INFO_BW_80}, 21210630b15SBryan O'Donoghue 21310630b15SBryan O'Donoghue /* 11 ac reserved indices */ 21410630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 21510630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 21610630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 21710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 21810630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 21910630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 22010630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 22110630b15SBryan O'Donoghue 22210630b15SBryan O'Donoghue /* 11ac 80 MHz 400 ns SGI MCS 6-7 */ 22310630b15SBryan O'Donoghue { 2925, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 }, 22410630b15SBryan O'Donoghue { 3250, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 }, 22510630b15SBryan O'Donoghue 22610630b15SBryan O'Donoghue /* 11ac reserved index */ 22710630b15SBryan O'Donoghue { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 }, 22810630b15SBryan O'Donoghue 22910630b15SBryan O'Donoghue /* 11ac 80 MHz 400ns SGI MCS 8-9 */ 23010630b15SBryan O'Donoghue { 3900, 8, RX_ENC_VHT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 }, 23110630b15SBryan O'Donoghue { 4333, 9, RX_ENC_VHT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 }, 2320aa90483SLoic Poulain }; 2330aa90483SLoic Poulain 234a224b47aSLoic Poulain static struct sk_buff *wcn36xx_unchain_msdu(struct sk_buff_head *amsdu) 235a224b47aSLoic Poulain { 236a224b47aSLoic Poulain struct sk_buff *skb, *first; 237a224b47aSLoic Poulain int total_len = 0; 238a224b47aSLoic Poulain int space; 239a224b47aSLoic Poulain 240a224b47aSLoic Poulain first = __skb_dequeue(amsdu); 241a224b47aSLoic Poulain 242a224b47aSLoic Poulain skb_queue_walk(amsdu, skb) 243a224b47aSLoic Poulain total_len += skb->len; 244a224b47aSLoic Poulain 245a224b47aSLoic Poulain space = total_len - skb_tailroom(first); 246a224b47aSLoic Poulain if (space > 0 && pskb_expand_head(first, 0, space, GFP_ATOMIC) < 0) { 247a224b47aSLoic Poulain __skb_queue_head(amsdu, first); 248a224b47aSLoic Poulain return NULL; 249a224b47aSLoic Poulain } 250a224b47aSLoic Poulain 251a224b47aSLoic Poulain /* Walk list again, copying contents into msdu_head */ 252a224b47aSLoic Poulain while ((skb = __skb_dequeue(amsdu))) { 253a224b47aSLoic Poulain skb_copy_from_linear_data(skb, skb_put(first, skb->len), 254a224b47aSLoic Poulain skb->len); 255a224b47aSLoic Poulain dev_kfree_skb_irq(skb); 256a224b47aSLoic Poulain } 257a224b47aSLoic Poulain 258a224b47aSLoic Poulain return first; 259a224b47aSLoic Poulain } 260a224b47aSLoic Poulain 261a224b47aSLoic Poulain static void __skb_queue_purge_irq(struct sk_buff_head *list) 262a224b47aSLoic Poulain { 263a224b47aSLoic Poulain struct sk_buff *skb; 264a224b47aSLoic Poulain 265a224b47aSLoic Poulain while ((skb = __skb_dequeue(list)) != NULL) 266a224b47aSLoic Poulain dev_kfree_skb_irq(skb); 267a224b47aSLoic Poulain } 268a224b47aSLoic Poulain 2698e84c258SEugene Krasnikov int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb) 2708e84c258SEugene Krasnikov { 2718e84c258SEugene Krasnikov struct ieee80211_rx_status status; 2720aa90483SLoic Poulain const struct wcn36xx_rate *rate; 2738e84c258SEugene Krasnikov struct ieee80211_hdr *hdr; 2748e84c258SEugene Krasnikov struct wcn36xx_rx_bd *bd; 2756ea131acSLoic Poulain struct ieee80211_supported_band *sband; 2768e84c258SEugene Krasnikov u16 fc, sn; 2778e84c258SEugene Krasnikov 2788e84c258SEugene Krasnikov /* 2798e84c258SEugene Krasnikov * All fields must be 0, otherwise it can lead to 2808e84c258SEugene Krasnikov * unexpected consequences. 2818e84c258SEugene Krasnikov */ 2828e84c258SEugene Krasnikov memset(&status, 0, sizeof(status)); 2838e84c258SEugene Krasnikov 2848e84c258SEugene Krasnikov bd = (struct wcn36xx_rx_bd *)skb->data; 2858e84c258SEugene Krasnikov buff_to_be((u32 *)bd, sizeof(*bd)/sizeof(u32)); 2868e84c258SEugene Krasnikov wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP, 2878e84c258SEugene Krasnikov "BD <<< ", (char *)bd, 2888e84c258SEugene Krasnikov sizeof(struct wcn36xx_rx_bd)); 2898e84c258SEugene Krasnikov 290a224b47aSLoic Poulain if (bd->pdu.mpdu_data_off <= bd->pdu.mpdu_header_off || 291a224b47aSLoic Poulain bd->pdu.mpdu_len < bd->pdu.mpdu_header_len) 292a224b47aSLoic Poulain goto drop; 293a224b47aSLoic Poulain 294a224b47aSLoic Poulain if (bd->asf && !bd->esf) { /* chained A-MSDU chunks */ 295a224b47aSLoic Poulain /* Sanity check */ 296a224b47aSLoic Poulain if (bd->pdu.mpdu_data_off + bd->pdu.mpdu_len > WCN36XX_PKT_SIZE) 297a224b47aSLoic Poulain goto drop; 298a224b47aSLoic Poulain 299a224b47aSLoic Poulain skb_put(skb, bd->pdu.mpdu_data_off + bd->pdu.mpdu_len); 300a224b47aSLoic Poulain skb_pull(skb, bd->pdu.mpdu_data_off); 301a224b47aSLoic Poulain 302a224b47aSLoic Poulain /* Only set status for first chained BD (with mac header) */ 303a224b47aSLoic Poulain goto done; 304a224b47aSLoic Poulain } 305a224b47aSLoic Poulain 306a224b47aSLoic Poulain if (bd->pdu.mpdu_header_off < sizeof(*bd) || 307a224b47aSLoic Poulain bd->pdu.mpdu_header_off + bd->pdu.mpdu_len > WCN36XX_PKT_SIZE) 308a224b47aSLoic Poulain goto drop; 309a224b47aSLoic Poulain 3108e84c258SEugene Krasnikov skb_put(skb, bd->pdu.mpdu_header_off + bd->pdu.mpdu_len); 3118e84c258SEugene Krasnikov skb_pull(skb, bd->pdu.mpdu_header_off); 3128e84c258SEugene Krasnikov 31388603903SBjorn Andersson hdr = (struct ieee80211_hdr *) skb->data; 31488603903SBjorn Andersson fc = __le16_to_cpu(hdr->frame_control); 31588603903SBjorn Andersson sn = IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr->seq_ctrl)); 31688603903SBjorn Andersson 3178e84c258SEugene Krasnikov status.freq = WCN36XX_CENTER_FREQ(wcn); 3188e84c258SEugene Krasnikov status.band = WCN36XX_BAND(wcn); 31988603903SBjorn Andersson status.mactime = 10; 3208e84c258SEugene Krasnikov status.signal = -get_rssi0(bd); 3218e84c258SEugene Krasnikov status.antenna = 1; 3228e84c258SEugene Krasnikov status.flag = 0; 3238e84c258SEugene Krasnikov status.rx_flags = 0; 3248e84c258SEugene Krasnikov status.flag |= RX_FLAG_IV_STRIPPED | 3258e84c258SEugene Krasnikov RX_FLAG_MMIC_STRIPPED | 3268e84c258SEugene Krasnikov RX_FLAG_DECRYPTED; 3278e84c258SEugene Krasnikov 3287fdd69c5SJohannes Berg wcn36xx_dbg(WCN36XX_DBG_RX, "status.flags=%x\n", status.flag); 3298e84c258SEugene Krasnikov 3300aa90483SLoic Poulain if (bd->rate_id < ARRAY_SIZE(wcn36xx_rate_table)) { 3310aa90483SLoic Poulain rate = &wcn36xx_rate_table[bd->rate_id]; 3320aa90483SLoic Poulain status.encoding = rate->encoding; 3330aa90483SLoic Poulain status.enc_flags = rate->encoding_flags; 3340aa90483SLoic Poulain status.bw = rate->bw; 3350aa90483SLoic Poulain status.rate_idx = rate->mcs_or_legacy_index; 3366ea131acSLoic Poulain sband = wcn->hw->wiphy->bands[status.band]; 3371af05d43SBryan O'Donoghue status.nss = 1; 3386ea131acSLoic Poulain 3396ea131acSLoic Poulain if (status.band == NL80211_BAND_5GHZ && 3406ea131acSLoic Poulain status.encoding == RX_ENC_LEGACY && 3416ea131acSLoic Poulain status.rate_idx >= sband->n_bitrates) { 3426ea131acSLoic Poulain /* no dsss rates in 5Ghz rates table */ 3436ea131acSLoic Poulain status.rate_idx -= 4; 3446ea131acSLoic Poulain } 3450aa90483SLoic Poulain } else { 3460aa90483SLoic Poulain status.encoding = 0; 3470aa90483SLoic Poulain status.bw = 0; 3480aa90483SLoic Poulain status.enc_flags = 0; 3490aa90483SLoic Poulain status.rate_idx = 0; 3500aa90483SLoic Poulain } 3510aa90483SLoic Poulain 3528678fd31SLoic Poulain if (ieee80211_is_beacon(hdr->frame_control) || 3538678fd31SLoic Poulain ieee80211_is_probe_resp(hdr->frame_control)) 3548678fd31SLoic Poulain status.boottime_ns = ktime_get_boottime_ns(); 3558678fd31SLoic Poulain 3568a27ca39SLoic Poulain if (bd->scan_learn) { 3578a27ca39SLoic Poulain /* If packet originates from hardware scanning, extract the 3588a27ca39SLoic Poulain * band/channel from bd descriptor. 3598a27ca39SLoic Poulain */ 3608a27ca39SLoic Poulain u8 hwch = (bd->reserved0 << 4) + bd->rx_ch; 3618a27ca39SLoic Poulain 3628a27ca39SLoic Poulain if (bd->rf_band != 1 && hwch <= sizeof(ab_rx_ch_map) && hwch >= 1) { 3638a27ca39SLoic Poulain status.band = NL80211_BAND_5GHZ; 3648a27ca39SLoic Poulain status.freq = ieee80211_channel_to_frequency(ab_rx_ch_map[hwch - 1], 3658a27ca39SLoic Poulain status.band); 3668a27ca39SLoic Poulain } else { 3678a27ca39SLoic Poulain status.band = NL80211_BAND_2GHZ; 3688a27ca39SLoic Poulain status.freq = ieee80211_channel_to_frequency(hwch, status.band); 3698a27ca39SLoic Poulain } 3708a27ca39SLoic Poulain } 3718a27ca39SLoic Poulain 3728e84c258SEugene Krasnikov memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); 3738e84c258SEugene Krasnikov 3748e84c258SEugene Krasnikov if (ieee80211_is_beacon(hdr->frame_control)) { 3758e84c258SEugene Krasnikov wcn36xx_dbg(WCN36XX_DBG_BEACON, "beacon skb %p len %d fc %04x sn %d\n", 3768e84c258SEugene Krasnikov skb, skb->len, fc, sn); 3778e84c258SEugene Krasnikov wcn36xx_dbg_dump(WCN36XX_DBG_BEACON_DUMP, "SKB <<< ", 3788e84c258SEugene Krasnikov (char *)skb->data, skb->len); 3798e84c258SEugene Krasnikov } else { 3808e84c258SEugene Krasnikov wcn36xx_dbg(WCN36XX_DBG_RX, "rx skb %p len %d fc %04x sn %d\n", 3818e84c258SEugene Krasnikov skb, skb->len, fc, sn); 3828e84c258SEugene Krasnikov wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP, "SKB <<< ", 3838e84c258SEugene Krasnikov (char *)skb->data, skb->len); 3848e84c258SEugene Krasnikov } 3858e84c258SEugene Krasnikov 386a224b47aSLoic Poulain done: 387a224b47aSLoic Poulain /* Chained AMSDU ? slow path */ 388a224b47aSLoic Poulain if (unlikely(bd->asf && !(bd->lsf && bd->esf))) { 389a224b47aSLoic Poulain if (bd->esf && !skb_queue_empty(&wcn->amsdu)) { 390a224b47aSLoic Poulain wcn36xx_err("Discarding non complete chain"); 391a224b47aSLoic Poulain __skb_queue_purge_irq(&wcn->amsdu); 392a224b47aSLoic Poulain } 393a224b47aSLoic Poulain 394a224b47aSLoic Poulain __skb_queue_tail(&wcn->amsdu, skb); 395a224b47aSLoic Poulain 396a224b47aSLoic Poulain if (!bd->lsf) 397a224b47aSLoic Poulain return 0; /* Not the last AMSDU, wait for more */ 398a224b47aSLoic Poulain 399a224b47aSLoic Poulain skb = wcn36xx_unchain_msdu(&wcn->amsdu); 400a224b47aSLoic Poulain if (!skb) 401a224b47aSLoic Poulain goto drop; 402a224b47aSLoic Poulain } 403a224b47aSLoic Poulain 4048e84c258SEugene Krasnikov ieee80211_rx_irqsafe(wcn->hw, skb); 4058e84c258SEugene Krasnikov 4068e84c258SEugene Krasnikov return 0; 407a224b47aSLoic Poulain 408a224b47aSLoic Poulain drop: /* drop everything */ 409a224b47aSLoic Poulain wcn36xx_err("Drop frame! skb:%p len:%u hoff:%u doff:%u asf=%u esf=%u lsf=%u\n", 410a224b47aSLoic Poulain skb, bd->pdu.mpdu_len, bd->pdu.mpdu_header_off, 411a224b47aSLoic Poulain bd->pdu.mpdu_data_off, bd->asf, bd->esf, bd->lsf); 412a224b47aSLoic Poulain 413a224b47aSLoic Poulain dev_kfree_skb_irq(skb); 414a224b47aSLoic Poulain __skb_queue_purge_irq(&wcn->amsdu); 415a224b47aSLoic Poulain 416a224b47aSLoic Poulain return -EINVAL; 4178e84c258SEugene Krasnikov } 4188e84c258SEugene Krasnikov 4198e84c258SEugene Krasnikov static void wcn36xx_set_tx_pdu(struct wcn36xx_tx_bd *bd, 4208e84c258SEugene Krasnikov u32 mpdu_header_len, 4218e84c258SEugene Krasnikov u32 len, 4228e84c258SEugene Krasnikov u16 tid) 4238e84c258SEugene Krasnikov { 4248e84c258SEugene Krasnikov bd->pdu.mpdu_header_len = mpdu_header_len; 4258e84c258SEugene Krasnikov bd->pdu.mpdu_header_off = sizeof(*bd); 4268e84c258SEugene Krasnikov bd->pdu.mpdu_data_off = bd->pdu.mpdu_header_len + 4278e84c258SEugene Krasnikov bd->pdu.mpdu_header_off; 4288e84c258SEugene Krasnikov bd->pdu.mpdu_len = len; 4298e84c258SEugene Krasnikov bd->pdu.tid = tid; 4308e84c258SEugene Krasnikov } 4318e84c258SEugene Krasnikov 4328e84c258SEugene Krasnikov static inline struct wcn36xx_vif *get_vif_by_addr(struct wcn36xx *wcn, 4338e84c258SEugene Krasnikov u8 *addr) 4348e84c258SEugene Krasnikov { 4358e84c258SEugene Krasnikov struct wcn36xx_vif *vif_priv = NULL; 4368e84c258SEugene Krasnikov struct ieee80211_vif *vif = NULL; 4378e84c258SEugene Krasnikov list_for_each_entry(vif_priv, &wcn->vif_list, list) { 438ce75877fSPontus Fuchs vif = wcn36xx_priv_to_vif(vif_priv); 4398e84c258SEugene Krasnikov if (memcmp(vif->addr, addr, ETH_ALEN) == 0) 4408e84c258SEugene Krasnikov return vif_priv; 4418e84c258SEugene Krasnikov } 4428e84c258SEugene Krasnikov wcn36xx_warn("vif %pM not found\n", addr); 4438e84c258SEugene Krasnikov return NULL; 4448e84c258SEugene Krasnikov } 445e26dc173SBob Copeland 446e26dc173SBob Copeland static void wcn36xx_tx_start_ampdu(struct wcn36xx *wcn, 447e26dc173SBob Copeland struct wcn36xx_sta *sta_priv, 448e26dc173SBob Copeland struct sk_buff *skb) 449e26dc173SBob Copeland { 450e26dc173SBob Copeland struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 451e26dc173SBob Copeland struct ieee80211_sta *sta; 452e26dc173SBob Copeland u8 *qc, tid; 453e26dc173SBob Copeland 454e26dc173SBob Copeland if (!conf_is_ht(&wcn->hw->conf)) 455e26dc173SBob Copeland return; 456e26dc173SBob Copeland 457e26dc173SBob Copeland sta = wcn36xx_priv_to_sta(sta_priv); 458e26dc173SBob Copeland 459e26dc173SBob Copeland if (WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) 460e26dc173SBob Copeland return; 461e26dc173SBob Copeland 462e26dc173SBob Copeland if (skb_get_queue_mapping(skb) == IEEE80211_AC_VO) 463e26dc173SBob Copeland return; 464e26dc173SBob Copeland 465e26dc173SBob Copeland qc = ieee80211_get_qos_ctl(hdr); 466e26dc173SBob Copeland tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 467e26dc173SBob Copeland 468e26dc173SBob Copeland spin_lock(&sta_priv->ampdu_lock); 469e26dc173SBob Copeland if (sta_priv->ampdu_state[tid] != WCN36XX_AMPDU_NONE) 470e26dc173SBob Copeland goto out_unlock; 471e26dc173SBob Copeland 472e26dc173SBob Copeland if (sta_priv->non_agg_frame_ct++ >= WCN36XX_AMPDU_START_THRESH) { 473e26dc173SBob Copeland sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START; 474e26dc173SBob Copeland sta_priv->non_agg_frame_ct = 0; 475e26dc173SBob Copeland ieee80211_start_tx_ba_session(sta, tid, 0); 476e26dc173SBob Copeland } 477e26dc173SBob Copeland out_unlock: 478e26dc173SBob Copeland spin_unlock(&sta_priv->ampdu_lock); 479e26dc173SBob Copeland } 480e26dc173SBob Copeland 4818e84c258SEugene Krasnikov static void wcn36xx_set_tx_data(struct wcn36xx_tx_bd *bd, 4828e84c258SEugene Krasnikov struct wcn36xx *wcn, 4838e84c258SEugene Krasnikov struct wcn36xx_vif **vif_priv, 4848e84c258SEugene Krasnikov struct wcn36xx_sta *sta_priv, 4855f3f9285SBob Copeland struct sk_buff *skb, 4868e84c258SEugene Krasnikov bool bcast) 4878e84c258SEugene Krasnikov { 4885f3f9285SBob Copeland struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 489512b191dSLoic Poulain struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 4908e84c258SEugene Krasnikov struct ieee80211_vif *vif = NULL; 4918e84c258SEugene Krasnikov struct wcn36xx_vif *__vif_priv = NULL; 492512b191dSLoic Poulain bool is_data_qos = ieee80211_is_data_qos(hdr->frame_control); 493512b191dSLoic Poulain u16 tid = 0; 494e26dc173SBob Copeland 4958e84c258SEugene Krasnikov bd->bd_rate = WCN36XX_BD_RATE_DATA; 4968e84c258SEugene Krasnikov 4978e84c258SEugene Krasnikov /* 4988e84c258SEugene Krasnikov * For not unicast frames mac80211 will not set sta pointer so use 4998e84c258SEugene Krasnikov * self_sta_index instead. 5008e84c258SEugene Krasnikov */ 5018e84c258SEugene Krasnikov if (sta_priv) { 5028e84c258SEugene Krasnikov __vif_priv = sta_priv->vif; 503ce75877fSPontus Fuchs vif = wcn36xx_priv_to_vif(__vif_priv); 5048e84c258SEugene Krasnikov 50582cad2a0SPontus Fuchs bd->dpu_sign = sta_priv->ucast_dpu_sign; 5068e84c258SEugene Krasnikov if (vif->type == NL80211_IFTYPE_STATION) { 5078e84c258SEugene Krasnikov bd->sta_index = sta_priv->bss_sta_index; 5088e84c258SEugene Krasnikov bd->dpu_desc_idx = sta_priv->bss_dpu_desc_index; 5098e84c258SEugene Krasnikov } else if (vif->type == NL80211_IFTYPE_AP || 5108e84c258SEugene Krasnikov vif->type == NL80211_IFTYPE_ADHOC || 5118e84c258SEugene Krasnikov vif->type == NL80211_IFTYPE_MESH_POINT) { 5128e84c258SEugene Krasnikov bd->sta_index = sta_priv->sta_index; 5138e84c258SEugene Krasnikov bd->dpu_desc_idx = sta_priv->dpu_desc_index; 5148e84c258SEugene Krasnikov } 5158e84c258SEugene Krasnikov } else { 5168e84c258SEugene Krasnikov __vif_priv = get_vif_by_addr(wcn, hdr->addr2); 5178e84c258SEugene Krasnikov bd->sta_index = __vif_priv->self_sta_index; 5188e84c258SEugene Krasnikov bd->dpu_desc_idx = __vif_priv->self_dpu_desc_index; 5192ba0b461SPontus Fuchs bd->dpu_sign = __vif_priv->self_ucast_dpu_sign; 52082cad2a0SPontus Fuchs } 5218e84c258SEugene Krasnikov 522512b191dSLoic Poulain if (is_data_qos) { 523512b191dSLoic Poulain tid = ieee80211_get_tid(hdr); 524512b191dSLoic Poulain /* TID->QID is one-to-one mapping */ 525512b191dSLoic Poulain bd->queue_id = tid; 526*113f304dSLoic Poulain bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_QOS; 527*113f304dSLoic Poulain } else { 528*113f304dSLoic Poulain bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_NON_QOS; 529512b191dSLoic Poulain } 530512b191dSLoic Poulain 531512b191dSLoic Poulain if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT || 532fdf21cc3SLoic Poulain (sta_priv && !sta_priv->is_data_encrypted)) { 5338e84c258SEugene Krasnikov bd->dpu_ne = 1; 534fdf21cc3SLoic Poulain } 5358e84c258SEugene Krasnikov 536512b191dSLoic Poulain if (ieee80211_is_any_nullfunc(hdr->frame_control)) { 537512b191dSLoic Poulain /* Don't use a regular queue for null packet (no ampdu) */ 538512b191dSLoic Poulain bd->queue_id = WCN36XX_TX_U_WQ_ID; 539d3fd2c95SLoic Poulain bd->bd_rate = WCN36XX_BD_RATE_CTRL; 540*113f304dSLoic Poulain if (ieee80211_is_qos_nullfunc(hdr->frame_control)) 541*113f304dSLoic Poulain bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_HOST; 542512b191dSLoic Poulain } 543512b191dSLoic Poulain 5448e84c258SEugene Krasnikov if (bcast) { 5458e84c258SEugene Krasnikov bd->ub = 1; 5468e84c258SEugene Krasnikov bd->ack_policy = 1; 5478e84c258SEugene Krasnikov } 5488e84c258SEugene Krasnikov *vif_priv = __vif_priv; 5495f3f9285SBob Copeland 5505f3f9285SBob Copeland wcn36xx_set_tx_pdu(bd, 551e26dc173SBob Copeland is_data_qos ? 5525f3f9285SBob Copeland sizeof(struct ieee80211_qos_hdr) : 5535f3f9285SBob Copeland sizeof(struct ieee80211_hdr_3addr), 554512b191dSLoic Poulain skb->len, tid); 555e26dc173SBob Copeland 556e26dc173SBob Copeland if (sta_priv && is_data_qos) 557e26dc173SBob Copeland wcn36xx_tx_start_ampdu(wcn, sta_priv, skb); 5588e84c258SEugene Krasnikov } 5598e84c258SEugene Krasnikov 5608e84c258SEugene Krasnikov static void wcn36xx_set_tx_mgmt(struct wcn36xx_tx_bd *bd, 5618e84c258SEugene Krasnikov struct wcn36xx *wcn, 5628e84c258SEugene Krasnikov struct wcn36xx_vif **vif_priv, 5635f3f9285SBob Copeland struct sk_buff *skb, 5648e84c258SEugene Krasnikov bool bcast) 5658e84c258SEugene Krasnikov { 5665f3f9285SBob Copeland struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 5678e84c258SEugene Krasnikov struct wcn36xx_vif *__vif_priv = 5688e84c258SEugene Krasnikov get_vif_by_addr(wcn, hdr->addr2); 5698e84c258SEugene Krasnikov bd->sta_index = __vif_priv->self_sta_index; 5708e84c258SEugene Krasnikov bd->dpu_desc_idx = __vif_priv->self_dpu_desc_index; 5718e84c258SEugene Krasnikov bd->dpu_ne = 1; 5728e84c258SEugene Krasnikov 5738e84c258SEugene Krasnikov /* default rate for unicast */ 5748e84c258SEugene Krasnikov if (ieee80211_is_mgmt(hdr->frame_control)) 57557fbcce3SJohannes Berg bd->bd_rate = (WCN36XX_BAND(wcn) == NL80211_BAND_5GHZ) ? 5768e84c258SEugene Krasnikov WCN36XX_BD_RATE_CTRL : 5778e84c258SEugene Krasnikov WCN36XX_BD_RATE_MGMT; 5788e84c258SEugene Krasnikov else if (ieee80211_is_ctl(hdr->frame_control)) 5798e84c258SEugene Krasnikov bd->bd_rate = WCN36XX_BD_RATE_CTRL; 5808e84c258SEugene Krasnikov else 5818e84c258SEugene Krasnikov wcn36xx_warn("frame control type unknown\n"); 5828e84c258SEugene Krasnikov 5838e84c258SEugene Krasnikov /* 5848e84c258SEugene Krasnikov * In joining state trick hardware that probe is sent as 5858e84c258SEugene Krasnikov * unicast even if address is broadcast. 5868e84c258SEugene Krasnikov */ 5878e84c258SEugene Krasnikov if (__vif_priv->is_joining && 5888e84c258SEugene Krasnikov ieee80211_is_probe_req(hdr->frame_control)) 5898e84c258SEugene Krasnikov bcast = false; 5908e84c258SEugene Krasnikov 5918e84c258SEugene Krasnikov if (bcast) { 5928e84c258SEugene Krasnikov /* broadcast */ 5938e84c258SEugene Krasnikov bd->ub = 1; 5948e84c258SEugene Krasnikov /* No ack needed not unicast */ 5958e84c258SEugene Krasnikov bd->ack_policy = 1; 5968e84c258SEugene Krasnikov bd->queue_id = WCN36XX_TX_B_WQ_ID; 5978e84c258SEugene Krasnikov } else 5988e84c258SEugene Krasnikov bd->queue_id = WCN36XX_TX_U_WQ_ID; 5998e84c258SEugene Krasnikov *vif_priv = __vif_priv; 6005f3f9285SBob Copeland 601*113f304dSLoic Poulain bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_NON_QOS; 602*113f304dSLoic Poulain 6035f3f9285SBob Copeland wcn36xx_set_tx_pdu(bd, 6045f3f9285SBob Copeland ieee80211_is_data_qos(hdr->frame_control) ? 6055f3f9285SBob Copeland sizeof(struct ieee80211_qos_hdr) : 6065f3f9285SBob Copeland sizeof(struct ieee80211_hdr_3addr), 6075f3f9285SBob Copeland skb->len, WCN36XX_TID); 6088e84c258SEugene Krasnikov } 6098e84c258SEugene Krasnikov 6108e84c258SEugene Krasnikov int wcn36xx_start_tx(struct wcn36xx *wcn, 6118e84c258SEugene Krasnikov struct wcn36xx_sta *sta_priv, 6128e84c258SEugene Krasnikov struct sk_buff *skb) 6138e84c258SEugene Krasnikov { 6148e84c258SEugene Krasnikov struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 6158e84c258SEugene Krasnikov struct wcn36xx_vif *vif_priv = NULL; 6168e84c258SEugene Krasnikov struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 6178e84c258SEugene Krasnikov bool is_low = ieee80211_is_data(hdr->frame_control); 6188e84c258SEugene Krasnikov bool bcast = is_broadcast_ether_addr(hdr->addr1) || 6198e84c258SEugene Krasnikov is_multicast_ether_addr(hdr->addr1); 620a9e79b11SLoic Poulain bool ack_ind = (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) && 621a9e79b11SLoic Poulain !(info->flags & IEEE80211_TX_CTL_NO_ACK); 622e5f99081SLoic Poulain struct wcn36xx_tx_bd bd; 623271f1e65SDaniel Mack int ret; 6248e84c258SEugene Krasnikov 625e5f99081SLoic Poulain memset(&bd, 0, sizeof(bd)); 6268e84c258SEugene Krasnikov 6278e84c258SEugene Krasnikov wcn36xx_dbg(WCN36XX_DBG_TX, 6288e84c258SEugene Krasnikov "tx skb %p len %d fc %04x sn %d %s %s\n", 6298e84c258SEugene Krasnikov skb, skb->len, __le16_to_cpu(hdr->frame_control), 6308e84c258SEugene Krasnikov IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr->seq_ctrl)), 6318e84c258SEugene Krasnikov is_low ? "low" : "high", bcast ? "bcast" : "ucast"); 6328e84c258SEugene Krasnikov 6338e84c258SEugene Krasnikov wcn36xx_dbg_dump(WCN36XX_DBG_TX_DUMP, "", skb->data, skb->len); 6348e84c258SEugene Krasnikov 635e5f99081SLoic Poulain bd.dpu_rf = WCN36XX_BMU_WQ_TX; 6368e84c258SEugene Krasnikov 637a9e79b11SLoic Poulain if (unlikely(ack_ind)) { 6388e84c258SEugene Krasnikov wcn36xx_dbg(WCN36XX_DBG_DXE, "TX_ACK status requested\n"); 639fdf21cc3SLoic Poulain 6408e84c258SEugene Krasnikov /* Only one at a time is supported by fw. Stop the TX queues 6418e84c258SEugene Krasnikov * until the ack status gets back. 6428e84c258SEugene Krasnikov */ 6438e84c258SEugene Krasnikov ieee80211_stop_queues(wcn->hw); 644fdf21cc3SLoic Poulain 645fdf21cc3SLoic Poulain /* Request ack indication from the firmware */ 646fdf21cc3SLoic Poulain bd.tx_comp = 1; 6478e84c258SEugene Krasnikov } 6488e84c258SEugene Krasnikov 6498e84c258SEugene Krasnikov /* Data frames served first*/ 6505f3f9285SBob Copeland if (is_low) 651e5f99081SLoic Poulain wcn36xx_set_tx_data(&bd, wcn, &vif_priv, sta_priv, skb, bcast); 6525f3f9285SBob Copeland else 6538e84c258SEugene Krasnikov /* MGMT and CTRL frames are handeld here*/ 654e5f99081SLoic Poulain wcn36xx_set_tx_mgmt(&bd, wcn, &vif_priv, skb, bcast); 6558e84c258SEugene Krasnikov 656e5f99081SLoic Poulain buff_to_be((u32 *)&bd, sizeof(bd)/sizeof(u32)); 657e5f99081SLoic Poulain bd.tx_bd_sign = 0xbdbdbdbd; 6588e84c258SEugene Krasnikov 659271f1e65SDaniel Mack ret = wcn36xx_dxe_tx_frame(wcn, vif_priv, &bd, skb, is_low); 660a9e79b11SLoic Poulain if (unlikely(ret && ack_ind)) { 661a9e79b11SLoic Poulain /* If the skb has not been transmitted, resume TX queue */ 662271f1e65SDaniel Mack ieee80211_wake_queues(wcn->hw); 663271f1e65SDaniel Mack } 664271f1e65SDaniel Mack 665271f1e65SDaniel Mack return ret; 6668e84c258SEugene Krasnikov } 667