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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 563C7CD5BDF for ; Wed, 25 Sep 2024 13:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cIRGXiqbpCwHel3eJFGrUBbElkNnKUDcIxPay6UwVps=; b=cOcD95ZIYPQ+P9S6CP0v9I2C4b E2VVAC37qnGz1t75H0ArMz/LL8kruOZSeSHpj4N2JtHtv5ShOBgS/ZTJbhl1j0UeVA1oXAsqlXpbx 6UPBoPVRRmhXmlnGOo4HgkAUl6l96gq9Z/cXaioRI71bEn/ZUTDOX6fJXZcOs+YaJGeaRIIQkyx8s dsfy5tbBMNO71tY9lrdX7MflgHHmCs0t2CTjLZpw0r3q9TvXdUKADWZB1n3crsCNMFlkRZ4kiZLNY K10YTzdjc8g6F+q+zu2aRAl2o91xm2U+OUPdmhlRl2nAjPwDazxiLHIE7hOviHrhgUZLsZ1QzqgZt cD7rnlKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stRt3-00000005KN0-1LBS; Wed, 25 Sep 2024 13:16:57 +0000 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stRrW-00000005K0T-1YE3 for linux-arm-kernel@lists.infradead.org; Wed, 25 Sep 2024 13:15:23 +0000 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c5b6069cabso764857a12.0 for ; Wed, 25 Sep 2024 06:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727270121; x=1727874921; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cIRGXiqbpCwHel3eJFGrUBbElkNnKUDcIxPay6UwVps=; b=KHB+GuGunbXfkBnUD0Eln8FPYvjKu7qudvoQFQFdeBGJJ4JVlnbrpOULJThJosFsUM mD3FqtFNZRaK6Z6AzhzrzuSednceXi+mCHj45gauBykbsAT5mVV2h5K+YmDsMbmo5uHf atLOwpYLBg5LR56wlSKrsUO1FGiF5CVZ7hkMYBC5rJhG5x3fiLo5GKfF2ncQ6+HkrpG/ iqVtoYb66s84WIvaLrLZOgjYKLDdrrr+LJlYLD89246TAySi9o8LU77RImOdZbaj8Skh tHFZF6QRG1/8w0lFVHOl2u02Ik0ftSTpbbnj2v1qFGwsQJinKR1yZln0E9Y1i/nsxLX+ 7+Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727270121; x=1727874921; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cIRGXiqbpCwHel3eJFGrUBbElkNnKUDcIxPay6UwVps=; b=CpxXB9Ux+4iUWZD2MSZOmt8j6wmTNTghkQEy8koXJ7mGJX0Tdk48kaJUJv91qJqUPg TTqB3EKvT6jfRoXyG4YB35n8/ZSU+oI/7XwOHGjnlrLPYXXYXqgovpFTF3i45UtmXKPJ /jaLqmCY/IfMwYVczTfvgNTa+KF0uw7gSRWxGAawotjWwueFjF9n8PaOAmakfMRP0J91 2EEGz4Wg96alCfHH8Adh310veMiJtn1XLTHe0dAcYrqZ3loohfRrEIvpeljTOZGhyJzp nSXJXYod5cW02/33KgaLKhZHQgWrgvFZLRK7NIHbcvaKNQPB3iurBWae1aZECAaJ6anz s8vw== X-Forwarded-Encrypted: i=1; AJvYcCXleyV6Eso1WbGe2KHkHrppasCodOVPEy/qu3BN25YXUogub84B7NV4FTs08wZ/r2l35d/bgwLL9ZCK+elQnl9/@lists.infradead.org X-Gm-Message-State: AOJu0YxPZVmHpmUnAcTvUW6Kj3dmTZ2RkDlNXA/G4mWHkQT/4X/9ybzJ jxIEHw3QVumCZ9ZPhcCBctADUZ8UhMYqKzM31a+YOH+6mpSck7m1 X-Google-Smtp-Source: AGHT+IHPosmiTyDgIhqNvtBau0LzG3wa4V86DjV0jr65QSkropiwCmtHnOleQT5i1l2q4KClBF+Opw== X-Received: by 2002:a17:907:3f96:b0:a80:a294:f8a with SMTP id a640c23a62f3a-a93a035c2c6mr115963566b.1.1727270120189; Wed, 25 Sep 2024 06:15:20 -0700 (PDT) Received: from skbuf ([188.25.134.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93930f787dsm205784366b.157.2024.09.25.06.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 06:15:19 -0700 (PDT) Date: Wed, 25 Sep 2024 16:15:17 +0300 From: Vladimir Oltean To: "Russell King (Oracle)" Cc: Andrew Lunn , Heiner Kallweit , Alexandre Torgue , "David S. Miller" , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Jiawen Wu , Jose Abreu , Jose Abreu , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Maxime Coquelin , Mengyuan Lou , netdev@vger.kernel.org, Paolo Abeni Subject: Re: [PATCH RFC net-next 06/10] net: dsa: sja1105: simplify static configuration reload Message-ID: <20240925131517.s562xmc5ekkslkhp@skbuf> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240925_061522_436638_89658934 X-CRM114-Status: GOOD ( 42.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Sep 23, 2024 at 03:01:25PM +0100, Russell King (Oracle) wrote: > The static configuration reload saves the port speed in the static > configuration tables by first converting it from the internal > respresentation to the SPEED_xxx ethtool representation, and then > converts it back to restore the setting. This is because > sja1105_adjust_port_config() takes the speed as SPEED_xxx. > > However, this is unnecessarily complex. If we split > sja1105_adjust_port_config() up, we can simply save and restore the > mac[port].speed member in the static configuration tables. > > Signed-off-by: Russell King (Oracle) > --- Thanks for the patch, and the idea is good. > drivers/net/dsa/sja1105/sja1105_main.c | 63 +++++++++++++------------- > 1 file changed, 32 insertions(+), 31 deletions(-) > > diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c > index bc7e50dcb57c..b95c64b7e705 100644 > --- a/drivers/net/dsa/sja1105/sja1105_main.c > +++ b/drivers/net/dsa/sja1105/sja1105_main.c > @@ -1257,29 +1257,11 @@ static int sja1105_parse_dt(struct sja1105_private *priv) > return rc; > } > > -/* Convert link speed from SJA1105 to ethtool encoding */ > -static int sja1105_port_speed_to_ethtool(struct sja1105_private *priv, > - u64 speed) > -{ > - if (speed == priv->info->port_speed[SJA1105_SPEED_10MBPS]) > - return SPEED_10; > - if (speed == priv->info->port_speed[SJA1105_SPEED_100MBPS]) > - return SPEED_100; > - if (speed == priv->info->port_speed[SJA1105_SPEED_1000MBPS]) > - return SPEED_1000; > - if (speed == priv->info->port_speed[SJA1105_SPEED_2500MBPS]) > - return SPEED_2500; > - return SPEED_UNKNOWN; > -} > - > -/* Set link speed in the MAC configuration for a specific port. */ > -static int sja1105_adjust_port_config(struct sja1105_private *priv, int port, > - int speed_mbps) > +static int sja1105_set_port_speed(struct sja1105_private *priv, int port, > + int speed_mbps) > { > struct sja1105_mac_config_entry *mac; > - struct device *dev = priv->ds->dev; I think if you could keep this line in the new sja1105_set_port_speed() function.. > u64 speed; > - int rc; > > /* On P/Q/R/S, one can read from the device via the MAC reconfiguration > * tables. On E/T, MAC reconfig tables are not readable, only writable. > @@ -1313,7 +1295,7 @@ static int sja1105_adjust_port_config(struct sja1105_private *priv, int port, > speed = priv->info->port_speed[SJA1105_SPEED_2500MBPS]; > break; > default: > - dev_err(dev, "Invalid speed %iMbps\n", speed_mbps); > + dev_err(priv->ds->dev, "Invalid speed %iMbps\n", speed_mbps); you could also get rid of this unnecessary line change. > return -EINVAL; > } There are 2 more changes which I believe should be made in sja1105_set_port_speed(): - since it isn't called from mac_config() anymore but from mac_link_up() (change which happened quite a while ago), it mustn't handle SPEED_UNKNOWN - we can trust that phylink will not call mac_link_up() with a speed outside what we provided in mac_capabilities, so we can remove the -EINVAL "default" speed_mbps case, and make this method return void, as it can never truly cause an error But I believe these are incremental changes which should be done after this patch. I've made a note of them and will create 2 patches on top when I have the spare time. > > @@ -1325,11 +1307,29 @@ static int sja1105_adjust_port_config(struct sja1105_private *priv, int port, > * we need to configure the PCS only (if even that). > */ > if (priv->phy_mode[port] == PHY_INTERFACE_MODE_SGMII) > - mac[port].speed = priv->info->port_speed[SJA1105_SPEED_1000MBPS]; > + speed = priv->info->port_speed[SJA1105_SPEED_1000MBPS]; > else if (priv->phy_mode[port] == PHY_INTERFACE_MODE_2500BASEX) > - mac[port].speed = priv->info->port_speed[SJA1105_SPEED_2500MBPS]; > - else > - mac[port].speed = speed; > + speed = priv->info->port_speed[SJA1105_SPEED_2500MBPS]; > + > + mac[port].speed = speed; > + > + return 0; > +} > + > +/* Set link speed in the MAC configuration for a specific port. */ Could this comment state this instead? "Write the MAC Configuration Table entry and, if necessary, the CGU settings, after a link speed change for this port." > +static int sja1105_set_port_config(struct sja1105_private *priv, int port) > +{ > + struct sja1105_mac_config_entry *mac; > + struct device *dev = priv->ds->dev; > + int rc; > + > + /* On P/Q/R/S, one can read from the device via the MAC reconfiguration > + * tables. On E/T, MAC reconfig tables are not readable, only writable. > + * We have to *know* what the MAC looks like. For the sake of keeping > + * the code common, we'll use the static configuration tables as a > + * reasonable approximation for both E/T and P/Q/R/S. > + */ > + mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries; > > /* Write to the dynamic reconfiguration tables */ > rc = sja1105_dynamic_config_write(priv, BLK_IDX_MAC_CONFIG, port, > @@ -1390,7 +1390,8 @@ static void sja1105_mac_link_up(struct phylink_config *config, > struct sja1105_private *priv = dp->ds->priv; > int port = dp->index; > > - sja1105_adjust_port_config(priv, port, speed); > + if (!sja1105_set_port_speed(priv, port, speed)) > + sja1105_set_port_config(priv, port); > > sja1105_inhibit_tx(priv, BIT(port), false); > } > @@ -2293,7 +2294,7 @@ int sja1105_static_config_reload(struct sja1105_private *priv, > { > struct ptp_system_timestamp ptp_sts_before; > struct ptp_system_timestamp ptp_sts_after; > - int speed_mbps[SJA1105_MAX_NUM_PORTS]; > + u64 mac_speed[SJA1105_MAX_NUM_PORTS]; Could you move this line lower to preserve the ordering by decreasing line length? > u16 bmcr[SJA1105_MAX_NUM_PORTS] = {0}; > struct sja1105_mac_config_entry *mac; > struct dsa_switch *ds = priv->ds; > @@ -2307,14 +2308,13 @@ int sja1105_static_config_reload(struct sja1105_private *priv, > > mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries; > > - /* Back up the dynamic link speed changed by sja1105_adjust_port_config > + /* Back up the dynamic link speed changed by sja1105_set_port_speed Could you please put () after the function name? I know the original code did not have it, but my coding style has changed in the past 5 years. > * in order to temporarily restore it to SJA1105_SPEED_AUTO - which the > * switch wants to see in the static config in order to allow us to > * change it through the dynamic interface later. > */ > for (i = 0; i < ds->num_ports; i++) { > - speed_mbps[i] = sja1105_port_speed_to_ethtool(priv, > - mac[i].speed); > + mac_speed[i] = mac[i].speed; > mac[i].speed = priv->info->port_speed[SJA1105_SPEED_AUTO]; > > if (priv->xpcs[i]) > @@ -2377,7 +2377,8 @@ int sja1105_static_config_reload(struct sja1105_private *priv, > struct dw_xpcs *xpcs = priv->xpcs[i]; > unsigned int neg_mode; > > - rc = sja1105_adjust_port_config(priv, i, speed_mbps[i]); > + mac[i].speed = mac_speed[i]; > + rc = sja1105_set_port_config(priv, i); > if (rc < 0) > goto out; > > -- > 2.30.2 >