net: hns3: use capability flag to indicate FEC
authorGuangbin Huang <huangguangbin2@huawei.com>
Sun, 27 Sep 2020 07:12:42 +0000 (15:12 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 27 Sep 2020 20:25:22 +0000 (13:25 -0700)
Currently, the revision of the pci device is used to identify
whether FEC is supported, which is not good for maintainability
and compatibility. So use a capability flag to do that.

Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hnae3.h
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

index e5835eec839c15562c839c6b89b0953249353006..7a6a17d44ad786a936aaf2f26341b1827c506082 100644 (file)
@@ -63,6 +63,7 @@
 #define HNAE3_ROCE_CLIENT_INITED_B             0x5
 #define HNAE3_DEV_SUPPORT_FD_B                 0x6
 #define HNAE3_DEV_SUPPORT_GRO_B                        0x7
+#define HNAE3_DEV_SUPPORT_FEC_B                        0x9
 
 #define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) |\
                BIT(HNAE3_DEV_SUPPORT_ROCE_B))
@@ -79,6 +80,9 @@
 #define hnae3_dev_gro_supported(hdev) \
        hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_GRO_B)
 
+#define hnae3_dev_fec_supported(hdev) \
+       hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_FEC_B)
+
 #define ring_ptr_move_fw(ring, p) \
        ((ring)->p = ((ring)->p + 1) % (ring)->desc_num)
 #define ring_ptr_move_bw(ring, p) \
index 96b4d9710043dfd9d507c479921db9725f5ebb03..c57ec5ed447a09808fa69bd0328e2447faeda05f 100644 (file)
@@ -1363,11 +1363,12 @@ static int hns3_get_fecparam(struct net_device *netdev,
                             struct ethtool_fecparam *fec)
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
+       struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
        const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
        u8 fec_ability;
        u8 fec_mode;
 
-       if (handle->pdev->revision == 0x20)
+       if (!hnae3_get_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_FEC_B))
                return -EOPNOTSUPP;
 
        if (!ops->get_fec)
@@ -1385,10 +1386,11 @@ static int hns3_set_fecparam(struct net_device *netdev,
                             struct ethtool_fecparam *fec)
 {
        struct hnae3_handle *handle = hns3_get_handle(netdev);
+       struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
        const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
        u32 fec_mode;
 
-       if (handle->pdev->revision == 0x20)
+       if (!hnae3_get_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_FEC_B))
                return -EOPNOTSUPP;
 
        if (!ops->set_fec)
index 9f6b1a6d4d09d66db4300e031cb8c392e0efa104..127f693d8a0b860467c26a9aaee638117c303088 100644 (file)
@@ -355,6 +355,7 @@ hclge_cmd_query_version_and_capability(struct hclge_dev *hdev)
            ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2) {
                hnae3_set_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_FD_B, 1);
                hnae3_set_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_GRO_B, 1);
+               hnae3_set_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_FEC_B, 1);
        }
 
        return ret;
index cc6d347c6f8d71d65f5d014f68a709318e6cc669..871632a14a2f8c4a0312a6136c0a436d1f552ebe 100644 (file)
@@ -1157,7 +1157,7 @@ static void hclge_parse_fiber_link_mode(struct hclge_dev *hdev,
        hclge_convert_setting_sr(mac, speed_ability);
        hclge_convert_setting_lr(mac, speed_ability);
        hclge_convert_setting_cr(mac, speed_ability);
-       if (hdev->pdev->revision >= 0x21)
+       if (hnae3_dev_fec_supported(hdev))
                hclge_convert_setting_fec(mac);
 
        linkmode_set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, mac->supported);
@@ -1171,7 +1171,7 @@ static void hclge_parse_backplane_link_mode(struct hclge_dev *hdev,
        struct hclge_mac *mac = &hdev->hw.mac;
 
        hclge_convert_setting_kr(mac, speed_ability);
-       if (hdev->pdev->revision >= 0x21)
+       if (hnae3_dev_fec_supported(hdev))
                hclge_convert_setting_fec(mac);
        linkmode_set_bit(ETHTOOL_LINK_MODE_Backplane_BIT, mac->supported);
        linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, mac->supported);