Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp863213rdb; Wed, 6 Dec 2023 01:59:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHO0VBjqxjtoWuKFs6TiYbdKV7Z+YIUGZ881jmS2+A2+w3TWpbsfHbEylffJeDdLDD9Rsz2 X-Received: by 2002:a05:6a20:3d1f:b0:18f:c1e9:cba8 with SMTP id y31-20020a056a203d1f00b0018fc1e9cba8mr673988pzi.106.1701856741109; Wed, 06 Dec 2023 01:59:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701856741; cv=none; d=google.com; s=arc-20160816; b=0Zv0wR5fhHRlWBlgSM2mDlJtVwDBV3Xd6l9G+wpWMLJ6WqoD1Gar7r7r7Na347guqR F9YB4UVYnje1pIr6Ic9ObtNdbTCuuFNJNbQZLhBhLzoGQ2qmOsgg24j9G7Pm2SWgWZQz 8D06yJbXfGXpcbTuTc67UQgyGJ/BvUZTmOaJ6TEtO6zT4WtVc7b5OwNezpCMXeNx4Uj5 g1NyMfmldxamR+rIDjR1xpXKvInFKvBUm1Ytem8yqBbtfi5zzMcurNFdu4+3W6l8rLmn uCZdamUqEQfJFkvY4qLiPNRC8UZO+46pmi9FG9eaEb5ikUb9+pC3PRRR5nO/4EsMEHYO 37NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=dasdfMtvb5/6F6Xl6tXdAQvmSib+B8MTu7AZcbGRRpI=; fh=4XFqYhoFoDZCNTsAMuumPWj6CnGttoVw9HRFMl4668g=; b=Kmx1oIeM6GHbHw3LXmZ3Px8sFxFDOwvNCHyrW56U2Vs2VFweY9sx/gf+Q7dZx0+utp hWoWSVEy+yiv6mV5RHDd3CC46YOQNxvQhnk8dgbKLkULflwvm9A/T3XCH7F+8QLycwUL 2WZsGVMInKpEzCrjfQ5u34lfhqwrvhGUicNm7hP3qGjK/iSRZJ+mdVDiwmjj/k3YrB+1 uZ1d9DdZE5L/is1x7/6LHBfPOxw7KL+ddnaVpUyRvgaWN1+1BOU+Lk8uzqg/u0DppanS us+foYsPyakr3nHlN/uSL2klhRlT0NQOJ+h+yT42Q8jJ37nbFgFNtOrczUMiblfg2gfD KETA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=E4sSHAHN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id a17-20020a656411000000b005c18d508531si7345460pgv.212.2023.12.06.01.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 01:59:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=E4sSHAHN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5442580C2572; Wed, 6 Dec 2023 01:58:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377345AbjLFJ6m (ORCPT + 99 others); Wed, 6 Dec 2023 04:58:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377306AbjLFJ6l (ORCPT ); Wed, 6 Dec 2023 04:58:41 -0500 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66CFFFA; Wed, 6 Dec 2023 01:58:46 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3BB97240008; Wed, 6 Dec 2023 09:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1701856724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dasdfMtvb5/6F6Xl6tXdAQvmSib+B8MTu7AZcbGRRpI=; b=E4sSHAHNbk/P25tK9GlNW898yfNEPsTTCpuSOrvNg3FDLAQa5H2MB8BRBjjdZkmc8iyIaA b6odeZBloX3O6K431Gft6l8bCm/hcnvr2+z/XM6Lahwsh4AtTFk85mbSpf7X6rzHKvMVt6 3umP9OEFpwaUVhEVEAcTVj0ieLjeJiNgKnvgJ0VctBblzzer+uzeuVxsOuDH5U9LF9cI2Q zzti/EjMfrFKZsIUnuinTx9zodpPb9o4h+HfB7PROhWn5RHP3LpKUYtFXinRhxwNKJWX1+ /fEfRmLP4XlanmKXIT1XLFJfuEOYBwF14EvjJt38ClTdAVVQVxjpVi8R93acjg== Date: Wed, 6 Dec 2023 10:58:38 +0100 From: Maxime Chevallier To: Daniel Golle Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chunfeng Yun , Vinod Koul , Kishon Vijay Abraham I , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Andrew Lunn , Heiner Kallweit , Russell King , Alexander Couzens , Qingfang Deng , SkyLake Huang , Philipp Zabel , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org Subject: Re: [RFC PATCH v2 5/8] net: pcs: add driver for MediaTek USXGMII PCS Message-ID: <20231206105838.069ae288@device.home> In-Reply-To: <3cd8af5e44554c2db2d7898494ee813967206bd9.1701826319.git.daniel@makrotopia.org> References: <3cd8af5e44554c2db2d7898494ee813967206bd9.1701826319.git.daniel@makrotopia.org> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-GND-Sasl: maxime.chevallier@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 01:58:58 -0800 (PST) Hello Daniel, On Wed, 6 Dec 2023 01:44:38 +0000 Daniel Golle wrote: > Add driver for USXGMII PCS found in the MediaTek MT7988 SoC and supporting > USXGMII, 10GBase-R and 5GBase-R interface modes. In order to support > Cisco SGMII, 1000Base-X and 2500Base-X via the also present LynxI PCS > create a wrapped PCS taking care of the components shared between the > new USXGMII PCS and the legacy LynxI PCS. > > Signed-off-by: Daniel Golle > --- [...] > + > +static int mtk_usxgmii_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, > + phy_interface_t interface, > + const unsigned long *advertising, > + bool permit_pause_to_mac) > +{ > + struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs); > + unsigned int an_ctrl = 0, link_timer = 0, xfi_mode = 0, adapt_mode = 0; > + bool mode_changed = false; Reverse christmas tree ordering can be used here (longest lines first) > + > + if (interface == PHY_INTERFACE_MODE_USXGMII) { > + an_ctrl = FIELD_PREP(USXGMII_AN_SYNC_CNT, 0x1FF) | USXGMII_AN_ENABLE; > + link_timer = FIELD_PREP(USXGMII_LINK_TIMER_IDLE_DETECT, 0x7B) | > + FIELD_PREP(USXGMII_LINK_TIMER_COMP_ACK_DETECT, 0x7B) | > + FIELD_PREP(USXGMII_LINK_TIMER_AN_RESTART, 0x7B); > + xfi_mode = FIELD_PREP(USXGMII_XFI_RX_MODE, USXGMII_XFI_MODE_10G) | > + FIELD_PREP(USXGMII_XFI_TX_MODE, USXGMII_XFI_MODE_10G); > + } else if (interface == PHY_INTERFACE_MODE_10GBASER) { > + an_ctrl = FIELD_PREP(USXGMII_AN_SYNC_CNT, 0x1FF); > + link_timer = FIELD_PREP(USXGMII_LINK_TIMER_IDLE_DETECT, 0x7B) | > + FIELD_PREP(USXGMII_LINK_TIMER_COMP_ACK_DETECT, 0x7B) | > + FIELD_PREP(USXGMII_LINK_TIMER_AN_RESTART, 0x7B); > + xfi_mode = FIELD_PREP(USXGMII_XFI_RX_MODE, USXGMII_XFI_MODE_10G) | > + FIELD_PREP(USXGMII_XFI_TX_MODE, USXGMII_XFI_MODE_10G); > + adapt_mode = USXGMII_RATE_UPDATE_MODE; > + } else if (interface == PHY_INTERFACE_MODE_5GBASER) { > + an_ctrl = FIELD_PREP(USXGMII_AN_SYNC_CNT, 0xFF); > + link_timer = FIELD_PREP(USXGMII_LINK_TIMER_IDLE_DETECT, 0x3D) | > + FIELD_PREP(USXGMII_LINK_TIMER_COMP_ACK_DETECT, 0x3D) | > + FIELD_PREP(USXGMII_LINK_TIMER_AN_RESTART, 0x3D); > + xfi_mode = FIELD_PREP(USXGMII_XFI_RX_MODE, USXGMII_XFI_MODE_5G) | > + FIELD_PREP(USXGMII_XFI_TX_MODE, USXGMII_XFI_MODE_5G); > + adapt_mode = USXGMII_RATE_UPDATE_MODE; > + } else { > + return -EINVAL; > + } > + > + adapt_mode |= FIELD_PREP(USXGMII_RATE_ADAPT_MODE, USXGMII_RATE_ADAPT_MODE_X1); > + > + if (mpcs->interface != interface) { > + mpcs->interface = interface; > + mode_changed = true; > + } > + > + mtk_usxgmii_reset(mpcs); > + > + /* Setup USXGMII AN ctrl */ > + mtk_m32(mpcs, RG_PCS_AN_CTRL0, > + USXGMII_AN_SYNC_CNT | USXGMII_AN_ENABLE, > + an_ctrl); > + > + mtk_m32(mpcs, RG_PCS_AN_CTRL2, > + USXGMII_LINK_TIMER_IDLE_DETECT | > + USXGMII_LINK_TIMER_COMP_ACK_DETECT | > + USXGMII_LINK_TIMER_AN_RESTART, > + link_timer); > + > + mpcs->neg_mode = neg_mode; > + > + /* Gated MAC CK */ > + mtk_m32(mpcs, RG_PHY_TOP_SPEED_CTRL1, > + USXGMII_MAC_CK_GATED, USXGMII_MAC_CK_GATED); > + > + /* Enable interface force mode */ > + mtk_m32(mpcs, RG_PHY_TOP_SPEED_CTRL1, > + USXGMII_IF_FORCE_EN, USXGMII_IF_FORCE_EN); > + > + /* Setup USXGMII adapt mode */ > + mtk_m32(mpcs, RG_PHY_TOP_SPEED_CTRL1, > + USXGMII_RATE_UPDATE_MODE | USXGMII_RATE_ADAPT_MODE, > + adapt_mode); > + > + /* Setup USXGMII speed */ > + mtk_m32(mpcs, RG_PHY_TOP_SPEED_CTRL1, > + USXGMII_XFI_RX_MODE | USXGMII_XFI_TX_MODE, > + xfi_mode); > + > + usleep_range(1, 10); > + > + /* Un-gated MAC CK */ > + mtk_m32(mpcs, RG_PHY_TOP_SPEED_CTRL1, USXGMII_MAC_CK_GATED, 0); > + > + usleep_range(1, 10); > + > + /* Disable interface force mode for the AN mode */ > + if (an_ctrl & USXGMII_AN_ENABLE) > + mtk_m32(mpcs, RG_PHY_TOP_SPEED_CTRL1, USXGMII_IF_FORCE_EN, 0); > + > + return mode_changed; > +} > + [...] > +static void mtk_usxgmii_pcs_get_state(struct phylink_pcs *pcs, > + struct phylink_link_state *state) > +{ > + struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs); > + > + /* Refresh USXGMII link status by toggling RG_PCS_AN_STATUS_UPDATE */ > + mtk_m32(mpcs, RG_PCS_RX_STATUS0, RG_PCS_RX_STATUS_UPDATE, > + RG_PCS_RX_STATUS_UPDATE); > + ndelay(1020); > + mtk_m32(mpcs, RG_PCS_RX_STATUS0, RG_PCS_RX_STATUS_UPDATE, 0); > + ndelay(1020); > + > + /* Read USXGMII link status */ > + state->link = FIELD_GET(RG_PCS_RX_LINK_STATUS, > + mtk_r32(mpcs, RG_PCS_RX_STATUS0)); > + > + /* Continuously repeat re-configuration sequence until link comes up */ > + if (!state->link) { > + mtk_usxgmii_pcs_config(pcs, mpcs->neg_mode, > + state->interface, NULL, false); > + return; .pcs_get_state() isn't called only for link state polling,but also when querying the link state from ethtool, from phylink_ethtool_ksettings_get(). As mtk_usxgmii_pcs_config triggers a pcs reset and reconfiguration, won't this disrupt the link ? Thanks, Maxime