All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] r8152: use ECM mode for future chips
@ 2014-11-24  3:09 Hayes Wang
  2014-11-24  3:09 ` [PATCH net-next 1/2] r8152: redefine REALTEK_USB_DEVICE Hayes Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hayes Wang @ 2014-11-24  3:09 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb, Hayes Wang

For the future chips which the r8152 doesn't support yet, we could
still use ECM mode for basic transmission.

Hayes Wang (2):
  r8152: redefine REALTEK_USB_DEVICE
  r8152: use ECM mode for unsupported chips

 drivers/net/usb/r8152.c | 118 +++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 107 insertions(+), 11 deletions(-)

-- 
1.9.3


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

* [PATCH net-next 1/2] r8152: redefine REALTEK_USB_DEVICE
  2014-11-24  3:09 [PATCH net-next 0/2] r8152: use ECM mode for future chips Hayes Wang
@ 2014-11-24  3:09 ` Hayes Wang
  2014-11-24  3:09 ` [PATCH net-next 2/2] r8152: use ECM mode for unsupported chips Hayes Wang
  2014-11-24  4:57 ` [PATCH net-next 0/2] r8152: use ECM mode for future chips David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Hayes Wang @ 2014-11-24  3:09 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb, Hayes Wang

Redefine REALTEK_USB_DEVICE for the desired USB interface for probe().
There are three USB interfaces for the device. USB_CLASS_COMM and
USB_CLASS_CDC_DATA are for ECM mode (config #2). USB_CLASS_VENDOR_SPEC
is for the vendor mode (config #1). However, we are not interesting
in USB_CLASS_CDC_DATA for probe(), so redefine REALTEK_USB_DEVICE
to ignore the USB interface class of USB_CLASS_CDC_DATA.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 4a9ece0..2d1c77e 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -24,6 +24,7 @@
 #include <net/ip6_checksum.h>
 #include <uapi/linux/mdio.h>
 #include <linux/mdio.h>
+#include <linux/usb/cdc.h>
 
 /* Version Information */
 #define DRIVER_VERSION "v1.07.0 (2014/10/09)"
@@ -466,9 +467,6 @@ enum rtl8152_flags {
 #define MCU_TYPE_PLA			0x0100
 #define MCU_TYPE_USB			0x0000
 
-#define REALTEK_USB_DEVICE(vend, prod)	\
-	USB_DEVICE_INTERFACE_CLASS(vend, prod, USB_CLASS_VENDOR_SPEC)
-
 struct tally_counter {
 	__le64	tx_packets;
 	__le64	rx_packets;
@@ -3915,11 +3913,27 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 	}
 }
 
+#define REALTEK_USB_DEVICE(vend, prod)	\
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = (vend), \
+	.idProduct = (prod), \
+	.bInterfaceClass = USB_CLASS_VENDOR_SPEC \
+}, \
+{ \
+	.match_flags = USB_DEVICE_ID_MATCH_INT_INFO | \
+		       USB_DEVICE_ID_MATCH_DEVICE, \
+	.idVendor = (vend), \
+	.idProduct = (prod), \
+	.bInterfaceClass = USB_CLASS_COMM, \
+	.bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
+	.bInterfaceProtocol = USB_CDC_PROTO_NONE
+
 /* table of devices that work with this driver */
 static struct usb_device_id rtl8152_table[] = {
-	{USB_DEVICE(VENDOR_ID_REALTEK, 0x8152)},
-	{USB_DEVICE(VENDOR_ID_REALTEK, 0x8153)},
-	{USB_DEVICE(VENDOR_ID_SAMSUNG, 0xa101)},
+	{REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8152)},
+	{REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8153)},
+	{REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, 0xa101)},
 	{}
 };
 
-- 
1.9.3


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

