2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
41 #include "ocs_hw_queues.h"
43 #define HW_QTOP_DEBUG 0
46 * @brief Initialize queues
48 * Given the parsed queue topology spec, the SLI queues are created and
51 * @param hw pointer to HW object
52 * @param qtop pointer to queue topology
54 * @return returns 0 for success, an error code value for failure.
57 ocs_hw_init_queues(ocs_hw_t *hw, ocs_hw_qtop_t *qtop)
60 uint32_t default_lengths[QTOP_LAST], len;
61 uint32_t rqset_len = 0, rqset_ulp = 0, rqset_count = 0;
62 uint8_t rqset_filter_mask = 0;
63 hw_eq_t *eqs[hw->config.n_rq];
64 hw_cq_t *cqs[hw->config.n_rq];
65 hw_rq_t *rqs[hw->config.n_rq];
66 ocs_hw_qtop_entry_t *qt, *next_qt;
77 default_lengths[QTOP_EQ] = 1024;
78 default_lengths[QTOP_CQ] = hw->num_qentries[SLI_QTYPE_CQ];
79 default_lengths[QTOP_WQ] = hw->num_qentries[SLI_QTYPE_WQ];
80 default_lengths[QTOP_RQ] = hw->num_qentries[SLI_QTYPE_RQ];
81 default_lengths[QTOP_MQ] = OCS_HW_MQ_DEPTH;
83 ocs_hw_verify(hw != NULL, OCS_HW_RTN_INVALID_ARG);
91 ocs_list_init(&hw->eq_list, hw_eq_t, link);
93 /* If MRQ is requested, Check if it is supported by SLI. */
94 if ((hw->config.n_rq > 1 ) && !hw->sli.config.features.flag.mrqp) {
95 ocs_log_err(hw->os, "MRQ topology not supported by SLI4.\n");
96 return OCS_HW_RTN_ERROR;
99 if (hw->config.n_rq > 1)
102 /* Allocate class WQ pools */
103 for (i = 0; i < ARRAY_SIZE(hw->wq_class_array); i++) {
104 hw->wq_class_array[i] = ocs_varray_alloc(hw->os, OCS_HW_MAX_NUM_WQ);
105 if (hw->wq_class_array[i] == NULL) {
106 ocs_log_err(hw->os, "ocs_varray_alloc for wq_class failed\n");
107 return OCS_HW_RTN_NO_MEMORY;
111 /* Allocate per CPU WQ pools */
112 for (i = 0; i < ARRAY_SIZE(hw->wq_cpu_array); i++) {
113 hw->wq_cpu_array[i] = ocs_varray_alloc(hw->os, OCS_HW_MAX_NUM_WQ);
114 if (hw->wq_cpu_array[i] == NULL) {
115 ocs_log_err(hw->os, "ocs_varray_alloc for wq_class failed\n");
116 return OCS_HW_RTN_NO_MEMORY;
120 ocs_hw_assert(qtop != NULL);
122 for (i = 0, qt = qtop->entries; i < qtop->inuse_count; i++, qt++) {
123 if (i == qtop->inuse_count - 1)
130 len = (qt->len) ? qt->len : default_lengths[QTOP_EQ];
132 if (qt->set_default) {
133 default_lengths[QTOP_EQ] = len;
137 eq = hw_new_eq(hw, len);
139 hw_queue_teardown(hw);
140 return OCS_HW_RTN_NO_MEMORY;
145 len = (qt->len) ? qt->len : default_lengths[QTOP_CQ];
147 if (qt->set_default) {
148 default_lengths[QTOP_CQ] = len;
152 if (!eq || !next_qt) {
156 /* If this CQ is for MRQ, then delay the creation */
157 if (!use_mrq || next_qt->entry != QTOP_RQ) {
158 cq = hw_new_cq(eq, len);
166 len = (qt->len) ? qt->len : default_lengths[QTOP_WQ];
167 if (qt->set_default) {
168 default_lengths[QTOP_WQ] = len;
172 if ((hw->ulp_start + qt->ulp) > hw->ulp_max) {
173 ocs_log_err(hw->os, "invalid ULP %d for WQ\n", qt->ulp);
174 hw_queue_teardown(hw);
175 return OCS_HW_RTN_NO_MEMORY;
181 wq = hw_new_wq(cq, len, qt->class, hw->ulp_start + qt->ulp);
186 /* Place this WQ on the EQ WQ array */
187 if (ocs_varray_add(eq->wq_array, wq)) {
188 ocs_log_err(hw->os, "QTOP_WQ: EQ ocs_varray_add failed\n");
189 hw_queue_teardown(hw);
190 return OCS_HW_RTN_ERROR;
193 /* Place this WQ on the HW class array */
194 if (qt->class < ARRAY_SIZE(hw->wq_class_array)) {
195 if (ocs_varray_add(hw->wq_class_array[qt->class], wq)) {
196 ocs_log_err(hw->os, "HW wq_class_array ocs_varray_add failed\n");
197 hw_queue_teardown(hw);
198 return OCS_HW_RTN_ERROR;
201 ocs_log_err(hw->os, "Invalid class value: %d\n", qt->class);
202 hw_queue_teardown(hw);
203 return OCS_HW_RTN_ERROR;
207 * Place this WQ on the per CPU list, asumming that EQs are mapped to cpu given
208 * by the EQ instance modulo number of CPUs
210 if (ocs_varray_add(hw->wq_cpu_array[eq->instance % ocs_get_num_cpus()], wq)) {
211 ocs_log_err(hw->os, "HW wq_cpu_array ocs_varray_add failed\n");
212 hw_queue_teardown(hw);
213 return OCS_HW_RTN_ERROR;
219 len = (qt->len) ? qt->len : default_lengths[QTOP_RQ];
220 if (qt->set_default) {
221 default_lengths[QTOP_RQ] = len;
225 if ((hw->ulp_start + qt->ulp) > hw->ulp_max) {
226 ocs_log_err(hw->os, "invalid ULP %d for RQ\n", qt->ulp);
227 hw_queue_teardown(hw);
228 return OCS_HW_RTN_NO_MEMORY;
232 mrq.rq_cfg[mrq.num_pairs].len = len;
233 mrq.rq_cfg[mrq.num_pairs].ulp = hw->ulp_start + qt->ulp;
234 mrq.rq_cfg[mrq.num_pairs].filter_mask = qt->filter_mask;
235 mrq.rq_cfg[mrq.num_pairs].eq = eq;
238 rq = hw_new_rq(cq, len, hw->ulp_start + qt->ulp);
240 hw_queue_teardown(hw);
241 return OCS_HW_RTN_NO_MEMORY;
243 rq->filter_mask = qt->filter_mask;
249 len = (qt->len) ? qt->len : default_lengths[QTOP_MQ];
250 if (qt->set_default) {
251 default_lengths[QTOP_MQ] = len;
258 mq = hw_new_mq(cq, len);
271 /* First create normal RQs. */
272 for (i = 0; i < mrq.num_pairs; i++) {
273 for (j = 0; j < mrq.num_pairs; j++) {
274 if ((i != j) && (mrq.rq_cfg[i].filter_mask == mrq.rq_cfg[j].filter_mask)) {
275 /* This should be created using set */
276 if (rqset_filter_mask && (rqset_filter_mask != mrq.rq_cfg[i].filter_mask)) {
277 ocs_log_crit(hw->os, "Cant create morethan one RQ Set\n");
278 hw_queue_teardown(hw);
279 return OCS_HW_RTN_ERROR;
280 } else if (!rqset_filter_mask){
281 rqset_filter_mask = mrq.rq_cfg[i].filter_mask;
282 rqset_len = mrq.rq_cfg[i].len;
283 rqset_ulp = mrq.rq_cfg[i].ulp;
285 eqs[rqset_count] = mrq.rq_cfg[i].eq;
290 if (j == mrq.num_pairs) {
292 cq = hw_new_cq(mrq.rq_cfg[i].eq, default_lengths[QTOP_CQ]);
294 hw_queue_teardown(hw);
295 return OCS_HW_RTN_NO_MEMORY;
298 rq = hw_new_rq(cq, mrq.rq_cfg[i].len, mrq.rq_cfg[i].ulp);
300 hw_queue_teardown(hw);
301 return OCS_HW_RTN_NO_MEMORY;
303 rq->filter_mask = mrq.rq_cfg[i].filter_mask;
307 /* Now create RQ Set */
309 if (rqset_count > OCE_HW_MAX_NUM_MRQ_PAIRS) {
311 "Max Supported MRQ pairs = %d\n",
312 OCE_HW_MAX_NUM_MRQ_PAIRS);
313 hw_queue_teardown(hw);
314 return OCS_HW_RTN_ERROR;
318 if (hw_new_cq_set(eqs, cqs, rqset_count, default_lengths[QTOP_CQ])) {
319 hw_queue_teardown(hw);
320 return OCS_HW_RTN_ERROR;
324 if (hw_new_rq_set(cqs, rqs, rqset_count, rqset_len, rqset_ulp)) {
325 hw_queue_teardown(hw);
326 return OCS_HW_RTN_ERROR;
329 for (i = 0; i < rqset_count ; i++) {
330 rqs[i]->filter_mask = rqset_filter_mask;
331 rqs[i]->is_mrq = TRUE;
332 rqs[i]->base_mrq_id = rqs[0]->hdr->id;
335 hw->hw_mrq_count = rqset_count;
339 return OCS_HW_RTN_SUCCESS;
341 hw_queue_teardown(hw);
342 return OCS_HW_RTN_NO_MEMORY;
347 * @brief Allocate a new EQ object
349 * A new EQ object is instantiated
351 * @param hw pointer to HW object
352 * @param entry_count number of entries in the EQ
354 * @return pointer to allocated EQ object
357 hw_new_eq(ocs_hw_t *hw, uint32_t entry_count)
359 hw_eq_t *eq = ocs_malloc(hw->os, sizeof(*eq), OCS_M_ZERO | OCS_M_NOWAIT);
362 eq->type = SLI_QTYPE_EQ;
364 eq->entry_count = entry_count;
365 eq->instance = hw->eq_count++;
366 eq->queue = &hw->eq[eq->instance];
367 ocs_list_init(&eq->cq_list, hw_cq_t, link);
369 eq->wq_array = ocs_varray_alloc(hw->os, OCS_HW_MAX_NUM_WQ);
370 if (eq->wq_array == NULL) {
371 ocs_free(hw->os, eq, sizeof(*eq));
374 if (sli_queue_alloc(&hw->sli, SLI_QTYPE_EQ, eq->queue, entry_count, NULL, 0)) {
375 ocs_log_err(hw->os, "EQ[%d] allocation failure\n", eq->instance);
376 ocs_free(hw->os, eq, sizeof(*eq));
379 sli_eq_modify_delay(&hw->sli, eq->queue, 1, 0, 8);
380 hw->hw_eq[eq->instance] = eq;
381 ocs_list_add_tail(&hw->eq_list, eq);
382 ocs_log_debug(hw->os, "create eq[%2d] id %3d len %4d\n", eq->instance, eq->queue->id,
391 * @brief Allocate a new CQ object
393 * A new CQ object is instantiated
395 * @param eq pointer to parent EQ object
396 * @param entry_count number of entries in the CQ
398 * @return pointer to allocated CQ object
401 hw_new_cq(hw_eq_t *eq, uint32_t entry_count)
403 ocs_hw_t *hw = eq->hw;
404 hw_cq_t *cq = ocs_malloc(hw->os, sizeof(*cq), OCS_M_ZERO | OCS_M_NOWAIT);
408 cq->type = SLI_QTYPE_CQ;
409 cq->instance = eq->hw->cq_count++;
410 cq->entry_count = entry_count;
411 cq->queue = &hw->cq[cq->instance];
413 ocs_list_init(&cq->q_list, hw_q_t, link);
415 if (sli_queue_alloc(&hw->sli, SLI_QTYPE_CQ, cq->queue, cq->entry_count, eq->queue, 0)) {
416 ocs_log_err(hw->os, "CQ[%d] allocation failure len=%d\n",
419 ocs_free(hw->os, cq, sizeof(*cq));
422 hw->hw_cq[cq->instance] = cq;
423 ocs_list_add_tail(&eq->cq_list, cq);
424 ocs_log_debug(hw->os, "create cq[%2d] id %3d len %4d\n", cq->instance, cq->queue->id,
432 * @brief Allocate a new CQ Set of objects.
434 * @param eqs pointer to a set of EQ objects.
435 * @param cqs pointer to a set of CQ objects to be returned.
436 * @param num_cqs number of CQ queues in the set.
437 * @param entry_count number of entries in the CQ.
439 * @return 0 on success and -1 on failure.
442 hw_new_cq_set(hw_eq_t *eqs[], hw_cq_t *cqs[], uint32_t num_cqs, uint32_t entry_count)
445 ocs_hw_t *hw = eqs[0]->hw;
446 sli4_t *sli4 = &hw->sli;
448 sli4_queue_t *qs[SLI_MAX_CQ_SET_COUNT], *assocs[SLI_MAX_CQ_SET_COUNT];
450 /* Initialise CQS pointers to NULL */
451 for (i = 0; i < num_cqs; i++) {
455 for (i = 0; i < num_cqs; i++) {
456 cq = ocs_malloc(hw->os, sizeof(*cq), OCS_M_ZERO | OCS_M_NOWAIT);
462 cq->type = SLI_QTYPE_CQ;
463 cq->instance = hw->cq_count++;
464 cq->entry_count = entry_count;
465 cq->queue = &hw->cq[cq->instance];
467 assocs[i] = eqs[i]->queue;
468 ocs_list_init(&cq->q_list, hw_q_t, link);
471 if (sli_cq_alloc_set(sli4, qs, num_cqs, entry_count, assocs)) {
472 ocs_log_err(NULL, "Failed to create CQ Set. \n");
476 for (i = 0; i < num_cqs; i++) {
477 hw->hw_cq[cqs[i]->instance] = cqs[i];
478 ocs_list_add_tail(&cqs[i]->eq->cq_list, cqs[i]);
484 for (i = 0; i < num_cqs; i++) {
486 ocs_free(hw->os, cqs[i], sizeof(*cqs[i]));
494 * @brief Allocate a new MQ object
496 * A new MQ object is instantiated
498 * @param cq pointer to parent CQ object
499 * @param entry_count number of entries in the MQ
501 * @return pointer to allocated MQ object
504 hw_new_mq(hw_cq_t *cq, uint32_t entry_count)
506 ocs_hw_t *hw = cq->eq->hw;
507 hw_mq_t *mq = ocs_malloc(hw->os, sizeof(*mq), OCS_M_ZERO | OCS_M_NOWAIT);
511 mq->type = SLI_QTYPE_MQ;
512 mq->instance = cq->eq->hw->mq_count++;
513 mq->entry_count = entry_count;
514 mq->entry_size = OCS_HW_MQ_DEPTH;
515 mq->queue = &hw->mq[mq->instance];
517 if (sli_queue_alloc(&hw->sli, SLI_QTYPE_MQ,
521 ocs_log_err(hw->os, "MQ allocation failure\n");
522 ocs_free(hw->os, mq, sizeof(*mq));
525 hw->hw_mq[mq->instance] = mq;
526 ocs_list_add_tail(&cq->q_list, mq);
527 ocs_log_debug(hw->os, "create mq[%2d] id %3d len %4d\n", mq->instance, mq->queue->id,
535 * @brief Allocate a new WQ object
537 * A new WQ object is instantiated
539 * @param cq pointer to parent CQ object
540 * @param entry_count number of entries in the WQ
541 * @param class WQ class
542 * @param ulp index of chute
544 * @return pointer to allocated WQ object
547 hw_new_wq(hw_cq_t *cq, uint32_t entry_count, uint32_t class, uint32_t ulp)
549 ocs_hw_t *hw = cq->eq->hw;
550 hw_wq_t *wq = ocs_malloc(hw->os, sizeof(*wq), OCS_M_ZERO | OCS_M_NOWAIT);
555 wq->type = SLI_QTYPE_WQ;
556 wq->instance = cq->eq->hw->wq_count++;
557 wq->entry_count = entry_count;
558 wq->queue = &hw->wq[wq->instance];
560 wq->wqec_set_count = OCS_HW_WQEC_SET_COUNT;
561 wq->wqec_count = wq->wqec_set_count;
562 wq->free_count = wq->entry_count - 1;
564 ocs_list_init(&wq->pending_list, ocs_hw_wqe_t, link);
566 if (sli_queue_alloc(&hw->sli, SLI_QTYPE_WQ, wq->queue, wq->entry_count, cq->queue, ulp)) {
567 ocs_log_err(hw->os, "WQ allocation failure\n");
568 ocs_free(hw->os, wq, sizeof(*wq));
571 hw->hw_wq[wq->instance] = wq;
572 ocs_list_add_tail(&cq->q_list, wq);
573 ocs_log_debug(hw->os, "create wq[%2d] id %3d len %4d cls %d ulp %d\n", wq->instance, wq->queue->id,
574 wq->entry_count, wq->class, wq->ulp);
581 * @brief Allocate a hw_rq_t object
583 * Allocate an RQ object, which encapsulates 2 SLI queues (for rq pair)
585 * @param cq pointer to parent CQ object
586 * @param entry_count number of entries in the RQs
587 * @param ulp ULP index for this RQ
589 * @return pointer to newly allocated hw_rq_t
592 hw_new_rq(hw_cq_t *cq, uint32_t entry_count, uint32_t ulp)
594 ocs_hw_t *hw = cq->eq->hw;
595 hw_rq_t *rq = ocs_malloc(hw->os, sizeof(*rq), OCS_M_ZERO | OCS_M_NOWAIT);
598 ocs_hw_get(hw, OCS_HW_MAX_RQ_ENTRIES, &max_hw_rq);
601 rq->instance = hw->hw_rq_count++;
603 rq->type = SLI_QTYPE_RQ;
606 rq->entry_count = OCS_MIN(entry_count, OCS_MIN(max_hw_rq, OCS_HW_RQ_NUM_HDR));
608 /* Create the header RQ */
609 ocs_hw_assert(hw->rq_count < ARRAY_SIZE(hw->rq));
610 rq->hdr = &hw->rq[hw->rq_count];
611 rq->hdr_entry_size = OCS_HW_RQ_HEADER_SIZE;
613 if (sli_fc_rq_alloc(&hw->sli, rq->hdr,
618 ocs_log_err(hw->os, "RQ allocation failure - header\n");
619 ocs_free(hw->os, rq, sizeof(*rq));
622 hw->hw_rq_lookup[hw->rq_count] = rq->instance; /* Update hw_rq_lookup[] */
624 ocs_log_debug(hw->os, "create rq[%2d] id %3d len %4d hdr size %4d ulp %d\n",
625 rq->instance, rq->hdr->id, rq->entry_count, rq->hdr_entry_size, rq->ulp);
627 /* Create the default data RQ */
628 ocs_hw_assert(hw->rq_count < ARRAY_SIZE(hw->rq));
629 rq->data = &hw->rq[hw->rq_count];
630 rq->data_entry_size = hw->config.rq_default_buffer_size;
632 if (sli_fc_rq_alloc(&hw->sli, rq->data,
637 ocs_log_err(hw->os, "RQ allocation failure - first burst\n");
638 ocs_free(hw->os, rq, sizeof(*rq));
641 hw->hw_rq_lookup[hw->rq_count] = rq->instance; /* Update hw_rq_lookup[] */
643 ocs_log_debug(hw->os, "create rq[%2d] id %3d len %4d data size %4d ulp %d\n", rq->instance,
644 rq->data->id, rq->entry_count, rq->data_entry_size, rq->ulp);
646 hw->hw_rq[rq->instance] = rq;
647 ocs_list_add_tail(&cq->q_list, rq);
649 rq->rq_tracker = ocs_malloc(hw->os, sizeof(ocs_hw_sequence_t*) *
650 rq->entry_count, OCS_M_ZERO | OCS_M_NOWAIT);
651 if (rq->rq_tracker == NULL) {
652 ocs_log_err(hw->os, "RQ tracker buf allocation failure\n");
660 * @brief Allocate a hw_rq_t object SET
662 * Allocate an RQ object SET, where each element in set
663 * encapsulates 2 SLI queues (for rq pair)
665 * @param cqs pointers to be associated with RQs.
666 * @param rqs RQ pointers to be returned on success.
667 * @param num_rq_pairs number of rq pairs in the Set.
668 * @param entry_count number of entries in the RQs
669 * @param ulp ULP index for this RQ
671 * @return 0 in success and -1 on failure.
674 hw_new_rq_set(hw_cq_t *cqs[], hw_rq_t *rqs[], uint32_t num_rq_pairs, uint32_t entry_count, uint32_t ulp)
676 ocs_hw_t *hw = cqs[0]->eq->hw;
678 sli4_queue_t *qs[SLI_MAX_RQ_SET_COUNT * 2] = { NULL };
679 uint32_t max_hw_rq, i, q_count;
681 ocs_hw_get(hw, OCS_HW_MAX_RQ_ENTRIES, &max_hw_rq);
683 /* Initialise RQS pointers */
684 for (i = 0; i < num_rq_pairs; i++) {
688 for (i = 0, q_count = 0; i < num_rq_pairs; i++, q_count += 2) {
689 rq = ocs_malloc(hw->os, sizeof(*rq), OCS_M_ZERO | OCS_M_NOWAIT);
694 rq->instance = hw->hw_rq_count++;
696 rq->type = SLI_QTYPE_RQ;
698 rq->entry_count = OCS_MIN(entry_count, OCS_MIN(max_hw_rq, OCS_HW_RQ_NUM_HDR));
701 rq->hdr = &hw->rq[hw->rq_count];
702 rq->hdr_entry_size = OCS_HW_RQ_HEADER_SIZE;
703 hw->hw_rq_lookup[hw->rq_count] = rq->instance;
705 qs[q_count] = rq->hdr;
708 rq->data = &hw->rq[hw->rq_count];
709 rq->data_entry_size = hw->config.rq_default_buffer_size;
710 hw->hw_rq_lookup[hw->rq_count] = rq->instance;
712 qs[q_count + 1] = rq->data;
714 rq->rq_tracker = NULL;
717 if (sli_fc_rq_set_alloc(&hw->sli, num_rq_pairs, qs,
720 rqs[0]->hdr_entry_size,
721 rqs[0]->data_entry_size,
723 ocs_log_err(hw->os, "RQ Set allocation failure for base CQ=%d\n", cqs[0]->queue->id);
727 for (i = 0; i < num_rq_pairs; i++) {
728 hw->hw_rq[rqs[i]->instance] = rqs[i];
729 ocs_list_add_tail(&cqs[i]->q_list, rqs[i]);
730 rqs[i]->rq_tracker = ocs_malloc(hw->os, sizeof(ocs_hw_sequence_t*) *
731 rqs[i]->entry_count, OCS_M_ZERO | OCS_M_NOWAIT);
732 if (rqs[i]->rq_tracker == NULL) {
733 ocs_log_err(hw->os, "RQ tracker buf allocation failure\n");
741 for (i = 0; i < num_rq_pairs; i++) {
742 if (rqs[i] != NULL) {
743 if (rqs[i]->rq_tracker != NULL) {
744 ocs_free(hw->os, rqs[i]->rq_tracker,
745 sizeof(ocs_hw_sequence_t*) *
746 rqs[i]->entry_count);
748 ocs_free(hw->os, rqs[i], sizeof(*rqs[i]));
756 * @brief Free an EQ object
758 * The EQ object and any child queue objects are freed
760 * @param eq pointer to EQ object
765 hw_del_eq(hw_eq_t *eq)
771 ocs_list_foreach_safe(&eq->cq_list, cq, cq_next) {
774 ocs_varray_free(eq->wq_array);
775 ocs_list_remove(&eq->hw->eq_list, eq);
776 eq->hw->hw_eq[eq->instance] = NULL;
777 ocs_free(eq->hw->os, eq, sizeof(*eq));
782 * @brief Free a CQ object
784 * The CQ object and any child queue objects are freed
786 * @param cq pointer to CQ object
791 hw_del_cq(hw_cq_t *cq)
797 ocs_list_foreach_safe(&cq->q_list, q, q_next) {
800 hw_del_mq((hw_mq_t*) q);
803 hw_del_wq((hw_wq_t*) q);
806 hw_del_rq((hw_rq_t*) q);
812 ocs_list_remove(&cq->eq->cq_list, cq);
813 cq->eq->hw->hw_cq[cq->instance] = NULL;
814 ocs_free(cq->eq->hw->os, cq, sizeof(*cq));
819 * @brief Free a MQ object
821 * The MQ object is freed
823 * @param mq pointer to MQ object
828 hw_del_mq(hw_mq_t *mq)
831 ocs_list_remove(&mq->cq->q_list, mq);
832 mq->cq->eq->hw->hw_mq[mq->instance] = NULL;
833 ocs_free(mq->cq->eq->hw->os, mq, sizeof(*mq));
838 * @brief Free a WQ object
840 * The WQ object is freed
842 * @param wq pointer to WQ object
847 hw_del_wq(hw_wq_t *wq)
850 ocs_list_remove(&wq->cq->q_list, wq);
851 wq->cq->eq->hw->hw_wq[wq->instance] = NULL;
852 ocs_free(wq->cq->eq->hw->os, wq, sizeof(*wq));
857 * @brief Free an RQ object
859 * The RQ object is freed
861 * @param rq pointer to RQ object
866 hw_del_rq(hw_rq_t *rq)
870 ocs_hw_t *hw = rq->cq->eq->hw;
871 /* Free RQ tracker */
872 if (rq->rq_tracker != NULL) {
873 ocs_free(hw->os, rq->rq_tracker, sizeof(ocs_hw_sequence_t*) * rq->entry_count);
874 rq->rq_tracker = NULL;
876 ocs_list_remove(&rq->cq->q_list, rq);
877 hw->hw_rq[rq->instance] = NULL;
878 ocs_free(hw->os, rq, sizeof(*rq));
883 * @brief Display HW queue objects
885 * The HW queue objects are displayed using ocs_log
887 * @param hw pointer to HW object
892 hw_queue_dump(ocs_hw_t *hw)
901 ocs_list_foreach(&hw->eq_list, eq) {
902 ocs_printf("eq[%d] id %2d\n", eq->instance, eq->queue->id);
903 ocs_list_foreach(&eq->cq_list, cq) {
904 ocs_printf(" cq[%d] id %2d current\n", cq->instance, cq->queue->id);
905 ocs_list_foreach(&cq->q_list, q) {
909 ocs_printf(" mq[%d] id %2d\n", mq->instance, mq->queue->id);
913 ocs_printf(" wq[%d] id %2d\n", wq->instance, wq->queue->id);
917 ocs_printf(" rq[%d] hdr id %2d\n", rq->instance, rq->hdr->id);
928 * @brief Teardown HW queue objects
930 * The HW queue objects are freed
932 * @param hw pointer to HW object
937 hw_queue_teardown(ocs_hw_t *hw)
943 if (ocs_list_valid(&hw->eq_list)) {
944 ocs_list_foreach_safe(&hw->eq_list, eq, eq_next) {
948 for (i = 0; i < ARRAY_SIZE(hw->wq_cpu_array); i++) {
949 ocs_varray_free(hw->wq_cpu_array[i]);
950 hw->wq_cpu_array[i] = NULL;
952 for (i = 0; i < ARRAY_SIZE(hw->wq_class_array); i++) {
953 ocs_varray_free(hw->wq_class_array[i]);
954 hw->wq_class_array[i] = NULL;
959 * @brief Allocate a WQ to an IO object
961 * The next work queue index is used to assign a WQ to an IO.
963 * If wq_steering is OCS_HW_WQ_STEERING_CLASS, a WQ from io->wq_class is
966 * If wq_steering is OCS_HW_WQ_STEERING_REQUEST, then a WQ from the EQ that
967 * the IO request came in on is selected.
969 * If wq_steering is OCS_HW_WQ_STEERING_CPU, then a WQ associted with the
970 * CPU the request is made on is selected.
972 * @param hw pointer to HW object
973 * @param io pointer to IO object
975 * @return Return pointer to next WQ
978 ocs_hw_queue_next_wq(ocs_hw_t *hw, ocs_hw_io_t *io)
983 switch(io->wq_steering) {
984 case OCS_HW_WQ_STEERING_CLASS:
985 if (likely(io->wq_class < ARRAY_SIZE(hw->wq_class_array))) {
986 wq = ocs_varray_iter_next(hw->wq_class_array[io->wq_class]);
989 case OCS_HW_WQ_STEERING_REQUEST:
991 if (likely(eq != NULL)) {
992 wq = ocs_varray_iter_next(eq->wq_array);
995 case OCS_HW_WQ_STEERING_CPU: {
996 uint32_t cpuidx = ocs_thread_getcpu();
998 if (likely(cpuidx < ARRAY_SIZE(hw->wq_cpu_array))) {
999 wq = ocs_varray_iter_next(hw->wq_cpu_array[cpuidx]);
1005 if (unlikely(wq == NULL)) {
1013 * @brief Return count of EQs for a queue topology object
1015 * The EQ count for in the HWs queue topology (hw->qtop) object is returned
1017 * @param hw pointer to HW object
1019 * @return count of EQs
1022 ocs_hw_qtop_eq_count(ocs_hw_t *hw)
1024 return hw->qtop->entry_counts[QTOP_EQ];
1027 #define TOKEN_LEN 32
1030 * @brief return string given a QTOP entry
1032 * @param entry QTOP entry
1034 * @return returns string or "unknown"
1038 qtopentry2s(ocs_hw_qtop_entry_e entry) {
1040 #define P(x) case x: return #x;
1046 P(QTOP_THREAD_START)
1056 * @brief Declare token types
1071 * @brief Declare token sub-types
1086 * @brief convert queue subtype to QTOP entry
1088 * @param q queue subtype
1090 * @return QTOP entry or 0
1092 static ocs_hw_qtop_entry_e
1093 subtype2qtop(tok_subtype_e q)
1096 case TOK_SUB_EQ: return QTOP_EQ;
1097 case TOK_SUB_CQ: return QTOP_CQ;
1098 case TOK_SUB_RQ: return QTOP_RQ;
1099 case TOK_SUB_MQ: return QTOP_MQ;
1100 case TOK_SUB_WQ: return QTOP_WQ;
1108 * @brief Declare token object
1112 tok_subtype_e subtype;
1113 char string[TOKEN_LEN];
1117 * @brief Declare token array object
1120 tok_t *tokens; /* Pointer to array of tokens */
1121 uint32_t alloc_count; /* Number of tokens in the array */
1122 uint32_t inuse_count; /* Number of tokens posted to array */
1123 uint32_t iter_idx; /* Iterator index */
1127 * @brief Declare token match structure
1132 tok_subtype_e subtype;
1136 * @brief test if character is ID start character
1138 * @param c character to test
1140 * @return TRUE if character is an ID start character
1145 return isalpha(c) || (c == '_') || (c == '$');
1149 * @brief test if character is an ID character
1151 * @param c character to test
1153 * @return TRUE if character is an ID character
1158 return idstart(c) || ocs_isdigit(c);
1162 * @brief Declare single character matches
1164 static tokmatch_t cmatches[] = {
1172 * @brief Declare identifier match strings
1174 static tokmatch_t smatches[] = {
1175 {"eq", TOK_QUEUE, TOK_SUB_EQ},
1176 {"cq", TOK_QUEUE, TOK_SUB_CQ},
1177 {"rq", TOK_QUEUE, TOK_SUB_RQ},
1178 {"mq", TOK_QUEUE, TOK_SUB_MQ},
1179 {"wq", TOK_QUEUE, TOK_SUB_WQ},
1180 {"len", TOK_ATTR_NAME, TOK_SUB_LEN},
1181 {"class", TOK_ATTR_NAME, TOK_SUB_CLASS},
1182 {"ulp", TOK_ATTR_NAME, TOK_SUB_ULP},
1183 {"filter", TOK_ATTR_NAME, TOK_SUB_FILTER},
1187 * @brief Scan string and return next token
1189 * The string is scanned and the next token is returned
1191 * @param s input string to scan
1192 * @param tok pointer to place scanned token
1194 * @return pointer to input string following scanned token, or NULL
1197 tokenize(const char *s, tok_t *tok)
1201 memset(tok, 0, sizeof(*tok));
1203 /* Skip over whitespace */
1204 while (*s && ocs_isspace(*s)) {
1208 /* Return if nothing left in this string */
1213 /* Look for single character matches */
1214 for (i = 0; i < ARRAY_SIZE(cmatches); i++) {
1215 if (cmatches[i].s[0] == *s) {
1216 tok->type = cmatches[i].type;
1217 tok->subtype = cmatches[i].subtype;
1218 tok->string[0] = *s++;
1223 /* Scan for a hex number or decimal */
1224 if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) {
1225 char *p = tok->string;
1227 tok->type = TOK_NUMBER;
1231 while ((*s == '.') || ocs_isxdigit(*s)) {
1232 if ((p - tok->string) < (int32_t)sizeof(tok->string)) {
1236 tok->type = TOK_NUMBER_LIST;
1242 } else if (ocs_isdigit(*s)) {
1243 char *p = tok->string;
1245 tok->type = TOK_NUMBER;
1246 while ((*s == ',') || ocs_isdigit(*s)) {
1247 if ((p - tok->string) < (int32_t)sizeof(tok->string)) {
1251 tok->type = TOK_NUMBER_LIST;
1259 /* Scan for an ID */
1261 char *p = tok->string;
1263 for (*p++ = *s++; idchar(*s); s++) {
1264 if ((p - tok->string) < TOKEN_LEN) {
1269 /* See if this is a $ number value */
1270 if (tok->string[0] == '$') {
1271 tok->type = TOK_NUMBER_VALUE;
1273 /* Look for a string match */
1274 for (i = 0; i < ARRAY_SIZE(smatches); i++) {
1275 if (strcmp(smatches[i].s, tok->string) == 0) {
1276 tok->type = smatches[i].type;
1277 tok->subtype = smatches[i].subtype;
1287 * @brief convert token type to string
1289 * @param type token type
1291 * @return string, or "unknown"
1294 token_type2s(tok_type_e type)
1297 #define P(x) case x: return #x;
1313 * @brief convert token sub-type to string
1315 * @param subtype token sub-type
1317 * @return string, or "unknown"
1320 token_subtype2s(tok_subtype_e subtype)
1323 #define P(x) case x: return #x;
1339 * @brief Generate syntax error message
1341 * A syntax error message is found, the input tokens are dumped up to and including
1342 * the token that failed as indicated by the current iterator index.
1344 * @param hw pointer to HW object
1345 * @param tokarray pointer to token array object
1350 tok_syntax(ocs_hw_t *hw, tokarray_t *tokarray)
1355 ocs_log_test(hw->os, "Syntax error:\n");
1357 for (i = 0, tok = tokarray->tokens; (i <= tokarray->inuse_count); i++, tok++) {
1358 ocs_log_test(hw->os, "%s [%2d] %-16s %-16s %s\n", (i == tokarray->iter_idx) ? ">>>" : " ", i,
1359 token_type2s(tok->type), token_subtype2s(tok->subtype), tok->string);
1364 * @brief parse a number
1366 * Parses tokens of type TOK_NUMBER and TOK_NUMBER_VALUE, returning a numeric value
1368 * @param hw pointer to HW object
1369 * @param qtop pointer to QTOP object
1370 * @param tok pointer to token to parse
1372 * @return numeric value
1375 tok_getnumber(ocs_hw_t *hw, ocs_hw_qtop_t *qtop, tok_t *tok)
1378 uint32_t num_cpus = ocs_get_num_cpus();
1381 case TOK_NUMBER_VALUE:
1382 if (ocs_strcmp(tok->string, "$ncpu") == 0) {
1384 } else if (ocs_strcmp(tok->string, "$ncpu1") == 0) {
1385 rval = num_cpus - 1;
1386 } else if (ocs_strcmp(tok->string, "$nwq") == 0) {
1388 rval = hw->config.n_wq;
1390 } else if (ocs_strcmp(tok->string, "$maxmrq") == 0) {
1391 rval = MIN(num_cpus, OCS_HW_MAX_MRQS);
1392 } else if (ocs_strcmp(tok->string, "$nulp") == 0) {
1393 rval = hw->ulp_max - hw->ulp_start + 1;
1394 } else if ((qtop->rptcount_idx > 0) && ocs_strcmp(tok->string, "$rpt0") == 0) {
1395 rval = qtop->rptcount[qtop->rptcount_idx-1];
1396 } else if ((qtop->rptcount_idx > 1) && ocs_strcmp(tok->string, "$rpt1") == 0) {
1397 rval = qtop->rptcount[qtop->rptcount_idx-2];
1398 } else if ((qtop->rptcount_idx > 2) && ocs_strcmp(tok->string, "$rpt2") == 0) {
1399 rval = qtop->rptcount[qtop->rptcount_idx-3];
1400 } else if ((qtop->rptcount_idx > 3) && ocs_strcmp(tok->string, "$rpt3") == 0) {
1401 rval = qtop->rptcount[qtop->rptcount_idx-4];
1403 rval = ocs_strtoul(tok->string, 0, 0);
1407 rval = ocs_strtoul(tok->string, 0, 0);
1416 * @brief parse an array of tokens
1418 * The tokens are semantically parsed, to generate QTOP entries.
1420 * @param hw pointer to HW object
1421 * @param tokarray array array of tokens
1422 * @param qtop ouptut QTOP object
1424 * @return returns 0 for success, a negative error code value for failure.
1427 parse_topology(ocs_hw_t *hw, tokarray_t *tokarray, ocs_hw_qtop_t *qtop)
1429 ocs_hw_qtop_entry_t *qt = qtop->entries + qtop->inuse_count;
1432 for (; (tokarray->iter_idx < tokarray->inuse_count) &&
1433 ((tok = &tokarray->tokens[tokarray->iter_idx]) != NULL); ) {
1434 if (qtop->inuse_count >= qtop->alloc_count) {
1438 qt = qtop->entries + qtop->inuse_count;
1440 switch (tok[0].type)
1443 qt->entry = subtype2qtop(tok[0].subtype);
1444 qt->set_default = FALSE;
1447 qtop->inuse_count++;
1449 tokarray->iter_idx++; /* Advance current token index */
1451 /* Parse for queue attributes, possibly multiple instances */
1452 while ((tokarray->iter_idx + 4) <= tokarray->inuse_count) {
1453 tok = &tokarray->tokens[tokarray->iter_idx];
1454 if( (tok[0].type == TOK_COLON) &&
1455 (tok[1].type == TOK_ATTR_NAME) &&
1456 (tok[2].type == TOK_EQUALS) &&
1457 ((tok[3].type == TOK_NUMBER) ||
1458 (tok[3].type == TOK_NUMBER_VALUE) ||
1459 (tok[3].type == TOK_NUMBER_LIST))) {
1460 switch (tok[1].subtype) {
1462 qt->len = tok_getnumber(hw, qtop, &tok[3]);
1466 qt->class = tok_getnumber(hw, qtop, &tok[3]);
1470 qt->ulp = tok_getnumber(hw, qtop, &tok[3]);
1473 case TOK_SUB_FILTER:
1474 if (tok[3].type == TOK_NUMBER_LIST) {
1476 char *p = tok[3].string;
1478 while ((p != NULL) && *p) {
1481 v = ocs_strtoul(p, 0, 0);
1486 p = ocs_strchr(p, ',');
1491 qt->filter_mask = mask;
1493 qt->filter_mask = (1U << tok_getnumber(hw, qtop, &tok[3]));
1499 /* Advance current token index */
1500 tokarray->iter_idx += 4;
1505 qtop->entry_counts[qt->entry]++;
1509 if ( ((tokarray->iter_idx + 5) <= tokarray->inuse_count) &&
1510 (tok[1].type == TOK_COLON) &&
1511 (tok[2].type == TOK_QUEUE) &&
1512 (tok[3].type == TOK_EQUALS) &&
1513 ((tok[4].type == TOK_NUMBER) || (tok[4].type == TOK_NUMBER_VALUE))) {
1514 qt->entry = subtype2qtop(tok[2].subtype);
1515 qt->set_default = TRUE;
1516 switch(tok[0].subtype) {
1518 qt->len = tok_getnumber(hw, qtop, &tok[4]);
1521 qt->class = tok_getnumber(hw, qtop, &tok[4]);
1524 qt->ulp = tok_getnumber(hw, qtop, &tok[4]);
1529 qtop->inuse_count++;
1530 tokarray->iter_idx += 5;
1532 tok_syntax(hw, tokarray);
1538 case TOK_NUMBER_VALUE: {
1539 uint32_t rpt_count = 1;
1542 rpt_count = tok_getnumber(hw, qtop, tok);
1544 if (tok[1].type == TOK_LPAREN) {
1545 uint32_t iter_idx_save;
1547 tokarray->iter_idx += 2;
1549 /* save token array iteration index */
1550 iter_idx_save = tokarray->iter_idx;
1552 for (i = 0; i < rpt_count; i++) {
1553 uint32_t rptcount_idx = qtop->rptcount_idx;
1555 if (qtop->rptcount_idx < ARRAY_SIZE(qtop->rptcount)) {
1556 qtop->rptcount[qtop->rptcount_idx++] = i;
1559 /* restore token array iteration index */
1560 tokarray->iter_idx = iter_idx_save;
1562 /* parse, append to qtop */
1563 parse_topology(hw, tokarray, qtop);
1565 qtop->rptcount_idx = rptcount_idx;
1572 tokarray->iter_idx++;
1576 tok_syntax(hw, tokarray);
1584 * @brief Parse queue topology string
1586 * The queue topology object is allocated, and filled with the results of parsing the
1587 * passed in queue topology string
1589 * @param hw pointer to HW object
1590 * @param qtop_string input queue topology string
1592 * @return pointer to allocated QTOP object, or NULL if there was an error
1595 ocs_hw_qtop_parse(ocs_hw_t *hw, const char *qtop_string)
1597 ocs_hw_qtop_t *qtop;
1598 tokarray_t tokarray;
1602 ocs_hw_qtop_entry_t *qt;
1605 ocs_log_debug(hw->os, "queue topology: %s\n", qtop_string);
1607 /* Allocate a token array */
1608 tokarray.tokens = ocs_malloc(hw->os, MAX_TOKENS * sizeof(*tokarray.tokens), OCS_M_ZERO | OCS_M_NOWAIT);
1609 if (tokarray.tokens == NULL) {
1612 tokarray.alloc_count = MAX_TOKENS;
1613 tokarray.inuse_count = 0;
1614 tokarray.iter_idx = 0;
1616 /* Parse the tokens */
1617 for (s = qtop_string; (tokarray.inuse_count < tokarray.alloc_count) &&
1618 ((s = tokenize(s, &tokarray.tokens[tokarray.inuse_count]))) != NULL; ) {
1619 tokarray.inuse_count++;
1622 /* Allocate a queue topology structure */
1623 qtop = ocs_malloc(hw->os, sizeof(*qtop), OCS_M_ZERO | OCS_M_NOWAIT);
1625 ocs_free(hw->os, tokarray.tokens, MAX_TOKENS * sizeof(*tokarray.tokens));
1626 ocs_log_err(hw->os, "malloc qtop failed\n");
1631 /* Allocate queue topology entries */
1632 qtop->entries = ocs_malloc(hw->os, OCS_HW_MAX_QTOP_ENTRIES*sizeof(*qtop->entries), OCS_M_ZERO | OCS_M_NOWAIT);
1633 if (qtop->entries == NULL) {
1634 ocs_log_err(hw->os, "malloc qtop entries failed\n");
1635 ocs_free(hw->os, qtop, sizeof(*qtop));
1636 ocs_free(hw->os, tokarray.tokens, MAX_TOKENS * sizeof(*tokarray.tokens));
1639 qtop->alloc_count = OCS_HW_MAX_QTOP_ENTRIES;
1640 qtop->inuse_count = 0;
1642 /* Parse the tokens */
1643 parse_topology(hw, &tokarray, qtop);
1645 for (i = 0, qt = qtop->entries; i < qtop->inuse_count; i++, qt++) {
1646 ocs_log_debug(hw->os, "entry %s set_df %d len %4d class %d ulp %d\n", qtopentry2s(qt->entry), qt->set_default, qt->len,
1647 qt->class, qt->ulp);
1651 /* Free the tokens array */
1652 ocs_free(hw->os, tokarray.tokens, MAX_TOKENS * sizeof(*tokarray.tokens));
1658 * @brief free queue topology object
1660 * @param qtop pointer to QTOP object
1665 ocs_hw_qtop_free(ocs_hw_qtop_t *qtop)
1668 if (qtop->entries != NULL) {
1669 ocs_free(qtop->os, qtop->entries, qtop->alloc_count*sizeof(*qtop->entries));
1671 ocs_free(qtop->os, qtop, sizeof(*qtop));
1675 /* Uncomment this to turn on RQ debug */
1676 // #define ENABLE_DEBUG_RQBUF
1678 static int32_t ocs_hw_rqpair_find(ocs_hw_t *hw, uint16_t rq_id);
1679 static ocs_hw_sequence_t * ocs_hw_rqpair_get(ocs_hw_t *hw, uint16_t rqindex, uint16_t bufindex);
1680 static int32_t ocs_hw_rqpair_put(ocs_hw_t *hw, ocs_hw_sequence_t *seq);
1681 static ocs_hw_rtn_e ocs_hw_rqpair_auto_xfer_rdy_buffer_sequence_reset(ocs_hw_t *hw, ocs_hw_sequence_t *seq);
1684 * @brief Process receive queue completions for RQ Pair mode.
1687 * RQ completions are processed. In RQ pair mode, a single header and single payload
1688 * buffer are received, and passed to the function that has registered for unsolicited
1691 * @param hw Hardware context.
1692 * @param cq Pointer to HW completion queue.
1693 * @param cqe Completion queue entry.
1695 * @return Returns 0 for success, or a negative error code value for failure.
1699 ocs_hw_rqpair_process_rq(ocs_hw_t *hw, hw_cq_t *cq, uint8_t *cqe)
1707 ocs_hw_sequence_t *seq;
1709 rq_status = sli_fc_rqe_rqid_and_index(&hw->sli, cqe, &rq_id, &index);
1710 if (0 != rq_status) {
1711 switch (rq_status) {
1712 case SLI4_FC_ASYNC_RQ_BUF_LEN_EXCEEDED:
1713 case SLI4_FC_ASYNC_RQ_DMA_FAILURE:
1714 /* just get RQ buffer then return to chip */
1715 rqindex = ocs_hw_rqpair_find(hw, rq_id);
1717 ocs_log_test(hw->os, "status=%#x: rq_id lookup failed for id=%#x\n",
1723 seq = ocs_hw_rqpair_get(hw, rqindex, index);
1725 /* return to chip */
1726 if (ocs_hw_rqpair_sequence_free(hw, seq)) {
1727 ocs_log_test(hw->os, "status=%#x, failed to return buffers to RQ\n",
1732 case SLI4_FC_ASYNC_RQ_INSUFF_BUF_NEEDED:
1733 case SLI4_FC_ASYNC_RQ_INSUFF_BUF_FRM_DISC:
1734 /* since RQ buffers were not consumed, cannot return them to chip */
1736 ocs_log_debug(hw->os, "Warning: RCQE status=%#x, \n", rq_status);
1743 rqindex = ocs_hw_rqpair_find(hw, rq_id);
1745 ocs_log_test(hw->os, "Error: rq_id lookup failed for id=%#x\n", rq_id);
1749 OCS_STAT({ hw_rq_t *rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; rq->use_count++; rq->hdr_use_count++;
1750 rq->payload_use_count++;})
1752 seq = ocs_hw_rqpair_get(hw, rqindex, index);
1753 ocs_hw_assert(seq != NULL);
1757 seq->out_of_xris = 0;
1761 sli_fc_rqe_length(&hw->sli, cqe, &h_len, &p_len);
1762 seq->header->dma.len = h_len;
1763 seq->payload->dma.len = p_len;
1764 seq->fcfi = sli_fc_rqe_fcfi(&hw->sli, cqe);
1765 seq->hw_priv = cq->eq;
1767 /* bounce enabled, single RQ, we snoop the ox_id to choose the cpuidx */
1768 if (hw->config.bounce) {
1769 fc_header_t *hdr = seq->header->dma.virt;
1770 uint32_t s_id = fc_be24toh(hdr->s_id);
1771 uint32_t d_id = fc_be24toh(hdr->d_id);
1772 uint32_t ox_id = ocs_be16toh(hdr->ox_id);
1773 if (hw->callback.bounce != NULL) {
1774 (*hw->callback.bounce)(ocs_hw_unsol_process_bounce, seq, s_id, d_id, ox_id);
1777 hw->callback.unsolicited(hw->args.unsolicited, seq);
1784 * @brief Process receive queue completions for RQ Pair mode - Auto xfer rdy
1787 * RQ completions are processed. In RQ pair mode, a single header and single payload
1788 * buffer are received, and passed to the function that has registered for unsolicited
1791 * @param hw Hardware context.
1792 * @param cq Pointer to HW completion queue.
1793 * @param cqe Completion queue entry.
1795 * @return Returns 0 for success, or a negative error code value for failure.
1799 ocs_hw_rqpair_process_auto_xfr_rdy_cmd(ocs_hw_t *hw, hw_cq_t *cq, uint8_t *cqe)
1801 /* Seems silly to call a SLI function to decode - use the structure directly for performance */
1802 sli4_fc_optimized_write_cmd_cqe_t *opt_wr = (sli4_fc_optimized_write_cmd_cqe_t*)cqe;
1809 ocs_hw_sequence_t *seq;
1810 uint8_t axr_lock_taken = 0;
1811 #if defined(OCS_DISC_SPIN_DELAY)
1816 rq_status = sli_fc_rqe_rqid_and_index(&hw->sli, cqe, &rq_id, &index);
1817 if (0 != rq_status) {
1818 switch (rq_status) {
1819 case SLI4_FC_ASYNC_RQ_BUF_LEN_EXCEEDED:
1820 case SLI4_FC_ASYNC_RQ_DMA_FAILURE:
1821 /* just get RQ buffer then return to chip */
1822 rqindex = ocs_hw_rqpair_find(hw, rq_id);
1824 ocs_log_err(hw->os, "status=%#x: rq_id lookup failed for id=%#x\n",
1830 seq = ocs_hw_rqpair_get(hw, rqindex, index);
1832 /* return to chip */
1833 if (ocs_hw_rqpair_sequence_free(hw, seq)) {
1834 ocs_log_err(hw->os, "status=%#x, failed to return buffers to RQ\n",
1839 case SLI4_FC_ASYNC_RQ_INSUFF_BUF_NEEDED:
1840 case SLI4_FC_ASYNC_RQ_INSUFF_BUF_FRM_DISC:
1841 /* since RQ buffers were not consumed, cannot return them to chip */
1842 ocs_log_debug(hw->os, "Warning: RCQE status=%#x, \n", rq_status);
1850 rqindex = ocs_hw_rqpair_find(hw, rq_id);
1852 ocs_log_err(hw->os, "Error: rq_id lookup failed for id=%#x\n", rq_id);
1856 OCS_STAT({ hw_rq_t *rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; rq->use_count++; rq->hdr_use_count++;
1857 rq->payload_use_count++;})
1859 seq = ocs_hw_rqpair_get(hw, rqindex, index);
1860 ocs_hw_assert(seq != NULL);
1863 seq->auto_xrdy = opt_wr->agxr;
1864 seq->out_of_xris = opt_wr->oox;
1865 seq->xri = opt_wr->xri;
1868 sli_fc_rqe_length(&hw->sli, cqe, &h_len, &p_len);
1869 seq->header->dma.len = h_len;
1870 seq->payload->dma.len = p_len;
1871 seq->fcfi = sli_fc_rqe_fcfi(&hw->sli, cqe);
1872 seq->hw_priv = cq->eq;
1874 if (seq->auto_xrdy) {
1875 fc_header_t *fc_hdr = seq->header->dma.virt;
1877 seq->hio = ocs_hw_io_lookup(hw, seq->xri);
1878 ocs_lock(&seq->hio->axr_lock);
1881 /* save the FCFI, src_id, dest_id and ox_id because we need it for the sequence object when the data comes. */
1882 seq->hio->axr_buf->fcfi = seq->fcfi;
1883 seq->hio->axr_buf->hdr.ox_id = fc_hdr->ox_id;
1884 seq->hio->axr_buf->hdr.s_id = fc_hdr->s_id;
1885 seq->hio->axr_buf->hdr.d_id = fc_hdr->d_id;
1886 seq->hio->axr_buf->cmd_cqe = 1;
1889 * Since auto xfer rdy is used for this IO, then clear the sequence
1890 * initiative bit in the header so that the upper layers wait for the
1891 * data. This should flow exactly like the first burst case.
1893 fc_hdr->f_ctl &= fc_htobe24(~FC_FCTL_SEQUENCE_INITIATIVE);
1895 /* If AXR CMD CQE came before previous TRSP CQE of same XRI */
1896 if (seq->hio->type == OCS_HW_IO_TARGET_RSP) {
1897 seq->hio->axr_buf->call_axr_cmd = 1;
1898 seq->hio->axr_buf->cmd_seq = seq;
1899 goto exit_ocs_hw_rqpair_process_auto_xfr_rdy_cmd;
1903 /* bounce enabled, single RQ, we snoop the ox_id to choose the cpuidx */
1904 if (hw->config.bounce) {
1905 fc_header_t *hdr = seq->header->dma.virt;
1906 uint32_t s_id = fc_be24toh(hdr->s_id);
1907 uint32_t d_id = fc_be24toh(hdr->d_id);
1908 uint32_t ox_id = ocs_be16toh(hdr->ox_id);
1909 if (hw->callback.bounce != NULL) {
1910 (*hw->callback.bounce)(ocs_hw_unsol_process_bounce, seq, s_id, d_id, ox_id);
1913 hw->callback.unsolicited(hw->args.unsolicited, seq);
1916 if (seq->auto_xrdy) {
1917 /* If data cqe came before cmd cqe in out of order in case of AXR */
1918 if(seq->hio->axr_buf->data_cqe == 1) {
1919 #if defined(OCS_DISC_SPIN_DELAY)
1920 if (ocs_get_property("disk_spin_delay", prop_buf, sizeof(prop_buf)) == 0) {
1921 delay = ocs_strtoul(prop_buf, 0, 0);
1925 /* bounce enabled, single RQ, we snoop the ox_id to choose the cpuidx */
1926 if (hw->config.bounce) {
1927 fc_header_t *hdr = seq->header->dma.virt;
1928 uint32_t s_id = fc_be24toh(hdr->s_id);
1929 uint32_t d_id = fc_be24toh(hdr->d_id);
1930 uint32_t ox_id = ocs_be16toh(hdr->ox_id);
1931 if (hw->callback.bounce != NULL) {
1932 (*hw->callback.bounce)(ocs_hw_unsol_process_bounce, &seq->hio->axr_buf->seq, s_id, d_id, ox_id);
1935 hw->callback.unsolicited(hw->args.unsolicited, &seq->hio->axr_buf->seq);
1940 exit_ocs_hw_rqpair_process_auto_xfr_rdy_cmd:
1941 if(axr_lock_taken) {
1942 ocs_unlock(&seq->hio->axr_lock);
1948 * @brief Process CQ completions for Auto xfer rdy data phases.
1951 * The data is DMA'd into the data buffer posted to the SGL prior to the XRI
1952 * being assigned to an IO. When the completion is received, All of the data
1953 * is in the single buffer.
1955 * @param hw Hardware context.
1956 * @param cq Pointer to HW completion queue.
1957 * @param cqe Completion queue entry.
1959 * @return Returns 0 for success, or a negative error code value for failure.
1963 ocs_hw_rqpair_process_auto_xfr_rdy_data(ocs_hw_t *hw, hw_cq_t *cq, uint8_t *cqe)
1965 /* Seems silly to call a SLI function to decode - use the structure directly for performance */
1966 sli4_fc_optimized_write_data_cqe_t *opt_wr = (sli4_fc_optimized_write_data_cqe_t*)cqe;
1967 ocs_hw_sequence_t *seq;
1969 ocs_hw_auto_xfer_rdy_buffer_t *buf;
1970 #if defined(OCS_DISC_SPIN_DELAY)
1974 /* Look up the IO */
1975 io = ocs_hw_io_lookup(hw, opt_wr->xri);
1976 ocs_lock(&io->axr_lock);
1982 seq->out_of_xris = 0;
1983 seq->xri = opt_wr->xri;
1985 seq->header = &buf->header;
1986 seq->payload = &buf->payload;
1988 seq->header->dma.len = sizeof(fc_header_t);
1989 seq->payload->dma.len = opt_wr->total_data_placed;
1990 seq->fcfi = buf->fcfi;
1991 seq->hw_priv = cq->eq;
1993 if (opt_wr->status == SLI4_FC_WCQE_STATUS_SUCCESS) {
1994 seq->status = OCS_HW_UNSOL_SUCCESS;
1995 } else if (opt_wr->status == SLI4_FC_WCQE_STATUS_REMOTE_STOP) {
1996 seq->status = OCS_HW_UNSOL_ABTS_RCVD;
1998 seq->status = OCS_HW_UNSOL_ERROR;
2001 /* If AXR CMD CQE came before previous TRSP CQE of same XRI */
2002 if(io->type == OCS_HW_IO_TARGET_RSP) {
2003 io->axr_buf->call_axr_data = 1;
2004 goto exit_ocs_hw_rqpair_process_auto_xfr_rdy_data;
2008 /* if data cqe came before cmd cqe, return here, cmd cqe will handle */
2009 goto exit_ocs_hw_rqpair_process_auto_xfr_rdy_data;
2011 #if defined(OCS_DISC_SPIN_DELAY)
2012 if (ocs_get_property("disk_spin_delay", prop_buf, sizeof(prop_buf)) == 0) {
2013 delay = ocs_strtoul(prop_buf, 0, 0);
2018 /* bounce enabled, single RQ, we snoop the ox_id to choose the cpuidx */
2019 if (hw->config.bounce) {
2020 fc_header_t *hdr = seq->header->dma.virt;
2021 uint32_t s_id = fc_be24toh(hdr->s_id);
2022 uint32_t d_id = fc_be24toh(hdr->d_id);
2023 uint32_t ox_id = ocs_be16toh(hdr->ox_id);
2024 if (hw->callback.bounce != NULL) {
2025 (*hw->callback.bounce)(ocs_hw_unsol_process_bounce, seq, s_id, d_id, ox_id);
2028 hw->callback.unsolicited(hw->args.unsolicited, seq);
2031 exit_ocs_hw_rqpair_process_auto_xfr_rdy_data:
2032 ocs_unlock(&io->axr_lock);
2037 * @brief Return pointer to RQ buffer entry.
2040 * Returns a pointer to the RQ buffer entry given by @c rqindex and @c bufindex.
2042 * @param hw Hardware context.
2043 * @param rqindex Index of the RQ that is being processed.
2044 * @param bufindex Index into the RQ that is being processed.
2046 * @return Pointer to the sequence structure, or NULL otherwise.
2048 static ocs_hw_sequence_t *
2049 ocs_hw_rqpair_get(ocs_hw_t *hw, uint16_t rqindex, uint16_t bufindex)
2051 sli4_queue_t *rq_hdr = &hw->rq[rqindex];
2052 sli4_queue_t *rq_payload = &hw->rq[rqindex+1];
2053 ocs_hw_sequence_t *seq = NULL;
2054 hw_rq_t *rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]];
2056 #if defined(ENABLE_DEBUG_RQBUF)
2057 uint64_t rqbuf_debug_value = 0xdead0000 | ((rq->id & 0xf) << 12) | (bufindex & 0xfff);
2060 if (bufindex >= rq_hdr->length) {
2061 ocs_log_err(hw->os, "RQ index %d bufindex %d exceed ring length %d for id %d\n",
2062 rqindex, bufindex, rq_hdr->length, rq_hdr->id);
2066 sli_queue_lock(rq_hdr);
2067 sli_queue_lock(rq_payload);
2069 #if defined(ENABLE_DEBUG_RQBUF)
2070 /* Put a debug value into the rq, to track which entries are still valid */
2071 _sli_queue_poke(&hw->sli, rq_hdr, bufindex, (uint8_t *)&rqbuf_debug_value);
2072 _sli_queue_poke(&hw->sli, rq_payload, bufindex, (uint8_t *)&rqbuf_debug_value);
2075 seq = rq->rq_tracker[bufindex];
2076 rq->rq_tracker[bufindex] = NULL;
2079 ocs_log_err(hw->os, "RQ buffer NULL, rqindex %d, bufindex %d, current q index = %d\n",
2080 rqindex, bufindex, rq_hdr->index);
2083 sli_queue_unlock(rq_payload);
2084 sli_queue_unlock(rq_hdr);
2089 * @brief Posts an RQ buffer to a queue and update the verification structures
2091 * @param hw hardware context
2092 * @param seq Pointer to sequence object.
2094 * @return Returns 0 on success, or a non-zero value otherwise.
2097 ocs_hw_rqpair_put(ocs_hw_t *hw, ocs_hw_sequence_t *seq)
2099 sli4_queue_t *rq_hdr = &hw->rq[seq->header->rqindex];
2100 sli4_queue_t *rq_payload = &hw->rq[seq->payload->rqindex];
2101 uint32_t hw_rq_index = hw->hw_rq_lookup[seq->header->rqindex];
2102 hw_rq_t *rq = hw->hw_rq[hw_rq_index];
2103 uint32_t phys_hdr[2];
2104 uint32_t phys_payload[2];
2106 int32_t qindex_payload;
2108 /* Update the RQ verification lookup tables */
2109 phys_hdr[0] = ocs_addr32_hi(seq->header->dma.phys);
2110 phys_hdr[1] = ocs_addr32_lo(seq->header->dma.phys);
2111 phys_payload[0] = ocs_addr32_hi(seq->payload->dma.phys);
2112 phys_payload[1] = ocs_addr32_lo(seq->payload->dma.phys);
2114 sli_queue_lock(rq_hdr);
2115 sli_queue_lock(rq_payload);
2118 * Note: The header must be posted last for buffer pair mode because
2119 * posting on the header queue posts the payload queue as well.
2120 * We do not ring the payload queue independently in RQ pair mode.
2122 qindex_payload = _sli_queue_write(&hw->sli, rq_payload, (void *)phys_payload);
2123 qindex_hdr = _sli_queue_write(&hw->sli, rq_hdr, (void *)phys_hdr);
2124 if (qindex_hdr < 0 ||
2125 qindex_payload < 0) {
2126 ocs_log_err(hw->os, "RQ_ID=%#x write failed\n", rq_hdr->id);
2127 sli_queue_unlock(rq_payload);
2128 sli_queue_unlock(rq_hdr);
2129 return OCS_HW_RTN_ERROR;
2132 /* ensure the indexes are the same */
2133 ocs_hw_assert(qindex_hdr == qindex_payload);
2135 /* Update the lookup table */
2136 if (rq->rq_tracker[qindex_hdr] == NULL) {
2137 rq->rq_tracker[qindex_hdr] = seq;
2139 ocs_log_test(hw->os, "expected rq_tracker[%d][%d] buffer to be NULL\n",
2140 hw_rq_index, qindex_hdr);
2143 sli_queue_unlock(rq_payload);
2144 sli_queue_unlock(rq_hdr);
2145 return OCS_HW_RTN_SUCCESS;
2149 * @brief Return RQ buffers (while in RQ pair mode).
2152 * The header and payload buffers are returned to the Receive Queue.
2154 * @param hw Hardware context.
2155 * @param seq Header/payload sequence buffers.
2157 * @return Returns OCS_HW_RTN_SUCCESS on success, or an error code value on failure.
2161 ocs_hw_rqpair_sequence_free(ocs_hw_t *hw, ocs_hw_sequence_t *seq)
2163 ocs_hw_rtn_e rc = OCS_HW_RTN_SUCCESS;
2165 /* Check for auto xfer rdy dummy buffers and call the proper release function. */
2166 if (seq->header->rqindex == OCS_HW_RQ_INDEX_DUMMY_HDR) {
2167 return ocs_hw_rqpair_auto_xfer_rdy_buffer_sequence_reset(hw, seq);
2171 * Post the data buffer first. Because in RQ pair mode, ringing the
2172 * doorbell of the header ring will post the data buffer as well.
2174 if (ocs_hw_rqpair_put(hw, seq)) {
2175 ocs_log_err(hw->os, "error writing buffers\n");
2176 return OCS_HW_RTN_ERROR;
2183 * @brief Find the RQ index of RQ_ID.
2185 * @param hw Hardware context.
2186 * @param rq_id RQ ID to find.
2188 * @return Returns the RQ index, or -1 if not found
2190 static inline int32_t
2191 ocs_hw_rqpair_find(ocs_hw_t *hw, uint16_t rq_id)
2193 return ocs_hw_queue_hash_find(hw->rq_hash, rq_id);
2197 * @ingroup devInitShutdown
2198 * @brief Allocate auto xfer rdy buffers.
2201 * Allocates the auto xfer rdy buffers and places them on the free list.
2203 * @param hw Hardware context allocated by the caller.
2204 * @param num_buffers Number of buffers to allocate.
2206 * @return Returns 0 on success, or a non-zero value on failure.
2209 ocs_hw_rqpair_auto_xfer_rdy_buffer_alloc(ocs_hw_t *hw, uint32_t num_buffers)
2211 ocs_hw_auto_xfer_rdy_buffer_t *buf;
2214 hw->auto_xfer_rdy_buf_pool = ocs_pool_alloc(hw->os, sizeof(ocs_hw_auto_xfer_rdy_buffer_t), num_buffers, FALSE);
2215 if (hw->auto_xfer_rdy_buf_pool == NULL) {
2216 ocs_log_err(hw->os, "Failure to allocate auto xfer ready buffer pool\n");
2217 return OCS_HW_RTN_NO_MEMORY;
2220 for (i = 0; i < num_buffers; i++) {
2221 /* allocate the wrapper object */
2222 buf = ocs_pool_get_instance(hw->auto_xfer_rdy_buf_pool, i);
2223 ocs_hw_assert(buf != NULL);
2225 /* allocate the auto xfer ready buffer */
2226 if (ocs_dma_alloc(hw->os, &buf->payload.dma, hw->config.auto_xfer_rdy_size, OCS_MIN_DMA_ALIGNMENT)) {
2227 ocs_log_err(hw->os, "DMA allocation failed\n");
2228 ocs_free(hw->os, buf, sizeof(*buf));
2229 return OCS_HW_RTN_NO_MEMORY;
2232 /* build a fake data header in big endian */
2233 buf->hdr.info = FC_RCTL_INFO_SOL_DATA;
2234 buf->hdr.r_ctl = FC_RCTL_FC4_DATA;
2235 buf->hdr.type = FC_TYPE_FCP;
2236 buf->hdr.f_ctl = fc_htobe24(FC_FCTL_EXCHANGE_RESPONDER |
2237 FC_FCTL_FIRST_SEQUENCE |
2238 FC_FCTL_LAST_SEQUENCE |
2239 FC_FCTL_END_SEQUENCE |
2240 FC_FCTL_SEQUENCE_INITIATIVE);
2242 /* build the fake header DMA object */
2243 buf->header.rqindex = OCS_HW_RQ_INDEX_DUMMY_HDR;
2244 buf->header.dma.virt = &buf->hdr;
2245 buf->header.dma.alloc = buf;
2246 buf->header.dma.size = sizeof(buf->hdr);
2247 buf->header.dma.len = sizeof(buf->hdr);
2249 buf->payload.rqindex = OCS_HW_RQ_INDEX_DUMMY_DATA;
2251 return OCS_HW_RTN_SUCCESS;
2255 * @ingroup devInitShutdown
2256 * @brief Post Auto xfer rdy buffers to the XRIs posted with DNRX.
2259 * When new buffers are freed, check existing XRIs waiting for buffers.
2261 * @param hw Hardware context allocated by the caller.
2264 ocs_hw_rqpair_auto_xfer_rdy_dnrx_check(ocs_hw_t *hw)
2269 ocs_lock(&hw->io_lock);
2271 while (!ocs_list_empty(&hw->io_port_dnrx)) {
2272 io = ocs_list_remove_head(&hw->io_port_dnrx);
2273 rc = ocs_hw_reque_xri(hw, io);
2279 ocs_unlock(&hw->io_lock);
2283 * @brief Called when the POST_SGL_PAGE command completes.
2286 * Free the mailbox command buffer.
2288 * @param hw Hardware context.
2289 * @param status Status field from the mbox completion.
2290 * @param mqe Mailbox response structure.
2291 * @param arg Pointer to a callback function that signals the caller that the command is done.
2293 * @return Returns 0.
2296 ocs_hw_rqpair_auto_xfer_rdy_move_to_port_cb(ocs_hw_t *hw, int32_t status, uint8_t *mqe, void *arg)
2299 ocs_log_debug(hw->os, "Status 0x%x\n", status);
2302 ocs_free(hw->os, mqe, SLI4_BMBX_SIZE);
2307 * @brief Prepares an XRI to move to the chip.
2310 * Puts the data SGL into the SGL list for the IO object and possibly registers
2311 * an SGL list for the XRI. Since both the POST_XRI and POST_SGL_PAGES commands are
2312 * mailbox commands, we don't need to wait for completion before preceding.
2314 * @param hw Hardware context allocated by the caller.
2315 * @param io Pointer to the IO object.
2317 * @return Returns OCS_HW_RTN_SUCCESS for success, or an error code value for failure.
2320 ocs_hw_rqpair_auto_xfer_rdy_move_to_port(ocs_hw_t *hw, ocs_hw_io_t *io)
2322 /* We only need to preregister the SGL if it has not yet been done. */
2323 if (!sli_get_sgl_preregister(&hw->sli)) {
2325 ocs_dma_t *psgls = &io->def_sgl;
2326 ocs_dma_t **sgls = &psgls;
2328 /* non-local buffer required for mailbox queue */
2329 post_sgl = ocs_malloc(hw->os, SLI4_BMBX_SIZE, OCS_M_NOWAIT);
2330 if (post_sgl == NULL) {
2331 ocs_log_err(hw->os, "no buffer for command\n");
2332 return OCS_HW_RTN_NO_MEMORY;
2334 if (sli_cmd_fcoe_post_sgl_pages(&hw->sli, post_sgl, SLI4_BMBX_SIZE,
2335 io->indicator, 1, sgls, NULL, NULL)) {
2336 if (ocs_hw_command(hw, post_sgl, OCS_CMD_NOWAIT,
2337 ocs_hw_rqpair_auto_xfer_rdy_move_to_port_cb, NULL)) {
2338 ocs_free(hw->os, post_sgl, SLI4_BMBX_SIZE);
2339 ocs_log_err(hw->os, "SGL post failed\n");
2340 return OCS_HW_RTN_ERROR;
2345 ocs_lock(&hw->io_lock);
2346 if (ocs_hw_rqpair_auto_xfer_rdy_buffer_post(hw, io, 0) != 0) { /* DNRX set - no buffer */
2347 ocs_unlock(&hw->io_lock);
2348 return OCS_HW_RTN_ERROR;
2350 ocs_unlock(&hw->io_lock);
2351 return OCS_HW_RTN_SUCCESS;
2355 * @brief Prepares an XRI to move back to the host.
2358 * Releases any attached buffer back to the pool.
2360 * @param hw Hardware context allocated by the caller.
2361 * @param io Pointer to the IO object.
2364 ocs_hw_rqpair_auto_xfer_rdy_move_to_host(ocs_hw_t *hw, ocs_hw_io_t *io)
2366 if (io->axr_buf != NULL) {
2367 ocs_lock(&hw->io_lock);
2368 /* check list and remove if there */
2369 if (ocs_list_on_list(&io->dnrx_link)) {
2370 ocs_list_remove(&hw->io_port_dnrx, io);
2371 io->auto_xfer_rdy_dnrx = 0;
2373 /* release the count for waiting for a buffer */
2374 ocs_hw_io_free(hw, io);
2377 ocs_pool_put(hw->auto_xfer_rdy_buf_pool, io->axr_buf);
2379 ocs_unlock(&hw->io_lock);
2381 ocs_hw_rqpair_auto_xfer_rdy_dnrx_check(hw);
2387 * @brief Posts an auto xfer rdy buffer to an IO.
2390 * Puts the data SGL into the SGL list for the IO object
2392 * @b Note: io_lock must be held.
2394 * @param hw Hardware context allocated by the caller.
2395 * @param io Pointer to the IO object.
2397 * @return Returns the value of DNRX bit in the TRSP and ABORT WQEs.
2400 ocs_hw_rqpair_auto_xfer_rdy_buffer_post(ocs_hw_t *hw, ocs_hw_io_t *io, int reuse_buf)
2402 ocs_hw_auto_xfer_rdy_buffer_t *buf;
2406 buf = ocs_pool_get(hw->auto_xfer_rdy_buf_pool);
2410 data = io->def_sgl.virt;
2411 data[0].sge_type = SLI4_SGE_TYPE_SKIP;
2415 * Note: if we are doing DIF assists, then the SGE[1] must contain the
2416 * DI_SEED SGE. The host is responsible for programming:
2417 * SGE Type (Word 2, bits 30:27)
2418 * Replacement App Tag (Word 2 bits 15:0)
2419 * App Tag (Word 3 bits 15:0)
2420 * New Ref Tag (Word 3 bit 23)
2421 * Metadata Enable (Word 3 bit 20)
2422 * Auto-Increment RefTag (Word 3 bit 19)
2423 * Block Size (Word 3 bits 18:16)
2424 * The following fields are managed by the SLI Port:
2425 * Ref Tag Compare (Word 0)
2426 * Replacement Ref Tag (Word 1) - In not the LBA
2427 * NA (Word 2 bit 25)
2428 * Opcode RX (Word 3 bits 27:24)
2429 * Checksum Enable (Word 3 bit 22)
2430 * RefTag Enable (Word 3 bit 21)
2432 * The first two SGLs are cleared by ocs_hw_io_init_sges(), so assume eveything is cleared.
2434 if (hw->config.auto_xfer_rdy_p_type) {
2435 sli4_diseed_sge_t *diseed = (sli4_diseed_sge_t*)&data[1];
2437 diseed->sge_type = SLI4_SGE_TYPE_DISEED;
2438 diseed->repl_app_tag = hw->config.auto_xfer_rdy_app_tag_value;
2439 diseed->app_tag_cmp = hw->config.auto_xfer_rdy_app_tag_value;
2440 diseed->check_app_tag = hw->config.auto_xfer_rdy_app_tag_valid;
2441 diseed->auto_incr_ref_tag = TRUE; /* Always the LBA */
2442 diseed->dif_blk_size = hw->config.auto_xfer_rdy_blk_size_chip;
2444 data[1].sge_type = SLI4_SGE_TYPE_SKIP;
2448 data[2].sge_type = SLI4_SGE_TYPE_DATA;
2449 data[2].buffer_address_high = ocs_addr32_hi(io->axr_buf->payload.dma.phys);
2450 data[2].buffer_address_low = ocs_addr32_lo(io->axr_buf->payload.dma.phys);
2451 data[2].buffer_length = io->axr_buf->payload.dma.size;
2452 data[2].last = TRUE;
2453 data[3].sge_type = SLI4_SGE_TYPE_SKIP;
2459 * @brief Return auto xfer ready buffers (while in RQ pair mode).
2462 * The header and payload buffers are returned to the auto xfer rdy pool.
2464 * @param hw Hardware context.
2465 * @param seq Header/payload sequence buffers.
2467 * @return Returns OCS_HW_RTN_SUCCESS for success, an error code value for failure.
2471 ocs_hw_rqpair_auto_xfer_rdy_buffer_sequence_reset(ocs_hw_t *hw, ocs_hw_sequence_t *seq)
2473 ocs_hw_auto_xfer_rdy_buffer_t *buf = seq->header->dma.alloc;
2478 buf->call_axr_cmd = 0;
2479 buf->call_axr_data = 0;
2481 /* build a fake data header in big endian */
2482 buf->hdr.info = FC_RCTL_INFO_SOL_DATA;
2483 buf->hdr.r_ctl = FC_RCTL_FC4_DATA;
2484 buf->hdr.type = FC_TYPE_FCP;
2485 buf->hdr.f_ctl = fc_htobe24(FC_FCTL_EXCHANGE_RESPONDER |
2486 FC_FCTL_FIRST_SEQUENCE |
2487 FC_FCTL_LAST_SEQUENCE |
2488 FC_FCTL_END_SEQUENCE |
2489 FC_FCTL_SEQUENCE_INITIATIVE);
2491 /* build the fake header DMA object */
2492 buf->header.rqindex = OCS_HW_RQ_INDEX_DUMMY_HDR;
2493 buf->header.dma.virt = &buf->hdr;
2494 buf->header.dma.alloc = buf;
2495 buf->header.dma.size = sizeof(buf->hdr);
2496 buf->header.dma.len = sizeof(buf->hdr);
2497 buf->payload.rqindex = OCS_HW_RQ_INDEX_DUMMY_DATA;
2499 ocs_hw_rqpair_auto_xfer_rdy_dnrx_check(hw);
2501 return OCS_HW_RTN_SUCCESS;
2505 * @ingroup devInitShutdown
2506 * @brief Free auto xfer rdy buffers.
2509 * Frees the auto xfer rdy buffers.
2511 * @param hw Hardware context allocated by the caller.
2513 * @return Returns 0 on success, or a non-zero value on failure.
2516 ocs_hw_rqpair_auto_xfer_rdy_buffer_free(ocs_hw_t *hw)
2518 ocs_hw_auto_xfer_rdy_buffer_t *buf;
2521 if (hw->auto_xfer_rdy_buf_pool != NULL) {
2522 ocs_lock(&hw->io_lock);
2523 for (i = 0; i < ocs_pool_get_count(hw->auto_xfer_rdy_buf_pool); i++) {
2524 buf = ocs_pool_get_instance(hw->auto_xfer_rdy_buf_pool, i);
2526 ocs_dma_free(hw->os, &buf->payload.dma);
2529 ocs_unlock(&hw->io_lock);
2531 ocs_pool_free(hw->auto_xfer_rdy_buf_pool);
2532 hw->auto_xfer_rdy_buf_pool = NULL;
2537 * @ingroup devInitShutdown
2538 * @brief Configure the rq_pair function from ocs_hw_init().
2541 * Allocates the buffers to auto xfer rdy and posts initial XRIs for this feature.
2543 * @param hw Hardware context allocated by the caller.
2545 * @return Returns 0 on success, or a non-zero value on failure.
2548 ocs_hw_rqpair_init(ocs_hw_t *hw)
2551 uint32_t xris_posted;
2553 ocs_log_debug(hw->os, "RQ Pair mode\n");
2556 * If we get this far, the auto XFR_RDY feature was enabled successfully, otherwise ocs_hw_init() would
2557 * return with an error. So allocate the buffers based on the initial XRI pool required to support this
2560 if (sli_get_auto_xfer_rdy_capable(&hw->sli) &&
2561 hw->config.auto_xfer_rdy_size > 0) {
2562 if (hw->auto_xfer_rdy_buf_pool == NULL) {
2564 * Allocate one more buffer than XRIs so that when all the XRIs are in use, we still have
2565 * one to post back for the case where the response phase is started in the context of
2566 * the data completion.
2568 rc = ocs_hw_rqpair_auto_xfer_rdy_buffer_alloc(hw, hw->config.auto_xfer_rdy_xri_cnt + 1);
2569 if (rc != OCS_HW_RTN_SUCCESS) {
2573 ocs_pool_reset(hw->auto_xfer_rdy_buf_pool);
2576 /* Post the auto XFR_RDY XRIs */
2577 xris_posted = ocs_hw_xri_move_to_port_owned(hw, hw->config.auto_xfer_rdy_xri_cnt);
2578 if (xris_posted != hw->config.auto_xfer_rdy_xri_cnt) {
2579 ocs_log_err(hw->os, "post_xri failed, only posted %d XRIs\n", xris_posted);
2580 return OCS_HW_RTN_ERROR;
2588 * @ingroup devInitShutdown
2589 * @brief Tear down the rq_pair function from ocs_hw_teardown().
2592 * Frees the buffers to auto xfer rdy.
2594 * @param hw Hardware context allocated by the caller.
2597 ocs_hw_rqpair_teardown(ocs_hw_t *hw)
2599 /* We need to free any auto xfer ready buffers */
2600 ocs_hw_rqpair_auto_xfer_rdy_buffer_free(hw);