Search Linux Wireless

RE: [PATCH v2 2/3] wifi: rtl8xxxu: Split up rtl8xxxu_identify_chip

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: Bitterblue Smith <rtl8821cerfe2@xxxxxxxxx>
> Sent: Sunday, November 6, 2022 6:54 AM
> To: linux-wireless@xxxxxxxxxxxxxxx
> Cc: Jes Sorensen <Jes.Sorensen@xxxxxxxxx>
> Subject: [PATCH v2 2/3] wifi: rtl8xxxu: Split up rtl8xxxu_identify_chip
> 
> Move the reusable parts into separate functions and create one
> identify_chip function for each chip type.
> 
> This is preparation for supporting the RTL8710BU chip, which would
> need too many ugly changes to this function. Another reason to do this
> is to get rid of the long and scary if..else if..else block in the
> middle of the function.
> 
> Everything should still work the same as before.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@xxxxxxxxx>
> ---
> v2:
>  - Make rtl8192cu_identify_chip and rtl8192eu_identify_chip static.
>    Reported-by: kernel test robot <lkp@xxxxxxxxx>
> ---
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |   5 +
>  .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |  32 +++
>  .../realtek/rtl8xxxu/rtl8xxxu_8192c.c         |  60 +++++
>  .../realtek/rtl8xxxu/rtl8xxxu_8192e.c         |  49 +++++
>  .../realtek/rtl8xxxu/rtl8xxxu_8723a.c         |  51 +++++
>  .../realtek/rtl8xxxu/rtl8xxxu_8723b.c         |  49 +++++
>  .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 207 +++++-------------
>  7 files changed, 297 insertions(+), 156 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> index 9f8b23160ed0..136992f0200c 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> @@ -1470,6 +1470,7 @@ struct rtl8xxxu_tx_urb {
>  };
> 
>  struct rtl8xxxu_fileops {
> +	int (*identify_chip) (struct rtl8xxxu_priv *priv);
>  	int (*parse_efuse) (struct rtl8xxxu_priv *priv);
>  	int (*load_firmware) (struct rtl8xxxu_priv *priv);
>  	int (*power_on) (struct rtl8xxxu_priv *priv);
> @@ -1562,6 +1563,10 @@ int rtl8xxxu_init_phy_regs(struct rtl8xxxu_priv *priv,
>  int rtl8xxxu_load_firmware(struct rtl8xxxu_priv *priv, char *fw_name);
>  void rtl8xxxu_firmware_self_reset(struct rtl8xxxu_priv *priv);
>  void rtl8xxxu_power_off(struct rtl8xxxu_priv *priv);
> +void rtl8xxxu_identify_vendor_1bit(struct rtl8xxxu_priv *priv, u32 vendor);
> +void rtl8xxxu_identify_vendor_2bits(struct rtl8xxxu_priv *priv, u32 vendor);
> +void rtl8xxxu_config_endpoints_sie(struct rtl8xxxu_priv *priv);
> +int rtl8xxxu_config_endpoints_no_sie(struct rtl8xxxu_priv *priv);
>  int rtl8xxxu_read_efuse8(struct rtl8xxxu_priv *priv, u16 offset, u8 *data);
>  void rtl8xxxu_reset_8051(struct rtl8xxxu_priv *priv);
>  int rtl8xxxu_auto_llt_table(struct rtl8xxxu_priv *priv);
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
> index 5eadeb02a762..4d044a8baa30 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
> @@ -321,6 +321,37 @@ static const struct rtl8xxxu_rfregval rtl8188fu_cut_b_radioa_init_table[] = {
>  	{0xff, 0xffffffff}
>  };
> 
> +static int rtl8188fu_identify_chip(struct rtl8xxxu_priv *priv)
> +{
> +	struct device *dev = &priv->udev->dev;
> +	u32 sys_cfg, vendor;
> +	int ret = 0;
> +
> +	sprintf(priv->chip_name, "8188FU");

strscpy(priv->chip_name, "8188FU", sizeof(priv->chip_name));

> +	priv->rtl_chip = RTL8188F;
> +	priv->rf_paths = 1;
> +	priv->rx_paths = 1;
> +	priv->tx_paths = 1;
> +	priv->has_wifi = 1;
> +
> +	sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
> +	priv->chip_cut = (sys_cfg & SYS_CFG_CHIP_VERSION_MASK) >>
> +		SYS_CFG_CHIP_VERSION_SHIFT;

priv->chip_cut = FIELD_GET(SYS_CFG_CHIP_VERSION_MASK, sys_cfg);

Then, remove #define SYS_CFG_CHIP_VERSION_SHIFT.

> +	if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
> +		dev_info(dev, "Unsupported test chip\n");
> +		ret = -ENOTSUPP;
> +		goto out;
> +	}
> +
> +	vendor = sys_cfg & SYS_CFG_VENDOR_EXT_MASK;
> +	rtl8xxxu_identify_vendor_2bits(priv, vendor);
> +
> +	ret = rtl8xxxu_config_endpoints_no_sie(priv);
> +
> +out:
> +	return ret;
> +}
> +
>  static void rtl8xxxu_8188f_channel_to_group(int channel, int *group, int *cck_group)
>  {
>  	if (channel < 3)
> @@ -1690,6 +1721,7 @@ static s8 rtl8188f_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
>  }
> 
>  struct rtl8xxxu_fileops rtl8188fu_fops = {
> +	.identify_chip = rtl8188fu_identify_chip,
>  	.parse_efuse = rtl8188fu_parse_efuse,
>  	.load_firmware = rtl8188fu_load_firmware,
>  	.power_on = rtl8188fu_power_on,
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
> index 9dfeeaa74927..815c1e278e4e 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192c.c
> @@ -326,6 +326,65 @@ static const struct rtl8xxxu_rfregval rtl8188ru_radioa_1t_highpa_table[] = {
>  	{0xff, 0xffffffff}
>  };
> 
> +static int rtl8192cu_identify_chip(struct rtl8xxxu_priv *priv)
> +{
> +	struct device *dev = &priv->udev->dev;
> +	u32 val32, bonding, sys_cfg, vendor;
> +	int ret = 0;
> +
> +	sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
> +	priv->chip_cut = (sys_cfg & SYS_CFG_CHIP_VERSION_MASK) >>
> +		SYS_CFG_CHIP_VERSION_SHIFT;

ditto.

> +	if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
> +		dev_info(dev, "Unsupported test chip\n");
> +		ret = -ENOTSUPP;
> +		goto out;
> +	}
> +
> +	if (sys_cfg & SYS_CFG_TYPE_ID) {
> +		bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
> +		bonding &= HPON_FSM_BONDING_MASK;
> +		if (bonding == HPON_FSM_BONDING_1T2R) {
> +			sprintf(priv->chip_name, "8191CU");

strscpy()

> +			priv->tx_paths = 1;
> +			priv->usb_interrupts = 1;
> +			priv->rtl_chip = RTL8191C;
> +		} else {
> +			sprintf(priv->chip_name, "8192CU");

strscpy()

> +			priv->tx_paths = 2;
> +			priv->usb_interrupts = 0;
> +			priv->rtl_chip = RTL8192C;
> +		}
> +		priv->rf_paths = 2;
> +		priv->rx_paths = 2;
> +	} else {
> +		sprintf(priv->chip_name, "8188CU");

strscpy()

> +		priv->rf_paths = 1;
> +		priv->rx_paths = 1;
> +		priv->tx_paths = 1;
> +		priv->rtl_chip = RTL8188C;
> +		priv->usb_interrupts = 0;
> +	}
> +	priv->has_wifi = 1;
> +
> +	vendor = sys_cfg & SYS_CFG_VENDOR_ID;
> +	rtl8xxxu_identify_vendor_1bit(priv, vendor);
> +
> +	val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
> +	priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;

priv->rom_rev = FIELD_GET(GPIO_RF_RL_ID, valu32);

> +
> +	rtl8xxxu_config_endpoints_sie(priv);
> +
> +	/*
> +	 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
> +	 */
> +	if (!priv->ep_tx_count)
> +		ret = rtl8xxxu_config_endpoints_no_sie(priv);
> +
> +out:
> +	return ret;
> +}
> +
>  static int rtl8192cu_load_firmware(struct rtl8xxxu_priv *priv)
>  {
>  	char *fw_name;
> @@ -541,6 +600,7 @@ static int rtl8192cu_power_on(struct rtl8xxxu_priv *priv)
>  }
> 
>  struct rtl8xxxu_fileops rtl8192cu_fops = {
> +	.identify_chip = rtl8192cu_identify_chip,
>  	.parse_efuse = rtl8192cu_parse_efuse,
>  	.load_firmware = rtl8192cu_load_firmware,
>  	.power_on = rtl8192cu_power_on,
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
> index 973a02afc82b..7a182073832b 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
> @@ -478,6 +478,54 @@ static const struct rtl8xxxu_rfregval rtl8192eu_radiob_init_table[] = {
>  	{0xff, 0xffffffff}
>  };
> 
> +static int rtl8192eu_identify_chip(struct rtl8xxxu_priv *priv)
> +{
> +	struct device *dev = &priv->udev->dev;
> +	u32 val32, bonding, sys_cfg, vendor;
> +	int ret = 0;
> +
> +	sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
> +	priv->chip_cut = (sys_cfg & SYS_CFG_CHIP_VERSION_MASK) >>
> +		SYS_CFG_CHIP_VERSION_SHIFT;

= FIELD_GET(...)

> +	if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
> +		dev_info(dev, "Unsupported test chip\n");
> +		ret = -ENOTSUPP;
> +		goto out;
> +	}
> +
> +	bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
> +	bonding &= HPON_FSM_BONDING_MASK;
> +	if (bonding == HPON_FSM_BONDING_1T2R) {
> +		sprintf(priv->chip_name, "8191EU");

strscpy()

> +		priv->tx_paths = 1;
> +		priv->rtl_chip = RTL8191E;
> +	} else {
> +		sprintf(priv->chip_name, "8192EU");

strscpy()

> +		priv->tx_paths = 2;
> +		priv->rtl_chip = RTL8192E;
> +	}
> +	priv->rf_paths = 2;
> +	priv->rx_paths = 2;
> +	priv->has_wifi = 1;
> +
> +	vendor = sys_cfg & SYS_CFG_VENDOR_EXT_MASK;
> +	rtl8xxxu_identify_vendor_2bits(priv, vendor);
> +
> +	val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
> +	priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;

FIELD_GET()

> +
> +	rtl8xxxu_config_endpoints_sie(priv);
> +
> +	/*
> +	 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
> +	 */
> +	if (!priv->ep_tx_count)
> +		ret = rtl8xxxu_config_endpoints_no_sie(priv);
> +
> +out:
> +	return ret;
> +}
> +
>  static void
>  rtl8192e_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
>  {
> @@ -1693,6 +1741,7 @@ static s8 rtl8192e_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
>  }
> 
>  struct rtl8xxxu_fileops rtl8192eu_fops = {
> +	.identify_chip = rtl8192eu_identify_chip,
>  	.parse_efuse = rtl8192eu_parse_efuse,
>  	.load_firmware = rtl8192eu_load_firmware,
>  	.power_on = rtl8192eu_power_on,
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
> index 8d8eb16a0970..33a1114a5853 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723a.c
> @@ -129,6 +129,56 @@ static const struct rtl8xxxu_rfregval rtl8723au_radioa_1t_init_table[] = {
>  	{0xff, 0xffffffff}
>  };
> 
> +static int rtl8723au_identify_chip(struct rtl8xxxu_priv *priv)
> +{
> +	struct device *dev = &priv->udev->dev;
> +	u32 val32, sys_cfg, vendor;
> +	int ret = 0;
> +
> +	sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
> +	priv->chip_cut = (sys_cfg & SYS_CFG_CHIP_VERSION_MASK) >>
> +		SYS_CFG_CHIP_VERSION_SHIFT;

FIELD_GET()

> +	if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
> +		dev_info(dev, "Unsupported test chip\n");
> +		ret = -ENOTSUPP;
> +		goto out;
> +	}
> +
> +	sprintf(priv->chip_name, "8723AU");

strscpy()

> +	priv->usb_interrupts = 1;
> +	priv->rtl_chip = RTL8723A;
> +
> +	priv->rf_paths = 1;
> +	priv->rx_paths = 1;
> +	priv->tx_paths = 1;
> +
> +	val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL);
> +	if (val32 & MULTI_WIFI_FUNC_EN)
> +		priv->has_wifi = 1;
> +	if (val32 & MULTI_BT_FUNC_EN)
> +		priv->has_bluetooth = 1;
> +	if (val32 & MULTI_GPS_FUNC_EN)
> +		priv->has_gps = 1;
> +	priv->is_multi_func = 1;
> +
> +	vendor = sys_cfg & SYS_CFG_VENDOR_ID;
> +	rtl8xxxu_identify_vendor_1bit(priv, vendor);
> +
> +	val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
> +	priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;

FIELD_GET()

> +
> +	rtl8xxxu_config_endpoints_sie(priv);
> +
> +	/*
> +	 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
> +	 */
> +	if (!priv->ep_tx_count)
> +		ret = rtl8xxxu_config_endpoints_no_sie(priv);
> +
> +out:
> +	return ret;
> +}
> +
>  static int rtl8723au_parse_efuse(struct rtl8xxxu_priv *priv)
>  {
>  	struct rtl8723au_efuse *efuse = &priv->efuse_wifi.efuse8723;
> @@ -409,6 +459,7 @@ s8 rtl8723a_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
>  }
> 
>  struct rtl8xxxu_fileops rtl8723au_fops = {
> +	.identify_chip = rtl8723au_identify_chip,
>  	.parse_efuse = rtl8723au_parse_efuse,
>  	.load_firmware = rtl8723au_load_firmware,
>  	.power_on = rtl8723au_power_on,
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
> index 27df8805cb18..558572bdd2c8 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
> @@ -304,6 +304,54 @@ static const struct rtl8xxxu_rfregval rtl8723bu_radioa_1t_init_table[] = {
>  	{0xff, 0xffffffff}
>  };
> 
> +static int rtl8723bu_identify_chip(struct rtl8xxxu_priv *priv)
> +{
> +	struct device *dev = &priv->udev->dev;
> +	u32 val32, sys_cfg, vendor;
> +	int ret = 0;
> +
> +	sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
> +	priv->chip_cut = (sys_cfg & SYS_CFG_CHIP_VERSION_MASK) >>
> +		SYS_CFG_CHIP_VERSION_SHIFT;

FIELD_GET()

> +	if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
> +		dev_info(dev, "Unsupported test chip\n");
> +		ret = -ENOTSUPP;
> +		goto out;
> +	}
> +
> +	sprintf(priv->chip_name, "8723BU");

strscpy()

> +	priv->rtl_chip = RTL8723B;
> +	priv->rf_paths = 1;
> +	priv->rx_paths = 1;
> +	priv->tx_paths = 1;
> +
> +	val32 = rtl8xxxu_read32(priv, REG_MULTI_FUNC_CTRL);
> +	if (val32 & MULTI_WIFI_FUNC_EN)
> +		priv->has_wifi = 1;
> +	if (val32 & MULTI_BT_FUNC_EN)
> +		priv->has_bluetooth = 1;
> +	if (val32 & MULTI_GPS_FUNC_EN)
> +		priv->has_gps = 1;
> +	priv->is_multi_func = 1;
> +
> +	vendor = sys_cfg & SYS_CFG_VENDOR_EXT_MASK;
> +	rtl8xxxu_identify_vendor_2bits(priv, vendor);
> +
> +	val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
> +	priv->rom_rev = (val32 & GPIO_RF_RL_ID) >> 28;

FIELD_GET()

> +
> +	rtl8xxxu_config_endpoints_sie(priv);
> +
> +	/*
> +	 * Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
> +	 */
> +	if (!priv->ep_tx_count)
> +		ret = rtl8xxxu_config_endpoints_no_sie(priv);
> +
> +out:
> +	return ret;
> +}
> +
>  static void rtl8723bu_write_btreg(struct rtl8xxxu_priv *priv, u8 reg, u8 data)
>  {
>  	struct h2c_cmd h2c;
> @@ -1668,6 +1716,7 @@ static s8 rtl8723b_cck_rssi(struct rtl8xxxu_priv *priv, u8 cck_agc_rpt)
>  }
> 
>  struct rtl8xxxu_fileops rtl8723bu_fops = {
> +	.identify_chip = rtl8723bu_identify_chip,
>  	.parse_efuse = rtl8723bu_parse_efuse,
>  	.load_firmware = rtl8723bu_load_firmware,
>  	.power_on = rtl8723bu_power_on,

[..]

Only some similar comments about FIELD_GET() and strscpy().

Ping-Ke





[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux