linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153
@ 2020-10-29 12:33 Hayes Wang
  2020-10-29 15:04 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Hayes Wang @ 2020-10-29 12:33 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, Hayes Wang

Support ECM mode based on cdc_ether with relative mii functions,
when CONFIG_USB_RTL8152 is not set, or the device is not supported
by r8152 driver.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/Makefile    |   2 +-
 drivers/net/usb/r8152.c     |   5 +-
 drivers/net/usb/r8153_ecm.c | 174 ++++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/usb/r8153_ecm.c

diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 99fd12be2111..99381e6bea78 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
-obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
+obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
 obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b1770489aca5..1b5d10f1de5f 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -6615,7 +6615,7 @@ static int rtl_fw_init(struct r8152 *tp)
 	return 0;
 }
 
-static u8 rtl_get_version(struct usb_interface *intf)
+u8 rtl8152_get_version(struct usb_interface *intf)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	u32 ocp_data = 0;
@@ -6673,12 +6673,13 @@ static u8 rtl_get_version(struct usb_interface *intf)
 
 	return version;
 }
+EXPORT_SYMBOL_GPL(rtl8152_get_version);
 
 static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
-	u8 version = rtl_get_version(intf);
+	u8 version = rtl8152_get_version(intf);
 	struct r8152 *tp;
 	struct net_device *netdev;
 	int ret;
diff --git a/drivers/net/usb/r8153_ecm.c b/drivers/net/usb/r8153_ecm.c
new file mode 100644
index 000000000000..723841525a6a
--- /dev/null
+++ b/drivers/net/usb/r8153_ecm.c
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+
+#define RTL8153_CMD		0X05
+#define RTL8153_REQT_READ	0xc0
+#define RTL8153_REQT_WRITE	0x40
+
+#define MCU_TYPE_PLA		0x0100
+#define OCP_BASE		0xe86c
+
+#define BYTE_EN_WORD		0x33
+
+#define REALTEK_VENDOR_ID	0x0bda
+
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+extern u8 rtl8152_get_version(struct usb_interface *intf);
+#endif
+
+static int pla_read_word(struct usbnet *dev, u16 index)
+{
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	if (shift)
+		byen <<= shift;
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8153_CMD, RTL8153_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+	if (ret < 0)
+		goto out;
+
+	ret = __le32_to_cpu(tmp);
+	ret >>= (shift * 8);
+	ret &= 0xffff;
+
+out:
+	return ret;
+}
+
+static int pla_write_word(struct usbnet *dev, u16 index, u32 data)
+{
+	u32 mask = 0xffff;
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	data &= mask;
+
+	if (shift) {
+		byen <<= shift;
+		mask <<= (shift * 8);
+		data <<= (shift * 8);
+	}
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8153_CMD, RTL8153_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+	if (ret < 0)
+		goto out;
+
+	data |= __le32_to_cpu(tmp) & ~mask;
+	tmp = __cpu_to_le32(data);
+
+	ret = usbnet_write_cmd(dev, RTL8153_CMD, RTL8153_REQT_WRITE, index,
+			       MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+out:
+	return ret;
+}
+
+static int r8153_ecm_mdio_read(struct net_device *netdev, int phy_id, int reg)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		goto out;
+
+	ret = pla_read_word(dev, 0xb400 + reg * 2);
+
+out:
+	return ret;
+}
+
+static void r8153_ecm_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		return;
+
+	ret = pla_write_word(dev, 0xb400 + reg * 2, val);
+}
+
+static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	int status;
+
+	status = usbnet_cdc_bind(dev, intf);
+	if (status < 0)
+		return status;
+
+	dev->mii.dev = dev->net;
+	dev->mii.mdio_read = r8153_ecm_mdio_read;
+	dev->mii.mdio_write = r8153_ecm_mdio_write;
+	dev->mii.reg_num_mask = 0x1f;
+	dev->mii.supports_gmii = 1;
+
+	return status;
+}
+
+static const struct driver_info r8153_info = {
+	.description =	"RTL8153 ECM Device",
+	.flags =	FLAG_ETHER,
+	.bind =		r8153_bind,
+	.unbind =	usbnet_cdc_unbind,
+	.status =	usbnet_cdc_status,
+	.manage_power =	usbnet_manage_power,
+};
+
+static const struct usb_device_id products[] = {
+{
+	USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	.driver_info = (unsigned long)&r8153_info,
+},
+
+	{ },		/* END */
+};
+MODULE_DEVICE_TABLE(usb, products);
+
+static int rtl8153_ecm_probe(struct usb_interface *intf,
+			     const struct usb_device_id *id)
+{
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+	if (rtl8152_get_version(intf))
+		return -ENODEV;
+#endif
+
+	return usbnet_probe(intf, id);
+}
+
+static struct usb_driver r8153_ecm_driver = {
+	.name =		"r8153_ecm",
+	.id_table =	products,
+	.probe =	rtl8153_ecm_probe,
+	.disconnect =	usbnet_disconnect,
+	.suspend =	usbnet_suspend,
+	.resume =	usbnet_resume,
+	.reset_resume =	usbnet_resume,
+	.supports_autosuspend = 1,
+	.disable_hub_initiated_lpm = 1,
+};
+
+module_usb_driver(r8153_ecm_driver);
+
+MODULE_AUTHOR("Hayes Wang");
+MODULE_DESCRIPTION("Realtek USB ECM device");
+MODULE_LICENSE("GPL");
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-10-29 12:33 [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
@ 2020-10-29 15:04 ` kernel test robot
  2020-10-30  3:23 ` [PATCH net-next v2] " Hayes Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 27+ messages in thread
From: kernel test robot @ 2020-10-29 15:04 UTC (permalink / raw)
  To: Hayes Wang, netdev; +Cc: kbuild-all, nic_swsd, linux-kernel, Hayes Wang

[-- Attachment #1: Type: text/plain, Size: 3482 bytes --]

Hi Hayes,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net/master]
[also build test WARNING on net-next/master ipvs/master linus/master v5.10-rc1 next-20201029]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hayes-Wang/net-usb-r8153_ecm-support-ECM-mode-for-RTL8153/20201029-203440
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git d6535dca28859d8d9ef80894eb287b2ac35a32e8
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/e34498795de95fbccb0f2feee72cd8df723f9fd3
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Hayes-Wang/net-usb-r8153_ecm-support-ECM-mode-for-RTL8153/20201029-203440
        git checkout e34498795de95fbccb0f2feee72cd8df723f9fd3
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=xtensa 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/net/usb/r8152.c:6618:4: warning: no previous prototype for 'rtl8152_get_version' [-Wmissing-prototypes]
    6618 | u8 rtl8152_get_version(struct usb_interface *intf)
         |    ^~~~~~~~~~~~~~~~~~~

vim +/rtl8152_get_version +6618 drivers/net/usb/r8152.c

  6617	
> 6618	u8 rtl8152_get_version(struct usb_interface *intf)
  6619	{
  6620		struct usb_device *udev = interface_to_usbdev(intf);
  6621		u32 ocp_data = 0;
  6622		__le32 *tmp;
  6623		u8 version;
  6624		int ret;
  6625	
  6626		tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
  6627		if (!tmp)
  6628			return 0;
  6629	
  6630		ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  6631				      RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
  6632				      PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
  6633		if (ret > 0)
  6634			ocp_data = (__le32_to_cpu(*tmp) >> 16) & VERSION_MASK;
  6635	
  6636		kfree(tmp);
  6637	
  6638		switch (ocp_data) {
  6639		case 0x4c00:
  6640			version = RTL_VER_01;
  6641			break;
  6642		case 0x4c10:
  6643			version = RTL_VER_02;
  6644			break;
  6645		case 0x5c00:
  6646			version = RTL_VER_03;
  6647			break;
  6648		case 0x5c10:
  6649			version = RTL_VER_04;
  6650			break;
  6651		case 0x5c20:
  6652			version = RTL_VER_05;
  6653			break;
  6654		case 0x5c30:
  6655			version = RTL_VER_06;
  6656			break;
  6657		case 0x4800:
  6658			version = RTL_VER_07;
  6659			break;
  6660		case 0x6000:
  6661			version = RTL_VER_08;
  6662			break;
  6663		case 0x6010:
  6664			version = RTL_VER_09;
  6665			break;
  6666		default:
  6667			version = RTL_VER_UNKNOWN;
  6668			dev_info(&intf->dev, "Unknown version 0x%04x\n", ocp_data);
  6669			break;
  6670		}
  6671	
  6672		dev_dbg(&intf->dev, "Detected version 0x%04x\n", version);
  6673	
  6674		return version;
  6675	}
  6676	EXPORT_SYMBOL_GPL(rtl8152_get_version);
  6677	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 66066 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-10-29 12:33 [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
  2020-10-29 15:04 ` kernel test robot
@ 2020-10-30  3:23 ` Hayes Wang
  2020-10-31 23:08   ` Jakub Kicinski
  2020-11-03  9:46 ` [PATCH net-next v3 0/2] drivers/net/usb: " Hayes Wang
  2020-11-04  2:19 ` [PATCH net-next v2 RESEND] " Hayes Wang
  3 siblings, 1 reply; 27+ messages in thread
From: Hayes Wang @ 2020-10-30  3:23 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb, Hayes Wang

Support ECM mode based on cdc_ether with relative mii functions,
when CONFIG_USB_RTL8152 is not set, or the device is not supported
by r8152 driver.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
v2:
Add include/linux/usb/r8152.h to avoid the warning about
no previous prototype for rtl8152_get_version.

 drivers/net/usb/Makefile    |   2 +-
 drivers/net/usb/r8152.c     |  30 +------
 drivers/net/usb/r8153_ecm.c | 162 ++++++++++++++++++++++++++++++++++++
 include/linux/usb/r8152.h   |  37 ++++++++
 4 files changed, 204 insertions(+), 27 deletions(-)
 create mode 100644 drivers/net/usb/r8153_ecm.c
 create mode 100644 include/linux/usb/r8152.h

diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 99fd12be2111..99381e6bea78 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
-obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
+obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
 obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b1770489aca5..7d2523d96c51 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -26,6 +26,7 @@
 #include <linux/acpi.h>
 #include <linux/firmware.h>
 #include <crypto/hash.h>
+#include <linux/usb/r8152.h>
 
 /* Information for net-next */
 #define NETNEXT_VERSION		"11"
@@ -653,18 +654,6 @@ enum rtl_register_content {
 
 #define INTR_LINK		0x0004
 
-#define RTL8152_REQT_READ	0xc0
-#define RTL8152_REQT_WRITE	0x40
-#define RTL8152_REQ_GET_REGS	0x05
-#define RTL8152_REQ_SET_REGS	0x05
-
-#define BYTE_EN_DWORD		0xff
-#define BYTE_EN_WORD		0x33
-#define BYTE_EN_BYTE		0x11
-#define BYTE_EN_SIX_BYTES	0x3f
-#define BYTE_EN_START_MASK	0x0f
-#define BYTE_EN_END_MASK	0xf0
-
 #define RTL8153_MAX_PACKET	9216 /* 9K */
 #define RTL8153_MAX_MTU		(RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \
 				 ETH_FCS_LEN)
@@ -689,21 +678,9 @@ enum rtl8152_flags {
 	LENOVO_MACPASSTHRU,
 };
 
-/* Define these values to match your device */
-#define VENDOR_ID_REALTEK		0x0bda
-#define VENDOR_ID_MICROSOFT		0x045e
-#define VENDOR_ID_SAMSUNG		0x04e8
-#define VENDOR_ID_LENOVO		0x17ef
-#define VENDOR_ID_LINKSYS		0x13b1
-#define VENDOR_ID_NVIDIA		0x0955
-#define VENDOR_ID_TPLINK		0x2357
-
 #define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
 #define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
 
-#define MCU_TYPE_PLA			0x0100
-#define MCU_TYPE_USB			0x0000
-
 struct tally_counter {
 	__le64	tx_packets;
 	__le64	rx_packets;
@@ -6615,7 +6592,7 @@ static int rtl_fw_init(struct r8152 *tp)
 	return 0;
 }
 
-static u8 rtl_get_version(struct usb_interface *intf)
+u8 rtl8152_get_version(struct usb_interface *intf)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	u32 ocp_data = 0;
@@ -6673,12 +6650,13 @@ static u8 rtl_get_version(struct usb_interface *intf)
 
 	return version;
 }
+EXPORT_SYMBOL_GPL(rtl8152_get_version);
 
 static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
-	u8 version = rtl_get_version(intf);
+	u8 version = rtl8152_get_version(intf);
 	struct r8152 *tp;
 	struct net_device *netdev;
 	int ret;
diff --git a/drivers/net/usb/r8153_ecm.c b/drivers/net/usb/r8153_ecm.c
new file mode 100644
index 000000000000..2c3fabd38b16
--- /dev/null
+++ b/drivers/net/usb/r8153_ecm.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/usb/r8152.h>
+
+#define OCP_BASE		0xe86c
+
+static int pla_read_word(struct usbnet *dev, u16 index)
+{
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	if (shift)
+		byen <<= shift;
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+	if (ret < 0)
+		goto out;
+
+	ret = __le32_to_cpu(tmp);
+	ret >>= (shift * 8);
+	ret &= 0xffff;
+
+out:
+	return ret;
+}
+
+static int pla_write_word(struct usbnet *dev, u16 index, u32 data)
+{
+	u32 mask = 0xffff;
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	data &= mask;
+
+	if (shift) {
+		byen <<= shift;
+		mask <<= (shift * 8);
+		data <<= (shift * 8);
+	}
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+	if (ret < 0)
+		goto out;
+
+	data |= __le32_to_cpu(tmp) & ~mask;
+	tmp = __cpu_to_le32(data);
+
+	ret = usbnet_write_cmd(dev, RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, index,
+			       MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+out:
+	return ret;
+}
+
+static int r8153_ecm_mdio_read(struct net_device *netdev, int phy_id, int reg)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		goto out;
+
+	ret = pla_read_word(dev, 0xb400 + reg * 2);
+
+out:
+	return ret;
+}
+
+static void r8153_ecm_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		return;
+
+	ret = pla_write_word(dev, 0xb400 + reg * 2, val);
+}
+
+static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	int status;
+
+	status = usbnet_cdc_bind(dev, intf);
+	if (status < 0)
+		return status;
+
+	dev->mii.dev = dev->net;
+	dev->mii.mdio_read = r8153_ecm_mdio_read;
+	dev->mii.mdio_write = r8153_ecm_mdio_write;
+	dev->mii.reg_num_mask = 0x1f;
+	dev->mii.supports_gmii = 1;
+
+	return status;
+}
+
+static const struct driver_info r8153_info = {
+	.description =	"RTL8153 ECM Device",
+	.flags =	FLAG_ETHER,
+	.bind =		r8153_bind,
+	.unbind =	usbnet_cdc_unbind,
+	.status =	usbnet_cdc_status,
+	.manage_power =	usbnet_manage_power,
+};
+
+static const struct usb_device_id products[] = {
+{
+	USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID_REALTEK, 0x8153, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	.driver_info = (unsigned long)&r8153_info,
+},
+
+	{ },		/* END */
+};
+MODULE_DEVICE_TABLE(usb, products);
+
+static int rtl8153_ecm_probe(struct usb_interface *intf,
+			     const struct usb_device_id *id)
+{
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+	if (rtl8152_get_version(intf))
+		return -ENODEV;
+#endif
+
+	return usbnet_probe(intf, id);
+}
+
+static struct usb_driver r8153_ecm_driver = {
+	.name =		"r8153_ecm",
+	.id_table =	products,
+	.probe =	rtl8153_ecm_probe,
+	.disconnect =	usbnet_disconnect,
+	.suspend =	usbnet_suspend,
+	.resume =	usbnet_resume,
+	.reset_resume =	usbnet_resume,
+	.supports_autosuspend = 1,
+	.disable_hub_initiated_lpm = 1,
+};
+
+module_usb_driver(r8153_ecm_driver);
+
+MODULE_AUTHOR("Hayes Wang");
+MODULE_DESCRIPTION("Realtek USB ECM device");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/r8152.h b/include/linux/usb/r8152.h
new file mode 100644
index 000000000000..20d88b1defc3
--- /dev/null
+++ b/include/linux/usb/r8152.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *  Copyright (c) 2020 Realtek Semiconductor Corp. All rights reserved.
+ */
+
+#ifndef	__LINUX_R8152_H
+#define __LINUX_R8152_H
+
+#define RTL8152_REQT_READ		0xc0
+#define RTL8152_REQT_WRITE		0x40
+#define RTL8152_REQ_GET_REGS		0x05
+#define RTL8152_REQ_SET_REGS		0x05
+
+#define BYTE_EN_DWORD			0xff
+#define BYTE_EN_WORD			0x33
+#define BYTE_EN_BYTE			0x11
+#define BYTE_EN_SIX_BYTES		0x3f
+#define BYTE_EN_START_MASK		0x0f
+#define BYTE_EN_END_MASK		0xf0
+
+#define MCU_TYPE_PLA			0x0100
+#define MCU_TYPE_USB			0x0000
+
+/* Define these values to match your device */
+#define VENDOR_ID_REALTEK		0x0bda
+#define VENDOR_ID_MICROSOFT		0x045e
+#define VENDOR_ID_SAMSUNG		0x04e8
+#define VENDOR_ID_LENOVO		0x17ef
+#define VENDOR_ID_LINKSYS		0x13b1
+#define VENDOR_ID_NVIDIA		0x0955
+#define VENDOR_ID_TPLINK		0x2357
+
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+extern u8 rtl8152_get_version(struct usb_interface *intf);
+#endif
+
+#endif /* __LINUX_R8152_H */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-10-30  3:23 ` [PATCH net-next v2] " Hayes Wang
@ 2020-10-31 23:08   ` Jakub Kicinski
  2020-11-02  7:20     ` Hayes Wang
  0 siblings, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-10-31 23:08 UTC (permalink / raw)
  To: Hayes Wang; +Cc: netdev, nic_swsd, linux-kernel, linux-usb

On Fri, 30 Oct 2020 11:23:08 +0800 Hayes Wang wrote:
> Support ECM mode based on cdc_ether with relative mii functions,
> when CONFIG_USB_RTL8152 is not set, or the device is not supported
> by r8152 driver.
> 
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>

Can you describe the use case in more detail?

AFAICT r8152 defines a match for the exact same device.
Does it not mean that which driver is used will be somewhat random 
if both are built?

> +/* Define these values to match your device */
> +#define VENDOR_ID_REALTEK		0x0bda
> +#define VENDOR_ID_MICROSOFT		0x045e
> +#define VENDOR_ID_SAMSUNG		0x04e8
> +#define VENDOR_ID_LENOVO		0x17ef
> +#define VENDOR_ID_LINKSYS		0x13b1
> +#define VENDOR_ID_NVIDIA		0x0955
> +#define VENDOR_ID_TPLINK		0x2357

$ git grep 0x2357 | grep -i tplink
drivers/net/usb/cdc_ether.c:#define TPLINK_VENDOR_ID	0x2357
drivers/net/usb/r8152.c:#define VENDOR_ID_TPLINK		0x2357
drivers/usb/serial/option.c:#define TPLINK_VENDOR_ID			0x2357

$ git grep 0x17ef | grep -i lenovo
drivers/hid/hid-ids.h:#define USB_VENDOR_ID_LENOVO		0x17ef
drivers/hid/wacom.h:#define USB_VENDOR_ID_LENOVO	0x17ef
drivers/net/usb/cdc_ether.c:#define LENOVO_VENDOR_ID	0x17ef
drivers/net/usb/r8152.c:#define VENDOR_ID_LENOVO		0x17ef

Time to consolidate those vendor id defines perhaps?

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-10-31 23:08   ` Jakub Kicinski
@ 2020-11-02  7:20     ` Hayes Wang
  2020-11-02 19:47       ` Jakub Kicinski
  0 siblings, 1 reply; 27+ messages in thread
From: Hayes Wang @ 2020-11-02  7:20 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, nic_swsd, linux-kernel, linux-usb

Jakub Kicinski <kuba@kernel.org>
[...]
> Can you describe the use case in more detail?
> 
> AFAICT r8152 defines a match for the exact same device.
> Does it not mean that which driver is used will be somewhat random
> if both are built?

I export rtl_get_version() from r8152. It would return none zero
value if r8152 could support this device. Both r8152 and r8153_ecm
would check the return value of rtl_get_version() in porbe().
Therefore, if rtl_get_version() return none zero value, the r8152
is used for the device with vendor mode. Otherwise, the r8153_ecm
is used for the device with ECM mode.

> > +/* Define these values to match your device */
> > +#define VENDOR_ID_REALTEK		0x0bda
> > +#define VENDOR_ID_MICROSOFT		0x045e
> > +#define VENDOR_ID_SAMSUNG		0x04e8
> > +#define VENDOR_ID_LENOVO		0x17ef
> > +#define VENDOR_ID_LINKSYS		0x13b1
> > +#define VENDOR_ID_NVIDIA		0x0955
> > +#define VENDOR_ID_TPLINK		0x2357
> 
> $ git grep 0x2357 | grep -i tplink
> drivers/net/usb/cdc_ether.c:#define TPLINK_VENDOR_ID	0x2357
> drivers/net/usb/r8152.c:#define VENDOR_ID_TPLINK		0x2357
> drivers/usb/serial/option.c:#define TPLINK_VENDOR_ID			0x2357
> 
> $ git grep 0x17ef | grep -i lenovo
> drivers/hid/hid-ids.h:#define USB_VENDOR_ID_LENOVO		0x17ef
> drivers/hid/wacom.h:#define USB_VENDOR_ID_LENOVO	0x17ef
> drivers/net/usb/cdc_ether.c:#define LENOVO_VENDOR_ID	0x17ef
> drivers/net/usb/r8152.c:#define VENDOR_ID_LENOVO		0x17ef
> 
> Time to consolidate those vendor id defines perhaps?

It seems that there is no such header file which I could include
or add the new vendor IDs.

Best Regards,
Hayes




^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-02  7:20     ` Hayes Wang
@ 2020-11-02 19:47       ` Jakub Kicinski
  2020-11-03  9:32         ` Greg Kroah-Hartman
  0 siblings, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-11-02 19:47 UTC (permalink / raw)
  To: Hayes Wang, Greg Kroah-Hartman
  Cc: netdev, nic_swsd, linux-kernel, linux-usb, Oliver Neukum

On Mon, 2 Nov 2020 07:20:15 +0000 Hayes Wang wrote:
> Jakub Kicinski <kuba@kernel.org>
> > Can you describe the use case in more detail?
> > 
> > AFAICT r8152 defines a match for the exact same device.
> > Does it not mean that which driver is used will be somewhat random
> > if both are built?  
> 
> I export rtl_get_version() from r8152. It would return none zero
> value if r8152 could support this device. Both r8152 and r8153_ecm
> would check the return value of rtl_get_version() in porbe().
> Therefore, if rtl_get_version() return none zero value, the r8152
> is used for the device with vendor mode. Otherwise, the r8153_ecm
> is used for the device with ECM mode.

Oh, I see, I missed that the rtl_get_version() checking is the inverse
of r8152.

> > > +/* Define these values to match your device */
> > > +#define VENDOR_ID_REALTEK		0x0bda
> > > +#define VENDOR_ID_MICROSOFT		0x045e
> > > +#define VENDOR_ID_SAMSUNG		0x04e8
> > > +#define VENDOR_ID_LENOVO		0x17ef
> > > +#define VENDOR_ID_LINKSYS		0x13b1
> > > +#define VENDOR_ID_NVIDIA		0x0955
> > > +#define VENDOR_ID_TPLINK		0x2357  
> > 
> > $ git grep 0x2357 | grep -i tplink
> > drivers/net/usb/cdc_ether.c:#define TPLINK_VENDOR_ID	0x2357
> > drivers/net/usb/r8152.c:#define VENDOR_ID_TPLINK		0x2357
> > drivers/usb/serial/option.c:#define TPLINK_VENDOR_ID			0x2357
> > 
> > $ git grep 0x17ef | grep -i lenovo
> > drivers/hid/hid-ids.h:#define USB_VENDOR_ID_LENOVO		0x17ef
> > drivers/hid/wacom.h:#define USB_VENDOR_ID_LENOVO	0x17ef
> > drivers/net/usb/cdc_ether.c:#define LENOVO_VENDOR_ID	0x17ef
> > drivers/net/usb/r8152.c:#define VENDOR_ID_LENOVO		0x17ef
> > 
> > Time to consolidate those vendor id defines perhaps?  
> 
> It seems that there is no such header file which I could include
> or add the new vendor IDs.

Please create one. (Adding Greg KH to the recipients, in case there is
a reason that USB subsystem doesn't have a common vendor id header.)

Also please make sure to add Oliver to the CC for v3, to make sure the
reuse of CDC_ETHER is okay.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-02 19:47       ` Jakub Kicinski
@ 2020-11-03  9:32         ` Greg Kroah-Hartman
  2020-11-03  9:51           ` Hayes Wang
  2020-11-03 16:15           ` Jakub Kicinski
  0 siblings, 2 replies; 27+ messages in thread
From: Greg Kroah-Hartman @ 2020-11-03  9:32 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Hayes Wang, netdev, nic_swsd, linux-kernel, linux-usb, Oliver Neukum

On Mon, Nov 02, 2020 at 11:47:18AM -0800, Jakub Kicinski wrote:
> On Mon, 2 Nov 2020 07:20:15 +0000 Hayes Wang wrote:
> > Jakub Kicinski <kuba@kernel.org>
> > > Can you describe the use case in more detail?
> > > 
> > > AFAICT r8152 defines a match for the exact same device.
> > > Does it not mean that which driver is used will be somewhat random
> > > if both are built?  
> > 
> > I export rtl_get_version() from r8152. It would return none zero
> > value if r8152 could support this device. Both r8152 and r8153_ecm
> > would check the return value of rtl_get_version() in porbe().
> > Therefore, if rtl_get_version() return none zero value, the r8152
> > is used for the device with vendor mode. Otherwise, the r8153_ecm
> > is used for the device with ECM mode.
> 
> Oh, I see, I missed that the rtl_get_version() checking is the inverse
> of r8152.
> 
> > > > +/* Define these values to match your device */
> > > > +#define VENDOR_ID_REALTEK		0x0bda
> > > > +#define VENDOR_ID_MICROSOFT		0x045e
> > > > +#define VENDOR_ID_SAMSUNG		0x04e8
> > > > +#define VENDOR_ID_LENOVO		0x17ef
> > > > +#define VENDOR_ID_LINKSYS		0x13b1
> > > > +#define VENDOR_ID_NVIDIA		0x0955
> > > > +#define VENDOR_ID_TPLINK		0x2357  
> > > 
> > > $ git grep 0x2357 | grep -i tplink
> > > drivers/net/usb/cdc_ether.c:#define TPLINK_VENDOR_ID	0x2357
> > > drivers/net/usb/r8152.c:#define VENDOR_ID_TPLINK		0x2357
> > > drivers/usb/serial/option.c:#define TPLINK_VENDOR_ID			0x2357
> > > 
> > > $ git grep 0x17ef | grep -i lenovo
> > > drivers/hid/hid-ids.h:#define USB_VENDOR_ID_LENOVO		0x17ef
> > > drivers/hid/wacom.h:#define USB_VENDOR_ID_LENOVO	0x17ef
> > > drivers/net/usb/cdc_ether.c:#define LENOVO_VENDOR_ID	0x17ef
> > > drivers/net/usb/r8152.c:#define VENDOR_ID_LENOVO		0x17ef
> > > 
> > > Time to consolidate those vendor id defines perhaps?  
> > 
> > It seems that there is no such header file which I could include
> > or add the new vendor IDs.
> 
> Please create one. (Adding Greg KH to the recipients, in case there is
> a reason that USB subsystem doesn't have a common vendor id header.)

There is a reason, it's a nightmare to maintain and handle merges for,
just don't do it.

Read the comments at the top of the pci_ids.h file if you are curious
why we don't even do this for PCI device ids anymore for the past 10+
years.

So no, please do not create such a common file, it is not needed or a
good idea.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next v3 0/2] drivers/net/usb: support ECM mode for RTL8153
  2020-10-29 12:33 [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
  2020-10-29 15:04 ` kernel test robot
  2020-10-30  3:23 ` [PATCH net-next v2] " Hayes Wang
@ 2020-11-03  9:46 ` Hayes Wang
  2020-11-03  9:46   ` [PATCH net-next v3 1/2] include/linux/usb: new header file for the vendor ID of USB devices Hayes Wang
  2020-11-03  9:46   ` [PATCH net-next v3 2/2] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
  2020-11-04  2:19 ` [PATCH net-next v2 RESEND] " Hayes Wang
  3 siblings, 2 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-03  9:46 UTC (permalink / raw)
  To: netdev, gregkh; +Cc: nic_swsd, linux-kernel, linux-usb, oliver, Hayes Wang

v3:
Move original patch to #2. And add a new patch #1 to consolidate vendor ID
of USB devices.

v2:
Add include/linux/usb/r8152.h to avoid the warning about
no previous prototype for rtl8152_get_version.

Hayes Wang (2):
  include/linux/usb: new header file for the vendor ID of USB devices
  net/usb/r8153_ecm: support ECM mode for RTL8153

 drivers/net/usb/Makefile          |   2 +-
 drivers/net/usb/cdc_ether.c       |  93 +++++++----------
 drivers/net/usb/r8152.c           |  68 +++++--------
 drivers/net/usb/r8153_ecm.c       | 162 ++++++++++++++++++++++++++++++
 include/linux/usb/r8152.h         |  30 ++++++
 include/linux/usb/usb_vendor_id.h |  51 ++++++++++
 6 files changed, 306 insertions(+), 100 deletions(-)
 create mode 100644 drivers/net/usb/r8153_ecm.c
 create mode 100644 include/linux/usb/r8152.h
 create mode 100644 include/linux/usb/usb_vendor_id.h

-- 
2.26.2


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next v3 1/2] include/linux/usb: new header file for the vendor ID of USB devices
  2020-11-03  9:46 ` [PATCH net-next v3 0/2] drivers/net/usb: " Hayes Wang
@ 2020-11-03  9:46   ` Hayes Wang
  2020-11-03  9:55     ` Greg KH
  2020-11-03  9:46   ` [PATCH net-next v3 2/2] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
  1 sibling, 1 reply; 27+ messages in thread
From: Hayes Wang @ 2020-11-03  9:46 UTC (permalink / raw)
  To: netdev, gregkh; +Cc: nic_swsd, linux-kernel, linux-usb, oliver, Hayes Wang

Add a new header file usb_vendor_id.h to consolidate the definitions
of the vendor ID of USB devices which may be used by cdc_ether and
r8152 driver.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/cdc_ether.c       | 139 +++++++++++++-----------------
 drivers/net/usb/r8152.c           |  48 +++++------
 include/linux/usb/usb_vendor_id.h |  51 +++++++++++
 3 files changed, 133 insertions(+), 105 deletions(-)
 create mode 100644 include/linux/usb/usb_vendor_id.h

diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 8c1d61c2cbac..1f6d9b46883a 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -17,6 +17,7 @@
 #include <linux/usb.h>
 #include <linux/usb/cdc.h>
 #include <linux/usb/usbnet.h>
+#include <linux/usb/usb_vendor_id.h>
 
 
 #if IS_ENABLED(CONFIG_USB_NET_RNDIS_HOST)
@@ -540,22 +541,6 @@ static const struct driver_info wwan_info = {
 
 /*-------------------------------------------------------------------------*/
 
-#define HUAWEI_VENDOR_ID	0x12D1
-#define NOVATEL_VENDOR_ID	0x1410
-#define ZTE_VENDOR_ID		0x19D2
-#define DELL_VENDOR_ID		0x413C
-#define REALTEK_VENDOR_ID	0x0bda
-#define SAMSUNG_VENDOR_ID	0x04e8
-#define LENOVO_VENDOR_ID	0x17ef
-#define LINKSYS_VENDOR_ID	0x13b1
-#define NVIDIA_VENDOR_ID	0x0955
-#define HP_VENDOR_ID		0x03f0
-#define MICROSOFT_VENDOR_ID	0x045e
-#define UBLOX_VENDOR_ID		0x1546
-#define TPLINK_VENDOR_ID	0x2357
-#define AQUANTIA_VENDOR_ID	0x2eca
-#define ASIX_VENDOR_ID		0x0b95
-
 static const struct usb_device_id	products[] = {
 /* BLACKLIST !!
  *
@@ -661,49 +646,49 @@ static const struct usb_device_id	products[] = {
 
 /* Novatel USB551L and MC551 - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0xB001, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_NOVATEL, 0xB001, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Novatel E362 - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0x9010, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_NOVATEL, 0x9010, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8195, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_DELL, 0x8195, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8196, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_DELL, 0x8196, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Dell Wireless 5804 (Novatel E371) - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x819b, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_DELL, 0x819b, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Novatel Expedite E371 - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0x9011, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_NOVATEL, 0x9011, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* HP lt2523 (Novatel E371) - handled by qmi_wwan */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(HP_VENDOR_ID, 0x421d, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_HP, 0x421d, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
@@ -717,127 +702,127 @@ static const struct usb_device_id	products[] = {
 
 /* Huawei E1820 - handled by qmi_wwan */
 {
-	USB_DEVICE_INTERFACE_NUMBER(HUAWEI_VENDOR_ID, 0x14ac, 1),
+	USB_DEVICE_INTERFACE_NUMBER(USB_VENDOR_ID_HUAWEI, 0x14ac, 1),
 	.driver_info = 0,
 },
 
 /* Realtek RTL8152 Based USB 2.0 Ethernet Adapters */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8152, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8152, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Realtek RTL8153 Based USB 3.0 Ethernet Adapters */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8153, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Samsung USB Ethernet Adapters */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, 0xa101, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_SAMSUNG, 0xa101, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 #if IS_ENABLED(CONFIG_USB_RTL8152)
 /* Linksys USB3GIGV1 Ethernet Adapter */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LINKSYS_VENDOR_ID, 0x0041, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LINKSYS, 0x0041, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 #endif
 
 /* ThinkPad USB-C Dock (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x3062, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0x3062, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* ThinkPad Thunderbolt 3 Dock (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x3069, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0x3069, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* ThinkPad Thunderbolt 3 Dock Gen 2 (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x3082, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0x3082, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Lenovo Thinkpad USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x7205, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0x7205, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Lenovo USB C to Ethernet Adapter (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x720c, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0x720c, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Lenovo USB-C Travel Hub (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x7214, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0x7214, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* ThinkPad USB-C Dock Gen 2 (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0xa387, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_LENOVO, 0xa387, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* NVIDIA Tegra USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(NVIDIA_VENDOR_ID, 0x09ff, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_NVIDIA, 0x09ff, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Microsoft Surface 2 dock (based on Realtek RTL8152) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(MICROSOFT_VENDOR_ID, 0x07ab, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_MICROSOFT, 0x07ab, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Microsoft Surface Ethernet Adapter (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(MICROSOFT_VENDOR_ID, 0x07c6, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_MICROSOFT, 0x07c6, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Microsoft Surface Ethernet Adapter (based on Realtek RTL8153B) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(MICROSOFT_VENDOR_ID, 0x0927, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_MICROSOFT, 0x0927, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* TP-LINK UE300 USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(TPLINK_VENDOR_ID, 0x0601, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_TPLINK, 0x0601, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = 0,
 },
 
 /* Aquantia AQtion USB to 5GbE Controller (based on AQC111U) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(AQUANTIA_VENDOR_ID, 0xc101,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_AQUANTIA, 0xc101,
 				      USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = 0,
@@ -845,7 +830,7 @@ static const struct usb_device_id	products[] = {
 
 /* ASIX USB 3.1 Gen1 to 5G Multi-Gigabit Ethernet Adapter(based on AQC111U) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(ASIX_VENDOR_ID, 0x2790, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ASIX, 0x2790, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = 0,
@@ -853,7 +838,7 @@ static const struct usb_device_id	products[] = {
 
 /* ASIX USB 3.1 Gen1 to 2.5G Multi-Gigabit Ethernet Adapter(based on AQC112U) */
 {
-	USB_DEVICE_AND_INTERFACE_INFO(ASIX_VENDOR_ID, 0x2791, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ASIX, 0x2791, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = 0,
@@ -887,31 +872,31 @@ static const struct usb_device_id	products[] = {
  */
 {
 	/* ZTE (Vodafone) K3805-Z */
-	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1003, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ZTE, 0x1003, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
 }, {
 	/* ZTE (Vodafone) K3806-Z */
-	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1015, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ZTE, 0x1015, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
 }, {
 	/* ZTE (Vodafone) K4510-Z */
-	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1173, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ZTE, 0x1173, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
 }, {
 	/* ZTE (Vodafone) K3770-Z */
-	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1177, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ZTE, 0x1177, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
 }, {
 	/* ZTE (Vodafone) K3772-Z */
-	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1181, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_ZTE, 0x1181, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
@@ -922,30 +907,30 @@ static const struct usb_device_id	products[] = {
 	.driver_info = (kernel_ulong_t) &wwan_info,
 }, {
 	/* Dell DW5580 modules */
-	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x81ba, USB_CLASS_COMM,
-			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_DELL, 0x81ba, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
 	.driver_info = (kernel_ulong_t)&wwan_info,
 }, {
 	/* Huawei ME906 and ME909 */
-	USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_HUAWEI, 0x15c1, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
 }, {
 	/* ZTE modules */
-	USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, USB_CLASS_COMM,
+	USB_VENDOR_AND_INTERFACE_INFO(USB_VENDOR_ID_ZTE, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&zte_cdc_info,
 }, {
 	/* U-blox TOBY-L2 */
-	USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1143, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_UBLOX, 0x1143, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
 }, {
 	/* U-blox SARA-U2 */
-	USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1104, USB_CLASS_COMM,
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_UBLOX, 0x1104, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET,
 				      USB_CDC_PROTO_NONE),
 	.driver_info = (unsigned long)&wwan_info,
@@ -972,7 +957,7 @@ static const struct usb_device_id	products[] = {
 
 }, {
 	/* Various Huawei modems with a network port like the UMG1831 */
-	USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_COMM,
+	USB_VENDOR_AND_INTERFACE_INFO(USB_VENDOR_ID_HUAWEI, USB_CLASS_COMM,
 				      USB_CDC_SUBCLASS_ETHERNET, 255),
 	.driver_info = (unsigned long)&wwan_info,
 },
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b1770489aca5..d8ae89aa470c 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -26,6 +26,7 @@
 #include <linux/acpi.h>
 #include <linux/firmware.h>
 #include <crypto/hash.h>
+#include <linux/usb/usb_vendor_id.h>
 
 /* Information for net-next */
 #define NETNEXT_VERSION		"11"
@@ -689,15 +690,6 @@ enum rtl8152_flags {
 	LENOVO_MACPASSTHRU,
 };
 
-/* Define these values to match your device */
-#define VENDOR_ID_REALTEK		0x0bda
-#define VENDOR_ID_MICROSOFT		0x045e
-#define VENDOR_ID_SAMSUNG		0x04e8
-#define VENDOR_ID_LENOVO		0x17ef
-#define VENDOR_ID_LINKSYS		0x13b1
-#define VENDOR_ID_NVIDIA		0x0955
-#define VENDOR_ID_TPLINK		0x2357
-
 #define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
 #define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
 
@@ -6753,7 +6745,7 @@ static int rtl8152_probe(struct usb_interface *intf,
 		netdev->hw_features &= ~NETIF_F_RXCSUM;
 	}
 
-	if (le16_to_cpu(udev->descriptor.idVendor) == VENDOR_ID_LENOVO) {
+	if (le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LENOVO) {
 		switch (le16_to_cpu(udev->descriptor.idProduct)) {
 		case DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2:
 		case DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2:
@@ -6879,24 +6871,24 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 
 /* table of devices that work with this driver */
 static const struct usb_device_id rtl8152_table[] = {
-	{REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8050)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8152)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8153)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_MICROSOFT, 0x07ab)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_MICROSOFT, 0x07c6)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_MICROSOFT, 0x0927)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, 0xa101)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x304f)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x3062)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x3069)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x3082)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x7205)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x720c)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0x7214)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LENOVO,  0xa387)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_LINKSYS, 0x0041)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_NVIDIA,  0x09ff)},
-	{REALTEK_USB_DEVICE(VENDOR_ID_TPLINK,  0x0601)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8050)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8152)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8153)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x07ab)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x07c6)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x0927)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, 0xa101)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x304f)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x3062)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x3069)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x3082)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x7205)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x720c)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0x7214)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LENOVO,  0xa387)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_LINKSYS, 0x0041)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_NVIDIA,  0x09ff)},
+	{REALTEK_USB_DEVICE(USB_VENDOR_ID_TPLINK,  0x0601)},
 	{}
 };
 
diff --git a/include/linux/usb/usb_vendor_id.h b/include/linux/usb/usb_vendor_id.h
new file mode 100644
index 000000000000..23b6e6849515
--- /dev/null
+++ b/include/linux/usb/usb_vendor_id.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef LINUX_USB_VENDOR_ID_H
+#define LINUX_USB_VENDOR_ID_H
+
+/* Realtek Semiconductor Corp. */
+#define USB_VENDOR_ID_REALTEK				0x0bda
+
+/* Microsoft Corp */
+#define USB_VENDOR_ID_MICROSOFT				0x045e
+
+/* Samsung */
+#define USB_VENDOR_ID_SAMSUNG				0x04e8
+
+/* Lenovo */
+#define USB_VENDOR_ID_LENOVO				0x17ef
+
+/* Linksys */
+#define USB_VENDOR_ID_LINKSYS				0x13b1
+
+/* NVIDIA Corp. */
+#define USB_VENDOR_ID_NVIDIA				0x0955
+
+/* TP-Link */
+#define USB_VENDOR_ID_TPLINK				0x2357
+
+/* Huawei Technologies Co., Ltd. */
+#define USB_VENDOR_ID_HUAWEI				0x12D1
+
+/* Novatel Wireless */
+#define USB_VENDOR_ID_NOVATEL				0x1410
+
+/* ZTE WCDMA Technologies MSM */
+#define USB_VENDOR_ID_ZTE				0x19D2
+
+/* Dell Computer Corp */
+#define USB_VENDOR_ID_DELL				0x413C
+
+/* HP, Inc */
+#define USB_VENDOR_ID_HP				0x03f0
+
+/* U-Blox AG */
+#define USB_VENDOR_ID_UBLOX				0x1546
+
+/* Aquantia */
+#define USB_VENDOR_ID_AQUANTIA				0x2eca
+
+/* ASIX Electronics Corp. */
+#define USB_VENDOR_ID_ASIX				0x0b95
+
+#endif /* LINUX_USB_VENDOR_ID_H */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH net-next v3 2/2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-03  9:46 ` [PATCH net-next v3 0/2] drivers/net/usb: " Hayes Wang
  2020-11-03  9:46   ` [PATCH net-next v3 1/2] include/linux/usb: new header file for the vendor ID of USB devices Hayes Wang
@ 2020-11-03  9:46   ` Hayes Wang
  1 sibling, 0 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-03  9:46 UTC (permalink / raw)
  To: netdev, gregkh; +Cc: nic_swsd, linux-kernel, linux-usb, oliver, Hayes Wang

