Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5650921pxj; Wed, 23 Jun 2021 06:11:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4s7iY9s//c4r9YgGRyx2ME3GxmHwwTK2RymMwTEDwB5XtglImjHSlPKt+/+qQATjgrDaB X-Received: by 2002:a17:907:3f1d:: with SMTP id hq29mr9997550ejc.323.1624453903484; Wed, 23 Jun 2021 06:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624453903; cv=none; d=google.com; s=arc-20160816; b=yqHRWcghQI0gEz6KVR6wOo3psNB8ZiHWm0zsSupltXHEfafcPaWwzT6fv+Z6HO+I/9 EaKlUVnfuSdNXpg8SEtEHnAp6A4FoDwsTf8JazzI632dqrvx6K2d2TUEUmfrFUv+TtU9 M6ap72GsCRV0KRdR6eH/X4th4CfUdHGfH5JaO5c3VokHoo7dm2O2R923whnyiB0y8hlV Wh9KiRlFF63zqbZBHgN0te9rUF6b9F5hvD67Xq0JjsD0HdVqcy4dDetq0UpE+/XTwT7+ nukPr7J2FsVvMgpMDqd79eHgrCHEwLaghWkRbZY5IgQufMH8d0dC4f02mb4hCpDoHijS 3Bdw== 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:ironport-sdr:ironport-sdr; bh=AnQt4rgca8miZSNxmz5H8z1dCYgw07DxERgaZSF4GE4=; b=K4ex0oFLLjilX3AoyTgmv6ypp6arY83yUu4p8Z/muRI/ioLa8Jd4F9EE8Ggwj5gcpc XvtuJe5XQP6NqJrFgMsTyYQ1ZwJMUHNdLKAwAym3CqKzw5jcCISpHRsuM1wi5Uu3bWsr CKLe8QmHWZFK4kiWtrNsYh8RgR8hTQCswnWfWhkSta15Zt0pgmqOGWapaEjptm5tw3rC lpovGsHu6p/MJDW69mXiBoI2iS/5gIn0K3jjpKXm98ybaoVhUVmIc6sDKYNwQgzQQuRw 6MJTnW4kGiNT8PEH/Ucj3GBv/U5n9mw3vpNHlB6JLr2odgW6YIXBMJIvD5D5XGuA3I0C O+5A== 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 g17si19279039ejr.586.2021.06.23.06.11.19; Wed, 23 Jun 2021 06:11:43 -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 S230496AbhFWNMF (ORCPT + 99 others); Wed, 23 Jun 2021 09:12:05 -0400 Received: from mga03.intel.com ([134.134.136.65]:44388 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231126AbhFWNMD (ORCPT ); Wed, 23 Jun 2021 09:12:03 -0400 IronPort-SDR: K7DGkeF+0S3RHlDnQxQnJ8AThy31G7ZKdaGX4zPwj8bcrmDq4TaB0aJNI0Qi8a3HjHVhDwOptr Fq/V7t5BBQ1A== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="207298336" X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="207298336" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2021 06:09:43 -0700 IronPort-SDR: 2Ww2ltAuTia9bEXIEITK6bMG3yryraNj/ALZPhjl0EP0LIDbqlM4jW780cX+L5EK4KkwU16Bwb Ohu1C6R4Cejg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="641979134" Received: from peileeli.png.intel.com ([172.30.240.12]) by fmsmga005.fm.intel.com with ESMTP; 23 Jun 2021 06:09:39 -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: [PATCH net-next] net: phy: marvell10g: enable WoL for mv2110 Date: Wed, 23 Jun 2021 21:09:29 +0800 Message-Id: <20210623130929.805559-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 Basically it is just to enable to WoL interrupt and enable WoL detection. Then, configure the MAC address into address detection register. Signed-off-by: Voon Weifeng Signed-off-by: Ling PeiLee --- drivers/net/phy/marvell10g.c | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index bbbc6ac8fa82..93410ece83af 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) @@ -106,6 +107,17 @@ enum { MV_V2_TEMP_CTRL_DISABLE = 0xc000, MV_V2_TEMP = 0xf08c, MV_V2_TEMP_UNKNOWN = 0x9600, /* unknown function */ + 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_STS = 0xf06f, + MV_V2_WOL_CLEAR_STS = BIT(15), + MV_V2_WOL_MAGIC_PKT_EN = BIT(0), + MV_V2_PORT_INTR_STS = 0xf040, + MV_V2_PORT_INTR_MASK = 0xf043, + MV_V2_WOL_INTR_EN = BIT(8), }; struct mv3310_chip { @@ -991,6 +1003,94 @@ static int mv2111_match_phy_device(struct phy_device *phydev) return mv211x_match_phy_device(phydev, false); } +static void mv2110_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) +{ + int ret = 0; + + wol->supported = WAKE_MAGIC; + wol->wolopts = 0; + + ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_WOL_CTRL); + + if (ret & MV_V2_WOL_MAGIC_PKT_EN) + wol->wolopts |= WAKE_MAGIC; +} + +static int mv2110_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) +{ + int ret = 0; + + 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_WOL_INTR_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_MAGIC_PKT_EN | + MV_V2_WOL_CLEAR_STS); + + if (ret < 0) + return ret; + + /* Reset the clear WOL status bit as it does not self-clear */ + ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_WOL_CTRL, + MV_V2_WOL_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_MAGIC_PKT_EN, + MV_V2_WOL_CLEAR_STS); + + if (ret < 0) + return ret; + + ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, + MV_V2_WOL_CTRL, + MV_V2_WOL_CLEAR_STS); + + if (ret < 0) + return ret; + } + + return ret; +} + static struct phy_driver mv3310_drivers[] = { { .phy_id = MARVELL_PHY_ID_88X3310, @@ -1045,6 +1145,8 @@ static struct phy_driver mv3310_drivers[] = { .set_tunable = mv3310_set_tunable, .remove = mv3310_remove, .set_loopback = genphy_c45_loopback, + .get_wol = mv2110_get_wol, + .set_wol = mv2110_set_wol, }, { .phy_id = MARVELL_PHY_ID_88E2110, -- 2.25.1