From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0F0FC282C4 for ; Sat, 9 Feb 2019 14:25:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 853BE217D8 for ; Sat, 9 Feb 2019 14:25:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rPdYBXOe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726832AbfBIOZA (ORCPT ); Sat, 9 Feb 2019 09:25:00 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35868 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726484AbfBIOZA (ORCPT ); Sat, 9 Feb 2019 09:25:00 -0500 Received: by mail-wm1-f68.google.com with SMTP id p6so8371995wmc.1 for ; Sat, 09 Feb 2019 06:24:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=nfw0ZRReJyePhYT3DSwOyhg3IcNZsGpU1JecLpha6eY=; b=rPdYBXOerFQ4GaCoQCFarXO06VSReNzlM/H8ui/evkKIQrbfosnLQmrY9FZqi+mG2/ JEM+YkV8KDujmh+TueCB4ZBEQRWeEhDdBRDjZ+YQF2iT6c9qQmUWKFyGaUJmvmYs+obs yZVMYuabU3PiwE7yaxsSdBMp/jyxfuF9d3h02A3E3SdPKBODP89mhbzVgDZOPGon+pWC Gs5CvnVhQIImxzvOuA8dtrpRlOYKl7GERUz1S70SD75t1EESiJnWws4VZOIGcN3YHQHn zc0jhPJ6b9YJyYOH6HmLRIKnnNPf++2H5wvBY2LtiPFxVb6nojx2fjcBN8c73aXhGln6 gdcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=nfw0ZRReJyePhYT3DSwOyhg3IcNZsGpU1JecLpha6eY=; b=TAho9Muz/NL/f1/nuQHdgNjyS+AowxIAMZDjYpP0bhaHKfIHkMoUXhuh2GnyA6tyNm E2b1GrmmWwWXF52h7uORz0MatyUDp/OTO2iKzV+cMKIhNn5eQwCDWTlAF65VQSuOavyc qF4dcwR8oFXmqODZBFDb47OeEXr/as5rfgjrOQkr4GreyWpHEkrqyDZx8dX62N6dKioR 0Isa+qdL34sTOM3wg3N8uxnPv/EO5/gGFdJSi5eNh0758DlWrJhQq3yczHLGYpueslvo /lmQCG5EgiBnLUitE5uJsgCqRiXoIXN+DH1geBnmUJE9APNlPixBx9Nb8yJO2R8f5fhd UkHA== X-Gm-Message-State: AHQUAuZBb7sTIUjXuQOMj8oNstY6bEvOwsjkBAYzR+FfE9zZIcfT8ls+ /5vCNsB84rSL8RjcDnJjfSugmzrd X-Google-Smtp-Source: AHgI3IazXhkHCwTNkTvgPlZTUln5sfkik4dnujMNHav8S5rq9Bkm8M3Msfr/Ndau0n08UAxnJe+N4A== X-Received: by 2002:a1c:7601:: with SMTP id r1mr2830341wmc.123.1549722298101; Sat, 09 Feb 2019 06:24:58 -0800 (PST) Received: from ?IPv6:2003:ea:8bf1:e200:aca4:3d:8205:4c97? (p200300EA8BF1E200ACA4003D82054C97.dip0.t-ipconnect.de. [2003:ea:8bf1:e200:aca4:3d:8205:4c97]) by smtp.googlemail.com with ESMTPSA id e8sm6807674wme.13.2019.02.09.06.24.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Feb 2019 06:24:57 -0800 (PST) To: Andrew Lunn , Florian Fainelli , David Miller Cc: "netdev@vger.kernel.org" From: Heiner Kallweit Subject: [PATCH net-next] net: phy: Add support for asking the PHY its abilities Message-ID: <19c1e5c4-2f86-a3ff-e971-a0098c605b3f@gmail.com> Date: Sat, 9 Feb 2019 15:24:47 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Andrew Lunn Add support for runtime determination of what the PHY supports, by adding a new function to the phy driver. The get_features call should set the phydev->supported member with the features the PHY supports. It is only called if phydrv->features is NULL. This requires minor changes to pause. The PHY driver should not set pause abilities, except for when it has odd cause capabilities, e.g. pause cannot be disabled. With this change, phydev->supported already contains the drivers abilities, including pause. So rather than considering phydrv->features, look at the phydev->supported, and enable pause if neither of the pause bits are already set. Signed-off-by: Andrew Lunn [hkallweit1@gmail.com: fixed small checkpatch complaint in one comment] Signed-off-by: Heiner Kallweit --- drivers/net/phy/phy_device.c | 31 +++++++++++++++---------------- include/linux/phy.h | 6 ++++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 92b7a71df..8573d17ec 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2236,7 +2236,14 @@ static int phy_probe(struct device *dev) * a controller will attach, and may modify one * or both of these values */ - linkmode_copy(phydev->supported, phydrv->features); + if (phydrv->features) { + linkmode_copy(phydev->supported, phydrv->features); + } else { + err = phydrv->get_features(phydev); + if (err) + goto out; + } + of_set_phy_supported(phydev); linkmode_copy(phydev->advertising, phydev->supported); @@ -2256,20 +2263,8 @@ static int phy_probe(struct device *dev) * (e.g. hardware erratum) where the driver wants to set only one * of these bits. */ - if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) || - test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) { - linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, - phydev->supported); - linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydev->supported); - if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features)) - linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, - phydev->supported); - if (test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydrv->features)) - linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydev->supported); - } else { + if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) && + !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) { linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, @@ -2315,7 +2310,11 @@ int phy_driver_register(struct phy_driver *new_driver, struct module *owner) { int retval; - if (WARN_ON(!new_driver->features)) { + /* Either the features are hard coded, or dynamically + * determine. It cannot be both or neither + */ + if (WARN_ON((!new_driver->features && !new_driver->get_features) || + (new_driver->features && new_driver->get_features))) { pr_err("%s: Driver features are missing\n", new_driver->name); return -EINVAL; } diff --git a/include/linux/phy.h b/include/linux/phy.h index f41bf651f..d2ffae992 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -502,6 +502,12 @@ struct phy_driver { */ int (*probe)(struct phy_device *phydev); + /* + * Probe the hardware to determine what abilities it has. + * Should only set phydev->supported. + */ + int (*get_features)(struct phy_device *phydev); + /* PHY Power Management */ int (*suspend)(struct phy_device *phydev); int (*resume)(struct phy_device *phydev); -- 2.20.1