diff mbox

sh_eth: add support to change MTU

Message ID 20170609153034.8777-1-niklas.soderlund+renesas@ragnatech.se
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Niklas Söderlund June 9, 2017, 3:30 p.m. UTC
The hardware supports the MTU to be changed and the driver it self is
somewhat prepared to support this. This patch hooks up the callbacks to
be able to change the MTU from user-space.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---

Based on v4.12-rc1 and tested on Renesas R-Car Koelsch M2.

Test procedure:

1. On host set MTU to something large (9000) was used for this test.

2. On target set MTU to something other then 1500, in this test the max 
   MTU of 1978 is used.

3. Send ping with large payload and observe that it works.

   ping -M do -s 1954 <target>

   The reason for 1954 instead of 1982 is two fold:

   1. On Linux (different on Mac IIRC) the ICMP/ping implementation 
      doesn’t encapsulate the 28 byte ICMP (8) + IP (20).
   2. The driver internally reserve 4 bytes of transmission buffer for 
      an optional VLAN header (4). And since no VLAN is used in this 
      setup the additional 4 bytes can carry data.

4. For extra verification the packet flow is inspected using tcpdump to 
   verify that there is no packet fragmentation.

 drivers/net/ethernet/renesas/sh_eth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Sergei Shtylyov June 9, 2017, 4:31 p.m. UTC | #1
Hello!

On 06/09/2017 06:30 PM, Niklas Söderlund wrote:

> The hardware supports the MTU to be changed and the driver it self is
> somewhat prepared to support this. This patch hooks up the callbacks to
> be able to change the MTU from user-space.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
[...]

    One more thing off my back, thanks! :-)
    I'm OK with this patch in principle (but have several nits):

Acked-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

> diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
> index f68c4db656eda846..da41eda7bfada6b9 100644
> --- a/drivers/net/ethernet/renesas/sh_eth.c
> +++ b/drivers/net/ethernet/renesas/sh_eth.c
[...]
> @@ -3171,6 +3184,13 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
>  	}
>  	sh_eth_set_default_cpu_data(mdp->cd);
>
> +	/* Datasheet states max MTU should be 2048 but due to the

    User's manual. :-)
    Somehow I thought it supports jumbo frames but the manual doesn't confirm 
that... ah, that's EtherAVB! :-)

> +	 * aliment calculations in sh_eth_ring_init() the practical

   Alignment.

> +	 * MTU is a bit less. Maybe this can be optimized some more.

    Undoubtedly... :-)

[...]

MBR, Sergei
Niklas Söderlund June 9, 2017, 8:27 p.m. UTC | #2
Hi Sergei,

Thanks for your feedback.

On 2017-06-09 19:31:09 +0300, Sergei Shtylyov wrote:
> Hello!
> 
> On 06/09/2017 06:30 PM, Niklas Söderlund wrote:
> 
> > The hardware supports the MTU to be changed and the driver it self is
> > somewhat prepared to support this. This patch hooks up the callbacks to
> > be able to change the MTU from user-space.
> > 
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> [...]
> 
>    One more thing off my back, thanks! :-)
>    I'm OK with this patch in principle (but have several nits):

Will update nits and send v2 containing your Acked-by.

> 
> Acked-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

Thanks :-)

> 
> > diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
> > index f68c4db656eda846..da41eda7bfada6b9 100644
> > --- a/drivers/net/ethernet/renesas/sh_eth.c
> > +++ b/drivers/net/ethernet/renesas/sh_eth.c
> [...]
> > @@ -3171,6 +3184,13 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
> >  	}
> >  	sh_eth_set_default_cpu_data(mdp->cd);
> > 
> > +	/* Datasheet states max MTU should be 2048 but due to the
> 
>    User's manual. :-)

Will update in v2.

>    Somehow I thought it supports jumbo frames but the manual doesn't confirm
> that... ah, that's EtherAVB! :-)

Yes I did look for that but could not find that for sh_eth :-)

> 
> > +	 * aliment calculations in sh_eth_ring_init() the practical
> 
>   Alignment.

Will fix in v2.

> 
> > +	 * MTU is a bit less. Maybe this can be optimized some more.
> 
>    Undoubtedly... :-)

:-)

> 
> [...]
> 
> MBR, Sergei
>
diff mbox

Patch

diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index f68c4db656eda846..da41eda7bfada6b9 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -2558,6 +2558,17 @@  static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
 	return phy_mii_ioctl(phydev, rq, cmd);
 }
 
+static int sh_eth_change_mtu(struct net_device *dev, int new_mtu)
+{
+	if (netif_running(dev))
+		return -EBUSY;
+
+	dev->mtu = new_mtu;
+	netdev_update_features(dev);
+
+	return 0;
+}
+
 /* For TSU_POSTn. Please refer to the manual about this (strange) bitfields */
 static void *sh_eth_tsu_get_post_reg_offset(struct sh_eth_private *mdp,
 					    int entry)
@@ -3029,6 +3040,7 @@  static const struct net_device_ops sh_eth_netdev_ops = {
 	.ndo_set_rx_mode	= sh_eth_set_rx_mode,
 	.ndo_tx_timeout		= sh_eth_tx_timeout,
 	.ndo_do_ioctl		= sh_eth_do_ioctl,
+	.ndo_change_mtu		= sh_eth_change_mtu,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= eth_mac_addr,
 };
@@ -3043,6 +3055,7 @@  static const struct net_device_ops sh_eth_netdev_ops_tsu = {
 	.ndo_vlan_rx_kill_vid	= sh_eth_vlan_rx_kill_vid,
 	.ndo_tx_timeout		= sh_eth_tx_timeout,
 	.ndo_do_ioctl		= sh_eth_do_ioctl,
+	.ndo_change_mtu		= sh_eth_change_mtu,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= eth_mac_addr,
 };
@@ -3171,6 +3184,13 @@  static int sh_eth_drv_probe(struct platform_device *pdev)
 	}
 	sh_eth_set_default_cpu_data(mdp->cd);
 
+	/* Datasheet states max MTU should be 2048 but due to the
+	 * aliment calculations in sh_eth_ring_init() the practical
+	 * MTU is a bit less. Maybe this can be optimized some more.
+	 */
+	ndev->max_mtu = 2000 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
+	ndev->min_mtu = ETH_MIN_MTU;
+
 	/* set function */
 	if (mdp->cd->tsu)
 		ndev->netdev_ops = &sh_eth_netdev_ops_tsu;