net/bnxt: fix endianness in ring macros
[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 #define CMP_VALID(cmp, raw_cons, ring)                                  \
13         (!!(rte_le_to_cpu_32(((struct cmpl_base *)(cmp))->info3_v) &    \
14             CMPL_BASE_V) == !((raw_cons) & ((ring)->ring_size)))
15
16 #define CMPL_VALID(cmp, v)                                              \
17         (!!(rte_le_to_cpu_32(((struct cmpl_base *)(cmp))->info3_v) &    \
18             CMPL_BASE_V) == !(v))
19
20 #define CMP_TYPE(cmp)                                           \
21         (((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK)
22
23 #define ADV_RAW_CMP(idx, n)     ((idx) + (n))
24 #define NEXT_RAW_CMP(idx)       ADV_RAW_CMP(idx, 1)
25 #define RING_CMP(ring, idx)     ((idx) & (ring)->ring_mask)
26 #define RING_CMPL(ring_mask, idx)       ((idx) & (ring_mask))
27 #define NEXT_CMP(idx)           RING_CMP(ADV_RAW_CMP(idx, 1))
28 #define FLIP_VALID(cons, mask, val)     ((cons) >= (mask) ? !(val) : (val))
29
30 #define DB_CP_REARM_FLAGS       (DB_KEY_CP | DB_IDX_VALID)
31 #define DB_CP_FLAGS             (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
32
33 #define NEXT_CMPL(cpr, idx, v, inc)     do { \
34         (idx) += (inc); \
35         if (unlikely((idx) >= (cpr)->cp_ring_struct->ring_size)) { \
36                 (v) = !(v); \
37                 (idx) = 0; \
38         } \
39 } while (0)
40 #define B_CP_DB_REARM(cpr, raw_cons)                                    \
41         rte_write32((DB_CP_REARM_FLAGS |                                \
42                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
43                     ((cpr)->cp_doorbell))
44
45 #define B_CP_DB_ARM(cpr)        rte_write32((DB_KEY_CP), ((cpr)->cp_doorbell))
46 #define B_CP_DB_DISARM(cpr)     (*(uint32_t *)((cpr)->cp_doorbell) = \
47                                  DB_KEY_CP | DB_IRQ_DIS)
48
49 #define B_CP_DB_IDX_ARM(cpr, cons)                                      \
50                 (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_REARM_FLAGS | \
51                                 (cons)))
52
53 #define B_CP_DB_IDX_DISARM(cpr, cons)   do {                            \
54                 rte_smp_wmb();                                          \
55                 (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_FLAGS |     \
56                                 (cons));                                \
57 } while (0)
58 #define B_CP_DIS_DB(cpr, raw_cons)                                      \
59         rte_write32((DB_CP_FLAGS |                                      \
60                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
61                     ((cpr)->cp_doorbell))
62 #define B_CP_DB(cpr, raw_cons, ring_mask)                               \
63         rte_write32((DB_CP_FLAGS |                                      \
64                     RING_CMPL((ring_mask), raw_cons)),  \
65                     ((cpr)->cp_doorbell))
66
67 struct bnxt_ring;
68 struct bnxt_cp_ring_info {
69         uint32_t                cp_raw_cons;
70         void                    *cp_doorbell;
71
72         struct cmpl_base        *cp_desc_ring;
73
74         rte_iova_t              cp_desc_mapping;
75
76         struct ctx_hw_stats     *hw_stats;
77         rte_iova_t              hw_stats_map;
78         uint32_t                hw_stats_ctx_id;
79
80         struct bnxt_ring        *cp_ring_struct;
81         uint16_t                cp_cons;
82         bool                    valid;
83 };
84
85 #define RX_CMP_L2_ERRORS                                                \
86         (RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR)
87
88 struct bnxt;
89 void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp);
90 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp);
91 int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp);
92
93 #endif