Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1321807pxv; Fri, 16 Jul 2021 06:49:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGqU1UfOUtIrqkuUje6dVVsaQLiU3CUN7jo3yVQDZJFeauQ2S+Mxee5cA+/iJfd7ZzHO5f X-Received: by 2002:a05:6638:218:: with SMTP id e24mr9196641jaq.38.1626443382241; Fri, 16 Jul 2021 06:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626443382; cv=none; d=google.com; s=arc-20160816; b=R8uyGQs0WDWtxqCDgvQBZKN+5OhSS8jaTugZkZxsd9kCNUdDLa1WBBjnSZ+UkRrqIc XncB50A/wC4FyaFxh/NpuHLYDU6SlmrCkGO6rLkyQi8Vv7StaY0xhzYGaUCGNf26YEwa bQI06zqvy5dLaD7/1mJ4BVQUP+bDJdXxauU0vCkck3oRDJeu5ZamLSuvtSqT0NBzwgNH cMZSaL4F6CvLjM84W9ae0xOLOoI+fRG+TxMXoFyYCF9NJsEep+0qKR2YxhJzAss3lnOH rGsHoCRTLvaB4BHpmmHxv2We3Z8tUAExTQFPoERuQHu27D4NdS6V+UCHIRFLOnqvGTdL c+kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ooROA7gZPrHlOaDqlWs8RdS0FLgXxaQ7y+/qe5oC8c0=; b=MbO9Y+nWJRkh65xqlQRaTEnlQ1PsJdd1W8rKr9EbgQ4OBrFXjzD0ztBK/nAf7xBopm 1eUoJ4sTueXLK5AosMjsCjIXH7RC22UXbcALhiIe5rLNqosrKetHrDrjNABG7pzfIEaA 7ytllHZyF7HADRwLySTUASBIzExAJ0TXm6GR2p9LuDCNhtkUd2qpFJRzLKYQxwoexFLf x/imPWwDQDk2eZyhhsleFrY5mglodtJPWglEZRoasExnhcGufjHZpTS73xtLPyQFKqxt 3GvuUmqGeLlxp1cbK3TJPrjYU/YoPO0QNoJdvvYaHIrk/81fmsXwBd3xlUPx7u7jL1+0 30CQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q15si284529ile.132.2021.07.16.06.49.29; Fri, 16 Jul 2021 06:49:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240029AbhGPNuR (ORCPT + 99 others); Fri, 16 Jul 2021 09:50:17 -0400 Received: from mga05.intel.com ([192.55.52.43]:31574 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232808AbhGPNuO (ORCPT ); Fri, 16 Jul 2021 09:50:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10046"; a="296375333" X-IronPort-AV: E=Sophos;i="5.84,245,1620716400"; d="scan'208";a="296375333" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2021 06:47:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,245,1620716400"; d="scan'208";a="506899157" Received: from peileeli.png.intel.com ([172.30.240.12]) by fmsmga002.fm.intel.com with ESMTP; 16 Jul 2021 06:47:16 -0700 From: Ling Pei Lee To: Russell King , Andrew Lunn , Heiner Kallweit , davem@davemloft.net, Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Behun , weifeng.voon@intel.com, vee.khee.wong@linux.intel.com, vee.khee.wong@intel.com, pei.lee.ling@intel.com Subject: [net-next,resend,V3] net: phy: marvell10g: enable WoL for 88X3310 and 88E2110 Date: Fri, 16 Jul 2021 21:46:45 +0800 Message-Id: <20210716134645.2249943-1-pei.lee.ling@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Voon Weifeng Implement Wake-on-LAN feature for 88X3310 and 88E2110. This is done by enabling WoL interrupt and WoL detection and configuring MAC address into WoL magic packet registers Signed-off-by: Voon Weifeng Signed-off-by: Ling Pei Lee --- Change Log: V3: (1) Update the commit message which is suggested by Marek. (2) Change patch title. (3) Remove MV_V2_WOL_STS register definition where it is not used. (4) Rename MV_V2_WOL_INTR_EN, MV_V2_WOL_CLEAR_STS and MV_V2_WOL_MAGIC_PKT_EN. (5) Move change log to signedoff below. (6) Fix indention problem in code. (7) Reorganize newly added register definition in recommeded order. (8) Change function name from mv2110{get|set}_wol to mv3110{get|set}_wol. (9) Fix mv3110{get|set}_wol characters exceed 80. V2: (1) Reviewer Marek request to rorganize code to readable way. (2) Reviewer Rusell request to put phy_clear_bits_mmd() outside of if(){}else{} and modify return ret to return phy_clear_bits_mmd(). (3) Reviewer Rusell request to add return on phy_read_mmd() in set_wol(). (4) Reorganize register layout to be put before MV_V2_TEMP_CTRL. (5) Add the .{get|set}_wol for 88E3110 too as per feedback from Russell. drivers/net/phy/marvell10g.c | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 53a433442803..0b7cae118ad7 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -28,6 +28,7 @@ #include #include #include +#include #define MV_PHY_ALASKA_NBT_QUIRK_MASK 0xfffffffe #define MV_PHY_ALASKA_NBT_QUIRK_REV (MARVELL_PHY_ID_88X3310 | 0xa) @@ -104,6 +105,16 @@ enum { MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN = 0x5, MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6, MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII = 0x7, + MV_V2_PORT_INTR_STS = 0xf040, + MV_V2_PORT_INTR_MASK = 0xf043, + MV_V2_PORT_INTR_STS_WOL_EN = BIT(8), + MV_V2_MAGIC_PKT_WORD0 = 0xf06b, + MV_V2_MAGIC_PKT_WORD1 = 0xf06c, + MV_V2_MAGIC_PKT_WORD2 = 0xf06d, + /* Wake on LAN registers */ + MV_V2_WOL_CTRL = 0xf06e, + MV_V2_WOL_CTRL_CLEAR_STS = BIT(15), + MV_V2_WOL_CTRL_MAGIC_PKT_EN = BIT(0), /* Temperature control/read registers (88X3310 only) */ MV_V2_TEMP_CTRL = 0xf08a, MV_V2_TEMP_CTRL_MASK = 0xc000, @@ -1020,6 +1031,80 @@ static int mv2111_match_phy_device(struct phy_device *phydev) return mv211x_match_phy_device(phydev, false); } +static void mv3110_get_wol(struct phy_device *phydev, + struct ethtool_wolinfo *wol) +{ + int ret; + + wol->supported = WAKE_MAGIC; + wol->wolopts = 0; + + ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_WOL_CTRL); + if (ret < 0) + return; + + if (ret & MV_V2_WOL_CTRL_MAGIC_PKT_EN) + wol->wolopts |= WAKE_MAGIC; +} + +static int mv3110_set_wol(struct phy_device *phydev, + struct ethtool_wolinfo *wol) +{ + int ret; + + if (wol->wolopts & WAKE_MAGIC) { + /* Enable the WOL interrupt */ + ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_PORT_INTR_MASK, + MV_V2_PORT_INTR_STS_WOL_EN); + if (ret < 0) + return ret; + + /* Store the device address for the magic packet */ + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_MAGIC_PKT_WORD2, + ((phydev->attached_dev->dev_addr[5] << 8) | + phydev->attached_dev->dev_addr[4])); + if (ret < 0) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_MAGIC_PKT_WORD1, + ((phydev->attached_dev->dev_addr[3] << 8) | + phydev->attached_dev->dev_addr[2])); + if (ret < 0) + return ret; + + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_MAGIC_PKT_WORD0, + ((phydev->attached_dev->dev_addr[1] << 8) | + phydev->attached_dev->dev_addr[0])); + if (ret < 0) + return ret; + + /* Clear WOL status and enable magic packet matching */ + ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_WOL_CTRL, + MV_V2_WOL_CTRL_MAGIC_PKT_EN | + MV_V2_WOL_CTRL_CLEAR_STS); + if (ret < 0) + return ret; + } else { + /* Disable magic packet matching & reset WOL status bit */ + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_WOL_CTRL, + MV_V2_WOL_CTRL_MAGIC_PKT_EN, + MV_V2_WOL_CTRL_CLEAR_STS); + if (ret < 0) + return ret; + } + + /* Reset the clear WOL status bit as it does not self-clear */ + return phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_WOL_CTRL, + MV_V2_WOL_CTRL_CLEAR_STS); +} + static struct phy_driver mv3310_drivers[] = { { .phy_id = MARVELL_PHY_ID_88X3310, @@ -1039,6 +1124,8 @@ static struct phy_driver mv3310_drivers[] = { .set_tunable = mv3310_set_tunable, .remove = mv3310_remove, .set_loopback = genphy_c45_loopback, + .get_wol = mv3110_get_wol, + .set_wol = mv3110_set_wol, }, { .phy_id = MARVELL_PHY_ID_88X3310, @@ -1076,6 +1163,8 @@ static struct phy_driver mv3310_drivers[] = { .set_tunable = mv3310_set_tunable, .remove = mv3310_remove, .set_loopback = genphy_c45_loopback, + .get_wol = mv3110_get_wol, + .set_wol = mv3110_set_wol, }, { .phy_id = MARVELL_PHY_ID_88E2110, -- 2.25.1