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 struct ecore_ptt *p_ptt;
91 enum _ecore_status_t rc;
93 /* A relatively short polling period w/o sleeping, to allow the FW to
94 * complete the ramrod and thus possibly to avoid the following sleeps.
96 if (!skip_quick_poll) {
97 rc = __ecore_spq_block(p_hwfn, p_ent, p_fw_ret, false);
98 if (rc == ECORE_SUCCESS)
102 /* Move to polling with a sleeping period between iterations */
103 rc = __ecore_spq_block(p_hwfn, p_ent, p_fw_ret, true);
104 if (rc == ECORE_SUCCESS)
105 return ECORE_SUCCESS;
107 p_ptt = ecore_ptt_acquire(p_hwfn);
111 DP_INFO(p_hwfn, "Ramrod is stuck, requesting MCP drain\n");
112 rc = ecore_mcp_drain(p_hwfn, p_ptt);
113 ecore_ptt_release(p_hwfn, p_ptt);
114 if (rc != ECORE_SUCCESS) {
115 DP_NOTICE(p_hwfn, true, "MCP drain failed\n");
119 /* Retry after drain */
120 rc = __ecore_spq_block(p_hwfn, p_ent, p_fw_ret, true);
121 if (rc == ECORE_SUCCESS)
122 return ECORE_SUCCESS;
124 comp_done = (struct ecore_spq_comp_done *)p_ent->comp_cb.cookie;
125 if (comp_done->done == 1) {
127 *p_fw_ret = comp_done->fw_return_code;
128 return ECORE_SUCCESS;
131 DP_NOTICE(p_hwfn, true,
132 "Ramrod is stuck [CID %08x cmd %02x proto %02x echo %04x]\n",
133 OSAL_LE32_TO_CPU(p_ent->elem.hdr.cid),
134 p_ent->elem.hdr.cmd_id, p_ent->elem.hdr.protocol_id,
135 OSAL_LE16_TO_CPU(p_ent->elem.hdr.echo));
137 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_RAMROD_FAIL);
142 /***************************************************************************
143 * SPQ entries inner API
144 ***************************************************************************/
145 static enum _ecore_status_t
146 ecore_spq_fill_entry(struct ecore_hwfn *p_hwfn, struct ecore_spq_entry *p_ent)
150 switch (p_ent->comp_mode) {
151 case ECORE_SPQ_MODE_EBLOCK:
152 case ECORE_SPQ_MODE_BLOCK:
153 p_ent->comp_cb.function = ecore_spq_blocking_cb;
155 case ECORE_SPQ_MODE_CB:
158 DP_NOTICE(p_hwfn, true, "Unknown SPQE completion mode %d\n",
163 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
164 "Ramrod header: [CID 0x%08x CMD 0x%02x protocol 0x%02x]"
165 " Data pointer: [%08x:%08x] Completion Mode: %s\n",
166 p_ent->elem.hdr.cid, p_ent->elem.hdr.cmd_id,
167 p_ent->elem.hdr.protocol_id,
168 p_ent->elem.data_ptr.hi, p_ent->elem.data_ptr.lo,
169 D_TRINE(p_ent->comp_mode, ECORE_SPQ_MODE_EBLOCK,
170 ECORE_SPQ_MODE_BLOCK, "MODE_EBLOCK", "MODE_BLOCK",
173 return ECORE_SUCCESS;
176 /***************************************************************************
178 ***************************************************************************/
179 static void ecore_spq_hw_initialize(struct ecore_hwfn *p_hwfn,
180 struct ecore_spq *p_spq)
182 struct ecore_cxt_info cxt_info;
183 struct core_conn_context *p_cxt;
184 enum _ecore_status_t rc;
187 cxt_info.iid = p_spq->cid;
189 rc = ecore_cxt_get_cid_info(p_hwfn, &cxt_info);
192 DP_NOTICE(p_hwfn, true, "Cannot find context info for cid=%d\n",
197 p_cxt = cxt_info.p_cxt;
199 /* @@@TBD we zero the context until we have ilt_reset implemented. */
200 OSAL_MEM_ZERO(p_cxt, sizeof(*p_cxt));
202 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev)) {
203 SET_FIELD(p_cxt->xstorm_ag_context.flags10,
204 E4_XSTORM_CORE_CONN_AG_CTX_DQ_CF_EN, 1);
205 SET_FIELD(p_cxt->xstorm_ag_context.flags1,
206 E4_XSTORM_CORE_CONN_AG_CTX_DQ_CF_ACTIVE, 1);
207 /* SET_FIELD(p_cxt->xstorm_ag_context.flags10,
208 * E4_XSTORM_CORE_CONN_AG_CTX_SLOW_PATH_EN, 1);
210 SET_FIELD(p_cxt->xstorm_ag_context.flags9,
211 E4_XSTORM_CORE_CONN_AG_CTX_CONSOLID_PROD_CF_EN, 1);
214 /* CDU validation - FIXME currently disabled */
216 /* QM physical queue */
217 physical_q = ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB);
218 p_cxt->xstorm_ag_context.physical_q0 = OSAL_CPU_TO_LE16(physical_q);
220 p_cxt->xstorm_st_context.spq_base_lo =
221 DMA_LO_LE(p_spq->chain.p_phys_addr);
222 p_cxt->xstorm_st_context.spq_base_hi =
223 DMA_HI_LE(p_spq->chain.p_phys_addr);
225 DMA_REGPAIR_LE(p_cxt->xstorm_st_context.consolid_base_addr,
226 p_hwfn->p_consq->chain.p_phys_addr);
229 static enum _ecore_status_t ecore_spq_hw_post(struct ecore_hwfn *p_hwfn,
230 struct ecore_spq *p_spq,
231 struct ecore_spq_entry *p_ent)
233 struct ecore_chain *p_chain = &p_hwfn->p_spq->chain;
234 struct core_db_data *p_db_data = &p_spq->db_data;
235 u16 echo = ecore_chain_get_prod_idx(p_chain);
236 struct slow_path_element *elem;
238 p_ent->elem.hdr.echo = OSAL_CPU_TO_LE16(echo);
239 elem = ecore_chain_produce(p_chain);
241 DP_NOTICE(p_hwfn, true, "Failed to produce from SPQ chain\n");
245 *elem = p_ent->elem; /* Struct assignment */
247 p_db_data->spq_prod =
248 OSAL_CPU_TO_LE16(ecore_chain_get_prod_idx(p_chain));
250 /* Make sure the SPQE is updated before the doorbell */
251 OSAL_WMB(p_hwfn->p_dev);
253 DOORBELL(p_hwfn, p_spq->db_addr_offset, *(u32 *)p_db_data);
255 /* Make sure doorbell is rang */
256 OSAL_WMB(p_hwfn->p_dev);
258 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
259 "Doorbelled [0x%08x, CID 0x%08x] with Flags: %02x"
260 " agg_params: %02x, prod: %04x\n",
261 p_spq->db_addr_offset, p_spq->cid, p_db_data->params,
262 p_db_data->agg_flags, ecore_chain_get_prod_idx(p_chain));
264 return ECORE_SUCCESS;
267 /***************************************************************************
268 * Asynchronous events
269 ***************************************************************************/
271 static enum _ecore_status_t
272 ecore_async_event_completion(struct ecore_hwfn *p_hwfn,
273 struct event_ring_entry *p_eqe)
275 switch (p_eqe->protocol_id) {
276 case PROTOCOLID_COMMON:
277 return ecore_sriov_eqe_event(p_hwfn,
279 p_eqe->echo, &p_eqe->data);
282 true, "Unknown Async completion for protocol: %d\n",
288 /***************************************************************************
290 ***************************************************************************/
291 void ecore_eq_prod_update(struct ecore_hwfn *p_hwfn, u16 prod)
293 u32 addr = GTT_BAR0_MAP_REG_USDM_RAM +
294 USTORM_EQE_CONS_OFFSET(p_hwfn->rel_pf_id);
296 REG_WR16(p_hwfn, addr, prod);
298 /* keep prod updates ordered */
299 OSAL_MMIOWB(p_hwfn->p_dev);
302 enum _ecore_status_t ecore_eq_completion(struct ecore_hwfn *p_hwfn,
305 struct ecore_eq *p_eq = cookie;
306 struct ecore_chain *p_chain = &p_eq->chain;
307 enum _ecore_status_t rc = 0;
309 /* take a snapshot of the FW consumer */
310 u16 fw_cons_idx = OSAL_LE16_TO_CPU(*p_eq->p_fw_cons);
312 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ, "fw_cons_idx %x\n", fw_cons_idx);
314 /* Need to guarantee the fw_cons index we use points to a usuable
315 * element (to comply with our chain), so our macros would comply
317 if ((fw_cons_idx & ecore_chain_get_usable_per_page(p_chain)) ==
318 ecore_chain_get_usable_per_page(p_chain)) {
319 fw_cons_idx += ecore_chain_get_unusable_per_page(p_chain);
322 /* Complete current segment of eq entries */
323 while (fw_cons_idx != ecore_chain_get_cons_idx(p_chain)) {
324 struct event_ring_entry *p_eqe = ecore_chain_consume(p_chain);
330 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
331 "op %x prot %x res0 %x echo %x fwret %x flags %x\n",
332 p_eqe->opcode, /* Event Opcode */
333 p_eqe->protocol_id, /* Event Protocol ID */
334 p_eqe->reserved0, /* Reserved */
335 /* Echo value from ramrod data on the host */
336 OSAL_LE16_TO_CPU(p_eqe->echo),
337 p_eqe->fw_return_code, /* FW return code for SP
342 if (GET_FIELD(p_eqe->flags, EVENT_RING_ENTRY_ASYNC)) {
343 if (ecore_async_event_completion(p_hwfn, p_eqe))
345 } else if (ecore_spq_completion(p_hwfn,
347 p_eqe->fw_return_code,
352 ecore_chain_recycle_consumed(p_chain);
355 ecore_eq_prod_update(p_hwfn, ecore_chain_get_prod_idx(p_chain));
360 enum _ecore_status_t ecore_eq_alloc(struct ecore_hwfn *p_hwfn, u16 num_elem)
362 struct ecore_eq *p_eq;
364 /* Allocate EQ struct */
365 p_eq = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_eq));
367 DP_NOTICE(p_hwfn, true,
368 "Failed to allocate `struct ecore_eq'\n");
372 /* Allocate and initialize EQ chain*/
373 if (ecore_chain_alloc(p_hwfn->p_dev,
374 ECORE_CHAIN_USE_TO_PRODUCE,
375 ECORE_CHAIN_MODE_PBL,
376 ECORE_CHAIN_CNT_TYPE_U16,
378 sizeof(union event_ring_element),
379 &p_eq->chain, OSAL_NULL) != ECORE_SUCCESS) {
380 DP_NOTICE(p_hwfn, true, "Failed to allocate eq chain\n");
381 goto eq_allocate_fail;
384 /* register EQ completion on the SP SB */
385 ecore_int_register_cb(p_hwfn, ecore_eq_completion,
386 p_eq, &p_eq->eq_sb_index, &p_eq->p_fw_cons);
389 return ECORE_SUCCESS;
392 OSAL_FREE(p_hwfn->p_dev, p_eq);
396 void ecore_eq_setup(struct ecore_hwfn *p_hwfn)
398 ecore_chain_reset(&p_hwfn->p_eq->chain);
401 void ecore_eq_free(struct ecore_hwfn *p_hwfn)
406 ecore_chain_free(p_hwfn->p_dev, &p_hwfn->p_eq->chain);
408 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_eq);
409 p_hwfn->p_eq = OSAL_NULL;
412 /***************************************************************************
413 * CQE API - manipulate EQ functionality
414 ***************************************************************************/
415 static enum _ecore_status_t ecore_cqe_completion(struct ecore_hwfn *p_hwfn,
416 struct eth_slow_path_rx_cqe
418 enum protocol_type protocol)
420 if (IS_VF(p_hwfn->p_dev))
421 return OSAL_VF_CQE_COMPLETION(p_hwfn, cqe, protocol);
423 /* @@@tmp - it's possible we'll eventually want to handle some
424 * actual commands that can arrive here, but for now this is only
425 * used to complete the ramrod using the echo value on the cqe
427 return ecore_spq_completion(p_hwfn, cqe->echo, 0, OSAL_NULL);
430 enum _ecore_status_t ecore_eth_cqe_completion(struct ecore_hwfn *p_hwfn,
431 struct eth_slow_path_rx_cqe *cqe)
433 enum _ecore_status_t rc;
435 rc = ecore_cqe_completion(p_hwfn, cqe, PROTOCOLID_ETH);
437 DP_NOTICE(p_hwfn, true,
438 "Failed to handle RXQ CQE [cmd 0x%02x]\n",
445 /***************************************************************************
446 * Slow hwfn Queue (spq)
447 ***************************************************************************/
448 void ecore_spq_setup(struct ecore_hwfn *p_hwfn)
450 struct ecore_spq *p_spq = p_hwfn->p_spq;
451 struct ecore_spq_entry *p_virt = OSAL_NULL;
452 struct core_db_data *p_db_data;
453 void OSAL_IOMEM *db_addr;
454 dma_addr_t p_phys = 0;
456 enum _ecore_status_t rc;
458 OSAL_LIST_INIT(&p_spq->pending);
459 OSAL_LIST_INIT(&p_spq->completion_pending);
460 OSAL_LIST_INIT(&p_spq->free_pool);
461 OSAL_LIST_INIT(&p_spq->unlimited_pending);
462 OSAL_SPIN_LOCK_INIT(&p_spq->lock);
465 p_phys = p_spq->p_phys + OFFSETOF(struct ecore_spq_entry, ramrod);
466 p_virt = p_spq->p_virt;
468 capacity = ecore_chain_get_capacity(&p_spq->chain);
469 for (i = 0; i < capacity; i++) {
470 DMA_REGPAIR_LE(p_virt->elem.data_ptr, p_phys);
472 OSAL_LIST_PUSH_TAIL(&p_virt->list, &p_spq->free_pool);
475 p_phys += sizeof(struct ecore_spq_entry);
479 p_spq->normal_count = 0;
480 p_spq->comp_count = 0;
481 p_spq->comp_sent_count = 0;
482 p_spq->unlimited_pending_count = 0;
484 OSAL_MEM_ZERO(p_spq->p_comp_bitmap,
485 SPQ_COMP_BMAP_SIZE * sizeof(unsigned long));
486 p_spq->comp_bitmap_idx = 0;
488 /* SPQ cid, cannot fail */
489 ecore_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_spq->cid);
490 ecore_spq_hw_initialize(p_hwfn, p_spq);
492 /* reset the chain itself */
493 ecore_chain_reset(&p_spq->chain);
495 /* Initialize the address/data of the SPQ doorbell */
496 p_spq->db_addr_offset = DB_ADDR(p_spq->cid, DQ_DEMS_LEGACY);
497 p_db_data = &p_spq->db_data;
498 OSAL_MEM_ZERO(p_db_data, sizeof(*p_db_data));
499 SET_FIELD(p_db_data->params, CORE_DB_DATA_DEST, DB_DEST_XCM);
500 SET_FIELD(p_db_data->params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_MAX);
501 SET_FIELD(p_db_data->params, CORE_DB_DATA_AGG_VAL_SEL,
502 DQ_XCM_CORE_SPQ_PROD_CMD);
503 p_db_data->agg_flags = DQ_XCM_CORE_DQ_CF_CMD;
505 /* Register the SPQ doorbell with the doorbell recovery mechanism */
506 db_addr = (void *)((u8 *)p_hwfn->doorbells + p_spq->db_addr_offset);
507 rc = ecore_db_recovery_add(p_hwfn->p_dev, db_addr, &p_spq->db_data,
508 DB_REC_WIDTH_32B, DB_REC_KERNEL);
509 if (rc != ECORE_SUCCESS)
511 "Failed to register the SPQ doorbell with the doorbell recovery mechanism\n");
514 enum _ecore_status_t ecore_spq_alloc(struct ecore_hwfn *p_hwfn)
516 struct ecore_spq_entry *p_virt = OSAL_NULL;
517 struct ecore_spq *p_spq = OSAL_NULL;
518 dma_addr_t p_phys = 0;
523 OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(struct ecore_spq));
525 DP_NOTICE(p_hwfn, true,
526 "Failed to allocate `struct ecore_spq'\n");
531 if (ecore_chain_alloc(p_hwfn->p_dev,
532 ECORE_CHAIN_USE_TO_PRODUCE,
533 ECORE_CHAIN_MODE_SINGLE,
534 ECORE_CHAIN_CNT_TYPE_U16,
535 0, /* N/A when the mode is SINGLE */
536 sizeof(struct slow_path_element),
537 &p_spq->chain, OSAL_NULL)) {
538 DP_NOTICE(p_hwfn, true, "Failed to allocate spq chain\n");
539 goto spq_allocate_fail;
542 /* allocate and fill the SPQ elements (incl. ramrod data list) */
543 capacity = ecore_chain_get_capacity(&p_spq->chain);
544 p_virt = OSAL_DMA_ALLOC_COHERENT(p_hwfn->p_dev, &p_phys,
546 sizeof(struct ecore_spq_entry));
548 goto spq_allocate_fail;
550 p_spq->p_virt = p_virt;
551 p_spq->p_phys = p_phys;
553 #ifdef CONFIG_ECORE_LOCK_ALLOC
554 OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_spq->lock);
557 p_hwfn->p_spq = p_spq;
558 return ECORE_SUCCESS;
561 ecore_chain_free(p_hwfn->p_dev, &p_spq->chain);
562 OSAL_FREE(p_hwfn->p_dev, p_spq);
566 void ecore_spq_free(struct ecore_hwfn *p_hwfn)
568 struct ecore_spq *p_spq = p_hwfn->p_spq;
569 void OSAL_IOMEM *db_addr;
575 /* Delete the SPQ doorbell from the doorbell recovery mechanism */
576 db_addr = (void *)((u8 *)p_hwfn->doorbells + p_spq->db_addr_offset);
577 ecore_db_recovery_del(p_hwfn->p_dev, db_addr, &p_spq->db_data);
580 capacity = ecore_chain_get_capacity(&p_spq->chain);
581 OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev,
585 sizeof(struct ecore_spq_entry));
588 ecore_chain_free(p_hwfn->p_dev, &p_spq->chain);
589 #ifdef CONFIG_ECORE_LOCK_ALLOC
590 OSAL_SPIN_LOCK_DEALLOC(&p_spq->lock);
593 OSAL_FREE(p_hwfn->p_dev, p_spq);
597 ecore_spq_get_entry(struct ecore_hwfn *p_hwfn, struct ecore_spq_entry **pp_ent)
599 struct ecore_spq *p_spq = p_hwfn->p_spq;
600 struct ecore_spq_entry *p_ent = OSAL_NULL;
601 enum _ecore_status_t rc = ECORE_SUCCESS;
603 OSAL_SPIN_LOCK(&p_spq->lock);
605 if (OSAL_LIST_IS_EMPTY(&p_spq->free_pool)) {
606 p_ent = OSAL_ZALLOC(p_hwfn->p_dev, GFP_ATOMIC, sizeof(*p_ent));
608 DP_NOTICE(p_hwfn, true,
609 "Failed to allocate an SPQ entry for a pending"
614 p_ent->queue = &p_spq->unlimited_pending;
616 p_ent = OSAL_LIST_FIRST_ENTRY(&p_spq->free_pool,
617 struct ecore_spq_entry, list);
618 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, &p_spq->free_pool);
619 p_ent->queue = &p_spq->pending;
625 OSAL_SPIN_UNLOCK(&p_spq->lock);
629 /* Locked variant; Should be called while the SPQ lock is taken */
630 static void __ecore_spq_return_entry(struct ecore_hwfn *p_hwfn,
631 struct ecore_spq_entry *p_ent)
633 OSAL_LIST_PUSH_TAIL(&p_ent->list, &p_hwfn->p_spq->free_pool);
636 void ecore_spq_return_entry(struct ecore_hwfn *p_hwfn,
637 struct ecore_spq_entry *p_ent)
639 OSAL_SPIN_LOCK(&p_hwfn->p_spq->lock);
640 __ecore_spq_return_entry(p_hwfn, p_ent);
641 OSAL_SPIN_UNLOCK(&p_hwfn->p_spq->lock);
645 * @brief ecore_spq_add_entry - adds a new entry to the pending
646 * list. Should be used while lock is being held.
648 * Addes an entry to the pending list is there is room (en empty
649 * element is available in the free_pool), or else places the
650 * entry in the unlimited_pending pool.
656 * @return enum _ecore_status_t
658 static enum _ecore_status_t
659 ecore_spq_add_entry(struct ecore_hwfn *p_hwfn,
660 struct ecore_spq_entry *p_ent, enum spq_priority priority)
662 struct ecore_spq *p_spq = p_hwfn->p_spq;
664 if (p_ent->queue == &p_spq->unlimited_pending) {
665 if (OSAL_LIST_IS_EMPTY(&p_spq->free_pool)) {
666 OSAL_LIST_PUSH_TAIL(&p_ent->list,
667 &p_spq->unlimited_pending);
668 p_spq->unlimited_pending_count++;
670 return ECORE_SUCCESS;
673 struct ecore_spq_entry *p_en2;
675 p_en2 = OSAL_LIST_FIRST_ENTRY(&p_spq->free_pool,
676 struct ecore_spq_entry,
678 OSAL_LIST_REMOVE_ENTRY(&p_en2->list, &p_spq->free_pool);
680 /* Copy the ring element physical pointer to the new
681 * entry, since we are about to override the entire ring
682 * entry and don't want to lose the pointer.
684 p_ent->elem.data_ptr = p_en2->elem.data_ptr;
688 /* EBLOCK responsible to free the allocated p_ent */
689 if (p_ent->comp_mode != ECORE_SPQ_MODE_EBLOCK)
690 OSAL_FREE(p_hwfn->p_dev, p_ent);
696 /* entry is to be placed in 'pending' queue */
698 case ECORE_SPQ_PRIORITY_NORMAL:
699 OSAL_LIST_PUSH_TAIL(&p_ent->list, &p_spq->pending);
700 p_spq->normal_count++;
702 case ECORE_SPQ_PRIORITY_HIGH:
703 OSAL_LIST_PUSH_HEAD(&p_ent->list, &p_spq->pending);
710 return ECORE_SUCCESS;
713 /***************************************************************************
715 ***************************************************************************/
717 u32 ecore_spq_get_cid(struct ecore_hwfn *p_hwfn)
720 return 0xffffffff; /* illegal */
721 return p_hwfn->p_spq->cid;
724 /***************************************************************************
725 * Posting new Ramrods
726 ***************************************************************************/
728 static enum _ecore_status_t ecore_spq_post_list(struct ecore_hwfn *p_hwfn,
732 struct ecore_spq *p_spq = p_hwfn->p_spq;
733 enum _ecore_status_t rc;
735 /* TODO - implementation might be wasteful; will always keep room
736 * for an additional high priority ramrod (even if one is already
739 while (ecore_chain_get_elem_left(&p_spq->chain) > keep_reserve &&
740 !OSAL_LIST_IS_EMPTY(head)) {
741 struct ecore_spq_entry *p_ent =
742 OSAL_LIST_FIRST_ENTRY(head, struct ecore_spq_entry, list);
743 if (p_ent != OSAL_NULL) {
745 #pragma warning(suppress : 6011 28182)
747 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, head);
748 OSAL_LIST_PUSH_TAIL(&p_ent->list,
749 &p_spq->completion_pending);
750 p_spq->comp_sent_count++;
752 rc = ecore_spq_hw_post(p_hwfn, p_spq, p_ent);
754 OSAL_LIST_REMOVE_ENTRY(&p_ent->list,
755 &p_spq->completion_pending);
756 __ecore_spq_return_entry(p_hwfn, p_ent);
762 return ECORE_SUCCESS;
765 static enum _ecore_status_t ecore_spq_pend_post(struct ecore_hwfn *p_hwfn)
767 struct ecore_spq *p_spq = p_hwfn->p_spq;
768 struct ecore_spq_entry *p_ent = OSAL_NULL;
770 while (!OSAL_LIST_IS_EMPTY(&p_spq->free_pool)) {
771 if (OSAL_LIST_IS_EMPTY(&p_spq->unlimited_pending))
774 p_ent = OSAL_LIST_FIRST_ENTRY(&p_spq->unlimited_pending,
775 struct ecore_spq_entry, list);
780 #pragma warning(suppress : 6011)
782 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, &p_spq->unlimited_pending);
784 ecore_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
787 return ecore_spq_post_list(p_hwfn,
788 &p_spq->pending, SPQ_HIGH_PRI_RESERVE_DEFAULT);
791 enum _ecore_status_t ecore_spq_post(struct ecore_hwfn *p_hwfn,
792 struct ecore_spq_entry *p_ent,
795 enum _ecore_status_t rc = ECORE_SUCCESS;
796 struct ecore_spq *p_spq = p_hwfn ? p_hwfn->p_spq : OSAL_NULL;
797 bool b_ret_ent = true;
803 DP_NOTICE(p_hwfn, true, "Got a NULL pointer\n");
807 if (p_hwfn->p_dev->recov_in_prog) {
808 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
809 "Recovery is in progress -> skip spq post"
810 " [cmd %02x protocol %02x]\n",
811 p_ent->elem.hdr.cmd_id, p_ent->elem.hdr.protocol_id);
812 /* Return success to let the flows to be completed successfully
813 * w/o any error handling.
815 return ECORE_SUCCESS;
818 OSAL_SPIN_LOCK(&p_spq->lock);
820 /* Complete the entry */
821 rc = ecore_spq_fill_entry(p_hwfn, p_ent);
823 /* Check return value after LOCK is taken for cleaner error flow */
827 /* Add the request to the pending queue */
828 rc = ecore_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
832 rc = ecore_spq_pend_post(p_hwfn);
834 /* Since it's possible that pending failed for a different
835 * entry [although unlikely], the failed entry was already
836 * dealt with; No need to return it here.
842 OSAL_SPIN_UNLOCK(&p_spq->lock);
844 if (p_ent->comp_mode == ECORE_SPQ_MODE_EBLOCK) {
845 /* For entries in ECORE BLOCK mode, the completion code cannot
846 * perform the necessary cleanup - if it did, we couldn't
847 * access p_ent here to see whether it's successful or not.
848 * Thus, after gaining the answer perform the cleanup here.
850 rc = ecore_spq_block(p_hwfn, p_ent, fw_return_code,
851 p_ent->queue == &p_spq->unlimited_pending);
853 if (p_ent->queue == &p_spq->unlimited_pending) {
854 /* This is an allocated p_ent which does not need to
857 OSAL_FREE(p_hwfn->p_dev, p_ent);
859 /* TBD: handle error flow and remove p_ent from
869 ecore_spq_return_entry(p_hwfn, p_ent);
874 OSAL_SPIN_LOCK(&p_spq->lock);
875 OSAL_LIST_REMOVE_ENTRY(&p_ent->list, &p_spq->completion_pending);
876 ecore_chain_return_produced(&p_spq->chain);
879 /* return to the free pool */
881 __ecore_spq_return_entry(p_hwfn, p_ent);
882 OSAL_SPIN_UNLOCK(&p_spq->lock);
887 enum _ecore_status_t ecore_spq_completion(struct ecore_hwfn *p_hwfn,
890 union event_ring_data *p_data)
892 struct ecore_spq *p_spq;
893 struct ecore_spq_entry *p_ent = OSAL_NULL;
894 struct ecore_spq_entry *tmp;
895 struct ecore_spq_entry *found = OSAL_NULL;
896 enum _ecore_status_t rc;
901 p_spq = p_hwfn->p_spq;
905 OSAL_SPIN_LOCK(&p_spq->lock);
906 OSAL_LIST_FOR_EACH_ENTRY_SAFE(p_ent,
908 &p_spq->completion_pending,
909 list, struct ecore_spq_entry) {
910 if (p_ent->elem.hdr.echo == echo) {
911 OSAL_LIST_REMOVE_ENTRY(&p_ent->list,
912 &p_spq->completion_pending);
914 /* Avoid overriding of SPQ entries when getting
915 * out-of-order completions, by marking the completions
916 * in a bitmap and increasing the chain consumer only
917 * for the first successive completed entries.
919 SPQ_COMP_BMAP_SET_BIT(p_spq, echo);
920 while (SPQ_COMP_BMAP_TEST_BIT(p_spq,
921 p_spq->comp_bitmap_idx)) {
922 SPQ_COMP_BMAP_CLEAR_BIT(p_spq,
923 p_spq->comp_bitmap_idx);
924 p_spq->comp_bitmap_idx++;
925 ecore_chain_return_produced(&p_spq->chain);
933 /* This is debug and should be relatively uncommon - depends
934 * on scenarios which have mutliple per-PF sent ramrods.
936 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
937 "Got completion for echo %04x - doesn't match"
938 " echo %04x in completion pending list\n",
939 OSAL_LE16_TO_CPU(echo),
940 OSAL_LE16_TO_CPU(p_ent->elem.hdr.echo));
943 /* Release lock before callback, as callback may post
944 * an additional ramrod.
946 OSAL_SPIN_UNLOCK(&p_spq->lock);
949 DP_NOTICE(p_hwfn, true,
950 "Failed to find an entry this"
951 " EQE [echo %04x] completes\n",
952 OSAL_LE16_TO_CPU(echo));
956 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
957 "Complete EQE [echo %04x]: func %p cookie %p)\n",
958 OSAL_LE16_TO_CPU(echo),
959 p_ent->comp_cb.function, p_ent->comp_cb.cookie);
960 if (found->comp_cb.function)
961 found->comp_cb.function(p_hwfn, found->comp_cb.cookie, p_data,
964 DP_VERBOSE(p_hwfn, ECORE_MSG_SPQ,
965 "Got a completion without a callback function\n");
967 if ((found->comp_mode != ECORE_SPQ_MODE_EBLOCK) ||
968 (found->queue == &p_spq->unlimited_pending))
969 /* EBLOCK is responsible for returning its own entry into the
970 * free list, unless it originally added the entry into the
971 * unlimited pending list.
973 ecore_spq_return_entry(p_hwfn, found);
975 /* Attempt to post pending requests */
976 OSAL_SPIN_LOCK(&p_spq->lock);
977 rc = ecore_spq_pend_post(p_hwfn);
978 OSAL_SPIN_UNLOCK(&p_spq->lock);
983 enum _ecore_status_t ecore_consq_alloc(struct ecore_hwfn *p_hwfn)
985 struct ecore_consq *p_consq;
987 /* Allocate ConsQ struct */
989 OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, sizeof(*p_consq));
991 DP_NOTICE(p_hwfn, true,
992 "Failed to allocate `struct ecore_consq'\n");
996 /* Allocate and initialize EQ chain */
997 if (ecore_chain_alloc(p_hwfn->p_dev,
998 ECORE_CHAIN_USE_TO_PRODUCE,
999 ECORE_CHAIN_MODE_PBL,
1000 ECORE_CHAIN_CNT_TYPE_U16,
1001 ECORE_CHAIN_PAGE_SIZE / 0x80,
1003 &p_consq->chain, OSAL_NULL) != ECORE_SUCCESS) {
1004 DP_NOTICE(p_hwfn, true, "Failed to allocate consq chain");
1005 goto consq_allocate_fail;
1008 p_hwfn->p_consq = p_consq;
1009 return ECORE_SUCCESS;
1011 consq_allocate_fail:
1012 OSAL_FREE(p_hwfn->p_dev, p_consq);
1016 void ecore_consq_setup(struct ecore_hwfn *p_hwfn)
1018 ecore_chain_reset(&p_hwfn->p_consq->chain);
1021 void ecore_consq_free(struct ecore_hwfn *p_hwfn)
1023 if (!p_hwfn->p_consq)
1026 ecore_chain_free(p_hwfn->p_dev, &p_hwfn->p_consq->chain);
1027 OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_consq);