Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4066090ybg; Fri, 25 Oct 2019 12:50:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxL+olW6/Z6khf/7KWgIJlIsymLLSNywa1qUgLRrcH+Gq6h70QkcNJbohYl0N9v5LwdzGv X-Received: by 2002:a50:f288:: with SMTP id f8mr5845451edm.43.1572033002134; Fri, 25 Oct 2019 12:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572033002; cv=none; d=google.com; s=arc-20160816; b=1EKE63ylH5rrRECoqp3KRY7HTprC1ZDYbxMj/IsMC/bGtPqqQvF4yoqurfEOH056WT 3YUweeAvU6s2Iiog1UCfMgsjFweBduSv4D6a1Ydb6tHiHSMMsec4W8IvSYck8JjN8Zgb gVse8QKmS9dw+vNz6ZfLswmC4eGIrqEHe4oTutTJlAw8kvlBjkLQcW3zcPjlRQuJIlBP vvqkDoZr1Di3SP6+tbPkTI1aEFF06Vuoix3k0yTXDf/Aj/D1bQR4shb4LB7ljXBd/KJk Qds2hIdc3j5GLwr1iurPkdJUsFgvBreE7lxx/AxLdM+XwaRb6dOE2PbQf6hlhoNOIyYZ 5cBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=UXFldIpTEXvM3BCnNG0m8fHTJzFYHwwbgacQg+PEy3Q=; b=b14MNh6yuXL2ToFfJfp01n4WB9qKEAgrCleTK75YXi/AlVDweG6wn/DC4BS+jcXL04 yeBGmoWrbPVNCypQy7luFC0Q6EOEfza/kxwVPTfMOTuTXo7YijkoLjfy041CB0q5GMFY ERrTg/7hM5bITRKRVAg5rPgVxTZp5Wf76gB7MNq2y93opv1RaHI9X6BvaS0I4NtraCxz kmxJlGYO9M7ZOd7dHOkr4vKdCm3seXfeFoImcwGlbwC7jiuxD3zvIDCqrRRDyVxhlvZx LDKIartabsmrHgX4cZyUogoEgXL9Kz7T6WaFxgOsbUrUB1dMwClcAXavyZYsmxfHyTYb kT8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h37si1842715eda.249.2019.10.25.12.49.38; Fri, 25 Oct 2019 12:50:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439323AbfJYLSK (ORCPT + 99 others); Fri, 25 Oct 2019 07:18:10 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:42533 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbfJYLSJ (ORCPT ); Fri, 25 Oct 2019 07:18:09 -0400 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iNxJY-0002cx-TZ; Fri, 25 Oct 2019 10:59:29 +0000 From: Kai-Heng Feng To: davem@davemloft.net, oliver@neukum.org Cc: hayeswang@realtek.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kai-Heng Feng Subject: [PATCH 2/2] r8152: Add macpassthru support for ThinkPad Thunderbolt 3 Dock Gen 2 Date: Fri, 25 Oct 2019 18:59:19 +0800 Message-Id: <20191025105919.689-2-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191025105919.689-1-kai.heng.feng@canonical.com> References: <20191025105919.689-1-kai.heng.feng@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ThinkPad Thunderbolt 3 Dock Gen 2 is another docking station that uses RTL8153 based USB ethernet. The device supports macpassthru, but it failed to pass the test of -AD, -BND and -BD. Simply bypass these tests since the device supports this feature just fine. Also the ACPI objects have some differences between Dell's and Lenovo's, so make those ACPI infos no longer hardcoded. BugLink: https://bugs.launchpad.net/bugs/1827961 Signed-off-by: Kai-Heng Feng --- drivers/net/usb/cdc_ether.c | 7 ++++ drivers/net/usb/r8152.c | 65 ++++++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c index 32f53de5b1fe..92751f6e792d 100644 --- a/drivers/net/usb/cdc_ether.c +++ b/drivers/net/usb/cdc_ether.c @@ -766,6 +766,13 @@ static const struct usb_device_id products[] = { .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), + .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, diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 1a987d4e45ab..65bdb745860c 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -658,6 +658,8 @@ enum rtl_register_content { #define RTL8152_NAPI_WEIGHT 64 #define rx_reserved_size(x) ((x) + VLAN_ETH_HLEN + ETH_FCS_LEN + \ sizeof(struct rx_desc) + RX_ALIGN) +/* Device quirks */ +#define R8152_QUIRK_LENOVO_MACPASSTHRU BIT(1) /* rtl8152 flags */ enum rtl8152_flags { @@ -670,6 +672,7 @@ enum rtl8152_flags { SCHEDULE_TASKLET, GREEN_ETHERNET, DELL_TB_RX_AGG_BUG, + LENOVO_MACPASSTHRU, }; /* Define these values to match your device */ @@ -1408,38 +1411,57 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) int ret = -EINVAL; u32 ocp_data; unsigned char buf[6]; - - /* test for -AD variant of RTL8153 */ - ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); - if ((ocp_data & AD_MASK) == 0x1000) { - /* test for MAC address pass-through bit */ - ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE); - if ((ocp_data & PASS_THRU_MASK) != 1) { - netif_dbg(tp, probe, tp->netdev, - "No efuse for RTL8153-AD MAC pass through\n"); - return -ENODEV; - } + bool bypass_test; + char *mac_obj_name; + acpi_object_type mac_obj_type; + int mac_strlen; + + if (test_bit(LENOVO_MACPASSTHRU, &tp->flags)) { + bypass_test = true; + mac_obj_name = "\\MACA"; + mac_obj_type = ACPI_TYPE_STRING; + mac_strlen = 0x16; } else { - /* test for RTL8153-BND and RTL8153-BD */ - ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1); - if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) { - netif_dbg(tp, probe, tp->netdev, - "Invalid variant for MAC pass through\n"); - return -ENODEV; + bypass_test = false; + mac_obj_name = "\\_SB.AMAC"; + mac_obj_type = ACPI_TYPE_BUFFER; + mac_strlen = 0x17; + } + + if (!bypass_test) { + /* test for -AD variant of RTL8153 */ + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0); + if ((ocp_data & AD_MASK) == 0x1000) { + /* test for MAC address pass-through bit */ + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, EFUSE); + if ((ocp_data & PASS_THRU_MASK) != 1) { + netif_dbg(tp, probe, tp->netdev, + "No efuse for RTL8153-AD MAC pass through\n"); + return -ENODEV; + } + } else { + /* test for RTL8153-BND and RTL8153-BD */ + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1); + if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) { + netif_dbg(tp, probe, tp->netdev, + "Invalid variant for MAC pass through\n"); + return -ENODEV; + } } } /* returns _AUXMAC_#AABBCCDDEEFF# */ - status = acpi_evaluate_object(NULL, "\\_SB.AMAC", NULL, &buffer); + status = acpi_evaluate_object(NULL, mac_obj_name, NULL, &buffer); obj = (union acpi_object *)buffer.pointer; if (!ACPI_SUCCESS(status)) return -ENODEV; - if (obj->type != ACPI_TYPE_BUFFER || obj->string.length != 0x17) { + if (obj->type != mac_obj_type || obj->string.length != mac_strlen) { netif_warn(tp, probe, tp->netdev, "Invalid buffer for pass-thru MAC addr: (%d, %d)\n", obj->type, obj->string.length); goto amacout; } + if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) != 0 || strncmp(obj->string.pointer + 0x15, "#", 1) != 0) { netif_warn(tp, probe, tp->netdev, @@ -6626,6 +6648,9 @@ static int rtl8152_probe(struct usb_interface *intf, netdev->hw_features &= ~NETIF_F_RXCSUM; } + if (id->driver_info & R8152_QUIRK_LENOVO_MACPASSTHRU) + set_bit(LENOVO_MACPASSTHRU, &tp->flags); + if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x3011 && udev->serial && (!strcmp(udev->serial, "000001000000") || !strcmp(udev->serial, "000002000000"))) { @@ -6754,6 +6779,8 @@ static const struct usb_device_id rtl8152_table[] = { {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x304f, 0)}, {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x3062, 0)}, {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x3069, 0)}, + {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x3082, + R8152_QUIRK_LENOVO_MACPASSTHRU)}, {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7205, 0)}, {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x720c, 0)}, {REALTEK_USB_DEVICE(VENDOR_ID_LENOVO, 0x7214, 0)}, -- 2.17.1