* [PATCH net-next 2/2] r8152: use ECM mode for unsupported chips
  2014-11-24  3:09 [PATCH net-next 0/2] r8152: use ECM mode for future chips Hayes Wang
  2014-11-24  3:09 ` [PATCH net-next 1/2] r8152: redefine REALTEK_USB_DEVICE Hayes Wang
@ 2014-11-24  3:09 ` Hayes Wang
  2014-11-24  4:57 ` [PATCH net-next 0/2] r8152: use ECM mode for future chips David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Hayes Wang @ 2014-11-24  3:09 UTC (permalink / raw)
  To: netdev; +Cc: nic_swsd, linux-kernel, linux-usb, Hayes Wang

Use usbnet_cdc_bind to initialize the chips which the driver doesn't
support yet, if the cdc_ether is set.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 87 insertions(+), 5 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 2d1c77e..9989e5b 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -25,9 +25,10 @@
 #include <uapi/linux/mdio.h>
 #include <linux/mdio.h>
 #include <linux/usb/cdc.h>
+#include <linux/usb/usbnet.h>
 
 /* Version Information */
-#define DRIVER_VERSION "v1.07.0 (2014/10/09)"
+#define DRIVER_VERSION "v1.08.0 (2014/11/24)"
 #define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
 #define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
 #define MODULENAME "r8152"
@@ -3219,12 +3220,24 @@ static void r8153_init(struct r8152 *tp)
 	rtl_tally_reset(tp);
 }
 
+static bool rtl_vendor_mode(struct usb_interface *intf)
+{
+	struct usb_host_interface *alt = intf->cur_altsetting;
+
+	return alt->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC;
+}
+
 static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
 {
 	struct r8152 *tp = usb_get_intfdata(intf);
 	struct net_device *netdev = tp->netdev;
 	int ret = 0;
 
+#if defined(CONFIG_USB_NET_CDCETHER) || defined(CONFIG_USB_NET_CDCETHER_MODULE)
+	if (!rtl_vendor_mode(intf))
+		return usbnet_suspend(intf, message);
+#endif /* CONFIG_USB_NET_CDCETHER */
+
 	mutex_lock(&tp->control);
 
 	if (PMSG_IS_AUTO(message)) {
@@ -3261,6 +3274,11 @@ static int rtl8152_resume(struct usb_interface *intf)
 {
 	struct r8152 *tp = usb_get_intfdata(intf);
 
+#if defined(CONFIG_USB_NET_CDCETHER) || defined(CONFIG_USB_NET_CDCETHER_MODULE)
+	if (!rtl_vendor_mode(intf))
+		return usbnet_resume(intf);
+#endif /* CONFIG_USB_NET_CDCETHER */
+
 	mutex_lock(&tp->control);
 
 	if (!test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
@@ -3742,6 +3760,17 @@ static void r8152b_get_version(struct r8152 *tp)
 	}
 }
 
+static bool rtl_supported(struct usb_device *udev)
+{
+	struct r8152 fake;
+
+	memset(&fake, 0, sizeof(fake));
+	fake.udev = udev;
+	r8152b_get_version(&fake);
+
+	return fake.version != RTL_VER_UNKNOWN;
+}
+
 static void rtl8152_unload(struct r8152 *tp)
 {
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
@@ -3803,13 +3832,28 @@ static int rtl8152_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
+	bool support = rtl_supported(udev);
 	struct r8152 *tp;
 	struct net_device *netdev;
-	int ret;
+	int ret = -ENODEV;
 
-	if (udev->actconfig->desc.bConfigurationValue != 1) {
-		usb_driver_set_configuration(udev, 1);
-		return -ENODEV;
+	if (!rtl_vendor_mode(intf)) {
+		if (support)
+			usb_driver_set_configuration(udev, 1);
+#if defined(CONFIG_USB_NET_CDCETHER) || defined(CONFIG_USB_NET_CDCETHER_MODULE)
+		else
+			ret = usbnet_probe(intf, id);
+#endif /* CONFIG_USB_NET_CDCETHER */
+
+		return ret;
+	} else if (!support) {
+		/* The driver doesn't support this chip yet.
+		 * Try to use cdc_ether.
+		 */
+#if defined(CONFIG_USB_NET_CDCETHER) || defined(CONFIG_USB_NET_CDCETHER_MODULE)
+		usb_driver_set_configuration(udev, 2);
+#endif /* CONFIG_USB_NET_CDCETHER */
+		return ret;
 	}
 
 	usb_reset_device(udev);
@@ -3899,6 +3943,13 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 {
 	struct r8152 *tp = usb_get_intfdata(intf);
 
+#if defined(CONFIG_USB_NET_CDCETHER) || defined(CONFIG_USB_NET_CDCETHER_MODULE)
+	if (!rtl_vendor_mode(intf)) {
+		usbnet_disconnect(intf);
+		return;
+	}
+#endif /* CONFIG_USB_NET_CDCETHER */
+
 	usb_set_intfdata(intf, NULL);
 	if (tp) {
 		struct usb_device *udev = tp->udev;
@@ -3913,6 +3964,35 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 	}
 }
 
+#if defined(CONFIG_USB_NET_CDCETHER) || defined(CONFIG_USB_NET_CDCETHER_MODULE)
+static const struct driver_info	cdc_info = {
+	.description =	"r815x CDC Ethernet Device",
+	.flags =	FLAG_ETHER | FLAG_POINTTOPOINT,
+	.bind =		usbnet_cdc_bind,
+	.unbind =	usbnet_cdc_unbind,
+	.status =	usbnet_cdc_status,
+	.manage_power =	usbnet_manage_power,
+};
+
+#define REALTEK_USB_DEVICE(vend, prod)	\
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = (vend), \
+	.idProduct = (prod), \
+	.bInterfaceClass = USB_CLASS_VENDOR_SPEC \
+}, \
+{ \
+	.match_flags = USB_DEVICE_ID_MATCH_INT_INFO | \
+		       USB_DEVICE_ID_MATCH_DEVICE, \
+	.idVendor = (vend), \
+	.idProduct = (prod), \
+	.bInterfaceClass = USB_CLASS_COMM, \
+	.bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
+	.bInterfaceProtocol = USB_CDC_PROTO_NONE, \
+	.driver_info = (unsigned long)&cdc_info,
+
+#else
+
 #define REALTEK_USB_DEVICE(vend, prod)	\
 	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
 		       USB_DEVICE_ID_MATCH_INT_CLASS, \
@@ -3929,6 +4009,8 @@ static void rtl8152_disconnect(struct usb_interface *intf)
 	.bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
 	.bInterfaceProtocol = USB_CDC_PROTO_NONE
 
+#endif /* CONFIG_USB_NET_CDCETHER */
+
 /* table of devices that work with this driver */
 static struct usb_device_id rtl8152_table[] = {
 	{REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, 0x8152)},
-- 
1.9.3


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

* Re: [PATCH net-next 0/2] r8152: use ECM mode for future chips
  2014-11-24  3:09 [PATCH net-next 0/2] r8152: use ECM mode for future chips Hayes Wang
  2014-11-24  3:09 ` [PATCH net-next 1/2] r8152: redefine REALTEK_USB_DEVICE Hayes Wang
  2014-11-24  3:09 ` [PATCH net-next 2/2] r8152: use ECM mode for unsupported chips Hayes Wang
@ 2014-11-24  4:57 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-11-24  4:57 UTC (permalink / raw)
  To: hayeswang; +Cc: netdev, nic_swsd, linux-kernel, linux-usb

From: Hayes Wang <hayeswang@realtek.com>
Date: Mon, 24 Nov 2014 11:09:47 +0800

> For the future chips which the r8152 doesn't support yet, we could
> still use ECM mode for basic transmission.

Gross, please don't do this.

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

end of thread, other threads:[~2014-11-24  4:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-24  3:09 [PATCH net-next 0/2] r8152: use ECM mode for future chips Hayes Wang
2014-11-24  3:09 ` [PATCH net-next 1/2] r8152: redefine REALTEK_USB_DEVICE Hayes Wang
2014-11-24  3:09 ` [PATCH net-next 2/2] r8152: use ECM mode for unsupported chips Hayes Wang
2014-11-24  4:57 ` [PATCH net-next 0/2] r8152: use ECM mode for future chips David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.