Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13341835rwd; Fri, 23 Jun 2023 21:31:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48TYc1WKkzyU6KjKq3iiWnX9T0iW5mf0luZZ42cy435u9HZ5+Gb0mcEUx+VT2ISVcTeU/8 X-Received: by 2002:a9d:6195:0:b0:6b7:1615:6d77 with SMTP id g21-20020a9d6195000000b006b716156d77mr5827704otk.17.1687581079950; Fri, 23 Jun 2023 21:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687581079; cv=none; d=google.com; s=arc-20160816; b=gtMOWOUVU9A15lPc8S6Dd7xlfC7B0j5HUtJmQ1Ut88BWHnrcp/m5IKJW9zvQMfSBAy 5D3MKKzfMrJVjaUVkXGxRCcwwJ/TVtrzCE0ewJL0lx1q5HFctnGrh/7h7KvTin9WQprz CY7LgLAO9COapFOEDdmHuRnw6nJOadpEQKLVqh38n18iCz9wUHbGVG4EtYkpLeRPVwd/ HfmBRW952OJmjEpS6YceHmlHIGsZKh/QPp5DJY1m+auU9lfr8wfET3JnauLZsgucPi1B MOu7HzxJBut+Wq/b8hmJ0BIbGKnl2wuvOdFYtV18yf7Y9OutdXIRbPKm0H5MPiWsWtuw nUeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=PCuh9aSXjoK8r6/sTg/D9QolCTlKGcoEEAFlcSDn2ec=; fh=ekD3W4z+VZQ+OcuxFengpzw2vXLZn1illsV/zdnh+BU=; b=JjglLpTEZNXiEIAqKZDNsNPcmbJF07S5bAwjQmjxv6TKG7tZ5vd0YOjOiC7KjlT9nm Ivm60gdYkLSmF10PldeW0zSHQ18QMcg0TK6/Aj1Ne/EbyK39K0hLG1tq3dxTPQorILQS bvG/ToGGXQo4JEPS1+ws0AY9KUR2YxjmHhDhmojuoxWz99LVpM+idYcHFwR729pT9GNw ZnWCgLsdWJrOsxHffEvSrt8Pjn5rYef6f695aFLtIXJIouFY8YP8BOfxPUqCVRzeeCbT +Xx+Bns9IFHGIYmy21skZxqT0LKO8CcSNarZVIWCi8wEwC06PORqHuH5KE35RcAM+coJ OvOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="oor0mh/5"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij8-20020a170902ab4800b001b52e5751c8si632770plb.102.2023.06.23.21.31.03; Fri, 23 Jun 2023 21:31:19 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20221208 header.b="oor0mh/5"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbjFXECm (ORCPT + 99 others); Sat, 24 Jun 2023 00:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjFXECl (ORCPT ); Sat, 24 Jun 2023 00:02:41 -0400 Received: from mail-vs1-xe34.google.com (mail-vs1-xe34.google.com [IPv6:2607:f8b0:4864:20::e34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA591E5D; Fri, 23 Jun 2023 21:02:39 -0700 (PDT) Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-440b66adc81so497594137.1; Fri, 23 Jun 2023 21:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687579359; x=1690171359; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PCuh9aSXjoK8r6/sTg/D9QolCTlKGcoEEAFlcSDn2ec=; b=oor0mh/5vd4dlbNE/ceGHvKqW1/K/usscKJafysxBp0tZfDdnty1iJFYvDJTKDewzA KM5/9GpiMpdSpk0cTzc7FSkAhVt52BkL4JiSZgtgwqBNuhjrQnyM1G+52btiFT+GtXJC FJCW1EVLeFFw4zyEH9QUExqsiTSvSrTP93IyfwVrGTKVgsXfwKl3HzFatm6OL36kQYZd OEWZlQMsnvkLNzawFOFaDMgkeEeDJZWvbpCeUstUde5trH59QT42ueb3tbwQpQntAnn0 XQ9JKwCDpgTdlgbRfHYYcQWOzdx9Lo1o13gByosoLZyTN1S6N9NRTkWVa3IQmUd5L3X8 SYnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687579359; x=1690171359; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PCuh9aSXjoK8r6/sTg/D9QolCTlKGcoEEAFlcSDn2ec=; b=hb4Rhtjt8oF1CQXdshpr6+hoeMjFk+axC8O+14isH1oGa2kXdFYEGytDdNOd4JxzE2 qu/6/Nt0L62kDmNkgKkxcIzZSWdzvQy+fcmKn/7LBGajbEY8XcyaLcIKhkrkTKlOjmEH Oe+DR7XBwFNuytY8sro71/fBHN1sI7JllhV4D7Jn5Gf15ZaBY3eHO4DYTVCv7IPwMYJl WKlmlS9HiErNNwqdz6H8nu9V78+4B/hoQrHnGCQvJdSxPvRzZlO1XcUcc7zuX+Qz6U4w tadr+L9WJKMXc7eYrzguuVvMnq1cLTdgtNrlarG4PdKNqpN+8TUWQTWnNI+xuRqkr77Y DkPw== X-Gm-Message-State: AC+VfDxchKWCFqr+lBNIXzYbCmYjwq+h2hZhzcF6WgVZGdMyzsB1GrzM uWLIqyQkLIbBmhRTmQL/A6GWToJHWEM6cGavOlg= X-Received: by 2002:a67:de81:0:b0:43f:4714:a03b with SMTP id r1-20020a67de81000000b0043f4714a03bmr12195580vsk.17.1687579358722; Fri, 23 Jun 2023 21:02:38 -0700 (PDT) MIME-Version: 1.0 References: <20230621191302.1405623-1-paweldembicki@gmail.com> In-Reply-To: From: =?UTF-8?Q?Pawe=C5=82_Dembicki?= Date: Sat, 24 Jun 2023 06:02:27 +0200 Message-ID: Subject: Re: [PATCH net-next 1/6] net: dsa: vsc73xx: convert to PHYLINK To: "Russell King (Oracle)" Cc: netdev@vger.kernel.org, linus.walleij@linaro.org, Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 czw., 22 cze 2023 o 13:55 Russell King (Oracle) napisa=C5=82(a): > > On Wed, Jun 21, 2023 at 09:12:56PM +0200, Pawel Dembicki wrote: > > + /* This driver does not make use of the speed, duplex, pause or t= he > > + * advertisement in its mac_config, so it is safe to mark this dr= iver > > + * as non-legacy. > > + */ > > + config->legacy_pre_march2020 =3D false; > > Great stuff, thanks! > > > +static void vsc73xx_phylink_mac_config(struct dsa_switch *ds, int port= , > > + unsigned int mode, > > + const struct phylink_link_state *s= tate) > > +{ > > + struct vsc73xx *vsc =3D ds->priv; > > Nit: normally have a blank line between function variable declarations > and the rest of the function body. > > > /* Special handling of the CPU-facing port */ > > if (port =3D=3D CPU_PORT) { > > /* Other ports are already initialized but not this one *= / > > @@ -775,104 +803,92 @@ static void vsc73xx_adjust_link(struct dsa_switc= h *ds, int port, > > VSC73XX_ADVPORTM_ENA_GTX | > > VSC73XX_ADVPORTM_DDR_MODE); > > } > > +} > > > > - /* This is the MAC confiuration that always need to happen > > - * after a PHY or the CPU port comes up or down. > > - */ > > - if (!phydev->link) { > > - int maxloop =3D 10; > > +static void vsc73xx_phylink_mac_link_down(struct dsa_switch *ds, int p= ort, > > + unsigned int mode, > > + phy_interface_t interface) > > +{ > > + struct vsc73xx *vsc =3D ds->priv; > > + u32 val; > > > > - dev_dbg(vsc->dev, "port %d: went down\n", > > - port); > > + int maxloop =3D VSC73XX_TABLE_ATTEMPTS; > > Reverse christmas-tree for variable declarations, and there shouldn't > be a blank line between them. In any case, I don't think you need > "maxloop" if you adopt my suggestion below. > > > > > - /* Disable RX on this port */ > > - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, > > - VSC73XX_MAC_CFG, > > - VSC73XX_MAC_CFG_RX_EN, 0); > > + dev_dbg(vsc->dev, "port %d: went down\n", > > + port); > > > > - /* Discard packets */ > > - vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, > > - VSC73XX_ARBDISC, BIT(port), BIT(port)= ); > > + /* Disable RX on this port */ > > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, > > + VSC73XX_MAC_CFG, > > + VSC73XX_MAC_CFG_RX_EN, 0); > > + > > + /* Discard packets */ > > + vsc73xx_update_bits(vsc, VSC73XX_BLOCK_ARBITER, 0, > > + VSC73XX_ARBDISC, BIT(port), BIT(port)); > > > > - /* Wait until queue is empty */ > > + /* Wait until queue is empty */ > > + vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, > > + VSC73XX_ARBEMPTY, &val); > > + while (!(val & BIT(port))) { > > + msleep(1); > > vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, > > VSC73XX_ARBEMPTY, &val); > > - while (!(val & BIT(port))) { > > - msleep(1); > > - vsc73xx_read(vsc, VSC73XX_BLOCK_ARBITER, 0, > > - VSC73XX_ARBEMPTY, &val); > > - if (--maxloop =3D=3D 0) { > > - dev_err(vsc->dev, > > - "timeout waiting for block arbite= r\n"); > > - /* Continue anyway */ > > - break; > > - } > > + if (--maxloop =3D=3D 0) { > > + dev_err(vsc->dev, > > + "timeout waiting for block arbiter\n"); > > + /* Continue anyway */ > > + break; > > } > > + } > > I know you're only moving this code, but I think it would be good to > _first_ have a patch that fixes this polling function: > > int ret, err; > ... > ret =3D read_poll_timeout(vsc73xx_read, err, > err < 0 || (val & BIT(port)), > 1000, 10000, false, > vsc, VSC73XX_BLOCK_ARBITER, 0, > VSC73XX_ARBEMPTY, &val); > if (ret !=3D 0) > dev_err(vsc->dev, > "timeout waiting for block arbiter\n"); > else if (err < 0) > dev_err(vsc->dev, > "error reading arbiter\n"); > > This avoids the issue that on the last iteration, the code reads the > register, test it, find the condition that's being waiting for is > false, _then_ waits and end up printing the error message - that last > wait is rather useless, and as the arbiter state isn't checked after > waiting, it could be that we had success during the last wait. > Thank you for the tips. I will prepare additional commit in v2 series. > > +static void vsc73xx_phylink_mac_link_up(struct dsa_switch *ds, int por= t, > > + unsigned int mode, > > + phy_interface_t interface, > > + struct phy_device *phydev, > > + int speed, int duplex, > > + bool tx_pause, bool rx_pause) > > +{ > > + struct vsc73xx *vsc =3D ds->priv; > > + u32 val; > > > > + switch (speed) { > > + case SPEED_1000: > > /* Set up default for internal port or external RGMII */ > > - if (phydev->interface =3D=3D PHY_INTERFACE_MODE_RGMII) > > + if (interface =3D=3D PHY_INTERFACE_MODE_RGMII) > > val =3D VSC73XX_MAC_CFG_1000M_F_RGMII; > > else > > val =3D VSC73XX_MAC_CFG_1000M_F_PHY; > > - vsc73xx_adjust_enable_port(vsc, port, phydev, val); > > - } else if (phydev->speed =3D=3D SPEED_100) { > > - if (phydev->duplex =3D=3D DUPLEX_FULL) { > > - val =3D VSC73XX_MAC_CFG_100_10M_F_PHY; > > - dev_dbg(vsc->dev, > > - "port %d: 100 Mbit full duplex mode\n", > > - port); > > - } else { > > - val =3D VSC73XX_MAC_CFG_100_10M_H_PHY; > > - dev_dbg(vsc->dev, > > - "port %d: 100 Mbit half duplex mode\n", > > - port); > > - } > > - vsc73xx_adjust_enable_port(vsc, port, phydev, val); > > - } else if (phydev->speed =3D=3D SPEED_10) { > > - if (phydev->duplex =3D=3D DUPLEX_FULL) { > > + break; > > + case SPEED_100: > > + case SPEED_10: > > + if (duplex =3D=3D DUPLEX_FULL) > > val =3D VSC73XX_MAC_CFG_100_10M_F_PHY; > > - dev_dbg(vsc->dev, > > - "port %d: 10 Mbit full duplex mode\n", > > - port); > > - } else { > > + else > > val =3D VSC73XX_MAC_CFG_100_10M_H_PHY; > > - dev_dbg(vsc->dev, > > - "port %d: 10 Mbit half duplex mode\n", > > - port); > > - } > > - vsc73xx_adjust_enable_port(vsc, port, phydev, val); > > - } else { > > - dev_err(vsc->dev, > > - "could not adjust link: unknown speed\n"); > > + break; > > } > > Do the dev_dbg() add anything useful over what phylink prints when the > link comes up? > > I don't think moving to a switch() statement for this is a good idea. > Given that "val" may be uninitialised, I suspect the following may be > a better solution: > > if (speed =3D=3D SPEED_1000 || speed =3D=3D SPEED_100 || speed = =3D=3D SPEED_10) { > if (speed =3D=3D SPEED_1000) { > ... > } else { > ... > } > > ... set VSC73XX_BLOCK_ANALYZER and call > vsc73xx_adjust_enable_port ... > } > > However, looking at the definitions of the various macros, it seems we > can do a little better by not using the VSC73XX_MAC_CFG_*M_[FH]_* > definitions: > > if (speed =3D=3D SPEED_1000) { > val =3D VSC73XX_MAC_CFG_GIGA_MODE | > VSC73XX_MAC_CFG_TX_IPG_1000M; > > if (interface =3D=3D PHY_INTERFACE_MODE_RGMII) > val |=3D VSC73XX_MAC_CFG_CLK_SEL_1000M; > else > val |=3D VSC73XX_MAC_CFG_CLK_SEL_EXT; > } else { > val =3D VSC73XX_MAC_CFG_TX_IPG_100_10M | > VSC73XX_MAC_CFG_CLK_SEL_EXT; > } > > if (duplex =3D=3D DUPLEX_FULL) > val |=3D VSC73XX_MAC_CFG_FDX; > > Now, this reveals a question: when operating in RGMII mode, why do we > need VSC73XX_MAC_CFG_CLK_SEL_1000M for 1G, and > VSC73XX_MAC_CFG_CLK_SEL_EXT for 10M and 100M, whereas "PHY" mode always > uses CLK_SEL_EXT ? > VSC73XX_MAC_CFG_CLK_SEL_EXT should be used always when phy is used, no matter what speed is. VSC73XX_MAC_CFG_CLK_SEL_1000M in RGMII mode. It can be even more simplified: if (speed =3D=3D SPEED_1000) val =3D VSC73XX_MAC_CFG_GIGA_MODE | VSC73XX_MAC_CFG_TX_IPG_1000M; else val =3D VSC73XX_MAC_CFG_TX_IPG_100_10M; if (interface =3D=3D PHY_INTERFACE_MODE_RGMII) val |=3D VSC73XX_MAC_CFG_CLK_SEL_1000M; else val |=3D VSC73XX_MAC_CFG_CLK_SEL_EXT; if (duplex =3D=3D DUPLEX_FULL) val |=3D VSC73XX_MAC_CFG_FDX; -- Pawel Dembicki