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