From patchwork Mon Nov 26 09:33:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10697879 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 1D38A16B1 for ; Mon, 26 Nov 2018 09:33:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D31D29818 for ; Mon, 26 Nov 2018 09:33:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F253E2981D; Mon, 26 Nov 2018 09:33:23 +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 691CC29818 for ; Mon, 26 Nov 2018 09:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbeKZU0v (ORCPT ); Mon, 26 Nov 2018 15:26:51 -0500 Received: from mail-eopbgr710041.outbound.protection.outlook.com ([40.107.71.41]:44880 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726290AbeKZU0t (ORCPT ); Mon, 26 Nov 2018 15:26:49 -0500 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=78OY4Br2DQxnRWsrfCOqsle6/T1hp0aQhUxvP0+oUxs=; b=q9O61bDHdiGyy3lS32glKigJBwgxyLJRqByuLKJJbyglVhvBSBex9zdm2z15SZ3pk/oDKvI1UWQdH7UaecvOQr9R9jF0xhEDGzf8CCkaVyI2VcVGbxk74dh9ARYRnpl0IS1SREBiWmvU4G+Qkew7Z5OudDFeTxRKXgHwdOlgQ1s= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1894.namprd07.prod.outlook.com (10.162.143.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1361.18; Mon, 26 Nov 2018 09:33:14 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::f8ee:2260:e410:fffd]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::f8ee:2260:e410:fffd%3]) with mapi id 15.20.1361.019; Mon, 26 Nov 2018 09:33:14 +0000 From: Igor Russkikh To: "linux-usb@vger.kernel.org" , "davem@davemloft.net" , "netdev@vger.kernel.org" CC: "andrew@lunn.ch" , Dmitry Bezrukov , Igor Russkikh Subject: [PATCH v4 net-next 07/21] net: usb: aqc111: Add support for getting and setting of MAC address Thread-Topic: [PATCH v4 net-next 07/21] net: usb: aqc111: Add support for getting and setting of MAC address Thread-Index: AQHUhWsOLjrd46Rb5EGWquMZItJoHA== Date: Mon, 26 Nov 2018 09:33:14 +0000 Message-ID: <68f0eeb9d18045cbf056042f5f29a72790fc468b.1543224254.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: AM6PR03CA0024.eurprd03.prod.outlook.com (2603:10a6:20b::37) 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;BY1PR0701MB1894;6:nhCsrxfpaj4cq1sC6qbSBiEoB2NT8rERQHIXV+bYSsrUrDpuVT4e/1ZCsLw2JKxSOLY31F68A7JCzahwJd3N5t/BmRJgaKM4TCALaoJXaV7n5NiARW6tfEM3EBLAJoHKaRbcqxNTUHfuZmOUPXz5tAwZxjpBubn5TfrU0yFgsSz6qDCgjdhFZavyUaP+3LzI6Tak5q1cMzrevq+kmu4FgI8rYKsCeQEHHGSi6+77Oylx6lj9ylUiv1JRhNnjmN6Js25sCgaS6HVleshU8ZHdO0KqYn6aZd8IOsuI65/Bod/rGbbQEJvZgMZagDAgVgZH6icZsCX0QhOtyi45OUJLqGvh6Of43DBPE+50oE0qIGPyeXi1RGnmGR+w8vDxdlsJiVKjqDtlEJ3/4tpudNNhVE5xQJczIeOnJyOVqcrjh2jfQIeW+eOv+swRnSsVvjh7KhDlXLO6x/3BkPkXFD0DUg==;5:GIHINPxYoSXq3AUBikmgGEgZmJU+Rw6a0TPzmCqStKPkNLcnXVQQo1HFTOqnbTxPRmNwycwedc+uwC+BGOp1VIbUZVwtx0tJpjw7AG1vlIosDKB+5xJlrsS5h0kPzhdasMBaH3/lYHcTDWuhW1LbBbunn0ElJgoIK1FFnasif+Y=;7:gpJRzrw4tgiW8QAAfkKy6I8x/rWaQ51WPfd+PmecI3Sps4evaiGYQEDmfG9qy7tB03DS0dls1NiSLwrkx0v2h3EfDRQ616CnRL+wWccEg9X0VwRjQWm+8+9JjLeDaL1MZZbNCBOQlgcJ5U3ZNudTiw== x-ms-office365-filtering-correlation-id: 766f4711-47ea-4bd9-cd9e-08d65382303e x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1894; x-ms-traffictypediagnostic: BY1PR0701MB1894: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(3231443)(944501410)(52105112)(10201501046)(93006095)(93001095)(148016)(149066)(150057)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1894;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1894; x-forefront-prvs: 086831DFB4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39840400004)(376002)(396003)(136003)(366004)(346002)(199004)(189003)(14454004)(102836004)(97736004)(71200400001)(71190400001)(54906003)(6436002)(72206003)(105586002)(110136005)(11346002)(446003)(186003)(486006)(25786009)(2906002)(7736002)(575784001)(86362001)(5660300001)(316002)(305945005)(2201001)(2501003)(53936002)(99286004)(36756003)(52116002)(6506007)(6116002)(76176011)(386003)(4326008)(3846002)(68736007)(6512007)(107886003)(476003)(81166006)(478600001)(118296001)(26005)(106356001)(8676002)(256004)(81156014)(14444005)(2616005)(6486002)(66066001)(44832011)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1894;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: UkGKlu8Uh0ehE0tR78kqb3yGLlDlycBsBo3dQ0hd/7qHaWxAOHojOKhRanc3WJyxzoIECIl1xI+rqMGBe3uNmS+jtEkc0AZi6OUpZpKC0YzJQLL64eEUB2tr0SFRL+YcWZrFSrYL1CEquM86JrVGGyChpcWZdAsRG/zF0wLdkY3a/3N17ZpSGRv7l2IdVKYOHYBnfkJF/QYSTEN8FR0WMkKHBZA8XabH9GUkWXKO+kcI7dwqVwwm48+8Oo+PfUYmAL0w36aUyn57wqg74xdAAVjZWtOsNcb2t5E1gxgTW3f42ylmvmw+XB2K9wrUk8W6R92FaDGJ6Wu6QecTq7Dm5/TuXjCXUm0SnJF2b6ocLKM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 766f4711-47ea-4bd9-cd9e-08d65382303e X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Nov 2018 09:33:14.4311 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1894 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 | 47 ++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 1 + 2 files changed, 48 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index e33be16b506c..390ed6cbc3fd 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -204,11 +205,43 @@ static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed) aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, &aqc111_data->phy_cfg); } +static int aqc111_set_mac_addr(struct net_device *net, void *p) +{ + struct usbnet *dev = netdev_priv(net); + int ret = 0; + + ret = eth_mac_addr(net, p); + if (ret < 0) + return ret; + + /* Set the MAC address */ + return aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_NODE_ID, ETH_ALEN, + ETH_ALEN, net->dev_addr); +} + static const struct net_device_ops aqc111_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop, + .ndo_set_mac_address = aqc111_set_mac_addr, + .ndo_validate_addr = eth_validate_addr, }; +static int aqc111_read_perm_mac(struct usbnet *dev) +{ + u8 buf[ETH_ALEN]; + int ret; + + ret = aqc111_read_cmd(dev, AQ_FLASH_PARAMETERS, 0, 0, ETH_ALEN, buf); + if (ret < 0) + goto out; + + ether_addr_copy(dev->net->perm_addr, buf); + + return 0; +out: + return ret; +} + static void aqc111_read_fw_version(struct usbnet *dev, struct aqc111_data *aqc111_data) { @@ -251,6 +284,12 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) /* store aqc111_data pointer in device data field */ dev->driver_priv = aqc111_data; + /* Init the MAC address */ + ret = aqc111_read_perm_mac(dev); + if (ret) + goto out; + + ether_addr_copy(dev->net->dev_addr, dev->net->perm_addr); dev->net->netdev_ops = &aqc111_netdev_ops; aqc111_read_fw_version(dev, aqc111_data); @@ -259,6 +298,10 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) SPEED_5000 : SPEED_1000; return 0; + +out: + kfree(aqc111_data); + return ret; } static void aqc111_unbind(struct usbnet *dev, struct usb_interface *intf) @@ -467,6 +510,10 @@ static int aqc111_reset(struct usbnet *dev) aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, &aqc111_data->phy_cfg); + /* Set the MAC address */ + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_NODE_ID, ETH_ALEN, + ETH_ALEN, dev->net->dev_addr); + reg8 = 0xFF; aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK, 1, 1, ®8); diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index f3b45d8ca4e3..0c8e1ee29893 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -11,6 +11,7 @@ #define __LINUX_USBNET_AQC111_H #define AQ_ACCESS_MAC 0x01 +#define AQ_FLASH_PARAMETERS 0x20 #define AQ_PHY_POWER 0x31 #define AQ_PHY_OPS 0x61