Commit a8e8b7ff authored by Salil's avatar Salil Committed by David S. Miller

net: hns3: Add support to change MTU in HNS3 hardware

This patch adds the following support to the HNS3 driver:
1. Support to change the Maximum Transmission Unit of a
   port in the HNS NIC hardware.
2. Initializes the supported MTU range for the netdevice.
Signed-off-by: default avatarlipeng <lipeng321@huawei.com>
Signed-off-by: default avatarSalil Mehta <salil.mehta@huawei.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 06552f8e
...@@ -1278,11 +1278,42 @@ static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, ...@@ -1278,11 +1278,42 @@ static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
return ret; return ret;
} }
static int hns3_nic_change_mtu(struct net_device *netdev, int new_mtu)
{
struct hns3_nic_priv *priv = netdev_priv(netdev);
struct hnae3_handle *h = priv->ae_handle;
bool if_running = netif_running(netdev);
int ret;
if (!h->ae_algo->ops->set_mtu)
return -EOPNOTSUPP;
/* if this was called with netdev up then bring netdevice down */
if (if_running) {
(void)hns3_nic_net_stop(netdev);
msleep(100);
}
ret = h->ae_algo->ops->set_mtu(h, new_mtu);
if (ret) {
netdev_err(netdev, "failed to change MTU in hardware %d\n",
ret);
return ret;
}
/* if the netdev was running earlier, bring it up again */
if (if_running && hns3_nic_net_open(netdev))
ret = -EINVAL;
return ret;
}
static const struct net_device_ops hns3_nic_netdev_ops = { static const struct net_device_ops hns3_nic_netdev_ops = {
.ndo_open = hns3_nic_net_open, .ndo_open = hns3_nic_net_open,
.ndo_stop = hns3_nic_net_stop, .ndo_stop = hns3_nic_net_stop,
.ndo_start_xmit = hns3_nic_net_xmit, .ndo_start_xmit = hns3_nic_net_xmit,
.ndo_set_mac_address = hns3_nic_net_set_mac_address, .ndo_set_mac_address = hns3_nic_net_set_mac_address,
.ndo_change_mtu = hns3_nic_change_mtu,
.ndo_set_features = hns3_nic_set_features, .ndo_set_features = hns3_nic_set_features,
.ndo_get_stats64 = hns3_nic_get_stats64, .ndo_get_stats64 = hns3_nic_get_stats64,
.ndo_setup_tc = hns3_nic_setup_tc, .ndo_setup_tc = hns3_nic_setup_tc,
...@@ -2752,6 +2783,9 @@ static int hns3_client_init(struct hnae3_handle *handle) ...@@ -2752,6 +2783,9 @@ static int hns3_client_init(struct hnae3_handle *handle)
goto out_reg_netdev_fail; goto out_reg_netdev_fail;
} }
/* MTU range: (ETH_MIN_MTU(kernel default) - 9706) */
netdev->max_mtu = HNS3_MAX_MTU - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
return ret; return ret;
out_reg_netdev_fail: out_reg_netdev_fail:
......
...@@ -76,6 +76,7 @@ enum hns3_nic_state { ...@@ -76,6 +76,7 @@ enum hns3_nic_state {
#define HNS3_RING_NAME_LEN 16 #define HNS3_RING_NAME_LEN 16
#define HNS3_BUFFER_SIZE_2048 2048 #define HNS3_BUFFER_SIZE_2048 2048
#define HNS3_RING_MAX_PENDING 32768 #define HNS3_RING_MAX_PENDING 32768
#define HNS3_MAX_MTU 9728
#define HNS3_BD_SIZE_512_TYPE 0 #define HNS3_BD_SIZE_512_TYPE 0
#define HNS3_BD_SIZE_1024_TYPE 1 #define HNS3_BD_SIZE_1024_TYPE 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment