From patchwork Fri Oct 5 10:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10627837 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 2747E184E for ; Fri, 5 Oct 2018 10:25:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AE5A28FD5 for ; Fri, 5 Oct 2018 10:25:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F77628FEF; Fri, 5 Oct 2018 10:25:21 +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 82EAE28FD5 for ; Fri, 5 Oct 2018 10:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728249AbeJERXT (ORCPT ); Fri, 5 Oct 2018 13:23:19 -0400 Received: from mail-eopbgr720041.outbound.protection.outlook.com ([40.107.72.41]:60857 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727535AbeJERXS (ORCPT ); Fri, 5 Oct 2018 13:23:18 -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=C/sVOtb/AncW1z8jzzrtZcx8MzvSaPYgfyLq0TuahJg=; b=KcNgvebGhnS6cizSkqDzOQuhGwUJb6Q/g03qAM9WZc9PMPxiWuYakE0zOqApf+ekPcjcxTpCT7SwLUiioXy8dy5o+5+pLqZ5zmuAE9ZEZT3m2CgNLNj8eWZUPfT2ot1vn0NPfuhs4UBqsNgrOQFDBasLyVC/2NMdZEBoEFgzSRI= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1781.namprd07.prod.outlook.com (10.162.141.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.18; Fri, 5 Oct 2018 10:24:58 +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:24:58 +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 07/19] net: usb: aqc111: Add support for getting and setting of MAC address Thread-Topic: [PATCH net-next 07/19] net: usb: aqc111: Add support for getting and setting of MAC address Thread-Index: AQHUXJWqCFS83B0fpECdQ4+E96Q/nA== Date: Fri, 5 Oct 2018 10:24:58 +0000 Message-ID: <9ab691fa129ceb7a8947fde6f307fbd855d085cf.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;BY1PR0701MB1781;6:cO8HTexlC7r3bk36DouKBWY0zwX8GY0NwxeyRbXIffH2/qLLheMbalETBkyKih38X+Ja5SDH6In/dCKqUigE2hOk/nFb3pYPmhyjamY9GUONl2SDGc2rzpfpyB0p3BO3cWbsbA5Pr0U4K+aLk/SBE7NGnwecmkDir2/2InVZPoEsr/mt/FHHQ61ptJekn3qlazNRCh/yeJOtyZ4RtbAdBb0p2jUlN/JcmU0xHY1F0cMpYg4LDqo7sL8Gd6vpzX4vqLI3MMy7qPUPVl0pFKED0E6clAI/D+L3uEVfVf0msGytDHqgqF9VBQbylDJ277OkiopvkNYBxJ5Jk4WqzTKvA7w32X73hBtofpYLPWut29gLB6E2MPWNdu6JuofW7Ej7SaL8lmuO1fEauvjZWw3HIqEkWBTyQKo200p2lJEY/L8HzpyYTx8UTzmOf5h9VRFhplSikO9etEog/n39hYA6OQ==;5:SzvE31SuDHJbu0hTf0O32y0QzoSrPOSy2J3yv5elBA+aMkqUgS5ZLt96cLulY/MaJVHA/ipJAUxMcjnWqqj2lLpNgDP2AodRc+nEIQ0M38tLn+s29WOORPy3PKOZaZUqyHu3aHyjJllQb0zYDDDhkGvOuMc7tGSBtH4Hkg4U6x4=;7:84yLgefh64EtZsmNNR98+WhjCB7F+lbqXuRCm0OjYnJT/81/axjD9sXcEud39M3kk/WKOXX3IExSzQ22WeOqzVLZFfzc2uAsDEdsDGzn+UggBBx6Q+Wo95VQ2ULvUzlegrfWugLTL0JnFW9n6bJtDOqpE5qLA71efoucMpvVNhqH3Zuc5GKcAraAux5YaBQHJ1HeLUnQ5PFZFED0TGlq5vQ86CeWDW7Bzc/dNZeQQ/GyGYoDhvdx4lbNp8DKj8hA x-ms-office365-filtering-correlation-id: f6ec3fb4-ff6c-49d4-288b-08d62aacccbc x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1781; x-ms-traffictypediagnostic: BY1PR0701MB1781: 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)(5005006)(8121501046)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(201708071742011)(7699051);SRVR:BY1PR0701MB1781;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1781; x-forefront-prvs: 0816F1D86E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(376002)(136003)(366004)(39850400004)(346002)(189003)(199004)(305945005)(4326008)(7736002)(81166006)(81156014)(8676002)(97736004)(186003)(71200400001)(102836004)(6506007)(2906002)(386003)(76176011)(26005)(11346002)(107886003)(446003)(6512007)(2616005)(118296001)(476003)(5660300001)(6486002)(53936002)(68736007)(8936002)(5250100002)(44832011)(66066001)(105586002)(486006)(106356001)(25786009)(6916009)(6436002)(71190400001)(72206003)(478600001)(2900100001)(14454004)(575784001)(6116002)(3846002)(86362001)(316002)(36756003)(99286004)(256004)(52116002)(14444005)(54906003);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1781;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: 28wZvCw941bqKlj4eGkRoY0UyAxoLom2SDkbfqWS8N/l0aTL2iFk8kbZ9ThqGhQRt8a75IWb9gM2VWkDN6axmCHE+2Y3MGWNPQNhOnPSNj1K+fP9Nm7B7AaDuQwymjSYmgkeDhrIRG0U9O3+Lm2VNjLHk1LoNVaSGCRPiv+9PQiElenZGwIy/W96M+Qh8AXO1d7S4P4Ixzk2fEhAG2R/UgusKLcVz/xMBQY/CBKQ2QptvwGdcPm5Lnx1UCN15wNDs88kY97QVHlDnSBR2eGJEUu8O/reyXG57n4LL3JpV399IsgJ+HylLd7ik4801P9rPkNt0U0YCRivmoKfSWILFl6tEUykkN47Jk45UoJXuzM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6ec3fb4-ff6c-49d4-288b-08d62aacccbc X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2018 10:24:58.2910 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1781 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 | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 1 + 2 files changed, 52 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 1d366f4a1c51..075f51cd04ab 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -266,11 +267,46 @@ static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed) aqc111_set_phy_speed_fw_iface(dev, aqc111_data); } +static int aqc111_set_mac_addr(struct net_device *net, void *p) +{ + struct usbnet *dev = netdev_priv(net); + struct sockaddr *addr = p; + + if (netif_running(net)) + return -EBUSY; + if (!is_valid_ether_addr(addr->sa_data)) + return -EADDRNOTAVAIL; + + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN); + + /* 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_get_mac(struct usbnet *dev, u8 *buf) +{ + int ret; + + ret = aqc111_read_cmd(dev, AQ_FLASH_PARAMETERS, 0, 0, 6, buf); + if (ret < 0) + goto out; + + memcpy(dev->net->dev_addr, buf, ETH_ALEN); + memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); + + return 0; +out: + return ret; +} + static void aqc111_read_fw_version(struct usbnet *dev, struct aqc111_data *aqc111_data) { @@ -289,6 +325,7 @@ static void aqc111_read_fw_version(struct usbnet *dev, static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) { + u8 buf[6] = { 0 }; int ret; struct usb_device *udev = interface_to_usbdev(intf); struct aqc111_data *aqc111_data; @@ -316,6 +353,12 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) dev->data[0] = (unsigned long)aqc111_data; memset(aqc111_data, 0, sizeof(*aqc111_data)); + /* Get the MAC address */ + memset(buf, 0, ETH_ALEN); + ret = aqc111_get_mac(dev, buf); + if (ret) + goto out; + dev->net->netdev_ops = &aqc111_netdev_ops; aqc111_read_fw_version(dev, aqc111_data); @@ -324,6 +367,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) @@ -587,6 +634,10 @@ static int aqc111_reset(struct usbnet *dev) 4, &aqc111_data->phy_ops); } + /* 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 5c5602e6d236..7ca5c5a6ec82 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_CMD 0x32 #define AQ_PHY_OPS 0x61