2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
11 #include "ecore_gtt_reg_addr.h"
12 #include "ecore_hsi_common.h"
14 #include "ecore_sp_api.h"
15 #include "ecore_spq.h"
16 #include "ecore_iro.h"
17 #include "ecore_init_fw_funcs.h"
18 #include "ecore_cxt.h"
19 #include "ecore_int.h"
20 #include "ecore_dev_api.h"
21 #include "ecore_mcp.h"
23 #include "ecore_sriov.h"
25 /***************************************************************************
26 * Structures & Definitions
27 ***************************************************************************/
29 #define SPQ_HIGH_PRI_RESERVE_DEFAULT (1)
31 #define SPQ_BLOCK_DELAY_MAX_ITER (10)
32 #define SPQ_BLOCK_DELAY_US (10)
33 #define SPQ_BLOCK_SLEEP_MAX_ITER (1000)
34 #define SPQ_BLOCK_SLEEP_MS (5)
36 /***************************************************************************
37 * Blocking Imp. (BLOCK/EBLOCK mode)
38 ***************************************************************************/
39 static void ecore_spq_blocking_cb(struct ecore_hwfn *p_hwfn,
41 union event_ring_data *data,
44 struct ecore_spq_comp_done *comp_done;
46 comp_done = (struct ecore_spq_comp_done *)cookie;
48 comp_done->done = 0x1;
49 comp_done->fw_return_code = fw_return_code;
51 /* make update visible to waiting thread */
52 OSAL_SMP_WMB(p_hwfn->p_dev);
55 static enum _ecore_status_t __ecore_spq_block(struct ecore_hwfn *p_hwfn,
56 struct ecore_spq_entry *p_ent,
58 bool sleep_between_iter)
60 struct ecore_spq_comp_done *comp_done;
63 comp_done = (struct ecore_spq_comp_done *)p_ent->comp_cb.cookie;
64 iter_cnt = sleep_between_iter ? SPQ_BLOCK_SLEEP_MAX_ITER
65 : SPQ_BLOCK_DELAY_MAX_ITER;
68 OSAL_POLL_MODE_DPC(p_hwfn);
69 OSAL_SMP_RMB(p_hwfn->p_dev);
70 if (comp_done->done == 1) {
72 *p_fw_ret = comp_done->fw_return_code;
76 if (sleep_between_iter)
77 OSAL_MSLEEP(SPQ_BLOCK_SLEEP_MS);
79 OSAL_UDELAY(SPQ_BLOCK_DELAY_US);
85 static enum _ecore_status_t ecore_spq_block(struct ecore_hwfn *p_hwfn,
86 struct ecore_spq_entry *p_ent,
87 u8 *p_fw_ret, bool skip_quick_poll)
89 struct ecore_spq_comp_done *comp_done;
90 enum _ecore_status_t rc;
92 /* A relatively short polling period w/o sleeping, to allow the FW to
93 * complete the ramrod and thus possibly to avoid the following sleeps.
95 if (!skip_quick_poll) {
96 rc = __ecore_spq_block(p_hwfn, p_ent, p_fw_ret, false);
97 if (rc == ECORE_SUCCESS)
101 /* Move to polling with a sleeping period between iterations */
102 rc = __ecore_spq_block(p_hwfn, p_ent, p_fw_ret, true);
103 if (rc == ECORE_SUCCESS)
104 return ECORE_SUCCESS;
106 DP_INFO(p_hwfn, "Ramrod is stuck, requesting MCP drain\n");
107 rc = ecore_mcp_drain(p_hwfn, p_hwfn->p_main_ptt);
108 if (rc != ECORE_SUCCESS) {
109 DP_NOTICE(p_hwfn, true, "MCP drain failed\n");
113 /* Retry after drain */
114 rc = __ecore_spq_block(p_hwfn, p_ent, p_fw_ret, true);
115 if (rc == ECORE_SUCCESS)
116 return ECORE_SUCCESS;
118 comp_done = (struct ecore_spq_comp_done *)p_ent->comp_cb.cookie;
119 if (comp_done->done == 1) {
121 *p_fw_ret = comp_done->fw_return_code;
122 return ECORE_SUCCESS;
125 DP_NOTICE(p_hwfn, true,
126 "Ramrod is stuck [CID %08x cmd %02x proto %02x echo %04x]\n",
127 OSAL_LE32_TO_CPU(p_ent->elem.hdr.cid),
128 p_ent->elem.hdr.cmd_id, p_ent->elem.hdr.protocol_id,
129 OSAL_LE16_TO_CPU(p_ent->elem.hdr.echo));
131 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_RAMROD_FAIL);
136 /***************************************************************************
137 * SPQ entries inner API
138 ***************************************************************************/
139 static enum _ecore_status_t
140 ecore_spq_fill_entry(struct ecore_hwfn *p_hwfn, struct ecore_spq_entry *p_ent)
144 switch (p_ent->comp_mode) {
145 case ECORE_SPQ_MODE_EBLOCK:
146 case ECORE_SPQ_MODE_BLOCK:
147 p_ent->comp_cb.function = ecore_spq_blocking_cb;
149 case ECORE_SPQ_MODE_CB:
152 DP_NOTICE(p_hwfn, true, "Unknown SPQE completion mode %d\n",
157 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
158 "Ramrod header: [CID 0x%08x CMD 0x%02x protocol 0x%02x]"
159 " Data pointer: [%08x:%08x] Completion Mode: %s\n",
160 p_ent->elem.hdr.cid, p_ent->elem.hdr.cmd_id,
161 p_ent->elem.hdr.protocol_id,
162 p_ent->elem.data_ptr.hi, p_ent->elem.data_ptr.lo,
163 D_TRINE(p_ent->comp_mode, ECORE_SPQ_MODE_EBLOCK,
164 ECORE_SPQ_MODE_BLOCK, "MODE_EBLOCK", "MODE_BLOCK",
167 return ECORE_SUCCESS;
170 /***************************************************************************
172 ***************************************************************************/
173 static void ecore_spq_hw_initialize(struct ecore_hwfn *p_hwfn,
174 struct ecore_spq *p_spq)
176 struct ecore_cxt_info cxt_info;
177 struct core_conn_context *p_cxt;
178 enum _ecore_status_t rc;
181 cxt_info.iid = p_spq->cid;
183 rc = ecore_cxt_get_cid_info(p_hwfn, &cxt_info);
186 DP_NOTICE(p_hwfn, true, "Cannot find context info for cid=%d\n",
191 p_cxt = cxt_info.p_cxt;
193 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev)) {
194 SET_FIELD(p_cxt->xstorm_ag_context.flags10,
195 E4_XSTORM_CORE_CONN_AG_CTX_DQ_CF_EN, 1);
196 SET_FIELD(p_cxt->xstorm_ag_context.flags1,
197 E4_XSTORM_CORE_CONN_AG_CTX_DQ_CF_ACTIVE, 1);
198 /* SET_FIELD(p_cxt->xstorm_ag_context.flags10,
199 * E4_XSTORM_CORE_CONN_AG_CTX_SLOW_PATH_EN, 1);
201 SET_FIELD(p_cxt->xstorm_ag_context.flags9,
202 E4_XSTORM_CORE_CONN_AG_CTX_CONSOLID_PROD_CF_EN, 1);
205 /* CDU validation - FIXME currently disabled */
207 /* QM physical queue */
208 physical_q = ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB);
209 p_cxt->xstorm_ag_context.physical_q0 = OSAL_CPU_TO_LE16(physical_q);
211 p_cxt->xstorm_st_context.spq_base_lo =
212 DMA_LO_LE(p_spq->chain.p_phys_addr);
213 p_cxt->xstorm_st_context.spq_base_hi =
214 DMA_HI_LE(p_spq->chain.p_phys_addr);
216 DMA_REGPAIR_LE(p_cxt->xstorm_st_context.consolid_base_addr,
217 p_hwfn->p_consq->chain.p_phys_addr);
220 static enum _ecore_status_t ecore_spq_hw_post(struct ecore_hwfn *p_hwfn,
221 struct ecore_spq *p_spq,
222 struct ecore_spq_entry *p_ent)
224 struct ecore_chain *p_chain = &p_hwfn->p_spq->chain;
225 u16 echo = ecore_chain_get_prod_idx(p_chain);
226 struct slow_path_element *elem;
227 struct core_db_data db;
229 p_ent->elem.hdr.echo = OSAL_CPU_TO_LE16(echo);
230 elem = ecore_chain_produce(p_chain);
232 DP_NOTICE(p_hwfn, true, "Failed to produce from SPQ chain\n");
236 *elem = p_ent->elem; /* struct assignment */
238 /* send a doorbell on the slow hwfn session */
239 OSAL_MEMSET(&db, 0, sizeof(db));
240 SET_FIELD(db.params, CORE_DB_DATA_DEST, DB_DEST_XCM);
241 SET_FIELD(db.params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
242 SET_FIELD(db.params, CORE_DB_DATA_AGG_VAL_SEL,
243 DQ_XCM_CORE_SPQ_PROD_CMD);
244 db.agg_flags = DQ_XCM_CORE_DQ_CF_CMD;
245 db.spq_prod = OSAL_CPU_TO_LE16(ecore_chain_get_prod_idx(p_chain));
247 /* make sure the SPQE is updated before the doorbell */
248 OSAL_WMB(p_hwfn->p_dev);
250 DOORBELL(p_hwfn, DB_ADDR(p_spq->cid, DQ_DEMS_LEGACY),
253 /* make sure doorbell is rang */
254 OSAL_WMB(p_hwfn->p_dev);
256 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
257 "Doorbelled [0x%08x, CID 0x%08x] with Flags: %02x"
258 " agg_params: %02x, prod: %04x\n",
259 DB_ADDR(p_spq->cid, DQ_DEMS_LEGACY), p_spq->cid, db.params,
260 db.agg_flags, ecore_chain_get_prod_idx(p_chain));
262 return ECORE_SUCCESS;
265 /***************************************************************************
266 * Asynchronous events
267 ***************************************************************************/
269 static enum _ecore_status_t
270 ecore_async_event_completion(struct ecore_hwfn *p_hwfn,
271 struct event_ring_entry *p_eqe)
273 switch (p_eqe->protocol_id) {
274 case PROTOCOLID_COMMON:
275 return ecore_sriov_eqe_event(p_hwfn,
277 p_eqe->echo, &p_eqe->data);
280 true, "Unknown Async completion for protocol: %d\n",
286 /***************************************************************************
288 ***************************************************************************/
289 void ecore_eq_prod_update(struct ecore_hwfn *p_hwfn, u16 prod)
291 u32 addr = GTT_BAR0_MAP_REG_USDM_RAM +
292 USTORM_EQE_CONS_OFFSET(p_hwfn->rel_pf_id);
294 REG_WR16(p_hwfn, addr, prod);
296 /* keep prod updates ordered */
297 OSAL_MMIOWB(p_hwfn->p_dev);
300 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn *p_hwfn,
303 struct ecore_eq *p_eq = cookie;
304 struct ecore_chain *p_chain = &p_eq->chain;
305 enum _ecore_status_t rc = 0;
307 /* take a snapshot of the FW consumer */
308 u16 fw_cons_idx = OSAL_LE16_TO_CPU(*p_eq->p_fw_cons);
310 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ, "fw_cons_idx %x\n", fw_cons_idx);
312 /* Need to guarantee the fw_cons index we use points to a usuable
313 * element (to comply with our chain), so our macros would comply
315 if ((fw_cons_idx & ecore_chain_get_usable_per_page(p_chain)) ==
316 ecore_chain_get_usable_per_page(p_chain)) {
317 fw_cons_idx += ecore_chain_get_unusable_per_page(p_chain);
320 /* Complete current segment of eq entries */
321 while (fw_cons_idx != ecore_chain_get_cons_idx(p_chain)) {
322 struct event_ring_entry *p_eqe = ecore_chain_consume(p_chain);
328 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
329 "op %x prot %x res0 %x echo %x fwret %x flags %x\n",
330 p_eqe->opcode, /* Event Opcode */
331 p_eqe->protocol_id, /* Event Protocol ID */
332 p_eqe->reserved0, /* Reserved */
333 /* Echo value from ramrod data on the host */
334 OSAL_LE16_TO_CPU(p_eqe->echo),
335 p_eqe->fw_return_code, /* FW return code for SP
340 if (GET_FIELD(p_eqe->flags, EVENT_RING_ENTRY_ASYNC)) {
341 if (ecore_async_event_completion(p_hwfn, p_eqe))
343 } else if (ecore_spq_completion(p_hwfn,
345 p_eqe->fw_return_code,
350 ecore_chain_recycle_consumed(p_chain);
353 ecore_eq_prod_update(p_hwfn, ecore_chain_get_prod_idx(p_chain));
358 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn *p_hwfn, u16 num_elem)
360 struct ecore_eq *p_eq;
362 /* Allocate EQ struct */
363 p_eq = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_eq));
365 DP_NOTICE(p_hwfn, true,
366 "Failed to allocate `struct ecore_eq'\n");
370 /* Allocate and initialize EQ chain*/
371 if (ecore_chain_alloc(p_hwfn->p_dev,
372 ECORE_CHAIN_USE_TO_PRODUCE,
373 ECORE_CHAIN_MODE_PBL,
374 ECORE_CHAIN_CNT_TYPE_U16,
376 sizeof(union event_ring_element),
377 &p_eq->chain, OSAL_NULL) != ECORE_SUCCESS) {
378 DP_NOTICE(p_hwfn, true, "Failed to allocate eq chain\n");
379 goto eq_allocate_fail;
382 /* register EQ completion on the SP SB */
383 ecore_int_register_cb(p_hwfn, ecore_eq_completion,
384 p_eq, &p_eq->eq_sb_index, &p_eq->p_fw_cons);
387 return ECORE_SUCCESS;
390 OSAL_FREE(p_hwfn->p_dev, p_eq);
394 void ecore_eq_setup(struct ecore_hwfn *p_hwfn)
396 ecore_chain_reset(&p_hwfn->p_eq->chain);
399 void ecore_eq_free(struct ecore_hwfn *p_hwfn)
404 ecore_chain_free(p_hwfn->p_dev, &p_hwfn->p_eq->chain);
406 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_eq);
407 p_hwfn->p_eq = OSAL_NULL;
410 /***************************************************************************
411 * CQE API - manipulate EQ functionality
412 ***************************************************************************/
413 static enum _ecore_status_t ecore_cqe_completion(struct ecore_hwfn *p_hwfn,
414 struct eth_slow_path_rx_cqe
416 enum protocol_type protocol)
418 if (IS_VF(p_hwfn->p_dev))
419 return OSAL_VF_CQE_COMPLETION(p_hwfn, cqe, protocol);
421 /* @@@tmp - it's possible we'll eventually want to handle some
422 * actual commands that can arrive here, but for now this is only
423 * used to complete the ramrod using the echo value on the cqe
425 return ecore_spq_completion(p_hwfn, cqe->echo, 0, OSAL_NULL);
428 enum _ecore_status_t ecore_eth_cqe_completion(struct ecore_hwfn *p_hwfn,
429 struct eth_slow_path_rx_cqe *cqe)
431 enum _ecore_status_t rc;
433 rc = ecore_cqe_completion(p_hwfn, cqe, PROTOCOLID_ETH);
435 DP_NOTICE(p_hwfn, true,
436 "Failed to handle RXQ CQE [cmd 0x%02x]\n",
443 /***************************************************************************
444 * Slow hwfn Queue (spq)
445 ***************************************************************************/
446 void ecore_spq_setup(struct ecore_hwfn *p_hwfn)
448 struct ecore_spq *p_spq = p_hwfn->p_spq;
449 struct ecore_spq_entry *p_virt = OSAL_NULL;
450 dma_addr_t p_phys = 0;
453 OSAL_LIST_INIT(&p_spq->pending);
454 OSAL_LIST_INIT(&p_spq->completion_pending);
455 OSAL_LIST_INIT(&p_spq->free_pool);
456 OSAL_LIST_INIT(&p_spq->unlimited_pending);
457 OSAL_SPIN_LOCK_INIT(&p_spq->lock);
460 p_phys = p_spq->p_phys + OFFSETOF(struct ecore_spq_entry, ramrod);
461 p_virt = p_spq->p_virt;
463 capacity = ecore_chain_get_capacity(&p_spq->chain);
464 for (i = 0; i < capacity; i++) {
465 DMA_REGPAIR_LE(p_virt->elem.data_ptr, p_phys);
467 OSAL_LIST_PUSH_TAIL(&p_virt->list, &p_spq->free_pool);
470 p_phys += sizeof(struct ecore_spq_entry);
474 p_spq->normal_count = 0;
475 p_spq->comp_count = 0;
476 p_spq->comp_sent_count = 0;
477 p_spq->unlimited_pending_count = 0;
479 OSAL_MEM_ZERO(p_spq->p_comp_bitmap,
480 SPQ_COMP_BMAP_SIZE * sizeof(unsigned long));
481 p_spq->comp_bitmap_idx = 0;
483 /* SPQ cid, cannot fail */
484 ecore_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_spq->cid);
485 ecore_spq_hw_initialize(p_hwfn, p_spq);
487 /* reset the chain itself */
488 ecore_chain_reset(&p_spq->chain);
491 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn *p_hwfn)
493 struct ecore_spq_entry *p_virt = OSAL_NULL;
494 struct ecore_spq *p_spq = OSAL_NULL;
495 dma_addr_t p_phys = 0;
500 OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(struct ecore_spq));
502 DP_NOTICE(p_hwfn, true,
503 "Failed to allocate `struct ecore_spq'\n");
508 if (ecore_chain_alloc(p_hwfn->p_dev,
509 ECORE_CHAIN_USE_TO_PRODUCE,
510 ECORE_CHAIN_MODE_SINGLE,
511 ECORE_CHAIN_CNT_TYPE_U16,
512 0, /* N/A when the mode is SINGLE */
513 sizeof(struct slow_path_element),
514 &p_spq->chain, OSAL_NULL)) {
515 DP_NOTICE(p_hwfn, true, "Failed to allocate spq chain\n");
516 goto spq_allocate_fail;
519 /* allocate and fill the SPQ elements (incl. ramrod data list) */
520 capacity = ecore_chain_get_capacity(&p_spq->chain);
521 p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev, &p_phys,
523 sizeof(struct ecore_spq_entry));
525 goto spq_allocate_fail;
527 p_spq->p_virt = p_virt;
528 p_spq->p_phys = p_phys;
530 OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_spq->lock);
532 p_hwfn->p_spq = p_spq;
533 return ECORE_SUCCESS;
536 ecore_chain_free(p_hwfn->p_dev, &p_spq->chain);
537 OSAL_FREE(p_hwfn->p_dev, p_spq);
541 void ecore_spq_free(struct ecore_hwfn *p_hwfn)
543 struct ecore_spq *p_spq = p_hwfn->p_spq;
550 capacity = ecore_chain_get_capacity(&p_spq->chain);
551 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
555 sizeof(struct ecore_spq_entry));
558 ecore_chain_free(p_hwfn->p_dev, &p_spq->chain);
559 OSAL_SPIN_LOCK_DEALLOC(&p_spq->lock);
560 OSAL_FREE(p_hwfn->p_dev, p_spq);
564 ecore_spq_get_entry(struct ecore_hwfn *p_hwfn, struct ecore_spq_entry **pp_ent)
566 struct ecore_spq *p_spq = p_hwfn->p_spq;
567 struct ecore_spq_entry *p_ent = OSAL_NULL;
568 enum _ecore_status_t rc = ECORE_SUCCESS;
570 OSAL_SPIN_LOCK(&p_spq->lock);
572 if (OSAL_LIST_IS_EMPTY(&p_spq->free_pool)) {
573 p_ent = OSAL_ZALLOC(p_hwfn->p_dev, GFP_ATOMIC, sizeof(*p_ent));
575 DP_NOTICE(p_hwfn, true,
576 "Failed to allocate an SPQ entry for a pending"
581 p_ent->queue = &p_spq->unlimited_pending;
583 p_ent = OSAL_LIST_FIRST_ENTRY(&p_spq->free_pool,
584 struct ecore_spq_entry, list);
585 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, &p_spq->free_pool);
586 p_ent->queue = &p_spq->pending;
592 OSAL_SPIN_UNLOCK(&p_spq->lock);
596 /* Locked variant; Should be called while the SPQ lock is taken */
597 static void __ecore_spq_return_entry(struct ecore_hwfn *p_hwfn,
598 struct ecore_spq_entry *p_ent)
600 OSAL_LIST_PUSH_TAIL(&p_ent->list, &p_hwfn->p_spq->free_pool);
603 void ecore_spq_return_entry(struct ecore_hwfn *p_hwfn,
604 struct ecore_spq_entry *p_ent)
606 OSAL_SPIN_LOCK(&p_hwfn->p_spq->lock);
607 __ecore_spq_return_entry(p_hwfn, p_ent);
608 OSAL_SPIN_UNLOCK(&p_hwfn->p_spq->lock);
612 * @brief ecore_spq_add_entry - adds a new entry to the pending
613 * list. Should be used while lock is being held.
615 * Addes an entry to the pending list is there is room (en empty
616 * element is available in the free_pool), or else places the
617 * entry in the unlimited_pending pool.
623 * @return enum _ecore_status_t
625 static enum _ecore_status_t
626 ecore_spq_add_entry(struct ecore_hwfn *p_hwfn,
627 struct ecore_spq_entry *p_ent, enum spq_priority priority)
629 struct ecore_spq *p_spq = p_hwfn->p_spq;
631 if (p_ent->queue == &p_spq->unlimited_pending) {
632 if (OSAL_LIST_IS_EMPTY(&p_spq->free_pool)) {
633 OSAL_LIST_PUSH_TAIL(&p_ent->list,
634 &p_spq->unlimited_pending);
635 p_spq->unlimited_pending_count++;
637 return ECORE_SUCCESS;
640 struct ecore_spq_entry *p_en2;
642 p_en2 = OSAL_LIST_FIRST_ENTRY(&p_spq->free_pool,
643 struct ecore_spq_entry,
645 OSAL_LIST_REMOVE_ENTRY(&p_en2->list, &p_spq->free_pool);
647 /* Copy the ring element physical pointer to the new
648 * entry, since we are about to override the entire ring
649 * entry and don't want to lose the pointer.
651 p_ent->elem.data_ptr = p_en2->elem.data_ptr;
655 /* EBLOCK responsible to free the allocated p_ent */
656 if (p_ent->comp_mode != ECORE_SPQ_MODE_EBLOCK)
657 OSAL_FREE(p_hwfn->p_dev, p_ent);
663 /* entry is to be placed in 'pending' queue */
665 case ECORE_SPQ_PRIORITY_NORMAL:
666 OSAL_LIST_PUSH_TAIL(&p_ent->list, &p_spq->pending);
667 p_spq->normal_count++;
669 case ECORE_SPQ_PRIORITY_HIGH:
670 OSAL_LIST_PUSH_HEAD(&p_ent->list, &p_spq->pending);
677 return ECORE_SUCCESS;
680 /***************************************************************************
682 ***************************************************************************/
684 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn)
687 return 0xffffffff; /* illegal */
688 return p_hwfn->p_spq->cid;
691 /***************************************************************************
692 * Posting new Ramrods
693 ***************************************************************************/
695 static enum _ecore_status_t ecore_spq_post_list(struct ecore_hwfn *p_hwfn,
699 struct ecore_spq *p_spq = p_hwfn->p_spq;
700 enum _ecore_status_t rc;
702 /* TODO - implementation might be wasteful; will always keep room
703 * for an additional high priority ramrod (even if one is already
706 while (ecore_chain_get_elem_left(&p_spq->chain) > keep_reserve &&
707 !OSAL_LIST_IS_EMPTY(head)) {
708 struct ecore_spq_entry *p_ent =
709 OSAL_LIST_FIRST_ENTRY(head, struct ecore_spq_entry, list);
710 if (p_ent != OSAL_NULL) {
712 #pragma warning(suppress : 6011 28182)
714 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, head);
715 OSAL_LIST_PUSH_TAIL(&p_ent->list,
716 &p_spq->completion_pending);
717 p_spq->comp_sent_count++;
719 rc = ecore_spq_hw_post(p_hwfn, p_spq, p_ent);
721 OSAL_LIST_REMOVE_ENTRY(&p_ent->list,
722 &p_spq->completion_pending);
723 __ecore_spq_return_entry(p_hwfn, p_ent);
729 return ECORE_SUCCESS;
732 static enum _ecore_status_t ecore_spq_pend_post(struct ecore_hwfn *p_hwfn)
734 struct ecore_spq *p_spq = p_hwfn->p_spq;
735 struct ecore_spq_entry *p_ent = OSAL_NULL;
737 while (!OSAL_LIST_IS_EMPTY(&p_spq->free_pool)) {
738 if (OSAL_LIST_IS_EMPTY(&p_spq->unlimited_pending))
741 p_ent = OSAL_LIST_FIRST_ENTRY(&p_spq->unlimited_pending,
742 struct ecore_spq_entry, list);
747 #pragma warning(suppress : 6011)
749 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, &p_spq->unlimited_pending);
751 ecore_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
754 return ecore_spq_post_list(p_hwfn,
755 &p_spq->pending, SPQ_HIGH_PRI_RESERVE_DEFAULT);
758 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn *p_hwfn,
759 struct ecore_spq_entry *p_ent,
762 enum _ecore_status_t rc = ECORE_SUCCESS;
763 struct ecore_spq *p_spq = p_hwfn ? p_hwfn->p_spq : OSAL_NULL;
764 bool b_ret_ent = true;
770 DP_NOTICE(p_hwfn, true, "Got a NULL pointer\n");
774 if (p_hwfn->p_dev->recov_in_prog) {
775 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
776 "Recovery is in progress -> skip spq post"
777 " [cmd %02x protocol %02x]\n",
778 p_ent->elem.hdr.cmd_id, p_ent->elem.hdr.protocol_id);
779 /* Return success to let the flows to be completed successfully
780 * w/o any error handling.
782 return ECORE_SUCCESS;
785 OSAL_SPIN_LOCK(&p_spq->lock);
787 /* Complete the entry */
788 rc = ecore_spq_fill_entry(p_hwfn, p_ent);
790 /* Check return value after LOCK is taken for cleaner error flow */
794 /* Add the request to the pending queue */
795 rc = ecore_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
799 rc = ecore_spq_pend_post(p_hwfn);
801 /* Since it's possible that pending failed for a different
802 * entry [although unlikely], the failed entry was already
803 * dealt with; No need to return it here.
809 OSAL_SPIN_UNLOCK(&p_spq->lock);
811 if (p_ent->comp_mode == ECORE_SPQ_MODE_EBLOCK) {
812 /* For entries in ECORE BLOCK mode, the completion code cannot
813 * perform the necessary cleanup - if it did, we couldn't
814 * access p_ent here to see whether it's successful or not.
815 * Thus, after gaining the answer perform the cleanup here.
817 rc = ecore_spq_block(p_hwfn, p_ent, fw_return_code,
818 p_ent->queue == &p_spq->unlimited_pending);
820 if (p_ent->queue == &p_spq->unlimited_pending) {
821 /* This is an allocated p_ent which does not need to
824 OSAL_FREE(p_hwfn->p_dev, p_ent);
826 /* TBD: handle error flow and remove p_ent from
836 ecore_spq_return_entry(p_hwfn, p_ent);
841 OSAL_SPIN_LOCK(&p_spq->lock);
842 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, &p_spq->completion_pending);
843 ecore_chain_return_produced(&p_spq->chain);
846 /* return to the free pool */
848 __ecore_spq_return_entry(p_hwfn, p_ent);
849 OSAL_SPIN_UNLOCK(&p_spq->lock);
854 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn *p_hwfn,
857 union event_ring_data *p_data)
859 struct ecore_spq *p_spq;
860 struct ecore_spq_entry *p_ent = OSAL_NULL;
861 struct ecore_spq_entry *tmp;
862 struct ecore_spq_entry *found = OSAL_NULL;
863 enum _ecore_status_t rc;
868 p_spq = p_hwfn->p_spq;
872 OSAL_SPIN_LOCK(&p_spq->lock);
873 OSAL_LIST_FOR_EACH_ENTRY_SAFE(p_ent,
875 &p_spq->completion_pending,
876 list, struct ecore_spq_entry) {
877 if (p_ent->elem.hdr.echo == echo) {
878 OSAL_LIST_REMOVE_ENTRY(&p_ent->list,
879 &p_spq->completion_pending);
881 /* Avoid overriding of SPQ entries when getting
882 * out-of-order completions, by marking the completions
883 * in a bitmap and increasing the chain consumer only
884 * for the first successive completed entries.
886 SPQ_COMP_BMAP_SET_BIT(p_spq, echo);
887 while (SPQ_COMP_BMAP_TEST_BIT(p_spq,
888 p_spq->comp_bitmap_idx)) {
889 SPQ_COMP_BMAP_CLEAR_BIT(p_spq,
890 p_spq->comp_bitmap_idx);
891 p_spq->comp_bitmap_idx++;
892 ecore_chain_return_produced(&p_spq->chain);
900 /* This is debug and should be relatively uncommon - depends
901 * on scenarios which have mutliple per-PF sent ramrods.
903 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
904 "Got completion for echo %04x - doesn't match"
905 " echo %04x in completion pending list\n",
906 OSAL_LE16_TO_CPU(echo),
907 OSAL_LE16_TO_CPU(p_ent->elem.hdr.echo));
910 /* Release lock before callback, as callback may post
911 * an additional ramrod.
913 OSAL_SPIN_UNLOCK(&p_spq->lock);
916 DP_NOTICE(p_hwfn, true,
917 "Failed to find an entry this"
918 " EQE [echo %04x] completes\n",
919 OSAL_LE16_TO_CPU(echo));
923 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
924 "Complete EQE [echo %04x]: func %p cookie %p)\n",
925 OSAL_LE16_TO_CPU(echo),
926 p_ent->comp_cb.function, p_ent->comp_cb.cookie);
927 if (found->comp_cb.function)
928 found->comp_cb.function(p_hwfn, found->comp_cb.cookie, p_data,
931 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
932 "Got a completion without a callback function\n");
934 if ((found->comp_mode != ECORE_SPQ_MODE_EBLOCK) ||
935 (found->queue == &p_spq->unlimited_pending))
936 /* EBLOCK is responsible for returning its own entry into the
937 * free list, unless it originally added the entry into the
938 * unlimited pending list.
940 ecore_spq_return_entry(p_hwfn, found);
942 /* Attempt to post pending requests */
943 OSAL_SPIN_LOCK(&p_spq->lock);
944 rc = ecore_spq_pend_post(p_hwfn);
945 OSAL_SPIN_UNLOCK(&p_spq->lock);
950 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn)
952 struct ecore_consq *p_consq;
954 /* Allocate ConsQ struct */
956 OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_consq));
958 DP_NOTICE(p_hwfn, true,
959 "Failed to allocate `struct ecore_consq'\n");
963 /* Allocate and initialize EQ chain */
964 if (ecore_chain_alloc(p_hwfn->p_dev,
965 ECORE_CHAIN_USE_TO_PRODUCE,
966 ECORE_CHAIN_MODE_PBL,
967 ECORE_CHAIN_CNT_TYPE_U16,
968 ECORE_CHAIN_PAGE_SIZE / 0x80,
970 &p_consq->chain, OSAL_NULL) != ECORE_SUCCESS) {
971 DP_NOTICE(p_hwfn, true, "Failed to allocate consq chain");
972 goto consq_allocate_fail;
975 p_hwfn->p_consq = p_consq;
976 return ECORE_SUCCESS;
979 OSAL_FREE(p_hwfn->p_dev, p_consq);
983 void ecore_consq_setup(struct ecore_hwfn *p_hwfn)
985 ecore_chain_reset(&p_hwfn->p_consq->chain);
988 void ecore_consq_free(struct ecore_hwfn *p_hwfn)
990 if (!p_hwfn->p_consq)
993 ecore_chain_free(p_hwfn->p_dev, &p_hwfn->p_consq->chain);
994 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_consq);