xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_ooo.c (revision 685dc743)
1 /*
2  * Copyright (c) 2018-2019 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * File : ecore_ooo.c
30  */
31 #include <sys/cdefs.h>
32 #include "bcm_osal.h"
33 
34 #include "ecore.h"
35 #include "ecore_status.h"
36 #include "ecore_ll2.h"
37 #include "ecore_ooo.h"
38 #include "ecore_iscsi.h"
39 #include "ecore_cxt.h"
40 /*
41  * Static OOO functions
42  */
43 
44 static struct ecore_ooo_archipelago *
ecore_ooo_seek_archipelago(struct ecore_ooo_info * p_ooo_info,u32 cid)45 ecore_ooo_seek_archipelago(struct ecore_ooo_info *p_ooo_info, u32 cid)
46 {
47 	u32 idx = (cid & 0xffff) - p_ooo_info->cid_base;
48 	struct ecore_ooo_archipelago *p_archipelago;
49 
50 	if (idx >= p_ooo_info->max_num_archipelagos)
51 		return OSAL_NULL;
52 
53 	p_archipelago = &p_ooo_info->p_archipelagos_mem[idx];
54 
55 	if (OSAL_LIST_IS_EMPTY(&p_archipelago->isles_list))
56 		return OSAL_NULL;
57 
58 	return p_archipelago;
59 }
60 
ecore_ooo_seek_isle(struct ecore_hwfn * p_hwfn,struct ecore_ooo_info * p_ooo_info,u32 cid,u8 isle)61 static struct ecore_ooo_isle *ecore_ooo_seek_isle(struct ecore_hwfn *p_hwfn,
62 						  struct ecore_ooo_info *p_ooo_info,
63 						  u32 cid, u8 isle)
64 {
65 	struct ecore_ooo_archipelago *p_archipelago = OSAL_NULL;
66 	struct ecore_ooo_isle *p_isle = OSAL_NULL;
67 	u8 the_num_of_isle = 1;
68 
69 	p_archipelago = ecore_ooo_seek_archipelago(p_ooo_info, cid);
70 	if (!p_archipelago) {
71 		DP_NOTICE(p_hwfn, true,
72 			 "Connection %d is not found in OOO list\n", cid);
73 		return OSAL_NULL;
74 	}
75 
76 	OSAL_LIST_FOR_EACH_ENTRY(p_isle,
77 				 &p_archipelago->isles_list,
78 				 list_entry, struct ecore_ooo_isle) {
79 		if (the_num_of_isle == isle)
80 			return p_isle;
81 		the_num_of_isle++;
82 	}
83 
84 	return OSAL_NULL;
85 }
86 
ecore_ooo_save_history_entry(struct ecore_ooo_info * p_ooo_info,struct ooo_opaque * p_cqe)87 void ecore_ooo_save_history_entry(struct ecore_ooo_info *p_ooo_info,
88 				  struct ooo_opaque *p_cqe)
89 {
90 	struct ecore_ooo_history *p_history = &p_ooo_info->ooo_history;
91 
92 	if (p_history->head_idx == p_history->num_of_cqes)
93 			p_history->head_idx = 0;
94 	p_history->p_cqes[p_history->head_idx] = *p_cqe;
95 	p_history->head_idx++;
96 }
97 
98 //#ifdef CONFIG_ECORE_ISCSI
99 #if defined(CONFIG_ECORE_ISCSI) || defined(CONFIG_ECORE_IWARP)
ecore_ooo_alloc(struct ecore_hwfn * p_hwfn)100 enum _ecore_status_t ecore_ooo_alloc(struct ecore_hwfn *p_hwfn)
101 {
102 	u16 max_num_archipelagos = 0, cid_base;
103 	struct ecore_ooo_info *p_ooo_info;
104 	u16 max_num_isles = 0;
105 	u32 i;
106 
107 	switch (p_hwfn->hw_info.personality) {
108 	case ECORE_PCI_ISCSI:
109 		max_num_archipelagos =
110 			p_hwfn->pf_params.iscsi_pf_params.num_cons;
111 		cid_base =(u16)ecore_cxt_get_proto_cid_start(p_hwfn,
112 							     PROTOCOLID_ISCSI);
113 		break;
114 	case ECORE_PCI_ETH_RDMA:
115 	case ECORE_PCI_ETH_IWARP:
116 		max_num_archipelagos =
117 			(u16)ecore_cxt_get_proto_cid_count(p_hwfn,
118 							   PROTOCOLID_IWARP,
119 							   OSAL_NULL);
120 		cid_base = (u16)ecore_cxt_get_proto_cid_start(p_hwfn,
121 							      PROTOCOLID_IWARP);
122 		break;
123 	default:
124 		DP_NOTICE(p_hwfn, true,
125 			  "Failed to allocate ecore_ooo_info: unknown personalization\n");
126 		return ECORE_INVAL;
127 	}
128 
129 	max_num_isles = ECORE_MAX_NUM_ISLES + max_num_archipelagos;
130 
131 	if (!max_num_archipelagos) {
132 		DP_NOTICE(p_hwfn, true,
133 			  "Failed to allocate ecore_ooo_info: unknown amount of connections\n");
134 		return ECORE_INVAL;
135 	}
136 
137 	p_ooo_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
138 				 sizeof(*p_ooo_info));
139 	if (!p_ooo_info) {
140 		DP_NOTICE(p_hwfn, true, "Failed to allocate ecore_ooo_info\n");
141 		return ECORE_NOMEM;
142 	}
143 	p_ooo_info->cid_base = cid_base; /* We look only at the icid */
144 	p_ooo_info->max_num_archipelagos = max_num_archipelagos;
145 
146 	OSAL_LIST_INIT(&p_ooo_info->free_buffers_list);
147 	OSAL_LIST_INIT(&p_ooo_info->ready_buffers_list);
148 	OSAL_LIST_INIT(&p_ooo_info->free_isles_list);
149 
150 	p_ooo_info->p_isles_mem =
151 		OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
152 			    sizeof(struct ecore_ooo_isle) *
153 			    max_num_isles);
154 	if (!p_ooo_info->p_isles_mem) {
155 		DP_NOTICE(p_hwfn,true,
156 			  "Failed to allocate ecore_ooo_info (isles)\n");
157 		goto no_isles_mem;
158 	}
159 
160 	for (i = 0; i < max_num_isles; i++) {
161 		OSAL_LIST_INIT(&p_ooo_info->p_isles_mem[i].buffers_list);
162 		OSAL_LIST_PUSH_TAIL(&p_ooo_info->p_isles_mem[i].list_entry,
163 				    &p_ooo_info->free_isles_list);
164 	}
165 
166 	p_ooo_info->p_archipelagos_mem =
167 		OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
168 			    sizeof(struct ecore_ooo_archipelago) *
169 			    max_num_archipelagos);
170 	if (!p_ooo_info->p_archipelagos_mem) {
171 		DP_NOTICE(p_hwfn,true,
172 			 "Failed to allocate ecore_ooo_info(archpelagos)\n");
173 		goto no_archipelagos_mem;
174 	}
175 
176 	for (i = 0; i < max_num_archipelagos; i++) {
177 		OSAL_LIST_INIT(&p_ooo_info->p_archipelagos_mem[i].isles_list);
178 	}
179 
180 	p_ooo_info->ooo_history.p_cqes =
181 		OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
182 			    sizeof(struct ooo_opaque) *
183 			    ECORE_MAX_NUM_OOO_HISTORY_ENTRIES);
184 	if (!p_ooo_info->ooo_history.p_cqes) {
185 		DP_NOTICE(p_hwfn,true,
186 			  "Failed to allocate ecore_ooo_info(history)\n");
187 		goto no_history_mem;
188 	}
189 	p_ooo_info->ooo_history.num_of_cqes =
190 		ECORE_MAX_NUM_OOO_HISTORY_ENTRIES;
191 
192 	p_hwfn->p_ooo_info = p_ooo_info;
193 	return ECORE_SUCCESS;
194 
195 no_history_mem:
196 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info->p_archipelagos_mem);
197 no_archipelagos_mem:
198 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info->p_isles_mem);
199 no_isles_mem:
200 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info);
201 	return ECORE_NOMEM;
202 }
203 #endif
204 
ecore_ooo_release_connection_isles(struct ecore_ooo_info * p_ooo_info,u32 cid)205 void ecore_ooo_release_connection_isles(struct ecore_ooo_info *p_ooo_info,
206 					u32 cid)
207 {
208 	struct ecore_ooo_archipelago *p_archipelago;
209 	struct ecore_ooo_buffer *p_buffer;
210 	struct ecore_ooo_isle *p_isle;
211 
212 	p_archipelago = ecore_ooo_seek_archipelago(p_ooo_info, cid);
213 	if (!p_archipelago)
214 		return;
215 
216 	while (!OSAL_LIST_IS_EMPTY(&p_archipelago->isles_list)) {
217 		p_isle = OSAL_LIST_FIRST_ENTRY(
218 				&p_archipelago->isles_list,
219 				struct ecore_ooo_isle, list_entry);
220 
221 #if defined(_NTDDK_)
222 #pragma warning(suppress : 6011 28182)
223 #endif
224 		OSAL_LIST_REMOVE_ENTRY(&p_isle->list_entry,
225 				       &p_archipelago->isles_list);
226 
227 		while (!OSAL_LIST_IS_EMPTY(&p_isle->buffers_list)) {
228 			p_buffer =
229 				OSAL_LIST_FIRST_ENTRY(
230 				&p_isle->buffers_list ,
231 				struct ecore_ooo_buffer, list_entry);
232 
233 			if (p_buffer == OSAL_NULL)
234 				break;
235 #if defined(_NTDDK_)
236 #pragma warning(suppress : 6011 28182)
237 #endif
238 			OSAL_LIST_REMOVE_ENTRY(&p_buffer->list_entry,
239 				      	       &p_isle->buffers_list);
240 				OSAL_LIST_PUSH_TAIL(&p_buffer->list_entry,
241 						&p_ooo_info->free_buffers_list);
242 			}
243 			OSAL_LIST_PUSH_TAIL(&p_isle->list_entry,
244 					&p_ooo_info->free_isles_list);
245 		}
246 
247 }
248 
ecore_ooo_release_all_isles(struct ecore_ooo_info * p_ooo_info)249 void ecore_ooo_release_all_isles(struct ecore_ooo_info *p_ooo_info)
250 {
251 	struct ecore_ooo_archipelago *p_archipelago;
252 	struct ecore_ooo_buffer *p_buffer;
253 	struct ecore_ooo_isle *p_isle;
254 	u32 i;
255 
256 	for (i = 0; i < p_ooo_info->max_num_archipelagos; i++) {
257 		p_archipelago = &(p_ooo_info->p_archipelagos_mem[i]);
258 
259 #if defined(_NTDDK_)
260 #pragma warning(suppress : 6011 28182)
261 #endif
262 		while (!OSAL_LIST_IS_EMPTY(&p_archipelago->isles_list)) {
263 			p_isle = OSAL_LIST_FIRST_ENTRY(
264 					&p_archipelago->isles_list,
265 					struct ecore_ooo_isle, list_entry);
266 
267 #if defined(_NTDDK_)
268 #pragma warning(suppress : 6011 28182)
269 #endif
270 			OSAL_LIST_REMOVE_ENTRY(&p_isle->list_entry,
271 					       &p_archipelago->isles_list);
272 
273 			while (!OSAL_LIST_IS_EMPTY(&p_isle->buffers_list)) {
274 				p_buffer =
275 					OSAL_LIST_FIRST_ENTRY(
276 					&p_isle->buffers_list ,
277 					struct ecore_ooo_buffer, list_entry);
278 
279 				if (p_buffer == OSAL_NULL)
280 					break;
281 #if defined(_NTDDK_)
282 #pragma warning(suppress : 6011 28182)
283 #endif
284 				OSAL_LIST_REMOVE_ENTRY(&p_buffer->list_entry,
285 						      &p_isle->buffers_list);
286 				OSAL_LIST_PUSH_TAIL(&p_buffer->list_entry,
287 					&p_ooo_info->free_buffers_list);
288 			}
289 			OSAL_LIST_PUSH_TAIL(&p_isle->list_entry,
290 				&p_ooo_info->free_isles_list);
291 		}
292 	}
293 	if (!OSAL_LIST_IS_EMPTY(&p_ooo_info->ready_buffers_list)) {
294 		OSAL_LIST_SPLICE_TAIL_INIT(&p_ooo_info->ready_buffers_list,
295 					  &p_ooo_info->free_buffers_list);
296 	}
297 }
298 
299 //#ifdef CONFIG_ECORE_ISCSI
300 #if defined(CONFIG_ECORE_ISCSI) || defined(CONFIG_ECORE_IWARP)
ecore_ooo_setup(struct ecore_hwfn * p_hwfn)301 void ecore_ooo_setup(struct ecore_hwfn *p_hwfn)
302 {
303 	ecore_ooo_release_all_isles(p_hwfn->p_ooo_info);
304 	OSAL_MEM_ZERO(p_hwfn->p_ooo_info->ooo_history.p_cqes,
305 		      p_hwfn->p_ooo_info->ooo_history.num_of_cqes *
306 		      sizeof(struct ooo_opaque));
307 	p_hwfn->p_ooo_info->ooo_history.head_idx = 0;
308 }
309 
ecore_ooo_free(struct ecore_hwfn * p_hwfn)310 void ecore_ooo_free(struct ecore_hwfn *p_hwfn)
311 {
312 	struct ecore_ooo_info *p_ooo_info = p_hwfn->p_ooo_info;
313 	struct ecore_ooo_buffer *p_buffer;
314 
315 	if (!p_ooo_info)
316 		return;
317 
318 	ecore_ooo_release_all_isles(p_ooo_info);
319 	while (!OSAL_LIST_IS_EMPTY(&p_ooo_info->free_buffers_list)) {
320 		p_buffer = OSAL_LIST_FIRST_ENTRY(&p_ooo_info->
321 						 free_buffers_list,
322 						 struct ecore_ooo_buffer,
323 						 list_entry);
324 		if (p_buffer == OSAL_NULL)
325 			break;
326 #if defined(_NTDDK_)
327 #pragma warning(suppress : 6011 28182)
328 #endif
329 		OSAL_LIST_REMOVE_ENTRY(&p_buffer->list_entry,
330 				       &p_ooo_info->free_buffers_list);
331 		OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
332 				       p_buffer->rx_buffer_virt_addr,
333 				       p_buffer->rx_buffer_phys_addr,
334 				       p_buffer->rx_buffer_size);
335 		OSAL_FREE(p_hwfn->p_dev, p_buffer);
336 	}
337 
338 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info->p_isles_mem);
339 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info->p_archipelagos_mem);
340 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info->ooo_history.p_cqes);
341 	OSAL_FREE(p_hwfn->p_dev, p_ooo_info);
342 	p_hwfn->p_ooo_info = OSAL_NULL;
343 }
344 #endif
345 
ecore_ooo_put_free_buffer(struct ecore_ooo_info * p_ooo_info,struct ecore_ooo_buffer * p_buffer)346 void ecore_ooo_put_free_buffer(struct ecore_ooo_info *p_ooo_info,
347 			       struct ecore_ooo_buffer *p_buffer)
348 {
349 	OSAL_LIST_PUSH_TAIL(&p_buffer->list_entry,
350 			    &p_ooo_info->free_buffers_list);
351 }
352 
353 struct ecore_ooo_buffer *
ecore_ooo_get_free_buffer(struct ecore_ooo_info * p_ooo_info)354 ecore_ooo_get_free_buffer(struct ecore_ooo_info *p_ooo_info)
355 {
356 	struct ecore_ooo_buffer	*p_buffer = OSAL_NULL;
357 
358 	if (!OSAL_LIST_IS_EMPTY(&p_ooo_info->free_buffers_list)) {
359 		p_buffer =
360 			OSAL_LIST_FIRST_ENTRY(
361 			&p_ooo_info->free_buffers_list,
362 			struct ecore_ooo_buffer, list_entry);
363 
364 		OSAL_LIST_REMOVE_ENTRY(&p_buffer->list_entry,
365 				      &p_ooo_info->free_buffers_list);
366 	}
367 
368 	return p_buffer;
369 }
370 
ecore_ooo_put_ready_buffer(struct ecore_ooo_info * p_ooo_info,struct ecore_ooo_buffer * p_buffer,u8 on_tail)371 void ecore_ooo_put_ready_buffer(struct ecore_ooo_info *p_ooo_info,
372 				struct ecore_ooo_buffer *p_buffer, u8 on_tail)
373 {
374 	if (on_tail) {
375 		OSAL_LIST_PUSH_TAIL(&p_buffer->list_entry,
376 				   &p_ooo_info->ready_buffers_list);
377 	} else {
378 		OSAL_LIST_PUSH_HEAD(&p_buffer->list_entry,
379 				   &p_ooo_info->ready_buffers_list);
380 	}
381 }
382 
383 struct ecore_ooo_buffer *
ecore_ooo_get_ready_buffer(struct ecore_ooo_info * p_ooo_info)384 ecore_ooo_get_ready_buffer(struct ecore_ooo_info *p_ooo_info)
385 {
386 	struct ecore_ooo_buffer	*p_buffer = OSAL_NULL;
387 
388 	if (!OSAL_LIST_IS_EMPTY(&p_ooo_info->ready_buffers_list)) {
389 		p_buffer =
390 			OSAL_LIST_FIRST_ENTRY(
391 			&p_ooo_info->ready_buffers_list,
392 			struct ecore_ooo_buffer, list_entry);
393 
394 		OSAL_LIST_REMOVE_ENTRY(&p_buffer->list_entry,
395 				      &p_ooo_info->ready_buffers_list);
396 	}
397 
398 	return p_buffer;
399 }
400 
ecore_ooo_delete_isles(struct ecore_hwfn * p_hwfn,struct ecore_ooo_info * p_ooo_info,u32 cid,u8 drop_isle,u8 drop_size)401 void ecore_ooo_delete_isles(struct ecore_hwfn *p_hwfn,
402 			   struct ecore_ooo_info *p_ooo_info,
403 			   u32 cid,
404 			   u8 drop_isle,
405 			   u8 drop_size)
406 {
407 	struct ecore_ooo_archipelago *p_archipelago = OSAL_NULL;
408 	struct ecore_ooo_isle *p_isle = OSAL_NULL;
409 	u8 isle_idx;
410 
411 	p_archipelago = ecore_ooo_seek_archipelago(p_ooo_info, cid);
412 	for (isle_idx = 0; isle_idx < drop_size; isle_idx++) {
413 		p_isle = ecore_ooo_seek_isle(p_hwfn, p_ooo_info,
414 					    cid, drop_isle);
415 		if (!p_isle) {
416 			DP_NOTICE(p_hwfn, true,
417 				 "Isle %d is not found(cid %d)\n",
418 				 drop_isle, cid);
419 			return;
420 		}
421 		if (OSAL_LIST_IS_EMPTY(&p_isle->buffers_list)) {
422 			DP_NOTICE(p_hwfn, true,
423 				 "Isle %d is empty(cid %d)\n",
424 				 drop_isle, cid);
425 		} else {
426 			OSAL_LIST_SPLICE_TAIL_INIT(&p_isle->buffers_list,
427 					&p_ooo_info->free_buffers_list);
428 		}
429 #if defined(_NTDDK_)
430 #pragma warning(suppress : 6011)
431 #endif
432 		OSAL_LIST_REMOVE_ENTRY(&p_isle->list_entry,
433 				      &p_archipelago->isles_list);
434 		p_ooo_info->cur_isles_number--;
435 		OSAL_LIST_PUSH_HEAD(&p_isle->list_entry,
436 				   &p_ooo_info->free_isles_list);
437 	}
438 }
439 
ecore_ooo_add_new_isle(struct ecore_hwfn * p_hwfn,struct ecore_ooo_info * p_ooo_info,u32 cid,u8 ooo_isle,struct ecore_ooo_buffer * p_buffer)440 void ecore_ooo_add_new_isle(struct ecore_hwfn *p_hwfn,
441 			   struct ecore_ooo_info *p_ooo_info,
442 			   u32 cid, u8 ooo_isle,
443 			   struct ecore_ooo_buffer *p_buffer)
444 {
445 	struct ecore_ooo_archipelago *p_archipelago = OSAL_NULL;
446 	struct ecore_ooo_isle *p_prev_isle = OSAL_NULL;
447 	struct ecore_ooo_isle *p_isle = OSAL_NULL;
448 
449 	if (ooo_isle > 1) {
450 		p_prev_isle = ecore_ooo_seek_isle(p_hwfn, p_ooo_info, cid, ooo_isle - 1);
451 		if (!p_prev_isle) {
452 			DP_NOTICE(p_hwfn, true,
453 				 "Isle %d is not found(cid %d)\n",
454 				 ooo_isle - 1, cid);
455 			return;
456 		}
457 	}
458 	p_archipelago = ecore_ooo_seek_archipelago(p_ooo_info, cid);
459 	if (!p_archipelago && (ooo_isle != 1)) {
460 		DP_NOTICE(p_hwfn, true,
461 			 "Connection %d is not found in OOO list\n", cid);
462 		return;
463 	}
464 
465 	if (!OSAL_LIST_IS_EMPTY(&p_ooo_info->free_isles_list)) {
466 		p_isle =
467 			OSAL_LIST_FIRST_ENTRY(
468 			&p_ooo_info->free_isles_list,
469 			struct ecore_ooo_isle, list_entry);
470 
471 		OSAL_LIST_REMOVE_ENTRY(&p_isle->list_entry,
472 				      &p_ooo_info->free_isles_list);
473 		if (!OSAL_LIST_IS_EMPTY(&p_isle->buffers_list)) {
474 			DP_NOTICE(p_hwfn, true, "Free isle is not empty\n");
475 			OSAL_LIST_INIT(&p_isle->buffers_list);
476 		}
477 	} else {
478 		DP_NOTICE(p_hwfn, true, "No more free isles\n");
479 		return;
480 	}
481 
482 	if (!p_archipelago) {
483 		u32 idx = (cid & 0xffff) - p_ooo_info->cid_base;
484 
485 		p_archipelago = &p_ooo_info->p_archipelagos_mem[idx];
486 	}
487 	OSAL_LIST_PUSH_HEAD(&p_buffer->list_entry, &p_isle->buffers_list);
488 	p_ooo_info->cur_isles_number++;
489 	p_ooo_info->gen_isles_number++;
490 	if (p_ooo_info->cur_isles_number > p_ooo_info->max_isles_number)
491 		p_ooo_info->max_isles_number = p_ooo_info->cur_isles_number;
492 	if (!p_prev_isle) {
493 		OSAL_LIST_PUSH_HEAD(&p_isle->list_entry, &p_archipelago->isles_list);
494 	} else {
495 		OSAL_LIST_INSERT_ENTRY_AFTER(&p_isle->list_entry,
496 			                    &p_prev_isle->list_entry,
497 					    &p_archipelago->isles_list);
498 	}
499 }
500 
ecore_ooo_add_new_buffer(struct ecore_hwfn * p_hwfn,struct ecore_ooo_info * p_ooo_info,u32 cid,u8 ooo_isle,struct ecore_ooo_buffer * p_buffer,u8 buffer_side)501 void ecore_ooo_add_new_buffer(struct ecore_hwfn	*p_hwfn,
502 			     struct ecore_ooo_info *p_ooo_info,
503 			     u32 cid,
504 			     u8 ooo_isle,
505 			     struct ecore_ooo_buffer *p_buffer,
506 		             u8 buffer_side)
507 {
508 	struct ecore_ooo_isle	* p_isle = OSAL_NULL;
509 	p_isle = ecore_ooo_seek_isle(p_hwfn, p_ooo_info, cid, ooo_isle);
510 	if (!p_isle) {
511 		DP_NOTICE(p_hwfn, true,
512 			 "Isle %d is not found(cid %d)\n",
513 			 ooo_isle, cid);
514 		return;
515 	}
516 	if (buffer_side == ECORE_OOO_LEFT_BUF) {
517 		OSAL_LIST_PUSH_HEAD(&p_buffer->list_entry,
518 				   &p_isle->buffers_list);
519 	} else {
520 		OSAL_LIST_PUSH_TAIL(&p_buffer->list_entry,
521 				   &p_isle->buffers_list);
522 	}
523 }
524 
ecore_ooo_join_isles(struct ecore_hwfn * p_hwfn,struct ecore_ooo_info * p_ooo_info,u32 cid,u8 left_isle)525 void ecore_ooo_join_isles(struct ecore_hwfn *p_hwfn,
526 			  struct ecore_ooo_info *p_ooo_info,
527 			  u32 cid, u8 left_isle)
528 {
529 	struct ecore_ooo_archipelago *p_archipelago = OSAL_NULL;
530 	struct ecore_ooo_isle *p_right_isle = OSAL_NULL;
531 	struct ecore_ooo_isle *p_left_isle = OSAL_NULL;
532 
533 	p_right_isle = ecore_ooo_seek_isle(p_hwfn, p_ooo_info, cid,
534 					  left_isle + 1);
535 	if (!p_right_isle) {
536 		DP_NOTICE(p_hwfn, true,
537 			 "Right isle %d is not found(cid %d)\n",
538 			 left_isle + 1, cid);
539 		return;
540 	}
541 	p_archipelago = ecore_ooo_seek_archipelago(p_ooo_info, cid);
542 	OSAL_LIST_REMOVE_ENTRY(&p_right_isle->list_entry,
543 			      &p_archipelago->isles_list);
544 	p_ooo_info->cur_isles_number--;
545 	if (left_isle) {
546 		p_left_isle = ecore_ooo_seek_isle(p_hwfn, p_ooo_info, cid,
547 						 left_isle);
548 		if (!p_left_isle) {
549 			DP_NOTICE(p_hwfn, true,
550 				 "Left isle %d is not found(cid %d)\n",
551 				 left_isle, cid);
552 			return;
553 		}
554 		OSAL_LIST_SPLICE_TAIL_INIT(&p_right_isle->buffers_list,
555 					  &p_left_isle->buffers_list);
556 	} else {
557 		OSAL_LIST_SPLICE_TAIL_INIT(&p_right_isle->buffers_list,
558 					  &p_ooo_info->ready_buffers_list);
559 	}
560 	OSAL_LIST_PUSH_TAIL(&p_right_isle->list_entry,
561 			   &p_ooo_info->free_isles_list);
562 }
563 
ecore_ooo_dump_rx_event(struct ecore_hwfn * p_hwfn,struct ooo_opaque * iscsi_ooo,struct ecore_ooo_buffer * p_buffer)564 void ecore_ooo_dump_rx_event(struct ecore_hwfn	*p_hwfn,
565 			     struct ooo_opaque *iscsi_ooo,
566 			     struct ecore_ooo_buffer *p_buffer)
567 {
568 	int i;
569 	u32 dp_module = ECORE_MSG_OOO;
570 	u32 ph_hi, ph_lo;
571 	u8 *packet_buffer = 0;
572 
573 	if (p_hwfn->dp_level > ECORE_LEVEL_VERBOSE)
574 		return;
575 	if (!(p_hwfn->dp_module & dp_module))
576 		return;
577 
578 	packet_buffer = (u8 *)p_buffer->rx_buffer_virt_addr +
579 		p_buffer->placement_offset;
580 	DP_VERBOSE(p_hwfn, dp_module,
581 		   "******************************************************\n");
582 	ph_hi = DMA_HI(p_buffer->rx_buffer_phys_addr);
583 	ph_lo = DMA_LO(p_buffer->rx_buffer_phys_addr);
584 	DP_VERBOSE(p_hwfn, dp_module,
585 		   "0x%x-%x: CID 0x%x, OP 0x%x, ISLE 0x%x\n",
586 		   ph_hi, ph_lo,
587 		   iscsi_ooo->cid, iscsi_ooo->ooo_opcode, iscsi_ooo->ooo_isle);
588 	for (i = 0; i < 64; i = i + 8) {
589 		DP_VERBOSE(p_hwfn, dp_module,
590 			   "0x%x-%x:  0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
591 			   ph_hi, ph_lo,
592 			   packet_buffer[i],
593 			   packet_buffer[i + 1],
594 			   packet_buffer[i + 2],
595 			   packet_buffer[i + 3],
596 			   packet_buffer[i + 4],
597 			   packet_buffer[i + 5],
598 			   packet_buffer[i + 6],
599 			   packet_buffer[i + 7]);
600 	}
601 }
602