Branch data Line data Source code
1 : : /*
2 : : * SPDX-License-Identifier: BSD-3-Clause
3 : : * Copyright(c) 2023 Napatech A/S
4 : : */
5 : :
6 : : #include "rte_spinlock.h"
7 : : #include "nt_util.h"
8 : : #include "ntlog.h"
9 : :
10 : : #include "nthw_drv.h"
11 : : #include "nthw_register.h"
12 : : #include "nthw_rac.h"
13 : :
14 : : #define RAB_DMA_WAIT (1000000)
15 : :
16 : : #define RAB_READ (0x01)
17 : : #define RAB_WRITE (0x02)
18 : : #define RAB_ECHO (0x08)
19 : : #define RAB_COMPLETION (0x0F)
20 : :
21 : : #define RAB_OPR_LO (28)
22 : :
23 : : #define RAB_CNT_LO (20)
24 : : #define RAB_CNT_BW (8)
25 : :
26 : : #define RAB_BUSID_LO (16)
27 : : #define RAB_BUSID_BW (4)
28 : :
29 : : #define RAB_ADDR_BW (16)
30 : :
31 : 0 : nthw_rac_t *nthw_rac_new(void)
32 : : {
33 : 0 : nthw_rac_t *p = malloc(sizeof(nthw_rac_t));
34 : :
35 [ # # ]: 0 : if (p)
36 : : memset(p, 0, sizeof(nthw_rac_t));
37 : :
38 : 0 : return p;
39 : : }
40 : :
41 : 0 : int nthw_rac_init(nthw_rac_t *p, nthw_fpga_t *p_fpga, struct fpga_info_s *p_fpga_info)
42 : : {
43 : : RTE_ASSERT(p_fpga_info);
44 : :
45 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
46 : 0 : nthw_module_t *p_mod = nthw_fpga_query_module(p_fpga, MOD_RAC, 0);
47 : :
48 [ # # ]: 0 : if (p == NULL)
49 [ # # ]: 0 : return p_mod == NULL ? -1 : 0;
50 : :
51 [ # # ]: 0 : if (p_mod == NULL) {
52 : 0 : NT_LOG(ERR, NTHW, "%s: RAC %d: no such instance", p_adapter_id_str, 0);
53 : 0 : return -1;
54 : : }
55 : :
56 : 0 : p->mp_fpga = p_fpga;
57 : 0 : p->mp_mod_rac = p_mod;
58 : :
59 : 0 : p->mn_param_rac_rab_interfaces =
60 : 0 : nthw_fpga_get_product_param(p->mp_fpga, NT_RAC_RAB_INTERFACES, 3);
61 : 0 : NT_LOG(DBG, NTHW, "%s: NT_RAC_RAB_INTERFACES=%d", p_adapter_id_str,
62 : : p->mn_param_rac_rab_interfaces);
63 : :
64 : 0 : p->mn_param_rac_rab_ob_update =
65 : 0 : nthw_fpga_get_product_param(p->mp_fpga, NT_RAC_RAB_OB_UPDATE, 0);
66 : 0 : NT_LOG(DBG, NTHW, "%s: NT_RAC_RAB_OB_UPDATE=%d", p_adapter_id_str,
67 : : p->mn_param_rac_rab_ob_update);
68 : :
69 : : /* Optional dummy test registers */
70 : 0 : p->mp_reg_dummy0 = nthw_module_query_register(p->mp_mod_rac, RAC_DUMMY0);
71 : 0 : p->mp_reg_dummy1 = nthw_module_query_register(p->mp_mod_rac, RAC_DUMMY1);
72 : 0 : p->mp_reg_dummy2 = nthw_module_query_register(p->mp_mod_rac, RAC_DUMMY2);
73 : :
74 : 0 : p->mp_reg_rab_init = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_INIT);
75 : 0 : p->mp_fld_rab_init = nthw_register_get_field(p->mp_reg_rab_init, RAC_RAB_INIT_RAB);
76 : 0 : p->mn_fld_rab_init_bw = nthw_field_get_bit_width(p->mp_fld_rab_init);
77 : 0 : p->mn_fld_rab_init_mask = nthw_field_get_mask(p->mp_fld_rab_init);
78 : :
79 : : /* RAC_RAB_INIT_RAB reg/field sanity checks: */
80 : : RTE_ASSERT(p->mn_fld_rab_init_mask == ((1UL << p->mn_fld_rab_init_bw) - 1));
81 : : RTE_ASSERT(p->mn_fld_rab_init_bw == p->mn_param_rac_rab_interfaces);
82 : :
83 : 0 : p->mp_reg_dbg_ctrl = nthw_module_query_register(p->mp_mod_rac, RAC_DBG_CTRL);
84 : :
85 [ # # ]: 0 : if (p->mp_reg_dbg_ctrl)
86 : 0 : p->mp_fld_dbg_ctrl = nthw_register_query_field(p->mp_reg_dbg_ctrl, RAC_DBG_CTRL_C);
87 : :
88 : : else
89 : 0 : p->mp_fld_dbg_ctrl = NULL;
90 : :
91 : 0 : p->mp_reg_dbg_data = nthw_module_query_register(p->mp_mod_rac, RAC_DBG_DATA);
92 : :
93 [ # # ]: 0 : if (p->mp_reg_dbg_data)
94 : 0 : p->mp_fld_dbg_data = nthw_register_query_field(p->mp_reg_dbg_data, RAC_DBG_DATA_D);
95 : :
96 : 0 : p->mp_reg_rab_ib_data = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_IB_DATA);
97 : 0 : p->mp_fld_rab_ib_data = nthw_register_get_field(p->mp_reg_rab_ib_data, RAC_RAB_IB_DATA_D);
98 : :
99 : 0 : p->mp_reg_rab_ob_data = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_OB_DATA);
100 : 0 : p->mp_fld_rab_ob_data = nthw_register_get_field(p->mp_reg_rab_ob_data, RAC_RAB_OB_DATA_D);
101 : :
102 : 0 : p->mp_reg_rab_buf_free = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_BUF_FREE);
103 : 0 : p->mp_fld_rab_buf_free_ib_free =
104 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_free, RAC_RAB_BUF_FREE_IB_FREE);
105 : 0 : p->mp_fld_rab_buf_free_ib_ovf =
106 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_free, RAC_RAB_BUF_FREE_IB_OVF);
107 : 0 : p->mp_fld_rab_buf_free_ob_free =
108 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_free, RAC_RAB_BUF_FREE_OB_FREE);
109 : 0 : p->mp_fld_rab_buf_free_ob_ovf =
110 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_free, RAC_RAB_BUF_FREE_OB_OVF);
111 : 0 : p->mp_fld_rab_buf_free_timeout =
112 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_free, RAC_RAB_BUF_FREE_TIMEOUT);
113 : :
114 : 0 : p->mp_reg_rab_buf_used = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_BUF_USED);
115 : 0 : p->mp_fld_rab_buf_used_ib_used =
116 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_used, RAC_RAB_BUF_USED_IB_USED);
117 : 0 : p->mp_fld_rab_buf_used_ob_used =
118 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_used, RAC_RAB_BUF_USED_OB_USED);
119 : 0 : p->mp_fld_rab_buf_used_flush =
120 : 0 : nthw_register_get_field(p->mp_reg_rab_buf_used, RAC_RAB_BUF_USED_FLUSH);
121 : :
122 : : /*
123 : : * RAC_RAB_DMA regs are optional - only found in real
124 : : * NT4GA - not found in 9231/9232 and earlier
125 : : */
126 : 0 : p->mp_reg_rab_dma_ib_lo = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_IB_LO);
127 : 0 : p->mp_fld_rab_dma_ib_lo_phy_addr =
128 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ib_lo, RAC_RAB_DMA_IB_LO_PHYADDR);
129 : :
130 : 0 : p->mp_reg_rab_dma_ib_hi = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_IB_HI);
131 : 0 : p->mp_fld_rab_dma_ib_hi_phy_addr =
132 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ib_hi, RAC_RAB_DMA_IB_HI_PHYADDR);
133 : :
134 : 0 : p->mp_reg_rab_dma_ob_lo = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_OB_LO);
135 : 0 : p->mp_fld_rab_dma_ob_lo_phy_addr =
136 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ob_lo, RAC_RAB_DMA_OB_LO_PHYADDR);
137 : :
138 : 0 : p->mp_reg_rab_dma_ob_hi = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_OB_HI);
139 : 0 : p->mp_fld_rab_dma_ob_hi_phy_addr =
140 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ob_hi, RAC_RAB_DMA_OB_HI_PHYADDR);
141 : :
142 : 0 : p->mp_reg_rab_dma_ib_wr = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_IB_WR);
143 : 0 : p->mp_fld_rab_dma_ib_wr_ptr =
144 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ib_wr, RAC_RAB_DMA_IB_WR_PTR);
145 : :
146 : 0 : p->mp_reg_rab_dma_ib_rd = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_IB_RD);
147 : 0 : p->mp_fld_rab_dma_ib_rd_ptr =
148 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ib_rd, RAC_RAB_DMA_IB_RD_PTR);
149 : :
150 : 0 : p->mp_reg_rab_dma_ob_wr = nthw_module_get_register(p->mp_mod_rac, RAC_RAB_DMA_OB_WR);
151 : 0 : p->mp_fld_rab_dma_ob_wr_ptr =
152 : 0 : nthw_register_get_field(p->mp_reg_rab_dma_ob_wr, RAC_RAB_DMA_OB_WR_PTR);
153 : :
154 : 0 : p->RAC_RAB_INIT_ADDR = nthw_register_get_address(p->mp_reg_rab_init);
155 : 0 : p->RAC_RAB_IB_DATA_ADDR = nthw_register_get_address(p->mp_reg_rab_ib_data);
156 : 0 : p->RAC_RAB_OB_DATA_ADDR = nthw_register_get_address(p->mp_reg_rab_ob_data);
157 : 0 : p->RAC_RAB_BUF_FREE_ADDR = nthw_register_get_address(p->mp_reg_rab_buf_free);
158 : 0 : p->RAC_RAB_BUF_USED_ADDR = nthw_register_get_address(p->mp_reg_rab_buf_used);
159 : :
160 : : /*
161 : : * RAC_RAB_DMA regs are optional - only found in real NT4GA - not found in 9231/9232 and
162 : : * earlier
163 : : */
164 : :
165 : 0 : p->RAC_RAB_DMA_IB_LO_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ib_lo);
166 : 0 : p->RAC_RAB_DMA_IB_HI_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ib_hi);
167 : 0 : p->RAC_RAB_DMA_OB_LO_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ob_lo);
168 : 0 : p->RAC_RAB_DMA_OB_HI_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ob_hi);
169 : 0 : p->RAC_RAB_DMA_IB_RD_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ib_rd);
170 : 0 : p->RAC_RAB_DMA_OB_WR_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ob_wr);
171 : 0 : p->RAC_RAB_DMA_IB_WR_ADDR = nthw_register_get_address(p->mp_reg_rab_dma_ib_wr);
172 : :
173 : 0 : p->RAC_RAB_BUF_FREE_IB_FREE_MASK = nthw_field_get_mask(p->mp_fld_rab_buf_free_ib_free);
174 : 0 : p->RAC_RAB_BUF_FREE_OB_FREE_MASK = nthw_field_get_mask(p->mp_fld_rab_buf_free_ob_free);
175 : 0 : p->RAC_RAB_BUF_USED_IB_USED_MASK = nthw_field_get_mask(p->mp_fld_rab_buf_used_ib_used);
176 : 0 : p->RAC_RAB_BUF_USED_OB_USED_MASK = nthw_field_get_mask(p->mp_fld_rab_buf_used_ob_used);
177 : :
178 : 0 : p->RAC_RAB_BUF_USED_FLUSH_MASK = nthw_field_get_mask(p->mp_fld_rab_buf_used_flush);
179 : :
180 : 0 : p->RAC_RAB_BUF_USED_OB_USED_LOW =
181 : 0 : nthw_field_get_bit_pos_low(p->mp_fld_rab_buf_used_ob_used);
182 : :
183 : 0 : p->mp_reg_rab_nmb_rd = nthw_module_query_register(p->mp_mod_rac, RAC_NMB_RD_ADR);
184 : :
185 [ # # ]: 0 : if (p->mp_reg_rab_nmb_rd)
186 : 0 : p->RAC_NMB_RD_ADR_ADDR = nthw_register_get_address(p->mp_reg_rab_nmb_rd);
187 : :
188 : 0 : p->mp_reg_rab_nmb_data = nthw_module_query_register(p->mp_mod_rac, RAC_NMB_DATA);
189 : :
190 [ # # ]: 0 : if (p->mp_reg_rab_nmb_data)
191 : 0 : p->RAC_NMB_DATA_ADDR = nthw_register_get_address(p->mp_reg_rab_nmb_data);
192 : :
193 : 0 : p->mp_reg_rab_nmb_wr = nthw_module_query_register(p->mp_mod_rac, RAC_NMB_WR_ADR);
194 : :
195 [ # # ]: 0 : if (p->mp_reg_rab_nmb_wr)
196 : 0 : p->RAC_NMB_WR_ADR_ADDR = nthw_register_get_address(p->mp_reg_rab_nmb_wr);
197 : :
198 : 0 : p->mp_reg_rab_nmb_status = nthw_module_query_register(p->mp_mod_rac, RAC_NMB_STATUS);
199 : :
200 [ # # ]: 0 : if (p->mp_reg_rab_nmb_status)
201 : 0 : p->RAC_NMB_STATUS_ADDR = nthw_register_get_address(p->mp_reg_rab_nmb_status);
202 : :
203 : 0 : p->m_dma = NULL;
204 : :
205 : : {
206 : : /*
207 : : * RAC is a primary communication channel - debug will be messy
208 : : * turn off debug by default - except for rac_rab_init
209 : : * NOTE: currently debug will not work - due to optimizations
210 : : */
211 : 0 : const int n_debug_mode = nthw_module_get_debug_mode(p->mp_mod_rac);
212 : :
213 [ # # ]: 0 : if (n_debug_mode && n_debug_mode <= 0xff) {
214 : 0 : nthw_module_set_debug_mode(p->mp_mod_rac, 0);
215 : 0 : nthw_register_set_debug_mode(p->mp_reg_rab_init, n_debug_mode);
216 : : }
217 : : }
218 : :
219 : : rte_spinlock_init(&p->m_mutex);
220 : :
221 : 0 : return 0;
222 : : }
223 : :
224 : : static int nthw_rac_get_rab_interface_count(const nthw_rac_t *p)
225 : : {
226 : 0 : return p->mn_param_rac_rab_interfaces;
227 : : }
228 : :
229 : : /* private function for internal RAC operations -
230 : : * improves log flexibility and prevents log flooding
231 : : */
232 : : static void nthw_rac_reg_read32(const struct fpga_info_s *p_fpga_info, uint32_t reg_addr,
233 : : uint32_t *p_data)
234 : : {
235 : 0 : *p_data = *(volatile uint32_t *)((uint8_t *)p_fpga_info->bar0_addr + reg_addr);
236 : : }
237 : :
238 : : /* private function for internal RAC operations -
239 : : * improves log flexibility and prevents log flooding
240 : : */
241 : : static void nthw_rac_reg_write32(const struct fpga_info_s *p_fpga_info, uint32_t reg_addr,
242 : : uint32_t n_data)
243 : : {
244 : 0 : *(volatile uint32_t *)((uint8_t *)p_fpga_info->bar0_addr + reg_addr) = n_data;
245 : 0 : }
246 : :
247 : 0 : static inline int _nthw_rac_wait_for_rab_done(const nthw_rac_t *p, uint32_t address,
248 : : uint32_t word_cnt)
249 : : {
250 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
251 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
252 : : uint32_t used = 0;
253 : : uint32_t retry;
254 : :
255 [ # # ]: 0 : for (retry = 0; retry < 100000; retry++) {
256 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, &used);
257 : 0 : used = (used & p->RAC_RAB_BUF_USED_OB_USED_MASK) >>
258 : 0 : p->RAC_RAB_BUF_USED_OB_USED_LOW;
259 : :
260 [ # # ]: 0 : if (used >= word_cnt)
261 : : break;
262 : : }
263 : :
264 [ # # ]: 0 : if (used < word_cnt) {
265 : 0 : NT_LOG(ERR, NTHW, "%s: Fail rab bus r/w addr=0x%08X used=%x wordcount=%" PRIu32 "",
266 : : p_adapter_id_str, address, used, word_cnt);
267 : 0 : return -1;
268 : : }
269 : :
270 : : return 0;
271 : : }
272 : :
273 : : /*
274 : : * NT_PCI_REG_P9xyz_RAC_RAB_INIT
275 : : *
276 : : * Initializes (resets) the programmable registers on the Register Access Buses (RAB).
277 : : * This initialization must be performed by software as part of the driver load procedure.
278 : : *
279 : : * Bit n of this field initializes the programmable registers on RAB interface n.
280 : : * Software must write one to the bit and then clear the bit again.
281 : : *
282 : : * All RAB module registers will be reset to their defaults.
283 : : * This includes the product specific RESET module (eg RST9xyz)
284 : : * As a consequence of this behavior the official reset sequence
285 : : * must be excersised - as all RAB modules will be held in reset.
286 : : */
287 : 0 : int nthw_rac_rab_init(nthw_rac_t *p, uint32_t n_rab_intf_mask)
288 : : {
289 : : /*
290 : : * Write rac_rab_init
291 : : * Perform operation twice - first to get trace of operation -
292 : : * second to get things done...
293 : : */
294 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
295 : 0 : nthw_field_set_val_flush32(p->mp_fld_rab_init, n_rab_intf_mask);
296 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_INIT_ADDR, n_rab_intf_mask);
297 : 0 : return 0;
298 : : }
299 : :
300 : 0 : int nthw_rac_rab_reset(nthw_rac_t *p)
301 : : {
302 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
303 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
304 : : (void)p_adapter_id_str;
305 : :
306 : : /* RAC RAB bus "flip/flip" reset */
307 : : const int n_rac_rab_bus_count = nthw_rac_get_rab_interface_count(p);
308 : 0 : const int n_rac_rab_bus_mask = (1 << n_rac_rab_bus_count) - 1;
309 : :
310 : 0 : NT_LOG(DBG, NTHW, "%s: NT_RAC_RAB_INTERFACES=%d (0x%02X)", p_adapter_id_str,
311 : : n_rac_rab_bus_count, n_rac_rab_bus_mask);
312 : : RTE_ASSERT(n_rac_rab_bus_count);
313 : : RTE_ASSERT(n_rac_rab_bus_mask);
314 : :
315 : : /* RAC RAB bus "flip/flip" reset first stage - new impl (ref RMT#37020) */
316 : 0 : nthw_rac_rab_init(p, 0);
317 : 0 : nthw_rac_rab_init(p, n_rac_rab_bus_mask);
318 : 0 : nthw_rac_rab_init(p, n_rac_rab_bus_mask & ~0x01);
319 : :
320 : 0 : return 0;
321 : : }
322 : :
323 : 0 : int nthw_rac_rab_setup(nthw_rac_t *p)
324 : : {
325 : : int rc = 0;
326 : :
327 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
328 : : uint32_t n_dma_buf_size = 2L * RAB_DMA_BUF_CNT * sizeof(uint32_t);
329 : 0 : const size_t align_size = nt_util_align_size(n_dma_buf_size);
330 : 0 : int numa_node = p_fpga_info->numa_node;
331 : : uint64_t dma_addr;
332 : : uint32_t buf;
333 : :
334 [ # # ]: 0 : if (!p->m_dma) {
335 : : struct nt_dma_s *vfio_dma;
336 : : /* FPGA needs Page alignment (4K) */
337 : 0 : vfio_dma = nt_dma_alloc(align_size, 0x1000, numa_node);
338 : :
339 [ # # ]: 0 : if (vfio_dma == NULL) {
340 : 0 : NT_LOG(ERR, NTNIC, "nt_dma_alloc failed");
341 : 0 : return -1;
342 : : }
343 : :
344 : 0 : p->m_dma_in_buf = (uint32_t *)vfio_dma->addr;
345 : 0 : p->m_dma_out_buf = p->m_dma_in_buf + RAB_DMA_BUF_CNT;
346 : 0 : p->m_dma = vfio_dma;
347 : : }
348 : :
349 : : /* Setup DMA on the adapter */
350 : 0 : dma_addr = p->m_dma->iova;
351 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_DMA_IB_LO_ADDR, dma_addr & 0xffffffff);
352 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_DMA_IB_HI_ADDR,
353 : 0 : (uint32_t)(dma_addr >> 32) & 0xffffffff);
354 : 0 : dma_addr += RAB_DMA_BUF_CNT * sizeof(uint32_t);
355 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_DMA_OB_LO_ADDR, dma_addr & 0xffffffff);
356 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_DMA_OB_HI_ADDR,
357 : 0 : (uint32_t)(dma_addr >> 32) & 0xffffffff);
358 : :
359 : : /* Set initial value of internal pointers */
360 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_DMA_IB_RD_ADDR, &buf);
361 : 0 : p->m_dma_in_ptr_wr = (uint16_t)(buf / sizeof(uint32_t));
362 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_DMA_OB_WR_ADDR, &buf);
363 : 0 : p->m_dma_out_ptr_rd = (uint16_t)(buf / sizeof(uint32_t));
364 : 0 : p->m_in_free = RAB_DMA_BUF_CNT;
365 : :
366 : 0 : return rc;
367 : : }
368 : :
369 : 0 : void nthw_rac_bar0_read32(const struct fpga_info_s *p_fpga_info, uint32_t reg_addr,
370 : : uint32_t word_cnt, uint32_t *p_data)
371 : : {
372 : : volatile const uint32_t *const src_addr =
373 : 0 : (uint32_t *)((uint8_t *)p_fpga_info->bar0_addr + reg_addr);
374 : :
375 [ # # ]: 0 : for (uint32_t i = 0; i < word_cnt; i++)
376 : 0 : p_data[i] = src_addr[i];
377 : 0 : }
378 : :
379 : 0 : void nthw_rac_bar0_write32(const struct fpga_info_s *p_fpga_info, uint32_t reg_addr,
380 : : uint32_t word_cnt, const uint32_t *p_data)
381 : : {
382 : : volatile uint32_t *const dst_addr =
383 : 0 : (uint32_t *)((uint8_t *)p_fpga_info->bar0_addr + reg_addr);
384 : :
385 [ # # ]: 0 : for (uint32_t i = 0; i < word_cnt; i++)
386 : 0 : dst_addr[i] = p_data[i];
387 : 0 : }
388 : :
389 : 0 : int nthw_rac_rab_dma_begin(nthw_rac_t *p)
390 : : {
391 : 0 : p->m_dma_active = true;
392 : :
393 : 0 : return 0;
394 : : }
395 : :
396 : 0 : static void nthw_rac_rab_dma_activate(nthw_rac_t *p)
397 : : {
398 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
399 : : const uint32_t completion = RAB_COMPLETION << RAB_OPR_LO;
400 : :
401 : : /* Write completion word */
402 : 0 : p->m_dma_in_buf[p->m_dma_in_ptr_wr] = completion;
403 : 0 : p->m_dma_in_ptr_wr = (uint16_t)((p->m_dma_in_ptr_wr + 1) & (RAB_DMA_BUF_CNT - 1));
404 : :
405 : : /* Clear output completion word */
406 : 0 : p->m_dma_out_buf[p->m_dma_out_ptr_rd] = 0;
407 : :
408 : : /* Update DMA pointer and start transfer */
409 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_DMA_IB_WR_ADDR,
410 : 0 : (uint32_t)(p->m_dma_in_ptr_wr * sizeof(uint32_t)));
411 : 0 : }
412 : :
413 : 0 : static int nthw_rac_rab_dma_wait(nthw_rac_t *p)
414 : : {
415 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
416 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
417 : : const uint32_t completion = RAB_COMPLETION << RAB_OPR_LO;
418 : : uint32_t i;
419 : :
420 [ # # ]: 0 : for (i = 0; i < RAB_DMA_WAIT; i++) {
421 : 0 : nt_os_wait_usec_poll(1);
422 : :
423 [ # # ]: 0 : if ((p->m_dma_out_buf[p->m_dma_out_ptr_rd] & completion) == completion)
424 : : break;
425 : : }
426 : :
427 [ # # ]: 0 : if (i == RAB_DMA_WAIT) {
428 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Unexpected value of completion (0x%08X)",
429 : : p_adapter_id_str, p->m_dma_out_buf[p->m_dma_out_ptr_rd]);
430 : 0 : return -1;
431 : : }
432 : :
433 : 0 : p->m_dma_out_ptr_rd = (uint16_t)((p->m_dma_out_ptr_rd + 1) & (RAB_DMA_BUF_CNT - 1));
434 : 0 : p->m_in_free = RAB_DMA_BUF_CNT;
435 : :
436 : 0 : return 0;
437 : : }
438 : :
439 : 0 : int nthw_rac_rab_dma_commit(nthw_rac_t *p)
440 : : {
441 : : int ret;
442 : :
443 : 0 : nthw_rac_rab_dma_activate(p);
444 : 0 : ret = nthw_rac_rab_dma_wait(p);
445 : :
446 : 0 : p->m_dma_active = false;
447 : :
448 : 0 : return ret;
449 : : }
450 : :
451 : 0 : uint32_t nthw_rac_rab_get_free(nthw_rac_t *p)
452 : : {
453 [ # # ]: 0 : if (!p->m_dma_active) {
454 : : /* Expecting mutex not to be locked! */
455 : : RTE_ASSERT(0); /* alert developer that something is wrong */
456 : : return -1;
457 : : }
458 : :
459 : 0 : return p->m_in_free;
460 : : }
461 : :
462 : 0 : int nthw_rac_rab_write32_dma(nthw_rac_t *p, nthw_rab_bus_id_t bus_id, uint32_t address,
463 : : uint32_t word_cnt, const uint32_t *p_data)
464 : : {
465 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
466 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
467 : :
468 [ # # ]: 0 : if (word_cnt == 0 || word_cnt > 256) {
469 : 0 : NT_LOG(ERR, NTHW,
470 : : "%s: Failed rab dma write length check - bus: %d addr: 0x%08X wordcount: %"
471 : : PRIu32 " - inBufFree: 0x%08X",
472 : : p_adapter_id_str, bus_id, address, word_cnt, p->m_in_free);
473 : : RTE_ASSERT(0); /* alert developer that something is wrong */
474 : 0 : return -1;
475 : : }
476 : :
477 [ # # ]: 0 : if (p->m_in_free < (word_cnt + 3)) {
478 : : /*
479 : : * No more memory available.
480 : : * nthw_rac_rab_dma_commit() needs to be called to start and finish pending
481 : : * transfers.
482 : : */
483 : : return -1;
484 : : }
485 : :
486 : 0 : p->m_in_free -= (word_cnt + 1);
487 : :
488 : : /* Write the command word */
489 : 0 : p->m_dma_in_buf[p->m_dma_in_ptr_wr] = (RAB_WRITE << RAB_OPR_LO) |
490 : 0 : ((word_cnt & ((1 << RAB_CNT_BW) - 1)) << RAB_CNT_LO) | (bus_id << RAB_BUSID_LO) |
491 : : address;
492 : 0 : p->m_dma_in_ptr_wr = (uint16_t)((p->m_dma_in_ptr_wr + 1) & (RAB_DMA_BUF_CNT - 1));
493 : :
494 [ # # ]: 0 : for (uint32_t i = 0; i < word_cnt; i++) {
495 : 0 : p->m_dma_in_buf[p->m_dma_in_ptr_wr] = p_data[i];
496 : 0 : p->m_dma_in_ptr_wr = (uint16_t)((p->m_dma_in_ptr_wr + 1) & (RAB_DMA_BUF_CNT - 1));
497 : : }
498 : :
499 : : return 0;
500 : : }
501 : :
502 : 0 : int nthw_rac_rab_read32_dma(nthw_rac_t *p, nthw_rab_bus_id_t bus_id, uint32_t address,
503 : : uint32_t word_cnt, struct dma_buf_ptr *buf_ptr)
504 : : {
505 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
506 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
507 : :
508 [ # # ]: 0 : if (word_cnt == 0 || word_cnt > 256) {
509 : 0 : NT_LOG(ERR, NTHW,
510 : : "%s: Failed rab dma read length check - bus: %d addr: 0x%08X wordcount: %"
511 : : PRIu32 " - inBufFree: 0x%08X",
512 : : p_adapter_id_str, bus_id, address, word_cnt, p->m_in_free);
513 : : RTE_ASSERT(0); /* alert developer that something is wrong */
514 : 0 : return -1;
515 : : }
516 : :
517 [ # # ]: 0 : if (p->m_in_free < 3) {
518 : : /*
519 : : * No more memory available.
520 : : * nthw_rac_rab_dma_commit() needs to be called to start and finish pending
521 : : * transfers.
522 : : */
523 : : return -1;
524 : : }
525 : :
526 : 0 : p->m_in_free -= 1;
527 : :
528 : : /* Write the command word */
529 : 0 : p->m_dma_in_buf[p->m_dma_in_ptr_wr] = (RAB_READ << RAB_OPR_LO) |
530 : 0 : ((word_cnt & ((1 << RAB_CNT_BW) - 1)) << RAB_CNT_LO) | (bus_id << RAB_BUSID_LO) |
531 : : address;
532 : 0 : p->m_dma_in_ptr_wr = (uint16_t)((p->m_dma_in_ptr_wr + 1) & (RAB_DMA_BUF_CNT - 1));
533 : :
534 : 0 : buf_ptr->index = p->m_dma_out_ptr_rd;
535 : 0 : buf_ptr->size = RAB_DMA_BUF_CNT;
536 : 0 : buf_ptr->base = p->m_dma_out_buf;
537 : 0 : p->m_dma_out_ptr_rd =
538 : 0 : (uint16_t)((p->m_dma_out_ptr_rd + word_cnt) & (RAB_DMA_BUF_CNT - 1U));
539 : :
540 : 0 : return 0;
541 : : }
542 : :
543 : 0 : int nthw_rac_rab_write32(nthw_rac_t *p, bool trc, nthw_rab_bus_id_t bus_id, uint32_t address,
544 : : uint32_t word_cnt, const uint32_t *p_data)
545 : : {
546 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
547 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
548 : : uint32_t buf_used;
549 : : uint32_t buf_free;
550 : : uint32_t in_buf_free;
551 : : uint32_t out_buf_free;
552 : : int res = 0;
553 : :
554 [ # # ]: 0 : if (address > (1 << RAB_ADDR_BW)) {
555 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal address: value too large %" PRIu32 " - max %d",
556 : : p_adapter_id_str, address, (1 << RAB_ADDR_BW));
557 : 0 : return -1;
558 : : }
559 : :
560 [ # # ]: 0 : if (bus_id > (1 << RAB_BUSID_BW)) {
561 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal bus id: value too large %" PRIu32 " - max %d",
562 : : p_adapter_id_str, bus_id, (1 << RAB_BUSID_BW));
563 : 0 : return -1;
564 : : }
565 : :
566 [ # # ]: 0 : if (word_cnt == 0) {
567 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal word count: value is zero (%" PRIu32 ")",
568 : : p_adapter_id_str, word_cnt);
569 : 0 : return -1;
570 : : }
571 : :
572 [ # # ]: 0 : if (word_cnt > (1 << RAB_CNT_BW)) {
573 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal word count: value too large %d - max %d",
574 : : p_adapter_id_str, word_cnt, (1 << RAB_CNT_BW));
575 : 0 : return -1;
576 : : }
577 : :
578 : 0 : rte_spinlock_lock(&p->m_mutex);
579 : :
580 [ # # ]: 0 : if (p->m_dma_active) {
581 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal operation: DMA enabled", p_adapter_id_str);
582 : : res = -1;
583 : 0 : goto exit_unlock_res;
584 : : }
585 : :
586 : : /* Read buffer free register */
587 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, &buf_free);
588 : :
589 : 0 : in_buf_free = buf_free & p->RAC_RAB_BUF_FREE_IB_FREE_MASK;
590 : 0 : out_buf_free = (buf_free & p->RAC_RAB_BUF_FREE_OB_FREE_MASK) >> 16;
591 : :
592 : : /* Read buffer used register */
593 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, &buf_used);
594 : :
595 : : buf_used =
596 : 0 : buf_used & (p->RAC_RAB_BUF_USED_IB_USED_MASK | p->RAC_RAB_BUF_USED_OB_USED_MASK);
597 : :
598 : : /*
599 : : * Verify that output buffer can hold one completion word,
600 : : * input buffer can hold the number of words to be written +
601 : : * one write and one completion command
602 : : * and that the input and output "used" buffer is 0
603 : : */
604 [ # # # # : 0 : if (out_buf_free >= 1 && in_buf_free >= word_cnt + 2 && buf_used == 0) {
# # ]
605 : : const uint32_t rab_oper_cmpl = (RAB_COMPLETION << RAB_OPR_LO);
606 : : uint32_t rab_echo_oper_cmpl;
607 : : uint32_t word_cnt_expected = 1;
608 : : uint32_t rab_oper_wr;
609 : : uint32_t i;
610 : :
611 : 0 : rab_oper_wr = (RAB_WRITE << RAB_OPR_LO) |
612 : 0 : ((word_cnt & ((1 << RAB_CNT_BW) - 1)) << RAB_CNT_LO) |
613 : 0 : (bus_id << RAB_BUSID_LO) | address;
614 : :
615 [ # # ]: 0 : if (trc) {
616 : 0 : rab_oper_wr |= (RAB_ECHO << RAB_OPR_LO);
617 : : word_cnt_expected += word_cnt + 1;
618 : : }
619 : :
620 : : /* Write command */
621 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_IB_DATA_ADDR, rab_oper_wr);
622 : :
623 : : /* Write data to input buffer */
624 [ # # ]: 0 : for (i = 0; i < word_cnt; i++)
625 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_IB_DATA_ADDR, p_data[i]);
626 : :
627 : : /* Write completion command */
628 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_IB_DATA_ADDR, rab_oper_cmpl);
629 : :
630 : : /* Wait until done */
631 [ # # ]: 0 : if (_nthw_rac_wait_for_rab_done(p, address, word_cnt_expected)) {
632 : : res = -1;
633 : 0 : goto exit_unlock_res;
634 : : }
635 : :
636 [ # # ]: 0 : if (trc) {
637 : : uint32_t rab_echo_oper_wr;
638 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR,
639 : : &rab_echo_oper_wr);
640 : :
641 [ # # ]: 0 : if (p->mn_param_rac_rab_ob_update)
642 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, 0);
643 : :
644 [ # # ]: 0 : if (rab_oper_wr != rab_echo_oper_wr) {
645 : 0 : NT_LOG(ERR, NTHW,
646 : : "%s: expected rab read echo oper (0x%08X) - read (0x%08X)",
647 : : p_adapter_id_str, rab_oper_wr, rab_echo_oper_wr);
648 : : }
649 : : }
650 : :
651 : : {
652 : : /* Read data from output buffer */
653 : : uint32_t data;
654 : : char *tmp_string;
655 : :
656 [ # # ]: 0 : if (trc) {
657 : 0 : tmp_string = ntlog_helper_str_alloc("Register::write");
658 : 0 : ntlog_helper_str_add(tmp_string,
659 : : "(Dev: NA, Bus: RAB%u, Addr: 0x%08X, Cnt: %d, Data:",
660 : : bus_id, address, word_cnt);
661 : : }
662 : :
663 [ # # ]: 0 : for (i = 0; i < word_cnt; i++) {
664 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, &data);
665 : :
666 [ # # ]: 0 : if (p->mn_param_rac_rab_ob_update) {
667 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR,
668 : : 0);
669 : : }
670 : :
671 [ # # ]: 0 : if (trc)
672 : 0 : ntlog_helper_str_add(tmp_string, " 0x%08X", data);
673 : : }
674 : :
675 [ # # ]: 0 : if (trc) {
676 : 0 : ntlog_helper_str_add(tmp_string, ")");
677 : 0 : NT_LOG(DBG, NTHW, "%s", tmp_string);
678 : 0 : ntlog_helper_str_free(tmp_string);
679 : : }
680 : : }
681 : :
682 : : /* Read completion from out buffer */
683 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, &rab_echo_oper_cmpl);
684 : :
685 [ # # ]: 0 : if (p->mn_param_rac_rab_ob_update)
686 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, 0);
687 : :
688 [ # # ]: 0 : if (rab_echo_oper_cmpl != rab_oper_cmpl) {
689 : 0 : NT_LOG(ERR, NTHW,
690 : : "%s: RAB: Unexpected value of completion (0x%08X)- inBufFree: 0x%08X, outBufFree: 0x%08X, bufUsed: 0x%08X",
691 : : p_adapter_id_str, rab_echo_oper_cmpl, in_buf_free, out_buf_free,
692 : : buf_used);
693 : : res = -1;
694 : 0 : goto exit_unlock_res;
695 : : }
696 : :
697 : : /* Read buffer free register */
698 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, &buf_free);
699 : :
700 [ # # ]: 0 : if (buf_free & 0x80000000) {
701 : : /* Clear Timeout and overflow bits */
702 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, 0x0);
703 : 0 : NT_LOG(ERR, NTHW,
704 : : "%s: RAB: timeout - Access outside register - bus: %d addr: 0x%08X - inBufFree: 0x%08X, outBufFree: 0x%08X, bufUsed: 0x%08X",
705 : : p_adapter_id_str, bus_id, address, in_buf_free, out_buf_free,
706 : : buf_used);
707 : : res = -1;
708 : 0 : goto exit_unlock_res;
709 : : }
710 : :
711 : : res = 0;
712 : 0 : goto exit_unlock_res;
713 : :
714 : : } else {
715 : 0 : NT_LOG(ERR, NTHW,
716 : : "%s: RAB: Fail rab bus buffer check - bus: %d addr: 0x%08X wordcount: %d - inBufFree: 0x%08X, outBufFree: 0x%08X, bufUsed: 0x%08X",
717 : : p_adapter_id_str, bus_id, address, word_cnt, in_buf_free, out_buf_free,
718 : : buf_used);
719 : : res = -1;
720 : 0 : goto exit_unlock_res;
721 : : }
722 : :
723 : 0 : exit_unlock_res:
724 : : rte_spinlock_unlock(&p->m_mutex);
725 : 0 : return res;
726 : : }
727 : :
728 : 0 : int nthw_rac_rab_read32(nthw_rac_t *p, bool trc, nthw_rab_bus_id_t bus_id, uint32_t address,
729 : : uint32_t word_cnt, uint32_t *p_data)
730 : : {
731 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
732 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
733 : : uint32_t buf_used;
734 : : uint32_t buf_free;
735 : : uint32_t in_buf_free;
736 : : uint32_t out_buf_free;
737 : : int res = 0;
738 : :
739 : 0 : rte_spinlock_lock(&p->m_mutex);
740 : :
741 [ # # ]: 0 : if (address > (1 << RAB_ADDR_BW)) {
742 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal address: value too large %" PRIu32 " - max %d",
743 : : p_adapter_id_str, address, (1 << RAB_ADDR_BW));
744 : : res = -1;
745 : 0 : goto exit_unlock_res;
746 : : }
747 : :
748 [ # # ]: 0 : if (bus_id > (1 << RAB_BUSID_BW)) {
749 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal bus id: value too large %" PRIu32 " - max %d",
750 : : p_adapter_id_str, bus_id, (1 << RAB_BUSID_BW));
751 : : res = -1;
752 : 0 : goto exit_unlock_res;
753 : : }
754 : :
755 [ # # ]: 0 : if (word_cnt == 0) {
756 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal word count: value is zero (%" PRIu32 ")",
757 : : p_adapter_id_str, word_cnt);
758 : : res = -1;
759 : 0 : goto exit_unlock_res;
760 : : }
761 : :
762 [ # # ]: 0 : if (word_cnt > (1 << RAB_CNT_BW)) {
763 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Illegal word count: value too large %" PRIu32 " - max %d",
764 : : p_adapter_id_str, word_cnt, (1 << RAB_CNT_BW));
765 : : res = -1;
766 : 0 : goto exit_unlock_res;
767 : : }
768 : :
769 : : /* Read buffer free register */
770 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, &buf_free);
771 : :
772 : 0 : in_buf_free = buf_free & p->RAC_RAB_BUF_FREE_IB_FREE_MASK;
773 : 0 : out_buf_free = (buf_free & p->RAC_RAB_BUF_FREE_OB_FREE_MASK) >> 16;
774 : :
775 : : /* Read buffer used register */
776 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, &buf_used);
777 : :
778 : : buf_used =
779 : 0 : buf_used & (p->RAC_RAB_BUF_USED_IB_USED_MASK | p->RAC_RAB_BUF_USED_OB_USED_MASK);
780 : :
781 : : /*
782 : : * Verify that output buffer can hold the number of words to be read,
783 : : * input buffer can hold one read command
784 : : * and that the input and output "used" buffer is 0
785 : : */
786 [ # # # # ]: 0 : if (out_buf_free >= word_cnt && in_buf_free >= 1 && buf_used == 0) {
787 : : const uint32_t rab_oper_cmpl = (RAB_COMPLETION << RAB_OPR_LO);
788 : : uint32_t rab_read_oper_cmpl;
789 : 0 : uint32_t word_cnt_expected = word_cnt + 1;
790 : : uint32_t rab_oper_rd;
791 : :
792 : 0 : rab_oper_rd = (RAB_READ << RAB_OPR_LO) |
793 : 0 : ((word_cnt & ((1 << RAB_CNT_BW) - 1)) << RAB_CNT_LO) |
794 : 0 : (bus_id << RAB_BUSID_LO) | address;
795 : :
796 [ # # ]: 0 : if (trc) {
797 : 0 : rab_oper_rd |= (RAB_ECHO << RAB_OPR_LO);
798 : 0 : word_cnt_expected++;
799 : : }
800 : :
801 : : /* Write command */
802 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_IB_DATA_ADDR, rab_oper_rd);
803 : :
804 : : /* Write completion command */
805 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_IB_DATA_ADDR, rab_oper_cmpl);
806 : :
807 : : /* Wait until done */
808 [ # # ]: 0 : if (_nthw_rac_wait_for_rab_done(p, address, word_cnt_expected)) {
809 : : res = -1;
810 : 0 : goto exit_unlock_res;
811 : : }
812 : :
813 [ # # ]: 0 : if (trc) {
814 : : uint32_t rab_echo_oper_rd;
815 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR,
816 : : &rab_echo_oper_rd);
817 : :
818 [ # # ]: 0 : if (p->mn_param_rac_rab_ob_update)
819 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, 0);
820 : :
821 [ # # ]: 0 : if (rab_oper_rd != rab_echo_oper_rd) {
822 : 0 : NT_LOG(ERR, NTHW,
823 : : "%s: RAB: expected rab read echo oper (0x%08X) - read (0x%08X)",
824 : : p_adapter_id_str, rab_oper_rd, rab_echo_oper_rd);
825 : : }
826 : : }
827 : :
828 : : {
829 : : /* Read data from output buffer */
830 : : uint32_t i;
831 : :
832 [ # # ]: 0 : for (i = 0; i < word_cnt; i++) {
833 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR,
834 : 0 : &p_data[i]);
835 : :
836 [ # # ]: 0 : if (p->mn_param_rac_rab_ob_update) {
837 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR,
838 : : 0);
839 : : }
840 : : }
841 : :
842 [ # # ]: 0 : if (trc) {
843 : 0 : char *tmp_string = ntlog_helper_str_alloc("Register::read");
844 : 0 : ntlog_helper_str_add(tmp_string,
845 : : "(Dev: NA, Bus: RAB%u, Addr: 0x%08X, Cnt: %d, Data:",
846 : : bus_id, address, word_cnt);
847 : :
848 [ # # ]: 0 : for (i = 0; i < word_cnt; i++)
849 : 0 : ntlog_helper_str_add(tmp_string, " 0x%08X", p_data[i]);
850 : :
851 : 0 : ntlog_helper_str_add(tmp_string, ")");
852 : 0 : NT_LOG(DBG, NTHW, "%s", tmp_string);
853 : 0 : ntlog_helper_str_free(tmp_string);
854 : : }
855 : : }
856 : :
857 : : /* Read completion from out buffer */
858 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, &rab_read_oper_cmpl);
859 : :
860 [ # # ]: 0 : if (p->mn_param_rac_rab_ob_update)
861 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_OB_DATA_ADDR, 0);
862 : :
863 [ # # ]: 0 : if (rab_read_oper_cmpl != rab_oper_cmpl) {
864 : 0 : NT_LOG(ERR, NTHW,
865 : : "%s: RAB: Unexpected value of completion (0x%08X)- inBufFree: 0x%08X, outBufFree: 0x%08X, bufUsed: 0x%08X",
866 : : p_adapter_id_str, rab_read_oper_cmpl, in_buf_free, out_buf_free,
867 : : buf_used);
868 : : res = -1;
869 : 0 : goto exit_unlock_res;
870 : : }
871 : :
872 : : /* Read buffer free register */
873 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, &buf_free);
874 : :
875 [ # # ]: 0 : if (buf_free & 0x80000000) {
876 : : /* Clear Timeout and overflow bits */
877 : : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, 0x0);
878 : 0 : NT_LOG(ERR, NTHW,
879 : : "%s: RAB: timeout - Access outside register - bus: %d addr: 0x%08X - inBufFree: 0x%08X, outBufFree: 0x%08X, bufUsed: 0x%08X",
880 : : p_adapter_id_str, bus_id, address, in_buf_free, out_buf_free,
881 : : buf_used);
882 : : res = -1;
883 : 0 : goto exit_unlock_res;
884 : : }
885 : :
886 : : res = 0;
887 : 0 : goto exit_unlock_res;
888 : :
889 : : } else {
890 : 0 : NT_LOG(ERR, NTHW,
891 : : "%s: RAB: Fail rab bus buffer check - bus: %d addr: 0x%08X wordcount: %d - inBufFree: 0x%08X, outBufFree: 0x%08X, bufUsed: 0x%08X",
892 : : p_adapter_id_str, bus_id, address, word_cnt, in_buf_free, out_buf_free,
893 : : buf_used);
894 : : res = -1;
895 : 0 : goto exit_unlock_res;
896 : : }
897 : :
898 : 0 : exit_unlock_res:
899 : : rte_spinlock_unlock(&p->m_mutex);
900 : 0 : return res;
901 : : }
902 : :
903 : 0 : int nthw_rac_rab_flush(nthw_rac_t *p)
904 : : {
905 : 0 : const struct fpga_info_s *const p_fpga_info = p->mp_fpga->p_fpga_info;
906 : 0 : const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
907 : : uint32_t data = 0;
908 : : uint32_t retry;
909 : : int res = 0;
910 : :
911 : 0 : rte_spinlock_lock(&p->m_mutex);
912 : :
913 : : /* Set the flush bit */
914 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR,
915 : : p->RAC_RAB_BUF_USED_FLUSH_MASK);
916 : :
917 : : /* Reset BUF FREE register */
918 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_FREE_ADDR, 0x0);
919 : :
920 : : /* Wait until OB_USED and IB_USED are 0 */
921 [ # # ]: 0 : for (retry = 0; retry < 100000; retry++) {
922 : 0 : nthw_rac_reg_read32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, &data);
923 : :
924 [ # # ]: 0 : if ((data & 0xFFFFFFFF) == p->RAC_RAB_BUF_USED_FLUSH_MASK)
925 : : break;
926 : : }
927 : :
928 [ # # ]: 0 : if (data != p->RAC_RAB_BUF_USED_FLUSH_MASK) {
929 : 0 : NT_LOG(ERR, NTHW, "%s: RAB: Rab bus flush error.", p_adapter_id_str);
930 : : res = -1;
931 : : }
932 : :
933 : : /* Clear flush bit when done */
934 : 0 : nthw_rac_reg_write32(p_fpga_info, p->RAC_RAB_BUF_USED_ADDR, 0x0);
935 : :
936 : : rte_spinlock_unlock(&p->m_mutex);
937 : 0 : return res;
938 : : }
|