From patchwork Fri Oct 5 10:25:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10627849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB2EF112B for ; Fri, 5 Oct 2018 10:25:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA44F28FE7 for ; Fri, 5 Oct 2018 10:25:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEA4328FFE; Fri, 5 Oct 2018 10:25:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CEF428FE7 for ; Fri, 5 Oct 2018 10:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728520AbeJERXo (ORCPT ); Fri, 5 Oct 2018 13:23:44 -0400 Received: from mail-bl2nam02on0086.outbound.protection.outlook.com ([104.47.38.86]:26494 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728325AbeJERXl (ORCPT ); Fri, 5 Oct 2018 13:23:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=AQUANTIA1COM.onmicrosoft.com; s=selector1-aquantia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tsXf/nMSN0httpBzoNW3tR3mJKm0BNB09AsgisWXjWI=; b=LkbDckSRnjMnvGUZjor9ighOQZl/sEhA6sPoeYP9W/ZAofiaVyD/p+H8Snn9VtqPl2ThPSAGjKZXPKaLCQ2rITaQjiHyy6PI2NukZVYmv4hvAGTjn68z/NVq+1iHYuhJ8LEXMcAW+5nYEnMHmwNDasRRW3lR7AslQnEeT2IM0QU= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1641.namprd07.prod.outlook.com (10.162.110.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.21; Fri, 5 Oct 2018 10:25:20 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17%2]) with mapi id 15.20.1207.021; Fri, 5 Oct 2018 10:25:20 +0000 From: Igor Russkikh To: "David S . Miller" CC: "linux-usb@vger.kernel.org" , "netdev@vger.kernel.org" , Igor Russkikh , Dmitry Bezrukov Subject: [PATCH net-next 16/19] net: usb: aqc111: Add RX VLAN filtering support Thread-Topic: [PATCH net-next 16/19] net: usb: aqc111: Add RX VLAN filtering support Thread-Index: AQHUXJW3czzme0NHGkaNbMjqZni63w== Date: Fri, 5 Oct 2018 10:25:20 +0000 Message-ID: <100f2bdc2e23a298afdf240180d224cf39d692ad.1538734658.git.igor.russkikh@aquantia.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5PR0602CA0024.eurprd06.prod.outlook.com (2603:10a6:203:a3::34) To BY1PR0701MB1660.namprd07.prod.outlook.com (2a01:111:e400:522a::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Igor.Russkikh@aquantia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [95.79.108.179] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BY1PR0701MB1641;6:mULxvKRoZAh+ZccquO3F18zQ9TmVz4+CiqEoP3udZMfOW7ws+86rodOwUNRpRUSssOh1z9Rkb3L/Q/+5lX8vEAzXJhhhy5ieOecbQv0FzJXWpKyl7SiJNOFEH8Mr+Sjbq8ztPix5sPgHZffwXZFKnYDrHyXVPJm5uhDMVCUQnb8PwPlTjEnhKLVFTVM77tVKTNaozRJ1PMBZNXgJvvrCFOgmxNat6tsDNtOk7Nn5LeJX+WAjZyMUP9BzxXot3QdCd/srY/4kcQAnJby42GRpvbHHJjt8SgnypFZveulDaCgricvY8f0nJUUOQsa1vGRs3JYh9Dc/CqhaVzAtjPnaiipE5ho3fY5ZZBpuQb/YZNdLptuGtNq0z+vzRx9hCIJRTbHwYus2tQ7wc/tDFIUcLkFEI2gqYsbOpGHT0i7lOauy0IrCQRgBpft+I2BERRdflCbAalJuqb+X4C6n2QNmuQ==;5:KZlOHsNgQqYrQXQnge+2KDlk2Kl3eosjx+06qLu7hgVHBMjNF5Ahq5s2/Qq64JIbvMoVZd1AkrIhyGEfqj/HrRO4L2xkMSVd+Gm7SwLZUEHktsMhfBQI6pETAie3V50Fnz3uBhLsWdNQKW/+iWx3O0QpBovJJaKmH7kQcUJOL20=;7:sZFrNL3kXpzo80Vm1HwzBYP8GQzsD5SEWeYU4Ef/9nFZfrPk61tsxXyoWn/67dawmCX0pUu0/4coMbuSJGIUVDw8zDi8i3xYzTQ2aUkbm4qrYoLk8ASAB62XydaxRZ7iOJTBZ71meOX8NHRrG8V32aLgxF//8HG+yhkarvbPSqCDuiPo332ctNlDLcQHt/GnboplIcRq04mF/Fl12ucn7mXE9UPs5RmQeGhyIAd1hP0YSDS9yqulfWP08nnXVX8M x-ms-office365-filtering-correlation-id: 9a22d2f2-24dd-4547-20d1-08d62aacd9c6 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1641; x-ms-traffictypediagnostic: BY1PR0701MB1641: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051);SRVR:BY1PR0701MB1641;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1641; x-forefront-prvs: 0816F1D86E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(346002)(136003)(39850400004)(396003)(199004)(189003)(575784001)(81166006)(81156014)(6436002)(86362001)(8676002)(118296001)(316002)(14454004)(6512007)(8936002)(66066001)(256004)(386003)(2900100001)(11346002)(2906002)(6506007)(6486002)(52116002)(36756003)(107886003)(3846002)(486006)(53936002)(71190400001)(476003)(99286004)(105586002)(14444005)(97736004)(26005)(44832011)(2616005)(68736007)(54906003)(186003)(5660300001)(5250100002)(71200400001)(446003)(76176011)(7736002)(4326008)(102836004)(106356001)(305945005)(478600001)(6116002)(6916009)(72206003)(25786009);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1641;H:BY1PR0701MB1660.namprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 0GzDBMuYvkLrzzYgosgIvzhJagWc8UP4GfO4rBQQB7RmEnSHIgYPDYok4QO/oEhfRC+hAHOylPU9T1thdaas7JZcECkfysPVqZ2a5ndE9uVsZeQHb53kewRABp5WNvGKkpjfc2yIt5eLAk43phoxbogfU4Qc8TPu84eQ+CHSy9mOH9Tc0w/Q+6knaA2NKs4jEErm7Gwebf7FEguI7GivO5N+VZhohWlQWIXSpv/ewNQggOq3I8AvRKDZj7u2M+v7BqpWLm3nFNksXC6El/bz6HgU0hD4wvZNly0KbQa8sxJrcA36UEJGN5FBO0a+dM4dMfclVlMQvdu+XZfZBAfcktnLN54qJMYxrG6fFkDuPh4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a22d2f2-24dd-4547-20d1-08d62aacd9c6 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2018 10:25:20.1823 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1641 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Bezrukov Signed-off-by: Dmitry Bezrukov Signed-off-by: Igor Russkikh --- drivers/net/usb/aqc111.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 2 +- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index a9051dd7c5bd..9908b0a04da6 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -351,6 +351,57 @@ static int aqc111_set_mac_addr(struct net_device *net, void *p) ETH_ALEN, net->dev_addr); } +static int aqc111_vlan_rx_kill_vid(struct net_device *net, + __be16 proto, u16 vid) +{ + struct usbnet *dev = netdev_priv(net); + u8 reg8 = 0; + u16 reg16 = 0; + u8 vlan_ctrl = 0; + + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); + vlan_ctrl = reg8; + + /* Address */ + reg8 = (vid / 16); + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_ADDRESS, 1, 1, ®8); + /* Data */ + reg8 = vlan_ctrl | SFR_VLAN_CONTROL_RD; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, 2, ®16); + reg16 &= ~(1 << (vid % 16)); + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, 2, ®16); + reg8 = vlan_ctrl | SFR_VLAN_CONTROL_WE; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); + + return 0; +} + +static int aqc111_vlan_rx_add_vid(struct net_device *net, __be16 proto, u16 vid) +{ + struct usbnet *dev = netdev_priv(net); + u8 reg8 = 0; + u16 reg16 = 0; + u8 vlan_ctrl = 0; + + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); + vlan_ctrl = reg8; + + /* Address */ + reg8 = (vid / 16); + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_ADDRESS, 1, 1, ®8); + /* Data */ + reg8 = vlan_ctrl | SFR_VLAN_CONTROL_RD; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, 2, ®16); + reg16 |= (1 << (vid % 16)); + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, 2, ®16); + reg8 = vlan_ctrl | SFR_VLAN_CONTROL_WE; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); + + return 0; +} + static void aqc111_set_rx_mode(struct net_device *net) { struct usbnet *dev = netdev_priv(net); @@ -393,6 +444,7 @@ static int aqc111_set_features(struct net_device *net, netdev_features_t features) { u8 reg8 = 0; + u16 reg16 = 0; struct usbnet *dev = netdev_priv(net); struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; netdev_features_t changed = net->features ^ features; @@ -426,6 +478,39 @@ static int aqc111_set_features(struct net_device *net, aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_RXCOE_CTL, 1, 1, ®8); } + if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) { + if (features & NETIF_F_HW_VLAN_CTAG_FILTER) { + u16 i = 0; + + for (i = 0; i < 256; i++) { + /* Address */ + reg8 = i; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, + SFR_VLAN_ID_ADDRESS, + 1, 1, ®8); + /* Data */ + aqc111_write_cmd(dev, AQ_ACCESS_MAC, + SFR_VLAN_ID_DATA0, + 2, 2, ®16); + reg8 = SFR_VLAN_CONTROL_WE; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, + SFR_VLAN_ID_CONTROL, + 1, 1, ®8); + } + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, + 1, 1, ®8); + reg8 |= SFR_VLAN_CONTROL_VFE; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, + SFR_VLAN_ID_CONTROL, 1, 1, ®8); + } else { + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, + 1, 1, ®8); + reg8 &= ~SFR_VLAN_CONTROL_VFE; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, + SFR_VLAN_ID_CONTROL, 1, 1, ®8); + } + } + return 0; } @@ -438,6 +523,8 @@ static const struct net_device_ops aqc111_netdev_ops = { .ndo_change_mtu = aqc111_change_mtu, .ndo_set_mac_address = aqc111_set_mac_addr, .ndo_validate_addr = eth_validate_addr, + .ndo_vlan_rx_add_vid = aqc111_vlan_rx_add_vid, + .ndo_vlan_rx_kill_vid = aqc111_vlan_rx_kill_vid, .ndo_set_rx_mode = aqc111_set_rx_mode, .ndo_set_features = aqc111_set_features, }; @@ -726,6 +813,8 @@ static int aqc111_link_reset(struct usbnet *dev) /* Vlan Tag Filter */ reg8 = SFR_VLAN_CONTROL_VSO; + if (dev->net->features & NETIF_F_HW_VLAN_CTAG_FILTER) + reg8 |= SFR_VLAN_CONTROL_VFE; aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8); @@ -994,6 +1083,7 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) new_skb->truesize = new_skb->len + sizeof(struct sk_buff); if (aqc111_data->rx_checksum) aqc111_rx_checksum(new_skb, &pkt_desc); + if (pkt_desc->vlan_ind) __vlan_hwaccel_put_tag(new_skb, htons(ETH_P_8021Q), diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index e33459d90ddd..a7ccee225e93 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -73,7 +73,7 @@ #define AQ_SUPPORT_HW_FEATURE (NETIF_F_SG | NETIF_F_IP_CSUM |\ NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |\ - NETIF_F_TSO) + NETIF_F_TSO | NETIF_F_HW_VLAN_CTAG_FILTER) #define AQ_SUPPORT_VLAN_FEATURE (NETIF_F_SG | NETIF_F_IP_CSUM |\ NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |\