1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/types.h>
10 #include <asm/byteorder.h>
12 #include <linux/delay.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/list.h>
17 #include <linux/pci.h>
18 #include <linux/slab.h>
19 #include <linux/spinlock.h>
20 #include <linux/string.h>
23 #include "qed_dev_api.h"
28 #include "qed_reg_addr.h"
30 #include "qed_sriov.h"
33 /***************************************************************************
34 * Structures & Definitions
35 ***************************************************************************/
37 #define SPQ_HIGH_PRI_RESERVE_DEFAULT (1)
39 #define SPQ_BLOCK_DELAY_MAX_ITER (10)
40 #define SPQ_BLOCK_DELAY_US (10)
41 #define SPQ_BLOCK_SLEEP_MAX_ITER (1000)
42 #define SPQ_BLOCK_SLEEP_MS (5)
44 /***************************************************************************
45 * Blocking Imp. (BLOCK/EBLOCK mode)
46 ***************************************************************************/
47 static void qed_spq_blocking_cb(struct qed_hwfn *p_hwfn,
49 union event_ring_data *data, u8 fw_return_code)
51 struct qed_spq_comp_done *comp_done;
53 comp_done = (struct qed_spq_comp_done *)cookie;
55 comp_done->fw_return_code = fw_return_code;
57 /* Make sure completion done is visible on waiting thread */
58 smp_store_release(&comp_done->done, 0x1);
61 static int __qed_spq_block(struct qed_hwfn *p_hwfn,
62 struct qed_spq_entry *p_ent,
63 u8 *p_fw_ret, bool sleep_between_iter)
65 struct qed_spq_comp_done *comp_done;
68 comp_done = (struct qed_spq_comp_done *)p_ent->comp_cb.cookie;
69 iter_cnt = sleep_between_iter ? SPQ_BLOCK_SLEEP_MAX_ITER
70 : SPQ_BLOCK_DELAY_MAX_ITER;
73 /* Validate we receive completion update */
74 if (READ_ONCE(comp_done->done) == 1) {
75 /* Read updated FW return value */
76 smp_read_barrier_depends();
78 *p_fw_ret = comp_done->fw_return_code;
82 if (sleep_between_iter)
83 msleep(SPQ_BLOCK_SLEEP_MS);
85 udelay(SPQ_BLOCK_DELAY_US);
91 static int qed_spq_block(struct qed_hwfn *p_hwfn,
92 struct qed_spq_entry *p_ent,
93 u8 *p_fw_ret, bool skip_quick_poll)
95 struct qed_spq_comp_done *comp_done;
98 /* A relatively short polling period w/o sleeping, to allow the FW to
99 * complete the ramrod and thus possibly to avoid the following sleeps.
101 if (!skip_quick_poll) {
102 rc = __qed_spq_block(p_hwfn, p_ent, p_fw_ret, false);
107 /* Move to polling with a sleeping period between iterations */
108 rc = __qed_spq_block(p_hwfn, p_ent, p_fw_ret, true);
112 DP_INFO(p_hwfn, "Ramrod is stuck, requesting MCP drain\n");
113 rc = qed_mcp_drain(p_hwfn, p_hwfn->p_main_ptt);
115 DP_NOTICE(p_hwfn, "MCP drain failed\n");
119 /* Retry after drain */
120 rc = __qed_spq_block(p_hwfn, p_ent, p_fw_ret, true);
124 comp_done = (struct qed_spq_comp_done *)p_ent->comp_cb.cookie;
125 if (comp_done->done == 1) {
127 *p_fw_ret = comp_done->fw_return_code;
132 "Ramrod is stuck [CID %08x cmd %02x protocol %02x echo %04x]\n",
133 le32_to_cpu(p_ent->elem.hdr.cid),
134 p_ent->elem.hdr.cmd_id,
135 p_ent->elem.hdr.protocol_id,
136 le16_to_cpu(p_ent->elem.hdr.echo));
141 /***************************************************************************
142 * SPQ entries inner API
143 ***************************************************************************/
144 static int qed_spq_fill_entry(struct qed_hwfn *p_hwfn,
145 struct qed_spq_entry *p_ent)
149 switch (p_ent->comp_mode) {
150 case QED_SPQ_MODE_EBLOCK:
151 case QED_SPQ_MODE_BLOCK:
152 p_ent->comp_cb.function = qed_spq_blocking_cb;
154 case QED_SPQ_MODE_CB:
157 DP_NOTICE(p_hwfn, "Unknown SPQE completion mode %d\n",
162 DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
163 "Ramrod header: [CID 0x%08x CMD 0x%02x protocol 0x%02x] Data pointer: [%08x:%08x] Completion Mode: %s\n",
165 p_ent->elem.hdr.cmd_id,
166 p_ent->elem.hdr.protocol_id,
167 p_ent->elem.data_ptr.hi,
168 p_ent->elem.data_ptr.lo,
169 D_TRINE(p_ent->comp_mode, QED_SPQ_MODE_EBLOCK,
170 QED_SPQ_MODE_BLOCK, "MODE_EBLOCK", "MODE_BLOCK",
176 /***************************************************************************
178 ***************************************************************************/
179 static void qed_spq_hw_initialize(struct qed_hwfn *p_hwfn,
180 struct qed_spq *p_spq)
183 struct qed_cxt_info cxt_info;
184 struct core_conn_context *p_cxt;
185 union qed_qm_pq_params pq_params;
188 cxt_info.iid = p_spq->cid;
190 rc = qed_cxt_get_cid_info(p_hwfn, &cxt_info);
193 DP_NOTICE(p_hwfn, "Cannot find context info for cid=%d\n",
198 p_cxt = cxt_info.p_cxt;
200 SET_FIELD(p_cxt->xstorm_ag_context.flags10,
201 XSTORM_CORE_CONN_AG_CTX_DQ_CF_EN, 1);
202 SET_FIELD(p_cxt->xstorm_ag_context.flags1,
203 XSTORM_CORE_CONN_AG_CTX_DQ_CF_ACTIVE, 1);
204 SET_FIELD(p_cxt->xstorm_ag_context.flags9,
205 XSTORM_CORE_CONN_AG_CTX_CONSOLID_PROD_CF_EN, 1);
207 /* QM physical queue */
208 memset(&pq_params, 0, sizeof(pq_params));
209 pq_params.core.tc = LB_TC;
210 pq = qed_get_qm_pq(p_hwfn, PROTOCOLID_CORE, &pq_params);
211 p_cxt->xstorm_ag_context.physical_q0 = cpu_to_le16(pq);
213 p_cxt->xstorm_st_context.spq_base_lo =
214 DMA_LO_LE(p_spq->chain.p_phys_addr);
215 p_cxt->xstorm_st_context.spq_base_hi =
216 DMA_HI_LE(p_spq->chain.p_phys_addr);
218 DMA_REGPAIR_LE(p_cxt->xstorm_st_context.consolid_base_addr,
219 p_hwfn->p_consq->chain.p_phys_addr);
222 static int qed_spq_hw_post(struct qed_hwfn *p_hwfn,
223 struct qed_spq *p_spq, struct qed_spq_entry *p_ent)
225 struct qed_chain *p_chain = &p_hwfn->p_spq->chain;
226 u16 echo = qed_chain_get_prod_idx(p_chain);
227 struct slow_path_element *elem;
228 struct core_db_data db;
230 p_ent->elem.hdr.echo = cpu_to_le16(echo);
231 elem = qed_chain_produce(p_chain);
233 DP_NOTICE(p_hwfn, "Failed to produce from SPQ chain\n");
237 *elem = p_ent->elem; /* struct assignment */
239 /* send a doorbell on the slow hwfn session */
240 memset(&db, 0, sizeof(db));
241 SET_FIELD(db.params, CORE_DB_DATA_DEST, DB_DEST_XCM);
242 SET_FIELD(db.params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
243 SET_FIELD(db.params, CORE_DB_DATA_AGG_VAL_SEL,
244 DQ_XCM_CORE_SPQ_PROD_CMD);
245 db.agg_flags = DQ_XCM_CORE_DQ_CF_CMD;
246 db.spq_prod = cpu_to_le16(qed_chain_get_prod_idx(p_chain));
248 /* make sure the SPQE is updated before the doorbell */
251 DOORBELL(p_hwfn, qed_db_addr(p_spq->cid, DQ_DEMS_LEGACY), *(u32 *)&db);
253 /* make sure doorbell is rang */
256 DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
257 "Doorbelled [0x%08x, CID 0x%08x] with Flags: %02x agg_params: %02x, prod: %04x\n",
258 qed_db_addr(p_spq->cid, DQ_DEMS_LEGACY),
259 p_spq->cid, db.params, db.agg_flags,
260 qed_chain_get_prod_idx(p_chain));
265 /***************************************************************************
266 * Asynchronous events
267 ***************************************************************************/
269 qed_async_event_completion(struct qed_hwfn *p_hwfn,
270 struct event_ring_entry *p_eqe)
272 switch (p_eqe->protocol_id) {
273 case PROTOCOLID_ROCE:
274 qed_async_roce_event(p_hwfn, p_eqe);
276 case PROTOCOLID_COMMON:
277 return qed_sriov_eqe_event(p_hwfn,
279 p_eqe->echo, &p_eqe->data);
282 "Unknown Async completion for protocol: %d\n",
288 /***************************************************************************
290 ***************************************************************************/
291 void qed_eq_prod_update(struct qed_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 */
302 int qed_eq_completion(struct qed_hwfn *p_hwfn, void *cookie)
304 struct qed_eq *p_eq = cookie;
305 struct qed_chain *p_chain = &p_eq->chain;
308 /* take a snapshot of the FW consumer */
309 u16 fw_cons_idx = le16_to_cpu(*p_eq->p_fw_cons);
311 DP_VERBOSE(p_hwfn, QED_MSG_SPQ, "fw_cons_idx %x\n", fw_cons_idx);
313 /* Need to guarantee the fw_cons index we use points to a usuable
314 * element (to comply with our chain), so our macros would comply
316 if ((fw_cons_idx & qed_chain_get_usable_per_page(p_chain)) ==
317 qed_chain_get_usable_per_page(p_chain))
318 fw_cons_idx += qed_chain_get_unusable_per_page(p_chain);
320 /* Complete current segment of eq entries */
321 while (fw_cons_idx != qed_chain_get_cons_idx(p_chain)) {
322 struct event_ring_entry *p_eqe = qed_chain_consume(p_chain);
329 DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
330 "op %x prot %x res0 %x echo %x fwret %x flags %x\n",
334 le16_to_cpu(p_eqe->echo),
335 p_eqe->fw_return_code,
338 if (GET_FIELD(p_eqe->flags, EVENT_RING_ENTRY_ASYNC)) {
339 if (qed_async_event_completion(p_hwfn, p_eqe))
341 } else if (qed_spq_completion(p_hwfn,
343 p_eqe->fw_return_code,
348 qed_chain_recycle_consumed(p_chain);
351 qed_eq_prod_update(p_hwfn, qed_chain_get_prod_idx(p_chain));
356 struct qed_eq *qed_eq_alloc(struct qed_hwfn *p_hwfn, u16 num_elem)
360 /* Allocate EQ struct */
361 p_eq = kzalloc(sizeof(*p_eq), GFP_KERNEL);
365 /* Allocate and initialize EQ chain*/
366 if (qed_chain_alloc(p_hwfn->cdev,
367 QED_CHAIN_USE_TO_PRODUCE,
369 QED_CHAIN_CNT_TYPE_U16,
371 sizeof(union event_ring_element),
373 goto eq_allocate_fail;
375 /* register EQ completion on the SP SB */
376 qed_int_register_cb(p_hwfn, qed_eq_completion,
377 p_eq, &p_eq->eq_sb_index, &p_eq->p_fw_cons);
382 qed_eq_free(p_hwfn, p_eq);
386 void qed_eq_setup(struct qed_hwfn *p_hwfn, struct qed_eq *p_eq)
388 qed_chain_reset(&p_eq->chain);
391 void qed_eq_free(struct qed_hwfn *p_hwfn, struct qed_eq *p_eq)
395 qed_chain_free(p_hwfn->cdev, &p_eq->chain);
399 /***************************************************************************
400 * CQE API - manipulate EQ functionality
401 ***************************************************************************/
402 static int qed_cqe_completion(struct qed_hwfn *p_hwfn,
403 struct eth_slow_path_rx_cqe *cqe,
404 enum protocol_type protocol)
406 if (IS_VF(p_hwfn->cdev))
409 /* @@@tmp - it's possible we'll eventually want to handle some
410 * actual commands that can arrive here, but for now this is only
411 * used to complete the ramrod using the echo value on the cqe
413 return qed_spq_completion(p_hwfn, cqe->echo, 0, NULL);
416 int qed_eth_cqe_completion(struct qed_hwfn *p_hwfn,
417 struct eth_slow_path_rx_cqe *cqe)
421 rc = qed_cqe_completion(p_hwfn, cqe, PROTOCOLID_ETH);
424 "Failed to handle RXQ CQE [cmd 0x%02x]\n",
430 /***************************************************************************
431 * Slow hwfn Queue (spq)
432 ***************************************************************************/
433 void qed_spq_setup(struct qed_hwfn *p_hwfn)
435 struct qed_spq *p_spq = p_hwfn->p_spq;
436 struct qed_spq_entry *p_virt = NULL;
437 dma_addr_t p_phys = 0;
440 INIT_LIST_HEAD(&p_spq->pending);
441 INIT_LIST_HEAD(&p_spq->completion_pending);
442 INIT_LIST_HEAD(&p_spq->free_pool);
443 INIT_LIST_HEAD(&p_spq->unlimited_pending);
444 spin_lock_init(&p_spq->lock);
447 p_phys = p_spq->p_phys + offsetof(struct qed_spq_entry, ramrod);
448 p_virt = p_spq->p_virt;
450 capacity = qed_chain_get_capacity(&p_spq->chain);
451 for (i = 0; i < capacity; i++) {
452 DMA_REGPAIR_LE(p_virt->elem.data_ptr, p_phys);
454 list_add_tail(&p_virt->list, &p_spq->free_pool);
457 p_phys += sizeof(struct qed_spq_entry);
461 p_spq->normal_count = 0;
462 p_spq->comp_count = 0;
463 p_spq->comp_sent_count = 0;
464 p_spq->unlimited_pending_count = 0;
466 bitmap_zero(p_spq->p_comp_bitmap, SPQ_RING_SIZE);
467 p_spq->comp_bitmap_idx = 0;
469 /* SPQ cid, cannot fail */
470 qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_spq->cid);
471 qed_spq_hw_initialize(p_hwfn, p_spq);
473 /* reset the chain itself */
474 qed_chain_reset(&p_spq->chain);
477 int qed_spq_alloc(struct qed_hwfn *p_hwfn)
479 struct qed_spq_entry *p_virt = NULL;
480 struct qed_spq *p_spq = NULL;
481 dma_addr_t p_phys = 0;
485 p_spq = kzalloc(sizeof(struct qed_spq), GFP_KERNEL);
490 if (qed_chain_alloc(p_hwfn->cdev,
491 QED_CHAIN_USE_TO_PRODUCE,
492 QED_CHAIN_MODE_SINGLE,
493 QED_CHAIN_CNT_TYPE_U16,
494 0, /* N/A when the mode is SINGLE */
495 sizeof(struct slow_path_element),
497 goto spq_allocate_fail;
499 /* allocate and fill the SPQ elements (incl. ramrod data list) */
500 capacity = qed_chain_get_capacity(&p_spq->chain);
501 p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
502 capacity * sizeof(struct qed_spq_entry),
503 &p_phys, GFP_KERNEL);
505 goto spq_allocate_fail;
507 p_spq->p_virt = p_virt;
508 p_spq->p_phys = p_phys;
509 p_hwfn->p_spq = p_spq;
514 qed_chain_free(p_hwfn->cdev, &p_spq->chain);
519 void qed_spq_free(struct qed_hwfn *p_hwfn)
521 struct qed_spq *p_spq = p_hwfn->p_spq;
528 capacity = qed_chain_get_capacity(&p_spq->chain);
529 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
531 sizeof(struct qed_spq_entry),
532 p_spq->p_virt, p_spq->p_phys);
535 qed_chain_free(p_hwfn->cdev, &p_spq->chain);
540 int qed_spq_get_entry(struct qed_hwfn *p_hwfn, struct qed_spq_entry **pp_ent)
542 struct qed_spq *p_spq = p_hwfn->p_spq;
543 struct qed_spq_entry *p_ent = NULL;
546 spin_lock_bh(&p_spq->lock);
548 if (list_empty(&p_spq->free_pool)) {
549 p_ent = kzalloc(sizeof(*p_ent), GFP_ATOMIC);
552 "Failed to allocate an SPQ entry for a pending ramrod\n");
556 p_ent->queue = &p_spq->unlimited_pending;
558 p_ent = list_first_entry(&p_spq->free_pool,
559 struct qed_spq_entry, list);
560 list_del(&p_ent->list);
561 p_ent->queue = &p_spq->pending;
567 spin_unlock_bh(&p_spq->lock);
571 /* Locked variant; Should be called while the SPQ lock is taken */
572 static void __qed_spq_return_entry(struct qed_hwfn *p_hwfn,
573 struct qed_spq_entry *p_ent)
575 list_add_tail(&p_ent->list, &p_hwfn->p_spq->free_pool);
578 void qed_spq_return_entry(struct qed_hwfn *p_hwfn, struct qed_spq_entry *p_ent)
580 spin_lock_bh(&p_hwfn->p_spq->lock);
581 __qed_spq_return_entry(p_hwfn, p_ent);
582 spin_unlock_bh(&p_hwfn->p_spq->lock);
586 * @brief qed_spq_add_entry - adds a new entry to the pending
587 * list. Should be used while lock is being held.
589 * Addes an entry to the pending list is there is room (en empty
590 * element is available in the free_pool), or else places the
591 * entry in the unlimited_pending pool.
599 static int qed_spq_add_entry(struct qed_hwfn *p_hwfn,
600 struct qed_spq_entry *p_ent,
601 enum spq_priority priority)
603 struct qed_spq *p_spq = p_hwfn->p_spq;
605 if (p_ent->queue == &p_spq->unlimited_pending) {
607 if (list_empty(&p_spq->free_pool)) {
608 list_add_tail(&p_ent->list, &p_spq->unlimited_pending);
609 p_spq->unlimited_pending_count++;
613 struct qed_spq_entry *p_en2;
615 p_en2 = list_first_entry(&p_spq->free_pool,
616 struct qed_spq_entry, list);
617 list_del(&p_en2->list);
619 /* Copy the ring element physical pointer to the new
620 * entry, since we are about to override the entire ring
621 * entry and don't want to lose the pointer.
623 p_ent->elem.data_ptr = p_en2->elem.data_ptr;
627 /* EBLOCK responsible to free the allocated p_ent */
628 if (p_ent->comp_mode != QED_SPQ_MODE_EBLOCK)
635 /* entry is to be placed in 'pending' queue */
637 case QED_SPQ_PRIORITY_NORMAL:
638 list_add_tail(&p_ent->list, &p_spq->pending);
639 p_spq->normal_count++;
641 case QED_SPQ_PRIORITY_HIGH:
642 list_add(&p_ent->list, &p_spq->pending);
652 /***************************************************************************
654 ***************************************************************************/
655 u32 qed_spq_get_cid(struct qed_hwfn *p_hwfn)
658 return 0xffffffff; /* illegal */
659 return p_hwfn->p_spq->cid;
662 /***************************************************************************
663 * Posting new Ramrods
664 ***************************************************************************/
665 static int qed_spq_post_list(struct qed_hwfn *p_hwfn,
666 struct list_head *head, u32 keep_reserve)
668 struct qed_spq *p_spq = p_hwfn->p_spq;
671 while (qed_chain_get_elem_left(&p_spq->chain) > keep_reserve &&
673 struct qed_spq_entry *p_ent =
674 list_first_entry(head, struct qed_spq_entry, list);
675 list_del(&p_ent->list);
676 list_add_tail(&p_ent->list, &p_spq->completion_pending);
677 p_spq->comp_sent_count++;
679 rc = qed_spq_hw_post(p_hwfn, p_spq, p_ent);
681 list_del(&p_ent->list);
682 __qed_spq_return_entry(p_hwfn, p_ent);
690 static int qed_spq_pend_post(struct qed_hwfn *p_hwfn)
692 struct qed_spq *p_spq = p_hwfn->p_spq;
693 struct qed_spq_entry *p_ent = NULL;
695 while (!list_empty(&p_spq->free_pool)) {
696 if (list_empty(&p_spq->unlimited_pending))
699 p_ent = list_first_entry(&p_spq->unlimited_pending,
700 struct qed_spq_entry, list);
704 list_del(&p_ent->list);
706 qed_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
709 return qed_spq_post_list(p_hwfn, &p_spq->pending,
710 SPQ_HIGH_PRI_RESERVE_DEFAULT);
713 int qed_spq_post(struct qed_hwfn *p_hwfn,
714 struct qed_spq_entry *p_ent, u8 *fw_return_code)
717 struct qed_spq *p_spq = p_hwfn ? p_hwfn->p_spq : NULL;
718 bool b_ret_ent = true;
724 DP_NOTICE(p_hwfn, "Got a NULL pointer\n");
728 /* Complete the entry */
729 rc = qed_spq_fill_entry(p_hwfn, p_ent);
731 spin_lock_bh(&p_spq->lock);
733 /* Check return value after LOCK is taken for cleaner error flow */
737 /* Add the request to the pending queue */
738 rc = qed_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
742 rc = qed_spq_pend_post(p_hwfn);
744 /* Since it's possible that pending failed for a different
745 * entry [although unlikely], the failed entry was already
746 * dealt with; No need to return it here.
752 spin_unlock_bh(&p_spq->lock);
754 if (p_ent->comp_mode == QED_SPQ_MODE_EBLOCK) {
755 /* For entries in QED BLOCK mode, the completion code cannot
756 * perform the necessary cleanup - if it did, we couldn't
757 * access p_ent here to see whether it's successful or not.
758 * Thus, after gaining the answer perform the cleanup here.
760 rc = qed_spq_block(p_hwfn, p_ent, fw_return_code,
761 p_ent->queue == &p_spq->unlimited_pending);
763 if (p_ent->queue == &p_spq->unlimited_pending) {
764 /* This is an allocated p_ent which does not need to
775 qed_spq_return_entry(p_hwfn, p_ent);
780 spin_lock_bh(&p_spq->lock);
781 list_del(&p_ent->list);
782 qed_chain_return_produced(&p_spq->chain);
785 /* return to the free pool */
787 __qed_spq_return_entry(p_hwfn, p_ent);
788 spin_unlock_bh(&p_spq->lock);
793 int qed_spq_completion(struct qed_hwfn *p_hwfn,
796 union event_ring_data *p_data)
798 struct qed_spq *p_spq;
799 struct qed_spq_entry *p_ent = NULL;
800 struct qed_spq_entry *tmp;
801 struct qed_spq_entry *found = NULL;
807 p_spq = p_hwfn->p_spq;
811 spin_lock_bh(&p_spq->lock);
812 list_for_each_entry_safe(p_ent, tmp, &p_spq->completion_pending, list) {
813 if (p_ent->elem.hdr.echo == echo) {
814 u16 pos = le16_to_cpu(echo) % SPQ_RING_SIZE;
816 list_del(&p_ent->list);
818 /* Avoid overriding of SPQ entries when getting
819 * out-of-order completions, by marking the completions
820 * in a bitmap and increasing the chain consumer only
821 * for the first successive completed entries.
823 __set_bit(pos, p_spq->p_comp_bitmap);
825 while (test_bit(p_spq->comp_bitmap_idx,
826 p_spq->p_comp_bitmap)) {
827 __clear_bit(p_spq->comp_bitmap_idx,
828 p_spq->p_comp_bitmap);
829 p_spq->comp_bitmap_idx++;
830 qed_chain_return_produced(&p_spq->chain);
838 /* This is relatively uncommon - depends on scenarios
839 * which have mutliple per-PF sent ramrods.
841 DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
842 "Got completion for echo %04x - doesn't match echo %04x in completion pending list\n",
844 le16_to_cpu(p_ent->elem.hdr.echo));
847 /* Release lock before callback, as callback may post
848 * an additional ramrod.
850 spin_unlock_bh(&p_spq->lock);
854 "Failed to find an entry this EQE [echo %04x] completes\n",
859 DP_VERBOSE(p_hwfn, QED_MSG_SPQ,
860 "Complete EQE [echo %04x]: func %p cookie %p)\n",
862 p_ent->comp_cb.function, p_ent->comp_cb.cookie);
863 if (found->comp_cb.function)
864 found->comp_cb.function(p_hwfn, found->comp_cb.cookie, p_data,
869 "Got a completion without a callback function\n");
871 if ((found->comp_mode != QED_SPQ_MODE_EBLOCK) ||
872 (found->queue == &p_spq->unlimited_pending))
873 /* EBLOCK is responsible for returning its own entry into the
874 * free list, unless it originally added the entry into the
875 * unlimited pending list.
877 qed_spq_return_entry(p_hwfn, found);
879 /* Attempt to post pending requests */
880 spin_lock_bh(&p_spq->lock);
881 rc = qed_spq_pend_post(p_hwfn);
882 spin_unlock_bh(&p_spq->lock);
887 struct qed_consq *qed_consq_alloc(struct qed_hwfn *p_hwfn)
889 struct qed_consq *p_consq;
891 /* Allocate ConsQ struct */
892 p_consq = kzalloc(sizeof(*p_consq), GFP_KERNEL);
896 /* Allocate and initialize EQ chain*/
897 if (qed_chain_alloc(p_hwfn->cdev,
898 QED_CHAIN_USE_TO_PRODUCE,
900 QED_CHAIN_CNT_TYPE_U16,
901 QED_CHAIN_PAGE_SIZE / 0x80,
902 0x80, &p_consq->chain))
903 goto consq_allocate_fail;
908 qed_consq_free(p_hwfn, p_consq);
912 void qed_consq_setup(struct qed_hwfn *p_hwfn, struct qed_consq *p_consq)
914 qed_chain_reset(&p_consq->chain);
917 void qed_consq_free(struct qed_hwfn *p_hwfn, struct qed_consq *p_consq)
921 qed_chain_free(p_hwfn->cdev, &p_consq->chain);