Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2023 Corigine, Inc.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #ifndef __NFP_COMMON_H__
7 : : #define __NFP_COMMON_H__
8 : :
9 : : #include <rte_byteorder.h>
10 : : #include <rte_ether.h>
11 : : #include <rte_io.h>
12 : : #include <rte_spinlock.h>
13 : :
14 : : #include "nfp_common_ctrl.h"
15 : :
16 : : #define NFP_QCP_QUEUE_ADDR_SZ (0x800)
17 : :
18 : : /* Macros for accessing the Queue Controller Peripheral 'CSRs' */
19 : : #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800)
20 : : #define NFP_QCP_QUEUE_ADD_RPTR 0x0000
21 : : #define NFP_QCP_QUEUE_ADD_WPTR 0x0004
22 : : #define NFP_QCP_QUEUE_STS_LO 0x0008
23 : : #define NFP_QCP_QUEUE_STS_LO_READPTR_MASK (0x3ffff)
24 : : #define NFP_QCP_QUEUE_STS_HI 0x000c
25 : : #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_MASK (0x3ffff)
26 : :
27 : : /* Read or Write Pointer of a queue */
28 : : enum nfp_qcp_ptr {
29 : : NFP_QCP_READ_PTR = 0,
30 : : NFP_QCP_WRITE_PTR
31 : : };
32 : :
33 : : struct nfp_hw {
34 : : uint8_t *ctrl_bar;
35 : : uint8_t *qcp_cfg;
36 : : uint32_t cap;
37 : : uint32_t cap_ext;
38 : : uint32_t ctrl;
39 : : uint32_t ctrl_ext;
40 : : rte_spinlock_t reconfig_lock;
41 : : struct rte_ether_addr mac_addr;
42 : : uint32_t cap_rss;
43 : : };
44 : :
45 : : static inline uint8_t
46 : : nn_readb(volatile const void *addr)
47 : : {
48 : : return rte_read8(addr);
49 : : }
50 : :
51 : : static inline void
52 : : nn_writeb(uint8_t val,
53 : : volatile void *addr)
54 : : {
55 : : rte_write8(val, addr);
56 : : }
57 : :
58 : : static inline uint32_t
59 : : nn_readl(volatile const void *addr)
60 : : {
61 : : return rte_read32(addr);
62 : : }
63 : :
64 : : static inline void
65 : : nn_writel(uint32_t val,
66 : : volatile void *addr)
67 : : {
68 : : rte_write32(val, addr);
69 : : }
70 : :
71 : : static inline uint16_t
72 : : nn_readw(volatile const void *addr)
73 : : {
74 : : return rte_read16(addr);
75 : : }
76 : :
77 : : static inline void
78 : : nn_writew(uint16_t val,
79 : : volatile void *addr)
80 : : {
81 : : rte_write16(val, addr);
82 : : }
83 : :
84 : : static inline uint64_t
85 : : nn_readq(volatile void *addr)
86 : : {
87 : : uint32_t low;
88 : : uint32_t high;
89 : : const volatile uint32_t *p = addr;
90 : :
91 : : high = nn_readl((volatile const void *)(p + 1));
92 : : low = nn_readl((volatile const void *)p);
93 : :
94 [ # # # # ]: 0 : return low + ((uint64_t)high << 32);
95 : : }
96 : :
97 : : static inline void
98 : : nn_writeq(uint64_t val,
99 : : volatile void *addr)
100 : : {
101 : 0 : nn_writel(val >> 32, (volatile char *)addr + 4);
102 : 0 : nn_writel(val, addr);
103 : : }
104 : :
105 : : static inline uint8_t
106 : : nn_cfg_readb(struct nfp_hw *hw,
107 : : uint32_t off)
108 : : {
109 : 0 : return nn_readb(hw->ctrl_bar + off);
110 : : }
111 : :
112 : : static inline void
113 : : nn_cfg_writeb(struct nfp_hw *hw,
114 : : uint32_t off,
115 : : uint8_t val)
116 : : {
117 : 0 : nn_writeb(val, hw->ctrl_bar + off);
118 : 0 : }
119 : :
120 : : static inline uint16_t
121 : : nn_cfg_readw(struct nfp_hw *hw,
122 : : uint32_t off)
123 : : {
124 : 0 : return rte_le_to_cpu_16(nn_readw(hw->ctrl_bar + off));
125 : : }
126 : :
127 : : static inline void
128 : : nn_cfg_writew(struct nfp_hw *hw,
129 : : uint32_t off,
130 : : uint16_t val)
131 : : {
132 : 0 : nn_writew(rte_cpu_to_le_16(val), hw->ctrl_bar + off);
133 : 0 : }
134 : :
135 : : static inline uint32_t
136 : : nn_cfg_readl(struct nfp_hw *hw,
137 : : uint32_t off)
138 : : {
139 : 0 : return rte_le_to_cpu_32(nn_readl(hw->ctrl_bar + off));
140 : : }
141 : :
142 : : static inline void
143 : : nn_cfg_writel(struct nfp_hw *hw,
144 : : uint32_t off,
145 : : uint32_t val)
146 : : {
147 : 0 : nn_writel(rte_cpu_to_le_32(val), hw->ctrl_bar + off);
148 : 0 : }
149 : :
150 : : static inline uint64_t
151 : : nn_cfg_readq(struct nfp_hw *hw,
152 : : uint32_t off)
153 : : {
154 : 0 : return rte_le_to_cpu_64(nn_readq(hw->ctrl_bar + off));
155 : : }
156 : :
157 : : static inline void
158 : : nn_cfg_writeq(struct nfp_hw *hw,
159 : : uint32_t off,
160 : : uint64_t val)
161 : : {
162 : 0 : nn_writeq(rte_cpu_to_le_64(val), hw->ctrl_bar + off);
163 : 0 : }
164 : :
165 : : /**
166 : : * Add the value to the selected pointer of a queue.
167 : : *
168 : : * @param queue
169 : : * Base address for queue structure
170 : : * @param ptr
171 : : * Add to the read or write pointer
172 : : * @param val
173 : : * Value to add to the queue pointer
174 : : */
175 : : static inline void
176 : : nfp_qcp_ptr_add(uint8_t *queue,
177 : : enum nfp_qcp_ptr ptr,
178 : : uint32_t val)
179 : : {
180 : : uint32_t off;
181 : :
182 : : if (ptr == NFP_QCP_READ_PTR)
183 : : off = NFP_QCP_QUEUE_ADD_RPTR;
184 : : else
185 : : off = NFP_QCP_QUEUE_ADD_WPTR;
186 : :
187 : : nn_writel(rte_cpu_to_le_32(val), queue + off);
188 : : }
189 : :
190 : : /**
191 : : * Read the current read/write pointer value for a queue.
192 : : *
193 : : * @param queue
194 : : * Base address for queue structure
195 : : * @param ptr
196 : : * Read or Write pointer
197 : : */
198 : : static inline uint32_t
199 : : nfp_qcp_read(uint8_t *queue,
200 : : enum nfp_qcp_ptr ptr)
201 : : {
202 : : uint32_t off;
203 : : uint32_t val;
204 : :
205 : : if (ptr == NFP_QCP_READ_PTR)
206 : : off = NFP_QCP_QUEUE_STS_LO;
207 : : else
208 : : off = NFP_QCP_QUEUE_STS_HI;
209 : :
210 : : val = rte_cpu_to_le_32(nn_readl(queue + off));
211 : :
212 : : if (ptr == NFP_QCP_READ_PTR)
213 : 0 : return val & NFP_QCP_QUEUE_STS_LO_READPTR_MASK;
214 : : else
215 : : return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_MASK;
216 : : }
217 : :
218 : : __rte_internal
219 : : int nfp_reconfig_real(struct nfp_hw *hw, uint32_t update);
220 : :
221 : : __rte_internal
222 : : int nfp_reconfig(struct nfp_hw *hw, uint32_t ctrl, uint32_t update);
223 : :
224 : : __rte_internal
225 : : int nfp_ext_reconfig(struct nfp_hw *hw, uint32_t ctrl_ext, uint32_t update);
226 : :
227 : : __rte_internal
228 : : void nfp_read_mac(struct nfp_hw *hw);
229 : :
230 : : __rte_internal
231 : : void nfp_write_mac(struct nfp_hw *hw, uint8_t *mac);
232 : :
233 : : __rte_internal
234 : : void nfp_enable_queues(struct nfp_hw *hw, uint16_t nb_rx_queues,
235 : : uint16_t nb_tx_queues);
236 : :
237 : : __rte_internal
238 : : void nfp_disable_queues(struct nfp_hw *hw);
239 : :
240 : : #endif/* __NFP_COMMON_H__ */
|