Support ECM mode based on cdc_ether with relative mii
functions, when CONFIG_USB_RTL8152 is not set, or the
device is not supported by r8152 driver.

Both r8152 and r8153_ecm would check the return value of
rtl8152_get_version() in porbe(). If rtl8152_get_version()
return none zero value, the r8152 is used for the device
with vendor mode. Otherwise, the r8153_ecm is used for the
device with ECM mode.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/Makefile    |   2 +-
 drivers/net/usb/r8152.c     |  22 +----
 drivers/net/usb/r8153_ecm.c | 162 ++++++++++++++++++++++++++++++++++++
 include/linux/usb/r8152.h   |  30 +++++++
 4 files changed, 197 insertions(+), 19 deletions(-)
 create mode 100644 drivers/net/usb/r8153_ecm.c
 create mode 100644 include/linux/usb/r8152.h

diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 99fd12be2111..99381e6bea78 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
-obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
+obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
 obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index d8ae89aa470c..41b803729996 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -26,7 +26,7 @@
 #include <linux/acpi.h>
 #include <linux/firmware.h>
 #include <crypto/hash.h>
-#include <linux/usb/usb_vendor_id.h>
+#include <linux/usb/r8152.h>
 
 /* Information for net-next */
 #define NETNEXT_VERSION		"11"
