Skip to contentSkip to conversation

net: hinic: Update the range of MTU from 256 to 9600

PATCH In review Cai Huoqing 3 participants 5 messages Oct 12, 2022 – Oct 13, 2022

Subsystems (3)
lore
Share & tools
lore

Cai Huoqing

author maintainer
#0 lore raw

PATCH 1/1 net: hinic: Update the range of MTU from 256 to 9600

From: caihuoqing <[email protected]>

Hinic hardware only support MTU from 256 to 9600, so set the max_mtu and min_mtu.

And not need to add the validity judgment when set mtu, because the judgment is made in net/core: dev_validate_mtu

---
 drivers/net/ethernet/huawei/hinic/hinic_dev.h  |  3 +++
 drivers/net/ethernet/huawei/hinic/hinic_main.c |  3 ++-
 drivers/net/ethernet/huawei/hinic/hinic_port.c | 17 +----------------
 3 files changed, 6 insertions(+), 17 deletions(-)
drivers/net/ethernet/huawei/hinic/hinic_dev.h +3 -0
index a4fbf44f944c..2bbc94c0a9c1 100644
@@ -22,6 +22,9 @@
 
 #define LP_PKT_CNT		64
 
+#define HINIC_MAX_MTU_SIZE		9600
+#define HINIC_MIN_MTU_SIZE		256
+
 enum hinic_flags {
 	HINIC_LINK_UP = BIT(0),
 	HINIC_INTF_UP = BIT(1),
drivers/net/ethernet/huawei/hinic/hinic_main.c +2 -1
index c23ee2ddbce3..41e52f775aae 100644
@@ -1189,7 +1189,8 @@ static int nic_dev_init(struct pci_dev *pdev)
 	else
 		netdev->netdev_ops = &hinicvf_netdev_ops;
 
-	netdev->max_mtu = ETH_MAX_MTU;
+	netdev->max_mtu = HINIC_MAX_MTU_SIZE;
+	netdev->min_mtu = HINIC_MIN_MTU_SIZE;
 
 	nic_dev = netdev_priv(netdev);
 	nic_dev->netdev = netdev;
drivers/net/ethernet/huawei/hinic/hinic_port.c +1 -16
index 28ae6f1201a8..0a39c3dffa9a 100644
@@ -17,9 +17,6 @@
 #include "hinic_port.h"
 #include "hinic_dev.h"
 
-#define HINIC_MIN_MTU_SIZE              256
-#define HINIC_MAX_JUMBO_FRAME_SIZE      15872
-
 enum mac_op {
 	MAC_DEL,
 	MAC_SET,
@@ -147,24 +144,12 @@ int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr)
  **/
 int hinic_port_set_mtu(struct hinic_dev *nic_dev, int new_mtu)
 {
-	struct net_device *netdev = nic_dev->netdev;
 	struct hinic_hwdev *hwdev = nic_dev->hwdev;
 	struct hinic_port_mtu_cmd port_mtu_cmd;
 	struct hinic_hwif *hwif = hwdev->hwif;
 	u16 out_size = sizeof(port_mtu_cmd);
 	struct pci_dev *pdev = hwif->pdev;
-	int err, max_frame;
-
-	if (new_mtu < HINIC_MIN_MTU_SIZE) {
-		netif_err(nic_dev, drv, netdev, "mtu < MIN MTU size");
-		return -EINVAL;
-	}
-
-	max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
-	if (max_frame > HINIC_MAX_JUMBO_FRAME_SIZE) {
-		netif_err(nic_dev, drv, netdev, "mtu > MAX MTU size");
-		return -EINVAL;
-	}
+	int err;
 
 	port_mtu_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
 	port_mtu_cmd.mtu = new_mtu;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 73 lines · Cai Huoqing

From: caihuoqing <[email protected]>

Hinic hardware only support MTU from 256 to 9600, so set the max_mtu and min_mtu.

And not need to add the validity judgment when set mtu, because the judgment is made in net/core: dev_validate_mtu

---
  drivers/net/ethernet/huawei/hinic/hinic_dev.h  |  3 +++
  drivers/net/ethernet/huawei/hinic/hinic_main.c |  3 ++-
  drivers/net/ethernet/huawei/hinic/hinic_port.c | 17 +----------------
  3 files changed, 6 insertions(+), 17 deletions(-)
drivers/net/ethernet/huawei/hinic/hinic_dev.h +3 -0
index a4fbf44f944c..2bbc94c0a9c1 100644
@@ -22,6 +22,9 @@
 
  #define LP_PKT_CNT		64
 
+#define HINIC_MAX_MTU_SIZE		9600
+#define HINIC_MIN_MTU_SIZE		256
+
  enum hinic_flags {
  	HINIC_LINK_UP = BIT(0),
  	HINIC_INTF_UP = BIT(1),
drivers/net/ethernet/huawei/hinic/hinic_main.c +2 -1
index c23ee2ddbce3..41e52f775aae 100644
@@ -1189,7 +1189,8 @@ static int nic_dev_init(struct pci_dev *pdev)
  	else
  		netdev->netdev_ops = &hinicvf_netdev_ops;
 
-	netdev->max_mtu = ETH_MAX_MTU;
+	netdev->max_mtu = HINIC_MAX_MTU_SIZE;
+	netdev->min_mtu = HINIC_MIN_MTU_SIZE;
 
  	nic_dev = netdev_priv(netdev);
  	nic_dev->netdev = netdev;
drivers/net/ethernet/huawei/hinic/hinic_port.c +0 -10
index 28ae6f1201a8..0a39c3dffa9a 100644
@@ -17,9 +17,6 @@
  #include "hinic_port.h"
  #include "hinic_dev.h"
 
-#define HINIC_MIN_MTU_SIZE              256
-#define HINIC_MAX_JUMBO_FRAME_SIZE      15872
-
  enum mac_op {
  	MAC_DEL,
  	MAC_SET,
@@ -147,24 +144,12 @@ int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr)
   **/
  int hinic_port_set_mtu(struct hinic_dev *nic_dev, int new_mtu)
  {
-	struct net_device *netdev = nic_dev->netdev;
  	struct hinic_hwdev *hwdev = nic_dev->hwdev;
  	struct hinic_port_mtu_cmd port_mtu_cmd;
  	struct hinic_hwif *hwif = hwdev->hwif;
  	u16 out_size = sizeof(port_mtu_cmd);
  	struct pci_dev *pdev = hwif->pdev;
-	int err, max_frame;
-
-	if (new_mtu < HINIC_MIN_MTU_SIZE) {
-		netif_err(nic_dev, drv, netdev, "mtu < MIN MTU size");
-		return -EINVAL;
-	}

drivers/net/ethernet/huawei/hinic/hinic_port.c int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr) · line 155

Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_port.c +1 -6
-
-	max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
-	if (max_frame > HINIC_MAX_JUMBO_FRAME_SIZE) {
-		netif_err(nic_dev, drv, netdev, "mtu > MAX MTU size");
-		return -EINVAL;
-	}
+	int err;
 
  	port_mtu_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
  	port_mtu_cmd.mtu = new_mtu;

Hi Cai:
You cannot change the maximum supported jumbo frame size.
Because as far as I know, this is not compatible with the older firmware version. If you change the maximum MTU, the maximum length of packets received by the port will be affected with older fw. So donot change it.

Zhengchao Shao

author maintainer
#2 lore raw
Quoted 18 lines · shaozhengchao
Quoted 15 lines · Cai Huoqing

From: caihuoqing <[email protected]>

Hinic hardware only support MTU from 256 to 9600, so set the max_mtu and min_mtu.

And not need to add the validity judgment when set mtu, because the judgment is made in net/core: dev_validate_mtu

---
  drivers/net/ethernet/huawei/hinic/hinic_dev.h  |  3 +++
  drivers/net/ethernet/huawei/hinic/hinic_main.c |  3 ++-
  drivers/net/ethernet/huawei/hinic/hinic_port.c | 17 +----------------
  3 files changed, 6 insertions(+), 17 deletions(-)
Quoted 7 lines

drivers/net/ethernet/huawei/hinic/hinic_dev.h line 23

Quoted 7 lines
drivers/net/ethernet/huawei/hinic/hinic_dev.h +1 -0
index a4fbf44f944c..2bbc94c0a9c1 100644
@@ -22,6 +22,9 @@
  #define LP_PKT_CNT		64
+#define HINIC_MAX_MTU_SIZE		9600

Hi Shao, thanks for your reply.

I will change it in patch v2, like
"#define HINIC_MAX_MTU_SIZE (HINIC_MAX_JUMBO_FRAME_SIZE - ETH_HLEN - ETH_FCS_LEN)" to compatible the old firmware (maybe some old cards).

Quoted 64 lines
Quoted 45 lines
drivers/net/ethernet/huawei/hinic/hinic_dev.h +2 -0
+#define HINIC_MIN_MTU_SIZE		256
+
  enum hinic_flags {
  	HINIC_LINK_UP = BIT(0),
  	HINIC_INTF_UP = BIT(1),
drivers/net/ethernet/huawei/hinic/hinic_main.c +2 -1
index c23ee2ddbce3..41e52f775aae 100644
@@ -1189,7 +1189,8 @@ static int nic_dev_init(struct pci_dev *pdev)
  	else
  		netdev->netdev_ops = &hinicvf_netdev_ops;
-	netdev->max_mtu = ETH_MAX_MTU;
+	netdev->max_mtu = HINIC_MAX_MTU_SIZE;
+	netdev->min_mtu = HINIC_MIN_MTU_SIZE;
  	nic_dev = netdev_priv(netdev);
  	nic_dev->netdev = netdev;
drivers/net/ethernet/huawei/hinic/hinic_port.c +0 -9
index 28ae6f1201a8..0a39c3dffa9a 100644
@@ -17,9 +17,6 @@
  #include "hinic_port.h"
  #include "hinic_dev.h"
-#define HINIC_MIN_MTU_SIZE              256
-#define HINIC_MAX_JUMBO_FRAME_SIZE      15872
-
  enum mac_op {
  	MAC_DEL,
  	MAC_SET,
@@ -147,24 +144,12 @@ int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr)
   **/
  int hinic_port_set_mtu(struct hinic_dev *nic_dev, int new_mtu)
  {
-	struct net_device *netdev = nic_dev->netdev;
  	struct hinic_hwdev *hwdev = nic_dev->hwdev;
  	struct hinic_port_mtu_cmd port_mtu_cmd;
  	struct hinic_hwif *hwif = hwdev->hwif;
  	u16 out_size = sizeof(port_mtu_cmd);
  	struct pci_dev *pdev = hwif->pdev;
-	int err, max_frame;
-
-	if (new_mtu < HINIC_MIN_MTU_SIZE) {
-		netif_err(nic_dev, drv, netdev, "mtu < MIN MTU size");
-		return -EINVAL;

drivers/net/ethernet/huawei/hinic/hinic_port.c int hinic_port_get_mac(struct hinic_dev *nic_dev, u8 *addr) · line 154

Quoted 10 lines
drivers/net/ethernet/huawei/hinic/hinic_port.c +1 -7
-	}
-
-	max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
-	if (max_frame > HINIC_MAX_JUMBO_FRAME_SIZE) {
-		netif_err(nic_dev, drv, netdev, "mtu > MAX MTU size");
-		return -EINVAL;
-	}
+	int err;
  	port_mtu_cmd.func_idx = HINIC_HWIF_FUNC_IDX(hwif);
  	port_mtu_cmd.mtu = new_mtu;

Hi Cai:
You cannot change the maximum supported jumbo frame size.
Because as far as I know, this is not compatible with the older firmware version. If you change the maximum MTU, the maximum length of packets received by the port will be affected with older fw. So donot change it.

Zhengchao Shao

maintainer
#3 lore raw
In reply to Cai Huoqing
Quoted 2 lines · On Wed, 12 Oct 2022 16:29:40 +0800 Cai Huoqing wrote:

Hinic hardware only support MTU from 256 to 9600, so set the max_mtu and min_mtu.

Sounds like a bug fix so please add a Fixes tag so that the patch gets backported to stable releases.

author maintainer
#4 lore raw
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 12 Oct 2022 16:29:40 +0800 Cai Huoqing wrote:

Hinic hardware only support MTU from 256 to 9600, so set the max_mtu and min_mtu.

Sounds like a bug fix so please add a Fixes tag so that the patch gets

Hi Jakub,
Not a bug fix, after v2 reverse the value of max_mtu for Shao's comments,
this patch just simplify the code.
v2 patch here:
https://lore.kernel.org/lkml/[email protected]/

Thanks,

Quoted 1 line

backported to stable releases.