1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/lockdep.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_cmnd.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/fc/fc_fs.h>
35 #include <linux/aer.h>
37 #include <linux/nvme-fc-driver.h>
42 #include "lpfc_sli4.h"
44 #include "lpfc_disc.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_nvmet.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_logmsg.h"
51 #include "lpfc_compat.h"
52 #include "lpfc_debugfs.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_version.h"
56 /* There are only four IOCB completion types. */
57 typedef enum _lpfc_iocb_type {
65 /* Provide function prototypes local to this module. */
66 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
68 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
69 uint8_t *, uint32_t *);
70 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
72 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
74 static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba *, struct lpfc_queue *,
76 static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
78 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *, struct lpfc_eqe *,
80 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
81 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
82 static int lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba,
83 struct lpfc_sli_ring *pring,
84 struct lpfc_iocbq *cmdiocb);
87 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
93 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
94 * @q: The Work Queue to operate on.
95 * @wqe: The work Queue Entry to put on the Work queue.
97 * This routine will copy the contents of @wqe to the next available entry on
98 * the @q. This function will then ring the Work Queue Doorbell to signal the
99 * HBA to start processing the Work Queue Entry. This function returns 0 if
100 * successful. If no entries are available on @q then this function will return
102 * The caller is expected to hold the hbalock when calling this routine.
105 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe)
107 union lpfc_wqe *temp_wqe;
108 struct lpfc_register doorbell;
112 /* sanity check on queue memory */
115 temp_wqe = q->qe[q->host_index].wqe;
117 /* If the host has not yet processed the next entry then we are done */
118 idx = ((q->host_index + 1) % q->entry_count);
119 if (idx == q->hba_index) {
124 /* set consumption flag every once in a while */
125 if (!((q->host_index + 1) % q->entry_repost))
126 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
127 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
128 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
129 lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
130 /* ensure WQE bcopy flushed before doorbell write */
133 /* Update the host index before invoking device */
134 host_index = q->host_index;
140 if (q->db_format == LPFC_DB_LIST_FORMAT) {
141 bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
142 bf_set(lpfc_wq_db_list_fm_index, &doorbell, host_index);
143 bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
144 } else if (q->db_format == LPFC_DB_RING_FORMAT) {
145 bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
146 bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
150 writel(doorbell.word0, q->db_regaddr);
156 * lpfc_sli4_wq_release - Updates internal hba index for WQ
157 * @q: The Work Queue to operate on.
158 * @index: The index to advance the hba index to.
160 * This routine will update the HBA index of a queue to reflect consumption of
161 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
162 * an entry the host calls this function to update the queue's internal
163 * pointers. This routine returns the number of entries that were consumed by
167 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
169 uint32_t released = 0;
171 /* sanity check on queue memory */
175 if (q->hba_index == index)
178 q->hba_index = ((q->hba_index + 1) % q->entry_count);
180 } while (q->hba_index != index);
185 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
186 * @q: The Mailbox Queue to operate on.
187 * @wqe: The Mailbox Queue Entry to put on the Work queue.
189 * This routine will copy the contents of @mqe to the next available entry on
190 * the @q. This function will then ring the Work Queue Doorbell to signal the
191 * HBA to start processing the Work Queue Entry. This function returns 0 if
192 * successful. If no entries are available on @q then this function will return
194 * The caller is expected to hold the hbalock when calling this routine.
197 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
199 struct lpfc_mqe *temp_mqe;
200 struct lpfc_register doorbell;
202 /* sanity check on queue memory */
205 temp_mqe = q->qe[q->host_index].mqe;
207 /* If the host has not yet processed the next entry then we are done */
208 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
210 lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
211 /* Save off the mailbox pointer for completion */
212 q->phba->mbox = (MAILBOX_t *)temp_mqe;
214 /* Update the host index before invoking device */
215 q->host_index = ((q->host_index + 1) % q->entry_count);
219 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
220 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
221 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
226 * lpfc_sli4_mq_release - Updates internal hba index for MQ
227 * @q: The Mailbox Queue to operate on.
229 * This routine will update the HBA index of a queue to reflect consumption of
230 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
231 * an entry the host calls this function to update the queue's internal
232 * pointers. This routine returns the number of entries that were consumed by
236 lpfc_sli4_mq_release(struct lpfc_queue *q)
238 /* sanity check on queue memory */
242 /* Clear the mailbox pointer for completion */
243 q->phba->mbox = NULL;
244 q->hba_index = ((q->hba_index + 1) % q->entry_count);
249 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
250 * @q: The Event Queue to get the first valid EQE from
252 * This routine will get the first valid Event Queue Entry from @q, update
253 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
254 * the Queue (no more work to do), or the Queue is full of EQEs that have been
255 * processed, but not popped back to the HBA then this routine will return NULL.
257 static struct lpfc_eqe *
258 lpfc_sli4_eq_get(struct lpfc_queue *q)
260 struct lpfc_eqe *eqe;
263 /* sanity check on queue memory */
266 eqe = q->qe[q->hba_index].eqe;
268 /* If the next EQE is not valid then we are done */
269 if (!bf_get_le32(lpfc_eqe_valid, eqe))
271 /* If the host has not yet processed the next entry then we are done */
272 idx = ((q->hba_index + 1) % q->entry_count);
273 if (idx == q->host_index)
279 * insert barrier for instruction interlock : data from the hardware
280 * must have the valid bit checked before it can be copied and acted
281 * upon. Speculative instructions were allowing a bcopy at the start
282 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
283 * after our return, to copy data before the valid bit check above
284 * was done. As such, some of the copied data was stale. The barrier
285 * ensures the check is before any data is copied.
292 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
293 * @q: The Event Queue to disable interrupts
297 lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
299 struct lpfc_register doorbell;
302 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
303 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
304 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
305 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
306 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
307 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
311 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
312 * @q: The Event Queue that the host has completed processing for.
313 * @arm: Indicates whether the host wants to arms this CQ.
315 * This routine will mark all Event Queue Entries on @q, from the last
316 * known completed entry to the last entry that was processed, as completed
317 * by clearing the valid bit for each completion queue entry. Then it will
318 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
319 * The internal host index in the @q will be updated by this routine to indicate
320 * that the host has finished processing the entries. The @arm parameter
321 * indicates that the queue should be rearmed when ringing the doorbell.
323 * This function will return the number of EQEs that were popped.
326 lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm)
328 uint32_t released = 0;
329 struct lpfc_eqe *temp_eqe;
330 struct lpfc_register doorbell;
332 /* sanity check on queue memory */
336 /* while there are valid entries */
337 while (q->hba_index != q->host_index) {
338 temp_eqe = q->qe[q->host_index].eqe;
339 bf_set_le32(lpfc_eqe_valid, temp_eqe, 0);
341 q->host_index = ((q->host_index + 1) % q->entry_count);
343 if (unlikely(released == 0 && !arm))
346 /* ring doorbell for number popped */
349 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
350 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
352 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
353 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
354 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
355 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
356 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
357 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
358 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
359 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
360 readl(q->phba->sli4_hba.EQCQDBregaddr);
365 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
366 * @q: The Completion Queue to get the first valid CQE from
368 * This routine will get the first valid Completion Queue Entry from @q, update
369 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
370 * the Queue (no more work to do), or the Queue is full of CQEs that have been
371 * processed, but not popped back to the HBA then this routine will return NULL.
373 static struct lpfc_cqe *
374 lpfc_sli4_cq_get(struct lpfc_queue *q)
376 struct lpfc_cqe *cqe;
379 /* sanity check on queue memory */
383 /* If the next CQE is not valid then we are done */
384 if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe))
386 /* If the host has not yet processed the next entry then we are done */
387 idx = ((q->hba_index + 1) % q->entry_count);
388 if (idx == q->host_index)
391 cqe = q->qe[q->hba_index].cqe;
395 * insert barrier for instruction interlock : data from the hardware
396 * must have the valid bit checked before it can be copied and acted
397 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
398 * instructions allowing action on content before valid bit checked,
399 * add barrier here as well. May not be needed as "content" is a
400 * single 32-bit entity here (vs multi word structure for cq's).
407 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
408 * @q: The Completion Queue that the host has completed processing for.
409 * @arm: Indicates whether the host wants to arms this CQ.
411 * This routine will mark all Completion queue entries on @q, from the last
412 * known completed entry to the last entry that was processed, as completed
413 * by clearing the valid bit for each completion queue entry. Then it will
414 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
415 * The internal host index in the @q will be updated by this routine to indicate
416 * that the host has finished processing the entries. The @arm parameter
417 * indicates that the queue should be rearmed when ringing the doorbell.
419 * This function will return the number of CQEs that were released.
422 lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm)
424 uint32_t released = 0;
425 struct lpfc_cqe *temp_qe;
426 struct lpfc_register doorbell;
428 /* sanity check on queue memory */
431 /* while there are valid entries */
432 while (q->hba_index != q->host_index) {
433 temp_qe = q->qe[q->host_index].cqe;
434 bf_set_le32(lpfc_cqe_valid, temp_qe, 0);
436 q->host_index = ((q->host_index + 1) % q->entry_count);
438 if (unlikely(released == 0 && !arm))
441 /* ring doorbell for number popped */
444 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
445 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released);
446 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
447 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
448 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
449 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
450 writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr);
455 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
456 * @q: The Header Receive Queue to operate on.
457 * @wqe: The Receive Queue Entry to put on the Receive queue.
459 * This routine will copy the contents of @wqe to the next available entry on
460 * the @q. This function will then ring the Receive Queue Doorbell to signal the
461 * HBA to start processing the Receive Queue Entry. This function returns the
462 * index that the rqe was copied to if successful. If no entries are available
463 * on @q then this function will return -ENOMEM.
464 * The caller is expected to hold the hbalock when calling this routine.
467 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
468 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
470 struct lpfc_rqe *temp_hrqe;
471 struct lpfc_rqe *temp_drqe;
472 struct lpfc_register doorbell;
475 /* sanity check on queue memory */
476 if (unlikely(!hq) || unlikely(!dq))
478 put_index = hq->host_index;
479 temp_hrqe = hq->qe[hq->host_index].rqe;
480 temp_drqe = dq->qe[dq->host_index].rqe;
482 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
484 if (hq->host_index != dq->host_index)
486 /* If the host has not yet processed the next entry then we are done */
487 if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index)
489 lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
490 lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
492 /* Update the host index to point to the next slot */
493 hq->host_index = ((hq->host_index + 1) % hq->entry_count);
494 dq->host_index = ((dq->host_index + 1) % dq->entry_count);
496 /* Ring The Header Receive Queue Doorbell */
497 if (!(hq->host_index % hq->entry_repost)) {
499 if (hq->db_format == LPFC_DB_RING_FORMAT) {
500 bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
502 bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
503 } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
504 bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
506 bf_set(lpfc_rq_db_list_fm_index, &doorbell,
508 bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
512 writel(doorbell.word0, hq->db_regaddr);
518 * lpfc_sli4_rq_release - Updates internal hba index for RQ
519 * @q: The Header Receive Queue to operate on.
521 * This routine will update the HBA index of a queue to reflect consumption of
522 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
523 * consumed an entry the host calls this function to update the queue's
524 * internal pointers. This routine returns the number of entries that were
525 * consumed by the HBA.
528 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
530 /* sanity check on queue memory */
531 if (unlikely(!hq) || unlikely(!dq))
534 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
536 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
537 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
542 * lpfc_cmd_iocb - Get next command iocb entry in the ring
543 * @phba: Pointer to HBA context object.
544 * @pring: Pointer to driver SLI ring object.
546 * This function returns pointer to next command iocb entry
547 * in the command ring. The caller must hold hbalock to prevent
548 * other threads consume the next command iocb.
549 * SLI-2/SLI-3 provide different sized iocbs.
551 static inline IOCB_t *
552 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
554 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
555 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
559 * lpfc_resp_iocb - Get next response iocb entry in the ring
560 * @phba: Pointer to HBA context object.
561 * @pring: Pointer to driver SLI ring object.
563 * This function returns pointer to next response iocb entry
564 * in the response ring. The caller must hold hbalock to make sure
565 * that no other thread consume the next response iocb.
566 * SLI-2/SLI-3 provide different sized iocbs.
568 static inline IOCB_t *
569 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
571 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
572 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
576 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
577 * @phba: Pointer to HBA context object.
579 * This function is called with hbalock held. This function
580 * allocates a new driver iocb object from the iocb pool. If the
581 * allocation is successful, it returns pointer to the newly
582 * allocated iocb object else it returns NULL.
585 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
587 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
588 struct lpfc_iocbq * iocbq = NULL;
590 lockdep_assert_held(&phba->hbalock);
592 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
595 if (phba->iocb_cnt > phba->iocb_max)
596 phba->iocb_max = phba->iocb_cnt;
601 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
602 * @phba: Pointer to HBA context object.
603 * @xritag: XRI value.
605 * This function clears the sglq pointer from the array of acive
606 * sglq's. The xritag that is passed in is used to index into the
607 * array. Before the xritag can be used it needs to be adjusted
608 * by subtracting the xribase.
610 * Returns sglq ponter = success, NULL = Failure.
613 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
615 struct lpfc_sglq *sglq;
617 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
618 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
623 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
624 * @phba: Pointer to HBA context object.
625 * @xritag: XRI value.
627 * This function returns the sglq pointer from the array of acive
628 * sglq's. The xritag that is passed in is used to index into the
629 * array. Before the xritag can be used it needs to be adjusted
630 * by subtracting the xribase.
632 * Returns sglq ponter = success, NULL = Failure.
635 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
637 struct lpfc_sglq *sglq;
639 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
644 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
645 * @phba: Pointer to HBA context object.
646 * @xritag: xri used in this exchange.
647 * @rrq: The RRQ to be cleared.
651 lpfc_clr_rrq_active(struct lpfc_hba *phba,
653 struct lpfc_node_rrq *rrq)
655 struct lpfc_nodelist *ndlp = NULL;
657 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
658 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
660 /* The target DID could have been swapped (cable swap)
661 * we should use the ndlp from the findnode if it is
664 if ((!ndlp) && rrq->ndlp)
670 if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
673 rrq->rrq_stop_time = 0;
676 mempool_free(rrq, phba->rrq_pool);
680 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
681 * @phba: Pointer to HBA context object.
683 * This function is called with hbalock held. This function
684 * Checks if stop_time (ratov from setting rrq active) has
685 * been reached, if it has and the send_rrq flag is set then
686 * it will call lpfc_send_rrq. If the send_rrq flag is not set
687 * then it will just call the routine to clear the rrq and
688 * free the rrq resource.
689 * The timer is set to the next rrq that is going to expire before
690 * leaving the routine.
694 lpfc_handle_rrq_active(struct lpfc_hba *phba)
696 struct lpfc_node_rrq *rrq;
697 struct lpfc_node_rrq *nextrrq;
698 unsigned long next_time;
699 unsigned long iflags;
702 spin_lock_irqsave(&phba->hbalock, iflags);
703 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
704 next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
705 list_for_each_entry_safe(rrq, nextrrq,
706 &phba->active_rrq_list, list) {
707 if (time_after(jiffies, rrq->rrq_stop_time))
708 list_move(&rrq->list, &send_rrq);
709 else if (time_before(rrq->rrq_stop_time, next_time))
710 next_time = rrq->rrq_stop_time;
712 spin_unlock_irqrestore(&phba->hbalock, iflags);
713 if ((!list_empty(&phba->active_rrq_list)) &&
714 (!(phba->pport->load_flag & FC_UNLOADING)))
715 mod_timer(&phba->rrq_tmr, next_time);
716 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
717 list_del(&rrq->list);
719 /* this call will free the rrq */
720 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
721 else if (lpfc_send_rrq(phba, rrq)) {
722 /* if we send the rrq then the completion handler
723 * will clear the bit in the xribitmap.
725 lpfc_clr_rrq_active(phba, rrq->xritag,
732 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
733 * @vport: Pointer to vport context object.
734 * @xri: The xri used in the exchange.
735 * @did: The targets DID for this exchange.
737 * returns NULL = rrq not found in the phba->active_rrq_list.
738 * rrq = rrq for this xri and target.
740 struct lpfc_node_rrq *
741 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
743 struct lpfc_hba *phba = vport->phba;
744 struct lpfc_node_rrq *rrq;
745 struct lpfc_node_rrq *nextrrq;
746 unsigned long iflags;
748 if (phba->sli_rev != LPFC_SLI_REV4)
750 spin_lock_irqsave(&phba->hbalock, iflags);
751 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
752 if (rrq->vport == vport && rrq->xritag == xri &&
753 rrq->nlp_DID == did){
754 list_del(&rrq->list);
755 spin_unlock_irqrestore(&phba->hbalock, iflags);
759 spin_unlock_irqrestore(&phba->hbalock, iflags);
764 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
765 * @vport: Pointer to vport context object.
766 * @ndlp: Pointer to the lpfc_node_list structure.
767 * If ndlp is NULL Remove all active RRQs for this vport from the
768 * phba->active_rrq_list and clear the rrq.
769 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
772 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
775 struct lpfc_hba *phba = vport->phba;
776 struct lpfc_node_rrq *rrq;
777 struct lpfc_node_rrq *nextrrq;
778 unsigned long iflags;
781 if (phba->sli_rev != LPFC_SLI_REV4)
784 lpfc_sli4_vport_delete_els_xri_aborted(vport);
785 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
787 spin_lock_irqsave(&phba->hbalock, iflags);
788 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
789 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
790 list_move(&rrq->list, &rrq_list);
791 spin_unlock_irqrestore(&phba->hbalock, iflags);
793 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
794 list_del(&rrq->list);
795 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
800 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
801 * @phba: Pointer to HBA context object.
802 * @ndlp: Targets nodelist pointer for this exchange.
803 * @xritag the xri in the bitmap to test.
805 * This function is called with hbalock held. This function
806 * returns 0 = rrq not active for this xri
807 * 1 = rrq is valid for this xri.
810 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
813 lockdep_assert_held(&phba->hbalock);
816 if (!ndlp->active_rrqs_xri_bitmap)
818 if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
825 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
826 * @phba: Pointer to HBA context object.
827 * @ndlp: nodelist pointer for this target.
828 * @xritag: xri used in this exchange.
829 * @rxid: Remote Exchange ID.
830 * @send_rrq: Flag used to determine if we should send rrq els cmd.
832 * This function takes the hbalock.
833 * The active bit is always set in the active rrq xri_bitmap even
834 * if there is no slot avaiable for the other rrq information.
836 * returns 0 rrq actived for this xri
837 * < 0 No memory or invalid ndlp.
840 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
841 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
843 unsigned long iflags;
844 struct lpfc_node_rrq *rrq;
850 if (!phba->cfg_enable_rrq)
853 spin_lock_irqsave(&phba->hbalock, iflags);
854 if (phba->pport->load_flag & FC_UNLOADING) {
855 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
860 * set the active bit even if there is no mem available.
862 if (NLP_CHK_FREE_REQ(ndlp))
865 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
868 if (!ndlp->active_rrqs_xri_bitmap)
871 if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
874 spin_unlock_irqrestore(&phba->hbalock, iflags);
875 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
877 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
878 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
879 " DID:0x%x Send:%d\n",
880 xritag, rxid, ndlp->nlp_DID, send_rrq);
883 if (phba->cfg_enable_rrq == 1)
884 rrq->send_rrq = send_rrq;
887 rrq->xritag = xritag;
888 rrq->rrq_stop_time = jiffies +
889 msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
891 rrq->nlp_DID = ndlp->nlp_DID;
892 rrq->vport = ndlp->vport;
894 spin_lock_irqsave(&phba->hbalock, iflags);
895 empty = list_empty(&phba->active_rrq_list);
896 list_add_tail(&rrq->list, &phba->active_rrq_list);
897 phba->hba_flag |= HBA_RRQ_ACTIVE;
899 lpfc_worker_wake_up(phba);
900 spin_unlock_irqrestore(&phba->hbalock, iflags);
903 spin_unlock_irqrestore(&phba->hbalock, iflags);
904 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
905 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
906 " DID:0x%x Send:%d\n",
907 xritag, rxid, ndlp->nlp_DID, send_rrq);
912 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
913 * @phba: Pointer to HBA context object.
914 * @piocb: Pointer to the iocbq.
916 * This function is called with the ring lock held. This function
917 * gets a new driver sglq object from the sglq list. If the
918 * list is not empty then it is successful, it returns pointer to the newly
919 * allocated sglq object else it returns NULL.
921 static struct lpfc_sglq *
922 __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
924 struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
925 struct lpfc_sglq *sglq = NULL;
926 struct lpfc_sglq *start_sglq = NULL;
927 struct lpfc_scsi_buf *lpfc_cmd;
928 struct lpfc_nodelist *ndlp;
931 lockdep_assert_held(&phba->hbalock);
933 if (piocbq->iocb_flag & LPFC_IO_FCP) {
934 lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1;
935 ndlp = lpfc_cmd->rdata->pnode;
936 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
937 !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
938 ndlp = piocbq->context_un.ndlp;
939 } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
940 if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
943 ndlp = piocbq->context_un.ndlp;
945 ndlp = piocbq->context1;
948 spin_lock(&phba->sli4_hba.sgl_list_lock);
949 list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
954 if (ndlp && ndlp->active_rrqs_xri_bitmap &&
955 test_bit(sglq->sli4_lxritag,
956 ndlp->active_rrqs_xri_bitmap)) {
957 /* This xri has an rrq outstanding for this DID.
958 * put it back in the list and get another xri.
960 list_add_tail(&sglq->list, lpfc_els_sgl_list);
962 list_remove_head(lpfc_els_sgl_list, sglq,
963 struct lpfc_sglq, list);
964 if (sglq == start_sglq) {
972 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
973 sglq->state = SGL_ALLOCATED;
975 spin_unlock(&phba->sli4_hba.sgl_list_lock);
980 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
981 * @phba: Pointer to HBA context object.
982 * @piocb: Pointer to the iocbq.
984 * This function is called with the sgl_list lock held. This function
985 * gets a new driver sglq object from the sglq list. If the
986 * list is not empty then it is successful, it returns pointer to the newly
987 * allocated sglq object else it returns NULL.
990 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
992 struct list_head *lpfc_nvmet_sgl_list;
993 struct lpfc_sglq *sglq = NULL;
995 lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
997 lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
999 list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
1002 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1003 sglq->state = SGL_ALLOCATED;
1008 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1009 * @phba: Pointer to HBA context object.
1011 * This function is called with no lock held. This function
1012 * allocates a new driver iocb object from the iocb pool. If the
1013 * allocation is successful, it returns pointer to the newly
1014 * allocated iocb object else it returns NULL.
1017 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
1019 struct lpfc_iocbq * iocbq = NULL;
1020 unsigned long iflags;
1022 spin_lock_irqsave(&phba->hbalock, iflags);
1023 iocbq = __lpfc_sli_get_iocbq(phba);
1024 spin_unlock_irqrestore(&phba->hbalock, iflags);
1029 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1030 * @phba: Pointer to HBA context object.
1031 * @iocbq: Pointer to driver iocb object.
1033 * This function is called with hbalock held to release driver
1034 * iocb object to the iocb pool. The iotag in the iocb object
1035 * does not change for each use of the iocb object. This function
1036 * clears all other fields of the iocb object when it is freed.
1037 * The sqlq structure that holds the xritag and phys and virtual
1038 * mappings for the scatter gather list is retrieved from the
1039 * active array of sglq. The get of the sglq pointer also clears
1040 * the entry in the array. If the status of the IO indiactes that
1041 * this IO was aborted then the sglq entry it put on the
1042 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1043 * IO has good status or fails for any other reason then the sglq
1044 * entry is added to the free list (lpfc_els_sgl_list).
1047 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1049 struct lpfc_sglq *sglq;
1050 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1051 unsigned long iflag = 0;
1052 struct lpfc_sli_ring *pring;
1054 lockdep_assert_held(&phba->hbalock);
1056 if (iocbq->sli4_xritag == NO_XRI)
1059 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
1063 if (iocbq->iocb_flag & LPFC_IO_NVMET) {
1064 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1066 sglq->state = SGL_FREED;
1068 list_add_tail(&sglq->list,
1069 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1070 spin_unlock_irqrestore(
1071 &phba->sli4_hba.sgl_list_lock, iflag);
1075 pring = phba->sli4_hba.els_wq->pring;
1076 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
1077 (sglq->state != SGL_XRI_ABORTED)) {
1078 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1080 list_add(&sglq->list,
1081 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1082 spin_unlock_irqrestore(
1083 &phba->sli4_hba.sgl_list_lock, iflag);
1085 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1087 sglq->state = SGL_FREED;
1089 list_add_tail(&sglq->list,
1090 &phba->sli4_hba.lpfc_els_sgl_list);
1091 spin_unlock_irqrestore(
1092 &phba->sli4_hba.sgl_list_lock, iflag);
1094 /* Check if TXQ queue needs to be serviced */
1095 if (!list_empty(&pring->txq))
1096 lpfc_worker_wake_up(phba);
1102 * Clean all volatile data fields, preserve iotag and node struct.
1104 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1105 iocbq->sli4_lxritag = NO_XRI;
1106 iocbq->sli4_xritag = NO_XRI;
1107 iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET |
1109 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1114 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1115 * @phba: Pointer to HBA context object.
1116 * @iocbq: Pointer to driver iocb object.
1118 * This function is called with hbalock held to release driver
1119 * iocb object to the iocb pool. The iotag in the iocb object
1120 * does not change for each use of the iocb object. This function
1121 * clears all other fields of the iocb object when it is freed.
1124 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1126 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1128 lockdep_assert_held(&phba->hbalock);
1131 * Clean all volatile data fields, preserve iotag and node struct.
1133 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1134 iocbq->sli4_xritag = NO_XRI;
1135 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1139 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1140 * @phba: Pointer to HBA context object.
1141 * @iocbq: Pointer to driver iocb object.
1143 * This function is called with hbalock held to release driver
1144 * iocb object to the iocb pool. The iotag in the iocb object
1145 * does not change for each use of the iocb object. This function
1146 * clears all other fields of the iocb object when it is freed.
1149 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1151 lockdep_assert_held(&phba->hbalock);
1153 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1158 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1159 * @phba: Pointer to HBA context object.
1160 * @iocbq: Pointer to driver iocb object.
1162 * This function is called with no lock held to release the iocb to
1166 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1168 unsigned long iflags;
1171 * Clean all volatile data fields, preserve iotag and node struct.
1173 spin_lock_irqsave(&phba->hbalock, iflags);
1174 __lpfc_sli_release_iocbq(phba, iocbq);
1175 spin_unlock_irqrestore(&phba->hbalock, iflags);
1179 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1180 * @phba: Pointer to HBA context object.
1181 * @iocblist: List of IOCBs.
1182 * @ulpstatus: ULP status in IOCB command field.
1183 * @ulpWord4: ULP word-4 in IOCB command field.
1185 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1186 * on the list by invoking the complete callback function associated with the
1187 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1191 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1192 uint32_t ulpstatus, uint32_t ulpWord4)
1194 struct lpfc_iocbq *piocb;
1196 while (!list_empty(iocblist)) {
1197 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1198 if (!piocb->iocb_cmpl)
1199 lpfc_sli_release_iocbq(phba, piocb);
1201 piocb->iocb.ulpStatus = ulpstatus;
1202 piocb->iocb.un.ulpWord[4] = ulpWord4;
1203 (piocb->iocb_cmpl) (phba, piocb, piocb);
1210 * lpfc_sli_iocb_cmd_type - Get the iocb type
1211 * @iocb_cmnd: iocb command code.
1213 * This function is called by ring event handler function to get the iocb type.
1214 * This function translates the iocb command to an iocb command type used to
1215 * decide the final disposition of each completed IOCB.
1216 * The function returns
1217 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1218 * LPFC_SOL_IOCB if it is a solicited iocb completion
1219 * LPFC_ABORT_IOCB if it is an abort iocb
1220 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1222 * The caller is not required to hold any lock.
1224 static lpfc_iocb_type
1225 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1227 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1229 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1232 switch (iocb_cmnd) {
1233 case CMD_XMIT_SEQUENCE_CR:
1234 case CMD_XMIT_SEQUENCE_CX:
1235 case CMD_XMIT_BCAST_CN:
1236 case CMD_XMIT_BCAST_CX:
1237 case CMD_ELS_REQUEST_CR:
1238 case CMD_ELS_REQUEST_CX:
1239 case CMD_CREATE_XRI_CR:
1240 case CMD_CREATE_XRI_CX:
1241 case CMD_GET_RPI_CN:
1242 case CMD_XMIT_ELS_RSP_CX:
1243 case CMD_GET_RPI_CR:
1244 case CMD_FCP_IWRITE_CR:
1245 case CMD_FCP_IWRITE_CX:
1246 case CMD_FCP_IREAD_CR:
1247 case CMD_FCP_IREAD_CX:
1248 case CMD_FCP_ICMND_CR:
1249 case CMD_FCP_ICMND_CX:
1250 case CMD_FCP_TSEND_CX:
1251 case CMD_FCP_TRSP_CX:
1252 case CMD_FCP_TRECEIVE_CX:
1253 case CMD_FCP_AUTO_TRSP_CX:
1254 case CMD_ADAPTER_MSG:
1255 case CMD_ADAPTER_DUMP:
1256 case CMD_XMIT_SEQUENCE64_CR:
1257 case CMD_XMIT_SEQUENCE64_CX:
1258 case CMD_XMIT_BCAST64_CN:
1259 case CMD_XMIT_BCAST64_CX:
1260 case CMD_ELS_REQUEST64_CR:
1261 case CMD_ELS_REQUEST64_CX:
1262 case CMD_FCP_IWRITE64_CR:
1263 case CMD_FCP_IWRITE64_CX:
1264 case CMD_FCP_IREAD64_CR:
1265 case CMD_FCP_IREAD64_CX:
1266 case CMD_FCP_ICMND64_CR:
1267 case CMD_FCP_ICMND64_CX:
1268 case CMD_FCP_TSEND64_CX:
1269 case CMD_FCP_TRSP64_CX:
1270 case CMD_FCP_TRECEIVE64_CX:
1271 case CMD_GEN_REQUEST64_CR:
1272 case CMD_GEN_REQUEST64_CX:
1273 case CMD_XMIT_ELS_RSP64_CX:
1274 case DSSCMD_IWRITE64_CR:
1275 case DSSCMD_IWRITE64_CX:
1276 case DSSCMD_IREAD64_CR:
1277 case DSSCMD_IREAD64_CX:
1278 type = LPFC_SOL_IOCB;
1280 case CMD_ABORT_XRI_CN:
1281 case CMD_ABORT_XRI_CX:
1282 case CMD_CLOSE_XRI_CN:
1283 case CMD_CLOSE_XRI_CX:
1284 case CMD_XRI_ABORTED_CX:
1285 case CMD_ABORT_MXRI64_CN:
1286 case CMD_XMIT_BLS_RSP64_CX:
1287 type = LPFC_ABORT_IOCB;
1289 case CMD_RCV_SEQUENCE_CX:
1290 case CMD_RCV_ELS_REQ_CX:
1291 case CMD_RCV_SEQUENCE64_CX:
1292 case CMD_RCV_ELS_REQ64_CX:
1293 case CMD_ASYNC_STATUS:
1294 case CMD_IOCB_RCV_SEQ64_CX:
1295 case CMD_IOCB_RCV_ELS64_CX:
1296 case CMD_IOCB_RCV_CONT64_CX:
1297 case CMD_IOCB_RET_XRI64_CX:
1298 type = LPFC_UNSOL_IOCB;
1300 case CMD_IOCB_XMIT_MSEQ64_CR:
1301 case CMD_IOCB_XMIT_MSEQ64_CX:
1302 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1303 case CMD_IOCB_RCV_ELS_LIST64_CX:
1304 case CMD_IOCB_CLOSE_EXTENDED_CN:
1305 case CMD_IOCB_ABORT_EXTENDED_CN:
1306 case CMD_IOCB_RET_HBQE64_CN:
1307 case CMD_IOCB_FCP_IBIDIR64_CR:
1308 case CMD_IOCB_FCP_IBIDIR64_CX:
1309 case CMD_IOCB_FCP_ITASKMGT64_CX:
1310 case CMD_IOCB_LOGENTRY_CN:
1311 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1312 printk("%s - Unhandled SLI-3 Command x%x\n",
1313 __func__, iocb_cmnd);
1314 type = LPFC_UNKNOWN_IOCB;
1317 type = LPFC_UNKNOWN_IOCB;
1325 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1326 * @phba: Pointer to HBA context object.
1328 * This function is called from SLI initialization code
1329 * to configure every ring of the HBA's SLI interface. The
1330 * caller is not required to hold any lock. This function issues
1331 * a config_ring mailbox command for each ring.
1332 * This function returns zero if successful else returns a negative
1336 lpfc_sli_ring_map(struct lpfc_hba *phba)
1338 struct lpfc_sli *psli = &phba->sli;
1343 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1347 phba->link_state = LPFC_INIT_MBX_CMDS;
1348 for (i = 0; i < psli->num_rings; i++) {
1349 lpfc_config_ring(phba, i, pmb);
1350 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1351 if (rc != MBX_SUCCESS) {
1352 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1353 "0446 Adapter failed to init (%d), "
1354 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1356 rc, pmbox->mbxCommand,
1357 pmbox->mbxStatus, i);
1358 phba->link_state = LPFC_HBA_ERROR;
1363 mempool_free(pmb, phba->mbox_mem_pool);
1368 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1369 * @phba: Pointer to HBA context object.
1370 * @pring: Pointer to driver SLI ring object.
1371 * @piocb: Pointer to the driver iocb object.
1373 * This function is called with hbalock held. The function adds the
1374 * new iocb to txcmplq of the given ring. This function always returns
1375 * 0. If this function is called for ELS ring, this function checks if
1376 * there is a vport associated with the ELS command. This function also
1377 * starts els_tmofunc timer if this is an ELS command.
1380 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1381 struct lpfc_iocbq *piocb)
1383 lockdep_assert_held(&phba->hbalock);
1387 list_add_tail(&piocb->list, &pring->txcmplq);
1388 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1390 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1391 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1392 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1393 BUG_ON(!piocb->vport);
1394 if (!(piocb->vport->load_flag & FC_UNLOADING))
1395 mod_timer(&piocb->vport->els_tmofunc,
1397 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1404 * lpfc_sli_ringtx_get - Get first element of the txq
1405 * @phba: Pointer to HBA context object.
1406 * @pring: Pointer to driver SLI ring object.
1408 * This function is called with hbalock held to get next
1409 * iocb in txq of the given ring. If there is any iocb in
1410 * the txq, the function returns first iocb in the list after
1411 * removing the iocb from the list, else it returns NULL.
1414 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1416 struct lpfc_iocbq *cmd_iocb;
1418 lockdep_assert_held(&phba->hbalock);
1420 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1425 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1426 * @phba: Pointer to HBA context object.
1427 * @pring: Pointer to driver SLI ring object.
1429 * This function is called with hbalock held and the caller must post the
1430 * iocb without releasing the lock. If the caller releases the lock,
1431 * iocb slot returned by the function is not guaranteed to be available.
1432 * The function returns pointer to the next available iocb slot if there
1433 * is available slot in the ring, else it returns NULL.
1434 * If the get index of the ring is ahead of the put index, the function
1435 * will post an error attention event to the worker thread to take the
1436 * HBA to offline state.
1439 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1441 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1442 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
1444 lockdep_assert_held(&phba->hbalock);
1446 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
1447 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
1448 pring->sli.sli3.next_cmdidx = 0;
1450 if (unlikely(pring->sli.sli3.local_getidx ==
1451 pring->sli.sli3.next_cmdidx)) {
1453 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
1455 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
1456 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1457 "0315 Ring %d issue: portCmdGet %d "
1458 "is bigger than cmd ring %d\n",
1460 pring->sli.sli3.local_getidx,
1463 phba->link_state = LPFC_HBA_ERROR;
1465 * All error attention handlers are posted to
1468 phba->work_ha |= HA_ERATT;
1469 phba->work_hs = HS_FFER3;
1471 lpfc_worker_wake_up(phba);
1476 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
1480 return lpfc_cmd_iocb(phba, pring);
1484 * lpfc_sli_next_iotag - Get an iotag for the iocb
1485 * @phba: Pointer to HBA context object.
1486 * @iocbq: Pointer to driver iocb object.
1488 * This function gets an iotag for the iocb. If there is no unused iotag and
1489 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1490 * array and assigns a new iotag.
1491 * The function returns the allocated iotag if successful, else returns zero.
1492 * Zero is not a valid iotag.
1493 * The caller is not required to hold any lock.
1496 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1498 struct lpfc_iocbq **new_arr;
1499 struct lpfc_iocbq **old_arr;
1501 struct lpfc_sli *psli = &phba->sli;
1504 spin_lock_irq(&phba->hbalock);
1505 iotag = psli->last_iotag;
1506 if(++iotag < psli->iocbq_lookup_len) {
1507 psli->last_iotag = iotag;
1508 psli->iocbq_lookup[iotag] = iocbq;
1509 spin_unlock_irq(&phba->hbalock);
1510 iocbq->iotag = iotag;
1512 } else if (psli->iocbq_lookup_len < (0xffff
1513 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1514 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1515 spin_unlock_irq(&phba->hbalock);
1516 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
1519 spin_lock_irq(&phba->hbalock);
1520 old_arr = psli->iocbq_lookup;
1521 if (new_len <= psli->iocbq_lookup_len) {
1522 /* highly unprobable case */
1524 iotag = psli->last_iotag;
1525 if(++iotag < psli->iocbq_lookup_len) {
1526 psli->last_iotag = iotag;
1527 psli->iocbq_lookup[iotag] = iocbq;
1528 spin_unlock_irq(&phba->hbalock);
1529 iocbq->iotag = iotag;
1532 spin_unlock_irq(&phba->hbalock);
1535 if (psli->iocbq_lookup)
1536 memcpy(new_arr, old_arr,
1537 ((psli->last_iotag + 1) *
1538 sizeof (struct lpfc_iocbq *)));
1539 psli->iocbq_lookup = new_arr;
1540 psli->iocbq_lookup_len = new_len;
1541 psli->last_iotag = iotag;
1542 psli->iocbq_lookup[iotag] = iocbq;
1543 spin_unlock_irq(&phba->hbalock);
1544 iocbq->iotag = iotag;
1549 spin_unlock_irq(&phba->hbalock);
1551 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1552 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1559 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1560 * @phba: Pointer to HBA context object.
1561 * @pring: Pointer to driver SLI ring object.
1562 * @iocb: Pointer to iocb slot in the ring.
1563 * @nextiocb: Pointer to driver iocb object which need to be
1564 * posted to firmware.
1566 * This function is called with hbalock held to post a new iocb to
1567 * the firmware. This function copies the new iocb to ring iocb slot and
1568 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1569 * a completion call back for this iocb else the function will free the
1573 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1574 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1576 lockdep_assert_held(&phba->hbalock);
1580 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1583 if (pring->ringno == LPFC_ELS_RING) {
1584 lpfc_debugfs_slow_ring_trc(phba,
1585 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1586 *(((uint32_t *) &nextiocb->iocb) + 4),
1587 *(((uint32_t *) &nextiocb->iocb) + 6),
1588 *(((uint32_t *) &nextiocb->iocb) + 7));
1592 * Issue iocb command to adapter
1594 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1596 pring->stats.iocb_cmd++;
1599 * If there is no completion routine to call, we can release the
1600 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1601 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1603 if (nextiocb->iocb_cmpl)
1604 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1606 __lpfc_sli_release_iocbq(phba, nextiocb);
1609 * Let the HBA know what IOCB slot will be the next one the
1610 * driver will put a command into.
1612 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
1613 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1617 * lpfc_sli_update_full_ring - Update the chip attention register
1618 * @phba: Pointer to HBA context object.
1619 * @pring: Pointer to driver SLI ring object.
1621 * The caller is not required to hold any lock for calling this function.
1622 * This function updates the chip attention bits for the ring to inform firmware
1623 * that there are pending work to be done for this ring and requests an
1624 * interrupt when there is space available in the ring. This function is
1625 * called when the driver is unable to post more iocbs to the ring due
1626 * to unavailability of space in the ring.
1629 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1631 int ringno = pring->ringno;
1633 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1638 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1639 * The HBA will tell us when an IOCB entry is available.
1641 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1642 readl(phba->CAregaddr); /* flush */
1644 pring->stats.iocb_cmd_full++;
1648 * lpfc_sli_update_ring - Update chip attention register
1649 * @phba: Pointer to HBA context object.
1650 * @pring: Pointer to driver SLI ring object.
1652 * This function updates the chip attention register bit for the
1653 * given ring to inform HBA that there is more work to be done
1654 * in this ring. The caller is not required to hold any lock.
1657 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1659 int ringno = pring->ringno;
1662 * Tell the HBA that there is work to do in this ring.
1664 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1666 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1667 readl(phba->CAregaddr); /* flush */
1672 * lpfc_sli_resume_iocb - Process iocbs in the txq
1673 * @phba: Pointer to HBA context object.
1674 * @pring: Pointer to driver SLI ring object.
1676 * This function is called with hbalock held to post pending iocbs
1677 * in the txq to the firmware. This function is called when driver
1678 * detects space available in the ring.
1681 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1684 struct lpfc_iocbq *nextiocb;
1686 lockdep_assert_held(&phba->hbalock);
1690 * (a) there is anything on the txq to send
1692 * (c) link attention events can be processed (fcp ring only)
1693 * (d) IOCB processing is not blocked by the outstanding mbox command.
1696 if (lpfc_is_link_up(phba) &&
1697 (!list_empty(&pring->txq)) &&
1698 (pring->ringno != LPFC_FCP_RING ||
1699 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1701 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1702 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1703 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1706 lpfc_sli_update_ring(phba, pring);
1708 lpfc_sli_update_full_ring(phba, pring);
1715 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1716 * @phba: Pointer to HBA context object.
1717 * @hbqno: HBQ number.
1719 * This function is called with hbalock held to get the next
1720 * available slot for the given HBQ. If there is free slot
1721 * available for the HBQ it will return pointer to the next available
1722 * HBQ entry else it will return NULL.
1724 static struct lpfc_hbq_entry *
1725 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1727 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1729 lockdep_assert_held(&phba->hbalock);
1731 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1732 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1733 hbqp->next_hbqPutIdx = 0;
1735 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1736 uint32_t raw_index = phba->hbq_get[hbqno];
1737 uint32_t getidx = le32_to_cpu(raw_index);
1739 hbqp->local_hbqGetIdx = getidx;
1741 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1742 lpfc_printf_log(phba, KERN_ERR,
1743 LOG_SLI | LOG_VPORT,
1744 "1802 HBQ %d: local_hbqGetIdx "
1745 "%u is > than hbqp->entry_count %u\n",
1746 hbqno, hbqp->local_hbqGetIdx,
1749 phba->link_state = LPFC_HBA_ERROR;
1753 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1757 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1762 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1763 * @phba: Pointer to HBA context object.
1765 * This function is called with no lock held to free all the
1766 * hbq buffers while uninitializing the SLI interface. It also
1767 * frees the HBQ buffers returned by the firmware but not yet
1768 * processed by the upper layers.
1771 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1773 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1774 struct hbq_dmabuf *hbq_buf;
1775 unsigned long flags;
1778 hbq_count = lpfc_sli_hbq_count();
1779 /* Return all memory used by all HBQs */
1780 spin_lock_irqsave(&phba->hbalock, flags);
1781 for (i = 0; i < hbq_count; ++i) {
1782 list_for_each_entry_safe(dmabuf, next_dmabuf,
1783 &phba->hbqs[i].hbq_buffer_list, list) {
1784 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1785 list_del(&hbq_buf->dbuf.list);
1786 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1788 phba->hbqs[i].buffer_count = 0;
1791 /* Mark the HBQs not in use */
1792 phba->hbq_in_use = 0;
1793 spin_unlock_irqrestore(&phba->hbalock, flags);
1797 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1798 * @phba: Pointer to HBA context object.
1799 * @hbqno: HBQ number.
1800 * @hbq_buf: Pointer to HBQ buffer.
1802 * This function is called with the hbalock held to post a
1803 * hbq buffer to the firmware. If the function finds an empty
1804 * slot in the HBQ, it will post the buffer. The function will return
1805 * pointer to the hbq entry if it successfully post the buffer
1806 * else it will return NULL.
1809 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
1810 struct hbq_dmabuf *hbq_buf)
1812 lockdep_assert_held(&phba->hbalock);
1813 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
1817 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1818 * @phba: Pointer to HBA context object.
1819 * @hbqno: HBQ number.
1820 * @hbq_buf: Pointer to HBQ buffer.
1822 * This function is called with the hbalock held to post a hbq buffer to the
1823 * firmware. If the function finds an empty slot in the HBQ, it will post the
1824 * buffer and place it on the hbq_buffer_list. The function will return zero if
1825 * it successfully post the buffer else it will return an error.
1828 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
1829 struct hbq_dmabuf *hbq_buf)
1831 struct lpfc_hbq_entry *hbqe;
1832 dma_addr_t physaddr = hbq_buf->dbuf.phys;
1834 lockdep_assert_held(&phba->hbalock);
1835 /* Get next HBQ entry slot to use */
1836 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
1838 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1840 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
1841 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
1842 hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
1843 hbqe->bde.tus.f.bdeFlags = 0;
1844 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
1845 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
1847 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
1848 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
1850 readl(phba->hbq_put + hbqno);
1851 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
1858 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1859 * @phba: Pointer to HBA context object.
1860 * @hbqno: HBQ number.
1861 * @hbq_buf: Pointer to HBQ buffer.
1863 * This function is called with the hbalock held to post an RQE to the SLI4
1864 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1865 * the hbq_buffer_list and return zero, otherwise it will return an error.
1868 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
1869 struct hbq_dmabuf *hbq_buf)
1872 struct lpfc_rqe hrqe;
1873 struct lpfc_rqe drqe;
1874 struct lpfc_queue *hrq;
1875 struct lpfc_queue *drq;
1877 if (hbqno != LPFC_ELS_HBQ)
1879 hrq = phba->sli4_hba.hdr_rq;
1880 drq = phba->sli4_hba.dat_rq;
1882 lockdep_assert_held(&phba->hbalock);
1883 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
1884 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
1885 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
1886 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
1887 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
1890 hbq_buf->tag = (rc | (hbqno << 16));
1891 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
1895 /* HBQ for ELS and CT traffic. */
1896 static struct lpfc_hbq_init lpfc_els_hbq = {
1901 .ring_mask = (1 << LPFC_ELS_RING),
1908 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
1913 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1914 * @phba: Pointer to HBA context object.
1915 * @hbqno: HBQ number.
1916 * @count: Number of HBQ buffers to be posted.
1918 * This function is called with no lock held to post more hbq buffers to the
1919 * given HBQ. The function returns the number of HBQ buffers successfully
1923 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
1925 uint32_t i, posted = 0;
1926 unsigned long flags;
1927 struct hbq_dmabuf *hbq_buffer;
1928 LIST_HEAD(hbq_buf_list);
1929 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
1932 if ((phba->hbqs[hbqno].buffer_count + count) >
1933 lpfc_hbq_defs[hbqno]->entry_count)
1934 count = lpfc_hbq_defs[hbqno]->entry_count -
1935 phba->hbqs[hbqno].buffer_count;
1938 /* Allocate HBQ entries */
1939 for (i = 0; i < count; i++) {
1940 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1943 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
1945 /* Check whether HBQ is still in use */
1946 spin_lock_irqsave(&phba->hbalock, flags);
1947 if (!phba->hbq_in_use)
1949 while (!list_empty(&hbq_buf_list)) {
1950 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1952 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
1954 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
1955 phba->hbqs[hbqno].buffer_count++;
1958 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1960 spin_unlock_irqrestore(&phba->hbalock, flags);
1963 spin_unlock_irqrestore(&phba->hbalock, flags);
1964 while (!list_empty(&hbq_buf_list)) {
1965 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
1967 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
1973 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1974 * @phba: Pointer to HBA context object.
1977 * This function posts more buffers to the HBQ. This function
1978 * is called with no lock held. The function returns the number of HBQ entries
1979 * successfully allocated.
1982 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
1984 if (phba->sli_rev == LPFC_SLI_REV4)
1987 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
1988 lpfc_hbq_defs[qno]->add_count);
1992 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1993 * @phba: Pointer to HBA context object.
1994 * @qno: HBQ queue number.
1996 * This function is called from SLI initialization code path with
1997 * no lock held to post initial HBQ buffers to firmware. The
1998 * function returns the number of HBQ entries successfully allocated.
2001 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
2003 if (phba->sli_rev == LPFC_SLI_REV4)
2004 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2005 lpfc_hbq_defs[qno]->entry_count);
2007 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2008 lpfc_hbq_defs[qno]->init_count);
2012 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2013 * @phba: Pointer to HBA context object.
2014 * @hbqno: HBQ number.
2016 * This function removes the first hbq buffer on an hbq list and returns a
2017 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2019 static struct hbq_dmabuf *
2020 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
2022 struct lpfc_dmabuf *d_buf;
2024 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
2027 return container_of(d_buf, struct hbq_dmabuf, dbuf);
2031 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2032 * @phba: Pointer to HBA context object.
2033 * @tag: Tag of the hbq buffer.
2035 * This function searches for the hbq buffer associated with the given tag in
2036 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2037 * otherwise it returns NULL.
2039 static struct hbq_dmabuf *
2040 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
2042 struct lpfc_dmabuf *d_buf;
2043 struct hbq_dmabuf *hbq_buf;
2047 if (hbqno >= LPFC_MAX_HBQS)
2050 spin_lock_irq(&phba->hbalock);
2051 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
2052 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2053 if (hbq_buf->tag == tag) {
2054 spin_unlock_irq(&phba->hbalock);
2058 spin_unlock_irq(&phba->hbalock);
2059 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
2060 "1803 Bad hbq tag. Data: x%x x%x\n",
2061 tag, phba->hbqs[tag >> 16].buffer_count);
2066 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2067 * @phba: Pointer to HBA context object.
2068 * @hbq_buffer: Pointer to HBQ buffer.
2070 * This function is called with hbalock. This function gives back
2071 * the hbq buffer to firmware. If the HBQ does not have space to
2072 * post the buffer, it will free the buffer.
2075 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2080 hbqno = hbq_buffer->tag >> 16;
2081 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2082 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2087 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2088 * @mbxCommand: mailbox command code.
2090 * This function is called by the mailbox event handler function to verify
2091 * that the completed mailbox command is a legitimate mailbox command. If the
2092 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2093 * and the mailbox event handler will take the HBA offline.
2096 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2100 switch (mbxCommand) {
2104 case MBX_WRITE_VPARMS:
2105 case MBX_RUN_BIU_DIAG:
2108 case MBX_CONFIG_LINK:
2109 case MBX_CONFIG_RING:
2110 case MBX_RESET_RING:
2111 case MBX_READ_CONFIG:
2112 case MBX_READ_RCONFIG:
2113 case MBX_READ_SPARM:
2114 case MBX_READ_STATUS:
2118 case MBX_READ_LNK_STAT:
2120 case MBX_UNREG_LOGIN:
2122 case MBX_DUMP_MEMORY:
2123 case MBX_DUMP_CONTEXT:
2126 case MBX_UPDATE_CFG:
2128 case MBX_DEL_LD_ENTRY:
2129 case MBX_RUN_PROGRAM:
2131 case MBX_SET_VARIABLE:
2132 case MBX_UNREG_D_ID:
2133 case MBX_KILL_BOARD:
2134 case MBX_CONFIG_FARP:
2137 case MBX_RUN_BIU_DIAG64:
2138 case MBX_CONFIG_PORT:
2139 case MBX_READ_SPARM64:
2140 case MBX_READ_RPI64:
2141 case MBX_REG_LOGIN64:
2142 case MBX_READ_TOPOLOGY:
2145 case MBX_LOAD_EXP_ROM:
2146 case MBX_ASYNCEVT_ENABLE:
2150 case MBX_PORT_CAPABILITIES:
2151 case MBX_PORT_IOV_CONTROL:
2152 case MBX_SLI4_CONFIG:
2153 case MBX_SLI4_REQ_FTRS:
2155 case MBX_UNREG_FCFI:
2160 case MBX_RESUME_RPI:
2161 case MBX_READ_EVENT_LOG_STATUS:
2162 case MBX_READ_EVENT_LOG:
2163 case MBX_SECURITY_MGMT:
2165 case MBX_ACCESS_VDATA:
2176 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2177 * @phba: Pointer to HBA context object.
2178 * @pmboxq: Pointer to mailbox command.
2180 * This is completion handler function for mailbox commands issued from
2181 * lpfc_sli_issue_mbox_wait function. This function is called by the
2182 * mailbox event handler function with no lock held. This function
2183 * will wake up thread waiting on the wait queue pointed by context1
2187 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2189 wait_queue_head_t *pdone_q;
2190 unsigned long drvr_flag;
2193 * If pdone_q is empty, the driver thread gave up waiting and
2194 * continued running.
2196 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2197 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2198 pdone_q = (wait_queue_head_t *) pmboxq->context1;
2200 wake_up_interruptible(pdone_q);
2201 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2207 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2208 * @phba: Pointer to HBA context object.
2209 * @pmb: Pointer to mailbox object.
2211 * This function is the default mailbox completion handler. It
2212 * frees the memory resources associated with the completed mailbox
2213 * command. If the completed command is a REG_LOGIN mailbox command,
2214 * this function will issue a UREG_LOGIN to re-claim the RPI.
2217 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2219 struct lpfc_vport *vport = pmb->vport;
2220 struct lpfc_dmabuf *mp;
2221 struct lpfc_nodelist *ndlp;
2222 struct Scsi_Host *shost;
2226 mp = (struct lpfc_dmabuf *) (pmb->context1);
2229 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2234 * If a REG_LOGIN succeeded after node is destroyed or node
2235 * is in re-discovery driver need to cleanup the RPI.
2237 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2238 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2239 !pmb->u.mb.mbxStatus) {
2240 rpi = pmb->u.mb.un.varWords[0];
2241 vpi = pmb->u.mb.un.varRegLogin.vpi;
2242 lpfc_unreg_login(phba, vpi, rpi, pmb);
2244 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2245 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2246 if (rc != MBX_NOT_FINISHED)
2250 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2251 !(phba->pport->load_flag & FC_UNLOADING) &&
2252 !pmb->u.mb.mbxStatus) {
2253 shost = lpfc_shost_from_vport(vport);
2254 spin_lock_irq(shost->host_lock);
2255 vport->vpi_state |= LPFC_VPI_REGISTERED;
2256 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2257 spin_unlock_irq(shost->host_lock);
2260 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2261 ndlp = (struct lpfc_nodelist *)pmb->context2;
2263 pmb->context2 = NULL;
2266 /* Check security permission status on INIT_LINK mailbox command */
2267 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2268 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2269 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2270 "2860 SLI authentication is required "
2271 "for INIT_LINK but has not done yet\n");
2273 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2274 lpfc_sli4_mbox_cmd_free(phba, pmb);
2276 mempool_free(pmb, phba->mbox_mem_pool);
2279 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2280 * @phba: Pointer to HBA context object.
2281 * @pmb: Pointer to mailbox object.
2283 * This function is the unreg rpi mailbox completion handler. It
2284 * frees the memory resources associated with the completed mailbox
2285 * command. An additional refrenece is put on the ndlp to prevent
2286 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2287 * the unreg mailbox command completes, this routine puts the
2292 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2294 struct lpfc_vport *vport = pmb->vport;
2295 struct lpfc_nodelist *ndlp;
2297 ndlp = pmb->context1;
2298 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2299 if (phba->sli_rev == LPFC_SLI_REV4 &&
2300 (bf_get(lpfc_sli_intf_if_type,
2301 &phba->sli4_hba.sli_intf) ==
2302 LPFC_SLI_INTF_IF_TYPE_2)) {
2304 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
2305 "0010 UNREG_LOGIN vpi:%x "
2306 "rpi:%x DID:%x map:%x %p\n",
2307 vport->vpi, ndlp->nlp_rpi,
2309 ndlp->nlp_usg_map, ndlp);
2310 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2316 mempool_free(pmb, phba->mbox_mem_pool);
2320 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2321 * @phba: Pointer to HBA context object.
2323 * This function is called with no lock held. This function processes all
2324 * the completed mailbox commands and gives it to upper layers. The interrupt
2325 * service routine processes mailbox completion interrupt and adds completed
2326 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2327 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2328 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2329 * function returns the mailbox commands to the upper layer by calling the
2330 * completion handler function of each mailbox.
2333 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
2340 phba->sli.slistat.mbox_event++;
2342 /* Get all completed mailboxe buffers into the cmplq */
2343 spin_lock_irq(&phba->hbalock);
2344 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2345 spin_unlock_irq(&phba->hbalock);
2347 /* Get a Mailbox buffer to setup mailbox commands for callback */
2349 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2355 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2357 lpfc_debugfs_disc_trc(pmb->vport,
2358 LPFC_DISC_TRC_MBOX_VPORT,
2359 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2360 (uint32_t)pmbox->mbxCommand,
2361 pmbox->un.varWords[0],
2362 pmbox->un.varWords[1]);
2365 lpfc_debugfs_disc_trc(phba->pport,
2367 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2368 (uint32_t)pmbox->mbxCommand,
2369 pmbox->un.varWords[0],
2370 pmbox->un.varWords[1]);
2375 * It is a fatal error if unknown mbox command completion.
2377 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2379 /* Unknown mailbox command compl */
2380 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2381 "(%d):0323 Unknown Mailbox command "
2382 "x%x (x%x/x%x) Cmpl\n",
2383 pmb->vport ? pmb->vport->vpi : 0,
2385 lpfc_sli_config_mbox_subsys_get(phba,
2387 lpfc_sli_config_mbox_opcode_get(phba,
2389 phba->link_state = LPFC_HBA_ERROR;
2390 phba->work_hs = HS_FFER3;
2391 lpfc_handle_eratt(phba);
2395 if (pmbox->mbxStatus) {
2396 phba->sli.slistat.mbox_stat_err++;
2397 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2398 /* Mbox cmd cmpl error - RETRYing */
2399 lpfc_printf_log(phba, KERN_INFO,
2401 "(%d):0305 Mbox cmd cmpl "
2402 "error - RETRYing Data: x%x "
2403 "(x%x/x%x) x%x x%x x%x\n",
2404 pmb->vport ? pmb->vport->vpi : 0,
2406 lpfc_sli_config_mbox_subsys_get(phba,
2408 lpfc_sli_config_mbox_opcode_get(phba,
2411 pmbox->un.varWords[0],
2412 pmb->vport->port_state);
2413 pmbox->mbxStatus = 0;
2414 pmbox->mbxOwner = OWN_HOST;
2415 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2416 if (rc != MBX_NOT_FINISHED)
2421 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2422 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2423 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2424 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2426 pmb->vport ? pmb->vport->vpi : 0,
2428 lpfc_sli_config_mbox_subsys_get(phba, pmb),
2429 lpfc_sli_config_mbox_opcode_get(phba, pmb),
2431 *((uint32_t *) pmbox),
2432 pmbox->un.varWords[0],
2433 pmbox->un.varWords[1],
2434 pmbox->un.varWords[2],
2435 pmbox->un.varWords[3],
2436 pmbox->un.varWords[4],
2437 pmbox->un.varWords[5],
2438 pmbox->un.varWords[6],
2439 pmbox->un.varWords[7],
2440 pmbox->un.varWords[8],
2441 pmbox->un.varWords[9],
2442 pmbox->un.varWords[10]);
2445 pmb->mbox_cmpl(phba,pmb);
2451 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2452 * @phba: Pointer to HBA context object.
2453 * @pring: Pointer to driver SLI ring object.
2456 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2457 * is set in the tag the buffer is posted for a particular exchange,
2458 * the function will return the buffer without replacing the buffer.
2459 * If the buffer is for unsolicited ELS or CT traffic, this function
2460 * returns the buffer and also posts another buffer to the firmware.
2462 static struct lpfc_dmabuf *
2463 lpfc_sli_get_buff(struct lpfc_hba *phba,
2464 struct lpfc_sli_ring *pring,
2467 struct hbq_dmabuf *hbq_entry;
2469 if (tag & QUE_BUFTAG_BIT)
2470 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
2471 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2474 return &hbq_entry->dbuf;
2478 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2479 * @phba: Pointer to HBA context object.
2480 * @pring: Pointer to driver SLI ring object.
2481 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2482 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2483 * @fch_type: the type for the first frame of the sequence.
2485 * This function is called with no lock held. This function uses the r_ctl and
2486 * type of the received sequence to find the correct callback function to call
2487 * to process the sequence.
2490 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2491 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
2498 /* todo: tgt: forward NVME LS to transport */
2504 /* unSolicited Responses */
2505 if (pring->prt[0].profile) {
2506 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
2507 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
2511 /* We must search, based on rctl / type
2512 for the right routine */
2513 for (i = 0; i < pring->num_mask; i++) {
2514 if ((pring->prt[i].rctl == fch_r_ctl) &&
2515 (pring->prt[i].type == fch_type)) {
2516 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
2517 (pring->prt[i].lpfc_sli_rcv_unsol_event)
2518 (phba, pring, saveq);
2526 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2527 * @phba: Pointer to HBA context object.
2528 * @pring: Pointer to driver SLI ring object.
2529 * @saveq: Pointer to the unsolicited iocb.
2531 * This function is called with no lock held by the ring event handler
2532 * when there is an unsolicited iocb posted to the response ring by the
2533 * firmware. This function gets the buffer associated with the iocbs
2534 * and calls the event handler for the ring. This function handles both
2535 * qring buffers and hbq buffers.
2536 * When the function returns 1 the caller can free the iocb object otherwise
2537 * upper layer functions will free the iocb objects.
2540 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2541 struct lpfc_iocbq *saveq)
2545 uint32_t Rctl, Type;
2546 struct lpfc_iocbq *iocbq;
2547 struct lpfc_dmabuf *dmzbuf;
2549 irsp = &(saveq->iocb);
2551 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
2552 if (pring->lpfc_sli_rcv_async_status)
2553 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
2555 lpfc_printf_log(phba,
2558 "0316 Ring %d handler: unexpected "
2559 "ASYNC_STATUS iocb received evt_code "
2562 irsp->un.asyncstat.evt_code);
2566 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
2567 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
2568 if (irsp->ulpBdeCount > 0) {
2569 dmzbuf = lpfc_sli_get_buff(phba, pring,
2570 irsp->un.ulpWord[3]);
2571 lpfc_in_buf_free(phba, dmzbuf);
2574 if (irsp->ulpBdeCount > 1) {
2575 dmzbuf = lpfc_sli_get_buff(phba, pring,
2576 irsp->unsli3.sli3Words[3]);
2577 lpfc_in_buf_free(phba, dmzbuf);
2580 if (irsp->ulpBdeCount > 2) {
2581 dmzbuf = lpfc_sli_get_buff(phba, pring,
2582 irsp->unsli3.sli3Words[7]);
2583 lpfc_in_buf_free(phba, dmzbuf);
2589 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2590 if (irsp->ulpBdeCount != 0) {
2591 saveq->context2 = lpfc_sli_get_buff(phba, pring,
2592 irsp->un.ulpWord[3]);
2593 if (!saveq->context2)
2594 lpfc_printf_log(phba,
2597 "0341 Ring %d Cannot find buffer for "
2598 "an unsolicited iocb. tag 0x%x\n",
2600 irsp->un.ulpWord[3]);
2602 if (irsp->ulpBdeCount == 2) {
2603 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2604 irsp->unsli3.sli3Words[7]);
2605 if (!saveq->context3)
2606 lpfc_printf_log(phba,
2609 "0342 Ring %d Cannot find buffer for an"
2610 " unsolicited iocb. tag 0x%x\n",
2612 irsp->unsli3.sli3Words[7]);
2614 list_for_each_entry(iocbq, &saveq->list, list) {
2615 irsp = &(iocbq->iocb);
2616 if (irsp->ulpBdeCount != 0) {
2617 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2618 irsp->un.ulpWord[3]);
2619 if (!iocbq->context2)
2620 lpfc_printf_log(phba,
2623 "0343 Ring %d Cannot find "
2624 "buffer for an unsolicited iocb"
2625 ". tag 0x%x\n", pring->ringno,
2626 irsp->un.ulpWord[3]);
2628 if (irsp->ulpBdeCount == 2) {
2629 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2630 irsp->unsli3.sli3Words[7]);
2631 if (!iocbq->context3)
2632 lpfc_printf_log(phba,
2635 "0344 Ring %d Cannot find "
2636 "buffer for an unsolicited "
2639 irsp->unsli3.sli3Words[7]);
2643 if (irsp->ulpBdeCount != 0 &&
2644 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2645 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2648 /* search continue save q for same XRI */
2649 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2650 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
2651 saveq->iocb.unsli3.rcvsli3.ox_id) {
2652 list_add_tail(&saveq->list, &iocbq->list);
2658 list_add_tail(&saveq->clist,
2659 &pring->iocb_continue_saveq);
2660 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2661 list_del_init(&iocbq->clist);
2663 irsp = &(saveq->iocb);
2667 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2668 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2669 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2670 Rctl = FC_RCTL_ELS_REQ;
2673 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2674 Rctl = w5p->hcsw.Rctl;
2675 Type = w5p->hcsw.Type;
2677 /* Firmware Workaround */
2678 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2679 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2680 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2681 Rctl = FC_RCTL_ELS_REQ;
2683 w5p->hcsw.Rctl = Rctl;
2684 w5p->hcsw.Type = Type;
2688 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2689 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2690 "0313 Ring %d handler: unexpected Rctl x%x "
2691 "Type x%x received\n",
2692 pring->ringno, Rctl, Type);
2698 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2699 * @phba: Pointer to HBA context object.
2700 * @pring: Pointer to driver SLI ring object.
2701 * @prspiocb: Pointer to response iocb object.
2703 * This function looks up the iocb_lookup table to get the command iocb
2704 * corresponding to the given response iocb using the iotag of the
2705 * response iocb. This function is called with the hbalock held.
2706 * This function returns the command iocb object if it finds the command
2707 * iocb else returns NULL.
2709 static struct lpfc_iocbq *
2710 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
2711 struct lpfc_sli_ring *pring,
2712 struct lpfc_iocbq *prspiocb)
2714 struct lpfc_iocbq *cmd_iocb = NULL;
2716 lockdep_assert_held(&phba->hbalock);
2718 iotag = prspiocb->iocb.ulpIoTag;
2720 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2721 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2722 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
2723 /* remove from txcmpl queue list */
2724 list_del_init(&cmd_iocb->list);
2725 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
2730 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2731 "0317 iotag x%x is out of "
2732 "range: max iotag x%x wd0 x%x\n",
2733 iotag, phba->sli.last_iotag,
2734 *(((uint32_t *) &prspiocb->iocb) + 7));
2739 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2740 * @phba: Pointer to HBA context object.
2741 * @pring: Pointer to driver SLI ring object.
2744 * This function looks up the iocb_lookup table to get the command iocb
2745 * corresponding to the given iotag. This function is called with the
2747 * This function returns the command iocb object if it finds the command
2748 * iocb else returns NULL.
2750 static struct lpfc_iocbq *
2751 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
2752 struct lpfc_sli_ring *pring, uint16_t iotag)
2754 struct lpfc_iocbq *cmd_iocb = NULL;
2756 lockdep_assert_held(&phba->hbalock);
2757 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
2758 cmd_iocb = phba->sli.iocbq_lookup[iotag];
2759 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
2760 /* remove from txcmpl queue list */
2761 list_del_init(&cmd_iocb->list);
2762 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
2767 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2768 "0372 iotag x%x lookup error: max iotag (x%x) "
2770 iotag, phba->sli.last_iotag,
2771 cmd_iocb ? cmd_iocb->iocb_flag : 0xffff);
2776 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2777 * @phba: Pointer to HBA context object.
2778 * @pring: Pointer to driver SLI ring object.
2779 * @saveq: Pointer to the response iocb to be processed.
2781 * This function is called by the ring event handler for non-fcp
2782 * rings when there is a new response iocb in the response ring.
2783 * The caller is not required to hold any locks. This function
2784 * gets the command iocb associated with the response iocb and
2785 * calls the completion handler for the command iocb. If there
2786 * is no completion handler, the function will free the resources
2787 * associated with command iocb. If the response iocb is for
2788 * an already aborted command iocb, the status of the completion
2789 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2790 * This function always returns 1.
2793 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2794 struct lpfc_iocbq *saveq)
2796 struct lpfc_iocbq *cmdiocbp;
2798 unsigned long iflag;
2800 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2801 spin_lock_irqsave(&phba->hbalock, iflag);
2802 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
2803 spin_unlock_irqrestore(&phba->hbalock, iflag);
2806 if (cmdiocbp->iocb_cmpl) {
2808 * If an ELS command failed send an event to mgmt
2811 if (saveq->iocb.ulpStatus &&
2812 (pring->ringno == LPFC_ELS_RING) &&
2813 (cmdiocbp->iocb.ulpCommand ==
2814 CMD_ELS_REQUEST64_CR))
2815 lpfc_send_els_failure_event(phba,
2819 * Post all ELS completions to the worker thread.
2820 * All other are passed to the completion callback.
2822 if (pring->ringno == LPFC_ELS_RING) {
2823 if ((phba->sli_rev < LPFC_SLI_REV4) &&
2824 (cmdiocbp->iocb_flag &
2825 LPFC_DRIVER_ABORTED)) {
2826 spin_lock_irqsave(&phba->hbalock,
2828 cmdiocbp->iocb_flag &=
2829 ~LPFC_DRIVER_ABORTED;
2830 spin_unlock_irqrestore(&phba->hbalock,
2832 saveq->iocb.ulpStatus =
2833 IOSTAT_LOCAL_REJECT;
2834 saveq->iocb.un.ulpWord[4] =
2837 /* Firmware could still be in progress
2838 * of DMAing payload, so don't free data
2839 * buffer till after a hbeat.
2841 spin_lock_irqsave(&phba->hbalock,
2843 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2844 spin_unlock_irqrestore(&phba->hbalock,
2847 if (phba->sli_rev == LPFC_SLI_REV4) {
2848 if (saveq->iocb_flag &
2849 LPFC_EXCHANGE_BUSY) {
2850 /* Set cmdiocb flag for the
2851 * exchange busy so sgl (xri)
2852 * will not be released until
2853 * the abort xri is received
2857 &phba->hbalock, iflag);
2858 cmdiocbp->iocb_flag |=
2860 spin_unlock_irqrestore(
2861 &phba->hbalock, iflag);
2863 if (cmdiocbp->iocb_flag &
2864 LPFC_DRIVER_ABORTED) {
2866 * Clear LPFC_DRIVER_ABORTED
2867 * bit in case it was driver
2871 &phba->hbalock, iflag);
2872 cmdiocbp->iocb_flag &=
2873 ~LPFC_DRIVER_ABORTED;
2874 spin_unlock_irqrestore(
2875 &phba->hbalock, iflag);
2876 cmdiocbp->iocb.ulpStatus =
2877 IOSTAT_LOCAL_REJECT;
2878 cmdiocbp->iocb.un.ulpWord[4] =
2879 IOERR_ABORT_REQUESTED;
2881 * For SLI4, irsiocb contains
2882 * NO_XRI in sli_xritag, it
2883 * shall not affect releasing
2884 * sgl (xri) process.
2886 saveq->iocb.ulpStatus =
2887 IOSTAT_LOCAL_REJECT;
2888 saveq->iocb.un.ulpWord[4] =
2891 &phba->hbalock, iflag);
2893 LPFC_DELAY_MEM_FREE;
2894 spin_unlock_irqrestore(
2895 &phba->hbalock, iflag);
2899 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
2901 lpfc_sli_release_iocbq(phba, cmdiocbp);
2904 * Unknown initiating command based on the response iotag.
2905 * This could be the case on the ELS ring because of
2908 if (pring->ringno != LPFC_ELS_RING) {
2910 * Ring <ringno> handler: unexpected completion IoTag
2913 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2914 "0322 Ring %d handler: "
2915 "unexpected completion IoTag x%x "
2916 "Data: x%x x%x x%x x%x\n",
2918 saveq->iocb.ulpIoTag,
2919 saveq->iocb.ulpStatus,
2920 saveq->iocb.un.ulpWord[4],
2921 saveq->iocb.ulpCommand,
2922 saveq->iocb.ulpContext);
2930 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2931 * @phba: Pointer to HBA context object.
2932 * @pring: Pointer to driver SLI ring object.
2934 * This function is called from the iocb ring event handlers when
2935 * put pointer is ahead of the get pointer for a ring. This function signal
2936 * an error attention condition to the worker thread and the worker
2937 * thread will transition the HBA to offline state.
2940 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2942 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2944 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2945 * rsp ring <portRspMax>
2947 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2948 "0312 Ring %d handler: portRspPut %d "
2949 "is bigger than rsp ring %d\n",
2950 pring->ringno, le32_to_cpu(pgp->rspPutInx),
2951 pring->sli.sli3.numRiocb);
2953 phba->link_state = LPFC_HBA_ERROR;
2956 * All error attention handlers are posted to
2959 phba->work_ha |= HA_ERATT;
2960 phba->work_hs = HS_FFER3;
2962 lpfc_worker_wake_up(phba);
2968 * lpfc_poll_eratt - Error attention polling timer timeout handler
2969 * @ptr: Pointer to address of HBA context object.
2971 * This function is invoked by the Error Attention polling timer when the
2972 * timer times out. It will check the SLI Error Attention register for
2973 * possible attention events. If so, it will post an Error Attention event
2974 * and wake up worker thread to process it. Otherwise, it will set up the
2975 * Error Attention polling timer for the next poll.
2977 void lpfc_poll_eratt(unsigned long ptr)
2979 struct lpfc_hba *phba;
2981 uint64_t sli_intr, cnt;
2983 phba = (struct lpfc_hba *)ptr;
2985 /* Here we will also keep track of interrupts per sec of the hba */
2986 sli_intr = phba->sli.slistat.sli_intr;
2988 if (phba->sli.slistat.sli_prev_intr > sli_intr)
2989 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
2992 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
2994 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
2995 do_div(cnt, phba->eratt_poll_interval);
2996 phba->sli.slistat.sli_ips = cnt;
2998 phba->sli.slistat.sli_prev_intr = sli_intr;
3000 /* Check chip HA register for error event */
3001 eratt = lpfc_sli_check_eratt(phba);
3004 /* Tell the worker thread there is work to do */
3005 lpfc_worker_wake_up(phba);
3007 /* Restart the timer for next eratt poll */
3008 mod_timer(&phba->eratt_poll,
3010 msecs_to_jiffies(1000 * phba->eratt_poll_interval));
3016 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3017 * @phba: Pointer to HBA context object.
3018 * @pring: Pointer to driver SLI ring object.
3019 * @mask: Host attention register mask for this ring.
3021 * This function is called from the interrupt context when there is a ring
3022 * event for the fcp ring. The caller does not hold any lock.
3023 * The function processes each response iocb in the response ring until it
3024 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3025 * LE bit set. The function will call the completion handler of the command iocb
3026 * if the response iocb indicates a completion for a command iocb or it is
3027 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3028 * function if this is an unsolicited iocb.
3029 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3030 * to check it explicitly.
3033 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
3034 struct lpfc_sli_ring *pring, uint32_t mask)
3036 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3037 IOCB_t *irsp = NULL;
3038 IOCB_t *entry = NULL;
3039 struct lpfc_iocbq *cmdiocbq = NULL;
3040 struct lpfc_iocbq rspiocbq;
3042 uint32_t portRspPut, portRspMax;
3044 lpfc_iocb_type type;
3045 unsigned long iflag;
3046 uint32_t rsp_cmpl = 0;
3048 spin_lock_irqsave(&phba->hbalock, iflag);
3049 pring->stats.iocb_event++;
3052 * The next available response entry should never exceed the maximum
3053 * entries. If it does, treat it as an adapter hardware error.
3055 portRspMax = pring->sli.sli3.numRiocb;
3056 portRspPut = le32_to_cpu(pgp->rspPutInx);
3057 if (unlikely(portRspPut >= portRspMax)) {
3058 lpfc_sli_rsp_pointers_error(phba, pring);
3059 spin_unlock_irqrestore(&phba->hbalock, iflag);
3062 if (phba->fcp_ring_in_use) {
3063 spin_unlock_irqrestore(&phba->hbalock, iflag);
3066 phba->fcp_ring_in_use = 1;
3069 while (pring->sli.sli3.rspidx != portRspPut) {
3071 * Fetch an entry off the ring and copy it into a local data
3072 * structure. The copy involves a byte-swap since the
3073 * network byte order and pci byte orders are different.
3075 entry = lpfc_resp_iocb(phba, pring);
3076 phba->last_completion_time = jiffies;
3078 if (++pring->sli.sli3.rspidx >= portRspMax)
3079 pring->sli.sli3.rspidx = 0;
3081 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
3082 (uint32_t *) &rspiocbq.iocb,
3083 phba->iocb_rsp_size);
3084 INIT_LIST_HEAD(&(rspiocbq.list));
3085 irsp = &rspiocbq.iocb;
3087 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
3088 pring->stats.iocb_rsp++;
3091 if (unlikely(irsp->ulpStatus)) {
3093 * If resource errors reported from HBA, reduce
3094 * queuedepths of the SCSI device.
3096 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3097 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3098 IOERR_NO_RESOURCES)) {
3099 spin_unlock_irqrestore(&phba->hbalock, iflag);
3100 phba->lpfc_rampdown_queue_depth(phba);
3101 spin_lock_irqsave(&phba->hbalock, iflag);
3104 /* Rsp ring <ringno> error: IOCB */
3105 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3106 "0336 Rsp Ring %d error: IOCB Data: "
3107 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3109 irsp->un.ulpWord[0],
3110 irsp->un.ulpWord[1],
3111 irsp->un.ulpWord[2],
3112 irsp->un.ulpWord[3],
3113 irsp->un.ulpWord[4],
3114 irsp->un.ulpWord[5],
3115 *(uint32_t *)&irsp->un1,
3116 *((uint32_t *)&irsp->un1 + 1));
3120 case LPFC_ABORT_IOCB:
3123 * Idle exchange closed via ABTS from port. No iocb
3124 * resources need to be recovered.
3126 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
3127 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3128 "0333 IOCB cmd 0x%x"
3129 " processed. Skipping"
3135 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3137 if (unlikely(!cmdiocbq))
3139 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3140 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3141 if (cmdiocbq->iocb_cmpl) {
3142 spin_unlock_irqrestore(&phba->hbalock, iflag);
3143 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
3145 spin_lock_irqsave(&phba->hbalock, iflag);
3148 case LPFC_UNSOL_IOCB:
3149 spin_unlock_irqrestore(&phba->hbalock, iflag);
3150 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
3151 spin_lock_irqsave(&phba->hbalock, iflag);
3154 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3155 char adaptermsg[LPFC_MAX_ADPTMSG];
3156 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3157 memcpy(&adaptermsg[0], (uint8_t *) irsp,
3159 dev_warn(&((phba->pcidev)->dev),
3161 phba->brd_no, adaptermsg);
3163 /* Unknown IOCB command */
3164 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3165 "0334 Unknown IOCB command "
3166 "Data: x%x, x%x x%x x%x x%x\n",
3167 type, irsp->ulpCommand,
3176 * The response IOCB has been processed. Update the ring
3177 * pointer in SLIM. If the port response put pointer has not
3178 * been updated, sync the pgp->rspPutInx and fetch the new port
3179 * response put pointer.
3181 writel(pring->sli.sli3.rspidx,
3182 &phba->host_gp[pring->ringno].rspGetInx);
3184 if (pring->sli.sli3.rspidx == portRspPut)
3185 portRspPut = le32_to_cpu(pgp->rspPutInx);
3188 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
3189 pring->stats.iocb_rsp_full++;
3190 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3191 writel(status, phba->CAregaddr);
3192 readl(phba->CAregaddr);
3194 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3195 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3196 pring->stats.iocb_cmd_empty++;
3198 /* Force update of the local copy of cmdGetInx */
3199 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3200 lpfc_sli_resume_iocb(phba, pring);
3202 if ((pring->lpfc_sli_cmd_available))
3203 (pring->lpfc_sli_cmd_available) (phba, pring);
3207 phba->fcp_ring_in_use = 0;
3208 spin_unlock_irqrestore(&phba->hbalock, iflag);
3213 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3214 * @phba: Pointer to HBA context object.
3215 * @pring: Pointer to driver SLI ring object.
3216 * @rspiocbp: Pointer to driver response IOCB object.
3218 * This function is called from the worker thread when there is a slow-path
3219 * response IOCB to process. This function chains all the response iocbs until
3220 * seeing the iocb with the LE bit set. The function will call
3221 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3222 * completion of a command iocb. The function will call the
3223 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3224 * The function frees the resources or calls the completion handler if this
3225 * iocb is an abort completion. The function returns NULL when the response
3226 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3227 * this function shall chain the iocb on to the iocb_continueq and return the
3228 * response iocb passed in.
3230 static struct lpfc_iocbq *
3231 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3232 struct lpfc_iocbq *rspiocbp)
3234 struct lpfc_iocbq *saveq;
3235 struct lpfc_iocbq *cmdiocbp;
3236 struct lpfc_iocbq *next_iocb;
3237 IOCB_t *irsp = NULL;
3238 uint32_t free_saveq;
3239 uint8_t iocb_cmd_type;
3240 lpfc_iocb_type type;
3241 unsigned long iflag;
3244 spin_lock_irqsave(&phba->hbalock, iflag);
3245 /* First add the response iocb to the countinueq list */
3246 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3247 pring->iocb_continueq_cnt++;
3249 /* Now, determine whether the list is completed for processing */
3250 irsp = &rspiocbp->iocb;
3253 * By default, the driver expects to free all resources
3254 * associated with this iocb completion.
3257 saveq = list_get_first(&pring->iocb_continueq,
3258 struct lpfc_iocbq, list);
3259 irsp = &(saveq->iocb);
3260 list_del_init(&pring->iocb_continueq);
3261 pring->iocb_continueq_cnt = 0;
3263 pring->stats.iocb_rsp++;
3266 * If resource errors reported from HBA, reduce
3267 * queuedepths of the SCSI device.
3269 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3270 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3271 IOERR_NO_RESOURCES)) {
3272 spin_unlock_irqrestore(&phba->hbalock, iflag);
3273 phba->lpfc_rampdown_queue_depth(phba);
3274 spin_lock_irqsave(&phba->hbalock, iflag);
3277 if (irsp->ulpStatus) {
3278 /* Rsp ring <ringno> error: IOCB */
3279 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3280 "0328 Rsp Ring %d error: "
3285 "x%x x%x x%x x%x\n",
3287 irsp->un.ulpWord[0],
3288 irsp->un.ulpWord[1],
3289 irsp->un.ulpWord[2],
3290 irsp->un.ulpWord[3],
3291 irsp->un.ulpWord[4],
3292 irsp->un.ulpWord[5],
3293 *(((uint32_t *) irsp) + 6),
3294 *(((uint32_t *) irsp) + 7),
3295 *(((uint32_t *) irsp) + 8),
3296 *(((uint32_t *) irsp) + 9),
3297 *(((uint32_t *) irsp) + 10),
3298 *(((uint32_t *) irsp) + 11),
3299 *(((uint32_t *) irsp) + 12),
3300 *(((uint32_t *) irsp) + 13),
3301 *(((uint32_t *) irsp) + 14),
3302 *(((uint32_t *) irsp) + 15));
3306 * Fetch the IOCB command type and call the correct completion
3307 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3308 * get freed back to the lpfc_iocb_list by the discovery
3311 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3312 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3315 spin_unlock_irqrestore(&phba->hbalock, iflag);
3316 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3317 spin_lock_irqsave(&phba->hbalock, iflag);
3320 case LPFC_UNSOL_IOCB:
3321 spin_unlock_irqrestore(&phba->hbalock, iflag);
3322 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3323 spin_lock_irqsave(&phba->hbalock, iflag);
3328 case LPFC_ABORT_IOCB:
3330 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX)
3331 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3334 /* Call the specified completion routine */
3335 if (cmdiocbp->iocb_cmpl) {
3336 spin_unlock_irqrestore(&phba->hbalock,
3338 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3340 spin_lock_irqsave(&phba->hbalock,
3343 __lpfc_sli_release_iocbq(phba,
3348 case LPFC_UNKNOWN_IOCB:
3349 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3350 char adaptermsg[LPFC_MAX_ADPTMSG];
3351 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3352 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3354 dev_warn(&((phba->pcidev)->dev),
3356 phba->brd_no, adaptermsg);
3358 /* Unknown IOCB command */
3359 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3360 "0335 Unknown IOCB "
3361 "command Data: x%x "
3372 list_for_each_entry_safe(rspiocbp, next_iocb,
3373 &saveq->list, list) {
3374 list_del_init(&rspiocbp->list);
3375 __lpfc_sli_release_iocbq(phba, rspiocbp);
3377 __lpfc_sli_release_iocbq(phba, saveq);
3381 spin_unlock_irqrestore(&phba->hbalock, iflag);
3386 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3387 * @phba: Pointer to HBA context object.
3388 * @pring: Pointer to driver SLI ring object.
3389 * @mask: Host attention register mask for this ring.
3391 * This routine wraps the actual slow_ring event process routine from the
3392 * API jump table function pointer from the lpfc_hba struct.
3395 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
3396 struct lpfc_sli_ring *pring, uint32_t mask)
3398 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
3402 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3403 * @phba: Pointer to HBA context object.
3404 * @pring: Pointer to driver SLI ring object.
3405 * @mask: Host attention register mask for this ring.
3407 * This function is called from the worker thread when there is a ring event
3408 * for non-fcp rings. The caller does not hold any lock. The function will
3409 * remove each response iocb in the response ring and calls the handle
3410 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3413 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
3414 struct lpfc_sli_ring *pring, uint32_t mask)
3416 struct lpfc_pgp *pgp;
3418 IOCB_t *irsp = NULL;
3419 struct lpfc_iocbq *rspiocbp = NULL;
3420 uint32_t portRspPut, portRspMax;
3421 unsigned long iflag;
3424 pgp = &phba->port_gp[pring->ringno];
3425 spin_lock_irqsave(&phba->hbalock, iflag);
3426 pring->stats.iocb_event++;
3429 * The next available response entry should never exceed the maximum
3430 * entries. If it does, treat it as an adapter hardware error.
3432 portRspMax = pring->sli.sli3.numRiocb;
3433 portRspPut = le32_to_cpu(pgp->rspPutInx);
3434 if (portRspPut >= portRspMax) {
3436 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3437 * rsp ring <portRspMax>
3439 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3440 "0303 Ring %d handler: portRspPut %d "
3441 "is bigger than rsp ring %d\n",
3442 pring->ringno, portRspPut, portRspMax);
3444 phba->link_state = LPFC_HBA_ERROR;
3445 spin_unlock_irqrestore(&phba->hbalock, iflag);
3447 phba->work_hs = HS_FFER3;
3448 lpfc_handle_eratt(phba);
3454 while (pring->sli.sli3.rspidx != portRspPut) {
3456 * Build a completion list and call the appropriate handler.
3457 * The process is to get the next available response iocb, get
3458 * a free iocb from the list, copy the response data into the
3459 * free iocb, insert to the continuation list, and update the
3460 * next response index to slim. This process makes response
3461 * iocb's in the ring available to DMA as fast as possible but
3462 * pays a penalty for a copy operation. Since the iocb is
3463 * only 32 bytes, this penalty is considered small relative to
3464 * the PCI reads for register values and a slim write. When
3465 * the ulpLe field is set, the entire Command has been
3468 entry = lpfc_resp_iocb(phba, pring);
3470 phba->last_completion_time = jiffies;
3471 rspiocbp = __lpfc_sli_get_iocbq(phba);
3472 if (rspiocbp == NULL) {
3473 printk(KERN_ERR "%s: out of buffers! Failing "
3474 "completion.\n", __func__);
3478 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
3479 phba->iocb_rsp_size);
3480 irsp = &rspiocbp->iocb;
3482 if (++pring->sli.sli3.rspidx >= portRspMax)
3483 pring->sli.sli3.rspidx = 0;
3485 if (pring->ringno == LPFC_ELS_RING) {
3486 lpfc_debugfs_slow_ring_trc(phba,
3487 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3488 *(((uint32_t *) irsp) + 4),
3489 *(((uint32_t *) irsp) + 6),
3490 *(((uint32_t *) irsp) + 7));
3493 writel(pring->sli.sli3.rspidx,
3494 &phba->host_gp[pring->ringno].rspGetInx);
3496 spin_unlock_irqrestore(&phba->hbalock, iflag);
3497 /* Handle the response IOCB */
3498 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
3499 spin_lock_irqsave(&phba->hbalock, iflag);
3502 * If the port response put pointer has not been updated, sync
3503 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3504 * response put pointer.
3506 if (pring->sli.sli3.rspidx == portRspPut) {
3507 portRspPut = le32_to_cpu(pgp->rspPutInx);
3509 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3511 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
3512 /* At least one response entry has been freed */
3513 pring->stats.iocb_rsp_full++;
3514 /* SET RxRE_RSP in Chip Att register */
3515 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3516 writel(status, phba->CAregaddr);
3517 readl(phba->CAregaddr); /* flush */
3519 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3520 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3521 pring->stats.iocb_cmd_empty++;
3523 /* Force update of the local copy of cmdGetInx */
3524 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3525 lpfc_sli_resume_iocb(phba, pring);
3527 if ((pring->lpfc_sli_cmd_available))
3528 (pring->lpfc_sli_cmd_available) (phba, pring);
3532 spin_unlock_irqrestore(&phba->hbalock, iflag);
3537 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3538 * @phba: Pointer to HBA context object.
3539 * @pring: Pointer to driver SLI ring object.
3540 * @mask: Host attention register mask for this ring.
3542 * This function is called from the worker thread when there is a pending
3543 * ELS response iocb on the driver internal slow-path response iocb worker
3544 * queue. The caller does not hold any lock. The function will remove each
3545 * response iocb from the response worker queue and calls the handle
3546 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3549 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3550 struct lpfc_sli_ring *pring, uint32_t mask)
3552 struct lpfc_iocbq *irspiocbq;
3553 struct hbq_dmabuf *dmabuf;
3554 struct lpfc_cq_event *cq_event;
3555 unsigned long iflag;
3557 spin_lock_irqsave(&phba->hbalock, iflag);
3558 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
3559 spin_unlock_irqrestore(&phba->hbalock, iflag);
3560 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
3561 /* Get the response iocb from the head of work queue */
3562 spin_lock_irqsave(&phba->hbalock, iflag);
3563 list_remove_head(&phba->sli4_hba.sp_queue_event,
3564 cq_event, struct lpfc_cq_event, list);
3565 spin_unlock_irqrestore(&phba->hbalock, iflag);
3567 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
3568 case CQE_CODE_COMPL_WQE:
3569 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
3571 /* Translate ELS WCQE to response IOCBQ */
3572 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
3575 lpfc_sli_sp_handle_rspiocb(phba, pring,
3578 case CQE_CODE_RECEIVE:
3579 case CQE_CODE_RECEIVE_V1:
3580 dmabuf = container_of(cq_event, struct hbq_dmabuf,
3582 lpfc_sli4_handle_received_buffer(phba, dmabuf);
3591 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3592 * @phba: Pointer to HBA context object.
3593 * @pring: Pointer to driver SLI ring object.
3595 * This function aborts all iocbs in the given ring and frees all the iocb
3596 * objects in txq. This function issues an abort iocb for all the iocb commands
3597 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3598 * the return of this function. The caller is not required to hold any locks.
3601 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3603 LIST_HEAD(completions);
3604 struct lpfc_iocbq *iocb, *next_iocb;
3606 if (pring->ringno == LPFC_ELS_RING) {
3607 lpfc_fabric_abort_hba(phba);
3610 /* Error everything on txq and txcmplq
3613 if (phba->sli_rev >= LPFC_SLI_REV4) {
3614 spin_lock_irq(&pring->ring_lock);
3615 list_splice_init(&pring->txq, &completions);
3617 spin_unlock_irq(&pring->ring_lock);
3619 spin_lock_irq(&phba->hbalock);
3620 /* Next issue ABTS for everything on the txcmplq */
3621 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3622 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3623 spin_unlock_irq(&phba->hbalock);
3625 spin_lock_irq(&phba->hbalock);
3626 list_splice_init(&pring->txq, &completions);
3629 /* Next issue ABTS for everything on the txcmplq */
3630 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3631 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3632 spin_unlock_irq(&phba->hbalock);
3635 /* Cancel all the IOCBs from the completions list */
3636 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3641 * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring
3642 * @phba: Pointer to HBA context object.
3643 * @pring: Pointer to driver SLI ring object.
3645 * This function aborts all iocbs in the given ring and frees all the iocb
3646 * objects in txq. This function issues an abort iocb for all the iocb commands
3647 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3648 * the return of this function. The caller is not required to hold any locks.
3651 lpfc_sli_abort_wqe_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3653 LIST_HEAD(completions);
3654 struct lpfc_iocbq *iocb, *next_iocb;
3656 if (pring->ringno == LPFC_ELS_RING)
3657 lpfc_fabric_abort_hba(phba);
3659 spin_lock_irq(&phba->hbalock);
3660 /* Next issue ABTS for everything on the txcmplq */
3661 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3662 lpfc_sli4_abort_nvme_io(phba, pring, iocb);
3663 spin_unlock_irq(&phba->hbalock);
3668 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3669 * @phba: Pointer to HBA context object.
3670 * @pring: Pointer to driver SLI ring object.
3672 * This function aborts all iocbs in FCP rings and frees all the iocb
3673 * objects in txq. This function issues an abort iocb for all the iocb commands
3674 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3675 * the return of this function. The caller is not required to hold any locks.
3678 lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
3680 struct lpfc_sli *psli = &phba->sli;
3681 struct lpfc_sli_ring *pring;
3684 /* Look on all the FCP Rings for the iotag */
3685 if (phba->sli_rev >= LPFC_SLI_REV4) {
3686 for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
3687 pring = phba->sli4_hba.fcp_wq[i]->pring;
3688 lpfc_sli_abort_iocb_ring(phba, pring);
3691 pring = &psli->sli3_ring[LPFC_FCP_RING];
3692 lpfc_sli_abort_iocb_ring(phba, pring);
3697 * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings
3698 * @phba: Pointer to HBA context object.
3700 * This function aborts all wqes in NVME rings. This function issues an
3701 * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in
3702 * the txcmplq is not guaranteed to complete before the return of this
3703 * function. The caller is not required to hold any locks.
3706 lpfc_sli_abort_nvme_rings(struct lpfc_hba *phba)
3708 struct lpfc_sli_ring *pring;
3711 if (phba->sli_rev < LPFC_SLI_REV4)
3714 /* Abort all IO on each NVME ring. */
3715 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
3716 pring = phba->sli4_hba.nvme_wq[i]->pring;
3717 lpfc_sli_abort_wqe_ring(phba, pring);
3723 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3724 * @phba: Pointer to HBA context object.
3726 * This function flushes all iocbs in the fcp ring and frees all the iocb
3727 * objects in txq and txcmplq. This function will not issue abort iocbs
3728 * for all the iocb commands in txcmplq, they will just be returned with
3729 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3730 * slot has been permanently disabled.
3733 lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
3737 struct lpfc_sli *psli = &phba->sli;
3738 struct lpfc_sli_ring *pring;
3741 spin_lock_irq(&phba->hbalock);
3742 /* Indicate the I/O queues are flushed */
3743 phba->hba_flag |= HBA_FCP_IOQ_FLUSH;
3744 spin_unlock_irq(&phba->hbalock);
3746 /* Look on all the FCP Rings for the iotag */
3747 if (phba->sli_rev >= LPFC_SLI_REV4) {
3748 for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
3749 pring = phba->sli4_hba.fcp_wq[i]->pring;
3751 spin_lock_irq(&pring->ring_lock);
3752 /* Retrieve everything on txq */
3753 list_splice_init(&pring->txq, &txq);
3754 /* Retrieve everything on the txcmplq */
3755 list_splice_init(&pring->txcmplq, &txcmplq);
3757 pring->txcmplq_cnt = 0;
3758 spin_unlock_irq(&pring->ring_lock);
3761 lpfc_sli_cancel_iocbs(phba, &txq,
3762 IOSTAT_LOCAL_REJECT,
3764 /* Flush the txcmpq */
3765 lpfc_sli_cancel_iocbs(phba, &txcmplq,
3766 IOSTAT_LOCAL_REJECT,
3770 pring = &psli->sli3_ring[LPFC_FCP_RING];
3772 spin_lock_irq(&phba->hbalock);
3773 /* Retrieve everything on txq */
3774 list_splice_init(&pring->txq, &txq);
3775 /* Retrieve everything on the txcmplq */
3776 list_splice_init(&pring->txcmplq, &txcmplq);
3778 pring->txcmplq_cnt = 0;
3779 spin_unlock_irq(&phba->hbalock);
3782 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
3784 /* Flush the txcmpq */
3785 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
3791 * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings
3792 * @phba: Pointer to HBA context object.
3794 * This function flushes all wqes in the nvme rings and frees all resources
3795 * in the txcmplq. This function does not issue abort wqes for the IO
3796 * commands in txcmplq, they will just be returned with
3797 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3798 * slot has been permanently disabled.
3801 lpfc_sli_flush_nvme_rings(struct lpfc_hba *phba)
3804 struct lpfc_sli_ring *pring;
3807 if (phba->sli_rev < LPFC_SLI_REV4)
3810 /* Hint to other driver operations that a flush is in progress. */
3811 spin_lock_irq(&phba->hbalock);
3812 phba->hba_flag |= HBA_NVME_IOQ_FLUSH;
3813 spin_unlock_irq(&phba->hbalock);
3815 /* Cycle through all NVME rings and complete each IO with
3816 * a local driver reason code. This is a flush so no
3817 * abort exchange to FW.
3819 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
3820 pring = phba->sli4_hba.nvme_wq[i]->pring;
3822 /* Retrieve everything on the txcmplq */
3823 spin_lock_irq(&pring->ring_lock);
3824 list_splice_init(&pring->txcmplq, &txcmplq);
3825 pring->txcmplq_cnt = 0;
3826 spin_unlock_irq(&pring->ring_lock);
3828 /* Flush the txcmpq &&&PAE */
3829 lpfc_sli_cancel_iocbs(phba, &txcmplq,
3830 IOSTAT_LOCAL_REJECT,
3836 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3837 * @phba: Pointer to HBA context object.
3838 * @mask: Bit mask to be checked.
3840 * This function reads the host status register and compares
3841 * with the provided bit mask to check if HBA completed
3842 * the restart. This function will wait in a loop for the
3843 * HBA to complete restart. If the HBA does not restart within
3844 * 15 iterations, the function will reset the HBA again. The
3845 * function returns 1 when HBA fail to restart otherwise returns
3849 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
3855 /* Read the HBA Host Status Register */
3856 if (lpfc_readl(phba->HSregaddr, &status))
3860 * Check status register every 100ms for 5 retries, then every
3861 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3862 * every 2.5 sec for 4.
3863 * Break our of the loop if errors occurred during init.
3865 while (((status & mask) != mask) &&
3866 !(status & HS_FFERM) &&
3878 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3879 lpfc_sli_brdrestart(phba);
3881 /* Read the HBA Host Status Register */
3882 if (lpfc_readl(phba->HSregaddr, &status)) {
3888 /* Check to see if any errors occurred during init */
3889 if ((status & HS_FFERM) || (i >= 20)) {
3890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3891 "2751 Adapter failed to restart, "
3892 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3894 readl(phba->MBslimaddr + 0xa8),
3895 readl(phba->MBslimaddr + 0xac));
3896 phba->link_state = LPFC_HBA_ERROR;
3904 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3905 * @phba: Pointer to HBA context object.
3906 * @mask: Bit mask to be checked.
3908 * This function checks the host status register to check if HBA is
3909 * ready. This function will wait in a loop for the HBA to be ready
3910 * If the HBA is not ready , the function will will reset the HBA PCI
3911 * function again. The function returns 1 when HBA fail to be ready
3912 * otherwise returns zero.
3915 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
3920 /* Read the HBA Host Status Register */
3921 status = lpfc_sli4_post_status_check(phba);
3924 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3925 lpfc_sli_brdrestart(phba);
3926 status = lpfc_sli4_post_status_check(phba);
3929 /* Check to see if any errors occurred during init */
3931 phba->link_state = LPFC_HBA_ERROR;
3934 phba->sli4_hba.intr_enable = 0;
3940 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3941 * @phba: Pointer to HBA context object.
3942 * @mask: Bit mask to be checked.
3944 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3945 * from the API jump table function pointer from the lpfc_hba struct.
3948 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
3950 return phba->lpfc_sli_brdready(phba, mask);
3953 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3956 * lpfc_reset_barrier - Make HBA ready for HBA reset
3957 * @phba: Pointer to HBA context object.
3959 * This function is called before resetting an HBA. This function is called
3960 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3962 void lpfc_reset_barrier(struct lpfc_hba *phba)
3964 uint32_t __iomem *resp_buf;
3965 uint32_t __iomem *mbox_buf;
3966 volatile uint32_t mbox;
3967 uint32_t hc_copy, ha_copy, resp_data;
3971 lockdep_assert_held(&phba->hbalock);
3973 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
3974 if (hdrtype != 0x80 ||
3975 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
3976 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
3980 * Tell the other part of the chip to suspend temporarily all
3983 resp_buf = phba->MBslimaddr;
3985 /* Disable the error attention */
3986 if (lpfc_readl(phba->HCregaddr, &hc_copy))
3988 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
3989 readl(phba->HCregaddr); /* flush */
3990 phba->link_flag |= LS_IGNORE_ERATT;
3992 if (lpfc_readl(phba->HAregaddr, &ha_copy))
3994 if (ha_copy & HA_ERATT) {
3995 /* Clear Chip error bit */
3996 writel(HA_ERATT, phba->HAregaddr);
3997 phba->pport->stopped = 1;
4001 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
4002 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
4004 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
4005 mbox_buf = phba->MBslimaddr;
4006 writel(mbox, mbox_buf);
4008 for (i = 0; i < 50; i++) {
4009 if (lpfc_readl((resp_buf + 1), &resp_data))
4011 if (resp_data != ~(BARRIER_TEST_PATTERN))
4017 if (lpfc_readl((resp_buf + 1), &resp_data))
4019 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
4020 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
4021 phba->pport->stopped)
4027 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
4029 for (i = 0; i < 500; i++) {
4030 if (lpfc_readl(resp_buf, &resp_data))
4032 if (resp_data != mbox)
4041 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4043 if (!(ha_copy & HA_ERATT))
4049 if (readl(phba->HAregaddr) & HA_ERATT) {
4050 writel(HA_ERATT, phba->HAregaddr);
4051 phba->pport->stopped = 1;
4055 phba->link_flag &= ~LS_IGNORE_ERATT;
4056 writel(hc_copy, phba->HCregaddr);
4057 readl(phba->HCregaddr); /* flush */
4061 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4062 * @phba: Pointer to HBA context object.
4064 * This function issues a kill_board mailbox command and waits for
4065 * the error attention interrupt. This function is called for stopping
4066 * the firmware processing. The caller is not required to hold any
4067 * locks. This function calls lpfc_hba_down_post function to free
4068 * any pending commands after the kill. The function will return 1 when it
4069 * fails to kill the board else will return 0.
4072 lpfc_sli_brdkill(struct lpfc_hba *phba)
4074 struct lpfc_sli *psli;
4084 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4085 "0329 Kill HBA Data: x%x x%x\n",
4086 phba->pport->port_state, psli->sli_flag);
4088 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4092 /* Disable the error attention */
4093 spin_lock_irq(&phba->hbalock);
4094 if (lpfc_readl(phba->HCregaddr, &status)) {
4095 spin_unlock_irq(&phba->hbalock);
4096 mempool_free(pmb, phba->mbox_mem_pool);
4099 status &= ~HC_ERINT_ENA;
4100 writel(status, phba->HCregaddr);
4101 readl(phba->HCregaddr); /* flush */
4102 phba->link_flag |= LS_IGNORE_ERATT;
4103 spin_unlock_irq(&phba->hbalock);
4105 lpfc_kill_board(phba, pmb);
4106 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4107 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4109 if (retval != MBX_SUCCESS) {
4110 if (retval != MBX_BUSY)
4111 mempool_free(pmb, phba->mbox_mem_pool);
4112 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4113 "2752 KILL_BOARD command failed retval %d\n",
4115 spin_lock_irq(&phba->hbalock);
4116 phba->link_flag &= ~LS_IGNORE_ERATT;
4117 spin_unlock_irq(&phba->hbalock);
4121 spin_lock_irq(&phba->hbalock);
4122 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4123 spin_unlock_irq(&phba->hbalock);
4125 mempool_free(pmb, phba->mbox_mem_pool);
4127 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4128 * attention every 100ms for 3 seconds. If we don't get ERATT after
4129 * 3 seconds we still set HBA_ERROR state because the status of the
4130 * board is now undefined.
4132 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4134 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
4136 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4140 del_timer_sync(&psli->mbox_tmo);
4141 if (ha_copy & HA_ERATT) {
4142 writel(HA_ERATT, phba->HAregaddr);
4143 phba->pport->stopped = 1;
4145 spin_lock_irq(&phba->hbalock);
4146 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4147 psli->mbox_active = NULL;
4148 phba->link_flag &= ~LS_IGNORE_ERATT;
4149 spin_unlock_irq(&phba->hbalock);
4151 lpfc_hba_down_post(phba);
4152 phba->link_state = LPFC_HBA_ERROR;
4154 return ha_copy & HA_ERATT ? 0 : 1;
4158 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4159 * @phba: Pointer to HBA context object.
4161 * This function resets the HBA by writing HC_INITFF to the control
4162 * register. After the HBA resets, this function resets all the iocb ring
4163 * indices. This function disables PCI layer parity checking during
4165 * This function returns 0 always.
4166 * The caller is not required to hold any locks.
4169 lpfc_sli_brdreset(struct lpfc_hba *phba)
4171 struct lpfc_sli *psli;
4172 struct lpfc_sli_ring *pring;
4179 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4180 "0325 Reset HBA Data: x%x x%x\n",
4181 phba->pport->port_state, psli->sli_flag);
4183 /* perform board reset */
4184 phba->fc_eventTag = 0;
4185 phba->link_events = 0;
4186 phba->pport->fc_myDID = 0;
4187 phba->pport->fc_prevDID = 0;
4189 /* Turn off parity checking and serr during the physical reset */
4190 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
4191 pci_write_config_word(phba->pcidev, PCI_COMMAND,
4193 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4195 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
4197 /* Now toggle INITFF bit in the Host Control Register */
4198 writel(HC_INITFF, phba->HCregaddr);
4200 readl(phba->HCregaddr); /* flush */
4201 writel(0, phba->HCregaddr);
4202 readl(phba->HCregaddr); /* flush */
4204 /* Restore PCI cmd register */
4205 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4207 /* Initialize relevant SLI info */
4208 for (i = 0; i < psli->num_rings; i++) {
4209 pring = &psli->sli3_ring[i];
4211 pring->sli.sli3.rspidx = 0;
4212 pring->sli.sli3.next_cmdidx = 0;
4213 pring->sli.sli3.local_getidx = 0;
4214 pring->sli.sli3.cmdidx = 0;
4215 pring->missbufcnt = 0;
4218 phba->link_state = LPFC_WARM_START;
4223 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4224 * @phba: Pointer to HBA context object.
4226 * This function resets a SLI4 HBA. This function disables PCI layer parity
4227 * checking during resets the device. The caller is not required to hold
4230 * This function returns 0 always.
4233 lpfc_sli4_brdreset(struct lpfc_hba *phba)
4235 struct lpfc_sli *psli = &phba->sli;
4240 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4241 "0295 Reset HBA Data: x%x x%x x%x\n",
4242 phba->pport->port_state, psli->sli_flag,
4245 /* perform board reset */
4246 phba->fc_eventTag = 0;
4247 phba->link_events = 0;
4248 phba->pport->fc_myDID = 0;
4249 phba->pport->fc_prevDID = 0;
4251 spin_lock_irq(&phba->hbalock);
4252 psli->sli_flag &= ~(LPFC_PROCESS_LA);
4253 phba->fcf.fcf_flag = 0;
4254 spin_unlock_irq(&phba->hbalock);
4256 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4257 if (phba->hba_flag & HBA_FW_DUMP_OP) {
4258 phba->hba_flag &= ~HBA_FW_DUMP_OP;
4262 /* Now physically reset the device */
4263 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4264 "0389 Performing PCI function reset!\n");
4266 /* Turn off parity checking and serr during the physical reset */
4267 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
4268 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
4269 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4271 /* Perform FCoE PCI function reset before freeing queue memory */
4272 rc = lpfc_pci_function_reset(phba);
4273 lpfc_sli4_queue_destroy(phba);
4275 /* Restore PCI cmd register */
4276 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4282 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4283 * @phba: Pointer to HBA context object.
4285 * This function is called in the SLI initialization code path to
4286 * restart the HBA. The caller is not required to hold any lock.
4287 * This function writes MBX_RESTART mailbox command to the SLIM and
4288 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4289 * function to free any pending commands. The function enables
4290 * POST only during the first initialization. The function returns zero.
4291 * The function does not guarantee completion of MBX_RESTART mailbox
4292 * command before the return of this function.
4295 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
4298 struct lpfc_sli *psli;
4299 volatile uint32_t word0;
4300 void __iomem *to_slim;
4301 uint32_t hba_aer_enabled;
4303 spin_lock_irq(&phba->hbalock);
4305 /* Take PCIe device Advanced Error Reporting (AER) state */
4306 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4311 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4312 "0337 Restart HBA Data: x%x x%x\n",
4313 phba->pport->port_state, psli->sli_flag);
4316 mb = (MAILBOX_t *) &word0;
4317 mb->mbxCommand = MBX_RESTART;
4320 lpfc_reset_barrier(phba);
4322 to_slim = phba->MBslimaddr;
4323 writel(*(uint32_t *) mb, to_slim);
4324 readl(to_slim); /* flush */
4326 /* Only skip post after fc_ffinit is completed */
4327 if (phba->pport->port_state)
4328 word0 = 1; /* This is really setting up word1 */
4330 word0 = 0; /* This is really setting up word1 */
4331 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4332 writel(*(uint32_t *) mb, to_slim);
4333 readl(to_slim); /* flush */
4335 lpfc_sli_brdreset(phba);
4336 phba->pport->stopped = 0;
4337 phba->link_state = LPFC_INIT_START;
4339 spin_unlock_irq(&phba->hbalock);
4341 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4342 psli->stats_start = get_seconds();
4344 /* Give the INITFF and Post time to settle. */
4347 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4348 if (hba_aer_enabled)
4349 pci_disable_pcie_error_reporting(phba->pcidev);
4351 lpfc_hba_down_post(phba);
4357 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4358 * @phba: Pointer to HBA context object.
4360 * This function is called in the SLI initialization code path to restart
4361 * a SLI4 HBA. The caller is not required to hold any lock.
4362 * At the end of the function, it calls lpfc_hba_down_post function to
4363 * free any pending commands.
4366 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
4368 struct lpfc_sli *psli = &phba->sli;
4369 uint32_t hba_aer_enabled;
4373 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4374 "0296 Restart HBA Data: x%x x%x\n",
4375 phba->pport->port_state, psli->sli_flag);
4377 /* Take PCIe device Advanced Error Reporting (AER) state */
4378 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4380 rc = lpfc_sli4_brdreset(phba);
4382 spin_lock_irq(&phba->hbalock);
4383 phba->pport->stopped = 0;
4384 phba->link_state = LPFC_INIT_START;
4386 spin_unlock_irq(&phba->hbalock);
4388 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4389 psli->stats_start = get_seconds();
4391 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4392 if (hba_aer_enabled)
4393 pci_disable_pcie_error_reporting(phba->pcidev);
4395 lpfc_hba_down_post(phba);
4401 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4402 * @phba: Pointer to HBA context object.
4404 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4405 * API jump table function pointer from the lpfc_hba struct.
4408 lpfc_sli_brdrestart(struct lpfc_hba *phba)
4410 return phba->lpfc_sli_brdrestart(phba);
4414 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4415 * @phba: Pointer to HBA context object.
4417 * This function is called after a HBA restart to wait for successful
4418 * restart of the HBA. Successful restart of the HBA is indicated by
4419 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4420 * iteration, the function will restart the HBA again. The function returns
4421 * zero if HBA successfully restarted else returns negative error code.
4424 lpfc_sli_chipset_init(struct lpfc_hba *phba)
4426 uint32_t status, i = 0;
4428 /* Read the HBA Host Status Register */
4429 if (lpfc_readl(phba->HSregaddr, &status))
4432 /* Check status register to see what current state is */
4434 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4436 /* Check every 10ms for 10 retries, then every 100ms for 90
4437 * retries, then every 1 sec for 50 retires for a total of
4438 * ~60 seconds before reset the board again and check every
4439 * 1 sec for 50 retries. The up to 60 seconds before the
4440 * board ready is required by the Falcon FIPS zeroization
4441 * complete, and any reset the board in between shall cause
4442 * restart of zeroization, further delay the board ready.
4445 /* Adapter failed to init, timeout, status reg
4447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4448 "0436 Adapter failed to init, "
4449 "timeout, status reg x%x, "
4450 "FW Data: A8 x%x AC x%x\n", status,
4451 readl(phba->MBslimaddr + 0xa8),
4452 readl(phba->MBslimaddr + 0xac));
4453 phba->link_state = LPFC_HBA_ERROR;
4457 /* Check to see if any errors occurred during init */
4458 if (status & HS_FFERM) {
4459 /* ERROR: During chipset initialization */
4460 /* Adapter failed to init, chipset, status reg
4462 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4463 "0437 Adapter failed to init, "
4464 "chipset, status reg x%x, "
4465 "FW Data: A8 x%x AC x%x\n", status,
4466 readl(phba->MBslimaddr + 0xa8),
4467 readl(phba->MBslimaddr + 0xac));
4468 phba->link_state = LPFC_HBA_ERROR;
4481 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4482 lpfc_sli_brdrestart(phba);
4484 /* Read the HBA Host Status Register */
4485 if (lpfc_readl(phba->HSregaddr, &status))
4489 /* Check to see if any errors occurred during init */
4490 if (status & HS_FFERM) {
4491 /* ERROR: During chipset initialization */
4492 /* Adapter failed to init, chipset, status reg <status> */
4493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4494 "0438 Adapter failed to init, chipset, "
4496 "FW Data: A8 x%x AC x%x\n", status,
4497 readl(phba->MBslimaddr + 0xa8),
4498 readl(phba->MBslimaddr + 0xac));
4499 phba->link_state = LPFC_HBA_ERROR;
4503 /* Clear all interrupt enable conditions */
4504 writel(0, phba->HCregaddr);
4505 readl(phba->HCregaddr); /* flush */
4507 /* setup host attn register */
4508 writel(0xffffffff, phba->HAregaddr);
4509 readl(phba->HAregaddr); /* flush */
4514 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4516 * This function calculates and returns the number of HBQs required to be
4520 lpfc_sli_hbq_count(void)
4522 return ARRAY_SIZE(lpfc_hbq_defs);
4526 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4528 * This function adds the number of hbq entries in every HBQ to get
4529 * the total number of hbq entries required for the HBA and returns
4533 lpfc_sli_hbq_entry_count(void)
4535 int hbq_count = lpfc_sli_hbq_count();
4539 for (i = 0; i < hbq_count; ++i)
4540 count += lpfc_hbq_defs[i]->entry_count;
4545 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4547 * This function calculates amount of memory required for all hbq entries
4548 * to be configured and returns the total memory required.
4551 lpfc_sli_hbq_size(void)
4553 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
4557 * lpfc_sli_hbq_setup - configure and initialize HBQs
4558 * @phba: Pointer to HBA context object.
4560 * This function is called during the SLI initialization to configure
4561 * all the HBQs and post buffers to the HBQ. The caller is not
4562 * required to hold any locks. This function will return zero if successful
4563 * else it will return negative error code.
4566 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
4568 int hbq_count = lpfc_sli_hbq_count();
4572 uint32_t hbq_entry_index;
4574 /* Get a Mailbox buffer to setup mailbox
4575 * commands for HBA initialization
4577 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4584 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4585 phba->link_state = LPFC_INIT_MBX_CMDS;
4586 phba->hbq_in_use = 1;
4588 hbq_entry_index = 0;
4589 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
4590 phba->hbqs[hbqno].next_hbqPutIdx = 0;
4591 phba->hbqs[hbqno].hbqPutIdx = 0;
4592 phba->hbqs[hbqno].local_hbqGetIdx = 0;
4593 phba->hbqs[hbqno].entry_count =
4594 lpfc_hbq_defs[hbqno]->entry_count;
4595 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
4596 hbq_entry_index, pmb);
4597 hbq_entry_index += phba->hbqs[hbqno].entry_count;
4599 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
4600 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4601 mbxStatus <status>, ring <num> */
4603 lpfc_printf_log(phba, KERN_ERR,
4604 LOG_SLI | LOG_VPORT,
4605 "1805 Adapter failed to init. "
4606 "Data: x%x x%x x%x\n",
4608 pmbox->mbxStatus, hbqno);
4610 phba->link_state = LPFC_HBA_ERROR;
4611 mempool_free(pmb, phba->mbox_mem_pool);
4615 phba->hbq_count = hbq_count;
4617 mempool_free(pmb, phba->mbox_mem_pool);
4619 /* Initially populate or replenish the HBQs */
4620 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
4621 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
4626 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4627 * @phba: Pointer to HBA context object.
4629 * This function is called during the SLI initialization to configure
4630 * all the HBQs and post buffers to the HBQ. The caller is not
4631 * required to hold any locks. This function will return zero if successful
4632 * else it will return negative error code.
4635 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
4637 phba->hbq_in_use = 1;
4638 phba->hbqs[LPFC_ELS_HBQ].entry_count =
4639 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
4640 phba->hbq_count = 1;
4641 lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
4642 /* Initially populate or replenish the HBQs */
4647 * lpfc_sli_config_port - Issue config port mailbox command
4648 * @phba: Pointer to HBA context object.
4649 * @sli_mode: sli mode - 2/3
4651 * This function is called by the sli intialization code path
4652 * to issue config_port mailbox command. This function restarts the
4653 * HBA firmware and issues a config_port mailbox command to configure
4654 * the SLI interface in the sli mode specified by sli_mode
4655 * variable. The caller is not required to hold any locks.
4656 * The function returns 0 if successful, else returns negative error
4660 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
4663 uint32_t resetcount = 0, rc = 0, done = 0;
4665 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4667 phba->link_state = LPFC_HBA_ERROR;
4671 phba->sli_rev = sli_mode;
4672 while (resetcount < 2 && !done) {
4673 spin_lock_irq(&phba->hbalock);
4674 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4675 spin_unlock_irq(&phba->hbalock);
4676 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4677 lpfc_sli_brdrestart(phba);
4678 rc = lpfc_sli_chipset_init(phba);
4682 spin_lock_irq(&phba->hbalock);
4683 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4684 spin_unlock_irq(&phba->hbalock);
4687 /* Call pre CONFIG_PORT mailbox command initialization. A
4688 * value of 0 means the call was successful. Any other
4689 * nonzero value is a failure, but if ERESTART is returned,
4690 * the driver may reset the HBA and try again.
4692 rc = lpfc_config_port_prep(phba);
4693 if (rc == -ERESTART) {
4694 phba->link_state = LPFC_LINK_UNKNOWN;
4699 phba->link_state = LPFC_INIT_MBX_CMDS;
4700 lpfc_config_port(phba, pmb);
4701 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4702 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
4703 LPFC_SLI3_HBQ_ENABLED |
4704 LPFC_SLI3_CRP_ENABLED |
4705 LPFC_SLI3_BG_ENABLED |
4706 LPFC_SLI3_DSS_ENABLED);
4707 if (rc != MBX_SUCCESS) {
4708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4709 "0442 Adapter failed to init, mbxCmd x%x "
4710 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4711 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
4712 spin_lock_irq(&phba->hbalock);
4713 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
4714 spin_unlock_irq(&phba->hbalock);
4717 /* Allow asynchronous mailbox command to go through */
4718 spin_lock_irq(&phba->hbalock);
4719 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4720 spin_unlock_irq(&phba->hbalock);
4723 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
4724 (pmb->u.mb.un.varCfgPort.gasabt == 0))
4725 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4726 "3110 Port did not grant ASABT\n");
4731 goto do_prep_failed;
4733 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
4734 if (!pmb->u.mb.un.varCfgPort.cMA) {
4736 goto do_prep_failed;
4738 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
4739 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
4740 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
4741 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
4742 phba->max_vpi : phba->max_vports;
4746 phba->fips_level = 0;
4747 phba->fips_spec_rev = 0;
4748 if (pmb->u.mb.un.varCfgPort.gdss) {
4749 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
4750 phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
4751 phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
4752 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4753 "2850 Security Crypto Active. FIPS x%d "
4755 phba->fips_level, phba->fips_spec_rev);
4757 if (pmb->u.mb.un.varCfgPort.sec_err) {
4758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4759 "2856 Config Port Security Crypto "
4761 pmb->u.mb.un.varCfgPort.sec_err);
4763 if (pmb->u.mb.un.varCfgPort.gerbm)
4764 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
4765 if (pmb->u.mb.un.varCfgPort.gcrp)
4766 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
4768 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
4769 phba->port_gp = phba->mbox->us.s3_pgp.port;
4771 if (phba->cfg_enable_bg) {
4772 if (pmb->u.mb.un.varCfgPort.gbg)
4773 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
4775 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4776 "0443 Adapter did not grant "
4780 phba->hbq_get = NULL;
4781 phba->port_gp = phba->mbox->us.s2.port;
4785 mempool_free(pmb, phba->mbox_mem_pool);
4791 * lpfc_sli_hba_setup - SLI intialization function
4792 * @phba: Pointer to HBA context object.
4794 * This function is the main SLI intialization function. This function
4795 * is called by the HBA intialization code, HBA reset code and HBA
4796 * error attention handler code. Caller is not required to hold any
4797 * locks. This function issues config_port mailbox command to configure
4798 * the SLI, setup iocb rings and HBQ rings. In the end the function
4799 * calls the config_port_post function to issue init_link mailbox
4800 * command and to start the discovery. The function will return zero
4801 * if successful, else it will return negative error code.
4804 lpfc_sli_hba_setup(struct lpfc_hba *phba)
4810 switch (phba->cfg_sli_mode) {
4812 if (phba->cfg_enable_npiv) {
4813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4814 "1824 NPIV enabled: Override sli_mode "
4815 "parameter (%d) to auto (0).\n",
4816 phba->cfg_sli_mode);
4825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4826 "1819 Unrecognized sli_mode parameter: %d.\n",
4827 phba->cfg_sli_mode);
4831 phba->fcp_embed_io = 0; /* SLI4 FC support only */
4833 rc = lpfc_sli_config_port(phba, mode);
4835 if (rc && phba->cfg_sli_mode == 3)
4836 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
4837 "1820 Unable to select SLI-3. "
4838 "Not supported by adapter.\n");
4839 if (rc && mode != 2)
4840 rc = lpfc_sli_config_port(phba, 2);
4841 else if (rc && mode == 2)
4842 rc = lpfc_sli_config_port(phba, 3);
4844 goto lpfc_sli_hba_setup_error;
4846 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4847 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
4848 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4850 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4851 "2709 This device supports "
4852 "Advanced Error Reporting (AER)\n");
4853 spin_lock_irq(&phba->hbalock);
4854 phba->hba_flag |= HBA_AER_ENABLED;
4855 spin_unlock_irq(&phba->hbalock);
4857 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4858 "2708 This device does not support "
4859 "Advanced Error Reporting (AER): %d\n",
4861 phba->cfg_aer_support = 0;
4865 if (phba->sli_rev == 3) {
4866 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
4867 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
4869 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
4870 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
4871 phba->sli3_options = 0;
4874 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4875 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4876 phba->sli_rev, phba->max_vpi);
4877 rc = lpfc_sli_ring_map(phba);
4880 goto lpfc_sli_hba_setup_error;
4882 /* Initialize VPIs. */
4883 if (phba->sli_rev == LPFC_SLI_REV3) {
4885 * The VPI bitmask and physical ID array are allocated
4886 * and initialized once only - at driver load. A port
4887 * reset doesn't need to reinitialize this memory.
4889 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
4890 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
4891 phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long),
4893 if (!phba->vpi_bmask) {
4895 goto lpfc_sli_hba_setup_error;
4898 phba->vpi_ids = kzalloc(
4899 (phba->max_vpi+1) * sizeof(uint16_t),
4901 if (!phba->vpi_ids) {
4902 kfree(phba->vpi_bmask);
4904 goto lpfc_sli_hba_setup_error;
4906 for (i = 0; i < phba->max_vpi; i++)
4907 phba->vpi_ids[i] = i;
4912 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4913 rc = lpfc_sli_hbq_setup(phba);
4915 goto lpfc_sli_hba_setup_error;
4917 spin_lock_irq(&phba->hbalock);
4918 phba->sli.sli_flag |= LPFC_PROCESS_LA;
4919 spin_unlock_irq(&phba->hbalock);
4921 rc = lpfc_config_port_post(phba);
4923 goto lpfc_sli_hba_setup_error;
4927 lpfc_sli_hba_setup_error:
4928 phba->link_state = LPFC_HBA_ERROR;
4929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4930 "0445 Firmware initialization failed\n");
4935 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4936 * @phba: Pointer to HBA context object.
4937 * @mboxq: mailbox pointer.
4938 * This function issue a dump mailbox command to read config region
4939 * 23 and parse the records in the region and populate driver
4943 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
4945 LPFC_MBOXQ_t *mboxq;
4946 struct lpfc_dmabuf *mp;
4947 struct lpfc_mqe *mqe;
4948 uint32_t data_length;
4951 /* Program the default value of vlan_id and fc_map */
4952 phba->valid_vlan = 0;
4953 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
4954 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4955 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4957 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4961 mqe = &mboxq->u.mqe;
4962 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
4964 goto out_free_mboxq;
4967 mp = (struct lpfc_dmabuf *) mboxq->context1;
4968 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4970 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
4971 "(%d):2571 Mailbox cmd x%x Status x%x "
4972 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4973 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4974 "CQ: x%x x%x x%x x%x\n",
4975 mboxq->vport ? mboxq->vport->vpi : 0,
4976 bf_get(lpfc_mqe_command, mqe),
4977 bf_get(lpfc_mqe_status, mqe),
4978 mqe->un.mb_words[0], mqe->un.mb_words[1],
4979 mqe->un.mb_words[2], mqe->un.mb_words[3],
4980 mqe->un.mb_words[4], mqe->un.mb_words[5],
4981 mqe->un.mb_words[6], mqe->un.mb_words[7],
4982 mqe->un.mb_words[8], mqe->un.mb_words[9],
4983 mqe->un.mb_words[10], mqe->un.mb_words[11],
4984 mqe->un.mb_words[12], mqe->un.mb_words[13],
4985 mqe->un.mb_words[14], mqe->un.mb_words[15],
4986 mqe->un.mb_words[16], mqe->un.mb_words[50],
4988 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
4989 mboxq->mcqe.trailer);
4992 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4995 goto out_free_mboxq;
4997 data_length = mqe->un.mb_words[5];
4998 if (data_length > DMP_RGN23_SIZE) {
4999 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5002 goto out_free_mboxq;
5005 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
5006 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5011 mempool_free(mboxq, phba->mbox_mem_pool);
5016 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5017 * @phba: pointer to lpfc hba data structure.
5018 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5019 * @vpd: pointer to the memory to hold resulting port vpd data.
5020 * @vpd_size: On input, the number of bytes allocated to @vpd.
5021 * On output, the number of data bytes in @vpd.
5023 * This routine executes a READ_REV SLI4 mailbox command. In
5024 * addition, this routine gets the port vpd data.
5028 * -ENOMEM - could not allocated memory.
5031 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5032 uint8_t *vpd, uint32_t *vpd_size)
5036 struct lpfc_dmabuf *dmabuf;
5037 struct lpfc_mqe *mqe;
5039 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5044 * Get a DMA buffer for the vpd data resulting from the READ_REV
5047 dma_size = *vpd_size;
5048 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, dma_size,
5049 &dmabuf->phys, GFP_KERNEL);
5050 if (!dmabuf->virt) {
5056 * The SLI4 implementation of READ_REV conflicts at word1,
5057 * bits 31:16 and SLI4 adds vpd functionality not present
5058 * in SLI3. This code corrects the conflicts.
5060 lpfc_read_rev(phba, mboxq);
5061 mqe = &mboxq->u.mqe;
5062 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
5063 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
5064 mqe->un.read_rev.word1 &= 0x0000FFFF;
5065 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
5066 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
5068 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5070 dma_free_coherent(&phba->pcidev->dev, dma_size,
5071 dmabuf->virt, dmabuf->phys);
5077 * The available vpd length cannot be bigger than the
5078 * DMA buffer passed to the port. Catch the less than
5079 * case and update the caller's size.
5081 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
5082 *vpd_size = mqe->un.read_rev.avail_vpd_len;
5084 memcpy(vpd, dmabuf->virt, *vpd_size);
5086 dma_free_coherent(&phba->pcidev->dev, dma_size,
5087 dmabuf->virt, dmabuf->phys);
5093 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5094 * @phba: pointer to lpfc hba data structure.
5096 * This routine retrieves SLI4 device physical port name this PCI function
5101 * otherwise - failed to retrieve physical port name
5104 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
5106 LPFC_MBOXQ_t *mboxq;
5107 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
5108 struct lpfc_controller_attribute *cntl_attr;
5109 struct lpfc_mbx_get_port_name *get_port_name;
5110 void *virtaddr = NULL;
5111 uint32_t alloclen, reqlen;
5112 uint32_t shdr_status, shdr_add_status;
5113 union lpfc_sli4_cfg_shdr *shdr;
5114 char cport_name = 0;
5117 /* We assume nothing at this point */
5118 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5119 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
5121 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5124 /* obtain link type and link number via READ_CONFIG */
5125 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5126 lpfc_sli4_read_config(phba);
5127 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
5128 goto retrieve_ppname;
5130 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5131 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
5132 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5133 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
5134 LPFC_SLI4_MBX_NEMBED);
5135 if (alloclen < reqlen) {
5136 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5137 "3084 Allocated DMA memory size (%d) is "
5138 "less than the requested DMA memory size "
5139 "(%d)\n", alloclen, reqlen);
5141 goto out_free_mboxq;
5143 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5144 virtaddr = mboxq->sge_array->addr[0];
5145 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
5146 shdr = &mbx_cntl_attr->cfg_shdr;
5147 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5148 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5149 if (shdr_status || shdr_add_status || rc) {
5150 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5151 "3085 Mailbox x%x (x%x/x%x) failed, "
5152 "rc:x%x, status:x%x, add_status:x%x\n",
5153 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5154 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5155 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5156 rc, shdr_status, shdr_add_status);
5158 goto out_free_mboxq;
5160 cntl_attr = &mbx_cntl_attr->cntl_attr;
5161 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
5162 phba->sli4_hba.lnk_info.lnk_tp =
5163 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
5164 phba->sli4_hba.lnk_info.lnk_no =
5165 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
5166 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5167 "3086 lnk_type:%d, lnk_numb:%d\n",
5168 phba->sli4_hba.lnk_info.lnk_tp,
5169 phba->sli4_hba.lnk_info.lnk_no);
5172 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5173 LPFC_MBOX_OPCODE_GET_PORT_NAME,
5174 sizeof(struct lpfc_mbx_get_port_name) -
5175 sizeof(struct lpfc_sli4_cfg_mhdr),
5176 LPFC_SLI4_MBX_EMBED);
5177 get_port_name = &mboxq->u.mqe.un.get_port_name;
5178 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
5179 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
5180 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
5181 phba->sli4_hba.lnk_info.lnk_tp);
5182 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5183 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5184 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5185 if (shdr_status || shdr_add_status || rc) {
5186 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5187 "3087 Mailbox x%x (x%x/x%x) failed: "
5188 "rc:x%x, status:x%x, add_status:x%x\n",
5189 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5190 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5191 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5192 rc, shdr_status, shdr_add_status);
5194 goto out_free_mboxq;
5196 switch (phba->sli4_hba.lnk_info.lnk_no) {
5197 case LPFC_LINK_NUMBER_0:
5198 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
5199 &get_port_name->u.response);
5200 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5202 case LPFC_LINK_NUMBER_1:
5203 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
5204 &get_port_name->u.response);
5205 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5207 case LPFC_LINK_NUMBER_2:
5208 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
5209 &get_port_name->u.response);
5210 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5212 case LPFC_LINK_NUMBER_3:
5213 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
5214 &get_port_name->u.response);
5215 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5221 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
5222 phba->Port[0] = cport_name;
5223 phba->Port[1] = '\0';
5224 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5225 "3091 SLI get port name: %s\n", phba->Port);
5229 if (rc != MBX_TIMEOUT) {
5230 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5231 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5233 mempool_free(mboxq, phba->mbox_mem_pool);
5239 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5240 * @phba: pointer to lpfc hba data structure.
5242 * This routine is called to explicitly arm the SLI4 device's completion and
5246 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
5250 lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM);
5251 lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM);
5252 if (phba->sli4_hba.nvmels_cq)
5253 lpfc_sli4_cq_release(phba->sli4_hba.nvmels_cq,
5256 if (phba->sli4_hba.fcp_cq)
5257 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
5258 lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[qidx],
5261 if (phba->sli4_hba.nvme_cq)
5262 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
5263 lpfc_sli4_cq_release(phba->sli4_hba.nvme_cq[qidx],
5267 lpfc_sli4_cq_release(phba->sli4_hba.oas_cq, LPFC_QUEUE_REARM);
5269 if (phba->sli4_hba.hba_eq)
5270 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
5271 lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[qidx],
5275 lpfc_sli4_eq_release(phba->sli4_hba.fof_eq, LPFC_QUEUE_REARM);
5279 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5280 * @phba: Pointer to HBA context object.
5281 * @type: The resource extent type.
5282 * @extnt_count: buffer to hold port available extent count.
5283 * @extnt_size: buffer to hold element count per extent.
5285 * This function calls the port and retrievs the number of available
5286 * extents and their size for a particular extent type.
5288 * Returns: 0 if successful. Nonzero otherwise.
5291 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
5292 uint16_t *extnt_count, uint16_t *extnt_size)
5297 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
5300 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5304 /* Find out how many extents are available for this resource type */
5305 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
5306 sizeof(struct lpfc_sli4_cfg_mhdr));
5307 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5308 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
5309 length, LPFC_SLI4_MBX_EMBED);
5311 /* Send an extents count of 0 - the GET doesn't use it. */
5312 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5313 LPFC_SLI4_MBX_EMBED);
5319 if (!phba->sli4_hba.intr_enable)
5320 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5322 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5323 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5330 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
5331 if (bf_get(lpfc_mbox_hdr_status,
5332 &rsrc_info->header.cfg_shdr.response)) {
5333 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5334 "2930 Failed to get resource extents "
5335 "Status 0x%x Add'l Status 0x%x\n",
5336 bf_get(lpfc_mbox_hdr_status,
5337 &rsrc_info->header.cfg_shdr.response),
5338 bf_get(lpfc_mbox_hdr_add_status,
5339 &rsrc_info->header.cfg_shdr.response));
5344 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
5346 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
5349 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5350 "3162 Retrieved extents type-%d from port: count:%d, "
5351 "size:%d\n", type, *extnt_count, *extnt_size);
5354 mempool_free(mbox, phba->mbox_mem_pool);
5359 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5360 * @phba: Pointer to HBA context object.
5361 * @type: The extent type to check.
5363 * This function reads the current available extents from the port and checks
5364 * if the extent count or extent size has changed since the last access.
5365 * Callers use this routine post port reset to understand if there is a
5366 * extent reprovisioning requirement.
5369 * -Error: error indicates problem.
5370 * 1: Extent count or size has changed.
5374 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
5376 uint16_t curr_ext_cnt, rsrc_ext_cnt;
5377 uint16_t size_diff, rsrc_ext_size;
5379 struct lpfc_rsrc_blks *rsrc_entry;
5380 struct list_head *rsrc_blk_list = NULL;
5384 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5391 case LPFC_RSC_TYPE_FCOE_RPI:
5392 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5394 case LPFC_RSC_TYPE_FCOE_VPI:
5395 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
5397 case LPFC_RSC_TYPE_FCOE_XRI:
5398 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5400 case LPFC_RSC_TYPE_FCOE_VFI:
5401 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5407 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
5409 if (rsrc_entry->rsrc_size != rsrc_ext_size)
5413 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
5420 * lpfc_sli4_cfg_post_extnts -
5421 * @phba: Pointer to HBA context object.
5422 * @extnt_cnt - number of available extents.
5423 * @type - the extent type (rpi, xri, vfi, vpi).
5424 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5425 * @mbox - pointer to the caller's allocated mailbox structure.
5427 * This function executes the extents allocation request. It also
5428 * takes care of the amount of memory needed to allocate or get the
5429 * allocated extents. It is the caller's responsibility to evaluate
5433 * -Error: Error value describes the condition found.
5437 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
5438 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
5443 uint32_t alloc_len, mbox_tmo;
5445 /* Calculate the total requested length of the dma memory */
5446 req_len = extnt_cnt * sizeof(uint16_t);
5449 * Calculate the size of an embedded mailbox. The uint32_t
5450 * accounts for extents-specific word.
5452 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5456 * Presume the allocation and response will fit into an embedded
5457 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5459 *emb = LPFC_SLI4_MBX_EMBED;
5460 if (req_len > emb_len) {
5461 req_len = extnt_cnt * sizeof(uint16_t) +
5462 sizeof(union lpfc_sli4_cfg_shdr) +
5464 *emb = LPFC_SLI4_MBX_NEMBED;
5467 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5468 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
5470 if (alloc_len < req_len) {
5471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5472 "2982 Allocated DMA memory size (x%x) is "
5473 "less than the requested DMA memory "
5474 "size (x%x)\n", alloc_len, req_len);
5477 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
5481 if (!phba->sli4_hba.intr_enable)
5482 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5484 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5485 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5494 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5495 * @phba: Pointer to HBA context object.
5496 * @type: The resource extent type to allocate.
5498 * This function allocates the number of elements for the specified
5502 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
5505 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
5506 uint16_t rsrc_id, rsrc_start, j, k;
5509 unsigned long longs;
5510 unsigned long *bmask;
5511 struct lpfc_rsrc_blks *rsrc_blks;
5514 struct lpfc_id_range *id_array = NULL;
5515 void *virtaddr = NULL;
5516 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5517 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5518 struct list_head *ext_blk_list;
5520 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5526 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
5527 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5528 "3009 No available Resource Extents "
5529 "for resource type 0x%x: Count: 0x%x, "
5530 "Size 0x%x\n", type, rsrc_cnt,
5535 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
5536 "2903 Post resource extents type-0x%x: "
5537 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
5539 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5543 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
5550 * Figure out where the response is located. Then get local pointers
5551 * to the response data. The port does not guarantee to respond to
5552 * all extents counts request so update the local variable with the
5553 * allocated count from the port.
5555 if (emb == LPFC_SLI4_MBX_EMBED) {
5556 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
5557 id_array = &rsrc_ext->u.rsp.id[0];
5558 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
5560 virtaddr = mbox->sge_array->addr[0];
5561 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
5562 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
5563 id_array = &n_rsrc->id;
5566 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
5567 rsrc_id_cnt = rsrc_cnt * rsrc_size;
5570 * Based on the resource size and count, correct the base and max
5573 length = sizeof(struct lpfc_rsrc_blks);
5575 case LPFC_RSC_TYPE_FCOE_RPI:
5576 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5577 sizeof(unsigned long),
5579 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5583 phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt *
5586 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5587 kfree(phba->sli4_hba.rpi_bmask);
5593 * The next_rpi was initialized with the maximum available
5594 * count but the port may allocate a smaller number. Catch
5595 * that case and update the next_rpi.
5597 phba->sli4_hba.next_rpi = rsrc_id_cnt;
5599 /* Initialize local ptrs for common extent processing later. */
5600 bmask = phba->sli4_hba.rpi_bmask;
5601 ids = phba->sli4_hba.rpi_ids;
5602 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5604 case LPFC_RSC_TYPE_FCOE_VPI:
5605 phba->vpi_bmask = kzalloc(longs *
5606 sizeof(unsigned long),
5608 if (unlikely(!phba->vpi_bmask)) {
5612 phba->vpi_ids = kzalloc(rsrc_id_cnt *
5615 if (unlikely(!phba->vpi_ids)) {
5616 kfree(phba->vpi_bmask);
5621 /* Initialize local ptrs for common extent processing later. */
5622 bmask = phba->vpi_bmask;
5623 ids = phba->vpi_ids;
5624 ext_blk_list = &phba->lpfc_vpi_blk_list;
5626 case LPFC_RSC_TYPE_FCOE_XRI:
5627 phba->sli4_hba.xri_bmask = kzalloc(longs *
5628 sizeof(unsigned long),
5630 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5634 phba->sli4_hba.max_cfg_param.xri_used = 0;
5635 phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt *
5638 if (unlikely(!phba->sli4_hba.xri_ids)) {
5639 kfree(phba->sli4_hba.xri_bmask);
5644 /* Initialize local ptrs for common extent processing later. */
5645 bmask = phba->sli4_hba.xri_bmask;
5646 ids = phba->sli4_hba.xri_ids;
5647 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5649 case LPFC_RSC_TYPE_FCOE_VFI:
5650 phba->sli4_hba.vfi_bmask = kzalloc(longs *
5651 sizeof(unsigned long),
5653 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5657 phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt *
5660 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5661 kfree(phba->sli4_hba.vfi_bmask);
5666 /* Initialize local ptrs for common extent processing later. */
5667 bmask = phba->sli4_hba.vfi_bmask;
5668 ids = phba->sli4_hba.vfi_ids;
5669 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5672 /* Unsupported Opcode. Fail call. */
5676 ext_blk_list = NULL;
5681 * Complete initializing the extent configuration with the
5682 * allocated ids assigned to this function. The bitmask serves
5683 * as an index into the array and manages the available ids. The
5684 * array just stores the ids communicated to the port via the wqes.
5686 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
5688 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
5691 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
5694 rsrc_blks = kzalloc(length, GFP_KERNEL);
5695 if (unlikely(!rsrc_blks)) {
5701 rsrc_blks->rsrc_start = rsrc_id;
5702 rsrc_blks->rsrc_size = rsrc_size;
5703 list_add_tail(&rsrc_blks->list, ext_blk_list);
5704 rsrc_start = rsrc_id;
5705 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
5706 phba->sli4_hba.scsi_xri_start = rsrc_start +
5707 lpfc_sli4_get_iocb_cnt(phba);
5708 phba->sli4_hba.nvme_xri_start =
5709 phba->sli4_hba.scsi_xri_start +
5710 phba->sli4_hba.scsi_xri_max;
5713 while (rsrc_id < (rsrc_start + rsrc_size)) {
5718 /* Entire word processed. Get next word.*/
5723 lpfc_sli4_mbox_cmd_free(phba, mbox);
5730 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5731 * @phba: Pointer to HBA context object.
5732 * @type: the extent's type.
5734 * This function deallocates all extents of a particular resource type.
5735 * SLI4 does not allow for deallocating a particular extent range. It
5736 * is the caller's responsibility to release all kernel memory resources.
5739 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
5742 uint32_t length, mbox_tmo = 0;
5744 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
5745 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
5747 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5752 * This function sends an embedded mailbox because it only sends the
5753 * the resource type. All extents of this type are released by the
5756 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
5757 sizeof(struct lpfc_sli4_cfg_mhdr));
5758 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5759 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
5760 length, LPFC_SLI4_MBX_EMBED);
5762 /* Send an extents count of 0 - the dealloc doesn't use it. */
5763 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5764 LPFC_SLI4_MBX_EMBED);
5769 if (!phba->sli4_hba.intr_enable)
5770 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5772 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5773 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5780 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
5781 if (bf_get(lpfc_mbox_hdr_status,
5782 &dealloc_rsrc->header.cfg_shdr.response)) {
5783 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5784 "2919 Failed to release resource extents "
5785 "for type %d - Status 0x%x Add'l Status 0x%x. "
5786 "Resource memory not released.\n",
5788 bf_get(lpfc_mbox_hdr_status,
5789 &dealloc_rsrc->header.cfg_shdr.response),
5790 bf_get(lpfc_mbox_hdr_add_status,
5791 &dealloc_rsrc->header.cfg_shdr.response));
5796 /* Release kernel memory resources for the specific type. */
5798 case LPFC_RSC_TYPE_FCOE_VPI:
5799 kfree(phba->vpi_bmask);
5800 kfree(phba->vpi_ids);
5801 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5802 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5803 &phba->lpfc_vpi_blk_list, list) {
5804 list_del_init(&rsrc_blk->list);
5807 phba->sli4_hba.max_cfg_param.vpi_used = 0;
5809 case LPFC_RSC_TYPE_FCOE_XRI:
5810 kfree(phba->sli4_hba.xri_bmask);
5811 kfree(phba->sli4_hba.xri_ids);
5812 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5813 &phba->sli4_hba.lpfc_xri_blk_list, list) {
5814 list_del_init(&rsrc_blk->list);
5818 case LPFC_RSC_TYPE_FCOE_VFI:
5819 kfree(phba->sli4_hba.vfi_bmask);
5820 kfree(phba->sli4_hba.vfi_ids);
5821 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5822 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5823 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
5824 list_del_init(&rsrc_blk->list);
5828 case LPFC_RSC_TYPE_FCOE_RPI:
5829 /* RPI bitmask and physical id array are cleaned up earlier. */
5830 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
5831 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
5832 list_del_init(&rsrc_blk->list);
5840 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
5843 mempool_free(mbox, phba->mbox_mem_pool);
5848 lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
5853 len = sizeof(struct lpfc_mbx_set_feature) -
5854 sizeof(struct lpfc_sli4_cfg_mhdr);
5855 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5856 LPFC_MBOX_OPCODE_SET_FEATURES, len,
5857 LPFC_SLI4_MBX_EMBED);
5860 case LPFC_SET_UE_RECOVERY:
5861 bf_set(lpfc_mbx_set_feature_UER,
5862 &mbox->u.mqe.un.set_feature, 1);
5863 mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
5864 mbox->u.mqe.un.set_feature.param_len = 8;
5866 case LPFC_SET_MDS_DIAGS:
5867 bf_set(lpfc_mbx_set_feature_mds,
5868 &mbox->u.mqe.un.set_feature, 1);
5869 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
5870 &mbox->u.mqe.un.set_feature, 0);
5871 mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
5872 mbox->u.mqe.un.set_feature.param_len = 8;
5880 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5881 * @phba: Pointer to HBA context object.
5883 * This function allocates all SLI4 resource identifiers.
5886 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
5888 int i, rc, error = 0;
5889 uint16_t count, base;
5890 unsigned long longs;
5892 if (!phba->sli4_hba.rpi_hdrs_in_use)
5893 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
5894 if (phba->sli4_hba.extents_in_use) {
5896 * The port supports resource extents. The XRI, VPI, VFI, RPI
5897 * resource extent count must be read and allocated before
5898 * provisioning the resource id arrays.
5900 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5901 LPFC_IDX_RSRC_RDY) {
5903 * Extent-based resources are set - the driver could
5904 * be in a port reset. Figure out if any corrective
5905 * actions need to be taken.
5907 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5908 LPFC_RSC_TYPE_FCOE_VFI);
5911 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5912 LPFC_RSC_TYPE_FCOE_VPI);
5915 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5916 LPFC_RSC_TYPE_FCOE_XRI);
5919 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
5920 LPFC_RSC_TYPE_FCOE_RPI);
5925 * It's possible that the number of resources
5926 * provided to this port instance changed between
5927 * resets. Detect this condition and reallocate
5928 * resources. Otherwise, there is no action.
5931 lpfc_printf_log(phba, KERN_INFO,
5932 LOG_MBOX | LOG_INIT,
5933 "2931 Detected extent resource "
5934 "change. Reallocating all "
5936 rc = lpfc_sli4_dealloc_extent(phba,
5937 LPFC_RSC_TYPE_FCOE_VFI);
5938 rc = lpfc_sli4_dealloc_extent(phba,
5939 LPFC_RSC_TYPE_FCOE_VPI);
5940 rc = lpfc_sli4_dealloc_extent(phba,
5941 LPFC_RSC_TYPE_FCOE_XRI);
5942 rc = lpfc_sli4_dealloc_extent(phba,
5943 LPFC_RSC_TYPE_FCOE_RPI);
5948 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
5952 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
5956 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
5960 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
5963 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
5968 * The port does not support resource extents. The XRI, VPI,
5969 * VFI, RPI resource ids were determined from READ_CONFIG.
5970 * Just allocate the bitmasks and provision the resource id
5971 * arrays. If a port reset is active, the resources don't
5972 * need any action - just exit.
5974 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
5975 LPFC_IDX_RSRC_RDY) {
5976 lpfc_sli4_dealloc_resource_identifiers(phba);
5977 lpfc_sli4_remove_rpis(phba);
5980 count = phba->sli4_hba.max_cfg_param.max_rpi;
5982 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5983 "3279 Invalid provisioning of "
5988 base = phba->sli4_hba.max_cfg_param.rpi_base;
5989 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
5990 phba->sli4_hba.rpi_bmask = kzalloc(longs *
5991 sizeof(unsigned long),
5993 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5997 phba->sli4_hba.rpi_ids = kzalloc(count *
6000 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6002 goto free_rpi_bmask;
6005 for (i = 0; i < count; i++)
6006 phba->sli4_hba.rpi_ids[i] = base + i;
6009 count = phba->sli4_hba.max_cfg_param.max_vpi;
6011 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6012 "3280 Invalid provisioning of "
6017 base = phba->sli4_hba.max_cfg_param.vpi_base;
6018 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6019 phba->vpi_bmask = kzalloc(longs *
6020 sizeof(unsigned long),
6022 if (unlikely(!phba->vpi_bmask)) {
6026 phba->vpi_ids = kzalloc(count *
6029 if (unlikely(!phba->vpi_ids)) {
6031 goto free_vpi_bmask;
6034 for (i = 0; i < count; i++)
6035 phba->vpi_ids[i] = base + i;
6038 count = phba->sli4_hba.max_cfg_param.max_xri;
6040 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6041 "3281 Invalid provisioning of "
6046 base = phba->sli4_hba.max_cfg_param.xri_base;
6047 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6048 phba->sli4_hba.xri_bmask = kzalloc(longs *
6049 sizeof(unsigned long),
6051 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6055 phba->sli4_hba.max_cfg_param.xri_used = 0;
6056 phba->sli4_hba.xri_ids = kzalloc(count *
6059 if (unlikely(!phba->sli4_hba.xri_ids)) {
6061 goto free_xri_bmask;
6064 for (i = 0; i < count; i++)
6065 phba->sli4_hba.xri_ids[i] = base + i;
6068 count = phba->sli4_hba.max_cfg_param.max_vfi;
6070 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6071 "3282 Invalid provisioning of "
6076 base = phba->sli4_hba.max_cfg_param.vfi_base;
6077 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6078 phba->sli4_hba.vfi_bmask = kzalloc(longs *
6079 sizeof(unsigned long),
6081 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6085 phba->sli4_hba.vfi_ids = kzalloc(count *
6088 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6090 goto free_vfi_bmask;
6093 for (i = 0; i < count; i++)
6094 phba->sli4_hba.vfi_ids[i] = base + i;
6097 * Mark all resources ready. An HBA reset doesn't need
6098 * to reset the initialization.
6100 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6106 kfree(phba->sli4_hba.vfi_bmask);
6107 phba->sli4_hba.vfi_bmask = NULL;
6109 kfree(phba->sli4_hba.xri_ids);
6110 phba->sli4_hba.xri_ids = NULL;
6112 kfree(phba->sli4_hba.xri_bmask);
6113 phba->sli4_hba.xri_bmask = NULL;
6115 kfree(phba->vpi_ids);
6116 phba->vpi_ids = NULL;
6118 kfree(phba->vpi_bmask);
6119 phba->vpi_bmask = NULL;
6121 kfree(phba->sli4_hba.rpi_ids);
6122 phba->sli4_hba.rpi_ids = NULL;
6124 kfree(phba->sli4_hba.rpi_bmask);
6125 phba->sli4_hba.rpi_bmask = NULL;
6131 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6132 * @phba: Pointer to HBA context object.
6134 * This function allocates the number of elements for the specified
6138 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
6140 if (phba->sli4_hba.extents_in_use) {
6141 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
6142 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
6143 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
6144 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
6146 kfree(phba->vpi_bmask);
6147 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6148 kfree(phba->vpi_ids);
6149 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6150 kfree(phba->sli4_hba.xri_bmask);
6151 kfree(phba->sli4_hba.xri_ids);
6152 kfree(phba->sli4_hba.vfi_bmask);
6153 kfree(phba->sli4_hba.vfi_ids);
6154 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6155 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6162 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6163 * @phba: Pointer to HBA context object.
6164 * @type: The resource extent type.
6165 * @extnt_count: buffer to hold port extent count response
6166 * @extnt_size: buffer to hold port extent size response.
6168 * This function calls the port to read the host allocated extents
6169 * for a particular type.
6172 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
6173 uint16_t *extnt_cnt, uint16_t *extnt_size)
6177 uint16_t curr_blks = 0;
6178 uint32_t req_len, emb_len;
6179 uint32_t alloc_len, mbox_tmo;
6180 struct list_head *blk_list_head;
6181 struct lpfc_rsrc_blks *rsrc_blk;
6183 void *virtaddr = NULL;
6184 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
6185 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
6186 union lpfc_sli4_cfg_shdr *shdr;
6189 case LPFC_RSC_TYPE_FCOE_VPI:
6190 blk_list_head = &phba->lpfc_vpi_blk_list;
6192 case LPFC_RSC_TYPE_FCOE_XRI:
6193 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
6195 case LPFC_RSC_TYPE_FCOE_VFI:
6196 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
6198 case LPFC_RSC_TYPE_FCOE_RPI:
6199 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
6205 /* Count the number of extents currently allocatd for this type. */
6206 list_for_each_entry(rsrc_blk, blk_list_head, list) {
6207 if (curr_blks == 0) {
6209 * The GET_ALLOCATED mailbox does not return the size,
6210 * just the count. The size should be just the size
6211 * stored in the current allocated block and all sizes
6212 * for an extent type are the same so set the return
6215 *extnt_size = rsrc_blk->rsrc_size;
6221 * Calculate the size of an embedded mailbox. The uint32_t
6222 * accounts for extents-specific word.
6224 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
6228 * Presume the allocation and response will fit into an embedded
6229 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6231 emb = LPFC_SLI4_MBX_EMBED;
6233 if (req_len > emb_len) {
6234 req_len = curr_blks * sizeof(uint16_t) +
6235 sizeof(union lpfc_sli4_cfg_shdr) +
6237 emb = LPFC_SLI4_MBX_NEMBED;
6240 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6243 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
6245 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6246 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
6248 if (alloc_len < req_len) {
6249 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6250 "2983 Allocated DMA memory size (x%x) is "
6251 "less than the requested DMA memory "
6252 "size (x%x)\n", alloc_len, req_len);
6256 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
6262 if (!phba->sli4_hba.intr_enable)
6263 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6265 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6266 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6275 * Figure out where the response is located. Then get local pointers
6276 * to the response data. The port does not guarantee to respond to
6277 * all extents counts request so update the local variable with the
6278 * allocated count from the port.
6280 if (emb == LPFC_SLI4_MBX_EMBED) {
6281 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
6282 shdr = &rsrc_ext->header.cfg_shdr;
6283 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
6285 virtaddr = mbox->sge_array->addr[0];
6286 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6287 shdr = &n_rsrc->cfg_shdr;
6288 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6291 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
6292 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
6293 "2984 Failed to read allocated resources "
6294 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6296 bf_get(lpfc_mbox_hdr_status, &shdr->response),
6297 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
6302 lpfc_sli4_mbox_cmd_free(phba, mbox);
6307 * lpfc_sli4_repost_sgl_list - Repsot the buffers sgl pages as block
6308 * @phba: pointer to lpfc hba data structure.
6309 * @pring: Pointer to driver SLI ring object.
6310 * @sgl_list: linked link of sgl buffers to post
6311 * @cnt: number of linked list buffers
6313 * This routine walks the list of buffers that have been allocated and
6314 * repost them to the port by using SGL block post. This is needed after a
6315 * pci_function_reset/warm_start or start. It attempts to construct blocks
6316 * of buffer sgls which contains contiguous xris and uses the non-embedded
6317 * SGL block post mailbox commands to post them to the port. For single
6318 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6319 * mailbox command for posting.
6321 * Returns: 0 = success, non-zero failure.
6324 lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
6325 struct list_head *sgl_list, int cnt)
6327 struct lpfc_sglq *sglq_entry = NULL;
6328 struct lpfc_sglq *sglq_entry_next = NULL;
6329 struct lpfc_sglq *sglq_entry_first = NULL;
6330 int status, total_cnt;
6331 int post_cnt = 0, num_posted = 0, block_cnt = 0;
6332 int last_xritag = NO_XRI;
6333 LIST_HEAD(prep_sgl_list);
6334 LIST_HEAD(blck_sgl_list);
6335 LIST_HEAD(allc_sgl_list);
6336 LIST_HEAD(post_sgl_list);
6337 LIST_HEAD(free_sgl_list);
6339 spin_lock_irq(&phba->hbalock);
6340 spin_lock(&phba->sli4_hba.sgl_list_lock);
6341 list_splice_init(sgl_list, &allc_sgl_list);
6342 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6343 spin_unlock_irq(&phba->hbalock);
6346 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
6347 &allc_sgl_list, list) {
6348 list_del_init(&sglq_entry->list);
6350 if ((last_xritag != NO_XRI) &&
6351 (sglq_entry->sli4_xritag != last_xritag + 1)) {
6352 /* a hole in xri block, form a sgl posting block */
6353 list_splice_init(&prep_sgl_list, &blck_sgl_list);
6354 post_cnt = block_cnt - 1;
6355 /* prepare list for next posting block */
6356 list_add_tail(&sglq_entry->list, &prep_sgl_list);
6359 /* prepare list for next posting block */
6360 list_add_tail(&sglq_entry->list, &prep_sgl_list);
6361 /* enough sgls for non-embed sgl mbox command */
6362 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
6363 list_splice_init(&prep_sgl_list,
6365 post_cnt = block_cnt;
6371 /* keep track of last sgl's xritag */
6372 last_xritag = sglq_entry->sli4_xritag;
6374 /* end of repost sgl list condition for buffers */
6375 if (num_posted == total_cnt) {
6376 if (post_cnt == 0) {
6377 list_splice_init(&prep_sgl_list,
6379 post_cnt = block_cnt;
6380 } else if (block_cnt == 1) {
6381 status = lpfc_sli4_post_sgl(phba,
6382 sglq_entry->phys, 0,
6383 sglq_entry->sli4_xritag);
6385 /* successful, put sgl to posted list */
6386 list_add_tail(&sglq_entry->list,
6389 /* Failure, put sgl to free list */
6390 lpfc_printf_log(phba, KERN_WARNING,
6392 "3159 Failed to post "
6393 "sgl, xritag:x%x\n",
6394 sglq_entry->sli4_xritag);
6395 list_add_tail(&sglq_entry->list,
6402 /* continue until a nembed page worth of sgls */
6406 /* post the buffer list sgls as a block */
6407 status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
6411 /* success, put sgl list to posted sgl list */
6412 list_splice_init(&blck_sgl_list, &post_sgl_list);
6414 /* Failure, put sgl list to free sgl list */
6415 sglq_entry_first = list_first_entry(&blck_sgl_list,
6418 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6419 "3160 Failed to post sgl-list, "
6421 sglq_entry_first->sli4_xritag,
6422 (sglq_entry_first->sli4_xritag +
6424 list_splice_init(&blck_sgl_list, &free_sgl_list);
6425 total_cnt -= post_cnt;
6428 /* don't reset xirtag due to hole in xri block */
6430 last_xritag = NO_XRI;
6432 /* reset sgl post count for next round of posting */
6436 /* free the sgls failed to post */
6437 lpfc_free_sgl_list(phba, &free_sgl_list);
6439 /* push sgls posted to the available list */
6440 if (!list_empty(&post_sgl_list)) {
6441 spin_lock_irq(&phba->hbalock);
6442 spin_lock(&phba->sli4_hba.sgl_list_lock);
6443 list_splice_init(&post_sgl_list, sgl_list);
6444 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6445 spin_unlock_irq(&phba->hbalock);
6447 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6448 "3161 Failure to post sgl to port.\n");
6452 /* return the number of XRIs actually posted */
6457 lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
6461 len = sizeof(struct lpfc_mbx_set_host_data) -
6462 sizeof(struct lpfc_sli4_cfg_mhdr);
6463 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6464 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
6465 LPFC_SLI4_MBX_EMBED);
6467 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
6468 mbox->u.mqe.un.set_host_data.param_len =
6469 LPFC_HOST_OS_DRIVER_VERSION_SIZE;
6470 snprintf(mbox->u.mqe.un.set_host_data.data,
6471 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
6472 "Linux %s v"LPFC_DRIVER_VERSION,
6473 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
6477 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6478 * @phba: Pointer to HBA context object.
6480 * This function is the main SLI4 device intialization PCI function. This
6481 * function is called by the HBA intialization code, HBA reset code and
6482 * HBA error attention handler code. Caller is not required to hold any
6486 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
6489 LPFC_MBOXQ_t *mboxq;
6490 struct lpfc_mqe *mqe;
6493 uint32_t ftr_rsp = 0;
6494 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
6495 struct lpfc_vport *vport = phba->pport;
6496 struct lpfc_dmabuf *mp;
6498 /* Perform a PCI function reset to start from clean */
6499 rc = lpfc_pci_function_reset(phba);
6503 /* Check the HBA Host Status Register for readyness */
6504 rc = lpfc_sli4_post_status_check(phba);
6508 spin_lock_irq(&phba->hbalock);
6509 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
6510 spin_unlock_irq(&phba->hbalock);
6514 * Allocate a single mailbox container for initializing the
6517 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6521 /* Issue READ_REV to collect vpd and FW information. */
6522 vpd_size = SLI4_PAGE_SIZE;
6523 vpd = kzalloc(vpd_size, GFP_KERNEL);
6529 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
6535 mqe = &mboxq->u.mqe;
6536 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
6537 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
6538 phba->hba_flag |= HBA_FCOE_MODE;
6539 phba->fcp_embed_io = 0; /* SLI4 FC support only */
6541 phba->hba_flag &= ~HBA_FCOE_MODE;
6544 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
6546 phba->hba_flag |= HBA_FIP_SUPPORT;
6548 phba->hba_flag &= ~HBA_FIP_SUPPORT;
6550 phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH;
6552 if (phba->sli_rev != LPFC_SLI_REV4) {
6553 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6554 "0376 READ_REV Error. SLI Level %d "
6555 "FCoE enabled %d\n",
6556 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
6563 * Continue initialization with default values even if driver failed
6564 * to read FCoE param config regions, only read parameters if the
6567 if (phba->hba_flag & HBA_FCOE_MODE &&
6568 lpfc_sli4_read_fcoe_params(phba))
6569 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
6570 "2570 Failed to read FCoE parameters\n");
6573 * Retrieve sli4 device physical port name, failure of doing it
6574 * is considered as non-fatal.
6576 rc = lpfc_sli4_retrieve_pport_name(phba);
6578 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6579 "3080 Successful retrieving SLI4 device "
6580 "physical port name: %s.\n", phba->Port);
6583 * Evaluate the read rev and vpd data. Populate the driver
6584 * state with the results. If this routine fails, the failure
6585 * is not fatal as the driver will use generic values.
6587 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
6588 if (unlikely(!rc)) {
6589 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6590 "0377 Error %d parsing vpd. "
6591 "Using defaults.\n", rc);
6596 /* Save information as VPD data */
6597 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
6598 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
6599 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
6600 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
6602 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
6604 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
6606 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
6608 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
6609 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
6610 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
6611 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
6612 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
6613 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
6614 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
6615 "(%d):0380 READ_REV Status x%x "
6616 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6617 mboxq->vport ? mboxq->vport->vpi : 0,
6618 bf_get(lpfc_mqe_status, mqe),
6619 phba->vpd.rev.opFwName,
6620 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
6621 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
6623 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6624 rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3);
6625 if (phba->pport->cfg_lun_queue_depth > rc) {
6626 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6627 "3362 LUN queue depth changed from %d to %d\n",
6628 phba->pport->cfg_lun_queue_depth, rc);
6629 phba->pport->cfg_lun_queue_depth = rc;
6632 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6633 LPFC_SLI_INTF_IF_TYPE_0) {
6634 lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
6635 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6636 if (rc == MBX_SUCCESS) {
6637 phba->hba_flag |= HBA_RECOVERABLE_UE;
6638 /* Set 1Sec interval to detect UE */
6639 phba->eratt_poll_interval = 1;
6640 phba->sli4_hba.ue_to_sr = bf_get(
6641 lpfc_mbx_set_feature_UESR,
6642 &mboxq->u.mqe.un.set_feature);
6643 phba->sli4_hba.ue_to_rp = bf_get(
6644 lpfc_mbx_set_feature_UERP,
6645 &mboxq->u.mqe.un.set_feature);
6649 if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
6650 /* Enable MDS Diagnostics only if the SLI Port supports it */
6651 lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
6652 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6653 if (rc != MBX_SUCCESS)
6654 phba->mds_diags_support = 0;
6658 * Discover the port's supported feature set and match it against the
6661 lpfc_request_features(phba, mboxq);
6662 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6669 * The port must support FCP initiator mode as this is the
6670 * only mode running in the host.
6672 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
6673 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6674 "0378 No support for fcpi mode.\n");
6677 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
6678 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
6680 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
6682 * If the port cannot support the host's requested features
6683 * then turn off the global config parameters to disable the
6684 * feature in the driver. This is not a fatal error.
6686 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
6687 if (phba->cfg_enable_bg) {
6688 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))
6689 phba->sli3_options |= LPFC_SLI3_BG_ENABLED;
6694 if (phba->max_vpi && phba->cfg_enable_npiv &&
6695 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
6699 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6700 "0379 Feature Mismatch Data: x%08x %08x "
6701 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
6702 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
6703 phba->cfg_enable_npiv, phba->max_vpi);
6704 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
6705 phba->cfg_enable_bg = 0;
6706 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
6707 phba->cfg_enable_npiv = 0;
6710 /* These SLI3 features are assumed in SLI4 */
6711 spin_lock_irq(&phba->hbalock);
6712 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
6713 spin_unlock_irq(&phba->hbalock);
6716 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6717 * calls depends on these resources to complete port setup.
6719 rc = lpfc_sli4_alloc_resource_identifiers(phba);
6721 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6722 "2920 Failed to alloc Resource IDs "
6727 lpfc_set_host_data(phba, mboxq);
6729 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6731 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
6732 "2134 Failed to set host os driver version %x",
6736 /* Read the port's service parameters. */
6737 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
6739 phba->link_state = LPFC_HBA_ERROR;
6744 mboxq->vport = vport;
6745 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6746 mp = (struct lpfc_dmabuf *) mboxq->context1;
6747 if (rc == MBX_SUCCESS) {
6748 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
6753 * This memory was allocated by the lpfc_read_sparam routine. Release
6754 * it to the mbuf pool.
6756 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6758 mboxq->context1 = NULL;
6760 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6761 "0382 READ_SPARAM command failed "
6762 "status %d, mbxStatus x%x\n",
6763 rc, bf_get(lpfc_mqe_status, mqe));
6764 phba->link_state = LPFC_HBA_ERROR;
6769 lpfc_update_vport_wwn(vport);
6771 /* Update the fc_host data structures with new wwn. */
6772 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
6773 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
6775 /* Create all the SLI4 queues */
6776 rc = lpfc_sli4_queue_create(phba);
6778 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6779 "3089 Failed to allocate queues\n");
6783 /* Set up all the queues to the device */
6784 rc = lpfc_sli4_queue_setup(phba);
6786 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6787 "0381 Error %d during queue setup.\n ", rc);
6788 goto out_stop_timers;
6790 /* Initialize the driver internal SLI layer lists. */
6791 lpfc_sli4_setup(phba);
6792 lpfc_sli4_queue_init(phba);
6794 /* update host els xri-sgl sizes and mappings */
6795 rc = lpfc_sli4_els_sgl_update(phba);
6797 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6798 "1400 Failed to update xri-sgl size and "
6799 "mapping: %d\n", rc);
6800 goto out_destroy_queue;
6803 /* register the els sgl pool to the port */
6804 rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
6805 phba->sli4_hba.els_xri_cnt);
6806 if (unlikely(rc < 0)) {
6807 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6808 "0582 Error %d during els sgl post "
6811 goto out_destroy_queue;
6813 phba->sli4_hba.els_xri_cnt = rc;
6815 if (phba->nvmet_support) {
6816 /* update host nvmet xri-sgl sizes and mappings */
6817 rc = lpfc_sli4_nvmet_sgl_update(phba);
6819 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6820 "6308 Failed to update nvmet-sgl size "
6821 "and mapping: %d\n", rc);
6822 goto out_destroy_queue;
6825 /* register the nvmet sgl pool to the port */
6826 rc = lpfc_sli4_repost_sgl_list(
6828 &phba->sli4_hba.lpfc_nvmet_sgl_list,
6829 phba->sli4_hba.nvmet_xri_cnt);
6830 if (unlikely(rc < 0)) {
6831 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6832 "3117 Error %d during nvmet "
6835 goto out_destroy_queue;
6837 phba->sli4_hba.nvmet_xri_cnt = rc;
6838 /* todo: tgt: create targetport */
6840 /* update host scsi xri-sgl sizes and mappings */
6841 rc = lpfc_sli4_scsi_sgl_update(phba);
6843 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6844 "6309 Failed to update scsi-sgl size "
6845 "and mapping: %d\n", rc);
6846 goto out_destroy_queue;
6849 /* update host nvme xri-sgl sizes and mappings */
6850 rc = lpfc_sli4_nvme_sgl_update(phba);
6852 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6853 "6082 Failed to update nvme-sgl size "
6854 "and mapping: %d\n", rc);
6855 goto out_destroy_queue;
6859 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6860 /* register the allocated scsi sgl pool to the port */
6861 rc = lpfc_sli4_repost_scsi_sgl_list(phba);
6863 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6864 "0383 Error %d during scsi sgl post "
6866 /* Some Scsi buffers were moved to abort scsi list */
6867 /* A pci function reset will repost them */
6869 goto out_destroy_queue;
6873 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
6874 (phba->nvmet_support == 0)) {
6876 /* register the allocated nvme sgl pool to the port */
6877 rc = lpfc_repost_nvme_sgl_list(phba);
6879 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6880 "6116 Error %d during nvme sgl post "
6882 /* Some NVME buffers were moved to abort nvme list */
6883 /* A pci function reset will repost them */
6885 goto out_destroy_queue;
6889 /* Post the rpi header region to the device. */
6890 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
6892 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6893 "0393 Error %d during rpi post operation\n",
6896 goto out_destroy_queue;
6898 lpfc_sli4_node_prep(phba);
6900 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
6901 if (phba->nvmet_support == 0) {
6903 * The FC Port needs to register FCFI (index 0)
6905 lpfc_reg_fcfi(phba, mboxq);
6906 mboxq->vport = phba->pport;
6907 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6908 if (rc != MBX_SUCCESS)
6909 goto out_unset_queue;
6911 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
6912 &mboxq->u.mqe.un.reg_fcfi);
6914 /* Check if the port is configured to be disabled */
6915 lpfc_sli_read_link_ste(phba);
6918 /* Arm the CQs and then EQs on device */
6919 lpfc_sli4_arm_cqeq_intr(phba);
6921 /* Indicate device interrupt mode */
6922 phba->sli4_hba.intr_enable = 1;
6924 /* Allow asynchronous mailbox command to go through */
6925 spin_lock_irq(&phba->hbalock);
6926 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
6927 spin_unlock_irq(&phba->hbalock);
6929 /* Post receive buffers to the device */
6930 lpfc_sli4_rb_setup(phba);
6932 /* Reset HBA FCF states after HBA reset */
6933 phba->fcf.fcf_flag = 0;
6934 phba->fcf.current_rec.flag = 0;
6936 /* Start the ELS watchdog timer */
6937 mod_timer(&vport->els_tmofunc,
6938 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
6940 /* Start heart beat timer */
6941 mod_timer(&phba->hb_tmofunc,
6942 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
6943 phba->hb_outstanding = 0;
6944 phba->last_completion_time = jiffies;
6946 /* Start error attention (ERATT) polling timer */
6947 mod_timer(&phba->eratt_poll,
6948 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
6950 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6951 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
6952 rc = pci_enable_pcie_error_reporting(phba->pcidev);
6954 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6955 "2829 This device supports "
6956 "Advanced Error Reporting (AER)\n");
6957 spin_lock_irq(&phba->hbalock);
6958 phba->hba_flag |= HBA_AER_ENABLED;
6959 spin_unlock_irq(&phba->hbalock);
6961 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6962 "2830 This device does not support "
6963 "Advanced Error Reporting (AER)\n");
6964 phba->cfg_aer_support = 0;
6970 * The port is ready, set the host's link state to LINK_DOWN
6971 * in preparation for link interrupts.
6973 spin_lock_irq(&phba->hbalock);
6974 phba->link_state = LPFC_LINK_DOWN;
6975 spin_unlock_irq(&phba->hbalock);
6976 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
6977 (phba->hba_flag & LINK_DISABLED)) {
6978 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
6979 "3103 Adapter Link is disabled.\n");
6980 lpfc_down_link(phba, mboxq);
6981 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6982 if (rc != MBX_SUCCESS) {
6983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
6984 "3104 Adapter failed to issue "
6985 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
6986 goto out_unset_queue;
6988 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
6989 /* don't perform init_link on SLI4 FC port loopback test */
6990 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
6991 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
6993 goto out_unset_queue;
6996 mempool_free(mboxq, phba->mbox_mem_pool);
6999 /* Unset all the queues set up in this routine when error out */
7000 lpfc_sli4_queue_unset(phba);
7002 lpfc_sli4_queue_destroy(phba);
7004 lpfc_stop_hba_timers(phba);
7006 mempool_free(mboxq, phba->mbox_mem_pool);
7011 * lpfc_mbox_timeout - Timeout call back function for mbox timer
7012 * @ptr: context object - pointer to hba structure.
7014 * This is the callback function for mailbox timer. The mailbox
7015 * timer is armed when a new mailbox command is issued and the timer
7016 * is deleted when the mailbox complete. The function is called by
7017 * the kernel timer code when a mailbox does not complete within
7018 * expected time. This function wakes up the worker thread to
7019 * process the mailbox timeout and returns. All the processing is
7020 * done by the worker thread function lpfc_mbox_timeout_handler.
7023 lpfc_mbox_timeout(unsigned long ptr)
7025 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7026 unsigned long iflag;
7027 uint32_t tmo_posted;
7029 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
7030 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
7032 phba->pport->work_port_events |= WORKER_MBOX_TMO;
7033 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
7036 lpfc_worker_wake_up(phba);
7041 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
7043 * @phba: Pointer to HBA context object.
7045 * This function checks if any mailbox completions are present on the mailbox
7049 lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
7053 struct lpfc_queue *mcq;
7054 struct lpfc_mcqe *mcqe;
7055 bool pending_completions = false;
7057 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
7060 /* Check for completions on mailbox completion queue */
7062 mcq = phba->sli4_hba.mbx_cq;
7063 idx = mcq->hba_index;
7064 while (bf_get_le32(lpfc_cqe_valid, mcq->qe[idx].cqe)) {
7065 mcqe = (struct lpfc_mcqe *)mcq->qe[idx].cqe;
7066 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
7067 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
7068 pending_completions = true;
7071 idx = (idx + 1) % mcq->entry_count;
7072 if (mcq->hba_index == idx)
7075 return pending_completions;
7080 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
7082 * @phba: Pointer to HBA context object.
7084 * For sli4, it is possible to miss an interrupt. As such mbox completions
7085 * maybe missed causing erroneous mailbox timeouts to occur. This function
7086 * checks to see if mbox completions are on the mailbox completion queue
7087 * and will process all the completions associated with the eq for the
7088 * mailbox completion queue.
7091 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
7095 struct lpfc_queue *fpeq = NULL;
7096 struct lpfc_eqe *eqe;
7099 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
7102 /* Find the eq associated with the mcq */
7104 if (phba->sli4_hba.hba_eq)
7105 for (eqidx = 0; eqidx < phba->io_channel_irqs; eqidx++)
7106 if (phba->sli4_hba.hba_eq[eqidx]->queue_id ==
7107 phba->sli4_hba.mbx_cq->assoc_qid) {
7108 fpeq = phba->sli4_hba.hba_eq[eqidx];
7114 /* Turn off interrupts from this EQ */
7116 lpfc_sli4_eq_clr_intr(fpeq);
7118 /* Check to see if a mbox completion is pending */
7120 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
7123 * If a mbox completion is pending, process all the events on EQ
7124 * associated with the mbox completion queue (this could include
7125 * mailbox commands, async events, els commands, receive queue data
7130 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
7131 lpfc_sli4_hba_handle_eqe(phba, eqe, eqidx);
7132 fpeq->EQ_processed++;
7135 /* Always clear and re-arm the EQ */
7137 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
7139 return mbox_pending;
7144 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
7145 * @phba: Pointer to HBA context object.
7147 * This function is called from worker thread when a mailbox command times out.
7148 * The caller is not required to hold any locks. This function will reset the
7149 * HBA and recover all the pending commands.
7152 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
7154 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
7155 MAILBOX_t *mb = NULL;
7157 struct lpfc_sli *psli = &phba->sli;
7159 /* If the mailbox completed, process the completion and return */
7160 if (lpfc_sli4_process_missed_mbox_completions(phba))
7165 /* Check the pmbox pointer first. There is a race condition
7166 * between the mbox timeout handler getting executed in the
7167 * worklist and the mailbox actually completing. When this
7168 * race condition occurs, the mbox_active will be NULL.
7170 spin_lock_irq(&phba->hbalock);
7171 if (pmbox == NULL) {
7172 lpfc_printf_log(phba, KERN_WARNING,
7174 "0353 Active Mailbox cleared - mailbox timeout "
7176 spin_unlock_irq(&phba->hbalock);
7180 /* Mbox cmd <mbxCommand> timeout */
7181 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7182 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
7184 phba->pport->port_state,
7186 phba->sli.mbox_active);
7187 spin_unlock_irq(&phba->hbalock);
7189 /* Setting state unknown so lpfc_sli_abort_iocb_ring
7190 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
7191 * it to fail all outstanding SCSI IO.
7193 spin_lock_irq(&phba->pport->work_port_lock);
7194 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
7195 spin_unlock_irq(&phba->pport->work_port_lock);
7196 spin_lock_irq(&phba->hbalock);
7197 phba->link_state = LPFC_LINK_UNKNOWN;
7198 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
7199 spin_unlock_irq(&phba->hbalock);
7201 lpfc_sli_abort_fcp_rings(phba);
7203 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7204 "0345 Resetting board due to mailbox timeout\n");
7206 /* Reset the HBA device */
7207 lpfc_reset_hba(phba);
7211 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
7212 * @phba: Pointer to HBA context object.
7213 * @pmbox: Pointer to mailbox object.
7214 * @flag: Flag indicating how the mailbox need to be processed.
7216 * This function is called by discovery code and HBA management code
7217 * to submit a mailbox command to firmware with SLI-3 interface spec. This
7218 * function gets the hbalock to protect the data structures.
7219 * The mailbox command can be submitted in polling mode, in which case
7220 * this function will wait in a polling loop for the completion of the
7222 * If the mailbox is submitted in no_wait mode (not polling) the
7223 * function will submit the command and returns immediately without waiting
7224 * for the mailbox completion. The no_wait is supported only when HBA
7225 * is in SLI2/SLI3 mode - interrupts are enabled.
7226 * The SLI interface allows only one mailbox pending at a time. If the
7227 * mailbox is issued in polling mode and there is already a mailbox
7228 * pending, then the function will return an error. If the mailbox is issued
7229 * in NO_WAIT mode and there is a mailbox pending already, the function
7230 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
7231 * The sli layer owns the mailbox object until the completion of mailbox
7232 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
7233 * return codes the caller owns the mailbox command after the return of
7237 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
7241 struct lpfc_sli *psli = &phba->sli;
7242 uint32_t status, evtctr;
7243 uint32_t ha_copy, hc_copy;
7245 unsigned long timeout;
7246 unsigned long drvr_flag = 0;
7247 uint32_t word0, ldata;
7248 void __iomem *to_slim;
7249 int processing_queue = 0;
7251 spin_lock_irqsave(&phba->hbalock, drvr_flag);
7253 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7254 /* processing mbox queue from intr_handler */
7255 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
7256 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7259 processing_queue = 1;
7260 pmbox = lpfc_mbox_get(phba);
7262 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7267 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
7268 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
7270 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7271 lpfc_printf_log(phba, KERN_ERR,
7272 LOG_MBOX | LOG_VPORT,
7273 "1806 Mbox x%x failed. No vport\n",
7274 pmbox->u.mb.mbxCommand);
7276 goto out_not_finished;
7280 /* If the PCI channel is in offline state, do not post mbox. */
7281 if (unlikely(pci_channel_offline(phba->pcidev))) {
7282 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7283 goto out_not_finished;
7286 /* If HBA has a deferred error attention, fail the iocb. */
7287 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
7288 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7289 goto out_not_finished;
7295 status = MBX_SUCCESS;
7297 if (phba->link_state == LPFC_HBA_ERROR) {
7298 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7300 /* Mbox command <mbxCommand> cannot issue */
7301 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7302 "(%d):0311 Mailbox command x%x cannot "
7303 "issue Data: x%x x%x\n",
7304 pmbox->vport ? pmbox->vport->vpi : 0,
7305 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
7306 goto out_not_finished;
7309 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
7310 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
7311 !(hc_copy & HC_MBINT_ENA)) {
7312 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7313 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7314 "(%d):2528 Mailbox command x%x cannot "
7315 "issue Data: x%x x%x\n",
7316 pmbox->vport ? pmbox->vport->vpi : 0,
7317 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
7318 goto out_not_finished;
7322 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
7323 /* Polling for a mbox command when another one is already active
7324 * is not allowed in SLI. Also, the driver must have established
7325 * SLI2 mode to queue and process multiple mbox commands.
7328 if (flag & MBX_POLL) {
7329 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7331 /* Mbox command <mbxCommand> cannot issue */
7332 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7333 "(%d):2529 Mailbox command x%x "
7334 "cannot issue Data: x%x x%x\n",
7335 pmbox->vport ? pmbox->vport->vpi : 0,
7336 pmbox->u.mb.mbxCommand,
7337 psli->sli_flag, flag);
7338 goto out_not_finished;
7341 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
7342 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7343 /* Mbox command <mbxCommand> cannot issue */
7344 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7345 "(%d):2530 Mailbox command x%x "
7346 "cannot issue Data: x%x x%x\n",
7347 pmbox->vport ? pmbox->vport->vpi : 0,
7348 pmbox->u.mb.mbxCommand,
7349 psli->sli_flag, flag);
7350 goto out_not_finished;
7353 /* Another mailbox command is still being processed, queue this
7354 * command to be processed later.
7356 lpfc_mbox_put(phba, pmbox);
7358 /* Mbox cmd issue - BUSY */
7359 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7360 "(%d):0308 Mbox cmd issue - BUSY Data: "
7361 "x%x x%x x%x x%x\n",
7362 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
7363 mbx->mbxCommand, phba->pport->port_state,
7364 psli->sli_flag, flag);
7366 psli->slistat.mbox_busy++;
7367 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7370 lpfc_debugfs_disc_trc(pmbox->vport,
7371 LPFC_DISC_TRC_MBOX_VPORT,
7372 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
7373 (uint32_t)mbx->mbxCommand,
7374 mbx->un.varWords[0], mbx->un.varWords[1]);
7377 lpfc_debugfs_disc_trc(phba->pport,
7379 "MBOX Bsy: cmd:x%x mb:x%x x%x",
7380 (uint32_t)mbx->mbxCommand,
7381 mbx->un.varWords[0], mbx->un.varWords[1]);
7387 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
7389 /* If we are not polling, we MUST be in SLI2 mode */
7390 if (flag != MBX_POLL) {
7391 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
7392 (mbx->mbxCommand != MBX_KILL_BOARD)) {
7393 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7394 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7395 /* Mbox command <mbxCommand> cannot issue */
7396 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7397 "(%d):2531 Mailbox command x%x "
7398 "cannot issue Data: x%x x%x\n",
7399 pmbox->vport ? pmbox->vport->vpi : 0,
7400 pmbox->u.mb.mbxCommand,
7401 psli->sli_flag, flag);
7402 goto out_not_finished;
7404 /* timeout active mbox command */
7405 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
7407 mod_timer(&psli->mbox_tmo, jiffies + timeout);
7410 /* Mailbox cmd <cmd> issue */
7411 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7412 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
7414 pmbox->vport ? pmbox->vport->vpi : 0,
7415 mbx->mbxCommand, phba->pport->port_state,
7416 psli->sli_flag, flag);
7418 if (mbx->mbxCommand != MBX_HEARTBEAT) {
7420 lpfc_debugfs_disc_trc(pmbox->vport,
7421 LPFC_DISC_TRC_MBOX_VPORT,
7422 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7423 (uint32_t)mbx->mbxCommand,
7424 mbx->un.varWords[0], mbx->un.varWords[1]);
7427 lpfc_debugfs_disc_trc(phba->pport,
7429 "MBOX Send: cmd:x%x mb:x%x x%x",
7430 (uint32_t)mbx->mbxCommand,
7431 mbx->un.varWords[0], mbx->un.varWords[1]);
7435 psli->slistat.mbox_cmd++;
7436 evtctr = psli->slistat.mbox_event;
7438 /* next set own bit for the adapter and copy over command word */
7439 mbx->mbxOwner = OWN_CHIP;
7441 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7442 /* Populate mbox extension offset word. */
7443 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
7444 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
7445 = (uint8_t *)phba->mbox_ext
7446 - (uint8_t *)phba->mbox;
7449 /* Copy the mailbox extension data */
7450 if (pmbox->in_ext_byte_len && pmbox->context2) {
7451 lpfc_sli_pcimem_bcopy(pmbox->context2,
7452 (uint8_t *)phba->mbox_ext,
7453 pmbox->in_ext_byte_len);
7455 /* Copy command data to host SLIM area */
7456 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
7458 /* Populate mbox extension offset word. */
7459 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
7460 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
7461 = MAILBOX_HBA_EXT_OFFSET;
7463 /* Copy the mailbox extension data */
7464 if (pmbox->in_ext_byte_len && pmbox->context2)
7465 lpfc_memcpy_to_slim(phba->MBslimaddr +
7466 MAILBOX_HBA_EXT_OFFSET,
7467 pmbox->context2, pmbox->in_ext_byte_len);
7469 if (mbx->mbxCommand == MBX_CONFIG_PORT)
7470 /* copy command data into host mbox for cmpl */
7471 lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
7474 /* First copy mbox command data to HBA SLIM, skip past first
7476 to_slim = phba->MBslimaddr + sizeof (uint32_t);
7477 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
7478 MAILBOX_CMD_SIZE - sizeof (uint32_t));
7480 /* Next copy over first word, with mbxOwner set */
7481 ldata = *((uint32_t *)mbx);
7482 to_slim = phba->MBslimaddr;
7483 writel(ldata, to_slim);
7484 readl(to_slim); /* flush */
7486 if (mbx->mbxCommand == MBX_CONFIG_PORT)
7487 /* switch over to host mailbox */
7488 psli->sli_flag |= LPFC_SLI_ACTIVE;
7495 /* Set up reference to mailbox command */
7496 psli->mbox_active = pmbox;
7497 /* Interrupt board to do it */
7498 writel(CA_MBATT, phba->CAregaddr);
7499 readl(phba->CAregaddr); /* flush */
7500 /* Don't wait for it to finish, just return */
7504 /* Set up null reference to mailbox command */
7505 psli->mbox_active = NULL;
7506 /* Interrupt board to do it */
7507 writel(CA_MBATT, phba->CAregaddr);
7508 readl(phba->CAregaddr); /* flush */
7510 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7511 /* First read mbox status word */
7512 word0 = *((uint32_t *)phba->mbox);
7513 word0 = le32_to_cpu(word0);
7515 /* First read mbox status word */
7516 if (lpfc_readl(phba->MBslimaddr, &word0)) {
7517 spin_unlock_irqrestore(&phba->hbalock,
7519 goto out_not_finished;
7523 /* Read the HBA Host Attention Register */
7524 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
7525 spin_unlock_irqrestore(&phba->hbalock,
7527 goto out_not_finished;
7529 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
7532 /* Wait for command to complete */
7533 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
7534 (!(ha_copy & HA_MBATT) &&
7535 (phba->link_state > LPFC_WARM_START))) {
7536 if (time_after(jiffies, timeout)) {
7537 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7538 spin_unlock_irqrestore(&phba->hbalock,
7540 goto out_not_finished;
7543 /* Check if we took a mbox interrupt while we were
7545 if (((word0 & OWN_CHIP) != OWN_CHIP)
7546 && (evtctr != psli->slistat.mbox_event))
7550 spin_unlock_irqrestore(&phba->hbalock,
7553 spin_lock_irqsave(&phba->hbalock, drvr_flag);
7556 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7557 /* First copy command data */
7558 word0 = *((uint32_t *)phba->mbox);
7559 word0 = le32_to_cpu(word0);
7560 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
7563 /* Check real SLIM for any errors */
7564 slimword0 = readl(phba->MBslimaddr);
7565 slimmb = (MAILBOX_t *) & slimword0;
7566 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
7567 && slimmb->mbxStatus) {
7574 /* First copy command data */
7575 word0 = readl(phba->MBslimaddr);
7577 /* Read the HBA Host Attention Register */
7578 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
7579 spin_unlock_irqrestore(&phba->hbalock,
7581 goto out_not_finished;
7585 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
7586 /* copy results back to user */
7587 lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
7589 /* Copy the mailbox extension data */
7590 if (pmbox->out_ext_byte_len && pmbox->context2) {
7591 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
7593 pmbox->out_ext_byte_len);
7596 /* First copy command data */
7597 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
7599 /* Copy the mailbox extension data */
7600 if (pmbox->out_ext_byte_len && pmbox->context2) {
7601 lpfc_memcpy_from_slim(pmbox->context2,
7603 MAILBOX_HBA_EXT_OFFSET,
7604 pmbox->out_ext_byte_len);
7608 writel(HA_MBATT, phba->HAregaddr);
7609 readl(phba->HAregaddr); /* flush */
7611 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7612 status = mbx->mbxStatus;
7615 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
7619 if (processing_queue) {
7620 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
7621 lpfc_mbox_cmpl_put(phba, pmbox);
7623 return MBX_NOT_FINISHED;
7627 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7628 * @phba: Pointer to HBA context object.
7630 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7631 * the driver internal pending mailbox queue. It will then try to wait out the
7632 * possible outstanding mailbox command before return.
7635 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7636 * the outstanding mailbox command timed out.
7639 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
7641 struct lpfc_sli *psli = &phba->sli;
7643 unsigned long timeout = 0;
7645 /* Mark the asynchronous mailbox command posting as blocked */
7646 spin_lock_irq(&phba->hbalock);
7647 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
7648 /* Determine how long we might wait for the active mailbox
7649 * command to be gracefully completed by firmware.
7651 if (phba->sli.mbox_active)
7652 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
7653 phba->sli.mbox_active) *
7655 spin_unlock_irq(&phba->hbalock);
7657 /* Make sure the mailbox is really active */
7659 lpfc_sli4_process_missed_mbox_completions(phba);
7661 /* Wait for the outstnading mailbox command to complete */
7662 while (phba->sli.mbox_active) {
7663 /* Check active mailbox complete status every 2ms */
7665 if (time_after(jiffies, timeout)) {
7666 /* Timeout, marked the outstanding cmd not complete */
7672 /* Can not cleanly block async mailbox command, fails it */
7674 spin_lock_irq(&phba->hbalock);
7675 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7676 spin_unlock_irq(&phba->hbalock);
7682 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7683 * @phba: Pointer to HBA context object.
7685 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7686 * commands from the driver internal pending mailbox queue. It makes sure
7687 * that there is no outstanding mailbox command before resuming posting
7688 * asynchronous mailbox commands. If, for any reason, there is outstanding
7689 * mailbox command, it will try to wait it out before resuming asynchronous
7690 * mailbox command posting.
7693 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
7695 struct lpfc_sli *psli = &phba->sli;
7697 spin_lock_irq(&phba->hbalock);
7698 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
7699 /* Asynchronous mailbox posting is not blocked, do nothing */
7700 spin_unlock_irq(&phba->hbalock);
7704 /* Outstanding synchronous mailbox command is guaranteed to be done,
7705 * successful or timeout, after timing-out the outstanding mailbox
7706 * command shall always be removed, so just unblock posting async
7707 * mailbox command and resume
7709 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7710 spin_unlock_irq(&phba->hbalock);
7712 /* wake up worker thread to post asynchronlous mailbox command */
7713 lpfc_worker_wake_up(phba);
7717 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7718 * @phba: Pointer to HBA context object.
7719 * @mboxq: Pointer to mailbox object.
7721 * The function waits for the bootstrap mailbox register ready bit from
7722 * port for twice the regular mailbox command timeout value.
7724 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7725 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7728 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7731 unsigned long timeout;
7732 struct lpfc_register bmbx_reg;
7734 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
7738 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
7739 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
7743 if (time_after(jiffies, timeout))
7744 return MBXERR_ERROR;
7745 } while (!db_ready);
7751 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7752 * @phba: Pointer to HBA context object.
7753 * @mboxq: Pointer to mailbox object.
7755 * The function posts a mailbox to the port. The mailbox is expected
7756 * to be comletely filled in and ready for the port to operate on it.
7757 * This routine executes a synchronous completion operation on the
7758 * mailbox by polling for its completion.
7760 * The caller must not be holding any locks when calling this routine.
7763 * MBX_SUCCESS - mailbox posted successfully
7764 * Any of the MBX error values.
7767 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7769 int rc = MBX_SUCCESS;
7770 unsigned long iflag;
7771 uint32_t mcqe_status;
7773 struct lpfc_sli *psli = &phba->sli;
7774 struct lpfc_mqe *mb = &mboxq->u.mqe;
7775 struct lpfc_bmbx_create *mbox_rgn;
7776 struct dma_address *dma_address;
7779 * Only one mailbox can be active to the bootstrap mailbox region
7780 * at a time and there is no queueing provided.
7782 spin_lock_irqsave(&phba->hbalock, iflag);
7783 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
7784 spin_unlock_irqrestore(&phba->hbalock, iflag);
7785 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7786 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7787 "cannot issue Data: x%x x%x\n",
7788 mboxq->vport ? mboxq->vport->vpi : 0,
7789 mboxq->u.mb.mbxCommand,
7790 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7791 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7792 psli->sli_flag, MBX_POLL);
7793 return MBXERR_ERROR;
7795 /* The server grabs the token and owns it until release */
7796 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
7797 phba->sli.mbox_active = mboxq;
7798 spin_unlock_irqrestore(&phba->hbalock, iflag);
7800 /* wait for bootstrap mbox register for readyness */
7801 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
7806 * Initialize the bootstrap memory region to avoid stale data areas
7807 * in the mailbox post. Then copy the caller's mailbox contents to
7808 * the bmbx mailbox region.
7810 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
7811 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
7812 lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
7813 sizeof(struct lpfc_mqe));
7815 /* Post the high mailbox dma address to the port and wait for ready. */
7816 dma_address = &phba->sli4_hba.bmbx.dma_address;
7817 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
7819 /* wait for bootstrap mbox register for hi-address write done */
7820 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
7824 /* Post the low mailbox dma address to the port. */
7825 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
7827 /* wait for bootstrap mbox register for low address write done */
7828 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
7833 * Read the CQ to ensure the mailbox has completed.
7834 * If so, update the mailbox status so that the upper layers
7835 * can complete the request normally.
7837 lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
7838 sizeof(struct lpfc_mqe));
7839 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
7840 lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
7841 sizeof(struct lpfc_mcqe));
7842 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
7844 * When the CQE status indicates a failure and the mailbox status
7845 * indicates success then copy the CQE status into the mailbox status
7846 * (and prefix it with x4000).
7848 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
7849 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
7850 bf_set(lpfc_mqe_status, mb,
7851 (LPFC_MBX_ERROR_RANGE | mcqe_status));
7854 lpfc_sli4_swap_str(phba, mboxq);
7856 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7857 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7858 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7859 " x%x x%x CQ: x%x x%x x%x x%x\n",
7860 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
7861 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7862 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7863 bf_get(lpfc_mqe_status, mb),
7864 mb->un.mb_words[0], mb->un.mb_words[1],
7865 mb->un.mb_words[2], mb->un.mb_words[3],
7866 mb->un.mb_words[4], mb->un.mb_words[5],
7867 mb->un.mb_words[6], mb->un.mb_words[7],
7868 mb->un.mb_words[8], mb->un.mb_words[9],
7869 mb->un.mb_words[10], mb->un.mb_words[11],
7870 mb->un.mb_words[12], mboxq->mcqe.word0,
7871 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
7872 mboxq->mcqe.trailer);
7874 /* We are holding the token, no needed for lock when release */
7875 spin_lock_irqsave(&phba->hbalock, iflag);
7876 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
7877 phba->sli.mbox_active = NULL;
7878 spin_unlock_irqrestore(&phba->hbalock, iflag);
7883 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7884 * @phba: Pointer to HBA context object.
7885 * @pmbox: Pointer to mailbox object.
7886 * @flag: Flag indicating how the mailbox need to be processed.
7888 * This function is called by discovery code and HBA management code to submit
7889 * a mailbox command to firmware with SLI-4 interface spec.
7891 * Return codes the caller owns the mailbox command after the return of the
7895 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
7898 struct lpfc_sli *psli = &phba->sli;
7899 unsigned long iflags;
7902 /* dump from issue mailbox command if setup */
7903 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
7905 rc = lpfc_mbox_dev_check(phba);
7907 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7908 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7909 "cannot issue Data: x%x x%x\n",
7910 mboxq->vport ? mboxq->vport->vpi : 0,
7911 mboxq->u.mb.mbxCommand,
7912 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7913 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7914 psli->sli_flag, flag);
7915 goto out_not_finished;
7918 /* Detect polling mode and jump to a handler */
7919 if (!phba->sli4_hba.intr_enable) {
7920 if (flag == MBX_POLL)
7921 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
7924 if (rc != MBX_SUCCESS)
7925 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7926 "(%d):2541 Mailbox command x%x "
7927 "(x%x/x%x) failure: "
7928 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7930 mboxq->vport ? mboxq->vport->vpi : 0,
7931 mboxq->u.mb.mbxCommand,
7932 lpfc_sli_config_mbox_subsys_get(phba,
7934 lpfc_sli_config_mbox_opcode_get(phba,
7936 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
7937 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
7938 bf_get(lpfc_mcqe_ext_status,
7940 psli->sli_flag, flag);
7942 } else if (flag == MBX_POLL) {
7943 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7944 "(%d):2542 Try to issue mailbox command "
7945 "x%x (x%x/x%x) synchronously ahead of async"
7946 "mailbox command queue: x%x x%x\n",
7947 mboxq->vport ? mboxq->vport->vpi : 0,
7948 mboxq->u.mb.mbxCommand,
7949 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7950 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7951 psli->sli_flag, flag);
7952 /* Try to block the asynchronous mailbox posting */
7953 rc = lpfc_sli4_async_mbox_block(phba);
7955 /* Successfully blocked, now issue sync mbox cmd */
7956 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
7957 if (rc != MBX_SUCCESS)
7958 lpfc_printf_log(phba, KERN_WARNING,
7960 "(%d):2597 Sync Mailbox command "
7961 "x%x (x%x/x%x) failure: "
7962 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7964 mboxq->vport ? mboxq->vport->vpi : 0,
7965 mboxq->u.mb.mbxCommand,
7966 lpfc_sli_config_mbox_subsys_get(phba,
7968 lpfc_sli_config_mbox_opcode_get(phba,
7970 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
7971 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
7972 bf_get(lpfc_mcqe_ext_status,
7974 psli->sli_flag, flag);
7975 /* Unblock the async mailbox posting afterward */
7976 lpfc_sli4_async_mbox_unblock(phba);
7981 /* Now, interrupt mode asynchrous mailbox command */
7982 rc = lpfc_mbox_cmd_check(phba, mboxq);
7984 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7985 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7986 "cannot issue Data: x%x x%x\n",
7987 mboxq->vport ? mboxq->vport->vpi : 0,
7988 mboxq->u.mb.mbxCommand,
7989 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
7990 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
7991 psli->sli_flag, flag);
7992 goto out_not_finished;
7995 /* Put the mailbox command to the driver internal FIFO */
7996 psli->slistat.mbox_busy++;
7997 spin_lock_irqsave(&phba->hbalock, iflags);
7998 lpfc_mbox_put(phba, mboxq);
7999 spin_unlock_irqrestore(&phba->hbalock, iflags);
8000 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8001 "(%d):0354 Mbox cmd issue - Enqueue Data: "
8002 "x%x (x%x/x%x) x%x x%x x%x\n",
8003 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
8004 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8005 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8006 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8007 phba->pport->port_state,
8008 psli->sli_flag, MBX_NOWAIT);
8009 /* Wake up worker thread to transport mailbox command from head */
8010 lpfc_worker_wake_up(phba);
8015 return MBX_NOT_FINISHED;
8019 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
8020 * @phba: Pointer to HBA context object.
8022 * This function is called by worker thread to send a mailbox command to
8023 * SLI4 HBA firmware.
8027 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
8029 struct lpfc_sli *psli = &phba->sli;
8030 LPFC_MBOXQ_t *mboxq;
8031 int rc = MBX_SUCCESS;
8032 unsigned long iflags;
8033 struct lpfc_mqe *mqe;
8036 /* Check interrupt mode before post async mailbox command */
8037 if (unlikely(!phba->sli4_hba.intr_enable))
8038 return MBX_NOT_FINISHED;
8040 /* Check for mailbox command service token */
8041 spin_lock_irqsave(&phba->hbalock, iflags);
8042 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8043 spin_unlock_irqrestore(&phba->hbalock, iflags);
8044 return MBX_NOT_FINISHED;
8046 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8047 spin_unlock_irqrestore(&phba->hbalock, iflags);
8048 return MBX_NOT_FINISHED;
8050 if (unlikely(phba->sli.mbox_active)) {
8051 spin_unlock_irqrestore(&phba->hbalock, iflags);
8052 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8053 "0384 There is pending active mailbox cmd\n");
8054 return MBX_NOT_FINISHED;
8056 /* Take the mailbox command service token */
8057 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8059 /* Get the next mailbox command from head of queue */
8060 mboxq = lpfc_mbox_get(phba);
8062 /* If no more mailbox command waiting for post, we're done */
8064 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8065 spin_unlock_irqrestore(&phba->hbalock, iflags);
8068 phba->sli.mbox_active = mboxq;
8069 spin_unlock_irqrestore(&phba->hbalock, iflags);
8071 /* Check device readiness for posting mailbox command */
8072 rc = lpfc_mbox_dev_check(phba);
8074 /* Driver clean routine will clean up pending mailbox */
8075 goto out_not_finished;
8077 /* Prepare the mbox command to be posted */
8078 mqe = &mboxq->u.mqe;
8079 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
8081 /* Start timer for the mbox_tmo and log some mailbox post messages */
8082 mod_timer(&psli->mbox_tmo, (jiffies +
8083 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
8085 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8086 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
8088 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
8089 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8090 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8091 phba->pport->port_state, psli->sli_flag);
8093 if (mbx_cmnd != MBX_HEARTBEAT) {
8095 lpfc_debugfs_disc_trc(mboxq->vport,
8096 LPFC_DISC_TRC_MBOX_VPORT,
8097 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8098 mbx_cmnd, mqe->un.mb_words[0],
8099 mqe->un.mb_words[1]);
8101 lpfc_debugfs_disc_trc(phba->pport,
8103 "MBOX Send: cmd:x%x mb:x%x x%x",
8104 mbx_cmnd, mqe->un.mb_words[0],
8105 mqe->un.mb_words[1]);
8108 psli->slistat.mbox_cmd++;
8110 /* Post the mailbox command to the port */
8111 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
8112 if (rc != MBX_SUCCESS) {
8113 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8114 "(%d):2533 Mailbox command x%x (x%x/x%x) "
8115 "cannot issue Data: x%x x%x\n",
8116 mboxq->vport ? mboxq->vport->vpi : 0,
8117 mboxq->u.mb.mbxCommand,
8118 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8119 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8120 psli->sli_flag, MBX_NOWAIT);
8121 goto out_not_finished;
8127 spin_lock_irqsave(&phba->hbalock, iflags);
8128 if (phba->sli.mbox_active) {
8129 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8130 __lpfc_mbox_cmpl_put(phba, mboxq);
8131 /* Release the token */
8132 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8133 phba->sli.mbox_active = NULL;
8135 spin_unlock_irqrestore(&phba->hbalock, iflags);
8137 return MBX_NOT_FINISHED;
8141 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
8142 * @phba: Pointer to HBA context object.
8143 * @pmbox: Pointer to mailbox object.
8144 * @flag: Flag indicating how the mailbox need to be processed.
8146 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
8147 * the API jump table function pointer from the lpfc_hba struct.
8149 * Return codes the caller owns the mailbox command after the return of the
8153 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
8155 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
8159 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
8160 * @phba: The hba struct for which this call is being executed.
8161 * @dev_grp: The HBA PCI-Device group number.
8163 * This routine sets up the mbox interface API function jump table in @phba
8165 * Returns: 0 - success, -ENODEV - failure.
8168 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8172 case LPFC_PCI_DEV_LP:
8173 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
8174 phba->lpfc_sli_handle_slow_ring_event =
8175 lpfc_sli_handle_slow_ring_event_s3;
8176 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
8177 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
8178 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
8180 case LPFC_PCI_DEV_OC:
8181 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
8182 phba->lpfc_sli_handle_slow_ring_event =
8183 lpfc_sli_handle_slow_ring_event_s4;
8184 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
8185 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
8186 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
8189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8190 "1420 Invalid HBA PCI-device group: 0x%x\n",
8199 * __lpfc_sli_ringtx_put - Add an iocb to the txq
8200 * @phba: Pointer to HBA context object.
8201 * @pring: Pointer to driver SLI ring object.
8202 * @piocb: Pointer to address of newly added command iocb.
8204 * This function is called with hbalock held to add a command
8205 * iocb to the txq when SLI layer cannot submit the command iocb
8209 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8210 struct lpfc_iocbq *piocb)
8212 lockdep_assert_held(&phba->hbalock);
8213 /* Insert the caller's iocb in the txq tail for later processing. */
8214 list_add_tail(&piocb->list, &pring->txq);
8218 * lpfc_sli_next_iocb - Get the next iocb in the txq
8219 * @phba: Pointer to HBA context object.
8220 * @pring: Pointer to driver SLI ring object.
8221 * @piocb: Pointer to address of newly added command iocb.
8223 * This function is called with hbalock held before a new
8224 * iocb is submitted to the firmware. This function checks
8225 * txq to flush the iocbs in txq to Firmware before
8226 * submitting new iocbs to the Firmware.
8227 * If there are iocbs in the txq which need to be submitted
8228 * to firmware, lpfc_sli_next_iocb returns the first element
8229 * of the txq after dequeuing it from txq.
8230 * If there is no iocb in the txq then the function will return
8231 * *piocb and *piocb is set to NULL. Caller needs to check
8232 * *piocb to find if there are more commands in the txq.
8234 static struct lpfc_iocbq *
8235 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8236 struct lpfc_iocbq **piocb)
8238 struct lpfc_iocbq * nextiocb;
8240 lockdep_assert_held(&phba->hbalock);
8242 nextiocb = lpfc_sli_ringtx_get(phba, pring);
8252 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
8253 * @phba: Pointer to HBA context object.
8254 * @ring_number: SLI ring number to issue iocb on.
8255 * @piocb: Pointer to command iocb.
8256 * @flag: Flag indicating if this command can be put into txq.
8258 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
8259 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
8260 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
8261 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
8262 * this function allows only iocbs for posting buffers. This function finds
8263 * next available slot in the command ring and posts the command to the
8264 * available slot and writes the port attention register to request HBA start
8265 * processing new iocb. If there is no slot available in the ring and
8266 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
8267 * the function returns IOCB_BUSY.
8269 * This function is called with hbalock held. The function will return success
8270 * after it successfully submit the iocb to firmware or after adding to the
8274 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
8275 struct lpfc_iocbq *piocb, uint32_t flag)
8277 struct lpfc_iocbq *nextiocb;
8279 struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
8281 lockdep_assert_held(&phba->hbalock);
8283 if (piocb->iocb_cmpl && (!piocb->vport) &&
8284 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
8285 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
8286 lpfc_printf_log(phba, KERN_ERR,
8287 LOG_SLI | LOG_VPORT,
8288 "1807 IOCB x%x failed. No vport\n",
8289 piocb->iocb.ulpCommand);
8295 /* If the PCI channel is in offline state, do not post iocbs. */
8296 if (unlikely(pci_channel_offline(phba->pcidev)))
8299 /* If HBA has a deferred error attention, fail the iocb. */
8300 if (unlikely(phba->hba_flag & DEFER_ERATT))
8304 * We should never get an IOCB if we are in a < LINK_DOWN state
8306 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
8310 * Check to see if we are blocking IOCB processing because of a
8311 * outstanding event.
8313 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
8316 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
8318 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
8319 * can be issued if the link is not up.
8321 switch (piocb->iocb.ulpCommand) {
8322 case CMD_GEN_REQUEST64_CR:
8323 case CMD_GEN_REQUEST64_CX:
8324 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
8325 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
8326 FC_RCTL_DD_UNSOL_CMD) ||
8327 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
8328 MENLO_TRANSPORT_TYPE))
8332 case CMD_QUE_RING_BUF_CN:
8333 case CMD_QUE_RING_BUF64_CN:
8335 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
8336 * completion, iocb_cmpl MUST be 0.
8338 if (piocb->iocb_cmpl)
8339 piocb->iocb_cmpl = NULL;
8341 case CMD_CREATE_XRI_CR:
8342 case CMD_CLOSE_XRI_CN:
8343 case CMD_CLOSE_XRI_CX:
8350 * For FCP commands, we must be in a state where we can process link
8353 } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
8354 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
8358 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
8359 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
8360 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
8363 lpfc_sli_update_ring(phba, pring);
8365 lpfc_sli_update_full_ring(phba, pring);
8368 return IOCB_SUCCESS;
8373 pring->stats.iocb_cmd_delay++;
8377 if (!(flag & SLI_IOCB_RET_IOCB)) {
8378 __lpfc_sli_ringtx_put(phba, pring, piocb);
8379 return IOCB_SUCCESS;
8386 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
8387 * @phba: Pointer to HBA context object.
8388 * @piocb: Pointer to command iocb.
8389 * @sglq: Pointer to the scatter gather queue object.
8391 * This routine converts the bpl or bde that is in the IOCB
8392 * to a sgl list for the sli4 hardware. The physical address
8393 * of the bpl/bde is converted back to a virtual address.
8394 * If the IOCB contains a BPL then the list of BDE's is
8395 * converted to sli4_sge's. If the IOCB contains a single
8396 * BDE then it is converted to a single sli_sge.
8397 * The IOCB is still in cpu endianess so the contents of
8398 * the bpl can be used without byte swapping.
8400 * Returns valid XRI = Success, NO_XRI = Failure.
8403 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
8404 struct lpfc_sglq *sglq)
8406 uint16_t xritag = NO_XRI;
8407 struct ulp_bde64 *bpl = NULL;
8408 struct ulp_bde64 bde;
8409 struct sli4_sge *sgl = NULL;
8410 struct lpfc_dmabuf *dmabuf;
8414 uint32_t offset = 0; /* accumulated offset in the sg request list */
8415 int inbound = 0; /* number of sg reply entries inbound from firmware */
8417 if (!piocbq || !sglq)
8420 sgl = (struct sli4_sge *)sglq->sgl;
8421 icmd = &piocbq->iocb;
8422 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
8423 return sglq->sli4_xritag;
8424 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
8425 numBdes = icmd->un.genreq64.bdl.bdeSize /
8426 sizeof(struct ulp_bde64);
8427 /* The addrHigh and addrLow fields within the IOCB
8428 * have not been byteswapped yet so there is no
8429 * need to swap them back.
8431 if (piocbq->context3)
8432 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
8436 bpl = (struct ulp_bde64 *)dmabuf->virt;
8440 for (i = 0; i < numBdes; i++) {
8441 /* Should already be byte swapped. */
8442 sgl->addr_hi = bpl->addrHigh;
8443 sgl->addr_lo = bpl->addrLow;
8445 sgl->word2 = le32_to_cpu(sgl->word2);
8446 if ((i+1) == numBdes)
8447 bf_set(lpfc_sli4_sge_last, sgl, 1);
8449 bf_set(lpfc_sli4_sge_last, sgl, 0);
8450 /* swap the size field back to the cpu so we
8451 * can assign it to the sgl.
8453 bde.tus.w = le32_to_cpu(bpl->tus.w);
8454 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
8455 /* The offsets in the sgl need to be accumulated
8456 * separately for the request and reply lists.
8457 * The request is always first, the reply follows.
8459 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
8460 /* add up the reply sg entries */
8461 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
8463 /* first inbound? reset the offset */
8466 bf_set(lpfc_sli4_sge_offset, sgl, offset);
8467 bf_set(lpfc_sli4_sge_type, sgl,
8468 LPFC_SGE_TYPE_DATA);
8469 offset += bde.tus.f.bdeSize;
8471 sgl->word2 = cpu_to_le32(sgl->word2);
8475 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
8476 /* The addrHigh and addrLow fields of the BDE have not
8477 * been byteswapped yet so they need to be swapped
8478 * before putting them in the sgl.
8481 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
8483 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
8484 sgl->word2 = le32_to_cpu(sgl->word2);
8485 bf_set(lpfc_sli4_sge_last, sgl, 1);
8486 sgl->word2 = cpu_to_le32(sgl->word2);
8488 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
8490 return sglq->sli4_xritag;
8494 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8495 * @phba: Pointer to HBA context object.
8496 * @piocb: Pointer to command iocb.
8497 * @wqe: Pointer to the work queue entry.
8499 * This routine converts the iocb command to its Work Queue Entry
8500 * equivalent. The wqe pointer should not have any fields set when
8501 * this routine is called because it will memcpy over them.
8502 * This routine does not set the CQ_ID or the WQEC bits in the
8505 * Returns: 0 = Success, IOCB_ERROR = Failure.
8508 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
8509 union lpfc_wqe *wqe)
8511 uint32_t xmit_len = 0, total_len = 0;
8515 uint8_t command_type = ELS_COMMAND_NON_FIP;
8518 uint16_t abrt_iotag;
8519 struct lpfc_iocbq *abrtiocbq;
8520 struct ulp_bde64 *bpl = NULL;
8521 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
8523 struct ulp_bde64 bde;
8524 struct lpfc_nodelist *ndlp;
8528 fip = phba->hba_flag & HBA_FIP_SUPPORT;
8529 /* The fcp commands will set command type */
8530 if (iocbq->iocb_flag & LPFC_IO_FCP)
8531 command_type = FCP_COMMAND;
8532 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
8533 command_type = ELS_COMMAND_FIP;
8535 command_type = ELS_COMMAND_NON_FIP;
8537 if (phba->fcp_embed_io)
8538 memset(wqe, 0, sizeof(union lpfc_wqe128));
8539 /* Some of the fields are in the right position already */
8540 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
8541 wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */
8542 wqe->generic.wqe_com.word10 = 0;
8544 abort_tag = (uint32_t) iocbq->iotag;
8545 xritag = iocbq->sli4_xritag;
8546 /* words0-2 bpl convert bde */
8547 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
8548 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
8549 sizeof(struct ulp_bde64);
8550 bpl = (struct ulp_bde64 *)
8551 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
8555 /* Should already be byte swapped. */
8556 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
8557 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
8558 /* swap the size field back to the cpu so we
8559 * can assign it to the sgl.
8561 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
8562 xmit_len = wqe->generic.bde.tus.f.bdeSize;
8564 for (i = 0; i < numBdes; i++) {
8565 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
8566 total_len += bde.tus.f.bdeSize;
8569 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
8571 iocbq->iocb.ulpIoTag = iocbq->iotag;
8572 cmnd = iocbq->iocb.ulpCommand;
8574 switch (iocbq->iocb.ulpCommand) {
8575 case CMD_ELS_REQUEST64_CR:
8576 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
8577 ndlp = iocbq->context_un.ndlp;
8579 ndlp = (struct lpfc_nodelist *)iocbq->context1;
8580 if (!iocbq->iocb.ulpLe) {
8581 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8582 "2007 Only Limited Edition cmd Format"
8583 " supported 0x%x\n",
8584 iocbq->iocb.ulpCommand);
8588 wqe->els_req.payload_len = xmit_len;
8589 /* Els_reguest64 has a TMO */
8590 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
8591 iocbq->iocb.ulpTimeout);
8592 /* Need a VF for word 4 set the vf bit*/
8593 bf_set(els_req64_vf, &wqe->els_req, 0);
8594 /* And a VFID for word 12 */
8595 bf_set(els_req64_vfid, &wqe->els_req, 0);
8596 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
8597 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
8598 iocbq->iocb.ulpContext);
8599 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
8600 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
8601 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8602 if (command_type == ELS_COMMAND_FIP)
8603 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
8604 >> LPFC_FIP_ELS_ID_SHIFT);
8605 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8606 iocbq->context2)->virt);
8607 if_type = bf_get(lpfc_sli_intf_if_type,
8608 &phba->sli4_hba.sli_intf);
8609 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8610 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
8611 *pcmd == ELS_CMD_SCR ||
8612 *pcmd == ELS_CMD_FDISC ||
8613 *pcmd == ELS_CMD_LOGO ||
8614 *pcmd == ELS_CMD_PLOGI)) {
8615 bf_set(els_req64_sp, &wqe->els_req, 1);
8616 bf_set(els_req64_sid, &wqe->els_req,
8617 iocbq->vport->fc_myDID);
8618 if ((*pcmd == ELS_CMD_FLOGI) &&
8619 !(phba->fc_topology ==
8620 LPFC_TOPOLOGY_LOOP))
8621 bf_set(els_req64_sid, &wqe->els_req, 0);
8622 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
8623 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
8624 phba->vpi_ids[iocbq->vport->vpi]);
8625 } else if (pcmd && iocbq->context1) {
8626 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
8627 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
8628 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
8631 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
8632 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
8633 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
8634 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
8635 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
8636 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
8637 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
8638 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
8639 wqe->els_req.max_response_payload_len = total_len - xmit_len;
8641 case CMD_XMIT_SEQUENCE64_CX:
8642 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
8643 iocbq->iocb.un.ulpWord[3]);
8644 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
8645 iocbq->iocb.unsli3.rcvsli3.ox_id);
8646 /* The entire sequence is transmitted for this IOCB */
8647 xmit_len = total_len;
8648 cmnd = CMD_XMIT_SEQUENCE64_CR;
8649 if (phba->link_flag & LS_LOOPBACK_MODE)
8650 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
8651 case CMD_XMIT_SEQUENCE64_CR:
8652 /* word3 iocb=io_tag32 wqe=reserved */
8653 wqe->xmit_sequence.rsvd3 = 0;
8654 /* word4 relative_offset memcpy */
8655 /* word5 r_ctl/df_ctl memcpy */
8656 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
8657 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
8658 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
8659 LPFC_WQE_IOD_WRITE);
8660 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
8661 LPFC_WQE_LENLOC_WORD12);
8662 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
8663 wqe->xmit_sequence.xmit_len = xmit_len;
8664 command_type = OTHER_COMMAND;
8666 case CMD_XMIT_BCAST64_CN:
8667 /* word3 iocb=iotag32 wqe=seq_payload_len */
8668 wqe->xmit_bcast64.seq_payload_len = xmit_len;
8669 /* word4 iocb=rsvd wqe=rsvd */
8670 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8671 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8672 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
8673 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8674 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
8675 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
8676 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
8677 LPFC_WQE_LENLOC_WORD3);
8678 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
8680 case CMD_FCP_IWRITE64_CR:
8681 command_type = FCP_COMMAND_DATA_OUT;
8682 /* word3 iocb=iotag wqe=payload_offset_len */
8683 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8684 bf_set(payload_offset_len, &wqe->fcp_iwrite,
8685 xmit_len + sizeof(struct fcp_rsp));
8686 bf_set(cmd_buff_len, &wqe->fcp_iwrite,
8688 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8689 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8690 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
8691 iocbq->iocb.ulpFCP2Rcvy);
8692 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
8693 /* Always open the exchange */
8694 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
8695 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
8696 LPFC_WQE_LENLOC_WORD4);
8697 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
8698 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
8699 if (iocbq->iocb_flag & LPFC_IO_OAS) {
8700 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
8701 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
8702 if (iocbq->priority) {
8703 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
8704 (iocbq->priority << 1));
8706 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
8707 (phba->cfg_XLanePriority << 1));
8710 /* Note, word 10 is already initialized to 0 */
8712 if (phba->fcp_embed_io) {
8713 struct lpfc_scsi_buf *lpfc_cmd;
8714 struct sli4_sge *sgl;
8715 union lpfc_wqe128 *wqe128;
8716 struct fcp_cmnd *fcp_cmnd;
8719 /* 128 byte wqe support here */
8720 wqe128 = (union lpfc_wqe128 *)wqe;
8722 lpfc_cmd = iocbq->context1;
8723 sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
8724 fcp_cmnd = lpfc_cmd->fcp_cmnd;
8726 /* Word 0-2 - FCP_CMND */
8727 wqe128->generic.bde.tus.f.bdeFlags =
8728 BUFF_TYPE_BDE_IMMED;
8729 wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
8730 wqe128->generic.bde.addrHigh = 0;
8731 wqe128->generic.bde.addrLow = 88; /* Word 22 */
8733 bf_set(wqe_wqes, &wqe128->fcp_iwrite.wqe_com, 1);
8735 /* Word 22-29 FCP CMND Payload */
8736 ptr = &wqe128->words[22];
8737 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
8740 case CMD_FCP_IREAD64_CR:
8741 /* word3 iocb=iotag wqe=payload_offset_len */
8742 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8743 bf_set(payload_offset_len, &wqe->fcp_iread,
8744 xmit_len + sizeof(struct fcp_rsp));
8745 bf_set(cmd_buff_len, &wqe->fcp_iread,
8747 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8748 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8749 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
8750 iocbq->iocb.ulpFCP2Rcvy);
8751 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
8752 /* Always open the exchange */
8753 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
8754 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
8755 LPFC_WQE_LENLOC_WORD4);
8756 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
8757 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
8758 if (iocbq->iocb_flag & LPFC_IO_OAS) {
8759 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
8760 bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
8761 if (iocbq->priority) {
8762 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
8763 (iocbq->priority << 1));
8765 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
8766 (phba->cfg_XLanePriority << 1));
8769 /* Note, word 10 is already initialized to 0 */
8771 if (phba->fcp_embed_io) {
8772 struct lpfc_scsi_buf *lpfc_cmd;
8773 struct sli4_sge *sgl;
8774 union lpfc_wqe128 *wqe128;
8775 struct fcp_cmnd *fcp_cmnd;
8778 /* 128 byte wqe support here */
8779 wqe128 = (union lpfc_wqe128 *)wqe;
8781 lpfc_cmd = iocbq->context1;
8782 sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
8783 fcp_cmnd = lpfc_cmd->fcp_cmnd;
8785 /* Word 0-2 - FCP_CMND */
8786 wqe128->generic.bde.tus.f.bdeFlags =
8787 BUFF_TYPE_BDE_IMMED;
8788 wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
8789 wqe128->generic.bde.addrHigh = 0;
8790 wqe128->generic.bde.addrLow = 88; /* Word 22 */
8792 bf_set(wqe_wqes, &wqe128->fcp_iread.wqe_com, 1);
8794 /* Word 22-29 FCP CMND Payload */
8795 ptr = &wqe128->words[22];
8796 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
8799 case CMD_FCP_ICMND64_CR:
8800 /* word3 iocb=iotag wqe=payload_offset_len */
8801 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8802 bf_set(payload_offset_len, &wqe->fcp_icmd,
8803 xmit_len + sizeof(struct fcp_rsp));
8804 bf_set(cmd_buff_len, &wqe->fcp_icmd,
8806 /* word3 iocb=IO_TAG wqe=reserved */
8807 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
8808 /* Always open the exchange */
8809 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
8810 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
8811 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
8812 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
8813 LPFC_WQE_LENLOC_NONE);
8814 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
8815 iocbq->iocb.ulpFCP2Rcvy);
8816 if (iocbq->iocb_flag & LPFC_IO_OAS) {
8817 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
8818 bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
8819 if (iocbq->priority) {
8820 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
8821 (iocbq->priority << 1));
8823 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
8824 (phba->cfg_XLanePriority << 1));
8827 /* Note, word 10 is already initialized to 0 */
8829 if (phba->fcp_embed_io) {
8830 struct lpfc_scsi_buf *lpfc_cmd;
8831 struct sli4_sge *sgl;
8832 union lpfc_wqe128 *wqe128;
8833 struct fcp_cmnd *fcp_cmnd;
8836 /* 128 byte wqe support here */
8837 wqe128 = (union lpfc_wqe128 *)wqe;
8839 lpfc_cmd = iocbq->context1;
8840 sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
8841 fcp_cmnd = lpfc_cmd->fcp_cmnd;
8843 /* Word 0-2 - FCP_CMND */
8844 wqe128->generic.bde.tus.f.bdeFlags =
8845 BUFF_TYPE_BDE_IMMED;
8846 wqe128->generic.bde.tus.f.bdeSize = sgl->sge_len;
8847 wqe128->generic.bde.addrHigh = 0;
8848 wqe128->generic.bde.addrLow = 88; /* Word 22 */
8850 bf_set(wqe_wqes, &wqe128->fcp_icmd.wqe_com, 1);
8852 /* Word 22-29 FCP CMND Payload */
8853 ptr = &wqe128->words[22];
8854 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
8857 case CMD_GEN_REQUEST64_CR:
8858 /* For this command calculate the xmit length of the
8862 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
8863 sizeof(struct ulp_bde64);
8864 for (i = 0; i < numBdes; i++) {
8865 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
8866 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
8868 xmit_len += bde.tus.f.bdeSize;
8870 /* word3 iocb=IO_TAG wqe=request_payload_len */
8871 wqe->gen_req.request_payload_len = xmit_len;
8872 /* word4 iocb=parameter wqe=relative_offset memcpy */
8873 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8874 /* word6 context tag copied in memcpy */
8875 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
8876 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
8877 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8878 "2015 Invalid CT %x command 0x%x\n",
8879 ct, iocbq->iocb.ulpCommand);
8882 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
8883 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
8884 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
8885 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
8886 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
8887 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
8888 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
8889 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
8890 wqe->gen_req.max_response_payload_len = total_len - xmit_len;
8891 command_type = OTHER_COMMAND;
8893 case CMD_XMIT_ELS_RSP64_CX:
8894 ndlp = (struct lpfc_nodelist *)iocbq->context1;
8895 /* words0-2 BDE memcpy */
8896 /* word3 iocb=iotag32 wqe=response_payload_len */
8897 wqe->xmit_els_rsp.response_payload_len = xmit_len;
8899 wqe->xmit_els_rsp.word4 = 0;
8900 /* word5 iocb=rsvd wge=did */
8901 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
8902 iocbq->iocb.un.xseq64.xmit_els_remoteID);
8904 if_type = bf_get(lpfc_sli_intf_if_type,
8905 &phba->sli4_hba.sli_intf);
8906 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8907 if (iocbq->vport->fc_flag & FC_PT2PT) {
8908 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
8909 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
8910 iocbq->vport->fc_myDID);
8911 if (iocbq->vport->fc_myDID == Fabric_DID) {
8913 &wqe->xmit_els_rsp.wqe_dest, 0);
8917 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
8918 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8919 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
8920 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
8921 iocbq->iocb.unsli3.rcvsli3.ox_id);
8922 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
8923 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
8924 phba->vpi_ids[iocbq->vport->vpi]);
8925 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
8926 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
8927 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
8928 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
8929 LPFC_WQE_LENLOC_WORD3);
8930 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
8931 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
8932 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
8933 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8934 iocbq->context2)->virt);
8935 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
8936 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
8937 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
8938 iocbq->vport->fc_myDID);
8939 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
8940 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
8941 phba->vpi_ids[phba->pport->vpi]);
8943 command_type = OTHER_COMMAND;
8945 case CMD_CLOSE_XRI_CN:
8946 case CMD_ABORT_XRI_CN:
8947 case CMD_ABORT_XRI_CX:
8948 /* words 0-2 memcpy should be 0 rserved */
8949 /* port will send abts */
8950 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
8951 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
8952 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
8953 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
8957 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
8959 * The link is down, or the command was ELS_FIP
8960 * so the fw does not need to send abts
8963 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
8965 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
8966 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
8967 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8968 wqe->abort_cmd.rsrvd5 = 0;
8969 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
8970 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
8971 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
8973 * The abort handler will send us CMD_ABORT_XRI_CN or
8974 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8976 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
8977 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
8978 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
8979 LPFC_WQE_LENLOC_NONE);
8980 cmnd = CMD_ABORT_XRI_CX;
8981 command_type = OTHER_COMMAND;
8984 case CMD_XMIT_BLS_RSP64_CX:
8985 ndlp = (struct lpfc_nodelist *)iocbq->context1;
8986 /* As BLS ABTS RSP WQE is very different from other WQEs,
8987 * we re-construct this WQE here based on information in
8988 * iocbq from scratch.
8990 memset(wqe, 0, sizeof(union lpfc_wqe));
8991 /* OX_ID is invariable to who sent ABTS to CT exchange */
8992 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
8993 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
8994 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
8995 LPFC_ABTS_UNSOL_INT) {
8996 /* ABTS sent by initiator to CT exchange, the
8997 * RX_ID field will be filled with the newly
8998 * allocated responder XRI.
9000 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
9001 iocbq->sli4_xritag);
9003 /* ABTS sent by responder to CT exchange, the
9004 * RX_ID field will be filled with the responder
9007 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
9008 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
9010 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
9011 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
9014 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
9016 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
9017 iocbq->iocb.ulpContext);
9018 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
9019 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
9020 phba->vpi_ids[phba->pport->vpi]);
9021 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
9022 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
9023 LPFC_WQE_LENLOC_NONE);
9024 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
9025 command_type = OTHER_COMMAND;
9026 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
9027 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
9028 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
9029 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
9030 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
9031 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
9032 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
9036 case CMD_XRI_ABORTED_CX:
9037 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
9038 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
9039 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
9040 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
9041 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
9043 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9044 "2014 Invalid command 0x%x\n",
9045 iocbq->iocb.ulpCommand);
9050 if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
9051 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
9052 else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
9053 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
9054 else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
9055 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
9056 iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
9057 LPFC_IO_DIF_INSERT);
9058 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
9059 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
9060 wqe->generic.wqe_com.abort_tag = abort_tag;
9061 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
9062 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
9063 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
9064 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
9069 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
9070 * @phba: Pointer to HBA context object.
9071 * @ring_number: SLI ring number to issue iocb on.
9072 * @piocb: Pointer to command iocb.
9073 * @flag: Flag indicating if this command can be put into txq.
9075 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
9076 * an iocb command to an HBA with SLI-4 interface spec.
9078 * This function is called with hbalock held. The function will return success
9079 * after it successfully submit the iocb to firmware or after adding to the
9083 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
9084 struct lpfc_iocbq *piocb, uint32_t flag)
9086 struct lpfc_sglq *sglq;
9087 union lpfc_wqe *wqe;
9088 union lpfc_wqe128 wqe128;
9089 struct lpfc_queue *wq;
9090 struct lpfc_sli_ring *pring;
9093 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
9094 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
9095 if (!phba->cfg_fof || (!(piocb->iocb_flag & LPFC_IO_OAS)))
9096 wq = phba->sli4_hba.fcp_wq[piocb->hba_wqidx];
9098 wq = phba->sli4_hba.oas_wq;
9100 wq = phba->sli4_hba.els_wq;
9103 /* Get corresponding ring */
9107 * The WQE can be either 64 or 128 bytes,
9108 * so allocate space on the stack assuming the largest.
9110 wqe = (union lpfc_wqe *)&wqe128;
9112 lockdep_assert_held(&phba->hbalock);
9114 if (piocb->sli4_xritag == NO_XRI) {
9115 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
9116 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
9119 if (!list_empty(&pring->txq)) {
9120 if (!(flag & SLI_IOCB_RET_IOCB)) {
9121 __lpfc_sli_ringtx_put(phba,
9123 return IOCB_SUCCESS;
9128 sglq = __lpfc_sli_get_els_sglq(phba, piocb);
9130 if (!(flag & SLI_IOCB_RET_IOCB)) {
9131 __lpfc_sli_ringtx_put(phba,
9134 return IOCB_SUCCESS;
9140 } else if (piocb->iocb_flag & LPFC_IO_FCP)
9141 /* These IO's already have an XRI and a mapped sgl. */
9145 * This is a continuation of a commandi,(CX) so this
9146 * sglq is on the active list
9148 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
9154 piocb->sli4_lxritag = sglq->sli4_lxritag;
9155 piocb->sli4_xritag = sglq->sli4_xritag;
9156 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
9160 if (lpfc_sli4_iocb2wqe(phba, piocb, wqe))
9163 if (lpfc_sli4_wq_put(wq, wqe))
9165 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
9171 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
9173 * This routine wraps the actual lockless version for issusing IOCB function
9174 * pointer from the lpfc_hba struct.
9177 * IOCB_ERROR - Error
9178 * IOCB_SUCCESS - Success
9182 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
9183 struct lpfc_iocbq *piocb, uint32_t flag)
9185 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
9189 * lpfc_sli_api_table_setup - Set up sli api function jump table
9190 * @phba: The hba struct for which this call is being executed.
9191 * @dev_grp: The HBA PCI-Device group number.
9193 * This routine sets up the SLI interface API function jump table in @phba
9195 * Returns: 0 - success, -ENODEV - failure.
9198 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
9202 case LPFC_PCI_DEV_LP:
9203 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
9204 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
9206 case LPFC_PCI_DEV_OC:
9207 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
9208 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
9211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9212 "1419 Invalid HBA PCI-device group: 0x%x\n",
9217 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
9222 * lpfc_sli4_calc_ring - Calculates which ring to use
9223 * @phba: Pointer to HBA context object.
9224 * @piocb: Pointer to command iocb.
9226 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
9227 * hba_wqidx, thus we need to calculate the corresponding ring.
9228 * Since ABORTS must go on the same WQ of the command they are
9229 * aborting, we use command's hba_wqidx.
9231 struct lpfc_sli_ring *
9232 lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
9234 if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
9235 if (!(phba->cfg_fof) ||
9236 (!(piocb->iocb_flag & LPFC_IO_FOF))) {
9237 if (unlikely(!phba->sli4_hba.fcp_wq))
9240 * for abort iocb hba_wqidx should already
9241 * be setup based on what work queue we used.
9243 if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX))
9245 lpfc_sli4_scmd_to_wqidx_distr(phba,
9247 return phba->sli4_hba.fcp_wq[piocb->hba_wqidx]->pring;
9249 if (unlikely(!phba->sli4_hba.oas_wq))
9251 piocb->hba_wqidx = 0;
9252 return phba->sli4_hba.oas_wq->pring;
9255 if (unlikely(!phba->sli4_hba.els_wq))
9257 piocb->hba_wqidx = 0;
9258 return phba->sli4_hba.els_wq->pring;
9263 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
9264 * @phba: Pointer to HBA context object.
9265 * @pring: Pointer to driver SLI ring object.
9266 * @piocb: Pointer to command iocb.
9267 * @flag: Flag indicating if this command can be put into txq.
9269 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
9270 * function. This function gets the hbalock and calls
9271 * __lpfc_sli_issue_iocb function and will return the error returned
9272 * by __lpfc_sli_issue_iocb function. This wrapper is used by
9273 * functions which do not hold hbalock.
9276 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
9277 struct lpfc_iocbq *piocb, uint32_t flag)
9279 struct lpfc_hba_eq_hdl *hba_eq_hdl;
9280 struct lpfc_sli_ring *pring;
9281 struct lpfc_queue *fpeq;
9282 struct lpfc_eqe *eqe;
9283 unsigned long iflags;
9286 if (phba->sli_rev == LPFC_SLI_REV4) {
9287 pring = lpfc_sli4_calc_ring(phba, piocb);
9288 if (unlikely(pring == NULL))
9291 spin_lock_irqsave(&pring->ring_lock, iflags);
9292 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
9293 spin_unlock_irqrestore(&pring->ring_lock, iflags);
9295 if (lpfc_fcp_look_ahead && (piocb->iocb_flag & LPFC_IO_FCP)) {
9296 idx = piocb->hba_wqidx;
9297 hba_eq_hdl = &phba->sli4_hba.hba_eq_hdl[idx];
9299 if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use)) {
9301 /* Get associated EQ with this index */
9302 fpeq = phba->sli4_hba.hba_eq[idx];
9304 /* Turn off interrupts from this EQ */
9305 lpfc_sli4_eq_clr_intr(fpeq);
9308 * Process all the events on FCP EQ
9310 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
9311 lpfc_sli4_hba_handle_eqe(phba,
9313 fpeq->EQ_processed++;
9316 /* Always clear and re-arm the EQ */
9317 lpfc_sli4_eq_release(fpeq,
9320 atomic_inc(&hba_eq_hdl->hba_eq_in_use);
9323 /* For now, SLI2/3 will still use hbalock */
9324 spin_lock_irqsave(&phba->hbalock, iflags);
9325 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
9326 spin_unlock_irqrestore(&phba->hbalock, iflags);
9332 * lpfc_extra_ring_setup - Extra ring setup function
9333 * @phba: Pointer to HBA context object.
9335 * This function is called while driver attaches with the
9336 * HBA to setup the extra ring. The extra ring is used
9337 * only when driver needs to support target mode functionality
9338 * or IP over FC functionalities.
9340 * This function is called with no lock held. SLI3 only.
9343 lpfc_extra_ring_setup( struct lpfc_hba *phba)
9345 struct lpfc_sli *psli;
9346 struct lpfc_sli_ring *pring;
9350 /* Adjust cmd/rsp ring iocb entries more evenly */
9352 /* Take some away from the FCP ring */
9353 pring = &psli->sli3_ring[LPFC_FCP_RING];
9354 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
9355 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
9356 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
9357 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
9359 /* and give them to the extra ring */
9360 pring = &psli->sli3_ring[LPFC_EXTRA_RING];
9362 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
9363 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
9364 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
9365 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
9367 /* Setup default profile for this ring */
9368 pring->iotag_max = 4096;
9369 pring->num_mask = 1;
9370 pring->prt[0].profile = 0; /* Mask 0 */
9371 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
9372 pring->prt[0].type = phba->cfg_multi_ring_type;
9373 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
9377 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
9378 * @phba: Pointer to HBA context object.
9379 * @iocbq: Pointer to iocb object.
9381 * The async_event handler calls this routine when it receives
9382 * an ASYNC_STATUS_CN event from the port. The port generates
9383 * this event when an Abort Sequence request to an rport fails
9384 * twice in succession. The abort could be originated by the
9385 * driver or by the port. The ABTS could have been for an ELS
9386 * or FCP IO. The port only generates this event when an ABTS
9387 * fails to complete after one retry.
9390 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
9391 struct lpfc_iocbq *iocbq)
9393 struct lpfc_nodelist *ndlp = NULL;
9394 uint16_t rpi = 0, vpi = 0;
9395 struct lpfc_vport *vport = NULL;
9397 /* The rpi in the ulpContext is vport-sensitive. */
9398 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
9399 rpi = iocbq->iocb.ulpContext;
9401 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9402 "3092 Port generated ABTS async event "
9403 "on vpi %d rpi %d status 0x%x\n",
9404 vpi, rpi, iocbq->iocb.ulpStatus);
9406 vport = lpfc_find_vport_by_vpid(phba, vpi);
9409 ndlp = lpfc_findnode_rpi(vport, rpi);
9410 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
9413 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
9414 lpfc_sli_abts_recover_port(vport, ndlp);
9418 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9419 "3095 Event Context not found, no "
9420 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
9421 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
9425 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
9426 * @phba: pointer to HBA context object.
9427 * @ndlp: nodelist pointer for the impacted rport.
9428 * @axri: pointer to the wcqe containing the failed exchange.
9430 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
9431 * port. The port generates this event when an abort exchange request to an
9432 * rport fails twice in succession with no reply. The abort could be originated
9433 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
9436 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
9437 struct lpfc_nodelist *ndlp,
9438 struct sli4_wcqe_xri_aborted *axri)
9440 struct lpfc_vport *vport;
9441 uint32_t ext_status = 0;
9443 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
9444 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9445 "3115 Node Context not found, driver "
9446 "ignoring abts err event\n");
9450 vport = ndlp->vport;
9451 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
9452 "3116 Port generated FCP XRI ABORT event on "
9453 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
9454 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
9455 bf_get(lpfc_wcqe_xa_xri, axri),
9456 bf_get(lpfc_wcqe_xa_status, axri),
9460 * Catch the ABTS protocol failure case. Older OCe FW releases returned
9461 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
9462 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
9464 ext_status = axri->parameter & IOERR_PARAM_MASK;
9465 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
9466 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
9467 lpfc_sli_abts_recover_port(vport, ndlp);
9471 * lpfc_sli_async_event_handler - ASYNC iocb handler function
9472 * @phba: Pointer to HBA context object.
9473 * @pring: Pointer to driver SLI ring object.
9474 * @iocbq: Pointer to iocb object.
9476 * This function is called by the slow ring event handler
9477 * function when there is an ASYNC event iocb in the ring.
9478 * This function is called with no lock held.
9479 * Currently this function handles only temperature related
9480 * ASYNC events. The function decodes the temperature sensor
9481 * event message and posts events for the management applications.
9484 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
9485 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
9489 struct temp_event temp_event_data;
9490 struct Scsi_Host *shost;
9493 icmd = &iocbq->iocb;
9494 evt_code = icmd->un.asyncstat.evt_code;
9497 case ASYNC_TEMP_WARN:
9498 case ASYNC_TEMP_SAFE:
9499 temp_event_data.data = (uint32_t) icmd->ulpContext;
9500 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
9501 if (evt_code == ASYNC_TEMP_WARN) {
9502 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
9503 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
9504 "0347 Adapter is very hot, please take "
9505 "corrective action. temperature : %d Celsius\n",
9506 (uint32_t) icmd->ulpContext);
9508 temp_event_data.event_code = LPFC_NORMAL_TEMP;
9509 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
9510 "0340 Adapter temperature is OK now. "
9511 "temperature : %d Celsius\n",
9512 (uint32_t) icmd->ulpContext);
9515 /* Send temperature change event to applications */
9516 shost = lpfc_shost_from_vport(phba->pport);
9517 fc_host_post_vendor_event(shost, fc_get_event_number(),
9518 sizeof(temp_event_data), (char *) &temp_event_data,
9521 case ASYNC_STATUS_CN:
9522 lpfc_sli_abts_err_handler(phba, iocbq);
9525 iocb_w = (uint32_t *) icmd;
9526 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9527 "0346 Ring %d handler: unexpected ASYNC_STATUS"
9529 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9530 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9531 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9532 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
9533 pring->ringno, icmd->un.asyncstat.evt_code,
9534 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
9535 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
9536 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
9537 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
9545 * lpfc_sli4_setup - SLI ring setup function
9546 * @phba: Pointer to HBA context object.
9548 * lpfc_sli_setup sets up rings of the SLI interface with
9549 * number of iocbs per ring and iotags. This function is
9550 * called while driver attach to the HBA and before the
9551 * interrupts are enabled. So there is no need for locking.
9553 * This function always returns 0.
9556 lpfc_sli4_setup(struct lpfc_hba *phba)
9558 struct lpfc_sli_ring *pring;
9560 pring = phba->sli4_hba.els_wq->pring;
9561 pring->num_mask = LPFC_MAX_RING_MASK;
9562 pring->prt[0].profile = 0; /* Mask 0 */
9563 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
9564 pring->prt[0].type = FC_TYPE_ELS;
9565 pring->prt[0].lpfc_sli_rcv_unsol_event =
9566 lpfc_els_unsol_event;
9567 pring->prt[1].profile = 0; /* Mask 1 */
9568 pring->prt[1].rctl = FC_RCTL_ELS_REP;
9569 pring->prt[1].type = FC_TYPE_ELS;
9570 pring->prt[1].lpfc_sli_rcv_unsol_event =
9571 lpfc_els_unsol_event;
9572 pring->prt[2].profile = 0; /* Mask 2 */
9573 /* NameServer Inquiry */
9574 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
9576 pring->prt[2].type = FC_TYPE_CT;
9577 pring->prt[2].lpfc_sli_rcv_unsol_event =
9578 lpfc_ct_unsol_event;
9579 pring->prt[3].profile = 0; /* Mask 3 */
9580 /* NameServer response */
9581 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
9583 pring->prt[3].type = FC_TYPE_CT;
9584 pring->prt[3].lpfc_sli_rcv_unsol_event =
9585 lpfc_ct_unsol_event;
9590 * lpfc_sli_setup - SLI ring setup function
9591 * @phba: Pointer to HBA context object.
9593 * lpfc_sli_setup sets up rings of the SLI interface with
9594 * number of iocbs per ring and iotags. This function is
9595 * called while driver attach to the HBA and before the
9596 * interrupts are enabled. So there is no need for locking.
9598 * This function always returns 0. SLI3 only.
9601 lpfc_sli_setup(struct lpfc_hba *phba)
9603 int i, totiocbsize = 0;
9604 struct lpfc_sli *psli = &phba->sli;
9605 struct lpfc_sli_ring *pring;
9607 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
9610 psli->iocbq_lookup = NULL;
9611 psli->iocbq_lookup_len = 0;
9612 psli->last_iotag = 0;
9614 for (i = 0; i < psli->num_rings; i++) {
9615 pring = &psli->sli3_ring[i];
9617 case LPFC_FCP_RING: /* ring 0 - FCP */
9618 /* numCiocb and numRiocb are used in config_port */
9619 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
9620 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
9621 pring->sli.sli3.numCiocb +=
9622 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
9623 pring->sli.sli3.numRiocb +=
9624 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
9625 pring->sli.sli3.numCiocb +=
9626 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
9627 pring->sli.sli3.numRiocb +=
9628 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
9629 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
9630 SLI3_IOCB_CMD_SIZE :
9632 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
9633 SLI3_IOCB_RSP_SIZE :
9635 pring->iotag_ctr = 0;
9637 (phba->cfg_hba_queue_depth * 2);
9638 pring->fast_iotag = pring->iotag_max;
9639 pring->num_mask = 0;
9641 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
9642 /* numCiocb and numRiocb are used in config_port */
9643 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
9644 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
9645 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
9646 SLI3_IOCB_CMD_SIZE :
9648 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
9649 SLI3_IOCB_RSP_SIZE :
9651 pring->iotag_max = phba->cfg_hba_queue_depth;
9652 pring->num_mask = 0;
9654 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
9655 /* numCiocb and numRiocb are used in config_port */
9656 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
9657 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
9658 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
9659 SLI3_IOCB_CMD_SIZE :
9661 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
9662 SLI3_IOCB_RSP_SIZE :
9664 pring->fast_iotag = 0;
9665 pring->iotag_ctr = 0;
9666 pring->iotag_max = 4096;
9667 pring->lpfc_sli_rcv_async_status =
9668 lpfc_sli_async_event_handler;
9669 pring->num_mask = LPFC_MAX_RING_MASK;
9670 pring->prt[0].profile = 0; /* Mask 0 */
9671 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
9672 pring->prt[0].type = FC_TYPE_ELS;
9673 pring->prt[0].lpfc_sli_rcv_unsol_event =
9674 lpfc_els_unsol_event;
9675 pring->prt[1].profile = 0; /* Mask 1 */
9676 pring->prt[1].rctl = FC_RCTL_ELS_REP;
9677 pring->prt[1].type = FC_TYPE_ELS;
9678 pring->prt[1].lpfc_sli_rcv_unsol_event =
9679 lpfc_els_unsol_event;
9680 pring->prt[2].profile = 0; /* Mask 2 */
9681 /* NameServer Inquiry */
9682 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
9684 pring->prt[2].type = FC_TYPE_CT;
9685 pring->prt[2].lpfc_sli_rcv_unsol_event =
9686 lpfc_ct_unsol_event;
9687 pring->prt[3].profile = 0; /* Mask 3 */
9688 /* NameServer response */
9689 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
9691 pring->prt[3].type = FC_TYPE_CT;
9692 pring->prt[3].lpfc_sli_rcv_unsol_event =
9693 lpfc_ct_unsol_event;
9696 totiocbsize += (pring->sli.sli3.numCiocb *
9697 pring->sli.sli3.sizeCiocb) +
9698 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
9700 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
9701 /* Too many cmd / rsp ring entries in SLI2 SLIM */
9702 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
9703 "SLI2 SLIM Data: x%x x%lx\n",
9704 phba->brd_no, totiocbsize,
9705 (unsigned long) MAX_SLIM_IOCB_SIZE);
9707 if (phba->cfg_multi_ring_support == 2)
9708 lpfc_extra_ring_setup(phba);
9714 * lpfc_sli4_queue_init - Queue initialization function
9715 * @phba: Pointer to HBA context object.
9717 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
9718 * ring. This function also initializes ring indices of each ring.
9719 * This function is called during the initialization of the SLI
9720 * interface of an HBA.
9721 * This function is called with no lock held and always returns
9725 lpfc_sli4_queue_init(struct lpfc_hba *phba)
9727 struct lpfc_sli *psli;
9728 struct lpfc_sli_ring *pring;
9732 spin_lock_irq(&phba->hbalock);
9733 INIT_LIST_HEAD(&psli->mboxq);
9734 INIT_LIST_HEAD(&psli->mboxq_cmpl);
9735 /* Initialize list headers for txq and txcmplq as double linked lists */
9736 for (i = 0; i < phba->cfg_fcp_io_channel; i++) {
9737 pring = phba->sli4_hba.fcp_wq[i]->pring;
9739 pring->ringno = LPFC_FCP_RING;
9740 INIT_LIST_HEAD(&pring->txq);
9741 INIT_LIST_HEAD(&pring->txcmplq);
9742 INIT_LIST_HEAD(&pring->iocb_continueq);
9743 spin_lock_init(&pring->ring_lock);
9745 for (i = 0; i < phba->cfg_nvme_io_channel; i++) {
9746 pring = phba->sli4_hba.nvme_wq[i]->pring;
9748 pring->ringno = LPFC_FCP_RING;
9749 INIT_LIST_HEAD(&pring->txq);
9750 INIT_LIST_HEAD(&pring->txcmplq);
9751 INIT_LIST_HEAD(&pring->iocb_continueq);
9752 spin_lock_init(&pring->ring_lock);
9754 pring = phba->sli4_hba.els_wq->pring;
9756 pring->ringno = LPFC_ELS_RING;
9757 INIT_LIST_HEAD(&pring->txq);
9758 INIT_LIST_HEAD(&pring->txcmplq);
9759 INIT_LIST_HEAD(&pring->iocb_continueq);
9760 spin_lock_init(&pring->ring_lock);
9762 if (phba->cfg_nvme_io_channel) {
9763 pring = phba->sli4_hba.nvmels_wq->pring;
9765 pring->ringno = LPFC_ELS_RING;
9766 INIT_LIST_HEAD(&pring->txq);
9767 INIT_LIST_HEAD(&pring->txcmplq);
9768 INIT_LIST_HEAD(&pring->iocb_continueq);
9769 spin_lock_init(&pring->ring_lock);
9772 if (phba->cfg_fof) {
9773 pring = phba->sli4_hba.oas_wq->pring;
9775 pring->ringno = LPFC_FCP_RING;
9776 INIT_LIST_HEAD(&pring->txq);
9777 INIT_LIST_HEAD(&pring->txcmplq);
9778 INIT_LIST_HEAD(&pring->iocb_continueq);
9779 spin_lock_init(&pring->ring_lock);
9782 spin_unlock_irq(&phba->hbalock);
9786 * lpfc_sli_queue_init - Queue initialization function
9787 * @phba: Pointer to HBA context object.
9789 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
9790 * ring. This function also initializes ring indices of each ring.
9791 * This function is called during the initialization of the SLI
9792 * interface of an HBA.
9793 * This function is called with no lock held and always returns
9797 lpfc_sli_queue_init(struct lpfc_hba *phba)
9799 struct lpfc_sli *psli;
9800 struct lpfc_sli_ring *pring;
9804 spin_lock_irq(&phba->hbalock);
9805 INIT_LIST_HEAD(&psli->mboxq);
9806 INIT_LIST_HEAD(&psli->mboxq_cmpl);
9807 /* Initialize list headers for txq and txcmplq as double linked lists */
9808 for (i = 0; i < psli->num_rings; i++) {
9809 pring = &psli->sli3_ring[i];
9811 pring->sli.sli3.next_cmdidx = 0;
9812 pring->sli.sli3.local_getidx = 0;
9813 pring->sli.sli3.cmdidx = 0;
9814 INIT_LIST_HEAD(&pring->iocb_continueq);
9815 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
9816 INIT_LIST_HEAD(&pring->postbufq);
9818 INIT_LIST_HEAD(&pring->txq);
9819 INIT_LIST_HEAD(&pring->txcmplq);
9820 spin_lock_init(&pring->ring_lock);
9822 spin_unlock_irq(&phba->hbalock);
9826 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9827 * @phba: Pointer to HBA context object.
9829 * This routine flushes the mailbox command subsystem. It will unconditionally
9830 * flush all the mailbox commands in the three possible stages in the mailbox
9831 * command sub-system: pending mailbox command queue; the outstanding mailbox
9832 * command; and completed mailbox command queue. It is caller's responsibility
9833 * to make sure that the driver is in the proper state to flush the mailbox
9834 * command sub-system. Namely, the posting of mailbox commands into the
9835 * pending mailbox command queue from the various clients must be stopped;
9836 * either the HBA is in a state that it will never works on the outstanding
9837 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
9838 * mailbox command has been completed.
9841 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
9843 LIST_HEAD(completions);
9844 struct lpfc_sli *psli = &phba->sli;
9846 unsigned long iflag;
9848 /* Flush all the mailbox commands in the mbox system */
9849 spin_lock_irqsave(&phba->hbalock, iflag);
9850 /* The pending mailbox command queue */
9851 list_splice_init(&phba->sli.mboxq, &completions);
9852 /* The outstanding active mailbox command */
9853 if (psli->mbox_active) {
9854 list_add_tail(&psli->mbox_active->list, &completions);
9855 psli->mbox_active = NULL;
9856 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9858 /* The completed mailbox command queue */
9859 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
9860 spin_unlock_irqrestore(&phba->hbalock, iflag);
9862 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
9863 while (!list_empty(&completions)) {
9864 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
9865 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
9867 pmb->mbox_cmpl(phba, pmb);
9872 * lpfc_sli_host_down - Vport cleanup function
9873 * @vport: Pointer to virtual port object.
9875 * lpfc_sli_host_down is called to clean up the resources
9876 * associated with a vport before destroying virtual
9877 * port data structures.
9878 * This function does following operations:
9879 * - Free discovery resources associated with this virtual
9881 * - Free iocbs associated with this virtual port in
9883 * - Send abort for all iocb commands associated with this
9886 * This function is called with no lock held and always returns 1.
9889 lpfc_sli_host_down(struct lpfc_vport *vport)
9891 LIST_HEAD(completions);
9892 struct lpfc_hba *phba = vport->phba;
9893 struct lpfc_sli *psli = &phba->sli;
9894 struct lpfc_queue *qp = NULL;
9895 struct lpfc_sli_ring *pring;
9896 struct lpfc_iocbq *iocb, *next_iocb;
9898 unsigned long flags = 0;
9899 uint16_t prev_pring_flag;
9901 lpfc_cleanup_discovery_resources(vport);
9903 spin_lock_irqsave(&phba->hbalock, flags);
9906 * Error everything on the txq since these iocbs
9907 * have not been given to the FW yet.
9908 * Also issue ABTS for everything on the txcmplq
9910 if (phba->sli_rev != LPFC_SLI_REV4) {
9911 for (i = 0; i < psli->num_rings; i++) {
9912 pring = &psli->sli3_ring[i];
9913 prev_pring_flag = pring->flag;
9914 /* Only slow rings */
9915 if (pring->ringno == LPFC_ELS_RING) {
9916 pring->flag |= LPFC_DEFERRED_RING_EVENT;
9917 /* Set the lpfc data pending flag */
9918 set_bit(LPFC_DATA_READY, &phba->data_flags);
9920 list_for_each_entry_safe(iocb, next_iocb,
9921 &pring->txq, list) {
9922 if (iocb->vport != vport)
9924 list_move_tail(&iocb->list, &completions);
9926 list_for_each_entry_safe(iocb, next_iocb,
9927 &pring->txcmplq, list) {
9928 if (iocb->vport != vport)
9930 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
9932 pring->flag = prev_pring_flag;
9935 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
9939 if (pring == phba->sli4_hba.els_wq->pring) {
9940 pring->flag |= LPFC_DEFERRED_RING_EVENT;
9941 /* Set the lpfc data pending flag */
9942 set_bit(LPFC_DATA_READY, &phba->data_flags);
9944 prev_pring_flag = pring->flag;
9945 spin_lock_irq(&pring->ring_lock);
9946 list_for_each_entry_safe(iocb, next_iocb,
9947 &pring->txq, list) {
9948 if (iocb->vport != vport)
9950 list_move_tail(&iocb->list, &completions);
9952 spin_unlock_irq(&pring->ring_lock);
9953 list_for_each_entry_safe(iocb, next_iocb,
9954 &pring->txcmplq, list) {
9955 if (iocb->vport != vport)
9957 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
9959 pring->flag = prev_pring_flag;
9962 spin_unlock_irqrestore(&phba->hbalock, flags);
9964 /* Cancel all the IOCBs from the completions list */
9965 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9971 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9972 * @phba: Pointer to HBA context object.
9974 * This function cleans up all iocb, buffers, mailbox commands
9975 * while shutting down the HBA. This function is called with no
9976 * lock held and always returns 1.
9977 * This function does the following to cleanup driver resources:
9978 * - Free discovery resources for each virtual port
9979 * - Cleanup any pending fabric iocbs
9980 * - Iterate through the iocb txq and free each entry
9982 * - Free up any buffer posted to the HBA
9983 * - Free mailbox commands in the mailbox queue.
9986 lpfc_sli_hba_down(struct lpfc_hba *phba)
9988 LIST_HEAD(completions);
9989 struct lpfc_sli *psli = &phba->sli;
9990 struct lpfc_queue *qp = NULL;
9991 struct lpfc_sli_ring *pring;
9992 struct lpfc_dmabuf *buf_ptr;
9993 unsigned long flags = 0;
9996 /* Shutdown the mailbox command sub-system */
9997 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
9999 lpfc_hba_down_prep(phba);
10001 lpfc_fabric_abort_hba(phba);
10003 spin_lock_irqsave(&phba->hbalock, flags);
10006 * Error everything on the txq since these iocbs
10007 * have not been given to the FW yet.
10009 if (phba->sli_rev != LPFC_SLI_REV4) {
10010 for (i = 0; i < psli->num_rings; i++) {
10011 pring = &psli->sli3_ring[i];
10012 /* Only slow rings */
10013 if (pring->ringno == LPFC_ELS_RING) {
10014 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10015 /* Set the lpfc data pending flag */
10016 set_bit(LPFC_DATA_READY, &phba->data_flags);
10018 list_splice_init(&pring->txq, &completions);
10021 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
10025 spin_lock_irq(&pring->ring_lock);
10026 list_splice_init(&pring->txq, &completions);
10027 spin_unlock_irq(&pring->ring_lock);
10028 if (pring == phba->sli4_hba.els_wq->pring) {
10029 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10030 /* Set the lpfc data pending flag */
10031 set_bit(LPFC_DATA_READY, &phba->data_flags);
10035 spin_unlock_irqrestore(&phba->hbalock, flags);
10037 /* Cancel all the IOCBs from the completions list */
10038 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10041 spin_lock_irqsave(&phba->hbalock, flags);
10042 list_splice_init(&phba->elsbuf, &completions);
10043 phba->elsbuf_cnt = 0;
10044 phba->elsbuf_prev_cnt = 0;
10045 spin_unlock_irqrestore(&phba->hbalock, flags);
10047 while (!list_empty(&completions)) {
10048 list_remove_head(&completions, buf_ptr,
10049 struct lpfc_dmabuf, list);
10050 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
10054 /* Return any active mbox cmds */
10055 del_timer_sync(&psli->mbox_tmo);
10057 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
10058 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
10059 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
10065 * lpfc_sli_pcimem_bcopy - SLI memory copy function
10066 * @srcp: Source memory pointer.
10067 * @destp: Destination memory pointer.
10068 * @cnt: Number of words required to be copied.
10070 * This function is used for copying data between driver memory
10071 * and the SLI memory. This function also changes the endianness
10072 * of each word if native endianness is different from SLI
10073 * endianness. This function can be called with or without
10077 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
10079 uint32_t *src = srcp;
10080 uint32_t *dest = destp;
10084 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
10086 ldata = le32_to_cpu(ldata);
10095 * lpfc_sli_bemem_bcopy - SLI memory copy function
10096 * @srcp: Source memory pointer.
10097 * @destp: Destination memory pointer.
10098 * @cnt: Number of words required to be copied.
10100 * This function is used for copying data between a data structure
10101 * with big endian representation to local endianness.
10102 * This function can be called with or without lock.
10105 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
10107 uint32_t *src = srcp;
10108 uint32_t *dest = destp;
10112 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
10114 ldata = be32_to_cpu(ldata);
10122 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
10123 * @phba: Pointer to HBA context object.
10124 * @pring: Pointer to driver SLI ring object.
10125 * @mp: Pointer to driver buffer object.
10127 * This function is called with no lock held.
10128 * It always return zero after adding the buffer to the postbufq
10132 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10133 struct lpfc_dmabuf *mp)
10135 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
10137 spin_lock_irq(&phba->hbalock);
10138 list_add_tail(&mp->list, &pring->postbufq);
10139 pring->postbufq_cnt++;
10140 spin_unlock_irq(&phba->hbalock);
10145 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
10146 * @phba: Pointer to HBA context object.
10148 * When HBQ is enabled, buffers are searched based on tags. This function
10149 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
10150 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
10151 * does not conflict with tags of buffer posted for unsolicited events.
10152 * The function returns the allocated tag. The function is called with
10156 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
10158 spin_lock_irq(&phba->hbalock);
10159 phba->buffer_tag_count++;
10161 * Always set the QUE_BUFTAG_BIT to distiguish between
10162 * a tag assigned by HBQ.
10164 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
10165 spin_unlock_irq(&phba->hbalock);
10166 return phba->buffer_tag_count;
10170 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
10171 * @phba: Pointer to HBA context object.
10172 * @pring: Pointer to driver SLI ring object.
10173 * @tag: Buffer tag.
10175 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
10176 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
10177 * iocb is posted to the response ring with the tag of the buffer.
10178 * This function searches the pring->postbufq list using the tag
10179 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
10180 * iocb. If the buffer is found then lpfc_dmabuf object of the
10181 * buffer is returned to the caller else NULL is returned.
10182 * This function is called with no lock held.
10184 struct lpfc_dmabuf *
10185 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10188 struct lpfc_dmabuf *mp, *next_mp;
10189 struct list_head *slp = &pring->postbufq;
10191 /* Search postbufq, from the beginning, looking for a match on tag */
10192 spin_lock_irq(&phba->hbalock);
10193 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
10194 if (mp->buffer_tag == tag) {
10195 list_del_init(&mp->list);
10196 pring->postbufq_cnt--;
10197 spin_unlock_irq(&phba->hbalock);
10202 spin_unlock_irq(&phba->hbalock);
10203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10204 "0402 Cannot find virtual addr for buffer tag on "
10205 "ring %d Data x%lx x%p x%p x%x\n",
10206 pring->ringno, (unsigned long) tag,
10207 slp->next, slp->prev, pring->postbufq_cnt);
10213 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
10214 * @phba: Pointer to HBA context object.
10215 * @pring: Pointer to driver SLI ring object.
10216 * @phys: DMA address of the buffer.
10218 * This function searches the buffer list using the dma_address
10219 * of unsolicited event to find the driver's lpfc_dmabuf object
10220 * corresponding to the dma_address. The function returns the
10221 * lpfc_dmabuf object if a buffer is found else it returns NULL.
10222 * This function is called by the ct and els unsolicited event
10223 * handlers to get the buffer associated with the unsolicited
10226 * This function is called with no lock held.
10228 struct lpfc_dmabuf *
10229 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10232 struct lpfc_dmabuf *mp, *next_mp;
10233 struct list_head *slp = &pring->postbufq;
10235 /* Search postbufq, from the beginning, looking for a match on phys */
10236 spin_lock_irq(&phba->hbalock);
10237 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
10238 if (mp->phys == phys) {
10239 list_del_init(&mp->list);
10240 pring->postbufq_cnt--;
10241 spin_unlock_irq(&phba->hbalock);
10246 spin_unlock_irq(&phba->hbalock);
10247 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10248 "0410 Cannot find virtual addr for mapped buf on "
10249 "ring %d Data x%llx x%p x%p x%x\n",
10250 pring->ringno, (unsigned long long)phys,
10251 slp->next, slp->prev, pring->postbufq_cnt);
10256 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
10257 * @phba: Pointer to HBA context object.
10258 * @cmdiocb: Pointer to driver command iocb object.
10259 * @rspiocb: Pointer to driver response iocb object.
10261 * This function is the completion handler for the abort iocbs for
10262 * ELS commands. This function is called from the ELS ring event
10263 * handler with no lock held. This function frees memory resources
10264 * associated with the abort iocb.
10267 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10268 struct lpfc_iocbq *rspiocb)
10270 IOCB_t *irsp = &rspiocb->iocb;
10271 uint16_t abort_iotag, abort_context;
10272 struct lpfc_iocbq *abort_iocb = NULL;
10274 if (irsp->ulpStatus) {
10277 * Assume that the port already completed and returned, or
10278 * will return the iocb. Just Log the message.
10280 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
10281 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
10283 spin_lock_irq(&phba->hbalock);
10284 if (phba->sli_rev < LPFC_SLI_REV4) {
10285 if (abort_iotag != 0 &&
10286 abort_iotag <= phba->sli.last_iotag)
10288 phba->sli.iocbq_lookup[abort_iotag];
10290 /* For sli4 the abort_tag is the XRI,
10291 * so the abort routine puts the iotag of the iocb
10292 * being aborted in the context field of the abort
10295 abort_iocb = phba->sli.iocbq_lookup[abort_context];
10297 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
10298 "0327 Cannot abort els iocb %p "
10299 "with tag %x context %x, abort status %x, "
10301 abort_iocb, abort_iotag, abort_context,
10302 irsp->ulpStatus, irsp->un.ulpWord[4]);
10304 spin_unlock_irq(&phba->hbalock);
10306 lpfc_sli_release_iocbq(phba, cmdiocb);
10311 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
10312 * @phba: Pointer to HBA context object.
10313 * @cmdiocb: Pointer to driver command iocb object.
10314 * @rspiocb: Pointer to driver response iocb object.
10316 * The function is called from SLI ring event handler with no
10317 * lock held. This function is the completion handler for ELS commands
10318 * which are aborted. The function frees memory resources used for
10319 * the aborted ELS commands.
10322 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10323 struct lpfc_iocbq *rspiocb)
10325 IOCB_t *irsp = &rspiocb->iocb;
10327 /* ELS cmd tag <ulpIoTag> completes */
10328 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
10329 "0139 Ignoring ELS cmd tag x%x completion Data: "
10331 irsp->ulpIoTag, irsp->ulpStatus,
10332 irsp->un.ulpWord[4], irsp->ulpTimeout);
10333 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
10334 lpfc_ct_free_iocb(phba, cmdiocb);
10336 lpfc_els_free_iocb(phba, cmdiocb);
10341 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
10342 * @phba: Pointer to HBA context object.
10343 * @pring: Pointer to driver SLI ring object.
10344 * @cmdiocb: Pointer to driver command iocb object.
10346 * This function issues an abort iocb for the provided command iocb down to
10347 * the port. Other than the case the outstanding command iocb is an abort
10348 * request, this function issues abort out unconditionally. This function is
10349 * called with hbalock held. The function returns 0 when it fails due to
10350 * memory allocation failure or when the command iocb is an abort request.
10353 lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10354 struct lpfc_iocbq *cmdiocb)
10356 struct lpfc_vport *vport = cmdiocb->vport;
10357 struct lpfc_iocbq *abtsiocbp;
10358 IOCB_t *icmd = NULL;
10359 IOCB_t *iabt = NULL;
10361 unsigned long iflags;
10363 lockdep_assert_held(&phba->hbalock);
10366 * There are certain command types we don't want to abort. And we
10367 * don't want to abort commands that are already in the process of
10370 icmd = &cmdiocb->iocb;
10371 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
10372 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
10373 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
10376 /* issue ABTS for this IOCB based on iotag */
10377 abtsiocbp = __lpfc_sli_get_iocbq(phba);
10378 if (abtsiocbp == NULL)
10381 /* This signals the response to set the correct status
10382 * before calling the completion handler
10384 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
10386 iabt = &abtsiocbp->iocb;
10387 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
10388 iabt->un.acxri.abortContextTag = icmd->ulpContext;
10389 if (phba->sli_rev == LPFC_SLI_REV4) {
10390 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
10391 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
10394 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
10396 iabt->ulpClass = icmd->ulpClass;
10398 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10399 abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
10400 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
10401 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
10402 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
10403 abtsiocbp->iocb_flag |= LPFC_IO_FOF;
10405 if (phba->link_state >= LPFC_LINK_UP)
10406 iabt->ulpCommand = CMD_ABORT_XRI_CN;
10408 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
10410 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
10411 abtsiocbp->vport = vport;
10413 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
10414 "0339 Abort xri x%x, original iotag x%x, "
10415 "abort cmd iotag x%x\n",
10416 iabt->un.acxri.abortIoTag,
10417 iabt->un.acxri.abortContextTag,
10420 if (phba->sli_rev == LPFC_SLI_REV4) {
10421 pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
10422 if (unlikely(pring == NULL))
10424 /* Note: both hbalock and ring_lock need to be set here */
10425 spin_lock_irqsave(&pring->ring_lock, iflags);
10426 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
10428 spin_unlock_irqrestore(&pring->ring_lock, iflags);
10430 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
10435 __lpfc_sli_release_iocbq(phba, abtsiocbp);
10438 * Caller to this routine should check for IOCB_ERROR
10439 * and handle it properly. This routine no longer removes
10440 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10446 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
10447 * @phba: Pointer to HBA context object.
10448 * @pring: Pointer to driver SLI ring object.
10449 * @cmdiocb: Pointer to driver command iocb object.
10451 * This function issues an abort iocb for the provided command iocb. In case
10452 * of unloading, the abort iocb will not be issued to commands on the ELS
10453 * ring. Instead, the callback function shall be changed to those commands
10454 * so that nothing happens when them finishes. This function is called with
10455 * hbalock held. The function returns 0 when the command iocb is an abort
10459 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10460 struct lpfc_iocbq *cmdiocb)
10462 struct lpfc_vport *vport = cmdiocb->vport;
10463 int retval = IOCB_ERROR;
10464 IOCB_t *icmd = NULL;
10466 lockdep_assert_held(&phba->hbalock);
10469 * There are certain command types we don't want to abort. And we
10470 * don't want to abort commands that are already in the process of
10473 icmd = &cmdiocb->iocb;
10474 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
10475 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
10476 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
10480 * If we're unloading, don't abort iocb on the ELS ring, but change
10481 * the callback so that nothing happens when it finishes.
10483 if ((vport->load_flag & FC_UNLOADING) &&
10484 (pring->ringno == LPFC_ELS_RING)) {
10485 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
10486 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
10488 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
10489 goto abort_iotag_exit;
10492 /* Now, we try to issue the abort to the cmdiocb out */
10493 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
10497 * Caller to this routine should check for IOCB_ERROR
10498 * and handle it properly. This routine no longer removes
10499 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10505 * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb
10506 * @phba: Pointer to HBA context object.
10507 * @pring: Pointer to driver SLI ring object.
10508 * @cmdiocb: Pointer to driver command iocb object.
10510 * This function issues an abort iocb for the provided command iocb down to
10511 * the port. Other than the case the outstanding command iocb is an abort
10512 * request, this function issues abort out unconditionally. This function is
10513 * called with hbalock held. The function returns 0 when it fails due to
10514 * memory allocation failure or when the command iocb is an abort request.
10517 lpfc_sli4_abort_nvme_io(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10518 struct lpfc_iocbq *cmdiocb)
10520 struct lpfc_vport *vport = cmdiocb->vport;
10521 struct lpfc_iocbq *abtsiocbp;
10522 union lpfc_wqe *abts_wqe;
10526 * There are certain command types we don't want to abort. And we
10527 * don't want to abort commands that are already in the process of
10530 if (cmdiocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
10531 cmdiocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN ||
10532 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
10535 /* issue ABTS for this io based on iotag */
10536 abtsiocbp = __lpfc_sli_get_iocbq(phba);
10537 if (abtsiocbp == NULL)
10540 /* This signals the response to set the correct status
10541 * before calling the completion handler
10543 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
10545 /* Complete prepping the abort wqe and issue to the FW. */
10546 abts_wqe = &abtsiocbp->wqe;
10547 bf_set(abort_cmd_ia, &abts_wqe->abort_cmd, 0);
10548 bf_set(abort_cmd_criteria, &abts_wqe->abort_cmd, T_XRI_TAG);
10550 /* Explicitly set reserved fields to zero.*/
10551 abts_wqe->abort_cmd.rsrvd4 = 0;
10552 abts_wqe->abort_cmd.rsrvd5 = 0;
10554 /* WQE Common - word 6. Context is XRI tag. Set 0. */
10555 bf_set(wqe_xri_tag, &abts_wqe->abort_cmd.wqe_com, 0);
10556 bf_set(wqe_ctxt_tag, &abts_wqe->abort_cmd.wqe_com, 0);
10559 bf_set(wqe_ct, &abts_wqe->abort_cmd.wqe_com, 0);
10560 bf_set(wqe_cmnd, &abts_wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
10561 bf_set(wqe_class, &abts_wqe->abort_cmd.wqe_com,
10562 cmdiocb->iocb.ulpClass);
10564 /* word 8 - tell the FW to abort the IO associated with this
10565 * outstanding exchange ID.
10567 abts_wqe->abort_cmd.wqe_com.abort_tag = cmdiocb->sli4_xritag;
10569 /* word 9 - this is the iotag for the abts_wqe completion. */
10570 bf_set(wqe_reqtag, &abts_wqe->abort_cmd.wqe_com,
10574 bf_set(wqe_wqid, &abts_wqe->abort_cmd.wqe_com, cmdiocb->hba_wqidx);
10575 bf_set(wqe_qosd, &abts_wqe->abort_cmd.wqe_com, 1);
10576 bf_set(wqe_lenloc, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
10579 bf_set(wqe_cmd_type, &abts_wqe->abort_cmd.wqe_com, OTHER_COMMAND);
10580 bf_set(wqe_wqec, &abts_wqe->abort_cmd.wqe_com, 1);
10581 bf_set(wqe_cqid, &abts_wqe->abort_cmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10583 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10584 abtsiocbp->iocb_flag |= LPFC_IO_NVME;
10585 abtsiocbp->vport = vport;
10586 abtsiocbp->wqe_cmpl = lpfc_nvme_abort_fcreq_cmpl;
10587 retval = lpfc_sli4_issue_wqe(phba, LPFC_FCP_RING, abtsiocbp);
10588 if (retval == IOCB_ERROR) {
10589 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME,
10590 "6147 Failed abts issue_wqe with status x%x "
10592 retval, cmdiocb->sli4_xritag);
10593 lpfc_sli_release_iocbq(phba, abtsiocbp);
10597 lpfc_printf_vlog(vport, KERN_ERR, LOG_NVME,
10598 "6148 Drv Abort NVME Request Issued for "
10599 "ox_id x%x on reqtag x%x\n",
10600 cmdiocb->sli4_xritag,
10607 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
10608 * @phba: pointer to lpfc HBA data structure.
10610 * This routine will abort all pending and outstanding iocbs to an HBA.
10613 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
10615 struct lpfc_sli *psli = &phba->sli;
10616 struct lpfc_sli_ring *pring;
10617 struct lpfc_queue *qp = NULL;
10620 if (phba->sli_rev != LPFC_SLI_REV4) {
10621 for (i = 0; i < psli->num_rings; i++) {
10622 pring = &psli->sli3_ring[i];
10623 lpfc_sli_abort_iocb_ring(phba, pring);
10627 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
10631 lpfc_sli_abort_iocb_ring(phba, pring);
10636 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
10637 * @iocbq: Pointer to driver iocb object.
10638 * @vport: Pointer to driver virtual port object.
10639 * @tgt_id: SCSI ID of the target.
10640 * @lun_id: LUN ID of the scsi device.
10641 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
10643 * This function acts as an iocb filter for functions which abort or count
10644 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
10645 * 0 if the filtering criteria is met for the given iocb and will return
10646 * 1 if the filtering criteria is not met.
10647 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
10648 * given iocb is for the SCSI device specified by vport, tgt_id and
10649 * lun_id parameter.
10650 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
10651 * given iocb is for the SCSI target specified by vport and tgt_id
10653 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
10654 * given iocb is for the SCSI host associated with the given vport.
10655 * This function is called with no locks held.
10658 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
10659 uint16_t tgt_id, uint64_t lun_id,
10660 lpfc_ctx_cmd ctx_cmd)
10662 struct lpfc_scsi_buf *lpfc_cmd;
10665 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
10668 if (iocbq->vport != vport)
10671 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
10673 if (lpfc_cmd->pCmd == NULL)
10678 if ((lpfc_cmd->rdata->pnode) &&
10679 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
10680 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
10684 if ((lpfc_cmd->rdata->pnode) &&
10685 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
10688 case LPFC_CTX_HOST:
10692 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
10693 __func__, ctx_cmd);
10701 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
10702 * @vport: Pointer to virtual port.
10703 * @tgt_id: SCSI ID of the target.
10704 * @lun_id: LUN ID of the scsi device.
10705 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10707 * This function returns number of FCP commands pending for the vport.
10708 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
10709 * commands pending on the vport associated with SCSI device specified
10710 * by tgt_id and lun_id parameters.
10711 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
10712 * commands pending on the vport associated with SCSI target specified
10713 * by tgt_id parameter.
10714 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
10715 * commands pending on the vport.
10716 * This function returns the number of iocbs which satisfy the filter.
10717 * This function is called without any lock held.
10720 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
10721 lpfc_ctx_cmd ctx_cmd)
10723 struct lpfc_hba *phba = vport->phba;
10724 struct lpfc_iocbq *iocbq;
10727 spin_lock_irq(&phba->hbalock);
10728 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
10729 iocbq = phba->sli.iocbq_lookup[i];
10731 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
10735 spin_unlock_irq(&phba->hbalock);
10741 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
10742 * @phba: Pointer to HBA context object
10743 * @cmdiocb: Pointer to command iocb object.
10744 * @rspiocb: Pointer to response iocb object.
10746 * This function is called when an aborted FCP iocb completes. This
10747 * function is called by the ring event handler with no lock held.
10748 * This function frees the iocb.
10751 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
10752 struct lpfc_iocbq *rspiocb)
10754 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10755 "3096 ABORT_XRI_CN completing on rpi x%x "
10756 "original iotag x%x, abort cmd iotag x%x "
10757 "status 0x%x, reason 0x%x\n",
10758 cmdiocb->iocb.un.acxri.abortContextTag,
10759 cmdiocb->iocb.un.acxri.abortIoTag,
10760 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
10761 rspiocb->iocb.un.ulpWord[4]);
10762 lpfc_sli_release_iocbq(phba, cmdiocb);
10767 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
10768 * @vport: Pointer to virtual port.
10769 * @pring: Pointer to driver SLI ring object.
10770 * @tgt_id: SCSI ID of the target.
10771 * @lun_id: LUN ID of the scsi device.
10772 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10774 * This function sends an abort command for every SCSI command
10775 * associated with the given virtual port pending on the ring
10776 * filtered by lpfc_sli_validate_fcp_iocb function.
10777 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
10778 * FCP iocbs associated with lun specified by tgt_id and lun_id
10780 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
10781 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10782 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
10783 * FCP iocbs associated with virtual port.
10784 * This function returns number of iocbs it failed to abort.
10785 * This function is called with no locks held.
10788 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
10789 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
10791 struct lpfc_hba *phba = vport->phba;
10792 struct lpfc_iocbq *iocbq;
10793 struct lpfc_iocbq *abtsiocb;
10794 IOCB_t *cmd = NULL;
10795 int errcnt = 0, ret_val = 0;
10798 for (i = 1; i <= phba->sli.last_iotag; i++) {
10799 iocbq = phba->sli.iocbq_lookup[i];
10801 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
10806 * If the iocbq is already being aborted, don't take a second
10807 * action, but do count it.
10809 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
10812 /* issue ABTS for this IOCB based on iotag */
10813 abtsiocb = lpfc_sli_get_iocbq(phba);
10814 if (abtsiocb == NULL) {
10819 /* indicate the IO is being aborted by the driver. */
10820 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
10822 cmd = &iocbq->iocb;
10823 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
10824 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
10825 if (phba->sli_rev == LPFC_SLI_REV4)
10826 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
10828 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
10829 abtsiocb->iocb.ulpLe = 1;
10830 abtsiocb->iocb.ulpClass = cmd->ulpClass;
10831 abtsiocb->vport = vport;
10833 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10834 abtsiocb->hba_wqidx = iocbq->hba_wqidx;
10835 if (iocbq->iocb_flag & LPFC_IO_FCP)
10836 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
10837 if (iocbq->iocb_flag & LPFC_IO_FOF)
10838 abtsiocb->iocb_flag |= LPFC_IO_FOF;
10840 if (lpfc_is_link_up(phba))
10841 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
10843 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
10845 /* Setup callback routine and issue the command. */
10846 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
10847 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
10849 if (ret_val == IOCB_ERROR) {
10850 lpfc_sli_release_iocbq(phba, abtsiocb);
10860 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
10861 * @vport: Pointer to virtual port.
10862 * @pring: Pointer to driver SLI ring object.
10863 * @tgt_id: SCSI ID of the target.
10864 * @lun_id: LUN ID of the scsi device.
10865 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10867 * This function sends an abort command for every SCSI command
10868 * associated with the given virtual port pending on the ring
10869 * filtered by lpfc_sli_validate_fcp_iocb function.
10870 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
10871 * FCP iocbs associated with lun specified by tgt_id and lun_id
10873 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
10874 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10875 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
10876 * FCP iocbs associated with virtual port.
10877 * This function returns number of iocbs it aborted .
10878 * This function is called with no locks held right after a taskmgmt
10882 lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
10883 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
10885 struct lpfc_hba *phba = vport->phba;
10886 struct lpfc_scsi_buf *lpfc_cmd;
10887 struct lpfc_iocbq *abtsiocbq;
10888 struct lpfc_nodelist *ndlp;
10889 struct lpfc_iocbq *iocbq;
10891 int sum, i, ret_val;
10892 unsigned long iflags;
10893 struct lpfc_sli_ring *pring_s4;
10895 spin_lock_irq(&phba->hbalock);
10897 /* all I/Os are in process of being flushed */
10898 if (phba->hba_flag & HBA_FCP_IOQ_FLUSH) {
10899 spin_unlock_irq(&phba->hbalock);
10904 for (i = 1; i <= phba->sli.last_iotag; i++) {
10905 iocbq = phba->sli.iocbq_lookup[i];
10907 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
10912 * If the iocbq is already being aborted, don't take a second
10913 * action, but do count it.
10915 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
10918 /* issue ABTS for this IOCB based on iotag */
10919 abtsiocbq = __lpfc_sli_get_iocbq(phba);
10920 if (abtsiocbq == NULL)
10923 icmd = &iocbq->iocb;
10924 abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
10925 abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
10926 if (phba->sli_rev == LPFC_SLI_REV4)
10927 abtsiocbq->iocb.un.acxri.abortIoTag =
10928 iocbq->sli4_xritag;
10930 abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
10931 abtsiocbq->iocb.ulpLe = 1;
10932 abtsiocbq->iocb.ulpClass = icmd->ulpClass;
10933 abtsiocbq->vport = vport;
10935 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10936 abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
10937 if (iocbq->iocb_flag & LPFC_IO_FCP)
10938 abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
10939 if (iocbq->iocb_flag & LPFC_IO_FOF)
10940 abtsiocbq->iocb_flag |= LPFC_IO_FOF;
10942 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
10943 ndlp = lpfc_cmd->rdata->pnode;
10945 if (lpfc_is_link_up(phba) &&
10946 (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
10947 abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
10949 abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
10951 /* Setup callback routine and issue the command. */
10952 abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
10955 * Indicate the IO is being aborted by the driver and set
10956 * the caller's flag into the aborted IO.
10958 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
10960 if (phba->sli_rev == LPFC_SLI_REV4) {
10961 pring_s4 = lpfc_sli4_calc_ring(phba, iocbq);
10962 if (pring_s4 == NULL)
10964 /* Note: both hbalock and ring_lock must be set here */
10965 spin_lock_irqsave(&pring_s4->ring_lock, iflags);
10966 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
10968 spin_unlock_irqrestore(&pring_s4->ring_lock, iflags);
10970 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
10975 if (ret_val == IOCB_ERROR)
10976 __lpfc_sli_release_iocbq(phba, abtsiocbq);
10980 spin_unlock_irq(&phba->hbalock);
10985 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
10986 * @phba: Pointer to HBA context object.
10987 * @cmdiocbq: Pointer to command iocb.
10988 * @rspiocbq: Pointer to response iocb.
10990 * This function is the completion handler for iocbs issued using
10991 * lpfc_sli_issue_iocb_wait function. This function is called by the
10992 * ring event handler function without any lock held. This function
10993 * can be called from both worker thread context and interrupt
10994 * context. This function also can be called from other thread which
10995 * cleans up the SLI layer objects.
10996 * This function copy the contents of the response iocb to the
10997 * response iocb memory object provided by the caller of
10998 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
10999 * sleeps for the iocb completion.
11002 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
11003 struct lpfc_iocbq *cmdiocbq,
11004 struct lpfc_iocbq *rspiocbq)
11006 wait_queue_head_t *pdone_q;
11007 unsigned long iflags;
11008 struct lpfc_scsi_buf *lpfc_cmd;
11010 spin_lock_irqsave(&phba->hbalock, iflags);
11011 if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
11014 * A time out has occurred for the iocb. If a time out
11015 * completion handler has been supplied, call it. Otherwise,
11016 * just free the iocbq.
11019 spin_unlock_irqrestore(&phba->hbalock, iflags);
11020 cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
11021 cmdiocbq->wait_iocb_cmpl = NULL;
11022 if (cmdiocbq->iocb_cmpl)
11023 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
11025 lpfc_sli_release_iocbq(phba, cmdiocbq);
11029 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
11030 if (cmdiocbq->context2 && rspiocbq)
11031 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
11032 &rspiocbq->iocb, sizeof(IOCB_t));
11034 /* Set the exchange busy flag for task management commands */
11035 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
11036 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
11037 lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf,
11039 lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY;
11042 pdone_q = cmdiocbq->context_un.wait_queue;
11045 spin_unlock_irqrestore(&phba->hbalock, iflags);
11050 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
11051 * @phba: Pointer to HBA context object..
11052 * @piocbq: Pointer to command iocb.
11053 * @flag: Flag to test.
11055 * This routine grabs the hbalock and then test the iocb_flag to
11056 * see if the passed in flag is set.
11058 * 1 if flag is set.
11059 * 0 if flag is not set.
11062 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
11063 struct lpfc_iocbq *piocbq, uint32_t flag)
11065 unsigned long iflags;
11068 spin_lock_irqsave(&phba->hbalock, iflags);
11069 ret = piocbq->iocb_flag & flag;
11070 spin_unlock_irqrestore(&phba->hbalock, iflags);
11076 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
11077 * @phba: Pointer to HBA context object..
11078 * @pring: Pointer to sli ring.
11079 * @piocb: Pointer to command iocb.
11080 * @prspiocbq: Pointer to response iocb.
11081 * @timeout: Timeout in number of seconds.
11083 * This function issues the iocb to firmware and waits for the
11084 * iocb to complete. The iocb_cmpl field of the shall be used
11085 * to handle iocbs which time out. If the field is NULL, the
11086 * function shall free the iocbq structure. If more clean up is
11087 * needed, the caller is expected to provide a completion function
11088 * that will provide the needed clean up. If the iocb command is
11089 * not completed within timeout seconds, the function will either
11090 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
11091 * completion function set in the iocb_cmpl field and then return
11092 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
11093 * resources if this function returns IOCB_TIMEDOUT.
11094 * The function waits for the iocb completion using an
11095 * non-interruptible wait.
11096 * This function will sleep while waiting for iocb completion.
11097 * So, this function should not be called from any context which
11098 * does not allow sleeping. Due to the same reason, this function
11099 * cannot be called with interrupt disabled.
11100 * This function assumes that the iocb completions occur while
11101 * this function sleep. So, this function cannot be called from
11102 * the thread which process iocb completion for this ring.
11103 * This function clears the iocb_flag of the iocb object before
11104 * issuing the iocb and the iocb completion handler sets this
11105 * flag and wakes this thread when the iocb completes.
11106 * The contents of the response iocb will be copied to prspiocbq
11107 * by the completion handler when the command completes.
11108 * This function returns IOCB_SUCCESS when success.
11109 * This function is called with no lock held.
11112 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
11113 uint32_t ring_number,
11114 struct lpfc_iocbq *piocb,
11115 struct lpfc_iocbq *prspiocbq,
11118 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
11119 long timeleft, timeout_req = 0;
11120 int retval = IOCB_SUCCESS;
11122 struct lpfc_iocbq *iocb;
11124 int txcmplq_cnt = 0;
11125 struct lpfc_sli_ring *pring;
11126 unsigned long iflags;
11127 bool iocb_completed = true;
11129 if (phba->sli_rev >= LPFC_SLI_REV4)
11130 pring = lpfc_sli4_calc_ring(phba, piocb);
11132 pring = &phba->sli.sli3_ring[ring_number];
11134 * If the caller has provided a response iocbq buffer, then context2
11135 * is NULL or its an error.
11138 if (piocb->context2)
11140 piocb->context2 = prspiocbq;
11143 piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
11144 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
11145 piocb->context_un.wait_queue = &done_q;
11146 piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
11148 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
11149 if (lpfc_readl(phba->HCregaddr, &creg_val))
11151 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
11152 writel(creg_val, phba->HCregaddr);
11153 readl(phba->HCregaddr); /* flush */
11156 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
11157 SLI_IOCB_RET_IOCB);
11158 if (retval == IOCB_SUCCESS) {
11159 timeout_req = msecs_to_jiffies(timeout * 1000);
11160 timeleft = wait_event_timeout(done_q,
11161 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
11163 spin_lock_irqsave(&phba->hbalock, iflags);
11164 if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
11167 * IOCB timed out. Inform the wake iocb wait
11168 * completion function and set local status
11171 iocb_completed = false;
11172 piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
11174 spin_unlock_irqrestore(&phba->hbalock, iflags);
11175 if (iocb_completed) {
11176 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11177 "0331 IOCB wake signaled\n");
11178 /* Note: we are not indicating if the IOCB has a success
11179 * status or not - that's for the caller to check.
11180 * IOCB_SUCCESS means just that the command was sent and
11181 * completed. Not that it completed successfully.
11183 } else if (timeleft == 0) {
11184 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11185 "0338 IOCB wait timeout error - no "
11186 "wake response Data x%x\n", timeout);
11187 retval = IOCB_TIMEDOUT;
11189 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11190 "0330 IOCB wake NOT set, "
11192 timeout, (timeleft / jiffies));
11193 retval = IOCB_TIMEDOUT;
11195 } else if (retval == IOCB_BUSY) {
11196 if (phba->cfg_log_verbose & LOG_SLI) {
11197 list_for_each_entry(iocb, &pring->txq, list) {
11200 list_for_each_entry(iocb, &pring->txcmplq, list) {
11203 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11204 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
11205 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
11209 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11210 "0332 IOCB wait issue failed, Data x%x\n",
11212 retval = IOCB_ERROR;
11215 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
11216 if (lpfc_readl(phba->HCregaddr, &creg_val))
11218 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
11219 writel(creg_val, phba->HCregaddr);
11220 readl(phba->HCregaddr); /* flush */
11224 piocb->context2 = NULL;
11226 piocb->context_un.wait_queue = NULL;
11227 piocb->iocb_cmpl = NULL;
11232 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
11233 * @phba: Pointer to HBA context object.
11234 * @pmboxq: Pointer to driver mailbox object.
11235 * @timeout: Timeout in number of seconds.
11237 * This function issues the mailbox to firmware and waits for the
11238 * mailbox command to complete. If the mailbox command is not
11239 * completed within timeout seconds, it returns MBX_TIMEOUT.
11240 * The function waits for the mailbox completion using an
11241 * interruptible wait. If the thread is woken up due to a
11242 * signal, MBX_TIMEOUT error is returned to the caller. Caller
11243 * should not free the mailbox resources, if this function returns
11245 * This function will sleep while waiting for mailbox completion.
11246 * So, this function should not be called from any context which
11247 * does not allow sleeping. Due to the same reason, this function
11248 * cannot be called with interrupt disabled.
11249 * This function assumes that the mailbox completion occurs while
11250 * this function sleep. So, this function cannot be called from
11251 * the worker thread which processes mailbox completion.
11252 * This function is called in the context of HBA management
11254 * This function returns MBX_SUCCESS when successful.
11255 * This function is called with no lock held.
11258 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
11261 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
11262 MAILBOX_t *mb = NULL;
11264 unsigned long flag;
11266 /* The caller might set context1 for extended buffer */
11267 if (pmboxq->context1)
11268 mb = (MAILBOX_t *)pmboxq->context1;
11270 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
11271 /* setup wake call as IOCB callback */
11272 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
11273 /* setup context field to pass wait_queue pointer to wake function */
11274 pmboxq->context1 = &done_q;
11276 /* now issue the command */
11277 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
11278 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
11279 wait_event_interruptible_timeout(done_q,
11280 pmboxq->mbox_flag & LPFC_MBX_WAKE,
11281 msecs_to_jiffies(timeout * 1000));
11283 spin_lock_irqsave(&phba->hbalock, flag);
11284 /* restore the possible extended buffer for free resource */
11285 pmboxq->context1 = (uint8_t *)mb;
11287 * if LPFC_MBX_WAKE flag is set the mailbox is completed
11288 * else do not free the resources.
11290 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
11291 retval = MBX_SUCCESS;
11293 retval = MBX_TIMEOUT;
11294 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
11296 spin_unlock_irqrestore(&phba->hbalock, flag);
11298 /* restore the possible extended buffer for free resource */
11299 pmboxq->context1 = (uint8_t *)mb;
11306 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
11307 * @phba: Pointer to HBA context.
11309 * This function is called to shutdown the driver's mailbox sub-system.
11310 * It first marks the mailbox sub-system is in a block state to prevent
11311 * the asynchronous mailbox command from issued off the pending mailbox
11312 * command queue. If the mailbox command sub-system shutdown is due to
11313 * HBA error conditions such as EEH or ERATT, this routine shall invoke
11314 * the mailbox sub-system flush routine to forcefully bring down the
11315 * mailbox sub-system. Otherwise, if it is due to normal condition (such
11316 * as with offline or HBA function reset), this routine will wait for the
11317 * outstanding mailbox command to complete before invoking the mailbox
11318 * sub-system flush routine to gracefully bring down mailbox sub-system.
11321 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
11323 struct lpfc_sli *psli = &phba->sli;
11324 unsigned long timeout;
11326 if (mbx_action == LPFC_MBX_NO_WAIT) {
11327 /* delay 100ms for port state */
11329 lpfc_sli_mbox_sys_flush(phba);
11332 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
11334 spin_lock_irq(&phba->hbalock);
11335 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
11337 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
11338 /* Determine how long we might wait for the active mailbox
11339 * command to be gracefully completed by firmware.
11341 if (phba->sli.mbox_active)
11342 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
11343 phba->sli.mbox_active) *
11345 spin_unlock_irq(&phba->hbalock);
11347 while (phba->sli.mbox_active) {
11348 /* Check active mailbox complete status every 2ms */
11350 if (time_after(jiffies, timeout))
11351 /* Timeout, let the mailbox flush routine to
11352 * forcefully release active mailbox command
11357 spin_unlock_irq(&phba->hbalock);
11359 lpfc_sli_mbox_sys_flush(phba);
11363 * lpfc_sli_eratt_read - read sli-3 error attention events
11364 * @phba: Pointer to HBA context.
11366 * This function is called to read the SLI3 device error attention registers
11367 * for possible error attention events. The caller must hold the hostlock
11368 * with spin_lock_irq().
11370 * This function returns 1 when there is Error Attention in the Host Attention
11371 * Register and returns 0 otherwise.
11374 lpfc_sli_eratt_read(struct lpfc_hba *phba)
11378 /* Read chip Host Attention (HA) register */
11379 if (lpfc_readl(phba->HAregaddr, &ha_copy))
11382 if (ha_copy & HA_ERATT) {
11383 /* Read host status register to retrieve error event */
11384 if (lpfc_sli_read_hs(phba))
11387 /* Check if there is a deferred error condition is active */
11388 if ((HS_FFER1 & phba->work_hs) &&
11389 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
11390 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
11391 phba->hba_flag |= DEFER_ERATT;
11392 /* Clear all interrupt enable conditions */
11393 writel(0, phba->HCregaddr);
11394 readl(phba->HCregaddr);
11397 /* Set the driver HA work bitmap */
11398 phba->work_ha |= HA_ERATT;
11399 /* Indicate polling handles this ERATT */
11400 phba->hba_flag |= HBA_ERATT_HANDLED;
11406 /* Set the driver HS work bitmap */
11407 phba->work_hs |= UNPLUG_ERR;
11408 /* Set the driver HA work bitmap */
11409 phba->work_ha |= HA_ERATT;
11410 /* Indicate polling handles this ERATT */
11411 phba->hba_flag |= HBA_ERATT_HANDLED;
11416 * lpfc_sli4_eratt_read - read sli-4 error attention events
11417 * @phba: Pointer to HBA context.
11419 * This function is called to read the SLI4 device error attention registers
11420 * for possible error attention events. The caller must hold the hostlock
11421 * with spin_lock_irq().
11423 * This function returns 1 when there is Error Attention in the Host Attention
11424 * Register and returns 0 otherwise.
11427 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
11429 uint32_t uerr_sta_hi, uerr_sta_lo;
11430 uint32_t if_type, portsmphr;
11431 struct lpfc_register portstat_reg;
11434 * For now, use the SLI4 device internal unrecoverable error
11435 * registers for error attention. This can be changed later.
11437 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
11439 case LPFC_SLI_INTF_IF_TYPE_0:
11440 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
11442 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
11444 phba->work_hs |= UNPLUG_ERR;
11445 phba->work_ha |= HA_ERATT;
11446 phba->hba_flag |= HBA_ERATT_HANDLED;
11449 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
11450 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
11451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11452 "1423 HBA Unrecoverable error: "
11453 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
11454 "ue_mask_lo_reg=0x%x, "
11455 "ue_mask_hi_reg=0x%x\n",
11456 uerr_sta_lo, uerr_sta_hi,
11457 phba->sli4_hba.ue_mask_lo,
11458 phba->sli4_hba.ue_mask_hi);
11459 phba->work_status[0] = uerr_sta_lo;
11460 phba->work_status[1] = uerr_sta_hi;
11461 phba->work_ha |= HA_ERATT;
11462 phba->hba_flag |= HBA_ERATT_HANDLED;
11466 case LPFC_SLI_INTF_IF_TYPE_2:
11467 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
11468 &portstat_reg.word0) ||
11469 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
11471 phba->work_hs |= UNPLUG_ERR;
11472 phba->work_ha |= HA_ERATT;
11473 phba->hba_flag |= HBA_ERATT_HANDLED;
11476 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
11477 phba->work_status[0] =
11478 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
11479 phba->work_status[1] =
11480 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
11481 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11482 "2885 Port Status Event: "
11483 "port status reg 0x%x, "
11484 "port smphr reg 0x%x, "
11485 "error 1=0x%x, error 2=0x%x\n",
11486 portstat_reg.word0,
11488 phba->work_status[0],
11489 phba->work_status[1]);
11490 phba->work_ha |= HA_ERATT;
11491 phba->hba_flag |= HBA_ERATT_HANDLED;
11495 case LPFC_SLI_INTF_IF_TYPE_1:
11497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11498 "2886 HBA Error Attention on unsupported "
11499 "if type %d.", if_type);
11507 * lpfc_sli_check_eratt - check error attention events
11508 * @phba: Pointer to HBA context.
11510 * This function is called from timer soft interrupt context to check HBA's
11511 * error attention register bit for error attention events.
11513 * This function returns 1 when there is Error Attention in the Host Attention
11514 * Register and returns 0 otherwise.
11517 lpfc_sli_check_eratt(struct lpfc_hba *phba)
11521 /* If somebody is waiting to handle an eratt, don't process it
11522 * here. The brdkill function will do this.
11524 if (phba->link_flag & LS_IGNORE_ERATT)
11527 /* Check if interrupt handler handles this ERATT */
11528 spin_lock_irq(&phba->hbalock);
11529 if (phba->hba_flag & HBA_ERATT_HANDLED) {
11530 /* Interrupt handler has handled ERATT */
11531 spin_unlock_irq(&phba->hbalock);
11536 * If there is deferred error attention, do not check for error
11539 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
11540 spin_unlock_irq(&phba->hbalock);
11544 /* If PCI channel is offline, don't process it */
11545 if (unlikely(pci_channel_offline(phba->pcidev))) {
11546 spin_unlock_irq(&phba->hbalock);
11550 switch (phba->sli_rev) {
11551 case LPFC_SLI_REV2:
11552 case LPFC_SLI_REV3:
11553 /* Read chip Host Attention (HA) register */
11554 ha_copy = lpfc_sli_eratt_read(phba);
11556 case LPFC_SLI_REV4:
11557 /* Read device Uncoverable Error (UERR) registers */
11558 ha_copy = lpfc_sli4_eratt_read(phba);
11561 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11562 "0299 Invalid SLI revision (%d)\n",
11567 spin_unlock_irq(&phba->hbalock);
11573 * lpfc_intr_state_check - Check device state for interrupt handling
11574 * @phba: Pointer to HBA context.
11576 * This inline routine checks whether a device or its PCI slot is in a state
11577 * that the interrupt should be handled.
11579 * This function returns 0 if the device or the PCI slot is in a state that
11580 * interrupt should be handled, otherwise -EIO.
11583 lpfc_intr_state_check(struct lpfc_hba *phba)
11585 /* If the pci channel is offline, ignore all the interrupts */
11586 if (unlikely(pci_channel_offline(phba->pcidev)))
11589 /* Update device level interrupt statistics */
11590 phba->sli.slistat.sli_intr++;
11592 /* Ignore all interrupts during initialization. */
11593 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
11600 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
11601 * @irq: Interrupt number.
11602 * @dev_id: The device context pointer.
11604 * This function is directly called from the PCI layer as an interrupt
11605 * service routine when device with SLI-3 interface spec is enabled with
11606 * MSI-X multi-message interrupt mode and there are slow-path events in
11607 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11608 * interrupt mode, this function is called as part of the device-level
11609 * interrupt handler. When the PCI slot is in error recovery or the HBA
11610 * is undergoing initialization, the interrupt handler will not process
11611 * the interrupt. The link attention and ELS ring attention events are
11612 * handled by the worker thread. The interrupt handler signals the worker
11613 * thread and returns for these events. This function is called without
11614 * any lock held. It gets the hbalock to access and update SLI data
11617 * This function returns IRQ_HANDLED when interrupt is handled else it
11618 * returns IRQ_NONE.
11621 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
11623 struct lpfc_hba *phba;
11624 uint32_t ha_copy, hc_copy;
11625 uint32_t work_ha_copy;
11626 unsigned long status;
11627 unsigned long iflag;
11630 MAILBOX_t *mbox, *pmbox;
11631 struct lpfc_vport *vport;
11632 struct lpfc_nodelist *ndlp;
11633 struct lpfc_dmabuf *mp;
11638 * Get the driver's phba structure from the dev_id and
11639 * assume the HBA is not interrupting.
11641 phba = (struct lpfc_hba *)dev_id;
11643 if (unlikely(!phba))
11647 * Stuff needs to be attented to when this function is invoked as an
11648 * individual interrupt handler in MSI-X multi-message interrupt mode
11650 if (phba->intr_type == MSIX) {
11651 /* Check device state for handling interrupt */
11652 if (lpfc_intr_state_check(phba))
11654 /* Need to read HA REG for slow-path events */
11655 spin_lock_irqsave(&phba->hbalock, iflag);
11656 if (lpfc_readl(phba->HAregaddr, &ha_copy))
11658 /* If somebody is waiting to handle an eratt don't process it
11659 * here. The brdkill function will do this.
11661 if (phba->link_flag & LS_IGNORE_ERATT)
11662 ha_copy &= ~HA_ERATT;
11663 /* Check the need for handling ERATT in interrupt handler */
11664 if (ha_copy & HA_ERATT) {
11665 if (phba->hba_flag & HBA_ERATT_HANDLED)
11666 /* ERATT polling has handled ERATT */
11667 ha_copy &= ~HA_ERATT;
11669 /* Indicate interrupt handler handles ERATT */
11670 phba->hba_flag |= HBA_ERATT_HANDLED;
11674 * If there is deferred error attention, do not check for any
11677 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
11678 spin_unlock_irqrestore(&phba->hbalock, iflag);
11682 /* Clear up only attention source related to slow-path */
11683 if (lpfc_readl(phba->HCregaddr, &hc_copy))
11686 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
11687 HC_LAINT_ENA | HC_ERINT_ENA),
11689 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
11691 writel(hc_copy, phba->HCregaddr);
11692 readl(phba->HAregaddr); /* flush */
11693 spin_unlock_irqrestore(&phba->hbalock, iflag);
11695 ha_copy = phba->ha_copy;
11697 work_ha_copy = ha_copy & phba->work_ha_mask;
11699 if (work_ha_copy) {
11700 if (work_ha_copy & HA_LATT) {
11701 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
11703 * Turn off Link Attention interrupts
11704 * until CLEAR_LA done
11706 spin_lock_irqsave(&phba->hbalock, iflag);
11707 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
11708 if (lpfc_readl(phba->HCregaddr, &control))
11710 control &= ~HC_LAINT_ENA;
11711 writel(control, phba->HCregaddr);
11712 readl(phba->HCregaddr); /* flush */
11713 spin_unlock_irqrestore(&phba->hbalock, iflag);
11716 work_ha_copy &= ~HA_LATT;
11719 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
11721 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
11722 * the only slow ring.
11724 status = (work_ha_copy &
11725 (HA_RXMASK << (4*LPFC_ELS_RING)));
11726 status >>= (4*LPFC_ELS_RING);
11727 if (status & HA_RXMASK) {
11728 spin_lock_irqsave(&phba->hbalock, iflag);
11729 if (lpfc_readl(phba->HCregaddr, &control))
11732 lpfc_debugfs_slow_ring_trc(phba,
11733 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
11735 (uint32_t)phba->sli.slistat.sli_intr);
11737 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
11738 lpfc_debugfs_slow_ring_trc(phba,
11739 "ISR Disable ring:"
11740 "pwork:x%x hawork:x%x wait:x%x",
11741 phba->work_ha, work_ha_copy,
11742 (uint32_t)((unsigned long)
11743 &phba->work_waitq));
11746 ~(HC_R0INT_ENA << LPFC_ELS_RING);
11747 writel(control, phba->HCregaddr);
11748 readl(phba->HCregaddr); /* flush */
11751 lpfc_debugfs_slow_ring_trc(phba,
11752 "ISR slow ring: pwork:"
11753 "x%x hawork:x%x wait:x%x",
11754 phba->work_ha, work_ha_copy,
11755 (uint32_t)((unsigned long)
11756 &phba->work_waitq));
11758 spin_unlock_irqrestore(&phba->hbalock, iflag);
11761 spin_lock_irqsave(&phba->hbalock, iflag);
11762 if (work_ha_copy & HA_ERATT) {
11763 if (lpfc_sli_read_hs(phba))
11766 * Check if there is a deferred error condition
11769 if ((HS_FFER1 & phba->work_hs) &&
11770 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
11771 HS_FFER6 | HS_FFER7 | HS_FFER8) &
11773 phba->hba_flag |= DEFER_ERATT;
11774 /* Clear all interrupt enable conditions */
11775 writel(0, phba->HCregaddr);
11776 readl(phba->HCregaddr);
11780 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
11781 pmb = phba->sli.mbox_active;
11782 pmbox = &pmb->u.mb;
11784 vport = pmb->vport;
11786 /* First check out the status word */
11787 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
11788 if (pmbox->mbxOwner != OWN_HOST) {
11789 spin_unlock_irqrestore(&phba->hbalock, iflag);
11791 * Stray Mailbox Interrupt, mbxCommand <cmd>
11792 * mbxStatus <status>
11794 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
11796 "(%d):0304 Stray Mailbox "
11797 "Interrupt mbxCommand x%x "
11799 (vport ? vport->vpi : 0),
11802 /* clear mailbox attention bit */
11803 work_ha_copy &= ~HA_MBATT;
11805 phba->sli.mbox_active = NULL;
11806 spin_unlock_irqrestore(&phba->hbalock, iflag);
11807 phba->last_completion_time = jiffies;
11808 del_timer(&phba->sli.mbox_tmo);
11809 if (pmb->mbox_cmpl) {
11810 lpfc_sli_pcimem_bcopy(mbox, pmbox,
11812 if (pmb->out_ext_byte_len &&
11814 lpfc_sli_pcimem_bcopy(
11817 pmb->out_ext_byte_len);
11819 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
11820 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
11822 lpfc_debugfs_disc_trc(vport,
11823 LPFC_DISC_TRC_MBOX_VPORT,
11824 "MBOX dflt rpi: : "
11825 "status:x%x rpi:x%x",
11826 (uint32_t)pmbox->mbxStatus,
11827 pmbox->un.varWords[0], 0);
11829 if (!pmbox->mbxStatus) {
11830 mp = (struct lpfc_dmabuf *)
11832 ndlp = (struct lpfc_nodelist *)
11835 /* Reg_LOGIN of dflt RPI was
11836 * successful. new lets get
11837 * rid of the RPI using the
11838 * same mbox buffer.
11840 lpfc_unreg_login(phba,
11842 pmbox->un.varWords[0],
11845 lpfc_mbx_cmpl_dflt_rpi;
11846 pmb->context1 = mp;
11847 pmb->context2 = ndlp;
11848 pmb->vport = vport;
11849 rc = lpfc_sli_issue_mbox(phba,
11852 if (rc != MBX_BUSY)
11853 lpfc_printf_log(phba,
11855 LOG_MBOX | LOG_SLI,
11856 "0350 rc should have"
11857 "been MBX_BUSY\n");
11858 if (rc != MBX_NOT_FINISHED)
11859 goto send_current_mbox;
11863 &phba->pport->work_port_lock,
11865 phba->pport->work_port_events &=
11867 spin_unlock_irqrestore(
11868 &phba->pport->work_port_lock,
11870 lpfc_mbox_cmpl_put(phba, pmb);
11873 spin_unlock_irqrestore(&phba->hbalock, iflag);
11875 if ((work_ha_copy & HA_MBATT) &&
11876 (phba->sli.mbox_active == NULL)) {
11878 /* Process next mailbox command if there is one */
11880 rc = lpfc_sli_issue_mbox(phba, NULL,
11882 } while (rc == MBX_NOT_FINISHED);
11883 if (rc != MBX_SUCCESS)
11884 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
11885 LOG_SLI, "0349 rc should be "
11889 spin_lock_irqsave(&phba->hbalock, iflag);
11890 phba->work_ha |= work_ha_copy;
11891 spin_unlock_irqrestore(&phba->hbalock, iflag);
11892 lpfc_worker_wake_up(phba);
11894 return IRQ_HANDLED;
11896 spin_unlock_irqrestore(&phba->hbalock, iflag);
11897 return IRQ_HANDLED;
11899 } /* lpfc_sli_sp_intr_handler */
11902 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
11903 * @irq: Interrupt number.
11904 * @dev_id: The device context pointer.
11906 * This function is directly called from the PCI layer as an interrupt
11907 * service routine when device with SLI-3 interface spec is enabled with
11908 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11909 * ring event in the HBA. However, when the device is enabled with either
11910 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11911 * device-level interrupt handler. When the PCI slot is in error recovery
11912 * or the HBA is undergoing initialization, the interrupt handler will not
11913 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11914 * the intrrupt context. This function is called without any lock held.
11915 * It gets the hbalock to access and update SLI data structures.
11917 * This function returns IRQ_HANDLED when interrupt is handled else it
11918 * returns IRQ_NONE.
11921 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
11923 struct lpfc_hba *phba;
11925 unsigned long status;
11926 unsigned long iflag;
11927 struct lpfc_sli_ring *pring;
11929 /* Get the driver's phba structure from the dev_id and
11930 * assume the HBA is not interrupting.
11932 phba = (struct lpfc_hba *) dev_id;
11934 if (unlikely(!phba))
11938 * Stuff needs to be attented to when this function is invoked as an
11939 * individual interrupt handler in MSI-X multi-message interrupt mode
11941 if (phba->intr_type == MSIX) {
11942 /* Check device state for handling interrupt */
11943 if (lpfc_intr_state_check(phba))
11945 /* Need to read HA REG for FCP ring and other ring events */
11946 if (lpfc_readl(phba->HAregaddr, &ha_copy))
11947 return IRQ_HANDLED;
11948 /* Clear up only attention source related to fast-path */
11949 spin_lock_irqsave(&phba->hbalock, iflag);
11951 * If there is deferred error attention, do not check for
11954 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
11955 spin_unlock_irqrestore(&phba->hbalock, iflag);
11958 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
11960 readl(phba->HAregaddr); /* flush */
11961 spin_unlock_irqrestore(&phba->hbalock, iflag);
11963 ha_copy = phba->ha_copy;
11966 * Process all events on FCP ring. Take the optimized path for FCP IO.
11968 ha_copy &= ~(phba->work_ha_mask);
11970 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
11971 status >>= (4*LPFC_FCP_RING);
11972 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
11973 if (status & HA_RXMASK)
11974 lpfc_sli_handle_fast_ring_event(phba, pring, status);
11976 if (phba->cfg_multi_ring_support == 2) {
11978 * Process all events on extra ring. Take the optimized path
11979 * for extra ring IO.
11981 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
11982 status >>= (4*LPFC_EXTRA_RING);
11983 if (status & HA_RXMASK) {
11984 lpfc_sli_handle_fast_ring_event(phba,
11985 &phba->sli.sli3_ring[LPFC_EXTRA_RING],
11989 return IRQ_HANDLED;
11990 } /* lpfc_sli_fp_intr_handler */
11993 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
11994 * @irq: Interrupt number.
11995 * @dev_id: The device context pointer.
11997 * This function is the HBA device-level interrupt handler to device with
11998 * SLI-3 interface spec, called from the PCI layer when either MSI or
11999 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
12000 * requires driver attention. This function invokes the slow-path interrupt
12001 * attention handling function and fast-path interrupt attention handling
12002 * function in turn to process the relevant HBA attention events. This
12003 * function is called without any lock held. It gets the hbalock to access
12004 * and update SLI data structures.
12006 * This function returns IRQ_HANDLED when interrupt is handled, else it
12007 * returns IRQ_NONE.
12010 lpfc_sli_intr_handler(int irq, void *dev_id)
12012 struct lpfc_hba *phba;
12013 irqreturn_t sp_irq_rc, fp_irq_rc;
12014 unsigned long status1, status2;
12018 * Get the driver's phba structure from the dev_id and
12019 * assume the HBA is not interrupting.
12021 phba = (struct lpfc_hba *) dev_id;
12023 if (unlikely(!phba))
12026 /* Check device state for handling interrupt */
12027 if (lpfc_intr_state_check(phba))
12030 spin_lock(&phba->hbalock);
12031 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
12032 spin_unlock(&phba->hbalock);
12033 return IRQ_HANDLED;
12036 if (unlikely(!phba->ha_copy)) {
12037 spin_unlock(&phba->hbalock);
12039 } else if (phba->ha_copy & HA_ERATT) {
12040 if (phba->hba_flag & HBA_ERATT_HANDLED)
12041 /* ERATT polling has handled ERATT */
12042 phba->ha_copy &= ~HA_ERATT;
12044 /* Indicate interrupt handler handles ERATT */
12045 phba->hba_flag |= HBA_ERATT_HANDLED;
12049 * If there is deferred error attention, do not check for any interrupt.
12051 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12052 spin_unlock(&phba->hbalock);
12056 /* Clear attention sources except link and error attentions */
12057 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
12058 spin_unlock(&phba->hbalock);
12059 return IRQ_HANDLED;
12061 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
12062 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
12064 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
12065 writel(hc_copy, phba->HCregaddr);
12066 readl(phba->HAregaddr); /* flush */
12067 spin_unlock(&phba->hbalock);
12070 * Invokes slow-path host attention interrupt handling as appropriate.
12073 /* status of events with mailbox and link attention */
12074 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
12076 /* status of events with ELS ring */
12077 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
12078 status2 >>= (4*LPFC_ELS_RING);
12080 if (status1 || (status2 & HA_RXMASK))
12081 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
12083 sp_irq_rc = IRQ_NONE;
12086 * Invoke fast-path host attention interrupt handling as appropriate.
12089 /* status of events with FCP ring */
12090 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
12091 status1 >>= (4*LPFC_FCP_RING);
12093 /* status of events with extra ring */
12094 if (phba->cfg_multi_ring_support == 2) {
12095 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
12096 status2 >>= (4*LPFC_EXTRA_RING);
12100 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
12101 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
12103 fp_irq_rc = IRQ_NONE;
12105 /* Return device-level interrupt handling status */
12106 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
12107 } /* lpfc_sli_intr_handler */
12110 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
12111 * @phba: pointer to lpfc hba data structure.
12113 * This routine is invoked by the worker thread to process all the pending
12114 * SLI4 FCP abort XRI events.
12116 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba)
12118 struct lpfc_cq_event *cq_event;
12120 /* First, declare the fcp xri abort event has been handled */
12121 spin_lock_irq(&phba->hbalock);
12122 phba->hba_flag &= ~FCP_XRI_ABORT_EVENT;
12123 spin_unlock_irq(&phba->hbalock);
12124 /* Now, handle all the fcp xri abort events */
12125 while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) {
12126 /* Get the first event from the head of the event queue */
12127 spin_lock_irq(&phba->hbalock);
12128 list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
12129 cq_event, struct lpfc_cq_event, list);
12130 spin_unlock_irq(&phba->hbalock);
12131 /* Notify aborted XRI for FCP work queue */
12132 lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
12133 /* Free the event processed back to the free pool */
12134 lpfc_sli4_cq_event_release(phba, cq_event);
12139 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12140 * @phba: pointer to lpfc hba data structure.
12142 * This routine is invoked by the worker thread to process all the pending
12143 * SLI4 els abort xri events.
12145 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
12147 struct lpfc_cq_event *cq_event;
12149 /* First, declare the els xri abort event has been handled */
12150 spin_lock_irq(&phba->hbalock);
12151 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
12152 spin_unlock_irq(&phba->hbalock);
12153 /* Now, handle all the els xri abort events */
12154 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
12155 /* Get the first event from the head of the event queue */
12156 spin_lock_irq(&phba->hbalock);
12157 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
12158 cq_event, struct lpfc_cq_event, list);
12159 spin_unlock_irq(&phba->hbalock);
12160 /* Notify aborted XRI for ELS work queue */
12161 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
12162 /* Free the event processed back to the free pool */
12163 lpfc_sli4_cq_event_release(phba, cq_event);
12168 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
12169 * @phba: pointer to lpfc hba data structure
12170 * @pIocbIn: pointer to the rspiocbq
12171 * @pIocbOut: pointer to the cmdiocbq
12172 * @wcqe: pointer to the complete wcqe
12174 * This routine transfers the fields of a command iocbq to a response iocbq
12175 * by copying all the IOCB fields from command iocbq and transferring the
12176 * completion status information from the complete wcqe.
12179 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
12180 struct lpfc_iocbq *pIocbIn,
12181 struct lpfc_iocbq *pIocbOut,
12182 struct lpfc_wcqe_complete *wcqe)
12185 unsigned long iflags;
12186 uint32_t status, max_response;
12187 struct lpfc_dmabuf *dmabuf;
12188 struct ulp_bde64 *bpl, bde;
12189 size_t offset = offsetof(struct lpfc_iocbq, iocb);
12191 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
12192 sizeof(struct lpfc_iocbq) - offset);
12193 /* Map WCQE parameters into irspiocb parameters */
12194 status = bf_get(lpfc_wcqe_c_status, wcqe);
12195 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
12196 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
12197 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
12198 pIocbIn->iocb.un.fcpi.fcpi_parm =
12199 pIocbOut->iocb.un.fcpi.fcpi_parm -
12200 wcqe->total_data_placed;
12202 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
12204 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
12205 switch (pIocbOut->iocb.ulpCommand) {
12206 case CMD_ELS_REQUEST64_CR:
12207 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
12208 bpl = (struct ulp_bde64 *)dmabuf->virt;
12209 bde.tus.w = le32_to_cpu(bpl[1].tus.w);
12210 max_response = bde.tus.f.bdeSize;
12212 case CMD_GEN_REQUEST64_CR:
12214 if (!pIocbOut->context3)
12216 numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
12217 sizeof(struct ulp_bde64);
12218 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
12219 bpl = (struct ulp_bde64 *)dmabuf->virt;
12220 for (i = 0; i < numBdes; i++) {
12221 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
12222 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
12223 max_response += bde.tus.f.bdeSize;
12227 max_response = wcqe->total_data_placed;
12230 if (max_response < wcqe->total_data_placed)
12231 pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
12233 pIocbIn->iocb.un.genreq64.bdl.bdeSize =
12234 wcqe->total_data_placed;
12237 /* Convert BG errors for completion status */
12238 if (status == CQE_STATUS_DI_ERROR) {
12239 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
12241 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
12242 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
12244 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
12246 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
12247 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
12248 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12249 BGS_GUARD_ERR_MASK;
12250 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
12251 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12252 BGS_APPTAG_ERR_MASK;
12253 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
12254 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12255 BGS_REFTAG_ERR_MASK;
12257 /* Check to see if there was any good data before the error */
12258 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
12259 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12260 BGS_HI_WATER_MARK_PRESENT_MASK;
12261 pIocbIn->iocb.unsli3.sli3_bg.bghm =
12262 wcqe->total_data_placed;
12266 * Set ALL the error bits to indicate we don't know what
12267 * type of error it is.
12269 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
12270 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12271 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
12272 BGS_GUARD_ERR_MASK);
12275 /* Pick up HBA exchange busy condition */
12276 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
12277 spin_lock_irqsave(&phba->hbalock, iflags);
12278 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
12279 spin_unlock_irqrestore(&phba->hbalock, iflags);
12284 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
12285 * @phba: Pointer to HBA context object.
12286 * @wcqe: Pointer to work-queue completion queue entry.
12288 * This routine handles an ELS work-queue completion event and construct
12289 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
12290 * discovery engine to handle.
12292 * Return: Pointer to the receive IOCBQ, NULL otherwise.
12294 static struct lpfc_iocbq *
12295 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
12296 struct lpfc_iocbq *irspiocbq)
12298 struct lpfc_sli_ring *pring;
12299 struct lpfc_iocbq *cmdiocbq;
12300 struct lpfc_wcqe_complete *wcqe;
12301 unsigned long iflags;
12303 pring = lpfc_phba_elsring(phba);
12305 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
12306 spin_lock_irqsave(&pring->ring_lock, iflags);
12307 pring->stats.iocb_event++;
12308 /* Look up the ELS command IOCB and create pseudo response IOCB */
12309 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
12310 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12311 /* Put the iocb back on the txcmplq */
12312 lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
12313 spin_unlock_irqrestore(&pring->ring_lock, iflags);
12315 if (unlikely(!cmdiocbq)) {
12316 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12317 "0386 ELS complete with no corresponding "
12318 "cmdiocb: iotag (%d)\n",
12319 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12320 lpfc_sli_release_iocbq(phba, irspiocbq);
12324 /* Fake the irspiocbq and copy necessary response information */
12325 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
12331 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
12332 * @phba: Pointer to HBA context object.
12333 * @cqe: Pointer to mailbox completion queue entry.
12335 * This routine process a mailbox completion queue entry with asynchrous
12338 * Return: true if work posted to worker thread, otherwise false.
12341 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
12343 struct lpfc_cq_event *cq_event;
12344 unsigned long iflags;
12346 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12347 "0392 Async Event: word0:x%x, word1:x%x, "
12348 "word2:x%x, word3:x%x\n", mcqe->word0,
12349 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
12351 /* Allocate a new internal CQ_EVENT entry */
12352 cq_event = lpfc_sli4_cq_event_alloc(phba);
12354 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12355 "0394 Failed to allocate CQ_EVENT entry\n");
12359 /* Move the CQE into an asynchronous event entry */
12360 memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe));
12361 spin_lock_irqsave(&phba->hbalock, iflags);
12362 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
12363 /* Set the async event flag */
12364 phba->hba_flag |= ASYNC_EVENT;
12365 spin_unlock_irqrestore(&phba->hbalock, iflags);
12371 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
12372 * @phba: Pointer to HBA context object.
12373 * @cqe: Pointer to mailbox completion queue entry.
12375 * This routine process a mailbox completion queue entry with mailbox
12376 * completion event.
12378 * Return: true if work posted to worker thread, otherwise false.
12381 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
12383 uint32_t mcqe_status;
12384 MAILBOX_t *mbox, *pmbox;
12385 struct lpfc_mqe *mqe;
12386 struct lpfc_vport *vport;
12387 struct lpfc_nodelist *ndlp;
12388 struct lpfc_dmabuf *mp;
12389 unsigned long iflags;
12391 bool workposted = false;
12394 /* If not a mailbox complete MCQE, out by checking mailbox consume */
12395 if (!bf_get(lpfc_trailer_completed, mcqe))
12396 goto out_no_mqe_complete;
12398 /* Get the reference to the active mbox command */
12399 spin_lock_irqsave(&phba->hbalock, iflags);
12400 pmb = phba->sli.mbox_active;
12401 if (unlikely(!pmb)) {
12402 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
12403 "1832 No pending MBOX command to handle\n");
12404 spin_unlock_irqrestore(&phba->hbalock, iflags);
12405 goto out_no_mqe_complete;
12407 spin_unlock_irqrestore(&phba->hbalock, iflags);
12409 pmbox = (MAILBOX_t *)&pmb->u.mqe;
12411 vport = pmb->vport;
12413 /* Reset heartbeat timer */
12414 phba->last_completion_time = jiffies;
12415 del_timer(&phba->sli.mbox_tmo);
12417 /* Move mbox data to caller's mailbox region, do endian swapping */
12418 if (pmb->mbox_cmpl && mbox)
12419 lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
12422 * For mcqe errors, conditionally move a modified error code to
12423 * the mbox so that the error will not be missed.
12425 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
12426 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
12427 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
12428 bf_set(lpfc_mqe_status, mqe,
12429 (LPFC_MBX_ERROR_RANGE | mcqe_status));
12431 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
12432 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
12433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
12434 "MBOX dflt rpi: status:x%x rpi:x%x",
12436 pmbox->un.varWords[0], 0);
12437 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
12438 mp = (struct lpfc_dmabuf *)(pmb->context1);
12439 ndlp = (struct lpfc_nodelist *)pmb->context2;
12440 /* Reg_LOGIN of dflt RPI was successful. Now lets get
12441 * RID of the PPI using the same mbox buffer.
12443 lpfc_unreg_login(phba, vport->vpi,
12444 pmbox->un.varWords[0], pmb);
12445 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
12446 pmb->context1 = mp;
12447 pmb->context2 = ndlp;
12448 pmb->vport = vport;
12449 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
12450 if (rc != MBX_BUSY)
12451 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
12452 LOG_SLI, "0385 rc should "
12453 "have been MBX_BUSY\n");
12454 if (rc != MBX_NOT_FINISHED)
12455 goto send_current_mbox;
12458 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
12459 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
12460 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
12462 /* There is mailbox completion work to do */
12463 spin_lock_irqsave(&phba->hbalock, iflags);
12464 __lpfc_mbox_cmpl_put(phba, pmb);
12465 phba->work_ha |= HA_MBATT;
12466 spin_unlock_irqrestore(&phba->hbalock, iflags);
12470 spin_lock_irqsave(&phba->hbalock, iflags);
12471 /* Release the mailbox command posting token */
12472 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
12473 /* Setting active mailbox pointer need to be in sync to flag clear */
12474 phba->sli.mbox_active = NULL;
12475 spin_unlock_irqrestore(&phba->hbalock, iflags);
12476 /* Wake up worker thread to post the next pending mailbox command */
12477 lpfc_worker_wake_up(phba);
12478 out_no_mqe_complete:
12479 if (bf_get(lpfc_trailer_consumed, mcqe))
12480 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
12485 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
12486 * @phba: Pointer to HBA context object.
12487 * @cqe: Pointer to mailbox completion queue entry.
12489 * This routine process a mailbox completion queue entry, it invokes the
12490 * proper mailbox complete handling or asynchrous event handling routine
12491 * according to the MCQE's async bit.
12493 * Return: true if work posted to worker thread, otherwise false.
12496 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe)
12498 struct lpfc_mcqe mcqe;
12501 /* Copy the mailbox MCQE and convert endian order as needed */
12502 lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
12504 /* Invoke the proper event handling routine */
12505 if (!bf_get(lpfc_trailer_async, &mcqe))
12506 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
12508 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
12513 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
12514 * @phba: Pointer to HBA context object.
12515 * @cq: Pointer to associated CQ
12516 * @wcqe: Pointer to work-queue completion queue entry.
12518 * This routine handles an ELS work-queue completion event.
12520 * Return: true if work posted to worker thread, otherwise false.
12523 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
12524 struct lpfc_wcqe_complete *wcqe)
12526 struct lpfc_iocbq *irspiocbq;
12527 unsigned long iflags;
12528 struct lpfc_sli_ring *pring = cq->pring;
12530 int txcmplq_cnt = 0;
12531 int fcp_txcmplq_cnt = 0;
12533 /* Get an irspiocbq for later ELS response processing use */
12534 irspiocbq = lpfc_sli_get_iocbq(phba);
12536 if (!list_empty(&pring->txq))
12538 if (!list_empty(&pring->txcmplq))
12540 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12541 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
12542 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
12543 txq_cnt, phba->iocb_cnt,
12549 /* Save off the slow-path queue event for work thread to process */
12550 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
12551 spin_lock_irqsave(&phba->hbalock, iflags);
12552 list_add_tail(&irspiocbq->cq_event.list,
12553 &phba->sli4_hba.sp_queue_event);
12554 phba->hba_flag |= HBA_SP_QUEUE_EVT;
12555 spin_unlock_irqrestore(&phba->hbalock, iflags);
12561 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
12562 * @phba: Pointer to HBA context object.
12563 * @wcqe: Pointer to work-queue completion queue entry.
12565 * This routine handles slow-path WQ entry comsumed event by invoking the
12566 * proper WQ release routine to the slow-path WQ.
12569 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
12570 struct lpfc_wcqe_release *wcqe)
12572 /* sanity check on queue memory */
12573 if (unlikely(!phba->sli4_hba.els_wq))
12575 /* Check for the slow-path ELS work queue */
12576 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
12577 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
12578 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
12580 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12581 "2579 Slow-path wqe consume event carries "
12582 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
12583 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
12584 phba->sli4_hba.els_wq->queue_id);
12588 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
12589 * @phba: Pointer to HBA context object.
12590 * @cq: Pointer to a WQ completion queue.
12591 * @wcqe: Pointer to work-queue completion queue entry.
12593 * This routine handles an XRI abort event.
12595 * Return: true if work posted to worker thread, otherwise false.
12598 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
12599 struct lpfc_queue *cq,
12600 struct sli4_wcqe_xri_aborted *wcqe)
12602 bool workposted = false;
12603 struct lpfc_cq_event *cq_event;
12604 unsigned long iflags;
12606 /* Allocate a new internal CQ_EVENT entry */
12607 cq_event = lpfc_sli4_cq_event_alloc(phba);
12609 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12610 "0602 Failed to allocate CQ_EVENT entry\n");
12614 /* Move the CQE into the proper xri abort event list */
12615 memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
12616 switch (cq->subtype) {
12618 spin_lock_irqsave(&phba->hbalock, iflags);
12619 list_add_tail(&cq_event->list,
12620 &phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
12621 /* Set the fcp xri abort event flag */
12622 phba->hba_flag |= FCP_XRI_ABORT_EVENT;
12623 spin_unlock_irqrestore(&phba->hbalock, iflags);
12627 spin_lock_irqsave(&phba->hbalock, iflags);
12628 list_add_tail(&cq_event->list,
12629 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
12630 /* Set the els xri abort event flag */
12631 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
12632 spin_unlock_irqrestore(&phba->hbalock, iflags);
12636 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12637 "0603 Invalid work queue CQE subtype (x%x)\n",
12639 workposted = false;
12646 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
12647 * @phba: Pointer to HBA context object.
12648 * @rcqe: Pointer to receive-queue completion queue entry.
12650 * This routine process a receive-queue completion queue entry.
12652 * Return: true if work posted to worker thread, otherwise false.
12655 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
12657 bool workposted = false;
12658 struct fc_frame_header *fc_hdr;
12659 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
12660 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
12661 struct hbq_dmabuf *dma_buf;
12662 uint32_t status, rq_id;
12663 unsigned long iflags;
12665 /* sanity check on queue memory */
12666 if (unlikely(!hrq) || unlikely(!drq))
12669 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
12670 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
12672 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
12673 if (rq_id != hrq->queue_id)
12676 status = bf_get(lpfc_rcqe_status, rcqe);
12678 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
12679 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12680 "2537 Receive Frame Truncated!!\n");
12681 hrq->RQ_buf_trunc++;
12682 case FC_STATUS_RQ_SUCCESS:
12683 lpfc_sli4_rq_release(hrq, drq);
12684 spin_lock_irqsave(&phba->hbalock, iflags);
12685 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
12687 hrq->RQ_no_buf_found++;
12688 spin_unlock_irqrestore(&phba->hbalock, iflags);
12692 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
12694 /* If a NVME LS event (type 0x28), treat it as Fast path */
12695 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
12697 /* save off the frame for the word thread to process */
12698 list_add_tail(&dma_buf->cq_event.list,
12699 &phba->sli4_hba.sp_queue_event);
12700 /* Frame received */
12701 phba->hba_flag |= HBA_SP_QUEUE_EVT;
12702 spin_unlock_irqrestore(&phba->hbalock, iflags);
12705 case FC_STATUS_INSUFF_BUF_NEED_BUF:
12706 case FC_STATUS_INSUFF_BUF_FRM_DISC:
12707 hrq->RQ_no_posted_buf++;
12708 /* Post more buffers if possible */
12709 spin_lock_irqsave(&phba->hbalock, iflags);
12710 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
12711 spin_unlock_irqrestore(&phba->hbalock, iflags);
12720 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
12721 * @phba: Pointer to HBA context object.
12722 * @cq: Pointer to the completion queue.
12723 * @wcqe: Pointer to a completion queue entry.
12725 * This routine process a slow-path work-queue or receive queue completion queue
12728 * Return: true if work posted to worker thread, otherwise false.
12731 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
12732 struct lpfc_cqe *cqe)
12734 struct lpfc_cqe cqevt;
12735 bool workposted = false;
12737 /* Copy the work queue CQE and convert endian order if needed */
12738 lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
12740 /* Check and process for different type of WCQE and dispatch */
12741 switch (bf_get(lpfc_cqe_code, &cqevt)) {
12742 case CQE_CODE_COMPL_WQE:
12743 /* Process the WQ/RQ complete event */
12744 phba->last_completion_time = jiffies;
12745 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
12746 (struct lpfc_wcqe_complete *)&cqevt);
12748 case CQE_CODE_RELEASE_WQE:
12749 /* Process the WQ release event */
12750 lpfc_sli4_sp_handle_rel_wcqe(phba,
12751 (struct lpfc_wcqe_release *)&cqevt);
12753 case CQE_CODE_XRI_ABORTED:
12754 /* Process the WQ XRI abort event */
12755 phba->last_completion_time = jiffies;
12756 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
12757 (struct sli4_wcqe_xri_aborted *)&cqevt);
12759 case CQE_CODE_RECEIVE:
12760 case CQE_CODE_RECEIVE_V1:
12761 /* Process the RQ event */
12762 phba->last_completion_time = jiffies;
12763 workposted = lpfc_sli4_sp_handle_rcqe(phba,
12764 (struct lpfc_rcqe *)&cqevt);
12767 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12768 "0388 Not a valid WCQE code: x%x\n",
12769 bf_get(lpfc_cqe_code, &cqevt));
12776 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
12777 * @phba: Pointer to HBA context object.
12778 * @eqe: Pointer to fast-path event queue entry.
12780 * This routine process a event queue entry from the slow-path event queue.
12781 * It will check the MajorCode and MinorCode to determine this is for a
12782 * completion event on a completion queue, if not, an error shall be logged
12783 * and just return. Otherwise, it will get to the corresponding completion
12784 * queue and process all the entries on that completion queue, rearm the
12785 * completion queue, and then return.
12789 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
12790 struct lpfc_queue *speq)
12792 struct lpfc_queue *cq = NULL, *childq;
12793 struct lpfc_cqe *cqe;
12794 bool workposted = false;
12798 /* Get the reference to the corresponding CQ */
12799 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
12801 list_for_each_entry(childq, &speq->child_list, list) {
12802 if (childq->queue_id == cqid) {
12807 if (unlikely(!cq)) {
12808 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
12809 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12810 "0365 Slow-path CQ identifier "
12811 "(%d) does not exist\n", cqid);
12815 /* Save EQ associated with this CQ */
12816 cq->assoc_qp = speq;
12818 /* Process all the entries to the CQ */
12819 switch (cq->type) {
12821 while ((cqe = lpfc_sli4_cq_get(cq))) {
12822 workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe);
12823 if (!(++ecount % cq->entry_repost))
12824 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
12829 while ((cqe = lpfc_sli4_cq_get(cq))) {
12830 if ((cq->subtype == LPFC_FCP) ||
12831 (cq->subtype == LPFC_NVME))
12832 workposted |= lpfc_sli4_fp_handle_cqe(phba, cq,
12835 workposted |= lpfc_sli4_sp_handle_cqe(phba, cq,
12837 if (!(++ecount % cq->entry_repost))
12838 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
12841 /* Track the max number of CQEs processed in 1 EQ */
12842 if (ecount > cq->CQ_max_cqe)
12843 cq->CQ_max_cqe = ecount;
12846 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12847 "0370 Invalid completion queue type (%d)\n",
12852 /* Catch the no cq entry condition, log an error */
12853 if (unlikely(ecount == 0))
12854 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12855 "0371 No entry from the CQ: identifier "
12856 "(x%x), type (%d)\n", cq->queue_id, cq->type);
12858 /* In any case, flash and re-arm the RCQ */
12859 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
12861 /* wake up worker thread if there are works to be done */
12863 lpfc_worker_wake_up(phba);
12867 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
12868 * @phba: Pointer to HBA context object.
12869 * @cq: Pointer to associated CQ
12870 * @wcqe: Pointer to work-queue completion queue entry.
12872 * This routine process a fast-path work queue completion entry from fast-path
12873 * event queue for FCP command response completion.
12876 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
12877 struct lpfc_wcqe_complete *wcqe)
12879 struct lpfc_sli_ring *pring = cq->pring;
12880 struct lpfc_iocbq *cmdiocbq;
12881 struct lpfc_iocbq irspiocbq;
12882 unsigned long iflags;
12884 /* Check for response status */
12885 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
12886 /* If resource errors reported from HBA, reduce queue
12887 * depth of the SCSI device.
12889 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
12890 IOSTAT_LOCAL_REJECT)) &&
12891 ((wcqe->parameter & IOERR_PARAM_MASK) ==
12892 IOERR_NO_RESOURCES))
12893 phba->lpfc_rampdown_queue_depth(phba);
12895 /* Log the error status */
12896 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12897 "0373 FCP complete error: status=x%x, "
12898 "hw_status=x%x, total_data_specified=%d, "
12899 "parameter=x%x, word3=x%x\n",
12900 bf_get(lpfc_wcqe_c_status, wcqe),
12901 bf_get(lpfc_wcqe_c_hw_status, wcqe),
12902 wcqe->total_data_placed, wcqe->parameter,
12906 /* Look up the FCP command IOCB and create pseudo response IOCB */
12907 spin_lock_irqsave(&pring->ring_lock, iflags);
12908 pring->stats.iocb_event++;
12909 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
12910 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12911 spin_unlock_irqrestore(&pring->ring_lock, iflags);
12912 if (unlikely(!cmdiocbq)) {
12913 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12914 "0374 FCP complete with no corresponding "
12915 "cmdiocb: iotag (%d)\n",
12916 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12921 cmdiocbq->isr_timestamp =
12922 cq->assoc_qp->isr_timestamp;
12924 if (cmdiocbq->iocb_cmpl == NULL) {
12925 if (cmdiocbq->wqe_cmpl) {
12926 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
12927 spin_lock_irqsave(&phba->hbalock, iflags);
12928 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
12929 spin_unlock_irqrestore(&phba->hbalock, iflags);
12932 /* Pass the cmd_iocb and the wcqe to the upper layer */
12933 (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe);
12936 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12937 "0375 FCP cmdiocb not callback function "
12939 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12943 /* Fake the irspiocb and copy necessary response information */
12944 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
12946 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
12947 spin_lock_irqsave(&phba->hbalock, iflags);
12948 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
12949 spin_unlock_irqrestore(&phba->hbalock, iflags);
12952 /* Pass the cmd_iocb and the rsp state to the upper layer */
12953 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
12957 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
12958 * @phba: Pointer to HBA context object.
12959 * @cq: Pointer to completion queue.
12960 * @wcqe: Pointer to work-queue completion queue entry.
12962 * This routine handles an fast-path WQ entry comsumed event by invoking the
12963 * proper WQ release routine to the slow-path WQ.
12966 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
12967 struct lpfc_wcqe_release *wcqe)
12969 struct lpfc_queue *childwq;
12970 bool wqid_matched = false;
12973 /* Check for fast-path FCP work queue release */
12974 hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
12975 list_for_each_entry(childwq, &cq->child_list, list) {
12976 if (childwq->queue_id == hba_wqid) {
12977 lpfc_sli4_wq_release(childwq,
12978 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
12979 wqid_matched = true;
12983 /* Report warning log message if no match found */
12984 if (wqid_matched != true)
12985 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12986 "2580 Fast-path wqe consume event carries "
12987 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
12991 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
12992 * @cq: Pointer to the completion queue.
12993 * @eqe: Pointer to fast-path completion queue entry.
12995 * This routine process a fast-path work queue completion entry from fast-path
12996 * event queue for FCP command response completion.
12999 lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13000 struct lpfc_cqe *cqe)
13002 struct lpfc_wcqe_release wcqe;
13003 bool workposted = false;
13005 /* Copy the work queue CQE and convert endian order if needed */
13006 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
13008 /* Check and process for different type of WCQE and dispatch */
13009 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
13010 case CQE_CODE_COMPL_WQE:
13011 case CQE_CODE_NVME_ERSP:
13013 /* Process the WQ complete event */
13014 phba->last_completion_time = jiffies;
13015 if ((cq->subtype == LPFC_FCP) || (cq->subtype == LPFC_NVME))
13016 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
13017 (struct lpfc_wcqe_complete *)&wcqe);
13018 if (cq->subtype == LPFC_NVME_LS)
13019 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
13020 (struct lpfc_wcqe_complete *)&wcqe);
13022 case CQE_CODE_RELEASE_WQE:
13023 cq->CQ_release_wqe++;
13024 /* Process the WQ release event */
13025 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
13026 (struct lpfc_wcqe_release *)&wcqe);
13028 case CQE_CODE_XRI_ABORTED:
13029 cq->CQ_xri_aborted++;
13030 /* Process the WQ XRI abort event */
13031 phba->last_completion_time = jiffies;
13032 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
13033 (struct sli4_wcqe_xri_aborted *)&wcqe);
13035 case CQE_CODE_RECEIVE_V1:
13036 case CQE_CODE_RECEIVE:
13037 phba->last_completion_time = jiffies;
13040 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13041 "0144 Not a valid CQE code: x%x\n",
13042 bf_get(lpfc_wcqe_c_code, &wcqe));
13049 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
13050 * @phba: Pointer to HBA context object.
13051 * @eqe: Pointer to fast-path event queue entry.
13053 * This routine process a event queue entry from the fast-path event queue.
13054 * It will check the MajorCode and MinorCode to determine this is for a
13055 * completion event on a completion queue, if not, an error shall be logged
13056 * and just return. Otherwise, it will get to the corresponding completion
13057 * queue and process all the entries on the completion queue, rearm the
13058 * completion queue, and then return.
13061 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
13064 struct lpfc_queue *cq = NULL;
13065 struct lpfc_cqe *cqe;
13066 bool workposted = false;
13070 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
13071 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13072 "0366 Not a valid completion "
13073 "event: majorcode=x%x, minorcode=x%x\n",
13074 bf_get_le32(lpfc_eqe_major_code, eqe),
13075 bf_get_le32(lpfc_eqe_minor_code, eqe));
13079 /* Get the reference to the corresponding CQ */
13080 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
13082 if (phba->sli4_hba.nvme_cq_map &&
13083 (cqid == phba->sli4_hba.nvme_cq_map[qidx])) {
13084 /* Process NVME / NVMET command completion */
13085 cq = phba->sli4_hba.nvme_cq[qidx];
13089 if (phba->sli4_hba.fcp_cq_map &&
13090 (cqid == phba->sli4_hba.fcp_cq_map[qidx])) {
13091 /* Process FCP command completion */
13092 cq = phba->sli4_hba.fcp_cq[qidx];
13096 if (phba->sli4_hba.nvmels_cq &&
13097 (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
13098 /* Process NVME unsol rcv */
13099 cq = phba->sli4_hba.nvmels_cq;
13102 /* Otherwise this is a Slow path event */
13104 lpfc_sli4_sp_handle_eqe(phba, eqe, phba->sli4_hba.hba_eq[qidx]);
13109 if (unlikely(cqid != cq->queue_id)) {
13110 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13111 "0368 Miss-matched fast-path completion "
13112 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
13113 cqid, cq->queue_id);
13117 /* Save EQ associated with this CQ */
13118 cq->assoc_qp = phba->sli4_hba.hba_eq[qidx];
13120 /* Process all the entries to the CQ */
13121 while ((cqe = lpfc_sli4_cq_get(cq))) {
13122 workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe);
13123 if (!(++ecount % cq->entry_repost))
13124 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
13127 /* Track the max number of CQEs processed in 1 EQ */
13128 if (ecount > cq->CQ_max_cqe)
13129 cq->CQ_max_cqe = ecount;
13131 /* Catch the no cq entry condition */
13132 if (unlikely(ecount == 0))
13133 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13134 "0369 No entry from fast-path completion "
13135 "queue fcpcqid=%d\n", cq->queue_id);
13137 /* In any case, flash and re-arm the CQ */
13138 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
13140 /* wake up worker thread if there are works to be done */
13142 lpfc_worker_wake_up(phba);
13146 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
13148 struct lpfc_eqe *eqe;
13150 /* walk all the EQ entries and drop on the floor */
13151 while ((eqe = lpfc_sli4_eq_get(eq)))
13154 /* Clear and re-arm the EQ */
13155 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
13160 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
13162 * @phba: Pointer to HBA context object.
13163 * @eqe: Pointer to fast-path event queue entry.
13165 * This routine process a event queue entry from the Flash Optimized Fabric
13166 * event queue. It will check the MajorCode and MinorCode to determine this
13167 * is for a completion event on a completion queue, if not, an error shall be
13168 * logged and just return. Otherwise, it will get to the corresponding
13169 * completion queue and process all the entries on the completion queue, rearm
13170 * the completion queue, and then return.
13173 lpfc_sli4_fof_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
13175 struct lpfc_queue *cq;
13176 struct lpfc_cqe *cqe;
13177 bool workposted = false;
13181 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
13182 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13183 "9147 Not a valid completion "
13184 "event: majorcode=x%x, minorcode=x%x\n",
13185 bf_get_le32(lpfc_eqe_major_code, eqe),
13186 bf_get_le32(lpfc_eqe_minor_code, eqe));
13190 /* Get the reference to the corresponding CQ */
13191 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
13193 /* Next check for OAS */
13194 cq = phba->sli4_hba.oas_cq;
13195 if (unlikely(!cq)) {
13196 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
13197 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13198 "9148 OAS completion queue "
13199 "does not exist\n");
13203 if (unlikely(cqid != cq->queue_id)) {
13204 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13205 "9149 Miss-matched fast-path compl "
13206 "queue id: eqcqid=%d, fcpcqid=%d\n",
13207 cqid, cq->queue_id);
13211 /* Process all the entries to the OAS CQ */
13212 while ((cqe = lpfc_sli4_cq_get(cq))) {
13213 workposted |= lpfc_sli4_fp_handle_cqe(phba, cq, cqe);
13214 if (!(++ecount % cq->entry_repost))
13215 lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM);
13218 /* Track the max number of CQEs processed in 1 EQ */
13219 if (ecount > cq->CQ_max_cqe)
13220 cq->CQ_max_cqe = ecount;
13222 /* Catch the no cq entry condition */
13223 if (unlikely(ecount == 0))
13224 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13225 "9153 No entry from fast-path completion "
13226 "queue fcpcqid=%d\n", cq->queue_id);
13228 /* In any case, flash and re-arm the CQ */
13229 lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM);
13231 /* wake up worker thread if there are works to be done */
13233 lpfc_worker_wake_up(phba);
13237 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
13238 * @irq: Interrupt number.
13239 * @dev_id: The device context pointer.
13241 * This function is directly called from the PCI layer as an interrupt
13242 * service routine when device with SLI-4 interface spec is enabled with
13243 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
13244 * IOCB ring event in the HBA. However, when the device is enabled with either
13245 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13246 * device-level interrupt handler. When the PCI slot is in error recovery
13247 * or the HBA is undergoing initialization, the interrupt handler will not
13248 * process the interrupt. The Flash Optimized Fabric ring event are handled in
13249 * the intrrupt context. This function is called without any lock held.
13250 * It gets the hbalock to access and update SLI data structures. Note that,
13251 * the EQ to CQ are one-to-one map such that the EQ index is
13252 * equal to that of CQ index.
13254 * This function returns IRQ_HANDLED when interrupt is handled else it
13255 * returns IRQ_NONE.
13258 lpfc_sli4_fof_intr_handler(int irq, void *dev_id)
13260 struct lpfc_hba *phba;
13261 struct lpfc_hba_eq_hdl *hba_eq_hdl;
13262 struct lpfc_queue *eq;
13263 struct lpfc_eqe *eqe;
13264 unsigned long iflag;
13267 /* Get the driver's phba structure from the dev_id */
13268 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
13269 phba = hba_eq_hdl->phba;
13271 if (unlikely(!phba))
13274 /* Get to the EQ struct associated with this vector */
13275 eq = phba->sli4_hba.fof_eq;
13279 /* Check device state for handling interrupt */
13280 if (unlikely(lpfc_intr_state_check(phba))) {
13282 /* Check again for link_state with lock held */
13283 spin_lock_irqsave(&phba->hbalock, iflag);
13284 if (phba->link_state < LPFC_LINK_DOWN)
13285 /* Flush, clear interrupt, and rearm the EQ */
13286 lpfc_sli4_eq_flush(phba, eq);
13287 spin_unlock_irqrestore(&phba->hbalock, iflag);
13292 * Process all the event on FCP fast-path EQ
13294 while ((eqe = lpfc_sli4_eq_get(eq))) {
13295 lpfc_sli4_fof_handle_eqe(phba, eqe);
13296 if (!(++ecount % eq->entry_repost))
13297 lpfc_sli4_eq_release(eq, LPFC_QUEUE_NOARM);
13298 eq->EQ_processed++;
13301 /* Track the max number of EQEs processed in 1 intr */
13302 if (ecount > eq->EQ_max_eqe)
13303 eq->EQ_max_eqe = ecount;
13306 if (unlikely(ecount == 0)) {
13309 if (phba->intr_type == MSIX)
13310 /* MSI-X treated interrupt served as no EQ share INT */
13311 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13312 "9145 MSI-X interrupt with no EQE\n");
13314 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13315 "9146 ISR interrupt with no EQE\n");
13316 /* Non MSI-X treated on interrupt as EQ share INT */
13320 /* Always clear and re-arm the fast-path EQ */
13321 lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM);
13322 return IRQ_HANDLED;
13326 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
13327 * @irq: Interrupt number.
13328 * @dev_id: The device context pointer.
13330 * This function is directly called from the PCI layer as an interrupt
13331 * service routine when device with SLI-4 interface spec is enabled with
13332 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13333 * ring event in the HBA. However, when the device is enabled with either
13334 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13335 * device-level interrupt handler. When the PCI slot is in error recovery
13336 * or the HBA is undergoing initialization, the interrupt handler will not
13337 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13338 * the intrrupt context. This function is called without any lock held.
13339 * It gets the hbalock to access and update SLI data structures. Note that,
13340 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
13341 * equal to that of FCP CQ index.
13343 * The link attention and ELS ring attention events are handled
13344 * by the worker thread. The interrupt handler signals the worker thread
13345 * and returns for these events. This function is called without any lock
13346 * held. It gets the hbalock to access and update SLI data structures.
13348 * This function returns IRQ_HANDLED when interrupt is handled else it
13349 * returns IRQ_NONE.
13352 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
13354 struct lpfc_hba *phba;
13355 struct lpfc_hba_eq_hdl *hba_eq_hdl;
13356 struct lpfc_queue *fpeq;
13357 struct lpfc_eqe *eqe;
13358 unsigned long iflag;
13362 /* Get the driver's phba structure from the dev_id */
13363 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
13364 phba = hba_eq_hdl->phba;
13365 hba_eqidx = hba_eq_hdl->idx;
13367 if (unlikely(!phba))
13369 if (unlikely(!phba->sli4_hba.hba_eq))
13372 /* Get to the EQ struct associated with this vector */
13373 fpeq = phba->sli4_hba.hba_eq[hba_eqidx];
13374 if (unlikely(!fpeq))
13377 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13378 if (phba->ktime_on)
13379 fpeq->isr_timestamp = ktime_get_ns();
13382 if (lpfc_fcp_look_ahead) {
13383 if (atomic_dec_and_test(&hba_eq_hdl->hba_eq_in_use))
13384 lpfc_sli4_eq_clr_intr(fpeq);
13386 atomic_inc(&hba_eq_hdl->hba_eq_in_use);
13391 /* Check device state for handling interrupt */
13392 if (unlikely(lpfc_intr_state_check(phba))) {
13393 fpeq->EQ_badstate++;
13394 /* Check again for link_state with lock held */
13395 spin_lock_irqsave(&phba->hbalock, iflag);
13396 if (phba->link_state < LPFC_LINK_DOWN)
13397 /* Flush, clear interrupt, and rearm the EQ */
13398 lpfc_sli4_eq_flush(phba, fpeq);
13399 spin_unlock_irqrestore(&phba->hbalock, iflag);
13400 if (lpfc_fcp_look_ahead)
13401 atomic_inc(&hba_eq_hdl->hba_eq_in_use);
13406 * Process all the event on FCP fast-path EQ
13408 while ((eqe = lpfc_sli4_eq_get(fpeq))) {
13412 lpfc_sli4_hba_handle_eqe(phba, eqe, hba_eqidx);
13413 if (!(++ecount % fpeq->entry_repost))
13414 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM);
13415 fpeq->EQ_processed++;
13418 /* Track the max number of EQEs processed in 1 intr */
13419 if (ecount > fpeq->EQ_max_eqe)
13420 fpeq->EQ_max_eqe = ecount;
13422 /* Always clear and re-arm the fast-path EQ */
13423 lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM);
13425 if (unlikely(ecount == 0)) {
13426 fpeq->EQ_no_entry++;
13428 if (lpfc_fcp_look_ahead) {
13429 atomic_inc(&hba_eq_hdl->hba_eq_in_use);
13433 if (phba->intr_type == MSIX)
13434 /* MSI-X treated interrupt served as no EQ share INT */
13435 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13436 "0358 MSI-X interrupt with no EQE\n");
13438 /* Non MSI-X treated on interrupt as EQ share INT */
13442 if (lpfc_fcp_look_ahead)
13443 atomic_inc(&hba_eq_hdl->hba_eq_in_use);
13445 return IRQ_HANDLED;
13446 } /* lpfc_sli4_fp_intr_handler */
13449 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
13450 * @irq: Interrupt number.
13451 * @dev_id: The device context pointer.
13453 * This function is the device-level interrupt handler to device with SLI-4
13454 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
13455 * interrupt mode is enabled and there is an event in the HBA which requires
13456 * driver attention. This function invokes the slow-path interrupt attention
13457 * handling function and fast-path interrupt attention handling function in
13458 * turn to process the relevant HBA attention events. This function is called
13459 * without any lock held. It gets the hbalock to access and update SLI data
13462 * This function returns IRQ_HANDLED when interrupt is handled, else it
13463 * returns IRQ_NONE.
13466 lpfc_sli4_intr_handler(int irq, void *dev_id)
13468 struct lpfc_hba *phba;
13469 irqreturn_t hba_irq_rc;
13470 bool hba_handled = false;
13473 /* Get the driver's phba structure from the dev_id */
13474 phba = (struct lpfc_hba *)dev_id;
13476 if (unlikely(!phba))
13480 * Invoke fast-path host attention interrupt handling as appropriate.
13482 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) {
13483 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
13484 &phba->sli4_hba.hba_eq_hdl[qidx]);
13485 if (hba_irq_rc == IRQ_HANDLED)
13486 hba_handled |= true;
13489 if (phba->cfg_fof) {
13490 hba_irq_rc = lpfc_sli4_fof_intr_handler(irq,
13491 &phba->sli4_hba.hba_eq_hdl[qidx]);
13492 if (hba_irq_rc == IRQ_HANDLED)
13493 hba_handled |= true;
13496 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
13497 } /* lpfc_sli4_intr_handler */
13500 * lpfc_sli4_queue_free - free a queue structure and associated memory
13501 * @queue: The queue structure to free.
13503 * This function frees a queue structure and the DMAable memory used for
13504 * the host resident queue. This function must be called after destroying the
13505 * queue on the HBA.
13508 lpfc_sli4_queue_free(struct lpfc_queue *queue)
13510 struct lpfc_dmabuf *dmabuf;
13515 while (!list_empty(&queue->page_list)) {
13516 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
13518 dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE,
13519 dmabuf->virt, dmabuf->phys);
13523 lpfc_free_rq_buffer(queue->phba, queue);
13524 kfree(queue->rqbp);
13526 kfree(queue->pring);
13532 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
13533 * @phba: The HBA that this queue is being created on.
13534 * @entry_size: The size of each queue entry for this queue.
13535 * @entry count: The number of entries that this queue will handle.
13537 * This function allocates a queue structure and the DMAable memory used for
13538 * the host resident queue. This function must be called before creating the
13539 * queue on the HBA.
13541 struct lpfc_queue *
13542 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size,
13543 uint32_t entry_count)
13545 struct lpfc_queue *queue;
13546 struct lpfc_dmabuf *dmabuf;
13547 int x, total_qe_count;
13549 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
13551 if (!phba->sli4_hba.pc_sli4_params.supported)
13552 hw_page_size = SLI4_PAGE_SIZE;
13554 queue = kzalloc(sizeof(struct lpfc_queue) +
13555 (sizeof(union sli4_qe) * entry_count), GFP_KERNEL);
13558 queue->page_count = (ALIGN(entry_size * entry_count,
13559 hw_page_size))/hw_page_size;
13561 /* If needed, Adjust page count to match the max the adapter supports */
13562 if (queue->page_count > phba->sli4_hba.pc_sli4_params.wqpcnt)
13563 queue->page_count = phba->sli4_hba.pc_sli4_params.wqpcnt;
13565 INIT_LIST_HEAD(&queue->list);
13566 INIT_LIST_HEAD(&queue->wq_list);
13567 INIT_LIST_HEAD(&queue->page_list);
13568 INIT_LIST_HEAD(&queue->child_list);
13569 for (x = 0, total_qe_count = 0; x < queue->page_count; x++) {
13570 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
13573 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
13574 hw_page_size, &dmabuf->phys,
13576 if (!dmabuf->virt) {
13580 dmabuf->buffer_tag = x;
13581 list_add_tail(&dmabuf->list, &queue->page_list);
13582 /* initialize queue's entry array */
13583 dma_pointer = dmabuf->virt;
13584 for (; total_qe_count < entry_count &&
13585 dma_pointer < (hw_page_size + dmabuf->virt);
13586 total_qe_count++, dma_pointer += entry_size) {
13587 queue->qe[total_qe_count].address = dma_pointer;
13590 queue->entry_size = entry_size;
13591 queue->entry_count = entry_count;
13594 * entry_repost is calculated based on the number of entries in the
13595 * queue. This works out except for RQs. If buffers are NOT initially
13596 * posted for every RQE, entry_repost should be adjusted accordingly.
13598 queue->entry_repost = (entry_count >> 3);
13599 if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST)
13600 queue->entry_repost = LPFC_QUEUE_MIN_REPOST;
13601 queue->phba = phba;
13605 lpfc_sli4_queue_free(queue);
13610 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
13611 * @phba: HBA structure that indicates port to create a queue on.
13612 * @pci_barset: PCI BAR set flag.
13614 * This function shall perform iomap of the specified PCI BAR address to host
13615 * memory address if not already done so and return it. The returned host
13616 * memory address can be NULL.
13618 static void __iomem *
13619 lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
13624 switch (pci_barset) {
13625 case WQ_PCI_BAR_0_AND_1:
13626 return phba->pci_bar0_memmap_p;
13627 case WQ_PCI_BAR_2_AND_3:
13628 return phba->pci_bar2_memmap_p;
13629 case WQ_PCI_BAR_4_AND_5:
13630 return phba->pci_bar4_memmap_p;
13638 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs
13639 * @phba: HBA structure that indicates port to create a queue on.
13640 * @startq: The starting FCP EQ to modify
13642 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
13644 * The @phba struct is used to send mailbox command to HBA. The @startq
13645 * is used to get the starting FCP EQ to change.
13646 * This function is asynchronous and will wait for the mailbox
13647 * command to finish before continuing.
13649 * On success this function will return a zero. If unable to allocate enough
13650 * memory this function will return -ENOMEM. If the queue create mailbox command
13651 * fails this function will return -ENXIO.
13654 lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq)
13656 struct lpfc_mbx_modify_eq_delay *eq_delay;
13657 LPFC_MBOXQ_t *mbox;
13658 struct lpfc_queue *eq;
13659 int cnt, rc, length, status = 0;
13660 uint32_t shdr_status, shdr_add_status;
13663 union lpfc_sli4_cfg_shdr *shdr;
13666 if (startq >= phba->io_channel_irqs)
13669 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13672 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
13673 sizeof(struct lpfc_sli4_cfg_mhdr));
13674 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13675 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
13676 length, LPFC_SLI4_MBX_EMBED);
13677 eq_delay = &mbox->u.mqe.un.eq_delay;
13679 /* Calculate delay multiper from maximum interrupt per second */
13680 result = phba->cfg_fcp_imax / phba->io_channel_irqs;
13681 if (result > LPFC_DMULT_CONST || result == 0)
13684 dmult = LPFC_DMULT_CONST/result - 1;
13687 for (qidx = startq; qidx < phba->io_channel_irqs; qidx++) {
13688 eq = phba->sli4_hba.hba_eq[qidx];
13691 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
13692 eq_delay->u.request.eq[cnt].phase = 0;
13693 eq_delay->u.request.eq[cnt].delay_multi = dmult;
13695 if (cnt >= LPFC_MAX_EQ_DELAY)
13698 eq_delay->u.request.num_eq = cnt;
13700 mbox->vport = phba->pport;
13701 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13702 mbox->context1 = NULL;
13703 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13704 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
13705 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13706 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13707 if (shdr_status || shdr_add_status || rc) {
13708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13709 "2512 MODIFY_EQ_DELAY mailbox failed with "
13710 "status x%x add_status x%x, mbx status x%x\n",
13711 shdr_status, shdr_add_status, rc);
13714 mempool_free(mbox, phba->mbox_mem_pool);
13719 * lpfc_eq_create - Create an Event Queue on the HBA
13720 * @phba: HBA structure that indicates port to create a queue on.
13721 * @eq: The queue structure to use to create the event queue.
13722 * @imax: The maximum interrupt per second limit.
13724 * This function creates an event queue, as detailed in @eq, on a port,
13725 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
13727 * The @phba struct is used to send mailbox command to HBA. The @eq struct
13728 * is used to get the entry count and entry size that are necessary to
13729 * determine the number of pages to allocate and use for this queue. This
13730 * function will send the EQ_CREATE mailbox command to the HBA to setup the
13731 * event queue. This function is asynchronous and will wait for the mailbox
13732 * command to finish before continuing.
13734 * On success this function will return a zero. If unable to allocate enough
13735 * memory this function will return -ENOMEM. If the queue create mailbox command
13736 * fails this function will return -ENXIO.
13739 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
13741 struct lpfc_mbx_eq_create *eq_create;
13742 LPFC_MBOXQ_t *mbox;
13743 int rc, length, status = 0;
13744 struct lpfc_dmabuf *dmabuf;
13745 uint32_t shdr_status, shdr_add_status;
13746 union lpfc_sli4_cfg_shdr *shdr;
13748 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
13750 /* sanity check on queue memory */
13753 if (!phba->sli4_hba.pc_sli4_params.supported)
13754 hw_page_size = SLI4_PAGE_SIZE;
13756 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13759 length = (sizeof(struct lpfc_mbx_eq_create) -
13760 sizeof(struct lpfc_sli4_cfg_mhdr));
13761 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13762 LPFC_MBOX_OPCODE_EQ_CREATE,
13763 length, LPFC_SLI4_MBX_EMBED);
13764 eq_create = &mbox->u.mqe.un.eq_create;
13765 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
13767 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
13769 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
13770 /* don't setup delay multiplier using EQ_CREATE */
13772 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
13774 switch (eq->entry_count) {
13776 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13777 "0360 Unsupported EQ count. (%d)\n",
13779 if (eq->entry_count < 256)
13781 /* otherwise default to smallest count (drop through) */
13783 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
13787 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
13791 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
13795 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
13799 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
13803 list_for_each_entry(dmabuf, &eq->page_list, list) {
13804 memset(dmabuf->virt, 0, hw_page_size);
13805 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
13806 putPaddrLow(dmabuf->phys);
13807 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
13808 putPaddrHigh(dmabuf->phys);
13810 mbox->vport = phba->pport;
13811 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13812 mbox->context1 = NULL;
13813 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13814 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
13815 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13816 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13817 if (shdr_status || shdr_add_status || rc) {
13818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13819 "2500 EQ_CREATE mailbox failed with "
13820 "status x%x add_status x%x, mbx status x%x\n",
13821 shdr_status, shdr_add_status, rc);
13824 eq->type = LPFC_EQ;
13825 eq->subtype = LPFC_NONE;
13826 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
13827 if (eq->queue_id == 0xFFFF)
13829 eq->host_index = 0;
13832 mempool_free(mbox, phba->mbox_mem_pool);
13837 * lpfc_cq_create - Create a Completion Queue on the HBA
13838 * @phba: HBA structure that indicates port to create a queue on.
13839 * @cq: The queue structure to use to create the completion queue.
13840 * @eq: The event queue to bind this completion queue to.
13842 * This function creates a completion queue, as detailed in @wq, on a port,
13843 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
13845 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13846 * is used to get the entry count and entry size that are necessary to
13847 * determine the number of pages to allocate and use for this queue. The @eq
13848 * is used to indicate which event queue to bind this completion queue to. This
13849 * function will send the CQ_CREATE mailbox command to the HBA to setup the
13850 * completion queue. This function is asynchronous and will wait for the mailbox
13851 * command to finish before continuing.
13853 * On success this function will return a zero. If unable to allocate enough
13854 * memory this function will return -ENOMEM. If the queue create mailbox command
13855 * fails this function will return -ENXIO.
13858 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
13859 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
13861 struct lpfc_mbx_cq_create *cq_create;
13862 struct lpfc_dmabuf *dmabuf;
13863 LPFC_MBOXQ_t *mbox;
13864 int rc, length, status = 0;
13865 uint32_t shdr_status, shdr_add_status;
13866 union lpfc_sli4_cfg_shdr *shdr;
13867 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
13869 /* sanity check on queue memory */
13872 if (!phba->sli4_hba.pc_sli4_params.supported)
13873 hw_page_size = SLI4_PAGE_SIZE;
13875 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
13878 length = (sizeof(struct lpfc_mbx_cq_create) -
13879 sizeof(struct lpfc_sli4_cfg_mhdr));
13880 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13881 LPFC_MBOX_OPCODE_CQ_CREATE,
13882 length, LPFC_SLI4_MBX_EMBED);
13883 cq_create = &mbox->u.mqe.un.cq_create;
13884 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
13885 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
13887 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
13888 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
13889 bf_set(lpfc_mbox_hdr_version, &shdr->request,
13890 phba->sli4_hba.pc_sli4_params.cqv);
13891 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
13892 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
13893 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1);
13894 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
13897 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
13900 switch (cq->entry_count) {
13902 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13903 "0361 Unsupported CQ count: "
13904 "entry cnt %d sz %d pg cnt %d repost %d\n",
13905 cq->entry_count, cq->entry_size,
13906 cq->page_count, cq->entry_repost);
13907 if (cq->entry_count < 256) {
13911 /* otherwise default to smallest count (drop through) */
13913 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
13917 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
13921 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
13925 list_for_each_entry(dmabuf, &cq->page_list, list) {
13926 memset(dmabuf->virt, 0, hw_page_size);
13927 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
13928 putPaddrLow(dmabuf->phys);
13929 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
13930 putPaddrHigh(dmabuf->phys);
13932 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
13934 /* The IOCTL status is embedded in the mailbox subheader. */
13935 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
13936 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
13937 if (shdr_status || shdr_add_status || rc) {
13938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
13939 "2501 CQ_CREATE mailbox failed with "
13940 "status x%x add_status x%x, mbx status x%x\n",
13941 shdr_status, shdr_add_status, rc);
13945 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
13946 if (cq->queue_id == 0xFFFF) {
13950 /* link the cq onto the parent eq child list */
13951 list_add_tail(&cq->list, &eq->child_list);
13952 /* Set up completion queue's type and subtype */
13954 cq->subtype = subtype;
13955 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
13956 cq->assoc_qid = eq->queue_id;
13957 cq->host_index = 0;
13961 mempool_free(mbox, phba->mbox_mem_pool);
13966 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
13967 * @phba: HBA structure that indicates port to create a queue on.
13968 * @mq: The queue structure to use to create the mailbox queue.
13969 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
13970 * @cq: The completion queue to associate with this cq.
13972 * This function provides failback (fb) functionality when the
13973 * mq_create_ext fails on older FW generations. It's purpose is identical
13974 * to mq_create_ext otherwise.
13976 * This routine cannot fail as all attributes were previously accessed and
13977 * initialized in mq_create_ext.
13980 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
13981 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
13983 struct lpfc_mbx_mq_create *mq_create;
13984 struct lpfc_dmabuf *dmabuf;
13987 length = (sizeof(struct lpfc_mbx_mq_create) -
13988 sizeof(struct lpfc_sli4_cfg_mhdr));
13989 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
13990 LPFC_MBOX_OPCODE_MQ_CREATE,
13991 length, LPFC_SLI4_MBX_EMBED);
13992 mq_create = &mbox->u.mqe.un.mq_create;
13993 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
13995 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
13997 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
13998 switch (mq->entry_count) {
14000 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
14001 LPFC_MQ_RING_SIZE_16);
14004 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
14005 LPFC_MQ_RING_SIZE_32);
14008 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
14009 LPFC_MQ_RING_SIZE_64);
14012 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
14013 LPFC_MQ_RING_SIZE_128);
14016 list_for_each_entry(dmabuf, &mq->page_list, list) {
14017 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
14018 putPaddrLow(dmabuf->phys);
14019 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
14020 putPaddrHigh(dmabuf->phys);
14025 * lpfc_mq_create - Create a mailbox Queue on the HBA
14026 * @phba: HBA structure that indicates port to create a queue on.
14027 * @mq: The queue structure to use to create the mailbox queue.
14028 * @cq: The completion queue to associate with this cq.
14029 * @subtype: The queue's subtype.
14031 * This function creates a mailbox queue, as detailed in @mq, on a port,
14032 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
14034 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14035 * is used to get the entry count and entry size that are necessary to
14036 * determine the number of pages to allocate and use for this queue. This
14037 * function will send the MQ_CREATE mailbox command to the HBA to setup the
14038 * mailbox queue. This function is asynchronous and will wait for the mailbox
14039 * command to finish before continuing.
14041 * On success this function will return a zero. If unable to allocate enough
14042 * memory this function will return -ENOMEM. If the queue create mailbox command
14043 * fails this function will return -ENXIO.
14046 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
14047 struct lpfc_queue *cq, uint32_t subtype)
14049 struct lpfc_mbx_mq_create *mq_create;
14050 struct lpfc_mbx_mq_create_ext *mq_create_ext;
14051 struct lpfc_dmabuf *dmabuf;
14052 LPFC_MBOXQ_t *mbox;
14053 int rc, length, status = 0;
14054 uint32_t shdr_status, shdr_add_status;
14055 union lpfc_sli4_cfg_shdr *shdr;
14056 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14058 /* sanity check on queue memory */
14061 if (!phba->sli4_hba.pc_sli4_params.supported)
14062 hw_page_size = SLI4_PAGE_SIZE;
14064 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14067 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
14068 sizeof(struct lpfc_sli4_cfg_mhdr));
14069 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14070 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
14071 length, LPFC_SLI4_MBX_EMBED);
14073 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
14074 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
14075 bf_set(lpfc_mbx_mq_create_ext_num_pages,
14076 &mq_create_ext->u.request, mq->page_count);
14077 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
14078 &mq_create_ext->u.request, 1);
14079 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
14080 &mq_create_ext->u.request, 1);
14081 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
14082 &mq_create_ext->u.request, 1);
14083 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
14084 &mq_create_ext->u.request, 1);
14085 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
14086 &mq_create_ext->u.request, 1);
14087 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
14088 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14089 phba->sli4_hba.pc_sli4_params.mqv);
14090 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
14091 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
14094 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
14096 switch (mq->entry_count) {
14098 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14099 "0362 Unsupported MQ count. (%d)\n",
14101 if (mq->entry_count < 16) {
14105 /* otherwise default to smallest count (drop through) */
14107 bf_set(lpfc_mq_context_ring_size,
14108 &mq_create_ext->u.request.context,
14109 LPFC_MQ_RING_SIZE_16);
14112 bf_set(lpfc_mq_context_ring_size,
14113 &mq_create_ext->u.request.context,
14114 LPFC_MQ_RING_SIZE_32);
14117 bf_set(lpfc_mq_context_ring_size,
14118 &mq_create_ext->u.request.context,
14119 LPFC_MQ_RING_SIZE_64);
14122 bf_set(lpfc_mq_context_ring_size,
14123 &mq_create_ext->u.request.context,
14124 LPFC_MQ_RING_SIZE_128);
14127 list_for_each_entry(dmabuf, &mq->page_list, list) {
14128 memset(dmabuf->virt, 0, hw_page_size);
14129 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
14130 putPaddrLow(dmabuf->phys);
14131 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
14132 putPaddrHigh(dmabuf->phys);
14134 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14135 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
14136 &mq_create_ext->u.response);
14137 if (rc != MBX_SUCCESS) {
14138 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14139 "2795 MQ_CREATE_EXT failed with "
14140 "status x%x. Failback to MQ_CREATE.\n",
14142 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
14143 mq_create = &mbox->u.mqe.un.mq_create;
14144 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14145 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
14146 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
14147 &mq_create->u.response);
14150 /* The IOCTL status is embedded in the mailbox subheader. */
14151 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14152 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14153 if (shdr_status || shdr_add_status || rc) {
14154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14155 "2502 MQ_CREATE mailbox failed with "
14156 "status x%x add_status x%x, mbx status x%x\n",
14157 shdr_status, shdr_add_status, rc);
14161 if (mq->queue_id == 0xFFFF) {
14165 mq->type = LPFC_MQ;
14166 mq->assoc_qid = cq->queue_id;
14167 mq->subtype = subtype;
14168 mq->host_index = 0;
14171 /* link the mq onto the parent cq child list */
14172 list_add_tail(&mq->list, &cq->child_list);
14174 mempool_free(mbox, phba->mbox_mem_pool);
14179 * lpfc_wq_create - Create a Work Queue on the HBA
14180 * @phba: HBA structure that indicates port to create a queue on.
14181 * @wq: The queue structure to use to create the work queue.
14182 * @cq: The completion queue to bind this work queue to.
14183 * @subtype: The subtype of the work queue indicating its functionality.
14185 * This function creates a work queue, as detailed in @wq, on a port, described
14186 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
14188 * The @phba struct is used to send mailbox command to HBA. The @wq struct
14189 * is used to get the entry count and entry size that are necessary to
14190 * determine the number of pages to allocate and use for this queue. The @cq
14191 * is used to indicate which completion queue to bind this work queue to. This
14192 * function will send the WQ_CREATE mailbox command to the HBA to setup the
14193 * work queue. This function is asynchronous and will wait for the mailbox
14194 * command to finish before continuing.
14196 * On success this function will return a zero. If unable to allocate enough
14197 * memory this function will return -ENOMEM. If the queue create mailbox command
14198 * fails this function will return -ENXIO.
14201 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
14202 struct lpfc_queue *cq, uint32_t subtype)
14204 struct lpfc_mbx_wq_create *wq_create;
14205 struct lpfc_dmabuf *dmabuf;
14206 LPFC_MBOXQ_t *mbox;
14207 int rc, length, status = 0;
14208 uint32_t shdr_status, shdr_add_status;
14209 union lpfc_sli4_cfg_shdr *shdr;
14210 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14211 struct dma_address *page;
14212 void __iomem *bar_memmap_p;
14213 uint32_t db_offset;
14214 uint16_t pci_barset;
14216 /* sanity check on queue memory */
14219 if (!phba->sli4_hba.pc_sli4_params.supported)
14220 hw_page_size = SLI4_PAGE_SIZE;
14222 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14225 length = (sizeof(struct lpfc_mbx_wq_create) -
14226 sizeof(struct lpfc_sli4_cfg_mhdr));
14227 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14228 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
14229 length, LPFC_SLI4_MBX_EMBED);
14230 wq_create = &mbox->u.mqe.un.wq_create;
14231 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
14232 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
14234 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
14237 /* wqv is the earliest version supported, NOT the latest */
14238 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14239 phba->sli4_hba.pc_sli4_params.wqv);
14241 switch (phba->sli4_hba.pc_sli4_params.wqv) {
14242 case LPFC_Q_CREATE_VERSION_0:
14243 switch (wq->entry_size) {
14246 /* Nothing to do, version 0 ONLY supports 64 byte */
14247 page = wq_create->u.request.page;
14250 if (!(phba->sli4_hba.pc_sli4_params.wqsize &
14251 LPFC_WQ_SZ128_SUPPORT)) {
14255 /* If we get here the HBA MUST also support V1 and
14258 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14259 LPFC_Q_CREATE_VERSION_1);
14261 bf_set(lpfc_mbx_wq_create_wqe_count,
14262 &wq_create->u.request_1, wq->entry_count);
14263 bf_set(lpfc_mbx_wq_create_wqe_size,
14264 &wq_create->u.request_1,
14265 LPFC_WQ_WQE_SIZE_128);
14266 bf_set(lpfc_mbx_wq_create_page_size,
14267 &wq_create->u.request_1,
14268 LPFC_WQ_PAGE_SIZE_4096);
14269 page = wq_create->u.request_1.page;
14273 case LPFC_Q_CREATE_VERSION_1:
14274 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
14276 switch (wq->entry_size) {
14279 bf_set(lpfc_mbx_wq_create_wqe_size,
14280 &wq_create->u.request_1,
14281 LPFC_WQ_WQE_SIZE_64);
14284 if (!(phba->sli4_hba.pc_sli4_params.wqsize &
14285 LPFC_WQ_SZ128_SUPPORT)) {
14289 bf_set(lpfc_mbx_wq_create_wqe_size,
14290 &wq_create->u.request_1,
14291 LPFC_WQ_WQE_SIZE_128);
14294 bf_set(lpfc_mbx_wq_create_page_size,
14295 &wq_create->u.request_1,
14296 LPFC_WQ_PAGE_SIZE_4096);
14297 page = wq_create->u.request_1.page;
14304 list_for_each_entry(dmabuf, &wq->page_list, list) {
14305 memset(dmabuf->virt, 0, hw_page_size);
14306 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
14307 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
14310 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
14311 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
14313 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14314 /* The IOCTL status is embedded in the mailbox subheader. */
14315 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14316 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14317 if (shdr_status || shdr_add_status || rc) {
14318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14319 "2503 WQ_CREATE mailbox failed with "
14320 "status x%x add_status x%x, mbx status x%x\n",
14321 shdr_status, shdr_add_status, rc);
14325 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response);
14326 if (wq->queue_id == 0xFFFF) {
14330 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
14331 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
14332 &wq_create->u.response);
14333 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
14334 (wq->db_format != LPFC_DB_RING_FORMAT)) {
14335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14336 "3265 WQ[%d] doorbell format not "
14337 "supported: x%x\n", wq->queue_id,
14342 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
14343 &wq_create->u.response);
14344 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
14345 if (!bar_memmap_p) {
14346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14347 "3263 WQ[%d] failed to memmap pci "
14348 "barset:x%x\n", wq->queue_id,
14353 db_offset = wq_create->u.response.doorbell_offset;
14354 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
14355 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
14356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14357 "3252 WQ[%d] doorbell offset not "
14358 "supported: x%x\n", wq->queue_id,
14363 wq->db_regaddr = bar_memmap_p + db_offset;
14364 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14365 "3264 WQ[%d]: barset:x%x, offset:x%x, "
14366 "format:x%x\n", wq->queue_id, pci_barset,
14367 db_offset, wq->db_format);
14369 wq->db_format = LPFC_DB_LIST_FORMAT;
14370 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
14372 wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
14373 if (wq->pring == NULL) {
14377 wq->type = LPFC_WQ;
14378 wq->assoc_qid = cq->queue_id;
14379 wq->subtype = subtype;
14380 wq->host_index = 0;
14382 wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL;
14384 /* link the wq onto the parent cq child list */
14385 list_add_tail(&wq->list, &cq->child_list);
14387 mempool_free(mbox, phba->mbox_mem_pool);
14392 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
14393 * @phba: HBA structure that indicates port to create a queue on.
14394 * @rq: The queue structure to use for the receive queue.
14395 * @qno: The associated HBQ number
14398 * For SLI4 we need to adjust the RQ repost value based on
14399 * the number of buffers that are initially posted to the RQ.
14402 lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno)
14406 /* sanity check on queue memory */
14409 cnt = lpfc_hbq_defs[qno]->entry_count;
14411 /* Recalc repost for RQs based on buffers initially posted */
14413 if (cnt < LPFC_QUEUE_MIN_REPOST)
14414 cnt = LPFC_QUEUE_MIN_REPOST;
14416 rq->entry_repost = cnt;
14420 * lpfc_rq_create - Create a Receive Queue on the HBA
14421 * @phba: HBA structure that indicates port to create a queue on.
14422 * @hrq: The queue structure to use to create the header receive queue.
14423 * @drq: The queue structure to use to create the data receive queue.
14424 * @cq: The completion queue to bind this work queue to.
14426 * This function creates a receive buffer queue pair , as detailed in @hrq and
14427 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
14430 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
14431 * struct is used to get the entry count that is necessary to determine the
14432 * number of pages to use for this queue. The @cq is used to indicate which
14433 * completion queue to bind received buffers that are posted to these queues to.
14434 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
14435 * receive queue pair. This function is asynchronous and will wait for the
14436 * mailbox command to finish before continuing.
14438 * On success this function will return a zero. If unable to allocate enough
14439 * memory this function will return -ENOMEM. If the queue create mailbox command
14440 * fails this function will return -ENXIO.
14443 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
14444 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
14446 struct lpfc_mbx_rq_create *rq_create;
14447 struct lpfc_dmabuf *dmabuf;
14448 LPFC_MBOXQ_t *mbox;
14449 int rc, length, status = 0;
14450 uint32_t shdr_status, shdr_add_status;
14451 union lpfc_sli4_cfg_shdr *shdr;
14452 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14453 void __iomem *bar_memmap_p;
14454 uint32_t db_offset;
14455 uint16_t pci_barset;
14457 /* sanity check on queue memory */
14458 if (!hrq || !drq || !cq)
14460 if (!phba->sli4_hba.pc_sli4_params.supported)
14461 hw_page_size = SLI4_PAGE_SIZE;
14463 if (hrq->entry_count != drq->entry_count)
14465 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14468 length = (sizeof(struct lpfc_mbx_rq_create) -
14469 sizeof(struct lpfc_sli4_cfg_mhdr));
14470 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14471 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
14472 length, LPFC_SLI4_MBX_EMBED);
14473 rq_create = &mbox->u.mqe.un.rq_create;
14474 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
14475 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14476 phba->sli4_hba.pc_sli4_params.rqv);
14477 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
14478 bf_set(lpfc_rq_context_rqe_count_1,
14479 &rq_create->u.request.context,
14481 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
14482 bf_set(lpfc_rq_context_rqe_size,
14483 &rq_create->u.request.context,
14485 bf_set(lpfc_rq_context_page_size,
14486 &rq_create->u.request.context,
14487 LPFC_RQ_PAGE_SIZE_4096);
14489 switch (hrq->entry_count) {
14491 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14492 "2535 Unsupported RQ count. (%d)\n",
14494 if (hrq->entry_count < 512) {
14498 /* otherwise default to smallest count (drop through) */
14500 bf_set(lpfc_rq_context_rqe_count,
14501 &rq_create->u.request.context,
14502 LPFC_RQ_RING_SIZE_512);
14505 bf_set(lpfc_rq_context_rqe_count,
14506 &rq_create->u.request.context,
14507 LPFC_RQ_RING_SIZE_1024);
14510 bf_set(lpfc_rq_context_rqe_count,
14511 &rq_create->u.request.context,
14512 LPFC_RQ_RING_SIZE_2048);
14515 bf_set(lpfc_rq_context_rqe_count,
14516 &rq_create->u.request.context,
14517 LPFC_RQ_RING_SIZE_4096);
14520 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
14521 LPFC_HDR_BUF_SIZE);
14523 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
14525 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
14527 list_for_each_entry(dmabuf, &hrq->page_list, list) {
14528 memset(dmabuf->virt, 0, hw_page_size);
14529 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
14530 putPaddrLow(dmabuf->phys);
14531 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
14532 putPaddrHigh(dmabuf->phys);
14534 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
14535 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
14537 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14538 /* The IOCTL status is embedded in the mailbox subheader. */
14539 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14540 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14541 if (shdr_status || shdr_add_status || rc) {
14542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14543 "2504 RQ_CREATE mailbox failed with "
14544 "status x%x add_status x%x, mbx status x%x\n",
14545 shdr_status, shdr_add_status, rc);
14549 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
14550 if (hrq->queue_id == 0xFFFF) {
14555 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
14556 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
14557 &rq_create->u.response);
14558 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
14559 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
14560 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14561 "3262 RQ [%d] doorbell format not "
14562 "supported: x%x\n", hrq->queue_id,
14568 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
14569 &rq_create->u.response);
14570 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
14571 if (!bar_memmap_p) {
14572 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14573 "3269 RQ[%d] failed to memmap pci "
14574 "barset:x%x\n", hrq->queue_id,
14580 db_offset = rq_create->u.response.doorbell_offset;
14581 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
14582 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
14583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14584 "3270 RQ[%d] doorbell offset not "
14585 "supported: x%x\n", hrq->queue_id,
14590 hrq->db_regaddr = bar_memmap_p + db_offset;
14591 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
14592 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
14593 "format:x%x\n", hrq->queue_id, pci_barset,
14594 db_offset, hrq->db_format);
14596 hrq->db_format = LPFC_DB_RING_FORMAT;
14597 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
14599 hrq->type = LPFC_HRQ;
14600 hrq->assoc_qid = cq->queue_id;
14601 hrq->subtype = subtype;
14602 hrq->host_index = 0;
14603 hrq->hba_index = 0;
14605 /* now create the data queue */
14606 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14607 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
14608 length, LPFC_SLI4_MBX_EMBED);
14609 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14610 phba->sli4_hba.pc_sli4_params.rqv);
14611 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
14612 bf_set(lpfc_rq_context_rqe_count_1,
14613 &rq_create->u.request.context, hrq->entry_count);
14614 rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE;
14615 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
14617 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
14618 (PAGE_SIZE/SLI4_PAGE_SIZE));
14620 switch (drq->entry_count) {
14622 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14623 "2536 Unsupported RQ count. (%d)\n",
14625 if (drq->entry_count < 512) {
14629 /* otherwise default to smallest count (drop through) */
14631 bf_set(lpfc_rq_context_rqe_count,
14632 &rq_create->u.request.context,
14633 LPFC_RQ_RING_SIZE_512);
14636 bf_set(lpfc_rq_context_rqe_count,
14637 &rq_create->u.request.context,
14638 LPFC_RQ_RING_SIZE_1024);
14641 bf_set(lpfc_rq_context_rqe_count,
14642 &rq_create->u.request.context,
14643 LPFC_RQ_RING_SIZE_2048);
14646 bf_set(lpfc_rq_context_rqe_count,
14647 &rq_create->u.request.context,
14648 LPFC_RQ_RING_SIZE_4096);
14651 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
14652 LPFC_DATA_BUF_SIZE);
14654 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
14656 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
14658 list_for_each_entry(dmabuf, &drq->page_list, list) {
14659 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
14660 putPaddrLow(dmabuf->phys);
14661 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
14662 putPaddrHigh(dmabuf->phys);
14664 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
14665 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
14666 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14667 /* The IOCTL status is embedded in the mailbox subheader. */
14668 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
14669 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14670 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14671 if (shdr_status || shdr_add_status || rc) {
14675 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
14676 if (drq->queue_id == 0xFFFF) {
14680 drq->type = LPFC_DRQ;
14681 drq->assoc_qid = cq->queue_id;
14682 drq->subtype = subtype;
14683 drq->host_index = 0;
14684 drq->hba_index = 0;
14686 /* link the header and data RQs onto the parent cq child list */
14687 list_add_tail(&hrq->list, &cq->child_list);
14688 list_add_tail(&drq->list, &cq->child_list);
14691 mempool_free(mbox, phba->mbox_mem_pool);
14696 * lpfc_eq_destroy - Destroy an event Queue on the HBA
14697 * @eq: The queue structure associated with the queue to destroy.
14699 * This function destroys a queue, as detailed in @eq by sending an mailbox
14700 * command, specific to the type of queue, to the HBA.
14702 * The @eq struct is used to get the queue ID of the queue to destroy.
14704 * On success this function will return a zero. If the queue destroy mailbox
14705 * command fails this function will return -ENXIO.
14708 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
14710 LPFC_MBOXQ_t *mbox;
14711 int rc, length, status = 0;
14712 uint32_t shdr_status, shdr_add_status;
14713 union lpfc_sli4_cfg_shdr *shdr;
14715 /* sanity check on queue memory */
14718 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
14721 length = (sizeof(struct lpfc_mbx_eq_destroy) -
14722 sizeof(struct lpfc_sli4_cfg_mhdr));
14723 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14724 LPFC_MBOX_OPCODE_EQ_DESTROY,
14725 length, LPFC_SLI4_MBX_EMBED);
14726 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
14728 mbox->vport = eq->phba->pport;
14729 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14731 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
14732 /* The IOCTL status is embedded in the mailbox subheader. */
14733 shdr = (union lpfc_sli4_cfg_shdr *)
14734 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
14735 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14736 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14737 if (shdr_status || shdr_add_status || rc) {
14738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14739 "2505 EQ_DESTROY mailbox failed with "
14740 "status x%x add_status x%x, mbx status x%x\n",
14741 shdr_status, shdr_add_status, rc);
14745 /* Remove eq from any list */
14746 list_del_init(&eq->list);
14747 mempool_free(mbox, eq->phba->mbox_mem_pool);
14752 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
14753 * @cq: The queue structure associated with the queue to destroy.
14755 * This function destroys a queue, as detailed in @cq by sending an mailbox
14756 * command, specific to the type of queue, to the HBA.
14758 * The @cq struct is used to get the queue ID of the queue to destroy.
14760 * On success this function will return a zero. If the queue destroy mailbox
14761 * command fails this function will return -ENXIO.
14764 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
14766 LPFC_MBOXQ_t *mbox;
14767 int rc, length, status = 0;
14768 uint32_t shdr_status, shdr_add_status;
14769 union lpfc_sli4_cfg_shdr *shdr;
14771 /* sanity check on queue memory */
14774 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
14777 length = (sizeof(struct lpfc_mbx_cq_destroy) -
14778 sizeof(struct lpfc_sli4_cfg_mhdr));
14779 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14780 LPFC_MBOX_OPCODE_CQ_DESTROY,
14781 length, LPFC_SLI4_MBX_EMBED);
14782 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
14784 mbox->vport = cq->phba->pport;
14785 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14786 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
14787 /* The IOCTL status is embedded in the mailbox subheader. */
14788 shdr = (union lpfc_sli4_cfg_shdr *)
14789 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
14790 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14791 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14792 if (shdr_status || shdr_add_status || rc) {
14793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14794 "2506 CQ_DESTROY mailbox failed with "
14795 "status x%x add_status x%x, mbx status x%x\n",
14796 shdr_status, shdr_add_status, rc);
14799 /* Remove cq from any list */
14800 list_del_init(&cq->list);
14801 mempool_free(mbox, cq->phba->mbox_mem_pool);
14806 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
14807 * @qm: The queue structure associated with the queue to destroy.
14809 * This function destroys a queue, as detailed in @mq by sending an mailbox
14810 * command, specific to the type of queue, to the HBA.
14812 * The @mq struct is used to get the queue ID of the queue to destroy.
14814 * On success this function will return a zero. If the queue destroy mailbox
14815 * command fails this function will return -ENXIO.
14818 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
14820 LPFC_MBOXQ_t *mbox;
14821 int rc, length, status = 0;
14822 uint32_t shdr_status, shdr_add_status;
14823 union lpfc_sli4_cfg_shdr *shdr;
14825 /* sanity check on queue memory */
14828 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
14831 length = (sizeof(struct lpfc_mbx_mq_destroy) -
14832 sizeof(struct lpfc_sli4_cfg_mhdr));
14833 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14834 LPFC_MBOX_OPCODE_MQ_DESTROY,
14835 length, LPFC_SLI4_MBX_EMBED);
14836 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
14838 mbox->vport = mq->phba->pport;
14839 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14840 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
14841 /* The IOCTL status is embedded in the mailbox subheader. */
14842 shdr = (union lpfc_sli4_cfg_shdr *)
14843 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
14844 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14845 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14846 if (shdr_status || shdr_add_status || rc) {
14847 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14848 "2507 MQ_DESTROY mailbox failed with "
14849 "status x%x add_status x%x, mbx status x%x\n",
14850 shdr_status, shdr_add_status, rc);
14853 /* Remove mq from any list */
14854 list_del_init(&mq->list);
14855 mempool_free(mbox, mq->phba->mbox_mem_pool);
14860 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
14861 * @wq: The queue structure associated with the queue to destroy.
14863 * This function destroys a queue, as detailed in @wq by sending an mailbox
14864 * command, specific to the type of queue, to the HBA.
14866 * The @wq struct is used to get the queue ID of the queue to destroy.
14868 * On success this function will return a zero. If the queue destroy mailbox
14869 * command fails this function will return -ENXIO.
14872 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
14874 LPFC_MBOXQ_t *mbox;
14875 int rc, length, status = 0;
14876 uint32_t shdr_status, shdr_add_status;
14877 union lpfc_sli4_cfg_shdr *shdr;
14879 /* sanity check on queue memory */
14882 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
14885 length = (sizeof(struct lpfc_mbx_wq_destroy) -
14886 sizeof(struct lpfc_sli4_cfg_mhdr));
14887 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14888 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
14889 length, LPFC_SLI4_MBX_EMBED);
14890 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
14892 mbox->vport = wq->phba->pport;
14893 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14894 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
14895 shdr = (union lpfc_sli4_cfg_shdr *)
14896 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
14897 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14898 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14899 if (shdr_status || shdr_add_status || rc) {
14900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14901 "2508 WQ_DESTROY mailbox failed with "
14902 "status x%x add_status x%x, mbx status x%x\n",
14903 shdr_status, shdr_add_status, rc);
14906 /* Remove wq from any list */
14907 list_del_init(&wq->list);
14908 mempool_free(mbox, wq->phba->mbox_mem_pool);
14913 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
14914 * @rq: The queue structure associated with the queue to destroy.
14916 * This function destroys a queue, as detailed in @rq by sending an mailbox
14917 * command, specific to the type of queue, to the HBA.
14919 * The @rq struct is used to get the queue ID of the queue to destroy.
14921 * On success this function will return a zero. If the queue destroy mailbox
14922 * command fails this function will return -ENXIO.
14925 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
14926 struct lpfc_queue *drq)
14928 LPFC_MBOXQ_t *mbox;
14929 int rc, length, status = 0;
14930 uint32_t shdr_status, shdr_add_status;
14931 union lpfc_sli4_cfg_shdr *shdr;
14933 /* sanity check on queue memory */
14936 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
14939 length = (sizeof(struct lpfc_mbx_rq_destroy) -
14940 sizeof(struct lpfc_sli4_cfg_mhdr));
14941 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14942 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
14943 length, LPFC_SLI4_MBX_EMBED);
14944 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
14946 mbox->vport = hrq->phba->pport;
14947 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14948 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
14949 /* The IOCTL status is embedded in the mailbox subheader. */
14950 shdr = (union lpfc_sli4_cfg_shdr *)
14951 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
14952 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14953 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14954 if (shdr_status || shdr_add_status || rc) {
14955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14956 "2509 RQ_DESTROY mailbox failed with "
14957 "status x%x add_status x%x, mbx status x%x\n",
14958 shdr_status, shdr_add_status, rc);
14959 if (rc != MBX_TIMEOUT)
14960 mempool_free(mbox, hrq->phba->mbox_mem_pool);
14963 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
14965 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
14966 shdr = (union lpfc_sli4_cfg_shdr *)
14967 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
14968 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14969 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14970 if (shdr_status || shdr_add_status || rc) {
14971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14972 "2510 RQ_DESTROY mailbox failed with "
14973 "status x%x add_status x%x, mbx status x%x\n",
14974 shdr_status, shdr_add_status, rc);
14977 list_del_init(&hrq->list);
14978 list_del_init(&drq->list);
14979 mempool_free(mbox, hrq->phba->mbox_mem_pool);
14984 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
14985 * @phba: The virtual port for which this call being executed.
14986 * @pdma_phys_addr0: Physical address of the 1st SGL page.
14987 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
14988 * @xritag: the xritag that ties this io to the SGL pages.
14990 * This routine will post the sgl pages for the IO that has the xritag
14991 * that is in the iocbq structure. The xritag is assigned during iocbq
14992 * creation and persists for as long as the driver is loaded.
14993 * if the caller has fewer than 256 scatter gather segments to map then
14994 * pdma_phys_addr1 should be 0.
14995 * If the caller needs to map more than 256 scatter gather segment then
14996 * pdma_phys_addr1 should be a valid physical address.
14997 * physical address for SGLs must be 64 byte aligned.
14998 * If you are going to map 2 SGL's then the first one must have 256 entries
14999 * the second sgl can have between 1 and 256 entries.
15003 * -ENXIO, -ENOMEM - Failure
15006 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
15007 dma_addr_t pdma_phys_addr0,
15008 dma_addr_t pdma_phys_addr1,
15011 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
15012 LPFC_MBOXQ_t *mbox;
15014 uint32_t shdr_status, shdr_add_status;
15016 union lpfc_sli4_cfg_shdr *shdr;
15018 if (xritag == NO_XRI) {
15019 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15020 "0364 Invalid param:\n");
15024 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15028 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15029 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
15030 sizeof(struct lpfc_mbx_post_sgl_pages) -
15031 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
15033 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
15034 &mbox->u.mqe.un.post_sgl_pages;
15035 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
15036 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
15038 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
15039 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
15040 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
15041 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
15043 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
15044 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
15045 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
15046 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
15047 if (!phba->sli4_hba.intr_enable)
15048 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15050 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
15051 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
15053 /* The IOCTL status is embedded in the mailbox subheader. */
15054 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
15055 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15056 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15057 if (rc != MBX_TIMEOUT)
15058 mempool_free(mbox, phba->mbox_mem_pool);
15059 if (shdr_status || shdr_add_status || rc) {
15060 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15061 "2511 POST_SGL mailbox failed with "
15062 "status x%x add_status x%x, mbx status x%x\n",
15063 shdr_status, shdr_add_status, rc);
15069 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
15070 * @phba: pointer to lpfc hba data structure.
15072 * This routine is invoked to post rpi header templates to the
15073 * HBA consistent with the SLI-4 interface spec. This routine
15074 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15075 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15078 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
15079 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15082 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
15087 * Fetch the next logical xri. Because this index is logical,
15088 * the driver starts at 0 each time.
15090 spin_lock_irq(&phba->hbalock);
15091 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
15092 phba->sli4_hba.max_cfg_param.max_xri, 0);
15093 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
15094 spin_unlock_irq(&phba->hbalock);
15097 set_bit(xri, phba->sli4_hba.xri_bmask);
15098 phba->sli4_hba.max_cfg_param.xri_used++;
15100 spin_unlock_irq(&phba->hbalock);
15105 * lpfc_sli4_free_xri - Release an xri for reuse.
15106 * @phba: pointer to lpfc hba data structure.
15108 * This routine is invoked to release an xri to the pool of
15109 * available rpis maintained by the driver.
15112 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
15114 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
15115 phba->sli4_hba.max_cfg_param.xri_used--;
15120 * lpfc_sli4_free_xri - Release an xri for reuse.
15121 * @phba: pointer to lpfc hba data structure.
15123 * This routine is invoked to release an xri to the pool of
15124 * available rpis maintained by the driver.
15127 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
15129 spin_lock_irq(&phba->hbalock);
15130 __lpfc_sli4_free_xri(phba, xri);
15131 spin_unlock_irq(&phba->hbalock);
15135 * lpfc_sli4_next_xritag - Get an xritag for the io
15136 * @phba: Pointer to HBA context object.
15138 * This function gets an xritag for the iocb. If there is no unused xritag
15139 * it will return 0xffff.
15140 * The function returns the allocated xritag if successful, else returns zero.
15141 * Zero is not a valid xritag.
15142 * The caller is not required to hold any lock.
15145 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
15147 uint16_t xri_index;
15149 xri_index = lpfc_sli4_alloc_xri(phba);
15150 if (xri_index == NO_XRI)
15151 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15152 "2004 Failed to allocate XRI.last XRITAG is %d"
15153 " Max XRI is %d, Used XRI is %d\n",
15155 phba->sli4_hba.max_cfg_param.max_xri,
15156 phba->sli4_hba.max_cfg_param.xri_used);
15161 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
15162 * @phba: pointer to lpfc hba data structure.
15163 * @post_sgl_list: pointer to els sgl entry list.
15164 * @count: number of els sgl entries on the list.
15166 * This routine is invoked to post a block of driver's sgl pages to the
15167 * HBA using non-embedded mailbox command. No Lock is held. This routine
15168 * is only called when the driver is loading and after all IO has been
15172 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
15173 struct list_head *post_sgl_list,
15176 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
15177 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
15178 struct sgl_page_pairs *sgl_pg_pairs;
15180 LPFC_MBOXQ_t *mbox;
15181 uint32_t reqlen, alloclen, pg_pairs;
15183 uint16_t xritag_start = 0;
15185 uint32_t shdr_status, shdr_add_status;
15186 union lpfc_sli4_cfg_shdr *shdr;
15188 reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
15189 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
15190 if (reqlen > SLI4_PAGE_SIZE) {
15191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15192 "2559 Block sgl registration required DMA "
15193 "size (%d) great than a page\n", reqlen);
15197 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15201 /* Allocate DMA memory and set up the non-embedded mailbox command */
15202 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15203 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
15204 LPFC_SLI4_MBX_NEMBED);
15206 if (alloclen < reqlen) {
15207 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15208 "0285 Allocated DMA memory size (%d) is "
15209 "less than the requested DMA memory "
15210 "size (%d)\n", alloclen, reqlen);
15211 lpfc_sli4_mbox_cmd_free(phba, mbox);
15214 /* Set up the SGL pages in the non-embedded DMA pages */
15215 viraddr = mbox->sge_array->addr[0];
15216 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
15217 sgl_pg_pairs = &sgl->sgl_pg_pairs;
15220 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
15221 /* Set up the sge entry */
15222 sgl_pg_pairs->sgl_pg0_addr_lo =
15223 cpu_to_le32(putPaddrLow(sglq_entry->phys));
15224 sgl_pg_pairs->sgl_pg0_addr_hi =
15225 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
15226 sgl_pg_pairs->sgl_pg1_addr_lo =
15227 cpu_to_le32(putPaddrLow(0));
15228 sgl_pg_pairs->sgl_pg1_addr_hi =
15229 cpu_to_le32(putPaddrHigh(0));
15231 /* Keep the first xritag on the list */
15233 xritag_start = sglq_entry->sli4_xritag;
15238 /* Complete initialization and perform endian conversion. */
15239 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
15240 bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
15241 sgl->word0 = cpu_to_le32(sgl->word0);
15243 if (!phba->sli4_hba.intr_enable)
15244 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15246 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
15247 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
15249 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
15250 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15251 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15252 if (rc != MBX_TIMEOUT)
15253 lpfc_sli4_mbox_cmd_free(phba, mbox);
15254 if (shdr_status || shdr_add_status || rc) {
15255 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15256 "2513 POST_SGL_BLOCK mailbox command failed "
15257 "status x%x add_status x%x mbx status x%x\n",
15258 shdr_status, shdr_add_status, rc);
15265 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
15266 * @phba: pointer to lpfc hba data structure.
15267 * @sblist: pointer to scsi buffer list.
15268 * @count: number of scsi buffers on the list.
15270 * This routine is invoked to post a block of @count scsi sgl pages from a
15271 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
15276 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba,
15277 struct list_head *sblist,
15280 struct lpfc_scsi_buf *psb;
15281 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
15282 struct sgl_page_pairs *sgl_pg_pairs;
15284 LPFC_MBOXQ_t *mbox;
15285 uint32_t reqlen, alloclen, pg_pairs;
15287 uint16_t xritag_start = 0;
15289 uint32_t shdr_status, shdr_add_status;
15290 dma_addr_t pdma_phys_bpl1;
15291 union lpfc_sli4_cfg_shdr *shdr;
15293 /* Calculate the requested length of the dma memory */
15294 reqlen = count * sizeof(struct sgl_page_pairs) +
15295 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
15296 if (reqlen > SLI4_PAGE_SIZE) {
15297 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
15298 "0217 Block sgl registration required DMA "
15299 "size (%d) great than a page\n", reqlen);
15302 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15305 "0283 Failed to allocate mbox cmd memory\n");
15309 /* Allocate DMA memory and set up the non-embedded mailbox command */
15310 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15311 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
15312 LPFC_SLI4_MBX_NEMBED);
15314 if (alloclen < reqlen) {
15315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15316 "2561 Allocated DMA memory size (%d) is "
15317 "less than the requested DMA memory "
15318 "size (%d)\n", alloclen, reqlen);
15319 lpfc_sli4_mbox_cmd_free(phba, mbox);
15323 /* Get the first SGE entry from the non-embedded DMA memory */
15324 viraddr = mbox->sge_array->addr[0];
15326 /* Set up the SGL pages in the non-embedded DMA pages */
15327 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
15328 sgl_pg_pairs = &sgl->sgl_pg_pairs;
15331 list_for_each_entry(psb, sblist, list) {
15332 /* Set up the sge entry */
15333 sgl_pg_pairs->sgl_pg0_addr_lo =
15334 cpu_to_le32(putPaddrLow(psb->dma_phys_bpl));
15335 sgl_pg_pairs->sgl_pg0_addr_hi =
15336 cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl));
15337 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
15338 pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE;
15340 pdma_phys_bpl1 = 0;
15341 sgl_pg_pairs->sgl_pg1_addr_lo =
15342 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
15343 sgl_pg_pairs->sgl_pg1_addr_hi =
15344 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
15345 /* Keep the first xritag on the list */
15347 xritag_start = psb->cur_iocbq.sli4_xritag;
15351 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
15352 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
15353 /* Perform endian conversion if necessary */
15354 sgl->word0 = cpu_to_le32(sgl->word0);
15356 if (!phba->sli4_hba.intr_enable)
15357 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15359 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
15360 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
15362 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
15363 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15364 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15365 if (rc != MBX_TIMEOUT)
15366 lpfc_sli4_mbox_cmd_free(phba, mbox);
15367 if (shdr_status || shdr_add_status || rc) {
15368 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15369 "2564 POST_SGL_BLOCK mailbox command failed "
15370 "status x%x add_status x%x mbx status x%x\n",
15371 shdr_status, shdr_add_status, rc);
15377 static char *lpfc_rctl_names[] = FC_RCTL_NAMES_INIT;
15378 static char *lpfc_type_names[] = FC_TYPE_NAMES_INIT;
15381 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
15382 * @phba: pointer to lpfc_hba struct that the frame was received on
15383 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
15385 * This function checks the fields in the @fc_hdr to see if the FC frame is a
15386 * valid type of frame that the LPFC driver will handle. This function will
15387 * return a zero if the frame is a valid frame or a non zero value when the
15388 * frame does not pass the check.
15391 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
15393 /* make rctl_names static to save stack space */
15394 struct fc_vft_header *fc_vft_hdr;
15395 uint32_t *header = (uint32_t *) fc_hdr;
15397 switch (fc_hdr->fh_r_ctl) {
15398 case FC_RCTL_DD_UNCAT: /* uncategorized information */
15399 case FC_RCTL_DD_SOL_DATA: /* solicited data */
15400 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
15401 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
15402 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
15403 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
15404 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
15405 case FC_RCTL_DD_CMD_STATUS: /* command status */
15406 case FC_RCTL_ELS_REQ: /* extended link services request */
15407 case FC_RCTL_ELS_REP: /* extended link services reply */
15408 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
15409 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
15410 case FC_RCTL_BA_NOP: /* basic link service NOP */
15411 case FC_RCTL_BA_ABTS: /* basic link service abort */
15412 case FC_RCTL_BA_RMC: /* remove connection */
15413 case FC_RCTL_BA_ACC: /* basic accept */
15414 case FC_RCTL_BA_RJT: /* basic reject */
15415 case FC_RCTL_BA_PRMT:
15416 case FC_RCTL_ACK_1: /* acknowledge_1 */
15417 case FC_RCTL_ACK_0: /* acknowledge_0 */
15418 case FC_RCTL_P_RJT: /* port reject */
15419 case FC_RCTL_F_RJT: /* fabric reject */
15420 case FC_RCTL_P_BSY: /* port busy */
15421 case FC_RCTL_F_BSY: /* fabric busy to data frame */
15422 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
15423 case FC_RCTL_LCR: /* link credit reset */
15424 case FC_RCTL_END: /* end */
15426 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
15427 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
15428 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
15429 return lpfc_fc_frame_check(phba, fc_hdr);
15433 switch (fc_hdr->fh_type) {
15446 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
15447 "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
15448 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
15449 lpfc_rctl_names[fc_hdr->fh_r_ctl], fc_hdr->fh_r_ctl,
15450 lpfc_type_names[fc_hdr->fh_type], fc_hdr->fh_type,
15451 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
15452 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
15453 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
15454 be32_to_cpu(header[6]));
15457 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
15458 "2539 Dropped frame rctl:%s type:%s\n",
15459 lpfc_rctl_names[fc_hdr->fh_r_ctl],
15460 lpfc_type_names[fc_hdr->fh_type]);
15465 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
15466 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
15468 * This function processes the FC header to retrieve the VFI from the VF
15469 * header, if one exists. This function will return the VFI if one exists
15470 * or 0 if no VSAN Header exists.
15473 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
15475 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
15477 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
15479 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
15483 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
15484 * @phba: Pointer to the HBA structure to search for the vport on
15485 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
15486 * @fcfi: The FC Fabric ID that the frame came from
15488 * This function searches the @phba for a vport that matches the content of the
15489 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
15490 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
15491 * returns the matching vport pointer or NULL if unable to match frame to a
15494 static struct lpfc_vport *
15495 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
15496 uint16_t fcfi, uint32_t did)
15498 struct lpfc_vport **vports;
15499 struct lpfc_vport *vport = NULL;
15502 if (did == Fabric_DID)
15503 return phba->pport;
15504 if ((phba->pport->fc_flag & FC_PT2PT) &&
15505 !(phba->link_state == LPFC_HBA_READY))
15506 return phba->pport;
15508 vports = lpfc_create_vport_work_array(phba);
15509 if (vports != NULL) {
15510 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
15511 if (phba->fcf.fcfi == fcfi &&
15512 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
15513 vports[i]->fc_myDID == did) {
15519 lpfc_destroy_vport_work_array(phba, vports);
15524 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
15525 * @vport: The vport to work on.
15527 * This function updates the receive sequence time stamp for this vport. The
15528 * receive sequence time stamp indicates the time that the last frame of the
15529 * the sequence that has been idle for the longest amount of time was received.
15530 * the driver uses this time stamp to indicate if any received sequences have
15534 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
15536 struct lpfc_dmabuf *h_buf;
15537 struct hbq_dmabuf *dmabuf = NULL;
15539 /* get the oldest sequence on the rcv list */
15540 h_buf = list_get_first(&vport->rcv_buffer_list,
15541 struct lpfc_dmabuf, list);
15544 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
15545 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
15549 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
15550 * @vport: The vport that the received sequences were sent to.
15552 * This function cleans up all outstanding received sequences. This is called
15553 * by the driver when a link event or user action invalidates all the received
15557 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
15559 struct lpfc_dmabuf *h_buf, *hnext;
15560 struct lpfc_dmabuf *d_buf, *dnext;
15561 struct hbq_dmabuf *dmabuf = NULL;
15563 /* start with the oldest sequence on the rcv list */
15564 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
15565 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
15566 list_del_init(&dmabuf->hbuf.list);
15567 list_for_each_entry_safe(d_buf, dnext,
15568 &dmabuf->dbuf.list, list) {
15569 list_del_init(&d_buf->list);
15570 lpfc_in_buf_free(vport->phba, d_buf);
15572 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
15577 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
15578 * @vport: The vport that the received sequences were sent to.
15580 * This function determines whether any received sequences have timed out by
15581 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
15582 * indicates that there is at least one timed out sequence this routine will
15583 * go through the received sequences one at a time from most inactive to most
15584 * active to determine which ones need to be cleaned up. Once it has determined
15585 * that a sequence needs to be cleaned up it will simply free up the resources
15586 * without sending an abort.
15589 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
15591 struct lpfc_dmabuf *h_buf, *hnext;
15592 struct lpfc_dmabuf *d_buf, *dnext;
15593 struct hbq_dmabuf *dmabuf = NULL;
15594 unsigned long timeout;
15595 int abort_count = 0;
15597 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
15598 vport->rcv_buffer_time_stamp);
15599 if (list_empty(&vport->rcv_buffer_list) ||
15600 time_before(jiffies, timeout))
15602 /* start with the oldest sequence on the rcv list */
15603 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
15604 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
15605 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
15606 dmabuf->time_stamp);
15607 if (time_before(jiffies, timeout))
15610 list_del_init(&dmabuf->hbuf.list);
15611 list_for_each_entry_safe(d_buf, dnext,
15612 &dmabuf->dbuf.list, list) {
15613 list_del_init(&d_buf->list);
15614 lpfc_in_buf_free(vport->phba, d_buf);
15616 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
15619 lpfc_update_rcv_time_stamp(vport);
15623 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
15624 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
15626 * This function searches through the existing incomplete sequences that have
15627 * been sent to this @vport. If the frame matches one of the incomplete
15628 * sequences then the dbuf in the @dmabuf is added to the list of frames that
15629 * make up that sequence. If no sequence is found that matches this frame then
15630 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
15631 * This function returns a pointer to the first dmabuf in the sequence list that
15632 * the frame was linked to.
15634 static struct hbq_dmabuf *
15635 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
15637 struct fc_frame_header *new_hdr;
15638 struct fc_frame_header *temp_hdr;
15639 struct lpfc_dmabuf *d_buf;
15640 struct lpfc_dmabuf *h_buf;
15641 struct hbq_dmabuf *seq_dmabuf = NULL;
15642 struct hbq_dmabuf *temp_dmabuf = NULL;
15645 INIT_LIST_HEAD(&dmabuf->dbuf.list);
15646 dmabuf->time_stamp = jiffies;
15647 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
15649 /* Use the hdr_buf to find the sequence that this frame belongs to */
15650 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
15651 temp_hdr = (struct fc_frame_header *)h_buf->virt;
15652 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
15653 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
15654 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
15656 /* found a pending sequence that matches this frame */
15657 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
15662 * This indicates first frame received for this sequence.
15663 * Queue the buffer on the vport's rcv_buffer_list.
15665 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
15666 lpfc_update_rcv_time_stamp(vport);
15669 temp_hdr = seq_dmabuf->hbuf.virt;
15670 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
15671 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
15672 list_del_init(&seq_dmabuf->hbuf.list);
15673 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
15674 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
15675 lpfc_update_rcv_time_stamp(vport);
15678 /* move this sequence to the tail to indicate a young sequence */
15679 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
15680 seq_dmabuf->time_stamp = jiffies;
15681 lpfc_update_rcv_time_stamp(vport);
15682 if (list_empty(&seq_dmabuf->dbuf.list)) {
15683 temp_hdr = dmabuf->hbuf.virt;
15684 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
15687 /* find the correct place in the sequence to insert this frame */
15688 d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
15690 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
15691 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
15693 * If the frame's sequence count is greater than the frame on
15694 * the list then insert the frame right after this frame
15696 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
15697 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
15698 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
15703 if (&d_buf->list == &seq_dmabuf->dbuf.list)
15705 d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
15714 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
15715 * @vport: pointer to a vitural port
15716 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15718 * This function tries to abort from the partially assembed sequence, described
15719 * by the information from basic abbort @dmabuf. It checks to see whether such
15720 * partially assembled sequence held by the driver. If so, it shall free up all
15721 * the frames from the partially assembled sequence.
15724 * true -- if there is matching partially assembled sequence present and all
15725 * the frames freed with the sequence;
15726 * false -- if there is no matching partially assembled sequence present so
15727 * nothing got aborted in the lower layer driver
15730 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
15731 struct hbq_dmabuf *dmabuf)
15733 struct fc_frame_header *new_hdr;
15734 struct fc_frame_header *temp_hdr;
15735 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
15736 struct hbq_dmabuf *seq_dmabuf = NULL;
15738 /* Use the hdr_buf to find the sequence that matches this frame */
15739 INIT_LIST_HEAD(&dmabuf->dbuf.list);
15740 INIT_LIST_HEAD(&dmabuf->hbuf.list);
15741 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
15742 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
15743 temp_hdr = (struct fc_frame_header *)h_buf->virt;
15744 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
15745 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
15746 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
15748 /* found a pending sequence that matches this frame */
15749 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
15753 /* Free up all the frames from the partially assembled sequence */
15755 list_for_each_entry_safe(d_buf, n_buf,
15756 &seq_dmabuf->dbuf.list, list) {
15757 list_del_init(&d_buf->list);
15758 lpfc_in_buf_free(vport->phba, d_buf);
15766 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
15767 * @vport: pointer to a vitural port
15768 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15770 * This function tries to abort from the assembed sequence from upper level
15771 * protocol, described by the information from basic abbort @dmabuf. It
15772 * checks to see whether such pending context exists at upper level protocol.
15773 * If so, it shall clean up the pending context.
15776 * true -- if there is matching pending context of the sequence cleaned
15778 * false -- if there is no matching pending context of the sequence present
15782 lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
15784 struct lpfc_hba *phba = vport->phba;
15787 /* Accepting abort at ulp with SLI4 only */
15788 if (phba->sli_rev < LPFC_SLI_REV4)
15791 /* Register all caring upper level protocols to attend abort */
15792 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
15800 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
15801 * @phba: Pointer to HBA context object.
15802 * @cmd_iocbq: pointer to the command iocbq structure.
15803 * @rsp_iocbq: pointer to the response iocbq structure.
15805 * This function handles the sequence abort response iocb command complete
15806 * event. It properly releases the memory allocated to the sequence abort
15810 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
15811 struct lpfc_iocbq *cmd_iocbq,
15812 struct lpfc_iocbq *rsp_iocbq)
15814 struct lpfc_nodelist *ndlp;
15817 ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
15818 lpfc_nlp_put(ndlp);
15819 lpfc_nlp_not_used(ndlp);
15820 lpfc_sli_release_iocbq(phba, cmd_iocbq);
15823 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
15824 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
15825 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15826 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
15827 rsp_iocbq->iocb.ulpStatus,
15828 rsp_iocbq->iocb.un.ulpWord[4]);
15832 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
15833 * @phba: Pointer to HBA context object.
15834 * @xri: xri id in transaction.
15836 * This function validates the xri maps to the known range of XRIs allocated an
15837 * used by the driver.
15840 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
15845 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
15846 if (xri == phba->sli4_hba.xri_ids[i])
15853 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
15854 * @phba: Pointer to HBA context object.
15855 * @fc_hdr: pointer to a FC frame header.
15857 * This function sends a basic response to a previous unsol sequence abort
15858 * event after aborting the sequence handling.
15861 lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
15862 struct fc_frame_header *fc_hdr, bool aborted)
15864 struct lpfc_hba *phba = vport->phba;
15865 struct lpfc_iocbq *ctiocb = NULL;
15866 struct lpfc_nodelist *ndlp;
15867 uint16_t oxid, rxid, xri, lxri;
15868 uint32_t sid, fctl;
15872 if (!lpfc_is_link_up(phba))
15875 sid = sli4_sid_from_fc_hdr(fc_hdr);
15876 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
15877 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
15879 ndlp = lpfc_findnode_did(vport, sid);
15881 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
15883 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
15884 "1268 Failed to allocate ndlp for "
15885 "oxid:x%x SID:x%x\n", oxid, sid);
15888 lpfc_nlp_init(vport, ndlp, sid);
15889 /* Put ndlp onto pport node list */
15890 lpfc_enqueue_node(vport, ndlp);
15891 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
15892 /* re-setup ndlp without removing from node list */
15893 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
15895 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
15896 "3275 Failed to active ndlp found "
15897 "for oxid:x%x SID:x%x\n", oxid, sid);
15902 /* Allocate buffer for rsp iocb */
15903 ctiocb = lpfc_sli_get_iocbq(phba);
15907 /* Extract the F_CTL field from FC_HDR */
15908 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
15910 icmd = &ctiocb->iocb;
15911 icmd->un.xseq64.bdl.bdeSize = 0;
15912 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
15913 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
15914 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
15915 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
15917 /* Fill in the rest of iocb fields */
15918 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
15919 icmd->ulpBdeCount = 0;
15921 icmd->ulpClass = CLASS3;
15922 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
15923 ctiocb->context1 = lpfc_nlp_get(ndlp);
15925 ctiocb->iocb_cmpl = NULL;
15926 ctiocb->vport = phba->pport;
15927 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
15928 ctiocb->sli4_lxritag = NO_XRI;
15929 ctiocb->sli4_xritag = NO_XRI;
15931 if (fctl & FC_FC_EX_CTX)
15932 /* Exchange responder sent the abort so we
15938 lxri = lpfc_sli4_xri_inrange(phba, xri);
15939 if (lxri != NO_XRI)
15940 lpfc_set_rrq_active(phba, ndlp, lxri,
15941 (xri == oxid) ? rxid : oxid, 0);
15942 /* For BA_ABTS from exchange responder, if the logical xri with
15943 * the oxid maps to the FCP XRI range, the port no longer has
15944 * that exchange context, send a BLS_RJT. Override the IOCB for
15947 if ((fctl & FC_FC_EX_CTX) &&
15948 (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
15949 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
15950 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
15951 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
15952 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
15955 /* If BA_ABTS failed to abort a partially assembled receive sequence,
15956 * the driver no longer has that exchange, send a BLS_RJT. Override
15957 * the IOCB for a BA_RJT.
15959 if (aborted == false) {
15960 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
15961 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
15962 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
15963 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
15966 if (fctl & FC_FC_EX_CTX) {
15967 /* ABTS sent by responder to CT exchange, construction
15968 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
15969 * field and RX_ID from ABTS for RX_ID field.
15971 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
15973 /* ABTS sent by initiator to CT exchange, construction
15974 * of BA_ACC will need to allocate a new XRI as for the
15977 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
15979 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
15980 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
15982 /* Xmit CT abts response on exchange <xid> */
15983 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
15984 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
15985 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
15987 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
15988 if (rc == IOCB_ERROR) {
15989 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
15990 "2925 Failed to issue CT ABTS RSP x%x on "
15991 "xri x%x, Data x%x\n",
15992 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
15994 lpfc_nlp_put(ndlp);
15995 ctiocb->context1 = NULL;
15996 lpfc_sli_release_iocbq(phba, ctiocb);
16001 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
16002 * @vport: Pointer to the vport on which this sequence was received
16003 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16005 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
16006 * receive sequence is only partially assembed by the driver, it shall abort
16007 * the partially assembled frames for the sequence. Otherwise, if the
16008 * unsolicited receive sequence has been completely assembled and passed to
16009 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
16010 * unsolicited sequence has been aborted. After that, it will issue a basic
16011 * accept to accept the abort.
16014 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
16015 struct hbq_dmabuf *dmabuf)
16017 struct lpfc_hba *phba = vport->phba;
16018 struct fc_frame_header fc_hdr;
16022 /* Make a copy of fc_hdr before the dmabuf being released */
16023 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
16024 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
16026 if (fctl & FC_FC_EX_CTX) {
16027 /* ABTS by responder to exchange, no cleanup needed */
16030 /* ABTS by initiator to exchange, need to do cleanup */
16031 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
16032 if (aborted == false)
16033 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
16035 lpfc_in_buf_free(phba, &dmabuf->dbuf);
16037 /* Respond with BA_ACC or BA_RJT accordingly */
16038 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
16042 * lpfc_seq_complete - Indicates if a sequence is complete
16043 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16045 * This function checks the sequence, starting with the frame described by
16046 * @dmabuf, to see if all the frames associated with this sequence are present.
16047 * the frames associated with this sequence are linked to the @dmabuf using the
16048 * dbuf list. This function looks for two major things. 1) That the first frame
16049 * has a sequence count of zero. 2) There is a frame with last frame of sequence
16050 * set. 3) That there are no holes in the sequence count. The function will
16051 * return 1 when the sequence is complete, otherwise it will return 0.
16054 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
16056 struct fc_frame_header *hdr;
16057 struct lpfc_dmabuf *d_buf;
16058 struct hbq_dmabuf *seq_dmabuf;
16062 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
16063 /* make sure first fame of sequence has a sequence count of zero */
16064 if (hdr->fh_seq_cnt != seq_count)
16066 fctl = (hdr->fh_f_ctl[0] << 16 |
16067 hdr->fh_f_ctl[1] << 8 |
16069 /* If last frame of sequence we can return success. */
16070 if (fctl & FC_FC_END_SEQ)
16072 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
16073 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
16074 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
16075 /* If there is a hole in the sequence count then fail. */
16076 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
16078 fctl = (hdr->fh_f_ctl[0] << 16 |
16079 hdr->fh_f_ctl[1] << 8 |
16081 /* If last frame of sequence we can return success. */
16082 if (fctl & FC_FC_END_SEQ)
16089 * lpfc_prep_seq - Prep sequence for ULP processing
16090 * @vport: Pointer to the vport on which this sequence was received
16091 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16093 * This function takes a sequence, described by a list of frames, and creates
16094 * a list of iocbq structures to describe the sequence. This iocbq list will be
16095 * used to issue to the generic unsolicited sequence handler. This routine
16096 * returns a pointer to the first iocbq in the list. If the function is unable
16097 * to allocate an iocbq then it throw out the received frames that were not
16098 * able to be described and return a pointer to the first iocbq. If unable to
16099 * allocate any iocbqs (including the first) this function will return NULL.
16101 static struct lpfc_iocbq *
16102 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
16104 struct hbq_dmabuf *hbq_buf;
16105 struct lpfc_dmabuf *d_buf, *n_buf;
16106 struct lpfc_iocbq *first_iocbq, *iocbq;
16107 struct fc_frame_header *fc_hdr;
16109 uint32_t len, tot_len;
16110 struct ulp_bde64 *pbde;
16112 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
16113 /* remove from receive buffer list */
16114 list_del_init(&seq_dmabuf->hbuf.list);
16115 lpfc_update_rcv_time_stamp(vport);
16116 /* get the Remote Port's SID */
16117 sid = sli4_sid_from_fc_hdr(fc_hdr);
16119 /* Get an iocbq struct to fill in. */
16120 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
16122 /* Initialize the first IOCB. */
16123 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
16124 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
16125 first_iocbq->vport = vport;
16127 /* Check FC Header to see what TYPE of frame we are rcv'ing */
16128 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
16129 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
16130 first_iocbq->iocb.un.rcvels.parmRo =
16131 sli4_did_from_fc_hdr(fc_hdr);
16132 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
16134 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
16135 first_iocbq->iocb.ulpContext = NO_XRI;
16136 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
16137 be16_to_cpu(fc_hdr->fh_ox_id);
16138 /* iocbq is prepped for internal consumption. Physical vpi. */
16139 first_iocbq->iocb.unsli3.rcvsli3.vpi =
16140 vport->phba->vpi_ids[vport->vpi];
16141 /* put the first buffer into the first IOCBq */
16142 tot_len = bf_get(lpfc_rcqe_length,
16143 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
16145 first_iocbq->context2 = &seq_dmabuf->dbuf;
16146 first_iocbq->context3 = NULL;
16147 first_iocbq->iocb.ulpBdeCount = 1;
16148 if (tot_len > LPFC_DATA_BUF_SIZE)
16149 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
16150 LPFC_DATA_BUF_SIZE;
16152 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
16154 first_iocbq->iocb.un.rcvels.remoteID = sid;
16156 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
16158 iocbq = first_iocbq;
16160 * Each IOCBq can have two Buffers assigned, so go through the list
16161 * of buffers for this sequence and save two buffers in each IOCBq
16163 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
16165 lpfc_in_buf_free(vport->phba, d_buf);
16168 if (!iocbq->context3) {
16169 iocbq->context3 = d_buf;
16170 iocbq->iocb.ulpBdeCount++;
16171 /* We need to get the size out of the right CQE */
16172 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
16173 len = bf_get(lpfc_rcqe_length,
16174 &hbq_buf->cq_event.cqe.rcqe_cmpl);
16175 pbde = (struct ulp_bde64 *)
16176 &iocbq->iocb.unsli3.sli3Words[4];
16177 if (len > LPFC_DATA_BUF_SIZE)
16178 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
16180 pbde->tus.f.bdeSize = len;
16182 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
16185 iocbq = lpfc_sli_get_iocbq(vport->phba);
16188 first_iocbq->iocb.ulpStatus =
16189 IOSTAT_FCP_RSP_ERROR;
16190 first_iocbq->iocb.un.ulpWord[4] =
16191 IOERR_NO_RESOURCES;
16193 lpfc_in_buf_free(vport->phba, d_buf);
16196 /* We need to get the size out of the right CQE */
16197 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
16198 len = bf_get(lpfc_rcqe_length,
16199 &hbq_buf->cq_event.cqe.rcqe_cmpl);
16200 iocbq->context2 = d_buf;
16201 iocbq->context3 = NULL;
16202 iocbq->iocb.ulpBdeCount = 1;
16203 if (len > LPFC_DATA_BUF_SIZE)
16204 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
16205 LPFC_DATA_BUF_SIZE;
16207 iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
16210 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
16212 iocbq->iocb.un.rcvels.remoteID = sid;
16213 list_add_tail(&iocbq->list, &first_iocbq->list);
16216 return first_iocbq;
16220 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
16221 struct hbq_dmabuf *seq_dmabuf)
16223 struct fc_frame_header *fc_hdr;
16224 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
16225 struct lpfc_hba *phba = vport->phba;
16227 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
16228 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
16230 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16231 "2707 Ring %d handler: Failed to allocate "
16232 "iocb Rctl x%x Type x%x received\n",
16234 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
16237 if (!lpfc_complete_unsol_iocb(phba,
16238 phba->sli4_hba.els_wq->pring,
16239 iocbq, fc_hdr->fh_r_ctl,
16241 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16242 "2540 Ring %d handler: unexpected Rctl "
16243 "x%x Type x%x received\n",
16245 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
16247 /* Free iocb created in lpfc_prep_seq */
16248 list_for_each_entry_safe(curr_iocb, next_iocb,
16249 &iocbq->list, list) {
16250 list_del_init(&curr_iocb->list);
16251 lpfc_sli_release_iocbq(phba, curr_iocb);
16253 lpfc_sli_release_iocbq(phba, iocbq);
16257 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
16258 * @phba: Pointer to HBA context object.
16260 * This function is called with no lock held. This function processes all
16261 * the received buffers and gives it to upper layers when a received buffer
16262 * indicates that it is the final frame in the sequence. The interrupt
16263 * service routine processes received buffers at interrupt contexts.
16264 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
16265 * appropriate receive function when the final frame in a sequence is received.
16268 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
16269 struct hbq_dmabuf *dmabuf)
16271 struct hbq_dmabuf *seq_dmabuf;
16272 struct fc_frame_header *fc_hdr;
16273 struct lpfc_vport *vport;
16277 /* Process each received buffer */
16278 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
16280 /* check to see if this a valid type of frame */
16281 if (lpfc_fc_frame_check(phba, fc_hdr)) {
16282 lpfc_in_buf_free(phba, &dmabuf->dbuf);
16286 if ((bf_get(lpfc_cqe_code,
16287 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
16288 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
16289 &dmabuf->cq_event.cqe.rcqe_cmpl);
16291 fcfi = bf_get(lpfc_rcqe_fcf_id,
16292 &dmabuf->cq_event.cqe.rcqe_cmpl);
16294 /* d_id this frame is directed to */
16295 did = sli4_did_from_fc_hdr(fc_hdr);
16297 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
16299 /* throw out the frame */
16300 lpfc_in_buf_free(phba, &dmabuf->dbuf);
16304 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
16305 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
16306 (did != Fabric_DID)) {
16308 * Throw out the frame if we are not pt2pt.
16309 * The pt2pt protocol allows for discovery frames
16310 * to be received without a registered VPI.
16312 if (!(vport->fc_flag & FC_PT2PT) ||
16313 (phba->link_state == LPFC_HBA_READY)) {
16314 lpfc_in_buf_free(phba, &dmabuf->dbuf);
16319 /* Handle the basic abort sequence (BA_ABTS) event */
16320 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
16321 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
16325 /* Link this frame */
16326 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
16328 /* unable to add frame to vport - throw it out */
16329 lpfc_in_buf_free(phba, &dmabuf->dbuf);
16332 /* If not last frame in sequence continue processing frames. */
16333 if (!lpfc_seq_complete(seq_dmabuf))
16336 /* Send the complete sequence to the upper layer protocol */
16337 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
16341 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
16342 * @phba: pointer to lpfc hba data structure.
16344 * This routine is invoked to post rpi header templates to the
16345 * HBA consistent with the SLI-4 interface spec. This routine
16346 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
16347 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
16349 * This routine does not require any locks. It's usage is expected
16350 * to be driver load or reset recovery when the driver is
16355 * -EIO - The mailbox failed to complete successfully.
16356 * When this error occurs, the driver is not guaranteed
16357 * to have any rpi regions posted to the device and
16358 * must either attempt to repost the regions or take a
16362 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
16364 struct lpfc_rpi_hdr *rpi_page;
16368 /* SLI4 ports that support extents do not require RPI headers. */
16369 if (!phba->sli4_hba.rpi_hdrs_in_use)
16371 if (phba->sli4_hba.extents_in_use)
16374 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
16376 * Assign the rpi headers a physical rpi only if the driver
16377 * has not initialized those resources. A port reset only
16378 * needs the headers posted.
16380 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
16382 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
16384 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
16385 if (rc != MBX_SUCCESS) {
16386 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16387 "2008 Error %d posting all rpi "
16395 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
16396 LPFC_RPI_RSRC_RDY);
16401 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
16402 * @phba: pointer to lpfc hba data structure.
16403 * @rpi_page: pointer to the rpi memory region.
16405 * This routine is invoked to post a single rpi header to the
16406 * HBA consistent with the SLI-4 interface spec. This memory region
16407 * maps up to 64 rpi context regions.
16411 * -ENOMEM - No available memory
16412 * -EIO - The mailbox failed to complete successfully.
16415 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
16417 LPFC_MBOXQ_t *mboxq;
16418 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
16420 uint32_t shdr_status, shdr_add_status;
16421 union lpfc_sli4_cfg_shdr *shdr;
16423 /* SLI4 ports that support extents do not require RPI headers. */
16424 if (!phba->sli4_hba.rpi_hdrs_in_use)
16426 if (phba->sli4_hba.extents_in_use)
16429 /* The port is notified of the header region via a mailbox command. */
16430 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16432 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16433 "2001 Unable to allocate memory for issuing "
16434 "SLI_CONFIG_SPECIAL mailbox command\n");
16438 /* Post all rpi memory regions to the port. */
16439 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
16440 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
16441 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
16442 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
16443 sizeof(struct lpfc_sli4_cfg_mhdr),
16444 LPFC_SLI4_MBX_EMBED);
16447 /* Post the physical rpi to the port for this rpi header. */
16448 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
16449 rpi_page->start_rpi);
16450 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
16451 hdr_tmpl, rpi_page->page_count);
16453 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
16454 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
16455 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
16456 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
16457 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16458 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16459 if (rc != MBX_TIMEOUT)
16460 mempool_free(mboxq, phba->mbox_mem_pool);
16461 if (shdr_status || shdr_add_status || rc) {
16462 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16463 "2514 POST_RPI_HDR mailbox failed with "
16464 "status x%x add_status x%x, mbx status x%x\n",
16465 shdr_status, shdr_add_status, rc);
16472 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
16473 * @phba: pointer to lpfc hba data structure.
16475 * This routine is invoked to post rpi header templates to the
16476 * HBA consistent with the SLI-4 interface spec. This routine
16477 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
16478 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
16481 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
16482 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
16485 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
16488 uint16_t max_rpi, rpi_limit;
16489 uint16_t rpi_remaining, lrpi = 0;
16490 struct lpfc_rpi_hdr *rpi_hdr;
16491 unsigned long iflag;
16494 * Fetch the next logical rpi. Because this index is logical,
16495 * the driver starts at 0 each time.
16497 spin_lock_irqsave(&phba->hbalock, iflag);
16498 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
16499 rpi_limit = phba->sli4_hba.next_rpi;
16501 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
16502 if (rpi >= rpi_limit)
16503 rpi = LPFC_RPI_ALLOC_ERROR;
16505 set_bit(rpi, phba->sli4_hba.rpi_bmask);
16506 phba->sli4_hba.max_cfg_param.rpi_used++;
16507 phba->sli4_hba.rpi_count++;
16509 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
16510 "0001 rpi:%x max:%x lim:%x\n",
16511 (int) rpi, max_rpi, rpi_limit);
16514 * Don't try to allocate more rpi header regions if the device limit
16515 * has been exhausted.
16517 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
16518 (phba->sli4_hba.rpi_count >= max_rpi)) {
16519 spin_unlock_irqrestore(&phba->hbalock, iflag);
16524 * RPI header postings are not required for SLI4 ports capable of
16527 if (!phba->sli4_hba.rpi_hdrs_in_use) {
16528 spin_unlock_irqrestore(&phba->hbalock, iflag);
16533 * If the driver is running low on rpi resources, allocate another
16534 * page now. Note that the next_rpi value is used because
16535 * it represents how many are actually in use whereas max_rpi notes
16536 * how many are supported max by the device.
16538 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
16539 spin_unlock_irqrestore(&phba->hbalock, iflag);
16540 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
16541 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
16543 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16544 "2002 Error Could not grow rpi "
16547 lrpi = rpi_hdr->start_rpi;
16548 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
16549 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
16557 * lpfc_sli4_free_rpi - Release an rpi for reuse.
16558 * @phba: pointer to lpfc hba data structure.
16560 * This routine is invoked to release an rpi to the pool of
16561 * available rpis maintained by the driver.
16564 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
16566 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
16567 phba->sli4_hba.rpi_count--;
16568 phba->sli4_hba.max_cfg_param.rpi_used--;
16573 * lpfc_sli4_free_rpi - Release an rpi for reuse.
16574 * @phba: pointer to lpfc hba data structure.
16576 * This routine is invoked to release an rpi to the pool of
16577 * available rpis maintained by the driver.
16580 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
16582 spin_lock_irq(&phba->hbalock);
16583 __lpfc_sli4_free_rpi(phba, rpi);
16584 spin_unlock_irq(&phba->hbalock);
16588 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
16589 * @phba: pointer to lpfc hba data structure.
16591 * This routine is invoked to remove the memory region that
16592 * provided rpi via a bitmask.
16595 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
16597 kfree(phba->sli4_hba.rpi_bmask);
16598 kfree(phba->sli4_hba.rpi_ids);
16599 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
16603 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
16604 * @phba: pointer to lpfc hba data structure.
16606 * This routine is invoked to remove the memory region that
16607 * provided rpi via a bitmask.
16610 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
16611 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
16613 LPFC_MBOXQ_t *mboxq;
16614 struct lpfc_hba *phba = ndlp->phba;
16617 /* The port is notified of the header region via a mailbox command. */
16618 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16622 /* Post all rpi memory regions to the port. */
16623 lpfc_resume_rpi(mboxq, ndlp);
16625 mboxq->mbox_cmpl = cmpl;
16626 mboxq->context1 = arg;
16627 mboxq->context2 = ndlp;
16629 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16630 mboxq->vport = ndlp->vport;
16631 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16632 if (rc == MBX_NOT_FINISHED) {
16633 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16634 "2010 Resume RPI Mailbox failed "
16635 "status %d, mbxStatus x%x\n", rc,
16636 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
16637 mempool_free(mboxq, phba->mbox_mem_pool);
16644 * lpfc_sli4_init_vpi - Initialize a vpi with the port
16645 * @vport: Pointer to the vport for which the vpi is being initialized
16647 * This routine is invoked to activate a vpi with the port.
16651 * -Evalue otherwise
16654 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
16656 LPFC_MBOXQ_t *mboxq;
16658 int retval = MBX_SUCCESS;
16660 struct lpfc_hba *phba = vport->phba;
16661 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16664 lpfc_init_vpi(phba, mboxq, vport->vpi);
16665 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
16666 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
16667 if (rc != MBX_SUCCESS) {
16668 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
16669 "2022 INIT VPI Mailbox failed "
16670 "status %d, mbxStatus x%x\n", rc,
16671 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
16674 if (rc != MBX_TIMEOUT)
16675 mempool_free(mboxq, vport->phba->mbox_mem_pool);
16681 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
16682 * @phba: pointer to lpfc hba data structure.
16683 * @mboxq: Pointer to mailbox object.
16685 * This routine is invoked to manually add a single FCF record. The caller
16686 * must pass a completely initialized FCF_Record. This routine takes
16687 * care of the nonembedded mailbox operations.
16690 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
16693 union lpfc_sli4_cfg_shdr *shdr;
16694 uint32_t shdr_status, shdr_add_status;
16696 virt_addr = mboxq->sge_array->addr[0];
16697 /* The IOCTL status is embedded in the mailbox subheader. */
16698 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
16699 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16700 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16702 if ((shdr_status || shdr_add_status) &&
16703 (shdr_status != STATUS_FCF_IN_USE))
16704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16705 "2558 ADD_FCF_RECORD mailbox failed with "
16706 "status x%x add_status x%x\n",
16707 shdr_status, shdr_add_status);
16709 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16713 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
16714 * @phba: pointer to lpfc hba data structure.
16715 * @fcf_record: pointer to the initialized fcf record to add.
16717 * This routine is invoked to manually add a single FCF record. The caller
16718 * must pass a completely initialized FCF_Record. This routine takes
16719 * care of the nonembedded mailbox operations.
16722 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
16725 LPFC_MBOXQ_t *mboxq;
16728 struct lpfc_mbx_sge sge;
16729 uint32_t alloc_len, req_len;
16732 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16735 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
16739 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
16742 /* Allocate DMA memory and set up the non-embedded mailbox command */
16743 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
16744 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
16745 req_len, LPFC_SLI4_MBX_NEMBED);
16746 if (alloc_len < req_len) {
16747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16748 "2523 Allocated DMA memory size (x%x) is "
16749 "less than the requested DMA memory "
16750 "size (x%x)\n", alloc_len, req_len);
16751 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16756 * Get the first SGE entry from the non-embedded DMA memory. This
16757 * routine only uses a single SGE.
16759 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
16760 virt_addr = mboxq->sge_array->addr[0];
16762 * Configure the FCF record for FCFI 0. This is the driver's
16763 * hardcoded default and gets used in nonFIP mode.
16765 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
16766 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
16767 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
16770 * Copy the fcf_index and the FCF Record Data. The data starts after
16771 * the FCoE header plus word10. The data copy needs to be endian
16774 bytep += sizeof(uint32_t);
16775 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
16776 mboxq->vport = phba->pport;
16777 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
16778 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16779 if (rc == MBX_NOT_FINISHED) {
16780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16781 "2515 ADD_FCF_RECORD mailbox failed with "
16782 "status 0x%x\n", rc);
16783 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16792 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
16793 * @phba: pointer to lpfc hba data structure.
16794 * @fcf_record: pointer to the fcf record to write the default data.
16795 * @fcf_index: FCF table entry index.
16797 * This routine is invoked to build the driver's default FCF record. The
16798 * values used are hardcoded. This routine handles memory initialization.
16802 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
16803 struct fcf_record *fcf_record,
16804 uint16_t fcf_index)
16806 memset(fcf_record, 0, sizeof(struct fcf_record));
16807 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
16808 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
16809 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
16810 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
16811 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
16812 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
16813 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
16814 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
16815 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
16816 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
16817 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
16818 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
16819 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
16820 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
16821 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
16822 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
16823 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
16824 /* Set the VLAN bit map */
16825 if (phba->valid_vlan) {
16826 fcf_record->vlan_bitmap[phba->vlan_id / 8]
16827 = 1 << (phba->vlan_id % 8);
16832 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
16833 * @phba: pointer to lpfc hba data structure.
16834 * @fcf_index: FCF table entry offset.
16836 * This routine is invoked to scan the entire FCF table by reading FCF
16837 * record and processing it one at a time starting from the @fcf_index
16838 * for initial FCF discovery or fast FCF failover rediscovery.
16840 * Return 0 if the mailbox command is submitted successfully, none 0
16844 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
16847 LPFC_MBOXQ_t *mboxq;
16849 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
16850 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
16851 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16853 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16854 "2000 Failed to allocate mbox for "
16857 goto fail_fcf_scan;
16859 /* Construct the read FCF record mailbox command */
16860 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
16863 goto fail_fcf_scan;
16865 /* Issue the mailbox command asynchronously */
16866 mboxq->vport = phba->pport;
16867 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
16869 spin_lock_irq(&phba->hbalock);
16870 phba->hba_flag |= FCF_TS_INPROG;
16871 spin_unlock_irq(&phba->hbalock);
16873 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16874 if (rc == MBX_NOT_FINISHED)
16877 /* Reset eligible FCF count for new scan */
16878 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
16879 phba->fcf.eligible_fcf_cnt = 0;
16885 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16886 /* FCF scan failed, clear FCF_TS_INPROG flag */
16887 spin_lock_irq(&phba->hbalock);
16888 phba->hba_flag &= ~FCF_TS_INPROG;
16889 spin_unlock_irq(&phba->hbalock);
16895 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
16896 * @phba: pointer to lpfc hba data structure.
16897 * @fcf_index: FCF table entry offset.
16899 * This routine is invoked to read an FCF record indicated by @fcf_index
16900 * and to use it for FLOGI roundrobin FCF failover.
16902 * Return 0 if the mailbox command is submitted successfully, none 0
16906 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
16909 LPFC_MBOXQ_t *mboxq;
16911 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16913 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
16914 "2763 Failed to allocate mbox for "
16917 goto fail_fcf_read;
16919 /* Construct the read FCF record mailbox command */
16920 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
16923 goto fail_fcf_read;
16925 /* Issue the mailbox command asynchronously */
16926 mboxq->vport = phba->pport;
16927 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
16928 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16929 if (rc == MBX_NOT_FINISHED)
16935 if (error && mboxq)
16936 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16941 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
16942 * @phba: pointer to lpfc hba data structure.
16943 * @fcf_index: FCF table entry offset.
16945 * This routine is invoked to read an FCF record indicated by @fcf_index to
16946 * determine whether it's eligible for FLOGI roundrobin failover list.
16948 * Return 0 if the mailbox command is submitted successfully, none 0
16952 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
16955 LPFC_MBOXQ_t *mboxq;
16957 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16959 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
16960 "2758 Failed to allocate mbox for "
16963 goto fail_fcf_read;
16965 /* Construct the read FCF record mailbox command */
16966 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
16969 goto fail_fcf_read;
16971 /* Issue the mailbox command asynchronously */
16972 mboxq->vport = phba->pport;
16973 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
16974 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
16975 if (rc == MBX_NOT_FINISHED)
16981 if (error && mboxq)
16982 lpfc_sli4_mbox_cmd_free(phba, mboxq);
16987 * lpfc_check_next_fcf_pri_level
16988 * phba pointer to the lpfc_hba struct for this port.
16989 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
16990 * routine when the rr_bmask is empty. The FCF indecies are put into the
16991 * rr_bmask based on their priority level. Starting from the highest priority
16992 * to the lowest. The most likely FCF candidate will be in the highest
16993 * priority group. When this routine is called it searches the fcf_pri list for
16994 * next lowest priority group and repopulates the rr_bmask with only those
16997 * 1=success 0=failure
17000 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
17002 uint16_t next_fcf_pri;
17003 uint16_t last_index;
17004 struct lpfc_fcf_pri *fcf_pri;
17008 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
17009 LPFC_SLI4_FCF_TBL_INDX_MAX);
17010 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
17011 "3060 Last IDX %d\n", last_index);
17013 /* Verify the priority list has 2 or more entries */
17014 spin_lock_irq(&phba->hbalock);
17015 if (list_empty(&phba->fcf.fcf_pri_list) ||
17016 list_is_singular(&phba->fcf.fcf_pri_list)) {
17017 spin_unlock_irq(&phba->hbalock);
17018 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
17019 "3061 Last IDX %d\n", last_index);
17020 return 0; /* Empty rr list */
17022 spin_unlock_irq(&phba->hbalock);
17026 * Clear the rr_bmask and set all of the bits that are at this
17029 memset(phba->fcf.fcf_rr_bmask, 0,
17030 sizeof(*phba->fcf.fcf_rr_bmask));
17031 spin_lock_irq(&phba->hbalock);
17032 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
17033 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
17036 * the 1st priority that has not FLOGI failed
17037 * will be the highest.
17040 next_fcf_pri = fcf_pri->fcf_rec.priority;
17041 spin_unlock_irq(&phba->hbalock);
17042 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
17043 rc = lpfc_sli4_fcf_rr_index_set(phba,
17044 fcf_pri->fcf_rec.fcf_index);
17048 spin_lock_irq(&phba->hbalock);
17051 * if next_fcf_pri was not set above and the list is not empty then
17052 * we have failed flogis on all of them. So reset flogi failed
17053 * and start at the beginning.
17055 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
17056 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
17057 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
17059 * the 1st priority that has not FLOGI failed
17060 * will be the highest.
17063 next_fcf_pri = fcf_pri->fcf_rec.priority;
17064 spin_unlock_irq(&phba->hbalock);
17065 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
17066 rc = lpfc_sli4_fcf_rr_index_set(phba,
17067 fcf_pri->fcf_rec.fcf_index);
17071 spin_lock_irq(&phba->hbalock);
17075 spin_unlock_irq(&phba->hbalock);
17080 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
17081 * @phba: pointer to lpfc hba data structure.
17083 * This routine is to get the next eligible FCF record index in a round
17084 * robin fashion. If the next eligible FCF record index equals to the
17085 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
17086 * shall be returned, otherwise, the next eligible FCF record's index
17087 * shall be returned.
17090 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
17092 uint16_t next_fcf_index;
17095 /* Search start from next bit of currently registered FCF index */
17096 next_fcf_index = phba->fcf.current_rec.fcf_indx;
17099 /* Determine the next fcf index to check */
17100 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
17101 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
17102 LPFC_SLI4_FCF_TBL_INDX_MAX,
17105 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
17106 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
17108 * If we have wrapped then we need to clear the bits that
17109 * have been tested so that we can detect when we should
17110 * change the priority level.
17112 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
17113 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
17117 /* Check roundrobin failover list empty condition */
17118 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
17119 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
17121 * If next fcf index is not found check if there are lower
17122 * Priority level fcf's in the fcf_priority list.
17123 * Set up the rr_bmask with all of the avaiable fcf bits
17124 * at that level and continue the selection process.
17126 if (lpfc_check_next_fcf_pri_level(phba))
17127 goto initial_priority;
17128 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
17129 "2844 No roundrobin failover FCF available\n");
17130 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
17131 return LPFC_FCOE_FCF_NEXT_NONE;
17133 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
17134 "3063 Only FCF available idx %d, flag %x\n",
17136 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
17137 return next_fcf_index;
17141 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
17142 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
17143 LPFC_FCF_FLOGI_FAILED) {
17144 if (list_is_singular(&phba->fcf.fcf_pri_list))
17145 return LPFC_FCOE_FCF_NEXT_NONE;
17147 goto next_priority;
17150 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
17151 "2845 Get next roundrobin failover FCF (x%x)\n",
17154 return next_fcf_index;
17158 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
17159 * @phba: pointer to lpfc hba data structure.
17161 * This routine sets the FCF record index in to the eligible bmask for
17162 * roundrobin failover search. It checks to make sure that the index
17163 * does not go beyond the range of the driver allocated bmask dimension
17164 * before setting the bit.
17166 * Returns 0 if the index bit successfully set, otherwise, it returns
17170 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
17172 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
17173 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
17174 "2610 FCF (x%x) reached driver's book "
17175 "keeping dimension:x%x\n",
17176 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
17179 /* Set the eligible FCF record index bmask */
17180 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
17182 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
17183 "2790 Set FCF (x%x) to roundrobin FCF failover "
17184 "bmask\n", fcf_index);
17190 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
17191 * @phba: pointer to lpfc hba data structure.
17193 * This routine clears the FCF record index from the eligible bmask for
17194 * roundrobin failover search. It checks to make sure that the index
17195 * does not go beyond the range of the driver allocated bmask dimension
17196 * before clearing the bit.
17199 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
17201 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
17202 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
17203 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
17204 "2762 FCF (x%x) reached driver's book "
17205 "keeping dimension:x%x\n",
17206 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
17209 /* Clear the eligible FCF record index bmask */
17210 spin_lock_irq(&phba->hbalock);
17211 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
17213 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
17214 list_del_init(&fcf_pri->list);
17218 spin_unlock_irq(&phba->hbalock);
17219 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
17221 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
17222 "2791 Clear FCF (x%x) from roundrobin failover "
17223 "bmask\n", fcf_index);
17227 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
17228 * @phba: pointer to lpfc hba data structure.
17230 * This routine is the completion routine for the rediscover FCF table mailbox
17231 * command. If the mailbox command returned failure, it will try to stop the
17232 * FCF rediscover wait timer.
17235 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
17237 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
17238 uint32_t shdr_status, shdr_add_status;
17240 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
17242 shdr_status = bf_get(lpfc_mbox_hdr_status,
17243 &redisc_fcf->header.cfg_shdr.response);
17244 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
17245 &redisc_fcf->header.cfg_shdr.response);
17246 if (shdr_status || shdr_add_status) {
17247 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
17248 "2746 Requesting for FCF rediscovery failed "
17249 "status x%x add_status x%x\n",
17250 shdr_status, shdr_add_status);
17251 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
17252 spin_lock_irq(&phba->hbalock);
17253 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
17254 spin_unlock_irq(&phba->hbalock);
17256 * CVL event triggered FCF rediscover request failed,
17257 * last resort to re-try current registered FCF entry.
17259 lpfc_retry_pport_discovery(phba);
17261 spin_lock_irq(&phba->hbalock);
17262 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
17263 spin_unlock_irq(&phba->hbalock);
17265 * DEAD FCF event triggered FCF rediscover request
17266 * failed, last resort to fail over as a link down
17267 * to FCF registration.
17269 lpfc_sli4_fcf_dead_failthrough(phba);
17272 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
17273 "2775 Start FCF rediscover quiescent timer\n");
17275 * Start FCF rediscovery wait timer for pending FCF
17276 * before rescan FCF record table.
17278 lpfc_fcf_redisc_wait_start_timer(phba);
17281 mempool_free(mbox, phba->mbox_mem_pool);
17285 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
17286 * @phba: pointer to lpfc hba data structure.
17288 * This routine is invoked to request for rediscovery of the entire FCF table
17292 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
17294 LPFC_MBOXQ_t *mbox;
17295 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
17298 /* Cancel retry delay timers to all vports before FCF rediscover */
17299 lpfc_cancel_all_vport_retry_delay_timer(phba);
17301 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17303 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17304 "2745 Failed to allocate mbox for "
17305 "requesting FCF rediscover.\n");
17309 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
17310 sizeof(struct lpfc_sli4_cfg_mhdr));
17311 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17312 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
17313 length, LPFC_SLI4_MBX_EMBED);
17315 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
17316 /* Set count to 0 for invalidating the entire FCF database */
17317 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
17319 /* Issue the mailbox command asynchronously */
17320 mbox->vport = phba->pport;
17321 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
17322 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
17324 if (rc == MBX_NOT_FINISHED) {
17325 mempool_free(mbox, phba->mbox_mem_pool);
17332 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
17333 * @phba: pointer to lpfc hba data structure.
17335 * This function is the failover routine as a last resort to the FCF DEAD
17336 * event when driver failed to perform fast FCF failover.
17339 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
17341 uint32_t link_state;
17344 * Last resort as FCF DEAD event failover will treat this as
17345 * a link down, but save the link state because we don't want
17346 * it to be changed to Link Down unless it is already down.
17348 link_state = phba->link_state;
17349 lpfc_linkdown(phba);
17350 phba->link_state = link_state;
17352 /* Unregister FCF if no devices connected to it */
17353 lpfc_unregister_unused_fcf(phba);
17357 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
17358 * @phba: pointer to lpfc hba data structure.
17359 * @rgn23_data: pointer to configure region 23 data.
17361 * This function gets SLI3 port configure region 23 data through memory dump
17362 * mailbox command. When it successfully retrieves data, the size of the data
17363 * will be returned, otherwise, 0 will be returned.
17366 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
17368 LPFC_MBOXQ_t *pmb = NULL;
17370 uint32_t offset = 0;
17376 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17379 "2600 failed to allocate mailbox memory\n");
17385 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
17386 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
17388 if (rc != MBX_SUCCESS) {
17389 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
17390 "2601 failed to read config "
17391 "region 23, rc 0x%x Status 0x%x\n",
17392 rc, mb->mbxStatus);
17393 mb->un.varDmp.word_cnt = 0;
17396 * dump mem may return a zero when finished or we got a
17397 * mailbox error, either way we are done.
17399 if (mb->un.varDmp.word_cnt == 0)
17401 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
17402 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
17404 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
17405 rgn23_data + offset,
17406 mb->un.varDmp.word_cnt);
17407 offset += mb->un.varDmp.word_cnt;
17408 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
17410 mempool_free(pmb, phba->mbox_mem_pool);
17415 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
17416 * @phba: pointer to lpfc hba data structure.
17417 * @rgn23_data: pointer to configure region 23 data.
17419 * This function gets SLI4 port configure region 23 data through memory dump
17420 * mailbox command. When it successfully retrieves data, the size of the data
17421 * will be returned, otherwise, 0 will be returned.
17424 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
17426 LPFC_MBOXQ_t *mboxq = NULL;
17427 struct lpfc_dmabuf *mp = NULL;
17428 struct lpfc_mqe *mqe;
17429 uint32_t data_length = 0;
17435 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17438 "3105 failed to allocate mailbox memory\n");
17442 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
17444 mqe = &mboxq->u.mqe;
17445 mp = (struct lpfc_dmabuf *) mboxq->context1;
17446 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
17449 data_length = mqe->un.mb_words[5];
17450 if (data_length == 0)
17452 if (data_length > DMP_RGN23_SIZE) {
17456 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
17458 mempool_free(mboxq, phba->mbox_mem_pool);
17460 lpfc_mbuf_free(phba, mp->virt, mp->phys);
17463 return data_length;
17467 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
17468 * @phba: pointer to lpfc hba data structure.
17470 * This function read region 23 and parse TLV for port status to
17471 * decide if the user disaled the port. If the TLV indicates the
17472 * port is disabled, the hba_flag is set accordingly.
17475 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
17477 uint8_t *rgn23_data = NULL;
17478 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
17479 uint32_t offset = 0;
17481 /* Get adapter Region 23 data */
17482 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
17486 if (phba->sli_rev < LPFC_SLI_REV4)
17487 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
17489 if_type = bf_get(lpfc_sli_intf_if_type,
17490 &phba->sli4_hba.sli_intf);
17491 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
17493 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
17499 /* Check the region signature first */
17500 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
17501 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17502 "2619 Config region 23 has bad signature\n");
17507 /* Check the data structure version */
17508 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
17509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17510 "2620 Config region 23 has bad version\n");
17515 /* Parse TLV entries in the region */
17516 while (offset < data_size) {
17517 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
17520 * If the TLV is not driver specific TLV or driver id is
17521 * not linux driver id, skip the record.
17523 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
17524 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
17525 (rgn23_data[offset + 3] != 0)) {
17526 offset += rgn23_data[offset + 1] * 4 + 4;
17530 /* Driver found a driver specific TLV in the config region */
17531 sub_tlv_len = rgn23_data[offset + 1] * 4;
17536 * Search for configured port state sub-TLV.
17538 while ((offset < data_size) &&
17539 (tlv_offset < sub_tlv_len)) {
17540 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
17545 if (rgn23_data[offset] != PORT_STE_TYPE) {
17546 offset += rgn23_data[offset + 1] * 4 + 4;
17547 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
17551 /* This HBA contains PORT_STE configured */
17552 if (!rgn23_data[offset + 2])
17553 phba->hba_flag |= LINK_DISABLED;
17565 * lpfc_wr_object - write an object to the firmware
17566 * @phba: HBA structure that indicates port to create a queue on.
17567 * @dmabuf_list: list of dmabufs to write to the port.
17568 * @size: the total byte value of the objects to write to the port.
17569 * @offset: the current offset to be used to start the transfer.
17571 * This routine will create a wr_object mailbox command to send to the port.
17572 * the mailbox command will be constructed using the dma buffers described in
17573 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
17574 * BDEs that the imbedded mailbox can support. The @offset variable will be
17575 * used to indicate the starting offset of the transfer and will also return
17576 * the offset after the write object mailbox has completed. @size is used to
17577 * determine the end of the object and whether the eof bit should be set.
17579 * Return 0 is successful and offset will contain the the new offset to use
17580 * for the next write.
17581 * Return negative value for error cases.
17584 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
17585 uint32_t size, uint32_t *offset)
17587 struct lpfc_mbx_wr_object *wr_object;
17588 LPFC_MBOXQ_t *mbox;
17590 uint32_t shdr_status, shdr_add_status;
17592 union lpfc_sli4_cfg_shdr *shdr;
17593 struct lpfc_dmabuf *dmabuf;
17594 uint32_t written = 0;
17596 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17600 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17601 LPFC_MBOX_OPCODE_WRITE_OBJECT,
17602 sizeof(struct lpfc_mbx_wr_object) -
17603 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
17605 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
17606 wr_object->u.request.write_offset = *offset;
17607 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
17608 wr_object->u.request.object_name[0] =
17609 cpu_to_le32(wr_object->u.request.object_name[0]);
17610 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
17611 list_for_each_entry(dmabuf, dmabuf_list, list) {
17612 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
17614 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
17615 wr_object->u.request.bde[i].addrHigh =
17616 putPaddrHigh(dmabuf->phys);
17617 if (written + SLI4_PAGE_SIZE >= size) {
17618 wr_object->u.request.bde[i].tus.f.bdeSize =
17620 written += (size - written);
17621 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
17623 wr_object->u.request.bde[i].tus.f.bdeSize =
17625 written += SLI4_PAGE_SIZE;
17629 wr_object->u.request.bde_count = i;
17630 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
17631 if (!phba->sli4_hba.intr_enable)
17632 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17634 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17635 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17637 /* The IOCTL status is embedded in the mailbox subheader. */
17638 shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr;
17639 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17640 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17641 if (rc != MBX_TIMEOUT)
17642 mempool_free(mbox, phba->mbox_mem_pool);
17643 if (shdr_status || shdr_add_status || rc) {
17644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17645 "3025 Write Object mailbox failed with "
17646 "status x%x add_status x%x, mbx status x%x\n",
17647 shdr_status, shdr_add_status, rc);
17650 *offset += wr_object->u.response.actual_write_length;
17655 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
17656 * @vport: pointer to vport data structure.
17658 * This function iterate through the mailboxq and clean up all REG_LOGIN
17659 * and REG_VPI mailbox commands associated with the vport. This function
17660 * is called when driver want to restart discovery of the vport due to
17661 * a Clear Virtual Link event.
17664 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
17666 struct lpfc_hba *phba = vport->phba;
17667 LPFC_MBOXQ_t *mb, *nextmb;
17668 struct lpfc_dmabuf *mp;
17669 struct lpfc_nodelist *ndlp;
17670 struct lpfc_nodelist *act_mbx_ndlp = NULL;
17671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
17672 LIST_HEAD(mbox_cmd_list);
17673 uint8_t restart_loop;
17675 /* Clean up internally queued mailbox commands with the vport */
17676 spin_lock_irq(&phba->hbalock);
17677 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
17678 if (mb->vport != vport)
17681 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
17682 (mb->u.mb.mbxCommand != MBX_REG_VPI))
17685 list_del(&mb->list);
17686 list_add_tail(&mb->list, &mbox_cmd_list);
17688 /* Clean up active mailbox command with the vport */
17689 mb = phba->sli.mbox_active;
17690 if (mb && (mb->vport == vport)) {
17691 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
17692 (mb->u.mb.mbxCommand == MBX_REG_VPI))
17693 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17694 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
17695 act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2;
17696 /* Put reference count for delayed processing */
17697 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
17698 /* Unregister the RPI when mailbox complete */
17699 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
17702 /* Cleanup any mailbox completions which are not yet processed */
17705 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
17707 * If this mailox is already processed or it is
17708 * for another vport ignore it.
17710 if ((mb->vport != vport) ||
17711 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
17714 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
17715 (mb->u.mb.mbxCommand != MBX_REG_VPI))
17718 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17719 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
17720 ndlp = (struct lpfc_nodelist *)mb->context2;
17721 /* Unregister the RPI when mailbox complete */
17722 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
17724 spin_unlock_irq(&phba->hbalock);
17725 spin_lock(shost->host_lock);
17726 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
17727 spin_unlock(shost->host_lock);
17728 spin_lock_irq(&phba->hbalock);
17732 } while (restart_loop);
17734 spin_unlock_irq(&phba->hbalock);
17736 /* Release the cleaned-up mailbox commands */
17737 while (!list_empty(&mbox_cmd_list)) {
17738 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
17739 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
17740 mp = (struct lpfc_dmabuf *) (mb->context1);
17742 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
17745 ndlp = (struct lpfc_nodelist *) mb->context2;
17746 mb->context2 = NULL;
17748 spin_lock(shost->host_lock);
17749 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
17750 spin_unlock(shost->host_lock);
17751 lpfc_nlp_put(ndlp);
17754 mempool_free(mb, phba->mbox_mem_pool);
17757 /* Release the ndlp with the cleaned-up active mailbox command */
17758 if (act_mbx_ndlp) {
17759 spin_lock(shost->host_lock);
17760 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
17761 spin_unlock(shost->host_lock);
17762 lpfc_nlp_put(act_mbx_ndlp);
17767 * lpfc_drain_txq - Drain the txq
17768 * @phba: Pointer to HBA context object.
17770 * This function attempt to submit IOCBs on the txq
17771 * to the adapter. For SLI4 adapters, the txq contains
17772 * ELS IOCBs that have been deferred because the there
17773 * are no SGLs. This congestion can occur with large
17774 * vport counts during node discovery.
17778 lpfc_drain_txq(struct lpfc_hba *phba)
17780 LIST_HEAD(completions);
17781 struct lpfc_sli_ring *pring;
17782 struct lpfc_iocbq *piocbq = NULL;
17783 unsigned long iflags = 0;
17784 char *fail_msg = NULL;
17785 struct lpfc_sglq *sglq;
17786 union lpfc_wqe128 wqe128;
17787 union lpfc_wqe *wqe = (union lpfc_wqe *) &wqe128;
17788 uint32_t txq_cnt = 0;
17790 pring = lpfc_phba_elsring(phba);
17792 spin_lock_irqsave(&pring->ring_lock, iflags);
17793 list_for_each_entry(piocbq, &pring->txq, list) {
17797 if (txq_cnt > pring->txq_max)
17798 pring->txq_max = txq_cnt;
17800 spin_unlock_irqrestore(&pring->ring_lock, iflags);
17802 while (!list_empty(&pring->txq)) {
17803 spin_lock_irqsave(&pring->ring_lock, iflags);
17805 piocbq = lpfc_sli_ringtx_get(phba, pring);
17807 spin_unlock_irqrestore(&pring->ring_lock, iflags);
17808 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17809 "2823 txq empty and txq_cnt is %d\n ",
17813 sglq = __lpfc_sli_get_els_sglq(phba, piocbq);
17815 __lpfc_sli_ringtx_put(phba, pring, piocbq);
17816 spin_unlock_irqrestore(&pring->ring_lock, iflags);
17821 /* The xri and iocb resources secured,
17822 * attempt to issue request
17824 piocbq->sli4_lxritag = sglq->sli4_lxritag;
17825 piocbq->sli4_xritag = sglq->sli4_xritag;
17826 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
17827 fail_msg = "to convert bpl to sgl";
17828 else if (lpfc_sli4_iocb2wqe(phba, piocbq, wqe))
17829 fail_msg = "to convert iocb to wqe";
17830 else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, wqe))
17831 fail_msg = " - Wq is full";
17833 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
17836 /* Failed means we can't issue and need to cancel */
17837 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17838 "2822 IOCB failed %s iotag 0x%x "
17841 piocbq->iotag, piocbq->sli4_xritag);
17842 list_add_tail(&piocbq->list, &completions);
17844 spin_unlock_irqrestore(&pring->ring_lock, iflags);
17847 /* Cancel all the IOCBs that cannot be issued */
17848 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
17849 IOERR_SLI_ABORTED);
17855 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
17856 * @phba: Pointer to HBA context object.
17857 * @pwqe: Pointer to command WQE.
17858 * @sglq: Pointer to the scatter gather queue object.
17860 * This routine converts the bpl or bde that is in the WQE
17861 * to a sgl list for the sli4 hardware. The physical address
17862 * of the bpl/bde is converted back to a virtual address.
17863 * If the WQE contains a BPL then the list of BDE's is
17864 * converted to sli4_sge's. If the WQE contains a single
17865 * BDE then it is converted to a single sli_sge.
17866 * The WQE is still in cpu endianness so the contents of
17867 * the bpl can be used without byte swapping.
17869 * Returns valid XRI = Success, NO_XRI = Failure.
17872 lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
17873 struct lpfc_sglq *sglq)
17875 uint16_t xritag = NO_XRI;
17876 struct ulp_bde64 *bpl = NULL;
17877 struct ulp_bde64 bde;
17878 struct sli4_sge *sgl = NULL;
17879 struct lpfc_dmabuf *dmabuf;
17880 union lpfc_wqe *wqe;
17883 uint32_t offset = 0; /* accumulated offset in the sg request list */
17884 int inbound = 0; /* number of sg reply entries inbound from firmware */
17887 if (!pwqeq || !sglq)
17890 sgl = (struct sli4_sge *)sglq->sgl;
17892 pwqeq->iocb.ulpIoTag = pwqeq->iotag;
17894 cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
17895 if (cmd == CMD_XMIT_BLS_RSP64_WQE)
17896 return sglq->sli4_xritag;
17897 numBdes = pwqeq->rsvd2;
17899 /* The addrHigh and addrLow fields within the WQE
17900 * have not been byteswapped yet so there is no
17901 * need to swap them back.
17903 if (pwqeq->context3)
17904 dmabuf = (struct lpfc_dmabuf *)pwqeq->context3;
17908 bpl = (struct ulp_bde64 *)dmabuf->virt;
17912 for (i = 0; i < numBdes; i++) {
17913 /* Should already be byte swapped. */
17914 sgl->addr_hi = bpl->addrHigh;
17915 sgl->addr_lo = bpl->addrLow;
17917 sgl->word2 = le32_to_cpu(sgl->word2);
17918 if ((i+1) == numBdes)
17919 bf_set(lpfc_sli4_sge_last, sgl, 1);
17921 bf_set(lpfc_sli4_sge_last, sgl, 0);
17922 /* swap the size field back to the cpu so we
17923 * can assign it to the sgl.
17925 bde.tus.w = le32_to_cpu(bpl->tus.w);
17926 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
17927 /* The offsets in the sgl need to be accumulated
17928 * separately for the request and reply lists.
17929 * The request is always first, the reply follows.
17932 case CMD_GEN_REQUEST64_WQE:
17933 /* add up the reply sg entries */
17934 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
17936 /* first inbound? reset the offset */
17939 bf_set(lpfc_sli4_sge_offset, sgl, offset);
17940 bf_set(lpfc_sli4_sge_type, sgl,
17941 LPFC_SGE_TYPE_DATA);
17942 offset += bde.tus.f.bdeSize;
17944 case CMD_FCP_TRSP64_WQE:
17945 bf_set(lpfc_sli4_sge_offset, sgl, 0);
17946 bf_set(lpfc_sli4_sge_type, sgl,
17947 LPFC_SGE_TYPE_DATA);
17949 case CMD_FCP_TSEND64_WQE:
17950 case CMD_FCP_TRECEIVE64_WQE:
17951 bf_set(lpfc_sli4_sge_type, sgl,
17952 bpl->tus.f.bdeFlags);
17956 offset += bde.tus.f.bdeSize;
17957 bf_set(lpfc_sli4_sge_offset, sgl, offset);
17960 sgl->word2 = cpu_to_le32(sgl->word2);
17964 } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
17965 /* The addrHigh and addrLow fields of the BDE have not
17966 * been byteswapped yet so they need to be swapped
17967 * before putting them in the sgl.
17969 sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
17970 sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
17971 sgl->word2 = le32_to_cpu(sgl->word2);
17972 bf_set(lpfc_sli4_sge_last, sgl, 1);
17973 sgl->word2 = cpu_to_le32(sgl->word2);
17974 sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
17976 return sglq->sli4_xritag;
17980 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
17981 * @phba: Pointer to HBA context object.
17982 * @ring_number: Base sli ring number
17983 * @pwqe: Pointer to command WQE.
17986 lpfc_sli4_issue_wqe(struct lpfc_hba *phba, uint32_t ring_number,
17987 struct lpfc_iocbq *pwqe)
17989 union lpfc_wqe *wqe = &pwqe->wqe;
17990 struct lpfc_nvmet_rcv_ctx *ctxp;
17991 struct lpfc_queue *wq;
17992 struct lpfc_sglq *sglq;
17993 struct lpfc_sli_ring *pring;
17994 unsigned long iflags;
17996 /* NVME_LS and NVME_LS ABTS requests. */
17997 if (pwqe->iocb_flag & LPFC_IO_NVME_LS) {
17998 pring = phba->sli4_hba.nvmels_wq->pring;
17999 spin_lock_irqsave(&pring->ring_lock, iflags);
18000 sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
18002 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18005 pwqe->sli4_lxritag = sglq->sli4_lxritag;
18006 pwqe->sli4_xritag = sglq->sli4_xritag;
18007 if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
18008 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18011 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
18012 pwqe->sli4_xritag);
18013 if (lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe)) {
18014 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18017 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
18018 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18022 /* NVME_FCREQ and NVME_ABTS requests */
18023 if (pwqe->iocb_flag & LPFC_IO_NVME) {
18024 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
18025 pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring;
18027 spin_lock_irqsave(&pring->ring_lock, iflags);
18028 wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx];
18029 bf_set(wqe_cqid, &wqe->generic.wqe_com,
18030 phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id);
18031 if (lpfc_sli4_wq_put(wq, wqe)) {
18032 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18035 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
18036 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18040 /* NVMET requests */
18041 if (pwqe->iocb_flag & LPFC_IO_NVMET) {
18042 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
18043 pring = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx]->pring;
18045 spin_lock_irqsave(&pring->ring_lock, iflags);
18046 ctxp = pwqe->context2;
18047 sglq = ctxp->rqb_buffer->sglq;
18048 if (pwqe->sli4_xritag == NO_XRI) {
18049 pwqe->sli4_lxritag = sglq->sli4_lxritag;
18050 pwqe->sli4_xritag = sglq->sli4_xritag;
18052 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
18053 pwqe->sli4_xritag);
18054 wq = phba->sli4_hba.nvme_wq[pwqe->hba_wqidx];
18055 bf_set(wqe_cqid, &wqe->generic.wqe_com,
18056 phba->sli4_hba.nvme_cq[pwqe->hba_wqidx]->queue_id);
18057 if (lpfc_sli4_wq_put(wq, wqe)) {
18058 spin_unlock_irqrestore(&pring->ring_lock, iflags);
18061 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
18062 spin_unlock_irqrestore(&pring->ring_lock, iflags);