public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: DENG Qingfang <dqfext@gmail.com>
Cc: netdev@vger.kernel.org, "Sean Wang" <sean.wang@mediatek.com>,
	"Landen Chao" <landen.chao@mediatek.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"René van Dorst" <opensource@vdorst.com>,
	"Chuanhong Guo" <gch981213@gmail.com>
Subject: Re: [PATCH v2 net-next] net: dsa: mt7530: support setting MTU
Date: Mon, 2 Nov 2020 15:40:17 +0200	[thread overview]
Message-ID: <20201102134017.d7wj3io45n4sipc5@skbuf> (raw)
In-Reply-To: <20201102075821.26873-1-dqfext@gmail.com>

On Mon, Nov 02, 2020 at 03:58:21PM +0800, DENG Qingfang wrote:
> MT7530/7531 has a global RX packet length register, which can be used
> to set MTU.
> 
> Supported packet length values are 1522 (1518 if untagged), 1536, 1552,
> and multiple of 1024 (from 2048 to 15360).
> 
> Signed-off-by: DENG Qingfang <dqfext@gmail.com>
> ---
> v1 -> v2:
> 	Avoid duplication of mt7530_rmw()
> 	Fix code wrapping
> ---
>  drivers/net/dsa/mt7530.c | 49 ++++++++++++++++++++++++++++++++++++++++
>  drivers/net/dsa/mt7530.h | 12 ++++++++++
>  2 files changed, 61 insertions(+)
> 
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index de7692b763d8..ca39f81de75a 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -1021,6 +1021,53 @@ mt7530_port_disable(struct dsa_switch *ds, int port)
>  	mutex_unlock(&priv->reg_mutex);
>  }
>  
> +static int
> +mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
> +{
> +	struct mt7530_priv *priv = ds->priv;
> +	struct mii_bus *bus = priv->bus;
> +	int length;
> +	u32 val;
> +
> +	/* When a new MTU is set, DSA always set the CPU port's MTU to the
> +	 * largest MTU of the slave ports. Because the switch only has a global
> +	 * RX length register, only allowing CPU port here is enough.
> +	 */
> +	if (!dsa_is_cpu_port(ds, port))
> +		return 0;
> +
> +	mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
> +
> +	val = mt7530_mii_read(priv, MT7530_GMACCR);
> +	val &= ~MAX_RX_PKT_LEN_MASK;
> +
> +	/* RX length also includes Ethernet header, MTK tag, and FCS length */
> +	length = new_mtu + ETH_HLEN + MTK_HDR_LEN + ETH_FCS_LEN;
> +	if (length <= 1522)
> +		val |= MAX_RX_PKT_LEN_1522;

Could you please fix the checkpatch warnings here?

> +	else if (length <= 1536)
> +		val |= MAX_RX_PKT_LEN_1536;
> +	else if (length <= 1552)
> +		val |= MAX_RX_PKT_LEN_1552;
> +	else {
> +		val &= ~MAX_RX_JUMBO_MASK;
> +		val |= MAX_RX_JUMBO(DIV_ROUND_UP(length, 1024));
> +		val |= MAX_RX_PKT_LEN_JUMBO;
> +	}
> +
> +	mt7530_mii_write(priv, MT7530_GMACCR, val);
> +
> +	mutex_unlock(&bus->mdio_lock);
> +
> +	return 0;
> +}
> +

      reply	other threads:[~2020-11-02 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02  7:58 [PATCH v2 net-next] net: dsa: mt7530: support setting MTU DENG Qingfang
2020-11-02 13:40 ` Vladimir Oltean [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201102134017.d7wj3io45n4sipc5@skbuf \
    --to=olteanv@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dqfext@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=gch981213@gmail.com \
    --cc=kuba@kernel.org \
    --cc=landen.chao@mediatek.com \
    --cc=netdev@vger.kernel.org \
    --cc=opensource@vdorst.com \
    --cc=sean.wang@mediatek.com \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox