Skip to content

Commit 603d11c

Browse files
committed
Merge branch 'hns3-next'
Huazhong Tan says: ==================== net: hns3: updates for -next To facilitate code maintenance and compatibility, #1 and #2 add device version to replace pci revision, #3 to #9 adds support for querying device capabilities and specifications, then the driver can use these query results to implement corresponding features (some features will be implemented later). And #10 is a minor cleanup since too many parameters for hclge_shaper_para_calc(). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 090bc03 + ff7e4d0 commit 603d11c

File tree

13 files changed

+548
-138
lines changed

13 files changed

+548
-138
lines changed

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

Lines changed: 77 additions & 4 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
@@ -54,8 +61,6 @@
5461
#define HNAE3_KNIC_CLIENT_INITED_B 0x3
5562
#define HNAE3_UNIC_CLIENT_INITED_B 0x4
5663
#define HNAE3_ROCE_CLIENT_INITED_B 0x5
57-
#define HNAE3_DEV_SUPPORT_FD_B 0x6
58-
#define HNAE3_DEV_SUPPORT_GRO_B 0x7
5964

6065
#define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) |\
6166
BIT(HNAE3_DEV_SUPPORT_ROCE_B))
@@ -66,11 +71,64 @@
6671
#define hnae3_dev_dcb_supported(hdev) \
6772
hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_DCB_B)
6873

74+
enum HNAE3_DEV_CAP_BITS {
75+
HNAE3_DEV_SUPPORT_FD_B,
76+
HNAE3_DEV_SUPPORT_GRO_B,
77+
HNAE3_DEV_SUPPORT_FEC_B,
78+
HNAE3_DEV_SUPPORT_UDP_GSO_B,
79+
HNAE3_DEV_SUPPORT_QB_B,
80+
HNAE3_DEV_SUPPORT_FD_FORWARD_TC_B,
81+
HNAE3_DEV_SUPPORT_PTP_B,
82+
HNAE3_DEV_SUPPORT_INT_QL_B,
83+
HNAE3_DEV_SUPPORT_SIMPLE_BD_B,
84+
HNAE3_DEV_SUPPORT_TX_PUSH_B,
85+
HNAE3_DEV_SUPPORT_PHY_IMP_B,
86+
HNAE3_DEV_SUPPORT_TQP_TXRX_INDEP_B,
87+
HNAE3_DEV_SUPPORT_HW_PAD_B,
88+
HNAE3_DEV_SUPPORT_STASH_B,
89+
};
90+
6991
#define hnae3_dev_fd_supported(hdev) \
70-
hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_FD_B)
92+
test_bit(HNAE3_DEV_SUPPORT_FD_B, (hdev)->ae_dev->caps)
7193

7294
#define hnae3_dev_gro_supported(hdev) \
73-
hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_GRO_B)
95+
test_bit(HNAE3_DEV_SUPPORT_GRO_B, (hdev)->ae_dev->caps)
96+
97+
#define hnae3_dev_fec_supported(hdev) \
98+
test_bit(HNAE3_DEV_SUPPORT_FEC_B, (hdev)->ae_dev->caps)
99+
100+
#define hnae3_dev_udp_gso_supported(hdev) \
101+
test_bit(HNAE3_DEV_SUPPORT_UDP_GSO_B, (hdev)->ae_dev->caps)
102+
103+
#define hnae3_dev_qb_supported(hdev) \
104+
test_bit(HNAE3_DEV_SUPPORT_QB_B, (hdev)->ae_dev->caps)
105+
106+
#define hnae3_dev_fd_forward_tc_supported(hdev) \
107+
test_bit(HNAE3_DEV_SUPPORT_FD_FORWARD_TC_B, (hdev)->ae_dev->caps)
108+
109+
#define hnae3_dev_ptp_supported(hdev) \
110+
test_bit(HNAE3_DEV_SUPPORT_PTP_B, (hdev)->ae_dev->caps)
111+
112+
#define hnae3_dev_int_ql_supported(hdev) \
113+
test_bit(HNAE3_DEV_SUPPORT_INT_QL_B, (hdev)->ae_dev->caps)
114+
115+
#define hnae3_dev_simple_bd_supported(hdev) \
116+
test_bit(HNAE3_DEV_SUPPORT_SIMPLE_BD_B, (hdev)->ae_dev->caps)
117+
118+
#define hnae3_dev_tx_push_supported(hdev) \
119+
test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, (hdev)->ae_dev->caps)
120+
121+
#define hnae3_dev_phy_imp_supported(hdev) \
122+
test_bit(HNAE3_DEV_SUPPORT_PHY_IMP_B, (hdev)->ae_dev->caps)
123+
124+
#define hnae3_dev_tqp_txrx_indep_supported(hdev) \
125+
test_bit(HNAE3_DEV_SUPPORT_TQP_TXRX_INDEP_B, (hdev)->ae_dev->caps)
126+
127+
#define hnae3_dev_hw_pad_supported(hdev) \
128+
test_bit(HNAE3_DEV_SUPPORT_HW_PAD_B, (hdev)->ae_dev->caps)
129+
130+
#define hnae3_dev_stash_supported(hdev) \
131+
test_bit(HNAE3_DEV_SUPPORT_STASH_B, (hdev)->ae_dev->caps)
74132

