linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] net: hinic: Set max_mtu/min_mtu directly to simplify the code.
@ 2022-10-24 10:33 Cai Huoqing
  2022-10-26  2:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Cai Huoqing @ 2022-10-24 10:33 UTC (permalink / raw)
  To: pabeni
  Cc: caihuoqing, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Qiao Ma, Zhengchao Shao, Christophe JAILLET, Gustavo A. R. Silva,
	netdev, linux-kernel

From: caihuoqing <cai.huoqing@linux.dev>

Set max_mtu/min_mtu directly to avoid making the validity judgment
when set mtu, because the judgment is made in net/core: dev_validate_mtu,
so to simplify the code.

Signed-off-by: caihuoqing <cai.huoqing@linux.dev>
---
v1->v2:
	1.Update changelog.
	2.Reverse MAX_MTU to max jumbo frame size.
v2->v3:
    1.Update signature
v3->v4:
	1.Fix whitespace-damaged

	v1 link: https://lore.kernel.org/lkml/20221012082945.10353-1-cai.huoqing@linux.dev/
	v2 link: https://lore.kernel.org/lkml/20221013083558.110621be@kernel.org/
	v3 link: https://lore.kernel.org/lkml/d9bac72cf3c7ee92ad399fff5dcaae85903adda5.camel@redhat.com/

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

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_dev.h b/drivers/net/ethernet/huawei/hinic/hinic_dev.h
index a4fbf44f944c..2bbc94c0a9c1 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_dev.h
+++ b/drivers/net/ethernet/huawei/hinic/hinic_dev.h
@@ -22,6 +22,10 @@
 
 #define LP_PKT_CNT		64
 
+#define HINIC_MAX_JUMBO_FRAME_SIZE      15872
+#define HINIC_MAX_MTU_SIZE      (HINIC_MAX_JUMBO_FRAME_SIZE - ETH_HLEN - ETH_FCS_LEN)
+#define HINIC_MIN_MTU_SIZE      256
+
 enum hinic_flags {
 	HINIC_LINK_UP = BIT(0),
 	HINIC_INTF_UP = BIT(1),
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_main.c b/drivers/net/ethernet/huawei/hinic/hinic_main.c
index c23ee2ddbce3..41e52f775aae 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_main.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_main.c
@@ -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;
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_port.c b/drivers/net/ethernet/huawei/hinic/hinic_port.c
index 28ae6f1201a8..0a39c3dffa9a 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_port.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_port.c
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v4] net: hinic: Set max_mtu/min_mtu directly to simplify the code.
  2022-10-24 10:33 [PATCH v4] net: hinic: Set max_mtu/min_mtu directly to simplify the code Cai Huoqing
@ 2022-10-26  2:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-10-26  2:50 UTC (permalink / raw)
  To: Cai Huoqing
  Cc: pabeni, davem, edumazet, kuba, mqaio, shaozhengchao,
	christophe.jaillet, gustavoars, netdev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 24 Oct 2022 18:33:35 +0800 you wrote:
> From: caihuoqing <cai.huoqing@linux.dev>
> 
> Set max_mtu/min_mtu directly to avoid making the validity judgment
> when set mtu, because the judgment is made in net/core: dev_validate_mtu,
> so to simplify the code.
> 
> Signed-off-by: caihuoqing <cai.huoqing@linux.dev>
> 
> [...]

Here is the summary with links:
  - [v4] net: hinic: Set max_mtu/min_mtu directly to simplify the code.
    https://git.kernel.org/netdev/net-next/c/022f19cf361b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-26  2:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24 10:33 [PATCH v4] net: hinic: Set max_mtu/min_mtu directly to simplify the code Cai Huoqing
2022-10-26  2:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).