From patchwork Tue Nov 13 14:44:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10680855 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 1C6BE13BF for ; Tue, 13 Nov 2018 14:44:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AC6028D48 for ; Tue, 13 Nov 2018 14:44:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F34B529208; Tue, 13 Nov 2018 14:44:43 +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 715F528E66 for ; Tue, 13 Nov 2018 14:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387776AbeKNAnJ (ORCPT ); Tue, 13 Nov 2018 19:43:09 -0500 Received: from mail-eopbgr810040.outbound.protection.outlook.com ([40.107.81.40]:18907 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726846AbeKNAnI (ORCPT ); Tue, 13 Nov 2018 19:43:08 -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=lBDORbT2ZxVS/GCFjOsY9aTCD+x7NrDBm/+pFRZ4VhU=; b=dv/d/deUPKpBiHZm/MPane2dnxCPYzN4kcRaGNxywEwvVqEaK6sFoUE5PL1gjETKaGel3DwCYM1euUT9EafciqrNZM58Irj3I/NlcD6gd8e3CbnmqocxuY5EQywKdPKsMNgsuekZFoxaRd/n7k9TQRWAf26AHIH1Zw4Jw0q8TTA= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1208.namprd07.prod.outlook.com (10.160.105.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.36; Tue, 13 Nov 2018 14:44:38 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::c031:16d9:9580:3d11]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::c031:16d9:9580:3d11%6]) with mapi id 15.20.1294.045; Tue, 13 Nov 2018 14:44:38 +0000 From: Igor Russkikh To: "David S . Miller" CC: "linux-usb@vger.kernel.org" , "netdev@vger.kernel.org" , Dmitry Bezrukov , Igor Russkikh Subject: [PATCH v2 net-next 03/21] net: usb: aqc111: Add implementation of read and write commands Thread-Topic: [PATCH v2 net-next 03/21] net: usb: aqc111: Add implementation of read and write commands Thread-Index: AQHUe19mITHYElWMw0ud4NGHi10wzg== Date: Tue, 13 Nov 2018 14:44:37 +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: AM5P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:206:15::26) 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;BY1PR0701MB1208;6:I8gUAQijy7A9y2kbNurvua7rLMbKk1T28YZgaM7Gwk/+bXB/iL//9SICrYlHyla8nsLcLaAbZStCHNWXlvM4dc+PEB6oxiYS6wbchqRDEk4SAFNUY+mi2CkrsbPjuknSBzHfLV8AiJr+IQoFaqgAqb9JOpBasUPVY4YjIL1fMm1wHpcQ4nCFt9LYdYn7Rj0bTz6mVz9d4r0g293tAlKW8dQ47Iziwb2OkJVHQbBfy1c+TiohmtRq7xnszCq4QXdLA+4oj8v/PkuUGOO6gd5VslQ5lc1XHFvUWEL1zRkFihwcTVSp0BkBKecJrbFMJKYGkgmopC2V+3b1xoTstgWdoIaSRfpnUKfGQwx/4N7EetCqot2mDJjFBbSUZ2nFPQdaSrqzxlsqmkeaV2H03lNDOY3cF5q9TMboXz167Tinc/roAsqMlu7A6suzJfvoDblTytcmrqnuNREPvc1R+j52pw==;5:KebSyMGVx5hAOmggoDh/7JUwVqWWPLH47Mpdr2uNu/AlqoLN1pA9raErSNMbY2kQIBB/QZ8N7MIaI6sGUPFVMmV0vpoM15JrTP8WZI+pitpIxQYSY1qBKMSBaJR5Kq58NZXtV2qnhUfJAutDNK+U8zrD2yPdVaA9clTzroqaeFU=;7:3j8I3YbxB3F9F4z8QjYVpsKfHuY+yAGCS9gB0dZdQKzcectWy2ScVJET2kLUaSa57tcOIlGqDrffY3rUFtawo/28D7LYP7XEDARYgsbcv2MRkjeqBlPjpM0wWegRl+o2R+mGHmI/iB/Buwj7R44wow== x-ms-office365-filtering-correlation-id: 870213a8-c924-41f7-db0e-08d649768910 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390060)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1208; x-ms-traffictypediagnostic: BY1PR0701MB1208: 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)(3231406)(944501410)(52105112)(10201501046)(93006095)(93001095)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1208;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1208; x-forefront-prvs: 085551F5A8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39850400004)(346002)(376002)(396003)(366004)(136003)(199004)(189003)(71190400001)(71200400001)(54906003)(72206003)(44832011)(305945005)(2906002)(66066001)(4326008)(118296001)(107886003)(105586002)(106356001)(36756003)(99286004)(52116002)(2900100001)(76176011)(476003)(14454004)(2616005)(6916009)(6506007)(186003)(575784001)(386003)(486006)(86362001)(8676002)(8936002)(102836004)(11346002)(446003)(5660300001)(6486002)(256004)(81156014)(81166006)(53936002)(25786009)(68736007)(26005)(97736004)(316002)(7736002)(3846002)(478600001)(6116002)(6436002)(6512007);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1208;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: 4MykahxbQ2me20HR1EF5D0fFT56gphJIKk9HsbGZTTy/WvPFwijrfQtNe2AVj0qTnqQKN+EytPZE9IRhKdTOabo1DNFrREtMqei1UVssa3EnIhblTKsS+lDfew19hWZXK1e9GWDI+EwUVBHLoRVssr3Ee/5aJJ3MtaMDtDJqEN2d6GFYOo1lPPq4Jv0unQLQ1kqcy8vxdjxpokQgsyX5WNoeAY+bhvZ65ispvjEKOoiqzvarLJRJj7d49RX1+hpnbcqqBXwa2n3Mx3f/0YhvIRm3xyDneoUc5odV/1ZJGjK5Wd5RE+j6Mc93rjO/hIww+rwx0mXXfdUoWMQu0TJZSQOJGz+9z3KFhntPuKsWj2M= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 870213a8-c924-41f7-db0e-08d649768910 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2018 14:44:37.8499 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1208 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 b54bb4a98ee3..34ed841b81dc 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 */