Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1644884pxb; Fri, 22 Oct 2021 05:10:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1wUr8WP5Aaw9qP/WEhITMu1mHAgGwu7Cx4k5LE06PyzzM/Pk8IVnhIg/QQ+yaYk/KnuGx X-Received: by 2002:a05:6402:891:: with SMTP id e17mr16697234edy.81.1634904634385; Fri, 22 Oct 2021 05:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634904634; cv=none; d=google.com; s=arc-20160816; b=FwxGP1VUB0Yju+meg3GCGHT2Wop2dPOfaUojD0Mq/+PzcyEDtVGfzvAI1kdj9QdbwX HDrS98TtpN6D8hOsDOXj13ihicSLESbQoVCRG1pYYmF2TRhCH/P+0jZrmJeE+ZJuHlXP YsX9FhDOkksSi0J4t/wHbVDbR9AUIixjul1QjVuLjyJg7K4ruuaCc2aCSz4NiJmwSAe4 XFzutjO2vjwOLME6EAFhkXhvjqxUDopQKrxziMdHr4enOHGSmgTfHZ/1qU/9JOOOFfoB jmudR6qMAAffvOZf+D5vgqhAjhtYMKLLAaJcYT7UzXbuS/HPvXIajCXDFIQoe2SFAWwp PZHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dmarc-filter:sender:dkim-signature; bh=udjfCplsA+/erjKFZrONey8j9k/1hCXKa9nQxxquIP4=; b=GCvbGzTOKv2qXakTgt8HEObq+h5XcbGe1QR4uHQeriKpUCtEIbqD4Sd5+trT++IND5 LY9WJ8x1r7fYhqgZiiX4nI6OF5k6WTZBz2PGa0dqSOKVQsbQEaTiG/WgErMZ6p8FSnKd SFed1hwYia3xdO2lpPGeVE+Dn3WJNBYK1+lvZqFNtvyaDA188poKKrjWOR7i63M5uZRX eGXl7qt4Ru5LSWNdZiX6eb/Hv0mddX7e+gvnZsZIq6cQoBps+hfkg406qdQmPz2jEhO1 QR/QWKXiytn/S/3NC802LxjMw0+7334cBV3VpTTKV4z76YGjWlsmM026BmkzTcwvFEPi Hmyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="M/bmHKst"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si11421549edf.22.2021.10.22.05.10.02; Fri, 22 Oct 2021 05:10:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="M/bmHKst"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232500AbhJVMJo (ORCPT + 99 others); Fri, 22 Oct 2021 08:09:44 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:60693 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231482AbhJVMJ0 (ORCPT ); Fri, 22 Oct 2021 08:09:26 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1634904429; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=udjfCplsA+/erjKFZrONey8j9k/1hCXKa9nQxxquIP4=; b=M/bmHKst/GltUvvsOZQQX0bHo3T3SypNTe0cigcmVhKC1meOZEoqDbqc0FPzHaeabXNgmUeH n5YS8cZ/RS4lnUHtHacltKo0gVNTbfG+mj/udF0ptZXA4rICw7LY4IFKttfj5U+4ivwSPSvF RU/gK/mtxnA04CWLwBKr5blwlaI= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 6172a95d67f107c611a3b3e8 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 22 Oct 2021 12:06:53 GMT Sender: luoj=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id D3B57C43617; Fri, 22 Oct 2021 12:06:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from akronite-sh-dev02.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: luoj) by smtp.codeaurora.org (Postfix) with ESMTPSA id 10D36C43618; Fri, 22 Oct 2021 12:06:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 smtp.codeaurora.org 10D36C43618 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=codeaurora.org From: Luo Jie To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, sricharan@codeaurora.org, Luo Jie Subject: [PATCH v4 06/14] net: phy: add qca8081 read_status Date: Fri, 22 Oct 2021 20:06:16 +0800 Message-Id: <20211022120624.18069-7-luoj@codeaurora.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022120624.18069-1-luoj@codeaurora.org> References: <20211022120624.18069-1-luoj@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1. Separate the function at803x_read_specific_status from the at803x_read_status, since it can be reused by the read_status of qca8081 phy driver excepting adding the 2500M speed. 2. Add the qca8081 read_status function qca808x_read_status. Signed-off-by: Luo Jie --- drivers/net/phy/at803x.c | 95 ++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 22 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index 460881320ebb..738f5a84cca6 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -41,6 +41,9 @@ #define AT803X_SS_SPEED_DUPLEX_RESOLVED BIT(11) #define AT803X_SS_MDIX BIT(6) +#define QCA808X_SS_SPEED_MASK GENMASK(9, 7) +#define QCA808X_SS_SPEED_2500 4 + #define AT803X_INTR_ENABLE 0x12 #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15) #define AT803X_INTR_ENABLE_SPEED_CHANGED BIT(14) @@ -951,27 +954,9 @@ static void at803x_link_change_notify(struct phy_device *phydev) } } -static int at803x_read_status(struct phy_device *phydev) +static int at803x_read_specific_status(struct phy_device *phydev) { - int ss, err, old_link = phydev->link; - - /* Update the link, but return if there was an error */ - err = genphy_update_link(phydev); - if (err) - return err; - - /* why bother the PHY if nothing can have changed */ - if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) - return 0; - - phydev->speed = SPEED_UNKNOWN; - phydev->duplex = DUPLEX_UNKNOWN; - phydev->pause = 0; - phydev->asym_pause = 0; - - err = genphy_read_lpa(phydev); - if (err < 0) - return err; + int ss; /* Read the AT8035 PHY-Specific Status register, which indicates the * speed and duplex that the PHY is actually using, irrespective of @@ -982,13 +967,19 @@ static int at803x_read_status(struct phy_device *phydev) return ss; if (ss & AT803X_SS_SPEED_DUPLEX_RESOLVED) { - int sfc; + int sfc, speed; sfc = phy_read(phydev, AT803X_SPECIFIC_FUNCTION_CONTROL); if (sfc < 0) return sfc; - switch (FIELD_GET(AT803X_SS_SPEED_MASK, ss)) { + /* qca8081 takes the different bits for speed value from at803x */ + if (phydev->drv->phy_id == QCA8081_PHY_ID) + speed = FIELD_GET(QCA808X_SS_SPEED_MASK, ss); + else + speed = FIELD_GET(AT803X_SS_SPEED_MASK, ss); + + switch (speed) { case AT803X_SS_SPEED_10: phydev->speed = SPEED_10; break; @@ -998,6 +989,9 @@ static int at803x_read_status(struct phy_device *phydev) case AT803X_SS_SPEED_1000: phydev->speed = SPEED_1000; break; + case QCA808X_SS_SPEED_2500: + phydev->speed = SPEED_2500; + break; } if (ss & AT803X_SS_DUPLEX) phydev->duplex = DUPLEX_FULL; @@ -1022,6 +1016,35 @@ static int at803x_read_status(struct phy_device *phydev) } } + return 0; +} + +static int at803x_read_status(struct phy_device *phydev) +{ + int err, old_link = phydev->link; + + /* Update the link, but return if there was an error */ + err = genphy_update_link(phydev); + if (err) + return err; + + /* why bother the PHY if nothing can have changed */ + if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) + return 0; + + phydev->speed = SPEED_UNKNOWN; + phydev->duplex = DUPLEX_UNKNOWN; + phydev->pause = 0; + phydev->asym_pause = 0; + + err = genphy_read_lpa(phydev); + if (err < 0) + return err; + + err = at803x_read_specific_status(phydev); + if (err < 0) + return err; + if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) phy_resolve_aneg_pause(phydev); @@ -1341,6 +1364,33 @@ static int qca83xx_config_init(struct phy_device *phydev) return 0; } +static int qca808x_read_status(struct phy_device *phydev) +{ + int ret; + + ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT); + if (ret < 0) + return ret; + + linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising, + ret & MDIO_AN_10GBT_STAT_LP2_5G); + + ret = genphy_read_status(phydev); + if (ret) + return ret; + + ret = at803x_read_specific_status(phydev); + if (ret < 0) + return ret; + + if (phydev->link && phydev->speed == SPEED_2500) + phydev->interface = PHY_INTERFACE_MODE_2500BASEX; + else + phydev->interface = PHY_INTERFACE_MODE_SMII; + + return 0; +} + static struct phy_driver at803x_driver[] = { { /* Qualcomm Atheros AR8035 */ @@ -1494,6 +1544,7 @@ static struct phy_driver at803x_driver[] = { .get_wol = at803x_get_wol, .suspend = genphy_suspend, .resume = genphy_resume, + .read_status = qca808x_read_status, }, }; module_phy_driver(at803x_driver); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project