Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4756536rwb; Sat, 10 Dec 2022 14:52:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf5WhZ31bDnxM94jI2htIsUIs61c98cS/4Cc3cJPAfwzgSb4/ynGCy26JvS73Ex5hZv8oPjT X-Received: by 2002:a17:902:b406:b0:189:e711:173 with SMTP id x6-20020a170902b40600b00189e7110173mr10850723plr.33.1670712771087; Sat, 10 Dec 2022 14:52:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670712771; cv=none; d=google.com; s=arc-20160816; b=cW71ifcut8AlrqK0ckrje3XIbEjXN/4yEb++eRCVzExZVRjIS8+sR7113eCpPLTdzC 7pXAM2n3xDShuz2TvkLnAet2ndvZigvCht5VU82mTS1Msv5gqYa9r+StC1fHmjKWEcqN XNbfr9DKniZdlici5nGf4VGK20OF+98zVHBScgix+WN8yuW0jK90XyLrp7sv+JboYQNp SkqdELlD6qrvt5C8xfgrJsKylkJk9Yjt5wq8l2wjY1MmW9CG5R+zdqxhsZg7mi57l1DC BDX9J3LLDYDras7EmqgRn6YII+s3WDQhLrxqgXWXg9Jon+85+TRZmS+a/MLU3WwOj2Vi HPKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Pwqt2w04D7PFVnjtQc3uvtXyNu5PqIc7EL2S+8xpYTk=; b=wMUw7oL8dsVQH4BgYccZ00FLi7iFJBPW2TkG6rVxzhA4fFa0EvutCDgmZamL48S6BL VeSo5K1733YgCwzpJyS89EcUmZStKNYvqzujE8cJh+k7mRlY1YTCl+gPhQvuCMOCk5Z4 Z6Uc9+7yMaq+7BYXV2KWMda/1tux7HYDBmxElVBbu9mwyz+vL9DT5MqZ4OlkMHfdIx38 NflqEkjUabNob82uYDaotvb7fX0phkRy9S0db/hj4wGDF9QokWwknuwAIhI00okbB7GL /rNV58k/F3LLsB9EWQE4J6TyNvnRJVaSZMIJVBiP+YDQKYyEhprCK0PGKBwEkV4CNfSQ ciaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mMRrKXS+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f68-20020a636a47000000b0047853fba938si5248076pgc.390.2022.12.10.14.52.39; Sat, 10 Dec 2022 14:52:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mMRrKXS+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbiLJWq5 (ORCPT + 74 others); Sat, 10 Dec 2022 17:46:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbiLJWqr (ORCPT ); Sat, 10 Dec 2022 17:46:47 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F89212D12; Sat, 10 Dec 2022 14:46:42 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id qk9so19521366ejc.3; Sat, 10 Dec 2022 14:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Pwqt2w04D7PFVnjtQc3uvtXyNu5PqIc7EL2S+8xpYTk=; b=mMRrKXS+Jp4DJYegi+AkRNfR5RjhRz8H7eIzZXi7EeTUzHbPRfvwdP3H+Bv611r9Jv vAtPQNsGODT/dn+t/pnLFvkYZiAXLA+bC0RFQ+PQ0bm3r2EFs4iNquNmgDFw7ik4qzKg m3mgHXnJ+FWo0L4za5AFe/Cpl5iJndINLELoF0Y3mTtv5rs2bJZPEdE/pT/FqUAyF1ix EFS8wcAPYQlmNUiyqDtFlYGooiYtngteADpRsCkcpRbO5mtPwlrSbKJccPulF4UW92J/ oTwnL/0v14QBo/NaFsnGSYOKGzkMNx1Y8LjA5PWLLSVrl7yW3V8Wb9PaXPeMQ/I3S4Xo 9xRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Pwqt2w04D7PFVnjtQc3uvtXyNu5PqIc7EL2S+8xpYTk=; b=CCO9Cnh7I0Ne3qx8faNm+Y0WBbH9JAyCCD+SKH87EBsDvO6EU71MCxxC40YIX/cwy0 wQX8cN8In0u6SLFDxh/9MllSzdhKqgZCzy6HkcgOwURd9v20RDH/DJCZSaUzAZh1CP7Y juiruDcDgno+7JjeUnv3TK5sl4d/5de8IiQeU/ZVT+Uf+EirNdmSo/YsuXrCCocJH1oU 4ZkJ45gRtNXQgSs5+v3MfuAZ6lBCAYyaFnJxo/eqXHO1b442rl9wyLibWTFyXx/lB8Ia QArga615GulpqJjs+NZFNIMyOJRTre2QNKs1fzPHf9Wm57EUr8mHXyfm+rReRRegXH5g 22JQ== X-Gm-Message-State: ANoB5plsTU//dWf7cdxk4QI5T9K1Ula89e0G60bjtYCSx57UhTMER9hw qrde9CYOx2pvHtXcFyz+ln8= X-Received: by 2002:a17:906:a099:b0:7ae:8144:690 with SMTP id q25-20020a170906a09900b007ae81440690mr9005985ejy.32.1670712401060; Sat, 10 Dec 2022 14:46:41 -0800 (PST) Received: from gvm01 (net-2-45-26-236.cust.vodafonedsl.it. [2.45.26.236]) by smtp.gmail.com with ESMTPSA id g23-20020a170906595700b007c0bb571da5sm1446743ejr.41.2022.12.10.14.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Dec 2022 14:46:40 -0800 (PST) Date: Sat, 10 Dec 2022 23:46:39 +0100 From: Piergiorgio Beruto To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Oleksij Rempel Subject: [PATCH v6 net-next 3/5] drivers/net/phy: add connection between ethtool and phylib for PLCA Message-ID: <75cb0eab15e62fc350e86ba9e5b0af72ea45b484.1670712151.git.piergiorgio.beruto@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the required connection between netlink ethtool and phylib to resolve PLCA get/set config and get status messages. Signed-off-by: Piergiorgio Beruto --- drivers/net/phy/phy.c | 175 +++++++++++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 3 + include/linux/phy.h | 7 ++ 3 files changed, 185 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index e5b6cb1a77f9..40d90ed2f0fb 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -543,6 +543,181 @@ int phy_ethtool_get_stats(struct phy_device *phydev, } EXPORT_SYMBOL(phy_ethtool_get_stats); +/** + * phy_ethtool_get_plca_cfg - Get PLCA RS configuration + * + * @phydev: the phy_device struct + * @plca_cfg: where to store the retrieved configuration + */ +int phy_ethtool_get_plca_cfg(struct phy_device *phydev, + struct phy_plca_cfg *plca_cfg) +{ + int ret; + + if (!phydev->drv) { + ret = -EIO; + goto out; + } + + if (!phydev->drv->get_plca_cfg) { + ret = -EOPNOTSUPP; + goto out; + } + + memset(plca_cfg, 0xFF, sizeof(*plca_cfg)); + + mutex_lock(&phydev->lock); + ret = phydev->drv->get_plca_cfg(phydev, plca_cfg); + + if (ret) + goto out_drv; + +out_drv: + mutex_unlock(&phydev->lock); +out: + return ret; +} + +/** + * phy_ethtool_set_plca_cfg - Set PLCA RS configuration + * + * @phydev: the phy_device struct + * @extack: extack for reporting useful error messages + * @plca_cfg: new PLCA configuration to apply + */ +int phy_ethtool_set_plca_cfg(struct phy_device *phydev, + const struct phy_plca_cfg *plca_cfg, + struct netlink_ext_ack *extack) +{ + int ret; + struct phy_plca_cfg *curr_plca_cfg = 0; + + if (!phydev->drv) { + ret = -EIO; + goto out; + } + + if (!phydev->drv->set_plca_cfg || + !phydev->drv->get_plca_cfg) { + ret = -EOPNOTSUPP; + goto out; + } + + curr_plca_cfg = kmalloc(sizeof(*curr_plca_cfg), GFP_KERNEL); + memset(curr_plca_cfg, 0xFF, sizeof(*curr_plca_cfg)); + + mutex_lock(&phydev->lock); + + ret = phydev->drv->get_plca_cfg(phydev, curr_plca_cfg); + if (ret) + goto out_drv; + + if (curr_plca_cfg->enabled < 0 && plca_cfg->enabled >= 0) { + NL_SET_ERR_MSG(extack, + "PHY does not support changing the PLCA 'enable' attribute"); + ret = -EINVAL; + goto out_drv; + } + + if (curr_plca_cfg->node_id < 0 && plca_cfg->node_id >= 0) { + NL_SET_ERR_MSG(extack, + "PHY does not support changing the PLCA 'local node ID' attribute"); + ret = -EINVAL; + goto out_drv; + } + + if (curr_plca_cfg->node_cnt < 0 && plca_cfg->node_cnt >= 0) { + NL_SET_ERR_MSG(extack, + "PHY does not support changing the PLCA 'node count' attribute"); + ret = -EINVAL; + goto out_drv; + } + + if (curr_plca_cfg->to_tmr < 0 && plca_cfg->to_tmr >= 0) { + NL_SET_ERR_MSG(extack, + "PHY does not support changing the PLCA 'TO timer' attribute"); + ret = -EINVAL; + goto out_drv; + } + + if (curr_plca_cfg->burst_cnt < 0 && plca_cfg->burst_cnt >= 0) { + NL_SET_ERR_MSG(extack, + "PHY does not support changing the PLCA 'burst count' attribute"); + ret = -EINVAL; + goto out_drv; + } + + if (curr_plca_cfg->burst_tmr < 0 && plca_cfg->burst_tmr >= 0) { + NL_SET_ERR_MSG(extack, + "PHY does not support changing the PLCA 'burst timer' attribute"); + ret = -EINVAL; + goto out_drv; + } + + // if enabling PLCA, perform additional sanity checks + if (plca_cfg->enabled > 0) { + if (!linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT, + phydev->advertising)) { + ret = -EOPNOTSUPP; + NL_SET_ERR_MSG(extack, + "Point to Multi-Point mode is not enabled"); + } + + // allow setting node_id concurrently with enabled + if (plca_cfg->node_id >= 0) + curr_plca_cfg->node_id = plca_cfg->node_id; + + if (curr_plca_cfg->node_id >= 255) { + NL_SET_ERR_MSG(extack, "PLCA node ID is not set"); + ret = -EINVAL; + goto out_drv; + } + } + + ret = phydev->drv->set_plca_cfg(phydev, plca_cfg); + if (ret) + goto out_drv; + +out_drv: + kfree(curr_plca_cfg); + mutex_unlock(&phydev->lock); +out: + return ret; +} + +/** + * phy_ethtool_get_plca_status - Get PLCA RS status information + * + * @phydev: the phy_device struct + * @plca_st: where to store the retrieved status information + */ +int phy_ethtool_get_plca_status(struct phy_device *phydev, + struct phy_plca_status *plca_st) +{ + int ret; + + if (!phydev->drv) { + ret = -EIO; + goto out; + } + + if (!phydev->drv->get_plca_status) { + ret = -EOPNOTSUPP; + goto out; + } + + mutex_lock(&phydev->lock); + ret = phydev->drv->get_plca_status(phydev, plca_st); + + if (ret) + goto out_drv; + +out_drv: + mutex_unlock(&phydev->lock); +out: + return ret; +} + /** * phy_start_cable_test - Start a cable test * diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8e48b3cec5e7..44bd06be9691 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3276,6 +3276,9 @@ static const struct ethtool_phy_ops phy_ethtool_phy_ops = { .get_sset_count = phy_ethtool_get_sset_count, .get_strings = phy_ethtool_get_strings, .get_stats = phy_ethtool_get_stats, + .get_plca_cfg = phy_ethtool_get_plca_cfg, + .set_plca_cfg = phy_ethtool_set_plca_cfg, + .get_plca_status = phy_ethtool_get_plca_status, .start_cable_test = phy_start_cable_test, .start_cable_test_tdr = phy_start_cable_test_tdr, }; diff --git a/include/linux/phy.h b/include/linux/phy.h index 2a5c2d3a5da5..e0dcd534fe6f 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1845,6 +1845,13 @@ int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data); int phy_ethtool_get_sset_count(struct phy_device *phydev); int phy_ethtool_get_stats(struct phy_device *phydev, struct ethtool_stats *stats, u64 *data); +int phy_ethtool_get_plca_cfg(struct phy_device *phydev, + struct phy_plca_cfg *plca_cfg); +int phy_ethtool_set_plca_cfg(struct phy_device *phydev, + const struct phy_plca_cfg *plca_cfg, + struct netlink_ext_ack *extack); +int phy_ethtool_get_plca_status(struct phy_device *phydev, + struct phy_plca_status *plca_st); static inline int phy_package_read(struct phy_device *phydev, u32 regnum) { -- 2.37.4