1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2019 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/interrupt.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/lockdep.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
37 #include <linux/aer.h>
39 #include <asm/set_memory.h>
42 #include <linux/nvme-fc-driver.h>
47 #include "lpfc_sli4.h"
49 #include "lpfc_disc.h"
51 #include "lpfc_scsi.h"
52 #include "lpfc_nvme.h"
53 #include "lpfc_nvmet.h"
54 #include "lpfc_crtn.h"
55 #include "lpfc_logmsg.h"
56 #include "lpfc_compat.h"
57 #include "lpfc_debugfs.h"
58 #include "lpfc_vport.h"
59 #include "lpfc_version.h"
61 /* There are only four IOCB completion types. */
62 typedef enum _lpfc_iocb_type {
70 /* Provide function prototypes local to this module. */
71 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
73 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
74 uint8_t *, uint32_t *);
75 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
77 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
79 static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
80 struct hbq_dmabuf *dmabuf);
81 static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba,
82 struct lpfc_queue *cq, struct lpfc_cqe *cqe);
83 static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
85 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba,
86 struct lpfc_queue *eq,
87 struct lpfc_eqe *eqe);
88 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
89 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
92 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
97 #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
99 * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
100 * @srcp: Source memory pointer.
101 * @destp: Destination memory pointer.
102 * @cnt: Number of words required to be copied.
103 * Must be a multiple of sizeof(uint64_t)
105 * This function is used for copying data between driver memory
106 * and the SLI WQ. This function also changes the endianness
107 * of each word if native endianness is different from SLI
108 * endianness. This function can be called with or without
112 lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
114 uint64_t *src = srcp;
115 uint64_t *dest = destp;
118 for (i = 0; i < (int)cnt; i += sizeof(uint64_t))
122 #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
126 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
127 * @q: The Work Queue to operate on.
128 * @wqe: The work Queue Entry to put on the Work queue.
130 * This routine will copy the contents of @wqe to the next available entry on
131 * the @q. This function will then ring the Work Queue Doorbell to signal the
132 * HBA to start processing the Work Queue Entry. This function returns 0 if
133 * successful. If no entries are available on @q then this function will return
135 * The caller is expected to hold the hbalock when calling this routine.
138 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe)
140 union lpfc_wqe *temp_wqe;
141 struct lpfc_register doorbell;
148 /* sanity check on queue memory */
151 temp_wqe = lpfc_sli4_qe(q, q->host_index);
153 /* If the host has not yet processed the next entry then we are done */
154 idx = ((q->host_index + 1) % q->entry_count);
155 if (idx == q->hba_index) {
160 /* set consumption flag every once in a while */
161 if (!((q->host_index + 1) % q->notify_interval))
162 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
164 bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
165 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
166 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
167 lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
168 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
169 /* write to DPP aperture taking advatage of Combined Writes */
170 tmp = (uint8_t *)temp_wqe;
172 for (i = 0; i < q->entry_size; i += sizeof(uint64_t))
173 __raw_writeq(*((uint64_t *)(tmp + i)),
176 for (i = 0; i < q->entry_size; i += sizeof(uint32_t))
177 __raw_writel(*((uint32_t *)(tmp + i)),
181 /* ensure WQE bcopy and DPP flushed before doorbell write */
184 /* Update the host index before invoking device */
185 host_index = q->host_index;
191 if (q->db_format == LPFC_DB_LIST_FORMAT) {
192 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
193 bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1);
194 bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1);
195 bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell,
197 bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell,
200 bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
201 bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
203 /* Leave bits <23:16> clear for if_type 6 dpp */
204 if_type = bf_get(lpfc_sli_intf_if_type,
205 &q->phba->sli4_hba.sli_intf);
206 if (if_type != LPFC_SLI_INTF_IF_TYPE_6)
207 bf_set(lpfc_wq_db_list_fm_index, &doorbell,
210 } else if (q->db_format == LPFC_DB_RING_FORMAT) {
211 bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
212 bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
216 writel(doorbell.word0, q->db_regaddr);
222 * lpfc_sli4_wq_release - Updates internal hba index for WQ
223 * @q: The Work Queue to operate on.
224 * @index: The index to advance the hba index to.
226 * This routine will update the HBA index of a queue to reflect consumption of
227 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
228 * an entry the host calls this function to update the queue's internal
229 * pointers. This routine returns the number of entries that were consumed by
233 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
235 uint32_t released = 0;
237 /* sanity check on queue memory */
241 if (q->hba_index == index)
244 q->hba_index = ((q->hba_index + 1) % q->entry_count);
246 } while (q->hba_index != index);
251 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
252 * @q: The Mailbox Queue to operate on.
253 * @wqe: The Mailbox Queue Entry to put on the Work queue.
255 * This routine will copy the contents of @mqe to the next available entry on
256 * the @q. This function will then ring the Work Queue Doorbell to signal the
257 * HBA to start processing the Work Queue Entry. This function returns 0 if
258 * successful. If no entries are available on @q then this function will return
260 * The caller is expected to hold the hbalock when calling this routine.
263 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
265 struct lpfc_mqe *temp_mqe;
266 struct lpfc_register doorbell;
268 /* sanity check on queue memory */
271 temp_mqe = lpfc_sli4_qe(q, q->host_index);
273 /* If the host has not yet processed the next entry then we are done */
274 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
276 lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
277 /* Save off the mailbox pointer for completion */
278 q->phba->mbox = (MAILBOX_t *)temp_mqe;
280 /* Update the host index before invoking device */
281 q->host_index = ((q->host_index + 1) % q->entry_count);
285 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
286 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
287 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
292 * lpfc_sli4_mq_release - Updates internal hba index for MQ
293 * @q: The Mailbox Queue to operate on.
295 * This routine will update the HBA index of a queue to reflect consumption of
296 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
297 * an entry the host calls this function to update the queue's internal
298 * pointers. This routine returns the number of entries that were consumed by
302 lpfc_sli4_mq_release(struct lpfc_queue *q)
304 /* sanity check on queue memory */
308 /* Clear the mailbox pointer for completion */
309 q->phba->mbox = NULL;
310 q->hba_index = ((q->hba_index + 1) % q->entry_count);
315 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
316 * @q: The Event Queue to get the first valid EQE from
318 * This routine will get the first valid Event Queue Entry from @q, update
319 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
320 * the Queue (no more work to do), or the Queue is full of EQEs that have been
321 * processed, but not popped back to the HBA then this routine will return NULL.
323 static struct lpfc_eqe *
324 lpfc_sli4_eq_get(struct lpfc_queue *q)
326 struct lpfc_eqe *eqe;
328 /* sanity check on queue memory */
331 eqe = lpfc_sli4_qe(q, q->host_index);
333 /* If the next EQE is not valid then we are done */
334 if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid)
338 * insert barrier for instruction interlock : data from the hardware
339 * must have the valid bit checked before it can be copied and acted
340 * upon. Speculative instructions were allowing a bcopy at the start
341 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
342 * after our return, to copy data before the valid bit check above
343 * was done. As such, some of the copied data was stale. The barrier
344 * ensures the check is before any data is copied.
351 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
352 * @q: The Event Queue to disable interrupts
356 lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
358 struct lpfc_register doorbell;
361 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
362 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
363 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
364 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
365 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
366 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
370 * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
371 * @q: The Event Queue to disable interrupts
375 lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q)
377 struct lpfc_register doorbell;
380 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
381 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
385 * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state
386 * @phba: adapter with EQ
387 * @q: The Event Queue that the host has completed processing for.
388 * @count: Number of elements that have been consumed
389 * @arm: Indicates whether the host wants to arms this CQ.
391 * This routine will notify the HBA, by ringing the doorbell, that count
392 * number of EQEs have been processed. The @arm parameter indicates whether
393 * the queue should be rearmed when ringing the doorbell.
396 lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
397 uint32_t count, bool arm)
399 struct lpfc_register doorbell;
401 /* sanity check on queue memory */
402 if (unlikely(!q || (count == 0 && !arm)))
405 /* ring doorbell for number popped */
408 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
409 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
411 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
412 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
413 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
414 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
415 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
416 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
417 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
418 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
419 readl(q->phba->sli4_hba.EQDBregaddr);
423 * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state
424 * @phba: adapter with EQ
425 * @q: The Event Queue that the host has completed processing for.
426 * @count: Number of elements that have been consumed
427 * @arm: Indicates whether the host wants to arms this CQ.
429 * This routine will notify the HBA, by ringing the doorbell, that count
430 * number of EQEs have been processed. The @arm parameter indicates whether
431 * the queue should be rearmed when ringing the doorbell.
434 lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
435 uint32_t count, bool arm)
437 struct lpfc_register doorbell;
439 /* sanity check on queue memory */
440 if (unlikely(!q || (count == 0 && !arm)))
443 /* ring doorbell for number popped */
446 bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1);
447 bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count);
448 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
449 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
450 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
451 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
452 readl(q->phba->sli4_hba.EQDBregaddr);
456 __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
457 struct lpfc_eqe *eqe)
459 if (!phba->sli4_hba.pc_sli4_params.eqav)
460 bf_set_le32(lpfc_eqe_valid, eqe, 0);
462 eq->host_index = ((eq->host_index + 1) % eq->entry_count);
464 /* if the index wrapped around, toggle the valid bit */
465 if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index)
466 eq->qe_valid = (eq->qe_valid) ? 0 : 1;
470 lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
472 struct lpfc_eqe *eqe;
475 /* walk all the EQ entries and drop on the floor */
476 eqe = lpfc_sli4_eq_get(eq);
478 __lpfc_sli4_consume_eqe(phba, eq, eqe);
480 eqe = lpfc_sli4_eq_get(eq);
483 /* Clear and re-arm the EQ */
484 phba->sli4_hba.sli4_write_eq_db(phba, eq, count, LPFC_QUEUE_REARM);
488 lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq)
490 struct lpfc_eqe *eqe;
491 int count = 0, consumed = 0;
493 if (cmpxchg(&eq->queue_claimed, 0, 1) != 0)
496 eqe = lpfc_sli4_eq_get(eq);
498 lpfc_sli4_hba_handle_eqe(phba, eq, eqe);
499 __lpfc_sli4_consume_eqe(phba, eq, eqe);
502 if (!(++count % eq->max_proc_limit))
505 if (!(count % eq->notify_interval)) {
506 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed,
511 eqe = lpfc_sli4_eq_get(eq);
513 eq->EQ_processed += count;
515 /* Track the max number of EQEs processed in 1 intr */
516 if (count > eq->EQ_max_eqe)
517 eq->EQ_max_eqe = count;
519 eq->queue_claimed = 0;
522 /* Always clear and re-arm the EQ */
523 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, LPFC_QUEUE_REARM);
529 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
530 * @q: The Completion Queue to get the first valid CQE from
532 * This routine will get the first valid Completion Queue Entry from @q, update
533 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
534 * the Queue (no more work to do), or the Queue is full of CQEs that have been
535 * processed, but not popped back to the HBA then this routine will return NULL.
537 static struct lpfc_cqe *
538 lpfc_sli4_cq_get(struct lpfc_queue *q)
540 struct lpfc_cqe *cqe;
542 /* sanity check on queue memory */
545 cqe = lpfc_sli4_qe(q, q->host_index);
547 /* If the next CQE is not valid then we are done */
548 if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid)
552 * insert barrier for instruction interlock : data from the hardware
553 * must have the valid bit checked before it can be copied and acted
554 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
555 * instructions allowing action on content before valid bit checked,
556 * add barrier here as well. May not be needed as "content" is a
557 * single 32-bit entity here (vs multi word structure for cq's).
564 __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
565 struct lpfc_cqe *cqe)
567 if (!phba->sli4_hba.pc_sli4_params.cqav)
568 bf_set_le32(lpfc_cqe_valid, cqe, 0);
570 cq->host_index = ((cq->host_index + 1) % cq->entry_count);
572 /* if the index wrapped around, toggle the valid bit */
573 if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index)
574 cq->qe_valid = (cq->qe_valid) ? 0 : 1;
578 * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state.
579 * @phba: the adapter with the CQ
580 * @q: The Completion Queue that the host has completed processing for.
581 * @count: the number of elements that were consumed
582 * @arm: Indicates whether the host wants to arms this CQ.
584 * This routine will notify the HBA, by ringing the doorbell, that the
585 * CQEs have been processed. The @arm parameter specifies whether the
586 * queue should be rearmed when ringing the doorbell.
589 lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
590 uint32_t count, bool arm)
592 struct lpfc_register doorbell;
594 /* sanity check on queue memory */
595 if (unlikely(!q || (count == 0 && !arm)))
598 /* ring doorbell for number popped */
601 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
602 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
603 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
604 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
605 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
606 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
607 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
611 * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state.
612 * @phba: the adapter with the CQ
613 * @q: The Completion Queue that the host has completed processing for.
614 * @count: the number of elements that were consumed
615 * @arm: Indicates whether the host wants to arms this CQ.
617 * This routine will notify the HBA, by ringing the doorbell, that the
618 * CQEs have been processed. The @arm parameter specifies whether the
619 * queue should be rearmed when ringing the doorbell.
622 lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
623 uint32_t count, bool arm)
625 struct lpfc_register doorbell;
627 /* sanity check on queue memory */
628 if (unlikely(!q || (count == 0 && !arm)))
631 /* ring doorbell for number popped */
634 bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1);
635 bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count);
636 bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id);
637 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
641 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
642 * @q: The Header Receive Queue to operate on.
643 * @wqe: The Receive Queue Entry to put on the Receive queue.
645 * This routine will copy the contents of @wqe to the next available entry on
646 * the @q. This function will then ring the Receive Queue Doorbell to signal the
647 * HBA to start processing the Receive Queue Entry. This function returns the
648 * index that the rqe was copied to if successful. If no entries are available
649 * on @q then this function will return -ENOMEM.
650 * The caller is expected to hold the hbalock when calling this routine.
653 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
654 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
656 struct lpfc_rqe *temp_hrqe;
657 struct lpfc_rqe *temp_drqe;
658 struct lpfc_register doorbell;
662 /* sanity check on queue memory */
663 if (unlikely(!hq) || unlikely(!dq))
665 hq_put_index = hq->host_index;
666 dq_put_index = dq->host_index;
667 temp_hrqe = lpfc_sli4_qe(hq, hq_put_index);
668 temp_drqe = lpfc_sli4_qe(dq, dq_put_index);
670 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
672 if (hq_put_index != dq_put_index)
674 /* If the host has not yet processed the next entry then we are done */
675 if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index)
677 lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
678 lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
680 /* Update the host index to point to the next slot */
681 hq->host_index = ((hq_put_index + 1) % hq->entry_count);
682 dq->host_index = ((dq_put_index + 1) % dq->entry_count);
685 /* Ring The Header Receive Queue Doorbell */
686 if (!(hq->host_index % hq->notify_interval)) {
688 if (hq->db_format == LPFC_DB_RING_FORMAT) {
689 bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
690 hq->notify_interval);
691 bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
692 } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
693 bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
694 hq->notify_interval);
695 bf_set(lpfc_rq_db_list_fm_index, &doorbell,
697 bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
701 writel(doorbell.word0, hq->db_regaddr);
707 * lpfc_sli4_rq_release - Updates internal hba index for RQ
708 * @q: The Header Receive Queue to operate on.
710 * This routine will update the HBA index of a queue to reflect consumption of
711 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
712 * consumed an entry the host calls this function to update the queue's
713 * internal pointers. This routine returns the number of entries that were
714 * consumed by the HBA.
717 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
719 /* sanity check on queue memory */
720 if (unlikely(!hq) || unlikely(!dq))
723 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
725 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
726 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
731 * lpfc_cmd_iocb - Get next command iocb entry in the ring
732 * @phba: Pointer to HBA context object.
733 * @pring: Pointer to driver SLI ring object.
735 * This function returns pointer to next command iocb entry
736 * in the command ring. The caller must hold hbalock to prevent
737 * other threads consume the next command iocb.
738 * SLI-2/SLI-3 provide different sized iocbs.
740 static inline IOCB_t *
741 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
743 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
744 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
748 * lpfc_resp_iocb - Get next response iocb entry in the ring
749 * @phba: Pointer to HBA context object.
750 * @pring: Pointer to driver SLI ring object.
752 * This function returns pointer to next response iocb entry
753 * in the response ring. The caller must hold hbalock to make sure
754 * that no other thread consume the next response iocb.
755 * SLI-2/SLI-3 provide different sized iocbs.
757 static inline IOCB_t *
758 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
760 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
761 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
765 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
766 * @phba: Pointer to HBA context object.
768 * This function is called with hbalock held. This function
769 * allocates a new driver iocb object from the iocb pool. If the
770 * allocation is successful, it returns pointer to the newly
771 * allocated iocb object else it returns NULL.
774 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
776 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
777 struct lpfc_iocbq * iocbq = NULL;
779 lockdep_assert_held(&phba->hbalock);
781 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
784 if (phba->iocb_cnt > phba->iocb_max)
785 phba->iocb_max = phba->iocb_cnt;
790 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
791 * @phba: Pointer to HBA context object.
792 * @xritag: XRI value.
794 * This function clears the sglq pointer from the array of acive
795 * sglq's. The xritag that is passed in is used to index into the
796 * array. Before the xritag can be used it needs to be adjusted
797 * by subtracting the xribase.
799 * Returns sglq ponter = success, NULL = Failure.
802 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
804 struct lpfc_sglq *sglq;
806 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
807 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
812 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
813 * @phba: Pointer to HBA context object.
814 * @xritag: XRI value.
816 * This function returns the sglq pointer from the array of acive
817 * sglq's. The xritag that is passed in is used to index into the
818 * array. Before the xritag can be used it needs to be adjusted
819 * by subtracting the xribase.
821 * Returns sglq ponter = success, NULL = Failure.
824 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
826 struct lpfc_sglq *sglq;
828 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
833 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
834 * @phba: Pointer to HBA context object.
835 * @xritag: xri used in this exchange.
836 * @rrq: The RRQ to be cleared.
840 lpfc_clr_rrq_active(struct lpfc_hba *phba,
842 struct lpfc_node_rrq *rrq)
844 struct lpfc_nodelist *ndlp = NULL;
846 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
847 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
849 /* The target DID could have been swapped (cable swap)
850 * we should use the ndlp from the findnode if it is
853 if ((!ndlp) && rrq->ndlp)
859 if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
862 rrq->rrq_stop_time = 0;
865 mempool_free(rrq, phba->rrq_pool);
869 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
870 * @phba: Pointer to HBA context object.
872 * This function is called with hbalock held. This function
873 * Checks if stop_time (ratov from setting rrq active) has
874 * been reached, if it has and the send_rrq flag is set then
875 * it will call lpfc_send_rrq. If the send_rrq flag is not set
876 * then it will just call the routine to clear the rrq and
877 * free the rrq resource.
878 * The timer is set to the next rrq that is going to expire before
879 * leaving the routine.
883 lpfc_handle_rrq_active(struct lpfc_hba *phba)
885 struct lpfc_node_rrq *rrq;
886 struct lpfc_node_rrq *nextrrq;
887 unsigned long next_time;
888 unsigned long iflags;
891 spin_lock_irqsave(&phba->hbalock, iflags);
892 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
893 next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
894 list_for_each_entry_safe(rrq, nextrrq,
895 &phba->active_rrq_list, list) {
896 if (time_after(jiffies, rrq->rrq_stop_time))
897 list_move(&rrq->list, &send_rrq);
898 else if (time_before(rrq->rrq_stop_time, next_time))
899 next_time = rrq->rrq_stop_time;
901 spin_unlock_irqrestore(&phba->hbalock, iflags);
902 if ((!list_empty(&phba->active_rrq_list)) &&
903 (!(phba->pport->load_flag & FC_UNLOADING)))
904 mod_timer(&phba->rrq_tmr, next_time);
905 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
906 list_del(&rrq->list);
907 if (!rrq->send_rrq) {
908 /* this call will free the rrq */
909 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
910 } else if (lpfc_send_rrq(phba, rrq)) {
911 /* if we send the rrq then the completion handler
912 * will clear the bit in the xribitmap.
914 lpfc_clr_rrq_active(phba, rrq->xritag,
921 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
922 * @vport: Pointer to vport context object.
923 * @xri: The xri used in the exchange.
924 * @did: The targets DID for this exchange.
926 * returns NULL = rrq not found in the phba->active_rrq_list.
927 * rrq = rrq for this xri and target.
929 struct lpfc_node_rrq *
930 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
932 struct lpfc_hba *phba = vport->phba;
933 struct lpfc_node_rrq *rrq;
934 struct lpfc_node_rrq *nextrrq;
935 unsigned long iflags;
937 if (phba->sli_rev != LPFC_SLI_REV4)
939 spin_lock_irqsave(&phba->hbalock, iflags);
940 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
941 if (rrq->vport == vport && rrq->xritag == xri &&
942 rrq->nlp_DID == did){
943 list_del(&rrq->list);
944 spin_unlock_irqrestore(&phba->hbalock, iflags);
948 spin_unlock_irqrestore(&phba->hbalock, iflags);
953 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
954 * @vport: Pointer to vport context object.
955 * @ndlp: Pointer to the lpfc_node_list structure.
956 * If ndlp is NULL Remove all active RRQs for this vport from the
957 * phba->active_rrq_list and clear the rrq.
958 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
961 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
964 struct lpfc_hba *phba = vport->phba;
965 struct lpfc_node_rrq *rrq;
966 struct lpfc_node_rrq *nextrrq;
967 unsigned long iflags;
970 if (phba->sli_rev != LPFC_SLI_REV4)
973 lpfc_sli4_vport_delete_els_xri_aborted(vport);
974 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
976 spin_lock_irqsave(&phba->hbalock, iflags);
977 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
978 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
979 list_move(&rrq->list, &rrq_list);
980 spin_unlock_irqrestore(&phba->hbalock, iflags);
982 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
983 list_del(&rrq->list);
984 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
989 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
990 * @phba: Pointer to HBA context object.
991 * @ndlp: Targets nodelist pointer for this exchange.
992 * @xritag the xri in the bitmap to test.
994 * This function returns:
995 * 0 = rrq not active for this xri
996 * 1 = rrq is valid for this xri.
999 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1004 if (!ndlp->active_rrqs_xri_bitmap)
1006 if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1013 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
1014 * @phba: Pointer to HBA context object.
1015 * @ndlp: nodelist pointer for this target.
1016 * @xritag: xri used in this exchange.
1017 * @rxid: Remote Exchange ID.
1018 * @send_rrq: Flag used to determine if we should send rrq els cmd.
1020 * This function takes the hbalock.
1021 * The active bit is always set in the active rrq xri_bitmap even
1022 * if there is no slot avaiable for the other rrq information.
1024 * returns 0 rrq actived for this xri
1025 * < 0 No memory or invalid ndlp.
1028 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1029 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
1031 unsigned long iflags;
1032 struct lpfc_node_rrq *rrq;
1038 if (!phba->cfg_enable_rrq)
1041 spin_lock_irqsave(&phba->hbalock, iflags);
1042 if (phba->pport->load_flag & FC_UNLOADING) {
1043 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1048 * set the active bit even if there is no mem available.
1050 if (NLP_CHK_FREE_REQ(ndlp))
1053 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
1056 if (!ndlp->active_rrqs_xri_bitmap)
1059 if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1062 spin_unlock_irqrestore(&phba->hbalock, iflags);
1063 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
1065 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1066 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
1067 " DID:0x%x Send:%d\n",
1068 xritag, rxid, ndlp->nlp_DID, send_rrq);
1071 if (phba->cfg_enable_rrq == 1)
1072 rrq->send_rrq = send_rrq;
1075 rrq->xritag = xritag;
1076 rrq->rrq_stop_time = jiffies +
1077 msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
1079 rrq->nlp_DID = ndlp->nlp_DID;
1080 rrq->vport = ndlp->vport;
1082 spin_lock_irqsave(&phba->hbalock, iflags);
1083 empty = list_empty(&phba->active_rrq_list);
1084 list_add_tail(&rrq->list, &phba->active_rrq_list);
1085 phba->hba_flag |= HBA_RRQ_ACTIVE;
1087 lpfc_worker_wake_up(phba);
1088 spin_unlock_irqrestore(&phba->hbalock, iflags);
1091 spin_unlock_irqrestore(&phba->hbalock, iflags);
1092 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1093 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
1094 " DID:0x%x Send:%d\n",
1095 xritag, rxid, ndlp->nlp_DID, send_rrq);
1100 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
1101 * @phba: Pointer to HBA context object.
1102 * @piocb: Pointer to the iocbq.
1104 * The driver calls this function with either the nvme ls ring lock
1105 * or the fc els ring lock held depending on the iocb usage. This function
1106 * gets a new driver sglq object from the sglq list. If the list is not empty
1107 * then it is successful, it returns pointer to the newly allocated sglq
1108 * object else it returns NULL.
1110 static struct lpfc_sglq *
1111 __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1113 struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
1114 struct lpfc_sglq *sglq = NULL;
1115 struct lpfc_sglq *start_sglq = NULL;
1116 struct lpfc_io_buf *lpfc_cmd;
1117 struct lpfc_nodelist *ndlp;
1118 struct lpfc_sli_ring *pring = NULL;
1121 if (piocbq->iocb_flag & LPFC_IO_NVME_LS)
1122 pring = phba->sli4_hba.nvmels_wq->pring;
1124 pring = lpfc_phba_elsring(phba);
1126 lockdep_assert_held(&pring->ring_lock);
1128 if (piocbq->iocb_flag & LPFC_IO_FCP) {
1129 lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1;
1130 ndlp = lpfc_cmd->rdata->pnode;
1131 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
1132 !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
1133 ndlp = piocbq->context_un.ndlp;
1134 } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
1135 if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
1138 ndlp = piocbq->context_un.ndlp;
1140 ndlp = piocbq->context1;
1143 spin_lock(&phba->sli4_hba.sgl_list_lock);
1144 list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
1149 if (ndlp && ndlp->active_rrqs_xri_bitmap &&
1150 test_bit(sglq->sli4_lxritag,
1151 ndlp->active_rrqs_xri_bitmap)) {
1152 /* This xri has an rrq outstanding for this DID.
1153 * put it back in the list and get another xri.
1155 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1157 list_remove_head(lpfc_els_sgl_list, sglq,
1158 struct lpfc_sglq, list);
1159 if (sglq == start_sglq) {
1160 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1168 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1169 sglq->state = SGL_ALLOCATED;
1171 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1176 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
1177 * @phba: Pointer to HBA context object.
1178 * @piocb: Pointer to the iocbq.
1180 * This function is called with the sgl_list lock held. This function
1181 * gets a new driver sglq object from the sglq list. If the
1182 * list is not empty then it is successful, it returns pointer to the newly
1183 * allocated sglq object else it returns NULL.
1186 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1188 struct list_head *lpfc_nvmet_sgl_list;
1189 struct lpfc_sglq *sglq = NULL;
1191 lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
1193 lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
1195 list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
1198 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1199 sglq->state = SGL_ALLOCATED;
1204 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1205 * @phba: Pointer to HBA context object.
1207 * This function is called with no lock held. This function
1208 * allocates a new driver iocb object from the iocb pool. If the
1209 * allocation is successful, it returns pointer to the newly
1210 * allocated iocb object else it returns NULL.
1213 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
1215 struct lpfc_iocbq * iocbq = NULL;
1216 unsigned long iflags;
1218 spin_lock_irqsave(&phba->hbalock, iflags);
1219 iocbq = __lpfc_sli_get_iocbq(phba);
1220 spin_unlock_irqrestore(&phba->hbalock, iflags);
1225 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1226 * @phba: Pointer to HBA context object.
1227 * @iocbq: Pointer to driver iocb object.
1229 * This function is called with hbalock held to release driver
1230 * iocb object to the iocb pool. The iotag in the iocb object
1231 * does not change for each use of the iocb object. This function
1232 * clears all other fields of the iocb object when it is freed.
1233 * The sqlq structure that holds the xritag and phys and virtual
1234 * mappings for the scatter gather list is retrieved from the
1235 * active array of sglq. The get of the sglq pointer also clears
1236 * the entry in the array. If the status of the IO indiactes that
1237 * this IO was aborted then the sglq entry it put on the
1238 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1239 * IO has good status or fails for any other reason then the sglq
1240 * entry is added to the free list (lpfc_els_sgl_list).
1243 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1245 struct lpfc_sglq *sglq;
1246 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1247 unsigned long iflag = 0;
1248 struct lpfc_sli_ring *pring;
1250 lockdep_assert_held(&phba->hbalock);
1252 if (iocbq->sli4_xritag == NO_XRI)
1255 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
1259 if (iocbq->iocb_flag & LPFC_IO_NVMET) {
1260 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1262 sglq->state = SGL_FREED;
1264 list_add_tail(&sglq->list,
1265 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1266 spin_unlock_irqrestore(
1267 &phba->sli4_hba.sgl_list_lock, iflag);
1271 pring = phba->sli4_hba.els_wq->pring;
1272 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
1273 (sglq->state != SGL_XRI_ABORTED)) {
1274 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1276 list_add(&sglq->list,
1277 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1278 spin_unlock_irqrestore(
1279 &phba->sli4_hba.sgl_list_lock, iflag);
1281 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1283 sglq->state = SGL_FREED;
1285 list_add_tail(&sglq->list,
1286 &phba->sli4_hba.lpfc_els_sgl_list);
1287 spin_unlock_irqrestore(
1288 &phba->sli4_hba.sgl_list_lock, iflag);
1290 /* Check if TXQ queue needs to be serviced */
1291 if (!list_empty(&pring->txq))
1292 lpfc_worker_wake_up(phba);
1298 * Clean all volatile data fields, preserve iotag and node struct.
1300 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1301 iocbq->sli4_lxritag = NO_XRI;
1302 iocbq->sli4_xritag = NO_XRI;
1303 iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET |
1305 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1310 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1311 * @phba: Pointer to HBA context object.
1312 * @iocbq: Pointer to driver iocb object.
1314 * This function is called with hbalock held to release driver
1315 * iocb object to the iocb pool. The iotag in the iocb object
1316 * does not change for each use of the iocb object. This function
1317 * clears all other fields of the iocb object when it is freed.
1320 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1322 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1324 lockdep_assert_held(&phba->hbalock);
1327 * Clean all volatile data fields, preserve iotag and node struct.
1329 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1330 iocbq->sli4_xritag = NO_XRI;
1331 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1335 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1336 * @phba: Pointer to HBA context object.
1337 * @iocbq: Pointer to driver iocb object.
1339 * This function is called with hbalock held to release driver
1340 * iocb object to the iocb pool. The iotag in the iocb object
1341 * does not change for each use of the iocb object. This function
1342 * clears all other fields of the iocb object when it is freed.
1345 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1347 lockdep_assert_held(&phba->hbalock);
1349 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1354 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1355 * @phba: Pointer to HBA context object.
1356 * @iocbq: Pointer to driver iocb object.
1358 * This function is called with no lock held to release the iocb to
1362 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1364 unsigned long iflags;
1367 * Clean all volatile data fields, preserve iotag and node struct.
1369 spin_lock_irqsave(&phba->hbalock, iflags);
1370 __lpfc_sli_release_iocbq(phba, iocbq);
1371 spin_unlock_irqrestore(&phba->hbalock, iflags);
1375 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1376 * @phba: Pointer to HBA context object.
1377 * @iocblist: List of IOCBs.
1378 * @ulpstatus: ULP status in IOCB command field.
1379 * @ulpWord4: ULP word-4 in IOCB command field.
1381 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1382 * on the list by invoking the complete callback function associated with the
1383 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1387 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1388 uint32_t ulpstatus, uint32_t ulpWord4)
1390 struct lpfc_iocbq *piocb;
1392 while (!list_empty(iocblist)) {
1393 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1394 if (!piocb->iocb_cmpl) {
1395 if (piocb->iocb_flag & LPFC_IO_NVME)
1396 lpfc_nvme_cancel_iocb(phba, piocb);
1398 lpfc_sli_release_iocbq(phba, piocb);
1400 piocb->iocb.ulpStatus = ulpstatus;
1401 piocb->iocb.un.ulpWord[4] = ulpWord4;
1402 (piocb->iocb_cmpl) (phba, piocb, piocb);
1409 * lpfc_sli_iocb_cmd_type - Get the iocb type
1410 * @iocb_cmnd: iocb command code.
1412 * This function is called by ring event handler function to get the iocb type.
1413 * This function translates the iocb command to an iocb command type used to
1414 * decide the final disposition of each completed IOCB.
1415 * The function returns
1416 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1417 * LPFC_SOL_IOCB if it is a solicited iocb completion
1418 * LPFC_ABORT_IOCB if it is an abort iocb
1419 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1421 * The caller is not required to hold any lock.
1423 static lpfc_iocb_type
1424 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1426 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1428 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1431 switch (iocb_cmnd) {
1432 case CMD_XMIT_SEQUENCE_CR:
1433 case CMD_XMIT_SEQUENCE_CX:
1434 case CMD_XMIT_BCAST_CN:
1435 case CMD_XMIT_BCAST_CX:
1436 case CMD_ELS_REQUEST_CR:
1437 case CMD_ELS_REQUEST_CX:
1438 case CMD_CREATE_XRI_CR:
1439 case CMD_CREATE_XRI_CX:
1440 case CMD_GET_RPI_CN:
1441 case CMD_XMIT_ELS_RSP_CX:
1442 case CMD_GET_RPI_CR:
1443 case CMD_FCP_IWRITE_CR:
1444 case CMD_FCP_IWRITE_CX:
1445 case CMD_FCP_IREAD_CR:
1446 case CMD_FCP_IREAD_CX:
1447 case CMD_FCP_ICMND_CR:
1448 case CMD_FCP_ICMND_CX:
1449 case CMD_FCP_TSEND_CX:
1450 case CMD_FCP_TRSP_CX:
1451 case CMD_FCP_TRECEIVE_CX:
1452 case CMD_FCP_AUTO_TRSP_CX:
1453 case CMD_ADAPTER_MSG:
1454 case CMD_ADAPTER_DUMP:
1455 case CMD_XMIT_SEQUENCE64_CR:
1456 case CMD_XMIT_SEQUENCE64_CX:
1457 case CMD_XMIT_BCAST64_CN:
1458 case CMD_XMIT_BCAST64_CX:
1459 case CMD_ELS_REQUEST64_CR:
1460 case CMD_ELS_REQUEST64_CX:
1461 case CMD_FCP_IWRITE64_CR:
1462 case CMD_FCP_IWRITE64_CX:
1463 case CMD_FCP_IREAD64_CR:
1464 case CMD_FCP_IREAD64_CX:
1465 case CMD_FCP_ICMND64_CR:
1466 case CMD_FCP_ICMND64_CX:
1467 case CMD_FCP_TSEND64_CX:
1468 case CMD_FCP_TRSP64_CX:
1469 case CMD_FCP_TRECEIVE64_CX:
1470 case CMD_GEN_REQUEST64_CR:
1471 case CMD_GEN_REQUEST64_CX:
1472 case CMD_XMIT_ELS_RSP64_CX:
1473 case DSSCMD_IWRITE64_CR:
1474 case DSSCMD_IWRITE64_CX:
1475 case DSSCMD_IREAD64_CR:
1476 case DSSCMD_IREAD64_CX:
1477 type = LPFC_SOL_IOCB;
1479 case CMD_ABORT_XRI_CN:
1480 case CMD_ABORT_XRI_CX:
1481 case CMD_CLOSE_XRI_CN:
1482 case CMD_CLOSE_XRI_CX:
1483 case CMD_XRI_ABORTED_CX:
1484 case CMD_ABORT_MXRI64_CN:
1485 case CMD_XMIT_BLS_RSP64_CX:
1486 type = LPFC_ABORT_IOCB;
1488 case CMD_RCV_SEQUENCE_CX:
1489 case CMD_RCV_ELS_REQ_CX:
1490 case CMD_RCV_SEQUENCE64_CX:
1491 case CMD_RCV_ELS_REQ64_CX:
1492 case CMD_ASYNC_STATUS:
1493 case CMD_IOCB_RCV_SEQ64_CX:
1494 case CMD_IOCB_RCV_ELS64_CX:
1495 case CMD_IOCB_RCV_CONT64_CX:
1496 case CMD_IOCB_RET_XRI64_CX:
1497 type = LPFC_UNSOL_IOCB;
1499 case CMD_IOCB_XMIT_MSEQ64_CR:
1500 case CMD_IOCB_XMIT_MSEQ64_CX:
1501 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1502 case CMD_IOCB_RCV_ELS_LIST64_CX:
1503 case CMD_IOCB_CLOSE_EXTENDED_CN:
1504 case CMD_IOCB_ABORT_EXTENDED_CN:
1505 case CMD_IOCB_RET_HBQE64_CN:
1506 case CMD_IOCB_FCP_IBIDIR64_CR:
1507 case CMD_IOCB_FCP_IBIDIR64_CX:
1508 case CMD_IOCB_FCP_ITASKMGT64_CX:
1509 case CMD_IOCB_LOGENTRY_CN:
1510 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1511 printk("%s - Unhandled SLI-3 Command x%x\n",
1512 __func__, iocb_cmnd);
1513 type = LPFC_UNKNOWN_IOCB;
1516 type = LPFC_UNKNOWN_IOCB;
1524 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1525 * @phba: Pointer to HBA context object.
1527 * This function is called from SLI initialization code
1528 * to configure every ring of the HBA's SLI interface. The
1529 * caller is not required to hold any lock. This function issues
1530 * a config_ring mailbox command for each ring.
1531 * This function returns zero if successful else returns a negative
1535 lpfc_sli_ring_map(struct lpfc_hba *phba)
1537 struct lpfc_sli *psli = &phba->sli;
1542 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1546 phba->link_state = LPFC_INIT_MBX_CMDS;
1547 for (i = 0; i < psli->num_rings; i++) {
1548 lpfc_config_ring(phba, i, pmb);
1549 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1550 if (rc != MBX_SUCCESS) {
1551 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1552 "0446 Adapter failed to init (%d), "
1553 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1555 rc, pmbox->mbxCommand,
1556 pmbox->mbxStatus, i);
1557 phba->link_state = LPFC_HBA_ERROR;
1562 mempool_free(pmb, phba->mbox_mem_pool);
1567 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1568 * @phba: Pointer to HBA context object.
1569 * @pring: Pointer to driver SLI ring object.
1570 * @piocb: Pointer to the driver iocb object.
1572 * The driver calls this function with the hbalock held for SLI3 ports or
1573 * the ring lock held for SLI4 ports. The function adds the
1574 * new iocb to txcmplq of the given ring. This function always returns
1575 * 0. If this function is called for ELS ring, this function checks if
1576 * there is a vport associated with the ELS command. This function also
1577 * starts els_tmofunc timer if this is an ELS command.
1580 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1581 struct lpfc_iocbq *piocb)
1583 if (phba->sli_rev == LPFC_SLI_REV4)
1584 lockdep_assert_held(&pring->ring_lock);
1586 lockdep_assert_held(&phba->hbalock);
1590 list_add_tail(&piocb->list, &pring->txcmplq);
1591 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1592 pring->txcmplq_cnt++;
1594 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1595 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1596 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1597 BUG_ON(!piocb->vport);
1598 if (!(piocb->vport->load_flag & FC_UNLOADING))
1599 mod_timer(&piocb->vport->els_tmofunc,
1601 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1608 * lpfc_sli_ringtx_get - Get first element of the txq
1609 * @phba: Pointer to HBA context object.
1610 * @pring: Pointer to driver SLI ring object.
1612 * This function is called with hbalock held to get next
1613 * iocb in txq of the given ring. If there is any iocb in
1614 * the txq, the function returns first iocb in the list after
1615 * removing the iocb from the list, else it returns NULL.
1618 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1620 struct lpfc_iocbq *cmd_iocb;
1622 lockdep_assert_held(&phba->hbalock);
1624 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1629 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1630 * @phba: Pointer to HBA context object.
1631 * @pring: Pointer to driver SLI ring object.
1633 * This function is called with hbalock held and the caller must post the
1634 * iocb without releasing the lock. If the caller releases the lock,
1635 * iocb slot returned by the function is not guaranteed to be available.
1636 * The function returns pointer to the next available iocb slot if there
1637 * is available slot in the ring, else it returns NULL.
1638 * If the get index of the ring is ahead of the put index, the function
1639 * will post an error attention event to the worker thread to take the
1640 * HBA to offline state.
1643 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1645 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1646 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
1648 lockdep_assert_held(&phba->hbalock);
1650 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
1651 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
1652 pring->sli.sli3.next_cmdidx = 0;
1654 if (unlikely(pring->sli.sli3.local_getidx ==
1655 pring->sli.sli3.next_cmdidx)) {
1657 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
1659 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
1660 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1661 "0315 Ring %d issue: portCmdGet %d "
1662 "is bigger than cmd ring %d\n",
1664 pring->sli.sli3.local_getidx,
1667 phba->link_state = LPFC_HBA_ERROR;
1669 * All error attention handlers are posted to
1672 phba->work_ha |= HA_ERATT;
1673 phba->work_hs = HS_FFER3;
1675 lpfc_worker_wake_up(phba);
1680 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
1684 return lpfc_cmd_iocb(phba, pring);
1688 * lpfc_sli_next_iotag - Get an iotag for the iocb
1689 * @phba: Pointer to HBA context object.
1690 * @iocbq: Pointer to driver iocb object.
1692 * This function gets an iotag for the iocb. If there is no unused iotag and
1693 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1694 * array and assigns a new iotag.
1695 * The function returns the allocated iotag if successful, else returns zero.
1696 * Zero is not a valid iotag.
1697 * The caller is not required to hold any lock.
1700 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1702 struct lpfc_iocbq **new_arr;
1703 struct lpfc_iocbq **old_arr;
1705 struct lpfc_sli *psli = &phba->sli;
1708 spin_lock_irq(&phba->hbalock);
1709 iotag = psli->last_iotag;
1710 if(++iotag < psli->iocbq_lookup_len) {
1711 psli->last_iotag = iotag;
1712 psli->iocbq_lookup[iotag] = iocbq;
1713 spin_unlock_irq(&phba->hbalock);
1714 iocbq->iotag = iotag;
1716 } else if (psli->iocbq_lookup_len < (0xffff
1717 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1718 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1719 spin_unlock_irq(&phba->hbalock);
1720 new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
1723 spin_lock_irq(&phba->hbalock);
1724 old_arr = psli->iocbq_lookup;
1725 if (new_len <= psli->iocbq_lookup_len) {
1726 /* highly unprobable case */
1728 iotag = psli->last_iotag;
1729 if(++iotag < psli->iocbq_lookup_len) {
1730 psli->last_iotag = iotag;
1731 psli->iocbq_lookup[iotag] = iocbq;
1732 spin_unlock_irq(&phba->hbalock);
1733 iocbq->iotag = iotag;
1736 spin_unlock_irq(&phba->hbalock);
1739 if (psli->iocbq_lookup)
1740 memcpy(new_arr, old_arr,
1741 ((psli->last_iotag + 1) *
1742 sizeof (struct lpfc_iocbq *)));
1743 psli->iocbq_lookup = new_arr;
1744 psli->iocbq_lookup_len = new_len;
1745 psli->last_iotag = iotag;
1746 psli->iocbq_lookup[iotag] = iocbq;
1747 spin_unlock_irq(&phba->hbalock);
1748 iocbq->iotag = iotag;
1753 spin_unlock_irq(&phba->hbalock);
1755 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1756 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1763 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1764 * @phba: Pointer to HBA context object.
1765 * @pring: Pointer to driver SLI ring object.
1766 * @iocb: Pointer to iocb slot in the ring.
1767 * @nextiocb: Pointer to driver iocb object which need to be
1768 * posted to firmware.
1770 * This function is called with hbalock held to post a new iocb to
1771 * the firmware. This function copies the new iocb to ring iocb slot and
1772 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1773 * a completion call back for this iocb else the function will free the
1777 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1778 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1780 lockdep_assert_held(&phba->hbalock);
1784 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1787 if (pring->ringno == LPFC_ELS_RING) {
1788 lpfc_debugfs_slow_ring_trc(phba,
1789 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1790 *(((uint32_t *) &nextiocb->iocb) + 4),
1791 *(((uint32_t *) &nextiocb->iocb) + 6),
1792 *(((uint32_t *) &nextiocb->iocb) + 7));
1796 * Issue iocb command to adapter
1798 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1800 pring->stats.iocb_cmd++;
1803 * If there is no completion routine to call, we can release the
1804 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1805 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1807 if (nextiocb->iocb_cmpl)
1808 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1810 __lpfc_sli_release_iocbq(phba, nextiocb);
1813 * Let the HBA know what IOCB slot will be the next one the
1814 * driver will put a command into.
1816 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
1817 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1821 * lpfc_sli_update_full_ring - Update the chip attention register
1822 * @phba: Pointer to HBA context object.
1823 * @pring: Pointer to driver SLI ring object.
1825 * The caller is not required to hold any lock for calling this function.
1826 * This function updates the chip attention bits for the ring to inform firmware
1827 * that there are pending work to be done for this ring and requests an
1828 * interrupt when there is space available in the ring. This function is
1829 * called when the driver is unable to post more iocbs to the ring due
1830 * to unavailability of space in the ring.
1833 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1835 int ringno = pring->ringno;
1837 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1842 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1843 * The HBA will tell us when an IOCB entry is available.
1845 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1846 readl(phba->CAregaddr); /* flush */
1848 pring->stats.iocb_cmd_full++;
1852 * lpfc_sli_update_ring - Update chip attention register
1853 * @phba: Pointer to HBA context object.
1854 * @pring: Pointer to driver SLI ring object.
1856 * This function updates the chip attention register bit for the
1857 * given ring to inform HBA that there is more work to be done
1858 * in this ring. The caller is not required to hold any lock.
1861 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1863 int ringno = pring->ringno;
1866 * Tell the HBA that there is work to do in this ring.
1868 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1870 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1871 readl(phba->CAregaddr); /* flush */
1876 * lpfc_sli_resume_iocb - Process iocbs in the txq
1877 * @phba: Pointer to HBA context object.
1878 * @pring: Pointer to driver SLI ring object.
1880 * This function is called with hbalock held to post pending iocbs
1881 * in the txq to the firmware. This function is called when driver
1882 * detects space available in the ring.
1885 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1888 struct lpfc_iocbq *nextiocb;
1890 lockdep_assert_held(&phba->hbalock);
1894 * (a) there is anything on the txq to send
1896 * (c) link attention events can be processed (fcp ring only)
1897 * (d) IOCB processing is not blocked by the outstanding mbox command.
1900 if (lpfc_is_link_up(phba) &&
1901 (!list_empty(&pring->txq)) &&
1902 (pring->ringno != LPFC_FCP_RING ||
1903 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1905 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1906 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1907 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1910 lpfc_sli_update_ring(phba, pring);
1912 lpfc_sli_update_full_ring(phba, pring);
1919 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1920 * @phba: Pointer to HBA context object.
1921 * @hbqno: HBQ number.
1923 * This function is called with hbalock held to get the next
1924 * available slot for the given HBQ. If there is free slot
1925 * available for the HBQ it will return pointer to the next available
1926 * HBQ entry else it will return NULL.
1928 static struct lpfc_hbq_entry *
1929 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1931 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1933 lockdep_assert_held(&phba->hbalock);
1935 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1936 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1937 hbqp->next_hbqPutIdx = 0;
1939 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1940 uint32_t raw_index = phba->hbq_get[hbqno];
1941 uint32_t getidx = le32_to_cpu(raw_index);
1943 hbqp->local_hbqGetIdx = getidx;
1945 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1946 lpfc_printf_log(phba, KERN_ERR,
1947 LOG_SLI | LOG_VPORT,
1948 "1802 HBQ %d: local_hbqGetIdx "
1949 "%u is > than hbqp->entry_count %u\n",
1950 hbqno, hbqp->local_hbqGetIdx,
1953 phba->link_state = LPFC_HBA_ERROR;
1957 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1961 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1966 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1967 * @phba: Pointer to HBA context object.
1969 * This function is called with no lock held to free all the
1970 * hbq buffers while uninitializing the SLI interface. It also
1971 * frees the HBQ buffers returned by the firmware but not yet
1972 * processed by the upper layers.
1975 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1977 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1978 struct hbq_dmabuf *hbq_buf;
1979 unsigned long flags;
1982 hbq_count = lpfc_sli_hbq_count();
1983 /* Return all memory used by all HBQs */
1984 spin_lock_irqsave(&phba->hbalock, flags);
1985 for (i = 0; i < hbq_count; ++i) {
1986 list_for_each_entry_safe(dmabuf, next_dmabuf,
1987 &phba->hbqs[i].hbq_buffer_list, list) {
1988 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
1989 list_del(&hbq_buf->dbuf.list);
1990 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
1992 phba->hbqs[i].buffer_count = 0;
1995 /* Mark the HBQs not in use */
1996 phba->hbq_in_use = 0;
1997 spin_unlock_irqrestore(&phba->hbalock, flags);
2001 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
2002 * @phba: Pointer to HBA context object.
2003 * @hbqno: HBQ number.
2004 * @hbq_buf: Pointer to HBQ buffer.
2006 * This function is called with the hbalock held to post a
2007 * hbq buffer to the firmware. If the function finds an empty
2008 * slot in the HBQ, it will post the buffer. The function will return
2009 * pointer to the hbq entry if it successfully post the buffer
2010 * else it will return NULL.
2013 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
2014 struct hbq_dmabuf *hbq_buf)
2016 lockdep_assert_held(&phba->hbalock);
2017 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
2021 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
2022 * @phba: Pointer to HBA context object.
2023 * @hbqno: HBQ number.
2024 * @hbq_buf: Pointer to HBQ buffer.
2026 * This function is called with the hbalock held to post a hbq buffer to the
2027 * firmware. If the function finds an empty slot in the HBQ, it will post the
2028 * buffer and place it on the hbq_buffer_list. The function will return zero if
2029 * it successfully post the buffer else it will return an error.
2032 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
2033 struct hbq_dmabuf *hbq_buf)
2035 struct lpfc_hbq_entry *hbqe;
2036 dma_addr_t physaddr = hbq_buf->dbuf.phys;
2038 lockdep_assert_held(&phba->hbalock);
2039 /* Get next HBQ entry slot to use */
2040 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
2042 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2044 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
2045 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
2046 hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
2047 hbqe->bde.tus.f.bdeFlags = 0;
2048 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
2049 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
2051 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
2052 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
2054 readl(phba->hbq_put + hbqno);
2055 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
2062 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
2063 * @phba: Pointer to HBA context object.
2064 * @hbqno: HBQ number.
2065 * @hbq_buf: Pointer to HBQ buffer.
2067 * This function is called with the hbalock held to post an RQE to the SLI4
2068 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
2069 * the hbq_buffer_list and return zero, otherwise it will return an error.
2072 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
2073 struct hbq_dmabuf *hbq_buf)
2076 struct lpfc_rqe hrqe;
2077 struct lpfc_rqe drqe;
2078 struct lpfc_queue *hrq;
2079 struct lpfc_queue *drq;
2081 if (hbqno != LPFC_ELS_HBQ)
2083 hrq = phba->sli4_hba.hdr_rq;
2084 drq = phba->sli4_hba.dat_rq;
2086 lockdep_assert_held(&phba->hbalock);
2087 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
2088 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
2089 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
2090 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
2091 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
2094 hbq_buf->tag = (rc | (hbqno << 16));
2095 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
2099 /* HBQ for ELS and CT traffic. */
2100 static struct lpfc_hbq_init lpfc_els_hbq = {
2105 .ring_mask = (1 << LPFC_ELS_RING),
2112 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
2117 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
2118 * @phba: Pointer to HBA context object.
2119 * @hbqno: HBQ number.
2120 * @count: Number of HBQ buffers to be posted.
2122 * This function is called with no lock held to post more hbq buffers to the
2123 * given HBQ. The function returns the number of HBQ buffers successfully
2127 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
2129 uint32_t i, posted = 0;
2130 unsigned long flags;
2131 struct hbq_dmabuf *hbq_buffer;
2132 LIST_HEAD(hbq_buf_list);
2133 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
2136 if ((phba->hbqs[hbqno].buffer_count + count) >
2137 lpfc_hbq_defs[hbqno]->entry_count)
2138 count = lpfc_hbq_defs[hbqno]->entry_count -
2139 phba->hbqs[hbqno].buffer_count;
2142 /* Allocate HBQ entries */
2143 for (i = 0; i < count; i++) {
2144 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
2147 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
2149 /* Check whether HBQ is still in use */
2150 spin_lock_irqsave(&phba->hbalock, flags);
2151 if (!phba->hbq_in_use)
2153 while (!list_empty(&hbq_buf_list)) {
2154 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2156 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
2158 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
2159 phba->hbqs[hbqno].buffer_count++;
2162 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2164 spin_unlock_irqrestore(&phba->hbalock, flags);
2167 spin_unlock_irqrestore(&phba->hbalock, flags);
2168 while (!list_empty(&hbq_buf_list)) {
2169 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2171 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2177 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
2178 * @phba: Pointer to HBA context object.
2181 * This function posts more buffers to the HBQ. This function
2182 * is called with no lock held. The function returns the number of HBQ entries
2183 * successfully allocated.
2186 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
2188 if (phba->sli_rev == LPFC_SLI_REV4)
2191 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2192 lpfc_hbq_defs[qno]->add_count);
2196 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2197 * @phba: Pointer to HBA context object.
2198 * @qno: HBQ queue number.
2200 * This function is called from SLI initialization code path with
2201 * no lock held to post initial HBQ buffers to firmware. The
2202 * function returns the number of HBQ entries successfully allocated.
2205 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
2207 if (phba->sli_rev == LPFC_SLI_REV4)
2208 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2209 lpfc_hbq_defs[qno]->entry_count);
2211 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2212 lpfc_hbq_defs[qno]->init_count);
2216 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2217 * @phba: Pointer to HBA context object.
2218 * @hbqno: HBQ number.
2220 * This function removes the first hbq buffer on an hbq list and returns a
2221 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2223 static struct hbq_dmabuf *
2224 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
2226 struct lpfc_dmabuf *d_buf;
2228 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
2231 return container_of(d_buf, struct hbq_dmabuf, dbuf);
2235 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2236 * @phba: Pointer to HBA context object.
2237 * @hbqno: HBQ number.
2239 * This function removes the first RQ buffer on an RQ buffer list and returns a
2240 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2242 static struct rqb_dmabuf *
2243 lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
2245 struct lpfc_dmabuf *h_buf;
2246 struct lpfc_rqb *rqbp;
2249 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
2250 struct lpfc_dmabuf, list);
2253 rqbp->buffer_count--;
2254 return container_of(h_buf, struct rqb_dmabuf, hbuf);
2258 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2259 * @phba: Pointer to HBA context object.
2260 * @tag: Tag of the hbq buffer.
2262 * This function searches for the hbq buffer associated with the given tag in
2263 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2264 * otherwise it returns NULL.
2266 static struct hbq_dmabuf *
2267 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
2269 struct lpfc_dmabuf *d_buf;
2270 struct hbq_dmabuf *hbq_buf;
2274 if (hbqno >= LPFC_MAX_HBQS)
2277 spin_lock_irq(&phba->hbalock);
2278 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
2279 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2280 if (hbq_buf->tag == tag) {
2281 spin_unlock_irq(&phba->hbalock);
2285 spin_unlock_irq(&phba->hbalock);
2286 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
2287 "1803 Bad hbq tag. Data: x%x x%x\n",
2288 tag, phba->hbqs[tag >> 16].buffer_count);
2293 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2294 * @phba: Pointer to HBA context object.
2295 * @hbq_buffer: Pointer to HBQ buffer.
2297 * This function is called with hbalock. This function gives back
2298 * the hbq buffer to firmware. If the HBQ does not have space to
2299 * post the buffer, it will free the buffer.
2302 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2307 hbqno = hbq_buffer->tag >> 16;
2308 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2309 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2314 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2315 * @mbxCommand: mailbox command code.
2317 * This function is called by the mailbox event handler function to verify
2318 * that the completed mailbox command is a legitimate mailbox command. If the
2319 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2320 * and the mailbox event handler will take the HBA offline.
2323 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2327 switch (mbxCommand) {
2331 case MBX_WRITE_VPARMS:
2332 case MBX_RUN_BIU_DIAG:
2335 case MBX_CONFIG_LINK:
2336 case MBX_CONFIG_RING:
2337 case MBX_RESET_RING:
2338 case MBX_READ_CONFIG:
2339 case MBX_READ_RCONFIG:
2340 case MBX_READ_SPARM:
2341 case MBX_READ_STATUS:
2345 case MBX_READ_LNK_STAT:
2347 case MBX_UNREG_LOGIN:
2349 case MBX_DUMP_MEMORY:
2350 case MBX_DUMP_CONTEXT:
2353 case MBX_UPDATE_CFG:
2355 case MBX_DEL_LD_ENTRY:
2356 case MBX_RUN_PROGRAM:
2358 case MBX_SET_VARIABLE:
2359 case MBX_UNREG_D_ID:
2360 case MBX_KILL_BOARD:
2361 case MBX_CONFIG_FARP:
2364 case MBX_RUN_BIU_DIAG64:
2365 case MBX_CONFIG_PORT:
2366 case MBX_READ_SPARM64:
2367 case MBX_READ_RPI64:
2368 case MBX_REG_LOGIN64:
2369 case MBX_READ_TOPOLOGY:
2372 case MBX_LOAD_EXP_ROM:
2373 case MBX_ASYNCEVT_ENABLE:
2377 case MBX_PORT_CAPABILITIES:
2378 case MBX_PORT_IOV_CONTROL:
2379 case MBX_SLI4_CONFIG:
2380 case MBX_SLI4_REQ_FTRS:
2382 case MBX_UNREG_FCFI:
2387 case MBX_RESUME_RPI:
2388 case MBX_READ_EVENT_LOG_STATUS:
2389 case MBX_READ_EVENT_LOG:
2390 case MBX_SECURITY_MGMT:
2392 case MBX_ACCESS_VDATA:
2403 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2404 * @phba: Pointer to HBA context object.
2405 * @pmboxq: Pointer to mailbox command.
2407 * This is completion handler function for mailbox commands issued from
2408 * lpfc_sli_issue_mbox_wait function. This function is called by the
2409 * mailbox event handler function with no lock held. This function
2410 * will wake up thread waiting on the wait queue pointed by context1
2414 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2416 unsigned long drvr_flag;
2417 struct completion *pmbox_done;
2420 * If pmbox_done is empty, the driver thread gave up waiting and
2421 * continued running.
2423 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2424 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2425 pmbox_done = (struct completion *)pmboxq->context3;
2427 complete(pmbox_done);
2428 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2433 __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2435 unsigned long iflags;
2437 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
2438 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
2439 spin_lock_irqsave(&vport->phba->ndlp_lock, iflags);
2440 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
2441 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
2442 spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags);
2444 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2448 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2449 * @phba: Pointer to HBA context object.
2450 * @pmb: Pointer to mailbox object.
2452 * This function is the default mailbox completion handler. It
2453 * frees the memory resources associated with the completed mailbox
2454 * command. If the completed command is a REG_LOGIN mailbox command,
2455 * this function will issue a UREG_LOGIN to re-claim the RPI.
2458 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2460 struct lpfc_vport *vport = pmb->vport;
2461 struct lpfc_dmabuf *mp;
2462 struct lpfc_nodelist *ndlp;
2463 struct Scsi_Host *shost;
2467 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
2470 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2475 * If a REG_LOGIN succeeded after node is destroyed or node
2476 * is in re-discovery driver need to cleanup the RPI.
2478 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2479 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2480 !pmb->u.mb.mbxStatus) {
2481 rpi = pmb->u.mb.un.varWords[0];
2482 vpi = pmb->u.mb.un.varRegLogin.vpi;
2483 lpfc_unreg_login(phba, vpi, rpi, pmb);
2485 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2486 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2487 if (rc != MBX_NOT_FINISHED)
2491 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2492 !(phba->pport->load_flag & FC_UNLOADING) &&
2493 !pmb->u.mb.mbxStatus) {
2494 shost = lpfc_shost_from_vport(vport);
2495 spin_lock_irq(shost->host_lock);
2496 vport->vpi_state |= LPFC_VPI_REGISTERED;
2497 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2498 spin_unlock_irq(shost->host_lock);
2501 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2502 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2504 pmb->ctx_buf = NULL;
2505 pmb->ctx_ndlp = NULL;
2508 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2509 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2511 /* Check to see if there are any deferred events to process */
2515 KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
2516 "1438 UNREG cmpl deferred mbox x%x "
2517 "on NPort x%x Data: x%x x%x %px\n",
2518 ndlp->nlp_rpi, ndlp->nlp_DID,
2519 ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp);
2521 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2522 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
2523 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2524 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
2525 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2527 __lpfc_sli_rpi_release(vport, ndlp);
2529 pmb->ctx_ndlp = NULL;
2533 /* Check security permission status on INIT_LINK mailbox command */
2534 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2535 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2536 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2537 "2860 SLI authentication is required "
2538 "for INIT_LINK but has not done yet\n");
2540 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2541 lpfc_sli4_mbox_cmd_free(phba, pmb);
2543 mempool_free(pmb, phba->mbox_mem_pool);
2546 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2547 * @phba: Pointer to HBA context object.
2548 * @pmb: Pointer to mailbox object.
2550 * This function is the unreg rpi mailbox completion handler. It
2551 * frees the memory resources associated with the completed mailbox
2552 * command. An additional refrenece is put on the ndlp to prevent
2553 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2554 * the unreg mailbox command completes, this routine puts the
2559 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2561 struct lpfc_vport *vport = pmb->vport;
2562 struct lpfc_nodelist *ndlp;
2564 ndlp = pmb->ctx_ndlp;
2565 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2566 if (phba->sli_rev == LPFC_SLI_REV4 &&
2567 (bf_get(lpfc_sli_intf_if_type,
2568 &phba->sli4_hba.sli_intf) >=
2569 LPFC_SLI_INTF_IF_TYPE_2)) {
2572 vport, KERN_INFO, LOG_MBOX | LOG_SLI,
2573 "0010 UNREG_LOGIN vpi:%x "
2574 "rpi:%x DID:%x defer x%x flg x%x "
2576 vport->vpi, ndlp->nlp_rpi,
2577 ndlp->nlp_DID, ndlp->nlp_defer_did,
2579 ndlp->nlp_usg_map, ndlp);
2580 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2583 /* Check to see if there are any deferred
2586 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2587 (ndlp->nlp_defer_did !=
2588 NLP_EVT_NOTHING_PENDING)) {
2590 vport, KERN_INFO, LOG_DISCOVERY,
2591 "4111 UNREG cmpl deferred "
2593 "NPort x%x Data: x%x x%px\n",
2594 ndlp->nlp_rpi, ndlp->nlp_DID,
2595 ndlp->nlp_defer_did, ndlp);
2596 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2597 ndlp->nlp_defer_did =
2598 NLP_EVT_NOTHING_PENDING;
2599 lpfc_issue_els_plogi(
2600 vport, ndlp->nlp_DID, 0);
2602 __lpfc_sli_rpi_release(vport, ndlp);
2608 mempool_free(pmb, phba->mbox_mem_pool);
2612 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2613 * @phba: Pointer to HBA context object.
2615 * This function is called with no lock held. This function processes all
2616 * the completed mailbox commands and gives it to upper layers. The interrupt
2617 * service routine processes mailbox completion interrupt and adds completed
2618 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2619 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2620 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2621 * function returns the mailbox commands to the upper layer by calling the
2622 * completion handler function of each mailbox.
2625 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
2632 phba->sli.slistat.mbox_event++;
2634 /* Get all completed mailboxe buffers into the cmplq */
2635 spin_lock_irq(&phba->hbalock);
2636 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2637 spin_unlock_irq(&phba->hbalock);
2639 /* Get a Mailbox buffer to setup mailbox commands for callback */
2641 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2647 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2649 lpfc_debugfs_disc_trc(pmb->vport,
2650 LPFC_DISC_TRC_MBOX_VPORT,
2651 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2652 (uint32_t)pmbox->mbxCommand,
2653 pmbox->un.varWords[0],
2654 pmbox->un.varWords[1]);
2657 lpfc_debugfs_disc_trc(phba->pport,
2659 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2660 (uint32_t)pmbox->mbxCommand,
2661 pmbox->un.varWords[0],
2662 pmbox->un.varWords[1]);
2667 * It is a fatal error if unknown mbox command completion.
2669 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2671 /* Unknown mailbox command compl */
2672 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2673 "(%d):0323 Unknown Mailbox command "
2674 "x%x (x%x/x%x) Cmpl\n",
2675 pmb->vport ? pmb->vport->vpi : 0,
2677 lpfc_sli_config_mbox_subsys_get(phba,
2679 lpfc_sli_config_mbox_opcode_get(phba,
2681 phba->link_state = LPFC_HBA_ERROR;
2682 phba->work_hs = HS_FFER3;
2683 lpfc_handle_eratt(phba);
2687 if (pmbox->mbxStatus) {
2688 phba->sli.slistat.mbox_stat_err++;
2689 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2690 /* Mbox cmd cmpl error - RETRYing */
2691 lpfc_printf_log(phba, KERN_INFO,
2693 "(%d):0305 Mbox cmd cmpl "
2694 "error - RETRYing Data: x%x "
2695 "(x%x/x%x) x%x x%x x%x\n",
2696 pmb->vport ? pmb->vport->vpi : 0,
2698 lpfc_sli_config_mbox_subsys_get(phba,
2700 lpfc_sli_config_mbox_opcode_get(phba,
2703 pmbox->un.varWords[0],
2704 pmb->vport->port_state);
2705 pmbox->mbxStatus = 0;
2706 pmbox->mbxOwner = OWN_HOST;
2707 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2708 if (rc != MBX_NOT_FINISHED)
2713 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2714 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2715 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
2716 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2718 pmb->vport ? pmb->vport->vpi : 0,
2720 lpfc_sli_config_mbox_subsys_get(phba, pmb),
2721 lpfc_sli_config_mbox_opcode_get(phba, pmb),
2723 *((uint32_t *) pmbox),
2724 pmbox->un.varWords[0],
2725 pmbox->un.varWords[1],
2726 pmbox->un.varWords[2],
2727 pmbox->un.varWords[3],
2728 pmbox->un.varWords[4],
2729 pmbox->un.varWords[5],
2730 pmbox->un.varWords[6],
2731 pmbox->un.varWords[7],
2732 pmbox->un.varWords[8],
2733 pmbox->un.varWords[9],
2734 pmbox->un.varWords[10]);
2737 pmb->mbox_cmpl(phba,pmb);
2743 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2744 * @phba: Pointer to HBA context object.
2745 * @pring: Pointer to driver SLI ring object.
2748 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2749 * is set in the tag the buffer is posted for a particular exchange,
2750 * the function will return the buffer without replacing the buffer.
2751 * If the buffer is for unsolicited ELS or CT traffic, this function
2752 * returns the buffer and also posts another buffer to the firmware.
2754 static struct lpfc_dmabuf *
2755 lpfc_sli_get_buff(struct lpfc_hba *phba,
2756 struct lpfc_sli_ring *pring,
2759 struct hbq_dmabuf *hbq_entry;
2761 if (tag & QUE_BUFTAG_BIT)
2762 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
2763 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2766 return &hbq_entry->dbuf;
2770 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2771 * @phba: Pointer to HBA context object.
2772 * @pring: Pointer to driver SLI ring object.
2773 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2774 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2775 * @fch_type: the type for the first frame of the sequence.
2777 * This function is called with no lock held. This function uses the r_ctl and
2778 * type of the received sequence to find the correct callback function to call
2779 * to process the sequence.
2782 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2783 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
2790 lpfc_nvmet_unsol_ls_event(phba, pring, saveq);
2796 /* unSolicited Responses */
2797 if (pring->prt[0].profile) {
2798 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
2799 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
2803 /* We must search, based on rctl / type
2804 for the right routine */
2805 for (i = 0; i < pring->num_mask; i++) {
2806 if ((pring->prt[i].rctl == fch_r_ctl) &&
2807 (pring->prt[i].type == fch_type)) {
2808 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
2809 (pring->prt[i].lpfc_sli_rcv_unsol_event)
2810 (phba, pring, saveq);
2818 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2819 * @phba: Pointer to HBA context object.
2820 * @pring: Pointer to driver SLI ring object.
2821 * @saveq: Pointer to the unsolicited iocb.
2823 * This function is called with no lock held by the ring event handler
2824 * when there is an unsolicited iocb posted to the response ring by the
2825 * firmware. This function gets the buffer associated with the iocbs
2826 * and calls the event handler for the ring. This function handles both
2827 * qring buffers and hbq buffers.
2828 * When the function returns 1 the caller can free the iocb object otherwise
2829 * upper layer functions will free the iocb objects.
2832 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2833 struct lpfc_iocbq *saveq)
2837 uint32_t Rctl, Type;
2838 struct lpfc_iocbq *iocbq;
2839 struct lpfc_dmabuf *dmzbuf;
2841 irsp = &(saveq->iocb);
2843 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
2844 if (pring->lpfc_sli_rcv_async_status)
2845 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
2847 lpfc_printf_log(phba,
2850 "0316 Ring %d handler: unexpected "
2851 "ASYNC_STATUS iocb received evt_code "
2854 irsp->un.asyncstat.evt_code);
2858 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
2859 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
2860 if (irsp->ulpBdeCount > 0) {
2861 dmzbuf = lpfc_sli_get_buff(phba, pring,
2862 irsp->un.ulpWord[3]);
2863 lpfc_in_buf_free(phba, dmzbuf);
2866 if (irsp->ulpBdeCount > 1) {
2867 dmzbuf = lpfc_sli_get_buff(phba, pring,
2868 irsp->unsli3.sli3Words[3]);
2869 lpfc_in_buf_free(phba, dmzbuf);
2872 if (irsp->ulpBdeCount > 2) {
2873 dmzbuf = lpfc_sli_get_buff(phba, pring,
2874 irsp->unsli3.sli3Words[7]);
2875 lpfc_in_buf_free(phba, dmzbuf);
2881 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2882 if (irsp->ulpBdeCount != 0) {
2883 saveq->context2 = lpfc_sli_get_buff(phba, pring,
2884 irsp->un.ulpWord[3]);
2885 if (!saveq->context2)
2886 lpfc_printf_log(phba,
2889 "0341 Ring %d Cannot find buffer for "
2890 "an unsolicited iocb. tag 0x%x\n",
2892 irsp->un.ulpWord[3]);
2894 if (irsp->ulpBdeCount == 2) {
2895 saveq->context3 = lpfc_sli_get_buff(phba, pring,
2896 irsp->unsli3.sli3Words[7]);
2897 if (!saveq->context3)
2898 lpfc_printf_log(phba,
2901 "0342 Ring %d Cannot find buffer for an"
2902 " unsolicited iocb. tag 0x%x\n",
2904 irsp->unsli3.sli3Words[7]);
2906 list_for_each_entry(iocbq, &saveq->list, list) {
2907 irsp = &(iocbq->iocb);
2908 if (irsp->ulpBdeCount != 0) {
2909 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
2910 irsp->un.ulpWord[3]);
2911 if (!iocbq->context2)
2912 lpfc_printf_log(phba,
2915 "0343 Ring %d Cannot find "
2916 "buffer for an unsolicited iocb"
2917 ". tag 0x%x\n", pring->ringno,
2918 irsp->un.ulpWord[3]);
2920 if (irsp->ulpBdeCount == 2) {
2921 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
2922 irsp->unsli3.sli3Words[7]);
2923 if (!iocbq->context3)
2924 lpfc_printf_log(phba,
2927 "0344 Ring %d Cannot find "
2928 "buffer for an unsolicited "
2931 irsp->unsli3.sli3Words[7]);
2935 if (irsp->ulpBdeCount != 0 &&
2936 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
2937 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
2940 /* search continue save q for same XRI */
2941 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
2942 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
2943 saveq->iocb.unsli3.rcvsli3.ox_id) {
2944 list_add_tail(&saveq->list, &iocbq->list);
2950 list_add_tail(&saveq->clist,
2951 &pring->iocb_continue_saveq);
2952 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
2953 list_del_init(&iocbq->clist);
2955 irsp = &(saveq->iocb);
2959 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
2960 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
2961 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
2962 Rctl = FC_RCTL_ELS_REQ;
2965 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
2966 Rctl = w5p->hcsw.Rctl;
2967 Type = w5p->hcsw.Type;
2969 /* Firmware Workaround */
2970 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
2971 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
2972 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
2973 Rctl = FC_RCTL_ELS_REQ;
2975 w5p->hcsw.Rctl = Rctl;
2976 w5p->hcsw.Type = Type;
2980 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
2981 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2982 "0313 Ring %d handler: unexpected Rctl x%x "
2983 "Type x%x received\n",
2984 pring->ringno, Rctl, Type);
2990 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2991 * @phba: Pointer to HBA context object.
2992 * @pring: Pointer to driver SLI ring object.
2993 * @prspiocb: Pointer to response iocb object.
2995 * This function looks up the iocb_lookup table to get the command iocb
2996 * corresponding to the given response iocb using the iotag of the
2997 * response iocb. The driver calls this function with the hbalock held
2998 * for SLI3 ports or the ring lock held for SLI4 ports.
2999 * This function returns the command iocb object if it finds the command
3000 * iocb else returns NULL.
3002 static struct lpfc_iocbq *
3003 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
3004 struct lpfc_sli_ring *pring,
3005 struct lpfc_iocbq *prspiocb)
3007 struct lpfc_iocbq *cmd_iocb = NULL;
3009 spinlock_t *temp_lock = NULL;
3010 unsigned long iflag = 0;
3012 if (phba->sli_rev == LPFC_SLI_REV4)
3013 temp_lock = &pring->ring_lock;
3015 temp_lock = &phba->hbalock;
3017 spin_lock_irqsave(temp_lock, iflag);
3018 iotag = prspiocb->iocb.ulpIoTag;
3020 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3021 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3022 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3023 /* remove from txcmpl queue list */
3024 list_del_init(&cmd_iocb->list);
3025 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3026 pring->txcmplq_cnt--;
3027 spin_unlock_irqrestore(temp_lock, iflag);
3032 spin_unlock_irqrestore(temp_lock, iflag);
3033 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3034 "0317 iotag x%x is out of "
3035 "range: max iotag x%x wd0 x%x\n",
3036 iotag, phba->sli.last_iotag,
3037 *(((uint32_t *) &prspiocb->iocb) + 7));
3042 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
3043 * @phba: Pointer to HBA context object.
3044 * @pring: Pointer to driver SLI ring object.
3047 * This function looks up the iocb_lookup table to get the command iocb
3048 * corresponding to the given iotag. The driver calls this function with
3049 * the ring lock held because this function is an SLI4 port only helper.
3050 * This function returns the command iocb object if it finds the command
3051 * iocb else returns NULL.
3053 static struct lpfc_iocbq *
3054 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
3055 struct lpfc_sli_ring *pring, uint16_t iotag)
3057 struct lpfc_iocbq *cmd_iocb = NULL;
3058 spinlock_t *temp_lock = NULL;
3059 unsigned long iflag = 0;
3061 if (phba->sli_rev == LPFC_SLI_REV4)
3062 temp_lock = &pring->ring_lock;
3064 temp_lock = &phba->hbalock;
3066 spin_lock_irqsave(temp_lock, iflag);
3067 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3068 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3069 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3070 /* remove from txcmpl queue list */
3071 list_del_init(&cmd_iocb->list);
3072 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3073 pring->txcmplq_cnt--;
3074 spin_unlock_irqrestore(temp_lock, iflag);
3079 spin_unlock_irqrestore(temp_lock, iflag);
3080 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3081 "0372 iotag x%x lookup error: max iotag (x%x) "
3083 iotag, phba->sli.last_iotag,
3084 cmd_iocb ? cmd_iocb->iocb_flag : 0xffff);
3089 * lpfc_sli_process_sol_iocb - process solicited iocb completion
3090 * @phba: Pointer to HBA context object.
3091 * @pring: Pointer to driver SLI ring object.
3092 * @saveq: Pointer to the response iocb to be processed.
3094 * This function is called by the ring event handler for non-fcp
3095 * rings when there is a new response iocb in the response ring.
3096 * The caller is not required to hold any locks. This function
3097 * gets the command iocb associated with the response iocb and
3098 * calls the completion handler for the command iocb. If there
3099 * is no completion handler, the function will free the resources
3100 * associated with command iocb. If the response iocb is for
3101 * an already aborted command iocb, the status of the completion
3102 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
3103 * This function always returns 1.
3106 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3107 struct lpfc_iocbq *saveq)
3109 struct lpfc_iocbq *cmdiocbp;
3111 unsigned long iflag;
3113 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
3115 if (cmdiocbp->iocb_cmpl) {
3117 * If an ELS command failed send an event to mgmt
3120 if (saveq->iocb.ulpStatus &&
3121 (pring->ringno == LPFC_ELS_RING) &&
3122 (cmdiocbp->iocb.ulpCommand ==
3123 CMD_ELS_REQUEST64_CR))
3124 lpfc_send_els_failure_event(phba,
3128 * Post all ELS completions to the worker thread.
3129 * All other are passed to the completion callback.
3131 if (pring->ringno == LPFC_ELS_RING) {
3132 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3133 (cmdiocbp->iocb_flag &
3134 LPFC_DRIVER_ABORTED)) {
3135 spin_lock_irqsave(&phba->hbalock,
3137 cmdiocbp->iocb_flag &=
3138 ~LPFC_DRIVER_ABORTED;
3139 spin_unlock_irqrestore(&phba->hbalock,
3141 saveq->iocb.ulpStatus =
3142 IOSTAT_LOCAL_REJECT;
3143 saveq->iocb.un.ulpWord[4] =
3146 /* Firmware could still be in progress
3147 * of DMAing payload, so don't free data
3148 * buffer till after a hbeat.
3150 spin_lock_irqsave(&phba->hbalock,
3152 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
3153 spin_unlock_irqrestore(&phba->hbalock,
3156 if (phba->sli_rev == LPFC_SLI_REV4) {
3157 if (saveq->iocb_flag &
3158 LPFC_EXCHANGE_BUSY) {
3159 /* Set cmdiocb flag for the
3160 * exchange busy so sgl (xri)
3161 * will not be released until
3162 * the abort xri is received
3166 &phba->hbalock, iflag);
3167 cmdiocbp->iocb_flag |=
3169 spin_unlock_irqrestore(
3170 &phba->hbalock, iflag);
3172 if (cmdiocbp->iocb_flag &
3173 LPFC_DRIVER_ABORTED) {
3175 * Clear LPFC_DRIVER_ABORTED
3176 * bit in case it was driver
3180 &phba->hbalock, iflag);
3181 cmdiocbp->iocb_flag &=
3182 ~LPFC_DRIVER_ABORTED;
3183 spin_unlock_irqrestore(
3184 &phba->hbalock, iflag);
3185 cmdiocbp->iocb.ulpStatus =
3186 IOSTAT_LOCAL_REJECT;
3187 cmdiocbp->iocb.un.ulpWord[4] =
3188 IOERR_ABORT_REQUESTED;
3190 * For SLI4, irsiocb contains
3191 * NO_XRI in sli_xritag, it
3192 * shall not affect releasing
3193 * sgl (xri) process.
3195 saveq->iocb.ulpStatus =
3196 IOSTAT_LOCAL_REJECT;
3197 saveq->iocb.un.ulpWord[4] =
3200 &phba->hbalock, iflag);
3202 LPFC_DELAY_MEM_FREE;
3203 spin_unlock_irqrestore(
3204 &phba->hbalock, iflag);
3208 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
3210 lpfc_sli_release_iocbq(phba, cmdiocbp);
3213 * Unknown initiating command based on the response iotag.
3214 * This could be the case on the ELS ring because of
3217 if (pring->ringno != LPFC_ELS_RING) {
3219 * Ring <ringno> handler: unexpected completion IoTag
3222 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3223 "0322 Ring %d handler: "
3224 "unexpected completion IoTag x%x "
3225 "Data: x%x x%x x%x x%x\n",
3227 saveq->iocb.ulpIoTag,
3228 saveq->iocb.ulpStatus,
3229 saveq->iocb.un.ulpWord[4],
3230 saveq->iocb.ulpCommand,
3231 saveq->iocb.ulpContext);
3239 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
3240 * @phba: Pointer to HBA context object.
3241 * @pring: Pointer to driver SLI ring object.
3243 * This function is called from the iocb ring event handlers when
3244 * put pointer is ahead of the get pointer for a ring. This function signal
3245 * an error attention condition to the worker thread and the worker
3246 * thread will transition the HBA to offline state.
3249 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3251 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3253 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3254 * rsp ring <portRspMax>
3256 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3257 "0312 Ring %d handler: portRspPut %d "
3258 "is bigger than rsp ring %d\n",
3259 pring->ringno, le32_to_cpu(pgp->rspPutInx),
3260 pring->sli.sli3.numRiocb);
3262 phba->link_state = LPFC_HBA_ERROR;
3265 * All error attention handlers are posted to
3268 phba->work_ha |= HA_ERATT;
3269 phba->work_hs = HS_FFER3;
3271 lpfc_worker_wake_up(phba);
3277 * lpfc_poll_eratt - Error attention polling timer timeout handler
3278 * @ptr: Pointer to address of HBA context object.
3280 * This function is invoked by the Error Attention polling timer when the
3281 * timer times out. It will check the SLI Error Attention register for
3282 * possible attention events. If so, it will post an Error Attention event
3283 * and wake up worker thread to process it. Otherwise, it will set up the
3284 * Error Attention polling timer for the next poll.
3286 void lpfc_poll_eratt(struct timer_list *t)
3288 struct lpfc_hba *phba;
3290 uint64_t sli_intr, cnt;
3292 phba = from_timer(phba, t, eratt_poll);
3294 /* Here we will also keep track of interrupts per sec of the hba */
3295 sli_intr = phba->sli.slistat.sli_intr;
3297 if (phba->sli.slistat.sli_prev_intr > sli_intr)
3298 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
3301 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
3303 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3304 do_div(cnt, phba->eratt_poll_interval);
3305 phba->sli.slistat.sli_ips = cnt;
3307 phba->sli.slistat.sli_prev_intr = sli_intr;
3309 /* Check chip HA register for error event */
3310 eratt = lpfc_sli_check_eratt(phba);
3313 /* Tell the worker thread there is work to do */
3314 lpfc_worker_wake_up(phba);
3316 /* Restart the timer for next eratt poll */
3317 mod_timer(&phba->eratt_poll,
3319 msecs_to_jiffies(1000 * phba->eratt_poll_interval));
3325 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3326 * @phba: Pointer to HBA context object.
3327 * @pring: Pointer to driver SLI ring object.
3328 * @mask: Host attention register mask for this ring.
3330 * This function is called from the interrupt context when there is a ring
3331 * event for the fcp ring. The caller does not hold any lock.
3332 * The function processes each response iocb in the response ring until it
3333 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3334 * LE bit set. The function will call the completion handler of the command iocb
3335 * if the response iocb indicates a completion for a command iocb or it is
3336 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3337 * function if this is an unsolicited iocb.
3338 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3339 * to check it explicitly.
3342 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
3343 struct lpfc_sli_ring *pring, uint32_t mask)
3345 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3346 IOCB_t *irsp = NULL;
3347 IOCB_t *entry = NULL;
3348 struct lpfc_iocbq *cmdiocbq = NULL;
3349 struct lpfc_iocbq rspiocbq;
3351 uint32_t portRspPut, portRspMax;
3353 lpfc_iocb_type type;
3354 unsigned long iflag;
3355 uint32_t rsp_cmpl = 0;
3357 spin_lock_irqsave(&phba->hbalock, iflag);
3358 pring->stats.iocb_event++;
3361 * The next available response entry should never exceed the maximum
3362 * entries. If it does, treat it as an adapter hardware error.
3364 portRspMax = pring->sli.sli3.numRiocb;
3365 portRspPut = le32_to_cpu(pgp->rspPutInx);
3366 if (unlikely(portRspPut >= portRspMax)) {
3367 lpfc_sli_rsp_pointers_error(phba, pring);
3368 spin_unlock_irqrestore(&phba->hbalock, iflag);
3371 if (phba->fcp_ring_in_use) {
3372 spin_unlock_irqrestore(&phba->hbalock, iflag);
3375 phba->fcp_ring_in_use = 1;
3378 while (pring->sli.sli3.rspidx != portRspPut) {
3380 * Fetch an entry off the ring and copy it into a local data
3381 * structure. The copy involves a byte-swap since the
3382 * network byte order and pci byte orders are different.
3384 entry = lpfc_resp_iocb(phba, pring);
3385 phba->last_completion_time = jiffies;
3387 if (++pring->sli.sli3.rspidx >= portRspMax)
3388 pring->sli.sli3.rspidx = 0;
3390 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
3391 (uint32_t *) &rspiocbq.iocb,
3392 phba->iocb_rsp_size);
3393 INIT_LIST_HEAD(&(rspiocbq.list));
3394 irsp = &rspiocbq.iocb;
3396 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
3397 pring->stats.iocb_rsp++;
3400 if (unlikely(irsp->ulpStatus)) {
3402 * If resource errors reported from HBA, reduce
3403 * queuedepths of the SCSI device.
3405 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3406 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3407 IOERR_NO_RESOURCES)) {
3408 spin_unlock_irqrestore(&phba->hbalock, iflag);
3409 phba->lpfc_rampdown_queue_depth(phba);
3410 spin_lock_irqsave(&phba->hbalock, iflag);
3413 /* Rsp ring <ringno> error: IOCB */
3414 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3415 "0336 Rsp Ring %d error: IOCB Data: "
3416 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3418 irsp->un.ulpWord[0],
3419 irsp->un.ulpWord[1],
3420 irsp->un.ulpWord[2],
3421 irsp->un.ulpWord[3],
3422 irsp->un.ulpWord[4],
3423 irsp->un.ulpWord[5],
3424 *(uint32_t *)&irsp->un1,
3425 *((uint32_t *)&irsp->un1 + 1));
3429 case LPFC_ABORT_IOCB:
3432 * Idle exchange closed via ABTS from port. No iocb
3433 * resources need to be recovered.
3435 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
3436 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3437 "0333 IOCB cmd 0x%x"
3438 " processed. Skipping"
3444 spin_unlock_irqrestore(&phba->hbalock, iflag);
3445 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3447 spin_lock_irqsave(&phba->hbalock, iflag);
3448 if (unlikely(!cmdiocbq))
3450 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3451 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3452 if (cmdiocbq->iocb_cmpl) {
3453 spin_unlock_irqrestore(&phba->hbalock, iflag);
3454 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
3456 spin_lock_irqsave(&phba->hbalock, iflag);
3459 case LPFC_UNSOL_IOCB:
3460 spin_unlock_irqrestore(&phba->hbalock, iflag);
3461 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
3462 spin_lock_irqsave(&phba->hbalock, iflag);
3465 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3466 char adaptermsg[LPFC_MAX_ADPTMSG];
3467 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3468 memcpy(&adaptermsg[0], (uint8_t *) irsp,
3470 dev_warn(&((phba->pcidev)->dev),
3472 phba->brd_no, adaptermsg);
3474 /* Unknown IOCB command */
3475 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3476 "0334 Unknown IOCB command "
3477 "Data: x%x, x%x x%x x%x x%x\n",
3478 type, irsp->ulpCommand,
3487 * The response IOCB has been processed. Update the ring
3488 * pointer in SLIM. If the port response put pointer has not
3489 * been updated, sync the pgp->rspPutInx and fetch the new port
3490 * response put pointer.
3492 writel(pring->sli.sli3.rspidx,
3493 &phba->host_gp[pring->ringno].rspGetInx);
3495 if (pring->sli.sli3.rspidx == portRspPut)
3496 portRspPut = le32_to_cpu(pgp->rspPutInx);
3499 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
3500 pring->stats.iocb_rsp_full++;
3501 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3502 writel(status, phba->CAregaddr);
3503 readl(phba->CAregaddr);
3505 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3506 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3507 pring->stats.iocb_cmd_empty++;
3509 /* Force update of the local copy of cmdGetInx */
3510 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3511 lpfc_sli_resume_iocb(phba, pring);
3513 if ((pring->lpfc_sli_cmd_available))
3514 (pring->lpfc_sli_cmd_available) (phba, pring);
3518 phba->fcp_ring_in_use = 0;
3519 spin_unlock_irqrestore(&phba->hbalock, iflag);
3524 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3525 * @phba: Pointer to HBA context object.
3526 * @pring: Pointer to driver SLI ring object.
3527 * @rspiocbp: Pointer to driver response IOCB object.
3529 * This function is called from the worker thread when there is a slow-path
3530 * response IOCB to process. This function chains all the response iocbs until
3531 * seeing the iocb with the LE bit set. The function will call
3532 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3533 * completion of a command iocb. The function will call the
3534 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3535 * The function frees the resources or calls the completion handler if this
3536 * iocb is an abort completion. The function returns NULL when the response
3537 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3538 * this function shall chain the iocb on to the iocb_continueq and return the
3539 * response iocb passed in.
3541 static struct lpfc_iocbq *
3542 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3543 struct lpfc_iocbq *rspiocbp)
3545 struct lpfc_iocbq *saveq;
3546 struct lpfc_iocbq *cmdiocbp;
3547 struct lpfc_iocbq *next_iocb;
3548 IOCB_t *irsp = NULL;
3549 uint32_t free_saveq;
3550 uint8_t iocb_cmd_type;
3551 lpfc_iocb_type type;
3552 unsigned long iflag;
3555 spin_lock_irqsave(&phba->hbalock, iflag);
3556 /* First add the response iocb to the countinueq list */
3557 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3558 pring->iocb_continueq_cnt++;
3560 /* Now, determine whether the list is completed for processing */
3561 irsp = &rspiocbp->iocb;
3564 * By default, the driver expects to free all resources
3565 * associated with this iocb completion.
3568 saveq = list_get_first(&pring->iocb_continueq,
3569 struct lpfc_iocbq, list);
3570 irsp = &(saveq->iocb);
3571 list_del_init(&pring->iocb_continueq);
3572 pring->iocb_continueq_cnt = 0;
3574 pring->stats.iocb_rsp++;
3577 * If resource errors reported from HBA, reduce
3578 * queuedepths of the SCSI device.
3580 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3581 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3582 IOERR_NO_RESOURCES)) {
3583 spin_unlock_irqrestore(&phba->hbalock, iflag);
3584 phba->lpfc_rampdown_queue_depth(phba);
3585 spin_lock_irqsave(&phba->hbalock, iflag);
3588 if (irsp->ulpStatus) {
3589 /* Rsp ring <ringno> error: IOCB */
3590 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3591 "0328 Rsp Ring %d error: "
3596 "x%x x%x x%x x%x\n",
3598 irsp->un.ulpWord[0],
3599 irsp->un.ulpWord[1],
3600 irsp->un.ulpWord[2],
3601 irsp->un.ulpWord[3],
3602 irsp->un.ulpWord[4],
3603 irsp->un.ulpWord[5],
3604 *(((uint32_t *) irsp) + 6),
3605 *(((uint32_t *) irsp) + 7),
3606 *(((uint32_t *) irsp) + 8),
3607 *(((uint32_t *) irsp) + 9),
3608 *(((uint32_t *) irsp) + 10),
3609 *(((uint32_t *) irsp) + 11),
3610 *(((uint32_t *) irsp) + 12),
3611 *(((uint32_t *) irsp) + 13),
3612 *(((uint32_t *) irsp) + 14),
3613 *(((uint32_t *) irsp) + 15));
3617 * Fetch the IOCB command type and call the correct completion
3618 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3619 * get freed back to the lpfc_iocb_list by the discovery
3622 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3623 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3626 spin_unlock_irqrestore(&phba->hbalock, iflag);
3627 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3628 spin_lock_irqsave(&phba->hbalock, iflag);
3631 case LPFC_UNSOL_IOCB:
3632 spin_unlock_irqrestore(&phba->hbalock, iflag);
3633 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3634 spin_lock_irqsave(&phba->hbalock, iflag);
3639 case LPFC_ABORT_IOCB:
3641 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) {
3642 spin_unlock_irqrestore(&phba->hbalock, iflag);
3643 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3645 spin_lock_irqsave(&phba->hbalock, iflag);
3648 /* Call the specified completion routine */
3649 if (cmdiocbp->iocb_cmpl) {
3650 spin_unlock_irqrestore(&phba->hbalock,
3652 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3654 spin_lock_irqsave(&phba->hbalock,
3657 __lpfc_sli_release_iocbq(phba,
3662 case LPFC_UNKNOWN_IOCB:
3663 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3664 char adaptermsg[LPFC_MAX_ADPTMSG];
3665 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3666 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3668 dev_warn(&((phba->pcidev)->dev),
3670 phba->brd_no, adaptermsg);
3672 /* Unknown IOCB command */
3673 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3674 "0335 Unknown IOCB "
3675 "command Data: x%x "
3686 list_for_each_entry_safe(rspiocbp, next_iocb,
3687 &saveq->list, list) {
3688 list_del_init(&rspiocbp->list);
3689 __lpfc_sli_release_iocbq(phba, rspiocbp);
3691 __lpfc_sli_release_iocbq(phba, saveq);
3695 spin_unlock_irqrestore(&phba->hbalock, iflag);
3700 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3701 * @phba: Pointer to HBA context object.
3702 * @pring: Pointer to driver SLI ring object.
3703 * @mask: Host attention register mask for this ring.
3705 * This routine wraps the actual slow_ring event process routine from the
3706 * API jump table function pointer from the lpfc_hba struct.
3709 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
3710 struct lpfc_sli_ring *pring, uint32_t mask)
3712 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
3716 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3717 * @phba: Pointer to HBA context object.
3718 * @pring: Pointer to driver SLI ring object.
3719 * @mask: Host attention register mask for this ring.
3721 * This function is called from the worker thread when there is a ring event
3722 * for non-fcp rings. The caller does not hold any lock. The function will
3723 * remove each response iocb in the response ring and calls the handle
3724 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3727 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
3728 struct lpfc_sli_ring *pring, uint32_t mask)
3730 struct lpfc_pgp *pgp;
3732 IOCB_t *irsp = NULL;
3733 struct lpfc_iocbq *rspiocbp = NULL;
3734 uint32_t portRspPut, portRspMax;
3735 unsigned long iflag;
3738 pgp = &phba->port_gp[pring->ringno];
3739 spin_lock_irqsave(&phba->hbalock, iflag);
3740 pring->stats.iocb_event++;
3743 * The next available response entry should never exceed the maximum
3744 * entries. If it does, treat it as an adapter hardware error.
3746 portRspMax = pring->sli.sli3.numRiocb;
3747 portRspPut = le32_to_cpu(pgp->rspPutInx);
3748 if (portRspPut >= portRspMax) {
3750 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3751 * rsp ring <portRspMax>
3753 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3754 "0303 Ring %d handler: portRspPut %d "
3755 "is bigger than rsp ring %d\n",
3756 pring->ringno, portRspPut, portRspMax);
3758 phba->link_state = LPFC_HBA_ERROR;
3759 spin_unlock_irqrestore(&phba->hbalock, iflag);
3761 phba->work_hs = HS_FFER3;
3762 lpfc_handle_eratt(phba);
3768 while (pring->sli.sli3.rspidx != portRspPut) {
3770 * Build a completion list and call the appropriate handler.
3771 * The process is to get the next available response iocb, get
3772 * a free iocb from the list, copy the response data into the
3773 * free iocb, insert to the continuation list, and update the
3774 * next response index to slim. This process makes response
3775 * iocb's in the ring available to DMA as fast as possible but
3776 * pays a penalty for a copy operation. Since the iocb is
3777 * only 32 bytes, this penalty is considered small relative to
3778 * the PCI reads for register values and a slim write. When
3779 * the ulpLe field is set, the entire Command has been
3782 entry = lpfc_resp_iocb(phba, pring);
3784 phba->last_completion_time = jiffies;
3785 rspiocbp = __lpfc_sli_get_iocbq(phba);
3786 if (rspiocbp == NULL) {
3787 printk(KERN_ERR "%s: out of buffers! Failing "
3788 "completion.\n", __func__);
3792 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
3793 phba->iocb_rsp_size);
3794 irsp = &rspiocbp->iocb;
3796 if (++pring->sli.sli3.rspidx >= portRspMax)
3797 pring->sli.sli3.rspidx = 0;
3799 if (pring->ringno == LPFC_ELS_RING) {
3800 lpfc_debugfs_slow_ring_trc(phba,
3801 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3802 *(((uint32_t *) irsp) + 4),
3803 *(((uint32_t *) irsp) + 6),
3804 *(((uint32_t *) irsp) + 7));
3807 writel(pring->sli.sli3.rspidx,
3808 &phba->host_gp[pring->ringno].rspGetInx);
3810 spin_unlock_irqrestore(&phba->hbalock, iflag);
3811 /* Handle the response IOCB */
3812 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
3813 spin_lock_irqsave(&phba->hbalock, iflag);
3816 * If the port response put pointer has not been updated, sync
3817 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3818 * response put pointer.
3820 if (pring->sli.sli3.rspidx == portRspPut) {
3821 portRspPut = le32_to_cpu(pgp->rspPutInx);
3823 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3825 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
3826 /* At least one response entry has been freed */
3827 pring->stats.iocb_rsp_full++;
3828 /* SET RxRE_RSP in Chip Att register */
3829 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3830 writel(status, phba->CAregaddr);
3831 readl(phba->CAregaddr); /* flush */
3833 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3834 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3835 pring->stats.iocb_cmd_empty++;
3837 /* Force update of the local copy of cmdGetInx */
3838 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3839 lpfc_sli_resume_iocb(phba, pring);
3841 if ((pring->lpfc_sli_cmd_available))
3842 (pring->lpfc_sli_cmd_available) (phba, pring);
3846 spin_unlock_irqrestore(&phba->hbalock, iflag);
3851 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3852 * @phba: Pointer to HBA context object.
3853 * @pring: Pointer to driver SLI ring object.
3854 * @mask: Host attention register mask for this ring.
3856 * This function is called from the worker thread when there is a pending
3857 * ELS response iocb on the driver internal slow-path response iocb worker
3858 * queue. The caller does not hold any lock. The function will remove each
3859 * response iocb from the response worker queue and calls the handle
3860 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3863 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
3864 struct lpfc_sli_ring *pring, uint32_t mask)
3866 struct lpfc_iocbq *irspiocbq;
3867 struct hbq_dmabuf *dmabuf;
3868 struct lpfc_cq_event *cq_event;
3869 unsigned long iflag;
3872 spin_lock_irqsave(&phba->hbalock, iflag);
3873 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
3874 spin_unlock_irqrestore(&phba->hbalock, iflag);
3875 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
3876 /* Get the response iocb from the head of work queue */
3877 spin_lock_irqsave(&phba->hbalock, iflag);
3878 list_remove_head(&phba->sli4_hba.sp_queue_event,
3879 cq_event, struct lpfc_cq_event, list);
3880 spin_unlock_irqrestore(&phba->hbalock, iflag);
3882 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
3883 case CQE_CODE_COMPL_WQE:
3884 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
3886 /* Translate ELS WCQE to response IOCBQ */
3887 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
3890 lpfc_sli_sp_handle_rspiocb(phba, pring,
3894 case CQE_CODE_RECEIVE:
3895 case CQE_CODE_RECEIVE_V1:
3896 dmabuf = container_of(cq_event, struct hbq_dmabuf,
3898 lpfc_sli4_handle_received_buffer(phba, dmabuf);
3905 /* Limit the number of events to 64 to avoid soft lockups */
3912 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3913 * @phba: Pointer to HBA context object.
3914 * @pring: Pointer to driver SLI ring object.
3916 * This function aborts all iocbs in the given ring and frees all the iocb
3917 * objects in txq. This function issues an abort iocb for all the iocb commands
3918 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3919 * the return of this function. The caller is not required to hold any locks.
3922 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3924 LIST_HEAD(completions);
3925 struct lpfc_iocbq *iocb, *next_iocb;
3927 if (pring->ringno == LPFC_ELS_RING) {
3928 lpfc_fabric_abort_hba(phba);
3931 /* Error everything on txq and txcmplq
3934 if (phba->sli_rev >= LPFC_SLI_REV4) {
3935 spin_lock_irq(&pring->ring_lock);
3936 list_splice_init(&pring->txq, &completions);
3938 spin_unlock_irq(&pring->ring_lock);
3940 spin_lock_irq(&phba->hbalock);
3941 /* Next issue ABTS for everything on the txcmplq */
3942 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3943 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3944 spin_unlock_irq(&phba->hbalock);
3946 spin_lock_irq(&phba->hbalock);
3947 list_splice_init(&pring->txq, &completions);
3950 /* Next issue ABTS for everything on the txcmplq */
3951 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
3952 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3953 spin_unlock_irq(&phba->hbalock);
3956 /* Cancel all the IOCBs from the completions list */
3957 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3962 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3963 * @phba: Pointer to HBA context object.
3964 * @pring: Pointer to driver SLI ring object.
3966 * This function aborts all iocbs in FCP rings and frees all the iocb
3967 * objects in txq. This function issues an abort iocb for all the iocb commands
3968 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3969 * the return of this function. The caller is not required to hold any locks.
3972 lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
3974 struct lpfc_sli *psli = &phba->sli;
3975 struct lpfc_sli_ring *pring;
3978 /* Look on all the FCP Rings for the iotag */
3979 if (phba->sli_rev >= LPFC_SLI_REV4) {
3980 for (i = 0; i < phba->cfg_hdw_queue; i++) {
3981 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
3982 lpfc_sli_abort_iocb_ring(phba, pring);
3985 pring = &psli->sli3_ring[LPFC_FCP_RING];
3986 lpfc_sli_abort_iocb_ring(phba, pring);
3991 * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
3992 * @phba: Pointer to HBA context object.
3994 * This function flushes all iocbs in the IO ring and frees all the iocb
3995 * objects in txq and txcmplq. This function will not issue abort iocbs
3996 * for all the iocb commands in txcmplq, they will just be returned with
3997 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3998 * slot has been permanently disabled.
4001 lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
4005 struct lpfc_sli *psli = &phba->sli;
4006 struct lpfc_sli_ring *pring;
4008 struct lpfc_iocbq *piocb, *next_iocb;
4010 spin_lock_irq(&phba->hbalock);
4011 /* Indicate the I/O queues are flushed */
4012 phba->hba_flag |= HBA_IOQ_FLUSH;
4013 spin_unlock_irq(&phba->hbalock);
4015 /* Look on all the FCP Rings for the iotag */
4016 if (phba->sli_rev >= LPFC_SLI_REV4) {
4017 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4018 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4020 spin_lock_irq(&pring->ring_lock);
4021 /* Retrieve everything on txq */
4022 list_splice_init(&pring->txq, &txq);
4023 list_for_each_entry_safe(piocb, next_iocb,
4024 &pring->txcmplq, list)
4025 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4026 /* Retrieve everything on the txcmplq */
4027 list_splice_init(&pring->txcmplq, &txcmplq);
4029 pring->txcmplq_cnt = 0;
4030 spin_unlock_irq(&pring->ring_lock);
4033 lpfc_sli_cancel_iocbs(phba, &txq,
4034 IOSTAT_LOCAL_REJECT,
4036 /* Flush the txcmpq */
4037 lpfc_sli_cancel_iocbs(phba, &txcmplq,
4038 IOSTAT_LOCAL_REJECT,
4042 pring = &psli->sli3_ring[LPFC_FCP_RING];
4044 spin_lock_irq(&phba->hbalock);
4045 /* Retrieve everything on txq */
4046 list_splice_init(&pring->txq, &txq);
4047 list_for_each_entry_safe(piocb, next_iocb,
4048 &pring->txcmplq, list)
4049 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4050 /* Retrieve everything on the txcmplq */
4051 list_splice_init(&pring->txcmplq, &txcmplq);
4053 pring->txcmplq_cnt = 0;
4054 spin_unlock_irq(&phba->hbalock);
4057 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
4059 /* Flush the txcmpq */
4060 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
4066 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
4067 * @phba: Pointer to HBA context object.
4068 * @mask: Bit mask to be checked.
4070 * This function reads the host status register and compares
4071 * with the provided bit mask to check if HBA completed
4072 * the restart. This function will wait in a loop for the
4073 * HBA to complete restart. If the HBA does not restart within
4074 * 15 iterations, the function will reset the HBA again. The
4075 * function returns 1 when HBA fail to restart otherwise returns
4079 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
4085 /* Read the HBA Host Status Register */
4086 if (lpfc_readl(phba->HSregaddr, &status))
4090 * Check status register every 100ms for 5 retries, then every
4091 * 500ms for 5, then every 2.5 sec for 5, then reset board and
4092 * every 2.5 sec for 4.
4093 * Break our of the loop if errors occurred during init.
4095 while (((status & mask) != mask) &&
4096 !(status & HS_FFERM) &&
4108 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4109 lpfc_sli_brdrestart(phba);
4111 /* Read the HBA Host Status Register */
4112 if (lpfc_readl(phba->HSregaddr, &status)) {
4118 /* Check to see if any errors occurred during init */
4119 if ((status & HS_FFERM) || (i >= 20)) {
4120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4121 "2751 Adapter failed to restart, "
4122 "status reg x%x, FW Data: A8 x%x AC x%x\n",
4124 readl(phba->MBslimaddr + 0xa8),
4125 readl(phba->MBslimaddr + 0xac));
4126 phba->link_state = LPFC_HBA_ERROR;
4134 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
4135 * @phba: Pointer to HBA context object.
4136 * @mask: Bit mask to be checked.
4138 * This function checks the host status register to check if HBA is
4139 * ready. This function will wait in a loop for the HBA to be ready
4140 * If the HBA is not ready , the function will will reset the HBA PCI
4141 * function again. The function returns 1 when HBA fail to be ready
4142 * otherwise returns zero.
4145 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
4150 /* Read the HBA Host Status Register */
4151 status = lpfc_sli4_post_status_check(phba);
4154 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4155 lpfc_sli_brdrestart(phba);
4156 status = lpfc_sli4_post_status_check(phba);
4159 /* Check to see if any errors occurred during init */
4161 phba->link_state = LPFC_HBA_ERROR;
4164 phba->sli4_hba.intr_enable = 0;
4170 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
4171 * @phba: Pointer to HBA context object.
4172 * @mask: Bit mask to be checked.
4174 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
4175 * from the API jump table function pointer from the lpfc_hba struct.
4178 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
4180 return phba->lpfc_sli_brdready(phba, mask);
4183 #define BARRIER_TEST_PATTERN (0xdeadbeef)
4186 * lpfc_reset_barrier - Make HBA ready for HBA reset
4187 * @phba: Pointer to HBA context object.
4189 * This function is called before resetting an HBA. This function is called
4190 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4192 void lpfc_reset_barrier(struct lpfc_hba *phba)
4194 uint32_t __iomem *resp_buf;
4195 uint32_t __iomem *mbox_buf;
4196 volatile uint32_t mbox;
4197 uint32_t hc_copy, ha_copy, resp_data;
4201 lockdep_assert_held(&phba->hbalock);
4203 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
4204 if (hdrtype != 0x80 ||
4205 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
4206 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
4210 * Tell the other part of the chip to suspend temporarily all
4213 resp_buf = phba->MBslimaddr;
4215 /* Disable the error attention */
4216 if (lpfc_readl(phba->HCregaddr, &hc_copy))
4218 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
4219 readl(phba->HCregaddr); /* flush */
4220 phba->link_flag |= LS_IGNORE_ERATT;
4222 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4224 if (ha_copy & HA_ERATT) {
4225 /* Clear Chip error bit */
4226 writel(HA_ERATT, phba->HAregaddr);
4227 phba->pport->stopped = 1;
4231 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
4232 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
4234 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
4235 mbox_buf = phba->MBslimaddr;
4236 writel(mbox, mbox_buf);
4238 for (i = 0; i < 50; i++) {
4239 if (lpfc_readl((resp_buf + 1), &resp_data))
4241 if (resp_data != ~(BARRIER_TEST_PATTERN))
4247 if (lpfc_readl((resp_buf + 1), &resp_data))
4249 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
4250 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
4251 phba->pport->stopped)
4257 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
4259 for (i = 0; i < 500; i++) {
4260 if (lpfc_readl(resp_buf, &resp_data))
4262 if (resp_data != mbox)
4271 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4273 if (!(ha_copy & HA_ERATT))
4279 if (readl(phba->HAregaddr) & HA_ERATT) {
4280 writel(HA_ERATT, phba->HAregaddr);
4281 phba->pport->stopped = 1;
4285 phba->link_flag &= ~LS_IGNORE_ERATT;
4286 writel(hc_copy, phba->HCregaddr);
4287 readl(phba->HCregaddr); /* flush */
4291 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4292 * @phba: Pointer to HBA context object.
4294 * This function issues a kill_board mailbox command and waits for
4295 * the error attention interrupt. This function is called for stopping
4296 * the firmware processing. The caller is not required to hold any
4297 * locks. This function calls lpfc_hba_down_post function to free
4298 * any pending commands after the kill. The function will return 1 when it
4299 * fails to kill the board else will return 0.
4302 lpfc_sli_brdkill(struct lpfc_hba *phba)
4304 struct lpfc_sli *psli;
4314 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4315 "0329 Kill HBA Data: x%x x%x\n",
4316 phba->pport->port_state, psli->sli_flag);
4318 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4322 /* Disable the error attention */
4323 spin_lock_irq(&phba->hbalock);
4324 if (lpfc_readl(phba->HCregaddr, &status)) {
4325 spin_unlock_irq(&phba->hbalock);
4326 mempool_free(pmb, phba->mbox_mem_pool);
4329 status &= ~HC_ERINT_ENA;
4330 writel(status, phba->HCregaddr);
4331 readl(phba->HCregaddr); /* flush */
4332 phba->link_flag |= LS_IGNORE_ERATT;
4333 spin_unlock_irq(&phba->hbalock);
4335 lpfc_kill_board(phba, pmb);
4336 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4337 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4339 if (retval != MBX_SUCCESS) {
4340 if (retval != MBX_BUSY)
4341 mempool_free(pmb, phba->mbox_mem_pool);
4342 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4343 "2752 KILL_BOARD command failed retval %d\n",
4345 spin_lock_irq(&phba->hbalock);
4346 phba->link_flag &= ~LS_IGNORE_ERATT;
4347 spin_unlock_irq(&phba->hbalock);
4351 spin_lock_irq(&phba->hbalock);
4352 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4353 spin_unlock_irq(&phba->hbalock);
4355 mempool_free(pmb, phba->mbox_mem_pool);
4357 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4358 * attention every 100ms for 3 seconds. If we don't get ERATT after
4359 * 3 seconds we still set HBA_ERROR state because the status of the
4360 * board is now undefined.
4362 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4364 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
4366 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4370 del_timer_sync(&psli->mbox_tmo);
4371 if (ha_copy & HA_ERATT) {
4372 writel(HA_ERATT, phba->HAregaddr);
4373 phba->pport->stopped = 1;
4375 spin_lock_irq(&phba->hbalock);
4376 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4377 psli->mbox_active = NULL;
4378 phba->link_flag &= ~LS_IGNORE_ERATT;
4379 spin_unlock_irq(&phba->hbalock);
4381 lpfc_hba_down_post(phba);
4382 phba->link_state = LPFC_HBA_ERROR;
4384 return ha_copy & HA_ERATT ? 0 : 1;
4388 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4389 * @phba: Pointer to HBA context object.
4391 * This function resets the HBA by writing HC_INITFF to the control
4392 * register. After the HBA resets, this function resets all the iocb ring
4393 * indices. This function disables PCI layer parity checking during
4395 * This function returns 0 always.
4396 * The caller is not required to hold any locks.
4399 lpfc_sli_brdreset(struct lpfc_hba *phba)
4401 struct lpfc_sli *psli;
4402 struct lpfc_sli_ring *pring;
4409 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4410 "0325 Reset HBA Data: x%x x%x\n",
4411 (phba->pport) ? phba->pport->port_state : 0,
4414 /* perform board reset */
4415 phba->fc_eventTag = 0;
4416 phba->link_events = 0;
4418 phba->pport->fc_myDID = 0;
4419 phba->pport->fc_prevDID = 0;
4422 /* Turn off parity checking and serr during the physical reset */
4423 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
4426 pci_write_config_word(phba->pcidev, PCI_COMMAND,
4428 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4430 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
4432 /* Now toggle INITFF bit in the Host Control Register */
4433 writel(HC_INITFF, phba->HCregaddr);
4435 readl(phba->HCregaddr); /* flush */
4436 writel(0, phba->HCregaddr);
4437 readl(phba->HCregaddr); /* flush */
4439 /* Restore PCI cmd register */
4440 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4442 /* Initialize relevant SLI info */
4443 for (i = 0; i < psli->num_rings; i++) {
4444 pring = &psli->sli3_ring[i];
4446 pring->sli.sli3.rspidx = 0;
4447 pring->sli.sli3.next_cmdidx = 0;
4448 pring->sli.sli3.local_getidx = 0;
4449 pring->sli.sli3.cmdidx = 0;
4450 pring->missbufcnt = 0;
4453 phba->link_state = LPFC_WARM_START;
4458 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4459 * @phba: Pointer to HBA context object.
4461 * This function resets a SLI4 HBA. This function disables PCI layer parity
4462 * checking during resets the device. The caller is not required to hold
4465 * This function returns 0 on success else returns negative error code.
4468 lpfc_sli4_brdreset(struct lpfc_hba *phba)
4470 struct lpfc_sli *psli = &phba->sli;
4475 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4476 "0295 Reset HBA Data: x%x x%x x%x\n",
4477 phba->pport->port_state, psli->sli_flag,
4480 /* perform board reset */
4481 phba->fc_eventTag = 0;
4482 phba->link_events = 0;
4483 phba->pport->fc_myDID = 0;
4484 phba->pport->fc_prevDID = 0;
4486 spin_lock_irq(&phba->hbalock);
4487 psli->sli_flag &= ~(LPFC_PROCESS_LA);
4488 phba->fcf.fcf_flag = 0;
4489 spin_unlock_irq(&phba->hbalock);
4491 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4492 if (phba->hba_flag & HBA_FW_DUMP_OP) {
4493 phba->hba_flag &= ~HBA_FW_DUMP_OP;
4497 /* Now physically reset the device */
4498 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4499 "0389 Performing PCI function reset!\n");
4501 /* Turn off parity checking and serr during the physical reset */
4502 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
4503 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4504 "3205 PCI read Config failed\n");
4508 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
4509 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4511 /* Perform FCoE PCI function reset before freeing queue memory */
4512 rc = lpfc_pci_function_reset(phba);
4514 /* Restore PCI cmd register */
4515 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4521 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4522 * @phba: Pointer to HBA context object.
4524 * This function is called in the SLI initialization code path to
4525 * restart the HBA. The caller is not required to hold any lock.
4526 * This function writes MBX_RESTART mailbox command to the SLIM and
4527 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4528 * function to free any pending commands. The function enables
4529 * POST only during the first initialization. The function returns zero.
4530 * The function does not guarantee completion of MBX_RESTART mailbox
4531 * command before the return of this function.
4534 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
4537 struct lpfc_sli *psli;
4538 volatile uint32_t word0;
4539 void __iomem *to_slim;
4540 uint32_t hba_aer_enabled;
4542 spin_lock_irq(&phba->hbalock);
4544 /* Take PCIe device Advanced Error Reporting (AER) state */
4545 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4550 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4551 "0337 Restart HBA Data: x%x x%x\n",
4552 (phba->pport) ? phba->pport->port_state : 0,
4556 mb = (MAILBOX_t *) &word0;
4557 mb->mbxCommand = MBX_RESTART;
4560 lpfc_reset_barrier(phba);
4562 to_slim = phba->MBslimaddr;
4563 writel(*(uint32_t *) mb, to_slim);
4564 readl(to_slim); /* flush */
4566 /* Only skip post after fc_ffinit is completed */
4567 if (phba->pport && phba->pport->port_state)
4568 word0 = 1; /* This is really setting up word1 */
4570 word0 = 0; /* This is really setting up word1 */
4571 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4572 writel(*(uint32_t *) mb, to_slim);
4573 readl(to_slim); /* flush */
4575 lpfc_sli_brdreset(phba);
4577 phba->pport->stopped = 0;
4578 phba->link_state = LPFC_INIT_START;
4580 spin_unlock_irq(&phba->hbalock);
4582 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4583 psli->stats_start = ktime_get_seconds();
4585 /* Give the INITFF and Post time to settle. */
4588 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4589 if (hba_aer_enabled)
4590 pci_disable_pcie_error_reporting(phba->pcidev);
4592 lpfc_hba_down_post(phba);
4598 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4599 * @phba: Pointer to HBA context object.
4601 * This function is called in the SLI initialization code path to restart
4602 * a SLI4 HBA. The caller is not required to hold any lock.
4603 * At the end of the function, it calls lpfc_hba_down_post function to
4604 * free any pending commands.
4607 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
4609 struct lpfc_sli *psli = &phba->sli;
4610 uint32_t hba_aer_enabled;
4614 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4615 "0296 Restart HBA Data: x%x x%x\n",
4616 phba->pport->port_state, psli->sli_flag);
4618 /* Take PCIe device Advanced Error Reporting (AER) state */
4619 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4621 rc = lpfc_sli4_brdreset(phba);
4623 phba->link_state = LPFC_HBA_ERROR;
4624 goto hba_down_queue;
4627 spin_lock_irq(&phba->hbalock);
4628 phba->pport->stopped = 0;
4629 phba->link_state = LPFC_INIT_START;
4631 spin_unlock_irq(&phba->hbalock);
4633 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4634 psli->stats_start = ktime_get_seconds();
4636 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4637 if (hba_aer_enabled)
4638 pci_disable_pcie_error_reporting(phba->pcidev);
4641 lpfc_hba_down_post(phba);
4642 lpfc_sli4_queue_destroy(phba);
4648 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4649 * @phba: Pointer to HBA context object.
4651 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4652 * API jump table function pointer from the lpfc_hba struct.
4655 lpfc_sli_brdrestart(struct lpfc_hba *phba)
4657 return phba->lpfc_sli_brdrestart(phba);
4661 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4662 * @phba: Pointer to HBA context object.
4664 * This function is called after a HBA restart to wait for successful
4665 * restart of the HBA. Successful restart of the HBA is indicated by
4666 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4667 * iteration, the function will restart the HBA again. The function returns
4668 * zero if HBA successfully restarted else returns negative error code.
4671 lpfc_sli_chipset_init(struct lpfc_hba *phba)
4673 uint32_t status, i = 0;
4675 /* Read the HBA Host Status Register */
4676 if (lpfc_readl(phba->HSregaddr, &status))
4679 /* Check status register to see what current state is */
4681 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4683 /* Check every 10ms for 10 retries, then every 100ms for 90
4684 * retries, then every 1 sec for 50 retires for a total of
4685 * ~60 seconds before reset the board again and check every
4686 * 1 sec for 50 retries. The up to 60 seconds before the
4687 * board ready is required by the Falcon FIPS zeroization
4688 * complete, and any reset the board in between shall cause
4689 * restart of zeroization, further delay the board ready.
4692 /* Adapter failed to init, timeout, status reg
4694 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4695 "0436 Adapter failed to init, "
4696 "timeout, status reg x%x, "
4697 "FW Data: A8 x%x AC x%x\n", status,
4698 readl(phba->MBslimaddr + 0xa8),
4699 readl(phba->MBslimaddr + 0xac));
4700 phba->link_state = LPFC_HBA_ERROR;
4704 /* Check to see if any errors occurred during init */
4705 if (status & HS_FFERM) {
4706 /* ERROR: During chipset initialization */
4707 /* Adapter failed to init, chipset, status reg
4709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4710 "0437 Adapter failed to init, "
4711 "chipset, status reg x%x, "
4712 "FW Data: A8 x%x AC x%x\n", status,
4713 readl(phba->MBslimaddr + 0xa8),
4714 readl(phba->MBslimaddr + 0xac));
4715 phba->link_state = LPFC_HBA_ERROR;
4728 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4729 lpfc_sli_brdrestart(phba);
4731 /* Read the HBA Host Status Register */
4732 if (lpfc_readl(phba->HSregaddr, &status))
4736 /* Check to see if any errors occurred during init */
4737 if (status & HS_FFERM) {
4738 /* ERROR: During chipset initialization */
4739 /* Adapter failed to init, chipset, status reg <status> */
4740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4741 "0438 Adapter failed to init, chipset, "
4743 "FW Data: A8 x%x AC x%x\n", status,
4744 readl(phba->MBslimaddr + 0xa8),
4745 readl(phba->MBslimaddr + 0xac));
4746 phba->link_state = LPFC_HBA_ERROR;
4750 /* Clear all interrupt enable conditions */
4751 writel(0, phba->HCregaddr);
4752 readl(phba->HCregaddr); /* flush */
4754 /* setup host attn register */
4755 writel(0xffffffff, phba->HAregaddr);
4756 readl(phba->HAregaddr); /* flush */
4761 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4763 * This function calculates and returns the number of HBQs required to be
4767 lpfc_sli_hbq_count(void)
4769 return ARRAY_SIZE(lpfc_hbq_defs);
4773 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4775 * This function adds the number of hbq entries in every HBQ to get
4776 * the total number of hbq entries required for the HBA and returns
4780 lpfc_sli_hbq_entry_count(void)
4782 int hbq_count = lpfc_sli_hbq_count();
4786 for (i = 0; i < hbq_count; ++i)
4787 count += lpfc_hbq_defs[i]->entry_count;
4792 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4794 * This function calculates amount of memory required for all hbq entries
4795 * to be configured and returns the total memory required.
4798 lpfc_sli_hbq_size(void)
4800 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
4804 * lpfc_sli_hbq_setup - configure and initialize HBQs
4805 * @phba: Pointer to HBA context object.
4807 * This function is called during the SLI initialization to configure
4808 * all the HBQs and post buffers to the HBQ. The caller is not
4809 * required to hold any locks. This function will return zero if successful
4810 * else it will return negative error code.
4813 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
4815 int hbq_count = lpfc_sli_hbq_count();
4819 uint32_t hbq_entry_index;
4821 /* Get a Mailbox buffer to setup mailbox
4822 * commands for HBA initialization
4824 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4831 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4832 phba->link_state = LPFC_INIT_MBX_CMDS;
4833 phba->hbq_in_use = 1;
4835 hbq_entry_index = 0;
4836 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
4837 phba->hbqs[hbqno].next_hbqPutIdx = 0;
4838 phba->hbqs[hbqno].hbqPutIdx = 0;
4839 phba->hbqs[hbqno].local_hbqGetIdx = 0;
4840 phba->hbqs[hbqno].entry_count =
4841 lpfc_hbq_defs[hbqno]->entry_count;
4842 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
4843 hbq_entry_index, pmb);
4844 hbq_entry_index += phba->hbqs[hbqno].entry_count;
4846 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
4847 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4848 mbxStatus <status>, ring <num> */
4850 lpfc_printf_log(phba, KERN_ERR,
4851 LOG_SLI | LOG_VPORT,
4852 "1805 Adapter failed to init. "
4853 "Data: x%x x%x x%x\n",
4855 pmbox->mbxStatus, hbqno);
4857 phba->link_state = LPFC_HBA_ERROR;
4858 mempool_free(pmb, phba->mbox_mem_pool);
4862 phba->hbq_count = hbq_count;
4864 mempool_free(pmb, phba->mbox_mem_pool);
4866 /* Initially populate or replenish the HBQs */
4867 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
4868 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
4873 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4874 * @phba: Pointer to HBA context object.
4876 * This function is called during the SLI initialization to configure
4877 * all the HBQs and post buffers to the HBQ. The caller is not
4878 * required to hold any locks. This function will return zero if successful
4879 * else it will return negative error code.
4882 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
4884 phba->hbq_in_use = 1;
4885 phba->hbqs[LPFC_ELS_HBQ].entry_count =
4886 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
4887 phba->hbq_count = 1;
4888 lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
4889 /* Initially populate or replenish the HBQs */
4894 * lpfc_sli_config_port - Issue config port mailbox command
4895 * @phba: Pointer to HBA context object.
4896 * @sli_mode: sli mode - 2/3
4898 * This function is called by the sli initialization code path
4899 * to issue config_port mailbox command. This function restarts the
4900 * HBA firmware and issues a config_port mailbox command to configure
4901 * the SLI interface in the sli mode specified by sli_mode
4902 * variable. The caller is not required to hold any locks.
4903 * The function returns 0 if successful, else returns negative error
4907 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
4910 uint32_t resetcount = 0, rc = 0, done = 0;
4912 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4914 phba->link_state = LPFC_HBA_ERROR;
4918 phba->sli_rev = sli_mode;
4919 while (resetcount < 2 && !done) {
4920 spin_lock_irq(&phba->hbalock);
4921 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
4922 spin_unlock_irq(&phba->hbalock);
4923 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4924 lpfc_sli_brdrestart(phba);
4925 rc = lpfc_sli_chipset_init(phba);
4929 spin_lock_irq(&phba->hbalock);
4930 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4931 spin_unlock_irq(&phba->hbalock);
4934 /* Call pre CONFIG_PORT mailbox command initialization. A
4935 * value of 0 means the call was successful. Any other
4936 * nonzero value is a failure, but if ERESTART is returned,
4937 * the driver may reset the HBA and try again.
4939 rc = lpfc_config_port_prep(phba);
4940 if (rc == -ERESTART) {
4941 phba->link_state = LPFC_LINK_UNKNOWN;
4946 phba->link_state = LPFC_INIT_MBX_CMDS;
4947 lpfc_config_port(phba, pmb);
4948 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4949 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
4950 LPFC_SLI3_HBQ_ENABLED |
4951 LPFC_SLI3_CRP_ENABLED |
4952 LPFC_SLI3_DSS_ENABLED);
4953 if (rc != MBX_SUCCESS) {
4954 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4955 "0442 Adapter failed to init, mbxCmd x%x "
4956 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4957 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
4958 spin_lock_irq(&phba->hbalock);
4959 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
4960 spin_unlock_irq(&phba->hbalock);
4963 /* Allow asynchronous mailbox command to go through */
4964 spin_lock_irq(&phba->hbalock);
4965 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
4966 spin_unlock_irq(&phba->hbalock);
4969 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
4970 (pmb->u.mb.un.varCfgPort.gasabt == 0))
4971 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4972 "3110 Port did not grant ASABT\n");
4977 goto do_prep_failed;
4979 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
4980 if (!pmb->u.mb.un.varCfgPort.cMA) {
4982 goto do_prep_failed;
4984 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
4985 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
4986 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
4987 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
4988 phba->max_vpi : phba->max_vports;
4992 phba->fips_level = 0;
4993 phba->fips_spec_rev = 0;
4994 if (pmb->u.mb.un.varCfgPort.gdss) {
4995 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
4996 phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
4997 phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
4998 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4999 "2850 Security Crypto Active. FIPS x%d "
5001 phba->fips_level, phba->fips_spec_rev);
5003 if (pmb->u.mb.un.varCfgPort.sec_err) {
5004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5005 "2856 Config Port Security Crypto "
5007 pmb->u.mb.un.varCfgPort.sec_err);
5009 if (pmb->u.mb.un.varCfgPort.gerbm)
5010 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
5011 if (pmb->u.mb.un.varCfgPort.gcrp)
5012 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
5014 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
5015 phba->port_gp = phba->mbox->us.s3_pgp.port;
5017 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5018 if (pmb->u.mb.un.varCfgPort.gbg == 0) {
5019 phba->cfg_enable_bg = 0;
5020 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
5021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5022 "0443 Adapter did not grant "
5027 phba->hbq_get = NULL;
5028 phba->port_gp = phba->mbox->us.s2.port;
5032 mempool_free(pmb, phba->mbox_mem_pool);
5038 * lpfc_sli_hba_setup - SLI initialization function
5039 * @phba: Pointer to HBA context object.
5041 * This function is the main SLI initialization function. This function
5042 * is called by the HBA initialization code, HBA reset code and HBA
5043 * error attention handler code. Caller is not required to hold any
5044 * locks. This function issues config_port mailbox command to configure
5045 * the SLI, setup iocb rings and HBQ rings. In the end the function
5046 * calls the config_port_post function to issue init_link mailbox
5047 * command and to start the discovery. The function will return zero
5048 * if successful, else it will return negative error code.
5051 lpfc_sli_hba_setup(struct lpfc_hba *phba)
5057 switch (phba->cfg_sli_mode) {
5059 if (phba->cfg_enable_npiv) {
5060 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
5061 "1824 NPIV enabled: Override sli_mode "
5062 "parameter (%d) to auto (0).\n",
5063 phba->cfg_sli_mode);
5072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
5073 "1819 Unrecognized sli_mode parameter: %d.\n",
5074 phba->cfg_sli_mode);
5078 phba->fcp_embed_io = 0; /* SLI4 FC support only */
5080 rc = lpfc_sli_config_port(phba, mode);
5082 if (rc && phba->cfg_sli_mode == 3)
5083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
5084 "1820 Unable to select SLI-3. "
5085 "Not supported by adapter.\n");
5086 if (rc && mode != 2)
5087 rc = lpfc_sli_config_port(phba, 2);
5088 else if (rc && mode == 2)
5089 rc = lpfc_sli_config_port(phba, 3);
5091 goto lpfc_sli_hba_setup_error;
5093 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5094 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
5095 rc = pci_enable_pcie_error_reporting(phba->pcidev);
5097 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5098 "2709 This device supports "
5099 "Advanced Error Reporting (AER)\n");
5100 spin_lock_irq(&phba->hbalock);
5101 phba->hba_flag |= HBA_AER_ENABLED;
5102 spin_unlock_irq(&phba->hbalock);
5104 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5105 "2708 This device does not support "
5106 "Advanced Error Reporting (AER): %d\n",
5108 phba->cfg_aer_support = 0;
5112 if (phba->sli_rev == 3) {
5113 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
5114 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
5116 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
5117 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
5118 phba->sli3_options = 0;
5121 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5122 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
5123 phba->sli_rev, phba->max_vpi);
5124 rc = lpfc_sli_ring_map(phba);
5127 goto lpfc_sli_hba_setup_error;
5129 /* Initialize VPIs. */
5130 if (phba->sli_rev == LPFC_SLI_REV3) {
5132 * The VPI bitmask and physical ID array are allocated
5133 * and initialized once only - at driver load. A port
5134 * reset doesn't need to reinitialize this memory.
5136 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
5137 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
5138 phba->vpi_bmask = kcalloc(longs,
5139 sizeof(unsigned long),
5141 if (!phba->vpi_bmask) {
5143 goto lpfc_sli_hba_setup_error;
5146 phba->vpi_ids = kcalloc(phba->max_vpi + 1,
5149 if (!phba->vpi_ids) {
5150 kfree(phba->vpi_bmask);
5152 goto lpfc_sli_hba_setup_error;
5154 for (i = 0; i < phba->max_vpi; i++)
5155 phba->vpi_ids[i] = i;
5160 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5161 rc = lpfc_sli_hbq_setup(phba);
5163 goto lpfc_sli_hba_setup_error;
5165 spin_lock_irq(&phba->hbalock);
5166 phba->sli.sli_flag |= LPFC_PROCESS_LA;
5167 spin_unlock_irq(&phba->hbalock);
5169 rc = lpfc_config_port_post(phba);
5171 goto lpfc_sli_hba_setup_error;
5175 lpfc_sli_hba_setup_error:
5176 phba->link_state = LPFC_HBA_ERROR;
5177 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5178 "0445 Firmware initialization failed\n");
5183 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
5184 * @phba: Pointer to HBA context object.
5185 * @mboxq: mailbox pointer.
5186 * This function issue a dump mailbox command to read config region
5187 * 23 and parse the records in the region and populate driver
5191 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
5193 LPFC_MBOXQ_t *mboxq;
5194 struct lpfc_dmabuf *mp;
5195 struct lpfc_mqe *mqe;
5196 uint32_t data_length;
5199 /* Program the default value of vlan_id and fc_map */
5200 phba->valid_vlan = 0;
5201 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5202 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5203 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5205 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5209 mqe = &mboxq->u.mqe;
5210 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
5212 goto out_free_mboxq;
5215 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
5216 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5218 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5219 "(%d):2571 Mailbox cmd x%x Status x%x "
5220 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5221 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5222 "CQ: x%x x%x x%x x%x\n",
5223 mboxq->vport ? mboxq->vport->vpi : 0,
5224 bf_get(lpfc_mqe_command, mqe),
5225 bf_get(lpfc_mqe_status, mqe),
5226 mqe->un.mb_words[0], mqe->un.mb_words[1],
5227 mqe->un.mb_words[2], mqe->un.mb_words[3],
5228 mqe->un.mb_words[4], mqe->un.mb_words[5],
5229 mqe->un.mb_words[6], mqe->un.mb_words[7],
5230 mqe->un.mb_words[8], mqe->un.mb_words[9],
5231 mqe->un.mb_words[10], mqe->un.mb_words[11],
5232 mqe->un.mb_words[12], mqe->un.mb_words[13],
5233 mqe->un.mb_words[14], mqe->un.mb_words[15],
5234 mqe->un.mb_words[16], mqe->un.mb_words[50],
5236 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5237 mboxq->mcqe.trailer);
5240 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5243 goto out_free_mboxq;
5245 data_length = mqe->un.mb_words[5];
5246 if (data_length > DMP_RGN23_SIZE) {
5247 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5250 goto out_free_mboxq;
5253 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
5254 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5259 mempool_free(mboxq, phba->mbox_mem_pool);
5264 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5265 * @phba: pointer to lpfc hba data structure.
5266 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5267 * @vpd: pointer to the memory to hold resulting port vpd data.
5268 * @vpd_size: On input, the number of bytes allocated to @vpd.
5269 * On output, the number of data bytes in @vpd.
5271 * This routine executes a READ_REV SLI4 mailbox command. In
5272 * addition, this routine gets the port vpd data.
5276 * -ENOMEM - could not allocated memory.
5279 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5280 uint8_t *vpd, uint32_t *vpd_size)
5284 struct lpfc_dmabuf *dmabuf;
5285 struct lpfc_mqe *mqe;
5287 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5292 * Get a DMA buffer for the vpd data resulting from the READ_REV
5295 dma_size = *vpd_size;
5296 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
5297 &dmabuf->phys, GFP_KERNEL);
5298 if (!dmabuf->virt) {
5304 * The SLI4 implementation of READ_REV conflicts at word1,
5305 * bits 31:16 and SLI4 adds vpd functionality not present
5306 * in SLI3. This code corrects the conflicts.
5308 lpfc_read_rev(phba, mboxq);
5309 mqe = &mboxq->u.mqe;
5310 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
5311 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
5312 mqe->un.read_rev.word1 &= 0x0000FFFF;
5313 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
5314 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
5316 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5318 dma_free_coherent(&phba->pcidev->dev, dma_size,
5319 dmabuf->virt, dmabuf->phys);
5325 * The available vpd length cannot be bigger than the
5326 * DMA buffer passed to the port. Catch the less than
5327 * case and update the caller's size.
5329 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
5330 *vpd_size = mqe->un.read_rev.avail_vpd_len;
5332 memcpy(vpd, dmabuf->virt, *vpd_size);
5334 dma_free_coherent(&phba->pcidev->dev, dma_size,
5335 dmabuf->virt, dmabuf->phys);
5341 * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
5342 * @phba: pointer to lpfc hba data structure.
5344 * This routine retrieves SLI4 device physical port name this PCI function
5349 * otherwise - failed to retrieve controller attributes
5352 lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
5354 LPFC_MBOXQ_t *mboxq;
5355 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
5356 struct lpfc_controller_attribute *cntl_attr;
5357 void *virtaddr = NULL;
5358 uint32_t alloclen, reqlen;
5359 uint32_t shdr_status, shdr_add_status;
5360 union lpfc_sli4_cfg_shdr *shdr;
5363 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5367 /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
5368 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
5369 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5370 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
5371 LPFC_SLI4_MBX_NEMBED);
5373 if (alloclen < reqlen) {
5374 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5375 "3084 Allocated DMA memory size (%d) is "
5376 "less than the requested DMA memory size "
5377 "(%d)\n", alloclen, reqlen);
5379 goto out_free_mboxq;
5381 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5382 virtaddr = mboxq->sge_array->addr[0];
5383 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
5384 shdr = &mbx_cntl_attr->cfg_shdr;
5385 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5386 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5387 if (shdr_status || shdr_add_status || rc) {
5388 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5389 "3085 Mailbox x%x (x%x/x%x) failed, "
5390 "rc:x%x, status:x%x, add_status:x%x\n",
5391 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5392 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5393 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5394 rc, shdr_status, shdr_add_status);
5396 goto out_free_mboxq;
5399 cntl_attr = &mbx_cntl_attr->cntl_attr;
5400 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
5401 phba->sli4_hba.lnk_info.lnk_tp =
5402 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
5403 phba->sli4_hba.lnk_info.lnk_no =
5404 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
5406 memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
5407 strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
5408 sizeof(phba->BIOSVersion));
5410 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5411 "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n",
5412 phba->sli4_hba.lnk_info.lnk_tp,
5413 phba->sli4_hba.lnk_info.lnk_no,
5416 if (rc != MBX_TIMEOUT) {
5417 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5418 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5420 mempool_free(mboxq, phba->mbox_mem_pool);
5426 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5427 * @phba: pointer to lpfc hba data structure.
5429 * This routine retrieves SLI4 device physical port name this PCI function
5434 * otherwise - failed to retrieve physical port name
5437 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
5439 LPFC_MBOXQ_t *mboxq;
5440 struct lpfc_mbx_get_port_name *get_port_name;
5441 uint32_t shdr_status, shdr_add_status;
5442 union lpfc_sli4_cfg_shdr *shdr;
5443 char cport_name = 0;
5446 /* We assume nothing at this point */
5447 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5448 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
5450 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5453 /* obtain link type and link number via READ_CONFIG */
5454 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5455 lpfc_sli4_read_config(phba);
5456 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
5457 goto retrieve_ppname;
5459 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5460 rc = lpfc_sli4_get_ctl_attr(phba);
5462 goto out_free_mboxq;
5465 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5466 LPFC_MBOX_OPCODE_GET_PORT_NAME,
5467 sizeof(struct lpfc_mbx_get_port_name) -
5468 sizeof(struct lpfc_sli4_cfg_mhdr),
5469 LPFC_SLI4_MBX_EMBED);
5470 get_port_name = &mboxq->u.mqe.un.get_port_name;
5471 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
5472 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
5473 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
5474 phba->sli4_hba.lnk_info.lnk_tp);
5475 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5476 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5477 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5478 if (shdr_status || shdr_add_status || rc) {
5479 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5480 "3087 Mailbox x%x (x%x/x%x) failed: "
5481 "rc:x%x, status:x%x, add_status:x%x\n",
5482 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5483 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5484 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5485 rc, shdr_status, shdr_add_status);
5487 goto out_free_mboxq;
5489 switch (phba->sli4_hba.lnk_info.lnk_no) {
5490 case LPFC_LINK_NUMBER_0:
5491 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
5492 &get_port_name->u.response);
5493 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5495 case LPFC_LINK_NUMBER_1:
5496 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
5497 &get_port_name->u.response);
5498 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5500 case LPFC_LINK_NUMBER_2:
5501 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
5502 &get_port_name->u.response);
5503 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5505 case LPFC_LINK_NUMBER_3:
5506 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
5507 &get_port_name->u.response);
5508 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5514 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
5515 phba->Port[0] = cport_name;
5516 phba->Port[1] = '\0';
5517 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5518 "3091 SLI get port name: %s\n", phba->Port);
5522 if (rc != MBX_TIMEOUT) {
5523 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5524 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5526 mempool_free(mboxq, phba->mbox_mem_pool);
5532 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5533 * @phba: pointer to lpfc hba data structure.
5535 * This routine is called to explicitly arm the SLI4 device's completion and
5539 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
5542 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
5543 struct lpfc_sli4_hdw_queue *qp;
5544 struct lpfc_queue *eq;
5546 sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
5547 sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
5548 if (sli4_hba->nvmels_cq)
5549 sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
5552 if (sli4_hba->hdwq) {
5553 /* Loop thru all Hardware Queues */
5554 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
5555 qp = &sli4_hba->hdwq[qidx];
5556 /* ARM the corresponding CQ */
5557 sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
5561 /* Loop thru all IRQ vectors */
5562 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
5563 eq = sli4_hba->hba_eq_hdl[qidx].eq;
5564 /* ARM the corresponding EQ */
5565 sli4_hba->sli4_write_eq_db(phba, eq,
5566 0, LPFC_QUEUE_REARM);
5570 if (phba->nvmet_support) {
5571 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
5572 sli4_hba->sli4_write_cq_db(phba,
5573 sli4_hba->nvmet_cqset[qidx], 0,
5580 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5581 * @phba: Pointer to HBA context object.
5582 * @type: The resource extent type.
5583 * @extnt_count: buffer to hold port available extent count.
5584 * @extnt_size: buffer to hold element count per extent.
5586 * This function calls the port and retrievs the number of available
5587 * extents and their size for a particular extent type.
5589 * Returns: 0 if successful. Nonzero otherwise.
5592 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
5593 uint16_t *extnt_count, uint16_t *extnt_size)
5598 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
5601 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5605 /* Find out how many extents are available for this resource type */
5606 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
5607 sizeof(struct lpfc_sli4_cfg_mhdr));
5608 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5609 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
5610 length, LPFC_SLI4_MBX_EMBED);
5612 /* Send an extents count of 0 - the GET doesn't use it. */
5613 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5614 LPFC_SLI4_MBX_EMBED);
5620 if (!phba->sli4_hba.intr_enable)
5621 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5623 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5624 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5631 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
5632 if (bf_get(lpfc_mbox_hdr_status,
5633 &rsrc_info->header.cfg_shdr.response)) {
5634 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5635 "2930 Failed to get resource extents "
5636 "Status 0x%x Add'l Status 0x%x\n",
5637 bf_get(lpfc_mbox_hdr_status,
5638 &rsrc_info->header.cfg_shdr.response),
5639 bf_get(lpfc_mbox_hdr_add_status,
5640 &rsrc_info->header.cfg_shdr.response));
5645 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
5647 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
5650 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5651 "3162 Retrieved extents type-%d from port: count:%d, "
5652 "size:%d\n", type, *extnt_count, *extnt_size);
5655 mempool_free(mbox, phba->mbox_mem_pool);
5660 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5661 * @phba: Pointer to HBA context object.
5662 * @type: The extent type to check.
5664 * This function reads the current available extents from the port and checks
5665 * if the extent count or extent size has changed since the last access.
5666 * Callers use this routine post port reset to understand if there is a
5667 * extent reprovisioning requirement.
5670 * -Error: error indicates problem.
5671 * 1: Extent count or size has changed.
5675 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
5677 uint16_t curr_ext_cnt, rsrc_ext_cnt;
5678 uint16_t size_diff, rsrc_ext_size;
5680 struct lpfc_rsrc_blks *rsrc_entry;
5681 struct list_head *rsrc_blk_list = NULL;
5685 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5692 case LPFC_RSC_TYPE_FCOE_RPI:
5693 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5695 case LPFC_RSC_TYPE_FCOE_VPI:
5696 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
5698 case LPFC_RSC_TYPE_FCOE_XRI:
5699 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5701 case LPFC_RSC_TYPE_FCOE_VFI:
5702 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5708 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
5710 if (rsrc_entry->rsrc_size != rsrc_ext_size)
5714 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
5721 * lpfc_sli4_cfg_post_extnts -
5722 * @phba: Pointer to HBA context object.
5723 * @extnt_cnt - number of available extents.
5724 * @type - the extent type (rpi, xri, vfi, vpi).
5725 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5726 * @mbox - pointer to the caller's allocated mailbox structure.
5728 * This function executes the extents allocation request. It also
5729 * takes care of the amount of memory needed to allocate or get the
5730 * allocated extents. It is the caller's responsibility to evaluate
5734 * -Error: Error value describes the condition found.
5738 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
5739 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
5744 uint32_t alloc_len, mbox_tmo;
5746 /* Calculate the total requested length of the dma memory */
5747 req_len = extnt_cnt * sizeof(uint16_t);
5750 * Calculate the size of an embedded mailbox. The uint32_t
5751 * accounts for extents-specific word.
5753 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5757 * Presume the allocation and response will fit into an embedded
5758 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5760 *emb = LPFC_SLI4_MBX_EMBED;
5761 if (req_len > emb_len) {
5762 req_len = extnt_cnt * sizeof(uint16_t) +
5763 sizeof(union lpfc_sli4_cfg_shdr) +
5765 *emb = LPFC_SLI4_MBX_NEMBED;
5768 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5769 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
5771 if (alloc_len < req_len) {
5772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5773 "2982 Allocated DMA memory size (x%x) is "
5774 "less than the requested DMA memory "
5775 "size (x%x)\n", alloc_len, req_len);
5778 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
5782 if (!phba->sli4_hba.intr_enable)
5783 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5785 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5786 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5795 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5796 * @phba: Pointer to HBA context object.
5797 * @type: The resource extent type to allocate.
5799 * This function allocates the number of elements for the specified
5803 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
5806 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
5807 uint16_t rsrc_id, rsrc_start, j, k;
5810 unsigned long longs;
5811 unsigned long *bmask;
5812 struct lpfc_rsrc_blks *rsrc_blks;
5815 struct lpfc_id_range *id_array = NULL;
5816 void *virtaddr = NULL;
5817 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5818 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5819 struct list_head *ext_blk_list;
5821 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5827 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
5828 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5829 "3009 No available Resource Extents "
5830 "for resource type 0x%x: Count: 0x%x, "
5831 "Size 0x%x\n", type, rsrc_cnt,
5836 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
5837 "2903 Post resource extents type-0x%x: "
5838 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
5840 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5844 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
5851 * Figure out where the response is located. Then get local pointers
5852 * to the response data. The port does not guarantee to respond to
5853 * all extents counts request so update the local variable with the
5854 * allocated count from the port.
5856 if (emb == LPFC_SLI4_MBX_EMBED) {
5857 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
5858 id_array = &rsrc_ext->u.rsp.id[0];
5859 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
5861 virtaddr = mbox->sge_array->addr[0];
5862 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
5863 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
5864 id_array = &n_rsrc->id;
5867 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
5868 rsrc_id_cnt = rsrc_cnt * rsrc_size;
5871 * Based on the resource size and count, correct the base and max
5874 length = sizeof(struct lpfc_rsrc_blks);
5876 case LPFC_RSC_TYPE_FCOE_RPI:
5877 phba->sli4_hba.rpi_bmask = kcalloc(longs,
5878 sizeof(unsigned long),
5880 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
5884 phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
5887 if (unlikely(!phba->sli4_hba.rpi_ids)) {
5888 kfree(phba->sli4_hba.rpi_bmask);
5894 * The next_rpi was initialized with the maximum available
5895 * count but the port may allocate a smaller number. Catch
5896 * that case and update the next_rpi.
5898 phba->sli4_hba.next_rpi = rsrc_id_cnt;
5900 /* Initialize local ptrs for common extent processing later. */
5901 bmask = phba->sli4_hba.rpi_bmask;
5902 ids = phba->sli4_hba.rpi_ids;
5903 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5905 case LPFC_RSC_TYPE_FCOE_VPI:
5906 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
5908 if (unlikely(!phba->vpi_bmask)) {
5912 phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
5914 if (unlikely(!phba->vpi_ids)) {
5915 kfree(phba->vpi_bmask);
5920 /* Initialize local ptrs for common extent processing later. */
5921 bmask = phba->vpi_bmask;
5922 ids = phba->vpi_ids;
5923 ext_blk_list = &phba->lpfc_vpi_blk_list;
5925 case LPFC_RSC_TYPE_FCOE_XRI:
5926 phba->sli4_hba.xri_bmask = kcalloc(longs,
5927 sizeof(unsigned long),
5929 if (unlikely(!phba->sli4_hba.xri_bmask)) {
5933 phba->sli4_hba.max_cfg_param.xri_used = 0;
5934 phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
5937 if (unlikely(!phba->sli4_hba.xri_ids)) {
5938 kfree(phba->sli4_hba.xri_bmask);
5943 /* Initialize local ptrs for common extent processing later. */
5944 bmask = phba->sli4_hba.xri_bmask;
5945 ids = phba->sli4_hba.xri_ids;
5946 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5948 case LPFC_RSC_TYPE_FCOE_VFI:
5949 phba->sli4_hba.vfi_bmask = kcalloc(longs,
5950 sizeof(unsigned long),
5952 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
5956 phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
5959 if (unlikely(!phba->sli4_hba.vfi_ids)) {
5960 kfree(phba->sli4_hba.vfi_bmask);
5965 /* Initialize local ptrs for common extent processing later. */
5966 bmask = phba->sli4_hba.vfi_bmask;
5967 ids = phba->sli4_hba.vfi_ids;
5968 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5971 /* Unsupported Opcode. Fail call. */
5975 ext_blk_list = NULL;
5980 * Complete initializing the extent configuration with the
5981 * allocated ids assigned to this function. The bitmask serves
5982 * as an index into the array and manages the available ids. The
5983 * array just stores the ids communicated to the port via the wqes.
5985 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
5987 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
5990 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
5993 rsrc_blks = kzalloc(length, GFP_KERNEL);
5994 if (unlikely(!rsrc_blks)) {
6000 rsrc_blks->rsrc_start = rsrc_id;
6001 rsrc_blks->rsrc_size = rsrc_size;
6002 list_add_tail(&rsrc_blks->list, ext_blk_list);
6003 rsrc_start = rsrc_id;
6004 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
6005 phba->sli4_hba.io_xri_start = rsrc_start +
6006 lpfc_sli4_get_iocb_cnt(phba);
6009 while (rsrc_id < (rsrc_start + rsrc_size)) {
6014 /* Entire word processed. Get next word.*/
6019 lpfc_sli4_mbox_cmd_free(phba, mbox);
6026 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
6027 * @phba: Pointer to HBA context object.
6028 * @type: the extent's type.
6030 * This function deallocates all extents of a particular resource type.
6031 * SLI4 does not allow for deallocating a particular extent range. It
6032 * is the caller's responsibility to release all kernel memory resources.
6035 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
6038 uint32_t length, mbox_tmo = 0;
6040 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
6041 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
6043 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6048 * This function sends an embedded mailbox because it only sends the
6049 * the resource type. All extents of this type are released by the
6052 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
6053 sizeof(struct lpfc_sli4_cfg_mhdr));
6054 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6055 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
6056 length, LPFC_SLI4_MBX_EMBED);
6058 /* Send an extents count of 0 - the dealloc doesn't use it. */
6059 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6060 LPFC_SLI4_MBX_EMBED);
6065 if (!phba->sli4_hba.intr_enable)
6066 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6068 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6069 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6076 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
6077 if (bf_get(lpfc_mbox_hdr_status,
6078 &dealloc_rsrc->header.cfg_shdr.response)) {
6079 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
6080 "2919 Failed to release resource extents "
6081 "for type %d - Status 0x%x Add'l Status 0x%x. "
6082 "Resource memory not released.\n",
6084 bf_get(lpfc_mbox_hdr_status,
6085 &dealloc_rsrc->header.cfg_shdr.response),
6086 bf_get(lpfc_mbox_hdr_add_status,
6087 &dealloc_rsrc->header.cfg_shdr.response));
6092 /* Release kernel memory resources for the specific type. */
6094 case LPFC_RSC_TYPE_FCOE_VPI:
6095 kfree(phba->vpi_bmask);
6096 kfree(phba->vpi_ids);
6097 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6098 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6099 &phba->lpfc_vpi_blk_list, list) {
6100 list_del_init(&rsrc_blk->list);
6103 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6105 case LPFC_RSC_TYPE_FCOE_XRI:
6106 kfree(phba->sli4_hba.xri_bmask);
6107 kfree(phba->sli4_hba.xri_ids);
6108 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6109 &phba->sli4_hba.lpfc_xri_blk_list, list) {
6110 list_del_init(&rsrc_blk->list);
6114 case LPFC_RSC_TYPE_FCOE_VFI:
6115 kfree(phba->sli4_hba.vfi_bmask);
6116 kfree(phba->sli4_hba.vfi_ids);
6117 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6118 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6119 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
6120 list_del_init(&rsrc_blk->list);
6124 case LPFC_RSC_TYPE_FCOE_RPI:
6125 /* RPI bitmask and physical id array are cleaned up earlier. */
6126 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6127 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
6128 list_del_init(&rsrc_blk->list);
6136 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6139 mempool_free(mbox, phba->mbox_mem_pool);
6144 lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
6149 len = sizeof(struct lpfc_mbx_set_feature) -
6150 sizeof(struct lpfc_sli4_cfg_mhdr);
6151 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6152 LPFC_MBOX_OPCODE_SET_FEATURES, len,
6153 LPFC_SLI4_MBX_EMBED);
6156 case LPFC_SET_UE_RECOVERY:
6157 bf_set(lpfc_mbx_set_feature_UER,
6158 &mbox->u.mqe.un.set_feature, 1);
6159 mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
6160 mbox->u.mqe.un.set_feature.param_len = 8;
6162 case LPFC_SET_MDS_DIAGS:
6163 bf_set(lpfc_mbx_set_feature_mds,
6164 &mbox->u.mqe.un.set_feature, 1);
6165 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
6166 &mbox->u.mqe.un.set_feature, 1);
6167 mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
6168 mbox->u.mqe.un.set_feature.param_len = 8;
6176 * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
6177 * @phba: Pointer to HBA context object.
6179 * Disable FW logging into host memory on the adapter. To
6180 * be done before reading logs from the host memory.
6183 lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
6185 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6187 ras_fwlog->ras_active = false;
6189 /* Disable FW logging to host memory */
6190 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
6191 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
6195 * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
6196 * @phba: Pointer to HBA context object.
6198 * This function is called to free memory allocated for RAS FW logging
6199 * support in the driver.
6202 lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
6204 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6205 struct lpfc_dmabuf *dmabuf, *next;
6207 if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
6208 list_for_each_entry_safe(dmabuf, next,
6209 &ras_fwlog->fwlog_buff_list,
6211 list_del(&dmabuf->list);
6212 dma_free_coherent(&phba->pcidev->dev,
6213 LPFC_RAS_MAX_ENTRY_SIZE,
6214 dmabuf->virt, dmabuf->phys);
6219 if (ras_fwlog->lwpd.virt) {
6220 dma_free_coherent(&phba->pcidev->dev,
6221 sizeof(uint32_t) * 2,
6222 ras_fwlog->lwpd.virt,
6223 ras_fwlog->lwpd.phys);
6224 ras_fwlog->lwpd.virt = NULL;
6227 ras_fwlog->ras_active = false;
6231 * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
6232 * @phba: Pointer to HBA context object.
6233 * @fwlog_buff_count: Count of buffers to be created.
6235 * This routine DMA memory for Log Write Position Data[LPWD] and buffer
6236 * to update FW log is posted to the adapter.
6237 * Buffer count is calculated based on module param ras_fwlog_buffsize
6238 * Size of each buffer posted to FW is 64K.
6242 lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
6243 uint32_t fwlog_buff_count)
6245 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6246 struct lpfc_dmabuf *dmabuf;
6249 /* Initialize List */
6250 INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
6252 /* Allocate memory for the LWPD */
6253 ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
6254 sizeof(uint32_t) * 2,
6255 &ras_fwlog->lwpd.phys,
6257 if (!ras_fwlog->lwpd.virt) {
6258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6259 "6185 LWPD Memory Alloc Failed\n");
6264 ras_fwlog->fw_buffcount = fwlog_buff_count;
6265 for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
6266 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
6270 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6271 "6186 Memory Alloc failed FW logging");
6275 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6276 LPFC_RAS_MAX_ENTRY_SIZE,
6277 &dmabuf->phys, GFP_KERNEL);
6278 if (!dmabuf->virt) {
6281 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6282 "6187 DMA Alloc Failed FW logging");
6285 dmabuf->buffer_tag = i;
6286 list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
6291 lpfc_sli4_ras_dma_free(phba);
6297 * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
6298 * @phba: pointer to lpfc hba data structure.
6299 * @pmboxq: pointer to the driver internal queue element for mailbox command.
6301 * Completion handler for driver's RAS MBX command to the device.
6304 lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6307 union lpfc_sli4_cfg_shdr *shdr;
6308 uint32_t shdr_status, shdr_add_status;
6309 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6313 shdr = (union lpfc_sli4_cfg_shdr *)
6314 &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
6315 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6316 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6318 if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
6319 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
6320 "6188 FW LOG mailbox "
6321 "completed with status x%x add_status x%x,"
6322 " mbx status x%x\n",
6323 shdr_status, shdr_add_status, mb->mbxStatus);
6325 ras_fwlog->ras_hwsupport = false;
6329 ras_fwlog->ras_active = true;
6330 mempool_free(pmb, phba->mbox_mem_pool);
6335 /* Free RAS DMA memory */
6336 lpfc_sli4_ras_dma_free(phba);
6337 mempool_free(pmb, phba->mbox_mem_pool);
6341 * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
6342 * @phba: pointer to lpfc hba data structure.
6343 * @fwlog_level: Logging verbosity level.
6344 * @fwlog_enable: Enable/Disable logging.
6346 * Initialize memory and post mailbox command to enable FW logging in host
6350 lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
6351 uint32_t fwlog_level,
6352 uint32_t fwlog_enable)
6354 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6355 struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
6356 struct lpfc_dmabuf *dmabuf;
6358 uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
6361 fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
6362 phba->cfg_ras_fwlog_buffsize);
6363 fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
6366 * If re-enabling FW logging support use earlier allocated
6367 * DMA buffers while posting MBX command.
6369 if (!ras_fwlog->lwpd.virt) {
6370 rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
6372 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6373 "6189 FW Log Memory Allocation Failed");
6378 /* Setup Mailbox command */
6379 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6381 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6382 "6190 RAS MBX Alloc Failed");
6387 ras_fwlog->fw_loglevel = fwlog_level;
6388 len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
6389 sizeof(struct lpfc_sli4_cfg_mhdr));
6391 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
6392 LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
6393 len, LPFC_SLI4_MBX_EMBED);
6395 mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
6396 bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
6398 bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
6399 ras_fwlog->fw_loglevel);
6400 bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
6401 ras_fwlog->fw_buffcount);
6402 bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
6403 LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
6405 /* Update DMA buffer address */
6406 list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
6407 memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
6409 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
6410 putPaddrLow(dmabuf->phys);
6412 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
6413 putPaddrHigh(dmabuf->phys);
6416 /* Update LPWD address */
6417 mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
6418 mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
6420 mbox->vport = phba->pport;
6421 mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
6423 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6425 if (rc == MBX_NOT_FINISHED) {
6426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6427 "6191 FW-Log Mailbox failed. "
6428 "status %d mbxStatus : x%x", rc,
6429 bf_get(lpfc_mqe_status, &mbox->u.mqe));
6430 mempool_free(mbox, phba->mbox_mem_pool);
6437 lpfc_sli4_ras_dma_free(phba);
6443 * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
6444 * @phba: Pointer to HBA context object.
6446 * Check if RAS is supported on the adapter and initialize it.
6449 lpfc_sli4_ras_setup(struct lpfc_hba *phba)
6451 /* Check RAS FW Log needs to be enabled or not */
6452 if (lpfc_check_fwlog_support(phba))
6455 lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6456 LPFC_RAS_ENABLE_LOGGING);
6460 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
6461 * @phba: Pointer to HBA context object.
6463 * This function allocates all SLI4 resource identifiers.
6466 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
6468 int i, rc, error = 0;
6469 uint16_t count, base;
6470 unsigned long longs;
6472 if (!phba->sli4_hba.rpi_hdrs_in_use)
6473 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
6474 if (phba->sli4_hba.extents_in_use) {
6476 * The port supports resource extents. The XRI, VPI, VFI, RPI
6477 * resource extent count must be read and allocated before
6478 * provisioning the resource id arrays.
6480 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
6481 LPFC_IDX_RSRC_RDY) {
6483 * Extent-based resources are set - the driver could
6484 * be in a port reset. Figure out if any corrective
6485 * actions need to be taken.
6487 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6488 LPFC_RSC_TYPE_FCOE_VFI);
6491 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6492 LPFC_RSC_TYPE_FCOE_VPI);
6495 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6496 LPFC_RSC_TYPE_FCOE_XRI);
6499 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6500 LPFC_RSC_TYPE_FCOE_RPI);
6505 * It's possible that the number of resources
6506 * provided to this port instance changed between
6507 * resets. Detect this condition and reallocate
6508 * resources. Otherwise, there is no action.
6511 lpfc_printf_log(phba, KERN_INFO,
6512 LOG_MBOX | LOG_INIT,
6513 "2931 Detected extent resource "
6514 "change. Reallocating all "
6516 rc = lpfc_sli4_dealloc_extent(phba,
6517 LPFC_RSC_TYPE_FCOE_VFI);
6518 rc = lpfc_sli4_dealloc_extent(phba,
6519 LPFC_RSC_TYPE_FCOE_VPI);
6520 rc = lpfc_sli4_dealloc_extent(phba,
6521 LPFC_RSC_TYPE_FCOE_XRI);
6522 rc = lpfc_sli4_dealloc_extent(phba,
6523 LPFC_RSC_TYPE_FCOE_RPI);
6528 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
6532 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
6536 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
6540 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
6543 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6548 * The port does not support resource extents. The XRI, VPI,
6549 * VFI, RPI resource ids were determined from READ_CONFIG.
6550 * Just allocate the bitmasks and provision the resource id
6551 * arrays. If a port reset is active, the resources don't
6552 * need any action - just exit.
6554 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
6555 LPFC_IDX_RSRC_RDY) {
6556 lpfc_sli4_dealloc_resource_identifiers(phba);
6557 lpfc_sli4_remove_rpis(phba);
6560 count = phba->sli4_hba.max_cfg_param.max_rpi;
6562 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6563 "3279 Invalid provisioning of "
6568 base = phba->sli4_hba.max_cfg_param.rpi_base;
6569 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6570 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6571 sizeof(unsigned long),
6573 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6577 phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
6579 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6581 goto free_rpi_bmask;
6584 for (i = 0; i < count; i++)
6585 phba->sli4_hba.rpi_ids[i] = base + i;
6588 count = phba->sli4_hba.max_cfg_param.max_vpi;
6590 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6591 "3280 Invalid provisioning of "
6596 base = phba->sli4_hba.max_cfg_param.vpi_base;
6597 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6598 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6600 if (unlikely(!phba->vpi_bmask)) {
6604 phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
6606 if (unlikely(!phba->vpi_ids)) {
6608 goto free_vpi_bmask;
6611 for (i = 0; i < count; i++)
6612 phba->vpi_ids[i] = base + i;
6615 count = phba->sli4_hba.max_cfg_param.max_xri;
6617 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6618 "3281 Invalid provisioning of "
6623 base = phba->sli4_hba.max_cfg_param.xri_base;
6624 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6625 phba->sli4_hba.xri_bmask = kcalloc(longs,
6626 sizeof(unsigned long),
6628 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6632 phba->sli4_hba.max_cfg_param.xri_used = 0;
6633 phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
6635 if (unlikely(!phba->sli4_hba.xri_ids)) {
6637 goto free_xri_bmask;
6640 for (i = 0; i < count; i++)
6641 phba->sli4_hba.xri_ids[i] = base + i;
6644 count = phba->sli4_hba.max_cfg_param.max_vfi;
6646 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6647 "3282 Invalid provisioning of "
6652 base = phba->sli4_hba.max_cfg_param.vfi_base;
6653 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6654 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6655 sizeof(unsigned long),
6657 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6661 phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
6663 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6665 goto free_vfi_bmask;
6668 for (i = 0; i < count; i++)
6669 phba->sli4_hba.vfi_ids[i] = base + i;
6672 * Mark all resources ready. An HBA reset doesn't need
6673 * to reset the initialization.
6675 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6681 kfree(phba->sli4_hba.vfi_bmask);
6682 phba->sli4_hba.vfi_bmask = NULL;
6684 kfree(phba->sli4_hba.xri_ids);
6685 phba->sli4_hba.xri_ids = NULL;
6687 kfree(phba->sli4_hba.xri_bmask);
6688 phba->sli4_hba.xri_bmask = NULL;
6690 kfree(phba->vpi_ids);
6691 phba->vpi_ids = NULL;
6693 kfree(phba->vpi_bmask);
6694 phba->vpi_bmask = NULL;
6696 kfree(phba->sli4_hba.rpi_ids);
6697 phba->sli4_hba.rpi_ids = NULL;
6699 kfree(phba->sli4_hba.rpi_bmask);
6700 phba->sli4_hba.rpi_bmask = NULL;
6706 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6707 * @phba: Pointer to HBA context object.
6709 * This function allocates the number of elements for the specified
6713 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
6715 if (phba->sli4_hba.extents_in_use) {
6716 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
6717 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
6718 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
6719 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
6721 kfree(phba->vpi_bmask);
6722 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6723 kfree(phba->vpi_ids);
6724 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6725 kfree(phba->sli4_hba.xri_bmask);
6726 kfree(phba->sli4_hba.xri_ids);
6727 kfree(phba->sli4_hba.vfi_bmask);
6728 kfree(phba->sli4_hba.vfi_ids);
6729 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6730 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6737 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6738 * @phba: Pointer to HBA context object.
6739 * @type: The resource extent type.
6740 * @extnt_count: buffer to hold port extent count response
6741 * @extnt_size: buffer to hold port extent size response.
6743 * This function calls the port to read the host allocated extents
6744 * for a particular type.
6747 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
6748 uint16_t *extnt_cnt, uint16_t *extnt_size)
6752 uint16_t curr_blks = 0;
6753 uint32_t req_len, emb_len;
6754 uint32_t alloc_len, mbox_tmo;
6755 struct list_head *blk_list_head;
6756 struct lpfc_rsrc_blks *rsrc_blk;
6758 void *virtaddr = NULL;
6759 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
6760 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
6761 union lpfc_sli4_cfg_shdr *shdr;
6764 case LPFC_RSC_TYPE_FCOE_VPI:
6765 blk_list_head = &phba->lpfc_vpi_blk_list;
6767 case LPFC_RSC_TYPE_FCOE_XRI:
6768 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
6770 case LPFC_RSC_TYPE_FCOE_VFI:
6771 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
6773 case LPFC_RSC_TYPE_FCOE_RPI:
6774 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
6780 /* Count the number of extents currently allocatd for this type. */
6781 list_for_each_entry(rsrc_blk, blk_list_head, list) {
6782 if (curr_blks == 0) {
6784 * The GET_ALLOCATED mailbox does not return the size,
6785 * just the count. The size should be just the size
6786 * stored in the current allocated block and all sizes
6787 * for an extent type are the same so set the return
6790 *extnt_size = rsrc_blk->rsrc_size;
6796 * Calculate the size of an embedded mailbox. The uint32_t
6797 * accounts for extents-specific word.
6799 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
6803 * Presume the allocation and response will fit into an embedded
6804 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6806 emb = LPFC_SLI4_MBX_EMBED;
6808 if (req_len > emb_len) {
6809 req_len = curr_blks * sizeof(uint16_t) +
6810 sizeof(union lpfc_sli4_cfg_shdr) +
6812 emb = LPFC_SLI4_MBX_NEMBED;
6815 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6818 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
6820 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6821 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
6823 if (alloc_len < req_len) {
6824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6825 "2983 Allocated DMA memory size (x%x) is "
6826 "less than the requested DMA memory "
6827 "size (x%x)\n", alloc_len, req_len);
6831 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
6837 if (!phba->sli4_hba.intr_enable)
6838 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6840 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6841 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6850 * Figure out where the response is located. Then get local pointers
6851 * to the response data. The port does not guarantee to respond to
6852 * all extents counts request so update the local variable with the
6853 * allocated count from the port.
6855 if (emb == LPFC_SLI4_MBX_EMBED) {
6856 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
6857 shdr = &rsrc_ext->header.cfg_shdr;
6858 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
6860 virtaddr = mbox->sge_array->addr[0];
6861 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6862 shdr = &n_rsrc->cfg_shdr;
6863 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6866 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
6867 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
6868 "2984 Failed to read allocated resources "
6869 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6871 bf_get(lpfc_mbox_hdr_status, &shdr->response),
6872 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
6877 lpfc_sli4_mbox_cmd_free(phba, mbox);
6882 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
6883 * @phba: pointer to lpfc hba data structure.
6884 * @pring: Pointer to driver SLI ring object.
6885 * @sgl_list: linked link of sgl buffers to post
6886 * @cnt: number of linked list buffers
6888 * This routine walks the list of buffers that have been allocated and
6889 * repost them to the port by using SGL block post. This is needed after a
6890 * pci_function_reset/warm_start or start. It attempts to construct blocks
6891 * of buffer sgls which contains contiguous xris and uses the non-embedded
6892 * SGL block post mailbox commands to post them to the port. For single
6893 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6894 * mailbox command for posting.
6896 * Returns: 0 = success, non-zero failure.
6899 lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
6900 struct list_head *sgl_list, int cnt)
6902 struct lpfc_sglq *sglq_entry = NULL;
6903 struct lpfc_sglq *sglq_entry_next = NULL;
6904 struct lpfc_sglq *sglq_entry_first = NULL;
6905 int status, total_cnt;
6906 int post_cnt = 0, num_posted = 0, block_cnt = 0;
6907 int last_xritag = NO_XRI;
6908 LIST_HEAD(prep_sgl_list);
6909 LIST_HEAD(blck_sgl_list);
6910 LIST_HEAD(allc_sgl_list);
6911 LIST_HEAD(post_sgl_list);
6912 LIST_HEAD(free_sgl_list);
6914 spin_lock_irq(&phba->hbalock);
6915 spin_lock(&phba->sli4_hba.sgl_list_lock);
6916 list_splice_init(sgl_list, &allc_sgl_list);
6917 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6918 spin_unlock_irq(&phba->hbalock);
6921 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
6922 &allc_sgl_list, list) {
6923 list_del_init(&sglq_entry->list);
6925 if ((last_xritag != NO_XRI) &&
6926 (sglq_entry->sli4_xritag != last_xritag + 1)) {
6927 /* a hole in xri block, form a sgl posting block */
6928 list_splice_init(&prep_sgl_list, &blck_sgl_list);
6929 post_cnt = block_cnt - 1;
6930 /* prepare list for next posting block */
6931 list_add_tail(&sglq_entry->list, &prep_sgl_list);
6934 /* prepare list for next posting block */
6935 list_add_tail(&sglq_entry->list, &prep_sgl_list);
6936 /* enough sgls for non-embed sgl mbox command */
6937 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
6938 list_splice_init(&prep_sgl_list,
6940 post_cnt = block_cnt;
6946 /* keep track of last sgl's xritag */
6947 last_xritag = sglq_entry->sli4_xritag;
6949 /* end of repost sgl list condition for buffers */
6950 if (num_posted == total_cnt) {
6951 if (post_cnt == 0) {
6952 list_splice_init(&prep_sgl_list,
6954 post_cnt = block_cnt;
6955 } else if (block_cnt == 1) {
6956 status = lpfc_sli4_post_sgl(phba,
6957 sglq_entry->phys, 0,
6958 sglq_entry->sli4_xritag);
6960 /* successful, put sgl to posted list */
6961 list_add_tail(&sglq_entry->list,
6964 /* Failure, put sgl to free list */
6965 lpfc_printf_log(phba, KERN_WARNING,
6967 "3159 Failed to post "
6968 "sgl, xritag:x%x\n",
6969 sglq_entry->sli4_xritag);
6970 list_add_tail(&sglq_entry->list,
6977 /* continue until a nembed page worth of sgls */
6981 /* post the buffer list sgls as a block */
6982 status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
6986 /* success, put sgl list to posted sgl list */
6987 list_splice_init(&blck_sgl_list, &post_sgl_list);
6989 /* Failure, put sgl list to free sgl list */
6990 sglq_entry_first = list_first_entry(&blck_sgl_list,
6993 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6994 "3160 Failed to post sgl-list, "
6996 sglq_entry_first->sli4_xritag,
6997 (sglq_entry_first->sli4_xritag +
6999 list_splice_init(&blck_sgl_list, &free_sgl_list);
7000 total_cnt -= post_cnt;
7003 /* don't reset xirtag due to hole in xri block */
7005 last_xritag = NO_XRI;
7007 /* reset sgl post count for next round of posting */
7011 /* free the sgls failed to post */
7012 lpfc_free_sgl_list(phba, &free_sgl_list);
7014 /* push sgls posted to the available list */
7015 if (!list_empty(&post_sgl_list)) {
7016 spin_lock_irq(&phba->hbalock);
7017 spin_lock(&phba->sli4_hba.sgl_list_lock);
7018 list_splice_init(&post_sgl_list, sgl_list);
7019 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7020 spin_unlock_irq(&phba->hbalock);
7022 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7023 "3161 Failure to post sgl to port.\n");
7027 /* return the number of XRIs actually posted */
7032 * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
7033 * @phba: pointer to lpfc hba data structure.
7035 * This routine walks the list of nvme buffers that have been allocated and
7036 * repost them to the port by using SGL block post. This is needed after a
7037 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
7038 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
7039 * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
7041 * Returns: 0 = success, non-zero failure.
7044 lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
7046 LIST_HEAD(post_nblist);
7047 int num_posted, rc = 0;
7049 /* get all NVME buffers need to repost to a local list */
7050 lpfc_io_buf_flush(phba, &post_nblist);
7052 /* post the list of nvme buffer sgls to port if available */
7053 if (!list_empty(&post_nblist)) {
7054 num_posted = lpfc_sli4_post_io_sgl_list(
7055 phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
7056 /* failed to post any nvme buffer, return error */
7057 if (num_posted == 0)
7064 lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
7068 len = sizeof(struct lpfc_mbx_set_host_data) -
7069 sizeof(struct lpfc_sli4_cfg_mhdr);
7070 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7071 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
7072 LPFC_SLI4_MBX_EMBED);
7074 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
7075 mbox->u.mqe.un.set_host_data.param_len =
7076 LPFC_HOST_OS_DRIVER_VERSION_SIZE;
7077 snprintf(mbox->u.mqe.un.set_host_data.data,
7078 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
7079 "Linux %s v"LPFC_DRIVER_VERSION,
7080 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
7084 lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7085 struct lpfc_queue *drq, int count, int idx)
7088 struct lpfc_rqe hrqe;
7089 struct lpfc_rqe drqe;
7090 struct lpfc_rqb *rqbp;
7091 unsigned long flags;
7092 struct rqb_dmabuf *rqb_buffer;
7093 LIST_HEAD(rqb_buf_list);
7095 spin_lock_irqsave(&phba->hbalock, flags);
7097 for (i = 0; i < count; i++) {
7098 /* IF RQ is already full, don't bother */
7099 if (rqbp->buffer_count + i >= rqbp->entry_count - 1)
7101 rqb_buffer = rqbp->rqb_alloc_buffer(phba);
7104 rqb_buffer->hrq = hrq;
7105 rqb_buffer->drq = drq;
7106 rqb_buffer->idx = idx;
7107 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7109 while (!list_empty(&rqb_buf_list)) {
7110 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7113 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7114 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7115 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7116 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7117 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7120 "6421 Cannot post to HRQ %d: %x %x %x "
7128 rqbp->rqb_free_buffer(phba, rqb_buffer);
7130 list_add_tail(&rqb_buffer->hbuf.list,
7131 &rqbp->rqb_buffer_list);
7132 rqbp->buffer_count++;
7135 spin_unlock_irqrestore(&phba->hbalock, flags);
7140 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
7141 * @phba: Pointer to HBA context object.
7143 * This function is the main SLI4 device initialization PCI function. This
7144 * function is called by the HBA initialization code, HBA reset code and
7145 * HBA error attention handler code. Caller is not required to hold any
7149 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
7151 int rc, i, cnt, len;
7152 LPFC_MBOXQ_t *mboxq;
7153 struct lpfc_mqe *mqe;
7156 uint32_t ftr_rsp = 0;
7157 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
7158 struct lpfc_vport *vport = phba->pport;
7159 struct lpfc_dmabuf *mp;
7160 struct lpfc_rqb *rqbp;
7162 /* Perform a PCI function reset to start from clean */
7163 rc = lpfc_pci_function_reset(phba);
7167 /* Check the HBA Host Status Register for readyness */
7168 rc = lpfc_sli4_post_status_check(phba);
7172 spin_lock_irq(&phba->hbalock);
7173 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
7174 spin_unlock_irq(&phba->hbalock);
7178 * Allocate a single mailbox container for initializing the
7181 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7185 /* Issue READ_REV to collect vpd and FW information. */
7186 vpd_size = SLI4_PAGE_SIZE;
7187 vpd = kzalloc(vpd_size, GFP_KERNEL);
7193 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
7199 mqe = &mboxq->u.mqe;
7200 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
7201 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
7202 phba->hba_flag |= HBA_FCOE_MODE;
7203 phba->fcp_embed_io = 0; /* SLI4 FC support only */
7205 phba->hba_flag &= ~HBA_FCOE_MODE;
7208 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
7210 phba->hba_flag |= HBA_FIP_SUPPORT;
7212 phba->hba_flag &= ~HBA_FIP_SUPPORT;
7214 phba->hba_flag &= ~HBA_IOQ_FLUSH;
7216 if (phba->sli_rev != LPFC_SLI_REV4) {
7217 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7218 "0376 READ_REV Error. SLI Level %d "
7219 "FCoE enabled %d\n",
7220 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
7227 * Continue initialization with default values even if driver failed
7228 * to read FCoE param config regions, only read parameters if the
7231 if (phba->hba_flag & HBA_FCOE_MODE &&
7232 lpfc_sli4_read_fcoe_params(phba))
7233 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
7234 "2570 Failed to read FCoE parameters\n");
7237 * Retrieve sli4 device physical port name, failure of doing it
7238 * is considered as non-fatal.
7240 rc = lpfc_sli4_retrieve_pport_name(phba);
7242 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7243 "3080 Successful retrieving SLI4 device "
7244 "physical port name: %s.\n", phba->Port);
7246 rc = lpfc_sli4_get_ctl_attr(phba);
7248 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7249 "8351 Successful retrieving SLI4 device "
7253 * Evaluate the read rev and vpd data. Populate the driver
7254 * state with the results. If this routine fails, the failure
7255 * is not fatal as the driver will use generic values.
7257 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
7258 if (unlikely(!rc)) {
7259 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7260 "0377 Error %d parsing vpd. "
7261 "Using defaults.\n", rc);
7266 /* Save information as VPD data */
7267 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
7268 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
7271 * This is because first G7 ASIC doesn't support the standard
7272 * 0x5a NVME cmd descriptor type/subtype
7274 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7275 LPFC_SLI_INTF_IF_TYPE_6) &&
7276 (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
7277 (phba->vpd.rev.smRev == 0) &&
7278 (phba->cfg_nvme_embed_cmd == 1))
7279 phba->cfg_nvme_embed_cmd = 0;
7281 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
7282 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
7284 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
7286 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
7288 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
7290 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
7291 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
7292 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
7293 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
7294 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
7295 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
7296 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7297 "(%d):0380 READ_REV Status x%x "
7298 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
7299 mboxq->vport ? mboxq->vport->vpi : 0,
7300 bf_get(lpfc_mqe_status, mqe),
7301 phba->vpd.rev.opFwName,
7302 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
7303 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
7305 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
7306 rc = (phba->sli4_hba.max_cfg_param.max_xri >> 3);
7307 if (phba->pport->cfg_lun_queue_depth > rc) {
7308 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7309 "3362 LUN queue depth changed from %d to %d\n",
7310 phba->pport->cfg_lun_queue_depth, rc);
7311 phba->pport->cfg_lun_queue_depth = rc;
7314 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7315 LPFC_SLI_INTF_IF_TYPE_0) {
7316 lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
7317 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7318 if (rc == MBX_SUCCESS) {
7319 phba->hba_flag |= HBA_RECOVERABLE_UE;
7320 /* Set 1Sec interval to detect UE */
7321 phba->eratt_poll_interval = 1;
7322 phba->sli4_hba.ue_to_sr = bf_get(
7323 lpfc_mbx_set_feature_UESR,
7324 &mboxq->u.mqe.un.set_feature);
7325 phba->sli4_hba.ue_to_rp = bf_get(
7326 lpfc_mbx_set_feature_UERP,
7327 &mboxq->u.mqe.un.set_feature);
7331 if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
7332 /* Enable MDS Diagnostics only if the SLI Port supports it */
7333 lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
7334 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7335 if (rc != MBX_SUCCESS)
7336 phba->mds_diags_support = 0;
7340 * Discover the port's supported feature set and match it against the
7343 lpfc_request_features(phba, mboxq);
7344 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7351 * The port must support FCP initiator mode as this is the
7352 * only mode running in the host.
7354 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
7355 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7356 "0378 No support for fcpi mode.\n");
7360 /* Performance Hints are ONLY for FCoE */
7361 if (phba->hba_flag & HBA_FCOE_MODE) {
7362 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
7363 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
7365 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
7369 * If the port cannot support the host's requested features
7370 * then turn off the global config parameters to disable the
7371 * feature in the driver. This is not a fatal error.
7373 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
7374 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
7375 phba->cfg_enable_bg = 0;
7376 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
7381 if (phba->max_vpi && phba->cfg_enable_npiv &&
7382 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
7386 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7387 "0379 Feature Mismatch Data: x%08x %08x "
7388 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
7389 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
7390 phba->cfg_enable_npiv, phba->max_vpi);
7391 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
7392 phba->cfg_enable_bg = 0;
7393 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
7394 phba->cfg_enable_npiv = 0;
7397 /* These SLI3 features are assumed in SLI4 */
7398 spin_lock_irq(&phba->hbalock);
7399 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
7400 spin_unlock_irq(&phba->hbalock);
7403 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
7404 * calls depends on these resources to complete port setup.
7406 rc = lpfc_sli4_alloc_resource_identifiers(phba);
7408 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7409 "2920 Failed to alloc Resource IDs "
7414 lpfc_set_host_data(phba, mboxq);
7416 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7418 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7419 "2134 Failed to set host os driver version %x",
7423 /* Read the port's service parameters. */
7424 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
7426 phba->link_state = LPFC_HBA_ERROR;
7431 mboxq->vport = vport;
7432 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7433 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
7434 if (rc == MBX_SUCCESS) {
7435 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
7440 * This memory was allocated by the lpfc_read_sparam routine. Release
7441 * it to the mbuf pool.
7443 lpfc_mbuf_free(phba, mp->virt, mp->phys);
7445 mboxq->ctx_buf = NULL;
7447 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7448 "0382 READ_SPARAM command failed "
7449 "status %d, mbxStatus x%x\n",
7450 rc, bf_get(lpfc_mqe_status, mqe));
7451 phba->link_state = LPFC_HBA_ERROR;
7456 lpfc_update_vport_wwn(vport);
7458 /* Update the fc_host data structures with new wwn. */
7459 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
7460 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
7462 /* Create all the SLI4 queues */
7463 rc = lpfc_sli4_queue_create(phba);
7465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7466 "3089 Failed to allocate queues\n");
7470 /* Set up all the queues to the device */
7471 rc = lpfc_sli4_queue_setup(phba);
7473 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7474 "0381 Error %d during queue setup.\n ", rc);
7475 goto out_stop_timers;
7477 /* Initialize the driver internal SLI layer lists. */
7478 lpfc_sli4_setup(phba);
7479 lpfc_sli4_queue_init(phba);
7481 /* update host els xri-sgl sizes and mappings */
7482 rc = lpfc_sli4_els_sgl_update(phba);
7484 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7485 "1400 Failed to update xri-sgl size and "
7486 "mapping: %d\n", rc);
7487 goto out_destroy_queue;
7490 /* register the els sgl pool to the port */
7491 rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
7492 phba->sli4_hba.els_xri_cnt);
7493 if (unlikely(rc < 0)) {
7494 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7495 "0582 Error %d during els sgl post "
7498 goto out_destroy_queue;
7500 phba->sli4_hba.els_xri_cnt = rc;
7502 if (phba->nvmet_support) {
7503 /* update host nvmet xri-sgl sizes and mappings */
7504 rc = lpfc_sli4_nvmet_sgl_update(phba);
7506 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7507 "6308 Failed to update nvmet-sgl size "
7508 "and mapping: %d\n", rc);
7509 goto out_destroy_queue;
7512 /* register the nvmet sgl pool to the port */
7513 rc = lpfc_sli4_repost_sgl_list(
7515 &phba->sli4_hba.lpfc_nvmet_sgl_list,
7516 phba->sli4_hba.nvmet_xri_cnt);
7517 if (unlikely(rc < 0)) {
7518 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7519 "3117 Error %d during nvmet "
7522 goto out_destroy_queue;
7524 phba->sli4_hba.nvmet_xri_cnt = rc;
7526 cnt = phba->cfg_iocb_cnt * 1024;
7527 /* We need 1 iocbq for every SGL, for IO processing */
7528 cnt += phba->sli4_hba.nvmet_xri_cnt;
7530 /* update host common xri-sgl sizes and mappings */
7531 rc = lpfc_sli4_io_sgl_update(phba);
7533 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7534 "6082 Failed to update nvme-sgl size "
7535 "and mapping: %d\n", rc);
7536 goto out_destroy_queue;
7539 /* register the allocated common sgl pool to the port */
7540 rc = lpfc_sli4_repost_io_sgl_list(phba);
7542 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7543 "6116 Error %d during nvme sgl post "
7545 /* Some NVME buffers were moved to abort nvme list */
7546 /* A pci function reset will repost them */
7548 goto out_destroy_queue;
7550 cnt = phba->cfg_iocb_cnt * 1024;
7553 if (!phba->sli.iocbq_lookup) {
7554 /* Initialize and populate the iocb list per host */
7555 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7556 "2821 initialize iocb list %d total %d\n",
7557 phba->cfg_iocb_cnt, cnt);
7558 rc = lpfc_init_iocb_list(phba, cnt);
7560 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7561 "1413 Failed to init iocb list.\n");
7562 goto out_destroy_queue;
7566 if (phba->nvmet_support)
7567 lpfc_nvmet_create_targetport(phba);
7569 if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
7570 /* Post initial buffers to all RQs created */
7571 for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
7572 rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
7573 INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
7574 rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
7575 rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
7576 rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
7577 rqbp->buffer_count = 0;
7579 lpfc_post_rq_buffer(
7580 phba, phba->sli4_hba.nvmet_mrq_hdr[i],
7581 phba->sli4_hba.nvmet_mrq_data[i],
7582 phba->cfg_nvmet_mrq_post, i);
7586 /* Post the rpi header region to the device. */
7587 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
7589 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7590 "0393 Error %d during rpi post operation\n",
7593 goto out_destroy_queue;
7595 lpfc_sli4_node_prep(phba);
7597 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
7598 if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
7600 * The FC Port needs to register FCFI (index 0)
7602 lpfc_reg_fcfi(phba, mboxq);
7603 mboxq->vport = phba->pport;
7604 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7605 if (rc != MBX_SUCCESS)
7606 goto out_unset_queue;
7608 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
7609 &mboxq->u.mqe.un.reg_fcfi);
7611 /* We are a NVME Target mode with MRQ > 1 */
7613 /* First register the FCFI */
7614 lpfc_reg_fcfi_mrq(phba, mboxq, 0);
7615 mboxq->vport = phba->pport;
7616 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7617 if (rc != MBX_SUCCESS)
7618 goto out_unset_queue;
7620 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
7621 &mboxq->u.mqe.un.reg_fcfi_mrq);
7623 /* Next register the MRQs */
7624 lpfc_reg_fcfi_mrq(phba, mboxq, 1);
7625 mboxq->vport = phba->pport;
7626 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7627 if (rc != MBX_SUCCESS)
7628 goto out_unset_queue;
7631 /* Check if the port is configured to be disabled */
7632 lpfc_sli_read_link_ste(phba);
7635 /* Don't post more new bufs if repost already recovered
7638 if (phba->nvmet_support == 0) {
7639 if (phba->sli4_hba.io_xri_cnt == 0) {
7640 len = lpfc_new_io_buf(
7641 phba, phba->sli4_hba.io_xri_max);
7644 goto out_unset_queue;
7647 if (phba->cfg_xri_rebalancing)
7648 lpfc_create_multixri_pools(phba);
7651 phba->cfg_xri_rebalancing = 0;
7654 /* Allow asynchronous mailbox command to go through */
7655 spin_lock_irq(&phba->hbalock);
7656 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7657 spin_unlock_irq(&phba->hbalock);
7659 /* Post receive buffers to the device */
7660 lpfc_sli4_rb_setup(phba);
7662 /* Reset HBA FCF states after HBA reset */
7663 phba->fcf.fcf_flag = 0;
7664 phba->fcf.current_rec.flag = 0;
7666 /* Start the ELS watchdog timer */
7667 mod_timer(&vport->els_tmofunc,
7668 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
7670 /* Start heart beat timer */
7671 mod_timer(&phba->hb_tmofunc,
7672 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
7673 phba->hb_outstanding = 0;
7674 phba->last_completion_time = jiffies;
7676 /* start eq_delay heartbeat */
7677 if (phba->cfg_auto_imax)
7678 queue_delayed_work(phba->wq, &phba->eq_delay_work,
7679 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
7681 /* Start error attention (ERATT) polling timer */
7682 mod_timer(&phba->eratt_poll,
7683 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
7685 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
7686 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
7687 rc = pci_enable_pcie_error_reporting(phba->pcidev);
7689 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7690 "2829 This device supports "
7691 "Advanced Error Reporting (AER)\n");
7692 spin_lock_irq(&phba->hbalock);
7693 phba->hba_flag |= HBA_AER_ENABLED;
7694 spin_unlock_irq(&phba->hbalock);
7696 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7697 "2830 This device does not support "
7698 "Advanced Error Reporting (AER)\n");
7699 phba->cfg_aer_support = 0;
7705 * The port is ready, set the host's link state to LINK_DOWN
7706 * in preparation for link interrupts.
7708 spin_lock_irq(&phba->hbalock);
7709 phba->link_state = LPFC_LINK_DOWN;
7711 /* Check if physical ports are trunked */
7712 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
7713 phba->trunk_link.link0.state = LPFC_LINK_DOWN;
7714 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
7715 phba->trunk_link.link1.state = LPFC_LINK_DOWN;
7716 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
7717 phba->trunk_link.link2.state = LPFC_LINK_DOWN;
7718 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
7719 phba->trunk_link.link3.state = LPFC_LINK_DOWN;
7720 spin_unlock_irq(&phba->hbalock);
7722 /* Arm the CQs and then EQs on device */
7723 lpfc_sli4_arm_cqeq_intr(phba);
7725 /* Indicate device interrupt mode */
7726 phba->sli4_hba.intr_enable = 1;
7728 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
7729 (phba->hba_flag & LINK_DISABLED)) {
7730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
7731 "3103 Adapter Link is disabled.\n");
7732 lpfc_down_link(phba, mboxq);
7733 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7734 if (rc != MBX_SUCCESS) {
7735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
7736 "3104 Adapter failed to issue "
7737 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
7738 goto out_io_buff_free;
7740 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
7741 /* don't perform init_link on SLI4 FC port loopback test */
7742 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
7743 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
7745 goto out_io_buff_free;
7748 mempool_free(mboxq, phba->mbox_mem_pool);
7751 /* Free allocated IO Buffers */
7754 /* Unset all the queues set up in this routine when error out */
7755 lpfc_sli4_queue_unset(phba);
7757 lpfc_free_iocb_list(phba);
7758 lpfc_sli4_queue_destroy(phba);
7760 lpfc_stop_hba_timers(phba);
7762 mempool_free(mboxq, phba->mbox_mem_pool);
7767 * lpfc_mbox_timeout - Timeout call back function for mbox timer
7768 * @ptr: context object - pointer to hba structure.
7770 * This is the callback function for mailbox timer. The mailbox
7771 * timer is armed when a new mailbox command is issued and the timer
7772 * is deleted when the mailbox complete. The function is called by
7773 * the kernel timer code when a mailbox does not complete within
7774 * expected time. This function wakes up the worker thread to
7775 * process the mailbox timeout and returns. All the processing is
7776 * done by the worker thread function lpfc_mbox_timeout_handler.
7779 lpfc_mbox_timeout(struct timer_list *t)
7781 struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo);
7782 unsigned long iflag;
7783 uint32_t tmo_posted;
7785 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
7786 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
7788 phba->pport->work_port_events |= WORKER_MBOX_TMO;
7789 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
7792 lpfc_worker_wake_up(phba);
7797 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
7799 * @phba: Pointer to HBA context object.
7801 * This function checks if any mailbox completions are present on the mailbox
7805 lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
7809 struct lpfc_queue *mcq;
7810 struct lpfc_mcqe *mcqe;
7811 bool pending_completions = false;
7814 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
7817 /* Check for completions on mailbox completion queue */
7819 mcq = phba->sli4_hba.mbx_cq;
7820 idx = mcq->hba_index;
7821 qe_valid = mcq->qe_valid;
7822 while (bf_get_le32(lpfc_cqe_valid,
7823 (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
7824 mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
7825 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
7826 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
7827 pending_completions = true;
7830 idx = (idx + 1) % mcq->entry_count;
7831 if (mcq->hba_index == idx)
7834 /* if the index wrapped around, toggle the valid bit */
7835 if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
7836 qe_valid = (qe_valid) ? 0 : 1;
7838 return pending_completions;
7843 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
7845 * @phba: Pointer to HBA context object.
7847 * For sli4, it is possible to miss an interrupt. As such mbox completions
7848 * maybe missed causing erroneous mailbox timeouts to occur. This function
7849 * checks to see if mbox completions are on the mailbox completion queue
7850 * and will process all the completions associated with the eq for the
7851 * mailbox completion queue.
7854 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
7856 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
7858 struct lpfc_queue *fpeq = NULL;
7859 struct lpfc_queue *eq;
7862 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
7865 /* Find the EQ associated with the mbox CQ */
7866 if (sli4_hba->hdwq) {
7867 for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
7868 eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
7869 if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
7878 /* Turn off interrupts from this EQ */
7880 sli4_hba->sli4_eq_clr_intr(fpeq);
7882 /* Check to see if a mbox completion is pending */
7884 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
7887 * If a mbox completion is pending, process all the events on EQ
7888 * associated with the mbox completion queue (this could include
7889 * mailbox commands, async events, els commands, receive queue data
7894 /* process and rearm the EQ */
7895 lpfc_sli4_process_eq(phba, fpeq);
7897 /* Always clear and re-arm the EQ */
7898 sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
7900 return mbox_pending;
7905 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
7906 * @phba: Pointer to HBA context object.
7908 * This function is called from worker thread when a mailbox command times out.
7909 * The caller is not required to hold any locks. This function will reset the
7910 * HBA and recover all the pending commands.
7913 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
7915 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
7916 MAILBOX_t *mb = NULL;
7918 struct lpfc_sli *psli = &phba->sli;
7920 /* If the mailbox completed, process the completion and return */
7921 if (lpfc_sli4_process_missed_mbox_completions(phba))
7926 /* Check the pmbox pointer first. There is a race condition
7927 * between the mbox timeout handler getting executed in the
7928 * worklist and the mailbox actually completing. When this
7929 * race condition occurs, the mbox_active will be NULL.
7931 spin_lock_irq(&phba->hbalock);
7932 if (pmbox == NULL) {
7933 lpfc_printf_log(phba, KERN_WARNING,
7935 "0353 Active Mailbox cleared - mailbox timeout "
7937 spin_unlock_irq(&phba->hbalock);
7941 /* Mbox cmd <mbxCommand> timeout */
7942 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7943 "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
7945 phba->pport->port_state,
7947 phba->sli.mbox_active);
7948 spin_unlock_irq(&phba->hbalock);
7950 /* Setting state unknown so lpfc_sli_abort_iocb_ring
7951 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
7952 * it to fail all outstanding SCSI IO.
7954 spin_lock_irq(&phba->pport->work_port_lock);
7955 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
7956 spin_unlock_irq(&phba->pport->work_port_lock);
7957 spin_lock_irq(&phba->hbalock);
7958 phba->link_state = LPFC_LINK_UNKNOWN;
7959 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
7960 spin_unlock_irq(&phba->hbalock);
7962 lpfc_sli_abort_fcp_rings(phba);
7964 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7965 "0345 Resetting board due to mailbox timeout\n");
7967 /* Reset the HBA device */
7968 lpfc_reset_hba(phba);
7972 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
7973 * @phba: Pointer to HBA context object.
7974 * @pmbox: Pointer to mailbox object.
7975 * @flag: Flag indicating how the mailbox need to be processed.
7977 * This function is called by discovery code and HBA management code
7978 * to submit a mailbox command to firmware with SLI-3 interface spec. This
7979 * function gets the hbalock to protect the data structures.
7980 * The mailbox command can be submitted in polling mode, in which case
7981 * this function will wait in a polling loop for the completion of the
7983 * If the mailbox is submitted in no_wait mode (not polling) the
7984 * function will submit the command and returns immediately without waiting
7985 * for the mailbox completion. The no_wait is supported only when HBA
7986 * is in SLI2/SLI3 mode - interrupts are enabled.
7987 * The SLI interface allows only one mailbox pending at a time. If the
7988 * mailbox is issued in polling mode and there is already a mailbox
7989 * pending, then the function will return an error. If the mailbox is issued
7990 * in NO_WAIT mode and there is a mailbox pending already, the function
7991 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
7992 * The sli layer owns the mailbox object until the completion of mailbox
7993 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
7994 * return codes the caller owns the mailbox command after the return of
7998 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
8002 struct lpfc_sli *psli = &phba->sli;
8003 uint32_t status, evtctr;
8004 uint32_t ha_copy, hc_copy;
8006 unsigned long timeout;
8007 unsigned long drvr_flag = 0;
8008 uint32_t word0, ldata;
8009 void __iomem *to_slim;
8010 int processing_queue = 0;
8012 spin_lock_irqsave(&phba->hbalock, drvr_flag);
8014 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8015 /* processing mbox queue from intr_handler */
8016 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8017 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8020 processing_queue = 1;
8021 pmbox = lpfc_mbox_get(phba);
8023 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8028 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
8029 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
8031 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8032 lpfc_printf_log(phba, KERN_ERR,
8033 LOG_MBOX | LOG_VPORT,
8034 "1806 Mbox x%x failed. No vport\n",
8035 pmbox->u.mb.mbxCommand);
8037 goto out_not_finished;
8041 /* If the PCI channel is in offline state, do not post mbox. */
8042 if (unlikely(pci_channel_offline(phba->pcidev))) {
8043 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8044 goto out_not_finished;
8047 /* If HBA has a deferred error attention, fail the iocb. */
8048 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8049 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8050 goto out_not_finished;
8056 status = MBX_SUCCESS;
8058 if (phba->link_state == LPFC_HBA_ERROR) {
8059 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8061 /* Mbox command <mbxCommand> cannot issue */
8062 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8063 "(%d):0311 Mailbox command x%x cannot "
8064 "issue Data: x%x x%x\n",
8065 pmbox->vport ? pmbox->vport->vpi : 0,
8066 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
8067 goto out_not_finished;
8070 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
8071 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
8072 !(hc_copy & HC_MBINT_ENA)) {
8073 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8074 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8075 "(%d):2528 Mailbox command x%x cannot "
8076 "issue Data: x%x x%x\n",
8077 pmbox->vport ? pmbox->vport->vpi : 0,
8078 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
8079 goto out_not_finished;
8083 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8084 /* Polling for a mbox command when another one is already active
8085 * is not allowed in SLI. Also, the driver must have established
8086 * SLI2 mode to queue and process multiple mbox commands.
8089 if (flag & MBX_POLL) {
8090 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8092 /* Mbox command <mbxCommand> cannot issue */
8093 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8094 "(%d):2529 Mailbox command x%x "
8095 "cannot issue Data: x%x x%x\n",
8096 pmbox->vport ? pmbox->vport->vpi : 0,
8097 pmbox->u.mb.mbxCommand,
8098 psli->sli_flag, flag);
8099 goto out_not_finished;
8102 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
8103 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8104 /* Mbox command <mbxCommand> cannot issue */
8105 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8106 "(%d):2530 Mailbox command x%x "
8107 "cannot issue Data: x%x x%x\n",
8108 pmbox->vport ? pmbox->vport->vpi : 0,
8109 pmbox->u.mb.mbxCommand,
8110 psli->sli_flag, flag);
8111 goto out_not_finished;
8114 /* Another mailbox command is still being processed, queue this
8115 * command to be processed later.
8117 lpfc_mbox_put(phba, pmbox);
8119 /* Mbox cmd issue - BUSY */
8120 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8121 "(%d):0308 Mbox cmd issue - BUSY Data: "
8122 "x%x x%x x%x x%x\n",
8123 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
8125 phba->pport ? phba->pport->port_state : 0xff,
8126 psli->sli_flag, flag);
8128 psli->slistat.mbox_busy++;
8129 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8132 lpfc_debugfs_disc_trc(pmbox->vport,
8133 LPFC_DISC_TRC_MBOX_VPORT,
8134 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
8135 (uint32_t)mbx->mbxCommand,
8136 mbx->un.varWords[0], mbx->un.varWords[1]);
8139 lpfc_debugfs_disc_trc(phba->pport,
8141 "MBOX Bsy: cmd:x%x mb:x%x x%x",
8142 (uint32_t)mbx->mbxCommand,
8143 mbx->un.varWords[0], mbx->un.varWords[1]);
8149 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8151 /* If we are not polling, we MUST be in SLI2 mode */
8152 if (flag != MBX_POLL) {
8153 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
8154 (mbx->mbxCommand != MBX_KILL_BOARD)) {
8155 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8156 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8157 /* Mbox command <mbxCommand> cannot issue */
8158 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8159 "(%d):2531 Mailbox command x%x "
8160 "cannot issue Data: x%x x%x\n",
8161 pmbox->vport ? pmbox->vport->vpi : 0,
8162 pmbox->u.mb.mbxCommand,
8163 psli->sli_flag, flag);
8164 goto out_not_finished;
8166 /* timeout active mbox command */
8167 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
8169 mod_timer(&psli->mbox_tmo, jiffies + timeout);
8172 /* Mailbox cmd <cmd> issue */
8173 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8174 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
8176 pmbox->vport ? pmbox->vport->vpi : 0,
8178 phba->pport ? phba->pport->port_state : 0xff,
8179 psli->sli_flag, flag);
8181 if (mbx->mbxCommand != MBX_HEARTBEAT) {
8183 lpfc_debugfs_disc_trc(pmbox->vport,
8184 LPFC_DISC_TRC_MBOX_VPORT,
8185 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8186 (uint32_t)mbx->mbxCommand,
8187 mbx->un.varWords[0], mbx->un.varWords[1]);
8190 lpfc_debugfs_disc_trc(phba->pport,
8192 "MBOX Send: cmd:x%x mb:x%x x%x",
8193 (uint32_t)mbx->mbxCommand,
8194 mbx->un.varWords[0], mbx->un.varWords[1]);
8198 psli->slistat.mbox_cmd++;
8199 evtctr = psli->slistat.mbox_event;
8201 /* next set own bit for the adapter and copy over command word */
8202 mbx->mbxOwner = OWN_CHIP;
8204 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8205 /* Populate mbox extension offset word. */
8206 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
8207 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
8208 = (uint8_t *)phba->mbox_ext
8209 - (uint8_t *)phba->mbox;
8212 /* Copy the mailbox extension data */
8213 if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
8214 lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
8215 (uint8_t *)phba->mbox_ext,
8216 pmbox->in_ext_byte_len);
8218 /* Copy command data to host SLIM area */
8219 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
8221 /* Populate mbox extension offset word. */
8222 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
8223 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
8224 = MAILBOX_HBA_EXT_OFFSET;
8226 /* Copy the mailbox extension data */
8227 if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
8228 lpfc_memcpy_to_slim(phba->MBslimaddr +
8229 MAILBOX_HBA_EXT_OFFSET,
8230 pmbox->ctx_buf, pmbox->in_ext_byte_len);
8232 if (mbx->mbxCommand == MBX_CONFIG_PORT)
8233 /* copy command data into host mbox for cmpl */
8234 lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
8237 /* First copy mbox command data to HBA SLIM, skip past first
8239 to_slim = phba->MBslimaddr + sizeof (uint32_t);
8240 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
8241 MAILBOX_CMD_SIZE - sizeof (uint32_t));
8243 /* Next copy over first word, with mbxOwner set */
8244 ldata = *((uint32_t *)mbx);
8245 to_slim = phba->MBslimaddr;
8246 writel(ldata, to_slim);
8247 readl(to_slim); /* flush */
8249 if (mbx->mbxCommand == MBX_CONFIG_PORT)
8250 /* switch over to host mailbox */
8251 psli->sli_flag |= LPFC_SLI_ACTIVE;
8258 /* Set up reference to mailbox command */
8259 psli->mbox_active = pmbox;
8260 /* Interrupt board to do it */
8261 writel(CA_MBATT, phba->CAregaddr);
8262 readl(phba->CAregaddr); /* flush */
8263 /* Don't wait for it to finish, just return */
8267 /* Set up null reference to mailbox command */
8268 psli->mbox_active = NULL;
8269 /* Interrupt board to do it */
8270 writel(CA_MBATT, phba->CAregaddr);
8271 readl(phba->CAregaddr); /* flush */
8273 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8274 /* First read mbox status word */
8275 word0 = *((uint32_t *)phba->mbox);
8276 word0 = le32_to_cpu(word0);
8278 /* First read mbox status word */
8279 if (lpfc_readl(phba->MBslimaddr, &word0)) {
8280 spin_unlock_irqrestore(&phba->hbalock,
8282 goto out_not_finished;
8286 /* Read the HBA Host Attention Register */
8287 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
8288 spin_unlock_irqrestore(&phba->hbalock,
8290 goto out_not_finished;
8292 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
8295 /* Wait for command to complete */
8296 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
8297 (!(ha_copy & HA_MBATT) &&
8298 (phba->link_state > LPFC_WARM_START))) {
8299 if (time_after(jiffies, timeout)) {
8300 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8301 spin_unlock_irqrestore(&phba->hbalock,
8303 goto out_not_finished;
8306 /* Check if we took a mbox interrupt while we were
8308 if (((word0 & OWN_CHIP) != OWN_CHIP)
8309 && (evtctr != psli->slistat.mbox_event))
8313 spin_unlock_irqrestore(&phba->hbalock,
8316 spin_lock_irqsave(&phba->hbalock, drvr_flag);
8319 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8320 /* First copy command data */
8321 word0 = *((uint32_t *)phba->mbox);
8322 word0 = le32_to_cpu(word0);
8323 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
8326 /* Check real SLIM for any errors */
8327 slimword0 = readl(phba->MBslimaddr);
8328 slimmb = (MAILBOX_t *) & slimword0;
8329 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
8330 && slimmb->mbxStatus) {
8337 /* First copy command data */
8338 word0 = readl(phba->MBslimaddr);
8340 /* Read the HBA Host Attention Register */
8341 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
8342 spin_unlock_irqrestore(&phba->hbalock,
8344 goto out_not_finished;
8348 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8349 /* copy results back to user */
8350 lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
8352 /* Copy the mailbox extension data */
8353 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
8354 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
8356 pmbox->out_ext_byte_len);
8359 /* First copy command data */
8360 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
8362 /* Copy the mailbox extension data */
8363 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
8364 lpfc_memcpy_from_slim(
8367 MAILBOX_HBA_EXT_OFFSET,
8368 pmbox->out_ext_byte_len);
8372 writel(HA_MBATT, phba->HAregaddr);
8373 readl(phba->HAregaddr); /* flush */
8375 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8376 status = mbx->mbxStatus;
8379 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8383 if (processing_queue) {
8384 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
8385 lpfc_mbox_cmpl_put(phba, pmbox);
8387 return MBX_NOT_FINISHED;
8391 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
8392 * @phba: Pointer to HBA context object.
8394 * The function blocks the posting of SLI4 asynchronous mailbox commands from
8395 * the driver internal pending mailbox queue. It will then try to wait out the
8396 * possible outstanding mailbox command before return.
8399 * 0 - the outstanding mailbox command completed; otherwise, the wait for
8400 * the outstanding mailbox command timed out.
8403 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
8405 struct lpfc_sli *psli = &phba->sli;
8407 unsigned long timeout = 0;
8409 /* Mark the asynchronous mailbox command posting as blocked */
8410 spin_lock_irq(&phba->hbalock);
8411 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8412 /* Determine how long we might wait for the active mailbox
8413 * command to be gracefully completed by firmware.
8415 if (phba->sli.mbox_active)
8416 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
8417 phba->sli.mbox_active) *
8419 spin_unlock_irq(&phba->hbalock);
8421 /* Make sure the mailbox is really active */
8423 lpfc_sli4_process_missed_mbox_completions(phba);
8425 /* Wait for the outstnading mailbox command to complete */
8426 while (phba->sli.mbox_active) {
8427 /* Check active mailbox complete status every 2ms */
8429 if (time_after(jiffies, timeout)) {
8430 /* Timeout, marked the outstanding cmd not complete */
8436 /* Can not cleanly block async mailbox command, fails it */
8438 spin_lock_irq(&phba->hbalock);
8439 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8440 spin_unlock_irq(&phba->hbalock);
8446 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
8447 * @phba: Pointer to HBA context object.
8449 * The function unblocks and resume posting of SLI4 asynchronous mailbox
8450 * commands from the driver internal pending mailbox queue. It makes sure
8451 * that there is no outstanding mailbox command before resuming posting
8452 * asynchronous mailbox commands. If, for any reason, there is outstanding
8453 * mailbox command, it will try to wait it out before resuming asynchronous
8454 * mailbox command posting.
8457 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
8459 struct lpfc_sli *psli = &phba->sli;
8461 spin_lock_irq(&phba->hbalock);
8462 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8463 /* Asynchronous mailbox posting is not blocked, do nothing */
8464 spin_unlock_irq(&phba->hbalock);
8468 /* Outstanding synchronous mailbox command is guaranteed to be done,
8469 * successful or timeout, after timing-out the outstanding mailbox
8470 * command shall always be removed, so just unblock posting async
8471 * mailbox command and resume
8473 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8474 spin_unlock_irq(&phba->hbalock);
8476 /* wake up worker thread to post asynchronlous mailbox command */
8477 lpfc_worker_wake_up(phba);
8481 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
8482 * @phba: Pointer to HBA context object.
8483 * @mboxq: Pointer to mailbox object.
8485 * The function waits for the bootstrap mailbox register ready bit from
8486 * port for twice the regular mailbox command timeout value.
8488 * 0 - no timeout on waiting for bootstrap mailbox register ready.
8489 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
8492 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8495 unsigned long timeout;
8496 struct lpfc_register bmbx_reg;
8498 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
8502 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
8503 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
8507 if (time_after(jiffies, timeout))
8508 return MBXERR_ERROR;
8509 } while (!db_ready);
8515 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
8516 * @phba: Pointer to HBA context object.
8517 * @mboxq: Pointer to mailbox object.
8519 * The function posts a mailbox to the port. The mailbox is expected
8520 * to be comletely filled in and ready for the port to operate on it.
8521 * This routine executes a synchronous completion operation on the
8522 * mailbox by polling for its completion.
8524 * The caller must not be holding any locks when calling this routine.
8527 * MBX_SUCCESS - mailbox posted successfully
8528 * Any of the MBX error values.
8531 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8533 int rc = MBX_SUCCESS;
8534 unsigned long iflag;
8535 uint32_t mcqe_status;
8537 struct lpfc_sli *psli = &phba->sli;
8538 struct lpfc_mqe *mb = &mboxq->u.mqe;
8539 struct lpfc_bmbx_create *mbox_rgn;
8540 struct dma_address *dma_address;
8543 * Only one mailbox can be active to the bootstrap mailbox region
8544 * at a time and there is no queueing provided.
8546 spin_lock_irqsave(&phba->hbalock, iflag);
8547 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8548 spin_unlock_irqrestore(&phba->hbalock, iflag);
8549 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8550 "(%d):2532 Mailbox command x%x (x%x/x%x) "
8551 "cannot issue Data: x%x x%x\n",
8552 mboxq->vport ? mboxq->vport->vpi : 0,
8553 mboxq->u.mb.mbxCommand,
8554 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8555 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8556 psli->sli_flag, MBX_POLL);
8557 return MBXERR_ERROR;
8559 /* The server grabs the token and owns it until release */
8560 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8561 phba->sli.mbox_active = mboxq;
8562 spin_unlock_irqrestore(&phba->hbalock, iflag);
8564 /* wait for bootstrap mbox register for readyness */
8565 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8569 * Initialize the bootstrap memory region to avoid stale data areas
8570 * in the mailbox post. Then copy the caller's mailbox contents to
8571 * the bmbx mailbox region.
8573 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
8574 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
8575 lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
8576 sizeof(struct lpfc_mqe));
8578 /* Post the high mailbox dma address to the port and wait for ready. */
8579 dma_address = &phba->sli4_hba.bmbx.dma_address;
8580 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
8582 /* wait for bootstrap mbox register for hi-address write done */
8583 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8587 /* Post the low mailbox dma address to the port. */
8588 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
8590 /* wait for bootstrap mbox register for low address write done */
8591 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8596 * Read the CQ to ensure the mailbox has completed.
8597 * If so, update the mailbox status so that the upper layers
8598 * can complete the request normally.
8600 lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
8601 sizeof(struct lpfc_mqe));
8602 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
8603 lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
8604 sizeof(struct lpfc_mcqe));
8605 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
8607 * When the CQE status indicates a failure and the mailbox status
8608 * indicates success then copy the CQE status into the mailbox status
8609 * (and prefix it with x4000).
8611 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
8612 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
8613 bf_set(lpfc_mqe_status, mb,
8614 (LPFC_MBX_ERROR_RANGE | mcqe_status));
8617 lpfc_sli4_swap_str(phba, mboxq);
8619 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8620 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
8621 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
8622 " x%x x%x CQ: x%x x%x x%x x%x\n",
8623 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
8624 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8625 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8626 bf_get(lpfc_mqe_status, mb),
8627 mb->un.mb_words[0], mb->un.mb_words[1],
8628 mb->un.mb_words[2], mb->un.mb_words[3],
8629 mb->un.mb_words[4], mb->un.mb_words[5],
8630 mb->un.mb_words[6], mb->un.mb_words[7],
8631 mb->un.mb_words[8], mb->un.mb_words[9],
8632 mb->un.mb_words[10], mb->un.mb_words[11],
8633 mb->un.mb_words[12], mboxq->mcqe.word0,
8634 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
8635 mboxq->mcqe.trailer);
8637 /* We are holding the token, no needed for lock when release */
8638 spin_lock_irqsave(&phba->hbalock, iflag);
8639 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8640 phba->sli.mbox_active = NULL;
8641 spin_unlock_irqrestore(&phba->hbalock, iflag);
8646 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
8647 * @phba: Pointer to HBA context object.
8648 * @pmbox: Pointer to mailbox object.
8649 * @flag: Flag indicating how the mailbox need to be processed.
8651 * This function is called by discovery code and HBA management code to submit
8652 * a mailbox command to firmware with SLI-4 interface spec.
8654 * Return codes the caller owns the mailbox command after the return of the
8658 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
8661 struct lpfc_sli *psli = &phba->sli;
8662 unsigned long iflags;
8665 /* dump from issue mailbox command if setup */
8666 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
8668 rc = lpfc_mbox_dev_check(phba);
8670 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8671 "(%d):2544 Mailbox command x%x (x%x/x%x) "
8672 "cannot issue Data: x%x x%x\n",
8673 mboxq->vport ? mboxq->vport->vpi : 0,
8674 mboxq->u.mb.mbxCommand,
8675 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8676 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8677 psli->sli_flag, flag);
8678 goto out_not_finished;
8681 /* Detect polling mode and jump to a handler */
8682 if (!phba->sli4_hba.intr_enable) {
8683 if (flag == MBX_POLL)
8684 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
8687 if (rc != MBX_SUCCESS)
8688 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8689 "(%d):2541 Mailbox command x%x "
8690 "(x%x/x%x) failure: "
8691 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8693 mboxq->vport ? mboxq->vport->vpi : 0,
8694 mboxq->u.mb.mbxCommand,
8695 lpfc_sli_config_mbox_subsys_get(phba,
8697 lpfc_sli_config_mbox_opcode_get(phba,
8699 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
8700 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
8701 bf_get(lpfc_mcqe_ext_status,
8703 psli->sli_flag, flag);
8705 } else if (flag == MBX_POLL) {
8706 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8707 "(%d):2542 Try to issue mailbox command "
8708 "x%x (x%x/x%x) synchronously ahead of async "
8709 "mailbox command queue: x%x x%x\n",
8710 mboxq->vport ? mboxq->vport->vpi : 0,
8711 mboxq->u.mb.mbxCommand,
8712 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8713 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8714 psli->sli_flag, flag);
8715 /* Try to block the asynchronous mailbox posting */
8716 rc = lpfc_sli4_async_mbox_block(phba);
8718 /* Successfully blocked, now issue sync mbox cmd */
8719 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
8720 if (rc != MBX_SUCCESS)
8721 lpfc_printf_log(phba, KERN_WARNING,
8723 "(%d):2597 Sync Mailbox command "
8724 "x%x (x%x/x%x) failure: "
8725 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8727 mboxq->vport ? mboxq->vport->vpi : 0,
8728 mboxq->u.mb.mbxCommand,
8729 lpfc_sli_config_mbox_subsys_get(phba,
8731 lpfc_sli_config_mbox_opcode_get(phba,
8733 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
8734 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
8735 bf_get(lpfc_mcqe_ext_status,
8737 psli->sli_flag, flag);
8738 /* Unblock the async mailbox posting afterward */
8739 lpfc_sli4_async_mbox_unblock(phba);
8744 /* Now, interrupt mode asynchrous mailbox command */
8745 rc = lpfc_mbox_cmd_check(phba, mboxq);
8747 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8748 "(%d):2543 Mailbox command x%x (x%x/x%x) "
8749 "cannot issue Data: x%x x%x\n",
8750 mboxq->vport ? mboxq->vport->vpi : 0,
8751 mboxq->u.mb.mbxCommand,
8752 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8753 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8754 psli->sli_flag, flag);
8755 goto out_not_finished;
8758 /* Put the mailbox command to the driver internal FIFO */
8759 psli->slistat.mbox_busy++;
8760 spin_lock_irqsave(&phba->hbalock, iflags);
8761 lpfc_mbox_put(phba, mboxq);
8762 spin_unlock_irqrestore(&phba->hbalock, iflags);
8763 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8764 "(%d):0354 Mbox cmd issue - Enqueue Data: "
8765 "x%x (x%x/x%x) x%x x%x x%x\n",
8766 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
8767 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8768 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8769 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8770 phba->pport->port_state,
8771 psli->sli_flag, MBX_NOWAIT);
8772 /* Wake up worker thread to transport mailbox command from head */
8773 lpfc_worker_wake_up(phba);
8778 return MBX_NOT_FINISHED;
8782 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
8783 * @phba: Pointer to HBA context object.
8785 * This function is called by worker thread to send a mailbox command to
8786 * SLI4 HBA firmware.
8790 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
8792 struct lpfc_sli *psli = &phba->sli;
8793 LPFC_MBOXQ_t *mboxq;
8794 int rc = MBX_SUCCESS;
8795 unsigned long iflags;
8796 struct lpfc_mqe *mqe;
8799 /* Check interrupt mode before post async mailbox command */
8800 if (unlikely(!phba->sli4_hba.intr_enable))
8801 return MBX_NOT_FINISHED;
8803 /* Check for mailbox command service token */
8804 spin_lock_irqsave(&phba->hbalock, iflags);
8805 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8806 spin_unlock_irqrestore(&phba->hbalock, iflags);
8807 return MBX_NOT_FINISHED;
8809 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8810 spin_unlock_irqrestore(&phba->hbalock, iflags);
8811 return MBX_NOT_FINISHED;
8813 if (unlikely(phba->sli.mbox_active)) {
8814 spin_unlock_irqrestore(&phba->hbalock, iflags);
8815 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8816 "0384 There is pending active mailbox cmd\n");
8817 return MBX_NOT_FINISHED;
8819 /* Take the mailbox command service token */
8820 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8822 /* Get the next mailbox command from head of queue */
8823 mboxq = lpfc_mbox_get(phba);
8825 /* If no more mailbox command waiting for post, we're done */
8827 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8828 spin_unlock_irqrestore(&phba->hbalock, iflags);
8831 phba->sli.mbox_active = mboxq;
8832 spin_unlock_irqrestore(&phba->hbalock, iflags);
8834 /* Check device readiness for posting mailbox command */
8835 rc = lpfc_mbox_dev_check(phba);
8837 /* Driver clean routine will clean up pending mailbox */
8838 goto out_not_finished;
8840 /* Prepare the mbox command to be posted */
8841 mqe = &mboxq->u.mqe;
8842 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
8844 /* Start timer for the mbox_tmo and log some mailbox post messages */
8845 mod_timer(&psli->mbox_tmo, (jiffies +
8846 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
8848 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8849 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
8851 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
8852 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8853 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8854 phba->pport->port_state, psli->sli_flag);
8856 if (mbx_cmnd != MBX_HEARTBEAT) {
8858 lpfc_debugfs_disc_trc(mboxq->vport,
8859 LPFC_DISC_TRC_MBOX_VPORT,
8860 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8861 mbx_cmnd, mqe->un.mb_words[0],
8862 mqe->un.mb_words[1]);
8864 lpfc_debugfs_disc_trc(phba->pport,
8866 "MBOX Send: cmd:x%x mb:x%x x%x",
8867 mbx_cmnd, mqe->un.mb_words[0],
8868 mqe->un.mb_words[1]);
8871 psli->slistat.mbox_cmd++;
8873 /* Post the mailbox command to the port */
8874 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
8875 if (rc != MBX_SUCCESS) {
8876 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8877 "(%d):2533 Mailbox command x%x (x%x/x%x) "
8878 "cannot issue Data: x%x x%x\n",
8879 mboxq->vport ? mboxq->vport->vpi : 0,
8880 mboxq->u.mb.mbxCommand,
8881 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8882 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8883 psli->sli_flag, MBX_NOWAIT);
8884 goto out_not_finished;
8890 spin_lock_irqsave(&phba->hbalock, iflags);
8891 if (phba->sli.mbox_active) {
8892 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
8893 __lpfc_mbox_cmpl_put(phba, mboxq);
8894 /* Release the token */
8895 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8896 phba->sli.mbox_active = NULL;
8898 spin_unlock_irqrestore(&phba->hbalock, iflags);
8900 return MBX_NOT_FINISHED;
8904 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
8905 * @phba: Pointer to HBA context object.
8906 * @pmbox: Pointer to mailbox object.
8907 * @flag: Flag indicating how the mailbox need to be processed.
8909 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
8910 * the API jump table function pointer from the lpfc_hba struct.
8912 * Return codes the caller owns the mailbox command after the return of the
8916 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
8918 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
8922 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
8923 * @phba: The hba struct for which this call is being executed.
8924 * @dev_grp: The HBA PCI-Device group number.
8926 * This routine sets up the mbox interface API function jump table in @phba
8928 * Returns: 0 - success, -ENODEV - failure.
8931 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
8935 case LPFC_PCI_DEV_LP:
8936 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
8937 phba->lpfc_sli_handle_slow_ring_event =
8938 lpfc_sli_handle_slow_ring_event_s3;
8939 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
8940 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
8941 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
8943 case LPFC_PCI_DEV_OC:
8944 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
8945 phba->lpfc_sli_handle_slow_ring_event =
8946 lpfc_sli_handle_slow_ring_event_s4;
8947 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
8948 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
8949 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
8952 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8953 "1420 Invalid HBA PCI-device group: 0x%x\n",
8962 * __lpfc_sli_ringtx_put - Add an iocb to the txq
8963 * @phba: Pointer to HBA context object.
8964 * @pring: Pointer to driver SLI ring object.
8965 * @piocb: Pointer to address of newly added command iocb.
8967 * This function is called with hbalock held to add a command
8968 * iocb to the txq when SLI layer cannot submit the command iocb
8972 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8973 struct lpfc_iocbq *piocb)
8975 lockdep_assert_held(&phba->hbalock);
8976 /* Insert the caller's iocb in the txq tail for later processing. */
8977 list_add_tail(&piocb->list, &pring->txq);
8981 * lpfc_sli_next_iocb - Get the next iocb in the txq
8982 * @phba: Pointer to HBA context object.
8983 * @pring: Pointer to driver SLI ring object.
8984 * @piocb: Pointer to address of newly added command iocb.
8986 * This function is called with hbalock held before a new
8987 * iocb is submitted to the firmware. This function checks
8988 * txq to flush the iocbs in txq to Firmware before
8989 * submitting new iocbs to the Firmware.
8990 * If there are iocbs in the txq which need to be submitted
8991 * to firmware, lpfc_sli_next_iocb returns the first element
8992 * of the txq after dequeuing it from txq.
8993 * If there is no iocb in the txq then the function will return
8994 * *piocb and *piocb is set to NULL. Caller needs to check
8995 * *piocb to find if there are more commands in the txq.
8997 static struct lpfc_iocbq *
8998 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8999 struct lpfc_iocbq **piocb)
9001 struct lpfc_iocbq * nextiocb;
9003 lockdep_assert_held(&phba->hbalock);
9005 nextiocb = lpfc_sli_ringtx_get(phba, pring);
9015 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
9016 * @phba: Pointer to HBA context object.
9017 * @ring_number: SLI ring number to issue iocb on.
9018 * @piocb: Pointer to command iocb.
9019 * @flag: Flag indicating if this command can be put into txq.
9021 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
9022 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
9023 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
9024 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
9025 * this function allows only iocbs for posting buffers. This function finds
9026 * next available slot in the command ring and posts the command to the
9027 * available slot and writes the port attention register to request HBA start
9028 * processing new iocb. If there is no slot available in the ring and
9029 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
9030 * the function returns IOCB_BUSY.
9032 * This function is called with hbalock held. The function will return success
9033 * after it successfully submit the iocb to firmware or after adding to the
9037 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
9038 struct lpfc_iocbq *piocb, uint32_t flag)
9040 struct lpfc_iocbq *nextiocb;
9042 struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
9044 lockdep_assert_held(&phba->hbalock);
9046 if (piocb->iocb_cmpl && (!piocb->vport) &&
9047 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
9048 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
9049 lpfc_printf_log(phba, KERN_ERR,
9050 LOG_SLI | LOG_VPORT,
9051 "1807 IOCB x%x failed. No vport\n",
9052 piocb->iocb.ulpCommand);
9058 /* If the PCI channel is in offline state, do not post iocbs. */
9059 if (unlikely(pci_channel_offline(phba->pcidev)))
9062 /* If HBA has a deferred error attention, fail the iocb. */
9063 if (unlikely(phba->hba_flag & DEFER_ERATT))
9067 * We should never get an IOCB if we are in a < LINK_DOWN state
9069 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
9073 * Check to see if we are blocking IOCB processing because of a
9074 * outstanding event.
9076 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
9079 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
9081 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
9082 * can be issued if the link is not up.
9084 switch (piocb->iocb.ulpCommand) {
9085 case CMD_GEN_REQUEST64_CR:
9086 case CMD_GEN_REQUEST64_CX:
9087 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
9088 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
9089 FC_RCTL_DD_UNSOL_CMD) ||
9090 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
9091 MENLO_TRANSPORT_TYPE))
9095 case CMD_QUE_RING_BUF_CN:
9096 case CMD_QUE_RING_BUF64_CN:
9098 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
9099 * completion, iocb_cmpl MUST be 0.
9101 if (piocb->iocb_cmpl)
9102 piocb->iocb_cmpl = NULL;
9104 case CMD_CREATE_XRI_CR:
9105 case CMD_CLOSE_XRI_CN:
9106 case CMD_CLOSE_XRI_CX:
9113 * For FCP commands, we must be in a state where we can process link
9116 } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
9117 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
9121 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
9122 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
9123 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
9126 lpfc_sli_update_ring(phba, pring);
9128 lpfc_sli_update_full_ring(phba, pring);
9131 return IOCB_SUCCESS;
9136 pring->stats.iocb_cmd_delay++;
9140 if (!(flag & SLI_IOCB_RET_IOCB)) {
9141 __lpfc_sli_ringtx_put(phba, pring, piocb);
9142 return IOCB_SUCCESS;
9149 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
9150 * @phba: Pointer to HBA context object.
9151 * @piocb: Pointer to command iocb.
9152 * @sglq: Pointer to the scatter gather queue object.
9154 * This routine converts the bpl or bde that is in the IOCB
9155 * to a sgl list for the sli4 hardware. The physical address
9156 * of the bpl/bde is converted back to a virtual address.
9157 * If the IOCB contains a BPL then the list of BDE's is
9158 * converted to sli4_sge's. If the IOCB contains a single
9159 * BDE then it is converted to a single sli_sge.
9160 * The IOCB is still in cpu endianess so the contents of
9161 * the bpl can be used without byte swapping.
9163 * Returns valid XRI = Success, NO_XRI = Failure.
9166 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
9167 struct lpfc_sglq *sglq)
9169 uint16_t xritag = NO_XRI;
9170 struct ulp_bde64 *bpl = NULL;
9171 struct ulp_bde64 bde;
9172 struct sli4_sge *sgl = NULL;
9173 struct lpfc_dmabuf *dmabuf;
9177 uint32_t offset = 0; /* accumulated offset in the sg request list */
9178 int inbound = 0; /* number of sg reply entries inbound from firmware */
9180 if (!piocbq || !sglq)
9183 sgl = (struct sli4_sge *)sglq->sgl;
9184 icmd = &piocbq->iocb;
9185 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
9186 return sglq->sli4_xritag;
9187 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
9188 numBdes = icmd->un.genreq64.bdl.bdeSize /
9189 sizeof(struct ulp_bde64);
9190 /* The addrHigh and addrLow fields within the IOCB
9191 * have not been byteswapped yet so there is no
9192 * need to swap them back.
9194 if (piocbq->context3)
9195 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
9199 bpl = (struct ulp_bde64 *)dmabuf->virt;
9203 for (i = 0; i < numBdes; i++) {
9204 /* Should already be byte swapped. */
9205 sgl->addr_hi = bpl->addrHigh;
9206 sgl->addr_lo = bpl->addrLow;
9208 sgl->word2 = le32_to_cpu(sgl->word2);
9209 if ((i+1) == numBdes)
9210 bf_set(lpfc_sli4_sge_last, sgl, 1);
9212 bf_set(lpfc_sli4_sge_last, sgl, 0);
9213 /* swap the size field back to the cpu so we
9214 * can assign it to the sgl.
9216 bde.tus.w = le32_to_cpu(bpl->tus.w);
9217 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
9218 /* The offsets in the sgl need to be accumulated
9219 * separately for the request and reply lists.
9220 * The request is always first, the reply follows.
9222 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
9223 /* add up the reply sg entries */
9224 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
9226 /* first inbound? reset the offset */
9229 bf_set(lpfc_sli4_sge_offset, sgl, offset);
9230 bf_set(lpfc_sli4_sge_type, sgl,
9231 LPFC_SGE_TYPE_DATA);
9232 offset += bde.tus.f.bdeSize;
9234 sgl->word2 = cpu_to_le32(sgl->word2);
9238 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
9239 /* The addrHigh and addrLow fields of the BDE have not
9240 * been byteswapped yet so they need to be swapped
9241 * before putting them in the sgl.
9244 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
9246 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
9247 sgl->word2 = le32_to_cpu(sgl->word2);
9248 bf_set(lpfc_sli4_sge_last, sgl, 1);
9249 sgl->word2 = cpu_to_le32(sgl->word2);
9251 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
9253 return sglq->sli4_xritag;
9257 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
9258 * @phba: Pointer to HBA context object.
9259 * @piocb: Pointer to command iocb.
9260 * @wqe: Pointer to the work queue entry.
9262 * This routine converts the iocb command to its Work Queue Entry
9263 * equivalent. The wqe pointer should not have any fields set when
9264 * this routine is called because it will memcpy over them.
9265 * This routine does not set the CQ_ID or the WQEC bits in the
9268 * Returns: 0 = Success, IOCB_ERROR = Failure.
9271 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
9272 union lpfc_wqe128 *wqe)
9274 uint32_t xmit_len = 0, total_len = 0;
9278 uint8_t command_type = ELS_COMMAND_NON_FIP;
9281 uint16_t abrt_iotag;
9282 struct lpfc_iocbq *abrtiocbq;
9283 struct ulp_bde64 *bpl = NULL;
9284 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
9286 struct ulp_bde64 bde;
9287 struct lpfc_nodelist *ndlp;
9291 fip = phba->hba_flag & HBA_FIP_SUPPORT;
9292 /* The fcp commands will set command type */
9293 if (iocbq->iocb_flag & LPFC_IO_FCP)
9294 command_type = FCP_COMMAND;
9295 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
9296 command_type = ELS_COMMAND_FIP;
9298 command_type = ELS_COMMAND_NON_FIP;
9300 if (phba->fcp_embed_io)
9301 memset(wqe, 0, sizeof(union lpfc_wqe128));
9302 /* Some of the fields are in the right position already */
9303 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
9304 /* The ct field has moved so reset */
9305 wqe->generic.wqe_com.word7 = 0;
9306 wqe->generic.wqe_com.word10 = 0;
9308 abort_tag = (uint32_t) iocbq->iotag;
9309 xritag = iocbq->sli4_xritag;
9310 /* words0-2 bpl convert bde */
9311 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
9312 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
9313 sizeof(struct ulp_bde64);
9314 bpl = (struct ulp_bde64 *)
9315 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
9319 /* Should already be byte swapped. */
9320 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
9321 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
9322 /* swap the size field back to the cpu so we
9323 * can assign it to the sgl.
9325 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
9326 xmit_len = wqe->generic.bde.tus.f.bdeSize;
9328 for (i = 0; i < numBdes; i++) {
9329 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
9330 total_len += bde.tus.f.bdeSize;
9333 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
9335 iocbq->iocb.ulpIoTag = iocbq->iotag;
9336 cmnd = iocbq->iocb.ulpCommand;
9338 switch (iocbq->iocb.ulpCommand) {
9339 case CMD_ELS_REQUEST64_CR:
9340 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
9341 ndlp = iocbq->context_un.ndlp;
9343 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9344 if (!iocbq->iocb.ulpLe) {
9345 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9346 "2007 Only Limited Edition cmd Format"
9347 " supported 0x%x\n",
9348 iocbq->iocb.ulpCommand);
9352 wqe->els_req.payload_len = xmit_len;
9353 /* Els_reguest64 has a TMO */
9354 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
9355 iocbq->iocb.ulpTimeout);
9356 /* Need a VF for word 4 set the vf bit*/
9357 bf_set(els_req64_vf, &wqe->els_req, 0);
9358 /* And a VFID for word 12 */
9359 bf_set(els_req64_vfid, &wqe->els_req, 0);
9360 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
9361 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9362 iocbq->iocb.ulpContext);
9363 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
9364 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
9365 /* CCP CCPE PV PRI in word10 were set in the memcpy */
9366 if (command_type == ELS_COMMAND_FIP)
9367 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
9368 >> LPFC_FIP_ELS_ID_SHIFT);
9369 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9370 iocbq->context2)->virt);
9371 if_type = bf_get(lpfc_sli_intf_if_type,
9372 &phba->sli4_hba.sli_intf);
9373 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9374 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
9375 *pcmd == ELS_CMD_SCR ||
9376 *pcmd == ELS_CMD_RSCN_XMT ||
9377 *pcmd == ELS_CMD_FDISC ||
9378 *pcmd == ELS_CMD_LOGO ||
9379 *pcmd == ELS_CMD_PLOGI)) {
9380 bf_set(els_req64_sp, &wqe->els_req, 1);
9381 bf_set(els_req64_sid, &wqe->els_req,
9382 iocbq->vport->fc_myDID);
9383 if ((*pcmd == ELS_CMD_FLOGI) &&
9384 !(phba->fc_topology ==
9385 LPFC_TOPOLOGY_LOOP))
9386 bf_set(els_req64_sid, &wqe->els_req, 0);
9387 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
9388 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9389 phba->vpi_ids[iocbq->vport->vpi]);
9390 } else if (pcmd && iocbq->context1) {
9391 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
9392 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9393 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9396 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
9397 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9398 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
9399 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
9400 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
9401 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
9402 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
9403 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
9404 wqe->els_req.max_response_payload_len = total_len - xmit_len;
9406 case CMD_XMIT_SEQUENCE64_CX:
9407 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
9408 iocbq->iocb.un.ulpWord[3]);
9409 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
9410 iocbq->iocb.unsli3.rcvsli3.ox_id);
9411 /* The entire sequence is transmitted for this IOCB */
9412 xmit_len = total_len;
9413 cmnd = CMD_XMIT_SEQUENCE64_CR;
9414 if (phba->link_flag & LS_LOOPBACK_MODE)
9415 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
9417 case CMD_XMIT_SEQUENCE64_CR:
9418 /* word3 iocb=io_tag32 wqe=reserved */
9419 wqe->xmit_sequence.rsvd3 = 0;
9420 /* word4 relative_offset memcpy */
9421 /* word5 r_ctl/df_ctl memcpy */
9422 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
9423 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
9424 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
9425 LPFC_WQE_IOD_WRITE);
9426 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
9427 LPFC_WQE_LENLOC_WORD12);
9428 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
9429 wqe->xmit_sequence.xmit_len = xmit_len;
9430 command_type = OTHER_COMMAND;
9432 case CMD_XMIT_BCAST64_CN:
9433 /* word3 iocb=iotag32 wqe=seq_payload_len */
9434 wqe->xmit_bcast64.seq_payload_len = xmit_len;
9435 /* word4 iocb=rsvd wqe=rsvd */
9436 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
9437 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
9438 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
9439 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9440 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
9441 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
9442 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
9443 LPFC_WQE_LENLOC_WORD3);
9444 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
9446 case CMD_FCP_IWRITE64_CR:
9447 command_type = FCP_COMMAND_DATA_OUT;
9448 /* word3 iocb=iotag wqe=payload_offset_len */
9449 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9450 bf_set(payload_offset_len, &wqe->fcp_iwrite,
9451 xmit_len + sizeof(struct fcp_rsp));
9452 bf_set(cmd_buff_len, &wqe->fcp_iwrite,
9454 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9455 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9456 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
9457 iocbq->iocb.ulpFCP2Rcvy);
9458 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
9459 /* Always open the exchange */
9460 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
9461 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
9462 LPFC_WQE_LENLOC_WORD4);
9463 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
9464 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
9465 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9466 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
9467 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
9468 if (iocbq->priority) {
9469 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
9470 (iocbq->priority << 1));
9472 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
9473 (phba->cfg_XLanePriority << 1));
9476 /* Note, word 10 is already initialized to 0 */
9478 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9479 if (phba->cfg_enable_pbde)
9480 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1);
9482 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
9484 if (phba->fcp_embed_io) {
9485 struct lpfc_io_buf *lpfc_cmd;
9486 struct sli4_sge *sgl;
9487 struct fcp_cmnd *fcp_cmnd;
9490 /* 128 byte wqe support here */
9492 lpfc_cmd = iocbq->context1;
9493 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9494 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9496 /* Word 0-2 - FCP_CMND */
9497 wqe->generic.bde.tus.f.bdeFlags =
9498 BUFF_TYPE_BDE_IMMED;
9499 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9500 wqe->generic.bde.addrHigh = 0;
9501 wqe->generic.bde.addrLow = 88; /* Word 22 */
9503 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
9504 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
9506 /* Word 22-29 FCP CMND Payload */
9507 ptr = &wqe->words[22];
9508 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9511 case CMD_FCP_IREAD64_CR:
9512 /* word3 iocb=iotag wqe=payload_offset_len */
9513 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9514 bf_set(payload_offset_len, &wqe->fcp_iread,
9515 xmit_len + sizeof(struct fcp_rsp));
9516 bf_set(cmd_buff_len, &wqe->fcp_iread,
9518 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9519 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9520 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
9521 iocbq->iocb.ulpFCP2Rcvy);
9522 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
9523 /* Always open the exchange */
9524 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
9525 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
9526 LPFC_WQE_LENLOC_WORD4);
9527 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
9528 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
9529 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9530 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
9531 bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
9532 if (iocbq->priority) {
9533 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
9534 (iocbq->priority << 1));
9536 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
9537 (phba->cfg_XLanePriority << 1));
9540 /* Note, word 10 is already initialized to 0 */
9542 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9543 if (phba->cfg_enable_pbde)
9544 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1);
9546 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
9548 if (phba->fcp_embed_io) {
9549 struct lpfc_io_buf *lpfc_cmd;
9550 struct sli4_sge *sgl;
9551 struct fcp_cmnd *fcp_cmnd;
9554 /* 128 byte wqe support here */
9556 lpfc_cmd = iocbq->context1;
9557 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9558 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9560 /* Word 0-2 - FCP_CMND */
9561 wqe->generic.bde.tus.f.bdeFlags =
9562 BUFF_TYPE_BDE_IMMED;
9563 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9564 wqe->generic.bde.addrHigh = 0;
9565 wqe->generic.bde.addrLow = 88; /* Word 22 */
9567 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
9568 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
9570 /* Word 22-29 FCP CMND Payload */
9571 ptr = &wqe->words[22];
9572 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9575 case CMD_FCP_ICMND64_CR:
9576 /* word3 iocb=iotag wqe=payload_offset_len */
9577 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9578 bf_set(payload_offset_len, &wqe->fcp_icmd,
9579 xmit_len + sizeof(struct fcp_rsp));
9580 bf_set(cmd_buff_len, &wqe->fcp_icmd,
9582 /* word3 iocb=IO_TAG wqe=reserved */
9583 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
9584 /* Always open the exchange */
9585 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
9586 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
9587 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
9588 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
9589 LPFC_WQE_LENLOC_NONE);
9590 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
9591 iocbq->iocb.ulpFCP2Rcvy);
9592 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9593 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
9594 bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
9595 if (iocbq->priority) {
9596 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
9597 (iocbq->priority << 1));
9599 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
9600 (phba->cfg_XLanePriority << 1));
9603 /* Note, word 10 is already initialized to 0 */
9605 if (phba->fcp_embed_io) {
9606 struct lpfc_io_buf *lpfc_cmd;
9607 struct sli4_sge *sgl;
9608 struct fcp_cmnd *fcp_cmnd;
9611 /* 128 byte wqe support here */
9613 lpfc_cmd = iocbq->context1;
9614 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9615 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9617 /* Word 0-2 - FCP_CMND */
9618 wqe->generic.bde.tus.f.bdeFlags =
9619 BUFF_TYPE_BDE_IMMED;
9620 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9621 wqe->generic.bde.addrHigh = 0;
9622 wqe->generic.bde.addrLow = 88; /* Word 22 */
9624 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
9625 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
9627 /* Word 22-29 FCP CMND Payload */
9628 ptr = &wqe->words[22];
9629 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9632 case CMD_GEN_REQUEST64_CR:
9633 /* For this command calculate the xmit length of the
9637 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
9638 sizeof(struct ulp_bde64);
9639 for (i = 0; i < numBdes; i++) {
9640 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
9641 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
9643 xmit_len += bde.tus.f.bdeSize;
9645 /* word3 iocb=IO_TAG wqe=request_payload_len */
9646 wqe->gen_req.request_payload_len = xmit_len;
9647 /* word4 iocb=parameter wqe=relative_offset memcpy */
9648 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
9649 /* word6 context tag copied in memcpy */
9650 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
9651 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
9652 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9653 "2015 Invalid CT %x command 0x%x\n",
9654 ct, iocbq->iocb.ulpCommand);
9657 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
9658 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
9659 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
9660 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
9661 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
9662 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
9663 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
9664 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
9665 wqe->gen_req.max_response_payload_len = total_len - xmit_len;
9666 command_type = OTHER_COMMAND;
9668 case CMD_XMIT_ELS_RSP64_CX:
9669 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9670 /* words0-2 BDE memcpy */
9671 /* word3 iocb=iotag32 wqe=response_payload_len */
9672 wqe->xmit_els_rsp.response_payload_len = xmit_len;
9674 wqe->xmit_els_rsp.word4 = 0;
9675 /* word5 iocb=rsvd wge=did */
9676 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
9677 iocbq->iocb.un.xseq64.xmit_els_remoteID);
9679 if_type = bf_get(lpfc_sli_intf_if_type,
9680 &phba->sli4_hba.sli_intf);
9681 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9682 if (iocbq->vport->fc_flag & FC_PT2PT) {
9683 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
9684 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
9685 iocbq->vport->fc_myDID);
9686 if (iocbq->vport->fc_myDID == Fabric_DID) {
9688 &wqe->xmit_els_rsp.wqe_dest, 0);
9692 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
9693 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9694 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
9695 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
9696 iocbq->iocb.unsli3.rcvsli3.ox_id);
9697 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
9698 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
9699 phba->vpi_ids[iocbq->vport->vpi]);
9700 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
9701 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
9702 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
9703 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
9704 LPFC_WQE_LENLOC_WORD3);
9705 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
9706 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
9707 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9708 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9709 iocbq->context2)->virt);
9710 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9711 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
9712 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
9713 iocbq->vport->fc_myDID);
9714 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
9715 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
9716 phba->vpi_ids[phba->pport->vpi]);
9718 command_type = OTHER_COMMAND;
9720 case CMD_CLOSE_XRI_CN:
9721 case CMD_ABORT_XRI_CN:
9722 case CMD_ABORT_XRI_CX:
9723 /* words 0-2 memcpy should be 0 rserved */
9724 /* port will send abts */
9725 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
9726 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
9727 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
9728 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
9732 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
9734 * The link is down, or the command was ELS_FIP
9735 * so the fw does not need to send abts
9738 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
9740 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
9741 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
9742 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
9743 wqe->abort_cmd.rsrvd5 = 0;
9744 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
9745 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9746 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
9748 * The abort handler will send us CMD_ABORT_XRI_CN or
9749 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
9751 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
9752 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
9753 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
9754 LPFC_WQE_LENLOC_NONE);
9755 cmnd = CMD_ABORT_XRI_CX;
9756 command_type = OTHER_COMMAND;
9759 case CMD_XMIT_BLS_RSP64_CX:
9760 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9761 /* As BLS ABTS RSP WQE is very different from other WQEs,
9762 * we re-construct this WQE here based on information in
9763 * iocbq from scratch.
9765 memset(wqe, 0, sizeof(*wqe));
9766 /* OX_ID is invariable to who sent ABTS to CT exchange */
9767 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
9768 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
9769 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
9770 LPFC_ABTS_UNSOL_INT) {
9771 /* ABTS sent by initiator to CT exchange, the
9772 * RX_ID field will be filled with the newly
9773 * allocated responder XRI.
9775 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
9776 iocbq->sli4_xritag);
9778 /* ABTS sent by responder to CT exchange, the
9779 * RX_ID field will be filled with the responder
9782 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
9783 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
9785 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
9786 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
9789 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
9791 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
9792 iocbq->iocb.ulpContext);
9793 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
9794 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
9795 phba->vpi_ids[phba->pport->vpi]);
9796 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
9797 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
9798 LPFC_WQE_LENLOC_NONE);
9799 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
9800 command_type = OTHER_COMMAND;
9801 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
9802 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
9803 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
9804 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
9805 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
9806 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
9807 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
9811 case CMD_SEND_FRAME:
9812 bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME);
9813 bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */
9814 bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */
9815 bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1);
9816 bf_set(wqe_xbl, &wqe->generic.wqe_com, 1);
9817 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
9818 bf_set(wqe_xc, &wqe->generic.wqe_com, 1);
9819 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA);
9820 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
9821 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
9822 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
9824 case CMD_XRI_ABORTED_CX:
9825 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
9826 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
9827 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
9828 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
9829 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
9831 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9832 "2014 Invalid command 0x%x\n",
9833 iocbq->iocb.ulpCommand);
9838 if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
9839 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
9840 else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
9841 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
9842 else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
9843 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
9844 iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
9845 LPFC_IO_DIF_INSERT);
9846 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
9847 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
9848 wqe->generic.wqe_com.abort_tag = abort_tag;
9849 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
9850 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
9851 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
9852 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
9857 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
9858 * @phba: Pointer to HBA context object.
9859 * @ring_number: SLI ring number to issue iocb on.
9860 * @piocb: Pointer to command iocb.
9861 * @flag: Flag indicating if this command can be put into txq.
9863 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
9864 * an iocb command to an HBA with SLI-4 interface spec.
9866 * This function is called with hbalock held. The function will return success
9867 * after it successfully submit the iocb to firmware or after adding to the
9871 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
9872 struct lpfc_iocbq *piocb, uint32_t flag)
9874 struct lpfc_sglq *sglq;
9875 union lpfc_wqe128 wqe;
9876 struct lpfc_queue *wq;
9877 struct lpfc_sli_ring *pring;
9880 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
9881 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
9882 wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
9884 wq = phba->sli4_hba.els_wq;
9887 /* Get corresponding ring */
9891 * The WQE can be either 64 or 128 bytes,
9894 lockdep_assert_held(&pring->ring_lock);
9896 if (piocb->sli4_xritag == NO_XRI) {
9897 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
9898 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
9901 if (!list_empty(&pring->txq)) {
9902 if (!(flag & SLI_IOCB_RET_IOCB)) {
9903 __lpfc_sli_ringtx_put(phba,
9905 return IOCB_SUCCESS;
9910 sglq = __lpfc_sli_get_els_sglq(phba, piocb);
9912 if (!(flag & SLI_IOCB_RET_IOCB)) {
9913 __lpfc_sli_ringtx_put(phba,
9916 return IOCB_SUCCESS;
9922 } else if (piocb->iocb_flag & LPFC_IO_FCP)
9923 /* These IO's already have an XRI and a mapped sgl. */
9927 * This is a continuation of a commandi,(CX) so this
9928 * sglq is on the active list
9930 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
9936 piocb->sli4_lxritag = sglq->sli4_lxritag;
9937 piocb->sli4_xritag = sglq->sli4_xritag;
9938 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
9942 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
9945 if (lpfc_sli4_wq_put(wq, &wqe))
9947 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
9953 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
9955 * This routine wraps the actual lockless version for issusing IOCB function
9956 * pointer from the lpfc_hba struct.
9959 * IOCB_ERROR - Error
9960 * IOCB_SUCCESS - Success
9964 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
9965 struct lpfc_iocbq *piocb, uint32_t flag)
9967 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
9971 * lpfc_sli_api_table_setup - Set up sli api function jump table
9972 * @phba: The hba struct for which this call is being executed.
9973 * @dev_grp: The HBA PCI-Device group number.
9975 * This routine sets up the SLI interface API function jump table in @phba
9977 * Returns: 0 - success, -ENODEV - failure.
9980 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
9984 case LPFC_PCI_DEV_LP:
9985 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
9986 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
9988 case LPFC_PCI_DEV_OC:
9989 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
9990 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
9993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9994 "1419 Invalid HBA PCI-device group: 0x%x\n",
9999 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
10004 * lpfc_sli4_calc_ring - Calculates which ring to use
10005 * @phba: Pointer to HBA context object.
10006 * @piocb: Pointer to command iocb.
10008 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
10009 * hba_wqidx, thus we need to calculate the corresponding ring.
10010 * Since ABORTS must go on the same WQ of the command they are
10011 * aborting, we use command's hba_wqidx.
10013 struct lpfc_sli_ring *
10014 lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
10016 struct lpfc_io_buf *lpfc_cmd;
10018 if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
10019 if (unlikely(!phba->sli4_hba.hdwq))
10022 * for abort iocb hba_wqidx should already
10023 * be setup based on what work queue we used.
10025 if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
10026 lpfc_cmd = (struct lpfc_io_buf *)piocb->context1;
10027 piocb->hba_wqidx = lpfc_cmd->hdwq_no;
10029 return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
10031 if (unlikely(!phba->sli4_hba.els_wq))
10033 piocb->hba_wqidx = 0;
10034 return phba->sli4_hba.els_wq->pring;
10039 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
10040 * @phba: Pointer to HBA context object.
10041 * @pring: Pointer to driver SLI ring object.
10042 * @piocb: Pointer to command iocb.
10043 * @flag: Flag indicating if this command can be put into txq.
10045 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
10046 * function. This function gets the hbalock and calls
10047 * __lpfc_sli_issue_iocb function and will return the error returned
10048 * by __lpfc_sli_issue_iocb function. This wrapper is used by
10049 * functions which do not hold hbalock.
10052 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
10053 struct lpfc_iocbq *piocb, uint32_t flag)
10055 struct lpfc_sli_ring *pring;
10056 unsigned long iflags;
10059 if (phba->sli_rev == LPFC_SLI_REV4) {
10060 pring = lpfc_sli4_calc_ring(phba, piocb);
10061 if (unlikely(pring == NULL))
10064 spin_lock_irqsave(&pring->ring_lock, iflags);
10065 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10066 spin_unlock_irqrestore(&pring->ring_lock, iflags);
10068 /* For now, SLI2/3 will still use hbalock */
10069 spin_lock_irqsave(&phba->hbalock, iflags);
10070 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10071 spin_unlock_irqrestore(&phba->hbalock, iflags);
10077 * lpfc_extra_ring_setup - Extra ring setup function
10078 * @phba: Pointer to HBA context object.
10080 * This function is called while driver attaches with the
10081 * HBA to setup the extra ring. The extra ring is used
10082 * only when driver needs to support target mode functionality
10083 * or IP over FC functionalities.
10085 * This function is called with no lock held. SLI3 only.
10088 lpfc_extra_ring_setup( struct lpfc_hba *phba)
10090 struct lpfc_sli *psli;
10091 struct lpfc_sli_ring *pring;
10095 /* Adjust cmd/rsp ring iocb entries more evenly */
10097 /* Take some away from the FCP ring */
10098 pring = &psli->sli3_ring[LPFC_FCP_RING];
10099 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10100 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10101 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10102 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10104 /* and give them to the extra ring */
10105 pring = &psli->sli3_ring[LPFC_EXTRA_RING];
10107 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10108 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10109 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10110 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10112 /* Setup default profile for this ring */
10113 pring->iotag_max = 4096;
10114 pring->num_mask = 1;
10115 pring->prt[0].profile = 0; /* Mask 0 */
10116 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
10117 pring->prt[0].type = phba->cfg_multi_ring_type;
10118 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
10122 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
10123 * @phba: Pointer to HBA context object.
10124 * @iocbq: Pointer to iocb object.
10126 * The async_event handler calls this routine when it receives
10127 * an ASYNC_STATUS_CN event from the port. The port generates
10128 * this event when an Abort Sequence request to an rport fails
10129 * twice in succession. The abort could be originated by the
10130 * driver or by the port. The ABTS could have been for an ELS
10131 * or FCP IO. The port only generates this event when an ABTS
10132 * fails to complete after one retry.
10135 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
10136 struct lpfc_iocbq *iocbq)
10138 struct lpfc_nodelist *ndlp = NULL;
10139 uint16_t rpi = 0, vpi = 0;
10140 struct lpfc_vport *vport = NULL;
10142 /* The rpi in the ulpContext is vport-sensitive. */
10143 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
10144 rpi = iocbq->iocb.ulpContext;
10146 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10147 "3092 Port generated ABTS async event "
10148 "on vpi %d rpi %d status 0x%x\n",
10149 vpi, rpi, iocbq->iocb.ulpStatus);
10151 vport = lpfc_find_vport_by_vpid(phba, vpi);
10154 ndlp = lpfc_findnode_rpi(vport, rpi);
10155 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
10158 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
10159 lpfc_sli_abts_recover_port(vport, ndlp);
10163 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10164 "3095 Event Context not found, no "
10165 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
10166 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
10170 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
10171 * @phba: pointer to HBA context object.
10172 * @ndlp: nodelist pointer for the impacted rport.
10173 * @axri: pointer to the wcqe containing the failed exchange.
10175 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
10176 * port. The port generates this event when an abort exchange request to an
10177 * rport fails twice in succession with no reply. The abort could be originated
10178 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
10181 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
10182 struct lpfc_nodelist *ndlp,
10183 struct sli4_wcqe_xri_aborted *axri)
10185 struct lpfc_vport *vport;
10186 uint32_t ext_status = 0;
10188 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
10189 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10190 "3115 Node Context not found, driver "
10191 "ignoring abts err event\n");
10195 vport = ndlp->vport;
10196 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10197 "3116 Port generated FCP XRI ABORT event on "
10198 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
10199 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
10200 bf_get(lpfc_wcqe_xa_xri, axri),
10201 bf_get(lpfc_wcqe_xa_status, axri),
10205 * Catch the ABTS protocol failure case. Older OCe FW releases returned
10206 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
10207 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
10209 ext_status = axri->parameter & IOERR_PARAM_MASK;
10210 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
10211 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
10212 lpfc_sli_abts_recover_port(vport, ndlp);
10216 * lpfc_sli_async_event_handler - ASYNC iocb handler function
10217 * @phba: Pointer to HBA context object.
10218 * @pring: Pointer to driver SLI ring object.
10219 * @iocbq: Pointer to iocb object.
10221 * This function is called by the slow ring event handler
10222 * function when there is an ASYNC event iocb in the ring.
10223 * This function is called with no lock held.
10224 * Currently this function handles only temperature related
10225 * ASYNC events. The function decodes the temperature sensor
10226 * event message and posts events for the management applications.
10229 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
10230 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
10234 struct temp_event temp_event_data;
10235 struct Scsi_Host *shost;
10238 icmd = &iocbq->iocb;
10239 evt_code = icmd->un.asyncstat.evt_code;
10241 switch (evt_code) {
10242 case ASYNC_TEMP_WARN:
10243 case ASYNC_TEMP_SAFE:
10244 temp_event_data.data = (uint32_t) icmd->ulpContext;
10245 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
10246 if (evt_code == ASYNC_TEMP_WARN) {
10247 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
10248 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
10249 "0347 Adapter is very hot, please take "
10250 "corrective action. temperature : %d Celsius\n",
10251 (uint32_t) icmd->ulpContext);
10253 temp_event_data.event_code = LPFC_NORMAL_TEMP;
10254 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
10255 "0340 Adapter temperature is OK now. "
10256 "temperature : %d Celsius\n",
10257 (uint32_t) icmd->ulpContext);
10260 /* Send temperature change event to applications */
10261 shost = lpfc_shost_from_vport(phba->pport);
10262 fc_host_post_vendor_event(shost, fc_get_event_number(),
10263 sizeof(temp_event_data), (char *) &temp_event_data,
10264 LPFC_NL_VENDOR_ID);
10266 case ASYNC_STATUS_CN:
10267 lpfc_sli_abts_err_handler(phba, iocbq);
10270 iocb_w = (uint32_t *) icmd;
10271 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10272 "0346 Ring %d handler: unexpected ASYNC_STATUS"
10274 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
10275 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
10276 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
10277 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
10278 pring->ringno, icmd->un.asyncstat.evt_code,
10279 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
10280 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
10281 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
10282 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
10290 * lpfc_sli4_setup - SLI ring setup function
10291 * @phba: Pointer to HBA context object.
10293 * lpfc_sli_setup sets up rings of the SLI interface with
10294 * number of iocbs per ring and iotags. This function is
10295 * called while driver attach to the HBA and before the
10296 * interrupts are enabled. So there is no need for locking.
10298 * This function always returns 0.
10301 lpfc_sli4_setup(struct lpfc_hba *phba)
10303 struct lpfc_sli_ring *pring;
10305 pring = phba->sli4_hba.els_wq->pring;
10306 pring->num_mask = LPFC_MAX_RING_MASK;
10307 pring->prt[0].profile = 0; /* Mask 0 */
10308 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
10309 pring->prt[0].type = FC_TYPE_ELS;
10310 pring->prt[0].lpfc_sli_rcv_unsol_event =
10311 lpfc_els_unsol_event;
10312 pring->prt[1].profile = 0; /* Mask 1 */
10313 pring->prt[1].rctl = FC_RCTL_ELS_REP;
10314 pring->prt[1].type = FC_TYPE_ELS;
10315 pring->prt[1].lpfc_sli_rcv_unsol_event =
10316 lpfc_els_unsol_event;
10317 pring->prt[2].profile = 0; /* Mask 2 */
10318 /* NameServer Inquiry */
10319 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
10321 pring->prt[2].type = FC_TYPE_CT;
10322 pring->prt[2].lpfc_sli_rcv_unsol_event =
10323 lpfc_ct_unsol_event;
10324 pring->prt[3].profile = 0; /* Mask 3 */
10325 /* NameServer response */
10326 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
10328 pring->prt[3].type = FC_TYPE_CT;
10329 pring->prt[3].lpfc_sli_rcv_unsol_event =
10330 lpfc_ct_unsol_event;
10335 * lpfc_sli_setup - SLI ring setup function
10336 * @phba: Pointer to HBA context object.
10338 * lpfc_sli_setup sets up rings of the SLI interface with
10339 * number of iocbs per ring and iotags. This function is
10340 * called while driver attach to the HBA and before the
10341 * interrupts are enabled. So there is no need for locking.
10343 * This function always returns 0. SLI3 only.
10346 lpfc_sli_setup(struct lpfc_hba *phba)
10348 int i, totiocbsize = 0;
10349 struct lpfc_sli *psli = &phba->sli;
10350 struct lpfc_sli_ring *pring;
10352 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
10353 psli->sli_flag = 0;
10355 psli->iocbq_lookup = NULL;
10356 psli->iocbq_lookup_len = 0;
10357 psli->last_iotag = 0;
10359 for (i = 0; i < psli->num_rings; i++) {
10360 pring = &psli->sli3_ring[i];
10362 case LPFC_FCP_RING: /* ring 0 - FCP */
10363 /* numCiocb and numRiocb are used in config_port */
10364 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
10365 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
10366 pring->sli.sli3.numCiocb +=
10367 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10368 pring->sli.sli3.numRiocb +=
10369 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10370 pring->sli.sli3.numCiocb +=
10371 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10372 pring->sli.sli3.numRiocb +=
10373 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10374 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10375 SLI3_IOCB_CMD_SIZE :
10376 SLI2_IOCB_CMD_SIZE;
10377 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10378 SLI3_IOCB_RSP_SIZE :
10379 SLI2_IOCB_RSP_SIZE;
10380 pring->iotag_ctr = 0;
10382 (phba->cfg_hba_queue_depth * 2);
10383 pring->fast_iotag = pring->iotag_max;
10384 pring->num_mask = 0;
10386 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
10387 /* numCiocb and numRiocb are used in config_port */
10388 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
10389 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
10390 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10391 SLI3_IOCB_CMD_SIZE :
10392 SLI2_IOCB_CMD_SIZE;
10393 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10394 SLI3_IOCB_RSP_SIZE :
10395 SLI2_IOCB_RSP_SIZE;
10396 pring->iotag_max = phba->cfg_hba_queue_depth;
10397 pring->num_mask = 0;
10399 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
10400 /* numCiocb and numRiocb are used in config_port */
10401 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
10402 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
10403 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10404 SLI3_IOCB_CMD_SIZE :
10405 SLI2_IOCB_CMD_SIZE;
10406 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10407 SLI3_IOCB_RSP_SIZE :
10408 SLI2_IOCB_RSP_SIZE;
10409 pring->fast_iotag = 0;
10410 pring->iotag_ctr = 0;
10411 pring->iotag_max = 4096;
10412 pring->lpfc_sli_rcv_async_status =
10413 lpfc_sli_async_event_handler;
10414 pring->num_mask = LPFC_MAX_RING_MASK;
10415 pring->prt[0].profile = 0; /* Mask 0 */
10416 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
10417 pring->prt[0].type = FC_TYPE_ELS;
10418 pring->prt[0].lpfc_sli_rcv_unsol_event =
10419 lpfc_els_unsol_event;
10420 pring->prt[1].profile = 0; /* Mask 1 */
10421 pring->prt[1].rctl = FC_RCTL_ELS_REP;
10422 pring->prt[1].type = FC_TYPE_ELS;
10423 pring->prt[1].lpfc_sli_rcv_unsol_event =
10424 lpfc_els_unsol_event;
10425 pring->prt[2].profile = 0; /* Mask 2 */
10426 /* NameServer Inquiry */
10427 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
10429 pring->prt[2].type = FC_TYPE_CT;
10430 pring->prt[2].lpfc_sli_rcv_unsol_event =
10431 lpfc_ct_unsol_event;
10432 pring->prt[3].profile = 0; /* Mask 3 */
10433 /* NameServer response */
10434 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
10436 pring->prt[3].type = FC_TYPE_CT;
10437 pring->prt[3].lpfc_sli_rcv_unsol_event =
10438 lpfc_ct_unsol_event;
10441 totiocbsize += (pring->sli.sli3.numCiocb *
10442 pring->sli.sli3.sizeCiocb) +
10443 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
10445 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
10446 /* Too many cmd / rsp ring entries in SLI2 SLIM */
10447 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
10448 "SLI2 SLIM Data: x%x x%lx\n",
10449 phba->brd_no, totiocbsize,
10450 (unsigned long) MAX_SLIM_IOCB_SIZE);
10452 if (phba->cfg_multi_ring_support == 2)
10453 lpfc_extra_ring_setup(phba);
10459 * lpfc_sli4_queue_init - Queue initialization function
10460 * @phba: Pointer to HBA context object.
10462 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
10463 * ring. This function also initializes ring indices of each ring.
10464 * This function is called during the initialization of the SLI
10465 * interface of an HBA.
10466 * This function is called with no lock held and always returns
10470 lpfc_sli4_queue_init(struct lpfc_hba *phba)
10472 struct lpfc_sli *psli;
10473 struct lpfc_sli_ring *pring;
10477 spin_lock_irq(&phba->hbalock);
10478 INIT_LIST_HEAD(&psli->mboxq);
10479 INIT_LIST_HEAD(&psli->mboxq_cmpl);
10480 /* Initialize list headers for txq and txcmplq as double linked lists */
10481 for (i = 0; i < phba->cfg_hdw_queue; i++) {
10482 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
10484 pring->ringno = LPFC_FCP_RING;
10485 pring->txcmplq_cnt = 0;
10486 INIT_LIST_HEAD(&pring->txq);
10487 INIT_LIST_HEAD(&pring->txcmplq);
10488 INIT_LIST_HEAD(&pring->iocb_continueq);
10489 spin_lock_init(&pring->ring_lock);
10491 pring = phba->sli4_hba.els_wq->pring;
10493 pring->ringno = LPFC_ELS_RING;
10494 pring->txcmplq_cnt = 0;
10495 INIT_LIST_HEAD(&pring->txq);
10496 INIT_LIST_HEAD(&pring->txcmplq);
10497 INIT_LIST_HEAD(&pring->iocb_continueq);
10498 spin_lock_init(&pring->ring_lock);
10500 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10501 pring = phba->sli4_hba.nvmels_wq->pring;
10503 pring->ringno = LPFC_ELS_RING;
10504 pring->txcmplq_cnt = 0;
10505 INIT_LIST_HEAD(&pring->txq);
10506 INIT_LIST_HEAD(&pring->txcmplq);
10507 INIT_LIST_HEAD(&pring->iocb_continueq);
10508 spin_lock_init(&pring->ring_lock);
10511 spin_unlock_irq(&phba->hbalock);
10515 * lpfc_sli_queue_init - Queue initialization function
10516 * @phba: Pointer to HBA context object.
10518 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
10519 * ring. This function also initializes ring indices of each ring.
10520 * This function is called during the initialization of the SLI
10521 * interface of an HBA.
10522 * This function is called with no lock held and always returns
10526 lpfc_sli_queue_init(struct lpfc_hba *phba)
10528 struct lpfc_sli *psli;
10529 struct lpfc_sli_ring *pring;
10533 spin_lock_irq(&phba->hbalock);
10534 INIT_LIST_HEAD(&psli->mboxq);
10535 INIT_LIST_HEAD(&psli->mboxq_cmpl);
10536 /* Initialize list headers for txq and txcmplq as double linked lists */
10537 for (i = 0; i < psli->num_rings; i++) {
10538 pring = &psli->sli3_ring[i];
10540 pring->sli.sli3.next_cmdidx = 0;
10541 pring->sli.sli3.local_getidx = 0;
10542 pring->sli.sli3.cmdidx = 0;
10543 INIT_LIST_HEAD(&pring->iocb_continueq);
10544 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
10545 INIT_LIST_HEAD(&pring->postbufq);
10547 INIT_LIST_HEAD(&pring->txq);
10548 INIT_LIST_HEAD(&pring->txcmplq);
10549 spin_lock_init(&pring->ring_lock);
10551 spin_unlock_irq(&phba->hbalock);
10555 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
10556 * @phba: Pointer to HBA context object.
10558 * This routine flushes the mailbox command subsystem. It will unconditionally
10559 * flush all the mailbox commands in the three possible stages in the mailbox
10560 * command sub-system: pending mailbox command queue; the outstanding mailbox
10561 * command; and completed mailbox command queue. It is caller's responsibility
10562 * to make sure that the driver is in the proper state to flush the mailbox
10563 * command sub-system. Namely, the posting of mailbox commands into the
10564 * pending mailbox command queue from the various clients must be stopped;
10565 * either the HBA is in a state that it will never works on the outstanding
10566 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
10567 * mailbox command has been completed.
10570 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
10572 LIST_HEAD(completions);
10573 struct lpfc_sli *psli = &phba->sli;
10575 unsigned long iflag;
10577 /* Disable softirqs, including timers from obtaining phba->hbalock */
10578 local_bh_disable();
10580 /* Flush all the mailbox commands in the mbox system */
10581 spin_lock_irqsave(&phba->hbalock, iflag);
10583 /* The pending mailbox command queue */
10584 list_splice_init(&phba->sli.mboxq, &completions);
10585 /* The outstanding active mailbox command */
10586 if (psli->mbox_active) {
10587 list_add_tail(&psli->mbox_active->list, &completions);
10588 psli->mbox_active = NULL;
10589 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10591 /* The completed mailbox command queue */
10592 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
10593 spin_unlock_irqrestore(&phba->hbalock, iflag);
10595 /* Enable softirqs again, done with phba->hbalock */
10598 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
10599 while (!list_empty(&completions)) {
10600 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
10601 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
10602 if (pmb->mbox_cmpl)
10603 pmb->mbox_cmpl(phba, pmb);
10608 * lpfc_sli_host_down - Vport cleanup function
10609 * @vport: Pointer to virtual port object.
10611 * lpfc_sli_host_down is called to clean up the resources
10612 * associated with a vport before destroying virtual
10613 * port data structures.
10614 * This function does following operations:
10615 * - Free discovery resources associated with this virtual
10617 * - Free iocbs associated with this virtual port in
10619 * - Send abort for all iocb commands associated with this
10620 * vport in txcmplq.
10622 * This function is called with no lock held and always returns 1.
10625 lpfc_sli_host_down(struct lpfc_vport *vport)
10627 LIST_HEAD(completions);
10628 struct lpfc_hba *phba = vport->phba;
10629 struct lpfc_sli *psli = &phba->sli;
10630 struct lpfc_queue *qp = NULL;
10631 struct lpfc_sli_ring *pring;
10632 struct lpfc_iocbq *iocb, *next_iocb;
10634 unsigned long flags = 0;
10635 uint16_t prev_pring_flag;
10637 lpfc_cleanup_discovery_resources(vport);
10639 spin_lock_irqsave(&phba->hbalock, flags);
10642 * Error everything on the txq since these iocbs
10643 * have not been given to the FW yet.
10644 * Also issue ABTS for everything on the txcmplq
10646 if (phba->sli_rev != LPFC_SLI_REV4) {
10647 for (i = 0; i < psli->num_rings; i++) {
10648 pring = &psli->sli3_ring[i];
10649 prev_pring_flag = pring->flag;
10650 /* Only slow rings */
10651 if (pring->ringno == LPFC_ELS_RING) {
10652 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10653 /* Set the lpfc data pending flag */
10654 set_bit(LPFC_DATA_READY, &phba->data_flags);
10656 list_for_each_entry_safe(iocb, next_iocb,
10657 &pring->txq, list) {
10658 if (iocb->vport != vport)
10660 list_move_tail(&iocb->list, &completions);
10662 list_for_each_entry_safe(iocb, next_iocb,
10663 &pring->txcmplq, list) {
10664 if (iocb->vport != vport)
10666 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
10668 pring->flag = prev_pring_flag;
10671 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
10675 if (pring == phba->sli4_hba.els_wq->pring) {
10676 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10677 /* Set the lpfc data pending flag */
10678 set_bit(LPFC_DATA_READY, &phba->data_flags);
10680 prev_pring_flag = pring->flag;
10681 spin_lock_irq(&pring->ring_lock);
10682 list_for_each_entry_safe(iocb, next_iocb,
10683 &pring->txq, list) {
10684 if (iocb->vport != vport)
10686 list_move_tail(&iocb->list, &completions);
10688 spin_unlock_irq(&pring->ring_lock);
10689 list_for_each_entry_safe(iocb, next_iocb,
10690 &pring->txcmplq, list) {
10691 if (iocb->vport != vport)
10693 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
10695 pring->flag = prev_pring_flag;
10698 spin_unlock_irqrestore(&phba->hbalock, flags);
10700 /* Cancel all the IOCBs from the completions list */
10701 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10707 * lpfc_sli_hba_down - Resource cleanup function for the HBA
10708 * @phba: Pointer to HBA context object.
10710 * This function cleans up all iocb, buffers, mailbox commands
10711 * while shutting down the HBA. This function is called with no
10712 * lock held and always returns 1.
10713 * This function does the following to cleanup driver resources:
10714 * - Free discovery resources for each virtual port
10715 * - Cleanup any pending fabric iocbs
10716 * - Iterate through the iocb txq and free each entry
10718 * - Free up any buffer posted to the HBA
10719 * - Free mailbox commands in the mailbox queue.
10722 lpfc_sli_hba_down(struct lpfc_hba *phba)
10724 LIST_HEAD(completions);
10725 struct lpfc_sli *psli = &phba->sli;
10726 struct lpfc_queue *qp = NULL;
10727 struct lpfc_sli_ring *pring;
10728 struct lpfc_dmabuf *buf_ptr;
10729 unsigned long flags = 0;
10732 /* Shutdown the mailbox command sub-system */
10733 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
10735 lpfc_hba_down_prep(phba);
10737 /* Disable softirqs, including timers from obtaining phba->hbalock */
10738 local_bh_disable();
10740 lpfc_fabric_abort_hba(phba);
10742 spin_lock_irqsave(&phba->hbalock, flags);
10745 * Error everything on the txq since these iocbs
10746 * have not been given to the FW yet.
10748 if (phba->sli_rev != LPFC_SLI_REV4) {
10749 for (i = 0; i < psli->num_rings; i++) {
10750 pring = &psli->sli3_ring[i];
10751 /* Only slow rings */
10752 if (pring->ringno == LPFC_ELS_RING) {
10753 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10754 /* Set the lpfc data pending flag */
10755 set_bit(LPFC_DATA_READY, &phba->data_flags);
10757 list_splice_init(&pring->txq, &completions);
10760 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
10764 spin_lock(&pring->ring_lock);
10765 list_splice_init(&pring->txq, &completions);
10766 spin_unlock(&pring->ring_lock);
10767 if (pring == phba->sli4_hba.els_wq->pring) {
10768 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10769 /* Set the lpfc data pending flag */
10770 set_bit(LPFC_DATA_READY, &phba->data_flags);
10774 spin_unlock_irqrestore(&phba->hbalock, flags);
10776 /* Cancel all the IOCBs from the completions list */
10777 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10780 spin_lock_irqsave(&phba->hbalock, flags);
10781 list_splice_init(&phba->elsbuf, &completions);
10782 phba->elsbuf_cnt = 0;
10783 phba->elsbuf_prev_cnt = 0;
10784 spin_unlock_irqrestore(&phba->hbalock, flags);
10786 while (!list_empty(&completions)) {
10787 list_remove_head(&completions, buf_ptr,
10788 struct lpfc_dmabuf, list);
10789 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
10793 /* Enable softirqs again, done with phba->hbalock */
10796 /* Return any active mbox cmds */
10797 del_timer_sync(&psli->mbox_tmo);
10799 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
10800 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
10801 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
10807 * lpfc_sli_pcimem_bcopy - SLI memory copy function
10808 * @srcp: Source memory pointer.
10809 * @destp: Destination memory pointer.
10810 * @cnt: Number of words required to be copied.
10812 * This function is used for copying data between driver memory
10813 * and the SLI memory. This function also changes the endianness
10814 * of each word if native endianness is different from SLI
10815 * endianness. This function can be called with or without
10819 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
10821 uint32_t *src = srcp;
10822 uint32_t *dest = destp;
10826 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
10828 ldata = le32_to_cpu(ldata);
10837 * lpfc_sli_bemem_bcopy - SLI memory copy function
10838 * @srcp: Source memory pointer.
10839 * @destp: Destination memory pointer.
10840 * @cnt: Number of words required to be copied.
10842 * This function is used for copying data between a data structure
10843 * with big endian representation to local endianness.
10844 * This function can be called with or without lock.
10847 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
10849 uint32_t *src = srcp;
10850 uint32_t *dest = destp;
10854 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
10856 ldata = be32_to_cpu(ldata);
10864 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
10865 * @phba: Pointer to HBA context object.
10866 * @pring: Pointer to driver SLI ring object.
10867 * @mp: Pointer to driver buffer object.
10869 * This function is called with no lock held.
10870 * It always return zero after adding the buffer to the postbufq
10874 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10875 struct lpfc_dmabuf *mp)
10877 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
10879 spin_lock_irq(&phba->hbalock);
10880 list_add_tail(&mp->list, &pring->postbufq);
10881 pring->postbufq_cnt++;
10882 spin_unlock_irq(&phba->hbalock);
10887 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
10888 * @phba: Pointer to HBA context object.
10890 * When HBQ is enabled, buffers are searched based on tags. This function
10891 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
10892 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
10893 * does not conflict with tags of buffer posted for unsolicited events.
10894 * The function returns the allocated tag. The function is called with
10898 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
10900 spin_lock_irq(&phba->hbalock);
10901 phba->buffer_tag_count++;
10903 * Always set the QUE_BUFTAG_BIT to distiguish between
10904 * a tag assigned by HBQ.
10906 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
10907 spin_unlock_irq(&phba->hbalock);
10908 return phba->buffer_tag_count;
10912 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
10913 * @phba: Pointer to HBA context object.
10914 * @pring: Pointer to driver SLI ring object.
10915 * @tag: Buffer tag.
10917 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
10918 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
10919 * iocb is posted to the response ring with the tag of the buffer.
10920 * This function searches the pring->postbufq list using the tag
10921 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
10922 * iocb. If the buffer is found then lpfc_dmabuf object of the
10923 * buffer is returned to the caller else NULL is returned.
10924 * This function is called with no lock held.
10926 struct lpfc_dmabuf *
10927 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10930 struct lpfc_dmabuf *mp, *next_mp;
10931 struct list_head *slp = &pring->postbufq;
10933 /* Search postbufq, from the beginning, looking for a match on tag */
10934 spin_lock_irq(&phba->hbalock);
10935 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
10936 if (mp->buffer_tag == tag) {
10937 list_del_init(&mp->list);
10938 pring->postbufq_cnt--;
10939 spin_unlock_irq(&phba->hbalock);
10944 spin_unlock_irq(&phba->hbalock);
10945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10946 "0402 Cannot find virtual addr for buffer tag on "
10947 "ring %d Data x%lx x%px x%px x%x\n",
10948 pring->ringno, (unsigned long) tag,
10949 slp->next, slp->prev, pring->postbufq_cnt);
10955 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
10956 * @phba: Pointer to HBA context object.
10957 * @pring: Pointer to driver SLI ring object.
10958 * @phys: DMA address of the buffer.
10960 * This function searches the buffer list using the dma_address
10961 * of unsolicited event to find the driver's lpfc_dmabuf object
10962 * corresponding to the dma_address. The function returns the
10963 * lpfc_dmabuf object if a buffer is found else it returns NULL.
10964 * This function is called by the ct and els unsolicited event
10965 * handlers to get the buffer associated with the unsolicited
10968 * This function is called with no lock held.
10970 struct lpfc_dmabuf *
10971 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10974 struct lpfc_dmabuf *mp, *next_mp;
10975 struct list_head *slp = &pring->postbufq;
10977 /* Search postbufq, from the beginning, looking for a match on phys */
10978 spin_lock_irq(&phba->hbalock);
10979 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
10980 if (mp->phys == phys) {
10981 list_del_init(&mp->list);
10982 pring->postbufq_cnt--;
10983 spin_unlock_irq(&phba->hbalock);
10988 spin_unlock_irq(&phba->hbalock);
10989 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10990 "0410 Cannot find virtual addr for mapped buf on "
10991 "ring %d Data x%llx x%px x%px x%x\n",
10992 pring->ringno, (unsigned long long)phys,
10993 slp->next, slp->prev, pring->postbufq_cnt);
10998 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
10999 * @phba: Pointer to HBA context object.
11000 * @cmdiocb: Pointer to driver command iocb object.
11001 * @rspiocb: Pointer to driver response iocb object.
11003 * This function is the completion handler for the abort iocbs for
11004 * ELS commands. This function is called from the ELS ring event
11005 * handler with no lock held. This function frees memory resources
11006 * associated with the abort iocb.
11009 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11010 struct lpfc_iocbq *rspiocb)
11012 IOCB_t *irsp = &rspiocb->iocb;
11013 uint16_t abort_iotag, abort_context;
11014 struct lpfc_iocbq *abort_iocb = NULL;
11016 if (irsp->ulpStatus) {
11019 * Assume that the port already completed and returned, or
11020 * will return the iocb. Just Log the message.
11022 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
11023 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
11025 spin_lock_irq(&phba->hbalock);
11026 if (phba->sli_rev < LPFC_SLI_REV4) {
11027 if (irsp->ulpCommand == CMD_ABORT_XRI_CX &&
11028 irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
11029 irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) {
11030 spin_unlock_irq(&phba->hbalock);
11033 if (abort_iotag != 0 &&
11034 abort_iotag <= phba->sli.last_iotag)
11036 phba->sli.iocbq_lookup[abort_iotag];
11038 /* For sli4 the abort_tag is the XRI,
11039 * so the abort routine puts the iotag of the iocb
11040 * being aborted in the context field of the abort
11043 abort_iocb = phba->sli.iocbq_lookup[abort_context];
11045 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
11046 "0327 Cannot abort els iocb x%px "
11047 "with tag %x context %x, abort status %x, "
11049 abort_iocb, abort_iotag, abort_context,
11050 irsp->ulpStatus, irsp->un.ulpWord[4]);
11052 spin_unlock_irq(&phba->hbalock);
11055 lpfc_sli_release_iocbq(phba, cmdiocb);
11060 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
11061 * @phba: Pointer to HBA context object.
11062 * @cmdiocb: Pointer to driver command iocb object.
11063 * @rspiocb: Pointer to driver response iocb object.
11065 * The function is called from SLI ring event handler with no
11066 * lock held. This function is the completion handler for ELS commands
11067 * which are aborted. The function frees memory resources used for
11068 * the aborted ELS commands.
11071 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11072 struct lpfc_iocbq *rspiocb)
11074 IOCB_t *irsp = &rspiocb->iocb;
11076 /* ELS cmd tag <ulpIoTag> completes */
11077 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
11078 "0139 Ignoring ELS cmd tag x%x completion Data: "
11080 irsp->ulpIoTag, irsp->ulpStatus,
11081 irsp->un.ulpWord[4], irsp->ulpTimeout);
11082 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
11083 lpfc_ct_free_iocb(phba, cmdiocb);
11085 lpfc_els_free_iocb(phba, cmdiocb);
11090 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
11091 * @phba: Pointer to HBA context object.
11092 * @pring: Pointer to driver SLI ring object.
11093 * @cmdiocb: Pointer to driver command iocb object.
11095 * This function issues an abort iocb for the provided command iocb down to
11096 * the port. Other than the case the outstanding command iocb is an abort
11097 * request, this function issues abort out unconditionally. This function is
11098 * called with hbalock held. The function returns 0 when it fails due to
11099 * memory allocation failure or when the command iocb is an abort request.
11102 lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11103 struct lpfc_iocbq *cmdiocb)
11105 struct lpfc_vport *vport = cmdiocb->vport;
11106 struct lpfc_iocbq *abtsiocbp;
11107 IOCB_t *icmd = NULL;
11108 IOCB_t *iabt = NULL;
11110 unsigned long iflags;
11111 struct lpfc_nodelist *ndlp;
11113 lockdep_assert_held(&phba->hbalock);
11116 * There are certain command types we don't want to abort. And we
11117 * don't want to abort commands that are already in the process of
11120 icmd = &cmdiocb->iocb;
11121 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
11122 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
11123 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
11126 /* issue ABTS for this IOCB based on iotag */
11127 abtsiocbp = __lpfc_sli_get_iocbq(phba);
11128 if (abtsiocbp == NULL)
11131 /* This signals the response to set the correct status
11132 * before calling the completion handler
11134 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
11136 iabt = &abtsiocbp->iocb;
11137 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
11138 iabt->un.acxri.abortContextTag = icmd->ulpContext;
11139 if (phba->sli_rev == LPFC_SLI_REV4) {
11140 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
11141 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
11143 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
11144 if (pring->ringno == LPFC_ELS_RING) {
11145 ndlp = (struct lpfc_nodelist *)(cmdiocb->context1);
11146 iabt->un.acxri.abortContextTag = ndlp->nlp_rpi;
11150 iabt->ulpClass = icmd->ulpClass;
11152 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11153 abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
11154 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
11155 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
11156 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
11157 abtsiocbp->iocb_flag |= LPFC_IO_FOF;
11159 if (phba->link_state >= LPFC_LINK_UP)
11160 iabt->ulpCommand = CMD_ABORT_XRI_CN;
11162 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
11164 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
11165 abtsiocbp->vport = vport;
11167 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
11168 "0339 Abort xri x%x, original iotag x%x, "
11169 "abort cmd iotag x%x\n",
11170 iabt->un.acxri.abortIoTag,
11171 iabt->un.acxri.abortContextTag,
11174 if (phba->sli_rev == LPFC_SLI_REV4) {
11175 pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
11176 if (unlikely(pring == NULL))
11178 /* Note: both hbalock and ring_lock need to be set here */
11179 spin_lock_irqsave(&pring->ring_lock, iflags);
11180 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
11182 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11184 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
11189 __lpfc_sli_release_iocbq(phba, abtsiocbp);
11192 * Caller to this routine should check for IOCB_ERROR
11193 * and handle it properly. This routine no longer removes
11194 * iocb off txcmplq and call compl in case of IOCB_ERROR.
11200 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
11201 * @phba: Pointer to HBA context object.
11202 * @pring: Pointer to driver SLI ring object.
11203 * @cmdiocb: Pointer to driver command iocb object.
11205 * This function issues an abort iocb for the provided command iocb. In case
11206 * of unloading, the abort iocb will not be issued to commands on the ELS
11207 * ring. Instead, the callback function shall be changed to those commands
11208 * so that nothing happens when them finishes. This function is called with
11209 * hbalock held. The function returns 0 when the command iocb is an abort
11213 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11214 struct lpfc_iocbq *cmdiocb)
11216 struct lpfc_vport *vport = cmdiocb->vport;
11217 int retval = IOCB_ERROR;
11218 IOCB_t *icmd = NULL;
11220 lockdep_assert_held(&phba->hbalock);
11223 * There are certain command types we don't want to abort. And we
11224 * don't want to abort commands that are already in the process of
11227 icmd = &cmdiocb->iocb;
11228 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
11229 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
11230 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
11234 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
11235 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
11237 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
11238 goto abort_iotag_exit;
11242 * If we're unloading, don't abort iocb on the ELS ring, but change
11243 * the callback so that nothing happens when it finishes.
11245 if ((vport->load_flag & FC_UNLOADING) &&
11246 (pring->ringno == LPFC_ELS_RING)) {
11247 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
11248 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
11250 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
11251 goto abort_iotag_exit;
11254 /* Now, we try to issue the abort to the cmdiocb out */
11255 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
11259 * Caller to this routine should check for IOCB_ERROR
11260 * and handle it properly. This routine no longer removes
11261 * iocb off txcmplq and call compl in case of IOCB_ERROR.
11267 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
11268 * @phba: pointer to lpfc HBA data structure.
11270 * This routine will abort all pending and outstanding iocbs to an HBA.
11273 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
11275 struct lpfc_sli *psli = &phba->sli;
11276 struct lpfc_sli_ring *pring;
11277 struct lpfc_queue *qp = NULL;
11280 if (phba->sli_rev != LPFC_SLI_REV4) {
11281 for (i = 0; i < psli->num_rings; i++) {
11282 pring = &psli->sli3_ring[i];
11283 lpfc_sli_abort_iocb_ring(phba, pring);
11287 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11291 lpfc_sli_abort_iocb_ring(phba, pring);
11296 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
11297 * @iocbq: Pointer to driver iocb object.
11298 * @vport: Pointer to driver virtual port object.
11299 * @tgt_id: SCSI ID of the target.
11300 * @lun_id: LUN ID of the scsi device.
11301 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
11303 * This function acts as an iocb filter for functions which abort or count
11304 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
11305 * 0 if the filtering criteria is met for the given iocb and will return
11306 * 1 if the filtering criteria is not met.
11307 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
11308 * given iocb is for the SCSI device specified by vport, tgt_id and
11309 * lun_id parameter.
11310 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
11311 * given iocb is for the SCSI target specified by vport and tgt_id
11313 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
11314 * given iocb is for the SCSI host associated with the given vport.
11315 * This function is called with no locks held.
11318 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
11319 uint16_t tgt_id, uint64_t lun_id,
11320 lpfc_ctx_cmd ctx_cmd)
11322 struct lpfc_io_buf *lpfc_cmd;
11325 if (iocbq->vport != vport)
11328 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
11329 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ))
11332 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
11334 if (lpfc_cmd->pCmd == NULL)
11339 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
11340 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
11341 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
11345 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
11346 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
11349 case LPFC_CTX_HOST:
11353 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
11354 __func__, ctx_cmd);
11362 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
11363 * @vport: Pointer to virtual port.
11364 * @tgt_id: SCSI ID of the target.
11365 * @lun_id: LUN ID of the scsi device.
11366 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11368 * This function returns number of FCP commands pending for the vport.
11369 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
11370 * commands pending on the vport associated with SCSI device specified
11371 * by tgt_id and lun_id parameters.
11372 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
11373 * commands pending on the vport associated with SCSI target specified
11374 * by tgt_id parameter.
11375 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
11376 * commands pending on the vport.
11377 * This function returns the number of iocbs which satisfy the filter.
11378 * This function is called without any lock held.
11381 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
11382 lpfc_ctx_cmd ctx_cmd)
11384 struct lpfc_hba *phba = vport->phba;
11385 struct lpfc_iocbq *iocbq;
11388 spin_lock_irq(&phba->hbalock);
11389 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
11390 iocbq = phba->sli.iocbq_lookup[i];
11392 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
11396 spin_unlock_irq(&phba->hbalock);
11402 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
11403 * @phba: Pointer to HBA context object
11404 * @cmdiocb: Pointer to command iocb object.
11405 * @rspiocb: Pointer to response iocb object.
11407 * This function is called when an aborted FCP iocb completes. This
11408 * function is called by the ring event handler with no lock held.
11409 * This function frees the iocb.
11412 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11413 struct lpfc_iocbq *rspiocb)
11415 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11416 "3096 ABORT_XRI_CN completing on rpi x%x "
11417 "original iotag x%x, abort cmd iotag x%x "
11418 "status 0x%x, reason 0x%x\n",
11419 cmdiocb->iocb.un.acxri.abortContextTag,
11420 cmdiocb->iocb.un.acxri.abortIoTag,
11421 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
11422 rspiocb->iocb.un.ulpWord[4]);
11423 lpfc_sli_release_iocbq(phba, cmdiocb);
11428 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
11429 * @vport: Pointer to virtual port.
11430 * @pring: Pointer to driver SLI ring object.
11431 * @tgt_id: SCSI ID of the target.
11432 * @lun_id: LUN ID of the scsi device.
11433 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11435 * This function sends an abort command for every SCSI command
11436 * associated with the given virtual port pending on the ring
11437 * filtered by lpfc_sli_validate_fcp_iocb function.
11438 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
11439 * FCP iocbs associated with lun specified by tgt_id and lun_id
11441 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
11442 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11443 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
11444 * FCP iocbs associated with virtual port.
11445 * This function returns number of iocbs it failed to abort.
11446 * This function is called with no locks held.
11449 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
11450 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
11452 struct lpfc_hba *phba = vport->phba;
11453 struct lpfc_iocbq *iocbq;
11454 struct lpfc_iocbq *abtsiocb;
11455 struct lpfc_sli_ring *pring_s4;
11456 IOCB_t *cmd = NULL;
11457 int errcnt = 0, ret_val = 0;
11460 /* all I/Os are in process of being flushed */
11461 if (phba->hba_flag & HBA_IOQ_FLUSH)
11464 for (i = 1; i <= phba->sli.last_iotag; i++) {
11465 iocbq = phba->sli.iocbq_lookup[i];
11467 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
11472 * If the iocbq is already being aborted, don't take a second
11473 * action, but do count it.
11475 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
11478 /* issue ABTS for this IOCB based on iotag */
11479 abtsiocb = lpfc_sli_get_iocbq(phba);
11480 if (abtsiocb == NULL) {
11485 /* indicate the IO is being aborted by the driver. */
11486 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
11488 cmd = &iocbq->iocb;
11489 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
11490 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
11491 if (phba->sli_rev == LPFC_SLI_REV4)
11492 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
11494 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
11495 abtsiocb->iocb.ulpLe = 1;
11496 abtsiocb->iocb.ulpClass = cmd->ulpClass;
11497 abtsiocb->vport = vport;
11499 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11500 abtsiocb->hba_wqidx = iocbq->hba_wqidx;
11501 if (iocbq->iocb_flag & LPFC_IO_FCP)
11502 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
11503 if (iocbq->iocb_flag & LPFC_IO_FOF)
11504 abtsiocb->iocb_flag |= LPFC_IO_FOF;
11506 if (lpfc_is_link_up(phba))
11507 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
11509 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
11511 /* Setup callback routine and issue the command. */
11512 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
11513 if (phba->sli_rev == LPFC_SLI_REV4) {
11514 pring_s4 = lpfc_sli4_calc_ring(phba, iocbq);
11517 ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno,
11520 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
11522 if (ret_val == IOCB_ERROR) {
11523 lpfc_sli_release_iocbq(phba, abtsiocb);
11533 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
11534 * @vport: Pointer to virtual port.
11535 * @pring: Pointer to driver SLI ring object.
11536 * @tgt_id: SCSI ID of the target.
11537 * @lun_id: LUN ID of the scsi device.
11538 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11540 * This function sends an abort command for every SCSI command
11541 * associated with the given virtual port pending on the ring
11542 * filtered by lpfc_sli_validate_fcp_iocb function.
11543 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
11544 * FCP iocbs associated with lun specified by tgt_id and lun_id
11546 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
11547 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11548 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
11549 * FCP iocbs associated with virtual port.
11550 * This function returns number of iocbs it aborted .
11551 * This function is called with no locks held right after a taskmgmt
11555 lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
11556 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
11558 struct lpfc_hba *phba = vport->phba;
11559 struct lpfc_io_buf *lpfc_cmd;
11560 struct lpfc_iocbq *abtsiocbq;
11561 struct lpfc_nodelist *ndlp;
11562 struct lpfc_iocbq *iocbq;
11564 int sum, i, ret_val;
11565 unsigned long iflags;
11566 struct lpfc_sli_ring *pring_s4 = NULL;
11568 spin_lock_irqsave(&phba->hbalock, iflags);
11570 /* all I/Os are in process of being flushed */
11571 if (phba->hba_flag & HBA_IOQ_FLUSH) {
11572 spin_unlock_irqrestore(&phba->hbalock, iflags);
11577 for (i = 1; i <= phba->sli.last_iotag; i++) {
11578 iocbq = phba->sli.iocbq_lookup[i];
11580 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
11584 /* Guard against IO completion being called at same time */
11585 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
11586 spin_lock(&lpfc_cmd->buf_lock);
11588 if (!lpfc_cmd->pCmd) {
11589 spin_unlock(&lpfc_cmd->buf_lock);
11593 if (phba->sli_rev == LPFC_SLI_REV4) {
11595 phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
11597 spin_unlock(&lpfc_cmd->buf_lock);
11600 /* Note: both hbalock and ring_lock must be set here */
11601 spin_lock(&pring_s4->ring_lock);
11605 * If the iocbq is already being aborted, don't take a second
11606 * action, but do count it.
11608 if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) ||
11609 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
11610 if (phba->sli_rev == LPFC_SLI_REV4)
11611 spin_unlock(&pring_s4->ring_lock);
11612 spin_unlock(&lpfc_cmd->buf_lock);
11616 /* issue ABTS for this IOCB based on iotag */
11617 abtsiocbq = __lpfc_sli_get_iocbq(phba);
11619 if (phba->sli_rev == LPFC_SLI_REV4)
11620 spin_unlock(&pring_s4->ring_lock);
11621 spin_unlock(&lpfc_cmd->buf_lock);
11625 icmd = &iocbq->iocb;
11626 abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
11627 abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
11628 if (phba->sli_rev == LPFC_SLI_REV4)
11629 abtsiocbq->iocb.un.acxri.abortIoTag =
11630 iocbq->sli4_xritag;
11632 abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
11633 abtsiocbq->iocb.ulpLe = 1;
11634 abtsiocbq->iocb.ulpClass = icmd->ulpClass;
11635 abtsiocbq->vport = vport;
11637 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11638 abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
11639 if (iocbq->iocb_flag & LPFC_IO_FCP)
11640 abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
11641 if (iocbq->iocb_flag & LPFC_IO_FOF)
11642 abtsiocbq->iocb_flag |= LPFC_IO_FOF;
11644 ndlp = lpfc_cmd->rdata->pnode;
11646 if (lpfc_is_link_up(phba) &&
11647 (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
11648 abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
11650 abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
11652 /* Setup callback routine and issue the command. */
11653 abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
11656 * Indicate the IO is being aborted by the driver and set
11657 * the caller's flag into the aborted IO.
11659 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
11661 if (phba->sli_rev == LPFC_SLI_REV4) {
11662 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
11664 spin_unlock(&pring_s4->ring_lock);
11666 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
11670 spin_unlock(&lpfc_cmd->buf_lock);
11672 if (ret_val == IOCB_ERROR)
11673 __lpfc_sli_release_iocbq(phba, abtsiocbq);
11677 spin_unlock_irqrestore(&phba->hbalock, iflags);
11682 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
11683 * @phba: Pointer to HBA context object.
11684 * @cmdiocbq: Pointer to command iocb.
11685 * @rspiocbq: Pointer to response iocb.
11687 * This function is the completion handler for iocbs issued using
11688 * lpfc_sli_issue_iocb_wait function. This function is called by the
11689 * ring event handler function without any lock held. This function
11690 * can be called from both worker thread context and interrupt
11691 * context. This function also can be called from other thread which
11692 * cleans up the SLI layer objects.
11693 * This function copy the contents of the response iocb to the
11694 * response iocb memory object provided by the caller of
11695 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
11696 * sleeps for the iocb completion.
11699 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
11700 struct lpfc_iocbq *cmdiocbq,
11701 struct lpfc_iocbq *rspiocbq)
11703 wait_queue_head_t *pdone_q;
11704 unsigned long iflags;
11705 struct lpfc_io_buf *lpfc_cmd;
11707 spin_lock_irqsave(&phba->hbalock, iflags);
11708 if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
11711 * A time out has occurred for the iocb. If a time out
11712 * completion handler has been supplied, call it. Otherwise,
11713 * just free the iocbq.
11716 spin_unlock_irqrestore(&phba->hbalock, iflags);
11717 cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
11718 cmdiocbq->wait_iocb_cmpl = NULL;
11719 if (cmdiocbq->iocb_cmpl)
11720 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
11722 lpfc_sli_release_iocbq(phba, cmdiocbq);
11726 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
11727 if (cmdiocbq->context2 && rspiocbq)
11728 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
11729 &rspiocbq->iocb, sizeof(IOCB_t));
11731 /* Set the exchange busy flag for task management commands */
11732 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
11733 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
11734 lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
11736 if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY))
11737 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
11739 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
11742 pdone_q = cmdiocbq->context_un.wait_queue;
11745 spin_unlock_irqrestore(&phba->hbalock, iflags);
11750 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
11751 * @phba: Pointer to HBA context object..
11752 * @piocbq: Pointer to command iocb.
11753 * @flag: Flag to test.
11755 * This routine grabs the hbalock and then test the iocb_flag to
11756 * see if the passed in flag is set.
11758 * 1 if flag is set.
11759 * 0 if flag is not set.
11762 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
11763 struct lpfc_iocbq *piocbq, uint32_t flag)
11765 unsigned long iflags;
11768 spin_lock_irqsave(&phba->hbalock, iflags);
11769 ret = piocbq->iocb_flag & flag;
11770 spin_unlock_irqrestore(&phba->hbalock, iflags);
11776 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
11777 * @phba: Pointer to HBA context object..
11778 * @pring: Pointer to sli ring.
11779 * @piocb: Pointer to command iocb.
11780 * @prspiocbq: Pointer to response iocb.
11781 * @timeout: Timeout in number of seconds.
11783 * This function issues the iocb to firmware and waits for the
11784 * iocb to complete. The iocb_cmpl field of the shall be used
11785 * to handle iocbs which time out. If the field is NULL, the
11786 * function shall free the iocbq structure. If more clean up is
11787 * needed, the caller is expected to provide a completion function
11788 * that will provide the needed clean up. If the iocb command is
11789 * not completed within timeout seconds, the function will either
11790 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
11791 * completion function set in the iocb_cmpl field and then return
11792 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
11793 * resources if this function returns IOCB_TIMEDOUT.
11794 * The function waits for the iocb completion using an
11795 * non-interruptible wait.
11796 * This function will sleep while waiting for iocb completion.
11797 * So, this function should not be called from any context which
11798 * does not allow sleeping. Due to the same reason, this function
11799 * cannot be called with interrupt disabled.
11800 * This function assumes that the iocb completions occur while
11801 * this function sleep. So, this function cannot be called from
11802 * the thread which process iocb completion for this ring.
11803 * This function clears the iocb_flag of the iocb object before
11804 * issuing the iocb and the iocb completion handler sets this
11805 * flag and wakes this thread when the iocb completes.
11806 * The contents of the response iocb will be copied to prspiocbq
11807 * by the completion handler when the command completes.
11808 * This function returns IOCB_SUCCESS when success.
11809 * This function is called with no lock held.
11812 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
11813 uint32_t ring_number,
11814 struct lpfc_iocbq *piocb,
11815 struct lpfc_iocbq *prspiocbq,
11818 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
11819 long timeleft, timeout_req = 0;
11820 int retval = IOCB_SUCCESS;
11822 struct lpfc_iocbq *iocb;
11824 int txcmplq_cnt = 0;
11825 struct lpfc_sli_ring *pring;
11826 unsigned long iflags;
11827 bool iocb_completed = true;
11829 if (phba->sli_rev >= LPFC_SLI_REV4)
11830 pring = lpfc_sli4_calc_ring(phba, piocb);
11832 pring = &phba->sli.sli3_ring[ring_number];
11834 * If the caller has provided a response iocbq buffer, then context2
11835 * is NULL or its an error.
11838 if (piocb->context2)
11840 piocb->context2 = prspiocbq;
11843 piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
11844 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
11845 piocb->context_un.wait_queue = &done_q;
11846 piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
11848 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
11849 if (lpfc_readl(phba->HCregaddr, &creg_val))
11851 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
11852 writel(creg_val, phba->HCregaddr);
11853 readl(phba->HCregaddr); /* flush */
11856 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
11857 SLI_IOCB_RET_IOCB);
11858 if (retval == IOCB_SUCCESS) {
11859 timeout_req = msecs_to_jiffies(timeout * 1000);
11860 timeleft = wait_event_timeout(done_q,
11861 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
11863 spin_lock_irqsave(&phba->hbalock, iflags);
11864 if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
11867 * IOCB timed out. Inform the wake iocb wait
11868 * completion function and set local status
11871 iocb_completed = false;
11872 piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
11874 spin_unlock_irqrestore(&phba->hbalock, iflags);
11875 if (iocb_completed) {
11876 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11877 "0331 IOCB wake signaled\n");
11878 /* Note: we are not indicating if the IOCB has a success
11879 * status or not - that's for the caller to check.
11880 * IOCB_SUCCESS means just that the command was sent and
11881 * completed. Not that it completed successfully.
11883 } else if (timeleft == 0) {
11884 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11885 "0338 IOCB wait timeout error - no "
11886 "wake response Data x%x\n", timeout);
11887 retval = IOCB_TIMEDOUT;
11889 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
11890 "0330 IOCB wake NOT set, "
11892 timeout, (timeleft / jiffies));
11893 retval = IOCB_TIMEDOUT;
11895 } else if (retval == IOCB_BUSY) {
11896 if (phba->cfg_log_verbose & LOG_SLI) {
11897 list_for_each_entry(iocb, &pring->txq, list) {
11900 list_for_each_entry(iocb, &pring->txcmplq, list) {
11903 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11904 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
11905 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
11909 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11910 "0332 IOCB wait issue failed, Data x%x\n",
11912 retval = IOCB_ERROR;
11915 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
11916 if (lpfc_readl(phba->HCregaddr, &creg_val))
11918 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
11919 writel(creg_val, phba->HCregaddr);
11920 readl(phba->HCregaddr); /* flush */
11924 piocb->context2 = NULL;
11926 piocb->context_un.wait_queue = NULL;
11927 piocb->iocb_cmpl = NULL;
11932 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
11933 * @phba: Pointer to HBA context object.
11934 * @pmboxq: Pointer to driver mailbox object.
11935 * @timeout: Timeout in number of seconds.
11937 * This function issues the mailbox to firmware and waits for the
11938 * mailbox command to complete. If the mailbox command is not
11939 * completed within timeout seconds, it returns MBX_TIMEOUT.
11940 * The function waits for the mailbox completion using an
11941 * interruptible wait. If the thread is woken up due to a
11942 * signal, MBX_TIMEOUT error is returned to the caller. Caller
11943 * should not free the mailbox resources, if this function returns
11945 * This function will sleep while waiting for mailbox completion.
11946 * So, this function should not be called from any context which
11947 * does not allow sleeping. Due to the same reason, this function
11948 * cannot be called with interrupt disabled.
11949 * This function assumes that the mailbox completion occurs while
11950 * this function sleep. So, this function cannot be called from
11951 * the worker thread which processes mailbox completion.
11952 * This function is called in the context of HBA management
11954 * This function returns MBX_SUCCESS when successful.
11955 * This function is called with no lock held.
11958 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
11961 struct completion mbox_done;
11963 unsigned long flag;
11965 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
11966 /* setup wake call as IOCB callback */
11967 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
11969 /* setup context3 field to pass wait_queue pointer to wake function */
11970 init_completion(&mbox_done);
11971 pmboxq->context3 = &mbox_done;
11972 /* now issue the command */
11973 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
11974 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
11975 wait_for_completion_timeout(&mbox_done,
11976 msecs_to_jiffies(timeout * 1000));
11978 spin_lock_irqsave(&phba->hbalock, flag);
11979 pmboxq->context3 = NULL;
11981 * if LPFC_MBX_WAKE flag is set the mailbox is completed
11982 * else do not free the resources.
11984 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
11985 retval = MBX_SUCCESS;
11987 retval = MBX_TIMEOUT;
11988 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
11990 spin_unlock_irqrestore(&phba->hbalock, flag);
11996 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
11997 * @phba: Pointer to HBA context.
11999 * This function is called to shutdown the driver's mailbox sub-system.
12000 * It first marks the mailbox sub-system is in a block state to prevent
12001 * the asynchronous mailbox command from issued off the pending mailbox
12002 * command queue. If the mailbox command sub-system shutdown is due to
12003 * HBA error conditions such as EEH or ERATT, this routine shall invoke
12004 * the mailbox sub-system flush routine to forcefully bring down the
12005 * mailbox sub-system. Otherwise, if it is due to normal condition (such
12006 * as with offline or HBA function reset), this routine will wait for the
12007 * outstanding mailbox command to complete before invoking the mailbox
12008 * sub-system flush routine to gracefully bring down mailbox sub-system.
12011 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
12013 struct lpfc_sli *psli = &phba->sli;
12014 unsigned long timeout;
12016 if (mbx_action == LPFC_MBX_NO_WAIT) {
12017 /* delay 100ms for port state */
12019 lpfc_sli_mbox_sys_flush(phba);
12022 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
12024 /* Disable softirqs, including timers from obtaining phba->hbalock */
12025 local_bh_disable();
12027 spin_lock_irq(&phba->hbalock);
12028 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
12030 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
12031 /* Determine how long we might wait for the active mailbox
12032 * command to be gracefully completed by firmware.
12034 if (phba->sli.mbox_active)
12035 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
12036 phba->sli.mbox_active) *
12038 spin_unlock_irq(&phba->hbalock);
12040 /* Enable softirqs again, done with phba->hbalock */
12043 while (phba->sli.mbox_active) {
12044 /* Check active mailbox complete status every 2ms */
12046 if (time_after(jiffies, timeout))
12047 /* Timeout, let the mailbox flush routine to
12048 * forcefully release active mailbox command
12053 spin_unlock_irq(&phba->hbalock);
12055 /* Enable softirqs again, done with phba->hbalock */
12059 lpfc_sli_mbox_sys_flush(phba);
12063 * lpfc_sli_eratt_read - read sli-3 error attention events
12064 * @phba: Pointer to HBA context.
12066 * This function is called to read the SLI3 device error attention registers
12067 * for possible error attention events. The caller must hold the hostlock
12068 * with spin_lock_irq().
12070 * This function returns 1 when there is Error Attention in the Host Attention
12071 * Register and returns 0 otherwise.
12074 lpfc_sli_eratt_read(struct lpfc_hba *phba)
12078 /* Read chip Host Attention (HA) register */
12079 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12082 if (ha_copy & HA_ERATT) {
12083 /* Read host status register to retrieve error event */
12084 if (lpfc_sli_read_hs(phba))
12087 /* Check if there is a deferred error condition is active */
12088 if ((HS_FFER1 & phba->work_hs) &&
12089 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
12090 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
12091 phba->hba_flag |= DEFER_ERATT;
12092 /* Clear all interrupt enable conditions */
12093 writel(0, phba->HCregaddr);
12094 readl(phba->HCregaddr);
12097 /* Set the driver HA work bitmap */
12098 phba->work_ha |= HA_ERATT;
12099 /* Indicate polling handles this ERATT */
12100 phba->hba_flag |= HBA_ERATT_HANDLED;
12106 /* Set the driver HS work bitmap */
12107 phba->work_hs |= UNPLUG_ERR;
12108 /* Set the driver HA work bitmap */
12109 phba->work_ha |= HA_ERATT;
12110 /* Indicate polling handles this ERATT */
12111 phba->hba_flag |= HBA_ERATT_HANDLED;
12116 * lpfc_sli4_eratt_read - read sli-4 error attention events
12117 * @phba: Pointer to HBA context.
12119 * This function is called to read the SLI4 device error attention registers
12120 * for possible error attention events. The caller must hold the hostlock
12121 * with spin_lock_irq().
12123 * This function returns 1 when there is Error Attention in the Host Attention
12124 * Register and returns 0 otherwise.
12127 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
12129 uint32_t uerr_sta_hi, uerr_sta_lo;
12130 uint32_t if_type, portsmphr;
12131 struct lpfc_register portstat_reg;
12134 * For now, use the SLI4 device internal unrecoverable error
12135 * registers for error attention. This can be changed later.
12137 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
12139 case LPFC_SLI_INTF_IF_TYPE_0:
12140 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
12142 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
12144 phba->work_hs |= UNPLUG_ERR;
12145 phba->work_ha |= HA_ERATT;
12146 phba->hba_flag |= HBA_ERATT_HANDLED;
12149 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
12150 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
12151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12152 "1423 HBA Unrecoverable error: "
12153 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
12154 "ue_mask_lo_reg=0x%x, "
12155 "ue_mask_hi_reg=0x%x\n",
12156 uerr_sta_lo, uerr_sta_hi,
12157 phba->sli4_hba.ue_mask_lo,
12158 phba->sli4_hba.ue_mask_hi);
12159 phba->work_status[0] = uerr_sta_lo;
12160 phba->work_status[1] = uerr_sta_hi;
12161 phba->work_ha |= HA_ERATT;
12162 phba->hba_flag |= HBA_ERATT_HANDLED;
12166 case LPFC_SLI_INTF_IF_TYPE_2:
12167 case LPFC_SLI_INTF_IF_TYPE_6:
12168 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
12169 &portstat_reg.word0) ||
12170 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
12172 phba->work_hs |= UNPLUG_ERR;
12173 phba->work_ha |= HA_ERATT;
12174 phba->hba_flag |= HBA_ERATT_HANDLED;
12177 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
12178 phba->work_status[0] =
12179 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
12180 phba->work_status[1] =
12181 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
12182 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12183 "2885 Port Status Event: "
12184 "port status reg 0x%x, "
12185 "port smphr reg 0x%x, "
12186 "error 1=0x%x, error 2=0x%x\n",
12187 portstat_reg.word0,
12189 phba->work_status[0],
12190 phba->work_status[1]);
12191 phba->work_ha |= HA_ERATT;
12192 phba->hba_flag |= HBA_ERATT_HANDLED;
12196 case LPFC_SLI_INTF_IF_TYPE_1:
12198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12199 "2886 HBA Error Attention on unsupported "
12200 "if type %d.", if_type);
12208 * lpfc_sli_check_eratt - check error attention events
12209 * @phba: Pointer to HBA context.
12211 * This function is called from timer soft interrupt context to check HBA's
12212 * error attention register bit for error attention events.
12214 * This function returns 1 when there is Error Attention in the Host Attention
12215 * Register and returns 0 otherwise.
12218 lpfc_sli_check_eratt(struct lpfc_hba *phba)
12222 /* If somebody is waiting to handle an eratt, don't process it
12223 * here. The brdkill function will do this.
12225 if (phba->link_flag & LS_IGNORE_ERATT)
12228 /* Check if interrupt handler handles this ERATT */
12229 spin_lock_irq(&phba->hbalock);
12230 if (phba->hba_flag & HBA_ERATT_HANDLED) {
12231 /* Interrupt handler has handled ERATT */
12232 spin_unlock_irq(&phba->hbalock);
12237 * If there is deferred error attention, do not check for error
12240 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12241 spin_unlock_irq(&phba->hbalock);
12245 /* If PCI channel is offline, don't process it */
12246 if (unlikely(pci_channel_offline(phba->pcidev))) {
12247 spin_unlock_irq(&phba->hbalock);
12251 switch (phba->sli_rev) {
12252 case LPFC_SLI_REV2:
12253 case LPFC_SLI_REV3:
12254 /* Read chip Host Attention (HA) register */
12255 ha_copy = lpfc_sli_eratt_read(phba);
12257 case LPFC_SLI_REV4:
12258 /* Read device Uncoverable Error (UERR) registers */
12259 ha_copy = lpfc_sli4_eratt_read(phba);
12262 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12263 "0299 Invalid SLI revision (%d)\n",
12268 spin_unlock_irq(&phba->hbalock);
12274 * lpfc_intr_state_check - Check device state for interrupt handling
12275 * @phba: Pointer to HBA context.
12277 * This inline routine checks whether a device or its PCI slot is in a state
12278 * that the interrupt should be handled.
12280 * This function returns 0 if the device or the PCI slot is in a state that
12281 * interrupt should be handled, otherwise -EIO.
12284 lpfc_intr_state_check(struct lpfc_hba *phba)
12286 /* If the pci channel is offline, ignore all the interrupts */
12287 if (unlikely(pci_channel_offline(phba->pcidev)))
12290 /* Update device level interrupt statistics */
12291 phba->sli.slistat.sli_intr++;
12293 /* Ignore all interrupts during initialization. */
12294 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
12301 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
12302 * @irq: Interrupt number.
12303 * @dev_id: The device context pointer.
12305 * This function is directly called from the PCI layer as an interrupt
12306 * service routine when device with SLI-3 interface spec is enabled with
12307 * MSI-X multi-message interrupt mode and there are slow-path events in
12308 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
12309 * interrupt mode, this function is called as part of the device-level
12310 * interrupt handler. When the PCI slot is in error recovery or the HBA
12311 * is undergoing initialization, the interrupt handler will not process
12312 * the interrupt. The link attention and ELS ring attention events are
12313 * handled by the worker thread. The interrupt handler signals the worker
12314 * thread and returns for these events. This function is called without
12315 * any lock held. It gets the hbalock to access and update SLI data
12318 * This function returns IRQ_HANDLED when interrupt is handled else it
12319 * returns IRQ_NONE.
12322 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
12324 struct lpfc_hba *phba;
12325 uint32_t ha_copy, hc_copy;
12326 uint32_t work_ha_copy;
12327 unsigned long status;
12328 unsigned long iflag;
12331 MAILBOX_t *mbox, *pmbox;
12332 struct lpfc_vport *vport;
12333 struct lpfc_nodelist *ndlp;
12334 struct lpfc_dmabuf *mp;
12339 * Get the driver's phba structure from the dev_id and
12340 * assume the HBA is not interrupting.
12342 phba = (struct lpfc_hba *)dev_id;
12344 if (unlikely(!phba))
12348 * Stuff needs to be attented to when this function is invoked as an
12349 * individual interrupt handler in MSI-X multi-message interrupt mode
12351 if (phba->intr_type == MSIX) {
12352 /* Check device state for handling interrupt */
12353 if (lpfc_intr_state_check(phba))
12355 /* Need to read HA REG for slow-path events */
12356 spin_lock_irqsave(&phba->hbalock, iflag);
12357 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12359 /* If somebody is waiting to handle an eratt don't process it
12360 * here. The brdkill function will do this.
12362 if (phba->link_flag & LS_IGNORE_ERATT)
12363 ha_copy &= ~HA_ERATT;
12364 /* Check the need for handling ERATT in interrupt handler */
12365 if (ha_copy & HA_ERATT) {
12366 if (phba->hba_flag & HBA_ERATT_HANDLED)
12367 /* ERATT polling has handled ERATT */
12368 ha_copy &= ~HA_ERATT;
12370 /* Indicate interrupt handler handles ERATT */
12371 phba->hba_flag |= HBA_ERATT_HANDLED;
12375 * If there is deferred error attention, do not check for any
12378 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12379 spin_unlock_irqrestore(&phba->hbalock, iflag);
12383 /* Clear up only attention source related to slow-path */
12384 if (lpfc_readl(phba->HCregaddr, &hc_copy))
12387 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
12388 HC_LAINT_ENA | HC_ERINT_ENA),
12390 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
12392 writel(hc_copy, phba->HCregaddr);
12393 readl(phba->HAregaddr); /* flush */
12394 spin_unlock_irqrestore(&phba->hbalock, iflag);
12396 ha_copy = phba->ha_copy;
12398 work_ha_copy = ha_copy & phba->work_ha_mask;
12400 if (work_ha_copy) {
12401 if (work_ha_copy & HA_LATT) {
12402 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
12404 * Turn off Link Attention interrupts
12405 * until CLEAR_LA done
12407 spin_lock_irqsave(&phba->hbalock, iflag);
12408 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
12409 if (lpfc_readl(phba->HCregaddr, &control))
12411 control &= ~HC_LAINT_ENA;
12412 writel(control, phba->HCregaddr);
12413 readl(phba->HCregaddr); /* flush */
12414 spin_unlock_irqrestore(&phba->hbalock, iflag);
12417 work_ha_copy &= ~HA_LATT;
12420 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
12422 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
12423 * the only slow ring.
12425 status = (work_ha_copy &
12426 (HA_RXMASK << (4*LPFC_ELS_RING)));
12427 status >>= (4*LPFC_ELS_RING);
12428 if (status & HA_RXMASK) {
12429 spin_lock_irqsave(&phba->hbalock, iflag);
12430 if (lpfc_readl(phba->HCregaddr, &control))
12433 lpfc_debugfs_slow_ring_trc(phba,
12434 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
12436 (uint32_t)phba->sli.slistat.sli_intr);
12438 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
12439 lpfc_debugfs_slow_ring_trc(phba,
12440 "ISR Disable ring:"
12441 "pwork:x%x hawork:x%x wait:x%x",
12442 phba->work_ha, work_ha_copy,
12443 (uint32_t)((unsigned long)
12444 &phba->work_waitq));
12447 ~(HC_R0INT_ENA << LPFC_ELS_RING);
12448 writel(control, phba->HCregaddr);
12449 readl(phba->HCregaddr); /* flush */
12452 lpfc_debugfs_slow_ring_trc(phba,
12453 "ISR slow ring: pwork:"
12454 "x%x hawork:x%x wait:x%x",
12455 phba->work_ha, work_ha_copy,
12456 (uint32_t)((unsigned long)
12457 &phba->work_waitq));
12459 spin_unlock_irqrestore(&phba->hbalock, iflag);
12462 spin_lock_irqsave(&phba->hbalock, iflag);
12463 if (work_ha_copy & HA_ERATT) {
12464 if (lpfc_sli_read_hs(phba))
12467 * Check if there is a deferred error condition
12470 if ((HS_FFER1 & phba->work_hs) &&
12471 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
12472 HS_FFER6 | HS_FFER7 | HS_FFER8) &
12474 phba->hba_flag |= DEFER_ERATT;
12475 /* Clear all interrupt enable conditions */
12476 writel(0, phba->HCregaddr);
12477 readl(phba->HCregaddr);
12481 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
12482 pmb = phba->sli.mbox_active;
12483 pmbox = &pmb->u.mb;
12485 vport = pmb->vport;
12487 /* First check out the status word */
12488 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
12489 if (pmbox->mbxOwner != OWN_HOST) {
12490 spin_unlock_irqrestore(&phba->hbalock, iflag);
12492 * Stray Mailbox Interrupt, mbxCommand <cmd>
12493 * mbxStatus <status>
12495 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
12497 "(%d):0304 Stray Mailbox "
12498 "Interrupt mbxCommand x%x "
12500 (vport ? vport->vpi : 0),
12503 /* clear mailbox attention bit */
12504 work_ha_copy &= ~HA_MBATT;
12506 phba->sli.mbox_active = NULL;
12507 spin_unlock_irqrestore(&phba->hbalock, iflag);
12508 phba->last_completion_time = jiffies;
12509 del_timer(&phba->sli.mbox_tmo);
12510 if (pmb->mbox_cmpl) {
12511 lpfc_sli_pcimem_bcopy(mbox, pmbox,
12513 if (pmb->out_ext_byte_len &&
12515 lpfc_sli_pcimem_bcopy(
12518 pmb->out_ext_byte_len);
12520 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
12521 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
12523 lpfc_debugfs_disc_trc(vport,
12524 LPFC_DISC_TRC_MBOX_VPORT,
12525 "MBOX dflt rpi: : "
12526 "status:x%x rpi:x%x",
12527 (uint32_t)pmbox->mbxStatus,
12528 pmbox->un.varWords[0], 0);
12530 if (!pmbox->mbxStatus) {
12531 mp = (struct lpfc_dmabuf *)
12533 ndlp = (struct lpfc_nodelist *)
12536 /* Reg_LOGIN of dflt RPI was
12537 * successful. new lets get
12538 * rid of the RPI using the
12539 * same mbox buffer.
12541 lpfc_unreg_login(phba,
12543 pmbox->un.varWords[0],
12546 lpfc_mbx_cmpl_dflt_rpi;
12548 pmb->ctx_ndlp = ndlp;
12549 pmb->vport = vport;
12550 rc = lpfc_sli_issue_mbox(phba,
12553 if (rc != MBX_BUSY)
12554 lpfc_printf_log(phba,
12556 LOG_MBOX | LOG_SLI,
12557 "0350 rc should have"
12558 "been MBX_BUSY\n");
12559 if (rc != MBX_NOT_FINISHED)
12560 goto send_current_mbox;
12564 &phba->pport->work_port_lock,
12566 phba->pport->work_port_events &=
12568 spin_unlock_irqrestore(
12569 &phba->pport->work_port_lock,
12571 lpfc_mbox_cmpl_put(phba, pmb);
12574 spin_unlock_irqrestore(&phba->hbalock, iflag);
12576 if ((work_ha_copy & HA_MBATT) &&
12577 (phba->sli.mbox_active == NULL)) {
12579 /* Process next mailbox command if there is one */
12581 rc = lpfc_sli_issue_mbox(phba, NULL,
12583 } while (rc == MBX_NOT_FINISHED);
12584 if (rc != MBX_SUCCESS)
12585 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
12586 LOG_SLI, "0349 rc should be "
12590 spin_lock_irqsave(&phba->hbalock, iflag);
12591 phba->work_ha |= work_ha_copy;
12592 spin_unlock_irqrestore(&phba->hbalock, iflag);
12593 lpfc_worker_wake_up(phba);
12595 return IRQ_HANDLED;
12597 spin_unlock_irqrestore(&phba->hbalock, iflag);
12598 return IRQ_HANDLED;
12600 } /* lpfc_sli_sp_intr_handler */
12603 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
12604 * @irq: Interrupt number.
12605 * @dev_id: The device context pointer.
12607 * This function is directly called from the PCI layer as an interrupt
12608 * service routine when device with SLI-3 interface spec is enabled with
12609 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12610 * ring event in the HBA. However, when the device is enabled with either
12611 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12612 * device-level interrupt handler. When the PCI slot is in error recovery
12613 * or the HBA is undergoing initialization, the interrupt handler will not
12614 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12615 * the intrrupt context. This function is called without any lock held.
12616 * It gets the hbalock to access and update SLI data structures.
12618 * This function returns IRQ_HANDLED when interrupt is handled else it
12619 * returns IRQ_NONE.
12622 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
12624 struct lpfc_hba *phba;
12626 unsigned long status;
12627 unsigned long iflag;
12628 struct lpfc_sli_ring *pring;
12630 /* Get the driver's phba structure from the dev_id and
12631 * assume the HBA is not interrupting.
12633 phba = (struct lpfc_hba *) dev_id;
12635 if (unlikely(!phba))
12639 * Stuff needs to be attented to when this function is invoked as an
12640 * individual interrupt handler in MSI-X multi-message interrupt mode
12642 if (phba->intr_type == MSIX) {
12643 /* Check device state for handling interrupt */
12644 if (lpfc_intr_state_check(phba))
12646 /* Need to read HA REG for FCP ring and other ring events */
12647 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12648 return IRQ_HANDLED;
12649 /* Clear up only attention source related to fast-path */
12650 spin_lock_irqsave(&phba->hbalock, iflag);
12652 * If there is deferred error attention, do not check for
12655 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12656 spin_unlock_irqrestore(&phba->hbalock, iflag);
12659 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
12661 readl(phba->HAregaddr); /* flush */
12662 spin_unlock_irqrestore(&phba->hbalock, iflag);
12664 ha_copy = phba->ha_copy;
12667 * Process all events on FCP ring. Take the optimized path for FCP IO.
12669 ha_copy &= ~(phba->work_ha_mask);
12671 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
12672 status >>= (4*LPFC_FCP_RING);
12673 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
12674 if (status & HA_RXMASK)
12675 lpfc_sli_handle_fast_ring_event(phba, pring, status);
12677 if (phba->cfg_multi_ring_support == 2) {
12679 * Process all events on extra ring. Take the optimized path
12680 * for extra ring IO.
12682 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
12683 status >>= (4*LPFC_EXTRA_RING);
12684 if (status & HA_RXMASK) {
12685 lpfc_sli_handle_fast_ring_event(phba,
12686 &phba->sli.sli3_ring[LPFC_EXTRA_RING],
12690 return IRQ_HANDLED;
12691 } /* lpfc_sli_fp_intr_handler */
12694 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
12695 * @irq: Interrupt number.
12696 * @dev_id: The device context pointer.
12698 * This function is the HBA device-level interrupt handler to device with
12699 * SLI-3 interface spec, called from the PCI layer when either MSI or
12700 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
12701 * requires driver attention. This function invokes the slow-path interrupt
12702 * attention handling function and fast-path interrupt attention handling
12703 * function in turn to process the relevant HBA attention events. This
12704 * function is called without any lock held. It gets the hbalock to access
12705 * and update SLI data structures.
12707 * This function returns IRQ_HANDLED when interrupt is handled, else it
12708 * returns IRQ_NONE.
12711 lpfc_sli_intr_handler(int irq, void *dev_id)
12713 struct lpfc_hba *phba;
12714 irqreturn_t sp_irq_rc, fp_irq_rc;
12715 unsigned long status1, status2;
12719 * Get the driver's phba structure from the dev_id and
12720 * assume the HBA is not interrupting.
12722 phba = (struct lpfc_hba *) dev_id;
12724 if (unlikely(!phba))
12727 /* Check device state for handling interrupt */
12728 if (lpfc_intr_state_check(phba))
12731 spin_lock(&phba->hbalock);
12732 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
12733 spin_unlock(&phba->hbalock);
12734 return IRQ_HANDLED;
12737 if (unlikely(!phba->ha_copy)) {
12738 spin_unlock(&phba->hbalock);
12740 } else if (phba->ha_copy & HA_ERATT) {
12741 if (phba->hba_flag & HBA_ERATT_HANDLED)
12742 /* ERATT polling has handled ERATT */
12743 phba->ha_copy &= ~HA_ERATT;
12745 /* Indicate interrupt handler handles ERATT */
12746 phba->hba_flag |= HBA_ERATT_HANDLED;
12750 * If there is deferred error attention, do not check for any interrupt.
12752 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12753 spin_unlock(&phba->hbalock);
12757 /* Clear attention sources except link and error attentions */
12758 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
12759 spin_unlock(&phba->hbalock);
12760 return IRQ_HANDLED;
12762 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
12763 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
12765 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
12766 writel(hc_copy, phba->HCregaddr);
12767 readl(phba->HAregaddr); /* flush */
12768 spin_unlock(&phba->hbalock);
12771 * Invokes slow-path host attention interrupt handling as appropriate.
12774 /* status of events with mailbox and link attention */
12775 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
12777 /* status of events with ELS ring */
12778 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
12779 status2 >>= (4*LPFC_ELS_RING);
12781 if (status1 || (status2 & HA_RXMASK))
12782 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
12784 sp_irq_rc = IRQ_NONE;
12787 * Invoke fast-path host attention interrupt handling as appropriate.
12790 /* status of events with FCP ring */
12791 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
12792 status1 >>= (4*LPFC_FCP_RING);
12794 /* status of events with extra ring */
12795 if (phba->cfg_multi_ring_support == 2) {
12796 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
12797 status2 >>= (4*LPFC_EXTRA_RING);
12801 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
12802 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
12804 fp_irq_rc = IRQ_NONE;
12806 /* Return device-level interrupt handling status */
12807 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
12808 } /* lpfc_sli_intr_handler */
12811 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12812 * @phba: pointer to lpfc hba data structure.
12814 * This routine is invoked by the worker thread to process all the pending
12815 * SLI4 els abort xri events.
12817 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
12819 struct lpfc_cq_event *cq_event;
12821 /* First, declare the els xri abort event has been handled */
12822 spin_lock_irq(&phba->hbalock);
12823 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
12824 spin_unlock_irq(&phba->hbalock);
12825 /* Now, handle all the els xri abort events */
12826 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
12827 /* Get the first event from the head of the event queue */
12828 spin_lock_irq(&phba->hbalock);
12829 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
12830 cq_event, struct lpfc_cq_event, list);
12831 spin_unlock_irq(&phba->hbalock);
12832 /* Notify aborted XRI for ELS work queue */
12833 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
12834 /* Free the event processed back to the free pool */
12835 lpfc_sli4_cq_event_release(phba, cq_event);
12840 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
12841 * @phba: pointer to lpfc hba data structure
12842 * @pIocbIn: pointer to the rspiocbq
12843 * @pIocbOut: pointer to the cmdiocbq
12844 * @wcqe: pointer to the complete wcqe
12846 * This routine transfers the fields of a command iocbq to a response iocbq
12847 * by copying all the IOCB fields from command iocbq and transferring the
12848 * completion status information from the complete wcqe.
12851 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
12852 struct lpfc_iocbq *pIocbIn,
12853 struct lpfc_iocbq *pIocbOut,
12854 struct lpfc_wcqe_complete *wcqe)
12857 unsigned long iflags;
12858 uint32_t status, max_response;
12859 struct lpfc_dmabuf *dmabuf;
12860 struct ulp_bde64 *bpl, bde;
12861 size_t offset = offsetof(struct lpfc_iocbq, iocb);
12863 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
12864 sizeof(struct lpfc_iocbq) - offset);
12865 /* Map WCQE parameters into irspiocb parameters */
12866 status = bf_get(lpfc_wcqe_c_status, wcqe);
12867 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
12868 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
12869 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
12870 pIocbIn->iocb.un.fcpi.fcpi_parm =
12871 pIocbOut->iocb.un.fcpi.fcpi_parm -
12872 wcqe->total_data_placed;
12874 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
12876 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
12877 switch (pIocbOut->iocb.ulpCommand) {
12878 case CMD_ELS_REQUEST64_CR:
12879 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
12880 bpl = (struct ulp_bde64 *)dmabuf->virt;
12881 bde.tus.w = le32_to_cpu(bpl[1].tus.w);
12882 max_response = bde.tus.f.bdeSize;
12884 case CMD_GEN_REQUEST64_CR:
12886 if (!pIocbOut->context3)
12888 numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
12889 sizeof(struct ulp_bde64);
12890 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
12891 bpl = (struct ulp_bde64 *)dmabuf->virt;
12892 for (i = 0; i < numBdes; i++) {
12893 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
12894 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
12895 max_response += bde.tus.f.bdeSize;
12899 max_response = wcqe->total_data_placed;
12902 if (max_response < wcqe->total_data_placed)
12903 pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
12905 pIocbIn->iocb.un.genreq64.bdl.bdeSize =
12906 wcqe->total_data_placed;
12909 /* Convert BG errors for completion status */
12910 if (status == CQE_STATUS_DI_ERROR) {
12911 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
12913 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
12914 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
12916 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
12918 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
12919 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
12920 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12921 BGS_GUARD_ERR_MASK;
12922 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
12923 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12924 BGS_APPTAG_ERR_MASK;
12925 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
12926 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12927 BGS_REFTAG_ERR_MASK;
12929 /* Check to see if there was any good data before the error */
12930 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
12931 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12932 BGS_HI_WATER_MARK_PRESENT_MASK;
12933 pIocbIn->iocb.unsli3.sli3_bg.bghm =
12934 wcqe->total_data_placed;
12938 * Set ALL the error bits to indicate we don't know what
12939 * type of error it is.
12941 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
12942 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
12943 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
12944 BGS_GUARD_ERR_MASK);
12947 /* Pick up HBA exchange busy condition */
12948 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
12949 spin_lock_irqsave(&phba->hbalock, iflags);
12950 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
12951 spin_unlock_irqrestore(&phba->hbalock, iflags);
12956 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
12957 * @phba: Pointer to HBA context object.
12958 * @wcqe: Pointer to work-queue completion queue entry.
12960 * This routine handles an ELS work-queue completion event and construct
12961 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
12962 * discovery engine to handle.
12964 * Return: Pointer to the receive IOCBQ, NULL otherwise.
12966 static struct lpfc_iocbq *
12967 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
12968 struct lpfc_iocbq *irspiocbq)
12970 struct lpfc_sli_ring *pring;
12971 struct lpfc_iocbq *cmdiocbq;
12972 struct lpfc_wcqe_complete *wcqe;
12973 unsigned long iflags;
12975 pring = lpfc_phba_elsring(phba);
12976 if (unlikely(!pring))
12979 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
12980 pring->stats.iocb_event++;
12981 /* Look up the ELS command IOCB and create pseudo response IOCB */
12982 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
12983 bf_get(lpfc_wcqe_c_request_tag, wcqe));
12984 if (unlikely(!cmdiocbq)) {
12985 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
12986 "0386 ELS complete with no corresponding "
12987 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
12988 wcqe->word0, wcqe->total_data_placed,
12989 wcqe->parameter, wcqe->word3);
12990 lpfc_sli_release_iocbq(phba, irspiocbq);
12994 spin_lock_irqsave(&pring->ring_lock, iflags);
12995 /* Put the iocb back on the txcmplq */
12996 lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
12997 spin_unlock_irqrestore(&pring->ring_lock, iflags);
12999 /* Fake the irspiocbq and copy necessary response information */
13000 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
13005 inline struct lpfc_cq_event *
13006 lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
13008 struct lpfc_cq_event *cq_event;
13010 /* Allocate a new internal CQ_EVENT entry */
13011 cq_event = lpfc_sli4_cq_event_alloc(phba);
13013 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13014 "0602 Failed to alloc CQ_EVENT entry\n");
13018 /* Move the CQE into the event */
13019 memcpy(&cq_event->cqe, entry, size);
13024 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
13025 * @phba: Pointer to HBA context object.
13026 * @cqe: Pointer to mailbox completion queue entry.
13028 * This routine process a mailbox completion queue entry with asynchrous
13031 * Return: true if work posted to worker thread, otherwise false.
13034 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
13036 struct lpfc_cq_event *cq_event;
13037 unsigned long iflags;
13039 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13040 "0392 Async Event: word0:x%x, word1:x%x, "
13041 "word2:x%x, word3:x%x\n", mcqe->word0,
13042 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
13044 cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
13047 spin_lock_irqsave(&phba->hbalock, iflags);
13048 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
13049 /* Set the async event flag */
13050 phba->hba_flag |= ASYNC_EVENT;
13051 spin_unlock_irqrestore(&phba->hbalock, iflags);
13057 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
13058 * @phba: Pointer to HBA context object.
13059 * @cqe: Pointer to mailbox completion queue entry.
13061 * This routine process a mailbox completion queue entry with mailbox
13062 * completion event.
13064 * Return: true if work posted to worker thread, otherwise false.
13067 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
13069 uint32_t mcqe_status;
13070 MAILBOX_t *mbox, *pmbox;
13071 struct lpfc_mqe *mqe;
13072 struct lpfc_vport *vport;
13073 struct lpfc_nodelist *ndlp;
13074 struct lpfc_dmabuf *mp;
13075 unsigned long iflags;
13077 bool workposted = false;
13080 /* If not a mailbox complete MCQE, out by checking mailbox consume */
13081 if (!bf_get(lpfc_trailer_completed, mcqe))
13082 goto out_no_mqe_complete;
13084 /* Get the reference to the active mbox command */
13085 spin_lock_irqsave(&phba->hbalock, iflags);
13086 pmb = phba->sli.mbox_active;
13087 if (unlikely(!pmb)) {
13088 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13089 "1832 No pending MBOX command to handle\n");
13090 spin_unlock_irqrestore(&phba->hbalock, iflags);
13091 goto out_no_mqe_complete;
13093 spin_unlock_irqrestore(&phba->hbalock, iflags);
13095 pmbox = (MAILBOX_t *)&pmb->u.mqe;
13097 vport = pmb->vport;
13099 /* Reset heartbeat timer */
13100 phba->last_completion_time = jiffies;
13101 del_timer(&phba->sli.mbox_tmo);
13103 /* Move mbox data to caller's mailbox region, do endian swapping */
13104 if (pmb->mbox_cmpl && mbox)
13105 lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
13108 * For mcqe errors, conditionally move a modified error code to
13109 * the mbox so that the error will not be missed.
13111 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
13112 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
13113 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
13114 bf_set(lpfc_mqe_status, mqe,
13115 (LPFC_MBX_ERROR_RANGE | mcqe_status));
13117 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
13118 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
13119 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
13120 "MBOX dflt rpi: status:x%x rpi:x%x",
13122 pmbox->un.varWords[0], 0);
13123 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
13124 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
13125 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
13126 /* Reg_LOGIN of dflt RPI was successful. Now lets get
13127 * RID of the PPI using the same mbox buffer.
13129 lpfc_unreg_login(phba, vport->vpi,
13130 pmbox->un.varWords[0], pmb);
13131 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
13133 pmb->ctx_ndlp = ndlp;
13134 pmb->vport = vport;
13135 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
13136 if (rc != MBX_BUSY)
13137 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
13138 LOG_SLI, "0385 rc should "
13139 "have been MBX_BUSY\n");
13140 if (rc != MBX_NOT_FINISHED)
13141 goto send_current_mbox;
13144 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
13145 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
13146 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
13148 /* There is mailbox completion work to do */
13149 spin_lock_irqsave(&phba->hbalock, iflags);
13150 __lpfc_mbox_cmpl_put(phba, pmb);
13151 phba->work_ha |= HA_MBATT;
13152 spin_unlock_irqrestore(&phba->hbalock, iflags);
13156 spin_lock_irqsave(&phba->hbalock, iflags);
13157 /* Release the mailbox command posting token */
13158 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13159 /* Setting active mailbox pointer need to be in sync to flag clear */
13160 phba->sli.mbox_active = NULL;
13161 if (bf_get(lpfc_trailer_consumed, mcqe))
13162 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13163 spin_unlock_irqrestore(&phba->hbalock, iflags);
13164 /* Wake up worker thread to post the next pending mailbox command */
13165 lpfc_worker_wake_up(phba);
13168 out_no_mqe_complete:
13169 spin_lock_irqsave(&phba->hbalock, iflags);
13170 if (bf_get(lpfc_trailer_consumed, mcqe))
13171 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13172 spin_unlock_irqrestore(&phba->hbalock, iflags);
13177 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
13178 * @phba: Pointer to HBA context object.
13179 * @cqe: Pointer to mailbox completion queue entry.
13181 * This routine process a mailbox completion queue entry, it invokes the
13182 * proper mailbox complete handling or asynchrous event handling routine
13183 * according to the MCQE's async bit.
13185 * Return: true if work posted to worker thread, otherwise false.
13188 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13189 struct lpfc_cqe *cqe)
13191 struct lpfc_mcqe mcqe;
13196 /* Copy the mailbox MCQE and convert endian order as needed */
13197 lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
13199 /* Invoke the proper event handling routine */
13200 if (!bf_get(lpfc_trailer_async, &mcqe))
13201 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
13203 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
13208 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
13209 * @phba: Pointer to HBA context object.
13210 * @cq: Pointer to associated CQ
13211 * @wcqe: Pointer to work-queue completion queue entry.
13213 * This routine handles an ELS work-queue completion event.
13215 * Return: true if work posted to worker thread, otherwise false.
13218 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13219 struct lpfc_wcqe_complete *wcqe)
13221 struct lpfc_iocbq *irspiocbq;
13222 unsigned long iflags;
13223 struct lpfc_sli_ring *pring = cq->pring;
13225 int txcmplq_cnt = 0;
13226 int fcp_txcmplq_cnt = 0;
13228 /* Check for response status */
13229 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
13230 /* Log the error status */
13231 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13232 "0357 ELS CQE error: status=x%x: "
13233 "CQE: %08x %08x %08x %08x\n",
13234 bf_get(lpfc_wcqe_c_status, wcqe),
13235 wcqe->word0, wcqe->total_data_placed,
13236 wcqe->parameter, wcqe->word3);
13239 /* Get an irspiocbq for later ELS response processing use */
13240 irspiocbq = lpfc_sli_get_iocbq(phba);
13242 if (!list_empty(&pring->txq))
13244 if (!list_empty(&pring->txcmplq))
13246 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13247 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
13248 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
13249 txq_cnt, phba->iocb_cnt,
13255 /* Save off the slow-path queue event for work thread to process */
13256 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
13257 spin_lock_irqsave(&phba->hbalock, iflags);
13258 list_add_tail(&irspiocbq->cq_event.list,
13259 &phba->sli4_hba.sp_queue_event);
13260 phba->hba_flag |= HBA_SP_QUEUE_EVT;
13261 spin_unlock_irqrestore(&phba->hbalock, iflags);
13267 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
13268 * @phba: Pointer to HBA context object.
13269 * @wcqe: Pointer to work-queue completion queue entry.
13271 * This routine handles slow-path WQ entry consumed event by invoking the
13272 * proper WQ release routine to the slow-path WQ.
13275 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
13276 struct lpfc_wcqe_release *wcqe)
13278 /* sanity check on queue memory */
13279 if (unlikely(!phba->sli4_hba.els_wq))
13281 /* Check for the slow-path ELS work queue */
13282 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
13283 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
13284 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
13286 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13287 "2579 Slow-path wqe consume event carries "
13288 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
13289 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
13290 phba->sli4_hba.els_wq->queue_id);
13294 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
13295 * @phba: Pointer to HBA context object.
13296 * @cq: Pointer to a WQ completion queue.
13297 * @wcqe: Pointer to work-queue completion queue entry.
13299 * This routine handles an XRI abort event.
13301 * Return: true if work posted to worker thread, otherwise false.
13304 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
13305 struct lpfc_queue *cq,
13306 struct sli4_wcqe_xri_aborted *wcqe)
13308 bool workposted = false;
13309 struct lpfc_cq_event *cq_event;
13310 unsigned long iflags;
13312 switch (cq->subtype) {
13314 lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
13315 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13316 /* Notify aborted XRI for NVME work queue */
13317 if (phba->nvmet_support)
13318 lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
13320 workposted = false;
13322 case LPFC_NVME_LS: /* NVME LS uses ELS resources */
13324 cq_event = lpfc_cq_event_setup(
13325 phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
13328 cq_event->hdwq = cq->hdwq;
13329 spin_lock_irqsave(&phba->hbalock, iflags);
13330 list_add_tail(&cq_event->list,
13331 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
13332 /* Set the els xri abort event flag */
13333 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
13334 spin_unlock_irqrestore(&phba->hbalock, iflags);
13338 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13339 "0603 Invalid CQ subtype %d: "
13340 "%08x %08x %08x %08x\n",
13341 cq->subtype, wcqe->word0, wcqe->parameter,
13342 wcqe->word2, wcqe->word3);
13343 workposted = false;
13349 #define FC_RCTL_MDS_DIAGS 0xF4
13352 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
13353 * @phba: Pointer to HBA context object.
13354 * @rcqe: Pointer to receive-queue completion queue entry.
13356 * This routine process a receive-queue completion queue entry.
13358 * Return: true if work posted to worker thread, otherwise false.
13361 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
13363 bool workposted = false;
13364 struct fc_frame_header *fc_hdr;
13365 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
13366 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
13367 struct lpfc_nvmet_tgtport *tgtp;
13368 struct hbq_dmabuf *dma_buf;
13369 uint32_t status, rq_id;
13370 unsigned long iflags;
13372 /* sanity check on queue memory */
13373 if (unlikely(!hrq) || unlikely(!drq))
13376 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
13377 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
13379 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
13380 if (rq_id != hrq->queue_id)
13383 status = bf_get(lpfc_rcqe_status, rcqe);
13385 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
13386 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13387 "2537 Receive Frame Truncated!!\n");
13389 case FC_STATUS_RQ_SUCCESS:
13390 spin_lock_irqsave(&phba->hbalock, iflags);
13391 lpfc_sli4_rq_release(hrq, drq);
13392 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
13394 hrq->RQ_no_buf_found++;
13395 spin_unlock_irqrestore(&phba->hbalock, iflags);
13399 hrq->RQ_buf_posted--;
13400 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
13402 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
13404 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
13405 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
13406 spin_unlock_irqrestore(&phba->hbalock, iflags);
13407 /* Handle MDS Loopback frames */
13408 lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf);
13412 /* save off the frame for the work thread to process */
13413 list_add_tail(&dma_buf->cq_event.list,
13414 &phba->sli4_hba.sp_queue_event);
13415 /* Frame received */
13416 phba->hba_flag |= HBA_SP_QUEUE_EVT;
13417 spin_unlock_irqrestore(&phba->hbalock, iflags);
13420 case FC_STATUS_INSUFF_BUF_FRM_DISC:
13421 if (phba->nvmet_support) {
13422 tgtp = phba->targetport->private;
13423 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME,
13424 "6402 RQE Error x%x, posted %d err_cnt "
13426 status, hrq->RQ_buf_posted,
13427 hrq->RQ_no_posted_buf,
13428 atomic_read(&tgtp->rcv_fcp_cmd_in),
13429 atomic_read(&tgtp->rcv_fcp_cmd_out),
13430 atomic_read(&tgtp->xmt_fcp_release));
13434 case FC_STATUS_INSUFF_BUF_NEED_BUF:
13435 hrq->RQ_no_posted_buf++;
13436 /* Post more buffers if possible */
13437 spin_lock_irqsave(&phba->hbalock, iflags);
13438 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
13439 spin_unlock_irqrestore(&phba->hbalock, iflags);
13448 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
13449 * @phba: Pointer to HBA context object.
13450 * @cq: Pointer to the completion queue.
13451 * @cqe: Pointer to a completion queue entry.
13453 * This routine process a slow-path work-queue or receive queue completion queue
13456 * Return: true if work posted to worker thread, otherwise false.
13459 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13460 struct lpfc_cqe *cqe)
13462 struct lpfc_cqe cqevt;
13463 bool workposted = false;
13465 /* Copy the work queue CQE and convert endian order if needed */
13466 lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
13468 /* Check and process for different type of WCQE and dispatch */
13469 switch (bf_get(lpfc_cqe_code, &cqevt)) {
13470 case CQE_CODE_COMPL_WQE:
13471 /* Process the WQ/RQ complete event */
13472 phba->last_completion_time = jiffies;
13473 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
13474 (struct lpfc_wcqe_complete *)&cqevt);
13476 case CQE_CODE_RELEASE_WQE:
13477 /* Process the WQ release event */
13478 lpfc_sli4_sp_handle_rel_wcqe(phba,
13479 (struct lpfc_wcqe_release *)&cqevt);
13481 case CQE_CODE_XRI_ABORTED:
13482 /* Process the WQ XRI abort event */
13483 phba->last_completion_time = jiffies;
13484 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
13485 (struct sli4_wcqe_xri_aborted *)&cqevt);
13487 case CQE_CODE_RECEIVE:
13488 case CQE_CODE_RECEIVE_V1:
13489 /* Process the RQ event */
13490 phba->last_completion_time = jiffies;
13491 workposted = lpfc_sli4_sp_handle_rcqe(phba,
13492 (struct lpfc_rcqe *)&cqevt);
13495 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13496 "0388 Not a valid WCQE code: x%x\n",
13497 bf_get(lpfc_cqe_code, &cqevt));
13504 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
13505 * @phba: Pointer to HBA context object.
13506 * @eqe: Pointer to fast-path event queue entry.
13508 * This routine process a event queue entry from the slow-path event queue.
13509 * It will check the MajorCode and MinorCode to determine this is for a
13510 * completion event on a completion queue, if not, an error shall be logged
13511 * and just return. Otherwise, it will get to the corresponding completion
13512 * queue and process all the entries on that completion queue, rearm the
13513 * completion queue, and then return.
13517 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
13518 struct lpfc_queue *speq)
13520 struct lpfc_queue *cq = NULL, *childq;
13523 /* Get the reference to the corresponding CQ */
13524 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
13526 list_for_each_entry(childq, &speq->child_list, list) {
13527 if (childq->queue_id == cqid) {
13532 if (unlikely(!cq)) {
13533 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
13534 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13535 "0365 Slow-path CQ identifier "
13536 "(%d) does not exist\n", cqid);
13540 /* Save EQ associated with this CQ */
13541 cq->assoc_qp = speq;
13543 if (!queue_work_on(cq->chann, phba->wq, &cq->spwork))
13544 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13545 "0390 Cannot schedule soft IRQ "
13546 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13547 cqid, cq->queue_id, raw_smp_processor_id());
13551 * __lpfc_sli4_process_cq - Process elements of a CQ
13552 * @phba: Pointer to HBA context object.
13553 * @cq: Pointer to CQ to be processed
13554 * @handler: Routine to process each cqe
13555 * @delay: Pointer to usdelay to set in case of rescheduling of the handler
13557 * This routine processes completion queue entries in a CQ. While a valid
13558 * queue element is found, the handler is called. During processing checks
13559 * are made for periodic doorbell writes to let the hardware know of
13560 * element consumption.
13562 * If the max limit on cqes to process is hit, or there are no more valid
13563 * entries, the loop stops. If we processed a sufficient number of elements,
13564 * meaning there is sufficient load, rather than rearming and generating
13565 * another interrupt, a cq rescheduling delay will be set. A delay of 0
13566 * indicates no rescheduling.
13568 * Returns True if work scheduled, False otherwise.
13571 __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
13572 bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
13573 struct lpfc_cqe *), unsigned long *delay)
13575 struct lpfc_cqe *cqe;
13576 bool workposted = false;
13577 int count = 0, consumed = 0;
13580 /* default - no reschedule */
13583 if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
13584 goto rearm_and_exit;
13586 /* Process all the entries to the CQ */
13588 cqe = lpfc_sli4_cq_get(cq);
13590 workposted |= handler(phba, cq, cqe);
13591 __lpfc_sli4_consume_cqe(phba, cq, cqe);
13594 if (!(++count % cq->max_proc_limit))
13597 if (!(count % cq->notify_interval)) {
13598 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
13603 if (count == LPFC_NVMET_CQ_NOTIFY)
13604 cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
13606 cqe = lpfc_sli4_cq_get(cq);
13608 if (count >= phba->cfg_cq_poll_threshold) {
13613 /* Track the max number of CQEs processed in 1 EQ */
13614 if (count > cq->CQ_max_cqe)
13615 cq->CQ_max_cqe = count;
13617 cq->assoc_qp->EQ_cqe_cnt += count;
13619 /* Catch the no cq entry condition */
13620 if (unlikely(count == 0))
13621 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13622 "0369 No entry from completion queue "
13623 "qid=%d\n", cq->queue_id);
13625 cq->queue_claimed = 0;
13628 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
13629 arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
13635 * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
13636 * @cq: pointer to CQ to process
13638 * This routine calls the cq processing routine with a handler specific
13639 * to the type of queue bound to it.
13641 * The CQ routine returns two values: the first is the calling status,
13642 * which indicates whether work was queued to the background discovery
13643 * thread. If true, the routine should wakeup the discovery thread;
13644 * the second is the delay parameter. If non-zero, rather than rearming
13645 * the CQ and yet another interrupt, the CQ handler should be queued so
13646 * that it is processed in a subsequent polling action. The value of
13647 * the delay indicates when to reschedule it.
13650 __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
13652 struct lpfc_hba *phba = cq->phba;
13653 unsigned long delay;
13654 bool workposted = false;
13656 /* Process and rearm the CQ */
13657 switch (cq->type) {
13659 workposted |= __lpfc_sli4_process_cq(phba, cq,
13660 lpfc_sli4_sp_handle_mcqe,
13664 if (cq->subtype == LPFC_IO)
13665 workposted |= __lpfc_sli4_process_cq(phba, cq,
13666 lpfc_sli4_fp_handle_cqe,
13669 workposted |= __lpfc_sli4_process_cq(phba, cq,
13670 lpfc_sli4_sp_handle_cqe,
13674 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13675 "0370 Invalid completion queue type (%d)\n",
13681 if (!queue_delayed_work_on(cq->chann, phba->wq,
13682 &cq->sched_spwork, delay))
13683 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13684 "0394 Cannot schedule soft IRQ "
13685 "for cqid=%d on CPU %d\n",
13686 cq->queue_id, cq->chann);
13689 /* wake up worker thread if there are works to be done */
13691 lpfc_worker_wake_up(phba);
13695 * lpfc_sli4_sp_process_cq - slow-path work handler when started by
13697 * @work: pointer to work element
13699 * translates from the work handler and calls the slow-path handler.
13702 lpfc_sli4_sp_process_cq(struct work_struct *work)
13704 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
13706 __lpfc_sli4_sp_process_cq(cq);
13710 * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
13711 * @work: pointer to work element
13713 * translates from the work handler and calls the slow-path handler.
13716 lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
13718 struct lpfc_queue *cq = container_of(to_delayed_work(work),
13719 struct lpfc_queue, sched_spwork);
13721 __lpfc_sli4_sp_process_cq(cq);
13725 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
13726 * @phba: Pointer to HBA context object.
13727 * @cq: Pointer to associated CQ
13728 * @wcqe: Pointer to work-queue completion queue entry.
13730 * This routine process a fast-path work queue completion entry from fast-path
13731 * event queue for FCP command response completion.
13734 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13735 struct lpfc_wcqe_complete *wcqe)
13737 struct lpfc_sli_ring *pring = cq->pring;
13738 struct lpfc_iocbq *cmdiocbq;
13739 struct lpfc_iocbq irspiocbq;
13740 unsigned long iflags;
13742 /* Check for response status */
13743 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
13744 /* If resource errors reported from HBA, reduce queue
13745 * depth of the SCSI device.
13747 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
13748 IOSTAT_LOCAL_REJECT)) &&
13749 ((wcqe->parameter & IOERR_PARAM_MASK) ==
13750 IOERR_NO_RESOURCES))
13751 phba->lpfc_rampdown_queue_depth(phba);
13753 /* Log the error status */
13754 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13755 "0373 FCP CQE error: status=x%x: "
13756 "CQE: %08x %08x %08x %08x\n",
13757 bf_get(lpfc_wcqe_c_status, wcqe),
13758 wcqe->word0, wcqe->total_data_placed,
13759 wcqe->parameter, wcqe->word3);
13762 /* Look up the FCP command IOCB and create pseudo response IOCB */
13763 spin_lock_irqsave(&pring->ring_lock, iflags);
13764 pring->stats.iocb_event++;
13765 spin_unlock_irqrestore(&pring->ring_lock, iflags);
13766 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
13767 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13768 if (unlikely(!cmdiocbq)) {
13769 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13770 "0374 FCP complete with no corresponding "
13771 "cmdiocb: iotag (%d)\n",
13772 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13775 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13776 cmdiocbq->isr_timestamp = cq->isr_timestamp;
13778 if (cmdiocbq->iocb_cmpl == NULL) {
13779 if (cmdiocbq->wqe_cmpl) {
13780 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
13781 spin_lock_irqsave(&phba->hbalock, iflags);
13782 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
13783 spin_unlock_irqrestore(&phba->hbalock, iflags);
13786 /* Pass the cmd_iocb and the wcqe to the upper layer */
13787 (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe);
13790 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13791 "0375 FCP cmdiocb not callback function "
13793 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13797 /* Fake the irspiocb and copy necessary response information */
13798 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
13800 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
13801 spin_lock_irqsave(&phba->hbalock, iflags);
13802 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
13803 spin_unlock_irqrestore(&phba->hbalock, iflags);
13806 /* Pass the cmd_iocb and the rsp state to the upper layer */
13807 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
13811 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
13812 * @phba: Pointer to HBA context object.
13813 * @cq: Pointer to completion queue.
13814 * @wcqe: Pointer to work-queue completion queue entry.
13816 * This routine handles an fast-path WQ entry consumed event by invoking the
13817 * proper WQ release routine to the slow-path WQ.
13820 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13821 struct lpfc_wcqe_release *wcqe)
13823 struct lpfc_queue *childwq;
13824 bool wqid_matched = false;
13827 /* Check for fast-path FCP work queue release */
13828 hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
13829 list_for_each_entry(childwq, &cq->child_list, list) {
13830 if (childwq->queue_id == hba_wqid) {
13831 lpfc_sli4_wq_release(childwq,
13832 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
13833 if (childwq->q_flag & HBA_NVMET_WQFULL)
13834 lpfc_nvmet_wqfull_process(phba, childwq);
13835 wqid_matched = true;
13839 /* Report warning log message if no match found */
13840 if (wqid_matched != true)
13841 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13842 "2580 Fast-path wqe consume event carries "
13843 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
13847 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
13848 * @phba: Pointer to HBA context object.
13849 * @rcqe: Pointer to receive-queue completion queue entry.
13851 * This routine process a receive-queue completion queue entry.
13853 * Return: true if work posted to worker thread, otherwise false.
13856 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13857 struct lpfc_rcqe *rcqe)
13859 bool workposted = false;
13860 struct lpfc_queue *hrq;
13861 struct lpfc_queue *drq;
13862 struct rqb_dmabuf *dma_buf;
13863 struct fc_frame_header *fc_hdr;
13864 struct lpfc_nvmet_tgtport *tgtp;
13865 uint32_t status, rq_id;
13866 unsigned long iflags;
13867 uint32_t fctl, idx;
13869 if ((phba->nvmet_support == 0) ||
13870 (phba->sli4_hba.nvmet_cqset == NULL))
13873 idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
13874 hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
13875 drq = phba->sli4_hba.nvmet_mrq_data[idx];
13877 /* sanity check on queue memory */
13878 if (unlikely(!hrq) || unlikely(!drq))
13881 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
13882 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
13884 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
13886 if ((phba->nvmet_support == 0) ||
13887 (rq_id != hrq->queue_id))
13890 status = bf_get(lpfc_rcqe_status, rcqe);
13892 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
13893 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13894 "6126 Receive Frame Truncated!!\n");
13896 case FC_STATUS_RQ_SUCCESS:
13897 spin_lock_irqsave(&phba->hbalock, iflags);
13898 lpfc_sli4_rq_release(hrq, drq);
13899 dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
13901 hrq->RQ_no_buf_found++;
13902 spin_unlock_irqrestore(&phba->hbalock, iflags);
13905 spin_unlock_irqrestore(&phba->hbalock, iflags);
13907 hrq->RQ_buf_posted--;
13908 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
13910 /* Just some basic sanity checks on FCP Command frame */
13911 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
13912 fc_hdr->fh_f_ctl[1] << 8 |
13913 fc_hdr->fh_f_ctl[2]);
13915 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
13916 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
13917 (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
13920 if (fc_hdr->fh_type == FC_TYPE_FCP) {
13921 dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
13922 lpfc_nvmet_unsol_fcp_event(
13923 phba, idx, dma_buf, cq->isr_timestamp,
13924 cq->q_flag & HBA_NVMET_CQ_NOTIFY);
13928 lpfc_rq_buf_free(phba, &dma_buf->hbuf);
13930 case FC_STATUS_INSUFF_BUF_FRM_DISC:
13931 if (phba->nvmet_support) {
13932 tgtp = phba->targetport->private;
13933 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME,
13934 "6401 RQE Error x%x, posted %d err_cnt "
13936 status, hrq->RQ_buf_posted,
13937 hrq->RQ_no_posted_buf,
13938 atomic_read(&tgtp->rcv_fcp_cmd_in),
13939 atomic_read(&tgtp->rcv_fcp_cmd_out),
13940 atomic_read(&tgtp->xmt_fcp_release));
13944 case FC_STATUS_INSUFF_BUF_NEED_BUF:
13945 hrq->RQ_no_posted_buf++;
13946 /* Post more buffers if possible */
13954 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
13955 * @phba: adapter with cq
13956 * @cq: Pointer to the completion queue.
13957 * @eqe: Pointer to fast-path completion queue entry.
13959 * This routine process a fast-path work queue completion entry from fast-path
13960 * event queue for FCP command response completion.
13962 * Return: true if work posted to worker thread, otherwise false.
13965 lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13966 struct lpfc_cqe *cqe)
13968 struct lpfc_wcqe_release wcqe;
13969 bool workposted = false;
13971 /* Copy the work queue CQE and convert endian order if needed */
13972 lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
13974 /* Check and process for different type of WCQE and dispatch */
13975 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
13976 case CQE_CODE_COMPL_WQE:
13977 case CQE_CODE_NVME_ERSP:
13979 /* Process the WQ complete event */
13980 phba->last_completion_time = jiffies;
13981 if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
13982 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
13983 (struct lpfc_wcqe_complete *)&wcqe);
13985 case CQE_CODE_RELEASE_WQE:
13986 cq->CQ_release_wqe++;
13987 /* Process the WQ release event */
13988 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
13989 (struct lpfc_wcqe_release *)&wcqe);
13991 case CQE_CODE_XRI_ABORTED:
13992 cq->CQ_xri_aborted++;
13993 /* Process the WQ XRI abort event */
13994 phba->last_completion_time = jiffies;
13995 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
13996 (struct sli4_wcqe_xri_aborted *)&wcqe);
13998 case CQE_CODE_RECEIVE_V1:
13999 case CQE_CODE_RECEIVE:
14000 phba->last_completion_time = jiffies;
14001 if (cq->subtype == LPFC_NVMET) {
14002 workposted = lpfc_sli4_nvmet_handle_rcqe(
14003 phba, cq, (struct lpfc_rcqe *)&wcqe);
14007 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14008 "0144 Not a valid CQE code: x%x\n",
14009 bf_get(lpfc_wcqe_c_code, &wcqe));
14016 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
14017 * @phba: Pointer to HBA context object.
14018 * @eqe: Pointer to fast-path event queue entry.
14020 * This routine process a event queue entry from the fast-path event queue.
14021 * It will check the MajorCode and MinorCode to determine this is for a
14022 * completion event on a completion queue, if not, an error shall be logged
14023 * and just return. Otherwise, it will get to the corresponding completion
14024 * queue and process all the entries on the completion queue, rearm the
14025 * completion queue, and then return.
14028 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
14029 struct lpfc_eqe *eqe)
14031 struct lpfc_queue *cq = NULL;
14032 uint32_t qidx = eq->hdwq;
14035 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
14036 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14037 "0366 Not a valid completion "
14038 "event: majorcode=x%x, minorcode=x%x\n",
14039 bf_get_le32(lpfc_eqe_major_code, eqe),
14040 bf_get_le32(lpfc_eqe_minor_code, eqe));
14044 /* Get the reference to the corresponding CQ */
14045 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
14047 /* Use the fast lookup method first */
14048 if (cqid <= phba->sli4_hba.cq_max) {
14049 cq = phba->sli4_hba.cq_lookup[cqid];
14054 /* Next check for NVMET completion */
14055 if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
14056 id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
14057 if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
14058 /* Process NVMET unsol rcv */
14059 cq = phba->sli4_hba.nvmet_cqset[cqid - id];
14064 if (phba->sli4_hba.nvmels_cq &&
14065 (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
14066 /* Process NVME unsol rcv */
14067 cq = phba->sli4_hba.nvmels_cq;
14070 /* Otherwise this is a Slow path event */
14072 lpfc_sli4_sp_handle_eqe(phba, eqe,
14073 phba->sli4_hba.hdwq[qidx].hba_eq);
14078 if (unlikely(cqid != cq->queue_id)) {
14079 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14080 "0368 Miss-matched fast-path completion "
14081 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
14082 cqid, cq->queue_id);
14087 #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
14088 if (phba->ktime_on)
14089 cq->isr_timestamp = ktime_get_ns();
14091 cq->isr_timestamp = 0;
14093 if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork))
14094 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14095 "0363 Cannot schedule soft IRQ "
14096 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
14097 cqid, cq->queue_id, raw_smp_processor_id());
14101 * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
14102 * @cq: Pointer to CQ to be processed
14104 * This routine calls the cq processing routine with the handler for
14107 * The CQ routine returns two values: the first is the calling status,
14108 * which indicates whether work was queued to the background discovery
14109 * thread. If true, the routine should wakeup the discovery thread;
14110 * the second is the delay parameter. If non-zero, rather than rearming
14111 * the CQ and yet another interrupt, the CQ handler should be queued so
14112 * that it is processed in a subsequent polling action. The value of
14113 * the delay indicates when to reschedule it.
14116 __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq)
14118 struct lpfc_hba *phba = cq->phba;
14119 unsigned long delay;
14120 bool workposted = false;
14122 /* process and rearm the CQ */
14123 workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
14127 if (!queue_delayed_work_on(cq->chann, phba->wq,
14128 &cq->sched_irqwork, delay))
14129 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14130 "0367 Cannot schedule soft IRQ "
14131 "for cqid=%d on CPU %d\n",
14132 cq->queue_id, cq->chann);
14135 /* wake up worker thread if there are works to be done */
14137 lpfc_worker_wake_up(phba);
14141 * lpfc_sli4_hba_process_cq - fast-path work handler when started by
14143 * @work: pointer to work element
14145 * translates from the work handler and calls the fast-path handler.
14148 lpfc_sli4_hba_process_cq(struct work_struct *work)
14150 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
14152 __lpfc_sli4_hba_process_cq(cq);
14156 * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer
14157 * @work: pointer to work element
14159 * translates from the work handler and calls the fast-path handler.
14162 lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
14164 struct lpfc_queue *cq = container_of(to_delayed_work(work),
14165 struct lpfc_queue, sched_irqwork);
14167 __lpfc_sli4_hba_process_cq(cq);
14171 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
14172 * @irq: Interrupt number.
14173 * @dev_id: The device context pointer.
14175 * This function is directly called from the PCI layer as an interrupt
14176 * service routine when device with SLI-4 interface spec is enabled with
14177 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
14178 * ring event in the HBA. However, when the device is enabled with either
14179 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
14180 * device-level interrupt handler. When the PCI slot is in error recovery
14181 * or the HBA is undergoing initialization, the interrupt handler will not
14182 * process the interrupt. The SCSI FCP fast-path ring event are handled in
14183 * the intrrupt context. This function is called without any lock held.
14184 * It gets the hbalock to access and update SLI data structures. Note that,
14185 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
14186 * equal to that of FCP CQ index.
14188 * The link attention and ELS ring attention events are handled
14189 * by the worker thread. The interrupt handler signals the worker thread
14190 * and returns for these events. This function is called without any lock
14191 * held. It gets the hbalock to access and update SLI data structures.
14193 * This function returns IRQ_HANDLED when interrupt is handled else it
14194 * returns IRQ_NONE.
14197 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
14199 struct lpfc_hba *phba;
14200 struct lpfc_hba_eq_hdl *hba_eq_hdl;
14201 struct lpfc_queue *fpeq;
14202 unsigned long iflag;
14205 struct lpfc_eq_intr_info *eqi;
14208 /* Get the driver's phba structure from the dev_id */
14209 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
14210 phba = hba_eq_hdl->phba;
14211 hba_eqidx = hba_eq_hdl->idx;
14213 if (unlikely(!phba))
14215 if (unlikely(!phba->sli4_hba.hdwq))
14218 /* Get to the EQ struct associated with this vector */
14219 fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
14220 if (unlikely(!fpeq))
14223 /* Check device state for handling interrupt */
14224 if (unlikely(lpfc_intr_state_check(phba))) {
14225 /* Check again for link_state with lock held */
14226 spin_lock_irqsave(&phba->hbalock, iflag);
14227 if (phba->link_state < LPFC_LINK_DOWN)
14228 /* Flush, clear interrupt, and rearm the EQ */
14229 lpfc_sli4_eq_flush(phba, fpeq);
14230 spin_unlock_irqrestore(&phba->hbalock, iflag);
14234 eqi = phba->sli4_hba.eq_info;
14235 icnt = this_cpu_inc_return(eqi->icnt);
14236 fpeq->last_cpu = raw_smp_processor_id();
14238 if (icnt > LPFC_EQD_ISR_TRIGGER &&
14239 phba->cfg_irq_chann == 1 &&
14240 phba->cfg_auto_imax &&
14241 fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
14242 phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
14243 lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
14245 /* process and rearm the EQ */
14246 ecount = lpfc_sli4_process_eq(phba, fpeq);
14248 if (unlikely(ecount == 0)) {
14249 fpeq->EQ_no_entry++;
14250 if (phba->intr_type == MSIX)
14251 /* MSI-X treated interrupt served as no EQ share INT */
14252 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14253 "0358 MSI-X interrupt with no EQE\n");
14255 /* Non MSI-X treated on interrupt as EQ share INT */
14259 return IRQ_HANDLED;
14260 } /* lpfc_sli4_fp_intr_handler */
14263 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
14264 * @irq: Interrupt number.
14265 * @dev_id: The device context pointer.
14267 * This function is the device-level interrupt handler to device with SLI-4
14268 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
14269 * interrupt mode is enabled and there is an event in the HBA which requires
14270 * driver attention. This function invokes the slow-path interrupt attention
14271 * handling function and fast-path interrupt attention handling function in
14272 * turn to process the relevant HBA attention events. This function is called
14273 * without any lock held. It gets the hbalock to access and update SLI data
14276 * This function returns IRQ_HANDLED when interrupt is handled, else it
14277 * returns IRQ_NONE.
14280 lpfc_sli4_intr_handler(int irq, void *dev_id)
14282 struct lpfc_hba *phba;
14283 irqreturn_t hba_irq_rc;
14284 bool hba_handled = false;
14287 /* Get the driver's phba structure from the dev_id */
14288 phba = (struct lpfc_hba *)dev_id;
14290 if (unlikely(!phba))
14294 * Invoke fast-path host attention interrupt handling as appropriate.
14296 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
14297 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
14298 &phba->sli4_hba.hba_eq_hdl[qidx]);
14299 if (hba_irq_rc == IRQ_HANDLED)
14300 hba_handled |= true;
14303 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
14304 } /* lpfc_sli4_intr_handler */
14307 * lpfc_sli4_queue_free - free a queue structure and associated memory
14308 * @queue: The queue structure to free.
14310 * This function frees a queue structure and the DMAable memory used for
14311 * the host resident queue. This function must be called after destroying the
14312 * queue on the HBA.
14315 lpfc_sli4_queue_free(struct lpfc_queue *queue)
14317 struct lpfc_dmabuf *dmabuf;
14322 if (!list_empty(&queue->wq_list))
14323 list_del(&queue->wq_list);
14325 while (!list_empty(&queue->page_list)) {
14326 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
14328 dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
14329 dmabuf->virt, dmabuf->phys);
14333 lpfc_free_rq_buffer(queue->phba, queue);
14334 kfree(queue->rqbp);
14337 if (!list_empty(&queue->cpu_list))
14338 list_del(&queue->cpu_list);
14345 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
14346 * @phba: The HBA that this queue is being created on.
14347 * @page_size: The size of a queue page
14348 * @entry_size: The size of each queue entry for this queue.
14349 * @entry count: The number of entries that this queue will handle.
14350 * @cpu: The cpu that will primarily utilize this queue.
14352 * This function allocates a queue structure and the DMAable memory used for
14353 * the host resident queue. This function must be called before creating the
14354 * queue on the HBA.
14356 struct lpfc_queue *
14357 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
14358 uint32_t entry_size, uint32_t entry_count, int cpu)
14360 struct lpfc_queue *queue;
14361 struct lpfc_dmabuf *dmabuf;
14362 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14365 if (!phba->sli4_hba.pc_sli4_params.supported)
14366 hw_page_size = page_size;
14368 pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
14370 /* If needed, Adjust page count to match the max the adapter supports */
14371 if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
14372 pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
14374 queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
14375 GFP_KERNEL, cpu_to_node(cpu));
14379 INIT_LIST_HEAD(&queue->list);
14380 INIT_LIST_HEAD(&queue->wq_list);
14381 INIT_LIST_HEAD(&queue->wqfull_list);
14382 INIT_LIST_HEAD(&queue->page_list);
14383 INIT_LIST_HEAD(&queue->child_list);
14384 INIT_LIST_HEAD(&queue->cpu_list);
14386 /* Set queue parameters now. If the system cannot provide memory
14387 * resources, the free routine needs to know what was allocated.
14389 queue->page_count = pgcnt;
14390 queue->q_pgs = (void **)&queue[1];
14391 queue->entry_cnt_per_pg = hw_page_size / entry_size;
14392 queue->entry_size = entry_size;
14393 queue->entry_count = entry_count;
14394 queue->page_size = hw_page_size;
14395 queue->phba = phba;
14397 for (x = 0; x < queue->page_count; x++) {
14398 dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
14399 dev_to_node(&phba->pcidev->dev));
14402 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14403 hw_page_size, &dmabuf->phys,
14405 if (!dmabuf->virt) {
14409 dmabuf->buffer_tag = x;
14410 list_add_tail(&dmabuf->list, &queue->page_list);
14411 /* use lpfc_sli4_qe to index a paritcular entry in this page */
14412 queue->q_pgs[x] = dmabuf->virt;
14414 INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
14415 INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
14416 INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
14417 INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
14419 /* notify_interval will be set during q creation */
14423 lpfc_sli4_queue_free(queue);
14428 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
14429 * @phba: HBA structure that indicates port to create a queue on.
14430 * @pci_barset: PCI BAR set flag.
14432 * This function shall perform iomap of the specified PCI BAR address to host
14433 * memory address if not already done so and return it. The returned host
14434 * memory address can be NULL.
14436 static void __iomem *
14437 lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
14442 switch (pci_barset) {
14443 case WQ_PCI_BAR_0_AND_1:
14444 return phba->pci_bar0_memmap_p;
14445 case WQ_PCI_BAR_2_AND_3:
14446 return phba->pci_bar2_memmap_p;
14447 case WQ_PCI_BAR_4_AND_5:
14448 return phba->pci_bar4_memmap_p;
14456 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
14457 * @phba: HBA structure that EQs are on.
14458 * @startq: The starting EQ index to modify
14459 * @numq: The number of EQs (consecutive indexes) to modify
14460 * @usdelay: amount of delay
14462 * This function revises the EQ delay on 1 or more EQs. The EQ delay
14463 * is set either by writing to a register (if supported by the SLI Port)
14464 * or by mailbox command. The mailbox command allows several EQs to be
14467 * The @phba struct is used to send a mailbox command to HBA. The @startq
14468 * is used to get the starting EQ index to change. The @numq value is
14469 * used to specify how many consecutive EQ indexes, starting at EQ index,
14470 * are to be changed. This function is asynchronous and will wait for any
14471 * mailbox commands to finish before returning.
14473 * On success this function will return a zero. If unable to allocate
14474 * enough memory this function will return -ENOMEM. If a mailbox command
14475 * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
14476 * have had their delay multipler changed.
14479 lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
14480 uint32_t numq, uint32_t usdelay)
14482 struct lpfc_mbx_modify_eq_delay *eq_delay;
14483 LPFC_MBOXQ_t *mbox;
14484 struct lpfc_queue *eq;
14485 int cnt = 0, rc, length;
14486 uint32_t shdr_status, shdr_add_status;
14489 union lpfc_sli4_cfg_shdr *shdr;
14491 if (startq >= phba->cfg_irq_chann)
14494 if (usdelay > 0xFFFF) {
14495 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
14496 "6429 usdelay %d too large. Scaled down to "
14497 "0xFFFF.\n", usdelay);
14501 /* set values by EQ_DELAY register if supported */
14502 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
14503 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
14504 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
14508 lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
14516 /* Otherwise, set values by mailbox cmd */
14518 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME,
14521 "6428 Failed allocating mailbox cmd buffer."
14522 " EQ delay was not set.\n");
14525 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
14526 sizeof(struct lpfc_sli4_cfg_mhdr));
14527 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14528 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
14529 length, LPFC_SLI4_MBX_EMBED);
14530 eq_delay = &mbox->u.mqe.un.eq_delay;
14532 /* Calculate delay multiper from maximum interrupt per second */
14533 dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
14536 if (dmult > LPFC_DMULT_MAX)
14537 dmult = LPFC_DMULT_MAX;
14539 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
14540 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
14543 eq->q_mode = usdelay;
14544 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
14545 eq_delay->u.request.eq[cnt].phase = 0;
14546 eq_delay->u.request.eq[cnt].delay_multi = dmult;
14551 eq_delay->u.request.num_eq = cnt;
14553 mbox->vport = phba->pport;
14554 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14555 mbox->ctx_buf = NULL;
14556 mbox->ctx_ndlp = NULL;
14557 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14558 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
14559 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14560 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14561 if (shdr_status || shdr_add_status || rc) {
14562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14563 "2512 MODIFY_EQ_DELAY mailbox failed with "
14564 "status x%x add_status x%x, mbx status x%x\n",
14565 shdr_status, shdr_add_status, rc);
14567 mempool_free(mbox, phba->mbox_mem_pool);
14572 * lpfc_eq_create - Create an Event Queue on the HBA
14573 * @phba: HBA structure that indicates port to create a queue on.
14574 * @eq: The queue structure to use to create the event queue.
14575 * @imax: The maximum interrupt per second limit.
14577 * This function creates an event queue, as detailed in @eq, on a port,
14578 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
14580 * The @phba struct is used to send mailbox command to HBA. The @eq struct
14581 * is used to get the entry count and entry size that are necessary to
14582 * determine the number of pages to allocate and use for this queue. This
14583 * function will send the EQ_CREATE mailbox command to the HBA to setup the
14584 * event queue. This function is asynchronous and will wait for the mailbox
14585 * command to finish before continuing.
14587 * On success this function will return a zero. If unable to allocate enough
14588 * memory this function will return -ENOMEM. If the queue create mailbox command
14589 * fails this function will return -ENXIO.
14592 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
14594 struct lpfc_mbx_eq_create *eq_create;
14595 LPFC_MBOXQ_t *mbox;
14596 int rc, length, status = 0;
14597 struct lpfc_dmabuf *dmabuf;
14598 uint32_t shdr_status, shdr_add_status;
14599 union lpfc_sli4_cfg_shdr *shdr;
14601 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14603 /* sanity check on queue memory */
14606 if (!phba->sli4_hba.pc_sli4_params.supported)
14607 hw_page_size = SLI4_PAGE_SIZE;
14609 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14612 length = (sizeof(struct lpfc_mbx_eq_create) -
14613 sizeof(struct lpfc_sli4_cfg_mhdr));
14614 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14615 LPFC_MBOX_OPCODE_EQ_CREATE,
14616 length, LPFC_SLI4_MBX_EMBED);
14617 eq_create = &mbox->u.mqe.un.eq_create;
14618 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
14619 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
14621 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
14623 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
14625 /* Use version 2 of CREATE_EQ if eqav is set */
14626 if (phba->sli4_hba.pc_sli4_params.eqav) {
14627 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14628 LPFC_Q_CREATE_VERSION_2);
14629 bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
14630 phba->sli4_hba.pc_sli4_params.eqav);
14633 /* don't setup delay multiplier using EQ_CREATE */
14635 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
14637 switch (eq->entry_count) {
14639 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14640 "0360 Unsupported EQ count. (%d)\n",
14642 if (eq->entry_count < 256) {
14646 /* fall through - otherwise default to smallest count */
14648 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14652 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14656 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14660 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14664 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14668 list_for_each_entry(dmabuf, &eq->page_list, list) {
14669 memset(dmabuf->virt, 0, hw_page_size);
14670 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
14671 putPaddrLow(dmabuf->phys);
14672 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
14673 putPaddrHigh(dmabuf->phys);
14675 mbox->vport = phba->pport;
14676 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14677 mbox->ctx_buf = NULL;
14678 mbox->ctx_ndlp = NULL;
14679 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14680 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14681 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14682 if (shdr_status || shdr_add_status || rc) {
14683 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14684 "2500 EQ_CREATE mailbox failed with "
14685 "status x%x add_status x%x, mbx status x%x\n",
14686 shdr_status, shdr_add_status, rc);
14689 eq->type = LPFC_EQ;
14690 eq->subtype = LPFC_NONE;
14691 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
14692 if (eq->queue_id == 0xFFFF)
14694 eq->host_index = 0;
14695 eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
14696 eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
14698 mempool_free(mbox, phba->mbox_mem_pool);
14703 * lpfc_cq_create - Create a Completion Queue on the HBA
14704 * @phba: HBA structure that indicates port to create a queue on.
14705 * @cq: The queue structure to use to create the completion queue.
14706 * @eq: The event queue to bind this completion queue to.
14708 * This function creates a completion queue, as detailed in @wq, on a port,
14709 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
14711 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14712 * is used to get the entry count and entry size that are necessary to
14713 * determine the number of pages to allocate and use for this queue. The @eq
14714 * is used to indicate which event queue to bind this completion queue to. This
14715 * function will send the CQ_CREATE mailbox command to the HBA to setup the
14716 * completion queue. This function is asynchronous and will wait for the mailbox
14717 * command to finish before continuing.
14719 * On success this function will return a zero. If unable to allocate enough
14720 * memory this function will return -ENOMEM. If the queue create mailbox command
14721 * fails this function will return -ENXIO.
14724 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
14725 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
14727 struct lpfc_mbx_cq_create *cq_create;
14728 struct lpfc_dmabuf *dmabuf;
14729 LPFC_MBOXQ_t *mbox;
14730 int rc, length, status = 0;
14731 uint32_t shdr_status, shdr_add_status;
14732 union lpfc_sli4_cfg_shdr *shdr;
14734 /* sanity check on queue memory */
14738 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14741 length = (sizeof(struct lpfc_mbx_cq_create) -
14742 sizeof(struct lpfc_sli4_cfg_mhdr));
14743 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14744 LPFC_MBOX_OPCODE_CQ_CREATE,
14745 length, LPFC_SLI4_MBX_EMBED);
14746 cq_create = &mbox->u.mqe.un.cq_create;
14747 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
14748 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
14750 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
14751 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
14752 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14753 phba->sli4_hba.pc_sli4_params.cqv);
14754 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
14755 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
14756 (cq->page_size / SLI4_PAGE_SIZE));
14757 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
14759 bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
14760 phba->sli4_hba.pc_sli4_params.cqav);
14762 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
14765 switch (cq->entry_count) {
14768 if (phba->sli4_hba.pc_sli4_params.cqv ==
14769 LPFC_Q_CREATE_VERSION_2) {
14770 cq_create->u.request.context.lpfc_cq_context_count =
14772 bf_set(lpfc_cq_context_count,
14773 &cq_create->u.request.context,
14774 LPFC_CQ_CNT_WORD7);
14779 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14780 "0361 Unsupported CQ count: "
14781 "entry cnt %d sz %d pg cnt %d\n",
14782 cq->entry_count, cq->entry_size,
14784 if (cq->entry_count < 256) {
14788 /* fall through - otherwise default to smallest count */
14790 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
14794 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
14798 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
14802 list_for_each_entry(dmabuf, &cq->page_list, list) {
14803 memset(dmabuf->virt, 0, cq->page_size);
14804 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
14805 putPaddrLow(dmabuf->phys);
14806 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
14807 putPaddrHigh(dmabuf->phys);
14809 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14811 /* The IOCTL status is embedded in the mailbox subheader. */
14812 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14813 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14814 if (shdr_status || shdr_add_status || rc) {
14815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14816 "2501 CQ_CREATE mailbox failed with "
14817 "status x%x add_status x%x, mbx status x%x\n",
14818 shdr_status, shdr_add_status, rc);
14822 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
14823 if (cq->queue_id == 0xFFFF) {
14827 /* link the cq onto the parent eq child list */
14828 list_add_tail(&cq->list, &eq->child_list);
14829 /* Set up completion queue's type and subtype */
14831 cq->subtype = subtype;
14832 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
14833 cq->assoc_qid = eq->queue_id;
14835 cq->host_index = 0;
14836 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
14837 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
14839 if (cq->queue_id > phba->sli4_hba.cq_max)
14840 phba->sli4_hba.cq_max = cq->queue_id;
14842 mempool_free(mbox, phba->mbox_mem_pool);
14847 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
14848 * @phba: HBA structure that indicates port to create a queue on.
14849 * @cqp: The queue structure array to use to create the completion queues.
14850 * @hdwq: The hardware queue array with the EQ to bind completion queues to.
14852 * This function creates a set of completion queue, s to support MRQ
14853 * as detailed in @cqp, on a port,
14854 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
14856 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14857 * is used to get the entry count and entry size that are necessary to
14858 * determine the number of pages to allocate and use for this queue. The @eq
14859 * is used to indicate which event queue to bind this completion queue to. This
14860 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
14861 * completion queue. This function is asynchronous and will wait for the mailbox
14862 * command to finish before continuing.
14864 * On success this function will return a zero. If unable to allocate enough
14865 * memory this function will return -ENOMEM. If the queue create mailbox command
14866 * fails this function will return -ENXIO.
14869 lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
14870 struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
14873 struct lpfc_queue *cq;
14874 struct lpfc_queue *eq;
14875 struct lpfc_mbx_cq_create_set *cq_set;
14876 struct lpfc_dmabuf *dmabuf;
14877 LPFC_MBOXQ_t *mbox;
14878 int rc, length, alloclen, status = 0;
14879 int cnt, idx, numcq, page_idx = 0;
14880 uint32_t shdr_status, shdr_add_status;
14881 union lpfc_sli4_cfg_shdr *shdr;
14882 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14884 /* sanity check on queue memory */
14885 numcq = phba->cfg_nvmet_mrq;
14886 if (!cqp || !hdwq || !numcq)
14889 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14893 length = sizeof(struct lpfc_mbx_cq_create_set);
14894 length += ((numcq * cqp[0]->page_count) *
14895 sizeof(struct dma_address));
14896 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
14897 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
14898 LPFC_SLI4_MBX_NEMBED);
14899 if (alloclen < length) {
14900 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14901 "3098 Allocated DMA memory size (%d) is "
14902 "less than the requested DMA memory size "
14903 "(%d)\n", alloclen, length);
14907 cq_set = mbox->sge_array->addr[0];
14908 shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
14909 bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
14911 for (idx = 0; idx < numcq; idx++) {
14913 eq = hdwq[idx].hba_eq;
14918 if (!phba->sli4_hba.pc_sli4_params.supported)
14919 hw_page_size = cq->page_size;
14923 bf_set(lpfc_mbx_cq_create_set_page_size,
14924 &cq_set->u.request,
14925 (hw_page_size / SLI4_PAGE_SIZE));
14926 bf_set(lpfc_mbx_cq_create_set_num_pages,
14927 &cq_set->u.request, cq->page_count);
14928 bf_set(lpfc_mbx_cq_create_set_evt,
14929 &cq_set->u.request, 1);
14930 bf_set(lpfc_mbx_cq_create_set_valid,
14931 &cq_set->u.request, 1);
14932 bf_set(lpfc_mbx_cq_create_set_cqe_size,
14933 &cq_set->u.request, 0);
14934 bf_set(lpfc_mbx_cq_create_set_num_cq,
14935 &cq_set->u.request, numcq);
14936 bf_set(lpfc_mbx_cq_create_set_autovalid,
14937 &cq_set->u.request,
14938 phba->sli4_hba.pc_sli4_params.cqav);
14939 switch (cq->entry_count) {
14942 if (phba->sli4_hba.pc_sli4_params.cqv ==
14943 LPFC_Q_CREATE_VERSION_2) {
14944 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
14945 &cq_set->u.request,
14947 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
14948 &cq_set->u.request,
14949 LPFC_CQ_CNT_WORD7);
14954 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14955 "3118 Bad CQ count. (%d)\n",
14957 if (cq->entry_count < 256) {
14961 /* fall through - otherwise default to smallest */
14963 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
14964 &cq_set->u.request, LPFC_CQ_CNT_256);
14967 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
14968 &cq_set->u.request, LPFC_CQ_CNT_512);
14971 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
14972 &cq_set->u.request, LPFC_CQ_CNT_1024);
14975 bf_set(lpfc_mbx_cq_create_set_eq_id0,
14976 &cq_set->u.request, eq->queue_id);
14979 bf_set(lpfc_mbx_cq_create_set_eq_id1,
14980 &cq_set->u.request, eq->queue_id);
14983 bf_set(lpfc_mbx_cq_create_set_eq_id2,
14984 &cq_set->u.request, eq->queue_id);
14987 bf_set(lpfc_mbx_cq_create_set_eq_id3,
14988 &cq_set->u.request, eq->queue_id);
14991 bf_set(lpfc_mbx_cq_create_set_eq_id4,
14992 &cq_set->u.request, eq->queue_id);
14995 bf_set(lpfc_mbx_cq_create_set_eq_id5,
14996 &cq_set->u.request, eq->queue_id);
14999 bf_set(lpfc_mbx_cq_create_set_eq_id6,
15000 &cq_set->u.request, eq->queue_id);
15003 bf_set(lpfc_mbx_cq_create_set_eq_id7,
15004 &cq_set->u.request, eq->queue_id);
15007 bf_set(lpfc_mbx_cq_create_set_eq_id8,
15008 &cq_set->u.request, eq->queue_id);
15011 bf_set(lpfc_mbx_cq_create_set_eq_id9,
15012 &cq_set->u.request, eq->queue_id);
15015 bf_set(lpfc_mbx_cq_create_set_eq_id10,
15016 &cq_set->u.request, eq->queue_id);
15019 bf_set(lpfc_mbx_cq_create_set_eq_id11,
15020 &cq_set->u.request, eq->queue_id);
15023 bf_set(lpfc_mbx_cq_create_set_eq_id12,
15024 &cq_set->u.request, eq->queue_id);
15027 bf_set(lpfc_mbx_cq_create_set_eq_id13,
15028 &cq_set->u.request, eq->queue_id);
15031 bf_set(lpfc_mbx_cq_create_set_eq_id14,
15032 &cq_set->u.request, eq->queue_id);
15035 bf_set(lpfc_mbx_cq_create_set_eq_id15,
15036 &cq_set->u.request, eq->queue_id);
15040 /* link the cq onto the parent eq child list */
15041 list_add_tail(&cq->list, &eq->child_list);
15042 /* Set up completion queue's type and subtype */
15044 cq->subtype = subtype;
15045 cq->assoc_qid = eq->queue_id;
15047 cq->host_index = 0;
15048 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
15049 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
15054 list_for_each_entry(dmabuf, &cq->page_list, list) {
15055 memset(dmabuf->virt, 0, hw_page_size);
15056 cnt = page_idx + dmabuf->buffer_tag;
15057 cq_set->u.request.page[cnt].addr_lo =
15058 putPaddrLow(dmabuf->phys);
15059 cq_set->u.request.page[cnt].addr_hi =
15060 putPaddrHigh(dmabuf->phys);
15066 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15068 /* The IOCTL status is embedded in the mailbox subheader. */
15069 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15070 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15071 if (shdr_status || shdr_add_status || rc) {
15072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15073 "3119 CQ_CREATE_SET mailbox failed with "
15074 "status x%x add_status x%x, mbx status x%x\n",
15075 shdr_status, shdr_add_status, rc);
15079 rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
15080 if (rc == 0xFFFF) {
15085 for (idx = 0; idx < numcq; idx++) {
15087 cq->queue_id = rc + idx;
15088 if (cq->queue_id > phba->sli4_hba.cq_max)
15089 phba->sli4_hba.cq_max = cq->queue_id;
15093 lpfc_sli4_mbox_cmd_free(phba, mbox);
15098 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
15099 * @phba: HBA structure that indicates port to create a queue on.
15100 * @mq: The queue structure to use to create the mailbox queue.
15101 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
15102 * @cq: The completion queue to associate with this cq.
15104 * This function provides failback (fb) functionality when the
15105 * mq_create_ext fails on older FW generations. It's purpose is identical
15106 * to mq_create_ext otherwise.
15108 * This routine cannot fail as all attributes were previously accessed and
15109 * initialized in mq_create_ext.
15112 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
15113 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
15115 struct lpfc_mbx_mq_create *mq_create;
15116 struct lpfc_dmabuf *dmabuf;
15119 length = (sizeof(struct lpfc_mbx_mq_create) -
15120 sizeof(struct lpfc_sli4_cfg_mhdr));
15121 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15122 LPFC_MBOX_OPCODE_MQ_CREATE,
15123 length, LPFC_SLI4_MBX_EMBED);
15124 mq_create = &mbox->u.mqe.un.mq_create;
15125 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
15127 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
15129 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
15130 switch (mq->entry_count) {
15132 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15133 LPFC_MQ_RING_SIZE_16);
15136 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15137 LPFC_MQ_RING_SIZE_32);
15140 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15141 LPFC_MQ_RING_SIZE_64);
15144 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15145 LPFC_MQ_RING_SIZE_128);
15148 list_for_each_entry(dmabuf, &mq->page_list, list) {
15149 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15150 putPaddrLow(dmabuf->phys);
15151 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15152 putPaddrHigh(dmabuf->phys);
15157 * lpfc_mq_create - Create a mailbox Queue on the HBA
15158 * @phba: HBA structure that indicates port to create a queue on.
15159 * @mq: The queue structure to use to create the mailbox queue.
15160 * @cq: The completion queue to associate with this cq.
15161 * @subtype: The queue's subtype.
15163 * This function creates a mailbox queue, as detailed in @mq, on a port,
15164 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
15166 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15167 * is used to get the entry count and entry size that are necessary to
15168 * determine the number of pages to allocate and use for this queue. This
15169 * function will send the MQ_CREATE mailbox command to the HBA to setup the
15170 * mailbox queue. This function is asynchronous and will wait for the mailbox
15171 * command to finish before continuing.
15173 * On success this function will return a zero. If unable to allocate enough
15174 * memory this function will return -ENOMEM. If the queue create mailbox command
15175 * fails this function will return -ENXIO.
15178 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
15179 struct lpfc_queue *cq, uint32_t subtype)
15181 struct lpfc_mbx_mq_create *mq_create;
15182 struct lpfc_mbx_mq_create_ext *mq_create_ext;
15183 struct lpfc_dmabuf *dmabuf;
15184 LPFC_MBOXQ_t *mbox;
15185 int rc, length, status = 0;
15186 uint32_t shdr_status, shdr_add_status;
15187 union lpfc_sli4_cfg_shdr *shdr;
15188 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15190 /* sanity check on queue memory */
15193 if (!phba->sli4_hba.pc_sli4_params.supported)
15194 hw_page_size = SLI4_PAGE_SIZE;
15196 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15199 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
15200 sizeof(struct lpfc_sli4_cfg_mhdr));
15201 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15202 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
15203 length, LPFC_SLI4_MBX_EMBED);
15205 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
15206 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
15207 bf_set(lpfc_mbx_mq_create_ext_num_pages,
15208 &mq_create_ext->u.request, mq->page_count);
15209 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
15210 &mq_create_ext->u.request, 1);
15211 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
15212 &mq_create_ext->u.request, 1);
15213 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
15214 &mq_create_ext->u.request, 1);
15215 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
15216 &mq_create_ext->u.request, 1);
15217 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
15218 &mq_create_ext->u.request, 1);
15219 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
15220 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15221 phba->sli4_hba.pc_sli4_params.mqv);
15222 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
15223 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
15226 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
15228 switch (mq->entry_count) {
15230 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15231 "0362 Unsupported MQ count. (%d)\n",
15233 if (mq->entry_count < 16) {
15237 /* fall through - otherwise default to smallest count */
15239 bf_set(lpfc_mq_context_ring_size,
15240 &mq_create_ext->u.request.context,
15241 LPFC_MQ_RING_SIZE_16);
15244 bf_set(lpfc_mq_context_ring_size,
15245 &mq_create_ext->u.request.context,
15246 LPFC_MQ_RING_SIZE_32);
15249 bf_set(lpfc_mq_context_ring_size,
15250 &mq_create_ext->u.request.context,
15251 LPFC_MQ_RING_SIZE_64);
15254 bf_set(lpfc_mq_context_ring_size,
15255 &mq_create_ext->u.request.context,
15256 LPFC_MQ_RING_SIZE_128);
15259 list_for_each_entry(dmabuf, &mq->page_list, list) {
15260 memset(dmabuf->virt, 0, hw_page_size);
15261 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
15262 putPaddrLow(dmabuf->phys);
15263 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
15264 putPaddrHigh(dmabuf->phys);
15266 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15267 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
15268 &mq_create_ext->u.response);
15269 if (rc != MBX_SUCCESS) {
15270 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15271 "2795 MQ_CREATE_EXT failed with "
15272 "status x%x. Failback to MQ_CREATE.\n",
15274 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
15275 mq_create = &mbox->u.mqe.un.mq_create;
15276 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15277 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
15278 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
15279 &mq_create->u.response);
15282 /* The IOCTL status is embedded in the mailbox subheader. */
15283 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15284 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15285 if (shdr_status || shdr_add_status || rc) {
15286 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15287 "2502 MQ_CREATE mailbox failed with "
15288 "status x%x add_status x%x, mbx status x%x\n",
15289 shdr_status, shdr_add_status, rc);
15293 if (mq->queue_id == 0xFFFF) {
15297 mq->type = LPFC_MQ;
15298 mq->assoc_qid = cq->queue_id;
15299 mq->subtype = subtype;
15300 mq->host_index = 0;
15303 /* link the mq onto the parent cq child list */
15304 list_add_tail(&mq->list, &cq->child_list);
15306 mempool_free(mbox, phba->mbox_mem_pool);
15311 * lpfc_wq_create - Create a Work Queue on the HBA
15312 * @phba: HBA structure that indicates port to create a queue on.
15313 * @wq: The queue structure to use to create the work queue.
15314 * @cq: The completion queue to bind this work queue to.
15315 * @subtype: The subtype of the work queue indicating its functionality.
15317 * This function creates a work queue, as detailed in @wq, on a port, described
15318 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
15320 * The @phba struct is used to send mailbox command to HBA. The @wq struct
15321 * is used to get the entry count and entry size that are necessary to
15322 * determine the number of pages to allocate and use for this queue. The @cq
15323 * is used to indicate which completion queue to bind this work queue to. This
15324 * function will send the WQ_CREATE mailbox command to the HBA to setup the
15325 * work queue. This function is asynchronous and will wait for the mailbox
15326 * command to finish before continuing.
15328 * On success this function will return a zero. If unable to allocate enough
15329 * memory this function will return -ENOMEM. If the queue create mailbox command
15330 * fails this function will return -ENXIO.
15333 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
15334 struct lpfc_queue *cq, uint32_t subtype)
15336 struct lpfc_mbx_wq_create *wq_create;
15337 struct lpfc_dmabuf *dmabuf;
15338 LPFC_MBOXQ_t *mbox;
15339 int rc, length, status = 0;
15340 uint32_t shdr_status, shdr_add_status;
15341 union lpfc_sli4_cfg_shdr *shdr;
15342 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15343 struct dma_address *page;
15344 void __iomem *bar_memmap_p;
15345 uint32_t db_offset;
15346 uint16_t pci_barset;
15347 uint8_t dpp_barset;
15348 uint32_t dpp_offset;
15349 unsigned long pg_addr;
15350 uint8_t wq_create_version;
15352 /* sanity check on queue memory */
15355 if (!phba->sli4_hba.pc_sli4_params.supported)
15356 hw_page_size = wq->page_size;
15358 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15361 length = (sizeof(struct lpfc_mbx_wq_create) -
15362 sizeof(struct lpfc_sli4_cfg_mhdr));
15363 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15364 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
15365 length, LPFC_SLI4_MBX_EMBED);
15366 wq_create = &mbox->u.mqe.un.wq_create;
15367 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
15368 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
15370 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
15373 /* wqv is the earliest version supported, NOT the latest */
15374 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15375 phba->sli4_hba.pc_sli4_params.wqv);
15377 if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
15378 (wq->page_size > SLI4_PAGE_SIZE))
15379 wq_create_version = LPFC_Q_CREATE_VERSION_1;
15381 wq_create_version = LPFC_Q_CREATE_VERSION_0;
15384 if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT)
15385 wq_create_version = LPFC_Q_CREATE_VERSION_1;
15387 wq_create_version = LPFC_Q_CREATE_VERSION_0;
15389 switch (wq_create_version) {
15390 case LPFC_Q_CREATE_VERSION_1:
15391 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
15393 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15394 LPFC_Q_CREATE_VERSION_1);
15396 switch (wq->entry_size) {
15399 bf_set(lpfc_mbx_wq_create_wqe_size,
15400 &wq_create->u.request_1,
15401 LPFC_WQ_WQE_SIZE_64);
15404 bf_set(lpfc_mbx_wq_create_wqe_size,
15405 &wq_create->u.request_1,
15406 LPFC_WQ_WQE_SIZE_128);
15409 /* Request DPP by default */
15410 bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
15411 bf_set(lpfc_mbx_wq_create_page_size,
15412 &wq_create->u.request_1,
15413 (wq->page_size / SLI4_PAGE_SIZE));
15414 page = wq_create->u.request_1.page;
15417 page = wq_create->u.request.page;
15421 list_for_each_entry(dmabuf, &wq->page_list, list) {
15422 memset(dmabuf->virt, 0, hw_page_size);
15423 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
15424 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
15427 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
15428 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
15430 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15431 /* The IOCTL status is embedded in the mailbox subheader. */
15432 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15433 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15434 if (shdr_status || shdr_add_status || rc) {
15435 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15436 "2503 WQ_CREATE mailbox failed with "
15437 "status x%x add_status x%x, mbx status x%x\n",
15438 shdr_status, shdr_add_status, rc);
15443 if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
15444 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
15445 &wq_create->u.response);
15447 wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
15448 &wq_create->u.response_1);
15450 if (wq->queue_id == 0xFFFF) {
15455 wq->db_format = LPFC_DB_LIST_FORMAT;
15456 if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
15457 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
15458 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
15459 &wq_create->u.response);
15460 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
15461 (wq->db_format != LPFC_DB_RING_FORMAT)) {
15462 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15463 "3265 WQ[%d] doorbell format "
15464 "not supported: x%x\n",
15465 wq->queue_id, wq->db_format);
15469 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
15470 &wq_create->u.response);
15471 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
15473 if (!bar_memmap_p) {
15474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15475 "3263 WQ[%d] failed to memmap "
15476 "pci barset:x%x\n",
15477 wq->queue_id, pci_barset);
15481 db_offset = wq_create->u.response.doorbell_offset;
15482 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
15483 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
15484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15485 "3252 WQ[%d] doorbell offset "
15486 "not supported: x%x\n",
15487 wq->queue_id, db_offset);
15491 wq->db_regaddr = bar_memmap_p + db_offset;
15492 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15493 "3264 WQ[%d]: barset:x%x, offset:x%x, "
15494 "format:x%x\n", wq->queue_id,
15495 pci_barset, db_offset, wq->db_format);
15497 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
15499 /* Check if DPP was honored by the firmware */
15500 wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
15501 &wq_create->u.response_1);
15502 if (wq->dpp_enable) {
15503 pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
15504 &wq_create->u.response_1);
15505 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
15507 if (!bar_memmap_p) {
15508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15509 "3267 WQ[%d] failed to memmap "
15510 "pci barset:x%x\n",
15511 wq->queue_id, pci_barset);
15515 db_offset = wq_create->u.response_1.doorbell_offset;
15516 wq->db_regaddr = bar_memmap_p + db_offset;
15517 wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
15518 &wq_create->u.response_1);
15519 dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
15520 &wq_create->u.response_1);
15521 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
15523 if (!bar_memmap_p) {
15524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15525 "3268 WQ[%d] failed to memmap "
15526 "pci barset:x%x\n",
15527 wq->queue_id, dpp_barset);
15531 dpp_offset = wq_create->u.response_1.dpp_offset;
15532 wq->dpp_regaddr = bar_memmap_p + dpp_offset;
15533 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15534 "3271 WQ[%d]: barset:x%x, offset:x%x, "
15535 "dpp_id:x%x dpp_barset:x%x "
15536 "dpp_offset:x%x\n",
15537 wq->queue_id, pci_barset, db_offset,
15538 wq->dpp_id, dpp_barset, dpp_offset);
15540 /* Enable combined writes for DPP aperture */
15541 pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
15543 rc = set_memory_wc(pg_addr, 1);
15545 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15546 "3272 Cannot setup Combined "
15547 "Write on WQ[%d] - disable DPP\n",
15549 phba->cfg_enable_dpp = 0;
15552 phba->cfg_enable_dpp = 0;
15555 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
15557 wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
15558 if (wq->pring == NULL) {
15562 wq->type = LPFC_WQ;
15563 wq->assoc_qid = cq->queue_id;
15564 wq->subtype = subtype;
15565 wq->host_index = 0;
15567 wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
15569 /* link the wq onto the parent cq child list */
15570 list_add_tail(&wq->list, &cq->child_list);
15572 mempool_free(mbox, phba->mbox_mem_pool);
15577 * lpfc_rq_create - Create a Receive Queue on the HBA
15578 * @phba: HBA structure that indicates port to create a queue on.
15579 * @hrq: The queue structure to use to create the header receive queue.
15580 * @drq: The queue structure to use to create the data receive queue.
15581 * @cq: The completion queue to bind this work queue to.
15583 * This function creates a receive buffer queue pair , as detailed in @hrq and
15584 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15587 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15588 * struct is used to get the entry count that is necessary to determine the
15589 * number of pages to use for this queue. The @cq is used to indicate which
15590 * completion queue to bind received buffers that are posted to these queues to.
15591 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15592 * receive queue pair. This function is asynchronous and will wait for the
15593 * mailbox command to finish before continuing.
15595 * On success this function will return a zero. If unable to allocate enough
15596 * memory this function will return -ENOMEM. If the queue create mailbox command
15597 * fails this function will return -ENXIO.
15600 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
15601 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
15603 struct lpfc_mbx_rq_create *rq_create;
15604 struct lpfc_dmabuf *dmabuf;
15605 LPFC_MBOXQ_t *mbox;
15606 int rc, length, status = 0;
15607 uint32_t shdr_status, shdr_add_status;
15608 union lpfc_sli4_cfg_shdr *shdr;
15609 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15610 void __iomem *bar_memmap_p;
15611 uint32_t db_offset;
15612 uint16_t pci_barset;
15614 /* sanity check on queue memory */
15615 if (!hrq || !drq || !cq)
15617 if (!phba->sli4_hba.pc_sli4_params.supported)
15618 hw_page_size = SLI4_PAGE_SIZE;
15620 if (hrq->entry_count != drq->entry_count)
15622 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15625 length = (sizeof(struct lpfc_mbx_rq_create) -
15626 sizeof(struct lpfc_sli4_cfg_mhdr));
15627 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15628 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
15629 length, LPFC_SLI4_MBX_EMBED);
15630 rq_create = &mbox->u.mqe.un.rq_create;
15631 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
15632 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15633 phba->sli4_hba.pc_sli4_params.rqv);
15634 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
15635 bf_set(lpfc_rq_context_rqe_count_1,
15636 &rq_create->u.request.context,
15638 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
15639 bf_set(lpfc_rq_context_rqe_size,
15640 &rq_create->u.request.context,
15642 bf_set(lpfc_rq_context_page_size,
15643 &rq_create->u.request.context,
15644 LPFC_RQ_PAGE_SIZE_4096);
15646 switch (hrq->entry_count) {
15648 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15649 "2535 Unsupported RQ count. (%d)\n",
15651 if (hrq->entry_count < 512) {
15655 /* fall through - otherwise default to smallest count */
15657 bf_set(lpfc_rq_context_rqe_count,
15658 &rq_create->u.request.context,
15659 LPFC_RQ_RING_SIZE_512);
15662 bf_set(lpfc_rq_context_rqe_count,
15663 &rq_create->u.request.context,
15664 LPFC_RQ_RING_SIZE_1024);
15667 bf_set(lpfc_rq_context_rqe_count,
15668 &rq_create->u.request.context,
15669 LPFC_RQ_RING_SIZE_2048);
15672 bf_set(lpfc_rq_context_rqe_count,
15673 &rq_create->u.request.context,
15674 LPFC_RQ_RING_SIZE_4096);
15677 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
15678 LPFC_HDR_BUF_SIZE);
15680 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
15682 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
15684 list_for_each_entry(dmabuf, &hrq->page_list, list) {
15685 memset(dmabuf->virt, 0, hw_page_size);
15686 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15687 putPaddrLow(dmabuf->phys);
15688 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15689 putPaddrHigh(dmabuf->phys);
15691 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
15692 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
15694 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15695 /* The IOCTL status is embedded in the mailbox subheader. */
15696 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15697 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15698 if (shdr_status || shdr_add_status || rc) {
15699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15700 "2504 RQ_CREATE mailbox failed with "
15701 "status x%x add_status x%x, mbx status x%x\n",
15702 shdr_status, shdr_add_status, rc);
15706 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
15707 if (hrq->queue_id == 0xFFFF) {
15712 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
15713 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
15714 &rq_create->u.response);
15715 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
15716 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
15717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15718 "3262 RQ [%d] doorbell format not "
15719 "supported: x%x\n", hrq->queue_id,
15725 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
15726 &rq_create->u.response);
15727 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
15728 if (!bar_memmap_p) {
15729 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15730 "3269 RQ[%d] failed to memmap pci "
15731 "barset:x%x\n", hrq->queue_id,
15737 db_offset = rq_create->u.response.doorbell_offset;
15738 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
15739 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
15740 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15741 "3270 RQ[%d] doorbell offset not "
15742 "supported: x%x\n", hrq->queue_id,
15747 hrq->db_regaddr = bar_memmap_p + db_offset;
15748 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15749 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
15750 "format:x%x\n", hrq->queue_id, pci_barset,
15751 db_offset, hrq->db_format);
15753 hrq->db_format = LPFC_DB_RING_FORMAT;
15754 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
15756 hrq->type = LPFC_HRQ;
15757 hrq->assoc_qid = cq->queue_id;
15758 hrq->subtype = subtype;
15759 hrq->host_index = 0;
15760 hrq->hba_index = 0;
15761 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
15763 /* now create the data queue */
15764 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15765 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
15766 length, LPFC_SLI4_MBX_EMBED);
15767 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15768 phba->sli4_hba.pc_sli4_params.rqv);
15769 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
15770 bf_set(lpfc_rq_context_rqe_count_1,
15771 &rq_create->u.request.context, hrq->entry_count);
15772 if (subtype == LPFC_NVMET)
15773 rq_create->u.request.context.buffer_size =
15774 LPFC_NVMET_DATA_BUF_SIZE;
15776 rq_create->u.request.context.buffer_size =
15777 LPFC_DATA_BUF_SIZE;
15778 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
15780 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
15781 (PAGE_SIZE/SLI4_PAGE_SIZE));
15783 switch (drq->entry_count) {
15785 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15786 "2536 Unsupported RQ count. (%d)\n",
15788 if (drq->entry_count < 512) {
15792 /* fall through - otherwise default to smallest count */
15794 bf_set(lpfc_rq_context_rqe_count,
15795 &rq_create->u.request.context,
15796 LPFC_RQ_RING_SIZE_512);
15799 bf_set(lpfc_rq_context_rqe_count,
15800 &rq_create->u.request.context,
15801 LPFC_RQ_RING_SIZE_1024);
15804 bf_set(lpfc_rq_context_rqe_count,
15805 &rq_create->u.request.context,
15806 LPFC_RQ_RING_SIZE_2048);
15809 bf_set(lpfc_rq_context_rqe_count,
15810 &rq_create->u.request.context,
15811 LPFC_RQ_RING_SIZE_4096);
15814 if (subtype == LPFC_NVMET)
15815 bf_set(lpfc_rq_context_buf_size,
15816 &rq_create->u.request.context,
15817 LPFC_NVMET_DATA_BUF_SIZE);
15819 bf_set(lpfc_rq_context_buf_size,
15820 &rq_create->u.request.context,
15821 LPFC_DATA_BUF_SIZE);
15823 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
15825 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
15827 list_for_each_entry(dmabuf, &drq->page_list, list) {
15828 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15829 putPaddrLow(dmabuf->phys);
15830 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15831 putPaddrHigh(dmabuf->phys);
15833 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
15834 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
15835 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15836 /* The IOCTL status is embedded in the mailbox subheader. */
15837 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
15838 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15839 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15840 if (shdr_status || shdr_add_status || rc) {
15844 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
15845 if (drq->queue_id == 0xFFFF) {
15849 drq->type = LPFC_DRQ;
15850 drq->assoc_qid = cq->queue_id;
15851 drq->subtype = subtype;
15852 drq->host_index = 0;
15853 drq->hba_index = 0;
15854 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
15856 /* link the header and data RQs onto the parent cq child list */
15857 list_add_tail(&hrq->list, &cq->child_list);
15858 list_add_tail(&drq->list, &cq->child_list);
15861 mempool_free(mbox, phba->mbox_mem_pool);
15866 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
15867 * @phba: HBA structure that indicates port to create a queue on.
15868 * @hrqp: The queue structure array to use to create the header receive queues.
15869 * @drqp: The queue structure array to use to create the data receive queues.
15870 * @cqp: The completion queue array to bind these receive queues to.
15872 * This function creates a receive buffer queue pair , as detailed in @hrq and
15873 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15876 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15877 * struct is used to get the entry count that is necessary to determine the
15878 * number of pages to use for this queue. The @cq is used to indicate which
15879 * completion queue to bind received buffers that are posted to these queues to.
15880 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15881 * receive queue pair. This function is asynchronous and will wait for the
15882 * mailbox command to finish before continuing.
15884 * On success this function will return a zero. If unable to allocate enough
15885 * memory this function will return -ENOMEM. If the queue create mailbox command
15886 * fails this function will return -ENXIO.
15889 lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
15890 struct lpfc_queue **drqp, struct lpfc_queue **cqp,
15893 struct lpfc_queue *hrq, *drq, *cq;
15894 struct lpfc_mbx_rq_create_v2 *rq_create;
15895 struct lpfc_dmabuf *dmabuf;
15896 LPFC_MBOXQ_t *mbox;
15897 int rc, length, alloclen, status = 0;
15898 int cnt, idx, numrq, page_idx = 0;
15899 uint32_t shdr_status, shdr_add_status;
15900 union lpfc_sli4_cfg_shdr *shdr;
15901 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15903 numrq = phba->cfg_nvmet_mrq;
15904 /* sanity check on array memory */
15905 if (!hrqp || !drqp || !cqp || !numrq)
15907 if (!phba->sli4_hba.pc_sli4_params.supported)
15908 hw_page_size = SLI4_PAGE_SIZE;
15910 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15914 length = sizeof(struct lpfc_mbx_rq_create_v2);
15915 length += ((2 * numrq * hrqp[0]->page_count) *
15916 sizeof(struct dma_address));
15918 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15919 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
15920 LPFC_SLI4_MBX_NEMBED);
15921 if (alloclen < length) {
15922 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15923 "3099 Allocated DMA memory size (%d) is "
15924 "less than the requested DMA memory size "
15925 "(%d)\n", alloclen, length);
15932 rq_create = mbox->sge_array->addr[0];
15933 shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
15935 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
15938 for (idx = 0; idx < numrq; idx++) {
15943 /* sanity check on queue memory */
15944 if (!hrq || !drq || !cq) {
15949 if (hrq->entry_count != drq->entry_count) {
15955 bf_set(lpfc_mbx_rq_create_num_pages,
15956 &rq_create->u.request,
15958 bf_set(lpfc_mbx_rq_create_rq_cnt,
15959 &rq_create->u.request, (numrq * 2));
15960 bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
15962 bf_set(lpfc_rq_context_base_cq,
15963 &rq_create->u.request.context,
15965 bf_set(lpfc_rq_context_data_size,
15966 &rq_create->u.request.context,
15967 LPFC_NVMET_DATA_BUF_SIZE);
15968 bf_set(lpfc_rq_context_hdr_size,
15969 &rq_create->u.request.context,
15970 LPFC_HDR_BUF_SIZE);
15971 bf_set(lpfc_rq_context_rqe_count_1,
15972 &rq_create->u.request.context,
15974 bf_set(lpfc_rq_context_rqe_size,
15975 &rq_create->u.request.context,
15977 bf_set(lpfc_rq_context_page_size,
15978 &rq_create->u.request.context,
15979 (PAGE_SIZE/SLI4_PAGE_SIZE));
15982 list_for_each_entry(dmabuf, &hrq->page_list, list) {
15983 memset(dmabuf->virt, 0, hw_page_size);
15984 cnt = page_idx + dmabuf->buffer_tag;
15985 rq_create->u.request.page[cnt].addr_lo =
15986 putPaddrLow(dmabuf->phys);
15987 rq_create->u.request.page[cnt].addr_hi =
15988 putPaddrHigh(dmabuf->phys);
15994 list_for_each_entry(dmabuf, &drq->page_list, list) {
15995 memset(dmabuf->virt, 0, hw_page_size);
15996 cnt = page_idx + dmabuf->buffer_tag;
15997 rq_create->u.request.page[cnt].addr_lo =
15998 putPaddrLow(dmabuf->phys);
15999 rq_create->u.request.page[cnt].addr_hi =
16000 putPaddrHigh(dmabuf->phys);
16005 hrq->db_format = LPFC_DB_RING_FORMAT;
16006 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16007 hrq->type = LPFC_HRQ;
16008 hrq->assoc_qid = cq->queue_id;
16009 hrq->subtype = subtype;
16010 hrq->host_index = 0;
16011 hrq->hba_index = 0;
16012 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16014 drq->db_format = LPFC_DB_RING_FORMAT;
16015 drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16016 drq->type = LPFC_DRQ;
16017 drq->assoc_qid = cq->queue_id;
16018 drq->subtype = subtype;
16019 drq->host_index = 0;
16020 drq->hba_index = 0;
16021 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16023 list_add_tail(&hrq->list, &cq->child_list);
16024 list_add_tail(&drq->list, &cq->child_list);
16027 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16028 /* The IOCTL status is embedded in the mailbox subheader. */
16029 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16030 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16031 if (shdr_status || shdr_add_status || rc) {
16032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16033 "3120 RQ_CREATE mailbox failed with "
16034 "status x%x add_status x%x, mbx status x%x\n",
16035 shdr_status, shdr_add_status, rc);
16039 rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16040 if (rc == 0xFFFF) {
16045 /* Initialize all RQs with associated queue id */
16046 for (idx = 0; idx < numrq; idx++) {
16048 hrq->queue_id = rc + (2 * idx);
16050 drq->queue_id = rc + (2 * idx) + 1;
16054 lpfc_sli4_mbox_cmd_free(phba, mbox);
16059 * lpfc_eq_destroy - Destroy an event Queue on the HBA
16060 * @eq: The queue structure associated with the queue to destroy.
16062 * This function destroys a queue, as detailed in @eq by sending an mailbox
16063 * command, specific to the type of queue, to the HBA.
16065 * The @eq struct is used to get the queue ID of the queue to destroy.
16067 * On success this function will return a zero. If the queue destroy mailbox
16068 * command fails this function will return -ENXIO.
16071 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
16073 LPFC_MBOXQ_t *mbox;
16074 int rc, length, status = 0;
16075 uint32_t shdr_status, shdr_add_status;
16076 union lpfc_sli4_cfg_shdr *shdr;
16078 /* sanity check on queue memory */
16082 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
16085 length = (sizeof(struct lpfc_mbx_eq_destroy) -
16086 sizeof(struct lpfc_sli4_cfg_mhdr));
16087 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16088 LPFC_MBOX_OPCODE_EQ_DESTROY,
16089 length, LPFC_SLI4_MBX_EMBED);
16090 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
16092 mbox->vport = eq->phba->pport;
16093 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16095 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
16096 /* The IOCTL status is embedded in the mailbox subheader. */
16097 shdr = (union lpfc_sli4_cfg_shdr *)
16098 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
16099 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16100 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16101 if (shdr_status || shdr_add_status || rc) {
16102 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16103 "2505 EQ_DESTROY mailbox failed with "
16104 "status x%x add_status x%x, mbx status x%x\n",
16105 shdr_status, shdr_add_status, rc);
16109 /* Remove eq from any list */
16110 list_del_init(&eq->list);
16111 mempool_free(mbox, eq->phba->mbox_mem_pool);
16116 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
16117 * @cq: The queue structure associated with the queue to destroy.
16119 * This function destroys a queue, as detailed in @cq by sending an mailbox
16120 * command, specific to the type of queue, to the HBA.
16122 * The @cq struct is used to get the queue ID of the queue to destroy.
16124 * On success this function will return a zero. If the queue destroy mailbox
16125 * command fails this function will return -ENXIO.
16128 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
16130 LPFC_MBOXQ_t *mbox;
16131 int rc, length, status = 0;
16132 uint32_t shdr_status, shdr_add_status;
16133 union lpfc_sli4_cfg_shdr *shdr;
16135 /* sanity check on queue memory */
16138 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
16141 length = (sizeof(struct lpfc_mbx_cq_destroy) -
16142 sizeof(struct lpfc_sli4_cfg_mhdr));
16143 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16144 LPFC_MBOX_OPCODE_CQ_DESTROY,
16145 length, LPFC_SLI4_MBX_EMBED);
16146 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
16148 mbox->vport = cq->phba->pport;
16149 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16150 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
16151 /* The IOCTL status is embedded in the mailbox subheader. */
16152 shdr = (union lpfc_sli4_cfg_shdr *)
16153 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
16154 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16155 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16156 if (shdr_status || shdr_add_status || rc) {
16157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16158 "2506 CQ_DESTROY mailbox failed with "
16159 "status x%x add_status x%x, mbx status x%x\n",
16160 shdr_status, shdr_add_status, rc);
16163 /* Remove cq from any list */
16164 list_del_init(&cq->list);
16165 mempool_free(mbox, cq->phba->mbox_mem_pool);
16170 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
16171 * @qm: The queue structure associated with the queue to destroy.
16173 * This function destroys a queue, as detailed in @mq by sending an mailbox
16174 * command, specific to the type of queue, to the HBA.
16176 * The @mq struct is used to get the queue ID of the queue to destroy.
16178 * On success this function will return a zero. If the queue destroy mailbox
16179 * command fails this function will return -ENXIO.
16182 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
16184 LPFC_MBOXQ_t *mbox;
16185 int rc, length, status = 0;
16186 uint32_t shdr_status, shdr_add_status;
16187 union lpfc_sli4_cfg_shdr *shdr;
16189 /* sanity check on queue memory */
16192 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
16195 length = (sizeof(struct lpfc_mbx_mq_destroy) -
16196 sizeof(struct lpfc_sli4_cfg_mhdr));
16197 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16198 LPFC_MBOX_OPCODE_MQ_DESTROY,
16199 length, LPFC_SLI4_MBX_EMBED);
16200 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
16202 mbox->vport = mq->phba->pport;
16203 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16204 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
16205 /* The IOCTL status is embedded in the mailbox subheader. */
16206 shdr = (union lpfc_sli4_cfg_shdr *)
16207 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
16208 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16209 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16210 if (shdr_status || shdr_add_status || rc) {
16211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16212 "2507 MQ_DESTROY mailbox failed with "
16213 "status x%x add_status x%x, mbx status x%x\n",
16214 shdr_status, shdr_add_status, rc);
16217 /* Remove mq from any list */
16218 list_del_init(&mq->list);
16219 mempool_free(mbox, mq->phba->mbox_mem_pool);
16224 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
16225 * @wq: The queue structure associated with the queue to destroy.
16227 * This function destroys a queue, as detailed in @wq by sending an mailbox
16228 * command, specific to the type of queue, to the HBA.
16230 * The @wq struct is used to get the queue ID of the queue to destroy.
16232 * On success this function will return a zero. If the queue destroy mailbox
16233 * command fails this function will return -ENXIO.
16236 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
16238 LPFC_MBOXQ_t *mbox;
16239 int rc, length, status = 0;
16240 uint32_t shdr_status, shdr_add_status;
16241 union lpfc_sli4_cfg_shdr *shdr;
16243 /* sanity check on queue memory */
16246 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
16249 length = (sizeof(struct lpfc_mbx_wq_destroy) -
16250 sizeof(struct lpfc_sli4_cfg_mhdr));
16251 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16252 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
16253 length, LPFC_SLI4_MBX_EMBED);
16254 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
16256 mbox->vport = wq->phba->pport;
16257 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16258 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
16259 shdr = (union lpfc_sli4_cfg_shdr *)
16260 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
16261 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16262 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16263 if (shdr_status || shdr_add_status || rc) {
16264 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16265 "2508 WQ_DESTROY mailbox failed with "
16266 "status x%x add_status x%x, mbx status x%x\n",
16267 shdr_status, shdr_add_status, rc);
16270 /* Remove wq from any list */
16271 list_del_init(&wq->list);
16274 mempool_free(mbox, wq->phba->mbox_mem_pool);
16279 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
16280 * @rq: The queue structure associated with the queue to destroy.
16282 * This function destroys a queue, as detailed in @rq by sending an mailbox
16283 * command, specific to the type of queue, to the HBA.
16285 * The @rq struct is used to get the queue ID of the queue to destroy.
16287 * On success this function will return a zero. If the queue destroy mailbox
16288 * command fails this function will return -ENXIO.
16291 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
16292 struct lpfc_queue *drq)
16294 LPFC_MBOXQ_t *mbox;
16295 int rc, length, status = 0;
16296 uint32_t shdr_status, shdr_add_status;
16297 union lpfc_sli4_cfg_shdr *shdr;
16299 /* sanity check on queue memory */
16302 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
16305 length = (sizeof(struct lpfc_mbx_rq_destroy) -
16306 sizeof(struct lpfc_sli4_cfg_mhdr));
16307 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16308 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
16309 length, LPFC_SLI4_MBX_EMBED);
16310 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
16312 mbox->vport = hrq->phba->pport;
16313 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16314 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
16315 /* The IOCTL status is embedded in the mailbox subheader. */
16316 shdr = (union lpfc_sli4_cfg_shdr *)
16317 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
16318 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16319 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16320 if (shdr_status || shdr_add_status || rc) {
16321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16322 "2509 RQ_DESTROY mailbox failed with "
16323 "status x%x add_status x%x, mbx status x%x\n",
16324 shdr_status, shdr_add_status, rc);
16325 if (rc != MBX_TIMEOUT)
16326 mempool_free(mbox, hrq->phba->mbox_mem_pool);
16329 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
16331 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
16332 shdr = (union lpfc_sli4_cfg_shdr *)
16333 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
16334 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16335 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16336 if (shdr_status || shdr_add_status || rc) {
16337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16338 "2510 RQ_DESTROY mailbox failed with "
16339 "status x%x add_status x%x, mbx status x%x\n",
16340 shdr_status, shdr_add_status, rc);
16343 list_del_init(&hrq->list);
16344 list_del_init(&drq->list);
16345 mempool_free(mbox, hrq->phba->mbox_mem_pool);
16350 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
16351 * @phba: The virtual port for which this call being executed.
16352 * @pdma_phys_addr0: Physical address of the 1st SGL page.
16353 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
16354 * @xritag: the xritag that ties this io to the SGL pages.
16356 * This routine will post the sgl pages for the IO that has the xritag
16357 * that is in the iocbq structure. The xritag is assigned during iocbq
16358 * creation and persists for as long as the driver is loaded.
16359 * if the caller has fewer than 256 scatter gather segments to map then
16360 * pdma_phys_addr1 should be 0.
16361 * If the caller needs to map more than 256 scatter gather segment then
16362 * pdma_phys_addr1 should be a valid physical address.
16363 * physical address for SGLs must be 64 byte aligned.
16364 * If you are going to map 2 SGL's then the first one must have 256 entries
16365 * the second sgl can have between 1 and 256 entries.
16369 * -ENXIO, -ENOMEM - Failure
16372 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
16373 dma_addr_t pdma_phys_addr0,
16374 dma_addr_t pdma_phys_addr1,
16377 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
16378 LPFC_MBOXQ_t *mbox;
16380 uint32_t shdr_status, shdr_add_status;
16382 union lpfc_sli4_cfg_shdr *shdr;
16384 if (xritag == NO_XRI) {
16385 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16386 "0364 Invalid param:\n");
16390 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16394 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16395 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
16396 sizeof(struct lpfc_mbx_post_sgl_pages) -
16397 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
16399 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
16400 &mbox->u.mqe.un.post_sgl_pages;
16401 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
16402 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
16404 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
16405 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
16406 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
16407 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
16409 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
16410 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
16411 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
16412 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
16413 if (!phba->sli4_hba.intr_enable)
16414 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16416 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
16417 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
16419 /* The IOCTL status is embedded in the mailbox subheader. */
16420 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
16421 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16422 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16423 if (rc != MBX_TIMEOUT)
16424 mempool_free(mbox, phba->mbox_mem_pool);
16425 if (shdr_status || shdr_add_status || rc) {
16426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16427 "2511 POST_SGL mailbox failed with "
16428 "status x%x add_status x%x, mbx status x%x\n",
16429 shdr_status, shdr_add_status, rc);
16435 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
16436 * @phba: pointer to lpfc hba data structure.
16438 * This routine is invoked to post rpi header templates to the
16439 * HBA consistent with the SLI-4 interface spec. This routine
16440 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
16441 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
16444 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
16445 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
16448 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
16453 * Fetch the next logical xri. Because this index is logical,
16454 * the driver starts at 0 each time.
16456 spin_lock_irq(&phba->hbalock);
16457 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
16458 phba->sli4_hba.max_cfg_param.max_xri, 0);
16459 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
16460 spin_unlock_irq(&phba->hbalock);
16463 set_bit(xri, phba->sli4_hba.xri_bmask);
16464 phba->sli4_hba.max_cfg_param.xri_used++;
16466 spin_unlock_irq(&phba->hbalock);
16471 * lpfc_sli4_free_xri - Release an xri for reuse.
16472 * @phba: pointer to lpfc hba data structure.
16474 * This routine is invoked to release an xri to the pool of
16475 * available rpis maintained by the driver.
16478 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
16480 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
16481 phba->sli4_hba.max_cfg_param.xri_used--;
16486 * lpfc_sli4_free_xri - Release an xri for reuse.
16487 * @phba: pointer to lpfc hba data structure.
16489 * This routine is invoked to release an xri to the pool of
16490 * available rpis maintained by the driver.
16493 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
16495 spin_lock_irq(&phba->hbalock);
16496 __lpfc_sli4_free_xri(phba, xri);
16497 spin_unlock_irq(&phba->hbalock);
16501 * lpfc_sli4_next_xritag - Get an xritag for the io
16502 * @phba: Pointer to HBA context object.
16504 * This function gets an xritag for the iocb. If there is no unused xritag
16505 * it will return 0xffff.
16506 * The function returns the allocated xritag if successful, else returns zero.
16507 * Zero is not a valid xritag.
16508 * The caller is not required to hold any lock.
16511 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
16513 uint16_t xri_index;
16515 xri_index = lpfc_sli4_alloc_xri(phba);
16516 if (xri_index == NO_XRI)
16517 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
16518 "2004 Failed to allocate XRI.last XRITAG is %d"
16519 " Max XRI is %d, Used XRI is %d\n",
16521 phba->sli4_hba.max_cfg_param.max_xri,
16522 phba->sli4_hba.max_cfg_param.xri_used);
16527 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
16528 * @phba: pointer to lpfc hba data structure.
16529 * @post_sgl_list: pointer to els sgl entry list.
16530 * @count: number of els sgl entries on the list.
16532 * This routine is invoked to post a block of driver's sgl pages to the
16533 * HBA using non-embedded mailbox command. No Lock is held. This routine
16534 * is only called when the driver is loading and after all IO has been
16538 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
16539 struct list_head *post_sgl_list,
16542 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
16543 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
16544 struct sgl_page_pairs *sgl_pg_pairs;
16546 LPFC_MBOXQ_t *mbox;
16547 uint32_t reqlen, alloclen, pg_pairs;
16549 uint16_t xritag_start = 0;
16551 uint32_t shdr_status, shdr_add_status;
16552 union lpfc_sli4_cfg_shdr *shdr;
16554 reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
16555 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
16556 if (reqlen > SLI4_PAGE_SIZE) {
16557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16558 "2559 Block sgl registration required DMA "
16559 "size (%d) great than a page\n", reqlen);
16563 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16567 /* Allocate DMA memory and set up the non-embedded mailbox command */
16568 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16569 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
16570 LPFC_SLI4_MBX_NEMBED);
16572 if (alloclen < reqlen) {
16573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16574 "0285 Allocated DMA memory size (%d) is "
16575 "less than the requested DMA memory "
16576 "size (%d)\n", alloclen, reqlen);
16577 lpfc_sli4_mbox_cmd_free(phba, mbox);
16580 /* Set up the SGL pages in the non-embedded DMA pages */
16581 viraddr = mbox->sge_array->addr[0];
16582 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
16583 sgl_pg_pairs = &sgl->sgl_pg_pairs;
16586 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
16587 /* Set up the sge entry */
16588 sgl_pg_pairs->sgl_pg0_addr_lo =
16589 cpu_to_le32(putPaddrLow(sglq_entry->phys));
16590 sgl_pg_pairs->sgl_pg0_addr_hi =
16591 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
16592 sgl_pg_pairs->sgl_pg1_addr_lo =
16593 cpu_to_le32(putPaddrLow(0));
16594 sgl_pg_pairs->sgl_pg1_addr_hi =
16595 cpu_to_le32(putPaddrHigh(0));
16597 /* Keep the first xritag on the list */
16599 xritag_start = sglq_entry->sli4_xritag;
16604 /* Complete initialization and perform endian conversion. */
16605 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
16606 bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
16607 sgl->word0 = cpu_to_le32(sgl->word0);
16609 if (!phba->sli4_hba.intr_enable)
16610 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16612 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
16613 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
16615 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
16616 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16617 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16618 if (rc != MBX_TIMEOUT)
16619 lpfc_sli4_mbox_cmd_free(phba, mbox);
16620 if (shdr_status || shdr_add_status || rc) {
16621 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16622 "2513 POST_SGL_BLOCK mailbox command failed "
16623 "status x%x add_status x%x mbx status x%x\n",
16624 shdr_status, shdr_add_status, rc);
16631 * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
16632 * @phba: pointer to lpfc hba data structure.
16633 * @nblist: pointer to nvme buffer list.
16634 * @count: number of scsi buffers on the list.
16636 * This routine is invoked to post a block of @count scsi sgl pages from a
16637 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
16642 lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
16645 struct lpfc_io_buf *lpfc_ncmd;
16646 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
16647 struct sgl_page_pairs *sgl_pg_pairs;
16649 LPFC_MBOXQ_t *mbox;
16650 uint32_t reqlen, alloclen, pg_pairs;
16652 uint16_t xritag_start = 0;
16654 uint32_t shdr_status, shdr_add_status;
16655 dma_addr_t pdma_phys_bpl1;
16656 union lpfc_sli4_cfg_shdr *shdr;
16658 /* Calculate the requested length of the dma memory */
16659 reqlen = count * sizeof(struct sgl_page_pairs) +
16660 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
16661 if (reqlen > SLI4_PAGE_SIZE) {
16662 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
16663 "6118 Block sgl registration required DMA "
16664 "size (%d) great than a page\n", reqlen);
16667 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16670 "6119 Failed to allocate mbox cmd memory\n");
16674 /* Allocate DMA memory and set up the non-embedded mailbox command */
16675 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16676 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
16677 reqlen, LPFC_SLI4_MBX_NEMBED);
16679 if (alloclen < reqlen) {
16680 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16681 "6120 Allocated DMA memory size (%d) is "
16682 "less than the requested DMA memory "
16683 "size (%d)\n", alloclen, reqlen);
16684 lpfc_sli4_mbox_cmd_free(phba, mbox);
16688 /* Get the first SGE entry from the non-embedded DMA memory */
16689 viraddr = mbox->sge_array->addr[0];
16691 /* Set up the SGL pages in the non-embedded DMA pages */
16692 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
16693 sgl_pg_pairs = &sgl->sgl_pg_pairs;
16696 list_for_each_entry(lpfc_ncmd, nblist, list) {
16697 /* Set up the sge entry */
16698 sgl_pg_pairs->sgl_pg0_addr_lo =
16699 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
16700 sgl_pg_pairs->sgl_pg0_addr_hi =
16701 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
16702 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
16703 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
16706 pdma_phys_bpl1 = 0;
16707 sgl_pg_pairs->sgl_pg1_addr_lo =
16708 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
16709 sgl_pg_pairs->sgl_pg1_addr_hi =
16710 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
16711 /* Keep the first xritag on the list */
16713 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
16717 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
16718 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
16719 /* Perform endian conversion if necessary */
16720 sgl->word0 = cpu_to_le32(sgl->word0);
16722 if (!phba->sli4_hba.intr_enable) {
16723 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16725 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
16726 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
16728 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
16729 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16730 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16731 if (rc != MBX_TIMEOUT)
16732 lpfc_sli4_mbox_cmd_free(phba, mbox);
16733 if (shdr_status || shdr_add_status || rc) {
16734 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16735 "6125 POST_SGL_BLOCK mailbox command failed "
16736 "status x%x add_status x%x mbx status x%x\n",
16737 shdr_status, shdr_add_status, rc);
16744 * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
16745 * @phba: pointer to lpfc hba data structure.
16746 * @post_nblist: pointer to the nvme buffer list.
16748 * This routine walks a list of nvme buffers that was passed in. It attempts
16749 * to construct blocks of nvme buffer sgls which contains contiguous xris and
16750 * uses the non-embedded SGL block post mailbox commands to post to the port.
16751 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
16752 * embedded SGL post mailbox command for posting. The @post_nblist passed in
16753 * must be local list, thus no lock is needed when manipulate the list.
16755 * Returns: 0 = failure, non-zero number of successfully posted buffers.
16758 lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
16759 struct list_head *post_nblist, int sb_count)
16761 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
16762 int status, sgl_size;
16763 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
16764 dma_addr_t pdma_phys_sgl1;
16765 int last_xritag = NO_XRI;
16767 LIST_HEAD(prep_nblist);
16768 LIST_HEAD(blck_nblist);
16769 LIST_HEAD(nvme_nblist);
16775 sgl_size = phba->cfg_sg_dma_buf_size;
16776 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
16777 list_del_init(&lpfc_ncmd->list);
16779 if ((last_xritag != NO_XRI) &&
16780 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
16781 /* a hole in xri block, form a sgl posting block */
16782 list_splice_init(&prep_nblist, &blck_nblist);
16783 post_cnt = block_cnt - 1;
16784 /* prepare list for next posting block */
16785 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
16788 /* prepare list for next posting block */
16789 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
16790 /* enough sgls for non-embed sgl mbox command */
16791 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
16792 list_splice_init(&prep_nblist, &blck_nblist);
16793 post_cnt = block_cnt;
16798 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
16800 /* end of repost sgl list condition for NVME buffers */
16801 if (num_posting == sb_count) {
16802 if (post_cnt == 0) {
16803 /* last sgl posting block */
16804 list_splice_init(&prep_nblist, &blck_nblist);
16805 post_cnt = block_cnt;
16806 } else if (block_cnt == 1) {
16807 /* last single sgl with non-contiguous xri */
16808 if (sgl_size > SGL_PAGE_SIZE)
16810 lpfc_ncmd->dma_phys_sgl +
16813 pdma_phys_sgl1 = 0;
16814 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
16815 status = lpfc_sli4_post_sgl(
16816 phba, lpfc_ncmd->dma_phys_sgl,
16817 pdma_phys_sgl1, cur_xritag);
16819 /* Post error. Buffer unavailable. */
16820 lpfc_ncmd->flags |=
16821 LPFC_SBUF_NOT_POSTED;
16823 /* Post success. Bffer available. */
16824 lpfc_ncmd->flags &=
16825 ~LPFC_SBUF_NOT_POSTED;
16826 lpfc_ncmd->status = IOSTAT_SUCCESS;
16829 /* success, put on NVME buffer sgl list */
16830 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
16834 /* continue until a nembed page worth of sgls */
16838 /* post block of NVME buffer list sgls */
16839 status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
16842 /* don't reset xirtag due to hole in xri block */
16843 if (block_cnt == 0)
16844 last_xritag = NO_XRI;
16846 /* reset NVME buffer post count for next round of posting */
16849 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
16850 while (!list_empty(&blck_nblist)) {
16851 list_remove_head(&blck_nblist, lpfc_ncmd,
16852 struct lpfc_io_buf, list);
16854 /* Post error. Mark buffer unavailable. */
16855 lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
16857 /* Post success, Mark buffer available. */
16858 lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
16859 lpfc_ncmd->status = IOSTAT_SUCCESS;
16862 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
16865 /* Push NVME buffers with sgl posted to the available list */
16866 lpfc_io_buf_replenish(phba, &nvme_nblist);
16872 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
16873 * @phba: pointer to lpfc_hba struct that the frame was received on
16874 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16876 * This function checks the fields in the @fc_hdr to see if the FC frame is a
16877 * valid type of frame that the LPFC driver will handle. This function will
16878 * return a zero if the frame is a valid frame or a non zero value when the
16879 * frame does not pass the check.
16882 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
16884 /* make rctl_names static to save stack space */
16885 struct fc_vft_header *fc_vft_hdr;
16886 uint32_t *header = (uint32_t *) fc_hdr;
16888 #define FC_RCTL_MDS_DIAGS 0xF4
16890 switch (fc_hdr->fh_r_ctl) {
16891 case FC_RCTL_DD_UNCAT: /* uncategorized information */
16892 case FC_RCTL_DD_SOL_DATA: /* solicited data */
16893 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
16894 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
16895 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
16896 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
16897 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
16898 case FC_RCTL_DD_CMD_STATUS: /* command status */
16899 case FC_RCTL_ELS_REQ: /* extended link services request */
16900 case FC_RCTL_ELS_REP: /* extended link services reply */
16901 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
16902 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
16903 case FC_RCTL_BA_NOP: /* basic link service NOP */
16904 case FC_RCTL_BA_ABTS: /* basic link service abort */
16905 case FC_RCTL_BA_RMC: /* remove connection */
16906 case FC_RCTL_BA_ACC: /* basic accept */
16907 case FC_RCTL_BA_RJT: /* basic reject */
16908 case FC_RCTL_BA_PRMT:
16909 case FC_RCTL_ACK_1: /* acknowledge_1 */
16910 case FC_RCTL_ACK_0: /* acknowledge_0 */
16911 case FC_RCTL_P_RJT: /* port reject */
16912 case FC_RCTL_F_RJT: /* fabric reject */
16913 case FC_RCTL_P_BSY: /* port busy */
16914 case FC_RCTL_F_BSY: /* fabric busy to data frame */
16915 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
16916 case FC_RCTL_LCR: /* link credit reset */
16917 case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
16918 case FC_RCTL_END: /* end */
16920 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
16921 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
16922 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
16923 return lpfc_fc_frame_check(phba, fc_hdr);
16928 switch (fc_hdr->fh_type) {
16941 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
16942 "2538 Received frame rctl:x%x, type:x%x, "
16943 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
16944 fc_hdr->fh_r_ctl, fc_hdr->fh_type,
16945 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
16946 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
16947 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
16948 be32_to_cpu(header[6]));
16951 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
16952 "2539 Dropped frame rctl:x%x type:x%x\n",
16953 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
16958 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
16959 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16961 * This function processes the FC header to retrieve the VFI from the VF
16962 * header, if one exists. This function will return the VFI if one exists
16963 * or 0 if no VSAN Header exists.
16966 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
16968 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
16970 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
16972 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
16976 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
16977 * @phba: Pointer to the HBA structure to search for the vport on
16978 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16979 * @fcfi: The FC Fabric ID that the frame came from
16981 * This function searches the @phba for a vport that matches the content of the
16982 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
16983 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
16984 * returns the matching vport pointer or NULL if unable to match frame to a
16987 static struct lpfc_vport *
16988 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
16989 uint16_t fcfi, uint32_t did)
16991 struct lpfc_vport **vports;
16992 struct lpfc_vport *vport = NULL;
16995 if (did == Fabric_DID)
16996 return phba->pport;
16997 if ((phba->pport->fc_flag & FC_PT2PT) &&
16998 !(phba->link_state == LPFC_HBA_READY))
16999 return phba->pport;
17001 vports = lpfc_create_vport_work_array(phba);
17002 if (vports != NULL) {
17003 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
17004 if (phba->fcf.fcfi == fcfi &&
17005 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
17006 vports[i]->fc_myDID == did) {
17012 lpfc_destroy_vport_work_array(phba, vports);
17017 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
17018 * @vport: The vport to work on.
17020 * This function updates the receive sequence time stamp for this vport. The
17021 * receive sequence time stamp indicates the time that the last frame of the
17022 * the sequence that has been idle for the longest amount of time was received.
17023 * the driver uses this time stamp to indicate if any received sequences have
17027 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
17029 struct lpfc_dmabuf *h_buf;
17030 struct hbq_dmabuf *dmabuf = NULL;
17032 /* get the oldest sequence on the rcv list */
17033 h_buf = list_get_first(&vport->rcv_buffer_list,
17034 struct lpfc_dmabuf, list);
17037 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17038 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
17042 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
17043 * @vport: The vport that the received sequences were sent to.
17045 * This function cleans up all outstanding received sequences. This is called
17046 * by the driver when a link event or user action invalidates all the received
17050 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
17052 struct lpfc_dmabuf *h_buf, *hnext;
17053 struct lpfc_dmabuf *d_buf, *dnext;
17054 struct hbq_dmabuf *dmabuf = NULL;
17056 /* start with the oldest sequence on the rcv list */
17057 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
17058 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17059 list_del_init(&dmabuf->hbuf.list);
17060 list_for_each_entry_safe(d_buf, dnext,
17061 &dmabuf->dbuf.list, list) {
17062 list_del_init(&d_buf->list);
17063 lpfc_in_buf_free(vport->phba, d_buf);
17065 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
17070 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
17071 * @vport: The vport that the received sequences were sent to.
17073 * This function determines whether any received sequences have timed out by
17074 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
17075 * indicates that there is at least one timed out sequence this routine will
17076 * go through the received sequences one at a time from most inactive to most
17077 * active to determine which ones need to be cleaned up. Once it has determined
17078 * that a sequence needs to be cleaned up it will simply free up the resources
17079 * without sending an abort.
17082 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
17084 struct lpfc_dmabuf *h_buf, *hnext;
17085 struct lpfc_dmabuf *d_buf, *dnext;
17086 struct hbq_dmabuf *dmabuf = NULL;
17087 unsigned long timeout;
17088 int abort_count = 0;
17090 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
17091 vport->rcv_buffer_time_stamp);
17092 if (list_empty(&vport->rcv_buffer_list) ||
17093 time_before(jiffies, timeout))
17095 /* start with the oldest sequence on the rcv list */
17096 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
17097 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17098 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
17099 dmabuf->time_stamp);
17100 if (time_before(jiffies, timeout))
17103 list_del_init(&dmabuf->hbuf.list);
17104 list_for_each_entry_safe(d_buf, dnext,
17105 &dmabuf->dbuf.list, list) {
17106 list_del_init(&d_buf->list);
17107 lpfc_in_buf_free(vport->phba, d_buf);
17109 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
17112 lpfc_update_rcv_time_stamp(vport);
17116 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
17117 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
17119 * This function searches through the existing incomplete sequences that have
17120 * been sent to this @vport. If the frame matches one of the incomplete
17121 * sequences then the dbuf in the @dmabuf is added to the list of frames that
17122 * make up that sequence. If no sequence is found that matches this frame then
17123 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
17124 * This function returns a pointer to the first dmabuf in the sequence list that
17125 * the frame was linked to.
17127 static struct hbq_dmabuf *
17128 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
17130 struct fc_frame_header *new_hdr;
17131 struct fc_frame_header *temp_hdr;
17132 struct lpfc_dmabuf *d_buf;
17133 struct lpfc_dmabuf *h_buf;
17134 struct hbq_dmabuf *seq_dmabuf = NULL;
17135 struct hbq_dmabuf *temp_dmabuf = NULL;
17138 INIT_LIST_HEAD(&dmabuf->dbuf.list);
17139 dmabuf->time_stamp = jiffies;
17140 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17142 /* Use the hdr_buf to find the sequence that this frame belongs to */
17143 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
17144 temp_hdr = (struct fc_frame_header *)h_buf->virt;
17145 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
17146 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
17147 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
17149 /* found a pending sequence that matches this frame */
17150 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17155 * This indicates first frame received for this sequence.
17156 * Queue the buffer on the vport's rcv_buffer_list.
17158 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
17159 lpfc_update_rcv_time_stamp(vport);
17162 temp_hdr = seq_dmabuf->hbuf.virt;
17163 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
17164 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
17165 list_del_init(&seq_dmabuf->hbuf.list);
17166 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
17167 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
17168 lpfc_update_rcv_time_stamp(vport);
17171 /* move this sequence to the tail to indicate a young sequence */
17172 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
17173 seq_dmabuf->time_stamp = jiffies;
17174 lpfc_update_rcv_time_stamp(vport);
17175 if (list_empty(&seq_dmabuf->dbuf.list)) {
17176 temp_hdr = dmabuf->hbuf.virt;
17177 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
17180 /* find the correct place in the sequence to insert this frame */
17181 d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
17183 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17184 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
17186 * If the frame's sequence count is greater than the frame on
17187 * the list then insert the frame right after this frame
17189 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
17190 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
17191 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
17196 if (&d_buf->list == &seq_dmabuf->dbuf.list)
17198 d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
17207 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
17208 * @vport: pointer to a vitural port
17209 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17211 * This function tries to abort from the partially assembed sequence, described
17212 * by the information from basic abbort @dmabuf. It checks to see whether such
17213 * partially assembled sequence held by the driver. If so, it shall free up all
17214 * the frames from the partially assembled sequence.
17217 * true -- if there is matching partially assembled sequence present and all
17218 * the frames freed with the sequence;
17219 * false -- if there is no matching partially assembled sequence present so
17220 * nothing got aborted in the lower layer driver
17223 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
17224 struct hbq_dmabuf *dmabuf)
17226 struct fc_frame_header *new_hdr;
17227 struct fc_frame_header *temp_hdr;
17228 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
17229 struct hbq_dmabuf *seq_dmabuf = NULL;
17231 /* Use the hdr_buf to find the sequence that matches this frame */
17232 INIT_LIST_HEAD(&dmabuf->dbuf.list);
17233 INIT_LIST_HEAD(&dmabuf->hbuf.list);
17234 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17235 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
17236 temp_hdr = (struct fc_frame_header *)h_buf->virt;
17237 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
17238 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
17239 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
17241 /* found a pending sequence that matches this frame */
17242 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17246 /* Free up all the frames from the partially assembled sequence */
17248 list_for_each_entry_safe(d_buf, n_buf,
17249 &seq_dmabuf->dbuf.list, list) {
17250 list_del_init(&d_buf->list);
17251 lpfc_in_buf_free(vport->phba, d_buf);
17259 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
17260 * @vport: pointer to a vitural port
17261 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17263 * This function tries to abort from the assembed sequence from upper level
17264 * protocol, described by the information from basic abbort @dmabuf. It
17265 * checks to see whether such pending context exists at upper level protocol.
17266 * If so, it shall clean up the pending context.
17269 * true -- if there is matching pending context of the sequence cleaned
17271 * false -- if there is no matching pending context of the sequence present
17275 lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
17277 struct lpfc_hba *phba = vport->phba;
17280 /* Accepting abort at ulp with SLI4 only */
17281 if (phba->sli_rev < LPFC_SLI_REV4)
17284 /* Register all caring upper level protocols to attend abort */
17285 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
17293 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
17294 * @phba: Pointer to HBA context object.
17295 * @cmd_iocbq: pointer to the command iocbq structure.
17296 * @rsp_iocbq: pointer to the response iocbq structure.
17298 * This function handles the sequence abort response iocb command complete
17299 * event. It properly releases the memory allocated to the sequence abort
17303 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
17304 struct lpfc_iocbq *cmd_iocbq,
17305 struct lpfc_iocbq *rsp_iocbq)
17307 struct lpfc_nodelist *ndlp;
17310 ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
17311 lpfc_nlp_put(ndlp);
17312 lpfc_nlp_not_used(ndlp);
17313 lpfc_sli_release_iocbq(phba, cmd_iocbq);
17316 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
17317 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
17318 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17319 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
17320 rsp_iocbq->iocb.ulpStatus,
17321 rsp_iocbq->iocb.un.ulpWord[4]);
17325 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
17326 * @phba: Pointer to HBA context object.
17327 * @xri: xri id in transaction.
17329 * This function validates the xri maps to the known range of XRIs allocated an
17330 * used by the driver.
17333 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
17338 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
17339 if (xri == phba->sli4_hba.xri_ids[i])
17346 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
17347 * @phba: Pointer to HBA context object.
17348 * @fc_hdr: pointer to a FC frame header.
17350 * This function sends a basic response to a previous unsol sequence abort
17351 * event after aborting the sequence handling.
17354 lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
17355 struct fc_frame_header *fc_hdr, bool aborted)
17357 struct lpfc_hba *phba = vport->phba;
17358 struct lpfc_iocbq *ctiocb = NULL;
17359 struct lpfc_nodelist *ndlp;
17360 uint16_t oxid, rxid, xri, lxri;
17361 uint32_t sid, fctl;
17365 if (!lpfc_is_link_up(phba))
17368 sid = sli4_sid_from_fc_hdr(fc_hdr);
17369 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
17370 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
17372 ndlp = lpfc_findnode_did(vport, sid);
17374 ndlp = lpfc_nlp_init(vport, sid);
17376 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
17377 "1268 Failed to allocate ndlp for "
17378 "oxid:x%x SID:x%x\n", oxid, sid);
17381 /* Put ndlp onto pport node list */
17382 lpfc_enqueue_node(vport, ndlp);
17383 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
17384 /* re-setup ndlp without removing from node list */
17385 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
17387 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
17388 "3275 Failed to active ndlp found "
17389 "for oxid:x%x SID:x%x\n", oxid, sid);
17394 /* Allocate buffer for rsp iocb */
17395 ctiocb = lpfc_sli_get_iocbq(phba);
17399 /* Extract the F_CTL field from FC_HDR */
17400 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
17402 icmd = &ctiocb->iocb;
17403 icmd->un.xseq64.bdl.bdeSize = 0;
17404 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
17405 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
17406 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
17407 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
17409 /* Fill in the rest of iocb fields */
17410 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
17411 icmd->ulpBdeCount = 0;
17413 icmd->ulpClass = CLASS3;
17414 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
17415 ctiocb->context1 = lpfc_nlp_get(ndlp);
17417 ctiocb->vport = phba->pport;
17418 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
17419 ctiocb->sli4_lxritag = NO_XRI;
17420 ctiocb->sli4_xritag = NO_XRI;
17422 if (fctl & FC_FC_EX_CTX)
17423 /* Exchange responder sent the abort so we
17429 lxri = lpfc_sli4_xri_inrange(phba, xri);
17430 if (lxri != NO_XRI)
17431 lpfc_set_rrq_active(phba, ndlp, lxri,
17432 (xri == oxid) ? rxid : oxid, 0);
17433 /* For BA_ABTS from exchange responder, if the logical xri with
17434 * the oxid maps to the FCP XRI range, the port no longer has
17435 * that exchange context, send a BLS_RJT. Override the IOCB for
17438 if ((fctl & FC_FC_EX_CTX) &&
17439 (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
17440 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
17441 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
17442 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
17443 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
17446 /* If BA_ABTS failed to abort a partially assembled receive sequence,
17447 * the driver no longer has that exchange, send a BLS_RJT. Override
17448 * the IOCB for a BA_RJT.
17450 if (aborted == false) {
17451 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
17452 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
17453 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
17454 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
17457 if (fctl & FC_FC_EX_CTX) {
17458 /* ABTS sent by responder to CT exchange, construction
17459 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
17460 * field and RX_ID from ABTS for RX_ID field.
17462 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
17464 /* ABTS sent by initiator to CT exchange, construction
17465 * of BA_ACC will need to allocate a new XRI as for the
17468 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
17470 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
17471 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
17473 /* Xmit CT abts response on exchange <xid> */
17474 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
17475 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
17476 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
17478 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
17479 if (rc == IOCB_ERROR) {
17480 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
17481 "2925 Failed to issue CT ABTS RSP x%x on "
17482 "xri x%x, Data x%x\n",
17483 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
17485 lpfc_nlp_put(ndlp);
17486 ctiocb->context1 = NULL;
17487 lpfc_sli_release_iocbq(phba, ctiocb);
17492 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
17493 * @vport: Pointer to the vport on which this sequence was received
17494 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17496 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
17497 * receive sequence is only partially assembed by the driver, it shall abort
17498 * the partially assembled frames for the sequence. Otherwise, if the
17499 * unsolicited receive sequence has been completely assembled and passed to
17500 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
17501 * unsolicited sequence has been aborted. After that, it will issue a basic
17502 * accept to accept the abort.
17505 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
17506 struct hbq_dmabuf *dmabuf)
17508 struct lpfc_hba *phba = vport->phba;
17509 struct fc_frame_header fc_hdr;
17513 /* Make a copy of fc_hdr before the dmabuf being released */
17514 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
17515 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
17517 if (fctl & FC_FC_EX_CTX) {
17518 /* ABTS by responder to exchange, no cleanup needed */
17521 /* ABTS by initiator to exchange, need to do cleanup */
17522 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
17523 if (aborted == false)
17524 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
17526 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17528 if (phba->nvmet_support) {
17529 lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
17533 /* Respond with BA_ACC or BA_RJT accordingly */
17534 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
17538 * lpfc_seq_complete - Indicates if a sequence is complete
17539 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17541 * This function checks the sequence, starting with the frame described by
17542 * @dmabuf, to see if all the frames associated with this sequence are present.
17543 * the frames associated with this sequence are linked to the @dmabuf using the
17544 * dbuf list. This function looks for two major things. 1) That the first frame
17545 * has a sequence count of zero. 2) There is a frame with last frame of sequence
17546 * set. 3) That there are no holes in the sequence count. The function will
17547 * return 1 when the sequence is complete, otherwise it will return 0.
17550 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
17552 struct fc_frame_header *hdr;
17553 struct lpfc_dmabuf *d_buf;
17554 struct hbq_dmabuf *seq_dmabuf;
17558 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17559 /* make sure first fame of sequence has a sequence count of zero */
17560 if (hdr->fh_seq_cnt != seq_count)
17562 fctl = (hdr->fh_f_ctl[0] << 16 |
17563 hdr->fh_f_ctl[1] << 8 |
17565 /* If last frame of sequence we can return success. */
17566 if (fctl & FC_FC_END_SEQ)
17568 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
17569 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17570 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
17571 /* If there is a hole in the sequence count then fail. */
17572 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
17574 fctl = (hdr->fh_f_ctl[0] << 16 |
17575 hdr->fh_f_ctl[1] << 8 |
17577 /* If last frame of sequence we can return success. */
17578 if (fctl & FC_FC_END_SEQ)
17585 * lpfc_prep_seq - Prep sequence for ULP processing
17586 * @vport: Pointer to the vport on which this sequence was received
17587 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17589 * This function takes a sequence, described by a list of frames, and creates
17590 * a list of iocbq structures to describe the sequence. This iocbq list will be
17591 * used to issue to the generic unsolicited sequence handler. This routine
17592 * returns a pointer to the first iocbq in the list. If the function is unable
17593 * to allocate an iocbq then it throw out the received frames that were not
17594 * able to be described and return a pointer to the first iocbq. If unable to
17595 * allocate any iocbqs (including the first) this function will return NULL.
17597 static struct lpfc_iocbq *
17598 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
17600 struct hbq_dmabuf *hbq_buf;
17601 struct lpfc_dmabuf *d_buf, *n_buf;
17602 struct lpfc_iocbq *first_iocbq, *iocbq;
17603 struct fc_frame_header *fc_hdr;
17605 uint32_t len, tot_len;
17606 struct ulp_bde64 *pbde;
17608 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
17609 /* remove from receive buffer list */
17610 list_del_init(&seq_dmabuf->hbuf.list);
17611 lpfc_update_rcv_time_stamp(vport);
17612 /* get the Remote Port's SID */
17613 sid = sli4_sid_from_fc_hdr(fc_hdr);
17615 /* Get an iocbq struct to fill in. */
17616 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
17618 /* Initialize the first IOCB. */
17619 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
17620 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
17621 first_iocbq->vport = vport;
17623 /* Check FC Header to see what TYPE of frame we are rcv'ing */
17624 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
17625 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
17626 first_iocbq->iocb.un.rcvels.parmRo =
17627 sli4_did_from_fc_hdr(fc_hdr);
17628 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
17630 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
17631 first_iocbq->iocb.ulpContext = NO_XRI;
17632 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
17633 be16_to_cpu(fc_hdr->fh_ox_id);
17634 /* iocbq is prepped for internal consumption. Physical vpi. */
17635 first_iocbq->iocb.unsli3.rcvsli3.vpi =
17636 vport->phba->vpi_ids[vport->vpi];
17637 /* put the first buffer into the first IOCBq */
17638 tot_len = bf_get(lpfc_rcqe_length,
17639 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
17641 first_iocbq->context2 = &seq_dmabuf->dbuf;
17642 first_iocbq->context3 = NULL;
17643 first_iocbq->iocb.ulpBdeCount = 1;
17644 if (tot_len > LPFC_DATA_BUF_SIZE)
17645 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
17646 LPFC_DATA_BUF_SIZE;
17648 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
17650 first_iocbq->iocb.un.rcvels.remoteID = sid;
17652 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
17654 iocbq = first_iocbq;
17656 * Each IOCBq can have two Buffers assigned, so go through the list
17657 * of buffers for this sequence and save two buffers in each IOCBq
17659 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
17661 lpfc_in_buf_free(vport->phba, d_buf);
17664 if (!iocbq->context3) {
17665 iocbq->context3 = d_buf;
17666 iocbq->iocb.ulpBdeCount++;
17667 /* We need to get the size out of the right CQE */
17668 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17669 len = bf_get(lpfc_rcqe_length,
17670 &hbq_buf->cq_event.cqe.rcqe_cmpl);
17671 pbde = (struct ulp_bde64 *)
17672 &iocbq->iocb.unsli3.sli3Words[4];
17673 if (len > LPFC_DATA_BUF_SIZE)
17674 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
17676 pbde->tus.f.bdeSize = len;
17678 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
17681 iocbq = lpfc_sli_get_iocbq(vport->phba);
17684 first_iocbq->iocb.ulpStatus =
17685 IOSTAT_FCP_RSP_ERROR;
17686 first_iocbq->iocb.un.ulpWord[4] =
17687 IOERR_NO_RESOURCES;
17689 lpfc_in_buf_free(vport->phba, d_buf);
17692 /* We need to get the size out of the right CQE */
17693 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17694 len = bf_get(lpfc_rcqe_length,
17695 &hbq_buf->cq_event.cqe.rcqe_cmpl);
17696 iocbq->context2 = d_buf;
17697 iocbq->context3 = NULL;
17698 iocbq->iocb.ulpBdeCount = 1;
17699 if (len > LPFC_DATA_BUF_SIZE)
17700 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
17701 LPFC_DATA_BUF_SIZE;
17703 iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
17706 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
17708 iocbq->iocb.un.rcvels.remoteID = sid;
17709 list_add_tail(&iocbq->list, &first_iocbq->list);
17712 return first_iocbq;
17716 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
17717 struct hbq_dmabuf *seq_dmabuf)
17719 struct fc_frame_header *fc_hdr;
17720 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
17721 struct lpfc_hba *phba = vport->phba;
17723 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
17724 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
17726 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17727 "2707 Ring %d handler: Failed to allocate "
17728 "iocb Rctl x%x Type x%x received\n",
17730 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
17733 if (!lpfc_complete_unsol_iocb(phba,
17734 phba->sli4_hba.els_wq->pring,
17735 iocbq, fc_hdr->fh_r_ctl,
17737 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17738 "2540 Ring %d handler: unexpected Rctl "
17739 "x%x Type x%x received\n",
17741 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
17743 /* Free iocb created in lpfc_prep_seq */
17744 list_for_each_entry_safe(curr_iocb, next_iocb,
17745 &iocbq->list, list) {
17746 list_del_init(&curr_iocb->list);
17747 lpfc_sli_release_iocbq(phba, curr_iocb);
17749 lpfc_sli_release_iocbq(phba, iocbq);
17753 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
17754 struct lpfc_iocbq *rspiocb)
17756 struct lpfc_dmabuf *pcmd = cmdiocb->context2;
17758 if (pcmd && pcmd->virt)
17759 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
17761 lpfc_sli_release_iocbq(phba, cmdiocb);
17762 lpfc_drain_txq(phba);
17766 lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
17767 struct hbq_dmabuf *dmabuf)
17769 struct fc_frame_header *fc_hdr;
17770 struct lpfc_hba *phba = vport->phba;
17771 struct lpfc_iocbq *iocbq = NULL;
17772 union lpfc_wqe *wqe;
17773 struct lpfc_dmabuf *pcmd = NULL;
17774 uint32_t frame_len;
17776 unsigned long iflags;
17778 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17779 frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
17781 /* Send the received frame back */
17782 iocbq = lpfc_sli_get_iocbq(phba);
17784 /* Queue cq event and wakeup worker thread to process it */
17785 spin_lock_irqsave(&phba->hbalock, iflags);
17786 list_add_tail(&dmabuf->cq_event.list,
17787 &phba->sli4_hba.sp_queue_event);
17788 phba->hba_flag |= HBA_SP_QUEUE_EVT;
17789 spin_unlock_irqrestore(&phba->hbalock, iflags);
17790 lpfc_worker_wake_up(phba);
17794 /* Allocate buffer for command payload */
17795 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
17797 pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
17799 if (!pcmd || !pcmd->virt)
17802 INIT_LIST_HEAD(&pcmd->list);
17804 /* copyin the payload */
17805 memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
17807 /* fill in BDE's for command */
17808 iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys);
17809 iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys);
17810 iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
17811 iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len;
17813 iocbq->context2 = pcmd;
17814 iocbq->vport = vport;
17815 iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
17816 iocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
17819 * Setup rest of the iocb as though it were a WQE
17820 * Build the SEND_FRAME WQE
17822 wqe = (union lpfc_wqe *)&iocbq->iocb;
17824 wqe->send_frame.frame_len = frame_len;
17825 wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr));
17826 wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1));
17827 wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2));
17828 wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3));
17829 wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4));
17830 wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5));
17832 iocbq->iocb.ulpCommand = CMD_SEND_FRAME;
17833 iocbq->iocb.ulpLe = 1;
17834 iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl;
17835 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
17836 if (rc == IOCB_ERROR)
17839 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17843 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
17844 "2023 Unable to process MDS loopback frame\n");
17845 if (pcmd && pcmd->virt)
17846 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
17849 lpfc_sli_release_iocbq(phba, iocbq);
17850 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17854 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
17855 * @phba: Pointer to HBA context object.
17857 * This function is called with no lock held. This function processes all
17858 * the received buffers and gives it to upper layers when a received buffer
17859 * indicates that it is the final frame in the sequence. The interrupt
17860 * service routine processes received buffers at interrupt contexts.
17861 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
17862 * appropriate receive function when the final frame in a sequence is received.
17865 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
17866 struct hbq_dmabuf *dmabuf)
17868 struct hbq_dmabuf *seq_dmabuf;
17869 struct fc_frame_header *fc_hdr;
17870 struct lpfc_vport *vport;
17874 /* Process each received buffer */
17875 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17877 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
17878 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
17879 vport = phba->pport;
17880 /* Handle MDS Loopback frames */
17881 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
17885 /* check to see if this a valid type of frame */
17886 if (lpfc_fc_frame_check(phba, fc_hdr)) {
17887 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17891 if ((bf_get(lpfc_cqe_code,
17892 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
17893 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
17894 &dmabuf->cq_event.cqe.rcqe_cmpl);
17896 fcfi = bf_get(lpfc_rcqe_fcf_id,
17897 &dmabuf->cq_event.cqe.rcqe_cmpl);
17899 if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
17900 vport = phba->pport;
17901 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
17902 "2023 MDS Loopback %d bytes\n",
17903 bf_get(lpfc_rcqe_length,
17904 &dmabuf->cq_event.cqe.rcqe_cmpl));
17905 /* Handle MDS Loopback frames */
17906 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
17910 /* d_id this frame is directed to */
17911 did = sli4_did_from_fc_hdr(fc_hdr);
17913 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
17915 /* throw out the frame */
17916 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17920 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
17921 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
17922 (did != Fabric_DID)) {
17924 * Throw out the frame if we are not pt2pt.
17925 * The pt2pt protocol allows for discovery frames
17926 * to be received without a registered VPI.
17928 if (!(vport->fc_flag & FC_PT2PT) ||
17929 (phba->link_state == LPFC_HBA_READY)) {
17930 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17935 /* Handle the basic abort sequence (BA_ABTS) event */
17936 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
17937 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
17941 /* Link this frame */
17942 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
17944 /* unable to add frame to vport - throw it out */
17945 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17948 /* If not last frame in sequence continue processing frames. */
17949 if (!lpfc_seq_complete(seq_dmabuf))
17952 /* Send the complete sequence to the upper layer protocol */
17953 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
17957 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
17958 * @phba: pointer to lpfc hba data structure.
17960 * This routine is invoked to post rpi header templates to the
17961 * HBA consistent with the SLI-4 interface spec. This routine
17962 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17963 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17965 * This routine does not require any locks. It's usage is expected
17966 * to be driver load or reset recovery when the driver is
17971 * -EIO - The mailbox failed to complete successfully.
17972 * When this error occurs, the driver is not guaranteed
17973 * to have any rpi regions posted to the device and
17974 * must either attempt to repost the regions or take a
17978 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
17980 struct lpfc_rpi_hdr *rpi_page;
17984 /* SLI4 ports that support extents do not require RPI headers. */
17985 if (!phba->sli4_hba.rpi_hdrs_in_use)
17987 if (phba->sli4_hba.extents_in_use)
17990 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
17992 * Assign the rpi headers a physical rpi only if the driver
17993 * has not initialized those resources. A port reset only
17994 * needs the headers posted.
17996 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
17998 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
18000 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
18001 if (rc != MBX_SUCCESS) {
18002 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18003 "2008 Error %d posting all rpi "
18011 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
18012 LPFC_RPI_RSRC_RDY);
18017 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
18018 * @phba: pointer to lpfc hba data structure.
18019 * @rpi_page: pointer to the rpi memory region.
18021 * This routine is invoked to post a single rpi header to the
18022 * HBA consistent with the SLI-4 interface spec. This memory region
18023 * maps up to 64 rpi context regions.
18027 * -ENOMEM - No available memory
18028 * -EIO - The mailbox failed to complete successfully.
18031 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
18033 LPFC_MBOXQ_t *mboxq;
18034 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
18036 uint32_t shdr_status, shdr_add_status;
18037 union lpfc_sli4_cfg_shdr *shdr;
18039 /* SLI4 ports that support extents do not require RPI headers. */
18040 if (!phba->sli4_hba.rpi_hdrs_in_use)
18042 if (phba->sli4_hba.extents_in_use)
18045 /* The port is notified of the header region via a mailbox command. */
18046 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18048 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18049 "2001 Unable to allocate memory for issuing "
18050 "SLI_CONFIG_SPECIAL mailbox command\n");
18054 /* Post all rpi memory regions to the port. */
18055 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
18056 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
18057 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
18058 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
18059 sizeof(struct lpfc_sli4_cfg_mhdr),
18060 LPFC_SLI4_MBX_EMBED);
18063 /* Post the physical rpi to the port for this rpi header. */
18064 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
18065 rpi_page->start_rpi);
18066 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
18067 hdr_tmpl, rpi_page->page_count);
18069 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
18070 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
18071 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
18072 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
18073 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18074 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18075 if (rc != MBX_TIMEOUT)
18076 mempool_free(mboxq, phba->mbox_mem_pool);
18077 if (shdr_status || shdr_add_status || rc) {
18078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18079 "2514 POST_RPI_HDR mailbox failed with "
18080 "status x%x add_status x%x, mbx status x%x\n",
18081 shdr_status, shdr_add_status, rc);
18085 * The next_rpi stores the next logical module-64 rpi value used
18086 * to post physical rpis in subsequent rpi postings.
18088 spin_lock_irq(&phba->hbalock);
18089 phba->sli4_hba.next_rpi = rpi_page->next_rpi;
18090 spin_unlock_irq(&phba->hbalock);
18096 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
18097 * @phba: pointer to lpfc hba data structure.
18099 * This routine is invoked to post rpi header templates to the
18100 * HBA consistent with the SLI-4 interface spec. This routine
18101 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
18102 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
18105 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
18106 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
18109 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
18112 uint16_t max_rpi, rpi_limit;
18113 uint16_t rpi_remaining, lrpi = 0;
18114 struct lpfc_rpi_hdr *rpi_hdr;
18115 unsigned long iflag;
18118 * Fetch the next logical rpi. Because this index is logical,
18119 * the driver starts at 0 each time.
18121 spin_lock_irqsave(&phba->hbalock, iflag);
18122 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
18123 rpi_limit = phba->sli4_hba.next_rpi;
18125 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
18126 if (rpi >= rpi_limit)
18127 rpi = LPFC_RPI_ALLOC_ERROR;
18129 set_bit(rpi, phba->sli4_hba.rpi_bmask);
18130 phba->sli4_hba.max_cfg_param.rpi_used++;
18131 phba->sli4_hba.rpi_count++;
18133 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
18134 "0001 rpi:%x max:%x lim:%x\n",
18135 (int) rpi, max_rpi, rpi_limit);
18138 * Don't try to allocate more rpi header regions if the device limit
18139 * has been exhausted.
18141 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
18142 (phba->sli4_hba.rpi_count >= max_rpi)) {
18143 spin_unlock_irqrestore(&phba->hbalock, iflag);
18148 * RPI header postings are not required for SLI4 ports capable of
18151 if (!phba->sli4_hba.rpi_hdrs_in_use) {
18152 spin_unlock_irqrestore(&phba->hbalock, iflag);
18157 * If the driver is running low on rpi resources, allocate another
18158 * page now. Note that the next_rpi value is used because
18159 * it represents how many are actually in use whereas max_rpi notes
18160 * how many are supported max by the device.
18162 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
18163 spin_unlock_irqrestore(&phba->hbalock, iflag);
18164 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
18165 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
18167 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18168 "2002 Error Could not grow rpi "
18171 lrpi = rpi_hdr->start_rpi;
18172 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
18173 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
18181 * lpfc_sli4_free_rpi - Release an rpi for reuse.
18182 * @phba: pointer to lpfc hba data structure.
18184 * This routine is invoked to release an rpi to the pool of
18185 * available rpis maintained by the driver.
18188 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
18191 * if the rpi value indicates a prior unreg has already
18192 * been done, skip the unreg.
18194 if (rpi == LPFC_RPI_ALLOC_ERROR)
18197 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
18198 phba->sli4_hba.rpi_count--;
18199 phba->sli4_hba.max_cfg_param.rpi_used--;
18201 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
18202 "2016 rpi %x not inuse\n",
18208 * lpfc_sli4_free_rpi - Release an rpi for reuse.
18209 * @phba: pointer to lpfc hba data structure.
18211 * This routine is invoked to release an rpi to the pool of
18212 * available rpis maintained by the driver.
18215 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
18217 spin_lock_irq(&phba->hbalock);
18218 __lpfc_sli4_free_rpi(phba, rpi);
18219 spin_unlock_irq(&phba->hbalock);
18223 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
18224 * @phba: pointer to lpfc hba data structure.
18226 * This routine is invoked to remove the memory region that
18227 * provided rpi via a bitmask.
18230 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
18232 kfree(phba->sli4_hba.rpi_bmask);
18233 kfree(phba->sli4_hba.rpi_ids);
18234 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
18238 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
18239 * @phba: pointer to lpfc hba data structure.
18241 * This routine is invoked to remove the memory region that
18242 * provided rpi via a bitmask.
18245 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
18246 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
18248 LPFC_MBOXQ_t *mboxq;
18249 struct lpfc_hba *phba = ndlp->phba;
18252 /* The port is notified of the header region via a mailbox command. */
18253 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18257 /* Post all rpi memory regions to the port. */
18258 lpfc_resume_rpi(mboxq, ndlp);
18260 mboxq->mbox_cmpl = cmpl;
18261 mboxq->ctx_buf = arg;
18262 mboxq->ctx_ndlp = ndlp;
18264 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
18265 mboxq->vport = ndlp->vport;
18266 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18267 if (rc == MBX_NOT_FINISHED) {
18268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18269 "2010 Resume RPI Mailbox failed "
18270 "status %d, mbxStatus x%x\n", rc,
18271 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
18272 mempool_free(mboxq, phba->mbox_mem_pool);
18279 * lpfc_sli4_init_vpi - Initialize a vpi with the port
18280 * @vport: Pointer to the vport for which the vpi is being initialized
18282 * This routine is invoked to activate a vpi with the port.
18286 * -Evalue otherwise
18289 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
18291 LPFC_MBOXQ_t *mboxq;
18293 int retval = MBX_SUCCESS;
18295 struct lpfc_hba *phba = vport->phba;
18296 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18299 lpfc_init_vpi(phba, mboxq, vport->vpi);
18300 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
18301 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
18302 if (rc != MBX_SUCCESS) {
18303 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
18304 "2022 INIT VPI Mailbox failed "
18305 "status %d, mbxStatus x%x\n", rc,
18306 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
18309 if (rc != MBX_TIMEOUT)
18310 mempool_free(mboxq, vport->phba->mbox_mem_pool);
18316 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
18317 * @phba: pointer to lpfc hba data structure.
18318 * @mboxq: Pointer to mailbox object.
18320 * This routine is invoked to manually add a single FCF record. The caller
18321 * must pass a completely initialized FCF_Record. This routine takes
18322 * care of the nonembedded mailbox operations.
18325 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
18328 union lpfc_sli4_cfg_shdr *shdr;
18329 uint32_t shdr_status, shdr_add_status;
18331 virt_addr = mboxq->sge_array->addr[0];
18332 /* The IOCTL status is embedded in the mailbox subheader. */
18333 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
18334 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18335 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18337 if ((shdr_status || shdr_add_status) &&
18338 (shdr_status != STATUS_FCF_IN_USE))
18339 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18340 "2558 ADD_FCF_RECORD mailbox failed with "
18341 "status x%x add_status x%x\n",
18342 shdr_status, shdr_add_status);
18344 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18348 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
18349 * @phba: pointer to lpfc hba data structure.
18350 * @fcf_record: pointer to the initialized fcf record to add.
18352 * This routine is invoked to manually add a single FCF record. The caller
18353 * must pass a completely initialized FCF_Record. This routine takes
18354 * care of the nonembedded mailbox operations.
18357 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
18360 LPFC_MBOXQ_t *mboxq;
18363 struct lpfc_mbx_sge sge;
18364 uint32_t alloc_len, req_len;
18367 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18369 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18370 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
18374 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
18377 /* Allocate DMA memory and set up the non-embedded mailbox command */
18378 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
18379 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
18380 req_len, LPFC_SLI4_MBX_NEMBED);
18381 if (alloc_len < req_len) {
18382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18383 "2523 Allocated DMA memory size (x%x) is "
18384 "less than the requested DMA memory "
18385 "size (x%x)\n", alloc_len, req_len);
18386 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18391 * Get the first SGE entry from the non-embedded DMA memory. This
18392 * routine only uses a single SGE.
18394 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
18395 virt_addr = mboxq->sge_array->addr[0];
18397 * Configure the FCF record for FCFI 0. This is the driver's
18398 * hardcoded default and gets used in nonFIP mode.
18400 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
18401 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
18402 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
18405 * Copy the fcf_index and the FCF Record Data. The data starts after
18406 * the FCoE header plus word10. The data copy needs to be endian
18409 bytep += sizeof(uint32_t);
18410 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
18411 mboxq->vport = phba->pport;
18412 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
18413 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18414 if (rc == MBX_NOT_FINISHED) {
18415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18416 "2515 ADD_FCF_RECORD mailbox failed with "
18417 "status 0x%x\n", rc);
18418 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18427 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
18428 * @phba: pointer to lpfc hba data structure.
18429 * @fcf_record: pointer to the fcf record to write the default data.
18430 * @fcf_index: FCF table entry index.
18432 * This routine is invoked to build the driver's default FCF record. The
18433 * values used are hardcoded. This routine handles memory initialization.
18437 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
18438 struct fcf_record *fcf_record,
18439 uint16_t fcf_index)
18441 memset(fcf_record, 0, sizeof(struct fcf_record));
18442 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
18443 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
18444 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
18445 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
18446 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
18447 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
18448 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
18449 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
18450 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
18451 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
18452 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
18453 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
18454 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
18455 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
18456 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
18457 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
18458 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
18459 /* Set the VLAN bit map */
18460 if (phba->valid_vlan) {
18461 fcf_record->vlan_bitmap[phba->vlan_id / 8]
18462 = 1 << (phba->vlan_id % 8);
18467 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
18468 * @phba: pointer to lpfc hba data structure.
18469 * @fcf_index: FCF table entry offset.
18471 * This routine is invoked to scan the entire FCF table by reading FCF
18472 * record and processing it one at a time starting from the @fcf_index
18473 * for initial FCF discovery or fast FCF failover rediscovery.
18475 * Return 0 if the mailbox command is submitted successfully, none 0
18479 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
18482 LPFC_MBOXQ_t *mboxq;
18484 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
18485 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
18486 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18489 "2000 Failed to allocate mbox for "
18492 goto fail_fcf_scan;
18494 /* Construct the read FCF record mailbox command */
18495 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
18498 goto fail_fcf_scan;
18500 /* Issue the mailbox command asynchronously */
18501 mboxq->vport = phba->pport;
18502 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
18504 spin_lock_irq(&phba->hbalock);
18505 phba->hba_flag |= FCF_TS_INPROG;
18506 spin_unlock_irq(&phba->hbalock);
18508 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18509 if (rc == MBX_NOT_FINISHED)
18512 /* Reset eligible FCF count for new scan */
18513 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
18514 phba->fcf.eligible_fcf_cnt = 0;
18520 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18521 /* FCF scan failed, clear FCF_TS_INPROG flag */
18522 spin_lock_irq(&phba->hbalock);
18523 phba->hba_flag &= ~FCF_TS_INPROG;
18524 spin_unlock_irq(&phba->hbalock);
18530 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
18531 * @phba: pointer to lpfc hba data structure.
18532 * @fcf_index: FCF table entry offset.
18534 * This routine is invoked to read an FCF record indicated by @fcf_index
18535 * and to use it for FLOGI roundrobin FCF failover.
18537 * Return 0 if the mailbox command is submitted successfully, none 0
18541 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
18544 LPFC_MBOXQ_t *mboxq;
18546 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18548 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
18549 "2763 Failed to allocate mbox for "
18552 goto fail_fcf_read;
18554 /* Construct the read FCF record mailbox command */
18555 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
18558 goto fail_fcf_read;
18560 /* Issue the mailbox command asynchronously */
18561 mboxq->vport = phba->pport;
18562 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
18563 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18564 if (rc == MBX_NOT_FINISHED)
18570 if (error && mboxq)
18571 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18576 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
18577 * @phba: pointer to lpfc hba data structure.
18578 * @fcf_index: FCF table entry offset.
18580 * This routine is invoked to read an FCF record indicated by @fcf_index to
18581 * determine whether it's eligible for FLOGI roundrobin failover list.
18583 * Return 0 if the mailbox command is submitted successfully, none 0
18587 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
18590 LPFC_MBOXQ_t *mboxq;
18592 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18594 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
18595 "2758 Failed to allocate mbox for "
18598 goto fail_fcf_read;
18600 /* Construct the read FCF record mailbox command */
18601 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
18604 goto fail_fcf_read;
18606 /* Issue the mailbox command asynchronously */
18607 mboxq->vport = phba->pport;
18608 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
18609 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18610 if (rc == MBX_NOT_FINISHED)
18616 if (error && mboxq)
18617 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18622 * lpfc_check_next_fcf_pri_level
18623 * phba pointer to the lpfc_hba struct for this port.
18624 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
18625 * routine when the rr_bmask is empty. The FCF indecies are put into the
18626 * rr_bmask based on their priority level. Starting from the highest priority
18627 * to the lowest. The most likely FCF candidate will be in the highest
18628 * priority group. When this routine is called it searches the fcf_pri list for
18629 * next lowest priority group and repopulates the rr_bmask with only those
18632 * 1=success 0=failure
18635 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
18637 uint16_t next_fcf_pri;
18638 uint16_t last_index;
18639 struct lpfc_fcf_pri *fcf_pri;
18643 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
18644 LPFC_SLI4_FCF_TBL_INDX_MAX);
18645 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
18646 "3060 Last IDX %d\n", last_index);
18648 /* Verify the priority list has 2 or more entries */
18649 spin_lock_irq(&phba->hbalock);
18650 if (list_empty(&phba->fcf.fcf_pri_list) ||
18651 list_is_singular(&phba->fcf.fcf_pri_list)) {
18652 spin_unlock_irq(&phba->hbalock);
18653 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
18654 "3061 Last IDX %d\n", last_index);
18655 return 0; /* Empty rr list */
18657 spin_unlock_irq(&phba->hbalock);
18661 * Clear the rr_bmask and set all of the bits that are at this
18664 memset(phba->fcf.fcf_rr_bmask, 0,
18665 sizeof(*phba->fcf.fcf_rr_bmask));
18666 spin_lock_irq(&phba->hbalock);
18667 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
18668 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
18671 * the 1st priority that has not FLOGI failed
18672 * will be the highest.
18675 next_fcf_pri = fcf_pri->fcf_rec.priority;
18676 spin_unlock_irq(&phba->hbalock);
18677 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
18678 rc = lpfc_sli4_fcf_rr_index_set(phba,
18679 fcf_pri->fcf_rec.fcf_index);
18683 spin_lock_irq(&phba->hbalock);
18686 * if next_fcf_pri was not set above and the list is not empty then
18687 * we have failed flogis on all of them. So reset flogi failed
18688 * and start at the beginning.
18690 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
18691 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
18692 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
18694 * the 1st priority that has not FLOGI failed
18695 * will be the highest.
18698 next_fcf_pri = fcf_pri->fcf_rec.priority;
18699 spin_unlock_irq(&phba->hbalock);
18700 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
18701 rc = lpfc_sli4_fcf_rr_index_set(phba,
18702 fcf_pri->fcf_rec.fcf_index);
18706 spin_lock_irq(&phba->hbalock);
18710 spin_unlock_irq(&phba->hbalock);
18715 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
18716 * @phba: pointer to lpfc hba data structure.
18718 * This routine is to get the next eligible FCF record index in a round
18719 * robin fashion. If the next eligible FCF record index equals to the
18720 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
18721 * shall be returned, otherwise, the next eligible FCF record's index
18722 * shall be returned.
18725 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
18727 uint16_t next_fcf_index;
18730 /* Search start from next bit of currently registered FCF index */
18731 next_fcf_index = phba->fcf.current_rec.fcf_indx;
18734 /* Determine the next fcf index to check */
18735 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
18736 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
18737 LPFC_SLI4_FCF_TBL_INDX_MAX,
18740 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
18741 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
18743 * If we have wrapped then we need to clear the bits that
18744 * have been tested so that we can detect when we should
18745 * change the priority level.
18747 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
18748 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
18752 /* Check roundrobin failover list empty condition */
18753 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
18754 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
18756 * If next fcf index is not found check if there are lower
18757 * Priority level fcf's in the fcf_priority list.
18758 * Set up the rr_bmask with all of the avaiable fcf bits
18759 * at that level and continue the selection process.
18761 if (lpfc_check_next_fcf_pri_level(phba))
18762 goto initial_priority;
18763 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
18764 "2844 No roundrobin failover FCF available\n");
18766 return LPFC_FCOE_FCF_NEXT_NONE;
18769 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
18770 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
18771 LPFC_FCF_FLOGI_FAILED) {
18772 if (list_is_singular(&phba->fcf.fcf_pri_list))
18773 return LPFC_FCOE_FCF_NEXT_NONE;
18775 goto next_priority;
18778 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
18779 "2845 Get next roundrobin failover FCF (x%x)\n",
18782 return next_fcf_index;
18786 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
18787 * @phba: pointer to lpfc hba data structure.
18789 * This routine sets the FCF record index in to the eligible bmask for
18790 * roundrobin failover search. It checks to make sure that the index
18791 * does not go beyond the range of the driver allocated bmask dimension
18792 * before setting the bit.
18794 * Returns 0 if the index bit successfully set, otherwise, it returns
18798 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
18800 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
18801 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
18802 "2610 FCF (x%x) reached driver's book "
18803 "keeping dimension:x%x\n",
18804 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
18807 /* Set the eligible FCF record index bmask */
18808 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
18810 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
18811 "2790 Set FCF (x%x) to roundrobin FCF failover "
18812 "bmask\n", fcf_index);
18818 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
18819 * @phba: pointer to lpfc hba data structure.
18821 * This routine clears the FCF record index from the eligible bmask for
18822 * roundrobin failover search. It checks to make sure that the index
18823 * does not go beyond the range of the driver allocated bmask dimension
18824 * before clearing the bit.
18827 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
18829 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
18830 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
18831 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
18832 "2762 FCF (x%x) reached driver's book "
18833 "keeping dimension:x%x\n",
18834 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
18837 /* Clear the eligible FCF record index bmask */
18838 spin_lock_irq(&phba->hbalock);
18839 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
18841 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
18842 list_del_init(&fcf_pri->list);
18846 spin_unlock_irq(&phba->hbalock);
18847 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
18849 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
18850 "2791 Clear FCF (x%x) from roundrobin failover "
18851 "bmask\n", fcf_index);
18855 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
18856 * @phba: pointer to lpfc hba data structure.
18858 * This routine is the completion routine for the rediscover FCF table mailbox
18859 * command. If the mailbox command returned failure, it will try to stop the
18860 * FCF rediscover wait timer.
18863 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
18865 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
18866 uint32_t shdr_status, shdr_add_status;
18868 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
18870 shdr_status = bf_get(lpfc_mbox_hdr_status,
18871 &redisc_fcf->header.cfg_shdr.response);
18872 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
18873 &redisc_fcf->header.cfg_shdr.response);
18874 if (shdr_status || shdr_add_status) {
18875 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
18876 "2746 Requesting for FCF rediscovery failed "
18877 "status x%x add_status x%x\n",
18878 shdr_status, shdr_add_status);
18879 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
18880 spin_lock_irq(&phba->hbalock);
18881 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
18882 spin_unlock_irq(&phba->hbalock);
18884 * CVL event triggered FCF rediscover request failed,
18885 * last resort to re-try current registered FCF entry.
18887 lpfc_retry_pport_discovery(phba);
18889 spin_lock_irq(&phba->hbalock);
18890 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
18891 spin_unlock_irq(&phba->hbalock);
18893 * DEAD FCF event triggered FCF rediscover request
18894 * failed, last resort to fail over as a link down
18895 * to FCF registration.
18897 lpfc_sli4_fcf_dead_failthrough(phba);
18900 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
18901 "2775 Start FCF rediscover quiescent timer\n");
18903 * Start FCF rediscovery wait timer for pending FCF
18904 * before rescan FCF record table.
18906 lpfc_fcf_redisc_wait_start_timer(phba);
18909 mempool_free(mbox, phba->mbox_mem_pool);
18913 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
18914 * @phba: pointer to lpfc hba data structure.
18916 * This routine is invoked to request for rediscovery of the entire FCF table
18920 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
18922 LPFC_MBOXQ_t *mbox;
18923 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
18926 /* Cancel retry delay timers to all vports before FCF rediscover */
18927 lpfc_cancel_all_vport_retry_delay_timer(phba);
18929 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18931 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18932 "2745 Failed to allocate mbox for "
18933 "requesting FCF rediscover.\n");
18937 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
18938 sizeof(struct lpfc_sli4_cfg_mhdr));
18939 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
18940 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
18941 length, LPFC_SLI4_MBX_EMBED);
18943 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
18944 /* Set count to 0 for invalidating the entire FCF database */
18945 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
18947 /* Issue the mailbox command asynchronously */
18948 mbox->vport = phba->pport;
18949 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
18950 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
18952 if (rc == MBX_NOT_FINISHED) {
18953 mempool_free(mbox, phba->mbox_mem_pool);
18960 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
18961 * @phba: pointer to lpfc hba data structure.
18963 * This function is the failover routine as a last resort to the FCF DEAD
18964 * event when driver failed to perform fast FCF failover.
18967 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
18969 uint32_t link_state;
18972 * Last resort as FCF DEAD event failover will treat this as
18973 * a link down, but save the link state because we don't want
18974 * it to be changed to Link Down unless it is already down.
18976 link_state = phba->link_state;
18977 lpfc_linkdown(phba);
18978 phba->link_state = link_state;
18980 /* Unregister FCF if no devices connected to it */
18981 lpfc_unregister_unused_fcf(phba);
18985 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
18986 * @phba: pointer to lpfc hba data structure.
18987 * @rgn23_data: pointer to configure region 23 data.
18989 * This function gets SLI3 port configure region 23 data through memory dump
18990 * mailbox command. When it successfully retrieves data, the size of the data
18991 * will be returned, otherwise, 0 will be returned.
18994 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
18996 LPFC_MBOXQ_t *pmb = NULL;
18998 uint32_t offset = 0;
19004 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19006 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19007 "2600 failed to allocate mailbox memory\n");
19013 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
19014 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
19016 if (rc != MBX_SUCCESS) {
19017 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19018 "2601 failed to read config "
19019 "region 23, rc 0x%x Status 0x%x\n",
19020 rc, mb->mbxStatus);
19021 mb->un.varDmp.word_cnt = 0;
19024 * dump mem may return a zero when finished or we got a
19025 * mailbox error, either way we are done.
19027 if (mb->un.varDmp.word_cnt == 0)
19029 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
19030 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
19032 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
19033 rgn23_data + offset,
19034 mb->un.varDmp.word_cnt);
19035 offset += mb->un.varDmp.word_cnt;
19036 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
19038 mempool_free(pmb, phba->mbox_mem_pool);
19043 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
19044 * @phba: pointer to lpfc hba data structure.
19045 * @rgn23_data: pointer to configure region 23 data.
19047 * This function gets SLI4 port configure region 23 data through memory dump
19048 * mailbox command. When it successfully retrieves data, the size of the data
19049 * will be returned, otherwise, 0 will be returned.
19052 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
19054 LPFC_MBOXQ_t *mboxq = NULL;
19055 struct lpfc_dmabuf *mp = NULL;
19056 struct lpfc_mqe *mqe;
19057 uint32_t data_length = 0;
19063 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19065 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19066 "3105 failed to allocate mailbox memory\n");
19070 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
19072 mqe = &mboxq->u.mqe;
19073 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
19074 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
19077 data_length = mqe->un.mb_words[5];
19078 if (data_length == 0)
19080 if (data_length > DMP_RGN23_SIZE) {
19084 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
19086 mempool_free(mboxq, phba->mbox_mem_pool);
19088 lpfc_mbuf_free(phba, mp->virt, mp->phys);
19091 return data_length;
19095 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
19096 * @phba: pointer to lpfc hba data structure.
19098 * This function read region 23 and parse TLV for port status to
19099 * decide if the user disaled the port. If the TLV indicates the
19100 * port is disabled, the hba_flag is set accordingly.
19103 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
19105 uint8_t *rgn23_data = NULL;
19106 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
19107 uint32_t offset = 0;
19109 /* Get adapter Region 23 data */
19110 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
19114 if (phba->sli_rev < LPFC_SLI_REV4)
19115 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
19117 if_type = bf_get(lpfc_sli_intf_if_type,
19118 &phba->sli4_hba.sli_intf);
19119 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
19121 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
19127 /* Check the region signature first */
19128 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
19129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19130 "2619 Config region 23 has bad signature\n");
19135 /* Check the data structure version */
19136 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
19137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19138 "2620 Config region 23 has bad version\n");
19143 /* Parse TLV entries in the region */
19144 while (offset < data_size) {
19145 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
19148 * If the TLV is not driver specific TLV or driver id is
19149 * not linux driver id, skip the record.
19151 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
19152 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
19153 (rgn23_data[offset + 3] != 0)) {
19154 offset += rgn23_data[offset + 1] * 4 + 4;
19158 /* Driver found a driver specific TLV in the config region */
19159 sub_tlv_len = rgn23_data[offset + 1] * 4;
19164 * Search for configured port state sub-TLV.
19166 while ((offset < data_size) &&
19167 (tlv_offset < sub_tlv_len)) {
19168 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
19173 if (rgn23_data[offset] != PORT_STE_TYPE) {
19174 offset += rgn23_data[offset + 1] * 4 + 4;
19175 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
19179 /* This HBA contains PORT_STE configured */
19180 if (!rgn23_data[offset + 2])
19181 phba->hba_flag |= LINK_DISABLED;
19193 * lpfc_wr_object - write an object to the firmware
19194 * @phba: HBA structure that indicates port to create a queue on.
19195 * @dmabuf_list: list of dmabufs to write to the port.
19196 * @size: the total byte value of the objects to write to the port.
19197 * @offset: the current offset to be used to start the transfer.
19199 * This routine will create a wr_object mailbox command to send to the port.
19200 * the mailbox command will be constructed using the dma buffers described in
19201 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
19202 * BDEs that the imbedded mailbox can support. The @offset variable will be
19203 * used to indicate the starting offset of the transfer and will also return
19204 * the offset after the write object mailbox has completed. @size is used to
19205 * determine the end of the object and whether the eof bit should be set.
19207 * Return 0 is successful and offset will contain the the new offset to use
19208 * for the next write.
19209 * Return negative value for error cases.
19212 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
19213 uint32_t size, uint32_t *offset)
19215 struct lpfc_mbx_wr_object *wr_object;
19216 LPFC_MBOXQ_t *mbox;
19218 uint32_t shdr_status, shdr_add_status, shdr_change_status;
19220 struct lpfc_dmabuf *dmabuf;
19221 uint32_t written = 0;
19222 bool check_change_status = false;
19224 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19228 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
19229 LPFC_MBOX_OPCODE_WRITE_OBJECT,
19230 sizeof(struct lpfc_mbx_wr_object) -
19231 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
19233 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
19234 wr_object->u.request.write_offset = *offset;
19235 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
19236 wr_object->u.request.object_name[0] =
19237 cpu_to_le32(wr_object->u.request.object_name[0]);
19238 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
19239 list_for_each_entry(dmabuf, dmabuf_list, list) {
19240 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
19242 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
19243 wr_object->u.request.bde[i].addrHigh =
19244 putPaddrHigh(dmabuf->phys);
19245 if (written + SLI4_PAGE_SIZE >= size) {
19246 wr_object->u.request.bde[i].tus.f.bdeSize =
19248 written += (size - written);
19249 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
19250 bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
19251 check_change_status = true;
19253 wr_object->u.request.bde[i].tus.f.bdeSize =
19255 written += SLI4_PAGE_SIZE;
19259 wr_object->u.request.bde_count = i;
19260 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
19261 if (!phba->sli4_hba.intr_enable)
19262 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
19264 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
19265 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
19267 /* The IOCTL status is embedded in the mailbox subheader. */
19268 shdr_status = bf_get(lpfc_mbox_hdr_status,
19269 &wr_object->header.cfg_shdr.response);
19270 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
19271 &wr_object->header.cfg_shdr.response);
19272 if (check_change_status) {
19273 shdr_change_status = bf_get(lpfc_wr_object_change_status,
19274 &wr_object->u.response);
19275 switch (shdr_change_status) {
19276 case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
19277 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19278 "3198 Firmware write complete: System "
19279 "reboot required to instantiate\n");
19281 case (LPFC_CHANGE_STATUS_FW_RESET):
19282 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19283 "3199 Firmware write complete: Firmware"
19284 " reset required to instantiate\n");
19286 case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
19287 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19288 "3200 Firmware write complete: Port "
19289 "Migration or PCI Reset required to "
19292 case (LPFC_CHANGE_STATUS_PCI_RESET):
19293 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19294 "3201 Firmware write complete: PCI "
19295 "Reset required to instantiate\n");
19301 if (rc != MBX_TIMEOUT)
19302 mempool_free(mbox, phba->mbox_mem_pool);
19303 if (shdr_status || shdr_add_status || rc) {
19304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19305 "3025 Write Object mailbox failed with "
19306 "status x%x add_status x%x, mbx status x%x\n",
19307 shdr_status, shdr_add_status, rc);
19309 *offset = shdr_add_status;
19311 *offset += wr_object->u.response.actual_write_length;
19316 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
19317 * @vport: pointer to vport data structure.
19319 * This function iterate through the mailboxq and clean up all REG_LOGIN
19320 * and REG_VPI mailbox commands associated with the vport. This function
19321 * is called when driver want to restart discovery of the vport due to
19322 * a Clear Virtual Link event.
19325 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
19327 struct lpfc_hba *phba = vport->phba;
19328 LPFC_MBOXQ_t *mb, *nextmb;
19329 struct lpfc_dmabuf *mp;
19330 struct lpfc_nodelist *ndlp;
19331 struct lpfc_nodelist *act_mbx_ndlp = NULL;
19332 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
19333 LIST_HEAD(mbox_cmd_list);
19334 uint8_t restart_loop;
19336 /* Clean up internally queued mailbox commands with the vport */
19337 spin_lock_irq(&phba->hbalock);
19338 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
19339 if (mb->vport != vport)
19342 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
19343 (mb->u.mb.mbxCommand != MBX_REG_VPI))
19346 list_del(&mb->list);
19347 list_add_tail(&mb->list, &mbox_cmd_list);
19349 /* Clean up active mailbox command with the vport */
19350 mb = phba->sli.mbox_active;
19351 if (mb && (mb->vport == vport)) {
19352 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
19353 (mb->u.mb.mbxCommand == MBX_REG_VPI))
19354 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19355 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
19356 act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
19357 /* Put reference count for delayed processing */
19358 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
19359 /* Unregister the RPI when mailbox complete */
19360 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
19363 /* Cleanup any mailbox completions which are not yet processed */
19366 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
19368 * If this mailox is already processed or it is
19369 * for another vport ignore it.
19371 if ((mb->vport != vport) ||
19372 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
19375 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
19376 (mb->u.mb.mbxCommand != MBX_REG_VPI))
19379 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19380 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
19381 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
19382 /* Unregister the RPI when mailbox complete */
19383 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
19385 spin_unlock_irq(&phba->hbalock);
19386 spin_lock(shost->host_lock);
19387 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
19388 spin_unlock(shost->host_lock);
19389 spin_lock_irq(&phba->hbalock);
19393 } while (restart_loop);
19395 spin_unlock_irq(&phba->hbalock);
19397 /* Release the cleaned-up mailbox commands */
19398 while (!list_empty(&mbox_cmd_list)) {
19399 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
19400 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
19401 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
19403 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
19406 mb->ctx_buf = NULL;
19407 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
19408 mb->ctx_ndlp = NULL;
19410 spin_lock(shost->host_lock);
19411 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
19412 spin_unlock(shost->host_lock);
19413 lpfc_nlp_put(ndlp);
19416 mempool_free(mb, phba->mbox_mem_pool);
19419 /* Release the ndlp with the cleaned-up active mailbox command */
19420 if (act_mbx_ndlp) {
19421 spin_lock(shost->host_lock);
19422 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
19423 spin_unlock(shost->host_lock);
19424 lpfc_nlp_put(act_mbx_ndlp);
19429 * lpfc_drain_txq - Drain the txq
19430 * @phba: Pointer to HBA context object.
19432 * This function attempt to submit IOCBs on the txq
19433 * to the adapter. For SLI4 adapters, the txq contains
19434 * ELS IOCBs that have been deferred because the there
19435 * are no SGLs. This congestion can occur with large
19436 * vport counts during node discovery.
19440 lpfc_drain_txq(struct lpfc_hba *phba)
19442 LIST_HEAD(completions);
19443 struct lpfc_sli_ring *pring;
19444 struct lpfc_iocbq *piocbq = NULL;
19445 unsigned long iflags = 0;
19446 char *fail_msg = NULL;
19447 struct lpfc_sglq *sglq;
19448 union lpfc_wqe128 wqe;
19449 uint32_t txq_cnt = 0;
19450 struct lpfc_queue *wq;
19452 if (phba->link_flag & LS_MDS_LOOPBACK) {
19453 /* MDS WQE are posted only to first WQ*/
19454 wq = phba->sli4_hba.hdwq[0].io_wq;
19459 wq = phba->sli4_hba.els_wq;
19462 pring = lpfc_phba_elsring(phba);
19465 if (unlikely(!pring) || list_empty(&pring->txq))
19468 spin_lock_irqsave(&pring->ring_lock, iflags);
19469 list_for_each_entry(piocbq, &pring->txq, list) {
19473 if (txq_cnt > pring->txq_max)
19474 pring->txq_max = txq_cnt;
19476 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19478 while (!list_empty(&pring->txq)) {
19479 spin_lock_irqsave(&pring->ring_lock, iflags);
19481 piocbq = lpfc_sli_ringtx_get(phba, pring);
19483 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19484 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
19485 "2823 txq empty and txq_cnt is %d\n ",
19489 sglq = __lpfc_sli_get_els_sglq(phba, piocbq);
19491 __lpfc_sli_ringtx_put(phba, pring, piocbq);
19492 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19497 /* The xri and iocb resources secured,
19498 * attempt to issue request
19500 piocbq->sli4_lxritag = sglq->sli4_lxritag;
19501 piocbq->sli4_xritag = sglq->sli4_xritag;
19502 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
19503 fail_msg = "to convert bpl to sgl";
19504 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
19505 fail_msg = "to convert iocb to wqe";
19506 else if (lpfc_sli4_wq_put(wq, &wqe))
19507 fail_msg = " - Wq is full";
19509 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
19512 /* Failed means we can't issue and need to cancel */
19513 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
19514 "2822 IOCB failed %s iotag 0x%x "
19517 piocbq->iotag, piocbq->sli4_xritag);
19518 list_add_tail(&piocbq->list, &completions);
19520 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19523 /* Cancel all the IOCBs that cannot be issued */
19524 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
19525 IOERR_SLI_ABORTED);
19531 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
19532 * @phba: Pointer to HBA context object.
19533 * @pwqe: Pointer to command WQE.
19534 * @sglq: Pointer to the scatter gather queue object.
19536 * This routine converts the bpl or bde that is in the WQE
19537 * to a sgl list for the sli4 hardware. The physical address
19538 * of the bpl/bde is converted back to a virtual address.
19539 * If the WQE contains a BPL then the list of BDE's is
19540 * converted to sli4_sge's. If the WQE contains a single
19541 * BDE then it is converted to a single sli_sge.
19542 * The WQE is still in cpu endianness so the contents of
19543 * the bpl can be used without byte swapping.
19545 * Returns valid XRI = Success, NO_XRI = Failure.
19548 lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
19549 struct lpfc_sglq *sglq)
19551 uint16_t xritag = NO_XRI;
19552 struct ulp_bde64 *bpl = NULL;
19553 struct ulp_bde64 bde;
19554 struct sli4_sge *sgl = NULL;
19555 struct lpfc_dmabuf *dmabuf;
19556 union lpfc_wqe128 *wqe;
19559 uint32_t offset = 0; /* accumulated offset in the sg request list */
19560 int inbound = 0; /* number of sg reply entries inbound from firmware */
19563 if (!pwqeq || !sglq)
19566 sgl = (struct sli4_sge *)sglq->sgl;
19568 pwqeq->iocb.ulpIoTag = pwqeq->iotag;
19570 cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
19571 if (cmd == CMD_XMIT_BLS_RSP64_WQE)
19572 return sglq->sli4_xritag;
19573 numBdes = pwqeq->rsvd2;
19575 /* The addrHigh and addrLow fields within the WQE
19576 * have not been byteswapped yet so there is no
19577 * need to swap them back.
19579 if (pwqeq->context3)
19580 dmabuf = (struct lpfc_dmabuf *)pwqeq->context3;
19584 bpl = (struct ulp_bde64 *)dmabuf->virt;
19588 for (i = 0; i < numBdes; i++) {
19589 /* Should already be byte swapped. */
19590 sgl->addr_hi = bpl->addrHigh;
19591 sgl->addr_lo = bpl->addrLow;
19593 sgl->word2 = le32_to_cpu(sgl->word2);
19594 if ((i+1) == numBdes)
19595 bf_set(lpfc_sli4_sge_last, sgl, 1);
19597 bf_set(lpfc_sli4_sge_last, sgl, 0);
19598 /* swap the size field back to the cpu so we
19599 * can assign it to the sgl.
19601 bde.tus.w = le32_to_cpu(bpl->tus.w);
19602 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
19603 /* The offsets in the sgl need to be accumulated
19604 * separately for the request and reply lists.
19605 * The request is always first, the reply follows.
19608 case CMD_GEN_REQUEST64_WQE:
19609 /* add up the reply sg entries */
19610 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
19612 /* first inbound? reset the offset */
19615 bf_set(lpfc_sli4_sge_offset, sgl, offset);
19616 bf_set(lpfc_sli4_sge_type, sgl,
19617 LPFC_SGE_TYPE_DATA);
19618 offset += bde.tus.f.bdeSize;
19620 case CMD_FCP_TRSP64_WQE:
19621 bf_set(lpfc_sli4_sge_offset, sgl, 0);
19622 bf_set(lpfc_sli4_sge_type, sgl,
19623 LPFC_SGE_TYPE_DATA);
19625 case CMD_FCP_TSEND64_WQE:
19626 case CMD_FCP_TRECEIVE64_WQE:
19627 bf_set(lpfc_sli4_sge_type, sgl,
19628 bpl->tus.f.bdeFlags);
19632 offset += bde.tus.f.bdeSize;
19633 bf_set(lpfc_sli4_sge_offset, sgl, offset);
19636 sgl->word2 = cpu_to_le32(sgl->word2);
19640 } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
19641 /* The addrHigh and addrLow fields of the BDE have not
19642 * been byteswapped yet so they need to be swapped
19643 * before putting them in the sgl.
19645 sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
19646 sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
19647 sgl->word2 = le32_to_cpu(sgl->word2);
19648 bf_set(lpfc_sli4_sge_last, sgl, 1);
19649 sgl->word2 = cpu_to_le32(sgl->word2);
19650 sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
19652 return sglq->sli4_xritag;
19656 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
19657 * @phba: Pointer to HBA context object.
19658 * @ring_number: Base sli ring number
19659 * @pwqe: Pointer to command WQE.
19662 lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
19663 struct lpfc_iocbq *pwqe)
19665 union lpfc_wqe128 *wqe = &pwqe->wqe;
19666 struct lpfc_nvmet_rcv_ctx *ctxp;
19667 struct lpfc_queue *wq;
19668 struct lpfc_sglq *sglq;
19669 struct lpfc_sli_ring *pring;
19670 unsigned long iflags;
19673 /* NVME_LS and NVME_LS ABTS requests. */
19674 if (pwqe->iocb_flag & LPFC_IO_NVME_LS) {
19675 pring = phba->sli4_hba.nvmels_wq->pring;
19676 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
19678 sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
19680 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19683 pwqe->sli4_lxritag = sglq->sli4_lxritag;
19684 pwqe->sli4_xritag = sglq->sli4_xritag;
19685 if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
19686 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19689 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
19690 pwqe->sli4_xritag);
19691 ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
19693 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19697 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
19698 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19702 /* NVME_FCREQ and NVME_ABTS requests */
19703 if (pwqe->iocb_flag & LPFC_IO_NVME) {
19704 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19708 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
19710 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
19712 ret = lpfc_sli4_wq_put(wq, wqe);
19714 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19717 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
19718 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19722 /* NVMET requests */
19723 if (pwqe->iocb_flag & LPFC_IO_NVMET) {
19724 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19728 ctxp = pwqe->context2;
19729 sglq = ctxp->ctxbuf->sglq;
19730 if (pwqe->sli4_xritag == NO_XRI) {
19731 pwqe->sli4_lxritag = sglq->sli4_lxritag;
19732 pwqe->sli4_xritag = sglq->sli4_xritag;
19734 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
19735 pwqe->sli4_xritag);
19736 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
19738 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
19740 ret = lpfc_sli4_wq_put(wq, wqe);
19742 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19745 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
19746 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19752 #ifdef LPFC_MXP_STAT
19754 * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
19755 * @phba: pointer to lpfc hba data structure.
19756 * @hwqid: belong to which HWQ.
19758 * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
19759 * 15 seconds after a test case is running.
19761 * The user should call lpfc_debugfs_multixripools_write before running a test
19762 * case to clear stat_snapshot_taken. Then the user starts a test case. During
19763 * test case is running, stat_snapshot_taken is incremented by 1 every time when
19764 * this routine is called from heartbeat timer. When stat_snapshot_taken is
19765 * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
19767 void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
19769 struct lpfc_sli4_hdw_queue *qp;
19770 struct lpfc_multixri_pool *multixri_pool;
19771 struct lpfc_pvt_pool *pvt_pool;
19772 struct lpfc_pbl_pool *pbl_pool;
19775 qp = &phba->sli4_hba.hdwq[hwqid];
19776 multixri_pool = qp->p_multixri_pool;
19777 if (!multixri_pool)
19780 if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
19781 pvt_pool = &qp->p_multixri_pool->pvt_pool;
19782 pbl_pool = &qp->p_multixri_pool->pbl_pool;
19783 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
19785 multixri_pool->stat_pbl_count = pbl_pool->count;
19786 multixri_pool->stat_pvt_count = pvt_pool->count;
19787 multixri_pool->stat_busy_count = txcmplq_cnt;
19790 multixri_pool->stat_snapshot_taken++;
19795 * lpfc_adjust_pvt_pool_count - Adjust private pool count
19796 * @phba: pointer to lpfc hba data structure.
19797 * @hwqid: belong to which HWQ.
19799 * This routine moves some XRIs from private to public pool when private pool
19802 void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
19804 struct lpfc_multixri_pool *multixri_pool;
19806 u32 prev_io_req_count;
19808 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
19809 if (!multixri_pool)
19811 io_req_count = multixri_pool->io_req_count;
19812 prev_io_req_count = multixri_pool->prev_io_req_count;
19814 if (prev_io_req_count != io_req_count) {
19815 /* Private pool is busy */
19816 multixri_pool->prev_io_req_count = io_req_count;
19818 /* Private pool is not busy.
19819 * Move XRIs from private to public pool.
19821 lpfc_move_xri_pvt_to_pbl(phba, hwqid);
19826 * lpfc_adjust_high_watermark - Adjust high watermark
19827 * @phba: pointer to lpfc hba data structure.
19828 * @hwqid: belong to which HWQ.
19830 * This routine sets high watermark as number of outstanding XRIs,
19831 * but make sure the new value is between xri_limit/2 and xri_limit.
19833 void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
19841 struct lpfc_multixri_pool *multixri_pool;
19842 struct lpfc_sli4_hdw_queue *qp;
19844 qp = &phba->sli4_hba.hdwq[hwqid];
19845 multixri_pool = qp->p_multixri_pool;
19846 if (!multixri_pool)
19848 xri_limit = multixri_pool->xri_limit;
19850 watermark_max = xri_limit;
19851 watermark_min = xri_limit / 2;
19853 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
19854 abts_io_bufs = qp->abts_scsi_io_bufs;
19855 abts_io_bufs += qp->abts_nvme_io_bufs;
19857 new_watermark = txcmplq_cnt + abts_io_bufs;
19858 new_watermark = min(watermark_max, new_watermark);
19859 new_watermark = max(watermark_min, new_watermark);
19860 multixri_pool->pvt_pool.high_watermark = new_watermark;
19862 #ifdef LPFC_MXP_STAT
19863 multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
19869 * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
19870 * @phba: pointer to lpfc hba data structure.
19871 * @hwqid: belong to which HWQ.
19873 * This routine is called from hearbeat timer when pvt_pool is idle.
19874 * All free XRIs are moved from private to public pool on hwqid with 2 steps.
19875 * The first step moves (all - low_watermark) amount of XRIs.
19876 * The second step moves the rest of XRIs.
19878 void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
19880 struct lpfc_pbl_pool *pbl_pool;
19881 struct lpfc_pvt_pool *pvt_pool;
19882 struct lpfc_sli4_hdw_queue *qp;
19883 struct lpfc_io_buf *lpfc_ncmd;
19884 struct lpfc_io_buf *lpfc_ncmd_next;
19885 unsigned long iflag;
19886 struct list_head tmp_list;
19889 qp = &phba->sli4_hba.hdwq[hwqid];
19890 pbl_pool = &qp->p_multixri_pool->pbl_pool;
19891 pvt_pool = &qp->p_multixri_pool->pvt_pool;
19894 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
19895 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
19897 if (pvt_pool->count > pvt_pool->low_watermark) {
19898 /* Step 1: move (all - low_watermark) from pvt_pool
19902 /* Move low watermark of bufs from pvt_pool to tmp_list */
19903 INIT_LIST_HEAD(&tmp_list);
19904 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
19905 &pvt_pool->list, list) {
19906 list_move_tail(&lpfc_ncmd->list, &tmp_list);
19908 if (tmp_count >= pvt_pool->low_watermark)
19912 /* Move all bufs from pvt_pool to pbl_pool */
19913 list_splice_init(&pvt_pool->list, &pbl_pool->list);
19915 /* Move all bufs from tmp_list to pvt_pool */
19916 list_splice(&tmp_list, &pvt_pool->list);
19918 pbl_pool->count += (pvt_pool->count - tmp_count);
19919 pvt_pool->count = tmp_count;
19921 /* Step 2: move the rest from pvt_pool to pbl_pool */
19922 list_splice_init(&pvt_pool->list, &pbl_pool->list);
19923 pbl_pool->count += pvt_pool->count;
19924 pvt_pool->count = 0;
19927 spin_unlock(&pvt_pool->lock);
19928 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
19932 * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
19933 * @phba: pointer to lpfc hba data structure
19934 * @pbl_pool: specified public free XRI pool
19935 * @pvt_pool: specified private free XRI pool
19936 * @count: number of XRIs to move
19938 * This routine tries to move some free common bufs from the specified pbl_pool
19939 * to the specified pvt_pool. It might move less than count XRIs if there's not
19940 * enough in public pool.
19943 * true - if XRIs are successfully moved from the specified pbl_pool to the
19944 * specified pvt_pool
19945 * false - if the specified pbl_pool is empty or locked by someone else
19948 _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
19949 struct lpfc_pbl_pool *pbl_pool,
19950 struct lpfc_pvt_pool *pvt_pool, u32 count)
19952 struct lpfc_io_buf *lpfc_ncmd;
19953 struct lpfc_io_buf *lpfc_ncmd_next;
19954 unsigned long iflag;
19957 ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
19959 if (pbl_pool->count) {
19960 /* Move a batch of XRIs from public to private pool */
19961 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
19962 list_for_each_entry_safe(lpfc_ncmd,
19966 list_move_tail(&lpfc_ncmd->list,
19975 spin_unlock(&pvt_pool->lock);
19976 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
19979 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
19986 * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
19987 * @phba: pointer to lpfc hba data structure.
19988 * @hwqid: belong to which HWQ.
19989 * @count: number of XRIs to move
19991 * This routine tries to find some free common bufs in one of public pools with
19992 * Round Robin method. The search always starts from local hwqid, then the next
19993 * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
19994 * a batch of free common bufs are moved to private pool on hwqid.
19995 * It might move less than count XRIs if there's not enough in public pool.
19997 void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
19999 struct lpfc_multixri_pool *multixri_pool;
20000 struct lpfc_multixri_pool *next_multixri_pool;
20001 struct lpfc_pvt_pool *pvt_pool;
20002 struct lpfc_pbl_pool *pbl_pool;
20003 struct lpfc_sli4_hdw_queue *qp;
20008 qp = &phba->sli4_hba.hdwq[hwqid];
20009 multixri_pool = qp->p_multixri_pool;
20010 pvt_pool = &multixri_pool->pvt_pool;
20011 pbl_pool = &multixri_pool->pbl_pool;
20013 /* Check if local pbl_pool is available */
20014 ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
20016 #ifdef LPFC_MXP_STAT
20017 multixri_pool->local_pbl_hit_count++;
20022 hwq_count = phba->cfg_hdw_queue;
20024 /* Get the next hwqid which was found last time */
20025 next_hwqid = multixri_pool->rrb_next_hwqid;
20028 /* Go to next hwq */
20029 next_hwqid = (next_hwqid + 1) % hwq_count;
20031 next_multixri_pool =
20032 phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
20033 pbl_pool = &next_multixri_pool->pbl_pool;
20035 /* Check if the public free xri pool is available */
20036 ret = _lpfc_move_xri_pbl_to_pvt(
20037 phba, qp, pbl_pool, pvt_pool, count);
20039 /* Exit while-loop if success or all hwqid are checked */
20040 } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
20042 /* Starting point for the next time */
20043 multixri_pool->rrb_next_hwqid = next_hwqid;
20046 /* stats: all public pools are empty*/
20047 multixri_pool->pbl_empty_count++;
20050 #ifdef LPFC_MXP_STAT
20052 if (next_hwqid == hwqid)
20053 multixri_pool->local_pbl_hit_count++;
20055 multixri_pool->other_pbl_hit_count++;
20061 * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
20062 * @phba: pointer to lpfc hba data structure.
20063 * @qp: belong to which HWQ.
20065 * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
20068 void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
20070 struct lpfc_multixri_pool *multixri_pool;
20071 struct lpfc_pvt_pool *pvt_pool;
20073 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
20074 pvt_pool = &multixri_pool->pvt_pool;
20076 if (pvt_pool->count < pvt_pool->low_watermark)
20077 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
20081 * lpfc_release_io_buf - Return one IO buf back to free pool
20082 * @phba: pointer to lpfc hba data structure.
20083 * @lpfc_ncmd: IO buf to be returned.
20084 * @qp: belong to which HWQ.
20086 * This routine returns one IO buf back to free pool. If this is an urgent IO,
20087 * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
20088 * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
20089 * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to
20090 * lpfc_io_buf_list_put.
20092 void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
20093 struct lpfc_sli4_hdw_queue *qp)
20095 unsigned long iflag;
20096 struct lpfc_pbl_pool *pbl_pool;
20097 struct lpfc_pvt_pool *pvt_pool;
20098 struct lpfc_epd_pool *epd_pool;
20104 /* MUST zero fields if buffer is reused by another protocol */
20105 lpfc_ncmd->nvmeCmd = NULL;
20106 lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL;
20107 lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL;
20109 if (phba->cfg_xri_rebalancing) {
20110 if (lpfc_ncmd->expedite) {
20111 /* Return to expedite pool */
20112 epd_pool = &phba->epd_pool;
20113 spin_lock_irqsave(&epd_pool->lock, iflag);
20114 list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
20116 spin_unlock_irqrestore(&epd_pool->lock, iflag);
20120 /* Avoid invalid access if an IO sneaks in and is being rejected
20121 * just _after_ xri pools are destroyed in lpfc_offline.
20122 * Nothing much can be done at this point.
20124 if (!qp->p_multixri_pool)
20127 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20128 pvt_pool = &qp->p_multixri_pool->pvt_pool;
20130 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
20131 abts_io_bufs = qp->abts_scsi_io_bufs;
20132 abts_io_bufs += qp->abts_nvme_io_bufs;
20134 xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
20135 xri_limit = qp->p_multixri_pool->xri_limit;
20137 #ifdef LPFC_MXP_STAT
20138 if (xri_owned <= xri_limit)
20139 qp->p_multixri_pool->below_limit_count++;
20141 qp->p_multixri_pool->above_limit_count++;
20144 /* XRI goes to either public or private free xri pool
20145 * based on watermark and xri_limit
20147 if ((pvt_pool->count < pvt_pool->low_watermark) ||
20148 (xri_owned < xri_limit &&
20149 pvt_pool->count < pvt_pool->high_watermark)) {
20150 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
20151 qp, free_pvt_pool);
20152 list_add_tail(&lpfc_ncmd->list,
20155 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
20157 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
20158 qp, free_pub_pool);
20159 list_add_tail(&lpfc_ncmd->list,
20162 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20165 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
20167 list_add_tail(&lpfc_ncmd->list,
20168 &qp->lpfc_io_buf_list_put);
20170 spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
20174 if (phba->cfg_xpsgl && !phba->nvmet_support &&
20175 !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
20176 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
20178 if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
20179 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
20183 * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
20184 * @phba: pointer to lpfc hba data structure.
20185 * @pvt_pool: pointer to private pool data structure.
20186 * @ndlp: pointer to lpfc nodelist data structure.
20188 * This routine tries to get one free IO buf from private pool.
20191 * pointer to one free IO buf - if private pool is not empty
20192 * NULL - if private pool is empty
20194 static struct lpfc_io_buf *
20195 lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
20196 struct lpfc_sli4_hdw_queue *qp,
20197 struct lpfc_pvt_pool *pvt_pool,
20198 struct lpfc_nodelist *ndlp)
20200 struct lpfc_io_buf *lpfc_ncmd;
20201 struct lpfc_io_buf *lpfc_ncmd_next;
20202 unsigned long iflag;
20204 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
20205 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
20206 &pvt_pool->list, list) {
20207 if (lpfc_test_rrq_active(
20208 phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
20210 list_del(&lpfc_ncmd->list);
20212 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
20215 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
20221 * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
20222 * @phba: pointer to lpfc hba data structure.
20224 * This routine tries to get one free IO buf from expedite pool.
20227 * pointer to one free IO buf - if expedite pool is not empty
20228 * NULL - if expedite pool is empty
20230 static struct lpfc_io_buf *
20231 lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
20233 struct lpfc_io_buf *lpfc_ncmd;
20234 struct lpfc_io_buf *lpfc_ncmd_next;
20235 unsigned long iflag;
20236 struct lpfc_epd_pool *epd_pool;
20238 epd_pool = &phba->epd_pool;
20241 spin_lock_irqsave(&epd_pool->lock, iflag);
20242 if (epd_pool->count > 0) {
20243 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
20244 &epd_pool->list, list) {
20245 list_del(&lpfc_ncmd->list);
20250 spin_unlock_irqrestore(&epd_pool->lock, iflag);
20256 * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
20257 * @phba: pointer to lpfc hba data structure.
20258 * @ndlp: pointer to lpfc nodelist data structure.
20259 * @hwqid: belong to which HWQ
20260 * @expedite: 1 means this request is urgent.
20262 * This routine will do the following actions and then return a pointer to
20265 * 1. If private free xri count is empty, move some XRIs from public to
20267 * 2. Get one XRI from private free xri pool.
20268 * 3. If we fail to get one from pvt_pool and this is an expedite request,
20269 * get one free xri from expedite pool.
20271 * Note: ndlp is only used on SCSI side for RRQ testing.
20272 * The caller should pass NULL for ndlp on NVME side.
20275 * pointer to one free IO buf - if private pool is not empty
20276 * NULL - if private pool is empty
20278 static struct lpfc_io_buf *
20279 lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
20280 struct lpfc_nodelist *ndlp,
20281 int hwqid, int expedite)
20283 struct lpfc_sli4_hdw_queue *qp;
20284 struct lpfc_multixri_pool *multixri_pool;
20285 struct lpfc_pvt_pool *pvt_pool;
20286 struct lpfc_io_buf *lpfc_ncmd;
20288 qp = &phba->sli4_hba.hdwq[hwqid];
20290 multixri_pool = qp->p_multixri_pool;
20291 pvt_pool = &multixri_pool->pvt_pool;
20292 multixri_pool->io_req_count++;
20294 /* If pvt_pool is empty, move some XRIs from public to private pool */
20295 if (pvt_pool->count == 0)
20296 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
20298 /* Get one XRI from private free xri pool */
20299 lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
20302 lpfc_ncmd->hdwq = qp;
20303 lpfc_ncmd->hdwq_no = hwqid;
20304 } else if (expedite) {
20305 /* If we fail to get one from pvt_pool and this is an expedite
20306 * request, get one free xri from expedite pool.
20308 lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
20314 static inline struct lpfc_io_buf *
20315 lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
20317 struct lpfc_sli4_hdw_queue *qp;
20318 struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
20320 qp = &phba->sli4_hba.hdwq[idx];
20321 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
20322 &qp->lpfc_io_buf_list_get, list) {
20323 if (lpfc_test_rrq_active(phba, ndlp,
20324 lpfc_cmd->cur_iocbq.sli4_lxritag))
20327 if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
20330 list_del_init(&lpfc_cmd->list);
20332 lpfc_cmd->hdwq = qp;
20333 lpfc_cmd->hdwq_no = idx;
20340 * lpfc_get_io_buf - Get one IO buffer from free pool
20341 * @phba: The HBA for which this call is being executed.
20342 * @ndlp: pointer to lpfc nodelist data structure.
20343 * @hwqid: belong to which HWQ
20344 * @expedite: 1 means this request is urgent.
20346 * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
20347 * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
20348 * a IO buffer from head of @hdwq io_buf_list and returns to caller.
20350 * Note: ndlp is only used on SCSI side for RRQ testing.
20351 * The caller should pass NULL for ndlp on NVME side.
20355 * Pointer to lpfc_io_buf - Success
20357 struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
20358 struct lpfc_nodelist *ndlp,
20359 u32 hwqid, int expedite)
20361 struct lpfc_sli4_hdw_queue *qp;
20362 unsigned long iflag;
20363 struct lpfc_io_buf *lpfc_cmd;
20365 qp = &phba->sli4_hba.hdwq[hwqid];
20368 if (phba->cfg_xri_rebalancing)
20369 lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
20370 phba, ndlp, hwqid, expedite);
20372 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
20373 qp, alloc_xri_get);
20374 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
20375 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
20377 lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
20378 qp, alloc_xri_put);
20379 list_splice(&qp->lpfc_io_buf_list_put,
20380 &qp->lpfc_io_buf_list_get);
20381 qp->get_io_bufs += qp->put_io_bufs;
20382 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
20383 qp->put_io_bufs = 0;
20384 spin_unlock(&qp->io_buf_list_put_lock);
20385 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
20387 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
20389 spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
20396 * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
20397 * @phba: The HBA for which this call is being executed.
20398 * @lpfc_buf: IO buf structure to append the SGL chunk
20400 * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
20401 * and will allocate an SGL chunk if the pool is empty.
20405 * Pointer to sli4_hybrid_sgl - Success
20407 struct sli4_hybrid_sgl *
20408 lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
20410 struct sli4_hybrid_sgl *list_entry = NULL;
20411 struct sli4_hybrid_sgl *tmp = NULL;
20412 struct sli4_hybrid_sgl *allocated_sgl = NULL;
20413 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20414 struct list_head *buf_list = &hdwq->sgl_list;
20416 spin_lock_irq(&hdwq->hdwq_lock);
20418 if (likely(!list_empty(buf_list))) {
20419 /* break off 1 chunk from the sgl_list */
20420 list_for_each_entry_safe(list_entry, tmp,
20421 buf_list, list_node) {
20422 list_move_tail(&list_entry->list_node,
20423 &lpfc_buf->dma_sgl_xtra_list);
20427 /* allocate more */
20428 spin_unlock_irq(&hdwq->hdwq_lock);
20429 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
20430 cpu_to_node(smp_processor_id()));
20432 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20433 "8353 error kmalloc memory for HDWQ "
20435 lpfc_buf->hdwq_no, __func__);
20439 tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
20440 GFP_ATOMIC, &tmp->dma_phys_sgl);
20441 if (!tmp->dma_sgl) {
20442 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20443 "8354 error pool_alloc memory for HDWQ "
20445 lpfc_buf->hdwq_no, __func__);
20450 spin_lock_irq(&hdwq->hdwq_lock);
20451 list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
20454 allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
20455 struct sli4_hybrid_sgl,
20458 spin_unlock_irq(&hdwq->hdwq_lock);
20460 return allocated_sgl;
20464 * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
20465 * @phba: The HBA for which this call is being executed.
20466 * @lpfc_buf: IO buf structure with the SGL chunk
20468 * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
20475 lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
20478 struct sli4_hybrid_sgl *list_entry = NULL;
20479 struct sli4_hybrid_sgl *tmp = NULL;
20480 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20481 struct list_head *buf_list = &hdwq->sgl_list;
20483 spin_lock_irq(&hdwq->hdwq_lock);
20485 if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
20486 list_for_each_entry_safe(list_entry, tmp,
20487 &lpfc_buf->dma_sgl_xtra_list,
20489 list_move_tail(&list_entry->list_node,
20496 spin_unlock_irq(&hdwq->hdwq_lock);
20501 * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
20502 * @phba: phba object
20503 * @hdwq: hdwq to cleanup sgl buff resources on
20505 * This routine frees all SGL chunks of hdwq SGL chunk pool.
20511 lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
20512 struct lpfc_sli4_hdw_queue *hdwq)
20514 struct list_head *buf_list = &hdwq->sgl_list;
20515 struct sli4_hybrid_sgl *list_entry = NULL;
20516 struct sli4_hybrid_sgl *tmp = NULL;
20518 spin_lock_irq(&hdwq->hdwq_lock);
20520 /* Free sgl pool */
20521 list_for_each_entry_safe(list_entry, tmp,
20522 buf_list, list_node) {
20523 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
20524 list_entry->dma_sgl,
20525 list_entry->dma_phys_sgl);
20526 list_del(&list_entry->list_node);
20530 spin_unlock_irq(&hdwq->hdwq_lock);
20534 * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
20535 * @phba: The HBA for which this call is being executed.
20536 * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
20538 * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
20539 * and will allocate an CMD/RSP buffer if the pool is empty.
20543 * Pointer to fcp_cmd_rsp_buf - Success
20545 struct fcp_cmd_rsp_buf *
20546 lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
20547 struct lpfc_io_buf *lpfc_buf)
20549 struct fcp_cmd_rsp_buf *list_entry = NULL;
20550 struct fcp_cmd_rsp_buf *tmp = NULL;
20551 struct fcp_cmd_rsp_buf *allocated_buf = NULL;
20552 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20553 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
20555 spin_lock_irq(&hdwq->hdwq_lock);
20557 if (likely(!list_empty(buf_list))) {
20558 /* break off 1 chunk from the list */
20559 list_for_each_entry_safe(list_entry, tmp,
20562 list_move_tail(&list_entry->list_node,
20563 &lpfc_buf->dma_cmd_rsp_list);
20567 /* allocate more */
20568 spin_unlock_irq(&hdwq->hdwq_lock);
20569 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
20570 cpu_to_node(smp_processor_id()));
20572 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20573 "8355 error kmalloc memory for HDWQ "
20575 lpfc_buf->hdwq_no, __func__);
20579 tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool,
20581 &tmp->fcp_cmd_rsp_dma_handle);
20583 if (!tmp->fcp_cmnd) {
20584 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20585 "8356 error pool_alloc memory for HDWQ "
20587 lpfc_buf->hdwq_no, __func__);
20592 tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
20593 sizeof(struct fcp_cmnd));
20595 spin_lock_irq(&hdwq->hdwq_lock);
20596 list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
20599 allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
20600 struct fcp_cmd_rsp_buf,
20603 spin_unlock_irq(&hdwq->hdwq_lock);
20605 return allocated_buf;
20609 * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
20610 * @phba: The HBA for which this call is being executed.
20611 * @lpfc_buf: IO buf structure with the CMD/RSP buf
20613 * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
20620 lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
20621 struct lpfc_io_buf *lpfc_buf)
20624 struct fcp_cmd_rsp_buf *list_entry = NULL;
20625 struct fcp_cmd_rsp_buf *tmp = NULL;
20626 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20627 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
20629 spin_lock_irq(&hdwq->hdwq_lock);
20631 if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
20632 list_for_each_entry_safe(list_entry, tmp,
20633 &lpfc_buf->dma_cmd_rsp_list,
20635 list_move_tail(&list_entry->list_node,
20642 spin_unlock_irq(&hdwq->hdwq_lock);
20647 * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
20648 * @phba: phba object
20649 * @hdwq: hdwq to cleanup cmd rsp buff resources on
20651 * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
20657 lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
20658 struct lpfc_sli4_hdw_queue *hdwq)
20660 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
20661 struct fcp_cmd_rsp_buf *list_entry = NULL;
20662 struct fcp_cmd_rsp_buf *tmp = NULL;
20664 spin_lock_irq(&hdwq->hdwq_lock);
20666 /* Free cmd_rsp buf pool */
20667 list_for_each_entry_safe(list_entry, tmp,
20670 dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
20671 list_entry->fcp_cmnd,
20672 list_entry->fcp_cmd_rsp_dma_handle);
20673 list_del(&list_entry->list_node);
20677 spin_unlock_irq(&hdwq->hdwq_lock);