From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934589AbcIGINV (ORCPT ); Wed, 7 Sep 2016 04:13:21 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:53698 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756325AbcIGIMz (ORCPT ); Wed, 7 Sep 2016 04:12:55 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.56 with qID u878Cr39019608, This message is accepted by code: ctloc85258 From: Hayes Wang To: CC: , , , Hayes Wang Subject: [PATCH net-next 3/3] r8152: add CONFIG_RTL8152_CONFIG_VALUE Date: Wed, 7 Sep 2016 16:12:22 +0800 Message-ID: <1394712342-15778-218-Taiwan-albertk@realtek.com> X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <1394712342-15778-215-Taiwan-albertk@realtek.com> References: <1394712342-15778-215-Taiwan-albertk@realtek.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.21.177.199] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org According to CONFIG_RTL8152_CONFIG_VALUE, to determine which mode the driver supports. The value 0 means to support both vendor mode and ECM mode. The value 1 means to support vendor mode only. The value 2 means to support ECM mode only. Signed-off-by: Hayes Wang --- drivers/net/usb/Kconfig | 13 +++++++++++++ drivers/net/usb/r8152.c | 30 ++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index cdde590..3d2fd09 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig @@ -106,6 +106,19 @@ config USB_RTL8152 To compile this driver as a module, choose M here: the module will be called r8152. +config RTL8152_CONFIG_VALUE + depends on USB_RTL8152 + int "RTL8152/RTL8153 USB Configuration Value" + default 1 + help + This is used to select the USB configuration value of RTL8152/RTL8153. + 0: support all configuration values. It means the user could + change the configuration value. However, it may have problem + if you change the configuration value frequently. Don't set + this value unless you really know what you want. + 1: use vendor mode only. (recommended) + 2: use ECM mode only. + config USB_LAN78XX tristate "Microchip LAN78XX Based USB Ethernet Adapters" select MII diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index c4e8339..480af78 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -30,7 +30,7 @@ #include /* Information for net-next */ -#define NETNEXT_VERSION "08" +#define NETNEXT_VERSION "09" /* Information for net */ #define NET_VERSION "5" @@ -4267,11 +4267,6 @@ static int rtl8152_probe(struct usb_interface *intf, if (version == RTL_VER_UNKNOWN) return -ENODEV; - if (udev->actconfig->desc.bConfigurationValue != 1) { - usb_driver_set_configuration(udev, 1); - return -ENODEV; - } - usb_reset_device(udev); netdev = alloc_etherdev(sizeof(struct r8152)); if (!netdev) { @@ -4403,9 +4398,32 @@ static void rtl8152_disconnect(struct usb_interface *intf) } } +static bool rtl_change_config(struct usb_interface *intf) +{ + struct usb_device *udev = interface_to_usbdev(intf); + u8 actconfig = udev->actconfig->desc.bConfigurationValue; + + if (CONFIG_RTL8152_CONFIG_VALUE <= 0 || + udev->descriptor.bNumConfigurations < CONFIG_RTL8152_CONFIG_VALUE || + actconfig == CONFIG_RTL8152_CONFIG_VALUE) + return false; + + if (CONFIG_RTL8152_CONFIG_VALUE == 1 && !rtl_get_version(intf)) + return false; + + return true; +} + static int rtl_usbnet_probe(struct usb_interface *intf, const struct usb_device_id *id) { + if (rtl_change_config(intf)) { + struct usb_device *udev = interface_to_usbdev(intf); + + usb_driver_set_configuration(udev, CONFIG_RTL8152_CONFIG_VALUE); + return -ENODEV; + } + switch (id->bInterfaceClass) { case USB_CLASS_VENDOR_SPEC: return rtl8152_probe(intf, id); -- 2.7.4