@@ -654,18 +654,6 @@ enum rtl_register_content {
 
 #define INTR_LINK		0x0004
 
-#define RTL8152_REQT_READ	0xc0
-#define RTL8152_REQT_WRITE	0x40
-#define RTL8152_REQ_GET_REGS	0x05
-#define RTL8152_REQ_SET_REGS	0x05
-
-#define BYTE_EN_DWORD		0xff
-#define BYTE_EN_WORD		0x33
-#define BYTE_EN_BYTE		0x11
-#define BYTE_EN_SIX_BYTES	0x3f
-#define BYTE_EN_START_MASK	0x0f
-#define BYTE_EN_END_MASK	0xf0
-
 #define RTL8153_MAX_PACKET	9216 /* 9K */
 #define RTL8153_MAX_MTU		(RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \
 				 ETH_FCS_LEN)
@@ -693,9 +681,6 @@ enum rtl8152_flags {
 #define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
 #define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
 
-#define MCU_TYPE_PLA			0x0100
-#define MCU_TYPE_USB			0x0000
-
 struct tally_counter {
 	__le64	tx_packets;
 	__le64	rx_packets;
@@ -6607,7 +6592,7 @@ static int rtl_fw_init(struct r8152 *tp)
 	return 0;
 }
 
-static u8 rtl_get_version(struct usb_interface *intf)
+u8 rtl8152_get_version(struct usb_interface *intf)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	u32 ocp_data = 0;
@@ -6665,12 +6650,13 @@ static u8 rtl_get_version(struct usb_interface *intf)
 
 	return version;
 }
+EXPORT_SYMBOL_GPL(rtl8152_get_version);
 
 static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
-	u8 version = rtl_get_version(intf);
+	u8 version = rtl8152_get_version(intf);
 	struct r8152 *tp;
 	struct net_device *netdev;
 	int ret;
diff --git a/drivers/net/usb/r8153_ecm.c b/drivers/net/usb/r8153_ecm.c
new file mode 100644
index 000000000000..13eba7a72633
--- /dev/null
+++ b/drivers/net/usb/r8153_ecm.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/usb/r8152.h>
+
+#define OCP_BASE		0xe86c
+
+static int pla_read_word(struct usbnet *dev, u16 index)
+{
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	if (shift)
+		byen <<= shift;
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+	if (ret < 0)
+		goto out;
+
+	ret = __le32_to_cpu(tmp);
+	ret >>= (shift * 8);
+	ret &= 0xffff;
+
+out:
+	return ret;
+}
+
+static int pla_write_word(struct usbnet *dev, u16 index, u32 data)
+{
+	u32 mask = 0xffff;
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	data &= mask;
+
+	if (shift) {
+		byen <<= shift;
+		mask <<= (shift * 8);
+		data <<= (shift * 8);
+	}
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+	if (ret < 0)
+		goto out;
+
+	data |= __le32_to_cpu(tmp) & ~mask;
+	tmp = __cpu_to_le32(data);
+
+	ret = usbnet_write_cmd(dev, RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, index,
+			       MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+out:
+	return ret;
+}
+
+static int r8153_ecm_mdio_read(struct net_device *netdev, int phy_id, int reg)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		goto out;
+
+	ret = pla_read_word(dev, 0xb400 + reg * 2);
+
+out:
+	return ret;
+}
+
+static void r8153_ecm_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		return;
+
+	ret = pla_write_word(dev, 0xb400 + reg * 2, val);
+}
+
+static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	int status;
+
+	status = usbnet_cdc_bind(dev, intf);
+	if (status < 0)
+		return status;
+
+	dev->mii.dev = dev->net;
+	dev->mii.mdio_read = r8153_ecm_mdio_read;
+	dev->mii.mdio_write = r8153_ecm_mdio_write;
+	dev->mii.reg_num_mask = 0x1f;
+	dev->mii.supports_gmii = 1;
+
+	return status;
+}
+
+static const struct driver_info r8153_info = {
+	.description =	"RTL8153 ECM Device",
+	.flags =	FLAG_ETHER,
+	.bind =		r8153_bind,
+	.unbind =	usbnet_cdc_unbind,
+	.status =	usbnet_cdc_status,
+	.manage_power =	usbnet_manage_power,
+};
+
+static const struct usb_device_id products[] = {
+{
+	USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_REALTEK, 0x8153, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	.driver_info = (unsigned long)&r8153_info,
+},
+
+	{ },		/* END */
+};
+MODULE_DEVICE_TABLE(usb, products);
+
+static int rtl8153_ecm_probe(struct usb_interface *intf,
+			     const struct usb_device_id *id)
+{
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+	if (rtl8152_get_version(intf))
+		return -ENODEV;
+#endif
+
+	return usbnet_probe(intf, id);
+}
+
+static struct usb_driver r8153_ecm_driver = {
+	.name =		"r8153_ecm",
+	.id_table =	products,
+	.probe =	rtl8153_ecm_probe,
+	.disconnect =	usbnet_disconnect,
+	.suspend =	usbnet_suspend,
+	.resume =	usbnet_resume,
+	.reset_resume =	usbnet_resume,
+	.supports_autosuspend = 1,
+	.disable_hub_initiated_lpm = 1,
+};
+
+module_usb_driver(r8153_ecm_driver);
+
+MODULE_AUTHOR("Hayes Wang");
+MODULE_DESCRIPTION("Realtek USB ECM device");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/r8152.h b/include/linux/usb/r8152.h
new file mode 100644
index 000000000000..663e694c9513
--- /dev/null
+++ b/include/linux/usb/r8152.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *  Copyright (c) 2020 Realtek Semiconductor Corp. All rights reserved.
+ */
+
+#ifndef	__LINUX_R8152_H
+#define __LINUX_R8152_H
+
+#include <linux/usb/usb_vendor_id.h>
+
+#define RTL8152_REQT_READ		0xc0
+#define RTL8152_REQT_WRITE		0x40
+#define RTL8152_REQ_GET_REGS		0x05
+#define RTL8152_REQ_SET_REGS		0x05
+
+#define BYTE_EN_DWORD			0xff
+#define BYTE_EN_WORD			0x33
+#define BYTE_EN_BYTE			0x11
+#define BYTE_EN_SIX_BYTES		0x3f
+#define BYTE_EN_START_MASK		0x0f
+#define BYTE_EN_END_MASK		0xf0
+
+#define MCU_TYPE_PLA			0x0100
+#define MCU_TYPE_USB			0x0000
+
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+extern u8 rtl8152_get_version(struct usb_interface *intf);
+#endif
+
+#endif /* __LINUX_R8152_H */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* RE: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-03  9:32         ` Greg Kroah-Hartman
@ 2020-11-03  9:51           ` Hayes Wang
  2020-11-03 16:15           ` Jakub Kicinski
  1 sibling, 0 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-03  9:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jakub Kicinski
  Cc: netdev, nic_swsd, linux-kernel, linux-usb, Oliver Neukum

Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Sent: Tuesday, November 3, 2020 5:33 PM
[...]
> There is a reason, it's a nightmare to maintain and handle merges for,
> just don't do it.
> 
> Read the comments at the top of the pci_ids.h file if you are curious
> why we don't even do this for PCI device ids anymore for the past 10+
> years.
> 
> So no, please do not create such a common file, it is not needed or a
> good idea.

Oops. I have sent it.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v3 1/2] include/linux/usb: new header file for the vendor ID of USB devices
  2020-11-03  9:46   ` [PATCH net-next v3 1/2] include/linux/usb: new header file for the vendor ID of USB devices Hayes Wang
@ 2020-11-03  9:55     ` Greg KH
  0 siblings, 0 replies; 27+ messages in thread
From: Greg KH @ 2020-11-03  9:55 UTC (permalink / raw)
  To: Hayes Wang; +Cc: netdev, nic_swsd, linux-kernel, linux-usb, oliver

On Tue, Nov 03, 2020 at 05:46:37PM +0800, Hayes Wang wrote:
> diff --git a/include/linux/usb/usb_vendor_id.h b/include/linux/usb/usb_vendor_id.h
> new file mode 100644
> index 000000000000..23b6e6849515
> --- /dev/null
> +++ b/include/linux/usb/usb_vendor_id.h
> @@ -0,0 +1,51 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +

<snip>

No, this is not ok, sorry.  Please see the top of the pci_ids.h file why
we do not do this.

There is nothing wrong with putting the individual ids in the different
drivers, we don't want one single huge file that is a pain for merges
and builds.  We learn from our past mistakes, please do not fail to
learn from history :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-03  9:32         ` Greg Kroah-Hartman
  2020-11-03  9:51           ` Hayes Wang
@ 2020-11-03 16:15           ` Jakub Kicinski
  2020-11-04  1:39             ` Hayes Wang
  1 sibling, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-11-03 16:15 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Hayes Wang, netdev, nic_swsd, linux-kernel, linux-usb, Oliver Neukum

On Tue, 3 Nov 2020 10:32:41 +0100 Greg Kroah-Hartman wrote:
> On Mon, Nov 02, 2020 at 11:47:18AM -0800, Jakub Kicinski wrote:
> > On Mon, 2 Nov 2020 07:20:15 +0000 Hayes Wang wrote:  
> > > Jakub Kicinski <kuba@kernel.org>  
> > > > Can you describe the use case in more detail?
> > > > 
> > > > AFAICT r8152 defines a match for the exact same device.
> > > > Does it not mean that which driver is used will be somewhat random
> > > > if both are built?    
> > > 
> > > I export rtl_get_version() from r8152. It would return none zero
> > > value if r8152 could support this device. Both r8152 and r8153_ecm
> > > would check the return value of rtl_get_version() in porbe().
> > > Therefore, if rtl_get_version() return none zero value, the r8152
> > > is used for the device with vendor mode. Otherwise, the r8153_ecm
> > > is used for the device with ECM mode.  
> > 
> > Oh, I see, I missed that the rtl_get_version() checking is the inverse
> > of r8152.
> >   
> > > > > +/* Define these values to match your device */
> > > > > +#define VENDOR_ID_REALTEK		0x0bda
> > > > > +#define VENDOR_ID_MICROSOFT		0x045e
> > > > > +#define VENDOR_ID_SAMSUNG		0x04e8
> > > > > +#define VENDOR_ID_LENOVO		0x17ef
> > > > > +#define VENDOR_ID_LINKSYS		0x13b1
> > > > > +#define VENDOR_ID_NVIDIA		0x0955
> > > > > +#define VENDOR_ID_TPLINK		0x2357    
> > > > 
> > > > $ git grep 0x2357 | grep -i tplink
> > > > drivers/net/usb/cdc_ether.c:#define TPLINK_VENDOR_ID	0x2357
> > > > drivers/net/usb/r8152.c:#define VENDOR_ID_TPLINK		0x2357
> > > > drivers/usb/serial/option.c:#define TPLINK_VENDOR_ID			0x2357
> > > > 
> > > > $ git grep 0x17ef | grep -i lenovo
> > > > drivers/hid/hid-ids.h:#define USB_VENDOR_ID_LENOVO		0x17ef
> > > > drivers/hid/wacom.h:#define USB_VENDOR_ID_LENOVO	0x17ef
> > > > drivers/net/usb/cdc_ether.c:#define LENOVO_VENDOR_ID	0x17ef
> > > > drivers/net/usb/r8152.c:#define VENDOR_ID_LENOVO		0x17ef
> > > > 
> > > > Time to consolidate those vendor id defines perhaps?    
> > > 
> > > It seems that there is no such header file which I could include
> > > or add the new vendor IDs.  
> > 
> > Please create one. (Adding Greg KH to the recipients, in case there is
> > a reason that USB subsystem doesn't have a common vendor id header.)  
> 
> There is a reason, it's a nightmare to maintain and handle merges for,
> just don't do it.

Ah! Good that we asked :)

