From patchwork Mon Aug 21 16:05:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 110573 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp4246249obb; Mon, 21 Aug 2017 09:06:02 -0700 (PDT) X-Received: by 10.98.147.138 with SMTP id r10mr17432158pfk.47.1503331562001; Mon, 21 Aug 2017 09:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503331561; cv=none; d=google.com; s=arc-20160816; b=FKarkwxsWxdprmbANgrBLuZuOue1XhBP4WwFUcG/Gkn7nRhIolIVO/Z2gtHcC85c7v /MbpqCvVTQllbWygXcEmEwmidbhspALPPQWwVMeYlbjWH/VPRlxqrlw+JiRAs7GqjVLz eF2euGZE5N0W1rdvyFC+u3o/xTE70aE2T59IqIyqy1h2M/w/692CwjTt/WG0C8YEtXcC TKYnS6l8hFLB9WNQmGX23DWYE8fiv/k+TYjY7WaKWTLwPWU0V2BoXJ8dzZkMXz8VIvPH eE38JKiHDlUzZjevJleeb4qFIIGdWXP7sMjfLwPIEgvvBNgV8aQbkwGhnrgVsLdI8sQy iBKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=GJwysD18mVYIMbdo/eBbsuIXjkSskagHuOo6AS+uJMM=; b=OFZeSELXxggBlmPEY+lYlzcd2ajKVqGe/+hs8T0WSkrAlwlwohuvVwKtBiPVy+SZEl /GlMV78Rv43LTSsrJY+8EpopLVXEgQgkFAB/x1PUNpwPPXQxK6s8mQi/JeVoCOGp4Gjv IUasVqMkPXVteh/2IJJAo2gWozgyfNZypppk2l13SBiKsfvMETts9fkDJSknlc7VAohA TpzRO7hxx9BIvor1T+5eaCf3fN81gnQki+dcSr1XDqHQhSIj2A1IOck9f4jpJPzTu3Wm s6BvB8sW6MwFac925vP8WPaK26tE1VjWuLdtEdEk3USDFY5paDpmIdYi90uiIfK0LtMy 336w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y7si7434741pgr.736.2017.08.21.09.06.01; Mon, 21 Aug 2017 09:06:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932136AbdHUQF7 (ORCPT + 26 others); Mon, 21 Aug 2017 12:05:59 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4973 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754297AbdHUQF5 (ORCPT ); Mon, 21 Aug 2017 12:05:57 -0400 Received: from 172.30.72.58 (EHLO DGGEMS404-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DFP27903; Tue, 22 Aug 2017 00:05:52 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.203.181.152) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.301.0; Tue, 22 Aug 2017 00:05:43 +0800 From: Salil Mehta To: CC: , , , , , , , Subject: [PATCH V4 net-next] net: hns3: Add support to change MTU in HNS3 hardware Date: Mon, 21 Aug 2017 17:05:24 +0100 Message-ID: <20170821160524.32760-1-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 MIME-Version: 1.0 X-Originating-IP: [10.203.181.152] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.599B04E1.004A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 52522e393d500c340680eef6ad4ec91a Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: lipeng Signed-off-by: Salil Mehta Reviewed-by: Andrew Lunn Reviewed-by: Leon Romanovsky --- PATCH V4: Addressed comments given by Leon Romanovsky 1. https://lkml.org/lkml/2017/8/21/212 PATCH V3: Addressed comments given by Leon Romanovsky 1. https://lkml.org/lkml/2017/8/20/27 PATCH V2: Addressed comments given by Andrew Lunn 1. https://lkml.org/lkml/2017/8/18/282 PATCH V1: Initial Submit --- .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 34 ++++++++++++++++++++++ .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h | 1 + 2 files changed, 35 insertions(+) -- 2.7.4 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c index e731f87..1c3e294 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c @@ -1278,11 +1278,42 @@ static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, 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 = { .ndo_open = hns3_nic_net_open, .ndo_stop = hns3_nic_net_stop, .ndo_start_xmit = hns3_nic_net_xmit, .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_get_stats64 = hns3_nic_get_stats64, .ndo_setup_tc = hns3_nic_setup_tc, @@ -2752,6 +2783,9 @@ static int hns3_client_init(struct hnae3_handle *handle) 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; out_reg_netdev_fail: diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h index a6e8f15..7e87461 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h @@ -76,6 +76,7 @@ enum hns3_nic_state { #define HNS3_RING_NAME_LEN 16 #define HNS3_BUFFER_SIZE_2048 2048 #define HNS3_RING_MAX_PENDING 32768 +#define HNS3_MAX_MTU 9728 #define HNS3_BD_SIZE_512_TYPE 0 #define HNS3_BD_SIZE_1024_TYPE 1