75133
#define ring_ptr_move_fw(ring, p) \
76134
((ring)->p = ((ring)->p + 1) % (ring)->desc_num)
@@ -209,6 +267,17 @@ struct hnae3_ring_chain_node {
209267
#define HNAE3_IS_TX_RING(node) \
210268
(((node)->flag & (1 << HNAE3_RING_TYPE_B)) == HNAE3_RING_TYPE_TX)
211269

270+
/* device specification info from firmware */
271+
struct hnae3_dev_specs {
272+
u32 mac_entry_num; /* number of mac-vlan table entry */
273+
u32 mng_entry_num; /* number of manager table entry */
274+
u32 max_tm_rate;
275+
u16 rss_ind_tbl_size;
276+
u16 rss_key_size;
277+
u16 int_ql_max; /* max value of interrupt coalesce based on INT_QL */
278+
u8 max_non_tso_bd_num; /* max BD number of one non-TSO packet */
279+
};
280+
212281
struct hnae3_client_ops {
213282
int (*init_instance)(struct hnae3_handle *handle);
214283
void (*uninit_instance)(struct hnae3_handle *handle, bool reset);
@@ -229,12 +298,16 @@ struct hnae3_client {
229298
struct list_head node;
230299
};
231300

301+
#define HNAE3_DEV_CAPS_MAX_NUM 96
232302
struct hnae3_ae_dev {
233303
struct pci_dev *pdev;
234304
const struct hnae3_ae_ops *ops;
235305
struct list_head node;
236306
u32 flag;
237307
unsigned long hw_err_reset_req;
308+
struct hnae3_dev_specs dev_specs;
309+
u32 dev_version;
310+
unsigned long caps[BITS_TO_LONGS(HNAE3_DEV_CAPS_MAX_NUM)];
238311
void *priv;
239312
};
240313

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
244244
dev_info(&h->pdev->dev, "queue info <number>\n");
245245
dev_info(&h->pdev->dev, "queue map\n");
246246
dev_info(&h->pdev->dev, "bd info <q_num> <bd index>\n");
247+
dev_info(&h->pdev->dev, "dev capability\n");
247248

248249
if (!hns3_is_phys_func(h->pdev))
249250
return;
@@ -285,6 +286,27 @@ static void hns3_dbg_help(struct hnae3_handle *h)
285286
dev_info(&h->pdev->dev, "%s", printf_buf);
286287
}
287288

289+
static void hns3_dbg_dev_caps(struct hnae3_handle *h)
290+
{
291+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
292+
unsigned long *caps;
293+
294+
caps = ae_dev->caps;
295+
296+
dev_info(&h->pdev->dev, "support FD: %s\n",
297+
test_bit(HNAE3_DEV_SUPPORT_FD_B, caps) ? "yes" : "no");
298+
dev_info(&h->pdev->dev, "support GRO: %s\n",
299+
test_bit(HNAE3_DEV_SUPPORT_GRO_B, caps) ? "yes" : "no");
300+
dev_info(&h->pdev->dev, "support FEC: %s\n",
301+
test_bit(HNAE3_DEV_SUPPORT_FEC_B, caps) ? "yes" : "no");
302+
dev_info(&h->pdev->dev, "support UDP GSO: %s\n",
303+
test_bit(HNAE3_DEV_SUPPORT_UDP_GSO_B, caps) ? "yes" : "no");
304+
dev_info(&h->pdev->dev, "support PTP: %s\n",
305+
test_bit(HNAE3_DEV_SUPPORT_PTP_B, caps) ? "yes" : "no");
306+
dev_info(&h->pdev->dev, "support INT QL: %s\n",
307+
test_bit(HNAE3_DEV_SUPPORT_INT_QL_B, caps) ? "yes" : "no");
308+
}
309+
288310
static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
289311
size_t count, loff_t *ppos)
290312
{
@@ -360,6 +382,8 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
360382
ret = hns3_dbg_queue_map(handle);
361383
else if (strncmp(cmd_buf, "bd info", 7) == 0)
362384
ret = hns3_dbg_bd_info(handle, cmd_buf);
385+
else if (strncmp(cmd_buf, "dev capability", 14) == 0)
386+
hns3_dbg_dev_caps(handle);
363387
else if (handle->ae_algo->ops->dbg_run_cmd)
364388
ret = handle->ae_algo->ops->dbg_run_cmd(handle, cmd_buf);
365389
else

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

Lines changed: 7 additions & 13 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,
@@ -2074,15 +2076,6 @@ static void hns3_disable_sriov(struct pci_dev *pdev)
20742076
pci_disable_sriov(pdev);
20752077
}
20762078