> Read the comments at the top of the pci_ids.h file if you are curious
> why we don't even do this for PCI device ids anymore for the past 10+
> years.
> 
> So no, please do not create such a common file, it is not needed or a
> good idea.

I wouldn't go that far, PCI subsystem just doesn't want everyone to add
IDs to the shared file unless there is a reason.

 *	Do not add new entries to this file unless the definitions
 *	are shared between multiple drivers.

Which seems quite reasonable. But it is most certainly your call :)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-03 16:15           ` Jakub Kicinski
@ 2020-11-04  1:39             ` Hayes Wang
  2020-11-04  1:44               ` Jakub Kicinski
  0 siblings, 1 reply; 27+ messages in thread
From: Hayes Wang @ 2020-11-04  1:39 UTC (permalink / raw)
  To: Jakub Kicinski, Greg Kroah-Hartman
  Cc: netdev, nic_swsd, linux-kernel, linux-usb, Oliver Neukum

Jakub Kicinski <kuba@kernel.org>
> Sent: Wednesday, November 4, 2020 12:16 AM
[...]
> > So no, please do not create such a common file, it is not needed or a
> > good idea.
> 
> I wouldn't go that far, PCI subsystem just doesn't want everyone to add
> IDs to the shared file unless there is a reason.
> 
>  *	Do not add new entries to this file unless the definitions
>  *	are shared between multiple drivers.
> 
> Which seems quite reasonable. But it is most certainly your call :)

Do I have to resend this patch?

Best Regards,
Hayes



^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-04  1:39             ` Hayes Wang
@ 2020-11-04  1:44               ` Jakub Kicinski
  0 siblings, 0 replies; 27+ messages in thread
From: Jakub Kicinski @ 2020-11-04  1:44 UTC (permalink / raw)
  To: Hayes Wang
  Cc: Greg Kroah-Hartman, netdev, nic_swsd, linux-kernel, linux-usb,
	Oliver Neukum

On Wed, 4 Nov 2020 01:39:52 +0000 Hayes Wang wrote:
> Jakub Kicinski <kuba@kernel.org>
> > Sent: Wednesday, November 4, 2020 12:16 AM  
> [...]
> > > So no, please do not create such a common file, it is not needed or a
> > > good idea.  
> > 
> > I wouldn't go that far, PCI subsystem just doesn't want everyone to add
> > IDs to the shared file unless there is a reason.
> > 
> >  *	Do not add new entries to this file unless the definitions
> >  *	are shared between multiple drivers.
> > 
> > Which seems quite reasonable. But it is most certainly your call :)  
> 
> Do I have to resend this patch?

Yes please, that'd be easiest for me. Also Oliver wasn't CCed on this
posting.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next v2 RESEND] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-10-29 12:33 [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
                   ` (2 preceding siblings ...)
  2020-11-03  9:46 ` [PATCH net-next v3 0/2] drivers/net/usb: " Hayes Wang
@ 2020-11-04  2:19 ` Hayes Wang
  2020-11-06  1:00   ` Jakub Kicinski
       [not found]   ` <CGME20201113152938eucas1p2c8500d9d3d0c892c7c2a2d56b32fedc0@eucas1p2.samsung.com>
  3 siblings, 2 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-04  2:19 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, oliver, linux-usb, Hayes Wang

Support ECM mode based on cdc_ether with relative mii functions,
when CONFIG_USB_RTL8152 is not set, or the device is not supported
by r8152 driver.

Both r8152 and r8153_ecm would check the return value of
rtl8152_get_version() in porbe(). If rtl8152_get_version()
return none zero value, the r8152 is used for the device
with vendor mode. Otherwise, the r8153_ecm is used for the
device with ECM mode.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/Makefile    |   2 +-
 drivers/net/usb/r8152.c     |  30 +------
 drivers/net/usb/r8153_ecm.c | 162 ++++++++++++++++++++++++++++++++++++
 include/linux/usb/r8152.h   |  37 ++++++++
 4 files changed, 204 insertions(+), 27 deletions(-)
 create mode 100644 drivers/net/usb/r8153_ecm.c
 create mode 100644 include/linux/usb/r8152.h

diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 99fd12be2111..99381e6bea78 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
-obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
+obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
 obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index b9b3d19a2e98..c448d6089821 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -26,6 +26,7 @@
 #include <linux/acpi.h>
 #include <linux/firmware.h>
 #include <crypto/hash.h>
+#include <linux/usb/r8152.h>
 
 /* Information for net-next */
 #define NETNEXT_VERSION		"11"
@@ -653,18 +654,6 @@ enum rtl_register_content {
 
 #define INTR_LINK		0x0004
 
-#define RTL8152_REQT_READ	0xc0
-#define RTL8152_REQT_WRITE	0x40
-#define RTL8152_REQ_GET_REGS	0x05
-#define RTL8152_REQ_SET_REGS	0x05
-
-#define BYTE_EN_DWORD		0xff
-#define BYTE_EN_WORD		0x33
-#define BYTE_EN_BYTE		0x11
-#define BYTE_EN_SIX_BYTES	0x3f
-#define BYTE_EN_START_MASK	0x0f
-#define BYTE_EN_END_MASK	0xf0
-
 #define RTL8153_MAX_PACKET	9216 /* 9K */
 #define RTL8153_MAX_MTU		(RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \
 				 ETH_FCS_LEN)
@@ -689,21 +678,9 @@ enum rtl8152_flags {
 	LENOVO_MACPASSTHRU,
 };
 
-/* Define these values to match your device */
-#define VENDOR_ID_REALTEK		0x0bda
-#define VENDOR_ID_MICROSOFT		0x045e
-#define VENDOR_ID_SAMSUNG		0x04e8
-#define VENDOR_ID_LENOVO		0x17ef
-#define VENDOR_ID_LINKSYS		0x13b1
-#define VENDOR_ID_NVIDIA		0x0955
-#define VENDOR_ID_TPLINK		0x2357
-
 #define DEVICE_ID_THINKPAD_THUNDERBOLT3_DOCK_GEN2	0x3082
 #define DEVICE_ID_THINKPAD_USB_C_DOCK_GEN2		0xa387
 
-#define MCU_TYPE_PLA			0x0100
-#define MCU_TYPE_USB			0x0000
-
 struct tally_counter {
 	__le64	tx_packets;
 	__le64	rx_packets;
@@ -6621,7 +6598,7 @@ static int rtl_fw_init(struct r8152 *tp)
 	return 0;
 }
 
-static u8 rtl_get_version(struct usb_interface *intf)
+u8 rtl8152_get_version(struct usb_interface *intf)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	u32 ocp_data = 0;
@@ -6679,12 +6656,13 @@ static u8 rtl_get_version(struct usb_interface *intf)
 
 	return version;
 }
+EXPORT_SYMBOL_GPL(rtl8152_get_version);
 
 static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
-	u8 version = rtl_get_version(intf);
+	u8 version = rtl8152_get_version(intf);
 	struct r8152 *tp;
 	struct net_device *netdev;
 	int ret;
