2a79e6e5457f74297bad505fccea9bc0a7c0523d
[dpdk.git] / drivers / net / hns3 / hns3_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2019 Hisilicon Limited.
3  */
4
5 #ifndef _HNS3_ETHDEV_H_
6 #define _HNS3_ETHDEV_H_
7
8 #include <sys/time.h>
9 #include <rte_alarm.h>
10
11 #include "hns3_cmd.h"
12 #include "hns3_mbx.h"
13 #include "hns3_rss.h"
14 #include "hns3_fdir.h"
15
16 /* Vendor ID */
17 #define PCI_VENDOR_ID_HUAWEI                    0x19e5
18
19 /* Device IDs */
20 #define HNS3_DEV_ID_GE                          0xA220
21 #define HNS3_DEV_ID_25GE                        0xA221
22 #define HNS3_DEV_ID_25GE_RDMA                   0xA222
23 #define HNS3_DEV_ID_50GE_RDMA                   0xA224
24 #define HNS3_DEV_ID_100G_RDMA_MACSEC            0xA226
25 #define HNS3_DEV_ID_100G_VF                     0xA22E
26 #define HNS3_DEV_ID_100G_RDMA_PFC_VF            0xA22F
27
28 #define HNS3_UC_MACADDR_NUM             128
29 #define HNS3_VF_UC_MACADDR_NUM          48
30 #define HNS3_MC_MACADDR_NUM             128
31
32 #define HNS3_MAX_BD_SIZE                65535
33 #define HNS3_MAX_TX_BD_PER_PKT          8
34 #define HNS3_MAX_FRAME_LEN              9728
35 #define HNS3_MIN_FRAME_LEN              64
36 #define HNS3_VLAN_TAG_SIZE              4
37 #define HNS3_DEFAULT_RX_BUF_LEN         2048
38
39 #define HNS3_ETH_OVERHEAD \
40         (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + HNS3_VLAN_TAG_SIZE * 2)
41 #define HNS3_PKTLEN_TO_MTU(pktlen)      ((pktlen) - HNS3_ETH_OVERHEAD)
42 #define HNS3_MAX_MTU    (HNS3_MAX_FRAME_LEN - HNS3_ETH_OVERHEAD)
43 #define HNS3_DEFAULT_MTU                1500UL
44 #define HNS3_DEFAULT_FRAME_LEN          (HNS3_DEFAULT_MTU + HNS3_ETH_OVERHEAD)
45
46 #define HNS3_4_TCS                      4
47 #define HNS3_8_TCS                      8
48
49 #define HNS3_MAX_PF_NUM                 8
50 #define HNS3_UMV_TBL_SIZE               3072
51 #define HNS3_DEFAULT_UMV_SPACE_PER_PF \
52         (HNS3_UMV_TBL_SIZE / HNS3_MAX_PF_NUM)
53
54 #define HNS3_PF_CFG_BLOCK_SIZE          32
55 #define HNS3_PF_CFG_DESC_NUM \
56         (HNS3_PF_CFG_BLOCK_SIZE / HNS3_CFG_RD_LEN_BYTES)
57
58 #define HNS3_DEFAULT_ENABLE_PFC_NUM     0
59
60 #define HNS3_INTR_UNREG_FAIL_RETRY_CNT  5
61 #define HNS3_INTR_UNREG_FAIL_DELAY_MS   500
62
63 #define HNS3_QUIT_RESET_CNT             10
64 #define HNS3_QUIT_RESET_DELAY_MS        100
65
66 #define HNS3_POLL_RESPONE_MS            1
67
68 #define HNS3_MAX_USER_PRIO              8
69 #define HNS3_PG_NUM                     4
70 enum hns3_fc_mode {
71         HNS3_FC_NONE,
72         HNS3_FC_RX_PAUSE,
73         HNS3_FC_TX_PAUSE,
74         HNS3_FC_FULL,
75         HNS3_FC_DEFAULT
76 };
77
78 #define HNS3_SCH_MODE_SP        0
79 #define HNS3_SCH_MODE_DWRR      1
80 struct hns3_pg_info {
81         uint8_t pg_id;
82         uint8_t pg_sch_mode;  /* 0: sp; 1: dwrr */
83         uint8_t tc_bit_map;
84         uint32_t bw_limit;
85         uint8_t tc_dwrr[HNS3_MAX_TC_NUM];
86 };
87
88 struct hns3_tc_info {
89         uint8_t tc_id;
90         uint8_t tc_sch_mode;  /* 0: sp; 1: dwrr */
91         uint8_t pgid;
92         uint32_t bw_limit;
93         uint8_t up_to_tc_map; /* user priority maping on the TC */
94 };
95
96 struct hns3_dcb_info {
97         uint8_t num_tc;
98         uint8_t num_pg;     /* It must be 1 if vNET-Base schd */
99         uint8_t pg_dwrr[HNS3_PG_NUM];
100         uint8_t prio_tc[HNS3_MAX_USER_PRIO];
101         struct hns3_pg_info pg_info[HNS3_PG_NUM];
102         struct hns3_tc_info tc_info[HNS3_MAX_TC_NUM];
103         uint8_t hw_pfc_map; /* Allow for packet drop or not on this TC */
104         uint8_t pfc_en; /* Pfc enabled or not for user priority */
105 };
106
107 enum hns3_fc_status {
108         HNS3_FC_STATUS_NONE,
109         HNS3_FC_STATUS_MAC_PAUSE,
110         HNS3_FC_STATUS_PFC,
111 };
112
113 struct hns3_tc_queue_info {
114         uint8_t tqp_offset;     /* TQP offset from base TQP */
115         uint8_t tqp_count;      /* Total TQPs */
116         uint8_t tc;             /* TC index */
117         bool enable;            /* If this TC is enable or not */
118 };
119
120 struct hns3_cfg {
121         uint8_t vmdq_vport_num;
122         uint8_t tc_num;
123         uint16_t tqp_desc_num;
124         uint16_t rx_buf_len;
125         uint16_t rss_size_max;
126         uint8_t phy_addr;
127         uint8_t media_type;
128         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
129         uint8_t default_speed;
130         uint32_t numa_node_map;
131         uint8_t speed_ability;
132         uint16_t umv_space;
133 };
134
135 /* mac media type */
136 enum hns3_media_type {
137         HNS3_MEDIA_TYPE_UNKNOWN,
138         HNS3_MEDIA_TYPE_FIBER,
139         HNS3_MEDIA_TYPE_COPPER,
140         HNS3_MEDIA_TYPE_BACKPLANE,
141         HNS3_MEDIA_TYPE_NONE,
142 };
143
144 struct hns3_mac {
145         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
146         bool default_addr_setted; /* whether default addr(mac_addr) is setted */
147         uint8_t media_type;
148         uint8_t phy_addr;
149         uint8_t link_duplex  : 1; /* ETH_LINK_[HALF/FULL]_DUPLEX */
150         uint8_t link_autoneg : 1; /* ETH_LINK_[AUTONEG/FIXED] */
151         uint8_t link_status  : 1; /* ETH_LINK_[DOWN/UP] */
152         uint32_t link_speed;      /* ETH_SPEED_NUM_ */
153 };
154
155
156 /* Primary process maintains driver state in main thread.
157  *
158  * +---------------+
159  * | UNINITIALIZED |<-----------+
160  * +---------------+            |
161  *      |.eth_dev_init          |.eth_dev_uninit
162  *      V                       |
163  * +---------------+------------+
164  * |  INITIALIZED  |
165  * +---------------+<-----------<---------------+
166  *      |.dev_configure         |               |
167  *      V                       |failed         |
168  * +---------------+------------+               |
169  * |  CONFIGURING  |                            |
170  * +---------------+----+                       |
171  *      |success        |                       |
172  *      |               |               +---------------+
173  *      |               |               |    CLOSING    |
174  *      |               |               +---------------+
175  *      |               |                       ^
176  *      V               |.dev_configure         |
177  * +---------------+----+                       |.dev_close
178  * |  CONFIGURED   |----------------------------+
179  * +---------------+<-----------+
180  *      |.dev_start             |
181  *      V                       |
182  * +---------------+            |
183  * |   STARTING    |------------^
184  * +---------------+ failed     |
185  *      |success                |
186  *      |               +---------------+
187  *      |               |   STOPPING    |
188  *      |               +---------------+
189  *      |                       ^
190  *      V                       |.dev_stop
191  * +---------------+------------+
192  * |    STARTED    |
193  * +---------------+
194  */
195 enum hns3_adapter_state {
196         HNS3_NIC_UNINITIALIZED = 0,
197         HNS3_NIC_INITIALIZED,
198         HNS3_NIC_CONFIGURING,
199         HNS3_NIC_CONFIGURED,
200         HNS3_NIC_STARTING,
201         HNS3_NIC_STARTED,
202         HNS3_NIC_STOPPING,
203         HNS3_NIC_CLOSING,
204         HNS3_NIC_CLOSED,
205         HNS3_NIC_REMOVED,
206         HNS3_NIC_NSTATES
207 };
208
209 /* Reset various stages, execute in order */
210 enum hns3_reset_stage {
211         /* Stop query services, stop transceiver, disable MAC */
212         RESET_STAGE_DOWN,
213         /* Clear reset completion flags, disable send command */
214         RESET_STAGE_PREWAIT,
215         /* Inform IMP to start resetting */
216         RESET_STAGE_REQ_HW_RESET,
217         /* Waiting for hardware reset to complete */
218         RESET_STAGE_WAIT,
219         /* Reinitialize hardware */
220         RESET_STAGE_DEV_INIT,
221         /* Restore user settings and enable MAC */
222         RESET_STAGE_RESTORE,
223         /* Restart query services, start transceiver */
224         RESET_STAGE_DONE,
225         /* Not in reset state */
226         RESET_STAGE_NONE,
227 };
228
229 enum hns3_reset_level {
230         HNS3_NONE_RESET,
231         HNS3_VF_FUNC_RESET, /* A VF function reset */
232         /*
233          * All VFs under a PF perform function reset.
234          * Kernel PF driver use mailbox to inform DPDK VF to do reset, the value
235          * of the reset level and the one defined in kernel driver should be
236          * same.
237          */
238         HNS3_VF_PF_FUNC_RESET = 2,
239         /*
240          * All VFs under a PF perform FLR reset.
241          * Kernel PF driver use mailbox to inform DPDK VF to do reset, the value
242          * of the reset level and the one defined in kernel driver should be
243          * same.
244          */
245         HNS3_VF_FULL_RESET = 3,
246         HNS3_FLR_RESET,     /* A VF perform FLR reset */
247         /* All VFs under the rootport perform a global or IMP reset */
248         HNS3_VF_RESET,
249         HNS3_FUNC_RESET,    /* A PF function reset */
250         /* All PFs under the rootport perform a global reset */
251         HNS3_GLOBAL_RESET,
252         HNS3_IMP_RESET,     /* All PFs under the rootport perform a IMP reset */
253         HNS3_MAX_RESET
254 };
255
256 enum hns3_wait_result {
257         HNS3_WAIT_UNKNOWN,
258         HNS3_WAIT_REQUEST,
259         HNS3_WAIT_SUCCESS,
260         HNS3_WAIT_TIMEOUT
261 };
262
263 #define HNS3_RESET_SYNC_US 100000
264
265 struct hns3_reset_stats {
266         uint64_t request_cnt; /* Total request reset times */
267         uint64_t global_cnt;  /* Total GLOBAL reset times */
268         uint64_t imp_cnt;     /* Total IMP reset times */
269         uint64_t exec_cnt;    /* Total reset executive times */
270         uint64_t success_cnt; /* Total reset successful times */
271         uint64_t fail_cnt;    /* Total reset failed times */
272         uint64_t merge_cnt;   /* Total merged in high reset times */
273 };
274
275 typedef bool (*check_completion_func)(struct hns3_hw *hw);
276
277 struct hns3_wait_data {
278         void *hns;
279         uint64_t end_ms;
280         uint64_t interval;
281         int16_t count;
282         enum hns3_wait_result result;
283         check_completion_func check_completion;
284 };
285
286 struct hns3_reset_ops {
287         void (*reset_service)(void *arg);
288         int (*stop_service)(struct hns3_adapter *hns);
289         int (*prepare_reset)(struct hns3_adapter *hns);
290         int (*wait_hardware_ready)(struct hns3_adapter *hns);
291         int (*reinit_dev)(struct hns3_adapter *hns);
292         int (*restore_conf)(struct hns3_adapter *hns);
293         int (*start_service)(struct hns3_adapter *hns);
294 };
295
296 enum hns3_schedule {
297         SCHEDULE_NONE,
298         SCHEDULE_PENDING,
299         SCHEDULE_REQUESTED,
300         SCHEDULE_DEFERRED,
301 };
302
303 struct hns3_reset_data {
304         enum hns3_reset_stage stage;
305         rte_atomic16_t schedule;
306         /* Reset flag, covering the entire reset process */
307         rte_atomic16_t resetting;
308         /* Used to disable sending cmds during reset */
309         rte_atomic16_t disable_cmd;
310         /* The reset level being processed */
311         enum hns3_reset_level level;
312         /* Reset level set, each bit represents a reset level */
313         uint64_t pending;
314         /* Request reset level set, from interrupt or mailbox */
315         uint64_t request;
316         int attempts; /* Reset failure retry */
317         int retries;  /* Timeout failure retry in reset_post */
318         /*
319          * At the time of global or IMP reset, the command cannot be sent to
320          * stop the tx/rx queues. Tx/Rx queues may be access mbuf during the
321          * reset process, so the mbuf is required to be released after the reset
322          * is completed.The mbuf_deferred_free is used to mark whether mbuf
323          * needs to be released.
324          */
325         bool mbuf_deferred_free;
326         struct timeval start_time;
327         struct hns3_reset_stats stats;
328         const struct hns3_reset_ops *ops;
329         struct hns3_wait_data *wait_data;
330 };
331
332 struct hns3_hw {
333         struct rte_eth_dev_data *data;
334         void *io_base;
335         struct hns3_cmq cmq;
336         struct hns3_mbx_resp_status mbx_resp; /* mailbox response */
337         struct hns3_mbx_arq_ring arq;         /* mailbox async rx queue */
338         pthread_t irq_thread_id;
339         struct hns3_mac mac;
340         unsigned int secondary_cnt; /* Number of secondary processes init'd. */
341         uint32_t fw_version;
342
343         uint16_t num_msi;
344         uint16_t total_tqps_num;    /* total task queue pairs of this PF */
345         uint16_t tqps_num;          /* num task queue pairs of this function */
346         uint16_t rss_size_max;      /* HW defined max RSS task queue */
347         uint16_t rx_buf_len;
348         uint16_t num_tx_desc;       /* desc num of per tx queue */
349         uint16_t num_rx_desc;       /* desc num of per rx queue */
350
351         struct rte_ether_addr mc_addrs[HNS3_MC_MACADDR_NUM];
352         int mc_addrs_num; /* Multicast mac addresses number */
353
354         /* The configuration info of RSS */
355         struct hns3_rss_conf rss_info;
356
357         uint8_t num_tc;             /* Total number of enabled TCs */
358         uint8_t hw_tc_map;
359         enum hns3_fc_mode current_mode;
360         enum hns3_fc_mode requested_mode;
361         struct hns3_dcb_info dcb_info;
362         enum hns3_fc_status current_fc_status; /* current flow control status */
363         struct hns3_tc_queue_info tc_queue[HNS3_MAX_TC_NUM];
364         uint16_t alloc_tqps;
365         uint16_t alloc_rss_size;    /* Queue number per TC */
366
367         uint32_t flag;
368         /*
369          * PMD setup and configuration is not thread safe. Since it is not
370          * performance sensitive, it is better to guarantee thread-safety
371          * and add device level lock. Adapter control operations which
372          * change its state should acquire the lock.
373          */
374         rte_spinlock_t lock;
375         enum hns3_adapter_state adapter_state;
376         struct hns3_reset_data reset;
377 };
378
379 #define HNS3_FLAG_TC_BASE_SCH_MODE              1
380 #define HNS3_FLAG_VNET_BASE_SCH_MODE            2
381
382 struct hns3_err_msix_intr_stats {
383         uint64_t mac_afifo_tnl_intr_cnt;
384         uint64_t ppu_mpf_abnormal_intr_st2_cnt;
385         uint64_t ssu_port_based_pf_intr_cnt;
386         uint64_t ppp_pf_abnormal_intr_cnt;
387         uint64_t ppu_pf_abnormal_intr_cnt;
388 };
389
390 /* vlan entry information. */
391 struct hns3_user_vlan_table {
392         LIST_ENTRY(hns3_user_vlan_table) next;
393         bool hd_tbl_status;
394         uint16_t vlan_id;
395 };
396
397 struct hns3_port_base_vlan_config {
398         uint16_t state;
399         uint16_t pvid;
400 };
401
402 /* Vlan tag configuration for RX direction */
403 struct hns3_rx_vtag_cfg {
404         uint8_t rx_vlan_offload_en; /* Whether enable rx vlan offload */
405         uint8_t strip_tag1_en;      /* Whether strip inner vlan tag */
406         uint8_t strip_tag2_en;      /* Whether strip outer vlan tag */
407         uint8_t vlan1_vlan_prionly; /* Inner VLAN Tag up to descriptor Enable */
408         uint8_t vlan2_vlan_prionly; /* Outer VLAN Tag up to descriptor Enable */
409 };
410
411 /* Vlan tag configuration for TX direction */
412 struct hns3_tx_vtag_cfg {
413         bool accept_tag1;           /* Whether accept tag1 packet from host */
414         bool accept_untag1;         /* Whether accept untag1 packet from host */
415         bool accept_tag2;
416         bool accept_untag2;
417         bool insert_tag1_en;        /* Whether insert inner vlan tag */
418         bool insert_tag2_en;        /* Whether insert outer vlan tag */
419         uint16_t default_tag1;      /* The default inner vlan tag to insert */
420         uint16_t default_tag2;      /* The default outer vlan tag to insert */
421 };
422
423 struct hns3_vtag_cfg {
424         struct hns3_rx_vtag_cfg rx_vcfg;
425         struct hns3_tx_vtag_cfg tx_vcfg;
426 };
427
428 /* Request types for IPC. */
429 enum hns3_mp_req_type {
430         HNS3_MP_REQ_START_RXTX = 1,
431         HNS3_MP_REQ_STOP_RXTX,
432         HNS3_MP_REQ_MAX
433 };
434
435 /* Pameters for IPC. */
436 struct hns3_mp_param {
437         enum hns3_mp_req_type type;
438         int port_id;
439         int result;
440 };
441
442 /* Request timeout for IPC. */
443 #define HNS3_MP_REQ_TIMEOUT_SEC 5
444
445 /* Key string for IPC. */
446 #define HNS3_MP_NAME "net_hns3_mp"
447
448 struct hns3_pf {
449         struct hns3_adapter *adapter;
450         bool is_main_pf;
451
452         uint32_t pkt_buf_size; /* Total pf buf size for tx/rx */
453         uint32_t tx_buf_size; /* Tx buffer size for each TC */
454         uint32_t dv_buf_size; /* Dv buffer size for each TC */
455
456         uint16_t mps; /* Max packet size */
457
458         uint8_t tx_sch_mode;
459         uint8_t tc_max; /* max number of tc driver supported */
460         uint8_t local_max_tc; /* max number of local tc */
461         uint8_t pfc_max;
462         uint8_t prio_tc[HNS3_MAX_USER_PRIO]; /* TC indexed by prio */
463         uint16_t pause_time;
464         bool support_fc_autoneg;       /* support FC autonegotiate */
465
466         uint16_t wanted_umv_size;
467         uint16_t max_umv_size;
468         uint16_t used_umv_size;
469
470         /* Statistics information for abnormal interrupt */
471         struct hns3_err_msix_intr_stats abn_int_stats;
472
473         bool support_sfp_query;
474
475         struct hns3_vtag_cfg vtag_config;
476         struct hns3_port_base_vlan_config port_base_vlan_cfg;
477         LIST_HEAD(vlan_tbl, hns3_user_vlan_table) vlan_list;
478
479         struct hns3_fdir_info fdir; /* flow director info */
480         LIST_HEAD(counters, hns3_flow_counter) flow_counters;
481 };
482
483 struct hns3_vf {
484         struct hns3_adapter *adapter;
485 };
486
487 struct hns3_adapter {
488         struct hns3_hw hw;
489
490         /* Specific for PF or VF */
491         bool is_vf; /* false - PF, true - VF */
492         union {
493                 struct hns3_pf pf;
494                 struct hns3_vf vf;
495         };
496 };
497
498 #define HNS3_DEV_SUPPORT_DCB_B                  0x0
499
500 #define hns3_dev_dcb_supported(hw) \
501         hns3_get_bit((hw)->flag, HNS3_DEV_SUPPORT_DCB_B)
502
503 #define HNS3_DEV_PRIVATE_TO_HW(adapter) \
504         (&((struct hns3_adapter *)adapter)->hw)
505 #define HNS3_DEV_PRIVATE_TO_ADAPTER(adapter) \
506         ((struct hns3_adapter *)adapter)
507 #define HNS3_DEV_PRIVATE_TO_PF(adapter) \
508         (&((struct hns3_adapter *)adapter)->pf)
509 #define HNS3VF_DEV_PRIVATE_TO_VF(adapter) \
510         (&((struct hns3_adapter *)adapter)->vf)
511 #define HNS3_DEV_HW_TO_ADAPTER(hw) \
512         container_of(hw, struct hns3_adapter, hw)
513
514 #define hns3_set_field(origin, mask, shift, val) \
515         do { \
516                 (origin) &= (~(mask)); \
517                 (origin) |= ((val) << (shift)) & (mask); \
518         } while (0)
519 #define hns3_get_field(origin, mask, shift) \
520         (((origin) & (mask)) >> (shift))
521 #define hns3_set_bit(origin, shift, val) \
522         hns3_set_field((origin), (0x1UL << (shift)), (shift), (val))
523 #define hns3_get_bit(origin, shift) \
524         hns3_get_field((origin), (0x1UL << (shift)), (shift))
525
526 /*
527  * upper_32_bits - return bits 32-63 of a number
528  * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
529  * the "right shift count >= width of type" warning when that quantity is
530  * 32-bits.
531  */
532 #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16))
533
534 /* lower_32_bits - return bits 0-31 of a number */
535 #define lower_32_bits(n) ((uint32_t)(n))
536
537 #define BIT(nr) (1UL << (nr))
538
539 #define BITS_PER_LONG   (__SIZEOF_LONG__ * 8)
540 #define GENMASK(h, l) \
541         (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
542
543 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
544 #define rounddown(x, y) ((x) - ((x) % (y)))
545
546 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
547
548 #define max_t(type, x, y) ({                    \
549         type __max1 = (x);                      \
550         type __max2 = (y);                      \
551         __max1 > __max2 ? __max1 : __max2; })
552
553 static inline void hns3_write_reg(void *base, uint32_t reg, uint32_t value)
554 {
555         rte_write32(value, (volatile void *)((char *)base + reg));
556 }
557
558 static inline uint32_t hns3_read_reg(void *base, uint32_t reg)
559 {
560         return rte_read32((volatile void *)((char *)base + reg));
561 }
562
563 #define hns3_write_dev(a, reg, value) \
564         hns3_write_reg((a)->io_base, (reg), (value))
565
566 #define hns3_read_dev(a, reg) \
567         hns3_read_reg((a)->io_base, (reg))
568
569 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
570
571 #define NEXT_ITEM_OF_ACTION(act, actions, index)                        \
572         do {                                                            \
573                 act = (actions) + (index);                              \
574                 while (act->type == RTE_FLOW_ACTION_TYPE_VOID) {        \
575                         (index)++;                                      \
576                         act = actions + index;                          \
577                 }                                                       \
578         } while (0)
579
580 #define MSEC_PER_SEC              1000L
581 #define USEC_PER_MSEC             1000L
582
583 static inline uint64_t
584 get_timeofday_ms(void)
585 {
586         struct timeval tv;
587
588         (void)gettimeofday(&tv, NULL);
589
590         return (uint64_t)tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC;
591 }
592
593 static inline uint64_t
594 hns3_atomic_test_bit(unsigned int nr, volatile uint64_t *addr)
595 {
596         uint64_t res;
597
598         res = (__atomic_load_n(addr, __ATOMIC_RELAXED) & (1UL << nr)) != 0;
599         return res;
600 }
601
602 static inline void
603 hns3_atomic_set_bit(unsigned int nr, volatile uint64_t *addr)
604 {
605         __atomic_fetch_or(addr, (1UL << nr), __ATOMIC_RELAXED);
606 }
607
608 static inline void
609 hns3_atomic_clear_bit(unsigned int nr, volatile uint64_t *addr)
610 {
611         __atomic_fetch_and(addr, ~(1UL << nr), __ATOMIC_RELAXED);
612 }
613
614 static inline int64_t
615 hns3_test_and_clear_bit(unsigned int nr, volatile uint64_t *addr)
616 {
617         uint64_t mask = (1UL << nr);
618
619         return __atomic_fetch_and(addr, ~mask, __ATOMIC_RELAXED) & mask;
620 }
621
622 int hns3_buffer_alloc(struct hns3_hw *hw);
623 int hns3_config_gro(struct hns3_hw *hw, bool en);
624 int hns3_dev_filter_ctrl(struct rte_eth_dev *dev,
625                          enum rte_filter_type filter_type,
626                          enum rte_filter_op filter_op, void *arg);
627
628 #endif /* _HNS3_ETHDEV_H_ */