Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5261646rwb; Sun, 4 Dec 2022 17:58:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf7TwHbxoWHX+Smdytr1fCpjAG4qdZyKwFyvlUbxOWfSTGhh1Jd7sPEcGvO/M9DNYUCo4xVK X-Received: by 2002:a17:902:7885:b0:189:1366:fba7 with SMTP id q5-20020a170902788500b001891366fba7mr64797578pll.45.1670205516335; Sun, 04 Dec 2022 17:58:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670205516; cv=none; d=google.com; s=arc-20160816; b=gTomLYoVO1Lhzufh/tfhk9XY+UERUXidHqqLymzcFemk0IjZ6mAIKf9SFaMYOQWaNU Juu3kRG1TGyJhStl+LJkBRmYi5zBOQD/lx4xKwhbhjbIHphHaaA8x/rgXPtmHNjlDbH1 48hg7gmOI2CPciVHgziD2pU8DFaRGUPUqhd/6QmRJdb6FmRCJwPPwOyr2RLTNMu9LzWb wP3edz1lXdiIYizuS+wBR4kRzKIo6bpm9Cd8hyxXIdRylcdE6yS4QckId24nNonuhOf5 SrGBayOvniJ+a+IR6gSrjAQPEw/8U+ZtHgsOO4dMPVrt6KkXI0gBS/W/LgWSizq+mZ2T tmmw== 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=Zx0zh9a0T5iZl9sxln0TAiuWj203m7h4iKF2Szbvrp0=; b=a9Eb8EVpdyrfDK6WlJSgkX8yiiUZoQAbtcjjUEPasPasYyH2dmHghIQv/GBeOMLKy1 YFG0BjmP41vKfQXlERS5sNbsYuRCcUfk/CUiIgjfoCPCRlFKcIVBe1jPVgLLoo0QIEmB TKZJk4ExoS2nT9IbnZa3ALuUtmsOJ8zUOI3OE+gXrPQ4F6hyRsZ5B5EiQKkahYQ+iw1T sJp+V9z/IaVx47o+6wyxmD0n0mfMcxQajG8J6sChDkUtlV2ZTFuvghjiz1PL9Ho0HN6E XfOULuCi9fmCJBdkwjQDttvC+Bo1uEn2xH4noUHS6uTKQgkmh1oWmXpgekoKPA72j65V ReBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=awv0SkNF; 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 g19-20020a170902d1d300b00189d56098b3si1656722plb.113.2022.12.04.17.58.25; Sun, 04 Dec 2022 17:58:36 -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=awv0SkNF; 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 S231307AbiLEBms (ORCPT + 83 others); Sun, 4 Dec 2022 20:42:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbiLEBmq (ORCPT ); Sun, 4 Dec 2022 20:42:46 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ABF02BC5; Sun, 4 Dec 2022 17:42:43 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id d20so13874623edn.0; Sun, 04 Dec 2022 17:42:43 -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=Zx0zh9a0T5iZl9sxln0TAiuWj203m7h4iKF2Szbvrp0=; b=awv0SkNFoyr16eJPD1g/QQTO0V97omRv/sGIo/J6X7kw5tJLVjtZgxT9r0BJNgk9tc vjP5ZOFI8z5KOB1ZiEwNvK1aCqhFYj2IHkU6NibVMYQg/mE75cv+pvEstYgrtCEo+L27 DvdpOXEqjPV7ccvDCbGLTbm1UZwexlYkeY42dwuCdduYiD5jybI0EcCbm7QaOj1HS0Mf dDNVThICUpAGiSyhhN00jXUEfmk9exz96mfj6be3iLm5ufJYi/tY8xflJgmOKSct+o6d 7fPc8cBi/gxGt7ikpQCyr7HWrWGj9bMT//JzG4oDawM/hfXMRX2ckEtSoz2QRKfXXM9+ rAtA== 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=Zx0zh9a0T5iZl9sxln0TAiuWj203m7h4iKF2Szbvrp0=; b=A5o82ZLe6mjs0O9dLibj/7WKeResidaFN2Ye2vjHnqRJj07lNOOknfGKuah3m5cc1D 1fKgv78kk3ZeV8zAKu8AdrS1Xy/mX/fu/Y7U3ieflKiS3018XlxgUvXDLODHkxSeJ8TQ oczlB4pnt9qDbIdOwpx4PDrWbRc/aS+zn0ZTZThKVAWRnFIiOe3QgYgF2jUcgkmaTHFh Is2VTnXBCLDzeLFGm7dtMxpPb9L+bwh6ngKeMXeY3yh6/6zLkqE/1GYxJl+6uV4HCm6Z xRMDRfiETG7eDETC6k5DCe5Ywkte8DKb2u7bhXrlE/xlVrG93KDUARvAp579byXn0eOM PjyQ== X-Gm-Message-State: ANoB5pmfZDIi7cl+0h8FbSYcEsVPb/K5GK05wvLjePAP5Tye7mJ/HtKa LVq6yNwVcS4KhG4dtjMF0F4= X-Received: by 2002:a05:6402:4504:b0:463:71ef:b9ce with SMTP id ez4-20020a056402450400b0046371efb9cemr62319669edb.75.1670204561802; Sun, 04 Dec 2022 17:42: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 oz13-20020a170906cd0d00b007ae566edb8bsm5696074ejb.73.2022.12.04.17.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 17:42:41 -0800 (PST) Date: Mon, 5 Dec 2022 02:42:50 +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 v2 net-next 3/4] drivers/net/phy: add connection between ethtool and phylib for PLCA Message-ID: 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 | 163 +++++++++++++++++++++++++++++++++++++++--- include/linux/phy.h | 17 ++++- 2 files changed, 168 insertions(+), 12 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 99e3497b6aa1..6bea928e405b 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -544,36 +544,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 *dev, +int phy_ethtool_get_plca_cfg(struct phy_device *phydev, struct phy_plca_cfg *plca_cfg) { - // TODO - return 0; + 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; } EXPORT_SYMBOL(phy_ethtool_get_plca_cfg); /** + * 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 *dev, +int phy_ethtool_set_plca_cfg(struct phy_device *phydev, struct netlink_ext_ack *extack, const struct phy_plca_cfg *plca_cfg) { - // TODO - return 0; + 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; + } EXPORT_SYMBOL(phy_ethtool_set_plca_cfg); /** + * 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 *dev, +int phy_ethtool_get_plca_status(struct phy_device *phydev, struct phy_plca_status *plca_st) { - // TODO - return 0; + 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; } EXPORT_SYMBOL(phy_ethtool_get_plca_status); diff --git a/include/linux/phy.h b/include/linux/phy.h index ab2c134d0a05..49d0488bf480 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1036,6 +1036,17 @@ 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); + + /* PLCA RS interface */ + /** @get_plca_cfg: Return the current PLCA configuration */ + int (*get_plca_cfg)(struct phy_device *dev, + struct phy_plca_cfg *plca_cfg); + /** @set_plca_cfg: Set the PLCA configuration */ + int (*set_plca_cfg)(struct phy_device *dev, + const struct phy_plca_cfg *plca_cfg); + /** @get_plca_status: Return the current PLCA status info */ + int (*get_plca_status)(struct phy_device *dev, + struct phy_plca_status *plca_st); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) @@ -1832,12 +1843,12 @@ 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 *dev, +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 *dev, +int phy_ethtool_set_plca_cfg(struct phy_device *phydev, struct netlink_ext_ack *extack, const struct phy_plca_cfg *plca_cfg); -int phy_ethtool_get_plca_status(struct phy_device *dev, +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.35.1