a6e87858ab020e499a87926dfca97e5a165f04ab
[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 CMP_TYPE(cmp)                                           \
45         (((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK)
46
47 #define ADV_RAW_CMP(idx, n)     ((idx) + (n))
48 #define NEXT_RAW_CMP(idx)       ADV_RAW_CMP(idx, 1)
49 #define RING_CMP(ring, idx)     ((idx) & (ring)->ring_mask)
50 #define NEXT_CMP(idx)           RING_CMP(ADV_RAW_CMP(idx, 1))
51
52 #define DB_CP_REARM_FLAGS       (DB_KEY_CP | DB_IDX_VALID)
53 #define DB_CP_FLAGS             (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
54
55 #define B_CP_DB_REARM(cpr, raw_cons)                                    \
56         rte_write32((DB_CP_REARM_FLAGS |                                \
57                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
58                     ((cpr)->cp_doorbell))
59
60 #define B_CP_DB_ARM(cpr)        rte_write32((DB_KEY_CP), ((cpr)->cp_doorbell))
61 #define B_CP_DB_DISARM(cpr)     (*(uint32_t *)((cpr)->cp_doorbell) = \
62                                  DB_KEY_CP | DB_IRQ_DIS)
63
64 #define B_CP_DB_IDX_ARM(cpr, cons)                                      \
65                 (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_REARM_FLAGS | \
66                                 (cons)))
67
68 #define B_CP_DB_IDX_DISARM(cpr, cons)   do {                            \
69                 rte_smp_wmb();                                          \
70                 (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_FLAGS |     \
71                                 (cons));                                \
72 } while (0)
73 #define B_CP_DIS_DB(cpr, raw_cons)                                      \
74         rte_write32((DB_CP_FLAGS |                                      \
75                     RING_CMP(((cpr)->cp_ring_struct), raw_cons)),       \
76                     ((cpr)->cp_doorbell))
77
78 struct bnxt_ring;
79 struct bnxt_cp_ring_info {
80         uint32_t                cp_raw_cons;
81         void                    *cp_doorbell;
82
83         struct cmpl_base        *cp_desc_ring;
84
85         phys_addr_t             cp_desc_mapping;
86
87         struct ctx_hw_stats     *hw_stats;
88         phys_addr_t             hw_stats_map;
89         uint32_t                hw_stats_ctx_id;
90
91         struct bnxt_ring        *cp_ring_struct;
92         uint16_t                cp_cons;
93         bool                    v;
94 };
95
96 #define RX_CMP_L2_ERRORS                                                \
97         (RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR)
98
99
100 struct bnxt;
101 int bnxt_alloc_def_cp_ring(struct bnxt *bp);
102 void bnxt_free_def_cp_ring(struct bnxt *bp);
103 int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id);
104 void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp);
105 void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp);
106
107 #endif