1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2016-2017 Hisilicon Limited.
4 #include <linux/acpi.h>
5 #include <linux/device.h>
6 #include <linux/etherdevice.h>
7 #include <linux/init.h>
8 #include <linux/interrupt.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/netdevice.h>
12 #include <linux/pci.h>
13 #include <linux/platform_device.h>
14 #include <linux/if_vlan.h>
15 #include <net/rtnetlink.h>
16 #include "hclge_cmd.h"
17 #include "hclge_dcb.h"
18 #include "hclge_main.h"
19 #include "hclge_mbx.h"
20 #include "hclge_mdio.h"
22 #include "hclge_err.h"
25 #define HCLGE_NAME "hclge"
26 #define HCLGE_STATS_READ(p, offset) (*((u64 *)((u8 *)(p) + (offset))))
27 #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
29 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu);
30 static int hclge_init_vlan_config(struct hclge_dev *hdev);
31 static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev);
32 static int hclge_set_umv_space(struct hclge_dev *hdev, u16 space_size,
33 u16 *allocated_size, bool is_alloc);
35 static struct hnae3_ae_algo ae_algo;
37 static const struct pci_device_id ae_algo_pci_tbl[] = {
38 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_GE), 0},
39 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE), 0},
40 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
41 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
42 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
43 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
44 {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
45 /* required last entry */
49 MODULE_DEVICE_TABLE(pci, ae_algo_pci_tbl);
51 static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
53 "Serdes serial Loopback test",
54 "Serdes parallel Loopback test",
58 static const struct hclge_comm_stats_str g_mac_stats_string[] = {
59 {"mac_tx_mac_pause_num",
60 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_mac_pause_num)},
61 {"mac_rx_mac_pause_num",
62 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_mac_pause_num)},
63 {"mac_tx_pfc_pri0_pkt_num",
64 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri0_pkt_num)},
65 {"mac_tx_pfc_pri1_pkt_num",
66 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri1_pkt_num)},
67 {"mac_tx_pfc_pri2_pkt_num",
68 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri2_pkt_num)},
69 {"mac_tx_pfc_pri3_pkt_num",
70 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri3_pkt_num)},
71 {"mac_tx_pfc_pri4_pkt_num",
72 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri4_pkt_num)},
73 {"mac_tx_pfc_pri5_pkt_num",
74 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri5_pkt_num)},
75 {"mac_tx_pfc_pri6_pkt_num",
76 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri6_pkt_num)},
77 {"mac_tx_pfc_pri7_pkt_num",
78 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_pfc_pri7_pkt_num)},
79 {"mac_rx_pfc_pri0_pkt_num",
80 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri0_pkt_num)},
81 {"mac_rx_pfc_pri1_pkt_num",
82 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri1_pkt_num)},
83 {"mac_rx_pfc_pri2_pkt_num",
84 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri2_pkt_num)},
85 {"mac_rx_pfc_pri3_pkt_num",
86 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri3_pkt_num)},
87 {"mac_rx_pfc_pri4_pkt_num",
88 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri4_pkt_num)},
89 {"mac_rx_pfc_pri5_pkt_num",
90 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri5_pkt_num)},
91 {"mac_rx_pfc_pri6_pkt_num",
92 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri6_pkt_num)},
93 {"mac_rx_pfc_pri7_pkt_num",
94 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_pfc_pri7_pkt_num)},
95 {"mac_tx_total_pkt_num",
96 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_total_pkt_num)},
97 {"mac_tx_total_oct_num",
98 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_total_oct_num)},
99 {"mac_tx_good_pkt_num",
100 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_good_pkt_num)},
101 {"mac_tx_bad_pkt_num",
102 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_bad_pkt_num)},
103 {"mac_tx_good_oct_num",
104 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_good_oct_num)},
105 {"mac_tx_bad_oct_num",
106 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_bad_oct_num)},
107 {"mac_tx_uni_pkt_num",
108 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_uni_pkt_num)},
109 {"mac_tx_multi_pkt_num",
110 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_multi_pkt_num)},
111 {"mac_tx_broad_pkt_num",
112 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_broad_pkt_num)},
113 {"mac_tx_undersize_pkt_num",
114 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_undersize_pkt_num)},
115 {"mac_tx_oversize_pkt_num",
116 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_oversize_pkt_num)},
117 {"mac_tx_64_oct_pkt_num",
118 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_64_oct_pkt_num)},
119 {"mac_tx_65_127_oct_pkt_num",
120 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_65_127_oct_pkt_num)},
121 {"mac_tx_128_255_oct_pkt_num",
122 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_128_255_oct_pkt_num)},
123 {"mac_tx_256_511_oct_pkt_num",
124 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_256_511_oct_pkt_num)},
125 {"mac_tx_512_1023_oct_pkt_num",
126 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_512_1023_oct_pkt_num)},
127 {"mac_tx_1024_1518_oct_pkt_num",
128 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_1024_1518_oct_pkt_num)},
129 {"mac_tx_1519_2047_oct_pkt_num",
130 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_1519_2047_oct_pkt_num)},
131 {"mac_tx_2048_4095_oct_pkt_num",
132 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_2048_4095_oct_pkt_num)},
133 {"mac_tx_4096_8191_oct_pkt_num",
134 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_4096_8191_oct_pkt_num)},
135 {"mac_tx_8192_9216_oct_pkt_num",
136 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_8192_9216_oct_pkt_num)},
137 {"mac_tx_9217_12287_oct_pkt_num",
138 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_9217_12287_oct_pkt_num)},
139 {"mac_tx_12288_16383_oct_pkt_num",
140 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_12288_16383_oct_pkt_num)},
141 {"mac_tx_1519_max_good_pkt_num",
142 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_1519_max_good_oct_pkt_num)},
143 {"mac_tx_1519_max_bad_pkt_num",
144 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_1519_max_bad_oct_pkt_num)},
145 {"mac_rx_total_pkt_num",
146 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_total_pkt_num)},
147 {"mac_rx_total_oct_num",
148 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_total_oct_num)},
149 {"mac_rx_good_pkt_num",
150 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_good_pkt_num)},
151 {"mac_rx_bad_pkt_num",
152 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_bad_pkt_num)},
153 {"mac_rx_good_oct_num",
154 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_good_oct_num)},
155 {"mac_rx_bad_oct_num",
156 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_bad_oct_num)},
157 {"mac_rx_uni_pkt_num",
158 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_uni_pkt_num)},
159 {"mac_rx_multi_pkt_num",
160 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_multi_pkt_num)},
161 {"mac_rx_broad_pkt_num",
162 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_broad_pkt_num)},
163 {"mac_rx_undersize_pkt_num",
164 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_undersize_pkt_num)},
165 {"mac_rx_oversize_pkt_num",
166 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_oversize_pkt_num)},
167 {"mac_rx_64_oct_pkt_num",
168 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_64_oct_pkt_num)},
169 {"mac_rx_65_127_oct_pkt_num",
170 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_65_127_oct_pkt_num)},
171 {"mac_rx_128_255_oct_pkt_num",
172 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_128_255_oct_pkt_num)},
173 {"mac_rx_256_511_oct_pkt_num",
174 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_256_511_oct_pkt_num)},
175 {"mac_rx_512_1023_oct_pkt_num",
176 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_512_1023_oct_pkt_num)},
177 {"mac_rx_1024_1518_oct_pkt_num",
178 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_1024_1518_oct_pkt_num)},
179 {"mac_rx_1519_2047_oct_pkt_num",
180 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_1519_2047_oct_pkt_num)},
181 {"mac_rx_2048_4095_oct_pkt_num",
182 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_2048_4095_oct_pkt_num)},
183 {"mac_rx_4096_8191_oct_pkt_num",
184 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_4096_8191_oct_pkt_num)},
185 {"mac_rx_8192_9216_oct_pkt_num",
186 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_8192_9216_oct_pkt_num)},
187 {"mac_rx_9217_12287_oct_pkt_num",
188 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_9217_12287_oct_pkt_num)},
189 {"mac_rx_12288_16383_oct_pkt_num",
190 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_12288_16383_oct_pkt_num)},
191 {"mac_rx_1519_max_good_pkt_num",
192 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_1519_max_good_oct_pkt_num)},
193 {"mac_rx_1519_max_bad_pkt_num",
194 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_1519_max_bad_oct_pkt_num)},
196 {"mac_tx_fragment_pkt_num",
197 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_fragment_pkt_num)},
198 {"mac_tx_undermin_pkt_num",
199 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_undermin_pkt_num)},
200 {"mac_tx_jabber_pkt_num",
201 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_jabber_pkt_num)},
202 {"mac_tx_err_all_pkt_num",
203 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_err_all_pkt_num)},
204 {"mac_tx_from_app_good_pkt_num",
205 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_from_app_good_pkt_num)},
206 {"mac_tx_from_app_bad_pkt_num",
207 HCLGE_MAC_STATS_FIELD_OFF(mac_tx_from_app_bad_pkt_num)},
208 {"mac_rx_fragment_pkt_num",
209 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_fragment_pkt_num)},
210 {"mac_rx_undermin_pkt_num",
211 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_undermin_pkt_num)},
212 {"mac_rx_jabber_pkt_num",
213 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_jabber_pkt_num)},
214 {"mac_rx_fcs_err_pkt_num",
215 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_fcs_err_pkt_num)},
216 {"mac_rx_send_app_good_pkt_num",
217 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_send_app_good_pkt_num)},
218 {"mac_rx_send_app_bad_pkt_num",
219 HCLGE_MAC_STATS_FIELD_OFF(mac_rx_send_app_bad_pkt_num)}
222 static const struct hclge_mac_mgr_tbl_entry_cmd hclge_mgr_table[] = {
224 .flags = HCLGE_MAC_MGR_MASK_VLAN_B,
225 .ethter_type = cpu_to_le16(HCLGE_MAC_ETHERTYPE_LLDP),
226 .mac_addr_hi32 = cpu_to_le32(htonl(0x0180C200)),
227 .mac_addr_lo16 = cpu_to_le16(htons(0x000E)),
228 .i_port_bitmap = 0x1,
232 static int hclge_mac_update_stats(struct hclge_dev *hdev)
234 #define HCLGE_MAC_CMD_NUM 21
235 #define HCLGE_RTN_DATA_NUM 4
237 u64 *data = (u64 *)(&hdev->hw_stats.mac_stats);
238 struct hclge_desc desc[HCLGE_MAC_CMD_NUM];
243 hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_STATS_MAC, true);
244 ret = hclge_cmd_send(&hdev->hw, desc, HCLGE_MAC_CMD_NUM);
246 dev_err(&hdev->pdev->dev,
247 "Get MAC pkt stats fail, status = %d.\n", ret);
252 for (i = 0; i < HCLGE_MAC_CMD_NUM; i++) {
253 if (unlikely(i == 0)) {
254 desc_data = (__le64 *)(&desc[i].data[0]);
255 n = HCLGE_RTN_DATA_NUM - 2;
257 desc_data = (__le64 *)(&desc[i]);
258 n = HCLGE_RTN_DATA_NUM;
260 for (k = 0; k < n; k++) {
261 *data++ += le64_to_cpu(*desc_data);
269 static int hclge_tqps_update_stats(struct hnae3_handle *handle)
271 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
272 struct hclge_vport *vport = hclge_get_vport(handle);
273 struct hclge_dev *hdev = vport->back;
274 struct hnae3_queue *queue;
275 struct hclge_desc desc[1];
276 struct hclge_tqp *tqp;
279 for (i = 0; i < kinfo->num_tqps; i++) {
280 queue = handle->kinfo.tqp[i];
281 tqp = container_of(queue, struct hclge_tqp, q);
282 /* command : HCLGE_OPC_QUERY_IGU_STAT */
283 hclge_cmd_setup_basic_desc(&desc[0],
284 HCLGE_OPC_QUERY_RX_STATUS,
287 desc[0].data[0] = cpu_to_le32((tqp->index & 0x1ff));
288 ret = hclge_cmd_send(&hdev->hw, desc, 1);
290 dev_err(&hdev->pdev->dev,
291 "Query tqp stat fail, status = %d,queue = %d\n",
295 tqp->tqp_stats.rcb_rx_ring_pktnum_rcd +=
296 le32_to_cpu(desc[0].data[1]);
299 for (i = 0; i < kinfo->num_tqps; i++) {
300 queue = handle->kinfo.tqp[i];
301 tqp = container_of(queue, struct hclge_tqp, q);
302 /* command : HCLGE_OPC_QUERY_IGU_STAT */
303 hclge_cmd_setup_basic_desc(&desc[0],
304 HCLGE_OPC_QUERY_TX_STATUS,
307 desc[0].data[0] = cpu_to_le32((tqp->index & 0x1ff));
308 ret = hclge_cmd_send(&hdev->hw, desc, 1);
310 dev_err(&hdev->pdev->dev,
311 "Query tqp stat fail, status = %d,queue = %d\n",
315 tqp->tqp_stats.rcb_tx_ring_pktnum_rcd +=
316 le32_to_cpu(desc[0].data[1]);
322 static u64 *hclge_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
324 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
325 struct hclge_tqp *tqp;
329 for (i = 0; i < kinfo->num_tqps; i++) {
330 tqp = container_of(kinfo->tqp[i], struct hclge_tqp, q);
331 *buff++ = tqp->tqp_stats.rcb_tx_ring_pktnum_rcd;
334 for (i = 0; i < kinfo->num_tqps; i++) {
335 tqp = container_of(kinfo->tqp[i], struct hclge_tqp, q);
336 *buff++ = tqp->tqp_stats.rcb_rx_ring_pktnum_rcd;
342 static int hclge_tqps_get_sset_count(struct hnae3_handle *handle, int stringset)
344 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
346 return kinfo->num_tqps * (2);
349 static u8 *hclge_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
351 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
355 for (i = 0; i < kinfo->num_tqps; i++) {
356 struct hclge_tqp *tqp = container_of(handle->kinfo.tqp[i],
357 struct hclge_tqp, q);
358 snprintf(buff, ETH_GSTRING_LEN, "txq%d_pktnum_rcd",
360 buff = buff + ETH_GSTRING_LEN;
363 for (i = 0; i < kinfo->num_tqps; i++) {
364 struct hclge_tqp *tqp = container_of(kinfo->tqp[i],
365 struct hclge_tqp, q);
366 snprintf(buff, ETH_GSTRING_LEN, "rxq%d_pktnum_rcd",
368 buff = buff + ETH_GSTRING_LEN;
374 static u64 *hclge_comm_get_stats(void *comm_stats,
375 const struct hclge_comm_stats_str strs[],
381 for (i = 0; i < size; i++)
382 buf[i] = HCLGE_STATS_READ(comm_stats, strs[i].offset);
387 static u8 *hclge_comm_get_strings(u32 stringset,
388 const struct hclge_comm_stats_str strs[],
391 char *buff = (char *)data;
394 if (stringset != ETH_SS_STATS)
397 for (i = 0; i < size; i++) {
398 snprintf(buff, ETH_GSTRING_LEN,
400 buff = buff + ETH_GSTRING_LEN;
406 static void hclge_update_netstat(struct hclge_hw_stats *hw_stats,
407 struct net_device_stats *net_stats)
409 net_stats->tx_dropped = 0;
410 net_stats->rx_errors = hw_stats->mac_stats.mac_rx_oversize_pkt_num;
411 net_stats->rx_errors += hw_stats->mac_stats.mac_rx_undersize_pkt_num;
412 net_stats->rx_errors += hw_stats->mac_stats.mac_rx_fcs_err_pkt_num;
414 net_stats->multicast = hw_stats->mac_stats.mac_tx_multi_pkt_num;
415 net_stats->multicast += hw_stats->mac_stats.mac_rx_multi_pkt_num;
417 net_stats->rx_crc_errors = hw_stats->mac_stats.mac_rx_fcs_err_pkt_num;
418 net_stats->rx_length_errors =
419 hw_stats->mac_stats.mac_rx_undersize_pkt_num;
420 net_stats->rx_length_errors +=
421 hw_stats->mac_stats.mac_rx_oversize_pkt_num;
422 net_stats->rx_over_errors =
423 hw_stats->mac_stats.mac_rx_oversize_pkt_num;
426 static void hclge_update_stats_for_all(struct hclge_dev *hdev)
428 struct hnae3_handle *handle;
431 handle = &hdev->vport[0].nic;
432 if (handle->client) {
433 status = hclge_tqps_update_stats(handle);
435 dev_err(&hdev->pdev->dev,
436 "Update TQPS stats fail, status = %d.\n",
441 status = hclge_mac_update_stats(hdev);
443 dev_err(&hdev->pdev->dev,
444 "Update MAC stats fail, status = %d.\n", status);
446 hclge_update_netstat(&hdev->hw_stats, &handle->kinfo.netdev->stats);
449 static void hclge_update_stats(struct hnae3_handle *handle,
450 struct net_device_stats *net_stats)
452 struct hclge_vport *vport = hclge_get_vport(handle);
453 struct hclge_dev *hdev = vport->back;
454 struct hclge_hw_stats *hw_stats = &hdev->hw_stats;
457 if (test_and_set_bit(HCLGE_STATE_STATISTICS_UPDATING, &hdev->state))
460 status = hclge_mac_update_stats(hdev);
462 dev_err(&hdev->pdev->dev,
463 "Update MAC stats fail, status = %d.\n",
466 status = hclge_tqps_update_stats(handle);
468 dev_err(&hdev->pdev->dev,
469 "Update TQPS stats fail, status = %d.\n",
472 hclge_update_netstat(hw_stats, net_stats);
474 clear_bit(HCLGE_STATE_STATISTICS_UPDATING, &hdev->state);
477 static int hclge_get_sset_count(struct hnae3_handle *handle, int stringset)
479 #define HCLGE_LOOPBACK_TEST_FLAGS (HNAE3_SUPPORT_APP_LOOPBACK |\
480 HNAE3_SUPPORT_PHY_LOOPBACK |\
481 HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK |\
482 HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK)
484 struct hclge_vport *vport = hclge_get_vport(handle);
485 struct hclge_dev *hdev = vport->back;
488 /* Loopback test support rules:
489 * mac: only GE mode support
490 * serdes: all mac mode will support include GE/XGE/LGE/CGE
491 * phy: only support when phy device exist on board
493 if (stringset == ETH_SS_TEST) {
494 /* clear loopback bit flags at first */
495 handle->flags = (handle->flags & (~HCLGE_LOOPBACK_TEST_FLAGS));
496 if (hdev->pdev->revision >= 0x21 ||
497 hdev->hw.mac.speed == HCLGE_MAC_SPEED_10M ||
498 hdev->hw.mac.speed == HCLGE_MAC_SPEED_100M ||
499 hdev->hw.mac.speed == HCLGE_MAC_SPEED_1G) {
501 handle->flags |= HNAE3_SUPPORT_APP_LOOPBACK;
505 handle->flags |= HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK;
506 handle->flags |= HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK;
507 } else if (stringset == ETH_SS_STATS) {
508 count = ARRAY_SIZE(g_mac_stats_string) +
509 hclge_tqps_get_sset_count(handle, stringset);
515 static void hclge_get_strings(struct hnae3_handle *handle,
519 u8 *p = (char *)data;
522 if (stringset == ETH_SS_STATS) {
523 size = ARRAY_SIZE(g_mac_stats_string);
524 p = hclge_comm_get_strings(stringset,
528 p = hclge_tqps_get_strings(handle, p);
529 } else if (stringset == ETH_SS_TEST) {
530 if (handle->flags & HNAE3_SUPPORT_APP_LOOPBACK) {
532 hns3_nic_test_strs[HNAE3_LOOP_APP],
534 p += ETH_GSTRING_LEN;
536 if (handle->flags & HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK) {
538 hns3_nic_test_strs[HNAE3_LOOP_SERIAL_SERDES],
540 p += ETH_GSTRING_LEN;
542 if (handle->flags & HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK) {
544 hns3_nic_test_strs[HNAE3_LOOP_PARALLEL_SERDES],
546 p += ETH_GSTRING_LEN;
548 if (handle->flags & HNAE3_SUPPORT_PHY_LOOPBACK) {
550 hns3_nic_test_strs[HNAE3_LOOP_PHY],
552 p += ETH_GSTRING_LEN;
557 static void hclge_get_stats(struct hnae3_handle *handle, u64 *data)
559 struct hclge_vport *vport = hclge_get_vport(handle);
560 struct hclge_dev *hdev = vport->back;
563 p = hclge_comm_get_stats(&hdev->hw_stats.mac_stats,
565 ARRAY_SIZE(g_mac_stats_string),
567 p = hclge_tqps_get_stats(handle, p);
570 static int hclge_parse_func_status(struct hclge_dev *hdev,
571 struct hclge_func_status_cmd *status)
573 if (!(status->pf_state & HCLGE_PF_STATE_DONE))
576 /* Set the pf to main pf */
577 if (status->pf_state & HCLGE_PF_STATE_MAIN)
578 hdev->flag |= HCLGE_FLAG_MAIN;
580 hdev->flag &= ~HCLGE_FLAG_MAIN;
585 static int hclge_query_function_status(struct hclge_dev *hdev)
587 struct hclge_func_status_cmd *req;
588 struct hclge_desc desc;
592 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_FUNC_STATUS, true);
593 req = (struct hclge_func_status_cmd *)desc.data;
596 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
598 dev_err(&hdev->pdev->dev,
599 "query function status failed %d.\n",
605 /* Check pf reset is done */
608 usleep_range(1000, 2000);
609 } while (timeout++ < 5);
611 ret = hclge_parse_func_status(hdev, req);
616 static int hclge_query_pf_resource(struct hclge_dev *hdev)
618 struct hclge_pf_res_cmd *req;
619 struct hclge_desc desc;
622 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_PF_RSRC, true);
623 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
625 dev_err(&hdev->pdev->dev,
626 "query pf resource failed %d.\n", ret);
630 req = (struct hclge_pf_res_cmd *)desc.data;
631 hdev->num_tqps = __le16_to_cpu(req->tqp_num);
632 hdev->pkt_buf_size = __le16_to_cpu(req->buf_size) << HCLGE_BUF_UNIT_S;
634 if (hnae3_dev_roce_supported(hdev)) {
635 hdev->roce_base_msix_offset =
636 hnae3_get_field(__le16_to_cpu(req->msixcap_localid_ba_rocee),
637 HCLGE_MSIX_OFT_ROCEE_M, HCLGE_MSIX_OFT_ROCEE_S);
639 hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number),
640 HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S);
642 /* PF should have NIC vectors and Roce vectors,
643 * NIC vectors are queued before Roce vectors.
645 hdev->num_msi = hdev->num_roce_msi +
646 hdev->roce_base_msix_offset;
649 hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number),
650 HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S);
656 static int hclge_parse_speed(int speed_cmd, int *speed)
660 *speed = HCLGE_MAC_SPEED_10M;
663 *speed = HCLGE_MAC_SPEED_100M;
666 *speed = HCLGE_MAC_SPEED_1G;
669 *speed = HCLGE_MAC_SPEED_10G;
672 *speed = HCLGE_MAC_SPEED_25G;
675 *speed = HCLGE_MAC_SPEED_40G;
678 *speed = HCLGE_MAC_SPEED_50G;
681 *speed = HCLGE_MAC_SPEED_100G;
690 static void hclge_parse_fiber_link_mode(struct hclge_dev *hdev,
693 unsigned long *supported = hdev->hw.mac.supported;
695 if (speed_ability & HCLGE_SUPPORT_1G_BIT)
696 set_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
699 if (speed_ability & HCLGE_SUPPORT_10G_BIT)
700 set_bit(ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
703 if (speed_ability & HCLGE_SUPPORT_25G_BIT)
704 set_bit(ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
707 if (speed_ability & HCLGE_SUPPORT_50G_BIT)
708 set_bit(ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
711 if (speed_ability & HCLGE_SUPPORT_100G_BIT)
712 set_bit(ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
715 set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, supported);
716 set_bit(ETHTOOL_LINK_MODE_Pause_BIT, supported);
719 static void hclge_parse_link_mode(struct hclge_dev *hdev, u8 speed_ability)
721 u8 media_type = hdev->hw.mac.media_type;
723 if (media_type != HNAE3_MEDIA_TYPE_FIBER)
726 hclge_parse_fiber_link_mode(hdev, speed_ability);
729 static void hclge_parse_cfg(struct hclge_cfg *cfg, struct hclge_desc *desc)
731 struct hclge_cfg_param_cmd *req;
732 u64 mac_addr_tmp_high;
736 req = (struct hclge_cfg_param_cmd *)desc[0].data;
738 /* get the configuration */
739 cfg->vmdq_vport_num = hnae3_get_field(__le32_to_cpu(req->param[0]),
742 cfg->tc_num = hnae3_get_field(__le32_to_cpu(req->param[0]),
743 HCLGE_CFG_TC_NUM_M, HCLGE_CFG_TC_NUM_S);
744 cfg->tqp_desc_num = hnae3_get_field(__le32_to_cpu(req->param[0]),
745 HCLGE_CFG_TQP_DESC_N_M,
746 HCLGE_CFG_TQP_DESC_N_S);
748 cfg->phy_addr = hnae3_get_field(__le32_to_cpu(req->param[1]),
749 HCLGE_CFG_PHY_ADDR_M,
750 HCLGE_CFG_PHY_ADDR_S);
751 cfg->media_type = hnae3_get_field(__le32_to_cpu(req->param[1]),
752 HCLGE_CFG_MEDIA_TP_M,
753 HCLGE_CFG_MEDIA_TP_S);
754 cfg->rx_buf_len = hnae3_get_field(__le32_to_cpu(req->param[1]),
755 HCLGE_CFG_RX_BUF_LEN_M,
756 HCLGE_CFG_RX_BUF_LEN_S);
757 /* get mac_address */
758 mac_addr_tmp = __le32_to_cpu(req->param[2]);
759 mac_addr_tmp_high = hnae3_get_field(__le32_to_cpu(req->param[3]),
760 HCLGE_CFG_MAC_ADDR_H_M,
761 HCLGE_CFG_MAC_ADDR_H_S);
763 mac_addr_tmp |= (mac_addr_tmp_high << 31) << 1;
765 cfg->default_speed = hnae3_get_field(__le32_to_cpu(req->param[3]),
766 HCLGE_CFG_DEFAULT_SPEED_M,
767 HCLGE_CFG_DEFAULT_SPEED_S);
768 cfg->rss_size_max = hnae3_get_field(__le32_to_cpu(req->param[3]),
769 HCLGE_CFG_RSS_SIZE_M,
770 HCLGE_CFG_RSS_SIZE_S);
772 for (i = 0; i < ETH_ALEN; i++)
773 cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
775 req = (struct hclge_cfg_param_cmd *)desc[1].data;
776 cfg->numa_node_map = __le32_to_cpu(req->param[0]);
778 cfg->speed_ability = hnae3_get_field(__le32_to_cpu(req->param[1]),
779 HCLGE_CFG_SPEED_ABILITY_M,
780 HCLGE_CFG_SPEED_ABILITY_S);
781 cfg->umv_space = hnae3_get_field(__le32_to_cpu(req->param[1]),
782 HCLGE_CFG_UMV_TBL_SPACE_M,
783 HCLGE_CFG_UMV_TBL_SPACE_S);
785 cfg->umv_space = HCLGE_DEFAULT_UMV_SPACE_PER_PF;
788 /* hclge_get_cfg: query the static parameter from flash
789 * @hdev: pointer to struct hclge_dev
790 * @hcfg: the config structure to be getted
792 static int hclge_get_cfg(struct hclge_dev *hdev, struct hclge_cfg *hcfg)
794 struct hclge_desc desc[HCLGE_PF_CFG_DESC_NUM];
795 struct hclge_cfg_param_cmd *req;
798 for (i = 0; i < HCLGE_PF_CFG_DESC_NUM; i++) {
801 req = (struct hclge_cfg_param_cmd *)desc[i].data;
802 hclge_cmd_setup_basic_desc(&desc[i], HCLGE_OPC_GET_CFG_PARAM,
804 hnae3_set_field(offset, HCLGE_CFG_OFFSET_M,
805 HCLGE_CFG_OFFSET_S, i * HCLGE_CFG_RD_LEN_BYTES);
806 /* Len should be united by 4 bytes when send to hardware */
807 hnae3_set_field(offset, HCLGE_CFG_RD_LEN_M, HCLGE_CFG_RD_LEN_S,
808 HCLGE_CFG_RD_LEN_BYTES / HCLGE_CFG_RD_LEN_UNIT);
809 req->offset = cpu_to_le32(offset);
812 ret = hclge_cmd_send(&hdev->hw, desc, HCLGE_PF_CFG_DESC_NUM);
814 dev_err(&hdev->pdev->dev, "get config failed %d.\n", ret);
818 hclge_parse_cfg(hcfg, desc);
823 static int hclge_get_cap(struct hclge_dev *hdev)
827 ret = hclge_query_function_status(hdev);
829 dev_err(&hdev->pdev->dev,
830 "query function status error %d.\n", ret);
834 /* get pf resource */
835 ret = hclge_query_pf_resource(hdev);
837 dev_err(&hdev->pdev->dev, "query pf resource error %d.\n", ret);
842 static int hclge_configure(struct hclge_dev *hdev)
844 struct hclge_cfg cfg;
847 ret = hclge_get_cfg(hdev, &cfg);
849 dev_err(&hdev->pdev->dev, "get mac mode error %d.\n", ret);
853 hdev->num_vmdq_vport = cfg.vmdq_vport_num;
854 hdev->base_tqp_pid = 0;
855 hdev->rss_size_max = cfg.rss_size_max;
856 hdev->rx_buf_len = cfg.rx_buf_len;
857 ether_addr_copy(hdev->hw.mac.mac_addr, cfg.mac_addr);
858 hdev->hw.mac.media_type = cfg.media_type;
859 hdev->hw.mac.phy_addr = cfg.phy_addr;
860 hdev->num_desc = cfg.tqp_desc_num;
861 hdev->tm_info.num_pg = 1;
862 hdev->tc_max = cfg.tc_num;
863 hdev->tm_info.hw_pfc_map = 0;
864 hdev->wanted_umv_size = cfg.umv_space;
866 ret = hclge_parse_speed(cfg.default_speed, &hdev->hw.mac.speed);
868 dev_err(&hdev->pdev->dev, "Get wrong speed ret=%d.\n", ret);
872 hclge_parse_link_mode(hdev, cfg.speed_ability);
874 if ((hdev->tc_max > HNAE3_MAX_TC) ||
875 (hdev->tc_max < 1)) {
876 dev_warn(&hdev->pdev->dev, "TC num = %d.\n",
881 /* Dev does not support DCB */
882 if (!hnae3_dev_dcb_supported(hdev)) {
886 hdev->pfc_max = hdev->tc_max;
889 hdev->tm_info.num_tc = hdev->tc_max;
891 /* Currently not support uncontiuous tc */
892 for (i = 0; i < hdev->tm_info.num_tc; i++)
893 hnae3_set_bit(hdev->hw_tc_map, i, 1);
895 hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
900 static int hclge_config_tso(struct hclge_dev *hdev, int tso_mss_min,
903 struct hclge_cfg_tso_status_cmd *req;
904 struct hclge_desc desc;
907 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_TSO_GENERIC_CONFIG, false);
909 req = (struct hclge_cfg_tso_status_cmd *)desc.data;
912 hnae3_set_field(tso_mss, HCLGE_TSO_MSS_MIN_M,
913 HCLGE_TSO_MSS_MIN_S, tso_mss_min);
914 req->tso_mss_min = cpu_to_le16(tso_mss);
917 hnae3_set_field(tso_mss, HCLGE_TSO_MSS_MIN_M,
918 HCLGE_TSO_MSS_MIN_S, tso_mss_max);
919 req->tso_mss_max = cpu_to_le16(tso_mss);
921 return hclge_cmd_send(&hdev->hw, &desc, 1);
924 static int hclge_alloc_tqps(struct hclge_dev *hdev)
926 struct hclge_tqp *tqp;
929 hdev->htqp = devm_kcalloc(&hdev->pdev->dev, hdev->num_tqps,
930 sizeof(struct hclge_tqp), GFP_KERNEL);
936 for (i = 0; i < hdev->num_tqps; i++) {
937 tqp->dev = &hdev->pdev->dev;
940 tqp->q.ae_algo = &ae_algo;
941 tqp->q.buf_size = hdev->rx_buf_len;
942 tqp->q.desc_num = hdev->num_desc;
943 tqp->q.io_base = hdev->hw.io_base + HCLGE_TQP_REG_OFFSET +
944 i * HCLGE_TQP_REG_SIZE;
952 static int hclge_map_tqps_to_func(struct hclge_dev *hdev, u16 func_id,
953 u16 tqp_pid, u16 tqp_vid, bool is_pf)
955 struct hclge_tqp_map_cmd *req;
956 struct hclge_desc desc;
959 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SET_TQP_MAP, false);
961 req = (struct hclge_tqp_map_cmd *)desc.data;
962 req->tqp_id = cpu_to_le16(tqp_pid);
963 req->tqp_vf = func_id;
964 req->tqp_flag = !is_pf << HCLGE_TQP_MAP_TYPE_B |
965 1 << HCLGE_TQP_MAP_EN_B;
966 req->tqp_vid = cpu_to_le16(tqp_vid);
968 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
970 dev_err(&hdev->pdev->dev, "TQP map failed %d.\n", ret);
975 static int hclge_assign_tqp(struct hclge_vport *vport)
977 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
978 struct hclge_dev *hdev = vport->back;
981 for (i = 0, alloced = 0; i < hdev->num_tqps &&
982 alloced < kinfo->num_tqps; i++) {
983 if (!hdev->htqp[i].alloced) {
984 hdev->htqp[i].q.handle = &vport->nic;
985 hdev->htqp[i].q.tqp_index = alloced;
986 hdev->htqp[i].q.desc_num = kinfo->num_desc;
987 kinfo->tqp[alloced] = &hdev->htqp[i].q;
988 hdev->htqp[i].alloced = true;
992 vport->alloc_tqps = kinfo->num_tqps;
997 static int hclge_knic_setup(struct hclge_vport *vport,
998 u16 num_tqps, u16 num_desc)
1000 struct hnae3_handle *nic = &vport->nic;
1001 struct hnae3_knic_private_info *kinfo = &nic->kinfo;
1002 struct hclge_dev *hdev = vport->back;
1005 kinfo->num_desc = num_desc;
1006 kinfo->rx_buf_len = hdev->rx_buf_len;
1007 kinfo->num_tc = min_t(u16, num_tqps, hdev->tm_info.num_tc);
1009 = min_t(u16, hdev->rss_size_max, num_tqps / kinfo->num_tc);
1010 kinfo->num_tqps = kinfo->rss_size * kinfo->num_tc;
1012 for (i = 0; i < HNAE3_MAX_TC; i++) {
1013 if (hdev->hw_tc_map & BIT(i)) {
1014 kinfo->tc_info[i].enable = true;
1015 kinfo->tc_info[i].tqp_offset = i * kinfo->rss_size;
1016 kinfo->tc_info[i].tqp_count = kinfo->rss_size;
1017 kinfo->tc_info[i].tc = i;
1019 /* Set to default queue if TC is disable */
1020 kinfo->tc_info[i].enable = false;
1021 kinfo->tc_info[i].tqp_offset = 0;
1022 kinfo->tc_info[i].tqp_count = 1;
1023 kinfo->tc_info[i].tc = 0;
1027 kinfo->tqp = devm_kcalloc(&hdev->pdev->dev, kinfo->num_tqps,
1028 sizeof(struct hnae3_queue *), GFP_KERNEL);
1032 ret = hclge_assign_tqp(vport);
1034 dev_err(&hdev->pdev->dev, "fail to assign TQPs %d.\n", ret);
1039 static int hclge_map_tqp_to_vport(struct hclge_dev *hdev,
1040 struct hclge_vport *vport)
1042 struct hnae3_handle *nic = &vport->nic;
1043 struct hnae3_knic_private_info *kinfo;
1046 kinfo = &nic->kinfo;
1047 for (i = 0; i < kinfo->num_tqps; i++) {
1048 struct hclge_tqp *q =
1049 container_of(kinfo->tqp[i], struct hclge_tqp, q);
1053 is_pf = !(vport->vport_id);
1054 ret = hclge_map_tqps_to_func(hdev, vport->vport_id, q->index,
1063 static int hclge_map_tqp(struct hclge_dev *hdev)
1065 struct hclge_vport *vport = hdev->vport;
1068 num_vport = hdev->num_vmdq_vport + hdev->num_req_vfs + 1;
1069 for (i = 0; i < num_vport; i++) {
1072 ret = hclge_map_tqp_to_vport(hdev, vport);
1082 static void hclge_unic_setup(struct hclge_vport *vport, u16 num_tqps)
1084 /* this would be initialized later */
1087 static int hclge_vport_setup(struct hclge_vport *vport, u16 num_tqps)
1089 struct hnae3_handle *nic = &vport->nic;
1090 struct hclge_dev *hdev = vport->back;
1093 nic->pdev = hdev->pdev;
1094 nic->ae_algo = &ae_algo;
1095 nic->numa_node_mask = hdev->numa_node_mask;
1097 if (hdev->ae_dev->dev_type == HNAE3_DEV_KNIC) {
1098 ret = hclge_knic_setup(vport, num_tqps, hdev->num_desc);
1100 dev_err(&hdev->pdev->dev, "knic setup failed %d\n",
1105 hclge_unic_setup(vport, num_tqps);
1111 static int hclge_alloc_vport(struct hclge_dev *hdev)
1113 struct pci_dev *pdev = hdev->pdev;
1114 struct hclge_vport *vport;
1120 /* We need to alloc a vport for main NIC of PF */
1121 num_vport = hdev->num_vmdq_vport + hdev->num_req_vfs + 1;
1123 if (hdev->num_tqps < num_vport) {
1124 dev_err(&hdev->pdev->dev, "tqps(%d) is less than vports(%d)",
1125 hdev->num_tqps, num_vport);
1129 /* Alloc the same number of TQPs for every vport */
1130 tqp_per_vport = hdev->num_tqps / num_vport;
1131 tqp_main_vport = tqp_per_vport + hdev->num_tqps % num_vport;
1133 vport = devm_kcalloc(&pdev->dev, num_vport, sizeof(struct hclge_vport),
1138 hdev->vport = vport;
1139 hdev->num_alloc_vport = num_vport;
1141 if (IS_ENABLED(CONFIG_PCI_IOV))
1142 hdev->num_alloc_vfs = hdev->num_req_vfs;
1144 for (i = 0; i < num_vport; i++) {
1146 vport->vport_id = i;
1149 ret = hclge_vport_setup(vport, tqp_main_vport);
1151 ret = hclge_vport_setup(vport, tqp_per_vport);
1154 "vport setup failed for vport %d, %d\n",
1165 static int hclge_cmd_alloc_tx_buff(struct hclge_dev *hdev,
1166 struct hclge_pkt_buf_alloc *buf_alloc)
1168 /* TX buffer size is unit by 128 byte */
1169 #define HCLGE_BUF_SIZE_UNIT_SHIFT 7
1170 #define HCLGE_BUF_SIZE_UPDATE_EN_MSK BIT(15)
1171 struct hclge_tx_buff_alloc_cmd *req;
1172 struct hclge_desc desc;
1176 req = (struct hclge_tx_buff_alloc_cmd *)desc.data;
1178 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_TX_BUFF_ALLOC, 0);
1179 for (i = 0; i < HCLGE_TC_NUM; i++) {
1180 u32 buf_size = buf_alloc->priv_buf[i].tx_buf_size;
1182 req->tx_pkt_buff[i] =
1183 cpu_to_le16((buf_size >> HCLGE_BUF_SIZE_UNIT_SHIFT) |
1184 HCLGE_BUF_SIZE_UPDATE_EN_MSK);
1187 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1189 dev_err(&hdev->pdev->dev, "tx buffer alloc cmd failed %d.\n",
1195 static int hclge_tx_buffer_alloc(struct hclge_dev *hdev,
1196 struct hclge_pkt_buf_alloc *buf_alloc)
1198 int ret = hclge_cmd_alloc_tx_buff(hdev, buf_alloc);
1201 dev_err(&hdev->pdev->dev, "tx buffer alloc failed %d\n", ret);
1206 static int hclge_get_tc_num(struct hclge_dev *hdev)
1210 for (i = 0; i < HCLGE_MAX_TC_NUM; i++)
1211 if (hdev->hw_tc_map & BIT(i))
1216 static int hclge_get_pfc_enalbe_num(struct hclge_dev *hdev)
1220 for (i = 0; i < HCLGE_MAX_TC_NUM; i++)
1221 if (hdev->hw_tc_map & BIT(i) &&
1222 hdev->tm_info.hw_pfc_map & BIT(i))
1227 /* Get the number of pfc enabled TCs, which have private buffer */
1228 static int hclge_get_pfc_priv_num(struct hclge_dev *hdev,
1229 struct hclge_pkt_buf_alloc *buf_alloc)
1231 struct hclge_priv_buf *priv;
1234 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1235 priv = &buf_alloc->priv_buf[i];
1236 if ((hdev->tm_info.hw_pfc_map & BIT(i)) &&
1244 /* Get the number of pfc disabled TCs, which have private buffer */
1245 static int hclge_get_no_pfc_priv_num(struct hclge_dev *hdev,
1246 struct hclge_pkt_buf_alloc *buf_alloc)
1248 struct hclge_priv_buf *priv;
1251 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1252 priv = &buf_alloc->priv_buf[i];
1253 if (hdev->hw_tc_map & BIT(i) &&
1254 !(hdev->tm_info.hw_pfc_map & BIT(i)) &&
1262 static u32 hclge_get_rx_priv_buff_alloced(struct hclge_pkt_buf_alloc *buf_alloc)
1264 struct hclge_priv_buf *priv;
1268 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1269 priv = &buf_alloc->priv_buf[i];
1271 rx_priv += priv->buf_size;
1276 static u32 hclge_get_tx_buff_alloced(struct hclge_pkt_buf_alloc *buf_alloc)
1278 u32 i, total_tx_size = 0;
1280 for (i = 0; i < HCLGE_MAX_TC_NUM; i++)
1281 total_tx_size += buf_alloc->priv_buf[i].tx_buf_size;
1283 return total_tx_size;
1286 static bool hclge_is_rx_buf_ok(struct hclge_dev *hdev,
1287 struct hclge_pkt_buf_alloc *buf_alloc,
1290 u32 shared_buf_min, shared_buf_tc, shared_std;
1291 int tc_num, pfc_enable_num;
1296 tc_num = hclge_get_tc_num(hdev);
1297 pfc_enable_num = hclge_get_pfc_enalbe_num(hdev);
1299 if (hnae3_dev_dcb_supported(hdev))
1300 shared_buf_min = 2 * hdev->mps + HCLGE_DEFAULT_DV;
1302 shared_buf_min = 2 * hdev->mps + HCLGE_DEFAULT_NON_DCB_DV;
1304 shared_buf_tc = pfc_enable_num * hdev->mps +
1305 (tc_num - pfc_enable_num) * hdev->mps / 2 +
1307 shared_std = max_t(u32, shared_buf_min, shared_buf_tc);
1309 rx_priv = hclge_get_rx_priv_buff_alloced(buf_alloc);
1310 if (rx_all <= rx_priv + shared_std)
1313 shared_buf = rx_all - rx_priv;
1314 buf_alloc->s_buf.buf_size = shared_buf;
1315 buf_alloc->s_buf.self.high = shared_buf;
1316 buf_alloc->s_buf.self.low = 2 * hdev->mps;
1318 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1319 if ((hdev->hw_tc_map & BIT(i)) &&
1320 (hdev->tm_info.hw_pfc_map & BIT(i))) {
1321 buf_alloc->s_buf.tc_thrd[i].low = hdev->mps;
1322 buf_alloc->s_buf.tc_thrd[i].high = 2 * hdev->mps;
1324 buf_alloc->s_buf.tc_thrd[i].low = 0;
1325 buf_alloc->s_buf.tc_thrd[i].high = hdev->mps;
1332 static int hclge_tx_buffer_calc(struct hclge_dev *hdev,
1333 struct hclge_pkt_buf_alloc *buf_alloc)
1337 total_size = hdev->pkt_buf_size;
1339 /* alloc tx buffer for all enabled tc */
1340 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1341 struct hclge_priv_buf *priv = &buf_alloc->priv_buf[i];
1343 if (total_size < HCLGE_DEFAULT_TX_BUF)
1346 if (hdev->hw_tc_map & BIT(i))
1347 priv->tx_buf_size = HCLGE_DEFAULT_TX_BUF;
1349 priv->tx_buf_size = 0;
1351 total_size -= priv->tx_buf_size;
1357 /* hclge_rx_buffer_calc: calculate the rx private buffer size for all TCs
1358 * @hdev: pointer to struct hclge_dev
1359 * @buf_alloc: pointer to buffer calculation data
1360 * @return: 0: calculate sucessful, negative: fail
1362 static int hclge_rx_buffer_calc(struct hclge_dev *hdev,
1363 struct hclge_pkt_buf_alloc *buf_alloc)
1365 #define HCLGE_BUF_SIZE_UNIT 128
1366 u32 rx_all = hdev->pkt_buf_size, aligned_mps;
1367 int no_pfc_priv_num, pfc_priv_num;
1368 struct hclge_priv_buf *priv;
1371 aligned_mps = round_up(hdev->mps, HCLGE_BUF_SIZE_UNIT);
1372 rx_all -= hclge_get_tx_buff_alloced(buf_alloc);
1374 /* When DCB is not supported, rx private
1375 * buffer is not allocated.
1377 if (!hnae3_dev_dcb_supported(hdev)) {
1378 if (!hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all))
1384 /* step 1, try to alloc private buffer for all enabled tc */
1385 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1386 priv = &buf_alloc->priv_buf[i];
1387 if (hdev->hw_tc_map & BIT(i)) {
1389 if (hdev->tm_info.hw_pfc_map & BIT(i)) {
1390 priv->wl.low = aligned_mps;
1391 priv->wl.high = priv->wl.low + aligned_mps;
1392 priv->buf_size = priv->wl.high +
1396 priv->wl.high = 2 * aligned_mps;
1397 priv->buf_size = priv->wl.high;
1407 if (hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all))
1410 /* step 2, try to decrease the buffer size of
1411 * no pfc TC's private buffer
1413 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1414 priv = &buf_alloc->priv_buf[i];
1421 if (!(hdev->hw_tc_map & BIT(i)))
1426 if (hdev->tm_info.hw_pfc_map & BIT(i)) {
1428 priv->wl.high = priv->wl.low + aligned_mps;
1429 priv->buf_size = priv->wl.high + HCLGE_DEFAULT_DV;
1432 priv->wl.high = aligned_mps;
1433 priv->buf_size = priv->wl.high;
1437 if (hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all))
1440 /* step 3, try to reduce the number of pfc disabled TCs,
1441 * which have private buffer
1443 /* get the total no pfc enable TC number, which have private buffer */
1444 no_pfc_priv_num = hclge_get_no_pfc_priv_num(hdev, buf_alloc);
1446 /* let the last to be cleared first */
1447 for (i = HCLGE_MAX_TC_NUM - 1; i >= 0; i--) {
1448 priv = &buf_alloc->priv_buf[i];
1450 if (hdev->hw_tc_map & BIT(i) &&
1451 !(hdev->tm_info.hw_pfc_map & BIT(i))) {
1452 /* Clear the no pfc TC private buffer */
1460 if (hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all) ||
1461 no_pfc_priv_num == 0)
1465 if (hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all))
1468 /* step 4, try to reduce the number of pfc enabled TCs
1469 * which have private buffer.
1471 pfc_priv_num = hclge_get_pfc_priv_num(hdev, buf_alloc);
1473 /* let the last to be cleared first */
1474 for (i = HCLGE_MAX_TC_NUM - 1; i >= 0; i--) {
1475 priv = &buf_alloc->priv_buf[i];
1477 if (hdev->hw_tc_map & BIT(i) &&
1478 hdev->tm_info.hw_pfc_map & BIT(i)) {
1479 /* Reduce the number of pfc TC with private buffer */
1487 if (hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all) ||
1491 if (hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all))
1497 static int hclge_rx_priv_buf_alloc(struct hclge_dev *hdev,
1498 struct hclge_pkt_buf_alloc *buf_alloc)
1500 struct hclge_rx_priv_buff_cmd *req;
1501 struct hclge_desc desc;
1505 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RX_PRIV_BUFF_ALLOC, false);
1506 req = (struct hclge_rx_priv_buff_cmd *)desc.data;
1508 /* Alloc private buffer TCs */
1509 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
1510 struct hclge_priv_buf *priv = &buf_alloc->priv_buf[i];
1513 cpu_to_le16(priv->buf_size >> HCLGE_BUF_UNIT_S);
1515 cpu_to_le16(1 << HCLGE_TC0_PRI_BUF_EN_B);
1519 cpu_to_le16((buf_alloc->s_buf.buf_size >> HCLGE_BUF_UNIT_S) |
1520 (1 << HCLGE_TC0_PRI_BUF_EN_B));
1522 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1524 dev_err(&hdev->pdev->dev,
1525 "rx private buffer alloc cmd failed %d\n", ret);
1530 static int hclge_rx_priv_wl_config(struct hclge_dev *hdev,
1531 struct hclge_pkt_buf_alloc *buf_alloc)
1533 struct hclge_rx_priv_wl_buf *req;
1534 struct hclge_priv_buf *priv;
1535 struct hclge_desc desc[2];
1539 for (i = 0; i < 2; i++) {
1540 hclge_cmd_setup_basic_desc(&desc[i], HCLGE_OPC_RX_PRIV_WL_ALLOC,
1542 req = (struct hclge_rx_priv_wl_buf *)desc[i].data;
1544 /* The first descriptor set the NEXT bit to 1 */
1546 desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
1548 desc[i].flag &= ~cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
1550 for (j = 0; j < HCLGE_TC_NUM_ONE_DESC; j++) {
1551 u32 idx = i * HCLGE_TC_NUM_ONE_DESC + j;
1553 priv = &buf_alloc->priv_buf[idx];
1554 req->tc_wl[j].high =
1555 cpu_to_le16(priv->wl.high >> HCLGE_BUF_UNIT_S);
1556 req->tc_wl[j].high |=
1557 cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
1559 cpu_to_le16(priv->wl.low >> HCLGE_BUF_UNIT_S);
1560 req->tc_wl[j].low |=
1561 cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
1565 /* Send 2 descriptor at one time */
1566 ret = hclge_cmd_send(&hdev->hw, desc, 2);
1568 dev_err(&hdev->pdev->dev,
1569 "rx private waterline config cmd failed %d\n",
1574 static int hclge_common_thrd_config(struct hclge_dev *hdev,
1575 struct hclge_pkt_buf_alloc *buf_alloc)
1577 struct hclge_shared_buf *s_buf = &buf_alloc->s_buf;
1578 struct hclge_rx_com_thrd *req;
1579 struct hclge_desc desc[2];
1580 struct hclge_tc_thrd *tc;
1584 for (i = 0; i < 2; i++) {
1585 hclge_cmd_setup_basic_desc(&desc[i],
1586 HCLGE_OPC_RX_COM_THRD_ALLOC, false);
1587 req = (struct hclge_rx_com_thrd *)&desc[i].data;
1589 /* The first descriptor set the NEXT bit to 1 */
1591 desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
1593 desc[i].flag &= ~cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
1595 for (j = 0; j < HCLGE_TC_NUM_ONE_DESC; j++) {
1596 tc = &s_buf->tc_thrd[i * HCLGE_TC_NUM_ONE_DESC + j];
1598 req->com_thrd[j].high =
1599 cpu_to_le16(tc->high >> HCLGE_BUF_UNIT_S);
1600 req->com_thrd[j].high |=
1601 cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
1602 req->com_thrd[j].low =
1603 cpu_to_le16(tc->low >> HCLGE_BUF_UNIT_S);
1604 req->com_thrd[j].low |=
1605 cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
1609 /* Send 2 descriptors at one time */
1610 ret = hclge_cmd_send(&hdev->hw, desc, 2);
1612 dev_err(&hdev->pdev->dev,
1613 "common threshold config cmd failed %d\n", ret);
1617 static int hclge_common_wl_config(struct hclge_dev *hdev,
1618 struct hclge_pkt_buf_alloc *buf_alloc)
1620 struct hclge_shared_buf *buf = &buf_alloc->s_buf;
1621 struct hclge_rx_com_wl *req;
1622 struct hclge_desc desc;
1625 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RX_COM_WL_ALLOC, false);
1627 req = (struct hclge_rx_com_wl *)desc.data;
1628 req->com_wl.high = cpu_to_le16(buf->self.high >> HCLGE_BUF_UNIT_S);
1629 req->com_wl.high |= cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
1631 req->com_wl.low = cpu_to_le16(buf->self.low >> HCLGE_BUF_UNIT_S);
1632 req->com_wl.low |= cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
1634 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1636 dev_err(&hdev->pdev->dev,
1637 "common waterline config cmd failed %d\n", ret);
1642 int hclge_buffer_alloc(struct hclge_dev *hdev)
1644 struct hclge_pkt_buf_alloc *pkt_buf;
1647 pkt_buf = kzalloc(sizeof(*pkt_buf), GFP_KERNEL);
1651 ret = hclge_tx_buffer_calc(hdev, pkt_buf);
1653 dev_err(&hdev->pdev->dev,
1654 "could not calc tx buffer size for all TCs %d\n", ret);
1658 ret = hclge_tx_buffer_alloc(hdev, pkt_buf);
1660 dev_err(&hdev->pdev->dev,
1661 "could not alloc tx buffers %d\n", ret);
1665 ret = hclge_rx_buffer_calc(hdev, pkt_buf);
1667 dev_err(&hdev->pdev->dev,
1668 "could not calc rx priv buffer size for all TCs %d\n",
1673 ret = hclge_rx_priv_buf_alloc(hdev, pkt_buf);
1675 dev_err(&hdev->pdev->dev, "could not alloc rx priv buffer %d\n",
1680 if (hnae3_dev_dcb_supported(hdev)) {
1681 ret = hclge_rx_priv_wl_config(hdev, pkt_buf);
1683 dev_err(&hdev->pdev->dev,
1684 "could not configure rx private waterline %d\n",
1689 ret = hclge_common_thrd_config(hdev, pkt_buf);
1691 dev_err(&hdev->pdev->dev,
1692 "could not configure common threshold %d\n",
1698 ret = hclge_common_wl_config(hdev, pkt_buf);
1700 dev_err(&hdev->pdev->dev,
1701 "could not configure common waterline %d\n", ret);
1708 static int hclge_init_roce_base_info(struct hclge_vport *vport)
1710 struct hnae3_handle *roce = &vport->roce;
1711 struct hnae3_handle *nic = &vport->nic;
1713 roce->rinfo.num_vectors = vport->back->num_roce_msi;
1715 if (vport->back->num_msi_left < vport->roce.rinfo.num_vectors ||
1716 vport->back->num_msi_left == 0)
1719 roce->rinfo.base_vector = vport->back->roce_base_vector;
1721 roce->rinfo.netdev = nic->kinfo.netdev;
1722 roce->rinfo.roce_io_base = vport->back->hw.io_base;
1724 roce->pdev = nic->pdev;
1725 roce->ae_algo = nic->ae_algo;
1726 roce->numa_node_mask = nic->numa_node_mask;
1731 static int hclge_init_msi(struct hclge_dev *hdev)
1733 struct pci_dev *pdev = hdev->pdev;
1737 vectors = pci_alloc_irq_vectors(pdev, 1, hdev->num_msi,
1738 PCI_IRQ_MSI | PCI_IRQ_MSIX);
1741 "failed(%d) to allocate MSI/MSI-X vectors\n",
1745 if (vectors < hdev->num_msi)
1746 dev_warn(&hdev->pdev->dev,
1747 "requested %d MSI/MSI-X, but allocated %d MSI/MSI-X\n",
1748 hdev->num_msi, vectors);
1750 hdev->num_msi = vectors;
1751 hdev->num_msi_left = vectors;
1752 hdev->base_msi_vector = pdev->irq;
1753 hdev->roce_base_vector = hdev->base_msi_vector +
1754 hdev->roce_base_msix_offset;
1756 hdev->vector_status = devm_kcalloc(&pdev->dev, hdev->num_msi,
1757 sizeof(u16), GFP_KERNEL);
1758 if (!hdev->vector_status) {
1759 pci_free_irq_vectors(pdev);
1763 for (i = 0; i < hdev->num_msi; i++)
1764 hdev->vector_status[i] = HCLGE_INVALID_VPORT;
1766 hdev->vector_irq = devm_kcalloc(&pdev->dev, hdev->num_msi,
1767 sizeof(int), GFP_KERNEL);
1768 if (!hdev->vector_irq) {
1769 pci_free_irq_vectors(pdev);
1776 static u8 hclge_check_speed_dup(u8 duplex, int speed)
1779 if (!(speed == HCLGE_MAC_SPEED_10M || speed == HCLGE_MAC_SPEED_100M))
1780 duplex = HCLGE_MAC_FULL;
1785 static int hclge_cfg_mac_speed_dup_hw(struct hclge_dev *hdev, int speed,
1788 struct hclge_config_mac_speed_dup_cmd *req;
1789 struct hclge_desc desc;
1792 req = (struct hclge_config_mac_speed_dup_cmd *)desc.data;
1794 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_SPEED_DUP, false);
1796 hnae3_set_bit(req->speed_dup, HCLGE_CFG_DUPLEX_B, !!duplex);
1799 case HCLGE_MAC_SPEED_10M:
1800 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1801 HCLGE_CFG_SPEED_S, 6);
1803 case HCLGE_MAC_SPEED_100M:
1804 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1805 HCLGE_CFG_SPEED_S, 7);
1807 case HCLGE_MAC_SPEED_1G:
1808 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1809 HCLGE_CFG_SPEED_S, 0);
1811 case HCLGE_MAC_SPEED_10G:
1812 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1813 HCLGE_CFG_SPEED_S, 1);
1815 case HCLGE_MAC_SPEED_25G:
1816 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1817 HCLGE_CFG_SPEED_S, 2);
1819 case HCLGE_MAC_SPEED_40G:
1820 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1821 HCLGE_CFG_SPEED_S, 3);
1823 case HCLGE_MAC_SPEED_50G:
1824 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1825 HCLGE_CFG_SPEED_S, 4);
1827 case HCLGE_MAC_SPEED_100G:
1828 hnae3_set_field(req->speed_dup, HCLGE_CFG_SPEED_M,
1829 HCLGE_CFG_SPEED_S, 5);
1832 dev_err(&hdev->pdev->dev, "invalid speed (%d)\n", speed);
1836 hnae3_set_bit(req->mac_change_fec_en, HCLGE_CFG_MAC_SPEED_CHANGE_EN_B,
1839 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1841 dev_err(&hdev->pdev->dev,
1842 "mac speed/duplex config cmd failed %d.\n", ret);
1849 int hclge_cfg_mac_speed_dup(struct hclge_dev *hdev, int speed, u8 duplex)
1853 duplex = hclge_check_speed_dup(duplex, speed);
1854 if (hdev->hw.mac.speed == speed && hdev->hw.mac.duplex == duplex)
1857 ret = hclge_cfg_mac_speed_dup_hw(hdev, speed, duplex);
1861 hdev->hw.mac.speed = speed;
1862 hdev->hw.mac.duplex = duplex;
1867 static int hclge_cfg_mac_speed_dup_h(struct hnae3_handle *handle, int speed,
1870 struct hclge_vport *vport = hclge_get_vport(handle);
1871 struct hclge_dev *hdev = vport->back;
1873 return hclge_cfg_mac_speed_dup(hdev, speed, duplex);
1876 static int hclge_query_mac_an_speed_dup(struct hclge_dev *hdev, int *speed,
1879 struct hclge_query_an_speed_dup_cmd *req;
1880 struct hclge_desc desc;
1884 req = (struct hclge_query_an_speed_dup_cmd *)desc.data;
1886 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_AN_RESULT, true);
1887 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1889 dev_err(&hdev->pdev->dev,
1890 "mac speed/autoneg/duplex query cmd failed %d\n",
1895 *duplex = hnae3_get_bit(req->an_syn_dup_speed, HCLGE_QUERY_DUPLEX_B);
1896 speed_tmp = hnae3_get_field(req->an_syn_dup_speed, HCLGE_QUERY_SPEED_M,
1897 HCLGE_QUERY_SPEED_S);
1899 ret = hclge_parse_speed(speed_tmp, speed);
1901 dev_err(&hdev->pdev->dev,
1902 "could not parse speed(=%d), %d\n", speed_tmp, ret);
1907 static int hclge_set_autoneg_en(struct hclge_dev *hdev, bool enable)
1909 struct hclge_config_auto_neg_cmd *req;
1910 struct hclge_desc desc;
1914 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_AN_MODE, false);
1916 req = (struct hclge_config_auto_neg_cmd *)desc.data;
1917 hnae3_set_bit(flag, HCLGE_MAC_CFG_AN_EN_B, !!enable);
1918 req->cfg_an_cmd_flag = cpu_to_le32(flag);
1920 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1922 dev_err(&hdev->pdev->dev, "auto neg set cmd failed %d.\n",
1928 static int hclge_set_autoneg(struct hnae3_handle *handle, bool enable)
1930 struct hclge_vport *vport = hclge_get_vport(handle);
1931 struct hclge_dev *hdev = vport->back;
1933 return hclge_set_autoneg_en(hdev, enable);
1936 static int hclge_get_autoneg(struct hnae3_handle *handle)
1938 struct hclge_vport *vport = hclge_get_vport(handle);
1939 struct hclge_dev *hdev = vport->back;
1940 struct phy_device *phydev = hdev->hw.mac.phydev;
1943 return phydev->autoneg;
1945 return hdev->hw.mac.autoneg;
1948 static int hclge_mac_init(struct hclge_dev *hdev)
1950 struct hnae3_handle *handle = &hdev->vport[0].nic;
1951 struct net_device *netdev = handle->kinfo.netdev;
1952 struct hclge_mac *mac = &hdev->hw.mac;
1956 hdev->hw.mac.duplex = HCLGE_MAC_FULL;
1957 ret = hclge_cfg_mac_speed_dup_hw(hdev, hdev->hw.mac.speed,
1958 hdev->hw.mac.duplex);
1960 dev_err(&hdev->pdev->dev,
1961 "Config mac speed dup fail ret=%d\n", ret);
1972 ret = hclge_set_mtu(handle, mtu);
1974 dev_err(&hdev->pdev->dev,
1975 "set mtu failed ret=%d\n", ret);
1980 static void hclge_mbx_task_schedule(struct hclge_dev *hdev)
1982 if (!test_and_set_bit(HCLGE_STATE_MBX_SERVICE_SCHED, &hdev->state))
1983 schedule_work(&hdev->mbx_service_task);
1986 static void hclge_reset_task_schedule(struct hclge_dev *hdev)
1988 if (!test_and_set_bit(HCLGE_STATE_RST_SERVICE_SCHED, &hdev->state))
1989 schedule_work(&hdev->rst_service_task);
1992 static void hclge_task_schedule(struct hclge_dev *hdev)
1994 if (!test_bit(HCLGE_STATE_DOWN, &hdev->state) &&
1995 !test_bit(HCLGE_STATE_REMOVING, &hdev->state) &&
1996 !test_and_set_bit(HCLGE_STATE_SERVICE_SCHED, &hdev->state))
1997 (void)schedule_work(&hdev->service_task);
2000 static int hclge_get_mac_link_status(struct hclge_dev *hdev)
2002 struct hclge_link_status_cmd *req;
2003 struct hclge_desc desc;
2007 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_LINK_STATUS, true);
2008 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
2010 dev_err(&hdev->pdev->dev, "get link status cmd failed %d\n",
2015 req = (struct hclge_link_status_cmd *)desc.data;
2016 link_status = req->status & HCLGE_LINK_STATUS_UP_M;
2018 return !!link_status;
2021 static int hclge_get_mac_phy_link(struct hclge_dev *hdev)
2026 if (test_bit(HCLGE_STATE_DOWN, &hdev->state))
2029 mac_state = hclge_get_mac_link_status(hdev);
2031 if (hdev->hw.mac.phydev) {
2032 if (hdev->hw.mac.phydev->state == PHY_RUNNING)
2033 link_stat = mac_state &
2034 hdev->hw.mac.phydev->link;
2039 link_stat = mac_state;
2045 static void hclge_update_link_status(struct hclge_dev *hdev)
2047 struct hnae3_client *client = hdev->nic_client;
2048 struct hnae3_handle *handle;
2054 state = hclge_get_mac_phy_link(hdev);
2055 if (state != hdev->hw.mac.link) {
2056 for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
2057 handle = &hdev->vport[i].nic;
2058 client->ops->link_status_change(handle, state);
2060 hdev->hw.mac.link = state;
2064 static int hclge_update_speed_duplex(struct hclge_dev *hdev)
2066 struct hclge_mac mac = hdev->hw.mac;
2071 /* get the speed and duplex as autoneg'result from mac cmd when phy
2074 if (mac.phydev || !mac.autoneg)
2077 ret = hclge_query_mac_an_speed_dup(hdev, &speed, &duplex);
2079 dev_err(&hdev->pdev->dev,
2080 "mac autoneg/speed/duplex query failed %d\n", ret);
2084 ret = hclge_cfg_mac_speed_dup(hdev, speed, duplex);
2086 dev_err(&hdev->pdev->dev,
2087 "mac speed/duplex config failed %d\n", ret);
2094 static int hclge_update_speed_duplex_h(struct hnae3_handle *handle)
2096 struct hclge_vport *vport = hclge_get_vport(handle);
2097 struct hclge_dev *hdev = vport->back;
2099 return hclge_update_speed_duplex(hdev);
2102 static int hclge_get_status(struct hnae3_handle *handle)
2104 struct hclge_vport *vport = hclge_get_vport(handle);
2105 struct hclge_dev *hdev = vport->back;
2107 hclge_update_link_status(hdev);
2109 return hdev->hw.mac.link;
2112 static void hclge_service_timer(struct timer_list *t)
2114 struct hclge_dev *hdev = from_timer(hdev, t, service_timer);
2116 mod_timer(&hdev->service_timer, jiffies + HZ);
2117 hdev->hw_stats.stats_timer++;
2118 hclge_task_schedule(hdev);
2121 static void hclge_service_complete(struct hclge_dev *hdev)
2123 WARN_ON(!test_bit(HCLGE_STATE_SERVICE_SCHED, &hdev->state));
2125 /* Flush memory before next watchdog */
2126 smp_mb__before_atomic();
2127 clear_bit(HCLGE_STATE_SERVICE_SCHED, &hdev->state);
2130 static u32 hclge_check_event_cause(struct hclge_dev *hdev, u32 *clearval)
2135 /* fetch the events from their corresponding regs */
2136 rst_src_reg = hclge_read_dev(&hdev->hw, HCLGE_MISC_VECTOR_INT_STS);
2137 cmdq_src_reg = hclge_read_dev(&hdev->hw, HCLGE_VECTOR0_CMDQ_SRC_REG);
2139 /* Assumption: If by any chance reset and mailbox events are reported
2140 * together then we will only process reset event in this go and will
2141 * defer the processing of the mailbox events. Since, we would have not
2142 * cleared RX CMDQ event this time we would receive again another
2143 * interrupt from H/W just for the mailbox.
2146 /* check for vector0 reset event sources */
2147 if (BIT(HCLGE_VECTOR0_GLOBALRESET_INT_B) & rst_src_reg) {
2148 dev_info(&hdev->pdev->dev, "global reset interrupt\n");
2149 set_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
2150 set_bit(HNAE3_GLOBAL_RESET, &hdev->reset_pending);
2151 *clearval = BIT(HCLGE_VECTOR0_GLOBALRESET_INT_B);
2152 return HCLGE_VECTOR0_EVENT_RST;
2155 if (BIT(HCLGE_VECTOR0_CORERESET_INT_B) & rst_src_reg) {
2156 dev_info(&hdev->pdev->dev, "core reset interrupt\n");
2157 set_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
2158 set_bit(HNAE3_CORE_RESET, &hdev->reset_pending);
2159 *clearval = BIT(HCLGE_VECTOR0_CORERESET_INT_B);
2160 return HCLGE_VECTOR0_EVENT_RST;
2163 if (BIT(HCLGE_VECTOR0_IMPRESET_INT_B) & rst_src_reg) {
2164 dev_info(&hdev->pdev->dev, "IMP reset interrupt\n");
2165 set_bit(HNAE3_IMP_RESET, &hdev->reset_pending);
2166 *clearval = BIT(HCLGE_VECTOR0_IMPRESET_INT_B);
2167 return HCLGE_VECTOR0_EVENT_RST;
2170 /* check for vector0 mailbox(=CMDQ RX) event source */
2171 if (BIT(HCLGE_VECTOR0_RX_CMDQ_INT_B) & cmdq_src_reg) {
2172 cmdq_src_reg &= ~BIT(HCLGE_VECTOR0_RX_CMDQ_INT_B);
2173 *clearval = cmdq_src_reg;
2174 return HCLGE_VECTOR0_EVENT_MBX;
2177 return HCLGE_VECTOR0_EVENT_OTHER;
2180 static void hclge_clear_event_cause(struct hclge_dev *hdev, u32 event_type,
2183 switch (event_type) {
2184 case HCLGE_VECTOR0_EVENT_RST:
2185 hclge_write_dev(&hdev->hw, HCLGE_MISC_RESET_STS_REG, regclr);
2187 case HCLGE_VECTOR0_EVENT_MBX:
2188 hclge_write_dev(&hdev->hw, HCLGE_VECTOR0_CMDQ_SRC_REG, regclr);
2195 static void hclge_clear_all_event_cause(struct hclge_dev *hdev)
2197 hclge_clear_event_cause(hdev, HCLGE_VECTOR0_EVENT_RST,
2198 BIT(HCLGE_VECTOR0_GLOBALRESET_INT_B) |
2199 BIT(HCLGE_VECTOR0_CORERESET_INT_B) |
2200 BIT(HCLGE_VECTOR0_IMPRESET_INT_B));
2201 hclge_clear_event_cause(hdev, HCLGE_VECTOR0_EVENT_MBX, 0);
2204 static void hclge_enable_vector(struct hclge_misc_vector *vector, bool enable)
2206 writel(enable ? 1 : 0, vector->addr);
2209 static irqreturn_t hclge_misc_irq_handle(int irq, void *data)
2211 struct hclge_dev *hdev = data;
2215 hclge_enable_vector(&hdev->misc_vector, false);
2216 event_cause = hclge_check_event_cause(hdev, &clearval);
2218 /* vector 0 interrupt is shared with reset and mailbox source events.*/
2219 switch (event_cause) {
2220 case HCLGE_VECTOR0_EVENT_RST:
2221 hclge_reset_task_schedule(hdev);
2223 case HCLGE_VECTOR0_EVENT_MBX:
2224 /* If we are here then,
2225 * 1. Either we are not handling any mbx task and we are not
2228 * 2. We could be handling a mbx task but nothing more is
2230 * In both cases, we should schedule mbx task as there are more
2231 * mbx messages reported by this interrupt.
2233 hclge_mbx_task_schedule(hdev);
2236 dev_warn(&hdev->pdev->dev,
2237 "received unknown or unhandled event of vector0\n");
2241 /* clear the source of interrupt if it is not cause by reset */
2242 if (event_cause == HCLGE_VECTOR0_EVENT_MBX) {
2243 hclge_clear_event_cause(hdev, event_cause, clearval);
2244 hclge_enable_vector(&hdev->misc_vector, true);
2250 static void hclge_free_vector(struct hclge_dev *hdev, int vector_id)
2252 if (hdev->vector_status[vector_id] == HCLGE_INVALID_VPORT) {
2253 dev_warn(&hdev->pdev->dev,
2254 "vector(vector_id %d) has been freed.\n", vector_id);
2258 hdev->vector_status[vector_id] = HCLGE_INVALID_VPORT;
2259 hdev->num_msi_left += 1;
2260 hdev->num_msi_used -= 1;
2263 static void hclge_get_misc_vector(struct hclge_dev *hdev)
2265 struct hclge_misc_vector *vector = &hdev->misc_vector;
2267 vector->vector_irq = pci_irq_vector(hdev->pdev, 0);
2269 vector->addr = hdev->hw.io_base + HCLGE_MISC_VECTOR_REG_BASE;
2270 hdev->vector_status[0] = 0;
2272 hdev->num_msi_left -= 1;
2273 hdev->num_msi_used += 1;
2276 static int hclge_misc_irq_init(struct hclge_dev *hdev)
2280 hclge_get_misc_vector(hdev);
2282 /* this would be explicitly freed in the end */
2283 ret = request_irq(hdev->misc_vector.vector_irq, hclge_misc_irq_handle,
2284 0, "hclge_misc", hdev);
2286 hclge_free_vector(hdev, 0);
2287 dev_err(&hdev->pdev->dev, "request misc irq(%d) fail\n",
2288 hdev->misc_vector.vector_irq);
2294 static void hclge_misc_irq_uninit(struct hclge_dev *hdev)
2296 free_irq(hdev->misc_vector.vector_irq, hdev);
2297 hclge_free_vector(hdev, 0);
2300 static int hclge_notify_client(struct hclge_dev *hdev,
2301 enum hnae3_reset_notify_type type)
2303 struct hnae3_client *client = hdev->nic_client;
2306 if (!client->ops->reset_notify)
2309 for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
2310 struct hnae3_handle *handle = &hdev->vport[i].nic;
2313 ret = client->ops->reset_notify(handle, type);
2315 dev_err(&hdev->pdev->dev,
2316 "notify nic client failed %d(%d)\n", type, ret);
2324 static int hclge_notify_roce_client(struct hclge_dev *hdev,
2325 enum hnae3_reset_notify_type type)
2327 struct hnae3_client *client = hdev->roce_client;
2334 if (!client->ops->reset_notify)
2337 for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
2338 struct hnae3_handle *handle = &hdev->vport[i].roce;
2340 ret = client->ops->reset_notify(handle, type);
2342 dev_err(&hdev->pdev->dev,
2343 "notify roce client failed %d(%d)",
2352 static int hclge_reset_wait(struct hclge_dev *hdev)
2354 #define HCLGE_RESET_WATI_MS 100
2355 #define HCLGE_RESET_WAIT_CNT 5
2356 u32 val, reg, reg_bit;
2359 switch (hdev->reset_type) {
2360 case HNAE3_GLOBAL_RESET:
2361 reg = HCLGE_GLOBAL_RESET_REG;
2362 reg_bit = HCLGE_GLOBAL_RESET_BIT;
2364 case HNAE3_CORE_RESET:
2365 reg = HCLGE_GLOBAL_RESET_REG;
2366 reg_bit = HCLGE_CORE_RESET_BIT;
2368 case HNAE3_FUNC_RESET:
2369 reg = HCLGE_FUN_RST_ING;
2370 reg_bit = HCLGE_FUN_RST_ING_B;
2373 dev_err(&hdev->pdev->dev,
2374 "Wait for unsupported reset type: %d\n",
2379 val = hclge_read_dev(&hdev->hw, reg);
2380 while (hnae3_get_bit(val, reg_bit) && cnt < HCLGE_RESET_WAIT_CNT) {
2381 msleep(HCLGE_RESET_WATI_MS);
2382 val = hclge_read_dev(&hdev->hw, reg);
2386 if (cnt >= HCLGE_RESET_WAIT_CNT) {
2387 dev_warn(&hdev->pdev->dev,
2388 "Wait for reset timeout: %d\n", hdev->reset_type);
2395 static int hclge_set_vf_rst(struct hclge_dev *hdev, int func_id, bool reset)
2397 struct hclge_vf_rst_cmd *req;
2398 struct hclge_desc desc;
2400 req = (struct hclge_vf_rst_cmd *)desc.data;
2401 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_GBL_RST_STATUS, false);
2402 req->dest_vfid = func_id;
2407 return hclge_cmd_send(&hdev->hw, &desc, 1);
2410 int hclge_set_all_vf_rst(struct hclge_dev *hdev, bool reset)
2414 for (i = hdev->num_vmdq_vport + 1; i < hdev->num_alloc_vport; i++) {
2415 struct hclge_vport *vport = &hdev->vport[i];
2418 /* Send cmd to set/clear VF's FUNC_RST_ING */
2419 ret = hclge_set_vf_rst(hdev, vport->vport_id, reset);
2421 dev_err(&hdev->pdev->dev,
2422 "set vf(%d) rst failded %d!\n",
2423 vport->vport_id, ret);
2430 /* Inform VF to process the reset.
2431 * hclge_inform_reset_assert_to_vf may fail if VF
2432 * driver is not loaded.
2434 ret = hclge_inform_reset_assert_to_vf(vport);
2436 dev_warn(&hdev->pdev->dev,
2437 "inform reset to vf(%d) failded %d!\n",
2438 vport->vport_id, ret);
2444 int hclge_func_reset_cmd(struct hclge_dev *hdev, int func_id)
2446 struct hclge_desc desc;
2447 struct hclge_reset_cmd *req = (struct hclge_reset_cmd *)desc.data;
2450 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_RST_TRIGGER, false);
2451 hnae3_set_bit(req->mac_func_reset, HCLGE_CFG_RESET_FUNC_B, 1);
2452 req->fun_reset_vfid = func_id;
2454 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
2456 dev_err(&hdev->pdev->dev,
2457 "send function reset cmd fail, status =%d\n", ret);
2462 static void hclge_do_reset(struct hclge_dev *hdev)
2464 struct pci_dev *pdev = hdev->pdev;
2467 switch (hdev->reset_type) {
2468 case HNAE3_GLOBAL_RESET:
2469 val = hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG);
2470 hnae3_set_bit(val, HCLGE_GLOBAL_RESET_BIT, 1);
2471 hclge_write_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG, val);
2472 dev_info(&pdev->dev, "Global Reset requested\n");
2474 case HNAE3_CORE_RESET:
2475 val = hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG);
2476 hnae3_set_bit(val, HCLGE_CORE_RESET_BIT, 1);
2477 hclge_write_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG, val);
2478 dev_info(&pdev->dev, "Core Reset requested\n");
2480 case HNAE3_FUNC_RESET:
2481 dev_info(&pdev->dev, "PF Reset requested\n");
2482 /* schedule again to check later */
2483 set_bit(HNAE3_FUNC_RESET, &hdev->reset_pending);
2484 hclge_reset_task_schedule(hdev);
2487 dev_warn(&pdev->dev,
2488 "Unsupported reset type: %d\n", hdev->reset_type);
2493 static enum hnae3_reset_type hclge_get_reset_level(struct hclge_dev *hdev,
2494 unsigned long *addr)
2496 enum hnae3_reset_type rst_level = HNAE3_NONE_RESET;
2498 /* return the highest priority reset level amongst all */
2499 if (test_bit(HNAE3_IMP_RESET, addr)) {
2500 rst_level = HNAE3_IMP_RESET;
2501 clear_bit(HNAE3_IMP_RESET, addr);
2502 clear_bit(HNAE3_GLOBAL_RESET, addr);
2503 clear_bit(HNAE3_CORE_RESET, addr);
2504 clear_bit(HNAE3_FUNC_RESET, addr);
2505 } else if (test_bit(HNAE3_GLOBAL_RESET, addr)) {
2506 rst_level = HNAE3_GLOBAL_RESET;
2507 clear_bit(HNAE3_GLOBAL_RESET, addr);
2508 clear_bit(HNAE3_CORE_RESET, addr);
2509 clear_bit(HNAE3_FUNC_RESET, addr);
2510 } else if (test_bit(HNAE3_CORE_RESET, addr)) {
2511 rst_level = HNAE3_CORE_RESET;
2512 clear_bit(HNAE3_CORE_RESET, addr);
2513 clear_bit(HNAE3_FUNC_RESET, addr);
2514 } else if (test_bit(HNAE3_FUNC_RESET, addr)) {
2515 rst_level = HNAE3_FUNC_RESET;
2516 clear_bit(HNAE3_FUNC_RESET, addr);
2522 static void hclge_clear_reset_cause(struct hclge_dev *hdev)
2526 switch (hdev->reset_type) {
2527 case HNAE3_IMP_RESET:
2528 clearval = BIT(HCLGE_VECTOR0_IMPRESET_INT_B);
2530 case HNAE3_GLOBAL_RESET:
2531 clearval = BIT(HCLGE_VECTOR0_GLOBALRESET_INT_B);
2533 case HNAE3_CORE_RESET:
2534 clearval = BIT(HCLGE_VECTOR0_CORERESET_INT_B);
2543 hclge_write_dev(&hdev->hw, HCLGE_MISC_RESET_STS_REG, clearval);
2544 hclge_enable_vector(&hdev->misc_vector, true);
2547 static int hclge_reset_prepare_down(struct hclge_dev *hdev)
2551 switch (hdev->reset_type) {
2552 case HNAE3_FUNC_RESET:
2553 ret = hclge_set_all_vf_rst(hdev, true);
2562 static int hclge_reset_prepare_wait(struct hclge_dev *hdev)
2566 switch (hdev->reset_type) {
2567 case HNAE3_FUNC_RESET:
2568 /* There is no mechanism for PF to know if VF has stopped IO
2569 * for now, just wait 100 ms for VF to stop IO
2572 ret = hclge_func_reset_cmd(hdev, 0);
2574 dev_err(&hdev->pdev->dev,
2575 "asserting function reset fail %d!\n", ret);
2579 /* After performaning pf reset, it is not necessary to do the
2580 * mailbox handling or send any command to firmware, because
2581 * any mailbox handling or command to firmware is only valid
2582 * after hclge_cmd_init is called.
2584 set_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
2590 dev_info(&hdev->pdev->dev, "prepare wait ok\n");
2595 static bool hclge_reset_err_handle(struct hclge_dev *hdev, bool is_timeout)
2597 #define MAX_RESET_FAIL_CNT 5
2598 #define RESET_UPGRADE_DELAY_SEC 10
2600 if (hdev->reset_pending) {
2601 dev_info(&hdev->pdev->dev, "Reset pending %lu\n",
2602 hdev->reset_pending);
2604 } else if ((hdev->reset_type != HNAE3_IMP_RESET) &&
2605 (hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG) &
2606 BIT(HCLGE_IMP_RESET_BIT))) {
2607 dev_info(&hdev->pdev->dev,
2608 "reset failed because IMP Reset is pending\n");
2609 hclge_clear_reset_cause(hdev);
2611 } else if (hdev->reset_fail_cnt < MAX_RESET_FAIL_CNT) {
2612 hdev->reset_fail_cnt++;
2614 set_bit(hdev->reset_type, &hdev->reset_pending);
2615 dev_info(&hdev->pdev->dev,
2616 "re-schedule to wait for hw reset done\n");
2620 dev_info(&hdev->pdev->dev, "Upgrade reset level\n");
2621 hclge_clear_reset_cause(hdev);
2622 mod_timer(&hdev->reset_timer,
2623 jiffies + RESET_UPGRADE_DELAY_SEC * HZ);
2628 hclge_clear_reset_cause(hdev);
2629 dev_err(&hdev->pdev->dev, "Reset fail!\n");
2633 static int hclge_reset_prepare_up(struct hclge_dev *hdev)
2637 switch (hdev->reset_type) {
2638 case HNAE3_FUNC_RESET:
2639 ret = hclge_set_all_vf_rst(hdev, false);
2648 static void hclge_reset(struct hclge_dev *hdev)
2650 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(hdev->pdev);
2651 bool is_timeout = false;
2654 /* Initialize ae_dev reset status as well, in case enet layer wants to
2655 * know if device is undergoing reset
2657 ae_dev->reset_type = hdev->reset_type;
2658 hdev->reset_count++;
2659 hdev->last_reset_time = jiffies;
2660 /* perform reset of the stack & ae device for a client */
2661 ret = hclge_notify_roce_client(hdev, HNAE3_DOWN_CLIENT);
2665 ret = hclge_reset_prepare_down(hdev);
2670 ret = hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
2672 goto err_reset_lock;
2676 ret = hclge_reset_prepare_wait(hdev);
2680 if (hclge_reset_wait(hdev)) {
2685 ret = hclge_notify_roce_client(hdev, HNAE3_UNINIT_CLIENT);
2690 ret = hclge_notify_client(hdev, HNAE3_UNINIT_CLIENT);
2692 goto err_reset_lock;
2694 ret = hclge_reset_ae_dev(hdev->ae_dev);
2696 goto err_reset_lock;
2698 ret = hclge_notify_client(hdev, HNAE3_INIT_CLIENT);
2700 goto err_reset_lock;
2702 hclge_clear_reset_cause(hdev);
2704 ret = hclge_reset_prepare_up(hdev);
2706 goto err_reset_lock;
2708 ret = hclge_notify_client(hdev, HNAE3_UP_CLIENT);
2710 goto err_reset_lock;
2714 ret = hclge_notify_roce_client(hdev, HNAE3_INIT_CLIENT);
2718 ret = hclge_notify_roce_client(hdev, HNAE3_UP_CLIENT);
2727 if (hclge_reset_err_handle(hdev, is_timeout))
2728 hclge_reset_task_schedule(hdev);
2731 static void hclge_reset_event(struct pci_dev *pdev, struct hnae3_handle *handle)
2733 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
2734 struct hclge_dev *hdev = ae_dev->priv;
2736 /* We might end up getting called broadly because of 2 below cases:
2737 * 1. Recoverable error was conveyed through APEI and only way to bring
2738 * normalcy is to reset.
2739 * 2. A new reset request from the stack due to timeout
2741 * For the first case,error event might not have ae handle available.
2742 * check if this is a new reset request and we are not here just because
2743 * last reset attempt did not succeed and watchdog hit us again. We will
2744 * know this if last reset request did not occur very recently (watchdog
2745 * timer = 5*HZ, let us check after sufficiently large time, say 4*5*Hz)
2746 * In case of new request we reset the "reset level" to PF reset.
2747 * And if it is a repeat reset request of the most recent one then we
2748 * want to make sure we throttle the reset request. Therefore, we will
2749 * not allow it again before 3*HZ times.
2752 handle = &hdev->vport[0].nic;
2754 if (time_before(jiffies, (hdev->last_reset_time + 3 * HZ)))
2756 else if (hdev->default_reset_request)
2758 hclge_get_reset_level(hdev,
2759 &hdev->default_reset_request);
2760 else if (time_after(jiffies, (hdev->last_reset_time + 4 * 5 * HZ)))
2761 hdev->reset_level = HNAE3_FUNC_RESET;
2763 dev_info(&hdev->pdev->dev, "received reset event , reset type is %d",
2766 /* request reset & schedule reset task */
2767 set_bit(hdev->reset_level, &hdev->reset_request);
2768 hclge_reset_task_schedule(hdev);
2770 if (hdev->reset_level < HNAE3_GLOBAL_RESET)
2771 hdev->reset_level++;
2774 static void hclge_set_def_reset_request(struct hnae3_ae_dev *ae_dev,
2775 enum hnae3_reset_type rst_type)
2777 struct hclge_dev *hdev = ae_dev->priv;
2779 set_bit(rst_type, &hdev->default_reset_request);
2782 static void hclge_reset_timer(struct timer_list *t)
2784 struct hclge_dev *hdev = from_timer(hdev, t, reset_timer);
2786 dev_info(&hdev->pdev->dev,
2787 "triggering global reset in reset timer\n");
2788 set_bit(HNAE3_GLOBAL_RESET, &hdev->default_reset_request);
2789 hclge_reset_event(hdev->pdev, NULL);
2792 static void hclge_reset_subtask(struct hclge_dev *hdev)
2794 /* check if there is any ongoing reset in the hardware. This status can
2795 * be checked from reset_pending. If there is then, we need to wait for
2796 * hardware to complete reset.
2797 * a. If we are able to figure out in reasonable time that hardware
2798 * has fully resetted then, we can proceed with driver, client
2800 * b. else, we can come back later to check this status so re-sched
2803 hdev->last_reset_time = jiffies;
2804 hdev->reset_type = hclge_get_reset_level(hdev, &hdev->reset_pending);
2805 if (hdev->reset_type != HNAE3_NONE_RESET)
2808 /* check if we got any *new* reset requests to be honored */
2809 hdev->reset_type = hclge_get_reset_level(hdev, &hdev->reset_request);
2810 if (hdev->reset_type != HNAE3_NONE_RESET)
2811 hclge_do_reset(hdev);
2813 hdev->reset_type = HNAE3_NONE_RESET;
2816 static void hclge_reset_service_task(struct work_struct *work)
2818 struct hclge_dev *hdev =
2819 container_of(work, struct hclge_dev, rst_service_task);
2821 if (test_and_set_bit(HCLGE_STATE_RST_HANDLING, &hdev->state))
2824 clear_bit(HCLGE_STATE_RST_SERVICE_SCHED, &hdev->state);
2826 hclge_reset_subtask(hdev);
2828 clear_bit(HCLGE_STATE_RST_HANDLING, &hdev->state);
2831 static void hclge_mailbox_service_task(struct work_struct *work)
2833 struct hclge_dev *hdev =
2834 container_of(work, struct hclge_dev, mbx_service_task);
2836 if (test_and_set_bit(HCLGE_STATE_MBX_HANDLING, &hdev->state))
2839 clear_bit(HCLGE_STATE_MBX_SERVICE_SCHED, &hdev->state);
2841 hclge_mbx_handler(hdev);
2843 clear_bit(HCLGE_STATE_MBX_HANDLING, &hdev->state);
2846 static void hclge_service_task(struct work_struct *work)
2848 struct hclge_dev *hdev =
2849 container_of(work, struct hclge_dev, service_task);
2851 if (hdev->hw_stats.stats_timer >= HCLGE_STATS_TIMER_INTERVAL) {
2852 hclge_update_stats_for_all(hdev);
2853 hdev->hw_stats.stats_timer = 0;
2856 hclge_update_speed_duplex(hdev);
2857 hclge_update_link_status(hdev);
2858 hclge_service_complete(hdev);
2861 struct hclge_vport *hclge_get_vport(struct hnae3_handle *handle)
2863 /* VF handle has no client */
2864 if (!handle->client)
2865 return container_of(handle, struct hclge_vport, nic);
2866 else if (handle->client->type == HNAE3_CLIENT_ROCE)
2867 return container_of(handle, struct hclge_vport, roce);
2869 return container_of(handle, struct hclge_vport, nic);
2872 static int hclge_get_vector(struct hnae3_handle *handle, u16 vector_num,
2873 struct hnae3_vector_info *vector_info)
2875 struct hclge_vport *vport = hclge_get_vport(handle);
2876 struct hnae3_vector_info *vector = vector_info;
2877 struct hclge_dev *hdev = vport->back;
2881 vector_num = min(hdev->num_msi_left, vector_num);
2883 for (j = 0; j < vector_num; j++) {
2884 for (i = 1; i < hdev->num_msi; i++) {
2885 if (hdev->vector_status[i] == HCLGE_INVALID_VPORT) {
2886 vector->vector = pci_irq_vector(hdev->pdev, i);
2887 vector->io_addr = hdev->hw.io_base +
2888 HCLGE_VECTOR_REG_BASE +
2889 (i - 1) * HCLGE_VECTOR_REG_OFFSET +
2891 HCLGE_VECTOR_VF_OFFSET;
2892 hdev->vector_status[i] = vport->vport_id;
2893 hdev->vector_irq[i] = vector->vector;
2902 hdev->num_msi_left -= alloc;
2903 hdev->num_msi_used += alloc;
2908 static int hclge_get_vector_index(struct hclge_dev *hdev, int vector)
2912 for (i = 0; i < hdev->num_msi; i++)
2913 if (vector == hdev->vector_irq[i])
2919 static int hclge_put_vector(struct hnae3_handle *handle, int vector)
2921 struct hclge_vport *vport = hclge_get_vport(handle);
2922 struct hclge_dev *hdev = vport->back;
2925 vector_id = hclge_get_vector_index(hdev, vector);
2926 if (vector_id < 0) {
2927 dev_err(&hdev->pdev->dev,
2928 "Get vector index fail. vector_id =%d\n", vector_id);
2932 hclge_free_vector(hdev, vector_id);
2937 static u32 hclge_get_rss_key_size(struct hnae3_handle *handle)
2939 return HCLGE_RSS_KEY_SIZE;
2942 static u32 hclge_get_rss_indir_size(struct hnae3_handle *handle)
2944 return HCLGE_RSS_IND_TBL_SIZE;
2947 static int hclge_set_rss_algo_key(struct hclge_dev *hdev,
2948 const u8 hfunc, const u8 *key)
2950 struct hclge_rss_config_cmd *req;
2951 struct hclge_desc desc;
2956 req = (struct hclge_rss_config_cmd *)desc.data;
2958 for (key_offset = 0; key_offset < 3; key_offset++) {
2959 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_GENERIC_CONFIG,
2962 req->hash_config |= (hfunc & HCLGE_RSS_HASH_ALGO_MASK);
2963 req->hash_config |= (key_offset << HCLGE_RSS_HASH_KEY_OFFSET_B);
2965 if (key_offset == 2)
2967 HCLGE_RSS_KEY_SIZE - HCLGE_RSS_HASH_KEY_NUM * 2;
2969 key_size = HCLGE_RSS_HASH_KEY_NUM;
2971 memcpy(req->hash_key,
2972 key + key_offset * HCLGE_RSS_HASH_KEY_NUM, key_size);
2974 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
2976 dev_err(&hdev->pdev->dev,
2977 "Configure RSS config fail, status = %d\n",
2985 static int hclge_set_rss_indir_table(struct hclge_dev *hdev, const u8 *indir)
2987 struct hclge_rss_indirection_table_cmd *req;
2988 struct hclge_desc desc;
2992 req = (struct hclge_rss_indirection_table_cmd *)desc.data;
2994 for (i = 0; i < HCLGE_RSS_CFG_TBL_NUM; i++) {
2995 hclge_cmd_setup_basic_desc
2996 (&desc, HCLGE_OPC_RSS_INDIR_TABLE, false);
2998 req->start_table_index =
2999 cpu_to_le16(i * HCLGE_RSS_CFG_TBL_SIZE);
3000 req->rss_set_bitmap = cpu_to_le16(HCLGE_RSS_SET_BITMAP_MSK);
3002 for (j = 0; j < HCLGE_RSS_CFG_TBL_SIZE; j++)
3003 req->rss_result[j] =
3004 indir[i * HCLGE_RSS_CFG_TBL_SIZE + j];
3006 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3008 dev_err(&hdev->pdev->dev,
3009 "Configure rss indir table fail,status = %d\n",
3017 static int hclge_set_rss_tc_mode(struct hclge_dev *hdev, u16 *tc_valid,
3018 u16 *tc_size, u16 *tc_offset)
3020 struct hclge_rss_tc_mode_cmd *req;
3021 struct hclge_desc desc;
3025 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_TC_MODE, false);
3026 req = (struct hclge_rss_tc_mode_cmd *)desc.data;
3028 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
3031 hnae3_set_bit(mode, HCLGE_RSS_TC_VALID_B, (tc_valid[i] & 0x1));
3032 hnae3_set_field(mode, HCLGE_RSS_TC_SIZE_M,
3033 HCLGE_RSS_TC_SIZE_S, tc_size[i]);
3034 hnae3_set_field(mode, HCLGE_RSS_TC_OFFSET_M,
3035 HCLGE_RSS_TC_OFFSET_S, tc_offset[i]);
3037 req->rss_tc_mode[i] = cpu_to_le16(mode);
3040 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3042 dev_err(&hdev->pdev->dev,
3043 "Configure rss tc mode fail, status = %d\n", ret);
3048 static void hclge_get_rss_type(struct hclge_vport *vport)
3050 if (vport->rss_tuple_sets.ipv4_tcp_en ||
3051 vport->rss_tuple_sets.ipv4_udp_en ||
3052 vport->rss_tuple_sets.ipv4_sctp_en ||
3053 vport->rss_tuple_sets.ipv6_tcp_en ||
3054 vport->rss_tuple_sets.ipv6_udp_en ||
3055 vport->rss_tuple_sets.ipv6_sctp_en)
3056 vport->nic.kinfo.rss_type = PKT_HASH_TYPE_L4;
3057 else if (vport->rss_tuple_sets.ipv4_fragment_en ||
3058 vport->rss_tuple_sets.ipv6_fragment_en)
3059 vport->nic.kinfo.rss_type = PKT_HASH_TYPE_L3;
3061 vport->nic.kinfo.rss_type = PKT_HASH_TYPE_NONE;
3064 static int hclge_set_rss_input_tuple(struct hclge_dev *hdev)
3066 struct hclge_rss_input_tuple_cmd *req;
3067 struct hclge_desc desc;
3070 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_INPUT_TUPLE, false);
3072 req = (struct hclge_rss_input_tuple_cmd *)desc.data;
3074 /* Get the tuple cfg from pf */
3075 req->ipv4_tcp_en = hdev->vport[0].rss_tuple_sets.ipv4_tcp_en;
3076 req->ipv4_udp_en = hdev->vport[0].rss_tuple_sets.ipv4_udp_en;
3077 req->ipv4_sctp_en = hdev->vport[0].rss_tuple_sets.ipv4_sctp_en;
3078 req->ipv4_fragment_en = hdev->vport[0].rss_tuple_sets.ipv4_fragment_en;
3079 req->ipv6_tcp_en = hdev->vport[0].rss_tuple_sets.ipv6_tcp_en;
3080 req->ipv6_udp_en = hdev->vport[0].rss_tuple_sets.ipv6_udp_en;
3081 req->ipv6_sctp_en = hdev->vport[0].rss_tuple_sets.ipv6_sctp_en;
3082 req->ipv6_fragment_en = hdev->vport[0].rss_tuple_sets.ipv6_fragment_en;
3083 hclge_get_rss_type(&hdev->vport[0]);
3084 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3086 dev_err(&hdev->pdev->dev,
3087 "Configure rss input fail, status = %d\n", ret);
3091 static int hclge_get_rss(struct hnae3_handle *handle, u32 *indir,
3094 struct hclge_vport *vport = hclge_get_vport(handle);
3097 /* Get hash algorithm */
3099 switch (vport->rss_algo) {
3100 case HCLGE_RSS_HASH_ALGO_TOEPLITZ:
3101 *hfunc = ETH_RSS_HASH_TOP;
3103 case HCLGE_RSS_HASH_ALGO_SIMPLE:
3104 *hfunc = ETH_RSS_HASH_XOR;
3107 *hfunc = ETH_RSS_HASH_UNKNOWN;
3112 /* Get the RSS Key required by the user */
3114 memcpy(key, vport->rss_hash_key, HCLGE_RSS_KEY_SIZE);
3116 /* Get indirect table */
3118 for (i = 0; i < HCLGE_RSS_IND_TBL_SIZE; i++)
3119 indir[i] = vport->rss_indirection_tbl[i];
3124 static int hclge_set_rss(struct hnae3_handle *handle, const u32 *indir,
3125 const u8 *key, const u8 hfunc)
3127 struct hclge_vport *vport = hclge_get_vport(handle);
3128 struct hclge_dev *hdev = vport->back;
3132 /* Set the RSS Hash Key if specififed by the user */
3135 case ETH_RSS_HASH_TOP:
3136 hash_algo = HCLGE_RSS_HASH_ALGO_TOEPLITZ;
3138 case ETH_RSS_HASH_XOR:
3139 hash_algo = HCLGE_RSS_HASH_ALGO_SIMPLE;
3141 case ETH_RSS_HASH_NO_CHANGE:
3142 hash_algo = vport->rss_algo;
3148 ret = hclge_set_rss_algo_key(hdev, hash_algo, key);
3152 /* Update the shadow RSS key with user specified qids */
3153 memcpy(vport->rss_hash_key, key, HCLGE_RSS_KEY_SIZE);
3154 vport->rss_algo = hash_algo;
3157 /* Update the shadow RSS table with user specified qids */
3158 for (i = 0; i < HCLGE_RSS_IND_TBL_SIZE; i++)
3159 vport->rss_indirection_tbl[i] = indir[i];
3161 /* Update the hardware */
3162 return hclge_set_rss_indir_table(hdev, vport->rss_indirection_tbl);
3165 static u8 hclge_get_rss_hash_bits(struct ethtool_rxnfc *nfc)
3167 u8 hash_sets = nfc->data & RXH_L4_B_0_1 ? HCLGE_S_PORT_BIT : 0;
3169 if (nfc->data & RXH_L4_B_2_3)
3170 hash_sets |= HCLGE_D_PORT_BIT;
3172 hash_sets &= ~HCLGE_D_PORT_BIT;
3174 if (nfc->data & RXH_IP_SRC)
3175 hash_sets |= HCLGE_S_IP_BIT;
3177 hash_sets &= ~HCLGE_S_IP_BIT;
3179 if (nfc->data & RXH_IP_DST)
3180 hash_sets |= HCLGE_D_IP_BIT;
3182 hash_sets &= ~HCLGE_D_IP_BIT;
3184 if (nfc->flow_type == SCTP_V4_FLOW || nfc->flow_type == SCTP_V6_FLOW)
3185 hash_sets |= HCLGE_V_TAG_BIT;
3190 static int hclge_set_rss_tuple(struct hnae3_handle *handle,
3191 struct ethtool_rxnfc *nfc)
3193 struct hclge_vport *vport = hclge_get_vport(handle);
3194 struct hclge_dev *hdev = vport->back;
3195 struct hclge_rss_input_tuple_cmd *req;
3196 struct hclge_desc desc;
3200 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
3201 RXH_L4_B_0_1 | RXH_L4_B_2_3))
3204 req = (struct hclge_rss_input_tuple_cmd *)desc.data;
3205 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_INPUT_TUPLE, false);
3207 req->ipv4_tcp_en = vport->rss_tuple_sets.ipv4_tcp_en;
3208 req->ipv4_udp_en = vport->rss_tuple_sets.ipv4_udp_en;
3209 req->ipv4_sctp_en = vport->rss_tuple_sets.ipv4_sctp_en;
3210 req->ipv4_fragment_en = vport->rss_tuple_sets.ipv4_fragment_en;
3211 req->ipv6_tcp_en = vport->rss_tuple_sets.ipv6_tcp_en;
3212 req->ipv6_udp_en = vport->rss_tuple_sets.ipv6_udp_en;
3213 req->ipv6_sctp_en = vport->rss_tuple_sets.ipv6_sctp_en;
3214 req->ipv6_fragment_en = vport->rss_tuple_sets.ipv6_fragment_en;
3216 tuple_sets = hclge_get_rss_hash_bits(nfc);
3217 switch (nfc->flow_type) {
3219 req->ipv4_tcp_en = tuple_sets;
3222 req->ipv6_tcp_en = tuple_sets;
3225 req->ipv4_udp_en = tuple_sets;
3228 req->ipv6_udp_en = tuple_sets;
3231 req->ipv4_sctp_en = tuple_sets;
3234 if ((nfc->data & RXH_L4_B_0_1) ||
3235 (nfc->data & RXH_L4_B_2_3))
3238 req->ipv6_sctp_en = tuple_sets;
3241 req->ipv4_fragment_en = HCLGE_RSS_INPUT_TUPLE_OTHER;
3244 req->ipv6_fragment_en = HCLGE_RSS_INPUT_TUPLE_OTHER;
3250 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3252 dev_err(&hdev->pdev->dev,
3253 "Set rss tuple fail, status = %d\n", ret);
3257 vport->rss_tuple_sets.ipv4_tcp_en = req->ipv4_tcp_en;
3258 vport->rss_tuple_sets.ipv4_udp_en = req->ipv4_udp_en;
3259 vport->rss_tuple_sets.ipv4_sctp_en = req->ipv4_sctp_en;
3260 vport->rss_tuple_sets.ipv4_fragment_en = req->ipv4_fragment_en;
3261 vport->rss_tuple_sets.ipv6_tcp_en = req->ipv6_tcp_en;
3262 vport->rss_tuple_sets.ipv6_udp_en = req->ipv6_udp_en;
3263 vport->rss_tuple_sets.ipv6_sctp_en = req->ipv6_sctp_en;
3264 vport->rss_tuple_sets.ipv6_fragment_en = req->ipv6_fragment_en;
3265 hclge_get_rss_type(vport);
3269 static int hclge_get_rss_tuple(struct hnae3_handle *handle,
3270 struct ethtool_rxnfc *nfc)
3272 struct hclge_vport *vport = hclge_get_vport(handle);
3277 switch (nfc->flow_type) {
3279 tuple_sets = vport->rss_tuple_sets.ipv4_tcp_en;
3282 tuple_sets = vport->rss_tuple_sets.ipv4_udp_en;
3285 tuple_sets = vport->rss_tuple_sets.ipv6_tcp_en;
3288 tuple_sets = vport->rss_tuple_sets.ipv6_udp_en;
3291 tuple_sets = vport->rss_tuple_sets.ipv4_sctp_en;
3294 tuple_sets = vport->rss_tuple_sets.ipv6_sctp_en;
3298 tuple_sets = HCLGE_S_IP_BIT | HCLGE_D_IP_BIT;
3307 if (tuple_sets & HCLGE_D_PORT_BIT)
3308 nfc->data |= RXH_L4_B_2_3;
3309 if (tuple_sets & HCLGE_S_PORT_BIT)
3310 nfc->data |= RXH_L4_B_0_1;
3311 if (tuple_sets & HCLGE_D_IP_BIT)
3312 nfc->data |= RXH_IP_DST;
3313 if (tuple_sets & HCLGE_S_IP_BIT)
3314 nfc->data |= RXH_IP_SRC;
3319 static int hclge_get_tc_size(struct hnae3_handle *handle)
3321 struct hclge_vport *vport = hclge_get_vport(handle);
3322 struct hclge_dev *hdev = vport->back;
3324 return hdev->rss_size_max;
3327 int hclge_rss_init_hw(struct hclge_dev *hdev)
3329 struct hclge_vport *vport = hdev->vport;
3330 u8 *rss_indir = vport[0].rss_indirection_tbl;
3331 u16 rss_size = vport[0].alloc_rss_size;
3332 u8 *key = vport[0].rss_hash_key;
3333 u8 hfunc = vport[0].rss_algo;
3334 u16 tc_offset[HCLGE_MAX_TC_NUM];
3335 u16 tc_valid[HCLGE_MAX_TC_NUM];
3336 u16 tc_size[HCLGE_MAX_TC_NUM];
3340 ret = hclge_set_rss_indir_table(hdev, rss_indir);
3344 ret = hclge_set_rss_algo_key(hdev, hfunc, key);
3348 ret = hclge_set_rss_input_tuple(hdev);
3352 /* Each TC have the same queue size, and tc_size set to hardware is
3353 * the log2 of roundup power of two of rss_size, the acutal queue
3354 * size is limited by indirection table.
3356 if (rss_size > HCLGE_RSS_TC_SIZE_7 || rss_size == 0) {
3357 dev_err(&hdev->pdev->dev,
3358 "Configure rss tc size failed, invalid TC_SIZE = %d\n",
3363 roundup_size = roundup_pow_of_two(rss_size);
3364 roundup_size = ilog2(roundup_size);
3366 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
3369 if (!(hdev->hw_tc_map & BIT(i)))
3373 tc_size[i] = roundup_size;
3374 tc_offset[i] = rss_size * i;
3377 return hclge_set_rss_tc_mode(hdev, tc_valid, tc_size, tc_offset);
3380 void hclge_rss_indir_init_cfg(struct hclge_dev *hdev)
3382 struct hclge_vport *vport = hdev->vport;
3385 for (j = 0; j < hdev->num_vmdq_vport + 1; j++) {
3386 for (i = 0; i < HCLGE_RSS_IND_TBL_SIZE; i++)
3387 vport[j].rss_indirection_tbl[i] =
3388 i % vport[j].alloc_rss_size;
3392 static void hclge_rss_init_cfg(struct hclge_dev *hdev)
3394 struct hclge_vport *vport = hdev->vport;
3397 for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
3398 vport[i].rss_tuple_sets.ipv4_tcp_en =
3399 HCLGE_RSS_INPUT_TUPLE_OTHER;
3400 vport[i].rss_tuple_sets.ipv4_udp_en =
3401 HCLGE_RSS_INPUT_TUPLE_OTHER;
3402 vport[i].rss_tuple_sets.ipv4_sctp_en =
3403 HCLGE_RSS_INPUT_TUPLE_SCTP;
3404 vport[i].rss_tuple_sets.ipv4_fragment_en =
3405 HCLGE_RSS_INPUT_TUPLE_OTHER;
3406 vport[i].rss_tuple_sets.ipv6_tcp_en =
3407 HCLGE_RSS_INPUT_TUPLE_OTHER;
3408 vport[i].rss_tuple_sets.ipv6_udp_en =
3409 HCLGE_RSS_INPUT_TUPLE_OTHER;
3410 vport[i].rss_tuple_sets.ipv6_sctp_en =
3411 HCLGE_RSS_INPUT_TUPLE_SCTP;
3412 vport[i].rss_tuple_sets.ipv6_fragment_en =
3413 HCLGE_RSS_INPUT_TUPLE_OTHER;
3415 vport[i].rss_algo = HCLGE_RSS_HASH_ALGO_TOEPLITZ;
3417 netdev_rss_key_fill(vport[i].rss_hash_key, HCLGE_RSS_KEY_SIZE);
3420 hclge_rss_indir_init_cfg(hdev);
3423 int hclge_bind_ring_with_vector(struct hclge_vport *vport,
3424 int vector_id, bool en,
3425 struct hnae3_ring_chain_node *ring_chain)
3427 struct hclge_dev *hdev = vport->back;
3428 struct hnae3_ring_chain_node *node;
3429 struct hclge_desc desc;
3430 struct hclge_ctrl_vector_chain_cmd *req
3431 = (struct hclge_ctrl_vector_chain_cmd *)desc.data;
3432 enum hclge_cmd_status status;
3433 enum hclge_opcode_type op;
3434 u16 tqp_type_and_id;
3437 op = en ? HCLGE_OPC_ADD_RING_TO_VECTOR : HCLGE_OPC_DEL_RING_TO_VECTOR;
3438 hclge_cmd_setup_basic_desc(&desc, op, false);
3439 req->int_vector_id = vector_id;
3442 for (node = ring_chain; node; node = node->next) {
3443 tqp_type_and_id = le16_to_cpu(req->tqp_type_and_id[i]);
3444 hnae3_set_field(tqp_type_and_id, HCLGE_INT_TYPE_M,
3446 hnae3_get_bit(node->flag, HNAE3_RING_TYPE_B));
3447 hnae3_set_field(tqp_type_and_id, HCLGE_TQP_ID_M,
3448 HCLGE_TQP_ID_S, node->tqp_index);
3449 hnae3_set_field(tqp_type_and_id, HCLGE_INT_GL_IDX_M,
3451 hnae3_get_field(node->int_gl_idx,
3452 HNAE3_RING_GL_IDX_M,
3453 HNAE3_RING_GL_IDX_S));
3454 req->tqp_type_and_id[i] = cpu_to_le16(tqp_type_and_id);
3455 if (++i >= HCLGE_VECTOR_ELEMENTS_PER_CMD) {
3456 req->int_cause_num = HCLGE_VECTOR_ELEMENTS_PER_CMD;
3457 req->vfid = vport->vport_id;
3459 status = hclge_cmd_send(&hdev->hw, &desc, 1);
3461 dev_err(&hdev->pdev->dev,
3462 "Map TQP fail, status is %d.\n",
3468 hclge_cmd_setup_basic_desc(&desc,
3471 req->int_vector_id = vector_id;
3476 req->int_cause_num = i;
3477 req->vfid = vport->vport_id;
3478 status = hclge_cmd_send(&hdev->hw, &desc, 1);
3480 dev_err(&hdev->pdev->dev,
3481 "Map TQP fail, status is %d.\n", status);
3489 static int hclge_map_ring_to_vector(struct hnae3_handle *handle,
3491 struct hnae3_ring_chain_node *ring_chain)
3493 struct hclge_vport *vport = hclge_get_vport(handle);
3494 struct hclge_dev *hdev = vport->back;
3497 vector_id = hclge_get_vector_index(hdev, vector);
3498 if (vector_id < 0) {
3499 dev_err(&hdev->pdev->dev,
3500 "Get vector index fail. vector_id =%d\n", vector_id);
3504 return hclge_bind_ring_with_vector(vport, vector_id, true, ring_chain);
3507 static int hclge_unmap_ring_frm_vector(struct hnae3_handle *handle,
3509 struct hnae3_ring_chain_node *ring_chain)
3511 struct hclge_vport *vport = hclge_get_vport(handle);
3512 struct hclge_dev *hdev = vport->back;
3515 if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state))
3518 vector_id = hclge_get_vector_index(hdev, vector);
3519 if (vector_id < 0) {
3520 dev_err(&handle->pdev->dev,
3521 "Get vector index fail. ret =%d\n", vector_id);
3525 ret = hclge_bind_ring_with_vector(vport, vector_id, false, ring_chain);
3527 dev_err(&handle->pdev->dev,
3528 "Unmap ring from vector fail. vectorid=%d, ret =%d\n",
3535 int hclge_cmd_set_promisc_mode(struct hclge_dev *hdev,
3536 struct hclge_promisc_param *param)
3538 struct hclge_promisc_cfg_cmd *req;
3539 struct hclge_desc desc;
3542 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_PROMISC_MODE, false);
3544 req = (struct hclge_promisc_cfg_cmd *)desc.data;
3545 req->vf_id = param->vf_id;
3547 /* HCLGE_PROMISC_TX_EN_B and HCLGE_PROMISC_RX_EN_B are not supported on
3548 * pdev revision(0x20), new revision support them. The
3549 * value of this two fields will not return error when driver
3550 * send command to fireware in revision(0x20).
3552 req->flag = (param->enable << HCLGE_PROMISC_EN_B) |
3553 HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B;
3555 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3557 dev_err(&hdev->pdev->dev,
3558 "Set promisc mode fail, status is %d.\n", ret);
3563 void hclge_promisc_param_init(struct hclge_promisc_param *param, bool en_uc,
3564 bool en_mc, bool en_bc, int vport_id)
3569 memset(param, 0, sizeof(struct hclge_promisc_param));
3571 param->enable = HCLGE_PROMISC_EN_UC;
3573 param->enable |= HCLGE_PROMISC_EN_MC;
3575 param->enable |= HCLGE_PROMISC_EN_BC;
3576 param->vf_id = vport_id;
3579 static int hclge_set_promisc_mode(struct hnae3_handle *handle, bool en_uc_pmc,
3582 struct hclge_vport *vport = hclge_get_vport(handle);
3583 struct hclge_dev *hdev = vport->back;
3584 struct hclge_promisc_param param;
3586 hclge_promisc_param_init(¶m, en_uc_pmc, en_mc_pmc, true,
3588 return hclge_cmd_set_promisc_mode(hdev, ¶m);
3591 static int hclge_get_fd_mode(struct hclge_dev *hdev, u8 *fd_mode)
3593 struct hclge_get_fd_mode_cmd *req;
3594 struct hclge_desc desc;
3597 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_FD_MODE_CTRL, true);
3599 req = (struct hclge_get_fd_mode_cmd *)desc.data;
3601 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3603 dev_err(&hdev->pdev->dev, "get fd mode fail, ret=%d\n", ret);
3607 *fd_mode = req->mode;
3612 static int hclge_get_fd_allocation(struct hclge_dev *hdev,
3613 u32 *stage1_entry_num,
3614 u32 *stage2_entry_num,
3615 u16 *stage1_counter_num,
3616 u16 *stage2_counter_num)
3618 struct hclge_get_fd_allocation_cmd *req;
3619 struct hclge_desc desc;
3622 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_FD_GET_ALLOCATION, true);
3624 req = (struct hclge_get_fd_allocation_cmd *)desc.data;
3626 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3628 dev_err(&hdev->pdev->dev, "query fd allocation fail, ret=%d\n",
3633 *stage1_entry_num = le32_to_cpu(req->stage1_entry_num);
3634 *stage2_entry_num = le32_to_cpu(req->stage2_entry_num);
3635 *stage1_counter_num = le16_to_cpu(req->stage1_counter_num);
3636 *stage2_counter_num = le16_to_cpu(req->stage2_counter_num);
3641 static int hclge_set_fd_key_config(struct hclge_dev *hdev, int stage_num)
3643 struct hclge_set_fd_key_config_cmd *req;
3644 struct hclge_fd_key_cfg *stage;
3645 struct hclge_desc desc;
3648 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_FD_KEY_CONFIG, false);
3650 req = (struct hclge_set_fd_key_config_cmd *)desc.data;
3651 stage = &hdev->fd_cfg.key_cfg[stage_num];
3652 req->stage = stage_num;
3653 req->key_select = stage->key_sel;
3654 req->inner_sipv6_word_en = stage->inner_sipv6_word_en;
3655 req->inner_dipv6_word_en = stage->inner_dipv6_word_en;
3656 req->outer_sipv6_word_en = stage->outer_sipv6_word_en;
3657 req->outer_dipv6_word_en = stage->outer_dipv6_word_en;
3658 req->tuple_mask = cpu_to_le32(~stage->tuple_active);
3659 req->meta_data_mask = cpu_to_le32(~stage->meta_data_active);
3661 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3663 dev_err(&hdev->pdev->dev, "set fd key fail, ret=%d\n", ret);
3668 static int hclge_init_fd_config(struct hclge_dev *hdev)
3670 #define LOW_2_WORDS 0x03
3671 struct hclge_fd_key_cfg *key_cfg;
3674 if (!hnae3_dev_fd_supported(hdev))
3677 ret = hclge_get_fd_mode(hdev, &hdev->fd_cfg.fd_mode);
3681 switch (hdev->fd_cfg.fd_mode) {
3682 case HCLGE_FD_MODE_DEPTH_2K_WIDTH_400B_STAGE_1:
3683 hdev->fd_cfg.max_key_length = MAX_KEY_LENGTH;
3685 case HCLGE_FD_MODE_DEPTH_4K_WIDTH_200B_STAGE_1:
3686 hdev->fd_cfg.max_key_length = MAX_KEY_LENGTH / 2;
3689 dev_err(&hdev->pdev->dev,
3690 "Unsupported flow director mode %d\n",
3691 hdev->fd_cfg.fd_mode);
3695 hdev->fd_cfg.fd_en = true;
3696 hdev->fd_cfg.proto_support =
3697 TCP_V4_FLOW | UDP_V4_FLOW | SCTP_V4_FLOW | TCP_V6_FLOW |
3698 UDP_V6_FLOW | SCTP_V6_FLOW | IPV4_USER_FLOW | IPV6_USER_FLOW;
3699 key_cfg = &hdev->fd_cfg.key_cfg[HCLGE_FD_STAGE_1];
3700 key_cfg->key_sel = HCLGE_FD_KEY_BASE_ON_TUPLE,
3701 key_cfg->inner_sipv6_word_en = LOW_2_WORDS;
3702 key_cfg->inner_dipv6_word_en = LOW_2_WORDS;
3703 key_cfg->outer_sipv6_word_en = 0;
3704 key_cfg->outer_dipv6_word_en = 0;
3706 key_cfg->tuple_active = BIT(INNER_VLAN_TAG_FST) | BIT(INNER_ETH_TYPE) |
3707 BIT(INNER_IP_PROTO) | BIT(INNER_IP_TOS) |
3708 BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) |
3709 BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT);
3711 /* If use max 400bit key, we can support tuples for ether type */
3712 if (hdev->fd_cfg.max_key_length == MAX_KEY_LENGTH) {
3713 hdev->fd_cfg.proto_support |= ETHER_FLOW;
3714 key_cfg->tuple_active |=
3715 BIT(INNER_DST_MAC) | BIT(INNER_SRC_MAC);
3718 /* roce_type is used to filter roce frames
3719 * dst_vport is used to specify the rule
3721 key_cfg->meta_data_active = BIT(ROCE_TYPE) | BIT(DST_VPORT);
3723 ret = hclge_get_fd_allocation(hdev,
3724 &hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1],
3725 &hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_2],
3726 &hdev->fd_cfg.cnt_num[HCLGE_FD_STAGE_1],
3727 &hdev->fd_cfg.cnt_num[HCLGE_FD_STAGE_2]);
3731 return hclge_set_fd_key_config(hdev, HCLGE_FD_STAGE_1);
3734 static int hclge_fd_tcam_config(struct hclge_dev *hdev, u8 stage, bool sel_x,
3735 int loc, u8 *key, bool is_add)
3737 struct hclge_fd_tcam_config_1_cmd *req1;
3738 struct hclge_fd_tcam_config_2_cmd *req2;
3739 struct hclge_fd_tcam_config_3_cmd *req3;
3740 struct hclge_desc desc[3];
3743 hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_FD_TCAM_OP, false);
3744 desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
3745 hclge_cmd_setup_basic_desc(&desc[1], HCLGE_OPC_FD_TCAM_OP, false);
3746 desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
3747 hclge_cmd_setup_basic_desc(&desc[2], HCLGE_OPC_FD_TCAM_OP, false);
3749 req1 = (struct hclge_fd_tcam_config_1_cmd *)desc[0].data;
3750 req2 = (struct hclge_fd_tcam_config_2_cmd *)desc[1].data;
3751 req3 = (struct hclge_fd_tcam_config_3_cmd *)desc[2].data;
3753 req1->stage = stage;
3754 req1->xy_sel = sel_x ? 1 : 0;
3755 hnae3_set_bit(req1->port_info, HCLGE_FD_EPORT_SW_EN_B, 0);
3756 req1->index = cpu_to_le32(loc);
3757 req1->entry_vld = sel_x ? is_add : 0;
3760 memcpy(req1->tcam_data, &key[0], sizeof(req1->tcam_data));
3761 memcpy(req2->tcam_data, &key[sizeof(req1->tcam_data)],
3762 sizeof(req2->tcam_data));
3763 memcpy(req3->tcam_data, &key[sizeof(req1->tcam_data) +
3764 sizeof(req2->tcam_data)], sizeof(req3->tcam_data));
3767 ret = hclge_cmd_send(&hdev->hw, desc, 3);
3769 dev_err(&hdev->pdev->dev,
3770 "config tcam key fail, ret=%d\n",
3776 static int hclge_fd_ad_config(struct hclge_dev *hdev, u8 stage, int loc,
3777 struct hclge_fd_ad_data *action)
3779 struct hclge_fd_ad_config_cmd *req;
3780 struct hclge_desc desc;
3784 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_FD_AD_OP, false);
3786 req = (struct hclge_fd_ad_config_cmd *)desc.data;
3787 req->index = cpu_to_le32(loc);
3790 hnae3_set_bit(ad_data, HCLGE_FD_AD_WR_RULE_ID_B,
3791 action->write_rule_id_to_bd);
3792 hnae3_set_field(ad_data, HCLGE_FD_AD_RULE_ID_M, HCLGE_FD_AD_RULE_ID_S,
3795 hnae3_set_bit(ad_data, HCLGE_FD_AD_DROP_B, action->drop_packet);
3796 hnae3_set_bit(ad_data, HCLGE_FD_AD_DIRECT_QID_B,
3797 action->forward_to_direct_queue);
3798 hnae3_set_field(ad_data, HCLGE_FD_AD_QID_M, HCLGE_FD_AD_QID_S,
3800 hnae3_set_bit(ad_data, HCLGE_FD_AD_USE_COUNTER_B, action->use_counter);
3801 hnae3_set_field(ad_data, HCLGE_FD_AD_COUNTER_NUM_M,
3802 HCLGE_FD_AD_COUNTER_NUM_S, action->counter_id);
3803 hnae3_set_bit(ad_data, HCLGE_FD_AD_NXT_STEP_B, action->use_next_stage);
3804 hnae3_set_field(ad_data, HCLGE_FD_AD_NXT_KEY_M, HCLGE_FD_AD_NXT_KEY_S,
3805 action->counter_id);
3807 req->ad_data = cpu_to_le64(ad_data);
3808 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
3810 dev_err(&hdev->pdev->dev, "fd ad config fail, ret=%d\n", ret);
3815 static bool hclge_fd_convert_tuple(u32 tuple_bit, u8 *key_x, u8 *key_y,
3816 struct hclge_fd_rule *rule)
3818 u16 tmp_x_s, tmp_y_s;
3819 u32 tmp_x_l, tmp_y_l;
3822 if (rule->unused_tuple & tuple_bit)
3825 switch (tuple_bit) {
3828 case BIT(INNER_DST_MAC):
3829 for (i = 0; i < 6; i++) {
3830 calc_x(key_x[5 - i], rule->tuples.dst_mac[i],
3831 rule->tuples_mask.dst_mac[i]);
3832 calc_y(key_y[5 - i], rule->tuples.dst_mac[i],
3833 rule->tuples_mask.dst_mac[i]);
3837 case BIT(INNER_SRC_MAC):
3838 for (i = 0; i < 6; i++) {
3839 calc_x(key_x[5 - i], rule->tuples.src_mac[i],
3840 rule->tuples.src_mac[i]);
3841 calc_y(key_y[5 - i], rule->tuples.src_mac[i],
3842 rule->tuples.src_mac[i]);
3846 case BIT(INNER_VLAN_TAG_FST):
3847 calc_x(tmp_x_s, rule->tuples.vlan_tag1,
3848 rule->tuples_mask.vlan_tag1);
3849 calc_y(tmp_y_s, rule->tuples.vlan_tag1,
3850 rule->tuples_mask.vlan_tag1);
3851 *(__le16 *)key_x = cpu_to_le16(tmp_x_s);
3852 *(__le16 *)key_y = cpu_to_le16(tmp_y_s);
3855 case BIT(INNER_ETH_TYPE):
3856 calc_x(tmp_x_s, rule->tuples.ether_proto,
3857 rule->tuples_mask.ether_proto);
3858 calc_y(tmp_y_s, rule->tuples.ether_proto,
3859 rule->tuples_mask.ether_proto);
3860 *(__le16 *)key_x = cpu_to_le16(tmp_x_s);
3861 *(__le16 *)key_y = cpu_to_le16(tmp_y_s);
3864 case BIT(INNER_IP_TOS):
3865 calc_x(*key_x, rule->tuples.ip_tos, rule->tuples_mask.ip_tos);
3866 calc_y(*key_y, rule->tuples.ip_tos, rule->tuples_mask.ip_tos);
3869 case BIT(INNER_IP_PROTO):
3870 calc_x(*key_x, rule->tuples.ip_proto,
3871 rule->tuples_mask.ip_proto);
3872 calc_y(*key_y, rule->tuples.ip_proto,
3873 rule->tuples_mask.ip_proto);
3876 case BIT(INNER_SRC_IP):
3877 calc_x(tmp_x_l, rule->tuples.src_ip[3],
3878 rule->tuples_mask.src_ip[3]);
3879 calc_y(tmp_y_l, rule->tuples.src_ip[3],
3880 rule->tuples_mask.src_ip[3]);
3881 *(__le32 *)key_x = cpu_to_le32(tmp_x_l);
3882 *(__le32 *)key_y = cpu_to_le32(tmp_y_l);
3885 case BIT(INNER_DST_IP):
3886 calc_x(tmp_x_l, rule->tuples.dst_ip[3],
3887 rule->tuples_mask.dst_ip[3]);
3888 calc_y(tmp_y_l, rule->tuples.dst_ip[3],
3889 rule->tuples_mask.dst_ip[3]);
3890 *(__le32 *)key_x = cpu_to_le32(tmp_x_l);
3891 *(__le32 *)key_y = cpu_to_le32(tmp_y_l);
3894 case BIT(INNER_SRC_PORT):
3895 calc_x(tmp_x_s, rule->tuples.src_port,
3896 rule->tuples_mask.src_port);
3897 calc_y(tmp_y_s, rule->tuples.src_port,
3898 rule->tuples_mask.src_port);
3899 *(__le16 *)key_x = cpu_to_le16(tmp_x_s);
3900 *(__le16 *)key_y = cpu_to_le16(tmp_y_s);
3903 case BIT(INNER_DST_PORT):
3904 calc_x(tmp_x_s, rule->tuples.dst_port,
3905 rule->tuples_mask.dst_port);
3906 calc_y(tmp_y_s, rule->tuples.dst_port,
3907 rule->tuples_mask.dst_port);
3908 *(__le16 *)key_x = cpu_to_le16(tmp_x_s);
3909 *(__le16 *)key_y = cpu_to_le16(tmp_y_s);
3917 static u32 hclge_get_port_number(enum HLCGE_PORT_TYPE port_type, u8 pf_id,
3918 u8 vf_id, u8 network_port_id)
3920 u32 port_number = 0;
3922 if (port_type == HOST_PORT) {
3923 hnae3_set_field(port_number, HCLGE_PF_ID_M, HCLGE_PF_ID_S,
3925 hnae3_set_field(port_number, HCLGE_VF_ID_M, HCLGE_VF_ID_S,
3927 hnae3_set_bit(port_number, HCLGE_PORT_TYPE_B, HOST_PORT);
3929 hnae3_set_field(port_number, HCLGE_NETWORK_PORT_ID_M,
3930 HCLGE_NETWORK_PORT_ID_S, network_port_id);
3931 hnae3_set_bit(port_number, HCLGE_PORT_TYPE_B, NETWORK_PORT);
3937 static void hclge_fd_convert_meta_data(struct hclge_fd_key_cfg *key_cfg,
3938 __le32 *key_x, __le32 *key_y,
3939 struct hclge_fd_rule *rule)
3941 u32 tuple_bit, meta_data = 0, tmp_x, tmp_y, port_number;
3942 u8 cur_pos = 0, tuple_size, shift_bits;
3945 for (i = 0; i < MAX_META_DATA; i++) {
3946 tuple_size = meta_data_key_info[i].key_length;
3947 tuple_bit = key_cfg->meta_data_active & BIT(i);
3949 switch (tuple_bit) {
3950 case BIT(ROCE_TYPE):
3951 hnae3_set_bit(meta_data, cur_pos, NIC_PACKET);
3952 cur_pos += tuple_size;
3954 case BIT(DST_VPORT):
3955 port_number = hclge_get_port_number(HOST_PORT, 0,
3957 hnae3_set_field(meta_data,
3958 GENMASK(cur_pos + tuple_size, cur_pos),
3959 cur_pos, port_number);
3960 cur_pos += tuple_size;
3967 calc_x(tmp_x, meta_data, 0xFFFFFFFF);
3968 calc_y(tmp_y, meta_data, 0xFFFFFFFF);
3969 shift_bits = sizeof(meta_data) * 8 - cur_pos;
3971 *key_x = cpu_to_le32(tmp_x << shift_bits);
3972 *key_y = cpu_to_le32(tmp_y << shift_bits);
3975 /* A complete key is combined with meta data key and tuple key.
3976 * Meta data key is stored at the MSB region, and tuple key is stored at
3977 * the LSB region, unused bits will be filled 0.
3979 static int hclge_config_key(struct hclge_dev *hdev, u8 stage,
3980 struct hclge_fd_rule *rule)
3982 struct hclge_fd_key_cfg *key_cfg = &hdev->fd_cfg.key_cfg[stage];
3983 u8 key_x[MAX_KEY_BYTES], key_y[MAX_KEY_BYTES];
3984 u8 *cur_key_x, *cur_key_y;
3985 int i, ret, tuple_size;
3986 u8 meta_data_region;
3988 memset(key_x, 0, sizeof(key_x));
3989 memset(key_y, 0, sizeof(key_y));
3993 for (i = 0 ; i < MAX_TUPLE; i++) {
3997 tuple_size = tuple_key_info[i].key_length / 8;
3998 check_tuple = key_cfg->tuple_active & BIT(i);
4000 tuple_valid = hclge_fd_convert_tuple(check_tuple, cur_key_x,
4003 cur_key_x += tuple_size;
4004 cur_key_y += tuple_size;
4008 meta_data_region = hdev->fd_cfg.max_key_length / 8 -
4009 MAX_META_DATA_LENGTH / 8;
4011 hclge_fd_convert_meta_data(key_cfg,
4012 (__le32 *)(key_x + meta_data_region),
4013 (__le32 *)(key_y + meta_data_region),
4016 ret = hclge_fd_tcam_config(hdev, stage, false, rule->location, key_y,
4019 dev_err(&hdev->pdev->dev,
4020 "fd key_y config fail, loc=%d, ret=%d\n",
4021 rule->queue_id, ret);
4025 ret = hclge_fd_tcam_config(hdev, stage, true, rule->location, key_x,
4028 dev_err(&hdev->pdev->dev,
4029 "fd key_x config fail, loc=%d, ret=%d\n",
4030 rule->queue_id, ret);
4034 static int hclge_config_action(struct hclge_dev *hdev, u8 stage,
4035 struct hclge_fd_rule *rule)
4037 struct hclge_fd_ad_data ad_data;
4039 ad_data.ad_id = rule->location;
4041 if (rule->action == HCLGE_FD_ACTION_DROP_PACKET) {
4042 ad_data.drop_packet = true;
4043 ad_data.forward_to_direct_queue = false;
4044 ad_data.queue_id = 0;
4046 ad_data.drop_packet = false;
4047 ad_data.forward_to_direct_queue = true;
4048 ad_data.queue_id = rule->queue_id;
4051 ad_data.use_counter = false;
4052 ad_data.counter_id = 0;
4054 ad_data.use_next_stage = false;
4055 ad_data.next_input_key = 0;
4057 ad_data.write_rule_id_to_bd = true;
4058 ad_data.rule_id = rule->location;
4060 return hclge_fd_ad_config(hdev, stage, ad_data.ad_id, &ad_data);
4063 static int hclge_fd_check_spec(struct hclge_dev *hdev,
4064 struct ethtool_rx_flow_spec *fs, u32 *unused)
4066 struct ethtool_tcpip4_spec *tcp_ip4_spec;
4067 struct ethtool_usrip4_spec *usr_ip4_spec;
4068 struct ethtool_tcpip6_spec *tcp_ip6_spec;
4069 struct ethtool_usrip6_spec *usr_ip6_spec;
4070 struct ethhdr *ether_spec;
4072 if (fs->location >= hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
4075 if (!(fs->flow_type & hdev->fd_cfg.proto_support))
4078 if ((fs->flow_type & FLOW_EXT) &&
4079 (fs->h_ext.data[0] != 0 || fs->h_ext.data[1] != 0)) {
4080 dev_err(&hdev->pdev->dev, "user-def bytes are not supported\n");
4084 switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
4088 tcp_ip4_spec = &fs->h_u.tcp_ip4_spec;
4089 *unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC);
4091 if (!tcp_ip4_spec->ip4src)
4092 *unused |= BIT(INNER_SRC_IP);
4094 if (!tcp_ip4_spec->ip4dst)
4095 *unused |= BIT(INNER_DST_IP);
4097 if (!tcp_ip4_spec->psrc)
4098 *unused |= BIT(INNER_SRC_PORT);
4100 if (!tcp_ip4_spec->pdst)
4101 *unused |= BIT(INNER_DST_PORT);
4103 if (!tcp_ip4_spec->tos)
4104 *unused |= BIT(INNER_IP_TOS);
4108 usr_ip4_spec = &fs->h_u.usr_ip4_spec;
4109 *unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
4110 BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT);
4112 if (!usr_ip4_spec->ip4src)
4113 *unused |= BIT(INNER_SRC_IP);
4115 if (!usr_ip4_spec->ip4dst)
4116 *unused |= BIT(INNER_DST_IP);
4118 if (!usr_ip4_spec->tos)
4119 *unused |= BIT(INNER_IP_TOS);
4121 if (!usr_ip4_spec->proto)
4122 *unused |= BIT(INNER_IP_PROTO);
4124 if (usr_ip4_spec->l4_4_bytes)
4127 if (usr_ip4_spec->ip_ver != ETH_RX_NFC_IP4)
4134 tcp_ip6_spec = &fs->h_u.tcp_ip6_spec;
4135 *unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
4138 if (!tcp_ip6_spec->ip6src[0] && !tcp_ip6_spec->ip6src[1] &&
4139 !tcp_ip6_spec->ip6src[2] && !tcp_ip6_spec->ip6src[3])
4140 *unused |= BIT(INNER_SRC_IP);
4142 if (!tcp_ip6_spec->ip6dst[0] && !tcp_ip6_spec->ip6dst[1] &&
4143 !tcp_ip6_spec->ip6dst[2] && !tcp_ip6_spec->ip6dst[3])
4144 *unused |= BIT(INNER_DST_IP);
4146 if (!tcp_ip6_spec->psrc)
4147 *unused |= BIT(INNER_SRC_PORT);
4149 if (!tcp_ip6_spec->pdst)
4150 *unused |= BIT(INNER_DST_PORT);
4152 if (tcp_ip6_spec->tclass)
4156 case IPV6_USER_FLOW:
4157 usr_ip6_spec = &fs->h_u.usr_ip6_spec;
4158 *unused |= BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC) |
4159 BIT(INNER_IP_TOS) | BIT(INNER_SRC_PORT) |
4160 BIT(INNER_DST_PORT);
4162 if (!usr_ip6_spec->ip6src[0] && !usr_ip6_spec->ip6src[1] &&
4163 !usr_ip6_spec->ip6src[2] && !usr_ip6_spec->ip6src[3])
4164 *unused |= BIT(INNER_SRC_IP);
4166 if (!usr_ip6_spec->ip6dst[0] && !usr_ip6_spec->ip6dst[1] &&
4167 !usr_ip6_spec->ip6dst[2] && !usr_ip6_spec->ip6dst[3])
4168 *unused |= BIT(INNER_DST_IP);
4170 if (!usr_ip6_spec->l4_proto)
4171 *unused |= BIT(INNER_IP_PROTO);
4173 if (usr_ip6_spec->tclass)
4176 if (usr_ip6_spec->l4_4_bytes)
4181 ether_spec = &fs->h_u.ether_spec;
4182 *unused |= BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) |
4183 BIT(INNER_SRC_PORT) | BIT(INNER_DST_PORT) |
4184 BIT(INNER_IP_TOS) | BIT(INNER_IP_PROTO);
4186 if (is_zero_ether_addr(ether_spec->h_source))
4187 *unused |= BIT(INNER_SRC_MAC);
4189 if (is_zero_ether_addr(ether_spec->h_dest))
4190 *unused |= BIT(INNER_DST_MAC);
4192 if (!ether_spec->h_proto)
4193 *unused |= BIT(INNER_ETH_TYPE);
4200 if ((fs->flow_type & FLOW_EXT)) {
4201 if (fs->h_ext.vlan_etype)
4203 if (!fs->h_ext.vlan_tci)
4204 *unused |= BIT(INNER_VLAN_TAG_FST);
4206 if (fs->m_ext.vlan_tci) {
4207 if (be16_to_cpu(fs->h_ext.vlan_tci) >= VLAN_N_VID)
4211 *unused |= BIT(INNER_VLAN_TAG_FST);
4214 if (fs->flow_type & FLOW_MAC_EXT) {
4215 if (!(hdev->fd_cfg.proto_support & ETHER_FLOW))
4218 if (is_zero_ether_addr(fs->h_ext.h_dest))
4219 *unused |= BIT(INNER_DST_MAC);
4221 *unused &= ~(BIT(INNER_DST_MAC));
4227 static bool hclge_fd_rule_exist(struct hclge_dev *hdev, u16 location)
4229 struct hclge_fd_rule *rule = NULL;
4230 struct hlist_node *node2;
4232 hlist_for_each_entry_safe(rule, node2, &hdev->fd_rule_list, rule_node) {
4233 if (rule->location >= location)
4237 return rule && rule->location == location;
4240 static int hclge_fd_update_rule_list(struct hclge_dev *hdev,
4241 struct hclge_fd_rule *new_rule,
4245 struct hclge_fd_rule *rule = NULL, *parent = NULL;
4246 struct hlist_node *node2;
4248 if (is_add && !new_rule)
4251 hlist_for_each_entry_safe(rule, node2,
4252 &hdev->fd_rule_list, rule_node) {
4253 if (rule->location >= location)
4258 if (rule && rule->location == location) {
4259 hlist_del(&rule->rule_node);
4261 hdev->hclge_fd_rule_num--;
4266 } else if (!is_add) {
4267 dev_err(&hdev->pdev->dev,
4268 "delete fail, rule %d is inexistent\n",
4273 INIT_HLIST_NODE(&new_rule->rule_node);
4276 hlist_add_behind(&new_rule->rule_node, &parent->rule_node);
4278 hlist_add_head(&new_rule->rule_node, &hdev->fd_rule_list);
4280 hdev->hclge_fd_rule_num++;
4285 static int hclge_fd_get_tuple(struct hclge_dev *hdev,
4286 struct ethtool_rx_flow_spec *fs,
4287 struct hclge_fd_rule *rule)
4289 u32 flow_type = fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT);
4291 switch (flow_type) {
4295 rule->tuples.src_ip[3] =
4296 be32_to_cpu(fs->h_u.tcp_ip4_spec.ip4src);
4297 rule->tuples_mask.src_ip[3] =
4298 be32_to_cpu(fs->m_u.tcp_ip4_spec.ip4src);
4300 rule->tuples.dst_ip[3] =
4301 be32_to_cpu(fs->h_u.tcp_ip4_spec.ip4dst);
4302 rule->tuples_mask.dst_ip[3] =
4303 be32_to_cpu(fs->m_u.tcp_ip4_spec.ip4dst);
4305 rule->tuples.src_port = be16_to_cpu(fs->h_u.tcp_ip4_spec.psrc);
4306 rule->tuples_mask.src_port =
4307 be16_to_cpu(fs->m_u.tcp_ip4_spec.psrc);
4309 rule->tuples.dst_port = be16_to_cpu(fs->h_u.tcp_ip4_spec.pdst);
4310 rule->tuples_mask.dst_port =
4311 be16_to_cpu(fs->m_u.tcp_ip4_spec.pdst);
4313 rule->tuples.ip_tos = fs->h_u.tcp_ip4_spec.tos;
4314 rule->tuples_mask.ip_tos = fs->m_u.tcp_ip4_spec.tos;
4316 rule->tuples.ether_proto = ETH_P_IP;
4317 rule->tuples_mask.ether_proto = 0xFFFF;
4321 rule->tuples.src_ip[3] =
4322 be32_to_cpu(fs->h_u.usr_ip4_spec.ip4src);
4323 rule->tuples_mask.src_ip[3] =
4324 be32_to_cpu(fs->m_u.usr_ip4_spec.ip4src);
4326 rule->tuples.dst_ip[3] =
4327 be32_to_cpu(fs->h_u.usr_ip4_spec.ip4dst);
4328 rule->tuples_mask.dst_ip[3] =
4329 be32_to_cpu(fs->m_u.usr_ip4_spec.ip4dst);
4331 rule->tuples.ip_tos = fs->h_u.usr_ip4_spec.tos;
4332 rule->tuples_mask.ip_tos = fs->m_u.usr_ip4_spec.tos;
4334 rule->tuples.ip_proto = fs->h_u.usr_ip4_spec.proto;
4335 rule->tuples_mask.ip_proto = fs->m_u.usr_ip4_spec.proto;
4337 rule->tuples.ether_proto = ETH_P_IP;
4338 rule->tuples_mask.ether_proto = 0xFFFF;
4344 be32_to_cpu_array(rule->tuples.src_ip,
4345 fs->h_u.tcp_ip6_spec.ip6src, 4);
4346 be32_to_cpu_array(rule->tuples_mask.src_ip,
4347 fs->m_u.tcp_ip6_spec.ip6src, 4);
4349 be32_to_cpu_array(rule->tuples.dst_ip,
4350 fs->h_u.tcp_ip6_spec.ip6dst, 4);
4351 be32_to_cpu_array(rule->tuples_mask.dst_ip,
4352 fs->m_u.tcp_ip6_spec.ip6dst, 4);
4354 rule->tuples.src_port = be16_to_cpu(fs->h_u.tcp_ip6_spec.psrc);
4355 rule->tuples_mask.src_port =
4356 be16_to_cpu(fs->m_u.tcp_ip6_spec.psrc);
4358 rule->tuples.dst_port = be16_to_cpu(fs->h_u.tcp_ip6_spec.pdst);
4359 rule->tuples_mask.dst_port =
4360 be16_to_cpu(fs->m_u.tcp_ip6_spec.pdst);
4362 rule->tuples.ether_proto = ETH_P_IPV6;
4363 rule->tuples_mask.ether_proto = 0xFFFF;
4366 case IPV6_USER_FLOW:
4367 be32_to_cpu_array(rule->tuples.src_ip,
4368 fs->h_u.usr_ip6_spec.ip6src, 4);
4369 be32_to_cpu_array(rule->tuples_mask.src_ip,
4370 fs->m_u.usr_ip6_spec.ip6src, 4);
4372 be32_to_cpu_array(rule->tuples.dst_ip,
4373 fs->h_u.usr_ip6_spec.ip6dst, 4);
4374 be32_to_cpu_array(rule->tuples_mask.dst_ip,
4375 fs->m_u.usr_ip6_spec.ip6dst, 4);
4377 rule->tuples.ip_proto = fs->h_u.usr_ip6_spec.l4_proto;
4378 rule->tuples_mask.ip_proto = fs->m_u.usr_ip6_spec.l4_proto;
4380 rule->tuples.ether_proto = ETH_P_IPV6;
4381 rule->tuples_mask.ether_proto = 0xFFFF;
4385 ether_addr_copy(rule->tuples.src_mac,
4386 fs->h_u.ether_spec.h_source);
4387 ether_addr_copy(rule->tuples_mask.src_mac,
4388 fs->m_u.ether_spec.h_source);
4390 ether_addr_copy(rule->tuples.dst_mac,
4391 fs->h_u.ether_spec.h_dest);
4392 ether_addr_copy(rule->tuples_mask.dst_mac,
4393 fs->m_u.ether_spec.h_dest);
4395 rule->tuples.ether_proto =
4396 be16_to_cpu(fs->h_u.ether_spec.h_proto);
4397 rule->tuples_mask.ether_proto =
4398 be16_to_cpu(fs->m_u.ether_spec.h_proto);
4405 switch (flow_type) {
4408 rule->tuples.ip_proto = IPPROTO_SCTP;
4409 rule->tuples_mask.ip_proto = 0xFF;
4413 rule->tuples.ip_proto = IPPROTO_TCP;
4414 rule->tuples_mask.ip_proto = 0xFF;
4418 rule->tuples.ip_proto = IPPROTO_UDP;
4419 rule->tuples_mask.ip_proto = 0xFF;
4425 if ((fs->flow_type & FLOW_EXT)) {
4426 rule->tuples.vlan_tag1 = be16_to_cpu(fs->h_ext.vlan_tci);
4427 rule->tuples_mask.vlan_tag1 = be16_to_cpu(fs->m_ext.vlan_tci);
4430 if (fs->flow_type & FLOW_MAC_EXT) {
4431 ether_addr_copy(rule->tuples.dst_mac, fs->h_ext.h_dest);
4432 ether_addr_copy(rule->tuples_mask.dst_mac, fs->m_ext.h_dest);
4438 static int hclge_add_fd_entry(struct hnae3_handle *handle,
4439 struct ethtool_rxnfc *cmd)
4441 struct hclge_vport *vport = hclge_get_vport(handle);
4442 struct hclge_dev *hdev = vport->back;
4443 u16 dst_vport_id = 0, q_index = 0;
4444 struct ethtool_rx_flow_spec *fs;
4445 struct hclge_fd_rule *rule;
4450 if (!hnae3_dev_fd_supported(hdev))
4453 if (!hdev->fd_cfg.fd_en) {
4454 dev_warn(&hdev->pdev->dev,
4455 "Please enable flow director first\n");
4459 fs = (struct ethtool_rx_flow_spec *)&cmd->fs;
4461 ret = hclge_fd_check_spec(hdev, fs, &unused);
4463 dev_err(&hdev->pdev->dev, "Check fd spec failed\n");
4467 if (fs->ring_cookie == RX_CLS_FLOW_DISC) {
4468 action = HCLGE_FD_ACTION_DROP_PACKET;
4470 u32 ring = ethtool_get_flow_spec_ring(fs->ring_cookie);
4471 u8 vf = ethtool_get_flow_spec_ring_vf(fs->ring_cookie);
4474 dst_vport_id = vf ? hdev->vport[vf].vport_id : vport->vport_id;
4475 tqps = vf ? hdev->vport[vf].alloc_tqps : vport->alloc_tqps;
4478 dev_err(&hdev->pdev->dev,
4479 "Error: queue id (%d) > max tqp num (%d)\n",
4484 if (vf > hdev->num_req_vfs) {
4485 dev_err(&hdev->pdev->dev,
4486 "Error: vf id (%d) > max vf num (%d)\n",
4487 vf, hdev->num_req_vfs);
4491 action = HCLGE_FD_ACTION_ACCEPT_PACKET;
4495 rule = kzalloc(sizeof(*rule), GFP_KERNEL);
4499 ret = hclge_fd_get_tuple(hdev, fs, rule);
4503 rule->flow_type = fs->flow_type;
4505 rule->location = fs->location;
4506 rule->unused_tuple = unused;
4507 rule->vf_id = dst_vport_id;
4508 rule->queue_id = q_index;
4509 rule->action = action;
4511 ret = hclge_config_action(hdev, HCLGE_FD_STAGE_1, rule);
4515 ret = hclge_config_key(hdev, HCLGE_FD_STAGE_1, rule);
4519 ret = hclge_fd_update_rule_list(hdev, rule, fs->location, true);
4530 static int hclge_del_fd_entry(struct hnae3_handle *handle,
4531 struct ethtool_rxnfc *cmd)
4533 struct hclge_vport *vport = hclge_get_vport(handle);
4534 struct hclge_dev *hdev = vport->back;
4535 struct ethtool_rx_flow_spec *fs;
4538 if (!hnae3_dev_fd_supported(hdev))
4541 fs = (struct ethtool_rx_flow_spec *)&cmd->fs;
4543 if (fs->location >= hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
4546 if (!hclge_fd_rule_exist(hdev, fs->location)) {
4547 dev_err(&hdev->pdev->dev,
4548 "Delete fail, rule %d is inexistent\n",
4553 ret = hclge_fd_tcam_config(hdev, HCLGE_FD_STAGE_1, true,
4554 fs->location, NULL, false);
4558 return hclge_fd_update_rule_list(hdev, NULL, fs->location,
4562 static void hclge_del_all_fd_entries(struct hnae3_handle *handle,
4565 struct hclge_vport *vport = hclge_get_vport(handle);
4566 struct hclge_dev *hdev = vport->back;
4567 struct hclge_fd_rule *rule;
4568 struct hlist_node *node;
4570 if (!hnae3_dev_fd_supported(hdev))
4574 hlist_for_each_entry_safe(rule, node, &hdev->fd_rule_list,
4576 hclge_fd_tcam_config(hdev, HCLGE_FD_STAGE_1, true,
4577 rule->location, NULL, false);
4578 hlist_del(&rule->rule_node);
4580 hdev->hclge_fd_rule_num--;
4583 hlist_for_each_entry_safe(rule, node, &hdev->fd_rule_list,
4585 hclge_fd_tcam_config(hdev, HCLGE_FD_STAGE_1, true,
4586 rule->location, NULL, false);
4590 static int hclge_restore_fd_entries(struct hnae3_handle *handle)
4592 struct hclge_vport *vport = hclge_get_vport(handle);
4593 struct hclge_dev *hdev = vport->back;
4594 struct hclge_fd_rule *rule;
4595 struct hlist_node *node;
4598 /* Return ok here, because reset error handling will check this
4599 * return value. If error is returned here, the reset process will
4602 if (!hnae3_dev_fd_supported(hdev))
4605 hlist_for_each_entry_safe(rule, node, &hdev->fd_rule_list, rule_node) {
4606 ret = hclge_config_action(hdev, HCLGE_FD_STAGE_1, rule);
4608 ret = hclge_config_key(hdev, HCLGE_FD_STAGE_1, rule);
4611 dev_warn(&hdev->pdev->dev,
4612 "Restore rule %d failed, remove it\n",
4614 hlist_del(&rule->rule_node);
4616 hdev->hclge_fd_rule_num--;
4622 static int hclge_get_fd_rule_cnt(struct hnae3_handle *handle,
4623 struct ethtool_rxnfc *cmd)
4625 struct hclge_vport *vport = hclge_get_vport(handle);
4626 struct hclge_dev *hdev = vport->back;
4628 if (!hnae3_dev_fd_supported(hdev))
4631 cmd->rule_cnt = hdev->hclge_fd_rule_num;
4632 cmd->data = hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1];
4637 static int hclge_get_fd_rule_info(struct hnae3_handle *handle,
4638 struct ethtool_rxnfc *cmd)
4640 struct hclge_vport *vport = hclge_get_vport(handle);
4641 struct hclge_fd_rule *rule = NULL;
4642 struct hclge_dev *hdev = vport->back;
4643 struct ethtool_rx_flow_spec *fs;
4644 struct hlist_node *node2;
4646 if (!hnae3_dev_fd_supported(hdev))
4649 fs = (struct ethtool_rx_flow_spec *)&cmd->fs;
4651 hlist_for_each_entry_safe(rule, node2, &hdev->fd_rule_list, rule_node) {
4652 if (rule->location >= fs->location)
4656 if (!rule || fs->location != rule->location)
4659 fs->flow_type = rule->flow_type;
4660 switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
4664 fs->h_u.tcp_ip4_spec.ip4src =
4665 cpu_to_be32(rule->tuples.src_ip[3]);
4666 fs->m_u.tcp_ip4_spec.ip4src =
4667 rule->unused_tuple & BIT(INNER_SRC_IP) ?
4668 0 : cpu_to_be32(rule->tuples_mask.src_ip[3]);
4670 fs->h_u.tcp_ip4_spec.ip4dst =
4671 cpu_to_be32(rule->tuples.dst_ip[3]);
4672 fs->m_u.tcp_ip4_spec.ip4dst =
4673 rule->unused_tuple & BIT(INNER_DST_IP) ?
4674 0 : cpu_to_be32(rule->tuples_mask.dst_ip[3]);
4676 fs->h_u.tcp_ip4_spec.psrc = cpu_to_be16(rule->tuples.src_port);
4677 fs->m_u.tcp_ip4_spec.psrc =
4678 rule->unused_tuple & BIT(INNER_SRC_PORT) ?
4679 0 : cpu_to_be16(rule->tuples_mask.src_port);
4681 fs->h_u.tcp_ip4_spec.pdst = cpu_to_be16(rule->tuples.dst_port);
4682 fs->m_u.tcp_ip4_spec.pdst =
4683 rule->unused_tuple & BIT(INNER_DST_PORT) ?
4684 0 : cpu_to_be16(rule->tuples_mask.dst_port);
4686 fs->h_u.tcp_ip4_spec.tos = rule->tuples.ip_tos;
4687 fs->m_u.tcp_ip4_spec.tos =
4688 rule->unused_tuple & BIT(INNER_IP_TOS) ?
4689 0 : rule->tuples_mask.ip_tos;
4693 fs->h_u.usr_ip4_spec.ip4src =
4694 cpu_to_be32(rule->tuples.src_ip[3]);
4695 fs->m_u.tcp_ip4_spec.ip4src =
4696 rule->unused_tuple & BIT(INNER_SRC_IP) ?
4697 0 : cpu_to_be32(rule->tuples_mask.src_ip[3]);
4699 fs->h_u.usr_ip4_spec.ip4dst =
4700 cpu_to_be32(rule->tuples.dst_ip[3]);
4701 fs->m_u.usr_ip4_spec.ip4dst =
4702 rule->unused_tuple & BIT(INNER_DST_IP) ?
4703 0 : cpu_to_be32(rule->tuples_mask.dst_ip[3]);
4705 fs->h_u.usr_ip4_spec.tos = rule->tuples.ip_tos;
4706 fs->m_u.usr_ip4_spec.tos =
4707 rule->unused_tuple & BIT(INNER_IP_TOS) ?
4708 0 : rule->tuples_mask.ip_tos;
4710 fs->h_u.usr_ip4_spec.proto = rule->tuples.ip_proto;
4711 fs->m_u.usr_ip4_spec.proto =
4712 rule->unused_tuple & BIT(INNER_IP_PROTO) ?
4713 0 : rule->tuples_mask.ip_proto;
4715 fs->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
4721 cpu_to_be32_array(fs->h_u.tcp_ip6_spec.ip6src,
4722 rule->tuples.src_ip, 4);
4723 if (rule->unused_tuple & BIT(INNER_SRC_IP))
4724 memset(fs->m_u.tcp_ip6_spec.ip6src, 0, sizeof(int) * 4);
4726 cpu_to_be32_array(fs->m_u.tcp_ip6_spec.ip6src,
4727 rule->tuples_mask.src_ip, 4);
4729 cpu_to_be32_array(fs->h_u.tcp_ip6_spec.ip6dst,
4730 rule->tuples.dst_ip, 4);
4731 if (rule->unused_tuple & BIT(INNER_DST_IP))
4732 memset(fs->m_u.tcp_ip6_spec.ip6dst, 0, sizeof(int) * 4);
4734 cpu_to_be32_array(fs->m_u.tcp_ip6_spec.ip6dst,
4735 rule->tuples_mask.dst_ip, 4);
4737 fs->h_u.tcp_ip6_spec.psrc = cpu_to_be16(rule->tuples.src_port);
4738 fs->m_u.tcp_ip6_spec.psrc =
4739 rule->unused_tuple & BIT(INNER_SRC_PORT) ?
4740 0 : cpu_to_be16(rule->tuples_mask.src_port);
4742 fs->h_u.tcp_ip6_spec.pdst = cpu_to_be16(rule->tuples.dst_port);
4743 fs->m_u.tcp_ip6_spec.pdst =
4744 rule->unused_tuple & BIT(INNER_DST_PORT) ?
4745 0 : cpu_to_be16(rule->tuples_mask.dst_port);
4748 case IPV6_USER_FLOW:
4749 cpu_to_be32_array(fs->h_u.usr_ip6_spec.ip6src,
4750 rule->tuples.src_ip, 4);
4751 if (rule->unused_tuple & BIT(INNER_SRC_IP))
4752 memset(fs->m_u.usr_ip6_spec.ip6src, 0, sizeof(int) * 4);
4754 cpu_to_be32_array(fs->m_u.usr_ip6_spec.ip6src,
4755 rule->tuples_mask.src_ip, 4);
4757 cpu_to_be32_array(fs->h_u.usr_ip6_spec.ip6dst,
4758 rule->tuples.dst_ip, 4);
4759 if (rule->unused_tuple & BIT(INNER_DST_IP))
4760 memset(fs->m_u.usr_ip6_spec.ip6dst, 0, sizeof(int) * 4);
4762 cpu_to_be32_array(fs->m_u.usr_ip6_spec.ip6dst,
4763 rule->tuples_mask.dst_ip, 4);
4765 fs->h_u.usr_ip6_spec.l4_proto = rule->tuples.ip_proto;
4766 fs->m_u.usr_ip6_spec.l4_proto =
4767 rule->unused_tuple & BIT(INNER_IP_PROTO) ?
4768 0 : rule->tuples_mask.ip_proto;
4772 ether_addr_copy(fs->h_u.ether_spec.h_source,
4773 rule->tuples.src_mac);
4774 if (rule->unused_tuple & BIT(INNER_SRC_MAC))
4775 eth_zero_addr(fs->m_u.ether_spec.h_source);
4777 ether_addr_copy(fs->m_u.ether_spec.h_source,
4778 rule->tuples_mask.src_mac);
4780 ether_addr_copy(fs->h_u.ether_spec.h_dest,
4781 rule->tuples.dst_mac);
4782 if (rule->unused_tuple & BIT(INNER_DST_MAC))
4783 eth_zero_addr(fs->m_u.ether_spec.h_dest);
4785 ether_addr_copy(fs->m_u.ether_spec.h_dest,
4786 rule->tuples_mask.dst_mac);
4788 fs->h_u.ether_spec.h_proto =
4789 cpu_to_be16(rule->tuples.ether_proto);
4790 fs->m_u.ether_spec.h_proto =
4791 rule->unused_tuple & BIT(INNER_ETH_TYPE) ?
4792 0 : cpu_to_be16(rule->tuples_mask.ether_proto);
4799 if (fs->flow_type & FLOW_EXT) {
4800 fs->h_ext.vlan_tci = cpu_to_be16(rule->tuples.vlan_tag1);
4801 fs->m_ext.vlan_tci =
4802 rule->unused_tuple & BIT(INNER_VLAN_TAG_FST) ?
4803 cpu_to_be16(VLAN_VID_MASK) :
4804 cpu_to_be16(rule->tuples_mask.vlan_tag1);
4807 if (fs->flow_type & FLOW_MAC_EXT) {
4808 ether_addr_copy(fs->h_ext.h_dest, rule->tuples.dst_mac);
4809 if (rule->unused_tuple & BIT(INNER_DST_MAC))
4810 eth_zero_addr(fs->m_u.ether_spec.h_dest);
4812 ether_addr_copy(fs->m_u.ether_spec.h_dest,
4813 rule->tuples_mask.dst_mac);
4816 if (rule->action == HCLGE_FD_ACTION_DROP_PACKET) {
4817 fs->ring_cookie = RX_CLS_FLOW_DISC;
4821 fs->ring_cookie = rule->queue_id;
4822 vf_id = rule->vf_id;
4823 vf_id <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
4824 fs->ring_cookie |= vf_id;
4830 static int hclge_get_all_rules(struct hnae3_handle *handle,
4831 struct ethtool_rxnfc *cmd, u32 *rule_locs)
4833 struct hclge_vport *vport = hclge_get_vport(handle);
4834 struct hclge_dev *hdev = vport->back;
4835 struct hclge_fd_rule *rule;
4836 struct hlist_node *node2;
4839 if (!hnae3_dev_fd_supported(hdev))
4842 cmd->data = hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1];
4844 hlist_for_each_entry_safe(rule, node2,
4845 &hdev->fd_rule_list, rule_node) {
4846 if (cnt == cmd->rule_cnt)
4849 rule_locs[cnt] = rule->location;
4853 cmd->rule_cnt = cnt;
4858 static bool hclge_get_hw_reset_stat(struct hnae3_handle *handle)
4860 struct hclge_vport *vport = hclge_get_vport(handle);
4861 struct hclge_dev *hdev = vport->back;
4863 return hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG) ||
4864 hclge_read_dev(&hdev->hw, HCLGE_FUN_RST_ING);
4867 static bool hclge_ae_dev_resetting(struct hnae3_handle *handle)
4869 struct hclge_vport *vport = hclge_get_vport(handle);
4870 struct hclge_dev *hdev = vport->back;
4872 return test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state);
4875 static unsigned long hclge_ae_dev_reset_cnt(struct hnae3_handle *handle)
4877 struct hclge_vport *vport = hclge_get_vport(handle);
4878 struct hclge_dev *hdev = vport->back;
4880 return hdev->reset_count;
4883 static void hclge_enable_fd(struct hnae3_handle *handle, bool enable)
4885 struct hclge_vport *vport = hclge_get_vport(handle);
4886 struct hclge_dev *hdev = vport->back;
4888 hdev->fd_cfg.fd_en = enable;
4890 hclge_del_all_fd_entries(handle, false);
4892 hclge_restore_fd_entries(handle);
4895 static void hclge_cfg_mac_mode(struct hclge_dev *hdev, bool enable)
4897 struct hclge_desc desc;
4898 struct hclge_config_mac_mode_cmd *req =
4899 (struct hclge_config_mac_mode_cmd *)desc.data;
4903 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAC_MODE, false);
4904 hnae3_set_bit(loop_en, HCLGE_MAC_TX_EN_B, enable);
4905 hnae3_set_bit(loop_en, HCLGE_MAC_RX_EN_B, enable);
4906 hnae3_set_bit(loop_en, HCLGE_MAC_PAD_TX_B, enable);
4907 hnae3_set_bit(loop_en, HCLGE_MAC_PAD_RX_B, enable);
4908 hnae3_set_bit(loop_en, HCLGE_MAC_1588_TX_B, 0);
4909 hnae3_set_bit(loop_en, HCLGE_MAC_1588_RX_B, 0);
4910 hnae3_set_bit(loop_en, HCLGE_MAC_APP_LP_B, 0);
4911 hnae3_set_bit(loop_en, HCLGE_MAC_LINE_LP_B, 0);
4912 hnae3_set_bit(loop_en, HCLGE_MAC_FCS_TX_B, enable);
4913 hnae3_set_bit(loop_en, HCLGE_MAC_RX_FCS_B, enable);
4914 hnae3_set_bit(loop_en, HCLGE_MAC_RX_FCS_STRIP_B, enable);
4915 hnae3_set_bit(loop_en, HCLGE_MAC_TX_OVERSIZE_TRUNCATE_B, enable);
4916 hnae3_set_bit(loop_en, HCLGE_MAC_RX_OVERSIZE_TRUNCATE_B, enable);
4917 hnae3_set_bit(loop_en, HCLGE_MAC_TX_UNDER_MIN_ERR_B, enable);
4918 req->txrx_pad_fcs_loop_en = cpu_to_le32(loop_en);
4920 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
4922 dev_err(&hdev->pdev->dev,
4923 "mac enable fail, ret =%d.\n", ret);
4926 static int hclge_set_app_loopback(struct hclge_dev *hdev, bool en)
4928 struct hclge_config_mac_mode_cmd *req;
4929 struct hclge_desc desc;
4933 req = (struct hclge_config_mac_mode_cmd *)&desc.data[0];
4934 /* 1 Read out the MAC mode config at first */
4935 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAC_MODE, true);
4936 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
4938 dev_err(&hdev->pdev->dev,
4939 "mac loopback get fail, ret =%d.\n", ret);
4943 /* 2 Then setup the loopback flag */
4944 loop_en = le32_to_cpu(req->txrx_pad_fcs_loop_en);
4945 hnae3_set_bit(loop_en, HCLGE_MAC_APP_LP_B, en ? 1 : 0);
4946 hnae3_set_bit(loop_en, HCLGE_MAC_TX_EN_B, en ? 1 : 0);
4947 hnae3_set_bit(loop_en, HCLGE_MAC_RX_EN_B, en ? 1 : 0);
4949 req->txrx_pad_fcs_loop_en = cpu_to_le32(loop_en);
4951 /* 3 Config mac work mode with loopback flag
4952 * and its original configure parameters
4954 hclge_cmd_reuse_desc(&desc, false);
4955 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
4957 dev_err(&hdev->pdev->dev,
4958 "mac loopback set fail, ret =%d.\n", ret);
4962 static int hclge_set_serdes_loopback(struct hclge_dev *hdev, bool en,
4963 enum hnae3_loop loop_mode)
4965 #define HCLGE_SERDES_RETRY_MS 10
4966 #define HCLGE_SERDES_RETRY_NUM 100
4967 struct hclge_serdes_lb_cmd *req;
4968 struct hclge_desc desc;
4972 req = (struct hclge_serdes_lb_cmd *)desc.data;
4973 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK, false);
4975 switch (loop_mode) {
4976 case HNAE3_LOOP_SERIAL_SERDES:
4977 loop_mode_b = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
4979 case HNAE3_LOOP_PARALLEL_SERDES:
4980 loop_mode_b = HCLGE_CMD_SERDES_PARALLEL_INNER_LOOP_B;
4983 dev_err(&hdev->pdev->dev,
4984 "unsupported serdes loopback mode %d\n", loop_mode);
4989 req->enable = loop_mode_b;
4990 req->mask = loop_mode_b;
4992 req->mask = loop_mode_b;
4995 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
4997 dev_err(&hdev->pdev->dev,
4998 "serdes loopback set fail, ret = %d\n", ret);
5003 msleep(HCLGE_SERDES_RETRY_MS);
5004 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK,
5006 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5008 dev_err(&hdev->pdev->dev,
5009 "serdes loopback get, ret = %d\n", ret);
5012 } while (++i < HCLGE_SERDES_RETRY_NUM &&
5013 !(req->result & HCLGE_CMD_SERDES_DONE_B));
5015 if (!(req->result & HCLGE_CMD_SERDES_DONE_B)) {
5016 dev_err(&hdev->pdev->dev, "serdes loopback set timeout\n");
5018 } else if (!(req->result & HCLGE_CMD_SERDES_SUCCESS_B)) {
5019 dev_err(&hdev->pdev->dev, "serdes loopback set failed in fw\n");
5023 hclge_cfg_mac_mode(hdev, en);
5027 static int hclge_tqp_enable(struct hclge_dev *hdev, int tqp_id,
5028 int stream_id, bool enable)
5030 struct hclge_desc desc;
5031 struct hclge_cfg_com_tqp_queue_cmd *req =
5032 (struct hclge_cfg_com_tqp_queue_cmd *)desc.data;
5035 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_COM_TQP_QUEUE, false);
5036 req->tqp_id = cpu_to_le16(tqp_id & HCLGE_RING_ID_MASK);
5037 req->stream_id = cpu_to_le16(stream_id);
5038 req->enable |= enable << HCLGE_TQP_ENABLE_B;
5040 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5042 dev_err(&hdev->pdev->dev,
5043 "Tqp enable fail, status =%d.\n", ret);
5047 static int hclge_set_loopback(struct hnae3_handle *handle,
5048 enum hnae3_loop loop_mode, bool en)
5050 struct hclge_vport *vport = hclge_get_vport(handle);
5051 struct hclge_dev *hdev = vport->back;
5054 switch (loop_mode) {
5055 case HNAE3_LOOP_APP:
5056 ret = hclge_set_app_loopback(hdev, en);
5058 case HNAE3_LOOP_SERIAL_SERDES:
5059 case HNAE3_LOOP_PARALLEL_SERDES:
5060 ret = hclge_set_serdes_loopback(hdev, en, loop_mode);
5064 dev_err(&hdev->pdev->dev,
5065 "loop_mode %d is not supported\n", loop_mode);
5069 for (i = 0; i < vport->alloc_tqps; i++) {
5070 ret = hclge_tqp_enable(hdev, i, 0, en);
5078 static void hclge_reset_tqp_stats(struct hnae3_handle *handle)
5080 struct hclge_vport *vport = hclge_get_vport(handle);
5081 struct hnae3_queue *queue;
5082 struct hclge_tqp *tqp;
5085 for (i = 0; i < vport->alloc_tqps; i++) {
5086 queue = handle->kinfo.tqp[i];
5087 tqp = container_of(queue, struct hclge_tqp, q);
5088 memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));
5092 static int hclge_ae_start(struct hnae3_handle *handle)
5094 struct hclge_vport *vport = hclge_get_vport(handle);
5095 struct hclge_dev *hdev = vport->back;
5098 hclge_cfg_mac_mode(hdev, true);
5099 clear_bit(HCLGE_STATE_DOWN, &hdev->state);
5100 mod_timer(&hdev->service_timer, jiffies + HZ);
5101 hdev->hw.mac.link = 0;
5103 /* reset tqp stats */
5104 hclge_reset_tqp_stats(handle);
5106 hclge_mac_start_phy(hdev);
5111 static void hclge_ae_stop(struct hnae3_handle *handle)
5113 struct hclge_vport *vport = hclge_get_vport(handle);
5114 struct hclge_dev *hdev = vport->back;
5116 set_bit(HCLGE_STATE_DOWN, &hdev->state);
5118 del_timer_sync(&hdev->service_timer);
5119 cancel_work_sync(&hdev->service_task);
5120 clear_bit(HCLGE_STATE_SERVICE_SCHED, &hdev->state);
5122 /* If it is not PF reset, the firmware will disable the MAC,
5123 * so it only need to stop phy here.
5125 if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) &&
5126 hdev->reset_type != HNAE3_FUNC_RESET) {
5127 hclge_mac_stop_phy(hdev);
5132 hclge_cfg_mac_mode(hdev, false);
5134 hclge_mac_stop_phy(hdev);
5136 /* reset tqp stats */
5137 hclge_reset_tqp_stats(handle);
5138 del_timer_sync(&hdev->service_timer);
5139 cancel_work_sync(&hdev->service_task);
5140 hclge_update_link_status(hdev);
5143 static int hclge_get_mac_vlan_cmd_status(struct hclge_vport *vport,
5144 u16 cmdq_resp, u8 resp_code,
5145 enum hclge_mac_vlan_tbl_opcode op)
5147 struct hclge_dev *hdev = vport->back;
5148 int return_status = -EIO;
5151 dev_err(&hdev->pdev->dev,
5152 "cmdq execute failed for get_mac_vlan_cmd_status,status=%d.\n",
5157 if (op == HCLGE_MAC_VLAN_ADD) {
5158 if ((!resp_code) || (resp_code == 1)) {
5160 } else if (resp_code == 2) {
5161 return_status = -ENOSPC;
5162 dev_err(&hdev->pdev->dev,
5163 "add mac addr failed for uc_overflow.\n");
5164 } else if (resp_code == 3) {
5165 return_status = -ENOSPC;
5166 dev_err(&hdev->pdev->dev,
5167 "add mac addr failed for mc_overflow.\n");
5169 dev_err(&hdev->pdev->dev,
5170 "add mac addr failed for undefined, code=%d.\n",
5173 } else if (op == HCLGE_MAC_VLAN_REMOVE) {
5176 } else if (resp_code == 1) {
5177 return_status = -ENOENT;
5178 dev_dbg(&hdev->pdev->dev,
5179 "remove mac addr failed for miss.\n");
5181 dev_err(&hdev->pdev->dev,
5182 "remove mac addr failed for undefined, code=%d.\n",
5185 } else if (op == HCLGE_MAC_VLAN_LKUP) {
5188 } else if (resp_code == 1) {
5189 return_status = -ENOENT;
5190 dev_dbg(&hdev->pdev->dev,
5191 "lookup mac addr failed for miss.\n");
5193 dev_err(&hdev->pdev->dev,
5194 "lookup mac addr failed for undefined, code=%d.\n",
5198 return_status = -EINVAL;
5199 dev_err(&hdev->pdev->dev,
5200 "unknown opcode for get_mac_vlan_cmd_status,opcode=%d.\n",
5204 return return_status;
5207 static int hclge_update_desc_vfid(struct hclge_desc *desc, int vfid, bool clr)
5212 if (vfid > 255 || vfid < 0)
5215 if (vfid >= 0 && vfid <= 191) {
5216 word_num = vfid / 32;
5217 bit_num = vfid % 32;
5219 desc[1].data[word_num] &= cpu_to_le32(~(1 << bit_num));
5221 desc[1].data[word_num] |= cpu_to_le32(1 << bit_num);
5223 word_num = (vfid - 192) / 32;
5224 bit_num = vfid % 32;
5226 desc[2].data[word_num] &= cpu_to_le32(~(1 << bit_num));
5228 desc[2].data[word_num] |= cpu_to_le32(1 << bit_num);
5234 static bool hclge_is_all_function_id_zero(struct hclge_desc *desc)
5236 #define HCLGE_DESC_NUMBER 3
5237 #define HCLGE_FUNC_NUMBER_PER_DESC 6
5240 for (i = 1; i < HCLGE_DESC_NUMBER; i++)
5241 for (j = 0; j < HCLGE_FUNC_NUMBER_PER_DESC; j++)
5242 if (desc[i].data[j])
5248 static void hclge_prepare_mac_addr(struct hclge_mac_vlan_tbl_entry_cmd *new_req,
5251 const unsigned char *mac_addr = addr;
5252 u32 high_val = mac_addr[2] << 16 | (mac_addr[3] << 24) |
5253 (mac_addr[0]) | (mac_addr[1] << 8);
5254 u32 low_val = mac_addr[4] | (mac_addr[5] << 8);
5256 new_req->mac_addr_hi32 = cpu_to_le32(high_val);
5257 new_req->mac_addr_lo16 = cpu_to_le16(low_val & 0xffff);
5260 static int hclge_remove_mac_vlan_tbl(struct hclge_vport *vport,
5261 struct hclge_mac_vlan_tbl_entry_cmd *req)
5263 struct hclge_dev *hdev = vport->back;
5264 struct hclge_desc desc;
5269 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_REMOVE, false);
5271 memcpy(desc.data, req, sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
5273 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5275 dev_err(&hdev->pdev->dev,
5276 "del mac addr failed for cmd_send, ret =%d.\n",
5280 resp_code = (le32_to_cpu(desc.data[0]) >> 8) & 0xff;
5281 retval = le16_to_cpu(desc.retval);
5283 return hclge_get_mac_vlan_cmd_status(vport, retval, resp_code,
5284 HCLGE_MAC_VLAN_REMOVE);
5287 static int hclge_lookup_mac_vlan_tbl(struct hclge_vport *vport,
5288 struct hclge_mac_vlan_tbl_entry_cmd *req,
5289 struct hclge_desc *desc,
5292 struct hclge_dev *hdev = vport->back;
5297 hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_MAC_VLAN_ADD, true);
5299 desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
5300 memcpy(desc[0].data,
5302 sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
5303 hclge_cmd_setup_basic_desc(&desc[1],
5304 HCLGE_OPC_MAC_VLAN_ADD,
5306 desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
5307 hclge_cmd_setup_basic_desc(&desc[2],
5308 HCLGE_OPC_MAC_VLAN_ADD,
5310 ret = hclge_cmd_send(&hdev->hw, desc, 3);
5312 memcpy(desc[0].data,
5314 sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
5315 ret = hclge_cmd_send(&hdev->hw, desc, 1);
5318 dev_err(&hdev->pdev->dev,
5319 "lookup mac addr failed for cmd_send, ret =%d.\n",
5323 resp_code = (le32_to_cpu(desc[0].data[0]) >> 8) & 0xff;
5324 retval = le16_to_cpu(desc[0].retval);
5326 return hclge_get_mac_vlan_cmd_status(vport, retval, resp_code,
5327 HCLGE_MAC_VLAN_LKUP);
5330 static int hclge_add_mac_vlan_tbl(struct hclge_vport *vport,
5331 struct hclge_mac_vlan_tbl_entry_cmd *req,
5332 struct hclge_desc *mc_desc)
5334 struct hclge_dev *hdev = vport->back;
5341 struct hclge_desc desc;
5343 hclge_cmd_setup_basic_desc(&desc,
5344 HCLGE_OPC_MAC_VLAN_ADD,
5346 memcpy(desc.data, req,
5347 sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
5348 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5349 resp_code = (le32_to_cpu(desc.data[0]) >> 8) & 0xff;
5350 retval = le16_to_cpu(desc.retval);
5352 cfg_status = hclge_get_mac_vlan_cmd_status(vport, retval,
5354 HCLGE_MAC_VLAN_ADD);
5356 hclge_cmd_reuse_desc(&mc_desc[0], false);
5357 mc_desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
5358 hclge_cmd_reuse_desc(&mc_desc[1], false);
5359 mc_desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
5360 hclge_cmd_reuse_desc(&mc_desc[2], false);
5361 mc_desc[2].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_NEXT);
5362 memcpy(mc_desc[0].data, req,
5363 sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
5364 ret = hclge_cmd_send(&hdev->hw, mc_desc, 3);
5365 resp_code = (le32_to_cpu(mc_desc[0].data[0]) >> 8) & 0xff;
5366 retval = le16_to_cpu(mc_desc[0].retval);
5368 cfg_status = hclge_get_mac_vlan_cmd_status(vport, retval,
5370 HCLGE_MAC_VLAN_ADD);
5374 dev_err(&hdev->pdev->dev,
5375 "add mac addr failed for cmd_send, ret =%d.\n",
5383 static int hclge_init_umv_space(struct hclge_dev *hdev)
5385 u16 allocated_size = 0;
5388 ret = hclge_set_umv_space(hdev, hdev->wanted_umv_size, &allocated_size,
5393 if (allocated_size < hdev->wanted_umv_size)
5394 dev_warn(&hdev->pdev->dev,
5395 "Alloc umv space failed, want %d, get %d\n",
5396 hdev->wanted_umv_size, allocated_size);
5398 mutex_init(&hdev->umv_mutex);
5399 hdev->max_umv_size = allocated_size;
5400 hdev->priv_umv_size = hdev->max_umv_size / (hdev->num_req_vfs + 2);
5401 hdev->share_umv_size = hdev->priv_umv_size +
5402 hdev->max_umv_size % (hdev->num_req_vfs + 2);
5407 static int hclge_uninit_umv_space(struct hclge_dev *hdev)
5411 if (hdev->max_umv_size > 0) {
5412 ret = hclge_set_umv_space(hdev, hdev->max_umv_size, NULL,
5416 hdev->max_umv_size = 0;
5418 mutex_destroy(&hdev->umv_mutex);
5423 static int hclge_set_umv_space(struct hclge_dev *hdev, u16 space_size,
5424 u16 *allocated_size, bool is_alloc)
5426 struct hclge_umv_spc_alc_cmd *req;
5427 struct hclge_desc desc;
5430 req = (struct hclge_umv_spc_alc_cmd *)desc.data;
5431 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_ALLOCATE, false);
5432 hnae3_set_bit(req->allocate, HCLGE_UMV_SPC_ALC_B, !is_alloc);
5433 req->space_size = cpu_to_le32(space_size);
5435 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5437 dev_err(&hdev->pdev->dev,
5438 "%s umv space failed for cmd_send, ret =%d\n",
5439 is_alloc ? "allocate" : "free", ret);
5443 if (is_alloc && allocated_size)
5444 *allocated_size = le32_to_cpu(desc.data[1]);
5449 static void hclge_reset_umv_space(struct hclge_dev *hdev)
5451 struct hclge_vport *vport;
5454 for (i = 0; i < hdev->num_alloc_vport; i++) {
5455 vport = &hdev->vport[i];
5456 vport->used_umv_num = 0;
5459 mutex_lock(&hdev->umv_mutex);
5460 hdev->share_umv_size = hdev->priv_umv_size +
5461 hdev->max_umv_size % (hdev->num_req_vfs + 2);
5462 mutex_unlock(&hdev->umv_mutex);
5465 static bool hclge_is_umv_space_full(struct hclge_vport *vport)
5467 struct hclge_dev *hdev = vport->back;
5470 mutex_lock(&hdev->umv_mutex);
5471 is_full = (vport->used_umv_num >= hdev->priv_umv_size &&
5472 hdev->share_umv_size == 0);
5473 mutex_unlock(&hdev->umv_mutex);
5478 static void hclge_update_umv_space(struct hclge_vport *vport, bool is_free)
5480 struct hclge_dev *hdev = vport->back;
5482 mutex_lock(&hdev->umv_mutex);
5484 if (vport->used_umv_num > hdev->priv_umv_size)
5485 hdev->share_umv_size++;
5486 vport->used_umv_num--;
5488 if (vport->used_umv_num >= hdev->priv_umv_size)
5489 hdev->share_umv_size--;
5490 vport->used_umv_num++;
5492 mutex_unlock(&hdev->umv_mutex);
5495 static int hclge_add_uc_addr(struct hnae3_handle *handle,
5496 const unsigned char *addr)
5498 struct hclge_vport *vport = hclge_get_vport(handle);
5500 return hclge_add_uc_addr_common(vport, addr);
5503 int hclge_add_uc_addr_common(struct hclge_vport *vport,
5504 const unsigned char *addr)
5506 struct hclge_dev *hdev = vport->back;
5507 struct hclge_mac_vlan_tbl_entry_cmd req;
5508 struct hclge_desc desc;
5509 u16 egress_port = 0;
5512 /* mac addr check */
5513 if (is_zero_ether_addr(addr) ||
5514 is_broadcast_ether_addr(addr) ||
5515 is_multicast_ether_addr(addr)) {
5516 dev_err(&hdev->pdev->dev,
5517 "Set_uc mac err! invalid mac:%pM. is_zero:%d,is_br=%d,is_mul=%d\n",
5519 is_zero_ether_addr(addr),
5520 is_broadcast_ether_addr(addr),
5521 is_multicast_ether_addr(addr));
5525 memset(&req, 0, sizeof(req));
5526 hnae3_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
5528 hnae3_set_field(egress_port, HCLGE_MAC_EPORT_VFID_M,
5529 HCLGE_MAC_EPORT_VFID_S, vport->vport_id);
5531 req.egress_port = cpu_to_le16(egress_port);
5533 hclge_prepare_mac_addr(&req, addr);
5535 /* Lookup the mac address in the mac_vlan table, and add
5536 * it if the entry is inexistent. Repeated unicast entry
5537 * is not allowed in the mac vlan table.
5539 ret = hclge_lookup_mac_vlan_tbl(vport, &req, &desc, false);
5540 if (ret == -ENOENT) {
5541 if (!hclge_is_umv_space_full(vport)) {
5542 ret = hclge_add_mac_vlan_tbl(vport, &req, NULL);
5544 hclge_update_umv_space(vport, false);
5548 dev_err(&hdev->pdev->dev, "UC MAC table full(%u)\n",
5549 hdev->priv_umv_size);
5554 /* check if we just hit the duplicate */
5558 dev_err(&hdev->pdev->dev,
5559 "PF failed to add unicast entry(%pM) in the MAC table\n",
5565 static int hclge_rm_uc_addr(struct hnae3_handle *handle,
5566 const unsigned char *addr)
5568 struct hclge_vport *vport = hclge_get_vport(handle);
5570 return hclge_rm_uc_addr_common(vport, addr);
5573 int hclge_rm_uc_addr_common(struct hclge_vport *vport,
5574 const unsigned char *addr)
5576 struct hclge_dev *hdev = vport->back;
5577 struct hclge_mac_vlan_tbl_entry_cmd req;
5580 /* mac addr check */
5581 if (is_zero_ether_addr(addr) ||
5582 is_broadcast_ether_addr(addr) ||
5583 is_multicast_ether_addr(addr)) {
5584 dev_dbg(&hdev->pdev->dev,
5585 "Remove mac err! invalid mac:%pM.\n",
5590 memset(&req, 0, sizeof(req));
5591 hnae3_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
5592 hnae3_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT0_EN_B, 0);
5593 hclge_prepare_mac_addr(&req, addr);
5594 ret = hclge_remove_mac_vlan_tbl(vport, &req);
5596 hclge_update_umv_space(vport, true);
5601 static int hclge_add_mc_addr(struct hnae3_handle *handle,
5602 const unsigned char *addr)
5604 struct hclge_vport *vport = hclge_get_vport(handle);
5606 return hclge_add_mc_addr_common(vport, addr);
5609 int hclge_add_mc_addr_common(struct hclge_vport *vport,
5610 const unsigned char *addr)
5612 struct hclge_dev *hdev = vport->back;
5613 struct hclge_mac_vlan_tbl_entry_cmd req;
5614 struct hclge_desc desc[3];
5617 /* mac addr check */
5618 if (!is_multicast_ether_addr(addr)) {
5619 dev_err(&hdev->pdev->dev,
5620 "Add mc mac err! invalid mac:%pM.\n",
5624 memset(&req, 0, sizeof(req));
5625 hnae3_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
5626 hnae3_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT0_EN_B, 0);
5627 hnae3_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT1_EN_B, 1);
5628 hnae3_set_bit(req.mc_mac_en, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
5629 hclge_prepare_mac_addr(&req, addr);
5630 status = hclge_lookup_mac_vlan_tbl(vport, &req, desc, true);
5632 /* This mac addr exist, update VFID for it */
5633 hclge_update_desc_vfid(desc, vport->vport_id, false);
5634 status = hclge_add_mac_vlan_tbl(vport, &req, desc);
5636 /* This mac addr do not exist, add new entry for it */
5637 memset(desc[0].data, 0, sizeof(desc[0].data));
5638 memset(desc[1].data, 0, sizeof(desc[0].data));
5639 memset(desc[2].data, 0, sizeof(desc[0].data));
5640 hclge_update_desc_vfid(desc, vport->vport_id, false);
5641 status = hclge_add_mac_vlan_tbl(vport, &req, desc);
5644 if (status == -ENOSPC)
5645 dev_err(&hdev->pdev->dev, "mc mac vlan table is full\n");
5650 static int hclge_rm_mc_addr(struct hnae3_handle *handle,
5651 const unsigned char *addr)
5653 struct hclge_vport *vport = hclge_get_vport(handle);
5655 return hclge_rm_mc_addr_common(vport, addr);
5658 int hclge_rm_mc_addr_common(struct hclge_vport *vport,
5659 const unsigned char *addr)
5661 struct hclge_dev *hdev = vport->back;
5662 struct hclge_mac_vlan_tbl_entry_cmd req;
5663 enum hclge_cmd_status status;
5664 struct hclge_desc desc[3];
5666 /* mac addr check */
5667 if (!is_multicast_ether_addr(addr)) {
5668 dev_dbg(&hdev->pdev->dev,
5669 "Remove mc mac err! invalid mac:%pM.\n",
5674 memset(&req, 0, sizeof(req));
5675 hnae3_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
5676 hnae3_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT0_EN_B, 0);
5677 hnae3_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT1_EN_B, 1);
5678 hnae3_set_bit(req.mc_mac_en, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
5679 hclge_prepare_mac_addr(&req, addr);
5680 status = hclge_lookup_mac_vlan_tbl(vport, &req, desc, true);
5682 /* This mac addr exist, remove this handle's VFID for it */
5683 hclge_update_desc_vfid(desc, vport->vport_id, true);
5685 if (hclge_is_all_function_id_zero(desc))
5686 /* All the vfid is zero, so need to delete this entry */
5687 status = hclge_remove_mac_vlan_tbl(vport, &req);
5689 /* Not all the vfid is zero, update the vfid */
5690 status = hclge_add_mac_vlan_tbl(vport, &req, desc);
5693 /* Maybe this mac address is in mta table, but it cannot be
5694 * deleted here because an entry of mta represents an address
5695 * range rather than a specific address. the delete action to
5696 * all entries will take effect in update_mta_status called by
5697 * hns3_nic_set_rx_mode.
5705 static int hclge_get_mac_ethertype_cmd_status(struct hclge_dev *hdev,
5706 u16 cmdq_resp, u8 resp_code)
5708 #define HCLGE_ETHERTYPE_SUCCESS_ADD 0
5709 #define HCLGE_ETHERTYPE_ALREADY_ADD 1
5710 #define HCLGE_ETHERTYPE_MGR_TBL_OVERFLOW 2
5711 #define HCLGE_ETHERTYPE_KEY_CONFLICT 3
5716 dev_err(&hdev->pdev->dev,
5717 "cmdq execute failed for get_mac_ethertype_cmd_status, status=%d.\n",
5722 switch (resp_code) {
5723 case HCLGE_ETHERTYPE_SUCCESS_ADD:
5724 case HCLGE_ETHERTYPE_ALREADY_ADD:
5727 case HCLGE_ETHERTYPE_MGR_TBL_OVERFLOW:
5728 dev_err(&hdev->pdev->dev,
5729 "add mac ethertype failed for manager table overflow.\n");
5730 return_status = -EIO;
5732 case HCLGE_ETHERTYPE_KEY_CONFLICT:
5733 dev_err(&hdev->pdev->dev,
5734 "add mac ethertype failed for key conflict.\n");
5735 return_status = -EIO;
5738 dev_err(&hdev->pdev->dev,
5739 "add mac ethertype failed for undefined, code=%d.\n",
5741 return_status = -EIO;
5744 return return_status;
5747 static int hclge_add_mgr_tbl(struct hclge_dev *hdev,
5748 const struct hclge_mac_mgr_tbl_entry_cmd *req)
5750 struct hclge_desc desc;
5755 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_ETHTYPE_ADD, false);
5756 memcpy(desc.data, req, sizeof(struct hclge_mac_mgr_tbl_entry_cmd));
5758 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5760 dev_err(&hdev->pdev->dev,
5761 "add mac ethertype failed for cmd_send, ret =%d.\n",
5766 resp_code = (le32_to_cpu(desc.data[0]) >> 8) & 0xff;
5767 retval = le16_to_cpu(desc.retval);
5769 return hclge_get_mac_ethertype_cmd_status(hdev, retval, resp_code);
5772 static int init_mgr_tbl(struct hclge_dev *hdev)
5777 for (i = 0; i < ARRAY_SIZE(hclge_mgr_table); i++) {
5778 ret = hclge_add_mgr_tbl(hdev, &hclge_mgr_table[i]);
5780 dev_err(&hdev->pdev->dev,
5781 "add mac ethertype failed, ret =%d.\n",
5790 static void hclge_get_mac_addr(struct hnae3_handle *handle, u8 *p)
5792 struct hclge_vport *vport = hclge_get_vport(handle);
5793 struct hclge_dev *hdev = vport->back;
5795 ether_addr_copy(p, hdev->hw.mac.mac_addr);
5798 static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
5801 const unsigned char *new_addr = (const unsigned char *)p;
5802 struct hclge_vport *vport = hclge_get_vport(handle);
5803 struct hclge_dev *hdev = vport->back;
5806 /* mac addr check */
5807 if (is_zero_ether_addr(new_addr) ||
5808 is_broadcast_ether_addr(new_addr) ||
5809 is_multicast_ether_addr(new_addr)) {
5810 dev_err(&hdev->pdev->dev,
5811 "Change uc mac err! invalid mac:%p.\n",
5816 if (!is_first && hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr))
5817 dev_warn(&hdev->pdev->dev,
5818 "remove old uc mac address fail.\n");
5820 ret = hclge_add_uc_addr(handle, new_addr);
5822 dev_err(&hdev->pdev->dev,
5823 "add uc mac address fail, ret =%d.\n",
5827 hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr))
5828 dev_err(&hdev->pdev->dev,
5829 "restore uc mac address fail.\n");
5834 ret = hclge_pause_addr_cfg(hdev, new_addr);
5836 dev_err(&hdev->pdev->dev,
5837 "configure mac pause address fail, ret =%d.\n",
5842 ether_addr_copy(hdev->hw.mac.mac_addr, new_addr);
5847 static int hclge_do_ioctl(struct hnae3_handle *handle, struct ifreq *ifr,
5850 struct hclge_vport *vport = hclge_get_vport(handle);
5851 struct hclge_dev *hdev = vport->back;
5853 if (!hdev->hw.mac.phydev)
5856 return phy_mii_ioctl(hdev->hw.mac.phydev, ifr, cmd);
5859 static int hclge_set_vlan_filter_ctrl(struct hclge_dev *hdev, u8 vlan_type,
5860 u8 fe_type, bool filter_en)
5862 struct hclge_vlan_filter_ctrl_cmd *req;
5863 struct hclge_desc desc;
5866 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_FILTER_CTRL, false);
5868 req = (struct hclge_vlan_filter_ctrl_cmd *)desc.data;
5869 req->vlan_type = vlan_type;
5870 req->vlan_fe = filter_en ? fe_type : 0;
5872 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
5874 dev_err(&hdev->pdev->dev, "set vlan filter fail, ret =%d.\n",
5880 #define HCLGE_FILTER_TYPE_VF 0
5881 #define HCLGE_FILTER_TYPE_PORT 1
5882 #define HCLGE_FILTER_FE_EGRESS_V1_B BIT(0)
5883 #define HCLGE_FILTER_FE_NIC_INGRESS_B BIT(0)
5884 #define HCLGE_FILTER_FE_NIC_EGRESS_B BIT(1)
5885 #define HCLGE_FILTER_FE_ROCE_INGRESS_B BIT(2)
5886 #define HCLGE_FILTER_FE_ROCE_EGRESS_B BIT(3)
5887 #define HCLGE_FILTER_FE_EGRESS (HCLGE_FILTER_FE_NIC_EGRESS_B \
5888 | HCLGE_FILTER_FE_ROCE_EGRESS_B)
5889 #define HCLGE_FILTER_FE_INGRESS (HCLGE_FILTER_FE_NIC_INGRESS_B \
5890 | HCLGE_FILTER_FE_ROCE_INGRESS_B)
5892 static void hclge_enable_vlan_filter(struct hnae3_handle *handle, bool enable)
5894 struct hclge_vport *vport = hclge_get_vport(handle);
5895 struct hclge_dev *hdev = vport->back;
5897 if (hdev->pdev->revision >= 0x21) {
5898 hclge_set_vlan_filter_ctrl(hdev, HCLGE_FILTER_TYPE_VF,
5899 HCLGE_FILTER_FE_EGRESS, enable);
5900 hclge_set_vlan_filter_ctrl(hdev, HCLGE_FILTER_TYPE_PORT,
5901 HCLGE_FILTER_FE_INGRESS, enable);
5903 hclge_set_vlan_filter_ctrl(hdev, HCLGE_FILTER_TYPE_VF,
5904 HCLGE_FILTER_FE_EGRESS_V1_B, enable);
5907 handle->netdev_flags |= HNAE3_VLAN_FLTR;
5909 handle->netdev_flags &= ~HNAE3_VLAN_FLTR;
5912 static int hclge_set_vf_vlan_common(struct hclge_dev *hdev, int vfid,
5913 bool is_kill, u16 vlan, u8 qos,
5916 #define HCLGE_MAX_VF_BYTES 16
5917 struct hclge_vlan_filter_vf_cfg_cmd *req0;
5918 struct hclge_vlan_filter_vf_cfg_cmd *req1;
5919 struct hclge_desc desc[2];
5924 hclge_cmd_setup_basic_desc(&desc[0],
5925 HCLGE_OPC_VLAN_FILTER_VF_CFG, false);
5926 hclge_cmd_setup_basic_desc(&desc[1],
5927 HCLGE_OPC_VLAN_FILTER_VF_CFG, false);
5929 desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
5931 vf_byte_off = vfid / 8;
5932 vf_byte_val = 1 << (vfid % 8);
5934 req0 = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[0].data;
5935 req1 = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[1].data;
5937 req0->vlan_id = cpu_to_le16(vlan);
5938 req0->vlan_cfg = is_kill;
5940 if (vf_byte_off < HCLGE_MAX_VF_BYTES)
5941 req0->vf_bitmap[vf_byte_off] = vf_byte_val;
5943 req1->vf_bitmap[vf_byte_off - HCLGE_MAX_VF_BYTES] = vf_byte_val;
5945 ret = hclge_cmd_send(&hdev->hw, desc, 2);
5947 dev_err(&hdev->pdev->dev,
5948 "Send vf vlan command fail, ret =%d.\n",
5954 #define HCLGE_VF_VLAN_NO_ENTRY 2
5955 if (!req0->resp_code || req0->resp_code == 1)
5958 if (req0->resp_code == HCLGE_VF_VLAN_NO_ENTRY) {
5959 dev_warn(&hdev->pdev->dev,
5960 "vf vlan table is full, vf vlan filter is disabled\n");
5964 dev_err(&hdev->pdev->dev,
5965 "Add vf vlan filter fail, ret =%d.\n",
5968 #define HCLGE_VF_VLAN_DEL_NO_FOUND 1
5969 if (!req0->resp_code)
5972 if (req0->resp_code == HCLGE_VF_VLAN_DEL_NO_FOUND) {
5973 dev_warn(&hdev->pdev->dev,
5974 "vlan %d filter is not in vf vlan table\n",
5979 dev_err(&hdev->pdev->dev,
5980 "Kill vf vlan filter fail, ret =%d.\n",
5987 static int hclge_set_port_vlan_filter(struct hclge_dev *hdev, __be16 proto,
5988 u16 vlan_id, bool is_kill)
5990 struct hclge_vlan_filter_pf_cfg_cmd *req;
5991 struct hclge_desc desc;
5992 u8 vlan_offset_byte_val;
5993 u8 vlan_offset_byte;
5997 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_FILTER_PF_CFG, false);
5999 vlan_offset_160 = vlan_id / 160;
6000 vlan_offset_byte = (vlan_id % 160) / 8;
6001 vlan_offset_byte_val = 1 << (vlan_id % 8);
6003 req = (struct hclge_vlan_filter_pf_cfg_cmd *)desc.data;
6004 req->vlan_offset = vlan_offset_160;
6005 req->vlan_cfg = is_kill;
6006 req->vlan_offset_bitmap[vlan_offset_byte] = vlan_offset_byte_val;
6008 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
6010 dev_err(&hdev->pdev->dev,
6011 "port vlan command, send fail, ret =%d.\n", ret);
6015 static int hclge_set_vlan_filter_hw(struct hclge_dev *hdev, __be16 proto,
6016 u16 vport_id, u16 vlan_id, u8 qos,
6019 u16 vport_idx, vport_num = 0;
6022 if (is_kill && !vlan_id)
6025 ret = hclge_set_vf_vlan_common(hdev, vport_id, is_kill, vlan_id,
6028 dev_err(&hdev->pdev->dev,
6029 "Set %d vport vlan filter config fail, ret =%d.\n",
6034 /* vlan 0 may be added twice when 8021q module is enabled */
6035 if (!is_kill && !vlan_id &&
6036 test_bit(vport_id, hdev->vlan_table[vlan_id]))
6039 if (!is_kill && test_and_set_bit(vport_id, hdev->vlan_table[vlan_id])) {
6040 dev_err(&hdev->pdev->dev,
6041 "Add port vlan failed, vport %d is already in vlan %d\n",
6047 !test_and_clear_bit(vport_id, hdev->vlan_table[vlan_id])) {
6048 dev_err(&hdev->pdev->dev,
6049 "Delete port vlan failed, vport %d is not in vlan %d\n",
6054 for_each_set_bit(vport_idx, hdev->vlan_table[vlan_id], HCLGE_VPORT_NUM)
6057 if ((is_kill && vport_num == 0) || (!is_kill && vport_num == 1))
6058 ret = hclge_set_port_vlan_filter(hdev, proto, vlan_id,
6064 int hclge_set_vlan_filter(struct hnae3_handle *handle, __be16 proto,
6065 u16 vlan_id, bool is_kill)
6067 struct hclge_vport *vport = hclge_get_vport(handle);
6068 struct hclge_dev *hdev = vport->back;
6070 return hclge_set_vlan_filter_hw(hdev, proto, vport->vport_id, vlan_id,
6074 static int hclge_set_vf_vlan_filter(struct hnae3_handle *handle, int vfid,
6075 u16 vlan, u8 qos, __be16 proto)
6077 struct hclge_vport *vport = hclge_get_vport(handle);
6078 struct hclge_dev *hdev = vport->back;
6080 if ((vfid >= hdev->num_alloc_vfs) || (vlan > 4095) || (qos > 7))
6082 if (proto != htons(ETH_P_8021Q))
6083 return -EPROTONOSUPPORT;
6085 return hclge_set_vlan_filter_hw(hdev, proto, vfid, vlan, qos, false);
6088 static int hclge_set_vlan_tx_offload_cfg(struct hclge_vport *vport)
6090 struct hclge_tx_vtag_cfg *vcfg = &vport->txvlan_cfg;
6091 struct hclge_vport_vtag_tx_cfg_cmd *req;
6092 struct hclge_dev *hdev = vport->back;
6093 struct hclge_desc desc;
6096 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_TX_CFG, false);
6098 req = (struct hclge_vport_vtag_tx_cfg_cmd *)desc.data;
6099 req->def_vlan_tag1 = cpu_to_le16(vcfg->default_tag1);
6100 req->def_vlan_tag2 = cpu_to_le16(vcfg->default_tag2);
6101 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG1_B,
6102 vcfg->accept_tag1 ? 1 : 0);
6103 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG1_B,
6104 vcfg->accept_untag1 ? 1 : 0);
6105 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG2_B,
6106 vcfg->accept_tag2 ? 1 : 0);
6107 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG2_B,
6108 vcfg->accept_untag2 ? 1 : 0);
6109 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG1_EN_B,
6110 vcfg->insert_tag1_en ? 1 : 0);
6111 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG2_EN_B,
6112 vcfg->insert_tag2_en ? 1 : 0);
6113 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_CFG_NIC_ROCE_SEL_B, 0);
6115 req->vf_offset = vport->vport_id / HCLGE_VF_NUM_PER_CMD;
6116 req->vf_bitmap[req->vf_offset] =
6117 1 << (vport->vport_id % HCLGE_VF_NUM_PER_BYTE);
6119 status = hclge_cmd_send(&hdev->hw, &desc, 1);
6121 dev_err(&hdev->pdev->dev,
6122 "Send port txvlan cfg command fail, ret =%d\n",
6128 static int hclge_set_vlan_rx_offload_cfg(struct hclge_vport *vport)
6130 struct hclge_rx_vtag_cfg *vcfg = &vport->rxvlan_cfg;
6131 struct hclge_vport_vtag_rx_cfg_cmd *req;
6132 struct hclge_dev *hdev = vport->back;
6133 struct hclge_desc desc;
6136 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_RX_CFG, false);
6138 req = (struct hclge_vport_vtag_rx_cfg_cmd *)desc.data;
6139 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_REM_TAG1_EN_B,
6140 vcfg->strip_tag1_en ? 1 : 0);
6141 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_REM_TAG2_EN_B,
6142 vcfg->strip_tag2_en ? 1 : 0);
6143 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_SHOW_TAG1_EN_B,
6144 vcfg->vlan1_vlan_prionly ? 1 : 0);
6145 hnae3_set_bit(req->vport_vlan_cfg, HCLGE_SHOW_TAG2_EN_B,
6146 vcfg->vlan2_vlan_prionly ? 1 : 0);
6148 req->vf_offset = vport->vport_id / HCLGE_VF_NUM_PER_CMD;
6149 req->vf_bitmap[req->vf_offset] =
6150 1 << (vport->vport_id % HCLGE_VF_NUM_PER_BYTE);
6152 status = hclge_cmd_send(&hdev->hw, &desc, 1);
6154 dev_err(&hdev->pdev->dev,
6155 "Send port rxvlan cfg command fail, ret =%d\n",
6161 static int hclge_set_vlan_protocol_type(struct hclge_dev *hdev)
6163 struct hclge_rx_vlan_type_cfg_cmd *rx_req;
6164 struct hclge_tx_vlan_type_cfg_cmd *tx_req;
6165 struct hclge_desc desc;
6168 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_TYPE_ID, false);
6169 rx_req = (struct hclge_rx_vlan_type_cfg_cmd *)desc.data;
6170 rx_req->ot_fst_vlan_type =
6171 cpu_to_le16(hdev->vlan_type_cfg.rx_ot_fst_vlan_type);
6172 rx_req->ot_sec_vlan_type =
6173 cpu_to_le16(hdev->vlan_type_cfg.rx_ot_sec_vlan_type);
6174 rx_req->in_fst_vlan_type =
6175 cpu_to_le16(hdev->vlan_type_cfg.rx_in_fst_vlan_type);
6176 rx_req->in_sec_vlan_type =
6177 cpu_to_le16(hdev->vlan_type_cfg.rx_in_sec_vlan_type);
6179 status = hclge_cmd_send(&hdev->hw, &desc, 1);
6181 dev_err(&hdev->pdev->dev,
6182 "Send rxvlan protocol type command fail, ret =%d\n",
6187 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_INSERT, false);
6189 tx_req = (struct hclge_tx_vlan_type_cfg_cmd *)desc.data;
6190 tx_req->ot_vlan_type = cpu_to_le16(hdev->vlan_type_cfg.tx_ot_vlan_type);
6191 tx_req->in_vlan_type = cpu_to_le16(hdev->vlan_type_cfg.tx_in_vlan_type);
6193 status = hclge_cmd_send(&hdev->hw, &desc, 1);
6195 dev_err(&hdev->pdev->dev,
6196 "Send txvlan protocol type command fail, ret =%d\n",
6202 static int hclge_init_vlan_config(struct hclge_dev *hdev)
6204 #define HCLGE_DEF_VLAN_TYPE 0x8100
6206 struct hnae3_handle *handle = &hdev->vport[0].nic;
6207 struct hclge_vport *vport;
6211 if (hdev->pdev->revision >= 0x21) {
6212 ret = hclge_set_vlan_filter_ctrl(hdev, HCLGE_FILTER_TYPE_VF,
6213 HCLGE_FILTER_FE_EGRESS, true);
6217 ret = hclge_set_vlan_filter_ctrl(hdev, HCLGE_FILTER_TYPE_PORT,
6218 HCLGE_FILTER_FE_INGRESS, true);
6222 ret = hclge_set_vlan_filter_ctrl(hdev, HCLGE_FILTER_TYPE_VF,
6223 HCLGE_FILTER_FE_EGRESS_V1_B,
6229 handle->netdev_flags |= HNAE3_VLAN_FLTR;
6231 hdev->vlan_type_cfg.rx_in_fst_vlan_type = HCLGE_DEF_VLAN_TYPE;
6232 hdev->vlan_type_cfg.rx_in_sec_vlan_type = HCLGE_DEF_VLAN_TYPE;
6233 hdev->vlan_type_cfg.rx_ot_fst_vlan_type = HCLGE_DEF_VLAN_TYPE;
6234 hdev->vlan_type_cfg.rx_ot_sec_vlan_type = HCLGE_DEF_VLAN_TYPE;
6235 hdev->vlan_type_cfg.tx_ot_vlan_type = HCLGE_DEF_VLAN_TYPE;
6236 hdev->vlan_type_cfg.tx_in_vlan_type = HCLGE_DEF_VLAN_TYPE;
6238 ret = hclge_set_vlan_protocol_type(hdev);
6242 for (i = 0; i < hdev->num_alloc_vport; i++) {
6243 vport = &hdev->vport[i];
6244 vport->txvlan_cfg.accept_tag1 = true;
6245 vport->txvlan_cfg.accept_untag1 = true;
6247 /* accept_tag2 and accept_untag2 are not supported on
6248 * pdev revision(0x20), new revision support them. The
6249 * value of this two fields will not return error when driver
6250 * send command to fireware in revision(0x20).
6251 * This two fields can not configured by user.
6253 vport->txvlan_cfg.accept_tag2 = true;
6254 vport->txvlan_cfg.accept_untag2 = true;
6256 vport->txvlan_cfg.insert_tag1_en = false;
6257 vport->txvlan_cfg.insert_tag2_en = false;
6258 vport->txvlan_cfg.default_tag1 = 0;
6259 vport->txvlan_cfg.default_tag2 = 0;
6261 ret = hclge_set_vlan_tx_offload_cfg(vport);
6265 vport->rxvlan_cfg.strip_tag1_en = false;
6266 vport->rxvlan_cfg.strip_tag2_en = true;
6267 vport->rxvlan_cfg.vlan1_vlan_prionly = false;
6268 vport->rxvlan_cfg.vlan2_vlan_prionly = false;
6270 ret = hclge_set_vlan_rx_offload_cfg(vport);
6275 return hclge_set_vlan_filter(handle, htons(ETH_P_8021Q), 0, false);
6278 int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
6280 struct hclge_vport *vport = hclge_get_vport(handle);
6282 vport->rxvlan_cfg.strip_tag1_en = false;
6283 vport->rxvlan_cfg.strip_tag2_en = enable;
6284 vport->rxvlan_cfg.vlan1_vlan_prionly = false;
6285 vport->rxvlan_cfg.vlan2_vlan_prionly = false;
6287 return hclge_set_vlan_rx_offload_cfg(vport);
6290 static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mtu)
6292 struct hclge_config_max_frm_size_cmd *req;
6293 struct hclge_desc desc;
6297 max_frm_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
6299 if (max_frm_size < HCLGE_MAC_MIN_FRAME ||
6300 max_frm_size > HCLGE_MAC_MAX_FRAME)
6303 max_frm_size = max(max_frm_size, HCLGE_MAC_DEFAULT_FRAME);
6305 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAX_FRM_SIZE, false);
6307 req = (struct hclge_config_max_frm_size_cmd *)desc.data;
6308 req->max_frm_size = cpu_to_le16(max_frm_size);
6309 req->min_frm_size = HCLGE_MAC_MIN_FRAME;
6311 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
6313 dev_err(&hdev->pdev->dev, "set mtu fail, ret =%d.\n", ret);
6315 hdev->mps = max_frm_size;
6320 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
6322 struct hclge_vport *vport = hclge_get_vport(handle);
6323 struct hclge_dev *hdev = vport->back;
6326 ret = hclge_set_mac_mtu(hdev, new_mtu);
6328 dev_err(&hdev->pdev->dev,
6329 "Change mtu fail, ret =%d\n", ret);
6333 ret = hclge_buffer_alloc(hdev);
6335 dev_err(&hdev->pdev->dev,
6336 "Allocate buffer fail, ret =%d\n", ret);
6341 static int hclge_send_reset_tqp_cmd(struct hclge_dev *hdev, u16 queue_id,
6344 struct hclge_reset_tqp_queue_cmd *req;
6345 struct hclge_desc desc;
6348 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RESET_TQP_QUEUE, false);
6350 req = (struct hclge_reset_tqp_queue_cmd *)desc.data;
6351 req->tqp_id = cpu_to_le16(queue_id & HCLGE_RING_ID_MASK);
6352 hnae3_set_bit(req->reset_req, HCLGE_TQP_RESET_B, enable);
6354 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
6356 dev_err(&hdev->pdev->dev,
6357 "Send tqp reset cmd error, status =%d\n", ret);
6364 static int hclge_get_reset_status(struct hclge_dev *hdev, u16 queue_id)
6366 struct hclge_reset_tqp_queue_cmd *req;
6367 struct hclge_desc desc;
6370 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RESET_TQP_QUEUE, true);
6372 req = (struct hclge_reset_tqp_queue_cmd *)desc.data;
6373 req->tqp_id = cpu_to_le16(queue_id & HCLGE_RING_ID_MASK);
6375 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
6377 dev_err(&hdev->pdev->dev,
6378 "Get reset status error, status =%d\n", ret);
6382 return hnae3_get_bit(req->ready_to_reset, HCLGE_TQP_RESET_B);
6385 static u16 hclge_covert_handle_qid_global(struct hnae3_handle *handle,
6388 struct hnae3_queue *queue;
6389 struct hclge_tqp *tqp;
6391 queue = handle->kinfo.tqp[queue_id];
6392 tqp = container_of(queue, struct hclge_tqp, q);
6397 int hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id)
6399 struct hclge_vport *vport = hclge_get_vport(handle);
6400 struct hclge_dev *hdev = vport->back;
6401 int reset_try_times = 0;
6406 queue_gid = hclge_covert_handle_qid_global(handle, queue_id);
6408 ret = hclge_tqp_enable(hdev, queue_id, 0, false);
6410 dev_err(&hdev->pdev->dev, "Disable tqp fail, ret = %d\n", ret);
6414 ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, true);
6416 dev_err(&hdev->pdev->dev,
6417 "Send reset tqp cmd fail, ret = %d\n", ret);
6421 reset_try_times = 0;
6422 while (reset_try_times++ < HCLGE_TQP_RESET_TRY_TIMES) {
6423 /* Wait for tqp hw reset */
6425 reset_status = hclge_get_reset_status(hdev, queue_gid);
6430 if (reset_try_times >= HCLGE_TQP_RESET_TRY_TIMES) {
6431 dev_err(&hdev->pdev->dev, "Reset TQP fail\n");
6435 ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, false);
6437 dev_err(&hdev->pdev->dev,
6438 "Deassert the soft reset fail, ret = %d\n", ret);
6443 void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id)
6445 struct hclge_dev *hdev = vport->back;
6446 int reset_try_times = 0;
6451 queue_gid = hclge_covert_handle_qid_global(&vport->nic, queue_id);
6453 ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, true);
6455 dev_warn(&hdev->pdev->dev,
6456 "Send reset tqp cmd fail, ret = %d\n", ret);
6460 reset_try_times = 0;
6461 while (reset_try_times++ < HCLGE_TQP_RESET_TRY_TIMES) {
6462 /* Wait for tqp hw reset */
6464 reset_status = hclge_get_reset_status(hdev, queue_gid);
6469 if (reset_try_times >= HCLGE_TQP_RESET_TRY_TIMES) {
6470 dev_warn(&hdev->pdev->dev, "Reset TQP fail\n");
6474 ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, false);
6476 dev_warn(&hdev->pdev->dev,
6477 "Deassert the soft reset fail, ret = %d\n", ret);
6480 static u32 hclge_get_fw_version(struct hnae3_handle *handle)
6482 struct hclge_vport *vport = hclge_get_vport(handle);
6483 struct hclge_dev *hdev = vport->back;
6485 return hdev->fw_version;
6488 static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 tx_en)
6490 struct phy_device *phydev = hdev->hw.mac.phydev;
6495 phy_set_asym_pause(phydev, rx_en, tx_en);
6498 static int hclge_cfg_pauseparam(struct hclge_dev *hdev, u32 rx_en, u32 tx_en)
6503 hdev->fc_mode_last_time = HCLGE_FC_FULL;
6504 else if (rx_en && !tx_en)
6505 hdev->fc_mode_last_time = HCLGE_FC_RX_PAUSE;
6506 else if (!rx_en && tx_en)
6507 hdev->fc_mode_last_time = HCLGE_FC_TX_PAUSE;
6509 hdev->fc_mode_last_time = HCLGE_FC_NONE;
6511 if (hdev->tm_info.fc_mode == HCLGE_FC_PFC)
6514 ret = hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
6516 dev_err(&hdev->pdev->dev, "configure pauseparam error, ret = %d.\n",
6521 hdev->tm_info.fc_mode = hdev->fc_mode_last_time;
6526 int hclge_cfg_flowctrl(struct hclge_dev *hdev)
6528 struct phy_device *phydev = hdev->hw.mac.phydev;
6529 u16 remote_advertising = 0;
6530 u16 local_advertising = 0;
6531 u32 rx_pause, tx_pause;
6534 if (!phydev->link || !phydev->autoneg)
6537 local_advertising = ethtool_adv_to_lcl_adv_t(phydev->advertising);
6540 remote_advertising = LPA_PAUSE_CAP;
6542 if (phydev->asym_pause)
6543 remote_advertising |= LPA_PAUSE_ASYM;
6545 flowctl = mii_resolve_flowctrl_fdx(local_advertising,
6546 remote_advertising);
6547 tx_pause = flowctl & FLOW_CTRL_TX;
6548 rx_pause = flowctl & FLOW_CTRL_RX;
6550 if (phydev->duplex == HCLGE_MAC_HALF) {
6555 return hclge_cfg_pauseparam(hdev, rx_pause, tx_pause);
6558 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
6559 u32 *rx_en, u32 *tx_en)
6561 struct hclge_vport *vport = hclge_get_vport(handle);
6562 struct hclge_dev *hdev = vport->back;
6564 *auto_neg = hclge_get_autoneg(handle);
6566 if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
6572 if (hdev->tm_info.fc_mode == HCLGE_FC_RX_PAUSE) {
6575 } else if (hdev->tm_info.fc_mode == HCLGE_FC_TX_PAUSE) {
6578 } else if (hdev->tm_info.fc_mode == HCLGE_FC_FULL) {
6587 static int hclge_set_pauseparam(struct hnae3_handle *handle, u32 auto_neg,
6588 u32 rx_en, u32 tx_en)
6590 struct hclge_vport *vport = hclge_get_vport(handle);
6591 struct hclge_dev *hdev = vport->back;
6592 struct phy_device *phydev = hdev->hw.mac.phydev;
6595 fc_autoneg = hclge_get_autoneg(handle);
6596 if (auto_neg != fc_autoneg) {
6597 dev_info(&hdev->pdev->dev,
6598 "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
6602 if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
6603 dev_info(&hdev->pdev->dev,
6604 "Priority flow control enabled. Cannot set link flow control.\n");
6608 hclge_set_flowctrl_adv(hdev, rx_en, tx_en);
6611 return hclge_cfg_pauseparam(hdev, rx_en, tx_en);
6613 /* Only support flow control negotiation for netdev with
6614 * phy attached for now.
6619 return phy_start_aneg(phydev);
6622 static void hclge_get_ksettings_an_result(struct hnae3_handle *handle,
6623 u8 *auto_neg, u32 *speed, u8 *duplex)
6625 struct hclge_vport *vport = hclge_get_vport(handle);
6626 struct hclge_dev *hdev = vport->back;
6629 *speed = hdev->hw.mac.speed;
6631 *duplex = hdev->hw.mac.duplex;
6633 *auto_neg = hdev->hw.mac.autoneg;
6636 static void hclge_get_media_type(struct hnae3_handle *handle, u8 *media_type)
6638 struct hclge_vport *vport = hclge_get_vport(handle);
6639 struct hclge_dev *hdev = vport->back;
6642 *media_type = hdev->hw.mac.media_type;
6645 static void hclge_get_mdix_mode(struct hnae3_handle *handle,
6646 u8 *tp_mdix_ctrl, u8 *tp_mdix)
6648 struct hclge_vport *vport = hclge_get_vport(handle);
6649 struct hclge_dev *hdev = vport->back;
6650 struct phy_device *phydev = hdev->hw.mac.phydev;
6651 int mdix_ctrl, mdix, retval, is_resolved;
6654 *tp_mdix_ctrl = ETH_TP_MDI_INVALID;
6655 *tp_mdix = ETH_TP_MDI_INVALID;
6659 phy_write(phydev, HCLGE_PHY_PAGE_REG, HCLGE_PHY_PAGE_MDIX);
6661 retval = phy_read(phydev, HCLGE_PHY_CSC_REG);
6662 mdix_ctrl = hnae3_get_field(retval, HCLGE_PHY_MDIX_CTRL_M,
6663 HCLGE_PHY_MDIX_CTRL_S);
6665 retval = phy_read(phydev, HCLGE_PHY_CSS_REG);
6666 mdix = hnae3_get_bit(retval, HCLGE_PHY_MDIX_STATUS_B);
6667 is_resolved = hnae3_get_bit(retval, HCLGE_PHY_SPEED_DUP_RESOLVE_B);
6669 phy_write(phydev, HCLGE_PHY_PAGE_REG, HCLGE_PHY_PAGE_COPPER);
6671 switch (mdix_ctrl) {
6673 *tp_mdix_ctrl = ETH_TP_MDI;
6676 *tp_mdix_ctrl = ETH_TP_MDI_X;
6679 *tp_mdix_ctrl = ETH_TP_MDI_AUTO;
6682 *tp_mdix_ctrl = ETH_TP_MDI_INVALID;
6687 *tp_mdix = ETH_TP_MDI_INVALID;
6689 *tp_mdix = ETH_TP_MDI_X;
6691 *tp_mdix = ETH_TP_MDI;
6694 static int hclge_init_instance_hw(struct hclge_dev *hdev)
6696 return hclge_mac_connect_phy(hdev);
6699 static void hclge_uninit_instance_hw(struct hclge_dev *hdev)
6701 hclge_mac_disconnect_phy(hdev);
6704 static int hclge_init_client_instance(struct hnae3_client *client,
6705 struct hnae3_ae_dev *ae_dev)
6707 struct hclge_dev *hdev = ae_dev->priv;
6708 struct hclge_vport *vport;
6711 for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
6712 vport = &hdev->vport[i];
6714 switch (client->type) {
6715 case HNAE3_CLIENT_KNIC:
6717 hdev->nic_client = client;
6718 vport->nic.client = client;
6719 ret = client->ops->init_instance(&vport->nic);
6723 ret = hclge_init_instance_hw(hdev);
6725 client->ops->uninit_instance(&vport->nic,
6730 hnae3_set_client_init_flag(client, ae_dev, 1);
6732 if (hdev->roce_client &&
6733 hnae3_dev_roce_supported(hdev)) {
6734 struct hnae3_client *rc = hdev->roce_client;
6736 ret = hclge_init_roce_base_info(vport);
6740 ret = rc->ops->init_instance(&vport->roce);
6744 hnae3_set_client_init_flag(hdev->roce_client,
6749 case HNAE3_CLIENT_UNIC:
6750 hdev->nic_client = client;
6751 vport->nic.client = client;
6753 ret = client->ops->init_instance(&vport->nic);
6757 hnae3_set_client_init_flag(client, ae_dev, 1);
6760 case HNAE3_CLIENT_ROCE:
6761 if (hnae3_dev_roce_supported(hdev)) {
6762 hdev->roce_client = client;
6763 vport->roce.client = client;
6766 if (hdev->roce_client && hdev->nic_client) {
6767 ret = hclge_init_roce_base_info(vport);
6771 ret = client->ops->init_instance(&vport->roce);
6775 hnae3_set_client_init_flag(client, ae_dev, 1);
6787 hdev->nic_client = NULL;
6788 vport->nic.client = NULL;
6791 hdev->roce_client = NULL;
6792 vport->roce.client = NULL;
6796 static void hclge_uninit_client_instance(struct hnae3_client *client,
6797 struct hnae3_ae_dev *ae_dev)
6799 struct hclge_dev *hdev = ae_dev->priv;
6800 struct hclge_vport *vport;
6803 for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
6804 vport = &hdev->vport[i];
6805 if (hdev->roce_client) {
6806 hdev->roce_client->ops->uninit_instance(&vport->roce,
6808 hdev->roce_client = NULL;
6809 vport->roce.client = NULL;
6811 if (client->type == HNAE3_CLIENT_ROCE)
6813 if (hdev->nic_client && client->ops->uninit_instance) {
6814 hclge_uninit_instance_hw(hdev);
6815 client->ops->uninit_instance(&vport->nic, 0);
6816 hdev->nic_client = NULL;
6817 vport->nic.client = NULL;
6822 static int hclge_pci_init(struct hclge_dev *hdev)
6824 struct pci_dev *pdev = hdev->pdev;
6825 struct hclge_hw *hw;
6828 ret = pci_enable_device(pdev);
6830 dev_err(&pdev->dev, "failed to enable PCI device\n");
6834 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
6836 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
6839 "can't set consistent PCI DMA");
6840 goto err_disable_device;
6842 dev_warn(&pdev->dev, "set DMA mask to 32 bits\n");
6845 ret = pci_request_regions(pdev, HCLGE_DRIVER_NAME);
6847 dev_err(&pdev->dev, "PCI request regions failed %d\n", ret);
6848 goto err_disable_device;
6851 pci_set_master(pdev);
6853 hw->io_base = pcim_iomap(pdev, 2, 0);
6855 dev_err(&pdev->dev, "Can't map configuration register space\n");
6857 goto err_clr_master;
6860 hdev->num_req_vfs = pci_sriov_get_totalvfs(pdev);
6864 pci_clear_master(pdev);
6865 pci_release_regions(pdev);
6867 pci_disable_device(pdev);
6872 static void hclge_pci_uninit(struct hclge_dev *hdev)
6874 struct pci_dev *pdev = hdev->pdev;
6876 pcim_iounmap(pdev, hdev->hw.io_base);
6877 pci_free_irq_vectors(pdev);
6878 pci_clear_master(pdev);
6879 pci_release_mem_regions(pdev);
6880 pci_disable_device(pdev);
6883 static void hclge_state_init(struct hclge_dev *hdev)
6885 set_bit(HCLGE_STATE_SERVICE_INITED, &hdev->state);
6886 set_bit(HCLGE_STATE_DOWN, &hdev->state);
6887 clear_bit(HCLGE_STATE_RST_SERVICE_SCHED, &hdev->state);
6888 clear_bit(HCLGE_STATE_RST_HANDLING, &hdev->state);
6889 clear_bit(HCLGE_STATE_MBX_SERVICE_SCHED, &hdev->state);
6890 clear_bit(HCLGE_STATE_MBX_HANDLING, &hdev->state);
6893 static void hclge_state_uninit(struct hclge_dev *hdev)
6895 set_bit(HCLGE_STATE_DOWN, &hdev->state);
6897 if (hdev->service_timer.function)
6898 del_timer_sync(&hdev->service_timer);
6899 if (hdev->reset_timer.function)
6900 del_timer_sync(&hdev->reset_timer);
6901 if (hdev->service_task.func)
6902 cancel_work_sync(&hdev->service_task);
6903 if (hdev->rst_service_task.func)
6904 cancel_work_sync(&hdev->rst_service_task);
6905 if (hdev->mbx_service_task.func)
6906 cancel_work_sync(&hdev->mbx_service_task);
6909 static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
6911 struct pci_dev *pdev = ae_dev->pdev;
6912 struct hclge_dev *hdev;
6915 hdev = devm_kzalloc(&pdev->dev, sizeof(*hdev), GFP_KERNEL);
6922 hdev->ae_dev = ae_dev;
6923 hdev->reset_type = HNAE3_NONE_RESET;
6924 hdev->reset_level = HNAE3_FUNC_RESET;
6925 ae_dev->priv = hdev;
6927 ret = hclge_pci_init(hdev);
6929 dev_err(&pdev->dev, "PCI init failed\n");
6933 /* Firmware command queue initialize */
6934 ret = hclge_cmd_queue_init(hdev);
6936 dev_err(&pdev->dev, "Cmd queue init failed, ret = %d.\n", ret);
6937 goto err_pci_uninit;
6940 /* Firmware command initialize */
6941 ret = hclge_cmd_init(hdev);
6943 goto err_cmd_uninit;
6945 ret = hclge_get_cap(hdev);
6947 dev_err(&pdev->dev, "get hw capability error, ret = %d.\n",
6949 goto err_cmd_uninit;
6952 ret = hclge_configure(hdev);
6954 dev_err(&pdev->dev, "Configure dev error, ret = %d.\n", ret);
6955 goto err_cmd_uninit;
6958 ret = hclge_init_msi(hdev);
6960 dev_err(&pdev->dev, "Init MSI/MSI-X error, ret = %d.\n", ret);
6961 goto err_cmd_uninit;
6964 ret = hclge_misc_irq_init(hdev);
6967 "Misc IRQ(vector0) init error, ret = %d.\n",
6969 goto err_msi_uninit;
6972 ret = hclge_alloc_tqps(hdev);
6974 dev_err(&pdev->dev, "Allocate TQPs error, ret = %d.\n", ret);
6975 goto err_msi_irq_uninit;
6978 ret = hclge_alloc_vport(hdev);
6980 dev_err(&pdev->dev, "Allocate vport error, ret = %d.\n", ret);
6981 goto err_msi_irq_uninit;
6984 ret = hclge_map_tqp(hdev);
6986 dev_err(&pdev->dev, "Map tqp error, ret = %d.\n", ret);
6987 goto err_msi_irq_uninit;
6990 if (hdev->hw.mac.media_type == HNAE3_MEDIA_TYPE_COPPER) {
6991 ret = hclge_mac_mdio_config(hdev);
6993 dev_err(&hdev->pdev->dev,
6994 "mdio config fail ret=%d\n", ret);
6995 goto err_msi_irq_uninit;
6999 ret = hclge_init_umv_space(hdev);
7001 dev_err(&pdev->dev, "umv space init error, ret=%d.\n", ret);
7002 goto err_msi_irq_uninit;
7005 ret = hclge_mac_init(hdev);
7007 dev_err(&pdev->dev, "Mac init error, ret = %d\n", ret);
7008 goto err_mdiobus_unreg;
7011 ret = hclge_config_tso(hdev, HCLGE_TSO_MSS_MIN, HCLGE_TSO_MSS_MAX);
7013 dev_err(&pdev->dev, "Enable tso fail, ret =%d\n", ret);
7014 goto err_mdiobus_unreg;
7017 ret = hclge_init_vlan_config(hdev);
7019 dev_err(&pdev->dev, "VLAN init fail, ret =%d\n", ret);
7020 goto err_mdiobus_unreg;
7023 ret = hclge_tm_schd_init(hdev);
7025 dev_err(&pdev->dev, "tm schd init fail, ret =%d\n", ret);
7026 goto err_mdiobus_unreg;
7029 hclge_rss_init_cfg(hdev);
7030 ret = hclge_rss_init_hw(hdev);
7032 dev_err(&pdev->dev, "Rss init fail, ret =%d\n", ret);
7033 goto err_mdiobus_unreg;
7036 ret = init_mgr_tbl(hdev);
7038 dev_err(&pdev->dev, "manager table init fail, ret =%d\n", ret);
7039 goto err_mdiobus_unreg;
7042 ret = hclge_init_fd_config(hdev);
7045 "fd table init fail, ret=%d\n", ret);
7046 goto err_mdiobus_unreg;
7049 ret = hclge_hw_error_set_state(hdev, true);
7052 "hw error interrupts enable failed, ret =%d\n", ret);
7053 goto err_mdiobus_unreg;
7056 hclge_dcb_ops_set(hdev);
7058 timer_setup(&hdev->service_timer, hclge_service_timer, 0);
7059 timer_setup(&hdev->reset_timer, hclge_reset_timer, 0);
7060 INIT_WORK(&hdev->service_task, hclge_service_task);
7061 INIT_WORK(&hdev->rst_service_task, hclge_reset_service_task);
7062 INIT_WORK(&hdev->mbx_service_task, hclge_mailbox_service_task);
7064 hclge_clear_all_event_cause(hdev);
7066 /* Enable MISC vector(vector0) */
7067 hclge_enable_vector(&hdev->misc_vector, true);
7069 hclge_state_init(hdev);
7070 hdev->last_reset_time = jiffies;
7072 pr_info("%s driver initialization finished.\n", HCLGE_DRIVER_NAME);
7076 if (hdev->hw.mac.phydev)
7077 mdiobus_unregister(hdev->hw.mac.mdio_bus);
7079 hclge_misc_irq_uninit(hdev);
7081 pci_free_irq_vectors(pdev);
7083 hclge_destroy_cmd_queue(&hdev->hw);
7085 pcim_iounmap(pdev, hdev->hw.io_base);
7086 pci_clear_master(pdev);
7087 pci_release_regions(pdev);
7088 pci_disable_device(pdev);
7093 static void hclge_stats_clear(struct hclge_dev *hdev)
7095 memset(&hdev->hw_stats, 0, sizeof(hdev->hw_stats));
7098 static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev)
7100 struct hclge_dev *hdev = ae_dev->priv;
7101 struct pci_dev *pdev = ae_dev->pdev;
7104 set_bit(HCLGE_STATE_DOWN, &hdev->state);
7106 hclge_stats_clear(hdev);
7107 memset(hdev->vlan_table, 0, sizeof(hdev->vlan_table));
7109 ret = hclge_cmd_init(hdev);
7111 dev_err(&pdev->dev, "Cmd queue init failed\n");
7115 ret = hclge_get_cap(hdev);
7117 dev_err(&pdev->dev, "get hw capability error, ret = %d.\n",
7122 ret = hclge_configure(hdev);
7124 dev_err(&pdev->dev, "Configure dev error, ret = %d.\n", ret);
7128 ret = hclge_map_tqp(hdev);
7130 dev_err(&pdev->dev, "Map tqp error, ret = %d.\n", ret);
7134 hclge_reset_umv_space(hdev);
7136 ret = hclge_mac_init(hdev);
7138 dev_err(&pdev->dev, "Mac init error, ret = %d\n", ret);
7142 ret = hclge_config_tso(hdev, HCLGE_TSO_MSS_MIN, HCLGE_TSO_MSS_MAX);
7144 dev_err(&pdev->dev, "Enable tso fail, ret =%d\n", ret);
7148 ret = hclge_init_vlan_config(hdev);
7150 dev_err(&pdev->dev, "VLAN init fail, ret =%d\n", ret);
7154 ret = hclge_tm_init_hw(hdev);
7156 dev_err(&pdev->dev, "tm init hw fail, ret =%d\n", ret);
7160 ret = hclge_rss_init_hw(hdev);
7162 dev_err(&pdev->dev, "Rss init fail, ret =%d\n", ret);
7166 ret = hclge_init_fd_config(hdev);
7169 "fd table init fail, ret=%d\n", ret);
7173 /* Re-enable the TM hw error interrupts because
7174 * they get disabled on core/global reset.
7176 if (hclge_enable_tm_hw_error(hdev, true))
7177 dev_err(&pdev->dev, "failed to enable TM hw error interrupts\n");
7179 dev_info(&pdev->dev, "Reset done, %s driver initialization finished.\n",
7185 static void hclge_uninit_ae_dev(struct hnae3_ae_dev *ae_dev)
7187 struct hclge_dev *hdev = ae_dev->priv;
7188 struct hclge_mac *mac = &hdev->hw.mac;
7190 hclge_state_uninit(hdev);
7193 mdiobus_unregister(mac->mdio_bus);
7195 hclge_uninit_umv_space(hdev);
7197 /* Disable MISC vector(vector0) */
7198 hclge_enable_vector(&hdev->misc_vector, false);
7199 synchronize_irq(hdev->misc_vector.vector_irq);
7201 hclge_hw_error_set_state(hdev, false);
7202 hclge_destroy_cmd_queue(&hdev->hw);
7203 hclge_misc_irq_uninit(hdev);
7204 hclge_pci_uninit(hdev);
7205 ae_dev->priv = NULL;
7208 static u32 hclge_get_max_channels(struct hnae3_handle *handle)
7210 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
7211 struct hclge_vport *vport = hclge_get_vport(handle);
7212 struct hclge_dev *hdev = vport->back;
7214 return min_t(u32, hdev->rss_size_max * kinfo->num_tc, hdev->num_tqps);
7217 static void hclge_get_channels(struct hnae3_handle *handle,
7218 struct ethtool_channels *ch)
7220 struct hclge_vport *vport = hclge_get_vport(handle);
7222 ch->max_combined = hclge_get_max_channels(handle);
7223 ch->other_count = 1;
7225 ch->combined_count = vport->alloc_tqps;
7228 static void hclge_get_tqps_and_rss_info(struct hnae3_handle *handle,
7229 u16 *alloc_tqps, u16 *max_rss_size)
7231 struct hclge_vport *vport = hclge_get_vport(handle);
7232 struct hclge_dev *hdev = vport->back;
7234 *alloc_tqps = vport->alloc_tqps;
7235 *max_rss_size = hdev->rss_size_max;
7238 static void hclge_release_tqp(struct hclge_vport *vport)
7240 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
7241 struct hclge_dev *hdev = vport->back;
7244 for (i = 0; i < kinfo->num_tqps; i++) {
7245 struct hclge_tqp *tqp =
7246 container_of(kinfo->tqp[i], struct hclge_tqp, q);
7248 tqp->q.handle = NULL;
7249 tqp->q.tqp_index = 0;
7250 tqp->alloced = false;
7253 devm_kfree(&hdev->pdev->dev, kinfo->tqp);
7257 static int hclge_set_channels(struct hnae3_handle *handle, u32 new_tqps_num)
7259 struct hclge_vport *vport = hclge_get_vport(handle);
7260 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
7261 struct hclge_dev *hdev = vport->back;
7262 int cur_rss_size = kinfo->rss_size;
7263 int cur_tqps = kinfo->num_tqps;
7264 u16 tc_offset[HCLGE_MAX_TC_NUM];
7265 u16 tc_valid[HCLGE_MAX_TC_NUM];
7266 u16 tc_size[HCLGE_MAX_TC_NUM];
7271 /* Free old tqps, and reallocate with new tqp number when nic setup */
7272 hclge_release_tqp(vport);
7274 ret = hclge_knic_setup(vport, new_tqps_num, kinfo->num_desc);
7276 dev_err(&hdev->pdev->dev, "setup nic fail, ret =%d\n", ret);
7280 ret = hclge_map_tqp_to_vport(hdev, vport);
7282 dev_err(&hdev->pdev->dev, "map vport tqp fail, ret =%d\n", ret);
7286 ret = hclge_tm_schd_init(hdev);
7288 dev_err(&hdev->pdev->dev, "tm schd init fail, ret =%d\n", ret);
7292 roundup_size = roundup_pow_of_two(kinfo->rss_size);
7293 roundup_size = ilog2(roundup_size);
7294 /* Set the RSS TC mode according to the new RSS size */
7295 for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
7298 if (!(hdev->hw_tc_map & BIT(i)))
7302 tc_size[i] = roundup_size;
7303 tc_offset[i] = kinfo->rss_size * i;
7305 ret = hclge_set_rss_tc_mode(hdev, tc_valid, tc_size, tc_offset);
7309 /* Reinitializes the rss indirect table according to the new RSS size */
7310 rss_indir = kcalloc(HCLGE_RSS_IND_TBL_SIZE, sizeof(u32), GFP_KERNEL);
7314 for (i = 0; i < HCLGE_RSS_IND_TBL_SIZE; i++)
7315 rss_indir[i] = i % kinfo->rss_size;
7317 ret = hclge_set_rss(handle, rss_indir, NULL, 0);
7319 dev_err(&hdev->pdev->dev, "set rss indir table fail, ret=%d\n",
7325 dev_info(&hdev->pdev->dev,
7326 "Channels changed, rss_size from %d to %d, tqps from %d to %d",
7327 cur_rss_size, kinfo->rss_size,
7328 cur_tqps, kinfo->rss_size * kinfo->num_tc);
7333 static int hclge_get_regs_num(struct hclge_dev *hdev, u32 *regs_num_32_bit,
7334 u32 *regs_num_64_bit)
7336 struct hclge_desc desc;
7340 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_REG_NUM, true);
7341 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
7343 dev_err(&hdev->pdev->dev,
7344 "Query register number cmd failed, ret = %d.\n", ret);
7348 *regs_num_32_bit = le32_to_cpu(desc.data[0]);
7349 *regs_num_64_bit = le32_to_cpu(desc.data[1]);
7351 total_num = *regs_num_32_bit + *regs_num_64_bit;
7358 static int hclge_get_32_bit_regs(struct hclge_dev *hdev, u32 regs_num,
7361 #define HCLGE_32_BIT_REG_RTN_DATANUM 8
7363 struct hclge_desc *desc;
7364 u32 *reg_val = data;
7373 cmd_num = DIV_ROUND_UP(regs_num + 2, HCLGE_32_BIT_REG_RTN_DATANUM);
7374 desc = kcalloc(cmd_num, sizeof(struct hclge_desc), GFP_KERNEL);
7378 hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_QUERY_32_BIT_REG, true);
7379 ret = hclge_cmd_send(&hdev->hw, desc, cmd_num);
7381 dev_err(&hdev->pdev->dev,
7382 "Query 32 bit register cmd failed, ret = %d.\n", ret);
7387 for (i = 0; i < cmd_num; i++) {
7389 desc_data = (__le32 *)(&desc[i].data[0]);
7390 n = HCLGE_32_BIT_REG_RTN_DATANUM - 2;
7392 desc_data = (__le32 *)(&desc[i]);
7393 n = HCLGE_32_BIT_REG_RTN_DATANUM;
7395 for (k = 0; k < n; k++) {
7396 *reg_val++ = le32_to_cpu(*desc_data++);
7408 static int hclge_get_64_bit_regs(struct hclge_dev *hdev, u32 regs_num,
7411 #define HCLGE_64_BIT_REG_RTN_DATANUM 4
7413 struct hclge_desc *desc;
7414 u64 *reg_val = data;
7423 cmd_num = DIV_ROUND_UP(regs_num + 1, HCLGE_64_BIT_REG_RTN_DATANUM);
7424 desc = kcalloc(cmd_num, sizeof(struct hclge_desc), GFP_KERNEL);
7428 hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_QUERY_64_BIT_REG, true);
7429 ret = hclge_cmd_send(&hdev->hw, desc, cmd_num);
7431 dev_err(&hdev->pdev->dev,
7432 "Query 64 bit register cmd failed, ret = %d.\n", ret);
7437 for (i = 0; i < cmd_num; i++) {
7439 desc_data = (__le64 *)(&desc[i].data[0]);
7440 n = HCLGE_64_BIT_REG_RTN_DATANUM - 1;
7442 desc_data = (__le64 *)(&desc[i]);
7443 n = HCLGE_64_BIT_REG_RTN_DATANUM;
7445 for (k = 0; k < n; k++) {
7446 *reg_val++ = le64_to_cpu(*desc_data++);
7458 static int hclge_get_regs_len(struct hnae3_handle *handle)
7460 struct hclge_vport *vport = hclge_get_vport(handle);
7461 struct hclge_dev *hdev = vport->back;
7462 u32 regs_num_32_bit, regs_num_64_bit;
7465 ret = hclge_get_regs_num(hdev, ®s_num_32_bit, ®s_num_64_bit);
7467 dev_err(&hdev->pdev->dev,
7468 "Get register number failed, ret = %d.\n", ret);
7472 return regs_num_32_bit * sizeof(u32) + regs_num_64_bit * sizeof(u64);
7475 static void hclge_get_regs(struct hnae3_handle *handle, u32 *version,
7478 struct hclge_vport *vport = hclge_get_vport(handle);
7479 struct hclge_dev *hdev = vport->back;
7480 u32 regs_num_32_bit, regs_num_64_bit;
7483 *version = hdev->fw_version;
7485 ret = hclge_get_regs_num(hdev, ®s_num_32_bit, ®s_num_64_bit);
7487 dev_err(&hdev->pdev->dev,
7488 "Get register number failed, ret = %d.\n", ret);
7492 ret = hclge_get_32_bit_regs(hdev, regs_num_32_bit, data);
7494 dev_err(&hdev->pdev->dev,
7495 "Get 32 bit register failed, ret = %d.\n", ret);
7499 data = (u32 *)data + regs_num_32_bit;
7500 ret = hclge_get_64_bit_regs(hdev, regs_num_64_bit,
7503 dev_err(&hdev->pdev->dev,
7504 "Get 64 bit register failed, ret = %d.\n", ret);
7507 static int hclge_set_led_status(struct hclge_dev *hdev, u8 locate_led_status)
7509 struct hclge_set_led_state_cmd *req;
7510 struct hclge_desc desc;
7513 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_LED_STATUS_CFG, false);
7515 req = (struct hclge_set_led_state_cmd *)desc.data;
7516 hnae3_set_field(req->locate_led_config, HCLGE_LED_LOCATE_STATE_M,
7517 HCLGE_LED_LOCATE_STATE_S, locate_led_status);
7519 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
7521 dev_err(&hdev->pdev->dev,
7522 "Send set led state cmd error, ret =%d\n", ret);
7527 enum hclge_led_status {
7530 HCLGE_LED_NO_CHANGE = 0xFF,
7533 static int hclge_set_led_id(struct hnae3_handle *handle,
7534 enum ethtool_phys_id_state status)
7536 struct hclge_vport *vport = hclge_get_vport(handle);
7537 struct hclge_dev *hdev = vport->back;
7540 case ETHTOOL_ID_ACTIVE:
7541 return hclge_set_led_status(hdev, HCLGE_LED_ON);
7542 case ETHTOOL_ID_INACTIVE:
7543 return hclge_set_led_status(hdev, HCLGE_LED_OFF);
7549 static void hclge_get_link_mode(struct hnae3_handle *handle,
7550 unsigned long *supported,
7551 unsigned long *advertising)
7553 unsigned int size = BITS_TO_LONGS(__ETHTOOL_LINK_MODE_MASK_NBITS);
7554 struct hclge_vport *vport = hclge_get_vport(handle);
7555 struct hclge_dev *hdev = vport->back;
7556 unsigned int idx = 0;
7558 for (; idx < size; idx++) {
7559 supported[idx] = hdev->hw.mac.supported[idx];
7560 advertising[idx] = hdev->hw.mac.advertising[idx];
7564 static const struct hnae3_ae_ops hclge_ops = {
7565 .init_ae_dev = hclge_init_ae_dev,
7566 .uninit_ae_dev = hclge_uninit_ae_dev,
7567 .init_client_instance = hclge_init_client_instance,
7568 .uninit_client_instance = hclge_uninit_client_instance,
7569 .map_ring_to_vector = hclge_map_ring_to_vector,
7570 .unmap_ring_from_vector = hclge_unmap_ring_frm_vector,
7571 .get_vector = hclge_get_vector,
7572 .put_vector = hclge_put_vector,
7573 .set_promisc_mode = hclge_set_promisc_mode,
7574 .set_loopback = hclge_set_loopback,
7575 .start = hclge_ae_start,
7576 .stop = hclge_ae_stop,
7577 .get_status = hclge_get_status,
7578 .get_ksettings_an_result = hclge_get_ksettings_an_result,
7579 .update_speed_duplex_h = hclge_update_speed_duplex_h,
7580 .cfg_mac_speed_dup_h = hclge_cfg_mac_speed_dup_h,
7581 .get_media_type = hclge_get_media_type,
7582 .get_rss_key_size = hclge_get_rss_key_size,
7583 .get_rss_indir_size = hclge_get_rss_indir_size,
7584 .get_rss = hclge_get_rss,
7585 .set_rss = hclge_set_rss,
7586 .set_rss_tuple = hclge_set_rss_tuple,
7587 .get_rss_tuple = hclge_get_rss_tuple,
7588 .get_tc_size = hclge_get_tc_size,
7589 .get_mac_addr = hclge_get_mac_addr,
7590 .set_mac_addr = hclge_set_mac_addr,
7591 .do_ioctl = hclge_do_ioctl,
7592 .add_uc_addr = hclge_add_uc_addr,
7593 .rm_uc_addr = hclge_rm_uc_addr,
7594 .add_mc_addr = hclge_add_mc_addr,
7595 .rm_mc_addr = hclge_rm_mc_addr,
7596 .set_autoneg = hclge_set_autoneg,
7597 .get_autoneg = hclge_get_autoneg,
7598 .get_pauseparam = hclge_get_pauseparam,
7599 .set_pauseparam = hclge_set_pauseparam,
7600 .set_mtu = hclge_set_mtu,
7601 .reset_queue = hclge_reset_tqp,
7602 .get_stats = hclge_get_stats,
7603 .update_stats = hclge_update_stats,
7604 .get_strings = hclge_get_strings,
7605 .get_sset_count = hclge_get_sset_count,
7606 .get_fw_version = hclge_get_fw_version,
7607 .get_mdix_mode = hclge_get_mdix_mode,
7608 .enable_vlan_filter = hclge_enable_vlan_filter,
7609 .set_vlan_filter = hclge_set_vlan_filter,
7610 .set_vf_vlan_filter = hclge_set_vf_vlan_filter,
7611 .enable_hw_strip_rxvtag = hclge_en_hw_strip_rxvtag,
7612 .reset_event = hclge_reset_event,
7613 .set_default_reset_request = hclge_set_def_reset_request,
7614 .get_tqps_and_rss_info = hclge_get_tqps_and_rss_info,
7615 .set_channels = hclge_set_channels,
7616 .get_channels = hclge_get_channels,
7617 .get_regs_len = hclge_get_regs_len,
7618 .get_regs = hclge_get_regs,
7619 .set_led_id = hclge_set_led_id,
7620 .get_link_mode = hclge_get_link_mode,
7621 .add_fd_entry = hclge_add_fd_entry,
7622 .del_fd_entry = hclge_del_fd_entry,
7623 .del_all_fd_entries = hclge_del_all_fd_entries,
7624 .get_fd_rule_cnt = hclge_get_fd_rule_cnt,
7625 .get_fd_rule_info = hclge_get_fd_rule_info,
7626 .get_fd_all_rules = hclge_get_all_rules,
7627 .restore_fd_rules = hclge_restore_fd_entries,
7628 .enable_fd = hclge_enable_fd,
7629 .process_hw_error = hclge_process_ras_hw_error,
7630 .get_hw_reset_stat = hclge_get_hw_reset_stat,
7631 .ae_dev_resetting = hclge_ae_dev_resetting,
7632 .ae_dev_reset_cnt = hclge_ae_dev_reset_cnt,
7635 static struct hnae3_ae_algo ae_algo = {
7637 .pdev_id_table = ae_algo_pci_tbl,
7640 static int hclge_init(void)
7642 pr_info("%s is initializing\n", HCLGE_NAME);
7644 hnae3_register_ae_algo(&ae_algo);
7649 static void hclge_exit(void)
7651 hnae3_unregister_ae_algo(&ae_algo);
7653 module_init(hclge_init);
7654 module_exit(hclge_exit);
7656 MODULE_LICENSE("GPL");
7657 MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
7658 MODULE_DESCRIPTION("HCLGE Driver");
7659 MODULE_VERSION(HCLGE_MOD_VERSION);