Skip to content

Commit 75efa06

Browse files
Niklas Söderlunddavem330
authored andcommitted
ravb: add support for changing MTU
Allow for changing the MTU within the limit of the maximum size of a descriptor (2048 bytes). Add the callback to change MTU from user-space and take the configurable MTU into account when configuring the hardware. Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a73d65b commit 75efa06

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

drivers/net/ethernet/renesas/ravb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ struct ravb_private {
10181018
u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */
10191019
u32 cur_tx[NUM_TX_QUEUE];
10201020
u32 dirty_tx[NUM_TX_QUEUE];
1021+
u32 rx_buf_sz; /* Based on MTU+slack. */
10211022
struct napi_struct napi[NUM_RX_QUEUE];
10221023
struct work_struct work;
10231024
/* MII transceiver section. */

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static void ravb_ring_free(struct net_device *ndev, int q)
238238
le32_to_cpu(desc->dptr)))
239239
dma_unmap_single(ndev->dev.parent,
240240
le32_to_cpu(desc->dptr),
241-
PKT_BUF_SZ,
241+
priv->rx_buf_sz,
242242
DMA_FROM_DEVICE);
243243
}
244244
ring_size = sizeof(struct ravb_ex_rx_desc) *
@@ -300,9 +300,9 @@ static void ravb_ring_format(struct net_device *ndev, int q)
300300
for (i = 0; i < priv->num_rx_ring[q]; i++) {
301301
/* RX descriptor */
302302
rx_desc = &priv->rx_ring[q][i];
303-
rx_desc->ds_cc = cpu_to_le16(PKT_BUF_SZ);
303+
rx_desc->ds_cc = cpu_to_le16(priv->rx_buf_sz);
304304
dma_addr = dma_map_single(ndev->dev.parent, priv->rx_skb[q][i]->data,
305-
PKT_BUF_SZ,
305+
priv->rx_buf_sz,
306306
DMA_FROM_DEVICE);
307307
/* We just set the data size to 0 for a failed mapping which
308308
* should prevent DMA from happening...
@@ -346,6 +346,10 @@ static int ravb_ring_init(struct net_device *ndev, int q)
346346
int ring_size;
347347
int i;
348348

349+
/* +16 gets room from the status from the card. */
350+
priv->rx_buf_sz = (ndev->mtu <= 1492 ? PKT_BUF_SZ : ndev->mtu) +
351+
ETH_HLEN + VLAN_HLEN;
352+
349353
/* Allocate RX and TX skb rings */
350354
priv->rx_skb[q] = kcalloc(priv->num_rx_ring[q],
351355
sizeof(*priv->rx_skb[q]), GFP_KERNEL);
@@ -355,7 +359,7 @@ static int ravb_ring_init(struct net_device *ndev, int q)
355359
goto error;
356360

357361
for (i = 0; i < priv->num_rx_ring[q]; i++) {
358-
skb = netdev_alloc_skb(ndev, PKT_BUF_SZ + RAVB_ALIGN - 1);
362+
skb = netdev_alloc_skb(ndev, priv->rx_buf_sz + RAVB_ALIGN - 1);
359363
if (!skb)
360364
goto error;
361365
ravb_set_buffer_align(skb);
@@ -586,7 +590,7 @@ static bool ravb_rx(struct net_device *ndev, int *quota, int q)
586590
skb = priv->rx_skb[q][entry];
587591
priv->rx_skb[q][entry] = NULL;
588592
dma_unmap_single(ndev->dev.parent, le32_to_cpu(desc->dptr),
589-
PKT_BUF_SZ,
593+
priv->rx_buf_sz,
590594
DMA_FROM_DEVICE);
591595
get_ts &= (q == RAVB_NC) ?
592596
RAVB_RXTSTAMP_TYPE_V2_L2_EVENT :
@@ -619,11 +623,12 @@ static bool ravb_rx(struct net_device *ndev, int *quota, int q)
619623
for (; priv->cur_rx[q] - priv->dirty_rx[q] > 0; priv->dirty_rx[q]++) {
620624
entry = priv->dirty_rx[q] % priv->num_rx_ring[q];
621625
desc = &priv->rx_ring[q][entry];
622-
desc->ds_cc = cpu_to_le16(PKT_BUF_SZ);
626+
desc->ds_cc = cpu_to_le16(priv->rx_buf_sz);
623627

624628
if (!priv->rx_skb[q][entry]) {
625629
skb = netdev_alloc_skb(ndev,
626-
PKT_BUF_SZ + RAVB_ALIGN - 1);
630+
priv->rx_buf_sz +
631+
RAVB_ALIGN - 1);
627632
if (!skb)
628633
break; /* Better luck next round. */
629634
ravb_set_buffer_align(skb);
@@ -1854,6 +1859,17 @@ static int ravb_do_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
18541859
return phy_mii_ioctl(phydev, req, cmd);
18551860
}
18561861

1862+
static int ravb_change_mtu(struct net_device *ndev, int new_mtu)
1863+
{
1864+
if (netif_running(ndev))
1865+
return -EBUSY;
1866+
1867+
ndev->mtu = new_mtu;
1868+
netdev_update_features(ndev);
1869+
1870+
return 0;
1871+
}
1872+
18571873
static void ravb_set_rx_csum(struct net_device *ndev, bool enable)
18581874
{
18591875
struct ravb_private *priv = netdev_priv(ndev);
@@ -1895,6 +1911,7 @@ static const struct net_device_ops ravb_netdev_ops = {
18951911
.ndo_set_rx_mode = ravb_set_rx_mode,
18961912
.ndo_tx_timeout = ravb_tx_timeout,
18971913
.ndo_do_ioctl = ravb_do_ioctl,
1914+
.ndo_change_mtu = ravb_change_mtu,
18981915
.ndo_validate_addr = eth_validate_addr,
18991916
.ndo_set_mac_address = eth_mac_addr,
19001917
.ndo_set_features = ravb_set_features,
@@ -2117,6 +2134,9 @@ static int ravb_probe(struct platform_device *pdev)
21172134
goto out_release;
21182135
}
21192136

2137+
ndev->max_mtu = 2048 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
2138+
ndev->min_mtu = ETH_MIN_MTU;
2139+
21202140
/* Set function */
21212141
ndev->netdev_ops = &ravb_netdev_ops;
21222142
ndev->ethtool_ops = &ravb_ethtool_ops;

0 commit comments

Comments
 (0)