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
37#define CMP_VALID(cmp, raw_cons, ring)					\
38	(!!(((struct cmpl_base *)(cmp))->info3_v & CMPL_BASE_V) ==	\
39	 !((raw_cons) & ((ring)->ring_size)))
40
41#define CMP_TYPE(cmp)						\
42	(((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK)
43
44#define ADV_RAW_CMP(idx, n)	((idx) + (n))
45#define NEXT_RAW_CMP(idx)	ADV_RAW_CMP(idx, 1)
46#define RING_CMP(ring, idx)	((idx) & (ring)->ring_mask)
47#define NEXT_CMP(idx)		RING_CMP(ADV_RAW_CMP(idx, 1))
48
49#define DB_CP_REARM_FLAGS	(DB_KEY_CP | DB_IDX_VALID)
50#define DB_CP_FLAGS		(DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
51
52#define B_CP_DB_REARM(cpr, raw_cons)					\
53		(*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_REARM_FLAGS | \
54				RING_CMP(cpr->cp_ring_struct, raw_cons)))
55
56#define B_CP_DIS_DB(cpr, raw_cons)					\
57		rte_smp_wmb();						\
58		(*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_FLAGS |	\
59				RING_CMP(cpr->cp_ring_struct, raw_cons)))
60
61struct bnxt_ring;
62struct bnxt_cp_ring_info {
63	uint32_t		cp_raw_cons;
64	void			*cp_doorbell;
65
66	struct cmpl_base	*cp_desc_ring;
67
68	phys_addr_t		cp_desc_mapping;
69
70	struct ctx_hw_stats	*hw_stats;
71	phys_addr_t		hw_stats_map;
72	uint32_t		hw_stats_ctx_id;
73
74	struct bnxt_ring	*cp_ring_struct;
75};
76
77#define RX_CMP_L2_ERRORS						\
78	(RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR)
79
80
81struct bnxt;
82void bnxt_free_def_cp_ring(struct bnxt *bp);
83int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id);
84void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp);
85void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp);
86
87#endif
88