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