Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2376570lqp; Sun, 24 Mar 2024 16:37:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXlMRnL19dDKCNRTAgOJytq6ynIJstEDW2Wur+l/UI21+sBkDUE+42LX+GunkDmr1/CJ1hIh3HftBoDJWyVlStEEYlAgcnCW6DumS10jQ== X-Google-Smtp-Source: AGHT+IGOJc1AiNSf3bu89xo9uV4yk0Rcv//Rg4aKRsYHAc+WdVj1+WKHqAReIdEfkHUMFkMf9MLy X-Received: by 2002:ae9:e401:0:b0:78a:2d4b:3b06 with SMTP id q1-20020ae9e401000000b0078a2d4b3b06mr5818926qkc.76.1711323452547; Sun, 24 Mar 2024 16:37:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711323452; cv=pass; d=google.com; s=arc-20160816; b=lvvHmHBpbolKbOIjeVcgeXdCl+8jXghWUtM0y/kr7SLjTpM8SWOf3fNbJ6iRG8XgYb 0sGn5G6xjtAzOqub5wr/8XHJRToCvSihOkQ3JIr1Kw/eLkEsRe8dYHIKUSJajjNsrgkM 4h6Wc1iJzuSnr5tDX/a9SKvhI9zmLq1YtK8MNeQ2649OWeHNRdV299lu5tj6i/QgZY7q cdkO9k9+WSANy8+shAbGhOxwvFh7oLeZDccOqJUOAesU1ZGBetx/5Tti/ShX4Tegyb8E BZlt2Xv6PbmpSYw+WjL89WF8IRQ3346kSqjK+XdFJuPfiHlDsIYi8RnMmgjTgeJwTmhM evBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+AHg1l4aDGhnE1knlx3xPKMtVmOPodF8a8vGieyg+0A=; fh=RfApuWMrCBQYs6j8reEIHEe4vQngvgoyYVaRxNjhx6g=; b=I5oS+jI29izAK21PBE5wqOVxZ4vMzajQdXJGYT8uFm/T3T/qYzaKBe4pRydgzVUI/d zGY0wqJUDZKaqI4CE91hNh7Ch8+jpRTalovSW8KSW2rM8rokFol1BjqM+2FKe5MENkak aSkUg1JedGUtIo0NuZJgrGiPRXRs/q1r0/d1ex5VyMVxRNdMuCfwvlBVacqWhGMKa/iP MPaFBg+GRFFSbDtVmtXXmyRgiTE6/yIAF7Tsl/WqZ69759WccaKspRHXS+gO3MjmVz5H Z6HfrkPHsJDNFQBxbG4/f/4gOmrXHbe7o9njeKhrDHDoMMkZb0bAXkE9KoK+FX7SJlaQ 0AJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HFrQ92eC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113178-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id oo14-20020a05620a530e00b00789ee0124ccsi4240985qkn.151.2024.03.24.16.37.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:37:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HFrQ92eC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113178-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113178-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 458F71C21CC1 for ; Sun, 24 Mar 2024 23:37:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B087F1769FC; Sun, 24 Mar 2024 22:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HFrQ92eC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CADC41769E4; Sun, 24 Mar 2024 22:39:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319980; cv=none; b=FAgpeX2jj5pJf80n+QnkjqayjjXTwn9VA0WpsDpDeM9ptU/vfFb9uRwjcXZL+gqsfXMVJ9/o7Nx4nWFTRaHJUOmFVay53bJdvPHM8rGA5PuGdEdb3ZhWQ/mVLRIk/r21GsdUoqsHW5HKINURdqrqxcp1h/8c6zlJxkf+ycSqM0w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319980; c=relaxed/simple; bh=k9fXtCbqXNZ0AnUWWV++CufZSs17sIiecx+63pb9vlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uc122Fn+eTevhl5k7ihxwsZbrQbZpcDq0B76gPRYKu8NQthbfWp45xKiin9FqZW8RRSawON72wNyafJkqK1veauD8/nUv6FnhU2r8nZkrXdxs0VFwtLufG9hjmEw7GRTkh7qFsEXm8A5ckEbd4luH2WajnnE3OADlURScLUhj5c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HFrQ92eC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C06D6C433F1; Sun, 24 Mar 2024 22:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319980; bh=k9fXtCbqXNZ0AnUWWV++CufZSs17sIiecx+63pb9vlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HFrQ92eC45Ll9sTswyYvPNnBNyd+VjNjV3XLeYfAy6wbGj/FrHodv1s+/9W2TI3uF U9OstyeplxmTx5XUMxc7uZZyEtyllJbXAgzhV44COOFTAVxo3ztBqj8Giyqir4xlyT lL8eQJrdL+3PD5l58rlMpJjgH4Gw/5WOp1LOu7tiy/1LUfo6uWRc0UVaNNlkd96ToF V+I5wkLjb7AzU1qjlw5vEjJDJXava+7aA6274xiNT6QMn2nKGbNtHR/+6YlZQaeDtB 1CK85q+GgAnsjdm3tCJdmQYVYJZXqpnUXGJBjJEZWFNWsN+8Z+0lJtEn31hHfciKwv 60aOOvDOfVNYA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bitterblue Smith , Ping-Ke Shih , Kalle Valo , Sasha Levin Subject: [PATCH 6.8 287/715] wifi: rtw88: 8821cu: Fix firmware upload fail Date: Sun, 24 Mar 2024 18:27:46 -0400 Message-ID: <20240324223455.1342824-288-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Bitterblue Smith [ Upstream commit 41a7acb7dde8395f52a707bbba7712a898dfafb0 ] 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 Acked-by: Ping-Ke Shih Signed-off-by: Kalle Valo Link: https://msgid.link/f12ed39d-28e8-4b8b-8d22-447bcf295afc@gmail.com Signed-off-by: Sasha Levin --- drivers/net/wireless/realtek/rtw88/usb.c | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c index e6ab1ac6d7093..a0188511099a1 100644 --- a/drivers/net/wireless/realtek/rtw88/usb.c +++ b/drivers/net/wireless/realtek/rtw88/usb.c @@ -33,6 +33,36 @@ static void rtw_usb_fill_tx_checksum(struct rtw_usb *rtwusb, rtw_tx_fill_txdesc_checksum(rtwdev, &pkt_info, skb->data); } +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; + bool reg_on_section = false; + u16 t_reg = 0x4e0; + u8 t_len = 1; + int status; + + /* There are three sections: + * 1. on (0x00~0xFF; 0x1000~0x10FF): this section is always powered on + * 2. off (< 0xFE00, excluding "on" section): this section could be + * powered off + * 3. local (>= 0xFE00): usb specific registers section + */ + if (addr <= 0xff || (addr >= 0x1000 && addr <= 0x10ff)) + reg_on_section = true; + + if (!reg_on_section) + 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 +88,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); } @@ -102,6 +137,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.0