77a22d24180c9af1c52a9b8e28cd8832b112fb01
[dpdk.git] / drivers / net / bnxt / bnxt_cpr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BNXT_CPR_H_
7 #define _BNXT_CPR_H_
8 #include <stdbool.h>
9
10 #include <rte_io.h>
11
12 struct bnxt_db_info;
13
14 #define CMP_VALID(cmp, raw_cons, ring)                                  \
15         (!!(rte_le_to_cpu_32(((struct cmpl_base *)(cmp))->info3_v) &    \
16             CMPL_BASE_V) == !((raw_cons) & ((ring)->ring_size)))
17
18 #define CMPL_VALID(cmp, v)                                              \
19         (!!(rte_le_to_cpu_32(((struct cmpl_base *)(cmp))->info3_v) &    \
20             CMPL_BASE_V) == !(v))
21
22 #define CMP_TYPE(cmp)                                           \
23         (((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK)
24
25 #define ADV_RAW_CMP(idx, n)     ((idx) + (n))
26 #define NEXT_RAW_CMP(idx)       ADV_RAW_CMP(idx, 1)
27 #define RING_CMP(ring, idx)     ((idx) & (ring)->ring_mask)
28 #define RING_CMPL(ring_mask, idx)       ((idx) & (ring_mask))
29 #define NEXT_CMP(idx)           RING_CMP(ADV_RAW_CMP(idx, 1))
30 #define FLIP_VALID(cons, mask, val)     ((cons) >= (mask) ? !(val) : (val))
31
32 #define DB_CP_REARM_FLAGS       (DB_KEY_CP | DB_IDX_VALID)
33 #define DB_CP_FLAGS             (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
34
35 #define NEXT_CMPL(cpr, idx, v, inc)     do { \
36         (idx) += (inc); \
37         if (unlikely((idx) >= (cpr)->cp_ring_struct->ring_size)) { \
38                 (v) = !(v); \
39                 (idx) = 0; \
40         } \
41 } while (0)
42 #define B_CP_DB_REARM(cpr, raw_cons)                                    \
43         rte_write32((DB_CP_REARM_FLAGS |                                \
44                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
45                     ((cpr)->cp_db.doorbell))
46
47 #define B_CP_DB_ARM(cpr)        rte_write32((DB_KEY_CP),                \
48                                             ((cpr)->cp_db.doorbell))
49
50 #define B_CP_DB_DISARM(cpr)     (*(uint32_t *)((cpr)->cp_db.doorbell) = \
51                                  DB_KEY_CP | DB_IRQ_DIS)
52
53 #define B_CP_DB_IDX_ARM(cpr, cons)                                      \
54                 (*(uint32_t *)((cpr)->cp_db.doorbell) = (DB_CP_REARM_FLAGS | \
55                                 (cons)))
56
57 #define B_CP_DB_IDX_DISARM(cpr, cons)   do {                            \
58                 rte_smp_wmb();                                          \
59                 (*(uint32_t *)((cpr)->cp_db.doorbell) = (DB_CP_FLAGS |  \
60                                 (cons));                                \
61 } while (0)
62 #define B_CP_DIS_DB(cpr, raw_cons)                                      \
63         rte_write32((DB_CP_FLAGS |                                      \
64                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
65                     ((cpr)->cp_db.doorbell))
66
67 #define B_CP_DB(cpr, raw_cons, ring_mask)                               \
68         rte_write32((DB_CP_FLAGS |                                      \
69                     RING_CMPL((ring_mask), raw_cons)),  \
70                     ((cpr)->cp_db.doorbell))
71
72 struct bnxt_db_info {
73         void            *doorbell;
74         uint32_t        db_key32;
75 };
76
77 struct bnxt_ring;
78 struct bnxt_cp_ring_info {
79         uint32_t                cp_raw_cons;
80
81         struct cmpl_base        *cp_desc_ring;
82         struct bnxt_db_info     cp_db;
83         rte_iova_t              cp_desc_mapping;
84
85         struct ctx_hw_stats     *hw_stats;
86         rte_iova_t              hw_stats_map;
87         uint32_t                hw_stats_ctx_id;
88
89         struct bnxt_ring        *cp_ring_struct;
90         uint16_t                cp_cons;
91         bool                    valid;
92 };
93
94 #define RX_CMP_L2_ERRORS                                                \
95         (RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR)
96
97 struct bnxt;
98 void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp);
99 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp);
100 int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp);
101
102 #endif