From: Hayes Wang <hayeswang@realtek.com>
To: <kuba@kernel.org>, <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <nic_swsd@realtek.com>,
<linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next 2/6] r8152: adjust rtl8152_check_firmware function
Date: Fri, 16 Apr 2021 16:04:33 +0800 [thread overview]
Message-ID: <1394712342-15778-352-Taiwan-albertk@realtek.com> (raw)
Message-ID: <20210416080433.eoGfE7SmSz9G1iT6ZPl4WM_udfvTSsCHnbm9qgetNJQ@z> (raw)
In-Reply-To: <1394712342-15778-350-Taiwan-albertk@realtek.com>
Use bits operations to record and check the firmware.
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
drivers/net/usb/r8152.c | 51 +++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 22 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 10db48f4ed77..28c9b4dc1a60 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -874,6 +874,14 @@ struct fw_header {
struct fw_block blocks[];
} __packed;
+enum rtl8152_fw_flags {
+ FW_FLAGS_USB = 0,
+ FW_FLAGS_PLA,
+ FW_FLAGS_START,
+ FW_FLAGS_STOP,
+ FW_FLAGS_NC,
+};
+
/**
* struct fw_mac - a firmware block used by RTL_FW_PLA and RTL_FW_USB.
* The layout of the firmware block is:
@@ -3800,10 +3808,7 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
{
const struct firmware *fw = rtl_fw->fw;
struct fw_header *fw_hdr = (struct fw_header *)fw->data;
- struct fw_mac *pla = NULL, *usb = NULL;
- struct fw_phy_patch_key *start = NULL;
- struct fw_phy_nc *phy_nc = NULL;
- struct fw_block *stop = NULL;
+ unsigned long fw_flags = 0;
long ret = -EFAULT;
int i;
@@ -3832,50 +3837,52 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
goto fail;
goto fw_end;
case RTL_FW_PLA:
- if (pla) {
+ if (test_bit(FW_FLAGS_PLA, &fw_flags)) {
dev_err(&tp->intf->dev,
"multiple PLA firmware encountered");
goto fail;
}
- pla = (struct fw_mac *)block;
- if (!rtl8152_is_fw_mac_ok(tp, pla)) {
+ if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) {
dev_err(&tp->intf->dev,
"check PLA firmware failed\n");
goto fail;
}
+ __set_bit(FW_FLAGS_PLA, &fw_flags);
break;
case RTL_FW_USB:
- if (usb) {
+ if (test_bit(FW_FLAGS_USB, &fw_flags)) {
dev_err(&tp->intf->dev,
"multiple USB firmware encountered");
goto fail;
}
- usb = (struct fw_mac *)block;
- if (!rtl8152_is_fw_mac_ok(tp, usb)) {
+ if (!rtl8152_is_fw_mac_ok(tp, (struct fw_mac *)block)) {
dev_err(&tp->intf->dev,
"check USB firmware failed\n");
goto fail;
}
+ __set_bit(FW_FLAGS_USB, &fw_flags);
break;
case RTL_FW_PHY_START:
- if (start || phy_nc || stop) {
+ if (test_bit(FW_FLAGS_START, &fw_flags) ||
+ test_bit(FW_FLAGS_NC, &fw_flags) ||
+ test_bit(FW_FLAGS_STOP, &fw_flags)) {
dev_err(&tp->intf->dev,
"check PHY_START fail\n");
goto fail;
}
- if (__le32_to_cpu(block->length) != sizeof(*start)) {
+ if (__le32_to_cpu(block->length) != sizeof(struct fw_phy_patch_key)) {
dev_err(&tp->intf->dev,
"Invalid length for PHY_START\n");
goto fail;
}
-
- start = (struct fw_phy_patch_key *)block;
+ __set_bit(FW_FLAGS_START, &fw_flags);
break;
case RTL_FW_PHY_STOP:
- if (stop || !start) {
+ if (test_bit(FW_FLAGS_STOP, &fw_flags) ||
+ !test_bit(FW_FLAGS_START, &fw_flags)) {
dev_err(&tp->intf->dev,
"Check PHY_STOP fail\n");
goto fail;
@@ -3886,28 +3893,28 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
"Invalid length for PHY_STOP\n");
goto fail;
}
-
- stop = block;
+ __set_bit(FW_FLAGS_STOP, &fw_flags);
break;
case RTL_FW_PHY_NC:
- if (!start || stop) {
+ if (!test_bit(FW_FLAGS_START, &fw_flags) ||
+ test_bit(FW_FLAGS_STOP, &fw_flags)) {
dev_err(&tp->intf->dev,
"check PHY_NC fail\n");
goto fail;
}
- if (phy_nc) {
+ if (test_bit(FW_FLAGS_NC, &fw_flags)) {
dev_err(&tp->intf->dev,
"multiple PHY NC encountered\n");
goto fail;
}
- phy_nc = (struct fw_phy_nc *)block;
- if (!rtl8152_is_fw_phy_nc_ok(tp, phy_nc)) {
+ if (!rtl8152_is_fw_phy_nc_ok(tp, (struct fw_phy_nc *)block)) {
dev_err(&tp->intf->dev,
"check PHY NC firmware failed\n");
goto fail;
}
+ __set_bit(FW_FLAGS_NC, &fw_flags);
break;
default:
@@ -3921,7 +3928,7 @@ static long rtl8152_check_firmware(struct r8152 *tp, struct rtl_fw *rtl_fw)
}
fw_end:
- if ((phy_nc || start) && !stop) {
+ if (test_bit(FW_FLAGS_START, &fw_flags) && !test_bit(FW_FLAGS_STOP, &fw_flags)) {
dev_err(&tp->intf->dev, "without PHY_STOP\n");
goto fail;
}
--
2.26.3
next prev parent reply other threads:[~2021-04-16 8:06 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-21 12:40 [PATCH net 0/9] r8152: serial fixes Hayes Wang
2020-01-21 12:40 ` [PATCH net 1/9] r8152: fix runtime resume for linking change Hayes Wang
2020-01-22 9:47 ` Sergei Shtylyov
2020-01-21 12:40 ` [PATCH net 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang
2020-01-21 12:54 ` David Miller
2020-01-21 13:01 ` Joe Perches
2020-01-21 13:19 ` Hayes Wang
2020-01-21 12:40 ` [PATCH net 3/9] r8152: get default setting of WOL before initializing Hayes Wang
2021-02-19 9:04 ` [PATCH net-next 0/4] r8152: minor adjustments Hayes Wang
2021-02-23 20:40 ` patchwork-bot+netdevbpf
2020-01-21 12:40 ` [PATCH net 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang
2021-02-19 9:04 ` [PATCH net-next 1/4] r8152: enable U1/U2 for USB_SPEED_SUPER Hayes Wang
2020-01-21 12:40 ` [PATCH net 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang
2021-02-19 9:04 ` [PATCH net-next 2/4] r8152: check if the pointer of the function exists Hayes Wang
2020-01-21 12:40 ` [PATCH net 6/9] r8152: disable test IO for RTL8153B Hayes Wang
2021-02-19 9:04 ` [PATCH net-next 3/4] r8152: replace netif_err with dev_err Hayes Wang
2020-01-21 12:40 ` [PATCH net 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang
2021-02-19 9:04 ` [PATCH net-next 4/4] r8152: spilt rtl_set_eee_plus and r8153b_green_en Hayes Wang
2020-01-21 12:40 ` [PATCH net 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang
2021-02-19 9:38 ` [PATCH net] r8152: move r8153_mac_clk_spd Hayes Wang
2021-02-19 18:22 ` Jakub Kicinski
2021-02-22 6:19 ` Hayes Wang
2020-01-21 12:40 ` [PATCH net 9/9] r8152: disable DelayPhyPwrChg Hayes Wang
2020-01-22 7:02 ` Grant Grundler
2020-01-22 7:50 ` Hayes Wang
2021-03-03 8:39 ` [PATCH net] Revert "r8152: adjust the settings about MAC clock speed down for RTL8153" Hayes Wang
2021-03-04 1:00 ` patchwork-bot+netdevbpf
2020-01-22 1:41 ` [PATCH net v2 0/9] r8152: serial fixes Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 1/9] r8152: fix runtime resume for linking change Hayes Wang
2021-03-19 7:37 ` [PATCH net] r8152: limit the RX buffer size of RTL8153A for USB 2.0 Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang
2021-04-16 8:04 ` [PATCH net-next 0/6] r8152: support new chips Hayes Wang
2021-04-16 22:40 ` patchwork-bot+netdevbpf
2020-01-22 1:41 ` [PATCH net v2 3/9] r8152: get default setting of WOL before initializing Hayes Wang
2021-04-16 8:04 ` [PATCH net-next 1/6] r8152: set inter fram gap time depending on speed Hayes Wang
2020-01-22 1:41 ` Hayes Wang [this message]
2021-04-16 8:04 ` [PATCH net-next 2/6] r8152: adjust rtl8152_check_firmware function Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang
2021-04-16 8:04 ` [PATCH net-next 3/6] r8152: add help function to change mtu Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 6/9] r8152: disable test IO for RTL8153B Hayes Wang
2021-04-16 8:04 ` [PATCH net-next 4/6] r8152: support new chips Hayes Wang
2021-04-16 21:50 ` Jakub Kicinski
2021-04-20 7:00 ` Hayes Wang
2021-04-20 18:34 ` Jakub Kicinski
2021-04-21 2:23 ` Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang
2021-04-16 8:04 ` [PATCH net-next 5/6] r8152: support PHY firmware for RTL8156 series Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang
2021-04-16 8:04 ` [PATCH net-next 6/6] r8152: search the configuration of vendor mode Hayes Wang
2020-01-22 1:41 ` [PATCH net v2 9/9] r8152: disable DelayPhyPwrChg Hayes Wang
2021-03-05 9:34 ` [PATCH net] r8169: fix r8168fp_adjust_ocp_cmd function Hayes Wang
2021-03-05 11:48 ` Heiner Kallweit
2021-03-05 21:10 ` patchwork-bot+netdevbpf
2020-01-22 8:02 ` [PATCH net v3 0/9] r8152: serial fixes Hayes Wang
2020-01-22 8:02 ` [PATCH net v3 1/9] r8152: fix runtime resume for linking change Hayes Wang
2021-04-23 9:44 ` [PATCH net-next 0/2] r8152: adjust REALTEK_USB_DEVICE Hayes Wang
2021-04-23 21:00 ` patchwork-bot+netdevbpf
2020-01-22 8:02 ` [PATCH net v3 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang
2021-04-23 9:44 ` [PATCH net-next 1/2] r8152: remove NCM mode from REALTEK_USB_DEVICE macro Hayes Wang
2020-01-22 8:02 ` [PATCH net v3 3/9] r8152: get default setting of WOL before initializing Hayes Wang
2021-04-23 9:44 ` [PATCH net-next 2/2] r8152: redefine REALTEK_USB_DEVICE macro Hayes Wang
2020-01-22 8:02 ` [PATCH net v3 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang
2021-04-24 6:09 ` [PATCH net-next] r8152: remove some bit operations Hayes Wang
2021-04-26 1:30 ` patchwork-bot+netdevbpf
2020-01-22 8:02 ` [PATCH net v3 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang
2021-05-21 9:07 ` [PATCH net] r8152: check the informaton of the device Hayes Wang
2021-05-21 9:42 ` Greg KH
2021-05-22 3:13 ` Hayes Wang
2020-01-22 8:02 ` [PATCH net v3 6/9] r8152: disable test IO for RTL8153B Hayes Wang
2021-05-22 5:24 ` [PATCH net v2] r8152: check the informaton of the device Hayes Wang
2021-05-22 7:32 ` Greg KH
2021-05-22 8:07 ` Johan Hovold
2021-05-24 1:49 ` Hayes Wang
2021-05-24 7:44 ` Johan Hovold
2020-01-22 8:02 ` [PATCH net v3 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang
2021-05-24 6:49 ` [PATCH net v3] r8152: check the informaton of the device Hayes Wang
2021-05-24 8:00 ` Johan Hovold
2021-05-24 8:54 ` Hayes Wang
2021-05-24 9:13 ` Johan Hovold
2021-05-24 20:20 ` patchwork-bot+netdevbpf
2020-01-22 8:02 ` [PATCH net v3 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang
2021-06-01 7:37 ` [PATCH net-next] r8152: support pauseparam of ethtool_ops Hayes Wang
2021-06-01 22:30 ` patchwork-bot+netdevbpf
2020-01-22 8:02 ` [PATCH net v3 9/9] r8152: disable DelayPhyPwrChg Hayes Wang
2021-06-17 10:00 ` [PATCH net-next] r8152: store the information of the pipes Hayes Wang
2021-06-17 19:20 ` patchwork-bot+netdevbpf
2020-01-23 10:21 ` [PATCH net v3 0/9] r8152: serial fixes David Miller
2021-04-22 8:48 ` [PATCH net-next] r8152: replace return with break for ram code speedup mode timeout Hayes Wang
2021-04-22 21:20 ` patchwork-bot+netdevbpf
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=1394712342-15778-352-Taiwan-albertk@realtek.com \
--to=hayeswang@realtek.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).