All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	Ping-Ke Shih <pkshih@realtek.com>
Subject: Re: [PATCH 1/4] wifi: rtw88: 8821cu: Fix firmware upload fail
Date: Wed, 28 Feb 2024 09:56:46 +0100	[thread overview]
Message-ID: <Zd71ToI36YgPUReF@pengutronix.de> (raw)
In-Reply-To: <731ea688-04ef-4f02-9d01-3e9026981057@gmail.com>

On Tue, Feb 27, 2024 at 02:18:20PM +0200, Bitterblue Smith wrote:
> RTL8822CU, RTL8822BU, and RTL8821CU need an extra register write after
> reading and writing certain addresses.
> 
> Without this, the firmware upload fails approximately more than 50% of
> the time.
> 
> Tested with RTL8811CU (Tenda U9 V2.0) which is the same as RTL8821CU
> but without Bluetooth.
> 
> Fixes: a82dfd33d123 ("wifi: rtw88: Add common USB chip support")
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> ---

On a RTL8821CU based chip this indeed makes the firmware upload failures
go away.

Tested-by: Sascha Hauer <s.hauer@pengutronix.de>

Sascha


>  drivers/net/wireless/realtek/rtw88/usb.c | 46 ++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c
> index 3c4f28c306a9..ff01f7056ca9 100644
> --- a/drivers/net/wireless/realtek/rtw88/usb.c
> +++ b/drivers/net/wireless/realtek/rtw88/usb.c
> @@ -33,6 +33,42 @@ static void rtw_usb_fill_tx_checksum(struct rtw_usb *rtwusb,
>  	rtw_tx_fill_txdesc_checksum(rtwdev, &pkt_info, skb->data);
>  }
>  
> +#define REG_ON_SEC 0x00
> +#define REG_OFF_SEC 0x01
> +#define REG_LOCAL_SEC 0x02
> +
> +static void rtw_usb_reg_sec(struct rtw_dev *rtwdev, u32 addr, __le32 *data)
> +{
> +	struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
> +	struct usb_device *udev = rtwusb->udev;
> +	u8 current_reg_sec;
> +	u16 t_reg = 0x4e0;
> +	u8 t_len = 1;
> +	int status;
> +
> +	if (addr < 0xFE00) {
> +		if (addr <= 0xff)
> +			current_reg_sec = REG_ON_SEC;
> +		else if (0x1000 <= addr && addr <= 0x10ff)
> +			current_reg_sec = REG_ON_SEC;
> +		else
> +			current_reg_sec = REG_OFF_SEC;
> +	} else {
> +		current_reg_sec = REG_LOCAL_SEC;
> +	}
> +
> +	if (current_reg_sec != REG_ON_SEC)
> +		return;
> +
> +	status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
> +				 RTW_USB_CMD_REQ, RTW_USB_CMD_WRITE,
> +				 t_reg, 0, data, t_len, 500);
> +
> +	if (status != t_len && status != -ENODEV)
> +		rtw_err(rtwdev, "%s: reg 0x%x, usb write %u fail, status: %d\n",
> +			__func__, t_reg, t_len, status);
> +}
> +
>  static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len)
>  {
>  	struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
> @@ -58,6 +94,11 @@ static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len)
>  		rtw_err(rtwdev, "read register 0x%x failed with %d\n",
>  			addr, ret);
>  
> +	if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C ||
> +	    rtwdev->chip->id == RTW_CHIP_TYPE_8822B ||
> +	    rtwdev->chip->id == RTW_CHIP_TYPE_8821C)
> +		rtw_usb_reg_sec(rtwdev, addr, data);
> +
>  	return le32_to_cpu(*data);
>  }
>  
> @@ -111,6 +152,11 @@ static void rtw_usb_write(struct rtw_dev *rtwdev, u32 addr, u32 val, int len)
>  	if (ret < 0 && ret != -ENODEV && count++ < 4)
>  		rtw_err(rtwdev, "write register 0x%x failed with %d\n",
>  			addr, ret);
> +
> +	if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C ||
> +	    rtwdev->chip->id == RTW_CHIP_TYPE_8822B ||
> +	    rtwdev->chip->id == RTW_CHIP_TYPE_8821C)
> +		rtw_usb_reg_sec(rtwdev, addr, data);
>  }
>  
>  static void rtw_usb_write8(struct rtw_dev *rtwdev, u32 addr, u8 val)
> -- 
> 2.43.2
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

      parent reply	other threads:[~2024-02-28  8:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 12:18 [PATCH 1/4] wifi: rtw88: 8821cu: Fix firmware upload fail Bitterblue Smith
2024-02-27 12:56 ` Sascha Hauer
2024-02-27 16:27   ` Bitterblue Smith
2024-02-28  8:55     ` Sascha Hauer
2024-02-29  1:37       ` Ping-Ke Shih
2024-02-29  1:43         ` Ping-Ke Shih
2024-02-28  8:56 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zd71ToI36YgPUReF@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.com \
    --cc=rtl8821cerfe2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.