From patchwork Wed Nov 21 10:13:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10692247 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 F29DB1751 for ; Wed, 21 Nov 2018 10:13:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBAF029412 for ; Wed, 21 Nov 2018 10:13:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB2372975D; Wed, 21 Nov 2018 10:13:33 +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 2432F29412 for ; Wed, 21 Nov 2018 10:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729181AbeKUUrT (ORCPT ); Wed, 21 Nov 2018 15:47:19 -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 S1726001AbeKUUrT (ORCPT ); Wed, 21 Nov 2018 15:47:19 -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=S/URxoN3WJzHeqXRMwKxORwhrJdIPQ1n0xeiffvf418=; b=jUwb9D9tWYx+xbTiah893eMzv6K0owp56fwUdO0HkB6oU8V9HBLhX3WE6eIhJsaH4gksqlmtTD+whNGHamv0ormtNZceLt3BoyEC8vYf6JJO+BrP6N1opgUCcK9CDG+VZKS2uyiasJMeAJzatLaaqZarffW2ExckW1gNMT+DDUw= 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:26 +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:26 +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 03/21] net: usb: aqc111: Add implementation of read and write commands Thread-Topic: [PATCH v3 net-next 03/21] net: usb: aqc111: Add implementation of read and write commands Thread-Index: AQHUgYLXZvhEKtXsWk2y9kdgjJk/7Q== Date: Wed, 21 Nov 2018 10:13:26 +0000 Message-ID: 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:ExkBy80+xZySmHm8q1dyL6xDP4YmsVv3QiZRYeeFVcNx/a/URzO9FxTZDaQRT5V2QyIIlc6H1MvRY3pmGXPXwc/oWaSUSRBiN9T6BnNWuwIGeXD/ZXbc2gh1yF0NEeG3BS9JBi/hBrMVWFjI/VS+UQMFytqcufHR9Y1vzUDDnAUr93bwP8nxeaM17ZgVAm2eX0D1c7B/TyyWvhJzA7ypVy6kH2hUplXU/HtKEZchoH8t/0HiBIYwuk5QegzgrQCCnYuxU8i54HV7ffwkikbWlwiH40tLLylsHs3awwozMry8oVi6jDNB+wBiTPt72tkeXi0d8Fi0HDyjlFmSqPnEmpNPWiQKOqM1+Ve9OUUnCYM4U2scrGzQSk8wh+leuKosUyy92J8Hc8nmTGHlpFPsYGnzlil1llQMcCdYebpMpRGOjPU4ztoECSpAEheMrIWsBw7EpmahOtwRpVe3MFdCMLA/6m05TBEZZZ2ZDbT+7aA=;5:GNlxhGbl8gWPfd2WLcgedrScnub4Mae9phJu3iYCwYoiVs//a5gCYkgp9afTVhyCb5S00/u5KzWFXQQc8WJCq9yU0zPdsWGuUg4ukVyMSsIcSGPk6woE5uoLQZ1sa251rXUVoJ2/4bhyizytJePoiMG8x9uCn/lcGAcos6fQ++A=;7:0Zn0WwZfV0UZPlJaEVwPYtXQGCETY5VfhQ+Bgi9dFARV1nMuHcFTrtdpq9aPD4maF6HJV0NbtkA2x2oynwPJJ9ZM7bba+Tz8E7HXdM6CWxaTqHTk/YJmRdC0gm6ZUmsJjbrroFzBBDD+xK7G/RnUtQ== x-ms-office365-filtering-correlation-id: 331cb3ab-e2d8-4f80-ab74-08d64f99f9e9 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:(112561432440764); 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)(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: R40RdykRq+P31fH55cW/wSImqzOyvATdzRvR9a7Lze5SXa1aGsz3ASXzrO8JMVITJmFZAVUVps2lzdxP33LNof6tSiPvQfa5Rq04COmlLEtYPbV/2pqVZ54yDsEgPiZbVntkcyz0Y72SN7FDTfnxroKyi0I6MwFGcnvBl+qJmYzqgav83DidR469slzKgDtiH7vgTHscbqbMZuO3AoZAdP+C2Lv2MIKLiiUfVtwyKkPbRuJxKx/29WjkfjGpiuDkHjbkUHFNaruBR5W/8YYLcEJAIMyQn4FEaags/yf5tVW4+RoKjSHh8lqYEXC22yhPzzx6bmKFFb2HHknmO5XCEqSofeSSzvPz2/TyaBDUZpU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 331cb3ab-e2d8-4f80-ab74-08d64f99f9e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2018 10:13:26.4997 (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 Read/write command register defines and functions Signed-off-by: Dmitry Bezrukov Signed-off-by: Igor Russkikh --- drivers/net/usb/aqc111.c | 92 ++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 18 ++++++++ 2 files changed, 110 insertions(+) create mode 100644 drivers/net/usb/aqc111.h diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index a2628856c580..fbd48b8a6944 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -14,6 +14,98 @@ #include #include +#include "aqc111.h" + +static int aqc111_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, + u16 index, u16 size, void *data) +{ + int ret; + + ret = usbnet_read_cmd_nopm(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, value, index, data, size); + + if (unlikely(ret < 0)) + netdev_warn(dev->net, + "Failed to read(0x%x) reg index 0x%04x: %d\n", + cmd, index, ret); + + return ret; +} + +static int aqc111_read_cmd(struct usbnet *dev, u8 cmd, u16 value, + u16 index, u16 size, void *data) +{ + int ret; + + ret = usbnet_read_cmd(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, value, index, data, size); + + if (unlikely(ret < 0)) + netdev_warn(dev->net, + "Failed to read(0x%x) reg index 0x%04x: %d\n", + cmd, index, ret); + + return ret; +} + +static int __aqc111_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, + u16 value, u16 index, u16 size, const void *data) +{ + int err = -ENOMEM; + void *buf = NULL; + + netdev_dbg(dev->net, + "%s cmd=%#x reqtype=%#x value=%#x index=%#x size=%d\n", + __func__, cmd, reqtype, value, index, size); + + if (data) { + buf = kmemdup(data, size, GFP_KERNEL); + if (!buf) + goto out; + } + + err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), + cmd, reqtype, value, index, buf, size, + (cmd == AQ_PHY_POWER) ? AQ_USB_PHY_SET_TIMEOUT : + AQ_USB_SET_TIMEOUT); + + if (unlikely(err < 0)) + netdev_warn(dev->net, + "Failed to write(0x%x) reg index 0x%04x: %d\n", + cmd, index, err); + kfree(buf); + +out: + return err; +} + +static int aqc111_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, + u16 index, u16 size, void *data) +{ + int ret; + + ret = __aqc111_write_cmd(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, value, index, size, data); + + return ret; +} + +static int aqc111_write_cmd(struct usbnet *dev, u8 cmd, u16 value, + u16 index, u16 size, void *data) +{ + int ret; + + if (usb_autopm_get_interface(dev->intf) < 0) + return -ENODEV; + + ret = __aqc111_write_cmd(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, value, index, size, data); + + usb_autopm_put_interface(dev->intf); + + return ret; +} + static const struct net_device_ops aqc111_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop, diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h new file mode 100644 index 000000000000..f4302f7f0cc3 --- /dev/null +++ b/drivers/net/usb/aqc111.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Aquantia Corp. Aquantia AQtion USB to 5GbE Controller + * Copyright (C) 2003-2005 David Hollis + * Copyright (C) 2005 Phil Chang + * Copyright (C) 2002-2003 TiVo Inc. + * Copyright (C) 2017-2018 ASIX + * Copyright (C) 2018 Aquantia Corp. + */ + +#ifndef __LINUX_USBNET_AQC111_H +#define __LINUX_USBNET_AQC111_H + +#define AQ_PHY_POWER 0x31 + +#define AQ_USB_PHY_SET_TIMEOUT 10000 +#define AQ_USB_SET_TIMEOUT 4000 + +#endif /* __LINUX_USBNET_AQC111_H */