From patchwork Fri Oct 5 10:25: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: 10627853 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 2EA00112B for ; Fri, 5 Oct 2018 10:25:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20FAC28FE7 for ; Fri, 5 Oct 2018 10:25:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A1428FFB; Fri, 5 Oct 2018 10:25:45 +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 4451128FE7 for ; Fri, 5 Oct 2018 10:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728545AbeJERXt (ORCPT ); Fri, 5 Oct 2018 13:23:49 -0400 Received: from mail-cys01nam02on0062.outbound.protection.outlook.com ([104.47.37.62]:21998 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728461AbeJERXt (ORCPT ); Fri, 5 Oct 2018 13:23:49 -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=Bho4muClEujPNSOXMd1TnJ0ulXsvkU8WU3r9SS7/hHY=; b=MXYMHd/ANTZxp7tQaSNRyIZbzDBIeT8fzliADOuPkfkxHOB04BkNKAWiQtw7k8BH+4gx5+N2aGAagB0z/m4HAmOf0bsuploY6tqPHB7Nv99Lu9We8r5ANguBikr4WQuOq6JwE0QLVJWG2AEmiHUzRnyRunQkWEbwqlQo5b1eZ7k= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1768.namprd07.prod.outlook.com (10.162.141.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.23; Fri, 5 Oct 2018 10:25:36 +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:25:36 +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 19/19] net: usb: aqc111: Add support for wake on LAN by MAGIC packet Thread-Topic: [PATCH net-next 19/19] net: usb: aqc111: Add support for wake on LAN by MAGIC packet Thread-Index: AQHUXJXAje/zeZQMG0K85N764SRgEw== Date: Fri, 5 Oct 2018 10:25:35 +0000 Message-ID: <1a7d4af1b3a6397b76338d543f86bb4c327f5060.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;BY1PR0701MB1768;6:b/iqhU/VDBsQSQCelBFOik7httXcLWAefr/11d0RGoePWR0OuQSzXLi9L2R4rhHIx8ZK9el6IMowV844ik6yVLM21sHxgZDD0g11+5TrAf6CemVkaBCk8DQLGF4zh9fw7Z0DrWd1B4HlRp/5iTln9+NqfcdS1ylO5vYS2jbgLGPUeaH8oqQl7R7n9TKMUvaiIpbLLH4ELkBGl0znSHNLEV7SlczywV87D/1YC6Qj3aglRxdYf9kWXSyJYbmYZH4lisqB7GG2UJZhL/X41T4qnePC1saJZ3S4IuqEux2ubXbj91WDp6ACypVf/b8mlbGWukd+es75mfmQv/XUrzToRaz8Bo2Wx3O+AOvYaAcdJYhCtWPHaRuu2qBJnlYDMJUubV3qD6EP0me9RmRyh8ukrbbSOzDBtjgdwi6vwUdO3vPWNnC8qW9s8M9qembmdxTjtHNjxWzd+BHBuTLedWasDQ==;5:P4U1NyzMhwHJ8lbwyPchrAiENMm6mLiZGvAr9Cg+owtSftkhx0bd4BWHAFukDcrKpkaju+7F1fmgOE9/gjr/jqqCCpRHYNPzYVKoApCmjv3cNR3Sh9VKHZKgy0jZhmleBvB9tcCz1zedV/3r2VhHNszcdhdhKDmm+y3MPq4CeJA=;7:dKOPpXQZUkFLCbPw4x4mt57Yo6Yc1TAgt09OMBWKOaoGuO+R7o6ZqfABx6MrXdJzZlB3aymizlbE+TjXrJT08LLah1RdIybBjcElQhjNxOq3fsvvHlMJpmqaGmBOoMuOTe1O/GeP/2KmDLw/e9VBeXKBhl/XGRJ4f0XNf7n5d+rsUpDWgefZJ8uHaO7eg/B6cyueLqCw7epQnDGp4JAQA/49y4XroWMrh1s7A2o8Pla7fjqFrWLl7M7ORCaqgbsu x-ms-office365-filtering-correlation-id: d10d2a11-5040-4041-9eb4-08d62aace330 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1768; x-ms-traffictypediagnostic: BY1PR0701MB1768: 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)(10201501046)(3002001)(93006095)(93001095)(3231355)(944501410)(52105095)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051);SRVR:BY1PR0701MB1768;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1768; x-forefront-prvs: 0816F1D86E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(346002)(376002)(396003)(39850400004)(136003)(199004)(189003)(186003)(26005)(4326008)(2906002)(102836004)(53936002)(486006)(81166006)(14454004)(8676002)(81156014)(446003)(8936002)(105586002)(5660300001)(106356001)(72206003)(11346002)(25786009)(68736007)(2900100001)(478600001)(76176011)(99286004)(6506007)(386003)(6436002)(6486002)(52116002)(6512007)(476003)(2616005)(256004)(97736004)(71190400001)(14444005)(44832011)(6916009)(36756003)(316002)(86362001)(71200400001)(5250100002)(107886003)(575784001)(305945005)(54906003)(7736002)(66066001)(118296001)(6116002)(3846002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1768;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: 5OAYMGN8U5LB7mEo4NvS2wajUa3u0vv0oItDJ4IvPZK5odu1yQ2nDRt7Y4+9orw99EbupkOec6XHZprILy/tO5VUc4vv/HvvIjQZctppk5qrrleanfyZG02uiul41syVSdlOPT3wKvYFMxb9YU+HaPjeCfDWrA82ceILCFq/CK8TkHcXXzm0AWmKz504Pr64umP/xlWaEpbmLhWxmzI0bnGbVf50KyuDXFp15VE8hsz/BVz5BLAeGhBobNmSsptVPA+k0Cz+cwtNvs4VA+bOVEGvw+JHOMtbZ0QBxqfbdIBd3n8L8hGeCtsir6CCEEe3KhCrqdep4CFYhg8iLkEe4Hv+4Lxz2Mx8zqNnhOnIXZs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d10d2a11-5040-4041-9eb4-08d62aace330 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2018 10:25:35.9797 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1768 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 | 203 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 11 +++ 2 files changed, 214 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 20d4347ea3ad..e2ea8dc54d3a 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -192,6 +192,35 @@ static void aqc111_get_drvinfo(struct net_device *net, info->regdump_len = 0x00; } +static void aqc111_get_wol(struct net_device *net, + struct ethtool_wolinfo *wolinfo) +{ + struct usbnet *dev = netdev_priv(net); + struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; + + wolinfo->supported = WAKE_MAGIC; + wolinfo->wolopts = 0; + + if (aqc111_data->wol_cfg.flags & AQ_WOL_FLAG_MP) + wolinfo->wolopts |= WAKE_MAGIC; +} + +static int aqc111_set_wol(struct net_device *net, + struct ethtool_wolinfo *wolinfo) +{ + struct usbnet *dev = netdev_priv(net); + struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; + + if (wolinfo->wolopts & ~WAKE_MAGIC) + return -EINVAL; + + aqc111_data->wol_cfg.flags = 0; + if (wolinfo->wolopts & WAKE_MAGIC) + aqc111_data->wol_cfg.flags |= AQ_WOL_FLAG_MP; + + return 0; +} + static void aqc111_speed_to_link_mode(u32 speed, struct ethtool_link_ksettings *elk) { @@ -441,6 +470,8 @@ static int aqc111_set_link_ksettings(struct net_device *net, static const struct ethtool_ops aqc111_ethtool_ops = { .get_drvinfo = aqc111_get_drvinfo, + .get_wol = aqc111_get_wol, + .set_wol = aqc111_set_wol, .get_msglevel = usbnet_get_msglevel, .set_msglevel = usbnet_set_msglevel, .get_link = ethtool_op_get_link, @@ -1346,6 +1377,176 @@ static const struct driver_info aqc111_info = { .tx_fixup = aqc111_tx_fixup, }; +static int aqc111_suspend(struct usb_interface *intf, pm_message_t message) +{ + struct usbnet *dev = usb_get_intfdata(intf); + struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; + u8 reg8; + u16 reg16; + u16 temp_rx_ctrl = 0x00; + + usbnet_suspend(intf, message); + + aqc111_read_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, 2, ®16); + temp_rx_ctrl = reg16; + /* Stop RX operations*/ + reg16 &= ~SFR_RX_CTL_START; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, + 2, 2, ®16); + /* Force bz */ + aqc111_read_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL, + 2, 2, ®16); + reg16 |= SFR_PHYPWR_RSTCTL_BZ; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL, + 2, 2, ®16); + + reg8 = SFR_BULK_OUT_EFF_EN; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BULK_OUT_CTRL, + 1, 1, ®8); + + temp_rx_ctrl &= ~(SFR_RX_CTL_START | SFR_RX_CTL_RF_WAK | + SFR_RX_CTL_AP | SFR_RX_CTL_AM); + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, + 2, 2, &temp_rx_ctrl); + + reg8 = 0x00; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH, + 1, 1, ®8); + + if (aqc111_data->wol_cfg.flags) { + aqc111_data->phy_ops.wol = 1; + if (aqc111_data->dpa) { + reg8 = 0; + if (aqc111_data->wol_cfg.flags & AQ_WOL_FLAG_MP) + reg8 |= SFR_MONITOR_MODE_RWMP; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MONITOR_MODE, 1, 1, ®8); + } else { + memcpy(aqc111_data->wol_cfg.hw_addr, + dev->net->dev_addr, ETH_ALEN); + } + + temp_rx_ctrl |= (SFR_RX_CTL_AB | SFR_RX_CTL_START); + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, + 2, 2, &temp_rx_ctrl); + reg8 = 0x00; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK, + 1, 1, ®8); + reg8 = SFR_BMRX_DMA_EN; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BMRX_DMA_CONTROL, + 1, 1, ®8); + reg8 = SFR_RX_PATH_READY; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH, + 1, 1, ®8); + reg8 = 0x07; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QCTRL, + 1, 1, ®8); + reg8 = 0x00; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_RX_BULKIN_QTIMR_LOW, 1, 1, ®8); + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_RX_BULKIN_QTIMR_HIGH, 1, 1, ®8); + reg8 = 0xFF; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QSIZE, + 1, 1, ®8); + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QIFG, + 1, 1, ®8); + + aqc111_read_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, + 2, 2, ®16); + reg16 |= SFR_MEDIUM_RECEIVE_EN; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); + + if (aqc111_data->dpa) { + aqc111_set_phy_speed(dev, AUTONEG_DISABLE, SPEED_100); + } else { + aqc111_write_cmd(dev, AQ_WOL_CFG, 0, 0, + WOL_CFG_SIZE, &aqc111_data->wol_cfg); + aqc111_write_cmd(dev, AQ_PHY_OPS, 0, 0, + 4, &aqc111_data->phy_ops); + } + } else { + aqc111_data->phy_ops.low_power = 1; + if (!aqc111_data->dpa) { + aqc111_write_cmd(dev, AQ_PHY_OPS, 0, 0, + 4, &aqc111_data->phy_ops); + } else { + reg16 = AQ_PHY_LOW_POWER_MODE; + aq_mdio_write_cmd(dev, AQ_GLB_STD_CTRL_REG, + AQ_PHY_GLOBAL_ADDR, 2, ®16); + } + + /* Disable RX path */ + aqc111_read_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); + reg16 &= ~SFR_MEDIUM_RECEIVE_EN; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); + } + + return 0; +} + +static int aqc111_resume(struct usb_interface *intf) +{ + struct usbnet *dev = usb_get_intfdata(intf); + struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; + u8 reg8; + u16 reg16; + + netif_carrier_off(dev->net); + + /* Power up ethernet PHY */ + aqc111_data->phy_ops.phy_power = 1; + aqc111_data->phy_ops.low_power = 0; + aqc111_data->phy_ops.wol = 0; + if (aqc111_data->dpa) { + aqc111_read_cmd_nopm(dev, AQ_PHY_POWER, 0, 0, 1, ®8); + if (reg8 == 0x00) { + reg8 = 0x02; + aqc111_write_cmd_nopm(dev, AQ_PHY_POWER, 0, 0, + 1, ®8); + msleep(200); + } + + aq_mdio_read_cmd(dev, AQ_GLB_STD_CTRL_REG, AQ_PHY_GLOBAL_ADDR, + 2, ®16); + if (reg16 & AQ_PHY_LOW_POWER_MODE) { + reg16 &= ~AQ_PHY_LOW_POWER_MODE; + aq_mdio_write_cmd(dev, AQ_GLB_STD_CTRL_REG, + AQ_PHY_GLOBAL_ADDR, 2, ®16); + } + } + + reg8 = 0xFF; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK, + 1, 1, ®8); + /* Configure RX control register => start operation */ + reg16 = aqc111_data->rxctl; + reg16 &= ~SFR_RX_CTL_START; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, 2, ®16); + + reg16 |= SFR_RX_CTL_START; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, 2, ®16); + + aqc111_set_phy_speed(dev, aqc111_data->autoneg, + aqc111_data->advertised_speed); + + aqc111_read_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); + reg16 |= SFR_MEDIUM_RECEIVE_EN; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); + reg8 = SFR_RX_PATH_READY; + aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH, + 1, 1, ®8); + reg8 = 0x0; + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BMRX_DMA_CONTROL, 1, 1, ®8); + + return usbnet_resume(intf); +} + #define AQC111_USB_ETH_DEV(vid, pid, table) \ .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ USB_DEVICE_ID_MATCH_INT_CLASS, \ @@ -1371,6 +1572,8 @@ static struct usb_driver aq_driver = { .name = "aqc111", .id_table = products, .probe = usbnet_probe, + .suspend = aqc111_suspend, + .resume = aqc111_resume, .disconnect = usbnet_disconnect, }; diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index a7ccee225e93..9a900c325273 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -19,6 +19,7 @@ #define AQ_FLASH_PARAMETERS 0x20 #define AQ_PHY_POWER 0x31 #define AQ_PHY_CMD 0x32 +#define AQ_WOL_CFG 0x60 #define AQ_PHY_OPS 0x61 #define AQC111_PHY_ID 0x00 @@ -169,6 +170,7 @@ #define AQ_FW_VER_MINOR 0xDB #define AQ_FW_VER_REV 0xDC +#define AQ_WOL_FLAG_MP 0x2 /******************************************************************************/ struct aqc111_phy_options { @@ -214,6 +216,14 @@ struct aqc111_phy_options { }; }; +struct aqc111_wol_cfg { + u8 hw_addr[6]; + u8 flags; + u8 rsvd[283]; +}; + +#define WOL_CFG_SIZE sizeof(struct aqc111_wol_cfg) + struct aqc111_data { u16 rxctl; u8 rx_checksum; @@ -228,6 +238,7 @@ struct aqc111_data { } fw_ver; u8 dpa; /*direct PHY access*/ struct aqc111_phy_options phy_ops; + struct aqc111_wol_cfg wol_cfg; } __packed; struct aqc111_int_data {