2077-
static void hns3_get_dev_capability(struct pci_dev *pdev,
2078-
struct hnae3_ae_dev *ae_dev)
2079-
{
2080-
if (pdev->revision >= 0x21) {
2081-
hnae3_set_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_FD_B, 1);
2082-
hnae3_set_bit(ae_dev->flag, HNAE3_DEV_SUPPORT_GRO_B, 1);
2083-
}
2084-
}
2085-
20862079
/* hns3_probe - Device initialization routine
20872080
* @pdev: PCI device information struct
20882081
* @ent: entry in hns3_pci_tbl
@@ -2104,7 +2097,6 @@ static int hns3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
21042097

21052098
ae_dev->pdev = pdev;
21062099
ae_dev->flag = ent->driver_data;
2107-
hns3_get_dev_capability(pdev, ae_dev);
21082100
pci_set_drvdata(pdev, ae_dev);
21092101

21102102
ret = hnae3_register_ae_dev(ae_dev);
@@ -2265,6 +2257,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
22652257
{
22662258
struct hnae3_handle *h = hns3_get_handle(netdev);
22672259
struct pci_dev *pdev = h->pdev;
2260+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
22682261

22692262
netdev->priv_flags |= IFF_UNICAST_FLT;
22702263

@@ -2302,7 +2295,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
23022295
NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_SCTP_CRC |
23032296
NETIF_F_FRAGLIST;
23042297

2305-
if (pdev->revision >= 0x21) {
2298+
if (ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2) {
23062299
netdev->hw_features |= NETIF_F_GRO_HW;
23072300
netdev->features |= NETIF_F_GRO_HW;
23082301

@@ -2801,8 +2794,9 @@ static bool hns3_parse_vlan_tag(struct hns3_enet_ring *ring,
28012794
{
28022795
struct hnae3_handle *handle = ring->tqp->handle;
28032796
struct pci_dev *pdev = ring->tqp->handle->pdev;
2797+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
28042798

2805-
if (pdev->revision == 0x20) {
2799+
if (unlikely(ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)) {
28062800
*vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
28072801
if (!(*vlan_tag & VLAN_VID_MASK))
28082802
*vlan_tag = le16_to_cpu(desc->rx.vlan_tag);

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

Lines changed: 19 additions & 11 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");
@@ -1071,9 +1076,6 @@ static int hns3_nway_reset(struct net_device *netdev)
10711076
if (phy)
10721077
return genphy_restart_aneg(phy);
10731078

1074-
if (handle->pdev->revision == 0x20)
1075-
return -EOPNOTSUPP;
1076-
10771079
return ops->restart_autoneg(handle);
10781080
}
10791081

@@ -1361,11 +1363,12 @@ static int hns3_get_fecparam(struct net_device *netdev,
13611363
struct ethtool_fecparam *fec)
13621364
{
13631365
struct hnae3_handle *handle = hns3_get_handle(netdev);
1366+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
13641367
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
13651368
u8 fec_ability;
13661369
u8 fec_mode;
13671370

1368-
if (handle->pdev->revision == 0x20)
1371+
if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
13691372
return -EOPNOTSUPP;
13701373

13711374
if (!ops->get_fec)
@@ -1383,10 +1386,11 @@ static int hns3_set_fecparam(struct net_device *netdev,
13831386
struct ethtool_fecparam *fec)
13841387
{
13851388
struct hnae3_handle *handle = hns3_get_handle(netdev);
1389+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
13861390
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
13871391
u32 fec_mode;
13881392

1389-
if (handle->pdev->revision == 0x20)
1393+
if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
13901394
return -EOPNOTSUPP;
13911395

13921396
if (!ops->set_fec)
@@ -1404,11 +1408,13 @@ static int hns3_get_module_info(struct net_device *netdev,
14041408
#define HNS3_SFF_8636_V1_3 0x03
14051409

14061410
struct hnae3_handle *handle = hns3_get_handle(netdev);
1411+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
14071412
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
14081413
struct hns3_sfp_type sfp_type;
14091414
int ret;
14101415

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

14141420
memset(&sfp_type, 0, sizeof(sfp_type));
@@ -1452,9 +1458,11 @@ static int hns3_get_module_eeprom(struct net_device *netdev,
14521458
struct ethtool_eeprom *ee, u8 *data)
14531459
{
14541460
struct hnae3_handle *handle = hns3_get_handle(netdev);
1461+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
14551462
const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
14561463

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

14601468
if (!ee->len)

0 commit comments

Comments
 (0)