From patchwork Tue Mar 7 15:54:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 65675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2520116wrd; Tue, 7 Mar 2023 08:16:49 -0800 (PST) X-Google-Smtp-Source: AK7set+zZ+/Bd/KTyrTBPo13ECk7kMun3tgpZuB7UETWUH/cdFbM8bJXVnlw2QPJIcZMPJqfej3P X-Received: by 2002:a05:6a20:ba88:b0:cc:b0e0:5534 with SMTP id fb8-20020a056a20ba8800b000ccb0e05534mr14922862pzb.60.1678205809076; Tue, 07 Mar 2023 08:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678205809; cv=none; d=google.com; s=arc-20160816; b=AXw78QZ0yTYV9nUirIBHWRSamlOJByltH2bGUyP+RbdA0jLGlqXGqC3ve7odgKxNx6 ecoxRnM93yMw8svsDTB2oAoAwQYq4hovu0AT+8CXjrvsIhM/LRjDyFJ8VuQdGHNdgYru tZrVCVBfItSrrbb+m7CScayVLirtELC3Af6xYdDK+9m9Y05TGwlwrCwdHQPQQd+69ERG NlAisCeIJApmPgLhGwR1Uszyt0d3Cu/m9hwcDu2NECvC/fUjI8wJSDaIpvC/00FWdZtB JELWQrJUgm4auDeYFABQJY97Mb/jS73dJJO0jWh4t7di+Po8PT/cdR3uiHahge50YUQ6 QoUg== 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; bh=ycdKN3sOPwnCSxM804I8obWYzgO8KiBJWKkURO/44Vk=; b=YyreKuRd2mkp3/7d0MZarT24u01v1X6EtY4xQSgBUzeIOWVffA2UkOTbQsmyDkHa0r fCN8ZtYyWy0taFqj2kbPI8hh2wbHrfcP42OtvQasea02Y0H5oImzAeBaR19ro5tV2EP7 FY2Yan+DrCh+iunoS0pUa4ZVbNBvk5IFcQIBZyOzEC6DBnPWqQ/bvPY2FtQRSx5bD+AJ atkrphR7dtruckytLrfkLSJrOv/BiEDrR11FP7vbqnxMWdkbnunXoIu3k/yRGaEqLHN7 h2Z2QDbma3thTL3tgjyU/PrAjih4sB38qd7k1ar6aHdbFqXiTNCJeNmDAgVXj1ieFOQb TyIw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a6566c5000000b004fc2586178dsi12738464pgw.234.2023.03.07.08.16.36; Tue, 07 Mar 2023 08:16:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbjCGP5W (ORCPT + 99 others); Tue, 7 Mar 2023 10:57:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231573AbjCGP4m (ORCPT ); Tue, 7 Mar 2023 10:56:42 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B5D92261; Tue, 7 Mar 2023 07:55:50 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pZZfI-0001s0-2A; Tue, 07 Mar 2023 16:55:48 +0100 Date: Tue, 7 Mar 2023 15:54:11 +0000 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Russell King , Heiner Kallweit , Lorenzo Bianconi , Mark Lee , John Crispin , Felix Fietkau , AngeloGioacchino Del Regno , Matthias Brugger , DENG Qingfang , Landen Chao , Sean Wang , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , Vladimir Oltean , Florian Fainelli , Andrew Lunn , Vladimir Oltean Cc: Jianhui Zhao , =?iso-8859-1?q?Bj=F8rn?= Mork , Frank Wunderlich , Alexander Couzens Subject: [PATCH net-next v12 09/18] net: ethernet: mtk_eth_soc: Fix link status for none-SGMII modes Message-ID: <1590fb0e69f6243ac6a961b16bf7ae7534f46949.1678201958.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759726334493803319?= X-GMAIL-MSGID: =?utf-8?q?1759726334493803319?= Link partner advertised link modes are not reported by the SerDes hardware if not operating in SGMII mode. Hence we cannot use phylink_mii_c22_pcs_decode_state() in this case. Implement reporting link and an_complete only and use speed according to the interface mode. Fixes: 14a44ab0330d ("net: mtk_eth_soc: partially convert to phylink_pcs") Signed-off-by: Daniel Golle Tested-by: Frank Wunderlich --- drivers/net/ethernet/mediatek/mtk_sgmii.c | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_sgmii.c b/drivers/net/ethernet/mediatek/mtk_sgmii.c index 58d8cb3aa7f4..98d80007d3bd 100644 --- a/drivers/net/ethernet/mediatek/mtk_sgmii.c +++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c @@ -23,14 +23,30 @@ static void mtk_pcs_get_state(struct phylink_pcs *pcs, struct phylink_link_state *state) { struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs); - unsigned int bm, adv; + unsigned int bm, bmsr, adv; - /* Read the BMSR and LPA */ + /* Read the BMSR */ regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &bm); - regmap_read(mpcs->regmap, SGMSYS_PCS_ADVERTISE, &adv); + bmsr = FIELD_GET(SGMII_BMSR, bm); - phylink_mii_c22_pcs_decode_state(state, FIELD_GET(SGMII_BMSR, bm), - FIELD_GET(SGMII_LPA, adv)); + /* link partner advertised link modes are not reported by the + * hardware when not operating in SGMII mode. Hence we cannot + * use phylink_mii_c22_pcs_decode_state() in this case. + */ + if (state->interface != PHY_INTERFACE_MODE_SGMII) { + state->link = !!(bmsr & BMSR_LSTATUS); + state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE); + state->speed = (state->interface == + PHY_INTERFACE_MODE_2500BASEX) ? + SPEED_2500 : SPEED_1000; + state->duplex = DUPLEX_FULL; + + return; + } + + /* Read LPA and use standard decode function for SGMII mode */ + regmap_read(mpcs->regmap, SGMSYS_PCS_ADVERTISE, &adv); + phylink_mii_c22_pcs_decode_state(state, bmsr, FIELD_GET(SGMII_LPA, adv)); } static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,