18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2010 Broadcom Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 118c2ecf20Sopenharmony_ci * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 138c2ecf20Sopenharmony_ci * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 148c2ecf20Sopenharmony_ci * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <brcmu_wifi.h> 188c2ecf20Sopenharmony_ci#include <brcmu_utils.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include "d11.h" 218c2ecf20Sopenharmony_ci#include "pub.h" 228c2ecf20Sopenharmony_ci#include "rate.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * Rate info per rate: It tells whether a rate is ofdm or not and its phy_rate 268c2ecf20Sopenharmony_ci * value 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ciconst u8 rate_info[BRCM_MAXRATE + 1] = { 298c2ecf20Sopenharmony_ci /* 0 1 2 3 4 5 6 7 8 9 */ 308c2ecf20Sopenharmony_ci/* 0 */ 0x00, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 318c2ecf20Sopenharmony_ci/* 10 */ 0x00, 0x37, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x00, 328c2ecf20Sopenharmony_ci/* 20 */ 0x00, 0x00, 0x6e, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 338c2ecf20Sopenharmony_ci/* 30 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 348c2ecf20Sopenharmony_ci/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x00, 358c2ecf20Sopenharmony_ci/* 50 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 368c2ecf20Sopenharmony_ci/* 60 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 378c2ecf20Sopenharmony_ci/* 70 */ 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 388c2ecf20Sopenharmony_ci/* 80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 398c2ecf20Sopenharmony_ci/* 90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 408c2ecf20Sopenharmony_ci/* 100 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* rates are in units of Kbps */ 448c2ecf20Sopenharmony_ciconst struct brcms_mcs_info mcs_table[MCS_TABLE_SIZE] = { 458c2ecf20Sopenharmony_ci /* MCS 0: SS 1, MOD: BPSK, CR 1/2 */ 468c2ecf20Sopenharmony_ci {6500, 13500, CEIL(6500 * 10, 9), CEIL(13500 * 10, 9), 0x00, 478c2ecf20Sopenharmony_ci BRCM_RATE_6M}, 488c2ecf20Sopenharmony_ci /* MCS 1: SS 1, MOD: QPSK, CR 1/2 */ 498c2ecf20Sopenharmony_ci {13000, 27000, CEIL(13000 * 10, 9), CEIL(27000 * 10, 9), 0x08, 508c2ecf20Sopenharmony_ci BRCM_RATE_12M}, 518c2ecf20Sopenharmony_ci /* MCS 2: SS 1, MOD: QPSK, CR 3/4 */ 528c2ecf20Sopenharmony_ci {19500, 40500, CEIL(19500 * 10, 9), CEIL(40500 * 10, 9), 0x0A, 538c2ecf20Sopenharmony_ci BRCM_RATE_18M}, 548c2ecf20Sopenharmony_ci /* MCS 3: SS 1, MOD: 16QAM, CR 1/2 */ 558c2ecf20Sopenharmony_ci {26000, 54000, CEIL(26000 * 10, 9), CEIL(54000 * 10, 9), 0x10, 568c2ecf20Sopenharmony_ci BRCM_RATE_24M}, 578c2ecf20Sopenharmony_ci /* MCS 4: SS 1, MOD: 16QAM, CR 3/4 */ 588c2ecf20Sopenharmony_ci {39000, 81000, CEIL(39000 * 10, 9), CEIL(81000 * 10, 9), 0x12, 598c2ecf20Sopenharmony_ci BRCM_RATE_36M}, 608c2ecf20Sopenharmony_ci /* MCS 5: SS 1, MOD: 64QAM, CR 2/3 */ 618c2ecf20Sopenharmony_ci {52000, 108000, CEIL(52000 * 10, 9), CEIL(108000 * 10, 9), 0x19, 628c2ecf20Sopenharmony_ci BRCM_RATE_48M}, 638c2ecf20Sopenharmony_ci /* MCS 6: SS 1, MOD: 64QAM, CR 3/4 */ 648c2ecf20Sopenharmony_ci {58500, 121500, CEIL(58500 * 10, 9), CEIL(121500 * 10, 9), 0x1A, 658c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 668c2ecf20Sopenharmony_ci /* MCS 7: SS 1, MOD: 64QAM, CR 5/6 */ 678c2ecf20Sopenharmony_ci {65000, 135000, CEIL(65000 * 10, 9), CEIL(135000 * 10, 9), 0x1C, 688c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 698c2ecf20Sopenharmony_ci /* MCS 8: SS 2, MOD: BPSK, CR 1/2 */ 708c2ecf20Sopenharmony_ci {13000, 27000, CEIL(13000 * 10, 9), CEIL(27000 * 10, 9), 0x40, 718c2ecf20Sopenharmony_ci BRCM_RATE_6M}, 728c2ecf20Sopenharmony_ci /* MCS 9: SS 2, MOD: QPSK, CR 1/2 */ 738c2ecf20Sopenharmony_ci {26000, 54000, CEIL(26000 * 10, 9), CEIL(54000 * 10, 9), 0x48, 748c2ecf20Sopenharmony_ci BRCM_RATE_12M}, 758c2ecf20Sopenharmony_ci /* MCS 10: SS 2, MOD: QPSK, CR 3/4 */ 768c2ecf20Sopenharmony_ci {39000, 81000, CEIL(39000 * 10, 9), CEIL(81000 * 10, 9), 0x4A, 778c2ecf20Sopenharmony_ci BRCM_RATE_18M}, 788c2ecf20Sopenharmony_ci /* MCS 11: SS 2, MOD: 16QAM, CR 1/2 */ 798c2ecf20Sopenharmony_ci {52000, 108000, CEIL(52000 * 10, 9), CEIL(108000 * 10, 9), 0x50, 808c2ecf20Sopenharmony_ci BRCM_RATE_24M}, 818c2ecf20Sopenharmony_ci /* MCS 12: SS 2, MOD: 16QAM, CR 3/4 */ 828c2ecf20Sopenharmony_ci {78000, 162000, CEIL(78000 * 10, 9), CEIL(162000 * 10, 9), 0x52, 838c2ecf20Sopenharmony_ci BRCM_RATE_36M}, 848c2ecf20Sopenharmony_ci /* MCS 13: SS 2, MOD: 64QAM, CR 2/3 */ 858c2ecf20Sopenharmony_ci {104000, 216000, CEIL(104000 * 10, 9), CEIL(216000 * 10, 9), 0x59, 868c2ecf20Sopenharmony_ci BRCM_RATE_48M}, 878c2ecf20Sopenharmony_ci /* MCS 14: SS 2, MOD: 64QAM, CR 3/4 */ 888c2ecf20Sopenharmony_ci {117000, 243000, CEIL(117000 * 10, 9), CEIL(243000 * 10, 9), 0x5A, 898c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 908c2ecf20Sopenharmony_ci /* MCS 15: SS 2, MOD: 64QAM, CR 5/6 */ 918c2ecf20Sopenharmony_ci {130000, 270000, CEIL(130000 * 10, 9), CEIL(270000 * 10, 9), 0x5C, 928c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 938c2ecf20Sopenharmony_ci /* MCS 16: SS 3, MOD: BPSK, CR 1/2 */ 948c2ecf20Sopenharmony_ci {19500, 40500, CEIL(19500 * 10, 9), CEIL(40500 * 10, 9), 0x80, 958c2ecf20Sopenharmony_ci BRCM_RATE_6M}, 968c2ecf20Sopenharmony_ci /* MCS 17: SS 3, MOD: QPSK, CR 1/2 */ 978c2ecf20Sopenharmony_ci {39000, 81000, CEIL(39000 * 10, 9), CEIL(81000 * 10, 9), 0x88, 988c2ecf20Sopenharmony_ci BRCM_RATE_12M}, 998c2ecf20Sopenharmony_ci /* MCS 18: SS 3, MOD: QPSK, CR 3/4 */ 1008c2ecf20Sopenharmony_ci {58500, 121500, CEIL(58500 * 10, 9), CEIL(121500 * 10, 9), 0x8A, 1018c2ecf20Sopenharmony_ci BRCM_RATE_18M}, 1028c2ecf20Sopenharmony_ci /* MCS 19: SS 3, MOD: 16QAM, CR 1/2 */ 1038c2ecf20Sopenharmony_ci {78000, 162000, CEIL(78000 * 10, 9), CEIL(162000 * 10, 9), 0x90, 1048c2ecf20Sopenharmony_ci BRCM_RATE_24M}, 1058c2ecf20Sopenharmony_ci /* MCS 20: SS 3, MOD: 16QAM, CR 3/4 */ 1068c2ecf20Sopenharmony_ci {117000, 243000, CEIL(117000 * 10, 9), CEIL(243000 * 10, 9), 0x92, 1078c2ecf20Sopenharmony_ci BRCM_RATE_36M}, 1088c2ecf20Sopenharmony_ci /* MCS 21: SS 3, MOD: 64QAM, CR 2/3 */ 1098c2ecf20Sopenharmony_ci {156000, 324000, CEIL(156000 * 10, 9), CEIL(324000 * 10, 9), 0x99, 1108c2ecf20Sopenharmony_ci BRCM_RATE_48M}, 1118c2ecf20Sopenharmony_ci /* MCS 22: SS 3, MOD: 64QAM, CR 3/4 */ 1128c2ecf20Sopenharmony_ci {175500, 364500, CEIL(175500 * 10, 9), CEIL(364500 * 10, 9), 0x9A, 1138c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 1148c2ecf20Sopenharmony_ci /* MCS 23: SS 3, MOD: 64QAM, CR 5/6 */ 1158c2ecf20Sopenharmony_ci {195000, 405000, CEIL(195000 * 10, 9), CEIL(405000 * 10, 9), 0x9B, 1168c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 1178c2ecf20Sopenharmony_ci /* MCS 24: SS 4, MOD: BPSK, CR 1/2 */ 1188c2ecf20Sopenharmony_ci {26000, 54000, CEIL(26000 * 10, 9), CEIL(54000 * 10, 9), 0xC0, 1198c2ecf20Sopenharmony_ci BRCM_RATE_6M}, 1208c2ecf20Sopenharmony_ci /* MCS 25: SS 4, MOD: QPSK, CR 1/2 */ 1218c2ecf20Sopenharmony_ci {52000, 108000, CEIL(52000 * 10, 9), CEIL(108000 * 10, 9), 0xC8, 1228c2ecf20Sopenharmony_ci BRCM_RATE_12M}, 1238c2ecf20Sopenharmony_ci /* MCS 26: SS 4, MOD: QPSK, CR 3/4 */ 1248c2ecf20Sopenharmony_ci {78000, 162000, CEIL(78000 * 10, 9), CEIL(162000 * 10, 9), 0xCA, 1258c2ecf20Sopenharmony_ci BRCM_RATE_18M}, 1268c2ecf20Sopenharmony_ci /* MCS 27: SS 4, MOD: 16QAM, CR 1/2 */ 1278c2ecf20Sopenharmony_ci {104000, 216000, CEIL(104000 * 10, 9), CEIL(216000 * 10, 9), 0xD0, 1288c2ecf20Sopenharmony_ci BRCM_RATE_24M}, 1298c2ecf20Sopenharmony_ci /* MCS 28: SS 4, MOD: 16QAM, CR 3/4 */ 1308c2ecf20Sopenharmony_ci {156000, 324000, CEIL(156000 * 10, 9), CEIL(324000 * 10, 9), 0xD2, 1318c2ecf20Sopenharmony_ci BRCM_RATE_36M}, 1328c2ecf20Sopenharmony_ci /* MCS 29: SS 4, MOD: 64QAM, CR 2/3 */ 1338c2ecf20Sopenharmony_ci {208000, 432000, CEIL(208000 * 10, 9), CEIL(432000 * 10, 9), 0xD9, 1348c2ecf20Sopenharmony_ci BRCM_RATE_48M}, 1358c2ecf20Sopenharmony_ci /* MCS 30: SS 4, MOD: 64QAM, CR 3/4 */ 1368c2ecf20Sopenharmony_ci {234000, 486000, CEIL(234000 * 10, 9), CEIL(486000 * 10, 9), 0xDA, 1378c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 1388c2ecf20Sopenharmony_ci /* MCS 31: SS 4, MOD: 64QAM, CR 5/6 */ 1398c2ecf20Sopenharmony_ci {260000, 540000, CEIL(260000 * 10, 9), CEIL(540000 * 10, 9), 0xDB, 1408c2ecf20Sopenharmony_ci BRCM_RATE_54M}, 1418c2ecf20Sopenharmony_ci /* MCS 32: SS 1, MOD: BPSK, CR 1/2 */ 1428c2ecf20Sopenharmony_ci {0, 6000, 0, CEIL(6000 * 10, 9), 0x00, BRCM_RATE_6M}, 1438c2ecf20Sopenharmony_ci}; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci/* 1468c2ecf20Sopenharmony_ci * phycfg for legacy OFDM frames: code rate, modulation scheme, spatial streams 1478c2ecf20Sopenharmony_ci * Number of spatial streams: always 1 other fields: refer to table 78 of 1488c2ecf20Sopenharmony_ci * section 17.3.2.2 of the original .11a standard 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_cistruct legacy_phycfg { 1518c2ecf20Sopenharmony_ci u32 rate_ofdm; /* ofdm mac rate */ 1528c2ecf20Sopenharmony_ci /* phy ctl byte 3, code rate, modulation type, # of streams */ 1538c2ecf20Sopenharmony_ci u8 tx_phy_ctl3; 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci/* Number of legacy_rate_cfg entries in the table */ 1578c2ecf20Sopenharmony_ci#define LEGACY_PHYCFG_TABLE_SIZE 12 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/* 1608c2ecf20Sopenharmony_ci * In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate 1618c2ecf20Sopenharmony_ci * Eventually MIMOPHY would also be converted to this format 1628c2ecf20Sopenharmony_ci * 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps 1638c2ecf20Sopenharmony_ci */ 1648c2ecf20Sopenharmony_cistatic const struct 1658c2ecf20Sopenharmony_cilegacy_phycfg legacy_phycfg_table[LEGACY_PHYCFG_TABLE_SIZE] = { 1668c2ecf20Sopenharmony_ci {BRCM_RATE_1M, 0x00}, /* CCK 1Mbps, data rate 0 */ 1678c2ecf20Sopenharmony_ci {BRCM_RATE_2M, 0x08}, /* CCK 2Mbps, data rate 1 */ 1688c2ecf20Sopenharmony_ci {BRCM_RATE_5M5, 0x10}, /* CCK 5.5Mbps, data rate 2 */ 1698c2ecf20Sopenharmony_ci {BRCM_RATE_11M, 0x18}, /* CCK 11Mbps, data rate 3 */ 1708c2ecf20Sopenharmony_ci /* OFDM 6Mbps, code rate 1/2, BPSK, 1 spatial stream */ 1718c2ecf20Sopenharmony_ci {BRCM_RATE_6M, 0x00}, 1728c2ecf20Sopenharmony_ci /* OFDM 9Mbps, code rate 3/4, BPSK, 1 spatial stream */ 1738c2ecf20Sopenharmony_ci {BRCM_RATE_9M, 0x02}, 1748c2ecf20Sopenharmony_ci /* OFDM 12Mbps, code rate 1/2, QPSK, 1 spatial stream */ 1758c2ecf20Sopenharmony_ci {BRCM_RATE_12M, 0x08}, 1768c2ecf20Sopenharmony_ci /* OFDM 18Mbps, code rate 3/4, QPSK, 1 spatial stream */ 1778c2ecf20Sopenharmony_ci {BRCM_RATE_18M, 0x0A}, 1788c2ecf20Sopenharmony_ci /* OFDM 24Mbps, code rate 1/2, 16-QAM, 1 spatial stream */ 1798c2ecf20Sopenharmony_ci {BRCM_RATE_24M, 0x10}, 1808c2ecf20Sopenharmony_ci /* OFDM 36Mbps, code rate 3/4, 16-QAM, 1 spatial stream */ 1818c2ecf20Sopenharmony_ci {BRCM_RATE_36M, 0x12}, 1828c2ecf20Sopenharmony_ci /* OFDM 48Mbps, code rate 2/3, 64-QAM, 1 spatial stream */ 1838c2ecf20Sopenharmony_ci {BRCM_RATE_48M, 0x19}, 1848c2ecf20Sopenharmony_ci /* OFDM 54Mbps, code rate 3/4, 64-QAM, 1 spatial stream */ 1858c2ecf20Sopenharmony_ci {BRCM_RATE_54M, 0x1A}, 1868c2ecf20Sopenharmony_ci}; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci/* Hardware rates (also encodes default basic rates) */ 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciconst struct brcms_c_rateset cck_ofdm_mimo_rates = { 1918c2ecf20Sopenharmony_ci 12, 1928c2ecf20Sopenharmony_ci /* 1b, 2b, 5.5b, 6, 9, 11b, 12, 18, 24, 36, 48, */ 1938c2ecf20Sopenharmony_ci { 0x82, 0x84, 0x8b, 0x0c, 0x12, 0x96, 0x18, 0x24, 0x30, 0x48, 0x60, 1948c2ecf20Sopenharmony_ci /* 54 Mbps */ 1958c2ecf20Sopenharmony_ci 0x6c}, 1968c2ecf20Sopenharmony_ci 0x00, 1978c2ecf20Sopenharmony_ci { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1988c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 1998c2ecf20Sopenharmony_ci}; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ciconst struct brcms_c_rateset ofdm_mimo_rates = { 2028c2ecf20Sopenharmony_ci 8, 2038c2ecf20Sopenharmony_ci /* 6b, 9, 12b, 18, 24b, 36, 48, 54 Mbps */ 2048c2ecf20Sopenharmony_ci { 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c}, 2058c2ecf20Sopenharmony_ci 0x00, 2068c2ecf20Sopenharmony_ci { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2078c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2088c2ecf20Sopenharmony_ci}; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* Default ratesets that include MCS32 for 40BW channels */ 2118c2ecf20Sopenharmony_cistatic const struct brcms_c_rateset cck_ofdm_40bw_mimo_rates = { 2128c2ecf20Sopenharmony_ci 12, 2138c2ecf20Sopenharmony_ci /* 1b, 2b, 5.5b, 6, 9, 11b, 12, 18, 24, 36, 48 */ 2148c2ecf20Sopenharmony_ci { 0x82, 0x84, 0x8b, 0x0c, 0x12, 0x96, 0x18, 0x24, 0x30, 0x48, 0x60, 2158c2ecf20Sopenharmony_ci /* 54 Mbps */ 2168c2ecf20Sopenharmony_ci 0x6c}, 2178c2ecf20Sopenharmony_ci 0x00, 2188c2ecf20Sopenharmony_ci { 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2198c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2208c2ecf20Sopenharmony_ci}; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic const struct brcms_c_rateset ofdm_40bw_mimo_rates = { 2238c2ecf20Sopenharmony_ci 8, 2248c2ecf20Sopenharmony_ci /* 6b, 9, 12b, 18, 24b, 36, 48, 54 Mbps */ 2258c2ecf20Sopenharmony_ci { 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c}, 2268c2ecf20Sopenharmony_ci 0x00, 2278c2ecf20Sopenharmony_ci { 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2288c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2298c2ecf20Sopenharmony_ci}; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ciconst struct brcms_c_rateset cck_ofdm_rates = { 2328c2ecf20Sopenharmony_ci 12, 2338c2ecf20Sopenharmony_ci /* 1b, 2b, 5.5b, 6, 9, 11b, 12, 18, 24, 36, 48,*/ 2348c2ecf20Sopenharmony_ci { 0x82, 0x84, 0x8b, 0x0c, 0x12, 0x96, 0x18, 0x24, 0x30, 0x48, 0x60, 2358c2ecf20Sopenharmony_ci /*54 Mbps */ 2368c2ecf20Sopenharmony_ci 0x6c}, 2378c2ecf20Sopenharmony_ci 0x00, 2388c2ecf20Sopenharmony_ci { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2398c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2408c2ecf20Sopenharmony_ci}; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ciconst struct brcms_c_rateset gphy_legacy_rates = { 2438c2ecf20Sopenharmony_ci 4, 2448c2ecf20Sopenharmony_ci /* 1b, 2b, 5.5b, 11b Mbps */ 2458c2ecf20Sopenharmony_ci { 0x82, 0x84, 0x8b, 0x96}, 2468c2ecf20Sopenharmony_ci 0x00, 2478c2ecf20Sopenharmony_ci { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2488c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2498c2ecf20Sopenharmony_ci}; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ciconst struct brcms_c_rateset ofdm_rates = { 2528c2ecf20Sopenharmony_ci 8, 2538c2ecf20Sopenharmony_ci /* 6b, 9, 12b, 18, 24b, 36, 48, 54 Mbps */ 2548c2ecf20Sopenharmony_ci { 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c}, 2558c2ecf20Sopenharmony_ci 0x00, 2568c2ecf20Sopenharmony_ci { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2578c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2588c2ecf20Sopenharmony_ci}; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ciconst struct brcms_c_rateset cck_rates = { 2618c2ecf20Sopenharmony_ci 4, 2628c2ecf20Sopenharmony_ci /* 1b, 2b, 5.5, 11 Mbps */ 2638c2ecf20Sopenharmony_ci { 0x82, 0x84, 0x0b, 0x16}, 2648c2ecf20Sopenharmony_ci 0x00, 2658c2ecf20Sopenharmony_ci { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 2668c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00} 2678c2ecf20Sopenharmony_ci}; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci/* check if rateset is valid. 2708c2ecf20Sopenharmony_ci * if check_brate is true, rateset without a basic rate is considered NOT valid. 2718c2ecf20Sopenharmony_ci */ 2728c2ecf20Sopenharmony_cistatic bool brcms_c_rateset_valid(struct brcms_c_rateset *rs, bool check_brate) 2738c2ecf20Sopenharmony_ci{ 2748c2ecf20Sopenharmony_ci uint idx; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci if (!rs->count) 2778c2ecf20Sopenharmony_ci return false; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci if (!check_brate) 2808c2ecf20Sopenharmony_ci return true; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci /* error if no basic rates */ 2838c2ecf20Sopenharmony_ci for (idx = 0; idx < rs->count; idx++) { 2848c2ecf20Sopenharmony_ci if (rs->rates[idx] & BRCMS_RATE_FLAG) 2858c2ecf20Sopenharmony_ci return true; 2868c2ecf20Sopenharmony_ci } 2878c2ecf20Sopenharmony_ci return false; 2888c2ecf20Sopenharmony_ci} 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_civoid brcms_c_rateset_mcs_upd(struct brcms_c_rateset *rs, u8 txstreams) 2918c2ecf20Sopenharmony_ci{ 2928c2ecf20Sopenharmony_ci int i; 2938c2ecf20Sopenharmony_ci for (i = txstreams; i < MAX_STREAMS_SUPPORTED; i++) 2948c2ecf20Sopenharmony_ci rs->mcs[i] = 0; 2958c2ecf20Sopenharmony_ci} 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci/* 2988c2ecf20Sopenharmony_ci * filter based on hardware rateset, and sort filtered rateset with basic 2998c2ecf20Sopenharmony_ci * bit(s) preserved, and check if resulting rateset is valid. 3008c2ecf20Sopenharmony_ci*/ 3018c2ecf20Sopenharmony_cibool 3028c2ecf20Sopenharmony_cibrcms_c_rate_hwrs_filter_sort_validate(struct brcms_c_rateset *rs, 3038c2ecf20Sopenharmony_ci const struct brcms_c_rateset *hw_rs, 3048c2ecf20Sopenharmony_ci bool check_brate, u8 txstreams) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci u8 rateset[BRCM_MAXRATE + 1]; 3078c2ecf20Sopenharmony_ci u8 r; 3088c2ecf20Sopenharmony_ci uint count; 3098c2ecf20Sopenharmony_ci uint i; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci memset(rateset, 0, sizeof(rateset)); 3128c2ecf20Sopenharmony_ci count = rs->count; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) { 3158c2ecf20Sopenharmony_ci /* mask off "basic rate" bit, BRCMS_RATE_FLAG */ 3168c2ecf20Sopenharmony_ci r = (int)rs->rates[i] & BRCMS_RATE_MASK; 3178c2ecf20Sopenharmony_ci if ((r > BRCM_MAXRATE) || (rate_info[r] == 0)) 3188c2ecf20Sopenharmony_ci continue; 3198c2ecf20Sopenharmony_ci rateset[r] = rs->rates[i]; /* preserve basic bit! */ 3208c2ecf20Sopenharmony_ci } 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci /* fill out the rates in order, looking at only supported rates */ 3238c2ecf20Sopenharmony_ci count = 0; 3248c2ecf20Sopenharmony_ci for (i = 0; i < hw_rs->count; i++) { 3258c2ecf20Sopenharmony_ci r = hw_rs->rates[i] & BRCMS_RATE_MASK; 3268c2ecf20Sopenharmony_ci if (rateset[r]) 3278c2ecf20Sopenharmony_ci rs->rates[count++] = rateset[r]; 3288c2ecf20Sopenharmony_ci } 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci rs->count = count; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci /* only set the mcs rate bit if the equivalent hw mcs bit is set */ 3338c2ecf20Sopenharmony_ci for (i = 0; i < MCSSET_LEN; i++) 3348c2ecf20Sopenharmony_ci rs->mcs[i] = (rs->mcs[i] & hw_rs->mcs[i]); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci if (brcms_c_rateset_valid(rs, check_brate)) 3378c2ecf20Sopenharmony_ci return true; 3388c2ecf20Sopenharmony_ci else 3398c2ecf20Sopenharmony_ci return false; 3408c2ecf20Sopenharmony_ci} 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci/* calculate the rate of a rx'd frame and return it as a ratespec */ 3438c2ecf20Sopenharmony_ciu32 brcms_c_compute_rspec(struct d11rxhdr *rxh, u8 *plcp) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci int phy_type; 3468c2ecf20Sopenharmony_ci u32 rspec = PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci phy_type = 3498c2ecf20Sopenharmony_ci ((rxh->RxChan & RXS_CHAN_PHYTYPE_MASK) >> RXS_CHAN_PHYTYPE_SHIFT); 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci if ((phy_type == PHY_TYPE_N) || (phy_type == PHY_TYPE_SSN) || 3528c2ecf20Sopenharmony_ci (phy_type == PHY_TYPE_LCN) || (phy_type == PHY_TYPE_HT)) { 3538c2ecf20Sopenharmony_ci switch (rxh->PhyRxStatus_0 & PRXS0_FT_MASK) { 3548c2ecf20Sopenharmony_ci case PRXS0_CCK: 3558c2ecf20Sopenharmony_ci rspec = 3568c2ecf20Sopenharmony_ci cck_phy2mac_rate( 3578c2ecf20Sopenharmony_ci ((struct cck_phy_hdr *) plcp)->signal); 3588c2ecf20Sopenharmony_ci break; 3598c2ecf20Sopenharmony_ci case PRXS0_OFDM: 3608c2ecf20Sopenharmony_ci rspec = 3618c2ecf20Sopenharmony_ci ofdm_phy2mac_rate( 3628c2ecf20Sopenharmony_ci ((struct ofdm_phy_hdr *) plcp)->rlpt[0]); 3638c2ecf20Sopenharmony_ci break; 3648c2ecf20Sopenharmony_ci case PRXS0_PREN: 3658c2ecf20Sopenharmony_ci rspec = (plcp[0] & MIMO_PLCP_MCS_MASK) | RSPEC_MIMORATE; 3668c2ecf20Sopenharmony_ci if (plcp[0] & MIMO_PLCP_40MHZ) { 3678c2ecf20Sopenharmony_ci /* indicate rspec is for 40 MHz mode */ 3688c2ecf20Sopenharmony_ci rspec &= ~RSPEC_BW_MASK; 3698c2ecf20Sopenharmony_ci rspec |= (PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT); 3708c2ecf20Sopenharmony_ci } 3718c2ecf20Sopenharmony_ci break; 3728c2ecf20Sopenharmony_ci case PRXS0_STDN: 3738c2ecf20Sopenharmony_ci /* fallthru */ 3748c2ecf20Sopenharmony_ci default: 3758c2ecf20Sopenharmony_ci /* not supported, error condition */ 3768c2ecf20Sopenharmony_ci break; 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci if (plcp3_issgi(plcp[3])) 3798c2ecf20Sopenharmony_ci rspec |= RSPEC_SHORT_GI; 3808c2ecf20Sopenharmony_ci } else 3818c2ecf20Sopenharmony_ci if ((phy_type == PHY_TYPE_A) || (rxh->PhyRxStatus_0 & PRXS0_OFDM)) 3828c2ecf20Sopenharmony_ci rspec = ofdm_phy2mac_rate( 3838c2ecf20Sopenharmony_ci ((struct ofdm_phy_hdr *) plcp)->rlpt[0]); 3848c2ecf20Sopenharmony_ci else 3858c2ecf20Sopenharmony_ci rspec = cck_phy2mac_rate( 3868c2ecf20Sopenharmony_ci ((struct cck_phy_hdr *) plcp)->signal); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci return rspec; 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/* copy rateset src to dst as-is (no masking or sorting) */ 3928c2ecf20Sopenharmony_civoid brcms_c_rateset_copy(const struct brcms_c_rateset *src, 3938c2ecf20Sopenharmony_ci struct brcms_c_rateset *dst) 3948c2ecf20Sopenharmony_ci{ 3958c2ecf20Sopenharmony_ci memcpy(dst, src, sizeof(struct brcms_c_rateset)); 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci/* 3998c2ecf20Sopenharmony_ci * Copy and selectively filter one rateset to another. 4008c2ecf20Sopenharmony_ci * 'basic_only' means only copy basic rates. 4018c2ecf20Sopenharmony_ci * 'rates' indicates cck (11b) and ofdm rates combinations. 4028c2ecf20Sopenharmony_ci * - 0: cck and ofdm 4038c2ecf20Sopenharmony_ci * - 1: cck only 4048c2ecf20Sopenharmony_ci * - 2: ofdm only 4058c2ecf20Sopenharmony_ci * 'xmask' is the copy mask (typically 0x7f or 0xff). 4068c2ecf20Sopenharmony_ci */ 4078c2ecf20Sopenharmony_civoid 4088c2ecf20Sopenharmony_cibrcms_c_rateset_filter(struct brcms_c_rateset *src, struct brcms_c_rateset *dst, 4098c2ecf20Sopenharmony_ci bool basic_only, u8 rates, uint xmask, bool mcsallow) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci uint i; 4128c2ecf20Sopenharmony_ci uint r; 4138c2ecf20Sopenharmony_ci uint count; 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci count = 0; 4168c2ecf20Sopenharmony_ci for (i = 0; i < src->count; i++) { 4178c2ecf20Sopenharmony_ci r = src->rates[i]; 4188c2ecf20Sopenharmony_ci if (basic_only && !(r & BRCMS_RATE_FLAG)) 4198c2ecf20Sopenharmony_ci continue; 4208c2ecf20Sopenharmony_ci if (rates == BRCMS_RATES_CCK && 4218c2ecf20Sopenharmony_ci is_ofdm_rate((r & BRCMS_RATE_MASK))) 4228c2ecf20Sopenharmony_ci continue; 4238c2ecf20Sopenharmony_ci if (rates == BRCMS_RATES_OFDM && 4248c2ecf20Sopenharmony_ci is_cck_rate((r & BRCMS_RATE_MASK))) 4258c2ecf20Sopenharmony_ci continue; 4268c2ecf20Sopenharmony_ci dst->rates[count++] = r & xmask; 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci dst->count = count; 4298c2ecf20Sopenharmony_ci dst->htphy_membership = src->htphy_membership; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci if (mcsallow && rates != BRCMS_RATES_CCK) 4328c2ecf20Sopenharmony_ci memcpy(&dst->mcs[0], &src->mcs[0], MCSSET_LEN); 4338c2ecf20Sopenharmony_ci else 4348c2ecf20Sopenharmony_ci brcms_c_rateset_mcs_clear(dst); 4358c2ecf20Sopenharmony_ci} 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci/* select rateset for a given phy_type and bandtype and filter it, sort it 4388c2ecf20Sopenharmony_ci * and fill rs_tgt with result 4398c2ecf20Sopenharmony_ci */ 4408c2ecf20Sopenharmony_civoid 4418c2ecf20Sopenharmony_cibrcms_c_rateset_default(struct brcms_c_rateset *rs_tgt, 4428c2ecf20Sopenharmony_ci const struct brcms_c_rateset *rs_hw, 4438c2ecf20Sopenharmony_ci uint phy_type, int bandtype, bool cck_only, 4448c2ecf20Sopenharmony_ci uint rate_mask, bool mcsallow, u8 bw, u8 txstreams) 4458c2ecf20Sopenharmony_ci{ 4468c2ecf20Sopenharmony_ci const struct brcms_c_rateset *rs_dflt; 4478c2ecf20Sopenharmony_ci struct brcms_c_rateset rs_sel; 4488c2ecf20Sopenharmony_ci if ((PHYTYPE_IS(phy_type, PHY_TYPE_HT)) || 4498c2ecf20Sopenharmony_ci (PHYTYPE_IS(phy_type, PHY_TYPE_N)) || 4508c2ecf20Sopenharmony_ci (PHYTYPE_IS(phy_type, PHY_TYPE_LCN)) || 4518c2ecf20Sopenharmony_ci (PHYTYPE_IS(phy_type, PHY_TYPE_SSN))) { 4528c2ecf20Sopenharmony_ci if (bandtype == BRCM_BAND_5G) 4538c2ecf20Sopenharmony_ci rs_dflt = (bw == BRCMS_20_MHZ ? 4548c2ecf20Sopenharmony_ci &ofdm_mimo_rates : &ofdm_40bw_mimo_rates); 4558c2ecf20Sopenharmony_ci else 4568c2ecf20Sopenharmony_ci rs_dflt = (bw == BRCMS_20_MHZ ? 4578c2ecf20Sopenharmony_ci &cck_ofdm_mimo_rates : 4588c2ecf20Sopenharmony_ci &cck_ofdm_40bw_mimo_rates); 4598c2ecf20Sopenharmony_ci } else if (PHYTYPE_IS(phy_type, PHY_TYPE_LP)) { 4608c2ecf20Sopenharmony_ci rs_dflt = (bandtype == BRCM_BAND_5G) ? 4618c2ecf20Sopenharmony_ci &ofdm_rates : &cck_ofdm_rates; 4628c2ecf20Sopenharmony_ci } else if (PHYTYPE_IS(phy_type, PHY_TYPE_A)) { 4638c2ecf20Sopenharmony_ci rs_dflt = &ofdm_rates; 4648c2ecf20Sopenharmony_ci } else if (PHYTYPE_IS(phy_type, PHY_TYPE_G)) { 4658c2ecf20Sopenharmony_ci rs_dflt = &cck_ofdm_rates; 4668c2ecf20Sopenharmony_ci } else { 4678c2ecf20Sopenharmony_ci /* should not happen, error condition */ 4688c2ecf20Sopenharmony_ci rs_dflt = &cck_rates; /* force cck */ 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci /* if hw rateset is not supplied, assign selected rateset to it */ 4728c2ecf20Sopenharmony_ci if (!rs_hw) 4738c2ecf20Sopenharmony_ci rs_hw = rs_dflt; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci brcms_c_rateset_copy(rs_dflt, &rs_sel); 4768c2ecf20Sopenharmony_ci brcms_c_rateset_mcs_upd(&rs_sel, txstreams); 4778c2ecf20Sopenharmony_ci brcms_c_rateset_filter(&rs_sel, rs_tgt, false, 4788c2ecf20Sopenharmony_ci cck_only ? BRCMS_RATES_CCK : BRCMS_RATES_CCK_OFDM, 4798c2ecf20Sopenharmony_ci rate_mask, mcsallow); 4808c2ecf20Sopenharmony_ci brcms_c_rate_hwrs_filter_sort_validate(rs_tgt, rs_hw, false, 4818c2ecf20Sopenharmony_ci mcsallow ? txstreams : 1); 4828c2ecf20Sopenharmony_ci} 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_cis16 brcms_c_rate_legacy_phyctl(uint rate) 4858c2ecf20Sopenharmony_ci{ 4868c2ecf20Sopenharmony_ci uint i; 4878c2ecf20Sopenharmony_ci for (i = 0; i < LEGACY_PHYCFG_TABLE_SIZE; i++) 4888c2ecf20Sopenharmony_ci if (rate == legacy_phycfg_table[i].rate_ofdm) 4898c2ecf20Sopenharmony_ci return legacy_phycfg_table[i].tx_phy_ctl3; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci return -1; 4928c2ecf20Sopenharmony_ci} 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_civoid brcms_c_rateset_mcs_clear(struct brcms_c_rateset *rateset) 4958c2ecf20Sopenharmony_ci{ 4968c2ecf20Sopenharmony_ci uint i; 4978c2ecf20Sopenharmony_ci for (i = 0; i < MCSSET_LEN; i++) 4988c2ecf20Sopenharmony_ci rateset->mcs[i] = 0; 4998c2ecf20Sopenharmony_ci} 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_civoid brcms_c_rateset_mcs_build(struct brcms_c_rateset *rateset, u8 txstreams) 5028c2ecf20Sopenharmony_ci{ 5038c2ecf20Sopenharmony_ci memcpy(&rateset->mcs[0], &cck_ofdm_mimo_rates.mcs[0], MCSSET_LEN); 5048c2ecf20Sopenharmony_ci brcms_c_rateset_mcs_upd(rateset, txstreams); 5058c2ecf20Sopenharmony_ci} 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci/* Based on bandwidth passed, allow/disallow MCS 32 in the rateset */ 5088c2ecf20Sopenharmony_civoid brcms_c_rateset_bw_mcs_filter(struct brcms_c_rateset *rateset, u8 bw) 5098c2ecf20Sopenharmony_ci{ 5108c2ecf20Sopenharmony_ci if (bw == BRCMS_40_MHZ) 5118c2ecf20Sopenharmony_ci setbit(rateset->mcs, 32); 5128c2ecf20Sopenharmony_ci else 5138c2ecf20Sopenharmony_ci clrbit(rateset->mcs, 32); 5148c2ecf20Sopenharmony_ci} 515