diff --git a/drivers/net/usb/r8153_ecm.c b/drivers/net/usb/r8153_ecm.c
new file mode 100644
index 000000000000..2c3fabd38b16
--- /dev/null
+++ b/drivers/net/usb/r8153_ecm.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/mii.h>
+#include <linux/usb.h>
+#include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
+#include <linux/usb/r8152.h>
+
+#define OCP_BASE		0xe86c
+
+static int pla_read_word(struct usbnet *dev, u16 index)
+{
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	if (shift)
+		byen <<= shift;
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+	if (ret < 0)
+		goto out;
+
+	ret = __le32_to_cpu(tmp);
+	ret >>= (shift * 8);
+	ret &= 0xffff;
+
+out:
+	return ret;
+}
+
+static int pla_write_word(struct usbnet *dev, u16 index, u32 data)
+{
+	u32 mask = 0xffff;
+	u16 byen = BYTE_EN_WORD;
+	u8 shift = index & 2;
+	__le32 tmp;
+	int ret;
+
+	data &= mask;
+
+	if (shift) {
+		byen <<= shift;
+		mask <<= (shift * 8);
+		data <<= (shift * 8);
+	}
+
+	index &= ~3;
+
+	ret = usbnet_read_cmd(dev, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, index,
+			      MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+	if (ret < 0)
+		goto out;
+
+	data |= __le32_to_cpu(tmp) & ~mask;
+	tmp = __cpu_to_le32(data);
+
+	ret = usbnet_write_cmd(dev, RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, index,
+			       MCU_TYPE_PLA | byen, &tmp, sizeof(tmp));
+
+out:
+	return ret;
+}
+
+static int r8153_ecm_mdio_read(struct net_device *netdev, int phy_id, int reg)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		goto out;
+
+	ret = pla_read_word(dev, 0xb400 + reg * 2);
+
+out:
+	return ret;
+}
+
+static void r8153_ecm_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
+{
+	struct usbnet *dev = netdev_priv(netdev);
+	int ret;
+
+	ret = pla_write_word(dev, OCP_BASE, 0xa000);
+	if (ret < 0)
+		return;
+
+	ret = pla_write_word(dev, 0xb400 + reg * 2, val);
+}
+
+static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	int status;
+
+	status = usbnet_cdc_bind(dev, intf);
+	if (status < 0)
+		return status;
+
+	dev->mii.dev = dev->net;
+	dev->mii.mdio_read = r8153_ecm_mdio_read;
+	dev->mii.mdio_write = r8153_ecm_mdio_write;
+	dev->mii.reg_num_mask = 0x1f;
+	dev->mii.supports_gmii = 1;
+
+	return status;
+}
+
+static const struct driver_info r8153_info = {
+	.description =	"RTL8153 ECM Device",
+	.flags =	FLAG_ETHER,
+	.bind =		r8153_bind,
+	.unbind =	usbnet_cdc_unbind,
+	.status =	usbnet_cdc_status,
+	.manage_power =	usbnet_manage_power,
+};
+
+static const struct usb_device_id products[] = {
+{
+	USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID_REALTEK, 0x8153, USB_CLASS_COMM,
+				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
+	.driver_info = (unsigned long)&r8153_info,
+},
+
+	{ },		/* END */
+};
+MODULE_DEVICE_TABLE(usb, products);
+
+static int rtl8153_ecm_probe(struct usb_interface *intf,
+			     const struct usb_device_id *id)
+{
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+	if (rtl8152_get_version(intf))
+		return -ENODEV;
+#endif
+
+	return usbnet_probe(intf, id);
+}
+
+static struct usb_driver r8153_ecm_driver = {
+	.name =		"r8153_ecm",
+	.id_table =	products,
+	.probe =	rtl8153_ecm_probe,
+	.disconnect =	usbnet_disconnect,
+	.suspend =	usbnet_suspend,
+	.resume =	usbnet_resume,
+	.reset_resume =	usbnet_resume,
+	.supports_autosuspend = 1,
+	.disable_hub_initiated_lpm = 1,
+};
+
+module_usb_driver(r8153_ecm_driver);
+
+MODULE_AUTHOR("Hayes Wang");
+MODULE_DESCRIPTION("Realtek USB ECM device");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/r8152.h b/include/linux/usb/r8152.h
new file mode 100644
index 000000000000..20d88b1defc3
--- /dev/null
+++ b/include/linux/usb/r8152.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ *  Copyright (c) 2020 Realtek Semiconductor Corp. All rights reserved.
+ */
+
+#ifndef	__LINUX_R8152_H
+#define __LINUX_R8152_H
+
+#define RTL8152_REQT_READ		0xc0
+#define RTL8152_REQT_WRITE		0x40
+#define RTL8152_REQ_GET_REGS		0x05
+#define RTL8152_REQ_SET_REGS		0x05
+
+#define BYTE_EN_DWORD			0xff
+#define BYTE_EN_WORD			0x33
+#define BYTE_EN_BYTE			0x11
+#define BYTE_EN_SIX_BYTES		0x3f
+#define BYTE_EN_START_MASK		0x0f
+#define BYTE_EN_END_MASK		0xf0
+
+#define MCU_TYPE_PLA			0x0100
+#define MCU_TYPE_USB			0x0000
+
+/* Define these values to match your device */
+#define VENDOR_ID_REALTEK		0x0bda
+#define VENDOR_ID_MICROSOFT		0x045e
+#define VENDOR_ID_SAMSUNG		0x04e8
+#define VENDOR_ID_LENOVO		0x17ef
+#define VENDOR_ID_LINKSYS		0x13b1
+#define VENDOR_ID_NVIDIA		0x0955
+#define VENDOR_ID_TPLINK		0x2357
+
+#if IS_REACHABLE(CONFIG_USB_RTL8152)
+extern u8 rtl8152_get_version(struct usb_interface *intf);
+#endif
+
+#endif /* __LINUX_R8152_H */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2 RESEND] net/usb/r8153_ecm: support ECM mode for RTL8153
  2020-11-04  2:19 ` [PATCH net-next v2 RESEND] " Hayes Wang
@ 2020-11-06  1:00   ` Jakub Kicinski
       [not found]   ` <CGME20201113152938eucas1p2c8500d9d3d0c892c7c2a2d56b32fedc0@eucas1p2.samsung.com>
  1 sibling, 0 replies; 27+ messages in thread
From: Jakub Kicinski @ 2020-11-06  1:00 UTC (permalink / raw)
  To: Hayes Wang; +Cc: netdev, nic_swsd, linux-kernel, oliver, linux-usb

On Wed, 4 Nov 2020 10:19:22 +0800 Hayes Wang wrote:
> Support ECM mode based on cdc_ether with relative mii functions,
> when CONFIG_USB_RTL8152 is not set, or the device is not supported
> by r8152 driver.
> 
> Both r8152 and r8153_ecm would check the return value of
> rtl8152_get_version() in porbe(). If rtl8152_get_version()
> return none zero value, the r8152 is used for the device
> with vendor mode. Otherwise, the r8153_ecm is used for the
> device with ECM mode.
> 
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2 RESEND] net/usb/r8153_ecm: support ECM mode for RTL8153
       [not found]   ` <CGME20201113152938eucas1p2c8500d9d3d0c892c7c2a2d56b32fedc0@eucas1p2.samsung.com>
