1
2
3
4
5
6
7
8
9
10#ifndef __HCLGE_MAIN_H
11#define __HCLGE_MAIN_H
12#include <linux/fs.h>
13#include <linux/types.h>
14#include <linux/phy.h>
15#include <linux/if_vlan.h>
16
17#include "hclge_cmd.h"
18#include "hnae3.h"
19
20#define HCLGE_MOD_VERSION "1.0"
21#define HCLGE_DRIVER_NAME "hclge"
22
23#define HCLGE_MAX_PF_NUM 8
24
25#define HCLGE_INVALID_VPORT 0xffff
26
27#define HCLGE_PF_CFG_BLOCK_SIZE 32
28#define HCLGE_PF_CFG_DESC_NUM \
29 (HCLGE_PF_CFG_BLOCK_SIZE / HCLGE_CFG_RD_LEN_BYTES)
30
31#define HCLGE_VECTOR_REG_BASE 0x20000
32#define HCLGE_MISC_VECTOR_REG_BASE 0x20400
33
34#define HCLGE_VECTOR_REG_OFFSET 0x4
35#define HCLGE_VECTOR_VF_OFFSET 0x100000
36
37#define HCLGE_RSS_IND_TBL_SIZE 512
38#define HCLGE_RSS_SET_BITMAP_MSK GENMASK(15, 0)
39#define HCLGE_RSS_KEY_SIZE 40
40#define HCLGE_RSS_HASH_ALGO_TOEPLITZ 0
41#define HCLGE_RSS_HASH_ALGO_SIMPLE 1
42#define HCLGE_RSS_HASH_ALGO_SYMMETRIC 2
43#define HCLGE_RSS_HASH_ALGO_MASK GENMASK(3, 0)
44#define HCLGE_RSS_CFG_TBL_NUM \
45 (HCLGE_RSS_IND_TBL_SIZE / HCLGE_RSS_CFG_TBL_SIZE)
46
47#define HCLGE_RSS_INPUT_TUPLE_OTHER GENMASK(3, 0)
48#define HCLGE_RSS_INPUT_TUPLE_SCTP GENMASK(4, 0)
49#define HCLGE_D_PORT_BIT BIT(0)
50#define HCLGE_S_PORT_BIT BIT(1)
51#define HCLGE_D_IP_BIT BIT(2)
52#define HCLGE_S_IP_BIT BIT(3)
53#define HCLGE_V_TAG_BIT BIT(4)
54
55#define HCLGE_RSS_TC_SIZE_0 1
56#define HCLGE_RSS_TC_SIZE_1 2
57#define HCLGE_RSS_TC_SIZE_2 4
58#define HCLGE_RSS_TC_SIZE_3 8
59#define HCLGE_RSS_TC_SIZE_4 16
60#define HCLGE_RSS_TC_SIZE_5 32
61#define HCLGE_RSS_TC_SIZE_6 64
62#define HCLGE_RSS_TC_SIZE_7 128
63
64#define HCLGE_UMV_TBL_SIZE 3072
65#define HCLGE_DEFAULT_UMV_SPACE_PER_PF \
66 (HCLGE_UMV_TBL_SIZE / HCLGE_MAX_PF_NUM)
67
68#define HCLGE_MTA_TBL_SIZE 4096
69
70#define HCLGE_TQP_RESET_TRY_TIMES 10
71
72#define HCLGE_PHY_PAGE_MDIX 0
73#define HCLGE_PHY_PAGE_COPPER 0
74
75
76#define HCLGE_PHY_PAGE_REG 22
77
78
79#define HCLGE_PHY_CSC_REG 16
80
81
82#define HCLGE_PHY_CSS_REG 17
83
84#define HCLGE_PHY_MDIX_CTRL_S (5)
85#define HCLGE_PHY_MDIX_CTRL_M GENMASK(6, 5)
86
87#define HCLGE_PHY_MDIX_STATUS_B (6)
88#define HCLGE_PHY_SPEED_DUP_RESOLVE_B (11)
89
90
91#define HCLGE_VF_NUM_PER_CMD 64
92#define HCLGE_VF_NUM_PER_BYTE 8
93
94
95#define HCLGE_MISC_RESET_STS_REG 0x20700
96#define HCLGE_MISC_VECTOR_INT_STS 0x20800
97#define HCLGE_GLOBAL_RESET_REG 0x20A00
98#define HCLGE_GLOBAL_RESET_BIT 0x0
99#define HCLGE_CORE_RESET_BIT 0x1
100#define HCLGE_FUN_RST_ING 0x20C00
101#define HCLGE_FUN_RST_ING_B 0
102
103
104#define HCLGE_VECTOR0_GLOBALRESET_INT_B 5
105#define HCLGE_VECTOR0_CORERESET_INT_B 6
106#define HCLGE_VECTOR0_IMPRESET_INT_B 7
107
108
109#define HCLGE_VECTOR0_CMDQ_SRC_REG 0x27100
110
111#define HCLGE_VECTOR0_RX_CMDQ_INT_B 1
112
113#define HCLGE_MAC_DEFAULT_FRAME \
114 (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN + ETH_DATA_LEN)
115#define HCLGE_MAC_MIN_FRAME 64
116#define HCLGE_MAC_MAX_FRAME 9728
117
118#define HCLGE_SUPPORT_1G_BIT BIT(0)
119#define HCLGE_SUPPORT_10G_BIT BIT(1)
120#define HCLGE_SUPPORT_25G_BIT BIT(2)
121#define HCLGE_SUPPORT_50G_BIT BIT(3)
122#define HCLGE_SUPPORT_100G_BIT BIT(4)
123
124enum HCLGE_DEV_STATE {
125 HCLGE_STATE_REINITING,
126 HCLGE_STATE_DOWN,
127 HCLGE_STATE_DISABLED,
128 HCLGE_STATE_REMOVING,
129 HCLGE_STATE_SERVICE_INITED,
130 HCLGE_STATE_SERVICE_SCHED,
131 HCLGE_STATE_RST_SERVICE_SCHED,
132 HCLGE_STATE_RST_HANDLING,
133 HCLGE_STATE_MBX_SERVICE_SCHED,
134 HCLGE_STATE_MBX_HANDLING,
135 HCLGE_STATE_STATISTICS_UPDATING,
136 HCLGE_STATE_CMD_DISABLE,
137 HCLGE_STATE_MAX
138};
139
140enum hclge_evt_cause {
141 HCLGE_VECTOR0_EVENT_RST,
142 HCLGE_VECTOR0_EVENT_MBX,
143 HCLGE_VECTOR0_EVENT_OTHER,
144};
145
146#define HCLGE_MPF_ENBALE 1
147struct hclge_caps {
148 u16 num_tqp;
149 u16 num_buffer_cell;
150 u32 flag;
151 u16 vmdq;
152};
153
154enum HCLGE_MAC_SPEED {
155 HCLGE_MAC_SPEED_10M = 10,
156 HCLGE_MAC_SPEED_100M = 100,
157 HCLGE_MAC_SPEED_1G = 1000,
158 HCLGE_MAC_SPEED_10G = 10000,
159 HCLGE_MAC_SPEED_25G = 25000,
160 HCLGE_MAC_SPEED_40G = 40000,
161 HCLGE_MAC_SPEED_50G = 50000,
162 HCLGE_MAC_SPEED_100G = 100000
163};
164
165enum HCLGE_MAC_DUPLEX {
166 HCLGE_MAC_HALF,
167 HCLGE_MAC_FULL
168};
169
170enum hclge_mta_dmac_sel_type {
171 HCLGE_MAC_ADDR_47_36,
172 HCLGE_MAC_ADDR_46_35,
173 HCLGE_MAC_ADDR_45_34,
174 HCLGE_MAC_ADDR_44_33,
175};
176
177struct hclge_mac {
178 u8 phy_addr;
179 u8 flag;
180 u8 media_type;
181 u8 mac_addr[ETH_ALEN];
182 u8 autoneg;
183 u8 duplex;
184 u32 speed;
185 int link;
186 struct phy_device *phydev;
187 struct mii_bus *mdio_bus;
188 phy_interface_t phy_if;
189 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
190 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
191};
192
193struct hclge_hw {
194 void __iomem *io_base;
195 struct hclge_mac mac;
196 int num_vec;
197 struct hclge_cmq cmq;
198 struct hclge_caps caps;
199};
200
201
202struct hlcge_tqp_stats {
203
204 u64 rcb_tx_ring_pktnum_rcd;
205
206 u64 rcb_rx_ring_pktnum_rcd;
207};
208
209struct hclge_tqp {
210 struct device *dev;
211 struct hnae3_queue q;
212 struct hlcge_tqp_stats tqp_stats;
213 u16 index;
214
215 bool alloced;
216};
217
218enum hclge_fc_mode {
219 HCLGE_FC_NONE,
220 HCLGE_FC_RX_PAUSE,
221 HCLGE_FC_TX_PAUSE,
222 HCLGE_FC_FULL,
223 HCLGE_FC_PFC,
224 HCLGE_FC_DEFAULT
225};
226
227#define HCLGE_PG_NUM 4
228#define HCLGE_SCH_MODE_SP 0
229#define HCLGE_SCH_MODE_DWRR 1
230struct hclge_pg_info {
231 u8 pg_id;
232 u8 pg_sch_mode;
233 u8 tc_bit_map;
234 u32 bw_limit;
235 u8 tc_dwrr[HNAE3_MAX_TC];
236};
237
238struct hclge_tc_info {
239 u8 tc_id;
240 u8 tc_sch_mode;
241 u8 pgid;
242 u32 bw_limit;
243};
244
245struct hclge_cfg {
246 u8 vmdq_vport_num;
247 u8 tc_num;
248 u16 tqp_desc_num;
249 u16 rx_buf_len;
250 u16 rss_size_max;
251 u8 phy_addr;
252 u8 media_type;
253 u8 mac_addr[ETH_ALEN];
254 u8 default_speed;
255 u32 numa_node_map;
256 u8 speed_ability;
257 u16 umv_space;
258};
259
260struct hclge_tm_info {
261 u8 num_tc;
262 u8 num_pg;
263 u8 pg_dwrr[HCLGE_PG_NUM];
264 u8 prio_tc[HNAE3_MAX_USER_PRIO];
265 struct hclge_pg_info pg_info[HCLGE_PG_NUM];
266 struct hclge_tc_info tc_info[HNAE3_MAX_TC];
267 enum hclge_fc_mode fc_mode;
268 u8 hw_pfc_map;
269};
270
271struct hclge_comm_stats_str {
272 char desc[ETH_GSTRING_LEN];
273 unsigned long offset;
274};
275
276
277struct hclge_mac_stats {
278 u64 mac_tx_mac_pause_num;
279 u64 mac_rx_mac_pause_num;
280 u64 mac_tx_pfc_pri0_pkt_num;
281 u64 mac_tx_pfc_pri1_pkt_num;
282 u64 mac_tx_pfc_pri2_pkt_num;
283 u64 mac_tx_pfc_pri3_pkt_num;
284 u64 mac_tx_pfc_pri4_pkt_num;
285 u64 mac_tx_pfc_pri5_pkt_num;
286 u64 mac_tx_pfc_pri6_pkt_num;
287 u64 mac_tx_pfc_pri7_pkt_num;
288 u64 mac_rx_pfc_pri0_pkt_num;
289 u64 mac_rx_pfc_pri1_pkt_num;
290 u64 mac_rx_pfc_pri2_pkt_num;
291 u64 mac_rx_pfc_pri3_pkt_num;
292 u64 mac_rx_pfc_pri4_pkt_num;
293 u64 mac_rx_pfc_pri5_pkt_num;
294 u64 mac_rx_pfc_pri6_pkt_num;
295 u64 mac_rx_pfc_pri7_pkt_num;
296 u64 mac_tx_total_pkt_num;
297 u64 mac_tx_total_oct_num;
298 u64 mac_tx_good_pkt_num;
299 u64 mac_tx_bad_pkt_num;
300 u64 mac_tx_good_oct_num;
301 u64 mac_tx_bad_oct_num;
302 u64 mac_tx_uni_pkt_num;
303 u64 mac_tx_multi_pkt_num;
304 u64 mac_tx_broad_pkt_num;
305 u64 mac_tx_undersize_pkt_num;
306 u64 mac_tx_oversize_pkt_num;
307 u64 mac_tx_64_oct_pkt_num;
308 u64 mac_tx_65_127_oct_pkt_num;
309 u64 mac_tx_128_255_oct_pkt_num;
310 u64 mac_tx_256_511_oct_pkt_num;
311 u64 mac_tx_512_1023_oct_pkt_num;
312 u64 mac_tx_1024_1518_oct_pkt_num;
313 u64 mac_tx_1519_2047_oct_pkt_num;
314 u64 mac_tx_2048_4095_oct_pkt_num;
315 u64 mac_tx_4096_8191_oct_pkt_num;
316 u64 rsv0;
317 u64 mac_tx_8192_9216_oct_pkt_num;
318 u64 mac_tx_9217_12287_oct_pkt_num;
319 u64 mac_tx_12288_16383_oct_pkt_num;
320 u64 mac_tx_1519_max_good_oct_pkt_num;
321 u64 mac_tx_1519_max_bad_oct_pkt_num;
322
323 u64 mac_rx_total_pkt_num;
324 u64 mac_rx_total_oct_num;
325 u64 mac_rx_good_pkt_num;
326 u64 mac_rx_bad_pkt_num;
327 u64 mac_rx_good_oct_num;
328 u64 mac_rx_bad_oct_num;
329 u64 mac_rx_uni_pkt_num;
330 u64 mac_rx_multi_pkt_num;
331 u64 mac_rx_broad_pkt_num;
332 u64 mac_rx_undersize_pkt_num;
333 u64 mac_rx_oversize_pkt_num;
334 u64 mac_rx_64_oct_pkt_num;
335 u64 mac_rx_65_127_oct_pkt_num;
336 u64 mac_rx_128_255_oct_pkt_num;
337 u64 mac_rx_256_511_oct_pkt_num;
338 u64 mac_rx_512_1023_oct_pkt_num;
339 u64 mac_rx_1024_1518_oct_pkt_num;
340 u64 mac_rx_1519_2047_oct_pkt_num;
341 u64 mac_rx_2048_4095_oct_pkt_num;
342 u64 mac_rx_4096_8191_oct_pkt_num;
343 u64 rsv1;
344 u64 mac_rx_8192_9216_oct_pkt_num;
345 u64 mac_rx_9217_12287_oct_pkt_num;
346 u64 mac_rx_12288_16383_oct_pkt_num;
347 u64 mac_rx_1519_max_good_oct_pkt_num;
348 u64 mac_rx_1519_max_bad_oct_pkt_num;
349
350 u64 mac_tx_fragment_pkt_num;
351 u64 mac_tx_undermin_pkt_num;
352 u64 mac_tx_jabber_pkt_num;
353 u64 mac_tx_err_all_pkt_num;
354 u64 mac_tx_from_app_good_pkt_num;
355 u64 mac_tx_from_app_bad_pkt_num;
356 u64 mac_rx_fragment_pkt_num;
357 u64 mac_rx_undermin_pkt_num;
358 u64 mac_rx_jabber_pkt_num;
359 u64 mac_rx_fcs_err_pkt_num;
360 u64 mac_rx_send_app_good_pkt_num;
361 u64 mac_rx_send_app_bad_pkt_num;
362};
363
364#define HCLGE_STATS_TIMER_INTERVAL (60 * 5)
365struct hclge_hw_stats {
366 struct hclge_mac_stats mac_stats;
367 u32 stats_timer;
368};
369
370struct hclge_vlan_type_cfg {
371 u16 rx_ot_fst_vlan_type;
372 u16 rx_ot_sec_vlan_type;
373 u16 rx_in_fst_vlan_type;
374 u16 rx_in_sec_vlan_type;
375 u16 tx_ot_vlan_type;
376 u16 tx_in_vlan_type;
377};
378
379#define HCLGE_VPORT_NUM 256
380struct hclge_dev {
381 struct pci_dev *pdev;
382 struct hnae3_ae_dev *ae_dev;
383 struct hclge_hw hw;
384 struct hclge_misc_vector misc_vector;
385 struct hclge_hw_stats hw_stats;
386 unsigned long state;
387
388 enum hnae3_reset_type reset_type;
389 unsigned long reset_request;
390 unsigned long reset_pending;
391 u32 fw_version;
392 u16 num_vmdq_vport;
393 u16 num_tqps;
394 u16 num_req_vfs;
395
396
397 u16 base_tqp_pid;
398 u16 alloc_rss_size;
399 u16 rss_size_max;
400
401
402 u16 fdir_pf_filter_count;
403 u16 num_alloc_vport;
404 u32 numa_node_mask;
405 u16 rx_buf_len;
406 u16 num_desc;
407 u8 hw_tc_map;
408 u8 tc_num_last_time;
409 enum hclge_fc_mode fc_mode_last_time;
410
411#define HCLGE_FLAG_TC_BASE_SCH_MODE 1
412#define HCLGE_FLAG_VNET_BASE_SCH_MODE 2
413 u8 tx_sch_mode;
414 u8 tc_max;
415 u8 pfc_max;
416
417 u8 default_up;
418 u8 dcbx_cap;
419 struct hclge_tm_info tm_info;
420
421 u16 num_msi;
422 u16 num_msi_left;
423 u16 num_msi_used;
424 u16 roce_base_msix_offset;
425 u32 base_msi_vector;
426 u16 *vector_status;
427 int *vector_irq;
428 u16 num_roce_msi;
429 int roce_base_vector;
430
431 u16 pending_udp_bitmap;
432
433 u16 rx_itr_default;
434 u16 tx_itr_default;
435
436 u16 adminq_work_limit;
437 unsigned long service_timer_period;
438 unsigned long service_timer_previous;
439 struct timer_list service_timer;
440 struct work_struct service_task;
441 struct work_struct rst_service_task;
442 struct work_struct mbx_service_task;
443
444 bool cur_promisc;
445 int num_alloc_vfs;
446
447 struct hclge_tqp *htqp;
448 struct hclge_vport *vport;
449
450 struct dentry *hclge_dbgfs;
451
452 struct hnae3_client *nic_client;
453 struct hnae3_client *roce_client;
454
455#define HCLGE_FLAG_MAIN BIT(0)
456#define HCLGE_FLAG_DCB_CAPABLE BIT(1)
457#define HCLGE_FLAG_DCB_ENABLE BIT(2)
458#define HCLGE_FLAG_MQPRIO_ENABLE BIT(3)
459 u32 flag;
460
461 u32 pkt_buf_size;
462 u32 tx_buf_size;
463 u32 dv_buf_size;
464
465 u32 mps;
466
467 enum hclge_mta_dmac_sel_type mta_mac_sel_type;
468 bool enable_mta;
469
470 struct hclge_vlan_type_cfg vlan_type_cfg;
471
472 unsigned long vlan_table[VLAN_N_VID][BITS_TO_LONGS(HCLGE_VPORT_NUM)];
473
474 u16 wanted_umv_size;
475
476 u16 max_umv_size;
477
478 u16 priv_umv_size;
479
480 u16 share_umv_size;
481 struct mutex umv_mutex;
482};
483
484
485struct hclge_tx_vtag_cfg {
486 bool accept_tag1;
487 bool accept_untag1;
488 bool accept_tag2;
489 bool accept_untag2;
490 bool insert_tag1_en;
491 bool insert_tag2_en;
492 u16 default_tag1;
493 u16 default_tag2;
494};
495
496
497struct hclge_rx_vtag_cfg {
498 bool strip_tag1_en;
499 bool strip_tag2_en;
500 bool vlan1_vlan_prionly;
501 bool vlan2_vlan_prionly;
502};
503
504struct hclge_rss_tuple_cfg {
505 u8 ipv4_tcp_en;
506 u8 ipv4_udp_en;
507 u8 ipv4_sctp_en;
508 u8 ipv4_fragment_en;
509 u8 ipv6_tcp_en;
510 u8 ipv6_udp_en;
511 u8 ipv6_sctp_en;
512 u8 ipv6_fragment_en;
513};
514
515struct hclge_vport {
516 u16 alloc_tqps;
517
518 u8 rss_hash_key[HCLGE_RSS_KEY_SIZE];
519
520 u8 rss_indirection_tbl[HCLGE_RSS_IND_TBL_SIZE];
521 int rss_algo;
522
523 struct hclge_rss_tuple_cfg rss_tuple_sets;
524
525 u16 alloc_rss_size;
526
527 u16 qs_offset;
528 u16 bw_limit;
529 u8 dwrr;
530
531 struct hclge_tx_vtag_cfg txvlan_cfg;
532 struct hclge_rx_vtag_cfg rxvlan_cfg;
533
534 u16 used_umv_num;
535
536 int vport_id;
537 struct hclge_dev *back;
538 struct hnae3_handle nic;
539 struct hnae3_handle roce;
540
541 bool accept_mta_mc;
542 unsigned long mta_shadow[BITS_TO_LONGS(HCLGE_MTA_TBL_SIZE)];
543};
544
545void hclge_promisc_param_init(struct hclge_promisc_param *param, bool en_uc,
546 bool en_mc, bool en_bc, int vport_id);
547
548int hclge_add_uc_addr_common(struct hclge_vport *vport,
549 const unsigned char *addr);
550int hclge_rm_uc_addr_common(struct hclge_vport *vport,
551 const unsigned char *addr);
552int hclge_add_mc_addr_common(struct hclge_vport *vport,
553 const unsigned char *addr);
554int hclge_rm_mc_addr_common(struct hclge_vport *vport,
555 const unsigned char *addr);
556
557int hclge_cfg_func_mta_filter(struct hclge_dev *hdev,
558 u8 func_id,
559 bool enable);
560int hclge_update_mta_status_common(struct hclge_vport *vport,
561 unsigned long *status,
562 u16 idx,
563 u16 count,
564 bool update_filter);
565
566struct hclge_vport *hclge_get_vport(struct hnae3_handle *handle);
567int hclge_bind_ring_with_vector(struct hclge_vport *vport,
568 int vector_id, bool en,
569 struct hnae3_ring_chain_node *ring_chain);
570
571static inline int hclge_get_queue_id(struct hnae3_queue *queue)
572{
573 struct hclge_tqp *tqp = container_of(queue, struct hclge_tqp, q);
574
575 return tqp->index;
576}
577
578int hclge_cfg_mac_speed_dup(struct hclge_dev *hdev, int speed, u8 duplex);
579int hclge_set_vlan_filter(struct hnae3_handle *handle, __be16 proto,
580 u16 vlan_id, bool is_kill);
581int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable);
582
583int hclge_buffer_alloc(struct hclge_dev *hdev);
584int hclge_rss_init_hw(struct hclge_dev *hdev);
585void hclge_rss_indir_init_cfg(struct hclge_dev *hdev);
586
587void hclge_mbx_handler(struct hclge_dev *hdev);
588void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
589void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id);
590int hclge_cfg_flowctrl(struct hclge_dev *hdev);
591int hclge_func_reset_cmd(struct hclge_dev *hdev, int func_id);
592#endif
593