From patchwork Wed Nov 21 10:13:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10692271 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 CD6101751 for ; Wed, 21 Nov 2018 10:14:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B98F52B8C7 for ; Wed, 21 Nov 2018 10:14:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADAD52B8CE; Wed, 21 Nov 2018 10:14:18 +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 2DD6F2B8CA for ; Wed, 21 Nov 2018 10:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729699AbeKUUsG (ORCPT ); Wed, 21 Nov 2018 15:48:06 -0500 Received: from mail-eopbgr790082.outbound.protection.outlook.com ([40.107.79.82]:39040 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728314AbeKUUsF (ORCPT ); Wed, 21 Nov 2018 15:48:05 -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=GDlXehAV2lmdP9BT5yZnzDPT50ebMZ+mtolW4w7JrcuHqgk2OLe3UdE1Tb1gFn1cyp2NTUhj6888YRcnyra684XubJF9T2Ty7Q34qgkBiwnjytMlLOzP+Xoqp5VXfWtDnw0+uB1eUpg6fxWPpFe2rQeVONSRJq85+TeA5YuWZ2I= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1159.namprd07.prod.outlook.com (10.160.105.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.36; Wed, 21 Nov 2018 10:13:35 +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.015; Wed, 21 Nov 2018 10:13:35 +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 v3 net-next 07/21] net: usb: aqc111: Add support for getting and setting of MAC address Thread-Topic: [PATCH v3 net-next 07/21] net: usb: aqc111: Add support for getting and setting of MAC address Thread-Index: AQHUgYLdnE7VPdc8K0ymWEn3RaKBcg== Date: Wed, 21 Nov 2018 10:13:35 +0000 Message-ID: <8f92711d8479a3df65849e60fd92c727e1e1f78a.1542794577.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: AM6PR0402CA0007.eurprd04.prod.outlook.com (2603:10a6:209::20) 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;BY1PR0701MB1159;6:1SdfyjqWeKTEcfiuI0d6gfcvphbL+kgk+z+Gmu42ywhlgKAor/DrVZRTC9aixOpGj1vHUBpmUVwUBrUvQ++Fqev9otyZ3LEcBTQ4SOxN0/5yIRfUagejVB5rW91jF7d4TuygK729W7arXNH6cMGPvM5jXsHGOJY8BspnP0g2DhSrNHLo/1RSDh1hBJddELtp5g5FkIekpsS84eeYkxTwLwvv+E+KVLSsUuywqTqYe6hRN9OY0BZLCDQVTXn9n3q0JmfGQ0DWvdHN22ojUOG9sQj+Q3QKAlYvuUmLugEEUf8T2LupZ+jKH1/RuqKSJPDJQJLjEajLow97MSaW66a6ZvESNip6SVQlh2dcXD/jVuKFuRhcOBMBsx4NXfCZtTx4A7Y7L8nMNakd5N+YLz/rbv2oPRZo0lGFff8lSQSgcmvYi33X+I98GnUTFSoApLCTwoEYZe2AWni5l5puucvP1G/oHHBnwLySfoGFoiWM4hA=;5:MIN0lmwaIncXQfjEErtyj9Czpyi8z8WGXqXE6m/sCXtRmLzyLa+jx3iqS5CUirxbavHy191zYgYDv6UC9dquekvI1N1eRlVYOz5YGL1w47P766baeu7LbSz4OdAlrtNWxBUg+r1b5kM11xv9UssIssQ2U0FI7YXNgibFq4c++4I=;7:DCmTYcCwRB9n69N4+LURO/GEbtqEjFQD2oNwq53otI/5P3OyRlQPHsJG26y8ZbO1+E0wfyurgem/MS7JSOrj5ZQVgH1OvsphTTaZuwOJobeHG7ukpDipXBFrPSO4HswMZeqSyeIekpLFpc3jZMeEzg== x-ms-office365-filtering-correlation-id: f7eaceef-04a9-42a3-dff2-08d64f99ff3f x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1159; x-ms-traffictypediagnostic: BY1PR0701MB1159: 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)(93006095)(93001095)(3231442)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1159;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1159; x-forefront-prvs: 08635C03D4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(346002)(39850400004)(396003)(376002)(366004)(136003)(189003)(199004)(186003)(386003)(446003)(44832011)(71200400001)(476003)(2616005)(66066001)(14444005)(256004)(6506007)(97736004)(71190400001)(81166006)(8936002)(102836004)(2900100001)(81156014)(118296001)(11346002)(68736007)(26005)(486006)(99286004)(52116002)(14454004)(305945005)(7736002)(2906002)(478600001)(6512007)(575784001)(86362001)(76176011)(5660300001)(3846002)(53936002)(6116002)(107886003)(106356001)(4326008)(105586002)(110136005)(316002)(25786009)(72206003)(36756003)(54906003)(8676002)(2201001)(2501003)(6436002)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1159;H:BY1PR0701MB1660.namprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: HcREmrEXljUehZrZovo0LwxoH98pKxWd33YP0kbUbxXnU501BM+i5ku2ZrTzeXPVw1rl0Bm6nmhFlFvcF1zIi5io3wjTrLkUbWprbldFeRbA45EFEeRroLlozVB7Kn0C/gXPDyBNnXdth8e4QhbIX1Xutj6vocOijzxVdnnGbPFb1KCbjlUvEerQmqd3EeAPrvedoPIKcxf/HejIKtOog/aLoZtNWcj39z4U31MUXDQkhmH9s/DCEkG0aHdbsQNF+/CLAX9UZSMXlb4CYysnHaxqa4eDVyXN0fHDgvOaGOylgJ2ZcGUN08/aX01u9K7ITDo5iTD+2xCceSScY18dNCFJ93eE3B1nlKug+hNU+K4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7eaceef-04a9-42a3-dff2-08d64f99ff3f X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2018 10:13:35.4220 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1159 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