From patchwork Tue Nov 13 14:45:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10680885 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 4E16414D6 for ; Tue, 13 Nov 2018 14:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BD041FF62 for ; Tue, 13 Nov 2018 14:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3001128E66; Tue, 13 Nov 2018 14:45:38 +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 71CDE1FF62 for ; Tue, 13 Nov 2018 14:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387976AbeKNAoD (ORCPT ); Tue, 13 Nov 2018 19:44:03 -0500 Received: from mail-eopbgr710051.outbound.protection.outlook.com ([40.107.71.51]:49377 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387876AbeKNAnu (ORCPT ); Tue, 13 Nov 2018 19:43:50 -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=+wknOsFpCavfYhbMN0bMYEZxV9cbD/FE4No4jJPpi0A=; b=d99vVY0LxmJBYMYs2JmbazqCTqhJ1tXY09S2NC+QmwbLYY5w7sKt6gPPGjBTtD/4ThRpEjlF0IhmA00lYCHUwHKZViauUnlUYo6f9bv6z1vxxQQBGqGXVdmMoxrvJZaCmBdv2a518KSH5XNwn8NjwEX15DKOdeqgJi6fnSTpDEg= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1349.namprd07.prod.outlook.com (10.160.109.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Tue, 13 Nov 2018 14:45:16 +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:45:16 +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 19/21] net: usb: aqc111: Add support for wake on LAN by MAGIC packet Thread-Topic: [PATCH v2 net-next 19/21] net: usb: aqc111: Add support for wake on LAN by MAGIC packet Thread-Index: AQHUe199R/dMCwkDk0+Dvnf1p3f65w== Date: Tue, 13 Nov 2018 14:45:16 +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;BY1PR0701MB1349;6:Ukai8akAvUlNLjBeI0q3m2Rj3Sb+41uivXepogAgPi6fe84mF9M92pLSl7LVYMMxxcPtkIF6JPdrFDGbub2CVDYfS8ytQbCLtfKdkVRO9XkgINDqi41AS+A5SAhdEud/pXZQrDJEfN2oxCq6CzxiF70fwaVYQ4QNSDWl9glXdtZjPDgOv7XShHVyUtywyHgBA3IKjhTY2u5wJf5sfb8XquRRpnrB1supi5eZ595cr+L1XLheMlLdOfa6SprTBLbIxejwM9LuQCMUbzsrJ8PKtjgv2cHjaS9l8tYdKhPhrWg38yfTo2cg9hpOSP/qza2P28NwovN9bqrFDzzocaUXJr/i2BaCMJDtTSPU0AvewXwm3xzRElnb1qt7+BuKc2BQ/sUM/OpoOtDkTeJ0X4oDUzZK6Ll292WNSntnQkPmbutEnlpz6NTlQtBzJ2ENCoIqsyMOdTbz7l4+06t9EMMz2A==;5:v9Fiu/ssmmUIdhs1GEgQGcytgEBThzxdXw6KxukawsoOEiUOGCaRY1zQ/34LJiZtxv0qlFnmiWOk1lxXymPkN2ERzwy+bUpRKLZFr17Fx3LdNcZOp9a6fgOK6AeuoRdKrQLpK1m7/4iQ+cyDtYFbV5ed6KpXlkiie5mBdmWU9N4=;7:nWFDbpgGwSD3UKceRVNKffofsCKmBKxSCBgiygvG2H7aFUxPUaU7h9kEuq3B+5QFIUFBrcRPmUVUZRMbLaEbDH/odSFIx5zGkgJUBroi+oR/VM39sMkxnPuSFZNy1/tVYSTomQoelc0TtUrBV0Dbmg== x-ms-office365-filtering-correlation-id: 7cadb3f5-7997-4f93-c53b-08d649769ff3 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390060)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1349; x-ms-traffictypediagnostic: BY1PR0701MB1349: 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)(10201501046)(3002001)(3231382)(944501410)(52105112)(93006095)(93001095)(148016)(149066)(150057)(6041310)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1349;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1349; x-forefront-prvs: 085551F5A8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39850400004)(376002)(346002)(396003)(366004)(136003)(199004)(189003)(5660300001)(478600001)(54906003)(71200400001)(14454004)(71190400001)(6436002)(105586002)(76176011)(52116002)(36756003)(4326008)(68736007)(99286004)(97736004)(81166006)(81156014)(8676002)(2906002)(86362001)(7736002)(316002)(575784001)(72206003)(305945005)(107886003)(2616005)(66066001)(6512007)(8936002)(2900100001)(256004)(25786009)(6916009)(14444005)(106356001)(11346002)(44832011)(3846002)(6116002)(6486002)(53936002)(486006)(186003)(118296001)(6506007)(386003)(446003)(476003)(102836004)(26005);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1349;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: 6Fiec0lGBdRnpCcO9MPlrwfDt8lbEpCu5t9Hd5Vpf3olQXY2ehGImD1pJYUCi/zzBmHqGLLxpiiX2a4Kojq1eL2Zxb8IJqQK6YzLRQHRDALnxdNl5P/pPyHJwABqS3hBN6eGcQZXySHnNXwlPw3sv3HNd/HKLcbgYKGr8y4SnYqmzfOdnt9x02N0QgGBS4OsWZEqoa547jTkruT7B9AsdWTc+l33/mYcIIQ9MSCBThZ+Yqo/Rf1Xu6b5Tp0sMweBQlryiVfnCACjzwVY35hMcAM7lqxWhJOcmtdk2eQBKTcgzL5EFnjnXxPhQI7/q3r2YPLRRs4rD8kdUh1ZWuSZJe93995W26o2EEoSjmtTWUg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7cadb3f5-7997-4f93-c53b-08d649769ff3 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2018 14:45:16.5421 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1349 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 | 215 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 12 +++ 2 files changed, 227 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 80fedf2ab2dd..16d1934cc815 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -53,6 +53,17 @@ static int aqc111_read_cmd(struct usbnet *dev, u8 cmd, u16 value, return ret; } +static int aqc111_read16_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, + u16 index, u16 *data) +{ + int ret = 0; + + ret = aqc111_read_cmd_nopm(dev, cmd, value, index, sizeof(*data), data); + le16_to_cpus(data); + + return ret; +} + static int aqc111_read16_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 *data) { @@ -209,6 +220,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 = dev->driver_priv; + + wolinfo->supported = WAKE_MAGIC; + wolinfo->wolopts = 0; + + if (aqc111_data->wol_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 = dev->driver_priv; + + if (wolinfo->wolopts & ~WAKE_MAGIC) + return -EINVAL; + + aqc111_data->wol_flags = 0; + if (wolinfo->wolopts & WAKE_MAGIC) + aqc111_data->wol_flags |= AQ_WOL_FLAG_MP; + + return 0; +} + static void aqc111_speed_to_link_mode(u32 speed, struct ethtool_link_ksettings *elk) { @@ -449,6 +489,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, @@ -1327,6 +1369,177 @@ 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 = dev->driver_priv; + u16 temp_rx_ctrl = 0x00; + u16 reg16; + u8 reg8; + + usbnet_suspend(intf, message); + + aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16); + temp_rx_ctrl = reg16; + /* Stop RX operations*/ + reg16 &= ~SFR_RX_CTL_START; + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16); + /* Force bz */ + aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL, + 2, ®16); + reg16 |= SFR_PHYPWR_RSTCTL_BZ; + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL, + 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_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, + 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_flags) { + struct aqc111_wol_cfg wol_cfg = { 0 }; + + aqc111_data->phy_cfg |= AQ_WOL; + if (aqc111_data->dpa) { + reg8 = 0; + if (aqc111_data->wol_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 { + ether_addr_copy(wol_cfg.hw_addr, dev->net->dev_addr); + wol_cfg.flags = aqc111_data->wol_flags; + } + + temp_rx_ctrl |= (SFR_RX_CTL_AB | SFR_RX_CTL_START); + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, + 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_read16_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, ®16); + reg16 |= SFR_MEDIUM_RECEIVE_EN; + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, ®16); + + if (aqc111_data->dpa) { + aqc111_set_phy_speed(dev, AUTONEG_ENABLE, SPEED_100); + } else { + aqc111_write_cmd(dev, AQ_WOL_CFG, 0, 0, + WOL_CFG_SIZE, &wol_cfg); + aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, + &aqc111_data->phy_cfg); + } + } else { + aqc111_data->phy_cfg |= AQ_LOW_POWER; + if (!aqc111_data->dpa) { + aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, + &aqc111_data->phy_cfg); + } else { + reg16 = AQ_PHY_LOW_POWER_MODE; + aqc111_mdio_write(dev, AQ_GLB_STD_CTRL_REG, + AQ_PHY_GLOBAL_ADDR, ®16); + } + + /* Disable RX path */ + aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, ®16); + reg16 &= ~SFR_MEDIUM_RECEIVE_EN; + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, + SFR_MEDIUM_STATUS_MODE, 2, ®16); + } + + return 0; +} + +static int aqc111_resume(struct usb_interface *intf) +{ + struct usbnet *dev = usb_get_intfdata(intf); + struct aqc111_data *aqc111_data = dev->driver_priv; + u16 reg16; + u8 reg8; + + netif_carrier_off(dev->net); + + /* Power up ethernet PHY */ + aqc111_data->phy_cfg |= AQ_PHY_POWER_EN; + aqc111_data->phy_cfg &= ~AQ_LOW_POWER; + aqc111_data->phy_cfg &= ~AQ_WOL; + 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); + } + + aqc111_mdio_read(dev, AQ_GLB_STD_CTRL_REG, AQ_PHY_GLOBAL_ADDR, + ®16); + if (reg16 & AQ_PHY_LOW_POWER_MODE) { + reg16 &= ~AQ_PHY_LOW_POWER_MODE; + aqc111_mdio_write(dev, AQ_GLB_STD_CTRL_REG, + AQ_PHY_GLOBAL_ADDR, ®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_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16); + + reg16 |= SFR_RX_CTL_START; + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16); + + aqc111_set_phy_speed(dev, aqc111_data->autoneg, + aqc111_data->advertised_speed); + + aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, + 2, ®16); + reg16 |= SFR_MEDIUM_RECEIVE_EN; + aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, + 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) \ USB_DEVICE_INTERFACE_CLASS((vid), (pid), USB_CLASS_VENDOR_SPEC), \ .driver_info = (unsigned long)&(table) @@ -1341,6 +1554,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 6c951ca5d261..b62ef420bb68 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 @@ -187,8 +188,18 @@ #define AQ_DSH_RETRIES_SHIFT 0x18 #define AQ_DSH_RETRIES_MASK 0xF000000 +#define AQ_WOL_FLAG_MP 0x2 + /******************************************************************************/ +struct aqc111_wol_cfg { + u8 hw_addr[6]; + u8 flags; + u8 rsvd[283]; +} __packed; + +#define WOL_CFG_SIZE sizeof(struct aqc111_wol_cfg) + struct aqc111_data { u16 rxctl; u8 rx_checksum; @@ -203,6 +214,7 @@ struct aqc111_data { } fw_ver; u8 dpa; /*direct PHY access*/ u32 phy_cfg; + u8 wol_flags; }; #define AQ_LS_MASK 0x8000