New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / net / bnxt / bnxt_cpr.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) Broadcom Limited.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Broadcom Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _BNXT_CPR_H_
35 #define _BNXT_CPR_H_
36 #include <stdbool.h>
37
38 #include <rte_io.h>
39
40 #define CMP_VALID(cmp, raw_cons, ring)                                  \
41         (!!(((struct cmpl_base *)(cmp))->info3_v & CMPL_BASE_V) ==      \
42          !((raw_cons) & ((ring)->ring_size)))
43
44 #define CMPL_VALID(cmp, v)                                              \
45         (!!(((struct cmpl_base *)(cmp))->info3_v & CMPL_BASE_V) == !(v))
46
47 #define CMP_TYPE(cmp)                                           \
48         (((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK)
49
50 #define ADV_RAW_CMP(idx, n)     ((idx) + (n))
51 #define NEXT_RAW_CMP(idx)       ADV_RAW_CMP(idx, 1)
52 #define RING_CMP(ring, idx)     ((idx) & (ring)->ring_mask)
53 #define NEXT_CMP(idx)           RING_CMP(ADV_RAW_CMP(idx, 1))
54 #define FLIP_VALID(cons, mask, val)     ((cons) >= (mask) ? !(val) : (val))
55
56 #define DB_CP_REARM_FLAGS       (DB_KEY_CP | DB_IDX_VALID)
57 #define DB_CP_FLAGS             (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
58
59 #define B_CP_DB_REARM(cpr, raw_cons)                                    \
60         rte_write32((DB_CP_REARM_FLAGS |                                \
61                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
62                     ((cpr)->cp_doorbell))
63
64 #define B_CP_DB_ARM(cpr)        rte_write32((DB_KEY_CP), ((cpr)->cp_doorbell))
65 #define B_CP_DB_DISARM(cpr)     (*(uint32_t *)((cpr)->cp_doorbell) = \
66                                  DB_KEY_CP | DB_IRQ_DIS)
67
68 #define B_CP_DB_IDX_ARM(cpr, cons)                                      \
69                 (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_REARM_FLAGS | \
70                                 (cons)))
71
72 #define B_CP_DB_IDX_DISARM(cpr, cons)   do {                            \
73                 rte_smp_wmb();                                          \
74                 (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_FLAGS |     \
75                                 (cons));                                \
76 } while (0)
77 #define B_CP_DIS_DB(cpr, raw_cons)                                      \
78         rte_write32((DB_CP_FLAGS |                                      \
79                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
80                     ((cpr)->cp_doorbell))
81
82 struct bnxt_ring;
83 struct bnxt_cp_ring_info {
84         uint32_t                cp_raw_cons;
85         void                    *cp_doorbell;
86
87         struct cmpl_base        *cp_desc_ring;
88
89         rte_iova_t              cp_desc_mapping;
90
91         struct ctx_hw_stats     *hw_stats;
92         rte_iova_t              hw_stats_map;
93         uint32_t                hw_stats_ctx_id;
94
95         struct bnxt_ring        *cp_ring_struct;
96         uint16_t                cp_cons;
97         bool                    valid;
98 };
99
100 #define RX_CMP_L2_ERRORS                                                \
101         (RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR)
102
103
104 struct bnxt;
105 int bnxt_alloc_def_cp_ring(struct bnxt *bp);
106 void bnxt_free_def_cp_ring(struct bnxt *bp);
107 int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id);
108 void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp);
109 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp);
110
111 #endif