1
0
mirror of https://github.com/corundum/corundum.git synced 2025-01-16 08:12:53 +08:00

Support changing MTU

This commit is contained in:
Alex Forencich 2019-11-19 13:30:35 -08:00
parent 2647f68124
commit e696433ecc
3 changed files with 40 additions and 3 deletions

View File

@ -148,6 +148,8 @@ struct mqnic_ring {
u32 cpl_index;
u32 mtu;
size_t buf_size;
u8 *buf;
dma_addr_t buf_dma_addr;

View File

@ -65,6 +65,7 @@ static int mqnic_start_port(struct net_device *ndev)
// set up RX queues
for (k = 0; k < priv->rx_queue_count; k++)
{
priv->rx_ring[k]->mtu = ndev->mtu;
mqnic_activate_rx_ring(priv, priv->rx_ring[k], k);
}
@ -338,6 +339,34 @@ static int mqnic_hwtstamp_get(struct net_device *ndev, struct ifreq *ifr)
}
}
static int mqnic_change_mtu(struct net_device *ndev, int new_mtu)
{
struct mqnic_priv *priv = netdev_priv(ndev);
struct mqnic_dev *mdev = priv->mdev;
if (new_mtu < ndev->min_mtu || new_mtu > ndev->max_mtu)
{
dev_err(&mdev->pdev->dev, "Bad MTU: %d", new_mtu);
return -EPERM;
}
dev_info(&mdev->pdev->dev, "New MTU: %d", new_mtu);
ndev->mtu = new_mtu;
if (netif_running(ndev))
{
mutex_lock(&mdev->state_lock);
mqnic_stop_port(ndev);
mqnic_start_port(ndev);
mutex_unlock(&mdev->state_lock);
}
return 0;
}
static int mqnic_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)
{
switch (cmd) {
@ -356,6 +385,7 @@ static const struct net_device_ops mqnic_netdev_ops = {
.ndo_start_xmit = mqnic_start_xmit,
.ndo_get_stats64 = mqnic_get_stats64,
.ndo_validate_addr = eth_validate_addr,
.ndo_change_mtu = mqnic_change_mtu,
.ndo_do_ioctl = mqnic_ioctl,
};
@ -535,7 +565,12 @@ int mqnic_init_netdev(struct mqnic_dev *mdev, int port, u8 __iomem *hw_addr)
ndev->hw_features |= 0;
ndev->min_mtu = ETH_MIN_MTU;
ndev->max_mtu = 2048; // TODO
ndev->max_mtu = 1500;
if (priv->ports[0] && priv->ports[0]->port_mtu)
{
ndev->max_mtu = priv->ports[0]->port_mtu-ETH_HLEN;
}
netif_carrier_off(ndev);

View File

@ -199,7 +199,7 @@ int mqnic_prepare_rx_desc(struct mqnic_priv *priv, struct mqnic_ring *ring, int
struct mqnic_desc *rx_desc = (struct mqnic_desc *)(ring->buf + index * sizeof(*rx_desc));
struct sk_buff *skb = rx_info->skb;
rx_info->len = 2048;
rx_info->len = ring->mtu+ETH_HLEN;
if (skb)
{
@ -207,7 +207,7 @@ int mqnic_prepare_rx_desc(struct mqnic_priv *priv, struct mqnic_ring *ring, int
return -1;
}
skb = __netdev_alloc_skb_ip_align(priv->ndev, 2048, GFP_ATOMIC);
skb = netdev_alloc_skb_ip_align(priv->ndev, rx_info->len);
if (!skb)
{
dev_err(&priv->mdev->pdev->dev, "mqnic_prepare_rx_desc failed to allocate skb on port %d", priv->port);