wireless: cl8k driver for Celeno IEEE 802.11ax devices
RFC v2 65/96 cl8k: add reg/reg_defs.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- .../net/wireless/celeno/cl8k/reg/reg_defs.h | 5494 +++++++++++++++++ 1 file changed, 5494 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/reg/reg_defs.h
drivers/net/wireless/celeno/cl8k/reg/reg_defs.h new file +5494 -0
@@ -0,0 +1,5494 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_REG_DEFS_H +#define CL_REG_DEFS_H + +#include <linux/types.h> +#include "reg/reg_access.h" +#include "hw.h" +#include "chip.h" + +#define CEVA_MCCI_BASE_ADDR 0x004B0000 + +#define CEVA_CORE_VERSION_ADDR (CEVA_MCCI_BASE_ADDR + 0x1000) +#define CEVA_CORE_ID_ADDR (CEVA_MCCI_BASE_ADDR + 0x1004) + +#define CEVA_CPM_BASE_ADDR (CEVA_MCCI_BASE_ADDR + 0x2000) + +/* PDMA */ +#define CEVA_CPM_PDEA_REG (CEVA_CPM_BASE_ADDR + 0x0008)/* External */ +#define CEVA_CPM_PDIA_REG (CEVA_CPM_BASE_ADDR + 0x000C)/* Internal */ +#define CEVA_CPM_PDTC_REG (CEVA_CPM_BASE_ADDR + 0x0010)/* Control */ + +/* DDMA */ +#define CEVA_CPM_DDEA_REG (CEVA_CPM_BASE_ADDR + 0x001c)/* External */ +#define CEVA_CPM_DDIA_REG (CEVA_CPM_BASE_ADDR + 0x0020)/* Internal */ +#define CEVA_CPM_DDTC_REG (CEVA_CPM_BASE_ADDR + 0x0024)/* Control */ + +#define CEVA_CPM_DDTC_WRITE_COMMAND 0x40000000 + +/* Translated internally to 0x60600000. */ +#define CEVA_SHARED_PMEM_BASE_ADDR_FROM_HOST 0x004C0000 + +/* Internal address to access Shared */ +#define CEVA_SHARED_PMEM_BASE_ADDR_INTERNAL 0x60600000/* PMEM */ +#define CEVA_SHARED_XMEM_BASE_ADDR_INTERNAL 0x60900000/* XMEM */ + +#define CEVA_DSP_DATA_SIZE 0x80000/* 512kB. */ +#define CEVA_DSP_EXT_DATA_SIZE 0x60000/* 384kB. */ + +/* 512kb */ +#define CEVA_INTERNAL_PMEM_SIZE 0x80000 + +#define CEVA_SHARED_PMEM_SIZE 0x20000/* 128kb */ +#define CEVA_SHARED_XMEM_SIZE 0x60000/* 384kB */ + +#define CEVA_MAX_PAGES (CEVA_INTERNAL_PMEM_SIZE / CEVA_SHARED_PMEM_SIZE) + +#define CEVA_SHARED_PMEM_CACHE_SIZE 0x8000/* 32kb */ + +#define REG_CMU_BASE_ADDR 0x007C6000 + +/* +* @brief CMU_CLK_EN register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 spare_afe_gnrl_en 0 +* 30 spare_sys_gnrl_en 0 +* 27 spare_riu44_clk_en 0 +* 26 spare_riu_clk_en 0 +* 25 spare_riu2x_clk_en 0 +* 24 spare_riu4x_clk_en 0 +* 23 spare_phy_clk_en 0 +* 22 spare_phy2x_clk_en 0 +* 21 spare_sysx_clk_en 0 +* 20 spare_sys2x_clk_en 0 +* 19 ricu_clk_en 0 +* 05 smac_proc_clk_en 1 +* 04 umac_proc_clk_en 1 +* 03 lmac_proc_clk_en 1 +* </pre> +*/ +#define CMU_CLK_EN_ADDR (REG_CMU_BASE_ADDR + 0x00000000) +#define CMU_CLK_EN_OFFSET 0x00000000 +#define CMU_CLK_EN_INDEX 0x00000000 +#define CMU_CLK_EN_RESET 0x00000038 + +static inline void cmu_clk_en_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,CMU_CLK_EN_ADDR , value); +} + +/* Field definitions */ +#define CMU_SPARE_AFE_GNRL_EN_BIT ((u32)0x80000000) +#define CMU_SPARE_AFE_GNRL_EN_POS 31 +#define CMU_SPARE_SYS_GNRL_EN_BIT ((u32)0x40000000) +#define CMU_SPARE_SYS_GNRL_EN_POS 30 +#define CMU_SPARE_RIU_44_CLK_EN_BIT ((u32)0x08000000) +#define CMU_SPARE_RIU_44_CLK_EN_POS 27 +#define CMU_SPARE_RIU_CLK_EN_BIT ((u32)0x04000000) +#define CMU_SPARE_RIU_CLK_EN_POS 26 +#define CMU_SPARE_RIU_2_X_CLK_EN_BIT ((u32)0x02000000) +#define CMU_SPARE_RIU_2_X_CLK_EN_POS 25 +#define CMU_SPARE_RIU_4_X_CLK_EN_BIT ((u32)0x01000000) +#define CMU_SPARE_RIU_4_X_CLK_EN_POS 24 +#define CMU_SPARE_PHY_CLK_EN_BIT ((u32)0x00800000) +#define CMU_SPARE_PHY_CLK_EN_POS 23 +#define CMU_SPARE_PHY_2_X_CLK_EN_BIT ((u32)0x00400000) +#define CMU_SPARE_PHY_2_X_CLK_EN_POS 22 +#define CMU_SPARE_SYSX_CLK_EN_BIT ((u32)0x00200000) +#define CMU_SPARE_SYSX_CLK_EN_POS 21 +#define CMU_SPARE_SYS_2_X_CLK_EN_BIT ((u32)0x00100000) +#define CMU_SPARE_SYS_2_X_CLK_EN_POS 20 +#define CMU_RICU_CLK_EN_BIT ((u32)0x00080000) +#define CMU_RICU_CLK_EN_POS 19 +#define CMU_SMAC_PROC_CLK_EN_BIT ((u32)0x00000020) +#define CMU_SMAC_PROC_CLK_EN_POS 5 +#define CMU_UMAC_PROC_CLK_EN_BIT ((u32)0x00000010) +#define CMU_UMAC_PROC_CLK_EN_POS 4 +#define CMU_LMAC_PROC_CLK_EN_BIT ((u32)0x00000008) +#define CMU_LMAC_PROC_CLK_EN_POS 3 + +#define CMU_MAC_ALL_CLK_EN (CMU_RICU_CLK_EN_BIT | \ + CMU_SMAC_PROC_CLK_EN_BIT | \ + CMU_UMAC_PROC_CLK_EN_BIT | \ + CMU_LMAC_PROC_CLK_EN_BIT) + +/* +* @brief CMU_PHY_0_CLK_EN register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 02 ceva0_clk_en 0 +* 01 phy0_apb_clk_en 0 +* 00 phy0_main_clk_en 0 +* </pre> +*/ +#define CMU_PHY_0_CLK_EN_ADDR (REG_CMU_BASE_ADDR + 0x00000004) +#define CMU_PHY_0_CLK_EN_OFFSET 0x00000004 +#define CMU_PHY_0_CLK_EN_INDEX 0x00000001 +#define CMU_PHY_0_CLK_EN_RESET 0x00000000 + +static inline void cmu_phy_0_clk_en_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,CMU_PHY_0_CLK_EN_ADDR , value); +} + +/* Field definitions */ +#define CMU_CEVA_0_CLK_EN_BIT ((u32)0x00000004) +#define CMU_CEVA_0_CLK_EN_POS 2 +#define CMU_PHY_0_APB_CLK_EN_BIT ((u32)0x00000002) +#define CMU_PHY_0_APB_CLK_EN_POS 1 +#define CMU_PHY_0_MAIN_CLK_EN_BIT ((u32)0x00000001) +#define CMU_PHY_0_MAIN_CLK_EN_POS 0 + +#define CMU_PHY0_CLK_EN (CMU_CEVA_0_CLK_EN_BIT | \ + CMU_PHY_0_APB_CLK_EN_BIT | \ + CMU_PHY_0_MAIN_CLK_EN_BIT) + +static inline void cmu_phy_0_clk_en_pack (struct cl_chip *chip,u8 ceva0clken, +u8 phy0apbclken,u8 phy0mainclken) +{ +ASSERT_ERR_CHIP ((((u32 )ceva0clken <<2 ) & ~((u32 )0x00000004 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )phy0apbclken <<1 ) & ~((u32 )0x00000002 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )phy0mainclken <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_0_CLK_EN_ADDR , + ((u32 )ceva0clken <<2 ) | ((u32 )phy0apbclken <<1 ) | + ((u32 )phy0mainclken <<0 )); +} + +static inline void cmu_phy_0_clk_en_ceva_0_clk_en_setf (struct cl_chip *chip,u8 ceva0clken) +{ +ASSERT_ERR_CHIP ((((u32 )ceva0clken <<2 ) & ~((u32 )0x00000004 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_0_CLK_EN_ADDR , + (cl_reg_read_chip (chip,CMU_PHY_0_CLK_EN_ADDR ) & ~((u32 )0x00000004 )) | + ((u32 )ceva0clken <<2 )); +} + +static inline void cmu_phy_0_clk_en_phy_0_apb_clk_en_setf (struct cl_chip *chip,u8 phy0apbclken) +{ +ASSERT_ERR_CHIP ((((u32 )phy0apbclken <<1 ) & ~((u32 )0x00000002 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_0_CLK_EN_ADDR , + (cl_reg_read_chip (chip,CMU_PHY_0_CLK_EN_ADDR ) & ~((u32 )0x00000002 )) | + ((u32 )phy0apbclken <<1 )); +} + +/* +* @brief CMU_PHY_1_CLK_EN register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 02 ceva1_clk_en 0 +* 01 phy1_apb_clk_en 0 +* 00 phy1_main_clk_en 0 +* </pre> +*/ +#define CMU_PHY_1_CLK_EN_ADDR (REG_CMU_BASE_ADDR + 0x00000008) +#define CMU_PHY_1_CLK_EN_OFFSET 0x00000008 +#define CMU_PHY_1_CLK_EN_INDEX 0x00000002 +#define CMU_PHY_1_CLK_EN_RESET 0x00000000 + +static inline void cmu_phy_1_clk_en_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,CMU_PHY_1_CLK_EN_ADDR , value); +} + +/* Field definitions */ +#define CMU_CEVA_1_CLK_EN_BIT ((u32)0x00000004) +#define CMU_CEVA_1_CLK_EN_POS 2 +#define CMU_PHY_1_APB_CLK_EN_BIT ((u32)0x00000002) +#define CMU_PHY_1_APB_CLK_EN_POS 1 +#define CMU_PHY_1_MAIN_CLK_EN_BIT ((u32)0x00000001) +#define CMU_PHY_1_MAIN_CLK_EN_POS 0 + +#define CMU_PHY1_CLK_EN (CMU_CEVA_1_CLK_EN_BIT | \ + CMU_PHY_1_APB_CLK_EN_BIT | \ + CMU_PHY_1_MAIN_CLK_EN_BIT) + +static inline void cmu_phy_1_clk_en_pack (struct cl_chip *chip,u8 ceva1clken, +u8 phy1apbclken,u8 phy1mainclken) +{ +ASSERT_ERR_CHIP ((((u32 )ceva1clken <<2 ) & ~((u32 )0x00000004 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )phy1apbclken <<1 ) & ~((u32 )0x00000002 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )phy1mainclken <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_1_CLK_EN_ADDR , + ((u32 )ceva1clken <<2 ) | ((u32 )phy1apbclken <<1 ) | + ((u32 )phy1mainclken <<0 )); +} + +static inline void cmu_phy_1_clk_en_ceva_1_clk_en_setf (struct cl_chip *chip,u8 ceva1clken) +{ +ASSERT_ERR_CHIP ((((u32 )ceva1clken <<2 ) & ~((u32 )0x00000004 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_1_CLK_EN_ADDR , + (cl_reg_read_chip (chip,CMU_PHY_1_CLK_EN_ADDR ) & ~((u32 )0x00000004 )) | + ((u32 )ceva1clken <<2 )); +} + +static inline void cmu_phy_1_clk_en_phy_1_apb_clk_en_setf (struct cl_chip *chip,u8 phy1apbclken) +{ +ASSERT_ERR_CHIP ((((u32 )phy1apbclken <<1 ) & ~((u32 )0x00000002 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_1_CLK_EN_ADDR , + (cl_reg_read_chip (chip,CMU_PHY_1_CLK_EN_ADDR ) & ~((u32 )0x00000002 )) | + ((u32 )phy1apbclken <<1 )); +} + +/* +* @brief CMU_CONTROL register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 gl_mux_sel 0 +* </pre> +*/ +#define CMU_CONTROL_ADDR (REG_CMU_BASE_ADDR + 0x0000000C) +#define CMU_CONTROL_OFFSET 0x0000000C +#define CMU_CONTROL_INDEX 0x00000003 +#define CMU_CONTROL_RESET 0x00000000 + +static inline void cmu_control_gl_mux_sel_setf (struct cl_chip *chip,u8 glmuxsel) +{ +ASSERT_ERR_CHIP ((((u32 )glmuxsel <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write_chip (chip,CMU_CONTROL_ADDR , (u32 )glmuxsel <<0 ); +} + +/* +* @brief CMU_RST register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 18 spare_riu44_reset_n 0 +* 17 spare_modem_reset_n 0 +* 16 spare_sys_reset_n 0 +* 15 n_RICURst 1 +* </pre> +*/ +#define CMU_RST_ADDR (REG_CMU_BASE_ADDR + 0x00000010) +#define CMU_RST_OFFSET 0x00000010 +#define CMU_RST_INDEX 0x00000004 +#define CMU_RST_RESET 0x0000FF80 + +static inline void cmu_rst_n_ricurst_setf (struct cl_chip *chip,u8 nricurst) +{ +ASSERT_ERR_CHIP ((((u32 )nricurst <<15 ) & ~((u32 )0x00008000 )) ==0 ); +cl_reg_write_chip (chip,CMU_RST_ADDR , + (cl_reg_read_chip (chip,CMU_RST_ADDR ) & ~((u32 )0x00008000 )) | + ((u32 )nricurst <<15 )); +} + +/* +* @brief CMU_PHY_0_RST register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 03 ceva0_global_rst_n 1 +* 02 mpif0_rst_n 1 +* 01 phy0_preset_n 1 +* 00 phy0_rst_n 1 +* </pre> +*/ +#define CMU_PHY_0_RST_ADDR (REG_CMU_BASE_ADDR + 0x00000014) +#define CMU_PHY_0_RST_OFFSET 0x00000014 +#define CMU_PHY_0_RST_INDEX 0x00000005 +#define CMU_PHY_0_RST_RESET 0x0000000F + +static inline void cmu_phy_0_rst_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,CMU_PHY_0_RST_ADDR , value); +} + +/* Field definitions */ +#define CMU_CEVA_0_GLOBAL_RST_N_BIT ((u32)0x00000008) +#define CMU_CEVA_0_GLOBAL_RST_N_POS 3 +#define CMU_MPIF_0_RST_N_BIT ((u32)0x00000004) +#define CMU_MPIF_0_RST_N_POS 2 +#define CMU_PHY_0_PRESET_N_BIT ((u32)0x00000002) +#define CMU_PHY_0_PRESET_N_POS 1 +#define CMU_PHY_0_RST_N_BIT ((u32)0x00000001) +#define CMU_PHY_0_RST_N_POS 0 + +#define CMU_PHY0_RST_EN (CMU_PHY_0_PRESET_N_BIT | \ + CMU_MPIF_0_RST_N_BIT | \ + CMU_PHY_0_RST_N_BIT | \ + CMU_CEVA_0_GLOBAL_RST_N_BIT) + +static inline void cmu_phy_0_rst_ceva_0_global_rst_n_setf (struct cl_chip *chip,u8 ceva0globalrstn) +{ +ASSERT_ERR_CHIP ((((u32 )ceva0globalrstn <<3 ) & ~((u32 )0x00000008 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_0_RST_ADDR , + (cl_reg_read_chip (chip,CMU_PHY_0_RST_ADDR ) & ~((u32 )0x00000008 )) | + ((u32 )ceva0globalrstn <<3 )); +} + +/* +* @brief CMU_PHY_1_RST register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 03 ceva1_global_rst_n 1 +* 02 mpif1_rst_n 1 +* 01 phy1_preset_n 1 +* 00 phy1_rst_n 1 +* </pre> +*/ +#define CMU_PHY_1_RST_ADDR (REG_CMU_BASE_ADDR + 0x00000018) +#define CMU_PHY_1_RST_OFFSET 0x00000018 +#define CMU_PHY_1_RST_INDEX 0x00000006 +#define CMU_PHY_1_RST_RESET 0x0000000F + +static inline void cmu_phy_1_rst_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,CMU_PHY_1_RST_ADDR , value); +} + +/* Field definitions */ +#define CMU_CEVA_1_GLOBAL_RST_N_BIT ((u32)0x00000008) +#define CMU_CEVA_1_GLOBAL_RST_N_POS 3 +#define CMU_MPIF_1_RST_N_BIT ((u32)0x00000004) +#define CMU_MPIF_1_RST_N_POS 2 +#define CMU_PHY_1_PRESET_N_BIT ((u32)0x00000002) +#define CMU_PHY_1_PRESET_N_POS 1 +#define CMU_PHY_1_RST_N_BIT ((u32)0x00000001) +#define CMU_PHY_1_RST_N_POS 0 + +#define CMU_PHY1_RST_EN (CMU_PHY_1_PRESET_N_BIT | \ + CMU_MPIF_1_RST_N_BIT | \ + CMU_PHY_1_RST_N_BIT | \ + CMU_CEVA_1_GLOBAL_RST_N_BIT) + +static inline void cmu_phy_1_rst_ceva_1_global_rst_n_setf (struct cl_chip *chip,u8 ceva1globalrstn) +{ +ASSERT_ERR_CHIP ((((u32 )ceva1globalrstn <<3 ) & ~((u32 )0x00000008 )) ==0 ); +cl_reg_write_chip (chip,CMU_PHY_1_RST_ADDR , + (cl_reg_read_chip (chip,CMU_PHY_1_RST_ADDR ) & ~((u32 )0x00000008 )) | + ((u32 )ceva1globalrstn <<3 )); +} + +/* +* @brief CMU_PLL_0_STAT register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 pll_lock 0 +* </pre> +*/ +#define CMU_PLL_0_STAT_ADDR (REG_CMU_BASE_ADDR + 0x00000040) +#define CMU_PLL_0_STAT_OFFSET 0x00000040 +#define CMU_PLL_0_STAT_INDEX 0x00000010 +#define CMU_PLL_0_STAT_RESET 0x00000000 + +static inline u8 cmu_pll_0_stat_pll_lock_getf (struct cl_chip *chip) +{ +u32 local_val =cl_reg_read_chip (chip,CMU_PLL_0_STAT_ADDR ); + +ASSERT_ERR_CHIP ((local_val & ~((u32 )0x80000000 )) ==0 ); +return (local_val >>31 ); +} + +/* +* @brief CMU_PLL_1_STAT register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 pll_lock 0 +* </pre> +*/ +#define CMU_PLL_1_STAT_ADDR (REG_CMU_BASE_ADDR + 0x00000050) +#define CMU_PLL_1_STAT_OFFSET 0x00000050 +#define CMU_PLL_1_STAT_INDEX 0x00000014 +#define CMU_PLL_1_STAT_RESET 0x00000000 + +static inline u8 cmu_pll_1_stat_pll_lock_getf (struct cl_chip *chip) +{ +u32 local_val =cl_reg_read_chip (chip,CMU_PLL_1_STAT_ADDR ); + +ASSERT_ERR_CHIP ((local_val & ~((u32 )0x80000000 )) ==0 ); +return (local_val >>31 ); +} + +/* +* @brief CMU_PHASE_SEL register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 20 gp_clk_phase_sel 1 +* 19 dac_cdb_clk_phase_sel 0 +* 18 adc_cdb_clk_phase_sel 0 +* 17 dac_clk_phase_sel 0 +* 16 adc_clk_phase_sel 0 +* </pre> +*/ +#define CMU_PHASE_SEL_ADDR (REG_CMU_BASE_ADDR + 0x00000060) +#define CMU_PHASE_SEL_OFFSET 0x00000060 +#define CMU_PHASE_SEL_INDEX 0x00000018 +#define CMU_PHASE_SEL_RESET 0x00100000 + +static inline void cmu_phase_sel_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,CMU_PHASE_SEL_ADDR , value); +} + +/* Field definitions */ +#define CMU_GP_CLK_PHASE_SEL_BIT ((u32)0x00100000) +#define CMU_GP_CLK_PHASE_SEL_POS 20 +#define CMU_DAC_CDB_CLK_PHASE_SEL_BIT ((u32)0x00080000) +#define CMU_DAC_CDB_CLK_PHASE_SEL_POS 19 +#define CMU_ADC_CDB_CLK_PHASE_SEL_BIT ((u32)0x00040000) +#define CMU_ADC_CDB_CLK_PHASE_SEL_POS 18 +#define CMU_DAC_CLK_PHASE_SEL_BIT ((u32)0x00020000) +#define CMU_DAC_CLK_PHASE_SEL_POS 17 +#define CMU_ADC_CLK_PHASE_SEL_BIT ((u32)0x00010000) +#define CMU_ADC_CLK_PHASE_SEL_POS 16 + +struct cl_fem_lna_enable_gpio { +union { +struct { +#ifdef __LITTLE_ENDIAN_BITFIELD +u16 b0 :1 , + b1 :1 , + b2 :1 , + b3 :1 , + b4 :1 , + b5 :1 , + b6 :1 , + b7 :1 , + b8 :1 , + b9 :1 , + b10 :1 , + b11 :1 , + rsv :4 ; +#else /* __BIG_ENDIAN_BITFIELD */ +u16 rsv :4 , + b11 :1 , + b10 :1 , + b9 :1 , + b8 :1 , + b7 :1 , + b6 :1 , + b5 :1 , + b4 :1 , + b3 :1 , + b2 :1 , + b1 :1 , + b0 :1 ; +#endif + } bits; +u16 val; + }; +}; + +struct cl_fem_pa_enable_gpio { +union { +struct { +#ifdef __LITTLE_ENDIAN_BITFIELD +u16 b0 :1 , + b1 :1 , + b2 :1 , + b3 :1 , + b4 :1 , + b5 :1 , + b6 :1 , + b7 :1 , + b8 :1 , + b9 :1 , + b10 :1 , + b11 :1 , + rsv :4 ; +#else /* __BIG_ENDIAN_BITFIELD */ +u16 rsv :4 , + b11 :1 , + b10 :1 , + b9 :1 , + b8 :1 , + b7 :1 , + b6 :1 , + b5 :1 , + b4 :1 , + b3 :1 , + b2 :1 , + b1 :1 , + b0 :1 ; +#endif + } bits; +u16 val; + }; +}; + +struct cl_fem_rx_active_gpio { +union { +struct { +#ifdef __LITTLE_ENDIAN_BITFIELD +u8 b0 :1 , + b1 :1 , + b2 :1 , + b3 :1 , + b4 :1 , + b5 :1 , + b6 :1 , + b7 :1 ; +#else /* __BIG_ENDIAN_BITFIELD */ +u8 b7 :1 , + b6 :1 , + b5 :1 , + b4 :1 , + b3 :1 , + b2 :1 , + b1 :1 , + b0 :1 ; +#endif + } bits; +u8 val; + }; +}; + +#define EXTRACT_BYPASS_LUT (lut) ((lut) & 0x7) +#define FEM_LUT_MASK 0x7777 + +#define PA_ENABLE_POS 0 +#define LNA_ENABLE_POS 1 +#define RX_ACTIVE_POS 2 +#define GET_BIT (reg, pos) (((reg) >> (pos)) & 0x1) + +#define LNA_ENABLE_GPIO_OUT_CFG (val) \ + (((1 << IO_CTRL_LNA_ENABLE_0_GPIO_ENABLE_POS) & IO_CTRL_LNA_ENABLE_0_GPIO_ENABLE_BIT) | \ + ((1 << IO_CTRL_LNA_ENABLE_0_GPIO_OE_POS) & IO_CTRL_LNA_ENABLE_0_GPIO_OE_BIT) | \ + (((u32)(val) << IO_CTRL_LNA_ENABLE_0_GPIO_OUT_POS) & IO_CTRL_LNA_ENABLE_0_GPIO_OUT_BIT)) +#define PA_ENABLE_GPIO_OUT_CFG (val) \ + (((1 << IO_CTRL_PA_ENABLE_0_GPIO_ENABLE_POS) & IO_CTRL_PA_ENABLE_0_GPIO_ENABLE_BIT) | \ + ((1 << IO_CTRL_PA_ENABLE_0_GPIO_OE_POS) & IO_CTRL_PA_ENABLE_0_GPIO_OE_BIT) | \ + (((u32)(val) << IO_CTRL_PA_ENABLE_0_GPIO_OUT_POS) & IO_CTRL_PA_ENABLE_0_GPIO_OUT_BIT)) +#define RX_ACTIVE_GPIO_OUT_CFG (val) \ + (((1 << IO_CTRL_RX_ACTIVE_0_GPIO_ENABLE_POS) & IO_CTRL_RX_ACTIVE_0_GPIO_ENABLE_BIT) | \ + ((1 << IO_CTRL_RX_ACTIVE_0_GPIO_OE_POS) & IO_CTRL_RX_ACTIVE_0_GPIO_OE_BIT) | \ + (((u32)(val) << IO_CTRL_RX_ACTIVE_0_GPIO_OUT_POS) & IO_CTRL_RX_ACTIVE_0_GPIO_OUT_BIT)) + +#define REG_IPC_BASE_ADDR 0x007C4000 + +/* +* @brief XMAC_2_HOST_RAW_STATUS register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 xmac2host_raw_status 0x0 +* </pre> +*/ +#define IPC_XMAC_2_HOST_RAW_STATUS_ADDR (REG_IPC_BASE_ADDR + 0x00000004) +#define IPC_XMAC_2_HOST_RAW_STATUS_OFFSET 0x00000004 +#define IPC_XMAC_2_HOST_RAW_STATUS_INDEX 0x00000001 +#define IPC_XMAC_2_HOST_RAW_STATUS_RESET 0x00000000 + +static inline u32 ipc_xmac_2_host_raw_status_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,IPC_XMAC_2_HOST_RAW_STATUS_ADDR ); +} + +/* +* @brief XMAC_2_HOST_ACK register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 xmac2host_trigger_clr 0x0 +* </pre> +*/ +#define IPC_XMAC_2_HOST_ACK_ADDR (REG_IPC_BASE_ADDR + 0x00000008) +#define IPC_XMAC_2_HOST_ACK_OFFSET 0x00000008 +#define IPC_XMAC_2_HOST_ACK_INDEX 0x00000002 +#define IPC_XMAC_2_HOST_ACK_RESET 0x00000000 + +static inline void ipc_xmac_2_host_ack_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_XMAC_2_HOST_ACK_ADDR , value); +} + +/* +* @brief XMAC_2_HOST_ENABLE_SET register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 xmac2host_enable_set 0x0 +* </pre> +*/ +#define IPC_XMAC_2_HOST_ENABLE_SET_ADDR (REG_IPC_BASE_ADDR + 0x0000000C) +#define IPC_XMAC_2_HOST_ENABLE_SET_OFFSET 0x0000000C +#define IPC_XMAC_2_HOST_ENABLE_SET_INDEX 0x00000003 +#define IPC_XMAC_2_HOST_ENABLE_SET_RESET 0x00000000 + +static inline void ipc_xmac_2_host_enable_set_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_XMAC_2_HOST_ENABLE_SET_ADDR , value); +} + +/* +* @brief XMAC_2_HOST_ENABLE_CLEAR register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 xmac2host_enable_clear 0x0 +* </pre> +*/ +#define IPC_XMAC_2_HOST_ENABLE_CLEAR_ADDR (REG_IPC_BASE_ADDR + 0x00000010) +#define IPC_XMAC_2_HOST_ENABLE_CLEAR_OFFSET 0x00000010 +#define IPC_XMAC_2_HOST_ENABLE_CLEAR_INDEX 0x00000004 +#define IPC_XMAC_2_HOST_ENABLE_CLEAR_RESET 0x00000000 + +static inline void ipc_xmac_2_host_enable_clear_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_XMAC_2_HOST_ENABLE_CLEAR_ADDR , value); +} + +/* +* @brief XMAC_2_HOST_STATUS register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 xmac2host_status 0x0 +* </pre> +*/ +#define IPC_XMAC_2_HOST_STATUS_ADDR (REG_IPC_BASE_ADDR + 0x00000014) +#define IPC_XMAC_2_HOST_STATUS_OFFSET 0x00000014 +#define IPC_XMAC_2_HOST_STATUS_INDEX 0x00000005 +#define IPC_XMAC_2_HOST_STATUS_RESET 0x00000000 + +static inline u32 ipc_xmac_2_host_status_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,IPC_XMAC_2_HOST_STATUS_ADDR ); +} + +/* +* @brief HOST_GLOBAL_INT_EN register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 master_int_enable 0 +* </pre> +*/ +#define IPC_HOST_GLOBAL_INT_EN_ADDR (REG_IPC_BASE_ADDR + 0x00000030) +#define IPC_HOST_GLOBAL_INT_EN_OFFSET 0x00000030 +#define IPC_HOST_GLOBAL_INT_EN_INDEX 0x0000000C +#define IPC_HOST_GLOBAL_INT_EN_RESET 0x00000000 + +static inline void ipc_host_global_int_en_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_HOST_GLOBAL_INT_EN_ADDR , value); +} + +/* +* @brief HOST_2_LMAC_TRIGGER register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 host2lmac_trigger 0x0 +* </pre> +*/ +#define IPC_HOST_2_LMAC_TRIGGER_ADDR (REG_IPC_BASE_ADDR + 0x00000080) +#define IPC_HOST_2_LMAC_TRIGGER_OFFSET 0x00000080 +#define IPC_HOST_2_LMAC_TRIGGER_INDEX 0x00000020 +#define IPC_HOST_2_LMAC_TRIGGER_RESET 0x00000000 + +static inline void ipc_host_2_lmac_trigger_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_HOST_2_LMAC_TRIGGER_ADDR , value); +} + +/* +* @brief HOST_2_UMAC_TRIGGER register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 host2umac_trigger 0x0 +* </pre> +*/ +#define IPC_HOST_2_UMAC_TRIGGER_ADDR (REG_IPC_BASE_ADDR + 0x00000084) +#define IPC_HOST_2_UMAC_TRIGGER_OFFSET 0x00000084 +#define IPC_HOST_2_UMAC_TRIGGER_INDEX 0x00000021 +#define IPC_HOST_2_UMAC_TRIGGER_RESET 0x00000000 + +static inline void ipc_host_2_umac_trigger_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_HOST_2_UMAC_TRIGGER_ADDR , value); +} + +/* +* @brief HOST_2_SMAC_TRIGGER register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 host2smac_trigger 0x0 +* </pre> +*/ +#define IPC_HOST_2_SMAC_TRIGGER_ADDR (REG_IPC_BASE_ADDR + 0x00000088) +#define IPC_HOST_2_SMAC_TRIGGER_OFFSET 0x00000088 +#define IPC_HOST_2_SMAC_TRIGGER_INDEX 0x00000022 +#define IPC_HOST_2_SMAC_TRIGGER_RESET 0x00000000 + +static inline void ipc_host_2_smac_trigger_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,IPC_HOST_2_SMAC_TRIGGER_ADDR , value); +} + +#define REG_LCU_COMMON_BASE_ADDR 0x007CF000 + +/* +* @brief LCU_COMMON_SW_RST register definition +* Software reset register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 SW_RST 0 +* </pre> +*/ +#define LCU_COMMON_SW_RST_ADDR (REG_LCU_COMMON_BASE_ADDR + 0x00000048) +#define LCU_COMMON_SW_RST_OFFSET 0x00000048 +#define LCU_COMMON_SW_RST_INDEX 0x00000012 +#define LCU_COMMON_SW_RST_RESET 0x00000000 + +static inline void lcu_common_sw_rst_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,LCU_COMMON_SW_RST_ADDR , value); +} + +#define REG_LCU_PHY_BASE_ADDR 0x0048E000 + +/* +* @brief LCU_CH_0_START register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 CH0_START 0 +* </pre> +*/ +#define LCU_PHY_LCU_CH_0_START_ADDR (REG_LCU_PHY_BASE_ADDR + 0x00000020) +#define LCU_PHY_LCU_CH_0_START_OFFSET 0x00000020 +#define LCU_PHY_LCU_CH_0_START_INDEX 0x00000008 +#define LCU_PHY_LCU_CH_0_START_RESET 0x00000000 + +/* +* @brief LCU_CH_0_STOP register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 CH0_STOP 0 +* </pre> +*/ +#define LCU_PHY_LCU_CH_0_STOP_ADDR (REG_LCU_PHY_BASE_ADDR + 0x00000070) +#define LCU_PHY_LCU_CH_0_STOP_OFFSET 0x00000070 +#define LCU_PHY_LCU_CH_0_STOP_INDEX 0x0000001C +#define LCU_PHY_LCU_CH_0_STOP_RESET 0x00000000 + +static inline void lcu_phy_lcu_ch_0_stop_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,LCU_PHY_LCU_CH_0_STOP_ADDR , value); +} + +/* +* @brief LCU_CH_1_STOP register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 CH1_STOP 0 +* </pre> +*/ +#define LCU_PHY_LCU_CH_1_STOP_ADDR (REG_LCU_PHY_BASE_ADDR + 0x00000074) +#define LCU_PHY_LCU_CH_1_STOP_OFFSET 0x00000074 +#define LCU_PHY_LCU_CH_1_STOP_INDEX 0x0000001D +#define LCU_PHY_LCU_CH_1_STOP_RESET 0x00000000 + +static inline void lcu_phy_lcu_ch_1_stop_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,LCU_PHY_LCU_CH_1_STOP_ADDR , value); +} + +/* +* @brief LCU_CH_0_STOP_EN register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 02 CH0_EXT_STOP_EN 0 +* 01 CH0_FIC_STOP_EN 0 +* 00 CH0_STOP_PTRN_EN 0 +* </pre> +*/ +#define LCU_PHY_LCU_CH_0_STOP_EN_ADDR (REG_LCU_PHY_BASE_ADDR + 0x00000078) +#define LCU_PHY_LCU_CH_0_STOP_EN_OFFSET 0x00000078 +#define LCU_PHY_LCU_CH_0_STOP_EN_INDEX 0x0000001E +#define LCU_PHY_LCU_CH_0_STOP_EN_RESET 0x00000000 + +/* +* @brief LCU_SW_RST register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 SW_RST 0 +* </pre> +*/ +#define LCU_PHY_LCU_SW_RST_ADDR (REG_LCU_PHY_BASE_ADDR + 0x00000154) +#define LCU_PHY_LCU_SW_RST_OFFSET 0x00000154 +#define LCU_PHY_LCU_SW_RST_INDEX 0x00000055 +#define LCU_PHY_LCU_SW_RST_RESET 0x00000000 + +static inline void lcu_phy_lcu_sw_rst_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,LCU_PHY_LCU_SW_RST_ADDR , value); +} + +/* +* @brief CONFIG_SPACE register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:26 ActiveAntennaSet 0x0 +* 25:20 RxCckActiveChain 0x0 +* 19:14 RxOfdmActiveChain 0x0 +* 13:08 TxCckActiveChain 0x0 +* 07:06 Band 0x0 +* 05:04 ChannelBandwidth 0x0 +* 03 OfdmOnly 0 +* 02 RxSensingMode 0 +* 01 UpdateSync 0 +* 00 StartupSync 0 +* </pre> +*/ +#define MACDSP_API_CONFIG_SPACE_ADDR (REG_MACDSP_API_BASE_ADDR + 0x00000010) +#define MACDSP_API_CONFIG_SPACE_OFFSET 0x00000010 +#define MACDSP_API_CONFIG_SPACE_INDEX 0x00000004 +#define MACDSP_API_CONFIG_SPACE_RESET 0x00000000 + +static inline void macdsp_api_config_space_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MACDSP_API_CONFIG_SPACE_ADDR , value); +} + +/* +* @brief STATE_CNTRL register definition +* This register controls the core's state transitions. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 07:04 NEXT_STATE 0x0 +* 03:00 CURRENT_STATE 0x0 +* </pre> +*/ +#define MAC_HW_STATE_CNTRL_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000038) +#define MAC_HW_STATE_CNTRL_OFFSET 0x00000038 +#define MAC_HW_STATE_CNTRL_INDEX 0x0000000E +#define MAC_HW_STATE_CNTRL_RESET 0x00000000 + +static inline void mac_hw_state_cntrl_next_state_setf (struct cl_hw *cl_hw,u8 nextstate) +{ +ASSERT_ERR ((((u32 )nextstate <<4 ) & ~((u32 )0x000000F0 )) ==0 ); +cl_reg_write (cl_hw,MAC_HW_STATE_CNTRL_ADDR , + (cl_reg_read (cl_hw,MAC_HW_STATE_CNTRL_ADDR ) & ~((u32 )0x000000F0 )) | + ((u32 )nextstate <<4 )); +} + +/* +* @brief MAC_CNTRL_1 register definition +* Contains various settings for controlling the operation of the core. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 EOF_PAD_FOR_HE 1 +* 30 EOF_PAD_FOR_VHT 0 +* 29:28 IMPLICIT_BF_INT_CONF 0x0 +* 27 DISABLE_BFR_RESP 0 +* 26 RX_RIFS_EN 0 +* 25 TSF_MGT_DISABLE 0 +* 24 TSF_UPDATED_BY_SW 0 +* 22 MAC_DETECT_UNDERRUN_EN 0 +* 21 DISABLE_MU_CTS_RESP 0 +* 20 BQRP_RESP_BY_FW 0 +* 19 BSRP_RESP_BY_FW 0 +* 18 ENABLE_NORMAL_ACK_RESP_IN_HE_MU_W_TRIG 0 +* 17 DISABLE_NORMAL_ACK_RESP_IN_HE_MU_WO_TRIG 0 +* 16:14 ABGN_MODE 0x3 +* 13 KEY_STO_RAM_RESET 0 +* 12 MIB_TABLE_RESET 0 +* 11 RATE_CONTROLLER_MPIF 1 +* 10 DISABLE_BA_RESP 0 +* 09 DISABLE_CTS_RESP 0 +* 08 DISABLE_ACK_RESP 0 +* 07 ACTIVE_CLK_GATING 1 +* 06 ENABLE_LP_CLK_SWITCH 0 +* 05 FORCE_MSTA_BA 0 +* 04 DISABLE_FAST_COMPARE 0 +* 03 CFP_AWARE 0 +* 02 PWR_MGT 0 +* 01 AP 0 +* 00 BSS_TYPE 1 +* </pre> +*/ +#define MAC_HW_MAC_CNTRL_1_ADDR (REG_MAC_HW_BASE_ADDR + 0x0000004C) +#define MAC_HW_MAC_CNTRL_1_OFFSET 0x0000004C +#define MAC_HW_MAC_CNTRL_1_INDEX 0x00000013 +#define MAC_HW_MAC_CNTRL_1_RESET 0x8000C881 + +static inline void mac_hw_mac_cntrl_1_active_clk_gating_setf (struct cl_hw *cl_hw, +u8 activeclkgating) +{ +ASSERT_ERR ((((u32 )activeclkgating <<7 ) & ~((u32 )0x00000080 )) ==0 ); +cl_reg_write (cl_hw,MAC_HW_MAC_CNTRL_1_ADDR , + (cl_reg_read (cl_hw,MAC_HW_MAC_CNTRL_1_ADDR ) & ~((u32 )0x00000080 )) | + ((u32 )activeclkgating <<7 )); +} + +/* +* @brief EDCA_CCA_BUSY register definition +* Indicates the CCA busy time. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 CCA_BUSY_DUR 0x0 +* </pre> +*/ +#define MAC_HW_EDCA_CCA_BUSY_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000220) +#define MAC_HW_EDCA_CCA_BUSY_OFFSET 0x00000220 +#define MAC_HW_EDCA_CCA_BUSY_INDEX 0x00000088 +#define MAC_HW_EDCA_CCA_BUSY_RESET 0x00000000 + +static inline u32 mac_hw_edca_cca_busy_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_EDCA_CCA_BUSY_ADDR ); +} + +/* +* @brief TX_MINE_BUSY register definition +* TX BUSY time by my TX frames register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 TX_MINE_TIME 0x0 +* </pre> +*/ +#define MAC_HW_TX_MINE_BUSY_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000238) +#define MAC_HW_TX_MINE_BUSY_OFFSET 0x00000238 +#define MAC_HW_TX_MINE_BUSY_INDEX 0x0000008E +#define MAC_HW_TX_MINE_BUSY_RESET 0x00000000 + +static inline u32 mac_hw_tx_mine_busy_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_TX_MINE_BUSY_ADDR ); +} + +/* +* @brief ADD_CCA_BUSY_SEC_20 register definition +* Indicates the CCA on Secondary 20MHz busy time. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 CCA_BUSY_DUR_SEC_20 0x0 +* </pre> +*/ +#define MAC_HW_ADD_CCA_BUSY_SEC_20_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000290) +#define MAC_HW_ADD_CCA_BUSY_SEC_20_OFFSET 0x00000290 +#define MAC_HW_ADD_CCA_BUSY_SEC_20_INDEX 0x000000A4 +#define MAC_HW_ADD_CCA_BUSY_SEC_20_RESET 0x00000000 + +static inline u32 mac_hw_add_cca_busy_sec_20_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_ADD_CCA_BUSY_SEC_20_ADDR ); +} + +/* +* @brief ADD_CCA_BUSY_SEC_40 register definition +* Indicates the CCA on Secondary 40MHz busy time. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 CCA_BUSY_DUR_SEC_40 0x0 +* </pre> +*/ +#define MAC_HW_ADD_CCA_BUSY_SEC_40_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000294) +#define MAC_HW_ADD_CCA_BUSY_SEC_40_OFFSET 0x00000294 +#define MAC_HW_ADD_CCA_BUSY_SEC_40_INDEX 0x000000A5 +#define MAC_HW_ADD_CCA_BUSY_SEC_40_RESET 0x00000000 + +static inline u32 mac_hw_add_cca_busy_sec_40_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_ADD_CCA_BUSY_SEC_40_ADDR ); +} + +/* +* @brief ADD_CCA_BUSY_SEC_80 register definition +* Indicates the CCA on Secondary 80MHz busy time. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 CCA_BUSY_DUR_SEC_80 0x0 +* </pre> +*/ +#define MAC_HW_ADD_CCA_BUSY_SEC_80_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000298) +#define MAC_HW_ADD_CCA_BUSY_SEC_80_OFFSET 0x00000298 +#define MAC_HW_ADD_CCA_BUSY_SEC_80_INDEX 0x000000A6 +#define MAC_HW_ADD_CCA_BUSY_SEC_80_RESET 0x00000000 + +static inline u32 mac_hw_add_cca_busy_sec_80_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_ADD_CCA_BUSY_SEC_80_ADDR ); +} + +/* +* @brief INTRA_BSS_NAV_BUSY register definition +* Count intra BSS NAV busy period register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 INTRA_BSS_NAV_BUSY_DUR 0x0 +* </pre> +*/ +#define MAC_HW_INTRA_BSS_NAV_BUSY_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000408) +#define MAC_HW_INTRA_BSS_NAV_BUSY_OFFSET 0x00000408 +#define MAC_HW_INTRA_BSS_NAV_BUSY_INDEX 0x00000102 +#define MAC_HW_INTRA_BSS_NAV_BUSY_RESET 0x00000000 + +static inline u32 mac_hw_intra_bss_nav_busy_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_INTRA_BSS_NAV_BUSY_ADDR ); +} + +/* +* @brief INTER_BSS_NAV_BUSY register definition +* Count inter BSS NAV busy period register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 INTER_BSS_NAV_BUSY_DUR 0x0 +* </pre> +*/ +#define MAC_HW_INTER_BSS_NAV_BUSY_ADDR (REG_MAC_HW_BASE_ADDR + 0x0000040C) +#define MAC_HW_INTER_BSS_NAV_BUSY_OFFSET 0x0000040C +#define MAC_HW_INTER_BSS_NAV_BUSY_INDEX 0x00000103 +#define MAC_HW_INTER_BSS_NAV_BUSY_RESET 0x00000000 + +static inline u32 mac_hw_inter_bss_nav_busy_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_INTER_BSS_NAV_BUSY_ADDR ); +} + +/* +* @brief DEBUG_PORT_SEL_A register definition +* Used to multiplex different sets of signals on the debug pins. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 15:08 DEBUG_PORT_SEL_1 0x0 +* 07:00 DEBUG_PORT_SEL_0 0x0 +* </pre> +*/ +#define MAC_HW_DEBUG_PORT_SEL_A_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000510) +#define MAC_HW_DEBUG_PORT_SEL_A_OFFSET 0x00000510 +#define MAC_HW_DEBUG_PORT_SEL_A_INDEX 0x00000144 +#define MAC_HW_DEBUG_PORT_SEL_A_RESET 0x00000000 + +static inline u32 mac_hw_debug_port_sel_a_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_DEBUG_PORT_SEL_A_ADDR ); +} + +static inline void mac_hw_debug_port_sel_a_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MAC_HW_DEBUG_PORT_SEL_A_ADDR , value); +} + +/* +* @brief DEBUG_PORT_SEL_B register definition +* Used to multiplex different sets of signals on the register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 15:08 DEBUG_PORT_SEL_3 0x0 +* 07:00 DEBUG_PORT_SEL_2 0x0 +* </pre> +*/ +#define MAC_HW_DEBUG_PORT_SEL_B_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000530) +#define MAC_HW_DEBUG_PORT_SEL_B_OFFSET 0x00000530 +#define MAC_HW_DEBUG_PORT_SEL_B_INDEX 0x0000014C +#define MAC_HW_DEBUG_PORT_SEL_B_RESET 0x00000000 + +static inline u32 mac_hw_debug_port_sel_b_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_DEBUG_PORT_SEL_B_ADDR ); +} + +static inline void mac_hw_debug_port_sel_b_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MAC_HW_DEBUG_PORT_SEL_B_ADDR , value); +} + +/* +* @brief DEBUG_PORT_SEL_C register definition +* Used to multiplex different sets of signals on the register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 15:08 DEBUG_PORT_SEL_5 0x0 +* 07:00 DEBUG_PORT_SEL_4 0x0 +* </pre> +*/ +#define MAC_HW_DEBUG_PORT_SEL_C_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000534) +#define MAC_HW_DEBUG_PORT_SEL_C_OFFSET 0x00000534 +#define MAC_HW_DEBUG_PORT_SEL_C_INDEX 0x0000014D +#define MAC_HW_DEBUG_PORT_SEL_C_RESET 0x00000000 + +static inline u32 mac_hw_debug_port_sel_c_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_DEBUG_PORT_SEL_C_ADDR ); +} + +static inline void mac_hw_debug_port_sel_c_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MAC_HW_DEBUG_PORT_SEL_C_ADDR , value); +} + +/* +* @brief DEBUG_PORT_EN register definition +* Used to determine which debug ports are enabled register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 05 EN5 0 +* 04 EN4 0 +* 03 EN3 0 +* 02 EN2 0 +* 01 EN1 0 +* 00 EN0 0 +* </pre> +*/ +#define MAC_HW_DEBUG_PORT_EN_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000538) +#define MAC_HW_DEBUG_PORT_EN_OFFSET 0x00000538 +#define MAC_HW_DEBUG_PORT_EN_INDEX 0x0000014E +#define MAC_HW_DEBUG_PORT_EN_RESET 0x00000000 + +static inline u32 mac_hw_debug_port_en_get (struct cl_hw *cl_hw) +{ +return cl_reg_read (cl_hw,MAC_HW_DEBUG_PORT_EN_ADDR ); +} + +static inline void mac_hw_debug_port_en_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MAC_HW_DEBUG_PORT_EN_ADDR , value); +} + +/* +* @brief DOZE_CNTRL_2 register definition +* Contains settings for controlling DOZE state. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 WAKE_UP_FROM_DOZE 0 +* 00 WAKE_UP_SW 1 +* </pre> +*/ +#define MAC_HW_DOZE_CNTRL_2_ADDR (REG_MAC_HW_BASE_ADDR + 0x00008048) +#define MAC_HW_DOZE_CNTRL_2_OFFSET 0x00008048 +#define MAC_HW_DOZE_CNTRL_2_INDEX 0x00002012 +#define MAC_HW_DOZE_CNTRL_2_RESET 0x00000001 + +static inline void mac_hw_doze_cntrl_2_wake_up_sw_setf (struct cl_hw *cl_hw,u8 wakeupsw) +{ +ASSERT_ERR ((((u32 )wakeupsw <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write (cl_hw,MAC_HW_DOZE_CNTRL_2_ADDR , + (cl_reg_read (cl_hw,MAC_HW_DOZE_CNTRL_2_ADDR ) & ~((u32 )0x00000001 )) | + ((u32 )wakeupsw <<0 )); +} + +#define MU_ADDR_OFFSET (i) ((i) << 16) +#define MAX_MU_CNT 8 + +/* +* @brief MAC_CNTRL_2 register definition +* Contains various settings for controlling the operation of the core. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 00 SOFT_RESET 0 +* </pre> +*/ +#define MAC_HW_MU_MAC_CNTRL_2_ADDR (REG_MAC_HW_BASE_ADDR + 0x00008050) +#define MAC_HW_MU_MAC_CNTRL_2_OFFSET 0x00008050 +#define MAC_HW_MU_MAC_CNTRL_2_INDEX 0x00002014 +#define MAC_HW_MU_MAC_CNTRL_2_RESET 0x00000000 + +static inline void mac_hw_mu_mac_cntrl_2_set (struct cl_hw *cl_hw,u32 value,u8 mu_idx) +{ +ASSERT_ERR (mu_idx <MAX_MU_CNT ); +cl_reg_write (cl_hw, (MAC_HW_MU_MAC_CNTRL_2_ADDR +MU_ADDR_OFFSET (mu_idx)), value); +} + +/* +* @brief MIB_TABLE register definition +* MIB table register description +* 1024 memory size +* </pre> +*/ +#define MAC_HW_MU_MIB_TABLE_ADDR (REG_MAC_HW_BASE_ADDR + 0x00000800) +#define MAC_HW_MU_MIB_TABLE_OFFSET 0x00000800 +#define MAC_HW_MU_MIB_TABLE_SIZE 0x00000400 +#define MAC_HW_MU_MIB_TABLE_END_ADDR (MAC_HW_MU_MIB_TABLE_ADDR + MAC_HW_MU_MIB_TABLE_SIZE - 1) + +#define REG_MACSYS_GCU_BASE_ADDR 0x007C5000 + +/* +* @brief CHIP_VERSION register definition +* Chip Version 8000B0 register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 23:08 PRODUCT_ID 0x8000 +* 07:04 STEP_ID 0xB +* 03:00 REV_ID 0x0 +* </pre> +*/ +#define MACSYS_GCU_CHIP_VERSION_ADDR (REG_MACSYS_GCU_BASE_ADDR + 0x00000050) +#define MACSYS_GCU_CHIP_VERSION_OFFSET 0x00000050 +#define MACSYS_GCU_CHIP_VERSION_INDEX 0x00000014 +#define MACSYS_GCU_CHIP_VERSION_RESET 0x008000B0 + +static inline u8 macsys_gcu_chip_version_step_id_getf (struct cl_chip *chip) +{ +u32 local_val =cl_reg_read_chip (chip,MACSYS_GCU_CHIP_VERSION_ADDR ); + +return ((local_val & ((u32 )0x000000F0 )) >>4 ); +} + +/* +* @brief XT_CONTROL register definition +* Tensilica control register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 21 smac_debug_en 0 +* 20 smac_break_in 0 +* 19 smac_ocd_halt_on_reset 1 +* 18 smac_run_stall 0 +* 17 smac_dreset_n 1 +* 16 smac_breset_n 0 +* 13 umac_debug_en 0 +* 12 umac_break_in 0 +* 11 umac_ocd_halt_on_reset 1 +* 10 umac_run_stall 0 +* 09 umac_dreset_n 1 +* 08 umac_breset_n 0 +* 05 lmac_debug_en 0 +* 04 lmac_break_in 0 +* 03 lmac_ocd_halt_on_reset 1 +* 02 lmac_run_stall 0 +* 01 lmac_dreset_n 1 +* 00 lmac_breset_n 0 +* </pre> +*/ +#define MACSYS_GCU_XT_CONTROL_ADDR (REG_MACSYS_GCU_BASE_ADDR + 0x000000F0) +#define MACSYS_GCU_XT_CONTROL_OFFSET 0x000000F0 +#define MACSYS_GCU_XT_CONTROL_INDEX 0x0000003C +#define MACSYS_GCU_XT_CONTROL_RESET 0x000A0A0A + +static inline u32 macsys_gcu_xt_control_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,MACSYS_GCU_XT_CONTROL_ADDR ); +} + +static inline void macsys_gcu_xt_control_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,MACSYS_GCU_XT_CONTROL_ADDR , value); +} + +#define REG_MODEM_GCU_BASE_ADDR 0x00480000 + +/* +* @brief MPU register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 21 MPU_CLK_F 0 +* 20 MPU_REG_CLK_F 0 +* 13 MPU_CLK_EN 0 +* 12 MPU_REG_CLK_EN 0 +* 01 MPU_RST_N 0 +* 00 MPU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_MPU_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000004) +#define MODEM_GCU_MPU_OFFSET 0x00000004 +#define MODEM_GCU_MPU_INDEX 0x00000001 +#define MODEM_GCU_MPU_RESET 0x00000000 + +static inline void modem_gcu_mpu_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_MPU_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_MPU_CLK_F_BIT ((u32)0x00200000) +#define MODEM_GCU_MPU_CLK_F_POS 21 +#define MODEM_GCU_MPU_REG_CLK_F_BIT ((u32)0x00100000) +#define MODEM_GCU_MPU_REG_CLK_F_POS 20 +#define MODEM_GCU_MPU_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_MPU_CLK_EN_POS 13 +#define MODEM_GCU_MPU_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_MPU_REG_CLK_EN_POS 12 +#define MODEM_GCU_MPU_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_MPU_RST_N_POS 1 +#define MODEM_GCU_MPU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_MPU_REG_RST_N_POS 0 + +/* +* @brief BPU register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 24 BPUL_RX_CLK_F 0 +* 23 BPU_CLK_F 0 +* 22 BPU_RX_CLK_F 0 +* 21 BPU_TX_CLK_F 0 +* 20 BPU_REG_CLK_F 0 +* 16 BPUL_RX_CLK_EN 0 +* 15 BPU_CLK_EN 0 +* 14 BPU_RX_CLK_EN 0 +* 13 BPU_TX_CLK_EN 0 +* 12 BPU_REG_CLK_EN 0 +* 03 BPU_RST_N 0 +* 02 BPU_RX_RST_N 0 +* 01 BPU_TX_RST_N 0 +* 00 BPU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_BPU_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000008) +#define MODEM_GCU_BPU_OFFSET 0x00000008 +#define MODEM_GCU_BPU_INDEX 0x00000002 +#define MODEM_GCU_BPU_RESET 0x00000000 + +static inline void modem_gcu_bpu_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_BPU_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_BPU_BPUL_RX_CLK_F_BIT ((u32)0x01000000) +#define MODEM_GCU_BPU_BPUL_RX_CLK_F_POS 24 +#define MODEM_GCU_BPU_CLK_F_BIT ((u32)0x00800000) +#define MODEM_GCU_BPU_CLK_F_POS 23 +#define MODEM_GCU_BPU_RX_CLK_F_BIT ((u32)0x00400000) +#define MODEM_GCU_BPU_RX_CLK_F_POS 22 +#define MODEM_GCU_BPU_TX_CLK_F_BIT ((u32)0x00200000) +#define MODEM_GCU_BPU_TX_CLK_F_POS 21 +#define MODEM_GCU_BPU_REG_CLK_F_BIT ((u32)0x00100000) +#define MODEM_GCU_BPU_REG_CLK_F_POS 20 +#define MODEM_GCU_BPU_BPUL_RX_CLK_EN_BIT ((u32)0x00010000) +#define MODEM_GCU_BPU_BPUL_RX_CLK_EN_POS 16 +#define MODEM_GCU_BPU_CLK_EN_BIT ((u32)0x00008000) +#define MODEM_GCU_BPU_CLK_EN_POS 15 +#define MODEM_GCU_BPU_RX_CLK_EN_BIT ((u32)0x00004000) +#define MODEM_GCU_BPU_RX_CLK_EN_POS 14 +#define MODEM_GCU_BPU_TX_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_BPU_TX_CLK_EN_POS 13 +#define MODEM_GCU_BPU_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_BPU_REG_CLK_EN_POS 12 +#define MODEM_GCU_BPU_RST_N_BIT ((u32)0x00000008) +#define MODEM_GCU_BPU_RST_N_POS 3 +#define MODEM_GCU_BPU_RX_RST_N_BIT ((u32)0x00000004) +#define MODEM_GCU_BPU_RX_RST_N_POS 2 +#define MODEM_GCU_BPU_TX_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_BPU_TX_RST_N_POS 1 +#define MODEM_GCU_BPU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_BPU_REG_RST_N_POS 0 + +/* +* @brief TFU register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 21 TFU_CLK_F 0 +* 20 TFU_REG_CLK_F 0 +* 13 TFU_CLK_EN 0 +* 12 TFU_REG_CLK_EN 0 +* 01 TFU_RST_N 0 +* 00 TFU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_TFU_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x0000000C) +#define MODEM_GCU_TFU_OFFSET 0x0000000C +#define MODEM_GCU_TFU_INDEX 0x00000003 +#define MODEM_GCU_TFU_RESET 0x00000000 + +static inline void modem_gcu_tfu_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_TFU_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_TFU_CLK_F_BIT ((u32)0x00200000) +#define MODEM_GCU_TFU_CLK_F_POS 21 +#define MODEM_GCU_TFU_REG_CLK_F_BIT ((u32)0x00100000) +#define MODEM_GCU_TFU_REG_CLK_F_POS 20 +#define MODEM_GCU_TFU_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_TFU_CLK_EN_POS 13 +#define MODEM_GCU_TFU_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_TFU_REG_CLK_EN_POS 12 +#define MODEM_GCU_TFU_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_TFU_RST_N_POS 1 +#define MODEM_GCU_TFU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_TFU_REG_RST_N_POS 0 + +/* +* @brief SMU register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 21 SMU_CLK_F 0 +* 20 SMU_REG_CLK_F 0 +* 13 SMU_CLK_EN 0 +* 12 SMU_REG_CLK_EN 0 +* 01 SMU_RST_N 0 +* 00 SMU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_SMU_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000010) +#define MODEM_GCU_SMU_OFFSET 0x00000010 +#define MODEM_GCU_SMU_INDEX 0x00000004 +#define MODEM_GCU_SMU_RESET 0x00000000 + +static inline void modem_gcu_smu_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_SMU_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_SMU_CLK_F_BIT ((u32)0x00200000) +#define MODEM_GCU_SMU_CLK_F_POS 21 +#define MODEM_GCU_SMU_REG_CLK_F_BIT ((u32)0x00100000) +#define MODEM_GCU_SMU_REG_CLK_F_POS 20 +#define MODEM_GCU_SMU_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_SMU_CLK_EN_POS 13 +#define MODEM_GCU_SMU_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_SMU_REG_CLK_EN_POS 12 +#define MODEM_GCU_SMU_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_SMU_RST_N_POS 1 +#define MODEM_GCU_SMU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_SMU_REG_RST_N_POS 0 + +/* +* @brief MUX_FIC register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 20 MUX_FIC_CLK_F 0 +* 12 MUX_FIC_CLK_EN 0 +* 01 FIC_MUX_SOFT_RST_N 1 +* 00 MUX_FIC_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_MUX_FIC_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000014) +#define MODEM_GCU_MUX_FIC_OFFSET 0x00000014 +#define MODEM_GCU_MUX_FIC_INDEX 0x00000005 +#define MODEM_GCU_MUX_FIC_RESET 0x00000002 + +static inline void modem_gcu_mux_fic_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_MUX_FIC_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_MUX_FIC_CLK_F_BIT ((u32)0x00100000) +#define MODEM_GCU_MUX_FIC_CLK_F_POS 20 +#define MODEM_GCU_MUX_FIC_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_MUX_FIC_CLK_EN_POS 12 +#define MODEM_GCU_MUX_FIC_SOFT_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_MUX_FIC_SOFT_RST_N_POS 1 +#define MODEM_GCU_MUX_FIC_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_MUX_FIC_RST_N_POS 0 + +/* +* @brief MUX_FIC_CONFIG register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 FIC_ISOLATED 0 +* 17 FIC_ISOLATE 0 +* 16 DISABLE_FIC_MESS 0 +* 15:08 MUX_FIC_CONFLICT_DELAY_WRITE 0x0 +* 07:00 MUX_FIC_CONFLICT_DELAY_READ 0x0 +* </pre> +*/ +#define MODEM_GCU_MUX_FIC_CONFIG_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x0000001C) +#define MODEM_GCU_MUX_FIC_CONFIG_OFFSET 0x0000001C +#define MODEM_GCU_MUX_FIC_CONFIG_INDEX 0x00000007 +#define MODEM_GCU_MUX_FIC_CONFIG_RESET 0x00000000 + +static inline void modem_gcu_mux_fic_config_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_MUX_FIC_CONFIG_ADDR , value); +} + +static inline u8 modem_gcu_mux_fic_config_fic_isolated_getf (struct cl_hw *cl_hw) +{ +u32 local_val =cl_reg_read (cl_hw,MODEM_GCU_MUX_FIC_CONFIG_ADDR ); + +return ((local_val & ((u32 )0x80000000 )) >>31 ); +} + +static inline void modem_gcu_mux_fic_config_fic_isolate_setf (struct cl_hw *cl_hw,u8 ficisolate) +{ +ASSERT_ERR ((((u32 )ficisolate <<17 ) & ~((u32 )0x00020000 )) ==0 ); +cl_reg_write (cl_hw,MODEM_GCU_MUX_FIC_CONFIG_ADDR , + (cl_reg_read (cl_hw,MODEM_GCU_MUX_FIC_CONFIG_ADDR ) & ~((u32 )0x00020000 )) | + ((u32 )ficisolate <<17 )); +} + +/* +* @brief RIU_RST register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 07 RIUFE_RST_N 0 +* 06 RIUAGC_RST_N 0 +* 05 RIU_MDM_B_RST_N 0 +* 04 RIULB_RST_N 0 +* 03 RIURC_RST_N 0 +* 02 RIU_RADAR_RST_N 0 +* 01 RIU_RST_N 0 +* 00 RIU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_RIU_RST_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000020) +#define MODEM_GCU_RIU_RST_OFFSET 0x00000020 +#define MODEM_GCU_RIU_RST_INDEX 0x00000008 +#define MODEM_GCU_RIU_RST_RESET 0x00000000 + +static inline void modem_gcu_riu_rst_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_RIU_RST_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_RIU_FE_RST_N_BIT ((u32)0x00000080) +#define MODEM_GCU_RIU_FE_RST_N_POS 7 +#define MODEM_GCU_RIU_AGC_RST_N_BIT ((u32)0x00000040) +#define MODEM_GCU_RIU_AGC_RST_N_POS 6 +#define MODEM_GCU_RIU_MDM_B_RST_N_BIT ((u32)0x00000020) +#define MODEM_GCU_RIU_MDM_B_RST_N_POS 5 +#define MODEM_GCU_RIU_LB_RST_N_BIT ((u32)0x00000010) +#define MODEM_GCU_RIU_LB_RST_N_POS 4 +#define MODEM_GCU_RIU_RC_RST_N_BIT ((u32)0x00000008) +#define MODEM_GCU_RIU_RC_RST_N_POS 3 +#define MODEM_GCU_RIU_RADAR_RST_N_BIT ((u32)0x00000004) +#define MODEM_GCU_RIU_RADAR_RST_N_POS 2 +#define MODEM_GCU_RIU_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_RIU_RST_N_POS 1 +#define MODEM_GCU_RIU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_RIU_REG_RST_N_POS 0 + +/* +* @brief RIU_CLK register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 RIUADC_PWR_CLK_F 0 +* 30 RIUFEA_5_CLK_F 0 +* 29 RIUFEA_4_CLK_F 0 +* 28 RIUFEA_3_CLK_F 0 +* 27 RIUFEA_2_CLK_F 0 +* 26 RIUFEA_1_CLK_F 0 +* 25 RIUFEA_0_CLK_F 0 +* 24 RIU_MDM_B_TX_CLK_F 0 +* 23 RIU_MDM_B_RX_CLK_F 0 +* 22 RIU_MDM_B_CLK_F 0 +* 21 RIULB_CLK_F 0 +* 20 RIURC_CLK_F 0 +* 19 RIU_RADAR_CLK_F 0 +* 18 RIUAGC_CLK_F 0 +* 17 RIU_CLK_F 0 +* 16 RIU_REG_CLK_F 0 +* 15 RIUADC_PWR_CLK_EN 0 +* 14 RIUFEA_5_CLK_EN 0 +* 13 RIUFEA_4_CLK_EN 0 +* 12 RIUFEA_3_CLK_EN 0 +* 11 RIUFEA_2_CLK_EN 0 +* 10 RIUFEA_1_CLK_EN 0 +* 09 RIUFEA_0_CLK_EN 0 +* 08 RIU_MDM_B_TX_CLK_EN 0 +* 07 RIU_MDM_B_RX_CLK_EN 0 +* 06 RIU_MDM_B_CLK_EN 0 +* 05 RIULB_CLK_EN 0 +* 04 RIURCR_CLK_EN 0 +* 03 RIU_RADAR_CLK_EN 0 +* 02 RIUAGC_CLK_EN 0 +* 01 RIU_CLK_EN 0 +* 00 RIU_REG_CLK_EN 0 +* </pre> +*/ +#define MODEM_GCU_RIU_CLK_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000024) +#define MODEM_GCU_RIU_CLK_OFFSET 0x00000024 +#define MODEM_GCU_RIU_CLK_INDEX 0x00000009 +#define MODEM_GCU_RIU_CLK_RESET 0x00000000 + +static inline void modem_gcu_riu_clk_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_RIU_CLK_ADDR , value); +} + +/* +* @brief SPU register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 21 SPU_CLK_F 0 +* 20 SPU_REG_CLK_F 0 +* 13 SPU_CLK_EN 0 +* 12 SPU_REG_CLK_EN 0 +* 01 SPU_RST_N 0 +* 00 SPU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_SPU_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000030) +#define MODEM_GCU_SPU_OFFSET 0x00000030 +#define MODEM_GCU_SPU_INDEX 0x0000000C +#define MODEM_GCU_SPU_RESET 0x00000000 + +static inline void modem_gcu_spu_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_SPU_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_SPU_CLK_F_BIT ((u32)0x00200000) +#define MODEM_GCU_SPU_CLK_F_POS 21 +#define MODEM_GCU_SPU_REG_CLK_F_BIT ((u32)0x00100000) +#define MODEM_GCU_SPU_REG_CLK_F_POS 20 +#define MODEM_GCU_SPU_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_SPU_CLK_EN_POS 13 +#define MODEM_GCU_SPU_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_SPU_REG_CLK_EN_POS 12 +#define MODEM_GCU_SPU_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_SPU_RST_N_POS 1 +#define MODEM_GCU_SPU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_SPU_REG_RST_N_POS 0 + +/* +* @brief LCU register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 14 LCU_HLF_CLK_EN 0 +* 13 LCU_CLK_EN 0 +* 12 LCU_REG_CLK_EN 0 +* 02 LCU_HLF_RST_N 0 +* 01 LCU_RST_N 0 +* 00 LCU_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_LCU_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000034) +#define MODEM_GCU_LCU_OFFSET 0x00000034 +#define MODEM_GCU_LCU_INDEX 0x0000000D +#define MODEM_GCU_LCU_RESET 0x00000000 + +static inline void modem_gcu_lcu_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_LCU_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_LCU_HLF_CLK_EN_BIT ((u32)0x00004000) +#define MODEM_GCU_LCU_HLF_CLK_EN_POS 14 +#define MODEM_GCU_LCU_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_LCU_CLK_EN_POS 13 +#define MODEM_GCU_LCU_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_LCU_REG_CLK_EN_POS 12 +#define MODEM_GCU_LCU_HLF_RST_N_BIT ((u32)0x00000004) +#define MODEM_GCU_LCU_HLF_RST_N_POS 2 +#define MODEM_GCU_LCU_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_LCU_RST_N_POS 1 +#define MODEM_GCU_LCU_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_LCU_REG_RST_N_POS 0 + +/* +* @brief EPA register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 13 EPA_CLK_EN 0 +* 12 EPA_REG_CLK_EN 0 +* 01 EPA_RST_N 0 +* 00 EPA_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_EPA_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000038) +#define MODEM_GCU_EPA_OFFSET 0x00000038 +#define MODEM_GCU_EPA_INDEX 0x0000000E +#define MODEM_GCU_EPA_RESET 0x00000000 + +static inline void modem_gcu_epa_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_EPA_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_EPA_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_EPA_CLK_EN_POS 13 +#define MODEM_GCU_EPA_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_EPA_REG_CLK_EN_POS 12 +#define MODEM_GCU_EPA_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_EPA_RST_N_POS 1 +#define MODEM_GCU_EPA_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_EPA_REG_RST_N_POS 0 + +/* +* @brief BF register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 13 BF_CLK_EN 0 +* 12 BF_REG_CLK_EN 0 +* 01 BF_RST_N 0 +* 00 BF_REG_RST_N 0 +* </pre> +*/ +#define MODEM_GCU_BF_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x0000003C) +#define MODEM_GCU_BF_OFFSET 0x0000003C +#define MODEM_GCU_BF_INDEX 0x0000000F +#define MODEM_GCU_BF_RESET 0x00000000 + +static inline void modem_gcu_bf_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_BF_ADDR , value); +} + +/* Field definitions */ +#define MODEM_GCU_BF_CLK_EN_BIT ((u32)0x00002000) +#define MODEM_GCU_BF_CLK_EN_POS 13 +#define MODEM_GCU_BF_REG_CLK_EN_BIT ((u32)0x00001000) +#define MODEM_GCU_BF_REG_CLK_EN_POS 12 +#define MODEM_GCU_BF_RST_N_BIT ((u32)0x00000002) +#define MODEM_GCU_BF_RST_N_POS 1 +#define MODEM_GCU_BF_REG_RST_N_BIT ((u32)0x00000001) +#define MODEM_GCU_BF_REG_RST_N_POS 0 + +/* +* @brief RIU_CLK_1 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 17 RIUFE_EXT_CLK_F 0 +* 16 RIUFRC_CLK_F 0 +* 01 RIUFE_EXT_CLK_EN 0 +* 00 RIUFRC_CLK_EN 0 +* </pre> +*/ +#define MODEM_GCU_RIU_CLK_1_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00000124) +#define MODEM_GCU_RIU_CLK_1_OFFSET 0x00000124 +#define MODEM_GCU_RIU_CLK_1_INDEX 0x00000049 +#define MODEM_GCU_RIU_CLK_1_RESET 0x00000000 + +static inline void modem_gcu_riu_clk_1_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_RIU_CLK_1_ADDR , value); +} + +/* +* @brief CEVA_CTRL register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 16 MCCI_ADDR_BASE 0 +* 14 VINTC 0 +* 12 NMI 0 +* 10:09 EXT_VOM 0x0 +* 08 EXT_PV 0 +* 07:06 UIA 0x0 +* 05 STOP_SD 0 +* 04 MON_STAT 0 +* 02 EXTERNAL_WAIT 1 +* 00 BOOT 0 +* </pre> +*/ +#define MODEM_GCU_CEVA_CTRL_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00001004) +#define MODEM_GCU_CEVA_CTRL_OFFSET 0x00001004 +#define MODEM_GCU_CEVA_CTRL_INDEX 0x00000401 +#define MODEM_GCU_CEVA_CTRL_RESET 0x00000004 + +static inline void modem_gcu_ceva_ctrl_external_wait_setf (struct cl_hw *cl_hw,u8 externalwait) +{ +ASSERT_ERR ((((u32 )externalwait <<2 ) & ~((u32 )0x00000004 )) ==0 ); +cl_reg_write (cl_hw,MODEM_GCU_CEVA_CTRL_ADDR , + (cl_reg_read (cl_hw,MODEM_GCU_CEVA_CTRL_ADDR ) & ~((u32 )0x00000004 )) | + ((u32 )externalwait <<2 )); +} + +static inline void modem_gcu_ceva_ctrl_boot_setf (struct cl_hw *cl_hw,u8 boot) +{ +ASSERT_ERR ((((u32 )boot <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write (cl_hw,MODEM_GCU_CEVA_CTRL_ADDR , + (cl_reg_read (cl_hw,MODEM_GCU_CEVA_CTRL_ADDR ) & ~((u32 )0x00000001 )) | + ((u32 )boot <<0 )); +} + +/* +* @brief CEVA_VEC register definition +* Ceva Vector register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:00 VECTOR 0x0 +* </pre> +*/ +#define MODEM_GCU_CEVA_VEC_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00001008) +#define MODEM_GCU_CEVA_VEC_OFFSET 0x00001008 +#define MODEM_GCU_CEVA_VEC_INDEX 0x00000402 +#define MODEM_GCU_CEVA_VEC_RESET 0x00000000 + +static inline void modem_gcu_ceva_vec_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_CEVA_VEC_ADDR , value); +} + +/* +* @brief RIU_CLK_BW register definition +* RIU clocks BW. register description +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 13 agc_clk_bw 0 +* 12:10 lb_mem_clk_bw 0x2 +* 09:08 agc_mem_clk_bw 0x1 +* 07:06 riu_afe_clk_bw 0x2 +* 05:04 phyfesync_bw 0x2 +* 03:02 adcpowclk_bw 0x2 +* 01:00 riulbgclk_bw 0x2 +* </pre> +*/ +#define MODEM_GCU_RIU_CLK_BW_ADDR (REG_MODEM_GCU_BASE_ADDR + 0x00001240) +#define MODEM_GCU_RIU_CLK_BW_OFFSET 0x00001240 +#define MODEM_GCU_RIU_CLK_BW_INDEX 0x00000490 +#define MODEM_GCU_RIU_CLK_BW_RESET 0x000009AA + +static inline void modem_gcu_riu_clk_bw_set (struct cl_hw *cl_hw,u32 value) +{ +cl_reg_write (cl_hw,MODEM_GCU_RIU_CLK_BW_ADDR , value); +} + +static inline void modem_gcu_riu_clk_bw_agc_mem_clk_bw_setf (struct cl_hw *cl_hw,u8 agcmemclkbw) +{ +ASSERT_ERR ((((u32 )agcmemclkbw <<8 ) & ~((u32 )0x00000300 )) ==0 ); +cl_reg_write (cl_hw,MODEM_GCU_RIU_CLK_BW_ADDR , + (cl_reg_read (cl_hw,MODEM_GCU_RIU_CLK_BW_ADDR ) & ~((u32 )0x00000300 )) | + ((u32 )agcmemclkbw <<8 )); +} + +/* +* @brief STATIC_CONF_0 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30 ARB_ONESHOT_BYPASS 1 +* 28 BTC_SEL 0 +* 27 CLK_SAVE_MODE 0 +* 26 RF_RST_N_DEFAULT 0 +* 25 RF_RST_N_REQ 0 +* 24 FORCE_RSSI_ON 0 +* 23:20 RSSI_M 0x2 +* 19:16 RSSI_N 0x6 +* 03:00 CDB_MODE_MAJ 0x0 +* </pre> +*/ +#define RICU_STATIC_CONF_0_ADDR (REG_RICU_BASE_ADDR + 0x00000004) +#define RICU_STATIC_CONF_0_OFFSET 0x00000004 +#define RICU_STATIC_CONF_0_INDEX 0x00000001 +#define RICU_STATIC_CONF_0_RESET 0x40260000 + +static inline void ricu_static_conf_0_btc_sel_setf (struct cl_chip *chip,u8 btcsel) +{ +ASSERT_ERR_CHIP ((((u32 )btcsel <<28 ) & ~((u32 )0x10000000 )) ==0 ); +cl_reg_write_chip (chip,RICU_STATIC_CONF_0_ADDR , + (cl_reg_read_chip (chip,RICU_STATIC_CONF_0_ADDR ) & ~((u32 )0x10000000 )) | + ((u32 )btcsel <<28 )); +} + +static inline void ricu_static_conf_0_clk_save_mode_setf (struct cl_chip *chip,u8 clksavemode) +{ +ASSERT_ERR_CHIP ((((u32 )clksavemode <<27 ) & ~((u32 )0x08000000 )) ==0 ); +cl_reg_write_chip (chip,RICU_STATIC_CONF_0_ADDR , + (cl_reg_read_chip (chip,RICU_STATIC_CONF_0_ADDR ) & ~((u32 )0x08000000 )) | + ((u32 )clksavemode <<27 )); +} + +static inline void ricu_static_conf_0_rf_rst_n_req_setf (struct cl_chip *chip,u8 rfrstnreq) +{ +ASSERT_ERR_CHIP ((((u32 )rfrstnreq <<25 ) & ~((u32 )0x02000000 )) ==0 ); +cl_reg_write_chip (chip,RICU_STATIC_CONF_0_ADDR , + (cl_reg_read_chip (chip,RICU_STATIC_CONF_0_ADDR ) & ~((u32 )0x02000000 )) | + ((u32 )rfrstnreq <<25 )); +} + +static inline u8 ricu_static_conf_0_cdb_mode_maj_getf (struct cl_chip *chip) +{ +u32 local_val =cl_reg_read_chip (chip,RICU_STATIC_CONF_0_ADDR ); + +return ((local_val & ((u32 )0x0000000F )) >>0 ); +} + +static inline void ricu_static_conf_0_cdb_mode_maj_setf (struct cl_chip *chip,u8 cdbmodemaj) +{ +ASSERT_ERR_CHIP ((((u32 )cdbmodemaj <<0 ) & ~((u32 )0x0000000F )) ==0 ); +cl_reg_write_chip (chip,RICU_STATIC_CONF_0_ADDR , + (cl_reg_read_chip (chip,RICU_STATIC_CONF_0_ADDR ) & ~((u32 )0x0000000F )) | + ((u32 )cdbmodemaj <<0 )); +} + +/* +* @brief AFE_CTL_0 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 PBIAS_CTRL_EN_LC 0 +* 30 PBIAS_CTRL_EN 0 +* 29 LRD_EN_LC 0 +* 28 LRD_EN 0 +* 27 LOCK_EN_LC 0 +* 26 LOCK_EN 1 +* 25 EN_GPADC_CLK 0 +* 24 EN_GPADC 0 +* 23 FEED_EN_LC 0 +* 22 FEED_EN 0 +* 21 EN_CS 1 +* 20 EN_CML_GEN 1 +* 18 EN_AFE_LDO 1 +* 17 EN_ADC_CLK 1 +* 15 AFC_ENB_LC 0 +* 14 AFC_ENB 0 +* 13 CP_MODE_LC 1 +* 12 BYPASS_LC 0 +* 11 BYPASS 0 +* 10 AFCINIT_SEL_LC 1 +* 09 AFCINIT_SEL 1 +* 08 EN_CLK_MON 0 +* 07 EN_DAC_CLK 1 +* 06 EN_CDB_DAC_CLK 0 +* 05 EN_CDB_ADC_CLK 0 +* 03 EN_CDB_GEN 0 +* 02 DACCLK_PHASESEL 0 +* 01 ADCCLK_PHASESEL 0 +* 00 CDB_CLK_RESETB 0 +* </pre> +*/ +#define RICU_AFE_CTL_0_ADDR (REG_RICU_BASE_ADDR + 0x00000010) +#define RICU_AFE_CTL_0_OFFSET 0x00000010 +#define RICU_AFE_CTL_0_INDEX 0x00000004 +#define RICU_AFE_CTL_0_RESET 0x04362680 + +static inline u32 ricu_afe_ctl_0_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,RICU_AFE_CTL_0_ADDR ); +} + +static inline void ricu_afe_ctl_0_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_0_ADDR , value); +} + +static inline void ricu_afe_ctl_0_lock_en_lc_setf (struct cl_chip *chip,u8 lockenlc) +{ +ASSERT_ERR_CHIP ((((u32 )lockenlc <<27 ) & ~((u32 )0x08000000 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_0_ADDR ) & ~((u32 )0x08000000 )) | + ((u32 )lockenlc <<27 )); +} + +/* Field definitions */ +#define RICU_AFE_CTL_0_PBIAS_CTRL_EN_LC_BIT ((u32)0x80000000) +#define RICU_AFE_CTL_0_PBIAS_CTRL_EN_LC_POS 31 +#define RICU_AFE_CTL_0_PBIAS_CTRL_EN_BIT ((u32)0x40000000) +#define RICU_AFE_CTL_0_PBIAS_CTRL_EN_POS 30 +#define RICU_AFE_CTL_0_LRD_EN_LC_BIT ((u32)0x20000000) +#define RICU_AFE_CTL_0_LRD_EN_LC_POS 29 +#define RICU_AFE_CTL_0_LRD_EN_BIT ((u32)0x10000000) +#define RICU_AFE_CTL_0_LRD_EN_POS 28 +#define RICU_AFE_CTL_0_LOCK_EN_LC_BIT ((u32)0x08000000) +#define RICU_AFE_CTL_0_LOCK_EN_LC_POS 27 +#define RICU_AFE_CTL_0_LOCK_EN_BIT ((u32)0x04000000) +#define RICU_AFE_CTL_0_LOCK_EN_POS 26 +#define RICU_AFE_CTL_0_EN_GPADC_CLK_BIT ((u32)0x02000000) +#define RICU_AFE_CTL_0_EN_GPADC_CLK_POS 25 +#define RICU_AFE_CTL_0_EN_GPADC_BIT ((u32)0x01000000) +#define RICU_AFE_CTL_0_EN_GPADC_POS 24 +#define RICU_AFE_CTL_0_FEED_EN_LC_BIT ((u32)0x00800000) +#define RICU_AFE_CTL_0_FEED_EN_LC_POS 23 +#define RICU_AFE_CTL_0_FEED_EN_BIT ((u32)0x00400000) +#define RICU_AFE_CTL_0_FEED_EN_POS 22 +#define RICU_AFE_CTL_0_EN_CS_BIT ((u32)0x00200000) +#define RICU_AFE_CTL_0_EN_CS_POS 21 +#define RICU_AFE_CTL_0_EN_CML_GEN_BIT ((u32)0x00100000) +#define RICU_AFE_CTL_0_EN_CML_GEN_POS 20 +#define RICU_AFE_CTL_0_EN_AFE_LDO_BIT ((u32)0x00040000) +#define RICU_AFE_CTL_0_EN_AFE_LDO_POS 18 +#define RICU_AFE_CTL_0_EN_ADC_CLK_BIT ((u32)0x00020000) +#define RICU_AFE_CTL_0_EN_ADC_CLK_POS 17 +#define RICU_AFE_CTL_0_AFC_ENB_LC_BIT ((u32)0x00008000) +#define RICU_AFE_CTL_0_AFC_ENB_LC_POS 15 +#define RICU_AFE_CTL_0_AFC_ENB_BIT ((u32)0x00004000) +#define RICU_AFE_CTL_0_AFC_ENB_POS 14 +#define RICU_AFE_CTL_0_CP_MODE_LC_BIT ((u32)0x00002000) +#define RICU_AFE_CTL_0_CP_MODE_LC_POS 13 +#define RICU_AFE_CTL_0_BYPASS_LC_BIT ((u32)0x00001000) +#define RICU_AFE_CTL_0_BYPASS_LC_POS 12 +#define RICU_AFE_CTL_0_BYPASS_BIT ((u32)0x00000800) +#define RICU_AFE_CTL_0_BYPASS_POS 11 +#define RICU_AFE_CTL_0_AFCINIT_SEL_LC_BIT ((u32)0x00000400) +#define RICU_AFE_CTL_0_AFCINIT_SEL_LC_POS 10 +#define RICU_AFE_CTL_0_AFCINIT_SEL_BIT ((u32)0x00000200) +#define RICU_AFE_CTL_0_AFCINIT_SEL_POS 9 +#define RICU_AFE_CTL_0_EN_CLK_MON_BIT ((u32)0x00000100) +#define RICU_AFE_CTL_0_EN_CLK_MON_POS 8 +#define RICU_AFE_CTL_0_EN_DAC_CLK_BIT ((u32)0x00000080) +#define RICU_AFE_CTL_0_EN_DAC_CLK_POS 7 +#define RICU_AFE_CTL_0_EN_CDB_DAC_CLK_BIT ((u32)0x00000040) +#define RICU_AFE_CTL_0_EN_CDB_DAC_CLK_POS 6 +#define RICU_AFE_CTL_0_EN_CDB_ADC_CLK_BIT ((u32)0x00000020) +#define RICU_AFE_CTL_0_EN_CDB_ADC_CLK_POS 5 +#define RICU_AFE_CTL_0_EN_CDB_GEN_BIT ((u32)0x00000008) +#define RICU_AFE_CTL_0_EN_CDB_GEN_POS 3 +#define RICU_AFE_CTL_0_DACCLK_PHASESEL_BIT ((u32)0x00000004) +#define RICU_AFE_CTL_0_DACCLK_PHASESEL_POS 2 +#define RICU_AFE_CTL_0_ADCCLK_PHASESEL_BIT ((u32)0x00000002) +#define RICU_AFE_CTL_0_ADCCLK_PHASESEL_POS 1 +#define RICU_AFE_CTL_0_CDB_CLK_RESETB_BIT ((u32)0x00000001) +#define RICU_AFE_CTL_0_CDB_CLK_RESETB_POS 0 + +static inline void ricu_afe_ctl_0_pbias_ctrl_en_lc_setf (struct cl_chip *chip,u8 pbiasctrlenlc) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_0_ADDR ) & ~((u32 )0x80000000 )) | + ((u32 )pbiasctrlenlc <<31 )); +} + +static inline void ricu_afe_ctl_0_cdb_clk_resetb_setf (struct cl_chip *chip,u8 cdbclkresetb) +{ +ASSERT_ERR_CHIP ((((u32 )cdbclkresetb <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_0_ADDR ) & ~((u32 )0x00000001 )) | + ((u32 )cdbclkresetb <<0 )); +} + +/* +* @brief AFE_CTL_1 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 14 VCO_BOOST 0 +* 13 SYS_ADCCLK_SEL 0 +* 12 SOC_PHASE_SEL 1 +* 11 SOC_CLK_SEL 1 +* 10 RESETB_LC 0 +* 09 RESETB 1 +* 08 PBIAS_CTRL_LC 0 +* 07 PBIAS_CTRL 0 +* 06 GP_CLK_PHASESEL 0 +* 05 FSEL_LC 0 +* 04 FSEL 0 +* 03 FOUT_MASK_LC 0 +* 02 FOUT_MASK 0 +* 01 EXTCLK_SEL 0 +* 00 EN_PLL_LDO 0 +* </pre> +*/ +#define RICU_AFE_CTL_1_ADDR (REG_RICU_BASE_ADDR + 0x00000014) +#define RICU_AFE_CTL_1_OFFSET 0x00000014 +#define RICU_AFE_CTL_1_INDEX 0x00000005 +#define RICU_AFE_CTL_1_RESET 0x00001A00 + +static inline void ricu_afe_ctl_1_resetb_lc_setf (struct cl_chip *chip,u8 resetblc) +{ +ASSERT_ERR_CHIP ((((u32 )resetblc <<10 ) & ~((u32 )0x00000400 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_1_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_1_ADDR ) & ~((u32 )0x00000400 )) | + ((u32 )resetblc <<10 )); +} + +static inline void ricu_afe_ctl_1_en_pll_ldo_setf (struct cl_chip *chip,u8 enpllldo) +{ +ASSERT_ERR_CHIP ((((u32 )enpllldo <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_1_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_1_ADDR ) & ~((u32 )0x00000001 )) | + ((u32 )enpllldo <<0 )); +} + +/* +* @brief AFE_CTL_2 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 23:22 LOCK_CON_REV_LC 0x0 +* 21:20 LOCK_CON_REV 0x0 +* 19:18 LOCK_CON_OUT_LC 0x3 +* 17:16 LOCK_CON_OUT 0x3 +* 15:14 LOCK_CON_IN_LC 0x3 +* 13:12 LOCK_CON_IN 0x3 +* 11:10 LOCK_CON_DLY_LC 0x3 +* 09:08 LOCK_CON_DLY 0x3 +* 07:06 ICP 0x1 +* 03:02 CTRL_IB 0x2 +* 01:00 CLK_MON_SEL 0x0 +* </pre> +*/ +#define RICU_AFE_CTL_2_ADDR (REG_RICU_BASE_ADDR + 0x00000018) +#define RICU_AFE_CTL_2_OFFSET 0x00000018 +#define RICU_AFE_CTL_2_INDEX 0x00000006 +#define RICU_AFE_CTL_2_RESET 0x000FFF48 + +static inline void ricu_afe_ctl_2_lock_con_rev_lc_setf (struct cl_chip *chip,u8 lockconrevlc) +{ +ASSERT_ERR_CHIP ((((u32 )lockconrevlc <<22 ) & ~((u32 )0x00C00000 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_2_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_2_ADDR ) & ~((u32 )0x00C00000 )) | + ((u32 )lockconrevlc <<22 )); +} + +/* +* @brief AFE_CTL_3 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:28 RSEL 0x0 +* 27:24 I_CSEL_LC 0xc +* 23:20 GM_LC 0xf +* 19:16 CSEL_LC 0x3 +* 15:12 CML_SEL 0x9 +* 11:09 S_LC 0x0 +* 08:06 S 0x0 +* 05:03 LBW_LC 0x7 +* 02:00 ICP_LC 0x7 +* </pre> +*/ +#define RICU_AFE_CTL_3_ADDR (REG_RICU_BASE_ADDR + 0x0000001C) +#define RICU_AFE_CTL_3_OFFSET 0x0000001C +#define RICU_AFE_CTL_3_INDEX 0x00000007 +#define RICU_AFE_CTL_3_RESET 0x0CF3903F + +static inline void ricu_afe_ctl_3_cml_sel_setf (struct cl_chip *chip,u8 cmlsel) +{ +ASSERT_ERR_CHIP ((((u32 )cmlsel <<12 ) & ~((u32 )0x0000F000 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_3_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_3_ADDR ) & ~((u32 )0x0000F000 )) | + ((u32 )cmlsel <<12 )); +} + +/* +* @brief AFE_CTL_5 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 23:18 MAIN_SEL_7_2 0x0 +* 17:12 P_LC 0x1 +* 11:06 P 0xA +* 05:00 CAP_BIAS_CODE_LC 0x4 +* </pre> +*/ +#define RICU_AFE_CTL_5_ADDR (REG_RICU_BASE_ADDR + 0x00000024) +#define RICU_AFE_CTL_5_OFFSET 0x00000024 +#define RICU_AFE_CTL_5_INDEX 0x00000009 +#define RICU_AFE_CTL_5_RESET 0x00001284 + +static inline void ricu_afe_ctl_5_main_sel_7_2_setf (struct cl_chip *chip,u8 mainsel72) +{ +ASSERT_ERR_CHIP ((((u32 )mainsel72 <<18 ) & ~((u32 )0x00FC0000 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_5_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTL_5_ADDR ) & ~((u32 )0x00FC0000 )) | + ((u32 )mainsel72 <<18 )); +} + +/* +* @brief AFE_CTL_8 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 EN_REF7 0 +* 30 EN_REF6 0 +* 29 EN_REF5 0 +* 28 EN_REF4 0 +* 27 EN_REF3 0 +* 26 EN_REF2 0 +* 25 EN_REF1 0 +* 24 EN_REF0 0 +* 23 EN_EXT_LOAD7 0 +* 22 EN_EXT_LOAD6 0 +* 21 EN_EXT_LOAD5 0 +* 20 EN_EXT_LOAD4 0 +* 19 EN_EXT_LOAD3 0 +* 18 EN_EXT_LOAD2 0 +* 17 EN_EXT_LOAD1 0 +* 16 EN_EXT_LOAD0 0 +* 15 CH_CML_SEL7 0 +* 14 CH_CML_SEL6 0 +* 13 CH_CML_SEL5 0 +* 12 CH_CML_SEL4 0 +* 11 CH_CML_SEL3 0 +* 10 CH_CML_SEL2 0 +* 09 CH_CML_SEL1 0 +* 08 CH_CML_SEL0 0 +* 07 EN_BGR7 0 +* 06 EN_BGR6 0 +* 05 EN_BGR5 0 +* 04 EN_BGR4 0 +* 03 EN_BGR3 0 +* 02 EN_BGR2 0 +* 01 EN_BGR1 0 +* 00 EN_BGR0 0 +* </pre> +*/ +#define RICU_AFE_CTL_8_ADDR (REG_RICU_BASE_ADDR + 0x00000030) +#define RICU_AFE_CTL_8_OFFSET 0x00000030 +#define RICU_AFE_CTL_8_INDEX 0x0000000C +#define RICU_AFE_CTL_8_RESET 0x00000000 + +static inline u32 ricu_afe_ctl_8_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,RICU_AFE_CTL_8_ADDR ); +} + +static inline void ricu_afe_ctl_8_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_8_ADDR , value); +} + +/* Field definitions */ +#define RICU_AFE_CTL_8_EN_REF_7_BIT ((u32)0x80000000) +#define RICU_AFE_CTL_8_EN_REF_7_POS 31 +#define RICU_AFE_CTL_8_EN_REF_6_BIT ((u32)0x40000000) +#define RICU_AFE_CTL_8_EN_REF_6_POS 30 +#define RICU_AFE_CTL_8_EN_REF_5_BIT ((u32)0x20000000) +#define RICU_AFE_CTL_8_EN_REF_5_POS 29 +#define RICU_AFE_CTL_8_EN_REF_4_BIT ((u32)0x10000000) +#define RICU_AFE_CTL_8_EN_REF_4_POS 28 +#define RICU_AFE_CTL_8_EN_REF_3_BIT ((u32)0x08000000) +#define RICU_AFE_CTL_8_EN_REF_3_POS 27 +#define RICU_AFE_CTL_8_EN_REF_2_BIT ((u32)0x04000000) +#define RICU_AFE_CTL_8_EN_REF_2_POS 26 +#define RICU_AFE_CTL_8_EN_REF_1_BIT ((u32)0x02000000) +#define RICU_AFE_CTL_8_EN_REF_1_POS 25 +#define RICU_AFE_CTL_8_EN_REF_0_BIT ((u32)0x01000000) +#define RICU_AFE_CTL_8_EN_REF_0_POS 24 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_7_BIT ((u32)0x00800000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_7_POS 23 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_6_BIT ((u32)0x00400000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_6_POS 22 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_5_BIT ((u32)0x00200000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_5_POS 21 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_4_BIT ((u32)0x00100000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_4_POS 20 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_3_BIT ((u32)0x00080000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_3_POS 19 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_2_BIT ((u32)0x00040000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_2_POS 18 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_1_BIT ((u32)0x00020000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_1_POS 17 +#define RICU_AFE_CTL_8_EN_EXT_LOAD_0_BIT ((u32)0x00010000) +#define RICU_AFE_CTL_8_EN_EXT_LOAD_0_POS 16 +#define RICU_AFE_CTL_8_CH_CML_SEL_7_BIT ((u32)0x00008000) +#define RICU_AFE_CTL_8_CH_CML_SEL_7_POS 15 +#define RICU_AFE_CTL_8_CH_CML_SEL_6_BIT ((u32)0x00004000) +#define RICU_AFE_CTL_8_CH_CML_SEL_6_POS 14 +#define RICU_AFE_CTL_8_CH_CML_SEL_5_BIT ((u32)0x00002000) +#define RICU_AFE_CTL_8_CH_CML_SEL_5_POS 13 +#define RICU_AFE_CTL_8_CH_CML_SEL_4_BIT ((u32)0x00001000) +#define RICU_AFE_CTL_8_CH_CML_SEL_4_POS 12 +#define RICU_AFE_CTL_8_CH_CML_SEL_3_BIT ((u32)0x00000800) +#define RICU_AFE_CTL_8_CH_CML_SEL_3_POS 11 +#define RICU_AFE_CTL_8_CH_CML_SEL_2_BIT ((u32)0x00000400) +#define RICU_AFE_CTL_8_CH_CML_SEL_2_POS 10 +#define RICU_AFE_CTL_8_CH_CML_SEL_1_BIT ((u32)0x00000200) +#define RICU_AFE_CTL_8_CH_CML_SEL_1_POS 9 +#define RICU_AFE_CTL_8_CH_CML_SEL_0_BIT ((u32)0x00000100) +#define RICU_AFE_CTL_8_CH_CML_SEL_0_POS 8 +#define RICU_AFE_CTL_8_EN_BGR_7_BIT ((u32)0x00000080) +#define RICU_AFE_CTL_8_EN_BGR_7_POS 7 +#define RICU_AFE_CTL_8_EN_BGR_6_BIT ((u32)0x00000040) +#define RICU_AFE_CTL_8_EN_BGR_6_POS 6 +#define RICU_AFE_CTL_8_EN_BGR_5_BIT ((u32)0x00000020) +#define RICU_AFE_CTL_8_EN_BGR_5_POS 5 +#define RICU_AFE_CTL_8_EN_BGR_4_BIT ((u32)0x00000010) +#define RICU_AFE_CTL_8_EN_BGR_4_POS 4 +#define RICU_AFE_CTL_8_EN_BGR_3_BIT ((u32)0x00000008) +#define RICU_AFE_CTL_8_EN_BGR_3_POS 3 +#define RICU_AFE_CTL_8_EN_BGR_2_BIT ((u32)0x00000004) +#define RICU_AFE_CTL_8_EN_BGR_2_POS 2 +#define RICU_AFE_CTL_8_EN_BGR_1_BIT ((u32)0x00000002) +#define RICU_AFE_CTL_8_EN_BGR_1_POS 1 +#define RICU_AFE_CTL_8_EN_BGR_0_BIT ((u32)0x00000001) +#define RICU_AFE_CTL_8_EN_BGR_0_POS 0 + +/* +* @brief AFE_CTL_9 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 EN_SIN2_BIAS7 1 +* 30 EN_SIN2_BIAS6 1 +* 29 EN_SIN2_BIAS5 1 +* 28 EN_SIN2_BIAS4 1 +* 27 EN_SIN2_BIAS3 1 +* 26 EN_SIN2_BIAS2 1 +* 25 EN_SIN2_BIAS1 1 +* 24 EN_SIN2_BIAS0 1 +* 23 EN_DAC_REF7 0 +* 22 EN_DAC_REF6 0 +* 21 EN_DAC_REF5 0 +* 20 EN_DAC_REF4 0 +* 19 EN_DAC_REF3 0 +* 18 EN_DAC_REF2 0 +* 17 EN_DAC_REF1 0 +* 16 EN_DAC_REF0 0 +* </pre> +*/ +#define RICU_AFE_CTL_9_ADDR (REG_RICU_BASE_ADDR + 0x00000034) +#define RICU_AFE_CTL_9_OFFSET 0x00000034 +#define RICU_AFE_CTL_9_INDEX 0x0000000D +#define RICU_AFE_CTL_9_RESET 0xFF000000 + +static inline u32 ricu_afe_ctl_9_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,RICU_AFE_CTL_9_ADDR ); +} + +static inline void ricu_afe_ctl_9_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_9_ADDR , value); +} + +/* Field definitions */ +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_7_BIT ((u32)0x80000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_7_POS 31 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_6_BIT ((u32)0x40000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_6_POS 30 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_5_BIT ((u32)0x20000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_5_POS 29 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_4_BIT ((u32)0x10000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_4_POS 28 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_3_BIT ((u32)0x08000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_3_POS 27 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_2_BIT ((u32)0x04000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_2_POS 26 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_1_BIT ((u32)0x02000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_1_POS 25 +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_0_BIT ((u32)0x01000000) +#define RICU_AFE_CTL_9_EN_SIN_2_BIAS_0_POS 24 +#define RICU_AFE_CTL_9_EN_DAC_REF_7_BIT ((u32)0x00800000) +#define RICU_AFE_CTL_9_EN_DAC_REF_7_POS 23 +#define RICU_AFE_CTL_9_EN_DAC_REF_6_BIT ((u32)0x00400000) +#define RICU_AFE_CTL_9_EN_DAC_REF_6_POS 22 +#define RICU_AFE_CTL_9_EN_DAC_REF_5_BIT ((u32)0x00200000) +#define RICU_AFE_CTL_9_EN_DAC_REF_5_POS 21 +#define RICU_AFE_CTL_9_EN_DAC_REF_4_BIT ((u32)0x00100000) +#define RICU_AFE_CTL_9_EN_DAC_REF_4_POS 20 +#define RICU_AFE_CTL_9_EN_DAC_REF_3_BIT ((u32)0x00080000) +#define RICU_AFE_CTL_9_EN_DAC_REF_3_POS 19 +#define RICU_AFE_CTL_9_EN_DAC_REF_2_BIT ((u32)0x00040000) +#define RICU_AFE_CTL_9_EN_DAC_REF_2_POS 18 +#define RICU_AFE_CTL_9_EN_DAC_REF_1_BIT ((u32)0x00020000) +#define RICU_AFE_CTL_9_EN_DAC_REF_1_POS 17 +#define RICU_AFE_CTL_9_EN_DAC_REF_0_BIT ((u32)0x00010000) +#define RICU_AFE_CTL_9_EN_DAC_REF_0_POS 16 + +/* +* @brief AFE_CTL_10 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 VC_LD7 0 +* 30 VC_LD6 0 +* 29 VC_LD5 0 +* 28 VC_LD4 0 +* 27 VC_LD3 0 +* 26 VC_LD2 0 +* 25 VC_LD1 0 +* 24 VC_LD0 0 +* 23 TWOS7 0 +* 22 TWOS6 0 +* 21 TWOS5 0 +* 20 TWOS4 0 +* 19 TWOS3 0 +* 18 TWOS2 0 +* 17 TWOS1 0 +* 16 TWOS0 0 +* 07 MINV7 1 +* 06 MINV6 1 +* 05 MINV5 1 +* 04 MINV4 1 +* 03 MINV3 1 +* 02 MINV2 1 +* 01 MINV1 1 +* 00 MINV0 1 +* </pre> +*/ +#define RICU_AFE_CTL_10_ADDR (REG_RICU_BASE_ADDR + 0x00000038) +#define RICU_AFE_CTL_10_OFFSET 0x00000038 +#define RICU_AFE_CTL_10_INDEX 0x0000000E +#define RICU_AFE_CTL_10_RESET 0x000000FF + +static inline void ricu_afe_ctl_10_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_10_ADDR , value); +} + +/* +* @brief AFE_CTL_12 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:30 EOC_CTRL7 0x0 +* 29:28 EOC_CTRL6 0x0 +* 27:26 EOC_CTRL5 0x0 +* 25:24 EOC_CTRL4 0x0 +* 23:22 EOC_CTRL3 0x0 +* 21:20 EOC_CTRL2 0x0 +* 19:18 EOC_CTRL1 0x0 +* 17:16 EOC_CTRL0 0x0 +* 15:14 IC_REFSSF7 0x1 +* 13:12 IC_REFSSF6 0x1 +* 11:10 IC_REFSSF5 0x1 +* 09:08 IC_REFSSF4 0x1 +* 07:06 IC_REFSSF3 0x1 +* 05:04 IC_REFSSF2 0x1 +* 03:02 IC_REFSSF1 0x1 +* 01:00 IC_REFSSF0 0x1 +* </pre> +*/ +#define RICU_AFE_CTL_12_ADDR (REG_RICU_BASE_ADDR + 0x00000040) +#define RICU_AFE_CTL_12_OFFSET 0x00000040 +#define RICU_AFE_CTL_12_INDEX 0x00000010 +#define RICU_AFE_CTL_12_RESET 0x00005555 + +static inline void ricu_afe_ctl_12_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_12_ADDR , value); +} + +/* Field definitions */ +#define RICU_AFE_CTL_12_EOC_CTRL_7_MASK ((u32)0xC0000000) +#define RICU_AFE_CTL_12_EOC_CTRL_7_LSB 30 +#define RICU_AFE_CTL_12_EOC_CTRL_7_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_6_MASK ((u32)0x30000000) +#define RICU_AFE_CTL_12_EOC_CTRL_6_LSB 28 +#define RICU_AFE_CTL_12_EOC_CTRL_6_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_5_MASK ((u32)0x0C000000) +#define RICU_AFE_CTL_12_EOC_CTRL_5_LSB 26 +#define RICU_AFE_CTL_12_EOC_CTRL_5_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_4_MASK ((u32)0x03000000) +#define RICU_AFE_CTL_12_EOC_CTRL_4_LSB 24 +#define RICU_AFE_CTL_12_EOC_CTRL_4_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_3_MASK ((u32)0x00C00000) +#define RICU_AFE_CTL_12_EOC_CTRL_3_LSB 22 +#define RICU_AFE_CTL_12_EOC_CTRL_3_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_2_MASK ((u32)0x00300000) +#define RICU_AFE_CTL_12_EOC_CTRL_2_LSB 20 +#define RICU_AFE_CTL_12_EOC_CTRL_2_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_1_MASK ((u32)0x000C0000) +#define RICU_AFE_CTL_12_EOC_CTRL_1_LSB 18 +#define RICU_AFE_CTL_12_EOC_CTRL_1_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_EOC_CTRL_0_MASK ((u32)0x00030000) +#define RICU_AFE_CTL_12_EOC_CTRL_0_LSB 16 +#define RICU_AFE_CTL_12_EOC_CTRL_0_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_7_MASK ((u32)0x0000C000) +#define RICU_AFE_CTL_12_IC_REFSSF_7_LSB 14 +#define RICU_AFE_CTL_12_IC_REFSSF_7_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_6_MASK ((u32)0x00003000) +#define RICU_AFE_CTL_12_IC_REFSSF_6_LSB 12 +#define RICU_AFE_CTL_12_IC_REFSSF_6_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_5_MASK ((u32)0x00000C00) +#define RICU_AFE_CTL_12_IC_REFSSF_5_LSB 10 +#define RICU_AFE_CTL_12_IC_REFSSF_5_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_4_MASK ((u32)0x00000300) +#define RICU_AFE_CTL_12_IC_REFSSF_4_LSB 8 +#define RICU_AFE_CTL_12_IC_REFSSF_4_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_3_MASK ((u32)0x000000C0) +#define RICU_AFE_CTL_12_IC_REFSSF_3_LSB 6 +#define RICU_AFE_CTL_12_IC_REFSSF_3_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_2_MASK ((u32)0x00000030) +#define RICU_AFE_CTL_12_IC_REFSSF_2_LSB 4 +#define RICU_AFE_CTL_12_IC_REFSSF_2_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_1_MASK ((u32)0x0000000C) +#define RICU_AFE_CTL_12_IC_REFSSF_1_LSB 2 +#define RICU_AFE_CTL_12_IC_REFSSF_1_WIDTH ((u32)0x00000002) +#define RICU_AFE_CTL_12_IC_REFSSF_0_MASK ((u32)0x00000003) +#define RICU_AFE_CTL_12_IC_REFSSF_0_LSB 0 +#define RICU_AFE_CTL_12_IC_REFSSF_0_WIDTH ((u32)0x00000002) + +/* +* @brief AFE_CTL_13 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31 FORCE_ADC_ON_PHY1 0 +* 30 FORCE_ADC_ON_PHY0 0 +* 16 EN_LB8_AUX 0 +* 15 EN_LB7 0 +* 14 EN_LB6 0 +* 13 EN_LB5 0 +* 12 EN_LB4 0 +* 11 EN_LB3 0 +* 10 EN_LB2 0 +* 09 EN_LB1 0 +* 08 EN_LB0 0 +* </pre> +*/ +#define RICU_AFE_CTL_13_ADDR (REG_RICU_BASE_ADDR + 0x00000044) +#define RICU_AFE_CTL_13_OFFSET 0x00000044 +#define RICU_AFE_CTL_13_INDEX 0x00000011 +#define RICU_AFE_CTL_13_RESET 0x00000000 + +static inline void ricu_afe_ctl_13_pack (struct cl_chip *chip,u8 forceadconphy1,u8 forceadconphy0, +u8 enlb8aux,u8 enlb7,u8 enlb6,u8 enlb5,u8 enlb4, +u8 enlb3,u8 enlb2,u8 enlb1,u8 enlb0) +{ +ASSERT_ERR_CHIP ((((u32 )forceadconphy0 <<30 ) & ~((u32 )0x40000000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb8aux <<16 ) & ~((u32 )0x00010000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb7 <<15 ) & ~((u32 )0x00008000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb6 <<14 ) & ~((u32 )0x00004000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb5 <<13 ) & ~((u32 )0x00002000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb4 <<12 ) & ~((u32 )0x00001000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb3 <<11 ) & ~((u32 )0x00000800 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb2 <<10 ) & ~((u32 )0x00000400 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb1 <<9 ) & ~((u32 )0x00000200 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enlb0 <<8 ) & ~((u32 )0x00000100 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_13_ADDR , + ((u32 )forceadconphy1 <<31 ) | ((u32 )forceadconphy0 <<30 ) | + ((u32 )enlb8aux <<16 ) | ((u32 )enlb7 <<15 ) | ((u32 )enlb6 <<14 ) | + ((u32 )enlb5 <<13 ) | ((u32 )enlb4 <<12 ) | ((u32 )enlb3 <<11 ) | + ((u32 )enlb2 <<10 ) | ((u32 )enlb1 <<9 ) | ((u32 )enlb0 <<8 )); +} + +/* +* @brief AFE_CTL_15 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30:28 EN_OUT_CM7 0x0 +* 26:24 EN_OUT_CM6 0x0 +* 22:20 EN_OUT_CM5 0x0 +* 18:16 EN_OUT_CM4 0x0 +* 14:12 EN_OUT_CM3 0x0 +* 10:08 EN_OUT_CM2 0x0 +* 06:04 EN_OUT_CM1 0x0 +* 02:00 EN_OUT_CM0 0x0 +* </pre> +*/ +#define RICU_AFE_CTL_15_ADDR (REG_RICU_BASE_ADDR + 0x0000004C) +#define RICU_AFE_CTL_15_OFFSET 0x0000004C +#define RICU_AFE_CTL_15_INDEX 0x00000013 +#define RICU_AFE_CTL_15_RESET 0x00000000 + +static inline void ricu_afe_ctl_15_pack (struct cl_chip *chip,u8 enoutcm7,u8 enoutcm6, +u8 enoutcm5,u8 enoutcm4,u8 enoutcm3, +u8 enoutcm2,u8 enoutcm1,u8 enoutcm0) +{ +ASSERT_ERR_CHIP ((((u32 )enoutcm7 <<28 ) & ~((u32 )0x70000000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm6 <<24 ) & ~((u32 )0x07000000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm5 <<20 ) & ~((u32 )0x00700000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm4 <<16 ) & ~((u32 )0x00070000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm3 <<12 ) & ~((u32 )0x00007000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm2 <<8 ) & ~((u32 )0x00000700 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm1 <<4 ) & ~((u32 )0x00000070 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )enoutcm0 <<0 ) & ~((u32 )0x00000007 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_15_ADDR , + ((u32 )enoutcm7 <<28 ) | ((u32 )enoutcm6 <<24 ) | ((u32 )enoutcm5 <<20 ) | + ((u32 )enoutcm4 <<16 ) | ((u32 )enoutcm3 <<12 ) | ((u32 )enoutcm2 <<8 ) | + ((u32 )enoutcm1 <<4 ) | ((u32 )enoutcm0 <<0 )); +} + +/* +* @brief AFE_CTL_17 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30:28 VC_REF7 0x1 +* 26:24 VC_REF6 0x1 +* 22:20 VC_REF5 0x1 +* 18:16 VC_REF4 0x1 +* 14:12 VC_REF3 0x1 +* 10:08 VC_REF2 0x1 +* 06:04 VC_REF1 0x1 +* 02:00 VC_REF0 0x1 +* </pre> +*/ +#define RICU_AFE_CTL_17_ADDR (REG_RICU_BASE_ADDR + 0x00000054) +#define RICU_AFE_CTL_17_OFFSET 0x00000054 +#define RICU_AFE_CTL_17_INDEX 0x00000015 +#define RICU_AFE_CTL_17_RESET 0x11111111 + +static inline void ricu_afe_ctl_17_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_17_ADDR , value); +} + +/* +* @brief AFE_CTL_19 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 31:28 COMP_CTRL7 0x4 +* 27:24 COMP_CTRL6 0x4 +* 23:20 COMP_CTRL5 0x4 +* 19:16 COMP_CTRL4 0x4 +* 15:12 COMP_CTRL3 0x4 +* 11:08 COMP_CTRL2 0x4 +* 07:04 COMP_CTRL1 0x4 +* 03:00 COMP_CTRL0 0x4 +* </pre> +*/ +#define RICU_AFE_CTL_19_ADDR (REG_RICU_BASE_ADDR + 0x0000005C) +#define RICU_AFE_CTL_19_OFFSET 0x0000005C +#define RICU_AFE_CTL_19_INDEX 0x00000017 +#define RICU_AFE_CTL_19_RESET 0x44444444 + +static inline void ricu_afe_ctl_19_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_19_ADDR , value); +} + +/* +* @brief AFE_CTL_23 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30:28 VC_LD_AVDI7 0x3 +* 26:24 VC_LD_AVDI6 0x3 +* 22:20 VC_LD_AVDI5 0x3 +* 18:16 VC_LD_AVDI4 0x3 +* 14:12 VC_LD_AVDI3 0x3 +* 10:08 VC_LD_AVDI2 0x3 +* 06:04 VC_LD_AVDI1 0x3 +* 02:00 VC_LD_AVDI0 0x3 +* </pre> +*/ +#define RICU_AFE_CTL_23_ADDR (REG_RICU_BASE_ADDR + 0x0000006C) +#define RICU_AFE_CTL_23_OFFSET 0x0000006C +#define RICU_AFE_CTL_23_INDEX 0x0000001B +#define RICU_AFE_CTL_23_RESET 0x33333333 + +static inline void ricu_afe_ctl_23_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_23_ADDR , value); +} + +/* +* @brief AFE_CTL_24 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30:28 VC_LD_AVDQ7 0x3 +* 26:24 VC_LD_AVDQ6 0x3 +* 22:20 VC_LD_AVDQ5 0x3 +* 18:16 VC_LD_AVDQ4 0x3 +* 14:12 VC_LD_AVDQ3 0x3 +* 10:08 VC_LD_AVDQ2 0x3 +* 06:04 VC_LD_AVDQ1 0x3 +* 02:00 VC_LD_AVDQ0 0x3 +* </pre> +*/ +#define RICU_AFE_CTL_24_ADDR (REG_RICU_BASE_ADDR + 0x00000070) +#define RICU_AFE_CTL_24_OFFSET 0x00000070 +#define RICU_AFE_CTL_24_INDEX 0x0000001C +#define RICU_AFE_CTL_24_RESET 0x33333333 + +static inline void ricu_afe_ctl_24_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_24_ADDR , value); +} + +/* +* @brief AFE_CTL_25 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 16 ROSEL0 0 +* 14:08 RO_CTRLQ0 0x7 +* 06:00 RO_CTRLI0 0x7 +* </pre> +*/ +#define RICU_AFE_CTL_25_ADDR (REG_RICU_BASE_ADDR + 0x00000074) +#define RICU_AFE_CTL_25_OFFSET 0x00000074 +#define RICU_AFE_CTL_25_INDEX 0x0000001D +#define RICU_AFE_CTL_25_RESET 0x00000707 + +static inline void ricu_afe_ctl_25_pack (struct cl_chip *chip,u8 rosel0,u8 roctrlq0,u8 roctrli0) +{ +ASSERT_ERR_CHIP ((((u32 )rosel0 <<16 ) & ~((u32 )0x00010000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrlq0 <<8 ) & ~((u32 )0x00007F00 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrli0 <<0 ) & ~((u32 )0x0000007F )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_25_ADDR , + ((u32 )rosel0 <<16 ) | ((u32 )roctrlq0 <<8 ) | ((u32 )roctrli0 <<0 )); +} + +/* +* @brief AFE_CTL_26 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 16 ROSEL1 0 +* 14:08 RO_CTRLQ1 0x7 +* 06:00 RO_CTRLI1 0x7 +* </pre> +*/ +#define RICU_AFE_CTL_26_ADDR (REG_RICU_BASE_ADDR + 0x00000078) +#define RICU_AFE_CTL_26_OFFSET 0x00000078 +#define RICU_AFE_CTL_26_INDEX 0x0000001E +#define RICU_AFE_CTL_26_RESET 0x00000707 + +static inline void ricu_afe_ctl_26_pack (struct cl_chip *chip,u8 rosel1,u8 roctrlq1,u8 roctrli1) +{ +ASSERT_ERR_CHIP ((((u32 )rosel1 <<16 ) & ~((u32 )0x00010000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrlq1 <<8 ) & ~((u32 )0x00007F00 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrli1 <<0 ) & ~((u32 )0x0000007F )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_26_ADDR , + ((u32 )rosel1 <<16 ) | ((u32 )roctrlq1 <<8 ) | ((u32 )roctrli1 <<0 )); +} + +/* +* @brief AFE_CTL_27 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 16 ROSEL2 0 +* 14:08 RO_CTRLQ2 0x7 +* 06:00 RO_CTRLI2 0x7 +* </pre> +*/ +#define RICU_AFE_CTL_27_ADDR (REG_RICU_BASE_ADDR + 0x0000007C) +#define RICU_AFE_CTL_27_OFFSET 0x0000007C +#define RICU_AFE_CTL_27_INDEX 0x0000001F +#define RICU_AFE_CTL_27_RESET 0x00000707 + +static inline void ricu_afe_ctl_27_pack (struct cl_chip *chip,u8 rosel2,u8 roctrlq2,u8 roctrli2) +{ +ASSERT_ERR_CHIP ((((u32 )rosel2 <<16 ) & ~((u32 )0x00010000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrlq2 <<8 ) & ~((u32 )0x00007F00 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrli2 <<0 ) & ~((u32 )0x0000007F )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_27_ADDR , + ((u32 )rosel2 <<16 ) | ((u32 )roctrlq2 <<8 ) | ((u32 )roctrli2 <<0 )); +} + +/* +* @brief AFE_CTL_29 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30:28 VC_CML7_I 0x5 +* 26:24 VC_CML6_I 0x5 +* 22:20 VC_CML5_I 0x5 +* 18:16 VC_CML4_I 0x5 +* 14:12 VC_CML3_I 0x5 +* 10:08 VC_CML2_I 0x5 +* 06:04 VC_CML1_I 0x5 +* 02:00 VC_CML0_I 0x5 +* </pre> +*/ +#define RICU_AFE_CTL_29_ADDR (REG_RICU_BASE_ADDR + 0x00000084) +#define RICU_AFE_CTL_29_OFFSET 0x00000084 +#define RICU_AFE_CTL_29_INDEX 0x00000021 +#define RICU_AFE_CTL_29_RESET 0x55555555 + +static inline void ricu_afe_ctl_29_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_29_ADDR , value); +} + +/* +* @brief AFE_CTL_30 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 30:28 VC_CML7_Q 0x5 +* 26:24 VC_CML6_Q 0x5 +* 22:20 VC_CML5_Q 0x5 +* 18:16 VC_CML4_Q 0x5 +* 14:12 VC_CML3_Q 0x5 +* 10:08 VC_CML2_Q 0x5 +* 06:04 VC_CML1_Q 0x5 +* 02:00 VC_CML0_Q 0x5 +* </pre> +*/ +#define RICU_AFE_CTL_30_ADDR (REG_RICU_BASE_ADDR + 0x00000088) +#define RICU_AFE_CTL_30_OFFSET 0x00000088 +#define RICU_AFE_CTL_30_INDEX 0x00000022 +#define RICU_AFE_CTL_30_RESET 0x55555555 + +static inline void ricu_afe_ctl_30_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTL_30_ADDR , value); +} + +/* +* @brief AFE_CTL_33 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 16 ROSEL3 0 +* 14:08 RO_CTRL3_Q 0x7 +* 06:00 RO_CTRL3_I 0x7 +* </pre> +*/ +#define RICU_AFE_CTL_33_ADDR (REG_RICU_BASE_ADDR + 0x00000094) +#define RICU_AFE_CTL_33_OFFSET 0x00000094 +#define RICU_AFE_CTL_33_INDEX 0x00000025 +#define RICU_AFE_CTL_33_RESET 0x00000707 + +static inline void ricu_afe_ctl_33_pack (struct cl_chip *chip,u8 rosel3,u8 roctrl3q,u8 roctrl3i) +{ +ASSERT_ERR_CHIP ((((u32 )rosel3 <<16 ) & ~((u32 )0x00010000 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrl3q <<8 ) & ~((u32 )0x00007F00 )) ==0 ); +ASSERT_ERR_CHIP ((((u32 )roctrl3i <<0 ) & ~((u32 )0x0000007F )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTL_33_ADDR , + ((u32 )rosel3 <<16 ) | ((u32 )roctrl3q <<8 ) | ((u32 )roctrl3i <<0 )); +} + +/* +* @brief AFE_CTRL_34_PHY_0 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 06 PHY0_ADC_SB_IGNORE_FIFO_INDICATION 0 +* 05:02 PHY0_ADC_SB_RD_DELAY 0x4 +* 01:00 PHY0_ADC_SB_MODE 0x0 +* </pre> +*/ +#define RICU_AFE_CTRL_34_PHY_0_ADDR (REG_RICU_BASE_ADDR + 0x0000009C) +#define RICU_AFE_CTRL_34_PHY_0_OFFSET 0x0000009C +#define RICU_AFE_CTRL_34_PHY_0_INDEX 0x00000027 +#define RICU_AFE_CTRL_34_PHY_0_RESET 0x00000010 + +static inline +void ricu_afe_ctrl_34_phy_0_adc_sb_ignore_fifo_indication_setf (struct cl_chip *chip, +u8 phy0adcsbignorefifoindication) +{ +ASSERT_ERR_CHIP ((((u32 )phy0adcsbignorefifoindication <<6 ) & ~((u32 )0x00000040 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_34_PHY_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_34_PHY_0_ADDR ) & + ~((u32 )0x00000040 )) | ((u32 )phy0adcsbignorefifoindication <<6 )); +} + +static inline void ricu_afe_ctrl_34_phy_0_adc_sb_rd_delay_setf (struct cl_chip *chip, +u8 phy0adcsbrddelay) +{ +ASSERT_ERR_CHIP ((((u32 )phy0adcsbrddelay <<2 ) & ~((u32 )0x0000003C )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_34_PHY_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_34_PHY_0_ADDR ) & + ~((u32 )0x0000003C )) | ((u32 )phy0adcsbrddelay <<2 )); +} + +/* +* @brief AFE_CTRL_36_PHY_0 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 07 PHY0_ADC_ALWAYS_EN_LD_IR 0 +* 06 PHY0_ADC_ALWAYS_EN_LD_AVDQ 0 +* 05 PHY0_ADC_ALWAYS_EN_LD_AVDI 0 +* 04 PHY0_ADC_ALWAYS_EN_ADCQ 0 +* 03 PHY0_ADC_ALWAYS_EN_ADCI 0 +* 01 PHY0_HW_MODE_DAC 0 +* 00 PHY0_HW_MODE_ADC 0 +* </pre> +*/ +#define RICU_AFE_CTRL_36_PHY_0_ADDR (REG_RICU_BASE_ADDR + 0x000000A0) +#define RICU_AFE_CTRL_36_PHY_0_OFFSET 0x000000A0 +#define RICU_AFE_CTRL_36_PHY_0_INDEX 0x00000028 +#define RICU_AFE_CTRL_36_PHY_0_RESET 0x00000000 + +static inline u32 ricu_afe_ctrl_36_phy_0_get (struct cl_chip *chip) +{ +return cl_reg_read_chip (chip,RICU_AFE_CTRL_36_PHY_0_ADDR ); +} + +static inline void ricu_afe_ctrl_36_phy_0_set (struct cl_chip *chip,u32 value) +{ +cl_reg_write_chip (chip,RICU_AFE_CTRL_36_PHY_0_ADDR , value); +} + +/* Field definitions */ +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_LD_IR_BIT ((u32)0x00000080) +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_LD_IR_POS 7 +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_LD_AVDQ_BIT ((u32)0x00000040) +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_LD_AVDQ_POS 6 +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_LD_AVDI_BIT ((u32)0x00000020) +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_LD_AVDI_POS 5 +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_ADCQ_BIT ((u32)0x00000010) +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_ADCQ_POS 4 +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_ADCI_BIT ((u32)0x00000008) +#define RICU_AFE_CTRL_36_PHY_0_ADC_ALWAYS_EN_ADCI_POS 3 +#define RICU_AFE_CTRL_36_PHY_0_HW_MODE_DAC_BIT ((u32)0x00000002) +#define RICU_AFE_CTRL_36_PHY_0_HW_MODE_DAC_POS 1 +#define RICU_AFE_CTRL_36_PHY_0_HW_MODE_ADC_BIT ((u32)0x00000001) +#define RICU_AFE_CTRL_36_PHY_0_HW_MODE_ADC_POS 0 + +static inline void ricu_afe_ctrl_36_phy_0_hw_mode_dac_setf (struct cl_chip *chip,u8 phy0hwmodedac) +{ +ASSERT_ERR_CHIP ((((u32 )phy0hwmodedac <<1 ) & ~((u32 )0x00000002 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_36_PHY_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_36_PHY_0_ADDR ) & + ~((u32 )0x00000002 )) | ((u32 )phy0hwmodedac <<1 )); +} + +static inline void ricu_afe_ctrl_36_phy_0_hw_mode_adc_setf (struct cl_chip *chip,u8 phy0hwmodeadc) +{ +ASSERT_ERR_CHIP ((((u32 )phy0hwmodeadc <<0 ) & ~((u32 )0x00000001 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_36_PHY_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_36_PHY_0_ADDR ) & + ~((u32 )0x00000001 )) | ((u32 )phy0hwmodeadc <<0 )); +} + +/* +* @brief AFE_CTRL_34_PHY_1 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 06 PHY1_ADC_SB_IGNORE_FIFO_INDICATION 0 +* 05:02 PHY1_ADC_SB_RD_DELAY 0x4 +* 01:00 PHY1_ADC_SB_MODE 0x0 +* </pre> +*/ +#define RICU_AFE_CTRL_34_PHY_1_ADDR (REG_RICU_BASE_ADDR + 0x000000A4) +#define RICU_AFE_CTRL_34_PHY_1_OFFSET 0x000000A4 +#define RICU_AFE_CTRL_34_PHY_1_INDEX 0x00000029 +#define RICU_AFE_CTRL_34_PHY_1_RESET 0x00000010 + +static inline +void ricu_afe_ctrl_34_phy_1_adc_sb_ignore_fifo_indication_setf (struct cl_chip *chip, +u8 phy1adcsbignorefifoindication) +{ +ASSERT_ERR_CHIP ((((u32 )phy1adcsbignorefifoindication <<6 ) & ~((u32 )0x00000040 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_34_PHY_1_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_34_PHY_1_ADDR ) & + ~((u32 )0x00000040 )) | ((u32 )phy1adcsbignorefifoindication <<6 )); +} + +static inline void ricu_afe_ctrl_34_phy_1_adc_sb_rd_delay_setf (struct cl_chip *chip, +u8 phy1adcsbrddelay) +{ +ASSERT_ERR_CHIP ((((u32 )phy1adcsbrddelay <<2 ) & ~((u32 )0x0000003C )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_34_PHY_1_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_34_PHY_1_ADDR ) & + ~((u32 )0x0000003C )) | ((u32 )phy1adcsbrddelay <<2 )); +} + +/* +* @brief AFE_CTRL_35_PHY_0 register definition +* <pre> +* Bits Field Name Reset Value +* ----- ------------------ ----------- +* 06 PHY0_DAC_SB_IGNORE_FIFO_INDICATION 0 +* 05:02 PHY0_DAC_SB_RD_DELAY 0x1 +* 01:00 PHY0_DAC_SB_MODE 0x0 +* </pre> +*/ +#define RICU_AFE_CTRL_35_PHY_0_ADDR (REG_RICU_BASE_ADDR + 0x000000A8) +#define RICU_AFE_CTRL_35_PHY_0_OFFSET 0x000000A8 +#define RICU_AFE_CTRL_35_PHY_0_INDEX 0x0000002A +#define RICU_AFE_CTRL_35_PHY_0_RESET 0x00000004 + +static inline +void ricu_afe_ctrl_35_phy_0_dac_sb_ignore_fifo_indication_setf (struct cl_chip *chip, +u8 phy0dacsbignorefifoindication) +{ +ASSERT_ERR_CHIP ((((u32 )phy0dacsbignorefifoindication <<6 ) & ~((u32 )0x00000040 )) ==0 ); +cl_reg_write_chip (chip,RICU_AFE_CTRL_35_PHY_0_ADDR , + (cl_reg_read_chip (chip,RICU_AFE_CTRL_35_PHY_0_ADDR ) & + ~((u32 )0x00000040 )) | ((u32 )phy0dacsbignorefifoindication <<6 )); +} + +static inline void ricu_afe_ctrl_35_phy_0_dac_sb_rd_delay_setf (struct cl_chip *chip, +u8 phy0dacsbrddelay) +{ +ASSERT_ERR_CHIP ((((u32 )phy0dacsbrddelay <<2 ) & ~((u32 )0x0000003C )) ==0 ); + cl_reg_write_chip(chip, RICU_AFE_CTRL_35_PHY_0_ADDR, + (cl_reg_read_chip(chip, RICU_AFE_CTRL_35_PHY_0_ADDR) &
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.36.1
Part of the diff is not shown here. View the raw message.
RFC v2 66/96 cl8k: add rfic.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/rfic.c | 232 ++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/rfic.c
drivers/net/wireless/celeno/cl8k/rfic.c new file +232 -0
@@ -0,0 +1,232 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/namei.h> + +#include "reg/reg_defs.h" +#include "phy.h" +#include "utils.h" +#include "rfic.h" + +#define PHY_DEV_NON_PHYSICAL 0x0 +#define MAX_LOOPS 15 +#define READ_REQ 1 +#define WRITE_REQ 0 + +int cl_spi_read (struct cl_hw *cl_hw,u8 page,u8 addr,u8 *val) +{ +struct mm_spi_read_cfm *cfm; +int ret =cl_msg_tx_spi_read (cl_hw, page, addr); + +if (ret) + goto out; + + cfm = (struct mm_spi_read_cfm *)(cl_hw->msg_cfm_params[MM_SPI_READ_CFM ]); +if (!cfm) { + ret = -ENOMSG ; + goto out; + } + +if (cfm->status ==0 ) { + *val = cfm->val; + }else { +cl_dbg_err (cl_hw,"SPI read failed\n" ); + *val =0 ; + } + +cl_msg_tx_free_cfm_params (cl_hw,MM_SPI_READ_CFM ); +return 0 ; + +out: + *val =0 ; +return ret; +} + +static int _cl_spi_driver_read (struct cl_hw *cl_hw,u8 more,u8 addr,u8 *val) +{ +u8 prescaler =4 ; +int loops =MAX_LOOPS ; + +riu_rc_sw_ctrl_pack (cl_hw,1 , more,0 ,0 ,1 ,1 ,1 ,1 , prescaler,READ_REQ , addr,0xFF ); +while (riu_rc_sw_ctrl_start_done_getf (cl_hw) && --loops) + ; + +if (!loops) { +cl_dbg_verbose (cl_hw,"Read error - addr [0x%02x]\n" , addr); +return -EBADE ; + } + + *val =riu_rc_sw_ctrl_data_getf (cl_hw); + +hwreg_pr (cl_hw,"more=%d, addr=0x%x, *val=0x%x\n" , more, addr, *val); + +return 0 ; +} + +static int _cl_spi_driver_write (struct cl_hw *cl_hw,u8 more,u8 addr,u8 val) +{ +u8 prescaler =4 ; +int loops =MAX_LOOPS ; + +hwreg_pr (cl_hw,"more=%d, addr=0x%x, val=0x%x\n" , more, addr, val); + +riu_rc_sw_ctrl_pack (cl_hw,1 , more,0 ,0 ,1 ,1 ,1 ,1 , prescaler,WRITE_REQ , addr, val); + +while (riu_rc_sw_ctrl_start_done_getf (cl_hw) && --loops) + ; + +if (!loops) { +cl_dbg_verbose (cl_hw,"Write error - addr [0x%02x] val [0x%02x]\n" , addr, val); +return -EBADE ; + } + +return 0 ; +} + +int cl_spi_driver_read_byte (struct cl_hw *cl_hw,u8 page,u8 addr,u8 *val) +{ +/* cl_spi_driver_read_byte should only be used when mac fw not loaded, +* else use cl_spi_read +*/ +int ret =0 ; + +spin_lock_bh (&cl_hw->chip->isr_lock); + + ret =_cl_spi_driver_write (cl_hw,1 ,0x03 , page); +if (ret) + goto read_exit; + + ret =_cl_spi_driver_read (cl_hw,0 , addr, val); +if (ret) + goto read_exit; + +read_exit: +spin_unlock_bh (&cl_hw->chip->isr_lock); + +return ret; +} + +static u8 cl_rfic_str_to_cmd (struct cl_hw *cl_hw,char *str) +{ +if (!strcmp (str,"DONE" )) +return OVERWRITE_DONE ; +else if (!strcmp (str,"SPI_R" )) +return SPI_RD_CMD ; +else if (!strcmp (str,"SPI_W" )) +return SPI_WR_CMD ; +else if (!strcmp (str,"GCU_W" )) +return GCU_WR_CMD ; +else if (!strcmp (str,"RIU_W" )) +return RIU_WR_CMD ; +else if (!strcmp (str,"GEN_W" )) +return GEN_WR_CMD ; +else if (!strcmp (str,"DELAY" )) +return UDELAY_CMD ; + +cl_dbg_err (cl_hw,"unknown command %s\n" , str); +return OVERWRITE_DONE ; +} + +static void cl_parse_rf_command (struct cl_hw *cl_hw,char *str, +struct cl_rf_reg_overwrite_info *info) +{ +int i =0 ; +char *ptr =NULL ; +u32 res =0 ; + +while ((ptr =strsep (&str," " )) && (*ptr !='\n' )) { +if (i ==0 ) { + info->cmd =cl_rfic_str_to_cmd (cl_hw, ptr); + }else { +if (kstrtou32 (ptr,16 , &res) !=0 ) { +pr_err ("%s: invalid data - %s\n" , __func__, ptr); +return ; + } + + info->data[i -1 ] =cpu_to_le32 (res); + res =0 ; + } + i++; + } +} + +#define RF_CMD_MAX_LEN 64 + +static void cl_parse_rf_commands_from_buf (struct cl_hw *cl_hw,char *buf,loff_t size, +struct cl_rf_reg_overwrite_info *info) +{ +int i =0 ; +char *line = buf; +char str[RF_CMD_MAX_LEN ]; +char *end; +int line_length =0 ; + +while (line && (line != (buf + size))) { +if ((*line =='#' ) || (*line =='\n' )) { +/* Skip comment or blank line */ + line =strstr (line,"\n" ) +1 ; + }else if (*line) { + end =strstr (line,"\n" ) +1 ; + line_length = end - line; + +if (line_length >=RF_CMD_MAX_LEN ) { +cl_dbg_err (cl_hw,"Command too long (%u)\n" , line_length); +return ; + } + +snprintf (str, line_length,"%s" , line); +cl_parse_rf_command (cl_hw, str, &info[i++]); + line += line_length; + } + } +} + +int cl_rfic_read_overwrite_file (struct cl_hw *cl_hw,struct cl_rf_reg_overwrite_info *info, +bool init) +{ +char *buf =NULL ; +size_t size =0 ; +char filename[CL_FILENAME_MAX ] = {0 }; +char path_name[CL_PATH_MAX ] = {0 }; +struct path path; + +if (init) +snprintf (filename,sizeof (filename),"rf_init_overwrite.txt" ); +else +snprintf (filename,sizeof (filename),"rf_tcv%d_overwrite.txt" , cl_hw->tcv_idx); + +snprintf (path_name,sizeof (path_name),"/lib/firmware/cl8k/%s" , filename); +if (kern_path (path_name,LOOKUP_FOLLOW , &path) <0 ) +return 0 ; + + size =cl_file_open_and_read (cl_hw->chip, filename, &buf); + +if (!buf) +return 0 ; + +cl_dbg_trace (cl_hw,"parsing %s !!!\n" , filename); +cl_parse_rf_commands_from_buf (cl_hw, buf, size, info); +kfree (buf); +return 0 ; +} + +static u8 cl_rfic_version (struct cl_hw *cl_hw) +{ +u8 value =0xff ; +int ret =cl_spi_driver_read_byte (cl_hw,0 ,0 , &value); + +if (ret <0 ) +cl_dbg_err (cl_hw,"%s: spi read failed" , __func__); + +return value; +} + +void cl_chip_set_rfic_version (struct cl_hw *cl_hw) +{/* Read version only on a physical phy */ +if (cl_hw->chip->conf->ci_phy_dev ==PHY_DEV_ATHOS || + cl_hw->chip->conf->ci_phy_dev ==PHY_DEV_OLYMPUS ) { + cl_hw->chip->rfic_version =cl_rfic_version (cl_hw); + }else { + cl_hw->chip->rfic_version =PHY_DEV_NON_PHYSICAL ; + } +}
Signature · 1 line
2.36.1
RFC v2 67/96 cl8k: add rfic.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/rfic.h | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/rfic.h
drivers/net/wireless/celeno/cl8k/rfic.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_RFIC_H +#define CL_RFIC_H + +#include "hw.h" + +#define ATHOS_A_VER 0xB1 +#define ATHOS_B_VER 0xB2 + +enum cl_rf_overwrite_cmd { +OVERWRITE_DONE , +SPI_RD_CMD , +SPI_WR_CMD , +GCU_WR_CMD , +RIU_WR_CMD , +UDELAY_CMD , +GEN_WR_CMD , +RF_OVERWRITE_CMD_MAX =OVERWRITE_DONE +}; + +int cl_spi_driver_read_byte (struct cl_hw *cl_hw,u8 page,u8 addr,u8 *val); +int cl_spi_read (struct cl_hw *cl_hw,u8 page,u8 addr,u8 *val); +int cl_rfic_read_overwrite_file (struct cl_hw *cl_hw, +struct cl_rf_reg_overwrite_info *info, +bool init); +void cl_chip_set_rfic_version (struct cl_hw *cl_hw); +#endif /* CL_RFIC_H */
Signature · 1 line
2.36.1
Re: [RFC v2 67/96] cl8k: add rfic.h
Quoted 27 lines · On 5/24/2022 4:34 AM, [email protected] wrote:
From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
Signed-off-by Viktor Barna <[email protected]>--- drivers/net/wireless/celeno/cl8k/rfic.h | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+)create mode 100644
drivers/net/wireless/celeno/cl8k/rfic.hdrivers/net/wireless/celeno/cl8k/rfic.h new file +10
-0@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_RFIC_H +#define CL_RFIC_H + +#include "hw.h" + +#define ATHOS_A_VER 0xB1 +#define ATHOS_B_VER 0xB2
drivers/net/wireless/celeno/cl8k/rfic.h line 20
Quoted 10 lines
drivers/net/wireless/celeno/cl8k/rfic.h new file +10
-0+ +enum cl_rf_overwrite_cmd { +OVERWRITE_DONE , +SPI_RD_CMD , +SPI_WR_CMD , +GCU_WR_CMD , +RIU_WR_CMD , +UDELAY_CMD , +GEN_WR_CMD , +RF_OVERWRITE_CMD_MAX =OVERWRITE_DONE
consider adding CL_ prefix to the enumerators to avoid namespace collision.
why is OVERWRITE_DONE the max command? that doesn't seem to make sense since other enumerators are defined after it.
Quoted 9 lines
drivers/net/wireless/celeno/cl8k/rfic.h new file +9
-0+}; + +int cl_spi_driver_read_byte (struct cl_hw *cl_hw,u8 page,u8 addr,u8 *val); +int cl_spi_read (struct cl_hw *cl_hw,u8 page,u8 addr,u8 *val); +int cl_rfic_read_overwrite_file (struct cl_hw *cl_hw, +struct cl_rf_reg_overwrite_info *info, +bool init); +void cl_chip_set_rfic_version (struct cl_hw *cl_hw); +#endif /* CL_RFIC_H */
Re: [RFC v2 67/96] cl8k: add rfic.h
Quoted 1 line · On Thu, 2 Jun 2022 13:40:23 -0700, [email protected] wrote:
consider adding
CL_prefix to the enumerators to avoid namespace collision.
Yes, thanks.
Quoted 2 lines
why is
OVERWRITE_DONEthe max command? that doesn't seem to make sense since other enumerators are defined after it.
Agree, that is an odd place. We likely will remove that in the next version of the code.
Best regards,
Viktor Barna
RFC v2 68/96 cl8k: add rx.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/rx.c | 1845 +++++++++++++++++++++++++ 1 file changed, 1845 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/rx.c
drivers/net/wireless/celeno/cl8k/rx.c new file +1845 -0
@@ -0,0 +1,1845 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/skbuff.h> +#include <net/mac80211.h> + +#include "tx.h" +#include "stats.h" +#include "rates.h" +#include "vns.h" +#include "dfs.h" +#include "recovery.h" +#include "def.h" +#include "mac80211.h" +#include "reg/reg_defs.h" +#include "key.h" +#include "utils.h" +#include "radio.h" +#include "vif.h" +#include "rx.h" + +/* Must correspond to FW definition of MM_SEC_DEFAULT_KEY_COUNT */ +#define MM_SEC_DEFAULT_KEY_COUNT 64 + +#define VHT_MCS_MASK 0x0F +#define VHT_MCS_OFT 0 + +/* Number of entries in HW legacy rate conversion table */ +#define LEGACY_RATE_MAX 16 +#define KSR_MGTK_BCAST_OFFSET 31 +#define KSR_BLOCK_SIZE 4 + +static const s8 legacy_rates_lut[LEGACY_RATE_MAX ] = { +0 ,/* 0: 1 Mbps */ +1 ,/* 1: 2 Mbps */ +2 ,/* 2: 5.5 Mbps */ +3 ,/* 3: 11 Mbps */ +-1 ,/* 4: Invalid */ +-1 ,/* 5: Invalid */ +-1 ,/* 6: Invalid */ +-1 ,/* 7: Invalid */ +10 ,/* 8: 48 Mbps */ +8 ,/* 9: 24 Mbps */ +6 ,/* 10: 12 Mbps */ +4 ,/* 11: 6 Mbps */ +11 ,/* 12: 54 Mbps */ +9 ,/* 13: 36 Mbps */ +7 ,/* 14: 18 Mbps */ +5 /* 15: 9 Mbps */ +}; + +/* +* rx_skb_cnt is an atomic counter that tracks the total number of skbs in +* the entire host. +* The counter is incremented when skb is allocated, and freed when the skb +* is freed (=destructor function called). +* Therefore the counter is global (and not part of cl_hw or cl_chip). +* +* rx_skb_max is the configured to: +* max(chip0->conf->ci_rx_skb_max, chip1->conf->ci_rx_skb_max) +*/ +static atomic_t rx_skb_cnt =ATOMIC_INIT (0 ); +static u32 rx_skb_max; + +static void cl_rx_skb_destructor (struct sk_buff *skb) +{ +atomic_dec (&rx_skb_cnt); +} + +static void cl_rx_skb_success (struct cl_vif *cl_vif,struct ieee80211_hdr *hdr, +u32 rx_packets,u32 rx_bytes) +{ +if (cl_vif) { +u8 ac =cl_rx_get_skb_ac (hdr); + + cl_vif->trfc_cntrs[ac].rx_packets += rx_packets; + cl_vif->trfc_cntrs[ac].rx_bytes += rx_bytes; + } +} + +static DEFINE_PER_CPU(struct tasklet_struct, rx_remote_tasklet_mac[TCV_TOTAL]); + +static call_single_data_t csd_rx_remote_cpu_mac[TCV_TOTAL ]; +static void cl_rx_remote_cpu_mac (struct cl_hw *cl_hw) +{ +int cpu = cl_hw->conf->ci_rx_remote_cpu_mac; +struct tasklet_struct *t = csd_rx_remote_cpu_mac[cl_hw->idx].info; + +if (!test_bit (TASKLET_STATE_SCHED , &t->state)) +smp_call_function_single_async (cpu, &csd_rx_remote_cpu_mac[cl_hw->idx]); +} + +static int cl_rx_check_err (struct cl_hw *cl_hw,struct sk_buff *skb,struct hw_rxhdr *rxhdr) +{ +u32 status; + +if (rxhdr->frm_successful_rx) +return 0 ; + +/* The status field is in offset of 14 u32's */ + status = *((u32 *)rxhdr +14 ); + +/* Ignore phy errors and do not drop the packet */ +if (rxhdr->phy_err) { + cl_hw->radio_stats[CL_RADIO_PHY_ERROR ]++; +cl_dbg_warn (cl_hw,"phy_err (status 0x%x)\n" , status); +return 0 ; + } + +/* From this point and on, drop the erroneous packets */ +if (rxhdr->fcs_err) { + cl_hw->radio_stats[CL_RADIO_FCS_ERROR ]++; +cl_dbg_err (cl_hw,"fcs_err (status 0x%x)\n" , status); + } + +if (rxhdr->rx_fifo_oflow) { + cl_hw->radio_stats[CL_RADIO_RX_FIFO_OVERFLOW ]++; +cl_dbg_err (cl_hw,"rx_fifo_oflow (status 0x%x)\n" , status); + } + +if (rxhdr->undef_err) { + cl_hw->radio_stats[CL_RADIO_UNDEFINED_ERROR ]++; +cl_dbg_err (cl_hw,"undef_err (status 0x%x)\n" , status); + } + +if (rxhdr->addr_mismatch) { + cl_hw->radio_stats[CL_RADIO_ADDRESS_MISMATCH ]++; +cl_dbg_err (cl_hw,"addr_mismatch (status 0x%x)\n" , status); + } + +if (rxhdr->amsdu_present && rxhdr->msdu_cnt >1 ) +cl_rx_amsdu_set_state_error (cl_hw, rxhdr,RX_AMSDU_ERR_NOT_SUCCESS ); + + cl_hw->rx_info.pkt_drop_not_success++; +cl_rx_skb_error (cl_hw); +kfree_skb (skb); + +return -EBADMSG ; +} + +static u8 chnl_bw_to_rate_info_bw[CHNL_BW_MAX ] = { + [CHNL_BW_20 ] =RATE_INFO_BW_20 , + [CHNL_BW_40 ] =RATE_INFO_BW_40 , + [CHNL_BW_80 ] =RATE_INFO_BW_80 , + [CHNL_BW_160 ] =RATE_INFO_BW_160 , +}; + +static u8 chnl_bw_factor[CHNL_BW_MAX ] = { + [CHNL_BW_20 ] =0 , + [CHNL_BW_40 ] =3 , + [CHNL_BW_80 ] =6 , + [CHNL_BW_160 ] =9 , +}; + +static int cl_rx_fill_status (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct sk_buff *skb, +struct hw_rxhdr *rxhdr,u8 *encrypt_len) +{ +s8 rssi[MAX_ANTENNAS ] =RX_HDR_RSSI (rxhdr); +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct ieee80211_rx_status *status =IEEE80211_SKB_RXCB (skb); +u8 tid =ieee80211_get_tid (hdr); + +memset (status,0 ,sizeof (struct ieee80211_rx_status )); + + status->mactime = ((u64 )le32_to_cpu ((rxhdr->tsf_hi)) <<32 ) |le32_to_cpu (rxhdr->tsf_lo); + status->flag |=RX_FLAG_MACTIME_END ; + +if (cl_sta && cl_sta->tid_agg_rx[tid]) + status->flag |=RX_FLAG_DUP_VALIDATED ; + + status->antenna = rxhdr->antenna_set; + status->band =cl_band_from_fw_idx (rxhdr->phy_band); + +if (rxhdr->format_mod >=FORMATMOD_HE_SU ) { + status->encoding =RX_ENC_HE ; + status->rate_idx = (rxhdr->mcs &VHT_MCS_MASK ) >>VHT_MCS_OFT ; + status->nss = rxhdr->n_sts +1 ; + +/* he_gi expectes to get values according to enum nl80211_he_gi */ + status->he_gi =cl_convert_gi_format_wrs_to_fw (WRS_MODE_HE , rxhdr->gi_type); + }else if (rxhdr->format_mod ==FORMATMOD_VHT ) { + status->encoding =RX_ENC_VHT ; + status->rate_idx = (rxhdr->mcs &VHT_MCS_MASK ) >>VHT_MCS_OFT ; + status->nss = rxhdr->n_sts +1 ; + +if (rxhdr->gi_type) + status->enc_flags |=RX_ENC_FLAG_SHORT_GI ; + }else if (rxhdr->format_mod ==FORMATMOD_HT_GF ) { + status->encoding =RX_ENC_HT ; + status->enc_flags |=RX_ENC_FLAG_HT_GF ; + status->rate_idx = rxhdr->mcs; + +if (rxhdr->gi_type) + status->enc_flags |=RX_ENC_FLAG_SHORT_GI ; + + }else if (rxhdr->format_mod ==FORMATMOD_HT_MF ) { + status->encoding =RX_ENC_HT ; + status->rate_idx = rxhdr->mcs; + +if (rxhdr->gi_type) + status->enc_flags |=RX_ENC_FLAG_SHORT_GI ; + }else { +if (legacy_rates_lut[rxhdr->leg_rate] !=-1 ) + status->rate_idx = legacy_rates_lut[rxhdr->leg_rate]; +if (status->band !=NL80211_BAND_2GHZ ) + status->rate_idx -=RATE_CTRL_OFFSET_OFDM ; +if (!rxhdr->pre_type) + status->enc_flags |=RX_ENC_FLAG_SHORTPRE ; + } + +if (rxhdr->aggregation) { + status->flag |=RX_FLAG_AMPDU_DETAILS ; + status->ampdu_reference = rxhdr->ampdu_cnt; + } + +/* +* Set bw field +*/ +if (rxhdr->ru_type) { + status->bw =RATE_INFO_BW_HE_RU ; + +if (rxhdr->ru_type ==CL_MU_OFDMA_RU_TYPE_26 ) +cl_rssi_bw_adjust (cl_hw, rxhdr,-9 ); +else if (rxhdr->ru_type ==CL_MU_OFDMA_RU_TYPE_52 ) +cl_rssi_bw_adjust (cl_hw, rxhdr,-6 ); +else if (rxhdr->ru_type ==CL_MU_OFDMA_RU_TYPE_106 ) +cl_rssi_bw_adjust (cl_hw, rxhdr,-3 ); + + status->he_ru =cl_ru_type_to_nl80211_he_ru_alloc (rxhdr->ru_type); + }else { +u8 factor = chnl_bw_factor[rxhdr->ch_bw]; + + status->bw = chnl_bw_to_rate_info_bw[rxhdr->ch_bw]; +cl_rssi_bw_adjust (cl_hw, rxhdr, factor); + } + +/* +* TODO: check if when a frame is received on 40MHz or more bandwidth, +* we need to take the center1_freq instead of the prim20_freq +*/ + status->freq =Q2_TO_FREQ (rxhdr->phy_prim20_freq); + + status->signal =cl_rssi_calc_equivalent (cl_hw, rssi); + +switch (rxhdr->decr_status) { +case CL_RX_HDR_DECR_UNENC : +if (!ieee80211_has_protected (hdr->frame_control)) +break ; + +cl_dbg_warn (cl_hw,"Protected frame unencrypted\n" ); + cl_hw->rx_info.pkt_drop_unencrypted++; +if (rxhdr->amsdu_present && rxhdr->msdu_cnt >1 ) +cl_rx_amsdu_set_state_error (cl_hw, rxhdr, +RX_AMSDU_ERR_UNENCRYPTED ); +return -EBADMSG ; +case CL_RX_HDR_DECR_ICVFAIL : +case CL_RX_HDR_DECR_AMSDUDISCARD : +case CL_RX_HDR_DECR_NULLKEY : +case CL_RX_HDR_DECR_CCMPFAIL : +cl_dbg_warn (cl_hw,"Decryption failed (%u)\n" , rxhdr->decr_status); + cl_hw->rx_info.pkt_drop_decrypt_fail++; + *encrypt_len =0 ; +if (rxhdr->amsdu_present && rxhdr->msdu_cnt >1 ) +cl_rx_amsdu_set_state_error (cl_hw, rxhdr,RX_AMSDU_ERR_DECRYPT_FAIL ); +return -EBADMSG ; +case CL_RX_HDR_DECR_WEPSUCCESS : +case CL_RX_HDR_DECR_TKIPSUCCESS : + *encrypt_len =IEEE80211_WEP_ICV_LEN ; + status->flag |= (RX_FLAG_DECRYPTED |RX_FLAG_ICV_STRIPPED ); +break ; +case CL_RX_HDR_DECR_CCMPSUCCESS : + *encrypt_len =IEEE80211_CCMP_HDR_LEN ; + status->flag |= (RX_FLAG_DECRYPTED |RX_FLAG_MIC_STRIPPED ); +break ; + } + +return 0 ; +} + +static void cl_rx_handle_mesh_reconnect (struct cl_hw *cl_hw, +struct ieee80211_mgmt *mgmt,struct cl_sta *cl_sta) +{ +struct ieee80211_sta *sta = cl_sta->sta; +struct cl_tx_queue *tx_queue; +u8 action_code = mgmt->u.action.u.self_prot.action_code; +u8 i; + +if (action_code ==WLAN_SP_MESH_PEERING_CONFIRM ) { +for (i =0 ; i <IEEE80211_NUM_TIDS ; i++) { + tx_queue = cl_sta->agg_tx_queues[i]; + +if (tx_queue) +ieee80211_stop_tx_ba_session (sta, i); + } + } +} + +static void cl_rx_action_frame_handler (struct cl_hw *cl_hw,struct cl_ieee80211_mgmt *mgmt, +int len,struct cl_sta *cl_sta) +{ +/* Verify action code is present */ +if (len <IEEE80211_MIN_ACTION_SIZE +1 ) +return ; + +switch (mgmt->u.action.category) { +case WLAN_CATEGORY_WNM : +break ; +case WLAN_CATEGORY_SELF_PROTECTED : +if (cl_sta && cl_sta->cl_vif->vif->type ==NL80211_IFTYPE_MESH_POINT ) +cl_rx_handle_mesh_reconnect (cl_hw, (struct ieee80211_mgmt *)mgmt, cl_sta); +break ; +default : +break ; + } +} + +static struct ieee80211_he_6ghz_oper * +cl_rx_get_he_6ghz_oper (const struct ieee80211_he_operation *he_oper) +{ +const u8 *ret = (void *)&he_oper->optional; +u32 he_oper_params; + + he_oper_params =le32_to_cpu (he_oper->he_oper_params); + +if (!(he_oper_params &IEEE80211_HE_OPERATION_6GHZ_OP_INFO )) +return NULL ; +if (he_oper_params &IEEE80211_HE_OPERATION_VHT_OPER_INFO ) + ret +=3 ; +if (he_oper_params &IEEE80211_HE_OPERATION_CO_HOSTED_BSS ) + ret++; + +return (void *)ret; +} + +static void +cl_rx_check_he_minrate_change (struct cl_sta *cl_sta, +const struct ieee80211_he_operation *he_oper) +{ +struct ieee80211_he_6ghz_oper * + he_6ghz_oper =cl_rx_get_he_6ghz_oper (he_oper); + +if (!he_6ghz_oper) +return ; + +if (he_6ghz_oper->minrate != cl_sta->wrs_sta.he_minrate) +cl_wrs_api_he_minrate_changed (cl_sta, he_6ghz_oper->minrate); +} + +static void cl_rx_handle_beacon (struct cl_hw *cl_hw, +struct sk_buff *skb, +struct cl_sta *cl_sta) +{ +struct ieee802_11_elems elems; +struct cl_vif *cl_vif = cl_sta->cl_vif; +struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; + size_t baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable); +struct ieee80211_bss_conf *bss_conf = &cl_vif->vif->bss_conf; + +if (cl_vif->vif->type !=NL80211_IFTYPE_STATION ) +return ; + +cl_ieee802_11_parse_elems (mgmt->u.beacon.variable, skb->len - baselen, &elems); + +if (!elems.parse_error && elems.he_operation && bss_conf->he_support) +cl_rx_check_he_minrate_change (cl_sta, elems.he_operation); +} + +static bool cl_rx_mgmt_check (struct cl_hw *cl_hw,struct sk_buff *skb, +struct cl_vif *cl_vif,struct cl_sta *cl_sta, +struct hw_rxhdr *rxhdr) +{ +struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; +__le16 fc = mgmt->frame_control; + +if (!ieee80211_is_mgmt (fc)) +return true; + +if (cl_sta) { +if (ieee80211_is_beacon (fc)) +cl_rx_handle_beacon (cl_hw, skb, cl_sta); +else if (ieee80211_is_action (fc)) +cl_rx_action_frame_handler (cl_hw, (struct cl_ieee80211_mgmt *)mgmt, + skb->len, cl_sta); + }else { +s8 rssi[MAX_ANTENNAS ] =RX_HDR_RSSI (rxhdr); + +cl_vns_mgmt_handler (cl_hw, mgmt->sa, rssi); + +if (ieee80211_is_assoc_req (fc) ||ieee80211_is_assoc_resp (fc)) { +cl_rssi_assoc_handle (cl_hw, mgmt->sa, rxhdr); +return true; + } + } + +return true; +} + +static void cl_rx_data_check (struct cl_hw *cl_hw,struct sk_buff *skb, +struct cl_sta *cl_sta,u32 packet_len,struct hw_rxhdr *rxhdr) +{ +if (cl_sta) { +cl_traffic_rx_handler (cl_hw, cl_sta, packet_len); + +if (!rxhdr->aggregation || (rxhdr->aggregation && rxhdr->mpdu_cnt ==0 )) +cl_motion_sense_rssi_data (cl_hw, cl_sta, rxhdr); + } +} + +static bool cl_rx_skb_done (struct cl_hw *cl_hw,struct sk_buff *skb, +struct cl_sta *cl_sta,struct hw_rxhdr *rxhdr) +{ +struct ieee80211_rx_status *status =IEEE80211_SKB_RXCB (skb); +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +__le16 fc = hdr->frame_control; +struct cl_vif *cl_vif =NULL ; + +/* Update trigger base statistics */ +cl_fw_dbg_trigger_based_update (cl_hw, rxhdr, hdr); +cl_fw_dbg_trigger_based_sta_update (cl_hw, rxhdr, hdr); + +if (cl_sta) { + cl_vif = cl_sta->cl_vif; + skb->dev = cl_vif->dev; + +cl_stats_update_rx_rate (cl_hw, cl_sta, rxhdr); + +if (!rxhdr->aggregation || (rxhdr->aggregation && rxhdr->mpdu_cnt ==0 )) +cl_rssi_rx_handler (cl_hw, cl_sta, rxhdr, status->signal); + }else { + cl_vif =cl_vif_get_by_mac (cl_hw, hdr->addr3); + skb->dev = cl_vif ? cl_vif->dev :NULL ; + +if (cl_hw_is_prod_or_listener (cl_hw)) +cl_stats_update_rx_rate_production (cl_hw, rxhdr); + } + +/* DATA */ +if (ieee80211_is_data (fc)) { +cl_wrs_update_rx_rate (cl_hw, cl_sta, rxhdr); +cl_rx_data_check (cl_hw, skb, cl_sta, skb->len, rxhdr); + goto out; + } + +/* MGMT/CTL */ +if (cl_sta) +cl_motion_sense_rssi_mgmt_ctl (cl_hw, cl_sta, rxhdr); + +/* MGMT */ +if (!cl_rx_mgmt_check (cl_hw, skb, cl_vif, cl_sta, rxhdr)) +return false; + +out: +if (rx_skb_max && +atomic_read (&rx_skb_cnt) >= rx_skb_max) { + cl_hw->rx_info.pkt_drop_host_limit++; +cl_rx_skb_drop (cl_hw, skb,1 ); +kfree_skb (skb); +return false; + } + +cl_rx_skb_success (cl_vif, hdr,1 , skb->len); + +return true; +} + +static void cl_rx_pass_to_mac (struct cl_hw *cl_hw, +struct ieee80211_sta *sta, +struct sk_buff_head *frames) +{ +if (cl_hw->conf->ci_rx_remote_cpu_mac ==-1 ) { +struct sk_buff *skb =NULL ; + +while ((skb =__skb_dequeue (frames))) +ieee80211_rx_napi (cl_hw->hw, sta, skb,NULL ); + }else { +struct sk_buff_head *rx_remote_queue_mac = &cl_hw->rx_remote_queue_mac; + +spin_lock (&rx_remote_queue_mac->lock); +skb_queue_splice_tail_init (frames, rx_remote_queue_mac); +spin_unlock (&rx_remote_queue_mac->lock); + +cl_rx_remote_cpu_mac (cl_hw); + } +} + +static void cl_rx_amsdu_done_reorder (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff_head *frames) +{ +struct sk_buff *skb =NULL ; +struct sk_buff_head reorder_buf; + +/* Init the reorder buffer */ +__skb_queue_head_init (&reorder_buf); + +while ((skb =__skb_dequeue (frames))) +cl_rx_reorder_ampdu (cl_hw, cl_sta, skb, &reorder_buf); + +if (!skb_queue_empty (&reorder_buf)) +cl_rx_pass_to_mac (cl_hw, cl_sta->sta, &reorder_buf); +} + +static void cl_rx_amsdu_done (struct cl_hw *cl_hw,struct cl_amsdu_rx_state *amsdu_rx_state) +{ +struct sk_buff_head *frames = &amsdu_rx_state->frames; +struct sk_buff *skb =__skb_peek (frames); +struct ieee80211_rx_status *status =IEEE80211_SKB_RXCB (skb); +struct cl_sta *cl_sta; +struct cl_vif *cl_vif; +struct hw_rxhdr *rxhdr = amsdu_rx_state->rxhdr; +u32 packet_len = amsdu_rx_state->packet_len; +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct ieee80211_sta *sta; + +if (cl_rx_amsdu_check_aggregation_attack (amsdu_rx_state)) { + cl_hw->rx_info.pkt_drop_amsdu_inj_attack += amsdu_rx_state->msdu_cnt; +__skb_queue_purge (frames); +return ; + } + +/* START - cl_sta protected block */ +cl_sta_lock (cl_hw); + cl_sta =cl_sta_get (cl_hw, amsdu_rx_state->sta_idx); + +if (!cl_sta) { +cl_sta_unlock (cl_hw); + cl_hw->rx_info.pkt_drop_sta_null += amsdu_rx_state->msdu_cnt; +__skb_queue_purge (frames); +return ; + } + + sta = cl_sta->sta; + cl_vif = cl_sta->cl_vif; + skb->dev = cl_vif->dev; + +cl_rx_data_check (cl_hw, skb, cl_sta, packet_len, rxhdr); +cl_stats_update_rx_rate (cl_hw, cl_sta, rxhdr); +cl_wrs_update_rx_rate (cl_hw, cl_sta, rxhdr); + +if (!rxhdr->aggregation || (rxhdr->aggregation && rxhdr->mpdu_cnt ==0 )) +cl_rssi_rx_handler (cl_hw, cl_sta, rxhdr, status->signal); + +cl_sta_unlock (cl_hw); +/* END - cl_sta protected block */ + +if (rx_skb_max && + (atomic_read (&rx_skb_cnt) + amsdu_rx_state->msdu_cnt) >= rx_skb_max) { + cl_hw->rx_info.pkt_drop_host_limit += amsdu_rx_state->msdu_cnt; +cl_rx_skb_drop (cl_hw, skb, amsdu_rx_state->msdu_cnt); +__skb_queue_purge (frames); +return ; + } + +cl_rx_skb_success (cl_vif, hdr, rxhdr->msdu_cnt, packet_len); + +if (cl_sta->tid_agg_rx[amsdu_rx_state->tid]) +cl_rx_amsdu_done_reorder (cl_hw, cl_sta, frames); +else +cl_rx_pass_to_mac (cl_hw, sta, frames); +} + +static void cl_rx_invalid_tailroom (struct cl_hw *cl_hw,struct hw_rxhdr *rxhdr, +struct sk_buff *skb,u32 len) +{ +cl_dbg_err (cl_hw,"Invalid RX header length - tailroom=%d, len=%u\n" , +skb_tailroom (skb), len); + +if (rxhdr->amsdu_present && rxhdr->msdu_cnt >1 ) +cl_rx_amsdu_set_state_error (cl_hw, rxhdr,RX_AMSDU_ERR_INVALID_TAILROOM ); + + cl_hw->rx_info.pkt_drop_tailroom_error++; +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +} + +static void cl_rx_invalid_pattern (struct cl_hw *cl_hw,struct sk_buff *skb,u32 pattern) +{ +cl_dbg_err (cl_hw,"WRONG PATTERN - 0x%x\n" , pattern); + cl_hw->rx_info.pkt_drop_wrong_pattern++; +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +} + +static int cl_rx_get_sta_idx (struct cl_hw *cl_hw,struct hw_rxhdr *rxhdr) +{ +int sta_idx = rxhdr->key_sram_index -MM_SEC_DEFAULT_KEY_COUNT ; +u8 vif_type; + +if (sta_idx <0 ) { + vif_type =cl_hw_get_iface_conf (cl_hw); +if (vif_type ==CL_IFCONF_MESH_AP || vif_type ==CL_IFCONF_MESH_ONLY ) { + sta_idx +=KSR_MGTK_BCAST_OFFSET ; + sta_idx /=KSR_BLOCK_SIZE ; + } + } + +if (sta_idx >=0 && sta_idx <CL_MAX_NUM_STA ) +return sta_idx; + +cl_dbg_err (cl_hw,"invalid sta_idx %d, key_sram_index=%d\n" , + sta_idx, rxhdr->key_sram_index); + +return -EINVAL ; +} + +static void cl_rx_handle_first_amsdu (struct cl_hw *cl_hw,struct sk_buff *skb, +struct cl_amsdu_rx_state *amsdu_rx_state, +struct hw_rxhdr *rxhdr,u8 sta_idx,u8 tid,u8 encrypt_len) +{ +/* +* First MSDU recived frame: +* ------------------------------------------ +* || WLAN_HDR || MSDU HDR || MSDU PAYLOAD || +* ------------------------------------------ +*/ +cl_rx_amsdu_stats (cl_hw, rxhdr->msdu_cnt); + +if (rxhdr->corrupted_amsdu) { +cl_rx_amsdu_first_corrupted (cl_hw, skb, rxhdr); + }else { +cl_rx_amsdu_first (cl_hw, skb, rxhdr, sta_idx, tid, encrypt_len); + +/* If there are more MSDU's, hold on with the update +* to the upper layer until A-MSDU is complete +*/ +if (amsdu_rx_state->msdu_remaining_cnt ==0 ) +cl_rx_amsdu_done (cl_hw, amsdu_rx_state); + } +} + +static void cl_rx_handle_sub_amsdu (struct cl_hw *cl_hw,struct sk_buff *skb, +struct cl_amsdu_rx_state *amsdu_rx_state) +{ +/* Update the remaining MSDU counter */ + amsdu_rx_state->msdu_remaining_cnt--; + +/* Free MSDU with error */ +if (amsdu_rx_state->amsdu_error) { +cl_rx_amsdu_sub_error (cl_hw, skb); +return ; + } + +/* Add the sub-MSDU to the existing ones */ +if (!cl_rx_amsdu_sub (cl_hw, skb)) +return ; + +/* This is the last MSDU, A-MSDU is complete, push to upper layer */ +if (amsdu_rx_state->msdu_remaining_cnt ==0 ) +cl_rx_amsdu_done (cl_hw, amsdu_rx_state); +} + +static void cl_rx_handle_ps (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct sk_buff *skb) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); +struct ieee80211_sta *sta = cl_sta->sta; +bool is_ps; +__le16 fc = hdr->frame_control; + +if (ieee80211_is_pspoll (fc) || +ieee80211_has_morefrags (fc) || + !(ieee80211_is_mgmt (fc) || +ieee80211_is_data (fc))) +return ; + + is_ps =ieee80211_has_pm (hdr->frame_control); + +cl_sta_ps_notify (cl_hw, cl_sta, is_ps); +ieee80211_sta_ps_transition (sta, is_ps); +} + +static void cl_rx_shift_rxhdr_rssi_values (struct cl_hw *cl_hw,struct hw_rxhdr *rxhdr) +{ +/* Fill in the rxhdr rssi "holes" so that values will start from rssi1 */ +switch (cl_hw->first_riu_chain) { +case 1 : + rxhdr->rssi1 = rxhdr->rssi2; + rxhdr->rssi2 = rxhdr->rssi3; + rxhdr->rssi3 = rxhdr->rssi4; + rxhdr->rssi4 = rxhdr->rssi5; + rxhdr->rssi5 = rxhdr->rssi6; +break ; +case 2 : + rxhdr->rssi1 = rxhdr->rssi3; + rxhdr->rssi2 = rxhdr->rssi4; + rxhdr->rssi3 = rxhdr->rssi5; + rxhdr->rssi4 = rxhdr->rssi6; +break ; +case 3 : + rxhdr->rssi1 = rxhdr->rssi4; + rxhdr->rssi2 = rxhdr->rssi5; + rxhdr->rssi3 = rxhdr->rssi6; +break ; +case 4 : + rxhdr->rssi1 = rxhdr->rssi5; + rxhdr->rssi2 = rxhdr->rssi6; +break ; +case 5 : + rxhdr->rssi1 = rxhdr->rssi6; +break ; +default : +break ; + } +} + +static void cl_rx_handle_skb (struct cl_hw *cl_hw,struct sk_buff *skb) +{ +u8 encrypt_len =0 ; +u8 tid =0 ; +u32 mpdu_offset =0 ; +u32 len =0 ; +int sta_idx =-1 ; +bool skb_done = false; +struct cl_sta *cl_sta =NULL ; +struct ieee80211_sta *sta =NULL ; +struct hw_rxhdr *rxhdr =NULL ; +struct cl_tid_ampdu_rx *tid_agg_rx =NULL ; +struct cl_amsdu_rx_state *amsdu_rx_state = &cl_hw->amsdu_rx_state; +s8 remote_cpu_mac = cl_hw->conf->ci_rx_remote_cpu_mac; + +if (amsdu_rx_state->msdu_remaining_cnt >0 ) { +cl_rx_handle_sub_amsdu (cl_hw, skb, amsdu_rx_state); +return ; + } + + rxhdr = (struct hw_rxhdr *)skb->data; + mpdu_offset =sizeof (struct hw_rxhdr ); + +if (rxhdr->rx_padding_done) + mpdu_offset +=CL_PADDING_IN_BYTES ; + +/* Pull the HW RX header */ +skb_reserve (skb, mpdu_offset); + +/* +* Sanity check - the embedded layer is responsible to validate the pattern correctness. +* If pattern is invalid then it is likely that the embedded layer did some thing wrong. +*/ +if (le32_to_cpu (rxhdr->pattern) !=IPC_RX_DMA_OVER_PATTERN ) { +cl_rx_invalid_pattern (cl_hw, skb,le32_to_cpu (rxhdr->pattern)); +return ; + } + +if (cl_rx_check_err (cl_hw, skb, rxhdr)) +return ; + +/* Convert gi from firmware format to driver format */ + rxhdr->gi_type =cl_convert_gi_format_fw_to_wrs (rxhdr->format_mod, rxhdr->gi_type); + +if (cl_hw->first_riu_chain >0 ) +cl_rx_shift_rxhdr_rssi_values (cl_hw, rxhdr); + +if (cl_hw->rssi_simulate) +cl_rssi_simulate (cl_hw, rxhdr); + +if (rxhdr->key_sram_v) + sta_idx =cl_rx_get_sta_idx (cl_hw, rxhdr); + +cl_sta_lock (cl_hw); + +if (sta_idx !=-1 ) { + cl_sta =cl_sta_get (cl_hw, sta_idx); + +if (cl_sta) { + sta = cl_sta->sta; + +if (cl_hw->conf->ci_fast_rx_en) { + tid =ieee80211_get_tid ((struct ieee80211_hdr *)skb->data); + tid_agg_rx = cl_sta->tid_agg_rx[tid]; +cl_rx_handle_ps (cl_hw, cl_sta, skb); + } + +/* Store the pointer to sta in the skb->sk field */ +if (remote_cpu_mac !=-1 ) + skb->sk = (struct sock *)sta; + } + } + +if (unlikely (cl_rx_fill_status (cl_hw, cl_sta, skb, rxhdr, &encrypt_len))) { +cl_sta_unlock (cl_hw); +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +return ; + } + +/* Is A-MSDU frame? */ +if (rxhdr->amsdu_present) { +cl_rx_handle_first_amsdu (cl_hw, skb, amsdu_rx_state, rxhdr, sta_idx, + tid, encrypt_len); +cl_sta_unlock (cl_hw); +return ; + } + + len = rxhdr->len; + +if (skb_tailroom (skb) >= len) { +/* Push the WLAN HDR + MDPU payload to the skb data */ +skb_put (skb, len); + cl_hw->rx_info.non_amsdu++; + }else { +cl_sta_unlock (cl_hw); +cl_rx_invalid_tailroom (cl_hw, rxhdr, skb, len); +return ; + } + + skb_done =cl_rx_skb_done (cl_hw, skb, cl_sta, rxhdr); + +cl_sta_unlock (cl_hw); + +if (!skb_done) +return ; + +if (tid_agg_rx) { +struct sk_buff_head reorder_buf; + +/* Init the reorder buffer */ +__skb_queue_head_init (&reorder_buf); +cl_rx_reorder_ampdu (cl_hw, cl_sta, skb, &reorder_buf); + +if (!skb_queue_empty (&reorder_buf)) +cl_rx_pass_to_mac (cl_hw, sta, &reorder_buf); + }else { +if (cl_key_handle_pn_validation (cl_hw, skb, cl_sta) ==CL_PN_VALID_STATE_FAILED ) { +kfree_skb (skb); +return ; + } + +if (remote_cpu_mac ==-1 ) { +ieee80211_rx_napi (cl_hw->hw, sta, skb,NULL ); + }else { +skb_queue_tail (&cl_hw->rx_remote_queue_mac, skb); +cl_rx_remote_cpu_mac (cl_hw); + } + } +} + +static bool cl_is_rx_allowed (struct cl_hw *cl_hw) +{ +return !(cl_radio_is_off (cl_hw) || + !test_bit (CL_DEV_STARTED , &cl_hw->drv_flags) || +test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags) || +cl_recovery_in_progress (cl_hw)); +} + +static void cl_rx_tasklet (unsigned long data) +{ +struct cl_hw *cl_hw = (struct cl_hw *)data; +struct sk_buff *skb =NULL ; +u16 pkt_cnt =0 ; + +if (unlikely (!cl_is_rx_allowed (cl_hw))) +return ; + +while ((skb =skb_dequeue (&cl_hw->rx_skb_queue))) { +cl_rx_handle_skb (cl_hw, skb); + +if (++pkt_cnt > cl_hw->conf->ce_rx_pkts_budget) { +if (cl_hw->chip->conf->ci_rx_resched_tasklet) +tasklet_schedule (&cl_hw->rx_resched_tasklet); +else +tasklet_schedule (&cl_hw->rx_tasklet); + + cl_hw->rx_info.exceed_pkt_budget++; +return ; + } + } +} + +static void cl_rx_resched_tasklet (unsigned long data) +{ +struct cl_hw *cl_hw = (struct cl_hw *)data; + +tasklet_schedule (&cl_hw->rx_tasklet); +} + +static void cl_rx_remote_tasklet_mac (unsigned long data) +{ +struct cl_hw *cl_hw = (struct cl_hw *)data; +struct sk_buff *skb =NULL ; +struct ieee80211_sta *sta; + +if (unlikely (!cl_is_rx_allowed (cl_hw))) +return ; + +cl_rx_remote_cpu_info (cl_hw); + +while ((skb =skb_dequeue (&cl_hw->rx_remote_queue_mac))) { +/* +* Get sta pointer from skb->sk (stored their in cl_rx_remote_cpu_mac) +* and reset skb->sk. +*/ + sta = (struct ieee80211_sta *)skb->sk; + skb->sk =NULL ; + +ieee80211_rx_napi (cl_hw->hw, sta, skb,NULL ); + } +} + +void cl_rx_init (struct cl_hw *cl_hw) +{ +s8 cpu_mac = cl_hw->conf->ci_rx_remote_cpu_mac; + +/* Set rx_skb_max to be the maximum of ci_rx_skb_max configured for each chip */ + rx_skb_max =max (cl_hw->chip->conf->ci_rx_skb_max, rx_skb_max); + +skb_queue_head_init (&cl_hw->rx_remote_queue_mac); +skb_queue_head_init (&cl_hw->rx_skb_queue); +__skb_queue_head_init (&cl_hw->amsdu_rx_state.frames); + +tasklet_init (&cl_hw->rx_tasklet, cl_rx_tasklet, (unsigned long )cl_hw); +tasklet_init (&cl_hw->rx_resched_tasklet, cl_rx_resched_tasklet, (unsigned long )cl_hw); + +if (cpu_mac >=0 ) { +struct tasklet_struct *t = &per_cpu (rx_remote_tasklet_mac[cl_hw->idx], cpu_mac); + +tasklet_init (t, + cl_rx_remote_tasklet_mac, + (unsigned long )cl_hw); + + csd_rx_remote_cpu_mac[cl_hw->idx].func = cl_rx_remote_tasklet_sched; + csd_rx_remote_cpu_mac[cl_hw->idx].info = t; + } +cl_rx_pci_init (cl_hw); +} + +void cl_rx_off (struct cl_hw *cl_hw) +{ +s8 cpu_mac = cl_hw->conf->ci_rx_remote_cpu_mac; + +if (cpu_mac >=0 ) +tasklet_kill (&per_cpu (rx_remote_tasklet_mac[cl_hw->idx], cpu_mac)); + +tasklet_kill (&cl_hw->rx_tasklet); +tasklet_kill (&cl_hw->rx_resched_tasklet); + +skb_queue_purge (&cl_hw->rx_remote_queue_mac); +skb_queue_purge (&cl_hw->rx_skb_queue); + +cl_rx_amsdu_reset (cl_hw); +cl_rx_pci_deinit (cl_hw); +} + +void cl_rx_remote_tasklet_sched (void *t) +{ +tasklet_schedule ((struct tasklet_struct *)t); +} + +void cl_rx_remote_cpu_info (struct cl_hw *cl_hw) +{ +u32 processor_id =smp_processor_id (); + +if (processor_id <CPU_MAX_NUM ) + cl_hw->rx_info.remote_cpu[processor_id]++; +} + +void cl_rx_push_queue (struct cl_hw *cl_hw,struct sk_buff *skb) +{ +skb_queue_tail (&cl_hw->rx_skb_queue, skb); +tasklet_schedule (&cl_hw->rx_tasklet); +} + +void cl_rx_skb_alloc_handler (struct sk_buff *skb) +{ + skb->destructor = cl_rx_skb_destructor; +atomic_inc (&rx_skb_cnt); +} + +void cl_rx_skb_error (struct cl_hw *cl_hw) +{ +/* +* When there is an error with the received packet we can't +* know the interface and the AC. +* So just use the first interface and BE. +*/ +struct cl_vif *cl_vif =cl_vif_get_first (cl_hw); + +if (!cl_vif) { +cl_dbg_err (cl_hw,"Couldn't find vif\n" ); +return ; + } + + cl_vif->trfc_cntrs[AC_BE ].rx_errors++; +} + +void cl_rx_skb_drop (struct cl_hw *cl_hw,struct sk_buff *skb,u8 cnt) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct cl_vif *cl_vif =cl_vif_get_by_mac (cl_hw, hdr->addr3); + +if (cl_vif) { +u8 ac =cl_rx_get_skb_ac (hdr); + + cl_vif->trfc_cntrs[ac].rx_dropped += cnt; + } +} + +void cl_rx_post_recovery (struct cl_hw *cl_hw) +{ +if (!skb_queue_empty (&cl_hw->rx_skb_queue)) +tasklet_schedule (&cl_hw->rx_tasklet); + +if (!skb_queue_empty (&cl_hw->rx_remote_queue_mac)) +tasklet_schedule (&per_cpu (rx_remote_tasklet_mac[cl_hw->idx], + cl_hw->conf->ci_rx_remote_cpu_mac)); +} + +u8 cl_rx_get_skb_ac (struct ieee80211_hdr *hdr) +{ +if (ieee80211_is_data_qos (hdr->frame_control)) { +u8 *qos_ctl =ieee80211_get_qos_ctl (hdr); +u8 tid = *qos_ctl &IEEE80211_QOS_CTL_TAG1D_MASK ; +return tid_to_ac[tid]; + } + +return AC_BE ; +} + +bool cl_rx_process_in_irq (struct cl_hw *cl_hw) +{ +struct cl_ipc_ring_indices *indices = cl_hw->ipc_env->ring_indices_elem->indices; +u32 read_idx =le32_to_cpu (indices->rxdesc_read_idx[CL_RX_BUF_RXM ]); +u32 write_idx =le32_to_cpu (indices->rxdesc_write_idx[CL_RX_BUF_RXM ]); +u32 free_buffers = read_idx - write_idx; + +if (free_buffers < (IPC_RXBUF_CNT_RXM /2 )) { + cl_hw->rx_info.buffer_process_irq++; +return true; + } + + cl_hw->rx_info.buffer_process_tasklet++; +return false; +} + +static bool cl_agg_rx_report_is_status_valid (u8 status) +{ +if (status ==MM_AGG_RX_REPORT_STAT_OK || + status ==MM_AGG_RX_REPORT_STAT_COLISION_WITH_COUNTER ) +return true; + +return false; +} + +static void sync_rx_rate (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct cl_wrs_info *wrs_info, +struct cl_wrs_params *wrs_params,u8 bw,u8 nss,u8 mcs,u8 gi) +{ +struct cl_wrs_rate_params *rate_params = &wrs_params->rate_params; + +if (bw == rate_params->bw && + nss == rate_params->nss && + mcs == rate_params->mcs && + gi == rate_params->gi) { +cl_wrs_api_rate_sync (cl_hw, cl_sta, wrs_params); + + wrs_info->synced = true; + wrs_info->quick_rate_check = true; + wrs_info->quick_rate_agg_cntr =0 ; + wrs_info->quick_rate_pkt_cntr =0 ; + }else { + wrs_info->sync_attempts++; + } +} + +void cl_agg_rx_report_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u8 sta_loc, +struct mm_agg_rx_ind *agg_report) +{ +struct cl_wrs_info *wrs_info =NULL ; +struct cl_wrs_params *wrs_params = cl_sta->wrs_sta.rx_params; +u16 success_cnt =le16_to_cpu (agg_report->correct_received_mpdu_count[sta_loc]); +u16 data_rate; +u8 nss = agg_report->nss_per_user[sta_loc]; +u8 mcs = agg_report->mcs_rate[sta_loc]; +u8 gi =CL_TF_GI_LTF_TO_GI (agg_report->gi_ltf); +u8 bw; + +if (!wrs_params || + !cl_agg_rx_report_is_status_valid (agg_report->status[sta_loc])) +return ; + + wrs_info = &cl_sta->wrs_info_rx; + + { +u8 ru_type =cl_ru_alloc_to_ru_type (agg_report->ru_allocation[sta_loc]); + + bw =cl_mu_ofdma_grp_convert_ru_type_to_bw (cl_hw, ru_type); + } + +/* WRS sync mechanism */ +if (!wrs_info->synced) +sync_rx_rate (cl_hw, cl_sta, wrs_info, wrs_params, bw, nss, mcs, gi); + + data_rate =cl_data_rates_get_x10 (WRS_MODE_HE , bw, nss, mcs, gi); + + wrs_info->success += success_cnt; + wrs_info->fail += (le16_to_cpu (agg_report->incorrect_received_mpdu_count[sta_loc]) + +le16_to_cpu (agg_report->incorrect_delimiter_count[sta_loc])); + wrs_info->epr_acc += ((u64 )success_cnt * data_rate); +} + +struct msduhdr { +u8 dest[ETH_ALEN ]; +u8 source[ETH_ALEN ]; +__be16 len; +} __packed; + +static void cl_rx_set_flag_amsdu_more (struct sk_buff *skb) +{ +struct ieee80211_rx_status *rx_status =IEEE80211_SKB_RXCB (skb); + + rx_status->flag |=RX_FLAG_AMSDU_MORE ; +} + +static void cl_rx_clear_flag_amsdu_more (struct sk_buff *skb) +{ +struct ieee80211_rx_status *rx_status =IEEE80211_SKB_RXCB (skb); + + rx_status->flag &= ~RX_FLAG_AMSDU_MORE ; +} + +static void cl_rx_add_80211_hdr (struct cl_amsdu_rx_state *amsdu_rx_state, +struct sk_buff *skb,struct sk_buff *first_skb) +{ +/* Copy the 802.11 header of the first skb */ +struct ieee80211_hdr *hdr_first = (struct ieee80211_hdr *)(first_skb->data); +u32 hdrlen_first =ieee80211_hdrlen (hdr_first->frame_control); +u32 total_bytes = hdrlen_first + amsdu_rx_state->encrypt_len; + +skb_push (skb, total_bytes); +memcpy (skb->data, first_skb->data, total_bytes); +} + +static void cl_rx_copy_status (struct cl_amsdu_rx_state *amsdu_rx_state, +struct sk_buff *skb,struct sk_buff *first_skb) +{ +struct ieee80211_rx_status *rx_status =IEEE80211_SKB_RXCB (skb); +struct ieee80211_rx_status *rx_status_first =IEEE80211_SKB_RXCB (first_skb); + +/* Copy rx_status from the first skb */ +memcpy (rx_status, rx_status_first,sizeof (struct ieee80211_rx_status )); + +/* If it is the last sub-frame clear RX_FLAG_AMSDU_MORE */ +if (amsdu_rx_state->msdu_remaining_cnt ==0 ) + rx_status->flag &= ~RX_FLAG_AMSDU_MORE ; +} + +static void cl_rx_amsdu_set_state (struct cl_hw *cl_hw,struct sk_buff *skb,struct hw_rxhdr *rxhdr, +u8 sta_idx,u8 tid,u32 packet_len,u8 encrypt_len) +{ +struct cl_amsdu_rx_state *amsdu_rx_state = &cl_hw->amsdu_rx_state; + + amsdu_rx_state->msdu_cnt = rxhdr->msdu_cnt; + amsdu_rx_state->msdu_remaining_cnt = rxhdr->msdu_cnt -1 ; + amsdu_rx_state->msdu_dma_align = rxhdr->msdu_dma_align; + amsdu_rx_state->amsdu_error =0 ; + amsdu_rx_state->encrypt_len = encrypt_len; + amsdu_rx_state->packet_len = packet_len; + amsdu_rx_state->rxhdr = rxhdr; + amsdu_rx_state->first_skb = skb; + amsdu_rx_state->sta_idx = sta_idx; + amsdu_rx_state->tid = tid; + +__skb_queue_head (&cl_hw->amsdu_rx_state.frames, skb); +} + +static void cl_rx_amsdu_first_length_error (struct cl_hw *cl_hw,struct sk_buff *skb, +struct hw_rxhdr *rxhdr,u32 len) +{ +cl_dbg_err (cl_hw,"RX-AMSDU length error (1/%u) - tailroom=%d, len=%u\n" , + rxhdr->msdu_cnt,skb_tailroom (skb), len); + +cl_rx_amsdu_set_state_error (cl_hw, rxhdr,RX_AMSDU_ERR_LENGTH ); + + cl_hw->rx_info.pkt_drop_amsdu_len_error++; +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +} + +static void cl_rx_amsdu_sub_length_error (struct cl_hw *cl_hw,struct sk_buff *skb,u32 len) +{ +struct cl_amsdu_rx_state *amsdu_rx_state = &cl_hw->amsdu_rx_state; +struct sk_buff *skb_tail; +u8 sub_cnt = amsdu_rx_state->msdu_cnt - amsdu_rx_state->msdu_remaining_cnt; + +cl_dbg_err (cl_hw,"RX-AMSDU length error (%u/%u) - tailroom=%d, len=%u\n" , + sub_cnt, amsdu_rx_state->msdu_cnt,skb_tailroom (skb), len); + +/* All remaining skbs in the AMSDU will be treated as errors */ + amsdu_rx_state->amsdu_error =RX_AMSDU_ERR_LENGTH ; + +/* Clear RX_FLAG_AMSDU_MORE in the last success skb that was received */ + skb_tail =skb_peek_tail (&amsdu_rx_state->frames); +cl_rx_clear_flag_amsdu_more (skb_tail); + + cl_hw->rx_info.pkt_drop_sub_amsdu_len_error++; +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +} + +static bool cl_rx_amsdu_is_frame_aggregation_attack (struct ieee80211_hdr *hdr, +const struct msduhdr *msdu_hdr) +{ +__le16 fc; +int to_ds; +int from_ds; + + fc = hdr->frame_control; + to_ds =ieee80211_has_tods (fc); + from_ds =ieee80211_has_fromds (fc); + +if (to_ds &&memcmp (hdr->addr2, msdu_hdr->source,ETH_ALEN )) +return true; + +if (from_ds &&memcmp (hdr->addr1, msdu_hdr->dest,ETH_ALEN ) && + !(is_multicast_ether_addr (hdr->addr3))) +return true; + +return false; +} + +void cl_rx_amsdu_first (struct cl_hw *cl_hw,struct sk_buff *skb, +struct hw_rxhdr *rxhdr,u8 sta_idx,u8 tid,u8 encrypt_len) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); +u32 hdr_len =ieee80211_hdrlen (hdr->frame_control); +struct msduhdr *msdu_hdr = (struct msduhdr *)(skb->data + hdr_len + encrypt_len); +u32 packet_len = hdr_len + encrypt_len +sizeof (struct msduhdr ) +ntohs (msdu_hdr->len); + +if (skb_tailroom (skb) < packet_len) { +cl_rx_amsdu_first_length_error (cl_hw, skb, rxhdr, packet_len); +return ; + } + +/* Put the WLAN header + MSDU header + payload in the skb data */ +skb_put (skb, packet_len); + +cl_rx_amsdu_set_state (cl_hw, skb, rxhdr, sta_idx, tid, packet_len, encrypt_len); + +/* Must be called after cl_rx_amsdu_set_state() */ +if (cl_hw->amsdu_rx_state.msdu_remaining_cnt >0 ) +cl_rx_set_flag_amsdu_more (skb); +} + +bool cl_rx_amsdu_sub (struct cl_hw *cl_hw,struct sk_buff *skb) +{ +/* +* ---------------------------------------------------------- +* | DMA padding 4 byte alignment | MSDU HDR | MSDU PAYLOAD | +* --------------------------------------------------------- +*/ +struct cl_amsdu_rx_state *amsdu_rx_state = &cl_hw->amsdu_rx_state; +struct sk_buff *first_skb = amsdu_rx_state->first_skb; +struct msduhdr *msdu_hdr; +u32 packet_len; + +/* +* Push the dma alignment to the reserved area, so that skb->data will +* point to the MSDU header +*/ +skb_reserve (skb, amsdu_rx_state->msdu_dma_align); + + msdu_hdr = (struct msduhdr *)(skb->data); + packet_len =sizeof (struct msduhdr ) +ntohs (msdu_hdr->len); + +if (skb_tailroom (skb) < packet_len) { +cl_rx_amsdu_sub_length_error (cl_hw, skb, packet_len); +return false; + } + +/* Put the MSDU HDR + MSDU PAYLOAD into the skb data area */ +skb_put (skb, packet_len); + + amsdu_rx_state->packet_len += packet_len; + +cl_rx_add_80211_hdr (amsdu_rx_state, skb, first_skb); +cl_rx_copy_status (amsdu_rx_state, skb, first_skb); + +/* Store the pointer to sta in the skb->sk field */ + skb->sk = first_skb->sk; + +__skb_queue_tail (&amsdu_rx_state->frames, skb); + +return true; +} + +bool cl_rx_amsdu_check_aggregation_attack (struct cl_amsdu_rx_state *amsdu_rx_state) +{ +u32 hdrlen =0 ; +struct sk_buff_head *frames = &amsdu_rx_state->frames; +struct hw_rxhdr *rxhdr = amsdu_rx_state->rxhdr; +struct ieee80211_hdr *hdr =NULL ; +struct msduhdr *msdu_hdr =NULL ; +struct sk_buff *skb =NULL ; + +/* Validate encryption info - forbid A-MSDU on pre-HT connections */ +switch (rxhdr->decr_status) { +case CL_RX_HDR_DECR_ICVFAIL : +case CL_RX_HDR_DECR_WEPSUCCESS : +case CL_RX_HDR_DECR_TKIPSUCCESS : +return true; +default : +break ; + } + + skb_queue_walk(frames, skb) { + hdr = (struct ieee80211_hdr *)(skb->data); + hdrlen =ieee80211_hdrlen (hdr->frame_control); + msdu_hdr = (struct msduhdr *)(skb->data + hdrlen + amsdu_rx_state->encrypt_len); +if (cl_rx_amsdu_is_frame_aggregation_attack (hdr, msdu_hdr)) +return true; + } + +return false; +} + +void cl_rx_amsdu_first_corrupted (struct cl_hw *cl_hw,struct sk_buff *skb, +struct hw_rxhdr *rxhdr) +{ +struct ieee80211_hdr *mac_hdr = (struct ieee80211_hdr *)(skb->data); + +cl_dbg_verbose (cl_hw,"Corrupted RX-AMSDU (1/%u), dest_addr=%pM\n" , + rxhdr->msdu_cnt, mac_hdr->addr1); + +cl_rx_amsdu_set_state_error (cl_hw, rxhdr,RX_AMSDU_ERR_CORRUPTED ); + + cl_hw->rx_info.pkt_drop_amsdu_corrupted++; +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +} + +void cl_rx_amsdu_sub_error (struct cl_hw *cl_hw,struct sk_buff *skb) +{ +struct cl_amsdu_rx_state *amsdu_rx_state = &cl_hw->amsdu_rx_state; +u8 sub_cnt = amsdu_rx_state->msdu_cnt - amsdu_rx_state->msdu_remaining_cnt; + +if (amsdu_rx_state->amsdu_error &RX_AMSDU_ERR_CORRUPTED ) { + cl_hw->rx_info.pkt_drop_sub_amsdu_corrupted++; + +cl_dbg_verbose (cl_hw,"Corrupted RX-AMSDU (%u/%u)\n" , + sub_cnt, amsdu_rx_state->msdu_cnt); + }else if (amsdu_rx_state->amsdu_error &RX_AMSDU_ERR_LENGTH ) { + cl_hw->rx_info.pkt_drop_sub_amsdu_len_error++; + +cl_dbg_verbose (cl_hw,"RX-AMSDU length error (%u/%u)\n" , + sub_cnt, amsdu_rx_state->msdu_cnt); + }else if (amsdu_rx_state->amsdu_error &RX_AMSDU_ERR_NOT_SUCCESS ) { + cl_hw->rx_info.pkt_drop_sub_amsdu_not_success++; + +cl_dbg_verbose (cl_hw,"RX-AMSDU not success (%u/%u)\n" , + sub_cnt, amsdu_rx_state->msdu_cnt); + }else if (amsdu_rx_state->amsdu_error &RX_AMSDU_ERR_UNENCRYPTED ) { + cl_hw->rx_info.pkt_drop_sub_amsdu_unencrypted++; + +cl_dbg_verbose (cl_hw,"Protected frame unencrypted (%u/%u)\n" , + sub_cnt, amsdu_rx_state->msdu_cnt); + }else if (amsdu_rx_state->amsdu_error &RX_AMSDU_ERR_DECRYPT_FAIL ) { + cl_hw->rx_info.pkt_drop_sub_amsdu_decrypt_fail++; + +cl_dbg_verbose (cl_hw,"Decryption failed (%u/%u)\n" , + sub_cnt, amsdu_rx_state->msdu_cnt); + }else if (amsdu_rx_state->amsdu_error &RX_AMSDU_ERR_INVALID_TAILROOM ) { + cl_hw->rx_info.pkt_drop_sub_amsdu_tailroom_error++; + +cl_dbg_verbose (cl_hw,"Invalid tailroom (%u/%u)\n" , + sub_cnt, amsdu_rx_state->msdu_cnt); + } + +cl_rx_skb_error (cl_hw); +kfree_skb (skb); +} + +void cl_rx_amsdu_set_state_error (struct cl_hw *cl_hw, +struct hw_rxhdr *rxhdr, +enum rx_amsdu_error err) +{ +struct cl_amsdu_rx_state *amsdu_rx_state = &cl_hw->amsdu_rx_state; + + amsdu_rx_state->msdu_cnt = rxhdr->msdu_cnt; + amsdu_rx_state->msdu_remaining_cnt = rxhdr->msdu_cnt -1 ; + amsdu_rx_state->amsdu_error = err; +} + +void cl_rx_amsdu_reset (struct cl_hw *cl_hw) +{ +/* Free pending frames */ +__skb_queue_purge (&cl_hw->amsdu_rx_state.frames); + +/* Reset RX A-MSDU state */ +memset (&cl_hw->amsdu_rx_state,0 ,sizeof (struct cl_amsdu_rx_state )); + +__skb_queue_head_init (&cl_hw->amsdu_rx_state.frames); +} + +void cl_rx_amsdu_stats (struct cl_hw *cl_hw,u8 msdu_cnt) +{ +/* +* Update A-MSDU statistics +* msdu_cnt 1 - 128 is mapped to 0 - 127. +*/ +if (msdu_cnt <=RX_MAX_MSDU_IN_AMSDU ) + cl_hw->rx_info.amsdu_cnt[msdu_cnt -1 ]++; +else +cl_dbg_err (cl_hw,"Invalid msdu_cnt [%u]\n" , msdu_cnt); +} + +/* Only ieee80211_hw_set() is defined in mac80211.h */ +static inline void _ieee80211_hw_clear (struct ieee80211_hw *hw, +enum ieee80211_hw_flags flg) +{ +return __clear_bit (flg, hw->flags); +} + +#define ieee80211_hw_clear (hw, flg) _ieee80211_hw_clear(hw, IEEE80211_HW_##flg) + +void cl_rx_amsdu_hw_en (struct ieee80211_hw *hw,bool rxamsdu_en) +{ +if (rxamsdu_en) +ieee80211_hw_set (hw,SUPPORTS_AMSDU_IN_AMPDU ); +else +ieee80211_hw_clear (hw,SUPPORTS_AMSDU_IN_AMPDU ); +} + +u32 cl_rx_filter_update_flags (struct cl_hw *cl_hw,u32 filter) +{ +u32 rx_filter =0 ; + +if (filter &FIF_ALLMULTI ) + rx_filter |=RX_CNTRL_ACCEPT_MULTICAST_BIT ; + +if (filter & (FIF_FCSFAIL |FIF_PLCPFAIL )) + rx_filter |=RX_CNTRL_ACCEPT_ERROR_FRAMES_BIT ; + +if (filter &FIF_BCN_PRBRESP_PROMISC ) + rx_filter |=RX_CNTRL_ACCEPT_OTHER_BSSID_BIT ; + +if (filter &FIF_CONTROL ) + rx_filter |=RX_CNTRL_ACCEPT_OTHER_CNTRL_FRAMES_BIT | +RX_CNTRL_ACCEPT_CF_END_BIT | +RX_CNTRL_ACCEPT_ACK_BIT | +RX_CNTRL_ACCEPT_CTS_BIT | +RX_CNTRL_ACCEPT_RTS_BIT | +RX_CNTRL_ACCEPT_BA_BIT |RX_CNTRL_ACCEPT_BAR_BIT ; + +if (filter &FIF_OTHER_BSS ) + rx_filter |=RX_CNTRL_ACCEPT_OTHER_BSSID_BIT ; + +if (filter &FIF_PSPOLL ) + rx_filter |=RX_CNTRL_ACCEPT_PS_POLL_BIT ; + +if (filter &FIF_PROBE_REQ ) + rx_filter |=RX_CNTRL_ACCEPT_PROBE_REQ_BIT ; + +/* Add the filter flags that are set by default and cannot be changed here */ + rx_filter |=CL_MAC80211_NOT_CHANGEABLE ; + +if (ieee80211_hw_check (cl_hw->hw,AMPDU_AGGREGATION )) + rx_filter |=RX_CNTRL_ACCEPT_BA_BIT ; + +/* +* work around for HW bug (AD 14672) +* In order for the response frames to BAR and RTS be with correct +* power they should always be accepted and found in the KSR +*/ + rx_filter |=RX_CNTRL_ACCEPT_BAR_BIT |RX_CNTRL_ACCEPT_RTS_BIT ; + +return rx_filter; +} + +static u32 cl_filter_get_flags (struct net_device *dev) +{ +struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev); + +return sdata->local->filter_flags; +} + +void cl_rx_filter_restore_flags (struct cl_hw *cl_hw) +{ +struct net_device *dev =cl_vif_get_first_net_device (cl_hw); +u32 filter =0 ; + +if (!dev) +return ; + + filter =cl_filter_get_flags (dev); +cl_dbg_verbose (cl_hw,"Restoring filter flags to 0x%x\n" , filter); +cl_msg_tx_set_filter (cl_hw, filter, false); +} + +void cl_rx_filter_set_promiscuous (struct cl_hw *cl_hw) +{ +u32 filter = ~(FIF_FCSFAIL |FIF_PLCPFAIL | (1 <<31 )); + +cl_dbg_verbose (cl_hw,"set promiscuous mode 0x%x\n" , filter); +cl_msg_tx_set_filter (cl_hw, filter, false); +} + +#define REORDER_BUF_TIMEOUT (HZ / 10) +#define REORDER_BUF_TIMEOUT_MS jiffies_to_msecs(REORDER_BUF_TIMEOUT + 1) + +static bool cl_rx_reorder_ready (struct cl_tid_ampdu_rx *tid_agg_rx,u8 index) +{ +struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index]; +struct sk_buff *tail =skb_peek_tail (frames); +struct ieee80211_rx_status *status; + +if (tid_agg_rx->reorder_buf_filtered &BIT_ULL (index)) +return true; + +if (!tail) +return false; + + status =IEEE80211_SKB_RXCB (tail); + +if (status->flag &RX_FLAG_AMSDU_MORE ) +return false; + +return true; +} + +static void cl_rx_release_reorder_frame (struct cl_tid_ampdu_rx *tid_agg_rx,int index, +struct sk_buff_head *frames) +{ +struct cl_hw *cl_hw = tid_agg_rx->cl_hw; +struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index]; +struct sk_buff *skb; +struct ieee80211_rx_status *status =NULL ; +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (tid_agg_rx->sta); +int pn_state =CL_PN_VALID_STATE_FAILED ; + +lockdep_assert_held (&tid_agg_rx->reorder_lock); + +if (skb_queue_empty (skb_list)) + goto no_frame; + + tid_agg_rx->stored_mpdu_num--; + +if (!cl_rx_reorder_ready (tid_agg_rx, index)) { +__skb_queue_purge (skb_list); + goto no_frame; + } + +/* For NON AMSDU - Single skb in skb_list +* For AMSDU - Validate first skb and set PN flag for rest. +*/ + skb =skb_peek (skb_list); + pn_state =cl_key_handle_pn_validation (cl_hw, skb, cl_sta); +if (pn_state ==CL_PN_VALID_STATE_FAILED ) { +__skb_queue_purge (skb_list); + goto no_frame; + } + +while ((skb =__skb_dequeue (skb_list))) { +if (pn_state ==CL_PN_VALID_STATE_SUCCESS ) { + status =IEEE80211_SKB_RXCB (skb); + status->flag |=RX_FLAG_PN_VALIDATED ; + } +__skb_queue_tail (frames, skb); + } + +no_frame: + tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL (index); + tid_agg_rx->head_seq_num =ieee80211_sn_inc (tid_agg_rx->head_seq_num); +} + +static void cl_rx_release_reorder_frames (struct cl_tid_ampdu_rx *tid_agg_rx, +u16 head_seq_num, +struct sk_buff_head *frames) +{ +int index; + +lockdep_assert_held (&tid_agg_rx->reorder_lock); + +while (ieee80211_sn_less (tid_agg_rx->head_seq_num, head_seq_num)) { + index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; +cl_rx_release_reorder_frame (tid_agg_rx, index, frames); + } +} + +static void cl_reorder_release (struct cl_tid_ampdu_rx *tid_agg_rx,struct sk_buff_head *frames) +{ +u8 index, i, j; + +lockdep_assert_held (&tid_agg_rx->reorder_lock); + +/* Release buffer until next hole */ + index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; +if (!cl_rx_reorder_ready (tid_agg_rx, index) && tid_agg_rx->stored_mpdu_num) { +u8 skipped =1 ; + +for (j = (index +1 ) % tid_agg_rx->buf_size; j != index; + j = (j +1 ) % tid_agg_rx->buf_size) { +if (!cl_rx_reorder_ready (tid_agg_rx, j)) { + skipped++; +continue ; + } +if (skipped && + !time_after (jiffies, tid_agg_rx->reorder_time[j] + +REORDER_BUF_TIMEOUT )) + goto set_release_timer; + +/* Incomplete A-MSDUs */ +for (i = (index +1 ) % tid_agg_rx->buf_size; i != j; + i = (i +1 ) % tid_agg_rx->buf_size) { +__skb_queue_purge (&tid_agg_rx->reorder_buf[i]); + } + +cl_rx_release_reorder_frame (tid_agg_rx, j, frames); + + tid_agg_rx->head_seq_num = + (tid_agg_rx->head_seq_num + + skipped) &IEEE80211_SN_MASK ; + skipped =0 ; + } + }else { +while (cl_rx_reorder_ready (tid_agg_rx, index)) { +cl_rx_release_reorder_frame (tid_agg_rx, index, frames); + index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; + } + } + +if (tid_agg_rx->stored_mpdu_num) { + j = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; + index = j; +for (; j != (index -1 ) % tid_agg_rx->buf_size; + j = (j +1 ) % tid_agg_rx->buf_size) { +if (cl_rx_reorder_ready (tid_agg_rx, j)) +break ; + } + + set_release_timer: +if (!tid_agg_rx->removed) +mod_timer (&tid_agg_rx->reorder_timer, tid_agg_rx->reorder_time[j] + +msecs_to_jiffies (REORDER_BUF_TIMEOUT_MS )); + }else { +del_timer (&tid_agg_rx->reorder_timer); + } +} + +static void cl_rx_reorder_release_timeout (struct timer_list *t) +{ +struct cl_tid_ampdu_rx *tid_agg_rx =from_timer (tid_agg_rx, t, reorder_timer); +struct sk_buff *skb =NULL ; +struct cl_hw *cl_hw =NULL ; +struct ieee80211_sta *sta =NULL ; +struct sk_buff_head buffer; + +if (!tid_agg_rx) +return ; + +__skb_queue_head_init (&buffer); + +spin_lock (&tid_agg_rx->reorder_lock); + + cl_hw = tid_agg_rx->cl_hw; + sta = tid_agg_rx->sta; +cl_reorder_release (tid_agg_rx, &buffer); + +spin_unlock (&tid_agg_rx->reorder_lock); + +while (!skb_queue_empty (&buffer)) { + skb =__skb_dequeue (&buffer); +ieee80211_rx_napi (cl_hw->hw, sta, skb,NULL ); + } +} + +static bool cl_rx_manage_reorder_buf (struct cl_tid_ampdu_rx *tid_agg_rx, +struct sk_buff *skb, +struct sk_buff_head *ordered_mpdu) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct ieee80211_rx_status *status =IEEE80211_SKB_RXCB (skb); +u16 sc =le16_to_cpu (hdr->seq_ctrl); +u16 mpdu_seq_num = (sc &IEEE80211_SCTL_SEQ ) >>4 ; +u16 head_seq_num, buf_size; +u8 index; +bool ret = true; + +if (unlikely (tid_agg_rx->auto_seq)) { + tid_agg_rx->auto_seq = false; + tid_agg_rx->ssn = mpdu_seq_num; + tid_agg_rx->head_seq_num = mpdu_seq_num; + } + + buf_size = tid_agg_rx->buf_size; + head_seq_num = tid_agg_rx->head_seq_num; + +/* Current SN is smaller than the SSN */ +if (unlikely (!tid_agg_rx->started)) { +if (ieee80211_sn_less (mpdu_seq_num, head_seq_num)) { + ret = false; + goto out; + } + tid_agg_rx->started = true; + } + +/* Out of date sequence number */ +if (ieee80211_sn_less (mpdu_seq_num, head_seq_num)) { +dev_kfree_skb (skb); + goto out; + } + +/* SN exceeds buffer window */ +if (!ieee80211_sn_less (mpdu_seq_num, head_seq_num + buf_size)) { + head_seq_num =ieee80211_sn_inc (ieee80211_sn_sub (mpdu_seq_num, buf_size)); +cl_rx_release_reorder_frames (tid_agg_rx, head_seq_num, ordered_mpdu); + } + + index = mpdu_seq_num % tid_agg_rx->buf_size; + +/* Frame already stored */ +if (cl_rx_reorder_ready (tid_agg_rx, index)) { +dev_kfree_skb (skb); + goto out; + } + +if (mpdu_seq_num == tid_agg_rx->head_seq_num && + tid_agg_rx->stored_mpdu_num ==0 ) { +if (!(status->flag &RX_FLAG_AMSDU_MORE )) { + tid_agg_rx->head_seq_num = +ieee80211_sn_inc (tid_agg_rx->head_seq_num); + } + ret = false; + goto out; + } + +/* Insert frame into reorder buffer */ +__skb_queue_tail (&tid_agg_rx->reorder_buf[index], skb); +if (!(status->flag &RX_FLAG_AMSDU_MORE )) { + tid_agg_rx->reorder_time[index] = jiffies; + tid_agg_rx->stored_mpdu_num++; +cl_reorder_release (tid_agg_rx, ordered_mpdu); + } + + out: +return ret; +} + +void cl_rx_reorder_ampdu (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,struct sk_buff_head *ordered_mpdu) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct cl_tid_ampdu_rx *tid_agg_rx; +u8 tid, ack_policy; + +if (!cl_sta) +return ; + + ack_policy = *ieee80211_get_qos_ctl (hdr) & +IEEE80211_QOS_CTL_ACK_POLICY_MASK ; + tid =ieee80211_get_tid (hdr); + + tid_agg_rx = cl_sta->tid_agg_rx[tid]; +if (!tid_agg_rx) +return ; + +spin_lock (&tid_agg_rx->reorder_lock); +if (!ieee80211_is_data_qos (hdr->frame_control) || +is_multicast_ether_addr (hdr->addr1)) + goto dont_reorder; + +if (unlikely (hdr->frame_control &cpu_to_le16 (IEEE80211_STYPE_NULLFUNC ))) + goto dont_reorder; + +if (ack_policy !=IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK && + ack_policy !=IEEE80211_QOS_CTL_ACK_POLICY_NORMAL ) + goto dont_reorder; + +/* Ignore EAPOL frames */ +if (cl_is_eapol (skb)) + goto dont_reorder; + +if (cl_rx_manage_reorder_buf (tid_agg_rx, skb, ordered_mpdu)) { +spin_unlock (&tid_agg_rx->reorder_lock); +return ; + } + + dont_reorder: +spin_unlock (&tid_agg_rx->reorder_lock); + +if (cl_key_handle_pn_validation (cl_hw, skb, cl_sta) ==CL_PN_VALID_STATE_FAILED ) { +dev_kfree_skb (skb); +return ; + } + +__skb_queue_tail (ordered_mpdu, skb); +} + +void cl_rx_reorder_close (struct cl_sta *cl_sta,u8 tid) +{ +struct cl_tid_ampdu_rx *tid_agg_rx = cl_sta->tid_agg_rx[tid]; +u16 i; + +spin_lock_bh (&tid_agg_rx->reorder_lock); + tid_agg_rx->removed = true; +spin_unlock_bh (&tid_agg_rx->reorder_lock); + +del_timer_sync (&tid_agg_rx->reorder_timer); + +spin_lock_bh (&tid_agg_rx->reorder_lock); +for (i =0 ; i < tid_agg_rx->buf_size; i++) +__skb_queue_purge (&tid_agg_rx->reorder_buf[i]); + +kfree (tid_agg_rx->reorder_buf); +kfree (tid_agg_rx->reorder_time); + cl_sta->tid_agg_rx[tid] =NULL ; + +spin_unlock_bh (&tid_agg_rx->reorder_lock); +kfree (tid_agg_rx); +} + +void cl_rx_reorder_init (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u8 tid,u16 buf_size) +{ +struct cl_tid_ampdu_rx *tid_agg_rx; +u16 i; + + tid_agg_rx =kzalloc (sizeof (*tid_agg_rx),GFP_KERNEL ); +if (!tid_agg_rx) +return ; + +spin_lock_init (&tid_agg_rx->reorder_lock); + +timer_setup (&tid_agg_rx->reorder_timer, cl_rx_reorder_release_timeout,0 ); + + tid_agg_rx->reorder_buf = +kcalloc (buf_size,sizeof (struct sk_buff_head ),GFP_KERNEL ); + tid_agg_rx->reorder_time = +kcalloc (buf_size,sizeof (unsigned long ),GFP_KERNEL ); +if (!tid_agg_rx->reorder_buf || !tid_agg_rx->reorder_time) { +pr_err ("Allocation failed!\n" ); +kfree (tid_agg_rx->reorder_buf); +kfree (tid_agg_rx->reorder_time); +return ; + } + +for (i =0 ; i < buf_size; i++) +__skb_queue_head_init (&tid_agg_rx->reorder_buf[i]); + + tid_agg_rx->ssn =0 ; + tid_agg_rx->head_seq_num =0 ; + tid_agg_rx->buf_size = buf_size; + tid_agg_rx->stored_mpdu_num =0 ; + tid_agg_rx->auto_seq =0 ; + tid_agg_rx->started = false; + tid_agg_rx->reorder_buf_filtered =0 ; + tid_agg_rx->tid = tid; + tid_agg_rx->sta = cl_sta->sta; + tid_agg_rx->cl_hw = cl_hw; + cl_sta->tid_agg_rx[tid] = tid_agg_rx; +}
Signature · 1 line
2.36.1
RFC v2 69/96 cl8k: add rx.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/rx.h | 505 ++++++++++++++++++++++++++ 1 file changed, 505 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/rx.h
drivers/net/wireless/celeno/cl8k/rx.h new file +505 -0
@@ -0,0 +1,505 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_RX_H +#define CL_RX_H + +#include <linux/skbuff.h> +#include <net/mac80211.h> + +#include "ipc_shared.h" + +/* Decryption status subfields */ +enum cl_rx_hdr_decr { +CL_RX_HDR_DECR_UNENC , +CL_RX_HDR_DECR_ICVFAIL , +CL_RX_HDR_DECR_CCMPFAIL , +CL_RX_HDR_DECR_AMSDUDISCARD , +CL_RX_HDR_DECR_NULLKEY , +CL_RX_HDR_DECR_WEPSUCCESS , +CL_RX_HDR_DECR_TKIPSUCCESS , +CL_RX_HDR_DECR_CCMPSUCCESS +}; + +#define CL_PADDING_IN_BYTES 2 + +struct hw_rxhdr { +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 msdu_cnt :8 ,/* [7:0] */ + corrupted_amsdu :1 ,/* [8] */ + reserved :1 ,/* [9] */ + msdu_dma_align :2 ,/* [11:10] */ + amsdu_error_code :4 ,/* [15:12] */ + reserved_2 :16 ;/* [31:16] */ +#else +u32 reserved_2 :16 ,/* [15:0] */ + amsdu_error_code :4 ,/* [19:16] */ + msdu_dma_align :2 ,/* [21:20] */ + reserved :1 ,/* [22] */ + corrupted_amsdu :1 ,/* [23] */ + msdu_cnt :8 ;/* [31:24] */ +#endif +/* Total length for the MPDU transfer */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 len :14 ,/* [13:0] */ + ampdu_cnt :2 ,/* [15:14] */ + rx_padding_done :1 ,/* [16] */ + rx_class_rule_res :7 ,/* [23:17] */ +/* AMPDU Status Information */ + mpdu_cnt :8 ;/* [31:24] */ +#else +u32 mpdu_cnt :8 ,/* [7:0] */ + rx_class_rule_res :7 ,/* [14:8] */ + rx_padding_done :1 ,/* [15] */ + ampdu_cnt :2 ,/* [17:16] */ + len :14 ;/* [31:18] */ +#endif + +/* TSF Low */ +__le32 tsf_lo; +/* TSF High */ +__le32 tsf_hi; + +/* Receive Vector 1a */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 leg_length :12 ,/* [11:0] */ + leg_rate :4 ,/* [15:12] */ + ht_length_l :16 ;/* [31:16] */ +#else +u32 ht_length_l :16 ,/* [15:0] */ + leg_rate :4 ,/* [19:16] */ + leg_length :12 ;/* [31:20] */ +#endif + +/* Receive Vector 1b */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 ht_length_h :8 ,/* [7:0] */ + mcs :7 ,/* [14:8] */ + pre_type :1 ,/* [15] */ + format_mod :4 ,/* [19:16] */ + reserved_1b :1 ,/* [20] */ + n_sts :3 ,/* [23:21] */ + lsig_valid :1 ,/* [24] */ + sounding :1 ,/* [25] */ + num_extn_ss :2 ,/* [27:26] */ + aggregation :1 ,/* [28] */ + fec_coding :1 ,/* [29] */ + dyn_bw :1 ,/* [30] */ + doze_not_allowed :1 ;/* [31] */ +#else +u32 doze_not_allowed :1 ,/* [0] */ + dyn_bw :1 ,/* [1] */ + fec_coding :1 ,/* [2] */ + aggregation :1 ,/* [3] */ + num_extn_ss :2 ,/* [5:4] */ + sounding :1 ,/* [6] */ + lsig_valid :1 ,/* [7] */ + n_sts :3 ,/* [10:8] */ + reserved_1b :1 ,/* [11] */ + format_mod :4 ,/* [15:12] */ + pre_type :1 ,/* [16] */ + mcs :7 ,/* [23:17] */ + ht_length_h :8 ;/* [31:24] */ +#endif + +/* Receive Vector 1c */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 sn :4 ,/* [3:0] */ + warn_1c :1 ,/* [4] */ + stbc :2 ,/* [6:5] */ + smoothing :1 ,/* [7] */ + partial_aid :9 ,/* [16:8] */ + group_id :6 ,/* [22:17] */ + reserved_1c :1 ,/* [23] */ + rssi1 :8 ;/* [31:24] */ +#else +u32 rssi1 :8 ,/* [7:0] */ + reserved_1c :1 ,/* [8] */ + group_id :6 ,/* [14:9] */ + partial_aid :9 ,/* [23:15] */ + smoothing :1 ,/* [24] */ + stbc :2 ,/* [26:25] */ + warn_1c :1 ,/* [27] */ + sn :4 ;/* [31:28] */ +#endif + +/* Receive Vector 1d */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +s32 rssi2 :8 ,/* [7:0] */ + rssi3 :8 ,/* [15:8] */ + rssi4 :8 ,/* [23:16] */ + rx_chains :8 ;/* [31:24] */ +#else +s32 rx_chains :8 ,/* [7:0] */ + rssi4 :8 ,/* [15:8] */ + rssi3 :8 ,/* [23:16] */ + rssi2 :8 ;/* [31:24] */ +#endif + +/* Receive Vector 1e */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 txop_duration :7 ,/* [6:0] */ + beam_change :1 ,/* [7] */ + mcs_sig_b :3 ,/* [10:8] */ + dcm :1 ,/* [11] */ + dcm_sig_b :1 ,/* [12] */ + beamformed :1 ,/* [13] */ + ltf_type :2 ,/* [15:14] */ + ru_band :1 ,/* [16] */ + ru_type :3 ,/* [19:17] */ + ru_index :6 ,/* [25:20] */ + pe_duration :3 ,/* [28:26] */ + ch_bw :2 ,/* [30:29] */ + reserved_1e :1 ;/* [31] */ +#else +u32 reserved_1e :1 ,/* [0] */ + ch_bw :2 ,/* [2:1] */ + pe_duration :3 ,/* [5:3] */ + ru_index :6 ,/* [11:6] */ + ru_type :3 ,/* [14:12] */ + ru_band :1 ,/* [15] */ + ltf_type :2 ,/* [17:16] */ + beamformed :1 ,/* [18] */ + dcm_sig_b :1 ,/* [19] */ + dcm :1 ,/* [20] */ + mcs_sig_b :3 ,/* [23:21] */ + beam_change :1 ,/* [24] */ + txop_duration :7 ;/* [31:25] */ +#endif + +/* Receive Vector 1f */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 spatial_reuse :16 ,/* [15:0] */ + service :16 ;/* [31:16] */ +#else +u32 service :16 ,/* [15:0] */ + spatial_reuse :16 ;/* [31:16] */ +#endif + +/* Receive Vector 1g */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 bss_color :6 ,/* [5:0] */ + gi_type :2 ,/* [7:6] */ + antenna_set :16 ,/* [23:8] */ + rssi5 :8 ;/* [31:24] */ +#else +u32 rssi5 :8 ,/* [7:0] */ + antenna_set :16 ,/* [23:8] */ + gi_type :2 ,/* [25:24] */ + bss_color :6 ;/* [31:26] */ +#endif + +/* Receive Vector 1h */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +s32 rssi6 :8 ,/* [7:0] */ + rssi7 :8 ,/* [15:8] */ + rssi8 :8 ,/* [23:16] */ + future_1 :8 ;/* [31:24] */ +#else +s32 future_1 :8 ,/* [7:0] */ + rssi8 :8 ,/* [15:8] */ + rssi7 :8 ,/* [23:16] */ + rssi6 :8 ;/* [31:24] */ +#endif + +/* Receive Vector 2a */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 rcpi :8 ,/* [7:0] */ + evm1 :8 ,/* [15:8] */ + evm2 :8 ,/* [23:16] */ + evm3 :8 ;/* [31:24] */ +#else +u32 evm3 :8 ,/* [7:0] */ + evm2 :8 ,/* [15:8] */ + evm1 :8 ,/* [23:16] */ + rcpi :8 ;/* [31:24] */ +#endif + +/* Receive Vector 2b */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 evm4 :8 ,/* [7:0] */ + warn_2b :1 ,/* [8] */ + reserved2b_1 :7 ,/* [15:9] */ + reserved2b_2 :8 ,/* [23:16] */ + reserved2b_3 :8 ;/* [31:24] */ +#else +u32 reserved2b_3 :8 ,/* [7:0] */ + reserved2b_2 :8 ,/* [15:8] */ + reserved2b_1 :7 ,/* [22:16] */ + warn_2b :1 ,/* [23] */ + evm4 :8 ;/* [31:24] */ +#endif + +/* Status **/ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 rx_vect2_valid :1 ,/* [0] */ + resp_frame :1 ,/* [1] */ + decr_status :3 ,/* [4:2] */ + rx_fifo_oflow :1 ,/* [5] */ + undef_err :1 ,/* [6] */ + phy_err :1 ,/* [7] */ + fcs_err :1 ,/* [8] */ + addr_mismatch :1 ,/* [9] */ + ga_frame :1 ,/* [10] */ + first_qos_data :1 ,/* [11] */ + amsdu_present :1 ,/* [12] */ + frm_successful_rx :1 ,/* [13] */ + desc_done_rx :1 ,/* [14] */ + desc_spare :1 ,/* [15] */ + key_sram_index :9 ,/* [24:16] */ + key_sram_v :1 ,/* [25] */ + type :2 ,/* [27:26] */ + subtype :4 ;/* [31:28] */ +#else +u32 subtype :4 ,/* [3:0] */ + type :2 ,/* [5:4] */ + key_sram_v :1 ,/* [6] */ + key_sram_index :9 ,/* [15:7] */ + desc_spare :1 ,/* [16] */ + desc_done_rx :1 ,/* [17] */ + frm_successful_rx :1 ,/* [18] */ + amsdu_present :1 ,/* [19] */ + first_qos_data :1 ,/* [20] */ + ga_frame :1 ,/* [21] */ + addr_mismatch :1 ,/* [22] */ + fcs_err :1 ,/* [23] */ + phy_err :1 ,/* [24] */ + undef_err :1 ,/* [25] */ + rx_fifo_oflow :1 ,/* [26] */ + decr_status :3 ,/* [29:27] */ + resp_frame :1 ,/* [30] */ + rx_vect2_valid :1 ;/* [31] */ +#endif + +/* PHY channel information 1 */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 phy_band :8 ,/* [7:0] */ + phy_channel_type :8 ,/* [15:8] */ + phy_prim20_freq :16 ;/* [31:16] */ +#else +u32 phy_prim20_freq :16 ,/* [15:0] */ + phy_channel_type :8 ,/* [23:16] */ + phy_band :8 ;/* [31:24] */ +#endif + +/* PHY channel information 2 */ +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 phy_center1_freq :16 ,/* [15:0] */ + phy_center2_freq :16 ;/* [31:16] */ +#else +u32 phy_center2_freq :16 ,/* [15:0] */ + phy_center1_freq :16 ;/* [31:16] */ +#endif + +/* Patten **/ +__le32 pattern; +}; + +enum cl_radio_stats { +CL_RADIO_FCS_ERROR =0 , +CL_RADIO_PHY_ERROR , +CL_RADIO_RX_FIFO_OVERFLOW , +CL_RADIO_ADDRESS_MISMATCH , +CL_RADIO_UNDEFINED_ERROR , +CL_RADIO_ERRORS_MAX +}; + +struct cl_rx_path_info { +u32 rx_desc[CL_RX_BUF_MAX ]; +u32 netif_rx; +u32 elem_alloc_fail; +u32 skb_null; +u32 pkt_drop_amsdu_corrupted; +u32 pkt_drop_sub_amsdu_corrupted; +u32 pkt_drop_amsdu_len_error; +u32 pkt_drop_sub_amsdu_len_error; +u32 pkt_drop_wrong_pattern; +u32 pkt_drop_not_success; +u32 pkt_drop_sub_amsdu_not_success; +u32 pkt_drop_unencrypted; +u32 pkt_drop_sub_amsdu_unencrypted; +u32 pkt_drop_decrypt_fail; +u32 pkt_drop_sub_amsdu_decrypt_fail; +u32 pkt_drop_tailroom_error; +u32 pkt_drop_sub_amsdu_tailroom_error; +u32 pkt_drop_amsdu_inj_attack; +u32 pkt_drop_sta_null; +u32 pkt_drop_host_limit; +u32 pkt_drop_invalid_pn; +u32 remote_cpu[CPU_MAX_NUM ]; +u32 exceed_pkt_budget; +u32 pkt_handle_bucket_rxm[IPC_RXBUF_NUM_BUCKETS_RXM ]; +u32 pkt_handle_bucket_fw[IPC_RXBUF_NUM_BUCKETS_FW ]; +u32 amsdu_cnt[RX_MAX_MSDU_IN_AMSDU ]; +u32 non_amsdu; +u32 buffer_process_irq; +u32 buffer_process_tasklet; +}; + +struct cl_hw ; +struct cl_vif ; +struct cl_sta ; +struct mm_agg_rx_ind ; + +void cl_rx_init (struct cl_hw *cl_hw); +void cl_rx_off (struct cl_hw *cl_hw); +void cl_rx_remote_tasklet_sched (void *t); +void cl_rx_remote_cpu_info (struct cl_hw *cl_hw); +void cl_rx_push_queue (struct cl_hw *cl_hw,struct sk_buff *skb); +void cl_rx_skb_alloc_handler (struct sk_buff *skb); +void cl_rx_skb_error (struct cl_hw *cl_hw); +void cl_rx_skb_drop (struct cl_hw *cl_hw,struct sk_buff *skb,u8 cnt); +void cl_rx_post_recovery (struct cl_hw *cl_hw); +void cl_rx_finish (struct cl_hw *cl_hw,struct sk_buff *skb,struct ieee80211_sta *sta); +u8 cl_rx_get_skb_ac (struct ieee80211_hdr *hdr); +bool cl_rx_process_in_irq (struct cl_hw *cl_hw); +void cl_agg_rx_report_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u8 sta_loc, +struct mm_agg_rx_ind *agg_report); + +enum rx_amsdu_error { +RX_AMSDU_ERR_CORRUPTED =0x1 , +RX_AMSDU_ERR_LENGTH =0x2 , +RX_AMSDU_ERR_NOT_SUCCESS =0x4 , +RX_AMSDU_ERR_UNENCRYPTED =0x8 , +RX_AMSDU_ERR_DECRYPT_FAIL =0x10 , +RX_AMSDU_ERR_INVALID_TAILROOM =0x20 , +}; + +struct cl_amsdu_rx_state { +u8 msdu_cnt; +u8 msdu_remaining_cnt; +/* +* MSDU padding - all MSDU pkt within A-MSDU are 4byte aligned (this +* value holds the alignment value) +* According to ieee80211 spec all MSDU share the same alignment +*/ +u8 msdu_dma_align; +u8 amsdu_error; +u8 encrypt_len; +u8 sta_idx; +u8 tid; +u32 packet_len; +struct hw_rxhdr *rxhdr; +struct sk_buff *first_skb; +struct sk_buff_head frames; +}; + +void cl_rx_amsdu_first (struct cl_hw *cl_hw,struct sk_buff *skb,struct hw_rxhdr *rxhdr, +u8 sta_idx,u8 tid,u8 encrypt_len); +bool cl_rx_amsdu_sub (struct cl_hw *cl_hw,struct sk_buff *skb); +bool cl_rx_amsdu_check_aggregation_attack (struct cl_amsdu_rx_state *amsdu_rx_state); +void cl_rx_amsdu_first_corrupted (struct cl_hw *cl_hw,struct sk_buff *skb, +struct hw_rxhdr *rxhdr); +void cl_rx_amsdu_sub_error (struct cl_hw *cl_hw,struct sk_buff *skb); +void cl_rx_amsdu_set_state_error (struct cl_hw *cl_hw, +struct hw_rxhdr *rxhdr, +enum rx_amsdu_error err); +void cl_rx_amsdu_reset (struct cl_hw *cl_hw); +void cl_rx_amsdu_stats (struct cl_hw *cl_hw,u8 msdu_cnt); +void cl_rx_amsdu_hw_en (struct ieee80211_hw *hw,bool rxamsdu_en); + +/* Field definitions */ +#define RX_CNTRL_EN_DUPLICATE_DETECTION_BIT ((u32)0x80000000) +#define RX_CNTRL_EN_DUPLICATE_DETECTION_POS 31 +#define RX_CNTRL_ACCEPT_UNKNOWN_BIT ((u32)0x40000000) +#define RX_CNTRL_ACCEPT_UNKNOWN_POS 30 +#define RX_CNTRL_ACCEPT_OTHER_DATA_FRAMES_BIT ((u32)0x20000000) +#define RX_CNTRL_ACCEPT_OTHER_DATA_FRAMES_POS 29 +#define RX_CNTRL_ACCEPT_QO_S_NULL_BIT ((u32)0x10000000) +#define RX_CNTRL_ACCEPT_QO_S_NULL_POS 28 +#define RX_CNTRL_ACCEPT_QCFWO_DATA_BIT ((u32)0x08000000) +#define RX_CNTRL_ACCEPT_QCFWO_DATA_POS 27 +#define RX_CNTRL_ACCEPT_Q_DATA_BIT ((u32)0x04000000) +#define RX_CNTRL_ACCEPT_Q_DATA_POS 26 +#define RX_CNTRL_ACCEPT_CFWO_DATA_BIT ((u32)0x02000000) +#define RX_CNTRL_ACCEPT_CFWO_DATA_POS 25 +#define RX_CNTRL_ACCEPT_DATA_BIT ((u32)0x01000000) +#define RX_CNTRL_ACCEPT_DATA_POS 24 +#define RX_CNTRL_ACCEPT_OTHER_CNTRL_FRAMES_BIT ((u32)0x00800000) +#define RX_CNTRL_ACCEPT_OTHER_CNTRL_FRAMES_POS 23 +#define RX_CNTRL_ACCEPT_CF_END_BIT ((u32)0x00400000) +#define RX_CNTRL_ACCEPT_CF_END_POS 22 +#define RX_CNTRL_ACCEPT_ACK_BIT ((u32)0x00200000) +#define RX_CNTRL_ACCEPT_ACK_POS 21 +#define RX_CNTRL_ACCEPT_CTS_BIT ((u32)0x00100000) +#define RX_CNTRL_ACCEPT_CTS_POS 20 +#define RX_CNTRL_ACCEPT_RTS_BIT ((u32)0x00080000) +#define RX_CNTRL_ACCEPT_RTS_POS 19 +#define RX_CNTRL_ACCEPT_PS_POLL_BIT ((u32)0x00040000) +#define RX_CNTRL_ACCEPT_PS_POLL_POS 18 +#define RX_CNTRL_ACCEPT_BA_BIT ((u32)0x00020000) +#define RX_CNTRL_ACCEPT_BA_POS 17 +#define RX_CNTRL_ACCEPT_BAR_BIT ((u32)0x00010000) +#define RX_CNTRL_ACCEPT_BAR_POS 16 +#define RX_CNTRL_ACCEPT_OTHER_MGMT_FRAMES_BIT ((u32)0x00008000) +#define RX_CNTRL_ACCEPT_OTHER_MGMT_FRAMES_POS 15 +#define RX_CNTRL_ACCEPT_ALL_BEACON_BIT ((u32)0x00002000) +#define RX_CNTRL_ACCEPT_ALL_BEACON_POS 13 +#define RX_CNTRL_ACCEPT_NOT_EXPECTED_BA_BIT ((u32)0x00001000) +#define RX_CNTRL_ACCEPT_NOT_EXPECTED_BA_POS 12 +#define RX_CNTRL_ACCEPT_DECRYPT_ERROR_FRAMES_BIT ((u32)0x00000800) +#define RX_CNTRL_ACCEPT_DECRYPT_ERROR_FRAMES_POS 11 +#define RX_CNTRL_ACCEPT_BEACON_BIT ((u32)0x00000400) +#define RX_CNTRL_ACCEPT_BEACON_POS 10 +#define RX_CNTRL_ACCEPT_PROBE_RESP_BIT ((u32)0x00000200) +#define RX_CNTRL_ACCEPT_PROBE_RESP_POS 9 +#define RX_CNTRL_ACCEPT_PROBE_REQ_BIT ((u32)0x00000100) +#define RX_CNTRL_ACCEPT_PROBE_REQ_POS 8 +#define RX_CNTRL_ACCEPT_MY_UNICAST_BIT ((u32)0x00000080) +#define RX_CNTRL_ACCEPT_MY_UNICAST_POS 7 +#define RX_CNTRL_ACCEPT_UNICAST_BIT ((u32)0x00000040) +#define RX_CNTRL_ACCEPT_UNICAST_POS 6 +#define RX_CNTRL_ACCEPT_ERROR_FRAMES_BIT ((u32)0x00000020) +#define RX_CNTRL_ACCEPT_ERROR_FRAMES_POS 5 +#define RX_CNTRL_ACCEPT_OTHER_BSSID_BIT ((u32)0x00000010) +#define RX_CNTRL_ACCEPT_OTHER_BSSID_POS 4 +#define RX_CNTRL_ACCEPT_BROADCAST_BIT ((u32)0x00000008) +#define RX_CNTRL_ACCEPT_BROADCAST_POS 3 +#define RX_CNTRL_ACCEPT_MULTICAST_BIT ((u32)0x00000004) +#define RX_CNTRL_ACCEPT_MULTICAST_POS 2 +#define RX_CNTRL_DONT_DECRYPT_BIT ((u32)0x00000002) +#define RX_CNTRL_DONT_DECRYPT_POS 1 +#define RX_CNTRL_EXC_UNENCRYPTED_BIT ((u32)0x00000001) +#define RX_CNTRL_EXC_UNENCRYPTED_POS 0 + +/* Default MAC Rx filters that cannot be changed by mac80211 */ +#define CL_MAC80211_NOT_CHANGEABLE ( \ + RX_CNTRL_ACCEPT_QO_S_NULL_BIT | \ + RX_CNTRL_ACCEPT_Q_DATA_BIT | \ + RX_CNTRL_ACCEPT_DATA_BIT | \ + RX_CNTRL_ACCEPT_OTHER_MGMT_FRAMES_BIT | \ + RX_CNTRL_ACCEPT_MY_UNICAST_BIT | \ + RX_CNTRL_ACCEPT_BROADCAST_BIT | \ + RX_CNTRL_ACCEPT_BEACON_BIT | \ + RX_CNTRL_ACCEPT_PROBE_RESP_BIT \ + ) + +u32 cl_rx_filter_update_flags (struct cl_hw *cl_hw,u32 filter); +void cl_rx_filter_restore_flags (struct cl_hw *cl_hw); +void cl_rx_filter_set_promiscuous (struct cl_hw *cl_hw); + +struct cl_tid_ampdu_rx { +spinlock_t reorder_lock; +u64 reorder_buf_filtered; +struct sk_buff_head *reorder_buf; +unsigned long *reorder_time; +struct ieee80211_sta *sta; +struct timer_list reorder_timer; +struct cl_hw *cl_hw; +u16 head_seq_num; +u16 stored_mpdu_num; +u16 ssn; +u16 buf_size; +u16 timeout; +u8 tid; +u8 auto_seq:1 , + removed:1 , + started:1 ; +}; + +void cl_rx_reorder_ampdu (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,struct sk_buff_head *ordered_mpdu); +void cl_rx_reorder_close (struct cl_sta *cl_sta,u8 tid); +void cl_rx_reorder_init (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u8 tid,u16 buf_size); + +#endif /* CL_RX_H */
Signature · 1 line
2.36.1
RFC v2 70/96 cl8k: add scan.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/scan.c | 392 ++++++++++++++++++++++++ 1 file changed, 392 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/scan.c
drivers/net/wireless/celeno/cl8k/scan.c new file +392 -0
@@ -0,0 +1,392 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/err.h> +#include <linux/mutex.h> +#include <linux/delay.h> +#include <linux/slab.h> + +#include "channel.h" +#include "chip.h" +#include "calib.h" +#include "debug.h" +#include "rates.h" +#include "vif.h" +#include "hw.h" +#include "scan.h" + +#define CL_MIN_SCAN_TIME_MS 50 +#define CL_MIN_WAIT_TIME_MS 20 + +static const char SCANNER_KTHREAD_NAME [] ="cl_scanner_kthread" ; + +int cl_scan_channel_switch (struct cl_hw *cl_hw,u8 channel,u8 bw, +bool allow_recalib) +{ +struct cl_vif *cl_vif =cl_vif_get_first (cl_hw); +struct cfg80211_chan_def *chandef =NULL ; +struct cfg80211_chan_def local_chandef; +struct ieee80211_channel *chan =NULL ; +u16 freq =ieee80211_channel_to_frequency (channel, cl_hw->nl_band); +int ret =0 ; + +if (!cl_vif) { + ret = -EINVAL ; + goto exit; + } + + chandef = &cl_vif->vif->bss_conf.chandef; + local_chandef = *chandef; + + chan =ieee80211_get_channel (cl_hw->hw->wiphy, freq); +if (!chan) { +cl_dbg_err (cl_hw,"Channel %u wasn't found!\n" , channel); + ret = -EINVAL ; + goto exit; + } + + local_chandef.chan = chan; +if (cl_chandef_calc (cl_hw, channel, bw, + &local_chandef.width, + &local_chandef.chan->center_freq, + &local_chandef.center_freq1)) { +cl_dbg_err (cl_hw,"Failed to extract chandef data for ch:%d\n" , + channel); + ret = -EINVAL ; + goto exit; + } + + *chandef = local_chandef; + cl_hw->hw->conf.chandef = local_chandef; + +if (cl_hw->chip->conf->ce_calib_runtime_en && allow_recalib) + ret =cl_calib_runtime_and_switch_channel (cl_hw, channel, bw, + freq, + chandef->center_freq1); +else + ret =cl_msg_tx_set_channel (cl_hw, channel, bw, freq, + chandef->center_freq1, +CL_CALIB_PARAMS_DEFAULT_STRUCT ); +exit: +return ret; +} + +static int cl_scan_channel (struct cl_chan_scanner *scanner,u8 ch_idx) +{ +u8 main_channel; +enum cl_channel_bw main_bw; +s32 res =0 ; +bool is_off_channel; +u64 scan_time_jiffies; + +/* +* 1. Save current channel +* 2. Disable tx +* 3. jump to new channel +* 4. Enable promiscious +* 5. Enable BSS collection +* 6. Reset stats counters +* 7. Sleep for scan_time +* 8. Calculate stats +* 9. Disable promiscious +* 10. Disable BSS collection +* 11. Switch to current channel +* 12. Enable tx +**/ + +cl_dbg_trace (scanner->cl_hw,"Starting scan on channel %u, scan time %u(ms)\n" , + scanner->channels[ch_idx].channel, scanner->scan_time); + +/* Save current channel */ + res =mutex_lock_interruptible (&scanner->cl_hw->set_channel_mutex); +if (res !=0 ) +return res; + main_channel = scanner->cl_hw->channel; + main_bw = scanner->cl_hw->bw; +mutex_unlock (&scanner->cl_hw->set_channel_mutex); + +cl_dbg_trace (scanner->cl_hw,"Main channel is %u with bw %u\n" , + main_channel, main_bw); + + is_off_channel = (scanner->channels[ch_idx].channel != main_channel) || + (scanner->channels[ch_idx].scan_bw != main_bw); + +/* Jump to new channel */ +if (is_off_channel) { +/* Disable tx */ +cl_tx_en (scanner->cl_hw,CL_TX_EN_SCAN , false); + + res =cl_scan_channel_switch (scanner->cl_hw, + scanner->channels[ch_idx].channel, + scanner->channels[ch_idx].scan_bw, + false); +if (res) { +cl_dbg_err (scanner->cl_hw, +"Channel switch failed: ch - %u, bw - %u, err - %d\n" , + scanner->channels[ch_idx].channel, + scanner->channels[ch_idx].scan_bw, res); + goto enable_tx; + } + }else { +cl_dbg_trace (scanner->cl_hw,"Scan on main channel %u\n" , main_channel); + } + +/* Enable promiscious mode */ +cl_rx_filter_set_promiscuous (scanner->cl_hw); + +/* Reset channel stats */ +cl_get_initial_channel_stats (scanner->cl_hw, &scanner->channels[ch_idx]); + +/* Sleep for scan time */ + scan_time_jiffies =msecs_to_jiffies (scanner->scan_time); + res =wait_for_completion_interruptible_timeout (&scanner->abort_completion, + scan_time_jiffies); +if (res >0 ) { +cl_dbg_err (scanner->cl_hw,"Scan on channel %u, bw %u, idx %u was aborted\n" , + scanner->channels[ch_idx].channel, + scanner->channels[ch_idx].scan_bw, ch_idx); + res =0 ; + } + +/* Calculate stats */ +cl_get_final_channel_stats (scanner->cl_hw, &scanner->channels[ch_idx]); + +/* Disable promiscious */ +cl_rx_filter_restore_flags (scanner->cl_hw); + +if (is_off_channel) { + res =cl_scan_channel_switch (scanner->cl_hw, main_channel, main_bw, false); +if (res) +cl_dbg_err (scanner->cl_hw, +"Switching to main ch %u, bw %u failed, err - %d\n" , + main_channel, main_bw, res); +enable_tx: +/* Enable tx */ +cl_tx_en (scanner->cl_hw,CL_TX_EN_SCAN , true); + } + +cl_dbg_trace (scanner->cl_hw,"Scan on channel %u finished, actual scan_time is %u ms\n" , + scanner->channels[ch_idx].channel, scanner->channels[ch_idx].scan_time_ms); + +return res; +} + +static s32 cl_run_off_channel_scan (struct cl_chan_scanner *scanner) +{ +u8 i =0 , scanned_channels =0 ; +s32 ret =0 ; + +for (i =0 ; i < scanner->channels_num && !scanner->scan_aborted; ++i) { +if (!scanner->channels[i].scan_enabled) +continue ; + + scanner->curr_ch_idx = i; + ret =cl_scan_channel (scanner, i); +if (ret) +cl_dbg_err (scanner->cl_hw,"scan failed, err - %d, channel - %u\n" , + ret, scanner->channels[i].channel); + +if (scanner->scan_aborted) +break ; + +cl_dbg_trace (scanner->cl_hw,"Scan on chan %u finished, waiting for time %u\n" , + scanner->channels[i].channel, scanner->wait_time); + + ++scanned_channels; +if (scanned_channels != scanner->scan_channels_num) { +u64 wait_time_jiffies; + + wait_time_jiffies =msecs_to_jiffies (scanner->wait_time); + ret =wait_for_completion_interruptible_timeout (&scanner->abort_completion, + wait_time_jiffies); +if (ret >0 ) { +cl_dbg_err (scanner->cl_hw,"Off-channel scan was aborted\n" ); + ret =0 ; + } + } + } + +if (scanner->completion_cb) + scanner->completion_cb (scanner->cl_hw, scanner->completion_arg); + +cl_dbg_info (scanner->cl_hw,"Off-channel scan on %u channels finished\n" , + scanner->scan_channels_num); + +return ret; +} + +static s32 cl_off_channel_scan_thread_fn (void *args) +{ +struct cl_chan_scanner *scanner = args; + +while (!kthread_should_stop ()) { +if (atomic_read (&scanner->scan_thread_busy)) { +cl_run_off_channel_scan (scanner); +atomic_set (&scanner->scan_thread_busy,0 ); +wake_up_interruptible (&scanner->wq); + } + +set_current_state (TASK_INTERRUPTIBLE ); +schedule (); + } + +return 0 ; +} + +static bool cl_is_scan_available (struct cl_chan_scanner *scanner) +{ +if (atomic_cmpxchg (&scanner->scan_thread_busy,0 ,1 ) ==1 ) { +cl_dbg_warn (scanner->cl_hw,"Off-channel scan is already in progress\n" ); +return false; + } + +return true; +} + +static enum cl_channel_bw cl_scanner_fix_input_bw (struct cl_chan_scanner *scanner,u8 bw) +{ +return (bw >=CHNL_BW_MAX ) ? scanner->cl_hw->bw : bw; +} + +static void cl_scanner_disable_everywhere (struct cl_chan_scanner *scanner) +{ +u8 j; + +for (j =0 ; j < scanner->channels_num; ++j) + scanner->channels[j].scan_enabled = false; +} + +s32 cl_trigger_off_channel_scan (struct cl_chan_scanner *scanner,u32 scan_time,u32 wait_time, +const u8 *channels,enum cl_channel_bw scan_bw,u8 channels_num, +void (*completion_cb)(struct cl_hw *cl_hw,void *arg), +void *completion_arg) +{ +u8 i, j; + +if (!channels || scan_bw >CHNL_BW_MAX ) +return -EINVAL ; + +if (!scanner->scans_enabled) +return 0 ; + +if (channels_num > scanner->channels_num) { +cl_dbg_err (scanner->cl_hw,"channels num %u is invalid, max is %u\n" , + channels_num, scanner->channels_num); +return -ERANGE ; + } + +if (!cl_is_scan_available (scanner)) +return -EBUSY ; + + scanner->completion_arg = completion_arg; + scanner->completion_cb = completion_cb; + scanner->scan_time =max_t (u32, scan_time,CL_MIN_SCAN_TIME_MS ); + scanner->wait_time =max_t (u32, wait_time,CL_MIN_WAIT_TIME_MS ); + scanner->scan_bw =cl_scanner_fix_input_bw (scanner, scan_bw); + scanner->scan_aborted = false; + +cl_scanner_disable_everywhere (scanner); + + scanner->scan_channels_num =0 ; +for (j =0 ; j < scanner->channels_num; ++j) { +for (i =0 ; i < channels_num; ++i) { +if (channels[i] != scanner->channels[j].channel) +continue ; + +if (!cl_chan_info_get (scanner->cl_hw, scanner->channels[j].channel, + scanner->scan_bw)) { +cl_dbg_warn (scanner->cl_hw,"channel %u with bw %u is disabled\n" , + scanner->channels[j].channel, scanner->scan_bw); +continue ; + } + + scanner->channels[j].scan_enabled = true; + ++scanner->scan_channels_num; + } + } + +reinit_completion (&scanner->abort_completion); + +wake_up_process (scanner->scan_thread); + +return 0 ; +} + +void cl_abort_scan (struct cl_chan_scanner *scanner) +{ + scanner->scan_aborted = true; +complete (&scanner->abort_completion); +cl_dbg_info (scanner->cl_hw,"Off-channel scan was aborted\n" ); +} + +bool cl_is_scan_in_progress (const struct cl_chan_scanner *scanner) +{ +return atomic_read (&scanner->scan_thread_busy); +} + +int cl_scanner_init (struct cl_hw *cl_hw) +{ +u8 i, j; +s32 ret =0 ; +u32 channels_num; +struct cl_chan_scanner *scanner; + + cl_hw->scanner =vzalloc (sizeof (*cl_hw->scanner)); +if (!cl_hw->scanner) +return -ENOMEM ; + + scanner = cl_hw->scanner; +init_completion (&scanner->abort_completion); + + scanner->cl_hw = cl_hw; + scanner->scans_enabled = true; + + channels_num =cl_channel_num (scanner->cl_hw); +for (i =0 , j =0 ; i < channels_num; ++i) { +u32 freq; + + freq =cl_channel_idx_to_freq (cl_hw, i); +if (!ieee80211_get_channel (cl_hw->hw->wiphy, freq)) +continue ; + + ret =cl_init_channel_stats (scanner->cl_hw, &scanner->channels[j], freq); +if (ret) +return ret; + +cl_dbg_trace (scanner->cl_hw,"Stats for channel %u at index %u initialized\n" , + scanner->channels[j].channel, j); + ++j; + } + + scanner->channels_num = j; + +atomic_set (&scanner->scan_thread_busy,0 ); +init_waitqueue_head (&scanner->wq); + + scanner->scan_thread =kthread_run (cl_off_channel_scan_thread_fn, + scanner,SCANNER_KTHREAD_NAME ); +if (IS_ERR (scanner->scan_thread)) { +cl_dbg_err (scanner->cl_hw,"unable to create kthread %s, err - %ld\n" , +SCANNER_KTHREAD_NAME ,PTR_ERR (scanner->scan_thread)); +return PTR_ERR (scanner->scan_thread); + } +cl_dbg_trace (scanner->cl_hw,"%s kthread was created, pid - %u\n" , +SCANNER_KTHREAD_NAME , scanner->scan_thread->pid); + +return ret; +} + +void cl_scanner_deinit (struct cl_hw *cl_hw) +{ +struct cl_chan_scanner *scanner = cl_hw->scanner; + +if (!scanner->scans_enabled) + goto out; + +if (scanner->scan_thread) +kthread_stop (scanner->scan_thread); + + out: +vfree (cl_hw->scanner); + cl_hw->scanner =NULL ; +}
Signature · 1 line
2.36.1
RFC v2 71/96 cl8k: add scan.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/scan.h | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/scan.h
drivers/net/wireless/celeno/cl8k/scan.h new file +53 -0
@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_SCAN_H +#define CL_SCAN_H + +#include <linux/kthread.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/completion.h> + +#include "channel.h" + +struct cl_chan_scanner { +struct cl_channel_stats channels[MAX_CHANNELS ]; +enum cl_channel_bw scan_bw; +u8 channels_num; +u8 scan_channels_num; +u8 curr_ch_idx; + +struct task_struct *scan_thread; +atomic_t scan_thread_busy; + +u32 scan_time; +u32 wait_time; + +bool scans_enabled; +bool scan_aborted; +struct completion abort_completion; + +u8 prescan_bw; +u32 prescan_channel; + +wait_queue_head_t wq; +struct cl_hw *cl_hw; + +void (*completion_cb)(struct cl_hw *cl_hw,void *arg); +void *completion_arg; +}; + +/* Use CHNL scan_bw =_BW_MAX to perform scan on current bandwidth */ +s32 cl_trigger_off_channel_scan (struct cl_chan_scanner *scanner,u32 scan_time,u32 wait_time, +const u8 *channels,enum cl_channel_bw scan_bw,u8 channels_num, +void (*completion_cb)(struct cl_hw *cl_hw,void *arg), +void *completion_arg); +void cl_abort_scan (struct cl_chan_scanner *scanner); +int cl_scanner_init (struct cl_hw *cl_hw); +void cl_scanner_deinit (struct cl_hw *cl_hw); +int cl_scan_channel_switch (struct cl_hw *cl_hw,u8 channel,u8 bw,bool allow_recalib); +bool cl_is_scan_in_progress (const struct cl_chan_scanner *scanner); + +#endif /* CL_SCAN_H */
Signature · 1 line
2.36.1
RFC v2 72/96 cl8k: add sounding.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/sounding.c | 1121 +++++++++++++++++++ 1 file changed, 1121 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/sounding.c
drivers/net/wireless/celeno/cl8k/sounding.c new file +1121 -0
@@ -0,0 +1,1121 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include "debug.h" +#include "bf.h" +#include "chip.h" +#include "utils.h" +#include "recovery.h" +#include "debug.h" +#include "hw.h" +#include "sounding.h" + +#define DBG_PREFIX_MAX_LENGTH 64 +#define sounding_pr (level, format, ...) \ + do { \ + if ((level) <= cl_hw->sounding.dbg_level) { \ + char __dbg_prefix[DBG_PREFIX_MAX_LENGTH] = {0}; \ + if ((level) >= DBG_LVL_TRACE) \ + snprintf(__dbg_prefix, DBG_PREFIX_MAX_LENGTH, "[%s][%d]", \ + __func__, __LINE__); \ + pr_debug("%s [Sounding] " format, __dbg_prefix, ##__VA_ARGS__); \ + } \ + } while (0) + +#define sounding_pr_verbose (...) sounding_pr(DBG_LVL_VERBOSE, ##__VA_ARGS__) +#define sounding_pr_err (...) sounding_pr(DBG_LVL_ERROR, ##__VA_ARGS__) +#define sounding_pr_warn (...) sounding_pr(DBG_LVL_WARNING, ##__VA_ARGS__) +#define sounding_pr_trace (...) sounding_pr(DBG_LVL_TRACE, ##__VA_ARGS__) +#define sounding_pr_info (...) sounding_pr(DBG_LVL_INFO, ##__VA_ARGS__) + +#define CL_SOUNDING_ALL_STA 0xff +#define CL_SOUNDING_LIFETIME_MAX 4095 +#define CL_SOUNDING_LIFETIME_FACTOR 5 +#define CL_SOUNDING_V_MATRIX_PADDING 32 +#define CL_V_MATRIX_MAC_OVERHEAD 41 +#define CL_Q_MATRIX_BITMAP_MASK 0xf + +enum cl_sounding_feedback_type { +CL_SOUNDING_FEEDBACK_TYPE_SU =0 , +CL_SOUNDING_FEEDBACK_TYPE_MU , +}; + +enum cl_sounding_ng { +CL_SOUNDING_NG_4 =0 , +CL_SOUNDING_NG_16 , +CL_SOUNDING_NG_MAX +}; + +struct sounding_work_data { +struct work_struct work; +struct cl_hw *cl_hw; +bool start; +bool is_recovery; +struct cl_sounding_info *elem;/* For stop and recovery cases */ +enum sounding_type sounding_type; +u8 gid; +u8 sta_num; +u8 bw; +u8 q_matrix_bitmap; +u8 sta_indices[CL_MU_MAX_STA_PER_GROUP ]; +}; + +static u16 ng_bw_to_nsc[CL_SOUNDING_NG_MAX ][CHNL_BW_MAX_HE ] = { + {64 ,128 ,256 ,512 }, + {32 ,32 ,64 ,128 } +}; + +static int cl_sounding_check_response (struct cl_hw *cl_hw,u8 param_err) +{ +int ret =-1 ; + +switch (param_err) { +case CL_SOUNDING_RSP_OK : +sounding_pr_trace ("param OK!\n" ); + ret =0 ; +break ; +case CL_SOUNDING_RSP_ERR_RLIMIT : +sounding_pr_err ("error, resource limit reached\n" ); +break ; +case CL_SOUNDING_RSP_ERR_BW : +sounding_pr_err ("error, unsupported BW tx requested\n" ); +break ; +case CL_SOUNDING_RSP_ERR_NSS : +sounding_pr_err ("error, unsupported ndp NSS tx requested\n" ); +break ; +case CL_SOUNDING_RSP_ERR_INTERVAL : +sounding_pr_err ("error, interval value is invalid\n" ); +break ; +case CL_SOUNDING_RSP_ERR_ALREADY : +sounding_pr_err ("error, station already associated/disassociated with sounding\n" ); +break ; +case CL_SOUNDING_RSP_ERR_STA : +sounding_pr_err ("error, station is inactive/active\n" ); +break ; +case CL_SOUNDING_RSP_ERR_TYPE : +sounding_pr_err ("error, invalid sounding type\n" ); +break ; +default : +sounding_pr_err ("error status unknown, BUG\n" ); +break ; + } + +return ret; +} + +static u32 cl_sounding_get_lifetime (struct cl_hw *cl_hw,u32 interval) +{ +u32 lifetime = (interval *CL_SOUNDING_LIFETIME_FACTOR ) >>1 ; + +if (lifetime >CL_SOUNDING_LIFETIME_MAX ) { +sounding_pr_err ("lifetime (%u) exceeds 4095\n" , lifetime); + lifetime =CL_SOUNDING_LIFETIME_MAX ; + } + +return lifetime; +} + +static bool cl_sounding_is_sta_ng_16_capable (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +bool mu_cap) +{ +struct ieee80211_sta_he_cap *he_cap = &cl_sta->sta->he_cap; + +if (he_cap->has_he) { +if (mu_cap) +return (he_cap->he_cap_elem.phy_cap_info[5 ] & +IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK ); +else +return (he_cap->he_cap_elem.phy_cap_info[5 ] & +IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK ); + } + +return false; +} + +static bool cl_sounding_is_sta_codebook_size_75_capable (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +struct ieee80211_sta_he_cap *he_cap = &cl_sta->sta->he_cap; + +if (he_cap->has_he) +return (he_cap->he_cap_elem.phy_cap_info[6 ] & +IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU ); + +return false; +} + +static void cl_sounding_extract_ng_cb_size (struct cl_hw *cl_hw,u8 fb_type_ng_cb_size, +enum cl_sounding_ng *ng,u8 *phi_psi_sum) +{ +enum cl_sounding_feedback_type fb_type = +SOUNDING_FEEDBACK_TYPE_VAL (fb_type_ng_cb_size); +u8 cb_size =SOUNDING_CODEBOOK_SIZE_VAL (fb_type_ng_cb_size); + + *ng =SOUNDING_NG_VAL (fb_type_ng_cb_size); + +switch (fb_type) { +case CL_SOUNDING_FEEDBACK_TYPE_SU : + *phi_psi_sum = (cb_size ?10 :6 ); +break ; +case CL_SOUNDING_FEEDBACK_TYPE_MU : + *phi_psi_sum = (cb_size ?16 :12 ); +break ; +default : +sounding_pr_err ("Invalid feedback_type %d\n" , fb_type); +break ; + } +} + +static u32 cl_sounding_get_v_matrix_size (struct cl_hw *cl_hw,u8 sta_idx,u8 bw,u8 nc,u8 nr, +u8 fb_type_ng_cb_size) +{ +enum cl_sounding_ng ng =0 ; +u8 phi_psi_sum =0 ; +u8 nsc; +u32 v_size; + +cl_sounding_extract_ng_cb_size (cl_hw, fb_type_ng_cb_size, &ng, &phi_psi_sum); + nsc = ng_bw_to_nsc[ng][bw]; + +/* NC and NR should start from 1 and not 0 for the below calculation */ + nc++; + nr++; + +/* v_size = [8*41 + 8*nc + (phi + psi)/2 * nsc*(nc * (2*nr-nc-1))] / 8 + extra padding */ + v_size =CL_V_MATRIX_MAC_OVERHEAD + nc + + ((phi_psi_sum * nsc * nc * (2 * nr - nc -1 )) >>4 ) + +CL_SOUNDING_V_MATRIX_PADDING ; + +sounding_pr_info ("sta %u, nc %u, nr %u, ng %d, phi_psi_sum %u, nsc %u, v_size %u\n" , + sta_idx, nc, nr, ng, phi_psi_sum, nsc, v_size); + +return v_size; +} + +static u32 cl_sounding_get_v_matrices_data_size (struct cl_hw *cl_hw, +struct sounding_info_per_sta *info_per_sta, +u8 sta_num,u8 bw,u8 nr) +{ +u8 i; +u32 v_size =0 ; + +for (i =0 ; i < sta_num; i++) + v_size +=cl_sounding_get_v_matrix_size (cl_hw, info_per_sta[i].sta_idx, + bw, info_per_sta[i].nc, + nr, info_per_sta[i].fb_type_ng_cb_size); + +sounding_pr_info ("v_matrices data size %u, sta_num %u\n" , v_size, sta_num); + +return v_size; +} + +static u32 cl_sounding_get_q_matrix_size (struct cl_hw *cl_hw, +const struct sounding_info_per_sta *info_per_sta, +u8 sta_num,u8 bw,u8 nr) +{ +u8 i; +u8 nc =0 ; +enum cl_sounding_ng ng =0 ; +u8 nsc, phi_psi_sum =0 ; +u32 q_size =0 ; + +/* +* NC and NR should start from 1 and not 0 for the below calculation +* In MU-MIMO case, when sta_num > 1, we should take the sum of all nc's +*/ +for (i =0 ; i < sta_num; i++) + nc += info_per_sta[i].nc +1 ; + + nr++; + +cl_sounding_extract_ng_cb_size (cl_hw, info_per_sta[0 ].fb_type_ng_cb_size, &ng, + &phi_psi_sum); + nsc = ng_bw_to_nsc[ng][bw]; + q_size = (nr * nc * nsc) <<2 ; + +sounding_pr_info ("q_matrix size %u, sta_num %u\n" , q_size, sta_num); + +return q_size; +} + +static u32 cl_sounding_get_required_xmem_size (struct cl_hw *cl_hw, +const struct mm_sounding_req *sounding_req, +const struct sounding_info_per_sta *info_per_sta) +{ +u8 i; +u8 sta_num = sounding_req->sta_num; +u8 q_matrix_bitmap = sounding_req->q_matrix_bitmap; +u8 bw = sounding_req->req_txbw; +u8 nr = sounding_req->ndp_nsts; +u32 total_size =0 ; + +/* +* In case of MU sounding only one Q matrix is generated. +* Otherwise, the number of Q matrices equals to te number of stations +*/ +if (sta_num >1 && + sounding_req->sounding_type !=SOUNDING_TYPE_HE_MU && + sounding_req->sounding_type !=SOUNDING_TYPE_VHT_MU ) +for (i =0 ; i < sta_num; i++) + total_size += +cl_sounding_get_q_matrix_size (cl_hw, &info_per_sta[i],1 , bw, nr); +else + total_size = +cl_sounding_get_q_matrix_size (cl_hw, info_per_sta, sta_num, bw, nr); + +/* +* If additional SU Q matrices should be generated - consider them also when calculating +* the required XMEM space +*/ +if (q_matrix_bitmap) { +for (i =0 ; i <CL_MU_MIMO_MAX_STA_PER_GRP ; i++) +if (q_matrix_bitmap &BIT (i)) + total_size += +cl_sounding_get_q_matrix_size (cl_hw, &info_per_sta[i],1 , bw, nr); + } + +return total_size; +} + +static bool cl_sounding_is_enough_xmem_space (struct cl_hw *cl_hw, +const struct mm_sounding_req *sounding_req, +const struct sounding_info_per_sta *info_per_sta, +u32 *required_size) +{ +struct cl_xmem *xmem_db = &cl_hw->chip->xmem_db; +u32 req_mem =cl_sounding_get_required_xmem_size (cl_hw, sounding_req, info_per_sta); + +if (required_size) + *required_size = req_mem; + +return ((xmem_db->size - xmem_db->total_used) >= req_mem); +} + +static void cl_sounding_fill_info_per_sta (struct cl_hw *cl_hw,u8 sounding_type,u8 bw,u8 sta_num, +struct cl_sta **cl_sta_arr, +struct sounding_info_per_sta *info_per_sta, +u8 *n_sts) +{ +u8 i; +u8 min_sts = cl_hw->num_antennas; +struct cl_sta *cl_sta =NULL ; +u8 mu_fb_type_ng_cb_size =FEEDBACK_TYPE_MU_NG_4_CODEBOOK_SIZE_9_7 ; +u8 curr_fb_type_ng_cb_size; +bool should_update_fb_type_ng_cb_size = false; + +for (i =0 ; i < sta_num; i++) { + cl_sta = cl_sta_arr[i]; + +if (!cl_sta) +continue ; + + info_per_sta[i].sta_idx = cl_sta->sta_idx; + info_per_sta[i].nc = cl_sta->bf_db.nc; + + min_sts =min (min_sts, cl_sta->bf_db.beamformee_sts); + +switch (sounding_type) { +case SOUNDING_TYPE_HE_CQI : +case SOUNDING_TYPE_HE_SU : +case SOUNDING_TYPE_VHT_SU : +case SOUNDING_TYPE_VHT_MU : + info_per_sta[i].fb_type_ng_cb_size = +FEEDBACK_TYPE_SU_NG_4_CODEBOOK_SIZE_4_2 ; +break ; +case SOUNDING_TYPE_HE_SU_TB : + info_per_sta[i].fb_type_ng_cb_size = +FEEDBACK_TYPE_SU_NG_4_CODEBOOK_SIZE_6_4 ; +break ; +case SOUNDING_TYPE_HE_CQI_TB : + info_per_sta[i].fb_type_ng_cb_size = +FEEDBACK_TYPE_CQI_TB ; +break ; +case SOUNDING_TYPE_HE_MU : +if (bw ==CHNL_BW_160 && + info_per_sta[i].nc >=WRS_SS_3 && + min_sts ==MAX_ANTENNAS ) { + should_update_fb_type_ng_cb_size = true; + +if (cl_sounding_is_sta_codebook_size_75_capable (cl_hw, cl_sta)) { + curr_fb_type_ng_cb_size = +FEEDBACK_TYPE_MU_NG_4_CODEBOOK_SIZE_7_5 ; + }else if (cl_sounding_is_sta_ng_16_capable (cl_hw, cl_sta, true)) { + curr_fb_type_ng_cb_size = +FEEDBACK_TYPE_MU_NG_16_CODEBOOK_SIZE_9_7 ; + }else { + curr_fb_type_ng_cb_size = +FEEDBACK_TYPE_MU_NG_4_CODEBOOK_SIZE_9_7 ; + mu_fb_type_ng_cb_size = +FEEDBACK_TYPE_MU_NG_4_CODEBOOK_SIZE_9_7 ; + min_sts--; + } + +if ((SOUNDING_NG_VAL (curr_fb_type_ng_cb_size) > +SOUNDING_NG_VAL (mu_fb_type_ng_cb_size)) || + (SOUNDING_CODEBOOK_SIZE_VAL (curr_fb_type_ng_cb_size) < +SOUNDING_CODEBOOK_SIZE_VAL (mu_fb_type_ng_cb_size))) + mu_fb_type_ng_cb_size = curr_fb_type_ng_cb_size; + } + + info_per_sta[i].fb_type_ng_cb_size = mu_fb_type_ng_cb_size; +break ; +default : +sounding_pr_trace ("Invalid sounding type %u\n" , sounding_type); +break ; + } + } + + *n_sts = min_sts; + +if (should_update_fb_type_ng_cb_size) +for (i =0 ; i < sta_num; i++) + info_per_sta[i].fb_type_ng_cb_size = mu_fb_type_ng_cb_size; +} + +static struct cl_sounding_info *cl_sounding_elem_alloc (struct cl_hw *cl_hw,u32 v_mat_len) +{ +struct cl_sounding_info *elem =NULL ; +dma_addr_t phys_dma_addr; +struct v_matrix_header *buf =NULL ; + + elem =kzalloc (sizeof (*elem),GFP_KERNEL ); + +if (!elem) { +CL_DBG (cl_hw,DBG_LVL_ERROR ,"kzalloc failed\n" ); +return NULL ; + } + + buf =dma_alloc_coherent (cl_hw->chip->dev, v_mat_len, &phys_dma_addr,GFP_KERNEL ); + +if (!buf) { +CL_DBG (cl_hw,DBG_LVL_ERROR ,"dma_alloc_coherent failed. size=%u\n" , v_mat_len); +kfree (elem); +return NULL ; + } + + elem->v_matrices_data = buf; + elem->v_matrices_dma_addr = phys_dma_addr; + elem->v_matrices_data_len = v_mat_len; + +return elem; +} + +static void cl_sounding_elem_free (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +struct v_matrix_header *v_data = elem->v_matrices_data; + +if (v_data) { +dma_free_coherent (cl_hw->chip->dev, elem->v_matrices_data_len, (void *)v_data, + elem->v_matrices_dma_addr); + }else { +sounding_pr_err ("%s: v_matrices_data is NULL for sid %u\n" , + __func__, elem->sounding_id); + } + + elem->v_matrices_data =NULL ; +kfree (elem); +} + +static void cl_sounding_req_success (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +cl_bf_sounding_req_success (cl_hw, elem); +} + +static void cl_sounding_req_failure (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +cl_bf_sounding_req_failure (cl_hw, elem); +} + +static void cl_sounding_increase_num_profiles (struct cl_hw *cl_hw,u8 sounding_type,u8 sta_num) +{ +if (SOUNDING_TYPE_IS_CQI (sounding_type)) + cl_hw->sounding.cqi_profiles += sta_num; +else + cl_hw->sounding.active_profiles += sta_num; +} + +static void cl_sounding_decrease_num_profiles (struct cl_hw *cl_hw,u8 sounding_type,u8 sta_num) +{ +if (SOUNDING_TYPE_IS_CQI (sounding_type)) + cl_hw->sounding.cqi_profiles -= sta_num; +else + cl_hw->sounding.active_profiles -= sta_num; +} + +static void _cl_sounding_add (struct cl_hw *cl_hw,struct cl_sounding_info *elem,u8 sounding_id, +u32 req_xmem) +{ +write_lock_bh (&cl_hw->sounding.list_lock); + elem->sounding_id = sounding_id; + elem->xmem_space = req_xmem; + cl_hw->chip->xmem_db.total_used += req_xmem; + cl_hw->sounding.num_soundings++; +list_add_tail (&elem->list, &cl_hw->sounding.head); +cl_sounding_increase_num_profiles (cl_hw, elem->type, elem->sta_num); +write_unlock_bh (&cl_hw->sounding.list_lock); +} + +static void cl_sounding_remove_from_list (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +/* Remove the sounding sequence from the list and update the XMEM and profile counters */ +write_lock_bh (&cl_hw->sounding.list_lock); +list_del (&elem->list); + cl_hw->chip->xmem_db.total_used -= elem->xmem_space; + cl_hw->sounding.num_soundings--; +cl_sounding_decrease_num_profiles (cl_hw, elem->type, elem->sta_num); +write_unlock_bh (&cl_hw->sounding.list_lock); +} + +static void cl_sounding_remove_recovery (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +u8 i; + +cl_sounding_remove_from_list (cl_hw, elem); + + { +/* Set invalid sid for all STAs related to this sounding sequence */ +for (i =0 ; i < elem->sta_num; i++) { +struct cl_sta *cl_sta = elem->su_cl_sta_arr[i]; + +if (cl_sta) + cl_sta->su_sid =INVALID_SID ; + } + } + +/* Free the deleted sounding element */ +cl_sounding_elem_free (cl_hw, elem); +} + +static void cl_sounding_start_handler (struct cl_hw *cl_hw,struct sounding_work_data *data) +{ +struct mm_sounding_req sounding_req; +struct mm_sounding_cfm *cfm =NULL ; +int ret =0 ; +u32 len =0 ; +u32 req_xmem =0 ; +struct cl_sounding_info *elem =NULL ; +u8 sounding_type = data->sounding_type; +u8 bw = data->bw; +u8 i, sta_num =0 ; +u8 q_matrix_bitmap = data->q_matrix_bitmap; +u8 min_nsts =0 ; +struct cl_sta *cl_sta_arr[CL_MU_MAX_STA_PER_GROUP ] = {NULL }; + +cl_sta_lock_bh (cl_hw); + +for (i =0 ; i < data->sta_num; i++) { +u8 sta_idx = data->sta_indices[i]; +struct cl_sta *cl_sta; + + cl_sta =cl_sta_get (cl_hw, sta_idx); + +if (!cl_sta) +continue ; + + cl_sta_arr[sta_num] = cl_sta; + sta_num++; + } + +if (!sta_num) { +cl_sta_unlock_bh (cl_hw); +sounding_pr_err ("%s: No STA found!\n" , __func__); +return ; + } + + q_matrix_bitmap &=CL_Q_MATRIX_BITMAP_MASK ; + +/* Configure sounding request parameters */ + sounding_req.start = true; + sounding_req.sounding_type = sounding_type; + sounding_req.req_txbw = bw; + sounding_req.sta_num = sta_num; + sounding_req.interval =cl_sounding_get_interval (cl_hw); + sounding_req.lifetime =cl_sounding_get_lifetime (cl_hw, sounding_req.interval); + sounding_req.q_matrix_bitmap = q_matrix_bitmap; +cl_sounding_fill_info_per_sta (cl_hw, sounding_type, bw, sta_num, cl_sta_arr, + sounding_req.info_per_sta, &min_nsts); +cl_sta_unlock_bh (cl_hw); + + sounding_req.ndp_nsts = min_nsts; + +if (data->is_recovery) { + elem = data->elem; + }else { +/* +* Check if there is enough XMEM space. +* Should be called after filling sounding req struct +*/ +if (!cl_sounding_is_enough_xmem_space (cl_hw, &sounding_req, + sounding_req.info_per_sta, &req_xmem)) { +sounding_pr_err ("There is not enough space in XMEM!\n" ); +return ; + } + +/* Should be called after filling info per STA */ + len =cl_sounding_get_v_matrices_data_size (cl_hw, sounding_req.info_per_sta, + sta_num, bw, min_nsts); + elem =cl_sounding_elem_alloc (cl_hw, len); + +if (!elem) +return ; + + elem->type = sounding_type; + elem->bw = bw; + elem->sta_num = sta_num; + elem->q_matrix_bitmap = q_matrix_bitmap; + +if (data->gid) + elem->gid = data->gid; +else +memcpy (elem->su_cl_sta_arr, cl_sta_arr, + sta_num *sizeof (cl_sta_arr[0 ])); + } + + sounding_req.host_address =cpu_to_le32 (elem->v_matrices_dma_addr); + +/* Print request parameters */ +sounding_pr_trace ("Request: start=%u, bfr_lifetime=%u, interval=%u, " +"req_txbw=%u, ndp_nsts=%u, sounding_type=%u\n" , + sounding_req.start, + sounding_req.lifetime, + sounding_req.interval, + sounding_req.req_txbw, + sounding_req.ndp_nsts, + sounding_req.sounding_type); + +/* Send message to firmware */ + ret =cl_msg_tx_sounding (cl_hw, &sounding_req); + +/* Check firmware response */ + cfm = cl_hw->msg_cfm_params[MM_SOUNDING_CFM ]; +if (ret ==0 && cfm) { + ret =cl_sounding_check_response (cl_hw, cfm->param_err); + +if (ret ==0 ) { +if (!data->is_recovery) +_cl_sounding_add (cl_hw, elem, cfm->sounding_id, req_xmem); + +cl_sounding_req_success (cl_hw, elem); + +sounding_pr_trace ("Sounding %u was enabled successfully\n" , + cfm->sounding_id); + }else { +cl_sounding_req_failure (cl_hw, elem); + +if (data->is_recovery) +cl_sounding_remove_recovery (cl_hw, elem); + } + }else { +sounding_pr_err ("%s: failed to send message (%d)\n" , __func__, ret); +cl_sounding_req_failure (cl_hw, elem); + +if (data->is_recovery) +cl_sounding_remove_recovery (cl_hw, elem); +else +cl_sounding_elem_free (cl_hw, elem); + } + +/* Free message confirmation */ +cl_msg_tx_free_cfm_params (cl_hw,MM_SOUNDING_CFM ); +} + +static void _cl_sounding_remove (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +u8 i; +struct sounding_work_data data = { + .cl_hw = cl_hw, + .bw = elem->bw, + .start = true, + .is_recovery = false, + .sta_num =0 + }; + +cl_sounding_remove_from_list (cl_hw, elem); + +/* Update invalid sid for all STAs related to this sounding sequence. +* Also start sounding for STAs that didn't request to stop sounding. +*/ + +for (i =0 ; i < elem->sta_num; i++) { +struct cl_sta *cl_sta = elem->su_cl_sta_arr[i]; + +if (!cl_sta) +continue ; + + cl_sta->su_sid =INVALID_SID ; + +/* After stopping the multi STA sounding - check if a new sounding is needed */ +if (elem->sounding_restart_required) { +if (!cl_sta->bf_db.sounding_remove_required) { + data.sta_indices[data.sta_num] = cl_sta->sta_idx; + data.sta_num++; + }else { + cl_sta->bf_db.sounding_remove_required = false; + } + } + } + +/* Start a new sounding for the remaining stations only when needed */ +if (data.sta_num) { +/* Determine new sounding type */ +if (SOUNDING_TYPE_IS_CQI (elem->type)) { +if (data.sta_num >1 ) + data.sounding_type = elem->type; +else + data.sounding_type =SOUNDING_TYPE_HE_CQI ; + }else if (SOUNDING_TYPE_IS_VHT (elem->type)) { + data.sounding_type =SOUNDING_TYPE_VHT_SU ; + }else { +if (data.sta_num >1 ) + data.sounding_type =SOUNDING_TYPE_HE_SU_TB ; +else + data.sounding_type =SOUNDING_TYPE_HE_SU ; + } + +cl_sounding_start_handler (cl_hw, &data); + } + +/* Free the deleted sounding element */ +cl_sounding_elem_free (cl_hw, elem); +} + +static void cl_sounding_stop_handler (struct cl_hw *cl_hw,struct cl_sounding_info *elem) +{ +struct mm_sounding_req sounding_req; +int ret =0 ; + +if (!elem) { +sounding_pr_err ("elem is NULL!!\n" ); +return ; + } + +/* Configure sounding request parameters */ + sounding_req.start = false; + sounding_req.sounding_type = elem->type; + sounding_req.sid = elem->sounding_id; + +/* Print request parameters */ +sounding_pr_trace ("Delete request: sid=%u, sounding_type=%u\n" , + elem->sounding_id, elem->type); + +/* Send message to firmware */ + ret =cl_msg_tx_sounding (cl_hw, &sounding_req); + +/* Check firmware response */ +if (ret) +sounding_pr_err ("%s: failed to send message (%d)\n" , __func__, ret); +else +/* Free message confirmation */ +cl_msg_tx_free_cfm_params (cl_hw,MM_SOUNDING_CFM ); + +/* Remove the sounding sequence from the list and update the used XMEM counter. +* Notice that elem is freed and shouldn't be accessed after the call to this function. +*/ +_cl_sounding_remove (cl_hw, elem); +} + +static void cl_sounding_handler_send_request (struct work_struct *work) +{ +struct sounding_work_data *data = (struct sounding_work_data *)work; +struct cl_hw *cl_hw = data->cl_hw; + +if (data->start) { +cl_sounding_start_handler (cl_hw, data); + }else { +u8 sid; + + { +u8 sta_idx = data->sta_indices[0 ]; +struct cl_sta *cl_sta; + +cl_sta_lock_bh (cl_hw); + cl_sta =cl_sta_get (cl_hw, sta_idx); + sid = cl_sta ? cl_sta->su_sid :U8_MAX ; +cl_sta_unlock_bh (cl_hw); + } + +if (data->elem) +cl_sounding_stop_handler (cl_hw, data->elem); +else +cl_sounding_stop_by_sid (cl_hw, sid, false); + } + +kfree (data); +} + +static u16 cl_sounding_calc_interval (struct cl_hw *cl_hw,u8 active_profiles) +{ +/* Sounding interval = min interval + [(active_profiles - 1) / STA step] * interval step */ + +u16 *coefs = cl_hw->conf->ce_sounding_interval_coefs; +u16 min_interval = coefs[SOUNDING_INTERVAL_COEF_MIN_INTERVAL ]; +u16 max_interval = coefs[SOUNDING_INTERVAL_COEF_MAX_INTERVAL ]; +u8 sta_step = coefs[SOUNDING_INTERVAL_COEF_STA_STEP ]; +u8 interval_step = coefs[SOUNDING_INTERVAL_COEF_INTERVAL_STEP ]; +u16 ret = min_interval; + +if (active_profiles <= sta_step) +return ret; + + active_profiles--; + ret += (active_profiles / sta_step) * interval_step; + +return min (ret, max_interval); +} + +static void cl_sounding_handler_change_interval (struct work_struct *work) +{ +struct sounding_work_data *data = (struct sounding_work_data *)work; +struct cl_hw *cl_hw = data->cl_hw; +struct mm_sounding_interval_cfm *sounding_interval_cfm =NULL ; +int ret =0 ; +/* Configure sounding request parameters */ +u16 interval =cl_sounding_get_interval (cl_hw); +u16 lifetime =cl_sounding_get_lifetime (cl_hw, interval); + +sounding_pr_trace ("Sounding interval request: sta_idx=%d, interval=%u, " +"lifetime=%u, sounding_type=%u\n" , +CL_SOUNDING_ALL_STA , interval, lifetime, data->sounding_type); + +/* Start/Stop synchronize sounding request periodically */ + ret =cl_msg_tx_sounding_interval (cl_hw, interval, lifetime, data->sounding_type, +CL_SOUNDING_ALL_STA ); + sounding_interval_cfm = cl_hw->msg_cfm_params[MM_SOUNDING_INTERVAL_CFM ]; +if (ret ==0 && sounding_interval_cfm) +cl_sounding_check_response (cl_hw, sounding_interval_cfm->param_err); +else +sounding_pr_err ("%s: failed to send message (%d)\n" , __func__, ret); + +cl_msg_tx_free_cfm_params (cl_hw,MM_SOUNDING_INTERVAL_CFM ); +kfree (data); +} + +static void cl_sounding_recovery_reset (struct cl_hw *cl_hw) +{ +struct cl_sounding_db *sounding_db = &cl_hw->sounding; + +memset (sounding_db->active_profiles_prev,0 ,sizeof (u8) *CL_SOUNDING_STABILITY_TIME ); + sounding_db->active_profiles_idx =0 ; +cl_sta_loop (cl_hw, cl_bf_reset_sounding_ind); +} + +void cl_sounding_init (struct cl_hw *cl_hw) +{ +struct cl_sounding_db *sounding_db = &cl_hw->sounding; + +memset (sounding_db,0 ,sizeof (*sounding_db)); + sounding_db->sounding_wq =create_workqueue ("cl_sounding_wq" ); + sounding_db->current_interval = + cl_hw->conf->ce_sounding_interval_coefs[SOUNDING_INTERVAL_COEF_MIN_INTERVAL ]; + sounding_db->dbg_level =1 ; + cl_hw->chip->xmem_db.size =XMEM_SIZE ; +INIT_LIST_HEAD (&sounding_db->head); +rwlock_init (&sounding_db->list_lock); +} + +void cl_sounding_close (struct cl_hw *cl_hw) +{ +struct cl_sounding_info *elem, *tmp; + +if (cl_hw->sounding.sounding_wq) +destroy_workqueue (cl_hw->sounding.sounding_wq); + +list_for_each_entry_safe (elem, tmp, &cl_hw->sounding.head, list) { +/* Don't try to start a new sounding sequence after stopping this one */ + elem->sounding_restart_required = false; +cl_sounding_stop_handler (cl_hw, elem); + } +} + +struct cl_sounding_info *cl_sounding_get_elem (struct cl_hw *cl_hw,u8 sounding_id) +{ +struct cl_sounding_info *elem =NULL ; + +read_lock_bh (&cl_hw->sounding.list_lock); + +list_for_each_entry (elem, &cl_hw->sounding.head, list) { +if (elem->sounding_id == sounding_id) { +read_unlock_bh (&cl_hw->sounding.list_lock); +return elem; + } + } + +read_unlock_bh (&cl_hw->sounding.list_lock); + +return NULL ; +} + +void cl_sounding_send_request (struct cl_hw *cl_hw,struct cl_sta **cl_sta_arr, +u8 sta_num,bool enable,u8 sounding_type,u8 bw, +void *mu_grp, +u8 q_matrix_bitmap,struct cl_sounding_info *recovery_elem) +{ +struct sounding_work_data *data; +struct cl_sounding_info *elem =NULL ; +u8 i; +struct cl_sta *cl_sta =NULL ; +bool background = (preempt_count () !=0 ); + +if (cl_band_is_24g (cl_hw) &&SOUNDING_TYPE_IS_VHT (sounding_type)) { +sounding_pr_err ("A VHT sounding type (%u) is not supported in 2.4g band\n" , + sounding_type); +return ; + } + +/* +* When Multiple STAs are members of a single sounding process, that is about to be stopped, +* we want to schedule the stopping work only once and possibly start another sounding +* sequence for STAs that still want to use it. +*/ +if (enable) + goto next; + + cl_sta = cl_sta_arr[0 ]; +if (cl_sta) { +u8 sid = cl_sta->su_sid; + +if (sid !=INVALID_SID ) { + elem =cl_sounding_get_elem (cl_hw, sid); + +if (!elem) { +sounding_pr_trace ("Sounding %u not found\n" , sid); +return ; + } + + cl_sta->bf_db.sounding_remove_required = true; + +if (elem->sounding_restart_required) +return ; + elem->sounding_restart_required = true; + } + } + +next: +/* data will be freed in work handler */ + data =kzalloc (sizeof (*data),GFP_ATOMIC ); + +if (!data) +return ; + + data->cl_hw = cl_hw; + data->start = enable; + data->sounding_type = sounding_type; + data->bw = bw; + data->is_recovery =cl_recovery_in_progress (cl_hw); + data->elem = recovery_elem ? recovery_elem : elem; + +/* Fill cl_sta_arr */ + { +for (i =0 ; i < sta_num; i++) + data->sta_indices[i] = cl_sta_arr[i]->sta_idx; + + data->sta_num = sta_num; + } + +if (background) { +INIT_WORK (&data->work, cl_sounding_handler_send_request); +queue_work (cl_hw->sounding.sounding_wq, &data->work); + }else { +cl_sounding_handler_send_request ((struct work_struct *)data); + } +} + +static void cl_sounding_change_interval (struct cl_hw *cl_hw,u8 sounding_type) +{ +/* Data will be freed in work handler */ +struct sounding_work_data *data =kzalloc (sizeof (*data),GFP_ATOMIC ); + +if (!data) +return ; + +INIT_WORK (&data->work, cl_sounding_handler_change_interval); + data->cl_hw = cl_hw; + data->sounding_type = sounding_type; +queue_work (cl_hw->sounding.sounding_wq, &data->work); +} + +void cl_sounding_stop_by_sid (struct cl_hw *cl_hw,u8 sid,bool sounding_restart_check) +{ +struct cl_sounding_info *elem =cl_sounding_get_elem (cl_hw, sid); + +if (!elem) { +sounding_pr_trace ("Sounding with id %u not found or is in the middle of removal\n" , + sid); +return ; + } + + elem->sounding_restart_required = sounding_restart_check; +cl_sounding_stop_handler (cl_hw, elem); +} + +void cl_sounding_maintenance (struct cl_hw *cl_hw) +{ +/* +* Change sounding_index accoording to number of active_profiles. +* sounding_index is modified only if number of active_profiles is stable for 5 seconds. +* +* Examples: +* e.g #1: active_profiles=2, active_profiles_prev=3,3,3,3,3 - stabilised on 3 +* e.g #3: active_profiles=2, active_profiles_prev=1,1,1,1,1 - stabilised on 1 +* e.g #2: active_profiles=5, active_profiles_prev=6,7,7,6,6 - stabilised on 6 +* e.g #4: active_profiles=5, active_profiles_prev=4,3,3,2,4 - stabilised on 4 +*/ + +int i =0 ; +u8 active_profiles_min =255 ; +u8 active_profiles_max =0 ; +u8 active_profiles = cl_hw->sounding.last_conf_active_profiles; +u8 active_profiles_new =0 ; +u16 interval; +u16 interval_new; + +/* Add to last 5 sec buffer */ + cl_hw->sounding.active_profiles_prev[cl_hw->sounding.active_profiles_idx] = + cl_hw->sounding.active_profiles; + +/* Increase cyclic index */ + cl_hw->sounding.active_profiles_idx++; +if (cl_hw->sounding.active_profiles_idx ==CL_SOUNDING_STABILITY_TIME ) + cl_hw->sounding.active_profiles_idx =0 ; + +/* Find active_profiles min/max in last 5 seconds */ +for (i =0 ; i <CL_SOUNDING_STABILITY_TIME ; i++) { +if (cl_hw->sounding.active_profiles_prev[i] < active_profiles_min) + active_profiles_min = cl_hw->sounding.active_profiles_prev[i]; + +if (cl_hw->sounding.active_profiles_prev[i] > active_profiles_max) + active_profiles_max = cl_hw->sounding.active_profiles_prev[i]; + } + +if (active_profiles < active_profiles_min) + active_profiles_new = active_profiles_min; +else if (active_profiles > active_profiles_max) + active_profiles_new = active_profiles_max; +else /* Active_profiles in last 5 seconds did not change or is not stable */ +return ; + + interval =cl_sounding_calc_interval (cl_hw, active_profiles); + interval_new =cl_sounding_calc_interval (cl_hw, active_profiles_new); + +/* Check if sounding interval changed */ +if (interval != interval_new) { + cl_hw->sounding.last_conf_active_profiles = active_profiles_new; + cl_hw->sounding.current_interval = interval_new; +cl_sounding_change_interval (cl_hw,SOUNDING_TYPE_MAX ); +sounding_pr_trace ("Interval: current = %u, new = %u\n" , + interval, interval_new); + } +} + +u16 cl_sounding_get_interval (struct cl_hw *cl_hw) +{ +return cl_hw->sounding.current_interval; +} + +static void cl_sounding_indication_pr (struct cl_hw *cl_hw, +struct mm_sounding_ind *ind, +struct v_matrix_header *v_matrix, +u8 *avg_snr) +{ +sounding_pr_info ("Sounding indication: nc index = %u, BFR BW = %u, " +"SNR1 = %u, SNR2 = %u, SNR3 = %u, SNR4 = %u, SNR5 = %u, SNR6 = %u," +"feedback type = %u, sta index = %u\n" , + v_matrix->nc_index, v_matrix->bw, + avg_snr[0 ], avg_snr[1 ], avg_snr[2 ], avg_snr[3 ], avg_snr[4 ], + avg_snr[5 ], ind->sounding_type, ind->sta_idx); +} + +static void cl_sounding_indication_su (struct cl_hw *cl_hw, +struct mm_sounding_ind *ind, +struct cl_sounding_info *sounding_elem) +{ +struct cl_sta *cl_sta; +struct v_matrix_header *v_matrix =NULL ; +u8 *avg_snr =NULL ; +bool pairing = false; + + v_matrix = sounding_elem->v_matrices_data + ind->v_matrix_offset[0 ]; + avg_snr = (u8 *)v_matrix + v_matrix->padding; + +cl_sta_lock (cl_hw); + cl_sta =cl_sta_get (cl_hw, ind->sta_idx); + +if (cl_sta) { +struct cl_bf_sta_db *bf_db = &cl_sta->bf_db; + +/* Update Nc for the current STA */ + bf_db->nc = v_matrix->nc_index; + bf_db->sounding_indications++; + +if (bf_db->sounding_indications ==1 ) { +/* +* After getting first indication disable the timer and set the BF +* bit in the firmware rate flags. +*/ +del_timer (&bf_db->timer); +cl_bf_update_rate (cl_hw, cl_sta); + pairing = true; + } + } + +cl_sta_unlock (cl_hw); + +/* Send a msg to fw to pair the STA with sounding ID */ +if (pairing) +cl_msg_tx_sounding_pairing (cl_hw, ind->sid, ind->sounding_type,0 , ind->sta_idx); + +cl_sounding_indication_pr (cl_hw, ind, v_matrix, avg_snr); +} + +void cl_sounding_indication (struct cl_hw *cl_hw,struct mm_sounding_ind *ind) +{ +struct cl_sounding_info *sounding_elem =NULL ; + + sounding_elem =cl_sounding_get_elem (cl_hw, ind->sid); + +if (!sounding_elem) { +sounding_pr_err ("[%s]: sounding id %u not found!\n" , __func__, ind->sid); +return ; + } + +switch (ind->sounding_type) { +case SOUNDING_TYPE_HE_SU : +case SOUNDING_TYPE_HE_SU_TB : +case SOUNDING_TYPE_VHT_SU : +case SOUNDING_TYPE_HE_CQI : +case SOUNDING_TYPE_HE_CQI_TB : +break ; +default : +sounding_pr_err ("[%s]: Invalid sounding type %u\n" , __func__, + ind->sounding_type); +return ; + } + +cl_sounding_indication_su (cl_hw, ind, sounding_elem); +} + +void cl_sounding_recovery (struct cl_hw *cl_hw) +{ +/* +* After recovery process we need to update sounding requests and +* sounding interval in firmware +*/ +struct cl_sounding_info *elem; + +/* No sounding is active */ +if (!cl_hw->sounding.num_soundings) +return ; + +/* Reset sounding parameters */ +cl_sounding_recovery_reset (cl_hw); + +/* +* Go over all clients that had sounding before recovery, +* and send a new sounding request to firmware. +*/ + +sounding_pr_trace ("Start sounding recovery\n" ); + +list_for_each_entry (elem, &cl_hw->sounding.head, list) +cl_bf_sounding_start (cl_hw, elem->type, elem->su_cl_sta_arr, elem->sta_num, elem); +} +
Signature · 1 line
2.36.1
RFC v2 73/96 cl8k: add sounding.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/sounding.h | 151 ++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/sounding.h
drivers/net/wireless/celeno/cl8k/sounding.h new file +151 -0
@@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_SOUNDING_H +#define CL_SOUNDING_H + +#include <linux/types.h> + +#include "fw.h" + +#define SOUNDING_ENABLE true +#define SOUNDING_DISABLE false +#define INVALID_SID 0xff +#define XMEM_SIZE (0x180 << 10)/* 384KB */ +#define CL_SOUNDING_STABILITY_TIME 5 +#define CL_SOUNDING_FACTOR 10 + +#define SOUNDING_FEEDBACK_TYPE_SHIFT 2 +#define SOUNDING_FEEDBACK_TYPE_MASK (BIT(SOUNDING_FEEDBACK_TYPE_SHIFT)) +#define SOUNDING_NG_SHIFT 1 +#define SOUNDING_NG_MASK (BIT(SOUNDING_NG_SHIFT)) +#define SOUNDING_MU_CODEBOOK_SIZE_SHIFT 0 +#define SOUNDING_MU_CODEBOOK_SIZE_MASK (BIT(SOUNDING_MU_CODEBOOK_SIZE_SHIFT)) +#define SOUNDING_FEEDBACK_TYPE_VAL (fb_type_ng_cb_size) (((fb_type_ng_cb_size) & \ + SOUNDING_FEEDBACK_TYPE_MASK) >> \ + SOUNDING_FEEDBACK_TYPE_SHIFT) +#define SOUNDING_NG_VAL (fb_type_ng_cb_size) (((fb_type_ng_cb_size) & \ + SOUNDING_NG_MASK) >> SOUNDING_NG_SHIFT) +#define SOUNDING_CODEBOOK_SIZE_VAL (fb_type_ng_cb_size) (((fb_type_ng_cb_size) & \ + SOUNDING_MU_CODEBOOK_SIZE_MASK) >> \ + SOUNDING_MU_CODEBOOK_SIZE_SHIFT) + +#define SOUNDING_TYPE_IS_VHT (type) ((type) == SOUNDING_TYPE_VHT_SU || \ + (type) == SOUNDING_TYPE_VHT_MU) +#define SOUNDING_TYPE_IS_CQI (type) ((type) == SOUNDING_TYPE_HE_CQI || \ + (type) == SOUNDING_TYPE_HE_CQI_TB) + +enum fb_type_ng_cb_size { +FEEDBACK_TYPE_SU_NG_4_CODEBOOK_SIZE_4_2 =0x0 , +FEEDBACK_TYPE_SU_NG_4_CODEBOOK_SIZE_6_4 , +FEEDBACK_TYPE_SU_NG_16_CODEBOOK_SIZE_4_2 , +FEEDBACK_TYPE_SU_NG_16_CODEBOOK_SIZE_6_4 , +FEEDBACK_TYPE_MU_NG_4_CODEBOOK_SIZE_7_5 , +FEEDBACK_TYPE_MU_NG_4_CODEBOOK_SIZE_9_7 , +FEEDBACK_TYPE_CQI_TB , +FEEDBACK_TYPE_MU_NG_16_CODEBOOK_SIZE_9_7 , +}; + +enum cl_sounding_response { +CL_SOUNDING_RSP_OK =0 , + +CL_SOUNDING_RSP_ERR_RLIMIT , +CL_SOUNDING_RSP_ERR_BW , +CL_SOUNDING_RSP_ERR_NSS , +CL_SOUNDING_RSP_ERR_INTERVAL , +CL_SOUNDING_RSP_ERR_ALREADY , +CL_SOUNDING_RSP_ERR_STA , +CL_SOUNDING_RSP_ERR_TYPE , +}; + +enum sounding_type { +SOUNDING_TYPE_HE_SU =0 , +SOUNDING_TYPE_HE_SU_TB , +SOUNDING_TYPE_VHT_SU , +SOUNDING_TYPE_HE_CQI , +SOUNDING_TYPE_HE_CQI_TB , +SOUNDING_TYPE_HE_MU , +SOUNDING_TYPE_VHT_MU , + +SOUNDING_TYPE_MAX +}; + +enum sounding_interval_coef { +SOUNDING_INTERVAL_COEF_MIN_INTERVAL =0 , +SOUNDING_INTERVAL_COEF_STA_STEP , +SOUNDING_INTERVAL_COEF_INTERVAL_STEP , +SOUNDING_INTERVAL_COEF_MAX_INTERVAL , +SOUNDING_INTERVAL_COEF_MAX +}; + +struct v_matrix_header { +u32 format :2 , + rsv1 :30 ; +u32 bw :2 , + nr_index :3 , + nc_index :3 , + rsv2 :24 ; +u32 grouping :4 , + rsv3 :28 ; +u32 feedback_type :1 , + codebook_info :3 , + rsv4 :28 ; +u32 ru_start_idx :7 , + rsv5 :25 ; +u32 ru_end_idx :7 , + rsv6 :25 ; +u32 padding :6 , + rsv7 :26 ; +u32 rsv8; +}; + +struct cl_sounding_info { +enum sounding_type type; +u8 sounding_id; +struct v_matrix_header *v_matrices_data; +u32 v_matrices_data_len; +u32 v_matrices_dma_addr; +u8 gid; +u8 bw; +u8 sta_num; +u8 q_matrix_bitmap; +struct cl_sta *su_cl_sta_arr[CL_MU_MAX_STA_PER_GROUP ]; +u32 xmem_space; +bool sounding_restart_required; +struct list_head list; +}; + +struct cl_sounding_db { +struct workqueue_struct *sounding_wq; +u8 num_soundings; +u8 cqi_profiles;/* Num of STAs with CQI active sounding */ +u8 active_profiles;/* Num of STAs with non-CQI active sounding */ +u8 active_profiles_prev[CL_SOUNDING_STABILITY_TIME ]; +u8 active_profiles_idx; +u8 dbg_level; +u8 current_interval; +u8 last_conf_active_profiles; +rwlock_t list_lock; +struct list_head head; +}; + +struct cl_xmem { +u32 total_used; +u32 size; +}; + +void cl_sounding_init (struct cl_hw *cl_hw); +void cl_sounding_close (struct cl_hw *cl_hw); +void cl_sounding_send_request (struct cl_hw *cl_hw,struct cl_sta **cl_sta_arr, +u8 sta_num,bool enable,u8 sounding_type,u8 bw, +void *mu_grp, +u8 q_matrix_bitmap,struct cl_sounding_info *recovery_elem); +void cl_sounding_switch_profile (struct cl_hw *cl_hw,u8 sta_idx_en,u8 sta_idx_dis); +void cl_sounding_stop_by_sid (struct cl_hw *cl_hw,u8 sid,bool sounding_restart_check); +void cl_sounding_maintenance (struct cl_hw *cl_hw); +u16 cl_sounding_get_interval (struct cl_hw *cl_hw); +void cl_sounding_recovery (struct cl_hw *cl_hw); +struct cl_sounding_info *cl_sounding_get_elem (struct cl_hw *cl_hw,u8 sounding_id); +void cl_sounding_indication (struct cl_hw *cl_hw,struct mm_sounding_ind *ind); + +#endif /* CL_SOUNDING_H */
Signature · 1 line
2.36.1
RFC v2 74/96 cl8k: add sta.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/sta.c | 507 +++++++++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/sta.c
drivers/net/wireless/celeno/cl8k/sta.c new file +507 -0
@@ -0,0 +1,507 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include "chip.h" +#include "phy.h" +#include "bf.h" +#include "vns.h" +#include "tx.h" +#include "radio.h" +#include "motion_sense.h" +#include "mac_addr.h" +#include "recovery.h" +#include "dfs.h" +#include "stats.h" +#include "utils.h" +#include "sta.h" + +void cl_sta_init (struct cl_hw *cl_hw) +{ +u32 i; + +rwlock_init (&cl_hw->cl_sta_db.lock); +INIT_LIST_HEAD (&cl_hw->cl_sta_db.head); + +for (i =0 ; i <CL_STA_HASH_SIZE ; i++) +INIT_LIST_HEAD (&cl_hw->cl_sta_db.hash[i]); +} + +void cl_sta_init_sta (struct cl_hw *cl_hw,struct ieee80211_sta *sta) +{ +if (!cl_recovery_in_progress (cl_hw)) { +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); + +/* Reset all cl_sta strcture */ +memset (cl_sta,0 ,sizeof (struct cl_sta )); + cl_sta->sta = sta; +/* +* Set sta_idx to 0xFF since FW expects this value as long as +* the STA is not fully connected +*/ + cl_sta->sta_idx =STA_IDX_INVALID ; + } +} + +static void cl_sta_add_to_lut (struct cl_hw *cl_hw,struct cl_vif *cl_vif,struct cl_sta *cl_sta) +{ +write_lock_bh (&cl_hw->cl_sta_db.lock); + + cl_hw->cl_sta_db.num++; + cl_vif->num_sta++; + cl_hw->cl_sta_db.lut[cl_sta->sta_idx] = cl_sta; + +/* Done here inside the lock because it allocates cl_stats */ +cl_stats_sta_add (cl_hw, cl_sta); + +write_unlock_bh (&cl_hw->cl_sta_db.lock); + +cl_dbg_verbose (cl_hw,"mac=%pM, sta_idx=%u, vif_index=%u\n" , + cl_sta->addr, cl_sta->sta_idx, cl_sta->cl_vif->vif_index); +} + +static void cl_sta_add_to_list (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +u8 hash_idx =CL_STA_HASH_IDX (cl_sta->addr[5 ]); + +write_lock_bh (&cl_hw->cl_sta_db.lock); + +/* Add to hash table */ +list_add (&cl_sta->list_hash, &cl_hw->cl_sta_db.hash[hash_idx]); + +/* Make sure that cl_sta's are stored in the list according to their sta_idx. */ +if (list_empty (&cl_hw->cl_sta_db.head)) { +list_add (&cl_sta->list, &cl_hw->cl_sta_db.head); + }else if (list_is_singular (&cl_hw->cl_sta_db.head)) { +struct cl_sta *cl_sta_singular = + list_first_entry(&cl_hw->cl_sta_db.head, struct cl_sta, list); + +if (cl_sta_singular->sta_idx < cl_sta->sta_idx) +list_add_tail (&cl_sta->list, &cl_hw->cl_sta_db.head); +else +list_add (&cl_sta->list, &cl_hw->cl_sta_db.head); + }else { +struct cl_sta *cl_sta_last = + list_last_entry(&cl_hw->cl_sta_db.head, struct cl_sta, list); + +if (cl_sta->sta_idx > cl_sta_last->sta_idx) { +list_add_tail (&cl_sta->list, &cl_hw->cl_sta_db.head); + }else { +struct cl_sta *cl_sta_next =NULL ; +struct cl_sta *cl_sta_prev =NULL ; + +list_for_each_entry (cl_sta_next, &cl_hw->cl_sta_db.head, list) { +if (cl_sta_next->sta_idx < cl_sta->sta_idx) +continue ; + + cl_sta_prev =list_prev_entry (cl_sta_next, list); +__list_add (&cl_sta->list, &cl_sta_prev->list, &cl_sta_next->list); +break ; + } + } + } + +write_unlock_bh (&cl_hw->cl_sta_db.lock); + + cl_sta->add_complete = true; +} + +static void cl_connection_data_add (struct cl_vif *cl_vif) +{ +struct cl_connection_data *conn_data = cl_vif->conn_data; + +if (cl_vif->num_sta > conn_data->max_client) { + conn_data->max_client = cl_vif->num_sta; + conn_data->max_client_timestamp =ktime_get_real_seconds (); + } + +if (cl_vif->num_sta == conn_data->watermark_threshold) + conn_data->watermark_reached_cnt++; +} + +static void cl_connection_data_remove (struct cl_vif *cl_vif) +{ +struct cl_connection_data *conn_data = cl_vif->conn_data; + +if (cl_vif->num_sta == conn_data->watermark_threshold) + conn_data->watermark_reached_cnt++; +} + +static void _cl_sta_add (struct cl_hw *cl_hw,struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct cl_vif *cl_vif = (struct cl_vif *)vif->drv_priv; +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); + +/* !!! Must be first !!! */ +cl_sta_add_to_lut (cl_hw, cl_vif, cl_sta); + +cl_baw_init (cl_sta); +cl_txq_sta_add (cl_hw, cl_sta); +cl_vns_sta_add (cl_hw, cl_sta); +cl_connection_data_add (cl_vif); + +/* +* Add rssi of association request to rssi pool +* Make sure to call it before cl_wrs_api_sta_add() +*/ +cl_rssi_assoc_find (cl_hw, cl_sta, cl_hw->cl_sta_db.num); + +cl_motion_sense_sta_add (cl_hw, cl_sta); +cl_bf_sta_add (cl_hw, cl_sta, sta); +cl_wrs_api_sta_add (cl_hw, sta); +cl_wrs_api_set_smps_mode (cl_hw, sta, sta->bandwidth); +#ifdef CONFIG_CL8K_DYN_MCAST_RATE +/* Should be called after cl_wrs_api_sta_add() */ +cl_dyn_mcast_rate_update_upon_assoc (cl_hw, cl_sta->wrs_sta.mode, + cl_hw->cl_sta_db.num); +#endif /* CONFIG_CL8K_DYN_MCAST_RATE */ +#ifdef CONFIG_CL8K_DYN_BCAST_RATE +cl_dyn_bcast_rate_update_upon_assoc (cl_hw, + cl_sta->wrs_sta.tx_su_params.rate_params.mcs, + cl_hw->cl_sta_db.num); +#endif /* CONFIG_CL8K_DYN_BCAST_RATE */ + +/* !!! Must be last !!! */ +cl_sta_add_to_list (cl_hw, cl_sta); +} + +/* +* Parse the ampdu density to retrieve the value in usec, according to +* the values defined in ieee80211.h +*/ +static u8 cl_sta_density2usec (u8 ampdu_density) +{ +switch (ampdu_density) { +case IEEE80211_HT_MPDU_DENSITY_NONE : +return 0 ; +/* 1 microsecond is our granularity */ +case IEEE80211_HT_MPDU_DENSITY_0_25 : +case IEEE80211_HT_MPDU_DENSITY_0_5 : +case IEEE80211_HT_MPDU_DENSITY_1 : +return 1 ; +case IEEE80211_HT_MPDU_DENSITY_2 : +return 2 ; +case IEEE80211_HT_MPDU_DENSITY_4 : +return 4 ; +case IEEE80211_HT_MPDU_DENSITY_8 : +return 8 ; +case IEEE80211_HT_MPDU_DENSITY_16 : +return 16 ; +default : +return 0 ; + } +} + +static void cl_sta_set_min_spacing (struct cl_hw *cl_hw, +struct ieee80211_sta *sta) +{ +bool is_6g =cl_band_is_6g (cl_hw); +u8 sta_min_spacing =0 ; +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); + +if (is_6g) + sta_min_spacing = +cl_sta_density2usec (le16_get_bits (sta->he_6ghz_capa.capa, +IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START )); +else if (sta->ht_cap.ht_supported) + sta_min_spacing = +cl_sta_density2usec (sta->ht_cap.ampdu_density); +else +cl_dbg_err (cl_hw,"HT is not supported - cannot set sta_min_spacing\n" ); + + cl_sta->ampdu_min_spacing = +max (cl_sta_density2usec (IEEE80211_HT_MPDU_DENSITY_1 ), sta_min_spacing); +} + +u32 cl_sta_num (struct cl_hw *cl_hw) +{ +u32 num =0 ; + +read_lock (&cl_hw->cl_sta_db.lock); + num = cl_hw->cl_sta_db.num; +read_unlock (&cl_hw->cl_sta_db.lock); + +return num; +} + +u32 cl_sta_num_bh (struct cl_hw *cl_hw) +{ +u32 num =0 ; + +read_lock_bh (&cl_hw->cl_sta_db.lock); + num = cl_hw->cl_sta_db.num; +read_unlock_bh (&cl_hw->cl_sta_db.lock); + +return num; +} + +struct cl_sta *cl_sta_get (struct cl_hw *cl_hw,u8 sta_idx) +{ +if (sta_idx <CL_MAX_NUM_STA ) +return cl_hw->cl_sta_db.lut[sta_idx]; + +return NULL ; +} + +struct cl_sta *cl_sta_get_by_addr (struct cl_hw *cl_hw,u8 *addr) +{ +struct cl_sta *cl_sta =NULL ; +u8 hash_idx =CL_STA_HASH_IDX (addr[5 ]); + +if (is_multicast_ether_addr (addr)) +return NULL ; + +list_for_each_entry (cl_sta, &cl_hw->cl_sta_db.hash[hash_idx], list_hash) +if (cl_mac_addr_compare (cl_sta->addr, addr)) +return cl_sta; + +return NULL ; +} + +void cl_sta_loop (struct cl_hw *cl_hw,sta_callback callback) +{ +struct cl_sta *cl_sta =NULL ; + +/* Go over all stations */ +read_lock (&cl_hw->cl_sta_db.lock); + +list_for_each_entry (cl_sta, &cl_hw->cl_sta_db.head, list) +callback (cl_hw, cl_sta); + +read_unlock (&cl_hw->cl_sta_db.lock); +} + +void cl_sta_loop_bh (struct cl_hw *cl_hw,sta_callback callback) +{ +struct cl_sta *cl_sta =NULL ; + +/* Go over all stations - use bottom-half lock */ +read_lock_bh (&cl_hw->cl_sta_db.lock); + +list_for_each_entry (cl_sta, &cl_hw->cl_sta_db.head, list) +callback (cl_hw, cl_sta); + +read_unlock_bh (&cl_hw->cl_sta_db.lock); +} + +static int cl_sta_add_to_firmware (struct cl_hw *cl_hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta = (struct cl_sta *)sta->drv_priv; +struct cl_vif *cl_vif = (struct cl_vif *)vif->drv_priv; +struct mm_sta_add_cfm *sta_add_cfm; +int error =0 ; +u8 recovery_sta_idx =0 ; +u32 rate_ctrl_info =0 ; + +if (cl_recovery_in_progress (cl_hw)) { +struct cl_wrs_rate_params *rate_params = &cl_sta->wrs_sta.tx_su_params.rate_params; + +/* +* If station is added to firmware during recovery, the driver passes to firmware +* the station index to be used instead of firmware selecting a free index +*/ + recovery_sta_idx = cl_sta->sta_idx; + +/* Keep current rate value */ + rate_ctrl_info =cl_rate_ctrl_generate (cl_hw, cl_sta, rate_params->mode, + rate_params->bw, rate_params->nss, + rate_params->mcs, rate_params->gi, + false, false); + }else { +bool is_cck =cl_band_is_24g (cl_hw) &&cl_hw_mode_is_b_or_bg (cl_hw); +u8 mode = is_cck ?WRS_MODE_CCK :WRS_MODE_OFDM ; + +/* +* Not in recovery: +* firmware will set sta_idx and will return in confirmation message +*/ + recovery_sta_idx =STA_IDX_INVALID ; + +/* Default rate value */ + rate_ctrl_info =cl_rate_ctrl_generate (cl_hw, cl_sta, mode, +0 ,0 ,0 ,0 , false, false); + } + +/* Must be called before cl_msg_tx_sta_add() */ +cl_sta_set_min_spacing (cl_hw, sta); + +/* Send message to firmware */ + error =cl_msg_tx_sta_add (cl_hw, sta, cl_vif, recovery_sta_idx, rate_ctrl_info); +if (error) +return error; + + sta_add_cfm = (struct mm_sta_add_cfm *)(cl_hw->msg_cfm_params[MM_STA_ADD_CFM ]); +if (!sta_add_cfm) +return -ENOMSG ; + +if (sta_add_cfm->status !=0 ) { +cl_dbg_verbose (cl_hw,"Status Error (%u)\n" , sta_add_cfm->status); +cl_msg_tx_free_cfm_params (cl_hw,MM_STA_ADD_CFM ); +return -EIO ; + } + +/* Save the index retrieved from firmware */ + cl_sta->sta_idx = sta_add_cfm->sta_idx; + +/* Release cfm msg */ +cl_msg_tx_free_cfm_params (cl_hw,MM_STA_ADD_CFM ); + +return 0 ; +} + +int cl_sta_add (struct cl_hw *cl_hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta = (struct cl_sta *)sta->drv_priv; +struct cl_vif *cl_vif = (struct cl_vif *)vif->drv_priv; +int error =0 ; + +if (cl_radio_is_going_down (cl_hw)) +return -EPERM ; + +if (vif->type ==NL80211_IFTYPE_MESH_POINT && + cl_vif->num_sta >=CL_MAX_NUM_MESH_POINT ) +return -EPERM ; + + cl_sta->cl_vif = cl_vif; +cl_mac_addr_copy (cl_sta->addr, sta->addr); + + error =cl_sta_add_to_firmware (cl_hw, vif, sta); +if (error) +return error; + +if (!cl_recovery_in_progress (cl_hw)) +if (vif->type !=NL80211_IFTYPE_STATION || + cl_hw->chip->conf->ce_production_mode) +_cl_sta_add (cl_hw, vif, sta); + +if (vif->type ==NL80211_IFTYPE_MESH_POINT && cl_vif->num_sta ==1 ) +set_bit (CL_DEV_MESH_AP , &cl_hw->drv_flags); + +return 0 ; +} + +void cl_sta_mgd_add (struct cl_hw *cl_hw,struct cl_vif *cl_vif,struct ieee80211_sta *sta) +{ +/* Should be called in station mode */ +struct cl_sta *cl_sta = (struct cl_sta *)sta->drv_priv; + +/* !!! Must be first !!! */ +cl_sta_add_to_lut (cl_hw, cl_vif, cl_sta); + +cl_baw_init (cl_sta); +cl_txq_sta_add (cl_hw, cl_sta); +cl_vns_sta_add (cl_hw, cl_sta); + +/* +* Add rssi of association response to rssi pool +* Make sure to call it before cl_wrs_api_sta_add() +*/ +cl_rssi_assoc_find (cl_hw, cl_sta, cl_hw->cl_sta_db.num); + +cl_connection_data_add (cl_vif); + +/* In station mode we assume that the AP we connect to is static */ +cl_motion_sense_sta_add (cl_hw, cl_sta); +cl_bf_sta_add (cl_hw, cl_sta, sta); +cl_wrs_api_sta_add (cl_hw, sta); +#ifdef CONFIG_CL8K_DYN_MCAST_RATE +/* Should be called after cl_wrs_api_sta_add() */ +cl_dyn_mcast_rate_update_upon_assoc (cl_hw, cl_sta->wrs_sta.mode, + cl_hw->cl_sta_db.num); +#endif /* CONFIG_CL8K_DYN_MCAST_RATE */ +#ifdef CONFIG_CL8K_DYN_BCAST_RATE +cl_dyn_bcast_rate_update_upon_assoc (cl_hw, + cl_sta->wrs_sta.tx_su_params.rate_params.mcs, + cl_hw->cl_sta_db.num); + +#endif /* CONFIG_CL8K_DYN_BCAST_RATE */ +/* !!! Must be last !!! */ +cl_sta_add_to_list (cl_hw, cl_sta); +} + +static void _cl_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +write_lock_bh (&cl_hw->cl_sta_db.lock); + +list_del (&cl_sta->list); +list_del (&cl_sta->list_hash); + + cl_hw->cl_sta_db.lut[cl_sta->sta_idx] =NULL ; + cl_hw->cl_sta_db.num--; + cl_sta->cl_vif->num_sta--; + +cl_dbg_verbose (cl_hw,"mac=%pM, sta_idx=%u, vif_index=%u\n" , + cl_sta->addr, cl_sta->sta_idx, cl_sta->cl_vif->vif_index); + +write_unlock_bh (&cl_hw->cl_sta_db.lock); +} + +void cl_sta_remove (struct cl_hw *cl_hw,struct ieee80211_vif *vif,struct ieee80211_sta *sta) +{ +struct cl_vif *cl_vif = (struct cl_vif *)vif->drv_priv; +struct cl_sta *cl_sta = (struct cl_sta *)sta->drv_priv; +u8 sta_idx = cl_sta->sta_idx; + + cl_sta->remove_start = true; + +/* !!! Must be first - remove from list and LUT !!! */ +_cl_sta_remove (cl_hw, cl_sta); + +cl_traffic_sta_remove (cl_hw, cl_sta); +cl_bf_sta_remove (cl_hw, cl_sta); +cl_connection_data_remove (cl_vif); +#ifdef CONFIG_CL8K_DYN_MCAST_RATE +cl_dyn_mcast_rate_update_upon_disassoc (cl_hw, + cl_sta->wrs_sta.mode, + cl_hw->cl_sta_db.num); +#endif /* CONFIG_CL8K_DYN_MCAST_RATE */ +#ifdef CONFIG_CL8K_DYN_BCAST_RATE +cl_dyn_bcast_rate_update_upon_disassoc (cl_hw, + cl_sta->wrs_sta.tx_su_params.rate_params.mcs, + cl_hw->cl_sta_db.num); +#endif /* CONFIG_CL8K_DYN_BCAST_RATE */ +cl_wrs_api_sta_remove (cl_hw, cl_sta); +cl_stats_sta_remove (cl_hw, cl_sta); + +/* +* TX stop flow: +* 1) Flush TX queues +* 2) Poll confirmation queue and clear enhanced TIM +* 3) Send MM_STA_DEL_REQ message to firmware +* 4) Flush confirmation queue +* 5) Reset write index +*/ + +cl_txq_flush_sta (cl_hw, cl_sta); +cl_single_cfm_poll_empty_sta (cl_hw, sta_idx); +cl_txq_sta_remove (cl_hw, sta_idx); + +if (cl_vif->vif->type ==NL80211_IFTYPE_MESH_POINT && + cl_vif->num_sta ==0 ) { +clear_bit (CL_DEV_MESH_AP , &cl_hw->drv_flags); + } + +cl_single_cfm_flush_sta (cl_hw, sta_idx); + +cl_msg_tx_sta_del (cl_hw, sta_idx); + +if (cl_vif->num_sta ==0 ) +cl_radio_off_wake_up (cl_hw); +} + +void cl_sta_ps_notify (struct cl_hw *cl_hw,struct cl_sta *cl_sta,bool is_ps) +{ +struct sta_info *stainfo =IEEE80211_STA_TO_STAINFO (cl_sta->sta); + +/* +* PS-Poll & UAPSD are handled by FW, by setting +* WLAN_STA_SP we ensure mac80211 does not re-handle. +* flag is unset at ieee80211_sta_ps_deliver_wakeup +*/ +if (is_ps) +set_sta_flag (stainfo,WLAN_STA_SP ); + +cl_stats_update_ps (cl_hw, cl_sta, is_ps); +} +
Signature · 1 line
2.36.1
RFC v2 75/96 cl8k: add sta.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/sta.h | 99 ++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/sta.h
drivers/net/wireless/celeno/cl8k/sta.h new file +99 -0
@@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_STA_H +#define CL_STA_H + +#include "sta_info.h" +#include "mac80211.h" +#include "rates.h" +#include "motion_sense.h" +#include "tx.h" +#include "traffic.h" +#include "bf.h" +#include "vns.h" + +#define IEEE80211_STA_TO_CL_STA (sta) ((struct cl_sta *)(sta)->drv_priv) +#define IEEE80211_STA_TO_STAINFO (ieee80211_sta) (container_of(ieee80211_sta, struct sta_info, sta)) + +#define CL_MAX_NUM_MESH_POINT 8 + +/* +* Structure used to save information relative to the managed stations. +* Will be used as the 'drv_priv' field of the "struct ieee80211_sta" structure. +*/ +struct cl_sta { +struct list_head list; +struct list_head list_hash; +u8 sta_idx; +u8 su_sid; +bool key_disable; +u8 addr[ETH_ALEN ]; +struct cl_baw baws[IEEE80211_NUM_TIDS ]; +struct cl_amsdu_ctrl amsdu_anchor[IEEE80211_NUM_TIDS ]; +struct cl_tx_queue *agg_tx_queues[IEEE80211_NUM_TIDS ]; +u8 rx_pn[IEEE80211_NUM_TIDS ][IEEE80211_CCMP_PN_LEN ]; +struct cl_vif *cl_vif; +struct ieee80211_sta *sta; +struct ieee80211_key_conf *key_conf; +struct cl_bf_sta_db bf_db; +struct cl_stats *stats; +s32 alpha_rssi; +bool manual_alpha_rssi; +s8 last_rssi[MAX_ANTENNAS ]; +u8 ampdu_min_spacing; +struct cl_traffic_sta traffic_db[TRAFFIC_DIRECTION_MAX ]; +struct cl_traffic_mon traffic_mon[CL_TRFC_MON_PROT_MAX ][CL_TRFC_MON_DIR_MAX ]; +struct cl_vns_sta_db vns_db; +u32 retry_count; +u32 data_pending[AC_MAX ]; +struct cl_wrs_info wrs_info_tx_su; +struct cl_wrs_info wrs_info_tx_mu_mimo; +struct cl_wrs_info wrs_info_rx; +struct cl_wrs_rssi wrs_rssi; +bool add_complete; +bool remove_start; +struct cl_wrs_sta wrs_sta; +struct cl_motion_sense motion_sense; +union cl_rate_ctrl_info_he rate_ctrl_he; +bool tf_support_dis; +struct cl_tid_ampdu_rx *tid_agg_rx[IEEE80211_NUM_TIDS ]; +u64 tx_bytes; +u64 rx_bytes; +bool stop_tx; +bool pause_tx; + +}; + +#define CL_STA_HASH_SIZE (CL_MAX_NUM_STA / 2) +#define CL_STA_HASH_MASK (CL_STA_HASH_SIZE - 1) +#define CL_STA_HASH_IDX (x) ((x) & CL_STA_HASH_MASK) + +struct cl_sta_db { +struct list_head head; +struct cl_sta *lut[CL_MAX_NUM_STA ]; +struct list_head hash[CL_STA_HASH_SIZE ]; +rwlock_t lock; +u32 num; +}; + +typedef void (*sta_callback )(struct cl_hw *,struct cl_sta *); + +/* These functions take the lock inside */ +u32 cl_sta_num (struct cl_hw *cl_hw); +u32 cl_sta_num_bh (struct cl_hw *cl_hw); + +/* Must take lock before calling these functions */ +struct cl_sta *cl_sta_get (struct cl_hw *cl_hw,u8 sta_idx); +struct cl_sta *cl_sta_get_by_addr (struct cl_hw *cl_hw,u8 *addr); + +void cl_sta_init (struct cl_hw *cl_hw); +void cl_sta_loop (struct cl_hw *cl_hw,sta_callback callback); +void cl_sta_loop_bh (struct cl_hw *cl_hw,sta_callback callback); +void cl_sta_init_sta (struct cl_hw *cl_hw,struct ieee80211_sta *sta); +int cl_sta_add (struct cl_hw *cl_hw,struct ieee80211_vif *vif,struct ieee80211_sta *sta); +void cl_sta_mgd_add (struct cl_hw *cl_hw,struct cl_vif *cl_vif,struct ieee80211_sta *sta); +void cl_sta_remove (struct cl_hw *cl_hw,struct ieee80211_vif *vif,struct ieee80211_sta *sta); +void cl_sta_ps_notify (struct cl_hw *cl_hw,struct cl_sta *cl_sta,bool is_ps); + +#endif /* CL_STA_H */
Signature · 1 line
2.36.1
RFC v2 76/96 cl8k: add stats.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/stats.c | 438 +++++++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/stats.c
drivers/net/wireless/celeno/cl8k/stats.c new file +438 -0
@@ -0,0 +1,438 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/string.h> + +#include "reg/reg_access.h" +#include "sta.h" +#include "utils.h" +#include "reg/reg_defs.h" +#include "rates.h" +#include "debug.h" +#include "tx.h" +#include "vif.h" +#include "stats.h" + +static void cll_stats_config_ps (struct cl_sta *cl_sta) +{ +struct sta_info *stainfo =IEEE80211_STA_TO_STAINFO (cl_sta->sta); + + cl_sta->stats->ps.timestamp_sleep = jiffies; + cl_sta->stats->ps.is_ps =test_sta_flag (stainfo,WLAN_STA_PS_STA ); +} + +static void cl_stats_free (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +kfree (cl_sta->stats); + cl_sta->stats =NULL ; +} + +static void cl_stats_disable (struct cl_hw *cl_hw) +{ +pr_debug ("Statistics disabled\n" ); + cl_hw->conf->ci_stats_en = false; +cl_sta_loop (cl_hw, cl_stats_free); + +if (cl_hw_is_prod_or_listener (cl_hw)) { +kfree (cl_hw->rx_stats); + cl_hw->rx_stats =NULL ; + } +} + +static void _cl_stats_update_tx (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report) +{ +struct cl_stats *stats = cl_sta->stats; +struct cl_tx_cntrs *cntrs; +union cl_rate_ctrl_info rate_ctrl_info = { + .word =le32_to_cpu (agg_report->rate_cntrl_info)}; +u8 bw, nss, mcs, gi, bf; + +switch (rate_ctrl_info.field.format_mod) { +case WRS_MODE_HE : + nss = (rate_ctrl_info.field.mcs_index >>4 ); + mcs = (rate_ctrl_info.field.mcs_index &0xF ); + gi = rate_ctrl_info.field.gi; + + { + bw = rate_ctrl_info.field.bw; + bf = agg_report->bf; + + cntrs = &stats->tx.he[bw][nss][mcs][gi][bf]; + } +break ; +case WRS_MODE_VHT : + bw = rate_ctrl_info.field.bw; + nss = (rate_ctrl_info.field.mcs_index >>4 ); + mcs = (rate_ctrl_info.field.mcs_index &0xF ); + gi = rate_ctrl_info.field.gi; + bf = agg_report->bf; + + cntrs = &stats->tx.vht[bw][nss][mcs][gi][bf]; +break ; +case WRS_MODE_HT : + bw = rate_ctrl_info.field.bw; + nss = (rate_ctrl_info.field.mcs_index >>3 ); + mcs = (rate_ctrl_info.field.mcs_index &0x7 ); + gi = rate_ctrl_info.field.gi; + cntrs = &stats->tx.ht[bw][nss][mcs][gi]; +break ; +case WRS_MODE_OFDM : + mcs = rate_ctrl_info.field.mcs_index -RATE_CTRL_OFFSET_OFDM ; + cntrs = &stats->tx.ofdm[mcs]; +break ; +case WRS_MODE_CCK : + mcs = rate_ctrl_info.field.mcs_index; + cntrs = &stats->tx.cck[mcs]; +break ; +default : +return ; + } + + cntrs->success += agg_report->success; + cntrs->fail += agg_report->fail; + stats->tx.packet_success += agg_report->success; + stats->tx.packet_fail += agg_report->fail; +} + +static void _cl_stats_update_rx_rate (struct cl_hw *cl_hw,struct cl_rx_stats *rx_stats, +struct hw_rxhdr *rxhdr) +{ +u8 bw, nss, mcs, gi; + +switch (rxhdr->format_mod) { +case FORMATMOD_HE_TRIG : + nss = rxhdr->n_sts &0x3 ; + mcs =min_t (u8, rxhdr->mcs,WRS_MCS_MAX_HE ); + gi =min_t (u8, rxhdr->gi_type,WRS_GI_MAX_HE ); + rx_stats->he_trig[rxhdr->ch_bw][nss][mcs][gi] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_HE_TRIG ; +break ; +case FORMATMOD_HE_EXT : + nss = rxhdr->n_sts &0x3 ; + mcs =min_t (u8, rxhdr->mcs,WRS_MCS_MAX_HE ); + gi =min_t (u8, rxhdr->gi_type,WRS_GI_MAX_HE ); + rx_stats->he_ext[rxhdr->ch_bw][nss][mcs][gi] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_HE_EXT ; +break ; +case FORMATMOD_HE_MU : + nss = rxhdr->n_sts &0x3 ; + mcs =min_t (u8, rxhdr->mcs,WRS_MCS_MAX_HE ); + gi =min_t (u8, rxhdr->gi_type,WRS_GI_MAX_HE ); + rx_stats->he_mu[rxhdr->ch_bw][nss][mcs][gi] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_HE_MU ; +break ; +case FORMATMOD_HE_SU : + nss = rxhdr->n_sts &0x3 ; + mcs =min_t (u8, rxhdr->mcs,WRS_MCS_MAX_HE ); + gi =min_t (u8, rxhdr->gi_type,WRS_GI_MAX_HE ); + rx_stats->he_su[rxhdr->ch_bw][nss][mcs][gi] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_HE_SU ; +break ; +case FORMATMOD_VHT : + nss = rxhdr->n_sts &0x3 ; + mcs =min_t (u8, rxhdr->mcs,WRS_MCS_MAX_VHT ); + gi = rxhdr->gi_type &0x1 ; + rx_stats->vht[rxhdr->ch_bw][nss][mcs][gi] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_VHT ; +break ; +case FORMATMOD_HT_MF : +case FORMATMOD_HT_GF : + bw = rxhdr->ch_bw &0x1 ; + nss = (rxhdr->mcs >>3 ) &0x3 ; + mcs = rxhdr->mcs &0x7 ; + gi = rxhdr->gi_type &0x1 ; + rx_stats->ht[bw][nss][mcs][gi] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_HT ; +break ; +case FORMATMOD_NON_HT : +if (rxhdr->mcs >=RATE_CTRL_OFFSET_OFDM ) { + mcs = (rxhdr->mcs -RATE_CTRL_OFFSET_OFDM ) &0x7 ; + rx_stats->ofdm[mcs] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_OFDM ; + }else if (cl_band_is_24g (cl_hw)) { + mcs = rxhdr->mcs &0x3 ; + rx_stats->cck[mcs] += rxhdr->frm_successful_rx; + rx_stats->flag |=RX_STATS_CCK ; + } +break ; + } + + rx_stats->packet_success += rxhdr->frm_successful_rx; +} + +void cl_stats_init (struct cl_hw *cl_hw) +{ +spin_lock_init (&cl_hw->lock_stats); + +if (cl_hw->conf->ci_stats_en &&cl_hw_is_prod_or_listener (cl_hw)) { + cl_hw->rx_stats =kzalloc (sizeof (*cl_hw->rx_stats),GFP_ATOMIC ); + +if (!cl_hw->rx_stats) + cl_hw->conf->ci_stats_en = false; + } +} + +void cl_stats_deinit (struct cl_hw *cl_hw) +{ +spin_lock_bh (&cl_hw->lock_stats); + +if (cl_hw->conf->ci_stats_en && (cl_hw_is_prod_or_listener (cl_hw))) { + cl_hw->conf->ci_stats_en = false; + +kfree (cl_hw->rx_stats); + cl_hw->rx_stats =NULL ; + } + +spin_unlock_bh (&cl_hw->lock_stats); +} + +void cl_stats_sta_add (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +/* +* If allocation failed disable ci_stats_en +* and free the memory of all other stations +*/ +bool disable = false; + +if (cl_hw->conf->ci_stats_en) { +/* +* Take regular lock and not BH, +* because cl_sta_add_to_lut() already disables BH +*/ +spin_lock (&cl_hw->lock_stats); + + cl_sta->stats =kzalloc (sizeof (*cl_sta->stats),GFP_ATOMIC ); + +if (cl_sta->stats) +cll_stats_config_ps (cl_sta); +else + disable = true; + +spin_unlock (&cl_hw->lock_stats); + } + +if (disable && cl_hw->conf->ci_stats_en) { +spin_lock_bh (&cl_hw->lock_stats); +cl_stats_disable (cl_hw); +spin_unlock_bh (&cl_hw->lock_stats); + } +} + +void cl_stats_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock_bh (&cl_hw->lock_stats); + +cl_stats_free (cl_hw, cl_sta); + +spin_unlock_bh (&cl_hw->lock_stats); +} + +void cl_stats_update_tx_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report) +{ +struct cl_stats *stats = cl_sta->stats; + +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock (&cl_hw->lock_stats); + + stats->tx.agg_cntr++; + stats->tx.fail_cntr += agg_report->fail; +_cl_stats_update_tx (cl_hw, cl_sta, agg_report); + +spin_unlock (&cl_hw->lock_stats); +} + +void cl_stats_update_tx_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report) +{ +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock (&cl_hw->lock_stats); + + cl_sta->stats->tx.fail_cntr += agg_report->fail; +_cl_stats_update_tx (cl_hw, cl_sta, agg_report); + +spin_unlock (&cl_hw->lock_stats); +} + +void cl_stats_update_rx_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +s8 rssi[MAX_ANTENNAS ]) +{ +int i; +s8 rx_rssi; + +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock_bh (&cl_hw->lock_stats); + +for (i =0 ; i < cl_hw->num_antennas; i++) { + rx_rssi = rssi[i] *-1 ; + +if (rx_rssi >=0 && rx_rssi <RSSI_ARR_SIZE ) + cl_sta->stats->rssi[rx_rssi][i]++; + } + +spin_unlock_bh (&cl_hw->lock_stats); +} + +void cl_stats_update_rx_rate (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct hw_rxhdr *rxhdr) +{ +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock (&cl_hw->lock_stats); + +_cl_stats_update_rx_rate (cl_hw, &cl_sta->stats->rx, rxhdr); + cl_sta->stats->fec_coding[rxhdr->fec_coding]++; + +spin_unlock (&cl_hw->lock_stats); +} + +void cl_stats_update_rx_rate_production (struct cl_hw *cl_hw,struct hw_rxhdr *rxhdr) +{ +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock (&cl_hw->lock_stats); + +_cl_stats_update_rx_rate (cl_hw, cl_hw->rx_stats, rxhdr); + +spin_unlock (&cl_hw->lock_stats); +} + +void cl_stats_update_ps (struct cl_hw *cl_hw,struct cl_sta *cl_sta,bool is_ps) +{ +struct cl_ps_stats *ps; + +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock_bh (&cl_hw->lock_stats); + + ps = &cl_sta->stats->ps; + +if (ps->is_ps == is_ps) + goto out; + + ps->is_ps = is_ps; + +if (is_ps) { + ps->timestamp_sleep = jiffies; + }else { +unsigned long sleep_time =jiffies_to_msecs (jiffies - ps->timestamp_sleep); + +if (sleep_time <=50 ) + ps->period[PS_PERIOD_50MS ]++; +else if (sleep_time <=100 ) + ps->period[PS_PERIOD_100MS ]++; +else if (sleep_time <=250 ) + ps->period[PS_PERIOD_250MS ]++; +else if (sleep_time <=500 ) + ps->period[PS_PERIOD_500MS ]++; +else if (sleep_time <=750 ) + ps->period[PS_PERIOD_750MS ]++; +else if (sleep_time <=1000 ) + ps->period[PS_PERIOD_1000MS ]++; +else if (sleep_time <=2000 ) + ps->period[PS_PERIOD_2000MS ]++; +else if (sleep_time <=5000 ) + ps->period[PS_PERIOD_5000MS ]++; +else if (sleep_time <=10000 ) + ps->period[PS_PERIOD_10000MS ]++; +else + ps->period[PS_PERIOD_ABOVE ]++; + } + +out: +spin_unlock_bh (&cl_hw->lock_stats); +} + +int cl_stats_get_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +struct cl_stats *stats =NULL ; +u32 i =0 , j =0 ; +u64 total_rssi =0 ; +s8 avg_signal =0 ; + +if (!cl_hw->conf->ci_stats_en) +return 0 ; + +u64 avg_rssi[MAX_ANTENNAS ] = {0 }; +u64 sum_rssi[MAX_ANTENNAS ] = {0 }; + +spin_lock_bh (&cl_hw->lock_stats); + + stats = cl_sta->stats; + +if (!stats) + goto out; + +for (i =0 ; i <RSSI_ARR_SIZE ; i++) { + total_rssi =0 ; + +for (j =0 ; j < cl_hw->num_antennas; j++) { + sum_rssi[j] += stats->rssi[i][j]; + avg_rssi[j] += i * stats->rssi[i][j]; + } + } + +for (j =0 ; j < cl_hw->num_antennas; j++) +if (sum_rssi[j]) + avg_rssi[j] =div64_u64 (avg_rssi[j], sum_rssi[j]); + +for (j =0 ; j < cl_hw->num_antennas; j++) + total_rssi += avg_rssi[j]; + + avg_signal = -div64_u64 (total_rssi, cl_hw->num_antennas); +out: +spin_unlock_bh (&cl_hw->lock_stats); + +return avg_signal; +} + +void cl_stats_get_tx (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +u64 *total_tx_success,u64 *total_tx_fail) +{ +if (!cl_hw->conf->ci_stats_en) +return ; + +spin_lock_bh (&cl_hw->lock_stats); + +if (!cl_sta->stats) + goto out; + + *total_tx_success = cl_sta->stats->tx.packet_success; + *total_tx_fail = cl_sta->stats->tx.packet_fail; + +out: +spin_unlock_bh (&cl_hw->lock_stats); +} + +u64 cl_stats_get_rx (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +u64 total_rx_packets =0 ; + +if (!cl_hw->conf->ci_stats_en) +return 0 ; + +spin_lock_bh (&cl_hw->lock_stats); + +if (!cl_sta->stats) + goto out; + + total_rx_packets = cl_sta->stats->rx.packet_success; + +out: +spin_unlock_bh (&cl_hw->lock_stats); + +return total_rx_packets; +} +
Signature · 1 line
2.36.1
Re: [RFC v2 76/96] cl8k: add stats.c
On 5/24/2022 4:34 AM, [email protected] wrote:
[snip]
Quoted 6 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +6
-0+static void _cl_stats_update_tx (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report) +{ +struct cl_stats *stats = cl_sta->stats; +struct cl_tx_cntrs *cntrs; +union cl_rate_ctrl_info rate_ctrl_info = {
drivers/net/wireless/celeno/cl8k/stats.c line 57
Quoted 10 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +10
-0+ .word = le32_to_cpu(agg_report->rate_cntrl_info)}; +u8 bw, nss, mcs, gi, bf; + +switch (rate_ctrl_info.field.format_mod) { +case WRS_MODE_HE : + nss = (rate_ctrl_info.field.mcs_index >>4 ); + mcs = (rate_ctrl_info.field.mcs_index &0xF ); + gi = rate_ctrl_info.field.gi; + + {
why an embedded block? seems to serve no purpose
drivers/net/wireless/celeno/cl8k/stats.c line 61
Quoted 4 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +4
-0+ bw = rate_ctrl_info.field.bw; + bf = agg_report->bf; + + cntrs = &stats->tx.he[bw][nss][mcs][gi][bf];
bad indentation
drivers/net/wireless/celeno/cl8k/stats.c line 71
Quoted 10 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +10
-0+ } +break ; +case WRS_MODE_VHT : + bw = rate_ctrl_info.field.bw; + nss = (rate_ctrl_info.field.mcs_index >>4 ); + mcs = (rate_ctrl_info.field.mcs_index &0xF ); + gi = rate_ctrl_info.field.gi; + bf = agg_report->bf; + + cntrs = &stats->tx.vht[bw][nss][mcs][gi][bf];
bad indentation
Quoted 19 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +19
-0+break ; +case WRS_MODE_HT : + bw = rate_ctrl_info.field.bw; + nss = (rate_ctrl_info.field.mcs_index >>3 ); + mcs = (rate_ctrl_info.field.mcs_index &0x7 ); + gi = rate_ctrl_info.field.gi; + cntrs = &stats->tx.ht[bw][nss][mcs][gi]; +break ; +case WRS_MODE_OFDM : + mcs = rate_ctrl_info.field.mcs_index -RATE_CTRL_OFFSET_OFDM ; + cntrs = &stats->tx.ofdm[mcs]; +break ; +case WRS_MODE_CCK : + mcs = rate_ctrl_info.field.mcs_index; + cntrs = &stats->tx.cck[mcs]; +break ; +default : +return ; + }
Re: [RFC v2 76/96] cl8k: add stats.c
Quoted 9 lines · On Thu, 2 Jun 2022 13:59:38 -0700, [email protected] wrote:
why an embedded block? seems to serve no purpose
drivers/net/wireless/celeno/cl8k/stats.c line 61
Quoted 4 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +4
-0+ bw = rate_ctrl_info.field.bw; + bf = agg_report->bf; + + cntrs = &stats->tx.he[bw][nss][mcs][gi][bf];bad indentation
Quoted 12 lines
drivers/net/wireless/celeno/cl8k/stats.c line 71
Quoted 10 lines
drivers/net/wireless/celeno/cl8k/stats.c new file +10
-0+ } +break ; +case WRS_MODE_VHT : + bw = rate_ctrl_info.field.bw; + nss = (rate_ctrl_info.field.mcs_index >>4 ); + mcs = (rate_ctrl_info.field.mcs_index &0xF ); + gi = rate_ctrl_info.field.gi; + bf = agg_report->bf; + + cntrs = &stats->tx.vht[bw][nss][mcs][gi][bf];bad indentation
Correct – that is an artifact from old version of code. Will fix that!
Best regards,
Viktor Barna
RFC v2 77/96 cl8k: add stats.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/stats.h | 108 +++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/stats.h
drivers/net/wireless/celeno/cl8k/stats.h new file +108 -0
@@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_STATS_H +#define CL_STATS_H + +#include "wrs.h" + +enum cl_rx_stats_flag { +RX_STATS_CCK =0x01 , +RX_STATS_OFDM =0x02 , +RX_STATS_HT =0x04 , +RX_STATS_VHT =0x08 , +RX_STATS_HE_SU =0x10 , +RX_STATS_HE_MU =0x20 , +RX_STATS_HE_EXT =0x40 , +RX_STATS_HE_TRIG =0x80 , +}; + +struct cl_rx_stats { +u32 he_trig[CHNL_BW_MAX_HE ][WRS_SS_MAX ][WRS_MCS_MAX_HE ][WRS_GI_MAX_HE ]; +u32 he_ext[CHNL_BW_MAX_HE ][WRS_SS_MAX ][WRS_MCS_MAX_HE ][WRS_GI_MAX_HE ]; +u32 he_mu[CHNL_BW_MAX_HE ][WRS_SS_MAX ][WRS_MCS_MAX_HE ][WRS_GI_MAX_HE ]; +u32 he_su[CHNL_BW_MAX_HE ][WRS_SS_MAX ][WRS_MCS_MAX_HE ][WRS_GI_MAX_HE ]; +u32 vht[CHNL_BW_MAX_VHT ][WRS_SS_MAX ][WRS_MCS_MAX_VHT ][WRS_GI_MAX_VHT ]; +u32 ht[CHNL_BW_MAX_HT ][WRS_SS_MAX ][WRS_MCS_MAX_HT ][WRS_GI_MAX_HT ]; +u32 ofdm[WRS_MCS_MAX_OFDM ]; +u32 cck[WRS_MCS_MAX_CCK ]; +u8 flag; +u64 packet_success; +}; + +#define RSSI_ARR_SIZE 128 +#define BF_IDX_MAX 2 + +struct cl_tx_cntrs { +u32 success; +u32 fail; +}; + +struct cl_tx_stats { +struct cl_tx_cntrs he[CHNL_BW_MAX ][WRS_SS_MAX ][WRS_MCS_MAX ][WRS_GI_MAX ][BF_IDX_MAX ]; +struct cl_tx_cntrs + vht[CHNL_BW_MAX_VHT ][WRS_SS_MAX ][WRS_MCS_MAX_VHT ][WRS_GI_MAX_VHT ][BF_IDX_MAX ]; +struct cl_tx_cntrs ht[CHNL_BW_MAX_HT ][WRS_SS_MAX ][WRS_MCS_MAX_HT ][WRS_GI_MAX_HT ]; +struct cl_tx_cntrs ofdm[WRS_MCS_MAX_OFDM ]; +struct cl_tx_cntrs cck[WRS_MCS_MAX_CCK ]; +u32 agg_cntr; +u32 fail_cntr; +u64 packet_success; +u64 packet_fail; +}; + +enum cl_ps_period { +PS_PERIOD_50MS , +PS_PERIOD_100MS , +PS_PERIOD_250MS , +PS_PERIOD_500MS , +PS_PERIOD_750MS , +PS_PERIOD_1000MS , +PS_PERIOD_2000MS , +PS_PERIOD_5000MS , +PS_PERIOD_10000MS , +PS_PERIOD_ABOVE , + +PS_PERIOD_MAX +}; + +struct cl_ps_stats { +bool is_ps; +unsigned long timestamp_sleep; +u32 period[PS_PERIOD_MAX ]; +}; + +enum cl_fec_coding { +CL_FEC_CODING_BCC , +CL_FEC_CODING_LDPC , +CL_FEC_CODING_MAX +}; + +struct cl_stats { +struct cl_tx_stats tx; +struct cl_rx_stats rx; +u32 rssi[RSSI_ARR_SIZE ][MAX_ANTENNAS ]; +u32 fec_coding[CL_FEC_CODING_MAX ]; +struct cl_ps_stats ps; +}; + +struct cl_vif ; + +void cl_stats_init (struct cl_hw *cl_hw); +void cl_stats_deinit (struct cl_hw *cl_hw); +void cl_stats_sta_add (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_stats_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_stats_update_tx_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report); +void cl_stats_update_tx_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report); +void cl_stats_update_rx_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta,s8 rssi[MAX_ANTENNAS ]); +void cl_stats_update_rx_rate (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct hw_rxhdr *rxhdr); +void cl_stats_update_rx_rate_production (struct cl_hw *cl_hw,struct hw_rxhdr *rxhdr); +void cl_stats_update_ps (struct cl_hw *cl_hw,struct cl_sta *cl_sta,bool is_ps); +void cl_stats_get_tx (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +u64 *total_success,u64 *total_fail); +u64 cl_stats_get_rx (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +int cl_stats_get_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta); + +#endif /* CL_STATS_H */
Signature · 1 line
2.36.1
RFC v2 78/96 cl8k: add tcv.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/tcv.c | 1259 ++++++++++++++++++++++++ 1 file changed, 1259 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/tcv.c
drivers/net/wireless/celeno/cl8k/tcv.c new file +1259 -0
@@ -0,0 +1,1259 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/slab.h> +#include <linux/moduleparam.h> +#include <linux/uaccess.h> + +#include "chip.h" +#include "recovery.h" +#include "vns.h" +#include "mac80211.h" +#include "config.h" +#include "rfic.h" +#include "e2p.h" +#include "hw.h" +#include "radio.h" +#include "utils.h" +#include "tcv.h" + +#define CL_TX_BCN_PENDING_CHAIN_MIN_TIME 10/* Usec */ +#define CL_MAX_NUM_OF_RETRY 15 +#define INVALID_CALIB_RX_GAIN 0xff + +static struct cl_tcv_conf conf = { + .ce_debug_level =DBG_LVL_ERROR , + .ce_radio_on = true, + .ce_ps_ctrl_enabled = true, + .ci_ieee80211h = false, + .ci_max_bss_num =ARRAY_SIZE (((struct cl_hw *)0 )->addresses), + .ci_short_guard_interval =1 , + .ci_max_mpdu_len =IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 , + .ci_max_ampdu_len_exp =IEEE80211_VHT_MAX_AMPDU_1024K , + .ce_dsp_code ="fwC.hex" , + .ce_dsp_data ="fwD.hex" , + .ce_dsp_external_data ="fwD.ext.hex" , + .ci_uapsd_en = true, + .ce_eirp_regulatory_op_en = true, + .ce_eirp_regulatory_prod_en = false, + .ci_agg_tx = true, + .ci_agg_rx = true, + .ce_txldpc_en = true, + .ci_ht_rxldpc_en = true, + .ci_vht_rxldpc_en = true, + .ci_he_rxldpc_en = true, + .ci_cs_required = false, + .ci_rx_sensitivity_prod = { + [0 ...MAX_ANTENNAS -1 ] =-100 , + }, + .ci_rx_sensitivity_op = { + [0 ...MAX_ANTENNAS -1 ] =-100 , + }, + .ci_min_he_en = false, + .ce_cck_tx_ant_mask =0x1 , + .ce_cck_rx_ant_mask =0x1 , + .ce_rx_nss =4 , + .ce_tx_nss =4 , + .ce_num_antennas =4 , + .ce_max_agg_size_tx =IEEE80211_MAX_AMPDU_BUF_HE , + .ce_max_agg_size_rx =IEEE80211_MAX_AMPDU_BUF_HE , + .ce_rxamsdu_en = true, + .ce_txamsdu_en =CL_AMSDU_TX_PAYLOAD_MAX , + .ci_tx_amsdu_min_data_rate =26 ,/* 26Mbps (= BW 20, NSS 0, MCS 3, GI 0) */ + .ci_tx_sw_amsdu_max_packets =0 , + .ci_tx_packet_limit =5000 , + .ci_sw_txhdr_pool =0 , + .ci_amsdu_txhdr_pool =0 , + .ci_tx_queue_size_agg =500 , + .ci_tx_queue_size_single =50 , + .ci_tx_push_cntrs_stat_en = false, + .ci_traffic_mon_en = false, + .ci_ipc_rxbuf_size = { + [CL_RX_BUF_RXM ] =IPC_RXBUF_SIZE , + [CL_RX_BUF_FW ] =IPC_RXBUF_SIZE + }, + .ce_max_retry =8 , + .ce_short_retry_limit =4 , + .ce_long_retry_limit =4 , + .ci_assoc_auth_retry_limit =0 , + .ci_cap_bandwidth =CHNL_BW_MAX , + .ci_chandef_channel =INVALID_CHAN_IDX , + .ci_chandef_bandwidth =CHNL_BW_MAX , + .ci_cck_in_hw_mode = true, + .ce_temp_comp_slope =8 , + .ci_fw_dbg_severity =CL_MACFW_DBG_SEV_WARNING , + .ci_fw_dbg_module =0x0FFFFF , + .ci_lcu_dbg_cfg_inx =4 , + .ci_dsp_lcu_mode =0 , + .ci_hal_idle_to =CL_DEFAULT_HAL_IDLE_TIMEOUT , + .ci_tx_ac0_to =CL_TX_DEFAULT_AC0_TIMEOUT , + .ci_tx_ac1_to =CL_TX_DEFAULT_AC1_TIMEOUT , + .ci_tx_ac2_to =CL_TX_DEFAULT_AC2_TIMEOUT , + .ci_tx_ac3_to =CL_TX_DEFAULT_AC3_TIMEOUT , + .ci_tx_bcn_to =CL_TX_DEFAULT_BCN_TIMEOUT , + .ce_hardware_power_table = {0 }, + .ce_arr_gain ="0,3,4.75,6,7,7.75" , + .ce_bf_gain_2_ant ="0" , + .ce_bf_gain_3_ant ="0" , + .ce_bf_gain_4_ant ="0" , + .ce_bf_gain_5_ant ="0" , + .ce_bf_gain_6_ant ="0" , + .ce_ant_gain ="0" , + .ce_ant_gain_36_64 ="0" , + .ce_ant_gain_100_140 ="0" , + .ce_ant_gain_149_165 ="0" , + .ci_min_ant_pwr ="0" , + .ci_bw_factor ="0,0,0,0" , + .ce_mcast_rate =0 , + .ce_dyn_mcast_rate_en = false, + .ce_dyn_bcast_rate_en = false, + .ce_default_mcs_ofdm =0 , + .ce_default_mcs_cck =0 , + .ce_prot_log_nav_en = false, + .ce_prot_mode =TXL_PROT_RTS_FW , + .ce_prot_rate_format =1 , + .ce_prot_rate_mcs =4 , + .ce_prot_rate_pre_type =0 , + .ce_bw_signaling_mode =0 , + .ci_dyn_cts_sta_thr =2 , + .ci_vns_pwr_limit =0 , + .ci_vns_pwr_mode =VNS_MODE_ALL , + .ci_vns_rssi_auto_resp_thr =-40 , + .ci_vns_rssi_thr =-40 , + .ci_vns_rssi_hys =3 , + .ci_vns_maintenance_time =2000 , + .ce_bcn_tx_path_min_time =1000 , + .ci_backup_bcn_en = true, + .ce_tx_txop_cut_en = true, + .ci_bcns_flushed_cnt_thr =3 , + .ci_phy_err_prevents_phy_dump = false, + .ci_tx_rx_delay =0 , + .ci_fw_assert_time_diff_sec =5 , + .ci_fw_assert_storm_detect_thd =10 , + .ce_hw_assert_time_max =CL_HW_ASSERT_TIME_MAX , + .ce_bg_assert_print =1 , + .ce_fw_watchdog_mode =FW_WD_INTERNAL_RECOVERY , + .ce_fw_watchdog_limit_count =5 , + .ce_fw_watchdog_limit_time =30 *1000 ,/* Msecs */ + .ci_rx_remote_cpu_drv =-1 , + .ci_rx_remote_cpu_mac =-1 , + .ci_pending_queue_size =500 , + .ce_tx_power_control =100 , + .ce_acs_coex_en = false, + .ci_dfs_initial_gain =77 , + .ci_dfs_agc_cd_th =48 , + .ci_dfs_long_pulse_min =100 , + .ci_dfs_long_pulse_max =5000 , + .ce_dfs_tbl_overwrite = {0 }, +/* 6G */ + .ce_ppmcs_offset_he_6g = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + [WRS_MCS_10 ] =0 , + [WRS_MCS_11 ] =0 , + }, +/* 5G */ + .ce_ppmcs_offset_he_36_64 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + [WRS_MCS_10 ] =0 , + [WRS_MCS_11 ] =0 , + }, + .ce_ppmcs_offset_he_100_140 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + [WRS_MCS_10 ] =0 , + [WRS_MCS_11 ] =0 , + }, + .ce_ppmcs_offset_he_149_165 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + [WRS_MCS_10 ] =0 , + [WRS_MCS_11 ] =0 , + }, + .ce_ppmcs_offset_ht_vht_36_64 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + }, + .ce_ppmcs_offset_ht_vht_100_140 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + }, + .ce_ppmcs_offset_ht_vht_149_165 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + }, + .ce_ppmcs_offset_ofdm_36_64 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + }, + .ce_ppmcs_offset_ofdm_100_140 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + }, + .ce_ppmcs_offset_ofdm_149_165 = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + }, +/* 24G */ + .ce_ppmcs_offset_he = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + [WRS_MCS_8 ] =0 , + [WRS_MCS_9 ] =0 , + [WRS_MCS_10 ] =0 , + [WRS_MCS_11 ] =0 , + }, + .ce_ppmcs_offset_ht = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + }, + .ce_ppmcs_offset_ofdm = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + [WRS_MCS_4 ] =0 , + [WRS_MCS_5 ] =0 , + [WRS_MCS_6 ] =0 , + [WRS_MCS_7 ] =0 , + }, + .ce_ppmcs_offset_cck = { + [WRS_MCS_0 ] =0 , + [WRS_MCS_1 ] =0 , + [WRS_MCS_2 ] =0 , + [WRS_MCS_3 ] =0 , + }, + .ce_ppbw_offset = { + [CHNL_BW_20 ] =0 , + [CHNL_BW_40 ] =0 , + [CHNL_BW_80 ] =0 , + [CHNL_BW_160 ] =0 , + }, + .ce_power_offset_prod_en = true, + .ci_bf_en = false, + .ci_bf_max_nss =2 , + .ce_sounding_interval_coefs = { + [SOUNDING_INTERVAL_COEF_MIN_INTERVAL ] =100 , + [SOUNDING_INTERVAL_COEF_STA_STEP ] =4 , + [SOUNDING_INTERVAL_COEF_INTERVAL_STEP ] =50 , + [SOUNDING_INTERVAL_COEF_MAX_INTERVAL ] =500 , + }, + .ci_rate_fallback = { + [CL_RATE_FALLBACK_COUNT_SU ] =4 , + [CL_RATE_FALLBACK_COUNT_MU ] =2 , + [CL_RATE_FALLBACK_RETRY_COUNT_THR ] =2 , + [CL_RATE_FALLBACK_BA_PER_THR ] =25 , + [CL_RATE_FALLBACK_BA_NOT_RECEIVED_THR ] =2 , + [CL_RATE_FALLBACK_DISABLE_MCS ] =1 + }, + .ce_rx_pkts_budget =512 , + .ci_band_num =5 , + .ci_mult_ampdu_in_txop_en = false, + .ce_wmm_aifsn = { + [AC_BK ] =3 , + [AC_BE ] =7 , + [AC_VI ] =1 , + [AC_VO ] =1 + }, + .ce_wmm_cwmin = { + [AC_BK ] =4 , + [AC_BE ] =4 , + [AC_VI ] =3 , + [AC_VO ] =2 + }, + .ce_wmm_cwmax = { + [AC_BK ] =10 , + [AC_BE ] =10 , + [AC_VI ] =4 , + [AC_VO ] =3 + }, + .ce_wmm_txop = { + [AC_BK ] =0 , + [AC_BE ] =0 , + [AC_VI ] =94 , + [AC_VO ] =47 + }, + .ci_su_force_min_spacing =CL_TX_MPDU_SPACING_INVALID , + .ci_mu_force_min_spacing =CL_TX_MPDU_SPACING_INVALID , + .ci_tf_mac_pad_dur =0 , + .ci_cca_timeout =300 , + .ce_tx_ba_session_timeout =30000 , + .ci_motion_sense_en = true, + .ci_motion_sense_rssi_thr =8 , + .ci_wrs_max_bw =CHNL_BW_160 , + .ci_wrs_min_bw =CHNL_BW_20 , + .ci_wrs_fixed_rate = { + [WRS_FIXED_PARAM_MODE ] =-1 , + [WRS_FIXED_PARAM_BW ] =-1 , + [WRS_FIXED_PARAM_NSS ] =-1 , + [WRS_FIXED_PARAM_MCS ] =-1 , + [WRS_FIXED_PARAM_GI ] =-1 + }, + .ce_he_mcs_nss_supp_tx = { + [WRS_SS_1 ...WRS_SS_4 ] =11 , + }, + .ce_he_mcs_nss_supp_rx = { + [WRS_SS_1 ...WRS_SS_4 ] =11 , + }, + .ce_vht_mcs_nss_supp_tx = { + [WRS_SS_1 ...WRS_SS_4 ] =9 , + }, + .ce_vht_mcs_nss_supp_rx = { + [WRS_SS_1 ...WRS_SS_4 ] =9 , + }, + .ci_pe_duration =U8_MAX , + .ci_pe_duration_bcast =PPE_16US , + .ci_gain_update_enable =1 , + .ci_mcs_sig_b =0 , + .ci_spp_ksr_value =1 , + .ci_rx_padding_en = false, + .ci_stats_en = false, + .ci_bar_disable = false, + .ci_ofdm_only = true, + .ci_hw_bsr = false, + .ci_drop_to_lower_bw = false, + .ci_force_icmp_single = false, + .ce_wrs_rx_en = false, + .ci_hr_factor = { + [CHNL_BW_20 ] =2 , + [CHNL_BW_40 ] =2 , + [CHNL_BW_80 ] =2 , + [CHNL_BW_160 ] =1 + }, + .ci_csd_en = true, + .ci_signal_extension_en = false, + .ci_vht_cap_24g = false, + .ci_tx_digital_gain =0x28282828 , + .ci_tx_digital_gain_cck =0x63636363 , + .ci_ofdm_cck_power_offset =-13 , + .ci_mac_clk_gating_en = true, + .ci_phy_clk_gating_en = true, + .ci_imaging_blocker = false, + .ci_sensing_ndp_tx_chain_mask =NDP_TX_PHY0 , + .ci_sensing_ndp_tx_bw =CHNL_BW_MAX , + .ci_sensing_ndp_tx_format =FORMATMOD_NON_HT , + .ci_sensing_ndp_tx_num_ltf =LTF_X1 , + .ci_calib_ant_tx = { + [0 ...MAX_ANTENNAS -1 ] =U8_MAX , + }, + .ci_calib_ant_rx = { + [0 ...MAX_ANTENNAS -1 ] =U8_MAX , + }, + .ci_cca_ed_rise_thr_dbm =-62 , + .ci_cca_ed_fall_thr_dbm =-65 , + .ci_cca_cs_en =1 , + .ci_cca_modem_en =0xf , + .ci_cca_main_ant =0 , + .ci_cca_second_ant =1 , + .ci_cca_flag0_ctrl =0x8 , + .ci_cca_flag1_ctrl =0x8 , + .ci_cca_flag2_ctrl =0x2 , + .ci_cca_flag3_ctrl =0xa , + .ci_cca_gi_rise_thr_dbm =-72 , + .ci_cca_gi_fall_thr_dbm =-75 , + .ci_cca_gi_pow_lim_dbm =-59 , + .ci_cca_ed_en =0x7ff , + .ci_cca_gi_en =0 , + .ci_rx_he_mu_ppdu = false, + .ci_fast_rx_en = true, + .ci_distance_auto_resp_all =0 , + .ci_distance_auto_resp_msta =0 , + .ci_fw_disable_recovery = false, + .ce_listener_en =0 , + .ci_tx_delay_tstamp_en = false, + .ci_calib_tx_init_tx_gain = { + [0 ...MAX_ANTENNAS -1 ] =CALIB_TX_GAIN_DEFAULT , + }, + .ci_calib_tx_init_rx_gain = { + [0 ...MAX_ANTENNAS -1 ] =INVALID_CALIB_RX_GAIN , + }, + .ci_calib_rx_init_tx_gain = { + [0 ...MAX_ANTENNAS -1 ] =CALIB_TX_GAIN_DEFAULT , + }, + .ci_calib_rx_init_rx_gain = { + [0 ...MAX_ANTENNAS -1 ] =INVALID_CALIB_RX_GAIN , + }, + .ci_calib_conf_rx_gain_upper_limit =INVALID_CALIB_RX_GAIN , + .ci_calib_conf_rx_gain_lower_limit =INVALID_CALIB_RX_GAIN , + .ci_calib_conf_tone_vector_20bw = {6 ,10 ,14 ,18 ,22 ,24 ,26 ,27 }, + .ci_calib_conf_tone_vector_40bw = {10 ,18 ,26 ,34 ,41 ,48 ,53 ,58 }, + .ci_calib_conf_tone_vector_80bw = {18 ,34 ,50 ,66 ,82 ,98 ,110 ,122 }, + .ci_calib_conf_tone_vector_160bw = {18 ,34 ,66 ,98 ,130 ,164 ,224 ,250 }, + .ci_calib_conf_gp_rad_trshld =GP_RAD_TRSHLD_DEFAULT , + .ci_calib_conf_ga_lin_upper_trshld =GA_LIN_UPPER_TRSHLD_DEFAULT , + .ci_calib_conf_ga_lin_lower_trshld =GA_LIN_LOWER_TRSHLD_DEFAULT , + .ci_calib_conf_singletons_num =SINGLETONS_NUM_DEFAULT , + .ci_calib_conf_rampup_time =RAMPUP_TIME , + .ci_calib_conf_lo_coarse_step =LO_COARSE_STEP , +#ifdef CONFIG_CL8K_EEPROM_STM24256 + .ci_calib_conf_lo_fine_step =LO_FINE_STEP , + .ci_calib_eeprom_channels_20mhz = {0 }, + .ci_calib_eeprom_channels_40mhz = {0 }, + .ci_calib_eeprom_channels_80mhz = {0 }, + .ci_calib_eeprom_channels_160mhz = {0 }, +#endif + .ci_mesh_basic_rates = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }, +}; + +static int cl_tcv_update_config (struct cl_hw *cl_hw,char *name,char *value) +{ +struct cl_tcv_conf *conf = cl_hw->conf; +int ret = -ENOENT ; + +do { +READ_S8 (ce_debug_level); +READ_BOOL (ce_radio_on); +READ_BOOL (ce_ps_ctrl_enabled); +READ_BOOL (ci_ieee80211h); +READ_U8 (ci_max_bss_num); +READ_U8 (ci_short_guard_interval); +READ_U8 (ci_max_mpdu_len); +READ_U8 (ci_max_ampdu_len_exp); +READ_STR (ce_dsp_code); +READ_STR (ce_dsp_data); +READ_STR (ce_dsp_external_data); +READ_BOOL (ci_uapsd_en); +READ_BOOL (ce_eirp_regulatory_op_en); +READ_BOOL (ce_eirp_regulatory_prod_en); +READ_BOOL (ci_agg_tx); +READ_BOOL (ci_agg_rx); +READ_BOOL (ce_txldpc_en); +READ_BOOL (ci_ht_rxldpc_en); +READ_BOOL (ci_vht_rxldpc_en); +READ_BOOL (ci_he_rxldpc_en); +READ_BOOL (ci_cs_required); +READ_S8_ARR (ci_rx_sensitivity_prod,MAX_ANTENNAS ); +READ_S8_ARR (ci_rx_sensitivity_op,MAX_ANTENNAS ); +READ_BOOL (ci_min_he_en); +READ_U8 (ce_cck_tx_ant_mask); +READ_U8 (ce_cck_rx_ant_mask); +READ_U8 (ce_rx_nss); +READ_U8 (ce_tx_nss); +READ_U8 (ce_num_antennas); +READ_U16 (ce_max_agg_size_tx); +READ_U16 (ce_max_agg_size_rx); +READ_BOOL (ce_rxamsdu_en); +READ_U8 (ce_txamsdu_en); +READ_U16 (ci_tx_amsdu_min_data_rate); +READ_U8 (ci_tx_sw_amsdu_max_packets); +READ_U16 (ci_tx_packet_limit); +READ_U16 (ci_sw_txhdr_pool); +READ_U16 (ci_amsdu_txhdr_pool); +READ_U16 (ci_tx_queue_size_agg); +READ_U16 (ci_tx_queue_size_single); +READ_BOOL (ci_tx_push_cntrs_stat_en); +READ_BOOL (ci_traffic_mon_en); +READ_U16_ARR (ci_ipc_rxbuf_size,CL_RX_BUF_MAX , true); +READ_U16 (ce_max_retry); +READ_U8 (ce_short_retry_limit); +READ_U8 (ce_long_retry_limit); +READ_U8 (ci_assoc_auth_retry_limit); +READ_U8 (ci_cap_bandwidth); +READ_U32 (ci_chandef_channel); +READ_U8 (ci_chandef_bandwidth); +READ_BOOL (ci_cck_in_hw_mode); +READ_S8 (ce_temp_comp_slope); +READ_U32 (ci_fw_dbg_severity); +READ_U32 (ci_fw_dbg_module); +READ_U8 (ci_lcu_dbg_cfg_inx); +READ_U8 (ci_dsp_lcu_mode); +READ_U32 (ci_hal_idle_to); +READ_U32 (ci_tx_ac0_to); +READ_U32 (ci_tx_ac1_to); +READ_U32 (ci_tx_ac2_to); +READ_U32 (ci_tx_ac3_to); +READ_U32 (ci_tx_bcn_to); +READ_STR (ce_hardware_power_table); +READ_STR (ce_arr_gain); +READ_STR (ce_bf_gain_2_ant); +READ_STR (ce_bf_gain_3_ant); +READ_STR (ce_bf_gain_4_ant); +READ_STR (ce_bf_gain_5_ant); +READ_STR (ce_bf_gain_6_ant); +READ_STR (ce_ant_gain); +READ_STR (ce_ant_gain_36_64); +READ_STR (ce_ant_gain_100_140); +READ_STR (ce_ant_gain_149_165); +READ_STR (ci_min_ant_pwr); +READ_STR (ci_bw_factor); +READ_U8 (ce_mcast_rate); +READ_BOOL (ce_dyn_mcast_rate_en); +READ_BOOL (ce_dyn_bcast_rate_en); +READ_U8 (ce_default_mcs_ofdm); +READ_U8 (ce_default_mcs_cck); +READ_BOOL (ce_prot_log_nav_en); +READ_U8 (ce_prot_mode); +READ_U8 (ce_prot_rate_format); +READ_U8 (ce_prot_rate_mcs); +READ_U8 (ce_prot_rate_pre_type); +READ_U8 (ce_bw_signaling_mode); +READ_U8 (ci_dyn_cts_sta_thr); +READ_S8 (ci_vns_pwr_limit); +READ_U8 (ci_vns_pwr_mode); +READ_S8 (ci_vns_rssi_auto_resp_thr); +READ_S8 (ci_vns_rssi_thr); +READ_S8 (ci_vns_rssi_hys); +READ_U16 (ci_vns_maintenance_time); +READ_U16 (ce_bcn_tx_path_min_time); +READ_BOOL (ci_backup_bcn_en); +READ_BOOL (ce_tx_txop_cut_en); +READ_U8 (ci_bcns_flushed_cnt_thr); +READ_BOOL (ci_phy_err_prevents_phy_dump); +READ_U8 (ci_tx_rx_delay); +READ_U8 (ci_fw_assert_time_diff_sec); +READ_U8 (ci_fw_assert_storm_detect_thd); +READ_U32 (ce_hw_assert_time_max); +READ_U8 (ce_bg_assert_print); +READ_U8 (ce_fw_watchdog_mode); +READ_U8 (ce_fw_watchdog_limit_count); +READ_U32 (ce_fw_watchdog_limit_time); +READ_S8 (ci_rx_remote_cpu_drv); +READ_S8 (ci_rx_remote_cpu_mac); +READ_U16 (ci_pending_queue_size); +READ_U8 (ce_tx_power_control); +READ_BOOL (ce_acs_coex_en); +READ_U8 (ci_dfs_initial_gain); +READ_U8 (ci_dfs_agc_cd_th); +READ_U16 (ci_dfs_long_pulse_min); +READ_U16 (ci_dfs_long_pulse_max); +READ_STR (ce_dfs_tbl_overwrite); +READ_S8_ARR (ce_ppmcs_offset_he_6g,WRS_MCS_MAX_HE ); +READ_S8_ARR (ce_ppmcs_offset_he_36_64,WRS_MCS_MAX_HE ); +READ_S8_ARR (ce_ppmcs_offset_he_100_140,WRS_MCS_MAX_HE ); +READ_S8_ARR (ce_ppmcs_offset_he_149_165,WRS_MCS_MAX_HE ); +READ_S8_ARR (ce_ppmcs_offset_ht_vht_36_64,WRS_MCS_MAX_VHT ); +READ_S8_ARR (ce_ppmcs_offset_ht_vht_100_140,WRS_MCS_MAX_VHT ); +READ_S8_ARR (ce_ppmcs_offset_ht_vht_149_165,WRS_MCS_MAX_VHT ); +READ_S8_ARR (ce_ppmcs_offset_ofdm_36_64,WRS_MCS_MAX_OFDM ); +READ_S8_ARR (ce_ppmcs_offset_ofdm_100_140,WRS_MCS_MAX_OFDM ); +READ_S8_ARR (ce_ppmcs_offset_ofdm_149_165,WRS_MCS_MAX_OFDM ); +READ_S8_ARR (ce_ppmcs_offset_he,WRS_MCS_MAX_HE ); +READ_S8_ARR (ce_ppmcs_offset_ht,WRS_MCS_MAX_HT ); +READ_S8_ARR (ce_ppmcs_offset_ofdm,WRS_MCS_MAX_OFDM ); +READ_S8_ARR (ce_ppmcs_offset_cck,WRS_MCS_MAX_CCK ); +READ_S8_ARR (ce_ppbw_offset,CHNL_BW_MAX ); +READ_BOOL (ce_power_offset_prod_en); +READ_BOOL (ci_bf_en); +READ_U8 (ci_bf_max_nss); +READ_U16_ARR (ce_sounding_interval_coefs,SOUNDING_INTERVAL_COEF_MAX , true); +READ_U8_ARR (ci_rate_fallback,CL_RATE_FALLBACK_MAX , true); +READ_U16 (ce_rx_pkts_budget); +READ_U8 (ci_band_num); +READ_BOOL (ci_mult_ampdu_in_txop_en); +READ_U8_ARR (ce_wmm_aifsn,AC_MAX , true); +READ_U8_ARR (ce_wmm_cwmin,AC_MAX , true); +READ_U8_ARR (ce_wmm_cwmax,AC_MAX , true); +READ_U16_ARR (ce_wmm_txop,AC_MAX , true); +READ_U8 (ci_su_force_min_spacing); +READ_U8 (ci_mu_force_min_spacing); +READ_U8 (ci_tf_mac_pad_dur); +READ_U32 (ci_cca_timeout); +READ_U16 (ce_tx_ba_session_timeout); +READ_BOOL (ci_motion_sense_en); +READ_S8 (ci_motion_sense_rssi_thr); +READ_U8 (ci_wrs_max_bw); +READ_U8 (ci_wrs_min_bw); +READ_S8_ARR (ci_wrs_fixed_rate,WRS_FIXED_PARAM_MAX ); +READ_U8_ARR (ce_he_mcs_nss_supp_tx,WRS_SS_MAX , true); +READ_U8_ARR (ce_he_mcs_nss_supp_rx,WRS_SS_MAX , true); +READ_U8_ARR (ce_vht_mcs_nss_supp_tx,WRS_SS_MAX , true); +READ_U8_ARR (ce_vht_mcs_nss_supp_rx,WRS_SS_MAX , true); +READ_U8 (ci_pe_duration); +READ_U8 (ci_pe_duration_bcast); +READ_U8 (ci_gain_update_enable); +READ_U8 (ci_mcs_sig_b); +READ_U8 (ci_spp_ksr_value); +READ_BOOL (ci_rx_padding_en); +READ_BOOL (ci_stats_en); +READ_BOOL (ci_bar_disable); +READ_BOOL (ci_ofdm_only); +READ_BOOL (ci_hw_bsr); +READ_BOOL (ci_drop_to_lower_bw); +READ_BOOL (ci_force_icmp_single); +READ_BOOL (ci_csd_en); +READ_BOOL (ce_wrs_rx_en); +READ_U8_ARR (ci_hr_factor,CHNL_BW_MAX , true); +READ_BOOL (ci_signal_extension_en); +READ_BOOL (ci_vht_cap_24g); +READ_U32 (ci_tx_digital_gain); +READ_U32 (ci_tx_digital_gain_cck); +READ_S8 (ci_ofdm_cck_power_offset); +READ_BOOL (ci_mac_clk_gating_en); +READ_BOOL (ci_phy_clk_gating_en); +READ_BOOL (ci_imaging_blocker); +READ_U8 (ci_sensing_ndp_tx_chain_mask); +READ_U8 (ci_sensing_ndp_tx_bw); +READ_U8 (ci_sensing_ndp_tx_format); +READ_U8 (ci_sensing_ndp_tx_num_ltf); +READ_U8_ARR (ci_calib_ant_tx,MAX_ANTENNAS , true); +READ_U8_ARR (ci_calib_ant_rx,MAX_ANTENNAS , true); +READ_S8 (ci_cca_ed_rise_thr_dbm); +READ_S8 (ci_cca_ed_fall_thr_dbm); +READ_U8 (ci_cca_cs_en); +READ_U8 (ci_cca_modem_en); +READ_U8 (ci_cca_main_ant); +READ_U8 (ci_cca_second_ant); +READ_U8 (ci_cca_flag0_ctrl); +READ_U8 (ci_cca_flag1_ctrl); +READ_U8 (ci_cca_flag2_ctrl); +READ_U8 (ci_cca_flag3_ctrl); +READ_S8 (ci_cca_gi_rise_thr_dbm); +READ_S8 (ci_cca_gi_fall_thr_dbm); +READ_S8 (ci_cca_gi_pow_lim_dbm); +READ_U16 (ci_cca_ed_en); +READ_U8 (ci_cca_gi_en); +READ_BOOL (ci_rx_he_mu_ppdu); +READ_BOOL (ci_fast_rx_en); +READ_U8 (ci_distance_auto_resp_all); +READ_U8 (ci_distance_auto_resp_msta); +READ_BOOL (ci_fw_disable_recovery); +READ_BOOL (ce_listener_en); +READ_BOOL (ci_tx_delay_tstamp_en); +READ_U8_ARR (ci_calib_tx_init_tx_gain,MAX_ANTENNAS , true); +READ_U8_ARR (ci_calib_tx_init_rx_gain,MAX_ANTENNAS , true); +READ_U8_ARR (ci_calib_rx_init_tx_gain,MAX_ANTENNAS , true); +READ_U8_ARR (ci_calib_rx_init_rx_gain,MAX_ANTENNAS , true); +READ_U8 (ci_calib_conf_rx_gain_upper_limit); +READ_U8 (ci_calib_conf_rx_gain_lower_limit); +READ_U8_ARR (ci_calib_conf_tone_vector_20bw,IQ_NUM_TONES_REQ , true); +READ_U8_ARR (ci_calib_conf_tone_vector_40bw,IQ_NUM_TONES_REQ , true); +READ_U8_ARR (ci_calib_conf_tone_vector_80bw,IQ_NUM_TONES_REQ , true); +READ_U8_ARR (ci_calib_conf_tone_vector_160bw,IQ_NUM_TONES_REQ , true); +READ_U32 (ci_calib_conf_gp_rad_trshld); +READ_U32 (ci_calib_conf_ga_lin_upper_trshld); +READ_U32 (ci_calib_conf_ga_lin_lower_trshld); +READ_U8 (ci_calib_conf_singletons_num); +READ_U16 (ci_calib_conf_rampup_time); +READ_U16 (ci_calib_conf_lo_coarse_step); +READ_U16 (ci_calib_conf_lo_fine_step); + +#ifdef CONFIG_CL8K_EEPROM_STM24256 +if (cl_hw_is_tcv0 (cl_hw)) { +READ_U16_ARR (ci_calib_eeprom_channels_20mhz, +EEPROM_CALIB_DATA_ELEM_NUM_20MHZ_TCV0 , false); +READ_U16_ARR (ci_calib_eeprom_channels_40mhz, +EEPROM_CALIB_DATA_ELEM_NUM_40MHZ_TCV0 , false); +READ_U16_ARR (ci_calib_eeprom_channels_80mhz, +EEPROM_CALIB_DATA_ELEM_NUM_80MHZ_TCV0 , false); +READ_U16_ARR (ci_calib_eeprom_channels_160mhz, +EEPROM_CALIB_DATA_ELEM_NUM_160MHZ_TCV0 , false); + } +if (cl_hw_is_tcv1 (cl_hw)) { +READ_U16_ARR (ci_calib_eeprom_channels_20mhz, +EEPROM_CALIB_DATA_ELEM_NUM_20MHZ_TCV1 , false); +READ_U16_ARR (ci_calib_eeprom_channels_40mhz, +EEPROM_CALIB_DATA_ELEM_NUM_40MHZ_TCV1 , false); +READ_U16_ARR (ci_calib_eeprom_channels_80mhz, +EEPROM_CALIB_DATA_ELEM_NUM_80MHZ_TCV1 , false); +READ_U16_ARR (ci_calib_eeprom_channels_160mhz, +EEPROM_CALIB_DATA_ELEM_NUM_160MHZ_TCV1 , false); + } +#endif +READ_U16_ARR (ci_mesh_basic_rates,MESH_BASIC_RATE_MAX , false); + }while (0 ); + +if (ret == -ENOENT ) { +if (cl_config_is_non_driver_param (name)) + ret =0 ; +else +CL_DBG_ERROR (cl_hw,"No matching conf for nvram parameter %s\n" , name); + } + +return ret; +} + +static int cl_tcv_set_all_params_from_buf (struct cl_hw *cl_hw,char *buf,size_t size) +{ +char *line = buf; +char name[MAX_PARAM_NAME_LENGTH ]; +char value[STR_LEN_256B ]; +char *begin; +char *end; +int ret =0 ; +int name_length =0 ; +int value_length =0 ; + +while (line &&strlen (line) && (line != (buf + size))) { +if ((*line =='#' ) || (*line =='\n' )) { +/* Skip comment or blank line */ + line =strstr (line,"\n" ) +1 ; + }else if (*line) { + begin = line; + end =strstr (begin,"=" ); + +if (!end) { + ret = -EBADMSG ; + goto exit; + } + + end++; + name_length = end - begin; + value_length =strstr (end,"\n" ) - end +1 ; + +if (name_length >=MAX_PARAM_NAME_LENGTH ) { +cl_dbg_err (cl_hw, +"Name too long (%u)\n" , name_length); + ret = -EBADMSG ; + goto exit; + } +if (value_length >=STR_LEN_256B ) { +cl_dbg_err (cl_hw, +"Value too long (%u)\n" , value_length); + ret = -EBADMSG ; + goto exit; + } + +snprintf (name, name_length,"%s" , begin); +snprintf (value, value_length,"%s" , end); + + ret =cl_tcv_update_config (cl_hw, name, value); +if (ret) + goto exit; + + line =strstr (line,"\n" ) +1 ; + } + } + +exit: + +return ret; +} + +static bool cl_tcv_is_valid_min_spacing (u8 min_spacing) +{ +return ((min_spacing ==0 ) || + (min_spacing ==1 ) || + (min_spacing ==2 ) || + (min_spacing ==3 ) || + (min_spacing ==4 ) || + (min_spacing ==6 ) || + (min_spacing ==8 ) || + (min_spacing ==10 ) || + (min_spacing ==12 ) || + (min_spacing ==14 ) || + (min_spacing ==16 ) || + (min_spacing ==18 ) || + (min_spacing ==20 ) || + (min_spacing ==24 ) || + (min_spacing ==CL_TX_MPDU_SPACING_INVALID )); +} + +static bool cl_tcv_is_valid_cca_config (struct cl_hw *cl_hw,struct cl_tcv_conf *conf) +{ +if (conf->ci_cca_ed_rise_thr_dbm <= conf->ci_cca_ed_fall_thr_dbm) { +CL_DBG_ERROR (cl_hw,"cca_ed_rise_thr_dbm (%u) <= cca_ed_fall_thr_dbm (%u)\n" , + conf->ci_cca_ed_rise_thr_dbm, conf->ci_cca_ed_fall_thr_dbm); +return false; + } + +if (conf->ci_cca_gi_rise_thr_dbm <= conf->ci_cca_gi_fall_thr_dbm) { +CL_DBG_ERROR (cl_hw,"cca_gi_rise_thr_dbm (%u) <= cca_gi_fall_thr_dbm (%u)\n" , + conf->ci_cca_gi_rise_thr_dbm, conf->ci_cca_gi_fall_thr_dbm); +return false; + } + +if (conf->ci_cca_gi_pow_lim_dbm <= conf->ci_cca_ed_rise_thr_dbm) { +CL_DBG_ERROR (cl_hw,"cca_gi_pow_lim_dbm (%u) <= cca_ed_rise_thr_dbm (%u)\n" , + conf->ci_cca_gi_pow_lim_dbm, conf->ci_cca_ed_rise_thr_dbm); +return false; + } + +return true; +} + +static inline void cl_tcv_set_default_channel (u32 *channel,u32 value) +{ +if (*channel ==INVALID_CHAN_IDX ) + *channel = value; +} + +static inline void cl_tcv_set_default_bandwidth (u8 *bw,u8 value) +{ +if (*bw ==CHNL_BW_MAX ) + *bw = value; +} + +static inline bool cl_tcv_is_valid_bandwidth (u8 *bw,u8 max_value) +{ +return *bw <= max_value; +} + +static bool cl_tcv_is_valid_channeling_context (struct cl_hw *cl_hw) +{ +struct cl_tcv_conf *conf = cl_hw->conf; +u32 dflt_channel =1 ; +u8 bw_limit =CHNL_BW_20 ; +char *band_str ="?" ; + +if (cl_band_is_24g (cl_hw)) { + dflt_channel =1 ; + bw_limit =CHNL_BW_40 ; + band_str ="24g" ; + }else if (cl_band_is_5g (cl_hw)) { + dflt_channel =36 ; + bw_limit =CHNL_BW_160 ; + band_str ="5g" ; + }else { + dflt_channel =1 ; + bw_limit =CHNL_BW_160 ; + band_str ="6g" ; + } + +cl_tcv_set_default_channel (&conf->ci_chandef_channel, dflt_channel); +cl_tcv_set_default_bandwidth (&conf->ci_chandef_bandwidth, bw_limit); +cl_tcv_set_default_bandwidth (&conf->ci_cap_bandwidth, bw_limit); + +/* Forcibly change BW limit for production mode in 24g */ +if (cl_band_is_24g (cl_hw) && cl_hw->chip->conf->ce_production_mode) + bw_limit =CHNL_BW_160 ; + +if (!cl_tcv_is_valid_bandwidth (&conf->ci_cap_bandwidth, bw_limit)) { +CL_DBG_ERROR (cl_hw,"Invalid channel bandwidth (%u) for %s\n" , + conf->ci_cap_bandwidth, band_str); +return false; + } + +return true; +} + +static int cl_tcv_post_configuration (struct cl_hw *cl_hw,const char *buf) +{ +struct cl_tcv_conf *conf = cl_hw->conf; +struct cl_chip *chip = cl_hw->chip; + +if (conf->ci_max_bss_num >ARRAY_SIZE (cl_hw->addresses)) { +CL_DBG_ERROR (cl_hw,"Invalid ci_max_bss_num (%u)\n" , + conf->ci_max_bss_num); +return -EINVAL ; + } + +/* Production mode */ +if (chip->conf->ce_production_mode) { +memcpy (cl_hw->rx_sensitivity, conf->ci_rx_sensitivity_prod,MAX_ANTENNAS ); + conf->ce_prot_mode =0 ; +/* Production is done in station mode */ +cl_hw_set_iface_conf (cl_hw,CL_IFCONF_STA ); + + }else { +if (chip->conf->ci_phy_dev ==PHY_DEV_LOOPBACK ) { +s8 rx_sens_loopback[MAX_ANTENNAS ] = {-96 ,-96 ,-96 ,-96 ,-96 ,-96 }; + +memcpy (cl_hw->rx_sensitivity, rx_sens_loopback,MAX_ANTENNAS ); + }else { +memcpy (cl_hw->rx_sensitivity, conf->ci_rx_sensitivity_op,MAX_ANTENNAS ); + } + } + +if (cl_hw_set_antennas (cl_hw)) { +CL_DBG_ERROR (cl_hw,"hw set antennas failed!\n" ); +return -EINVAL ; + } + +if (!cl_tcv_is_valid_cca_config (cl_hw, conf)) +return -EINVAL ; + +if (conf->ce_num_antennas) { +/* Validate: ce_num_antennas, ce_rx_nss, ce_tx_nss */ +if (conf->ce_num_antennas <MIN_ANTENNAS || + conf->ce_num_antennas >MAX_ANTENNAS ) { +CL_DBG_ERROR (cl_hw,"Invalid ce_num_antennas (%u)\n" , + conf->ce_num_antennas); +return -EINVAL ; + } + +if (conf->ce_rx_nss <1 || + conf->ce_rx_nss >WRS_SS_MAX || + conf->ce_rx_nss > conf->ce_num_antennas) { +CL_DBG_ERROR (cl_hw,"Invalid ce_rx_nss (%u)\n" , conf->ce_rx_nss); +return -EINVAL ; + } + +if (conf->ce_tx_nss <1 || + conf->ce_tx_nss >WRS_SS_MAX || + conf->ce_tx_nss > conf->ce_num_antennas) { +CL_DBG_ERROR (cl_hw,"Invalid ce_tx_nss (%u)\n" , conf->ce_tx_nss); +return -EINVAL ; + } + +/* Validate: ce_cck_tx_ant_mask and ce_cck_rx_ant_mask */ +if (cl_band_is_24g (cl_hw)) { +u8 ant_shift =cl_hw_ant_shift (cl_hw); +u8 ant_bitmap = (((1 << conf->ce_num_antennas) -1 ) << ant_shift); +u8 num_cck_ant_tx =hweight8 (conf->ce_cck_tx_ant_mask); +u8 num_cck_ant_rx =hweight8 (conf->ce_cck_rx_ant_mask); + +if ((ant_bitmap & conf->ce_cck_tx_ant_mask) != conf->ce_cck_tx_ant_mask) { +CL_DBG_ERROR (cl_hw,"Invalid ce_cck_tx_ant_mask (0x%x), " +"does not match ce_num_antennas mask (0x%x)\n" , + conf->ce_cck_tx_ant_mask, ant_bitmap); +return -EINVAL ; + } + +if ((ant_bitmap & conf->ce_cck_rx_ant_mask) != conf->ce_cck_rx_ant_mask) { +CL_DBG_ERROR (cl_hw,"Invalid ce_cck_rx_ant_mask (0x%x), " +"does not match ce_num_antennas mask (0x%x)\n" , + conf->ce_cck_rx_ant_mask, ant_bitmap); +return -EINVAL ; + } + +if (conf->ce_cck_tx_ant_mask ==0 ) { +CL_DBG_ERROR (cl_hw,"Invalid ce_cck_tx_ant_mask, can't be 0x0\n" ); +return -EINVAL ; + } + +if (conf->ce_cck_rx_ant_mask ==0 ) { +CL_DBG_ERROR (cl_hw,"Invalid ce_cck_rx_ant_mask, can't be 0x0\n" ); +return -EINVAL ; + } + +if (num_cck_ant_tx >MAX_ANTENNAS_CCK ) { +CL_DBG_ERROR (cl_hw,"Invalid ce_cck_tx_ant_mask (0x%x), " +"number of set bits exceeds %u\n" , + num_cck_ant_tx,MAX_ANTENNAS_CCK ); +return -EINVAL ; + } + +if (num_cck_ant_rx >MAX_ANTENNAS_CCK ) { +CL_DBG_ERROR (cl_hw,"Invalid ce_cck_rx_ant_mask (0x%x), " +"number of set bits exceeds %u\n" , + num_cck_ant_rx,MAX_ANTENNAS_CCK ); +return -EINVAL ; + } + } + } + +if (conf->ce_prot_mode ==TXL_PROT_RTS ) { +CL_DBG_ERROR (cl_hw,"ce_prot_mode %u is not supported\n" ,TXL_PROT_RTS ); +return -EINVAL ; + } + +if (!cl_tcv_is_valid_channeling_context (cl_hw)) +return -EINVAL ; + +if (cl_band_is_5g (cl_hw)) { +if (!conf->ci_ofdm_only) { +CL_DBG_ERROR (cl_hw,"ci_ofdm_only must be set to 1 for 5g band\n" ); +return -EINVAL ; + } + } + +/* Validate ce_bcn_tx_path_min_time */ +if (conf->ce_bcn_tx_path_min_time <=CL_TX_BCN_PENDING_CHAIN_MIN_TIME ) { +CL_DBG_ERROR (cl_hw,"Invalid ce_bcn_tx_path_min_time (%u)\n" , + conf->ce_bcn_tx_path_min_time); +return -EINVAL ; + } + +if (conf->ci_tx_sw_amsdu_max_packets >MAX_TX_SW_AMSDU_PACKET ) { +cl_dbg_err (cl_hw,"ERROR: Invalid ci_tx_sw_amsdu_max_packets (%u), set default (%u)\n" , + conf->ci_tx_sw_amsdu_max_packets,MAX_TX_SW_AMSDU_PACKET ); + + conf->ci_tx_sw_amsdu_max_packets =MAX_TX_SW_AMSDU_PACKET ; + } + +if (conf->ce_tx_power_control >100 || conf->ce_tx_power_control <1 ) { +cl_dbg_err (cl_hw,"ERROR: Invalid ce_tx_power_control (%u), set default 100\n" , + conf->ce_tx_power_control); + + conf->ce_tx_power_control =100 ; + } + +if (conf->ce_max_retry >CL_MAX_NUM_OF_RETRY ) { +cl_dbg_err (cl_hw,"ERROR: Invalid ce_max_retry (%u), set default to maximum (%u)\n" , + conf->ce_max_retry,CL_MAX_NUM_OF_RETRY ); + + conf->ce_max_retry =CL_MAX_NUM_OF_RETRY ; + } + +if (!cl_tcv_is_valid_min_spacing (conf->ci_su_force_min_spacing)) { +cl_dbg_err (cl_hw,"ERROR: Invalid ci_su_force_min_spacing (%u), must be 0/1/2/3/4/6/8/10/12/14/16/18/20/24, set default %u\n" , + conf->ci_su_force_min_spacing,CL_TX_MPDU_SPACING_INVALID ); + + conf->ci_su_force_min_spacing =CL_TX_MPDU_SPACING_INVALID ; + } + +if (!cl_tcv_is_valid_min_spacing (conf->ci_mu_force_min_spacing)) { +cl_dbg_err (cl_hw,"ERROR: Invalid ci_mu_force_min_spacing (%u), must be 0/1/2/3/4/6/8/10/12/14/16/18/20/24, set default %u\n" , + conf->ci_mu_force_min_spacing,CL_TX_MPDU_SPACING_INVALID ); + + conf->ci_mu_force_min_spacing =CL_TX_MPDU_SPACING_INVALID ; + } + +if (conf->ci_max_mpdu_len !=IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 && + conf->ci_max_mpdu_len !=IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 && + conf->ci_max_mpdu_len !=IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 ) { +cl_dbg_err (cl_hw,"ERROR: Invalid 'ci_max_mpdu_len' (%u). Must be 0/1/2. Setting to 0\n" , + conf->ci_max_mpdu_len); + + conf->ci_max_mpdu_len =IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 ; + } + +if (cl_hw_is_tcv1 (cl_hw) &&cl_chip_is_both_enabled (chip)) { +/* Check that sum of ce_num_antennas in both TCV's is smaller than max_antennas */ +struct cl_hw *cl_hw_tcv0 = chip->cl_hw_tcv0; +u8 num_ant_tcv0 = cl_hw_tcv0->conf->ce_num_antennas; +u8 num_ant_tcv1 = conf->ce_num_antennas; +u8 total_ant = num_ant_tcv0 + num_ant_tcv1; + +if (total_ant > chip->max_antennas) { +CL_DBG_ERROR (cl_hw, +"Invalid ce_num_antennas tcv0=%u, tcv1=%u, total=%u, max=%u\n" , + num_ant_tcv0, num_ant_tcv1, total_ant, chip->max_antennas); +return -1 ; + } + } + +if (cl_hw_is_prod_or_listener (cl_hw) && !conf->ce_power_offset_prod_en) { +cl_dbg_err (cl_hw,"Disable PPMCS/PPBW in production mode\n" ); + +if (cl_band_is_6g (cl_hw)) { +memset (conf->ce_ppmcs_offset_he_6g,0 , +sizeof (conf->ce_ppmcs_offset_he_6g)); + }else if (cl_band_is_5g (cl_hw)) { +memset (conf->ce_ppmcs_offset_he_36_64,0 , +sizeof (conf->ce_ppmcs_offset_he_36_64)); +memset (conf->ce_ppmcs_offset_he_100_140,0 , +sizeof (conf->ce_ppmcs_offset_he_100_140)); +memset (conf->ce_ppmcs_offset_he_149_165,0 , +sizeof (conf->ce_ppmcs_offset_he_149_165)); +memset (conf->ce_ppmcs_offset_ht_vht_36_64,0 , +sizeof (conf->ce_ppmcs_offset_ht_vht_36_64)); +memset (conf->ce_ppmcs_offset_ht_vht_100_140,0 , +sizeof (conf->ce_ppmcs_offset_ht_vht_100_140)); +memset (conf->ce_ppmcs_offset_ht_vht_149_165,0 , +sizeof (conf->ce_ppmcs_offset_ht_vht_149_165)); +memset (conf->ce_ppmcs_offset_ofdm_36_64,0 , +sizeof (conf->ce_ppmcs_offset_ofdm_36_64)); +memset (conf->ce_ppmcs_offset_ofdm_100_140,0 , +sizeof (conf->ce_ppmcs_offset_ofdm_100_140)); +memset (conf->ce_ppmcs_offset_ofdm_149_165,0 , +sizeof (conf->ce_ppmcs_offset_ofdm_149_165)); + }else { +memset (conf->ce_ppmcs_offset_he,0 ,sizeof (conf->ce_ppmcs_offset_he)); +memset (conf->ce_ppmcs_offset_ht,0 ,sizeof (conf->ce_ppmcs_offset_ht)); +memset (conf->ce_ppmcs_offset_ofdm,0 ,sizeof (conf->ce_ppmcs_offset_ofdm)); +memset (conf->ce_ppmcs_offset_cck,0 ,sizeof (conf->ce_ppmcs_offset_cck)); + } + +memset (conf->ce_ppbw_offset,0 ,sizeof (conf->ce_ppbw_offset)); + } + +if (!cl_band_is_24g (cl_hw) && cl_hw->conf->ci_signal_extension_en) { +cl_dbg_err (cl_hw,"ERROR: Invalid 'ci_signal_extension_en' (%u). Must be 0 for non 2.4Ghz band. Setting to 0\n" , + conf->ce_dyn_mcast_rate_en); + + conf->ci_signal_extension_en = false; + } + +if (conf->ce_dyn_mcast_rate_en &&cl_band_is_6g (cl_hw)) { +cl_dbg_err (cl_hw,"ERROR: Invalid 'ce_dyn_mcast_rate_en' (%u). Must be 0 on 6Ghz band. Setting to 0\n" , + conf->ce_dyn_mcast_rate_en); + + conf->ce_dyn_mcast_rate_en =0 ; + } + +if (conf->ce_dyn_bcast_rate_en &&cl_band_is_6g (cl_hw)) { +cl_dbg_err (cl_hw,"ERROR: Invalid 'ce_dyn_bcast_rate_en' (%u). Must be 0 on 6Ghz band. Setting to 0\n" , + conf->ce_dyn_bcast_rate_en); + + conf->ce_dyn_bcast_rate_en =0 ; + } + +return 0 ; +} + +int cl_tcv_config_read (struct cl_hw *cl_hw) +{ +struct cl_chip *chip = cl_hw->chip; +char *buf =NULL ; +size_t size =0 ; +int ret =0 ; +char filename[CL_FILENAME_MAX ] = {0 }; +u8 tcv_idx = cl_hw->idx; + +snprintf (filename,sizeof (filename),"cl_tcv%u.dat" , tcv_idx); +pr_debug ("%s: %s\n" , __func__, filename); + size =cl_file_open_and_read (chip, filename, &buf); + +if (!buf) { +pr_err ("read %s failed !!!\n" , filename); +return -ENODATA ; + } + + ret =cl_tcv_set_all_params_from_buf (cl_hw, buf, size); +if (ret) { +kfree (buf); +return ret; + } + + ret =cl_tcv_post_configuration (cl_hw,NULL ); +if (ret) { +kfree (buf); +return ret; + } + +kfree (buf); + +return ret; +} + +int cl_tcv_config_alloc (struct cl_hw *cl_hw) +{ + cl_hw->conf =kzalloc (sizeof (*cl_hw->conf),GFP_KERNEL ); + +if (!cl_hw->conf) +return -ENOMEM ; + +/* Copy default values */ +memcpy (cl_hw->conf, &conf,sizeof (struct cl_tcv_conf )); + +return 0 ; +} + +void cl_tcv_config_free (struct cl_hw *cl_hw) +{ +kfree (cl_hw->conf); + cl_hw->conf =NULL ; +} + +void cl_tcv_config_validate_calib_params (struct cl_hw *cl_hw) +{ +struct cl_tcv_conf *conf = cl_hw->conf; +u8 chain =0 ; + +if (cl_hw->chip->conf->ci_phy_dev ==PHY_DEV_ATHOS ) { +if (cl_hw->chip->rfic_version ==ATHOS_B_VER ) { +for (chain =0 ; chain <MAX_ANTENNAS ; chain++) { +if (conf->ci_calib_tx_init_rx_gain[chain] ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_tx_init_rx_gain[chain] = +CALIB_RX_GAIN_DEFAULT_ATHOS_B ; +if (conf->ci_calib_rx_init_rx_gain[chain] ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_rx_init_rx_gain[chain] = +CALIB_RX_GAIN_DEFAULT_ATHOS_B ; + } + +if (conf->ci_calib_conf_rx_gain_upper_limit ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_conf_rx_gain_upper_limit = +CALIB_RX_GAIN_UPPER_LIMIT_ATHOS_B ; +if (conf->ci_calib_conf_rx_gain_lower_limit ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_conf_rx_gain_lower_limit = +CALIB_RX_GAIN_LOWER_LIMIT_ATHOS_B ; + }else { +for (chain =0 ; chain <MAX_ANTENNAS ; chain++) { +if (conf->ci_calib_tx_init_rx_gain[chain] ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_tx_init_rx_gain[chain] = +CALIB_RX_GAIN_DEFAULT_ATHOS ; +if (conf->ci_calib_rx_init_rx_gain[chain] ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_rx_init_rx_gain[chain] = +CALIB_RX_GAIN_DEFAULT_ATHOS ; + } + +if (conf->ci_calib_conf_rx_gain_upper_limit ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_conf_rx_gain_upper_limit = +CALIB_RX_GAIN_UPPER_LIMIT_ATHOS ; +if (conf->ci_calib_conf_rx_gain_lower_limit ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_conf_rx_gain_lower_limit = +CALIB_RX_GAIN_LOWER_LIMIT_ATHOS ; + } + }else { +for (chain =0 ; chain <MAX_ANTENNAS ; chain++) { +if (conf->ci_calib_tx_init_rx_gain[chain] ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_tx_init_rx_gain[chain] =CALIB_RX_GAIN_DEFAULT ; + +if (conf->ci_calib_rx_init_rx_gain[chain] ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_rx_init_rx_gain[chain] =CALIB_RX_GAIN_DEFAULT ; + } + +if (conf->ci_calib_conf_rx_gain_upper_limit ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_conf_rx_gain_upper_limit =CALIB_RX_GAIN_UPPER_LIMIT ; +if (conf->ci_calib_conf_rx_gain_lower_limit ==INVALID_CALIB_RX_GAIN ) + conf->ci_calib_conf_rx_gain_lower_limit =CALIB_RX_GAIN_LOWER_LIMIT ; + } +}
Signature · 1 line
2.36.1
RFC v2 79/96 cl8k: add tcv.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/tcv.h | 283 +++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/tcv.h
drivers/net/wireless/celeno/cl8k/tcv.h new file +283 -0
@@ -0,0 +1,283 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_TCV_CONFIG_H +#define CL_TCV_CONFIG_H + +#include "def.h" +#include "ipc_shared.h" +#include "radio.h" +#include "sounding.h" +#include "eeprom.h" + +/** +* TCV (=Tranceiver) configuration, is related to the specific band on top +* of specific chipset. +*/ +#define CL_DEFAULT_HAL_IDLE_TIMEOUT 16000/* Idle request - 16ms */ +#define CL_TX_DEFAULT_AC0_TIMEOUT 500000/* Background - 500ms */ +#define CL_TX_DEFAULT_AC1_TIMEOUT 300000/* Best effort - 300ms */ +#define CL_TX_DEFAULT_AC2_TIMEOUT 200000/* Video - 200ms */ +#define CL_TX_DEFAULT_AC3_TIMEOUT 200000/* Voice - 200ms */ +#define CL_TX_DEFAULT_BCN_TIMEOUT 150000/* Beacon - 150ms */ + +/* Minimal MPDU spacing we support in TX - correspond to FW NX_TX_MPDU_SPACING */ +#define CL_TX_MPDU_SPACING_INVALID 0xFF + +enum { +CL_RATE_FALLBACK_COUNT_SU , +CL_RATE_FALLBACK_COUNT_MU , +CL_RATE_FALLBACK_RETRY_COUNT_THR , +CL_RATE_FALLBACK_BA_PER_THR , +CL_RATE_FALLBACK_BA_NOT_RECEIVED_THR , +CL_RATE_FALLBACK_DISABLE_MCS , + +CL_RATE_FALLBACK_MAX , +}; + +struct cl_tcv_conf { +s8 ce_debug_level; +bool ce_radio_on; +bool ce_ps_ctrl_enabled; +bool ci_ieee80211h; +u8 ci_max_bss_num; +u8 ci_short_guard_interval; +u8 ci_max_mpdu_len; +u8 ci_max_ampdu_len_exp; +s8 ce_dsp_code[STR_LEN_32B ]; +s8 ce_dsp_data[STR_LEN_32B ]; +s8 ce_dsp_external_data[STR_LEN_32B ]; +bool ci_uapsd_en; +bool ce_eirp_regulatory_op_en; +bool ce_eirp_regulatory_prod_en; +bool ci_agg_tx; +bool ci_agg_rx; +bool ce_txldpc_en; +bool ci_ht_rxldpc_en; +bool ci_vht_rxldpc_en; +bool ci_he_rxldpc_en; +bool ci_cs_required; +s8 ci_rx_sensitivity_prod[MAX_ANTENNAS ]; +s8 ci_rx_sensitivity_op[MAX_ANTENNAS ]; +bool ci_min_he_en; +u8 ce_cck_tx_ant_mask; +u8 ce_cck_rx_ant_mask; +u8 ce_rx_nss; +u8 ce_tx_nss; +u8 ce_num_antennas; +u16 ce_max_agg_size_tx; +u16 ce_max_agg_size_rx; +bool ce_rxamsdu_en; +u8 ce_txamsdu_en; +u16 ci_tx_amsdu_min_data_rate; +u8 ci_tx_sw_amsdu_max_packets; +u16 ci_tx_packet_limit; +u16 ci_sw_txhdr_pool; +u16 ci_amsdu_txhdr_pool; +u16 ci_tx_queue_size_agg; +u16 ci_tx_queue_size_single; +bool ci_tx_push_cntrs_stat_en; +bool ci_traffic_mon_en; +u16 ci_ipc_rxbuf_size[CL_RX_BUF_MAX ]; +u16 ce_max_retry; +u8 ce_short_retry_limit; +u8 ce_long_retry_limit; +u8 ci_assoc_auth_retry_limit; +u8 ci_cap_bandwidth; +u32 ci_chandef_channel; +u8 ci_chandef_bandwidth; +bool ci_cck_in_hw_mode; +s8 ce_temp_comp_slope; +u32 ci_fw_dbg_severity; +u32 ci_fw_dbg_module; +u8 ci_lcu_dbg_cfg_inx; +u8 ci_dsp_lcu_mode; +u32 ci_hal_idle_to; +u32 ci_tx_ac0_to; +u32 ci_tx_ac1_to; +u32 ci_tx_ac2_to; +u32 ci_tx_ac3_to; +u32 ci_tx_bcn_to; +s8 ce_hardware_power_table[STR_LEN_256B ]; +s8 ce_arr_gain[STR_LEN_32B ]; +s8 ce_bf_gain_2_ant[STR_LEN_32B ]; +s8 ce_bf_gain_3_ant[STR_LEN_32B ]; +s8 ce_bf_gain_4_ant[STR_LEN_32B ]; +s8 ce_bf_gain_5_ant[STR_LEN_32B ]; +s8 ce_bf_gain_6_ant[STR_LEN_32B ]; +s8 ce_ant_gain[STR_LEN_32B ]; +s8 ce_ant_gain_36_64[STR_LEN_32B ]; +s8 ce_ant_gain_100_140[STR_LEN_32B ]; +s8 ce_ant_gain_149_165[STR_LEN_32B ]; +s8 ci_min_ant_pwr[STR_LEN_32B ]; +s8 ci_bw_factor[STR_LEN_32B ]; +u8 ce_mcast_rate; +bool ce_dyn_mcast_rate_en; +bool ce_dyn_bcast_rate_en; +u8 ce_default_mcs_ofdm; +u8 ce_default_mcs_cck; +bool ce_prot_log_nav_en; +u8 ce_prot_mode; +u8 ce_prot_rate_format; +u8 ce_prot_rate_mcs; +u8 ce_prot_rate_pre_type; +u8 ce_bw_signaling_mode; +u8 ci_dyn_cts_sta_thr; +s8 ci_vns_pwr_limit; +u8 ci_vns_pwr_mode; +s8 ci_vns_rssi_auto_resp_thr; +s8 ci_vns_rssi_thr; +s8 ci_vns_rssi_hys; +u16 ci_vns_maintenance_time; +u16 ce_bcn_tx_path_min_time; +bool ci_backup_bcn_en; +bool ce_tx_txop_cut_en; +u8 ci_bcns_flushed_cnt_thr; +bool ci_phy_err_prevents_phy_dump; +u8 ci_tx_rx_delay; +u8 ci_fw_assert_time_diff_sec; +u8 ci_fw_assert_storm_detect_thd; +u32 ce_hw_assert_time_max; +u8 ce_bg_assert_print; +u8 ce_fw_watchdog_mode; +u8 ce_fw_watchdog_limit_count; +u32 ce_fw_watchdog_limit_time; +s8 ci_rx_remote_cpu_drv; +s8 ci_rx_remote_cpu_mac; +u16 ci_pending_queue_size; +u8 ce_tx_power_control; +bool ce_acs_coex_en; +u8 ci_dfs_initial_gain; +u8 ci_dfs_agc_cd_th; +u16 ci_dfs_long_pulse_min; +u16 ci_dfs_long_pulse_max; +s8 ce_dfs_tbl_overwrite[STR_LEN_64B ]; +/* Power Per MCS values - 6g */ +s8 ce_ppmcs_offset_he_6g[WRS_MCS_MAX_HE ]; +/* Power Per MCS values - 5g */ +s8 ce_ppmcs_offset_he_36_64[WRS_MCS_MAX_HE ]; +s8 ce_ppmcs_offset_he_100_140[WRS_MCS_MAX_HE ]; +s8 ce_ppmcs_offset_he_149_165[WRS_MCS_MAX_HE ]; +s8 ce_ppmcs_offset_ht_vht_36_64[WRS_MCS_MAX_VHT ]; +s8 ce_ppmcs_offset_ht_vht_100_140[WRS_MCS_MAX_VHT ]; +s8 ce_ppmcs_offset_ht_vht_149_165[WRS_MCS_MAX_VHT ]; +s8 ce_ppmcs_offset_ofdm_36_64[WRS_MCS_MAX_OFDM ]; +s8 ce_ppmcs_offset_ofdm_100_140[WRS_MCS_MAX_OFDM ]; +s8 ce_ppmcs_offset_ofdm_149_165[WRS_MCS_MAX_OFDM ]; +/* Power Per MCS values - 24g */ +s8 ce_ppmcs_offset_he[WRS_MCS_MAX_HE ]; +s8 ce_ppmcs_offset_ht[WRS_MCS_MAX_HT ]; +s8 ce_ppmcs_offset_ofdm[WRS_MCS_MAX_OFDM ]; +s8 ce_ppmcs_offset_cck[WRS_MCS_MAX_CCK ]; +/* Power Per BW values - all bands */ +s8 ce_ppbw_offset[CHNL_BW_MAX ]; +bool ce_power_offset_prod_en; +bool ci_bf_en; +u8 ci_bf_max_nss; +u16 ce_sounding_interval_coefs[SOUNDING_INTERVAL_COEF_MAX ]; +u8 ci_rate_fallback[CL_RATE_FALLBACK_MAX ]; +u16 ce_rx_pkts_budget; +u8 ci_band_num; +bool ci_mult_ampdu_in_txop_en; +u8 ce_wmm_aifsn[AC_MAX ]; +u8 ce_wmm_cwmin[AC_MAX ]; +u8 ce_wmm_cwmax[AC_MAX ]; +u16 ce_wmm_txop[AC_MAX ]; +u8 ci_su_force_min_spacing; +u8 ci_mu_force_min_spacing; +u8 ci_tf_mac_pad_dur; +u32 ci_cca_timeout; +u16 ce_tx_ba_session_timeout; +bool ci_motion_sense_en; +s8 ci_motion_sense_rssi_thr; +u8 ci_wrs_max_bw; +u8 ci_wrs_min_bw; +s8 ci_wrs_fixed_rate[WRS_FIXED_PARAM_MAX ]; +u8 ce_he_mcs_nss_supp_tx[WRS_SS_MAX ]; +u8 ce_he_mcs_nss_supp_rx[WRS_SS_MAX ]; +u8 ce_vht_mcs_nss_supp_tx[WRS_SS_MAX ]; +u8 ce_vht_mcs_nss_supp_rx[WRS_SS_MAX ]; +u8 ci_pe_duration; +u8 ci_pe_duration_bcast; +u8 ci_gain_update_enable; +u8 ci_mcs_sig_b; +u8 ci_spp_ksr_value; +bool ci_rx_padding_en; +bool ci_stats_en; +bool ci_bar_disable; +bool ci_ofdm_only; +bool ci_hw_bsr; +bool ci_drop_to_lower_bw; +bool ci_force_icmp_single; +bool ce_wrs_rx_en; +u8 ci_hr_factor[CHNL_BW_MAX ]; +bool ci_csd_en; +bool ci_signal_extension_en; +bool ci_vht_cap_24g; +u32 ci_tx_digital_gain; +u32 ci_tx_digital_gain_cck; +s8 ci_ofdm_cck_power_offset; +bool ci_mac_clk_gating_en; +bool ci_phy_clk_gating_en; +bool ci_imaging_blocker; +u8 ci_sensing_ndp_tx_chain_mask; +u8 ci_sensing_ndp_tx_bw; +u8 ci_sensing_ndp_tx_format; +u8 ci_sensing_ndp_tx_num_ltf; +u8 ci_calib_ant_tx[MAX_ANTENNAS ]; +u8 ci_calib_ant_rx[MAX_ANTENNAS ]; +s8 ci_cca_ed_rise_thr_dbm; +s8 ci_cca_ed_fall_thr_dbm; +u8 ci_cca_cs_en; +u8 ci_cca_modem_en; +u8 ci_cca_main_ant; +u8 ci_cca_second_ant; +u8 ci_cca_flag0_ctrl; +u8 ci_cca_flag1_ctrl; +u8 ci_cca_flag2_ctrl; +u8 ci_cca_flag3_ctrl; +s8 ci_cca_gi_rise_thr_dbm; +s8 ci_cca_gi_fall_thr_dbm; +s8 ci_cca_gi_pow_lim_dbm; +u16 ci_cca_ed_en; +u8 ci_cca_gi_en; +bool ci_rx_he_mu_ppdu; +bool ci_fast_rx_en; +u8 ci_distance_auto_resp_all; +u8 ci_distance_auto_resp_msta; +bool ci_fw_disable_recovery; +bool ce_listener_en; +bool ci_tx_delay_tstamp_en; +u8 ci_calib_tx_init_tx_gain[MAX_ANTENNAS ]; +u8 ci_calib_tx_init_rx_gain[MAX_ANTENNAS ]; +u8 ci_calib_rx_init_tx_gain[MAX_ANTENNAS ]; +u8 ci_calib_rx_init_rx_gain[MAX_ANTENNAS ]; +u8 ci_calib_conf_rx_gain_upper_limit; +u8 ci_calib_conf_rx_gain_lower_limit; +u8 ci_calib_conf_tone_vector_20bw[IQ_NUM_TONES_REQ ]; +u8 ci_calib_conf_tone_vector_40bw[IQ_NUM_TONES_REQ ]; +u8 ci_calib_conf_tone_vector_80bw[IQ_NUM_TONES_REQ ]; +u8 ci_calib_conf_tone_vector_160bw[IQ_NUM_TONES_REQ ]; +u32 ci_calib_conf_gp_rad_trshld; +u32 ci_calib_conf_ga_lin_upper_trshld; +u32 ci_calib_conf_ga_lin_lower_trshld; +u8 ci_calib_conf_singletons_num; +u16 ci_calib_conf_rampup_time; +u16 ci_calib_conf_lo_coarse_step; +u16 ci_calib_conf_lo_fine_step; +#ifdef CONFIG_CL8K_EEPROM_STM24256 +u16 ci_calib_eeprom_channels_20mhz[EEPROM_CALIB_DATA_ELEM_NUM_20MHZ_TCV0 ]; +u16 ci_calib_eeprom_channels_40mhz[EEPROM_CALIB_DATA_ELEM_NUM_40MHZ_TCV0 ]; +u16 ci_calib_eeprom_channels_80mhz[EEPROM_CALIB_DATA_ELEM_NUM_80MHZ_TCV0 ]; +u16 ci_calib_eeprom_channels_160mhz[EEPROM_CALIB_DATA_ELEM_NUM_160MHZ_TCV0 ]; +#endif +u16 ci_mesh_basic_rates[MESH_BASIC_RATE_MAX ]; +}; + +int cl_tcv_config_read (struct cl_hw *cl_hw); +u8 cl_tcv_config_get_num_ap (struct cl_hw *cl_hw); +int cl_tcv_config_alloc (struct cl_hw *cl_hw); +void cl_tcv_config_free (struct cl_hw *cl_hw); +void cl_tcv_config_validate_calib_params (struct cl_hw *cl_hw); + +#endif /* CL_TCV_CONFIG_H */
Signature · 1 line
2.36.1
RFC v2 80/96 cl8k: add temperature.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- .../net/wireless/celeno/cl8k/temperature.c | 634 ++++++++++++++++++ 1 file changed, 634 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/temperature.c
drivers/net/wireless/celeno/cl8k/temperature.c new file +634 -0
@@ -0,0 +1,634 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/kthread.h> + +#include "hw.h" +#include "e2p.h" +#include "channel.h" +#include "power.h" +#include "debug.h" +#include "utils.h" +#include "radio.h" +#include "temperature.h" + +#define TEMP_DIFF_INVALID 0x7F + +#define TEMPERATURE_MIN 0 +#define TEMPERATURE_MAX 127 + +#define DUTY_CYCLE_MAX 100 +#define DUTY_CYCLE_MIN 20 +#define DUTY_CYCLE_STEP 20 + +#define TEMP_MEASUREMENT_TIMEOUT msecs_to_jiffies(500) + +static int cl_temperature_read_fw (struct cl_hw *cl_hw,enum cl_temp_mode desired_temp_mode, +u16 *raw_bits) +{ +u8 retval =0 ; +struct mm_anamon_read_cfm *cfm; + +if (cl_msg_tx_anamon_read (cl_hw,ANAMON_MODE_TEMPERATURE , desired_temp_mode,0 ) !=0 ) { +cl_dbg_err (cl_hw,"cl_msg_tx_anamon_read failed\n" ); +cl_msg_tx_free_cfm_params (cl_hw,MM_ANAMON_READ_CFM ); +return -1 ; + } + + cfm = (struct mm_anamon_read_cfm *)(cl_hw->msg_cfm_params[MM_ANAMON_READ_CFM ]); +if (!cfm) +return -ENOMSG ; + + retval = cfm->retval; + *raw_bits = ((le16_to_cpu (cfm->raw_bits_data_0) +le16_to_cpu (cfm->raw_bits_data_1)) /2 ); +cl_msg_tx_free_cfm_params (cl_hw,MM_ANAMON_READ_CFM ); + +return retval ?0 :-1 ; +} + +static s16 cl_raw_bits_to_temperature (u16 raw_bits,enum cl_temp_mode desired_temp_mode) +{ +s16 adcmv =cl_adc_to_mv (raw_bits); + +/* Calculation of external thermistor */ +if (desired_temp_mode ==TEMP_MODE_EXTERNAL ) { +/* +* External-temperature calculation: +* Ext_tmp = -196 * adcv ^ 3 + 403 * adcv ^ 2 - 356 * adcv + 146 +* +* Ext_tmp = -196 * (adcmv / 1000) ^ 3 + +* 403 * (adcmv / 1000) ^ 2 - +* 356 * (adcmv / 1000) + +* 146 +* +* Ext_tmp = (-196 * adcmv ^ 3 + +* 403000 * adcmv ^ 2 - +* 356000000 * adcmv + +* 146000000000) / 1000000000 +*/ +return (s16 )div_s64 (-196ULL * adcmv * adcmv * adcmv + +403000ULL * adcmv * adcmv - +356000000ULL * adcmv + +146000000000ULL , +1000000000 ); + } + +/* Calculation of internal thermistor - ADCmv * slope - 163 (slope=0.290) */ +if (desired_temp_mode ==TEMP_MODE_INTERNAL ) +return ((adcmv *29 ) /100 ) -163 ; + +return 0 ; +} + +static void cl_temperature_set_power_offset (struct cl_hw *cl_hw,s8 power_offset) +{ +s8 total_pwr_offset[MAX_ANTENNAS ] = {0 }; +u8 chan_idx =cl_channel_to_index (cl_hw, cl_hw->channel); +u8 i =0 ; + + cl_hw->temp_comp_db.power_offset = power_offset; + +if (chan_idx ==INVALID_CHAN_IDX ) + goto out; + +for (i =0 ; i <MAX_ANTENNAS ; i++) { + total_pwr_offset[i] = + (cl_hw->tx_pow_info[chan_idx][i].offset + +POWER_OFFSET_RES * power_offset); + } + +out: +cl_msg_tx_set_ant_pwr_offset (cl_hw, total_pwr_offset); +} + +static void cl_temperature_comp_tcv (struct cl_chip *chip,struct cl_hw *cl_hw,s16 temp_internal) +{ +struct cl_temp_comp_db *temp_comp_db = &cl_hw->temp_comp_db; +s8 new_power_offset =0 ; + +/* Accumulate temperature delta */ + temp_comp_db->acc_temp_delta += (temp_internal - temp_comp_db->calib_temperature); + +/* Check if it is time to make a new decision */ +if ((chip->temperature.comp_iterations %CL_TEMP_COMP_ITERATIONS ) !=0 ) +return ; + +/* Average the temperature delta over the last CL_TEMP_COMP_ITERATIONS samples */ + temp_comp_db->avg_temp_delta =DIV_ROUND_CLOSEST (temp_comp_db->acc_temp_delta, +CL_TEMP_COMP_ITERATIONS ); + +/* Reset accumulated temp delta */ + temp_comp_db->acc_temp_delta =0 ; + + new_power_offset = (s8 )DIV_ROUND_CLOSEST (temp_comp_db->avg_temp_delta * + cl_hw->conf->ce_temp_comp_slope,100 ); + +if (temp_comp_db->power_offset == new_power_offset) +return ; + +cl_dbg_trace (cl_hw,"calib_temperature %d, avg_temp_delta %d, power_offset %d\n" , + temp_comp_db->calib_temperature, + temp_comp_db->avg_temp_delta, + new_power_offset); + +cl_temperature_set_power_offset (cl_hw, new_power_offset); +} + +static void cl_temperature_comp (struct cl_chip *chip,struct cl_hw *cl_hw) +{ +struct cl_temperature *temperature = &chip->temperature; +s16 temp_internal =0 ; + +if (!chip->conf->ce_temp_comp_en) +return ; + + temp_internal =cl_temperature_read (cl_hw,TEMP_MODE_INTERNAL ); + temperature->comp_iterations++; + +cl_dbg_chip_trace (chip,"comp_iterations = %u, temp_internal = %d\n" , + (temperature->comp_iterations %CL_TEMP_COMP_ITERATIONS ), temp_internal); + +if (cl_chip_is_tcv0_enabled (chip)) +cl_temperature_comp_tcv (chip, chip->cl_hw_tcv0, temp_internal); + +if (cl_chip_is_tcv1_enabled (chip)) +cl_temperature_comp_tcv (chip, chip->cl_hw_tcv1, temp_internal); +} + +static void cl_temperature_tx_duty_cycle (struct cl_chip *chip,u8 duty_cycle) +{ +u16 periodic_tx_time_on = chip->conf->ce_temp_protect_tx_period_ms * duty_cycle /100 ; +u16 periodic_tx_time_off = chip->conf->ce_temp_protect_tx_period_ms - periodic_tx_time_on; + +if (cl_chip_is_tcv0_enabled (chip)) +cl_msg_tx_start_periodic_tx_time (chip->cl_hw_tcv0, + periodic_tx_time_off, periodic_tx_time_on); + +if (cl_chip_is_tcv1_enabled (chip)) +cl_msg_tx_start_periodic_tx_time (chip->cl_hw_tcv1, + periodic_tx_time_off, periodic_tx_time_on); +} + +static void cl_temperature_protect_radio_off (struct cl_chip *chip,s16 temp_avg) +{ +struct cl_temp_protect_db *temp_protect_db = &chip->temperature.protect_db; +struct cl_chip_conf *conf = chip->conf; + +if (temp_protect_db->force_radio_off) +return ; + +cl_radio_off_chip (chip); + temp_protect_db->force_radio_off = true; +cl_dbg_chip_verbose (chip,"temperature [%d] >= radio off threshold [%d] --> radio off!\n" , + temp_avg, conf->ce_temp_protect_radio_off_th); +} + +static void cl_temperature_protect_radio_on (struct cl_chip *chip,s16 temp_avg) +{ +struct cl_temp_protect_db *temp_protect_db = &chip->temperature.protect_db; +struct cl_chip_conf *conf = chip->conf; +s16 temp_thr = conf->ce_temp_protect_radio_off_th -CL_TEMP_PROTECT_RADIO_OFF_HYST ; + +if (temp_avg >= temp_thr) +return ; + +cl_radio_on_chip (chip); + temp_protect_db->force_radio_off = false; +cl_dbg_chip_verbose (chip,"temperature [%d] < radio off threshold - hysteresis [%d] " +"--> radio on!\n" , + temp_avg, temp_thr); +} + +static void cl_temperature_protect_dec_duty_cycle (struct cl_chip *chip,s16 temp_avg) +{ +struct cl_temp_protect_db *temp_protect_db = &chip->temperature.protect_db; +struct cl_chip_conf *conf = chip->conf; + +if (temp_protect_db->duty_cycle ==DUTY_CYCLE_MIN ) +return ; + + temp_protect_db->duty_cycle -=DUTY_CYCLE_STEP ; +cl_temperature_tx_duty_cycle (chip, temp_protect_db->duty_cycle); +cl_dbg_chip_warn (chip, +"temperature [%d] > protect_th_max [%d] --> decrease duty cycle [%u]!\n" , + temp_avg, conf->ce_temp_protect_th_max, temp_protect_db->duty_cycle); +} + +static void cl_temperature_protect_inc_duty_cycle (struct cl_chip *chip,s16 temp_avg) +{ +struct cl_temp_protect_db *temp_protect_db = &chip->temperature.protect_db; +struct cl_chip_conf *conf = chip->conf; + +if (temp_protect_db->duty_cycle ==DUTY_CYCLE_MAX ) +return ; + + temp_protect_db->duty_cycle +=DUTY_CYCLE_STEP ; +cl_temperature_tx_duty_cycle (chip, temp_protect_db->duty_cycle); +cl_dbg_chip_warn (chip, +"temperature [%d] < protect_th_min [%d] --> increase duty cycle [%u]!\n" , + temp_avg, conf->ce_temp_protect_th_min, temp_protect_db->duty_cycle); +} + +static void cl_temperature_protect_decision (struct cl_chip *chip,s16 temp_avg) +{ +struct cl_temp_protect_db *temp_protect_db = &chip->temperature.protect_db; +struct cl_chip_conf *conf = chip->conf; + +/* Test mode - force test_mode_duty_cycle */ +if (unlikely (temp_protect_db->test_mode_duty_cycle !=DUTY_CYCLE_MAX )) { +cl_temperature_tx_duty_cycle (chip, temp_protect_db->test_mode_duty_cycle); +return ; + } + +/* Temperature protection logic: +* +* If the temperature is greater or equal to the radio off threshold +* then set the radio off. +* If the temperature is below the (radio off threshold - hysteresis [10]) +* then set the radio on again. +* +* Any time the temperature is greater than the max threshold then we +* decrease the duty cycle. +* Any time the temperature is below the min threshold then we increase +* the duty cycle. +*/ +if (temp_avg >= conf->ce_temp_protect_radio_off_th) { +cl_temperature_protect_radio_off (chip, temp_avg); +return ; + } + +if (temp_protect_db->force_radio_off) { +cl_temperature_protect_radio_on (chip, temp_avg); +return ; + } + +if (temp_avg > conf->ce_temp_protect_th_max) { +cl_temperature_protect_dec_duty_cycle (chip, temp_avg); +return ; + } + +if (temp_avg < chip->conf->ce_temp_protect_th_min) { +cl_temperature_protect_inc_duty_cycle (chip, temp_avg); +return ; + } +} + +static s16 cl_temperature_avg_protect (struct cl_temp_protect_db *temp_protect_db) +{ +/* Calculate average of last_samples */ +u8 i; +s32 temp_avg =0 ; + +for (i =0 ; i <CL_TEMP_PROTECT_NUM_SAMPLES ; i++) + temp_avg += temp_protect_db->last_samples[i]; + +return (s16)(temp_avg /CL_TEMP_PROTECT_NUM_SAMPLES ); +} + +static void cl_temperature_protect_handle_read (struct cl_chip *chip,s16 temp) +{ +struct cl_temp_protect_db *temp_protect_db = &chip->temperature.protect_db; +unsigned long curr_time =jiffies_to_msecs (jiffies); +unsigned long delta_time = curr_time - temp_protect_db->last_timestamp; + +/* Add current read */ + temp_protect_db->last_samples[temp_protect_db->curr_idx] = temp; + temp_protect_db->curr_idx = (temp_protect_db->curr_idx +1 ) %CL_TEMP_PROTECT_NUM_SAMPLES ; + +if (delta_time >=CL_TEMP_PROTECT_INTERVAL_MS ) { +s16 temp_avg =cl_temperature_avg_protect (temp_protect_db); + +cl_dbg_chip_trace (chip,"temp_avg = %d, delta_time = %lu\n" , temp_avg, delta_time); +cl_temperature_protect_decision (chip, temp_avg); + temp_protect_db->last_timestamp = curr_time; + } +} + +static void cl_temperature_protect (struct cl_chip *chip,struct cl_hw *cl_hw) +{ +s16 protect_temp =0 ; +struct cl_chip_conf *conf = chip->conf; + +switch (conf->ce_temp_protect_en) { +case TEMP_PROTECT_OFF : +return ; +case TEMP_PROTECT_INTERNAL : + protect_temp =cl_temperature_read (cl_hw,TEMP_MODE_INTERNAL ) + + conf->ce_temp_protect_delta; +break ; +case TEMP_PROTECT_EXTERNAL : + protect_temp =cl_temperature_read (cl_hw,TEMP_MODE_EXTERNAL ) + + conf->ce_temp_protect_delta; +break ; +case TEMP_PROTECT_DIFF : + protect_temp =cl_temperature_read (cl_hw,TEMP_MODE_INTERNAL ) - + chip->temperature.diff_internal_external + conf->ce_temp_protect_delta; +break ; + } + +cl_temperature_protect_handle_read (chip, protect_temp); +} + +static int cl_e2p_read_temp_diff (struct cl_chip *chip,s8 *temp_diff) +{ +/* Read temp_diff from eeprom */ +return cl_e2p_read (chip, temp_diff,SIZE_GEN_TEMP_DIFF ,ADDR_GEN_TEMP_DIFF ); +} + +static int cl_e2p_write_temp_diff (struct cl_chip *chip,s8 temp_diff) +{ +/* Writing temp_diff to eeprom */ +return cl_e2p_write (chip, (u8 *)&temp_diff,SIZE_GEN_TEMP_DIFF ,ADDR_GEN_TEMP_DIFF ); +} + +static int cl_temperature_diff_update (struct cl_hw *cl_hw) +{ +s8 temp_diff =cl_temperature_read (cl_hw,TEMP_MODE_INTERNAL ) - +cl_temperature_read (cl_hw,TEMP_MODE_EXTERNAL ); + +if (cl_e2p_write_temp_diff (cl_hw->chip, temp_diff)) { +cl_dbg_err (cl_hw,"Error occurred while writing temperature diff to EEPROM.\n" ); +return -1 ; + } + + cl_hw->chip->temperature.diff_internal_external = temp_diff; +return 0 ; +} + +static struct cl_hw *cl_init_measurement (struct cl_chip *chip) +{ +struct cl_hw *cl_hw =NULL ; + +mutex_lock (&chip->temperature.hw_lock); + cl_hw =cl_chip_is_tcv0_enabled (chip) ? chip->cl_hw_tcv0 : chip->cl_hw_tcv1; +if (cl_hw &&test_bit (CL_DEV_STARTED , &cl_hw->drv_flags) && + !(cl_hw->conf && cl_hw->conf->ce_listener_en)) +set_bit (cl_hw->tcv_idx, &chip->temperature.used_hw_map); +else + cl_hw =NULL ; +mutex_unlock (&chip->temperature.hw_lock); + +return cl_hw; +} + +static void cl_deinit_measurement (struct cl_hw *cl_hw) +{ +struct cl_temperature *temperature = &cl_hw->chip->temperature; + +clear_bit (cl_hw->tcv_idx, &temperature->used_hw_map); +wake_up (&temperature->measurement_done); +} + +void cl_temperature_wait_for_measurement (struct cl_chip *chip,u8 tcv_idx) +{ +struct cl_temperature *temperature = &chip->temperature; +int timeout =0 ; + +mutex_lock (&temperature->hw_lock); +if (!test_bit (tcv_idx, &temperature->used_hw_map)) + goto exit; + + timeout =wait_event_timeout (temperature->measurement_done, + !test_bit (tcv_idx, &temperature->used_hw_map), +TEMP_MEASUREMENT_TIMEOUT ); +WARN_ONCE (timeout !=0 ,"Measurment timeout reached!\n" ); + +exit: +mutex_unlock (&temperature->hw_lock); +} + +static int cl_temperature_kthread (void *arg) +{ +struct cl_chip *chip = (struct cl_chip *)arg; +struct cl_hw *cl_hw =NULL ; +unsigned long timeout =msecs_to_jiffies (CL_TEMPERATURE_TIMER_INTERVAL_MS ); + +while (!kthread_should_stop ()) { + cl_hw =cl_init_measurement (chip); +if (cl_hw) { +cl_temperature_comp (chip, cl_hw); +cl_temperature_protect (chip, cl_hw); +cl_deinit_measurement (cl_hw); + } + +if (wait_event_timeout (chip->temperature.wait_done, +kthread_should_stop (), timeout)) { +cl_dbg_chip_trace (chip,"exit temperature kthread\n" ); +return 0 ; + } + } + +return 0 ; +} + +static void cl_temperature_recovery_protect (struct cl_hw *cl_hw) +{ +struct cl_chip *chip = cl_hw->chip; + +if (chip->conf->ce_temp_protect_en !=TEMP_PROTECT_OFF ) { +u8 duty_cycle = chip->temperature.protect_db.duty_cycle; + +if (duty_cycle <DUTY_CYCLE_MAX ) { +u16 periodic_tx_time_on = + chip->conf->ce_temp_protect_tx_period_ms * duty_cycle /100 ; +u16 periodic_tx_time_off = + chip->conf->ce_temp_protect_tx_period_ms - periodic_tx_time_on; + +cl_msg_tx_start_periodic_tx_time (cl_hw, periodic_tx_time_off, + periodic_tx_time_on); + } + } +} + +static void cl_temperature_recovery_comp (struct cl_hw *cl_hw) +{ +struct cl_chip *chip = cl_hw->chip; +s8 power_offset = cl_hw->temp_comp_db.power_offset; + +if (!chip->conf->ce_temp_comp_en) +return ; + +if (power_offset) +cl_temperature_set_power_offset (cl_hw, power_offset); +} + +void cl_temperature_init (struct cl_chip *chip) +{ +struct cl_temperature *temperature = &chip->temperature; +struct cl_temp_protect_db *temp_protect_db = &temperature->protect_db; +unsigned long curr_time_ms =jiffies_to_msecs (jiffies); + +init_waitqueue_head (&temperature->wait_done); +init_waitqueue_head (&temperature->measurement_done); + +mutex_init (&temperature->mutex); +mutex_init (&temperature->hw_lock); + + temperature->internal_last =UNCALIBRATED_TEMPERATURE ; + temperature->internal_read_timestamp = curr_time_ms; + temperature->external_last =UNCALIBRATED_TEMPERATURE ; + temperature->external_read_timestamp = curr_time_ms; + +/* Temp_protect_db init */ + temp_protect_db->duty_cycle =DUTY_CYCLE_MAX ; + temp_protect_db->test_mode_duty_cycle =DUTY_CYCLE_MAX ; + temp_protect_db->last_timestamp = curr_time_ms; + + temperature->kthread =kthread_run (cl_temperature_kthread, + chip, +"cl_temperature_kthread_%u" , + chip->idx); +if (IS_ERR (temperature->kthread)) { +cl_dbg_chip_err (chip,"Failed to create temperature kthread\n" ); + temperature->kthread =NULL ; + } +} + +void cl_temperature_close (struct cl_chip *chip) +{ +struct cl_temperature *temperature = &chip->temperature; + +if (temperature->kthread) { +cl_dbg_chip_trace (chip,"stopping temperature kthread\n" ); +if (kthread_stop (temperature->kthread) != -EINTR ) +wake_up (&temperature->wait_done); + + temperature->kthread =NULL ; + } +} + +s8 cl_temperature_read (struct cl_hw *cl_hw,enum cl_temp_mode mode) +{ +u16 raw_bits =0 ; +s16 temp_val =0 ; +unsigned long curr_time =jiffies_to_msecs (jiffies); +unsigned long diff_time =0 ; +struct cl_chip *chip = cl_hw->chip; +struct cl_temperature *temperature = &chip->temperature; + +if (!IS_REAL_PHY (chip)) +return UNCALIBRATED_TEMPERATURE ; + +mutex_lock (&temperature->mutex); + +switch (mode) { +case TEMP_MODE_INTERNAL : + diff_time = curr_time - temperature->internal_read_timestamp; +if (diff_time <=CL_TEMPERATURE_UPDATE_INTERVAL_MS ) { + temp_val = temperature->internal_last; +cl_dbg_chip_trace (chip,"Return last internal temperature %d\n" , temp_val); + goto read_out; + } +break ; +case TEMP_MODE_EXTERNAL : + diff_time = curr_time - temperature->external_read_timestamp; +if (diff_time <=CL_TEMPERATURE_UPDATE_INTERVAL_MS ) { + temp_val = temperature->external_last; +cl_dbg_chip_trace (chip,"Return last external temperature %d\n" , temp_val); + goto read_out; + } +break ; +default : +cl_dbg_chip_err (chip,"Invalid temperature mode %d\n" , mode); + goto read_err; + } + +if (cl_temperature_read_fw (cl_hw, mode, &raw_bits)) { +cl_dbg_chip_err (chip,"Temperature read failed\n" ); + goto read_err; + } + + temp_val =cl_raw_bits_to_temperature (raw_bits, mode); + +if (temp_val >TEMPERATURE_MAX || temp_val <TEMPERATURE_MIN ) { +cl_dbg_chip_err (chip,"Invalid temperature value %d\n" , temp_val); + goto read_err; + } + +/* Update temperature read db */ +if (mode ==TEMP_MODE_INTERNAL ) { + temperature->internal_last = temp_val; + temperature->internal_read_timestamp =jiffies_to_msecs (jiffies); +cl_dbg_chip_trace (chip,"Read and save internal temperature %d\n" , temp_val); + }else { + temperature->external_last = temp_val; + temperature->external_read_timestamp =jiffies_to_msecs (jiffies); +cl_dbg_chip_trace (chip,"Read and save external temperature %d\n" , temp_val); + } + +read_out: +mutex_unlock (&temperature->mutex); +return temp_val; + +read_err: +/* If temperature read failed return the last valid value */ +mutex_unlock (&temperature->mutex); + +return (mode ==TEMP_MODE_INTERNAL ) ? + temperature->internal_last : temperature->external_last; +} + +void cl_temperature_recovery (struct cl_hw *cl_hw) +{ +cl_temperature_recovery_protect (cl_hw); +cl_temperature_recovery_comp (cl_hw); +} + +int cl_temperature_diff_e2p_read (struct cl_hw *cl_hw) +{ +struct cl_chip *chip = cl_hw->chip; +struct cl_temperature *temperature = &chip->temperature; + +if (cl_e2p_read_temp_diff (chip, &temperature->diff_internal_external) || + temperature->diff_internal_external ==TEMP_DIFF_INVALID ) { +if (cl_temperature_diff_update (cl_hw)) +return -1 ; + +cl_dbg_chip_verbose (chip,"Temperature difference: Internal - External = %d\n" , + temperature->diff_internal_external); + } + +return 0 ; +} + +s16 cl_temperature_calib_calc (struct cl_hw *cl_hw,u16 raw_bits) +{ +struct cl_chip *chip = cl_hw->chip; +s16 temperature =cl_raw_bits_to_temperature (raw_bits,TEMP_MODE_INTERNAL ) + + chip->conf->ce_temp_protect_delta; + +if (temperature >=TEMPERATURE_MIN && temperature <=TEMPERATURE_MAX ) +return temperature; + +cl_dbg_chip_err (chip,"Invalid temperature = %d\n" , temperature); + +return (chip->temperature.internal_last + chip->conf->ce_temp_protect_delta); +} + +void cl_temperature_comp_update_calib (struct cl_hw *cl_hw) +{ +u8 chan_idx =cl_channel_to_index (cl_hw, cl_hw->channel); +u8 ant, ant_cnt =0 ; +s16 total_temp =0 ; +struct cl_tx_power_info *info =NULL ; + +if (unlikely (chan_idx ==INVALID_CHAN_IDX )) { +cl_dbg_err (cl_hw,"Unsupported frequency %u\n" , cl_hw->center_freq); +return ; + } + + info = &cl_hw->tx_pow_info[chan_idx][0 ]; + +/* Sum up the temperature of all phys */ +for (ant =0 ; ant <MAX_ANTENNAS && ant_cnt < cl_hw->num_antennas; ant++) { +if (!(cl_hw->mask_num_antennas &BIT (ant))) +continue ; + + total_temp += info[ant].temperature; + ant_cnt++; + } + +/* Average the total temperature and update chan_params */ + cl_hw->temp_comp_db.calib_temperature =DIV_ROUND_CLOSEST (total_temp, cl_hw->num_antennas); +} +
Signature · 1 line
2.36.1
RFC v2 81/96 cl8k: add temperature.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- .../net/wireless/celeno/cl8k/temperature.h | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/temperature.h
drivers/net/wireless/celeno/cl8k/temperature.h new file +71 -0
@@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_TEMPERATURE_H +#define CL_TEMPERATURE_H + +#include <net/mac80211.h> + +#define CL_TEMP_PROTECT_INTERVAL_MS 40000 +#define CL_TEMP_PROTECT_NUM_SAMPLES 4 +#define CL_TEMP_PROTECT_RADIO_OFF_HYST 10 +#define CL_TEMP_COMP_ITERATIONS 4 +#define CL_TEMPERATURE_TIMER_INTERVAL_MS 4000 +#define CL_TEMPERATURE_UPDATE_INTERVAL_MS (CL_TEMPERATURE_TIMER_INTERVAL_MS - 100) + +enum cl_temp_state { +TEMP_PROTECT_OFF , +TEMP_PROTECT_INTERNAL , +TEMP_PROTECT_EXTERNAL , +TEMP_PROTECT_DIFF +}; + +enum cl_temp_mode { +TEMP_MODE_INTERNAL , +TEMP_MODE_EXTERNAL +}; + +struct cl_temp_comp_db { +s8 calib_temperature; +s8 power_offset; +s32 acc_temp_delta; +s32 avg_temp_delta; +}; + +struct cl_temp_protect_db { +bool force_radio_off; +u8 duty_cycle; +u8 test_mode_duty_cycle; +u8 curr_idx; +s16 last_samples[CL_TEMP_PROTECT_NUM_SAMPLES ]; +unsigned long last_timestamp; +}; + +struct cl_temperature { +s8 diff_internal_external; +u8 comp_iterations; +struct cl_temp_protect_db protect_db; +struct task_struct *kthread; +wait_queue_head_t wait_done; +wait_queue_head_t measurement_done; +s16 internal_last; +s16 external_last; +unsigned long internal_read_timestamp; +unsigned long external_read_timestamp; +struct mutex mutex; +struct mutex hw_lock; +unsigned long used_hw_map; +}; + +struct cl_chip ; + +void cl_temperature_init (struct cl_chip *chip); +void cl_temperature_close (struct cl_chip *chip); +s8 cl_temperature_read (struct cl_hw *cl_hw,enum cl_temp_mode mode); +void cl_temperature_recovery (struct cl_hw *cl_hw); +int cl_temperature_diff_e2p_read (struct cl_hw *cl_hw); +s16 cl_temperature_calib_calc (struct cl_hw *cl_hw,u16 raw_bits); +void cl_temperature_comp_update_calib (struct cl_hw *cl_hw); +void cl_temperature_wait_for_measurement (struct cl_chip *chip,u8 tcv_idx); + +#endif /* CL_TEMPERATURE_H */
Signature · 1 line
2.36.1
RFC v2 82/96 cl8k: add traffic.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/traffic.c | 254 +++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/traffic.c
drivers/net/wireless/celeno/cl8k/traffic.c new file +254 -0
@@ -0,0 +1,254 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/ip.h> +#include <linux/ipv6.h> + +#include "bf.h" +#include "tx.h" +#include "radio.h" +#include "utils.h" +#include "debug.h" +#include "hw.h" +#include "traffic.h" + +#define TRAFFIC_CNTR_ACTIVE_THR 3/* 3 * 100ms = 300ms */ +#define TRAFFIC_CNTR_IDLE_THR 20/* 20 * 100ms = 2sec */ + +/* Threshold in bytes */ +#define TRAFFIC_ACTIVE_THR_DRV 1920/* = 150Kbit/sec (150 * 1024 / 8 / 10) */ +#define TRAFFIC_ACTIVE_THR_BF 26214/* = 2mbit/sec (2 * 1024 * 1024 / 8 / 10) */ +#define TRAFFIC_ACTIVE_THR_MU 131070/* = 10mbit/sec (10 * 1024 * 1024 / 8 / 10) */ +#define TRAFFIC_ACTIVE_THR_EDCA_6G 2621440/* = 200mbit/sec (200 * 1024 * 1024 / 8 / 10) */ +#define TRAFFIC_ACTIVE_THR_EDCA_5G 2621440/* = 200mbit/sec (200 * 1024 * 1024 / 8 / 10) */ +#define TRAFFIC_ACTIVE_THR_EDCA_24G 655360/* = 50mbit/sec (50 * 1024 * 1024 / 8 / 10) */ +#define TRAFFIC_ACTIVE_THR_DFS 13107/* = 1mbit/sec (1 * 1024 * 1024 / 8 / 10) */ + +static void cl_traffic_mon_ipv4 (struct sk_buff *skb,struct cl_sta *cl_sta, +enum cl_traffic_mon_direction direction) +{ +struct iphdr *iphdr =ip_hdr (skb); + +if (iphdr->protocol ==IPPROTO_UDP ) + cl_sta->traffic_mon[CL_TRFC_MON_PROT_UDP ][direction].bytes += +ntohs (iphdr->tot_len) -IPV4_HDR_LEN (iphdr->ihl) -sizeof (struct udphdr ); +else if (iphdr->protocol ==IPPROTO_TCP ) + cl_sta->traffic_mon[CL_TRFC_MON_PROT_TCP ][direction].bytes += +ntohs (iphdr->tot_len) -IPV4_HDR_LEN (iphdr->ihl) -sizeof (struct tcphdr ); +} + +static void cl_traffic_mon_ipv6 (struct sk_buff *skb,struct cl_sta *cl_sta, +enum cl_traffic_mon_direction direction) +{ +struct ipv6hdr *ipv6hdr =ipv6_hdr (skb); + +if (ipv6hdr->nexthdr ==IPPROTO_UDP ) + cl_sta->traffic_mon[CL_TRFC_MON_PROT_UDP ][direction].bytes += +ntohs (ipv6hdr->payload_len) -sizeof (struct udphdr ); +else if (ipv6hdr->nexthdr ==IPPROTO_TCP ) + cl_sta->traffic_mon[CL_TRFC_MON_PROT_TCP ][direction].bytes += +ntohs (ipv6hdr->payload_len) -sizeof (struct tcphdr ); +} + +static void cl_traffic_mon_calc (struct sk_buff *skb,struct cl_sta *cl_sta, +enum cl_traffic_mon_direction direction) +{ +if (cl_set_network_header_if_proto (skb,ETH_P_IP )) +cl_traffic_mon_ipv4 (skb, cl_sta, direction); +else if (cl_set_network_header_if_proto (skb,ETH_P_IPV6 )) +cl_traffic_mon_ipv6 (skb, cl_sta, direction); +} + +void cl_traffic_mon_tx (struct cl_sta *cl_sta,struct sk_buff *skb) +{ +struct cl_hw *cl_hw = cl_sta->cl_vif->cl_hw; + +if (cl_hw->conf->ci_traffic_mon_en) +cl_traffic_mon_calc (skb, cl_sta,CL_TRFC_MON_DIR_DL ); +} + +void cl_traffic_mon_rx (struct cl_sta *cl_sta,struct sk_buff *skb) +{ +struct cl_hw *cl_hw = cl_sta->cl_vif->cl_hw; + +if (cl_hw->conf->ci_traffic_mon_en) +cl_traffic_mon_calc (skb, cl_sta,CL_TRFC_MON_DIR_UL ); +} + +void cl_traffic_mon_sta_maintenance (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +u8 i, j; + +for (i =0 ; i <CL_TRFC_MON_PROT_MAX ; i++) +for (j =0 ; j <CL_TRFC_MON_DIR_MAX ; j++) { + cl_sta->traffic_mon[i][j].bytes_per_sec = cl_sta->traffic_mon[i][j].bytes; + cl_sta->traffic_mon[i][j].bytes =0 ; + } +} + +static void cl_traffic_sta_start (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +enum cl_traffic_level level,enum cl_traffic_direction direction) +{ + cl_hw->traffic_db.num_active_sta_dir[direction][level]++; + +/* If other direction is not active increase num_active_sta */ +if (!cl_sta->traffic_db[1 - direction].activity_db[level].is_active) + cl_hw->traffic_db.num_active_sta[level]++; + +if (level ==TRAFFIC_LEVEL_DRV ) { +/* +* Dynamic CTS: +* If protection mode is disabled, environment is clean, +* and station threshold was reached switch to CTS. +*/ +if (cl_hw->traffic_db.num_active_sta[TRAFFIC_LEVEL_DRV ] == + cl_hw->conf->ci_dyn_cts_sta_thr) { +if (cl_prot_mode_get (cl_hw) ==TXL_NO_PROT ) { + cl_hw->traffic_db.dynamic_cts = true; +cl_prot_mode_set (cl_hw,TXL_PROT_CTS ); + } + } + }else if (level ==TRAFFIC_LEVEL_BF ) { +if (direction ==TRAFFIC_DIRECTION_TX ) +cl_bf_sta_active (cl_hw, cl_sta, true); + } +} + +static void cl_traffic_sta_stop (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +enum cl_traffic_level level,enum cl_traffic_direction direction) +{ + cl_hw->traffic_db.num_active_sta_dir[direction][level]--; + +/* If other direction is not active decrease num_active_sta */ +if (!cl_sta->traffic_db[1 - direction].activity_db[level].is_active) + cl_hw->traffic_db.num_active_sta[level]--; + +if (level ==TRAFFIC_LEVEL_DRV ) { +/* Dynamic CTS: +* If it was turned on and active station count became lower than +* threshold --> return to no protection +*/ +if (cl_hw->traffic_db.dynamic_cts) { +if (cl_hw->traffic_db.num_active_sta[TRAFFIC_LEVEL_DRV ] == + (cl_hw->conf->ci_dyn_cts_sta_thr -1 )) { + cl_hw->traffic_db.dynamic_cts = false; +cl_prot_mode_set (cl_hw,TXL_NO_PROT ); + } + } + }else if (level ==TRAFFIC_LEVEL_BF ) { +if (direction ==TRAFFIC_DIRECTION_TX ) +cl_bf_sta_active (cl_hw, cl_sta, false); + } +} + +static void cl_traffic_check_activity (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +enum cl_traffic_level level, +enum cl_traffic_direction direction) +{ +struct cl_traffic_activity *activity_db = + &cl_sta->traffic_db[direction].activity_db[level]; +u32 num_bytes = cl_sta->traffic_db[direction].num_bytes; + +if (num_bytes > cl_hw->traffic_db.active_bytes_thr[level]) { + activity_db->cntr_active++; + activity_db->cntr_idle =0 ; + +/* If traffic is above threshold for X consective times change state to active */ +if (!activity_db->is_active && + activity_db->cntr_active >=TRAFFIC_CNTR_ACTIVE_THR ) { + activity_db->is_active = true; +cl_traffic_sta_start (cl_hw, cl_sta, level, direction); + } + }else { + activity_db->cntr_active =0 ; + activity_db->cntr_idle++; + +/* If traffic is below threshold for Y consective times change state to idle */ +if (activity_db->is_active && activity_db->cntr_idle >=TRAFFIC_CNTR_IDLE_THR ) { + activity_db->is_active = false; +cl_traffic_sta_stop (cl_hw, cl_sta, level, direction); + } + } +} + +static void cl_traffic_monitor_sta_traffic (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +enum cl_traffic_level level =0 ; + +/* Check Tx & Rx activity in all levels */ +for (level =0 ; level <TRAFFIC_LEVEL_MAX ; level++) { +cl_traffic_check_activity (cl_hw, cl_sta, level,TRAFFIC_DIRECTION_TX ); +cl_traffic_check_activity (cl_hw, cl_sta, level,TRAFFIC_DIRECTION_RX ); + } + +/* Save previous Tx num bytes */ + cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].num_bytes_prev = + cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].num_bytes; + +/* Reset num_bytes */ + cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].num_bytes =0 ; + cl_sta->traffic_db[TRAFFIC_DIRECTION_RX ].num_bytes =0 ; +} + +void cl_traffic_init (struct cl_hw *cl_hw) +{ +struct cl_traffic_main *traffic_db = &cl_hw->traffic_db; + + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_DRV ] =TRAFFIC_ACTIVE_THR_DRV ; + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_BF ] =TRAFFIC_ACTIVE_THR_BF ; + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_MU ] =TRAFFIC_ACTIVE_THR_MU ; + +if (cl_band_is_6g (cl_hw)) + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_EDCA ] =TRAFFIC_ACTIVE_THR_EDCA_6G ; +else if (cl_band_is_5g (cl_hw)) + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_EDCA ] =TRAFFIC_ACTIVE_THR_EDCA_5G ; +else + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_EDCA ] =TRAFFIC_ACTIVE_THR_EDCA_24G ; + + traffic_db->active_bytes_thr[TRAFFIC_LEVEL_DFS ] =TRAFFIC_ACTIVE_THR_DFS ; +} + +void cl_traffic_tx_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u32 num_bytes) +{ + cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].num_bytes += num_bytes; + cl_sta->tx_bytes += num_bytes; +} + +void cl_traffic_rx_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u32 num_bytes) +{ + cl_sta->traffic_db[TRAFFIC_DIRECTION_RX ].num_bytes += num_bytes; + cl_sta->rx_bytes += num_bytes; +} + +void cl_traffic_maintenance (struct cl_hw *cl_hw) +{ +cl_sta_loop (cl_hw, cl_traffic_monitor_sta_traffic); +} + +void cl_traffic_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +/* Check if station disconnected during traffic */ +enum cl_traffic_level level =0 ; +enum cl_traffic_direction direction =0 ; + +for (direction =0 ; direction <TRAFFIC_DIRECTION_MAX ; direction++) { +for (level =0 ; level <TRAFFIC_LEVEL_MAX ; level++) { +if (cl_sta->traffic_db[direction].activity_db[level].is_active) +cl_traffic_sta_stop (cl_hw, cl_sta, level, direction); + } + +memset (&cl_sta->traffic_db,0 ,sizeof (cl_sta->traffic_db)); + } +} + +bool cl_traffic_is_sta_active (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +return (cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].activity_db[TRAFFIC_LEVEL_DRV ].is_active || + cl_sta->traffic_db[TRAFFIC_DIRECTION_RX ].activity_db[TRAFFIC_LEVEL_DRV ].is_active); +} + +bool cl_traffic_is_sta_tx_exist (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +return ((cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].num_bytes !=0 ) || + (cl_sta->traffic_db[TRAFFIC_DIRECTION_TX ].num_bytes_prev !=0 )); +}
Signature · 1 line
2.36.1
RFC v2 83/96 cl8k: add traffic.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/traffic.h | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/traffic.h
drivers/net/wireless/celeno/cl8k/traffic.h new file +77 -0
@@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_TRAFFIC_H +#define CL_TRAFFIC_H + +#include <linux/dcache.h> +#include <linux/skbuff.h> + +enum cl_traffic_mon_protocol { +CL_TRFC_MON_PROT_TCP , +CL_TRFC_MON_PROT_UDP , +CL_TRFC_MON_PROT_MAX , +}; + +enum cl_traffic_mon_direction { +CL_TRFC_MON_DIR_DL , +CL_TRFC_MON_DIR_UL , +CL_TRFC_MON_DIR_MAX , +}; + +struct cl_traffic_mon { +u32 bytes_per_sec; +u32 bytes; +}; + +enum cl_traffic_direction { +TRAFFIC_DIRECTION_TX , +TRAFFIC_DIRECTION_RX , + +TRAFFIC_DIRECTION_MAX +}; + +enum cl_traffic_level { +TRAFFIC_LEVEL_DRV , +TRAFFIC_LEVEL_BF , +TRAFFIC_LEVEL_MU , +TRAFFIC_LEVEL_EDCA , +TRAFFIC_LEVEL_DFS , + +TRAFFIC_LEVEL_MAX +}; + +struct cl_traffic_activity { +u8 cntr_active; +u8 cntr_idle; +bool is_active; +}; + +struct cl_traffic_sta { +struct cl_traffic_activity activity_db[TRAFFIC_LEVEL_MAX ]; +u32 num_bytes; +u32 num_bytes_prev; +}; + +struct cl_traffic_main { +u32 num_active_sta[TRAFFIC_LEVEL_MAX ]; +u32 num_active_sta_dir[TRAFFIC_DIRECTION_MAX ][TRAFFIC_LEVEL_MAX ]; +u32 active_bytes_thr[TRAFFIC_LEVEL_MAX ]; +bool dynamic_cts; +}; + +struct cl_sta ; +struct cl_hw ; + +void cl_traffic_mon_tx (struct cl_sta *cl_sta,struct sk_buff *skb); +void cl_traffic_mon_rx (struct cl_sta *cl_sta,struct sk_buff *skb); +void cl_traffic_mon_sta_maintenance (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_traffic_init (struct cl_hw *cl_hw); +void cl_traffic_tx_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u32 num_bytes); +void cl_traffic_rx_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u32 num_bytes); +void cl_traffic_maintenance (struct cl_hw *cl_hw); +void cl_traffic_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +bool cl_traffic_is_sta_active (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +bool cl_traffic_is_sta_tx_exist (struct cl_hw *cl_hw,struct cl_sta *cl_sta); + +#endif /* CL_TRAFFIC_H */
Signature · 1 line
2.36.1
RFC v2 84/96 cl8k: add tx.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/tx.c | 3397 +++++++++++++++++++++++++ 1 file changed, 3397 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/tx.c
drivers/net/wireless/celeno/cl8k/tx.c new file +3397 -0
@@ -0,0 +1,3397 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include "mac_addr.h" +#include "sta.h" +#include "hw.h" +#include "utils.h" +#include "fw.h" +#include "key.h" +#include "dfs.h" +#include "radio.h" +#include "enhanced_tim.h" +#include "rates.h" +#include "stats.h" +#include "debug.h" +#include "tx.h" + +/* Expected Acknowledgment */ +#define EXPECTED_NO_ACK 0 +#define EXPECTED_ACK 1 + +void cl_tx_update_hist_tstamp (struct cl_tx_queue *tx_queue,struct sk_buff *skb, +u32 tstamp_hist[],bool update_skb_ktime) +{ +s64 diff_ms; +ktime_t ktime =ktime_get (); + + diff_ms =ktime_ms_delta (ktime, skb->tstamp); + +if (diff_ms >=DELAY_HIST_SIZE ) + diff_ms =DELAY_HIST_SIZE -1 ; + + tstamp_hist[diff_ms]++; + +if (update_skb_ktime) + skb->tstamp = ktime; +} + +static void cl_tx_cpu_single (struct cl_hw *cl_hw) +{ +u32 processor_id =smp_processor_id (); + +if (processor_id <CPU_MAX_NUM ) + cl_hw->cpu_cntr.tx_single[processor_id]++; +} + +static void cl_tx_cpu_agg (struct cl_hw *cl_hw) +{ +u32 processor_id =smp_processor_id (); + +if (processor_id <CPU_MAX_NUM ) + cl_hw->cpu_cntr.tx_agg[processor_id]++; +} + +static char cl_tx_ctrl_single_frame_type (__le16 fc) +{ +if (ieee80211_is_data_qos (fc)) +return CL_TX_SINGLE_FRAME_TYPE_QOS_DATA ; +else if (ieee80211_is_qos_nullfunc (fc)) +return CL_TX_SINGLE_FRAME_TYPE_QOS_NULL ; +else if (ieee80211_is_mgmt (fc)) +return CL_TX_SINGLE_FRAME_TYPE_MANAGEMENT ; +else +return CL_TX_SINGLE_FRAME_TYPE_OTHER ; +} + +static void cl_tx_single_prep (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr, +u16 frame_len,u8 hdr_pads,bool is_vns) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (sw_txhdr->skb); +struct ieee80211_key_conf *key_conf = tx_info->control.hw_key; +struct txdesc *txdesc = &sw_txhdr->txdesc; +struct tx_host_info *host_info = &txdesc->host_info; +struct cl_vif *cl_vif =NULL ; + +/* Reset txdesc */ +memset (txdesc,0 ,sizeof (struct txdesc )); + +/* Vif_index must be filled in even without header conversion */ + cl_vif = (struct cl_vif *)tx_info->control.vif->drv_priv; + host_info->vif_index = cl_vif->vif_index; + +if (hdr_pads) + host_info->host_padding |=BIT (0 ); + + host_info->is_bcn = sw_txhdr->is_bcn; + host_info->expected_ack = (tx_info->flags &IEEE80211_TX_CTL_NO_ACK ) ? +EXPECTED_NO_ACK :EXPECTED_ACK ; + +/* Beware when prot and sta is unknown */ +if (key_conf) { + frame_len += key_conf->icv_len; + host_info->is_protected = true; + host_info->hw_key_idx = key_conf->hw_key_idx; + } + + host_info->packet_cnt =1 ; + + txdesc->umacdesc.packet_len[0 ] =cpu_to_le16 (frame_len); + txdesc->e2w_txhdr_param.frame_ctrl = sw_txhdr->fc; + txdesc->e2w_result.bcmc = (sw_txhdr->sta_idx ==STA_IDX_INVALID ); + txdesc->e2w_result.tid = sw_txhdr->tid; + txdesc->e2w_result.is_vns = is_vns; + txdesc->e2w_result.is_txinject = false; + txdesc->e2w_result.single_type =cl_tx_ctrl_single_frame_type (sw_txhdr->fc); + txdesc->e2w_result.single_valid_sta__agg_e2w_tx_done = !!sw_txhdr->cl_sta; + txdesc->e2w_natt_param.sta_index = sw_txhdr->sta_idx; + +/* Set rate control */ +cl_rate_ctrl_update_desc_single (cl_hw, host_info, sw_txhdr); +} + +static void cl_tx_sub_frame_set (struct cl_sta *cl_sta,u8 tid) +{ +struct cl_tx_queue *tx_queue = cl_sta->agg_tx_queues[tid]; + +if (tx_queue) + tx_queue->total_packets++; +} + +static void cl_tx_send (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr, +struct cl_amsdu_ctrl *amsdu_anchor) +{ +struct cl_tx_queue *tx_queue = sw_txhdr->tx_queue; +struct cl_sta *cl_sta = sw_txhdr->cl_sta; + + tx_queue->total_packets++; + +if (cl_txq_is_fw_full (tx_queue) || (cl_sta && cl_sta->pause_tx)) { +/* If firmware is full push the packet to the queue */ +cl_txq_push (cl_hw, sw_txhdr); + }else if (amsdu_anchor && amsdu_anchor->is_sw_amsdu) { +cl_txq_push (cl_hw, sw_txhdr); +tasklet_schedule (&cl_hw->tx_task); + }else if (!list_empty (&tx_queue->hdrs) || cl_hw->tx_db.force_amsdu) { +/* +* If queue in driver is not empty push the packet to the queue, +* and call cl_txq_sched() to transfer packets from the queue to firmware +*/ +cl_txq_push (cl_hw, sw_txhdr); +cl_txq_sched (cl_hw, tx_queue); + }else { +/* Push the packet directly to firmware */ +cl_tx_push (cl_hw, sw_txhdr, tx_queue); + } +} + +void cl_tx_push (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr,struct cl_tx_queue *tx_queue) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (sw_txhdr->skb); +struct ieee80211_key_conf *keyconf = tx_info->control.hw_key; +struct cl_sta *cl_sta = sw_txhdr->cl_sta; +struct cl_vif *cl_vif = sw_txhdr->cl_vif; +u8 tid = sw_txhdr->tid; +struct txdesc *txdesc = &sw_txhdr->txdesc; +struct tx_host_info *host_info = &txdesc->host_info; +struct cl_e2w_txhdr_param *e2w_txhdr_param = &txdesc->e2w_txhdr_param; +struct ieee80211_hdr *hdr80211 = sw_txhdr->hdr80211; +u8 queue_type = tx_queue->type; +bool is_mgmt =ieee80211_is_mgmt (sw_txhdr->fc); + +if (cl_key_is_cipher_ccmp_gcmp (keyconf)) { +/* +* In case of CCMP or GCMP encryption we need to inc pn. +* In case of amsdu/header_conversion we need to pass it to firmware as well +*/ +u64 pn =atomic64_inc_return (&keyconf->tx_pn); + +if (txdesc->e2w_natt_param.hdr_conv_enable) { +memcpy (&e2w_txhdr_param->encrypt_pn, &pn,CL_CCMP_GCMP_PN_SIZE ); + }else { +u8 hdrlen =ieee80211_hdrlen (sw_txhdr->fc); + +cl_key_ccmp_gcmp_pn_to_hdr ((u8 *)hdr80211 + hdrlen, pn, keyconf->keyidx); + } + } + +if (queue_type ==QUEUE_TYPE_AGG ) { +struct cl_baw *baw = &cl_sta->baws[tid]; +bool is_amsdu =cl_tx_ctrl_is_amsdu (tx_info); + +if (is_amsdu) { +struct cl_amsdu_ctrl *amsdu_anchor = &cl_sta->amsdu_anchor[tid]; + +if (sw_txhdr->is_sw_amsdu) { +u8 pkt_cnt = sw_txhdr->sw_amsdu_packet_cnt; + +if (pkt_cnt ==1 ) +cl_tx_amsdu_unset (sw_txhdr);/* Clear AMSDU bit. */ + +if (hdr80211) + hdr80211->seq_ctrl =cpu_to_le16 (baw->tid_seq); + + tx_queue->stats_sw_amsdu_cnt[pkt_cnt -1 ]++; + }else { +u8 pkt_cnt = host_info->packet_cnt; + +if (pkt_cnt ==1 ) +cl_tx_amsdu_unset (sw_txhdr);/* Clear AMSDU bit. */ + + tx_queue->stats_hw_amsdu_cnt[pkt_cnt -1 ]++; + } + +/* Reset anchor if needed */ +if (amsdu_anchor->sw_txhdr == sw_txhdr) +cl_tx_amsdu_anchor_init (amsdu_anchor); + } + +if (hdr80211) + hdr80211->seq_ctrl =cpu_to_le16 (baw->tid_seq); + +/* Update sequence number and increase it */ + e2w_txhdr_param->seq_ctrl =cpu_to_le16 (baw->tid_seq); + baw->tid_seq =INC_SN (baw->tid_seq); + + }else { +/* +* Update sequence number and increase it +* Management sequence number is set by firmware. +*/ +if (!is_mgmt) { + hdr80211->seq_ctrl |=cpu_to_le16 (cl_vif->sequence_number); + cl_vif->sequence_number =INC_SN (cl_vif->sequence_number); + }else { +if (ieee80211_vif_is_mesh (cl_vif->vif)) { +struct ieee80211_mgmt *mgmt = (void *)sw_txhdr->skb->data; +u16 capab; + +if (mgmt->u.action.u.addba_req.action_code == +WLAN_ACTION_ADDBA_RESP ) { + capab =le16_to_cpu (mgmt->u.action.u.addba_resp.capab); + capab &= ~IEEE80211_ADDBA_PARAM_AMSDU_MASK ; + mgmt->u.action.u.addba_resp.capab =cpu_to_le16 (capab); + } + } + } + } + +cl_drv_ops_pkt_fw_send (cl_hw, sw_txhdr, tx_queue); +} + +void cl_tx_single_free_skb (struct cl_hw *cl_hw,struct sk_buff *skb) +{ +if (IEEE80211_SKB_CB (skb)->ack_frame_id) +ieee80211_tx_status (cl_hw->hw, skb); +else +dev_kfree_skb_any (skb); +} + +void cl_tx_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool is_vns,bool lock) +{ +struct cl_tx_queue *tx_queue; +struct cl_sw_txhdr *sw_txhdr; +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +struct cl_vif *cl_vif =TX_INFO_TO_CL_VIF (cl_hw, tx_info); +struct ieee80211_hdr *hdr80211 = (struct ieee80211_hdr *)skb->data; +u8 hdr_pads =CL_SKB_DATA_ALIGN_PADS (hdr80211); +__le16 fc = hdr80211->frame_control; +u16 frame_len = (u16 )skb->len; +u8 tid =ieee80211_is_data_qos (fc) ?ieee80211_get_tid (hdr80211) :0 ; +u8 ac = tid_to_ac[tid]; +bool is_beacon =ieee80211_is_beacon (fc); + +cl_tx_cpu_single (cl_hw); + +if (unlikely (!test_bit (CL_DEV_STARTED , &cl_hw->drv_flags) || +test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags))) { +cl_tx_single_free_skb (cl_hw, skb); + cl_hw->tx_packet_cntr.drop.dev_flags++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + +if (unlikely (!cl_vif->tx_en || cl_hw->tx_disable_flags)) { +cl_tx_single_free_skb (cl_hw, skb); + cl_hw->tx_packet_cntr.drop.tx_disable++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + +/* Check if packet length exceeds max size */ +if (unlikely (frame_len >CL_TX_MAX_FRAME_LEN_SINGLE )) { +cl_tx_single_free_skb (cl_hw, skb); +cl_dbg_err (cl_hw,"frame_len (%u) exceeds max size\n" , frame_len); + cl_hw->tx_packet_cntr.drop.length_limit++; + cl_vif->trfc_cntrs[ac].tx_errors++; +return ; + } + +if (cl_sta && cl_sta->key_disable) { +cl_tx_single_free_skb (cl_hw, skb); + cl_hw->tx_packet_cntr.drop.key_disable++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + +/* Allocate sw_txhdr */ + sw_txhdr =cl_sw_txhdr_alloc (cl_hw); + +if (unlikely (!sw_txhdr)) { +cl_tx_single_free_skb (cl_hw, skb); +cl_dbg_verbose (cl_hw,"sw_txhdr alloc failed\n" ); + cl_hw->tx_packet_cntr.drop.txhdr_alloc_fail++; + cl_vif->trfc_cntrs[ac].tx_errors++; +return ; + } + +/* Prepare sw_txhdr */ + sw_txhdr->hdr80211 = hdr80211; + sw_txhdr->hw_queue = tx_info->hw_queue; + sw_txhdr->is_bcn = is_beacon; + sw_txhdr->skb = skb; + sw_txhdr->map_len = frame_len + hdr_pads; + sw_txhdr->fc = fc; + sw_txhdr->cl_vif = cl_vif; + sw_txhdr->tid = tid; + sw_txhdr->ac = ac; + +if (cl_sta) { + sw_txhdr->cl_sta = cl_sta; + sw_txhdr->sta_idx = cl_sta->sta_idx; + }else { + sw_txhdr->cl_sta =NULL ; + sw_txhdr->sta_idx =STA_IDX_INVALID ; + } + +/* Prepare txdesc */ +cl_tx_single_prep (cl_hw, sw_txhdr, frame_len, hdr_pads, is_vns); + +/* +* Fetch the driver queue. +* IEEE80211_TX_CTL_AMPDU is not set in tx_info->flags, otherwise cl_tx_agg() +* would have been called and not cl_tx_single(). +* Therefore there is no need to check if tx_queue is NULL or if queue type +* is QUEUE_TYPE_AGG. +*/ + tx_queue =cl_txq_get (cl_hw, sw_txhdr); +if (!tx_queue) { +cl_tx_single_free_skb (cl_hw, skb); +cl_dbg_verbose (cl_hw,"tx_queue is NULL\n" ); + cl_vif->trfc_cntrs[ac].tx_errors++; +cl_sw_txhdr_free (cl_hw, sw_txhdr); +return ; + } + + sw_txhdr->tx_queue = tx_queue; + +if (lock) { +if (tx_queue->type ==QUEUE_TYPE_BCMC ) { +/* +* All other broadcast/multicast packets are buffered in +* ieee80211_tx_h_multicast_ps_buf() and will follow the beacon. +*/ +spin_lock_bh (&cl_hw->tx_lock_bcmc); +cl_tx_send (cl_hw, sw_txhdr,NULL ); +spin_unlock_bh (&cl_hw->tx_lock_bcmc); + }else { +spin_lock_bh (&cl_hw->tx_lock_single); +cl_tx_send (cl_hw, sw_txhdr,NULL ); +spin_unlock_bh (&cl_hw->tx_lock_single); + } + }else { +cl_tx_send (cl_hw, sw_txhdr,NULL ); + } +} + +void cl_tx_fast_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool lock) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +u8 tid = skb->priority &IEEE80211_QOS_CTL_TID_MASK ; + +/* hw_key must be set before calling cl_tx_8023_to_wlan() */ + tx_info->control.hw_key =cl_key_get (cl_sta); + +/* Convert 802.3 to 802.11 header */ +if (cl_tx_8023_to_wlan (cl_hw, skb, cl_sta, tid) ==0 ) { +bool is_vns =cl_vns_is_very_near (cl_hw, cl_sta, skb); +u8 ac = tid_to_ac[tid]; + + tx_info->hw_queue = ac; + tx_info->control.vif = cl_sta->cl_vif->vif; + + cl_hw->tx_packet_cntr.forward.drv_fast_single++; + +cl_tx_single (cl_hw, cl_sta, skb, is_vns, lock); + } +} + +void cl_tx_agg_prep (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr, +u16 frame_len,u8 hdr_pads,bool hdr_conv) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (sw_txhdr->skb); +struct ieee80211_key_conf *key_conf = tx_info->control.hw_key; +struct txdesc *txdesc = &sw_txhdr->txdesc; +struct lmacapi *umacdesc = &txdesc->umacdesc; +struct tx_host_info *host_info = &txdesc->host_info; +u16 qos_ctrl = sw_txhdr->tid; + +/* Reset txdesc */ +memset (txdesc,0 ,sizeof (struct txdesc )); + + txdesc->e2w_result.tid = sw_txhdr->tid; + txdesc->e2w_result.is_txinject = false; + txdesc->e2w_natt_param.sta_index = sw_txhdr->sta_idx; + txdesc->e2w_natt_param.ampdu = true; + txdesc->e2w_natt_param.hdr_conv_enable = hdr_conv; + +if (hdr_conv) { +if (cl_tx_ctrl_is_amsdu (tx_info)) + qos_ctrl |=IEEE80211_QOS_CTL_A_MSDU_PRESENT ; + + txdesc->e2w_txhdr_param.frame_ctrl = sw_txhdr->fc; + txdesc->e2w_txhdr_param.qos_ctrl =cpu_to_le16 (qos_ctrl); + } + +if (hdr_pads) + host_info->host_padding |=BIT (0 ); + +/* Vif_index must be filled in even without header conversion */ + host_info->vif_index = sw_txhdr->cl_sta->cl_vif->vif_index; + +/* Set the expected_ack flag */ + host_info->expected_ack = (tx_info->flags &IEEE80211_TX_CTL_NO_ACK ) ? +EXPECTED_NO_ACK :EXPECTED_ACK ; + +if (key_conf) { + host_info->is_protected = true; + host_info->hw_key_idx = key_conf->hw_key_idx; + +if (!hdr_conv) + frame_len += key_conf->icv_len; + } + + host_info->packet_cnt =1 ; + umacdesc->packet_len[0 ] =cpu_to_le16 (frame_len); + +/* Set rate control */ +cl_rate_ctrl_update_desc_agg (cl_hw, host_info); +} + +static __le16 cl_tx_agg_frame_control (struct cl_vif *cl_vif, +struct ieee80211_key_conf *key_conf, +u8 *hdrlen) +{ +struct ieee80211_vif *vif = cl_vif->vif; +struct ieee80211_sub_if_data *sdata =vif_to_sdata (vif); +enum nl80211_iftype type = vif->type; +__le16 fc =cpu_to_le16 (IEEE80211_FTYPE_DATA |IEEE80211_STYPE_QOS_DATA ); + +if (type ==NL80211_IFTYPE_AP ) { + fc |=cpu_to_le16 (IEEE80211_FCTL_FROMDS ); + *hdrlen =26 ; + }else if (type ==NL80211_IFTYPE_STATION ) { + fc |=cpu_to_le16 (IEEE80211_FCTL_TODS ); + +if (sdata->u.mgd.use_4addr) { + fc |=cpu_to_le16 (IEEE80211_FCTL_FROMDS ); + *hdrlen =32 ; + }else { + *hdrlen =26 ; + } + } + +if (key_conf) + fc |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED ); + +return fc; +} + +static void _cl_tx_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool hdr_conv) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +struct ieee80211_key_conf *key_conf = tx_info->control.hw_key; +struct cl_sw_txhdr *sw_txhdr =NULL ; +struct cl_tx_queue *tx_queue =NULL ; +struct cl_vif *cl_vif = cl_sta->cl_vif; +u16 frame_len = (u16 )skb->len; +u16 total_frame_len =0 ; +u8 hdr_pads =CL_SKB_DATA_ALIGN_PADS (skb->data); +u8 is_amsdu =cl_tx_ctrl_is_amsdu (tx_info); +u8 tid = skb->priority &IEEE80211_QOS_CTL_TAG1D_MASK ; +u8 ac = tid_to_ac[tid]; +u8 hdrlen =0 ; + +cl_tx_cpu_agg (cl_hw); + +if (unlikely (!test_bit (CL_DEV_STARTED , &cl_hw->drv_flags) || +test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags))) { +kfree_skb (skb); + cl_hw->tx_packet_cntr.drop.dev_flags++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + +if (unlikely (!cl_vif->tx_en || cl_hw->tx_disable_flags)) { +kfree_skb (skb); + cl_hw->tx_packet_cntr.drop.tx_disable++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + +/* Check if packet length exceeds max size */ +if (unlikely (frame_len >CL_TX_MAX_FRAME_LEN_AGG )) { +kfree_skb (skb); +cl_dbg_err (cl_hw,"frame_len exceeds max size %d\n" , frame_len); + cl_hw->tx_packet_cntr.drop.length_limit++; + cl_vif->trfc_cntrs[ac].tx_errors++; +return ; + } + +if (cl_sta->key_disable) { +kfree_skb (skb); + cl_hw->tx_packet_cntr.drop.key_disable++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + +/* Check if amsdu is enable for current skb */ +if (is_amsdu) { +enum cl_amsdu_result amsdu_res =cl_tx_amsdu_set (cl_hw, cl_sta, skb, tid); + +switch (amsdu_res) { +case CL_AMSDU_SKIP : + is_amsdu = false; + tx_info->control.flags &= ~IEEE80211_TX_CTRL_AMSDU ; +case CL_AMSDU_ANCHOR_SET : +/* +* If new anchor was set, or AMSDU is +* skipped continue building sw_txhdr +*/ +break ; +case CL_AMSDU_SUB_FRAME_SET : +cl_tx_sub_frame_set (cl_sta, tid); + fallthrough; +case CL_AMSDU_FAILED : +default : +return ; + } + }else { +/* +* If not amsdu & anchor exist. reset current anchor +* in order to avoid reordring packets. +*/ +if (cl_sta->amsdu_anchor[tid].sw_txhdr) +cl_tx_amsdu_anchor_init (&cl_sta->amsdu_anchor[tid]); + } + +/* Allocate sw_txhdr */ + sw_txhdr =cl_sw_txhdr_alloc (cl_hw); +if (unlikely (!sw_txhdr)) { +kfree_skb (skb); +cl_dbg_err (cl_hw,"sw_txhdr alloc failed\n" ); + cl_hw->tx_packet_cntr.drop.txhdr_alloc_fail++; + cl_vif->trfc_cntrs[ac].tx_errors++; +return ; + } + +if (cl_vif->vif->type ==NL80211_IFTYPE_MESH_POINT ) + tx_info->hw_queue = ac; + +/* Fill sw_txhdr */ + sw_txhdr->tid = tid; + sw_txhdr->ac = ac; + sw_txhdr->hw_queue = tx_info->hw_queue; + sw_txhdr->cl_sta = cl_sta; + sw_txhdr->sta_idx = cl_sta->sta_idx; + sw_txhdr->is_bcn =0 ; + sw_txhdr->skb = skb; + sw_txhdr->map_len = frame_len + hdr_pads; + sw_txhdr->cl_vif = cl_vif; + +if (cl_sta->amsdu_anchor[tid].is_sw_amsdu) { + sw_txhdr->is_sw_amsdu = true; + sw_txhdr->sw_amsdu_packet_cnt =1 ; + }else { + sw_txhdr->is_sw_amsdu = false; + } + +if (hdr_conv) { + sw_txhdr->hdr80211 =NULL ; + sw_txhdr->fc =cl_tx_agg_frame_control (cl_vif, key_conf, &hdrlen); + }else { +struct ieee80211_hdr *hdr80211 = (struct ieee80211_hdr *)skb->data; +__le16 fc = hdr80211->frame_control; + + sw_txhdr->hdr80211 = hdr80211; + sw_txhdr->fc = fc; + hdrlen =ieee80211_hdrlen (fc); + } + +/* Fetch the relevant agg queue */ + tx_queue = cl_sta->agg_tx_queues[tid]; + +if (unlikely (!tx_queue)) { +kfree_skb (skb); +cl_sw_txhdr_free (cl_hw, sw_txhdr); +cl_dbg_err (cl_hw,"tx_queue is NULL [sta_idx = %u] [tid = %u]\n" , + cl_sta->sta_idx, tid); + cl_hw->tx_packet_cntr.drop.queue_null++; + cl_vif->trfc_cntrs[ac].tx_dropped++; +return ; + } + + sw_txhdr->tx_queue = tx_queue; + + total_frame_len = frame_len + hdrlen -sizeof (struct ethhdr ); + +if (key_conf) + total_frame_len += key_conf->icv_len; + +/* Prepare txdesc */ +cl_tx_agg_prep (cl_hw, sw_txhdr, frame_len, hdr_pads, hdr_conv); + +/* +* AMSDU - first sub frame +* !!! Must be done after calling cl_tx_agg_prep() !!! +*/ +if (is_amsdu) +cl_tx_amsdu_first_sub_frame (sw_txhdr, cl_sta, skb, tid); + +cl_tx_send (cl_hw, sw_txhdr, &cl_sta->amsdu_anchor[tid]); +} + +void cl_tx_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool hdr_conv,bool lock) +{ +if (lock) { +spin_lock_bh (&cl_hw->tx_lock_agg); +_cl_tx_agg (cl_hw, cl_sta, skb, hdr_conv); +spin_unlock_bh (&cl_hw->tx_lock_agg); + }else { +_cl_tx_agg (cl_hw, cl_sta, skb, hdr_conv); + } +} + +static void cl_tx_reset_session_timer (struct ieee80211_sta *sta,u8 tid) +{ +struct tid_ampdu_tx *tid_tx =NULL ; +struct sta_info *stainfo =IEEE80211_STA_TO_STAINFO (sta); + + tid_tx =rcu_dereference (stainfo->ampdu_mlme.tid_tx[tid]); + +if (tid_tx && tid_tx->timeout) + tid_tx->last_tx = jiffies; +} + +void cl_tx_fast_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool lock) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +struct ieee80211_vif *vif = cl_sta->cl_vif->vif; +u16 ac =skb_get_queue_mapping (skb); +u8 tid = skb->priority &IEEE80211_QOS_CTL_TAG1D_MASK ; + + tx_info->control.vif = vif; + tx_info->control.hw_key =cl_key_get (cl_sta); + tx_info->hw_queue = vif->hw_queue[ac]; + tx_info->flags |=IEEE80211_TX_CTL_AMPDU ; + +if (cl_sta->baws[tid].amsdu && + (cl_wrs_api_get_tx_sta_data_rate (cl_sta) > cl_hw->conf->ci_tx_amsdu_min_data_rate)) + tx_info->control.flags |=IEEE80211_TX_CTRL_AMSDU ; + +cl_tx_agg (cl_hw, cl_sta, skb, true, lock); +cl_tx_reset_session_timer (cl_sta->sta, tid); + cl_hw->tx_packet_cntr.forward.drv_fast_agg++; +} + +void cl_tx_wlan_to_8023 (struct sk_buff *skb) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct ethhdr tmp_eth; +struct ethhdr *ehdr; +struct { +u8 hdr[ETH_ALEN ]__aligned(2) ; +__be16 proto; + } payload; +u16 hdrlen =ieee80211_hdrlen (hdr->frame_control); +u8 enc_len =cl_key_get_cipher_len (skb); + +cl_mac_addr_copy (tmp_eth.h_dest,ieee80211_get_DA (hdr)); +cl_mac_addr_copy (tmp_eth.h_source,ieee80211_get_SA (hdr)); +skb_copy_bits (skb, hdrlen, &payload,sizeof (payload)); + tmp_eth.h_proto = payload.proto; + +if (enc_len) { +memcpy (skb->data + hdrlen, + skb->data + hdrlen + enc_len, + skb->len - hdrlen - enc_len); +skb_trim (skb, skb->len - enc_len); + } + +if (likely ((ether_addr_equal (payload.hdr, rfc1042_header) && + tmp_eth.h_proto !=htons (ETH_P_AARP ) && + tmp_eth.h_proto !=htons (ETH_P_IPX )) || +ether_addr_equal (payload.hdr, bridge_tunnel_header))) +/* Remove RFC1042 or Bridge-Tunnel encapsulation and replace ether_type */ + hdrlen +=ETH_ALEN +2 ; +else + tmp_eth.h_proto =htons (skb->len - hdrlen); + +skb_pull (skb, hdrlen); + ehdr =skb_push (skb,sizeof (struct ethhdr )); +memcpy (ehdr, &tmp_eth,sizeof (tmp_eth)); +} + +u16 cl_tx_prepare_wlan_hdr (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,struct ieee80211_hdr *hdr) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +u16 hdrlen =0 ; +__le16 fc =cpu_to_le16 (IEEE80211_FTYPE_DATA |IEEE80211_STYPE_DATA ); +struct ieee80211_vif *vif = cl_sta->cl_vif->vif; + +if (tx_info->control.hw_key) + fc |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED ); + +switch (vif->type) { +case NL80211_IFTYPE_AP : + fc |=cpu_to_le16 (IEEE80211_FCTL_FROMDS ); +/* DA BSSID SA */ +memcpy (hdr->addr1, skb->data,ETH_ALEN ); +memcpy (hdr->addr2, vif->addr,ETH_ALEN ); +memcpy (hdr->addr3, skb->data +ETH_ALEN ,ETH_ALEN ); + hdrlen =24 ; +break ; +case NL80211_IFTYPE_STATION : + { +struct wireless_dev *wdev = skb->dev->ieee80211_ptr; + +if (wdev && wdev->use_4addr) { + fc |=cpu_to_le16 (IEEE80211_FCTL_FROMDS | +IEEE80211_FCTL_TODS ); +/* RA TA DA SA */ +memcpy (hdr->addr1, vif->bss_conf.bssid,ETH_ALEN ); +memcpy (hdr->addr2, vif->addr,ETH_ALEN ); +memcpy (hdr->addr3, skb->data,ETH_ALEN ); +memcpy (hdr->addr4, skb->data +ETH_ALEN ,ETH_ALEN ); + hdrlen =30 ; + }else { + fc |=cpu_to_le16 (IEEE80211_FCTL_TODS ); +/* BSSID SA DA */ +memcpy (hdr->addr1, vif->bss_conf.bssid,ETH_ALEN ); +memcpy (hdr->addr2, skb->data +ETH_ALEN ,ETH_ALEN ); +memcpy (hdr->addr3, skb->data,ETH_ALEN ); + hdrlen =24 ; + } + } +break ; +case NL80211_IFTYPE_MESH_POINT : +cl_dbg_trace (cl_hw,"vif type mesh_point, invalid tx path\n" ); +return 0 ; +default : +cl_dbg_err (cl_hw,"Unknown vif type %d !!!\n" , vif->type); +return 0 ; + } + +if (cl_sta->sta->wme) { + fc |=cpu_to_le16 (IEEE80211_STYPE_QOS_DATA ); + hdrlen +=2 ; + } + + hdr->frame_control = fc; + hdr->duration_id =0 ; + hdr->seq_ctrl =0 ; + +return hdrlen; +} + +int cl_tx_8023_to_wlan (struct cl_hw *cl_hw,struct sk_buff *skb,struct cl_sta *cl_sta,u8 tid) +{ +struct ieee80211_hdr hdr; +int head_need, ret =0 ; +u16 ethertype, hdrlen; +const u8 *encaps_data =NULL ; +int encaps_len =0 , skip_header_bytes =ETH_HLEN ; +u8 enc_len =cl_key_get_cipher_len (skb); + +/* Convert Ethernet header to proper 802.11 header */ + ethertype = (skb->data[12 ] <<8 ) | skb->data[13 ]; + + hdrlen =cl_tx_prepare_wlan_hdr (cl_hw, cl_sta, skb, &hdr); +if (!hdrlen) { + ret = -EINVAL ; + goto free; + } + +if (ethertype >=ETH_P_802_3_MIN ) { + encaps_data = rfc1042_header; + encaps_len =sizeof (rfc1042_header); + skip_header_bytes -=2 ; + } + +skb_pull (skb, skip_header_bytes); + head_need = hdrlen + enc_len + encaps_len -skb_headroom (skb); + +if (head_need >0 ) { + head_need = ((head_need +3 ) & ~3 ); +if (pskb_expand_head (skb, head_need,0 ,GFP_ATOMIC )) { + ret = -ENOMEM ; + goto free; + } + } + +if (encaps_data) +memcpy (skb_push (skb, encaps_len), encaps_data, encaps_len); + +skb_push (skb, hdrlen + enc_len); + +if (cl_sta->sta->wme) { +u16 qos_ctrl = tid; + +memcpy (skb->data, &hdr, hdrlen -2 ); +memcpy (skb->data + hdrlen -2 , &qos_ctrl,2 ); + }else { +memcpy (skb->data, &hdr, hdrlen); + } + +skb_reset_mac_header (skb); + +return ret; +free: + cl_hw->tx_packet_cntr.drop.build_hdr_fail++; + cl_sta->cl_vif->trfc_cntrs[tid_to_ac[tid]].tx_errors++; +kfree_skb (skb); + skb =NULL ; + +return ret; +} + +void cl_tx_check_start_ba_session (struct cl_hw *cl_hw, +struct ieee80211_sta *sta, +struct sk_buff *skb) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +struct sta_info *stainfo =IEEE80211_STA_TO_STAINFO (sta); +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +u8 tid; + +/* TODO: What about HE? */ +if (!sta->ht_cap.ht_supported && + !sta->vht_cap.vht_supported && + !cl_band_is_6g (cl_hw)) +return ; + +if (test_sta_flag (stainfo,WLAN_STA_PS_STA )) +return ; + +if ((tx_info->flags &IEEE80211_TX_CTL_AMPDU ) && + !(tx_info->flags &IEEE80211_TX_STAT_AMPDU )) +return ; + +if (cl_tx_ctrl_is_eapol (tx_info)) +return ; + +if (unlikely (!ieee80211_is_data_qos (hdr->frame_control))) +return ; + +if (unlikely (skb->protocol ==cpu_to_be16 (ETH_P_PAE ))) +return ; + + tid =ieee80211_get_tid (hdr); + +if (likely (stainfo->ampdu_mlme.tid_tx[tid])) +return ; + +ieee80211_start_tx_ba_session (sta, tid, cl_hw->conf->ce_tx_ba_session_timeout); +} + +static void cl_tx_handle_beacon_tim (struct ieee80211_hw *hw,struct sk_buff *skb) +{ +struct cl_hw *cl_hw = (struct cl_hw *)hw->priv; +struct cl_sta *cl_sta =NULL ; +struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; +const u8 *tim_ie =cfg80211_find_ie (WLAN_EID_TIM , mgmt->u.beacon.variable, skb->len); +struct ieee80211_tim_ie *tim =NULL ; + +/* Offset of the element */ + tim = (void *)(tim_ie +BCN_IE_TIM_BIT_OFFSET ); + +cl_sta_lock (cl_hw); + +/* Loop through all STA's */ +list_for_each_entry (cl_sta, &cl_hw->cl_sta_db.head, list) { +if (cl_traffic_is_sta_tx_exist (cl_hw, cl_sta)) { +u8 sta_aid = cl_sta->sta->aid; +u8 map_index = sta_aid /BITS_PER_BYTE ; + +/* Update STA's AID in TIM bit */ + tim->virtual_map[map_index] |=BIT (sta_aid %BITS_PER_BYTE ); + } + } + +cl_sta_unlock (cl_hw); +} + +static struct sk_buff *cl_tx_beacon_get (struct ieee80211_hw *hw, +struct ieee80211_vif *vif) +{ +struct sk_buff *skb =NULL ; + + skb =ieee80211_beacon_get (hw, vif); + +/* Handle beacon TIM bitmap */ +if (skb) +cl_tx_handle_beacon_tim (hw, skb); + +return skb; +} + +static void cl_tx_mc (struct cl_vif *cl_vif,int *mc_fw_free) +{ +struct cl_hw *cl_hw = cl_vif->cl_hw; +struct ieee80211_vif *vif = cl_vif->vif; +struct sk_buff *skb =NULL ; +struct ieee80211_tx_info *tx_info; + +if (unlikely (!vif)) +return ; + +while (((*mc_fw_free) >0 ) && + (skb =ieee80211_get_buffered_bc (cl_hw->hw, vif))) { +/* Route this MCBC frame to the BCN ipc queue */ + tx_info =IEEE80211_SKB_CB (skb); + tx_info->hw_queue =CL_HWQ_BCN ; + + (*mc_fw_free)--; + +/* Clear more data bit if this is the last frame in this SP */ +if (*mc_fw_free ==0 ) { +struct ieee80211_hdr *hdr = + (struct ieee80211_hdr *)skb->data; + hdr->frame_control &= +cpu_to_le16 (~IEEE80211_FCTL_MOREDATA ); + } + +cl_tx_single (cl_hw,NULL , skb, false, true); + } +} + +void cl_tx_bcn_mesh_task (unsigned long data) +{ +struct cl_vif *cl_vif =NULL ; +struct cl_hw *cl_hw =NULL ; +struct ieee80211_tx_info *tx_info; +struct sk_buff *skb; +int mc_fw_free; + + cl_vif = (struct cl_vif *)data; +if (!cl_vif) +return ; + + cl_hw = cl_vif->cl_hw; + +if (!cl_hw || !cl_vif->vif || cl_vif->vif->type !=NL80211_IFTYPE_MESH_POINT || +cl_radio_is_off (cl_hw) || +cl_recovery_in_progress (cl_hw) || + !test_bit (CL_DEV_STARTED , &cl_hw->drv_flags) || +test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags) || + cl_hw->tx_disable_flags) +return ; + + skb =cl_tx_beacon_get (cl_hw->hw, cl_vif->vif); +if (!skb) +return ; + +/* Route this BCN to the BCN ipc queue */ + tx_info =IEEE80211_SKB_CB (skb); + tx_info->hw_queue =CL_HWQ_BCN ; + +cl_tx_single (cl_hw,NULL , skb, false, true); + + mc_fw_free = cl_hw->tx_queues->bcmc.fw_free_space; +cl_tx_mc (cl_vif, &mc_fw_free); +} + +static void cl_tx_bcn (struct cl_vif *cl_vif) +{ +struct cl_hw *cl_hw = cl_vif->cl_hw; +struct ieee80211_vif *vif = cl_vif->vif; +struct ieee80211_tx_info *tx_info; +struct sk_buff *skb; + +if (!vif || vif->type !=NL80211_IFTYPE_AP ) +return ; + +/* +* If we are in the middle of the CAC, we allow regular channel switch +* and retrigger the CAC (If needed). +* Or - if radar is detected, we wait for all CSAs to be transmitted, +* before allowing channel switch +*/ +if (cl_dfs_is_in_cac (cl_hw) && vif->csa_active) { +ieee80211_csa_finish (vif); +return ; + } + + skb =cl_tx_beacon_get (cl_hw->hw, vif); +if (!skb) +return ; + +/* Route this BCN to the BCN ipc queue */ + tx_info =IEEE80211_SKB_CB (skb); + tx_info->hw_queue =CL_HWQ_BCN ; + +cl_tx_single (cl_hw,NULL , skb, false, true); +} + +bool cl_is_tx_allowed (struct cl_hw *cl_hw) +{ +return !(cl_radio_is_off (cl_hw) || + cl_hw->vif_db.num_iface_bcn ==0 || +cl_recovery_in_progress (cl_hw) || + cl_hw->tx_db.block_bcn || + cl_hw->tx_disable_flags || + !test_bit (CL_DEV_STARTED , &cl_hw->drv_flags) || +test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags)); +} + +/* cl_tx_bcns_tasklet - generate BCNs and TX buffered MC frames each BCN DTIM interval +* +* Beacons are sent first followed by cyclic MC for fairness between VIF's +* the FW buffer is restricted to "IPC_TXDESC_CNT_BCMC" buffer size. +*/ +void cl_tx_bcns_tasklet (unsigned long data) +{ +struct cl_hw *cl_hw = (struct cl_hw *)data; +struct cl_vif *cl_vif =NULL ; +int mc_fw_free =0 ; + +read_lock (&cl_hw->vif_db.lock); + +if (!cl_is_tx_allowed (cl_hw)) + goto out; +list_for_each_entry (cl_vif, &cl_hw->vif_db.head, list) +cl_tx_bcn (cl_vif); + + cl_vif = cl_hw->mc_vif; + mc_fw_free = cl_hw->tx_queues->bcmc.fw_free_space; + +do { +cl_tx_mc (cl_vif, &mc_fw_free); +/* Cl_vif_get_next() is cyclic */ + cl_vif =cl_vif_get_next (cl_hw, cl_vif); + }while ((cl_vif != cl_hw->mc_vif) && mc_fw_free); + + cl_hw->mc_vif =cl_vif_get_next (cl_hw, cl_hw->mc_vif); + +out: +read_unlock (&cl_hw->vif_db.lock); +} + +void cl_tx_en (struct cl_hw *cl_hw,u8 reason,bool enable) +{ +unsigned long tx_disable_flags_prev = cl_hw->tx_disable_flags; + +if (enable) { +clear_bit (reason, &cl_hw->tx_disable_flags); + +if (tx_disable_flags_prev !=0 && cl_hw->tx_disable_flags ==0 ) +if (cl_hw->conf->ci_backup_bcn_en) +cl_msg_tx_backup_bcn_en (cl_hw, true); + }else { +set_bit (reason, &cl_hw->tx_disable_flags); + +if (tx_disable_flags_prev ==0 ) +if (cl_hw->conf->ci_backup_bcn_en) +cl_msg_tx_backup_bcn_en (cl_hw, false); + } +} + +static void cl_tx_flush (struct cl_hw *cl_hw) +{ +/* Flush bcmc */ +spin_lock_bh (&cl_hw->tx_lock_bcmc); +cl_bcmc_cfm_flush_queue (cl_hw,NULL ); +spin_unlock_bh (&cl_hw->tx_lock_bcmc); + +/* Flush single */ +spin_lock_bh (&cl_hw->tx_lock_single); +cl_txq_flush_all_single (cl_hw); +cl_single_cfm_flush_all (cl_hw); +spin_unlock_bh (&cl_hw->tx_lock_single); + +/* Flush agg */ +spin_lock_bh (&cl_hw->tx_lock_agg); +cl_txq_flush_all_agg (cl_hw); +cl_agg_cfm_flush_all (cl_hw); +spin_unlock_bh (&cl_hw->tx_lock_agg); +} + +void cl_tx_off (struct cl_hw *cl_hw) +{ +cl_txq_stop (cl_hw); +cl_tx_flush (cl_hw); +} + +void cl_tx_drop_skb (struct sk_buff *skb) +{ + skb->dev->stats.rx_dropped++; +kfree_skb (skb); +} + +#define AGG_POLL_TIMEOUT 50 + +/* +* cl_hw->agg_cfm_queues: +* These queues are used to keep pointers to skb's sent +* as aggregation and waiting for confirmation. +*/ + +void cl_agg_cfm_init (struct cl_hw *cl_hw) +{ +int i =0 ; + +for (i =0 ; i <IPC_MAX_BA_SESSIONS ; i++) +INIT_LIST_HEAD (&cl_hw->agg_cfm_queues[i].head); +} + +void cl_agg_cfm_add (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr,u8 agg_idx) +{ +spin_lock (&cl_hw->tx_lock_cfm_agg); +list_add_tail (&sw_txhdr->cfm_list, &cl_hw->agg_cfm_queues[agg_idx].head); +spin_unlock (&cl_hw->tx_lock_cfm_agg); +} + +static void cl_agg_cfm_amsdu_free (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +struct cl_amsdu_txhdr *amsdu_txhdr =NULL ; +struct cl_amsdu_txhdr *tmp =NULL ; +struct sk_buff *sub_skb =NULL ; +struct ieee80211_tx_info *tx_info_sub_skb =NULL ; + +list_for_each_entry_safe (amsdu_txhdr, tmp, &sw_txhdr->amsdu_txhdr.list, list) { + sub_skb = amsdu_txhdr->skb; + tx_info_sub_skb =IEEE80211_SKB_CB (sub_skb); + +list_del (&amsdu_txhdr->list); +dma_unmap_single (cl_hw->chip->dev, amsdu_txhdr->dma_addr, + (size_t )sub_skb->len,DMA_TO_DEVICE ); +kfree_skb (sub_skb); +cl_tx_amsdu_txhdr_free (cl_hw, amsdu_txhdr); + } +} + +void cl_agg_cfm_free_head_skb (struct cl_hw *cl_hw, +struct cl_agg_cfm_queue *cfm_queue, +u8 ba_queue_idx) +{ +struct cl_sw_txhdr *sw_txhdr =list_first_entry (&cfm_queue->head, + struct cl_sw_txhdr, + cfm_list); +struct sk_buff *skb = sw_txhdr->skb; +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +dma_addr_t dma_addr =le32_to_cpu (sw_txhdr->txdesc.umacdesc.packet_addr[0 ]); + +if (cl_hw->conf->ci_tx_delay_tstamp_en) +cl_tx_update_hist_tstamp (cfm_queue->tx_queue, skb, + cfm_queue->tx_queue->hist_push_to_cfm, false); + +dma_unmap_single (cl_hw->chip->dev, dma_addr, sw_txhdr->map_len,DMA_TO_DEVICE ); + +/* If amsdu list not empty free sub MSDU frames first, including amsdu_txhdr */ +if (cl_tx_ctrl_is_amsdu (tx_info)) +if (!list_empty (&sw_txhdr->amsdu_txhdr.list)) +cl_agg_cfm_amsdu_free (cl_hw, sw_txhdr); + +consume_skb (skb); +list_del (&sw_txhdr->cfm_list); +cl_sw_txhdr_free (cl_hw, sw_txhdr); +} + +static void cl_agg_cfm_flush_queue (struct cl_hw *cl_hw,u8 agg_idx) +{ +struct cl_agg_cfm_queue *cfm_queue = &cl_hw->agg_cfm_queues[agg_idx]; +struct cl_tx_queue *tx_queue = cfm_queue->tx_queue; +struct sk_buff *skb =NULL ; +struct cl_sw_txhdr *sw_txhdr =NULL ; +dma_addr_t dma_addr =0 ; +struct ieee80211_tx_info *tx_info; + +if (!tx_queue) +return ; + +if (list_empty (&cfm_queue->head)) +return ; + +do { + sw_txhdr = list_first_entry(&cfm_queue->head, struct cl_sw_txhdr, cfm_list); + skb = sw_txhdr->skb; + + dma_addr =le32_to_cpu (sw_txhdr->txdesc.umacdesc.packet_addr[0 ]); +dma_unmap_single (cl_hw->chip->dev, dma_addr, sw_txhdr->map_len,DMA_TO_DEVICE ); + + tx_info =IEEE80211_SKB_CB (skb); + +/* If amsdu list not empty free sub MSDU frames first, including amsdu_txhdr */ +if (cl_tx_ctrl_is_amsdu (tx_info)) +if (!list_empty (&sw_txhdr->amsdu_txhdr.list)) +cl_agg_cfm_amsdu_free (cl_hw, sw_txhdr); + + tx_queue->total_fw_cfm++; + +kfree_skb (skb); +list_del (&sw_txhdr->cfm_list); +cl_sw_txhdr_free (cl_hw, sw_txhdr); + }while (!list_empty (&cfm_queue->head)); + +/* +* Set fw_free_space back to maximum after flushing the queue +* and clear the enhanced TIM. +*/ + tx_queue->fw_free_space = tx_queue->fw_max_size; +cl_enhanced_tim_clear_tx_agg (cl_hw, agg_idx, tx_queue->hw_index, + tx_queue->cl_sta, tx_queue->tid); + + cfm_queue->tx_queue =NULL ; +} + +void cl_agg_cfm_flush_all (struct cl_hw *cl_hw) +{ +int i =0 ; + +/* Don't use BH lock, because cl_agg_cfm_flush_all() is called with BH disabled */ +spin_lock (&cl_hw->tx_lock_cfm_agg); + +for (i =0 ; i <IPC_MAX_BA_SESSIONS ; i++) +cl_agg_cfm_flush_queue (cl_hw, i); + +spin_unlock (&cl_hw->tx_lock_cfm_agg); +} + +static void cl_agg_cfm_poll_timeout (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue, +u8 agg_idx,bool flush) +{ +/* +* When polling failed clear the enhanced TIM so that firmware will +* not try to transmit these packets. +* If flush is set cl_enhanced_tim_clear_tx_agg() is called inside +* cl_agg_cfm_flush_queue(). +*/ +cl_dbg_err (cl_hw,"Polling timeout (queue_idx = %u)\n" , agg_idx); + +spin_lock_bh (&cl_hw->tx_lock_cfm_agg); + +if (flush) +cl_agg_cfm_flush_queue (cl_hw, agg_idx); +else +cl_enhanced_tim_clear_tx_agg (cl_hw, agg_idx, tx_queue->hw_index, + tx_queue->cl_sta, tx_queue->tid); + +spin_unlock_bh (&cl_hw->tx_lock_cfm_agg); +} + +void cl_agg_cfm_poll_empty (struct cl_hw *cl_hw,u8 agg_idx,bool flush) +{ +struct cl_agg_cfm_queue *cfm_queue = &cl_hw->agg_cfm_queues[agg_idx]; +bool empty = false; +int i =0 ; + +if (test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags)) +return ; + +while (true) { +spin_lock_bh (&cl_hw->tx_lock_cfm_agg); + empty =list_empty (&cfm_queue->head); +spin_unlock_bh (&cl_hw->tx_lock_cfm_agg); + +if (empty) +return ; + +if (++i ==AGG_POLL_TIMEOUT ) { +cl_agg_cfm_poll_timeout (cl_hw, cfm_queue->tx_queue, agg_idx, flush); +return ; + } + +msleep (20 ); + } +} + +void cl_agg_cfm_poll_empty_sta (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +int i =0 ; +struct cl_tx_queue *tx_queue =NULL ; + +for (i =0 ; i <IEEE80211_NUM_TIDS ; i++) { + tx_queue = cl_sta->agg_tx_queues[i]; + +if (tx_queue) +cl_agg_cfm_poll_empty (cl_hw, tx_queue->index, false); + } +} + +void cl_agg_cfm_clear_tim_bit_sta (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +int i =0 ; +struct cl_tx_queue *tx_queue =NULL ; + +for (i =0 ; i <IEEE80211_NUM_TIDS ; i++) { + tx_queue = cl_sta->agg_tx_queues[i]; + +if (tx_queue) { +spin_lock_bh (&cl_hw->tx_lock_agg); +cl_enhanced_tim_clear_tx_agg (cl_hw, tx_queue->index, tx_queue->hw_index, + tx_queue->cl_sta, tx_queue->tid); +spin_unlock_bh (&cl_hw->tx_lock_agg); + } + } +} + +void cl_agg_cfm_set_ssn (struct cl_hw *cl_hw,u16 ssn,u8 idx) +{ +spin_lock_bh (&cl_hw->tx_lock_cfm_agg); + cl_hw->agg_cfm_queues[idx].ssn = ssn; +spin_unlock_bh (&cl_hw->tx_lock_cfm_agg); +} + +void cl_agg_cfm_set_tx_queue (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue,u8 idx) +{ +spin_lock_bh (&cl_hw->tx_lock_cfm_agg); + cl_hw->agg_cfm_queues[idx].tx_queue = tx_queue; +spin_unlock_bh (&cl_hw->tx_lock_cfm_agg); +} + +static bool cl_is_same_rate (struct cl_agg_tx_report *agg_report, +struct cl_wrs_rate_params *rate_params) +{ +union cl_rate_ctrl_info rate_ctrl_info = { + .word =le32_to_cpu (agg_report->rate_cntrl_info)}; +u8 mcs =U8_MAX , nss =U8_MAX ; + +if (agg_report->bw_requested != rate_params->bw) +return false; + +cl_rate_ctrl_parse (&rate_ctrl_info, &nss, &mcs); + +return ((mcs == rate_params->mcs) && (nss == rate_params->nss)); +} + +static void cl_sync_tx_rate (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report, +struct cl_wrs_info *wrs_info,struct cl_wrs_params *wrs_params) +{ +if (!agg_report->is_fallback &&cl_is_same_rate (agg_report, &wrs_params->rate_params)) { +cl_wrs_api_rate_sync (cl_hw, cl_sta, wrs_params); + + wrs_info->synced = true; + wrs_info->quick_rate_check = true; + wrs_info->quick_rate_agg_cntr =0 ; + wrs_info->quick_rate_pkt_cntr =0 ; + }else { + wrs_info->sync_attempts++; + } +} + +static void cl_ba_not_received_handler (struct cl_hw *cl_hw,struct cl_wrs_info *wrs_info, +struct cl_agg_tx_report *agg_report) +{ +/* Ignore 'BA not received' if station is in power-save or if RTS limit was reached */ +if (agg_report->is_sta_ps || agg_report->is_rts_retry_limit_reached) +return ; + +/* Count number of consecutive 'BA not received' */ + wrs_info->ba_not_rcv_consecutive++; + +/* Save longest sequence of consecutive 'BA not received' */ +if (wrs_info->ba_not_rcv_consecutive > wrs_info->ba_not_rcv_consecutive_max) + wrs_info->ba_not_rcv_consecutive_max = wrs_info->ba_not_rcv_consecutive; + +if (cl_hw->wrs_db.ba_not_rcv_collision_filter) { +/* +* First 'BA not received' - might just be a collision. +* Don't add fail to ba_not_rcv but keep aside. +* Second consecutive 'BA not received' - not likely to be a collisions. +* Add fail to ba_not_rcv including previous fail that was kept aside. +* More than two consecutive 'BA not received' - very unlikely to be a collisions. +* Add fail to ba_not_rcv. +*/ +if (wrs_info->ba_not_rcv_consecutive ==1 ) + wrs_info->fail_prev = agg_report->fail; +else if (wrs_info->ba_not_rcv_consecutive ==2 ) + wrs_info->ba_not_rcv += (agg_report->fail + wrs_info->fail_prev); +else + wrs_info->ba_not_rcv += agg_report->fail; + }else { + wrs_info->ba_not_rcv += agg_report->fail; + } +} + +void cl_agg_tx_report_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report) +{ +struct cl_wrs_info *wrs_info =NULL ; +struct cl_wrs_params *wrs_params =NULL ; +u8 group_id; +bool skip_epr_update = false; +union cl_rate_ctrl_info rate_ctrl_info = { + .word =le32_to_cpu (agg_report->rate_cntrl_info)}; + + wrs_params = &cl_sta->wrs_sta.tx_su_params; + wrs_info = &cl_sta->wrs_info_tx_su; + group_id =0 ; + +/* Retry_count for cl_wlan */ + cl_sta->retry_count += agg_report->success_after_retry; + +/* +* In case of big packets (4300 in VHT and 5400 in HE) and low +* rate (BW 20, NSS 1, MCS 0), firmware will increase rate to MCS 1, +* and give an indication to driver (set rate_fix_mcs1 in cl_agg_tx_report). +* WRS should also move to MCS 1, and give the maximum time +* penalty time from MCS 0 toMCS 1. +*/ +if (agg_report->rate_fix_mcs1 && + !agg_report->is_fallback && +cl_wrs_api_up_mcs1 (cl_hw, cl_sta, wrs_params)) +return ; + +/* WRS sync mechanism */ +if (!wrs_info->synced) +cl_sync_tx_rate (cl_hw, cl_sta, agg_report, wrs_info, wrs_params); + +if (agg_report->bf && cl_sta->bf_db.is_on && !cl_sta->bf_db.synced) { + cl_sta->bf_db.synced = true; +/* Resetting the WRS UP weights */ +cl_wrs_api_beamforming_sync (cl_hw, cl_sta); + } + +if (agg_report->ba_not_received) { +cl_ba_not_received_handler (cl_hw, wrs_info, agg_report); + }else { +if (!skip_epr_update) + wrs_info->fail += agg_report->fail; + + wrs_info->ba_not_rcv_consecutive =0 ; + } + +if (!skip_epr_update) { +u8 mcs =0 , nss =0 , bw =0 ; +u16 data_rate =0 ; + +switch (agg_report->bw_requested) { +case CHNL_BW_160 : + bw = (cl_hw->wrs_db.adjacent_interference20 || + cl_hw->wrs_db.adjacent_interference40 || + cl_hw->wrs_db.adjacent_interference80) ? + rate_ctrl_info.field.bw : agg_report->bw_requested; +break ; +case CHNL_BW_80 : + bw = (cl_hw->wrs_db.adjacent_interference20 || + cl_hw->wrs_db.adjacent_interference40) ? + rate_ctrl_info.field.bw : agg_report->bw_requested; +break ; +case CHNL_BW_40 : + bw = cl_hw->wrs_db.adjacent_interference20 ? + rate_ctrl_info.field.bw : agg_report->bw_requested; +break ; +case CHNL_BW_20 : + bw = agg_report->bw_requested; +break ; + } + +cl_rate_ctrl_parse (&rate_ctrl_info, &nss, &mcs); + + data_rate =cl_data_rates_get_x10 (rate_ctrl_info.field.format_mod, + bw, + nss, + mcs, + rate_ctrl_info.field.gi); + + wrs_info->epr_acc += ((u64 )agg_report->success * data_rate); + wrs_info->success += agg_report->success; + } + +if (cl_hw->wrs_db.quick_down_en && + wrs_info->quick_rate_check && +cl_is_same_rate (agg_report, &wrs_params->rate_params)) { + wrs_info->quick_rate_agg_cntr++; + wrs_info->quick_rate_pkt_cntr += (agg_report->success + agg_report->fail); + +if (wrs_info->quick_rate_agg_cntr >= cl_hw->wrs_db.quick_down_agg_thr && + wrs_info->quick_rate_pkt_cntr > cl_hw->wrs_db.quick_down_pkt_thr) { + wrs_info->quick_rate_check = false; +cl_wrs_api_quick_down_check (cl_hw, cl_sta, wrs_params); + } + } +} + +void cl_agg_tx_report_simulate_for_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_hw_tx_status *status) +{ +/* Assign statistics struct */ +struct cl_agg_tx_report agg_report; +union cl_rate_ctrl_info rate_ctrl_info; + +memset (&agg_report,0 ,sizeof (struct cl_agg_tx_report )); + + agg_report.bf = status->bf; + agg_report.success = status->frm_successful; + agg_report.fail = status->num_mpdu_retries + (status->frm_successful ?0 :1 ); + agg_report.success_after_retry = + (status->frm_successful && status->num_mpdu_retries); + agg_report.retry_limit_reached = !status->frm_successful; + agg_report.success_more_one_retry = + (status->frm_successful && (status->num_mpdu_retries >1 )); + agg_report.sta_idx = cl_sta->sta_idx; + agg_report.bw_requested = status->bw_requested; + + rate_ctrl_info.field.bw = status->bw_transmitted; + rate_ctrl_info.field.gi = status->gi; + rate_ctrl_info.field.format_mod = status->format_mod; + rate_ctrl_info.field.mcs_index = status->mcs_index; + +cl_rate_ctrl_convert (&rate_ctrl_info); + + agg_report.rate_cntrl_info =cpu_to_le32 (rate_ctrl_info.word); +cl_agg_tx_report_handler (cl_hw, cl_sta, &agg_report); +cl_stats_update_tx_single (cl_hw, cl_sta, &agg_report); +} + +void cl_baw_init (struct cl_sta *cl_sta) +{ +u8 tid; + +for (tid =0 ; tid <IEEE80211_NUM_TIDS ; tid++) +__skb_queue_head_init (&cl_sta->baws[tid].pending); +} + +void cl_baw_start (struct cl_baw *baw,u16 ssn) +{ + baw->ssn = ssn; + baw->action_start = true; +} + +void cl_baw_operational (struct cl_hw *cl_hw,struct cl_baw *baw, +u8 fw_agg_idx,bool amsdu_supported) +{ + baw->fw_agg_idx = fw_agg_idx; + baw->tid_seq =IEEE80211_SN_TO_SEQ (baw->ssn); + baw->action_start = false; + baw->amsdu = (cl_hw->txamsdu_en && amsdu_supported); +} + +void cl_baw_stop (struct cl_baw *baw) +{ + baw->action_start = false; +} + +void cl_baw_pending_to_agg (struct cl_hw *cl_hw, +struct cl_sta *cl_sta, +u8 tid) +{ +struct cl_baw *baw = &cl_sta->baws[tid]; +struct sk_buff *skb; + +while (!skb_queue_empty (&baw->pending)) { + skb =__skb_dequeue (&baw->pending); +cl_tx_fast_agg (cl_hw, cl_sta, skb, false); + } +} + +void cl_baw_pending_to_single (struct cl_hw *cl_hw, +struct cl_sta *cl_sta, +struct cl_baw *baw) +{ +struct sk_buff *skb; + +while (!skb_queue_empty (&baw->pending)) { + skb =__skb_dequeue (&baw->pending); +cl_tx_fast_single (cl_hw, cl_sta, skb, false); + } +} + +void cl_baw_pending_purge (struct cl_baw *baw) +{ +if (!skb_queue_empty (&baw->pending)) +__skb_queue_purge (&baw->pending); +} + +/* +* cl_hw->bcmc_cfm_queue: +* This queue is used to keep pointers to already sent +* beacon skb's that are waiting for confirmation. +*/ + +static void cl_bcmc_free_sw_txhdr (struct cl_hw *cl_hw, +struct cl_sw_txhdr *sw_txhdr) +{ +dma_addr_t dma_addr; +struct sk_buff *skb =NULL ; + + dma_addr =le32_to_cpu (sw_txhdr->txdesc.umacdesc.packet_addr[0 ]); + skb = sw_txhdr->skb; + +dma_unmap_single (cl_hw->chip->dev, dma_addr, sw_txhdr->map_len,DMA_TO_DEVICE ); +dev_kfree_skb_irq (skb); +list_del (&sw_txhdr->cfm_list); +cl_sw_txhdr_free (cl_hw, sw_txhdr); +} + +static bool cl_bcmc_is_list_empty_per_vif (struct cl_hw *cl_hw, +struct cl_vif *cl_vif) +{ +struct cl_single_cfm_queue *cfm_queue = &cl_hw->bcmc_cfm_queue; +struct cl_sw_txhdr *sw_txhdr =NULL ; + +list_for_each_entry (sw_txhdr, &cfm_queue->head, cfm_list) +if (sw_txhdr->cl_vif == cl_vif) +return false; + +return true; +} + +void cl_bcmc_cfm_init (struct cl_hw *cl_hw) +{ +INIT_LIST_HEAD (&cl_hw->bcmc_cfm_queue.head); +} + +void cl_bcmc_cfm_add (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +list_add_tail (&sw_txhdr->cfm_list, &cl_hw->bcmc_cfm_queue.head); +} + +struct cl_sw_txhdr *cl_bcmc_cfm_find (struct cl_hw *cl_hw,dma_addr_t dma_addr,bool keep_in_list) +{ +struct cl_single_cfm_queue *cfm_queue = &cl_hw->bcmc_cfm_queue; +struct cl_sw_txhdr *sw_txhdr =NULL ; +struct cl_sw_txhdr *tmp =NULL ; + +list_for_each_entry_safe (sw_txhdr, tmp, &cfm_queue->head, cfm_list) { +if (le32_to_cpu (sw_txhdr->txdesc.umacdesc.packet_addr[0 ]) == dma_addr) { +if (!keep_in_list) +list_del (&sw_txhdr->cfm_list); + +return sw_txhdr; + } + } + +return NULL ; +} + +void cl_bcmc_cfm_flush_queue (struct cl_hw *cl_hw, +struct cl_vif *cl_vif) +{ +struct cl_single_cfm_queue *cfm_queue = &cl_hw->bcmc_cfm_queue; +struct cl_sw_txhdr *sw_txhdr =NULL ; +struct cl_sw_txhdr *tmp =NULL ; + +/* Only flush the specific cl_vif related confirmations */ +if (cl_vif) { +list_for_each_entry_safe (sw_txhdr, tmp, &cfm_queue->head, cfm_list) { +if (sw_txhdr->cl_vif == cl_vif) { +cl_bcmc_free_sw_txhdr (cl_hw, sw_txhdr); + cl_hw->tx_queues->bcmc.fw_free_space++; + } + } + +return ; + } + +while (!list_empty (&cfm_queue->head)) { + sw_txhdr = list_first_entry(&cfm_queue->head, struct cl_sw_txhdr, cfm_list); +cl_bcmc_free_sw_txhdr (cl_hw, sw_txhdr); + } + +/* Set fw_free_space back to maximum after flushing the queue */ + cl_hw->tx_queues->bcmc.fw_free_space = cl_hw->tx_queues->bcmc.fw_max_size; +} + +void cl_bcmc_cfm_poll_empty_per_vif (struct cl_hw *cl_hw, +struct cl_vif *cl_vif) +{ +bool empty = false; +int i =0 ; + +if (test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags)) +return ; + +while (i++ <BCMC_POLL_TIMEOUT ) { +spin_lock_bh (&cl_hw->tx_lock_bcmc); + empty =cl_bcmc_is_list_empty_per_vif (cl_hw, cl_vif); +spin_unlock_bh (&cl_hw->tx_lock_bcmc); + +if (empty) +return ; + +msleep (20 ); + } + +cl_dbg_err (cl_hw,"Polling timeout vif_index %d\n" , cl_vif->vif_index); + +spin_lock_bh (&cl_hw->tx_lock_bcmc); +cl_bcmc_cfm_flush_queue (cl_hw, cl_vif); +spin_unlock_bh (&cl_hw->tx_lock_bcmc); +} + +/* +* cl_hw->single_cfm_queues: +* These queues are used to keep pointers to skb's sent +* as singles and waiting for confirmation. +*/ + +#define SINGLE_POLL_TIMEOUT 50 + +void cl_single_cfm_init (struct cl_hw *cl_hw) +{ +int i =0 ; + +for (i =0 ; i <MAX_SINGLE_QUEUES ; i++) +INIT_LIST_HEAD (&cl_hw->single_cfm_queues[i].head); +} + +void cl_single_cfm_add (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr,u32 queue_idx) +{ +list_add_tail (&sw_txhdr->cfm_list, &cl_hw->single_cfm_queues[queue_idx].head); +} + +struct cl_sw_txhdr *cl_single_cfm_find (struct cl_hw *cl_hw,u32 queue_idx, +dma_addr_t dma_addr) +{ +struct cl_single_cfm_queue *cfm_queue =NULL ; +struct cl_sw_txhdr *sw_txhdr =NULL ; +struct cl_sw_txhdr *tmp =NULL ; + +if (queue_idx >=MAX_SINGLE_QUEUES ) +return NULL ; + + cfm_queue = &cl_hw->single_cfm_queues[queue_idx]; + +list_for_each_entry_safe (sw_txhdr, tmp, &cfm_queue->head, cfm_list) +if (le32_to_cpu (sw_txhdr->txdesc.umacdesc.packet_addr[0 ]) == dma_addr) { +list_del (&sw_txhdr->cfm_list); + +return sw_txhdr; + } + +return NULL ; +} + +static void cl_single_cfm_flush_queue (struct cl_hw *cl_hw,u32 queue_idx) +{ +struct cl_single_cfm_queue *cfm_queue = &cl_hw->single_cfm_queues[queue_idx]; +struct cl_tx_queue *tx_queue =NULL ; +struct cl_sw_txhdr *sw_txhdr =NULL ; +struct sk_buff *skb =NULL ; +struct ieee80211_tx_info *tx_info =NULL ; +dma_addr_t dma_addr; + +if (list_empty (&cfm_queue->head)) +return ; + +do { + sw_txhdr = list_first_entry(&cfm_queue->head, struct cl_sw_txhdr, cfm_list); + dma_addr =le32_to_cpu (sw_txhdr->txdesc.umacdesc.packet_addr[0 ]); + skb = sw_txhdr->skb; + tx_info =IEEE80211_SKB_CB (skb); + +dma_unmap_single (cl_hw->chip->dev, dma_addr, sw_txhdr->map_len,DMA_TO_DEVICE ); + +cl_tx_single_free_skb (cl_hw, skb); +list_del (&sw_txhdr->cfm_list); +cl_sw_txhdr_free (cl_hw, sw_txhdr); + }while (!list_empty (&cfm_queue->head)); + +/* +* Set fw_free_space back to maximum after flushing the queue +* and clear the enhanced TIM. +*/ + tx_queue = &cl_hw->tx_queues->single[queue_idx]; + tx_queue->fw_free_space = tx_queue->fw_max_size; +cl_enhanced_tim_clear_tx_single (cl_hw, queue_idx, tx_queue->hw_index, + false, tx_queue->cl_sta, tx_queue->tid); +} + +void cl_single_cfm_flush_all (struct cl_hw *cl_hw) +{ +u32 i =0 ; + +for (i =0 ; i <MAX_SINGLE_QUEUES ; i++) +cl_single_cfm_flush_queue (cl_hw, i); +} + +void cl_single_cfm_flush_sta (struct cl_hw *cl_hw,u8 sta_idx) +{ +/* Flush all single confirmation queues of this sta, and reset write index */ +u8 ac; +u16 queue_idx; + +spin_lock_bh (&cl_hw->tx_lock_single); + +for (ac =0 ; ac <AC_MAX ; ac++) { + queue_idx =QUEUE_IDX (sta_idx, ac); +cl_single_cfm_flush_queue (cl_hw, queue_idx); + + cl_hw->ipc_env->ring_indices_elem->indices->txdesc_write_idx.single[queue_idx] =0 ; + } + +spin_unlock_bh (&cl_hw->tx_lock_single); +} + +static void cl_single_cfm_poll_timeout (struct cl_hw *cl_hw,u32 queue_idx) +{ +/* +* When polling failed clear the enhanced TIM so that firmware will +* not try to transmit these packets. +*/ +struct cl_tx_queue *tx_queue = &cl_hw->tx_queues->single[queue_idx]; + +cl_dbg_err (cl_hw,"Polling timeout (queue_idx = %u)\n" , queue_idx); + +spin_lock_bh (&cl_hw->tx_lock_single); +cl_enhanced_tim_clear_tx_single (cl_hw, queue_idx, tx_queue->hw_index, + false, tx_queue->cl_sta, tx_queue->tid); +spin_unlock_bh (&cl_hw->tx_lock_single); +} + +void cl_single_cfm_poll_empty (struct cl_hw *cl_hw,u32 queue_idx) +{ +struct cl_single_cfm_queue *cfm_queue = &cl_hw->single_cfm_queues[queue_idx]; +bool empty = false; +int i =0 ; + +if (test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags)) +return ; + +while (true) { +spin_lock_bh (&cl_hw->tx_lock_single); + empty =list_empty (&cfm_queue->head); +spin_unlock_bh (&cl_hw->tx_lock_single); + +if (empty) +return ; + +if (++i ==SINGLE_POLL_TIMEOUT ) { +cl_single_cfm_poll_timeout (cl_hw, queue_idx); +return ; + } + +msleep (20 ); + } +} + +static bool cl_list_hp_empty_sta (struct cl_hw *cl_hw,u8 sta_idx) +{ +struct cl_single_cfm_queue *hp_cfm_queue = &cl_hw->single_cfm_queues[HIGH_PRIORITY_QUEUE ]; +struct cl_sw_txhdr *sw_txhdr =NULL ; + +list_for_each_entry (sw_txhdr, &hp_cfm_queue->head, cfm_list) +if (sw_txhdr->sta_idx == sta_idx) +return false; + +return true; +} + +static void cl_single_cfm_poll_empty_hp (struct cl_hw *cl_hw,u8 sta_idx) +{ +bool empty = false; +int i =0 ; + +if (test_bit (CL_DEV_FW_ERROR , &cl_hw->drv_flags)) +return ; + +while (true) { +spin_lock_bh (&cl_hw->tx_lock_single); + empty =cl_list_hp_empty_sta (cl_hw, sta_idx); +spin_unlock_bh (&cl_hw->tx_lock_single); + +if (empty) +return ; + +if (++i ==SINGLE_POLL_TIMEOUT ) { +cl_single_cfm_poll_timeout (cl_hw,HIGH_PRIORITY_QUEUE ); +return ; + } + +msleep (20 ); + } +} + +void cl_single_cfm_poll_empty_sta (struct cl_hw *cl_hw,u8 sta_idx) +{ +/* +* Poll all single queues belonging to this station, and poll all +* packets belonging to this station in the high priority queue. +*/ +u8 ac; +u16 queue_idx; + +for (ac =0 ; ac <AC_MAX ; ac++) { + queue_idx =QUEUE_IDX (sta_idx, ac); +cl_single_cfm_poll_empty (cl_hw, queue_idx); + } + +cl_single_cfm_poll_empty_hp (cl_hw, sta_idx); +} + +void cl_single_cfm_clear_tim_bit_sta (struct cl_hw *cl_hw,u8 sta_idx) +{ +u8 ac; +u16 queue_idx; +struct cl_tx_queue *tx_queue =NULL ; + +for (ac =0 ; ac <AC_MAX ; ac++) { + queue_idx =QUEUE_IDX (sta_idx, ac); + tx_queue = &cl_hw->tx_queues->single[queue_idx]; + +spin_lock_bh (&cl_hw->tx_lock_single); +cl_enhanced_tim_clear_tx_single (cl_hw, queue_idx, tx_queue->hw_index, + false, tx_queue->cl_sta, tx_queue->tid); +spin_unlock_bh (&cl_hw->tx_lock_single); + } + + tx_queue = &cl_hw->tx_queues->single[HIGH_PRIORITY_QUEUE ]; + +spin_lock_bh (&cl_hw->tx_lock_single); +cl_enhanced_tim_clear_tx_single (cl_hw,HIGH_PRIORITY_QUEUE , tx_queue->hw_index, + false, tx_queue->cl_sta, tx_queue->tid); +spin_unlock_bh (&cl_hw->tx_lock_single); +} + +static int cl_sw_txhdr_init_pool (struct cl_hw *cl_hw,u16 sw_txhdr_pool) +{ +u16 i =0 ; +u32 sw_txhdr_pool_size = sw_txhdr_pool *sizeof (struct cl_sw_txhdr ); +struct cl_sw_txhdr *sw_txhdr; + +INIT_LIST_HEAD (&cl_hw->head_sw_txhdr_pool); +spin_lock_init (&cl_hw->lock_sw_txhdr_pool); + +for (i =0 ; i < sw_txhdr_pool; i++) { + sw_txhdr =kzalloc (sizeof (*sw_txhdr),GFP_ATOMIC ); + +if (unlikely (!sw_txhdr)) { +cl_dbg_verbose (cl_hw,"sw_txhdr NULL\n" ); +return -1 ; + } + +list_add (&sw_txhdr->list_pool, &cl_hw->head_sw_txhdr_pool); + } + +cl_dbg_verbose (cl_hw," - pool %u, size %u\n" , sw_txhdr_pool, sw_txhdr_pool_size); + +return 0 ; +} + +static int cl_sw_txhdr_init_cache (struct cl_hw *cl_hw) +{ +char sw_txhdr_cache_name[MODULE_NAME_LEN +32 ] = {0 }; + +snprintf (sw_txhdr_cache_name,sizeof (sw_txhdr_cache_name), +"%s_sw_txhdr_cache" ,THIS_MODULE ->name); + + cl_hw->sw_txhdr_cache =kmem_cache_create (sw_txhdr_cache_name, +sizeof (struct cl_sw_txhdr ), +0 , + (SLAB_HWCACHE_ALIGN |SLAB_PANIC ), +NULL ); + +if (!cl_hw->sw_txhdr_cache) { +cl_dbg_verbose (cl_hw,"sw_txhdr_cache NULL\n" ); +return -1 ; + } + +return 0 ; +} + +int cl_sw_txhdr_init (struct cl_hw *cl_hw) +{ +u16 sw_txhdr_pool = cl_hw->conf->ci_sw_txhdr_pool; + +if (sw_txhdr_pool) +return cl_sw_txhdr_init_pool (cl_hw, sw_txhdr_pool); +else +return cl_sw_txhdr_init_cache (cl_hw); +} + +static void cl_sw_txhdr_deinit_pool (struct cl_hw *cl_hw) +{ +struct cl_sw_txhdr *sw_txhdr, *tmp; + +list_for_each_entry_safe (sw_txhdr, tmp, &cl_hw->head_sw_txhdr_pool, list_pool) { +list_del (&sw_txhdr->list_pool); +kfree (sw_txhdr); + } +} + +static void cl_sw_txhdr_deinit_cache (struct cl_hw *cl_hw) +{ +kmem_cache_destroy (cl_hw->sw_txhdr_cache); +} + +void cl_sw_txhdr_deinit (struct cl_hw *cl_hw) +{ +if (cl_hw->conf->ci_sw_txhdr_pool) +cl_sw_txhdr_deinit_pool (cl_hw); +else +cl_sw_txhdr_deinit_cache (cl_hw); +} + +static inline struct cl_sw_txhdr *cl_sw_txhdr_alloc_pool (struct cl_hw *cl_hw) +{ +struct cl_sw_txhdr *sw_txhdr =NULL ; + +spin_lock_bh (&cl_hw->lock_sw_txhdr_pool); + sw_txhdr =list_first_entry_or_null (&cl_hw->head_sw_txhdr_pool, + struct cl_sw_txhdr, list_pool); + +if (sw_txhdr) { +list_del (&sw_txhdr->list_pool); +spin_unlock_bh (&cl_hw->lock_sw_txhdr_pool); +return sw_txhdr; + } + +spin_unlock_bh (&cl_hw->lock_sw_txhdr_pool); +return NULL ; +} + +static inline struct cl_sw_txhdr *cl_sw_txhdr_alloc_cache (struct cl_hw *cl_hw) +{ +return kmem_cache_alloc (cl_hw->sw_txhdr_cache,GFP_ATOMIC ); +} + +struct cl_sw_txhdr *cl_sw_txhdr_alloc (struct cl_hw *cl_hw) +{ +if (cl_hw->conf->ci_sw_txhdr_pool) +return cl_sw_txhdr_alloc_pool (cl_hw); +else +return cl_sw_txhdr_alloc_cache (cl_hw); +} + +static inline void cl_sw_txhdr_free_pool (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +spin_lock_bh (&cl_hw->lock_sw_txhdr_pool); +list_add_tail (&sw_txhdr->list_pool, &cl_hw->head_sw_txhdr_pool); +spin_unlock_bh (&cl_hw->lock_sw_txhdr_pool); +} + +static inline void cl_sw_txhdr_free_cache (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +kmem_cache_free (cl_hw->sw_txhdr_cache, sw_txhdr); +} + +void cl_sw_txhdr_free (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +if (cl_hw->conf->ci_sw_txhdr_pool) +cl_sw_txhdr_free_pool (cl_hw, sw_txhdr); +else +cl_sw_txhdr_free_cache (cl_hw, sw_txhdr); +} + +#define CL_AMSDU_HDR_LEN 14 + +static bool cl_tx_amsdu_is_sw (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,u16 pkt_len) +{ +bool syn_rst_push = false; +bool tcp_ack = false; + +if (cl_hw->conf->ci_tx_sw_amsdu_max_packets <=1 ) +return false; + + tcp_ack =cl_is_tcp_ack (skb, &syn_rst_push); + +if (!tcp_ack || syn_rst_push) +return false; + +if ((cl_wrs_api_get_tx_sta_data_rate (cl_sta) * cl_sta->ampdu_min_spacing) <= + (pkt_len <<3 )) +return false; + +return true; +} + +static int cl_tx_amsdu_anchor_set (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,u8 tid) +{ +/* +* Packet length calculation in HW - +* Add 802.11 header (maximum possible size) instead if 802.3 +* Add AMSDU header +* Add RFC1042 header (according to ether-type) +* Add IV and ICV (if there is encryption) +*/ +struct cl_amsdu_ctrl *amsdu_anchor = &cl_sta->amsdu_anchor[tid]; +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (skb); +struct ieee80211_key_conf *key_conf = tx_info->control.hw_key; +u16 ethertype = (skb->data[12 ] <<8 ) | skb->data[13 ]; +u16 pkt_len = skb->len +CL_WLAN_HEADER_MAX_SIZE ; + +if (key_conf) + pkt_len += (key_conf->iv_len + key_conf->icv_len); + +if (ethertype >=ETH_P_802_3_MIN ) + pkt_len +=sizeof (rfc1042_header); + + amsdu_anchor->rem_len = amsdu_anchor->max_len - pkt_len; + amsdu_anchor->packet_cnt =1 ; + amsdu_anchor->is_sw_amsdu =cl_tx_amsdu_is_sw (cl_hw, cl_sta, skb, pkt_len); + +return CL_AMSDU_ANCHOR_SET ; +} + +static void cl_tx_amsdu_anchor_umacdesc_update (struct txdesc *txdesc,u8 idx, +u16 len,dma_addr_t dma_addr, +bool is_padding) +{ +struct lmacapi *umacdesc = &txdesc->umacdesc; + + umacdesc->packet_len[idx] =cpu_to_le16 (len); + umacdesc->packet_addr[idx] =cpu_to_le32 (dma_addr); + txdesc->host_info.packet_cnt++; + +/* Update padding bit of current msdu sub-frame */ +if (is_padding) + txdesc->host_info.host_padding |=BIT (idx); +} + +static struct cl_amsdu_txhdr *cl_tx_amsdu_txhdr_alloc (struct cl_hw *cl_hw) +{ +if (cl_hw->conf->ci_amsdu_txhdr_pool) { +struct cl_amsdu_txhdr *amsdu_txhdr = +list_first_entry_or_null (&cl_hw->head_amsdu_txhdr_pool, + struct cl_amsdu_txhdr, + list_pool); + +if (amsdu_txhdr) { +list_del (&amsdu_txhdr->list_pool); +return amsdu_txhdr; + } + +return NULL ; + }else { +return kmem_cache_alloc (cl_hw->amsdu_txhdr_cache,GFP_ATOMIC ); + } +} + +static void _cl_tx_amsdu_transfer_single (struct cl_hw *cl_hw, +struct sk_buff *skb, +struct cl_sta *cl_sta, +u8 tid) +{ +struct ieee80211_tx_info *tx_info; + + tx_info =IEEE80211_SKB_CB (skb); + tx_info->flags &= ~IEEE80211_TX_CTL_AMPDU ; + tx_info->control.flags &= ~IEEE80211_TX_CTRL_AMSDU ; + +if (cl_tx_8023_to_wlan (cl_hw, skb, cl_sta, tid) ==0 ) { + cl_hw->tx_packet_cntr.transfer.agg_to_single++; +cl_tx_single (cl_hw, cl_sta, skb, false, false); + } +} + +static void cl_tx_amsdu_set_sw_sub_amsdu_hdr (struct sk_buff *skb) +{ +u16 ethertype = (skb->data[12 ] <<8 ) | skb->data[13 ]; +int rfc1042_len =0 ; +void *data; +struct ethhdr *amsdu_hdr; + +if (ethertype >=ETH_P_802_3_MIN ) + rfc1042_len =sizeof (rfc1042_header); + + data =skb_push (skb, rfc1042_len +2 ); +memmove (data, data + rfc1042_len +2 ,2 *ETH_ALEN ); + + amsdu_hdr = (struct ethhdr *)data; + amsdu_hdr->h_proto =cpu_to_be16 (skb->len -ETH_HLEN ); + +memcpy (data +ETH_HLEN , rfc1042_header, rfc1042_len); +} + +static int cl_tx_amsdu_add_sw_amsdu_hdr (struct cl_hw *cl_hw, +struct cl_amsdu_ctrl *amsdu_anchor) +{ +struct cl_sw_txhdr *anchor_sw_txhdr = amsdu_anchor->sw_txhdr; +struct sk_buff *skb = anchor_sw_txhdr->skb; +struct cl_sta *cl_sta = anchor_sw_txhdr->cl_sta; +struct ieee80211_hdr hdr; +u16 ethertype = (skb->data[12 ] <<8 ) | skb->data[13 ]; +u16 hdrlen =cl_tx_prepare_wlan_hdr (cl_hw, cl_sta, skb, &hdr); +int rfc1042_len =0 ; +int head_need =0 ; +u8 enc_len =cl_key_get_cipher_len (skb); +u16 qos_ctrl = anchor_sw_txhdr->tid |IEEE80211_QOS_CTL_A_MSDU_PRESENT ; + +if (!hdrlen) +return -EINVAL ; + +if (ethertype >=ETH_P_802_3_MIN ) + rfc1042_len =sizeof (rfc1042_header); + + amsdu_anchor->hdrlen = hdrlen; + head_need = hdrlen + enc_len + rfc1042_len -skb_headroom (skb); +if (head_need >0 ) { + head_need = ((head_need +3 ) & ~3 ); +if (pskb_expand_head (skb, head_need,0 ,GFP_ATOMIC )) +return -ENOMEM ; + } + +cl_tx_amsdu_set_sw_sub_amsdu_hdr (skb); + +skb_push (skb, hdrlen + enc_len); +memcpy (skb->data, &hdr, hdrlen -2 ); +memcpy (skb->data + hdrlen -2 , &qos_ctrl,2 ); +skb_reset_mac_header (skb); + anchor_sw_txhdr->txdesc.e2w_natt_param.hdr_conv_enable = false; + anchor_sw_txhdr->hdr80211 = (struct ieee80211_hdr *)skb->data; + +return 0 ; +} + +static int cl_tx_amsdu_sw_aggregate (struct cl_hw *cl_hw, +struct cl_amsdu_ctrl *amsdu_anchor, +struct sk_buff *skb) +{ +struct cl_sw_txhdr *anchor_sw_txhdr = amsdu_anchor->sw_txhdr; +struct sk_buff *anchor_skb = anchor_sw_txhdr->skb; +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (anchor_skb); +struct ieee80211_key_conf *key_conf = tx_info->control.hw_key; +u16 total_frame_len =0 ; +struct cl_tx_queue *tx_queue = anchor_sw_txhdr->tx_queue; +int head_pad =0 ; +int sub_pad =0 ; +bool syn_rst_push = false; +bool tcp_ack =cl_is_tcp_ack (skb, &syn_rst_push); + +/* Worst case: rfc1042(6) + ET(2) + pad(2) = 10 */ +if (!tcp_ack || + (skb_tailroom (anchor_skb) < (skb->len +10 ))) { +if (tx_queue->num_packets ==1 ) +cl_txq_sched (cl_hw, tx_queue); +cl_tx_amsdu_anchor_init (amsdu_anchor); +return cl_tx_amsdu_anchor_set (cl_hw, anchor_sw_txhdr->cl_sta, + skb, anchor_sw_txhdr->tid); + } + +if (amsdu_anchor->packet_cnt ==1 && +cl_tx_amsdu_add_sw_amsdu_hdr (cl_hw, amsdu_anchor)) +return CL_AMSDU_FAILED ; + +cl_tx_amsdu_set_sw_sub_amsdu_hdr (skb); + sub_pad =CL_SKB_DATA_ALIGN_PADS (anchor_skb->len - + amsdu_anchor->hdrlen); +memset (skb_push (skb, sub_pad),0 , sub_pad); +memcpy (skb_put (anchor_skb, skb->len), skb->data, skb->len); + +kfree_skb (skb); + amsdu_anchor->packet_cnt++; + anchor_sw_txhdr->sw_amsdu_packet_cnt++; + head_pad =CL_SKB_DATA_ALIGN_PADS (anchor_skb->data); + +if (head_pad) { + anchor_sw_txhdr->map_len = anchor_skb->len + head_pad; + anchor_sw_txhdr->txdesc.host_info.host_padding |=BIT (0 ); + }else { + anchor_sw_txhdr->map_len = anchor_skb->len; + anchor_sw_txhdr->txdesc.host_info.host_padding =0 ; + } + + total_frame_len = anchor_skb->len; +if (key_conf) + total_frame_len += key_conf->icv_len; + + anchor_sw_txhdr->txdesc.umacdesc.packet_len[0 ] =cpu_to_le16 (total_frame_len); + +if (amsdu_anchor->packet_cnt == cl_hw->conf->ci_tx_sw_amsdu_max_packets || + syn_rst_push) { +if (tx_queue->num_packets ==1 ) +cl_txq_sched (cl_hw, tx_queue); +cl_tx_amsdu_anchor_init (amsdu_anchor); + } + +return CL_AMSDU_SUB_FRAME_SET ; +} + +void cl_tx_amsdu_anchor_init (struct cl_amsdu_ctrl *amsdu_anchor) +{ + amsdu_anchor->rem_len = amsdu_anchor->max_len; + amsdu_anchor->sw_txhdr =NULL ; + amsdu_anchor->packet_cnt =0 ; + amsdu_anchor->is_sw_amsdu = false; +} + +void cl_tx_amsdu_anchor_reset (struct cl_amsdu_ctrl *amsdu_anchor) +{ + amsdu_anchor->sw_txhdr =NULL ; + amsdu_anchor->rem_len =0 ; + amsdu_anchor->max_len =0 ; + amsdu_anchor->packet_cnt =0 ; + amsdu_anchor->is_sw_amsdu = false; +} + +void cl_tx_amsdu_set_max_len (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u8 tid) +{ +struct ieee80211_sta_vht_cap *vht_cap = &cl_sta->sta->vht_cap; +struct cl_amsdu_ctrl *amsdu_anchor = &cl_sta->amsdu_anchor[tid]; +u32 length =U32_MAX ; + + amsdu_anchor->max_len =3839 ; + +if (cl_band_is_6g (cl_hw)) { +u16 capa =le16_to_cpu (cl_sta->sta->he_6ghz_capa.capa); + + length = (capa &IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN ) >> +HE_6GHZ_CAP_MAX_MPDU_LEN_OFFSET ; + }else if (vht_cap->vht_supported) { + length = vht_cap->cap &IEEE80211_VHT_CAP_MAX_MPDU_MASK ; + } + +switch (length) { +case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 : + amsdu_anchor->max_len =3895 ; +break ; +case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 : + amsdu_anchor->max_len =7991 ; +break ; +case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 : + amsdu_anchor->max_len =11454 ; +break ; +default : +break ; + } + + amsdu_anchor->rem_len = amsdu_anchor->max_len; + +cl_dbg_trace (cl_hw,"AMSDU supported - sta_idx=%u, max_len=%d\n" , + cl_sta->sta_idx, amsdu_anchor->max_len); +} + +void cl_tx_amsdu_first_sub_frame (struct cl_sw_txhdr *sw_txhdr,struct cl_sta *cl_sta, +struct sk_buff *skb,u8 tid) +{ +/* Set the anchor sw_txhdr */ + cl_sta->amsdu_anchor[tid].sw_txhdr = sw_txhdr; + +INIT_LIST_HEAD (&sw_txhdr->amsdu_txhdr.list); + sw_txhdr->amsdu_txhdr.skb = skb; +} + +void cl_tx_amsdu_flush_sub_frames (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +struct cl_amsdu_txhdr *amsdu_txhdr =NULL , *tmp =NULL ; +struct sk_buff *sub_skb =NULL ; + +/* Free mid & last AMSDU sub frames */ +list_for_each_entry_safe (amsdu_txhdr, tmp, &sw_txhdr->amsdu_txhdr.list, list) { + sub_skb = amsdu_txhdr->skb; +list_del (&amsdu_txhdr->list); + +dma_unmap_single (cl_hw->chip->dev, amsdu_txhdr->dma_addr, + (size_t )sub_skb->len,DMA_TO_DEVICE ); +kfree_skb (sub_skb); +cl_tx_amsdu_txhdr_free (cl_hw, amsdu_txhdr); + cl_hw->tx_packet_cntr.drop.queue_flush++; + sw_txhdr->cl_vif->trfc_cntrs[sw_txhdr->ac].tx_dropped++; + } + +/* Free first AMSDU sub frame */ +kfree_skb (sw_txhdr->skb); +cl_sw_txhdr_free (cl_hw, sw_txhdr); +} + +void cl_tx_amsdu_transfer_single (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +/* +* Transfer all skbs in sw_txhdr to a temporary list, free sw_txhdr, +* and then push the temporary list to the single path. +*/ +struct cl_amsdu_txhdr *amsdu_txhdr, *tmp; +struct sk_buff *skb; +struct cl_sta *cl_sta = sw_txhdr->cl_sta; +u8 tid = sw_txhdr->tid; + +/* Transfer first AMSDU sub frame */ +_cl_tx_amsdu_transfer_single (cl_hw, sw_txhdr->skb, cl_sta, tid); + +/* Transfer mid & last AMSDU sub frames */ +list_for_each_entry_safe (amsdu_txhdr, tmp, &sw_txhdr->amsdu_txhdr.list, list) { + skb = amsdu_txhdr->skb; + +list_del (&amsdu_txhdr->list); +dma_unmap_single (cl_hw->chip->dev, amsdu_txhdr->dma_addr, + (size_t )skb->len,DMA_TO_DEVICE ); +cl_tx_amsdu_txhdr_free (cl_hw, amsdu_txhdr); + +_cl_tx_amsdu_transfer_single (cl_hw, skb, cl_sta, tid); + } +} + +int cl_tx_amsdu_set (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct sk_buff *skb,u8 tid) +{ +struct cl_amsdu_ctrl *amsdu_anchor = &cl_sta->amsdu_anchor[tid]; +struct cl_sw_txhdr *anchor_sw_txhdr = amsdu_anchor->sw_txhdr; +u16 packet_len = skb->len; +u8 packet_cnt; +bool is_mesh =ieee80211_vif_is_mesh (cl_sta->cl_vif->vif); +u8 packet_cnt_max = cl_hw->txamsdu_en; + +/* Check if anchor exist */ +if (!anchor_sw_txhdr) { +/* Sanity check - skb len < amsdu_max_len */ +if (unlikely (packet_len > amsdu_anchor->max_len) || is_mesh) +return CL_AMSDU_SKIP ; +else +return cl_tx_amsdu_anchor_set (cl_hw, cl_sta, skb, tid); + } + +if (amsdu_anchor->is_sw_amsdu) +return cl_tx_amsdu_sw_aggregate (cl_hw, amsdu_anchor, skb); + +/* +* 1. Check if there is enough space in AMSDU +* 2. Check if A-MSDU packet count is less than maximum. +*/ + packet_cnt = amsdu_anchor->packet_cnt; + +if (amsdu_anchor->rem_len > packet_len && + packet_cnt < packet_cnt_max && + !is_mesh) { +struct cl_amsdu_txhdr *amsdu_txhdr =NULL ; +u8 hdr_pads =CL_SKB_DATA_ALIGN_PADS (skb->data); +u16 ethertype = (skb->data[12 ] <<8 ) | skb->data[13 ]; +u16 total_packet_len = packet_len + hdr_pads; +u16 curr_amsdu_len = amsdu_anchor->max_len - amsdu_anchor->rem_len; +dma_addr_t dma_addr; + +if (ethertype >=ETH_P_802_3_MIN ) + total_packet_len +=sizeof (rfc1042_header); + +/* +* High number of MSDUs in AMSDU can cause underrun in the +* E2W module. +* Therefore, host is required to set Num MSDU in AMSDU using +* the following rules +* +* AMSDU Length AMSDU agg size +* len < 4*256 3 or less +* len >= 4*256 4 or less +* len >= 5*256 5 or less +* len >= 6*256 6 or less +* len >= 7*256 7 or less +* len >= 8*256 8 or less +*/ +if (packet_cnt >=CL_AMSDU_MIN_AGG_SIZE ) { +u16 new_amsdu_len = curr_amsdu_len + packet_len; + +if (new_amsdu_len < ((packet_cnt +1 ) *CL_AMSDU_CONST_LEN )) +return cl_tx_amsdu_anchor_set (cl_hw, cl_sta, skb, tid); + } + + amsdu_txhdr =cl_tx_amsdu_txhdr_alloc (cl_hw); +if (unlikely (!amsdu_txhdr)) { +kfree_skb (skb); +cl_dbg_err (cl_hw,"AMSDU FAILED to alloc amsdu txhdr\n" ); + cl_hw->tx_packet_cntr.drop.amsdu_alloc_fail++; + cl_sta->cl_vif->trfc_cntrs[anchor_sw_txhdr->ac].tx_errors++; +return CL_AMSDU_FAILED ; + } + + amsdu_txhdr->skb = skb; +list_add_tail (&amsdu_txhdr->list, &anchor_sw_txhdr->amsdu_txhdr.list); + +/* Update anchor fields */ + amsdu_anchor->rem_len -= total_packet_len; + amsdu_anchor->packet_cnt++; + +/* Get DMA address for skb */ + dma_addr =dma_map_single (cl_hw->chip->dev, (u8 *)skb->data - hdr_pads, + packet_len + hdr_pads,DMA_TO_DEVICE ); +if (WARN_ON (dma_mapping_error (cl_hw->chip->dev, dma_addr))) { +kfree_skb (skb); +cl_tx_amsdu_txhdr_free (cl_hw, amsdu_txhdr); +cl_dbg_err (cl_hw,"dma_mapping_error\n" ); + cl_hw->tx_packet_cntr.drop.amsdu_dma_map_err++; + cl_sta->cl_vif->trfc_cntrs[anchor_sw_txhdr->ac].tx_errors++; +return CL_AMSDU_FAILED ; + } + +/* Add AMSDU HDR len of the first packet */ +if (amsdu_anchor->packet_cnt ==2 ) + total_packet_len +=CL_AMSDU_HDR_LEN ; + + amsdu_txhdr->dma_addr = dma_addr; + +/* Update sw_txhdr packet_len, packet_addr, packet_cnt fields */ +cl_tx_amsdu_anchor_umacdesc_update (&anchor_sw_txhdr->txdesc, packet_cnt, + packet_len, dma_addr, hdr_pads); + +/* If we reached max AMSDU payload count, mark anchor as NULL */ +if (amsdu_anchor->packet_cnt >= packet_cnt_max) +cl_tx_amsdu_anchor_init (amsdu_anchor); + +return CL_AMSDU_SUB_FRAME_SET ; + } +/* Not enough space remain, set new anchor length is ok */ +if (unlikely (packet_len > amsdu_anchor->max_len) || is_mesh) { +cl_tx_amsdu_anchor_init (amsdu_anchor); +return CL_AMSDU_SKIP ; + }else { +return cl_tx_amsdu_anchor_set (cl_hw, cl_sta, skb, tid); + } +} + +void cl_tx_amsdu_unset (struct cl_sw_txhdr *sw_txhdr) +{ +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (sw_txhdr->skb); + + tx_info->control.flags &= ~IEEE80211_TX_CTRL_AMSDU ; + + sw_txhdr->txdesc.e2w_txhdr_param.qos_ctrl &= + ~cpu_to_le16 (IEEE80211_QOS_CTL_A_MSDU_PRESENT ); +} + +/* +* Two options for allocating cl_amsdu_txhdr: +* 1) pool +* 2) cache +*/ + +static int cl_tx_amsdu_txhdr_init_pool (struct cl_hw *cl_hw) +{ +u16 amsdu_txhdr_pool = cl_hw->conf->ci_amsdu_txhdr_pool; +u32 i =0 ; +u32 amsdu_txhdr_pool_size = amsdu_txhdr_pool *sizeof (struct cl_amsdu_txhdr ); +struct cl_amsdu_txhdr *amsdu_txhdr; + +INIT_LIST_HEAD (&cl_hw->head_amsdu_txhdr_pool); + +for (i =0 ; i < amsdu_txhdr_pool; i++) { + amsdu_txhdr =kzalloc (sizeof (*amsdu_txhdr),GFP_ATOMIC ); + +if (unlikely (!amsdu_txhdr)) { +cl_dbg_err (cl_hw,"amsdu_txhdr NULL\n" ); +return -1 ; + } + +list_add (&amsdu_txhdr->list_pool, &cl_hw->head_amsdu_txhdr_pool); + } + +cl_dbg_verbose (cl_hw," - pool %u, size %u\n" , + amsdu_txhdr_pool, amsdu_txhdr_pool_size); + +return 0 ; +} + +static int cl_tx_amsdu_txhdr_init_cache (struct cl_hw *cl_hw) +{ +char amsdu_txhdr_cache_name[MODULE_NAME_LEN +32 ] = {0 }; + +snprintf (amsdu_txhdr_cache_name,sizeof (amsdu_txhdr_cache_name), +"%s_amsdu_txhdr_cache" ,THIS_MODULE ->name); + + cl_hw->amsdu_txhdr_cache =kmem_cache_create (amsdu_txhdr_cache_name, +sizeof (struct cl_amsdu_txhdr ), +0 , + (SLAB_HWCACHE_ALIGN |SLAB_PANIC ), +NULL ); + +if (!cl_hw->amsdu_txhdr_cache) { +cl_dbg_err (cl_hw,"amsdu_txhdr_cache NULL\n" ); +return -1 ; + } + +return 0 ; +} + +int cl_tx_amsdu_txhdr_init (struct cl_hw *cl_hw) +{ +if (cl_hw->conf->ci_amsdu_txhdr_pool) +return cl_tx_amsdu_txhdr_init_pool (cl_hw); +else +return cl_tx_amsdu_txhdr_init_cache (cl_hw); +} + +static void cl_tx_amsdu_txhdr_deinit_pool (struct cl_hw *cl_hw) +{ +struct cl_amsdu_txhdr *amsdu_txhdr, *tmp; + +list_for_each_entry_safe (amsdu_txhdr, tmp, &cl_hw->head_amsdu_txhdr_pool, list_pool) { +list_del (&amsdu_txhdr->list_pool); +kfree (amsdu_txhdr); + } +} + +static void cl_tx_amsdu_txhdr_deinit_cache (struct cl_hw *cl_hw) +{ +kmem_cache_destroy (cl_hw->amsdu_txhdr_cache); +} + +void cl_tx_amsdu_txhdr_deinit (struct cl_hw *cl_hw) +{ +if (cl_hw->conf->ci_amsdu_txhdr_pool) +cl_tx_amsdu_txhdr_deinit_pool (cl_hw); +else +cl_tx_amsdu_txhdr_deinit_cache (cl_hw); +} + +void cl_tx_amsdu_txhdr_free (struct cl_hw *cl_hw,struct cl_amsdu_txhdr *amsdu_txhdr) +{ +if (cl_hw->conf->ci_amsdu_txhdr_pool) +list_add_tail (&amsdu_txhdr->list_pool, &cl_hw->head_amsdu_txhdr_pool); +else +kmem_cache_free (cl_hw->amsdu_txhdr_cache, amsdu_txhdr); +} + +static const u8 cl_tid2hwq[IEEE80211_NUM_TIDS ] = { +CL_HWQ_BE , +CL_HWQ_BK , +CL_HWQ_BK , +CL_HWQ_BE , +CL_HWQ_VI , +CL_HWQ_VI , +CL_HWQ_VO , +CL_HWQ_VO , +/* At the moment, all others TID are mapped to BE */ +CL_HWQ_BE , +CL_HWQ_BE , +CL_HWQ_BE , +CL_HWQ_BE , +CL_HWQ_BE , +CL_HWQ_BE , +CL_HWQ_BE , +CL_HWQ_BE , +}; + +static void cl_txq_sched_list_add (struct cl_tx_queue *tx_queue,struct cl_hw *cl_hw) +{ +/* Add to schedule queue */ +if (tx_queue->sched) +return ; + + tx_queue->sched = true; +if (tx_queue->type ==QUEUE_TYPE_AGG ) +list_add_tail (&tx_queue->sched_list, &cl_hw->list_sched_q_agg); +else +list_add_tail (&tx_queue->sched_list, &cl_hw->list_sched_q_single); +} + +static void cl_txq_sched_list_remove (struct cl_tx_queue *tx_queue) +{ +/* Remove from schedule queue */ +if (tx_queue->sched) { + tx_queue->sched = false; +list_del (&tx_queue->sched_list); + } +} + +static void cl_txq_sched_list_remove_if_empty (struct cl_tx_queue *tx_queue) +{ +/* If queue is empty remove it from schedule list */ +if (list_empty (&tx_queue->hdrs)) +cl_txq_sched_list_remove (tx_queue); +} + +static void cl_txq_transfer_single_to_agg (struct cl_hw *cl_hw, +struct cl_tx_queue *single_queue, +struct cl_tx_queue *agg_queue,u8 tid) +{ +struct cl_sw_txhdr *sw_txhdr, *sw_txhdr_tmp; +struct ieee80211_tx_info *tx_info; +struct sk_buff *skb; +u8 hdr_pads; + +spin_lock_bh (&cl_hw->tx_lock_single); + +if (single_queue->num_packets ==0 ) + goto out; + +list_for_each_entry_safe (sw_txhdr, sw_txhdr_tmp, &single_queue->hdrs, tx_queue_list) { +if (sw_txhdr->tid != tid) +continue ; + +if (!ieee80211_is_data_qos (sw_txhdr->fc)) +continue ; + + cl_hw->tx_packet_cntr.transfer.single_to_agg++; + +/* Remove from single queue */ +list_del (&sw_txhdr->tx_queue_list); + +/* Update single queue counters */ + single_queue->num_packets--; + single_queue->total_packets--; + +/* Turn on AMPDU flag */ + skb = sw_txhdr->skb; + tx_info =IEEE80211_SKB_CB (skb); + tx_info->flags |=IEEE80211_TX_CTL_AMPDU ; + +/* Convert header back and Push skb to agg queue */ +cl_tx_wlan_to_8023 (skb); + hdr_pads =CL_SKB_DATA_ALIGN_PADS (skb->data); +cl_tx_agg_prep (cl_hw, sw_txhdr, skb->len, hdr_pads, true); + agg_queue->total_packets++; + sw_txhdr->hdr80211 =NULL ; + sw_txhdr->tx_queue = agg_queue; +cl_txq_push (cl_hw, sw_txhdr); + +/* Schedule tasklet to try and empty the queue */ +tasklet_schedule (&cl_hw->tx_task); + } + +/* If single queue is empty remove it from schedule list */ +cl_txq_sched_list_remove_if_empty (single_queue); + +out: +spin_unlock_bh (&cl_hw->tx_lock_single); +} + +static void cl_txq_delete_packets (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue,u8 sta_idx) +{ +struct cl_sw_txhdr *sw_txhdr, *sw_txhdr_tmp; + +list_for_each_entry_safe (sw_txhdr, sw_txhdr_tmp, &tx_queue->hdrs, tx_queue_list) { +/* +* Brodcast frames do not have cl_sta and should not be +* deleted at station remove sequence. +*/ +if (!sw_txhdr->cl_sta) +continue ; + +if (sw_txhdr->sta_idx != sta_idx) +continue ; + +list_del (&sw_txhdr->tx_queue_list); + tx_queue->num_packets--; + +cl_tx_single_free_skb (cl_hw, sw_txhdr->skb); +cl_sw_txhdr_free (cl_hw, sw_txhdr); + } + +/* If queue is empty remove it from schedule list */ +cl_txq_sched_list_remove_if_empty (tx_queue); +} + +static void cl_txq_reset_counters (struct cl_tx_queue *tx_queue) +{ + tx_queue->total_fw_push_desc =0 ; + tx_queue->total_fw_push_skb =0 ; + tx_queue->total_fw_cfm =0 ; + tx_queue->total_packets =0 ; + tx_queue->dump_queue_full =0 ; + tx_queue->dump_dma_map_fail =0 ; + +memset (tx_queue->stats_hw_amsdu_cnt,0 , +sizeof (tx_queue->stats_hw_amsdu_cnt)); + +memset (tx_queue->stats_sw_amsdu_cnt,0 , +sizeof (tx_queue->stats_sw_amsdu_cnt)); +} + +static void cl_txq_flush (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue) +{ +struct cl_sw_txhdr *sw_txhdr, *sw_txhdr_tmp; +struct ieee80211_tx_info *tx_info; + +if (tx_queue->num_packets ==0 ) +return ; + +list_for_each_entry_safe (sw_txhdr, sw_txhdr_tmp, &tx_queue->hdrs, tx_queue_list) { +list_del (&sw_txhdr->tx_queue_list); + tx_queue->num_packets--; + +/* Can not send AMSDU frames as singles */ + tx_info =IEEE80211_SKB_CB (sw_txhdr->skb); + +/* Free mid & last AMSDU sub frames */ +if (cl_tx_ctrl_is_amsdu (tx_info)) { +cl_tx_amsdu_flush_sub_frames (cl_hw, sw_txhdr); + }else { +if (tx_queue->type ==QUEUE_TYPE_SINGLE ) +cl_tx_single_free_skb (cl_hw, sw_txhdr->skb); +else +kfree_skb (sw_txhdr->skb); + + cl_hw->tx_packet_cntr.drop.queue_flush++; + sw_txhdr->cl_vif->trfc_cntrs[sw_txhdr->ac].tx_dropped++; +cl_sw_txhdr_free (cl_hw, sw_txhdr); + } + } + +/* Remove from schedule queue */ +cl_txq_sched_list_remove (tx_queue); + +/* Sanity check that queue is empty */ +WARN_ON (tx_queue->num_packets >0 ); +} + +static void cl_txq_agg_size_set (struct cl_hw *cl_hw) +{ +struct cl_tx_queue *tx_queue =NULL ; +u16 new_size =0 ; +u16 drv_max_size =0 ; +int i =0 ; +int j =0 ; + +if (!cl_hw->used_agg_queues || !cl_hw->conf->ci_tx_packet_limit) +return ; + + new_size = cl_hw->conf->ci_tx_packet_limit / cl_hw->used_agg_queues; + drv_max_size =max (new_size, cl_hw->conf->ci_tx_queue_size_agg); + +for (i =0 ; i <IPC_MAX_BA_SESSIONS ; i++) { + tx_queue = &cl_hw->tx_queues->agg[i]; + +if (!tx_queue->cl_sta) +continue ; + + tx_queue->max_packets = drv_max_size; + + j++; +if (j == cl_hw->used_agg_queues) +break ; + } + +cl_dbg_trace (cl_hw,"drv_max_size = %u\n" , drv_max_size); +} + +static int cl_txq_request_find (struct cl_hw *cl_hw,u8 sta_idx,u8 tid) +{ +int i =0 ; +struct cl_req_agg_db *req_agg_db =NULL ; +u8 req_agg_queues =0 ; + +for (i =0 ; (i <IPC_MAX_BA_SESSIONS ) && (req_agg_queues < cl_hw->req_agg_queues); i++) { + req_agg_db = &cl_hw->req_agg_db[i]; + +if (!req_agg_db->is_used) +continue ; + + req_agg_queues++; + +if (sta_idx == req_agg_db->sta_idx && tid == req_agg_db->tid) +return i; + } + +return -1 ; +} + +static void cl_txq_push_cntrs_update (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue, +u32 orig_drv_cnt,u32 orig_fw_cnt) +{ +u32 total_pushed; +u32 idx; + +if (!cl_hw->conf->ci_tx_push_cntrs_stat_en) +return ; + + total_pushed = orig_drv_cnt - tx_queue->num_packets; + idx = tx_queue->push_cntrs_db.tx_push_logger_idx %TX_PUSH_LOGGER_SIZE ; + tx_queue->push_cntrs_db.tx_push_cntr_hist[total_pushed]++; + tx_queue->push_cntrs_db.tx_push_logger[idx][TX_PUSH_LOGGER_DRV_CNT ] = orig_drv_cnt; + tx_queue->push_cntrs_db.tx_push_logger[idx][TX_PUSH_LOGGER_FW_CNT ] = orig_fw_cnt; + tx_queue->push_cntrs_db.tx_push_logger[idx][TX_PUSH_LOGGER_PKT_PUSHED ] = total_pushed; + ++tx_queue->push_cntrs_db.tx_push_logger_idx; +} + +static void cl_txq_task_single (struct cl_hw *cl_hw) +{ +/* Schedule single queues */ +struct cl_tx_queue *tx_queue, *tx_queue_tmp; + +spin_lock (&cl_hw->tx_lock_single); + +list_for_each_entry_safe (tx_queue, tx_queue_tmp, &cl_hw->list_sched_q_single, sched_list) +cl_txq_sched (cl_hw, tx_queue); + +/* Rotate the queue so next schedule will start with a different queue */ +list_rotate_left (&cl_hw->list_sched_q_single); + +spin_unlock (&cl_hw->tx_lock_single); +} + +static void cl_txq_task_agg (struct cl_hw *cl_hw) +{ +/* Schedule agg queueus */ +struct cl_tx_queue *tx_queue, *tx_queue_tmp; + +spin_lock (&cl_hw->tx_lock_agg); + +list_for_each_entry_safe (tx_queue, tx_queue_tmp, &cl_hw->list_sched_q_agg, sched_list) +cl_txq_sched (cl_hw, tx_queue); + +/* Rotate the queue so next schedule will start with a different queue */ +list_rotate_left (&cl_hw->list_sched_q_agg); + +spin_unlock (&cl_hw->tx_lock_agg); +} + +static void cl_txq_task (unsigned long data) +{ +struct cl_hw *cl_hw = (struct cl_hw *)data; + +cl_txq_task_single (cl_hw); +cl_txq_task_agg (cl_hw); +} + +static void cl_txq_agg_inc_usage_cntr (struct cl_hw *cl_hw) +{ +/* Should be called in cl_hw->tx_lock_agg context */ + cl_hw->used_agg_queues++; +cl_txq_agg_size_set (cl_hw); +} + +static void cl_txq_agg_dec_usage_cntr (struct cl_hw *cl_hw) +{ +/* Should be called in cl_hw->tx_lock_agg context */ +WARN_ON_ONCE (cl_hw->used_agg_queues ==0 ); + + cl_hw->used_agg_queues--; +cl_txq_agg_size_set (cl_hw); +} + +static void cl_txq_init_single (struct cl_hw *cl_hw) +{ +struct cl_tx_queue *tx_queue; +u32 i; + +spin_lock_bh (&cl_hw->tx_lock_single); + +INIT_LIST_HEAD (&cl_hw->list_sched_q_single); + +for (i =0 ; i <MAX_SINGLE_QUEUES ; i++) { + tx_queue = &cl_hw->tx_queues->single[i]; +memset (tx_queue,0 ,sizeof (struct cl_tx_queue )); +INIT_LIST_HEAD (&tx_queue->hdrs); + tx_queue->hw_index = i /FW_MAX_NUM_STA ; + tx_queue->fw_max_size =IPC_TXDESC_CNT_SINGLE ; + tx_queue->fw_free_space =IPC_TXDESC_CNT_SINGLE ; + tx_queue->index = i; + tx_queue->max_packets = cl_hw->conf->ci_tx_queue_size_single; + tx_queue->type =QUEUE_TYPE_SINGLE ; + } + +spin_unlock_bh (&cl_hw->tx_lock_single); +} + +static void cl_txq_init_bcmc (struct cl_hw *cl_hw) +{ +struct cl_tx_queue *tx_queue; + +spin_lock_bh (&cl_hw->tx_lock_bcmc); + + tx_queue = &cl_hw->tx_queues->bcmc; +memset (tx_queue,0 ,sizeof (struct cl_tx_queue )); +INIT_LIST_HEAD (&tx_queue->hdrs); + tx_queue->hw_index =CL_HWQ_BCN ; + tx_queue->fw_max_size =IPC_TXDESC_CNT_BCMC ; + tx_queue->fw_free_space =IPC_TXDESC_CNT_BCMC ; + tx_queue->index =0 ; + tx_queue->max_packets =0 ; + tx_queue->type =QUEUE_TYPE_BCMC ; + +spin_unlock_bh (&cl_hw->tx_lock_bcmc); +} + +static void cl_txq_init_agg (struct cl_hw *cl_hw) +{ +spin_lock_bh (&cl_hw->tx_lock_agg); +INIT_LIST_HEAD (&cl_hw->list_sched_q_agg); +spin_unlock_bh (&cl_hw->tx_lock_agg); +} + +static void cl_txq_agg_request_reset (struct cl_hw *cl_hw) +{ + cl_hw->req_agg_queues =0 ; +memset (cl_hw->req_agg_db,0 ,sizeof (cl_hw->req_agg_db)); +} + +void cl_txq_init (struct cl_hw *cl_hw) +{ +tasklet_init (&cl_hw->tx_task, cl_txq_task, (unsigned long )cl_hw); + +cl_txq_agg_request_reset (cl_hw); +cl_txq_init_single (cl_hw); +cl_txq_init_bcmc (cl_hw); +cl_txq_init_agg (cl_hw); +} + +void cl_txq_stop (struct cl_hw *cl_hw) +{ +tasklet_kill (&cl_hw->tx_task); +} + +struct cl_tx_queue *cl_txq_get (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr) +{ +struct cl_sta *cl_sta = sw_txhdr->cl_sta; +struct ieee80211_tx_info *tx_info =IEEE80211_SKB_CB (sw_txhdr->skb); +u8 hw_queue = sw_txhdr->hw_queue; + +if (!cl_sta && + hw_queue ==CL_HWQ_VO && +is_multicast_ether_addr (sw_txhdr->hdr80211->addr1)) { +/* +* If HW queue is VO and packet is multicast, it was not buffered +* by mac80211, and it should be pushed to the high-priority queue
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.36.1
Part of the diff is not shown here. View the raw message.
RFC v2 85/96 cl8k: add tx.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/tx.h | 467 ++++++++++++++++++++++++++ 1 file changed, 467 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/tx.h
drivers/net/wireless/celeno/cl8k/tx.h new file +467 -0
@@ -0,0 +1,467 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_TX_H +#define CL_TX_H + +#include <linux/interrupt.h> + +#include "sta_info.h" +#include "vif.h" +#include "ipc_shared.h" +#include "fw.h" +#include "wrs.h" + +enum cl_queue_type { +QUEUE_TYPE_SINGLE , +QUEUE_TYPE_AGG , +QUEUE_TYPE_BCMC , + +QUEUE_TYPE_MAX +}; + +#define QUEUE_IDX (sta, ac) ((sta) + (ac) * FW_MAX_NUM_STA) + +#define TX_PUSH_LOGGER_SIZE 256 + +#define BCMC_POLL_TIMEOUT 50 + +enum cl_tx_push_logger_param { +TX_PUSH_LOGGER_DRV_CNT , +TX_PUSH_LOGGER_FW_CNT , +TX_PUSH_LOGGER_PKT_PUSHED , +TX_PUSH_LOGGER_MAX , +}; + +struct cl_tx_push_cntrs { +u32 tx_push_cntr_hist[TXDESC_AGG_Q_SIZE_MAX +1 ]; +u32 tx_push_logger[TX_PUSH_LOGGER_SIZE ][TX_PUSH_LOGGER_MAX ]; +u32 tx_push_logger_idx; +}; + +struct cl_tx_queue { +struct list_head sched_list; +struct list_head hdrs; +struct cl_sta *cl_sta; +bool sched; +u16 fw_free_space; +u16 fw_max_size; +u8 type; +u8 tid; +u8 hw_index; +u16 index; +u16 max_packets; +u16 num_packets; +u32 total_packets; +u32 total_fw_push_desc; +u32 total_fw_push_skb; +u32 total_fw_cfm; +u32 dump_queue_full; +u32 dump_dma_map_fail; +u32 stats_hw_amsdu_cnt[CL_AMSDU_TX_PAYLOAD_MAX ]; +u32 stats_sw_amsdu_cnt[MAX_TX_SW_AMSDU_PACKET ]; +u32 hist_xmit_to_push[DELAY_HIST_SIZE ]; +u32 hist_push_to_cfm[DELAY_HIST_SIZE ]; +struct cl_tx_push_cntrs push_cntrs_db; +}; + +/* +* struct cl_tx_queues: +* This structure holds all driver TX queues, +* The queues buffer frames pushed by upper layer and push them to lower IPC layer. +*/ +struct cl_tx_queues { +struct cl_tx_queue agg[IPC_MAX_BA_SESSIONS ]; +struct cl_tx_queue single[MAX_SINGLE_QUEUES ]; +struct cl_tx_queue bcmc; +}; + +struct cl_req_agg_db { +bool is_used; +u8 sta_idx; +u8 tid; +}; + +#define INC_SN (sn) (((sn) + 0x10) & IEEE80211_SCTL_SEQ) +#define DEC_SN (sn) (((sn) - 0x10) & IEEE80211_SCTL_SEQ) + +#define CL_TX_LIFETIME_MS 4000 + +#define CL_SKB_DATA_ALIGN_SZ 4 +#define CL_SKB_DATA_ALIGN_MSK (CL_SKB_DATA_ALIGN_SZ - 1) +#define CL_SKB_DATA_ALIGN_PADS (x) \ + ((CL_SKB_DATA_ALIGN_SZ - ((ptrdiff_t)(x) & CL_SKB_DATA_ALIGN_MSK)) & CL_SKB_DATA_ALIGN_MSK) + +#define CL_TX_MAX_FRAME_LEN_SINGLE 4096 +#define CL_TX_MAX_FRAME_LEN_AGG 2000 + +struct cl_hw_tx_status { +u32 mcs_index :7 ;/* [6:0] */ +u32 is_bcmc :1 ;/* [7] */ +u32 num_mpdu_retries :4 ;/* [11:8] */ +u32 rsv :4 ;/* [15:12] */ +u32 format_mod :4 ;/* [19:16] */ +u32 bw_requested :2 ;/* [21:20] */ +u32 bf :1 ;/* [22] */ +u32 frm_successful :1 ;/* [23] */ +u32 bw_transmitted :2 ;/* [25:24] */ +u32 freespace_inc_skip :1 ;/* [26] */ +u32 keep_skb :1 ;/* [27] */ +u32 gi :2 ;/* [29:28] */ +u32 descriptor_done_sw :1 ;/* [30] */ +u32 descriptor_done_hw :1 ;/* [31] */ +}; + +enum cl_tx_flags { +CL_TX_EN_DFS , +CL_TX_EN_SCAN +}; + +enum cl_tx_single_frame_type { +CL_TX_SINGLE_FRAME_TYPE_QOS_DATA , +CL_TX_SINGLE_FRAME_TYPE_QOS_NULL , +CL_TX_SINGLE_FRAME_TYPE_MANAGEMENT , +CL_TX_SINGLE_FRAME_TYPE_OTHER +}; + +struct cl_tx_db { +bool force_amsdu; +bool block_bcn; +bool block_prob_resp; +}; + +struct cl_tx_drop_cntr { +u32 radio_off; +u32 in_recovery; +u32 short_length; +u32 pending_full; +u32 packet_limit; +u32 dev_flags; +u32 tx_disable; +u32 length_limit; +u32 txhdr_alloc_fail; +u32 queue_null; +u32 amsdu_alloc_fail; +u32 amsdu_dma_map_err; +u32 build_hdr_fail; +u32 key_disable; +u32 queue_flush; +u32 probe_response; +u32 sta_null_in_agg; +u32 sta_stop_tx; +}; + +struct cl_tx_forward_cntr { +u32 tx_start; +u32 drv_fast_agg; +u32 drv_fast_single; +u32 to_mac; +u32 from_mac_single; +u32 from_mac_agg; +}; + +struct cl_tx_transfer_cntr { +u32 single_to_agg; +u32 agg_to_single; +}; + +struct cl_tx_packet_cntr { +struct cl_tx_forward_cntr forward; +struct cl_tx_drop_cntr drop; +struct cl_tx_transfer_cntr transfer; +}; + +struct cl_cpu_cntr { +u32 tx_agg[CPU_MAX_NUM ]; +u32 tx_single[CPU_MAX_NUM ]; +}; + +static inline bool cl_tx_ctrl_is_amsdu (struct ieee80211_tx_info *tx_info) +{ +return !!(tx_info->control.flags &IEEE80211_TX_CTRL_AMSDU ); +} + +static inline bool cl_tx_ctrl_is_eapol (struct ieee80211_tx_info *tx_info) +{ +return !!(tx_info->control.flags &IEEE80211_TX_CTRL_PORT_CTRL_PROTO ); +} + +struct cl_agg_cfm_queue { +struct list_head head; +struct cl_tx_queue *tx_queue; +u16 ssn; +}; + +/* Structure containing the parameters of the MM_AGG_TX_REPORT_IND message. */ +struct cl_agg_tx_report { +__le32 rate_cntrl_info; +__le32 rate_cntrl_info_he; + +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 sta_idx :8 , + is_sta_ps :1 , + bw_requested :2 , + is_agg :1 , + ba_not_received :1 , + ba_received_empty :1 , + bf :1 , + is_fallback :1 , + mu_su_gid :6 , + mu_mimo_valid :1 , + mu_ofdma_valid :1 , + rate_fix_mcs1 :1 , + rsv0 :7 ; + +u32 success :9 , + fail :9 , + below_baw_cnt :9 , + num_prot_retries :5 ; + +u32 success_after_retry :9 , + success_more_one_retry :9 , + retry_limit_reached :9 , + is_retry :1 , + is_rts_retry_limit_reached :1 , + prot_type :3 ; + +u32 rssi1 :8 , + rssi2 :8 , + rssi3 :8 , + rssi4 :8 ; + +u32 rssi5 :8 , + rssi6 :8 , + rsv1 :16 ; +#else +u32 rsv0 :7 , + rate_fix_mcs1 :1 , + mu_ofdma_valid :1 , + mu_mimo_valid :1 , + mu_su_gid :6 , + is_fallback :1 , + bf :1 , + ba_received_empty :1 , + ba_not_received :1 , + is_agg :1 , + bw_requested :2 , + is_sta_ps :1 , + sta_idx :8 ; + +u32 num_prot_retries :5 , + below_baw_cnt :9 , + fail :9 , + success :9 ; + +u32 prot_type :3 , + is_rts_retry_limit_reached :1 , + is_retry :1 , + retry_limit_reached :9 , + success_more_one_retry :9 , + success_after_retry :9 ; + +u32 rssi4 :8 , + rssi3 :8 , + rssi2 :8 , + rssi1 :8 ; + +u32 rsv1 :16 , + rssi6 :8 , + rssi5 :8 ; +#endif +u16 new_ssn; +u8 tx_queue_idx; + +}; + +void cl_agg_tx_report_handler (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_agg_tx_report *agg_report); +void cl_agg_tx_report_simulate_for_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_hw_tx_status *status); + +/* Per RA/TID Data for AMPDU TX */ +struct cl_baw { +u8 fw_agg_idx; +bool amsdu; +bool action_start; +u16 ssn; +u16 tid_seq; +struct sk_buff_head pending; +}; + +enum cl_amsdu_result { +CL_AMSDU_ANCHOR_SET , +CL_AMSDU_SUB_FRAME_SET , +CL_AMSDU_SKIP , +CL_AMSDU_FAILED +}; + +/* Max size of 802.11 WLAN header */ +#define CL_WLAN_HEADER_MAX_SIZE 36 + +#define CL_AMSDU_MIN_AGG_SIZE 3 +#define CL_AMSDU_CONST_LEN 256 + +struct cl_amsdu_txhdr { +struct list_head list; +struct list_head list_pool; +struct sk_buff *skb; +dma_addr_t dma_addr; +}; + +struct cl_amsdu_ctrl { +struct cl_sw_txhdr *sw_txhdr; +u16 rem_len; +u16 max_len; +u16 hdrlen; +u8 packet_cnt; +bool is_sw_amsdu; +}; + +struct cl_sw_txhdr { +struct list_head list_pool; +struct list_head tx_queue_list; +struct list_head cfm_list; +struct ieee80211_hdr *hdr80211; +struct cl_tx_queue *tx_queue; +struct cl_sta *cl_sta; +struct cl_vif *cl_vif; +struct cl_amsdu_txhdr amsdu_txhdr; +u8 hw_queue :3 , + is_bcn :1 , + tid :4 ; +u8 ac :2 , + is_sw_amsdu :1 , + sw_amsdu_packet_cnt :4 , + rsv :1 ; +/* +* singles queue index used to push the txdesc to the ipc layer +* this issue solve race condition in which we +* CFM of packet that associated with disconnected STA and has invalid +* cl_sta pointerinside this struct +*/ +u8 sta_idx; +__le16 fc; +struct sk_buff *skb; +struct txdesc txdesc; +size_t map_len; +u16 total_pkt_len; +}; + +void cl_tx_init (struct cl_hw *cl_hw); +void cl_tx_check_start_ba_session (struct cl_hw *cl_hw, +struct ieee80211_sta *sta, +struct sk_buff *skb); +void cl_tx_bcns_tasklet (unsigned long data); +void cl_tx_single_free_skb (struct cl_hw *cl_hw,struct sk_buff *skb); +void cl_tx_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool is_vns,bool lock); +void cl_tx_fast_single (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool lock); +void cl_tx_agg_prep (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr, +u16 frame_len,u8 hdr_pads,bool hdr_conv); +void cl_tx_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool hdr_conv,bool lock); +void cl_tx_fast_agg (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,bool lock); +u16 cl_tx_prepare_wlan_hdr (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct sk_buff *skb,struct ieee80211_hdr *hdr); +void cl_tx_wlan_to_8023 (struct sk_buff *skb); +int cl_tx_8023_to_wlan (struct cl_hw *cl_hw,struct sk_buff *skb,struct cl_sta *cl_sta,u8 tid); +void cl_tx_push (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr,struct cl_tx_queue *tx_queue); +void cl_tx_bcn_mesh_task (unsigned long data); +void cl_tx_en (struct cl_hw *cl_hw,u8 reason,bool enable); +void cl_tx_off (struct cl_hw *cl_hw); +void cl_tx_drop_skb (struct sk_buff *skb); +void cl_tx_update_hist_tstamp (struct cl_tx_queue *tx_queue,struct sk_buff *skb, +u32 tstamp_hist[DELAY_HIST_SIZE ],bool update_skb_ktime); +bool cl_is_tx_allowed (struct cl_hw *cl_hw); +void cl_agg_cfm_init (struct cl_hw *cl_hw); +void cl_agg_cfm_add (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr,u8 agg_idx); +void cl_agg_cfm_free_head_skb (struct cl_hw *cl_hw, +struct cl_agg_cfm_queue *cfm_queue, +u8 ba_queue_idx); +void cl_agg_cfm_flush_all (struct cl_hw *cl_hw); +void cl_agg_cfm_poll_empty (struct cl_hw *cl_hw,u8 agg_idx,bool flush); +void cl_agg_cfm_poll_empty_sta (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_agg_cfm_clear_tim_bit_sta (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_agg_cfm_set_ssn (struct cl_hw *cl_hw,u16 ssn,u8 idx); +void cl_agg_cfm_set_tx_queue (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue,u8 idx); +void cl_baw_init (struct cl_sta *cl_sta); +void cl_baw_start (struct cl_baw *baw,u16 ssn); +void cl_baw_operational (struct cl_hw *cl_hw,struct cl_baw *baw, +u8 fw_agg_idx,bool amsdu_supported); +void cl_baw_stop (struct cl_baw *baw); +void cl_baw_pending_to_agg (struct cl_hw *cl_hw, +struct cl_sta *cl_sta, +u8 tid); +void cl_baw_pending_to_single (struct cl_hw *cl_hw, +struct cl_sta *cl_sta, +struct cl_baw *baw); +void cl_baw_pending_purge (struct cl_baw *baw); + +void cl_bcmc_cfm_init (struct cl_hw *cl_hw); +void cl_bcmc_cfm_add (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr); +struct cl_sw_txhdr *cl_bcmc_cfm_find (struct cl_hw *cl_hw,dma_addr_t dma_addr, +bool keep_in_list); +void cl_bcmc_cfm_flush_queue (struct cl_hw *cl_hw,struct cl_vif *cl_vif); +void cl_bcmc_cfm_poll_empty_per_vif (struct cl_hw *cl_hw, +struct cl_vif *cl_vif); + +struct cl_single_cfm_queue { +struct list_head head; +}; + +void cl_single_cfm_init (struct cl_hw *cl_hw); +void cl_single_cfm_add (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr,u32 queue_idx); +struct cl_sw_txhdr *cl_single_cfm_find (struct cl_hw *cl_hw,u32 queue_idx, +dma_addr_t dma_addr); +void cl_single_cfm_flush_all (struct cl_hw *cl_hw); +void cl_single_cfm_flush_sta (struct cl_hw *cl_hw,u8 sta_idx); +void cl_single_cfm_poll_empty (struct cl_hw *cl_hw,u32 queue_idx); +void cl_single_cfm_poll_empty_sta (struct cl_hw *cl_hw,u8 sta_idx); +void cl_single_cfm_clear_tim_bit_sta (struct cl_hw *cl_hw,u8 sta_idx); + +int cl_sw_txhdr_init (struct cl_hw *cl_hw); +void cl_sw_txhdr_deinit (struct cl_hw *cl_hw); +struct cl_sw_txhdr *cl_sw_txhdr_alloc (struct cl_hw *cl_hw); +void cl_sw_txhdr_free (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr); +void cl_tx_amsdu_anchor_init (struct cl_amsdu_ctrl *amsdu_anchor); +void cl_tx_amsdu_anchor_reset (struct cl_amsdu_ctrl *amsdu_anchor); +void cl_tx_amsdu_set_max_len (struct cl_hw *cl_hw,struct cl_sta *cl_sta,u8 tid); +void cl_tx_amsdu_first_sub_frame (struct cl_sw_txhdr *sw_txhdr,struct cl_sta *cl_sta, +struct sk_buff *skb,u8 tid); +void cl_tx_amsdu_flush_sub_frames (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr); +void cl_tx_amsdu_transfer_single (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr); +int cl_tx_amsdu_set (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct sk_buff *skb,u8 tid); +void cl_tx_amsdu_unset (struct cl_sw_txhdr *sw_txhdr); + +int cl_tx_amsdu_txhdr_init (struct cl_hw *cl_hw); +void cl_tx_amsdu_txhdr_deinit (struct cl_hw *cl_hw); +void cl_tx_amsdu_txhdr_free (struct cl_hw *cl_hw,struct cl_amsdu_txhdr *amsdu_txhdr); + +void cl_txq_init (struct cl_hw *cl_hw); +void cl_txq_stop (struct cl_hw *cl_hw); +struct cl_tx_queue *cl_txq_get (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr); +void cl_txq_push (struct cl_hw *cl_hw,struct cl_sw_txhdr *sw_txhdr); +void cl_txq_sched (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue); +void cl_txq_agg_alloc (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct mm_ba_add_cfm *ba_add_cfm,u16 buf_size); +void cl_txq_agg_free (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue, +struct cl_sta *cl_sta,u8 tid); +void cl_txq_agg_stop (struct cl_sta *cl_sta,u8 tid); +void cl_txq_sta_add (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_txq_sta_remove (struct cl_hw *cl_hw,u8 sta_idx); +void cl_txq_transfer_agg_to_single (struct cl_hw *cl_hw,struct cl_tx_queue *agg_queue); +void cl_txq_flush_agg (struct cl_hw *cl_hw,struct cl_tx_queue *tx_queue,bool lock); +void cl_txq_flush_all_agg (struct cl_hw *cl_hw); +void cl_txq_flush_all_single (struct cl_hw *cl_hw); +void cl_txq_flush_sta (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_txq_agg_request_add (struct cl_hw *cl_hw,u8 sta_idx,u8 tid); +void cl_txq_agg_request_del (struct cl_hw *cl_hw,u8 sta_idx,u8 tid); +bool cl_txq_is_agg_available (struct cl_hw *cl_hw); +bool cl_txq_is_fw_empty (struct cl_tx_queue *tx_queue); +bool cl_txq_is_fw_full (struct cl_tx_queue *tx_queue); +u16 cl_txq_desc_in_fw (struct cl_tx_queue *tx_queue); +bool cl_txq_frames_pending (struct cl_hw *cl_hw); + +#endif /* CL_TX_H */
Signature · 1 line
2.36.1
RFC v2 86/96 cl8k: add utils.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/utils.c | 642 +++++++++++++++++++++++ 1 file changed, 642 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/utils.c
drivers/net/wireless/celeno/cl8k/utils.c new file +642 -0
@@ -0,0 +1,642 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/dma-mapping.h> +#include <linux/list.h> +#include <linux/jiffies.h> +#include <linux/kthread.h> +#include <net/mac80211.h> +#include <linux/sched/signal.h> +#include <linux/firmware.h> +#include <linux/if_vlan.h> +#include <linux/ip.h> +#include <linux/ipv6.h> + +#include "hw.h" +#include "ipc_shared.h" +#include "radio.h" +#include "traffic.h" +#include "reg/reg_defs.h" +#include "utils.h" + +#define GI_08 0 +#define GI_16 1 +#define GI_32 2 +#define GI_04 3 + +#define GI_MAX_FW 4 +#define GI_MAX_HE 3 +#define GI_MAX_HT_VHT 2 + +static u8 conv_wrs_gi_ht_vht[GI_MAX_HT_VHT ] = { + [WRS_GI_LONG ] =GI_08 , + [WRS_GI_SHORT ] =GI_04 +}; + +static u8 conv_wrs_gi_he[GI_MAX_HE ] = { + [WRS_GI_LONG ] =GI_32 , + [WRS_GI_SHORT ] =GI_16 , + [WRS_GI_VSHORT ] =GI_08 +}; + +static u8 conv_fw_gi_ht_vht[GI_MAX_FW ] = { + [GI_08 ] =WRS_GI_LONG , + [GI_16 ] =0 , + [GI_32 ] =0 , + [GI_04 ] =WRS_GI_SHORT , +}; + +static u8 conv_fw_gi_he[GI_MAX_FW ] = { + [GI_08 ] =WRS_GI_VSHORT , + [GI_16 ] =WRS_GI_SHORT , + [GI_32 ] =WRS_GI_LONG , + [GI_04 ] =0 , +}; + +static const u8 cl_mu_ofdma_ru_type_to_bw_conversion[CL_MU_OFDMA_RU_TYPE_MAX ] = { +CHNL_BW_2_5 , +CHNL_BW_2_5 , +CHNL_BW_5 , +CHNL_BW_10 , +CHNL_BW_20 , +CHNL_BW_40 , +CHNL_BW_80 , +CHNL_BW_160 +}; + +void cl_hex_dump (char *caption,u8 *buffer,u32 length,u32 offset,bool is_byte) +{ +u8 *pt = buffer; +u32 i; +bool end_nl = false; +char buf[STR_LEN_256B ] = {0 }; +int len =0 ; + +if (caption) +pr_debug ("%s: %p, len = %u\n" , caption, buffer, length); + +if (is_byte) { +for (i =0 ; i < length; i++) { +if (i %16 ==0 ) + len +=snprintf (buf + len,sizeof (buf) - len, +"0x%04x : " , i + offset); + len +=snprintf (buf + len,sizeof (buf) - len, +"%02x " , ((u8 )pt[i])); + end_nl = true; +if (i %16 ==15 ) { +pr_debug ("%s" , buf); + len =0 ; + end_nl = false; + } + } + }else { +for (i =0 ; i < (length /sizeof (u32)); i++) { +if (i %4 ==0 ) + len +=snprintf (buf + len,sizeof (buf) - len, +"0x%04x : " , + (u32)(i *sizeof (u32) + offset)); + len +=snprintf (buf + len,sizeof (buf) - len, +"%08x " , *((u32 *)(pt + i *sizeof (u32)))); + end_nl = true; +if (i %4 ==3 ) { +pr_debug ("%s" , buf); + len =0 ; + end_nl = false; + } + } + } + +if (end_nl) +pr_debug ("%s" , buf); +} + +u8 cl_convert_gi_format_wrs_to_fw (u8 wrs_mode,u8 gi) +{ +if (wrs_mode ==WRS_MODE_HE && gi <GI_MAX_HE ) +return conv_wrs_gi_he[gi]; +else if (wrs_mode >WRS_MODE_OFDM && gi <GI_MAX_HT_VHT ) +return conv_wrs_gi_ht_vht[gi]; +else +return 0 ; +} + +u8 cl_convert_gi_format_fw_to_wrs (u8 format_mode,u8 gi) +{ +if (gi <GI_MAX_FW ) { +if (format_mode >=FORMATMOD_HE_SU ) +return conv_fw_gi_he[gi]; +else if (format_mode >=FORMATMOD_HT_MF ) +return conv_fw_gi_ht_vht[gi]; + } + +return 0 ; +} + +static u8 map_gi_to_ltf[WRS_GI_MAX ] = { + [WRS_GI_LONG ] =LTF_X4 , + [WRS_GI_SHORT ] =LTF_X2 , + [WRS_GI_VSHORT ] =LTF_X2 , +}; + +u8 cl_map_gi_to_ltf (u8 mode,u8 gi) +{ +if (mode ==WRS_MODE_HE && gi <WRS_GI_MAX ) +return map_gi_to_ltf[gi]; + +return 0 ; +} + +/* This table holds 10^(-110 -> 0) Q39 values for rx RSSI and noise floor calculations */ +#define CL_EXP_TBL_SIZE 111/* 10^x table size (-110 -> 0dBm) */ + +static u64 CL_EXP_10 [CL_EXP_TBL_SIZE ] = { +0x7FFFFFFFFFULL ,0x65AC8C2F36ULL ,0x50C335D3DBULL ,0x4026E73CCDULL ,0x32F52CFEEAULL , +0x287A26C490ULL ,0x2026F30FBBULL ,0x198A13577CULL ,0x144960C577ULL ,0x101D3F2D96ULL , +0x0CCCCCCCCDULL ,0x0A2ADAD185ULL ,0x08138561FCULL ,0x066A4A52E1ULL ,0x0518847FE4ULL , +0x040C3713A8ULL ,0x0337184E5FULL ,0x028DCEBBF3ULL ,0x0207567A25ULL ,0x019C86515CULL , +0x0147AE147BULL ,0x01044914F4ULL ,0x00CEC089CCULL ,0x00A43AA1E3ULL ,0x008273A664ULL , +0x00679F1B91ULL ,0x00524F3B0AULL ,0x0041617932ULL ,0x0033EF0C37ULL ,0x002940A1BCULL , +0x0020C49BA6ULL ,0x001A074EE5ULL ,0x0014ACDA94ULL ,0x00106C4364ULL ,0x000D0B90A4ULL , +0x000A5CB5F5ULL ,0x00083B1F81ULL ,0x000689BF52ULL ,0x0005318139ULL ,0x000420102CULL , +0x000346DC5DULL ,0x00029A54B1ULL ,0x000211490FULL ,0x0001A46D24ULL ,0x00014DF4DDULL , +0x0001094565ULL ,0x0000D2B65AULL ,0x0000A75FEFULL ,0x000084F352ULL ,0x0000699B38ULL , +0x000053E2D6ULL ,0x000042A212ULL ,0x000034EDB5ULL ,0x00002A0AEAULL ,0x0000216549ULL , +0x00001A86F1ULL ,0x000015123CULL ,0x000010BCCBULL ,0x00000D4B88ULL ,0x00000A8F86ULL , +0x000008637CULL ,0x000006A9CFULL ,0x0000054AF8ULL ,0x000004344BULL ,0x00000356EEULL , +0x000002A718ULL ,0x0000021B6CULL ,0x000001AC7BULL ,0x000001545AULL ,0x0000010E5AULL , +0x000000D6C0ULL ,0x000000AA95ULL ,0x000000877FULL ,0x0000006BA1ULL ,0x000000557EULL , +0x00000043E9ULL ,0x00000035F1ULL ,0x0000002AD9ULL ,0x0000002209ULL ,0x0000001B09ULL , +0x000000157AULL ,0x000000110FULL ,0x0000000D8DULL ,0x0000000AC3ULL ,0x000000088DULL , +0x00000006CAULL ,0x0000000565ULL ,0x0000000449ULL ,0x0000000367ULL ,0x00000002B4ULL , +0x0000000226ULL ,0x00000001B5ULL ,0x000000015BULL ,0x0000000114ULL ,0x00000000DBULL , +0x00000000AEULL ,0x000000008AULL ,0x000000006EULL ,0x0000000057ULL ,0x0000000045ULL , +0x0000000037ULL ,0x000000002CULL ,0x0000000023ULL ,0x000000001CULL ,0x0000000016ULL , +0x0000000011ULL ,0x000000000EULL ,0x000000000BULL ,0x0000000009ULL ,0x0000000007ULL , +0x0000000005ULL +}; + +static s8 cl_eng_to_noise_floor (u64 eng) +{ +s8 i =0 ; +s8 noise =0 ; +s64 min_delta =S64_MAX ; + +for (i =CL_EXP_TBL_SIZE -1 ; i >=0 ; i--) { +if (abs ((s64)(((s64 )eng) - ((s64 )CL_EXP_10 [i]))) < min_delta) { + min_delta =abs ((s64)(((s64 )eng) - ((s64 )CL_EXP_10 [i]))); + noise = i; + } + } + +return (-noise); +} + +static void cl_read_reg_noise (struct cl_hw *cl_hw,s8 res[4 ]) +{ +u32 reg_val =riu_agcinbdpow_20_pnoisestat_get (cl_hw); +u8 i =0 ; + +for (i =0 ; i <4 ; i++) { +u8 curr_val = (reg_val >> (i *8 )) &0xFF ; +/* Convert reg value to real value */ + res[i] = curr_val -0xFF ; + } +} + +s8 cl_calc_noise_floor (struct cl_hw *cl_hw,const s8 *reg_noise_floor) +{ +s8 noise_floor[4 ] = {0 }; +u64 noise_floor_eng =0 ; + +if (reg_noise_floor) +memcpy (noise_floor, reg_noise_floor,sizeof (noise_floor)); +else +cl_read_reg_noise (cl_hw, noise_floor); + + noise_floor[0 ] =abs (noise_floor[0 ]); + noise_floor[1 ] =abs (noise_floor[1 ]); + noise_floor[2 ] =abs (noise_floor[2 ]); + noise_floor[3 ] =abs (noise_floor[3 ]); + +BUILD_BUG_ON (CL_EXP_TBL_SIZE >S8_MAX ); + noise_floor_eng = (CL_EXP_10 [min_t (s8, noise_floor[0 ],CL_EXP_TBL_SIZE -1 )] + +CL_EXP_10 [min_t (s8, noise_floor[1 ],CL_EXP_TBL_SIZE -1 )] + +CL_EXP_10 [min_t (s8, noise_floor[2 ],CL_EXP_TBL_SIZE -1 )] + +CL_EXP_10 [min_t (s8, noise_floor[3 ],CL_EXP_TBL_SIZE -1 )]); + + noise_floor_eng =div64_u64 (noise_floor_eng,4 ); + +return cl_eng_to_noise_floor (noise_floor_eng); +} + +u8 cl_convert_signed_to_reg_value (s8 val) +{ +bool sign = val <0 ; +u8 res =abs (val); + +if (sign) + res |= (1 <<7 ); + +return res; +} + +static const int nl_width_to_phy_bw[] = { + [NL80211_CHAN_WIDTH_20_NOHT ] =CHNL_BW_20 , + [NL80211_CHAN_WIDTH_20 ] =CHNL_BW_20 , + [NL80211_CHAN_WIDTH_40 ] =CHNL_BW_40 , + [NL80211_CHAN_WIDTH_80 ] =CHNL_BW_80 , + [NL80211_CHAN_WIDTH_80P80 ] =CHNL_BW_20 , + [NL80211_CHAN_WIDTH_160 ] =CHNL_BW_160 , + [NL80211_CHAN_WIDTH_5 ] =CHNL_BW_20 , + [NL80211_CHAN_WIDTH_10 ] =CHNL_BW_20 , +}; + +u8 cl_width_to_bw (enum nl80211_chan_width width) +{ +if (width <=NL80211_CHAN_WIDTH_10 ) +return nl_width_to_phy_bw[width]; + +return CHNL_BW_20 ; +} + +u8 cl_center_freq_offset (u8 bw) +{ +if (bw ==CHNL_BW_160 ) +return 70 ; + +if (bw ==CHNL_BW_80 ) +return 30 ; + +if (bw ==CHNL_BW_40 ) +return 10 ; + +return 0 ; +} + +u8 cl_max_bw_idx (u8 wrs_mode,bool is_24g) +{ +if (wrs_mode <WRS_MODE_HT ) +return CHNL_BW_20 +1 ; + +if (wrs_mode ==WRS_MODE_HT || is_24g) +return CHNL_BW_40 +1 ; + +return CHNL_BW_MAX ; +} + +bool cl_hw_mode_is_b_or_bg (struct cl_hw *cl_hw) +{ +return (cl_hw->hw_mode ==HW_MODE_B || + cl_hw->hw_mode ==HW_MODE_BG ); +} + +#define LENGTH_LLC 3 +#define LENGTH_SSNAP 5 + +bool cl_is_eapol (struct sk_buff *skb) +{ +struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; +__le16 fc = hdr->frame_control; +unsigned int hdrlen =0 ; +unsigned short ethertype =0 ; +u8 *temp =NULL ; + +/* Find the wireless header size */ + hdrlen =ieee80211_has_a4 (fc) ?30 :24 ; + +if (ieee80211_is_data_qos (fc)) { + hdrlen +=IEEE80211_QOS_CTL_LEN ; + +if (ieee80211_has_order (fc)) + hdrlen +=IEEE80211_HT_CTL_LEN ; + } + +/* Skip wireless header */ + temp = (u8 *)(skb->data + hdrlen); + +/* Skip LLC and SNAP header */ +if (PKT_HAS_LLC_HDR (temp)) + ethertype =cl_get_ether_type (LENGTH_LLC +LENGTH_SSNAP -2 , temp); + +return ethertype ==ETH_P_PAE ; +} + +u8 cl_ru_alloc_to_ru_type (u8 ru_alloc) +{ +if (ru_alloc <=CL_TF_RU_ALLOC_MAX_TYPE_1 ) +return CL_MU_OFDMA_RU_TYPE_26 ; +else if (ru_alloc <=CL_TF_RU_ALLOC_MAX_TYPE_2 ) +return CL_MU_OFDMA_RU_TYPE_52 ; +else if (ru_alloc <=CL_TF_RU_ALLOC_MAX_TYPE_3 ) +return CL_MU_OFDMA_RU_TYPE_106 ; +else if (ru_alloc <=CL_TF_RU_ALLOC_MAX_TYPE_4 ) +return CL_MU_OFDMA_RU_TYPE_242 ; +else if (ru_alloc <=CL_TF_RU_ALLOC_MAX_TYPE_5 ) +return CL_MU_OFDMA_RU_TYPE_484 ; +else if (ru_alloc <=CL_TF_RU_ALLOC_MAX_TYPE_6 ) +return CL_MU_OFDMA_RU_TYPE_996 ; +else +return CL_MU_OFDMA_RU_TYPE_2x996; +} + +bool cl_is_valid_g_rates (const u8 *rate_ie) +{ +int i, rate; + +for (i =0 ; i < rate_ie[1 ]; i++) { + rate = rate_ie[2 + i] &CL_SUPP_RATE_MASK ; +switch (rate) { +case CL_80211G_RATE_6MB : +case CL_80211G_RATE_9MB : +case CL_80211G_RATE_12MB : +case CL_80211G_RATE_18MB : +case CL_80211G_RATE_24MB : +case CL_80211G_RATE_36MB : +case CL_80211G_RATE_48MB : +case CL_80211G_RATE_54MB : +return true; + } + } +return false; +} + +enum cl_wireless_mode cl_recalc_wireless_mode (struct cl_hw *cl_hw, +bool ieee80211n, +bool ieee80211ac, +bool ieee80211ax) +{ +enum cl_wireless_mode wireless_mode = cl_hw->wireless_mode; + +if (!ieee80211n && !ieee80211ac && !ieee80211ax) + wireless_mode =WIRELESS_MODE_LEGACY ; +else if (ieee80211n && (cl_band_is_24g (cl_hw) || ieee80211ac) && ieee80211ax) + wireless_mode =WIRELESS_MODE_HT_VHT_HE ; +else if (ieee80211n && ieee80211ac) + wireless_mode =WIRELESS_MODE_HT_VHT ; +else if (ieee80211n) + wireless_mode =WIRELESS_MODE_HT ; +else if (ieee80211ax) + wireless_mode =WIRELESS_MODE_HE ; + +return wireless_mode; +} + +enum nl80211_he_ru_alloc cl_ru_type_to_nl80211_he_ru_alloc (enum cl_mu_ofdma_ru_type ru_type) +{ +switch (ru_type) { +case CL_MU_OFDMA_RU_TYPE_26 : +return NL80211_RATE_INFO_HE_RU_ALLOC_26 ; +case CL_MU_OFDMA_RU_TYPE_52 : +return NL80211_RATE_INFO_HE_RU_ALLOC_52 ; +case CL_MU_OFDMA_RU_TYPE_106 : +return NL80211_RATE_INFO_HE_RU_ALLOC_106 ; +case CL_MU_OFDMA_RU_TYPE_242 : +return NL80211_RATE_INFO_HE_RU_ALLOC_242 ; +case CL_MU_OFDMA_RU_TYPE_484 : +return NL80211_RATE_INFO_HE_RU_ALLOC_484 ; +case CL_MU_OFDMA_RU_TYPE_996 : +return NL80211_RATE_INFO_HE_RU_ALLOC_996 ; +case CL_MU_OFDMA_RU_TYPE_2x996: +return NL80211_RATE_INFO_HE_RU_ALLOC_2x996; +default : +return 0 ; + } +} + +u8 cl_mu_ofdma_grp_convert_ru_type_to_bw (struct cl_hw *cl_hw,u8 ru_type) +{ +if (ru_type >=CL_MU_OFDMA_RU_TYPE_MAX ) { +pr_err ("Invalid RU type %u\n" , ru_type); +return 0 ; + } + +return cl_mu_ofdma_ru_type_to_bw_conversion[ru_type]; +} + +void cl_ieee802_11_parse_elems (const u8 *ies,size_t ies_len,struct ieee802_11_elems *elems) +{ +u8 *ie =NULL ; + +memset (elems,0 ,sizeof (*elems)); + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_SSID , ies, ies_len); +if (ie) { + elems->ssid = (const u8 *)&ie[2 ]; + elems->ssid_len = ie[1 ]; + } + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_SUPP_RATES , ies, ies_len); +if (ie) { + elems->supp_rates = (const u8 *)&ie[2 ]; + elems->supp_rates_len = ie[1 ]; + } + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_HT_CAPABILITY , ies, ies_len); +if (ie) + elems->ht_cap_elem = (struct ieee80211_ht_cap *)&ie[2 ]; + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_HT_OPERATION , ies, ies_len); +if (ie) + elems->ht_operation = (struct ieee80211_ht_operation *)&ie[2 ]; + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_VHT_CAPABILITY , ies, ies_len); +if (ie) + elems->vht_cap_elem = (struct ieee80211_vht_cap *)&ie[2 ]; + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_VHT_OPERATION , ies, ies_len); +if (ie) + elems->vht_operation = (struct ieee80211_vht_operation *)&ie[2 ]; + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_TIM , ies, ies_len); +if (ie) { + elems->tim = (struct ieee80211_tim_ie *)&ie[2 ]; + elems->tim_len = ie[1 ]; + } + + ie = (u8 *)cfg80211_find_ie (WLAN_EID_RSN , ies, ies_len); +if (ie) { + elems->rsn = (const u8 *)&ie[2 ]; + elems->rsn_len = ie[1 ]; + } + + ie = (u8 *)cfg80211_find_ext_ie (WLAN_EID_EXT_SUPP_RATES , ies, ies_len); +if (ie) { + elems->ext_supp_rates = (const u8 *)&ie[2 ]; + elems->ext_supp_rates_len = ie[1 ]; + } + + ie = (u8 *)cfg80211_find_ext_ie (WLAN_EID_EXT_HE_CAPABILITY , ies, ies_len); +if (ie) { + elems->he_cap = (const u8 *)&ie[2 ]; + elems->he_cap_len = ie[1 ]; + } + + ie = (u8 *)cfg80211_find_ext_ie (WLAN_EID_EXT_HE_OPERATION , ies, ies_len); +if (ie) + elems->he_operation = (struct ieee80211_he_operation *)&ie[2 ]; +} + +size_t cl_file_open_and_read (struct cl_chip *chip,const char *filename, +char **buf) +{ +const struct firmware *fw; +size_t size =0 ; +int ret =0 ; +char path_name[CL_PATH_MAX ] = {0 }; + +snprintf (path_name,sizeof (path_name),"cl8k/%s" , filename); + ret =request_firmware_direct (&fw, path_name, chip->dev); + +if (ret) { +cl_dbg_chip_err (chip,"request_firmware_direct %s failed\n" , + path_name); +return 0 ; + } + +if (!fw || !fw->data) { +cl_dbg_chip_err (chip,"Invalid firmware %s\n" , path_name); + goto out; + } + + size = fw->size; + +/* +* Add one byte with a '\0' so that string manipulation functions +* used for parsing these files can find the string '\0' terminator. +* Make sure size is aligned to 4. +*/ + *buf =kzalloc (ALIGN (size +1 ,4 ),GFP_KERNEL ); +if (!(*buf)) { + size =0 ; + goto out; + } + +memcpy (*buf, fw->data, size); + +out: +release_firmware (fw); + +return size; +} + +static __be16 cl_get_eth_proto (struct sk_buff *skb) +{ +if (!skb->mac_header) +skb_reset_mac_header (skb); + +if (eth_hdr (skb)->h_proto ==htons (ETH_P_8021Q )) +return vlan_eth_hdr (skb)->h_vlan_encapsulated_proto; +else +return eth_hdr (skb)->h_proto; +} + +bool cl_set_network_header_if_proto (struct sk_buff *skb,u16 protocol) +{ +if (cl_get_eth_proto (skb) ==htons (protocol)) { +const bool has_vlan_header =eth_hdr (skb)->h_proto ==htons (ETH_P_8021Q ); +const size_t h_offset = + (eth_hdr (skb) == (struct ethhdr *)(skb->data)) ?ETH_HLEN :0 ; + +skb_set_network_header (skb, h_offset + ((has_vlan_header) ?VLAN_HLEN :0 )); + +return true; + } + +return false; +} + +bool cl_is_ipv4_packet (struct sk_buff *skb) +{ +return cl_set_network_header_if_proto (skb,ETH_P_IP ) && + (ip_hdr (skb)->ihl >=5 ) && + (ip_hdr (skb)->version ==IPVERSION ); +} + +bool cl_is_ipv6_packet (struct sk_buff *skb) +{ +return cl_set_network_header_if_proto (skb,ETH_P_IPV6 ) && + (ipv6_hdr (skb)->version ==6 ); +} + +#define TCP_ACK_MAX_LEN 100 + +bool cl_is_tcp_ack (struct sk_buff *skb,bool *syn_rst_push) +{ +if (skb->len >TCP_ACK_MAX_LEN ) + goto out; + +if (cl_is_ipv4_packet (skb)) { +struct iphdr *iphdr =ip_hdr (skb); + +if (iphdr->protocol ==IPPROTO_TCP ) { +struct tcphdr *tcp_hdr = (struct tcphdr *) + ((char *)iphdr + +IPV4_HDR_LEN (iphdr->ihl)); +u16 data_size =ntohs (iphdr->tot_len) - +IPV4_HDR_LEN (iphdr->ihl) - + (tcp_hdr->doff *4 ); + + *syn_rst_push = tcp_hdr->syn || tcp_hdr->rst || tcp_hdr->psh; + +return (data_size ==0 ); + } + }else if (cl_is_ipv6_packet (skb)) { +struct ipv6hdr *ipv6hdr =ipv6_hdr (skb); + +if (ipv6hdr->nexthdr ==IPPROTO_TCP ) { +struct tcphdr *tcp_hdr = (struct tcphdr *) + ((char *)ipv6hdr + +sizeof (struct ipv6hdr )); +u16 data_size =ntohs (ipv6hdr->payload_len) - + (tcp_hdr->doff *4 ); + + *syn_rst_push = tcp_hdr->syn || tcp_hdr->rst || tcp_hdr->psh; + +return (data_size ==0 ); + } + } + +out: + *syn_rst_push = false; +return false; +} + +bool cl_band_is_6g (struct cl_hw *cl_hw) +{ +return (cl_hw->conf->ci_band_num ==6 ); +} + +bool cl_band_is_5g (struct cl_hw *cl_hw) +{ +return (cl_hw->conf->ci_band_num ==5 ); +} + +bool cl_band_is_24g (struct cl_hw *cl_hw) +{ +return (cl_hw->conf->ci_band_num ==24 ); +} + +u8 cl_band_to_fw_idx (struct cl_hw *cl_hw) +{ +if (cl_hw->nl_band ==NL80211_BAND_6GHZ ) +return FW_BAND_6GHZ ; + +if (cl_hw->nl_band ==NL80211_BAND_5GHZ ) +return FW_BAND_5GHZ ; + +return FW_BAND_2GHZ ; +} + +static u8 fw_to_nl_band[FW_BAND_MAX ] = { + [FW_BAND_6GHZ ] =NL80211_BAND_6GHZ , + [FW_BAND_5GHZ ] =NL80211_BAND_5GHZ , + [FW_BAND_2GHZ ] =NL80211_BAND_2GHZ , +}; + +u8 cl_band_from_fw_idx (u32 phy_band) +{ +if (phy_band <FW_BAND_MAX ) +return fw_to_nl_band[phy_band]; + +return FW_BAND_MAX ; +}
Signature · 1 line
2.36.1