]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
net: hns3: Refactor mac mtu setting related functions
authorYunsheng Lin <linyunsheng@huawei.com>
Sun, 18 Nov 2018 03:19:11 +0000 (03:19 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sun, 18 Nov 2018 05:57:29 +0000 (21:57 -0800)
This patch refactors mac mtu setting related functions,
normalizes the use of mps and mtu.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

index c944090d3adf00ced94f323768248319e245ab11..d58d3c193ab7225b2b40d4a25542305f71618027 100644 (file)
@@ -3610,8 +3610,7 @@ static int hns3_client_init(struct hnae3_handle *handle)
        hns3_dcbnl_setup(handle);
 
        /* MTU range: (ETH_MIN_MTU(kernel default) - 9702) */
-       netdev->max_mtu =
-               HNS3_MAX_MTU - (ETH_HLEN + ETH_FCS_LEN + 2 * VLAN_HLEN);
+       netdev->max_mtu = HNS3_MAX_MTU;
 
        set_bit(HNS3_NIC_STATE_INITED, &priv->state);
 
index 3365c959698385a8885d3c368e9f1eb22951044d..bbf227ba30f8688d243a9c9319965704ac82af78 100644 (file)
@@ -76,7 +76,10 @@ enum hns3_nic_state {
 #define HNS3_RING_MAX_PENDING                  32768
 #define HNS3_RING_MIN_PENDING                  8
 #define HNS3_RING_BD_MULTIPLE                  8
-#define HNS3_MAX_MTU                           9728
+/* max frame size of mac */
+#define HNS3_MAC_MAX_FRAME                     9728
+#define HNS3_MAX_MTU \
+       (HNS3_MAC_MAX_FRAME - (ETH_HLEN + ETH_FCS_LEN + 2 * VLAN_HLEN))
 
 #define HNS3_BD_SIZE_512_TYPE                  0
 #define HNS3_BD_SIZE_1024_TYPE                 1
index 019f747e486ac971ede2439354c858070f49e2aa..0a8297f67b06c935330440b0f828e6221ccd0e8a 100644 (file)
@@ -26,7 +26,7 @@
 #define HCLGE_STATS_READ(p, offset) (*((u64 *)((u8 *)(p) + (offset))))
 #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
 
-static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu);
+static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mps);
 static int hclge_init_vlan_config(struct hclge_dev *hdev);
 static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev);
 static int hclge_set_umv_space(struct hclge_dev *hdev, u16 space_size,
@@ -1969,10 +1969,7 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
 
 static int hclge_mac_init(struct hclge_dev *hdev)
 {
-       struct hnae3_handle *handle = &hdev->vport[0].nic;
-       struct net_device *netdev = handle->kinfo.netdev;
        struct hclge_mac *mac = &hdev->hw.mac;
-       int mtu;
        int ret;
 
        hdev->hw.mac.duplex = HCLGE_MAC_FULL;
@@ -1986,15 +1983,16 @@ static int hclge_mac_init(struct hclge_dev *hdev)
 
        mac->link = 0;
 
-       if (netdev)
-               mtu = netdev->mtu;
-       else
-               mtu = ETH_DATA_LEN;
+       ret = hclge_set_mac_mtu(hdev, hdev->mps);
+       if (ret) {
+               dev_err(&hdev->pdev->dev, "set mtu failed ret=%d\n", ret);
+               return ret;
+       }
 
-       ret = hclge_set_mtu(handle, mtu);
+       ret = hclge_buffer_alloc(hdev);
        if (ret)
                dev_err(&hdev->pdev->dev,
-                       "set mtu failed ret=%d\n", ret);
+                       "allocate buffer fail, ret=%d\n", ret);
 
        return ret;
 }
@@ -6357,49 +6355,42 @@ int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
        return hclge_set_vlan_rx_offload_cfg(vport);
 }
 
-static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mtu)
+static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mps)
 {
        struct hclge_config_max_frm_size_cmd *req;
        struct hclge_desc desc;
-       int max_frm_size;
-       int ret;
-
-       max_frm_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + 2 * VLAN_HLEN;
-
-       if (max_frm_size < HCLGE_MAC_MIN_FRAME ||
-           max_frm_size > HCLGE_MAC_MAX_FRAME)
-               return -EINVAL;
 
-       max_frm_size = max(max_frm_size, HCLGE_MAC_DEFAULT_FRAME);
+       new_mps = max(new_mps, HCLGE_MAC_DEFAULT_FRAME);
 
        hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAX_FRM_SIZE, false);
 
        req = (struct hclge_config_max_frm_size_cmd *)desc.data;
-       req->max_frm_size = cpu_to_le16(max_frm_size);
+       req->max_frm_size = cpu_to_le16(new_mps);
        req->min_frm_size = HCLGE_MAC_MIN_FRAME;
 
-       ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-       if (ret)
-               dev_err(&hdev->pdev->dev, "set mtu fail, ret =%d.\n", ret);
-       else
-               hdev->mps = max_frm_size;
-
-       return ret;
+       return hclge_cmd_send(&hdev->hw, &desc, 1);
 }
 
 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
        struct hclge_dev *hdev = vport->back;
-       int ret;
+       int max_frm_size, ret;
 
-       ret = hclge_set_mac_mtu(hdev, new_mtu);
+       max_frm_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + 2 * VLAN_HLEN;
+       if (max_frm_size < HCLGE_MAC_MIN_FRAME ||
+           max_frm_size > HCLGE_MAC_MAX_FRAME)
+               return -EINVAL;
+
+       ret = hclge_set_mac_mtu(hdev, max_frm_size);
        if (ret) {
                dev_err(&hdev->pdev->dev,
                        "Change mtu fail, ret =%d\n", ret);
                return ret;
        }
 
+       hdev->mps = max_frm_size;
+
        ret = hclge_buffer_alloc(hdev);
        if (ret)
                dev_err(&hdev->pdev->dev,
@@ -7021,6 +7012,7 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
        hdev->reset_type = HNAE3_NONE_RESET;
        hdev->reset_level = HNAE3_FUNC_RESET;
        ae_dev->priv = hdev;
+       hdev->mps = ETH_FRAME_LEN + ETH_FCS_LEN + 2 * VLAN_HLEN;
 
        ret = hclge_pci_init(hdev);
        if (ret) {