From patchwork Thu Jul 2 04:29:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 1320979 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sDDj04JA; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49y4rb53rtz9s1x for ; Thu, 2 Jul 2020 14:30:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726832AbgGBE3w (ORCPT ); Thu, 2 Jul 2020 00:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725857AbgGBE3u (ORCPT ); Thu, 2 Jul 2020 00:29:50 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA6AC08C5C1; Wed, 1 Jul 2020 21:29:49 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x3so6429134pfo.9; Wed, 01 Jul 2020 21:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OVEIjgo+3KNuOB+vFKlCBkTjGwZpPasz23+EtfM4OT0=; b=sDDj04JAtlk688hpG0D28hWUnvmmU6LfDBDVd9JVPeL+Tngvc/hVFd4q9YGQBA286A W13iphRuEHgMCdKGS//8TOCpU7dfZpRVq2PUM7EK3Ob2yE4c7i4mvNu3+8+MTAd7JmxS W6rD6Wy3cHgwSlD1vdx1eE7tK2BQFMey1OmodyUmeUcsj2p6unwRuplIs5YQNaT94uMT BFJAel8oLrVBpnG4uN8TfOBz9CCmSVRIGRkHMd8RBAj6KUkiw9KW86JVmGRAfjlGRYE6 dJct0Ol78+3Tg2654IIkZ7VToasQ65eEs5QTAhqQzO+/VLaLckYfue8/HNeHfmyNjfv8 VUKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OVEIjgo+3KNuOB+vFKlCBkTjGwZpPasz23+EtfM4OT0=; b=REz1MJhzu0aA6Tfr/ChUr0rWccRbUNAfBUYesG84Mvrt8LdRldHzjHIsvIZaFvso5o 8FoEmz3GT9MwFq9/6jfRMP7fJHh2YY2y0yRjSoIWPddjw9jCeNR9WbBBKoobPDwZS9Qa Bi0yIXZ+dEX1HG5wNHtPvQaJrFwNXL9zXVihe7x/ifgObAnNuvsVBrKdnvz651z5py2w tFLC6hT1u2ux9JfzCfLUaNPeuZ4TO6o5eQBPwAWijX6ju1Fae4Jvrx5q4x8mYjhwWZV2 JKrdTUyGoN5C+t4h6m1XbgVCuZ7V35QhZwZPiSLxuGTcG9EK7fFihoKPQNUK4R8IvhF8 LcHQ== X-Gm-Message-State: AOAM532rdsDeZrXQFHEsj4UHY0bgmEID2MXELrK2wuslPPbHEWnZW5e/ PneZxHrB9uUJJHVfGVhcin2W4v7B X-Google-Smtp-Source: ABdhPJybOnM2Osn89cYgNTAuOn/m6lDpLxhzIy9LGGAKFJcaEPH9q0AzU4fh/neYKErWxGJY3PEeiA== X-Received: by 2002:aa7:9ec2:: with SMTP id r2mr27238404pfq.265.1593664189129; Wed, 01 Jul 2020 21:29:49 -0700 (PDT) Received: from localhost.localdomain (ip68-111-84-250.oc.oc.cox.net. [68.111.84.250]) by smtp.gmail.com with ESMTPSA id np5sm6806248pjb.43.2020.07.01.21.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 21:29:48 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Michal Kubecek , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 1/4] net: Add cable test netdevice operations Date: Wed, 1 Jul 2020 21:29:39 -0700 Message-Id: <20200702042942.76674-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702042942.76674-1-f.fainelli@gmail.com> References: <20200702042942.76674-1-f.fainelli@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation for decoupling the ethtool cable test from the PHY library, add definitions for two new network device operations: * ndo_cable_test_start * ndo_cable_test_tdr_start In a subsequent patch we will start making use of those. Signed-off-by: Florian Fainelli --- include/linux/netdevice.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 39e28e11863c..43f640579973 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -936,6 +936,8 @@ struct dev_ifalias { struct devlink; struct tlsdev_ops; +struct phy_tdr_config; +struct netlink_ext_ack; struct netdev_name_node { struct hlist_node hlist; @@ -1278,6 +1280,13 @@ struct netdev_net_notifier { * int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm *p, * int cmd); * Add, change, delete or get information on an IPv4 tunnel. + * int (*ndo_cable_test_start)(struct net_device *dev, + * struct netlink_ext_ack *extack); + * Start a cable test. + * int (*ndo_cable_test_tdr_start)(struct net_device *dev, + * struct netlink_ext_ack *extack, + * const struct phy_tdr_config *config); + * Start a raw TDR (Time Domain Reflectometry) cable test. */ struct net_device_ops { int (*ndo_init)(struct net_device *dev); @@ -1485,6 +1494,11 @@ struct net_device_ops { struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev); int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm *p, int cmd); + int (*ndo_cable_test_start)(struct net_device *dev, + struct netlink_ext_ack *exact); + int (*ndo_cable_test_tdr_start)(struct net_device *dev, + struct netlink_ext_ack *exact, + const struct phy_tdr_config *config); }; /** From patchwork Thu Jul 2 04:29:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 1320980 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=G5lHQdj5; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49y4rg1Bnhz9s1x for ; Thu, 2 Jul 2020 14:30:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728063AbgGBEaK (ORCPT ); Thu, 2 Jul 2020 00:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726772AbgGBE3v (ORCPT ); Thu, 2 Jul 2020 00:29:51 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D5DC08C5C1; Wed, 1 Jul 2020 21:29:51 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id j19so5966299pgm.11; Wed, 01 Jul 2020 21:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SaAU3hiUVjWUOyctEYYV6JFwfF6beu9s6jHYabXwfSA=; b=G5lHQdj5Pr4h4MJTATX1WSjQXr2p/dUKlJKcKTN76mRq8mGEobeT3q6rLcIELyvYvj y1N71K2gFsDty2BQA9tFML8QOIA+1quS3kuwCZB/X+5tIWDxy1DUXgZs1EK9Ya1Lztzy bXRfYDYgOn4KyJzjUyrFU58YuKJ4t2E02dRxs6hjDLjVZMka79q+Dmtnrj1gmyuW5Ded NCWNNZkdbAGt5hBFF3aTaJNh01O4K0v3DlIzz1KIVHK6fcXWIsVp02L/a/xxMEihuyaj mE66dFBkHr/BICkaGr3HBZj+5zPFsgAD6xtAdjsHJ5f44OrG/YtEufzpbktMQ1Yk3Ybn 3ARw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SaAU3hiUVjWUOyctEYYV6JFwfF6beu9s6jHYabXwfSA=; b=bzx7tyRz+mVscSq3hYsDGhHMQUubQ+31hx10SFlqqLVgqk2OKnzdKaiIaUo3Cx7/0X TYyn+aN8s/FkOj/pv/babMils1RFlQ5hkMn3uGXzJTqlGnlamPr3Arbla5jU5+gqiJTF 7turi5N1vmRbD+yFu5xUmihBJJiYBB+Oj6nCCYg1px5KuxGcYdFJioJDrmEhCIe8ZlrY yNSXh7MU6HydTuXwJ1JbawA3ZeOiOpncptLRDPts/cxtSKR1rcjIZHsJ/vxU9923mVQw psHAxbt8adTXpOiOloOagS3KhDiBptUzVT40kv1OLWT1wN0j+pUbzV4inGy0EX7U5rQ0 FlSA== X-Gm-Message-State: AOAM533bNDnxM9oedUEauu8GW5w+hv/YJiM8xrDwHb7e4cAAOO15yX+l X/xObtT2STdAhLoidH1RNMe+FHfe X-Google-Smtp-Source: ABdhPJz3/KKfzHuDvNfqVxeI/Jgth8b2+1UZulOFJWzmi4ZzNpNZgMMaOXW2LbaOZDW6Yp2tBRjeFg== X-Received: by 2002:a63:5a20:: with SMTP id o32mr14284177pgb.15.1593664190745; Wed, 01 Jul 2020 21:29:50 -0700 (PDT) Received: from localhost.localdomain (ip68-111-84-250.oc.oc.cox.net. [68.111.84.250]) by smtp.gmail.com with ESMTPSA id np5sm6806248pjb.43.2020.07.01.21.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 21:29:49 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Michal Kubecek , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 2/4] net: phy: Change cable test arguments to net_device Date: Wed, 1 Jul 2020 21:29:40 -0700 Message-Id: <20200702042942.76674-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702042942.76674-1-f.fainelli@gmail.com> References: <20200702042942.76674-1-f.fainelli@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In order to untangle the ethtool/cabletest feature with the PHY library, make the PHY library functions take a net_device argument and derive the phy_device reference from there. No functional changes introduced. Signed-off-by: Florian Fainelli --- drivers/net/phy/phy.c | 18 ++++++++++++++---- include/linux/phy.h | 8 ++++---- net/ethtool/cabletest.c | 4 ++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 56cfae950472..fbb74f37b961 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -489,12 +489,17 @@ static void phy_abort_cable_test(struct phy_device *phydev) phydev_err(phydev, "Error while aborting cable test"); } -int phy_start_cable_test(struct phy_device *phydev, +int phy_start_cable_test(struct net_device *dev, struct netlink_ext_ack *extack) { - struct net_device *dev = phydev->attached_dev; + struct phy_device *phydev = dev->phydev; int err = -ENOMEM; + if (!dev->phydev) { + NL_SET_ERR_MSG(extack, "Network device not attached to a PHY"); + return -EOPNOTSUPP; + } + if (!(phydev->drv && phydev->drv->cable_test_start && phydev->drv->cable_test_get_status)) { @@ -552,13 +557,18 @@ int phy_start_cable_test(struct phy_device *phydev, } EXPORT_SYMBOL(phy_start_cable_test); -int phy_start_cable_test_tdr(struct phy_device *phydev, +int phy_start_cable_test_tdr(struct net_device *dev, struct netlink_ext_ack *extack, const struct phy_tdr_config *config) { - struct net_device *dev = phydev->attached_dev; + struct phy_device *phydev = dev->phydev; int err = -ENOMEM; + if (!dev->phydev) { + NL_SET_ERR_MSG(extack, "Network device not attached to a PHY"); + return -EOPNOTSUPP; + } + if (!(phydev->drv && phydev->drv->cable_test_tdr_start && phydev->drv->cable_test_get_status)) { diff --git a/include/linux/phy.h b/include/linux/phy.h index 101a48fa6750..53b95c52869d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1266,21 +1266,21 @@ int phy_restart_aneg(struct phy_device *phydev); int phy_reset_after_clk_enable(struct phy_device *phydev); #if IS_ENABLED(CONFIG_PHYLIB) -int phy_start_cable_test(struct phy_device *phydev, +int phy_start_cable_test(struct net_device *dev, struct netlink_ext_ack *extack); -int phy_start_cable_test_tdr(struct phy_device *phydev, +int phy_start_cable_test_tdr(struct net_device *dev, struct netlink_ext_ack *extack, const struct phy_tdr_config *config); #else static inline -int phy_start_cable_test(struct phy_device *phydev, +int phy_start_cable_test(struct net_device *dev, struct netlink_ext_ack *extack) { NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support"); return -EOPNOTSUPP; } static inline -int phy_start_cable_test_tdr(struct phy_device *phydev, +int phy_start_cable_test_tdr(struct net_device *dev, struct netlink_ext_ack *extack, const struct phy_tdr_config *config) { diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index 7194956aa09e..0d940a91493b 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -85,7 +85,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) if (ret < 0) goto out_rtnl; - ret = phy_start_cable_test(dev->phydev, info->extack); + ret = phy_start_cable_test(dev, info->extack); ethnl_ops_complete(dev); @@ -341,7 +341,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) if (ret < 0) goto out_rtnl; - ret = phy_start_cable_test_tdr(dev->phydev, info->extack, &cfg); + ret = phy_start_cable_test_tdr(dev, info->extack, &cfg); ethnl_ops_complete(dev); From patchwork Thu Jul 2 04:29:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 1320977 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=FlT7PBbH; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49y4rR5Q8dz9sTN for ; Thu, 2 Jul 2020 14:29:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbgGBE3z (ORCPT ); Thu, 2 Jul 2020 00:29:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbgGBE3x (ORCPT ); Thu, 2 Jul 2020 00:29:53 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38437C08C5C1; Wed, 1 Jul 2020 21:29:53 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id f16so1567701pjt.0; Wed, 01 Jul 2020 21:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1Od+hFGDWW+xh79eFx8APnbyBK84QUAzLz4kk0NdbRw=; b=FlT7PBbHdvAZXrHU90iSUnmGAGsvYJKZnXpcUdYCs7g48XlmeMu/SmtJeGSUcxMDqD OF4Um3I2bXCJCUTiOV7tXtWvh/4Obg619fVOmbE5/zKTC7AF+UX2h4MOzmIzQjD/t5ff scYxLGi97AI9S4HYjlbD3m4vETsKH3OyAqVKwploBtK5GKWY8JBvIcxaxnfM3A/t/pw0 am3a+5/5SRQSJdRq8W64/bT7vwv7Sj6emcv1/+hkzp7bHDZpwyHrt6u2NzeZrF5hnzh2 wbgKaH66sxDEtsgTjlBzcSZEKJwT8NaE/IT7Rs73gNoJ9BfMFrGwgJ2NrZ/o1kV0r8Ro IvGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1Od+hFGDWW+xh79eFx8APnbyBK84QUAzLz4kk0NdbRw=; b=MGKmS7H4Pgz2trT3JQhhoLl443rFabW3mwKcBDozHlFT6pm5GXiAW1hLvQMlWeifdr kjQbk2tZ1mVopz3YHR336NF4sxzq1Sx/xNdILVDzZzt8M6l2hU0zCzVIkqDd5FW8tRh9 82BAX3dty2SQP6ZwYa3H5sfkOcSfkmCPXFfRvamDTxs/TP91gcvdTryPupA6OSt4rQQ3 S4ijXtga6OfopQyyDs4SDAkA/9Wu1h0ufSpv8zbsmR6ribYHE5/E6efpKBwLdkndj9nc KKtovIuEFhUoTvUl12xhAOHRFiCzy95+rSnhzaWDejZhctCGlbtQAiDmR2i4vQxY0K41 jNpg== X-Gm-Message-State: AOAM531ibPe32GeRvL69ET1LIkU09BSjLVcelUEF1wCZDyKeFSTk8pLk NTFsO7fweIDw1QFMVwYx9nSfskqC X-Google-Smtp-Source: ABdhPJyLON1SbcJQiApagT4Y/5mqzmZ4NIkp2UYO+BNfXE/A4TR8kvR+2Q3GAgMn5mSDDNdfPqaCSg== X-Received: by 2002:a17:902:162:: with SMTP id 89mr25012159plb.211.1593664192305; Wed, 01 Jul 2020 21:29:52 -0700 (PDT) Received: from localhost.localdomain (ip68-111-84-250.oc.oc.cox.net. [68.111.84.250]) by smtp.gmail.com with ESMTPSA id np5sm6806248pjb.43.2020.07.01.21.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 21:29:51 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Michal Kubecek , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 3/4] net: phy: Automatically set-up cable test netdev_ops Date: Wed, 1 Jul 2020 21:29:41 -0700 Message-Id: <20200702042942.76674-4-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702042942.76674-1-f.fainelli@gmail.com> References: <20200702042942.76674-1-f.fainelli@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Upon attach, override the net_device operations with the PHY library cable test operations and conversely, upon detach, revert to the original net_device operations. This will allows us in a subsequent patch to finally decouple the ethtool/cabletest from the PHY library hard depenencies. Signed-off-by: Florian Fainelli --- drivers/net/phy/phy_device.c | 32 ++++++++++++++++++++++++++++++++ include/linux/phy.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index eb1068a77ce1..100d85541a06 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1246,6 +1246,36 @@ phy_standalone_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(phy_standalone); +static int phy_setup_netdev_ops(struct net_device *dev) +{ + struct phy_device *phydev = dev->phydev; + struct net_device_ops *ops; + + ops = devm_kzalloc(&phydev->mdio.dev, sizeof(*ops), GFP_KERNEL); + if (!ops) + return -ENOMEM; + + phydev->orig_ndo_ops = dev->netdev_ops; + if (phydev->orig_ndo_ops) + memcpy(ops, phydev->orig_ndo_ops, sizeof(*ops)); + + ops->ndo_cable_test_start = phy_start_cable_test; + ops->ndo_cable_test_tdr_start = phy_start_cable_test_tdr; + + dev->netdev_ops = ops; + + return 0; +} + +static void phy_teardown_netdev_ops(struct net_device *dev) +{ + struct phy_device *phydev = dev->phydev; + + if (phydev->orig_ndo_ops) + dev->netdev_ops = phydev->orig_ndo_ops; + phydev->orig_ndo_ops = NULL; +} + /** * phy_sfp_attach - attach the SFP bus to the PHY upstream network device * @upstream: pointer to the phy device @@ -1380,6 +1410,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, if (dev) { phydev->attached_dev = dev; dev->phydev = phydev; + phy_setup_netdev_ops(dev); if (phydev->sfp_bus_attached) dev->sfp_bus = phydev->sfp_bus; @@ -1676,6 +1707,7 @@ void phy_detach(struct phy_device *phydev) phy_suspend(phydev); if (dev) { + phy_teardown_netdev_ops(dev); phydev->attached_dev->phydev = NULL; phydev->attached_dev = NULL; } diff --git a/include/linux/phy.h b/include/linux/phy.h index 53b95c52869d..04e35afa43ae 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -544,6 +544,8 @@ struct phy_device { /* MACsec management functions */ const struct macsec_ops *macsec_ops; #endif + /* Original attached network device netdev_ops pointer */ + const struct net_device_ops *orig_ndo_ops; }; #define to_phy_device(d) container_of(to_mdio_device(d), \ struct phy_device, mdio) From patchwork Thu Jul 2 04:29:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 1320978 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ESsnn5vZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49y4rS6XkQz9sTN for ; Thu, 2 Jul 2020 14:30:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgGBE37 (ORCPT ); Thu, 2 Jul 2020 00:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726993AbgGBE3y (ORCPT ); Thu, 2 Jul 2020 00:29:54 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACD20C08C5C1; Wed, 1 Jul 2020 21:29:54 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id l63so12810521pge.12; Wed, 01 Jul 2020 21:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9CSB4wi1g7ALKJ04YCMbv+vCl7X+afKawoSmLzpgxuY=; b=ESsnn5vZuS4vJ60Up0eoOHlsAE+XfplVIhKXsIR5wcaVOjCeSB55kASeLTxSyGEC8T 77NpsRy0/BZXxa+o/6yGeik+cbKh1ub1jzXvjEYQTSMhefgi8ZDUOTv2acI/mFCeVZls IPcCOwfY4pn7q9l1APycCKVAjiEprExb7B1hzDwPNs379TIbxs1aieaJ1k+JpG+STeiy 5y5z2oIcBXOO0rcG3VDSmxZ2bTSHHPV/OKMa1tRZsVdS7Q/7Tj5EiSOTPMA7c5R+ZxWN YHMRb+ibOIgTi5iQLDKXvnlSae2TyPjGCkZjOpSiRjkA2jj3es5Fu/RxM+SK9R6ehfYe BGYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9CSB4wi1g7ALKJ04YCMbv+vCl7X+afKawoSmLzpgxuY=; b=gencqdzZapCjf8lgpmvQ5tgSJG0dhOcjKrhsD4IPgD7A7OH3hlsSzu9FSpoCKDUXWH 0AGNw8vKOa7ksu1vSIX7KP/x58Ddx4tfRFuTLJx6wYGGDzHdAhGCMxmbvSdSVAIHEvEx 1SW0bw2FfLZQFV/FoXmWH42MdWcYv2T2GjfAsNGyRnId9rZQ54oZpoptwRe7Pbjtr+4H wi7WwQm18ehJ1+O0IXa8iY3V2QaZzbFYGGQlM0lWxz3UdfpO6tPgr3Df8HS0sy22+PVe O47hKJjk2r6sYWgASQ9LpMfCSo9LRiNvGPgF3iz9u9KNEX6rEEwbYFdj5m+gcVExflhy ZClg== X-Gm-Message-State: AOAM531a0KwaPCqnUeRj/pLXaRY8oWX4vqhQZww8Kz+aGwrmq5tZ6eA0 gIWIEvDLmEKHBICMn/yK1hBP/vcx X-Google-Smtp-Source: ABdhPJx1zY7xiFM8NE2ejpIuwVuSC6zC0a9nWDMyHkgYaW2QFEguugNXexWjvoR2x9gBwX8qDj/v5g== X-Received: by 2002:a62:2b96:: with SMTP id r144mr26837035pfr.272.1593664193794; Wed, 01 Jul 2020 21:29:53 -0700 (PDT) Received: from localhost.localdomain (ip68-111-84-250.oc.oc.cox.net. [68.111.84.250]) by smtp.gmail.com with ESMTPSA id np5sm6806248pjb.43.2020.07.01.21.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 21:29:53 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Michal Kubecek , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next 4/4] net: ethtool: Remove PHYLIB dependency Date: Wed, 1 Jul 2020 21:29:42 -0700 Message-Id: <20200702042942.76674-5-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702042942.76674-1-f.fainelli@gmail.com> References: <20200702042942.76674-1-f.fainelli@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that we have converted the ethtool/cabletest code to use netdev_ops, we can remove the PHY library dependency since the function pointers will now be provided upon PHY attachment to the network device. Signed-off-by: Florian Fainelli --- net/Kconfig | 1 - net/ethtool/cabletest.c | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/net/Kconfig b/net/Kconfig index d1672280d6a4..3831206977a1 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -455,7 +455,6 @@ config FAILOVER config ETHTOOL_NETLINK bool "Netlink interface for ethtool" default y - depends on PHYLIB=y || PHYLIB=n help An alternative userspace interface for ethtool based on generic netlink. It provides better extensibility and some new features, diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index 0d940a91493b..d8e2eb427613 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -58,6 +58,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) { struct nlattr *tb[ETHTOOL_A_CABLE_TEST_MAX + 1]; struct ethnl_req_info req_info = {}; + const struct net_device_ops *ops; struct net_device *dev; int ret; @@ -75,7 +76,8 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) return ret; dev = req_info.dev; - if (!dev->phydev) { + ops = dev->netdev_ops; + if (!ops->ndo_cable_test_start) { ret = -EOPNOTSUPP; goto out_dev_put; } @@ -85,7 +87,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) if (ret < 0) goto out_rtnl; - ret = phy_start_cable_test(dev, info->extack); + ret = ops->ndo_cable_test_start(dev, info->extack); ethnl_ops_complete(dev); @@ -308,6 +310,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *tb[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1]; struct ethnl_req_info req_info = {}; + const struct net_device_ops *ops; struct phy_tdr_config cfg; struct net_device *dev; int ret; @@ -326,7 +329,8 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) return ret; dev = req_info.dev; - if (!dev->phydev) { + ops = dev->netdev_ops; + if (!ops->ndo_cable_test_tdr_start) { ret = -EOPNOTSUPP; goto out_dev_put; } @@ -341,7 +345,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) if (ret < 0) goto out_rtnl; - ret = phy_start_cable_test_tdr(dev, info->extack, &cfg); + ret = ops->ndo_cable_test_tdr_start(dev, info->extack, &cfg); ethnl_ops_complete(dev);