Skip to content

Commit 295ba23

Browse files
Guangbin Huangdavem330
authored andcommitted
net: hns3: add device version to replace pci revision
To better identify the device version, struct hnae3_handle adds a member dev_version to replace pci revision. The dev_version consists of hardware version and PCI revision. The hardware version is queried from firmware by an existing firmware version query command. 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>
1 parent 090bc03 commit 295ba23

File tree

10 files changed

+100
-69
lines changed

10 files changed

+100
-69
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434

3535
#define HNAE3_MIN_VECTOR_NUM 2 /* first one for misc, another for IO */
3636

37+
/* Device version */
38+
#define HNAE3_DEVICE_VERSION_V1 0x00020
39+
#define HNAE3_DEVICE_VERSION_V2 0x00021
40+
#define HNAE3_DEVICE_VERSION_V3 0x00030
41+
42+
#define HNAE3_PCI_REVISION_BIT_SIZE 8
43+
3744
/* Device IDs */
3845
#define HNAE3_DEV_ID_GE 0xA220
3946
#define HNAE3_DEV_ID_25GE 0xA221
@@ -235,6 +242,7 @@ struct hnae3_ae_dev {
235242
struct list_head node;
236243
u32 flag;
237244
unsigned long hw_err_reset_req;
245+
u32 dev_version;
238246
void *priv;
239247
};
240248

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,11 @@ void hns3_enable_vlan_filter(struct net_device *netdev, bool enable)
629629
{
630630
struct hns3_nic_priv *priv = netdev_priv(netdev);
631631
struct hnae3_handle *h = priv->ae_handle;
632+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
632633
bool last_state;
633634

634-
if (h->pdev->revision >= 0x21 && h->ae_algo->ops->enable_vlan_filter) {
635+
if (ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2 &&
636+
h->ae_algo->ops->enable_vlan_filter) {
635637
last_state = h->netdev_flags & HNAE3_VLAN_FLTR ? true : false;
636638
if (enable != last_state) {
637639
netdev_info(netdev,
@@ -2265,6 +2267,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
22652267
{
22662268
struct hnae3_handle *h = hns3_get_handle(netdev);
22672269
struct pci_dev *pdev = h->pdev;
2270+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
22682271

22692272
netdev->priv_flags |= IFF_UNICAST_FLT;
22702273

@@ -2302,7 +2305,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
23022305
NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_SCTP_CRC |
23032306
NETIF_F_FRAGLIST;
23042307

2305-
if (pdev->revision >= 0x21) {
2308+
if (ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2) {
23062309
netdev->hw_features |= NETIF_F_GRO_HW;
23072310
netdev->features |= NETIF_F_GRO_HW;
23082311

@@ -2801,8 +2804,9 @@ static bool hns3_parse_vlan_tag(struct hns3_enet_ring *ring,
28012804
{
28022805
struct hnae3_handle *handle = ring->tqp->handle;
28032806
struct pci_dev *pdev = ring->tqp->handle->pdev;
2807+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
28042808

2805-
if (pdev->revision == 0x20) {
2809+
if (unlikely(ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)) {
28062810
*vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
28072811
if (!(*vlan_tag & VLAN_VID_MASK))
28082812
*vlan_tag = le16_to_cpu(desc->rx.vlan_tag);

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static const struct hns3_stats hns3_rxq_stats[] = {
7777
static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
7878
{
7979
struct hnae3_handle *h = hns3_get_handle(ndev);
80+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
8081
bool vlan_filter_enable;
8182
int ret;
8283

@@ -96,7 +97,7 @@ static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
9697
break;
9798
}
9899

99-
if (ret || h->pdev->revision >= 0x21)
100+
if (ret || ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2)
100101
return ret;
101102

102103
if (en) {
@@ -147,6 +148,7 @@ static void hns3_lp_setup_skb(struct sk_buff *skb)
147148

148149
struct net_device *ndev = skb->dev;
149150
struct hnae3_handle *handle;
151+
struct hnae3_ae_dev *ae_dev;
150152
unsigned char *packet;
151153
struct ethhdr *ethh;
152154
unsigned int i;
@@ -163,7 +165,8 @@ static void hns3_lp_setup_skb(struct sk_buff *skb)
163165
* the purpose of mac or serdes selftest.
164166
*/
165167
handle = hns3_get_handle(ndev);
166-
if (handle->pdev->revision == 0x20)
168+
ae_dev = pci_get_drvdata(handle->pdev);
169+
if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)
167170
ethh->h_dest[5] += HNS3_NIC_LB_DST_MAC_ADDR;
168171
eth_zero_addr(ethh->h_source);
169172
ethh->h_proto = htons(ETH_P_ARP);
@@ -761,6 +764,7 @@ static int hns3_set_link_ksettings(struct net_device *netdev,
761764
const struct ethtool_link_ksettings *cmd)
762765
{
763766
struct hnae3_handle *handle = hns3_get_handle(netdev);
767+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
764768
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
765769
int ret;
766770

@@ -782,7 +786,7 @@ static int hns3_set_link_ksettings(struct net_device *netdev,
782786
return phy_ethtool_ksettings_set(netdev->phydev, cmd);
783787
}
784788

785-
if (handle->pdev->revision == 0x20)
789+
if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)
786790
return -EOPNOTSUPP;
787791

788792
ret = hns3_check_ksettings_param(netdev, cmd);
@@ -846,11 +850,12 @@ static int hns3_set_rss(struct net_device *netdev, const u32 *indir,
846850
const u8 *key, const u8 hfunc)
847851
{
848852
struct hnae3_handle *h = hns3_get_handle(netdev);
853+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
849854

850855
if (!h->ae_algo->ops->set_rss)
851856
return -EOPNOTSUPP;
852857

853-
if ((h->pdev->revision == 0x20 &&
858+
if ((ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 &&
854859
hfunc != ETH_RSS_HASH_TOP) || (hfunc != ETH_RSS_HASH_NO_CHANGE &&
855860
hfunc != ETH_RSS_HASH_TOP && hfunc != ETH_RSS_HASH_XOR)) {
856861
netdev_err(netdev, "hash func not supported\n");
@@ -1404,11 +1409,13 @@ static int hns3_get_module_info(struct net_device *netdev,
14041409
#define HNS3_SFF_8636_V1_3 0x03
14051410

14061411
struct hnae3_handle *handle = hns3_get_handle(netdev);
1412+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
14071413
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
14081414
struct hns3_sfp_type sfp_type;
14091415
int ret;
14101416

1411-
if (handle->pdev->revision == 0x20 || !ops->get_module_eeprom)
1417+
if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1418+
!ops->get_module_eeprom)
14121419
return -EOPNOTSUPP;
14131420

14141421
memset(&sfp_type, 0, sizeof(sfp_type));
@@ -1452,9 +1459,11 @@ static int hns3_get_module_eeprom(struct net_device *netdev,
14521459
struct ethtool_eeprom *ee, u8 *data)
14531460
{
14541461
struct hnae3_handle *handle = hns3_get_handle(netdev);
1462+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
14551463
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
14561464

1457-
if (handle->pdev->revision == 0x20 || !ops->get_module_eeprom)
1465+
if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1466+
!ops->get_module_eeprom)
14581467
return -EOPNOTSUPP;
14591468

14601469
if (!ee->len)

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,25 @@ int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
330330
return retval;
331331
}
332332

333-
static enum hclge_cmd_status hclge_cmd_query_firmware_version(
334-
struct hclge_hw *hw, u32 *version)
333+
static enum hclge_cmd_status hclge_cmd_query_version(struct hclge_dev *hdev)
335334
{
335+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(hdev->pdev);
336336
struct hclge_query_version_cmd *resp;
337337
struct hclge_desc desc;
338338
int ret;
339339

340340
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_FW_VER, 1);
341341
resp = (struct hclge_query_version_cmd *)desc.data;
342342

343-
ret = hclge_cmd_send(hw, &desc, 1);
344-
if (!ret)
345-
*version = le32_to_cpu(resp->firmware);
343+
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
344+
if (ret)
345+
return ret;
346+
347+
hdev->fw_version = le32_to_cpu(resp->firmware);
348+
349+
ae_dev->dev_version = le32_to_cpu(resp->hardware) <<
350+
HNAE3_PCI_REVISION_BIT_SIZE;
351+
ae_dev->dev_version |= hdev->pdev->revision;
346352

347353
return ret;
348354
}
@@ -402,7 +408,6 @@ static int hclge_firmware_compat_config(struct hclge_dev *hdev)
402408

403409
int hclge_cmd_init(struct hclge_dev *hdev)
404410
{
405-
u32 version;
406411
int ret;
407412

408413
spin_lock_bh(&hdev->hw.cmq.csq.lock);
@@ -431,22 +436,21 @@ int hclge_cmd_init(struct hclge_dev *hdev)
431436
goto err_cmd_init;
432437
}
433438

434-
ret = hclge_cmd_query_firmware_version(&hdev->hw, &version);
439+
ret = hclge_cmd_query_version(hdev);
435440
if (ret) {
436441
dev_err(&hdev->pdev->dev,
437-
"firmware version query failed %d\n", ret);
442+
"failed to query version ret=%d\n", ret);
438443
goto err_cmd_init;
439444
}
440-
hdev->fw_version = version;
441445

442446
dev_info(&hdev->pdev->dev, "The firmware version is %lu.%lu.%lu.%lu\n",
443-
hnae3_get_field(version, HNAE3_FW_VERSION_BYTE3_MASK,
447+
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
444448
HNAE3_FW_VERSION_BYTE3_SHIFT),
445-
hnae3_get_field(version, HNAE3_FW_VERSION_BYTE2_MASK,
449+
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE2_MASK,
446450
HNAE3_FW_VERSION_BYTE2_SHIFT),
447-
hnae3_get_field(version, HNAE3_FW_VERSION_BYTE1_MASK,
451+
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE1_MASK,
448452
HNAE3_FW_VERSION_BYTE1_SHIFT),
449-
hnae3_get_field(version, HNAE3_FW_VERSION_BYTE0_MASK,
453+
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE0_MASK,
450454
HNAE3_FW_VERSION_BYTE0_SHIFT));
451455

452456
/* ask the firmware to enable some features, driver can work without

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ struct hclge_rx_priv_buff_cmd {
364364

365365
struct hclge_query_version_cmd {
366366
__le32 firmware;
367-
__le32 firmware_rsv[5];
367+
__le32 hardware;
368+
__le32 rsv[4];
368369
};
369370

370371
#define HCLGE_RX_PRIV_EN_B 15

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ static int hclge_config_ncsi_hw_err_int(struct hclge_dev *hdev, bool en)
729729
struct hclge_desc desc;
730730
int ret;
731731

732-
if (hdev->pdev->revision < 0x21)
732+
if (hdev->ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)
733733
return 0;
734734

735735
/* configure NCSI error interrupts */
@@ -808,7 +808,7 @@ static int hclge_config_ppp_error_interrupt(struct hclge_dev *hdev, u32 cmd,
808808
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN_MASK);
809809
desc[1].data[1] =
810810
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT1_EN_MASK);
811-
if (hdev->pdev->revision >= 0x21)
811+
if (hdev->ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2)
812812
desc[1].data[2] =
813813
cpu_to_le32(HCLGE_PPP_PF_ERR_INT_EN_MASK);
814814
} else if (cmd == HCLGE_PPP_CMD1_INT_CMD) {
@@ -1041,7 +1041,7 @@ static int hclge_config_ssu_hw_err_int(struct hclge_dev *hdev, bool en)
10411041
hclge_cmd_setup_basic_desc(&desc[1], HCLGE_SSU_COMMON_INT_CMD, false);
10421042

10431043
if (en) {
1044-
if (hdev->pdev->revision >= 0x21)
1044+
if (hdev->ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2)
10451045
desc[0].data[0] =
10461046
cpu_to_le32(HCLGE_SSU_COMMON_INT_EN);
10471047
else
@@ -1550,7 +1550,8 @@ int hclge_config_rocee_ras_interrupt(struct hclge_dev *hdev, bool en)
15501550
struct hclge_desc desc;
15511551
int ret;
15521552

1553-
if (hdev->pdev->revision < 0x21 || !hnae3_dev_roce_supported(hdev))
1553+
if (hdev->ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1554+
!hnae3_dev_roce_supported(hdev))
15541555
return 0;
15551556

15561557
hclge_cmd_setup_basic_desc(&desc, HCLGE_CONFIG_ROCEE_RAS_INT_EN, false);
@@ -1663,7 +1664,7 @@ pci_ers_result_t hclge_handle_hw_ras_error(struct hnae3_ae_dev *ae_dev)
16631664
}
16641665

16651666
/* Handling Non-fatal Rocee RAS errors */
1666-
if (hdev->pdev->revision >= 0x21 &&
1667+
if (hdev->ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2 &&
16671668
status & HCLGE_RAS_REG_ROCEE_ERR_MASK) {
16681669
dev_err(dev, "ROCEE Non-Fatal RAS error identified\n");
16691670
hclge_handle_rocee_ras_error(ae_dev);

0 commit comments

Comments
 (0)