net/bnxt: remove unnecessary comment
[dpdk.git] / drivers / net / bnxt / bnxt_cpr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 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 NQ_CMP_VALID(nqcmp, raw_cons, ring)             \
23         (!!((nqcmp)->v & rte_cpu_to_le_32(NQ_CN_V)) ==  \
24          !((raw_cons) & ((ring)->ring_size)))
25
26 #define CMP_TYPE(cmp)                                           \
27         (((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK)
28
29 /* Get completion length from completion type, in 16-byte units. */
30 #define CMP_LEN(cmp_type) (((cmp_type) & 1) + 1)
31
32
33 #define ADV_RAW_CMP(idx, n)     ((idx) + (n))
34 #define NEXT_RAW_CMP(idx)       ADV_RAW_CMP(idx, 1)
35 #define RING_CMP(ring, idx)     ((idx) & (ring)->ring_mask)
36 #define RING_CMPL(ring_mask, idx)       ((idx) & (ring_mask))
37 #define NEXT_CMP(idx)           RING_CMP(ADV_RAW_CMP(idx, 1))
38 #define FLIP_VALID(cons, mask, val)     ((cons) >= (mask) ? !(val) : (val))
39
40 #define DB_CP_REARM_FLAGS       (DB_KEY_CP | DB_IDX_VALID)
41 #define DB_CP_FLAGS             (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
42
43 #define NEXT_CMPL(cpr, idx, v, inc)     do { \
44         (idx) += (inc); \
45         if (unlikely((idx) >= (cpr)->cp_ring_struct->ring_size)) { \
46                 (v) = !(v); \
47                 (idx) = 0; \
48         } \
49 } while (0)
50 #define B_CP_DB_REARM(cpr, raw_cons)                                    \
51         rte_write32((DB_CP_REARM_FLAGS |                                \
52                     DB_RING_IDX(&((cpr)->cp_db), raw_cons)),            \
53                     ((cpr)->cp_db.doorbell))
54
55 #define B_CP_DB_ARM(cpr)        rte_write32((DB_KEY_CP),                \
56                                             ((cpr)->cp_db.doorbell))
57
58 #define B_CP_DB_DISARM(cpr)     (*(uint32_t *)((cpr)->cp_db.doorbell) = \
59                                  DB_KEY_CP | DB_IRQ_DIS)
60
61 #define B_CP_DB_IDX_ARM(cpr, cons)                                      \
62                 (*(uint32_t *)((cpr)->cp_db.doorbell) = (DB_CP_REARM_FLAGS | \
63                                 (cons)))
64
65 #define B_CP_DB_IDX_DISARM(cpr, cons)   do {                            \
66                 rte_smp_wmb();                                          \
67                 (*(uint32_t *)((cpr)->cp_db.doorbell) = (DB_CP_FLAGS |  \
68                                 (cons));                                \
69 } while (0)
70 #define B_CP_DIS_DB(cpr, raw_cons)                                      \
71         rte_write32_relaxed((DB_CP_FLAGS |                              \
72                     DB_RING_IDX(&((cpr)->cp_db), raw_cons)),            \
73                     ((cpr)->cp_db.doorbell))
74
75 #define B_CP_DB(cpr, raw_cons, ring_mask)                               \
76         rte_write32((DB_CP_FLAGS |                                      \
77                     RING_CMPL((ring_mask), raw_cons)),  \
78                     ((cpr)->cp_db.doorbell))
79
80 struct bnxt_db_info {
81         void                    *doorbell;
82         union {
83                 uint64_t        db_key64;
84                 uint32_t        db_key32;
85         };
86         bool                    db_64;
87         uint32_t                db_ring_mask;
88         uint32_t                db_epoch_mask;
89         uint32_t                db_epoch_shift;
90 };
91
92 #define DB_EPOCH(db, idx)       (((idx) & (db)->db_epoch_mask) <<       \
93                                  ((db)->db_epoch_shift))
94 #define DB_RING_IDX(db, idx)    (((idx) & (db)->db_ring_mask) |         \
95                                  DB_EPOCH(db, idx))
96
97 struct bnxt_ring;
98 struct bnxt_cp_ring_info {
99         uint32_t                cp_raw_cons;
100
101         struct cmpl_base        *cp_desc_ring;
102         struct bnxt_db_info     cp_db;
103         rte_iova_t              cp_desc_mapping;
104
105         struct ctx_hw_stats     *hw_stats;
106         rte_iova_t              hw_stats_map;
107         uint32_t                hw_stats_ctx_id;
108
109         struct bnxt_ring        *cp_ring_struct;
110         bool                    valid;
111 };
112
113 #define RX_CMP_L2_ERRORS                                                \
114         (RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR)
115
116 struct bnxt;
117 void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp);
118 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp);
119 int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp);
120 void bnxt_dev_reset_and_resume(void *arg);
121 void bnxt_wait_for_device_shutdown(struct bnxt *bp);
122
123 #define EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL     \
124         HWRM_ASYNC_EVENT_CMPL_RESET_NOTIFY_EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL
125 #define EVENT_DATA1_REASON_CODE_MASK                   \
126         HWRM_ASYNC_EVENT_CMPL_RESET_NOTIFY_EVENT_DATA1_REASON_CODE_MASK
127
128 #define EVENT_DATA1_FLAGS_MASK                         \
129         HWRM_ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_MASK
130
131 #define EVENT_DATA1_FLAGS_MASTER_FUNC                  \
132         HWRM_ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_MASTER_FUNC
133
134 #define EVENT_DATA1_FLAGS_RECOVERY_ENABLED             \
135         HWRM_ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_RECOVERY_ENABLED
136
137 bool bnxt_is_recovery_enabled(struct bnxt *bp);
138 bool bnxt_is_master_func(struct bnxt *bp);
139
140 void bnxt_stop_rxtx(struct bnxt *bp);
141 #endif