xref: /dpdk/drivers/net/bnxt/bnxt_ring.h (revision 4e2cf9af)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Broadcom
3  * All rights reserved.
4  */
5 
6 #ifndef _BNXT_RING_H_
7 #define _BNXT_RING_H_
8 
9 #include <inttypes.h>
10 
11 #include <rte_memory.h>
12 
13 #define RING_ADV(ring, idx, n)		(((idx) + (n)) & (ring)->ring_mask)
14 #define RING_NEXT(ring, idx)		RING_ADV(ring, idx, 1)
15 
16 #define DB_IDX_MASK						0xffffff
17 #define DB_IDX_VALID						(0x1 << 26)
18 #define DB_IRQ_DIS						(0x1 << 27)
19 #define DB_KEY_TX						(0x0 << 28)
20 #define DB_KEY_RX						(0x1 << 28)
21 #define DB_KEY_CP						(0x2 << 28)
22 #define DB_KEY_ST						(0x3 << 28)
23 #define DB_KEY_TX_PUSH						(0x4 << 28)
24 #define DB_LONG_TX_PUSH						(0x2 << 24)
25 
26 #define DEFAULT_CP_RING_SIZE	256
27 #define DEFAULT_RX_RING_SIZE	256
28 #define DEFAULT_TX_RING_SIZE	256
29 
30 #define AGG_RING_SIZE_FACTOR	2
31 #define AGG_RING_MULTIPLIER	2
32 
33 /* These assume 4k pages */
34 #define MAX_RX_DESC_CNT (8 * 1024)
35 #define MAX_TX_DESC_CNT (4 * 1024)
36 #define MAX_CP_DESC_CNT (16 * 1024)
37 
38 #define INVALID_HW_RING_ID      ((uint16_t)-1)
39 #define INVALID_STATS_CTX_ID		((uint16_t)-1)
40 
41 struct bnxt_ring {
42 	void			*bd;
43 	rte_iova_t		bd_dma;
44 	uint32_t		ring_size;
45 	uint32_t		ring_mask;
46 
47 	int			vmem_size;
48 	void			**vmem;
49 
50 	uint16_t		fw_ring_id; /* Ring id filled by Chimp FW */
51 	uint16_t                fw_rx_ring_id;
52 	const void		*mem_zone;
53 };
54 
55 struct bnxt_ring_grp_info {
56 	uint16_t	fw_stats_ctx;
57 	uint16_t	fw_grp_id;
58 	uint16_t	rx_fw_ring_id;
59 	uint16_t	cp_fw_ring_id;
60 	uint16_t	ag_fw_ring_id;
61 };
62 
63 struct bnxt;
64 struct bnxt_tx_ring_info;
65 struct bnxt_rx_ring_info;
66 struct bnxt_cp_ring_info;
67 void bnxt_free_ring(struct bnxt_ring *ring);
68 int bnxt_alloc_ring_grps(struct bnxt *bp);
69 int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx,
70 			    struct bnxt_tx_queue *txq,
71 			    struct bnxt_rx_queue *rxq,
72 			    struct bnxt_cp_ring_info *cp_ring_info,
73 			    struct bnxt_cp_ring_info *nq_ring_info,
74 			    const char *suffix);
75 int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index);
76 int bnxt_alloc_hwrm_rings(struct bnxt *bp);
77 int bnxt_alloc_async_cp_ring(struct bnxt *bp);
78 void bnxt_free_async_cp_ring(struct bnxt *bp);
79 int bnxt_alloc_async_ring_struct(struct bnxt *bp);
80 int bnxt_alloc_rxtx_nq_ring(struct bnxt *bp);
81 void bnxt_free_rxtx_nq_ring(struct bnxt *bp);
82 
83 static inline void bnxt_db_write(struct bnxt_db_info *db, uint32_t idx)
84 {
85 	rte_io_wmb();
86 
87 	if (db->db_64)
88 		rte_write64_relaxed(db->db_key64 | idx, db->doorbell);
89 	else
90 		rte_write32_relaxed(db->db_key32 | idx, db->doorbell);
91 }
92 
93 /* Ring an NQ doorbell and disable interrupts for the ring. */
94 static inline void bnxt_db_nq(struct bnxt_cp_ring_info *cpr)
95 {
96 	if (unlikely(!cpr->cp_db.db_64))
97 		return;
98 
99 	rte_io_wmb();
100 	rte_write64_relaxed(cpr->cp_db.db_key64 | DBR_TYPE_NQ |
101 			    RING_CMP(cpr->cp_ring_struct, cpr->cp_raw_cons),
102 			    cpr->cp_db.doorbell);
103 }
104 
105 /* Ring an NQ doorbell and enable interrupts for the ring. */
106 static inline void bnxt_db_nq_arm(struct bnxt_cp_ring_info *cpr)
107 {
108 	if (unlikely(!cpr->cp_db.db_64))
109 		return;
110 
111 	rte_io_wmb();
112 	rte_write64_relaxed(cpr->cp_db.db_key64 | DBR_TYPE_NQ_ARM |
113 			    RING_CMP(cpr->cp_ring_struct, cpr->cp_raw_cons),
114 			    cpr->cp_db.doorbell);
115 }
116 
117 static inline void bnxt_db_cq(struct bnxt_cp_ring_info *cpr)
118 {
119 	struct bnxt_db_info *db = &cpr->cp_db;
120 	uint32_t idx = RING_CMP(cpr->cp_ring_struct, cpr->cp_raw_cons);
121 
122 	rte_compiler_barrier();
123 	if (db->db_64)
124 		rte_write64_relaxed(db->db_key64 | idx, db->doorbell);
125 	else
126 		B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
127 }
128 
129 #endif
130