From patchwork Mon Oct 24 10:33:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cai Huoqing X-Patchwork-Id: 8323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp368851wru; Mon, 24 Oct 2022 03:35:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uuVP77SA/9CzgStS9pmIXzutcPvikS3JaSfOP5Gm4HeF/pvuJVgZ4f6DNZZtaqBc3LdHk X-Received: by 2002:a17:906:8457:b0:78d:b793:5511 with SMTP id e23-20020a170906845700b0078db7935511mr26647298ejy.393.1666607721424; Mon, 24 Oct 2022 03:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666607721; cv=none; d=google.com; s=arc-20160816; b=kYZrr9Nzpl6lV+dQsCTU2B+ORFNliMzAzUJ8NaidXPd/6w4FkzmJOeJp+8Q1NgqABL uoJs3TInZ8FSs3sc2dEFpXZgB6tGIVmmpckVT5r3Jf1i1mjR2KQVYAVfdiUzCh0AIAdL qe7vTfeTU9IdMw0lwGnv36L7y2d0Rs0XNaIoZtc5+SYiUTGxQnCdNg2hRqhlBa21jJWX goe4oafy/rgjOCAtKV3crG934A8fVoIStuRlOVneTlo9tDRczy8dDg2cWgfPs1vmVB5A RXhGmaMnEt3GNys0a4nLru7OQiuIIfj8gB4vnqKm8858MZlklSUJa+t0Fzcbb5iBj++d IhVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qpUmDlUO3lFzWoHe1gc5HAzZMJB7JaPr1kJnHfNQapk=; b=RMY5V5ocqGeWnQdqLeRxoCupBm1oLERSJMXpqbwNkhTp72eHsnaCl4Mz+eoKs0PhhE zfNjYEgs//mhU1emxcca+mjo9FkstC/3joHEcrYqRiLRJa6swl7M+cTFuwABPNNUZ4mp URbHEJfXLHVnmuZdXwopiKvF7KtFUiF4V/+gpWgE4wxNZ4LaM1hXd+HTuvJjyIp7KTsa SnEX3p5Ysq5UwJCwmnzesuSyiBIfNdLGnBJGvf7Uz9ZjltKNrbfoKnTQ99Pxc1gZgcZj zRH0RsI5l6kyBfikQ4itrds6uLpDH6pCGVA6wvOYSS4Z52YT4AIZZm+l7/Ci8LbCWy0o qR2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=keKUL2kM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht21-20020a170907609500b007a7a3b40920si2421333ejc.995.2022.10.24.03.34.57; Mon, 24 Oct 2022 03:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=keKUL2kM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbiJXKeC (ORCPT + 99 others); Mon, 24 Oct 2022 06:34:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbiJXKeA (ORCPT ); Mon, 24 Oct 2022 06:34:00 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1939255B1; Mon, 24 Oct 2022 03:33:58 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1666607636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qpUmDlUO3lFzWoHe1gc5HAzZMJB7JaPr1kJnHfNQapk=; b=keKUL2kM4SepU5a7A4+p+xyjH1lDFSjkI5Rkp7jzgrN0eULsLMawfXmc3TPdNt4JCYwhSn VHdK3s8SvjAGD1YIAcxVa3aGwPkb3Y1rshdlostDzfq/cshLMdBWH4E1wCOoWMTNygglAy 57kIdkKbJW3iD4AMrjTaciZYTtsSQko= From: Cai Huoqing To: pabeni@redhat.com Cc: caihuoqing , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Qiao Ma , Zhengchao Shao , Christophe JAILLET , "Gustavo A. R. Silva" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] net: hinic: Set max_mtu/min_mtu directly to simplify the code. Date: Mon, 24 Oct 2022 18:33:35 +0800 Message-Id: <20221024103349.4494-1-cai.huoqing@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747564858092490860?= X-GMAIL-MSGID: =?utf-8?q?1747564858092490860?= From: caihuoqing 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 --- 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;