@ 2020-11-13 15:29     ` Marek Szyprowski
  2020-11-16  6:52       ` [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver Hayes Wang
  0 siblings, 1 reply; 27+ messages in thread
From: Marek Szyprowski @ 2020-11-13 15:29 UTC (permalink / raw)
  To: Hayes Wang, netdev
  Cc: nic_swsd, linux-kernel, oliver, linux-usb,
	'Linux Samsung SOC',
	Bartlomiej Zolnierkiewicz, Krzysztof Kozlowski

Hi Hayes,

On 04.11.2020 03:19, Hayes Wang wrote:
> Support ECM mode based on cdc_ether with relative mii functions,
> when CONFIG_USB_RTL8152 is not set, or the device is not supported
> by r8152 driver.
>
> Both r8152 and r8153_ecm would check the return value of
> rtl8152_get_version() in porbe(). If rtl8152_get_version()
> return none zero value, the r8152 is used for the device
> with vendor mode. Otherwise, the r8153_ecm is used for the
> device with ECM mode.
>
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>

This patch landed recently in linux-next and breaks ethernet operation 
on Samsung Exynos5422 Odroid XU4/HC1 boards when kernel is compiled from 
arm/configs/multi_v7_defconfig. The main problem is that the hardware is 
bound to r8153_ecm driver, not to the r8152. Manually switching the 
drivers by "echo 4-1:2.0 >/sys/bus/usb/drivers/r8153_ecm/unbind && echo 
4-1:2.0 >/sys/bus/usb/drivers/r8152/bind" fixes ethernet operation.

This is because in multi_v7_defconfig r8153_ecm driver is built-in (as 
it is tied to CONFIG_USB_NET_CDCETHER), while the r8152 driver is 
compiled as module and loaded when r8153_ecm has already bound.

I think that r8153_ecm driver should have a separate Kconfig symbol, 
which matches the r8152 driver (either both are built-in or both as 
modules), otherwise those 2 drivers cannot properly detect their cases.

> ---
>   drivers/net/usb/Makefile    |   2 +-
>   drivers/net/usb/r8152.c     |  30 +------
>   drivers/net/usb/r8153_ecm.c | 162 ++++++++++++++++++++++++++++++++++++
>   include/linux/usb/r8152.h   |  37 ++++++++
>   4 files changed, 204 insertions(+), 27 deletions(-)
>   create mode 100644 drivers/net/usb/r8153_ecm.c
>   create mode 100644 include/linux/usb/r8152.h
>
> > ...

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-13 15:29     ` Marek Szyprowski
@ 2020-11-16  6:52       ` Hayes Wang
  2020-11-16  9:18         ` Marek Szyprowski
  2020-11-18  6:43         ` [PATCH net-next v2] " Hayes Wang
  0 siblings, 2 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-16  6:52 UTC (permalink / raw)
  To: netdev, m.szyprowski; +Cc: nic_swsd, linux-kernel, linux-usb, Hayes Wang

Avoid r8153_ecm is compiled as built-in, if r8152 driver is compiled
as modules. Otherwise, the r8153_ecm would be used, even though the
device is supported by r8152 driver.

Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/Makefile | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 99381e6bea78..98f4c100955e 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
-obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
+obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
 obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
@@ -41,3 +41,11 @@ obj-$(CONFIG_USB_NET_QMI_WWAN)	+= qmi_wwan.o
 obj-$(CONFIG_USB_NET_CDC_MBIM)	+= cdc_mbim.o
 obj-$(CONFIG_USB_NET_CH9200)	+= ch9200.o
 obj-$(CONFIG_USB_NET_AQC111)	+= aqc111.o
+
+ifdef CONFIG_USB_NET_CDCETHER
+ifeq ($(CONFIG_USB_RTL8152), m)
+obj-$(CONFIG_USB_RTL8152)	+= r8153_ecm.o
+else
+obj-$(CONFIG_USB_NET_CDCETHER)	+= r8153_ecm.o
+endif
+endif
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-16  6:52       ` [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver Hayes Wang
@ 2020-11-16  9:18         ` Marek Szyprowski
  2020-11-16 17:02           ` Jakub Kicinski
  2020-11-18  6:43         ` [PATCH net-next v2] " Hayes Wang
  1 sibling, 1 reply; 27+ messages in thread
From: Marek Szyprowski @ 2020-11-16  9:18 UTC (permalink / raw)
  To: Hayes Wang, netdev; +Cc: nic_swsd, linux-kernel, linux-usb

Hi

On 16.11.2020 07:52, Hayes Wang wrote:
> Avoid r8153_ecm is compiled as built-in, if r8152 driver is compiled
> as modules. Otherwise, the r8153_ecm would be used, even though the
> device is supported by r8152 driver.
>
> Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>

Yes, this fixes this issue, although I would prefer a separate Kconfig 
entry for r8153_ecm with proper dependencies instead of this ifdefs in 
Makefile.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   drivers/net/usb/Makefile | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
> index 99381e6bea78..98f4c100955e 100644
> --- a/drivers/net/usb/Makefile
> +++ b/drivers/net/usb/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
>   obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
>   asix-y := asix_devices.o asix_common.o ax88172a.o
>   obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
> -obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
> +obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
>   obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
>   obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
>   obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
> @@ -41,3 +41,11 @@ obj-$(CONFIG_USB_NET_QMI_WWAN)	+= qmi_wwan.o
>   obj-$(CONFIG_USB_NET_CDC_MBIM)	+= cdc_mbim.o
>   obj-$(CONFIG_USB_NET_CH9200)	+= ch9200.o
>   obj-$(CONFIG_USB_NET_AQC111)	+= aqc111.o
> +
> +ifdef CONFIG_USB_NET_CDCETHER
> +ifeq ($(CONFIG_USB_RTL8152), m)
> +obj-$(CONFIG_USB_RTL8152)	+= r8153_ecm.o
> +else
> +obj-$(CONFIG_USB_NET_CDCETHER)	+= r8153_ecm.o
> +endif
> +endif

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-16  9:18         ` Marek Szyprowski
@ 2020-11-16 17:02           ` Jakub Kicinski
  2020-11-17  1:50             ` Hayes Wang
  0 siblings, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-11-16 17:02 UTC (permalink / raw)
  To: Marek Szyprowski; +Cc: Hayes Wang, netdev, nic_swsd, linux-kernel, linux-usb

On Mon, 16 Nov 2020 10:18:13 +0100 Marek Szyprowski wrote:
> On 16.11.2020 07:52, Hayes Wang wrote:
> > Avoid r8153_ecm is compiled as built-in, if r8152 driver is compiled
> > as modules. Otherwise, the r8153_ecm would be used, even though the
> > device is supported by r8152 driver.
> >
> > Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153")
> > Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> > Signed-off-by: Hayes Wang <hayeswang@realtek.com>  
> 
> Yes, this fixes this issue, although I would prefer a separate Kconfig 
> entry for r8153_ecm with proper dependencies instead of this ifdefs in 
> Makefile.

Agreed, this is what dependency resolution is for.

Let's just make this a separate Kconfig entry.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-16 17:02           ` Jakub Kicinski
@ 2020-11-17  1:50             ` Hayes Wang
  2020-11-17 16:11               ` Jakub Kicinski
  0 siblings, 1 reply; 27+ messages in thread
From: Hayes Wang @ 2020-11-17  1:50 UTC (permalink / raw)
  To: Jakub Kicinski, Marek Szyprowski
  Cc: netdev, nic_swsd, linux-kernel, linux-usb

Jakub Kicinski <kuba@kernel.org>
> Sent: Tuesday, November 17, 2020 1:03 AM
[...]
> > Yes, this fixes this issue, although I would prefer a separate Kconfig
> > entry for r8153_ecm with proper dependencies instead of this ifdefs in
> > Makefile.
> 
> Agreed, this is what dependency resolution is for.
> 
> Let's just make this a separate Kconfig entry.

Excuse me. I am not familiar with Kconfig.

I wish r8153_ecm could be used, even
CONFIG_USB_RTL8152 is not defined.

How should set it in Kconfig? 

Best Regards,
Hayes


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-17  1:50             ` Hayes Wang
@ 2020-11-17 16:11               ` Jakub Kicinski
  2020-11-18  1:21                 ` Hayes Wang
  0 siblings, 1 reply; 27+ messages in thread
From: Jakub Kicinski @ 2020-11-17 16:11 UTC (permalink / raw)
  To: Hayes Wang; +Cc: Marek Szyprowski, netdev, nic_swsd, linux-kernel, linux-usb

On Tue, 17 Nov 2020 01:50:03 +0000 Hayes Wang wrote:
> Jakub Kicinski <kuba@kernel.org>
> > Sent: Tuesday, November 17, 2020 1:03 AM  
> [...]
> > > Yes, this fixes this issue, although I would prefer a separate Kconfig
> > > entry for r8153_ecm with proper dependencies instead of this ifdefs in
> > > Makefile.  
> > 
> > Agreed, this is what dependency resolution is for.
> > 
> > Let's just make this a separate Kconfig entry.  
> 
> Excuse me. I am not familiar with Kconfig.
> 
> I wish r8153_ecm could be used, even
> CONFIG_USB_RTL8152 is not defined.
> 
> How should set it in Kconfig? 

Something like this?

config USB_RTL8153_ECM
	tristate <headline text>
	select MII
	select USB_NET_CDCETHER
	depends on USB_RTL8152 || USB_RTL8152=n
	help
		<you help text>


select clauses will pull in the dependencies you need, and the
dependency on RTL8152 will be satisfied either when RTL8152's code 
is reachable (both are modules or RTL8152 is built in) or when RTL8152
is not built at all.

Does that help?

^ permalink raw reply	[flat|nested] 27+ messages in thread

* RE: [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-17 16:11               ` Jakub Kicinski
@ 2020-11-18  1:21                 ` Hayes Wang
  0 siblings, 0 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-18  1:21 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Marek Szyprowski, netdev, nic_swsd, linux-kernel, linux-usb

Jakub Kicinski <kuba@kernel.org>
> Sent: Wednesday, November 18, 2020 12:12 AM
[...]
> Something like this?
> 
> config USB_RTL8153_ECM
> 	tristate <headline text>
> 	select MII
> 	select USB_NET_CDCETHER
> 	depends on USB_RTL8152 || USB_RTL8152=n
> 	help
> 		<you help text>
> 
> 
> select clauses will pull in the dependencies you need, and the
> dependency on RTL8152 will be satisfied either when RTL8152's code
> is reachable (both are modules or RTL8152 is built in) or when RTL8152
> is not built at all.
> 
> Does that help?

Thanks a lot.
I would test it.

Best Regards,
Hayes


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH net-next v2] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-16  6:52       ` [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver Hayes Wang
  2020-11-16  9:18         ` Marek Szyprowski
@ 2020-11-18  6:43         ` Hayes Wang
  2020-11-18  8:18           ` Marek Szyprowski
  2020-11-19 16:50           ` patchwork-bot+netdevbpf
  1 sibling, 2 replies; 27+ messages in thread
From: Hayes Wang @ 2020-11-18  6:43 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb, m.szyprowski, Hayes Wang

Avoid r8153_ecm is compiled as built-in, if r8152 driver is compiled
as modules. Otherwise, the r8153_ecm would be used, even though the
device is supported by r8152 driver.

Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
v2:
Use a separate Kconfig entry for r8153_ecm with proper dependencies.

 drivers/net/usb/Kconfig  | 9 +++++++++
 drivers/net/usb/Makefile | 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index b46993d5f997..1e3719028780 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -628,4 +628,13 @@ config USB_NET_AQC111
 	  This driver should work with at least the following devices:
 	  * Aquantia AQtion USB to 5GbE
 
+config USB_RTL8153_ECM
+	tristate "RTL8153 ECM support"
+	depends on USB_NET_CDCETHER && (USB_RTL8152 || USB_RTL8152=n)
+	default y
+	help
+	  This option supports ECM mode for RTL8153 ethernet adapter, when
+	  CONFIG_USB_RTL8152 is not set, or the RTL8153 device is not
+	  supported by r8152 driver.
+
 endif # USB_NET_DRIVERS
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 99381e6bea78..4964f7b326fb 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
-obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
+obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
 obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
@@ -41,3 +41,4 @@ obj-$(CONFIG_USB_NET_QMI_WWAN)	+= qmi_wwan.o
 obj-$(CONFIG_USB_NET_CDC_MBIM)	+= cdc_mbim.o
 obj-$(CONFIG_USB_NET_CH9200)	+= ch9200.o
 obj-$(CONFIG_USB_NET_AQC111)	+= aqc111.o
+obj-$(CONFIG_USB_RTL8153_ECM)	+= r8153_ecm.o
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-18  6:43         ` [PATCH net-next v2] " Hayes Wang
@ 2020-11-18  8:18           ` Marek Szyprowski
  2020-11-19 16:50           ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 27+ messages in thread
From: Marek Szyprowski @ 2020-11-18  8:18 UTC (permalink / raw)
  To: Hayes Wang, netdev; +Cc: nic_swsd, linux-kernel, linux-usb

Hi

On 18.11.2020 07:43, Hayes Wang wrote:
> Avoid r8153_ecm is compiled as built-in, if r8152 driver is compiled
> as modules. Otherwise, the r8153_ecm would be used, even though the
> device is supported by r8152 driver.
>
> Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>

Yes, this looks like a proper fix.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
> v2:
> Use a separate Kconfig entry for r8153_ecm with proper dependencies.
>
>   drivers/net/usb/Kconfig  | 9 +++++++++
>   drivers/net/usb/Makefile | 3 ++-
>   2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
> index b46993d5f997..1e3719028780 100644
> --- a/drivers/net/usb/Kconfig
> +++ b/drivers/net/usb/Kconfig
> @@ -628,4 +628,13 @@ config USB_NET_AQC111
>   	  This driver should work with at least the following devices:
>   	  * Aquantia AQtion USB to 5GbE
>   
> +config USB_RTL8153_ECM
> +	tristate "RTL8153 ECM support"
> +	depends on USB_NET_CDCETHER && (USB_RTL8152 || USB_RTL8152=n)
> +	default y
> +	help
> +	  This option supports ECM mode for RTL8153 ethernet adapter, when
> +	  CONFIG_USB_RTL8152 is not set, or the RTL8153 device is not
> +	  supported by r8152 driver.
> +
>   endif # USB_NET_DRIVERS
> diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
> index 99381e6bea78..4964f7b326fb 100644
> --- a/drivers/net/usb/Makefile
> +++ b/drivers/net/usb/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
>   obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
>   asix-y := asix_devices.o asix_common.o ax88172a.o
>   obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
> -obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o r8153_ecm.o
> +obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
>   obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
>   obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
>   obj-$(CONFIG_USB_NET_SR9700)	+= sr9700.o
> @@ -41,3 +41,4 @@ obj-$(CONFIG_USB_NET_QMI_WWAN)	+= qmi_wwan.o
>   obj-$(CONFIG_USB_NET_CDC_MBIM)	+= cdc_mbim.o
>   obj-$(CONFIG_USB_NET_CH9200)	+= ch9200.o
>   obj-$(CONFIG_USB_NET_AQC111)	+= aqc111.o
> +obj-$(CONFIG_USB_RTL8153_ECM)	+= r8153_ecm.o

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH net-next v2] r8153_ecm: avoid to be prior to r8152 driver
  2020-11-18  6:43         ` [PATCH net-next v2] " Hayes Wang
  2020-11-18  8:18           ` Marek Szyprowski
@ 2020-11-19 16:50           ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 27+ messages in thread
From: patchwork-bot+netdevbpf @ 2020-11-19 16:50 UTC (permalink / raw)
  To: Hayes Wang; +Cc: netdev, nic_swsd, linux-kernel, linux-usb, m.szyprowski

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Wed, 18 Nov 2020 14:43:58 +0800 you wrote:
> Avoid r8153_ecm is compiled as built-in, if r8152 driver is compiled
> as modules. Otherwise, the r8153_ecm would be used, even though the
> device is supported by r8152 driver.
> 
> Fixes: c1aedf015ebd ("net/usb/r8153_ecm: support ECM mode for RTL8153")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Hayes Wang <hayeswang@realtek.com>
> 
> [...]

Here is the summary with links:
  - [net-next,v2] r8153_ecm: avoid to be prior to r8152 driver
    https://git.kernel.org/netdev/net-next/c/657bc1d10bfc

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-11-19 16:50 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 12:33 [PATCH] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
2020-10-29 15:04 ` kernel test robot
2020-10-30  3:23 ` [PATCH net-next v2] " Hayes Wang
2020-10-31 23:08   ` Jakub Kicinski
2020-11-02  7:20     ` Hayes Wang
2020-11-02 19:47       ` Jakub Kicinski
2020-11-03  9:32         ` Greg Kroah-Hartman
2020-11-03  9:51           ` Hayes Wang
2020-11-03 16:15           ` Jakub Kicinski
2020-11-04  1:39             ` Hayes Wang
2020-11-04  1:44               ` Jakub Kicinski
2020-11-03  9:46 ` [PATCH net-next v3 0/2] drivers/net/usb: " Hayes Wang
2020-11-03  9:46   ` [PATCH net-next v3 1/2] include/linux/usb: new header file for the vendor ID of USB devices Hayes Wang
2020-11-03  9:55     ` Greg KH
2020-11-03  9:46   ` [PATCH net-next v3 2/2] net/usb/r8153_ecm: support ECM mode for RTL8153 Hayes Wang
2020-11-04  2:19 ` [PATCH net-next v2 RESEND] " Hayes Wang
2020-11-06  1:00   ` Jakub Kicinski
     [not found]   ` <CGME20201113152938eucas1p2c8500d9d3d0c892c7c2a2d56b32fedc0@eucas1p2.samsung.com>
2020-11-13 15:29     ` Marek Szyprowski
2020-11-16  6:52       ` [PATCH net-next] r8153_ecm: avoid to be prior to r8152 driver Hayes Wang
2020-11-16  9:18         ` Marek Szyprowski
2020-11-16 17:02           ` Jakub Kicinski
2020-11-17  1:50             ` Hayes Wang
2020-11-17 16:11               ` Jakub Kicinski
2020-11-18  1:21                 ` Hayes Wang
2020-11-18  6:43         ` [PATCH net-next v2] " Hayes Wang
2020-11-18  8:18           ` Marek Szyprowski
2020-11-19 16:50           ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).