From patchwork Wed Oct 25 17:32:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436492 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEAD01C683 for ; Wed, 25 Oct 2023 17:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="NGV53MPA" Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A353B138 for ; Wed, 25 Oct 2023 10:34:37 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7781b176131so2620485a.1 for ; Wed, 25 Oct 2023 10:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255276; x=1698860076; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=RyE3i5t9k7g5+3Y7P+D0v4H0c3MYDysKEdDAXf+58QE=; b=NGV53MPAEnGNp5d4Agl4zWVwTe1ZNPxkIG5wXIkegTzDwRKibSmCA2S3mjG2JD910f DKd7cMvBRR1p6IV81BNkYf+DZQdKee60+vTZBZ+Lnp+Vq8N2GdGHgioRj1D3vFN+w6yR uZzPnl/+X1bgZQHzYnMEC79W+eepvwMZGXmbM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255276; x=1698860076; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RyE3i5t9k7g5+3Y7P+D0v4H0c3MYDysKEdDAXf+58QE=; b=HuDRf/KgTHQCJ1OxB9FvfLu8YRBqyYGbDfLrLr8YudkZ/CkNv/3gdDczmEXopyCDW8 fW2mRRKXh2Uc608gXGkSh47X5N0rjsadAGMytuVM9riGJXNeBSBMzrC4wdT2P5RrmS4D 1lI+o8EaDUUj+97kfoEvo83mmuhmOQxKlJaYTHLJBAoa3gf4cmnfwk3w/oG9+zHzlhWq cwR/7BsAwuPbXXPurYbDihwmxQijgvzgoYPrLjRzrcYnYl51H3JjjMkwnew5XhqjAUd3 M7EjD8HlQ6hl4C538EmqJ2W9CwCwpRbMaFslhA64gMsIel10mMAhpEl15S6R5fMIto+p N63A== X-Gm-Message-State: AOJu0YyxH3VNVflYT5NaAt3AGEUn3f2VrTo3ajS7GKoCiSaCNs3+Bxxo JJc45I3bfITTW6nVo5SwiD2/7vGgwlzwLcEGgPE6IZ4A+vwcA0Vxjen5mxETNLAu50ASMdspdwh HXWCgSs2uabAC+4c5nbiYWQnxPdR6rKpFaL56pysY3UQvR4j3cmXgX/zTGIm8L/H0rBqRWwrVs7 A95DzlFgl5nXRg X-Google-Smtp-Source: AGHT+IGPGGduNorc5Zru7sVUkApuBtefzcmppO5LF+rUA+P2lmGkGG/tn6kg3TC9a+SlMaFkuAF7hg== X-Received: by 2002:a05:620a:2947:b0:76f:1318:d7d1 with SMTP id n7-20020a05620a294700b0076f1318d7d1mr17479300qkp.75.1698255275882; Wed, 25 Oct 2023 10:34:35 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:35 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 1/5] net: ethtool: Make RXNFC walking code accept a callback Date: Wed, 25 Oct 2023 10:32:56 -0700 Message-Id: <20231025173300.1776832-2-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org In preparation for iterating over RXNFC rules for a different purpose, factor the generic code that already does that by allowing a callback to be specified. The body of ethtool_get_max_rxnfc_channel() now accepts a callback as an argument and is renamed to __ethtool_for_each_rxnfc(). Signed-off-by: Florian Fainelli --- net/ethtool/common.c | 54 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index b4419fb6df6a..143dae872fb2 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -536,12 +536,24 @@ static int ethtool_get_rxnfc_rule_count(struct net_device *dev) return info.rule_cnt; } -int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) +/** + * __ethtool_for_each_rxnfc: Iterate over each RXNFC rule installed + * @dev: network device + * @cb: callback to analyze an %ethtool_rxnfc rule + * @priv: private pointer passed to the callback + * + * @cb is supposed to return the following: + * < 0 on error + * == 0 to continue + * > 0 to stop iterating + */ +static int __ethtool_for_each_rxnfc(struct net_device *dev, + int (*cb)(struct ethtool_rxnfc *info, + void *priv), void *priv) { const struct ethtool_ops *ops = dev->ethtool_ops; struct ethtool_rxnfc *info; int err, i, rule_cnt; - u64 max_ring = 0; if (!ops->get_rxnfc) return -EOPNOTSUPP; @@ -570,16 +582,14 @@ int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) if (err) goto err_free_info; - if (rule_info.fs.ring_cookie != RX_CLS_FLOW_DISC && - rule_info.fs.ring_cookie != RX_CLS_FLOW_WAKE && - !(rule_info.flow_type & FLOW_RSS) && - !ethtool_get_flow_spec_ring_vf(rule_info.fs.ring_cookie)) - max_ring = - max_t(u64, max_ring, rule_info.fs.ring_cookie); + err = cb(&rule_info, priv); + if (err < 0) + goto err_free_info; + if (err > 0) + break; } kvfree(info); - *max = max_ring; return 0; err_free_info: @@ -587,6 +597,32 @@ int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) return err; } +static int __ethtool_get_max_rxnfc_channel(struct ethtool_rxnfc *rule_info, + void *priv) +{ + u64 *max_ring = priv; + + if (rule_info->fs.ring_cookie != RX_CLS_FLOW_DISC && + rule_info->fs.ring_cookie != RX_CLS_FLOW_WAKE && + !(rule_info->flow_type & FLOW_RSS) && + !ethtool_get_flow_spec_ring_vf(rule_info->fs.ring_cookie)) + *max_ring = + max_t(u64, *max_ring, rule_info->fs.ring_cookie); + + return 0; +} + +int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max) +{ + u64 max_ring = 0; + int ret; + + ret = __ethtool_for_each_rxnfc(dev, __ethtool_get_max_rxnfc_channel, + &max_ring); + *max = max_ring; + return ret; +} + int ethtool_get_max_rxfh_channel(struct net_device *dev, u32 *max) { u32 dev_size, current_max = 0; From patchwork Wed Oct 25 17:32:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436493 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 628DE30F97 for ; Wed, 25 Oct 2023 17:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="hVLljGW+" Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFFC182 for ; Wed, 25 Oct 2023 10:34:40 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7789577b53fso1759585a.3 for ; Wed, 25 Oct 2023 10:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255279; x=1698860079; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=qX3EL2q6pN74SwRInbjnbLAH7jYoC+JLJCmE0WvVx0s=; b=hVLljGW++ht2jJMtN9VLgaFHB5jWbwRh6KqmaC9a42XlrSj0h/s37a3XBDBqNn+Dvc 6H7gpO5txgBvFE7mXpknX4PUotT7IbZ43+uSywmDFdG1zSqArxOgI6FM8gVNsLIfZyWQ FozqJ0O20O17/kWzrrJ3Gtp3eu44XSaFFwzik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255279; x=1698860079; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qX3EL2q6pN74SwRInbjnbLAH7jYoC+JLJCmE0WvVx0s=; b=Hgshg7x41DMNXlR74Q+SjoG+W4M8zWmVP9xPkReMsqE1nqfuLu/31ju6QTS8HEoPJ/ lqnFTLWA4p+UThGCsRdXdtnNND0yLegjXMcBo0tD/xelav/3zFqCCc9jGSCfSr67yHJe aSq+YIEyYfyrh7PBUfZBty7CPts8BvkhwFw1XATNx9p5Fys0HAbJaZiioY7Pud5oaEiS zVswqZj3ikqzQAblntFC8I8vHZWG7kK7UuGrJ4dXY+ns7PJAIdAW30jj5pS0mpUfwmqW D1EEGmR3aDKGeHaTnqkZhgjlMzrlH6l04RlMhRHqwqU1DshNaxRfg/2T/iBGzNWlzVWz 3OUg== X-Gm-Message-State: AOJu0YweSoh9bPO59/pxeCKCVHv8koigYjXbLoqX0WibYuDE0XR3t3/B irrSbv6eC1itKnR19vODc4DxSummdMqxU8jSi3mv+nqMEz3f+4dveX+tEEN0r6vb/xHwoCLFzEu KCnxh5rIg8PF1QP2o5uFeI/niV/R0fwVhS0TUD2NQRVo4AtATHSAXKBSZypIIBPjyH8xNasQRbS D8VJ+vfgDLJke5 X-Google-Smtp-Source: AGHT+IFp9bGKQ4w8/MwEaeQRNWEE1mGnGVHX8bh4pF339G1+0DlNED741jUjMoH59k57ABJUCkqgkA== X-Received: by 2002:a05:620a:4609:b0:779:de52:8743 with SMTP id br9-20020a05620a460900b00779de528743mr10541880qkb.27.1698255278944; Wed, 25 Oct 2023 10:34:38 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:38 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 2/5] net: ethtool: Add validation for WAKE_FILTER Date: Wed, 25 Oct 2023 10:32:57 -0700 Message-Id: <20231025173300.1776832-3-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org A driver implementing WAKE_FILTER must first install at least one rule with RX_CLS_FLOW_WAKE for WAKE_FILTER to be effective. Iterate over RXNFC rules to validate that condition while trying to enable WAKE_FILTER. Signed-off-by: Florian Fainelli --- net/ethtool/common.c | 42 ++++++++++++++++++++++++++++++++++++++++++ net/ethtool/common.h | 3 +++ net/ethtool/ioctl.c | 3 +++ net/ethtool/wol.c | 3 +++ 4 files changed, 51 insertions(+) diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 143dae872fb2..bab901b35731 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -742,3 +742,45 @@ ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size) } } EXPORT_SYMBOL_GPL(ethtool_forced_speed_maps_init); + +static int __ethtool_check_rxnfc_wake_filter(struct ethtool_rxnfc *rule_info, + void *priv) +{ + bool *verdict = priv; + + if (rule_info->fs.ring_cookie == RX_CLS_FLOW_WAKE) { + *verdict = true; + return 1; + } + + return 0; +} + +/** + * ethtool_dev_check_wake_filter: Tests if a network device can use the + * WAKE_FILTER Wake-on-LAN option. + * @dev: network device to test + * @wol: %ethtool_wolinfo structure with Wake-on-LAN configuration + * + * Returns true if there is no support for %WAKE_FILTER, no support + * for RXNFC ethtool operations, or if there is at least one WAKE_FILTER + * installed. + */ +bool ethtool_dev_check_wake_filter(struct net_device *dev, + const struct ethtool_wolinfo *wol) +{ + bool verdict = false; + int ret; + + if (!(wol->wolopts & WAKE_FILTER)) + return true; + + if (!dev->ethtool_ops->get_rxnfc || + !dev->ethtool_ops->set_rxnfc) + return true; + + ret = __ethtool_for_each_rxnfc(dev, __ethtool_check_rxnfc_wake_filter, + &verdict); + + return ret < 0 ? false : verdict; +} diff --git a/net/ethtool/common.h b/net/ethtool/common.h index 28b8aaaf9bcb..6cd3286d5038 100644 --- a/net/ethtool/common.h +++ b/net/ethtool/common.h @@ -56,4 +56,7 @@ int ethtool_get_module_eeprom_call(struct net_device *dev, bool __ethtool_dev_mm_supported(struct net_device *dev); +bool ethtool_dev_check_wake_filter(struct net_device *dev, + const struct ethtool_wolinfo *wol); + #endif /* _ETHTOOL_COMMON_H */ diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 0b0ce4f81c01..954446185158 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1457,6 +1457,9 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) !memcmp(wol.sopass, cur_wol.sopass, sizeof(wol.sopass))) return 0; + if (!ethtool_dev_check_wake_filter(dev, &wol)) + return -EOPNOTSUPP; + ret = dev->ethtool_ops->set_wol(dev, &wol); if (ret) return ret; diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index 0ed56c9ac1bc..65fbe743a070 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -132,6 +132,9 @@ ethnl_set_wol(struct ethnl_req_info *req_info, struct genl_info *info) tb[ETHTOOL_A_WOL_SOPASS], &mod); } + if (!ethtool_dev_check_wake_filter(dev, &wol)) + return -EOPNOTSUPP; + if (!mod) return 0; ret = dev->ethtool_ops->set_wol(dev, &wol); From patchwork Wed Oct 25 17:32:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436494 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1367330F97 for ; Wed, 25 Oct 2023 17:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="UqrUW0n4" Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84A2F18C for ; Wed, 25 Oct 2023 10:34:43 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7788f513872so2772785a.1 for ; Wed, 25 Oct 2023 10:34:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255282; x=1698860082; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=7lLc74iucfkSagTngo0w/CgNB4zg7uJtat26T1MBATc=; b=UqrUW0n4XTBWq5Yx5prN9SD8Z10GTN5s1rdSyZcwxQPV416fFxhoWpC/wxyaY015QK /78Up3W05yYeL09XtUw/Dpkm+yUiQRhmsn2rIz15jC4VDP2e11KBIsfOWNBxcz2c485K D85iWDfeUe4Zxi5UpSP+PgTj9zvnVgdIRQH9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255282; x=1698860082; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7lLc74iucfkSagTngo0w/CgNB4zg7uJtat26T1MBATc=; b=Ok+g355L0FzAbDOeBc2tovF4Mu0b2ML/oMiXW26US7PsJXv+N9C85zagTSa7eOSF72 M7grEAdB55gI55Lm2YiChkna3BqFHD5Yo1lNwMsGHHv69V0SC5FifAh8KrGJzkAk3Yag S9SLj8LR3eaYM64vywVQAn26mM9alJAcek6jqkA9l7i0UEomDKyaBHDhkJTXncyvBLR1 BFiOjPU7gfS1aTSyLjqLM7+GpHmUQyjFq6i+o+VQu6VXoC3EGQdP6rZl8uMGxnERPzer aEMMneWQYgbahlRQBsNSI/54YxBgFaHWhOWecfVzWqJelDg1zHv8gCFyww+fRPCV9a3w OssQ== X-Gm-Message-State: AOJu0Yxc0V6+CLkvjFL0lOrKYXJGpd52sk70meuEC1F6agl4s35rydFf pRlFgTMB2YxjAyb1RIaeOEHTeaUh3RuSPfoXreMEMXg5KLxP0XwCyWQC6R3vefmA+6rmU4HXmrd v/IokuIwRcx5GcMp/a5KbCf18lXwu8STTGWnwPzCqUG4ph6QJPhlr15KZYHvrQ9t2qtjpFabvEq 2fs8AmGcYWW1H1 X-Google-Smtp-Source: AGHT+IER/THKzyidQcAgA/umHbCwsV/um2ZoKrQMP+KKtFbJj+HpP1SXBEAn7Gsby6nW7J7QiBr+/A== X-Received: by 2002:a05:620a:410c:b0:767:f1de:293c with SMTP id j12-20020a05620a410c00b00767f1de293cmr16749409qko.59.1698255282064; Wed, 25 Oct 2023 10:34:42 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:41 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 3/5] net: phy: Add pluming for ethtool_{get,set}_rxnfc Date: Wed, 25 Oct 2023 10:32:58 -0700 Message-Id: <20231025173300.1776832-4-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Ethernet MAC drivers supporting Wake-on-LAN using programmable filters (WAKE_FILTER) typically configure such programmable filters using the ethtool::set_rxnfc API and with a sepcial RX_CLS_FLOW_WAKE to indicate the filter is also wake-up capable. In order to offer the same functionality for capable Ethernet PHY drivers, wire-up the ethtool::{get,set}_rxnfc APIs within the PHY library. Signed-off-by: Florian Fainelli --- drivers/net/phy/phy.c | 19 +++++++++++++++++++ include/linux/phy.h | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index a5fa077650e8..e2f2cc38ff31 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1740,3 +1740,22 @@ int phy_ethtool_nway_reset(struct net_device *ndev) return ret; } EXPORT_SYMBOL(phy_ethtool_nway_reset); + +int phy_ethtool_get_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *nfc, u32 *rule_locs) +{ + if (phydev->drv && phydev->drv->get_rxnfc) + return phydev->drv->get_rxnfc(phydev, nfc, rule_locs); + + return -EOPNOTSUPP; +} +EXPORT_SYMBOL(phy_ethtool_get_rxnfc); + +int phy_ethtool_set_rxnfc(struct phy_device *phydev, struct ethtool_rxnfc *nfc) +{ + if (phydev->drv && phydev->drv->set_rxnfc) + return phydev->drv->set_rxnfc(phydev, nfc); + + return -EOPNOTSUPP; +} +EXPORT_SYMBOL(phy_ethtool_set_rxnfc); diff --git a/include/linux/phy.h b/include/linux/phy.h index 3cc52826f18e..03e7c6352aef 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1077,6 +1077,10 @@ struct phy_driver { int (*get_sqi)(struct phy_device *dev); /** @get_sqi_max: Get the maximum signal quality indication */ int (*get_sqi_max)(struct phy_device *dev); + /* Used for WAKE_FILTER programming only */ + int (*get_rxnfc)(struct phy_device *dev, + struct ethtool_rxnfc *nfc, u32 *rule_locs); + int (*set_rxnfc)(struct phy_device *dev, struct ethtool_rxnfc *nfc); /* PLCA RS interface */ /** @get_plca_cfg: Return the current PLCA configuration */ @@ -1989,6 +1993,10 @@ int phy_ethtool_set_plca_cfg(struct phy_device *phydev, struct netlink_ext_ack *extack); int phy_ethtool_get_plca_status(struct phy_device *phydev, struct phy_plca_status *plca_st); +int phy_ethtool_get_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *nfc, u32 *rule_locs); +int phy_ethtool_set_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *nfc); int __phy_hwtstamp_get(struct phy_device *phydev, struct kernel_hwtstamp_config *config); From patchwork Wed Oct 25 17:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436495 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02EBE30FAA for ; Wed, 25 Oct 2023 17:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="HpuAFmgj" Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADD22191 for ; Wed, 25 Oct 2023 10:34:46 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-77063481352so91182185a.1 for ; Wed, 25 Oct 2023 10:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255285; x=1698860085; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=c8+5YRU5In394lzK1h64/+1G0a5at+miMyMaqUxh4ZI=; b=HpuAFmgjmc78kI3f/ZUnB+gieniet3zXC8ZeY0wk1taGkHWCF5j5DgF9mc2hsN2ZFp bC43uwTzZaIAZSgfy3zjFpWvjaRb2T7/FtHoMd6dpVe9+gKZnBifH7+MwihybJK9Hu+a JD5UOxHLvnQpvCVbqk+reG1+5tWyAnyd175+4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255285; x=1698860085; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c8+5YRU5In394lzK1h64/+1G0a5at+miMyMaqUxh4ZI=; b=BalCePVqxOmwJobalyvIJsZZTCIGTT+sxHURQrmTP9geIoZxwBsaHEkclZm776Oxa2 GO1rj5KEp8QUP707ckSNpkUNMI1Zur1cr4yybX3tYW7wcqMB33B/MzaWWIgehnP1vbyR LcbsNDHFecNjmAOLAYf/mWbp21A8VBZCn/eFyII1YV4tBAaOIj4bc2xRwG/lMywa2Ros GQ8qYqukOdKV/ohbIv2Hjbx200x/jfE4b17JbpNdFw60yRzmmhKskDlQsVk2i08gxfXL eruDO0f48WM9ikH+scQwY9u6a1MDAs7QTuTWv3z9kO4L+Hr0ulEyDQm4z2a7jshJFzCp M8lw== X-Gm-Message-State: AOJu0Yxj9tK6+j4lvgOm2ZOumUc4CH+oteIhQXv8pLEwdmjYuRpVK+IJ McAOc3Bk1MJOqzc+vpDX1AxRjNSWADs+ggJXeEmS5aUpimYfr/xdBsVjBH3TEPuhDRYfinBs0mF U4UbnTtQkPH0I5Mwz11x8gT2h58MKmI/O7T/o0FaOtAx4xAnFf8IttO47d3vDCPwMparGJAC5y2 ZwJ3e//hHU6Dxh X-Google-Smtp-Source: AGHT+IFZ3v7uyHLlZyF+4u7hT906f65PCbZ4ddr1Z+093ZEiOkO0ZgKBiYz7kELbXCJvuF59/SDvmA== X-Received: by 2002:a05:620a:394c:b0:777:5d4:bb4 with SMTP id qs12-20020a05620a394c00b0077705d40bb4mr435302qkn.3.1698255285167; Wed, 25 Oct 2023 10:34:45 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:44 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 4/5] net: phy: broadcom: Add support for WAKE_FILTER Date: Wed, 25 Oct 2023 10:32:59 -0700 Message-Id: <20231025173300.1776832-5-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Since the PHY is capable of matching any arbitrary Ethernet MAC destination as a programmable wake-up pattern, add support for doing that using the WAKE_FILTER and ethtool::rxnfc API. For instance, in order to wake-up from the Ethernet MAC address corresponding to the IPv4 multicast IP address of 224.0.0.251 (e.g.: multicast DNS), one could do: ethtool -N eth0 flow-type ether dst 01:00:5e:00:00:fb loc 0 action -2 ethtool -n eth0 Total 1 rules Filter: 0 Flow Type: Raw Ethernet Src MAC addr: 00:00:00:00:00:00 mask: FF:FF:FF:FF:FF:FF Dest MAC addr: 01:00:5E:00:00:FB mask: 00:00:00:00:00:00 Ethertype: 0x0 mask: 0xFFFF Action: Wake-on-LAN ethtool -s eth0 wol f Signed-off-by: Florian Fainelli --- drivers/net/phy/bcm-phy-lib.c | 195 +++++++++++++++++++++++++++++++++- drivers/net/phy/bcm-phy-lib.h | 5 + drivers/net/phy/broadcom.c | 2 + 3 files changed, 201 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c index 876f28fd8256..cfbeedc5ee81 100644 --- a/drivers/net/phy/bcm-phy-lib.c +++ b/drivers/net/phy/bcm-phy-lib.c @@ -827,7 +827,8 @@ EXPORT_SYMBOL_GPL(bcm_phy_cable_test_get_status_rdb); WAKE_MCAST | \ WAKE_BCAST | \ WAKE_MAGIC | \ - WAKE_MAGICSECURE) + WAKE_MAGICSECURE | \ + WAKE_FILTER) int bcm_phy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) { @@ -881,6 +882,12 @@ int bcm_phy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) ctl &= ~BCM54XX_WOL_DIR_PKT_EN; ctl &= ~(BCM54XX_WOL_SECKEY_OPT_MASK << BCM54XX_WOL_SECKEY_OPT_SHIFT); + /* For WAKE_FILTER, we have already programmed the desired MAC DA + * and associated mask by the time we get there. + */ + if (wol->wolopts & WAKE_FILTER) + goto program_ctl; + /* When using WAKE_MAGIC, we program the magic pattern filter to match * the device's MAC address and we accept any MAC DA in the Ethernet * frame. @@ -935,6 +942,7 @@ int bcm_phy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) return ret; } +program_ctl: if (wol->wolopts & WAKE_MAGICSECURE) { ctl |= BCM54XX_WOL_SECKEY_OPT_6B << BCM54XX_WOL_SECKEY_OPT_SHIFT; @@ -999,6 +1007,16 @@ void bcm_phy_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) if (!(ctl & BCM54XX_WOL_EN)) return; + ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_SEC_KEY_8B); + if (ret < 0) + return; + + /* Mutualy exclusive with other modes */ + if (ret) { + wol->wolopts |= WAKE_FILTER; + return; + } + for (i = 0; i < sizeof(da) / 2; i++) { ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_MPD_DATA2(2 - i)); @@ -1066,6 +1084,181 @@ int bcm_phy_led_brightness_set(struct phy_device *phydev, } EXPORT_SYMBOL_GPL(bcm_phy_led_brightness_set); +static int bcm_phy_get_rule(struct phy_device *phydev, + struct ethtool_rxnfc *nfc, + int loc) +{ + u8 da[ETH_ALEN]; + unsigned int i; + int ret; + + if (loc != 0) + return -EINVAL; + + memset(nfc, 0, sizeof(*nfc)); + nfc->flow_type = ETHER_FLOW; + nfc->fs.flow_type = ETHER_FLOW; + + for (i = 0; i < sizeof(da) / 2; i++) { + ret = bcm_phy_read_exp(phydev, + BCM54XX_WOL_MPD_DATA2(2 - i)); + if (ret < 0) + return ret; + + da[i * 2] = ret >> 8; + da[i * 2 + 1] = ret & 0xff; + } + ether_addr_copy(nfc->fs.h_u.ether_spec.h_dest, da); + + for (i = 0; i < sizeof(da) / 2; i++) { + ret = bcm_phy_read_exp(phydev, + BCM54XX_WOL_MASK(2 - i)); + if (ret < 0) + return ret; + + da[i * 2] = ~(ret >> 8); + da[i * 2 + 1] = ~(ret & 0xff); + } + ether_addr_copy(nfc->fs.m_u.ether_spec.h_dest, da); + + ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_INNER_PROTO); + if (ret < 0) + return ret; + + nfc->fs.h_u.ether_spec.h_proto = be16_to_cpu(ret); + + nfc->fs.ring_cookie = RX_CLS_FLOW_WAKE; + nfc->fs.location = 0; + + return 0; +} + +static int bcm_phy_set_rule(struct phy_device *phydev, + struct ethtool_rxnfc *nfc) +{ + int ret = -EOPNOTSUPP; + unsigned int i; + __be16 h_proto; + const u8 *da; + + /* We support only matching on the MAC DA with a custom mask and + * optionally with a specific Ethernet type, reject anything else. + */ + if (nfc->fs.ring_cookie != RX_CLS_FLOW_WAKE || + (nfc->fs.location != 0 && + nfc->fs.location != RX_CLS_LOC_ANY && + nfc->fs.location != RX_CLS_LOC_FIRST) || + nfc->fs.flow_type != ETHER_FLOW || + !is_zero_ether_addr(nfc->fs.h_u.ether_spec.h_source) || + !is_zero_ether_addr(nfc->fs.m_u.ether_spec.h_source)) + return ret; + + ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_SEC_KEY_8B); + if (ret < 0) + return ret; + + if (ret) + return -EBUSY; + + if (nfc->fs.location == RX_CLS_LOC_ANY || + nfc->fs.location == RX_CLS_LOC_FIRST) + nfc->fs.location = 0; + + da = nfc->fs.h_u.ether_spec.h_dest; + for (i = 0; i < ETH_ALEN / 2; i++) { + ret = bcm_phy_write_exp(phydev, + BCM54XX_WOL_MPD_DATA2(2 - i), + da[i * 2] << 8 | da[i * 2 + 1]); + if (ret < 0) + return ret; + } + + da = nfc->fs.m_u.ether_spec.h_dest; + for (i = 0; i < ETH_ALEN / 2; i++) { + ret = bcm_phy_write_exp(phydev, + BCM54XX_WOL_MASK(2 - i), + da[i * 2] << 8 | da[i * 2 + 1]); + if (ret < 0) + return ret; + } + + /* Restore default inner protocol field unless overridden by the flow + * specification. + */ + h_proto = be16_to_cpu(nfc->fs.h_u.ether_spec.h_proto); + if (!h_proto) + h_proto = ETH_P_8021Q; + + ret = bcm_phy_write_exp(phydev, BCM54XX_WOL_INNER_PROTO, + h_proto); + if (ret) + return ret; + + /* Use BCM54XX_WOL_SEC_KEY_8B as a scratch register to record + * that we installed a filter rule. + */ + return bcm_phy_write_exp(phydev, BCM54XX_WOL_SEC_KEY_8B, 1); +} + +int bcm_phy_get_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *cmd, u32 *rule_locs) +{ + int err = 0, rule_cnt = 0; + + err = bcm_phy_read_exp(phydev, BCM54XX_WOL_SEC_KEY_8B); + if (err < 0) + return err; + + rule_cnt = err; + err = 0; + + switch (cmd->cmd) { + case ETHTOOL_GRXCLSRLCNT: + cmd->rule_cnt = rule_cnt; + cmd->data = 1 | RX_CLS_LOC_SPECIAL; + break; + case ETHTOOL_GRXCLSRULE: + err = bcm_phy_get_rule(phydev, cmd, cmd->fs.location); + break; + case ETHTOOL_GRXCLSRLALL: + if (rule_cnt) + rule_locs[0] = 0; + cmd->rule_cnt = rule_cnt; + cmd->data = 1; + break; + default: + err = -EOPNOTSUPP; + break; + } + + return err; +} +EXPORT_SYMBOL_GPL(bcm_phy_get_rxnfc); + +int bcm_phy_set_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *cmd) +{ + int err = 0; + + switch (cmd->cmd) { + case ETHTOOL_SRXCLSRLINS: + err = bcm_phy_set_rule(phydev, cmd); + break; + case ETHTOOL_SRXCLSRLDEL: + if (cmd->fs.location != 0) + return err; + + err = bcm_phy_write_exp(phydev, BCM54XX_WOL_SEC_KEY_8B, 0); + break; + default: + err = -EOPNOTSUPP; + break; + } + + return err; +} +EXPORT_SYMBOL_GPL(bcm_phy_set_rxnfc); + MODULE_DESCRIPTION("Broadcom PHY Library"); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Broadcom Corporation"); diff --git a/drivers/net/phy/bcm-phy-lib.h b/drivers/net/phy/bcm-phy-lib.h index b52189e45a84..7081edcec06b 100644 --- a/drivers/net/phy/bcm-phy-lib.h +++ b/drivers/net/phy/bcm-phy-lib.h @@ -121,4 +121,9 @@ irqreturn_t bcm_phy_wol_isr(int irq, void *dev_id); int bcm_phy_led_brightness_set(struct phy_device *phydev, u8 index, enum led_brightness value); +int bcm_phy_get_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *nfc, u32 *rule_locs); +int bcm_phy_set_rxnfc(struct phy_device *phydev, + struct ethtool_rxnfc *nfc); + #endif /* _LINUX_BCM_PHY_LIB_H */ diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index 3a627105675a..6c2212bd2779 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -1107,6 +1107,8 @@ static struct phy_driver broadcom_drivers[] = { .get_wol = bcm54xx_phy_get_wol, .set_wol = bcm54xx_phy_set_wol, .led_brightness_set = bcm_phy_led_brightness_set, + .get_rxnfc = bcm_phy_get_rxnfc, + .set_rxnfc = bcm_phy_set_rxnfc, }, { .phy_id = PHY_ID_BCM5461, .phy_id_mask = 0xfffffff0, From patchwork Wed Oct 25 17:33:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13436496 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 975DA30D0A for ; Wed, 25 Oct 2023 17:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="cgOKSV4c" Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F36B1BB for ; Wed, 25 Oct 2023 10:34:49 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-777745f1541so3929385a.0 for ; Wed, 25 Oct 2023 10:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1698255288; x=1698860088; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ZkQVj+ohSvU7ZndpStLgdRxD2UAEprv6Wx2YjnFhCwA=; b=cgOKSV4cKIBPLMuHSNCbijMwtU1Ql8jgr8H5K8/chCPqyIQptRWSi0bLAO5mowmLqW yxDIKdkdHqqpf/9ipxw+D9MDsgu17oG4lPnni0a/GuYNxukW2X1KMu1g3Fm5AdicXn7+ O18dU+j4PKNr5EgoIEqXAG+ijfrRyNJcwdFhk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698255288; x=1698860088; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZkQVj+ohSvU7ZndpStLgdRxD2UAEprv6Wx2YjnFhCwA=; b=OllfunTG/M5hwCyln17j0g7yvkIJyKHhWdFA2HFwwGSm9rEZC/1aJH2WAkMFPhPECV F9ej82W69yaVXdv3vsGTxhlkMUfDq5v7iRiDJty6C+7KTg8nQlnqTE2tO8BcovQR9dYH ZgwVML8q3/E4XVqFr03o02hQgDT6+FPDax0gwKfCNwyByGaeWw3QArNDWjdybDp6mBtE SrVymLj+mIm3RIJ/MQo5o67ON9dMsiH5zkOmzEeUrBhoWnFPA7aAD8XgU9u7cTKNRbpv u4O825lfwrbPzIUcXL2lTrhuNlx7SvJSvl2W2hBtky8i+vIx2O4QyzURk+lqMazfQPVr +FfQ== X-Gm-Message-State: AOJu0YyzMmW/L9al+YEao+9SHJABcfhrtMHHnw6uwNxZca8UDuP+4msN AXRCqag0mz6Cm3DM24AlYosBsS13xziV17qHdY4H+JtoLiI+g+xvw+3QPFxVnYMR5/OnW57WAp4 8k3EV4gXxCWoBGiVcYsgWZItD1lXeuYS821ed6l0BKPzL0l9cUOLWvtK2vUC4MxUns6NZfWMjr6 JBz5f0oMmGr3nT X-Google-Smtp-Source: AGHT+IEef6QF/8p68iyCZ9o8f0b0Gm4vRrfNv0vO7xt3hJm/S4UpLNGER58UumgewAJGcwWGxQM56g== X-Received: by 2002:a05:620a:c4f:b0:775:687f:4c2b with SMTP id u15-20020a05620a0c4f00b00775687f4c2bmr17929165qki.44.1698255288271; Wed, 25 Oct 2023 10:34:48 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b00767dcf6f4adsm4332384qkb.51.2023.10.25.10.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:34:47 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Doug Berger , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Vladimir Oltean , Tariq Toukan , Gal Pressman , Willem de Bruijn , Daniil Tatianin , Simon Horman , Justin Chen , Ratheesh Kannoth , Joe Damato , Vincent Mailhol , Jiri Pirko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 5/5] net: bcmgenet: Interrogate PHY for WAKE_FILTER programming Date: Wed, 25 Oct 2023 10:33:00 -0700 Message-Id: <20231025173300.1776832-6-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025173300.1776832-1-florian.fainelli@broadcom.com> References: <20231025173300.1776832-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Determine whether the PHY can support waking up from the user programmed network filter, and if it can utilize it. Signed-off-by: Florian Fainelli > --- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 16 ++++++++++++++++ drivers/net/phy/bcm-phy-lib.c | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index 9282403d1bf6..9d01c13552eb 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -1524,6 +1524,14 @@ static int bcmgenet_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) struct bcmgenet_priv *priv = netdev_priv(dev); int err = 0; + if (dev->phydev) { + err = phy_ethtool_set_rxnfc(dev->phydev, cmd); + if (err != -EOPNOTSUPP) + return err; + + err = 0; + } + switch (cmd->cmd) { case ETHTOOL_SRXCLSRLINS: err = bcmgenet_insert_flow(dev, cmd); @@ -1579,6 +1587,14 @@ static int bcmgenet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, int err = 0; int i = 0; + if (dev->phydev) { + err = phy_ethtool_get_rxnfc(dev->phydev, cmd, rule_locs); + if (err != -EOPNOTSUPP) + return err; + + err = 0; + } + switch (cmd->cmd) { case ETHTOOL_GRXRINGS: cmd->data = priv->hw_params->rx_queues ?: 1; diff --git a/drivers/net/phy/bcm-phy-lib.c b/drivers/net/phy/bcm-phy-lib.c index cfbeedc5ee81..569aeab68f97 100644 --- a/drivers/net/phy/bcm-phy-lib.c +++ b/drivers/net/phy/bcm-phy-lib.c @@ -888,6 +888,15 @@ int bcm_phy_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) if (wol->wolopts & WAKE_FILTER) goto program_ctl; + /* Enabling options other than WAKE_FILTER nullifies the one and only + * network rule that we support. + */ + if (!(wol->wolopts & WAKE_FILTER)) { + ret = bcm_phy_write_exp(phydev, BCM54XX_WOL_SEC_KEY_8B, 0); + if (ret < 0) + return ret; + } + /* When using WAKE_MAGIC, we program the magic pattern filter to match * the device's MAC address and we accept any MAC DA in the Ethernet * frame. @@ -1175,9 +1184,10 @@ static int bcm_phy_set_rule(struct phy_device *phydev, da = nfc->fs.m_u.ether_spec.h_dest; for (i = 0; i < ETH_ALEN / 2; i++) { + u16 mask = da[i * 2] << 8 | da[i * 2 + 1]; ret = bcm_phy_write_exp(phydev, BCM54XX_WOL_MASK(2 - i), - da[i * 2] << 8 | da[i * 2 + 1]); + ~mask); if (ret < 0) return ret; }