| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/02 04:53 | flow | patch-triage |
5mArgs:null Results: {
"EnableConfigs": [
"USB_RTL8152",
"USB_NET_DRIVERS",
"USB",
"NET"
],
"FocusSymbols": [
"rtl_tgphy_access",
"wait_tgphy_cmd_ready",
"rtl_fc_pause_pkt_en",
"r8157_phy_read",
"r8157_phy_write",
"rtl8157_enable",
"rtl8157_up",
"rtl8157_down",
"rtl8157_change_mtu",
"r8159_hw_phy_cfg",
"r8159_init",
"r8157_init",
"rtl8156b_enable",
"rtl8156b_init",
"wait_autoload_done",
"__rtl_get_pkg_det"
],
"KMSANReasoning": "The patch adds support for Realtek RTL8157 and RTL8159 chipsets in the r8152 USB ethernet driver. Key changes include:\n- Splitting RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100 using a package detection helper (__rtl_get_pkg_det).\n- Refactoring PHY and SRAM register access functions (ocp_reg_read, sram_read, sram2_read, r8152_mdio_read) to return status/error codes and write read values through pointer arguments.\n- Adding chipset-specific initialization, enable, suspend/resume, and hardware configuration routines.\n- Improving error checking in ethtool and ioctl handlers.\n\nRegarding KMSAN vs KASAN applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and info-leaks to userspace.\n- In all callers of the refactored read functions (ocp_reg_read, sram_read, etc.), the output variables are either explicitly pre-initialized (e.g. `data = 0` in r8153_phy_status and r8152_mmd_read) or are only read after verifying that the function returned non-negative success codes.\n- In `__rtl_get_pkg_det()`, the heap buffer `tmp` allocated via `kmalloc_obj()` is only accessed if `usb_control_msg()` returns `sizeof(*tmp)` (4 bytes); otherwise, a default initialized value (0) is returned.\n- In user-facing interfaces (such as `rtl8152_ioctl`, `rtl8152_get_pauseparam`, `r8153_get_eee`, and `rtl8152_get_link_ksettings`), error checks abort execution with a negative return code before any copying to userspace occurs, and output structures (`pause`, `data-\u003eval_out`, `eee`) are fully populated or zero-initialized.\n- No uninitialized data or kernel structure padding is exposed to userspace or used in control flow.\n\nTherefore, the patch does not introduce uninitialized memory risks that would require a dedicated KMSAN fuzzing session; standard KASAN/sanitizer testing is appropriate.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces and refactors substantial hardware initialization and configuration logic for RTL8156B, RTL8157, and RTL8159 USB Ethernet adapters in the r8152 driver. Changes include new TGPHY access routines (rtl_tgphy_access), pause packet count calculations (rtl_fc_pause_pkt_en), package detection (__rtl_get_pkg_det), polling helpers (wait_autoload_done), and revised WARN_ON_ONCE assertions during PHY configuration. These code paths are fully reachable in virtualized environments via USB device emulation (e.g. syzkaller syz_usb_connect / USB Raw Gadget) and subsequent network device and ethtool/ioctl operations.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/02 04:53 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 3cf8c5c313bdcfe921621a6dcd8d2353064c8dbd\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Fri Oct 2 04:53:29 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c\nindex af3d7dcb2f141..baac964fea80f 100644\n--- a/drivers/net/usb/r8152.c\n+++ b/drivers/net/usb/r8152.c\n@@ -64,6 +64,7 @@\n #define PLA_MACDBG_POST\t\t0xd38e\t/* RTL_VER_04 only */\n #define PLA_EXTRA_STATUS\t0xd398\n #define PLA_GPHY_CTRL\t\t0xd3ae\n+#define PLA_PKG_DET\t\t0xdc48\n #define PLA_POL_GPIO_CTRL\t0xdc6a\n #define PLA_EFUSE_DATA\t\t0xdd00\n #define PLA_EFUSE_CMD\t\t0xdd02\n@@ -78,6 +79,7 @@\n #define PLA_EEE_TXTWSYS_2P5G\t0xe058\n #define PLA_EEEP_CR\t\t0xe080\n #define PLA_MAC_PWR_CTRL\t0xe0c0\n+#define PLA_RMT_WAKE\t\t0xe0c8\n #define PLA_MAC_PWR_CTRL2\t0xe0ca\n #define PLA_MAC_PWR_CTRL3\t0xe0cc\n #define PLA_MAC_PWR_CTRL4\t0xe0ce\n@@ -87,6 +89,7 @@\n #define PLA_MTPS\t\t0xe615\n #define PLA_TXFIFO_CTRL\t\t0xe618\n #define PLA_TXFIFO_FULL\t\t0xe61a\n+#define PLA_PAUSE_LIMIT 0xe61e\n #define PLA_RSTTALLY\t\t0xe800\n #define PLA_CR\t\t\t0xe813\n #define PLA_CRWECR\t\t0xe81c\n@@ -129,6 +132,7 @@\n #define USB_BURST_SIZE\t\t0xcfc0\n #define USB_FW_FIX_EN0\t\t0xcfca\n #define USB_FW_FIX_EN1\t\t0xcfcc\n+#define USB_FW_USB_VER 0xcfd7\n #define USB_LPM_CONFIG\t\t0xcfd8\n #define USB_ECM_OPTION\t\t0xcfee\n #define USB_CSTMR\t\t0xcfef\t/* RTL8153A */\n@@ -160,6 +164,9 @@\n #define USB_ADV_ADDR\t\t0xd5d6\n #define USB_ADV_DATA\t\t0xd5d8\n #define USB_ADV_CMD\t\t0xd5dc\n+#define USB_TGPHY_ADDR\t\t0xd630\n+#define USB_TGPHY_DATA\t\t0xd632\n+#define USB_TGPHY_CMD\t\t0xd634\n #define USB_UPS_CTRL\t\t0xd800\n #define USB_POWER_CUT\t\t0xd80a\n #define USB_MISC_0\t\t0xd81a\n@@ -289,10 +296,17 @@\n #define IFG_144NS\t\tBIT(9)\n #define IFG_96NS\t\t(BIT(9) | BIT(8))\n \n+/* PLA_PKG_DET */\n+#define PKG_MASK\t\t0x1e\n+\n /* PLA_MTPS */\n #define MTPS_JUMBO\t\t(12 * 1024 / 64)\n #define MTPS_DEFAULT\t\t(6 * 1024 / 64)\n \n+/* PLA_PAUSE_LIMIT */\n+#define PAUSE_LIMIT_EN\t\tBIT(3)\n+#define PAUSE_LIMIT_MASK\t0xf0\n+\n /* PLA_RSTTALLY */\n #define TALLY_RESET\t\t0x0001\n \n@@ -371,6 +385,9 @@\n #define MCU_CLK_RATIO_MASK\t0x0f0f0f0f\n #define ALDPS_SPDWN_RATIO\t0x0f87\n \n+/* PLA_RMT_WAKE */\n+#define RMT_WAKE_EN\t\tBIT(0)\n+\n /* PLA_MAC_PWR_CTRL2 */\n #define EEE_SPDWN_RATIO\t\t0x8007\n #define MAC_CLK_SPDWN_EN\tBIT(15)\n@@ -417,6 +434,7 @@\n \n /* PLA_INDICATE_FALG */\n #define UPCOMING_RUNTIME_D3\tBIT(0)\n+#define PREBOOT_OPTION\t\tBIT(1)\n \n /* PLA_MACDBG_PRE and PLA_MACDBG_POST */\n #define DEBUG_OE\t\tBIT(0)\n@@ -502,6 +520,10 @@\n #define ADV_CMD_WR\t\tBIT(1)\n #define ADV_CMD_IP\t\tBIT(2)\n \n+/* USB_TGPHY_CMD */\n+#define TGPHY_CMD_BUSY\t\tBIT(0)\n+#define TGPHY_CMD_WR\t\tBIT(1)\n+\n /* USB_UPS_CTRL */\n #define POWER_CUT\t\t0x0100\n \n@@ -542,6 +564,7 @@\n #define RX_AGG_DISABLE\t\t0x0010\n #define RX_ZERO_EN\t\t0x0080\n #define RX_DESC_16B\t\t0x0400\n+#define RX_END_TRANSFER_EN\tBIT(11)\n \n /* USB_U2P3_CTRL */\n #define U2P3_ENABLE\t\t0x0001\n@@ -597,6 +620,11 @@\n #define UPS_FLAGS_250M_CKDIV\t\tBIT(2)\n #define UPS_FLAGS_EN_ALDPS\t\tBIT(3)\n #define UPS_FLAGS_CTAP_SHORT_DIS\tBIT(4)\n+#define UPS_FLAGS_EN_100M_EEE\t\tBIT(9)\n+#define UPS_FLAGS_EN_1000M_EEE\t\tBIT(10)\n+#define UPS_FLAGS_EN_2500M_EEE\t\tBIT(11)\n+#define UPS_FLAGS_EN_5000M_EEE\t\tBIT(12)\n+#define UPS_FLAGS_EN_10G_EEE\t\tBIT(13)\n #define UPS_FLAGS_SPEED_MASK\t\t(0xf \u003c\u003c 16)\n #define ups_flags_speed(x)\t\t((x) \u003c\u003c 16)\n #define UPS_FLAGS_EN_EEE\t\tBIT(20)\n@@ -645,6 +673,7 @@ enum spd_duplex {\n /* OCP_POWER_CFG */\n #define EEE_CLKDIV_EN\t\t0x8000\n #define EN_ALDPS\t\t0x0004\n+#define EN_ALDPS_PLLOFF 0x0002\n #define EN_10M_PLLOFF\t\t0x0001\n \n /* OCP_EEE_CONFIG1 */\n@@ -948,6 +977,8 @@ struct r8152 {\n \t\tvoid (*hw_phy_cfg)(struct r8152 *tp);\n \t\tvoid (*autosuspend_en)(struct r8152 *tp, bool enable);\n \t\tvoid (*change_mtu)(struct r8152 *tp);\n+\t\tint (*phy_read)(struct r8152 *tp, u16 addr, u16 *data);\n+\t\tint (*phy_write)(struct r8152 *tp, u16 addr, u16 data);\n \t} rtl_ops;\n \n \tstruct ups_info {\n@@ -1247,7 +1278,8 @@ enum rtl_version {\n \tRTL_VER_14,\n \tRTL_VER_15,\n \tRTL_VER_16,\n-\tRTL_VER_17,\n+\tRTL_VER_17_QFN68,\n+\tRTL_VER_17_QFN100,\n \n \tRTL_VER_MAX\n };\n@@ -1626,7 +1658,7 @@ static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)\n \tgeneric_ocp_write(tp, index, byen, sizeof(tmp), \u0026tmp, type);\n }\n \n-static u16 ocp_reg_read(struct r8152 *tp, u16 addr)\n+static int r8152_phy_read(struct r8152 *tp, u16 addr, u16 *data)\n {\n \tu16 ocp_base, ocp_index;\n \n@@ -1637,10 +1669,12 @@ static u16 ocp_reg_read(struct r8152 *tp, u16 addr)\n \t}\n \n \tocp_index = (addr \u0026 0x0fff) | 0xb000;\n-\treturn ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);\n+\t*data = ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);\n+\n+\treturn 0;\n }\n \n-static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)\n+static int r8152_phy_write(struct r8152 *tp, u16 addr, u16 data)\n {\n \tu16 ocp_base, ocp_index;\n \n@@ -1652,16 +1686,33 @@ static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)\n \n \tocp_index = (addr \u0026 0x0fff) | 0xb000;\n \tocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);\n+\n+\treturn 0;\n }\n \n-static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)\n+static int ocp_reg_read(struct r8152 *tp, u16 addr, u16 *data)\n {\n-\tocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);\n+\treturn tp-\u003ertl_ops.phy_read(tp, addr, data);\n }\n \n-static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)\n+static int ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)\n {\n-\treturn ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);\n+\treturn tp-\u003ertl_ops.phy_write(tp, addr, data);\n+}\n+\n+static inline int r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)\n+{\n+\treturn ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);\n+}\n+\n+static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)\n+{\n+\tu16 data;\n+\tint ret;\n+\n+\tret = ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2, \u0026data);\n+\n+\treturn ret \u003c 0 ? ret : data;\n }\n \n static int wait_cmd_ready(struct r8152 *tp, u16 cmd)\n@@ -1780,16 +1831,32 @@ static int rtl_ip_set_bits(struct r8152 *tp, u16 addr, u32 set)\n \treturn rtl_ip_w0w1(tp, addr, 0, set);\n }\n \n-static void sram_write(struct r8152 *tp, u16 addr, u16 data)\n+static int sram_write(struct r8152 *tp, u16 addr, u16 data)\n {\n-\tocp_reg_write(tp, OCP_SRAM_ADDR, addr);\n-\tocp_reg_write(tp, OCP_SRAM_DATA, data);\n+\tint ret;\n+\n+\tret = ocp_reg_write(tp, OCP_SRAM_ADDR, addr);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = ocp_reg_write(tp, OCP_SRAM_DATA, data);\n+\n+out:\n+\treturn ret;\n }\n \n-static u16 sram_read(struct r8152 *tp, u16 addr)\n+static int sram_read(struct r8152 *tp, u16 addr, u16 *data)\n {\n-\tocp_reg_write(tp, OCP_SRAM_ADDR, addr);\n-\treturn ocp_reg_read(tp, OCP_SRAM_DATA);\n+\tint ret;\n+\n+\tret = ocp_reg_write(tp, OCP_SRAM_ADDR, addr);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = ocp_reg_read(tp, OCP_SRAM_DATA, data);\n+\n+out:\n+\treturn ret;\n }\n \n static int read_mii_word(struct net_device *netdev, int phy_id, int reg)\n@@ -1894,90 +1961,219 @@ static void ocp_byte_set_bits(struct r8152 *tp, u16 type, u16 index, u8 set)\n \tocp_byte_w0w1(tp, type, index, 0, set);\n }\n \n-static void ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n+static int ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n {\n \tu16 data;\n+\tint ret;\n+\n+\tret = ocp_reg_read(tp, addr, \u0026data);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n \n-\tdata = ocp_reg_read(tp, addr);\n \tdata = (data \u0026 ~clear) | set;\n-\tocp_reg_write(tp, addr, data);\n+\tret = ocp_reg_write(tp, addr, data);\n+\n+out:\n+\treturn ret;\n }\n \n-static void ocp_reg_clr_bits(struct r8152 *tp, u16 addr, u16 clear)\n+static int ocp_reg_clr_bits(struct r8152 *tp, u16 addr, u16 clear)\n {\n-\tocp_reg_w0w1(tp, addr, clear, 0);\n+\treturn ocp_reg_w0w1(tp, addr, clear, 0);\n }\n \n-static void ocp_reg_set_bits(struct r8152 *tp, u16 addr, u16 set)\n+static int ocp_reg_set_bits(struct r8152 *tp, u16 addr, u16 set)\n {\n-\tocp_reg_w0w1(tp, addr, 0, set);\n+\treturn ocp_reg_w0w1(tp, addr, 0, set);\n }\n \n-static void sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n+static int sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n {\n \tu16 data;\n+\tint ret;\n+\n+\tret = sram_read(tp, addr, \u0026data);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n \n-\tdata = sram_read(tp, addr);\n \tdata = (data \u0026 ~clear) | set;\n-\tocp_reg_write(tp, OCP_SRAM_DATA, data);\n+\tret = ocp_reg_write(tp, OCP_SRAM_DATA, data);\n+\n+out:\n+\treturn ret;\n }\n \n-static void sram_clr_bits(struct r8152 *tp, u16 addr, u16 clear)\n+static int sram_clr_bits(struct r8152 *tp, u16 addr, u16 clear)\n {\n-\tsram_write_w0w1(tp, addr, clear, 0);\n+\treturn sram_write_w0w1(tp, addr, clear, 0);\n }\n \n-static void sram_set_bits(struct r8152 *tp, u16 addr, u16 set)\n+static int sram_set_bits(struct r8152 *tp, u16 addr, u16 set)\n {\n-\tsram_write_w0w1(tp, addr, 0, set);\n+\treturn sram_write_w0w1(tp, addr, 0, set);\n }\n \n-static void sram2_write(struct r8152 *tp, u16 addr, u16 data)\n+static int sram2_write(struct r8152 *tp, u16 addr, u16 data)\n {\n-\tocp_reg_write(tp, OCP_SRAM2_ADDR, addr);\n-\tocp_reg_write(tp, OCP_SRAM2_DATA, data);\n+\tint ret;\n+\n+\tret = ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = ocp_reg_write(tp, OCP_SRAM2_DATA, data);\n+\n+out:\n+\treturn ret;\n }\n \n-static u16 sram2_read(struct r8152 *tp, u16 addr)\n+static int sram2_read(struct r8152 *tp, u16 addr, u16 *data)\n {\n-\tocp_reg_write(tp, OCP_SRAM2_ADDR, addr);\n-\treturn ocp_reg_read(tp, OCP_SRAM2_DATA);\n+\tint ret;\n+\n+\tret = ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = ocp_reg_read(tp, OCP_SRAM2_DATA, data);\n+\n+out:\n+\treturn ret;\n }\n \n-static void sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n+static int sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n {\n \tu16 data;\n+\tint ret;\n+\n+\tret = sram2_read(tp, addr, \u0026data);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n \n-\tdata = sram2_read(tp, addr);\n \tdata = (data \u0026 ~clear) | set;\n-\tocp_reg_write(tp, OCP_SRAM2_DATA, data);\n+\tret = ocp_reg_write(tp, OCP_SRAM2_DATA, data);\n+\n+out:\n+\treturn ret;\n }\n \n-static void r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)\n+static int sram2_set_bits(struct r8152 *tp, u16 addr, u16 set)\n+{\n+\treturn sram2_write_w0w1(tp, addr, 0, set);\n+}\n+\n+static int sram2_clr_bits(struct r8152 *tp, u16 addr, u16 clear)\n+{\n+\treturn sram2_write_w0w1(tp, addr, clear, 0);\n+}\n+\n+static int r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)\n {\n \tint data;\n \n \tdata = r8152_mdio_read(tp, addr);\n-\tr8152_mdio_write(tp, addr, data \u0026 ~clear);\n+\tif (data \u003c 0)\n+\t\tgoto out;\n+\n+\tdata = r8152_mdio_write(tp, addr, data \u0026 ~clear);\n+\n+out:\n+\treturn data;\n }\n \n-static void r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)\n+static int r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)\n {\n \tint data;\n \n \tdata = r8152_mdio_read(tp, addr);\n-\tr8152_mdio_write(tp, addr, data | set);\n+\tif (data \u003c 0)\n+\t\tgoto out;\n+\n+\tdata = r8152_mdio_write(tp, addr, data | set);\n+\n+out:\n+\treturn data;\n }\n \n static int r8152_mdio_test_and_clr_bit(struct r8152 *tp, u16 addr, u16 clear)\n {\n-\tint data;\n+\tint data, ret;\n \n-\tdata = r8152_mdio_read(tp, addr);\n-\tif (data \u0026 clear)\n-\t\tr8152_mdio_write(tp, addr, data \u0026 ~clear);\n+\tret = r8152_mdio_read(tp, addr);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tdata = ret;\n+\tif (data \u0026 clear) {\n+\t\tret = r8152_mdio_write(tp, addr, data \u0026 ~clear);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out;\n+\t}\n+\n+\tret = !!(data \u0026 clear);\n+\n+out:\n+\treturn ret;\n+}\n+\n+static int wait_tgphy_cmd_ready(struct r8152 *tp)\n+{\n+\tu16 ocp_data;\n+\tint ret;\n+\n+\tret = read_poll_timeout(ocp_read_word, ocp_data,\n+\t\t\t\ttest_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags) ||\n+\t\t\t\t!(ocp_data \u0026 TGPHY_CMD_BUSY),\n+\t\t\t\t2000, 20000, false, tp,\n+\t\t\t\tMCU_TYPE_USB, USB_TGPHY_CMD);\n+\n+\tif (ret) {\n+\t\trtl_set_inaccessible(tp);\n+\t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"TGPHY cmd busy timeout\\n\");\n+\t}\n+\n+\treturn test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags) ? -ENODEV : ret;\n+}\n+\n+static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data, bool write)\n+{\n+\tu16 cmd = 0;\n+\tint ret;\n+\n+\tret = wait_tgphy_cmd_ready(tp);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tif (write) {\n+\t\tcmd |= TGPHY_CMD_WR;\n+\t\tocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA, *data);\n+\t}\n+\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_ADDR, addr);\n+\n+\tcmd |= TGPHY_CMD_BUSY;\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_CMD, cmd);\n+\n+\tif (!write) {\n+\t\tret = wait_tgphy_cmd_ready(tp);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out;\n+\n+\t\t*data = ocp_read_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA);\n+\t}\n+\n+out:\n+\treturn test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags) ? -ENODEV : ret;\n+}\n+\n+static int r8157_phy_read(struct r8152 *tp, u16 addr, u16 *data)\n+{\n+\treturn rtl_tgphy_access(tp, addr, data, false);\n+}\n \n-\treturn data \u0026 clear;\n+static int r8157_phy_write(struct r8152 *tp, u16 addr, u16 data)\n+{\n+\treturn rtl_tgphy_access(tp, addr, \u0026data, true);\n }\n \n static int\n@@ -3412,7 +3608,8 @@ static void rtl8152_nic_reset(struct r8152 *tp)\n \t\tbreak;\n \n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_CR, CR_RE | CR_TE);\n \t\tbreak;\n \n@@ -3452,7 +3649,7 @@ static void rtl_eee_plus_en(struct r8152 *tp, bool enable)\n \n static void rtl_set_eee_plus(struct r8152 *tp)\n {\n-\tif (tp-\u003eversion == RTL_VER_17)\n+\tif (tp-\u003eversion == RTL_VER_17_QFN68 || tp-\u003eversion == RTL_VER_17_QFN100)\n \t\treturn rtl_eee_plus_en(tp, false);\n \n \tif (rtl8152_get_speed(tp) \u0026 _10bps)\n@@ -3640,7 +3837,8 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp)\n \tcase RTL_VER_13:\n \tcase RTL_VER_15:\n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,\n \t\t\t 640 / 8);\n \t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,\n@@ -3685,7 +3883,8 @@ static void r8153_set_rx_early_size(struct r8152 *tp)\n \t\t\t ocp_data / 8);\n \t\tbreak;\n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,\n \t\t\t ocp_data / 16);\n \t\tbreak;\n@@ -3801,6 +4000,8 @@ static void rtl_rx_vlan_en(struct r8152 *tp, bool enable)\n \tcase RTL_VER_13:\n \tcase RTL_VER_15:\n \tcase RTL_VER_16:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \tdefault:\n \t\tif (enable)\n \t\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_RCR1,\n@@ -4051,8 +4252,27 @@ static void r8156_ups_flags(struct r8152 *tp)\n \tif (tp-\u003eups_info.aldps)\n \t\tups_flags |= UPS_FLAGS_EN_ALDPS;\n \n-\tif (tp-\u003eups_info.eee)\n-\t\tups_flags |= UPS_FLAGS_EN_EEE;\n+\tif (tp-\u003eups_info.eee) {\n+\t\tswitch (tp-\u003eversion) {\n+\t\tcase RTL_VER_17_QFN68:\n+\t\t\tif (tp-\u003eeee_adv \u0026 MDIO_EEE_10GT)\n+\t\t\t\tups_flags |= UPS_FLAGS_EN_10G_EEE;\n+\t\t\tfallthrough;\n+\t\tcase RTL_VER_16:\n+\t\t\tif (tp-\u003eeee_adv \u0026 MDIO_EEE_100TX)\n+\t\t\t\tups_flags |= UPS_FLAGS_EN_100M_EEE;\n+\t\t\tif (tp-\u003eeee_adv \u0026 MDIO_EEE_1000T)\n+\t\t\t\tups_flags |= UPS_FLAGS_EN_1000M_EEE;\n+\t\t\tif (tp-\u003eeee_adv2 \u0026 MDIO_EEE_2_5GT)\n+\t\t\t\tups_flags |= UPS_FLAGS_EN_2500M_EEE;\n+\t\t\tif (tp-\u003eeee_adv2 \u0026 MDIO_EEE_5GT)\n+\t\t\t\tups_flags |= UPS_FLAGS_EN_5000M_EEE;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tups_flags |= UPS_FLAGS_EN_EEE;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n \n \tif (tp-\u003eups_info.flow_control)\n \t\tups_flags |= UPS_FLAGS_EN_FLOW_CTR;\n@@ -4103,20 +4323,33 @@ static void r8156_ups_flags(struct r8152 *tp)\n \tcase NWAY_2500M_FULL:\n \t\tups_flags |= ups_flags_speed(9);\n \t\tbreak;\n+\tcase NWAY_5000M_FULL:\n+\t\tups_flags |= ups_flags_speed(10);\n+\t\tbreak;\n+\tcase NWAY_10000M_FULL:\n+\t\tups_flags |= ups_flags_speed(11);\n+\t\tbreak;\n \tdefault:\n \t\tbreak;\n \t}\n \n-\tswitch (tp-\u003eups_info.lite_mode) {\n-\tcase 1:\n-\t\tups_flags |= 0 \u003c\u003c 5;\n-\t\tbreak;\n-\tcase 2:\n-\t\tups_flags |= 2 \u003c\u003c 5;\n+\tswitch (tp-\u003eversion) {\n+\tcase RTL_VER_16:\n+\tcase RTL_VER_17_QFN68:\n \t\tbreak;\n-\tcase 0:\n \tdefault:\n-\t\tups_flags |= 1 \u003c\u003c 5;\n+\t\tswitch (tp-\u003eups_info.lite_mode) {\n+\t\tcase 1:\n+\t\t\tups_flags |= 0 \u003c\u003c 5;\n+\t\t\tbreak;\n+\t\tcase 2:\n+\t\t\tups_flags |= 2 \u003c\u003c 5;\n+\t\t\tbreak;\n+\t\tcase 0:\n+\t\tdefault:\n+\t\t\tups_flags |= 1 \u003c\u003c 5;\n+\t\t\tbreak;\n+\t\t}\n \t\tbreak;\n \t}\n \n@@ -4150,11 +4383,13 @@ static void r8153b_green_en(struct r8152 *tp, bool enable)\n \n static u16 r8153_phy_status(struct r8152 *tp, u16 desired)\n {\n-\tu16 data;\n+\tu16 data = 0;\n \tint i;\n \n \tfor (i = 0; i \u003c 500; i++) {\n-\t\tdata = ocp_reg_read(tp, OCP_PHY_STATUS);\n+\t\tif (ocp_reg_read(tp, OCP_PHY_STATUS, \u0026data) \u003c 0)\n+\t\t\tbreak;\n+\n \t\tdata \u0026= PHY_STAT_MASK;\n \t\tif (desired) {\n \t\t\tif (data == desired)\n@@ -4172,6 +4407,23 @@ static u16 r8153_phy_status(struct r8152 *tp, u16 desired)\n \treturn data;\n }\n \n+static int wait_autoload_done(struct r8152 *tp)\n+{\n+\tu16 ocp_data;\n+\tint ret;\n+\n+\tret = read_poll_timeout(ocp_read_word, ocp_data,\n+\t\t\t\ttest_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags) ||\n+\t\t\t\t(ocp_data \u0026 AUTOLOAD_DONE),\n+\t\t\t\t20000, 10 * USEC_PER_SEC, false, tp,\n+\t\t\t\tMCU_TYPE_PLA, PLA_BOOT_CTRL);\n+\n+\tif (ret)\n+\t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"autoload done timeout\\n\");\n+\n+\treturn test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags) ? -ENODEV : 0;\n+}\n+\n static void r8153b_ups_en(struct r8152 *tp, bool enable)\n {\n \tif (enable) {\n@@ -4190,16 +4442,8 @@ static void r8153b_ups_en(struct r8152 *tp, bool enable)\n \t\t\t\t UPS_FORCE_PWR_DOWN);\n \n \t\tif (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) \u0026 PCUT_STATUS) {\n-\t\t\tint i;\n-\n-\t\t\tfor (i = 0; i \u003c 500; i++) {\n-\t\t\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\t\t\treturn;\n-\t\t\t\tif (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) \u0026\n-\t\t\t\t AUTOLOAD_DONE)\n-\t\t\t\t\tbreak;\n-\t\t\t\tmsleep(20);\n-\t\t\t}\n+\t\t\tif (wait_autoload_done(tp))\n+\t\t\t\treturn;\n \n \t\t\ttp-\u003ertl_ops.hw_phy_cfg(tp);\n \n@@ -4227,16 +4471,8 @@ static void r8153c_ups_en(struct r8152 *tp, bool enable)\n \t\t\t\t UPS_FORCE_PWR_DOWN);\n \n \t\tif (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) \u0026 PCUT_STATUS) {\n-\t\t\tint i;\n-\n-\t\t\tfor (i = 0; i \u003c 500; i++) {\n-\t\t\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\t\t\treturn;\n-\t\t\t\tif (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) \u0026\n-\t\t\t\t AUTOLOAD_DONE)\n-\t\t\t\t\tbreak;\n-\t\t\t\tmsleep(20);\n-\t\t\t}\n+\t\t\tif (wait_autoload_done(tp))\n+\t\t\t\treturn;\n \n \t\t\ttp-\u003ertl_ops.hw_phy_cfg(tp);\n \n@@ -4288,6 +4524,49 @@ static void r8156_ups_en(struct r8152 *tp, bool enable)\n \t}\n }\n \n+static void r8157_ups_en(struct r8152 *tp, bool enable)\n+{\n+\tif (enable) {\n+\t\tr8156_ups_flags(tp);\n+\n+\t\tocp_byte_set_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,\n+\t\t\t\t UPS_EN | USP_PREWAKE | PHASE2_EN);\n+\n+\t\tocp_byte_set_bits(tp, MCU_TYPE_USB, USB_MISC_2,\n+\t\t\t\t UPS_FORCE_PWR_DOWN);\n+\t} else {\n+\t\tocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,\n+\t\t\t\t UPS_EN | USP_PREWAKE);\n+\n+\t\tocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_MISC_2,\n+\t\t\t\t UPS_FORCE_PWR_DOWN);\n+\n+\t\tif (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) \u0026 PCUT_STATUS) {\n+\t\t\tu32 ocp_data;\n+\t\t\tint ret;\n+\n+\t\t\tret = read_poll_timeout(ocp_read_word, ocp_data,\n+\t\t\t\t\t\tocp_data \u0026 BACKUP_RESTRORE, 200,\n+\t\t\t\t\t\t20000, false, tp, MCU_TYPE_USB,\n+\t\t\t\t\t\tUSB_GPHY_CTRL);\n+\t\t\tif (ret) {\n+\t\t\t\trtl_set_inaccessible(tp);\n+\t\t\t\tdev_err(\u0026tp-\u003eintf-\u003edev,\n+\t\t\t\t\t\"backup-restore timed out\\n\");\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\t/* clear USB fw_ver_reg */\n+\t\t\tocp_write_byte(tp, MCU_TYPE_USB, USB_FW_USB_VER, 0);\n+\n+\t\t\ttp-\u003ertl_ops.hw_phy_cfg(tp);\n+\n+\t\t\trtl8152_set_speed(tp, tp-\u003eautoneg, tp-\u003espeed,\n+\t\t\t\t\t tp-\u003eduplex, tp-\u003eadvertising);\n+\t\t}\n+\t}\n+}\n+\n static void r8153_power_cut_en(struct r8152 *tp, bool enable)\n {\n \tif (enable)\n@@ -4446,9 +4725,28 @@ static void rtl8157_runtime_enable(struct r8152 *tp, bool enable)\n \t\tr8153b_u1u2en(tp, false);\n \t\tr8157_u2p3en(tp, false);\n \t\trtl_runtime_suspend_enable(tp, true);\n+\n+\t\tswitch (tp-\u003eversion) {\n+\t\tcase RTL_VER_16:\n+\t\tcase RTL_VER_17_QFN68:\n+\t\t\tr8157_ups_en(tp, true);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n \t} else {\n \t\tr8153_queue_wake(tp, false);\n \t\trtl_runtime_suspend_enable(tp, false);\n+\n+\t\tswitch (tp-\u003eversion) {\n+\t\tcase RTL_VER_16:\n+\t\tcase RTL_VER_17_QFN68:\n+\t\t\tr8157_ups_en(tp, false);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tr8157_u2p3en(tp, true);\n \t\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n \t\t\tr8153b_u1u2en(tp, true);\n@@ -4480,6 +4778,8 @@ static void r8153_teredo_off(struct r8152 *tp)\n \tcase RTL_VER_14:\n \tcase RTL_VER_15:\n \tcase RTL_VER_16:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \tdefault:\n \t\t/* The bit 0 ~ 7 are relative with teredo settings. They are\n \t\t * W1C (write 1 to clear), so set all 1 to disable it.\n@@ -4534,7 +4834,8 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)\n \t\tbreak;\n \tcase RTL_VER_14:\n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \tdefault:\n \t\tocp_write_word(tp, type, USB_BP2_EN, 0);\n \t\tbp_num = 16;\n@@ -4556,7 +4857,8 @@ static inline void rtl_reset_ocp_base(struct r8152 *tp)\n static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)\n {\n \tu16 check;\n-\tint i;\n+\tu16 ocp_data;\n+\tint i, ret;\n \n \tif (request) {\n \t\tocp_reg_set_bits(tp, OCP_PHY_PATCH_CMD, PATCH_REQUEST);\n@@ -4567,25 +4869,29 @@ static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)\n \t}\n \n \tfor (i = 0; wait \u0026\u0026 i \u003c 5000; i++) {\n-\t\tu32 ocp_data;\n-\n \t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\t\treturn -ENODEV;\n \n \t\tusleep_range(1000, 2000);\n-\t\tocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT);\n-\t\tif ((ocp_data \u0026 PATCH_READY) ^ check)\n+\t\tret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, \u0026ocp_data);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\t\telse if ((ocp_data \u0026 PATCH_READY) ^ check)\n \t\t\tbreak;\n \t}\n \n-\tif (request \u0026\u0026 wait \u0026\u0026\n-\t !(ocp_reg_read(tp, OCP_PHY_PATCH_STAT) \u0026 PATCH_READY)) {\n-\t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"PHY patch request fail\\n\");\n-\t\trtl_phy_patch_request(tp, false, false);\n-\t\treturn -ETIME;\n-\t} else {\n-\t\treturn 0;\n+\tif (request \u0026\u0026 wait) {\n+\t\tret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, \u0026ocp_data);\n+\t\tif (ret \u003c 0) {\n+\t\t\treturn ret;\n+\t\t} else if (!(ocp_data \u0026 PATCH_READY)) {\n+\t\t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"PHY patch request fail\\n\");\n+\t\t\trtl_phy_patch_request(tp, false, false);\n+\t\t\treturn -ETIME;\n+\t\t}\n \t}\n+\n+\treturn 0;\n }\n \n static void rtl_patch_key_set(struct r8152 *tp, u16 key_addr, u16 patch_key)\n@@ -4646,7 +4952,8 @@ static bool rtl8152_is_fw_phy_speed_up_ok(struct r8152 *tp, struct fw_phy_speed_\n \tcase RTL_VER_13:\n \tcase RTL_VER_15:\n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \tdefault:\n \t\tbreak;\n \t}\n@@ -5299,10 +5606,14 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,\n {\n \tu32 len;\n \tu8 *data;\n+\tu16 ver;\n \n \trtl_reset_ocp_base(tp);\n \n-\tif (sram_read(tp, SRAM_GPHY_FW_VER) \u003e= __le16_to_cpu(phy-\u003eversion)) {\n+\tif (sram_read(tp, SRAM_GPHY_FW_VER, \u0026ver) \u003c 0)\n+\t\treturn;\n+\n+\tif (ver \u003e= __le16_to_cpu(phy-\u003eversion)) {\n \t\tdev_dbg(\u0026tp-\u003eintf-\u003edev, \"PHY firmware has been the newest\\n\");\n \t\treturn;\n \t}\n@@ -5349,7 +5660,8 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,\n \n \trtl_phy_patch_request(tp, false, wait);\n \n-\tif (sram_read(tp, SRAM_GPHY_FW_VER) == __le16_to_cpu(phy-\u003eversion))\n+\tif (sram_read(tp, SRAM_GPHY_FW_VER, \u0026ver) \u003e= 0 \u0026\u0026\n+\t ver == __le16_to_cpu(phy-\u003eversion))\n \t\tdev_dbg(\u0026tp-\u003eintf-\u003edev, \"successfully applied %s\\n\", phy-\u003einfo);\n \telse\n \t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"ram code speedup mode fail\\n\");\n@@ -5357,14 +5669,17 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,\n \n static int rtl8152_fw_phy_ver(struct r8152 *tp, struct fw_phy_ver *phy_ver)\n {\n-\tu16 ver_addr, ver;\n+\tu16 ver_addr, ver, cur_ver;\n \n \tver_addr = __le16_to_cpu(phy_ver-\u003ever.addr);\n \tver = __le16_to_cpu(phy_ver-\u003ever.data);\n \n \trtl_reset_ocp_base(tp);\n \n-\tif (sram_read(tp, ver_addr) \u003e= ver) {\n+\tif (sram_read(tp, ver_addr, \u0026cur_ver) \u003c 0)\n+\t\treturn 0;\n+\n+\tif (cur_ver \u003e= ver) {\n \t\tdev_dbg(\u0026tp-\u003eintf-\u003edev, \"PHY firmware has been the newest\\n\");\n \t\treturn 0;\n \t}\n@@ -5383,7 +5698,8 @@ static void rtl8152_fw_phy_fixup(struct r8152 *tp, struct fw_phy_fixup *fix)\n \trtl_reset_ocp_base(tp);\n \n \taddr = __le16_to_cpu(fix-\u003esetting.addr);\n-\tdata = ocp_reg_read(tp, addr);\n+\tif (ocp_reg_read(tp, addr, \u0026data) \u003c 0)\n+\t\treturn;\n \n \tswitch (__le16_to_cpu(fix-\u003ebit_cmd)) {\n \tcase FW_FIXUP_AND:\n@@ -5687,10 +6003,10 @@ static inline void r8152_mmd_indirect(struct r8152 *tp, u16 dev, u16 reg)\n \n static u16 r8152_mmd_read(struct r8152 *tp, u16 dev, u16 reg)\n {\n-\tu16 data;\n+\tu16 data = 0;\n \n \tr8152_mmd_indirect(tp, dev, reg);\n-\tdata = ocp_reg_read(tp, OCP_EEE_DATA);\n+\tocp_reg_read(tp, OCP_EEE_DATA, \u0026data);\n \tocp_reg_write(tp, OCP_EEE_AR, 0x0000);\n \n \treturn data;\n@@ -5755,7 +6071,8 @@ static void r8156_eee_en(struct r8152 *tp, bool enable)\n \n \tr8153_eee_en(tp, enable);\n \n-\tconfig = ocp_reg_read(tp, OCP_EEE_ADV2);\n+\tif (ocp_reg_read(tp, OCP_EEE_ADV2, \u0026config) \u003c 0)\n+\t\treturn;\n \n \tif (enable \u0026\u0026 (tp-\u003eeee_adv2 \u0026 MDIO_EEE_2_5GT))\n \t\tconfig |= MDIO_EEE_2_5GT;\n@@ -5806,7 +6123,8 @@ static void rtl_eee_enable(struct r8152 *tp, bool enable)\n \tcase RTL_VER_13:\n \tcase RTL_VER_15:\n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\tif (enable) {\n \t\t\tr8156_eee_en(tp, true);\n \t\t\tocp_reg_write(tp, OCP_EEE_ADV, tp-\u003eeee_adv);\n@@ -5961,27 +6279,126 @@ static void r8152b_enter_oob(struct r8152 *tp)\n \t\t\t RCR_APM | RCR_AM | RCR_AB);\n }\n \n-static int r8153_pre_firmware_1(struct r8152 *tp)\n+static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)\n {\n-\tint i;\n+\tint log2_ratio, ratio;\n+\tu16 num_pause_pkts;\n+\tu32 ocp_data;\n \n-\t/* Wait till the WTD timer is ready. It would take at most 104 ms. */\n-\tfor (i = 0; i \u003c 104; i++) {\n-\t\tu32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL);\n+\tswitch (tp-\u003eversion) {\n+\tcase RTL_VER_10:\n+\tcase RTL_VER_11:\n+\t\tocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,\n+\t\t\t CTRL_TIMER_EN | (1000 / 8));\n \n-\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\treturn -ENODEV;\n-\t\tif (!(ocp_data \u0026 WTD1_EN))\n-\t\t\tbreak;\n-\t\tusleep_range(1000, 2000);\n-\t}\n+\t\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,\n+\t\t\t\t FLOW_CTRL_PATCH_OPT);\n \n-\treturn 0;\n-}\n+\t\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);\n+\t\tbreak;\n+\tcase RTL_VER_12:\n+\tcase RTL_VER_13:\n+\tcase RTL_VER_15:\n+\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);\n \n-static int r8153_post_firmware_1(struct r8152 *tp)\n-{\n-\t/* set USB_BP_4 to support USB_SPEED_SUPER only */\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);\n+\n+\t\t/* enable fc timer and set timer to 600 ms. */\n+\t\tocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,\n+\t\t\t CTRL_TIMER_EN | (600 / 8));\n+\n+\t\tocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL);\n+\t\tif (!(ocp_data \u0026 DACK_DET_EN))\n+\t\t\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,\n+\t\t\t\t\t FLOW_CTRL_PATCH_2);\n+\n+\t\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);\n+\t\tbreak;\n+\tcase RTL_VER_16:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n+\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);\n+\n+\t\tnum_pause_pkts = 0xa;\n+\t\tratio = 10000;\n+\n+\t\tif (speed \u0026 _10bps) {\n+\t\t\tratio /= 10;\n+\t\t} else if (speed \u0026 _100bps) {\n+\t\t\tratio /= 100;\n+\t\t} else if (speed \u0026 _1000bps) {\n+\t\t\tratio /= 1000;\n+\t\t} else if (speed \u0026 _2500bps) {\n+\t\t\tratio /= 2500;\n+\t\t} else if (speed \u0026 _5000bps) {\n+\t\t\tratio /= 5000;\n+\t\t} else if (speed \u0026 _10000bps) {\n+\t\t\tratio /= 10000;\n+\t\t} else {\n+\t\t\t/* No rate bit is set: the link dropped after\n+\t\t\t * the caller checked it, or the PHY reported a\n+\t\t\t * 500 or 1250 Mbit/s sub-rate, which the driver\n+\t\t\t * never advertises. Disarm the limit.\n+\t\t\t */\n+\t\t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"Unknown link speed\\n\");\n+\t\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,\n+\t\t\t\t\t PAUSE_LIMIT_EN);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tlog2_ratio = ilog2(ratio);\n+\t\tnum_pause_pkts -= log2_ratio;\n+\n+\t\t/* Round ratio up to the next power of two if it is\n+\t\t * more than halfway there. Floating-point is avoided\n+\t\t * by rewriting ratio \u003e 1.5 * 2^log2_ratio as\n+\t\t * 2 * ratio \u003e 3 * 2^log2_ratio.\n+\t\t */\n+\t\tif (2 * ratio \u003e 3 * (1 \u003c\u003c log2_ratio))\n+\t\t\tnum_pause_pkts--;\n+\n+\t\t/* At most 2^num_pause_pkts pause packets would be sent.\n+\t\t *\n+\t\t * 10 Mbit/s -\u003e 2^0\n+\t\t * 100 Mbit/s -\u003e 2^3\n+\t\t * 1 Gbit/s -\u003e 2^7\n+\t\t * 2.5 Gbit/s -\u003e 2^8\n+\t\t * 5 Gbit/s -\u003e 2^9\n+\t\t * 10 Gbit/s -\u003e 2^10\n+\t\t */\n+\t\tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,\n+\t\t\t PAUSE_LIMIT_MASK | PAUSE_LIMIT_EN,\n+\t\t\t num_pause_pkts \u003c\u003c 4);\n+\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,\n+\t\t\t\t PAUSE_LIMIT_EN);\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+}\n+\n+static int r8153_pre_firmware_1(struct r8152 *tp)\n+{\n+\tint i;\n+\n+\t/* Wait till the WTD timer is ready. It would take at most 104 ms. */\n+\tfor (i = 0; i \u003c 104; i++) {\n+\t\tu32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL);\n+\n+\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\t\treturn -ENODEV;\n+\t\tif (!(ocp_data \u0026 WTD1_EN))\n+\t\t\tbreak;\n+\t\tusleep_range(1000, 2000);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int r8153_post_firmware_1(struct r8152 *tp)\n+{\n+\t/* set USB_BP_4 to support USB_SPEED_SUPER only */\n \tif (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) \u0026 FORCE_SUPER)\n \t\tocp_write_word(tp, MCU_TYPE_USB, USB_BP_4, BP4_SUPER_ONLY);\n \n@@ -6210,8 +6627,8 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)\n \t * rg_saw_cnt = OCP reg 0xC426 Bit[13:0]\n \t * swr_cnt_1ms_ini = 16000000 / rg_saw_cnt\n \t */\n-\tocp_data = ocp_reg_read(tp, 0xc426);\n-\tocp_data \u0026= 0x3fff;\n+\tocp_reg_read(tp, 0xc426, \u0026data);\n+\tocp_data = data \u0026 0x3fff;\n \tif (ocp_data) {\n \t\tu32 swr_cnt_1ms_ini;\n \n@@ -6391,24 +6808,16 @@ static int rtl8156_enable(struct r8152 *tp)\n \tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\treturn -ENODEV;\n \n-\tif (tp-\u003eversion \u003c RTL_VER_12)\n-\t\tr8156_fc_parameter(tp);\n-\n+\tr8156_fc_parameter(tp);\n \tset_tx_qlen(tp);\n \trtl_set_eee_plus(tp);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_12 \u0026\u0026 tp-\u003eversion \u003c= RTL_VER_17)\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);\n-\n \tr8153_set_rx_early_timeout(tp);\n \tr8153_set_rx_early_size(tp);\n \n \tspeed = rtl8152_get_speed(tp);\n \trtl_set_ifg(tp, speed);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_16)\n-\t\treturn rtl_enable(tp);\n-\n \tif (speed \u0026 _2500bps)\n \t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,\n \t\t\t\t IDLE_SPDWN_EN);\n@@ -6416,12 +6825,10 @@ static int rtl8156_enable(struct r8152 *tp)\n \t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,\n \t\t\t\t IDLE_SPDWN_EN);\n \n-\tif (tp-\u003eversion \u003c RTL_VER_12) {\n-\t\tif (speed \u0026 _1000bps)\n-\t\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11);\n-\t\telse if (speed \u0026 _500bps)\n-\t\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d);\n-\t}\n+\tif (speed \u0026 _1000bps)\n+\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11);\n+\telse if (speed \u0026 _500bps)\n+\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d);\n \n \tif (tp-\u003eudev-\u003espeed == USB_SPEED_HIGH) {\n \t\t/* USB 0xb45e[3:0] l1_nyet_hird */\n@@ -6446,6 +6853,69 @@ static void rtl8156_disable(struct r8152 *tp)\n \trtl8153_disable(tp);\n }\n \n+static int rtl8156b_enable(struct r8152 *tp)\n+{\n+\tu16 speed;\n+\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn -ENODEV;\n+\n+\tset_tx_qlen(tp);\n+\trtl_set_eee_plus(tp);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);\n+\n+\tr8153_set_rx_early_timeout(tp);\n+\tr8153_set_rx_early_size(tp);\n+\n+\tspeed = rtl8152_get_speed(tp);\n+\trtl_set_ifg(tp, speed);\n+\n+\tif (speed \u0026 _2500bps)\n+\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,\n+\t\t\t\t IDLE_SPDWN_EN);\n+\telse\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,\n+\t\t\t\t IDLE_SPDWN_EN);\n+\n+\tif (tp-\u003eudev-\u003espeed == USB_SPEED_HIGH) {\n+\t\t/* USB 0xb45e[3:0] l1_nyet_hird */\n+\t\tif (is_flow_control(speed))\n+\t\t\tocp_word_w0w1(tp, MCU_TYPE_USB, USB_L1_CTRL, 0xf, 0xf);\n+\t\telse\n+\t\t\tocp_word_w0w1(tp, MCU_TYPE_USB, USB_L1_CTRL, 0xf, 0x1);\n+\t}\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);\n+\tusleep_range(1000, 2000);\n+\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);\n+\n+\treturn rtl_enable(tp);\n+}\n+\n+static int rtl8157_enable(struct r8152 *tp)\n+{\n+\tu16 speed;\n+\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn -ENODEV;\n+\n+\tset_tx_qlen(tp);\n+\trtl_set_eee_plus(tp);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);\n+\n+\tr8153_set_rx_early_timeout(tp);\n+\tr8153_set_rx_early_size(tp);\n+\n+\tspeed = rtl8152_get_speed(tp);\n+\trtl_fc_pause_pkt_en(tp, speed);\n+\n+\trtl_set_ifg(tp, speed);\n+\n+\treturn rtl_enable(tp);\n+}\n+\n static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n \t\t\t u32 advertising)\n {\n@@ -6517,7 +6987,11 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n \t\tif (!advertising)\n \t\t\treturn -EINVAL;\n \n-\t\torig = r8152_mdio_read(tp, MII_ADVERTISE);\n+\t\tret = r8152_mdio_read(tp, MII_ADVERTISE);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out;\n+\n+\t\torig = ret;\n \t\tnew1 = orig \u0026 ~(ADVERTISE_10HALF | ADVERTISE_10FULL |\n \t\t\t\tADVERTISE_100HALF | ADVERTISE_100FULL);\n \t\tif (advertising \u0026 RTL_ADVERTISED_10_HALF) {\n@@ -6544,7 +7018,11 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n \t\t}\n \n \t\tif (tp-\u003emii.supports_gmii) {\n-\t\t\torig = r8152_mdio_read(tp, MII_CTRL1000);\n+\t\t\tret = r8152_mdio_read(tp, MII_CTRL1000);\n+\t\t\tif (ret \u003c 0)\n+\t\t\t\tgoto out;\n+\n+\t\t\torig = ret;\n \t\t\tnew1 = orig \u0026 ~(ADVERTISE_1000FULL |\n \t\t\t\t\tADVERTISE_1000HALF);\n \n@@ -6558,7 +7036,10 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n \t\t}\n \n \t\tif (tp-\u003esupport_2500full || tp-\u003esupport_5000full || tp-\u003esupport_10000full) {\n-\t\t\torig = ocp_reg_read(tp, OCP_10GBT_CTRL);\n+\t\t\tret = ocp_reg_read(tp, OCP_10GBT_CTRL, \u0026orig);\n+\t\t\tif (ret \u003c 0)\n+\t\t\t\tgoto out;\n+\n \t\t\tnew1 = orig \u0026 ~(MDIO_AN_10GBT_CTRL_ADV2_5G | MDIO_AN_10GBT_CTRL_ADV5G\n \t\t\t\t\t| MDIO_AN_10GBT_CTRL_ADV10G);\n \n@@ -6589,20 +7070,23 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n \tif (test_and_clear_bit(PHY_RESET, \u0026tp-\u003eflags))\n \t\tbmcr |= BMCR_RESET;\n \n-\tr8152_mdio_write(tp, MII_BMCR, bmcr);\n+\tret = r8152_mdio_write(tp, MII_BMCR, bmcr);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n \n \tif (bmcr \u0026 BMCR_RESET) {\n \t\tint i;\n \n \t\tfor (i = 0; i \u003c 50; i++) {\n \t\t\tmsleep(20);\n-\t\t\tif ((r8152_mdio_read(tp, MII_BMCR) \u0026 BMCR_RESET) == 0)\n+\t\t\tret = r8152_mdio_read(tp, MII_BMCR);\n+\t\t\tif (ret \u003c 0 || !(ret \u0026 BMCR_RESET))\n \t\t\t\tbreak;\n \t\t}\n \t}\n \n out:\n-\treturn ret;\n+\treturn ret \u003c 0 ? ret : 0;\n }\n \n static void rtl8152_up(struct r8152 *tp)\n@@ -6806,8 +7290,7 @@ static void rtl8156_up(struct r8152 *tp)\n \t\treturn;\n \n \tr8153b_u1u2en(tp, false);\n-\tif (tp-\u003eversion \u003c RTL_VER_16)\n-\t\tr8153_u2p3en(tp, false);\n+\tr8153_u2p3en(tp, false);\n \tr8153_aldps_en(tp, false);\n \n \trxdy_gated_en(tp, true);\n@@ -6820,8 +7303,7 @@ static void rtl8156_up(struct r8152 *tp)\n \n \tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_16)\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));\n \n \tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);\n \n@@ -6843,11 +7325,11 @@ static void rtl8156_up(struct r8152 *tp)\n \tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, RXFIFO_FULL_MASK,\n \t\t 0x08);\n \n-\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, PLA_MCU_SPDWN_EN);\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,\n+\t\t\t PLA_MCU_SPDWN_EN);\n \n-\tif (tp-\u003eversion \u003c RTL_VER_16)\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,\n-\t\t\t\t RG_PWRDN_EN | ALL_SPEED_OFF);\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,\n+\t\t\t RG_PWRDN_EN | ALL_SPEED_OFF);\n \n \tocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400);\n \n@@ -6857,10 +7339,19 @@ static void rtl8156_up(struct r8152 *tp)\n \t}\n \n \tr8153_aldps_en(tp, true);\n-\tif (tp-\u003eversion \u003c RTL_VER_16)\n-\t\tr8153_u2p3en(tp, true);\n+\tr8153_u2p3en(tp, true);\n+\n+\tswitch (tp-\u003eversion) {\n+\tcase RTL_VER_13:\n+\tcase RTL_VER_15:\n+\t\t/* Enable Clear_SDR */\n+\t\tocp_word_set_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(15));\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n \n-\tif (tp-\u003eversion \u003c RTL_VER_16 \u0026\u0026 tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n+\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n \t\tr8153b_u1u2en(tp, true);\n }\n \n@@ -6873,12 +7364,9 @@ static void rtl8156_down(struct r8152 *tp)\n \n \tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,\n \t\t\t PLA_MCU_SPDWN_EN);\n-\n \tr8153b_u1u2en(tp, false);\n-\tif (tp-\u003eversion \u003c RTL_VER_16) {\n-\t\tr8153_u2p3en(tp, false);\n-\t\tr8153b_power_cut_en(tp, false);\n-\t}\n+\tr8153_u2p3en(tp, false);\n+\tr8153b_power_cut_en(tp, false);\n \tr8153_aldps_en(tp, false);\n \n \tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);\n@@ -6900,7 +7388,125 @@ static void rtl8156_down(struct r8152 *tp)\n \t */\n \tocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff);\n \n-\tocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);\n+\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_BDC_CR, ALDPS_PROXY_MODE);\n+\n+\tocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL,\n+\t\t\t NOW_IS_OOB | DIS_MCU_CLROOB);\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);\n+\n+\trtl_rx_vlan_en(tp, true);\n+\trxdy_gated_en(tp, false);\n+\n+\tocp_dword_set_bits(tp, MCU_TYPE_PLA, PLA_RCR,\n+\t\t\t RCR_APM | RCR_AM | RCR_AB);\n+\n+\tr8153_aldps_en(tp, true);\n+}\n+\n+static void rtl8157_change_mtu(struct r8152 *tp)\n+{\n+\tu32 max_pkt_size = mtu_to_size(tp-\u003enetdev-\u003emtu);\n+\tu32 ocp_data;\n+\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, max_pkt_size);\n+\n+\t/* Use at least 10K for MTPS */\n+\tocp_data = max_t(u32, max_pkt_size, 10 * 1024) / 64;\n+\n+\t/* 16 * 1024 / 64 = 0x100, so the max is 0xff for 8 bits data */\n+\tocp_data = min_t(u32, ocp_data, 0xff);\n+\n+\tocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, ocp_data);\n+\tr8156_fc_parameter(tp);\n+\n+\t/* TX share fifo free credit full threshold */\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64);\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL,\n+\t\t ALIGN(max_pkt_size + tp-\u003etx_desc.size, 1024) / 16);\n+}\n+\n+static void rtl8157_up(struct r8152 *tp)\n+{\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn;\n+\n+\tr8153b_u1u2en(tp, false);\n+\tr8153_aldps_en(tp, false);\n+\n+\trxdy_gated_en(tp, true);\n+\tr8153_teredo_off(tp);\n+\n+\tocp_dword_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, RCR_ACPT_ALL);\n+\n+\trtl8152_nic_reset(tp);\n+\trtl_reset_bmu(tp);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);\n+\n+\trtl_rx_vlan_en(tp, tp-\u003enetdev-\u003efeatures \u0026 NETIF_F_HW_VLAN_CTAG_RX);\n+\n+\trtl8157_change_mtu(tp);\n+\n+\t/* share FIFO settings */\n+\tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, RXFIFO_FULL_MASK,\n+\t\t 0x08);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,\n+\t\t\t RG_PWRDN_EN | ALL_SPEED_OFF);\n+\n+\tocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400);\n+\n+\tif (tp-\u003esaved_wolopts != __rtl_get_wol(tp)) {\n+\t\tnetif_warn(tp, ifup, tp-\u003enetdev, \"wol setting is changed\\n\");\n+\t\t__rtl_set_wol(tp, tp-\u003esaved_wolopts);\n+\t}\n+\n+\tr8153_aldps_en(tp, true);\n+\n+\t/* Enable Clear_SDR */\n+\tocp_byte_set_bits(tp, MCU_TYPE_USB, 0xd378, BIT(7));\n+\t/* Clear SDR bit */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(15));\n+}\n+\n+static void rtl8157_down(struct r8152 *tp)\n+{\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags)) {\n+\t\trtl_drop_queued_tx(tp);\n+\t\treturn;\n+\t}\n+\n+\tr8153b_u1u2en(tp, false);\n+\tr8153_aldps_en(tp, false);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);\n+\n+\t/* RX FIFO settings for OOB */\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 64 / 16);\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 1024 / 16);\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 4096 / 16);\n+\n+\trtl_disable(tp);\n+\trtl_reset_bmu(tp);\n+\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1526);\n+\tocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, 10 * 1024 / 64);\n+\n+\t/* Clear teredo wake event. bit[15:8] is the teredo wakeup\n+\t * type. Set it to zero. bits[7:0] are the W1C bits about\n+\t * the events. Set them to all 1 to clear them.\n+\t */\n+\tocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff);\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_BDC_CR, ALDPS_PROXY_MODE);\n+\n+\tocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL,\n+\t\t\t NOW_IS_OOB | DIS_MCU_CLROOB);\n \n \tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);\n \n@@ -6931,7 +7537,12 @@ static bool rtl8152_in_nway(struct r8152 *tp)\n \n static bool rtl8153_in_nway(struct r8152 *tp)\n {\n-\tu16 phy_state = ocp_reg_read(tp, OCP_PHY_STATE) \u0026 0xff;\n+\tu16 phy_state;\n+\n+\tif (ocp_reg_read(tp, OCP_PHY_STATE, \u0026phy_state) \u003c 0)\n+\t\treturn false;\n+\n+\tphy_state \u0026= 0xff;\n \n \tif (phy_state == TXDIS_STATE || phy_state == ABD_STATE)\n \t\treturn false;\n@@ -6947,7 +7558,9 @@ static void r8156_mdio_force_mode(struct r8152 *tp)\n \t * 0: MDIO force mode\n \t * 1: MMD force mode\n \t */\n-\tdata = ocp_reg_read(tp, 0xa5b4);\n+\tif (ocp_reg_read(tp, 0xa5b4, \u0026data) \u003c 0)\n+\t\treturn;\n+\n \tif (data \u0026 BIT(15)) {\n \t\tdata \u0026= ~BIT(15);\n \t\tocp_reg_write(tp, 0xa5b4, data);\n@@ -7225,22 +7838,14 @@ static void r8152b_init(struct r8152 *tp)\n static void r8153_init(struct r8152 *tp)\n {\n \tu32 ocp_data;\n-\tint i;\n \n \tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\treturn;\n \n \tr8153_u1u2en(tp, false);\n \n-\tfor (i = 0; i \u003c 500; i++) {\n-\t\tif (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) \u0026\n-\t\t AUTOLOAD_DONE)\n-\t\t\tbreak;\n-\n-\t\tmsleep(20);\n-\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\tbreak;\n-\t}\n+\tif (wait_autoload_done(tp))\n+\t\treturn;\n \n \tr8153_phy_status(tp, 0);\n \n@@ -7341,22 +7946,13 @@ static void r8153_init(struct r8152 *tp)\n \n static void r8153b_init(struct r8152 *tp)\n {\n-\tint i;\n-\n \tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\treturn;\n \n \tr8153b_u1u2en(tp, false);\n \n-\tfor (i = 0; i \u003c 500; i++) {\n-\t\tif (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) \u0026\n-\t\t AUTOLOAD_DONE)\n-\t\t\tbreak;\n-\n-\t\tmsleep(20);\n-\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\tbreak;\n-\t}\n+\tif (wait_autoload_done(tp))\n+\t\treturn;\n \n \tr8153_phy_status(tp, 0);\n \n@@ -7411,8 +8007,6 @@ static void r8153b_init(struct r8152 *tp)\n \n static void r8153c_init(struct r8152 *tp)\n {\n-\tint i;\n-\n \tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\treturn;\n \n@@ -7425,15 +8019,8 @@ static void r8153c_init(struct r8152 *tp)\n \n \tocp_word_set_bits(tp, MCU_TYPE_USB, 0xcbf0, BIT(1));\n \n-\tfor (i = 0; i \u003c 500; i++) {\n-\t\tif (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) \u0026\n-\t\t AUTOLOAD_DONE)\n-\t\t\tbreak;\n-\n-\t\tmsleep(20);\n-\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\treturn;\n-\t}\n+\tif (wait_autoload_done(tp))\n+\t\treturn;\n \n \tr8153_phy_status(tp, 0);\n \n@@ -7505,7 +8092,8 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)\n \trtl_eee_enable(tp, false);\n \n \tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n-\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON);\n+\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n+\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n \n \tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n \n@@ -7612,19 +8200,20 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)\n \t\tocp_reg_clr_bits(tp, 0xa86a, BIT(0));\n \n \t\t/* MDI SWAP */\n+\t\tocp_reg_read(tp, 0xd068, \u0026data);\n \t\tif ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) \u0026 MID_REVERSE) \u0026\u0026\n-\t\t (ocp_reg_read(tp, 0xd068) \u0026 BIT(1))) {\n+\t\t (data \u0026 BIT(1))) {\n \t\t\tu16 swap_a, swap_b;\n \n-\t\t\tdata = ocp_reg_read(tp, 0xd068);\n+\t\t\tocp_reg_read(tp, 0xd068, \u0026data);\n \t\t\tdata \u0026= ~0x1f;\n \t\t\tdata |= 0x1; /* p0 */\n \t\t\tocp_reg_write(tp, 0xd068, data);\n-\t\t\tswap_a = ocp_reg_read(tp, 0xd06a);\n+\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_a);\n \t\t\tdata \u0026= ~0x18;\n \t\t\tdata |= 0x18; /* p3 */\n \t\t\tocp_reg_write(tp, 0xd068, data);\n-\t\t\tswap_b = ocp_reg_read(tp, 0xd06a);\n+\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_b);\n \t\t\tdata \u0026= ~0x18; /* p0 */\n \t\t\tocp_reg_write(tp, 0xd068, data);\n \t\t\tocp_reg_write(tp, 0xd06a,\n@@ -7636,11 +8225,11 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)\n \t\t\tdata \u0026= ~0x18;\n \t\t\tdata |= 0x08; /* p1 */\n \t\t\tocp_reg_write(tp, 0xd068, data);\n-\t\t\tswap_a = ocp_reg_read(tp, 0xd06a);\n+\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_a);\n \t\t\tdata \u0026= ~0x18;\n \t\t\tdata |= 0x10; /* p2 */\n \t\t\tocp_reg_write(tp, 0xd068, data);\n-\t\t\tswap_b = ocp_reg_read(tp, 0xd06a);\n+\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_b);\n \t\t\tdata \u0026= ~0x18;\n \t\t\tdata |= 0x08; /* p1 */\n \t\t\tocp_reg_write(tp, 0xd068, data);\n@@ -7651,16 +8240,16 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)\n \t\t\tocp_reg_write(tp, 0xd068, data);\n \t\t\tocp_reg_write(tp, 0xd06a,\n \t\t\t\t (swap_b \u0026 ~0x7ff) | (swap_a \u0026 0x7ff));\n-\t\t\tswap_a = ocp_reg_read(tp, 0xbd5a);\n-\t\t\tswap_b = ocp_reg_read(tp, 0xbd5c);\n+\t\t\tocp_reg_read(tp, 0xbd5a, \u0026swap_a);\n+\t\t\tocp_reg_read(tp, 0xbd5c, \u0026swap_b);\n \t\t\tocp_reg_write(tp, 0xbd5a, (swap_a \u0026 ~0x1f1f) |\n \t\t\t\t ((swap_b \u0026 0x1f) \u003c\u003c 8) |\n \t\t\t\t ((swap_b \u003e\u003e 8) \u0026 0x1f));\n \t\t\tocp_reg_write(tp, 0xbd5c, (swap_b \u0026 ~0x1f1f) |\n \t\t\t\t ((swap_a \u0026 0x1f) \u003c\u003c 8) |\n \t\t\t\t ((swap_a \u003e\u003e 8) \u0026 0x1f));\n-\t\t\tswap_a = ocp_reg_read(tp, 0xbc18);\n-\t\t\tswap_b = ocp_reg_read(tp, 0xbc1a);\n+\t\t\tocp_reg_read(tp, 0xbc18, \u0026swap_a);\n+\t\t\tocp_reg_read(tp, 0xbc1a, \u0026swap_b);\n \t\t\tocp_reg_write(tp, 0xbc18, (swap_a \u0026 ~0x1f1f) |\n \t\t\t\t ((swap_b \u0026 0x1f) \u003c\u003c 8) |\n \t\t\t\t ((swap_b \u003e\u003e 8) \u0026 0x1f));\n@@ -7740,7 +8329,8 @@ static void r8156b_hw_phy_cfg(struct r8152 *tp)\n \trtl_eee_enable(tp, false);\n \n \tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n-\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON);\n+\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n+\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n \n \tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n \n@@ -7979,17 +8569,21 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \trtl_eee_enable(tp, false);\n \n \tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n-\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON);\n+\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n+\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n \n \t/* PFM mode */\n \tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n \n \t/* Advanced Power Saving parameter */\n-\tocp_reg_set_bits(tp, 0xa430, BIT(0) | BIT(1));\n+\tocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);\n \n \t/* Disable ALDPS force mode */\n \tocp_reg_clr_bits(tp, 0xa44a, BIT(2));\n \n+\t/* Disable bypass_turn_off_clk_in_aldps */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));\n+\n \tswitch (tp-\u003eversion) {\n \tcase RTL_VER_16:\n \t\t/* XG_INRX parameter */\n@@ -8005,7 +8599,7 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \t\tsram2_write_w0w1(tp, 0x8078, 0xff00, 0x3000);\n \n \t\t/* green mode */\n-\t\tsram2_write_w0w1(tp, 0x89e9, 0xff00, 0);\n+\t\tsram2_clr_bits(tp, 0x89e9, 0xff00);\n \t\tsram2_write_w0w1(tp, 0x8ffd, 0xff00, 0x0100);\n \t\tsram2_write_w0w1(tp, 0x8ffe, 0xff00, 0x0200);\n \t\tsram2_write_w0w1(tp, 0x8fff, 0xff00, 0x0400);\n@@ -8111,11 +8705,86 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \t\tsram2_write_w0w1(tp, 0x807c, 0xff00, 0x5000);\n \t\tsram2_write_w0w1(tp, 0x809d, 0xff00, 0x5000);\n \t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tif (rtl_phy_patch_request(tp, true, true))\n+\t\treturn;\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);\n+\n+\tocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);\n+\n+\ttp-\u003eups_info._10m_ckdiv = true;\n+\ttp-\u003eups_info.eee_plloff_100 = false;\n+\ttp-\u003eups_info.eee_plloff_giga = false;\n+\n+\tocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);\n+\ttp-\u003eups_info.eee_ckdiv = true;\n+\n+\trtl_phy_patch_request(tp, false, true);\n+\n+\trtl_green_en(tp, test_bit(GREEN_ETHERNET, \u0026tp-\u003eflags));\n+\n+\tocp_reg_clr_bits(tp, 0xa428, BIT(9));\n+\tocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1));\n+\ttp-\u003eups_info.lite_mode = 0;\n+\n+\tif (tp-\u003eeee_en)\n+\t\trtl_eee_enable(tp, true);\n+\n+\tr8153_aldps_en(tp, true);\n+\tr8152b_enable_fc(tp);\n+\n+\tset_bit(PHY_RESET, \u0026tp-\u003eflags);\n+}\n+\n+static void r8159_hw_phy_cfg(struct r8152 *tp)\n+{\n+\tu16 data;\n+\n+\tr8156b_wait_loading_flash(tp);\n+\n+\tocp_word_test_and_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);\n+\n+\tdata = r8153_phy_status(tp, 0);\n+\tswitch (data) {\n+\tcase PHY_STAT_EXT_INIT:\n+\t\trtl8152_apply_firmware(tp, true);\n+\t\tocp_reg_clr_bits(tp, 0xa466, BIT(0));\n+\t\tocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));\n+\t\tbreak;\n+\tcase PHY_STAT_LAN_ON:\n+\tcase PHY_STAT_PWRDN:\n+\tdefault:\n+\t\trtl8152_apply_firmware(tp, false);\n+\t\tbreak;\n+\t}\n+\n+\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n \n-\tcase RTL_VER_17:\n-\t\t/* Disable bypass turn off clk in ALDPS */\n-\t\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));\n+\tr8153_aldps_en(tp, false);\n \n+\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n+\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n+\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n+\n+\t/* PFM mode */\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n+\n+\t/* Advanced Power Saving parameter */\n+\tocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);\n+\n+\t/* Disable ALDPS force mode */\n+\tocp_reg_clr_bits(tp, 0xa44a, BIT(2));\n+\n+\t/* Disable bypass_turn_off_clk_in_aldps */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));\n+\n+\tswitch (tp-\u003eversion) {\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\t/* Power level tuning\n \t\t * test mode power level\n \t\t */\n@@ -8125,22 +8794,35 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \t\tsram_write_w0w1(tp, 0x81ae, 0xff00, 0x0f00);\n \t\tsram_write_w0w1(tp, 0x81b9, 0xff00, 0xb900);\n \t\t/* normal link TX filter */\n-\t\tsram2_write_w0w1(tp, 0x83b0, 0x0e00, 0);\n-\t\tsram2_write_w0w1(tp, 0x83c5, 0x0e00, 0);\n-\t\tsram2_write_w0w1(tp, 0x83da, 0x0e00, 0);\n-\t\tsram2_write_w0w1(tp, 0x83ef, 0x0e00, 0);\n+\t\tsram2_clr_bits(tp, 0x83b0, 0x0e00);\n+\t\tsram2_clr_bits(tp, 0x83c5, 0x0e00);\n+\t\tsram2_clr_bits(tp, 0x83da, 0x0e00);\n+\t\tsram2_clr_bits(tp, 0x83ef, 0x0e00);\n+\n+\t\tocp_reg_w0w1(tp, 0xbf38, 0x01f0, 0x0160);\n+\t\tocp_reg_w0w1(tp, 0xbf3a, 0x001f, 0x0014);\n+\t\t/* shorten CLKS latency */\n+\t\tocp_reg_clr_bits(tp, 0xbf28, BIT(14) | BIT(13));\n+\t\tocp_reg_clr_bits(tp, 0xbf2c, BIT(15) | BIT(14));\n+\t\t/* CMP_Timer on MP_Timer=333\n+\t\t * GPHY OCP 0xbf28 bit[0] = 0x1\n+\t\t * GPHY OCP 0xbf28 bit[6:1] = 0x3\n+\t\t * GPHY OCP 0xbf28 bit[12:7] = 0x3\n+\t\t */\n+\t\tocp_reg_w0w1(tp, 0xbf28, 0x1fff, 0x0187);\n+\t\tocp_reg_w0w1(tp, 0xbf2a, 0x3f, 0x03);\n \n \t\t/* AFE power saving for 2.5G \u0026 5G */\n \t\tsram_write(tp, 0x8173, 0x8620);\n \t\tsram_write(tp, 0x8175, 0x8671);\n \n-\t\tsram_write_w0w1(tp, 0x817c, 0, BIT(13));\n-\t\tsram_write_w0w1(tp, 0x8187, 0, BIT(13));\n-\t\tsram_write_w0w1(tp, 0x8192, 0, BIT(13));\n-\t\tsram_write_w0w1(tp, 0x819d, 0, BIT(13));\n-\t\tsram_write_w0w1(tp, 0x81a8, BIT(13), 0);\n-\t\tsram_write_w0w1(tp, 0x81b3, BIT(13), 0);\n-\t\tsram_write_w0w1(tp, 0x81be, 0, BIT(13));\n+\t\tsram_set_bits(tp, 0x817c, BIT(13));\n+\t\tsram_set_bits(tp, 0x8187, BIT(13));\n+\t\tsram_set_bits(tp, 0x8192, BIT(13));\n+\t\tsram_set_bits(tp, 0x819d, BIT(13));\n+\t\tsram_clr_bits(tp, 0x81a8, BIT(13));\n+\t\tsram_clr_bits(tp, 0x81b3, BIT(13));\n+\t\tsram_set_bits(tp, 0x81be, BIT(13));\n \n \t\tsram_write_w0w1(tp, 0x817d, 0xff00, 0xa600);\n \t\tsram_write_w0w1(tp, 0x8188, 0xff00, 0xa600);\n@@ -8204,10 +8886,10 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \t\tsram2_write_w0w1(tp, 0x84b2, 0xff00, 0x6000);\n \t\t/* Training AAGC PAR (with uc2 patch) */\n \t\tsram2_write(tp, 0x8ffc, 0x6008);\n-\t\tsram2_write(tp, 0x8ffe, 0xf450);\n+\t\tsram2_write(tp, 0x8ffe, 0xf4ff);\n \t\t/* DAC BGK */\n-\t\tsram2_write_w0w1(tp, 0x8015, 0, BIT(9));\n-\t\tsram2_write_w0w1(tp, 0x8016, 0, BIT(11));\n+\t\tsram2_set_bits(tp, 0x8015, BIT(9));\n+\t\tsram2_set_bits(tp, 0x8016, BIT(11));\n \t\tsram2_write_w0w1(tp, 0x8fe6, 0xff00, 0x0800);\n \t\tsram2_write(tp, 0x8fe4, 0x2114);\n \t\t/* 10G PBO table */\n@@ -8216,14 +8898,14 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \t\tsram2_write_w0w1(tp, 0x864b, 0xff00, 0xdc00);\n \t\t/* 2.5G ado power window size */\n \t\tsram2_write_w0w1(tp, 0x8154, 0xc000, 0x4000);\n-\t\tsram2_write_w0w1(tp, 0x8158, 0xc000, 0);\n+\t\tsram2_clr_bits(tp, 0x8158, 0xc000);\n \t\t/* 10G lock far */\n \t\tsram2_write(tp, 0x826c, 0xffff);\n \t\tsram2_write(tp, 0x826e, 0xffff);\n \t\t/* XG INRX parameter */\n \t\tsram2_write_w0w1(tp, 0x8872, 0xff00, 0x0e00);\n-\t\tsram_write_w0w1(tp, 0x8012, 0, BIT(11));\n-\t\tsram_write_w0w1(tp, 0x8012, 0, BIT(14));\n+\t\tsram_set_bits(tp, 0x8012, BIT(11));\n+\t\tsram_set_bits(tp, 0x8012, BIT(14));\n \t\tocp_reg_set_bits(tp, 0xb576, BIT(0));\n \t\tsram_write_w0w1(tp, 0x834a, 0xff00, 0x0700);\n \t\tsram2_write_w0w1(tp, 0x8217, 0x3f00, 0x2a00);\n@@ -8234,100 +8916,373 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)\n \t\t/* improve UBE */\n \t\tocp_reg_set_bits(tp, 0xbf0c, 0x7 \u003c\u003c 11);\n \t\t/* close Sparse NEC, improve connect 5EUU cable performance */\n-\t\tsram2_write_w0w1(tp, 0x88de, 0xff00, 0);\n+\t\tsram2_clr_bits(tp, 0x88de, 0xff00);\n \t\t/* 5G slave compatibility issue */\n \t\tsram2_write(tp, 0x80b4, 0x5195);\n \n-\t\t/* XG Test Mode\n-\t\t * xgtstm_map_tbl for mdi_cap_sel\n-\t\t */\n-\t\tsram_write(tp, 0x8370, 0x8671);\n-\t\tsram_write(tp, 0x8372, 0x86c8);\n-\t\t/* xgtstm_amp_map_tbl for REG_IBX_UP_SHIFT_L */\n-\t\tsram_write(tp, 0x8401, 0x86c8);\n-\t\tsram_write(tp, 0x8403, 0x86da);\n-\t\tsram_write_w0w1(tp, 0x8406, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x8408, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x840a, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x840c, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x840e, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x8410, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x8412, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x8414, 0x1800, 0x1000);\n-\t\tsram_write_w0w1(tp, 0x8416, 0x1800, 0x1000);\n+\t\t/* XG Test Mode\n+\t\t * xgtstm_map_tbl for mdi_cap_sel\n+\t\t */\n+\t\tsram_write(tp, 0x8370, 0x8671);\n+\t\tsram_write(tp, 0x8372, 0x86c8);\n+\t\t/* xgtstm_amp_map_tbl for REG_IBX_UP_SHIFT_L */\n+\t\tsram_write(tp, 0x8401, 0x86c8);\n+\t\tsram_write(tp, 0x8403, 0x86da);\n+\t\tsram_write_w0w1(tp, 0x8406, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x8408, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x840a, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x840c, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x840e, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x8410, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x8412, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x8414, 0x1800, 0x1000);\n+\t\tsram_write_w0w1(tp, 0x8416, 0x1800, 0x1000);\n+\n+\t\t/* Cable Test Patch */\n+\t\tsram_write(tp, 0x82bd, 0x1f40);\n+\n+\t\t/* Thermal sensor parameters */\n+\t\tocp_reg_w0w1(tp, 0xbfb4, 0x07ff, 0x0328);\n+\t\tocp_reg_write(tp, 0xbfb6, 0x3e14);\n+\n+\t\t/* spdchg_gtx_shape_100M */\n+\t\tocp_reg_write(tp, OCP_SRAM_ADDR, 0x81c4);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x003b);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0086);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00b7);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00db);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00c3);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0078);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0047);\n+\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0023);\n+\n+\t\t/* lsbmsk_parameters\n+\t\t * RL6961_lsbmsk_parameter_250207\n+\t\t */\n+\t\tsram2_write(tp, 0x88d7, 0x01a0);\n+\t\tsram2_write(tp, 0x88d9, 0x01a0);\n+\t\tsram2_write(tp, 0x8ffa, 0x002a);\n+\n+\t\tsram2_write(tp, 0x8fee, 0xffdf);\n+\t\tsram2_write(tp, 0x8ff0, 0xffff);\n+\t\tsram2_write(tp, 0x8ff2, 0x0a4a);\n+\t\tsram2_write(tp, 0x8ff4, 0xaa5a);\n+\t\tsram2_write(tp, 0x8ff6, 0x0a4a);\n+\t\tsram2_write(tp, 0x8ff8, 0xaa5a);\n+\n+\t\tsram2_write_w0w1(tp, 0x88d5, 0xff00, 0x0200);\n+\n+\t\t/* spdchg_pga1_lpf_cap */\n+\t\tsram_write_w0w1(tp, 0x84bb, 0xff00, 0x0a00);\n+\t\tsram_write_w0w1(tp, 0x84c0, 0xff00, 0x1600);\n+\n+\t\t/* ENET PLL jitter improvement */\n+\t\tocp_reg_w0w1(tp, 0xbf8a, 0xfc00, 0x2000);\n+\t\tocp_reg_set_bits(tp, 0xbf88, BIT(2));\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tif (rtl_phy_patch_request(tp, true, true))\n+\t\treturn;\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);\n+\n+\tocp_reg_clr_bits(tp, OCP_DOWN_SPEED,\n+\t\t\t EN_EEE_100 | EN_EEE_1000 | EN_10M_CLKDIV);\n+\ttp-\u003eups_info._10m_ckdiv = false;\n+\ttp-\u003eups_info.eee_plloff_100 = false;\n+\ttp-\u003eups_info.eee_plloff_giga = false;\n+\n+\tocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);\n+\ttp-\u003eups_info.eee_ckdiv = true;\n+\n+\trtl_phy_patch_request(tp, false, true);\n+\n+\trtl_green_en(tp, test_bit(GREEN_ETHERNET, \u0026tp-\u003eflags));\n+\n+\tocp_reg_clr_bits(tp, 0xa428, BIT(9));\n+\tocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1) | BIT(2));\n+\ttp-\u003eups_info.lite_mode = 0;\n+\n+\tif (tp-\u003eeee_en)\n+\t\trtl_eee_enable(tp, true);\n+\n+\tr8153_aldps_en(tp, true);\n+\tr8152b_enable_fc(tp);\n+\n+\tset_bit(PHY_RESET, \u0026tp-\u003eflags);\n+}\n+\n+static void r8156_init(struct r8152 *tp)\n+{\n+\tu16 data;\n+\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn;\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);\n+\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);\n+\n+\tr8153b_u1u2en(tp, false);\n+\n+\tif (wait_autoload_done(tp))\n+\t\treturn;\n+\n+\tdata = r8153_phy_status(tp, 0);\n+\tif (data == PHY_STAT_EXT_INIT)\n+\t\tocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));\n+\n+\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n+\n+\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n+\n+\tr8153_u2p3en(tp, false);\n+\n+\t/* MSC timer = 0xfff * 8ms = 32760 ms */\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);\n+\n+\t/* U1/U2/L1 idle timer. 500 us */\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);\n+\n+\tr8153b_power_cut_en(tp, false);\n+\tr8156_ups_en(tp, false);\n+\tr8153_queue_wake(tp, false);\n+\trtl_runtime_suspend_enable(tp, false);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);\n+\n+\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n+\t\tr8153b_u1u2en(tp, true);\n+\n+\tusb_enable_lpm(tp-\u003eudev);\n+\n+\trtl_fc_pause_pkt_en(tp, 0);\n+\n+\tr8156_mac_clk_spd(tp, true);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,\n+\t\t\t PLA_MCU_SPDWN_EN);\n+\n+\tif (rtl8152_get_speed(tp) \u0026 LINK_STATUS)\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t\t CUR_LINK_OK | POLL_LINK_CHG);\n+\telse\n+\t\tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, CUR_LINK_OK,\n+\t\t\t POLL_LINK_CHG);\n+\n+\tset_bit(GREEN_ETHERNET, \u0026tp-\u003eflags);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,\n+\t\t\t RX_AGG_DISABLE | RX_ZERO_EN);\n+\n+\tocp_byte_set_bits(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ACT_ODMA);\n+\n+\tr8156_mdio_force_mode(tp);\n+\trtl_tally_reset(tp);\n+\n+\ttp-\u003ecoalesce = 15000; /* 15 us */\n+}\n+\n+static void r8156b_u2phy_backup(struct r8152 *tp)\n+{\n+\tocp_write_word(tp, MCU_TYPE_USB, 0xd3ce, 0x181b);\n+\tocp_write_dword(tp, MCU_TYPE_USB, 0xd3d0, 0x616ccd99);\n+\tocp_write_dword(tp, MCU_TYPE_USB, 0xd3d4, 0x08fc8101);\n+\tocp_write_dword(tp, MCU_TYPE_USB, 0xd3d8, 0x159b1100);\n+\tocp_write_word(tp, MCU_TYPE_USB, 0xd3dc, 0x0a00);\n+}\n+\n+static void r8156b_init(struct r8152 *tp)\n+{\n+\tu16 data;\n+\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn;\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);\n+\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);\n+\n+\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_U2P3_CTRL, RX_DETECT8);\n+\n+\tr8153b_u1u2en(tp, false);\n+\n+\tswitch (tp-\u003eversion) {\n+\tcase RTL_VER_13:\n+\tcase RTL_VER_15:\n+\t\tr8156b_wait_loading_flash(tp);\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tif (wait_autoload_done(tp))\n+\t\treturn;\n+\n+\tdata = r8153_phy_status(tp, 0);\n+\tif (data == PHY_STAT_EXT_INIT) {\n+\t\tocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));\n+\t\tocp_reg_clr_bits(tp, 0xa466, BIT(0));\n+\t}\n+\n+\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n+\n+\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n+\n+\tr8153_u2p3en(tp, false);\n+\n+\t/* Disable Auto Speed up */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);\n+\n+\t/* MSC timer = 0xfff * 8ms = 32760 ms */\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);\n+\n+\t/* U1/U2/L1 idle timer. 500 us */\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);\n+\n+\tr8156b_u2phy_backup(tp);\n+\n+\tr8153b_power_cut_en(tp, false);\n+\tr8156_ups_en(tp, false);\n+\tr8153_queue_wake(tp, false);\n+\trtl_runtime_suspend_enable(tp, false);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);\n+\n+\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n+\t\tr8153b_u1u2en(tp, true);\n+\n+\tusb_enable_lpm(tp-\u003eudev);\n+\n+\trtl_fc_pause_pkt_en(tp, 0);\n+\n+\tr8156_mac_clk_spd(tp, true);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,\n+\t\t\t PLA_MCU_SPDWN_EN);\n+\n+\tif (rtl8152_get_speed(tp) \u0026 LINK_STATUS)\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t\t CUR_LINK_OK | POLL_LINK_CHG);\n+\telse\n+\t\tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t CUR_LINK_OK, POLL_LINK_CHG);\n+\n+\tset_bit(GREEN_ETHERNET, \u0026tp-\u003eflags);\n+\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,\n+\t\t\t RX_AGG_DISABLE | RX_ZERO_EN);\n+\n+\tr8156_mdio_force_mode(tp);\n+\trtl_tally_reset(tp);\n+\n+\ttp-\u003ecoalesce = 15000;\t/* 15 us */\n+}\n \n-\t\t/* Cable Test Patch */\n-\t\tsram_write(tp, 0x82bd, 0x1f40);\n+static void r8157_init(struct r8152 *tp)\n+{\n+\tu16 data;\n \n-\t\t/* Thermal sensor parameters */\n-\t\tocp_reg_w0w1(tp, 0xbfb4, 0x07ff, 0x0328);\n-\t\tocp_reg_write(tp, 0xbfb6, 0x3e14);\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn;\n \n-\t\t/* spdchg_gtx_shape_100M */\n-\t\tocp_reg_write(tp, OCP_SRAM_ADDR, 0x81c4);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x003b);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0086);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00b7);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00db);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00c3);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0078);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0047);\n-\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0023);\n+\t/* Enable SW reset */\n+\tocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));\n \n-\t\t/* lsbmsk_parameters\n-\t\t * RL6961_lsbmsk_parameter_250207\n-\t\t */\n-\t\tsram2_write(tp, 0x88d7, 0x01a0);\n-\t\tsram2_write(tp, 0x88d9, 0x01a0);\n-\t\tsram2_write(tp, 0x8ffa, 0x002a);\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);\n \n-\t\tsram2_write(tp, 0x8fee, 0xffdf);\n-\t\tsram2_write(tp, 0x8ff0, 0xffff);\n-\t\tsram2_write(tp, 0x8ff2, 0x0a4a);\n-\t\tsram2_write(tp, 0x8ff4, 0xaa5a);\n-\t\tsram2_write(tp, 0x8ff6, 0x0a4a);\n-\t\tsram2_write(tp, 0x8ff8, 0xaa5a);\n+\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);\n \n-\t\tsram2_write_w0w1(tp, 0x88d5, 0xff00, 0x0200);\n-\t\tbreak;\n+\tr8153b_u1u2en(tp, false);\n \n-\tdefault:\n-\t\tbreak;\n-\t}\n+\tr8156b_wait_loading_flash(tp);\n \n-\tif (rtl_phy_patch_request(tp, true, true))\n+\tif (wait_autoload_done(tp))\n \t\treturn;\n \n-\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);\n+\tdata = r8153_phy_status(tp, 0);\n+\tif (data == PHY_STAT_EXT_INIT) {\n+\t\tocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));\n+\t\tocp_reg_clr_bits(tp, 0xa466, BIT(0));\n+\t}\n \n-\tocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);\n+\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n \n-\ttp-\u003eups_info._10m_ckdiv = true;\n-\ttp-\u003eups_info.eee_plloff_100 = false;\n-\ttp-\u003eups_info.eee_plloff_giga = false;\n+\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n \n-\tocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);\n-\ttp-\u003eups_info.eee_ckdiv = true;\n+\tr8157_u2p3en(tp, false);\n \n-\trtl_phy_patch_request(tp, false, true);\n+\t/* Disable Interrupt Mitigation */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,\n+\t\t\t BIT(0) | BIT(1) | BIT(2) | BIT(7));\n \n-\trtl_green_en(tp, test_bit(GREEN_ETHERNET, \u0026tp-\u003eflags));\n+\t/* Disable Auto Speed up */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);\n \n-\tocp_reg_clr_bits(tp, 0xa428, BIT(9));\n-\tocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1));\n-\ttp-\u003eups_info.lite_mode = 0;\n+\t/* MSC timer = 0xfff * 8ms = 32760 ms */\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);\n \n-\tif (tp-\u003eeee_en)\n-\t\trtl_eee_enable(tp, true);\n+\t/* U1/U2/L1 idle timer. 500 us */\n+\tocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);\n \n-\tr8153_aldps_en(tp, true);\n-\tr8152b_enable_fc(tp);\n+\tr8157_power_cut_en(tp, false);\n+\tr8157_ups_en(tp, false);\n+\tr8153_queue_wake(tp, false);\n+\trtl_runtime_suspend_enable(tp, false);\n \n-\tset_bit(PHY_RESET, \u0026tp-\u003eflags);\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);\n+\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);\n+\n+\t/* Clear Warm RST / Bus RST event flag */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));\n+\n+\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n+\t\tr8153b_u1u2en(tp, true);\n+\n+\tusb_enable_lpm(tp-\u003eudev);\n+\n+\tr8156_mac_clk_spd(tp, true);\n+\n+\tif (rtl8152_get_speed(tp) \u0026 LINK_STATUS)\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t\t CUR_LINK_OK | POLL_LINK_CHG);\n+\telse\n+\t\tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t CUR_LINK_OK, POLL_LINK_CHG);\n+\n+\tset_bit(GREEN_ETHERNET, \u0026tp-\u003eflags);\n+\n+\t/* RX aggregation / 16 bytes RX descriptor / Bulk In End transfer */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,\n+\t\t\t RX_AGG_DISABLE | RX_DESC_16B | RX_END_TRANSFER_EN);\n+\n+\t/* Disable Rx Zero Len */\n+\trtl_bmu_clr_bits(tp, 0x2300, BIT(3));\n+\n+\t/* TX descriptor Signature */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));\n+\n+\tr8156_mdio_force_mode(tp);\n+\trtl_tally_reset(tp);\n+\n+\ttp-\u003ecoalesce = 15000;\t/* 15 us */\n }\n \n static int r8159_wait_backup_restore(struct r8152 *tp)\n@@ -8342,78 +9297,53 @@ static int r8159_wait_backup_restore(struct r8152 *tp)\n \t\t\t ocp_data \u0026 BACKUP_RESTRORE, 200, 20000, false);\n }\n \n-static void r8156_init(struct r8152 *tp)\n+static void r8159_init(struct r8152 *tp)\n {\n-\tu32 ocp_data;\n \tu16 data;\n-\tint i;\n \n \tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\treturn;\n \n-\tif (tp-\u003eversion == RTL_VER_16 || tp-\u003eversion == RTL_VER_17) {\n-\t\tocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));\n-\t\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));\n-\t}\n+\t/* Enable SW reset */\n+\tocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));\n \n \tocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);\n \n-\tif (tp-\u003eversion \u003c RTL_VER_16)\n-\t\tocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);\n-\n \tocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_12 \u0026\u0026 tp-\u003eversion \u003c= RTL_VER_15)\n-\t\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_U2P3_CTRL, RX_DETECT8);\n-\n \tr8153b_u1u2en(tp, false);\n \n-\tswitch (tp-\u003eversion) {\n-\tcase RTL_VER_13:\n-\tcase RTL_VER_15:\n-\tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n-\t\tr8156b_wait_loading_flash(tp);\n-\t\tbreak;\n-\tdefault:\n-\t\tbreak;\n-\t}\n-\n-\tfor (i = 0; i \u003c 500; i++) {\n-\t\tif (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) \u0026\n-\t\t AUTOLOAD_DONE)\n-\t\t\tbreak;\n+\tr8156b_wait_loading_flash(tp);\n \n-\t\tmsleep(20);\n-\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n-\t\t\treturn;\n-\t}\n+\tif (wait_autoload_done(tp))\n+\t\treturn;\n \n-\tif (tp-\u003eversion == RTL_VER_17 \u0026\u0026 r8159_wait_backup_restore(tp)) {\n+\tif (r8159_wait_backup_restore(tp)) {\n \t\trtl_set_inaccessible(tp);\n-\t\tdev_err(\u0026tp-\u003eintf-\u003edev, \"init failed, backup-restore timed out\\n\");\n+\t\tdev_err(\u0026tp-\u003eintf-\u003edev,\n+\t\t\t\"init failed, backup-restore timed out\\n\");\n \t\treturn;\n \t}\n \n \tdata = r8153_phy_status(tp, 0);\n \tif (data == PHY_STAT_EXT_INIT) {\n \t\tocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));\n-\t\tif (tp-\u003eversion \u003e= RTL_VER_12)\n-\t\t\tocp_reg_clr_bits(tp, 0xa466, BIT(0));\n+\t\tocp_reg_clr_bits(tp, 0xa466, BIT(0));\n \t}\n \n-\tdata = r8152_mdio_read(tp, MII_BMCR);\n-\tif (data \u0026 BMCR_PDOWN) {\n-\t\tdata \u0026= ~BMCR_PDOWN;\n-\t\tr8152_mdio_write(tp, MII_BMCR, data);\n-\t}\n+\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n \n \tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_16)\n-\t\tr8157_u2p3en(tp, false);\n-\telse\n-\t\tr8153_u2p3en(tp, false);\n+\tr8157_u2p3en(tp, false);\n+\n+\t/* Disable Interrupt Mitigation */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,\n+\t\t\t BIT(0) | BIT(1) | BIT(2) | BIT(7));\n+\n+\t/* Disable Auto Speed up */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);\n \n \t/* MSC timer = 0xfff * 8ms = 32760 ms */\n \tocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);\n@@ -8421,72 +9351,53 @@ static void r8156_init(struct r8152 *tp)\n \t/* U1/U2/L1 idle timer. 500 us */\n \tocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_16)\n-\t\tr8157_power_cut_en(tp, false);\n-\telse\n-\t\tr8153b_power_cut_en(tp, false);\n-\n-\tr8156_ups_en(tp, false);\n+\tr8157_power_cut_en(tp, false);\n+\tr8157_ups_en(tp, false);\n \tr8153_queue_wake(tp, false);\n \trtl_runtime_suspend_enable(tp, false);\n \n-\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n-\t\tr8153b_u1u2en(tp, true);\n-\n-\tusb_enable_lpm(tp-\u003eudev);\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_12 \u0026\u0026 tp-\u003eversion \u003c= RTL_VER_15) {\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);\n+\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);\n \n-\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);\n+\t/* Clear Warm RST / Bus RST event flag */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));\n \n-\t\t/* enable fc timer and set timer to 600 ms. */\n-\t\tocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, CTRL_TIMER_EN | (600 / 8));\n+\t/* Disable FW u1u2 patch option */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xb9a6, BIT(0));\n \n-\t\tocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL);\n-\t\tif (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) \u0026 DACK_DET_EN))\n-\t\t\tocp_data |= FLOW_CTRL_PATCH_2;\n-\t\tocp_data \u0026= ~AUTO_SPEEDUP;\n-\t\tocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data);\n+\tif (tp-\u003eudev-\u003espeed \u003e= USB_SPEED_SUPER)\n+\t\tr8153b_u1u2en(tp, true);\n \n-\t\tocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);\n-\t}\n+\tusb_enable_lpm(tp-\u003eudev);\n \n \tr8156_mac_clk_spd(tp, true);\n \n-\tif (tp-\u003eversion \u003c RTL_VER_16)\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, PLA_MCU_SPDWN_EN);\n-\n-\tocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);\n \tif (rtl8152_get_speed(tp) \u0026 LINK_STATUS)\n-\t\tocp_data |= CUR_LINK_OK;\n+\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t\t CUR_LINK_OK | POLL_LINK_CHG);\n \telse\n-\t\tocp_data \u0026= ~CUR_LINK_OK;\n-\tocp_data |= POLL_LINK_CHG;\n-\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);\n+\t\tocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,\n+\t\t\t CUR_LINK_OK, POLL_LINK_CHG);\n \n \tset_bit(GREEN_ETHERNET, \u0026tp-\u003eflags);\n \n-\t/* RX aggregation / 16 bytes RX descriptor\n-\t * BIT(11) is specific to RTL8159, with unknown meaning\n-\t */\n-\tif (tp-\u003eversion == RTL_VER_17)\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,\n-\t\t\t\t RX_AGG_DISABLE | RX_DESC_16B | BIT(11));\n-\telse if (tp-\u003eversion == RTL_VER_16)\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL, RX_AGG_DISABLE | RX_DESC_16B);\n-\telse\n-\t\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL, RX_AGG_DISABLE | RX_ZERO_EN);\n+\t/* RX aggregation / 16 bytes RX descriptor / Bulk In End transfer */\n+\tocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,\n+\t\t\t RX_AGG_DISABLE | RX_DESC_16B | RX_END_TRANSFER_EN);\n \n-\tif (tp-\u003eversion \u003c RTL_VER_12)\n-\t\tocp_byte_set_bits(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ACT_ODMA);\n+\t/* Disable Rx Zero Len */\n+\trtl_bmu_clr_bits(tp, 0x2300, BIT(3));\n \n-\tif (tp-\u003eversion \u003e= RTL_VER_16) {\n-\t\t/* Disable Rx Zero Len */\n-\t\trtl_bmu_clr_bits(tp, 0x2300, BIT(3));\n-\t\t/* TX descriptor Signature */\n-\t\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));\n-\t}\n+\t/* TX descriptor Signature */\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));\n+\n+\t/* Enable u2phy backup restore patch */\n+\tif (tp-\u003eversion == RTL_VER_17_QFN68)\n+\t\tocp_byte_set_bits(tp, MCU_TYPE_USB, 0xb99c, BIT(0));\n+\n+\t/* Enable u3phy patch backup */\n+\tocp_write_word(tp, MCU_TYPE_USB, 0xb9a2, 0x0448);\n \n \tr8156_mdio_force_mode(tp);\n \trtl_tally_reset(tp);\n@@ -8926,8 +9837,16 @@ int rtl8152_get_link_ksettings(struct net_device *netdev,\n \t\t\t cmd-\u003elink_modes.supported, tp-\u003esupport_10000full);\n \n \tif (tp-\u003esupport_2500full || tp-\u003esupport_5000full || tp-\u003esupport_10000full) {\n-\t\tu16 ocp_10gbt_ctrl = ocp_reg_read(tp, OCP_10GBT_CTRL);\n-\t\tu16 ocp_10gbt_stat = ocp_reg_read(tp, OCP_10GBT_STAT);\n+\t\tu16 ocp_10gbt_ctrl;\n+\t\tu16 ocp_10gbt_stat;\n+\n+\t\tret = ocp_reg_read(tp, OCP_10GBT_CTRL, \u0026ocp_10gbt_ctrl);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out_unlock;\n+\n+\t\tret = ocp_reg_read(tp, OCP_10GBT_STAT, \u0026ocp_10gbt_stat);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out_unlock;\n \n \t\tif (tp-\u003esupport_2500full) {\n \t\t\tlinkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,\n@@ -8969,12 +9888,13 @@ int rtl8152_get_link_ksettings(struct net_device *netdev,\n \t\t}\n \t}\n \n+out_unlock:\n \tmutex_unlock(\u0026tp-\u003econtrol);\n \n \tusb_autopm_put_interface(tp-\u003eintf);\n \n out:\n-\treturn ret;\n+\treturn ret \u003c 0 ? ret : 0;\n }\n \n static int rtl8152_set_link_ksettings(struct net_device *dev,\n@@ -9155,21 +10075,37 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)\n \t__ETHTOOL_DECLARE_LINK_MODE_MASK(common) = {};\n \tu16 speed = rtl8152_get_speed(tp);\n \tu16 val;\n+\tint ret;\n+\n+\tret = ocp_reg_read(tp, OCP_EEE_ABLE, \u0026val);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n \n-\tval = ocp_reg_read(tp, OCP_EEE_ABLE);\n \tmii_eee_cap1_mod_linkmode_t(eee-\u003esupported, val);\n \n-\tval = ocp_reg_read(tp, OCP_EEE_ADV);\n+\tret = ocp_reg_read(tp, OCP_EEE_ADV, \u0026val);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n \tmii_eee_cap1_mod_linkmode_t(eee-\u003eadvertised, val);\n \n-\tval = ocp_reg_read(tp, OCP_EEE_LPABLE);\n+\tret = ocp_reg_read(tp, OCP_EEE_LPABLE, \u0026val);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n \tmii_eee_cap1_mod_linkmode_t(eee-\u003elp_advertised, val);\n \n \tif (tp-\u003esupport_2500full || tp-\u003esupport_5000full) {\n-\t\tval = ocp_reg_read(tp, OCP_EEE_ADV2);\n+\t\tret = ocp_reg_read(tp, OCP_EEE_ADV2, \u0026val);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out;\n+\n \t\tmii_eee_cap2_mod_linkmode_adv_t(eee-\u003eadvertised, val);\n \n-\t\tval = ocp_reg_read(tp, OCP_EEE_LPABLE2);\n+\t\tret = ocp_reg_read(tp, OCP_EEE_LPABLE2, \u0026val);\n+\t\tif (ret \u003c 0)\n+\t\t\tgoto out;\n+\n \t\tmii_eee_cap2_mod_linkmode_adv_t(eee-\u003elp_advertised, val);\n \t}\n \n@@ -9205,7 +10141,8 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)\n \tlinkmode_and(common, common, eee-\u003elp_advertised);\n \teee-\u003eeee_active = !linkmode_empty(common);\n \n-\treturn 0;\n+out:\n+\treturn ret \u003c 0 ? ret : 0;\n }\n \n static int\n@@ -9445,7 +10382,7 @@ static int rtl8152_set_ringparam(struct net_device *netdev,\n static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)\n {\n \tstruct r8152 *tp = netdev_priv(netdev);\n-\tu16 bmcr, lcladv, rmtadv;\n+\tint bmcr, lcladv, rmtadv;\n \tu8 cap;\n \n \tif (usb_autopm_get_interface(tp-\u003eintf) \u003c 0)\n@@ -9461,7 +10398,10 @@ static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pau\n \n \tusb_autopm_put_interface(tp-\u003eintf);\n \n-\tif (!(bmcr \u0026 BMCR_ANENABLE)) {\n+\t/* Without a readable PHY, or with autoneg off, there is no flow\n+\t * control to report.\n+\t */\n+\tif (bmcr \u003c 0 || lcladv \u003c 0 || rmtadv \u003c 0 || !(bmcr \u0026 BMCR_ANENABLE)) {\n \t\tpause-\u003eautoneg = 0;\n \t\tpause-\u003erx_pause = 0;\n \t\tpause-\u003etx_pause = 0;\n@@ -9492,7 +10432,11 @@ static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_paus\n \n \tmutex_lock(\u0026tp-\u003econtrol);\n \n-\tif (pause-\u003eautoneg \u0026\u0026 !(r8152_mdio_read(tp, MII_BMCR) \u0026 BMCR_ANENABLE)) {\n+\tret = r8152_mdio_read(tp, MII_BMCR);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tif (pause-\u003eautoneg \u0026\u0026 !(ret \u0026 BMCR_ANENABLE)) {\n \t\tret = -EINVAL;\n \t\tgoto out;\n \t}\n@@ -9503,16 +10447,20 @@ static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_paus\n \tif (pause-\u003etx_pause)\n \t\tcap |= FLOW_CTRL_TX;\n \n-\told = r8152_mdio_read(tp, MII_ADVERTISE);\n+\tret = r8152_mdio_read(tp, MII_ADVERTISE);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\told = ret;\n \tnew1 = (old \u0026 ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM)) | mii_advertise_flowctrl(cap);\n \tif (old != new1)\n-\t\tr8152_mdio_write(tp, MII_ADVERTISE, new1);\n+\t\tret = r8152_mdio_write(tp, MII_ADVERTISE, new1);\n \n out:\n \tmutex_unlock(\u0026tp-\u003econtrol);\n \tusb_autopm_put_interface(tp-\u003eintf);\n \n-\treturn ret;\n+\treturn ret \u003c 0 ? ret : 0;\n }\n \n static const struct ethtool_ops ops = {\n@@ -9546,7 +10494,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)\n {\n \tstruct r8152 *tp = netdev_priv(netdev);\n \tstruct mii_ioctl_data *data = if_mii(rq);\n-\tint res;\n+\tint res, val;\n \n \tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n \t\treturn -ENODEV;\n@@ -9562,7 +10510,11 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)\n \n \tcase SIOCGMIIREG:\n \t\tmutex_lock(\u0026tp-\u003econtrol);\n-\t\tdata-\u003eval_out = r8152_mdio_read(tp, data-\u003ereg_num);\n+\t\tval = r8152_mdio_read(tp, data-\u003ereg_num);\n+\t\tif (val \u003c 0)\n+\t\t\tres = val;\n+\t\telse\n+\t\t\tdata-\u003eval_out = val;\n \t\tmutex_unlock(\u0026tp-\u003econtrol);\n \t\tbreak;\n \n@@ -9572,7 +10524,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)\n \t\t\tbreak;\n \t\t}\n \t\tmutex_lock(\u0026tp-\u003econtrol);\n-\t\tr8152_mdio_write(tp, data-\u003ereg_num, data-\u003eval_in);\n+\t\tres = r8152_mdio_write(tp, data-\u003ereg_num, data-\u003eval_in);\n \t\tmutex_unlock(\u0026tp-\u003econtrol);\n \t\tbreak;\n \n@@ -9663,11 +10615,6 @@ static void rtl8153_unload(struct r8152 *tp)\n \t\treturn;\n \n \tr8153_power_cut_en(tp, false);\n-\n-\tif (tp-\u003eversion \u003e= RTL_VER_16) {\n-\t\t/* Disable Interrupt Mitigation */\n-\t\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04, BIT(0) | BIT(1) | BIT(2) | BIT(7));\n-\t}\n }\n \n static void rtl8153b_unload(struct r8152 *tp)\n@@ -9678,6 +10625,16 @@ static void rtl8153b_unload(struct r8152 *tp)\n \tr8153b_power_cut_en(tp, false);\n }\n \n+static void rtl8157_unload(struct r8152 *tp)\n+{\n+\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n+\t\treturn;\n+\n+\tr8157_power_cut_en(tp, false);\n+\tocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,\n+\t\t\t BIT(0) | BIT(1) | BIT(2) | BIT(7));\n+}\n+\n static int r8152_desc_init(struct r8152 *tp)\n {\n \ttp-\u003erx_desc.size = sizeof(struct rx_desc);\n@@ -9730,6 +10687,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\tops-\u003ein_nway\t\t= rtl8152_in_nway;\n \t\tops-\u003ehw_phy_cfg\t\t= r8152b_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl_runtime_suspend_enable;\n+\t\tops-\u003ephy_read\t\t= r8152_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8152_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 16 * 1024;\n \t\ttp-\u003eeee_en\t\t= true;\n \t\ttp-\u003eeee_adv\t\t= MDIO_EEE_100TX;\n@@ -9752,6 +10711,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\tops-\u003ehw_phy_cfg\t\t= r8153_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8153_runtime_enable;\n \t\tops-\u003echange_mtu\t\t= rtl8153_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8152_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8152_phy_write;\n \t\tif (tp-\u003eudev-\u003espeed \u003c USB_SPEED_SUPER)\n \t\t\ttp-\u003erx_buf_sz\t= 16 * 1024;\n \t\telse\n@@ -9775,6 +10736,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\tops-\u003ehw_phy_cfg\t\t= r8153b_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8153b_runtime_enable;\n \t\tops-\u003echange_mtu\t\t= rtl8153_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8152_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8152_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 32 * 1024;\n \t\ttp-\u003eeee_en\t\t= true;\n \t\ttp-\u003eeee_adv\t\t= MDIO_EEE_1000T | MDIO_EEE_100TX;\n@@ -9799,6 +10762,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\tops-\u003ehw_phy_cfg\t\t= r8156_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8156_runtime_enable;\n \t\tops-\u003echange_mtu\t\t= rtl8156_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8152_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8152_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 48 * 1024;\n \t\ttp-\u003esupport_2500full\t= 1;\n \t\tr8152_desc_init(tp);\n@@ -9812,8 +10777,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\ttp-\u003eeee_en\t\t= true;\n \t\ttp-\u003eeee_adv\t\t= MDIO_EEE_1000T | MDIO_EEE_100TX;\n \t\ttp-\u003eeee_adv2\t\t= MDIO_EEE_2_5GT;\n-\t\tops-\u003einit\t\t= r8156_init;\n-\t\tops-\u003eenable\t\t= rtl8156_enable;\n+\t\tops-\u003einit\t\t= r8156b_init;\n+\t\tops-\u003eenable\t\t= rtl8156b_enable;\n \t\tops-\u003edisable\t\t= rtl8153_disable;\n \t\tops-\u003eup\t\t\t= rtl8156_up;\n \t\tops-\u003edown\t\t= rtl8156_down;\n@@ -9824,6 +10789,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\tops-\u003ehw_phy_cfg\t\t= r8156b_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8156_runtime_enable;\n \t\tops-\u003echange_mtu\t\t= rtl8156_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8152_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8152_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 48 * 1024;\n \t\tr8152_desc_init(tp);\n \t\tbreak;\n@@ -9841,6 +10808,8 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\tops-\u003ehw_phy_cfg\t\t= r8153c_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8153c_runtime_enable;\n \t\tops-\u003echange_mtu\t\t= rtl8153c_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8152_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8152_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 32 * 1024;\n \t\ttp-\u003eeee_en\t\t= true;\n \t\ttp-\u003eeee_adv\t\t= MDIO_EEE_1000T | MDIO_EEE_100TX;\n@@ -9851,40 +10820,45 @@ static int rtl_ops_init(struct r8152 *tp)\n \t\ttp-\u003eeee_en\t\t= true;\n \t\ttp-\u003eeee_adv\t\t= MDIO_EEE_1000T | MDIO_EEE_100TX;\n \t\ttp-\u003eeee_adv2\t\t= MDIO_EEE_2_5GT | MDIO_EEE_5GT;\n-\t\tops-\u003einit\t\t= r8156_init;\n-\t\tops-\u003eenable\t\t= rtl8156_enable;\n+\t\tops-\u003einit\t\t= r8157_init;\n+\t\tops-\u003eenable\t\t= rtl8157_enable;\n \t\tops-\u003edisable\t\t= rtl8153_disable;\n-\t\tops-\u003eup\t\t\t= rtl8156_up;\n-\t\tops-\u003edown\t\t= rtl8156_down;\n-\t\tops-\u003eunload\t\t= rtl8153_unload;\n+\t\tops-\u003eup\t\t\t= rtl8157_up;\n+\t\tops-\u003edown\t\t= rtl8157_down;\n+\t\tops-\u003eunload\t\t= rtl8157_unload;\n \t\tops-\u003eeee_get\t\t= r8153_get_eee;\n \t\tops-\u003eeee_set\t\t= r8152_set_eee;\n \t\tops-\u003ein_nway\t\t= rtl8153_in_nway;\n \t\tops-\u003ehw_phy_cfg\t\t= r8157_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8157_runtime_enable;\n-\t\tops-\u003echange_mtu\t\t= rtl8156_change_mtu;\n+\t\tops-\u003echange_mtu\t\t= rtl8157_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8157_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8157_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 32 * 1024;\n \t\ttp-\u003esupport_2500full\t= 1;\n \t\ttp-\u003esupport_5000full\t= 1;\n \t\tr8157_desc_init(tp);\n \t\tbreak;\n \n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\ttp-\u003eeee_en\t\t= true;\n \t\ttp-\u003eeee_adv\t\t= MDIO_EEE_100TX | MDIO_EEE_1000T | MDIO_EEE_10GT;\n \t\ttp-\u003eeee_adv2\t\t= MDIO_EEE_2_5GT | MDIO_EEE_5GT;\n-\t\tops-\u003einit\t\t= r8156_init;\n-\t\tops-\u003eenable\t\t= rtl8156_enable;\n+\t\tops-\u003einit\t\t= r8159_init;\n+\t\tops-\u003eenable\t\t= rtl8157_enable;\n \t\tops-\u003edisable\t\t= rtl8153_disable;\n-\t\tops-\u003eup\t\t\t= rtl8156_up;\n-\t\tops-\u003edown\t\t= rtl8156_down;\n-\t\tops-\u003eunload\t\t= rtl8153_unload;\n+\t\tops-\u003eup\t\t\t= rtl8157_up;\n+\t\tops-\u003edown\t\t= rtl8157_down;\n+\t\tops-\u003eunload\t\t= rtl8157_unload;\n \t\tops-\u003eeee_get\t\t= r8153_get_eee;\n \t\tops-\u003eeee_set\t\t= r8152_set_eee;\n \t\tops-\u003ein_nway\t\t= rtl8153_in_nway;\n-\t\tops-\u003ehw_phy_cfg\t\t= r8157_hw_phy_cfg;\n+\t\tops-\u003ehw_phy_cfg\t\t= r8159_hw_phy_cfg;\n \t\tops-\u003eautosuspend_en\t= rtl8157_runtime_enable;\n-\t\tops-\u003echange_mtu\t\t= rtl8156_change_mtu;\n+\t\tops-\u003echange_mtu\t\t= rtl8157_change_mtu;\n+\t\tops-\u003ephy_read\t\t= r8157_phy_read;\n+\t\tops-\u003ephy_write\t\t= r8157_phy_write;\n \t\ttp-\u003erx_buf_sz\t\t= 48 * 1024;\n \t\ttp-\u003esupport_2500full\t= 1;\n \t\ttp-\u003esupport_5000full\t= 1;\n@@ -9961,7 +10935,8 @@ static int rtl_fw_init(struct r8152 *tp)\n \tcase RTL_VER_16:\n \t\trtl_fw-\u003efw_name\t\t= FIRMWARE_8157_1;\n \t\tbreak;\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\trtl_fw-\u003efw_name\t\t= FIRMWARE_8159_1;\n \t\tbreak;\n \tdefault:\n@@ -9971,9 +10946,38 @@ static int rtl_fw_init(struct r8152 *tp)\n \treturn 0;\n }\n \n+static u32 __rtl_get_pkg_det(struct usb_device *udev)\n+{\n+\tu32 pkg_det = 0;\n+\t__le32 *tmp;\n+\tint ret, i;\n+\n+\ttmp = kmalloc_obj(*tmp);\n+\tif (!tmp)\n+\t\treturn 0;\n+\n+\tfor (i = 0, ret = 0; i \u003c 3 \u0026\u0026 ret != 4; i++)\n+\t\tret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),\n+\t\t\t\t RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,\n+\t\t\t\t PLA_PKG_DET, MCU_TYPE_PLA, tmp,\n+\t\t\t\t sizeof(*tmp), USB_CTRL_GET_TIMEOUT);\n+\n+\tif (ret == sizeof(*tmp)) {\n+\t\tif (i != 0)\n+\t\t\tdev_warn(\u0026udev-\u003edev,\n+\t\t\t\t \"Needed %d retries to read package\\n\", i);\n+\n+\t\tpkg_det = __le32_to_cpu(*tmp) \u0026 PKG_MASK;\n+\t}\n+\n+\tkfree(tmp);\n+\treturn pkg_det;\n+}\n+\n static u8 __rtl_get_hw_ver(struct usb_device *udev)\n {\n \tu32 ocp_data = 0;\n+\tu32 pkg_det = 0;\n \t__le32 *tmp;\n \tu8 version;\n \tint ret;\n@@ -10056,7 +11060,16 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev)\n \t\tversion = RTL_VER_16;\n \t\tbreak;\n \tcase 0x2020:\n-\t\tversion = RTL_VER_17;\n+\t\tpkg_det = __rtl_get_pkg_det(udev);\n+\t\tif (pkg_det == 0x1e || pkg_det == 0x1c) {\n+\t\t\tversion = RTL_VER_17_QFN68;\n+\t\t} else if (pkg_det == 0x18 || pkg_det == 0x1a) {\n+\t\t\tversion = RTL_VER_17_QFN100;\n+\t\t} else {\n+\t\t\tversion = RTL_VER_UNKNOWN;\n+\t\t\tdev_info(\u0026udev-\u003edev, \"Unknown package 0x%04x\\n\",\n+\t\t\t\t pkg_det);\n+\t\t}\n \t\tbreak;\n \tdefault:\n \t\tversion = RTL_VER_UNKNOWN;\n@@ -10215,7 +11228,8 @@ static int rtl8152_probe_once(struct usb_interface *intf,\n \tcase RTL_VER_13:\n \tcase RTL_VER_15:\n \tcase RTL_VER_16:\n-\tcase RTL_VER_17:\n+\tcase RTL_VER_17_QFN68:\n+\tcase RTL_VER_17_QFN100:\n \t\tnetdev-\u003emax_mtu = size_to_mtu(16 * 1024);\n \t\tbreak;\n \tcase RTL_VER_01:\n"
} |
| 2/1 | 2026/10/02 04:53 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"USB_RTL8152",
"USB_NET_DRIVERS",
"USB",
"NET"
],
"FocusSymbols": [
"rtl_tgphy_access",
"wait_tgphy_cmd_ready",
"rtl_fc_pause_pkt_en",
"r8157_phy_read",
"r8157_phy_write",
"rtl8157_enable",
"rtl8157_up",
"rtl8157_down",
"rtl8157_change_mtu",
"r8159_hw_phy_cfg",
"r8159_init",
"r8157_init",
"rtl8156b_enable",
"rtl8156b_init",
"wait_autoload_done",
"__rtl_get_pkg_det"
],
"Reasoning": "The patch introduces and refactors substantial hardware initialization and configuration logic for RTL8156B, RTL8157, and RTL8159 USB Ethernet adapters in the r8152 driver. Changes include new TGPHY access routines (rtl_tgphy_access), pause packet count calculations (rtl_fc_pause_pkt_en), package detection (__rtl_get_pkg_det), polling helpers (wait_autoload_done), and revised WARN_ON_ONCE assertions during PHY configuration. These code paths are fully reachable in virtualized environments via USB device emulation (e.g. syzkaller syz_usb_connect / USB Raw Gadget) and subsequent network device and ethtool/ioctl operations.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 3cf8c5c313bdcfe921621a6dcd8d2353064c8dbd
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Oct 2 04:53:29 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index af3d7dcb2f141..baac964fea80f 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -64,6 +64,7 @@
#define PLA_MACDBG_POST 0xd38e /* RTL_VER_04 only */
#define PLA_EXTRA_STATUS 0xd398
#define PLA_GPHY_CTRL 0xd3ae
+#define PLA_PKG_DET 0xdc48
#define PLA_POL_GPIO_CTRL 0xdc6a
#define PLA_EFUSE_DATA 0xdd00
#define PLA_EFUSE_CMD 0xdd02
@@ -78,6 +79,7 @@
#define PLA_EEE_TXTWSYS_2P5G 0xe058
#define PLA_EEEP_CR 0xe080
#define PLA_MAC_PWR_CTRL 0xe0c0
+#define PLA_RMT_WAKE 0xe0c8
#define PLA_MAC_PWR_CTRL2 0xe0ca
#define PLA_MAC_PWR_CTRL3 0xe0cc
#define PLA_MAC_PWR_CTRL4 0xe0ce
@@ -87,6 +89,7 @@
#define PLA_MTPS 0xe615
#define PLA_TXFIFO_CTRL 0xe618
#define PLA_TXFIFO_FULL 0xe61a
+#define PLA_PAUSE_LIMIT 0xe61e
#define PLA_RSTTALLY 0xe800
#define PLA_CR 0xe813
#define PLA_CRWECR 0xe81c
@@ -129,6 +132,7 @@
#define USB_BURST_SIZE 0xcfc0
#define USB_FW_FIX_EN0 0xcfca
#define USB_FW_FIX_EN1 0xcfcc
+#define USB_FW_USB_VER 0xcfd7
#define USB_LPM_CONFIG 0xcfd8
#define USB_ECM_OPTION 0xcfee
#define USB_CSTMR 0xcfef /* RTL8153A */
@@ -160,6 +164,9 @@
#define USB_ADV_ADDR 0xd5d6
#define USB_ADV_DATA 0xd5d8
#define USB_ADV_CMD 0xd5dc
+#define USB_TGPHY_ADDR 0xd630
+#define USB_TGPHY_DATA 0xd632
+#define USB_TGPHY_CMD 0xd634
#define USB_UPS_CTRL 0xd800
#define USB_POWER_CUT 0xd80a
#define USB_MISC_0 0xd81a
@@ -289,10 +296,17 @@
#define IFG_144NS BIT(9)
#define IFG_96NS (BIT(9) | BIT(8))
+/* PLA_PKG_DET */
+#define PKG_MASK 0x1e
+
/* PLA_MTPS */
#define MTPS_JUMBO (12 * 1024 / 64)
#define MTPS_DEFAULT (6 * 1024 / 64)
+/* PLA_PAUSE_LIMIT */
+#define PAUSE_LIMIT_EN BIT(3)
+#define PAUSE_LIMIT_MASK 0xf0
+
/* PLA_RSTTALLY */
#define TALLY_RESET 0x0001
@@ -371,6 +385,9 @@
#define MCU_CLK_RATIO_MASK 0x0f0f0f0f
#define ALDPS_SPDWN_RATIO 0x0f87
+/* PLA_RMT_WAKE */
+#define RMT_WAKE_EN BIT(0)
+
/* PLA_MAC_PWR_CTRL2 */
#define EEE_SPDWN_RATIO 0x8007
#define MAC_CLK_SPDWN_EN BIT(15)
@@ -417,6 +434,7 @@
/* PLA_INDICATE_FALG */
#define UPCOMING_RUNTIME_D3 BIT(0)
+#define PREBOOT_OPTION BIT(1)
/* PLA_MACDBG_PRE and PLA_MACDBG_POST */
#define DEBUG_OE BIT(0)
@@ -502,6 +520,10 @@
#define ADV_CMD_WR BIT(1)
#define ADV_CMD_IP BIT(2)
+/* USB_TGPHY_CMD */
+#define TGPHY_CMD_BUSY BIT(0)
+#define TGPHY_CMD_WR BIT(1)
+
/* USB_UPS_CTRL */
#define POWER_CUT 0x0100
@@ -542,6 +564,7 @@
#define RX_AGG_DISABLE 0x0010
#define RX_ZERO_EN 0x0080
#define RX_DESC_16B 0x0400
+#define RX_END_TRANSFER_EN BIT(11)
/* USB_U2P3_CTRL */
#define U2P3_ENABLE 0x0001
@@ -597,6 +620,11 @@
#define UPS_FLAGS_250M_CKDIV BIT(2)
#define UPS_FLAGS_EN_ALDPS BIT(3)
#define UPS_FLAGS_CTAP_SHORT_DIS BIT(4)
+#define UPS_FLAGS_EN_100M_EEE BIT(9)
+#define UPS_FLAGS_EN_1000M_EEE BIT(10)
+#define UPS_FLAGS_EN_2500M_EEE BIT(11)
+#define UPS_FLAGS_EN_5000M_EEE BIT(12)
+#define UPS_FLAGS_EN_10G_EEE BIT(13)
#define UPS_FLAGS_SPEED_MASK (0xf << 16)
#define ups_flags_speed(x) ((x) << 16)
#define UPS_FLAGS_EN_EEE BIT(20)
@@ -645,6 +673,7 @@ enum spd_duplex {
/* OCP_POWER_CFG */
#define EEE_CLKDIV_EN 0x8000
#define EN_ALDPS 0x0004
+#define EN_ALDPS_PLLOFF 0x0002
#define EN_10M_PLLOFF 0x0001
/* OCP_EEE_CONFIG1 */
@@ -948,6 +977,8 @@ struct r8152 {
void (*hw_phy_cfg)(struct r8152 *tp);
void (*autosuspend_en)(struct r8152 *tp, bool enable);
void (*change_mtu)(struct r8152 *tp);
+ int (*phy_read)(struct r8152 *tp, u16 addr, u16 *data);
+ int (*phy_write)(struct r8152 *tp, u16 addr, u16 data);
} rtl_ops;
struct ups_info {
@@ -1247,7 +1278,8 @@ enum rtl_version {
RTL_VER_14,
RTL_VER_15,
RTL_VER_16,
- RTL_VER_17,
+ RTL_VER_17_QFN68,
+ RTL_VER_17_QFN100,
RTL_VER_MAX
};
@@ -1626,7 +1658,7 @@ static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
}
-static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
+static int r8152_phy_read(struct r8152 *tp, u16 addr, u16 *data)
{
u16 ocp_base, ocp_index;
@@ -1637,10 +1669,12 @@ static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
}
ocp_index = (addr & 0x0fff) | 0xb000;
- return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
+ *data = ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
+
+ return 0;
}
-static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
+static int r8152_phy_write(struct r8152 *tp, u16 addr, u16 data)
{
u16 ocp_base, ocp_index;
@@ -1652,16 +1686,33 @@ static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
ocp_index = (addr & 0x0fff) | 0xb000;
ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
+
+ return 0;
}
-static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
+static int ocp_reg_read(struct r8152 *tp, u16 addr, u16 *data)
{
- ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
+ return tp->rtl_ops.phy_read(tp, addr, data);
}
-static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+static int ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
{
- return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
+ return tp->rtl_ops.phy_write(tp, addr, data);
+}
+
+static inline int r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
+{
+ return ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
+}
+
+static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+{
+ u16 data;
+ int ret;
+
+ ret = ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2, &data);
+
+ return ret < 0 ? ret : data;
}
static int wait_cmd_ready(struct r8152 *tp, u16 cmd)
@@ -1780,16 +1831,32 @@ static int rtl_ip_set_bits(struct r8152 *tp, u16 addr, u32 set)
return rtl_ip_w0w1(tp, addr, 0, set);
}
-static void sram_write(struct r8152 *tp, u16 addr, u16 data)
+static int sram_write(struct r8152 *tp, u16 addr, u16 data)
{
- ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
- ocp_reg_write(tp, OCP_SRAM_DATA, data);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_write(tp, OCP_SRAM_DATA, data);
+
+out:
+ return ret;
}
-static u16 sram_read(struct r8152 *tp, u16 addr)
+static int sram_read(struct r8152 *tp, u16 addr, u16 *data)
{
- ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
- return ocp_reg_read(tp, OCP_SRAM_DATA);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_read(tp, OCP_SRAM_DATA, data);
+
+out:
+ return ret;
}
static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
@@ -1894,90 +1961,219 @@ static void ocp_byte_set_bits(struct r8152 *tp, u16 type, u16 index, u8 set)
ocp_byte_w0w1(tp, type, index, 0, set);
}
-static void ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
+static int ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
{
u16 data;
+ int ret;
+
+ ret = ocp_reg_read(tp, addr, &data);
+ if (ret < 0)
+ goto out;
- data = ocp_reg_read(tp, addr);
data = (data & ~clear) | set;
- ocp_reg_write(tp, addr, data);
+ ret = ocp_reg_write(tp, addr, data);
+
+out:
+ return ret;
}
-static void ocp_reg_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
+static int ocp_reg_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
{
- ocp_reg_w0w1(tp, addr, clear, 0);
+ return ocp_reg_w0w1(tp, addr, clear, 0);
}
-static void ocp_reg_set_bits(struct r8152 *tp, u16 addr, u16 set)
+static int ocp_reg_set_bits(struct r8152 *tp, u16 addr, u16 set)
{
- ocp_reg_w0w1(tp, addr, 0, set);
+ return ocp_reg_w0w1(tp, addr, 0, set);
}
-static void sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
+static int sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
{
u16 data;
+ int ret;
+
+ ret = sram_read(tp, addr, &data);
+ if (ret < 0)
+ goto out;
- data = sram_read(tp, addr);
data = (data & ~clear) | set;
- ocp_reg_write(tp, OCP_SRAM_DATA, data);
+ ret = ocp_reg_write(tp, OCP_SRAM_DATA, data);
+
+out:
+ return ret;
}
-static void sram_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
+static int sram_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
{
- sram_write_w0w1(tp, addr, clear, 0);
+ return sram_write_w0w1(tp, addr, clear, 0);
}
-static void sram_set_bits(struct r8152 *tp, u16 addr, u16 set)
+static int sram_set_bits(struct r8152 *tp, u16 addr, u16 set)
{
- sram_write_w0w1(tp, addr, 0, set);
+ return sram_write_w0w1(tp, addr, 0, set);
}
-static void sram2_write(struct r8152 *tp, u16 addr, u16 data)
+static int sram2_write(struct r8152 *tp, u16 addr, u16 data)
{
- ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
- ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+
+out:
+ return ret;
}
-static u16 sram2_read(struct r8152 *tp, u16 addr)
+static int sram2_read(struct r8152 *tp, u16 addr, u16 *data)
{
- ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
- return ocp_reg_read(tp, OCP_SRAM2_DATA);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_read(tp, OCP_SRAM2_DATA, data);
+
+out:
+ return ret;
}
-static void sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
+static int sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
{
u16 data;
+ int ret;
+
+ ret = sram2_read(tp, addr, &data);
+ if (ret < 0)
+ goto out;
- data = sram2_read(tp, addr);
data = (data & ~clear) | set;
- ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+ ret = ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+
+out:
+ return ret;
}
-static void r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)
+static int sram2_set_bits(struct r8152 *tp, u16 addr, u16 set)
+{
+ return sram2_write_w0w1(tp, addr, 0, set);
+}
+
+static int sram2_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
+{
+ return sram2_write_w0w1(tp, addr, clear, 0);
+}
+
+static int r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)
{
int data;
data = r8152_mdio_read(tp, addr);
- r8152_mdio_write(tp, addr, data & ~clear);
+ if (data < 0)
+ goto out;
+
+ data = r8152_mdio_write(tp, addr, data & ~clear);
+
+out:
+ return data;
}
-static void r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)
+static int r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)
{
int data;
data = r8152_mdio_read(tp, addr);
- r8152_mdio_write(tp, addr, data | set);
+ if (data < 0)
+ goto out;
+
+ data = r8152_mdio_write(tp, addr, data | set);
+
+out:
+ return data;
}
static int r8152_mdio_test_and_clr_bit(struct r8152 *tp, u16 addr, u16 clear)
{
- int data;
+ int data, ret;
- data = r8152_mdio_read(tp, addr);
- if (data & clear)
- r8152_mdio_write(tp, addr, data & ~clear);
+ ret = r8152_mdio_read(tp, addr);
+ if (ret < 0)
+ goto out;
+
+ data = ret;
+ if (data & clear) {
+ ret = r8152_mdio_write(tp, addr, data & ~clear);
+ if (ret < 0)
+ goto out;
+ }
+
+ ret = !!(data & clear);
+
+out:
+ return ret;
+}
+
+static int wait_tgphy_cmd_ready(struct r8152 *tp)
+{
+ u16 ocp_data;
+ int ret;
+
+ ret = read_poll_timeout(ocp_read_word, ocp_data,
+ test_bit(RTL8152_INACCESSIBLE, &tp->flags) ||
+ !(ocp_data & TGPHY_CMD_BUSY),
+ 2000, 20000, false, tp,
+ MCU_TYPE_USB, USB_TGPHY_CMD);
+
+ if (ret) {
+ rtl_set_inaccessible(tp);
+ dev_err(&tp->intf->dev, "TGPHY cmd busy timeout\n");
+ }
+
+ return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : ret;
+}
+
+static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data, bool write)
+{
+ u16 cmd = 0;
+ int ret;
+
+ ret = wait_tgphy_cmd_ready(tp);
+ if (ret < 0)
+ goto out;
+
+ if (write) {
+ cmd |= TGPHY_CMD_WR;
+ ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA, *data);
+ }
+
+ ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_ADDR, addr);
+
+ cmd |= TGPHY_CMD_BUSY;
+ ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_CMD, cmd);
+
+ if (!write) {
+ ret = wait_tgphy_cmd_ready(tp);
+ if (ret < 0)
+ goto out;
+
+ *data = ocp_read_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA);
+ }
+
+out:
+ return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : ret;
+}
+
+static int r8157_phy_read(struct r8152 *tp, u16 addr, u16 *data)
+{
+ return rtl_tgphy_access(tp, addr, data, false);
+}
- return data & clear;
+static int r8157_phy_write(struct r8152 *tp, u16 addr, u16 data)
+{
+ return rtl_tgphy_access(tp, addr, &data, true);
}
static int
@@ -3412,7 +3608,8 @@ static void rtl8152_nic_reset(struct r8152 *tp)
break;
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_CR, CR_RE | CR_TE);
break;
@@ -3452,7 +3649,7 @@ static void rtl_eee_plus_en(struct r8152 *tp, bool enable)
static void rtl_set_eee_plus(struct r8152 *tp)
{
- if (tp->version == RTL_VER_17)
+ if (tp->version == RTL_VER_17_QFN68 || tp->version == RTL_VER_17_QFN100)
return rtl_eee_plus_en(tp, false);
if (rtl8152_get_speed(tp) & _10bps)
@@ -3640,7 +3837,8 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp)
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
640 / 8);
ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,
@@ -3685,7 +3883,8 @@ static void r8153_set_rx_early_size(struct r8152 *tp)
ocp_data / 8);
break;
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,
ocp_data / 16);
break;
@@ -3801,6 +4000,8 @@ static void rtl_rx_vlan_en(struct r8152 *tp, bool enable)
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
if (enable)
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_RCR1,
@@ -4051,8 +4252,27 @@ static void r8156_ups_flags(struct r8152 *tp)
if (tp->ups_info.aldps)
ups_flags |= UPS_FLAGS_EN_ALDPS;
- if (tp->ups_info.eee)
- ups_flags |= UPS_FLAGS_EN_EEE;
+ if (tp->ups_info.eee) {
+ switch (tp->version) {
+ case RTL_VER_17_QFN68:
+ if (tp->eee_adv & MDIO_EEE_10GT)
+ ups_flags |= UPS_FLAGS_EN_10G_EEE;
+ fallthrough;
+ case RTL_VER_16:
+ if (tp->eee_adv & MDIO_EEE_100TX)
+ ups_flags |= UPS_FLAGS_EN_100M_EEE;
+ if (tp->eee_adv & MDIO_EEE_1000T)
+ ups_flags |= UPS_FLAGS_EN_1000M_EEE;
+ if (tp->eee_adv2 & MDIO_EEE_2_5GT)
+ ups_flags |= UPS_FLAGS_EN_2500M_EEE;
+ if (tp->eee_adv2 & MDIO_EEE_5GT)
+ ups_flags |= UPS_FLAGS_EN_5000M_EEE;
+ break;
+ default:
+ ups_flags |= UPS_FLAGS_EN_EEE;
+ break;
+ }
+ }
if (tp->ups_info.flow_control)
ups_flags |= UPS_FLAGS_EN_FLOW_CTR;
@@ -4103,20 +4323,33 @@ static void r8156_ups_flags(struct r8152 *tp)
case NWAY_2500M_FULL:
ups_flags |= ups_flags_speed(9);
break;
+ case NWAY_5000M_FULL:
+ ups_flags |= ups_flags_speed(10);
+ break;
+ case NWAY_10000M_FULL:
+ ups_flags |= ups_flags_speed(11);
+ break;
default:
break;
}
- switch (tp->ups_info.lite_mode) {
- case 1:
- ups_flags |= 0 << 5;
- break;
- case 2:
- ups_flags |= 2 << 5;
+ switch (tp->version) {
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
break;
- case 0:
default:
- ups_flags |= 1 << 5;
+ switch (tp->ups_info.lite_mode) {
+ case 1:
+ ups_flags |= 0 << 5;
+ break;
+ case 2:
+ ups_flags |= 2 << 5;
+ break;
+ case 0:
+ default:
+ ups_flags |= 1 << 5;
+ break;
+ }
break;
}
@@ -4150,11 +4383,13 @@ static void r8153b_green_en(struct r8152 *tp, bool enable)
static u16 r8153_phy_status(struct r8152 *tp, u16 desired)
{
- u16 data;
+ u16 data = 0;
int i;
for (i = 0; i < 500; i++) {
- data = ocp_reg_read(tp, OCP_PHY_STATUS);
+ if (ocp_reg_read(tp, OCP_PHY_STATUS, &data) < 0)
+ break;
+
data &= PHY_STAT_MASK;
if (desired) {
if (data == desired)
@@ -4172,6 +4407,23 @@ static u16 r8153_phy_status(struct r8152 *tp, u16 desired)
return data;
}
+static int wait_autoload_done(struct r8152 *tp)
+{
+ u16 ocp_data;
+ int ret;
+
+ ret = read_poll_timeout(ocp_read_word, ocp_data,
+ test_bit(RTL8152_INACCESSIBLE, &tp->flags) ||
+ (ocp_data & AUTOLOAD_DONE),
+ 20000, 10 * USEC_PER_SEC, false, tp,
+ MCU_TYPE_PLA, PLA_BOOT_CTRL);
+
+ if (ret)
+ dev_err(&tp->intf->dev, "autoload done timeout\n");
+
+ return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : 0;
+}
+
static void r8153b_ups_en(struct r8152 *tp, bool enable)
{
if (enable) {
@@ -4190,16 +4442,8 @@ static void r8153b_ups_en(struct r8152 *tp, bool enable)
UPS_FORCE_PWR_DOWN);
if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
- int i;
-
- for (i = 0; i < 500; i++) {
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
- msleep(20);
- }
+ if (wait_autoload_done(tp))
+ return;
tp->rtl_ops.hw_phy_cfg(tp);
@@ -4227,16 +4471,8 @@ static void r8153c_ups_en(struct r8152 *tp, bool enable)
UPS_FORCE_PWR_DOWN);
if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
- int i;
-
- for (i = 0; i < 500; i++) {
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
- msleep(20);
- }
+ if (wait_autoload_done(tp))
+ return;
tp->rtl_ops.hw_phy_cfg(tp);
@@ -4288,6 +4524,49 @@ static void r8156_ups_en(struct r8152 *tp, bool enable)
}
}
+static void r8157_ups_en(struct r8152 *tp, bool enable)
+{
+ if (enable) {
+ r8156_ups_flags(tp);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,
+ UPS_EN | USP_PREWAKE | PHASE2_EN);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_MISC_2,
+ UPS_FORCE_PWR_DOWN);
+ } else {
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,
+ UPS_EN | USP_PREWAKE);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_MISC_2,
+ UPS_FORCE_PWR_DOWN);
+
+ if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
+ u32 ocp_data;
+ int ret;
+
+ ret = read_poll_timeout(ocp_read_word, ocp_data,
+ ocp_data & BACKUP_RESTRORE, 200,
+ 20000, false, tp, MCU_TYPE_USB,
+ USB_GPHY_CTRL);
+ if (ret) {
+ rtl_set_inaccessible(tp);
+ dev_err(&tp->intf->dev,
+ "backup-restore timed out\n");
+ return;
+ }
+
+ /* clear USB fw_ver_reg */
+ ocp_write_byte(tp, MCU_TYPE_USB, USB_FW_USB_VER, 0);
+
+ tp->rtl_ops.hw_phy_cfg(tp);
+
+ rtl8152_set_speed(tp, tp->autoneg, tp->speed,
+ tp->duplex, tp->advertising);
+ }
+ }
+}
+
static void r8153_power_cut_en(struct r8152 *tp, bool enable)
{
if (enable)
@@ -4446,9 +4725,28 @@ static void rtl8157_runtime_enable(struct r8152 *tp, bool enable)
r8153b_u1u2en(tp, false);
r8157_u2p3en(tp, false);
rtl_runtime_suspend_enable(tp, true);
+
+ switch (tp->version) {
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ r8157_ups_en(tp, true);
+ break;
+ default:
+ break;
+ }
} else {
r8153_queue_wake(tp, false);
rtl_runtime_suspend_enable(tp, false);
+
+ switch (tp->version) {
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ r8157_ups_en(tp, false);
+ break;
+ default:
+ break;
+ }
+
r8157_u2p3en(tp, true);
if (tp->udev->speed >= USB_SPEED_SUPER)
r8153b_u1u2en(tp, true);
@@ -4480,6 +4778,8 @@ static void r8153_teredo_off(struct r8152 *tp)
case RTL_VER_14:
case RTL_VER_15:
case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
/* The bit 0 ~ 7 are relative with teredo settings. They are
* W1C (write 1 to clear), so set all 1 to disable it.
@@ -4534,7 +4834,8 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)
break;
case RTL_VER_14:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
ocp_write_word(tp, type, USB_BP2_EN, 0);
bp_num = 16;
@@ -4556,7 +4857,8 @@ static inline void rtl_reset_ocp_base(struct r8152 *tp)
static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)
{
u16 check;
- int i;
+ u16 ocp_data;
+ int i, ret;
if (request) {
ocp_reg_set_bits(tp, OCP_PHY_PATCH_CMD, PATCH_REQUEST);
@@ -4567,25 +4869,29 @@ static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)
}
for (i = 0; wait && i < 5000; i++) {
- u32 ocp_data;
-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return -ENODEV;
usleep_range(1000, 2000);
- ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT);
- if ((ocp_data & PATCH_READY) ^ check)
+ ret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, &ocp_data);
+ if (ret < 0)
+ return ret;
+ else if ((ocp_data & PATCH_READY) ^ check)
break;
}
- if (request && wait &&
- !(ocp_reg_read(tp, OCP_PHY_PATCH_STAT) & PATCH_READY)) {
- dev_err(&tp->intf->dev, "PHY patch request fail\n");
- rtl_phy_patch_request(tp, false, false);
- return -ETIME;
- } else {
- return 0;
+ if (request && wait) {
+ ret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, &ocp_data);
+ if (ret < 0) {
+ return ret;
+ } else if (!(ocp_data & PATCH_READY)) {
+ dev_err(&tp->intf->dev, "PHY patch request fail\n");
+ rtl_phy_patch_request(tp, false, false);
+ return -ETIME;
+ }
}
+
+ return 0;
}
static void rtl_patch_key_set(struct r8152 *tp, u16 key_addr, u16 patch_key)
@@ -4646,7 +4952,8 @@ static bool rtl8152_is_fw_phy_speed_up_ok(struct r8152 *tp, struct fw_phy_speed_
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
break;
}
@@ -5299,10 +5606,14 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,
{
u32 len;
u8 *data;
+ u16 ver;
rtl_reset_ocp_base(tp);
- if (sram_read(tp, SRAM_GPHY_FW_VER) >= __le16_to_cpu(phy->version)) {
+ if (sram_read(tp, SRAM_GPHY_FW_VER, &ver) < 0)
+ return;
+
+ if (ver >= __le16_to_cpu(phy->version)) {
dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n");
return;
}
@@ -5349,7 +5660,8 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,
rtl_phy_patch_request(tp, false, wait);
- if (sram_read(tp, SRAM_GPHY_FW_VER) == __le16_to_cpu(phy->version))
+ if (sram_read(tp, SRAM_GPHY_FW_VER, &ver) >= 0 &&
+ ver == __le16_to_cpu(phy->version))
dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info);
else
dev_err(&tp->intf->dev, "ram code speedup mode fail\n");
@@ -5357,14 +5669,17 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,
static int rtl8152_fw_phy_ver(struct r8152 *tp, struct fw_phy_ver *phy_ver)
{
- u16 ver_addr, ver;
+ u16 ver_addr, ver, cur_ver;
ver_addr = __le16_to_cpu(phy_ver->ver.addr);
ver = __le16_to_cpu(phy_ver->ver.data);
rtl_reset_ocp_base(tp);
- if (sram_read(tp, ver_addr) >= ver) {
+ if (sram_read(tp, ver_addr, &cur_ver) < 0)
+ return 0;
+
+ if (cur_ver >= ver) {
dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n");
return 0;
}
@@ -5383,7 +5698,8 @@ static void rtl8152_fw_phy_fixup(struct r8152 *tp, struct fw_phy_fixup *fix)
rtl_reset_ocp_base(tp);
addr = __le16_to_cpu(fix->setting.addr);
- data = ocp_reg_read(tp, addr);
+ if (ocp_reg_read(tp, addr, &data) < 0)
+ return;
switch (__le16_to_cpu(fix->bit_cmd)) {
case FW_FIXUP_AND:
@@ -5687,10 +6003,10 @@ static inline void r8152_mmd_indirect(struct r8152 *tp, u16 dev, u16 reg)
static u16 r8152_mmd_read(struct r8152 *tp, u16 dev, u16 reg)
{
- u16 data;
+ u16 data = 0;
r8152_mmd_indirect(tp, dev, reg);
- data = ocp_reg_read(tp, OCP_EEE_DATA);
+ ocp_reg_read(tp, OCP_EEE_DATA, &data);
ocp_reg_write(tp, OCP_EEE_AR, 0x0000);
return data;
@@ -5755,7 +6071,8 @@ static void r8156_eee_en(struct r8152 *tp, bool enable)
r8153_eee_en(tp, enable);
- config = ocp_reg_read(tp, OCP_EEE_ADV2);
+ if (ocp_reg_read(tp, OCP_EEE_ADV2, &config) < 0)
+ return;
if (enable && (tp->eee_adv2 & MDIO_EEE_2_5GT))
config |= MDIO_EEE_2_5GT;
@@ -5806,7 +6123,8 @@ static void rtl_eee_enable(struct r8152 *tp, bool enable)
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
if (enable) {
r8156_eee_en(tp, true);
ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv);
@@ -5961,27 +6279,126 @@ static void r8152b_enter_oob(struct r8152 *tp)
RCR_APM | RCR_AM | RCR_AB);
}
-static int r8153_pre_firmware_1(struct r8152 *tp)
+static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)
{
- int i;
+ int log2_ratio, ratio;
+ u16 num_pause_pkts;
+ u32 ocp_data;
- /* Wait till the WTD timer is ready. It would take at most 104 ms. */
- for (i = 0; i < 104; i++) {
- u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL);
+ switch (tp->version) {
+ case RTL_VER_10:
+ case RTL_VER_11:
+ ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
+ CTRL_TIMER_EN | (1000 / 8));
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return -ENODEV;
- if (!(ocp_data & WTD1_EN))
- break;
- usleep_range(1000, 2000);
- }
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
+ FLOW_CTRL_PATCH_OPT);
- return 0;
-}
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ break;
+ case RTL_VER_12:
+ case RTL_VER_13:
+ case RTL_VER_15:
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
-static int r8153_post_firmware_1(struct r8152 *tp)
-{
- /* set USB_BP_4 to support USB_SPEED_SUPER only */
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);
+
+ /* enable fc timer and set timer to 600 ms. */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
+ CTRL_TIMER_EN | (600 / 8));
+
+ ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL);
+ if (!(ocp_data & DACK_DET_EN))
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
+ FLOW_CTRL_PATCH_2);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ break;
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
+
+ num_pause_pkts = 0xa;
+ ratio = 10000;
+
+ if (speed & _10bps) {
+ ratio /= 10;
+ } else if (speed & _100bps) {
+ ratio /= 100;
+ } else if (speed & _1000bps) {
+ ratio /= 1000;
+ } else if (speed & _2500bps) {
+ ratio /= 2500;
+ } else if (speed & _5000bps) {
+ ratio /= 5000;
+ } else if (speed & _10000bps) {
+ ratio /= 10000;
+ } else {
+ /* No rate bit is set: the link dropped after
+ * the caller checked it, or the PHY reported a
+ * 500 or 1250 Mbit/s sub-rate, which the driver
+ * never advertises. Disarm the limit.
+ */
+ dev_err(&tp->intf->dev, "Unknown link speed\n");
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_EN);
+ break;
+ }
+
+ log2_ratio = ilog2(ratio);
+ num_pause_pkts -= log2_ratio;
+
+ /* Round ratio up to the next power of two if it is
+ * more than halfway there. Floating-point is avoided
+ * by rewriting ratio > 1.5 * 2^log2_ratio as
+ * 2 * ratio > 3 * 2^log2_ratio.
+ */
+ if (2 * ratio > 3 * (1 << log2_ratio))
+ num_pause_pkts--;
+
+ /* At most 2^num_pause_pkts pause packets would be sent.
+ *
+ * 10 Mbit/s -> 2^0
+ * 100 Mbit/s -> 2^3
+ * 1 Gbit/s -> 2^7
+ * 2.5 Gbit/s -> 2^8
+ * 5 Gbit/s -> 2^9
+ * 10 Gbit/s -> 2^10
+ */
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_MASK | PAUSE_LIMIT_EN,
+ num_pause_pkts << 4);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_EN);
+ break;
+ default:
+ break;
+ }
+}
+
+static int r8153_pre_firmware_1(struct r8152 *tp)
+{
+ int i;
+
+ /* Wait till the WTD timer is ready. It would take at most 104 ms. */
+ for (i = 0; i < 104; i++) {
+ u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL);
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return -ENODEV;
+ if (!(ocp_data & WTD1_EN))
+ break;
+ usleep_range(1000, 2000);
+ }
+
+ return 0;
+}
+
+static int r8153_post_firmware_1(struct r8152 *tp)
+{
+ /* set USB_BP_4 to support USB_SPEED_SUPER only */
if (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) & FORCE_SUPER)
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_4, BP4_SUPER_ONLY);
@@ -6210,8 +6627,8 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
* rg_saw_cnt = OCP reg 0xC426 Bit[13:0]
* swr_cnt_1ms_ini = 16000000 / rg_saw_cnt
*/
- ocp_data = ocp_reg_read(tp, 0xc426);
- ocp_data &= 0x3fff;
+ ocp_reg_read(tp, 0xc426, &data);
+ ocp_data = data & 0x3fff;
if (ocp_data) {
u32 swr_cnt_1ms_ini;
@@ -6391,24 +6808,16 @@ static int rtl8156_enable(struct r8152 *tp)
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return -ENODEV;
- if (tp->version < RTL_VER_12)
- r8156_fc_parameter(tp);
-
+ r8156_fc_parameter(tp);
set_tx_qlen(tp);
rtl_set_eee_plus(tp);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_17)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
-
r8153_set_rx_early_timeout(tp);
r8153_set_rx_early_size(tp);
speed = rtl8152_get_speed(tp);
rtl_set_ifg(tp, speed);
- if (tp->version >= RTL_VER_16)
- return rtl_enable(tp);
-
if (speed & _2500bps)
ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
IDLE_SPDWN_EN);
@@ -6416,12 +6825,10 @@ static int rtl8156_enable(struct r8152 *tp)
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
IDLE_SPDWN_EN);
- if (tp->version < RTL_VER_12) {
- if (speed & _1000bps)
- ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11);
- else if (speed & _500bps)
- ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d);
- }
+ if (speed & _1000bps)
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11);
+ else if (speed & _500bps)
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d);
if (tp->udev->speed == USB_SPEED_HIGH) {
/* USB 0xb45e[3:0] l1_nyet_hird */
@@ -6446,6 +6853,69 @@ static void rtl8156_disable(struct r8152 *tp)
rtl8153_disable(tp);
}
+static int rtl8156b_enable(struct r8152 *tp)
+{
+ u16 speed;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return -ENODEV;
+
+ set_tx_qlen(tp);
+ rtl_set_eee_plus(tp);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
+
+ r8153_set_rx_early_timeout(tp);
+ r8153_set_rx_early_size(tp);
+
+ speed = rtl8152_get_speed(tp);
+ rtl_set_ifg(tp, speed);
+
+ if (speed & _2500bps)
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
+ IDLE_SPDWN_EN);
+ else
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
+ IDLE_SPDWN_EN);
+
+ if (tp->udev->speed == USB_SPEED_HIGH) {
+ /* USB 0xb45e[3:0] l1_nyet_hird */
+ if (is_flow_control(speed))
+ ocp_word_w0w1(tp, MCU_TYPE_USB, USB_L1_CTRL, 0xf, 0xf);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_USB, USB_L1_CTRL, 0xf, 0x1);
+ }
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ usleep_range(1000, 2000);
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+
+ return rtl_enable(tp);
+}
+
+static int rtl8157_enable(struct r8152 *tp)
+{
+ u16 speed;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return -ENODEV;
+
+ set_tx_qlen(tp);
+ rtl_set_eee_plus(tp);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
+
+ r8153_set_rx_early_timeout(tp);
+ r8153_set_rx_early_size(tp);
+
+ speed = rtl8152_get_speed(tp);
+ rtl_fc_pause_pkt_en(tp, speed);
+
+ rtl_set_ifg(tp, speed);
+
+ return rtl_enable(tp);
+}
+
static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
u32 advertising)
{
@@ -6517,7 +6987,11 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
if (!advertising)
return -EINVAL;
- orig = r8152_mdio_read(tp, MII_ADVERTISE);
+ ret = r8152_mdio_read(tp, MII_ADVERTISE);
+ if (ret < 0)
+ goto out;
+
+ orig = ret;
new1 = orig & ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
ADVERTISE_100HALF | ADVERTISE_100FULL);
if (advertising & RTL_ADVERTISED_10_HALF) {
@@ -6544,7 +7018,11 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
}
if (tp->mii.supports_gmii) {
- orig = r8152_mdio_read(tp, MII_CTRL1000);
+ ret = r8152_mdio_read(tp, MII_CTRL1000);
+ if (ret < 0)
+ goto out;
+
+ orig = ret;
new1 = orig & ~(ADVERTISE_1000FULL |
ADVERTISE_1000HALF);
@@ -6558,7 +7036,10 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
}
if (tp->support_2500full || tp->support_5000full || tp->support_10000full) {
- orig = ocp_reg_read(tp, OCP_10GBT_CTRL);
+ ret = ocp_reg_read(tp, OCP_10GBT_CTRL, &orig);
+ if (ret < 0)
+ goto out;
+
new1 = orig & ~(MDIO_AN_10GBT_CTRL_ADV2_5G | MDIO_AN_10GBT_CTRL_ADV5G
| MDIO_AN_10GBT_CTRL_ADV10G);
@@ -6589,20 +7070,23 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
if (test_and_clear_bit(PHY_RESET, &tp->flags))
bmcr |= BMCR_RESET;
- r8152_mdio_write(tp, MII_BMCR, bmcr);
+ ret = r8152_mdio_write(tp, MII_BMCR, bmcr);
+ if (ret < 0)
+ goto out;
if (bmcr & BMCR_RESET) {
int i;
for (i = 0; i < 50; i++) {
msleep(20);
- if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0)
+ ret = r8152_mdio_read(tp, MII_BMCR);
+ if (ret < 0 || !(ret & BMCR_RESET))
break;
}
}
out:
- return ret;
+ return ret < 0 ? ret : 0;
}
static void rtl8152_up(struct r8152 *tp)
@@ -6806,8 +7290,7 @@ static void rtl8156_up(struct r8152 *tp)
return;
r8153b_u1u2en(tp, false);
- if (tp->version < RTL_VER_16)
- r8153_u2p3en(tp, false);
+ r8153_u2p3en(tp, false);
r8153_aldps_en(tp, false);
rxdy_gated_en(tp, true);
@@ -6820,8 +7303,7 @@ static void rtl8156_up(struct r8152 *tp)
ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
- if (tp->version >= RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));
ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
@@ -6843,11 +7325,11 @@ static void rtl8156_up(struct r8152 *tp)
ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, RXFIFO_FULL_MASK,
0x08);
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, PLA_MCU_SPDWN_EN);
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
+ PLA_MCU_SPDWN_EN);
- if (tp->version < RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,
- RG_PWRDN_EN | ALL_SPEED_OFF);
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,
+ RG_PWRDN_EN | ALL_SPEED_OFF);
ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400);
@@ -6857,10 +7339,19 @@ static void rtl8156_up(struct r8152 *tp)
}
r8153_aldps_en(tp, true);
- if (tp->version < RTL_VER_16)
- r8153_u2p3en(tp, true);
+ r8153_u2p3en(tp, true);
+
+ switch (tp->version) {
+ case RTL_VER_13:
+ case RTL_VER_15:
+ /* Enable Clear_SDR */
+ ocp_word_set_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(15));
+ break;
+ default:
+ break;
+ }
- if (tp->version < RTL_VER_16 && tp->udev->speed >= USB_SPEED_SUPER)
+ if (tp->udev->speed >= USB_SPEED_SUPER)
r8153b_u1u2en(tp, true);
}
@@ -6873,12 +7364,9 @@ static void rtl8156_down(struct r8152 *tp)
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
PLA_MCU_SPDWN_EN);
-
r8153b_u1u2en(tp, false);
- if (tp->version < RTL_VER_16) {
- r8153_u2p3en(tp, false);
- r8153b_power_cut_en(tp, false);
- }
+ r8153_u2p3en(tp, false);
+ r8153b_power_cut_en(tp, false);
r8153_aldps_en(tp, false);
ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
@@ -6900,7 +7388,125 @@ static void rtl8156_down(struct r8152 *tp)
*/
ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff);
- ocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_BDC_CR, ALDPS_PROXY_MODE);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL,
+ NOW_IS_OOB | DIS_MCU_CLROOB);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
+
+ rtl_rx_vlan_en(tp, true);
+ rxdy_gated_en(tp, false);
+
+ ocp_dword_set_bits(tp, MCU_TYPE_PLA, PLA_RCR,
+ RCR_APM | RCR_AM | RCR_AB);
+
+ r8153_aldps_en(tp, true);
+}
+
+static void rtl8157_change_mtu(struct r8152 *tp)
+{
+ u32 max_pkt_size = mtu_to_size(tp->netdev->mtu);
+ u32 ocp_data;
+
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, max_pkt_size);
+
+ /* Use at least 10K for MTPS */
+ ocp_data = max_t(u32, max_pkt_size, 10 * 1024) / 64;
+
+ /* 16 * 1024 / 64 = 0x100, so the max is 0xff for 8 bits data */
+ ocp_data = min_t(u32, ocp_data, 0xff);
+
+ ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, ocp_data);
+ r8156_fc_parameter(tp);
+
+ /* TX share fifo free credit full threshold */
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64);
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL,
+ ALIGN(max_pkt_size + tp->tx_desc.size, 1024) / 16);
+}
+
+static void rtl8157_up(struct r8152 *tp)
+{
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ r8153b_u1u2en(tp, false);
+ r8153_aldps_en(tp, false);
+
+ rxdy_gated_en(tp, true);
+ r8153_teredo_off(tp);
+
+ ocp_dword_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, RCR_ACPT_ALL);
+
+ rtl8152_nic_reset(tp);
+ rtl_reset_bmu(tp);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
+
+ rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX);
+
+ rtl8157_change_mtu(tp);
+
+ /* share FIFO settings */
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, RXFIFO_FULL_MASK,
+ 0x08);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,
+ RG_PWRDN_EN | ALL_SPEED_OFF);
+
+ ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400);
+
+ if (tp->saved_wolopts != __rtl_get_wol(tp)) {
+ netif_warn(tp, ifup, tp->netdev, "wol setting is changed\n");
+ __rtl_set_wol(tp, tp->saved_wolopts);
+ }
+
+ r8153_aldps_en(tp, true);
+
+ /* Enable Clear_SDR */
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xd378, BIT(7));
+ /* Clear SDR bit */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(15));
+}
+
+static void rtl8157_down(struct r8152 *tp)
+{
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) {
+ rtl_drop_queued_tx(tp);
+ return;
+ }
+
+ r8153b_u1u2en(tp, false);
+ r8153_aldps_en(tp, false);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
+
+ /* RX FIFO settings for OOB */
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 64 / 16);
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 1024 / 16);
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 4096 / 16);
+
+ rtl_disable(tp);
+ rtl_reset_bmu(tp);
+
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1526);
+ ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, 10 * 1024 / 64);
+
+ /* Clear teredo wake event. bit[15:8] is the teredo wakeup
+ * type. Set it to zero. bits[7:0] are the W1C bits about
+ * the events. Set them to all 1 to clear them.
+ */
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_BDC_CR, ALDPS_PROXY_MODE);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL,
+ NOW_IS_OOB | DIS_MCU_CLROOB);
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
@@ -6931,7 +7537,12 @@ static bool rtl8152_in_nway(struct r8152 *tp)
static bool rtl8153_in_nway(struct r8152 *tp)
{
- u16 phy_state = ocp_reg_read(tp, OCP_PHY_STATE) & 0xff;
+ u16 phy_state;
+
+ if (ocp_reg_read(tp, OCP_PHY_STATE, &phy_state) < 0)
+ return false;
+
+ phy_state &= 0xff;
if (phy_state == TXDIS_STATE || phy_state == ABD_STATE)
return false;
@@ -6947,7 +7558,9 @@ static void r8156_mdio_force_mode(struct r8152 *tp)
* 0: MDIO force mode
* 1: MMD force mode
*/
- data = ocp_reg_read(tp, 0xa5b4);
+ if (ocp_reg_read(tp, 0xa5b4, &data) < 0)
+ return;
+
if (data & BIT(15)) {
data &= ~BIT(15);
ocp_reg_write(tp, 0xa5b4, data);
@@ -7225,22 +7838,14 @@ static void r8152b_init(struct r8152 *tp)
static void r8153_init(struct r8152 *tp)
{
u32 ocp_data;
- int i;
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
r8153_u1u2en(tp, false);
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
-
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- break;
- }
+ if (wait_autoload_done(tp))
+ return;
r8153_phy_status(tp, 0);
@@ -7341,22 +7946,13 @@ static void r8153_init(struct r8152 *tp)
static void r8153b_init(struct r8152 *tp)
{
- int i;
-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
r8153b_u1u2en(tp, false);
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
-
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- break;
- }
+ if (wait_autoload_done(tp))
+ return;
r8153_phy_status(tp, 0);
@@ -7411,8 +8007,6 @@ static void r8153b_init(struct r8152 *tp)
static void r8153c_init(struct r8152 *tp)
{
- int i;
-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
@@ -7425,15 +8019,8 @@ static void r8153c_init(struct r8152 *tp)
ocp_word_set_bits(tp, MCU_TYPE_USB, 0xcbf0, BIT(1));
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
-
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- }
+ if (wait_autoload_done(tp))
+ return;
r8153_phy_status(tp, 0);
@@ -7505,7 +8092,8 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
rtl_eee_enable(tp, false);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- WARN_ON_ONCE(data != PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
@@ -7612,19 +8200,20 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
ocp_reg_clr_bits(tp, 0xa86a, BIT(0));
/* MDI SWAP */
+ ocp_reg_read(tp, 0xd068, &data);
if ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) & MID_REVERSE) &&
- (ocp_reg_read(tp, 0xd068) & BIT(1))) {
+ (data & BIT(1))) {
u16 swap_a, swap_b;
- data = ocp_reg_read(tp, 0xd068);
+ ocp_reg_read(tp, 0xd068, &data);
data &= ~0x1f;
data |= 0x1; /* p0 */
ocp_reg_write(tp, 0xd068, data);
- swap_a = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_a);
data &= ~0x18;
data |= 0x18; /* p3 */
ocp_reg_write(tp, 0xd068, data);
- swap_b = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_b);
data &= ~0x18; /* p0 */
ocp_reg_write(tp, 0xd068, data);
ocp_reg_write(tp, 0xd06a,
@@ -7636,11 +8225,11 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
data &= ~0x18;
data |= 0x08; /* p1 */
ocp_reg_write(tp, 0xd068, data);
- swap_a = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_a);
data &= ~0x18;
data |= 0x10; /* p2 */
ocp_reg_write(tp, 0xd068, data);
- swap_b = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_b);
data &= ~0x18;
data |= 0x08; /* p1 */
ocp_reg_write(tp, 0xd068, data);
@@ -7651,16 +8240,16 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
ocp_reg_write(tp, 0xd068, data);
ocp_reg_write(tp, 0xd06a,
(swap_b & ~0x7ff) | (swap_a & 0x7ff));
- swap_a = ocp_reg_read(tp, 0xbd5a);
- swap_b = ocp_reg_read(tp, 0xbd5c);
+ ocp_reg_read(tp, 0xbd5a, &swap_a);
+ ocp_reg_read(tp, 0xbd5c, &swap_b);
ocp_reg_write(tp, 0xbd5a, (swap_a & ~0x1f1f) |
((swap_b & 0x1f) << 8) |
((swap_b >> 8) & 0x1f));
ocp_reg_write(tp, 0xbd5c, (swap_b & ~0x1f1f) |
((swap_a & 0x1f) << 8) |
((swap_a >> 8) & 0x1f));
- swap_a = ocp_reg_read(tp, 0xbc18);
- swap_b = ocp_reg_read(tp, 0xbc1a);
+ ocp_reg_read(tp, 0xbc18, &swap_a);
+ ocp_reg_read(tp, 0xbc1a, &swap_b);
ocp_reg_write(tp, 0xbc18, (swap_a & ~0x1f1f) |
((swap_b & 0x1f) << 8) |
((swap_b >> 8) & 0x1f));
@@ -7740,7 +8329,8 @@ static void r8156b_hw_phy_cfg(struct r8152 *tp)
rtl_eee_enable(tp, false);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- WARN_ON_ONCE(data != PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
@@ -7979,17 +8569,21 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
rtl_eee_enable(tp, false);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- WARN_ON_ONCE(data != PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
/* PFM mode */
ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
/* Advanced Power Saving parameter */
- ocp_reg_set_bits(tp, 0xa430, BIT(0) | BIT(1));
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);
/* Disable ALDPS force mode */
ocp_reg_clr_bits(tp, 0xa44a, BIT(2));
+ /* Disable bypass_turn_off_clk_in_aldps */
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
+
switch (tp->version) {
case RTL_VER_16:
/* XG_INRX parameter */
@@ -8005,7 +8599,7 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x8078, 0xff00, 0x3000);
/* green mode */
- sram2_write_w0w1(tp, 0x89e9, 0xff00, 0);
+ sram2_clr_bits(tp, 0x89e9, 0xff00);
sram2_write_w0w1(tp, 0x8ffd, 0xff00, 0x0100);
sram2_write_w0w1(tp, 0x8ffe, 0xff00, 0x0200);
sram2_write_w0w1(tp, 0x8fff, 0xff00, 0x0400);
@@ -8111,11 +8705,86 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x807c, 0xff00, 0x5000);
sram2_write_w0w1(tp, 0x809d, 0xff00, 0x5000);
break;
+ default:
+ break;
+ }
+
+ if (rtl_phy_patch_request(tp, true, true))
+ return;
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);
+
+ ocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);
+
+ tp->ups_info._10m_ckdiv = true;
+ tp->ups_info.eee_plloff_100 = false;
+ tp->ups_info.eee_plloff_giga = false;
+
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);
+ tp->ups_info.eee_ckdiv = true;
+
+ rtl_phy_patch_request(tp, false, true);
+
+ rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags));
+
+ ocp_reg_clr_bits(tp, 0xa428, BIT(9));
+ ocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1));
+ tp->ups_info.lite_mode = 0;
+
+ if (tp->eee_en)
+ rtl_eee_enable(tp, true);
+
+ r8153_aldps_en(tp, true);
+ r8152b_enable_fc(tp);
+
+ set_bit(PHY_RESET, &tp->flags);
+}
+
+static void r8159_hw_phy_cfg(struct r8152 *tp)
+{
+ u16 data;
+
+ r8156b_wait_loading_flash(tp);
+
+ ocp_word_test_and_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);
+
+ data = r8153_phy_status(tp, 0);
+ switch (data) {
+ case PHY_STAT_EXT_INIT:
+ rtl8152_apply_firmware(tp, true);
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+ break;
+ case PHY_STAT_LAN_ON:
+ case PHY_STAT_PWRDN:
+ default:
+ rtl8152_apply_firmware(tp, false);
+ break;
+ }
+
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
- case RTL_VER_17:
- /* Disable bypass turn off clk in ALDPS */
- ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
+ r8153_aldps_en(tp, false);
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
+
+ /* PFM mode */
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
+
+ /* Advanced Power Saving parameter */
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);
+
+ /* Disable ALDPS force mode */
+ ocp_reg_clr_bits(tp, 0xa44a, BIT(2));
+
+ /* Disable bypass_turn_off_clk_in_aldps */
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
+
+ switch (tp->version) {
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
/* Power level tuning
* test mode power level
*/
@@ -8125,22 +8794,35 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram_write_w0w1(tp, 0x81ae, 0xff00, 0x0f00);
sram_write_w0w1(tp, 0x81b9, 0xff00, 0xb900);
/* normal link TX filter */
- sram2_write_w0w1(tp, 0x83b0, 0x0e00, 0);
- sram2_write_w0w1(tp, 0x83c5, 0x0e00, 0);
- sram2_write_w0w1(tp, 0x83da, 0x0e00, 0);
- sram2_write_w0w1(tp, 0x83ef, 0x0e00, 0);
+ sram2_clr_bits(tp, 0x83b0, 0x0e00);
+ sram2_clr_bits(tp, 0x83c5, 0x0e00);
+ sram2_clr_bits(tp, 0x83da, 0x0e00);
+ sram2_clr_bits(tp, 0x83ef, 0x0e00);
+
+ ocp_reg_w0w1(tp, 0xbf38, 0x01f0, 0x0160);
+ ocp_reg_w0w1(tp, 0xbf3a, 0x001f, 0x0014);
+ /* shorten CLKS latency */
+ ocp_reg_clr_bits(tp, 0xbf28, BIT(14) | BIT(13));
+ ocp_reg_clr_bits(tp, 0xbf2c, BIT(15) | BIT(14));
+ /* CMP_Timer on MP_Timer=333
+ * GPHY OCP 0xbf28 bit[0] = 0x1
+ * GPHY OCP 0xbf28 bit[6:1] = 0x3
+ * GPHY OCP 0xbf28 bit[12:7] = 0x3
+ */
+ ocp_reg_w0w1(tp, 0xbf28, 0x1fff, 0x0187);
+ ocp_reg_w0w1(tp, 0xbf2a, 0x3f, 0x03);
/* AFE power saving for 2.5G & 5G */
sram_write(tp, 0x8173, 0x8620);
sram_write(tp, 0x8175, 0x8671);
- sram_write_w0w1(tp, 0x817c, 0, BIT(13));
- sram_write_w0w1(tp, 0x8187, 0, BIT(13));
- sram_write_w0w1(tp, 0x8192, 0, BIT(13));
- sram_write_w0w1(tp, 0x819d, 0, BIT(13));
- sram_write_w0w1(tp, 0x81a8, BIT(13), 0);
- sram_write_w0w1(tp, 0x81b3, BIT(13), 0);
- sram_write_w0w1(tp, 0x81be, 0, BIT(13));
+ sram_set_bits(tp, 0x817c, BIT(13));
+ sram_set_bits(tp, 0x8187, BIT(13));
+ sram_set_bits(tp, 0x8192, BIT(13));
+ sram_set_bits(tp, 0x819d, BIT(13));
+ sram_clr_bits(tp, 0x81a8, BIT(13));
+ sram_clr_bits(tp, 0x81b3, BIT(13));
+ sram_set_bits(tp, 0x81be, BIT(13));
sram_write_w0w1(tp, 0x817d, 0xff00, 0xa600);
sram_write_w0w1(tp, 0x8188, 0xff00, 0xa600);
@@ -8204,10 +8886,10 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x84b2, 0xff00, 0x6000);
/* Training AAGC PAR (with uc2 patch) */
sram2_write(tp, 0x8ffc, 0x6008);
- sram2_write(tp, 0x8ffe, 0xf450);
+ sram2_write(tp, 0x8ffe, 0xf4ff);
/* DAC BGK */
- sram2_write_w0w1(tp, 0x8015, 0, BIT(9));
- sram2_write_w0w1(tp, 0x8016, 0, BIT(11));
+ sram2_set_bits(tp, 0x8015, BIT(9));
+ sram2_set_bits(tp, 0x8016, BIT(11));
sram2_write_w0w1(tp, 0x8fe6, 0xff00, 0x0800);
sram2_write(tp, 0x8fe4, 0x2114);
/* 10G PBO table */
@@ -8216,14 +8898,14 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x864b, 0xff00, 0xdc00);
/* 2.5G ado power window size */
sram2_write_w0w1(tp, 0x8154, 0xc000, 0x4000);
- sram2_write_w0w1(tp, 0x8158, 0xc000, 0);
+ sram2_clr_bits(tp, 0x8158, 0xc000);
/* 10G lock far */
sram2_write(tp, 0x826c, 0xffff);
sram2_write(tp, 0x826e, 0xffff);
/* XG INRX parameter */
sram2_write_w0w1(tp, 0x8872, 0xff00, 0x0e00);
- sram_write_w0w1(tp, 0x8012, 0, BIT(11));
- sram_write_w0w1(tp, 0x8012, 0, BIT(14));
+ sram_set_bits(tp, 0x8012, BIT(11));
+ sram_set_bits(tp, 0x8012, BIT(14));
ocp_reg_set_bits(tp, 0xb576, BIT(0));
sram_write_w0w1(tp, 0x834a, 0xff00, 0x0700);
sram2_write_w0w1(tp, 0x8217, 0x3f00, 0x2a00);
@@ -8234,100 +8916,373 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
/* improve UBE */
ocp_reg_set_bits(tp, 0xbf0c, 0x7 << 11);
/* close Sparse NEC, improve connect 5EUU cable performance */
- sram2_write_w0w1(tp, 0x88de, 0xff00, 0);
+ sram2_clr_bits(tp, 0x88de, 0xff00);
/* 5G slave compatibility issue */
sram2_write(tp, 0x80b4, 0x5195);
- /* XG Test Mode
- * xgtstm_map_tbl for mdi_cap_sel
- */
- sram_write(tp, 0x8370, 0x8671);
- sram_write(tp, 0x8372, 0x86c8);
- /* xgtstm_amp_map_tbl for REG_IBX_UP_SHIFT_L */
- sram_write(tp, 0x8401, 0x86c8);
- sram_write(tp, 0x8403, 0x86da);
- sram_write_w0w1(tp, 0x8406, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8408, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x840a, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x840c, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x840e, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8410, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8412, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8414, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8416, 0x1800, 0x1000);
+ /* XG Test Mode
+ * xgtstm_map_tbl for mdi_cap_sel
+ */
+ sram_write(tp, 0x8370, 0x8671);
+ sram_write(tp, 0x8372, 0x86c8);
+ /* xgtstm_amp_map_tbl for REG_IBX_UP_SHIFT_L */
+ sram_write(tp, 0x8401, 0x86c8);
+ sram_write(tp, 0x8403, 0x86da);
+ sram_write_w0w1(tp, 0x8406, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8408, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x840a, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x840c, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x840e, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8410, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8412, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8414, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8416, 0x1800, 0x1000);
+
+ /* Cable Test Patch */
+ sram_write(tp, 0x82bd, 0x1f40);
+
+ /* Thermal sensor parameters */
+ ocp_reg_w0w1(tp, 0xbfb4, 0x07ff, 0x0328);
+ ocp_reg_write(tp, 0xbfb6, 0x3e14);
+
+ /* spdchg_gtx_shape_100M */
+ ocp_reg_write(tp, OCP_SRAM_ADDR, 0x81c4);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x003b);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0086);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00b7);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00db);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00c3);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0078);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0047);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0023);
+
+ /* lsbmsk_parameters
+ * RL6961_lsbmsk_parameter_250207
+ */
+ sram2_write(tp, 0x88d7, 0x01a0);
+ sram2_write(tp, 0x88d9, 0x01a0);
+ sram2_write(tp, 0x8ffa, 0x002a);
+
+ sram2_write(tp, 0x8fee, 0xffdf);
+ sram2_write(tp, 0x8ff0, 0xffff);
+ sram2_write(tp, 0x8ff2, 0x0a4a);
+ sram2_write(tp, 0x8ff4, 0xaa5a);
+ sram2_write(tp, 0x8ff6, 0x0a4a);
+ sram2_write(tp, 0x8ff8, 0xaa5a);
+
+ sram2_write_w0w1(tp, 0x88d5, 0xff00, 0x0200);
+
+ /* spdchg_pga1_lpf_cap */
+ sram_write_w0w1(tp, 0x84bb, 0xff00, 0x0a00);
+ sram_write_w0w1(tp, 0x84c0, 0xff00, 0x1600);
+
+ /* ENET PLL jitter improvement */
+ ocp_reg_w0w1(tp, 0xbf8a, 0xfc00, 0x2000);
+ ocp_reg_set_bits(tp, 0xbf88, BIT(2));
+ break;
+ default:
+ break;
+ }
+
+ if (rtl_phy_patch_request(tp, true, true))
+ return;
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);
+
+ ocp_reg_clr_bits(tp, OCP_DOWN_SPEED,
+ EN_EEE_100 | EN_EEE_1000 | EN_10M_CLKDIV);
+ tp->ups_info._10m_ckdiv = false;
+ tp->ups_info.eee_plloff_100 = false;
+ tp->ups_info.eee_plloff_giga = false;
+
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);
+ tp->ups_info.eee_ckdiv = true;
+
+ rtl_phy_patch_request(tp, false, true);
+
+ rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags));
+
+ ocp_reg_clr_bits(tp, 0xa428, BIT(9));
+ ocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1) | BIT(2));
+ tp->ups_info.lite_mode = 0;
+
+ if (tp->eee_en)
+ rtl_eee_enable(tp, true);
+
+ r8153_aldps_en(tp, true);
+ r8152b_enable_fc(tp);
+
+ set_bit(PHY_RESET, &tp->flags);
+}
+
+static void r8156_init(struct r8152 *tp)
+{
+ u16 data;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
+
+ ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
+
+ r8153b_u1u2en(tp, false);
+
+ if (wait_autoload_done(tp))
+ return;
+
+ data = r8153_phy_status(tp, 0);
+ if (data == PHY_STAT_EXT_INIT)
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
+
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
+
+ r8153_u2p3en(tp, false);
+
+ /* MSC timer = 0xfff * 8ms = 32760 ms */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
+
+ /* U1/U2/L1 idle timer. 500 us */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
+
+ r8153b_power_cut_en(tp, false);
+ r8156_ups_en(tp, false);
+ r8153_queue_wake(tp, false);
+ rtl_runtime_suspend_enable(tp, false);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
+
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
+
+ usb_enable_lpm(tp->udev);
+
+ rtl_fc_pause_pkt_en(tp, 0);
+
+ r8156_mac_clk_spd(tp, true);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
+ PLA_MCU_SPDWN_EN);
+
+ if (rtl8152_get_speed(tp) & LINK_STATUS)
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, CUR_LINK_OK,
+ POLL_LINK_CHG);
+
+ set_bit(GREEN_ETHERNET, &tp->flags);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_ZERO_EN);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ACT_ODMA);
+
+ r8156_mdio_force_mode(tp);
+ rtl_tally_reset(tp);
+
+ tp->coalesce = 15000; /* 15 us */
+}
+
+static void r8156b_u2phy_backup(struct r8152 *tp)
+{
+ ocp_write_word(tp, MCU_TYPE_USB, 0xd3ce, 0x181b);
+ ocp_write_dword(tp, MCU_TYPE_USB, 0xd3d0, 0x616ccd99);
+ ocp_write_dword(tp, MCU_TYPE_USB, 0xd3d4, 0x08fc8101);
+ ocp_write_dword(tp, MCU_TYPE_USB, 0xd3d8, 0x159b1100);
+ ocp_write_word(tp, MCU_TYPE_USB, 0xd3dc, 0x0a00);
+}
+
+static void r8156b_init(struct r8152 *tp)
+{
+ u16 data;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
+
+ ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_U2P3_CTRL, RX_DETECT8);
+
+ r8153b_u1u2en(tp, false);
+
+ switch (tp->version) {
+ case RTL_VER_13:
+ case RTL_VER_15:
+ r8156b_wait_loading_flash(tp);
+ break;
+ default:
+ break;
+ }
+
+ if (wait_autoload_done(tp))
+ return;
+
+ data = r8153_phy_status(tp, 0);
+ if (data == PHY_STAT_EXT_INIT) {
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ }
+
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
+
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
+
+ r8153_u2p3en(tp, false);
+
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
+
+ /* MSC timer = 0xfff * 8ms = 32760 ms */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
+
+ /* U1/U2/L1 idle timer. 500 us */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
+
+ r8156b_u2phy_backup(tp);
+
+ r8153b_power_cut_en(tp, false);
+ r8156_ups_en(tp, false);
+ r8153_queue_wake(tp, false);
+ rtl_runtime_suspend_enable(tp, false);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
+
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
+
+ usb_enable_lpm(tp->udev);
+
+ rtl_fc_pause_pkt_en(tp, 0);
+
+ r8156_mac_clk_spd(tp, true);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
+ PLA_MCU_SPDWN_EN);
+
+ if (rtl8152_get_speed(tp) & LINK_STATUS)
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK, POLL_LINK_CHG);
+
+ set_bit(GREEN_ETHERNET, &tp->flags);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_ZERO_EN);
+
+ r8156_mdio_force_mode(tp);
+ rtl_tally_reset(tp);
+
+ tp->coalesce = 15000; /* 15 us */
+}
- /* Cable Test Patch */
- sram_write(tp, 0x82bd, 0x1f40);
+static void r8157_init(struct r8152 *tp)
+{
+ u16 data;
- /* Thermal sensor parameters */
- ocp_reg_w0w1(tp, 0xbfb4, 0x07ff, 0x0328);
- ocp_reg_write(tp, 0xbfb6, 0x3e14);
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
- /* spdchg_gtx_shape_100M */
- ocp_reg_write(tp, OCP_SRAM_ADDR, 0x81c4);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x003b);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0086);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00b7);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00db);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00c3);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0078);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0047);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0023);
+ /* Enable SW reset */
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));
- /* lsbmsk_parameters
- * RL6961_lsbmsk_parameter_250207
- */
- sram2_write(tp, 0x88d7, 0x01a0);
- sram2_write(tp, 0x88d9, 0x01a0);
- sram2_write(tp, 0x8ffa, 0x002a);
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
- sram2_write(tp, 0x8fee, 0xffdf);
- sram2_write(tp, 0x8ff0, 0xffff);
- sram2_write(tp, 0x8ff2, 0x0a4a);
- sram2_write(tp, 0x8ff4, 0xaa5a);
- sram2_write(tp, 0x8ff6, 0x0a4a);
- sram2_write(tp, 0x8ff8, 0xaa5a);
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
- sram2_write_w0w1(tp, 0x88d5, 0xff00, 0x0200);
- break;
+ r8153b_u1u2en(tp, false);
- default:
- break;
- }
+ r8156b_wait_loading_flash(tp);
- if (rtl_phy_patch_request(tp, true, true))
+ if (wait_autoload_done(tp))
return;
- ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);
+ data = r8153_phy_status(tp, 0);
+ if (data == PHY_STAT_EXT_INIT) {
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ }
- ocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
- tp->ups_info._10m_ckdiv = true;
- tp->ups_info.eee_plloff_100 = false;
- tp->ups_info.eee_plloff_giga = false;
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- ocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);
- tp->ups_info.eee_ckdiv = true;
+ r8157_u2p3en(tp, false);
- rtl_phy_patch_request(tp, false, true);
+ /* Disable Interrupt Mitigation */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,
+ BIT(0) | BIT(1) | BIT(2) | BIT(7));
- rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags));
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
- ocp_reg_clr_bits(tp, 0xa428, BIT(9));
- ocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1));
- tp->ups_info.lite_mode = 0;
+ /* MSC timer = 0xfff * 8ms = 32760 ms */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
- if (tp->eee_en)
- rtl_eee_enable(tp, true);
+ /* U1/U2/L1 idle timer. 500 us */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
- r8153_aldps_en(tp, true);
- r8152b_enable_fc(tp);
+ r8157_power_cut_en(tp, false);
+ r8157_ups_en(tp, false);
+ r8153_queue_wake(tp, false);
+ rtl_runtime_suspend_enable(tp, false);
- set_bit(PHY_RESET, &tp->flags);
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
+
+ /* Clear Warm RST / Bus RST event flag */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));
+
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
+
+ usb_enable_lpm(tp->udev);
+
+ r8156_mac_clk_spd(tp, true);
+
+ if (rtl8152_get_speed(tp) & LINK_STATUS)
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK, POLL_LINK_CHG);
+
+ set_bit(GREEN_ETHERNET, &tp->flags);
+
+ /* RX aggregation / 16 bytes RX descriptor / Bulk In End transfer */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_DESC_16B | RX_END_TRANSFER_EN);
+
+ /* Disable Rx Zero Len */
+ rtl_bmu_clr_bits(tp, 0x2300, BIT(3));
+
+ /* TX descriptor Signature */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
+
+ r8156_mdio_force_mode(tp);
+ rtl_tally_reset(tp);
+
+ tp->coalesce = 15000; /* 15 us */
}
static int r8159_wait_backup_restore(struct r8152 *tp)
@@ -8342,78 +9297,53 @@ static int r8159_wait_backup_restore(struct r8152 *tp)
ocp_data & BACKUP_RESTRORE, 200, 20000, false);
}
-static void r8156_init(struct r8152 *tp)
+static void r8159_init(struct r8152 *tp)
{
- u32 ocp_data;
u16 data;
- int i;
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
- if (tp->version == RTL_VER_16 || tp->version == RTL_VER_17) {
- ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));
- ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));
- }
+ /* Enable SW reset */
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));
ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
- if (tp->version < RTL_VER_16)
- ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);
-
ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15)
- ocp_word_set_bits(tp, MCU_TYPE_USB, USB_U2P3_CTRL, RX_DETECT8);
-
r8153b_u1u2en(tp, false);
- switch (tp->version) {
- case RTL_VER_13:
- case RTL_VER_15:
- case RTL_VER_16:
- case RTL_VER_17:
- r8156b_wait_loading_flash(tp);
- break;
- default:
- break;
- }
-
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
+ r8156b_wait_loading_flash(tp);
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- }
+ if (wait_autoload_done(tp))
+ return;
- if (tp->version == RTL_VER_17 && r8159_wait_backup_restore(tp)) {
+ if (r8159_wait_backup_restore(tp)) {
rtl_set_inaccessible(tp);
- dev_err(&tp->intf->dev, "init failed, backup-restore timed out\n");
+ dev_err(&tp->intf->dev,
+ "init failed, backup-restore timed out\n");
return;
}
data = r8153_phy_status(tp, 0);
if (data == PHY_STAT_EXT_INIT) {
ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
- if (tp->version >= RTL_VER_12)
- ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
}
- data = r8152_mdio_read(tp, MII_BMCR);
- if (data & BMCR_PDOWN) {
- data &= ~BMCR_PDOWN;
- r8152_mdio_write(tp, MII_BMCR, data);
- }
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- if (tp->version >= RTL_VER_16)
- r8157_u2p3en(tp, false);
- else
- r8153_u2p3en(tp, false);
+ r8157_u2p3en(tp, false);
+
+ /* Disable Interrupt Mitigation */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,
+ BIT(0) | BIT(1) | BIT(2) | BIT(7));
+
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
/* MSC timer = 0xfff * 8ms = 32760 ms */
ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
@@ -8421,72 +9351,53 @@ static void r8156_init(struct r8152 *tp)
/* U1/U2/L1 idle timer. 500 us */
ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
- if (tp->version >= RTL_VER_16)
- r8157_power_cut_en(tp, false);
- else
- r8153b_power_cut_en(tp, false);
-
- r8156_ups_en(tp, false);
+ r8157_power_cut_en(tp, false);
+ r8157_ups_en(tp, false);
r8153_queue_wake(tp, false);
rtl_runtime_suspend_enable(tp, false);
- if (tp->udev->speed >= USB_SPEED_SUPER)
- r8153b_u1u2en(tp, true);
-
- usb_enable_lpm(tp->udev);
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15) {
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
- ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);
+ /* Clear Warm RST / Bus RST event flag */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));
- /* enable fc timer and set timer to 600 ms. */
- ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, CTRL_TIMER_EN | (600 / 8));
+ /* Disable FW u1u2 patch option */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xb9a6, BIT(0));
- ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL);
- if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & DACK_DET_EN))
- ocp_data |= FLOW_CTRL_PATCH_2;
- ocp_data &= ~AUTO_SPEEDUP;
- ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data);
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
- ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
- }
+ usb_enable_lpm(tp->udev);
r8156_mac_clk_spd(tp, true);
- if (tp->version < RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, PLA_MCU_SPDWN_EN);
-
- ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
if (rtl8152_get_speed(tp) & LINK_STATUS)
- ocp_data |= CUR_LINK_OK;
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
else
- ocp_data &= ~CUR_LINK_OK;
- ocp_data |= POLL_LINK_CHG;
- ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK, POLL_LINK_CHG);
set_bit(GREEN_ETHERNET, &tp->flags);
- /* RX aggregation / 16 bytes RX descriptor
- * BIT(11) is specific to RTL8159, with unknown meaning
- */
- if (tp->version == RTL_VER_17)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
- RX_AGG_DISABLE | RX_DESC_16B | BIT(11));
- else if (tp->version == RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL, RX_AGG_DISABLE | RX_DESC_16B);
- else
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL, RX_AGG_DISABLE | RX_ZERO_EN);
+ /* RX aggregation / 16 bytes RX descriptor / Bulk In End transfer */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_DESC_16B | RX_END_TRANSFER_EN);
- if (tp->version < RTL_VER_12)
- ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ACT_ODMA);
+ /* Disable Rx Zero Len */
+ rtl_bmu_clr_bits(tp, 0x2300, BIT(3));
- if (tp->version >= RTL_VER_16) {
- /* Disable Rx Zero Len */
- rtl_bmu_clr_bits(tp, 0x2300, BIT(3));
- /* TX descriptor Signature */
- ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
- }
+ /* TX descriptor Signature */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
+
+ /* Enable u2phy backup restore patch */
+ if (tp->version == RTL_VER_17_QFN68)
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xb99c, BIT(0));
+
+ /* Enable u3phy patch backup */
+ ocp_write_word(tp, MCU_TYPE_USB, 0xb9a2, 0x0448);
r8156_mdio_force_mode(tp);
rtl_tally_reset(tp);
@@ -8926,8 +9837,16 @@ int rtl8152_get_link_ksettings(struct net_device *netdev,
cmd->link_modes.supported, tp->support_10000full);
if (tp->support_2500full || tp->support_5000full || tp->support_10000full) {
- u16 ocp_10gbt_ctrl = ocp_reg_read(tp, OCP_10GBT_CTRL);
- u16 ocp_10gbt_stat = ocp_reg_read(tp, OCP_10GBT_STAT);
+ u16 ocp_10gbt_ctrl;
+ u16 ocp_10gbt_stat;
+
+ ret = ocp_reg_read(tp, OCP_10GBT_CTRL, &ocp_10gbt_ctrl);
+ if (ret < 0)
+ goto out_unlock;
+
+ ret = ocp_reg_read(tp, OCP_10GBT_STAT, &ocp_10gbt_stat);
+ if (ret < 0)
+ goto out_unlock;
if (tp->support_2500full) {
linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
@@ -8969,12 +9888,13 @@ int rtl8152_get_link_ksettings(struct net_device *netdev,
}
}
+out_unlock:
mutex_unlock(&tp->control);
usb_autopm_put_interface(tp->intf);
out:
- return ret;
+ return ret < 0 ? ret : 0;
}
static int rtl8152_set_link_ksettings(struct net_device *dev,
@@ -9155,21 +10075,37 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)
__ETHTOOL_DECLARE_LINK_MODE_MASK(common) = {};
u16 speed = rtl8152_get_speed(tp);
u16 val;
+ int ret;
+
+ ret = ocp_reg_read(tp, OCP_EEE_ABLE, &val);
+ if (ret < 0)
+ goto out;
- val = ocp_reg_read(tp, OCP_EEE_ABLE);
mii_eee_cap1_mod_linkmode_t(eee->supported, val);
- val = ocp_reg_read(tp, OCP_EEE_ADV);
+ ret = ocp_reg_read(tp, OCP_EEE_ADV, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap1_mod_linkmode_t(eee->advertised, val);
- val = ocp_reg_read(tp, OCP_EEE_LPABLE);
+ ret = ocp_reg_read(tp, OCP_EEE_LPABLE, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap1_mod_linkmode_t(eee->lp_advertised, val);
if (tp->support_2500full || tp->support_5000full) {
- val = ocp_reg_read(tp, OCP_EEE_ADV2);
+ ret = ocp_reg_read(tp, OCP_EEE_ADV2, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap2_mod_linkmode_adv_t(eee->advertised, val);
- val = ocp_reg_read(tp, OCP_EEE_LPABLE2);
+ ret = ocp_reg_read(tp, OCP_EEE_LPABLE2, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap2_mod_linkmode_adv_t(eee->lp_advertised, val);
}
@@ -9205,7 +10141,8 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)
linkmode_and(common, common, eee->lp_advertised);
eee->eee_active = !linkmode_empty(common);
- return 0;
+out:
+ return ret < 0 ? ret : 0;
}
static int
@@ -9445,7 +10382,7 @@ static int rtl8152_set_ringparam(struct net_device *netdev,
static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
{
struct r8152 *tp = netdev_priv(netdev);
- u16 bmcr, lcladv, rmtadv;
+ int bmcr, lcladv, rmtadv;
u8 cap;
if (usb_autopm_get_interface(tp->intf) < 0)
@@ -9461,7 +10398,10 @@ static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pau
usb_autopm_put_interface(tp->intf);
- if (!(bmcr & BMCR_ANENABLE)) {
+ /* Without a readable PHY, or with autoneg off, there is no flow
+ * control to report.
+ */
+ if (bmcr < 0 || lcladv < 0 || rmtadv < 0 || !(bmcr & BMCR_ANENABLE)) {
pause->autoneg = 0;
pause->rx_pause = 0;
pause->tx_pause = 0;
@@ -9492,7 +10432,11 @@ static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_paus
mutex_lock(&tp->control);
- if (pause->autoneg && !(r8152_mdio_read(tp, MII_BMCR) & BMCR_ANENABLE)) {
+ ret = r8152_mdio_read(tp, MII_BMCR);
+ if (ret < 0)
+ goto out;
+
+ if (pause->autoneg && !(ret & BMCR_ANENABLE)) {
ret = -EINVAL;
goto out;
}
@@ -9503,16 +10447,20 @@ static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_paus
if (pause->tx_pause)
cap |= FLOW_CTRL_TX;
- old = r8152_mdio_read(tp, MII_ADVERTISE);
+ ret = r8152_mdio_read(tp, MII_ADVERTISE);
+ if (ret < 0)
+ goto out;
+
+ old = ret;
new1 = (old & ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM)) | mii_advertise_flowctrl(cap);
if (old != new1)
- r8152_mdio_write(tp, MII_ADVERTISE, new1);
+ ret = r8152_mdio_write(tp, MII_ADVERTISE, new1);
out:
mutex_unlock(&tp->control);
usb_autopm_put_interface(tp->intf);
- return ret;
+ return ret < 0 ? ret : 0;
}
static const struct ethtool_ops ops = {
@@ -9546,7 +10494,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{
struct r8152 *tp = netdev_priv(netdev);
struct mii_ioctl_data *data = if_mii(rq);
- int res;
+ int res, val;
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return -ENODEV;
@@ -9562,7 +10510,11 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
case SIOCGMIIREG:
mutex_lock(&tp->control);
- data->val_out = r8152_mdio_read(tp, data->reg_num);
+ val = r8152_mdio_read(tp, data->reg_num);
+ if (val < 0)
+ res = val;
+ else
+ data->val_out = val;
mutex_unlock(&tp->control);
break;
@@ -9572,7 +10524,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
break;
}
mutex_lock(&tp->control);
- r8152_mdio_write(tp, data->reg_num, data->val_in);
+ res = r8152_mdio_write(tp, data->reg_num, data->val_in);
mutex_unlock(&tp->control);
break;
@@ -9663,11 +10615,6 @@ static void rtl8153_unload(struct r8152 *tp)
return;
r8153_power_cut_en(tp, false);
-
- if (tp->version >= RTL_VER_16) {
- /* Disable Interrupt Mitigation */
- ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04, BIT(0) | BIT(1) | BIT(2) | BIT(7));
- }
}
static void rtl8153b_unload(struct r8152 *tp)
@@ -9678,6 +10625,16 @@ static void rtl8153b_unload(struct r8152 *tp)
r8153b_power_cut_en(tp, false);
}
+static void rtl8157_unload(struct r8152 *tp)
+{
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ r8157_power_cut_en(tp, false);
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,
+ BIT(0) | BIT(1) | BIT(2) | BIT(7));
+}
+
static int r8152_desc_init(struct r8152 *tp)
{
tp->rx_desc.size = sizeof(struct rx_desc);
@@ -9730,6 +10687,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->in_nway = rtl8152_in_nway;
ops->hw_phy_cfg = r8152b_hw_phy_cfg;
ops->autosuspend_en = rtl_runtime_suspend_enable;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 16 * 1024;
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_100TX;
@@ -9752,6 +10711,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8153_hw_phy_cfg;
ops->autosuspend_en = rtl8153_runtime_enable;
ops->change_mtu = rtl8153_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
if (tp->udev->speed < USB_SPEED_SUPER)
tp->rx_buf_sz = 16 * 1024;
else
@@ -9775,6 +10736,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8153b_hw_phy_cfg;
ops->autosuspend_en = rtl8153b_runtime_enable;
ops->change_mtu = rtl8153_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 32 * 1024;
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
@@ -9799,6 +10762,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8156_hw_phy_cfg;
ops->autosuspend_en = rtl8156_runtime_enable;
ops->change_mtu = rtl8156_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 48 * 1024;
tp->support_2500full = 1;
r8152_desc_init(tp);
@@ -9812,8 +10777,8 @@ static int rtl_ops_init(struct r8152 *tp)
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
tp->eee_adv2 = MDIO_EEE_2_5GT;
- ops->init = r8156_init;
- ops->enable = rtl8156_enable;
+ ops->init = r8156b_init;
+ ops->enable = rtl8156b_enable;
ops->disable = rtl8153_disable;
ops->up = rtl8156_up;
ops->down = rtl8156_down;
@@ -9824,6 +10789,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8156b_hw_phy_cfg;
ops->autosuspend_en = rtl8156_runtime_enable;
ops->change_mtu = rtl8156_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 48 * 1024;
r8152_desc_init(tp);
break;
@@ -9841,6 +10808,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8153c_hw_phy_cfg;
ops->autosuspend_en = rtl8153c_runtime_enable;
ops->change_mtu = rtl8153c_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 32 * 1024;
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
@@ -9851,40 +10820,45 @@ static int rtl_ops_init(struct r8152 *tp)
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
tp->eee_adv2 = MDIO_EEE_2_5GT | MDIO_EEE_5GT;
- ops->init = r8156_init;
- ops->enable = rtl8156_enable;
+ ops->init = r8157_init;
+ ops->enable = rtl8157_enable;
ops->disable = rtl8153_disable;
- ops->up = rtl8156_up;
- ops->down = rtl8156_down;
- ops->unload = rtl8153_unload;
+ ops->up = rtl8157_up;
+ ops->down = rtl8157_down;
+ ops->unload = rtl8157_unload;
ops->eee_get = r8153_get_eee;
ops->eee_set = r8152_set_eee;
ops->in_nway = rtl8153_in_nway;
ops->hw_phy_cfg = r8157_hw_phy_cfg;
ops->autosuspend_en = rtl8157_runtime_enable;
- ops->change_mtu = rtl8156_change_mtu;
+ ops->change_mtu = rtl8157_change_mtu;
+ ops->phy_read = r8157_phy_read;
+ ops->phy_write = r8157_phy_write;
tp->rx_buf_sz = 32 * 1024;
tp->support_2500full = 1;
tp->support_5000full = 1;
r8157_desc_init(tp);
break;
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_100TX | MDIO_EEE_1000T | MDIO_EEE_10GT;
tp->eee_adv2 = MDIO_EEE_2_5GT | MDIO_EEE_5GT;
- ops->init = r8156_init;
- ops->enable = rtl8156_enable;
+ ops->init = r8159_init;
+ ops->enable = rtl8157_enable;
ops->disable = rtl8153_disable;
- ops->up = rtl8156_up;
- ops->down = rtl8156_down;
- ops->unload = rtl8153_unload;
+ ops->up = rtl8157_up;
+ ops->down = rtl8157_down;
+ ops->unload = rtl8157_unload;
ops->eee_get = r8153_get_eee;
ops->eee_set = r8152_set_eee;
ops->in_nway = rtl8153_in_nway;
- ops->hw_phy_cfg = r8157_hw_phy_cfg;
+ ops->hw_phy_cfg = r8159_hw_phy_cfg;
ops->autosuspend_en = rtl8157_runtime_enable;
- ops->change_mtu = rtl8156_change_mtu;
+ ops->change_mtu = rtl8157_change_mtu;
+ ops->phy_read = r8157_phy_read;
+ ops->phy_write = r8157_phy_write;
tp->rx_buf_sz = 48 * 1024;
tp->support_2500full = 1;
tp->support_5000full = 1;
@@ -9961,7 +10935,8 @@ static int rtl_fw_init(struct r8152 *tp)
case RTL_VER_16:
rtl_fw->fw_name = FIRMWARE_8157_1;
break;
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
rtl_fw->fw_name = FIRMWARE_8159_1;
break;
default:
@@ -9971,9 +10946,38 @@ static int rtl_fw_init(struct r8152 *tp)
return 0;
}
+static u32 __rtl_get_pkg_det(struct usb_device *udev)
+{
+ u32 pkg_det = 0;
+ __le32 *tmp;
+ int ret, i;
+
+ tmp = kmalloc_obj(*tmp);
+ if (!tmp)
+ return 0;
+
+ for (i = 0, ret = 0; i < 3 && ret != 4; i++)
+ ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+ RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
+ PLA_PKG_DET, MCU_TYPE_PLA, tmp,
+ sizeof(*tmp), USB_CTRL_GET_TIMEOUT);
+
+ if (ret == sizeof(*tmp)) {
+ if (i != 0)
+ dev_warn(&udev->dev,
+ "Needed %d retries to read package\n", i);
+
+ pkg_det = __le32_to_cpu(*tmp) & PKG_MASK;
+ }
+
+ kfree(tmp);
+ return pkg_det;
+}
+
static u8 __rtl_get_hw_ver(struct usb_device *udev)
{
u32 ocp_data = 0;
+ u32 pkg_det = 0;
__le32 *tmp;
u8 version;
int ret;
@@ -10056,7 +11060,16 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev)
version = RTL_VER_16;
break;
case 0x2020:
- version = RTL_VER_17;
+ pkg_det = __rtl_get_pkg_det(udev);
+ if (pkg_det == 0x1e || pkg_det == 0x1c) {
+ version = RTL_VER_17_QFN68;
+ } else if (pkg_det == 0x18 || pkg_det == 0x1a) {
+ version = RTL_VER_17_QFN100;
+ } else {
+ version = RTL_VER_UNKNOWN;
+ dev_info(&udev->dev, "Unknown package 0x%04x\n",
+ pkg_det);
+ }
break;
default:
version = RTL_VER_UNKNOWN;
@@ -10215,7 +11228,8 @@ static int rtl8152_probe_once(struct usb_interface *intf,
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
netdev->max_mtu = size_to_mtu(16 * 1024);
break;
case RTL_VER_01:
|
| 3/2 | 2026/10/02 04:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 47017 output: 35 thoughts: 396 Thoughts: **Evaluating the Patch for Reachability** Okay, so the task at hand is to evaluate this patch series on the Linux kernel, specifically targeting the amd64 architecture. My focus, initially, is on the patch affecting `drivers/net/usb/r8152.c`. First, I need to understand what this `r8152` component is – ah, Realtek's USB Ethernet driver. My immediate thought is, "Can this even be fuzzed?" Is USB networking a reachable attack surface? Time for a quick refresh on the triage philosophy. Reachability is the absolute primary gatekeeper. The code needs to be executable in a standard virtualized environment. We are talking QEMU here, with software emulated devices like USB gadgets, netdev, or tun/tap. If the code is structurally unreachable, even with complex logic, then it's a no-go. The philosophy explicitly lists drivers accessible via virtual buses, like virtio, USB gadget, and loopback, as targets. Excellent. Now, I recall Syzkaller has the capability to fuzz USB drivers via Raw Gadget or USB emulation through `syz_usb_connect`. This is great news. I can definitely use this to fuzz USB Ethernet adapters, like our `r8152` driver. So, the next step is to verify whether `r8152` is actually reachable via this USB fuzzing in Syzkaller, or if the driver can be reached in standard virtualized environments. To confirm, I should also confirm what configurations are necessary, what the patch does, and to verify whether USB drivers are considered reachable. And, of course, I should quickly check the `Kconfig` for `r8152`. |
| 4/2 | 2026/10/02 04:53 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_USB_RTL8152",
"PathPrefix": "drivers/net/usb"
}Results: {
"Output": "drivers/net/usb/Kconfig=636=config USB_RTL8153_ECM\n--\ndrivers/net/usb/Kconfig-641-\t This option supports ECM mode for RTL8153 ethernet adapter, when\ndrivers/net/usb/Kconfig:642:\t CONFIG_USB_RTL8152 is not set, or the RTL8153 device is not\ndrivers/net/usb/Kconfig-643-\t supported by r8152 driver.\n--\ndrivers/net/usb/Makefile=9=obj-$(CONFIG_USB_RTL8150)\t+= rtl8150.o\ndrivers/net/usb/Makefile:10:obj-$(CONFIG_USB_RTL8152)\t+= r8152.o\ndrivers/net/usb/Makefile-11-obj-$(CONFIG_USB_HSO)\t\t+= hso.o\n--\ndrivers/net/usb/r8152.c=11121=static int rtl8152_probe_once(struct usb_interface *intf,\n--\ndrivers/net/usb/r8152.c-11286-\ttp-\u003ertl_ops.init(tp);\ndrivers/net/usb/r8152.c:11287:#if IS_BUILTIN(CONFIG_USB_RTL8152)\ndrivers/net/usb/r8152.c-11288-\t/* Retry in case request_firmware() is not ready yet. */\n--\ndrivers/net/usb/r8153_ecm.c=149=static int rtl8153_ecm_probe(struct usb_interface *intf,\n--\ndrivers/net/usb/r8153_ecm.c-151-{\ndrivers/net/usb/r8153_ecm.c:152:#if IS_REACHABLE(CONFIG_USB_RTL8152)\ndrivers/net/usb/r8153_ecm.c-153-\tif (rtl8152_get_version(intf))\n"
} |
| 5/2 | 2026/10/02 04:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48348 output: 36 thoughts: 44 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating USB Ethernet Driver Configuration** Right, so I need to dig into the configuration for this particular USB Ethernet adapter. My initial thought is to navigate straight to the source, so I'm thinking I should start by examining `drivers/net/usb/Kconfig`. I seem to recall that's the canonical place for all these device-specific options, and I'm guessing the configuration options for a Realtek RTL8152 based device would be around the 600 line mark, or perhaps a section near that line. Alternatively, a quick `grep` for `USB_RTL8152` within the `Kconfig` file would certainly be faster. I just want to quickly pinpoint the relevant configuration symbol, and figure out how it’s tied into the rest of the build. I expect this will illuminate dependencies, default settings, and any specific driver nuances. From there, I can move on to the driver source itself. |
| 6/2 | 2026/10/02 04:53 | tool | grepper |
0mArgs:{
"Expression": "USB_RTL8152",
"PathPrefix": "drivers/net/usb/Kconfig"
}Results: {
"Output": "drivers/net/usb/Kconfig=88=config USB_RTL8150\n--\ndrivers/net/usb/Kconfig-98-\ndrivers/net/usb/Kconfig:99:config USB_RTL8152\ndrivers/net/usb/Kconfig-100-\ttristate \"Realtek RTL8152/RTL8153 Based USB Ethernet Adapters\"\n--\ndrivers/net/usb/Kconfig=636=config USB_RTL8153_ECM\ndrivers/net/usb/Kconfig-637-\ttristate\ndrivers/net/usb/Kconfig:638:\tdepends on USB_NET_CDCETHER \u0026\u0026 (USB_RTL8152 || USB_RTL8152=n)\ndrivers/net/usb/Kconfig-639-\tdefault y\n--\ndrivers/net/usb/Kconfig-641-\t This option supports ECM mode for RTL8153 ethernet adapter, when\ndrivers/net/usb/Kconfig:642:\t CONFIG_USB_RTL8152 is not set, or the RTL8153 device is not\ndrivers/net/usb/Kconfig-643-\t supported by r8152 driver.\n"
} |
| 7/2 | 2026/10/02 04:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48962 output: 35 thoughts: 36 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing the USB RTL8152 Driver Configuration** Alright, let's dive into the kernel configuration file, specifically `drivers/net/usb/Kconfig`, and pinpoint what's going on around line 99. The goal, as always, is a deep understanding of the dependencies and conditional compilation flags that govern the inclusion of `CONFIG_USB_RTL8152`. I need to see *precisely* what needs to be in place for that driver to even be considered during the build process. I'm looking for the breadcrumbs that explain why it might be enabled, disabled, or built as a module in different scenarios. I'm expecting to see dependencies on the USB core, perhaps specific USB controller drivers, and potentially other network-related options. This will help me quickly understand any potential conflicts, identify common build configurations, and, as always, better know how to debug it if I ever need to troubleshoot it. |
| 8/2 | 2026/10/02 04:53 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/Kconfig",
"FirstLine": 95,
"LineCount": 30
}Results: {
"Contents": " 95:\t\n 96:\t\t To compile this driver as a module, choose M here: the\n 97:\t\t module will be called rtl8150.\n 98:\t\n 99:\tconfig USB_RTL8152\n 100:\t\ttristate \"Realtek RTL8152/RTL8153 Based USB Ethernet Adapters\"\n 101:\t\tselect MII\n 102:\t\tselect PHYLIB\n 103:\t\tselect CRC32\n 104:\t\tselect CRYPTO_LIB_SHA256\n 105:\t\thelp\n 106:\t\t This option adds support for Realtek RTL8152 based USB 2.0\n 107:\t\t 10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000\n 108:\t\t Ethernet adapters.\n 109:\t\n 110:\t\t To compile this driver as a module, choose M here: the\n 111:\t\t module will be called r8152.\n 112:\t\n 113:\tconfig USB_LAN78XX\n 114:\t\ttristate \"Microchip LAN78XX Based USB Ethernet Adapters\"\n 115:\t\tselect MII\n 116:\t\tselect PHYLINK\n 117:\t\tselect MICROCHIP_PHY\n 118:\t\tselect CRC32\n 119:\t\timply NET_SELFTESTS\n 120:\t\thelp\n 121:\t\t This option adds support for Microchip LAN78XX based USB 2\n 122:\t\t \u0026 USB 3 10/100/1000 Ethernet adapters.\n 123:\t\t LAN7800 : USB 3 to 10/100/1000 Ethernet adapter\n 124:\t\t LAN7850 : USB 2 to 10/100/1000 Ethernet adapter\n"
} |
| 9/2 | 2026/10/02 04:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49761 output: 34 thoughts: 20 Thoughts: Here's my take on those thoughts: **Navigating the USB Network Driver Dependencies** Okay, so I need to understand the configuration dependencies within the USB network driver subsystem. My immediate thought is to dive into the `drivers/net/usb/Kconfig` file. That's the go-to place for defining all the Kconfig options, menu structure, and crucially, those inter-dependencies between features and parent menus. I want to see exactly how these USB network drivers are organized – what's nested under what, and what other kernel features they might rely upon. This will inform my next steps in how to modify the kernel. |
| 10/2 | 2026/10/02 04:53 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t#\n 3:\t# USB Network devices configuration\n 4:\t#\n 5:\tcomment \"Host-side USB support is needed for USB Network Adapter support\"\n 6:\t\tdepends on !USB \u0026\u0026 NET\n 7:\t\n 8:\tmenuconfig USB_NET_DRIVERS\n 9:\t\ttristate \"USB Network Adapters\"\n 10:\t\tdefault USB if USB\n 11:\t\tdepends on USB \u0026\u0026 NET\n 12:\t\n 13:\tif USB_NET_DRIVERS\n 14:\t\n 15:\tconfig USB_CATC\n 16:\t\ttristate \"USB CATC NetMate-based Ethernet device support\"\n 17:\t\tselect CRC32\n 18:\t\thelp\n 19:\t\t Say Y if you want to use one of the following 10Mbps USB Ethernet\n 20:\t\t device based on the EL1210A chip. Supported devices are:\n 21:\t\t Belkin F5U011\n 22:\t\t Belkin F5U111\n 23:\t\t CATC NetMate\n 24:\t\t CATC NetMate II\n 25:\t\t smartBridges smartNIC\n 26:\t\n 27:\t\t This driver makes the adapter appear as a normal Ethernet interface,\n 28:\t\t typically on eth0, if it is the only ethernet device, or perhaps on\n 29:\t\t eth1, if you have a PCI or ISA ethernet card installed.\n 30:\t\n 31:\t\t To compile this driver as a module, choose M here: the\n 32:\t\t module will be called catc.\n 33:\t\n 34:\tconfig USB_KAWETH\n 35:\t\ttristate \"USB KLSI KL5USB101-based ethernet device support\"\n 36:\t\thelp\n 37:\t\t Say Y here if you want to use one of the following 10Mbps only\n 38:\t\t USB Ethernet adapters based on the KLSI KL5KUSB101B chipset:\n 39:\t\t 3Com 3C19250\n 40:\t\t ADS USB-10BT\n"
} |
| 11/2 | 2026/10/02 04:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50510 output: 40 thoughts: 1908 Thoughts: **Fuzzing Feasibility Analysis: Realtek RTL8152 USB Driver** Okay, so I'm looking at this Realtek RTL8152 USB driver, `USB_RTL8152`, and figuring out if it's a good candidate for syzkaller fuzzing. It's dependent on `USB` and `NET`, which is a good starting point. I need to determine if the changes in the patch I'm examining make it fuzzable. First, I recall that USB drivers are explicitly listed as reachable via USB gadget and raw gadget emulation within syzkaller's documentation. That's a strong positive indicator. Section 3 of the relevant documentation confirms that drivers accessible via virtual buses are worth fuzzing. Section 2, however, provides a list of situations where fuzzing should be avoided. None of the negative criteria seem to apply here. The hardware is not structurally unreachable, because it can be emulated. Furthermore, the driver patch doesn't only touch teardown callbacks, but also `probe`, `init`, `ioctl`, `ethtool`, `up`, `down`, which are all accessible via sockets, ioctls, ethtool netlink/ioctls and so on. Next, I need to look at the patch itself to determine the extent of its changes. The toolset for inspecting the git log isn't directly available, but I have the diff, and I can extract the information needed. Here's a breakdown of the observed changes: 1. **Register Defines:** New Platform Abstraction Layer (PLA) and USB register defines were added: `PLA_PKG_DET`, `PLA_RMT_WAKE`, `PLA_PAUSE_LIMIT`, `USB_FW_USB_VER`, and `USB_TGPHY_*`. These suggest new functionality and potential areas to target. 2. **Function Pointers:** New function pointers were added to the `struct r8152`: `phy_read` and `phy_write`. This suggests that the PHY access has been updated. 3. **Version Enumeration:** The `RTL_VER_17` enumeration was split into `RTL_VER_17_QFN68` and `RTL_VER_17_QFN100`. This increases the coverage for different device variants. 4. **PHY Access Refactoring:** The code for PHY read/write was substantially modified. `ocp_reg_read/write` now use out-parameters/return values, and helpers like `r8152_phy_read/write` (and variants) were introduced. The new `read_poll_timeout` function and a helper function `wait_autoload_done` were added. This likely improves reliability. 5. **New Helpers/Functions:** The addition of `wait_autoload_done`, `r8157_ups_en`, and `rtl_fc_pause_pkt_en` hints at new functionality, logic, and potential for control plane interactions. The `rtl_fc_pause_pkt_en` function looks particularly interesting due to its complex arithmetic. 6. **Driver Initialization and Management:** New functions `rtl8156b_enable`, `rtl8157_enable`, `rtl8157_change_mtu`, `rtl8157_up`, `rtl8157_down`, `r8156_init`, `r8156b_init`, `r8157_init`, `r8159_init`, and `rtl8157_unload` were added. These are all critical for device setup and teardown. This area is essential for proper fuzzing. 7. **Error Handling:** Modifications to `WARN_ON_ONCE` statements in various `hw_phy_cfg` functions, along with added logic, demonstrate enhanced error handling. 8. **Netdev Integration:** Modifications to `rtl8152_get_link_ksettings`, `r8153_get_eee`, `rtl8152_get_pauseparam`, `rtl8152_set_pauseparam`, and `rtl8152_ioctl` indicate the integration with the network stack has been refined. 9. **USB device binding:** `usb_device_id` is used, so it binds to USB devices via this mechanism, meaning that syzkaller can identify them. All of these new functions and modifications expose new code paths and state transitions that are all potentially fuzzable. I think that the changes look promising for syzkaller fuzzing. The updated register defines, new PHY access code, and added device initialization/management functions significantly increase the attack surface. The integration with the network |
| 12/2 | 2026/10/02 04:53 | tool | grepper |
0mArgs:{
"Expression": "rtl8152_table",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=11370=static void rtl8152_disconnect(struct usb_interface *intf)\n--\ndrivers/net/usb/r8152.c-11388-/* table of devices that work with this driver */\ndrivers/net/usb/r8152.c:11389:static const struct usb_device_id rtl8152_table[] = {\ndrivers/net/usb/r8152.c-11390-\t/* Realtek */\n--\ndrivers/net/usb/r8152.c-11432-\ndrivers/net/usb/r8152.c:11433:MODULE_DEVICE_TABLE(usb, rtl8152_table);\ndrivers/net/usb/r8152.c-11434-\ndrivers/net/usb/r8152.c=11435=static struct usb_driver rtl8152_driver = {\ndrivers/net/usb/r8152.c-11436-\t.name =\t\tMODULENAME,\ndrivers/net/usb/r8152.c:11437:\t.id_table =\trtl8152_table,\ndrivers/net/usb/r8152.c-11438-\t.probe =\trtl8152_probe,\n--\ndrivers/net/usb/r8152.c=11479=static struct usb_device_driver rtl8152_cfgselector_driver = {\n--\ndrivers/net/usb/r8152.c-11481-\t.choose_configuration = rtl8152_cfgselector_choose_configuration,\ndrivers/net/usb/r8152.c:11482:\t.id_table = rtl8152_table,\ndrivers/net/usb/r8152.c-11483-\t.generic_subclass = 1,\n"
} |
| 13/2 | 2026/10/02 04:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53998 output: 43 thoughts: 104 Thoughts: **Analyzing the RTL8152 USB Driver Initialization** Okay, let's break this down systematically. My understanding is that the `rtl8152_driver` utilizes `rtl8152_probe` as its primary probing function. The key here is how this probe is triggered. From what I recall, when Syzkaller simulates a USB device connection, specifically a `syz_usb_connect` call, and the connected device's Vendor ID (VID) and Product ID (PID) are a match against those entries defined in `rtl8152_table`, `rtl8152_probe` will be executed. Given this context, my next logical step is to delve into the implementation of `rtl8152_probe` itself. I need to examine its code to gain an in-depth understanding of its functionality and how it interacts with the broader USB network device framework. Specifically, I'll be looking in `drivers/net/usb/r8152.c` for this critical routine. I expect that I will be able to get a better sense of any potential attack surfaces. |
| 14/2 | 2026/10/02 04:54 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 11340,
"LineCount": 45
}Results: {
"Contents": "11340:\t\t\t\t const struct usb_device_id *id)\n11341:\t{\n11342:\t\tu8 version;\n11343:\t\tint ret;\n11344:\t\tint i;\n11345:\t\n11346:\t\tif (intf-\u003ecur_altsetting-\u003edesc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)\n11347:\t\t\treturn -ENODEV;\n11348:\t\n11349:\t\tif (!rtl_check_vendor_ok(intf))\n11350:\t\t\treturn -ENODEV;\n11351:\t\n11352:\t\tversion = rtl8152_get_version(intf);\n11353:\t\tif (version == RTL_VER_UNKNOWN)\n11354:\t\t\treturn -ENODEV;\n11355:\t\n11356:\t\tfor (i = 0; i \u003c RTL8152_PROBE_TRIES; i++) {\n11357:\t\t\tret = rtl8152_probe_once(intf, id, version);\n11358:\t\t\tif (ret != -EAGAIN)\n11359:\t\t\t\tbreak;\n11360:\t\t}\n11361:\t\tif (ret == -EAGAIN) {\n11362:\t\t\tdev_err(\u0026intf-\u003edev,\n11363:\t\t\t\t\"r8152 failed probe after %d tries; giving up\\n\", i);\n11364:\t\t\treturn -ENODEV;\n11365:\t\t}\n11366:\t\n11367:\t\treturn ret;\n11368:\t}\n11369:\t\n11370:\tstatic void rtl8152_disconnect(struct usb_interface *intf)\n11371:\t{\n11372:\t\tstruct r8152 *tp = usb_get_intfdata(intf);\n11373:\t\n11374:\t\tusb_set_intfdata(intf, NULL);\n11375:\t\tif (tp) {\n11376:\t\t\trtl_set_unplug(tp);\n11377:\t\n11378:\t\t\tunregister_netdev(tp-\u003enetdev);\n11379:\t\t\ttasklet_kill(\u0026tp-\u003etx_tl);\n11380:\t\t\tcancel_delayed_work_sync(\u0026tp-\u003ehw_phy_work);\n11381:\t\t\tif (tp-\u003ertl_ops.unload)\n11382:\t\t\t\ttp-\u003ertl_ops.unload(tp);\n11383:\t\t\trtl8152_release_firmware(tp);\n11384:\t\t\tfree_netdev(tp-\u003enetdev);\n"
} |
| 15/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55107 output: 41 thoughts: 35 Thoughts: Here's my analysis of the provided snippet, as if it were my thought process: **Diving into the RTL8152 Driver** Alright, let's dissect this `rtl8152` driver code. My immediate focus is on `rtl8152_get_version(intf)`. I want to understand how the hardware version is determined within this function. My next step will be to trace the execution path and identify how the `__rtl_get_hw_ver` function is called within the context of `rtl8152_get_version`. I need to figure out the chain of events here. Understanding this will give me a better grasp of how the RTL8152 device version is ascertained. |
| 16/2 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "__rtl_get_hw_ver",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=10949=static u32 __rtl_get_pkg_det(struct usb_device *udev)\n--\ndrivers/net/usb/r8152.c-10976-\ndrivers/net/usb/r8152.c:10977:static u8 __rtl_get_hw_ver(struct usb_device *udev)\ndrivers/net/usb/r8152.c-10978-{\n--\ndrivers/net/usb/r8152.c=11083=u8 rtl8152_get_version(struct usb_interface *intf)\n--\ndrivers/net/usb/r8152.c-11086-\ndrivers/net/usb/r8152.c:11087:\tversion = __rtl_get_hw_ver(interface_to_usbdev(intf));\ndrivers/net/usb/r8152.c-11088-\n--\ndrivers/net/usb/r8152.c=11449=static int rtl8152_cfgselector_choose_configuration(struct usb_device *udev)\n--\ndrivers/net/usb/r8152.c-11456-\t */\ndrivers/net/usb/r8152.c:11457:\tif (__rtl_get_hw_ver(udev) == RTL_VER_UNKNOWN)\ndrivers/net/usb/r8152.c-11458-\t\treturn -ENODEV;\n"
} |
| 17/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55747 output: 40 thoughts: 560 Thoughts: **Analyzing a Potential Fuzzing Target: Realtek USB Ethernet Driver** Okay, I'm looking at this Realtek USB Ethernet driver code. My focus is on understanding how a fuzzer could potentially manipulate its execution. I see this `__rtl_get_hw_ver(udev)` function is crucial. It reads from the USB device using `usb_control_msg` to determine the hardware version. Specifically, it calls `__rtl_get_pkg_det(udev)` to retrieve a "pkg_det" value. The code is structured where if the value returned is `0x2020`, it triggers a comparison with `0x1e` or `0x1c` to select `RTL_VER_17_QFN68`, or with `0x18` or `0x1a` for `RTL_VER_17_QFN100`. Aha! This is where the vulnerability window opens. A USB fuzzer, like syzkaller with its USB emulation capabilities, can control the *responses* to those `usb_control_msg` calls. If the fuzzer can force the responses to return a specific value, like `0x2020` followed by `0x1e` or `0x18`, I can effectively steer the code down the paths leading to the different `RTL_VER_17_*` versions. Now, after this version detection, the code calls `rtl8152_probe_once`, initializing the driver. I see that `rtl_ops_init(tp)` is executed and the `tp->rtl_ops.init(tp)` function will be called, resulting in the call of `r8157_init(tp)` or `r8159_init(tp)`. It's likely that different `RTL_VER_17_*` versions will have distinct control flows within these initialization routines. The next step in the normal execution path involves network device opening, `rtl8152_open` function. It seems like a good point to inspect if my prior path manipulations have any consequences. I'll need to check the code in `rtl8152_open` and its callers to assess the impact of these earlier choices, as `rtl8152_open` is called when `ifconfig up` or `ip link set up` are executed. Let's see what happens during device initialization and subsequent operations when the driver is initialized under a particular `RTL_VER_17_*` setting. |
| 18/2 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "rtl8152_open",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=7683=static int rtl_notifier(struct notifier_block *nb, unsigned long action,\n--\ndrivers/net/usb/r8152.c-7708-\ndrivers/net/usb/r8152.c:7709:static int rtl8152_open(struct net_device *netdev)\ndrivers/net/usb/r8152.c-7710-{\n--\ndrivers/net/usb/r8152.c=10589=static const struct net_device_ops rtl8152_netdev_ops = {\ndrivers/net/usb/r8152.c:10590:\t.ndo_open\t\t= rtl8152_open,\ndrivers/net/usb/r8152.c-10591-\t.ndo_stop\t\t= rtl8152_close,\n"
} |
| 19/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 57142 output: 34 thoughts: 692 Thoughts: **My Assessment of the RTL8152 USB Ethernet Driver's Fuzzing Potential** Okay, let's break this down. My initial assessment is that this `rtl8152` driver is *definitely* worth fuzzing. The logic path is clear: `rtl8152_open` initiates the sequence, leading to `rtl8152_up` which calls out to a set of operational functions, `tp->rtl_ops.up`, `tp->rtl_ops.enable`. MTU changes via standard interfaces (`SIOCSIFMTU`, netlink) trigger `tp->rtl_ops.change_mtu`. Ethtool commands and MII register access via ioctls call more of these methods. Crucially, on driver down (`rtl8152_close`), we see `tp->rtl_ops.down`. This is a pretty standard driver flow, but the key is how *reachable* it is. The text highlighted that this driver is, in fact, reachable. USB gadget emulation, sockets, netlink, ethtool, and ioctls are all methods of interfacing with the driver. That is a solid vector for testing! The presence of those interfaces strongly indicates that this driver is highly exposed to potential misuse. Now, let's examine those assertions. The `WARN_ON_ONCE` statements in `r8156_hw_phy_cfg`, `r8156b_hw_phy_cfg`, `r8157_hw_phy_cfg`, and `r8159_hw_phy_cfg` are particularly interesting. They check the `PHY_STAT_LAN_ON` status, and if it's not set *and* the driver isn't in an inaccessible state (via the `RTL8152_INACCESSIBLE` flag), a warning is raised. Assertions that can be triggered in reachable code *demand* fuzzing. We need to explore the corner cases that could lead to `data != PHY_STAT_LAN_ON`, especially considering the network interfaces available to us. This needs fuzzing, especially given that assertion. The text explicitly calls out that we shouldn't blindly trust claims of "no functional change" or refactorings; all changes, especially those touching reachable code or data structures, warrant close scrutiny. The highlighted text clearly states that any restructuring of reachable data structures, helper abstractions, or algorithm flows means it is *definitely* worth fuzzing. Finally, we need to quickly verify the build config for this driver. According to the text, we have to make sure that the dependencies are met. From a quick glance at the dependencies listed, `config USB_RTL8152` depends on `USB_NET_DRIVERS`, which depends on `USB && NET`. I'll need to double check the kernel config options to ensure these are enabled, but I'm expecting this to be an easy hurdle. Given that USB is such a common target, this should be a simple requirement to satisfy. Therefore, my conclusion is `WorthFuzzing = true`. |
| 20/2 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "source \"drivers/net/usb/Kconfig\"",
"PathPrefix": "drivers/net"
}Results: {
"Output": "drivers/net/Kconfig=532=source \"drivers/s390/net/Kconfig\"\ndrivers/net/Kconfig-533-\ndrivers/net/Kconfig:534:source \"drivers/net/usb/Kconfig\"\ndrivers/net/Kconfig-535-\n"
} |
| 21/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 58615 output: 34 thoughts: 30 Thoughts: Okay, let's dive into this. Here's how I'd approach that kernel configuration file check: **Kernel Configuration Investigation** Alright, so I need to zero in on `drivers/net/Kconfig` around line 534. The key here is not just finding the line, but understanding its context. The very first question I'm asking myself is: *Is there an `if` block surrounding that line?* Because that's the crucial detail, right? A conditional compilation statement is going to drastically change the behavior of that option. If it's *within* an `if` block, that whole section's inclusion hinges on some other config option being set. So my focus isn't just on the line, but the surrounding code structure. Determining the existence of that `if` block, and the condition it tests, is paramount. That's the first step in understanding what's going on with this specific network driver configuration. |
| 22/2 | 2026/10/02 04:54 | tool | read-file |
0mArgs:{
"File": "drivers/net/Kconfig",
"FirstLine": 525,
"LineCount": 25
}Results: {
"Contents": " 525:\t\n 526:\tsource \"drivers/net/plip/Kconfig\"\n 527:\t\n 528:\tsource \"drivers/net/ppp/Kconfig\"\n 529:\t\n 530:\tsource \"drivers/net/slip/Kconfig\"\n 531:\t\n 532:\tsource \"drivers/s390/net/Kconfig\"\n 533:\t\n 534:\tsource \"drivers/net/usb/Kconfig\"\n 535:\t\n 536:\tsource \"drivers/net/wireless/Kconfig\"\n 537:\t\n 538:\tsource \"drivers/net/wan/Kconfig\"\n 539:\t\n 540:\tsource \"drivers/net/ieee802154/Kconfig\"\n 541:\t\n 542:\tsource \"drivers/net/wwan/Kconfig\"\n 543:\t\n 544:\tconfig XEN_NETDEV_FRONTEND\n 545:\t\ttristate \"Xen network device frontend driver\"\n 546:\t\tdepends on XEN\n 547:\t\tselect XEN_XENBUS_FRONTEND\n 548:\t\tselect PAGE_POOL\n 549:\t\tdefault y\n"
} |
| 23/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 59221 output: 35 thoughts: 277 Thoughts: **Analyzing USB Network Adapter Support** Okay, so I'm looking at `drivers/net/usb/Kconfig` here. The first thing that jumps out is that there's a comment specifically stating that host-side USB support is essential for USB Network Adapter functionality – that's a key starting point. This `USB_NET_DRIVERS` config is important, it sounds like. It's tristate "USB Network Adapters", defaulting to USB if USB is enabled, and depends on both USB and NET. So enabling USB networking inherently requires both general USB support and networking support, which makes sense. Now, if `USB_NET_DRIVERS` is set, we get into the details, and I'm interested in the `USB_RTL8152` config. This is for Realtek adapters, which I've worked with before, and it's also tristate. It selects MII, PHYLIB, CRC32, and CRYPTO_LIB_SHA256, which all seem reasonable dependencies for a USB Ethernet adapter, and I expect to find these in the driver. So, the dependency chain seems pretty straightforward: `USB_RTL8152` depends on `USB_NET_DRIVERS`, which in turn depends on `USB` and `NET`. Therefore, to enable `USB_RTL8152` I need `USB_RTL8152`, `USB_NET_DRIVERS`, `USB`, and `NET` configs. However, the tristate state means that `USB_NET_DRIVERS` might not *always* be needed if `USB_RTL8152` is directly enabled. Let me quickly double-check that by verifying if `r8152.c` references other configs that are directly linked to it. |
| 24/2 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=947=struct r8152 {\n--\ndrivers/net/usb/r8152.c-961-\tstruct mutex control;\t/* use for hw setting */\ndrivers/net/usb/r8152.c:962:#ifdef CONFIG_PM_SLEEP\ndrivers/net/usb/r8152.c-963-\tstruct notifier_block pm_notifier;\n--\ndrivers/net/usb/r8152.c=4618=static bool rtl_can_wakeup(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-4621-\ndrivers/net/usb/r8152.c:4622:\treturn (udev-\u003eactconfig-\u003edesc.bmAttributes \u0026 USB_CONFIG_ATT_WAKEUP);\ndrivers/net/usb/r8152.c-4623-}\n--\ndrivers/net/usb/r8152.c=7649=static void rtl_hw_phy_work_func_t(struct work_struct *work)\n--\ndrivers/net/usb/r8152.c-7681-\ndrivers/net/usb/r8152.c:7682:#ifdef CONFIG_PM_SLEEP\ndrivers/net/usb/r8152.c-7683-static int rtl_notifier(struct notifier_block *nb, unsigned long action,\n--\ndrivers/net/usb/r8152.c=7709=static int rtl8152_open(struct net_device *netdev)\n--\ndrivers/net/usb/r8152.c-7748-\tusb_autopm_put_interface(tp-\u003eintf);\ndrivers/net/usb/r8152.c:7749:#ifdef CONFIG_PM_SLEEP\ndrivers/net/usb/r8152.c-7750-\ttp-\u003epm_notifier.notifier_call = rtl_notifier;\n--\ndrivers/net/usb/r8152.c=7764=static int rtl8152_close(struct net_device *netdev)\n--\ndrivers/net/usb/r8152.c-7768-\ndrivers/net/usb/r8152.c:7769:#ifdef CONFIG_PM_SLEEP\ndrivers/net/usb/r8152.c-7770-\tunregister_pm_notifier(\u0026tp-\u003epm_notifier);\n--\ndrivers/net/usb/r8152.c=11121=static int rtl8152_probe_once(struct usb_interface *intf,\n--\ndrivers/net/usb/r8152.c-11286-\ttp-\u003ertl_ops.init(tp);\ndrivers/net/usb/r8152.c:11287:#if IS_BUILTIN(CONFIG_USB_RTL8152)\ndrivers/net/usb/r8152.c-11288-\t/* Retry in case request_firmware() is not ready yet. */\n"
} |
| 25/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 60713 output: 58 thoughts: 1339 Thoughts: **Focus Symbol Determination: r8152.c Analysis** Okay, time to analyze the FocusSymbols, following the guidelines, naturally. I need to zero in on the functions that are *specifically* relevant to the changes in `r8152.c`, avoiding any ubiquitous functions that would dilute the fuzzing effort. My goal is to pinpoint the critical logic added or modified. First, let's go through the functions added or modified: I see `__rtl_get_pkg_det` and it's static, so it isn't going to be directly addressable. Moving on, `__rtl_get_hw_ver` is static, so I will need to determine if it is relevant through its callers. The same is true for `wait_autoload_done`, `wait_tgphy_cmd_ready`, and `rtl_tgphy_access`. These all look like helper functions. The `r8157_phy_read` and `r8157_phy_write` functions are assigned to `ops->phy_read` and `ops->phy_write` respectively. These might be important. `r8152_phy_read` and `r8152_phy_write` are assigned to the same. I'll need to remember that. Then `ocp_reg_read`, `ocp_reg_write`, `r8152_mdio_read`, and `r8152_mdio_write` are all static. Let's remember the inline nature of `r8152_mdio_write`. `sram_write`, `sram_read`, `ocp_reg_w0w1`, and `sram_write_w0w1` are all static. And then, `sram2_write`, `sram2_read`, `sram2_write_w0w1`, `sram2_set_bits`, `sram2_clr_bits`, `r8152_mdio_clr_bit`, `r8152_mdio_set_bit`, and `r8152_mdio_test_and_clr_bit` are all static. Moving on, `rtl_fc_pause_pkt_en` is static but called in several initialization functions: `rtl8157_enable`, `r8156_init`, and `r8156b_init`. That's an important connection. `r8156b_enable` and `rtl8157_enable` are static but are assigned to `ops->enable`, so that's key. Similarly, `rtl8157_ups_en` is static but called in `rtl8157_runtime_enable`, `r8157_init`, and `r8159_init`. `rtl8157_change_mtu`, `rtl8157_up`, and `rtl8157_down` are all static but assigned to operational functions. More static functions: `r8156_hw_phy_cfg`, `r8156b_hw_phy_cfg`, `r8157_hw_phy_cfg`, `r8159_hw_phy_cfg` are assigned to `ops->hw_phy_cfg`. Finally, `r8156_init`, `r8156b_init`, `r8157_init`, and `r8159_init` are assigned to `ops->init`. Alright, it's getting clearer. I need to remember the static and non-static nature. And there are several non-static functions as well. `rtl8152_get_link_ksettings` is a non-static function. `r8153_get_eee` is static but assigned to `ops->eee_get`. `rtl8152_get_pauseparam` and `rtl8152_set_pauseparam` are static but assigned to `ethtool_ops`, and `rtl8152_ioctl` is static but assigned to `netdev_ops`. `rtl8157_unload` is static, assigned to `ops->unload`, and `rtl_ops_init` is static and likely important for initialization. I'll need to double check `rtl8152_probe_once` and `rtl8152_probe`. Okay, I've got a good list, and I'll focus my fuzzing efforts on the non-static functions and those static functions that are assigned |
| 26/2 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "(EXPORT_SYMBOL|static [a-zA-Z0-9_]+ rtl8152_probe)",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=11083=u8 rtl8152_get_version(struct usb_interface *intf)\n--\ndrivers/net/usb/r8152.c-11092-}\ndrivers/net/usb/r8152.c:11093:EXPORT_SYMBOL_GPL(rtl8152_get_version);\ndrivers/net/usb/r8152.c-11094-\ndrivers/net/usb/r8152.c=11095=static bool rtl8152_supports_lenovo_macpassthru(struct usb_device *udev)\n--\ndrivers/net/usb/r8152.c-11120-\ndrivers/net/usb/r8152.c:11121:static int rtl8152_probe_once(struct usb_interface *intf,\ndrivers/net/usb/r8152.c-11122-\t\t\t const struct usb_device_id *id, u8 version)\n--\ndrivers/net/usb/r8152.c-11338-\ndrivers/net/usb/r8152.c:11339:static int rtl8152_probe(struct usb_interface *intf,\ndrivers/net/usb/r8152.c-11340-\t\t\t const struct usb_device_id *id)\n"
} |
| 27/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63511 output: 45 thoughts: 782 Thoughts: **Focusing on Targetable Symbols for Coverage** Okay, wait a minute. This is important. Even static functions within `.c` files, unless the compiler inlines them, *do* have symbols in `vmlinux/kallsyms`. The documentation specifically emphasizes handling *static inline* functions in headers, which is different. The key here is that if a function has its address taken, like in the case of callbacks or function pointers, it *cannot* be inlined. Let's look at the functions I'm interested in: `r8157_phy_read`, `r8157_phy_write`, `rtl8157_enable`, `rtl8157_change_mtu`, `rtl8157_up`, `rtl8157_down`, `rtl8157_unload`, `r8159_hw_phy_cfg`, `r8159_init`, `r8157_init`, `r8156b_init`, `r8156b_enable`, `r8152_phy_read`, `r8152_phy_write`. These are all distinct symbols. Functions called by function pointers or complex functions like `rtl_tgphy_access`, `rtl_fc_pause_pkt_en`, `rtl8152_ioctl`, `rtl8152_get_link_ksettings`, `rtl8152_get_pauseparam`, `rtl8152_set_pauseparam`, `r8153_get_eee` are also distinct symbols. And let's not forget the entrypoints like `rtl8152_probe` and `rtl8152_probe_once`. So, the game plan is to select the most appropriate feature-specific symbols to guide fuzzing, avoiding dilution and ensuring effective coverage. Okay, let's analyze the potential candidates: * `rtl_tgphy_access` - implements the new TGPHY bus access logic * `rtl_fc_pause_pkt_en` - implements the new flow control pause packet calculation logic * `r8157_phy_read` * `r8157_phy_write` * `rtl8157_enable` * `rtl8157_up` * `rtl8157_down` * `r8159_hw_phy_cfg` * `r8159_init` * `r8157_init` * `rtl8156b_enable` * `rtl8156b_init` * `rtl8152_ioctl` * `rtl8152_get_link_ksettings` * `rtl8152_set_pauseparam` * `wait_autoload_done` Now, to make sure I haven't missed anything, let's just quickly check if `rtl8152_get_link_ksettings` is declared in a header or defined as static, just to be sure. I'll just grep for that. |
| 28/2 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "rtl8152_get_link_ksettings",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=9812=static\ndrivers/net/usb/r8152.c:9813:int rtl8152_get_link_ksettings(struct net_device *netdev,\ndrivers/net/usb/r8152.c-9814-\t\t\t struct ethtool_link_ksettings *cmd)\n--\ndrivers/net/usb/r8152.c=10466=static const struct ethtool_ops ops = {\n--\ndrivers/net/usb/r8152.c-10481-\t.set_eee = rtl_ethtool_set_eee,\ndrivers/net/usb/r8152.c:10482:\t.get_link_ksettings = rtl8152_get_link_ksettings,\ndrivers/net/usb/r8152.c-10483-\t.set_link_ksettings = rtl8152_set_link_ksettings,\n"
} |
| 29/2 | 2026/10/02 04:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 65317 output: 385 thoughts: 953 Thoughts: **Analyzing the USB RTL8152 Driver Patch** Alright, let's break this down methodically. My initial thought was to consider including both `rtl8152_probe_once` and `rtl8152_probe`, but I need to keep the focus precisely on the changes introduced by this patch. First, I need to identify the key functions that really capture the essence of what's being modified. I should aim for around 5 to 15 key functions. After reviewing, here's my list, which I believe accurately reflects the most significant changes: - `rtl_tgphy_access` - `rtl_fc_pause_pkt_en` - `r8157_phy_read` - `r8157_phy_write` - `rtl8157_enable` - `rtl8157_up` - `rtl8157_down` - `rtl8157_change_mtu` - `r8159_hw_phy_cfg` - `r8159_init` - `r8157_init` - `r8156b_enable` - `r8156b_init` - `wait_autoload_done` - `__rtl_get_pkg_det` Next, I need to determine the required configurations. The Kconfig dependencies for `CONFIG_USB_RTL8152` are: `USB`, `USB_NET_DRIVERS`, and `NET`. I also checked for optional configurations like `CONFIG_PM_SLEEP`, but they're not essential here. Therefore, the required configurations are: `USB_RTL8152`, `USB_NET_DRIVERS`, `USB`, and `NET`. Finally, I need to assess whether this code is suitable for fuzzing. I'm confident that it is. This patch refactors the PHY access layer to return errors, adds support for RTL8159 (RTL_VER_17 variants), adds new pause packet calculation with logic, adds hw phy configuration routines, wait timeouts, and modifies assertions. More importantly, this is all code that is *reachable* in a standard virtualized environment like QEMU or even with syzkaller's USB emulation. Given these points, I'll set `WorthFuzzing = true`. I've carefully considered the context, and I'm ready to proceed with the tool call, ensuring all parameters are correct. |
| 30/2 | 2026/10/02 04:54 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"USB_RTL8152",
"USB_NET_DRIVERS",
"USB",
"NET"
],
"FocusSymbols": [
"rtl_tgphy_access",
"wait_tgphy_cmd_ready",
"rtl_fc_pause_pkt_en",
"r8157_phy_read",
"r8157_phy_write",
"rtl8157_enable",
"rtl8157_up",
"rtl8157_down",
"rtl8157_change_mtu",
"r8159_hw_phy_cfg",
"r8159_init",
"r8157_init",
"rtl8156b_enable",
"rtl8156b_init",
"wait_autoload_done",
"__rtl_get_pkg_det"
],
"Reasoning": "The patch introduces and refactors substantial hardware initialization and configuration logic for RTL8156B, RTL8157, and RTL8159 USB Ethernet adapters in the r8152 driver. Changes include new TGPHY access routines (rtl_tgphy_access), pause packet count calculations (rtl_fc_pause_pkt_en), package detection (__rtl_get_pkg_det), polling helpers (wait_autoload_done), and revised WARN_ON_ONCE assertions during PHY configuration. These code paths are fully reachable in virtualized environments via USB device emulation (e.g. syzkaller syz_usb_connect / USB Raw Gadget) and subsequent network device and ethtool/ioctl operations.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"USB_RTL8152",
"USB_NET_DRIVERS",
"USB",
"NET"
],
"FocusSymbols": [
"rtl_tgphy_access",
"wait_tgphy_cmd_ready",
"rtl_fc_pause_pkt_en",
"r8157_phy_read",
"r8157_phy_write",
"rtl8157_enable",
"rtl8157_up",
"rtl8157_down",
"rtl8157_change_mtu",
"r8159_hw_phy_cfg",
"r8159_init",
"r8157_init",
"rtl8156b_enable",
"rtl8156b_init",
"wait_autoload_done",
"__rtl_get_pkg_det"
],
"Reasoning": "The patch introduces and refactors substantial hardware initialization and configuration logic for RTL8156B, RTL8157, and RTL8159 USB Ethernet adapters in the r8152 driver. Changes include new TGPHY access routines (rtl_tgphy_access), pause packet count calculations (rtl_fc_pause_pkt_en), package detection (__rtl_get_pkg_det), polling helpers (wait_autoload_done), and revised WARN_ON_ONCE assertions during PHY configuration. These code paths are fully reachable in virtualized environments via USB device emulation (e.g. syzkaller syz_usb_connect / USB Raw Gadget) and subsequent network device and ethtool/ioctl operations.",
"WorthFuzzing": true
} |
| 31/1 | 2026/10/02 04:54 | action | If |
4mArgs:{
"WorthFuzzing": true
}Results: null |
| 32/2 | 2026/10/02 04:54 | agent | kmsan-evaluator |
4mModel:core Args: null Results: {
"KMSANReasoning": "The patch adds support for Realtek RTL8157 and RTL8159 chipsets in the r8152 USB ethernet driver. Key changes include:\n- Splitting RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100 using a package detection helper (__rtl_get_pkg_det).\n- Refactoring PHY and SRAM register access functions (ocp_reg_read, sram_read, sram2_read, r8152_mdio_read) to return status/error codes and write read values through pointer arguments.\n- Adding chipset-specific initialization, enable, suspend/resume, and hardware configuration routines.\n- Improving error checking in ethtool and ioctl handlers.\n\nRegarding KMSAN vs KASAN applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and info-leaks to userspace.\n- In all callers of the refactored read functions (ocp_reg_read, sram_read, etc.), the output variables are either explicitly pre-initialized (e.g. `data = 0` in r8153_phy_status and r8152_mmd_read) or are only read after verifying that the function returned non-negative success codes.\n- In `__rtl_get_pkg_det()`, the heap buffer `tmp` allocated via `kmalloc_obj()` is only accessed if `usb_control_msg()` returns `sizeof(*tmp)` (4 bytes); otherwise, a default initialized value (0) is returned.\n- In user-facing interfaces (such as `rtl8152_ioctl`, `rtl8152_get_pauseparam`, `r8153_get_eee`, and `rtl8152_get_link_ksettings`), error checks abort execution with a negative return code before any copying to userspace occurs, and output structures (`pause`, `data-\u003eval_out`, `eee`) are fully populated or zero-initialized.\n- No uninitialized data or kernel structure padding is exposed to userspace or used in control flow.\n\nTherefore, the patch does not introduce uninitialized memory risks that would require a dedicated KMSAN fuzzing session; standard KASAN/sanitizer testing is appropriate.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 3cf8c5c313bdcfe921621a6dcd8d2353064c8dbd
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Oct 2 04:53:29 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index af3d7dcb2f141..baac964fea80f 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -64,6 +64,7 @@
#define PLA_MACDBG_POST 0xd38e /* RTL_VER_04 only */
#define PLA_EXTRA_STATUS 0xd398
#define PLA_GPHY_CTRL 0xd3ae
+#define PLA_PKG_DET 0xdc48
#define PLA_POL_GPIO_CTRL 0xdc6a
#define PLA_EFUSE_DATA 0xdd00
#define PLA_EFUSE_CMD 0xdd02
@@ -78,6 +79,7 @@
#define PLA_EEE_TXTWSYS_2P5G 0xe058
#define PLA_EEEP_CR 0xe080
#define PLA_MAC_PWR_CTRL 0xe0c0
+#define PLA_RMT_WAKE 0xe0c8
#define PLA_MAC_PWR_CTRL2 0xe0ca
#define PLA_MAC_PWR_CTRL3 0xe0cc
#define PLA_MAC_PWR_CTRL4 0xe0ce
@@ -87,6 +89,7 @@
#define PLA_MTPS 0xe615
#define PLA_TXFIFO_CTRL 0xe618
#define PLA_TXFIFO_FULL 0xe61a
+#define PLA_PAUSE_LIMIT 0xe61e
#define PLA_RSTTALLY 0xe800
#define PLA_CR 0xe813
#define PLA_CRWECR 0xe81c
@@ -129,6 +132,7 @@
#define USB_BURST_SIZE 0xcfc0
#define USB_FW_FIX_EN0 0xcfca
#define USB_FW_FIX_EN1 0xcfcc
+#define USB_FW_USB_VER 0xcfd7
#define USB_LPM_CONFIG 0xcfd8
#define USB_ECM_OPTION 0xcfee
#define USB_CSTMR 0xcfef /* RTL8153A */
@@ -160,6 +164,9 @@
#define USB_ADV_ADDR 0xd5d6
#define USB_ADV_DATA 0xd5d8
#define USB_ADV_CMD 0xd5dc
+#define USB_TGPHY_ADDR 0xd630
+#define USB_TGPHY_DATA 0xd632
+#define USB_TGPHY_CMD 0xd634
#define USB_UPS_CTRL 0xd800
#define USB_POWER_CUT 0xd80a
#define USB_MISC_0 0xd81a
@@ -289,10 +296,17 @@
#define IFG_144NS BIT(9)
#define IFG_96NS (BIT(9) | BIT(8))
+/* PLA_PKG_DET */
+#define PKG_MASK 0x1e
+
/* PLA_MTPS */
#define MTPS_JUMBO (12 * 1024 / 64)
#define MTPS_DEFAULT (6 * 1024 / 64)
+/* PLA_PAUSE_LIMIT */
+#define PAUSE_LIMIT_EN BIT(3)
+#define PAUSE_LIMIT_MASK 0xf0
+
/* PLA_RSTTALLY */
#define TALLY_RESET 0x0001
@@ -371,6 +385,9 @@
#define MCU_CLK_RATIO_MASK 0x0f0f0f0f
#define ALDPS_SPDWN_RATIO 0x0f87
+/* PLA_RMT_WAKE */
+#define RMT_WAKE_EN BIT(0)
+
/* PLA_MAC_PWR_CTRL2 */
#define EEE_SPDWN_RATIO 0x8007
#define MAC_CLK_SPDWN_EN BIT(15)
@@ -417,6 +434,7 @@
/* PLA_INDICATE_FALG */
#define UPCOMING_RUNTIME_D3 BIT(0)
+#define PREBOOT_OPTION BIT(1)
/* PLA_MACDBG_PRE and PLA_MACDBG_POST */
#define DEBUG_OE BIT(0)
@@ -502,6 +520,10 @@
#define ADV_CMD_WR BIT(1)
#define ADV_CMD_IP BIT(2)
+/* USB_TGPHY_CMD */
+#define TGPHY_CMD_BUSY BIT(0)
+#define TGPHY_CMD_WR BIT(1)
+
/* USB_UPS_CTRL */
#define POWER_CUT 0x0100
@@ -542,6 +564,7 @@
#define RX_AGG_DISABLE 0x0010
#define RX_ZERO_EN 0x0080
#define RX_DESC_16B 0x0400
+#define RX_END_TRANSFER_EN BIT(11)
/* USB_U2P3_CTRL */
#define U2P3_ENABLE 0x0001
@@ -597,6 +620,11 @@
#define UPS_FLAGS_250M_CKDIV BIT(2)
#define UPS_FLAGS_EN_ALDPS BIT(3)
#define UPS_FLAGS_CTAP_SHORT_DIS BIT(4)
+#define UPS_FLAGS_EN_100M_EEE BIT(9)
+#define UPS_FLAGS_EN_1000M_EEE BIT(10)
+#define UPS_FLAGS_EN_2500M_EEE BIT(11)
+#define UPS_FLAGS_EN_5000M_EEE BIT(12)
+#define UPS_FLAGS_EN_10G_EEE BIT(13)
#define UPS_FLAGS_SPEED_MASK (0xf << 16)
#define ups_flags_speed(x) ((x) << 16)
#define UPS_FLAGS_EN_EEE BIT(20)
@@ -645,6 +673,7 @@ enum spd_duplex {
/* OCP_POWER_CFG */
#define EEE_CLKDIV_EN 0x8000
#define EN_ALDPS 0x0004
+#define EN_ALDPS_PLLOFF 0x0002
#define EN_10M_PLLOFF 0x0001
/* OCP_EEE_CONFIG1 */
@@ -948,6 +977,8 @@ struct r8152 {
void (*hw_phy_cfg)(struct r8152 *tp);
void (*autosuspend_en)(struct r8152 *tp, bool enable);
void (*change_mtu)(struct r8152 *tp);
+ int (*phy_read)(struct r8152 *tp, u16 addr, u16 *data);
+ int (*phy_write)(struct r8152 *tp, u16 addr, u16 data);
} rtl_ops;
struct ups_info {
@@ -1247,7 +1278,8 @@ enum rtl_version {
RTL_VER_14,
RTL_VER_15,
RTL_VER_16,
- RTL_VER_17,
+ RTL_VER_17_QFN68,
+ RTL_VER_17_QFN100,
RTL_VER_MAX
};
@@ -1626,7 +1658,7 @@ static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
}
-static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
+static int r8152_phy_read(struct r8152 *tp, u16 addr, u16 *data)
{
u16 ocp_base, ocp_index;
@@ -1637,10 +1669,12 @@ static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
}
ocp_index = (addr & 0x0fff) | 0xb000;
- return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
+ *data = ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
+
+ return 0;
}
-static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
+static int r8152_phy_write(struct r8152 *tp, u16 addr, u16 data)
{
u16 ocp_base, ocp_index;
@@ -1652,16 +1686,33 @@ static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
ocp_index = (addr & 0x0fff) | 0xb000;
ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
+
+ return 0;
}
-static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
+static int ocp_reg_read(struct r8152 *tp, u16 addr, u16 *data)
{
- ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
+ return tp->rtl_ops.phy_read(tp, addr, data);
}
-static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+static int ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
{
- return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
+ return tp->rtl_ops.phy_write(tp, addr, data);
+}
+
+static inline int r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
+{
+ return ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
+}
+
+static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
+{
+ u16 data;
+ int ret;
+
+ ret = ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2, &data);
+
+ return ret < 0 ? ret : data;
}
static int wait_cmd_ready(struct r8152 *tp, u16 cmd)
@@ -1780,16 +1831,32 @@ static int rtl_ip_set_bits(struct r8152 *tp, u16 addr, u32 set)
return rtl_ip_w0w1(tp, addr, 0, set);
}
-static void sram_write(struct r8152 *tp, u16 addr, u16 data)
+static int sram_write(struct r8152 *tp, u16 addr, u16 data)
{
- ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
- ocp_reg_write(tp, OCP_SRAM_DATA, data);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_write(tp, OCP_SRAM_DATA, data);
+
+out:
+ return ret;
}
-static u16 sram_read(struct r8152 *tp, u16 addr)
+static int sram_read(struct r8152 *tp, u16 addr, u16 *data)
{
- ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
- return ocp_reg_read(tp, OCP_SRAM_DATA);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_read(tp, OCP_SRAM_DATA, data);
+
+out:
+ return ret;
}
static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
@@ -1894,90 +1961,219 @@ static void ocp_byte_set_bits(struct r8152 *tp, u16 type, u16 index, u8 set)
ocp_byte_w0w1(tp, type, index, 0, set);
}
-static void ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
+static int ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
{
u16 data;
+ int ret;
+
+ ret = ocp_reg_read(tp, addr, &data);
+ if (ret < 0)
+ goto out;
- data = ocp_reg_read(tp, addr);
data = (data & ~clear) | set;
- ocp_reg_write(tp, addr, data);
+ ret = ocp_reg_write(tp, addr, data);
+
+out:
+ return ret;
}
-static void ocp_reg_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
+static int ocp_reg_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
{
- ocp_reg_w0w1(tp, addr, clear, 0);
+ return ocp_reg_w0w1(tp, addr, clear, 0);
}
-static void ocp_reg_set_bits(struct r8152 *tp, u16 addr, u16 set)
+static int ocp_reg_set_bits(struct r8152 *tp, u16 addr, u16 set)
{
- ocp_reg_w0w1(tp, addr, 0, set);
+ return ocp_reg_w0w1(tp, addr, 0, set);
}
-static void sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
+static int sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
{
u16 data;
+ int ret;
+
+ ret = sram_read(tp, addr, &data);
+ if (ret < 0)
+ goto out;
- data = sram_read(tp, addr);
data = (data & ~clear) | set;
- ocp_reg_write(tp, OCP_SRAM_DATA, data);
+ ret = ocp_reg_write(tp, OCP_SRAM_DATA, data);
+
+out:
+ return ret;
}
-static void sram_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
+static int sram_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
{
- sram_write_w0w1(tp, addr, clear, 0);
+ return sram_write_w0w1(tp, addr, clear, 0);
}
-static void sram_set_bits(struct r8152 *tp, u16 addr, u16 set)
+static int sram_set_bits(struct r8152 *tp, u16 addr, u16 set)
{
- sram_write_w0w1(tp, addr, 0, set);
+ return sram_write_w0w1(tp, addr, 0, set);
}
-static void sram2_write(struct r8152 *tp, u16 addr, u16 data)
+static int sram2_write(struct r8152 *tp, u16 addr, u16 data)
{
- ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
- ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+
+out:
+ return ret;
}
-static u16 sram2_read(struct r8152 *tp, u16 addr)
+static int sram2_read(struct r8152 *tp, u16 addr, u16 *data)
{
- ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
- return ocp_reg_read(tp, OCP_SRAM2_DATA);
+ int ret;
+
+ ret = ocp_reg_write(tp, OCP_SRAM2_ADDR, addr);
+ if (ret < 0)
+ goto out;
+
+ ret = ocp_reg_read(tp, OCP_SRAM2_DATA, data);
+
+out:
+ return ret;
}
-static void sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
+static int sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)
{
u16 data;
+ int ret;
+
+ ret = sram2_read(tp, addr, &data);
+ if (ret < 0)
+ goto out;
- data = sram2_read(tp, addr);
data = (data & ~clear) | set;
- ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+ ret = ocp_reg_write(tp, OCP_SRAM2_DATA, data);
+
+out:
+ return ret;
}
-static void r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)
+static int sram2_set_bits(struct r8152 *tp, u16 addr, u16 set)
+{
+ return sram2_write_w0w1(tp, addr, 0, set);
+}
+
+static int sram2_clr_bits(struct r8152 *tp, u16 addr, u16 clear)
+{
+ return sram2_write_w0w1(tp, addr, clear, 0);
+}
+
+static int r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)
{
int data;
data = r8152_mdio_read(tp, addr);
- r8152_mdio_write(tp, addr, data & ~clear);
+ if (data < 0)
+ goto out;
+
+ data = r8152_mdio_write(tp, addr, data & ~clear);
+
+out:
+ return data;
}
-static void r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)
+static int r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)
{
int data;
data = r8152_mdio_read(tp, addr);
- r8152_mdio_write(tp, addr, data | set);
+ if (data < 0)
+ goto out;
+
+ data = r8152_mdio_write(tp, addr, data | set);
+
+out:
+ return data;
}
static int r8152_mdio_test_and_clr_bit(struct r8152 *tp, u16 addr, u16 clear)
{
- int data;
+ int data, ret;
- data = r8152_mdio_read(tp, addr);
- if (data & clear)
- r8152_mdio_write(tp, addr, data & ~clear);
+ ret = r8152_mdio_read(tp, addr);
+ if (ret < 0)
+ goto out;
+
+ data = ret;
+ if (data & clear) {
+ ret = r8152_mdio_write(tp, addr, data & ~clear);
+ if (ret < 0)
+ goto out;
+ }
+
+ ret = !!(data & clear);
+
+out:
+ return ret;
+}
+
+static int wait_tgphy_cmd_ready(struct r8152 *tp)
+{
+ u16 ocp_data;
+ int ret;
+
+ ret = read_poll_timeout(ocp_read_word, ocp_data,
+ test_bit(RTL8152_INACCESSIBLE, &tp->flags) ||
+ !(ocp_data & TGPHY_CMD_BUSY),
+ 2000, 20000, false, tp,
+ MCU_TYPE_USB, USB_TGPHY_CMD);
+
+ if (ret) {
+ rtl_set_inaccessible(tp);
+ dev_err(&tp->intf->dev, "TGPHY cmd busy timeout\n");
+ }
+
+ return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : ret;
+}
+
+static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data, bool write)
+{
+ u16 cmd = 0;
+ int ret;
+
+ ret = wait_tgphy_cmd_ready(tp);
+ if (ret < 0)
+ goto out;
+
+ if (write) {
+ cmd |= TGPHY_CMD_WR;
+ ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA, *data);
+ }
+
+ ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_ADDR, addr);
+
+ cmd |= TGPHY_CMD_BUSY;
+ ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_CMD, cmd);
+
+ if (!write) {
+ ret = wait_tgphy_cmd_ready(tp);
+ if (ret < 0)
+ goto out;
+
+ *data = ocp_read_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA);
+ }
+
+out:
+ return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : ret;
+}
+
+static int r8157_phy_read(struct r8152 *tp, u16 addr, u16 *data)
+{
+ return rtl_tgphy_access(tp, addr, data, false);
+}
- return data & clear;
+static int r8157_phy_write(struct r8152 *tp, u16 addr, u16 data)
+{
+ return rtl_tgphy_access(tp, addr, &data, true);
}
static int
@@ -3412,7 +3608,8 @@ static void rtl8152_nic_reset(struct r8152 *tp)
break;
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_CR, CR_RE | CR_TE);
break;
@@ -3452,7 +3649,7 @@ static void rtl_eee_plus_en(struct r8152 *tp, bool enable)
static void rtl_set_eee_plus(struct r8152 *tp)
{
- if (tp->version == RTL_VER_17)
+ if (tp->version == RTL_VER_17_QFN68 || tp->version == RTL_VER_17_QFN100)
return rtl_eee_plus_en(tp, false);
if (rtl8152_get_speed(tp) & _10bps)
@@ -3640,7 +3837,8 @@ static void r8153_set_rx_early_timeout(struct r8152 *tp)
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,
640 / 8);
ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,
@@ -3685,7 +3883,8 @@ static void r8153_set_rx_early_size(struct r8152 *tp)
ocp_data / 8);
break;
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
ocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,
ocp_data / 16);
break;
@@ -3801,6 +4000,8 @@ static void rtl_rx_vlan_en(struct r8152 *tp, bool enable)
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
if (enable)
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_RCR1,
@@ -4051,8 +4252,27 @@ static void r8156_ups_flags(struct r8152 *tp)
if (tp->ups_info.aldps)
ups_flags |= UPS_FLAGS_EN_ALDPS;
- if (tp->ups_info.eee)
- ups_flags |= UPS_FLAGS_EN_EEE;
+ if (tp->ups_info.eee) {
+ switch (tp->version) {
+ case RTL_VER_17_QFN68:
+ if (tp->eee_adv & MDIO_EEE_10GT)
+ ups_flags |= UPS_FLAGS_EN_10G_EEE;
+ fallthrough;
+ case RTL_VER_16:
+ if (tp->eee_adv & MDIO_EEE_100TX)
+ ups_flags |= UPS_FLAGS_EN_100M_EEE;
+ if (tp->eee_adv & MDIO_EEE_1000T)
+ ups_flags |= UPS_FLAGS_EN_1000M_EEE;
+ if (tp->eee_adv2 & MDIO_EEE_2_5GT)
+ ups_flags |= UPS_FLAGS_EN_2500M_EEE;
+ if (tp->eee_adv2 & MDIO_EEE_5GT)
+ ups_flags |= UPS_FLAGS_EN_5000M_EEE;
+ break;
+ default:
+ ups_flags |= UPS_FLAGS_EN_EEE;
+ break;
+ }
+ }
if (tp->ups_info.flow_control)
ups_flags |= UPS_FLAGS_EN_FLOW_CTR;
@@ -4103,20 +4323,33 @@ static void r8156_ups_flags(struct r8152 *tp)
case NWAY_2500M_FULL:
ups_flags |= ups_flags_speed(9);
break;
+ case NWAY_5000M_FULL:
+ ups_flags |= ups_flags_speed(10);
+ break;
+ case NWAY_10000M_FULL:
+ ups_flags |= ups_flags_speed(11);
+ break;
default:
break;
}
- switch (tp->ups_info.lite_mode) {
- case 1:
- ups_flags |= 0 << 5;
- break;
- case 2:
- ups_flags |= 2 << 5;
+ switch (tp->version) {
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
break;
- case 0:
default:
- ups_flags |= 1 << 5;
+ switch (tp->ups_info.lite_mode) {
+ case 1:
+ ups_flags |= 0 << 5;
+ break;
+ case 2:
+ ups_flags |= 2 << 5;
+ break;
+ case 0:
+ default:
+ ups_flags |= 1 << 5;
+ break;
+ }
break;
}
@@ -4150,11 +4383,13 @@ static void r8153b_green_en(struct r8152 *tp, bool enable)
static u16 r8153_phy_status(struct r8152 *tp, u16 desired)
{
- u16 data;
+ u16 data = 0;
int i;
for (i = 0; i < 500; i++) {
- data = ocp_reg_read(tp, OCP_PHY_STATUS);
+ if (ocp_reg_read(tp, OCP_PHY_STATUS, &data) < 0)
+ break;
+
data &= PHY_STAT_MASK;
if (desired) {
if (data == desired)
@@ -4172,6 +4407,23 @@ static u16 r8153_phy_status(struct r8152 *tp, u16 desired)
return data;
}
+static int wait_autoload_done(struct r8152 *tp)
+{
+ u16 ocp_data;
+ int ret;
+
+ ret = read_poll_timeout(ocp_read_word, ocp_data,
+ test_bit(RTL8152_INACCESSIBLE, &tp->flags) ||
+ (ocp_data & AUTOLOAD_DONE),
+ 20000, 10 * USEC_PER_SEC, false, tp,
+ MCU_TYPE_PLA, PLA_BOOT_CTRL);
+
+ if (ret)
+ dev_err(&tp->intf->dev, "autoload done timeout\n");
+
+ return test_bit(RTL8152_INACCESSIBLE, &tp->flags) ? -ENODEV : 0;
+}
+
static void r8153b_ups_en(struct r8152 *tp, bool enable)
{
if (enable) {
@@ -4190,16 +4442,8 @@ static void r8153b_ups_en(struct r8152 *tp, bool enable)
UPS_FORCE_PWR_DOWN);
if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
- int i;
-
- for (i = 0; i < 500; i++) {
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
- msleep(20);
- }
+ if (wait_autoload_done(tp))
+ return;
tp->rtl_ops.hw_phy_cfg(tp);
@@ -4227,16 +4471,8 @@ static void r8153c_ups_en(struct r8152 *tp, bool enable)
UPS_FORCE_PWR_DOWN);
if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
- int i;
-
- for (i = 0; i < 500; i++) {
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
- msleep(20);
- }
+ if (wait_autoload_done(tp))
+ return;
tp->rtl_ops.hw_phy_cfg(tp);
@@ -4288,6 +4524,49 @@ static void r8156_ups_en(struct r8152 *tp, bool enable)
}
}
+static void r8157_ups_en(struct r8152 *tp, bool enable)
+{
+ if (enable) {
+ r8156_ups_flags(tp);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,
+ UPS_EN | USP_PREWAKE | PHASE2_EN);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_MISC_2,
+ UPS_FORCE_PWR_DOWN);
+ } else {
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_POWER_CUT,
+ UPS_EN | USP_PREWAKE);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_MISC_2,
+ UPS_FORCE_PWR_DOWN);
+
+ if (ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0) & PCUT_STATUS) {
+ u32 ocp_data;
+ int ret;
+
+ ret = read_poll_timeout(ocp_read_word, ocp_data,
+ ocp_data & BACKUP_RESTRORE, 200,
+ 20000, false, tp, MCU_TYPE_USB,
+ USB_GPHY_CTRL);
+ if (ret) {
+ rtl_set_inaccessible(tp);
+ dev_err(&tp->intf->dev,
+ "backup-restore timed out\n");
+ return;
+ }
+
+ /* clear USB fw_ver_reg */
+ ocp_write_byte(tp, MCU_TYPE_USB, USB_FW_USB_VER, 0);
+
+ tp->rtl_ops.hw_phy_cfg(tp);
+
+ rtl8152_set_speed(tp, tp->autoneg, tp->speed,
+ tp->duplex, tp->advertising);
+ }
+ }
+}
+
static void r8153_power_cut_en(struct r8152 *tp, bool enable)
{
if (enable)
@@ -4446,9 +4725,28 @@ static void rtl8157_runtime_enable(struct r8152 *tp, bool enable)
r8153b_u1u2en(tp, false);
r8157_u2p3en(tp, false);
rtl_runtime_suspend_enable(tp, true);
+
+ switch (tp->version) {
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ r8157_ups_en(tp, true);
+ break;
+ default:
+ break;
+ }
} else {
r8153_queue_wake(tp, false);
rtl_runtime_suspend_enable(tp, false);
+
+ switch (tp->version) {
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ r8157_ups_en(tp, false);
+ break;
+ default:
+ break;
+ }
+
r8157_u2p3en(tp, true);
if (tp->udev->speed >= USB_SPEED_SUPER)
r8153b_u1u2en(tp, true);
@@ -4480,6 +4778,8 @@ static void r8153_teredo_off(struct r8152 *tp)
case RTL_VER_14:
case RTL_VER_15:
case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
/* The bit 0 ~ 7 are relative with teredo settings. They are
* W1C (write 1 to clear), so set all 1 to disable it.
@@ -4534,7 +4834,8 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type)
break;
case RTL_VER_14:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
ocp_write_word(tp, type, USB_BP2_EN, 0);
bp_num = 16;
@@ -4556,7 +4857,8 @@ static inline void rtl_reset_ocp_base(struct r8152 *tp)
static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)
{
u16 check;
- int i;
+ u16 ocp_data;
+ int i, ret;
if (request) {
ocp_reg_set_bits(tp, OCP_PHY_PATCH_CMD, PATCH_REQUEST);
@@ -4567,25 +4869,29 @@ static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)
}
for (i = 0; wait && i < 5000; i++) {
- u32 ocp_data;
-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return -ENODEV;
usleep_range(1000, 2000);
- ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT);
- if ((ocp_data & PATCH_READY) ^ check)
+ ret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, &ocp_data);
+ if (ret < 0)
+ return ret;
+ else if ((ocp_data & PATCH_READY) ^ check)
break;
}
- if (request && wait &&
- !(ocp_reg_read(tp, OCP_PHY_PATCH_STAT) & PATCH_READY)) {
- dev_err(&tp->intf->dev, "PHY patch request fail\n");
- rtl_phy_patch_request(tp, false, false);
- return -ETIME;
- } else {
- return 0;
+ if (request && wait) {
+ ret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, &ocp_data);
+ if (ret < 0) {
+ return ret;
+ } else if (!(ocp_data & PATCH_READY)) {
+ dev_err(&tp->intf->dev, "PHY patch request fail\n");
+ rtl_phy_patch_request(tp, false, false);
+ return -ETIME;
+ }
}
+
+ return 0;
}
static void rtl_patch_key_set(struct r8152 *tp, u16 key_addr, u16 patch_key)
@@ -4646,7 +4952,8 @@ static bool rtl8152_is_fw_phy_speed_up_ok(struct r8152 *tp, struct fw_phy_speed_
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
default:
break;
}
@@ -5299,10 +5606,14 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,
{
u32 len;
u8 *data;
+ u16 ver;
rtl_reset_ocp_base(tp);
- if (sram_read(tp, SRAM_GPHY_FW_VER) >= __le16_to_cpu(phy->version)) {
+ if (sram_read(tp, SRAM_GPHY_FW_VER, &ver) < 0)
+ return;
+
+ if (ver >= __le16_to_cpu(phy->version)) {
dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n");
return;
}
@@ -5349,7 +5660,8 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,
rtl_phy_patch_request(tp, false, wait);
- if (sram_read(tp, SRAM_GPHY_FW_VER) == __le16_to_cpu(phy->version))
+ if (sram_read(tp, SRAM_GPHY_FW_VER, &ver) >= 0 &&
+ ver == __le16_to_cpu(phy->version))
dev_dbg(&tp->intf->dev, "successfully applied %s\n", phy->info);
else
dev_err(&tp->intf->dev, "ram code speedup mode fail\n");
@@ -5357,14 +5669,17 @@ static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy,
static int rtl8152_fw_phy_ver(struct r8152 *tp, struct fw_phy_ver *phy_ver)
{
- u16 ver_addr, ver;
+ u16 ver_addr, ver, cur_ver;
ver_addr = __le16_to_cpu(phy_ver->ver.addr);
ver = __le16_to_cpu(phy_ver->ver.data);
rtl_reset_ocp_base(tp);
- if (sram_read(tp, ver_addr) >= ver) {
+ if (sram_read(tp, ver_addr, &cur_ver) < 0)
+ return 0;
+
+ if (cur_ver >= ver) {
dev_dbg(&tp->intf->dev, "PHY firmware has been the newest\n");
return 0;
}
@@ -5383,7 +5698,8 @@ static void rtl8152_fw_phy_fixup(struct r8152 *tp, struct fw_phy_fixup *fix)
rtl_reset_ocp_base(tp);
addr = __le16_to_cpu(fix->setting.addr);
- data = ocp_reg_read(tp, addr);
+ if (ocp_reg_read(tp, addr, &data) < 0)
+ return;
switch (__le16_to_cpu(fix->bit_cmd)) {
case FW_FIXUP_AND:
@@ -5687,10 +6003,10 @@ static inline void r8152_mmd_indirect(struct r8152 *tp, u16 dev, u16 reg)
static u16 r8152_mmd_read(struct r8152 *tp, u16 dev, u16 reg)
{
- u16 data;
+ u16 data = 0;
r8152_mmd_indirect(tp, dev, reg);
- data = ocp_reg_read(tp, OCP_EEE_DATA);
+ ocp_reg_read(tp, OCP_EEE_DATA, &data);
ocp_reg_write(tp, OCP_EEE_AR, 0x0000);
return data;
@@ -5755,7 +6071,8 @@ static void r8156_eee_en(struct r8152 *tp, bool enable)
r8153_eee_en(tp, enable);
- config = ocp_reg_read(tp, OCP_EEE_ADV2);
+ if (ocp_reg_read(tp, OCP_EEE_ADV2, &config) < 0)
+ return;
if (enable && (tp->eee_adv2 & MDIO_EEE_2_5GT))
config |= MDIO_EEE_2_5GT;
@@ -5806,7 +6123,8 @@ static void rtl_eee_enable(struct r8152 *tp, bool enable)
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
if (enable) {
r8156_eee_en(tp, true);
ocp_reg_write(tp, OCP_EEE_ADV, tp->eee_adv);
@@ -5961,27 +6279,126 @@ static void r8152b_enter_oob(struct r8152 *tp)
RCR_APM | RCR_AM | RCR_AB);
}
-static int r8153_pre_firmware_1(struct r8152 *tp)
+static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)
{
- int i;
+ int log2_ratio, ratio;
+ u16 num_pause_pkts;
+ u32 ocp_data;
- /* Wait till the WTD timer is ready. It would take at most 104 ms. */
- for (i = 0; i < 104; i++) {
- u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL);
+ switch (tp->version) {
+ case RTL_VER_10:
+ case RTL_VER_11:
+ ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
+ CTRL_TIMER_EN | (1000 / 8));
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return -ENODEV;
- if (!(ocp_data & WTD1_EN))
- break;
- usleep_range(1000, 2000);
- }
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
+ FLOW_CTRL_PATCH_OPT);
- return 0;
-}
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ break;
+ case RTL_VER_12:
+ case RTL_VER_13:
+ case RTL_VER_15:
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
-static int r8153_post_firmware_1(struct r8152 *tp)
-{
- /* set USB_BP_4 to support USB_SPEED_SUPER only */
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);
+
+ /* enable fc timer and set timer to 600 ms. */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
+ CTRL_TIMER_EN | (600 / 8));
+
+ ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL);
+ if (!(ocp_data & DACK_DET_EN))
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
+ FLOW_CTRL_PATCH_2);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ break;
+ case RTL_VER_16:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
+
+ num_pause_pkts = 0xa;
+ ratio = 10000;
+
+ if (speed & _10bps) {
+ ratio /= 10;
+ } else if (speed & _100bps) {
+ ratio /= 100;
+ } else if (speed & _1000bps) {
+ ratio /= 1000;
+ } else if (speed & _2500bps) {
+ ratio /= 2500;
+ } else if (speed & _5000bps) {
+ ratio /= 5000;
+ } else if (speed & _10000bps) {
+ ratio /= 10000;
+ } else {
+ /* No rate bit is set: the link dropped after
+ * the caller checked it, or the PHY reported a
+ * 500 or 1250 Mbit/s sub-rate, which the driver
+ * never advertises. Disarm the limit.
+ */
+ dev_err(&tp->intf->dev, "Unknown link speed\n");
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_EN);
+ break;
+ }
+
+ log2_ratio = ilog2(ratio);
+ num_pause_pkts -= log2_ratio;
+
+ /* Round ratio up to the next power of two if it is
+ * more than halfway there. Floating-point is avoided
+ * by rewriting ratio > 1.5 * 2^log2_ratio as
+ * 2 * ratio > 3 * 2^log2_ratio.
+ */
+ if (2 * ratio > 3 * (1 << log2_ratio))
+ num_pause_pkts--;
+
+ /* At most 2^num_pause_pkts pause packets would be sent.
+ *
+ * 10 Mbit/s -> 2^0
+ * 100 Mbit/s -> 2^3
+ * 1 Gbit/s -> 2^7
+ * 2.5 Gbit/s -> 2^8
+ * 5 Gbit/s -> 2^9
+ * 10 Gbit/s -> 2^10
+ */
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_MASK | PAUSE_LIMIT_EN,
+ num_pause_pkts << 4);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_EN);
+ break;
+ default:
+ break;
+ }
+}
+
+static int r8153_pre_firmware_1(struct r8152 *tp)
+{
+ int i;
+
+ /* Wait till the WTD timer is ready. It would take at most 104 ms. */
+ for (i = 0; i < 104; i++) {
+ u32 ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_WDT1_CTRL);
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return -ENODEV;
+ if (!(ocp_data & WTD1_EN))
+ break;
+ usleep_range(1000, 2000);
+ }
+
+ return 0;
+}
+
+static int r8153_post_firmware_1(struct r8152 *tp)
+{
+ /* set USB_BP_4 to support USB_SPEED_SUPER only */
if (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) & FORCE_SUPER)
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_4, BP4_SUPER_ONLY);
@@ -6210,8 +6627,8 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
* rg_saw_cnt = OCP reg 0xC426 Bit[13:0]
* swr_cnt_1ms_ini = 16000000 / rg_saw_cnt
*/
- ocp_data = ocp_reg_read(tp, 0xc426);
- ocp_data &= 0x3fff;
+ ocp_reg_read(tp, 0xc426, &data);
+ ocp_data = data & 0x3fff;
if (ocp_data) {
u32 swr_cnt_1ms_ini;
@@ -6391,24 +6808,16 @@ static int rtl8156_enable(struct r8152 *tp)
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return -ENODEV;
- if (tp->version < RTL_VER_12)
- r8156_fc_parameter(tp);
-
+ r8156_fc_parameter(tp);
set_tx_qlen(tp);
rtl_set_eee_plus(tp);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_17)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
-
r8153_set_rx_early_timeout(tp);
r8153_set_rx_early_size(tp);
speed = rtl8152_get_speed(tp);
rtl_set_ifg(tp, speed);
- if (tp->version >= RTL_VER_16)
- return rtl_enable(tp);
-
if (speed & _2500bps)
ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
IDLE_SPDWN_EN);
@@ -6416,12 +6825,10 @@ static int rtl8156_enable(struct r8152 *tp)
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
IDLE_SPDWN_EN);
- if (tp->version < RTL_VER_12) {
- if (speed & _1000bps)
- ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11);
- else if (speed & _500bps)
- ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d);
- }
+ if (speed & _1000bps)
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x11);
+ else if (speed & _500bps)
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_TXTWSYS, 0x3d);
if (tp->udev->speed == USB_SPEED_HIGH) {
/* USB 0xb45e[3:0] l1_nyet_hird */
@@ -6446,6 +6853,69 @@ static void rtl8156_disable(struct r8152 *tp)
rtl8153_disable(tp);
}
+static int rtl8156b_enable(struct r8152 *tp)
+{
+ u16 speed;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return -ENODEV;
+
+ set_tx_qlen(tp);
+ rtl_set_eee_plus(tp);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
+
+ r8153_set_rx_early_timeout(tp);
+ r8153_set_rx_early_size(tp);
+
+ speed = rtl8152_get_speed(tp);
+ rtl_set_ifg(tp, speed);
+
+ if (speed & _2500bps)
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
+ IDLE_SPDWN_EN);
+ else
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
+ IDLE_SPDWN_EN);
+
+ if (tp->udev->speed == USB_SPEED_HIGH) {
+ /* USB 0xb45e[3:0] l1_nyet_hird */
+ if (is_flow_control(speed))
+ ocp_word_w0w1(tp, MCU_TYPE_USB, USB_L1_CTRL, 0xf, 0xf);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_USB, USB_L1_CTRL, 0xf, 0x1);
+ }
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ usleep_range(1000, 2000);
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+
+ return rtl_enable(tp);
+}
+
+static int rtl8157_enable(struct r8152 *tp)
+{
+ u16 speed;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return -ENODEV;
+
+ set_tx_qlen(tp);
+ rtl_set_eee_plus(tp);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_RX_AGGR_NUM, RX_AGGR_NUM_MASK);
+
+ r8153_set_rx_early_timeout(tp);
+ r8153_set_rx_early_size(tp);
+
+ speed = rtl8152_get_speed(tp);
+ rtl_fc_pause_pkt_en(tp, speed);
+
+ rtl_set_ifg(tp, speed);
+
+ return rtl_enable(tp);
+}
+
static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
u32 advertising)
{
@@ -6517,7 +6987,11 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
if (!advertising)
return -EINVAL;
- orig = r8152_mdio_read(tp, MII_ADVERTISE);
+ ret = r8152_mdio_read(tp, MII_ADVERTISE);
+ if (ret < 0)
+ goto out;
+
+ orig = ret;
new1 = orig & ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
ADVERTISE_100HALF | ADVERTISE_100FULL);
if (advertising & RTL_ADVERTISED_10_HALF) {
@@ -6544,7 +7018,11 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
}
if (tp->mii.supports_gmii) {
- orig = r8152_mdio_read(tp, MII_CTRL1000);
+ ret = r8152_mdio_read(tp, MII_CTRL1000);
+ if (ret < 0)
+ goto out;
+
+ orig = ret;
new1 = orig & ~(ADVERTISE_1000FULL |
ADVERTISE_1000HALF);
@@ -6558,7 +7036,10 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
}
if (tp->support_2500full || tp->support_5000full || tp->support_10000full) {
- orig = ocp_reg_read(tp, OCP_10GBT_CTRL);
+ ret = ocp_reg_read(tp, OCP_10GBT_CTRL, &orig);
+ if (ret < 0)
+ goto out;
+
new1 = orig & ~(MDIO_AN_10GBT_CTRL_ADV2_5G | MDIO_AN_10GBT_CTRL_ADV5G
| MDIO_AN_10GBT_CTRL_ADV10G);
@@ -6589,20 +7070,23 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
if (test_and_clear_bit(PHY_RESET, &tp->flags))
bmcr |= BMCR_RESET;
- r8152_mdio_write(tp, MII_BMCR, bmcr);
+ ret = r8152_mdio_write(tp, MII_BMCR, bmcr);
+ if (ret < 0)
+ goto out;
if (bmcr & BMCR_RESET) {
int i;
for (i = 0; i < 50; i++) {
msleep(20);
- if ((r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET) == 0)
+ ret = r8152_mdio_read(tp, MII_BMCR);
+ if (ret < 0 || !(ret & BMCR_RESET))
break;
}
}
out:
- return ret;
+ return ret < 0 ? ret : 0;
}
static void rtl8152_up(struct r8152 *tp)
@@ -6806,8 +7290,7 @@ static void rtl8156_up(struct r8152 *tp)
return;
r8153b_u1u2en(tp, false);
- if (tp->version < RTL_VER_16)
- r8153_u2p3en(tp, false);
+ r8153_u2p3en(tp, false);
r8153_aldps_en(tp, false);
rxdy_gated_en(tp, true);
@@ -6820,8 +7303,7 @@ static void rtl8156_up(struct r8152 *tp)
ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
- if (tp->version >= RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));
ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
@@ -6843,11 +7325,11 @@ static void rtl8156_up(struct r8152 *tp)
ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, RXFIFO_FULL_MASK,
0x08);
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, PLA_MCU_SPDWN_EN);
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
+ PLA_MCU_SPDWN_EN);
- if (tp->version < RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,
- RG_PWRDN_EN | ALL_SPEED_OFF);
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,
+ RG_PWRDN_EN | ALL_SPEED_OFF);
ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400);
@@ -6857,10 +7339,19 @@ static void rtl8156_up(struct r8152 *tp)
}
r8153_aldps_en(tp, true);
- if (tp->version < RTL_VER_16)
- r8153_u2p3en(tp, true);
+ r8153_u2p3en(tp, true);
+
+ switch (tp->version) {
+ case RTL_VER_13:
+ case RTL_VER_15:
+ /* Enable Clear_SDR */
+ ocp_word_set_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(15));
+ break;
+ default:
+ break;
+ }
- if (tp->version < RTL_VER_16 && tp->udev->speed >= USB_SPEED_SUPER)
+ if (tp->udev->speed >= USB_SPEED_SUPER)
r8153b_u1u2en(tp, true);
}
@@ -6873,12 +7364,9 @@ static void rtl8156_down(struct r8152 *tp)
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
PLA_MCU_SPDWN_EN);
-
r8153b_u1u2en(tp, false);
- if (tp->version < RTL_VER_16) {
- r8153_u2p3en(tp, false);
- r8153b_power_cut_en(tp, false);
- }
+ r8153_u2p3en(tp, false);
+ r8153b_power_cut_en(tp, false);
r8153_aldps_en(tp, false);
ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
@@ -6900,7 +7388,125 @@ static void rtl8156_down(struct r8152 *tp)
*/
ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff);
- ocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_BDC_CR, ALDPS_PROXY_MODE);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL,
+ NOW_IS_OOB | DIS_MCU_CLROOB);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
+
+ rtl_rx_vlan_en(tp, true);
+ rxdy_gated_en(tp, false);
+
+ ocp_dword_set_bits(tp, MCU_TYPE_PLA, PLA_RCR,
+ RCR_APM | RCR_AM | RCR_AB);
+
+ r8153_aldps_en(tp, true);
+}
+
+static void rtl8157_change_mtu(struct r8152 *tp)
+{
+ u32 max_pkt_size = mtu_to_size(tp->netdev->mtu);
+ u32 ocp_data;
+
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, max_pkt_size);
+
+ /* Use at least 10K for MTPS */
+ ocp_data = max_t(u32, max_pkt_size, 10 * 1024) / 64;
+
+ /* 16 * 1024 / 64 = 0x100, so the max is 0xff for 8 bits data */
+ ocp_data = min_t(u32, ocp_data, 0xff);
+
+ ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, ocp_data);
+ r8156_fc_parameter(tp);
+
+ /* TX share fifo free credit full threshold */
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, 512 / 64);
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_TXFIFO_FULL,
+ ALIGN(max_pkt_size + tp->tx_desc.size, 1024) / 16);
+}
+
+static void rtl8157_up(struct r8152 *tp)
+{
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ r8153b_u1u2en(tp, false);
+ r8153_aldps_en(tp, false);
+
+ rxdy_gated_en(tp, true);
+ r8153_teredo_off(tp);
+
+ ocp_dword_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, RCR_ACPT_ALL);
+
+ rtl8152_nic_reset(tp);
+ rtl_reset_bmu(tp);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR1, BIT(3));
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
+
+ rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX);
+
+ rtl8157_change_mtu(tp);
+
+ /* share FIFO settings */
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, RXFIFO_FULL_MASK,
+ 0x08);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_SPEED_OPTION,
+ RG_PWRDN_EN | ALL_SPEED_OFF);
+
+ ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, 0x00600400);
+
+ if (tp->saved_wolopts != __rtl_get_wol(tp)) {
+ netif_warn(tp, ifup, tp->netdev, "wol setting is changed\n");
+ __rtl_set_wol(tp, tp->saved_wolopts);
+ }
+
+ r8153_aldps_en(tp, true);
+
+ /* Enable Clear_SDR */
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xd378, BIT(7));
+ /* Clear SDR bit */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(15));
+}
+
+static void rtl8157_down(struct r8152 *tp)
+{
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) {
+ rtl_drop_queued_tx(tp);
+ return;
+ }
+
+ r8153b_u1u2en(tp, false);
+ r8153_aldps_en(tp, false);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, NOW_IS_OOB);
+
+ /* RX FIFO settings for OOB */
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_FULL, 64 / 16);
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_FULL, 1024 / 16);
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RX_FIFO_EMPTY, 4096 / 16);
+
+ rtl_disable(tp);
+ rtl_reset_bmu(tp);
+
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1526);
+ ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, 10 * 1024 / 64);
+
+ /* Clear teredo wake event. bit[15:8] is the teredo wakeup
+ * type. Set it to zero. bits[7:0] are the W1C bits about
+ * the events. Set them to all 1 to clear them.
+ */
+ ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_WAKE_BASE, 0x00ff);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_BDC_CR, ALDPS_PROXY_MODE);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_PLA, PLA_OOB_CTRL,
+ NOW_IS_OOB | DIS_MCU_CLROOB);
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, MCU_BORW_EN);
@@ -6931,7 +7537,12 @@ static bool rtl8152_in_nway(struct r8152 *tp)
static bool rtl8153_in_nway(struct r8152 *tp)
{
- u16 phy_state = ocp_reg_read(tp, OCP_PHY_STATE) & 0xff;
+ u16 phy_state;
+
+ if (ocp_reg_read(tp, OCP_PHY_STATE, &phy_state) < 0)
+ return false;
+
+ phy_state &= 0xff;
if (phy_state == TXDIS_STATE || phy_state == ABD_STATE)
return false;
@@ -6947,7 +7558,9 @@ static void r8156_mdio_force_mode(struct r8152 *tp)
* 0: MDIO force mode
* 1: MMD force mode
*/
- data = ocp_reg_read(tp, 0xa5b4);
+ if (ocp_reg_read(tp, 0xa5b4, &data) < 0)
+ return;
+
if (data & BIT(15)) {
data &= ~BIT(15);
ocp_reg_write(tp, 0xa5b4, data);
@@ -7225,22 +7838,14 @@ static void r8152b_init(struct r8152 *tp)
static void r8153_init(struct r8152 *tp)
{
u32 ocp_data;
- int i;
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
r8153_u1u2en(tp, false);
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
-
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- break;
- }
+ if (wait_autoload_done(tp))
+ return;
r8153_phy_status(tp, 0);
@@ -7341,22 +7946,13 @@ static void r8153_init(struct r8152 *tp)
static void r8153b_init(struct r8152 *tp)
{
- int i;
-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
r8153b_u1u2en(tp, false);
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
-
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- break;
- }
+ if (wait_autoload_done(tp))
+ return;
r8153_phy_status(tp, 0);
@@ -7411,8 +8007,6 @@ static void r8153b_init(struct r8152 *tp)
static void r8153c_init(struct r8152 *tp)
{
- int i;
-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
@@ -7425,15 +8019,8 @@ static void r8153c_init(struct r8152 *tp)
ocp_word_set_bits(tp, MCU_TYPE_USB, 0xcbf0, BIT(1));
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
-
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- }
+ if (wait_autoload_done(tp))
+ return;
r8153_phy_status(tp, 0);
@@ -7505,7 +8092,8 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
rtl_eee_enable(tp, false);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- WARN_ON_ONCE(data != PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
@@ -7612,19 +8200,20 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
ocp_reg_clr_bits(tp, 0xa86a, BIT(0));
/* MDI SWAP */
+ ocp_reg_read(tp, 0xd068, &data);
if ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) & MID_REVERSE) &&
- (ocp_reg_read(tp, 0xd068) & BIT(1))) {
+ (data & BIT(1))) {
u16 swap_a, swap_b;
- data = ocp_reg_read(tp, 0xd068);
+ ocp_reg_read(tp, 0xd068, &data);
data &= ~0x1f;
data |= 0x1; /* p0 */
ocp_reg_write(tp, 0xd068, data);
- swap_a = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_a);
data &= ~0x18;
data |= 0x18; /* p3 */
ocp_reg_write(tp, 0xd068, data);
- swap_b = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_b);
data &= ~0x18; /* p0 */
ocp_reg_write(tp, 0xd068, data);
ocp_reg_write(tp, 0xd06a,
@@ -7636,11 +8225,11 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
data &= ~0x18;
data |= 0x08; /* p1 */
ocp_reg_write(tp, 0xd068, data);
- swap_a = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_a);
data &= ~0x18;
data |= 0x10; /* p2 */
ocp_reg_write(tp, 0xd068, data);
- swap_b = ocp_reg_read(tp, 0xd06a);
+ ocp_reg_read(tp, 0xd06a, &swap_b);
data &= ~0x18;
data |= 0x08; /* p1 */
ocp_reg_write(tp, 0xd068, data);
@@ -7651,16 +8240,16 @@ static void r8156_hw_phy_cfg(struct r8152 *tp)
ocp_reg_write(tp, 0xd068, data);
ocp_reg_write(tp, 0xd06a,
(swap_b & ~0x7ff) | (swap_a & 0x7ff));
- swap_a = ocp_reg_read(tp, 0xbd5a);
- swap_b = ocp_reg_read(tp, 0xbd5c);
+ ocp_reg_read(tp, 0xbd5a, &swap_a);
+ ocp_reg_read(tp, 0xbd5c, &swap_b);
ocp_reg_write(tp, 0xbd5a, (swap_a & ~0x1f1f) |
((swap_b & 0x1f) << 8) |
((swap_b >> 8) & 0x1f));
ocp_reg_write(tp, 0xbd5c, (swap_b & ~0x1f1f) |
((swap_a & 0x1f) << 8) |
((swap_a >> 8) & 0x1f));
- swap_a = ocp_reg_read(tp, 0xbc18);
- swap_b = ocp_reg_read(tp, 0xbc1a);
+ ocp_reg_read(tp, 0xbc18, &swap_a);
+ ocp_reg_read(tp, 0xbc1a, &swap_b);
ocp_reg_write(tp, 0xbc18, (swap_a & ~0x1f1f) |
((swap_b & 0x1f) << 8) |
((swap_b >> 8) & 0x1f));
@@ -7740,7 +8329,8 @@ static void r8156b_hw_phy_cfg(struct r8152 *tp)
rtl_eee_enable(tp, false);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- WARN_ON_ONCE(data != PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
@@ -7979,17 +8569,21 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
rtl_eee_enable(tp, false);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- WARN_ON_ONCE(data != PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
/* PFM mode */
ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
/* Advanced Power Saving parameter */
- ocp_reg_set_bits(tp, 0xa430, BIT(0) | BIT(1));
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);
/* Disable ALDPS force mode */
ocp_reg_clr_bits(tp, 0xa44a, BIT(2));
+ /* Disable bypass_turn_off_clk_in_aldps */
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
+
switch (tp->version) {
case RTL_VER_16:
/* XG_INRX parameter */
@@ -8005,7 +8599,7 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x8078, 0xff00, 0x3000);
/* green mode */
- sram2_write_w0w1(tp, 0x89e9, 0xff00, 0);
+ sram2_clr_bits(tp, 0x89e9, 0xff00);
sram2_write_w0w1(tp, 0x8ffd, 0xff00, 0x0100);
sram2_write_w0w1(tp, 0x8ffe, 0xff00, 0x0200);
sram2_write_w0w1(tp, 0x8fff, 0xff00, 0x0400);
@@ -8111,11 +8705,86 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x807c, 0xff00, 0x5000);
sram2_write_w0w1(tp, 0x809d, 0xff00, 0x5000);
break;
+ default:
+ break;
+ }
+
+ if (rtl_phy_patch_request(tp, true, true))
+ return;
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);
+
+ ocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);
+
+ tp->ups_info._10m_ckdiv = true;
+ tp->ups_info.eee_plloff_100 = false;
+ tp->ups_info.eee_plloff_giga = false;
+
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);
+ tp->ups_info.eee_ckdiv = true;
+
+ rtl_phy_patch_request(tp, false, true);
+
+ rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags));
+
+ ocp_reg_clr_bits(tp, 0xa428, BIT(9));
+ ocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1));
+ tp->ups_info.lite_mode = 0;
+
+ if (tp->eee_en)
+ rtl_eee_enable(tp, true);
+
+ r8153_aldps_en(tp, true);
+ r8152b_enable_fc(tp);
+
+ set_bit(PHY_RESET, &tp->flags);
+}
+
+static void r8159_hw_phy_cfg(struct r8152 *tp)
+{
+ u16 data;
+
+ r8156b_wait_loading_flash(tp);
+
+ ocp_word_test_and_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);
+
+ data = r8153_phy_status(tp, 0);
+ switch (data) {
+ case PHY_STAT_EXT_INIT:
+ rtl8152_apply_firmware(tp, true);
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+ break;
+ case PHY_STAT_LAN_ON:
+ case PHY_STAT_PWRDN:
+ default:
+ rtl8152_apply_firmware(tp, false);
+ break;
+ }
+
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
- case RTL_VER_17:
- /* Disable bypass turn off clk in ALDPS */
- ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
+ r8153_aldps_en(tp, false);
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
+ WARN_ON_ONCE(data != PHY_STAT_LAN_ON &&
+ !test_bit(RTL8152_INACCESSIBLE, &tp->flags));
+
+ /* PFM mode */
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);
+
+ /* Advanced Power Saving parameter */
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);
+
+ /* Disable ALDPS force mode */
+ ocp_reg_clr_bits(tp, 0xa44a, BIT(2));
+
+ /* Disable bypass_turn_off_clk_in_aldps */
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));
+
+ switch (tp->version) {
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
/* Power level tuning
* test mode power level
*/
@@ -8125,22 +8794,35 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram_write_w0w1(tp, 0x81ae, 0xff00, 0x0f00);
sram_write_w0w1(tp, 0x81b9, 0xff00, 0xb900);
/* normal link TX filter */
- sram2_write_w0w1(tp, 0x83b0, 0x0e00, 0);
- sram2_write_w0w1(tp, 0x83c5, 0x0e00, 0);
- sram2_write_w0w1(tp, 0x83da, 0x0e00, 0);
- sram2_write_w0w1(tp, 0x83ef, 0x0e00, 0);
+ sram2_clr_bits(tp, 0x83b0, 0x0e00);
+ sram2_clr_bits(tp, 0x83c5, 0x0e00);
+ sram2_clr_bits(tp, 0x83da, 0x0e00);
+ sram2_clr_bits(tp, 0x83ef, 0x0e00);
+
+ ocp_reg_w0w1(tp, 0xbf38, 0x01f0, 0x0160);
+ ocp_reg_w0w1(tp, 0xbf3a, 0x001f, 0x0014);
+ /* shorten CLKS latency */
+ ocp_reg_clr_bits(tp, 0xbf28, BIT(14) | BIT(13));
+ ocp_reg_clr_bits(tp, 0xbf2c, BIT(15) | BIT(14));
+ /* CMP_Timer on MP_Timer=333
+ * GPHY OCP 0xbf28 bit[0] = 0x1
+ * GPHY OCP 0xbf28 bit[6:1] = 0x3
+ * GPHY OCP 0xbf28 bit[12:7] = 0x3
+ */
+ ocp_reg_w0w1(tp, 0xbf28, 0x1fff, 0x0187);
+ ocp_reg_w0w1(tp, 0xbf2a, 0x3f, 0x03);
/* AFE power saving for 2.5G & 5G */
sram_write(tp, 0x8173, 0x8620);
sram_write(tp, 0x8175, 0x8671);
- sram_write_w0w1(tp, 0x817c, 0, BIT(13));
- sram_write_w0w1(tp, 0x8187, 0, BIT(13));
- sram_write_w0w1(tp, 0x8192, 0, BIT(13));
- sram_write_w0w1(tp, 0x819d, 0, BIT(13));
- sram_write_w0w1(tp, 0x81a8, BIT(13), 0);
- sram_write_w0w1(tp, 0x81b3, BIT(13), 0);
- sram_write_w0w1(tp, 0x81be, 0, BIT(13));
+ sram_set_bits(tp, 0x817c, BIT(13));
+ sram_set_bits(tp, 0x8187, BIT(13));
+ sram_set_bits(tp, 0x8192, BIT(13));
+ sram_set_bits(tp, 0x819d, BIT(13));
+ sram_clr_bits(tp, 0x81a8, BIT(13));
+ sram_clr_bits(tp, 0x81b3, BIT(13));
+ sram_set_bits(tp, 0x81be, BIT(13));
sram_write_w0w1(tp, 0x817d, 0xff00, 0xa600);
sram_write_w0w1(tp, 0x8188, 0xff00, 0xa600);
@@ -8204,10 +8886,10 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x84b2, 0xff00, 0x6000);
/* Training AAGC PAR (with uc2 patch) */
sram2_write(tp, 0x8ffc, 0x6008);
- sram2_write(tp, 0x8ffe, 0xf450);
+ sram2_write(tp, 0x8ffe, 0xf4ff);
/* DAC BGK */
- sram2_write_w0w1(tp, 0x8015, 0, BIT(9));
- sram2_write_w0w1(tp, 0x8016, 0, BIT(11));
+ sram2_set_bits(tp, 0x8015, BIT(9));
+ sram2_set_bits(tp, 0x8016, BIT(11));
sram2_write_w0w1(tp, 0x8fe6, 0xff00, 0x0800);
sram2_write(tp, 0x8fe4, 0x2114);
/* 10G PBO table */
@@ -8216,14 +8898,14 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
sram2_write_w0w1(tp, 0x864b, 0xff00, 0xdc00);
/* 2.5G ado power window size */
sram2_write_w0w1(tp, 0x8154, 0xc000, 0x4000);
- sram2_write_w0w1(tp, 0x8158, 0xc000, 0);
+ sram2_clr_bits(tp, 0x8158, 0xc000);
/* 10G lock far */
sram2_write(tp, 0x826c, 0xffff);
sram2_write(tp, 0x826e, 0xffff);
/* XG INRX parameter */
sram2_write_w0w1(tp, 0x8872, 0xff00, 0x0e00);
- sram_write_w0w1(tp, 0x8012, 0, BIT(11));
- sram_write_w0w1(tp, 0x8012, 0, BIT(14));
+ sram_set_bits(tp, 0x8012, BIT(11));
+ sram_set_bits(tp, 0x8012, BIT(14));
ocp_reg_set_bits(tp, 0xb576, BIT(0));
sram_write_w0w1(tp, 0x834a, 0xff00, 0x0700);
sram2_write_w0w1(tp, 0x8217, 0x3f00, 0x2a00);
@@ -8234,100 +8916,373 @@ static void r8157_hw_phy_cfg(struct r8152 *tp)
/* improve UBE */
ocp_reg_set_bits(tp, 0xbf0c, 0x7 << 11);
/* close Sparse NEC, improve connect 5EUU cable performance */
- sram2_write_w0w1(tp, 0x88de, 0xff00, 0);
+ sram2_clr_bits(tp, 0x88de, 0xff00);
/* 5G slave compatibility issue */
sram2_write(tp, 0x80b4, 0x5195);
- /* XG Test Mode
- * xgtstm_map_tbl for mdi_cap_sel
- */
- sram_write(tp, 0x8370, 0x8671);
- sram_write(tp, 0x8372, 0x86c8);
- /* xgtstm_amp_map_tbl for REG_IBX_UP_SHIFT_L */
- sram_write(tp, 0x8401, 0x86c8);
- sram_write(tp, 0x8403, 0x86da);
- sram_write_w0w1(tp, 0x8406, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8408, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x840a, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x840c, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x840e, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8410, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8412, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8414, 0x1800, 0x1000);
- sram_write_w0w1(tp, 0x8416, 0x1800, 0x1000);
+ /* XG Test Mode
+ * xgtstm_map_tbl for mdi_cap_sel
+ */
+ sram_write(tp, 0x8370, 0x8671);
+ sram_write(tp, 0x8372, 0x86c8);
+ /* xgtstm_amp_map_tbl for REG_IBX_UP_SHIFT_L */
+ sram_write(tp, 0x8401, 0x86c8);
+ sram_write(tp, 0x8403, 0x86da);
+ sram_write_w0w1(tp, 0x8406, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8408, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x840a, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x840c, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x840e, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8410, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8412, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8414, 0x1800, 0x1000);
+ sram_write_w0w1(tp, 0x8416, 0x1800, 0x1000);
+
+ /* Cable Test Patch */
+ sram_write(tp, 0x82bd, 0x1f40);
+
+ /* Thermal sensor parameters */
+ ocp_reg_w0w1(tp, 0xbfb4, 0x07ff, 0x0328);
+ ocp_reg_write(tp, 0xbfb6, 0x3e14);
+
+ /* spdchg_gtx_shape_100M */
+ ocp_reg_write(tp, OCP_SRAM_ADDR, 0x81c4);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x003b);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0086);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00b7);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00db);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x00c3);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0078);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0047);
+ ocp_reg_write(tp, OCP_SRAM_DATA, 0x0023);
+
+ /* lsbmsk_parameters
+ * RL6961_lsbmsk_parameter_250207
+ */
+ sram2_write(tp, 0x88d7, 0x01a0);
+ sram2_write(tp, 0x88d9, 0x01a0);
+ sram2_write(tp, 0x8ffa, 0x002a);
+
+ sram2_write(tp, 0x8fee, 0xffdf);
+ sram2_write(tp, 0x8ff0, 0xffff);
+ sram2_write(tp, 0x8ff2, 0x0a4a);
+ sram2_write(tp, 0x8ff4, 0xaa5a);
+ sram2_write(tp, 0x8ff6, 0x0a4a);
+ sram2_write(tp, 0x8ff8, 0xaa5a);
+
+ sram2_write_w0w1(tp, 0x88d5, 0xff00, 0x0200);
+
+ /* spdchg_pga1_lpf_cap */
+ sram_write_w0w1(tp, 0x84bb, 0xff00, 0x0a00);
+ sram_write_w0w1(tp, 0x84c0, 0xff00, 0x1600);
+
+ /* ENET PLL jitter improvement */
+ ocp_reg_w0w1(tp, 0xbf8a, 0xfc00, 0x2000);
+ ocp_reg_set_bits(tp, 0xbf88, BIT(2));
+ break;
+ default:
+ break;
+ }
+
+ if (rtl_phy_patch_request(tp, true, true))
+ return;
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);
+
+ ocp_reg_clr_bits(tp, OCP_DOWN_SPEED,
+ EN_EEE_100 | EN_EEE_1000 | EN_10M_CLKDIV);
+ tp->ups_info._10m_ckdiv = false;
+ tp->ups_info.eee_plloff_100 = false;
+ tp->ups_info.eee_plloff_giga = false;
+
+ ocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);
+ tp->ups_info.eee_ckdiv = true;
+
+ rtl_phy_patch_request(tp, false, true);
+
+ rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags));
+
+ ocp_reg_clr_bits(tp, 0xa428, BIT(9));
+ ocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1) | BIT(2));
+ tp->ups_info.lite_mode = 0;
+
+ if (tp->eee_en)
+ rtl_eee_enable(tp, true);
+
+ r8153_aldps_en(tp, true);
+ r8152b_enable_fc(tp);
+
+ set_bit(PHY_RESET, &tp->flags);
+}
+
+static void r8156_init(struct r8152 *tp)
+{
+ u16 data;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
+
+ ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
+
+ r8153b_u1u2en(tp, false);
+
+ if (wait_autoload_done(tp))
+ return;
+
+ data = r8153_phy_status(tp, 0);
+ if (data == PHY_STAT_EXT_INIT)
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
+
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
+
+ r8153_u2p3en(tp, false);
+
+ /* MSC timer = 0xfff * 8ms = 32760 ms */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
+
+ /* U1/U2/L1 idle timer. 500 us */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
+
+ r8153b_power_cut_en(tp, false);
+ r8156_ups_en(tp, false);
+ r8153_queue_wake(tp, false);
+ rtl_runtime_suspend_enable(tp, false);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
+
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
+
+ usb_enable_lpm(tp->udev);
+
+ rtl_fc_pause_pkt_en(tp, 0);
+
+ r8156_mac_clk_spd(tp, true);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
+ PLA_MCU_SPDWN_EN);
+
+ if (rtl8152_get_speed(tp) & LINK_STATUS)
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, CUR_LINK_OK,
+ POLL_LINK_CHG);
+
+ set_bit(GREEN_ETHERNET, &tp->flags);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_ZERO_EN);
+
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ACT_ODMA);
+
+ r8156_mdio_force_mode(tp);
+ rtl_tally_reset(tp);
+
+ tp->coalesce = 15000; /* 15 us */
+}
+
+static void r8156b_u2phy_backup(struct r8152 *tp)
+{
+ ocp_write_word(tp, MCU_TYPE_USB, 0xd3ce, 0x181b);
+ ocp_write_dword(tp, MCU_TYPE_USB, 0xd3d0, 0x616ccd99);
+ ocp_write_dword(tp, MCU_TYPE_USB, 0xd3d4, 0x08fc8101);
+ ocp_write_dword(tp, MCU_TYPE_USB, 0xd3d8, 0x159b1100);
+ ocp_write_word(tp, MCU_TYPE_USB, 0xd3dc, 0x0a00);
+}
+
+static void r8156b_init(struct r8152 *tp)
+{
+ u16 data;
+
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
+
+ ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_U2P3_CTRL, RX_DETECT8);
+
+ r8153b_u1u2en(tp, false);
+
+ switch (tp->version) {
+ case RTL_VER_13:
+ case RTL_VER_15:
+ r8156b_wait_loading_flash(tp);
+ break;
+ default:
+ break;
+ }
+
+ if (wait_autoload_done(tp))
+ return;
+
+ data = r8153_phy_status(tp, 0);
+ if (data == PHY_STAT_EXT_INIT) {
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ }
+
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
+
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
+
+ r8153_u2p3en(tp, false);
+
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
+
+ /* MSC timer = 0xfff * 8ms = 32760 ms */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
+
+ /* U1/U2/L1 idle timer. 500 us */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
+
+ r8156b_u2phy_backup(tp);
+
+ r8153b_power_cut_en(tp, false);
+ r8156_ups_en(tp, false);
+ r8153_queue_wake(tp, false);
+ rtl_runtime_suspend_enable(tp, false);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
+
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
+
+ usb_enable_lpm(tp->udev);
+
+ rtl_fc_pause_pkt_en(tp, 0);
+
+ r8156_mac_clk_spd(tp, true);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
+ PLA_MCU_SPDWN_EN);
+
+ if (rtl8152_get_speed(tp) & LINK_STATUS)
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK, POLL_LINK_CHG);
+
+ set_bit(GREEN_ETHERNET, &tp->flags);
+
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_ZERO_EN);
+
+ r8156_mdio_force_mode(tp);
+ rtl_tally_reset(tp);
+
+ tp->coalesce = 15000; /* 15 us */
+}
- /* Cable Test Patch */
- sram_write(tp, 0x82bd, 0x1f40);
+static void r8157_init(struct r8152 *tp)
+{
+ u16 data;
- /* Thermal sensor parameters */
- ocp_reg_w0w1(tp, 0xbfb4, 0x07ff, 0x0328);
- ocp_reg_write(tp, 0xbfb6, 0x3e14);
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
- /* spdchg_gtx_shape_100M */
- ocp_reg_write(tp, OCP_SRAM_ADDR, 0x81c4);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x003b);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0086);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00b7);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00db);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00fe);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x00c3);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0078);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0047);
- ocp_reg_write(tp, OCP_SRAM_DATA, 0x0023);
+ /* Enable SW reset */
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));
- /* lsbmsk_parameters
- * RL6961_lsbmsk_parameter_250207
- */
- sram2_write(tp, 0x88d7, 0x01a0);
- sram2_write(tp, 0x88d9, 0x01a0);
- sram2_write(tp, 0x8ffa, 0x002a);
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
- sram2_write(tp, 0x8fee, 0xffdf);
- sram2_write(tp, 0x8ff0, 0xffff);
- sram2_write(tp, 0x8ff2, 0x0a4a);
- sram2_write(tp, 0x8ff4, 0xaa5a);
- sram2_write(tp, 0x8ff6, 0x0a4a);
- sram2_write(tp, 0x8ff8, 0xaa5a);
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
- sram2_write_w0w1(tp, 0x88d5, 0xff00, 0x0200);
- break;
+ r8153b_u1u2en(tp, false);
- default:
- break;
- }
+ r8156b_wait_loading_flash(tp);
- if (rtl_phy_patch_request(tp, true, true))
+ if (wait_autoload_done(tp))
return;
- ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);
+ data = r8153_phy_status(tp, 0);
+ if (data == PHY_STAT_EXT_INIT) {
+ ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ }
- ocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
- tp->ups_info._10m_ckdiv = true;
- tp->ups_info.eee_plloff_100 = false;
- tp->ups_info.eee_plloff_giga = false;
+ data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- ocp_reg_set_bits(tp, OCP_POWER_CFG, EEE_CLKDIV_EN);
- tp->ups_info.eee_ckdiv = true;
+ r8157_u2p3en(tp, false);
- rtl_phy_patch_request(tp, false, true);
+ /* Disable Interrupt Mitigation */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,
+ BIT(0) | BIT(1) | BIT(2) | BIT(7));
- rtl_green_en(tp, test_bit(GREEN_ETHERNET, &tp->flags));
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
- ocp_reg_clr_bits(tp, 0xa428, BIT(9));
- ocp_reg_clr_bits(tp, 0xa5ea, BIT(0) | BIT(1));
- tp->ups_info.lite_mode = 0;
+ /* MSC timer = 0xfff * 8ms = 32760 ms */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
- if (tp->eee_en)
- rtl_eee_enable(tp, true);
+ /* U1/U2/L1 idle timer. 500 us */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
- r8153_aldps_en(tp, true);
- r8152b_enable_fc(tp);
+ r8157_power_cut_en(tp, false);
+ r8157_ups_en(tp, false);
+ r8153_queue_wake(tp, false);
+ rtl_runtime_suspend_enable(tp, false);
- set_bit(PHY_RESET, &tp->flags);
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
+
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
+
+ /* Clear Warm RST / Bus RST event flag */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));
+
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
+
+ usb_enable_lpm(tp->udev);
+
+ r8156_mac_clk_spd(tp, true);
+
+ if (rtl8152_get_speed(tp) & LINK_STATUS)
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
+ else
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK, POLL_LINK_CHG);
+
+ set_bit(GREEN_ETHERNET, &tp->flags);
+
+ /* RX aggregation / 16 bytes RX descriptor / Bulk In End transfer */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_DESC_16B | RX_END_TRANSFER_EN);
+
+ /* Disable Rx Zero Len */
+ rtl_bmu_clr_bits(tp, 0x2300, BIT(3));
+
+ /* TX descriptor Signature */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
+
+ r8156_mdio_force_mode(tp);
+ rtl_tally_reset(tp);
+
+ tp->coalesce = 15000; /* 15 us */
}
static int r8159_wait_backup_restore(struct r8152 *tp)
@@ -8342,78 +9297,53 @@ static int r8159_wait_backup_restore(struct r8152 *tp)
ocp_data & BACKUP_RESTRORE, 200, 20000, false);
}
-static void r8156_init(struct r8152 *tp)
+static void r8159_init(struct r8152 *tp)
{
- u32 ocp_data;
u16 data;
- int i;
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return;
- if (tp->version == RTL_VER_16 || tp->version == RTL_VER_17) {
- ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));
- ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));
- }
+ /* Enable SW reset */
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xcffe, BIT(3));
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd3ca, BIT(0));
ocp_byte_clr_bits(tp, MCU_TYPE_USB, USB_ECM_OP, EN_ALL_SPEED);
- if (tp->version < RTL_VER_16)
- ocp_write_word(tp, MCU_TYPE_USB, USB_SPEED_OPTION, 0);
-
ocp_word_set_bits(tp, MCU_TYPE_USB, USB_ECM_OPTION, BYPASS_MAC_RESET);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15)
- ocp_word_set_bits(tp, MCU_TYPE_USB, USB_U2P3_CTRL, RX_DETECT8);
-
r8153b_u1u2en(tp, false);
- switch (tp->version) {
- case RTL_VER_13:
- case RTL_VER_15:
- case RTL_VER_16:
- case RTL_VER_17:
- r8156b_wait_loading_flash(tp);
- break;
- default:
- break;
- }
-
- for (i = 0; i < 500; i++) {
- if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
- AUTOLOAD_DONE)
- break;
+ r8156b_wait_loading_flash(tp);
- msleep(20);
- if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
- return;
- }
+ if (wait_autoload_done(tp))
+ return;
- if (tp->version == RTL_VER_17 && r8159_wait_backup_restore(tp)) {
+ if (r8159_wait_backup_restore(tp)) {
rtl_set_inaccessible(tp);
- dev_err(&tp->intf->dev, "init failed, backup-restore timed out\n");
+ dev_err(&tp->intf->dev,
+ "init failed, backup-restore timed out\n");
return;
}
data = r8153_phy_status(tp, 0);
if (data == PHY_STAT_EXT_INIT) {
ocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));
- if (tp->version >= RTL_VER_12)
- ocp_reg_clr_bits(tp, 0xa466, BIT(0));
+ ocp_reg_clr_bits(tp, 0xa466, BIT(0));
}
- data = r8152_mdio_read(tp, MII_BMCR);
- if (data & BMCR_PDOWN) {
- data &= ~BMCR_PDOWN;
- r8152_mdio_write(tp, MII_BMCR, data);
- }
+ r8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
- if (tp->version >= RTL_VER_16)
- r8157_u2p3en(tp, false);
- else
- r8153_u2p3en(tp, false);
+ r8157_u2p3en(tp, false);
+
+ /* Disable Interrupt Mitigation */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,
+ BIT(0) | BIT(1) | BIT(2) | BIT(7));
+
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
/* MSC timer = 0xfff * 8ms = 32760 ms */
ocp_write_word(tp, MCU_TYPE_USB, USB_MSC_TIMER, 0x0fff);
@@ -8421,72 +9351,53 @@ static void r8156_init(struct r8152 *tp)
/* U1/U2/L1 idle timer. 500 us */
ocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);
- if (tp->version >= RTL_VER_16)
- r8157_power_cut_en(tp, false);
- else
- r8153b_power_cut_en(tp, false);
-
- r8156_ups_en(tp, false);
+ r8157_power_cut_en(tp, false);
+ r8157_ups_en(tp, false);
r8153_queue_wake(tp, false);
rtl_runtime_suspend_enable(tp, false);
- if (tp->udev->speed >= USB_SPEED_SUPER)
- r8153b_u1u2en(tp, true);
-
- usb_enable_lpm(tp->udev);
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_INDICATE_FALG, PREBOOT_OPTION);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15) {
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
+ ocp_byte_clr_bits(tp, MCU_TYPE_PLA, PLA_RMT_WAKE, RMT_WAKE_EN);
- ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);
+ /* Clear Warm RST / Bus RST event flag */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, 0xcd06, BIT(11));
- /* enable fc timer and set timer to 600 ms. */
- ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, CTRL_TIMER_EN | (600 / 8));
+ /* Disable FW u1u2 patch option */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xb9a6, BIT(0));
- ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL);
- if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & DACK_DET_EN))
- ocp_data |= FLOW_CTRL_PATCH_2;
- ocp_data &= ~AUTO_SPEEDUP;
- ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data);
+ if (tp->udev->speed >= USB_SPEED_SUPER)
+ r8153b_u1u2en(tp, true);
- ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
- }
+ usb_enable_lpm(tp->udev);
r8156_mac_clk_spd(tp, true);
- if (tp->version < RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, PLA_MCU_SPDWN_EN);
-
- ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
if (rtl8152_get_speed(tp) & LINK_STATUS)
- ocp_data |= CUR_LINK_OK;
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK | POLL_LINK_CHG);
else
- ocp_data &= ~CUR_LINK_OK;
- ocp_data |= POLL_LINK_CHG;
- ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS,
+ CUR_LINK_OK, POLL_LINK_CHG);
set_bit(GREEN_ETHERNET, &tp->flags);
- /* RX aggregation / 16 bytes RX descriptor
- * BIT(11) is specific to RTL8159, with unknown meaning
- */
- if (tp->version == RTL_VER_17)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
- RX_AGG_DISABLE | RX_DESC_16B | BIT(11));
- else if (tp->version == RTL_VER_16)
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL, RX_AGG_DISABLE | RX_DESC_16B);
- else
- ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL, RX_AGG_DISABLE | RX_ZERO_EN);
+ /* RX aggregation / 16 bytes RX descriptor / Bulk In End transfer */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_USB_CTRL,
+ RX_AGG_DISABLE | RX_DESC_16B | RX_END_TRANSFER_EN);
- if (tp->version < RTL_VER_12)
- ocp_byte_set_bits(tp, MCU_TYPE_USB, USB_BMU_CONFIG, ACT_ODMA);
+ /* Disable Rx Zero Len */
+ rtl_bmu_clr_bits(tp, 0x2300, BIT(3));
- if (tp->version >= RTL_VER_16) {
- /* Disable Rx Zero Len */
- rtl_bmu_clr_bits(tp, 0x2300, BIT(3));
- /* TX descriptor Signature */
- ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
- }
+ /* TX descriptor Signature */
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xd4ae, BIT(1));
+
+ /* Enable u2phy backup restore patch */
+ if (tp->version == RTL_VER_17_QFN68)
+ ocp_byte_set_bits(tp, MCU_TYPE_USB, 0xb99c, BIT(0));
+
+ /* Enable u3phy patch backup */
+ ocp_write_word(tp, MCU_TYPE_USB, 0xb9a2, 0x0448);
r8156_mdio_force_mode(tp);
rtl_tally_reset(tp);
@@ -8926,8 +9837,16 @@ int rtl8152_get_link_ksettings(struct net_device *netdev,
cmd->link_modes.supported, tp->support_10000full);
if (tp->support_2500full || tp->support_5000full || tp->support_10000full) {
- u16 ocp_10gbt_ctrl = ocp_reg_read(tp, OCP_10GBT_CTRL);
- u16 ocp_10gbt_stat = ocp_reg_read(tp, OCP_10GBT_STAT);
+ u16 ocp_10gbt_ctrl;
+ u16 ocp_10gbt_stat;
+
+ ret = ocp_reg_read(tp, OCP_10GBT_CTRL, &ocp_10gbt_ctrl);
+ if (ret < 0)
+ goto out_unlock;
+
+ ret = ocp_reg_read(tp, OCP_10GBT_STAT, &ocp_10gbt_stat);
+ if (ret < 0)
+ goto out_unlock;
if (tp->support_2500full) {
linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
@@ -8969,12 +9888,13 @@ int rtl8152_get_link_ksettings(struct net_device *netdev,
}
}
+out_unlock:
mutex_unlock(&tp->control);
usb_autopm_put_interface(tp->intf);
out:
- return ret;
+ return ret < 0 ? ret : 0;
}
static int rtl8152_set_link_ksettings(struct net_device *dev,
@@ -9155,21 +10075,37 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)
__ETHTOOL_DECLARE_LINK_MODE_MASK(common) = {};
u16 speed = rtl8152_get_speed(tp);
u16 val;
+ int ret;
+
+ ret = ocp_reg_read(tp, OCP_EEE_ABLE, &val);
+ if (ret < 0)
+ goto out;
- val = ocp_reg_read(tp, OCP_EEE_ABLE);
mii_eee_cap1_mod_linkmode_t(eee->supported, val);
- val = ocp_reg_read(tp, OCP_EEE_ADV);
+ ret = ocp_reg_read(tp, OCP_EEE_ADV, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap1_mod_linkmode_t(eee->advertised, val);
- val = ocp_reg_read(tp, OCP_EEE_LPABLE);
+ ret = ocp_reg_read(tp, OCP_EEE_LPABLE, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap1_mod_linkmode_t(eee->lp_advertised, val);
if (tp->support_2500full || tp->support_5000full) {
- val = ocp_reg_read(tp, OCP_EEE_ADV2);
+ ret = ocp_reg_read(tp, OCP_EEE_ADV2, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap2_mod_linkmode_adv_t(eee->advertised, val);
- val = ocp_reg_read(tp, OCP_EEE_LPABLE2);
+ ret = ocp_reg_read(tp, OCP_EEE_LPABLE2, &val);
+ if (ret < 0)
+ goto out;
+
mii_eee_cap2_mod_linkmode_adv_t(eee->lp_advertised, val);
}
@@ -9205,7 +10141,8 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)
linkmode_and(common, common, eee->lp_advertised);
eee->eee_active = !linkmode_empty(common);
- return 0;
+out:
+ return ret < 0 ? ret : 0;
}
static int
@@ -9445,7 +10382,7 @@ static int rtl8152_set_ringparam(struct net_device *netdev,
static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
{
struct r8152 *tp = netdev_priv(netdev);
- u16 bmcr, lcladv, rmtadv;
+ int bmcr, lcladv, rmtadv;
u8 cap;
if (usb_autopm_get_interface(tp->intf) < 0)
@@ -9461,7 +10398,10 @@ static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pau
usb_autopm_put_interface(tp->intf);
- if (!(bmcr & BMCR_ANENABLE)) {
+ /* Without a readable PHY, or with autoneg off, there is no flow
+ * control to report.
+ */
+ if (bmcr < 0 || lcladv < 0 || rmtadv < 0 || !(bmcr & BMCR_ANENABLE)) {
pause->autoneg = 0;
pause->rx_pause = 0;
pause->tx_pause = 0;
@@ -9492,7 +10432,11 @@ static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_paus
mutex_lock(&tp->control);
- if (pause->autoneg && !(r8152_mdio_read(tp, MII_BMCR) & BMCR_ANENABLE)) {
+ ret = r8152_mdio_read(tp, MII_BMCR);
+ if (ret < 0)
+ goto out;
+
+ if (pause->autoneg && !(ret & BMCR_ANENABLE)) {
ret = -EINVAL;
goto out;
}
@@ -9503,16 +10447,20 @@ static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_paus
if (pause->tx_pause)
cap |= FLOW_CTRL_TX;
- old = r8152_mdio_read(tp, MII_ADVERTISE);
+ ret = r8152_mdio_read(tp, MII_ADVERTISE);
+ if (ret < 0)
+ goto out;
+
+ old = ret;
new1 = (old & ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM)) | mii_advertise_flowctrl(cap);
if (old != new1)
- r8152_mdio_write(tp, MII_ADVERTISE, new1);
+ ret = r8152_mdio_write(tp, MII_ADVERTISE, new1);
out:
mutex_unlock(&tp->control);
usb_autopm_put_interface(tp->intf);
- return ret;
+ return ret < 0 ? ret : 0;
}
static const struct ethtool_ops ops = {
@@ -9546,7 +10494,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{
struct r8152 *tp = netdev_priv(netdev);
struct mii_ioctl_data *data = if_mii(rq);
- int res;
+ int res, val;
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
return -ENODEV;
@@ -9562,7 +10510,11 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
case SIOCGMIIREG:
mutex_lock(&tp->control);
- data->val_out = r8152_mdio_read(tp, data->reg_num);
+ val = r8152_mdio_read(tp, data->reg_num);
+ if (val < 0)
+ res = val;
+ else
+ data->val_out = val;
mutex_unlock(&tp->control);
break;
@@ -9572,7 +10524,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
break;
}
mutex_lock(&tp->control);
- r8152_mdio_write(tp, data->reg_num, data->val_in);
+ res = r8152_mdio_write(tp, data->reg_num, data->val_in);
mutex_unlock(&tp->control);
break;
@@ -9663,11 +10615,6 @@ static void rtl8153_unload(struct r8152 *tp)
return;
r8153_power_cut_en(tp, false);
-
- if (tp->version >= RTL_VER_16) {
- /* Disable Interrupt Mitigation */
- ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04, BIT(0) | BIT(1) | BIT(2) | BIT(7));
- }
}
static void rtl8153b_unload(struct r8152 *tp)
@@ -9678,6 +10625,16 @@ static void rtl8153b_unload(struct r8152 *tp)
r8153b_power_cut_en(tp, false);
}
+static void rtl8157_unload(struct r8152 *tp)
+{
+ if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
+ return;
+
+ r8157_power_cut_en(tp, false);
+ ocp_byte_clr_bits(tp, MCU_TYPE_USB, 0xcf04,
+ BIT(0) | BIT(1) | BIT(2) | BIT(7));
+}
+
static int r8152_desc_init(struct r8152 *tp)
{
tp->rx_desc.size = sizeof(struct rx_desc);
@@ -9730,6 +10687,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->in_nway = rtl8152_in_nway;
ops->hw_phy_cfg = r8152b_hw_phy_cfg;
ops->autosuspend_en = rtl_runtime_suspend_enable;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 16 * 1024;
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_100TX;
@@ -9752,6 +10711,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8153_hw_phy_cfg;
ops->autosuspend_en = rtl8153_runtime_enable;
ops->change_mtu = rtl8153_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
if (tp->udev->speed < USB_SPEED_SUPER)
tp->rx_buf_sz = 16 * 1024;
else
@@ -9775,6 +10736,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8153b_hw_phy_cfg;
ops->autosuspend_en = rtl8153b_runtime_enable;
ops->change_mtu = rtl8153_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 32 * 1024;
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
@@ -9799,6 +10762,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8156_hw_phy_cfg;
ops->autosuspend_en = rtl8156_runtime_enable;
ops->change_mtu = rtl8156_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 48 * 1024;
tp->support_2500full = 1;
r8152_desc_init(tp);
@@ -9812,8 +10777,8 @@ static int rtl_ops_init(struct r8152 *tp)
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
tp->eee_adv2 = MDIO_EEE_2_5GT;
- ops->init = r8156_init;
- ops->enable = rtl8156_enable;
+ ops->init = r8156b_init;
+ ops->enable = rtl8156b_enable;
ops->disable = rtl8153_disable;
ops->up = rtl8156_up;
ops->down = rtl8156_down;
@@ -9824,6 +10789,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8156b_hw_phy_cfg;
ops->autosuspend_en = rtl8156_runtime_enable;
ops->change_mtu = rtl8156_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 48 * 1024;
r8152_desc_init(tp);
break;
@@ -9841,6 +10808,8 @@ static int rtl_ops_init(struct r8152 *tp)
ops->hw_phy_cfg = r8153c_hw_phy_cfg;
ops->autosuspend_en = rtl8153c_runtime_enable;
ops->change_mtu = rtl8153c_change_mtu;
+ ops->phy_read = r8152_phy_read;
+ ops->phy_write = r8152_phy_write;
tp->rx_buf_sz = 32 * 1024;
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
@@ -9851,40 +10820,45 @@ static int rtl_ops_init(struct r8152 *tp)
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
tp->eee_adv2 = MDIO_EEE_2_5GT | MDIO_EEE_5GT;
- ops->init = r8156_init;
- ops->enable = rtl8156_enable;
+ ops->init = r8157_init;
+ ops->enable = rtl8157_enable;
ops->disable = rtl8153_disable;
- ops->up = rtl8156_up;
- ops->down = rtl8156_down;
- ops->unload = rtl8153_unload;
+ ops->up = rtl8157_up;
+ ops->down = rtl8157_down;
+ ops->unload = rtl8157_unload;
ops->eee_get = r8153_get_eee;
ops->eee_set = r8152_set_eee;
ops->in_nway = rtl8153_in_nway;
ops->hw_phy_cfg = r8157_hw_phy_cfg;
ops->autosuspend_en = rtl8157_runtime_enable;
- ops->change_mtu = rtl8156_change_mtu;
+ ops->change_mtu = rtl8157_change_mtu;
+ ops->phy_read = r8157_phy_read;
+ ops->phy_write = r8157_phy_write;
tp->rx_buf_sz = 32 * 1024;
tp->support_2500full = 1;
tp->support_5000full = 1;
r8157_desc_init(tp);
break;
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
tp->eee_en = true;
tp->eee_adv = MDIO_EEE_100TX | MDIO_EEE_1000T | MDIO_EEE_10GT;
tp->eee_adv2 = MDIO_EEE_2_5GT | MDIO_EEE_5GT;
- ops->init = r8156_init;
- ops->enable = rtl8156_enable;
+ ops->init = r8159_init;
+ ops->enable = rtl8157_enable;
ops->disable = rtl8153_disable;
- ops->up = rtl8156_up;
- ops->down = rtl8156_down;
- ops->unload = rtl8153_unload;
+ ops->up = rtl8157_up;
+ ops->down = rtl8157_down;
+ ops->unload = rtl8157_unload;
ops->eee_get = r8153_get_eee;
ops->eee_set = r8152_set_eee;
ops->in_nway = rtl8153_in_nway;
- ops->hw_phy_cfg = r8157_hw_phy_cfg;
+ ops->hw_phy_cfg = r8159_hw_phy_cfg;
ops->autosuspend_en = rtl8157_runtime_enable;
- ops->change_mtu = rtl8156_change_mtu;
+ ops->change_mtu = rtl8157_change_mtu;
+ ops->phy_read = r8157_phy_read;
+ ops->phy_write = r8157_phy_write;
tp->rx_buf_sz = 48 * 1024;
tp->support_2500full = 1;
tp->support_5000full = 1;
@@ -9961,7 +10935,8 @@ static int rtl_fw_init(struct r8152 *tp)
case RTL_VER_16:
rtl_fw->fw_name = FIRMWARE_8157_1;
break;
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
rtl_fw->fw_name = FIRMWARE_8159_1;
break;
default:
@@ -9971,9 +10946,38 @@ static int rtl_fw_init(struct r8152 *tp)
return 0;
}
+static u32 __rtl_get_pkg_det(struct usb_device *udev)
+{
+ u32 pkg_det = 0;
+ __le32 *tmp;
+ int ret, i;
+
+ tmp = kmalloc_obj(*tmp);
+ if (!tmp)
+ return 0;
+
+ for (i = 0, ret = 0; i < 3 && ret != 4; i++)
+ ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+ RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
+ PLA_PKG_DET, MCU_TYPE_PLA, tmp,
+ sizeof(*tmp), USB_CTRL_GET_TIMEOUT);
+
+ if (ret == sizeof(*tmp)) {
+ if (i != 0)
+ dev_warn(&udev->dev,
+ "Needed %d retries to read package\n", i);
+
+ pkg_det = __le32_to_cpu(*tmp) & PKG_MASK;
+ }
+
+ kfree(tmp);
+ return pkg_det;
+}
+
static u8 __rtl_get_hw_ver(struct usb_device *udev)
{
u32 ocp_data = 0;
+ u32 pkg_det = 0;
__le32 *tmp;
u8 version;
int ret;
@@ -10056,7 +11060,16 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev)
version = RTL_VER_16;
break;
case 0x2020:
- version = RTL_VER_17;
+ pkg_det = __rtl_get_pkg_det(udev);
+ if (pkg_det == 0x1e || pkg_det == 0x1c) {
+ version = RTL_VER_17_QFN68;
+ } else if (pkg_det == 0x18 || pkg_det == 0x1a) {
+ version = RTL_VER_17_QFN100;
+ } else {
+ version = RTL_VER_UNKNOWN;
+ dev_info(&udev->dev, "Unknown package 0x%04x\n",
+ pkg_det);
+ }
break;
default:
version = RTL_VER_UNKNOWN;
@@ -10215,7 +11228,8 @@ static int rtl8152_probe_once(struct usb_interface *intf,
case RTL_VER_13:
case RTL_VER_15:
case RTL_VER_16:
- case RTL_VER_17:
+ case RTL_VER_17_QFN68:
+ case RTL_VER_17_QFN100:
netdev->max_mtu = size_to_mtu(16 * 1024);
break;
case RTL_VER_01:
|
| 33/3 | 2026/10/02 04:54 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46229 output: 45 thoughts: 2965 Thoughts: **KMSAN Fuzzing Evaluation for r8152.c Patch** Okay, let's break this down. The task is to determine if this r8152.c patch warrants a dedicated KMSAN fuzzing session. My initial thought process involves a deep dive into the patch's changes, specifically focusing on potential uninitialized variable reads, which is a key KMSAN trigger. The core focus here is on the changes to the `ocp_reg_read`, `sram_read`, `sram2_read` and associated functions, and their callers, and whether any data passed back might be uninitialized. First, I quickly grasped the context: new registers for RTL8157/8159, splitting versions, and changes to various read/write functions. The introduction of `r8152_phy_read` and `r8157_phy_read`, along with related helper functions (`wait_tgphy_cmd_ready`, etc.), immediately caught my eye as potential areas to scrutinize. The immediate concern is this: if a low level read fails, does the called function *always* return the error code, or does it return a *potentially* uninitialized data value? I looked directly at `r8152_phy_read` where it's clear that if `ocp_write_word` fails (returns non-zero), then the data is not set. The caller *must* check the return code. Similarly, in `rtl_tgphy_access`, `*data` isn't set if `wait_tgphy_cmd_ready` returns an error. This is a common pattern in the kernel where the caller assumes that the pointer is only valid on success, and the function returns the error. Now comes the *detailed* examination of *every* caller of `ocp_reg_read`, `sram_read`, `sram2_read` and the like. My thought is, I need to methodically check *each* call site and determine if: 1. The return value is checked. 2. If the return value is checked *and* an error is returned, is the `data` pointer used *before* return? 3. If the return value is ignored, is the `data` pointer potentially uninitialized? The review of each function followed: 1. `r8152_mdio_read`: Safe, returns `ret` on error. Data is only returned on success. 2. `sram_read`: Returns `ret` directly, so ok. 3. `ocp_reg_w0w1`: Same, checks `ret` and returns it on error. 4. `sram_write_w0w1`: Returns `ret` directly. 5. `sram2_read`: Same pattern. 6. `sram2_write_w0w1`: Follows established pattern. 7. `r8152_mdio_test_and_clr_bit`: Uses the return value. 8. `r8153_phy_status`: Initializes data to 0. 9. `rtl_phy_patch_request`: Checks the return value on every call. 10. `rtl_ram_code_speed_up`: return directly. 11. `rtl8152_fw_phy_ver`: return directly. 12. `rtl8152_fw_phy_fixup`: Only uses the return value to determine if the next line should be executed. 13. `r8152_mmd_read`: Initializes data to 0. 14. `r8156_eee_en`: Only returns in the case of a failed read. 15. `r8153b_hw_phy_cfg`: Read the file for the value of the `data` variable. The systematic inspection yielded no immediate red flags, but it was *essential* to be absolutely certain. The critical aspect here is ensuring that these changes, while introducing new functionality, do not introduce exploitable uninitialized read vulnerabilities. While the patch looks safe in that it *correctly* handles error returns and initialization, a deeper analysis with KMSAN in particular, would be warranted. Thus, a dedicated fuzzing session would be a prudent course of action for this patch. |
| 34/3 | 2026/10/02 04:54 | tool | grepper |
0mArgs:{
"Expression": "r8153b_hw_phy_cfg",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=6567=static u32 r8152_efuse_read(struct r8152 *tp, u8 addr)\n--\ndrivers/net/usb/r8152.c-6578-\ndrivers/net/usb/r8152.c:6579:static void r8153b_hw_phy_cfg(struct r8152 *tp)\ndrivers/net/usb/r8152.c-6580-{\n--\ndrivers/net/usb/r8152.c=6669=static void r8153c_hw_phy_cfg(struct r8152 *tp)\ndrivers/net/usb/r8152.c-6670-{\ndrivers/net/usb/r8152.c:6671:\tr8153b_hw_phy_cfg(tp);\ndrivers/net/usb/r8152.c-6672-\n--\ndrivers/net/usb/r8152.c=10670=static int rtl_ops_init(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-10735-\t\tops-\u003ein_nway\t\t= rtl8153_in_nway;\ndrivers/net/usb/r8152.c:10736:\t\tops-\u003ehw_phy_cfg\t\t= r8153b_hw_phy_cfg;\ndrivers/net/usb/r8152.c-10737-\t\tops-\u003eautosuspend_en\t= rtl8153b_runtime_enable;\n"
} |
| 35/3 | 2026/10/02 04:54 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50631 output: 42 thoughts: 31 Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in this field, and writing in the first person: **Navigating the PHY Configuration Code** Alright, I need to get into the details of the hardware PHY configuration, specifically focusing around line 6579 of the `r8153b_hw_phy_cfg` file. Let's start by using `read-file` to get the context around that specific line. This is the quickest way to get my bearings and see what’s going on without wading through the entire file. I know this code pretty well, but a quick refresher around a specific line is always beneficial to save time when diagnosing an issue, especially with so much code. Let's see what we find! |
| 36/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 6579,
"LineCount": 60
}Results: {
"Contents": "6579:\tstatic void r8153b_hw_phy_cfg(struct r8152 *tp)\n6580:\t{\n6581:\t\tu32 ocp_data;\n6582:\t\tu16 data;\n6583:\t\n6584:\t\tocp_word_test_and_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);\n6585:\t\n6586:\t\t/* disable ALDPS before updating the PHY parameters */\n6587:\t\tr8153_aldps_en(tp, false);\n6588:\t\n6589:\t\t/* disable EEE before updating the PHY parameters */\n6590:\t\trtl_eee_enable(tp, false);\n6591:\t\n6592:\t\t/* U1/U2/L1 idle timer. 500 us */\n6593:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);\n6594:\t\n6595:\t\tdata = r8153_phy_status(tp, 0);\n6596:\t\n6597:\t\tswitch (data) {\n6598:\t\tcase PHY_STAT_PWRDN:\n6599:\t\tcase PHY_STAT_EXT_INIT:\n6600:\t\t\trtl8152_apply_firmware(tp, true);\n6601:\t\n6602:\t\t\tr8152_mdio_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n6603:\t\t\tbreak;\n6604:\t\tcase PHY_STAT_LAN_ON:\n6605:\t\tdefault:\n6606:\t\t\trtl8152_apply_firmware(tp, false);\n6607:\t\t\tbreak;\n6608:\t\t}\n6609:\t\n6610:\t\tr8153b_green_en(tp, test_bit(GREEN_ETHERNET, \u0026tp-\u003eflags));\n6611:\t\n6612:\t\tsram_set_bits(tp, SRAM_GREEN_CFG, R_TUNE_EN);\n6613:\t\n6614:\t\tocp_reg_set_bits(tp, OCP_NCTL_CFG, PGA_RETURN_EN);\n6615:\t\n6616:\t\t/* ADC Bias Calibration:\n6617:\t\t * read efuse offset 0x7d to get a 17-bit data. Remove the dummy/fake\n6618:\t\t * bit (bit3) to rebuild the real 16-bit data. Write the data to the\n6619:\t\t * ADC ioffset.\n6620:\t\t */\n6621:\t\tocp_data = r8152_efuse_read(tp, 0x7d);\n6622:\t\tdata = (u16)(((ocp_data \u0026 0x1fff0) \u003e\u003e 1) | (ocp_data \u0026 0x7));\n6623:\t\tif (data != 0xffff)\n6624:\t\t\tocp_reg_write(tp, OCP_ADC_IOFFSET, data);\n6625:\t\n6626:\t\t/* ups mode tx-link-pulse timing adjustment:\n6627:\t\t * rg_saw_cnt = OCP reg 0xC426 Bit[13:0]\n6628:\t\t * swr_cnt_1ms_ini = 16000000 / rg_saw_cnt\n6629:\t\t */\n6630:\t\tocp_reg_read(tp, 0xc426, \u0026data);\n6631:\t\tocp_data = data \u0026 0x3fff;\n6632:\t\tif (ocp_data) {\n6633:\t\t\tu32 swr_cnt_1ms_ini;\n6634:\t\n6635:\t\t\tswr_cnt_1ms_ini = (16000000 / ocp_data) \u0026 SAW_CNT_1MS_MASK;\n6636:\t\t\tocp_word_w0w1(tp, MCU_TYPE_USB, USB_UPS_CFG, SAW_CNT_1MS_MASK,\n6637:\t\t\t\t swr_cnt_1ms_ini);\n6638:\t\t}\n"
} |
| 37/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51993 output: 42 thoughts: 525 Thoughts: **Analyzing Potential Data Initialization Issues** Okay, let's dive into this. I'm looking specifically at lines 6622 and 6630, where `u16 data;` is declared and then used. Line 6622 initializes `data` with a bitwise operation: `data = (u16)(((ocp_data & 0x1fff0) >> 1) | (ocp_data & 0x7));`. Then, line 6630 uses it in `ocp_reg_read(tp, 0xc426, &data);`. My immediate concern is, what happens if `ocp_reg_read` *fails*? Does `data` retain the value assigned on line 6622, or is it uninitialized in the calling function? I need to understand what `ocp_reg_read` does. Let's see... within `r8153b_hw_phy_cfg`, it uses `tp->rtl_ops.phy_read`, which is defined as `r8152_phy_read`. Good, I know the source code of this function. Looking at `r8152_phy_read`, I see that it involves `ocp_write_word` and `ocp_read_word`. Crucially, if `ocp_write_word` returns non-zero (indicating a failure), it returns `-EIO` *without* modifying the value pointed to by the `data` pointer. So, `*data` is not updated when a write fails. I have to consider the fact that in `r8153b_hw_phy_cfg`, `data` *was* initialized on line 6622, so it's not uninitialized memory on the stack in that scenario; it's got the value that was assigned to it earlier. The point is, failure of `ocp_reg_read` will return the original value. I should also check other similar functions that use `ocp_reg_read`. Let me quickly check the implementation of `r8156_hw_phy_cfg`, focusing on lines 8200-8260 and similar sections for initialization flow. This is important to verify there aren't similar potential issues in other parts of the code base. |
| 38/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 8195,
"LineCount": 70
}Results: {
"Contents": "8195:\t\t\tocp_reg_clr_bits(tp, 0xa454, BIT(0));\n8196:\t\n8197:\t\t\t/* CS DSP solution */\n8198:\t\t\tocp_reg_set_bits(tp, OCP_10GBT_CTRL, RTL_ADV2_5G_F_R);\n8199:\t\t\tocp_reg_clr_bits(tp, 0xad4e, BIT(4));\n8200:\t\t\tocp_reg_clr_bits(tp, 0xa86a, BIT(0));\n8201:\t\n8202:\t\t\t/* MDI SWAP */\n8203:\t\t\tocp_reg_read(tp, 0xd068, \u0026data);\n8204:\t\t\tif ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) \u0026 MID_REVERSE) \u0026\u0026\n8205:\t\t\t (data \u0026 BIT(1))) {\n8206:\t\t\t\tu16 swap_a, swap_b;\n8207:\t\n8208:\t\t\t\tocp_reg_read(tp, 0xd068, \u0026data);\n8209:\t\t\t\tdata \u0026= ~0x1f;\n8210:\t\t\t\tdata |= 0x1; /* p0 */\n8211:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8212:\t\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_a);\n8213:\t\t\t\tdata \u0026= ~0x18;\n8214:\t\t\t\tdata |= 0x18; /* p3 */\n8215:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8216:\t\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_b);\n8217:\t\t\t\tdata \u0026= ~0x18; /* p0 */\n8218:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8219:\t\t\t\tocp_reg_write(tp, 0xd06a,\n8220:\t\t\t\t\t (swap_a \u0026 ~0x7ff) | (swap_b \u0026 0x7ff));\n8221:\t\t\t\tdata |= 0x18; /* p3 */\n8222:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8223:\t\t\t\tocp_reg_write(tp, 0xd06a,\n8224:\t\t\t\t\t (swap_b \u0026 ~0x7ff) | (swap_a \u0026 0x7ff));\n8225:\t\t\t\tdata \u0026= ~0x18;\n8226:\t\t\t\tdata |= 0x08; /* p1 */\n8227:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8228:\t\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_a);\n8229:\t\t\t\tdata \u0026= ~0x18;\n8230:\t\t\t\tdata |= 0x10; /* p2 */\n8231:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8232:\t\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_b);\n8233:\t\t\t\tdata \u0026= ~0x18;\n8234:\t\t\t\tdata |= 0x08; /* p1 */\n8235:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8236:\t\t\t\tocp_reg_write(tp, 0xd06a,\n8237:\t\t\t\t\t (swap_a \u0026 ~0x7ff) | (swap_b \u0026 0x7ff));\n8238:\t\t\t\tdata \u0026= ~0x18;\n8239:\t\t\t\tdata |= 0x10; /* p2 */\n8240:\t\t\t\tocp_reg_write(tp, 0xd068, data);\n8241:\t\t\t\tocp_reg_write(tp, 0xd06a,\n8242:\t\t\t\t\t (swap_b \u0026 ~0x7ff) | (swap_a \u0026 0x7ff));\n8243:\t\t\t\tocp_reg_read(tp, 0xbd5a, \u0026swap_a);\n8244:\t\t\t\tocp_reg_read(tp, 0xbd5c, \u0026swap_b);\n8245:\t\t\t\tocp_reg_write(tp, 0xbd5a, (swap_a \u0026 ~0x1f1f) |\n8246:\t\t\t\t\t ((swap_b \u0026 0x1f) \u003c\u003c 8) |\n8247:\t\t\t\t\t ((swap_b \u003e\u003e 8) \u0026 0x1f));\n8248:\t\t\t\tocp_reg_write(tp, 0xbd5c, (swap_b \u0026 ~0x1f1f) |\n8249:\t\t\t\t\t ((swap_a \u0026 0x1f) \u003c\u003c 8) |\n8250:\t\t\t\t\t ((swap_a \u003e\u003e 8) \u0026 0x1f));\n8251:\t\t\t\tocp_reg_read(tp, 0xbc18, \u0026swap_a);\n8252:\t\t\t\tocp_reg_read(tp, 0xbc1a, \u0026swap_b);\n8253:\t\t\t\tocp_reg_write(tp, 0xbc18, (swap_a \u0026 ~0x1f1f) |\n8254:\t\t\t\t\t ((swap_b \u0026 0x1f) \u003c\u003c 8) |\n8255:\t\t\t\t\t ((swap_b \u003e\u003e 8) \u0026 0x1f));\n8256:\t\t\t\tocp_reg_write(tp, 0xbc1a, (swap_b \u0026 ~0x1f1f) |\n8257:\t\t\t\t\t ((swap_a \u0026 0x1f) \u003c\u003c 8) |\n8258:\t\t\t\t\t ((swap_a \u003e\u003e 8) \u0026 0x1f));\n8259:\t\t\t}\n8260:\t\n8261:\t\t\t/* Notify the MAC when the speed is changed to force mode. */\n8262:\t\t\tocp_reg_set_bits(tp, OCP_INTR_EN, INTR_SPEED_FORCE);\n8263:\t\t\tbreak;\n8264:\t\tdefault:\n"
} |
| 39/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54687 output: 42 thoughts: 76 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience: **Diving into r8156_hw_phy_cfg: Locating the Data** Alright, I need to get a handle on how this data is being used, so let's jump straight into lines 8203-8259 of `r8156_hw_phy_cfg`. I'm going to start by getting my bearings: I need to quickly determine the scope of `data` within this function. The context I need is that it would need to be declared either locally within the section of code specified, or potentially passed in from an outside source. I want to see how `data` is initialized, what its type is, and most importantly where it's declared in relation to that block of code. This quick dive into declarations will tell me a lot about the data's lifecycle and potential side effects. I'll scroll back up within `r8156_hw_phy_cfg` and locate the declaration. Knowing the origin will make the rest of the analysis far more efficient. |
| 40/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 8080,
"LineCount": 40
}Results: {
"Contents": "8080:\t\t\tbreak;\n8081:\t\tcase PHY_STAT_LAN_ON:\n8082:\t\tcase PHY_STAT_PWRDN:\n8083:\t\tdefault:\n8084:\t\t\trtl8152_apply_firmware(tp, false);\n8085:\t\t\tbreak;\n8086:\t\t}\n8087:\t\n8088:\t\t/* disable ALDPS before updating the PHY parameters */\n8089:\t\tr8153_aldps_en(tp, false);\n8090:\t\n8091:\t\t/* disable EEE before updating the PHY parameters */\n8092:\t\trtl_eee_enable(tp, false);\n8093:\t\n8094:\t\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n8095:\t\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n8096:\t\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n8097:\t\n8098:\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n8099:\t\n8100:\t\tswitch (tp-\u003eversion) {\n8101:\t\tcase RTL_VER_10:\n8102:\t\t\tocp_reg_w0w1(tp, 0xad40, 0x3ff, BIT(7) | BIT(2));\n8103:\t\n8104:\t\t\tocp_reg_set_bits(tp, 0xad4e, BIT(4));\n8105:\t\t\tocp_reg_w0w1(tp, 0xad16, 0x3ff, 0x6);\n8106:\t\t\tocp_reg_w0w1(tp, 0xad32, 0x3f, 0x6);\n8107:\t\t\tocp_reg_clr_bits(tp, 0xac08, BIT(12) | BIT(8));\n8108:\t\t\tocp_reg_w0w1(tp, 0xac8a, BIT(15), BIT(12) | BIT(13) | BIT(14));\n8109:\t\t\tocp_reg_set_bits(tp, 0xad18, BIT(10));\n8110:\t\t\tocp_reg_set_bits(tp, 0xad1a, 0x3ff);\n8111:\t\t\tocp_reg_set_bits(tp, 0xad1c, 0x3ff);\n8112:\t\n8113:\t\t\tsram_write_w0w1(tp, 0x80ea, 0xff00, 0xc400);\n8114:\t\t\tsram_write_w0w1(tp, 0x80eb, 0x0700, 0x0300);\n8115:\t\t\tsram_write_w0w1(tp, 0x80f8, 0xff00, 0x1c00);\n8116:\t\t\tsram_write_w0w1(tp, 0x80f1, 0xff00, 0x3000);\n8117:\t\n8118:\t\t\tsram_write_w0w1(tp, 0x80fe, 0xff00, 0xa500);\n8119:\t\t\tsram_write_w0w1(tp, 0x8102, 0xff00, 0x5000);\n"
} |
| 41/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55984 output: 39 thoughts: 790 Thoughts: **Analyzing Potential Failure Points in `r8156_hw_phy_cfg`** Okay, so I'm looking at `r8156_hw_phy_cfg` and I see this line: `data = r8153_phy_status(tp, PHY_STAT_LAN_ON);` at line 8094. But then, my mind jumps to lines 8206 and beyond, and I see these `swap_a` and `swap_b` variables being used. My first thought is about potential issues, particularly if `ocp_reg_read(tp, 0xd06a, &swap_a);` fails. If that read fails, does `swap_a` even get initialized? And what does *that* mean downstream? Gotta figure that out. Okay, let's back up and see what `ocp_reg_read` actually *does*. It calls `tp->rtl_ops.phy_read`. Right, and we're looking at the RTL_VER_11 version of things, which means `phy_read` is set to `r8152_phy_read`. Got it. Now, let's drill down into `r8152_phy_read`. Okay, we've got OCP base address stuff, conditional logic, and then the actual read via `ocp_read_word`. Important! `ocp_write_word` is involved too, based on the earlier code. The critical piece here is *what* `ocp_write_word` returns if it fails. That will determine whether that failure will propagate to our `swap_a` variable or not. Need to dig into that one next. |
| 42/3 | 2026/10/02 04:55 | tool | grepper |
0mArgs:{
"Expression": "ocp_write_word",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 415 lines.\nUse more precise expression if possible.\n\ndrivers/net/usb/r8152.c=1583=static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)\n--\ndrivers/net/usb/r8152.c-1601-\ndrivers/net/usb/r8152.c:1602:static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)\ndrivers/net/usb/r8152.c-1603-{\n--\ndrivers/net/usb/r8152.c=1661=static int r8152_phy_read(struct r8152 *tp, u16 addr, u16 *data)\n--\ndrivers/net/usb/r8152.c-1666-\tif (ocp_base != tp-\u003eocp_base) {\ndrivers/net/usb/r8152.c:1667:\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);\ndrivers/net/usb/r8152.c-1668-\t\ttp-\u003eocp_base = ocp_base;\n--\ndrivers/net/usb/r8152.c=1677=static int r8152_phy_write(struct r8152 *tp, u16 addr, u16 data)\n--\ndrivers/net/usb/r8152.c-1682-\tif (ocp_base != tp-\u003eocp_base) {\ndrivers/net/usb/r8152.c:1683:\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);\ndrivers/net/usb/r8152.c-1684-\t\ttp-\u003eocp_base = ocp_base;\n--\ndrivers/net/usb/r8152.c-1687-\tocp_index = (addr \u0026 0x0fff) | 0xb000;\ndrivers/net/usb/r8152.c:1688:\tocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);\ndrivers/net/usb/r8152.c-1689-\n--\ndrivers/net/usb/r8152.c=1724=static int ocp_adv_read(struct r8152 *tp, u16 cmd, u16 addr, u32 *data)\n--\ndrivers/net/usb/r8152.c-1731-\ndrivers/net/usb/r8152.c:1732:\tocp_write_word(tp, MCU_TYPE_USB, USB_ADV_ADDR, addr);\ndrivers/net/usb/r8152.c-1733-\ndrivers/net/usb/r8152.c-1734-\tcmd |= ADV_CMD_BUSY;\ndrivers/net/usb/r8152.c:1735:\tocp_write_word(tp, MCU_TYPE_USB, USB_ADV_CMD, cmd);\ndrivers/net/usb/r8152.c-1736-\n--\ndrivers/net/usb/r8152.c=1747=static int ocp_adv_write(struct r8152 *tp, u16 cmd, u16 addr, u32 data)\n--\ndrivers/net/usb/r8152.c-1757-\ndrivers/net/usb/r8152.c:1758:\tocp_write_word(tp, MCU_TYPE_USB, USB_ADV_ADDR, addr);\ndrivers/net/usb/r8152.c-1759-\ndrivers/net/usb/r8152.c-1760-\tcmd |= ADV_CMD_BUSY;\ndrivers/net/usb/r8152.c:1761:\tocp_write_word(tp, MCU_TYPE_USB, USB_ADV_CMD, cmd);\ndrivers/net/usb/r8152.c-1762-\n--\ndrivers/net/usb/r8152.c=1903=ocp_word_w0w1(struct r8152 *tp, u16 type, u16 index, u16 clear, u16 set)\n--\ndrivers/net/usb/r8152.c-1908-\tocp_data = (ocp_data \u0026 ~clear) | set;\ndrivers/net/usb/r8152.c:1909:\tocp_write_word(tp, type, index, ocp_data);\ndrivers/net/usb/r8152.c-1910-}\n--\ndrivers/net/usb/r8152.c=1943=ocp_word_test_and_clr_bits(struct r8152 *tp, u16 type, u16 index, u16 clear)\n--\ndrivers/net/usb/r8152.c-1948-\tif (ocp_data \u0026 clear)\ndrivers/net/usb/r8152.c:1949:\t\tocp_write_word(tp, type, index, ocp_data \u0026 ~clear);\ndrivers/net/usb/r8152.c-1950-\n--\ndrivers/net/usb/r8152.c=2138=static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data, bool write)\n--\ndrivers/net/usb/r8152.c-2148-\t\tcmd |= TGPHY_CMD_WR;\ndrivers/net/usb/r8152.c:2149:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA, *data);\ndrivers/net/usb/r8152.c-2150-\t}\ndrivers/net/usb/r8152.c-2151-\ndrivers/net/usb/r8152.c:2152:\tocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_ADDR, addr);\ndrivers/net/usb/r8152.c-2153-\ndrivers/net/usb/r8152.c-2154-\tcmd |= TGPHY_CMD_BUSY;\ndrivers/net/usb/r8152.c:2155:\tocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_CMD, cmd);\ndrivers/net/usb/r8152.c-2156-\n--\ndrivers/net/usb/r8152.c=3809=static void r8153_set_rx_early_timeout(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-3817-\tcase RTL_VER_06:\ndrivers/net/usb/r8152.c:3818:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,\ndrivers/net/usb/r8152.c-3819-\t\t\t ocp_data);\n--\ndrivers/net/usb/r8152.c-3827-\t\t */\ndrivers/net/usb/r8152.c:3828:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,\ndrivers/net/usb/r8152.c-3829-\t\t\t 128 / 8);\ndrivers/net/usb/r8152.c:3830:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,\ndrivers/net/usb/r8152.c-3831-\t\t\t ocp_data);\n--\ndrivers/net/usb/r8152.c-3841-\tcase RTL_VER_17_QFN100:\ndrivers/net/usb/r8152.c:3842:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_TIMEOUT,\ndrivers/net/usb/r8152.c-3843-\t\t\t 640 / 8);\ndrivers/net/usb/r8152.c:3844:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EXTRA_AGGR_TMR,\ndrivers/net/usb/r8152.c-3845-\t\t\t ocp_data);\n--\ndrivers/net/usb/r8152.c=3858=static void r8153_set_rx_early_size(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-3866-\tcase RTL_VER_06:\ndrivers/net/usb/r8152.c:3867:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,\ndrivers/net/usb/r8152.c-3868-\t\t\t ocp_data / 4);\n--\ndrivers/net/usb/r8152.c-3872-\tcase RTL_VER_14:\ndrivers/net/usb/r8152.c:3873:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,\ndrivers/net/usb/r8152.c-3874-\t\t\t ocp_data / 8);\n--\ndrivers/net/usb/r8152.c-3881-\tcase RTL_VER_15:\ndrivers/net/usb/r8152.c:3882:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,\ndrivers/net/usb/r8152.c-3883-\t\t\t ocp_data / 8);\n--\ndrivers/net/usb/r8152.c-3887-\tcase RTL_VER_17_QFN100:\ndrivers/net/usb/r8152.c:3888:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_RX_EARLY_SIZE,\ndrivers/net/usb/r8152.c-3889-\t\t\t ocp_data / 16);\n--\ndrivers/net/usb/r8152.c=4117=static void r8156_mac_clk_spd(struct r8152 *tp, bool enable)\n--\ndrivers/net/usb/r8152.c-4121-\t\t/* aldps_spdwn_ratio, tp10_spdwn_ratio */\ndrivers/net/usb/r8152.c:4122:\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, 0x0403);\ndrivers/net/usb/r8152.c-4123-\n--\ndrivers/net/usb/r8152.c=4756=static void r8153_teredo_off(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-4790-\ndrivers/net/usb/r8152.c:4791:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE);\ndrivers/net/usb/r8152.c:4792:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0);\ndrivers/net/usb/r8152.c-4793-\tocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0);\n--\ndrivers/net/usb/r8152.c=4805=static void rtl_clear_bp(struct r8152 *tp, u16 type)\n--\ndrivers/net/usb/r8152.c-4818-\t\tif (type == MCU_TYPE_USB) {\ndrivers/net/usb/r8152.c:4819:\t\t\tocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0);\ndrivers/net/usb/r8152.c-4820-\t\t\tbp_num = 16;\n--\ndrivers/net/usb/r8152.c-4839-\tdefault:\ndrivers/net/usb/r8152.c:4840:\t\tocp_write_word(tp, type, USB_BP2_EN, 0);\ndrivers/net/usb/r8152.c-4841-\t\tbp_num = 16;\n--\ndrivers/net/usb/r8152.c-4848-\tusleep_range(3000, 6000);\ndrivers/net/usb/r8152.c:4849:\tocp_write_word(tp, type, PLA_BP_BA, 0);\ndrivers/net/usb/r8152.c-4850-}\n--\ndrivers/net/usb/r8152.c=5795=static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac)\n--\ndrivers/net/usb/r8152.c-5824-\t !(ocp_read_word(tp, MCU_TYPE_PLA, PLA_MACDBG_POST) \u0026 DEBUG_OE)) {\ndrivers/net/usb/r8152.c:5825:\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_MACDBG_PRE, DEBUG_LTSSM);\ndrivers/net/usb/r8152.c:5826:\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_MACDBG_POST, DEBUG_LTSSM);\ndrivers/net/usb/r8152.c-5827-\t}\n--\ndrivers/net/usb/r8152.c-5841-\ndrivers/net/usb/r8152.c:5842:\tocp_write_word(tp, type, __le16_to_cpu(mac-\u003ebp_ba_addr),\ndrivers/net/usb/r8152.c-5843-\t\t __le16_to_cpu(mac-\u003ebp_ba_value));\n--\ndrivers/net/usb/r8152.c-5854-\tif (bp_en_addr)\ndrivers/net/usb/r8152.c:5855:\t\tocp_write_word(tp, type, bp_en_addr,\ndrivers/net/usb/r8152.c-5856-\t\t\t __le16_to_cpu(mac-\u003ebp_en_value));\n--\ndrivers/net/usb/r8152.c=6197=static void r8152b_exit_oob(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6245-\ndrivers/net/usb/r8152.c:6246:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);\ndrivers/net/usb/r8152.c-6247-\n--\ndrivers/net/usb/r8152.c=6251=static void r8152b_enter_oob(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6266-\ndrivers/net/usb/r8152.c:6267:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);\ndrivers/net/usb/r8152.c-6268-\n--\ndrivers/net/usb/r8152.c=6282=static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)\n--\ndrivers/net/usb/r8152.c-6290-\tcase RTL_VER_11:\ndrivers/net/usb/r8152.c:6291:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,\ndrivers/net/usb/r8152.c-6292-\t\t\t CTRL_TIMER_EN | (1000 / 8));\n--\ndrivers/net/usb/r8152.c-6306-\t\t/* enable fc timer and set timer to 600 ms. */\ndrivers/net/usb/r8152.c:6307:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,\ndrivers/net/usb/r8152.c-6308-\t\t\t CTRL_TIMER_EN | (600 / 8));\n--\ndrivers/net/usb/r8152.c=6399=static int r8153_post_firmware_1(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6402-\tif (ocp_read_byte(tp, MCU_TYPE_USB, USB_CSTMR) \u0026 FORCE_SUPER)\ndrivers/net/usb/r8152.c:6403:\t\tocp_write_word(tp, MCU_TYPE_USB, USB_BP_4, BP4_SUPER_ONLY);\ndrivers/net/usb/r8152.c-6404-\ndrivers/net/usb/r8152.c-6405-\t/* reset UPHY timer to 36 ms */\ndrivers/net/usb/r8152.c:6406:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_UPHY_TIMER, 36000 / 16);\ndrivers/net/usb/r8152.c-6407-\n--\ndrivers/net/usb/r8152.c=6420=static int r8153_post_firmware_2(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6426-\t/* reset UPHY timer to 36 ms */\ndrivers/net/usb/r8152.c:6427:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_UPHY_TIMER, 36000 / 16);\ndrivers/net/usb/r8152.c-6428-\ndrivers/net/usb/r8152.c-6429-\t/* enable U3P3 check, set the counter to 4 */\ndrivers/net/usb/r8152.c:6430:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, U3P3_CHECK_EN | 4);\ndrivers/net/usb/r8152.c-6431-\n--\ndrivers/net/usb/r8152.c=6450=static int r8153b_pre_firmware_1(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6452-\t/* enable fc timer and set timer to 1 second. */\ndrivers/net/usb/r8152.c:6453:\tocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,\ndrivers/net/usb/r8152.c-6454-\t\t CTRL_TIMER_EN | (1000 / 8));\n--\ndrivers/net/usb/r8152.c=6567=static u32 r8152_efuse_read(struct r8152 *tp, u8 addr)\n--\ndrivers/net/usb/r8152.c-6570-\ndrivers/net/usb/r8152.c:6571:\tocp_write_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD, EFUSE_READ_CMD | addr);\ndrivers/net/usb/r8152.c-6572-\tocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EFUSE_CMD);\n--\ndrivers/net/usb/r8152.c=6579=static void r8153b_hw_phy_cfg(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6592-\t/* U1/U2/L1 idle timer. 500 us */\ndrivers/net/usb/r8152.c:6593:\tocp_write_word(tp, MCU_TYPE_USB, USB_U1U2_TIMER, 500);\ndrivers/net/usb/r8152.c-6594-\n--\n\n"
} |
| 43/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62679 output: 42 thoughts: 25 Thoughts: Okay, let's dive into this. Here's my understanding, assuming I'm the one thinking this: **Analyzing `r8152_phy_read` - Line 1661 and Beyond** Alright, I'm going to revisit `r8152_phy_read` and I need to hone in specifically around line 1661. I remember we were having some issues there, and it's time to refresh my memory and pinpoint the relevant section of the code. Let's see if the potential problem, that I remember facing, is still present. I need to understand this function's behavior in detail. |
| 44/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 1655,
"LineCount": 40
}Results: {
"Contents": "1655:\t\n1656:\t\ttmp = __cpu_to_le32(data);\n1657:\t\n1658:\t\tgeneric_ocp_write(tp, index, byen, sizeof(tmp), \u0026tmp, type);\n1659:\t}\n1660:\t\n1661:\tstatic int r8152_phy_read(struct r8152 *tp, u16 addr, u16 *data)\n1662:\t{\n1663:\t\tu16 ocp_base, ocp_index;\n1664:\t\n1665:\t\tocp_base = addr \u0026 0xf000;\n1666:\t\tif (ocp_base != tp-\u003eocp_base) {\n1667:\t\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);\n1668:\t\t\ttp-\u003eocp_base = ocp_base;\n1669:\t\t}\n1670:\t\n1671:\t\tocp_index = (addr \u0026 0x0fff) | 0xb000;\n1672:\t\t*data = ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);\n1673:\t\n1674:\t\treturn 0;\n1675:\t}\n1676:\t\n1677:\tstatic int r8152_phy_write(struct r8152 *tp, u16 addr, u16 data)\n1678:\t{\n1679:\t\tu16 ocp_base, ocp_index;\n1680:\t\n1681:\t\tocp_base = addr \u0026 0xf000;\n1682:\t\tif (ocp_base != tp-\u003eocp_base) {\n1683:\t\t\tocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);\n1684:\t\t\ttp-\u003eocp_base = ocp_base;\n1685:\t\t}\n1686:\t\n1687:\t\tocp_index = (addr \u0026 0x0fff) | 0xb000;\n1688:\t\tocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);\n1689:\t\n1690:\t\treturn 0;\n1691:\t}\n1692:\t\n1693:\tstatic int ocp_reg_read(struct r8152 *tp, u16 addr, u16 *data)\n1694:\t{\n"
} |
| 45/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63580 output: 42 thoughts: 71 Thoughts: Here's my summary, as I delve into this code: **Diving into the r8152 PHY Read** Okay, so `r8152_phy_read` is always returning 0. That's... not ideal. And it's also assigning the value obtained from `ocp_read_word` to `*data`. Alright, let's unpack this. The return value is always zero... is that by design, or an error? It definitely needs checking - usually a PHY read will indicate success, so this is strange. But more importantly, what is `ocp_read_word` even *doing*? I need to understand that function's behavior to have any hope of understanding the result. It seems like it's the core of the read operation, interacting with the `MCU_TYPE_PLA` and `ocp_index` parameters. Time to trace into `ocp_read_word` and see what's happening under the hood. I suspect this is the key to figuring out why this read is always giving us the same result. |
| 46/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 1580,
"LineCount": 30
}Results: {
"Contents": "1580:\t\tgeneric_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), \u0026tmp, type);\n1581:\t}\n1582:\t\n1583:\tstatic u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)\n1584:\t{\n1585:\t\tu32 data;\n1586:\t\t__le32 tmp;\n1587:\t\tu16 byen = BYTE_EN_WORD;\n1588:\t\tu8 shift = index \u0026 2;\n1589:\t\n1590:\t\tindex \u0026= ~3;\n1591:\t\tbyen \u003c\u003c= shift;\n1592:\t\n1593:\t\tgeneric_ocp_read(tp, index, sizeof(tmp), \u0026tmp, type | byen);\n1594:\t\n1595:\t\tdata = __le32_to_cpu(tmp);\n1596:\t\tdata \u003e\u003e= (shift * 8);\n1597:\t\tdata \u0026= 0xffff;\n1598:\t\n1599:\t\treturn (u16)data;\n1600:\t}\n1601:\t\n1602:\tstatic void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)\n1603:\t{\n1604:\t\tu32 mask = 0xffff;\n1605:\t\t__le32 tmp;\n1606:\t\tu16 byen = BYTE_EN_WORD;\n1607:\t\tu8 shift = index \u0026 2;\n1608:\t\n1609:\t\tdata \u0026= mask;\n"
} |
| 47/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64380 output: 39 thoughts: 12 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Analyzing the `generic_ocp_read` Function** Wait a second... let me refocus. My initial thinking was on track, but I need to zoom in on this `generic_ocp_read` function. It’s critical to understand its behavior and implications within the broader context. Specifically, I need to understand its role within the wider framework, considering its implications on read latency, coherency protocols, and potential race conditions. Is this function atomic? Does it handle partial reads? Does it use any caching mechanism? These are all burning questions I need to answer before proceeding. My experience tells me that a deep dive here is essential before making any major design decisions further down the line. I need to know how it interfaces with the underlying hardware, how it handles potential errors, and its overall performance profile. Without a clear understanding of `generic_ocp_read`, I'm operating with incomplete information, and I am likely to miss key performance or correctness issues. This could lead to a massive rework down the line, so best to invest in understanding this function now. Let's see how this thing truly works. |
| 48/3 | 2026/10/02 04:55 | tool | grepper |
0mArgs:{
"Expression": "generic_ocp_read",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=1444=static void rtl_set_unplug(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-1449-\ndrivers/net/usb/r8152.c:1450:static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,\ndrivers/net/usb/r8152.c-1451-\t\t\t void *data, u16 type)\n--\ndrivers/net/usb/r8152.c=1550=int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)\ndrivers/net/usb/r8152.c-1551-{\ndrivers/net/usb/r8152.c:1552:\treturn generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA);\ndrivers/net/usb/r8152.c-1553-}\n--\ndrivers/net/usb/r8152.c=1567=static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)\n--\ndrivers/net/usb/r8152.c-1570-\ndrivers/net/usb/r8152.c:1571:\tgeneric_ocp_read(tp, index, sizeof(data), \u0026data, type);\ndrivers/net/usb/r8152.c-1572-\n--\ndrivers/net/usb/r8152.c=1583=static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)\n--\ndrivers/net/usb/r8152.c-1592-\ndrivers/net/usb/r8152.c:1593:\tgeneric_ocp_read(tp, index, sizeof(tmp), \u0026tmp, type | byen);\ndrivers/net/usb/r8152.c-1594-\n--\ndrivers/net/usb/r8152.c=1623=static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)\n--\ndrivers/net/usb/r8152.c-1630-\ndrivers/net/usb/r8152.c:1631:\tgeneric_ocp_read(tp, index, sizeof(tmp), \u0026tmp, type);\ndrivers/net/usb/r8152.c-1632-\n--\ndrivers/net/usb/r8152.c=9992=static void rtl8152_get_ethtool_stats(struct net_device *dev,\n--\ndrivers/net/usb/r8152.c-10000-\ndrivers/net/usb/r8152.c:10001:\tgeneric_ocp_read(tp, PLA_TALLYCNT, sizeof(tally), \u0026tally, MCU_TYPE_PLA);\ndrivers/net/usb/r8152.c-10002-\n"
} |
| 49/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 65523 output: 42 thoughts: 13 Thoughts: Okay, let's break this down. Here's how I'd approach summarizing the "Thoughts" based on the prompt, speaking in the first person, and assuming a high level of expertise: **Examining `generic_ocp_read`** Alright, so the instruction is to look at `generic_ocp_read`. Immediately, my mind starts to race, assuming I know the context – likely within the realm of Open Compute Project (OCP) systems, and a read operation. "Generic" usually implies a level of abstraction, a generalized function that could be applied across various hardware configurations. My first questions would involve: * **What level of abstraction are we talking about?** Is this hardware-specific, firmware-specific, or more of an API call at a higher level? Knowing the scope is critical to understanding its design and purpose. * **What kind of data are we reading?** OCP covers a wide spectrum of components - BMC information, fan speed, power metrics, or more. Determining what this function is designed to access will dictate the potential complexities. * **What are the performance implications?** "Generic" can sometimes mean a performance penalty due to increased overhead. How efficient is this read operation in practice? Are there specific use cases where it might be preferable, or where a more targeted read is necessary? * **Are there any error handling mechanisms?** The system should be robust, so I immediately begin to consider what failure conditions this function handles, and what the potential failure modes are. * **How does it interact with other components?** Is this a standalone function, or does it interact with an abstraction layer? Knowing this would help to decide where the code lives. I need to understand the architectural intent behind `generic_ocp_read`. Is it meant to be a single point of entry, simplifying the code, or does it exist as a convenience function, but at the cost of performance? The next step, naturally, is to begin to trace the code, or to review the documentation. |
| 50/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 1450,
"LineCount": 40
}Results: {
"Contents": "1450:\tstatic int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,\n1451:\t\t\t\t void *data, u16 type)\n1452:\t{\n1453:\t\tu16 limit = 64;\n1454:\t\tint ret = 0;\n1455:\t\n1456:\t\tif (test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags))\n1457:\t\t\treturn -ENODEV;\n1458:\t\n1459:\t\t/* both size and indix must be 4 bytes align */\n1460:\t\tif ((size \u0026 3) || !size || (index \u0026 3) || !data)\n1461:\t\t\treturn -EPERM;\n1462:\t\n1463:\t\tif ((u32)index + (u32)size \u003e 0xffff)\n1464:\t\t\treturn -EPERM;\n1465:\t\n1466:\t\twhile (size) {\n1467:\t\t\tu16 n = min(size, limit);\n1468:\t\n1469:\t\t\tret = get_registers(tp, index, type, n, data);\n1470:\t\t\tif (ret \u003c 0)\n1471:\t\t\t\tbreak;\n1472:\t\n1473:\t\t\tindex += n;\n1474:\t\t\tdata += n;\n1475:\t\t\tsize -= n;\n1476:\t\t}\n1477:\t\n1478:\t\tif (ret == -ENODEV)\n1479:\t\t\trtl_set_unplug(tp);\n1480:\t\n1481:\t\treturn ret;\n1482:\t}\n1483:\t\n1484:\tstatic int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,\n1485:\t\t\t\t u16 size, void *data, u16 type)\n1486:\t{\n1487:\t\tint ret;\n1488:\t\tu16 byteen_start, byteen_end, byen;\n1489:\t\tu16 limit = 512;\n"
} |
| 51/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 66597 output: 20 thoughts: 536 Thoughts: **Analyzing the New Code** Okay, so `ocp_read_word` uses `generic_ocp_read`, which is existing code, so that's not the focus. My attention is drawn to `__rtl_get_pkg_det` and what it introduces or changes. Let's dig in. The code allocates memory with `kmalloc_obj(*tmp)`. Hang on... `kmalloc_obj(*tmp)`? That looks fishy. It's allocating based on the *contents* of an uninitialized pointer! Then I see the control message is executed three times to attempt to get the data, and if one attempt results in getting the correct number of bytes, the loop is exited and the contents are examined. Okay, so if `ret == sizeof(*tmp)`, then `*tmp` was, presumably, populated by `usb_control_msg`. Right? The return value of `usb_control_msg` is checked against `sizeof(*tmp)`. And what if `ret` is *less* than `sizeof(*tmp)`? That's covered; it'll be caught by the `ret == sizeof(*tmp)` check, so we don't have to worry about partial transfers. I see that if `usb_control_msg` succeeds and transfers four bytes, `tmp` is filled with data. Now, is `tmp` uninitialized before the `usb_control_msg`? Yes! However, the code *only* dereferences `*tmp` if the `usb_control_msg` call succeeded and the right number of bytes were written. So, is that a valid allocation size for the pointer? The code looks safe *if* `kmalloc_obj` is what I think it is, that is, a size-based allocation function! I need to confirm if `kmalloc_obj` is indeed a kernel function/macro. That's the next step to confirm this. Let me check the kernel sources... |
| 52/3 | 2026/10/02 04:55 | tool | grepper |
0mArgs:{
"Expression": "#define kmalloc_obj"
}Results: {
"Output": "include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);\n--\ninclude/linux/slab.h-1123- */\ninclude/linux/slab.h:1124:#define kmalloc_obj(VAR_OR_TYPE, ...) \\\ninclude/linux/slab.h-1125-\t__alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), 1)\n--\ninclude/linux/slab.h-1135- */\ninclude/linux/slab.h:1136:#define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \\\ninclude/linux/slab.h-1137-\t__alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), COUNT)\n--\nlib/decompress_unxz.c-163-#undef vfree\nlib/decompress_unxz.c:164:#define kmalloc_obj(type) malloc(sizeof(type))\nlib/decompress_unxz.c-165-#define kfree(ptr) free(ptr)\n--\ntools/virtio/linux/kernel.h=63=static inline void *kmalloc_array(unsigned n, size_t s, gfp_t gfp)\n--\ntools/virtio/linux/kernel.h-67-\ntools/virtio/linux/kernel.h:68:#define kmalloc_obj(VAR_OR_TYPE, ...) \\\ntools/virtio/linux/kernel.h-69-\t((typeof(VAR_OR_TYPE) *)kmalloc(sizeof(typeof(VAR_OR_TYPE)), 0))\ntools/virtio/linux/kernel.h-70-\ntools/virtio/linux/kernel.h:71:#define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \\\ntools/virtio/linux/kernel.h-72-\t((typeof(VAR_OR_TYPE) *)kmalloc(sizeof(typeof(VAR_OR_TYPE)) * (COUNT), 0))\n"
} |
| 53/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 68096 output: 43 thoughts: 35 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person: **Diving into `r8152.c` and `__rtl_get_hw_ver`** Alright, I need to get a better handle on how this hardware version retrieval function, `__rtl_get_hw_ver`, is being used within the `r8152.c` driver. I'm going to quickly scan the rest of the file. I want to see *how* and *where* they're leveraging that function. Is it primarily for feature detection, conditional code paths, or maybe just simple debugging and logging? Are there any obvious areas where the version information is critical to the driver's operation, or does it seem more ancillary? My goal is to quickly understand the function's significance to the driver's overall logic and identify any potential dependencies or areas of concern, given my knowledge of similar USB network drivers. I'm looking for patterns, common usage idioms, and anything that jumps out as unusual or potentially problematic. |
| 54/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 10035,
"LineCount": 40
}Results: {
"Contents": "10035:\t\tval = r8152_mmd_read(tp, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE);\n10036:\t\tmii_eee_cap1_mod_linkmode_t(eee-\u003esupported, val);\n10037:\t\n10038:\t\tval = r8152_mmd_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV);\n10039:\t\tmii_eee_cap1_mod_linkmode_t(eee-\u003eadvertised, val);\n10040:\t\n10041:\t\tval = r8152_mmd_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE);\n10042:\t\tmii_eee_cap1_mod_linkmode_t(eee-\u003elp_advertised, val);\n10043:\t\n10044:\t\teee-\u003eeee_enabled = tp-\u003eeee_en;\n10045:\t\n10046:\t\tif (speed \u0026 _1000bps)\n10047:\t\t\tlinkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, common);\n10048:\t\tif (speed \u0026 _100bps)\n10049:\t\t\tlinkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, common);\n10050:\t\n10051:\t\tlinkmode_and(common, common, eee-\u003eadvertised);\n10052:\t\tlinkmode_and(common, common, eee-\u003elp_advertised);\n10053:\t\teee-\u003eeee_active = !linkmode_empty(common);\n10054:\t\n10055:\t\treturn 0;\n10056:\t}\n10057:\t\n10058:\tstatic int r8152_set_eee(struct r8152 *tp, struct ethtool_keee *eee)\n10059:\t{\n10060:\t\tu16 val = linkmode_to_mii_eee_cap1_t(eee-\u003eadvertised);\n10061:\t\n10062:\t\ttp-\u003eeee_en = eee-\u003eeee_enabled;\n10063:\t\ttp-\u003eeee_adv = val;\n10064:\t\tif (tp-\u003esupport_2500full || tp-\u003esupport_5000full) {\n10065:\t\t\tval = linkmode_to_mii_eee_cap2_t(eee-\u003eadvertised);\n10066:\t\t\ttp-\u003eeee_adv2 = val;\n10067:\t\t}\n10068:\t\trtl_eee_enable(tp, tp-\u003eeee_en);\n10069:\t\n10070:\t\treturn 0;\n10071:\t}\n10072:\t\n10073:\tstatic int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)\n10074:\t{\n"
} |
| 55/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 69214 output: 43 thoughts: 17 Thoughts: Here's my thought process, as it stands: **Locating `__rtl_get_hw_ver`** Okay, so I need to track down the location of the `__rtl_get_hw_ver` function. That's the key starting point. I need to understand its role and how it's being used. I'm going to quickly check in my environment to see where I can find it. Usually, a quick search in the project's source code, possibly with grep or a similar tool, will point me in the right direction. I'll focus on the more likely areas first: the device driver code or the hardware abstraction layer, depending on the architecture. It's likely involved in hardware version identification, so that is the context in which I'll be looking. Let's start the search... |
| 56/3 | 2026/10/02 04:55 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 10960,
"LineCount": 50
}Results: {
"Contents": "10960:\t\t\tret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),\n10961:\t\t\t\t\t RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,\n10962:\t\t\t\t\t PLA_PKG_DET, MCU_TYPE_PLA, tmp,\n10963:\t\t\t\t\t sizeof(*tmp), USB_CTRL_GET_TIMEOUT);\n10964:\t\n10965:\t\tif (ret == sizeof(*tmp)) {\n10966:\t\t\tif (i != 0)\n10967:\t\t\t\tdev_warn(\u0026udev-\u003edev,\n10968:\t\t\t\t\t \"Needed %d retries to read package\\n\", i);\n10969:\t\n10970:\t\t\tpkg_det = __le32_to_cpu(*tmp) \u0026 PKG_MASK;\n10971:\t\t}\n10972:\t\n10973:\t\tkfree(tmp);\n10974:\t\treturn pkg_det;\n10975:\t}\n10976:\t\n10977:\tstatic u8 __rtl_get_hw_ver(struct usb_device *udev)\n10978:\t{\n10979:\t\tu32 ocp_data = 0;\n10980:\t\tu32 pkg_det = 0;\n10981:\t\t__le32 *tmp;\n10982:\t\tu8 version;\n10983:\t\tint ret;\n10984:\t\tint i;\n10985:\t\n10986:\t\ttmp = kmalloc_obj(*tmp);\n10987:\t\tif (!tmp)\n10988:\t\t\treturn 0;\n10989:\t\n10990:\t\t/* Retry up to 3 times in case there is a transitory error. We do this\n10991:\t\t * since retrying a read of the version is always safe and this\n10992:\t\t * function doesn't take advantage of r8152_control_msg().\n10993:\t\t */\n10994:\t\tfor (i = 0; i \u003c 3; i++) {\n10995:\t\t\tret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),\n10996:\t\t\t\t\t RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,\n10997:\t\t\t\t\t PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp),\n10998:\t\t\t\t\t USB_CTRL_GET_TIMEOUT);\n10999:\t\t\tif (ret \u003e 0) {\n11000:\t\t\t\tocp_data = (__le32_to_cpu(*tmp) \u003e\u003e 16) \u0026 VERSION_MASK;\n11001:\t\t\t\tbreak;\n11002:\t\t\t}\n11003:\t\t}\n11004:\t\n11005:\t\tif (i != 0 \u0026\u0026 ret \u003e 0)\n11006:\t\t\tdev_warn(\u0026udev-\u003edev, \"Needed %d retries to read version\\n\", i);\n11007:\t\n11008:\t\tkfree(tmp);\n11009:\t\n"
} |
| 57/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 70305 output: 68 thoughts: 1600 Thoughts: **Analyzing Potential Uninitialized Read Vulnerabilities in the Driver** Okay, let's break this down systematically. I'm focusing on potential uninitialized read vulnerabilities introduced or addressed by this recent code change. First, I examined the comparison between `__rtl_get_pkg_det` and the original `__rtl_get_hw_ver`. The key difference lies in how they handle the USB control message read. In `__rtl_get_pkg_det`, the code explicitly checks the return value of `usb_control_msg`. It *only* reads `*tmp` if the read was successful. The loop continues until the read succeeds or a maximum number of retries is reached. This is a good practice as it prevents reading uninitialized data. Then, I shifted focus to the `ioctl` changes in `rtl8152_ioctl`. I noticed how the `r8152_mdio_read` function's return value is handled. The *previous* implementation was vulnerable. Now, if `r8152_mdio_read` returns an error, this error code is propagated back through the `ioctl` path, ensuring that `data->val_out` is *not* written to. The crucial question now becomes whether the driver attempts to copy this potentially uninitialized `data` structure back to userspace when an error occurs. I had to consult `dev_ioctl.c` to see if the error return prevented the `copy_to_user` call. The good news is, it does. Therefore, there's no way to leak uninitialized data. I then moved to `rtl8152_get_pauseparam`. I noticed that all fields of the `pause` structure are explicitly initialized, even when errors occur. This is a good sign. Next, I looked at `r8153_get_eee`. Here, a pointer to an `ethtool_keee` structure is passed from the ethtool core. The code checks for failures in `ocp_reg_read`. Crucially, if an error is encountered, the code uses `goto out;` and `return ret < 0 ? ret : 0;`. This means that if `ocp_reg_read` fails, the function returns the error code to the ethtool core, and crucially, aborts before writing anything to the user-provided structure. The error code will then be propagated back to userspace, and no uninitialized data will be copied. Similarly, I examined `rtl8152_get_link_ksettings`. The same pattern applies: if `ocp_reg_read` fails, the function jumps to `out_unlock` and returns the error code, preventing any uninitialized data from being exposed to the user. Finally, I checked `r8159_hw_phy_cfg`. The `data` variable is set by `r8153_phy_status(tp, 0)`. *Crucially*, I need to be *absolutely certain* that all calls to the older `ocp_reg_read` (the version that took two arguments) have been completely removed. If any calls to the old `ocp_reg_read` (u16 addr) signature are left, it would be catastrophic. So I need to use `grepper` and verify that the old calls are all now with the new signature `ocp_reg_read(tp, address, &data)`. Good news, the compiler would likely catch the old signature and not let it compile. I should do a full search, though, just to be sure. In summary, this driver seems to be handling potential uninitialized read issues very carefully. The introduction of explicit error checks, early exits on failure, and the pattern of only writing data back to the user-provided structures *after* successful reads are all good practices that have effectively mitigated any vulnerability in these sections. The thoroughness and consistency is commendable. The search for the old `ocp_reg_read` signature is an important double check. |
| 58/3 | 2026/10/02 04:55 | tool | grepper |
0mError:no matches Args: {
"Expression": "ocp_reg_read\\([a-zA-Z0-9_\u003e -]+, [a-zA-Z0-9_\u003e -]+\\)",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"error": "no matches"
} |
| 59/3 | 2026/10/02 04:55 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 72857 output: 40 thoughts: 28 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing the r8152.c Driver: Hunting for `ocp_reg_read()`** Alright, let's dive into this. My initial instinct is to use `grep` – the workhorse. Specifically, I'm targeting the `drivers/net/usb/r8152.c` file. The goal here is pretty clear: I'm looking for every instance of `ocp_reg_read(`. This tells me immediately we are working with an Realtek RTL8152 USB ethernet adapter and are potentially trying to identify how register reads are performed within that specific device driver. Knowing this is the target function name tells me the device likely uses an OCP (Open Core Protocol) interface of some kind to allow the CPU to read registers from the device and understand what data is coming back, likely status or configuration information. I'm going to want to examine the context of each match to see how those register reads are being handled, what registers are being targeted, and how the results are being interpreted and used within the driver's logic. This should give me a good handle on how the hardware is being accessed, and potentially provide insights into any specific issues or areas I might want to investigate further (maybe, potentially, debugging a specific hardware problem). This also is going to give me some good starting points if I want to dive more into how the USB transport is actually facilitating the register reads. Let's see what we find. |
| 60/3 | 2026/10/02 04:57 | tool | grepper |
0mArgs:{
"Expression": "ocp_reg_read\\(",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=1677=static int r8152_phy_write(struct r8152 *tp, u16 addr, u16 data)\n--\ndrivers/net/usb/r8152.c-1692-\ndrivers/net/usb/r8152.c:1693:static int ocp_reg_read(struct r8152 *tp, u16 addr, u16 *data)\ndrivers/net/usb/r8152.c-1694-{\n--\ndrivers/net/usb/r8152.c=1708=static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)\n--\ndrivers/net/usb/r8152.c-1712-\ndrivers/net/usb/r8152.c:1713:\tret = ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2, \u0026data);\ndrivers/net/usb/r8152.c-1714-\n--\ndrivers/net/usb/r8152.c=1848=static int sram_read(struct r8152 *tp, u16 addr, u16 *data)\n--\ndrivers/net/usb/r8152.c-1855-\ndrivers/net/usb/r8152.c:1856:\tret = ocp_reg_read(tp, OCP_SRAM_DATA, data);\ndrivers/net/usb/r8152.c-1857-\n--\ndrivers/net/usb/r8152.c=1964=static int ocp_reg_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n--\ndrivers/net/usb/r8152.c-1968-\ndrivers/net/usb/r8152.c:1969:\tret = ocp_reg_read(tp, addr, \u0026data);\ndrivers/net/usb/r8152.c-1970-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c=2030=static int sram2_read(struct r8152 *tp, u16 addr, u16 *data)\n--\ndrivers/net/usb/r8152.c-2037-\ndrivers/net/usb/r8152.c:2038:\tret = ocp_reg_read(tp, OCP_SRAM2_DATA, data);\ndrivers/net/usb/r8152.c-2039-\n--\ndrivers/net/usb/r8152.c=4384=static u16 r8153_phy_status(struct r8152 *tp, u16 desired)\n--\ndrivers/net/usb/r8152.c-4389-\tfor (i = 0; i \u003c 500; i++) {\ndrivers/net/usb/r8152.c:4390:\t\tif (ocp_reg_read(tp, OCP_PHY_STATUS, \u0026data) \u003c 0)\ndrivers/net/usb/r8152.c-4391-\t\t\tbreak;\n--\ndrivers/net/usb/r8152.c=4857=static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait)\n--\ndrivers/net/usb/r8152.c-4875-\t\tusleep_range(1000, 2000);\ndrivers/net/usb/r8152.c:4876:\t\tret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, \u0026ocp_data);\ndrivers/net/usb/r8152.c-4877-\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-4883-\tif (request \u0026\u0026 wait) {\ndrivers/net/usb/r8152.c:4884:\t\tret = ocp_reg_read(tp, OCP_PHY_PATCH_STAT, \u0026ocp_data);\ndrivers/net/usb/r8152.c-4885-\t\tif (ret \u003c 0) {\n--\ndrivers/net/usb/r8152.c=5694=static void rtl8152_fw_phy_fixup(struct r8152 *tp, struct fw_phy_fixup *fix)\n--\ndrivers/net/usb/r8152.c-5700-\taddr = __le16_to_cpu(fix-\u003esetting.addr);\ndrivers/net/usb/r8152.c:5701:\tif (ocp_reg_read(tp, addr, \u0026data) \u003c 0)\ndrivers/net/usb/r8152.c-5702-\t\treturn;\n--\ndrivers/net/usb/r8152.c=6004=static u16 r8152_mmd_read(struct r8152 *tp, u16 dev, u16 reg)\n--\ndrivers/net/usb/r8152.c-6008-\tr8152_mmd_indirect(tp, dev, reg);\ndrivers/net/usb/r8152.c:6009:\tocp_reg_read(tp, OCP_EEE_DATA, \u0026data);\ndrivers/net/usb/r8152.c-6010-\tocp_reg_write(tp, OCP_EEE_AR, 0x0000);\n--\ndrivers/net/usb/r8152.c=6068=static void r8156_eee_en(struct r8152 *tp, bool enable)\n--\ndrivers/net/usb/r8152.c-6073-\ndrivers/net/usb/r8152.c:6074:\tif (ocp_reg_read(tp, OCP_EEE_ADV2, \u0026config) \u003c 0)\ndrivers/net/usb/r8152.c-6075-\t\treturn;\n--\ndrivers/net/usb/r8152.c=6579=static void r8153b_hw_phy_cfg(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-6629-\t */\ndrivers/net/usb/r8152.c:6630:\tocp_reg_read(tp, 0xc426, \u0026data);\ndrivers/net/usb/r8152.c-6631-\tocp_data = data \u0026 0x3fff;\n--\ndrivers/net/usb/r8152.c=6919=static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n--\ndrivers/net/usb/r8152.c-7038-\t\tif (tp-\u003esupport_2500full || tp-\u003esupport_5000full || tp-\u003esupport_10000full) {\ndrivers/net/usb/r8152.c:7039:\t\t\tret = ocp_reg_read(tp, OCP_10GBT_CTRL, \u0026orig);\ndrivers/net/usb/r8152.c-7040-\t\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c=7538=static bool rtl8153_in_nway(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-7541-\ndrivers/net/usb/r8152.c:7542:\tif (ocp_reg_read(tp, OCP_PHY_STATE, \u0026phy_state) \u003c 0)\ndrivers/net/usb/r8152.c-7543-\t\treturn false;\n--\ndrivers/net/usb/r8152.c=7553=static void r8156_mdio_force_mode(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-7560-\t */\ndrivers/net/usb/r8152.c:7561:\tif (ocp_reg_read(tp, 0xa5b4, \u0026data) \u003c 0)\ndrivers/net/usb/r8152.c-7562-\t\treturn;\n--\ndrivers/net/usb/r8152.c=8068=static void r8156_hw_phy_cfg(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-8202-\t\t/* MDI SWAP */\ndrivers/net/usb/r8152.c:8203:\t\tocp_reg_read(tp, 0xd068, \u0026data);\ndrivers/net/usb/r8152.c-8204-\t\tif ((ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CFG) \u0026 MID_REVERSE) \u0026\u0026\n--\ndrivers/net/usb/r8152.c-8207-\ndrivers/net/usb/r8152.c:8208:\t\t\tocp_reg_read(tp, 0xd068, \u0026data);\ndrivers/net/usb/r8152.c-8209-\t\t\tdata \u0026= ~0x1f;\n--\ndrivers/net/usb/r8152.c-8211-\t\t\tocp_reg_write(tp, 0xd068, data);\ndrivers/net/usb/r8152.c:8212:\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_a);\ndrivers/net/usb/r8152.c-8213-\t\t\tdata \u0026= ~0x18;\n--\ndrivers/net/usb/r8152.c-8215-\t\t\tocp_reg_write(tp, 0xd068, data);\ndrivers/net/usb/r8152.c:8216:\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_b);\ndrivers/net/usb/r8152.c-8217-\t\t\tdata \u0026= ~0x18; /* p0 */\n--\ndrivers/net/usb/r8152.c-8227-\t\t\tocp_reg_write(tp, 0xd068, data);\ndrivers/net/usb/r8152.c:8228:\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_a);\ndrivers/net/usb/r8152.c-8229-\t\t\tdata \u0026= ~0x18;\n--\ndrivers/net/usb/r8152.c-8231-\t\t\tocp_reg_write(tp, 0xd068, data);\ndrivers/net/usb/r8152.c:8232:\t\t\tocp_reg_read(tp, 0xd06a, \u0026swap_b);\ndrivers/net/usb/r8152.c-8233-\t\t\tdata \u0026= ~0x18;\n--\ndrivers/net/usb/r8152.c-8242-\t\t\t\t (swap_b \u0026 ~0x7ff) | (swap_a \u0026 0x7ff));\ndrivers/net/usb/r8152.c:8243:\t\t\tocp_reg_read(tp, 0xbd5a, \u0026swap_a);\ndrivers/net/usb/r8152.c:8244:\t\t\tocp_reg_read(tp, 0xbd5c, \u0026swap_b);\ndrivers/net/usb/r8152.c-8245-\t\t\tocp_reg_write(tp, 0xbd5a, (swap_a \u0026 ~0x1f1f) |\n--\ndrivers/net/usb/r8152.c-8250-\t\t\t\t ((swap_a \u003e\u003e 8) \u0026 0x1f));\ndrivers/net/usb/r8152.c:8251:\t\t\tocp_reg_read(tp, 0xbc18, \u0026swap_a);\ndrivers/net/usb/r8152.c:8252:\t\t\tocp_reg_read(tp, 0xbc1a, \u0026swap_b);\ndrivers/net/usb/r8152.c-8253-\t\t\tocp_reg_write(tp, 0xbc18, (swap_a \u0026 ~0x1f1f) |\n--\ndrivers/net/usb/r8152.c=9813=int rtl8152_get_link_ksettings(struct net_device *netdev,\n--\ndrivers/net/usb/r8152.c-9842-\ndrivers/net/usb/r8152.c:9843:\t\tret = ocp_reg_read(tp, OCP_10GBT_CTRL, \u0026ocp_10gbt_ctrl);\ndrivers/net/usb/r8152.c-9844-\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-9846-\ndrivers/net/usb/r8152.c:9847:\t\tret = ocp_reg_read(tp, OCP_10GBT_STAT, \u0026ocp_10gbt_stat);\ndrivers/net/usb/r8152.c-9848-\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c=10073=static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)\n--\ndrivers/net/usb/r8152.c-10079-\ndrivers/net/usb/r8152.c:10080:\tret = ocp_reg_read(tp, OCP_EEE_ABLE, \u0026val);\ndrivers/net/usb/r8152.c-10081-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-10085-\ndrivers/net/usb/r8152.c:10086:\tret = ocp_reg_read(tp, OCP_EEE_ADV, \u0026val);\ndrivers/net/usb/r8152.c-10087-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-10091-\ndrivers/net/usb/r8152.c:10092:\tret = ocp_reg_read(tp, OCP_EEE_LPABLE, \u0026val);\ndrivers/net/usb/r8152.c-10093-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-10098-\tif (tp-\u003esupport_2500full || tp-\u003esupport_5000full) {\ndrivers/net/usb/r8152.c:10099:\t\tret = ocp_reg_read(tp, OCP_EEE_ADV2, \u0026val);\ndrivers/net/usb/r8152.c-10100-\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-10104-\ndrivers/net/usb/r8152.c:10105:\t\tret = ocp_reg_read(tp, OCP_EEE_LPABLE2, \u0026val);\ndrivers/net/usb/r8152.c-10106-\t\tif (ret \u003c 0)\n"
} |
| 61/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 77339 output: 42 thoughts: 1242 Thoughts: **Analyzing Potential `ocp_reg_read` Failures**
Okay, so I've gone through and updated all the `ocp_reg_read` calls, but I need to make sure I haven't missed a critical vulnerability. Let's dig into that `r8156_hw_phy_cfg` function and specifically this sequence:
```c
ocp_reg_read(tp, 0xd068, &data);
data &= ~0x1f;
data |= 0x1; /* p0 */
ocp_reg_write(tp, 0xd068, data);
ocp_reg_read(tp, 0xd06a, &swap_a);
data &= ~0x18;
data |= 0x18; /* p3 */
ocp_reg_write(tp, 0xd068, data);
ocp_reg_read(tp, 0xd06a, &swap_b);
data &= ~0x18; /* p0 */
ocp_reg_write(tp, 0xd068, data);
ocp_reg_write(tp, 0xd06a,
(swap_a & ~0x7ff) | (swap_b & 0x7ff));
```
The thing that immediately jumps out is: what happens if the `ocp_reg_read(tp, 0xd06a, &swap_a)` fails? Does it ever check this? The answer is... no, and this is where it gets interesting because this might not be an issue.
Now, let's refresh our memory. For this r8156 chip, `tp->rtl_ops.phy_read` is `r8152_phy_read`. And, I need to know how it actually reads, so I check it:
```c
static int r8152_phy_read(struct r8152 *tp, u16 addr, u16 *data)
{
u16 ocp_base, ocp_index;
ocp_base = addr & 0xf000;
if (ocp_base != tp->ocp_base) {
ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
tp->ocp_base = ocp_base;
}
ocp_index = (addr & 0x0fff) | 0xb000;
*data = ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
return 0;
}
```
Wait a second. `r8152_phy_read` *unconditionally* writes to `*data`, always returning 0, regardless of any potential read errors from `ocp_read_word`. That's... not ideal from an error handling standpoint.
But, does this apply to other chips, too? I need to understand the full landscape here.
Let's check `r8157_phy_read`:
```c
static int r8157_phy_read(struct r8152 *tp, u16 addr, u16 *data)
{
return rtl_tgphy_access(tp, addr, data, false);
}
```
Okay, so `r8157_phy_read` calls `rtl_tgphy_access`. Let's see what that does:
```c
static int rtl_tgphy_access(struct r8152 *tp, u16 addr, u16 *data, bool write)
{
u16 cmd = 0;
int ret;
ret = wait_tgphy_cmd_ready(tp);
if (ret < 0)
goto out;
if (write) {
cmd |= TGPHY_CMD_WR;
ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_DATA, *data);
}
ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_ADDR, addr);
cmd |= TGPHY_CMD_BUSY;
ocp_write_word(tp, MCU_TYPE_USB, USB_TGPHY_CMD, cmd);
if (!write) {
ret = wait
|
| 62/3 | 2026/10/02 04:57 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 8560,
"LineCount": 80
}Results: {
"Contents": "8560:\t\tcase PHY_STAT_PWRDN:\n8561:\t\tdefault:\n8562:\t\t\trtl8152_apply_firmware(tp, false);\n8563:\t\t\tbreak;\n8564:\t\t}\n8565:\t\n8566:\t\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n8567:\t\n8568:\t\tr8153_aldps_en(tp, false);\n8569:\t\trtl_eee_enable(tp, false);\n8570:\t\n8571:\t\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n8572:\t\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n8573:\t\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n8574:\t\n8575:\t\t/* PFM mode */\n8576:\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n8577:\t\n8578:\t\t/* Advanced Power Saving parameter */\n8579:\t\tocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);\n8580:\t\n8581:\t\t/* Disable ALDPS force mode */\n8582:\t\tocp_reg_clr_bits(tp, 0xa44a, BIT(2));\n8583:\t\n8584:\t\t/* Disable bypass_turn_off_clk_in_aldps */\n8585:\t\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));\n8586:\t\n8587:\t\tswitch (tp-\u003eversion) {\n8588:\t\tcase RTL_VER_16:\n8589:\t\t\t/* XG_INRX parameter */\n8590:\t\t\tsram_write_w0w1(tp, 0x8183, 0xff00, 0x5900);\n8591:\t\t\tocp_reg_set_bits(tp, 0xa654, BIT(11));\n8592:\t\t\tocp_reg_set_bits(tp, 0xb648, BIT(14));\n8593:\t\t\tocp_reg_clr_bits(tp, 0xad2c, BIT(15));\n8594:\t\t\tocp_reg_set_bits(tp, 0xad94, BIT(5));\n8595:\t\t\tocp_reg_set_bits(tp, 0xada0, BIT(1));\n8596:\t\t\tocp_reg_w0w1(tp, 0xae06, 0xfc00, 0x7c00);\n8597:\t\t\tsram2_write_w0w1(tp, 0x8647, 0xff00, 0xe600);\n8598:\t\t\tsram2_write_w0w1(tp, 0x8036, 0xff00, 0x3000);\n8599:\t\t\tsram2_write_w0w1(tp, 0x8078, 0xff00, 0x3000);\n8600:\t\n8601:\t\t\t/* green mode */\n8602:\t\t\tsram2_clr_bits(tp, 0x89e9, 0xff00);\n8603:\t\t\tsram2_write_w0w1(tp, 0x8ffd, 0xff00, 0x0100);\n8604:\t\t\tsram2_write_w0w1(tp, 0x8ffe, 0xff00, 0x0200);\n8605:\t\t\tsram2_write_w0w1(tp, 0x8fff, 0xff00, 0x0400);\n8606:\t\n8607:\t\t\t/* recognize AQC/Bcom function */\n8608:\t\t\tsram_write_w0w1(tp, 0x8018, 0xff00, 0x7700);\n8609:\t\t\tocp_reg_write(tp, OCP_SRAM_ADDR, 0x8f9c);\n8610:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0005);\n8611:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0000);\n8612:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x00ed);\n8613:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0502);\n8614:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0b00);\n8615:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0xd401);\n8616:\t\t\tsram_write_w0w1(tp, 0x8fa8, 0xff00, 0x2900);\n8617:\t\n8618:\t\t\t/* RFI_corr_thd 5g */\n8619:\t\t\tsram2_write_w0w1(tp, 0x814b, 0xff00, 0x1100);\n8620:\t\t\tsram2_write_w0w1(tp, 0x814d, 0xff00, 0x1100);\n8621:\t\t\tsram2_write_w0w1(tp, 0x814f, 0xff00, 0x0b00);\n8622:\t\t\tsram2_write_w0w1(tp, 0x8142, 0xff00, 0x0100);\n8623:\t\t\tsram2_write_w0w1(tp, 0x8144, 0xff00, 0x0100);\n8624:\t\t\tsram2_write_w0w1(tp, 0x8150, 0xff00, 0x0100);\n8625:\t\n8626:\t\t\t/* RFI_corr_thd 2p5g */\n8627:\t\t\tsram2_write_w0w1(tp, 0x8118, 0xff00, 0x0700);\n8628:\t\t\tsram2_write_w0w1(tp, 0x811a, 0xff00, 0x0700);\n8629:\t\t\tsram2_write_w0w1(tp, 0x811c, 0xff00, 0x0500);\n8630:\t\t\tsram2_write_w0w1(tp, 0x810f, 0xff00, 0x0100);\n8631:\t\t\tsram2_write_w0w1(tp, 0x8111, 0xff00, 0x0100);\n8632:\t\t\tsram2_write_w0w1(tp, 0x811d, 0xff00, 0x0100);\n8633:\t\n8634:\t\t\t/* RFI parameter */\n8635:\t\t\tocp_reg_clr_bits(tp, 0xad1c, BIT(8));\n8636:\t\t\tocp_reg_w0w1(tp, 0xade8, 0xffc0, 0x1400);\n8637:\t\t\tsram2_write_w0w1(tp, 0x864b, 0xff00, 0x9d00);\n8638:\t\t\tsram2_write_w0w1(tp, 0x862c, 0xff00, 0x1200);\n8639:\t\t\tocp_reg_write(tp, OCP_SRAM_ADDR, 0x8566);\n"
} |
| 63/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 81799 output: 42 thoughts: 17 Thoughts: Okay, here's my attempt at summarizing the thought process, speaking from a first-person perspective as a field expert, and starting with a bolded header: **Diving Deeper into the Core Data** Alright, I'm ready to dive into the next block of the analysis. Let's focus our attention on lines 8640 through 8740. This segment should be quite relevant to the current problem, I think. I expect it to have some key indicators we can use to start drilling down. Let's see what emerges. |
| 64/3 | 2026/10/02 04:57 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 8640,
"LineCount": 80
}Results: {
"Contents": "8640:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x003f);\n8641:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x3f02);\n8642:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x023c);\n8643:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x3b0a);\n8644:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x1c00);\n8645:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0000);\n8646:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0000);\n8647:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0000);\n8648:\t\t\tocp_reg_write(tp, OCP_SRAM_DATA, 0x0000);\n8649:\t\n8650:\t\t\t/* RFI-color noise gen parameter 5g */\n8651:\t\t\tocp_reg_set_bits(tp, 0xad9c, BIT(5));\n8652:\t\t\tsram2_write_w0w1(tp, 0x8122, 0xff00, 0x0c00);\n8653:\t\t\tocp_reg_write(tp, OCP_SRAM2_ADDR, 0x82c8);\n8654:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03ed);\n8655:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03ff);\n8656:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0009);\n8657:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03fe);\n8658:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x000b);\n8659:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0021);\n8660:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03f7);\n8661:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03b8);\n8662:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03e0);\n8663:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0049);\n8664:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0049);\n8665:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03e0);\n8666:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03b8);\n8667:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03f7);\n8668:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0021);\n8669:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x000b);\n8670:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03fe);\n8671:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0009);\n8672:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03ff);\n8673:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03ed);\n8674:\t\n8675:\t\t\t/* RFI-color noise gen parameter 2p5g */\n8676:\t\t\tsram2_write_w0w1(tp, 0x80ef, 0xff00, 0x0c00);\n8677:\t\t\tocp_reg_write(tp, OCP_SRAM2_ADDR, 0x82a0);\n8678:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x000e);\n8679:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03fe);\n8680:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03ed);\n8681:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0006);\n8682:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x001a);\n8683:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03f1);\n8684:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03d8);\n8685:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0023);\n8686:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0054);\n8687:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0322);\n8688:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x00dd);\n8689:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03ab);\n8690:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03dc);\n8691:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0027);\n8692:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x000e);\n8693:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03e5);\n8694:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03f9);\n8695:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0012);\n8696:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x0001);\n8697:\t\t\tocp_reg_write(tp, OCP_SRAM2_DATA, 0x03f1);\n8698:\t\n8699:\t\t\t/* modify thermal speed down threshold */\n8700:\t\t\tocp_reg_w0w1(tp, 0xb54c, 0xffc0, 0x3700);\n8701:\t\n8702:\t\t\t/* XG compatibility modification */\n8703:\t\t\tocp_reg_set_bits(tp, 0xb648, BIT(6));\n8704:\t\t\tsram2_write_w0w1(tp, 0x8082, 0xff00, 0x5d00);\n8705:\t\t\tsram2_write_w0w1(tp, 0x807c, 0xff00, 0x5000);\n8706:\t\t\tsram2_write_w0w1(tp, 0x809d, 0xff00, 0x5000);\n8707:\t\t\tbreak;\n8708:\t\tdefault:\n8709:\t\t\tbreak;\n8710:\t\t}\n8711:\t\n8712:\t\tif (rtl_phy_patch_request(tp, true, true))\n8713:\t\t\treturn;\n8714:\t\n8715:\t\tocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, EEE_SPDWN_EN);\n8716:\t\n8717:\t\tocp_reg_w0w1(tp, OCP_DOWN_SPEED, EN_EEE_100 | EN_EEE_1000, EN_10M_CLKDIV);\n8718:\t\n8719:\t\ttp-\u003eups_info._10m_ckdiv = true;\n"
} |
| 65/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 84266 output: 42 thoughts: 32 Thoughts: Here's my analysis of the provided snippet, rendered in the first person, assuming an expert user: **Deep Dive into r8159_hw_phy_cfg** Alright, let's zero in on `r8159_hw_phy_cfg` within lines 8740-8950. Given the naming convention, I'm expecting this section to handle hardware PHY configuration for the RTL8159. Knowing this chip, I anticipate a fair bit of intricate detail here. My immediate thought is, what are the specific PHY initialization sequences, register settings, and any potential workaround or optimization logic contained within these lines? I need to quickly identify the key registers being manipulated and understand the rationale behind the specific bit patterns being written. This is critical because any misconfiguration here can directly impact link establishment, speed negotiation, and overall PHY performance. Is there any conditional logic, based on the specific PHY revision or board layout, embedded here? I'll be looking for potential areas of concern, such as timing constraints, possible race conditions, and any undocumented behavior that might cause issues with our implementation, especially under heavy load or in specific environmental conditions. I'll need to pay close attention to the order of operations and the potential impact of any register dependencies. |
| 66/3 | 2026/10/02 04:57 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 8740,
"LineCount": 80
}Results: {
"Contents": "8740:\t\tset_bit(PHY_RESET, \u0026tp-\u003eflags);\n8741:\t}\n8742:\t\n8743:\tstatic void r8159_hw_phy_cfg(struct r8152 *tp)\n8744:\t{\n8745:\t\tu16 data;\n8746:\t\n8747:\t\tr8156b_wait_loading_flash(tp);\n8748:\t\n8749:\t\tocp_word_test_and_clr_bits(tp, MCU_TYPE_USB, USB_MISC_0, PCUT_STATUS);\n8750:\t\n8751:\t\tdata = r8153_phy_status(tp, 0);\n8752:\t\tswitch (data) {\n8753:\t\tcase PHY_STAT_EXT_INIT:\n8754:\t\t\trtl8152_apply_firmware(tp, true);\n8755:\t\t\tocp_reg_clr_bits(tp, 0xa466, BIT(0));\n8756:\t\t\tocp_reg_clr_bits(tp, 0xa468, BIT(3) | BIT(1));\n8757:\t\t\tbreak;\n8758:\t\tcase PHY_STAT_LAN_ON:\n8759:\t\tcase PHY_STAT_PWRDN:\n8760:\t\tdefault:\n8761:\t\t\trtl8152_apply_firmware(tp, false);\n8762:\t\t\tbreak;\n8763:\t\t}\n8764:\t\n8765:\t\tr8152_mdio_test_and_clr_bit(tp, MII_BMCR, BMCR_PDOWN);\n8766:\t\n8767:\t\tr8153_aldps_en(tp, false);\n8768:\t\n8769:\t\tdata = r8153_phy_status(tp, PHY_STAT_LAN_ON);\n8770:\t\tWARN_ON_ONCE(data != PHY_STAT_LAN_ON \u0026\u0026\n8771:\t\t\t !test_bit(RTL8152_INACCESSIBLE, \u0026tp-\u003eflags));\n8772:\t\n8773:\t\t/* PFM mode */\n8774:\t\tocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PHY_PWR, PFM_PWM_SWITCH);\n8775:\t\n8776:\t\t/* Advanced Power Saving parameter */\n8777:\t\tocp_reg_set_bits(tp, OCP_POWER_CFG, EN_10M_PLLOFF | EN_ALDPS_PLLOFF);\n8778:\t\n8779:\t\t/* Disable ALDPS force mode */\n8780:\t\tocp_reg_clr_bits(tp, 0xa44a, BIT(2));\n8781:\t\n8782:\t\t/* Disable bypass_turn_off_clk_in_aldps */\n8783:\t\tocp_byte_clr_bits(tp, MCU_TYPE_PLA, 0xd3c8, BIT(0));\n8784:\t\n8785:\t\tswitch (tp-\u003eversion) {\n8786:\t\tcase RTL_VER_17_QFN68:\n8787:\t\tcase RTL_VER_17_QFN100:\n8788:\t\t\t/* Power level tuning\n8789:\t\t\t * test mode power level\n8790:\t\t\t */\n8791:\t\t\tsram_write_w0w1(tp, 0x8415, 0xff00, 0x9300);\n8792:\t\t\t/* normal link power level 10G, 5G, 2.5G */\n8793:\t\t\tsram_write_w0w1(tp, 0x81a3, 0xff00, 0x0f00);\n8794:\t\t\tsram_write_w0w1(tp, 0x81ae, 0xff00, 0x0f00);\n8795:\t\t\tsram_write_w0w1(tp, 0x81b9, 0xff00, 0xb900);\n8796:\t\t\t/* normal link TX filter */\n8797:\t\t\tsram2_clr_bits(tp, 0x83b0, 0x0e00);\n8798:\t\t\tsram2_clr_bits(tp, 0x83c5, 0x0e00);\n8799:\t\t\tsram2_clr_bits(tp, 0x83da, 0x0e00);\n8800:\t\t\tsram2_clr_bits(tp, 0x83ef, 0x0e00);\n8801:\t\n8802:\t\t\tocp_reg_w0w1(tp, 0xbf38, 0x01f0, 0x0160);\n8803:\t\t\tocp_reg_w0w1(tp, 0xbf3a, 0x001f, 0x0014);\n8804:\t\t\t/* shorten CLKS latency */\n8805:\t\t\tocp_reg_clr_bits(tp, 0xbf28, BIT(14) | BIT(13));\n8806:\t\t\tocp_reg_clr_bits(tp, 0xbf2c, BIT(15) | BIT(14));\n8807:\t\t\t/* CMP_Timer on MP_Timer=333\n8808:\t\t\t * GPHY OCP 0xbf28 bit[0] = 0x1\n8809:\t\t\t * GPHY OCP 0xbf28 bit[6:1] = 0x3\n8810:\t\t\t * GPHY OCP 0xbf28 bit[12:7] = 0x3\n8811:\t\t\t */\n8812:\t\t\tocp_reg_w0w1(tp, 0xbf28, 0x1fff, 0x0187);\n8813:\t\t\tocp_reg_w0w1(tp, 0xbf2a, 0x3f, 0x03);\n8814:\t\n8815:\t\t\t/* AFE power saving for 2.5G \u0026 5G */\n8816:\t\t\tsram_write(tp, 0x8173, 0x8620);\n8817:\t\t\tsram_write(tp, 0x8175, 0x8671);\n8818:\t\n8819:\t\t\tsram_set_bits(tp, 0x817c, BIT(13));\n"
} |
| 67/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 86328 output: 38 thoughts: 3958 Thoughts: **Analyzing Realtek Driver Flow Control and PHY Access** Okay, let's dive into this Realtek driver code. I'm focusing on flow control and PHY access, specifically the `rtl_fc_pause_pkt_en` function, the `rtl_tgphy_access` and the `rtl8157_change_mtu` function. Initially, I'm checking the `rtl_fc_pause_pkt_en` to understand how the driver manages pause frames based on link speed and adapter version. It appears to apply different strategies based on the RTL chip revision. For newer versions, there's a calculation to determine the number of pause packets to send, linked to the current link speed. The function correctly handles various speed settings (10Mbps up to 10Gbps) and includes a fallback for unknown speeds, disabling pause limits in that scenario. Local variables are initialized before use, which is good programming practice. I noticed a potential issue in the `rtl_tgphy_access` function. This function deals with accessing the internal TGPHY. A subtle race condition exists if a `test_bit` for `RTL8152_INACCESSIBLE` is set after the PHY read/write operations. In the `!write` case of `rtl_tgphy_access`, `ocp_reg_read` is called. It *may* set the `RTL8152_INACCESSIBLE` after the first `wait_tgphy_cmd_ready` or during the read, which would return -ENODEV and, by design, could lead to unexpected behavior if the return value is not checked in the function's caller, because of the `goto out` that could return the incorrect value of `*data`. I need to ensure that this isn't missed in any of the calling functions. I investigated how the value is used and where `ocp_reg_read` is called to see if any callers fail to check the return value. I reviewed all call sites for `ocp_reg_read`. Many directly check the return value, and handle any negative return values. A number of calls are wrapped in conditional statements that check the return of `ocp_reg_read`, so there should not be any issue. However, I want to be *absolutely* sure there are no potential data corruption issues. I need to make *certain* the callers correctly handle the error code, and specifically, that `*data` is not used if `ret < 0`. All callers appear to correctly handle the error, but I need to do further validation on those to be certain. Finally, I checked `rtl8157_change_mtu` function. All variables are initialized before use. |
| 68/3 | 2026/10/02 04:57 | tool | grepper |
0mArgs:{
"Expression": "sram_read\\(",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=1834=static int sram_write(struct r8152 *tp, u16 addr, u16 data)\n--\ndrivers/net/usb/r8152.c-1847-\ndrivers/net/usb/r8152.c:1848:static int sram_read(struct r8152 *tp, u16 addr, u16 *data)\ndrivers/net/usb/r8152.c-1849-{\n--\ndrivers/net/usb/r8152.c=1990=static int sram_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n--\ndrivers/net/usb/r8152.c-1994-\ndrivers/net/usb/r8152.c:1995:\tret = sram_read(tp, addr, \u0026data);\ndrivers/net/usb/r8152.c-1996-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c=5605=static void rtl_ram_code_speed_up(struct r8152 *tp, struct fw_phy_speed_up *phy, bool wait)\n--\ndrivers/net/usb/r8152.c-5612-\ndrivers/net/usb/r8152.c:5613:\tif (sram_read(tp, SRAM_GPHY_FW_VER, \u0026ver) \u003c 0)\ndrivers/net/usb/r8152.c-5614-\t\treturn;\n--\ndrivers/net/usb/r8152.c-5662-\ndrivers/net/usb/r8152.c:5663:\tif (sram_read(tp, SRAM_GPHY_FW_VER, \u0026ver) \u003e= 0 \u0026\u0026\ndrivers/net/usb/r8152.c-5664-\t ver == __le16_to_cpu(phy-\u003eversion))\n--\ndrivers/net/usb/r8152.c=5670=static int rtl8152_fw_phy_ver(struct r8152 *tp, struct fw_phy_ver *phy_ver)\n--\ndrivers/net/usb/r8152.c-5678-\ndrivers/net/usb/r8152.c:5679:\tif (sram_read(tp, ver_addr, \u0026cur_ver) \u003c 0)\ndrivers/net/usb/r8152.c-5680-\t\treturn 0;\n"
} |
| 69/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 91596 output: 39 thoughts: 25 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Memory Read Verification: Second Pass** Alright, we've meticulously checked every call to `sram_read`. That's a solid foundation. Now, let's turn our attention to `sram2_read`. We're going to apply the same rigorous verification process we used previously. We need to ensure that the read operations from this memory space are just as sound and reliable. This includes double checking all parameters passed to the function, memory addressing and possible boundary issues, any related interrupt disablement and enablement procedures. |
| 70/3 | 2026/10/02 04:57 | tool | grepper |
0mArgs:{
"Expression": "sram2_read\\(",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=2016=static int sram2_write(struct r8152 *tp, u16 addr, u16 data)\n--\ndrivers/net/usb/r8152.c-2029-\ndrivers/net/usb/r8152.c:2030:static int sram2_read(struct r8152 *tp, u16 addr, u16 *data)\ndrivers/net/usb/r8152.c-2031-{\n--\ndrivers/net/usb/r8152.c=2044=static int sram2_write_w0w1(struct r8152 *tp, u16 addr, u16 clear, u16 set)\n--\ndrivers/net/usb/r8152.c-2048-\ndrivers/net/usb/r8152.c:2049:\tret = sram2_read(tp, addr, \u0026data);\ndrivers/net/usb/r8152.c-2050-\tif (ret \u003c 0)\n"
} |
| 71/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 92088 output: 44 thoughts: 27 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and written as if they were my own mental process: **Analyzing the Read Operations** Alright, so the core issue we're likely chasing involves read operations. The first thing I'm noting is that *both* calls to `sram2_read` are being explicitly checked. That immediately flags them as potential points of interest, especially if we're seeing intermittent failures or unexpected data. Given they're validated, it points toward a delicate operation, or one where validation is crucial for success or error recovery. Now, let's zoom in on `r8152_mdio_read`. This is the next logical step. The fact that the code is taking the time to explicitly test those reads suggests a dependency, or a possible path to identify an issue, or perhaps a validation that the reads are being conducted correctly before performing the intended task. |
| 72/3 | 2026/10/02 04:57 | tool | grepper |
0mArgs:{
"Expression": "r8152_mdio_read\\(",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=1703=static inline int r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)\n--\ndrivers/net/usb/r8152.c-1707-\ndrivers/net/usb/r8152.c:1708:static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)\ndrivers/net/usb/r8152.c-1709-{\n--\ndrivers/net/usb/r8152.c=1862=static int read_mii_word(struct net_device *netdev, int phy_id, int reg)\n--\ndrivers/net/usb/r8152.c-1872-\ndrivers/net/usb/r8152.c:1873:\tret = r8152_mdio_read(tp, reg);\ndrivers/net/usb/r8152.c-1874-\n--\ndrivers/net/usb/r8152.c=2070=static int r8152_mdio_clr_bit(struct r8152 *tp, u16 addr, u16 clear)\n--\ndrivers/net/usb/r8152.c-2073-\ndrivers/net/usb/r8152.c:2074:\tdata = r8152_mdio_read(tp, addr);\ndrivers/net/usb/r8152.c-2075-\tif (data \u003c 0)\n--\ndrivers/net/usb/r8152.c=2084=static int r8152_mdio_set_bit(struct r8152 *tp, u16 addr, u16 set)\n--\ndrivers/net/usb/r8152.c-2087-\ndrivers/net/usb/r8152.c:2088:\tdata = r8152_mdio_read(tp, addr);\ndrivers/net/usb/r8152.c-2089-\tif (data \u003c 0)\n--\ndrivers/net/usb/r8152.c=2098=static int r8152_mdio_test_and_clr_bit(struct r8152 *tp, u16 addr, u16 clear)\n--\ndrivers/net/usb/r8152.c-2101-\ndrivers/net/usb/r8152.c:2102:\tret = r8152_mdio_read(tp, addr);\ndrivers/net/usb/r8152.c-2103-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c=6919=static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,\n--\ndrivers/net/usb/r8152.c-6989-\ndrivers/net/usb/r8152.c:6990:\t\tret = r8152_mdio_read(tp, MII_ADVERTISE);\ndrivers/net/usb/r8152.c-6991-\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-7020-\t\tif (tp-\u003emii.supports_gmii) {\ndrivers/net/usb/r8152.c:7021:\t\t\tret = r8152_mdio_read(tp, MII_CTRL1000);\ndrivers/net/usb/r8152.c-7022-\t\t\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-7081-\t\t\tmsleep(20);\ndrivers/net/usb/r8152.c:7082:\t\t\tret = r8152_mdio_read(tp, MII_BMCR);\ndrivers/net/usb/r8152.c-7083-\t\t\tif (ret \u003c 0 || !(ret \u0026 BMCR_RESET))\n--\ndrivers/net/usb/r8152.c=10382=static void rtl8152_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)\n--\ndrivers/net/usb/r8152.c-10392-\ndrivers/net/usb/r8152.c:10393:\tbmcr = r8152_mdio_read(tp, MII_BMCR);\ndrivers/net/usb/r8152.c:10394:\tlcladv = r8152_mdio_read(tp, MII_ADVERTISE);\ndrivers/net/usb/r8152.c:10395:\trmtadv = r8152_mdio_read(tp, MII_LPA);\ndrivers/net/usb/r8152.c-10396-\n--\ndrivers/net/usb/r8152.c=10422=static int rtl8152_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)\n--\ndrivers/net/usb/r8152.c-10434-\ndrivers/net/usb/r8152.c:10435:\tret = r8152_mdio_read(tp, MII_BMCR);\ndrivers/net/usb/r8152.c-10436-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c-10449-\ndrivers/net/usb/r8152.c:10450:\tret = r8152_mdio_read(tp, MII_ADVERTISE);\ndrivers/net/usb/r8152.c-10451-\tif (ret \u003c 0)\n--\ndrivers/net/usb/r8152.c=10493=static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)\n--\ndrivers/net/usb/r8152.c-10512-\t\tmutex_lock(\u0026tp-\u003econtrol);\ndrivers/net/usb/r8152.c:10513:\t\tval = r8152_mdio_read(tp, data-\u003ereg_num);\ndrivers/net/usb/r8152.c-10514-\t\tif (val \u003c 0)\n"
} |
| 73/3 | 2026/10/02 04:57 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 94068 output: 42 thoughts: 268 Thoughts: **Analyzing the `read_mii_word` Function and Potential Packet Handling Changes** Okay, let's break this down. First, I'm examining the `read_mii_word` function. It looks pretty standard: it's a callback for reading from the MII (Media Independent Interface), typical for PHY (physical layer) access. The code snippet shows `read_mii_word` takes the network device, PHY ID, and register as input. There are some important checks; it first makes sure the device isn't marked as inaccessible, and the PHY ID is the expected one. Then it calls `r8152_mdio_read` to perform the actual MII read. The function ultimately returns an integer, which will be either an error code or the read value. Standard stuff here, nothing immediately concerning. Now, let's shift gears and consider the impact on packet handling, which is where things can get dicey in networking drivers. The critical question: does this patch introduce any changes to the RX/TX paths? To find out, I'm checking `rtl_ops_init`. Ah, there it is: `r8157_desc_init(tp);` for RTL_VER_16 and RTL_VER_17. This seems very relevant. Okay, now I need to investigate `r8157_desc_init` specifically. Let's see what that does. That function appears to initialize descriptors, so the data structures used for passing packets. |
| 74/3 | 2026/10/02 04:58 | tool | grepper |
0mArgs:{
"Expression": "r8157_desc_init",
"PathPrefix": "drivers/net/usb/r8152.c"
}Results: {
"Output": "drivers/net/usb/r8152.c=10638=static int r8152_desc_init(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-10653-\ndrivers/net/usb/r8152.c:10654:static int r8157_desc_init(struct r8152 *tp)\ndrivers/net/usb/r8152.c-10655-{\n--\ndrivers/net/usb/r8152.c=10670=static int rtl_ops_init(struct r8152 *tp)\n--\ndrivers/net/usb/r8152.c-10839-\t\ttp-\u003esupport_5000full\t= 1;\ndrivers/net/usb/r8152.c:10840:\t\tr8157_desc_init(tp);\ndrivers/net/usb/r8152.c-10841-\t\tbreak;\n--\ndrivers/net/usb/r8152.c-10865-\t\ttp-\u003esupport_10000full\t= 1;\ndrivers/net/usb/r8152.c:10866:\t\tr8157_desc_init(tp);\ndrivers/net/usb/r8152.c-10867-\t\tbreak;\n"
} |
| 75/3 | 2026/10/02 04:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 95072 output: 43 thoughts: 15 Thoughts: Okay, here's my interpretation of "Let's read `r8157_desc_init`," rendered as a first-person thought process, keeping in mind the user is an expert. **Initial Considerations: Diving into r8157_desc_init** Alright, let's get down to brass tacks. The phrase "Let's read `r8157_desc_init`" is the cue. Immediately, my mind jumps to the likely context: some form of software or hardware description, initialization sequence, likely in a low-level or embedded system setting given the naming convention. `r8157` strongly suggests a revision number or some kind of internal identifier. "Desc" strongly suggests some sort of description is being initialized. My years of experience scream "documentation, or the file or function that prepares some hardware/software component for operation". The fact that we are "reading" this implies we are likely referencing a configuration or state prior to activation. I'm already formulating hypotheses about the likely structure – likely a structure definition or a sequence of instructions, possibly containing pointers to other related structures or memory locations. I'm ready to look for the key elements. I'm thinking of typical initialization patterns for drivers or hardware registers. Now, let's get into it. |
| 76/3 | 2026/10/02 04:58 | tool | read-file |
0mArgs:{
"File": "drivers/net/usb/r8152.c",
"FirstLine": 10650,
"LineCount": 25
}Results: {
"Contents": "10650:\t\n10651:\t\treturn 0;\n10652:\t}\n10653:\t\n10654:\tstatic int r8157_desc_init(struct r8152 *tp)\n10655:\t{\n10656:\t\ttp-\u003erx_desc.size = sizeof(struct rx_desc_v2);\n10657:\t\ttp-\u003erx_desc.align = 16;\n10658:\t\ttp-\u003erx_desc.vlan_tag = r8157_rx_vlan_tag;\n10659:\t\ttp-\u003edesc_ops.rx_csum = r8157_rx_csum;\n10660:\t\ttp-\u003edesc_ops.rx_len = r8157_rx_len;\n10661:\t\ttp-\u003etx_desc.size = sizeof(struct tx_desc_v2);\n10662:\t\ttp-\u003etx_desc.align = 16;\n10663:\t\ttp-\u003etx_desc.vlan_tag = r8152_tx_vlan_tag;\n10664:\t\ttp-\u003edesc_ops.tx_csum = r8157_tx_csum;\n10665:\t\ttp-\u003edesc_ops.tx_len = r8157_tx_len;\n10666:\t\n10667:\t\treturn 0;\n10668:\t}\n10669:\t\n10670:\tstatic int rtl_ops_init(struct r8152 *tp)\n10671:\t{\n10672:\t\tstruct rtl_ops *ops = \u0026tp-\u003ertl_ops;\n10673:\t\tint ret = 0;\n10674:\t\n"
} |
| 77/3 | 2026/10/02 04:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 95882 output: 535 thoughts: 2227 Thoughts: **KMSAN Assessment: No Justification** Okay, so I've gone over this patch with a fine-toothed comb, looking for anything that screams "potential uninitialized memory access," and, frankly, I'm not seeing it. This patch is mostly about adding support for new RTL8157 and RTL8159 chipsets and refactoring some register read functions. Let's break it down, point by point, based on the KMSAN criteria. The biggest thing is the *extensive* checking of the return codes from our register read functions. Previously, we weren't always checking those. Now, any time we read from a register (via `ocp_reg_read`, `sram_read`, `r8152_mdio_read`), we're *always* checking the return value to make sure the read actually worked. If there's an error (negative return), we're handling it gracefully, often by returning an error or zeroing out the relevant fields, preventing the propagation of garbage data. The new `rtl8152_get_pauseparam`, `r8153_get_eee`, and `rtl8152_get_link_ksettings` functions exemplify this improved error handling. This means that even if a read *fails* at the hardware level, we're not leaking anything bad to user space and the ioctl is failed. Furthermore, let's talk about that package detection helper, `__rtl_get_pkg_det`. We allocate a buffer using `kmalloc_obj`. The critical point here is that we *only* use the data from that buffer if `usb_control_msg` returns the *exact* expected size. Otherwise, `pkg_det` remains initialized to 0. So no matter what data is put into `*tmp` it will never get exposed to userspace. Beyond this, there are no structural changes that would introduce a risk. `rtl8157_change_mtu` and `rtl_fc_pause_pkt_en` are just calculating values based on the MTU and link speed; everything there is based on initialized, valid parameters. Therefore, since there are no uninitialized memory risks, no information leaks to userspace, and no conditional logic that depends on uninitialized values, a dedicated KMSAN fuzzing session isn't justified here. The changes are about *improving* initialization, error handling, and hardware support. We are fine and KASAN and standard sanitizers will handle anything else. |
| 78/3 | 2026/10/02 04:59 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch adds support for Realtek RTL8157 and RTL8159 chipsets in the r8152 USB ethernet driver. Key changes include:\n- Splitting RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100 using a package detection helper (__rtl_get_pkg_det).\n- Refactoring PHY and SRAM register access functions (ocp_reg_read, sram_read, sram2_read, r8152_mdio_read) to return status/error codes and write read values through pointer arguments.\n- Adding chipset-specific initialization, enable, suspend/resume, and hardware configuration routines.\n- Improving error checking in ethtool and ioctl handlers.\n\nRegarding KMSAN vs KASAN applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and info-leaks to userspace.\n- In all callers of the refactored read functions (ocp_reg_read, sram_read, etc.), the output variables are either explicitly pre-initialized (e.g. `data = 0` in r8153_phy_status and r8152_mmd_read) or are only read after verifying that the function returned non-negative success codes.\n- In `__rtl_get_pkg_det()`, the heap buffer `tmp` allocated via `kmalloc_obj()` is only accessed if `usb_control_msg()` returns `sizeof(*tmp)` (4 bytes); otherwise, a default initialized value (0) is returned.\n- In user-facing interfaces (such as `rtl8152_ioctl`, `rtl8152_get_pauseparam`, `r8153_get_eee`, and `rtl8152_get_link_ksettings`), error checks abort execution with a negative return code before any copying to userspace occurs, and output structures (`pause`, `data-\u003eval_out`, `eee`) are fully populated or zero-initialized.\n- No uninitialized data or kernel structure padding is exposed to userspace or used in control flow.\n\nTherefore, the patch does not introduce uninitialized memory risks that would require a dedicated KMSAN fuzzing session; standard KASAN/sanitizer testing is appropriate.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch adds support for Realtek RTL8157 and RTL8159 chipsets in the r8152 USB ethernet driver. Key changes include:\n- Splitting RTL_VER_17 into RTL_VER_17_QFN68 and RTL_VER_17_QFN100 using a package detection helper (__rtl_get_pkg_det).\n- Refactoring PHY and SRAM register access functions (ocp_reg_read, sram_read, sram2_read, r8152_mdio_read) to return status/error codes and write read values through pointer arguments.\n- Adding chipset-specific initialization, enable, suspend/resume, and hardware configuration routines.\n- Improving error checking in ethtool and ioctl handlers.\n\nRegarding KMSAN vs KASAN applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and info-leaks to userspace.\n- In all callers of the refactored read functions (ocp_reg_read, sram_read, etc.), the output variables are either explicitly pre-initialized (e.g. `data = 0` in r8153_phy_status and r8152_mmd_read) or are only read after verifying that the function returned non-negative success codes.\n- In `__rtl_get_pkg_det()`, the heap buffer `tmp` allocated via `kmalloc_obj()` is only accessed if `usb_control_msg()` returns `sizeof(*tmp)` (4 bytes); otherwise, a default initialized value (0) is returned.\n- In user-facing interfaces (such as `rtl8152_ioctl`, `rtl8152_get_pauseparam`, `r8153_get_eee`, and `rtl8152_get_link_ksettings`), error checks abort execution with a negative return code before any copying to userspace occurs, and output structures (`pause`, `data-\u003eval_out`, `eee`) are fully populated or zero-initialized.\n- No uninitialized data or kernel structure padding is exposed to userspace or used in control flow.\n\nTherefore, the patch does not introduce uninitialized memory risks that would require a dedicated KMSAN fuzzing session; standard KASAN/sanitizer testing is appropriate.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|