1
2
3
4#ifndef __HNAE3_H
5#define __HNAE3_H
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/acpi.h>
25#include <linux/dcbnl.h>
26#include <linux/delay.h>
27#include <linux/device.h>
28#include <linux/module.h>
29#include <linux/netdevice.h>
30#include <linux/pci.h>
31#include <linux/types.h>
32
33#define HNAE3_MOD_VERSION "1.0"
34
35
36#define HNAE3_DEV_ID_GE 0xA220
37#define HNAE3_DEV_ID_25GE 0xA221
38#define HNAE3_DEV_ID_25GE_RDMA 0xA222
39#define HNAE3_DEV_ID_25GE_RDMA_MACSEC 0xA223
40#define HNAE3_DEV_ID_50GE_RDMA 0xA224
41#define HNAE3_DEV_ID_50GE_RDMA_MACSEC 0xA225
42#define HNAE3_DEV_ID_100G_RDMA_MACSEC 0xA226
43#define HNAE3_DEV_ID_100G_VF 0xA22E
44#define HNAE3_DEV_ID_100G_RDMA_DCB_PFC_VF 0xA22F
45
46#define HNAE3_CLASS_NAME_SIZE 16
47
48#define HNAE3_DEV_INITED_B 0x0
49#define HNAE3_DEV_SUPPORT_ROCE_B 0x1
50#define HNAE3_DEV_SUPPORT_DCB_B 0x2
51#define HNAE3_KNIC_CLIENT_INITED_B 0x3
52#define HNAE3_UNIC_CLIENT_INITED_B 0x4
53#define HNAE3_ROCE_CLIENT_INITED_B 0x5
54#define HNAE3_DEV_SUPPORT_FD_B 0x6
55#define HNAE3_DEV_SUPPORT_GRO_B 0x7
56
57#define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) |\
58 BIT(HNAE3_DEV_SUPPORT_ROCE_B))
59
60#define hnae3_dev_roce_supported(hdev) \
61 hnae3_get_bit(hdev->ae_dev->flag, HNAE3_DEV_SUPPORT_ROCE_B)
62
63#define hnae3_dev_dcb_supported(hdev) \
64 hnae3_get_bit(hdev->ae_dev->flag, HNAE3_DEV_SUPPORT_DCB_B)
65
66#define hnae3_dev_fd_supported(hdev) \
67 hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_FD_B)
68
69#define hnae3_dev_gro_supported(hdev) \
70 hnae3_get_bit((hdev)->ae_dev->flag, HNAE3_DEV_SUPPORT_GRO_B)
71
72#define ring_ptr_move_fw(ring, p) \
73 ((ring)->p = ((ring)->p + 1) % (ring)->desc_num)
74#define ring_ptr_move_bw(ring, p) \
75 ((ring)->p = ((ring)->p - 1 + (ring)->desc_num) % (ring)->desc_num)
76
77enum hns_desc_type {
78 DESC_TYPE_SKB,
79 DESC_TYPE_PAGE,
80};
81
82struct hnae3_handle;
83
84struct hnae3_queue {
85 void __iomem *io_base;
86 struct hnae3_ae_algo *ae_algo;
87 struct hnae3_handle *handle;
88 int tqp_index;
89 u32 buf_size;
90 u16 tx_desc_num;
91 u16 rx_desc_num;
92};
93
94
95enum hnae3_loop {
96 HNAE3_LOOP_APP,
97 HNAE3_LOOP_SERIAL_SERDES,
98 HNAE3_LOOP_PARALLEL_SERDES,
99 HNAE3_LOOP_PHY,
100 HNAE3_LOOP_NONE,
101};
102
103enum hnae3_client_type {
104 HNAE3_CLIENT_KNIC,
105 HNAE3_CLIENT_ROCE,
106};
107
108
109enum hnae3_media_type {
110 HNAE3_MEDIA_TYPE_UNKNOWN,
111 HNAE3_MEDIA_TYPE_FIBER,
112 HNAE3_MEDIA_TYPE_COPPER,
113 HNAE3_MEDIA_TYPE_BACKPLANE,
114 HNAE3_MEDIA_TYPE_NONE,
115};
116
117
118enum hnae3_module_type {
119 HNAE3_MODULE_TYPE_UNKNOWN = 0x00,
120 HNAE3_MODULE_TYPE_FIBRE_LR = 0x01,
121 HNAE3_MODULE_TYPE_FIBRE_SR = 0x02,
122 HNAE3_MODULE_TYPE_AOC = 0x03,
123 HNAE3_MODULE_TYPE_CR = 0x04,
124 HNAE3_MODULE_TYPE_KR = 0x05,
125 HNAE3_MODULE_TYPE_TP = 0x06,
126
127};
128
129enum hnae3_fec_mode {
130 HNAE3_FEC_AUTO = 0,
131 HNAE3_FEC_BASER,
132 HNAE3_FEC_RS,
133 HNAE3_FEC_USER_DEF,
134};
135
136enum hnae3_reset_notify_type {
137 HNAE3_UP_CLIENT,
138 HNAE3_DOWN_CLIENT,
139 HNAE3_INIT_CLIENT,
140 HNAE3_UNINIT_CLIENT,
141 HNAE3_RESTORE_CLIENT,
142};
143
144enum hnae3_reset_type {
145 HNAE3_VF_RESET,
146 HNAE3_VF_FUNC_RESET,
147 HNAE3_VF_PF_FUNC_RESET,
148 HNAE3_VF_FULL_RESET,
149 HNAE3_FLR_RESET,
150 HNAE3_FUNC_RESET,
151 HNAE3_GLOBAL_RESET,
152 HNAE3_IMP_RESET,
153 HNAE3_UNKNOWN_RESET,
154 HNAE3_NONE_RESET,
155};
156
157enum hnae3_flr_state {
158 HNAE3_FLR_DOWN,
159 HNAE3_FLR_DONE,
160};
161
162enum hnae3_port_base_vlan_state {
163 HNAE3_PORT_BASE_VLAN_DISABLE,
164 HNAE3_PORT_BASE_VLAN_ENABLE,
165 HNAE3_PORT_BASE_VLAN_MODIFY,
166 HNAE3_PORT_BASE_VLAN_NOCHANGE,
167};
168
169struct hnae3_vector_info {
170 u8 __iomem *io_addr;
171 int vector;
172};
173
174#define HNAE3_RING_TYPE_B 0
175#define HNAE3_RING_TYPE_TX 0
176#define HNAE3_RING_TYPE_RX 1
177#define HNAE3_RING_GL_IDX_S 0
178#define HNAE3_RING_GL_IDX_M GENMASK(1, 0)
179#define HNAE3_RING_GL_RX 0
180#define HNAE3_RING_GL_TX 1
181
182struct hnae3_ring_chain_node {
183 struct hnae3_ring_chain_node *next;
184 u32 tqp_index;
185 u32 flag;
186 u32 int_gl_idx;
187};
188
189#define HNAE3_IS_TX_RING(node) \
190 (((node)->flag & (1 << HNAE3_RING_TYPE_B)) == HNAE3_RING_TYPE_TX)
191
192struct hnae3_client_ops {
193 int (*init_instance)(struct hnae3_handle *handle);
194 void (*uninit_instance)(struct hnae3_handle *handle, bool reset);
195 void (*link_status_change)(struct hnae3_handle *handle, bool state);
196 int (*setup_tc)(struct hnae3_handle *handle, u8 tc);
197 int (*reset_notify)(struct hnae3_handle *handle,
198 enum hnae3_reset_notify_type type);
199 enum hnae3_reset_type (*process_hw_error)(struct hnae3_handle *handle);
200};
201
202#define HNAE3_CLIENT_NAME_LENGTH 16
203struct hnae3_client {
204 char name[HNAE3_CLIENT_NAME_LENGTH];
205 unsigned long state;
206 enum hnae3_client_type type;
207 const struct hnae3_client_ops *ops;
208 struct list_head node;
209};
210
211struct hnae3_ae_dev {
212 struct pci_dev *pdev;
213 const struct hnae3_ae_ops *ops;
214 struct list_head node;
215 u32 flag;
216 unsigned long hw_err_reset_req;
217 enum hnae3_reset_type reset_type;
218 void *priv;
219};
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345struct hnae3_ae_ops {
346 int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
347 void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev);
348 void (*flr_prepare)(struct hnae3_ae_dev *ae_dev);
349 void (*flr_done)(struct hnae3_ae_dev *ae_dev);
350 int (*init_client_instance)(struct hnae3_client *client,
351 struct hnae3_ae_dev *ae_dev);
352 void (*uninit_client_instance)(struct hnae3_client *client,
353 struct hnae3_ae_dev *ae_dev);
354 int (*start)(struct hnae3_handle *handle);
355 void (*stop)(struct hnae3_handle *handle);
356 int (*client_start)(struct hnae3_handle *handle);
357 void (*client_stop)(struct hnae3_handle *handle);
358 int (*get_status)(struct hnae3_handle *handle);
359 void (*get_ksettings_an_result)(struct hnae3_handle *handle,
360 u8 *auto_neg, u32 *speed, u8 *duplex);
361
362 int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int speed,
363 u8 duplex);
364
365 void (*get_media_type)(struct hnae3_handle *handle, u8 *media_type,
366 u8 *module_type);
367 int (*check_port_speed)(struct hnae3_handle *handle, u32 speed);
368 void (*get_fec)(struct hnae3_handle *handle, u8 *fec_ability,
369 u8 *fec_mode);
370 int (*set_fec)(struct hnae3_handle *handle, u32 fec_mode);
371 void (*adjust_link)(struct hnae3_handle *handle, int speed, int duplex);
372 int (*set_loopback)(struct hnae3_handle *handle,
373 enum hnae3_loop loop_mode, bool en);
374
375 int (*set_promisc_mode)(struct hnae3_handle *handle, bool en_uc_pmc,
376 bool en_mc_pmc);
377 int (*set_mtu)(struct hnae3_handle *handle, int new_mtu);
378
379 void (*get_pauseparam)(struct hnae3_handle *handle,
380 u32 *auto_neg, u32 *rx_en, u32 *tx_en);
381 int (*set_pauseparam)(struct hnae3_handle *handle,
382 u32 auto_neg, u32 rx_en, u32 tx_en);
383
384 int (*set_autoneg)(struct hnae3_handle *handle, bool enable);
385 int (*get_autoneg)(struct hnae3_handle *handle);
386 int (*restart_autoneg)(struct hnae3_handle *handle);
387 int (*halt_autoneg)(struct hnae3_handle *handle, bool halt);
388
389 void (*get_coalesce_usecs)(struct hnae3_handle *handle,
390 u32 *tx_usecs, u32 *rx_usecs);
391 void (*get_rx_max_coalesced_frames)(struct hnae3_handle *handle,
392 u32 *tx_frames, u32 *rx_frames);
393 int (*set_coalesce_usecs)(struct hnae3_handle *handle, u32 timeout);
394 int (*set_coalesce_frames)(struct hnae3_handle *handle,
395 u32 coalesce_frames);
396 void (*get_coalesce_range)(struct hnae3_handle *handle,
397 u32 *tx_frames_low, u32 *rx_frames_low,
398 u32 *tx_frames_high, u32 *rx_frames_high,
399 u32 *tx_usecs_low, u32 *rx_usecs_low,
400 u32 *tx_usecs_high, u32 *rx_usecs_high);
401
402 void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p);
403 int (*set_mac_addr)(struct hnae3_handle *handle, void *p,
404 bool is_first);
405 int (*do_ioctl)(struct hnae3_handle *handle,
406 struct ifreq *ifr, int cmd);
407 int (*add_uc_addr)(struct hnae3_handle *handle,
408 const unsigned char *addr);
409 int (*rm_uc_addr)(struct hnae3_handle *handle,
410 const unsigned char *addr);
411 int (*set_mc_addr)(struct hnae3_handle *handle, void *addr);
412 int (*add_mc_addr)(struct hnae3_handle *handle,
413 const unsigned char *addr);
414 int (*rm_mc_addr)(struct hnae3_handle *handle,
415 const unsigned char *addr);
416 void (*set_tso_stats)(struct hnae3_handle *handle, int enable);
417 void (*update_stats)(struct hnae3_handle *handle,
418 struct net_device_stats *net_stats);
419 void (*get_stats)(struct hnae3_handle *handle, u64 *data);
420 void (*get_mac_pause_stats)(struct hnae3_handle *handle, u64 *tx_cnt,
421 u64 *rx_cnt);
422 void (*get_strings)(struct hnae3_handle *handle,
423 u32 stringset, u8 *data);
424 int (*get_sset_count)(struct hnae3_handle *handle, int stringset);
425
426 void (*get_regs)(struct hnae3_handle *handle, u32 *version,
427 void *data);
428 int (*get_regs_len)(struct hnae3_handle *handle);
429
430 u32 (*get_rss_key_size)(struct hnae3_handle *handle);
431 u32 (*get_rss_indir_size)(struct hnae3_handle *handle);
432 int (*get_rss)(struct hnae3_handle *handle, u32 *indir, u8 *key,
433 u8 *hfunc);
434 int (*set_rss)(struct hnae3_handle *handle, const u32 *indir,
435 const u8 *key, const u8 hfunc);
436 int (*set_rss_tuple)(struct hnae3_handle *handle,
437 struct ethtool_rxnfc *cmd);
438 int (*get_rss_tuple)(struct hnae3_handle *handle,
439 struct ethtool_rxnfc *cmd);
440
441 int (*get_tc_size)(struct hnae3_handle *handle);
442
443 int (*get_vector)(struct hnae3_handle *handle, u16 vector_num,
444 struct hnae3_vector_info *vector_info);
445 int (*put_vector)(struct hnae3_handle *handle, int vector_num);
446 int (*map_ring_to_vector)(struct hnae3_handle *handle,
447 int vector_num,
448 struct hnae3_ring_chain_node *vr_chain);
449 int (*unmap_ring_from_vector)(struct hnae3_handle *handle,
450 int vector_num,
451 struct hnae3_ring_chain_node *vr_chain);
452
453 int (*reset_queue)(struct hnae3_handle *handle, u16 queue_id);
454 u32 (*get_fw_version)(struct hnae3_handle *handle);
455 void (*get_mdix_mode)(struct hnae3_handle *handle,
456 u8 *tp_mdix_ctrl, u8 *tp_mdix);
457
458 void (*enable_vlan_filter)(struct hnae3_handle *handle, bool enable);
459 int (*set_vlan_filter)(struct hnae3_handle *handle, __be16 proto,
460 u16 vlan_id, bool is_kill);
461 int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
462 u16 vlan, u8 qos, __be16 proto);
463 int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
464 void (*reset_event)(struct pci_dev *pdev, struct hnae3_handle *handle);
465 enum hnae3_reset_type (*get_reset_level)(struct hnae3_ae_dev *ae_dev,
466 unsigned long *addr);
467 void (*set_default_reset_request)(struct hnae3_ae_dev *ae_dev,
468 enum hnae3_reset_type rst_type);
469 void (*get_channels)(struct hnae3_handle *handle,
470 struct ethtool_channels *ch);
471 void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
472 u16 *alloc_tqps, u16 *max_rss_size);
473 int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num,
474 bool rxfh_configured);
475 void (*get_flowctrl_adv)(struct hnae3_handle *handle,
476 u32 *flowctrl_adv);
477 int (*set_led_id)(struct hnae3_handle *handle,
478 enum ethtool_phys_id_state status);
479 void (*get_link_mode)(struct hnae3_handle *handle,
480 unsigned long *supported,
481 unsigned long *advertising);
482 int (*add_fd_entry)(struct hnae3_handle *handle,
483 struct ethtool_rxnfc *cmd);
484 int (*del_fd_entry)(struct hnae3_handle *handle,
485 struct ethtool_rxnfc *cmd);
486 void (*del_all_fd_entries)(struct hnae3_handle *handle,
487 bool clear_list);
488 int (*get_fd_rule_cnt)(struct hnae3_handle *handle,
489 struct ethtool_rxnfc *cmd);
490 int (*get_fd_rule_info)(struct hnae3_handle *handle,
491 struct ethtool_rxnfc *cmd);
492 int (*get_fd_all_rules)(struct hnae3_handle *handle,
493 struct ethtool_rxnfc *cmd, u32 *rule_locs);
494 int (*restore_fd_rules)(struct hnae3_handle *handle);
495 void (*enable_fd)(struct hnae3_handle *handle, bool enable);
496 int (*add_arfs_entry)(struct hnae3_handle *handle, u16 queue_id,
497 u16 flow_id, struct flow_keys *fkeys);
498 int (*dbg_run_cmd)(struct hnae3_handle *handle, const char *cmd_buf);
499 pci_ers_result_t (*handle_hw_ras_error)(struct hnae3_ae_dev *ae_dev);
500 bool (*get_hw_reset_stat)(struct hnae3_handle *handle);
501 bool (*ae_dev_resetting)(struct hnae3_handle *handle);
502 unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
503 int (*set_gro_en)(struct hnae3_handle *handle, bool enable);
504 u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id);
505 void (*set_timer_task)(struct hnae3_handle *handle, bool enable);
506 int (*mac_connect_phy)(struct hnae3_handle *handle);
507 void (*mac_disconnect_phy)(struct hnae3_handle *handle);
508 void (*restore_vlan_table)(struct hnae3_handle *handle);
509};
510
511struct hnae3_dcb_ops {
512
513 int (*ieee_getets)(struct hnae3_handle *, struct ieee_ets *);
514 int (*ieee_setets)(struct hnae3_handle *, struct ieee_ets *);
515 int (*ieee_getpfc)(struct hnae3_handle *, struct ieee_pfc *);
516 int (*ieee_setpfc)(struct hnae3_handle *, struct ieee_pfc *);
517
518
519 u8 (*getdcbx)(struct hnae3_handle *);
520 u8 (*setdcbx)(struct hnae3_handle *, u8);
521
522 int (*setup_tc)(struct hnae3_handle *, u8, u8 *);
523};
524
525struct hnae3_ae_algo {
526 const struct hnae3_ae_ops *ops;
527 struct list_head node;
528 const struct pci_device_id *pdev_id_table;
529};
530
531#define HNAE3_INT_NAME_LEN (IFNAMSIZ + 16)
532#define HNAE3_ITR_COUNTDOWN_START 100
533
534struct hnae3_tc_info {
535 u16 tqp_offset;
536 u16 tqp_count;
537 u8 tc;
538 bool enable;
539};
540
541#define HNAE3_MAX_TC 8
542#define HNAE3_MAX_USER_PRIO 8
543struct hnae3_knic_private_info {
544 struct net_device *netdev;
545 u16 rss_size;
546 u16 req_rss_size;
547 u16 rx_buf_len;
548 u16 num_tx_desc;
549 u16 num_rx_desc;
550
551 u8 num_tc;
552 u8 prio_tc[HNAE3_MAX_USER_PRIO];
553 struct hnae3_tc_info tc_info[HNAE3_MAX_TC];
554
555 u16 num_tqps;
556 struct hnae3_queue **tqp;
557 const struct hnae3_dcb_ops *dcb_ops;
558
559 u16 int_rl_setting;
560 enum pkt_hash_types rss_type;
561};
562
563struct hnae3_roce_private_info {
564 struct net_device *netdev;
565 void __iomem *roce_io_base;
566 int base_vector;
567 int num_vectors;
568
569
570
571
572
573 unsigned long reset_state;
574 unsigned long instance_state;
575 unsigned long state;
576};
577
578struct hnae3_unic_private_info {
579 struct net_device *netdev;
580 u16 rx_buf_len;
581 u16 num_tx_desc;
582 u16 num_rx_desc;
583
584 u16 num_tqps;
585 struct hnae3_queue **tqp;
586};
587
588#define HNAE3_SUPPORT_APP_LOOPBACK BIT(0)
589#define HNAE3_SUPPORT_PHY_LOOPBACK BIT(1)
590#define HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK BIT(2)
591#define HNAE3_SUPPORT_VF BIT(3)
592#define HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK BIT(4)
593
594#define HNAE3_USER_UPE BIT(0)
595#define HNAE3_USER_MPE BIT(1)
596#define HNAE3_BPE BIT(2)
597#define HNAE3_OVERFLOW_UPE BIT(3)
598#define HNAE3_OVERFLOW_MPE BIT(4)
599#define HNAE3_VLAN_FLTR BIT(5)
600#define HNAE3_UPE (HNAE3_USER_UPE | HNAE3_OVERFLOW_UPE)
601#define HNAE3_MPE (HNAE3_USER_MPE | HNAE3_OVERFLOW_MPE)
602
603struct hnae3_handle {
604 struct hnae3_client *client;
605 struct pci_dev *pdev;
606 void *priv;
607 struct hnae3_ae_algo *ae_algo;
608 u64 flags;
609
610 union {
611 struct net_device *netdev;
612 struct hnae3_knic_private_info kinfo;
613 struct hnae3_unic_private_info uinfo;
614 struct hnae3_roce_private_info rinfo;
615 };
616
617 u32 numa_node_mask;
618
619 enum hnae3_port_base_vlan_state port_base_vlan_state;
620
621 u8 netdev_flags;
622 struct dentry *hnae3_dbgfs;
623
624
625 u32 msg_enable;
626};
627
628#define hnae3_set_field(origin, mask, shift, val) \
629 do { \
630 (origin) &= (~(mask)); \
631 (origin) |= ((val) << (shift)) & (mask); \
632 } while (0)
633#define hnae3_get_field(origin, mask, shift) (((origin) & (mask)) >> (shift))
634
635#define hnae3_set_bit(origin, shift, val) \
636 hnae3_set_field((origin), (0x1 << (shift)), (shift), (val))
637#define hnae3_get_bit(origin, shift) \
638 hnae3_get_field((origin), (0x1 << (shift)), (shift))
639
640int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev);
641void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev);
642
643void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo);
644void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo);
645
646void hnae3_unregister_client(struct hnae3_client *client);
647int hnae3_register_client(struct hnae3_client *client);
648
649void hnae3_set_client_init_flag(struct hnae3_client *client,
650 struct hnae3_ae_dev *ae_dev,
651 unsigned int inited);
652#endif
653