1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 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>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_crtn.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_compat.h"
54 #include "lpfc_debugfs.h"
55 #include "lpfc_vport.h"
56 #include "lpfc_version.h"
58 /* There are only four IOCB completion types. */
59 typedef enum _lpfc_iocb_type {
67 /* Provide function prototypes local to this module. */
68 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
70 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
71 uint8_t *, uint32_t *);
72 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
74 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
76 static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
77 struct hbq_dmabuf *dmabuf);
78 static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba,
79 struct lpfc_queue *cq, struct lpfc_cqe *cqe);
80 static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
82 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba,
83 struct lpfc_queue *eq,
84 struct lpfc_eqe *eqe);
85 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
86 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
87 static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q);
88 static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba,
89 struct lpfc_queue *cq,
90 struct lpfc_cqe *cqe);
93 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
98 #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
100 * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
101 * @srcp: Source memory pointer.
102 * @destp: Destination memory pointer.
103 * @cnt: Number of words required to be copied.
104 * Must be a multiple of sizeof(uint64_t)
106 * This function is used for copying data between driver memory
107 * and the SLI WQ. This function also changes the endianness
108 * of each word if native endianness is different from SLI
109 * endianness. This function can be called with or without
113 lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
115 uint64_t *src = srcp;
116 uint64_t *dest = destp;
119 for (i = 0; i < (int)cnt; i += sizeof(uint64_t))
123 #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
127 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
128 * @q: The Work Queue to operate on.
129 * @wqe: The work Queue Entry to put on the Work queue.
131 * This routine will copy the contents of @wqe to the next available entry on
132 * the @q. This function will then ring the Work Queue Doorbell to signal the
133 * HBA to start processing the Work Queue Entry. This function returns 0 if
134 * successful. If no entries are available on @q then this function will return
136 * The caller is expected to hold the hbalock when calling this routine.
139 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe)
141 union lpfc_wqe *temp_wqe;
142 struct lpfc_register doorbell;
149 /* sanity check on queue memory */
152 temp_wqe = lpfc_sli4_qe(q, q->host_index);
154 /* If the host has not yet processed the next entry then we are done */
155 idx = ((q->host_index + 1) % q->entry_count);
156 if (idx == q->hba_index) {
161 /* set consumption flag every once in a while */
162 if (!((q->host_index + 1) % q->notify_interval))
163 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
165 bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
166 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
167 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
168 lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
169 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
170 /* write to DPP aperture taking advatage of Combined Writes */
171 tmp = (uint8_t *)temp_wqe;
173 for (i = 0; i < q->entry_size; i += sizeof(uint64_t))
174 __raw_writeq(*((uint64_t *)(tmp + i)),
177 for (i = 0; i < q->entry_size; i += sizeof(uint32_t))
178 __raw_writel(*((uint32_t *)(tmp + i)),
182 /* ensure WQE bcopy and DPP flushed before doorbell write */
185 /* Update the host index before invoking device */
186 host_index = q->host_index;
192 if (q->db_format == LPFC_DB_LIST_FORMAT) {
193 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
194 bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1);
195 bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1);
196 bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell,
198 bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell,
201 bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
202 bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
204 /* Leave bits <23:16> clear for if_type 6 dpp */
205 if_type = bf_get(lpfc_sli_intf_if_type,
206 &q->phba->sli4_hba.sli_intf);
207 if (if_type != LPFC_SLI_INTF_IF_TYPE_6)
208 bf_set(lpfc_wq_db_list_fm_index, &doorbell,
211 } else if (q->db_format == LPFC_DB_RING_FORMAT) {
212 bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
213 bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
217 writel(doorbell.word0, q->db_regaddr);
223 * lpfc_sli4_wq_release - Updates internal hba index for WQ
224 * @q: The Work Queue to operate on.
225 * @index: The index to advance the hba index to.
227 * This routine will update the HBA index of a queue to reflect consumption of
228 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
229 * an entry the host calls this function to update the queue's internal
233 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
235 /* sanity check on queue memory */
239 q->hba_index = index;
243 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
244 * @q: The Mailbox Queue to operate on.
245 * @wqe: The Mailbox Queue Entry to put on the Work queue.
247 * This routine will copy the contents of @mqe to the next available entry on
248 * the @q. This function will then ring the Work Queue Doorbell to signal the
249 * HBA to start processing the Work Queue Entry. This function returns 0 if
250 * successful. If no entries are available on @q then this function will return
252 * The caller is expected to hold the hbalock when calling this routine.
255 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
257 struct lpfc_mqe *temp_mqe;
258 struct lpfc_register doorbell;
260 /* sanity check on queue memory */
263 temp_mqe = lpfc_sli4_qe(q, q->host_index);
265 /* If the host has not yet processed the next entry then we are done */
266 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
268 lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
269 /* Save off the mailbox pointer for completion */
270 q->phba->mbox = (MAILBOX_t *)temp_mqe;
272 /* Update the host index before invoking device */
273 q->host_index = ((q->host_index + 1) % q->entry_count);
277 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
278 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
279 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
284 * lpfc_sli4_mq_release - Updates internal hba index for MQ
285 * @q: The Mailbox Queue to operate on.
287 * This routine will update the HBA index of a queue to reflect consumption of
288 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
289 * an entry the host calls this function to update the queue's internal
290 * pointers. This routine returns the number of entries that were consumed by
294 lpfc_sli4_mq_release(struct lpfc_queue *q)
296 /* sanity check on queue memory */
300 /* Clear the mailbox pointer for completion */
301 q->phba->mbox = NULL;
302 q->hba_index = ((q->hba_index + 1) % q->entry_count);
307 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
308 * @q: The Event Queue to get the first valid EQE from
310 * This routine will get the first valid Event Queue Entry from @q, update
311 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
312 * the Queue (no more work to do), or the Queue is full of EQEs that have been
313 * processed, but not popped back to the HBA then this routine will return NULL.
315 static struct lpfc_eqe *
316 lpfc_sli4_eq_get(struct lpfc_queue *q)
318 struct lpfc_eqe *eqe;
320 /* sanity check on queue memory */
323 eqe = lpfc_sli4_qe(q, q->host_index);
325 /* If the next EQE is not valid then we are done */
326 if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid)
330 * insert barrier for instruction interlock : data from the hardware
331 * must have the valid bit checked before it can be copied and acted
332 * upon. Speculative instructions were allowing a bcopy at the start
333 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
334 * after our return, to copy data before the valid bit check above
335 * was done. As such, some of the copied data was stale. The barrier
336 * ensures the check is before any data is copied.
343 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
344 * @q: The Event Queue to disable interrupts
348 lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
350 struct lpfc_register doorbell;
353 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
354 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
355 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
356 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
357 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
358 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
362 * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
363 * @q: The Event Queue to disable interrupts
367 lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q)
369 struct lpfc_register doorbell;
372 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
373 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
377 * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state
378 * @phba: adapter with EQ
379 * @q: The Event Queue that the host has completed processing for.
380 * @count: Number of elements that have been consumed
381 * @arm: Indicates whether the host wants to arms this CQ.
383 * This routine will notify the HBA, by ringing the doorbell, that count
384 * number of EQEs have been processed. The @arm parameter indicates whether
385 * the queue should be rearmed when ringing the doorbell.
388 lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
389 uint32_t count, bool arm)
391 struct lpfc_register doorbell;
393 /* sanity check on queue memory */
394 if (unlikely(!q || (count == 0 && !arm)))
397 /* ring doorbell for number popped */
400 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
401 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
403 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
404 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
405 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
406 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
407 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
408 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
409 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
410 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
411 readl(q->phba->sli4_hba.EQDBregaddr);
415 * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state
416 * @phba: adapter with EQ
417 * @q: The Event Queue that the host has completed processing for.
418 * @count: Number of elements that have been consumed
419 * @arm: Indicates whether the host wants to arms this CQ.
421 * This routine will notify the HBA, by ringing the doorbell, that count
422 * number of EQEs have been processed. The @arm parameter indicates whether
423 * the queue should be rearmed when ringing the doorbell.
426 lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
427 uint32_t count, bool arm)
429 struct lpfc_register doorbell;
431 /* sanity check on queue memory */
432 if (unlikely(!q || (count == 0 && !arm)))
435 /* ring doorbell for number popped */
438 bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1);
439 bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count);
440 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
441 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
442 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
443 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
444 readl(q->phba->sli4_hba.EQDBregaddr);
448 __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
449 struct lpfc_eqe *eqe)
451 if (!phba->sli4_hba.pc_sli4_params.eqav)
452 bf_set_le32(lpfc_eqe_valid, eqe, 0);
454 eq->host_index = ((eq->host_index + 1) % eq->entry_count);
456 /* if the index wrapped around, toggle the valid bit */
457 if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index)
458 eq->qe_valid = (eq->qe_valid) ? 0 : 1;
462 lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
464 struct lpfc_eqe *eqe = NULL;
465 u32 eq_count = 0, cq_count = 0;
466 struct lpfc_cqe *cqe = NULL;
467 struct lpfc_queue *cq = NULL, *childq = NULL;
470 /* walk all the EQ entries and drop on the floor */
471 eqe = lpfc_sli4_eq_get(eq);
473 /* Get the reference to the corresponding CQ */
474 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
477 list_for_each_entry(childq, &eq->child_list, list) {
478 if (childq->queue_id == cqid) {
483 /* If CQ is valid, iterate through it and drop all the CQEs */
485 cqe = lpfc_sli4_cq_get(cq);
487 __lpfc_sli4_consume_cqe(phba, cq, cqe);
489 cqe = lpfc_sli4_cq_get(cq);
491 /* Clear and re-arm the CQ */
492 phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count,
496 __lpfc_sli4_consume_eqe(phba, eq, eqe);
498 eqe = lpfc_sli4_eq_get(eq);
501 /* Clear and re-arm the EQ */
502 phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM);
506 lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq,
509 struct lpfc_eqe *eqe;
510 int count = 0, consumed = 0;
512 if (cmpxchg(&eq->queue_claimed, 0, 1) != 0)
515 eqe = lpfc_sli4_eq_get(eq);
517 lpfc_sli4_hba_handle_eqe(phba, eq, eqe);
518 __lpfc_sli4_consume_eqe(phba, eq, eqe);
521 if (!(++count % eq->max_proc_limit))
524 if (!(count % eq->notify_interval)) {
525 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed,
530 eqe = lpfc_sli4_eq_get(eq);
532 eq->EQ_processed += count;
534 /* Track the max number of EQEs processed in 1 intr */
535 if (count > eq->EQ_max_eqe)
536 eq->EQ_max_eqe = count;
538 xchg(&eq->queue_claimed, 0);
541 /* Always clear the EQ. */
542 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm);
548 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
549 * @q: The Completion Queue to get the first valid CQE from
551 * This routine will get the first valid Completion Queue Entry from @q, update
552 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
553 * the Queue (no more work to do), or the Queue is full of CQEs that have been
554 * processed, but not popped back to the HBA then this routine will return NULL.
556 static struct lpfc_cqe *
557 lpfc_sli4_cq_get(struct lpfc_queue *q)
559 struct lpfc_cqe *cqe;
561 /* sanity check on queue memory */
564 cqe = lpfc_sli4_qe(q, q->host_index);
566 /* If the next CQE is not valid then we are done */
567 if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid)
571 * insert barrier for instruction interlock : data from the hardware
572 * must have the valid bit checked before it can be copied and acted
573 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
574 * instructions allowing action on content before valid bit checked,
575 * add barrier here as well. May not be needed as "content" is a
576 * single 32-bit entity here (vs multi word structure for cq's).
583 __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
584 struct lpfc_cqe *cqe)
586 if (!phba->sli4_hba.pc_sli4_params.cqav)
587 bf_set_le32(lpfc_cqe_valid, cqe, 0);
589 cq->host_index = ((cq->host_index + 1) % cq->entry_count);
591 /* if the index wrapped around, toggle the valid bit */
592 if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index)
593 cq->qe_valid = (cq->qe_valid) ? 0 : 1;
597 * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state.
598 * @phba: the adapter with the CQ
599 * @q: The Completion Queue that the host has completed processing for.
600 * @count: the number of elements that were consumed
601 * @arm: Indicates whether the host wants to arms this CQ.
603 * This routine will notify the HBA, by ringing the doorbell, that the
604 * CQEs have been processed. The @arm parameter specifies whether the
605 * queue should be rearmed when ringing the doorbell.
608 lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
609 uint32_t count, bool arm)
611 struct lpfc_register doorbell;
613 /* sanity check on queue memory */
614 if (unlikely(!q || (count == 0 && !arm)))
617 /* ring doorbell for number popped */
620 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
621 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
622 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
623 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
624 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
625 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
626 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
630 * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state.
631 * @phba: the adapter with the CQ
632 * @q: The Completion Queue that the host has completed processing for.
633 * @count: the number of elements that were consumed
634 * @arm: Indicates whether the host wants to arms this CQ.
636 * This routine will notify the HBA, by ringing the doorbell, that the
637 * CQEs have been processed. The @arm parameter specifies whether the
638 * queue should be rearmed when ringing the doorbell.
641 lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
642 uint32_t count, bool arm)
644 struct lpfc_register doorbell;
646 /* sanity check on queue memory */
647 if (unlikely(!q || (count == 0 && !arm)))
650 /* ring doorbell for number popped */
653 bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1);
654 bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count);
655 bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id);
656 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
660 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
661 * @q: The Header Receive Queue to operate on.
662 * @wqe: The Receive Queue Entry to put on the Receive queue.
664 * This routine will copy the contents of @wqe to the next available entry on
665 * the @q. This function will then ring the Receive Queue Doorbell to signal the
666 * HBA to start processing the Receive Queue Entry. This function returns the
667 * index that the rqe was copied to if successful. If no entries are available
668 * on @q then this function will return -ENOMEM.
669 * The caller is expected to hold the hbalock when calling this routine.
672 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
673 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
675 struct lpfc_rqe *temp_hrqe;
676 struct lpfc_rqe *temp_drqe;
677 struct lpfc_register doorbell;
681 /* sanity check on queue memory */
682 if (unlikely(!hq) || unlikely(!dq))
684 hq_put_index = hq->host_index;
685 dq_put_index = dq->host_index;
686 temp_hrqe = lpfc_sli4_qe(hq, hq_put_index);
687 temp_drqe = lpfc_sli4_qe(dq, dq_put_index);
689 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
691 if (hq_put_index != dq_put_index)
693 /* If the host has not yet processed the next entry then we are done */
694 if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index)
696 lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
697 lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
699 /* Update the host index to point to the next slot */
700 hq->host_index = ((hq_put_index + 1) % hq->entry_count);
701 dq->host_index = ((dq_put_index + 1) % dq->entry_count);
704 /* Ring The Header Receive Queue Doorbell */
705 if (!(hq->host_index % hq->notify_interval)) {
707 if (hq->db_format == LPFC_DB_RING_FORMAT) {
708 bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
709 hq->notify_interval);
710 bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
711 } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
712 bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
713 hq->notify_interval);
714 bf_set(lpfc_rq_db_list_fm_index, &doorbell,
716 bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
720 writel(doorbell.word0, hq->db_regaddr);
726 * lpfc_sli4_rq_release - Updates internal hba index for RQ
727 * @q: The Header Receive Queue to operate on.
729 * This routine will update the HBA index of a queue to reflect consumption of
730 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
731 * consumed an entry the host calls this function to update the queue's
732 * internal pointers. This routine returns the number of entries that were
733 * consumed by the HBA.
736 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
738 /* sanity check on queue memory */
739 if (unlikely(!hq) || unlikely(!dq))
742 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
744 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
745 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
750 * lpfc_cmd_iocb - Get next command iocb entry in the ring
751 * @phba: Pointer to HBA context object.
752 * @pring: Pointer to driver SLI ring object.
754 * This function returns pointer to next command iocb entry
755 * in the command ring. The caller must hold hbalock to prevent
756 * other threads consume the next command iocb.
757 * SLI-2/SLI-3 provide different sized iocbs.
759 static inline IOCB_t *
760 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
762 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
763 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
767 * lpfc_resp_iocb - Get next response iocb entry in the ring
768 * @phba: Pointer to HBA context object.
769 * @pring: Pointer to driver SLI ring object.
771 * This function returns pointer to next response iocb entry
772 * in the response ring. The caller must hold hbalock to make sure
773 * that no other thread consume the next response iocb.
774 * SLI-2/SLI-3 provide different sized iocbs.
776 static inline IOCB_t *
777 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
779 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
780 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
784 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
785 * @phba: Pointer to HBA context object.
787 * This function is called with hbalock held. This function
788 * allocates a new driver iocb object from the iocb pool. If the
789 * allocation is successful, it returns pointer to the newly
790 * allocated iocb object else it returns NULL.
793 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
795 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
796 struct lpfc_iocbq * iocbq = NULL;
798 lockdep_assert_held(&phba->hbalock);
800 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
803 if (phba->iocb_cnt > phba->iocb_max)
804 phba->iocb_max = phba->iocb_cnt;
809 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
810 * @phba: Pointer to HBA context object.
811 * @xritag: XRI value.
813 * This function clears the sglq pointer from the array of acive
814 * sglq's. The xritag that is passed in is used to index into the
815 * array. Before the xritag can be used it needs to be adjusted
816 * by subtracting the xribase.
818 * Returns sglq ponter = success, NULL = Failure.
821 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
823 struct lpfc_sglq *sglq;
825 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
826 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
831 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
832 * @phba: Pointer to HBA context object.
833 * @xritag: XRI value.
835 * This function returns the sglq pointer from the array of acive
836 * sglq's. The xritag that is passed in is used to index into the
837 * array. Before the xritag can be used it needs to be adjusted
838 * by subtracting the xribase.
840 * Returns sglq ponter = success, NULL = Failure.
843 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
845 struct lpfc_sglq *sglq;
847 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
852 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
853 * @phba: Pointer to HBA context object.
854 * @xritag: xri used in this exchange.
855 * @rrq: The RRQ to be cleared.
859 lpfc_clr_rrq_active(struct lpfc_hba *phba,
861 struct lpfc_node_rrq *rrq)
863 struct lpfc_nodelist *ndlp = NULL;
865 if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp))
866 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
868 /* The target DID could have been swapped (cable swap)
869 * we should use the ndlp from the findnode if it is
872 if ((!ndlp) && rrq->ndlp)
878 if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
881 rrq->rrq_stop_time = 0;
884 mempool_free(rrq, phba->rrq_pool);
888 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
889 * @phba: Pointer to HBA context object.
891 * This function is called with hbalock held. This function
892 * Checks if stop_time (ratov from setting rrq active) has
893 * been reached, if it has and the send_rrq flag is set then
894 * it will call lpfc_send_rrq. If the send_rrq flag is not set
895 * then it will just call the routine to clear the rrq and
896 * free the rrq resource.
897 * The timer is set to the next rrq that is going to expire before
898 * leaving the routine.
902 lpfc_handle_rrq_active(struct lpfc_hba *phba)
904 struct lpfc_node_rrq *rrq;
905 struct lpfc_node_rrq *nextrrq;
906 unsigned long next_time;
907 unsigned long iflags;
910 spin_lock_irqsave(&phba->hbalock, iflags);
911 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
912 next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
913 list_for_each_entry_safe(rrq, nextrrq,
914 &phba->active_rrq_list, list) {
915 if (time_after(jiffies, rrq->rrq_stop_time))
916 list_move(&rrq->list, &send_rrq);
917 else if (time_before(rrq->rrq_stop_time, next_time))
918 next_time = rrq->rrq_stop_time;
920 spin_unlock_irqrestore(&phba->hbalock, iflags);
921 if ((!list_empty(&phba->active_rrq_list)) &&
922 (!(phba->pport->load_flag & FC_UNLOADING)))
923 mod_timer(&phba->rrq_tmr, next_time);
924 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
925 list_del(&rrq->list);
926 if (!rrq->send_rrq) {
927 /* this call will free the rrq */
928 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
929 } else if (lpfc_send_rrq(phba, rrq)) {
930 /* if we send the rrq then the completion handler
931 * will clear the bit in the xribitmap.
933 lpfc_clr_rrq_active(phba, rrq->xritag,
940 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
941 * @vport: Pointer to vport context object.
942 * @xri: The xri used in the exchange.
943 * @did: The targets DID for this exchange.
945 * returns NULL = rrq not found in the phba->active_rrq_list.
946 * rrq = rrq for this xri and target.
948 struct lpfc_node_rrq *
949 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
951 struct lpfc_hba *phba = vport->phba;
952 struct lpfc_node_rrq *rrq;
953 struct lpfc_node_rrq *nextrrq;
954 unsigned long iflags;
956 if (phba->sli_rev != LPFC_SLI_REV4)
958 spin_lock_irqsave(&phba->hbalock, iflags);
959 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
960 if (rrq->vport == vport && rrq->xritag == xri &&
961 rrq->nlp_DID == did){
962 list_del(&rrq->list);
963 spin_unlock_irqrestore(&phba->hbalock, iflags);
967 spin_unlock_irqrestore(&phba->hbalock, iflags);
972 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
973 * @vport: Pointer to vport context object.
974 * @ndlp: Pointer to the lpfc_node_list structure.
975 * If ndlp is NULL Remove all active RRQs for this vport from the
976 * phba->active_rrq_list and clear the rrq.
977 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
980 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
983 struct lpfc_hba *phba = vport->phba;
984 struct lpfc_node_rrq *rrq;
985 struct lpfc_node_rrq *nextrrq;
986 unsigned long iflags;
989 if (phba->sli_rev != LPFC_SLI_REV4)
992 lpfc_sli4_vport_delete_els_xri_aborted(vport);
993 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
995 spin_lock_irqsave(&phba->hbalock, iflags);
996 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list)
997 if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp))
998 list_move(&rrq->list, &rrq_list);
999 spin_unlock_irqrestore(&phba->hbalock, iflags);
1001 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
1002 list_del(&rrq->list);
1003 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1008 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
1009 * @phba: Pointer to HBA context object.
1010 * @ndlp: Targets nodelist pointer for this exchange.
1011 * @xritag the xri in the bitmap to test.
1013 * This function returns:
1014 * 0 = rrq not active for this xri
1015 * 1 = rrq is valid for this xri.
1018 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1023 if (!ndlp->active_rrqs_xri_bitmap)
1025 if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1032 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
1033 * @phba: Pointer to HBA context object.
1034 * @ndlp: nodelist pointer for this target.
1035 * @xritag: xri used in this exchange.
1036 * @rxid: Remote Exchange ID.
1037 * @send_rrq: Flag used to determine if we should send rrq els cmd.
1039 * This function takes the hbalock.
1040 * The active bit is always set in the active rrq xri_bitmap even
1041 * if there is no slot avaiable for the other rrq information.
1043 * returns 0 rrq actived for this xri
1044 * < 0 No memory or invalid ndlp.
1047 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1048 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
1050 unsigned long iflags;
1051 struct lpfc_node_rrq *rrq;
1057 if (!phba->cfg_enable_rrq)
1060 spin_lock_irqsave(&phba->hbalock, iflags);
1061 if (phba->pport->load_flag & FC_UNLOADING) {
1062 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1067 * set the active bit even if there is no mem available.
1069 if (NLP_CHK_FREE_REQ(ndlp))
1072 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
1075 if (!ndlp->active_rrqs_xri_bitmap)
1078 if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1081 spin_unlock_irqrestore(&phba->hbalock, iflags);
1082 rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL);
1084 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1085 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
1086 " DID:0x%x Send:%d\n",
1087 xritag, rxid, ndlp->nlp_DID, send_rrq);
1090 if (phba->cfg_enable_rrq == 1)
1091 rrq->send_rrq = send_rrq;
1094 rrq->xritag = xritag;
1095 rrq->rrq_stop_time = jiffies +
1096 msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
1098 rrq->nlp_DID = ndlp->nlp_DID;
1099 rrq->vport = ndlp->vport;
1101 spin_lock_irqsave(&phba->hbalock, iflags);
1102 empty = list_empty(&phba->active_rrq_list);
1103 list_add_tail(&rrq->list, &phba->active_rrq_list);
1104 phba->hba_flag |= HBA_RRQ_ACTIVE;
1106 lpfc_worker_wake_up(phba);
1107 spin_unlock_irqrestore(&phba->hbalock, iflags);
1110 spin_unlock_irqrestore(&phba->hbalock, iflags);
1111 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1112 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
1113 " DID:0x%x Send:%d\n",
1114 xritag, rxid, ndlp->nlp_DID, send_rrq);
1119 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
1120 * @phba: Pointer to HBA context object.
1121 * @piocb: Pointer to the iocbq.
1123 * The driver calls this function with either the nvme ls ring lock
1124 * or the fc els ring lock held depending on the iocb usage. This function
1125 * gets a new driver sglq object from the sglq list. If the list is not empty
1126 * then it is successful, it returns pointer to the newly allocated sglq
1127 * object else it returns NULL.
1129 static struct lpfc_sglq *
1130 __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1132 struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
1133 struct lpfc_sglq *sglq = NULL;
1134 struct lpfc_sglq *start_sglq = NULL;
1135 struct lpfc_io_buf *lpfc_cmd;
1136 struct lpfc_nodelist *ndlp;
1137 struct lpfc_sli_ring *pring = NULL;
1140 if (piocbq->iocb_flag & LPFC_IO_NVME_LS)
1141 pring = phba->sli4_hba.nvmels_wq->pring;
1143 pring = lpfc_phba_elsring(phba);
1145 lockdep_assert_held(&pring->ring_lock);
1147 if (piocbq->iocb_flag & LPFC_IO_FCP) {
1148 lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1;
1149 ndlp = lpfc_cmd->rdata->pnode;
1150 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
1151 !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
1152 ndlp = piocbq->context_un.ndlp;
1153 } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
1154 if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
1157 ndlp = piocbq->context_un.ndlp;
1159 ndlp = piocbq->context1;
1162 spin_lock(&phba->sli4_hba.sgl_list_lock);
1163 list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
1168 if (ndlp && ndlp->active_rrqs_xri_bitmap &&
1169 test_bit(sglq->sli4_lxritag,
1170 ndlp->active_rrqs_xri_bitmap)) {
1171 /* This xri has an rrq outstanding for this DID.
1172 * put it back in the list and get another xri.
1174 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1176 list_remove_head(lpfc_els_sgl_list, sglq,
1177 struct lpfc_sglq, list);
1178 if (sglq == start_sglq) {
1179 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1187 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1188 sglq->state = SGL_ALLOCATED;
1190 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1195 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
1196 * @phba: Pointer to HBA context object.
1197 * @piocb: Pointer to the iocbq.
1199 * This function is called with the sgl_list lock held. This function
1200 * gets a new driver sglq object from the sglq list. If the
1201 * list is not empty then it is successful, it returns pointer to the newly
1202 * allocated sglq object else it returns NULL.
1205 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1207 struct list_head *lpfc_nvmet_sgl_list;
1208 struct lpfc_sglq *sglq = NULL;
1210 lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
1212 lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
1214 list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
1217 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1218 sglq->state = SGL_ALLOCATED;
1223 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1224 * @phba: Pointer to HBA context object.
1226 * This function is called with no lock held. This function
1227 * allocates a new driver iocb object from the iocb pool. If the
1228 * allocation is successful, it returns pointer to the newly
1229 * allocated iocb object else it returns NULL.
1232 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
1234 struct lpfc_iocbq * iocbq = NULL;
1235 unsigned long iflags;
1237 spin_lock_irqsave(&phba->hbalock, iflags);
1238 iocbq = __lpfc_sli_get_iocbq(phba);
1239 spin_unlock_irqrestore(&phba->hbalock, iflags);
1244 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1245 * @phba: Pointer to HBA context object.
1246 * @iocbq: Pointer to driver iocb object.
1248 * This function is called to release the driver iocb object
1249 * to the iocb pool. The iotag in the iocb object
1250 * does not change for each use of the iocb object. This function
1251 * clears all other fields of the iocb object when it is freed.
1252 * The sqlq structure that holds the xritag and phys and virtual
1253 * mappings for the scatter gather list is retrieved from the
1254 * active array of sglq. The get of the sglq pointer also clears
1255 * the entry in the array. If the status of the IO indiactes that
1256 * this IO was aborted then the sglq entry it put on the
1257 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1258 * IO has good status or fails for any other reason then the sglq
1259 * entry is added to the free list (lpfc_els_sgl_list). The hbalock is
1260 * asserted held in the code path calling this routine.
1263 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1265 struct lpfc_sglq *sglq;
1266 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1267 unsigned long iflag = 0;
1268 struct lpfc_sli_ring *pring;
1270 if (iocbq->sli4_xritag == NO_XRI)
1273 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
1277 if (iocbq->iocb_flag & LPFC_IO_NVMET) {
1278 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1280 sglq->state = SGL_FREED;
1282 list_add_tail(&sglq->list,
1283 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1284 spin_unlock_irqrestore(
1285 &phba->sli4_hba.sgl_list_lock, iflag);
1289 pring = phba->sli4_hba.els_wq->pring;
1290 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
1291 (sglq->state != SGL_XRI_ABORTED)) {
1292 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1294 list_add(&sglq->list,
1295 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1296 spin_unlock_irqrestore(
1297 &phba->sli4_hba.sgl_list_lock, iflag);
1299 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1301 sglq->state = SGL_FREED;
1303 list_add_tail(&sglq->list,
1304 &phba->sli4_hba.lpfc_els_sgl_list);
1305 spin_unlock_irqrestore(
1306 &phba->sli4_hba.sgl_list_lock, iflag);
1308 /* Check if TXQ queue needs to be serviced */
1309 if (!list_empty(&pring->txq))
1310 lpfc_worker_wake_up(phba);
1316 * Clean all volatile data fields, preserve iotag and node struct.
1318 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1319 iocbq->sli4_lxritag = NO_XRI;
1320 iocbq->sli4_xritag = NO_XRI;
1321 iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET |
1323 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1328 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1329 * @phba: Pointer to HBA context object.
1330 * @iocbq: Pointer to driver iocb object.
1332 * This function is called to release the driver iocb object to the
1333 * iocb pool. The iotag in the iocb object does not change for each
1334 * use of the iocb object. This function clears all other fields of
1335 * the iocb object when it is freed. The hbalock is asserted held in
1336 * the code path calling this routine.
1339 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1341 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1344 * Clean all volatile data fields, preserve iotag and node struct.
1346 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1347 iocbq->sli4_xritag = NO_XRI;
1348 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1352 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1353 * @phba: Pointer to HBA context object.
1354 * @iocbq: Pointer to driver iocb object.
1356 * This function is called with hbalock held to release driver
1357 * iocb object to the iocb pool. The iotag in the iocb object
1358 * does not change for each use of the iocb object. This function
1359 * clears all other fields of the iocb object when it is freed.
1362 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1364 lockdep_assert_held(&phba->hbalock);
1366 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1371 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1372 * @phba: Pointer to HBA context object.
1373 * @iocbq: Pointer to driver iocb object.
1375 * This function is called with no lock held to release the iocb to
1379 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1381 unsigned long iflags;
1384 * Clean all volatile data fields, preserve iotag and node struct.
1386 spin_lock_irqsave(&phba->hbalock, iflags);
1387 __lpfc_sli_release_iocbq(phba, iocbq);
1388 spin_unlock_irqrestore(&phba->hbalock, iflags);
1392 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1393 * @phba: Pointer to HBA context object.
1394 * @iocblist: List of IOCBs.
1395 * @ulpstatus: ULP status in IOCB command field.
1396 * @ulpWord4: ULP word-4 in IOCB command field.
1398 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1399 * on the list by invoking the complete callback function associated with the
1400 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1404 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1405 uint32_t ulpstatus, uint32_t ulpWord4)
1407 struct lpfc_iocbq *piocb;
1409 while (!list_empty(iocblist)) {
1410 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1411 if (!piocb->iocb_cmpl) {
1412 if (piocb->iocb_flag & LPFC_IO_NVME)
1413 lpfc_nvme_cancel_iocb(phba, piocb);
1415 lpfc_sli_release_iocbq(phba, piocb);
1417 piocb->iocb.ulpStatus = ulpstatus;
1418 piocb->iocb.un.ulpWord[4] = ulpWord4;
1419 (piocb->iocb_cmpl) (phba, piocb, piocb);
1426 * lpfc_sli_iocb_cmd_type - Get the iocb type
1427 * @iocb_cmnd: iocb command code.
1429 * This function is called by ring event handler function to get the iocb type.
1430 * This function translates the iocb command to an iocb command type used to
1431 * decide the final disposition of each completed IOCB.
1432 * The function returns
1433 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1434 * LPFC_SOL_IOCB if it is a solicited iocb completion
1435 * LPFC_ABORT_IOCB if it is an abort iocb
1436 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1438 * The caller is not required to hold any lock.
1440 static lpfc_iocb_type
1441 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1443 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1445 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1448 switch (iocb_cmnd) {
1449 case CMD_XMIT_SEQUENCE_CR:
1450 case CMD_XMIT_SEQUENCE_CX:
1451 case CMD_XMIT_BCAST_CN:
1452 case CMD_XMIT_BCAST_CX:
1453 case CMD_ELS_REQUEST_CR:
1454 case CMD_ELS_REQUEST_CX:
1455 case CMD_CREATE_XRI_CR:
1456 case CMD_CREATE_XRI_CX:
1457 case CMD_GET_RPI_CN:
1458 case CMD_XMIT_ELS_RSP_CX:
1459 case CMD_GET_RPI_CR:
1460 case CMD_FCP_IWRITE_CR:
1461 case CMD_FCP_IWRITE_CX:
1462 case CMD_FCP_IREAD_CR:
1463 case CMD_FCP_IREAD_CX:
1464 case CMD_FCP_ICMND_CR:
1465 case CMD_FCP_ICMND_CX:
1466 case CMD_FCP_TSEND_CX:
1467 case CMD_FCP_TRSP_CX:
1468 case CMD_FCP_TRECEIVE_CX:
1469 case CMD_FCP_AUTO_TRSP_CX:
1470 case CMD_ADAPTER_MSG:
1471 case CMD_ADAPTER_DUMP:
1472 case CMD_XMIT_SEQUENCE64_CR:
1473 case CMD_XMIT_SEQUENCE64_CX:
1474 case CMD_XMIT_BCAST64_CN:
1475 case CMD_XMIT_BCAST64_CX:
1476 case CMD_ELS_REQUEST64_CR:
1477 case CMD_ELS_REQUEST64_CX:
1478 case CMD_FCP_IWRITE64_CR:
1479 case CMD_FCP_IWRITE64_CX:
1480 case CMD_FCP_IREAD64_CR:
1481 case CMD_FCP_IREAD64_CX:
1482 case CMD_FCP_ICMND64_CR:
1483 case CMD_FCP_ICMND64_CX:
1484 case CMD_FCP_TSEND64_CX:
1485 case CMD_FCP_TRSP64_CX:
1486 case CMD_FCP_TRECEIVE64_CX:
1487 case CMD_GEN_REQUEST64_CR:
1488 case CMD_GEN_REQUEST64_CX:
1489 case CMD_XMIT_ELS_RSP64_CX:
1490 case DSSCMD_IWRITE64_CR:
1491 case DSSCMD_IWRITE64_CX:
1492 case DSSCMD_IREAD64_CR:
1493 case DSSCMD_IREAD64_CX:
1494 type = LPFC_SOL_IOCB;
1496 case CMD_ABORT_XRI_CN:
1497 case CMD_ABORT_XRI_CX:
1498 case CMD_CLOSE_XRI_CN:
1499 case CMD_CLOSE_XRI_CX:
1500 case CMD_XRI_ABORTED_CX:
1501 case CMD_ABORT_MXRI64_CN:
1502 case CMD_XMIT_BLS_RSP64_CX:
1503 type = LPFC_ABORT_IOCB;
1505 case CMD_RCV_SEQUENCE_CX:
1506 case CMD_RCV_ELS_REQ_CX:
1507 case CMD_RCV_SEQUENCE64_CX:
1508 case CMD_RCV_ELS_REQ64_CX:
1509 case CMD_ASYNC_STATUS:
1510 case CMD_IOCB_RCV_SEQ64_CX:
1511 case CMD_IOCB_RCV_ELS64_CX:
1512 case CMD_IOCB_RCV_CONT64_CX:
1513 case CMD_IOCB_RET_XRI64_CX:
1514 type = LPFC_UNSOL_IOCB;
1516 case CMD_IOCB_XMIT_MSEQ64_CR:
1517 case CMD_IOCB_XMIT_MSEQ64_CX:
1518 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1519 case CMD_IOCB_RCV_ELS_LIST64_CX:
1520 case CMD_IOCB_CLOSE_EXTENDED_CN:
1521 case CMD_IOCB_ABORT_EXTENDED_CN:
1522 case CMD_IOCB_RET_HBQE64_CN:
1523 case CMD_IOCB_FCP_IBIDIR64_CR:
1524 case CMD_IOCB_FCP_IBIDIR64_CX:
1525 case CMD_IOCB_FCP_ITASKMGT64_CX:
1526 case CMD_IOCB_LOGENTRY_CN:
1527 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1528 printk("%s - Unhandled SLI-3 Command x%x\n",
1529 __func__, iocb_cmnd);
1530 type = LPFC_UNKNOWN_IOCB;
1533 type = LPFC_UNKNOWN_IOCB;
1541 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1542 * @phba: Pointer to HBA context object.
1544 * This function is called from SLI initialization code
1545 * to configure every ring of the HBA's SLI interface. The
1546 * caller is not required to hold any lock. This function issues
1547 * a config_ring mailbox command for each ring.
1548 * This function returns zero if successful else returns a negative
1552 lpfc_sli_ring_map(struct lpfc_hba *phba)
1554 struct lpfc_sli *psli = &phba->sli;
1559 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1563 phba->link_state = LPFC_INIT_MBX_CMDS;
1564 for (i = 0; i < psli->num_rings; i++) {
1565 lpfc_config_ring(phba, i, pmb);
1566 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1567 if (rc != MBX_SUCCESS) {
1568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1569 "0446 Adapter failed to init (%d), "
1570 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1572 rc, pmbox->mbxCommand,
1573 pmbox->mbxStatus, i);
1574 phba->link_state = LPFC_HBA_ERROR;
1579 mempool_free(pmb, phba->mbox_mem_pool);
1584 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1585 * @phba: Pointer to HBA context object.
1586 * @pring: Pointer to driver SLI ring object.
1587 * @piocb: Pointer to the driver iocb object.
1589 * The driver calls this function with the hbalock held for SLI3 ports or
1590 * the ring lock held for SLI4 ports. The function adds the
1591 * new iocb to txcmplq of the given ring. This function always returns
1592 * 0. If this function is called for ELS ring, this function checks if
1593 * there is a vport associated with the ELS command. This function also
1594 * starts els_tmofunc timer if this is an ELS command.
1597 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1598 struct lpfc_iocbq *piocb)
1600 if (phba->sli_rev == LPFC_SLI_REV4)
1601 lockdep_assert_held(&pring->ring_lock);
1603 lockdep_assert_held(&phba->hbalock);
1607 list_add_tail(&piocb->list, &pring->txcmplq);
1608 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1609 pring->txcmplq_cnt++;
1611 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1612 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1613 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1614 BUG_ON(!piocb->vport);
1615 if (!(piocb->vport->load_flag & FC_UNLOADING))
1616 mod_timer(&piocb->vport->els_tmofunc,
1618 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1625 * lpfc_sli_ringtx_get - Get first element of the txq
1626 * @phba: Pointer to HBA context object.
1627 * @pring: Pointer to driver SLI ring object.
1629 * This function is called with hbalock held to get next
1630 * iocb in txq of the given ring. If there is any iocb in
1631 * the txq, the function returns first iocb in the list after
1632 * removing the iocb from the list, else it returns NULL.
1635 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1637 struct lpfc_iocbq *cmd_iocb;
1639 lockdep_assert_held(&phba->hbalock);
1641 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1646 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1647 * @phba: Pointer to HBA context object.
1648 * @pring: Pointer to driver SLI ring object.
1650 * This function is called with hbalock held and the caller must post the
1651 * iocb without releasing the lock. If the caller releases the lock,
1652 * iocb slot returned by the function is not guaranteed to be available.
1653 * The function returns pointer to the next available iocb slot if there
1654 * is available slot in the ring, else it returns NULL.
1655 * If the get index of the ring is ahead of the put index, the function
1656 * will post an error attention event to the worker thread to take the
1657 * HBA to offline state.
1660 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1662 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1663 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
1665 lockdep_assert_held(&phba->hbalock);
1667 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
1668 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
1669 pring->sli.sli3.next_cmdidx = 0;
1671 if (unlikely(pring->sli.sli3.local_getidx ==
1672 pring->sli.sli3.next_cmdidx)) {
1674 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
1676 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
1677 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1678 "0315 Ring %d issue: portCmdGet %d "
1679 "is bigger than cmd ring %d\n",
1681 pring->sli.sli3.local_getidx,
1684 phba->link_state = LPFC_HBA_ERROR;
1686 * All error attention handlers are posted to
1689 phba->work_ha |= HA_ERATT;
1690 phba->work_hs = HS_FFER3;
1692 lpfc_worker_wake_up(phba);
1697 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
1701 return lpfc_cmd_iocb(phba, pring);
1705 * lpfc_sli_next_iotag - Get an iotag for the iocb
1706 * @phba: Pointer to HBA context object.
1707 * @iocbq: Pointer to driver iocb object.
1709 * This function gets an iotag for the iocb. If there is no unused iotag and
1710 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1711 * array and assigns a new iotag.
1712 * The function returns the allocated iotag if successful, else returns zero.
1713 * Zero is not a valid iotag.
1714 * The caller is not required to hold any lock.
1717 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1719 struct lpfc_iocbq **new_arr;
1720 struct lpfc_iocbq **old_arr;
1722 struct lpfc_sli *psli = &phba->sli;
1725 spin_lock_irq(&phba->hbalock);
1726 iotag = psli->last_iotag;
1727 if(++iotag < psli->iocbq_lookup_len) {
1728 psli->last_iotag = iotag;
1729 psli->iocbq_lookup[iotag] = iocbq;
1730 spin_unlock_irq(&phba->hbalock);
1731 iocbq->iotag = iotag;
1733 } else if (psli->iocbq_lookup_len < (0xffff
1734 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1735 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1736 spin_unlock_irq(&phba->hbalock);
1737 new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
1740 spin_lock_irq(&phba->hbalock);
1741 old_arr = psli->iocbq_lookup;
1742 if (new_len <= psli->iocbq_lookup_len) {
1743 /* highly unprobable case */
1745 iotag = psli->last_iotag;
1746 if(++iotag < psli->iocbq_lookup_len) {
1747 psli->last_iotag = iotag;
1748 psli->iocbq_lookup[iotag] = iocbq;
1749 spin_unlock_irq(&phba->hbalock);
1750 iocbq->iotag = iotag;
1753 spin_unlock_irq(&phba->hbalock);
1756 if (psli->iocbq_lookup)
1757 memcpy(new_arr, old_arr,
1758 ((psli->last_iotag + 1) *
1759 sizeof (struct lpfc_iocbq *)));
1760 psli->iocbq_lookup = new_arr;
1761 psli->iocbq_lookup_len = new_len;
1762 psli->last_iotag = iotag;
1763 psli->iocbq_lookup[iotag] = iocbq;
1764 spin_unlock_irq(&phba->hbalock);
1765 iocbq->iotag = iotag;
1770 spin_unlock_irq(&phba->hbalock);
1772 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1773 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1780 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1781 * @phba: Pointer to HBA context object.
1782 * @pring: Pointer to driver SLI ring object.
1783 * @iocb: Pointer to iocb slot in the ring.
1784 * @nextiocb: Pointer to driver iocb object which need to be
1785 * posted to firmware.
1787 * This function is called to post a new iocb to the firmware. This
1788 * function copies the new iocb to ring iocb slot and updates the
1789 * ring pointers. It adds the new iocb to txcmplq if there is
1790 * a completion call back for this iocb else the function will free the
1791 * iocb object. The hbalock is asserted held in the code path calling
1795 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1796 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1801 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1804 if (pring->ringno == LPFC_ELS_RING) {
1805 lpfc_debugfs_slow_ring_trc(phba,
1806 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1807 *(((uint32_t *) &nextiocb->iocb) + 4),
1808 *(((uint32_t *) &nextiocb->iocb) + 6),
1809 *(((uint32_t *) &nextiocb->iocb) + 7));
1813 * Issue iocb command to adapter
1815 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1817 pring->stats.iocb_cmd++;
1820 * If there is no completion routine to call, we can release the
1821 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1822 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1824 if (nextiocb->iocb_cmpl)
1825 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1827 __lpfc_sli_release_iocbq(phba, nextiocb);
1830 * Let the HBA know what IOCB slot will be the next one the
1831 * driver will put a command into.
1833 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
1834 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1838 * lpfc_sli_update_full_ring - Update the chip attention register
1839 * @phba: Pointer to HBA context object.
1840 * @pring: Pointer to driver SLI ring object.
1842 * The caller is not required to hold any lock for calling this function.
1843 * This function updates the chip attention bits for the ring to inform firmware
1844 * that there are pending work to be done for this ring and requests an
1845 * interrupt when there is space available in the ring. This function is
1846 * called when the driver is unable to post more iocbs to the ring due
1847 * to unavailability of space in the ring.
1850 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1852 int ringno = pring->ringno;
1854 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1859 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1860 * The HBA will tell us when an IOCB entry is available.
1862 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1863 readl(phba->CAregaddr); /* flush */
1865 pring->stats.iocb_cmd_full++;
1869 * lpfc_sli_update_ring - Update chip attention register
1870 * @phba: Pointer to HBA context object.
1871 * @pring: Pointer to driver SLI ring object.
1873 * This function updates the chip attention register bit for the
1874 * given ring to inform HBA that there is more work to be done
1875 * in this ring. The caller is not required to hold any lock.
1878 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1880 int ringno = pring->ringno;
1883 * Tell the HBA that there is work to do in this ring.
1885 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
1887 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
1888 readl(phba->CAregaddr); /* flush */
1893 * lpfc_sli_resume_iocb - Process iocbs in the txq
1894 * @phba: Pointer to HBA context object.
1895 * @pring: Pointer to driver SLI ring object.
1897 * This function is called with hbalock held to post pending iocbs
1898 * in the txq to the firmware. This function is called when driver
1899 * detects space available in the ring.
1902 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1905 struct lpfc_iocbq *nextiocb;
1907 lockdep_assert_held(&phba->hbalock);
1911 * (a) there is anything on the txq to send
1913 * (c) link attention events can be processed (fcp ring only)
1914 * (d) IOCB processing is not blocked by the outstanding mbox command.
1917 if (lpfc_is_link_up(phba) &&
1918 (!list_empty(&pring->txq)) &&
1919 (pring->ringno != LPFC_FCP_RING ||
1920 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
1922 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
1923 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
1924 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
1927 lpfc_sli_update_ring(phba, pring);
1929 lpfc_sli_update_full_ring(phba, pring);
1936 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1937 * @phba: Pointer to HBA context object.
1938 * @hbqno: HBQ number.
1940 * This function is called with hbalock held to get the next
1941 * available slot for the given HBQ. If there is free slot
1942 * available for the HBQ it will return pointer to the next available
1943 * HBQ entry else it will return NULL.
1945 static struct lpfc_hbq_entry *
1946 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
1948 struct hbq_s *hbqp = &phba->hbqs[hbqno];
1950 lockdep_assert_held(&phba->hbalock);
1952 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
1953 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
1954 hbqp->next_hbqPutIdx = 0;
1956 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
1957 uint32_t raw_index = phba->hbq_get[hbqno];
1958 uint32_t getidx = le32_to_cpu(raw_index);
1960 hbqp->local_hbqGetIdx = getidx;
1962 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
1963 lpfc_printf_log(phba, KERN_ERR,
1964 LOG_SLI | LOG_VPORT,
1965 "1802 HBQ %d: local_hbqGetIdx "
1966 "%u is > than hbqp->entry_count %u\n",
1967 hbqno, hbqp->local_hbqGetIdx,
1970 phba->link_state = LPFC_HBA_ERROR;
1974 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
1978 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
1983 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1984 * @phba: Pointer to HBA context object.
1986 * This function is called with no lock held to free all the
1987 * hbq buffers while uninitializing the SLI interface. It also
1988 * frees the HBQ buffers returned by the firmware but not yet
1989 * processed by the upper layers.
1992 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
1994 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
1995 struct hbq_dmabuf *hbq_buf;
1996 unsigned long flags;
1999 hbq_count = lpfc_sli_hbq_count();
2000 /* Return all memory used by all HBQs */
2001 spin_lock_irqsave(&phba->hbalock, flags);
2002 for (i = 0; i < hbq_count; ++i) {
2003 list_for_each_entry_safe(dmabuf, next_dmabuf,
2004 &phba->hbqs[i].hbq_buffer_list, list) {
2005 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
2006 list_del(&hbq_buf->dbuf.list);
2007 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
2009 phba->hbqs[i].buffer_count = 0;
2012 /* Mark the HBQs not in use */
2013 phba->hbq_in_use = 0;
2014 spin_unlock_irqrestore(&phba->hbalock, flags);
2018 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
2019 * @phba: Pointer to HBA context object.
2020 * @hbqno: HBQ number.
2021 * @hbq_buf: Pointer to HBQ buffer.
2023 * This function is called with the hbalock held to post a
2024 * hbq buffer to the firmware. If the function finds an empty
2025 * slot in the HBQ, it will post the buffer. The function will return
2026 * pointer to the hbq entry if it successfully post the buffer
2027 * else it will return NULL.
2030 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
2031 struct hbq_dmabuf *hbq_buf)
2033 lockdep_assert_held(&phba->hbalock);
2034 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
2038 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
2039 * @phba: Pointer to HBA context object.
2040 * @hbqno: HBQ number.
2041 * @hbq_buf: Pointer to HBQ buffer.
2043 * This function is called with the hbalock held to post a hbq buffer to the
2044 * firmware. If the function finds an empty slot in the HBQ, it will post the
2045 * buffer and place it on the hbq_buffer_list. The function will return zero if
2046 * it successfully post the buffer else it will return an error.
2049 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
2050 struct hbq_dmabuf *hbq_buf)
2052 struct lpfc_hbq_entry *hbqe;
2053 dma_addr_t physaddr = hbq_buf->dbuf.phys;
2055 lockdep_assert_held(&phba->hbalock);
2056 /* Get next HBQ entry slot to use */
2057 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
2059 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2061 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
2062 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
2063 hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
2064 hbqe->bde.tus.f.bdeFlags = 0;
2065 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
2066 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
2068 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
2069 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
2071 readl(phba->hbq_put + hbqno);
2072 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
2079 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
2080 * @phba: Pointer to HBA context object.
2081 * @hbqno: HBQ number.
2082 * @hbq_buf: Pointer to HBQ buffer.
2084 * This function is called with the hbalock held to post an RQE to the SLI4
2085 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
2086 * the hbq_buffer_list and return zero, otherwise it will return an error.
2089 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
2090 struct hbq_dmabuf *hbq_buf)
2093 struct lpfc_rqe hrqe;
2094 struct lpfc_rqe drqe;
2095 struct lpfc_queue *hrq;
2096 struct lpfc_queue *drq;
2098 if (hbqno != LPFC_ELS_HBQ)
2100 hrq = phba->sli4_hba.hdr_rq;
2101 drq = phba->sli4_hba.dat_rq;
2103 lockdep_assert_held(&phba->hbalock);
2104 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
2105 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
2106 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
2107 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
2108 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
2111 hbq_buf->tag = (rc | (hbqno << 16));
2112 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
2116 /* HBQ for ELS and CT traffic. */
2117 static struct lpfc_hbq_init lpfc_els_hbq = {
2122 .ring_mask = (1 << LPFC_ELS_RING),
2129 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
2134 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
2135 * @phba: Pointer to HBA context object.
2136 * @hbqno: HBQ number.
2137 * @count: Number of HBQ buffers to be posted.
2139 * This function is called with no lock held to post more hbq buffers to the
2140 * given HBQ. The function returns the number of HBQ buffers successfully
2144 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
2146 uint32_t i, posted = 0;
2147 unsigned long flags;
2148 struct hbq_dmabuf *hbq_buffer;
2149 LIST_HEAD(hbq_buf_list);
2150 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
2153 if ((phba->hbqs[hbqno].buffer_count + count) >
2154 lpfc_hbq_defs[hbqno]->entry_count)
2155 count = lpfc_hbq_defs[hbqno]->entry_count -
2156 phba->hbqs[hbqno].buffer_count;
2159 /* Allocate HBQ entries */
2160 for (i = 0; i < count; i++) {
2161 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
2164 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
2166 /* Check whether HBQ is still in use */
2167 spin_lock_irqsave(&phba->hbalock, flags);
2168 if (!phba->hbq_in_use)
2170 while (!list_empty(&hbq_buf_list)) {
2171 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2173 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
2175 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
2176 phba->hbqs[hbqno].buffer_count++;
2179 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2181 spin_unlock_irqrestore(&phba->hbalock, flags);
2184 spin_unlock_irqrestore(&phba->hbalock, flags);
2185 while (!list_empty(&hbq_buf_list)) {
2186 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2188 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2194 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
2195 * @phba: Pointer to HBA context object.
2198 * This function posts more buffers to the HBQ. This function
2199 * is called with no lock held. The function returns the number of HBQ entries
2200 * successfully allocated.
2203 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
2205 if (phba->sli_rev == LPFC_SLI_REV4)
2208 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2209 lpfc_hbq_defs[qno]->add_count);
2213 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2214 * @phba: Pointer to HBA context object.
2215 * @qno: HBQ queue number.
2217 * This function is called from SLI initialization code path with
2218 * no lock held to post initial HBQ buffers to firmware. The
2219 * function returns the number of HBQ entries successfully allocated.
2222 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
2224 if (phba->sli_rev == LPFC_SLI_REV4)
2225 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2226 lpfc_hbq_defs[qno]->entry_count);
2228 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2229 lpfc_hbq_defs[qno]->init_count);
2233 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2234 * @phba: Pointer to HBA context object.
2235 * @hbqno: HBQ number.
2237 * This function removes the first hbq buffer on an hbq list and returns a
2238 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2240 static struct hbq_dmabuf *
2241 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
2243 struct lpfc_dmabuf *d_buf;
2245 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
2248 return container_of(d_buf, struct hbq_dmabuf, dbuf);
2252 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2253 * @phba: Pointer to HBA context object.
2254 * @hbqno: HBQ number.
2256 * This function removes the first RQ buffer on an RQ buffer list and returns a
2257 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2259 static struct rqb_dmabuf *
2260 lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
2262 struct lpfc_dmabuf *h_buf;
2263 struct lpfc_rqb *rqbp;
2266 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
2267 struct lpfc_dmabuf, list);
2270 rqbp->buffer_count--;
2271 return container_of(h_buf, struct rqb_dmabuf, hbuf);
2275 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2276 * @phba: Pointer to HBA context object.
2277 * @tag: Tag of the hbq buffer.
2279 * This function searches for the hbq buffer associated with the given tag in
2280 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2281 * otherwise it returns NULL.
2283 static struct hbq_dmabuf *
2284 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
2286 struct lpfc_dmabuf *d_buf;
2287 struct hbq_dmabuf *hbq_buf;
2291 if (hbqno >= LPFC_MAX_HBQS)
2294 spin_lock_irq(&phba->hbalock);
2295 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
2296 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2297 if (hbq_buf->tag == tag) {
2298 spin_unlock_irq(&phba->hbalock);
2302 spin_unlock_irq(&phba->hbalock);
2303 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
2304 "1803 Bad hbq tag. Data: x%x x%x\n",
2305 tag, phba->hbqs[tag >> 16].buffer_count);
2310 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2311 * @phba: Pointer to HBA context object.
2312 * @hbq_buffer: Pointer to HBQ buffer.
2314 * This function is called with hbalock. This function gives back
2315 * the hbq buffer to firmware. If the HBQ does not have space to
2316 * post the buffer, it will free the buffer.
2319 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2324 hbqno = hbq_buffer->tag >> 16;
2325 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2326 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2331 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2332 * @mbxCommand: mailbox command code.
2334 * This function is called by the mailbox event handler function to verify
2335 * that the completed mailbox command is a legitimate mailbox command. If the
2336 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2337 * and the mailbox event handler will take the HBA offline.
2340 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2344 switch (mbxCommand) {
2348 case MBX_WRITE_VPARMS:
2349 case MBX_RUN_BIU_DIAG:
2352 case MBX_CONFIG_LINK:
2353 case MBX_CONFIG_RING:
2354 case MBX_RESET_RING:
2355 case MBX_READ_CONFIG:
2356 case MBX_READ_RCONFIG:
2357 case MBX_READ_SPARM:
2358 case MBX_READ_STATUS:
2362 case MBX_READ_LNK_STAT:
2364 case MBX_UNREG_LOGIN:
2366 case MBX_DUMP_MEMORY:
2367 case MBX_DUMP_CONTEXT:
2370 case MBX_UPDATE_CFG:
2372 case MBX_DEL_LD_ENTRY:
2373 case MBX_RUN_PROGRAM:
2375 case MBX_SET_VARIABLE:
2376 case MBX_UNREG_D_ID:
2377 case MBX_KILL_BOARD:
2378 case MBX_CONFIG_FARP:
2381 case MBX_RUN_BIU_DIAG64:
2382 case MBX_CONFIG_PORT:
2383 case MBX_READ_SPARM64:
2384 case MBX_READ_RPI64:
2385 case MBX_REG_LOGIN64:
2386 case MBX_READ_TOPOLOGY:
2389 case MBX_LOAD_EXP_ROM:
2390 case MBX_ASYNCEVT_ENABLE:
2394 case MBX_PORT_CAPABILITIES:
2395 case MBX_PORT_IOV_CONTROL:
2396 case MBX_SLI4_CONFIG:
2397 case MBX_SLI4_REQ_FTRS:
2399 case MBX_UNREG_FCFI:
2404 case MBX_RESUME_RPI:
2405 case MBX_READ_EVENT_LOG_STATUS:
2406 case MBX_READ_EVENT_LOG:
2407 case MBX_SECURITY_MGMT:
2409 case MBX_ACCESS_VDATA:
2420 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2421 * @phba: Pointer to HBA context object.
2422 * @pmboxq: Pointer to mailbox command.
2424 * This is completion handler function for mailbox commands issued from
2425 * lpfc_sli_issue_mbox_wait function. This function is called by the
2426 * mailbox event handler function with no lock held. This function
2427 * will wake up thread waiting on the wait queue pointed by context1
2431 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2433 unsigned long drvr_flag;
2434 struct completion *pmbox_done;
2437 * If pmbox_done is empty, the driver thread gave up waiting and
2438 * continued running.
2440 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2441 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2442 pmbox_done = (struct completion *)pmboxq->context3;
2444 complete(pmbox_done);
2445 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2450 __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2452 unsigned long iflags;
2454 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
2455 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
2456 spin_lock_irqsave(&vport->phba->ndlp_lock, iflags);
2457 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
2458 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
2459 spin_unlock_irqrestore(&vport->phba->ndlp_lock, iflags);
2461 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2465 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2466 * @phba: Pointer to HBA context object.
2467 * @pmb: Pointer to mailbox object.
2469 * This function is the default mailbox completion handler. It
2470 * frees the memory resources associated with the completed mailbox
2471 * command. If the completed command is a REG_LOGIN mailbox command,
2472 * this function will issue a UREG_LOGIN to re-claim the RPI.
2475 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2477 struct lpfc_vport *vport = pmb->vport;
2478 struct lpfc_dmabuf *mp;
2479 struct lpfc_nodelist *ndlp;
2480 struct Scsi_Host *shost;
2484 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
2487 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2492 * If a REG_LOGIN succeeded after node is destroyed or node
2493 * is in re-discovery driver need to cleanup the RPI.
2495 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2496 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2497 !pmb->u.mb.mbxStatus) {
2498 rpi = pmb->u.mb.un.varWords[0];
2499 vpi = pmb->u.mb.un.varRegLogin.vpi;
2500 if (phba->sli_rev == LPFC_SLI_REV4)
2501 vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
2502 lpfc_unreg_login(phba, vpi, rpi, pmb);
2504 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2505 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2506 if (rc != MBX_NOT_FINISHED)
2510 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2511 !(phba->pport->load_flag & FC_UNLOADING) &&
2512 !pmb->u.mb.mbxStatus) {
2513 shost = lpfc_shost_from_vport(vport);
2514 spin_lock_irq(shost->host_lock);
2515 vport->vpi_state |= LPFC_VPI_REGISTERED;
2516 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2517 spin_unlock_irq(shost->host_lock);
2520 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2521 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2523 pmb->ctx_buf = NULL;
2524 pmb->ctx_ndlp = NULL;
2527 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2528 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2530 /* Check to see if there are any deferred events to process */
2534 KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
2535 "1438 UNREG cmpl deferred mbox x%x "
2536 "on NPort x%x Data: x%x x%x %px\n",
2537 ndlp->nlp_rpi, ndlp->nlp_DID,
2538 ndlp->nlp_flag, ndlp->nlp_defer_did, ndlp);
2540 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2541 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
2542 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2543 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
2544 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2546 __lpfc_sli_rpi_release(vport, ndlp);
2548 if (vport->load_flag & FC_UNLOADING)
2550 pmb->ctx_ndlp = NULL;
2554 /* Check security permission status on INIT_LINK mailbox command */
2555 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2556 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2557 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2558 "2860 SLI authentication is required "
2559 "for INIT_LINK but has not done yet\n");
2561 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2562 lpfc_sli4_mbox_cmd_free(phba, pmb);
2564 mempool_free(pmb, phba->mbox_mem_pool);
2567 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2568 * @phba: Pointer to HBA context object.
2569 * @pmb: Pointer to mailbox object.
2571 * This function is the unreg rpi mailbox completion handler. It
2572 * frees the memory resources associated with the completed mailbox
2573 * command. An additional refrenece is put on the ndlp to prevent
2574 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2575 * the unreg mailbox command completes, this routine puts the
2580 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2582 struct lpfc_vport *vport = pmb->vport;
2583 struct lpfc_nodelist *ndlp;
2585 ndlp = pmb->ctx_ndlp;
2586 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2587 if (phba->sli_rev == LPFC_SLI_REV4 &&
2588 (bf_get(lpfc_sli_intf_if_type,
2589 &phba->sli4_hba.sli_intf) >=
2590 LPFC_SLI_INTF_IF_TYPE_2)) {
2593 vport, KERN_INFO, LOG_MBOX | LOG_SLI,
2594 "0010 UNREG_LOGIN vpi:%x "
2595 "rpi:%x DID:%x defer x%x flg x%x "
2597 vport->vpi, ndlp->nlp_rpi,
2598 ndlp->nlp_DID, ndlp->nlp_defer_did,
2600 ndlp->nlp_usg_map, ndlp);
2601 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2604 /* Check to see if there are any deferred
2607 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2608 (ndlp->nlp_defer_did !=
2609 NLP_EVT_NOTHING_PENDING)) {
2611 vport, KERN_INFO, LOG_DISCOVERY,
2612 "4111 UNREG cmpl deferred "
2614 "NPort x%x Data: x%x x%px\n",
2615 ndlp->nlp_rpi, ndlp->nlp_DID,
2616 ndlp->nlp_defer_did, ndlp);
2617 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2618 ndlp->nlp_defer_did =
2619 NLP_EVT_NOTHING_PENDING;
2620 lpfc_issue_els_plogi(
2621 vport, ndlp->nlp_DID, 0);
2623 __lpfc_sli_rpi_release(vport, ndlp);
2629 mempool_free(pmb, phba->mbox_mem_pool);
2633 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2634 * @phba: Pointer to HBA context object.
2636 * This function is called with no lock held. This function processes all
2637 * the completed mailbox commands and gives it to upper layers. The interrupt
2638 * service routine processes mailbox completion interrupt and adds completed
2639 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2640 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2641 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2642 * function returns the mailbox commands to the upper layer by calling the
2643 * completion handler function of each mailbox.
2646 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
2653 phba->sli.slistat.mbox_event++;
2655 /* Get all completed mailboxe buffers into the cmplq */
2656 spin_lock_irq(&phba->hbalock);
2657 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2658 spin_unlock_irq(&phba->hbalock);
2660 /* Get a Mailbox buffer to setup mailbox commands for callback */
2662 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2668 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2670 lpfc_debugfs_disc_trc(pmb->vport,
2671 LPFC_DISC_TRC_MBOX_VPORT,
2672 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2673 (uint32_t)pmbox->mbxCommand,
2674 pmbox->un.varWords[0],
2675 pmbox->un.varWords[1]);
2678 lpfc_debugfs_disc_trc(phba->pport,
2680 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2681 (uint32_t)pmbox->mbxCommand,
2682 pmbox->un.varWords[0],
2683 pmbox->un.varWords[1]);
2688 * It is a fatal error if unknown mbox command completion.
2690 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2692 /* Unknown mailbox command compl */
2693 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2694 "(%d):0323 Unknown Mailbox command "
2695 "x%x (x%x/x%x) Cmpl\n",
2696 pmb->vport ? pmb->vport->vpi :
2699 lpfc_sli_config_mbox_subsys_get(phba,
2701 lpfc_sli_config_mbox_opcode_get(phba,
2703 phba->link_state = LPFC_HBA_ERROR;
2704 phba->work_hs = HS_FFER3;
2705 lpfc_handle_eratt(phba);
2709 if (pmbox->mbxStatus) {
2710 phba->sli.slistat.mbox_stat_err++;
2711 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2712 /* Mbox cmd cmpl error - RETRYing */
2713 lpfc_printf_log(phba, KERN_INFO,
2715 "(%d):0305 Mbox cmd cmpl "
2716 "error - RETRYing Data: x%x "
2717 "(x%x/x%x) x%x x%x x%x\n",
2718 pmb->vport ? pmb->vport->vpi :
2721 lpfc_sli_config_mbox_subsys_get(phba,
2723 lpfc_sli_config_mbox_opcode_get(phba,
2726 pmbox->un.varWords[0],
2727 pmb->vport ? pmb->vport->port_state :
2728 LPFC_VPORT_UNKNOWN);
2729 pmbox->mbxStatus = 0;
2730 pmbox->mbxOwner = OWN_HOST;
2731 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2732 if (rc != MBX_NOT_FINISHED)
2737 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2738 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2739 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
2740 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2742 pmb->vport ? pmb->vport->vpi : 0,
2744 lpfc_sli_config_mbox_subsys_get(phba, pmb),
2745 lpfc_sli_config_mbox_opcode_get(phba, pmb),
2747 *((uint32_t *) pmbox),
2748 pmbox->un.varWords[0],
2749 pmbox->un.varWords[1],
2750 pmbox->un.varWords[2],
2751 pmbox->un.varWords[3],
2752 pmbox->un.varWords[4],
2753 pmbox->un.varWords[5],
2754 pmbox->un.varWords[6],
2755 pmbox->un.varWords[7],
2756 pmbox->un.varWords[8],
2757 pmbox->un.varWords[9],
2758 pmbox->un.varWords[10]);
2761 pmb->mbox_cmpl(phba,pmb);
2767 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2768 * @phba: Pointer to HBA context object.
2769 * @pring: Pointer to driver SLI ring object.
2772 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2773 * is set in the tag the buffer is posted for a particular exchange,
2774 * the function will return the buffer without replacing the buffer.
2775 * If the buffer is for unsolicited ELS or CT traffic, this function
2776 * returns the buffer and also posts another buffer to the firmware.
2778 static struct lpfc_dmabuf *
2779 lpfc_sli_get_buff(struct lpfc_hba *phba,
2780 struct lpfc_sli_ring *pring,
2783 struct hbq_dmabuf *hbq_entry;
2785 if (tag & QUE_BUFTAG_BIT)
2786 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
2787 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2790 return &hbq_entry->dbuf;
2794 * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer
2795 * containing a NVME LS request.
2796 * @phba: pointer to lpfc hba data structure.
2797 * @piocb: pointer to the iocbq struct representing the sequence starting
2800 * This routine initially validates the NVME LS, validates there is a login
2801 * with the port that sent the LS, and then calls the appropriate nvme host
2802 * or target LS request handler.
2805 lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
2807 struct lpfc_nodelist *ndlp;
2808 struct lpfc_dmabuf *d_buf;
2809 struct hbq_dmabuf *nvmebuf;
2810 struct fc_frame_header *fc_hdr;
2811 struct lpfc_async_xchg_ctx *axchg = NULL;
2812 char *failwhy = NULL;
2813 uint32_t oxid, sid, did, fctl, size;
2816 d_buf = piocb->context2;
2818 nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2819 fc_hdr = nvmebuf->hbuf.virt;
2820 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
2821 sid = sli4_sid_from_fc_hdr(fc_hdr);
2822 did = sli4_did_from_fc_hdr(fc_hdr);
2823 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
2824 fc_hdr->fh_f_ctl[1] << 8 |
2825 fc_hdr->fh_f_ctl[2]);
2826 size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
2828 lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n",
2831 if (phba->pport->load_flag & FC_UNLOADING) {
2832 failwhy = "Driver Unloading";
2833 } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
2834 failwhy = "NVME FC4 Disabled";
2835 } else if (!phba->nvmet_support && !phba->pport->localport) {
2836 failwhy = "No Localport";
2837 } else if (phba->nvmet_support && !phba->targetport) {
2838 failwhy = "No Targetport";
2839 } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) {
2840 failwhy = "Bad NVME LS R_CTL";
2841 } else if (unlikely((fctl & 0x00FF0000) !=
2842 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) {
2843 failwhy = "Bad NVME LS F_CTL";
2845 axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC);
2847 failwhy = "No CTX memory";
2850 if (unlikely(failwhy)) {
2851 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC | LOG_NVME_IOERR,
2852 "6154 Drop NVME LS: SID %06X OXID x%X: %s\n",
2853 sid, oxid, failwhy);
2857 /* validate the source of the LS is logged in */
2858 ndlp = lpfc_findnode_did(phba->pport, sid);
2859 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
2860 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2861 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
2862 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
2863 "6216 NVME Unsol rcv: No ndlp: "
2864 "NPort_ID x%x oxid x%x\n",
2875 axchg->state = LPFC_NVME_STE_LS_RCV;
2876 axchg->entry_cnt = 1;
2877 axchg->rqb_buffer = (void *)nvmebuf;
2878 axchg->hdwq = &phba->sli4_hba.hdwq[0];
2879 axchg->payload = nvmebuf->dbuf.virt;
2880 INIT_LIST_HEAD(&axchg->list);
2882 if (phba->nvmet_support)
2883 ret = lpfc_nvmet_handle_lsreq(phba, axchg);
2885 ret = lpfc_nvme_handle_lsreq(phba, axchg);
2887 /* if zero, LS was successfully handled. If non-zero, LS not handled */
2891 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC | LOG_NVME_IOERR,
2892 "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X "
2893 "NVMe%s handler failed %d\n",
2895 (phba->nvmet_support) ? "T" : "I", ret);
2899 /* recycle receive buffer */
2900 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
2902 /* If start of new exchange, abort it */
2903 if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX)))
2904 ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
2911 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2912 * @phba: Pointer to HBA context object.
2913 * @pring: Pointer to driver SLI ring object.
2914 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2915 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2916 * @fch_type: the type for the first frame of the sequence.
2918 * This function is called with no lock held. This function uses the r_ctl and
2919 * type of the received sequence to find the correct callback function to call
2920 * to process the sequence.
2923 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2924 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
2931 lpfc_nvme_unsol_ls_handler(phba, saveq);
2937 /* unSolicited Responses */
2938 if (pring->prt[0].profile) {
2939 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
2940 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
2944 /* We must search, based on rctl / type
2945 for the right routine */
2946 for (i = 0; i < pring->num_mask; i++) {
2947 if ((pring->prt[i].rctl == fch_r_ctl) &&
2948 (pring->prt[i].type == fch_type)) {
2949 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
2950 (pring->prt[i].lpfc_sli_rcv_unsol_event)
2951 (phba, pring, saveq);
2959 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2960 * @phba: Pointer to HBA context object.
2961 * @pring: Pointer to driver SLI ring object.
2962 * @saveq: Pointer to the unsolicited iocb.
2964 * This function is called with no lock held by the ring event handler
2965 * when there is an unsolicited iocb posted to the response ring by the
2966 * firmware. This function gets the buffer associated with the iocbs
2967 * and calls the event handler for the ring. This function handles both
2968 * qring buffers and hbq buffers.
2969 * When the function returns 1 the caller can free the iocb object otherwise
2970 * upper layer functions will free the iocb objects.
2973 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2974 struct lpfc_iocbq *saveq)
2978 uint32_t Rctl, Type;
2979 struct lpfc_iocbq *iocbq;
2980 struct lpfc_dmabuf *dmzbuf;
2982 irsp = &(saveq->iocb);
2984 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
2985 if (pring->lpfc_sli_rcv_async_status)
2986 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
2988 lpfc_printf_log(phba,
2991 "0316 Ring %d handler: unexpected "
2992 "ASYNC_STATUS iocb received evt_code "
2995 irsp->un.asyncstat.evt_code);
2999 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
3000 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
3001 if (irsp->ulpBdeCount > 0) {
3002 dmzbuf = lpfc_sli_get_buff(phba, pring,
3003 irsp->un.ulpWord[3]);
3004 lpfc_in_buf_free(phba, dmzbuf);
3007 if (irsp->ulpBdeCount > 1) {
3008 dmzbuf = lpfc_sli_get_buff(phba, pring,
3009 irsp->unsli3.sli3Words[3]);
3010 lpfc_in_buf_free(phba, dmzbuf);
3013 if (irsp->ulpBdeCount > 2) {
3014 dmzbuf = lpfc_sli_get_buff(phba, pring,
3015 irsp->unsli3.sli3Words[7]);
3016 lpfc_in_buf_free(phba, dmzbuf);
3022 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3023 if (irsp->ulpBdeCount != 0) {
3024 saveq->context2 = lpfc_sli_get_buff(phba, pring,
3025 irsp->un.ulpWord[3]);
3026 if (!saveq->context2)
3027 lpfc_printf_log(phba,
3030 "0341 Ring %d Cannot find buffer for "
3031 "an unsolicited iocb. tag 0x%x\n",
3033 irsp->un.ulpWord[3]);
3035 if (irsp->ulpBdeCount == 2) {
3036 saveq->context3 = lpfc_sli_get_buff(phba, pring,
3037 irsp->unsli3.sli3Words[7]);
3038 if (!saveq->context3)
3039 lpfc_printf_log(phba,
3042 "0342 Ring %d Cannot find buffer for an"
3043 " unsolicited iocb. tag 0x%x\n",
3045 irsp->unsli3.sli3Words[7]);
3047 list_for_each_entry(iocbq, &saveq->list, list) {
3048 irsp = &(iocbq->iocb);
3049 if (irsp->ulpBdeCount != 0) {
3050 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
3051 irsp->un.ulpWord[3]);
3052 if (!iocbq->context2)
3053 lpfc_printf_log(phba,
3056 "0343 Ring %d Cannot find "
3057 "buffer for an unsolicited iocb"
3058 ". tag 0x%x\n", pring->ringno,
3059 irsp->un.ulpWord[3]);
3061 if (irsp->ulpBdeCount == 2) {
3062 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
3063 irsp->unsli3.sli3Words[7]);
3064 if (!iocbq->context3)
3065 lpfc_printf_log(phba,
3068 "0344 Ring %d Cannot find "
3069 "buffer for an unsolicited "
3072 irsp->unsli3.sli3Words[7]);
3076 if (irsp->ulpBdeCount != 0 &&
3077 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
3078 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
3081 /* search continue save q for same XRI */
3082 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
3083 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
3084 saveq->iocb.unsli3.rcvsli3.ox_id) {
3085 list_add_tail(&saveq->list, &iocbq->list);
3091 list_add_tail(&saveq->clist,
3092 &pring->iocb_continue_saveq);
3093 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
3094 list_del_init(&iocbq->clist);
3096 irsp = &(saveq->iocb);
3100 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
3101 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
3102 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
3103 Rctl = FC_RCTL_ELS_REQ;
3106 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
3107 Rctl = w5p->hcsw.Rctl;
3108 Type = w5p->hcsw.Type;
3110 /* Firmware Workaround */
3111 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
3112 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
3113 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
3114 Rctl = FC_RCTL_ELS_REQ;
3116 w5p->hcsw.Rctl = Rctl;
3117 w5p->hcsw.Type = Type;
3121 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
3122 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3123 "0313 Ring %d handler: unexpected Rctl x%x "
3124 "Type x%x received\n",
3125 pring->ringno, Rctl, Type);
3131 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
3132 * @phba: Pointer to HBA context object.
3133 * @pring: Pointer to driver SLI ring object.
3134 * @prspiocb: Pointer to response iocb object.
3136 * This function looks up the iocb_lookup table to get the command iocb
3137 * corresponding to the given response iocb using the iotag of the
3138 * response iocb. The driver calls this function with the hbalock held
3139 * for SLI3 ports or the ring lock held for SLI4 ports.
3140 * This function returns the command iocb object if it finds the command
3141 * iocb else returns NULL.
3143 static struct lpfc_iocbq *
3144 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
3145 struct lpfc_sli_ring *pring,
3146 struct lpfc_iocbq *prspiocb)
3148 struct lpfc_iocbq *cmd_iocb = NULL;
3150 spinlock_t *temp_lock = NULL;
3151 unsigned long iflag = 0;
3153 if (phba->sli_rev == LPFC_SLI_REV4)
3154 temp_lock = &pring->ring_lock;
3156 temp_lock = &phba->hbalock;
3158 spin_lock_irqsave(temp_lock, iflag);
3159 iotag = prspiocb->iocb.ulpIoTag;
3161 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3162 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3163 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3164 /* remove from txcmpl queue list */
3165 list_del_init(&cmd_iocb->list);
3166 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3167 pring->txcmplq_cnt--;
3168 spin_unlock_irqrestore(temp_lock, iflag);
3173 spin_unlock_irqrestore(temp_lock, iflag);
3174 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3175 "0317 iotag x%x is out of "
3176 "range: max iotag x%x wd0 x%x\n",
3177 iotag, phba->sli.last_iotag,
3178 *(((uint32_t *) &prspiocb->iocb) + 7));
3183 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
3184 * @phba: Pointer to HBA context object.
3185 * @pring: Pointer to driver SLI ring object.
3188 * This function looks up the iocb_lookup table to get the command iocb
3189 * corresponding to the given iotag. The driver calls this function with
3190 * the ring lock held because this function is an SLI4 port only helper.
3191 * This function returns the command iocb object if it finds the command
3192 * iocb else returns NULL.
3194 static struct lpfc_iocbq *
3195 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
3196 struct lpfc_sli_ring *pring, uint16_t iotag)
3198 struct lpfc_iocbq *cmd_iocb = NULL;
3199 spinlock_t *temp_lock = NULL;
3200 unsigned long iflag = 0;
3202 if (phba->sli_rev == LPFC_SLI_REV4)
3203 temp_lock = &pring->ring_lock;
3205 temp_lock = &phba->hbalock;
3207 spin_lock_irqsave(temp_lock, iflag);
3208 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3209 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3210 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3211 /* remove from txcmpl queue list */
3212 list_del_init(&cmd_iocb->list);
3213 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3214 pring->txcmplq_cnt--;
3215 spin_unlock_irqrestore(temp_lock, iflag);
3220 spin_unlock_irqrestore(temp_lock, iflag);
3221 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3222 "0372 iotag x%x lookup error: max iotag (x%x) "
3224 iotag, phba->sli.last_iotag,
3225 cmd_iocb ? cmd_iocb->iocb_flag : 0xffff);
3230 * lpfc_sli_process_sol_iocb - process solicited iocb completion
3231 * @phba: Pointer to HBA context object.
3232 * @pring: Pointer to driver SLI ring object.
3233 * @saveq: Pointer to the response iocb to be processed.
3235 * This function is called by the ring event handler for non-fcp
3236 * rings when there is a new response iocb in the response ring.
3237 * The caller is not required to hold any locks. This function
3238 * gets the command iocb associated with the response iocb and
3239 * calls the completion handler for the command iocb. If there
3240 * is no completion handler, the function will free the resources
3241 * associated with command iocb. If the response iocb is for
3242 * an already aborted command iocb, the status of the completion
3243 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
3244 * This function always returns 1.
3247 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3248 struct lpfc_iocbq *saveq)
3250 struct lpfc_iocbq *cmdiocbp;
3252 unsigned long iflag;
3254 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
3256 if (cmdiocbp->iocb_cmpl) {
3258 * If an ELS command failed send an event to mgmt
3261 if (saveq->iocb.ulpStatus &&
3262 (pring->ringno == LPFC_ELS_RING) &&
3263 (cmdiocbp->iocb.ulpCommand ==
3264 CMD_ELS_REQUEST64_CR))
3265 lpfc_send_els_failure_event(phba,
3269 * Post all ELS completions to the worker thread.
3270 * All other are passed to the completion callback.
3272 if (pring->ringno == LPFC_ELS_RING) {
3273 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3274 (cmdiocbp->iocb_flag &
3275 LPFC_DRIVER_ABORTED)) {
3276 spin_lock_irqsave(&phba->hbalock,
3278 cmdiocbp->iocb_flag &=
3279 ~LPFC_DRIVER_ABORTED;
3280 spin_unlock_irqrestore(&phba->hbalock,
3282 saveq->iocb.ulpStatus =
3283 IOSTAT_LOCAL_REJECT;
3284 saveq->iocb.un.ulpWord[4] =
3287 /* Firmware could still be in progress
3288 * of DMAing payload, so don't free data
3289 * buffer till after a hbeat.
3291 spin_lock_irqsave(&phba->hbalock,
3293 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
3294 spin_unlock_irqrestore(&phba->hbalock,
3297 if (phba->sli_rev == LPFC_SLI_REV4) {
3298 if (saveq->iocb_flag &
3299 LPFC_EXCHANGE_BUSY) {
3300 /* Set cmdiocb flag for the
3301 * exchange busy so sgl (xri)
3302 * will not be released until
3303 * the abort xri is received
3307 &phba->hbalock, iflag);
3308 cmdiocbp->iocb_flag |=
3310 spin_unlock_irqrestore(
3311 &phba->hbalock, iflag);
3313 if (cmdiocbp->iocb_flag &
3314 LPFC_DRIVER_ABORTED) {
3316 * Clear LPFC_DRIVER_ABORTED
3317 * bit in case it was driver
3321 &phba->hbalock, iflag);
3322 cmdiocbp->iocb_flag &=
3323 ~LPFC_DRIVER_ABORTED;
3324 spin_unlock_irqrestore(
3325 &phba->hbalock, iflag);
3326 cmdiocbp->iocb.ulpStatus =
3327 IOSTAT_LOCAL_REJECT;
3328 cmdiocbp->iocb.un.ulpWord[4] =
3329 IOERR_ABORT_REQUESTED;
3331 * For SLI4, irsiocb contains
3332 * NO_XRI in sli_xritag, it
3333 * shall not affect releasing
3334 * sgl (xri) process.
3336 saveq->iocb.ulpStatus =
3337 IOSTAT_LOCAL_REJECT;
3338 saveq->iocb.un.ulpWord[4] =
3341 &phba->hbalock, iflag);
3343 LPFC_DELAY_MEM_FREE;
3344 spin_unlock_irqrestore(
3345 &phba->hbalock, iflag);
3349 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
3351 lpfc_sli_release_iocbq(phba, cmdiocbp);
3354 * Unknown initiating command based on the response iotag.
3355 * This could be the case on the ELS ring because of
3358 if (pring->ringno != LPFC_ELS_RING) {
3360 * Ring <ringno> handler: unexpected completion IoTag
3363 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3364 "0322 Ring %d handler: "
3365 "unexpected completion IoTag x%x "
3366 "Data: x%x x%x x%x x%x\n",
3368 saveq->iocb.ulpIoTag,
3369 saveq->iocb.ulpStatus,
3370 saveq->iocb.un.ulpWord[4],
3371 saveq->iocb.ulpCommand,
3372 saveq->iocb.ulpContext);
3380 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
3381 * @phba: Pointer to HBA context object.
3382 * @pring: Pointer to driver SLI ring object.
3384 * This function is called from the iocb ring event handlers when
3385 * put pointer is ahead of the get pointer for a ring. This function signal
3386 * an error attention condition to the worker thread and the worker
3387 * thread will transition the HBA to offline state.
3390 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3392 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3394 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3395 * rsp ring <portRspMax>
3397 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3398 "0312 Ring %d handler: portRspPut %d "
3399 "is bigger than rsp ring %d\n",
3400 pring->ringno, le32_to_cpu(pgp->rspPutInx),
3401 pring->sli.sli3.numRiocb);
3403 phba->link_state = LPFC_HBA_ERROR;
3406 * All error attention handlers are posted to
3409 phba->work_ha |= HA_ERATT;
3410 phba->work_hs = HS_FFER3;
3412 lpfc_worker_wake_up(phba);
3418 * lpfc_poll_eratt - Error attention polling timer timeout handler
3419 * @ptr: Pointer to address of HBA context object.
3421 * This function is invoked by the Error Attention polling timer when the
3422 * timer times out. It will check the SLI Error Attention register for
3423 * possible attention events. If so, it will post an Error Attention event
3424 * and wake up worker thread to process it. Otherwise, it will set up the
3425 * Error Attention polling timer for the next poll.
3427 void lpfc_poll_eratt(struct timer_list *t)
3429 struct lpfc_hba *phba;
3431 uint64_t sli_intr, cnt;
3433 phba = from_timer(phba, t, eratt_poll);
3435 /* Here we will also keep track of interrupts per sec of the hba */
3436 sli_intr = phba->sli.slistat.sli_intr;
3438 if (phba->sli.slistat.sli_prev_intr > sli_intr)
3439 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
3442 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
3444 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3445 do_div(cnt, phba->eratt_poll_interval);
3446 phba->sli.slistat.sli_ips = cnt;
3448 phba->sli.slistat.sli_prev_intr = sli_intr;
3450 /* Check chip HA register for error event */
3451 eratt = lpfc_sli_check_eratt(phba);
3454 /* Tell the worker thread there is work to do */
3455 lpfc_worker_wake_up(phba);
3457 /* Restart the timer for next eratt poll */
3458 mod_timer(&phba->eratt_poll,
3460 msecs_to_jiffies(1000 * phba->eratt_poll_interval));
3466 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3467 * @phba: Pointer to HBA context object.
3468 * @pring: Pointer to driver SLI ring object.
3469 * @mask: Host attention register mask for this ring.
3471 * This function is called from the interrupt context when there is a ring
3472 * event for the fcp ring. The caller does not hold any lock.
3473 * The function processes each response iocb in the response ring until it
3474 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3475 * LE bit set. The function will call the completion handler of the command iocb
3476 * if the response iocb indicates a completion for a command iocb or it is
3477 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3478 * function if this is an unsolicited iocb.
3479 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3480 * to check it explicitly.
3483 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
3484 struct lpfc_sli_ring *pring, uint32_t mask)
3486 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3487 IOCB_t *irsp = NULL;
3488 IOCB_t *entry = NULL;
3489 struct lpfc_iocbq *cmdiocbq = NULL;
3490 struct lpfc_iocbq rspiocbq;
3492 uint32_t portRspPut, portRspMax;
3494 lpfc_iocb_type type;
3495 unsigned long iflag;
3496 uint32_t rsp_cmpl = 0;
3498 spin_lock_irqsave(&phba->hbalock, iflag);
3499 pring->stats.iocb_event++;
3502 * The next available response entry should never exceed the maximum
3503 * entries. If it does, treat it as an adapter hardware error.
3505 portRspMax = pring->sli.sli3.numRiocb;
3506 portRspPut = le32_to_cpu(pgp->rspPutInx);
3507 if (unlikely(portRspPut >= portRspMax)) {
3508 lpfc_sli_rsp_pointers_error(phba, pring);
3509 spin_unlock_irqrestore(&phba->hbalock, iflag);
3512 if (phba->fcp_ring_in_use) {
3513 spin_unlock_irqrestore(&phba->hbalock, iflag);
3516 phba->fcp_ring_in_use = 1;
3519 while (pring->sli.sli3.rspidx != portRspPut) {
3521 * Fetch an entry off the ring and copy it into a local data
3522 * structure. The copy involves a byte-swap since the
3523 * network byte order and pci byte orders are different.
3525 entry = lpfc_resp_iocb(phba, pring);
3526 phba->last_completion_time = jiffies;
3528 if (++pring->sli.sli3.rspidx >= portRspMax)
3529 pring->sli.sli3.rspidx = 0;
3531 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
3532 (uint32_t *) &rspiocbq.iocb,
3533 phba->iocb_rsp_size);
3534 INIT_LIST_HEAD(&(rspiocbq.list));
3535 irsp = &rspiocbq.iocb;
3537 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
3538 pring->stats.iocb_rsp++;
3541 if (unlikely(irsp->ulpStatus)) {
3543 * If resource errors reported from HBA, reduce
3544 * queuedepths of the SCSI device.
3546 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3547 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3548 IOERR_NO_RESOURCES)) {
3549 spin_unlock_irqrestore(&phba->hbalock, iflag);
3550 phba->lpfc_rampdown_queue_depth(phba);
3551 spin_lock_irqsave(&phba->hbalock, iflag);
3554 /* Rsp ring <ringno> error: IOCB */
3555 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3556 "0336 Rsp Ring %d error: IOCB Data: "
3557 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3559 irsp->un.ulpWord[0],
3560 irsp->un.ulpWord[1],
3561 irsp->un.ulpWord[2],
3562 irsp->un.ulpWord[3],
3563 irsp->un.ulpWord[4],
3564 irsp->un.ulpWord[5],
3565 *(uint32_t *)&irsp->un1,
3566 *((uint32_t *)&irsp->un1 + 1));
3570 case LPFC_ABORT_IOCB:
3573 * Idle exchange closed via ABTS from port. No iocb
3574 * resources need to be recovered.
3576 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
3577 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3578 "0333 IOCB cmd 0x%x"
3579 " processed. Skipping"
3585 spin_unlock_irqrestore(&phba->hbalock, iflag);
3586 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3588 spin_lock_irqsave(&phba->hbalock, iflag);
3589 if (unlikely(!cmdiocbq))
3591 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3592 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3593 if (cmdiocbq->iocb_cmpl) {
3594 spin_unlock_irqrestore(&phba->hbalock, iflag);
3595 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
3597 spin_lock_irqsave(&phba->hbalock, iflag);
3600 case LPFC_UNSOL_IOCB:
3601 spin_unlock_irqrestore(&phba->hbalock, iflag);
3602 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
3603 spin_lock_irqsave(&phba->hbalock, iflag);
3606 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3607 char adaptermsg[LPFC_MAX_ADPTMSG];
3608 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3609 memcpy(&adaptermsg[0], (uint8_t *) irsp,
3611 dev_warn(&((phba->pcidev)->dev),
3613 phba->brd_no, adaptermsg);
3615 /* Unknown IOCB command */
3616 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3617 "0334 Unknown IOCB command "
3618 "Data: x%x, x%x x%x x%x x%x\n",
3619 type, irsp->ulpCommand,
3628 * The response IOCB has been processed. Update the ring
3629 * pointer in SLIM. If the port response put pointer has not
3630 * been updated, sync the pgp->rspPutInx and fetch the new port
3631 * response put pointer.
3633 writel(pring->sli.sli3.rspidx,
3634 &phba->host_gp[pring->ringno].rspGetInx);
3636 if (pring->sli.sli3.rspidx == portRspPut)
3637 portRspPut = le32_to_cpu(pgp->rspPutInx);
3640 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
3641 pring->stats.iocb_rsp_full++;
3642 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3643 writel(status, phba->CAregaddr);
3644 readl(phba->CAregaddr);
3646 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3647 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3648 pring->stats.iocb_cmd_empty++;
3650 /* Force update of the local copy of cmdGetInx */
3651 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3652 lpfc_sli_resume_iocb(phba, pring);
3654 if ((pring->lpfc_sli_cmd_available))
3655 (pring->lpfc_sli_cmd_available) (phba, pring);
3659 phba->fcp_ring_in_use = 0;
3660 spin_unlock_irqrestore(&phba->hbalock, iflag);
3665 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3666 * @phba: Pointer to HBA context object.
3667 * @pring: Pointer to driver SLI ring object.
3668 * @rspiocbp: Pointer to driver response IOCB object.
3670 * This function is called from the worker thread when there is a slow-path
3671 * response IOCB to process. This function chains all the response iocbs until
3672 * seeing the iocb with the LE bit set. The function will call
3673 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3674 * completion of a command iocb. The function will call the
3675 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3676 * The function frees the resources or calls the completion handler if this
3677 * iocb is an abort completion. The function returns NULL when the response
3678 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3679 * this function shall chain the iocb on to the iocb_continueq and return the
3680 * response iocb passed in.
3682 static struct lpfc_iocbq *
3683 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3684 struct lpfc_iocbq *rspiocbp)
3686 struct lpfc_iocbq *saveq;
3687 struct lpfc_iocbq *cmdiocbp;
3688 struct lpfc_iocbq *next_iocb;
3689 IOCB_t *irsp = NULL;
3690 uint32_t free_saveq;
3691 uint8_t iocb_cmd_type;
3692 lpfc_iocb_type type;
3693 unsigned long iflag;
3696 spin_lock_irqsave(&phba->hbalock, iflag);
3697 /* First add the response iocb to the countinueq list */
3698 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3699 pring->iocb_continueq_cnt++;
3701 /* Now, determine whether the list is completed for processing */
3702 irsp = &rspiocbp->iocb;
3705 * By default, the driver expects to free all resources
3706 * associated with this iocb completion.
3709 saveq = list_get_first(&pring->iocb_continueq,
3710 struct lpfc_iocbq, list);
3711 irsp = &(saveq->iocb);
3712 list_del_init(&pring->iocb_continueq);
3713 pring->iocb_continueq_cnt = 0;
3715 pring->stats.iocb_rsp++;
3718 * If resource errors reported from HBA, reduce
3719 * queuedepths of the SCSI device.
3721 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3722 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3723 IOERR_NO_RESOURCES)) {
3724 spin_unlock_irqrestore(&phba->hbalock, iflag);
3725 phba->lpfc_rampdown_queue_depth(phba);
3726 spin_lock_irqsave(&phba->hbalock, iflag);
3729 if (irsp->ulpStatus) {
3730 /* Rsp ring <ringno> error: IOCB */
3731 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3732 "0328 Rsp Ring %d error: "
3737 "x%x x%x x%x x%x\n",
3739 irsp->un.ulpWord[0],
3740 irsp->un.ulpWord[1],
3741 irsp->un.ulpWord[2],
3742 irsp->un.ulpWord[3],
3743 irsp->un.ulpWord[4],
3744 irsp->un.ulpWord[5],
3745 *(((uint32_t *) irsp) + 6),
3746 *(((uint32_t *) irsp) + 7),
3747 *(((uint32_t *) irsp) + 8),
3748 *(((uint32_t *) irsp) + 9),
3749 *(((uint32_t *) irsp) + 10),
3750 *(((uint32_t *) irsp) + 11),
3751 *(((uint32_t *) irsp) + 12),
3752 *(((uint32_t *) irsp) + 13),
3753 *(((uint32_t *) irsp) + 14),
3754 *(((uint32_t *) irsp) + 15));
3758 * Fetch the IOCB command type and call the correct completion
3759 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3760 * get freed back to the lpfc_iocb_list by the discovery
3763 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3764 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3767 spin_unlock_irqrestore(&phba->hbalock, iflag);
3768 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3769 spin_lock_irqsave(&phba->hbalock, iflag);
3772 case LPFC_UNSOL_IOCB:
3773 spin_unlock_irqrestore(&phba->hbalock, iflag);
3774 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3775 spin_lock_irqsave(&phba->hbalock, iflag);
3780 case LPFC_ABORT_IOCB:
3782 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) {
3783 spin_unlock_irqrestore(&phba->hbalock, iflag);
3784 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3786 spin_lock_irqsave(&phba->hbalock, iflag);
3789 /* Call the specified completion routine */
3790 if (cmdiocbp->iocb_cmpl) {
3791 spin_unlock_irqrestore(&phba->hbalock,
3793 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3795 spin_lock_irqsave(&phba->hbalock,
3798 __lpfc_sli_release_iocbq(phba,
3803 case LPFC_UNKNOWN_IOCB:
3804 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3805 char adaptermsg[LPFC_MAX_ADPTMSG];
3806 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3807 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3809 dev_warn(&((phba->pcidev)->dev),
3811 phba->brd_no, adaptermsg);
3813 /* Unknown IOCB command */
3814 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3815 "0335 Unknown IOCB "
3816 "command Data: x%x "
3827 list_for_each_entry_safe(rspiocbp, next_iocb,
3828 &saveq->list, list) {
3829 list_del_init(&rspiocbp->list);
3830 __lpfc_sli_release_iocbq(phba, rspiocbp);
3832 __lpfc_sli_release_iocbq(phba, saveq);
3836 spin_unlock_irqrestore(&phba->hbalock, iflag);
3841 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3842 * @phba: Pointer to HBA context object.
3843 * @pring: Pointer to driver SLI ring object.
3844 * @mask: Host attention register mask for this ring.
3846 * This routine wraps the actual slow_ring event process routine from the
3847 * API jump table function pointer from the lpfc_hba struct.
3850 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
3851 struct lpfc_sli_ring *pring, uint32_t mask)
3853 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
3857 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3858 * @phba: Pointer to HBA context object.
3859 * @pring: Pointer to driver SLI ring object.
3860 * @mask: Host attention register mask for this ring.
3862 * This function is called from the worker thread when there is a ring event
3863 * for non-fcp rings. The caller does not hold any lock. The function will
3864 * remove each response iocb in the response ring and calls the handle
3865 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3868 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
3869 struct lpfc_sli_ring *pring, uint32_t mask)
3871 struct lpfc_pgp *pgp;
3873 IOCB_t *irsp = NULL;
3874 struct lpfc_iocbq *rspiocbp = NULL;
3875 uint32_t portRspPut, portRspMax;
3876 unsigned long iflag;
3879 pgp = &phba->port_gp[pring->ringno];
3880 spin_lock_irqsave(&phba->hbalock, iflag);
3881 pring->stats.iocb_event++;
3884 * The next available response entry should never exceed the maximum
3885 * entries. If it does, treat it as an adapter hardware error.
3887 portRspMax = pring->sli.sli3.numRiocb;
3888 portRspPut = le32_to_cpu(pgp->rspPutInx);
3889 if (portRspPut >= portRspMax) {
3891 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3892 * rsp ring <portRspMax>
3894 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3895 "0303 Ring %d handler: portRspPut %d "
3896 "is bigger than rsp ring %d\n",
3897 pring->ringno, portRspPut, portRspMax);
3899 phba->link_state = LPFC_HBA_ERROR;
3900 spin_unlock_irqrestore(&phba->hbalock, iflag);
3902 phba->work_hs = HS_FFER3;
3903 lpfc_handle_eratt(phba);
3909 while (pring->sli.sli3.rspidx != portRspPut) {
3911 * Build a completion list and call the appropriate handler.
3912 * The process is to get the next available response iocb, get
3913 * a free iocb from the list, copy the response data into the
3914 * free iocb, insert to the continuation list, and update the
3915 * next response index to slim. This process makes response
3916 * iocb's in the ring available to DMA as fast as possible but
3917 * pays a penalty for a copy operation. Since the iocb is
3918 * only 32 bytes, this penalty is considered small relative to
3919 * the PCI reads for register values and a slim write. When
3920 * the ulpLe field is set, the entire Command has been
3923 entry = lpfc_resp_iocb(phba, pring);
3925 phba->last_completion_time = jiffies;
3926 rspiocbp = __lpfc_sli_get_iocbq(phba);
3927 if (rspiocbp == NULL) {
3928 printk(KERN_ERR "%s: out of buffers! Failing "
3929 "completion.\n", __func__);
3933 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
3934 phba->iocb_rsp_size);
3935 irsp = &rspiocbp->iocb;
3937 if (++pring->sli.sli3.rspidx >= portRspMax)
3938 pring->sli.sli3.rspidx = 0;
3940 if (pring->ringno == LPFC_ELS_RING) {
3941 lpfc_debugfs_slow_ring_trc(phba,
3942 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3943 *(((uint32_t *) irsp) + 4),
3944 *(((uint32_t *) irsp) + 6),
3945 *(((uint32_t *) irsp) + 7));
3948 writel(pring->sli.sli3.rspidx,
3949 &phba->host_gp[pring->ringno].rspGetInx);
3951 spin_unlock_irqrestore(&phba->hbalock, iflag);
3952 /* Handle the response IOCB */
3953 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
3954 spin_lock_irqsave(&phba->hbalock, iflag);
3957 * If the port response put pointer has not been updated, sync
3958 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3959 * response put pointer.
3961 if (pring->sli.sli3.rspidx == portRspPut) {
3962 portRspPut = le32_to_cpu(pgp->rspPutInx);
3964 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3966 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
3967 /* At least one response entry has been freed */
3968 pring->stats.iocb_rsp_full++;
3969 /* SET RxRE_RSP in Chip Att register */
3970 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3971 writel(status, phba->CAregaddr);
3972 readl(phba->CAregaddr); /* flush */
3974 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3975 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3976 pring->stats.iocb_cmd_empty++;
3978 /* Force update of the local copy of cmdGetInx */
3979 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3980 lpfc_sli_resume_iocb(phba, pring);
3982 if ((pring->lpfc_sli_cmd_available))
3983 (pring->lpfc_sli_cmd_available) (phba, pring);
3987 spin_unlock_irqrestore(&phba->hbalock, iflag);
3992 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3993 * @phba: Pointer to HBA context object.
3994 * @pring: Pointer to driver SLI ring object.
3995 * @mask: Host attention register mask for this ring.
3997 * This function is called from the worker thread when there is a pending
3998 * ELS response iocb on the driver internal slow-path response iocb worker
3999 * queue. The caller does not hold any lock. The function will remove each
4000 * response iocb from the response worker queue and calls the handle
4001 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4004 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
4005 struct lpfc_sli_ring *pring, uint32_t mask)
4007 struct lpfc_iocbq *irspiocbq;
4008 struct hbq_dmabuf *dmabuf;
4009 struct lpfc_cq_event *cq_event;
4010 unsigned long iflag;
4013 spin_lock_irqsave(&phba->hbalock, iflag);
4014 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
4015 spin_unlock_irqrestore(&phba->hbalock, iflag);
4016 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
4017 /* Get the response iocb from the head of work queue */
4018 spin_lock_irqsave(&phba->hbalock, iflag);
4019 list_remove_head(&phba->sli4_hba.sp_queue_event,
4020 cq_event, struct lpfc_cq_event, list);
4021 spin_unlock_irqrestore(&phba->hbalock, iflag);
4023 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
4024 case CQE_CODE_COMPL_WQE:
4025 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
4027 /* Translate ELS WCQE to response IOCBQ */
4028 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
4031 lpfc_sli_sp_handle_rspiocb(phba, pring,
4035 case CQE_CODE_RECEIVE:
4036 case CQE_CODE_RECEIVE_V1:
4037 dmabuf = container_of(cq_event, struct hbq_dmabuf,
4039 lpfc_sli4_handle_received_buffer(phba, dmabuf);
4046 /* Limit the number of events to 64 to avoid soft lockups */
4053 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
4054 * @phba: Pointer to HBA context object.
4055 * @pring: Pointer to driver SLI ring object.
4057 * This function aborts all iocbs in the given ring and frees all the iocb
4058 * objects in txq. This function issues an abort iocb for all the iocb commands
4059 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4060 * the return of this function. The caller is not required to hold any locks.
4063 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
4065 LIST_HEAD(completions);
4066 struct lpfc_iocbq *iocb, *next_iocb;
4068 if (pring->ringno == LPFC_ELS_RING) {
4069 lpfc_fabric_abort_hba(phba);
4072 /* Error everything on txq and txcmplq
4075 if (phba->sli_rev >= LPFC_SLI_REV4) {
4076 spin_lock_irq(&pring->ring_lock);
4077 list_splice_init(&pring->txq, &completions);
4079 spin_unlock_irq(&pring->ring_lock);
4081 spin_lock_irq(&phba->hbalock);
4082 /* Next issue ABTS for everything on the txcmplq */
4083 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
4084 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
4085 spin_unlock_irq(&phba->hbalock);
4087 spin_lock_irq(&phba->hbalock);
4088 list_splice_init(&pring->txq, &completions);
4091 /* Next issue ABTS for everything on the txcmplq */
4092 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
4093 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
4094 spin_unlock_irq(&phba->hbalock);
4097 /* Cancel all the IOCBs from the completions list */
4098 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4103 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
4104 * @phba: Pointer to HBA context object.
4105 * @pring: Pointer to driver SLI ring object.
4107 * This function aborts all iocbs in FCP rings and frees all the iocb
4108 * objects in txq. This function issues an abort iocb for all the iocb commands
4109 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4110 * the return of this function. The caller is not required to hold any locks.
4113 lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
4115 struct lpfc_sli *psli = &phba->sli;
4116 struct lpfc_sli_ring *pring;
4119 /* Look on all the FCP Rings for the iotag */
4120 if (phba->sli_rev >= LPFC_SLI_REV4) {
4121 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4122 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4123 lpfc_sli_abort_iocb_ring(phba, pring);
4126 pring = &psli->sli3_ring[LPFC_FCP_RING];
4127 lpfc_sli_abort_iocb_ring(phba, pring);
4132 * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
4133 * @phba: Pointer to HBA context object.
4135 * This function flushes all iocbs in the IO ring and frees all the iocb
4136 * objects in txq and txcmplq. This function will not issue abort iocbs
4137 * for all the iocb commands in txcmplq, they will just be returned with
4138 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
4139 * slot has been permanently disabled.
4142 lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
4146 struct lpfc_sli *psli = &phba->sli;
4147 struct lpfc_sli_ring *pring;
4149 struct lpfc_iocbq *piocb, *next_iocb;
4151 spin_lock_irq(&phba->hbalock);
4152 if (phba->hba_flag & HBA_IOQ_FLUSH ||
4153 !phba->sli4_hba.hdwq) {
4154 spin_unlock_irq(&phba->hbalock);
4157 /* Indicate the I/O queues are flushed */
4158 phba->hba_flag |= HBA_IOQ_FLUSH;
4159 spin_unlock_irq(&phba->hbalock);
4161 /* Look on all the FCP Rings for the iotag */
4162 if (phba->sli_rev >= LPFC_SLI_REV4) {
4163 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4164 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4166 spin_lock_irq(&pring->ring_lock);
4167 /* Retrieve everything on txq */
4168 list_splice_init(&pring->txq, &txq);
4169 list_for_each_entry_safe(piocb, next_iocb,
4170 &pring->txcmplq, list)
4171 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4172 /* Retrieve everything on the txcmplq */
4173 list_splice_init(&pring->txcmplq, &txcmplq);
4175 pring->txcmplq_cnt = 0;
4176 spin_unlock_irq(&pring->ring_lock);
4179 lpfc_sli_cancel_iocbs(phba, &txq,
4180 IOSTAT_LOCAL_REJECT,
4182 /* Flush the txcmpq */
4183 lpfc_sli_cancel_iocbs(phba, &txcmplq,
4184 IOSTAT_LOCAL_REJECT,
4188 pring = &psli->sli3_ring[LPFC_FCP_RING];
4190 spin_lock_irq(&phba->hbalock);
4191 /* Retrieve everything on txq */
4192 list_splice_init(&pring->txq, &txq);
4193 list_for_each_entry_safe(piocb, next_iocb,
4194 &pring->txcmplq, list)
4195 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4196 /* Retrieve everything on the txcmplq */
4197 list_splice_init(&pring->txcmplq, &txcmplq);
4199 pring->txcmplq_cnt = 0;
4200 spin_unlock_irq(&phba->hbalock);
4203 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
4205 /* Flush the txcmpq */
4206 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
4212 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
4213 * @phba: Pointer to HBA context object.
4214 * @mask: Bit mask to be checked.
4216 * This function reads the host status register and compares
4217 * with the provided bit mask to check if HBA completed
4218 * the restart. This function will wait in a loop for the
4219 * HBA to complete restart. If the HBA does not restart within
4220 * 15 iterations, the function will reset the HBA again. The
4221 * function returns 1 when HBA fail to restart otherwise returns
4225 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
4231 /* Read the HBA Host Status Register */
4232 if (lpfc_readl(phba->HSregaddr, &status))
4236 * Check status register every 100ms for 5 retries, then every
4237 * 500ms for 5, then every 2.5 sec for 5, then reset board and
4238 * every 2.5 sec for 4.
4239 * Break our of the loop if errors occurred during init.
4241 while (((status & mask) != mask) &&
4242 !(status & HS_FFERM) &&
4254 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4255 lpfc_sli_brdrestart(phba);
4257 /* Read the HBA Host Status Register */
4258 if (lpfc_readl(phba->HSregaddr, &status)) {
4264 /* Check to see if any errors occurred during init */
4265 if ((status & HS_FFERM) || (i >= 20)) {
4266 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4267 "2751 Adapter failed to restart, "
4268 "status reg x%x, FW Data: A8 x%x AC x%x\n",
4270 readl(phba->MBslimaddr + 0xa8),
4271 readl(phba->MBslimaddr + 0xac));
4272 phba->link_state = LPFC_HBA_ERROR;
4280 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
4281 * @phba: Pointer to HBA context object.
4282 * @mask: Bit mask to be checked.
4284 * This function checks the host status register to check if HBA is
4285 * ready. This function will wait in a loop for the HBA to be ready
4286 * If the HBA is not ready , the function will will reset the HBA PCI
4287 * function again. The function returns 1 when HBA fail to be ready
4288 * otherwise returns zero.
4291 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
4296 /* Read the HBA Host Status Register */
4297 status = lpfc_sli4_post_status_check(phba);
4300 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4301 lpfc_sli_brdrestart(phba);
4302 status = lpfc_sli4_post_status_check(phba);
4305 /* Check to see if any errors occurred during init */
4307 phba->link_state = LPFC_HBA_ERROR;
4310 phba->sli4_hba.intr_enable = 0;
4316 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
4317 * @phba: Pointer to HBA context object.
4318 * @mask: Bit mask to be checked.
4320 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
4321 * from the API jump table function pointer from the lpfc_hba struct.
4324 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
4326 return phba->lpfc_sli_brdready(phba, mask);
4329 #define BARRIER_TEST_PATTERN (0xdeadbeef)
4332 * lpfc_reset_barrier - Make HBA ready for HBA reset
4333 * @phba: Pointer to HBA context object.
4335 * This function is called before resetting an HBA. This function is called
4336 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4338 void lpfc_reset_barrier(struct lpfc_hba *phba)
4340 uint32_t __iomem *resp_buf;
4341 uint32_t __iomem *mbox_buf;
4342 volatile uint32_t mbox;
4343 uint32_t hc_copy, ha_copy, resp_data;
4347 lockdep_assert_held(&phba->hbalock);
4349 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
4350 if (hdrtype != 0x80 ||
4351 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
4352 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
4356 * Tell the other part of the chip to suspend temporarily all
4359 resp_buf = phba->MBslimaddr;
4361 /* Disable the error attention */
4362 if (lpfc_readl(phba->HCregaddr, &hc_copy))
4364 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
4365 readl(phba->HCregaddr); /* flush */
4366 phba->link_flag |= LS_IGNORE_ERATT;
4368 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4370 if (ha_copy & HA_ERATT) {
4371 /* Clear Chip error bit */
4372 writel(HA_ERATT, phba->HAregaddr);
4373 phba->pport->stopped = 1;
4377 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
4378 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
4380 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
4381 mbox_buf = phba->MBslimaddr;
4382 writel(mbox, mbox_buf);
4384 for (i = 0; i < 50; i++) {
4385 if (lpfc_readl((resp_buf + 1), &resp_data))
4387 if (resp_data != ~(BARRIER_TEST_PATTERN))
4393 if (lpfc_readl((resp_buf + 1), &resp_data))
4395 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
4396 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
4397 phba->pport->stopped)
4403 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
4405 for (i = 0; i < 500; i++) {
4406 if (lpfc_readl(resp_buf, &resp_data))
4408 if (resp_data != mbox)
4417 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4419 if (!(ha_copy & HA_ERATT))
4425 if (readl(phba->HAregaddr) & HA_ERATT) {
4426 writel(HA_ERATT, phba->HAregaddr);
4427 phba->pport->stopped = 1;
4431 phba->link_flag &= ~LS_IGNORE_ERATT;
4432 writel(hc_copy, phba->HCregaddr);
4433 readl(phba->HCregaddr); /* flush */
4437 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4438 * @phba: Pointer to HBA context object.
4440 * This function issues a kill_board mailbox command and waits for
4441 * the error attention interrupt. This function is called for stopping
4442 * the firmware processing. The caller is not required to hold any
4443 * locks. This function calls lpfc_hba_down_post function to free
4444 * any pending commands after the kill. The function will return 1 when it
4445 * fails to kill the board else will return 0.
4448 lpfc_sli_brdkill(struct lpfc_hba *phba)
4450 struct lpfc_sli *psli;
4460 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4461 "0329 Kill HBA Data: x%x x%x\n",
4462 phba->pport->port_state, psli->sli_flag);
4464 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4468 /* Disable the error attention */
4469 spin_lock_irq(&phba->hbalock);
4470 if (lpfc_readl(phba->HCregaddr, &status)) {
4471 spin_unlock_irq(&phba->hbalock);
4472 mempool_free(pmb, phba->mbox_mem_pool);
4475 status &= ~HC_ERINT_ENA;
4476 writel(status, phba->HCregaddr);
4477 readl(phba->HCregaddr); /* flush */
4478 phba->link_flag |= LS_IGNORE_ERATT;
4479 spin_unlock_irq(&phba->hbalock);
4481 lpfc_kill_board(phba, pmb);
4482 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4483 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4485 if (retval != MBX_SUCCESS) {
4486 if (retval != MBX_BUSY)
4487 mempool_free(pmb, phba->mbox_mem_pool);
4488 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4489 "2752 KILL_BOARD command failed retval %d\n",
4491 spin_lock_irq(&phba->hbalock);
4492 phba->link_flag &= ~LS_IGNORE_ERATT;
4493 spin_unlock_irq(&phba->hbalock);
4497 spin_lock_irq(&phba->hbalock);
4498 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4499 spin_unlock_irq(&phba->hbalock);
4501 mempool_free(pmb, phba->mbox_mem_pool);
4503 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4504 * attention every 100ms for 3 seconds. If we don't get ERATT after
4505 * 3 seconds we still set HBA_ERROR state because the status of the
4506 * board is now undefined.
4508 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4510 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
4512 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4516 del_timer_sync(&psli->mbox_tmo);
4517 if (ha_copy & HA_ERATT) {
4518 writel(HA_ERATT, phba->HAregaddr);
4519 phba->pport->stopped = 1;
4521 spin_lock_irq(&phba->hbalock);
4522 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4523 psli->mbox_active = NULL;
4524 phba->link_flag &= ~LS_IGNORE_ERATT;
4525 spin_unlock_irq(&phba->hbalock);
4527 lpfc_hba_down_post(phba);
4528 phba->link_state = LPFC_HBA_ERROR;
4530 return ha_copy & HA_ERATT ? 0 : 1;
4534 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4535 * @phba: Pointer to HBA context object.
4537 * This function resets the HBA by writing HC_INITFF to the control
4538 * register. After the HBA resets, this function resets all the iocb ring
4539 * indices. This function disables PCI layer parity checking during
4541 * This function returns 0 always.
4542 * The caller is not required to hold any locks.
4545 lpfc_sli_brdreset(struct lpfc_hba *phba)
4547 struct lpfc_sli *psli;
4548 struct lpfc_sli_ring *pring;
4555 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4556 "0325 Reset HBA Data: x%x x%x\n",
4557 (phba->pport) ? phba->pport->port_state : 0,
4560 /* perform board reset */
4561 phba->fc_eventTag = 0;
4562 phba->link_events = 0;
4564 phba->pport->fc_myDID = 0;
4565 phba->pport->fc_prevDID = 0;
4568 /* Turn off parity checking and serr during the physical reset */
4569 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
4572 pci_write_config_word(phba->pcidev, PCI_COMMAND,
4574 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4576 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
4578 /* Now toggle INITFF bit in the Host Control Register */
4579 writel(HC_INITFF, phba->HCregaddr);
4581 readl(phba->HCregaddr); /* flush */
4582 writel(0, phba->HCregaddr);
4583 readl(phba->HCregaddr); /* flush */
4585 /* Restore PCI cmd register */
4586 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4588 /* Initialize relevant SLI info */
4589 for (i = 0; i < psli->num_rings; i++) {
4590 pring = &psli->sli3_ring[i];
4592 pring->sli.sli3.rspidx = 0;
4593 pring->sli.sli3.next_cmdidx = 0;
4594 pring->sli.sli3.local_getidx = 0;
4595 pring->sli.sli3.cmdidx = 0;
4596 pring->missbufcnt = 0;
4599 phba->link_state = LPFC_WARM_START;
4604 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4605 * @phba: Pointer to HBA context object.
4607 * This function resets a SLI4 HBA. This function disables PCI layer parity
4608 * checking during resets the device. The caller is not required to hold
4611 * This function returns 0 on success else returns negative error code.
4614 lpfc_sli4_brdreset(struct lpfc_hba *phba)
4616 struct lpfc_sli *psli = &phba->sli;
4621 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4622 "0295 Reset HBA Data: x%x x%x x%x\n",
4623 phba->pport->port_state, psli->sli_flag,
4626 /* perform board reset */
4627 phba->fc_eventTag = 0;
4628 phba->link_events = 0;
4629 phba->pport->fc_myDID = 0;
4630 phba->pport->fc_prevDID = 0;
4632 spin_lock_irq(&phba->hbalock);
4633 psli->sli_flag &= ~(LPFC_PROCESS_LA);
4634 phba->fcf.fcf_flag = 0;
4635 spin_unlock_irq(&phba->hbalock);
4637 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4638 if (phba->hba_flag & HBA_FW_DUMP_OP) {
4639 phba->hba_flag &= ~HBA_FW_DUMP_OP;
4643 /* Now physically reset the device */
4644 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4645 "0389 Performing PCI function reset!\n");
4647 /* Turn off parity checking and serr during the physical reset */
4648 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
4649 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4650 "3205 PCI read Config failed\n");
4654 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
4655 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4657 /* Perform FCoE PCI function reset before freeing queue memory */
4658 rc = lpfc_pci_function_reset(phba);
4660 /* Restore PCI cmd register */
4661 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4667 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4668 * @phba: Pointer to HBA context object.
4670 * This function is called in the SLI initialization code path to
4671 * restart the HBA. The caller is not required to hold any lock.
4672 * This function writes MBX_RESTART mailbox command to the SLIM and
4673 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4674 * function to free any pending commands. The function enables
4675 * POST only during the first initialization. The function returns zero.
4676 * The function does not guarantee completion of MBX_RESTART mailbox
4677 * command before the return of this function.
4680 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
4683 struct lpfc_sli *psli;
4684 volatile uint32_t word0;
4685 void __iomem *to_slim;
4686 uint32_t hba_aer_enabled;
4688 spin_lock_irq(&phba->hbalock);
4690 /* Take PCIe device Advanced Error Reporting (AER) state */
4691 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4696 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4697 "0337 Restart HBA Data: x%x x%x\n",
4698 (phba->pport) ? phba->pport->port_state : 0,
4702 mb = (MAILBOX_t *) &word0;
4703 mb->mbxCommand = MBX_RESTART;
4706 lpfc_reset_barrier(phba);
4708 to_slim = phba->MBslimaddr;
4709 writel(*(uint32_t *) mb, to_slim);
4710 readl(to_slim); /* flush */
4712 /* Only skip post after fc_ffinit is completed */
4713 if (phba->pport && phba->pport->port_state)
4714 word0 = 1; /* This is really setting up word1 */
4716 word0 = 0; /* This is really setting up word1 */
4717 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4718 writel(*(uint32_t *) mb, to_slim);
4719 readl(to_slim); /* flush */
4721 lpfc_sli_brdreset(phba);
4723 phba->pport->stopped = 0;
4724 phba->link_state = LPFC_INIT_START;
4726 spin_unlock_irq(&phba->hbalock);
4728 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4729 psli->stats_start = ktime_get_seconds();
4731 /* Give the INITFF and Post time to settle. */
4734 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4735 if (hba_aer_enabled)
4736 pci_disable_pcie_error_reporting(phba->pcidev);
4738 lpfc_hba_down_post(phba);
4744 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4745 * @phba: Pointer to HBA context object.
4747 * This function is called in the SLI initialization code path to restart
4748 * a SLI4 HBA. The caller is not required to hold any lock.
4749 * At the end of the function, it calls lpfc_hba_down_post function to
4750 * free any pending commands.
4753 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
4755 struct lpfc_sli *psli = &phba->sli;
4756 uint32_t hba_aer_enabled;
4760 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4761 "0296 Restart HBA Data: x%x x%x\n",
4762 phba->pport->port_state, psli->sli_flag);
4764 /* Take PCIe device Advanced Error Reporting (AER) state */
4765 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4767 rc = lpfc_sli4_brdreset(phba);
4769 phba->link_state = LPFC_HBA_ERROR;
4770 goto hba_down_queue;
4773 spin_lock_irq(&phba->hbalock);
4774 phba->pport->stopped = 0;
4775 phba->link_state = LPFC_INIT_START;
4777 spin_unlock_irq(&phba->hbalock);
4779 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4780 psli->stats_start = ktime_get_seconds();
4782 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4783 if (hba_aer_enabled)
4784 pci_disable_pcie_error_reporting(phba->pcidev);
4787 lpfc_hba_down_post(phba);
4788 lpfc_sli4_queue_destroy(phba);
4794 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4795 * @phba: Pointer to HBA context object.
4797 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4798 * API jump table function pointer from the lpfc_hba struct.
4801 lpfc_sli_brdrestart(struct lpfc_hba *phba)
4803 return phba->lpfc_sli_brdrestart(phba);
4807 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4808 * @phba: Pointer to HBA context object.
4810 * This function is called after a HBA restart to wait for successful
4811 * restart of the HBA. Successful restart of the HBA is indicated by
4812 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4813 * iteration, the function will restart the HBA again. The function returns
4814 * zero if HBA successfully restarted else returns negative error code.
4817 lpfc_sli_chipset_init(struct lpfc_hba *phba)
4819 uint32_t status, i = 0;
4821 /* Read the HBA Host Status Register */
4822 if (lpfc_readl(phba->HSregaddr, &status))
4825 /* Check status register to see what current state is */
4827 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4829 /* Check every 10ms for 10 retries, then every 100ms for 90
4830 * retries, then every 1 sec for 50 retires for a total of
4831 * ~60 seconds before reset the board again and check every
4832 * 1 sec for 50 retries. The up to 60 seconds before the
4833 * board ready is required by the Falcon FIPS zeroization
4834 * complete, and any reset the board in between shall cause
4835 * restart of zeroization, further delay the board ready.
4838 /* Adapter failed to init, timeout, status reg
4840 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4841 "0436 Adapter failed to init, "
4842 "timeout, status reg x%x, "
4843 "FW Data: A8 x%x AC x%x\n", status,
4844 readl(phba->MBslimaddr + 0xa8),
4845 readl(phba->MBslimaddr + 0xac));
4846 phba->link_state = LPFC_HBA_ERROR;
4850 /* Check to see if any errors occurred during init */
4851 if (status & HS_FFERM) {
4852 /* ERROR: During chipset initialization */
4853 /* Adapter failed to init, chipset, status reg
4855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4856 "0437 Adapter failed to init, "
4857 "chipset, status reg x%x, "
4858 "FW Data: A8 x%x AC x%x\n", status,
4859 readl(phba->MBslimaddr + 0xa8),
4860 readl(phba->MBslimaddr + 0xac));
4861 phba->link_state = LPFC_HBA_ERROR;
4874 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4875 lpfc_sli_brdrestart(phba);
4877 /* Read the HBA Host Status Register */
4878 if (lpfc_readl(phba->HSregaddr, &status))
4882 /* Check to see if any errors occurred during init */
4883 if (status & HS_FFERM) {
4884 /* ERROR: During chipset initialization */
4885 /* Adapter failed to init, chipset, status reg <status> */
4886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4887 "0438 Adapter failed to init, chipset, "
4889 "FW Data: A8 x%x AC x%x\n", status,
4890 readl(phba->MBslimaddr + 0xa8),
4891 readl(phba->MBslimaddr + 0xac));
4892 phba->link_state = LPFC_HBA_ERROR;
4896 /* Clear all interrupt enable conditions */
4897 writel(0, phba->HCregaddr);
4898 readl(phba->HCregaddr); /* flush */
4900 /* setup host attn register */
4901 writel(0xffffffff, phba->HAregaddr);
4902 readl(phba->HAregaddr); /* flush */
4907 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4909 * This function calculates and returns the number of HBQs required to be
4913 lpfc_sli_hbq_count(void)
4915 return ARRAY_SIZE(lpfc_hbq_defs);
4919 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4921 * This function adds the number of hbq entries in every HBQ to get
4922 * the total number of hbq entries required for the HBA and returns
4926 lpfc_sli_hbq_entry_count(void)
4928 int hbq_count = lpfc_sli_hbq_count();
4932 for (i = 0; i < hbq_count; ++i)
4933 count += lpfc_hbq_defs[i]->entry_count;
4938 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4940 * This function calculates amount of memory required for all hbq entries
4941 * to be configured and returns the total memory required.
4944 lpfc_sli_hbq_size(void)
4946 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
4950 * lpfc_sli_hbq_setup - configure and initialize HBQs
4951 * @phba: Pointer to HBA context object.
4953 * This function is called during the SLI initialization to configure
4954 * all the HBQs and post buffers to the HBQ. The caller is not
4955 * required to hold any locks. This function will return zero if successful
4956 * else it will return negative error code.
4959 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
4961 int hbq_count = lpfc_sli_hbq_count();
4965 uint32_t hbq_entry_index;
4967 /* Get a Mailbox buffer to setup mailbox
4968 * commands for HBA initialization
4970 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4977 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4978 phba->link_state = LPFC_INIT_MBX_CMDS;
4979 phba->hbq_in_use = 1;
4981 hbq_entry_index = 0;
4982 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
4983 phba->hbqs[hbqno].next_hbqPutIdx = 0;
4984 phba->hbqs[hbqno].hbqPutIdx = 0;
4985 phba->hbqs[hbqno].local_hbqGetIdx = 0;
4986 phba->hbqs[hbqno].entry_count =
4987 lpfc_hbq_defs[hbqno]->entry_count;
4988 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
4989 hbq_entry_index, pmb);
4990 hbq_entry_index += phba->hbqs[hbqno].entry_count;
4992 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
4993 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4994 mbxStatus <status>, ring <num> */
4996 lpfc_printf_log(phba, KERN_ERR,
4997 LOG_SLI | LOG_VPORT,
4998 "1805 Adapter failed to init. "
4999 "Data: x%x x%x x%x\n",
5001 pmbox->mbxStatus, hbqno);
5003 phba->link_state = LPFC_HBA_ERROR;
5004 mempool_free(pmb, phba->mbox_mem_pool);
5008 phba->hbq_count = hbq_count;
5010 mempool_free(pmb, phba->mbox_mem_pool);
5012 /* Initially populate or replenish the HBQs */
5013 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
5014 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
5019 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
5020 * @phba: Pointer to HBA context object.
5022 * This function is called during the SLI initialization to configure
5023 * all the HBQs and post buffers to the HBQ. The caller is not
5024 * required to hold any locks. This function will return zero if successful
5025 * else it will return negative error code.
5028 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
5030 phba->hbq_in_use = 1;
5032 * Specific case when the MDS diagnostics is enabled and supported.
5033 * The receive buffer count is truncated to manage the incoming
5036 if (phba->cfg_enable_mds_diags && phba->mds_diags_support)
5037 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5038 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1;
5040 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5041 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
5042 phba->hbq_count = 1;
5043 lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
5044 /* Initially populate or replenish the HBQs */
5049 * lpfc_sli_config_port - Issue config port mailbox command
5050 * @phba: Pointer to HBA context object.
5051 * @sli_mode: sli mode - 2/3
5053 * This function is called by the sli initialization code path
5054 * to issue config_port mailbox command. This function restarts the
5055 * HBA firmware and issues a config_port mailbox command to configure
5056 * the SLI interface in the sli mode specified by sli_mode
5057 * variable. The caller is not required to hold any locks.
5058 * The function returns 0 if successful, else returns negative error
5062 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
5065 uint32_t resetcount = 0, rc = 0, done = 0;
5067 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5069 phba->link_state = LPFC_HBA_ERROR;
5073 phba->sli_rev = sli_mode;
5074 while (resetcount < 2 && !done) {
5075 spin_lock_irq(&phba->hbalock);
5076 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5077 spin_unlock_irq(&phba->hbalock);
5078 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5079 lpfc_sli_brdrestart(phba);
5080 rc = lpfc_sli_chipset_init(phba);
5084 spin_lock_irq(&phba->hbalock);
5085 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5086 spin_unlock_irq(&phba->hbalock);
5089 /* Call pre CONFIG_PORT mailbox command initialization. A
5090 * value of 0 means the call was successful. Any other
5091 * nonzero value is a failure, but if ERESTART is returned,
5092 * the driver may reset the HBA and try again.
5094 rc = lpfc_config_port_prep(phba);
5095 if (rc == -ERESTART) {
5096 phba->link_state = LPFC_LINK_UNKNOWN;
5101 phba->link_state = LPFC_INIT_MBX_CMDS;
5102 lpfc_config_port(phba, pmb);
5103 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
5104 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
5105 LPFC_SLI3_HBQ_ENABLED |
5106 LPFC_SLI3_CRP_ENABLED |
5107 LPFC_SLI3_DSS_ENABLED);
5108 if (rc != MBX_SUCCESS) {
5109 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5110 "0442 Adapter failed to init, mbxCmd x%x "
5111 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
5112 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
5113 spin_lock_irq(&phba->hbalock);
5114 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
5115 spin_unlock_irq(&phba->hbalock);
5118 /* Allow asynchronous mailbox command to go through */
5119 spin_lock_irq(&phba->hbalock);
5120 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5121 spin_unlock_irq(&phba->hbalock);
5124 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
5125 (pmb->u.mb.un.varCfgPort.gasabt == 0))
5126 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5127 "3110 Port did not grant ASABT\n");
5132 goto do_prep_failed;
5134 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
5135 if (!pmb->u.mb.un.varCfgPort.cMA) {
5137 goto do_prep_failed;
5139 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
5140 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
5141 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
5142 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
5143 phba->max_vpi : phba->max_vports;
5147 if (pmb->u.mb.un.varCfgPort.gerbm)
5148 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
5149 if (pmb->u.mb.un.varCfgPort.gcrp)
5150 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
5152 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
5153 phba->port_gp = phba->mbox->us.s3_pgp.port;
5155 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5156 if (pmb->u.mb.un.varCfgPort.gbg == 0) {
5157 phba->cfg_enable_bg = 0;
5158 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
5159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5160 "0443 Adapter did not grant "
5165 phba->hbq_get = NULL;
5166 phba->port_gp = phba->mbox->us.s2.port;
5170 mempool_free(pmb, phba->mbox_mem_pool);
5176 * lpfc_sli_hba_setup - SLI initialization function
5177 * @phba: Pointer to HBA context object.
5179 * This function is the main SLI initialization function. This function
5180 * is called by the HBA initialization code, HBA reset code and HBA
5181 * error attention handler code. Caller is not required to hold any
5182 * locks. This function issues config_port mailbox command to configure
5183 * the SLI, setup iocb rings and HBQ rings. In the end the function
5184 * calls the config_port_post function to issue init_link mailbox
5185 * command and to start the discovery. The function will return zero
5186 * if successful, else it will return negative error code.
5189 lpfc_sli_hba_setup(struct lpfc_hba *phba)
5195 switch (phba->cfg_sli_mode) {
5197 if (phba->cfg_enable_npiv) {
5198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
5199 "1824 NPIV enabled: Override sli_mode "
5200 "parameter (%d) to auto (0).\n",
5201 phba->cfg_sli_mode);
5210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
5211 "1819 Unrecognized sli_mode parameter: %d.\n",
5212 phba->cfg_sli_mode);
5216 phba->fcp_embed_io = 0; /* SLI4 FC support only */
5218 rc = lpfc_sli_config_port(phba, mode);
5220 if (rc && phba->cfg_sli_mode == 3)
5221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
5222 "1820 Unable to select SLI-3. "
5223 "Not supported by adapter.\n");
5224 if (rc && mode != 2)
5225 rc = lpfc_sli_config_port(phba, 2);
5226 else if (rc && mode == 2)
5227 rc = lpfc_sli_config_port(phba, 3);
5229 goto lpfc_sli_hba_setup_error;
5231 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5232 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
5233 rc = pci_enable_pcie_error_reporting(phba->pcidev);
5235 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5236 "2709 This device supports "
5237 "Advanced Error Reporting (AER)\n");
5238 spin_lock_irq(&phba->hbalock);
5239 phba->hba_flag |= HBA_AER_ENABLED;
5240 spin_unlock_irq(&phba->hbalock);
5242 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5243 "2708 This device does not support "
5244 "Advanced Error Reporting (AER): %d\n",
5246 phba->cfg_aer_support = 0;
5250 if (phba->sli_rev == 3) {
5251 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
5252 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
5254 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
5255 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
5256 phba->sli3_options = 0;
5259 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5260 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
5261 phba->sli_rev, phba->max_vpi);
5262 rc = lpfc_sli_ring_map(phba);
5265 goto lpfc_sli_hba_setup_error;
5267 /* Initialize VPIs. */
5268 if (phba->sli_rev == LPFC_SLI_REV3) {
5270 * The VPI bitmask and physical ID array are allocated
5271 * and initialized once only - at driver load. A port
5272 * reset doesn't need to reinitialize this memory.
5274 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
5275 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
5276 phba->vpi_bmask = kcalloc(longs,
5277 sizeof(unsigned long),
5279 if (!phba->vpi_bmask) {
5281 goto lpfc_sli_hba_setup_error;
5284 phba->vpi_ids = kcalloc(phba->max_vpi + 1,
5287 if (!phba->vpi_ids) {
5288 kfree(phba->vpi_bmask);
5290 goto lpfc_sli_hba_setup_error;
5292 for (i = 0; i < phba->max_vpi; i++)
5293 phba->vpi_ids[i] = i;
5298 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5299 rc = lpfc_sli_hbq_setup(phba);
5301 goto lpfc_sli_hba_setup_error;
5303 spin_lock_irq(&phba->hbalock);
5304 phba->sli.sli_flag |= LPFC_PROCESS_LA;
5305 spin_unlock_irq(&phba->hbalock);
5307 rc = lpfc_config_port_post(phba);
5309 goto lpfc_sli_hba_setup_error;
5313 lpfc_sli_hba_setup_error:
5314 phba->link_state = LPFC_HBA_ERROR;
5315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5316 "0445 Firmware initialization failed\n");
5321 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
5322 * @phba: Pointer to HBA context object.
5323 * @mboxq: mailbox pointer.
5324 * This function issue a dump mailbox command to read config region
5325 * 23 and parse the records in the region and populate driver
5329 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
5331 LPFC_MBOXQ_t *mboxq;
5332 struct lpfc_dmabuf *mp;
5333 struct lpfc_mqe *mqe;
5334 uint32_t data_length;
5337 /* Program the default value of vlan_id and fc_map */
5338 phba->valid_vlan = 0;
5339 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5340 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5341 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5343 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5347 mqe = &mboxq->u.mqe;
5348 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
5350 goto out_free_mboxq;
5353 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
5354 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5356 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5357 "(%d):2571 Mailbox cmd x%x Status x%x "
5358 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5359 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5360 "CQ: x%x x%x x%x x%x\n",
5361 mboxq->vport ? mboxq->vport->vpi : 0,
5362 bf_get(lpfc_mqe_command, mqe),
5363 bf_get(lpfc_mqe_status, mqe),
5364 mqe->un.mb_words[0], mqe->un.mb_words[1],
5365 mqe->un.mb_words[2], mqe->un.mb_words[3],
5366 mqe->un.mb_words[4], mqe->un.mb_words[5],
5367 mqe->un.mb_words[6], mqe->un.mb_words[7],
5368 mqe->un.mb_words[8], mqe->un.mb_words[9],
5369 mqe->un.mb_words[10], mqe->un.mb_words[11],
5370 mqe->un.mb_words[12], mqe->un.mb_words[13],
5371 mqe->un.mb_words[14], mqe->un.mb_words[15],
5372 mqe->un.mb_words[16], mqe->un.mb_words[50],
5374 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5375 mboxq->mcqe.trailer);
5378 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5381 goto out_free_mboxq;
5383 data_length = mqe->un.mb_words[5];
5384 if (data_length > DMP_RGN23_SIZE) {
5385 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5388 goto out_free_mboxq;
5391 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
5392 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5397 mempool_free(mboxq, phba->mbox_mem_pool);
5402 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5403 * @phba: pointer to lpfc hba data structure.
5404 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5405 * @vpd: pointer to the memory to hold resulting port vpd data.
5406 * @vpd_size: On input, the number of bytes allocated to @vpd.
5407 * On output, the number of data bytes in @vpd.
5409 * This routine executes a READ_REV SLI4 mailbox command. In
5410 * addition, this routine gets the port vpd data.
5414 * -ENOMEM - could not allocated memory.
5417 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5418 uint8_t *vpd, uint32_t *vpd_size)
5422 struct lpfc_dmabuf *dmabuf;
5423 struct lpfc_mqe *mqe;
5425 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5430 * Get a DMA buffer for the vpd data resulting from the READ_REV
5433 dma_size = *vpd_size;
5434 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
5435 &dmabuf->phys, GFP_KERNEL);
5436 if (!dmabuf->virt) {
5442 * The SLI4 implementation of READ_REV conflicts at word1,
5443 * bits 31:16 and SLI4 adds vpd functionality not present
5444 * in SLI3. This code corrects the conflicts.
5446 lpfc_read_rev(phba, mboxq);
5447 mqe = &mboxq->u.mqe;
5448 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
5449 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
5450 mqe->un.read_rev.word1 &= 0x0000FFFF;
5451 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
5452 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
5454 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5456 dma_free_coherent(&phba->pcidev->dev, dma_size,
5457 dmabuf->virt, dmabuf->phys);
5463 * The available vpd length cannot be bigger than the
5464 * DMA buffer passed to the port. Catch the less than
5465 * case and update the caller's size.
5467 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
5468 *vpd_size = mqe->un.read_rev.avail_vpd_len;
5470 memcpy(vpd, dmabuf->virt, *vpd_size);
5472 dma_free_coherent(&phba->pcidev->dev, dma_size,
5473 dmabuf->virt, dmabuf->phys);
5479 * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
5480 * @phba: pointer to lpfc hba data structure.
5482 * This routine retrieves SLI4 device physical port name this PCI function
5487 * otherwise - failed to retrieve controller attributes
5490 lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
5492 LPFC_MBOXQ_t *mboxq;
5493 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
5494 struct lpfc_controller_attribute *cntl_attr;
5495 void *virtaddr = NULL;
5496 uint32_t alloclen, reqlen;
5497 uint32_t shdr_status, shdr_add_status;
5498 union lpfc_sli4_cfg_shdr *shdr;
5501 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5505 /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
5506 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
5507 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5508 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
5509 LPFC_SLI4_MBX_NEMBED);
5511 if (alloclen < reqlen) {
5512 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5513 "3084 Allocated DMA memory size (%d) is "
5514 "less than the requested DMA memory size "
5515 "(%d)\n", alloclen, reqlen);
5517 goto out_free_mboxq;
5519 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5520 virtaddr = mboxq->sge_array->addr[0];
5521 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
5522 shdr = &mbx_cntl_attr->cfg_shdr;
5523 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5524 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5525 if (shdr_status || shdr_add_status || rc) {
5526 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5527 "3085 Mailbox x%x (x%x/x%x) failed, "
5528 "rc:x%x, status:x%x, add_status:x%x\n",
5529 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5530 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5531 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5532 rc, shdr_status, shdr_add_status);
5534 goto out_free_mboxq;
5537 cntl_attr = &mbx_cntl_attr->cntl_attr;
5538 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
5539 phba->sli4_hba.lnk_info.lnk_tp =
5540 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
5541 phba->sli4_hba.lnk_info.lnk_no =
5542 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
5544 memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
5545 strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
5546 sizeof(phba->BIOSVersion));
5548 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5549 "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n",
5550 phba->sli4_hba.lnk_info.lnk_tp,
5551 phba->sli4_hba.lnk_info.lnk_no,
5554 if (rc != MBX_TIMEOUT) {
5555 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5556 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5558 mempool_free(mboxq, phba->mbox_mem_pool);
5564 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5565 * @phba: pointer to lpfc hba data structure.
5567 * This routine retrieves SLI4 device physical port name this PCI function
5572 * otherwise - failed to retrieve physical port name
5575 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
5577 LPFC_MBOXQ_t *mboxq;
5578 struct lpfc_mbx_get_port_name *get_port_name;
5579 uint32_t shdr_status, shdr_add_status;
5580 union lpfc_sli4_cfg_shdr *shdr;
5581 char cport_name = 0;
5584 /* We assume nothing at this point */
5585 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5586 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
5588 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5591 /* obtain link type and link number via READ_CONFIG */
5592 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5593 lpfc_sli4_read_config(phba);
5594 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
5595 goto retrieve_ppname;
5597 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5598 rc = lpfc_sli4_get_ctl_attr(phba);
5600 goto out_free_mboxq;
5603 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5604 LPFC_MBOX_OPCODE_GET_PORT_NAME,
5605 sizeof(struct lpfc_mbx_get_port_name) -
5606 sizeof(struct lpfc_sli4_cfg_mhdr),
5607 LPFC_SLI4_MBX_EMBED);
5608 get_port_name = &mboxq->u.mqe.un.get_port_name;
5609 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
5610 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
5611 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
5612 phba->sli4_hba.lnk_info.lnk_tp);
5613 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5614 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5615 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5616 if (shdr_status || shdr_add_status || rc) {
5617 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5618 "3087 Mailbox x%x (x%x/x%x) failed: "
5619 "rc:x%x, status:x%x, add_status:x%x\n",
5620 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5621 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5622 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5623 rc, shdr_status, shdr_add_status);
5625 goto out_free_mboxq;
5627 switch (phba->sli4_hba.lnk_info.lnk_no) {
5628 case LPFC_LINK_NUMBER_0:
5629 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
5630 &get_port_name->u.response);
5631 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5633 case LPFC_LINK_NUMBER_1:
5634 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
5635 &get_port_name->u.response);
5636 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5638 case LPFC_LINK_NUMBER_2:
5639 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
5640 &get_port_name->u.response);
5641 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5643 case LPFC_LINK_NUMBER_3:
5644 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
5645 &get_port_name->u.response);
5646 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5652 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
5653 phba->Port[0] = cport_name;
5654 phba->Port[1] = '\0';
5655 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5656 "3091 SLI get port name: %s\n", phba->Port);
5660 if (rc != MBX_TIMEOUT) {
5661 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5662 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5664 mempool_free(mboxq, phba->mbox_mem_pool);
5670 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5671 * @phba: pointer to lpfc hba data structure.
5673 * This routine is called to explicitly arm the SLI4 device's completion and
5677 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
5680 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
5681 struct lpfc_sli4_hdw_queue *qp;
5682 struct lpfc_queue *eq;
5684 sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
5685 sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
5686 if (sli4_hba->nvmels_cq)
5687 sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
5690 if (sli4_hba->hdwq) {
5691 /* Loop thru all Hardware Queues */
5692 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
5693 qp = &sli4_hba->hdwq[qidx];
5694 /* ARM the corresponding CQ */
5695 sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
5699 /* Loop thru all IRQ vectors */
5700 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
5701 eq = sli4_hba->hba_eq_hdl[qidx].eq;
5702 /* ARM the corresponding EQ */
5703 sli4_hba->sli4_write_eq_db(phba, eq,
5704 0, LPFC_QUEUE_REARM);
5708 if (phba->nvmet_support) {
5709 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
5710 sli4_hba->sli4_write_cq_db(phba,
5711 sli4_hba->nvmet_cqset[qidx], 0,
5718 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5719 * @phba: Pointer to HBA context object.
5720 * @type: The resource extent type.
5721 * @extnt_count: buffer to hold port available extent count.
5722 * @extnt_size: buffer to hold element count per extent.
5724 * This function calls the port and retrievs the number of available
5725 * extents and their size for a particular extent type.
5727 * Returns: 0 if successful. Nonzero otherwise.
5730 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
5731 uint16_t *extnt_count, uint16_t *extnt_size)
5736 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
5739 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5743 /* Find out how many extents are available for this resource type */
5744 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
5745 sizeof(struct lpfc_sli4_cfg_mhdr));
5746 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5747 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
5748 length, LPFC_SLI4_MBX_EMBED);
5750 /* Send an extents count of 0 - the GET doesn't use it. */
5751 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5752 LPFC_SLI4_MBX_EMBED);
5758 if (!phba->sli4_hba.intr_enable)
5759 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5761 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5762 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5769 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
5770 if (bf_get(lpfc_mbox_hdr_status,
5771 &rsrc_info->header.cfg_shdr.response)) {
5772 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5773 "2930 Failed to get resource extents "
5774 "Status 0x%x Add'l Status 0x%x\n",
5775 bf_get(lpfc_mbox_hdr_status,
5776 &rsrc_info->header.cfg_shdr.response),
5777 bf_get(lpfc_mbox_hdr_add_status,
5778 &rsrc_info->header.cfg_shdr.response));
5783 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
5785 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
5788 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5789 "3162 Retrieved extents type-%d from port: count:%d, "
5790 "size:%d\n", type, *extnt_count, *extnt_size);
5793 mempool_free(mbox, phba->mbox_mem_pool);
5798 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5799 * @phba: Pointer to HBA context object.
5800 * @type: The extent type to check.
5802 * This function reads the current available extents from the port and checks
5803 * if the extent count or extent size has changed since the last access.
5804 * Callers use this routine post port reset to understand if there is a
5805 * extent reprovisioning requirement.
5808 * -Error: error indicates problem.
5809 * 1: Extent count or size has changed.
5813 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
5815 uint16_t curr_ext_cnt, rsrc_ext_cnt;
5816 uint16_t size_diff, rsrc_ext_size;
5818 struct lpfc_rsrc_blks *rsrc_entry;
5819 struct list_head *rsrc_blk_list = NULL;
5823 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5830 case LPFC_RSC_TYPE_FCOE_RPI:
5831 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5833 case LPFC_RSC_TYPE_FCOE_VPI:
5834 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
5836 case LPFC_RSC_TYPE_FCOE_XRI:
5837 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5839 case LPFC_RSC_TYPE_FCOE_VFI:
5840 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5846 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
5848 if (rsrc_entry->rsrc_size != rsrc_ext_size)
5852 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
5859 * lpfc_sli4_cfg_post_extnts -
5860 * @phba: Pointer to HBA context object.
5861 * @extnt_cnt - number of available extents.
5862 * @type - the extent type (rpi, xri, vfi, vpi).
5863 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5864 * @mbox - pointer to the caller's allocated mailbox structure.
5866 * This function executes the extents allocation request. It also
5867 * takes care of the amount of memory needed to allocate or get the
5868 * allocated extents. It is the caller's responsibility to evaluate
5872 * -Error: Error value describes the condition found.
5876 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
5877 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
5882 uint32_t alloc_len, mbox_tmo;
5884 /* Calculate the total requested length of the dma memory */
5885 req_len = extnt_cnt * sizeof(uint16_t);
5888 * Calculate the size of an embedded mailbox. The uint32_t
5889 * accounts for extents-specific word.
5891 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
5895 * Presume the allocation and response will fit into an embedded
5896 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5898 *emb = LPFC_SLI4_MBX_EMBED;
5899 if (req_len > emb_len) {
5900 req_len = extnt_cnt * sizeof(uint16_t) +
5901 sizeof(union lpfc_sli4_cfg_shdr) +
5903 *emb = LPFC_SLI4_MBX_NEMBED;
5906 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5907 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
5909 if (alloc_len < req_len) {
5910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5911 "2982 Allocated DMA memory size (x%x) is "
5912 "less than the requested DMA memory "
5913 "size (x%x)\n", alloc_len, req_len);
5916 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
5920 if (!phba->sli4_hba.intr_enable)
5921 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5923 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5924 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5933 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5934 * @phba: Pointer to HBA context object.
5935 * @type: The resource extent type to allocate.
5937 * This function allocates the number of elements for the specified
5941 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
5944 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
5945 uint16_t rsrc_id, rsrc_start, j, k;
5948 unsigned long longs;
5949 unsigned long *bmask;
5950 struct lpfc_rsrc_blks *rsrc_blks;
5953 struct lpfc_id_range *id_array = NULL;
5954 void *virtaddr = NULL;
5955 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
5956 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
5957 struct list_head *ext_blk_list;
5959 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5965 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
5966 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
5967 "3009 No available Resource Extents "
5968 "for resource type 0x%x: Count: 0x%x, "
5969 "Size 0x%x\n", type, rsrc_cnt,
5974 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
5975 "2903 Post resource extents type-0x%x: "
5976 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
5978 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5982 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
5989 * Figure out where the response is located. Then get local pointers
5990 * to the response data. The port does not guarantee to respond to
5991 * all extents counts request so update the local variable with the
5992 * allocated count from the port.
5994 if (emb == LPFC_SLI4_MBX_EMBED) {
5995 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
5996 id_array = &rsrc_ext->u.rsp.id[0];
5997 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
5999 virtaddr = mbox->sge_array->addr[0];
6000 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6001 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6002 id_array = &n_rsrc->id;
6005 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
6006 rsrc_id_cnt = rsrc_cnt * rsrc_size;
6009 * Based on the resource size and count, correct the base and max
6012 length = sizeof(struct lpfc_rsrc_blks);
6014 case LPFC_RSC_TYPE_FCOE_RPI:
6015 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6016 sizeof(unsigned long),
6018 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6022 phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
6025 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6026 kfree(phba->sli4_hba.rpi_bmask);
6032 * The next_rpi was initialized with the maximum available
6033 * count but the port may allocate a smaller number. Catch
6034 * that case and update the next_rpi.
6036 phba->sli4_hba.next_rpi = rsrc_id_cnt;
6038 /* Initialize local ptrs for common extent processing later. */
6039 bmask = phba->sli4_hba.rpi_bmask;
6040 ids = phba->sli4_hba.rpi_ids;
6041 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
6043 case LPFC_RSC_TYPE_FCOE_VPI:
6044 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6046 if (unlikely(!phba->vpi_bmask)) {
6050 phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
6052 if (unlikely(!phba->vpi_ids)) {
6053 kfree(phba->vpi_bmask);
6058 /* Initialize local ptrs for common extent processing later. */
6059 bmask = phba->vpi_bmask;
6060 ids = phba->vpi_ids;
6061 ext_blk_list = &phba->lpfc_vpi_blk_list;
6063 case LPFC_RSC_TYPE_FCOE_XRI:
6064 phba->sli4_hba.xri_bmask = kcalloc(longs,
6065 sizeof(unsigned long),
6067 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6071 phba->sli4_hba.max_cfg_param.xri_used = 0;
6072 phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
6075 if (unlikely(!phba->sli4_hba.xri_ids)) {
6076 kfree(phba->sli4_hba.xri_bmask);
6081 /* Initialize local ptrs for common extent processing later. */
6082 bmask = phba->sli4_hba.xri_bmask;
6083 ids = phba->sli4_hba.xri_ids;
6084 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
6086 case LPFC_RSC_TYPE_FCOE_VFI:
6087 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6088 sizeof(unsigned long),
6090 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6094 phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
6097 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6098 kfree(phba->sli4_hba.vfi_bmask);
6103 /* Initialize local ptrs for common extent processing later. */
6104 bmask = phba->sli4_hba.vfi_bmask;
6105 ids = phba->sli4_hba.vfi_ids;
6106 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
6109 /* Unsupported Opcode. Fail call. */
6113 ext_blk_list = NULL;
6118 * Complete initializing the extent configuration with the
6119 * allocated ids assigned to this function. The bitmask serves
6120 * as an index into the array and manages the available ids. The
6121 * array just stores the ids communicated to the port via the wqes.
6123 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
6125 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
6128 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
6131 rsrc_blks = kzalloc(length, GFP_KERNEL);
6132 if (unlikely(!rsrc_blks)) {
6138 rsrc_blks->rsrc_start = rsrc_id;
6139 rsrc_blks->rsrc_size = rsrc_size;
6140 list_add_tail(&rsrc_blks->list, ext_blk_list);
6141 rsrc_start = rsrc_id;
6142 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
6143 phba->sli4_hba.io_xri_start = rsrc_start +
6144 lpfc_sli4_get_iocb_cnt(phba);
6147 while (rsrc_id < (rsrc_start + rsrc_size)) {
6152 /* Entire word processed. Get next word.*/
6157 lpfc_sli4_mbox_cmd_free(phba, mbox);
6164 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
6165 * @phba: Pointer to HBA context object.
6166 * @type: the extent's type.
6168 * This function deallocates all extents of a particular resource type.
6169 * SLI4 does not allow for deallocating a particular extent range. It
6170 * is the caller's responsibility to release all kernel memory resources.
6173 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
6176 uint32_t length, mbox_tmo = 0;
6178 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
6179 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
6181 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6186 * This function sends an embedded mailbox because it only sends the
6187 * the resource type. All extents of this type are released by the
6190 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
6191 sizeof(struct lpfc_sli4_cfg_mhdr));
6192 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6193 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
6194 length, LPFC_SLI4_MBX_EMBED);
6196 /* Send an extents count of 0 - the dealloc doesn't use it. */
6197 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6198 LPFC_SLI4_MBX_EMBED);
6203 if (!phba->sli4_hba.intr_enable)
6204 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6206 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6207 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6214 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
6215 if (bf_get(lpfc_mbox_hdr_status,
6216 &dealloc_rsrc->header.cfg_shdr.response)) {
6217 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
6218 "2919 Failed to release resource extents "
6219 "for type %d - Status 0x%x Add'l Status 0x%x. "
6220 "Resource memory not released.\n",
6222 bf_get(lpfc_mbox_hdr_status,
6223 &dealloc_rsrc->header.cfg_shdr.response),
6224 bf_get(lpfc_mbox_hdr_add_status,
6225 &dealloc_rsrc->header.cfg_shdr.response));
6230 /* Release kernel memory resources for the specific type. */
6232 case LPFC_RSC_TYPE_FCOE_VPI:
6233 kfree(phba->vpi_bmask);
6234 kfree(phba->vpi_ids);
6235 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6236 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6237 &phba->lpfc_vpi_blk_list, list) {
6238 list_del_init(&rsrc_blk->list);
6241 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6243 case LPFC_RSC_TYPE_FCOE_XRI:
6244 kfree(phba->sli4_hba.xri_bmask);
6245 kfree(phba->sli4_hba.xri_ids);
6246 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6247 &phba->sli4_hba.lpfc_xri_blk_list, list) {
6248 list_del_init(&rsrc_blk->list);
6252 case LPFC_RSC_TYPE_FCOE_VFI:
6253 kfree(phba->sli4_hba.vfi_bmask);
6254 kfree(phba->sli4_hba.vfi_ids);
6255 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6256 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6257 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
6258 list_del_init(&rsrc_blk->list);
6262 case LPFC_RSC_TYPE_FCOE_RPI:
6263 /* RPI bitmask and physical id array are cleaned up earlier. */
6264 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6265 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
6266 list_del_init(&rsrc_blk->list);
6274 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6277 mempool_free(mbox, phba->mbox_mem_pool);
6282 lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
6287 len = sizeof(struct lpfc_mbx_set_feature) -
6288 sizeof(struct lpfc_sli4_cfg_mhdr);
6289 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6290 LPFC_MBOX_OPCODE_SET_FEATURES, len,
6291 LPFC_SLI4_MBX_EMBED);
6294 case LPFC_SET_UE_RECOVERY:
6295 bf_set(lpfc_mbx_set_feature_UER,
6296 &mbox->u.mqe.un.set_feature, 1);
6297 mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
6298 mbox->u.mqe.un.set_feature.param_len = 8;
6300 case LPFC_SET_MDS_DIAGS:
6301 bf_set(lpfc_mbx_set_feature_mds,
6302 &mbox->u.mqe.un.set_feature, 1);
6303 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
6304 &mbox->u.mqe.un.set_feature, 1);
6305 mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
6306 mbox->u.mqe.un.set_feature.param_len = 8;
6308 case LPFC_SET_DUAL_DUMP:
6309 bf_set(lpfc_mbx_set_feature_dd,
6310 &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP);
6311 bf_set(lpfc_mbx_set_feature_ddquery,
6312 &mbox->u.mqe.un.set_feature, 0);
6313 mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP;
6314 mbox->u.mqe.un.set_feature.param_len = 4;
6322 * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
6323 * @phba: Pointer to HBA context object.
6325 * Disable FW logging into host memory on the adapter. To
6326 * be done before reading logs from the host memory.
6329 lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
6331 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6333 spin_lock_irq(&phba->hbalock);
6334 ras_fwlog->state = INACTIVE;
6335 spin_unlock_irq(&phba->hbalock);
6337 /* Disable FW logging to host memory */
6338 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
6339 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
6341 /* Wait 10ms for firmware to stop using DMA buffer */
6342 usleep_range(10 * 1000, 20 * 1000);
6346 * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
6347 * @phba: Pointer to HBA context object.
6349 * This function is called to free memory allocated for RAS FW logging
6350 * support in the driver.
6353 lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
6355 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6356 struct lpfc_dmabuf *dmabuf, *next;
6358 if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
6359 list_for_each_entry_safe(dmabuf, next,
6360 &ras_fwlog->fwlog_buff_list,
6362 list_del(&dmabuf->list);
6363 dma_free_coherent(&phba->pcidev->dev,
6364 LPFC_RAS_MAX_ENTRY_SIZE,
6365 dmabuf->virt, dmabuf->phys);
6370 if (ras_fwlog->lwpd.virt) {
6371 dma_free_coherent(&phba->pcidev->dev,
6372 sizeof(uint32_t) * 2,
6373 ras_fwlog->lwpd.virt,
6374 ras_fwlog->lwpd.phys);
6375 ras_fwlog->lwpd.virt = NULL;
6378 spin_lock_irq(&phba->hbalock);
6379 ras_fwlog->state = INACTIVE;
6380 spin_unlock_irq(&phba->hbalock);
6384 * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
6385 * @phba: Pointer to HBA context object.
6386 * @fwlog_buff_count: Count of buffers to be created.
6388 * This routine DMA memory for Log Write Position Data[LPWD] and buffer
6389 * to update FW log is posted to the adapter.
6390 * Buffer count is calculated based on module param ras_fwlog_buffsize
6391 * Size of each buffer posted to FW is 64K.
6395 lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
6396 uint32_t fwlog_buff_count)
6398 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6399 struct lpfc_dmabuf *dmabuf;
6402 /* Initialize List */
6403 INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
6405 /* Allocate memory for the LWPD */
6406 ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
6407 sizeof(uint32_t) * 2,
6408 &ras_fwlog->lwpd.phys,
6410 if (!ras_fwlog->lwpd.virt) {
6411 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6412 "6185 LWPD Memory Alloc Failed\n");
6417 ras_fwlog->fw_buffcount = fwlog_buff_count;
6418 for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
6419 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
6423 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6424 "6186 Memory Alloc failed FW logging");
6428 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6429 LPFC_RAS_MAX_ENTRY_SIZE,
6430 &dmabuf->phys, GFP_KERNEL);
6431 if (!dmabuf->virt) {
6434 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6435 "6187 DMA Alloc Failed FW logging");
6438 dmabuf->buffer_tag = i;
6439 list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
6444 lpfc_sli4_ras_dma_free(phba);
6450 * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
6451 * @phba: pointer to lpfc hba data structure.
6452 * @pmboxq: pointer to the driver internal queue element for mailbox command.
6454 * Completion handler for driver's RAS MBX command to the device.
6457 lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6460 union lpfc_sli4_cfg_shdr *shdr;
6461 uint32_t shdr_status, shdr_add_status;
6462 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6466 shdr = (union lpfc_sli4_cfg_shdr *)
6467 &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
6468 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6469 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6471 if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
6472 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
6473 "6188 FW LOG mailbox "
6474 "completed with status x%x add_status x%x,"
6475 " mbx status x%x\n",
6476 shdr_status, shdr_add_status, mb->mbxStatus);
6478 ras_fwlog->ras_hwsupport = false;
6482 spin_lock_irq(&phba->hbalock);
6483 ras_fwlog->state = ACTIVE;
6484 spin_unlock_irq(&phba->hbalock);
6485 mempool_free(pmb, phba->mbox_mem_pool);
6490 /* Free RAS DMA memory */
6491 lpfc_sli4_ras_dma_free(phba);
6492 mempool_free(pmb, phba->mbox_mem_pool);
6496 * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
6497 * @phba: pointer to lpfc hba data structure.
6498 * @fwlog_level: Logging verbosity level.
6499 * @fwlog_enable: Enable/Disable logging.
6501 * Initialize memory and post mailbox command to enable FW logging in host
6505 lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
6506 uint32_t fwlog_level,
6507 uint32_t fwlog_enable)
6509 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6510 struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
6511 struct lpfc_dmabuf *dmabuf;
6513 uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
6516 spin_lock_irq(&phba->hbalock);
6517 ras_fwlog->state = INACTIVE;
6518 spin_unlock_irq(&phba->hbalock);
6520 fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
6521 phba->cfg_ras_fwlog_buffsize);
6522 fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
6525 * If re-enabling FW logging support use earlier allocated
6526 * DMA buffers while posting MBX command.
6528 if (!ras_fwlog->lwpd.virt) {
6529 rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
6531 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6532 "6189 FW Log Memory Allocation Failed");
6537 /* Setup Mailbox command */
6538 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6541 "6190 RAS MBX Alloc Failed");
6546 ras_fwlog->fw_loglevel = fwlog_level;
6547 len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
6548 sizeof(struct lpfc_sli4_cfg_mhdr));
6550 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
6551 LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
6552 len, LPFC_SLI4_MBX_EMBED);
6554 mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
6555 bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
6557 bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
6558 ras_fwlog->fw_loglevel);
6559 bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
6560 ras_fwlog->fw_buffcount);
6561 bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
6562 LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
6564 /* Update DMA buffer address */
6565 list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
6566 memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
6568 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
6569 putPaddrLow(dmabuf->phys);
6571 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
6572 putPaddrHigh(dmabuf->phys);
6575 /* Update LPWD address */
6576 mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
6577 mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
6579 spin_lock_irq(&phba->hbalock);
6580 ras_fwlog->state = REG_INPROGRESS;
6581 spin_unlock_irq(&phba->hbalock);
6582 mbox->vport = phba->pport;
6583 mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
6585 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6587 if (rc == MBX_NOT_FINISHED) {
6588 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6589 "6191 FW-Log Mailbox failed. "
6590 "status %d mbxStatus : x%x", rc,
6591 bf_get(lpfc_mqe_status, &mbox->u.mqe));
6592 mempool_free(mbox, phba->mbox_mem_pool);
6599 lpfc_sli4_ras_dma_free(phba);
6605 * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
6606 * @phba: Pointer to HBA context object.
6608 * Check if RAS is supported on the adapter and initialize it.
6611 lpfc_sli4_ras_setup(struct lpfc_hba *phba)
6613 /* Check RAS FW Log needs to be enabled or not */
6614 if (lpfc_check_fwlog_support(phba))
6617 lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6618 LPFC_RAS_ENABLE_LOGGING);
6622 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
6623 * @phba: Pointer to HBA context object.
6625 * This function allocates all SLI4 resource identifiers.
6628 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
6630 int i, rc, error = 0;
6631 uint16_t count, base;
6632 unsigned long longs;
6634 if (!phba->sli4_hba.rpi_hdrs_in_use)
6635 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
6636 if (phba->sli4_hba.extents_in_use) {
6638 * The port supports resource extents. The XRI, VPI, VFI, RPI
6639 * resource extent count must be read and allocated before
6640 * provisioning the resource id arrays.
6642 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
6643 LPFC_IDX_RSRC_RDY) {
6645 * Extent-based resources are set - the driver could
6646 * be in a port reset. Figure out if any corrective
6647 * actions need to be taken.
6649 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6650 LPFC_RSC_TYPE_FCOE_VFI);
6653 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6654 LPFC_RSC_TYPE_FCOE_VPI);
6657 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6658 LPFC_RSC_TYPE_FCOE_XRI);
6661 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6662 LPFC_RSC_TYPE_FCOE_RPI);
6667 * It's possible that the number of resources
6668 * provided to this port instance changed between
6669 * resets. Detect this condition and reallocate
6670 * resources. Otherwise, there is no action.
6673 lpfc_printf_log(phba, KERN_INFO,
6674 LOG_MBOX | LOG_INIT,
6675 "2931 Detected extent resource "
6676 "change. Reallocating all "
6678 rc = lpfc_sli4_dealloc_extent(phba,
6679 LPFC_RSC_TYPE_FCOE_VFI);
6680 rc = lpfc_sli4_dealloc_extent(phba,
6681 LPFC_RSC_TYPE_FCOE_VPI);
6682 rc = lpfc_sli4_dealloc_extent(phba,
6683 LPFC_RSC_TYPE_FCOE_XRI);
6684 rc = lpfc_sli4_dealloc_extent(phba,
6685 LPFC_RSC_TYPE_FCOE_RPI);
6690 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
6694 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
6698 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
6702 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
6705 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6710 * The port does not support resource extents. The XRI, VPI,
6711 * VFI, RPI resource ids were determined from READ_CONFIG.
6712 * Just allocate the bitmasks and provision the resource id
6713 * arrays. If a port reset is active, the resources don't
6714 * need any action - just exit.
6716 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
6717 LPFC_IDX_RSRC_RDY) {
6718 lpfc_sli4_dealloc_resource_identifiers(phba);
6719 lpfc_sli4_remove_rpis(phba);
6722 count = phba->sli4_hba.max_cfg_param.max_rpi;
6724 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6725 "3279 Invalid provisioning of "
6730 base = phba->sli4_hba.max_cfg_param.rpi_base;
6731 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6732 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6733 sizeof(unsigned long),
6735 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6739 phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
6741 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6743 goto free_rpi_bmask;
6746 for (i = 0; i < count; i++)
6747 phba->sli4_hba.rpi_ids[i] = base + i;
6750 count = phba->sli4_hba.max_cfg_param.max_vpi;
6752 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6753 "3280 Invalid provisioning of "
6758 base = phba->sli4_hba.max_cfg_param.vpi_base;
6759 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6760 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6762 if (unlikely(!phba->vpi_bmask)) {
6766 phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
6768 if (unlikely(!phba->vpi_ids)) {
6770 goto free_vpi_bmask;
6773 for (i = 0; i < count; i++)
6774 phba->vpi_ids[i] = base + i;
6777 count = phba->sli4_hba.max_cfg_param.max_xri;
6779 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6780 "3281 Invalid provisioning of "
6785 base = phba->sli4_hba.max_cfg_param.xri_base;
6786 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6787 phba->sli4_hba.xri_bmask = kcalloc(longs,
6788 sizeof(unsigned long),
6790 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6794 phba->sli4_hba.max_cfg_param.xri_used = 0;
6795 phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
6797 if (unlikely(!phba->sli4_hba.xri_ids)) {
6799 goto free_xri_bmask;
6802 for (i = 0; i < count; i++)
6803 phba->sli4_hba.xri_ids[i] = base + i;
6806 count = phba->sli4_hba.max_cfg_param.max_vfi;
6808 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6809 "3282 Invalid provisioning of "
6814 base = phba->sli4_hba.max_cfg_param.vfi_base;
6815 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6816 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6817 sizeof(unsigned long),
6819 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6823 phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
6825 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6827 goto free_vfi_bmask;
6830 for (i = 0; i < count; i++)
6831 phba->sli4_hba.vfi_ids[i] = base + i;
6834 * Mark all resources ready. An HBA reset doesn't need
6835 * to reset the initialization.
6837 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6843 kfree(phba->sli4_hba.vfi_bmask);
6844 phba->sli4_hba.vfi_bmask = NULL;
6846 kfree(phba->sli4_hba.xri_ids);
6847 phba->sli4_hba.xri_ids = NULL;
6849 kfree(phba->sli4_hba.xri_bmask);
6850 phba->sli4_hba.xri_bmask = NULL;
6852 kfree(phba->vpi_ids);
6853 phba->vpi_ids = NULL;
6855 kfree(phba->vpi_bmask);
6856 phba->vpi_bmask = NULL;
6858 kfree(phba->sli4_hba.rpi_ids);
6859 phba->sli4_hba.rpi_ids = NULL;
6861 kfree(phba->sli4_hba.rpi_bmask);
6862 phba->sli4_hba.rpi_bmask = NULL;
6868 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6869 * @phba: Pointer to HBA context object.
6871 * This function allocates the number of elements for the specified
6875 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
6877 if (phba->sli4_hba.extents_in_use) {
6878 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
6879 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
6880 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
6881 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
6883 kfree(phba->vpi_bmask);
6884 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6885 kfree(phba->vpi_ids);
6886 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6887 kfree(phba->sli4_hba.xri_bmask);
6888 kfree(phba->sli4_hba.xri_ids);
6889 kfree(phba->sli4_hba.vfi_bmask);
6890 kfree(phba->sli4_hba.vfi_ids);
6891 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6892 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6899 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6900 * @phba: Pointer to HBA context object.
6901 * @type: The resource extent type.
6902 * @extnt_count: buffer to hold port extent count response
6903 * @extnt_size: buffer to hold port extent size response.
6905 * This function calls the port to read the host allocated extents
6906 * for a particular type.
6909 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
6910 uint16_t *extnt_cnt, uint16_t *extnt_size)
6914 uint16_t curr_blks = 0;
6915 uint32_t req_len, emb_len;
6916 uint32_t alloc_len, mbox_tmo;
6917 struct list_head *blk_list_head;
6918 struct lpfc_rsrc_blks *rsrc_blk;
6920 void *virtaddr = NULL;
6921 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
6922 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
6923 union lpfc_sli4_cfg_shdr *shdr;
6926 case LPFC_RSC_TYPE_FCOE_VPI:
6927 blk_list_head = &phba->lpfc_vpi_blk_list;
6929 case LPFC_RSC_TYPE_FCOE_XRI:
6930 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
6932 case LPFC_RSC_TYPE_FCOE_VFI:
6933 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
6935 case LPFC_RSC_TYPE_FCOE_RPI:
6936 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
6942 /* Count the number of extents currently allocatd for this type. */
6943 list_for_each_entry(rsrc_blk, blk_list_head, list) {
6944 if (curr_blks == 0) {
6946 * The GET_ALLOCATED mailbox does not return the size,
6947 * just the count. The size should be just the size
6948 * stored in the current allocated block and all sizes
6949 * for an extent type are the same so set the return
6952 *extnt_size = rsrc_blk->rsrc_size;
6958 * Calculate the size of an embedded mailbox. The uint32_t
6959 * accounts for extents-specific word.
6961 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
6965 * Presume the allocation and response will fit into an embedded
6966 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6968 emb = LPFC_SLI4_MBX_EMBED;
6970 if (req_len > emb_len) {
6971 req_len = curr_blks * sizeof(uint16_t) +
6972 sizeof(union lpfc_sli4_cfg_shdr) +
6974 emb = LPFC_SLI4_MBX_NEMBED;
6977 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6980 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
6982 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6983 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
6985 if (alloc_len < req_len) {
6986 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6987 "2983 Allocated DMA memory size (x%x) is "
6988 "less than the requested DMA memory "
6989 "size (x%x)\n", alloc_len, req_len);
6993 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
6999 if (!phba->sli4_hba.intr_enable)
7000 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
7002 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
7003 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
7012 * Figure out where the response is located. Then get local pointers
7013 * to the response data. The port does not guarantee to respond to
7014 * all extents counts request so update the local variable with the
7015 * allocated count from the port.
7017 if (emb == LPFC_SLI4_MBX_EMBED) {
7018 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
7019 shdr = &rsrc_ext->header.cfg_shdr;
7020 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
7022 virtaddr = mbox->sge_array->addr[0];
7023 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
7024 shdr = &n_rsrc->cfg_shdr;
7025 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
7028 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
7029 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
7030 "2984 Failed to read allocated resources "
7031 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
7033 bf_get(lpfc_mbox_hdr_status, &shdr->response),
7034 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
7039 lpfc_sli4_mbox_cmd_free(phba, mbox);
7044 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
7045 * @phba: pointer to lpfc hba data structure.
7046 * @pring: Pointer to driver SLI ring object.
7047 * @sgl_list: linked link of sgl buffers to post
7048 * @cnt: number of linked list buffers
7050 * This routine walks the list of buffers that have been allocated and
7051 * repost them to the port by using SGL block post. This is needed after a
7052 * pci_function_reset/warm_start or start. It attempts to construct blocks
7053 * of buffer sgls which contains contiguous xris and uses the non-embedded
7054 * SGL block post mailbox commands to post them to the port. For single
7055 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
7056 * mailbox command for posting.
7058 * Returns: 0 = success, non-zero failure.
7061 lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
7062 struct list_head *sgl_list, int cnt)
7064 struct lpfc_sglq *sglq_entry = NULL;
7065 struct lpfc_sglq *sglq_entry_next = NULL;
7066 struct lpfc_sglq *sglq_entry_first = NULL;
7067 int status, total_cnt;
7068 int post_cnt = 0, num_posted = 0, block_cnt = 0;
7069 int last_xritag = NO_XRI;
7070 LIST_HEAD(prep_sgl_list);
7071 LIST_HEAD(blck_sgl_list);
7072 LIST_HEAD(allc_sgl_list);
7073 LIST_HEAD(post_sgl_list);
7074 LIST_HEAD(free_sgl_list);
7076 spin_lock_irq(&phba->hbalock);
7077 spin_lock(&phba->sli4_hba.sgl_list_lock);
7078 list_splice_init(sgl_list, &allc_sgl_list);
7079 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7080 spin_unlock_irq(&phba->hbalock);
7083 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
7084 &allc_sgl_list, list) {
7085 list_del_init(&sglq_entry->list);
7087 if ((last_xritag != NO_XRI) &&
7088 (sglq_entry->sli4_xritag != last_xritag + 1)) {
7089 /* a hole in xri block, form a sgl posting block */
7090 list_splice_init(&prep_sgl_list, &blck_sgl_list);
7091 post_cnt = block_cnt - 1;
7092 /* prepare list for next posting block */
7093 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7096 /* prepare list for next posting block */
7097 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7098 /* enough sgls for non-embed sgl mbox command */
7099 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
7100 list_splice_init(&prep_sgl_list,
7102 post_cnt = block_cnt;
7108 /* keep track of last sgl's xritag */
7109 last_xritag = sglq_entry->sli4_xritag;
7111 /* end of repost sgl list condition for buffers */
7112 if (num_posted == total_cnt) {
7113 if (post_cnt == 0) {
7114 list_splice_init(&prep_sgl_list,
7116 post_cnt = block_cnt;
7117 } else if (block_cnt == 1) {
7118 status = lpfc_sli4_post_sgl(phba,
7119 sglq_entry->phys, 0,
7120 sglq_entry->sli4_xritag);
7122 /* successful, put sgl to posted list */
7123 list_add_tail(&sglq_entry->list,
7126 /* Failure, put sgl to free list */
7127 lpfc_printf_log(phba, KERN_WARNING,
7129 "3159 Failed to post "
7130 "sgl, xritag:x%x\n",
7131 sglq_entry->sli4_xritag);
7132 list_add_tail(&sglq_entry->list,
7139 /* continue until a nembed page worth of sgls */
7143 /* post the buffer list sgls as a block */
7144 status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
7148 /* success, put sgl list to posted sgl list */
7149 list_splice_init(&blck_sgl_list, &post_sgl_list);
7151 /* Failure, put sgl list to free sgl list */
7152 sglq_entry_first = list_first_entry(&blck_sgl_list,
7155 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7156 "3160 Failed to post sgl-list, "
7158 sglq_entry_first->sli4_xritag,
7159 (sglq_entry_first->sli4_xritag +
7161 list_splice_init(&blck_sgl_list, &free_sgl_list);
7162 total_cnt -= post_cnt;
7165 /* don't reset xirtag due to hole in xri block */
7167 last_xritag = NO_XRI;
7169 /* reset sgl post count for next round of posting */
7173 /* free the sgls failed to post */
7174 lpfc_free_sgl_list(phba, &free_sgl_list);
7176 /* push sgls posted to the available list */
7177 if (!list_empty(&post_sgl_list)) {
7178 spin_lock_irq(&phba->hbalock);
7179 spin_lock(&phba->sli4_hba.sgl_list_lock);
7180 list_splice_init(&post_sgl_list, sgl_list);
7181 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7182 spin_unlock_irq(&phba->hbalock);
7184 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7185 "3161 Failure to post sgl to port.\n");
7189 /* return the number of XRIs actually posted */
7194 * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
7195 * @phba: pointer to lpfc hba data structure.
7197 * This routine walks the list of nvme buffers that have been allocated and
7198 * repost them to the port by using SGL block post. This is needed after a
7199 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
7200 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
7201 * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
7203 * Returns: 0 = success, non-zero failure.
7206 lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
7208 LIST_HEAD(post_nblist);
7209 int num_posted, rc = 0;
7211 /* get all NVME buffers need to repost to a local list */
7212 lpfc_io_buf_flush(phba, &post_nblist);
7214 /* post the list of nvme buffer sgls to port if available */
7215 if (!list_empty(&post_nblist)) {
7216 num_posted = lpfc_sli4_post_io_sgl_list(
7217 phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
7218 /* failed to post any nvme buffer, return error */
7219 if (num_posted == 0)
7226 lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
7230 len = sizeof(struct lpfc_mbx_set_host_data) -
7231 sizeof(struct lpfc_sli4_cfg_mhdr);
7232 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7233 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
7234 LPFC_SLI4_MBX_EMBED);
7236 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
7237 mbox->u.mqe.un.set_host_data.param_len =
7238 LPFC_HOST_OS_DRIVER_VERSION_SIZE;
7239 snprintf(mbox->u.mqe.un.set_host_data.data,
7240 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
7241 "Linux %s v"LPFC_DRIVER_VERSION,
7242 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
7246 lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7247 struct lpfc_queue *drq, int count, int idx)
7250 struct lpfc_rqe hrqe;
7251 struct lpfc_rqe drqe;
7252 struct lpfc_rqb *rqbp;
7253 unsigned long flags;
7254 struct rqb_dmabuf *rqb_buffer;
7255 LIST_HEAD(rqb_buf_list);
7257 spin_lock_irqsave(&phba->hbalock, flags);
7259 for (i = 0; i < count; i++) {
7260 /* IF RQ is already full, don't bother */
7261 if (rqbp->buffer_count + i >= rqbp->entry_count - 1)
7263 rqb_buffer = rqbp->rqb_alloc_buffer(phba);
7266 rqb_buffer->hrq = hrq;
7267 rqb_buffer->drq = drq;
7268 rqb_buffer->idx = idx;
7269 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7271 while (!list_empty(&rqb_buf_list)) {
7272 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7275 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7276 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7277 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7278 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7279 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7282 "6421 Cannot post to HRQ %d: %x %x %x "
7290 rqbp->rqb_free_buffer(phba, rqb_buffer);
7292 list_add_tail(&rqb_buffer->hbuf.list,
7293 &rqbp->rqb_buffer_list);
7294 rqbp->buffer_count++;
7297 spin_unlock_irqrestore(&phba->hbalock, flags);
7302 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
7303 * @phba: Pointer to HBA context object.
7305 * This function is the main SLI4 device initialization PCI function. This
7306 * function is called by the HBA initialization code, HBA reset code and
7307 * HBA error attention handler code. Caller is not required to hold any
7311 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
7313 int rc, i, cnt, len, dd;
7314 LPFC_MBOXQ_t *mboxq;
7315 struct lpfc_mqe *mqe;
7318 uint32_t ftr_rsp = 0;
7319 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
7320 struct lpfc_vport *vport = phba->pport;
7321 struct lpfc_dmabuf *mp;
7322 struct lpfc_rqb *rqbp;
7324 /* Perform a PCI function reset to start from clean */
7325 rc = lpfc_pci_function_reset(phba);
7329 /* Check the HBA Host Status Register for readyness */
7330 rc = lpfc_sli4_post_status_check(phba);
7334 spin_lock_irq(&phba->hbalock);
7335 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
7336 spin_unlock_irq(&phba->hbalock);
7340 * Allocate a single mailbox container for initializing the
7343 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7347 /* Issue READ_REV to collect vpd and FW information. */
7348 vpd_size = SLI4_PAGE_SIZE;
7349 vpd = kzalloc(vpd_size, GFP_KERNEL);
7355 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
7361 mqe = &mboxq->u.mqe;
7362 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
7363 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
7364 phba->hba_flag |= HBA_FCOE_MODE;
7365 phba->fcp_embed_io = 0; /* SLI4 FC support only */
7367 phba->hba_flag &= ~HBA_FCOE_MODE;
7370 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
7372 phba->hba_flag |= HBA_FIP_SUPPORT;
7374 phba->hba_flag &= ~HBA_FIP_SUPPORT;
7376 phba->hba_flag &= ~HBA_IOQ_FLUSH;
7378 if (phba->sli_rev != LPFC_SLI_REV4) {
7379 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7380 "0376 READ_REV Error. SLI Level %d "
7381 "FCoE enabled %d\n",
7382 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
7389 * Continue initialization with default values even if driver failed
7390 * to read FCoE param config regions, only read parameters if the
7393 if (phba->hba_flag & HBA_FCOE_MODE &&
7394 lpfc_sli4_read_fcoe_params(phba))
7395 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
7396 "2570 Failed to read FCoE parameters\n");
7399 * Retrieve sli4 device physical port name, failure of doing it
7400 * is considered as non-fatal.
7402 rc = lpfc_sli4_retrieve_pport_name(phba);
7404 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7405 "3080 Successful retrieving SLI4 device "
7406 "physical port name: %s.\n", phba->Port);
7408 rc = lpfc_sli4_get_ctl_attr(phba);
7410 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7411 "8351 Successful retrieving SLI4 device "
7415 * Evaluate the read rev and vpd data. Populate the driver
7416 * state with the results. If this routine fails, the failure
7417 * is not fatal as the driver will use generic values.
7419 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
7420 if (unlikely(!rc)) {
7421 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7422 "0377 Error %d parsing vpd. "
7423 "Using defaults.\n", rc);
7428 /* Save information as VPD data */
7429 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
7430 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
7433 * This is because first G7 ASIC doesn't support the standard
7434 * 0x5a NVME cmd descriptor type/subtype
7436 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7437 LPFC_SLI_INTF_IF_TYPE_6) &&
7438 (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
7439 (phba->vpd.rev.smRev == 0) &&
7440 (phba->cfg_nvme_embed_cmd == 1))
7441 phba->cfg_nvme_embed_cmd = 0;
7443 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
7444 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
7446 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
7448 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
7450 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
7452 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
7453 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
7454 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
7455 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
7456 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
7457 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
7458 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7459 "(%d):0380 READ_REV Status x%x "
7460 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
7461 mboxq->vport ? mboxq->vport->vpi : 0,
7462 bf_get(lpfc_mqe_status, mqe),
7463 phba->vpd.rev.opFwName,
7464 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
7465 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
7467 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7468 LPFC_SLI_INTF_IF_TYPE_0) {
7469 lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
7470 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7471 if (rc == MBX_SUCCESS) {
7472 phba->hba_flag |= HBA_RECOVERABLE_UE;
7473 /* Set 1Sec interval to detect UE */
7474 phba->eratt_poll_interval = 1;
7475 phba->sli4_hba.ue_to_sr = bf_get(
7476 lpfc_mbx_set_feature_UESR,
7477 &mboxq->u.mqe.un.set_feature);
7478 phba->sli4_hba.ue_to_rp = bf_get(
7479 lpfc_mbx_set_feature_UERP,
7480 &mboxq->u.mqe.un.set_feature);
7484 if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
7485 /* Enable MDS Diagnostics only if the SLI Port supports it */
7486 lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
7487 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7488 if (rc != MBX_SUCCESS)
7489 phba->mds_diags_support = 0;
7493 * Discover the port's supported feature set and match it against the
7496 lpfc_request_features(phba, mboxq);
7497 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7504 * The port must support FCP initiator mode as this is the
7505 * only mode running in the host.
7507 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
7508 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7509 "0378 No support for fcpi mode.\n");
7513 /* Performance Hints are ONLY for FCoE */
7514 if (phba->hba_flag & HBA_FCOE_MODE) {
7515 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
7516 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
7518 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
7522 * If the port cannot support the host's requested features
7523 * then turn off the global config parameters to disable the
7524 * feature in the driver. This is not a fatal error.
7526 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
7527 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
7528 phba->cfg_enable_bg = 0;
7529 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
7534 if (phba->max_vpi && phba->cfg_enable_npiv &&
7535 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
7539 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7540 "0379 Feature Mismatch Data: x%08x %08x "
7541 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
7542 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
7543 phba->cfg_enable_npiv, phba->max_vpi);
7544 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
7545 phba->cfg_enable_bg = 0;
7546 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
7547 phba->cfg_enable_npiv = 0;
7550 /* These SLI3 features are assumed in SLI4 */
7551 spin_lock_irq(&phba->hbalock);
7552 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
7553 spin_unlock_irq(&phba->hbalock);
7555 /* Always try to enable dual dump feature if we can */
7556 lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP);
7557 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7558 dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature);
7559 if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP))
7560 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_INIT,
7561 "6448 Dual Dump is enabled\n");
7563 lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT,
7564 "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, "
7566 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7567 lpfc_sli_config_mbox_subsys_get(
7569 lpfc_sli_config_mbox_opcode_get(
7573 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
7574 * calls depends on these resources to complete port setup.
7576 rc = lpfc_sli4_alloc_resource_identifiers(phba);
7578 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7579 "2920 Failed to alloc Resource IDs "
7584 lpfc_set_host_data(phba, mboxq);
7586 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7588 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7589 "2134 Failed to set host os driver version %x",
7593 /* Read the port's service parameters. */
7594 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
7596 phba->link_state = LPFC_HBA_ERROR;
7601 mboxq->vport = vport;
7602 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7603 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
7604 if (rc == MBX_SUCCESS) {
7605 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
7610 * This memory was allocated by the lpfc_read_sparam routine. Release
7611 * it to the mbuf pool.
7613 lpfc_mbuf_free(phba, mp->virt, mp->phys);
7615 mboxq->ctx_buf = NULL;
7617 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7618 "0382 READ_SPARAM command failed "
7619 "status %d, mbxStatus x%x\n",
7620 rc, bf_get(lpfc_mqe_status, mqe));
7621 phba->link_state = LPFC_HBA_ERROR;
7626 lpfc_update_vport_wwn(vport);
7628 /* Update the fc_host data structures with new wwn. */
7629 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
7630 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
7632 /* Create all the SLI4 queues */
7633 rc = lpfc_sli4_queue_create(phba);
7635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7636 "3089 Failed to allocate queues\n");
7640 /* Set up all the queues to the device */
7641 rc = lpfc_sli4_queue_setup(phba);
7643 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7644 "0381 Error %d during queue setup.\n ", rc);
7645 goto out_stop_timers;
7647 /* Initialize the driver internal SLI layer lists. */
7648 lpfc_sli4_setup(phba);
7649 lpfc_sli4_queue_init(phba);
7651 /* update host els xri-sgl sizes and mappings */
7652 rc = lpfc_sli4_els_sgl_update(phba);
7654 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7655 "1400 Failed to update xri-sgl size and "
7656 "mapping: %d\n", rc);
7657 goto out_destroy_queue;
7660 /* register the els sgl pool to the port */
7661 rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
7662 phba->sli4_hba.els_xri_cnt);
7663 if (unlikely(rc < 0)) {
7664 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7665 "0582 Error %d during els sgl post "
7668 goto out_destroy_queue;
7670 phba->sli4_hba.els_xri_cnt = rc;
7672 if (phba->nvmet_support) {
7673 /* update host nvmet xri-sgl sizes and mappings */
7674 rc = lpfc_sli4_nvmet_sgl_update(phba);
7676 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7677 "6308 Failed to update nvmet-sgl size "
7678 "and mapping: %d\n", rc);
7679 goto out_destroy_queue;
7682 /* register the nvmet sgl pool to the port */
7683 rc = lpfc_sli4_repost_sgl_list(
7685 &phba->sli4_hba.lpfc_nvmet_sgl_list,
7686 phba->sli4_hba.nvmet_xri_cnt);
7687 if (unlikely(rc < 0)) {
7688 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7689 "3117 Error %d during nvmet "
7692 goto out_destroy_queue;
7694 phba->sli4_hba.nvmet_xri_cnt = rc;
7696 /* We allocate an iocbq for every receive context SGL.
7697 * The additional allocation is for abort and ls handling.
7699 cnt = phba->sli4_hba.nvmet_xri_cnt +
7700 phba->sli4_hba.max_cfg_param.max_xri;
7702 /* update host common xri-sgl sizes and mappings */
7703 rc = lpfc_sli4_io_sgl_update(phba);
7705 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7706 "6082 Failed to update nvme-sgl size "
7707 "and mapping: %d\n", rc);
7708 goto out_destroy_queue;
7711 /* register the allocated common sgl pool to the port */
7712 rc = lpfc_sli4_repost_io_sgl_list(phba);
7714 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7715 "6116 Error %d during nvme sgl post "
7717 /* Some NVME buffers were moved to abort nvme list */
7718 /* A pci function reset will repost them */
7720 goto out_destroy_queue;
7722 /* Each lpfc_io_buf job structure has an iocbq element.
7723 * This cnt provides for abort, els, ct and ls requests.
7725 cnt = phba->sli4_hba.max_cfg_param.max_xri;
7728 if (!phba->sli.iocbq_lookup) {
7729 /* Initialize and populate the iocb list per host */
7730 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7731 "2821 initialize iocb list with %d entries\n",
7733 rc = lpfc_init_iocb_list(phba, cnt);
7735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7736 "1413 Failed to init iocb list.\n");
7737 goto out_destroy_queue;
7741 if (phba->nvmet_support)
7742 lpfc_nvmet_create_targetport(phba);
7744 if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
7745 /* Post initial buffers to all RQs created */
7746 for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
7747 rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
7748 INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
7749 rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
7750 rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
7751 rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
7752 rqbp->buffer_count = 0;
7754 lpfc_post_rq_buffer(
7755 phba, phba->sli4_hba.nvmet_mrq_hdr[i],
7756 phba->sli4_hba.nvmet_mrq_data[i],
7757 phba->cfg_nvmet_mrq_post, i);
7761 /* Post the rpi header region to the device. */
7762 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
7764 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
7765 "0393 Error %d during rpi post operation\n",
7768 goto out_destroy_queue;
7770 lpfc_sli4_node_prep(phba);
7772 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
7773 if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
7775 * The FC Port needs to register FCFI (index 0)
7777 lpfc_reg_fcfi(phba, mboxq);
7778 mboxq->vport = phba->pport;
7779 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7780 if (rc != MBX_SUCCESS)
7781 goto out_unset_queue;
7783 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
7784 &mboxq->u.mqe.un.reg_fcfi);
7786 /* We are a NVME Target mode with MRQ > 1 */
7788 /* First register the FCFI */
7789 lpfc_reg_fcfi_mrq(phba, mboxq, 0);
7790 mboxq->vport = phba->pport;
7791 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7792 if (rc != MBX_SUCCESS)
7793 goto out_unset_queue;
7795 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
7796 &mboxq->u.mqe.un.reg_fcfi_mrq);
7798 /* Next register the MRQs */
7799 lpfc_reg_fcfi_mrq(phba, mboxq, 1);
7800 mboxq->vport = phba->pport;
7801 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7802 if (rc != MBX_SUCCESS)
7803 goto out_unset_queue;
7806 /* Check if the port is configured to be disabled */
7807 lpfc_sli_read_link_ste(phba);
7810 /* Don't post more new bufs if repost already recovered
7813 if (phba->nvmet_support == 0) {
7814 if (phba->sli4_hba.io_xri_cnt == 0) {
7815 len = lpfc_new_io_buf(
7816 phba, phba->sli4_hba.io_xri_max);
7819 goto out_unset_queue;
7822 if (phba->cfg_xri_rebalancing)
7823 lpfc_create_multixri_pools(phba);
7826 phba->cfg_xri_rebalancing = 0;
7829 /* Allow asynchronous mailbox command to go through */
7830 spin_lock_irq(&phba->hbalock);
7831 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
7832 spin_unlock_irq(&phba->hbalock);
7834 /* Post receive buffers to the device */
7835 lpfc_sli4_rb_setup(phba);
7837 /* Reset HBA FCF states after HBA reset */
7838 phba->fcf.fcf_flag = 0;
7839 phba->fcf.current_rec.flag = 0;
7841 /* Start the ELS watchdog timer */
7842 mod_timer(&vport->els_tmofunc,
7843 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
7845 /* Start heart beat timer */
7846 mod_timer(&phba->hb_tmofunc,
7847 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
7848 phba->hb_outstanding = 0;
7849 phba->last_completion_time = jiffies;
7851 /* start eq_delay heartbeat */
7852 if (phba->cfg_auto_imax)
7853 queue_delayed_work(phba->wq, &phba->eq_delay_work,
7854 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
7856 /* Start error attention (ERATT) polling timer */
7857 mod_timer(&phba->eratt_poll,
7858 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
7860 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
7861 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
7862 rc = pci_enable_pcie_error_reporting(phba->pcidev);
7864 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7865 "2829 This device supports "
7866 "Advanced Error Reporting (AER)\n");
7867 spin_lock_irq(&phba->hbalock);
7868 phba->hba_flag |= HBA_AER_ENABLED;
7869 spin_unlock_irq(&phba->hbalock);
7871 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7872 "2830 This device does not support "
7873 "Advanced Error Reporting (AER)\n");
7874 phba->cfg_aer_support = 0;
7880 * The port is ready, set the host's link state to LINK_DOWN
7881 * in preparation for link interrupts.
7883 spin_lock_irq(&phba->hbalock);
7884 phba->link_state = LPFC_LINK_DOWN;
7886 /* Check if physical ports are trunked */
7887 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
7888 phba->trunk_link.link0.state = LPFC_LINK_DOWN;
7889 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
7890 phba->trunk_link.link1.state = LPFC_LINK_DOWN;
7891 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
7892 phba->trunk_link.link2.state = LPFC_LINK_DOWN;
7893 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
7894 phba->trunk_link.link3.state = LPFC_LINK_DOWN;
7895 spin_unlock_irq(&phba->hbalock);
7897 /* Arm the CQs and then EQs on device */
7898 lpfc_sli4_arm_cqeq_intr(phba);
7900 /* Indicate device interrupt mode */
7901 phba->sli4_hba.intr_enable = 1;
7903 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
7904 (phba->hba_flag & LINK_DISABLED)) {
7905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
7906 "3103 Adapter Link is disabled.\n");
7907 lpfc_down_link(phba, mboxq);
7908 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7909 if (rc != MBX_SUCCESS) {
7910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI,
7911 "3104 Adapter failed to issue "
7912 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
7913 goto out_io_buff_free;
7915 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
7916 /* don't perform init_link on SLI4 FC port loopback test */
7917 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
7918 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
7920 goto out_io_buff_free;
7923 mempool_free(mboxq, phba->mbox_mem_pool);
7926 /* Free allocated IO Buffers */
7929 /* Unset all the queues set up in this routine when error out */
7930 lpfc_sli4_queue_unset(phba);
7932 lpfc_free_iocb_list(phba);
7933 lpfc_sli4_queue_destroy(phba);
7935 lpfc_stop_hba_timers(phba);
7937 mempool_free(mboxq, phba->mbox_mem_pool);
7942 * lpfc_mbox_timeout - Timeout call back function for mbox timer
7943 * @ptr: context object - pointer to hba structure.
7945 * This is the callback function for mailbox timer. The mailbox
7946 * timer is armed when a new mailbox command is issued and the timer
7947 * is deleted when the mailbox complete. The function is called by
7948 * the kernel timer code when a mailbox does not complete within
7949 * expected time. This function wakes up the worker thread to
7950 * process the mailbox timeout and returns. All the processing is
7951 * done by the worker thread function lpfc_mbox_timeout_handler.
7954 lpfc_mbox_timeout(struct timer_list *t)
7956 struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo);
7957 unsigned long iflag;
7958 uint32_t tmo_posted;
7960 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
7961 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
7963 phba->pport->work_port_events |= WORKER_MBOX_TMO;
7964 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
7967 lpfc_worker_wake_up(phba);
7972 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
7974 * @phba: Pointer to HBA context object.
7976 * This function checks if any mailbox completions are present on the mailbox
7980 lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
7984 struct lpfc_queue *mcq;
7985 struct lpfc_mcqe *mcqe;
7986 bool pending_completions = false;
7989 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
7992 /* Check for completions on mailbox completion queue */
7994 mcq = phba->sli4_hba.mbx_cq;
7995 idx = mcq->hba_index;
7996 qe_valid = mcq->qe_valid;
7997 while (bf_get_le32(lpfc_cqe_valid,
7998 (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
7999 mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
8000 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
8001 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
8002 pending_completions = true;
8005 idx = (idx + 1) % mcq->entry_count;
8006 if (mcq->hba_index == idx)
8009 /* if the index wrapped around, toggle the valid bit */
8010 if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
8011 qe_valid = (qe_valid) ? 0 : 1;
8013 return pending_completions;
8018 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
8020 * @phba: Pointer to HBA context object.
8022 * For sli4, it is possible to miss an interrupt. As such mbox completions
8023 * maybe missed causing erroneous mailbox timeouts to occur. This function
8024 * checks to see if mbox completions are on the mailbox completion queue
8025 * and will process all the completions associated with the eq for the
8026 * mailbox completion queue.
8029 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
8031 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
8033 struct lpfc_queue *fpeq = NULL;
8034 struct lpfc_queue *eq;
8037 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
8040 /* Find the EQ associated with the mbox CQ */
8041 if (sli4_hba->hdwq) {
8042 for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
8043 eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
8044 if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
8053 /* Turn off interrupts from this EQ */
8055 sli4_hba->sli4_eq_clr_intr(fpeq);
8057 /* Check to see if a mbox completion is pending */
8059 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
8062 * If a mbox completion is pending, process all the events on EQ
8063 * associated with the mbox completion queue (this could include
8064 * mailbox commands, async events, els commands, receive queue data
8069 /* process and rearm the EQ */
8070 lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
8072 /* Always clear and re-arm the EQ */
8073 sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
8075 return mbox_pending;
8080 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
8081 * @phba: Pointer to HBA context object.
8083 * This function is called from worker thread when a mailbox command times out.
8084 * The caller is not required to hold any locks. This function will reset the
8085 * HBA and recover all the pending commands.
8088 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
8090 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
8091 MAILBOX_t *mb = NULL;
8093 struct lpfc_sli *psli = &phba->sli;
8095 /* If the mailbox completed, process the completion and return */
8096 if (lpfc_sli4_process_missed_mbox_completions(phba))
8101 /* Check the pmbox pointer first. There is a race condition
8102 * between the mbox timeout handler getting executed in the
8103 * worklist and the mailbox actually completing. When this
8104 * race condition occurs, the mbox_active will be NULL.
8106 spin_lock_irq(&phba->hbalock);
8107 if (pmbox == NULL) {
8108 lpfc_printf_log(phba, KERN_WARNING,
8110 "0353 Active Mailbox cleared - mailbox timeout "
8112 spin_unlock_irq(&phba->hbalock);
8116 /* Mbox cmd <mbxCommand> timeout */
8117 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8118 "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
8120 phba->pport->port_state,
8122 phba->sli.mbox_active);
8123 spin_unlock_irq(&phba->hbalock);
8125 /* Setting state unknown so lpfc_sli_abort_iocb_ring
8126 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
8127 * it to fail all outstanding SCSI IO.
8129 spin_lock_irq(&phba->pport->work_port_lock);
8130 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
8131 spin_unlock_irq(&phba->pport->work_port_lock);
8132 spin_lock_irq(&phba->hbalock);
8133 phba->link_state = LPFC_LINK_UNKNOWN;
8134 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
8135 spin_unlock_irq(&phba->hbalock);
8137 lpfc_sli_abort_fcp_rings(phba);
8139 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8140 "0345 Resetting board due to mailbox timeout\n");
8142 /* Reset the HBA device */
8143 lpfc_reset_hba(phba);
8147 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
8148 * @phba: Pointer to HBA context object.
8149 * @pmbox: Pointer to mailbox object.
8150 * @flag: Flag indicating how the mailbox need to be processed.
8152 * This function is called by discovery code and HBA management code
8153 * to submit a mailbox command to firmware with SLI-3 interface spec. This
8154 * function gets the hbalock to protect the data structures.
8155 * The mailbox command can be submitted in polling mode, in which case
8156 * this function will wait in a polling loop for the completion of the
8158 * If the mailbox is submitted in no_wait mode (not polling) the
8159 * function will submit the command and returns immediately without waiting
8160 * for the mailbox completion. The no_wait is supported only when HBA
8161 * is in SLI2/SLI3 mode - interrupts are enabled.
8162 * The SLI interface allows only one mailbox pending at a time. If the
8163 * mailbox is issued in polling mode and there is already a mailbox
8164 * pending, then the function will return an error. If the mailbox is issued
8165 * in NO_WAIT mode and there is a mailbox pending already, the function
8166 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
8167 * The sli layer owns the mailbox object until the completion of mailbox
8168 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
8169 * return codes the caller owns the mailbox command after the return of
8173 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
8177 struct lpfc_sli *psli = &phba->sli;
8178 uint32_t status, evtctr;
8179 uint32_t ha_copy, hc_copy;
8181 unsigned long timeout;
8182 unsigned long drvr_flag = 0;
8183 uint32_t word0, ldata;
8184 void __iomem *to_slim;
8185 int processing_queue = 0;
8187 spin_lock_irqsave(&phba->hbalock, drvr_flag);
8189 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8190 /* processing mbox queue from intr_handler */
8191 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8192 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8195 processing_queue = 1;
8196 pmbox = lpfc_mbox_get(phba);
8198 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8203 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
8204 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
8206 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8207 lpfc_printf_log(phba, KERN_ERR,
8208 LOG_MBOX | LOG_VPORT,
8209 "1806 Mbox x%x failed. No vport\n",
8210 pmbox->u.mb.mbxCommand);
8212 goto out_not_finished;
8216 /* If the PCI channel is in offline state, do not post mbox. */
8217 if (unlikely(pci_channel_offline(phba->pcidev))) {
8218 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8219 goto out_not_finished;
8222 /* If HBA has a deferred error attention, fail the iocb. */
8223 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8224 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8225 goto out_not_finished;
8231 status = MBX_SUCCESS;
8233 if (phba->link_state == LPFC_HBA_ERROR) {
8234 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8236 /* Mbox command <mbxCommand> cannot issue */
8237 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8238 "(%d):0311 Mailbox command x%x cannot "
8239 "issue Data: x%x x%x\n",
8240 pmbox->vport ? pmbox->vport->vpi : 0,
8241 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
8242 goto out_not_finished;
8245 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
8246 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
8247 !(hc_copy & HC_MBINT_ENA)) {
8248 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8249 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8250 "(%d):2528 Mailbox command x%x cannot "
8251 "issue Data: x%x x%x\n",
8252 pmbox->vport ? pmbox->vport->vpi : 0,
8253 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
8254 goto out_not_finished;
8258 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8259 /* Polling for a mbox command when another one is already active
8260 * is not allowed in SLI. Also, the driver must have established
8261 * SLI2 mode to queue and process multiple mbox commands.
8264 if (flag & MBX_POLL) {
8265 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8267 /* Mbox command <mbxCommand> cannot issue */
8268 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8269 "(%d):2529 Mailbox command x%x "
8270 "cannot issue Data: x%x x%x\n",
8271 pmbox->vport ? pmbox->vport->vpi : 0,
8272 pmbox->u.mb.mbxCommand,
8273 psli->sli_flag, flag);
8274 goto out_not_finished;
8277 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
8278 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8279 /* Mbox command <mbxCommand> cannot issue */
8280 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8281 "(%d):2530 Mailbox command x%x "
8282 "cannot issue Data: x%x x%x\n",
8283 pmbox->vport ? pmbox->vport->vpi : 0,
8284 pmbox->u.mb.mbxCommand,
8285 psli->sli_flag, flag);
8286 goto out_not_finished;
8289 /* Another mailbox command is still being processed, queue this
8290 * command to be processed later.
8292 lpfc_mbox_put(phba, pmbox);
8294 /* Mbox cmd issue - BUSY */
8295 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8296 "(%d):0308 Mbox cmd issue - BUSY Data: "
8297 "x%x x%x x%x x%x\n",
8298 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
8300 phba->pport ? phba->pport->port_state : 0xff,
8301 psli->sli_flag, flag);
8303 psli->slistat.mbox_busy++;
8304 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8307 lpfc_debugfs_disc_trc(pmbox->vport,
8308 LPFC_DISC_TRC_MBOX_VPORT,
8309 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
8310 (uint32_t)mbx->mbxCommand,
8311 mbx->un.varWords[0], mbx->un.varWords[1]);
8314 lpfc_debugfs_disc_trc(phba->pport,
8316 "MBOX Bsy: cmd:x%x mb:x%x x%x",
8317 (uint32_t)mbx->mbxCommand,
8318 mbx->un.varWords[0], mbx->un.varWords[1]);
8324 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8326 /* If we are not polling, we MUST be in SLI2 mode */
8327 if (flag != MBX_POLL) {
8328 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
8329 (mbx->mbxCommand != MBX_KILL_BOARD)) {
8330 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8331 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8332 /* Mbox command <mbxCommand> cannot issue */
8333 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8334 "(%d):2531 Mailbox command x%x "
8335 "cannot issue Data: x%x x%x\n",
8336 pmbox->vport ? pmbox->vport->vpi : 0,
8337 pmbox->u.mb.mbxCommand,
8338 psli->sli_flag, flag);
8339 goto out_not_finished;
8341 /* timeout active mbox command */
8342 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
8344 mod_timer(&psli->mbox_tmo, jiffies + timeout);
8347 /* Mailbox cmd <cmd> issue */
8348 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8349 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
8351 pmbox->vport ? pmbox->vport->vpi : 0,
8353 phba->pport ? phba->pport->port_state : 0xff,
8354 psli->sli_flag, flag);
8356 if (mbx->mbxCommand != MBX_HEARTBEAT) {
8358 lpfc_debugfs_disc_trc(pmbox->vport,
8359 LPFC_DISC_TRC_MBOX_VPORT,
8360 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8361 (uint32_t)mbx->mbxCommand,
8362 mbx->un.varWords[0], mbx->un.varWords[1]);
8365 lpfc_debugfs_disc_trc(phba->pport,
8367 "MBOX Send: cmd:x%x mb:x%x x%x",
8368 (uint32_t)mbx->mbxCommand,
8369 mbx->un.varWords[0], mbx->un.varWords[1]);
8373 psli->slistat.mbox_cmd++;
8374 evtctr = psli->slistat.mbox_event;
8376 /* next set own bit for the adapter and copy over command word */
8377 mbx->mbxOwner = OWN_CHIP;
8379 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8380 /* Populate mbox extension offset word. */
8381 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
8382 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
8383 = (uint8_t *)phba->mbox_ext
8384 - (uint8_t *)phba->mbox;
8387 /* Copy the mailbox extension data */
8388 if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
8389 lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
8390 (uint8_t *)phba->mbox_ext,
8391 pmbox->in_ext_byte_len);
8393 /* Copy command data to host SLIM area */
8394 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
8396 /* Populate mbox extension offset word. */
8397 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
8398 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
8399 = MAILBOX_HBA_EXT_OFFSET;
8401 /* Copy the mailbox extension data */
8402 if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
8403 lpfc_memcpy_to_slim(phba->MBslimaddr +
8404 MAILBOX_HBA_EXT_OFFSET,
8405 pmbox->ctx_buf, pmbox->in_ext_byte_len);
8407 if (mbx->mbxCommand == MBX_CONFIG_PORT)
8408 /* copy command data into host mbox for cmpl */
8409 lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
8412 /* First copy mbox command data to HBA SLIM, skip past first
8414 to_slim = phba->MBslimaddr + sizeof (uint32_t);
8415 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
8416 MAILBOX_CMD_SIZE - sizeof (uint32_t));
8418 /* Next copy over first word, with mbxOwner set */
8419 ldata = *((uint32_t *)mbx);
8420 to_slim = phba->MBslimaddr;
8421 writel(ldata, to_slim);
8422 readl(to_slim); /* flush */
8424 if (mbx->mbxCommand == MBX_CONFIG_PORT)
8425 /* switch over to host mailbox */
8426 psli->sli_flag |= LPFC_SLI_ACTIVE;
8433 /* Set up reference to mailbox command */
8434 psli->mbox_active = pmbox;
8435 /* Interrupt board to do it */
8436 writel(CA_MBATT, phba->CAregaddr);
8437 readl(phba->CAregaddr); /* flush */
8438 /* Don't wait for it to finish, just return */
8442 /* Set up null reference to mailbox command */
8443 psli->mbox_active = NULL;
8444 /* Interrupt board to do it */
8445 writel(CA_MBATT, phba->CAregaddr);
8446 readl(phba->CAregaddr); /* flush */
8448 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8449 /* First read mbox status word */
8450 word0 = *((uint32_t *)phba->mbox);
8451 word0 = le32_to_cpu(word0);
8453 /* First read mbox status word */
8454 if (lpfc_readl(phba->MBslimaddr, &word0)) {
8455 spin_unlock_irqrestore(&phba->hbalock,
8457 goto out_not_finished;
8461 /* Read the HBA Host Attention Register */
8462 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
8463 spin_unlock_irqrestore(&phba->hbalock,
8465 goto out_not_finished;
8467 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
8470 /* Wait for command to complete */
8471 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
8472 (!(ha_copy & HA_MBATT) &&
8473 (phba->link_state > LPFC_WARM_START))) {
8474 if (time_after(jiffies, timeout)) {
8475 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8476 spin_unlock_irqrestore(&phba->hbalock,
8478 goto out_not_finished;
8481 /* Check if we took a mbox interrupt while we were
8483 if (((word0 & OWN_CHIP) != OWN_CHIP)
8484 && (evtctr != psli->slistat.mbox_event))
8488 spin_unlock_irqrestore(&phba->hbalock,
8491 spin_lock_irqsave(&phba->hbalock, drvr_flag);
8494 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8495 /* First copy command data */
8496 word0 = *((uint32_t *)phba->mbox);
8497 word0 = le32_to_cpu(word0);
8498 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
8501 /* Check real SLIM for any errors */
8502 slimword0 = readl(phba->MBslimaddr);
8503 slimmb = (MAILBOX_t *) & slimword0;
8504 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
8505 && slimmb->mbxStatus) {
8512 /* First copy command data */
8513 word0 = readl(phba->MBslimaddr);
8515 /* Read the HBA Host Attention Register */
8516 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
8517 spin_unlock_irqrestore(&phba->hbalock,
8519 goto out_not_finished;
8523 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8524 /* copy results back to user */
8525 lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
8527 /* Copy the mailbox extension data */
8528 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
8529 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
8531 pmbox->out_ext_byte_len);
8534 /* First copy command data */
8535 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
8537 /* Copy the mailbox extension data */
8538 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
8539 lpfc_memcpy_from_slim(
8542 MAILBOX_HBA_EXT_OFFSET,
8543 pmbox->out_ext_byte_len);
8547 writel(HA_MBATT, phba->HAregaddr);
8548 readl(phba->HAregaddr); /* flush */
8550 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8551 status = mbx->mbxStatus;
8554 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8558 if (processing_queue) {
8559 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
8560 lpfc_mbox_cmpl_put(phba, pmbox);
8562 return MBX_NOT_FINISHED;
8566 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
8567 * @phba: Pointer to HBA context object.
8569 * The function blocks the posting of SLI4 asynchronous mailbox commands from
8570 * the driver internal pending mailbox queue. It will then try to wait out the
8571 * possible outstanding mailbox command before return.
8574 * 0 - the outstanding mailbox command completed; otherwise, the wait for
8575 * the outstanding mailbox command timed out.
8578 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
8580 struct lpfc_sli *psli = &phba->sli;
8582 unsigned long timeout = 0;
8584 /* Mark the asynchronous mailbox command posting as blocked */
8585 spin_lock_irq(&phba->hbalock);
8586 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8587 /* Determine how long we might wait for the active mailbox
8588 * command to be gracefully completed by firmware.
8590 if (phba->sli.mbox_active)
8591 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
8592 phba->sli.mbox_active) *
8594 spin_unlock_irq(&phba->hbalock);
8596 /* Make sure the mailbox is really active */
8598 lpfc_sli4_process_missed_mbox_completions(phba);
8600 /* Wait for the outstnading mailbox command to complete */
8601 while (phba->sli.mbox_active) {
8602 /* Check active mailbox complete status every 2ms */
8604 if (time_after(jiffies, timeout)) {
8605 /* Timeout, marked the outstanding cmd not complete */
8611 /* Can not cleanly block async mailbox command, fails it */
8613 spin_lock_irq(&phba->hbalock);
8614 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8615 spin_unlock_irq(&phba->hbalock);
8621 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
8622 * @phba: Pointer to HBA context object.
8624 * The function unblocks and resume posting of SLI4 asynchronous mailbox
8625 * commands from the driver internal pending mailbox queue. It makes sure
8626 * that there is no outstanding mailbox command before resuming posting
8627 * asynchronous mailbox commands. If, for any reason, there is outstanding
8628 * mailbox command, it will try to wait it out before resuming asynchronous
8629 * mailbox command posting.
8632 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
8634 struct lpfc_sli *psli = &phba->sli;
8636 spin_lock_irq(&phba->hbalock);
8637 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8638 /* Asynchronous mailbox posting is not blocked, do nothing */
8639 spin_unlock_irq(&phba->hbalock);
8643 /* Outstanding synchronous mailbox command is guaranteed to be done,
8644 * successful or timeout, after timing-out the outstanding mailbox
8645 * command shall always be removed, so just unblock posting async
8646 * mailbox command and resume
8648 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8649 spin_unlock_irq(&phba->hbalock);
8651 /* wake up worker thread to post asynchronous mailbox command */
8652 lpfc_worker_wake_up(phba);
8656 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
8657 * @phba: Pointer to HBA context object.
8658 * @mboxq: Pointer to mailbox object.
8660 * The function waits for the bootstrap mailbox register ready bit from
8661 * port for twice the regular mailbox command timeout value.
8663 * 0 - no timeout on waiting for bootstrap mailbox register ready.
8664 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
8667 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8670 unsigned long timeout;
8671 struct lpfc_register bmbx_reg;
8673 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
8677 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
8678 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
8682 if (time_after(jiffies, timeout))
8683 return MBXERR_ERROR;
8684 } while (!db_ready);
8690 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
8691 * @phba: Pointer to HBA context object.
8692 * @mboxq: Pointer to mailbox object.
8694 * The function posts a mailbox to the port. The mailbox is expected
8695 * to be comletely filled in and ready for the port to operate on it.
8696 * This routine executes a synchronous completion operation on the
8697 * mailbox by polling for its completion.
8699 * The caller must not be holding any locks when calling this routine.
8702 * MBX_SUCCESS - mailbox posted successfully
8703 * Any of the MBX error values.
8706 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8708 int rc = MBX_SUCCESS;
8709 unsigned long iflag;
8710 uint32_t mcqe_status;
8712 struct lpfc_sli *psli = &phba->sli;
8713 struct lpfc_mqe *mb = &mboxq->u.mqe;
8714 struct lpfc_bmbx_create *mbox_rgn;
8715 struct dma_address *dma_address;
8718 * Only one mailbox can be active to the bootstrap mailbox region
8719 * at a time and there is no queueing provided.
8721 spin_lock_irqsave(&phba->hbalock, iflag);
8722 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8723 spin_unlock_irqrestore(&phba->hbalock, iflag);
8724 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8725 "(%d):2532 Mailbox command x%x (x%x/x%x) "
8726 "cannot issue Data: x%x x%x\n",
8727 mboxq->vport ? mboxq->vport->vpi : 0,
8728 mboxq->u.mb.mbxCommand,
8729 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8730 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8731 psli->sli_flag, MBX_POLL);
8732 return MBXERR_ERROR;
8734 /* The server grabs the token and owns it until release */
8735 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8736 phba->sli.mbox_active = mboxq;
8737 spin_unlock_irqrestore(&phba->hbalock, iflag);
8739 /* wait for bootstrap mbox register for readyness */
8740 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8744 * Initialize the bootstrap memory region to avoid stale data areas
8745 * in the mailbox post. Then copy the caller's mailbox contents to
8746 * the bmbx mailbox region.
8748 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
8749 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
8750 lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
8751 sizeof(struct lpfc_mqe));
8753 /* Post the high mailbox dma address to the port and wait for ready. */
8754 dma_address = &phba->sli4_hba.bmbx.dma_address;
8755 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
8757 /* wait for bootstrap mbox register for hi-address write done */
8758 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8762 /* Post the low mailbox dma address to the port. */
8763 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
8765 /* wait for bootstrap mbox register for low address write done */
8766 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8771 * Read the CQ to ensure the mailbox has completed.
8772 * If so, update the mailbox status so that the upper layers
8773 * can complete the request normally.
8775 lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
8776 sizeof(struct lpfc_mqe));
8777 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
8778 lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
8779 sizeof(struct lpfc_mcqe));
8780 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
8782 * When the CQE status indicates a failure and the mailbox status
8783 * indicates success then copy the CQE status into the mailbox status
8784 * (and prefix it with x4000).
8786 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
8787 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
8788 bf_set(lpfc_mqe_status, mb,
8789 (LPFC_MBX_ERROR_RANGE | mcqe_status));
8792 lpfc_sli4_swap_str(phba, mboxq);
8794 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8795 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
8796 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
8797 " x%x x%x CQ: x%x x%x x%x x%x\n",
8798 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
8799 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8800 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8801 bf_get(lpfc_mqe_status, mb),
8802 mb->un.mb_words[0], mb->un.mb_words[1],
8803 mb->un.mb_words[2], mb->un.mb_words[3],
8804 mb->un.mb_words[4], mb->un.mb_words[5],
8805 mb->un.mb_words[6], mb->un.mb_words[7],
8806 mb->un.mb_words[8], mb->un.mb_words[9],
8807 mb->un.mb_words[10], mb->un.mb_words[11],
8808 mb->un.mb_words[12], mboxq->mcqe.word0,
8809 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
8810 mboxq->mcqe.trailer);
8812 /* We are holding the token, no needed for lock when release */
8813 spin_lock_irqsave(&phba->hbalock, iflag);
8814 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8815 phba->sli.mbox_active = NULL;
8816 spin_unlock_irqrestore(&phba->hbalock, iflag);
8821 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
8822 * @phba: Pointer to HBA context object.
8823 * @pmbox: Pointer to mailbox object.
8824 * @flag: Flag indicating how the mailbox need to be processed.
8826 * This function is called by discovery code and HBA management code to submit
8827 * a mailbox command to firmware with SLI-4 interface spec.
8829 * Return codes the caller owns the mailbox command after the return of the
8833 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
8836 struct lpfc_sli *psli = &phba->sli;
8837 unsigned long iflags;
8840 /* dump from issue mailbox command if setup */
8841 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
8843 rc = lpfc_mbox_dev_check(phba);
8845 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8846 "(%d):2544 Mailbox command x%x (x%x/x%x) "
8847 "cannot issue Data: x%x x%x\n",
8848 mboxq->vport ? mboxq->vport->vpi : 0,
8849 mboxq->u.mb.mbxCommand,
8850 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8851 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8852 psli->sli_flag, flag);
8853 goto out_not_finished;
8856 /* Detect polling mode and jump to a handler */
8857 if (!phba->sli4_hba.intr_enable) {
8858 if (flag == MBX_POLL)
8859 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
8862 if (rc != MBX_SUCCESS)
8863 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8864 "(%d):2541 Mailbox command x%x "
8865 "(x%x/x%x) failure: "
8866 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8868 mboxq->vport ? mboxq->vport->vpi : 0,
8869 mboxq->u.mb.mbxCommand,
8870 lpfc_sli_config_mbox_subsys_get(phba,
8872 lpfc_sli_config_mbox_opcode_get(phba,
8874 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
8875 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
8876 bf_get(lpfc_mcqe_ext_status,
8878 psli->sli_flag, flag);
8880 } else if (flag == MBX_POLL) {
8881 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8882 "(%d):2542 Try to issue mailbox command "
8883 "x%x (x%x/x%x) synchronously ahead of async "
8884 "mailbox command queue: x%x x%x\n",
8885 mboxq->vport ? mboxq->vport->vpi : 0,
8886 mboxq->u.mb.mbxCommand,
8887 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8888 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8889 psli->sli_flag, flag);
8890 /* Try to block the asynchronous mailbox posting */
8891 rc = lpfc_sli4_async_mbox_block(phba);
8893 /* Successfully blocked, now issue sync mbox cmd */
8894 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
8895 if (rc != MBX_SUCCESS)
8896 lpfc_printf_log(phba, KERN_WARNING,
8898 "(%d):2597 Sync Mailbox command "
8899 "x%x (x%x/x%x) failure: "
8900 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8902 mboxq->vport ? mboxq->vport->vpi : 0,
8903 mboxq->u.mb.mbxCommand,
8904 lpfc_sli_config_mbox_subsys_get(phba,
8906 lpfc_sli_config_mbox_opcode_get(phba,
8908 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
8909 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
8910 bf_get(lpfc_mcqe_ext_status,
8912 psli->sli_flag, flag);
8913 /* Unblock the async mailbox posting afterward */
8914 lpfc_sli4_async_mbox_unblock(phba);
8919 /* Now, interrupt mode asynchronous mailbox command */
8920 rc = lpfc_mbox_cmd_check(phba, mboxq);
8922 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8923 "(%d):2543 Mailbox command x%x (x%x/x%x) "
8924 "cannot issue Data: x%x x%x\n",
8925 mboxq->vport ? mboxq->vport->vpi : 0,
8926 mboxq->u.mb.mbxCommand,
8927 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8928 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8929 psli->sli_flag, flag);
8930 goto out_not_finished;
8933 /* Put the mailbox command to the driver internal FIFO */
8934 psli->slistat.mbox_busy++;
8935 spin_lock_irqsave(&phba->hbalock, iflags);
8936 lpfc_mbox_put(phba, mboxq);
8937 spin_unlock_irqrestore(&phba->hbalock, iflags);
8938 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8939 "(%d):0354 Mbox cmd issue - Enqueue Data: "
8940 "x%x (x%x/x%x) x%x x%x x%x\n",
8941 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
8942 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8943 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8944 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8945 phba->pport->port_state,
8946 psli->sli_flag, MBX_NOWAIT);
8947 /* Wake up worker thread to transport mailbox command from head */
8948 lpfc_worker_wake_up(phba);
8953 return MBX_NOT_FINISHED;
8957 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
8958 * @phba: Pointer to HBA context object.
8960 * This function is called by worker thread to send a mailbox command to
8961 * SLI4 HBA firmware.
8965 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
8967 struct lpfc_sli *psli = &phba->sli;
8968 LPFC_MBOXQ_t *mboxq;
8969 int rc = MBX_SUCCESS;
8970 unsigned long iflags;
8971 struct lpfc_mqe *mqe;
8974 /* Check interrupt mode before post async mailbox command */
8975 if (unlikely(!phba->sli4_hba.intr_enable))
8976 return MBX_NOT_FINISHED;
8978 /* Check for mailbox command service token */
8979 spin_lock_irqsave(&phba->hbalock, iflags);
8980 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8981 spin_unlock_irqrestore(&phba->hbalock, iflags);
8982 return MBX_NOT_FINISHED;
8984 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8985 spin_unlock_irqrestore(&phba->hbalock, iflags);
8986 return MBX_NOT_FINISHED;
8988 if (unlikely(phba->sli.mbox_active)) {
8989 spin_unlock_irqrestore(&phba->hbalock, iflags);
8990 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
8991 "0384 There is pending active mailbox cmd\n");
8992 return MBX_NOT_FINISHED;
8994 /* Take the mailbox command service token */
8995 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8997 /* Get the next mailbox command from head of queue */
8998 mboxq = lpfc_mbox_get(phba);
9000 /* If no more mailbox command waiting for post, we're done */
9002 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9003 spin_unlock_irqrestore(&phba->hbalock, iflags);
9006 phba->sli.mbox_active = mboxq;
9007 spin_unlock_irqrestore(&phba->hbalock, iflags);
9009 /* Check device readiness for posting mailbox command */
9010 rc = lpfc_mbox_dev_check(phba);
9012 /* Driver clean routine will clean up pending mailbox */
9013 goto out_not_finished;
9015 /* Prepare the mbox command to be posted */
9016 mqe = &mboxq->u.mqe;
9017 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
9019 /* Start timer for the mbox_tmo and log some mailbox post messages */
9020 mod_timer(&psli->mbox_tmo, (jiffies +
9021 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
9023 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9024 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
9026 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
9027 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9028 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9029 phba->pport->port_state, psli->sli_flag);
9031 if (mbx_cmnd != MBX_HEARTBEAT) {
9033 lpfc_debugfs_disc_trc(mboxq->vport,
9034 LPFC_DISC_TRC_MBOX_VPORT,
9035 "MBOX Send vport: cmd:x%x mb:x%x x%x",
9036 mbx_cmnd, mqe->un.mb_words[0],
9037 mqe->un.mb_words[1]);
9039 lpfc_debugfs_disc_trc(phba->pport,
9041 "MBOX Send: cmd:x%x mb:x%x x%x",
9042 mbx_cmnd, mqe->un.mb_words[0],
9043 mqe->un.mb_words[1]);
9046 psli->slistat.mbox_cmd++;
9048 /* Post the mailbox command to the port */
9049 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
9050 if (rc != MBX_SUCCESS) {
9051 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
9052 "(%d):2533 Mailbox command x%x (x%x/x%x) "
9053 "cannot issue Data: x%x x%x\n",
9054 mboxq->vport ? mboxq->vport->vpi : 0,
9055 mboxq->u.mb.mbxCommand,
9056 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9057 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9058 psli->sli_flag, MBX_NOWAIT);
9059 goto out_not_finished;
9065 spin_lock_irqsave(&phba->hbalock, iflags);
9066 if (phba->sli.mbox_active) {
9067 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9068 __lpfc_mbox_cmpl_put(phba, mboxq);
9069 /* Release the token */
9070 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9071 phba->sli.mbox_active = NULL;
9073 spin_unlock_irqrestore(&phba->hbalock, iflags);
9075 return MBX_NOT_FINISHED;
9079 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
9080 * @phba: Pointer to HBA context object.
9081 * @pmbox: Pointer to mailbox object.
9082 * @flag: Flag indicating how the mailbox need to be processed.
9084 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
9085 * the API jump table function pointer from the lpfc_hba struct.
9087 * Return codes the caller owns the mailbox command after the return of the
9091 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
9093 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
9097 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
9098 * @phba: The hba struct for which this call is being executed.
9099 * @dev_grp: The HBA PCI-Device group number.
9101 * This routine sets up the mbox interface API function jump table in @phba
9103 * Returns: 0 - success, -ENODEV - failure.
9106 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
9110 case LPFC_PCI_DEV_LP:
9111 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
9112 phba->lpfc_sli_handle_slow_ring_event =
9113 lpfc_sli_handle_slow_ring_event_s3;
9114 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
9115 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
9116 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
9118 case LPFC_PCI_DEV_OC:
9119 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
9120 phba->lpfc_sli_handle_slow_ring_event =
9121 lpfc_sli_handle_slow_ring_event_s4;
9122 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
9123 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
9124 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
9127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9128 "1420 Invalid HBA PCI-device group: 0x%x\n",
9137 * __lpfc_sli_ringtx_put - Add an iocb to the txq
9138 * @phba: Pointer to HBA context object.
9139 * @pring: Pointer to driver SLI ring object.
9140 * @piocb: Pointer to address of newly added command iocb.
9142 * This function is called with hbalock held for SLI3 ports or
9143 * the ring lock held for SLI4 ports to add a command
9144 * iocb to the txq when SLI layer cannot submit the command iocb
9148 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9149 struct lpfc_iocbq *piocb)
9151 if (phba->sli_rev == LPFC_SLI_REV4)
9152 lockdep_assert_held(&pring->ring_lock);
9154 lockdep_assert_held(&phba->hbalock);
9155 /* Insert the caller's iocb in the txq tail for later processing. */
9156 list_add_tail(&piocb->list, &pring->txq);
9160 * lpfc_sli_next_iocb - Get the next iocb in the txq
9161 * @phba: Pointer to HBA context object.
9162 * @pring: Pointer to driver SLI ring object.
9163 * @piocb: Pointer to address of newly added command iocb.
9165 * This function is called with hbalock held before a new
9166 * iocb is submitted to the firmware. This function checks
9167 * txq to flush the iocbs in txq to Firmware before
9168 * submitting new iocbs to the Firmware.
9169 * If there are iocbs in the txq which need to be submitted
9170 * to firmware, lpfc_sli_next_iocb returns the first element
9171 * of the txq after dequeuing it from txq.
9172 * If there is no iocb in the txq then the function will return
9173 * *piocb and *piocb is set to NULL. Caller needs to check
9174 * *piocb to find if there are more commands in the txq.
9176 static struct lpfc_iocbq *
9177 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9178 struct lpfc_iocbq **piocb)
9180 struct lpfc_iocbq * nextiocb;
9182 lockdep_assert_held(&phba->hbalock);
9184 nextiocb = lpfc_sli_ringtx_get(phba, pring);
9194 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
9195 * @phba: Pointer to HBA context object.
9196 * @ring_number: SLI ring number to issue iocb on.
9197 * @piocb: Pointer to command iocb.
9198 * @flag: Flag indicating if this command can be put into txq.
9200 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
9201 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
9202 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
9203 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
9204 * this function allows only iocbs for posting buffers. This function finds
9205 * next available slot in the command ring and posts the command to the
9206 * available slot and writes the port attention register to request HBA start
9207 * processing new iocb. If there is no slot available in the ring and
9208 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
9209 * the function returns IOCB_BUSY.
9211 * This function is called with hbalock held. The function will return success
9212 * after it successfully submit the iocb to firmware or after adding to the
9216 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
9217 struct lpfc_iocbq *piocb, uint32_t flag)
9219 struct lpfc_iocbq *nextiocb;
9221 struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
9223 lockdep_assert_held(&phba->hbalock);
9225 if (piocb->iocb_cmpl && (!piocb->vport) &&
9226 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
9227 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
9228 lpfc_printf_log(phba, KERN_ERR,
9229 LOG_SLI | LOG_VPORT,
9230 "1807 IOCB x%x failed. No vport\n",
9231 piocb->iocb.ulpCommand);
9237 /* If the PCI channel is in offline state, do not post iocbs. */
9238 if (unlikely(pci_channel_offline(phba->pcidev)))
9241 /* If HBA has a deferred error attention, fail the iocb. */
9242 if (unlikely(phba->hba_flag & DEFER_ERATT))
9246 * We should never get an IOCB if we are in a < LINK_DOWN state
9248 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
9252 * Check to see if we are blocking IOCB processing because of a
9253 * outstanding event.
9255 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
9258 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
9260 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
9261 * can be issued if the link is not up.
9263 switch (piocb->iocb.ulpCommand) {
9264 case CMD_GEN_REQUEST64_CR:
9265 case CMD_GEN_REQUEST64_CX:
9266 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
9267 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
9268 FC_RCTL_DD_UNSOL_CMD) ||
9269 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
9270 MENLO_TRANSPORT_TYPE))
9274 case CMD_QUE_RING_BUF_CN:
9275 case CMD_QUE_RING_BUF64_CN:
9277 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
9278 * completion, iocb_cmpl MUST be 0.
9280 if (piocb->iocb_cmpl)
9281 piocb->iocb_cmpl = NULL;
9283 case CMD_CREATE_XRI_CR:
9284 case CMD_CLOSE_XRI_CN:
9285 case CMD_CLOSE_XRI_CX:
9292 * For FCP commands, we must be in a state where we can process link
9295 } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
9296 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
9300 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
9301 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
9302 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
9305 lpfc_sli_update_ring(phba, pring);
9307 lpfc_sli_update_full_ring(phba, pring);
9310 return IOCB_SUCCESS;
9315 pring->stats.iocb_cmd_delay++;
9319 if (!(flag & SLI_IOCB_RET_IOCB)) {
9320 __lpfc_sli_ringtx_put(phba, pring, piocb);
9321 return IOCB_SUCCESS;
9328 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
9329 * @phba: Pointer to HBA context object.
9330 * @piocb: Pointer to command iocb.
9331 * @sglq: Pointer to the scatter gather queue object.
9333 * This routine converts the bpl or bde that is in the IOCB
9334 * to a sgl list for the sli4 hardware. The physical address
9335 * of the bpl/bde is converted back to a virtual address.
9336 * If the IOCB contains a BPL then the list of BDE's is
9337 * converted to sli4_sge's. If the IOCB contains a single
9338 * BDE then it is converted to a single sli_sge.
9339 * The IOCB is still in cpu endianess so the contents of
9340 * the bpl can be used without byte swapping.
9342 * Returns valid XRI = Success, NO_XRI = Failure.
9345 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
9346 struct lpfc_sglq *sglq)
9348 uint16_t xritag = NO_XRI;
9349 struct ulp_bde64 *bpl = NULL;
9350 struct ulp_bde64 bde;
9351 struct sli4_sge *sgl = NULL;
9352 struct lpfc_dmabuf *dmabuf;
9356 uint32_t offset = 0; /* accumulated offset in the sg request list */
9357 int inbound = 0; /* number of sg reply entries inbound from firmware */
9359 if (!piocbq || !sglq)
9362 sgl = (struct sli4_sge *)sglq->sgl;
9363 icmd = &piocbq->iocb;
9364 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
9365 return sglq->sli4_xritag;
9366 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
9367 numBdes = icmd->un.genreq64.bdl.bdeSize /
9368 sizeof(struct ulp_bde64);
9369 /* The addrHigh and addrLow fields within the IOCB
9370 * have not been byteswapped yet so there is no
9371 * need to swap them back.
9373 if (piocbq->context3)
9374 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
9378 bpl = (struct ulp_bde64 *)dmabuf->virt;
9382 for (i = 0; i < numBdes; i++) {
9383 /* Should already be byte swapped. */
9384 sgl->addr_hi = bpl->addrHigh;
9385 sgl->addr_lo = bpl->addrLow;
9387 sgl->word2 = le32_to_cpu(sgl->word2);
9388 if ((i+1) == numBdes)
9389 bf_set(lpfc_sli4_sge_last, sgl, 1);
9391 bf_set(lpfc_sli4_sge_last, sgl, 0);
9392 /* swap the size field back to the cpu so we
9393 * can assign it to the sgl.
9395 bde.tus.w = le32_to_cpu(bpl->tus.w);
9396 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
9397 /* The offsets in the sgl need to be accumulated
9398 * separately for the request and reply lists.
9399 * The request is always first, the reply follows.
9401 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
9402 /* add up the reply sg entries */
9403 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
9405 /* first inbound? reset the offset */
9408 bf_set(lpfc_sli4_sge_offset, sgl, offset);
9409 bf_set(lpfc_sli4_sge_type, sgl,
9410 LPFC_SGE_TYPE_DATA);
9411 offset += bde.tus.f.bdeSize;
9413 sgl->word2 = cpu_to_le32(sgl->word2);
9417 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
9418 /* The addrHigh and addrLow fields of the BDE have not
9419 * been byteswapped yet so they need to be swapped
9420 * before putting them in the sgl.
9423 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
9425 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
9426 sgl->word2 = le32_to_cpu(sgl->word2);
9427 bf_set(lpfc_sli4_sge_last, sgl, 1);
9428 sgl->word2 = cpu_to_le32(sgl->word2);
9430 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
9432 return sglq->sli4_xritag;
9436 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
9437 * @phba: Pointer to HBA context object.
9438 * @piocb: Pointer to command iocb.
9439 * @wqe: Pointer to the work queue entry.
9441 * This routine converts the iocb command to its Work Queue Entry
9442 * equivalent. The wqe pointer should not have any fields set when
9443 * this routine is called because it will memcpy over them.
9444 * This routine does not set the CQ_ID or the WQEC bits in the
9447 * Returns: 0 = Success, IOCB_ERROR = Failure.
9450 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
9451 union lpfc_wqe128 *wqe)
9453 uint32_t xmit_len = 0, total_len = 0;
9457 uint8_t command_type = ELS_COMMAND_NON_FIP;
9460 uint16_t abrt_iotag;
9461 struct lpfc_iocbq *abrtiocbq;
9462 struct ulp_bde64 *bpl = NULL;
9463 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
9465 struct ulp_bde64 bde;
9466 struct lpfc_nodelist *ndlp;
9470 fip = phba->hba_flag & HBA_FIP_SUPPORT;
9471 /* The fcp commands will set command type */
9472 if (iocbq->iocb_flag & LPFC_IO_FCP)
9473 command_type = FCP_COMMAND;
9474 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
9475 command_type = ELS_COMMAND_FIP;
9477 command_type = ELS_COMMAND_NON_FIP;
9479 if (phba->fcp_embed_io)
9480 memset(wqe, 0, sizeof(union lpfc_wqe128));
9481 /* Some of the fields are in the right position already */
9482 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
9483 /* The ct field has moved so reset */
9484 wqe->generic.wqe_com.word7 = 0;
9485 wqe->generic.wqe_com.word10 = 0;
9487 abort_tag = (uint32_t) iocbq->iotag;
9488 xritag = iocbq->sli4_xritag;
9489 /* words0-2 bpl convert bde */
9490 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
9491 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
9492 sizeof(struct ulp_bde64);
9493 bpl = (struct ulp_bde64 *)
9494 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
9498 /* Should already be byte swapped. */
9499 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
9500 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
9501 /* swap the size field back to the cpu so we
9502 * can assign it to the sgl.
9504 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
9505 xmit_len = wqe->generic.bde.tus.f.bdeSize;
9507 for (i = 0; i < numBdes; i++) {
9508 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
9509 total_len += bde.tus.f.bdeSize;
9512 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
9514 iocbq->iocb.ulpIoTag = iocbq->iotag;
9515 cmnd = iocbq->iocb.ulpCommand;
9517 switch (iocbq->iocb.ulpCommand) {
9518 case CMD_ELS_REQUEST64_CR:
9519 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
9520 ndlp = iocbq->context_un.ndlp;
9522 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9523 if (!iocbq->iocb.ulpLe) {
9524 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9525 "2007 Only Limited Edition cmd Format"
9526 " supported 0x%x\n",
9527 iocbq->iocb.ulpCommand);
9531 wqe->els_req.payload_len = xmit_len;
9532 /* Els_reguest64 has a TMO */
9533 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
9534 iocbq->iocb.ulpTimeout);
9535 /* Need a VF for word 4 set the vf bit*/
9536 bf_set(els_req64_vf, &wqe->els_req, 0);
9537 /* And a VFID for word 12 */
9538 bf_set(els_req64_vfid, &wqe->els_req, 0);
9539 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
9540 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9541 iocbq->iocb.ulpContext);
9542 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
9543 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
9544 /* CCP CCPE PV PRI in word10 were set in the memcpy */
9545 if (command_type == ELS_COMMAND_FIP)
9546 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
9547 >> LPFC_FIP_ELS_ID_SHIFT);
9548 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9549 iocbq->context2)->virt);
9550 if_type = bf_get(lpfc_sli_intf_if_type,
9551 &phba->sli4_hba.sli_intf);
9552 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9553 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
9554 *pcmd == ELS_CMD_SCR ||
9555 *pcmd == ELS_CMD_RDF ||
9556 *pcmd == ELS_CMD_RSCN_XMT ||
9557 *pcmd == ELS_CMD_FDISC ||
9558 *pcmd == ELS_CMD_LOGO ||
9559 *pcmd == ELS_CMD_PLOGI)) {
9560 bf_set(els_req64_sp, &wqe->els_req, 1);
9561 bf_set(els_req64_sid, &wqe->els_req,
9562 iocbq->vport->fc_myDID);
9563 if ((*pcmd == ELS_CMD_FLOGI) &&
9564 !(phba->fc_topology ==
9565 LPFC_TOPOLOGY_LOOP))
9566 bf_set(els_req64_sid, &wqe->els_req, 0);
9567 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
9568 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9569 phba->vpi_ids[iocbq->vport->vpi]);
9570 } else if (pcmd && iocbq->context1) {
9571 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
9572 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9573 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9576 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
9577 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9578 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
9579 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
9580 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
9581 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
9582 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
9583 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
9584 wqe->els_req.max_response_payload_len = total_len - xmit_len;
9586 case CMD_XMIT_SEQUENCE64_CX:
9587 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
9588 iocbq->iocb.un.ulpWord[3]);
9589 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
9590 iocbq->iocb.unsli3.rcvsli3.ox_id);
9591 /* The entire sequence is transmitted for this IOCB */
9592 xmit_len = total_len;
9593 cmnd = CMD_XMIT_SEQUENCE64_CR;
9594 if (phba->link_flag & LS_LOOPBACK_MODE)
9595 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
9597 case CMD_XMIT_SEQUENCE64_CR:
9598 /* word3 iocb=io_tag32 wqe=reserved */
9599 wqe->xmit_sequence.rsvd3 = 0;
9600 /* word4 relative_offset memcpy */
9601 /* word5 r_ctl/df_ctl memcpy */
9602 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
9603 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
9604 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
9605 LPFC_WQE_IOD_WRITE);
9606 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
9607 LPFC_WQE_LENLOC_WORD12);
9608 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
9609 wqe->xmit_sequence.xmit_len = xmit_len;
9610 command_type = OTHER_COMMAND;
9612 case CMD_XMIT_BCAST64_CN:
9613 /* word3 iocb=iotag32 wqe=seq_payload_len */
9614 wqe->xmit_bcast64.seq_payload_len = xmit_len;
9615 /* word4 iocb=rsvd wqe=rsvd */
9616 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
9617 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
9618 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
9619 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9620 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
9621 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
9622 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
9623 LPFC_WQE_LENLOC_WORD3);
9624 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
9626 case CMD_FCP_IWRITE64_CR:
9627 command_type = FCP_COMMAND_DATA_OUT;
9628 /* word3 iocb=iotag wqe=payload_offset_len */
9629 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9630 bf_set(payload_offset_len, &wqe->fcp_iwrite,
9631 xmit_len + sizeof(struct fcp_rsp));
9632 bf_set(cmd_buff_len, &wqe->fcp_iwrite,
9634 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9635 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9636 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
9637 iocbq->iocb.ulpFCP2Rcvy);
9638 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
9639 /* Always open the exchange */
9640 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
9641 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
9642 LPFC_WQE_LENLOC_WORD4);
9643 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
9644 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
9645 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9646 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
9647 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
9648 if (iocbq->priority) {
9649 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
9650 (iocbq->priority << 1));
9652 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
9653 (phba->cfg_XLanePriority << 1));
9656 /* Note, word 10 is already initialized to 0 */
9658 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9659 if (phba->cfg_enable_pbde)
9660 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1);
9662 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
9664 if (phba->fcp_embed_io) {
9665 struct lpfc_io_buf *lpfc_cmd;
9666 struct sli4_sge *sgl;
9667 struct fcp_cmnd *fcp_cmnd;
9670 /* 128 byte wqe support here */
9672 lpfc_cmd = iocbq->context1;
9673 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9674 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9676 /* Word 0-2 - FCP_CMND */
9677 wqe->generic.bde.tus.f.bdeFlags =
9678 BUFF_TYPE_BDE_IMMED;
9679 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9680 wqe->generic.bde.addrHigh = 0;
9681 wqe->generic.bde.addrLow = 88; /* Word 22 */
9683 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
9684 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
9686 /* Word 22-29 FCP CMND Payload */
9687 ptr = &wqe->words[22];
9688 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9691 case CMD_FCP_IREAD64_CR:
9692 /* word3 iocb=iotag wqe=payload_offset_len */
9693 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9694 bf_set(payload_offset_len, &wqe->fcp_iread,
9695 xmit_len + sizeof(struct fcp_rsp));
9696 bf_set(cmd_buff_len, &wqe->fcp_iread,
9698 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9699 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9700 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
9701 iocbq->iocb.ulpFCP2Rcvy);
9702 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
9703 /* Always open the exchange */
9704 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
9705 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
9706 LPFC_WQE_LENLOC_WORD4);
9707 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
9708 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
9709 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9710 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
9711 bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
9712 if (iocbq->priority) {
9713 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
9714 (iocbq->priority << 1));
9716 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
9717 (phba->cfg_XLanePriority << 1));
9720 /* Note, word 10 is already initialized to 0 */
9722 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9723 if (phba->cfg_enable_pbde)
9724 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1);
9726 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
9728 if (phba->fcp_embed_io) {
9729 struct lpfc_io_buf *lpfc_cmd;
9730 struct sli4_sge *sgl;
9731 struct fcp_cmnd *fcp_cmnd;
9734 /* 128 byte wqe support here */
9736 lpfc_cmd = iocbq->context1;
9737 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9738 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9740 /* Word 0-2 - FCP_CMND */
9741 wqe->generic.bde.tus.f.bdeFlags =
9742 BUFF_TYPE_BDE_IMMED;
9743 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9744 wqe->generic.bde.addrHigh = 0;
9745 wqe->generic.bde.addrLow = 88; /* Word 22 */
9747 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
9748 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
9750 /* Word 22-29 FCP CMND Payload */
9751 ptr = &wqe->words[22];
9752 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9755 case CMD_FCP_ICMND64_CR:
9756 /* word3 iocb=iotag wqe=payload_offset_len */
9757 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9758 bf_set(payload_offset_len, &wqe->fcp_icmd,
9759 xmit_len + sizeof(struct fcp_rsp));
9760 bf_set(cmd_buff_len, &wqe->fcp_icmd,
9762 /* word3 iocb=IO_TAG wqe=reserved */
9763 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
9764 /* Always open the exchange */
9765 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
9766 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
9767 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
9768 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
9769 LPFC_WQE_LENLOC_NONE);
9770 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
9771 iocbq->iocb.ulpFCP2Rcvy);
9772 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9773 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
9774 bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
9775 if (iocbq->priority) {
9776 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
9777 (iocbq->priority << 1));
9779 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
9780 (phba->cfg_XLanePriority << 1));
9783 /* Note, word 10 is already initialized to 0 */
9785 if (phba->fcp_embed_io) {
9786 struct lpfc_io_buf *lpfc_cmd;
9787 struct sli4_sge *sgl;
9788 struct fcp_cmnd *fcp_cmnd;
9791 /* 128 byte wqe support here */
9793 lpfc_cmd = iocbq->context1;
9794 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9795 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9797 /* Word 0-2 - FCP_CMND */
9798 wqe->generic.bde.tus.f.bdeFlags =
9799 BUFF_TYPE_BDE_IMMED;
9800 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9801 wqe->generic.bde.addrHigh = 0;
9802 wqe->generic.bde.addrLow = 88; /* Word 22 */
9804 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
9805 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
9807 /* Word 22-29 FCP CMND Payload */
9808 ptr = &wqe->words[22];
9809 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9812 case CMD_GEN_REQUEST64_CR:
9813 /* For this command calculate the xmit length of the
9817 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
9818 sizeof(struct ulp_bde64);
9819 for (i = 0; i < numBdes; i++) {
9820 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
9821 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
9823 xmit_len += bde.tus.f.bdeSize;
9825 /* word3 iocb=IO_TAG wqe=request_payload_len */
9826 wqe->gen_req.request_payload_len = xmit_len;
9827 /* word4 iocb=parameter wqe=relative_offset memcpy */
9828 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
9829 /* word6 context tag copied in memcpy */
9830 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
9831 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
9832 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9833 "2015 Invalid CT %x command 0x%x\n",
9834 ct, iocbq->iocb.ulpCommand);
9837 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
9838 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
9839 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
9840 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
9841 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
9842 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
9843 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
9844 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
9845 wqe->gen_req.max_response_payload_len = total_len - xmit_len;
9846 command_type = OTHER_COMMAND;
9848 case CMD_XMIT_ELS_RSP64_CX:
9849 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9850 /* words0-2 BDE memcpy */
9851 /* word3 iocb=iotag32 wqe=response_payload_len */
9852 wqe->xmit_els_rsp.response_payload_len = xmit_len;
9854 wqe->xmit_els_rsp.word4 = 0;
9855 /* word5 iocb=rsvd wge=did */
9856 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
9857 iocbq->iocb.un.xseq64.xmit_els_remoteID);
9859 if_type = bf_get(lpfc_sli_intf_if_type,
9860 &phba->sli4_hba.sli_intf);
9861 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9862 if (iocbq->vport->fc_flag & FC_PT2PT) {
9863 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
9864 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
9865 iocbq->vport->fc_myDID);
9866 if (iocbq->vport->fc_myDID == Fabric_DID) {
9868 &wqe->xmit_els_rsp.wqe_dest, 0);
9872 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
9873 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9874 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
9875 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
9876 iocbq->iocb.unsli3.rcvsli3.ox_id);
9877 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
9878 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
9879 phba->vpi_ids[iocbq->vport->vpi]);
9880 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
9881 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
9882 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
9883 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
9884 LPFC_WQE_LENLOC_WORD3);
9885 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
9886 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
9887 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9888 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9889 iocbq->context2)->virt);
9890 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9891 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
9892 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
9893 iocbq->vport->fc_myDID);
9894 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
9895 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
9896 phba->vpi_ids[phba->pport->vpi]);
9898 command_type = OTHER_COMMAND;
9900 case CMD_CLOSE_XRI_CN:
9901 case CMD_ABORT_XRI_CN:
9902 case CMD_ABORT_XRI_CX:
9903 /* words 0-2 memcpy should be 0 rserved */
9904 /* port will send abts */
9905 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
9906 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
9907 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
9908 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
9912 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
9914 * The link is down, or the command was ELS_FIP
9915 * so the fw does not need to send abts
9918 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
9920 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
9921 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
9922 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
9923 wqe->abort_cmd.rsrvd5 = 0;
9924 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
9925 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9926 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
9928 * The abort handler will send us CMD_ABORT_XRI_CN or
9929 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
9931 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
9932 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
9933 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
9934 LPFC_WQE_LENLOC_NONE);
9935 cmnd = CMD_ABORT_XRI_CX;
9936 command_type = OTHER_COMMAND;
9939 case CMD_XMIT_BLS_RSP64_CX:
9940 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9941 /* As BLS ABTS RSP WQE is very different from other WQEs,
9942 * we re-construct this WQE here based on information in
9943 * iocbq from scratch.
9945 memset(wqe, 0, sizeof(*wqe));
9946 /* OX_ID is invariable to who sent ABTS to CT exchange */
9947 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
9948 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
9949 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
9950 LPFC_ABTS_UNSOL_INT) {
9951 /* ABTS sent by initiator to CT exchange, the
9952 * RX_ID field will be filled with the newly
9953 * allocated responder XRI.
9955 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
9956 iocbq->sli4_xritag);
9958 /* ABTS sent by responder to CT exchange, the
9959 * RX_ID field will be filled with the responder
9962 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
9963 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
9965 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
9966 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
9969 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
9971 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
9972 iocbq->iocb.ulpContext);
9973 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
9974 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
9975 phba->vpi_ids[phba->pport->vpi]);
9976 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
9977 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
9978 LPFC_WQE_LENLOC_NONE);
9979 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
9980 command_type = OTHER_COMMAND;
9981 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
9982 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
9983 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
9984 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
9985 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
9986 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
9987 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
9991 case CMD_SEND_FRAME:
9992 bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME);
9993 bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */
9994 bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */
9995 bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1);
9996 bf_set(wqe_xbl, &wqe->generic.wqe_com, 1);
9997 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
9998 bf_set(wqe_xc, &wqe->generic.wqe_com, 1);
9999 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA);
10000 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10001 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
10002 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
10004 case CMD_XRI_ABORTED_CX:
10005 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
10006 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
10007 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
10008 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
10009 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
10011 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10012 "2014 Invalid command 0x%x\n",
10013 iocbq->iocb.ulpCommand);
10018 if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
10019 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
10020 else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
10021 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
10022 else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
10023 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
10024 iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
10025 LPFC_IO_DIF_INSERT);
10026 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
10027 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
10028 wqe->generic.wqe_com.abort_tag = abort_tag;
10029 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
10030 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
10031 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
10032 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10037 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
10038 * @phba: Pointer to HBA context object.
10039 * @ring_number: SLI ring number to issue iocb on.
10040 * @piocb: Pointer to command iocb.
10041 * @flag: Flag indicating if this command can be put into txq.
10043 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
10044 * an iocb command to an HBA with SLI-4 interface spec.
10046 * This function is called with ringlock held. The function will return success
10047 * after it successfully submit the iocb to firmware or after adding to the
10051 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
10052 struct lpfc_iocbq *piocb, uint32_t flag)
10054 struct lpfc_sglq *sglq;
10055 union lpfc_wqe128 wqe;
10056 struct lpfc_queue *wq;
10057 struct lpfc_sli_ring *pring;
10060 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
10061 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
10062 wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
10064 wq = phba->sli4_hba.els_wq;
10067 /* Get corresponding ring */
10071 * The WQE can be either 64 or 128 bytes,
10074 lockdep_assert_held(&pring->ring_lock);
10076 if (piocb->sli4_xritag == NO_XRI) {
10077 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
10078 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
10081 if (!list_empty(&pring->txq)) {
10082 if (!(flag & SLI_IOCB_RET_IOCB)) {
10083 __lpfc_sli_ringtx_put(phba,
10085 return IOCB_SUCCESS;
10090 sglq = __lpfc_sli_get_els_sglq(phba, piocb);
10092 if (!(flag & SLI_IOCB_RET_IOCB)) {
10093 __lpfc_sli_ringtx_put(phba,
10096 return IOCB_SUCCESS;
10102 } else if (piocb->iocb_flag & LPFC_IO_FCP)
10103 /* These IO's already have an XRI and a mapped sgl. */
10107 * This is a continuation of a commandi,(CX) so this
10108 * sglq is on the active list
10110 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
10116 piocb->sli4_lxritag = sglq->sli4_lxritag;
10117 piocb->sli4_xritag = sglq->sli4_xritag;
10118 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
10122 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
10125 if (lpfc_sli4_wq_put(wq, &wqe))
10127 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
10133 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
10135 * This routine wraps the actual lockless version for issusing IOCB function
10136 * pointer from the lpfc_hba struct.
10139 * IOCB_ERROR - Error
10140 * IOCB_SUCCESS - Success
10144 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
10145 struct lpfc_iocbq *piocb, uint32_t flag)
10147 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10151 * lpfc_sli_api_table_setup - Set up sli api function jump table
10152 * @phba: The hba struct for which this call is being executed.
10153 * @dev_grp: The HBA PCI-Device group number.
10155 * This routine sets up the SLI interface API function jump table in @phba
10157 * Returns: 0 - success, -ENODEV - failure.
10160 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
10164 case LPFC_PCI_DEV_LP:
10165 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
10166 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
10168 case LPFC_PCI_DEV_OC:
10169 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
10170 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
10173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10174 "1419 Invalid HBA PCI-device group: 0x%x\n",
10179 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
10184 * lpfc_sli4_calc_ring - Calculates which ring to use
10185 * @phba: Pointer to HBA context object.
10186 * @piocb: Pointer to command iocb.
10188 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
10189 * hba_wqidx, thus we need to calculate the corresponding ring.
10190 * Since ABORTS must go on the same WQ of the command they are
10191 * aborting, we use command's hba_wqidx.
10193 struct lpfc_sli_ring *
10194 lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
10196 struct lpfc_io_buf *lpfc_cmd;
10198 if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
10199 if (unlikely(!phba->sli4_hba.hdwq))
10202 * for abort iocb hba_wqidx should already
10203 * be setup based on what work queue we used.
10205 if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
10206 lpfc_cmd = (struct lpfc_io_buf *)piocb->context1;
10207 piocb->hba_wqidx = lpfc_cmd->hdwq_no;
10209 return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
10211 if (unlikely(!phba->sli4_hba.els_wq))
10213 piocb->hba_wqidx = 0;
10214 return phba->sli4_hba.els_wq->pring;
10219 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
10220 * @phba: Pointer to HBA context object.
10221 * @pring: Pointer to driver SLI ring object.
10222 * @piocb: Pointer to command iocb.
10223 * @flag: Flag indicating if this command can be put into txq.
10225 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
10226 * function. This function gets the hbalock and calls
10227 * __lpfc_sli_issue_iocb function and will return the error returned
10228 * by __lpfc_sli_issue_iocb function. This wrapper is used by
10229 * functions which do not hold hbalock.
10232 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
10233 struct lpfc_iocbq *piocb, uint32_t flag)
10235 struct lpfc_sli_ring *pring;
10236 struct lpfc_queue *eq;
10237 unsigned long iflags;
10240 if (phba->sli_rev == LPFC_SLI_REV4) {
10241 eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq;
10243 pring = lpfc_sli4_calc_ring(phba, piocb);
10244 if (unlikely(pring == NULL))
10247 spin_lock_irqsave(&pring->ring_lock, iflags);
10248 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10249 spin_unlock_irqrestore(&pring->ring_lock, iflags);
10251 lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH);
10253 /* For now, SLI2/3 will still use hbalock */
10254 spin_lock_irqsave(&phba->hbalock, iflags);
10255 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10256 spin_unlock_irqrestore(&phba->hbalock, iflags);
10262 * lpfc_extra_ring_setup - Extra ring setup function
10263 * @phba: Pointer to HBA context object.
10265 * This function is called while driver attaches with the
10266 * HBA to setup the extra ring. The extra ring is used
10267 * only when driver needs to support target mode functionality
10268 * or IP over FC functionalities.
10270 * This function is called with no lock held. SLI3 only.
10273 lpfc_extra_ring_setup( struct lpfc_hba *phba)
10275 struct lpfc_sli *psli;
10276 struct lpfc_sli_ring *pring;
10280 /* Adjust cmd/rsp ring iocb entries more evenly */
10282 /* Take some away from the FCP ring */
10283 pring = &psli->sli3_ring[LPFC_FCP_RING];
10284 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10285 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10286 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10287 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10289 /* and give them to the extra ring */
10290 pring = &psli->sli3_ring[LPFC_EXTRA_RING];
10292 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10293 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10294 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10295 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10297 /* Setup default profile for this ring */
10298 pring->iotag_max = 4096;
10299 pring->num_mask = 1;
10300 pring->prt[0].profile = 0; /* Mask 0 */
10301 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
10302 pring->prt[0].type = phba->cfg_multi_ring_type;
10303 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
10307 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
10308 * @phba: Pointer to HBA context object.
10309 * @iocbq: Pointer to iocb object.
10311 * The async_event handler calls this routine when it receives
10312 * an ASYNC_STATUS_CN event from the port. The port generates
10313 * this event when an Abort Sequence request to an rport fails
10314 * twice in succession. The abort could be originated by the
10315 * driver or by the port. The ABTS could have been for an ELS
10316 * or FCP IO. The port only generates this event when an ABTS
10317 * fails to complete after one retry.
10320 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
10321 struct lpfc_iocbq *iocbq)
10323 struct lpfc_nodelist *ndlp = NULL;
10324 uint16_t rpi = 0, vpi = 0;
10325 struct lpfc_vport *vport = NULL;
10327 /* The rpi in the ulpContext is vport-sensitive. */
10328 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
10329 rpi = iocbq->iocb.ulpContext;
10331 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10332 "3092 Port generated ABTS async event "
10333 "on vpi %d rpi %d status 0x%x\n",
10334 vpi, rpi, iocbq->iocb.ulpStatus);
10336 vport = lpfc_find_vport_by_vpid(phba, vpi);
10339 ndlp = lpfc_findnode_rpi(vport, rpi);
10340 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
10343 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
10344 lpfc_sli_abts_recover_port(vport, ndlp);
10348 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10349 "3095 Event Context not found, no "
10350 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
10351 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
10355 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
10356 * @phba: pointer to HBA context object.
10357 * @ndlp: nodelist pointer for the impacted rport.
10358 * @axri: pointer to the wcqe containing the failed exchange.
10360 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
10361 * port. The port generates this event when an abort exchange request to an
10362 * rport fails twice in succession with no reply. The abort could be originated
10363 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
10366 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
10367 struct lpfc_nodelist *ndlp,
10368 struct sli4_wcqe_xri_aborted *axri)
10370 struct lpfc_vport *vport;
10371 uint32_t ext_status = 0;
10373 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
10374 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10375 "3115 Node Context not found, driver "
10376 "ignoring abts err event\n");
10380 vport = ndlp->vport;
10381 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10382 "3116 Port generated FCP XRI ABORT event on "
10383 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
10384 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
10385 bf_get(lpfc_wcqe_xa_xri, axri),
10386 bf_get(lpfc_wcqe_xa_status, axri),
10390 * Catch the ABTS protocol failure case. Older OCe FW releases returned
10391 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
10392 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
10394 ext_status = axri->parameter & IOERR_PARAM_MASK;
10395 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
10396 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
10397 lpfc_sli_abts_recover_port(vport, ndlp);
10401 * lpfc_sli_async_event_handler - ASYNC iocb handler function
10402 * @phba: Pointer to HBA context object.
10403 * @pring: Pointer to driver SLI ring object.
10404 * @iocbq: Pointer to iocb object.
10406 * This function is called by the slow ring event handler
10407 * function when there is an ASYNC event iocb in the ring.
10408 * This function is called with no lock held.
10409 * Currently this function handles only temperature related
10410 * ASYNC events. The function decodes the temperature sensor
10411 * event message and posts events for the management applications.
10414 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
10415 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
10419 struct temp_event temp_event_data;
10420 struct Scsi_Host *shost;
10423 icmd = &iocbq->iocb;
10424 evt_code = icmd->un.asyncstat.evt_code;
10426 switch (evt_code) {
10427 case ASYNC_TEMP_WARN:
10428 case ASYNC_TEMP_SAFE:
10429 temp_event_data.data = (uint32_t) icmd->ulpContext;
10430 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
10431 if (evt_code == ASYNC_TEMP_WARN) {
10432 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
10433 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
10434 "0347 Adapter is very hot, please take "
10435 "corrective action. temperature : %d Celsius\n",
10436 (uint32_t) icmd->ulpContext);
10438 temp_event_data.event_code = LPFC_NORMAL_TEMP;
10439 lpfc_printf_log(phba, KERN_ERR, LOG_TEMP,
10440 "0340 Adapter temperature is OK now. "
10441 "temperature : %d Celsius\n",
10442 (uint32_t) icmd->ulpContext);
10445 /* Send temperature change event to applications */
10446 shost = lpfc_shost_from_vport(phba->pport);
10447 fc_host_post_vendor_event(shost, fc_get_event_number(),
10448 sizeof(temp_event_data), (char *) &temp_event_data,
10449 LPFC_NL_VENDOR_ID);
10451 case ASYNC_STATUS_CN:
10452 lpfc_sli_abts_err_handler(phba, iocbq);
10455 iocb_w = (uint32_t *) icmd;
10456 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
10457 "0346 Ring %d handler: unexpected ASYNC_STATUS"
10459 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
10460 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
10461 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
10462 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
10463 pring->ringno, icmd->un.asyncstat.evt_code,
10464 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
10465 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
10466 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
10467 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
10475 * lpfc_sli4_setup - SLI ring setup function
10476 * @phba: Pointer to HBA context object.
10478 * lpfc_sli_setup sets up rings of the SLI interface with
10479 * number of iocbs per ring and iotags. This function is
10480 * called while driver attach to the HBA and before the
10481 * interrupts are enabled. So there is no need for locking.
10483 * This function always returns 0.
10486 lpfc_sli4_setup(struct lpfc_hba *phba)
10488 struct lpfc_sli_ring *pring;
10490 pring = phba->sli4_hba.els_wq->pring;
10491 pring->num_mask = LPFC_MAX_RING_MASK;
10492 pring->prt[0].profile = 0; /* Mask 0 */
10493 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
10494 pring->prt[0].type = FC_TYPE_ELS;
10495 pring->prt[0].lpfc_sli_rcv_unsol_event =
10496 lpfc_els_unsol_event;
10497 pring->prt[1].profile = 0; /* Mask 1 */
10498 pring->prt[1].rctl = FC_RCTL_ELS_REP;
10499 pring->prt[1].type = FC_TYPE_ELS;
10500 pring->prt[1].lpfc_sli_rcv_unsol_event =
10501 lpfc_els_unsol_event;
10502 pring->prt[2].profile = 0; /* Mask 2 */
10503 /* NameServer Inquiry */
10504 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
10506 pring->prt[2].type = FC_TYPE_CT;
10507 pring->prt[2].lpfc_sli_rcv_unsol_event =
10508 lpfc_ct_unsol_event;
10509 pring->prt[3].profile = 0; /* Mask 3 */
10510 /* NameServer response */
10511 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
10513 pring->prt[3].type = FC_TYPE_CT;
10514 pring->prt[3].lpfc_sli_rcv_unsol_event =
10515 lpfc_ct_unsol_event;
10520 * lpfc_sli_setup - SLI ring setup function
10521 * @phba: Pointer to HBA context object.
10523 * lpfc_sli_setup sets up rings of the SLI interface with
10524 * number of iocbs per ring and iotags. This function is
10525 * called while driver attach to the HBA and before the
10526 * interrupts are enabled. So there is no need for locking.
10528 * This function always returns 0. SLI3 only.
10531 lpfc_sli_setup(struct lpfc_hba *phba)
10533 int i, totiocbsize = 0;
10534 struct lpfc_sli *psli = &phba->sli;
10535 struct lpfc_sli_ring *pring;
10537 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
10538 psli->sli_flag = 0;
10540 psli->iocbq_lookup = NULL;
10541 psli->iocbq_lookup_len = 0;
10542 psli->last_iotag = 0;
10544 for (i = 0; i < psli->num_rings; i++) {
10545 pring = &psli->sli3_ring[i];
10547 case LPFC_FCP_RING: /* ring 0 - FCP */
10548 /* numCiocb and numRiocb are used in config_port */
10549 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
10550 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
10551 pring->sli.sli3.numCiocb +=
10552 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10553 pring->sli.sli3.numRiocb +=
10554 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10555 pring->sli.sli3.numCiocb +=
10556 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10557 pring->sli.sli3.numRiocb +=
10558 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10559 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10560 SLI3_IOCB_CMD_SIZE :
10561 SLI2_IOCB_CMD_SIZE;
10562 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10563 SLI3_IOCB_RSP_SIZE :
10564 SLI2_IOCB_RSP_SIZE;
10565 pring->iotag_ctr = 0;
10567 (phba->cfg_hba_queue_depth * 2);
10568 pring->fast_iotag = pring->iotag_max;
10569 pring->num_mask = 0;
10571 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
10572 /* numCiocb and numRiocb are used in config_port */
10573 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
10574 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
10575 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10576 SLI3_IOCB_CMD_SIZE :
10577 SLI2_IOCB_CMD_SIZE;
10578 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10579 SLI3_IOCB_RSP_SIZE :
10580 SLI2_IOCB_RSP_SIZE;
10581 pring->iotag_max = phba->cfg_hba_queue_depth;
10582 pring->num_mask = 0;
10584 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
10585 /* numCiocb and numRiocb are used in config_port */
10586 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
10587 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
10588 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10589 SLI3_IOCB_CMD_SIZE :
10590 SLI2_IOCB_CMD_SIZE;
10591 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10592 SLI3_IOCB_RSP_SIZE :
10593 SLI2_IOCB_RSP_SIZE;
10594 pring->fast_iotag = 0;
10595 pring->iotag_ctr = 0;
10596 pring->iotag_max = 4096;
10597 pring->lpfc_sli_rcv_async_status =
10598 lpfc_sli_async_event_handler;
10599 pring->num_mask = LPFC_MAX_RING_MASK;
10600 pring->prt[0].profile = 0; /* Mask 0 */
10601 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
10602 pring->prt[0].type = FC_TYPE_ELS;
10603 pring->prt[0].lpfc_sli_rcv_unsol_event =
10604 lpfc_els_unsol_event;
10605 pring->prt[1].profile = 0; /* Mask 1 */
10606 pring->prt[1].rctl = FC_RCTL_ELS_REP;
10607 pring->prt[1].type = FC_TYPE_ELS;
10608 pring->prt[1].lpfc_sli_rcv_unsol_event =
10609 lpfc_els_unsol_event;
10610 pring->prt[2].profile = 0; /* Mask 2 */
10611 /* NameServer Inquiry */
10612 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
10614 pring->prt[2].type = FC_TYPE_CT;
10615 pring->prt[2].lpfc_sli_rcv_unsol_event =
10616 lpfc_ct_unsol_event;
10617 pring->prt[3].profile = 0; /* Mask 3 */
10618 /* NameServer response */
10619 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
10621 pring->prt[3].type = FC_TYPE_CT;
10622 pring->prt[3].lpfc_sli_rcv_unsol_event =
10623 lpfc_ct_unsol_event;
10626 totiocbsize += (pring->sli.sli3.numCiocb *
10627 pring->sli.sli3.sizeCiocb) +
10628 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
10630 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
10631 /* Too many cmd / rsp ring entries in SLI2 SLIM */
10632 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
10633 "SLI2 SLIM Data: x%x x%lx\n",
10634 phba->brd_no, totiocbsize,
10635 (unsigned long) MAX_SLIM_IOCB_SIZE);
10637 if (phba->cfg_multi_ring_support == 2)
10638 lpfc_extra_ring_setup(phba);
10644 * lpfc_sli4_queue_init - Queue initialization function
10645 * @phba: Pointer to HBA context object.
10647 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
10648 * ring. This function also initializes ring indices of each ring.
10649 * This function is called during the initialization of the SLI
10650 * interface of an HBA.
10651 * This function is called with no lock held and always returns
10655 lpfc_sli4_queue_init(struct lpfc_hba *phba)
10657 struct lpfc_sli *psli;
10658 struct lpfc_sli_ring *pring;
10662 spin_lock_irq(&phba->hbalock);
10663 INIT_LIST_HEAD(&psli->mboxq);
10664 INIT_LIST_HEAD(&psli->mboxq_cmpl);
10665 /* Initialize list headers for txq and txcmplq as double linked lists */
10666 for (i = 0; i < phba->cfg_hdw_queue; i++) {
10667 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
10669 pring->ringno = LPFC_FCP_RING;
10670 pring->txcmplq_cnt = 0;
10671 INIT_LIST_HEAD(&pring->txq);
10672 INIT_LIST_HEAD(&pring->txcmplq);
10673 INIT_LIST_HEAD(&pring->iocb_continueq);
10674 spin_lock_init(&pring->ring_lock);
10676 pring = phba->sli4_hba.els_wq->pring;
10678 pring->ringno = LPFC_ELS_RING;
10679 pring->txcmplq_cnt = 0;
10680 INIT_LIST_HEAD(&pring->txq);
10681 INIT_LIST_HEAD(&pring->txcmplq);
10682 INIT_LIST_HEAD(&pring->iocb_continueq);
10683 spin_lock_init(&pring->ring_lock);
10685 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
10686 pring = phba->sli4_hba.nvmels_wq->pring;
10688 pring->ringno = LPFC_ELS_RING;
10689 pring->txcmplq_cnt = 0;
10690 INIT_LIST_HEAD(&pring->txq);
10691 INIT_LIST_HEAD(&pring->txcmplq);
10692 INIT_LIST_HEAD(&pring->iocb_continueq);
10693 spin_lock_init(&pring->ring_lock);
10696 spin_unlock_irq(&phba->hbalock);
10700 * lpfc_sli_queue_init - Queue initialization function
10701 * @phba: Pointer to HBA context object.
10703 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
10704 * ring. This function also initializes ring indices of each ring.
10705 * This function is called during the initialization of the SLI
10706 * interface of an HBA.
10707 * This function is called with no lock held and always returns
10711 lpfc_sli_queue_init(struct lpfc_hba *phba)
10713 struct lpfc_sli *psli;
10714 struct lpfc_sli_ring *pring;
10718 spin_lock_irq(&phba->hbalock);
10719 INIT_LIST_HEAD(&psli->mboxq);
10720 INIT_LIST_HEAD(&psli->mboxq_cmpl);
10721 /* Initialize list headers for txq and txcmplq as double linked lists */
10722 for (i = 0; i < psli->num_rings; i++) {
10723 pring = &psli->sli3_ring[i];
10725 pring->sli.sli3.next_cmdidx = 0;
10726 pring->sli.sli3.local_getidx = 0;
10727 pring->sli.sli3.cmdidx = 0;
10728 INIT_LIST_HEAD(&pring->iocb_continueq);
10729 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
10730 INIT_LIST_HEAD(&pring->postbufq);
10732 INIT_LIST_HEAD(&pring->txq);
10733 INIT_LIST_HEAD(&pring->txcmplq);
10734 spin_lock_init(&pring->ring_lock);
10736 spin_unlock_irq(&phba->hbalock);
10740 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
10741 * @phba: Pointer to HBA context object.
10743 * This routine flushes the mailbox command subsystem. It will unconditionally
10744 * flush all the mailbox commands in the three possible stages in the mailbox
10745 * command sub-system: pending mailbox command queue; the outstanding mailbox
10746 * command; and completed mailbox command queue. It is caller's responsibility
10747 * to make sure that the driver is in the proper state to flush the mailbox
10748 * command sub-system. Namely, the posting of mailbox commands into the
10749 * pending mailbox command queue from the various clients must be stopped;
10750 * either the HBA is in a state that it will never works on the outstanding
10751 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
10752 * mailbox command has been completed.
10755 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
10757 LIST_HEAD(completions);
10758 struct lpfc_sli *psli = &phba->sli;
10760 unsigned long iflag;
10762 /* Disable softirqs, including timers from obtaining phba->hbalock */
10763 local_bh_disable();
10765 /* Flush all the mailbox commands in the mbox system */
10766 spin_lock_irqsave(&phba->hbalock, iflag);
10768 /* The pending mailbox command queue */
10769 list_splice_init(&phba->sli.mboxq, &completions);
10770 /* The outstanding active mailbox command */
10771 if (psli->mbox_active) {
10772 list_add_tail(&psli->mbox_active->list, &completions);
10773 psli->mbox_active = NULL;
10774 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10776 /* The completed mailbox command queue */
10777 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
10778 spin_unlock_irqrestore(&phba->hbalock, iflag);
10780 /* Enable softirqs again, done with phba->hbalock */
10783 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
10784 while (!list_empty(&completions)) {
10785 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
10786 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
10787 if (pmb->mbox_cmpl)
10788 pmb->mbox_cmpl(phba, pmb);
10793 * lpfc_sli_host_down - Vport cleanup function
10794 * @vport: Pointer to virtual port object.
10796 * lpfc_sli_host_down is called to clean up the resources
10797 * associated with a vport before destroying virtual
10798 * port data structures.
10799 * This function does following operations:
10800 * - Free discovery resources associated with this virtual
10802 * - Free iocbs associated with this virtual port in
10804 * - Send abort for all iocb commands associated with this
10805 * vport in txcmplq.
10807 * This function is called with no lock held and always returns 1.
10810 lpfc_sli_host_down(struct lpfc_vport *vport)
10812 LIST_HEAD(completions);
10813 struct lpfc_hba *phba = vport->phba;
10814 struct lpfc_sli *psli = &phba->sli;
10815 struct lpfc_queue *qp = NULL;
10816 struct lpfc_sli_ring *pring;
10817 struct lpfc_iocbq *iocb, *next_iocb;
10819 unsigned long flags = 0;
10820 uint16_t prev_pring_flag;
10822 lpfc_cleanup_discovery_resources(vport);
10824 spin_lock_irqsave(&phba->hbalock, flags);
10827 * Error everything on the txq since these iocbs
10828 * have not been given to the FW yet.
10829 * Also issue ABTS for everything on the txcmplq
10831 if (phba->sli_rev != LPFC_SLI_REV4) {
10832 for (i = 0; i < psli->num_rings; i++) {
10833 pring = &psli->sli3_ring[i];
10834 prev_pring_flag = pring->flag;
10835 /* Only slow rings */
10836 if (pring->ringno == LPFC_ELS_RING) {
10837 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10838 /* Set the lpfc data pending flag */
10839 set_bit(LPFC_DATA_READY, &phba->data_flags);
10841 list_for_each_entry_safe(iocb, next_iocb,
10842 &pring->txq, list) {
10843 if (iocb->vport != vport)
10845 list_move_tail(&iocb->list, &completions);
10847 list_for_each_entry_safe(iocb, next_iocb,
10848 &pring->txcmplq, list) {
10849 if (iocb->vport != vport)
10851 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
10853 pring->flag = prev_pring_flag;
10856 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
10860 if (pring == phba->sli4_hba.els_wq->pring) {
10861 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10862 /* Set the lpfc data pending flag */
10863 set_bit(LPFC_DATA_READY, &phba->data_flags);
10865 prev_pring_flag = pring->flag;
10866 spin_lock(&pring->ring_lock);
10867 list_for_each_entry_safe(iocb, next_iocb,
10868 &pring->txq, list) {
10869 if (iocb->vport != vport)
10871 list_move_tail(&iocb->list, &completions);
10873 spin_unlock(&pring->ring_lock);
10874 list_for_each_entry_safe(iocb, next_iocb,
10875 &pring->txcmplq, list) {
10876 if (iocb->vport != vport)
10878 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
10880 pring->flag = prev_pring_flag;
10883 spin_unlock_irqrestore(&phba->hbalock, flags);
10885 /* Cancel all the IOCBs from the completions list */
10886 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10892 * lpfc_sli_hba_down - Resource cleanup function for the HBA
10893 * @phba: Pointer to HBA context object.
10895 * This function cleans up all iocb, buffers, mailbox commands
10896 * while shutting down the HBA. This function is called with no
10897 * lock held and always returns 1.
10898 * This function does the following to cleanup driver resources:
10899 * - Free discovery resources for each virtual port
10900 * - Cleanup any pending fabric iocbs
10901 * - Iterate through the iocb txq and free each entry
10903 * - Free up any buffer posted to the HBA
10904 * - Free mailbox commands in the mailbox queue.
10907 lpfc_sli_hba_down(struct lpfc_hba *phba)
10909 LIST_HEAD(completions);
10910 struct lpfc_sli *psli = &phba->sli;
10911 struct lpfc_queue *qp = NULL;
10912 struct lpfc_sli_ring *pring;
10913 struct lpfc_dmabuf *buf_ptr;
10914 unsigned long flags = 0;
10917 /* Shutdown the mailbox command sub-system */
10918 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
10920 lpfc_hba_down_prep(phba);
10922 /* Disable softirqs, including timers from obtaining phba->hbalock */
10923 local_bh_disable();
10925 lpfc_fabric_abort_hba(phba);
10927 spin_lock_irqsave(&phba->hbalock, flags);
10930 * Error everything on the txq since these iocbs
10931 * have not been given to the FW yet.
10933 if (phba->sli_rev != LPFC_SLI_REV4) {
10934 for (i = 0; i < psli->num_rings; i++) {
10935 pring = &psli->sli3_ring[i];
10936 /* Only slow rings */
10937 if (pring->ringno == LPFC_ELS_RING) {
10938 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10939 /* Set the lpfc data pending flag */
10940 set_bit(LPFC_DATA_READY, &phba->data_flags);
10942 list_splice_init(&pring->txq, &completions);
10945 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
10949 spin_lock(&pring->ring_lock);
10950 list_splice_init(&pring->txq, &completions);
10951 spin_unlock(&pring->ring_lock);
10952 if (pring == phba->sli4_hba.els_wq->pring) {
10953 pring->flag |= LPFC_DEFERRED_RING_EVENT;
10954 /* Set the lpfc data pending flag */
10955 set_bit(LPFC_DATA_READY, &phba->data_flags);
10959 spin_unlock_irqrestore(&phba->hbalock, flags);
10961 /* Cancel all the IOCBs from the completions list */
10962 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10965 spin_lock_irqsave(&phba->hbalock, flags);
10966 list_splice_init(&phba->elsbuf, &completions);
10967 phba->elsbuf_cnt = 0;
10968 phba->elsbuf_prev_cnt = 0;
10969 spin_unlock_irqrestore(&phba->hbalock, flags);
10971 while (!list_empty(&completions)) {
10972 list_remove_head(&completions, buf_ptr,
10973 struct lpfc_dmabuf, list);
10974 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
10978 /* Enable softirqs again, done with phba->hbalock */
10981 /* Return any active mbox cmds */
10982 del_timer_sync(&psli->mbox_tmo);
10984 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
10985 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
10986 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
10992 * lpfc_sli_pcimem_bcopy - SLI memory copy function
10993 * @srcp: Source memory pointer.
10994 * @destp: Destination memory pointer.
10995 * @cnt: Number of words required to be copied.
10997 * This function is used for copying data between driver memory
10998 * and the SLI memory. This function also changes the endianness
10999 * of each word if native endianness is different from SLI
11000 * endianness. This function can be called with or without
11004 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
11006 uint32_t *src = srcp;
11007 uint32_t *dest = destp;
11011 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
11013 ldata = le32_to_cpu(ldata);
11022 * lpfc_sli_bemem_bcopy - SLI memory copy function
11023 * @srcp: Source memory pointer.
11024 * @destp: Destination memory pointer.
11025 * @cnt: Number of words required to be copied.
11027 * This function is used for copying data between a data structure
11028 * with big endian representation to local endianness.
11029 * This function can be called with or without lock.
11032 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
11034 uint32_t *src = srcp;
11035 uint32_t *dest = destp;
11039 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
11041 ldata = be32_to_cpu(ldata);
11049 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
11050 * @phba: Pointer to HBA context object.
11051 * @pring: Pointer to driver SLI ring object.
11052 * @mp: Pointer to driver buffer object.
11054 * This function is called with no lock held.
11055 * It always return zero after adding the buffer to the postbufq
11059 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11060 struct lpfc_dmabuf *mp)
11062 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
11064 spin_lock_irq(&phba->hbalock);
11065 list_add_tail(&mp->list, &pring->postbufq);
11066 pring->postbufq_cnt++;
11067 spin_unlock_irq(&phba->hbalock);
11072 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
11073 * @phba: Pointer to HBA context object.
11075 * When HBQ is enabled, buffers are searched based on tags. This function
11076 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
11077 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
11078 * does not conflict with tags of buffer posted for unsolicited events.
11079 * The function returns the allocated tag. The function is called with
11083 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
11085 spin_lock_irq(&phba->hbalock);
11086 phba->buffer_tag_count++;
11088 * Always set the QUE_BUFTAG_BIT to distiguish between
11089 * a tag assigned by HBQ.
11091 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
11092 spin_unlock_irq(&phba->hbalock);
11093 return phba->buffer_tag_count;
11097 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
11098 * @phba: Pointer to HBA context object.
11099 * @pring: Pointer to driver SLI ring object.
11100 * @tag: Buffer tag.
11102 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
11103 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
11104 * iocb is posted to the response ring with the tag of the buffer.
11105 * This function searches the pring->postbufq list using the tag
11106 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
11107 * iocb. If the buffer is found then lpfc_dmabuf object of the
11108 * buffer is returned to the caller else NULL is returned.
11109 * This function is called with no lock held.
11111 struct lpfc_dmabuf *
11112 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11115 struct lpfc_dmabuf *mp, *next_mp;
11116 struct list_head *slp = &pring->postbufq;
11118 /* Search postbufq, from the beginning, looking for a match on tag */
11119 spin_lock_irq(&phba->hbalock);
11120 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
11121 if (mp->buffer_tag == tag) {
11122 list_del_init(&mp->list);
11123 pring->postbufq_cnt--;
11124 spin_unlock_irq(&phba->hbalock);
11129 spin_unlock_irq(&phba->hbalock);
11130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11131 "0402 Cannot find virtual addr for buffer tag on "
11132 "ring %d Data x%lx x%px x%px x%x\n",
11133 pring->ringno, (unsigned long) tag,
11134 slp->next, slp->prev, pring->postbufq_cnt);
11140 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
11141 * @phba: Pointer to HBA context object.
11142 * @pring: Pointer to driver SLI ring object.
11143 * @phys: DMA address of the buffer.
11145 * This function searches the buffer list using the dma_address
11146 * of unsolicited event to find the driver's lpfc_dmabuf object
11147 * corresponding to the dma_address. The function returns the
11148 * lpfc_dmabuf object if a buffer is found else it returns NULL.
11149 * This function is called by the ct and els unsolicited event
11150 * handlers to get the buffer associated with the unsolicited
11153 * This function is called with no lock held.
11155 struct lpfc_dmabuf *
11156 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11159 struct lpfc_dmabuf *mp, *next_mp;
11160 struct list_head *slp = &pring->postbufq;
11162 /* Search postbufq, from the beginning, looking for a match on phys */
11163 spin_lock_irq(&phba->hbalock);
11164 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
11165 if (mp->phys == phys) {
11166 list_del_init(&mp->list);
11167 pring->postbufq_cnt--;
11168 spin_unlock_irq(&phba->hbalock);
11173 spin_unlock_irq(&phba->hbalock);
11174 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11175 "0410 Cannot find virtual addr for mapped buf on "
11176 "ring %d Data x%llx x%px x%px x%x\n",
11177 pring->ringno, (unsigned long long)phys,
11178 slp->next, slp->prev, pring->postbufq_cnt);
11183 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
11184 * @phba: Pointer to HBA context object.
11185 * @cmdiocb: Pointer to driver command iocb object.
11186 * @rspiocb: Pointer to driver response iocb object.
11188 * This function is the completion handler for the abort iocbs for
11189 * ELS commands. This function is called from the ELS ring event
11190 * handler with no lock held. This function frees memory resources
11191 * associated with the abort iocb.
11194 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11195 struct lpfc_iocbq *rspiocb)
11197 IOCB_t *irsp = &rspiocb->iocb;
11198 uint16_t abort_iotag, abort_context;
11199 struct lpfc_iocbq *abort_iocb = NULL;
11201 if (irsp->ulpStatus) {
11204 * Assume that the port already completed and returned, or
11205 * will return the iocb. Just Log the message.
11207 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
11208 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
11210 spin_lock_irq(&phba->hbalock);
11211 if (phba->sli_rev < LPFC_SLI_REV4) {
11212 if (irsp->ulpCommand == CMD_ABORT_XRI_CX &&
11213 irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
11214 irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) {
11215 spin_unlock_irq(&phba->hbalock);
11218 if (abort_iotag != 0 &&
11219 abort_iotag <= phba->sli.last_iotag)
11221 phba->sli.iocbq_lookup[abort_iotag];
11223 /* For sli4 the abort_tag is the XRI,
11224 * so the abort routine puts the iotag of the iocb
11225 * being aborted in the context field of the abort
11228 abort_iocb = phba->sli.iocbq_lookup[abort_context];
11230 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
11231 "0327 Cannot abort els iocb x%px "
11232 "with tag %x context %x, abort status %x, "
11234 abort_iocb, abort_iotag, abort_context,
11235 irsp->ulpStatus, irsp->un.ulpWord[4]);
11237 spin_unlock_irq(&phba->hbalock);
11240 lpfc_sli_release_iocbq(phba, cmdiocb);
11245 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
11246 * @phba: Pointer to HBA context object.
11247 * @cmdiocb: Pointer to driver command iocb object.
11248 * @rspiocb: Pointer to driver response iocb object.
11250 * The function is called from SLI ring event handler with no
11251 * lock held. This function is the completion handler for ELS commands
11252 * which are aborted. The function frees memory resources used for
11253 * the aborted ELS commands.
11256 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11257 struct lpfc_iocbq *rspiocb)
11259 IOCB_t *irsp = &rspiocb->iocb;
11261 /* ELS cmd tag <ulpIoTag> completes */
11262 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
11263 "0139 Ignoring ELS cmd tag x%x completion Data: "
11265 irsp->ulpIoTag, irsp->ulpStatus,
11266 irsp->un.ulpWord[4], irsp->ulpTimeout);
11267 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
11268 lpfc_ct_free_iocb(phba, cmdiocb);
11270 lpfc_els_free_iocb(phba, cmdiocb);
11275 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
11276 * @phba: Pointer to HBA context object.
11277 * @pring: Pointer to driver SLI ring object.
11278 * @cmdiocb: Pointer to driver command iocb object.
11280 * This function issues an abort iocb for the provided command iocb down to
11281 * the port. Other than the case the outstanding command iocb is an abort
11282 * request, this function issues abort out unconditionally. This function is
11283 * called with hbalock held. The function returns 0 when it fails due to
11284 * memory allocation failure or when the command iocb is an abort request.
11285 * The hbalock is asserted held in the code path calling this routine.
11288 lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11289 struct lpfc_iocbq *cmdiocb)
11291 struct lpfc_vport *vport = cmdiocb->vport;
11292 struct lpfc_iocbq *abtsiocbp;
11293 IOCB_t *icmd = NULL;
11294 IOCB_t *iabt = NULL;
11296 unsigned long iflags;
11297 struct lpfc_nodelist *ndlp;
11300 * There are certain command types we don't want to abort. And we
11301 * don't want to abort commands that are already in the process of
11304 icmd = &cmdiocb->iocb;
11305 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
11306 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
11307 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
11310 /* issue ABTS for this IOCB based on iotag */
11311 abtsiocbp = __lpfc_sli_get_iocbq(phba);
11312 if (abtsiocbp == NULL)
11315 /* This signals the response to set the correct status
11316 * before calling the completion handler
11318 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
11320 iabt = &abtsiocbp->iocb;
11321 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
11322 iabt->un.acxri.abortContextTag = icmd->ulpContext;
11323 if (phba->sli_rev == LPFC_SLI_REV4) {
11324 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
11325 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
11327 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
11328 if (pring->ringno == LPFC_ELS_RING) {
11329 ndlp = (struct lpfc_nodelist *)(cmdiocb->context1);
11330 iabt->un.acxri.abortContextTag = ndlp->nlp_rpi;
11334 iabt->ulpClass = icmd->ulpClass;
11336 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11337 abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
11338 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
11339 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
11340 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
11341 abtsiocbp->iocb_flag |= LPFC_IO_FOF;
11343 if (phba->link_state >= LPFC_LINK_UP)
11344 iabt->ulpCommand = CMD_ABORT_XRI_CN;
11346 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
11348 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
11349 abtsiocbp->vport = vport;
11351 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
11352 "0339 Abort xri x%x, original iotag x%x, "
11353 "abort cmd iotag x%x\n",
11354 iabt->un.acxri.abortIoTag,
11355 iabt->un.acxri.abortContextTag,
11358 if (phba->sli_rev == LPFC_SLI_REV4) {
11359 pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
11360 if (unlikely(pring == NULL))
11362 /* Note: both hbalock and ring_lock need to be set here */
11363 spin_lock_irqsave(&pring->ring_lock, iflags);
11364 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
11366 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11368 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
11373 __lpfc_sli_release_iocbq(phba, abtsiocbp);
11376 * Caller to this routine should check for IOCB_ERROR
11377 * and handle it properly. This routine no longer removes
11378 * iocb off txcmplq and call compl in case of IOCB_ERROR.
11384 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
11385 * @phba: Pointer to HBA context object.
11386 * @pring: Pointer to driver SLI ring object.
11387 * @cmdiocb: Pointer to driver command iocb object.
11389 * This function issues an abort iocb for the provided command iocb. In case
11390 * of unloading, the abort iocb will not be issued to commands on the ELS
11391 * ring. Instead, the callback function shall be changed to those commands
11392 * so that nothing happens when them finishes. This function is called with
11393 * hbalock held. The function returns 0 when the command iocb is an abort
11397 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11398 struct lpfc_iocbq *cmdiocb)
11400 struct lpfc_vport *vport = cmdiocb->vport;
11401 int retval = IOCB_ERROR;
11402 IOCB_t *icmd = NULL;
11404 lockdep_assert_held(&phba->hbalock);
11407 * There are certain command types we don't want to abort. And we
11408 * don't want to abort commands that are already in the process of
11411 icmd = &cmdiocb->iocb;
11412 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
11413 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
11414 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
11418 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
11419 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
11421 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
11422 goto abort_iotag_exit;
11426 * If we're unloading, don't abort iocb on the ELS ring, but change
11427 * the callback so that nothing happens when it finishes.
11429 if ((vport->load_flag & FC_UNLOADING) &&
11430 (pring->ringno == LPFC_ELS_RING)) {
11431 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
11432 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
11434 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
11435 goto abort_iotag_exit;
11438 /* Now, we try to issue the abort to the cmdiocb out */
11439 retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb);
11443 * Caller to this routine should check for IOCB_ERROR
11444 * and handle it properly. This routine no longer removes
11445 * iocb off txcmplq and call compl in case of IOCB_ERROR.
11451 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
11452 * @phba: pointer to lpfc HBA data structure.
11454 * This routine will abort all pending and outstanding iocbs to an HBA.
11457 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
11459 struct lpfc_sli *psli = &phba->sli;
11460 struct lpfc_sli_ring *pring;
11461 struct lpfc_queue *qp = NULL;
11464 if (phba->sli_rev != LPFC_SLI_REV4) {
11465 for (i = 0; i < psli->num_rings; i++) {
11466 pring = &psli->sli3_ring[i];
11467 lpfc_sli_abort_iocb_ring(phba, pring);
11471 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11475 lpfc_sli_abort_iocb_ring(phba, pring);
11480 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
11481 * @iocbq: Pointer to driver iocb object.
11482 * @vport: Pointer to driver virtual port object.
11483 * @tgt_id: SCSI ID of the target.
11484 * @lun_id: LUN ID of the scsi device.
11485 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
11487 * This function acts as an iocb filter for functions which abort or count
11488 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
11489 * 0 if the filtering criteria is met for the given iocb and will return
11490 * 1 if the filtering criteria is not met.
11491 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
11492 * given iocb is for the SCSI device specified by vport, tgt_id and
11493 * lun_id parameter.
11494 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
11495 * given iocb is for the SCSI target specified by vport and tgt_id
11497 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
11498 * given iocb is for the SCSI host associated with the given vport.
11499 * This function is called with no locks held.
11502 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
11503 uint16_t tgt_id, uint64_t lun_id,
11504 lpfc_ctx_cmd ctx_cmd)
11506 struct lpfc_io_buf *lpfc_cmd;
11509 if (iocbq->vport != vport)
11512 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
11513 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ))
11516 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
11518 if (lpfc_cmd->pCmd == NULL)
11523 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
11524 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
11525 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
11529 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
11530 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
11533 case LPFC_CTX_HOST:
11537 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
11538 __func__, ctx_cmd);
11546 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
11547 * @vport: Pointer to virtual port.
11548 * @tgt_id: SCSI ID of the target.
11549 * @lun_id: LUN ID of the scsi device.
11550 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11552 * This function returns number of FCP commands pending for the vport.
11553 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
11554 * commands pending on the vport associated with SCSI device specified
11555 * by tgt_id and lun_id parameters.
11556 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
11557 * commands pending on the vport associated with SCSI target specified
11558 * by tgt_id parameter.
11559 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
11560 * commands pending on the vport.
11561 * This function returns the number of iocbs which satisfy the filter.
11562 * This function is called without any lock held.
11565 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
11566 lpfc_ctx_cmd ctx_cmd)
11568 struct lpfc_hba *phba = vport->phba;
11569 struct lpfc_iocbq *iocbq;
11572 spin_lock_irq(&phba->hbalock);
11573 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
11574 iocbq = phba->sli.iocbq_lookup[i];
11576 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
11580 spin_unlock_irq(&phba->hbalock);
11586 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
11587 * @phba: Pointer to HBA context object
11588 * @cmdiocb: Pointer to command iocb object.
11589 * @rspiocb: Pointer to response iocb object.
11591 * This function is called when an aborted FCP iocb completes. This
11592 * function is called by the ring event handler with no lock held.
11593 * This function frees the iocb.
11596 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11597 struct lpfc_iocbq *rspiocb)
11599 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11600 "3096 ABORT_XRI_CN completing on rpi x%x "
11601 "original iotag x%x, abort cmd iotag x%x "
11602 "status 0x%x, reason 0x%x\n",
11603 cmdiocb->iocb.un.acxri.abortContextTag,
11604 cmdiocb->iocb.un.acxri.abortIoTag,
11605 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
11606 rspiocb->iocb.un.ulpWord[4]);
11607 lpfc_sli_release_iocbq(phba, cmdiocb);
11612 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
11613 * @vport: Pointer to virtual port.
11614 * @pring: Pointer to driver SLI ring object.
11615 * @tgt_id: SCSI ID of the target.
11616 * @lun_id: LUN ID of the scsi device.
11617 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11619 * This function sends an abort command for every SCSI command
11620 * associated with the given virtual port pending on the ring
11621 * filtered by lpfc_sli_validate_fcp_iocb function.
11622 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
11623 * FCP iocbs associated with lun specified by tgt_id and lun_id
11625 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
11626 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11627 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
11628 * FCP iocbs associated with virtual port.
11629 * This function returns number of iocbs it failed to abort.
11630 * This function is called with no locks held.
11633 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
11634 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
11636 struct lpfc_hba *phba = vport->phba;
11637 struct lpfc_iocbq *iocbq;
11638 struct lpfc_iocbq *abtsiocb;
11639 struct lpfc_sli_ring *pring_s4;
11640 IOCB_t *cmd = NULL;
11641 int errcnt = 0, ret_val = 0;
11644 /* all I/Os are in process of being flushed */
11645 if (phba->hba_flag & HBA_IOQ_FLUSH)
11648 for (i = 1; i <= phba->sli.last_iotag; i++) {
11649 iocbq = phba->sli.iocbq_lookup[i];
11651 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
11656 * If the iocbq is already being aborted, don't take a second
11657 * action, but do count it.
11659 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED)
11662 /* issue ABTS for this IOCB based on iotag */
11663 abtsiocb = lpfc_sli_get_iocbq(phba);
11664 if (abtsiocb == NULL) {
11669 /* indicate the IO is being aborted by the driver. */
11670 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
11672 cmd = &iocbq->iocb;
11673 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
11674 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
11675 if (phba->sli_rev == LPFC_SLI_REV4)
11676 abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag;
11678 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
11679 abtsiocb->iocb.ulpLe = 1;
11680 abtsiocb->iocb.ulpClass = cmd->ulpClass;
11681 abtsiocb->vport = vport;
11683 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11684 abtsiocb->hba_wqidx = iocbq->hba_wqidx;
11685 if (iocbq->iocb_flag & LPFC_IO_FCP)
11686 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
11687 if (iocbq->iocb_flag & LPFC_IO_FOF)
11688 abtsiocb->iocb_flag |= LPFC_IO_FOF;
11690 if (lpfc_is_link_up(phba))
11691 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
11693 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
11695 /* Setup callback routine and issue the command. */
11696 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
11697 if (phba->sli_rev == LPFC_SLI_REV4) {
11698 pring_s4 = lpfc_sli4_calc_ring(phba, iocbq);
11701 ret_val = lpfc_sli_issue_iocb(phba, pring_s4->ringno,
11704 ret_val = lpfc_sli_issue_iocb(phba, pring->ringno,
11706 if (ret_val == IOCB_ERROR) {
11707 lpfc_sli_release_iocbq(phba, abtsiocb);
11717 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
11718 * @vport: Pointer to virtual port.
11719 * @pring: Pointer to driver SLI ring object.
11720 * @tgt_id: SCSI ID of the target.
11721 * @lun_id: LUN ID of the scsi device.
11722 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11724 * This function sends an abort command for every SCSI command
11725 * associated with the given virtual port pending on the ring
11726 * filtered by lpfc_sli_validate_fcp_iocb function.
11727 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
11728 * FCP iocbs associated with lun specified by tgt_id and lun_id
11730 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
11731 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11732 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
11733 * FCP iocbs associated with virtual port.
11734 * This function returns number of iocbs it aborted .
11735 * This function is called with no locks held right after a taskmgmt
11739 lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
11740 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
11742 struct lpfc_hba *phba = vport->phba;
11743 struct lpfc_io_buf *lpfc_cmd;
11744 struct lpfc_iocbq *abtsiocbq;
11745 struct lpfc_nodelist *ndlp;
11746 struct lpfc_iocbq *iocbq;
11748 int sum, i, ret_val;
11749 unsigned long iflags;
11750 struct lpfc_sli_ring *pring_s4 = NULL;
11752 spin_lock_irqsave(&phba->hbalock, iflags);
11754 /* all I/Os are in process of being flushed */
11755 if (phba->hba_flag & HBA_IOQ_FLUSH) {
11756 spin_unlock_irqrestore(&phba->hbalock, iflags);
11761 for (i = 1; i <= phba->sli.last_iotag; i++) {
11762 iocbq = phba->sli.iocbq_lookup[i];
11764 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
11768 /* Guard against IO completion being called at same time */
11769 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
11770 spin_lock(&lpfc_cmd->buf_lock);
11772 if (!lpfc_cmd->pCmd) {
11773 spin_unlock(&lpfc_cmd->buf_lock);
11777 if (phba->sli_rev == LPFC_SLI_REV4) {
11779 phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
11781 spin_unlock(&lpfc_cmd->buf_lock);
11784 /* Note: both hbalock and ring_lock must be set here */
11785 spin_lock(&pring_s4->ring_lock);
11789 * If the iocbq is already being aborted, don't take a second
11790 * action, but do count it.
11792 if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) ||
11793 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
11794 if (phba->sli_rev == LPFC_SLI_REV4)
11795 spin_unlock(&pring_s4->ring_lock);
11796 spin_unlock(&lpfc_cmd->buf_lock);
11800 /* issue ABTS for this IOCB based on iotag */
11801 abtsiocbq = __lpfc_sli_get_iocbq(phba);
11803 if (phba->sli_rev == LPFC_SLI_REV4)
11804 spin_unlock(&pring_s4->ring_lock);
11805 spin_unlock(&lpfc_cmd->buf_lock);
11809 icmd = &iocbq->iocb;
11810 abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
11811 abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
11812 if (phba->sli_rev == LPFC_SLI_REV4)
11813 abtsiocbq->iocb.un.acxri.abortIoTag =
11814 iocbq->sli4_xritag;
11816 abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
11817 abtsiocbq->iocb.ulpLe = 1;
11818 abtsiocbq->iocb.ulpClass = icmd->ulpClass;
11819 abtsiocbq->vport = vport;
11821 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11822 abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
11823 if (iocbq->iocb_flag & LPFC_IO_FCP)
11824 abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
11825 if (iocbq->iocb_flag & LPFC_IO_FOF)
11826 abtsiocbq->iocb_flag |= LPFC_IO_FOF;
11828 ndlp = lpfc_cmd->rdata->pnode;
11830 if (lpfc_is_link_up(phba) &&
11831 (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
11832 abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
11834 abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
11836 /* Setup callback routine and issue the command. */
11837 abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
11840 * Indicate the IO is being aborted by the driver and set
11841 * the caller's flag into the aborted IO.
11843 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
11845 if (phba->sli_rev == LPFC_SLI_REV4) {
11846 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
11848 spin_unlock(&pring_s4->ring_lock);
11850 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
11854 spin_unlock(&lpfc_cmd->buf_lock);
11856 if (ret_val == IOCB_ERROR)
11857 __lpfc_sli_release_iocbq(phba, abtsiocbq);
11861 spin_unlock_irqrestore(&phba->hbalock, iflags);
11866 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
11867 * @phba: Pointer to HBA context object.
11868 * @cmdiocbq: Pointer to command iocb.
11869 * @rspiocbq: Pointer to response iocb.
11871 * This function is the completion handler for iocbs issued using
11872 * lpfc_sli_issue_iocb_wait function. This function is called by the
11873 * ring event handler function without any lock held. This function
11874 * can be called from both worker thread context and interrupt
11875 * context. This function also can be called from other thread which
11876 * cleans up the SLI layer objects.
11877 * This function copy the contents of the response iocb to the
11878 * response iocb memory object provided by the caller of
11879 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
11880 * sleeps for the iocb completion.
11883 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
11884 struct lpfc_iocbq *cmdiocbq,
11885 struct lpfc_iocbq *rspiocbq)
11887 wait_queue_head_t *pdone_q;
11888 unsigned long iflags;
11889 struct lpfc_io_buf *lpfc_cmd;
11891 spin_lock_irqsave(&phba->hbalock, iflags);
11892 if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
11895 * A time out has occurred for the iocb. If a time out
11896 * completion handler has been supplied, call it. Otherwise,
11897 * just free the iocbq.
11900 spin_unlock_irqrestore(&phba->hbalock, iflags);
11901 cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
11902 cmdiocbq->wait_iocb_cmpl = NULL;
11903 if (cmdiocbq->iocb_cmpl)
11904 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
11906 lpfc_sli_release_iocbq(phba, cmdiocbq);
11910 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
11911 if (cmdiocbq->context2 && rspiocbq)
11912 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
11913 &rspiocbq->iocb, sizeof(IOCB_t));
11915 /* Set the exchange busy flag for task management commands */
11916 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
11917 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
11918 lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
11920 if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY))
11921 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
11923 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
11926 pdone_q = cmdiocbq->context_un.wait_queue;
11929 spin_unlock_irqrestore(&phba->hbalock, iflags);
11934 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
11935 * @phba: Pointer to HBA context object..
11936 * @piocbq: Pointer to command iocb.
11937 * @flag: Flag to test.
11939 * This routine grabs the hbalock and then test the iocb_flag to
11940 * see if the passed in flag is set.
11942 * 1 if flag is set.
11943 * 0 if flag is not set.
11946 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
11947 struct lpfc_iocbq *piocbq, uint32_t flag)
11949 unsigned long iflags;
11952 spin_lock_irqsave(&phba->hbalock, iflags);
11953 ret = piocbq->iocb_flag & flag;
11954 spin_unlock_irqrestore(&phba->hbalock, iflags);
11960 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
11961 * @phba: Pointer to HBA context object..
11962 * @pring: Pointer to sli ring.
11963 * @piocb: Pointer to command iocb.
11964 * @prspiocbq: Pointer to response iocb.
11965 * @timeout: Timeout in number of seconds.
11967 * This function issues the iocb to firmware and waits for the
11968 * iocb to complete. The iocb_cmpl field of the shall be used
11969 * to handle iocbs which time out. If the field is NULL, the
11970 * function shall free the iocbq structure. If more clean up is
11971 * needed, the caller is expected to provide a completion function
11972 * that will provide the needed clean up. If the iocb command is
11973 * not completed within timeout seconds, the function will either
11974 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
11975 * completion function set in the iocb_cmpl field and then return
11976 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
11977 * resources if this function returns IOCB_TIMEDOUT.
11978 * The function waits for the iocb completion using an
11979 * non-interruptible wait.
11980 * This function will sleep while waiting for iocb completion.
11981 * So, this function should not be called from any context which
11982 * does not allow sleeping. Due to the same reason, this function
11983 * cannot be called with interrupt disabled.
11984 * This function assumes that the iocb completions occur while
11985 * this function sleep. So, this function cannot be called from
11986 * the thread which process iocb completion for this ring.
11987 * This function clears the iocb_flag of the iocb object before
11988 * issuing the iocb and the iocb completion handler sets this
11989 * flag and wakes this thread when the iocb completes.
11990 * The contents of the response iocb will be copied to prspiocbq
11991 * by the completion handler when the command completes.
11992 * This function returns IOCB_SUCCESS when success.
11993 * This function is called with no lock held.
11996 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
11997 uint32_t ring_number,
11998 struct lpfc_iocbq *piocb,
11999 struct lpfc_iocbq *prspiocbq,
12002 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
12003 long timeleft, timeout_req = 0;
12004 int retval = IOCB_SUCCESS;
12006 struct lpfc_iocbq *iocb;
12008 int txcmplq_cnt = 0;
12009 struct lpfc_sli_ring *pring;
12010 unsigned long iflags;
12011 bool iocb_completed = true;
12013 if (phba->sli_rev >= LPFC_SLI_REV4)
12014 pring = lpfc_sli4_calc_ring(phba, piocb);
12016 pring = &phba->sli.sli3_ring[ring_number];
12018 * If the caller has provided a response iocbq buffer, then context2
12019 * is NULL or its an error.
12022 if (piocb->context2)
12024 piocb->context2 = prspiocbq;
12027 piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
12028 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
12029 piocb->context_un.wait_queue = &done_q;
12030 piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
12032 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
12033 if (lpfc_readl(phba->HCregaddr, &creg_val))
12035 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
12036 writel(creg_val, phba->HCregaddr);
12037 readl(phba->HCregaddr); /* flush */
12040 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
12041 SLI_IOCB_RET_IOCB);
12042 if (retval == IOCB_SUCCESS) {
12043 timeout_req = msecs_to_jiffies(timeout * 1000);
12044 timeleft = wait_event_timeout(done_q,
12045 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
12047 spin_lock_irqsave(&phba->hbalock, iflags);
12048 if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
12051 * IOCB timed out. Inform the wake iocb wait
12052 * completion function and set local status
12055 iocb_completed = false;
12056 piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
12058 spin_unlock_irqrestore(&phba->hbalock, iflags);
12059 if (iocb_completed) {
12060 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12061 "0331 IOCB wake signaled\n");
12062 /* Note: we are not indicating if the IOCB has a success
12063 * status or not - that's for the caller to check.
12064 * IOCB_SUCCESS means just that the command was sent and
12065 * completed. Not that it completed successfully.
12067 } else if (timeleft == 0) {
12068 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12069 "0338 IOCB wait timeout error - no "
12070 "wake response Data x%x\n", timeout);
12071 retval = IOCB_TIMEDOUT;
12073 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12074 "0330 IOCB wake NOT set, "
12076 timeout, (timeleft / jiffies));
12077 retval = IOCB_TIMEDOUT;
12079 } else if (retval == IOCB_BUSY) {
12080 if (phba->cfg_log_verbose & LOG_SLI) {
12081 list_for_each_entry(iocb, &pring->txq, list) {
12084 list_for_each_entry(iocb, &pring->txcmplq, list) {
12087 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12088 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
12089 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
12093 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12094 "0332 IOCB wait issue failed, Data x%x\n",
12096 retval = IOCB_ERROR;
12099 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
12100 if (lpfc_readl(phba->HCregaddr, &creg_val))
12102 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
12103 writel(creg_val, phba->HCregaddr);
12104 readl(phba->HCregaddr); /* flush */
12108 piocb->context2 = NULL;
12110 piocb->context_un.wait_queue = NULL;
12111 piocb->iocb_cmpl = NULL;
12116 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
12117 * @phba: Pointer to HBA context object.
12118 * @pmboxq: Pointer to driver mailbox object.
12119 * @timeout: Timeout in number of seconds.
12121 * This function issues the mailbox to firmware and waits for the
12122 * mailbox command to complete. If the mailbox command is not
12123 * completed within timeout seconds, it returns MBX_TIMEOUT.
12124 * The function waits for the mailbox completion using an
12125 * interruptible wait. If the thread is woken up due to a
12126 * signal, MBX_TIMEOUT error is returned to the caller. Caller
12127 * should not free the mailbox resources, if this function returns
12129 * This function will sleep while waiting for mailbox completion.
12130 * So, this function should not be called from any context which
12131 * does not allow sleeping. Due to the same reason, this function
12132 * cannot be called with interrupt disabled.
12133 * This function assumes that the mailbox completion occurs while
12134 * this function sleep. So, this function cannot be called from
12135 * the worker thread which processes mailbox completion.
12136 * This function is called in the context of HBA management
12138 * This function returns MBX_SUCCESS when successful.
12139 * This function is called with no lock held.
12142 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
12145 struct completion mbox_done;
12147 unsigned long flag;
12149 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
12150 /* setup wake call as IOCB callback */
12151 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
12153 /* setup context3 field to pass wait_queue pointer to wake function */
12154 init_completion(&mbox_done);
12155 pmboxq->context3 = &mbox_done;
12156 /* now issue the command */
12157 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
12158 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
12159 wait_for_completion_timeout(&mbox_done,
12160 msecs_to_jiffies(timeout * 1000));
12162 spin_lock_irqsave(&phba->hbalock, flag);
12163 pmboxq->context3 = NULL;
12165 * if LPFC_MBX_WAKE flag is set the mailbox is completed
12166 * else do not free the resources.
12168 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
12169 retval = MBX_SUCCESS;
12171 retval = MBX_TIMEOUT;
12172 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12174 spin_unlock_irqrestore(&phba->hbalock, flag);
12180 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
12181 * @phba: Pointer to HBA context.
12183 * This function is called to shutdown the driver's mailbox sub-system.
12184 * It first marks the mailbox sub-system is in a block state to prevent
12185 * the asynchronous mailbox command from issued off the pending mailbox
12186 * command queue. If the mailbox command sub-system shutdown is due to
12187 * HBA error conditions such as EEH or ERATT, this routine shall invoke
12188 * the mailbox sub-system flush routine to forcefully bring down the
12189 * mailbox sub-system. Otherwise, if it is due to normal condition (such
12190 * as with offline or HBA function reset), this routine will wait for the
12191 * outstanding mailbox command to complete before invoking the mailbox
12192 * sub-system flush routine to gracefully bring down mailbox sub-system.
12195 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
12197 struct lpfc_sli *psli = &phba->sli;
12198 unsigned long timeout;
12200 if (mbx_action == LPFC_MBX_NO_WAIT) {
12201 /* delay 100ms for port state */
12203 lpfc_sli_mbox_sys_flush(phba);
12206 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
12208 /* Disable softirqs, including timers from obtaining phba->hbalock */
12209 local_bh_disable();
12211 spin_lock_irq(&phba->hbalock);
12212 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
12214 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
12215 /* Determine how long we might wait for the active mailbox
12216 * command to be gracefully completed by firmware.
12218 if (phba->sli.mbox_active)
12219 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
12220 phba->sli.mbox_active) *
12222 spin_unlock_irq(&phba->hbalock);
12224 /* Enable softirqs again, done with phba->hbalock */
12227 while (phba->sli.mbox_active) {
12228 /* Check active mailbox complete status every 2ms */
12230 if (time_after(jiffies, timeout))
12231 /* Timeout, let the mailbox flush routine to
12232 * forcefully release active mailbox command
12237 spin_unlock_irq(&phba->hbalock);
12239 /* Enable softirqs again, done with phba->hbalock */
12243 lpfc_sli_mbox_sys_flush(phba);
12247 * lpfc_sli_eratt_read - read sli-3 error attention events
12248 * @phba: Pointer to HBA context.
12250 * This function is called to read the SLI3 device error attention registers
12251 * for possible error attention events. The caller must hold the hostlock
12252 * with spin_lock_irq().
12254 * This function returns 1 when there is Error Attention in the Host Attention
12255 * Register and returns 0 otherwise.
12258 lpfc_sli_eratt_read(struct lpfc_hba *phba)
12262 /* Read chip Host Attention (HA) register */
12263 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12266 if (ha_copy & HA_ERATT) {
12267 /* Read host status register to retrieve error event */
12268 if (lpfc_sli_read_hs(phba))
12271 /* Check if there is a deferred error condition is active */
12272 if ((HS_FFER1 & phba->work_hs) &&
12273 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
12274 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
12275 phba->hba_flag |= DEFER_ERATT;
12276 /* Clear all interrupt enable conditions */
12277 writel(0, phba->HCregaddr);
12278 readl(phba->HCregaddr);
12281 /* Set the driver HA work bitmap */
12282 phba->work_ha |= HA_ERATT;
12283 /* Indicate polling handles this ERATT */
12284 phba->hba_flag |= HBA_ERATT_HANDLED;
12290 /* Set the driver HS work bitmap */
12291 phba->work_hs |= UNPLUG_ERR;
12292 /* Set the driver HA work bitmap */
12293 phba->work_ha |= HA_ERATT;
12294 /* Indicate polling handles this ERATT */
12295 phba->hba_flag |= HBA_ERATT_HANDLED;
12300 * lpfc_sli4_eratt_read - read sli-4 error attention events
12301 * @phba: Pointer to HBA context.
12303 * This function is called to read the SLI4 device error attention registers
12304 * for possible error attention events. The caller must hold the hostlock
12305 * with spin_lock_irq().
12307 * This function returns 1 when there is Error Attention in the Host Attention
12308 * Register and returns 0 otherwise.
12311 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
12313 uint32_t uerr_sta_hi, uerr_sta_lo;
12314 uint32_t if_type, portsmphr;
12315 struct lpfc_register portstat_reg;
12318 * For now, use the SLI4 device internal unrecoverable error
12319 * registers for error attention. This can be changed later.
12321 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
12323 case LPFC_SLI_INTF_IF_TYPE_0:
12324 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
12326 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
12328 phba->work_hs |= UNPLUG_ERR;
12329 phba->work_ha |= HA_ERATT;
12330 phba->hba_flag |= HBA_ERATT_HANDLED;
12333 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
12334 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
12335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12336 "1423 HBA Unrecoverable error: "
12337 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
12338 "ue_mask_lo_reg=0x%x, "
12339 "ue_mask_hi_reg=0x%x\n",
12340 uerr_sta_lo, uerr_sta_hi,
12341 phba->sli4_hba.ue_mask_lo,
12342 phba->sli4_hba.ue_mask_hi);
12343 phba->work_status[0] = uerr_sta_lo;
12344 phba->work_status[1] = uerr_sta_hi;
12345 phba->work_ha |= HA_ERATT;
12346 phba->hba_flag |= HBA_ERATT_HANDLED;
12350 case LPFC_SLI_INTF_IF_TYPE_2:
12351 case LPFC_SLI_INTF_IF_TYPE_6:
12352 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
12353 &portstat_reg.word0) ||
12354 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
12356 phba->work_hs |= UNPLUG_ERR;
12357 phba->work_ha |= HA_ERATT;
12358 phba->hba_flag |= HBA_ERATT_HANDLED;
12361 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
12362 phba->work_status[0] =
12363 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
12364 phba->work_status[1] =
12365 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
12366 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12367 "2885 Port Status Event: "
12368 "port status reg 0x%x, "
12369 "port smphr reg 0x%x, "
12370 "error 1=0x%x, error 2=0x%x\n",
12371 portstat_reg.word0,
12373 phba->work_status[0],
12374 phba->work_status[1]);
12375 phba->work_ha |= HA_ERATT;
12376 phba->hba_flag |= HBA_ERATT_HANDLED;
12380 case LPFC_SLI_INTF_IF_TYPE_1:
12382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12383 "2886 HBA Error Attention on unsupported "
12384 "if type %d.", if_type);
12392 * lpfc_sli_check_eratt - check error attention events
12393 * @phba: Pointer to HBA context.
12395 * This function is called from timer soft interrupt context to check HBA's
12396 * error attention register bit for error attention events.
12398 * This function returns 1 when there is Error Attention in the Host Attention
12399 * Register and returns 0 otherwise.
12402 lpfc_sli_check_eratt(struct lpfc_hba *phba)
12406 /* If somebody is waiting to handle an eratt, don't process it
12407 * here. The brdkill function will do this.
12409 if (phba->link_flag & LS_IGNORE_ERATT)
12412 /* Check if interrupt handler handles this ERATT */
12413 spin_lock_irq(&phba->hbalock);
12414 if (phba->hba_flag & HBA_ERATT_HANDLED) {
12415 /* Interrupt handler has handled ERATT */
12416 spin_unlock_irq(&phba->hbalock);
12421 * If there is deferred error attention, do not check for error
12424 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12425 spin_unlock_irq(&phba->hbalock);
12429 /* If PCI channel is offline, don't process it */
12430 if (unlikely(pci_channel_offline(phba->pcidev))) {
12431 spin_unlock_irq(&phba->hbalock);
12435 switch (phba->sli_rev) {
12436 case LPFC_SLI_REV2:
12437 case LPFC_SLI_REV3:
12438 /* Read chip Host Attention (HA) register */
12439 ha_copy = lpfc_sli_eratt_read(phba);
12441 case LPFC_SLI_REV4:
12442 /* Read device Uncoverable Error (UERR) registers */
12443 ha_copy = lpfc_sli4_eratt_read(phba);
12446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12447 "0299 Invalid SLI revision (%d)\n",
12452 spin_unlock_irq(&phba->hbalock);
12458 * lpfc_intr_state_check - Check device state for interrupt handling
12459 * @phba: Pointer to HBA context.
12461 * This inline routine checks whether a device or its PCI slot is in a state
12462 * that the interrupt should be handled.
12464 * This function returns 0 if the device or the PCI slot is in a state that
12465 * interrupt should be handled, otherwise -EIO.
12468 lpfc_intr_state_check(struct lpfc_hba *phba)
12470 /* If the pci channel is offline, ignore all the interrupts */
12471 if (unlikely(pci_channel_offline(phba->pcidev)))
12474 /* Update device level interrupt statistics */
12475 phba->sli.slistat.sli_intr++;
12477 /* Ignore all interrupts during initialization. */
12478 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
12485 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
12486 * @irq: Interrupt number.
12487 * @dev_id: The device context pointer.
12489 * This function is directly called from the PCI layer as an interrupt
12490 * service routine when device with SLI-3 interface spec is enabled with
12491 * MSI-X multi-message interrupt mode and there are slow-path events in
12492 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
12493 * interrupt mode, this function is called as part of the device-level
12494 * interrupt handler. When the PCI slot is in error recovery or the HBA
12495 * is undergoing initialization, the interrupt handler will not process
12496 * the interrupt. The link attention and ELS ring attention events are
12497 * handled by the worker thread. The interrupt handler signals the worker
12498 * thread and returns for these events. This function is called without
12499 * any lock held. It gets the hbalock to access and update SLI data
12502 * This function returns IRQ_HANDLED when interrupt is handled else it
12503 * returns IRQ_NONE.
12506 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
12508 struct lpfc_hba *phba;
12509 uint32_t ha_copy, hc_copy;
12510 uint32_t work_ha_copy;
12511 unsigned long status;
12512 unsigned long iflag;
12515 MAILBOX_t *mbox, *pmbox;
12516 struct lpfc_vport *vport;
12517 struct lpfc_nodelist *ndlp;
12518 struct lpfc_dmabuf *mp;
12523 * Get the driver's phba structure from the dev_id and
12524 * assume the HBA is not interrupting.
12526 phba = (struct lpfc_hba *)dev_id;
12528 if (unlikely(!phba))
12532 * Stuff needs to be attented to when this function is invoked as an
12533 * individual interrupt handler in MSI-X multi-message interrupt mode
12535 if (phba->intr_type == MSIX) {
12536 /* Check device state for handling interrupt */
12537 if (lpfc_intr_state_check(phba))
12539 /* Need to read HA REG for slow-path events */
12540 spin_lock_irqsave(&phba->hbalock, iflag);
12541 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12543 /* If somebody is waiting to handle an eratt don't process it
12544 * here. The brdkill function will do this.
12546 if (phba->link_flag & LS_IGNORE_ERATT)
12547 ha_copy &= ~HA_ERATT;
12548 /* Check the need for handling ERATT in interrupt handler */
12549 if (ha_copy & HA_ERATT) {
12550 if (phba->hba_flag & HBA_ERATT_HANDLED)
12551 /* ERATT polling has handled ERATT */
12552 ha_copy &= ~HA_ERATT;
12554 /* Indicate interrupt handler handles ERATT */
12555 phba->hba_flag |= HBA_ERATT_HANDLED;
12559 * If there is deferred error attention, do not check for any
12562 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12563 spin_unlock_irqrestore(&phba->hbalock, iflag);
12567 /* Clear up only attention source related to slow-path */
12568 if (lpfc_readl(phba->HCregaddr, &hc_copy))
12571 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
12572 HC_LAINT_ENA | HC_ERINT_ENA),
12574 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
12576 writel(hc_copy, phba->HCregaddr);
12577 readl(phba->HAregaddr); /* flush */
12578 spin_unlock_irqrestore(&phba->hbalock, iflag);
12580 ha_copy = phba->ha_copy;
12582 work_ha_copy = ha_copy & phba->work_ha_mask;
12584 if (work_ha_copy) {
12585 if (work_ha_copy & HA_LATT) {
12586 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
12588 * Turn off Link Attention interrupts
12589 * until CLEAR_LA done
12591 spin_lock_irqsave(&phba->hbalock, iflag);
12592 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
12593 if (lpfc_readl(phba->HCregaddr, &control))
12595 control &= ~HC_LAINT_ENA;
12596 writel(control, phba->HCregaddr);
12597 readl(phba->HCregaddr); /* flush */
12598 spin_unlock_irqrestore(&phba->hbalock, iflag);
12601 work_ha_copy &= ~HA_LATT;
12604 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
12606 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
12607 * the only slow ring.
12609 status = (work_ha_copy &
12610 (HA_RXMASK << (4*LPFC_ELS_RING)));
12611 status >>= (4*LPFC_ELS_RING);
12612 if (status & HA_RXMASK) {
12613 spin_lock_irqsave(&phba->hbalock, iflag);
12614 if (lpfc_readl(phba->HCregaddr, &control))
12617 lpfc_debugfs_slow_ring_trc(phba,
12618 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
12620 (uint32_t)phba->sli.slistat.sli_intr);
12622 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
12623 lpfc_debugfs_slow_ring_trc(phba,
12624 "ISR Disable ring:"
12625 "pwork:x%x hawork:x%x wait:x%x",
12626 phba->work_ha, work_ha_copy,
12627 (uint32_t)((unsigned long)
12628 &phba->work_waitq));
12631 ~(HC_R0INT_ENA << LPFC_ELS_RING);
12632 writel(control, phba->HCregaddr);
12633 readl(phba->HCregaddr); /* flush */
12636 lpfc_debugfs_slow_ring_trc(phba,
12637 "ISR slow ring: pwork:"
12638 "x%x hawork:x%x wait:x%x",
12639 phba->work_ha, work_ha_copy,
12640 (uint32_t)((unsigned long)
12641 &phba->work_waitq));
12643 spin_unlock_irqrestore(&phba->hbalock, iflag);
12646 spin_lock_irqsave(&phba->hbalock, iflag);
12647 if (work_ha_copy & HA_ERATT) {
12648 if (lpfc_sli_read_hs(phba))
12651 * Check if there is a deferred error condition
12654 if ((HS_FFER1 & phba->work_hs) &&
12655 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
12656 HS_FFER6 | HS_FFER7 | HS_FFER8) &
12658 phba->hba_flag |= DEFER_ERATT;
12659 /* Clear all interrupt enable conditions */
12660 writel(0, phba->HCregaddr);
12661 readl(phba->HCregaddr);
12665 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
12666 pmb = phba->sli.mbox_active;
12667 pmbox = &pmb->u.mb;
12669 vport = pmb->vport;
12671 /* First check out the status word */
12672 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
12673 if (pmbox->mbxOwner != OWN_HOST) {
12674 spin_unlock_irqrestore(&phba->hbalock, iflag);
12676 * Stray Mailbox Interrupt, mbxCommand <cmd>
12677 * mbxStatus <status>
12679 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
12681 "(%d):0304 Stray Mailbox "
12682 "Interrupt mbxCommand x%x "
12684 (vport ? vport->vpi : 0),
12687 /* clear mailbox attention bit */
12688 work_ha_copy &= ~HA_MBATT;
12690 phba->sli.mbox_active = NULL;
12691 spin_unlock_irqrestore(&phba->hbalock, iflag);
12692 phba->last_completion_time = jiffies;
12693 del_timer(&phba->sli.mbox_tmo);
12694 if (pmb->mbox_cmpl) {
12695 lpfc_sli_pcimem_bcopy(mbox, pmbox,
12697 if (pmb->out_ext_byte_len &&
12699 lpfc_sli_pcimem_bcopy(
12702 pmb->out_ext_byte_len);
12704 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
12705 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
12707 lpfc_debugfs_disc_trc(vport,
12708 LPFC_DISC_TRC_MBOX_VPORT,
12709 "MBOX dflt rpi: : "
12710 "status:x%x rpi:x%x",
12711 (uint32_t)pmbox->mbxStatus,
12712 pmbox->un.varWords[0], 0);
12714 if (!pmbox->mbxStatus) {
12715 mp = (struct lpfc_dmabuf *)
12717 ndlp = (struct lpfc_nodelist *)
12720 /* Reg_LOGIN of dflt RPI was
12721 * successful. new lets get
12722 * rid of the RPI using the
12723 * same mbox buffer.
12725 lpfc_unreg_login(phba,
12727 pmbox->un.varWords[0],
12730 lpfc_mbx_cmpl_dflt_rpi;
12732 pmb->ctx_ndlp = ndlp;
12733 pmb->vport = vport;
12734 rc = lpfc_sli_issue_mbox(phba,
12737 if (rc != MBX_BUSY)
12738 lpfc_printf_log(phba,
12740 LOG_MBOX | LOG_SLI,
12741 "0350 rc should have"
12742 "been MBX_BUSY\n");
12743 if (rc != MBX_NOT_FINISHED)
12744 goto send_current_mbox;
12748 &phba->pport->work_port_lock,
12750 phba->pport->work_port_events &=
12752 spin_unlock_irqrestore(
12753 &phba->pport->work_port_lock,
12755 lpfc_mbox_cmpl_put(phba, pmb);
12758 spin_unlock_irqrestore(&phba->hbalock, iflag);
12760 if ((work_ha_copy & HA_MBATT) &&
12761 (phba->sli.mbox_active == NULL)) {
12763 /* Process next mailbox command if there is one */
12765 rc = lpfc_sli_issue_mbox(phba, NULL,
12767 } while (rc == MBX_NOT_FINISHED);
12768 if (rc != MBX_SUCCESS)
12769 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
12770 LOG_SLI, "0349 rc should be "
12774 spin_lock_irqsave(&phba->hbalock, iflag);
12775 phba->work_ha |= work_ha_copy;
12776 spin_unlock_irqrestore(&phba->hbalock, iflag);
12777 lpfc_worker_wake_up(phba);
12779 return IRQ_HANDLED;
12781 spin_unlock_irqrestore(&phba->hbalock, iflag);
12782 return IRQ_HANDLED;
12784 } /* lpfc_sli_sp_intr_handler */
12787 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
12788 * @irq: Interrupt number.
12789 * @dev_id: The device context pointer.
12791 * This function is directly called from the PCI layer as an interrupt
12792 * service routine when device with SLI-3 interface spec is enabled with
12793 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12794 * ring event in the HBA. However, when the device is enabled with either
12795 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12796 * device-level interrupt handler. When the PCI slot is in error recovery
12797 * or the HBA is undergoing initialization, the interrupt handler will not
12798 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12799 * the intrrupt context. This function is called without any lock held.
12800 * It gets the hbalock to access and update SLI data structures.
12802 * This function returns IRQ_HANDLED when interrupt is handled else it
12803 * returns IRQ_NONE.
12806 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
12808 struct lpfc_hba *phba;
12810 unsigned long status;
12811 unsigned long iflag;
12812 struct lpfc_sli_ring *pring;
12814 /* Get the driver's phba structure from the dev_id and
12815 * assume the HBA is not interrupting.
12817 phba = (struct lpfc_hba *) dev_id;
12819 if (unlikely(!phba))
12823 * Stuff needs to be attented to when this function is invoked as an
12824 * individual interrupt handler in MSI-X multi-message interrupt mode
12826 if (phba->intr_type == MSIX) {
12827 /* Check device state for handling interrupt */
12828 if (lpfc_intr_state_check(phba))
12830 /* Need to read HA REG for FCP ring and other ring events */
12831 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12832 return IRQ_HANDLED;
12833 /* Clear up only attention source related to fast-path */
12834 spin_lock_irqsave(&phba->hbalock, iflag);
12836 * If there is deferred error attention, do not check for
12839 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12840 spin_unlock_irqrestore(&phba->hbalock, iflag);
12843 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
12845 readl(phba->HAregaddr); /* flush */
12846 spin_unlock_irqrestore(&phba->hbalock, iflag);
12848 ha_copy = phba->ha_copy;
12851 * Process all events on FCP ring. Take the optimized path for FCP IO.
12853 ha_copy &= ~(phba->work_ha_mask);
12855 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
12856 status >>= (4*LPFC_FCP_RING);
12857 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
12858 if (status & HA_RXMASK)
12859 lpfc_sli_handle_fast_ring_event(phba, pring, status);
12861 if (phba->cfg_multi_ring_support == 2) {
12863 * Process all events on extra ring. Take the optimized path
12864 * for extra ring IO.
12866 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
12867 status >>= (4*LPFC_EXTRA_RING);
12868 if (status & HA_RXMASK) {
12869 lpfc_sli_handle_fast_ring_event(phba,
12870 &phba->sli.sli3_ring[LPFC_EXTRA_RING],
12874 return IRQ_HANDLED;
12875 } /* lpfc_sli_fp_intr_handler */
12878 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
12879 * @irq: Interrupt number.
12880 * @dev_id: The device context pointer.
12882 * This function is the HBA device-level interrupt handler to device with
12883 * SLI-3 interface spec, called from the PCI layer when either MSI or
12884 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
12885 * requires driver attention. This function invokes the slow-path interrupt
12886 * attention handling function and fast-path interrupt attention handling
12887 * function in turn to process the relevant HBA attention events. This
12888 * function is called without any lock held. It gets the hbalock to access
12889 * and update SLI data structures.
12891 * This function returns IRQ_HANDLED when interrupt is handled, else it
12892 * returns IRQ_NONE.
12895 lpfc_sli_intr_handler(int irq, void *dev_id)
12897 struct lpfc_hba *phba;
12898 irqreturn_t sp_irq_rc, fp_irq_rc;
12899 unsigned long status1, status2;
12903 * Get the driver's phba structure from the dev_id and
12904 * assume the HBA is not interrupting.
12906 phba = (struct lpfc_hba *) dev_id;
12908 if (unlikely(!phba))
12911 /* Check device state for handling interrupt */
12912 if (lpfc_intr_state_check(phba))
12915 spin_lock(&phba->hbalock);
12916 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
12917 spin_unlock(&phba->hbalock);
12918 return IRQ_HANDLED;
12921 if (unlikely(!phba->ha_copy)) {
12922 spin_unlock(&phba->hbalock);
12924 } else if (phba->ha_copy & HA_ERATT) {
12925 if (phba->hba_flag & HBA_ERATT_HANDLED)
12926 /* ERATT polling has handled ERATT */
12927 phba->ha_copy &= ~HA_ERATT;
12929 /* Indicate interrupt handler handles ERATT */
12930 phba->hba_flag |= HBA_ERATT_HANDLED;
12934 * If there is deferred error attention, do not check for any interrupt.
12936 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12937 spin_unlock(&phba->hbalock);
12941 /* Clear attention sources except link and error attentions */
12942 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
12943 spin_unlock(&phba->hbalock);
12944 return IRQ_HANDLED;
12946 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
12947 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
12949 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
12950 writel(hc_copy, phba->HCregaddr);
12951 readl(phba->HAregaddr); /* flush */
12952 spin_unlock(&phba->hbalock);
12955 * Invokes slow-path host attention interrupt handling as appropriate.
12958 /* status of events with mailbox and link attention */
12959 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
12961 /* status of events with ELS ring */
12962 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
12963 status2 >>= (4*LPFC_ELS_RING);
12965 if (status1 || (status2 & HA_RXMASK))
12966 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
12968 sp_irq_rc = IRQ_NONE;
12971 * Invoke fast-path host attention interrupt handling as appropriate.
12974 /* status of events with FCP ring */
12975 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
12976 status1 >>= (4*LPFC_FCP_RING);
12978 /* status of events with extra ring */
12979 if (phba->cfg_multi_ring_support == 2) {
12980 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
12981 status2 >>= (4*LPFC_EXTRA_RING);
12985 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
12986 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
12988 fp_irq_rc = IRQ_NONE;
12990 /* Return device-level interrupt handling status */
12991 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
12992 } /* lpfc_sli_intr_handler */
12995 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12996 * @phba: pointer to lpfc hba data structure.
12998 * This routine is invoked by the worker thread to process all the pending
12999 * SLI4 els abort xri events.
13001 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
13003 struct lpfc_cq_event *cq_event;
13005 /* First, declare the els xri abort event has been handled */
13006 spin_lock_irq(&phba->hbalock);
13007 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
13008 spin_unlock_irq(&phba->hbalock);
13009 /* Now, handle all the els xri abort events */
13010 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
13011 /* Get the first event from the head of the event queue */
13012 spin_lock_irq(&phba->hbalock);
13013 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
13014 cq_event, struct lpfc_cq_event, list);
13015 spin_unlock_irq(&phba->hbalock);
13016 /* Notify aborted XRI for ELS work queue */
13017 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
13018 /* Free the event processed back to the free pool */
13019 lpfc_sli4_cq_event_release(phba, cq_event);
13024 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
13025 * @phba: pointer to lpfc hba data structure
13026 * @pIocbIn: pointer to the rspiocbq
13027 * @pIocbOut: pointer to the cmdiocbq
13028 * @wcqe: pointer to the complete wcqe
13030 * This routine transfers the fields of a command iocbq to a response iocbq
13031 * by copying all the IOCB fields from command iocbq and transferring the
13032 * completion status information from the complete wcqe.
13035 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
13036 struct lpfc_iocbq *pIocbIn,
13037 struct lpfc_iocbq *pIocbOut,
13038 struct lpfc_wcqe_complete *wcqe)
13041 unsigned long iflags;
13042 uint32_t status, max_response;
13043 struct lpfc_dmabuf *dmabuf;
13044 struct ulp_bde64 *bpl, bde;
13045 size_t offset = offsetof(struct lpfc_iocbq, iocb);
13047 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
13048 sizeof(struct lpfc_iocbq) - offset);
13049 /* Map WCQE parameters into irspiocb parameters */
13050 status = bf_get(lpfc_wcqe_c_status, wcqe);
13051 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
13052 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
13053 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
13054 pIocbIn->iocb.un.fcpi.fcpi_parm =
13055 pIocbOut->iocb.un.fcpi.fcpi_parm -
13056 wcqe->total_data_placed;
13058 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
13060 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
13061 switch (pIocbOut->iocb.ulpCommand) {
13062 case CMD_ELS_REQUEST64_CR:
13063 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
13064 bpl = (struct ulp_bde64 *)dmabuf->virt;
13065 bde.tus.w = le32_to_cpu(bpl[1].tus.w);
13066 max_response = bde.tus.f.bdeSize;
13068 case CMD_GEN_REQUEST64_CR:
13070 if (!pIocbOut->context3)
13072 numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
13073 sizeof(struct ulp_bde64);
13074 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
13075 bpl = (struct ulp_bde64 *)dmabuf->virt;
13076 for (i = 0; i < numBdes; i++) {
13077 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
13078 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
13079 max_response += bde.tus.f.bdeSize;
13083 max_response = wcqe->total_data_placed;
13086 if (max_response < wcqe->total_data_placed)
13087 pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
13089 pIocbIn->iocb.un.genreq64.bdl.bdeSize =
13090 wcqe->total_data_placed;
13093 /* Convert BG errors for completion status */
13094 if (status == CQE_STATUS_DI_ERROR) {
13095 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
13097 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
13098 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
13100 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
13102 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
13103 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
13104 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13105 BGS_GUARD_ERR_MASK;
13106 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
13107 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13108 BGS_APPTAG_ERR_MASK;
13109 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
13110 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13111 BGS_REFTAG_ERR_MASK;
13113 /* Check to see if there was any good data before the error */
13114 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
13115 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13116 BGS_HI_WATER_MARK_PRESENT_MASK;
13117 pIocbIn->iocb.unsli3.sli3_bg.bghm =
13118 wcqe->total_data_placed;
13122 * Set ALL the error bits to indicate we don't know what
13123 * type of error it is.
13125 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
13126 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13127 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
13128 BGS_GUARD_ERR_MASK);
13131 /* Pick up HBA exchange busy condition */
13132 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
13133 spin_lock_irqsave(&phba->hbalock, iflags);
13134 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
13135 spin_unlock_irqrestore(&phba->hbalock, iflags);
13140 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
13141 * @phba: Pointer to HBA context object.
13142 * @wcqe: Pointer to work-queue completion queue entry.
13144 * This routine handles an ELS work-queue completion event and construct
13145 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
13146 * discovery engine to handle.
13148 * Return: Pointer to the receive IOCBQ, NULL otherwise.
13150 static struct lpfc_iocbq *
13151 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
13152 struct lpfc_iocbq *irspiocbq)
13154 struct lpfc_sli_ring *pring;
13155 struct lpfc_iocbq *cmdiocbq;
13156 struct lpfc_wcqe_complete *wcqe;
13157 unsigned long iflags;
13159 pring = lpfc_phba_elsring(phba);
13160 if (unlikely(!pring))
13163 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
13164 pring->stats.iocb_event++;
13165 /* Look up the ELS command IOCB and create pseudo response IOCB */
13166 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
13167 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13168 if (unlikely(!cmdiocbq)) {
13169 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13170 "0386 ELS complete with no corresponding "
13171 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
13172 wcqe->word0, wcqe->total_data_placed,
13173 wcqe->parameter, wcqe->word3);
13174 lpfc_sli_release_iocbq(phba, irspiocbq);
13178 spin_lock_irqsave(&pring->ring_lock, iflags);
13179 /* Put the iocb back on the txcmplq */
13180 lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
13181 spin_unlock_irqrestore(&pring->ring_lock, iflags);
13183 /* Fake the irspiocbq and copy necessary response information */
13184 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
13189 inline struct lpfc_cq_event *
13190 lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
13192 struct lpfc_cq_event *cq_event;
13194 /* Allocate a new internal CQ_EVENT entry */
13195 cq_event = lpfc_sli4_cq_event_alloc(phba);
13197 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13198 "0602 Failed to alloc CQ_EVENT entry\n");
13202 /* Move the CQE into the event */
13203 memcpy(&cq_event->cqe, entry, size);
13208 * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event
13209 * @phba: Pointer to HBA context object.
13210 * @cqe: Pointer to mailbox completion queue entry.
13212 * This routine process a mailbox completion queue entry with asynchronous
13215 * Return: true if work posted to worker thread, otherwise false.
13218 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
13220 struct lpfc_cq_event *cq_event;
13221 unsigned long iflags;
13223 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13224 "0392 Async Event: word0:x%x, word1:x%x, "
13225 "word2:x%x, word3:x%x\n", mcqe->word0,
13226 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
13228 cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
13231 spin_lock_irqsave(&phba->hbalock, iflags);
13232 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
13233 /* Set the async event flag */
13234 phba->hba_flag |= ASYNC_EVENT;
13235 spin_unlock_irqrestore(&phba->hbalock, iflags);
13241 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
13242 * @phba: Pointer to HBA context object.
13243 * @cqe: Pointer to mailbox completion queue entry.
13245 * This routine process a mailbox completion queue entry with mailbox
13246 * completion event.
13248 * Return: true if work posted to worker thread, otherwise false.
13251 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
13253 uint32_t mcqe_status;
13254 MAILBOX_t *mbox, *pmbox;
13255 struct lpfc_mqe *mqe;
13256 struct lpfc_vport *vport;
13257 struct lpfc_nodelist *ndlp;
13258 struct lpfc_dmabuf *mp;
13259 unsigned long iflags;
13261 bool workposted = false;
13264 /* If not a mailbox complete MCQE, out by checking mailbox consume */
13265 if (!bf_get(lpfc_trailer_completed, mcqe))
13266 goto out_no_mqe_complete;
13268 /* Get the reference to the active mbox command */
13269 spin_lock_irqsave(&phba->hbalock, iflags);
13270 pmb = phba->sli.mbox_active;
13271 if (unlikely(!pmb)) {
13272 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
13273 "1832 No pending MBOX command to handle\n");
13274 spin_unlock_irqrestore(&phba->hbalock, iflags);
13275 goto out_no_mqe_complete;
13277 spin_unlock_irqrestore(&phba->hbalock, iflags);
13279 pmbox = (MAILBOX_t *)&pmb->u.mqe;
13281 vport = pmb->vport;
13283 /* Reset heartbeat timer */
13284 phba->last_completion_time = jiffies;
13285 del_timer(&phba->sli.mbox_tmo);
13287 /* Move mbox data to caller's mailbox region, do endian swapping */
13288 if (pmb->mbox_cmpl && mbox)
13289 lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
13292 * For mcqe errors, conditionally move a modified error code to
13293 * the mbox so that the error will not be missed.
13295 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
13296 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
13297 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
13298 bf_set(lpfc_mqe_status, mqe,
13299 (LPFC_MBX_ERROR_RANGE | mcqe_status));
13301 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
13302 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
13303 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
13304 "MBOX dflt rpi: status:x%x rpi:x%x",
13306 pmbox->un.varWords[0], 0);
13307 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
13308 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
13309 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
13310 /* Reg_LOGIN of dflt RPI was successful. Now lets get
13311 * RID of the PPI using the same mbox buffer.
13313 lpfc_unreg_login(phba, vport->vpi,
13314 pmbox->un.varWords[0], pmb);
13315 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
13317 pmb->ctx_ndlp = ndlp;
13318 pmb->vport = vport;
13319 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
13320 if (rc != MBX_BUSY)
13321 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
13322 LOG_SLI, "0385 rc should "
13323 "have been MBX_BUSY\n");
13324 if (rc != MBX_NOT_FINISHED)
13325 goto send_current_mbox;
13328 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
13329 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
13330 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
13332 /* There is mailbox completion work to do */
13333 spin_lock_irqsave(&phba->hbalock, iflags);
13334 __lpfc_mbox_cmpl_put(phba, pmb);
13335 phba->work_ha |= HA_MBATT;
13336 spin_unlock_irqrestore(&phba->hbalock, iflags);
13340 spin_lock_irqsave(&phba->hbalock, iflags);
13341 /* Release the mailbox command posting token */
13342 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13343 /* Setting active mailbox pointer need to be in sync to flag clear */
13344 phba->sli.mbox_active = NULL;
13345 if (bf_get(lpfc_trailer_consumed, mcqe))
13346 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13347 spin_unlock_irqrestore(&phba->hbalock, iflags);
13348 /* Wake up worker thread to post the next pending mailbox command */
13349 lpfc_worker_wake_up(phba);
13352 out_no_mqe_complete:
13353 spin_lock_irqsave(&phba->hbalock, iflags);
13354 if (bf_get(lpfc_trailer_consumed, mcqe))
13355 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13356 spin_unlock_irqrestore(&phba->hbalock, iflags);
13361 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
13362 * @phba: Pointer to HBA context object.
13363 * @cqe: Pointer to mailbox completion queue entry.
13365 * This routine process a mailbox completion queue entry, it invokes the
13366 * proper mailbox complete handling or asynchronous event handling routine
13367 * according to the MCQE's async bit.
13369 * Return: true if work posted to worker thread, otherwise false.
13372 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13373 struct lpfc_cqe *cqe)
13375 struct lpfc_mcqe mcqe;
13380 /* Copy the mailbox MCQE and convert endian order as needed */
13381 lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
13383 /* Invoke the proper event handling routine */
13384 if (!bf_get(lpfc_trailer_async, &mcqe))
13385 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
13387 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
13392 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
13393 * @phba: Pointer to HBA context object.
13394 * @cq: Pointer to associated CQ
13395 * @wcqe: Pointer to work-queue completion queue entry.
13397 * This routine handles an ELS work-queue completion event.
13399 * Return: true if work posted to worker thread, otherwise false.
13402 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13403 struct lpfc_wcqe_complete *wcqe)
13405 struct lpfc_iocbq *irspiocbq;
13406 unsigned long iflags;
13407 struct lpfc_sli_ring *pring = cq->pring;
13409 int txcmplq_cnt = 0;
13411 /* Check for response status */
13412 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
13413 /* Log the error status */
13414 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13415 "0357 ELS CQE error: status=x%x: "
13416 "CQE: %08x %08x %08x %08x\n",
13417 bf_get(lpfc_wcqe_c_status, wcqe),
13418 wcqe->word0, wcqe->total_data_placed,
13419 wcqe->parameter, wcqe->word3);
13422 /* Get an irspiocbq for later ELS response processing use */
13423 irspiocbq = lpfc_sli_get_iocbq(phba);
13425 if (!list_empty(&pring->txq))
13427 if (!list_empty(&pring->txcmplq))
13429 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13430 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
13431 "els_txcmplq_cnt=%d\n",
13432 txq_cnt, phba->iocb_cnt,
13437 /* Save off the slow-path queue event for work thread to process */
13438 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
13439 spin_lock_irqsave(&phba->hbalock, iflags);
13440 list_add_tail(&irspiocbq->cq_event.list,
13441 &phba->sli4_hba.sp_queue_event);
13442 phba->hba_flag |= HBA_SP_QUEUE_EVT;
13443 spin_unlock_irqrestore(&phba->hbalock, iflags);
13449 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
13450 * @phba: Pointer to HBA context object.
13451 * @wcqe: Pointer to work-queue completion queue entry.
13453 * This routine handles slow-path WQ entry consumed event by invoking the
13454 * proper WQ release routine to the slow-path WQ.
13457 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
13458 struct lpfc_wcqe_release *wcqe)
13460 /* sanity check on queue memory */
13461 if (unlikely(!phba->sli4_hba.els_wq))
13463 /* Check for the slow-path ELS work queue */
13464 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
13465 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
13466 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
13468 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13469 "2579 Slow-path wqe consume event carries "
13470 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
13471 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
13472 phba->sli4_hba.els_wq->queue_id);
13476 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
13477 * @phba: Pointer to HBA context object.
13478 * @cq: Pointer to a WQ completion queue.
13479 * @wcqe: Pointer to work-queue completion queue entry.
13481 * This routine handles an XRI abort event.
13483 * Return: true if work posted to worker thread, otherwise false.
13486 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
13487 struct lpfc_queue *cq,
13488 struct sli4_wcqe_xri_aborted *wcqe)
13490 bool workposted = false;
13491 struct lpfc_cq_event *cq_event;
13492 unsigned long iflags;
13494 switch (cq->subtype) {
13496 lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
13497 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13498 /* Notify aborted XRI for NVME work queue */
13499 if (phba->nvmet_support)
13500 lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
13502 workposted = false;
13504 case LPFC_NVME_LS: /* NVME LS uses ELS resources */
13506 cq_event = lpfc_cq_event_setup(
13507 phba, wcqe, sizeof(struct sli4_wcqe_xri_aborted));
13510 cq_event->hdwq = cq->hdwq;
13511 spin_lock_irqsave(&phba->hbalock, iflags);
13512 list_add_tail(&cq_event->list,
13513 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
13514 /* Set the els xri abort event flag */
13515 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
13516 spin_unlock_irqrestore(&phba->hbalock, iflags);
13520 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13521 "0603 Invalid CQ subtype %d: "
13522 "%08x %08x %08x %08x\n",
13523 cq->subtype, wcqe->word0, wcqe->parameter,
13524 wcqe->word2, wcqe->word3);
13525 workposted = false;
13531 #define FC_RCTL_MDS_DIAGS 0xF4
13534 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
13535 * @phba: Pointer to HBA context object.
13536 * @rcqe: Pointer to receive-queue completion queue entry.
13538 * This routine process a receive-queue completion queue entry.
13540 * Return: true if work posted to worker thread, otherwise false.
13543 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
13545 bool workposted = false;
13546 struct fc_frame_header *fc_hdr;
13547 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
13548 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
13549 struct lpfc_nvmet_tgtport *tgtp;
13550 struct hbq_dmabuf *dma_buf;
13551 uint32_t status, rq_id;
13552 unsigned long iflags;
13554 /* sanity check on queue memory */
13555 if (unlikely(!hrq) || unlikely(!drq))
13558 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
13559 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
13561 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
13562 if (rq_id != hrq->queue_id)
13565 status = bf_get(lpfc_rcqe_status, rcqe);
13567 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
13568 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13569 "2537 Receive Frame Truncated!!\n");
13571 case FC_STATUS_RQ_SUCCESS:
13572 spin_lock_irqsave(&phba->hbalock, iflags);
13573 lpfc_sli4_rq_release(hrq, drq);
13574 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
13576 hrq->RQ_no_buf_found++;
13577 spin_unlock_irqrestore(&phba->hbalock, iflags);
13581 hrq->RQ_buf_posted--;
13582 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
13584 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
13586 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
13587 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
13588 spin_unlock_irqrestore(&phba->hbalock, iflags);
13589 /* Handle MDS Loopback frames */
13590 lpfc_sli4_handle_mds_loopback(phba->pport, dma_buf);
13594 /* save off the frame for the work thread to process */
13595 list_add_tail(&dma_buf->cq_event.list,
13596 &phba->sli4_hba.sp_queue_event);
13597 /* Frame received */
13598 phba->hba_flag |= HBA_SP_QUEUE_EVT;
13599 spin_unlock_irqrestore(&phba->hbalock, iflags);
13602 case FC_STATUS_INSUFF_BUF_FRM_DISC:
13603 if (phba->nvmet_support) {
13604 tgtp = phba->targetport->private;
13605 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME,
13606 "6402 RQE Error x%x, posted %d err_cnt "
13608 status, hrq->RQ_buf_posted,
13609 hrq->RQ_no_posted_buf,
13610 atomic_read(&tgtp->rcv_fcp_cmd_in),
13611 atomic_read(&tgtp->rcv_fcp_cmd_out),
13612 atomic_read(&tgtp->xmt_fcp_release));
13616 case FC_STATUS_INSUFF_BUF_NEED_BUF:
13617 hrq->RQ_no_posted_buf++;
13618 /* Post more buffers if possible */
13619 spin_lock_irqsave(&phba->hbalock, iflags);
13620 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
13621 spin_unlock_irqrestore(&phba->hbalock, iflags);
13630 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
13631 * @phba: Pointer to HBA context object.
13632 * @cq: Pointer to the completion queue.
13633 * @cqe: Pointer to a completion queue entry.
13635 * This routine process a slow-path work-queue or receive queue completion queue
13638 * Return: true if work posted to worker thread, otherwise false.
13641 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13642 struct lpfc_cqe *cqe)
13644 struct lpfc_cqe cqevt;
13645 bool workposted = false;
13647 /* Copy the work queue CQE and convert endian order if needed */
13648 lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
13650 /* Check and process for different type of WCQE and dispatch */
13651 switch (bf_get(lpfc_cqe_code, &cqevt)) {
13652 case CQE_CODE_COMPL_WQE:
13653 /* Process the WQ/RQ complete event */
13654 phba->last_completion_time = jiffies;
13655 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
13656 (struct lpfc_wcqe_complete *)&cqevt);
13658 case CQE_CODE_RELEASE_WQE:
13659 /* Process the WQ release event */
13660 lpfc_sli4_sp_handle_rel_wcqe(phba,
13661 (struct lpfc_wcqe_release *)&cqevt);
13663 case CQE_CODE_XRI_ABORTED:
13664 /* Process the WQ XRI abort event */
13665 phba->last_completion_time = jiffies;
13666 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
13667 (struct sli4_wcqe_xri_aborted *)&cqevt);
13669 case CQE_CODE_RECEIVE:
13670 case CQE_CODE_RECEIVE_V1:
13671 /* Process the RQ event */
13672 phba->last_completion_time = jiffies;
13673 workposted = lpfc_sli4_sp_handle_rcqe(phba,
13674 (struct lpfc_rcqe *)&cqevt);
13677 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13678 "0388 Not a valid WCQE code: x%x\n",
13679 bf_get(lpfc_cqe_code, &cqevt));
13686 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
13687 * @phba: Pointer to HBA context object.
13688 * @eqe: Pointer to fast-path event queue entry.
13690 * This routine process a event queue entry from the slow-path event queue.
13691 * It will check the MajorCode and MinorCode to determine this is for a
13692 * completion event on a completion queue, if not, an error shall be logged
13693 * and just return. Otherwise, it will get to the corresponding completion
13694 * queue and process all the entries on that completion queue, rearm the
13695 * completion queue, and then return.
13699 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
13700 struct lpfc_queue *speq)
13702 struct lpfc_queue *cq = NULL, *childq;
13705 /* Get the reference to the corresponding CQ */
13706 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
13708 list_for_each_entry(childq, &speq->child_list, list) {
13709 if (childq->queue_id == cqid) {
13714 if (unlikely(!cq)) {
13715 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
13716 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13717 "0365 Slow-path CQ identifier "
13718 "(%d) does not exist\n", cqid);
13722 /* Save EQ associated with this CQ */
13723 cq->assoc_qp = speq;
13725 if (!queue_work_on(cq->chann, phba->wq, &cq->spwork))
13726 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13727 "0390 Cannot schedule soft IRQ "
13728 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13729 cqid, cq->queue_id, raw_smp_processor_id());
13733 * __lpfc_sli4_process_cq - Process elements of a CQ
13734 * @phba: Pointer to HBA context object.
13735 * @cq: Pointer to CQ to be processed
13736 * @handler: Routine to process each cqe
13737 * @delay: Pointer to usdelay to set in case of rescheduling of the handler
13739 * This routine processes completion queue entries in a CQ. While a valid
13740 * queue element is found, the handler is called. During processing checks
13741 * are made for periodic doorbell writes to let the hardware know of
13742 * element consumption.
13744 * If the max limit on cqes to process is hit, or there are no more valid
13745 * entries, the loop stops. If we processed a sufficient number of elements,
13746 * meaning there is sufficient load, rather than rearming and generating
13747 * another interrupt, a cq rescheduling delay will be set. A delay of 0
13748 * indicates no rescheduling.
13750 * Returns True if work scheduled, False otherwise.
13753 __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
13754 bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
13755 struct lpfc_cqe *), unsigned long *delay)
13757 struct lpfc_cqe *cqe;
13758 bool workposted = false;
13759 int count = 0, consumed = 0;
13762 /* default - no reschedule */
13765 if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
13766 goto rearm_and_exit;
13768 /* Process all the entries to the CQ */
13770 cqe = lpfc_sli4_cq_get(cq);
13772 workposted |= handler(phba, cq, cqe);
13773 __lpfc_sli4_consume_cqe(phba, cq, cqe);
13776 if (!(++count % cq->max_proc_limit))
13779 if (!(count % cq->notify_interval)) {
13780 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
13783 cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK;
13786 if (count == LPFC_NVMET_CQ_NOTIFY)
13787 cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
13789 cqe = lpfc_sli4_cq_get(cq);
13791 if (count >= phba->cfg_cq_poll_threshold) {
13796 /* Track the max number of CQEs processed in 1 EQ */
13797 if (count > cq->CQ_max_cqe)
13798 cq->CQ_max_cqe = count;
13800 cq->assoc_qp->EQ_cqe_cnt += count;
13802 /* Catch the no cq entry condition */
13803 if (unlikely(count == 0))
13804 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13805 "0369 No entry from completion queue "
13806 "qid=%d\n", cq->queue_id);
13808 xchg(&cq->queue_claimed, 0);
13811 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
13812 arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
13818 * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
13819 * @cq: pointer to CQ to process
13821 * This routine calls the cq processing routine with a handler specific
13822 * to the type of queue bound to it.
13824 * The CQ routine returns two values: the first is the calling status,
13825 * which indicates whether work was queued to the background discovery
13826 * thread. If true, the routine should wakeup the discovery thread;
13827 * the second is the delay parameter. If non-zero, rather than rearming
13828 * the CQ and yet another interrupt, the CQ handler should be queued so
13829 * that it is processed in a subsequent polling action. The value of
13830 * the delay indicates when to reschedule it.
13833 __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
13835 struct lpfc_hba *phba = cq->phba;
13836 unsigned long delay;
13837 bool workposted = false;
13839 /* Process and rearm the CQ */
13840 switch (cq->type) {
13842 workposted |= __lpfc_sli4_process_cq(phba, cq,
13843 lpfc_sli4_sp_handle_mcqe,
13847 if (cq->subtype == LPFC_IO)
13848 workposted |= __lpfc_sli4_process_cq(phba, cq,
13849 lpfc_sli4_fp_handle_cqe,
13852 workposted |= __lpfc_sli4_process_cq(phba, cq,
13853 lpfc_sli4_sp_handle_cqe,
13857 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13858 "0370 Invalid completion queue type (%d)\n",
13864 if (!queue_delayed_work_on(cq->chann, phba->wq,
13865 &cq->sched_spwork, delay))
13866 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
13867 "0394 Cannot schedule soft IRQ "
13868 "for cqid=%d on CPU %d\n",
13869 cq->queue_id, cq->chann);
13872 /* wake up worker thread if there are works to be done */
13874 lpfc_worker_wake_up(phba);
13878 * lpfc_sli4_sp_process_cq - slow-path work handler when started by
13880 * @work: pointer to work element
13882 * translates from the work handler and calls the slow-path handler.
13885 lpfc_sli4_sp_process_cq(struct work_struct *work)
13887 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
13889 __lpfc_sli4_sp_process_cq(cq);
13893 * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
13894 * @work: pointer to work element
13896 * translates from the work handler and calls the slow-path handler.
13899 lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
13901 struct lpfc_queue *cq = container_of(to_delayed_work(work),
13902 struct lpfc_queue, sched_spwork);
13904 __lpfc_sli4_sp_process_cq(cq);
13908 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
13909 * @phba: Pointer to HBA context object.
13910 * @cq: Pointer to associated CQ
13911 * @wcqe: Pointer to work-queue completion queue entry.
13913 * This routine process a fast-path work queue completion entry from fast-path
13914 * event queue for FCP command response completion.
13917 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13918 struct lpfc_wcqe_complete *wcqe)
13920 struct lpfc_sli_ring *pring = cq->pring;
13921 struct lpfc_iocbq *cmdiocbq;
13922 struct lpfc_iocbq irspiocbq;
13923 unsigned long iflags;
13925 /* Check for response status */
13926 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
13927 /* If resource errors reported from HBA, reduce queue
13928 * depth of the SCSI device.
13930 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
13931 IOSTAT_LOCAL_REJECT)) &&
13932 ((wcqe->parameter & IOERR_PARAM_MASK) ==
13933 IOERR_NO_RESOURCES))
13934 phba->lpfc_rampdown_queue_depth(phba);
13936 /* Log the error status */
13937 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13938 "0373 FCP CQE error: status=x%x: "
13939 "CQE: %08x %08x %08x %08x\n",
13940 bf_get(lpfc_wcqe_c_status, wcqe),
13941 wcqe->word0, wcqe->total_data_placed,
13942 wcqe->parameter, wcqe->word3);
13945 /* Look up the FCP command IOCB and create pseudo response IOCB */
13946 spin_lock_irqsave(&pring->ring_lock, iflags);
13947 pring->stats.iocb_event++;
13948 spin_unlock_irqrestore(&pring->ring_lock, iflags);
13949 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
13950 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13951 if (unlikely(!cmdiocbq)) {
13952 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13953 "0374 FCP complete with no corresponding "
13954 "cmdiocb: iotag (%d)\n",
13955 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13958 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13959 cmdiocbq->isr_timestamp = cq->isr_timestamp;
13961 if (cmdiocbq->iocb_cmpl == NULL) {
13962 if (cmdiocbq->wqe_cmpl) {
13963 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
13964 spin_lock_irqsave(&phba->hbalock, iflags);
13965 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
13966 spin_unlock_irqrestore(&phba->hbalock, iflags);
13969 /* Pass the cmd_iocb and the wcqe to the upper layer */
13970 (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe);
13973 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13974 "0375 FCP cmdiocb not callback function "
13976 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13980 /* Fake the irspiocb and copy necessary response information */
13981 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
13983 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
13984 spin_lock_irqsave(&phba->hbalock, iflags);
13985 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
13986 spin_unlock_irqrestore(&phba->hbalock, iflags);
13989 /* Pass the cmd_iocb and the rsp state to the upper layer */
13990 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
13994 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
13995 * @phba: Pointer to HBA context object.
13996 * @cq: Pointer to completion queue.
13997 * @wcqe: Pointer to work-queue completion queue entry.
13999 * This routine handles an fast-path WQ entry consumed event by invoking the
14000 * proper WQ release routine to the slow-path WQ.
14003 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14004 struct lpfc_wcqe_release *wcqe)
14006 struct lpfc_queue *childwq;
14007 bool wqid_matched = false;
14010 /* Check for fast-path FCP work queue release */
14011 hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
14012 list_for_each_entry(childwq, &cq->child_list, list) {
14013 if (childwq->queue_id == hba_wqid) {
14014 lpfc_sli4_wq_release(childwq,
14015 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
14016 if (childwq->q_flag & HBA_NVMET_WQFULL)
14017 lpfc_nvmet_wqfull_process(phba, childwq);
14018 wqid_matched = true;
14022 /* Report warning log message if no match found */
14023 if (wqid_matched != true)
14024 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14025 "2580 Fast-path wqe consume event carries "
14026 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
14030 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
14031 * @phba: Pointer to HBA context object.
14032 * @rcqe: Pointer to receive-queue completion queue entry.
14034 * This routine process a receive-queue completion queue entry.
14036 * Return: true if work posted to worker thread, otherwise false.
14039 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14040 struct lpfc_rcqe *rcqe)
14042 bool workposted = false;
14043 struct lpfc_queue *hrq;
14044 struct lpfc_queue *drq;
14045 struct rqb_dmabuf *dma_buf;
14046 struct fc_frame_header *fc_hdr;
14047 struct lpfc_nvmet_tgtport *tgtp;
14048 uint32_t status, rq_id;
14049 unsigned long iflags;
14050 uint32_t fctl, idx;
14052 if ((phba->nvmet_support == 0) ||
14053 (phba->sli4_hba.nvmet_cqset == NULL))
14056 idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
14057 hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
14058 drq = phba->sli4_hba.nvmet_mrq_data[idx];
14060 /* sanity check on queue memory */
14061 if (unlikely(!hrq) || unlikely(!drq))
14064 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
14065 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
14067 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
14069 if ((phba->nvmet_support == 0) ||
14070 (rq_id != hrq->queue_id))
14073 status = bf_get(lpfc_rcqe_status, rcqe);
14075 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
14076 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14077 "6126 Receive Frame Truncated!!\n");
14079 case FC_STATUS_RQ_SUCCESS:
14080 spin_lock_irqsave(&phba->hbalock, iflags);
14081 lpfc_sli4_rq_release(hrq, drq);
14082 dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
14084 hrq->RQ_no_buf_found++;
14085 spin_unlock_irqrestore(&phba->hbalock, iflags);
14088 spin_unlock_irqrestore(&phba->hbalock, iflags);
14090 hrq->RQ_buf_posted--;
14091 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
14093 /* Just some basic sanity checks on FCP Command frame */
14094 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
14095 fc_hdr->fh_f_ctl[1] << 8 |
14096 fc_hdr->fh_f_ctl[2]);
14098 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
14099 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
14100 (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
14103 if (fc_hdr->fh_type == FC_TYPE_FCP) {
14104 dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
14105 lpfc_nvmet_unsol_fcp_event(
14106 phba, idx, dma_buf, cq->isr_timestamp,
14107 cq->q_flag & HBA_NVMET_CQ_NOTIFY);
14111 lpfc_rq_buf_free(phba, &dma_buf->hbuf);
14113 case FC_STATUS_INSUFF_BUF_FRM_DISC:
14114 if (phba->nvmet_support) {
14115 tgtp = phba->targetport->private;
14116 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_NVME,
14117 "6401 RQE Error x%x, posted %d err_cnt "
14119 status, hrq->RQ_buf_posted,
14120 hrq->RQ_no_posted_buf,
14121 atomic_read(&tgtp->rcv_fcp_cmd_in),
14122 atomic_read(&tgtp->rcv_fcp_cmd_out),
14123 atomic_read(&tgtp->xmt_fcp_release));
14127 case FC_STATUS_INSUFF_BUF_NEED_BUF:
14128 hrq->RQ_no_posted_buf++;
14129 /* Post more buffers if possible */
14137 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
14138 * @phba: adapter with cq
14139 * @cq: Pointer to the completion queue.
14140 * @eqe: Pointer to fast-path completion queue entry.
14142 * This routine process a fast-path work queue completion entry from fast-path
14143 * event queue for FCP command response completion.
14145 * Return: true if work posted to worker thread, otherwise false.
14148 lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14149 struct lpfc_cqe *cqe)
14151 struct lpfc_wcqe_release wcqe;
14152 bool workposted = false;
14154 /* Copy the work queue CQE and convert endian order if needed */
14155 lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
14157 /* Check and process for different type of WCQE and dispatch */
14158 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
14159 case CQE_CODE_COMPL_WQE:
14160 case CQE_CODE_NVME_ERSP:
14162 /* Process the WQ complete event */
14163 phba->last_completion_time = jiffies;
14164 if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
14165 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
14166 (struct lpfc_wcqe_complete *)&wcqe);
14168 case CQE_CODE_RELEASE_WQE:
14169 cq->CQ_release_wqe++;
14170 /* Process the WQ release event */
14171 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
14172 (struct lpfc_wcqe_release *)&wcqe);
14174 case CQE_CODE_XRI_ABORTED:
14175 cq->CQ_xri_aborted++;
14176 /* Process the WQ XRI abort event */
14177 phba->last_completion_time = jiffies;
14178 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
14179 (struct sli4_wcqe_xri_aborted *)&wcqe);
14181 case CQE_CODE_RECEIVE_V1:
14182 case CQE_CODE_RECEIVE:
14183 phba->last_completion_time = jiffies;
14184 if (cq->subtype == LPFC_NVMET) {
14185 workposted = lpfc_sli4_nvmet_handle_rcqe(
14186 phba, cq, (struct lpfc_rcqe *)&wcqe);
14190 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14191 "0144 Not a valid CQE code: x%x\n",
14192 bf_get(lpfc_wcqe_c_code, &wcqe));
14199 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
14200 * @phba: Pointer to HBA context object.
14201 * @eqe: Pointer to fast-path event queue entry.
14203 * This routine process a event queue entry from the fast-path event queue.
14204 * It will check the MajorCode and MinorCode to determine this is for a
14205 * completion event on a completion queue, if not, an error shall be logged
14206 * and just return. Otherwise, it will get to the corresponding completion
14207 * queue and process all the entries on the completion queue, rearm the
14208 * completion queue, and then return.
14211 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
14212 struct lpfc_eqe *eqe)
14214 struct lpfc_queue *cq = NULL;
14215 uint32_t qidx = eq->hdwq;
14218 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
14219 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14220 "0366 Not a valid completion "
14221 "event: majorcode=x%x, minorcode=x%x\n",
14222 bf_get_le32(lpfc_eqe_major_code, eqe),
14223 bf_get_le32(lpfc_eqe_minor_code, eqe));
14227 /* Get the reference to the corresponding CQ */
14228 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
14230 /* Use the fast lookup method first */
14231 if (cqid <= phba->sli4_hba.cq_max) {
14232 cq = phba->sli4_hba.cq_lookup[cqid];
14237 /* Next check for NVMET completion */
14238 if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
14239 id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
14240 if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
14241 /* Process NVMET unsol rcv */
14242 cq = phba->sli4_hba.nvmet_cqset[cqid - id];
14247 if (phba->sli4_hba.nvmels_cq &&
14248 (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
14249 /* Process NVME unsol rcv */
14250 cq = phba->sli4_hba.nvmels_cq;
14253 /* Otherwise this is a Slow path event */
14255 lpfc_sli4_sp_handle_eqe(phba, eqe,
14256 phba->sli4_hba.hdwq[qidx].hba_eq);
14261 if (unlikely(cqid != cq->queue_id)) {
14262 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14263 "0368 Miss-matched fast-path completion "
14264 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
14265 cqid, cq->queue_id);
14270 #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
14271 if (phba->ktime_on)
14272 cq->isr_timestamp = ktime_get_ns();
14274 cq->isr_timestamp = 0;
14276 if (!queue_work_on(cq->chann, phba->wq, &cq->irqwork))
14277 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14278 "0363 Cannot schedule soft IRQ "
14279 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
14280 cqid, cq->queue_id, raw_smp_processor_id());
14284 * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
14285 * @cq: Pointer to CQ to be processed
14287 * This routine calls the cq processing routine with the handler for
14290 * The CQ routine returns two values: the first is the calling status,
14291 * which indicates whether work was queued to the background discovery
14292 * thread. If true, the routine should wakeup the discovery thread;
14293 * the second is the delay parameter. If non-zero, rather than rearming
14294 * the CQ and yet another interrupt, the CQ handler should be queued so
14295 * that it is processed in a subsequent polling action. The value of
14296 * the delay indicates when to reschedule it.
14299 __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq)
14301 struct lpfc_hba *phba = cq->phba;
14302 unsigned long delay;
14303 bool workposted = false;
14305 /* process and rearm the CQ */
14306 workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
14310 if (!queue_delayed_work_on(cq->chann, phba->wq,
14311 &cq->sched_irqwork, delay))
14312 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14313 "0367 Cannot schedule soft IRQ "
14314 "for cqid=%d on CPU %d\n",
14315 cq->queue_id, cq->chann);
14318 /* wake up worker thread if there are works to be done */
14320 lpfc_worker_wake_up(phba);
14324 * lpfc_sli4_hba_process_cq - fast-path work handler when started by
14326 * @work: pointer to work element
14328 * translates from the work handler and calls the fast-path handler.
14331 lpfc_sli4_hba_process_cq(struct work_struct *work)
14333 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
14335 __lpfc_sli4_hba_process_cq(cq);
14339 * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer
14340 * @work: pointer to work element
14342 * translates from the work handler and calls the fast-path handler.
14345 lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
14347 struct lpfc_queue *cq = container_of(to_delayed_work(work),
14348 struct lpfc_queue, sched_irqwork);
14350 __lpfc_sli4_hba_process_cq(cq);
14354 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
14355 * @irq: Interrupt number.
14356 * @dev_id: The device context pointer.
14358 * This function is directly called from the PCI layer as an interrupt
14359 * service routine when device with SLI-4 interface spec is enabled with
14360 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
14361 * ring event in the HBA. However, when the device is enabled with either
14362 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
14363 * device-level interrupt handler. When the PCI slot is in error recovery
14364 * or the HBA is undergoing initialization, the interrupt handler will not
14365 * process the interrupt. The SCSI FCP fast-path ring event are handled in
14366 * the intrrupt context. This function is called without any lock held.
14367 * It gets the hbalock to access and update SLI data structures. Note that,
14368 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
14369 * equal to that of FCP CQ index.
14371 * The link attention and ELS ring attention events are handled
14372 * by the worker thread. The interrupt handler signals the worker thread
14373 * and returns for these events. This function is called without any lock
14374 * held. It gets the hbalock to access and update SLI data structures.
14376 * This function returns IRQ_HANDLED when interrupt is handled else it
14377 * returns IRQ_NONE.
14380 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
14382 struct lpfc_hba *phba;
14383 struct lpfc_hba_eq_hdl *hba_eq_hdl;
14384 struct lpfc_queue *fpeq;
14385 unsigned long iflag;
14388 struct lpfc_eq_intr_info *eqi;
14390 /* Get the driver's phba structure from the dev_id */
14391 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
14392 phba = hba_eq_hdl->phba;
14393 hba_eqidx = hba_eq_hdl->idx;
14395 if (unlikely(!phba))
14397 if (unlikely(!phba->sli4_hba.hdwq))
14400 /* Get to the EQ struct associated with this vector */
14401 fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
14402 if (unlikely(!fpeq))
14405 /* Check device state for handling interrupt */
14406 if (unlikely(lpfc_intr_state_check(phba))) {
14407 /* Check again for link_state with lock held */
14408 spin_lock_irqsave(&phba->hbalock, iflag);
14409 if (phba->link_state < LPFC_LINK_DOWN)
14410 /* Flush, clear interrupt, and rearm the EQ */
14411 lpfc_sli4_eqcq_flush(phba, fpeq);
14412 spin_unlock_irqrestore(&phba->hbalock, iflag);
14416 eqi = this_cpu_ptr(phba->sli4_hba.eq_info);
14419 fpeq->last_cpu = raw_smp_processor_id();
14421 if (eqi->icnt > LPFC_EQD_ISR_TRIGGER &&
14422 fpeq->q_flag & HBA_EQ_DELAY_CHK &&
14423 phba->cfg_auto_imax &&
14424 fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
14425 phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
14426 lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
14428 /* process and rearm the EQ */
14429 ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
14431 if (unlikely(ecount == 0)) {
14432 fpeq->EQ_no_entry++;
14433 if (phba->intr_type == MSIX)
14434 /* MSI-X treated interrupt served as no EQ share INT */
14435 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14436 "0358 MSI-X interrupt with no EQE\n");
14438 /* Non MSI-X treated on interrupt as EQ share INT */
14442 return IRQ_HANDLED;
14443 } /* lpfc_sli4_fp_intr_handler */
14446 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
14447 * @irq: Interrupt number.
14448 * @dev_id: The device context pointer.
14450 * This function is the device-level interrupt handler to device with SLI-4
14451 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
14452 * interrupt mode is enabled and there is an event in the HBA which requires
14453 * driver attention. This function invokes the slow-path interrupt attention
14454 * handling function and fast-path interrupt attention handling function in
14455 * turn to process the relevant HBA attention events. This function is called
14456 * without any lock held. It gets the hbalock to access and update SLI data
14459 * This function returns IRQ_HANDLED when interrupt is handled, else it
14460 * returns IRQ_NONE.
14463 lpfc_sli4_intr_handler(int irq, void *dev_id)
14465 struct lpfc_hba *phba;
14466 irqreturn_t hba_irq_rc;
14467 bool hba_handled = false;
14470 /* Get the driver's phba structure from the dev_id */
14471 phba = (struct lpfc_hba *)dev_id;
14473 if (unlikely(!phba))
14477 * Invoke fast-path host attention interrupt handling as appropriate.
14479 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
14480 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
14481 &phba->sli4_hba.hba_eq_hdl[qidx]);
14482 if (hba_irq_rc == IRQ_HANDLED)
14483 hba_handled |= true;
14486 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
14487 } /* lpfc_sli4_intr_handler */
14489 void lpfc_sli4_poll_hbtimer(struct timer_list *t)
14491 struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer);
14492 struct lpfc_queue *eq;
14497 list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list)
14498 i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH);
14499 if (!list_empty(&phba->poll_list))
14500 mod_timer(&phba->cpuhp_poll_timer,
14501 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
14506 inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path)
14508 struct lpfc_hba *phba = eq->phba;
14512 * Unlocking an irq is one of the entry point to check
14513 * for re-schedule, but we are good for io submission
14514 * path as midlayer does a get_cpu to glue us in. Flush
14515 * out the invalidate queue so we can see the updated
14520 if (READ_ONCE(eq->mode) == LPFC_EQ_POLL)
14521 /* We will not likely get the completion for the caller
14522 * during this iteration but i guess that's fine.
14523 * Future io's coming on this eq should be able to
14524 * pick it up. As for the case of single io's, they
14525 * will be handled through a sched from polling timer
14526 * function which is currently triggered every 1msec.
14528 i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM);
14533 static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq)
14535 struct lpfc_hba *phba = eq->phba;
14537 /* kickstart slowpath processing if needed */
14538 if (list_empty(&phba->poll_list))
14539 mod_timer(&phba->cpuhp_poll_timer,
14540 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
14542 list_add_rcu(&eq->_poll_list, &phba->poll_list);
14546 static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq)
14548 struct lpfc_hba *phba = eq->phba;
14550 /* Disable slowpath processing for this eq. Kick start the eq
14551 * by RE-ARMING the eq's ASAP
14553 list_del_rcu(&eq->_poll_list);
14556 if (list_empty(&phba->poll_list))
14557 del_timer_sync(&phba->cpuhp_poll_timer);
14560 void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba)
14562 struct lpfc_queue *eq, *next;
14564 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list)
14565 list_del(&eq->_poll_list);
14567 INIT_LIST_HEAD(&phba->poll_list);
14572 __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode)
14574 if (mode == eq->mode)
14577 * currently this function is only called during a hotplug
14578 * event and the cpu on which this function is executing
14579 * is going offline. By now the hotplug has instructed
14580 * the scheduler to remove this cpu from cpu active mask.
14581 * So we don't need to work about being put aside by the
14582 * scheduler for a high priority process. Yes, the inte-
14583 * rrupts could come but they are known to retire ASAP.
14586 /* Disable polling in the fastpath */
14587 WRITE_ONCE(eq->mode, mode);
14588 /* flush out the store buffer */
14592 * Add this eq to the polling list and start polling. For
14593 * a grace period both interrupt handler and poller will
14594 * try to process the eq _but_ that's fine. We have a
14595 * synchronization mechanism in place (queue_claimed) to
14596 * deal with it. This is just a draining phase for int-
14597 * errupt handler (not eq's) as we have guranteed through
14598 * barrier that all the CPUs have seen the new CQ_POLLED
14599 * state. which will effectively disable the REARMING of
14600 * the EQ. The whole idea is eq's die off eventually as
14601 * we are not rearming EQ's anymore.
14603 mode ? lpfc_sli4_add_to_poll_list(eq) :
14604 lpfc_sli4_remove_from_poll_list(eq);
14607 void lpfc_sli4_start_polling(struct lpfc_queue *eq)
14609 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL);
14612 void lpfc_sli4_stop_polling(struct lpfc_queue *eq)
14614 struct lpfc_hba *phba = eq->phba;
14616 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT);
14618 /* Kick start for the pending io's in h/w.
14619 * Once we switch back to interrupt processing on a eq
14620 * the io path completion will only arm eq's when it
14621 * receives a completion. But since eq's are in disa-
14622 * rmed state it doesn't receive a completion. This
14623 * creates a deadlock scenaro.
14625 phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM);
14629 * lpfc_sli4_queue_free - free a queue structure and associated memory
14630 * @queue: The queue structure to free.
14632 * This function frees a queue structure and the DMAable memory used for
14633 * the host resident queue. This function must be called after destroying the
14634 * queue on the HBA.
14637 lpfc_sli4_queue_free(struct lpfc_queue *queue)
14639 struct lpfc_dmabuf *dmabuf;
14644 if (!list_empty(&queue->wq_list))
14645 list_del(&queue->wq_list);
14647 while (!list_empty(&queue->page_list)) {
14648 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
14650 dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
14651 dmabuf->virt, dmabuf->phys);
14655 lpfc_free_rq_buffer(queue->phba, queue);
14656 kfree(queue->rqbp);
14659 if (!list_empty(&queue->cpu_list))
14660 list_del(&queue->cpu_list);
14667 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
14668 * @phba: The HBA that this queue is being created on.
14669 * @page_size: The size of a queue page
14670 * @entry_size: The size of each queue entry for this queue.
14671 * @entry count: The number of entries that this queue will handle.
14672 * @cpu: The cpu that will primarily utilize this queue.
14674 * This function allocates a queue structure and the DMAable memory used for
14675 * the host resident queue. This function must be called before creating the
14676 * queue on the HBA.
14678 struct lpfc_queue *
14679 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
14680 uint32_t entry_size, uint32_t entry_count, int cpu)
14682 struct lpfc_queue *queue;
14683 struct lpfc_dmabuf *dmabuf;
14684 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14687 if (!phba->sli4_hba.pc_sli4_params.supported)
14688 hw_page_size = page_size;
14690 pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
14692 /* If needed, Adjust page count to match the max the adapter supports */
14693 if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
14694 pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
14696 queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
14697 GFP_KERNEL, cpu_to_node(cpu));
14701 INIT_LIST_HEAD(&queue->list);
14702 INIT_LIST_HEAD(&queue->_poll_list);
14703 INIT_LIST_HEAD(&queue->wq_list);
14704 INIT_LIST_HEAD(&queue->wqfull_list);
14705 INIT_LIST_HEAD(&queue->page_list);
14706 INIT_LIST_HEAD(&queue->child_list);
14707 INIT_LIST_HEAD(&queue->cpu_list);
14709 /* Set queue parameters now. If the system cannot provide memory
14710 * resources, the free routine needs to know what was allocated.
14712 queue->page_count = pgcnt;
14713 queue->q_pgs = (void **)&queue[1];
14714 queue->entry_cnt_per_pg = hw_page_size / entry_size;
14715 queue->entry_size = entry_size;
14716 queue->entry_count = entry_count;
14717 queue->page_size = hw_page_size;
14718 queue->phba = phba;
14720 for (x = 0; x < queue->page_count; x++) {
14721 dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
14722 dev_to_node(&phba->pcidev->dev));
14725 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
14726 hw_page_size, &dmabuf->phys,
14728 if (!dmabuf->virt) {
14732 dmabuf->buffer_tag = x;
14733 list_add_tail(&dmabuf->list, &queue->page_list);
14734 /* use lpfc_sli4_qe to index a paritcular entry in this page */
14735 queue->q_pgs[x] = dmabuf->virt;
14737 INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
14738 INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
14739 INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
14740 INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
14742 /* notify_interval will be set during q creation */
14746 lpfc_sli4_queue_free(queue);
14751 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
14752 * @phba: HBA structure that indicates port to create a queue on.
14753 * @pci_barset: PCI BAR set flag.
14755 * This function shall perform iomap of the specified PCI BAR address to host
14756 * memory address if not already done so and return it. The returned host
14757 * memory address can be NULL.
14759 static void __iomem *
14760 lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
14765 switch (pci_barset) {
14766 case WQ_PCI_BAR_0_AND_1:
14767 return phba->pci_bar0_memmap_p;
14768 case WQ_PCI_BAR_2_AND_3:
14769 return phba->pci_bar2_memmap_p;
14770 case WQ_PCI_BAR_4_AND_5:
14771 return phba->pci_bar4_memmap_p;
14779 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
14780 * @phba: HBA structure that EQs are on.
14781 * @startq: The starting EQ index to modify
14782 * @numq: The number of EQs (consecutive indexes) to modify
14783 * @usdelay: amount of delay
14785 * This function revises the EQ delay on 1 or more EQs. The EQ delay
14786 * is set either by writing to a register (if supported by the SLI Port)
14787 * or by mailbox command. The mailbox command allows several EQs to be
14790 * The @phba struct is used to send a mailbox command to HBA. The @startq
14791 * is used to get the starting EQ index to change. The @numq value is
14792 * used to specify how many consecutive EQ indexes, starting at EQ index,
14793 * are to be changed. This function is asynchronous and will wait for any
14794 * mailbox commands to finish before returning.
14796 * On success this function will return a zero. If unable to allocate
14797 * enough memory this function will return -ENOMEM. If a mailbox command
14798 * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
14799 * have had their delay multipler changed.
14802 lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
14803 uint32_t numq, uint32_t usdelay)
14805 struct lpfc_mbx_modify_eq_delay *eq_delay;
14806 LPFC_MBOXQ_t *mbox;
14807 struct lpfc_queue *eq;
14808 int cnt = 0, rc, length;
14809 uint32_t shdr_status, shdr_add_status;
14812 union lpfc_sli4_cfg_shdr *shdr;
14814 if (startq >= phba->cfg_irq_chann)
14817 if (usdelay > 0xFFFF) {
14818 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
14819 "6429 usdelay %d too large. Scaled down to "
14820 "0xFFFF.\n", usdelay);
14824 /* set values by EQ_DELAY register if supported */
14825 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
14826 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
14827 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
14831 lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
14839 /* Otherwise, set values by mailbox cmd */
14841 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_FCP | LOG_NVME,
14844 "6428 Failed allocating mailbox cmd buffer."
14845 " EQ delay was not set.\n");
14848 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
14849 sizeof(struct lpfc_sli4_cfg_mhdr));
14850 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14851 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
14852 length, LPFC_SLI4_MBX_EMBED);
14853 eq_delay = &mbox->u.mqe.un.eq_delay;
14855 /* Calculate delay multiper from maximum interrupt per second */
14856 dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
14859 if (dmult > LPFC_DMULT_MAX)
14860 dmult = LPFC_DMULT_MAX;
14862 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
14863 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
14866 eq->q_mode = usdelay;
14867 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
14868 eq_delay->u.request.eq[cnt].phase = 0;
14869 eq_delay->u.request.eq[cnt].delay_multi = dmult;
14874 eq_delay->u.request.num_eq = cnt;
14876 mbox->vport = phba->pport;
14877 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
14878 mbox->ctx_buf = NULL;
14879 mbox->ctx_ndlp = NULL;
14880 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
14881 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
14882 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
14883 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
14884 if (shdr_status || shdr_add_status || rc) {
14885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
14886 "2512 MODIFY_EQ_DELAY mailbox failed with "
14887 "status x%x add_status x%x, mbx status x%x\n",
14888 shdr_status, shdr_add_status, rc);
14890 mempool_free(mbox, phba->mbox_mem_pool);
14895 * lpfc_eq_create - Create an Event Queue on the HBA
14896 * @phba: HBA structure that indicates port to create a queue on.
14897 * @eq: The queue structure to use to create the event queue.
14898 * @imax: The maximum interrupt per second limit.
14900 * This function creates an event queue, as detailed in @eq, on a port,
14901 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
14903 * The @phba struct is used to send mailbox command to HBA. The @eq struct
14904 * is used to get the entry count and entry size that are necessary to
14905 * determine the number of pages to allocate and use for this queue. This
14906 * function will send the EQ_CREATE mailbox command to the HBA to setup the
14907 * event queue. This function is asynchronous and will wait for the mailbox
14908 * command to finish before continuing.
14910 * On success this function will return a zero. If unable to allocate enough
14911 * memory this function will return -ENOMEM. If the queue create mailbox command
14912 * fails this function will return -ENXIO.
14915 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
14917 struct lpfc_mbx_eq_create *eq_create;
14918 LPFC_MBOXQ_t *mbox;
14919 int rc, length, status = 0;
14920 struct lpfc_dmabuf *dmabuf;
14921 uint32_t shdr_status, shdr_add_status;
14922 union lpfc_sli4_cfg_shdr *shdr;
14924 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
14926 /* sanity check on queue memory */
14929 if (!phba->sli4_hba.pc_sli4_params.supported)
14930 hw_page_size = SLI4_PAGE_SIZE;
14932 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
14935 length = (sizeof(struct lpfc_mbx_eq_create) -
14936 sizeof(struct lpfc_sli4_cfg_mhdr));
14937 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
14938 LPFC_MBOX_OPCODE_EQ_CREATE,
14939 length, LPFC_SLI4_MBX_EMBED);
14940 eq_create = &mbox->u.mqe.un.eq_create;
14941 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
14942 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
14944 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
14946 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
14948 /* Use version 2 of CREATE_EQ if eqav is set */
14949 if (phba->sli4_hba.pc_sli4_params.eqav) {
14950 bf_set(lpfc_mbox_hdr_version, &shdr->request,
14951 LPFC_Q_CREATE_VERSION_2);
14952 bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
14953 phba->sli4_hba.pc_sli4_params.eqav);
14956 /* don't setup delay multiplier using EQ_CREATE */
14958 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
14960 switch (eq->entry_count) {
14962 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
14963 "0360 Unsupported EQ count. (%d)\n",
14965 if (eq->entry_count < 256) {
14969 /* fall through - otherwise default to smallest count */
14971 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14975 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14979 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14983 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14987 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
14991 list_for_each_entry(dmabuf, &eq->page_list, list) {
14992 memset(dmabuf->virt, 0, hw_page_size);
14993 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
14994 putPaddrLow(dmabuf->phys);
14995 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
14996 putPaddrHigh(dmabuf->phys);
14998 mbox->vport = phba->pport;
14999 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
15000 mbox->ctx_buf = NULL;
15001 mbox->ctx_ndlp = NULL;
15002 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15003 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15004 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15005 if (shdr_status || shdr_add_status || rc) {
15006 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15007 "2500 EQ_CREATE mailbox failed with "
15008 "status x%x add_status x%x, mbx status x%x\n",
15009 shdr_status, shdr_add_status, rc);
15012 eq->type = LPFC_EQ;
15013 eq->subtype = LPFC_NONE;
15014 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
15015 if (eq->queue_id == 0xFFFF)
15017 eq->host_index = 0;
15018 eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
15019 eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
15021 mempool_free(mbox, phba->mbox_mem_pool);
15026 * lpfc_cq_create - Create a Completion Queue on the HBA
15027 * @phba: HBA structure that indicates port to create a queue on.
15028 * @cq: The queue structure to use to create the completion queue.
15029 * @eq: The event queue to bind this completion queue to.
15031 * This function creates a completion queue, as detailed in @wq, on a port,
15032 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
15034 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15035 * is used to get the entry count and entry size that are necessary to
15036 * determine the number of pages to allocate and use for this queue. The @eq
15037 * is used to indicate which event queue to bind this completion queue to. This
15038 * function will send the CQ_CREATE mailbox command to the HBA to setup the
15039 * completion queue. This function is asynchronous and will wait for the mailbox
15040 * command to finish before continuing.
15042 * On success this function will return a zero. If unable to allocate enough
15043 * memory this function will return -ENOMEM. If the queue create mailbox command
15044 * fails this function will return -ENXIO.
15047 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
15048 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
15050 struct lpfc_mbx_cq_create *cq_create;
15051 struct lpfc_dmabuf *dmabuf;
15052 LPFC_MBOXQ_t *mbox;
15053 int rc, length, status = 0;
15054 uint32_t shdr_status, shdr_add_status;
15055 union lpfc_sli4_cfg_shdr *shdr;
15057 /* sanity check on queue memory */
15061 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15064 length = (sizeof(struct lpfc_mbx_cq_create) -
15065 sizeof(struct lpfc_sli4_cfg_mhdr));
15066 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15067 LPFC_MBOX_OPCODE_CQ_CREATE,
15068 length, LPFC_SLI4_MBX_EMBED);
15069 cq_create = &mbox->u.mqe.un.cq_create;
15070 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
15071 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
15073 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
15074 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
15075 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15076 phba->sli4_hba.pc_sli4_params.cqv);
15077 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
15078 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
15079 (cq->page_size / SLI4_PAGE_SIZE));
15080 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
15082 bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
15083 phba->sli4_hba.pc_sli4_params.cqav);
15085 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
15088 switch (cq->entry_count) {
15091 if (phba->sli4_hba.pc_sli4_params.cqv ==
15092 LPFC_Q_CREATE_VERSION_2) {
15093 cq_create->u.request.context.lpfc_cq_context_count =
15095 bf_set(lpfc_cq_context_count,
15096 &cq_create->u.request.context,
15097 LPFC_CQ_CNT_WORD7);
15102 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15103 "0361 Unsupported CQ count: "
15104 "entry cnt %d sz %d pg cnt %d\n",
15105 cq->entry_count, cq->entry_size,
15107 if (cq->entry_count < 256) {
15111 /* fall through - otherwise default to smallest count */
15113 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
15117 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
15121 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
15125 list_for_each_entry(dmabuf, &cq->page_list, list) {
15126 memset(dmabuf->virt, 0, cq->page_size);
15127 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15128 putPaddrLow(dmabuf->phys);
15129 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15130 putPaddrHigh(dmabuf->phys);
15132 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15134 /* The IOCTL status is embedded in the mailbox subheader. */
15135 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15136 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15137 if (shdr_status || shdr_add_status || rc) {
15138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15139 "2501 CQ_CREATE mailbox failed with "
15140 "status x%x add_status x%x, mbx status x%x\n",
15141 shdr_status, shdr_add_status, rc);
15145 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
15146 if (cq->queue_id == 0xFFFF) {
15150 /* link the cq onto the parent eq child list */
15151 list_add_tail(&cq->list, &eq->child_list);
15152 /* Set up completion queue's type and subtype */
15154 cq->subtype = subtype;
15155 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
15156 cq->assoc_qid = eq->queue_id;
15158 cq->host_index = 0;
15159 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
15160 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
15162 if (cq->queue_id > phba->sli4_hba.cq_max)
15163 phba->sli4_hba.cq_max = cq->queue_id;
15165 mempool_free(mbox, phba->mbox_mem_pool);
15170 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
15171 * @phba: HBA structure that indicates port to create a queue on.
15172 * @cqp: The queue structure array to use to create the completion queues.
15173 * @hdwq: The hardware queue array with the EQ to bind completion queues to.
15175 * This function creates a set of completion queue, s to support MRQ
15176 * as detailed in @cqp, on a port,
15177 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
15179 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15180 * is used to get the entry count and entry size that are necessary to
15181 * determine the number of pages to allocate and use for this queue. The @eq
15182 * is used to indicate which event queue to bind this completion queue to. This
15183 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
15184 * completion queue. This function is asynchronous and will wait for the mailbox
15185 * command to finish before continuing.
15187 * On success this function will return a zero. If unable to allocate enough
15188 * memory this function will return -ENOMEM. If the queue create mailbox command
15189 * fails this function will return -ENXIO.
15192 lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
15193 struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
15196 struct lpfc_queue *cq;
15197 struct lpfc_queue *eq;
15198 struct lpfc_mbx_cq_create_set *cq_set;
15199 struct lpfc_dmabuf *dmabuf;
15200 LPFC_MBOXQ_t *mbox;
15201 int rc, length, alloclen, status = 0;
15202 int cnt, idx, numcq, page_idx = 0;
15203 uint32_t shdr_status, shdr_add_status;
15204 union lpfc_sli4_cfg_shdr *shdr;
15205 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15207 /* sanity check on queue memory */
15208 numcq = phba->cfg_nvmet_mrq;
15209 if (!cqp || !hdwq || !numcq)
15212 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15216 length = sizeof(struct lpfc_mbx_cq_create_set);
15217 length += ((numcq * cqp[0]->page_count) *
15218 sizeof(struct dma_address));
15219 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15220 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
15221 LPFC_SLI4_MBX_NEMBED);
15222 if (alloclen < length) {
15223 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15224 "3098 Allocated DMA memory size (%d) is "
15225 "less than the requested DMA memory size "
15226 "(%d)\n", alloclen, length);
15230 cq_set = mbox->sge_array->addr[0];
15231 shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
15232 bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
15234 for (idx = 0; idx < numcq; idx++) {
15236 eq = hdwq[idx].hba_eq;
15241 if (!phba->sli4_hba.pc_sli4_params.supported)
15242 hw_page_size = cq->page_size;
15246 bf_set(lpfc_mbx_cq_create_set_page_size,
15247 &cq_set->u.request,
15248 (hw_page_size / SLI4_PAGE_SIZE));
15249 bf_set(lpfc_mbx_cq_create_set_num_pages,
15250 &cq_set->u.request, cq->page_count);
15251 bf_set(lpfc_mbx_cq_create_set_evt,
15252 &cq_set->u.request, 1);
15253 bf_set(lpfc_mbx_cq_create_set_valid,
15254 &cq_set->u.request, 1);
15255 bf_set(lpfc_mbx_cq_create_set_cqe_size,
15256 &cq_set->u.request, 0);
15257 bf_set(lpfc_mbx_cq_create_set_num_cq,
15258 &cq_set->u.request, numcq);
15259 bf_set(lpfc_mbx_cq_create_set_autovalid,
15260 &cq_set->u.request,
15261 phba->sli4_hba.pc_sli4_params.cqav);
15262 switch (cq->entry_count) {
15265 if (phba->sli4_hba.pc_sli4_params.cqv ==
15266 LPFC_Q_CREATE_VERSION_2) {
15267 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15268 &cq_set->u.request,
15270 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15271 &cq_set->u.request,
15272 LPFC_CQ_CNT_WORD7);
15277 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15278 "3118 Bad CQ count. (%d)\n",
15280 if (cq->entry_count < 256) {
15284 /* fall through - otherwise default to smallest */
15286 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15287 &cq_set->u.request, LPFC_CQ_CNT_256);
15290 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15291 &cq_set->u.request, LPFC_CQ_CNT_512);
15294 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15295 &cq_set->u.request, LPFC_CQ_CNT_1024);
15298 bf_set(lpfc_mbx_cq_create_set_eq_id0,
15299 &cq_set->u.request, eq->queue_id);
15302 bf_set(lpfc_mbx_cq_create_set_eq_id1,
15303 &cq_set->u.request, eq->queue_id);
15306 bf_set(lpfc_mbx_cq_create_set_eq_id2,
15307 &cq_set->u.request, eq->queue_id);
15310 bf_set(lpfc_mbx_cq_create_set_eq_id3,
15311 &cq_set->u.request, eq->queue_id);
15314 bf_set(lpfc_mbx_cq_create_set_eq_id4,
15315 &cq_set->u.request, eq->queue_id);
15318 bf_set(lpfc_mbx_cq_create_set_eq_id5,
15319 &cq_set->u.request, eq->queue_id);
15322 bf_set(lpfc_mbx_cq_create_set_eq_id6,
15323 &cq_set->u.request, eq->queue_id);
15326 bf_set(lpfc_mbx_cq_create_set_eq_id7,
15327 &cq_set->u.request, eq->queue_id);
15330 bf_set(lpfc_mbx_cq_create_set_eq_id8,
15331 &cq_set->u.request, eq->queue_id);
15334 bf_set(lpfc_mbx_cq_create_set_eq_id9,
15335 &cq_set->u.request, eq->queue_id);
15338 bf_set(lpfc_mbx_cq_create_set_eq_id10,
15339 &cq_set->u.request, eq->queue_id);
15342 bf_set(lpfc_mbx_cq_create_set_eq_id11,
15343 &cq_set->u.request, eq->queue_id);
15346 bf_set(lpfc_mbx_cq_create_set_eq_id12,
15347 &cq_set->u.request, eq->queue_id);
15350 bf_set(lpfc_mbx_cq_create_set_eq_id13,
15351 &cq_set->u.request, eq->queue_id);
15354 bf_set(lpfc_mbx_cq_create_set_eq_id14,
15355 &cq_set->u.request, eq->queue_id);
15358 bf_set(lpfc_mbx_cq_create_set_eq_id15,
15359 &cq_set->u.request, eq->queue_id);
15363 /* link the cq onto the parent eq child list */
15364 list_add_tail(&cq->list, &eq->child_list);
15365 /* Set up completion queue's type and subtype */
15367 cq->subtype = subtype;
15368 cq->assoc_qid = eq->queue_id;
15370 cq->host_index = 0;
15371 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
15372 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
15377 list_for_each_entry(dmabuf, &cq->page_list, list) {
15378 memset(dmabuf->virt, 0, hw_page_size);
15379 cnt = page_idx + dmabuf->buffer_tag;
15380 cq_set->u.request.page[cnt].addr_lo =
15381 putPaddrLow(dmabuf->phys);
15382 cq_set->u.request.page[cnt].addr_hi =
15383 putPaddrHigh(dmabuf->phys);
15389 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15391 /* The IOCTL status is embedded in the mailbox subheader. */
15392 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15393 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15394 if (shdr_status || shdr_add_status || rc) {
15395 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15396 "3119 CQ_CREATE_SET mailbox failed with "
15397 "status x%x add_status x%x, mbx status x%x\n",
15398 shdr_status, shdr_add_status, rc);
15402 rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
15403 if (rc == 0xFFFF) {
15408 for (idx = 0; idx < numcq; idx++) {
15410 cq->queue_id = rc + idx;
15411 if (cq->queue_id > phba->sli4_hba.cq_max)
15412 phba->sli4_hba.cq_max = cq->queue_id;
15416 lpfc_sli4_mbox_cmd_free(phba, mbox);
15421 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
15422 * @phba: HBA structure that indicates port to create a queue on.
15423 * @mq: The queue structure to use to create the mailbox queue.
15424 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
15425 * @cq: The completion queue to associate with this cq.
15427 * This function provides failback (fb) functionality when the
15428 * mq_create_ext fails on older FW generations. It's purpose is identical
15429 * to mq_create_ext otherwise.
15431 * This routine cannot fail as all attributes were previously accessed and
15432 * initialized in mq_create_ext.
15435 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
15436 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
15438 struct lpfc_mbx_mq_create *mq_create;
15439 struct lpfc_dmabuf *dmabuf;
15442 length = (sizeof(struct lpfc_mbx_mq_create) -
15443 sizeof(struct lpfc_sli4_cfg_mhdr));
15444 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15445 LPFC_MBOX_OPCODE_MQ_CREATE,
15446 length, LPFC_SLI4_MBX_EMBED);
15447 mq_create = &mbox->u.mqe.un.mq_create;
15448 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
15450 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
15452 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
15453 switch (mq->entry_count) {
15455 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15456 LPFC_MQ_RING_SIZE_16);
15459 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15460 LPFC_MQ_RING_SIZE_32);
15463 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15464 LPFC_MQ_RING_SIZE_64);
15467 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15468 LPFC_MQ_RING_SIZE_128);
15471 list_for_each_entry(dmabuf, &mq->page_list, list) {
15472 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15473 putPaddrLow(dmabuf->phys);
15474 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15475 putPaddrHigh(dmabuf->phys);
15480 * lpfc_mq_create - Create a mailbox Queue on the HBA
15481 * @phba: HBA structure that indicates port to create a queue on.
15482 * @mq: The queue structure to use to create the mailbox queue.
15483 * @cq: The completion queue to associate with this cq.
15484 * @subtype: The queue's subtype.
15486 * This function creates a mailbox queue, as detailed in @mq, on a port,
15487 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
15489 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15490 * is used to get the entry count and entry size that are necessary to
15491 * determine the number of pages to allocate and use for this queue. This
15492 * function will send the MQ_CREATE mailbox command to the HBA to setup the
15493 * mailbox queue. This function is asynchronous and will wait for the mailbox
15494 * command to finish before continuing.
15496 * On success this function will return a zero. If unable to allocate enough
15497 * memory this function will return -ENOMEM. If the queue create mailbox command
15498 * fails this function will return -ENXIO.
15501 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
15502 struct lpfc_queue *cq, uint32_t subtype)
15504 struct lpfc_mbx_mq_create *mq_create;
15505 struct lpfc_mbx_mq_create_ext *mq_create_ext;
15506 struct lpfc_dmabuf *dmabuf;
15507 LPFC_MBOXQ_t *mbox;
15508 int rc, length, status = 0;
15509 uint32_t shdr_status, shdr_add_status;
15510 union lpfc_sli4_cfg_shdr *shdr;
15511 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15513 /* sanity check on queue memory */
15516 if (!phba->sli4_hba.pc_sli4_params.supported)
15517 hw_page_size = SLI4_PAGE_SIZE;
15519 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15522 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
15523 sizeof(struct lpfc_sli4_cfg_mhdr));
15524 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15525 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
15526 length, LPFC_SLI4_MBX_EMBED);
15528 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
15529 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
15530 bf_set(lpfc_mbx_mq_create_ext_num_pages,
15531 &mq_create_ext->u.request, mq->page_count);
15532 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
15533 &mq_create_ext->u.request, 1);
15534 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
15535 &mq_create_ext->u.request, 1);
15536 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
15537 &mq_create_ext->u.request, 1);
15538 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
15539 &mq_create_ext->u.request, 1);
15540 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
15541 &mq_create_ext->u.request, 1);
15542 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
15543 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15544 phba->sli4_hba.pc_sli4_params.mqv);
15545 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
15546 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
15549 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
15551 switch (mq->entry_count) {
15553 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15554 "0362 Unsupported MQ count. (%d)\n",
15556 if (mq->entry_count < 16) {
15560 /* fall through - otherwise default to smallest count */
15562 bf_set(lpfc_mq_context_ring_size,
15563 &mq_create_ext->u.request.context,
15564 LPFC_MQ_RING_SIZE_16);
15567 bf_set(lpfc_mq_context_ring_size,
15568 &mq_create_ext->u.request.context,
15569 LPFC_MQ_RING_SIZE_32);
15572 bf_set(lpfc_mq_context_ring_size,
15573 &mq_create_ext->u.request.context,
15574 LPFC_MQ_RING_SIZE_64);
15577 bf_set(lpfc_mq_context_ring_size,
15578 &mq_create_ext->u.request.context,
15579 LPFC_MQ_RING_SIZE_128);
15582 list_for_each_entry(dmabuf, &mq->page_list, list) {
15583 memset(dmabuf->virt, 0, hw_page_size);
15584 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
15585 putPaddrLow(dmabuf->phys);
15586 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
15587 putPaddrHigh(dmabuf->phys);
15589 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15590 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
15591 &mq_create_ext->u.response);
15592 if (rc != MBX_SUCCESS) {
15593 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15594 "2795 MQ_CREATE_EXT failed with "
15595 "status x%x. Failback to MQ_CREATE.\n",
15597 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
15598 mq_create = &mbox->u.mqe.un.mq_create;
15599 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15600 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
15601 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
15602 &mq_create->u.response);
15605 /* The IOCTL status is embedded in the mailbox subheader. */
15606 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15607 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15608 if (shdr_status || shdr_add_status || rc) {
15609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15610 "2502 MQ_CREATE mailbox failed with "
15611 "status x%x add_status x%x, mbx status x%x\n",
15612 shdr_status, shdr_add_status, rc);
15616 if (mq->queue_id == 0xFFFF) {
15620 mq->type = LPFC_MQ;
15621 mq->assoc_qid = cq->queue_id;
15622 mq->subtype = subtype;
15623 mq->host_index = 0;
15626 /* link the mq onto the parent cq child list */
15627 list_add_tail(&mq->list, &cq->child_list);
15629 mempool_free(mbox, phba->mbox_mem_pool);
15634 * lpfc_wq_create - Create a Work Queue on the HBA
15635 * @phba: HBA structure that indicates port to create a queue on.
15636 * @wq: The queue structure to use to create the work queue.
15637 * @cq: The completion queue to bind this work queue to.
15638 * @subtype: The subtype of the work queue indicating its functionality.
15640 * This function creates a work queue, as detailed in @wq, on a port, described
15641 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
15643 * The @phba struct is used to send mailbox command to HBA. The @wq struct
15644 * is used to get the entry count and entry size that are necessary to
15645 * determine the number of pages to allocate and use for this queue. The @cq
15646 * is used to indicate which completion queue to bind this work queue to. This
15647 * function will send the WQ_CREATE mailbox command to the HBA to setup the
15648 * work queue. This function is asynchronous and will wait for the mailbox
15649 * command to finish before continuing.
15651 * On success this function will return a zero. If unable to allocate enough
15652 * memory this function will return -ENOMEM. If the queue create mailbox command
15653 * fails this function will return -ENXIO.
15656 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
15657 struct lpfc_queue *cq, uint32_t subtype)
15659 struct lpfc_mbx_wq_create *wq_create;
15660 struct lpfc_dmabuf *dmabuf;
15661 LPFC_MBOXQ_t *mbox;
15662 int rc, length, status = 0;
15663 uint32_t shdr_status, shdr_add_status;
15664 union lpfc_sli4_cfg_shdr *shdr;
15665 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15666 struct dma_address *page;
15667 void __iomem *bar_memmap_p;
15668 uint32_t db_offset;
15669 uint16_t pci_barset;
15670 uint8_t dpp_barset;
15671 uint32_t dpp_offset;
15672 unsigned long pg_addr;
15673 uint8_t wq_create_version;
15675 /* sanity check on queue memory */
15678 if (!phba->sli4_hba.pc_sli4_params.supported)
15679 hw_page_size = wq->page_size;
15681 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15684 length = (sizeof(struct lpfc_mbx_wq_create) -
15685 sizeof(struct lpfc_sli4_cfg_mhdr));
15686 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15687 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
15688 length, LPFC_SLI4_MBX_EMBED);
15689 wq_create = &mbox->u.mqe.un.wq_create;
15690 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
15691 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
15693 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
15696 /* wqv is the earliest version supported, NOT the latest */
15697 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15698 phba->sli4_hba.pc_sli4_params.wqv);
15700 if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
15701 (wq->page_size > SLI4_PAGE_SIZE))
15702 wq_create_version = LPFC_Q_CREATE_VERSION_1;
15704 wq_create_version = LPFC_Q_CREATE_VERSION_0;
15707 if (phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT)
15708 wq_create_version = LPFC_Q_CREATE_VERSION_1;
15710 wq_create_version = LPFC_Q_CREATE_VERSION_0;
15712 switch (wq_create_version) {
15713 case LPFC_Q_CREATE_VERSION_1:
15714 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
15716 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15717 LPFC_Q_CREATE_VERSION_1);
15719 switch (wq->entry_size) {
15722 bf_set(lpfc_mbx_wq_create_wqe_size,
15723 &wq_create->u.request_1,
15724 LPFC_WQ_WQE_SIZE_64);
15727 bf_set(lpfc_mbx_wq_create_wqe_size,
15728 &wq_create->u.request_1,
15729 LPFC_WQ_WQE_SIZE_128);
15732 /* Request DPP by default */
15733 bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
15734 bf_set(lpfc_mbx_wq_create_page_size,
15735 &wq_create->u.request_1,
15736 (wq->page_size / SLI4_PAGE_SIZE));
15737 page = wq_create->u.request_1.page;
15740 page = wq_create->u.request.page;
15744 list_for_each_entry(dmabuf, &wq->page_list, list) {
15745 memset(dmabuf->virt, 0, hw_page_size);
15746 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
15747 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
15750 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
15751 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
15753 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15754 /* The IOCTL status is embedded in the mailbox subheader. */
15755 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15756 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15757 if (shdr_status || shdr_add_status || rc) {
15758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15759 "2503 WQ_CREATE mailbox failed with "
15760 "status x%x add_status x%x, mbx status x%x\n",
15761 shdr_status, shdr_add_status, rc);
15766 if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
15767 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
15768 &wq_create->u.response);
15770 wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
15771 &wq_create->u.response_1);
15773 if (wq->queue_id == 0xFFFF) {
15778 wq->db_format = LPFC_DB_LIST_FORMAT;
15779 if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
15780 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
15781 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
15782 &wq_create->u.response);
15783 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
15784 (wq->db_format != LPFC_DB_RING_FORMAT)) {
15785 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15786 "3265 WQ[%d] doorbell format "
15787 "not supported: x%x\n",
15788 wq->queue_id, wq->db_format);
15792 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
15793 &wq_create->u.response);
15794 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
15796 if (!bar_memmap_p) {
15797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15798 "3263 WQ[%d] failed to memmap "
15799 "pci barset:x%x\n",
15800 wq->queue_id, pci_barset);
15804 db_offset = wq_create->u.response.doorbell_offset;
15805 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
15806 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
15807 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15808 "3252 WQ[%d] doorbell offset "
15809 "not supported: x%x\n",
15810 wq->queue_id, db_offset);
15814 wq->db_regaddr = bar_memmap_p + db_offset;
15815 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15816 "3264 WQ[%d]: barset:x%x, offset:x%x, "
15817 "format:x%x\n", wq->queue_id,
15818 pci_barset, db_offset, wq->db_format);
15820 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
15822 /* Check if DPP was honored by the firmware */
15823 wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
15824 &wq_create->u.response_1);
15825 if (wq->dpp_enable) {
15826 pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
15827 &wq_create->u.response_1);
15828 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
15830 if (!bar_memmap_p) {
15831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15832 "3267 WQ[%d] failed to memmap "
15833 "pci barset:x%x\n",
15834 wq->queue_id, pci_barset);
15838 db_offset = wq_create->u.response_1.doorbell_offset;
15839 wq->db_regaddr = bar_memmap_p + db_offset;
15840 wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
15841 &wq_create->u.response_1);
15842 dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
15843 &wq_create->u.response_1);
15844 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
15846 if (!bar_memmap_p) {
15847 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15848 "3268 WQ[%d] failed to memmap "
15849 "pci barset:x%x\n",
15850 wq->queue_id, dpp_barset);
15854 dpp_offset = wq_create->u.response_1.dpp_offset;
15855 wq->dpp_regaddr = bar_memmap_p + dpp_offset;
15856 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
15857 "3271 WQ[%d]: barset:x%x, offset:x%x, "
15858 "dpp_id:x%x dpp_barset:x%x "
15859 "dpp_offset:x%x\n",
15860 wq->queue_id, pci_barset, db_offset,
15861 wq->dpp_id, dpp_barset, dpp_offset);
15863 /* Enable combined writes for DPP aperture */
15864 pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
15866 rc = set_memory_wc(pg_addr, 1);
15868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
15869 "3272 Cannot setup Combined "
15870 "Write on WQ[%d] - disable DPP\n",
15872 phba->cfg_enable_dpp = 0;
15875 phba->cfg_enable_dpp = 0;
15878 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
15880 wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
15881 if (wq->pring == NULL) {
15885 wq->type = LPFC_WQ;
15886 wq->assoc_qid = cq->queue_id;
15887 wq->subtype = subtype;
15888 wq->host_index = 0;
15890 wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
15892 /* link the wq onto the parent cq child list */
15893 list_add_tail(&wq->list, &cq->child_list);
15895 mempool_free(mbox, phba->mbox_mem_pool);
15900 * lpfc_rq_create - Create a Receive Queue on the HBA
15901 * @phba: HBA structure that indicates port to create a queue on.
15902 * @hrq: The queue structure to use to create the header receive queue.
15903 * @drq: The queue structure to use to create the data receive queue.
15904 * @cq: The completion queue to bind this work queue to.
15906 * This function creates a receive buffer queue pair , as detailed in @hrq and
15907 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15910 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15911 * struct is used to get the entry count that is necessary to determine the
15912 * number of pages to use for this queue. The @cq is used to indicate which
15913 * completion queue to bind received buffers that are posted to these queues to.
15914 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15915 * receive queue pair. This function is asynchronous and will wait for the
15916 * mailbox command to finish before continuing.
15918 * On success this function will return a zero. If unable to allocate enough
15919 * memory this function will return -ENOMEM. If the queue create mailbox command
15920 * fails this function will return -ENXIO.
15923 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
15924 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
15926 struct lpfc_mbx_rq_create *rq_create;
15927 struct lpfc_dmabuf *dmabuf;
15928 LPFC_MBOXQ_t *mbox;
15929 int rc, length, status = 0;
15930 uint32_t shdr_status, shdr_add_status;
15931 union lpfc_sli4_cfg_shdr *shdr;
15932 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15933 void __iomem *bar_memmap_p;
15934 uint32_t db_offset;
15935 uint16_t pci_barset;
15937 /* sanity check on queue memory */
15938 if (!hrq || !drq || !cq)
15940 if (!phba->sli4_hba.pc_sli4_params.supported)
15941 hw_page_size = SLI4_PAGE_SIZE;
15943 if (hrq->entry_count != drq->entry_count)
15945 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15948 length = (sizeof(struct lpfc_mbx_rq_create) -
15949 sizeof(struct lpfc_sli4_cfg_mhdr));
15950 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15951 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
15952 length, LPFC_SLI4_MBX_EMBED);
15953 rq_create = &mbox->u.mqe.un.rq_create;
15954 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
15955 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15956 phba->sli4_hba.pc_sli4_params.rqv);
15957 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
15958 bf_set(lpfc_rq_context_rqe_count_1,
15959 &rq_create->u.request.context,
15961 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
15962 bf_set(lpfc_rq_context_rqe_size,
15963 &rq_create->u.request.context,
15965 bf_set(lpfc_rq_context_page_size,
15966 &rq_create->u.request.context,
15967 LPFC_RQ_PAGE_SIZE_4096);
15969 switch (hrq->entry_count) {
15971 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
15972 "2535 Unsupported RQ count. (%d)\n",
15974 if (hrq->entry_count < 512) {
15978 /* fall through - otherwise default to smallest count */
15980 bf_set(lpfc_rq_context_rqe_count,
15981 &rq_create->u.request.context,
15982 LPFC_RQ_RING_SIZE_512);
15985 bf_set(lpfc_rq_context_rqe_count,
15986 &rq_create->u.request.context,
15987 LPFC_RQ_RING_SIZE_1024);
15990 bf_set(lpfc_rq_context_rqe_count,
15991 &rq_create->u.request.context,
15992 LPFC_RQ_RING_SIZE_2048);
15995 bf_set(lpfc_rq_context_rqe_count,
15996 &rq_create->u.request.context,
15997 LPFC_RQ_RING_SIZE_4096);
16000 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
16001 LPFC_HDR_BUF_SIZE);
16003 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
16005 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
16007 list_for_each_entry(dmabuf, &hrq->page_list, list) {
16008 memset(dmabuf->virt, 0, hw_page_size);
16009 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16010 putPaddrLow(dmabuf->phys);
16011 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16012 putPaddrHigh(dmabuf->phys);
16014 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16015 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
16017 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16018 /* The IOCTL status is embedded in the mailbox subheader. */
16019 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16020 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16021 if (shdr_status || shdr_add_status || rc) {
16022 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16023 "2504 RQ_CREATE mailbox failed with "
16024 "status x%x add_status x%x, mbx status x%x\n",
16025 shdr_status, shdr_add_status, rc);
16029 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16030 if (hrq->queue_id == 0xFFFF) {
16035 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
16036 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
16037 &rq_create->u.response);
16038 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
16039 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
16040 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16041 "3262 RQ [%d] doorbell format not "
16042 "supported: x%x\n", hrq->queue_id,
16048 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
16049 &rq_create->u.response);
16050 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
16051 if (!bar_memmap_p) {
16052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16053 "3269 RQ[%d] failed to memmap pci "
16054 "barset:x%x\n", hrq->queue_id,
16060 db_offset = rq_create->u.response.doorbell_offset;
16061 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
16062 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
16063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16064 "3270 RQ[%d] doorbell offset not "
16065 "supported: x%x\n", hrq->queue_id,
16070 hrq->db_regaddr = bar_memmap_p + db_offset;
16071 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16072 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
16073 "format:x%x\n", hrq->queue_id, pci_barset,
16074 db_offset, hrq->db_format);
16076 hrq->db_format = LPFC_DB_RING_FORMAT;
16077 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16079 hrq->type = LPFC_HRQ;
16080 hrq->assoc_qid = cq->queue_id;
16081 hrq->subtype = subtype;
16082 hrq->host_index = 0;
16083 hrq->hba_index = 0;
16084 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16086 /* now create the data queue */
16087 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16088 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
16089 length, LPFC_SLI4_MBX_EMBED);
16090 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16091 phba->sli4_hba.pc_sli4_params.rqv);
16092 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
16093 bf_set(lpfc_rq_context_rqe_count_1,
16094 &rq_create->u.request.context, hrq->entry_count);
16095 if (subtype == LPFC_NVMET)
16096 rq_create->u.request.context.buffer_size =
16097 LPFC_NVMET_DATA_BUF_SIZE;
16099 rq_create->u.request.context.buffer_size =
16100 LPFC_DATA_BUF_SIZE;
16101 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
16103 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
16104 (PAGE_SIZE/SLI4_PAGE_SIZE));
16106 switch (drq->entry_count) {
16108 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16109 "2536 Unsupported RQ count. (%d)\n",
16111 if (drq->entry_count < 512) {
16115 /* fall through - otherwise default to smallest count */
16117 bf_set(lpfc_rq_context_rqe_count,
16118 &rq_create->u.request.context,
16119 LPFC_RQ_RING_SIZE_512);
16122 bf_set(lpfc_rq_context_rqe_count,
16123 &rq_create->u.request.context,
16124 LPFC_RQ_RING_SIZE_1024);
16127 bf_set(lpfc_rq_context_rqe_count,
16128 &rq_create->u.request.context,
16129 LPFC_RQ_RING_SIZE_2048);
16132 bf_set(lpfc_rq_context_rqe_count,
16133 &rq_create->u.request.context,
16134 LPFC_RQ_RING_SIZE_4096);
16137 if (subtype == LPFC_NVMET)
16138 bf_set(lpfc_rq_context_buf_size,
16139 &rq_create->u.request.context,
16140 LPFC_NVMET_DATA_BUF_SIZE);
16142 bf_set(lpfc_rq_context_buf_size,
16143 &rq_create->u.request.context,
16144 LPFC_DATA_BUF_SIZE);
16146 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
16148 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
16150 list_for_each_entry(dmabuf, &drq->page_list, list) {
16151 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16152 putPaddrLow(dmabuf->phys);
16153 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16154 putPaddrHigh(dmabuf->phys);
16156 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16157 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
16158 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16159 /* The IOCTL status is embedded in the mailbox subheader. */
16160 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
16161 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16162 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16163 if (shdr_status || shdr_add_status || rc) {
16167 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16168 if (drq->queue_id == 0xFFFF) {
16172 drq->type = LPFC_DRQ;
16173 drq->assoc_qid = cq->queue_id;
16174 drq->subtype = subtype;
16175 drq->host_index = 0;
16176 drq->hba_index = 0;
16177 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16179 /* link the header and data RQs onto the parent cq child list */
16180 list_add_tail(&hrq->list, &cq->child_list);
16181 list_add_tail(&drq->list, &cq->child_list);
16184 mempool_free(mbox, phba->mbox_mem_pool);
16189 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
16190 * @phba: HBA structure that indicates port to create a queue on.
16191 * @hrqp: The queue structure array to use to create the header receive queues.
16192 * @drqp: The queue structure array to use to create the data receive queues.
16193 * @cqp: The completion queue array to bind these receive queues to.
16195 * This function creates a receive buffer queue pair , as detailed in @hrq and
16196 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
16199 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
16200 * struct is used to get the entry count that is necessary to determine the
16201 * number of pages to use for this queue. The @cq is used to indicate which
16202 * completion queue to bind received buffers that are posted to these queues to.
16203 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
16204 * receive queue pair. This function is asynchronous and will wait for the
16205 * mailbox command to finish before continuing.
16207 * On success this function will return a zero. If unable to allocate enough
16208 * memory this function will return -ENOMEM. If the queue create mailbox command
16209 * fails this function will return -ENXIO.
16212 lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
16213 struct lpfc_queue **drqp, struct lpfc_queue **cqp,
16216 struct lpfc_queue *hrq, *drq, *cq;
16217 struct lpfc_mbx_rq_create_v2 *rq_create;
16218 struct lpfc_dmabuf *dmabuf;
16219 LPFC_MBOXQ_t *mbox;
16220 int rc, length, alloclen, status = 0;
16221 int cnt, idx, numrq, page_idx = 0;
16222 uint32_t shdr_status, shdr_add_status;
16223 union lpfc_sli4_cfg_shdr *shdr;
16224 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16226 numrq = phba->cfg_nvmet_mrq;
16227 /* sanity check on array memory */
16228 if (!hrqp || !drqp || !cqp || !numrq)
16230 if (!phba->sli4_hba.pc_sli4_params.supported)
16231 hw_page_size = SLI4_PAGE_SIZE;
16233 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16237 length = sizeof(struct lpfc_mbx_rq_create_v2);
16238 length += ((2 * numrq * hrqp[0]->page_count) *
16239 sizeof(struct dma_address));
16241 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16242 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
16243 LPFC_SLI4_MBX_NEMBED);
16244 if (alloclen < length) {
16245 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16246 "3099 Allocated DMA memory size (%d) is "
16247 "less than the requested DMA memory size "
16248 "(%d)\n", alloclen, length);
16255 rq_create = mbox->sge_array->addr[0];
16256 shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
16258 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
16261 for (idx = 0; idx < numrq; idx++) {
16266 /* sanity check on queue memory */
16267 if (!hrq || !drq || !cq) {
16272 if (hrq->entry_count != drq->entry_count) {
16278 bf_set(lpfc_mbx_rq_create_num_pages,
16279 &rq_create->u.request,
16281 bf_set(lpfc_mbx_rq_create_rq_cnt,
16282 &rq_create->u.request, (numrq * 2));
16283 bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
16285 bf_set(lpfc_rq_context_base_cq,
16286 &rq_create->u.request.context,
16288 bf_set(lpfc_rq_context_data_size,
16289 &rq_create->u.request.context,
16290 LPFC_NVMET_DATA_BUF_SIZE);
16291 bf_set(lpfc_rq_context_hdr_size,
16292 &rq_create->u.request.context,
16293 LPFC_HDR_BUF_SIZE);
16294 bf_set(lpfc_rq_context_rqe_count_1,
16295 &rq_create->u.request.context,
16297 bf_set(lpfc_rq_context_rqe_size,
16298 &rq_create->u.request.context,
16300 bf_set(lpfc_rq_context_page_size,
16301 &rq_create->u.request.context,
16302 (PAGE_SIZE/SLI4_PAGE_SIZE));
16305 list_for_each_entry(dmabuf, &hrq->page_list, list) {
16306 memset(dmabuf->virt, 0, hw_page_size);
16307 cnt = page_idx + dmabuf->buffer_tag;
16308 rq_create->u.request.page[cnt].addr_lo =
16309 putPaddrLow(dmabuf->phys);
16310 rq_create->u.request.page[cnt].addr_hi =
16311 putPaddrHigh(dmabuf->phys);
16317 list_for_each_entry(dmabuf, &drq->page_list, list) {
16318 memset(dmabuf->virt, 0, hw_page_size);
16319 cnt = page_idx + dmabuf->buffer_tag;
16320 rq_create->u.request.page[cnt].addr_lo =
16321 putPaddrLow(dmabuf->phys);
16322 rq_create->u.request.page[cnt].addr_hi =
16323 putPaddrHigh(dmabuf->phys);
16328 hrq->db_format = LPFC_DB_RING_FORMAT;
16329 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16330 hrq->type = LPFC_HRQ;
16331 hrq->assoc_qid = cq->queue_id;
16332 hrq->subtype = subtype;
16333 hrq->host_index = 0;
16334 hrq->hba_index = 0;
16335 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16337 drq->db_format = LPFC_DB_RING_FORMAT;
16338 drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16339 drq->type = LPFC_DRQ;
16340 drq->assoc_qid = cq->queue_id;
16341 drq->subtype = subtype;
16342 drq->host_index = 0;
16343 drq->hba_index = 0;
16344 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16346 list_add_tail(&hrq->list, &cq->child_list);
16347 list_add_tail(&drq->list, &cq->child_list);
16350 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16351 /* The IOCTL status is embedded in the mailbox subheader. */
16352 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16353 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16354 if (shdr_status || shdr_add_status || rc) {
16355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16356 "3120 RQ_CREATE mailbox failed with "
16357 "status x%x add_status x%x, mbx status x%x\n",
16358 shdr_status, shdr_add_status, rc);
16362 rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16363 if (rc == 0xFFFF) {
16368 /* Initialize all RQs with associated queue id */
16369 for (idx = 0; idx < numrq; idx++) {
16371 hrq->queue_id = rc + (2 * idx);
16373 drq->queue_id = rc + (2 * idx) + 1;
16377 lpfc_sli4_mbox_cmd_free(phba, mbox);
16382 * lpfc_eq_destroy - Destroy an event Queue on the HBA
16383 * @eq: The queue structure associated with the queue to destroy.
16385 * This function destroys a queue, as detailed in @eq by sending an mailbox
16386 * command, specific to the type of queue, to the HBA.
16388 * The @eq struct is used to get the queue ID of the queue to destroy.
16390 * On success this function will return a zero. If the queue destroy mailbox
16391 * command fails this function will return -ENXIO.
16394 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
16396 LPFC_MBOXQ_t *mbox;
16397 int rc, length, status = 0;
16398 uint32_t shdr_status, shdr_add_status;
16399 union lpfc_sli4_cfg_shdr *shdr;
16401 /* sanity check on queue memory */
16405 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
16408 length = (sizeof(struct lpfc_mbx_eq_destroy) -
16409 sizeof(struct lpfc_sli4_cfg_mhdr));
16410 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16411 LPFC_MBOX_OPCODE_EQ_DESTROY,
16412 length, LPFC_SLI4_MBX_EMBED);
16413 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
16415 mbox->vport = eq->phba->pport;
16416 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16418 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
16419 /* The IOCTL status is embedded in the mailbox subheader. */
16420 shdr = (union lpfc_sli4_cfg_shdr *)
16421 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
16422 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16423 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16424 if (shdr_status || shdr_add_status || rc) {
16425 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16426 "2505 EQ_DESTROY mailbox failed with "
16427 "status x%x add_status x%x, mbx status x%x\n",
16428 shdr_status, shdr_add_status, rc);
16432 /* Remove eq from any list */
16433 list_del_init(&eq->list);
16434 mempool_free(mbox, eq->phba->mbox_mem_pool);
16439 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
16440 * @cq: The queue structure associated with the queue to destroy.
16442 * This function destroys a queue, as detailed in @cq by sending an mailbox
16443 * command, specific to the type of queue, to the HBA.
16445 * The @cq struct is used to get the queue ID of the queue to destroy.
16447 * On success this function will return a zero. If the queue destroy mailbox
16448 * command fails this function will return -ENXIO.
16451 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
16453 LPFC_MBOXQ_t *mbox;
16454 int rc, length, status = 0;
16455 uint32_t shdr_status, shdr_add_status;
16456 union lpfc_sli4_cfg_shdr *shdr;
16458 /* sanity check on queue memory */
16461 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
16464 length = (sizeof(struct lpfc_mbx_cq_destroy) -
16465 sizeof(struct lpfc_sli4_cfg_mhdr));
16466 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16467 LPFC_MBOX_OPCODE_CQ_DESTROY,
16468 length, LPFC_SLI4_MBX_EMBED);
16469 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
16471 mbox->vport = cq->phba->pport;
16472 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16473 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
16474 /* The IOCTL status is embedded in the mailbox subheader. */
16475 shdr = (union lpfc_sli4_cfg_shdr *)
16476 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
16477 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16478 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16479 if (shdr_status || shdr_add_status || rc) {
16480 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16481 "2506 CQ_DESTROY mailbox failed with "
16482 "status x%x add_status x%x, mbx status x%x\n",
16483 shdr_status, shdr_add_status, rc);
16486 /* Remove cq from any list */
16487 list_del_init(&cq->list);
16488 mempool_free(mbox, cq->phba->mbox_mem_pool);
16493 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
16494 * @qm: The queue structure associated with the queue to destroy.
16496 * This function destroys a queue, as detailed in @mq by sending an mailbox
16497 * command, specific to the type of queue, to the HBA.
16499 * The @mq struct is used to get the queue ID of the queue to destroy.
16501 * On success this function will return a zero. If the queue destroy mailbox
16502 * command fails this function will return -ENXIO.
16505 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
16507 LPFC_MBOXQ_t *mbox;
16508 int rc, length, status = 0;
16509 uint32_t shdr_status, shdr_add_status;
16510 union lpfc_sli4_cfg_shdr *shdr;
16512 /* sanity check on queue memory */
16515 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
16518 length = (sizeof(struct lpfc_mbx_mq_destroy) -
16519 sizeof(struct lpfc_sli4_cfg_mhdr));
16520 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16521 LPFC_MBOX_OPCODE_MQ_DESTROY,
16522 length, LPFC_SLI4_MBX_EMBED);
16523 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
16525 mbox->vport = mq->phba->pport;
16526 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16527 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
16528 /* The IOCTL status is embedded in the mailbox subheader. */
16529 shdr = (union lpfc_sli4_cfg_shdr *)
16530 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
16531 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16532 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16533 if (shdr_status || shdr_add_status || rc) {
16534 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16535 "2507 MQ_DESTROY mailbox failed with "
16536 "status x%x add_status x%x, mbx status x%x\n",
16537 shdr_status, shdr_add_status, rc);
16540 /* Remove mq from any list */
16541 list_del_init(&mq->list);
16542 mempool_free(mbox, mq->phba->mbox_mem_pool);
16547 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
16548 * @wq: The queue structure associated with the queue to destroy.
16550 * This function destroys a queue, as detailed in @wq by sending an mailbox
16551 * command, specific to the type of queue, to the HBA.
16553 * The @wq struct is used to get the queue ID of the queue to destroy.
16555 * On success this function will return a zero. If the queue destroy mailbox
16556 * command fails this function will return -ENXIO.
16559 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
16561 LPFC_MBOXQ_t *mbox;
16562 int rc, length, status = 0;
16563 uint32_t shdr_status, shdr_add_status;
16564 union lpfc_sli4_cfg_shdr *shdr;
16566 /* sanity check on queue memory */
16569 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
16572 length = (sizeof(struct lpfc_mbx_wq_destroy) -
16573 sizeof(struct lpfc_sli4_cfg_mhdr));
16574 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16575 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
16576 length, LPFC_SLI4_MBX_EMBED);
16577 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
16579 mbox->vport = wq->phba->pport;
16580 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16581 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
16582 shdr = (union lpfc_sli4_cfg_shdr *)
16583 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
16584 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16585 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16586 if (shdr_status || shdr_add_status || rc) {
16587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16588 "2508 WQ_DESTROY mailbox failed with "
16589 "status x%x add_status x%x, mbx status x%x\n",
16590 shdr_status, shdr_add_status, rc);
16593 /* Remove wq from any list */
16594 list_del_init(&wq->list);
16597 mempool_free(mbox, wq->phba->mbox_mem_pool);
16602 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
16603 * @rq: The queue structure associated with the queue to destroy.
16605 * This function destroys a queue, as detailed in @rq by sending an mailbox
16606 * command, specific to the type of queue, to the HBA.
16608 * The @rq struct is used to get the queue ID of the queue to destroy.
16610 * On success this function will return a zero. If the queue destroy mailbox
16611 * command fails this function will return -ENXIO.
16614 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
16615 struct lpfc_queue *drq)
16617 LPFC_MBOXQ_t *mbox;
16618 int rc, length, status = 0;
16619 uint32_t shdr_status, shdr_add_status;
16620 union lpfc_sli4_cfg_shdr *shdr;
16622 /* sanity check on queue memory */
16625 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
16628 length = (sizeof(struct lpfc_mbx_rq_destroy) -
16629 sizeof(struct lpfc_sli4_cfg_mhdr));
16630 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16631 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
16632 length, LPFC_SLI4_MBX_EMBED);
16633 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
16635 mbox->vport = hrq->phba->pport;
16636 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16637 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
16638 /* The IOCTL status is embedded in the mailbox subheader. */
16639 shdr = (union lpfc_sli4_cfg_shdr *)
16640 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
16641 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16642 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16643 if (shdr_status || shdr_add_status || rc) {
16644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16645 "2509 RQ_DESTROY mailbox failed with "
16646 "status x%x add_status x%x, mbx status x%x\n",
16647 shdr_status, shdr_add_status, rc);
16648 if (rc != MBX_TIMEOUT)
16649 mempool_free(mbox, hrq->phba->mbox_mem_pool);
16652 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
16654 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
16655 shdr = (union lpfc_sli4_cfg_shdr *)
16656 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
16657 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16658 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16659 if (shdr_status || shdr_add_status || rc) {
16660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16661 "2510 RQ_DESTROY mailbox failed with "
16662 "status x%x add_status x%x, mbx status x%x\n",
16663 shdr_status, shdr_add_status, rc);
16666 list_del_init(&hrq->list);
16667 list_del_init(&drq->list);
16668 mempool_free(mbox, hrq->phba->mbox_mem_pool);
16673 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
16674 * @phba: The virtual port for which this call being executed.
16675 * @pdma_phys_addr0: Physical address of the 1st SGL page.
16676 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
16677 * @xritag: the xritag that ties this io to the SGL pages.
16679 * This routine will post the sgl pages for the IO that has the xritag
16680 * that is in the iocbq structure. The xritag is assigned during iocbq
16681 * creation and persists for as long as the driver is loaded.
16682 * if the caller has fewer than 256 scatter gather segments to map then
16683 * pdma_phys_addr1 should be 0.
16684 * If the caller needs to map more than 256 scatter gather segment then
16685 * pdma_phys_addr1 should be a valid physical address.
16686 * physical address for SGLs must be 64 byte aligned.
16687 * If you are going to map 2 SGL's then the first one must have 256 entries
16688 * the second sgl can have between 1 and 256 entries.
16692 * -ENXIO, -ENOMEM - Failure
16695 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
16696 dma_addr_t pdma_phys_addr0,
16697 dma_addr_t pdma_phys_addr1,
16700 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
16701 LPFC_MBOXQ_t *mbox;
16703 uint32_t shdr_status, shdr_add_status;
16705 union lpfc_sli4_cfg_shdr *shdr;
16707 if (xritag == NO_XRI) {
16708 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16709 "0364 Invalid param:\n");
16713 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16717 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16718 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
16719 sizeof(struct lpfc_mbx_post_sgl_pages) -
16720 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
16722 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
16723 &mbox->u.mqe.un.post_sgl_pages;
16724 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
16725 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
16727 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
16728 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
16729 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
16730 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
16732 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
16733 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
16734 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
16735 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
16736 if (!phba->sli4_hba.intr_enable)
16737 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16739 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
16740 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
16742 /* The IOCTL status is embedded in the mailbox subheader. */
16743 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
16744 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16745 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16746 if (rc != MBX_TIMEOUT)
16747 mempool_free(mbox, phba->mbox_mem_pool);
16748 if (shdr_status || shdr_add_status || rc) {
16749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16750 "2511 POST_SGL mailbox failed with "
16751 "status x%x add_status x%x, mbx status x%x\n",
16752 shdr_status, shdr_add_status, rc);
16758 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
16759 * @phba: pointer to lpfc hba data structure.
16761 * This routine is invoked to post rpi header templates to the
16762 * HBA consistent with the SLI-4 interface spec. This routine
16763 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
16764 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
16767 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
16768 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
16771 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
16776 * Fetch the next logical xri. Because this index is logical,
16777 * the driver starts at 0 each time.
16779 spin_lock_irq(&phba->hbalock);
16780 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
16781 phba->sli4_hba.max_cfg_param.max_xri, 0);
16782 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
16783 spin_unlock_irq(&phba->hbalock);
16786 set_bit(xri, phba->sli4_hba.xri_bmask);
16787 phba->sli4_hba.max_cfg_param.xri_used++;
16789 spin_unlock_irq(&phba->hbalock);
16794 * lpfc_sli4_free_xri - Release an xri for reuse.
16795 * @phba: pointer to lpfc hba data structure.
16797 * This routine is invoked to release an xri to the pool of
16798 * available rpis maintained by the driver.
16801 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
16803 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
16804 phba->sli4_hba.max_cfg_param.xri_used--;
16809 * lpfc_sli4_free_xri - Release an xri for reuse.
16810 * @phba: pointer to lpfc hba data structure.
16812 * This routine is invoked to release an xri to the pool of
16813 * available rpis maintained by the driver.
16816 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
16818 spin_lock_irq(&phba->hbalock);
16819 __lpfc_sli4_free_xri(phba, xri);
16820 spin_unlock_irq(&phba->hbalock);
16824 * lpfc_sli4_next_xritag - Get an xritag for the io
16825 * @phba: Pointer to HBA context object.
16827 * This function gets an xritag for the iocb. If there is no unused xritag
16828 * it will return 0xffff.
16829 * The function returns the allocated xritag if successful, else returns zero.
16830 * Zero is not a valid xritag.
16831 * The caller is not required to hold any lock.
16834 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
16836 uint16_t xri_index;
16838 xri_index = lpfc_sli4_alloc_xri(phba);
16839 if (xri_index == NO_XRI)
16840 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
16841 "2004 Failed to allocate XRI.last XRITAG is %d"
16842 " Max XRI is %d, Used XRI is %d\n",
16844 phba->sli4_hba.max_cfg_param.max_xri,
16845 phba->sli4_hba.max_cfg_param.xri_used);
16850 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
16851 * @phba: pointer to lpfc hba data structure.
16852 * @post_sgl_list: pointer to els sgl entry list.
16853 * @count: number of els sgl entries on the list.
16855 * This routine is invoked to post a block of driver's sgl pages to the
16856 * HBA using non-embedded mailbox command. No Lock is held. This routine
16857 * is only called when the driver is loading and after all IO has been
16861 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
16862 struct list_head *post_sgl_list,
16865 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
16866 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
16867 struct sgl_page_pairs *sgl_pg_pairs;
16869 LPFC_MBOXQ_t *mbox;
16870 uint32_t reqlen, alloclen, pg_pairs;
16872 uint16_t xritag_start = 0;
16874 uint32_t shdr_status, shdr_add_status;
16875 union lpfc_sli4_cfg_shdr *shdr;
16877 reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
16878 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
16879 if (reqlen > SLI4_PAGE_SIZE) {
16880 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16881 "2559 Block sgl registration required DMA "
16882 "size (%d) great than a page\n", reqlen);
16886 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16890 /* Allocate DMA memory and set up the non-embedded mailbox command */
16891 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16892 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
16893 LPFC_SLI4_MBX_NEMBED);
16895 if (alloclen < reqlen) {
16896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16897 "0285 Allocated DMA memory size (%d) is "
16898 "less than the requested DMA memory "
16899 "size (%d)\n", alloclen, reqlen);
16900 lpfc_sli4_mbox_cmd_free(phba, mbox);
16903 /* Set up the SGL pages in the non-embedded DMA pages */
16904 viraddr = mbox->sge_array->addr[0];
16905 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
16906 sgl_pg_pairs = &sgl->sgl_pg_pairs;
16909 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
16910 /* Set up the sge entry */
16911 sgl_pg_pairs->sgl_pg0_addr_lo =
16912 cpu_to_le32(putPaddrLow(sglq_entry->phys));
16913 sgl_pg_pairs->sgl_pg0_addr_hi =
16914 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
16915 sgl_pg_pairs->sgl_pg1_addr_lo =
16916 cpu_to_le32(putPaddrLow(0));
16917 sgl_pg_pairs->sgl_pg1_addr_hi =
16918 cpu_to_le32(putPaddrHigh(0));
16920 /* Keep the first xritag on the list */
16922 xritag_start = sglq_entry->sli4_xritag;
16927 /* Complete initialization and perform endian conversion. */
16928 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
16929 bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
16930 sgl->word0 = cpu_to_le32(sgl->word0);
16932 if (!phba->sli4_hba.intr_enable)
16933 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16935 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
16936 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
16938 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
16939 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16940 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16941 if (rc != MBX_TIMEOUT)
16942 lpfc_sli4_mbox_cmd_free(phba, mbox);
16943 if (shdr_status || shdr_add_status || rc) {
16944 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
16945 "2513 POST_SGL_BLOCK mailbox command failed "
16946 "status x%x add_status x%x mbx status x%x\n",
16947 shdr_status, shdr_add_status, rc);
16954 * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
16955 * @phba: pointer to lpfc hba data structure.
16956 * @nblist: pointer to nvme buffer list.
16957 * @count: number of scsi buffers on the list.
16959 * This routine is invoked to post a block of @count scsi sgl pages from a
16960 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
16965 lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
16968 struct lpfc_io_buf *lpfc_ncmd;
16969 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
16970 struct sgl_page_pairs *sgl_pg_pairs;
16972 LPFC_MBOXQ_t *mbox;
16973 uint32_t reqlen, alloclen, pg_pairs;
16975 uint16_t xritag_start = 0;
16977 uint32_t shdr_status, shdr_add_status;
16978 dma_addr_t pdma_phys_bpl1;
16979 union lpfc_sli4_cfg_shdr *shdr;
16981 /* Calculate the requested length of the dma memory */
16982 reqlen = count * sizeof(struct sgl_page_pairs) +
16983 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
16984 if (reqlen > SLI4_PAGE_SIZE) {
16985 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
16986 "6118 Block sgl registration required DMA "
16987 "size (%d) great than a page\n", reqlen);
16990 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16992 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16993 "6119 Failed to allocate mbox cmd memory\n");
16997 /* Allocate DMA memory and set up the non-embedded mailbox command */
16998 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16999 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
17000 reqlen, LPFC_SLI4_MBX_NEMBED);
17002 if (alloclen < reqlen) {
17003 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17004 "6120 Allocated DMA memory size (%d) is "
17005 "less than the requested DMA memory "
17006 "size (%d)\n", alloclen, reqlen);
17007 lpfc_sli4_mbox_cmd_free(phba, mbox);
17011 /* Get the first SGE entry from the non-embedded DMA memory */
17012 viraddr = mbox->sge_array->addr[0];
17014 /* Set up the SGL pages in the non-embedded DMA pages */
17015 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
17016 sgl_pg_pairs = &sgl->sgl_pg_pairs;
17019 list_for_each_entry(lpfc_ncmd, nblist, list) {
17020 /* Set up the sge entry */
17021 sgl_pg_pairs->sgl_pg0_addr_lo =
17022 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
17023 sgl_pg_pairs->sgl_pg0_addr_hi =
17024 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
17025 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
17026 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
17029 pdma_phys_bpl1 = 0;
17030 sgl_pg_pairs->sgl_pg1_addr_lo =
17031 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
17032 sgl_pg_pairs->sgl_pg1_addr_hi =
17033 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
17034 /* Keep the first xritag on the list */
17036 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
17040 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
17041 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
17042 /* Perform endian conversion if necessary */
17043 sgl->word0 = cpu_to_le32(sgl->word0);
17045 if (!phba->sli4_hba.intr_enable) {
17046 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17048 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17049 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17051 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
17052 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17053 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17054 if (rc != MBX_TIMEOUT)
17055 lpfc_sli4_mbox_cmd_free(phba, mbox);
17056 if (shdr_status || shdr_add_status || rc) {
17057 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17058 "6125 POST_SGL_BLOCK mailbox command failed "
17059 "status x%x add_status x%x mbx status x%x\n",
17060 shdr_status, shdr_add_status, rc);
17067 * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
17068 * @phba: pointer to lpfc hba data structure.
17069 * @post_nblist: pointer to the nvme buffer list.
17071 * This routine walks a list of nvme buffers that was passed in. It attempts
17072 * to construct blocks of nvme buffer sgls which contains contiguous xris and
17073 * uses the non-embedded SGL block post mailbox commands to post to the port.
17074 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
17075 * embedded SGL post mailbox command for posting. The @post_nblist passed in
17076 * must be local list, thus no lock is needed when manipulate the list.
17078 * Returns: 0 = failure, non-zero number of successfully posted buffers.
17081 lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
17082 struct list_head *post_nblist, int sb_count)
17084 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
17085 int status, sgl_size;
17086 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
17087 dma_addr_t pdma_phys_sgl1;
17088 int last_xritag = NO_XRI;
17090 LIST_HEAD(prep_nblist);
17091 LIST_HEAD(blck_nblist);
17092 LIST_HEAD(nvme_nblist);
17098 sgl_size = phba->cfg_sg_dma_buf_size;
17099 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
17100 list_del_init(&lpfc_ncmd->list);
17102 if ((last_xritag != NO_XRI) &&
17103 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
17104 /* a hole in xri block, form a sgl posting block */
17105 list_splice_init(&prep_nblist, &blck_nblist);
17106 post_cnt = block_cnt - 1;
17107 /* prepare list for next posting block */
17108 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
17111 /* prepare list for next posting block */
17112 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
17113 /* enough sgls for non-embed sgl mbox command */
17114 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
17115 list_splice_init(&prep_nblist, &blck_nblist);
17116 post_cnt = block_cnt;
17121 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
17123 /* end of repost sgl list condition for NVME buffers */
17124 if (num_posting == sb_count) {
17125 if (post_cnt == 0) {
17126 /* last sgl posting block */
17127 list_splice_init(&prep_nblist, &blck_nblist);
17128 post_cnt = block_cnt;
17129 } else if (block_cnt == 1) {
17130 /* last single sgl with non-contiguous xri */
17131 if (sgl_size > SGL_PAGE_SIZE)
17133 lpfc_ncmd->dma_phys_sgl +
17136 pdma_phys_sgl1 = 0;
17137 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
17138 status = lpfc_sli4_post_sgl(
17139 phba, lpfc_ncmd->dma_phys_sgl,
17140 pdma_phys_sgl1, cur_xritag);
17142 /* Post error. Buffer unavailable. */
17143 lpfc_ncmd->flags |=
17144 LPFC_SBUF_NOT_POSTED;
17146 /* Post success. Bffer available. */
17147 lpfc_ncmd->flags &=
17148 ~LPFC_SBUF_NOT_POSTED;
17149 lpfc_ncmd->status = IOSTAT_SUCCESS;
17152 /* success, put on NVME buffer sgl list */
17153 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
17157 /* continue until a nembed page worth of sgls */
17161 /* post block of NVME buffer list sgls */
17162 status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
17165 /* don't reset xirtag due to hole in xri block */
17166 if (block_cnt == 0)
17167 last_xritag = NO_XRI;
17169 /* reset NVME buffer post count for next round of posting */
17172 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
17173 while (!list_empty(&blck_nblist)) {
17174 list_remove_head(&blck_nblist, lpfc_ncmd,
17175 struct lpfc_io_buf, list);
17177 /* Post error. Mark buffer unavailable. */
17178 lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
17180 /* Post success, Mark buffer available. */
17181 lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
17182 lpfc_ncmd->status = IOSTAT_SUCCESS;
17185 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
17188 /* Push NVME buffers with sgl posted to the available list */
17189 lpfc_io_buf_replenish(phba, &nvme_nblist);
17195 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
17196 * @phba: pointer to lpfc_hba struct that the frame was received on
17197 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
17199 * This function checks the fields in the @fc_hdr to see if the FC frame is a
17200 * valid type of frame that the LPFC driver will handle. This function will
17201 * return a zero if the frame is a valid frame or a non zero value when the
17202 * frame does not pass the check.
17205 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
17207 /* make rctl_names static to save stack space */
17208 struct fc_vft_header *fc_vft_hdr;
17209 uint32_t *header = (uint32_t *) fc_hdr;
17211 #define FC_RCTL_MDS_DIAGS 0xF4
17213 switch (fc_hdr->fh_r_ctl) {
17214 case FC_RCTL_DD_UNCAT: /* uncategorized information */
17215 case FC_RCTL_DD_SOL_DATA: /* solicited data */
17216 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
17217 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
17218 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
17219 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
17220 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
17221 case FC_RCTL_DD_CMD_STATUS: /* command status */
17222 case FC_RCTL_ELS_REQ: /* extended link services request */
17223 case FC_RCTL_ELS_REP: /* extended link services reply */
17224 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
17225 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
17226 case FC_RCTL_BA_NOP: /* basic link service NOP */
17227 case FC_RCTL_BA_ABTS: /* basic link service abort */
17228 case FC_RCTL_BA_RMC: /* remove connection */
17229 case FC_RCTL_BA_ACC: /* basic accept */
17230 case FC_RCTL_BA_RJT: /* basic reject */
17231 case FC_RCTL_BA_PRMT:
17232 case FC_RCTL_ACK_1: /* acknowledge_1 */
17233 case FC_RCTL_ACK_0: /* acknowledge_0 */
17234 case FC_RCTL_P_RJT: /* port reject */
17235 case FC_RCTL_F_RJT: /* fabric reject */
17236 case FC_RCTL_P_BSY: /* port busy */
17237 case FC_RCTL_F_BSY: /* fabric busy to data frame */
17238 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
17239 case FC_RCTL_LCR: /* link credit reset */
17240 case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
17241 case FC_RCTL_END: /* end */
17243 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
17244 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
17245 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
17246 return lpfc_fc_frame_check(phba, fc_hdr);
17251 switch (fc_hdr->fh_type) {
17264 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
17265 "2538 Received frame rctl:x%x, type:x%x, "
17266 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
17267 fc_hdr->fh_r_ctl, fc_hdr->fh_type,
17268 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
17269 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
17270 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
17271 be32_to_cpu(header[6]));
17274 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
17275 "2539 Dropped frame rctl:x%x type:x%x\n",
17276 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
17281 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
17282 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
17284 * This function processes the FC header to retrieve the VFI from the VF
17285 * header, if one exists. This function will return the VFI if one exists
17286 * or 0 if no VSAN Header exists.
17289 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
17291 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
17293 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
17295 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
17299 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
17300 * @phba: Pointer to the HBA structure to search for the vport on
17301 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
17302 * @fcfi: The FC Fabric ID that the frame came from
17304 * This function searches the @phba for a vport that matches the content of the
17305 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
17306 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
17307 * returns the matching vport pointer or NULL if unable to match frame to a
17310 static struct lpfc_vport *
17311 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
17312 uint16_t fcfi, uint32_t did)
17314 struct lpfc_vport **vports;
17315 struct lpfc_vport *vport = NULL;
17318 if (did == Fabric_DID)
17319 return phba->pport;
17320 if ((phba->pport->fc_flag & FC_PT2PT) &&
17321 !(phba->link_state == LPFC_HBA_READY))
17322 return phba->pport;
17324 vports = lpfc_create_vport_work_array(phba);
17325 if (vports != NULL) {
17326 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
17327 if (phba->fcf.fcfi == fcfi &&
17328 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
17329 vports[i]->fc_myDID == did) {
17335 lpfc_destroy_vport_work_array(phba, vports);
17340 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
17341 * @vport: The vport to work on.
17343 * This function updates the receive sequence time stamp for this vport. The
17344 * receive sequence time stamp indicates the time that the last frame of the
17345 * the sequence that has been idle for the longest amount of time was received.
17346 * the driver uses this time stamp to indicate if any received sequences have
17350 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
17352 struct lpfc_dmabuf *h_buf;
17353 struct hbq_dmabuf *dmabuf = NULL;
17355 /* get the oldest sequence on the rcv list */
17356 h_buf = list_get_first(&vport->rcv_buffer_list,
17357 struct lpfc_dmabuf, list);
17360 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17361 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
17365 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
17366 * @vport: The vport that the received sequences were sent to.
17368 * This function cleans up all outstanding received sequences. This is called
17369 * by the driver when a link event or user action invalidates all the received
17373 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
17375 struct lpfc_dmabuf *h_buf, *hnext;
17376 struct lpfc_dmabuf *d_buf, *dnext;
17377 struct hbq_dmabuf *dmabuf = NULL;
17379 /* start with the oldest sequence on the rcv list */
17380 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
17381 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17382 list_del_init(&dmabuf->hbuf.list);
17383 list_for_each_entry_safe(d_buf, dnext,
17384 &dmabuf->dbuf.list, list) {
17385 list_del_init(&d_buf->list);
17386 lpfc_in_buf_free(vport->phba, d_buf);
17388 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
17393 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
17394 * @vport: The vport that the received sequences were sent to.
17396 * This function determines whether any received sequences have timed out by
17397 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
17398 * indicates that there is at least one timed out sequence this routine will
17399 * go through the received sequences one at a time from most inactive to most
17400 * active to determine which ones need to be cleaned up. Once it has determined
17401 * that a sequence needs to be cleaned up it will simply free up the resources
17402 * without sending an abort.
17405 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
17407 struct lpfc_dmabuf *h_buf, *hnext;
17408 struct lpfc_dmabuf *d_buf, *dnext;
17409 struct hbq_dmabuf *dmabuf = NULL;
17410 unsigned long timeout;
17411 int abort_count = 0;
17413 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
17414 vport->rcv_buffer_time_stamp);
17415 if (list_empty(&vport->rcv_buffer_list) ||
17416 time_before(jiffies, timeout))
17418 /* start with the oldest sequence on the rcv list */
17419 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
17420 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17421 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
17422 dmabuf->time_stamp);
17423 if (time_before(jiffies, timeout))
17426 list_del_init(&dmabuf->hbuf.list);
17427 list_for_each_entry_safe(d_buf, dnext,
17428 &dmabuf->dbuf.list, list) {
17429 list_del_init(&d_buf->list);
17430 lpfc_in_buf_free(vport->phba, d_buf);
17432 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
17435 lpfc_update_rcv_time_stamp(vport);
17439 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
17440 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
17442 * This function searches through the existing incomplete sequences that have
17443 * been sent to this @vport. If the frame matches one of the incomplete
17444 * sequences then the dbuf in the @dmabuf is added to the list of frames that
17445 * make up that sequence. If no sequence is found that matches this frame then
17446 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
17447 * This function returns a pointer to the first dmabuf in the sequence list that
17448 * the frame was linked to.
17450 static struct hbq_dmabuf *
17451 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
17453 struct fc_frame_header *new_hdr;
17454 struct fc_frame_header *temp_hdr;
17455 struct lpfc_dmabuf *d_buf;
17456 struct lpfc_dmabuf *h_buf;
17457 struct hbq_dmabuf *seq_dmabuf = NULL;
17458 struct hbq_dmabuf *temp_dmabuf = NULL;
17461 INIT_LIST_HEAD(&dmabuf->dbuf.list);
17462 dmabuf->time_stamp = jiffies;
17463 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17465 /* Use the hdr_buf to find the sequence that this frame belongs to */
17466 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
17467 temp_hdr = (struct fc_frame_header *)h_buf->virt;
17468 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
17469 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
17470 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
17472 /* found a pending sequence that matches this frame */
17473 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17478 * This indicates first frame received for this sequence.
17479 * Queue the buffer on the vport's rcv_buffer_list.
17481 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
17482 lpfc_update_rcv_time_stamp(vport);
17485 temp_hdr = seq_dmabuf->hbuf.virt;
17486 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
17487 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
17488 list_del_init(&seq_dmabuf->hbuf.list);
17489 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
17490 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
17491 lpfc_update_rcv_time_stamp(vport);
17494 /* move this sequence to the tail to indicate a young sequence */
17495 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
17496 seq_dmabuf->time_stamp = jiffies;
17497 lpfc_update_rcv_time_stamp(vport);
17498 if (list_empty(&seq_dmabuf->dbuf.list)) {
17499 temp_hdr = dmabuf->hbuf.virt;
17500 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
17503 /* find the correct place in the sequence to insert this frame */
17504 d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
17506 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17507 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
17509 * If the frame's sequence count is greater than the frame on
17510 * the list then insert the frame right after this frame
17512 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
17513 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
17514 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
17519 if (&d_buf->list == &seq_dmabuf->dbuf.list)
17521 d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
17530 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
17531 * @vport: pointer to a vitural port
17532 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17534 * This function tries to abort from the partially assembed sequence, described
17535 * by the information from basic abbort @dmabuf. It checks to see whether such
17536 * partially assembled sequence held by the driver. If so, it shall free up all
17537 * the frames from the partially assembled sequence.
17540 * true -- if there is matching partially assembled sequence present and all
17541 * the frames freed with the sequence;
17542 * false -- if there is no matching partially assembled sequence present so
17543 * nothing got aborted in the lower layer driver
17546 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
17547 struct hbq_dmabuf *dmabuf)
17549 struct fc_frame_header *new_hdr;
17550 struct fc_frame_header *temp_hdr;
17551 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
17552 struct hbq_dmabuf *seq_dmabuf = NULL;
17554 /* Use the hdr_buf to find the sequence that matches this frame */
17555 INIT_LIST_HEAD(&dmabuf->dbuf.list);
17556 INIT_LIST_HEAD(&dmabuf->hbuf.list);
17557 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17558 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
17559 temp_hdr = (struct fc_frame_header *)h_buf->virt;
17560 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
17561 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
17562 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
17564 /* found a pending sequence that matches this frame */
17565 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17569 /* Free up all the frames from the partially assembled sequence */
17571 list_for_each_entry_safe(d_buf, n_buf,
17572 &seq_dmabuf->dbuf.list, list) {
17573 list_del_init(&d_buf->list);
17574 lpfc_in_buf_free(vport->phba, d_buf);
17582 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
17583 * @vport: pointer to a vitural port
17584 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17586 * This function tries to abort from the assembed sequence from upper level
17587 * protocol, described by the information from basic abbort @dmabuf. It
17588 * checks to see whether such pending context exists at upper level protocol.
17589 * If so, it shall clean up the pending context.
17592 * true -- if there is matching pending context of the sequence cleaned
17594 * false -- if there is no matching pending context of the sequence present
17598 lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
17600 struct lpfc_hba *phba = vport->phba;
17603 /* Accepting abort at ulp with SLI4 only */
17604 if (phba->sli_rev < LPFC_SLI_REV4)
17607 /* Register all caring upper level protocols to attend abort */
17608 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
17616 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
17617 * @phba: Pointer to HBA context object.
17618 * @cmd_iocbq: pointer to the command iocbq structure.
17619 * @rsp_iocbq: pointer to the response iocbq structure.
17621 * This function handles the sequence abort response iocb command complete
17622 * event. It properly releases the memory allocated to the sequence abort
17626 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
17627 struct lpfc_iocbq *cmd_iocbq,
17628 struct lpfc_iocbq *rsp_iocbq)
17630 struct lpfc_nodelist *ndlp;
17633 ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
17634 lpfc_nlp_put(ndlp);
17635 lpfc_nlp_not_used(ndlp);
17636 lpfc_sli_release_iocbq(phba, cmd_iocbq);
17639 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
17640 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
17641 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
17642 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
17643 rsp_iocbq->iocb.ulpStatus,
17644 rsp_iocbq->iocb.un.ulpWord[4]);
17648 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
17649 * @phba: Pointer to HBA context object.
17650 * @xri: xri id in transaction.
17652 * This function validates the xri maps to the known range of XRIs allocated an
17653 * used by the driver.
17656 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
17661 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
17662 if (xri == phba->sli4_hba.xri_ids[i])
17669 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
17670 * @phba: Pointer to HBA context object.
17671 * @fc_hdr: pointer to a FC frame header.
17673 * This function sends a basic response to a previous unsol sequence abort
17674 * event after aborting the sequence handling.
17677 lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
17678 struct fc_frame_header *fc_hdr, bool aborted)
17680 struct lpfc_hba *phba = vport->phba;
17681 struct lpfc_iocbq *ctiocb = NULL;
17682 struct lpfc_nodelist *ndlp;
17683 uint16_t oxid, rxid, xri, lxri;
17684 uint32_t sid, fctl;
17688 if (!lpfc_is_link_up(phba))
17691 sid = sli4_sid_from_fc_hdr(fc_hdr);
17692 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
17693 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
17695 ndlp = lpfc_findnode_did(vport, sid);
17697 ndlp = lpfc_nlp_init(vport, sid);
17699 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
17700 "1268 Failed to allocate ndlp for "
17701 "oxid:x%x SID:x%x\n", oxid, sid);
17704 /* Put ndlp onto pport node list */
17705 lpfc_enqueue_node(vport, ndlp);
17706 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
17707 /* re-setup ndlp without removing from node list */
17708 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
17710 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
17711 "3275 Failed to active ndlp found "
17712 "for oxid:x%x SID:x%x\n", oxid, sid);
17717 /* Allocate buffer for rsp iocb */
17718 ctiocb = lpfc_sli_get_iocbq(phba);
17722 /* Extract the F_CTL field from FC_HDR */
17723 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
17725 icmd = &ctiocb->iocb;
17726 icmd->un.xseq64.bdl.bdeSize = 0;
17727 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
17728 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
17729 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
17730 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
17732 /* Fill in the rest of iocb fields */
17733 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
17734 icmd->ulpBdeCount = 0;
17736 icmd->ulpClass = CLASS3;
17737 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
17738 ctiocb->context1 = lpfc_nlp_get(ndlp);
17740 ctiocb->vport = phba->pport;
17741 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
17742 ctiocb->sli4_lxritag = NO_XRI;
17743 ctiocb->sli4_xritag = NO_XRI;
17745 if (fctl & FC_FC_EX_CTX)
17746 /* Exchange responder sent the abort so we
17752 lxri = lpfc_sli4_xri_inrange(phba, xri);
17753 if (lxri != NO_XRI)
17754 lpfc_set_rrq_active(phba, ndlp, lxri,
17755 (xri == oxid) ? rxid : oxid, 0);
17756 /* For BA_ABTS from exchange responder, if the logical xri with
17757 * the oxid maps to the FCP XRI range, the port no longer has
17758 * that exchange context, send a BLS_RJT. Override the IOCB for
17761 if ((fctl & FC_FC_EX_CTX) &&
17762 (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
17763 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
17764 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
17765 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
17766 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
17769 /* If BA_ABTS failed to abort a partially assembled receive sequence,
17770 * the driver no longer has that exchange, send a BLS_RJT. Override
17771 * the IOCB for a BA_RJT.
17773 if (aborted == false) {
17774 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
17775 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
17776 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
17777 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
17780 if (fctl & FC_FC_EX_CTX) {
17781 /* ABTS sent by responder to CT exchange, construction
17782 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
17783 * field and RX_ID from ABTS for RX_ID field.
17785 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
17787 /* ABTS sent by initiator to CT exchange, construction
17788 * of BA_ACC will need to allocate a new XRI as for the
17791 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
17793 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
17794 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
17796 /* Xmit CT abts response on exchange <xid> */
17797 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
17798 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
17799 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
17801 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
17802 if (rc == IOCB_ERROR) {
17803 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
17804 "2925 Failed to issue CT ABTS RSP x%x on "
17805 "xri x%x, Data x%x\n",
17806 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
17808 lpfc_nlp_put(ndlp);
17809 ctiocb->context1 = NULL;
17810 lpfc_sli_release_iocbq(phba, ctiocb);
17815 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
17816 * @vport: Pointer to the vport on which this sequence was received
17817 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17819 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
17820 * receive sequence is only partially assembed by the driver, it shall abort
17821 * the partially assembled frames for the sequence. Otherwise, if the
17822 * unsolicited receive sequence has been completely assembled and passed to
17823 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
17824 * unsolicited sequence has been aborted. After that, it will issue a basic
17825 * accept to accept the abort.
17828 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
17829 struct hbq_dmabuf *dmabuf)
17831 struct lpfc_hba *phba = vport->phba;
17832 struct fc_frame_header fc_hdr;
17836 /* Make a copy of fc_hdr before the dmabuf being released */
17837 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
17838 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
17840 if (fctl & FC_FC_EX_CTX) {
17841 /* ABTS by responder to exchange, no cleanup needed */
17844 /* ABTS by initiator to exchange, need to do cleanup */
17845 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
17846 if (aborted == false)
17847 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
17849 lpfc_in_buf_free(phba, &dmabuf->dbuf);
17851 if (phba->nvmet_support) {
17852 lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
17856 /* Respond with BA_ACC or BA_RJT accordingly */
17857 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
17861 * lpfc_seq_complete - Indicates if a sequence is complete
17862 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17864 * This function checks the sequence, starting with the frame described by
17865 * @dmabuf, to see if all the frames associated with this sequence are present.
17866 * the frames associated with this sequence are linked to the @dmabuf using the
17867 * dbuf list. This function looks for two major things. 1) That the first frame
17868 * has a sequence count of zero. 2) There is a frame with last frame of sequence
17869 * set. 3) That there are no holes in the sequence count. The function will
17870 * return 1 when the sequence is complete, otherwise it will return 0.
17873 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
17875 struct fc_frame_header *hdr;
17876 struct lpfc_dmabuf *d_buf;
17877 struct hbq_dmabuf *seq_dmabuf;
17881 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17882 /* make sure first fame of sequence has a sequence count of zero */
17883 if (hdr->fh_seq_cnt != seq_count)
17885 fctl = (hdr->fh_f_ctl[0] << 16 |
17886 hdr->fh_f_ctl[1] << 8 |
17888 /* If last frame of sequence we can return success. */
17889 if (fctl & FC_FC_END_SEQ)
17891 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
17892 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17893 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
17894 /* If there is a hole in the sequence count then fail. */
17895 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
17897 fctl = (hdr->fh_f_ctl[0] << 16 |
17898 hdr->fh_f_ctl[1] << 8 |
17900 /* If last frame of sequence we can return success. */
17901 if (fctl & FC_FC_END_SEQ)
17908 * lpfc_prep_seq - Prep sequence for ULP processing
17909 * @vport: Pointer to the vport on which this sequence was received
17910 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17912 * This function takes a sequence, described by a list of frames, and creates
17913 * a list of iocbq structures to describe the sequence. This iocbq list will be
17914 * used to issue to the generic unsolicited sequence handler. This routine
17915 * returns a pointer to the first iocbq in the list. If the function is unable
17916 * to allocate an iocbq then it throw out the received frames that were not
17917 * able to be described and return a pointer to the first iocbq. If unable to
17918 * allocate any iocbqs (including the first) this function will return NULL.
17920 static struct lpfc_iocbq *
17921 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
17923 struct hbq_dmabuf *hbq_buf;
17924 struct lpfc_dmabuf *d_buf, *n_buf;
17925 struct lpfc_iocbq *first_iocbq, *iocbq;
17926 struct fc_frame_header *fc_hdr;
17928 uint32_t len, tot_len;
17929 struct ulp_bde64 *pbde;
17931 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
17932 /* remove from receive buffer list */
17933 list_del_init(&seq_dmabuf->hbuf.list);
17934 lpfc_update_rcv_time_stamp(vport);
17935 /* get the Remote Port's SID */
17936 sid = sli4_sid_from_fc_hdr(fc_hdr);
17938 /* Get an iocbq struct to fill in. */
17939 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
17941 /* Initialize the first IOCB. */
17942 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
17943 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
17944 first_iocbq->vport = vport;
17946 /* Check FC Header to see what TYPE of frame we are rcv'ing */
17947 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
17948 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
17949 first_iocbq->iocb.un.rcvels.parmRo =
17950 sli4_did_from_fc_hdr(fc_hdr);
17951 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
17953 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
17954 first_iocbq->iocb.ulpContext = NO_XRI;
17955 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
17956 be16_to_cpu(fc_hdr->fh_ox_id);
17957 /* iocbq is prepped for internal consumption. Physical vpi. */
17958 first_iocbq->iocb.unsli3.rcvsli3.vpi =
17959 vport->phba->vpi_ids[vport->vpi];
17960 /* put the first buffer into the first IOCBq */
17961 tot_len = bf_get(lpfc_rcqe_length,
17962 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
17964 first_iocbq->context2 = &seq_dmabuf->dbuf;
17965 first_iocbq->context3 = NULL;
17966 first_iocbq->iocb.ulpBdeCount = 1;
17967 if (tot_len > LPFC_DATA_BUF_SIZE)
17968 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
17969 LPFC_DATA_BUF_SIZE;
17971 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
17973 first_iocbq->iocb.un.rcvels.remoteID = sid;
17975 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
17977 iocbq = first_iocbq;
17979 * Each IOCBq can have two Buffers assigned, so go through the list
17980 * of buffers for this sequence and save two buffers in each IOCBq
17982 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
17984 lpfc_in_buf_free(vport->phba, d_buf);
17987 if (!iocbq->context3) {
17988 iocbq->context3 = d_buf;
17989 iocbq->iocb.ulpBdeCount++;
17990 /* We need to get the size out of the right CQE */
17991 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17992 len = bf_get(lpfc_rcqe_length,
17993 &hbq_buf->cq_event.cqe.rcqe_cmpl);
17994 pbde = (struct ulp_bde64 *)
17995 &iocbq->iocb.unsli3.sli3Words[4];
17996 if (len > LPFC_DATA_BUF_SIZE)
17997 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
17999 pbde->tus.f.bdeSize = len;
18001 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
18004 iocbq = lpfc_sli_get_iocbq(vport->phba);
18007 first_iocbq->iocb.ulpStatus =
18008 IOSTAT_FCP_RSP_ERROR;
18009 first_iocbq->iocb.un.ulpWord[4] =
18010 IOERR_NO_RESOURCES;
18012 lpfc_in_buf_free(vport->phba, d_buf);
18015 /* We need to get the size out of the right CQE */
18016 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
18017 len = bf_get(lpfc_rcqe_length,
18018 &hbq_buf->cq_event.cqe.rcqe_cmpl);
18019 iocbq->context2 = d_buf;
18020 iocbq->context3 = NULL;
18021 iocbq->iocb.ulpBdeCount = 1;
18022 if (len > LPFC_DATA_BUF_SIZE)
18023 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
18024 LPFC_DATA_BUF_SIZE;
18026 iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
18029 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
18031 iocbq->iocb.un.rcvels.remoteID = sid;
18032 list_add_tail(&iocbq->list, &first_iocbq->list);
18035 /* Free the sequence's header buffer */
18037 lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf);
18039 return first_iocbq;
18043 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
18044 struct hbq_dmabuf *seq_dmabuf)
18046 struct fc_frame_header *fc_hdr;
18047 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
18048 struct lpfc_hba *phba = vport->phba;
18050 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
18051 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
18053 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18054 "2707 Ring %d handler: Failed to allocate "
18055 "iocb Rctl x%x Type x%x received\n",
18057 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
18060 if (!lpfc_complete_unsol_iocb(phba,
18061 phba->sli4_hba.els_wq->pring,
18062 iocbq, fc_hdr->fh_r_ctl,
18064 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18065 "2540 Ring %d handler: unexpected Rctl "
18066 "x%x Type x%x received\n",
18068 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
18070 /* Free iocb created in lpfc_prep_seq */
18071 list_for_each_entry_safe(curr_iocb, next_iocb,
18072 &iocbq->list, list) {
18073 list_del_init(&curr_iocb->list);
18074 lpfc_sli_release_iocbq(phba, curr_iocb);
18076 lpfc_sli_release_iocbq(phba, iocbq);
18080 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
18081 struct lpfc_iocbq *rspiocb)
18083 struct lpfc_dmabuf *pcmd = cmdiocb->context2;
18085 if (pcmd && pcmd->virt)
18086 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
18088 lpfc_sli_release_iocbq(phba, cmdiocb);
18089 lpfc_drain_txq(phba);
18093 lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
18094 struct hbq_dmabuf *dmabuf)
18096 struct fc_frame_header *fc_hdr;
18097 struct lpfc_hba *phba = vport->phba;
18098 struct lpfc_iocbq *iocbq = NULL;
18099 union lpfc_wqe *wqe;
18100 struct lpfc_dmabuf *pcmd = NULL;
18101 uint32_t frame_len;
18103 unsigned long iflags;
18105 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18106 frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
18108 /* Send the received frame back */
18109 iocbq = lpfc_sli_get_iocbq(phba);
18111 /* Queue cq event and wakeup worker thread to process it */
18112 spin_lock_irqsave(&phba->hbalock, iflags);
18113 list_add_tail(&dmabuf->cq_event.list,
18114 &phba->sli4_hba.sp_queue_event);
18115 phba->hba_flag |= HBA_SP_QUEUE_EVT;
18116 spin_unlock_irqrestore(&phba->hbalock, iflags);
18117 lpfc_worker_wake_up(phba);
18121 /* Allocate buffer for command payload */
18122 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
18124 pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
18126 if (!pcmd || !pcmd->virt)
18129 INIT_LIST_HEAD(&pcmd->list);
18131 /* copyin the payload */
18132 memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
18134 /* fill in BDE's for command */
18135 iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys);
18136 iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys);
18137 iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
18138 iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len;
18140 iocbq->context2 = pcmd;
18141 iocbq->vport = vport;
18142 iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
18143 iocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
18146 * Setup rest of the iocb as though it were a WQE
18147 * Build the SEND_FRAME WQE
18149 wqe = (union lpfc_wqe *)&iocbq->iocb;
18151 wqe->send_frame.frame_len = frame_len;
18152 wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr));
18153 wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1));
18154 wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2));
18155 wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3));
18156 wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4));
18157 wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5));
18159 iocbq->iocb.ulpCommand = CMD_SEND_FRAME;
18160 iocbq->iocb.ulpLe = 1;
18161 iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl;
18162 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
18163 if (rc == IOCB_ERROR)
18166 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18170 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
18171 "2023 Unable to process MDS loopback frame\n");
18172 if (pcmd && pcmd->virt)
18173 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
18176 lpfc_sli_release_iocbq(phba, iocbq);
18177 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18181 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
18182 * @phba: Pointer to HBA context object.
18184 * This function is called with no lock held. This function processes all
18185 * the received buffers and gives it to upper layers when a received buffer
18186 * indicates that it is the final frame in the sequence. The interrupt
18187 * service routine processes received buffers at interrupt contexts.
18188 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
18189 * appropriate receive function when the final frame in a sequence is received.
18192 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
18193 struct hbq_dmabuf *dmabuf)
18195 struct hbq_dmabuf *seq_dmabuf;
18196 struct fc_frame_header *fc_hdr;
18197 struct lpfc_vport *vport;
18201 /* Process each received buffer */
18202 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18204 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
18205 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
18206 vport = phba->pport;
18207 /* Handle MDS Loopback frames */
18208 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
18212 /* check to see if this a valid type of frame */
18213 if (lpfc_fc_frame_check(phba, fc_hdr)) {
18214 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18218 if ((bf_get(lpfc_cqe_code,
18219 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
18220 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
18221 &dmabuf->cq_event.cqe.rcqe_cmpl);
18223 fcfi = bf_get(lpfc_rcqe_fcf_id,
18224 &dmabuf->cq_event.cqe.rcqe_cmpl);
18226 if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
18227 vport = phba->pport;
18228 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
18229 "2023 MDS Loopback %d bytes\n",
18230 bf_get(lpfc_rcqe_length,
18231 &dmabuf->cq_event.cqe.rcqe_cmpl));
18232 /* Handle MDS Loopback frames */
18233 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
18237 /* d_id this frame is directed to */
18238 did = sli4_did_from_fc_hdr(fc_hdr);
18240 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
18242 /* throw out the frame */
18243 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18247 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
18248 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
18249 (did != Fabric_DID)) {
18251 * Throw out the frame if we are not pt2pt.
18252 * The pt2pt protocol allows for discovery frames
18253 * to be received without a registered VPI.
18255 if (!(vport->fc_flag & FC_PT2PT) ||
18256 (phba->link_state == LPFC_HBA_READY)) {
18257 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18262 /* Handle the basic abort sequence (BA_ABTS) event */
18263 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
18264 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
18268 /* Link this frame */
18269 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
18271 /* unable to add frame to vport - throw it out */
18272 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18275 /* If not last frame in sequence continue processing frames. */
18276 if (!lpfc_seq_complete(seq_dmabuf))
18279 /* Send the complete sequence to the upper layer protocol */
18280 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
18284 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
18285 * @phba: pointer to lpfc hba data structure.
18287 * This routine is invoked to post rpi header templates to the
18288 * HBA consistent with the SLI-4 interface spec. This routine
18289 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
18290 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
18292 * This routine does not require any locks. It's usage is expected
18293 * to be driver load or reset recovery when the driver is
18298 * -EIO - The mailbox failed to complete successfully.
18299 * When this error occurs, the driver is not guaranteed
18300 * to have any rpi regions posted to the device and
18301 * must either attempt to repost the regions or take a
18305 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
18307 struct lpfc_rpi_hdr *rpi_page;
18311 /* SLI4 ports that support extents do not require RPI headers. */
18312 if (!phba->sli4_hba.rpi_hdrs_in_use)
18314 if (phba->sli4_hba.extents_in_use)
18317 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
18319 * Assign the rpi headers a physical rpi only if the driver
18320 * has not initialized those resources. A port reset only
18321 * needs the headers posted.
18323 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
18325 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
18327 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
18328 if (rc != MBX_SUCCESS) {
18329 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18330 "2008 Error %d posting all rpi "
18338 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
18339 LPFC_RPI_RSRC_RDY);
18344 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
18345 * @phba: pointer to lpfc hba data structure.
18346 * @rpi_page: pointer to the rpi memory region.
18348 * This routine is invoked to post a single rpi header to the
18349 * HBA consistent with the SLI-4 interface spec. This memory region
18350 * maps up to 64 rpi context regions.
18354 * -ENOMEM - No available memory
18355 * -EIO - The mailbox failed to complete successfully.
18358 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
18360 LPFC_MBOXQ_t *mboxq;
18361 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
18363 uint32_t shdr_status, shdr_add_status;
18364 union lpfc_sli4_cfg_shdr *shdr;
18366 /* SLI4 ports that support extents do not require RPI headers. */
18367 if (!phba->sli4_hba.rpi_hdrs_in_use)
18369 if (phba->sli4_hba.extents_in_use)
18372 /* The port is notified of the header region via a mailbox command. */
18373 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18375 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18376 "2001 Unable to allocate memory for issuing "
18377 "SLI_CONFIG_SPECIAL mailbox command\n");
18381 /* Post all rpi memory regions to the port. */
18382 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
18383 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
18384 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
18385 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
18386 sizeof(struct lpfc_sli4_cfg_mhdr),
18387 LPFC_SLI4_MBX_EMBED);
18390 /* Post the physical rpi to the port for this rpi header. */
18391 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
18392 rpi_page->start_rpi);
18393 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
18394 hdr_tmpl, rpi_page->page_count);
18396 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
18397 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
18398 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
18399 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
18400 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18401 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18402 if (rc != MBX_TIMEOUT)
18403 mempool_free(mboxq, phba->mbox_mem_pool);
18404 if (shdr_status || shdr_add_status || rc) {
18405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18406 "2514 POST_RPI_HDR mailbox failed with "
18407 "status x%x add_status x%x, mbx status x%x\n",
18408 shdr_status, shdr_add_status, rc);
18412 * The next_rpi stores the next logical module-64 rpi value used
18413 * to post physical rpis in subsequent rpi postings.
18415 spin_lock_irq(&phba->hbalock);
18416 phba->sli4_hba.next_rpi = rpi_page->next_rpi;
18417 spin_unlock_irq(&phba->hbalock);
18423 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
18424 * @phba: pointer to lpfc hba data structure.
18426 * This routine is invoked to post rpi header templates to the
18427 * HBA consistent with the SLI-4 interface spec. This routine
18428 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
18429 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
18432 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
18433 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
18436 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
18439 uint16_t max_rpi, rpi_limit;
18440 uint16_t rpi_remaining, lrpi = 0;
18441 struct lpfc_rpi_hdr *rpi_hdr;
18442 unsigned long iflag;
18445 * Fetch the next logical rpi. Because this index is logical,
18446 * the driver starts at 0 each time.
18448 spin_lock_irqsave(&phba->hbalock, iflag);
18449 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
18450 rpi_limit = phba->sli4_hba.next_rpi;
18452 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
18453 if (rpi >= rpi_limit)
18454 rpi = LPFC_RPI_ALLOC_ERROR;
18456 set_bit(rpi, phba->sli4_hba.rpi_bmask);
18457 phba->sli4_hba.max_cfg_param.rpi_used++;
18458 phba->sli4_hba.rpi_count++;
18460 lpfc_printf_log(phba, KERN_INFO,
18461 LOG_NODE | LOG_DISCOVERY,
18462 "0001 Allocated rpi:x%x max:x%x lim:x%x\n",
18463 (int) rpi, max_rpi, rpi_limit);
18466 * Don't try to allocate more rpi header regions if the device limit
18467 * has been exhausted.
18469 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
18470 (phba->sli4_hba.rpi_count >= max_rpi)) {
18471 spin_unlock_irqrestore(&phba->hbalock, iflag);
18476 * RPI header postings are not required for SLI4 ports capable of
18479 if (!phba->sli4_hba.rpi_hdrs_in_use) {
18480 spin_unlock_irqrestore(&phba->hbalock, iflag);
18485 * If the driver is running low on rpi resources, allocate another
18486 * page now. Note that the next_rpi value is used because
18487 * it represents how many are actually in use whereas max_rpi notes
18488 * how many are supported max by the device.
18490 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
18491 spin_unlock_irqrestore(&phba->hbalock, iflag);
18492 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
18493 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
18495 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18496 "2002 Error Could not grow rpi "
18499 lrpi = rpi_hdr->start_rpi;
18500 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
18501 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
18509 * lpfc_sli4_free_rpi - Release an rpi for reuse.
18510 * @phba: pointer to lpfc hba data structure.
18512 * This routine is invoked to release an rpi to the pool of
18513 * available rpis maintained by the driver.
18516 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
18519 * if the rpi value indicates a prior unreg has already
18520 * been done, skip the unreg.
18522 if (rpi == LPFC_RPI_ALLOC_ERROR)
18525 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
18526 phba->sli4_hba.rpi_count--;
18527 phba->sli4_hba.max_cfg_param.rpi_used--;
18529 lpfc_printf_log(phba, KERN_INFO,
18530 LOG_NODE | LOG_DISCOVERY,
18531 "2016 rpi %x not inuse\n",
18537 * lpfc_sli4_free_rpi - Release an rpi for reuse.
18538 * @phba: pointer to lpfc hba data structure.
18540 * This routine is invoked to release an rpi to the pool of
18541 * available rpis maintained by the driver.
18544 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
18546 spin_lock_irq(&phba->hbalock);
18547 __lpfc_sli4_free_rpi(phba, rpi);
18548 spin_unlock_irq(&phba->hbalock);
18552 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
18553 * @phba: pointer to lpfc hba data structure.
18555 * This routine is invoked to remove the memory region that
18556 * provided rpi via a bitmask.
18559 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
18561 kfree(phba->sli4_hba.rpi_bmask);
18562 kfree(phba->sli4_hba.rpi_ids);
18563 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
18567 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
18568 * @phba: pointer to lpfc hba data structure.
18570 * This routine is invoked to remove the memory region that
18571 * provided rpi via a bitmask.
18574 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
18575 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
18577 LPFC_MBOXQ_t *mboxq;
18578 struct lpfc_hba *phba = ndlp->phba;
18581 /* The port is notified of the header region via a mailbox command. */
18582 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18586 /* Post all rpi memory regions to the port. */
18587 lpfc_resume_rpi(mboxq, ndlp);
18589 mboxq->mbox_cmpl = cmpl;
18590 mboxq->ctx_buf = arg;
18591 mboxq->ctx_ndlp = ndlp;
18593 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
18594 mboxq->vport = ndlp->vport;
18595 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18596 if (rc == MBX_NOT_FINISHED) {
18597 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
18598 "2010 Resume RPI Mailbox failed "
18599 "status %d, mbxStatus x%x\n", rc,
18600 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
18601 mempool_free(mboxq, phba->mbox_mem_pool);
18608 * lpfc_sli4_init_vpi - Initialize a vpi with the port
18609 * @vport: Pointer to the vport for which the vpi is being initialized
18611 * This routine is invoked to activate a vpi with the port.
18615 * -Evalue otherwise
18618 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
18620 LPFC_MBOXQ_t *mboxq;
18622 int retval = MBX_SUCCESS;
18624 struct lpfc_hba *phba = vport->phba;
18625 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18628 lpfc_init_vpi(phba, mboxq, vport->vpi);
18629 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
18630 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
18631 if (rc != MBX_SUCCESS) {
18632 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
18633 "2022 INIT VPI Mailbox failed "
18634 "status %d, mbxStatus x%x\n", rc,
18635 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
18638 if (rc != MBX_TIMEOUT)
18639 mempool_free(mboxq, vport->phba->mbox_mem_pool);
18645 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
18646 * @phba: pointer to lpfc hba data structure.
18647 * @mboxq: Pointer to mailbox object.
18649 * This routine is invoked to manually add a single FCF record. The caller
18650 * must pass a completely initialized FCF_Record. This routine takes
18651 * care of the nonembedded mailbox operations.
18654 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
18657 union lpfc_sli4_cfg_shdr *shdr;
18658 uint32_t shdr_status, shdr_add_status;
18660 virt_addr = mboxq->sge_array->addr[0];
18661 /* The IOCTL status is embedded in the mailbox subheader. */
18662 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
18663 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18664 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18666 if ((shdr_status || shdr_add_status) &&
18667 (shdr_status != STATUS_FCF_IN_USE))
18668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18669 "2558 ADD_FCF_RECORD mailbox failed with "
18670 "status x%x add_status x%x\n",
18671 shdr_status, shdr_add_status);
18673 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18677 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
18678 * @phba: pointer to lpfc hba data structure.
18679 * @fcf_record: pointer to the initialized fcf record to add.
18681 * This routine is invoked to manually add a single FCF record. The caller
18682 * must pass a completely initialized FCF_Record. This routine takes
18683 * care of the nonembedded mailbox operations.
18686 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
18689 LPFC_MBOXQ_t *mboxq;
18692 struct lpfc_mbx_sge sge;
18693 uint32_t alloc_len, req_len;
18696 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18699 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
18703 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
18706 /* Allocate DMA memory and set up the non-embedded mailbox command */
18707 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
18708 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
18709 req_len, LPFC_SLI4_MBX_NEMBED);
18710 if (alloc_len < req_len) {
18711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18712 "2523 Allocated DMA memory size (x%x) is "
18713 "less than the requested DMA memory "
18714 "size (x%x)\n", alloc_len, req_len);
18715 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18720 * Get the first SGE entry from the non-embedded DMA memory. This
18721 * routine only uses a single SGE.
18723 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
18724 virt_addr = mboxq->sge_array->addr[0];
18726 * Configure the FCF record for FCFI 0. This is the driver's
18727 * hardcoded default and gets used in nonFIP mode.
18729 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
18730 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
18731 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
18734 * Copy the fcf_index and the FCF Record Data. The data starts after
18735 * the FCoE header plus word10. The data copy needs to be endian
18738 bytep += sizeof(uint32_t);
18739 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
18740 mboxq->vport = phba->pport;
18741 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
18742 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18743 if (rc == MBX_NOT_FINISHED) {
18744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18745 "2515 ADD_FCF_RECORD mailbox failed with "
18746 "status 0x%x\n", rc);
18747 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18756 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
18757 * @phba: pointer to lpfc hba data structure.
18758 * @fcf_record: pointer to the fcf record to write the default data.
18759 * @fcf_index: FCF table entry index.
18761 * This routine is invoked to build the driver's default FCF record. The
18762 * values used are hardcoded. This routine handles memory initialization.
18766 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
18767 struct fcf_record *fcf_record,
18768 uint16_t fcf_index)
18770 memset(fcf_record, 0, sizeof(struct fcf_record));
18771 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
18772 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
18773 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
18774 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
18775 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
18776 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
18777 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
18778 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
18779 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
18780 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
18781 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
18782 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
18783 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
18784 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
18785 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
18786 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
18787 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
18788 /* Set the VLAN bit map */
18789 if (phba->valid_vlan) {
18790 fcf_record->vlan_bitmap[phba->vlan_id / 8]
18791 = 1 << (phba->vlan_id % 8);
18796 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
18797 * @phba: pointer to lpfc hba data structure.
18798 * @fcf_index: FCF table entry offset.
18800 * This routine is invoked to scan the entire FCF table by reading FCF
18801 * record and processing it one at a time starting from the @fcf_index
18802 * for initial FCF discovery or fast FCF failover rediscovery.
18804 * Return 0 if the mailbox command is submitted successfully, none 0
18808 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
18811 LPFC_MBOXQ_t *mboxq;
18813 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
18814 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
18815 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18817 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
18818 "2000 Failed to allocate mbox for "
18821 goto fail_fcf_scan;
18823 /* Construct the read FCF record mailbox command */
18824 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
18827 goto fail_fcf_scan;
18829 /* Issue the mailbox command asynchronously */
18830 mboxq->vport = phba->pport;
18831 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
18833 spin_lock_irq(&phba->hbalock);
18834 phba->hba_flag |= FCF_TS_INPROG;
18835 spin_unlock_irq(&phba->hbalock);
18837 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18838 if (rc == MBX_NOT_FINISHED)
18841 /* Reset eligible FCF count for new scan */
18842 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
18843 phba->fcf.eligible_fcf_cnt = 0;
18849 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18850 /* FCF scan failed, clear FCF_TS_INPROG flag */
18851 spin_lock_irq(&phba->hbalock);
18852 phba->hba_flag &= ~FCF_TS_INPROG;
18853 spin_unlock_irq(&phba->hbalock);
18859 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
18860 * @phba: pointer to lpfc hba data structure.
18861 * @fcf_index: FCF table entry offset.
18863 * This routine is invoked to read an FCF record indicated by @fcf_index
18864 * and to use it for FLOGI roundrobin FCF failover.
18866 * Return 0 if the mailbox command is submitted successfully, none 0
18870 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
18873 LPFC_MBOXQ_t *mboxq;
18875 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18877 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
18878 "2763 Failed to allocate mbox for "
18881 goto fail_fcf_read;
18883 /* Construct the read FCF record mailbox command */
18884 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
18887 goto fail_fcf_read;
18889 /* Issue the mailbox command asynchronously */
18890 mboxq->vport = phba->pport;
18891 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
18892 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18893 if (rc == MBX_NOT_FINISHED)
18899 if (error && mboxq)
18900 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18905 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
18906 * @phba: pointer to lpfc hba data structure.
18907 * @fcf_index: FCF table entry offset.
18909 * This routine is invoked to read an FCF record indicated by @fcf_index to
18910 * determine whether it's eligible for FLOGI roundrobin failover list.
18912 * Return 0 if the mailbox command is submitted successfully, none 0
18916 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
18919 LPFC_MBOXQ_t *mboxq;
18921 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18923 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
18924 "2758 Failed to allocate mbox for "
18927 goto fail_fcf_read;
18929 /* Construct the read FCF record mailbox command */
18930 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
18933 goto fail_fcf_read;
18935 /* Issue the mailbox command asynchronously */
18936 mboxq->vport = phba->pport;
18937 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
18938 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
18939 if (rc == MBX_NOT_FINISHED)
18945 if (error && mboxq)
18946 lpfc_sli4_mbox_cmd_free(phba, mboxq);
18951 * lpfc_check_next_fcf_pri_level
18952 * phba pointer to the lpfc_hba struct for this port.
18953 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
18954 * routine when the rr_bmask is empty. The FCF indecies are put into the
18955 * rr_bmask based on their priority level. Starting from the highest priority
18956 * to the lowest. The most likely FCF candidate will be in the highest
18957 * priority group. When this routine is called it searches the fcf_pri list for
18958 * next lowest priority group and repopulates the rr_bmask with only those
18961 * 1=success 0=failure
18964 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
18966 uint16_t next_fcf_pri;
18967 uint16_t last_index;
18968 struct lpfc_fcf_pri *fcf_pri;
18972 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
18973 LPFC_SLI4_FCF_TBL_INDX_MAX);
18974 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
18975 "3060 Last IDX %d\n", last_index);
18977 /* Verify the priority list has 2 or more entries */
18978 spin_lock_irq(&phba->hbalock);
18979 if (list_empty(&phba->fcf.fcf_pri_list) ||
18980 list_is_singular(&phba->fcf.fcf_pri_list)) {
18981 spin_unlock_irq(&phba->hbalock);
18982 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
18983 "3061 Last IDX %d\n", last_index);
18984 return 0; /* Empty rr list */
18986 spin_unlock_irq(&phba->hbalock);
18990 * Clear the rr_bmask and set all of the bits that are at this
18993 memset(phba->fcf.fcf_rr_bmask, 0,
18994 sizeof(*phba->fcf.fcf_rr_bmask));
18995 spin_lock_irq(&phba->hbalock);
18996 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
18997 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
19000 * the 1st priority that has not FLOGI failed
19001 * will be the highest.
19004 next_fcf_pri = fcf_pri->fcf_rec.priority;
19005 spin_unlock_irq(&phba->hbalock);
19006 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
19007 rc = lpfc_sli4_fcf_rr_index_set(phba,
19008 fcf_pri->fcf_rec.fcf_index);
19012 spin_lock_irq(&phba->hbalock);
19015 * if next_fcf_pri was not set above and the list is not empty then
19016 * we have failed flogis on all of them. So reset flogi failed
19017 * and start at the beginning.
19019 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
19020 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
19021 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
19023 * the 1st priority that has not FLOGI failed
19024 * will be the highest.
19027 next_fcf_pri = fcf_pri->fcf_rec.priority;
19028 spin_unlock_irq(&phba->hbalock);
19029 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
19030 rc = lpfc_sli4_fcf_rr_index_set(phba,
19031 fcf_pri->fcf_rec.fcf_index);
19035 spin_lock_irq(&phba->hbalock);
19039 spin_unlock_irq(&phba->hbalock);
19044 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
19045 * @phba: pointer to lpfc hba data structure.
19047 * This routine is to get the next eligible FCF record index in a round
19048 * robin fashion. If the next eligible FCF record index equals to the
19049 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
19050 * shall be returned, otherwise, the next eligible FCF record's index
19051 * shall be returned.
19054 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
19056 uint16_t next_fcf_index;
19059 /* Search start from next bit of currently registered FCF index */
19060 next_fcf_index = phba->fcf.current_rec.fcf_indx;
19063 /* Determine the next fcf index to check */
19064 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
19065 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
19066 LPFC_SLI4_FCF_TBL_INDX_MAX,
19069 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
19070 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
19072 * If we have wrapped then we need to clear the bits that
19073 * have been tested so that we can detect when we should
19074 * change the priority level.
19076 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
19077 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
19081 /* Check roundrobin failover list empty condition */
19082 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
19083 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
19085 * If next fcf index is not found check if there are lower
19086 * Priority level fcf's in the fcf_priority list.
19087 * Set up the rr_bmask with all of the avaiable fcf bits
19088 * at that level and continue the selection process.
19090 if (lpfc_check_next_fcf_pri_level(phba))
19091 goto initial_priority;
19092 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
19093 "2844 No roundrobin failover FCF available\n");
19095 return LPFC_FCOE_FCF_NEXT_NONE;
19098 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
19099 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
19100 LPFC_FCF_FLOGI_FAILED) {
19101 if (list_is_singular(&phba->fcf.fcf_pri_list))
19102 return LPFC_FCOE_FCF_NEXT_NONE;
19104 goto next_priority;
19107 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19108 "2845 Get next roundrobin failover FCF (x%x)\n",
19111 return next_fcf_index;
19115 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
19116 * @phba: pointer to lpfc hba data structure.
19118 * This routine sets the FCF record index in to the eligible bmask for
19119 * roundrobin failover search. It checks to make sure that the index
19120 * does not go beyond the range of the driver allocated bmask dimension
19121 * before setting the bit.
19123 * Returns 0 if the index bit successfully set, otherwise, it returns
19127 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
19129 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
19130 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19131 "2610 FCF (x%x) reached driver's book "
19132 "keeping dimension:x%x\n",
19133 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
19136 /* Set the eligible FCF record index bmask */
19137 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
19139 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19140 "2790 Set FCF (x%x) to roundrobin FCF failover "
19141 "bmask\n", fcf_index);
19147 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
19148 * @phba: pointer to lpfc hba data structure.
19150 * This routine clears the FCF record index from the eligible bmask for
19151 * roundrobin failover search. It checks to make sure that the index
19152 * does not go beyond the range of the driver allocated bmask dimension
19153 * before clearing the bit.
19156 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
19158 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
19159 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
19160 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19161 "2762 FCF (x%x) reached driver's book "
19162 "keeping dimension:x%x\n",
19163 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
19166 /* Clear the eligible FCF record index bmask */
19167 spin_lock_irq(&phba->hbalock);
19168 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
19170 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
19171 list_del_init(&fcf_pri->list);
19175 spin_unlock_irq(&phba->hbalock);
19176 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
19178 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19179 "2791 Clear FCF (x%x) from roundrobin failover "
19180 "bmask\n", fcf_index);
19184 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
19185 * @phba: pointer to lpfc hba data structure.
19187 * This routine is the completion routine for the rediscover FCF table mailbox
19188 * command. If the mailbox command returned failure, it will try to stop the
19189 * FCF rediscover wait timer.
19192 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
19194 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
19195 uint32_t shdr_status, shdr_add_status;
19197 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
19199 shdr_status = bf_get(lpfc_mbox_hdr_status,
19200 &redisc_fcf->header.cfg_shdr.response);
19201 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
19202 &redisc_fcf->header.cfg_shdr.response);
19203 if (shdr_status || shdr_add_status) {
19204 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19205 "2746 Requesting for FCF rediscovery failed "
19206 "status x%x add_status x%x\n",
19207 shdr_status, shdr_add_status);
19208 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
19209 spin_lock_irq(&phba->hbalock);
19210 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
19211 spin_unlock_irq(&phba->hbalock);
19213 * CVL event triggered FCF rediscover request failed,
19214 * last resort to re-try current registered FCF entry.
19216 lpfc_retry_pport_discovery(phba);
19218 spin_lock_irq(&phba->hbalock);
19219 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
19220 spin_unlock_irq(&phba->hbalock);
19222 * DEAD FCF event triggered FCF rediscover request
19223 * failed, last resort to fail over as a link down
19224 * to FCF registration.
19226 lpfc_sli4_fcf_dead_failthrough(phba);
19229 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19230 "2775 Start FCF rediscover quiescent timer\n");
19232 * Start FCF rediscovery wait timer for pending FCF
19233 * before rescan FCF record table.
19235 lpfc_fcf_redisc_wait_start_timer(phba);
19238 mempool_free(mbox, phba->mbox_mem_pool);
19242 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
19243 * @phba: pointer to lpfc hba data structure.
19245 * This routine is invoked to request for rediscovery of the entire FCF table
19249 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
19251 LPFC_MBOXQ_t *mbox;
19252 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
19255 /* Cancel retry delay timers to all vports before FCF rediscover */
19256 lpfc_cancel_all_vport_retry_delay_timer(phba);
19258 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19260 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
19261 "2745 Failed to allocate mbox for "
19262 "requesting FCF rediscover.\n");
19266 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
19267 sizeof(struct lpfc_sli4_cfg_mhdr));
19268 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
19269 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
19270 length, LPFC_SLI4_MBX_EMBED);
19272 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
19273 /* Set count to 0 for invalidating the entire FCF database */
19274 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
19276 /* Issue the mailbox command asynchronously */
19277 mbox->vport = phba->pport;
19278 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
19279 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
19281 if (rc == MBX_NOT_FINISHED) {
19282 mempool_free(mbox, phba->mbox_mem_pool);
19289 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
19290 * @phba: pointer to lpfc hba data structure.
19292 * This function is the failover routine as a last resort to the FCF DEAD
19293 * event when driver failed to perform fast FCF failover.
19296 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
19298 uint32_t link_state;
19301 * Last resort as FCF DEAD event failover will treat this as
19302 * a link down, but save the link state because we don't want
19303 * it to be changed to Link Down unless it is already down.
19305 link_state = phba->link_state;
19306 lpfc_linkdown(phba);
19307 phba->link_state = link_state;
19309 /* Unregister FCF if no devices connected to it */
19310 lpfc_unregister_unused_fcf(phba);
19314 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
19315 * @phba: pointer to lpfc hba data structure.
19316 * @rgn23_data: pointer to configure region 23 data.
19318 * This function gets SLI3 port configure region 23 data through memory dump
19319 * mailbox command. When it successfully retrieves data, the size of the data
19320 * will be returned, otherwise, 0 will be returned.
19323 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
19325 LPFC_MBOXQ_t *pmb = NULL;
19327 uint32_t offset = 0;
19333 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19336 "2600 failed to allocate mailbox memory\n");
19342 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
19343 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
19345 if (rc != MBX_SUCCESS) {
19346 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19347 "2601 failed to read config "
19348 "region 23, rc 0x%x Status 0x%x\n",
19349 rc, mb->mbxStatus);
19350 mb->un.varDmp.word_cnt = 0;
19353 * dump mem may return a zero when finished or we got a
19354 * mailbox error, either way we are done.
19356 if (mb->un.varDmp.word_cnt == 0)
19358 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
19359 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
19361 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
19362 rgn23_data + offset,
19363 mb->un.varDmp.word_cnt);
19364 offset += mb->un.varDmp.word_cnt;
19365 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
19367 mempool_free(pmb, phba->mbox_mem_pool);
19372 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
19373 * @phba: pointer to lpfc hba data structure.
19374 * @rgn23_data: pointer to configure region 23 data.
19376 * This function gets SLI4 port configure region 23 data through memory dump
19377 * mailbox command. When it successfully retrieves data, the size of the data
19378 * will be returned, otherwise, 0 will be returned.
19381 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
19383 LPFC_MBOXQ_t *mboxq = NULL;
19384 struct lpfc_dmabuf *mp = NULL;
19385 struct lpfc_mqe *mqe;
19386 uint32_t data_length = 0;
19392 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19394 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19395 "3105 failed to allocate mailbox memory\n");
19399 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
19401 mqe = &mboxq->u.mqe;
19402 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
19403 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
19406 data_length = mqe->un.mb_words[5];
19407 if (data_length == 0)
19409 if (data_length > DMP_RGN23_SIZE) {
19413 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
19415 mempool_free(mboxq, phba->mbox_mem_pool);
19417 lpfc_mbuf_free(phba, mp->virt, mp->phys);
19420 return data_length;
19424 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
19425 * @phba: pointer to lpfc hba data structure.
19427 * This function read region 23 and parse TLV for port status to
19428 * decide if the user disaled the port. If the TLV indicates the
19429 * port is disabled, the hba_flag is set accordingly.
19432 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
19434 uint8_t *rgn23_data = NULL;
19435 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
19436 uint32_t offset = 0;
19438 /* Get adapter Region 23 data */
19439 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
19443 if (phba->sli_rev < LPFC_SLI_REV4)
19444 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
19446 if_type = bf_get(lpfc_sli_intf_if_type,
19447 &phba->sli4_hba.sli_intf);
19448 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
19450 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
19456 /* Check the region signature first */
19457 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
19458 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19459 "2619 Config region 23 has bad signature\n");
19464 /* Check the data structure version */
19465 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
19466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19467 "2620 Config region 23 has bad version\n");
19472 /* Parse TLV entries in the region */
19473 while (offset < data_size) {
19474 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
19477 * If the TLV is not driver specific TLV or driver id is
19478 * not linux driver id, skip the record.
19480 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
19481 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
19482 (rgn23_data[offset + 3] != 0)) {
19483 offset += rgn23_data[offset + 1] * 4 + 4;
19487 /* Driver found a driver specific TLV in the config region */
19488 sub_tlv_len = rgn23_data[offset + 1] * 4;
19493 * Search for configured port state sub-TLV.
19495 while ((offset < data_size) &&
19496 (tlv_offset < sub_tlv_len)) {
19497 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
19502 if (rgn23_data[offset] != PORT_STE_TYPE) {
19503 offset += rgn23_data[offset + 1] * 4 + 4;
19504 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
19508 /* This HBA contains PORT_STE configured */
19509 if (!rgn23_data[offset + 2])
19510 phba->hba_flag |= LINK_DISABLED;
19522 * lpfc_wr_object - write an object to the firmware
19523 * @phba: HBA structure that indicates port to create a queue on.
19524 * @dmabuf_list: list of dmabufs to write to the port.
19525 * @size: the total byte value of the objects to write to the port.
19526 * @offset: the current offset to be used to start the transfer.
19528 * This routine will create a wr_object mailbox command to send to the port.
19529 * the mailbox command will be constructed using the dma buffers described in
19530 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
19531 * BDEs that the imbedded mailbox can support. The @offset variable will be
19532 * used to indicate the starting offset of the transfer and will also return
19533 * the offset after the write object mailbox has completed. @size is used to
19534 * determine the end of the object and whether the eof bit should be set.
19536 * Return 0 is successful and offset will contain the the new offset to use
19537 * for the next write.
19538 * Return negative value for error cases.
19541 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
19542 uint32_t size, uint32_t *offset)
19544 struct lpfc_mbx_wr_object *wr_object;
19545 LPFC_MBOXQ_t *mbox;
19547 uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf;
19549 struct lpfc_dmabuf *dmabuf;
19550 uint32_t written = 0;
19551 bool check_change_status = false;
19553 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19557 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
19558 LPFC_MBOX_OPCODE_WRITE_OBJECT,
19559 sizeof(struct lpfc_mbx_wr_object) -
19560 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
19562 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
19563 wr_object->u.request.write_offset = *offset;
19564 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
19565 wr_object->u.request.object_name[0] =
19566 cpu_to_le32(wr_object->u.request.object_name[0]);
19567 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
19568 list_for_each_entry(dmabuf, dmabuf_list, list) {
19569 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
19571 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
19572 wr_object->u.request.bde[i].addrHigh =
19573 putPaddrHigh(dmabuf->phys);
19574 if (written + SLI4_PAGE_SIZE >= size) {
19575 wr_object->u.request.bde[i].tus.f.bdeSize =
19577 written += (size - written);
19578 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
19579 bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
19580 check_change_status = true;
19582 wr_object->u.request.bde[i].tus.f.bdeSize =
19584 written += SLI4_PAGE_SIZE;
19588 wr_object->u.request.bde_count = i;
19589 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
19590 if (!phba->sli4_hba.intr_enable)
19591 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
19593 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
19594 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
19596 /* The IOCTL status is embedded in the mailbox subheader. */
19597 shdr_status = bf_get(lpfc_mbox_hdr_status,
19598 &wr_object->header.cfg_shdr.response);
19599 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
19600 &wr_object->header.cfg_shdr.response);
19601 if (check_change_status) {
19602 shdr_change_status = bf_get(lpfc_wr_object_change_status,
19603 &wr_object->u.response);
19605 if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET ||
19606 shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) {
19607 shdr_csf = bf_get(lpfc_wr_object_csf,
19608 &wr_object->u.response);
19610 shdr_change_status =
19611 LPFC_CHANGE_STATUS_PCI_RESET;
19614 switch (shdr_change_status) {
19615 case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
19616 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19617 "3198 Firmware write complete: System "
19618 "reboot required to instantiate\n");
19620 case (LPFC_CHANGE_STATUS_FW_RESET):
19621 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19622 "3199 Firmware write complete: Firmware"
19623 " reset required to instantiate\n");
19625 case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
19626 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19627 "3200 Firmware write complete: Port "
19628 "Migration or PCI Reset required to "
19631 case (LPFC_CHANGE_STATUS_PCI_RESET):
19632 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19633 "3201 Firmware write complete: PCI "
19634 "Reset required to instantiate\n");
19640 if (rc != MBX_TIMEOUT)
19641 mempool_free(mbox, phba->mbox_mem_pool);
19642 if (shdr_status || shdr_add_status || rc) {
19643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
19644 "3025 Write Object mailbox failed with "
19645 "status x%x add_status x%x, mbx status x%x\n",
19646 shdr_status, shdr_add_status, rc);
19648 *offset = shdr_add_status;
19650 *offset += wr_object->u.response.actual_write_length;
19655 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
19656 * @vport: pointer to vport data structure.
19658 * This function iterate through the mailboxq and clean up all REG_LOGIN
19659 * and REG_VPI mailbox commands associated with the vport. This function
19660 * is called when driver want to restart discovery of the vport due to
19661 * a Clear Virtual Link event.
19664 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
19666 struct lpfc_hba *phba = vport->phba;
19667 LPFC_MBOXQ_t *mb, *nextmb;
19668 struct lpfc_dmabuf *mp;
19669 struct lpfc_nodelist *ndlp;
19670 struct lpfc_nodelist *act_mbx_ndlp = NULL;
19671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
19672 LIST_HEAD(mbox_cmd_list);
19673 uint8_t restart_loop;
19675 /* Clean up internally queued mailbox commands with the vport */
19676 spin_lock_irq(&phba->hbalock);
19677 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
19678 if (mb->vport != vport)
19681 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
19682 (mb->u.mb.mbxCommand != MBX_REG_VPI))
19685 list_del(&mb->list);
19686 list_add_tail(&mb->list, &mbox_cmd_list);
19688 /* Clean up active mailbox command with the vport */
19689 mb = phba->sli.mbox_active;
19690 if (mb && (mb->vport == vport)) {
19691 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
19692 (mb->u.mb.mbxCommand == MBX_REG_VPI))
19693 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19694 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
19695 act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
19696 /* Put reference count for delayed processing */
19697 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
19698 /* Unregister the RPI when mailbox complete */
19699 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
19702 /* Cleanup any mailbox completions which are not yet processed */
19705 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
19707 * If this mailox is already processed or it is
19708 * for another vport ignore it.
19710 if ((mb->vport != vport) ||
19711 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
19714 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
19715 (mb->u.mb.mbxCommand != MBX_REG_VPI))
19718 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19719 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
19720 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
19721 /* Unregister the RPI when mailbox complete */
19722 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
19724 spin_unlock_irq(&phba->hbalock);
19725 spin_lock(shost->host_lock);
19726 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
19727 spin_unlock(shost->host_lock);
19728 spin_lock_irq(&phba->hbalock);
19732 } while (restart_loop);
19734 spin_unlock_irq(&phba->hbalock);
19736 /* Release the cleaned-up mailbox commands */
19737 while (!list_empty(&mbox_cmd_list)) {
19738 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
19739 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
19740 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
19742 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
19745 mb->ctx_buf = NULL;
19746 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
19747 mb->ctx_ndlp = NULL;
19749 spin_lock(shost->host_lock);
19750 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
19751 spin_unlock(shost->host_lock);
19752 lpfc_nlp_put(ndlp);
19755 mempool_free(mb, phba->mbox_mem_pool);
19758 /* Release the ndlp with the cleaned-up active mailbox command */
19759 if (act_mbx_ndlp) {
19760 spin_lock(shost->host_lock);
19761 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
19762 spin_unlock(shost->host_lock);
19763 lpfc_nlp_put(act_mbx_ndlp);
19768 * lpfc_drain_txq - Drain the txq
19769 * @phba: Pointer to HBA context object.
19771 * This function attempt to submit IOCBs on the txq
19772 * to the adapter. For SLI4 adapters, the txq contains
19773 * ELS IOCBs that have been deferred because the there
19774 * are no SGLs. This congestion can occur with large
19775 * vport counts during node discovery.
19779 lpfc_drain_txq(struct lpfc_hba *phba)
19781 LIST_HEAD(completions);
19782 struct lpfc_sli_ring *pring;
19783 struct lpfc_iocbq *piocbq = NULL;
19784 unsigned long iflags = 0;
19785 char *fail_msg = NULL;
19786 struct lpfc_sglq *sglq;
19787 union lpfc_wqe128 wqe;
19788 uint32_t txq_cnt = 0;
19789 struct lpfc_queue *wq;
19791 if (phba->link_flag & LS_MDS_LOOPBACK) {
19792 /* MDS WQE are posted only to first WQ*/
19793 wq = phba->sli4_hba.hdwq[0].io_wq;
19798 wq = phba->sli4_hba.els_wq;
19801 pring = lpfc_phba_elsring(phba);
19804 if (unlikely(!pring) || list_empty(&pring->txq))
19807 spin_lock_irqsave(&pring->ring_lock, iflags);
19808 list_for_each_entry(piocbq, &pring->txq, list) {
19812 if (txq_cnt > pring->txq_max)
19813 pring->txq_max = txq_cnt;
19815 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19817 while (!list_empty(&pring->txq)) {
19818 spin_lock_irqsave(&pring->ring_lock, iflags);
19820 piocbq = lpfc_sli_ringtx_get(phba, pring);
19822 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19823 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
19824 "2823 txq empty and txq_cnt is %d\n ",
19828 sglq = __lpfc_sli_get_els_sglq(phba, piocbq);
19830 __lpfc_sli_ringtx_put(phba, pring, piocbq);
19831 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19836 /* The xri and iocb resources secured,
19837 * attempt to issue request
19839 piocbq->sli4_lxritag = sglq->sli4_lxritag;
19840 piocbq->sli4_xritag = sglq->sli4_xritag;
19841 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
19842 fail_msg = "to convert bpl to sgl";
19843 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
19844 fail_msg = "to convert iocb to wqe";
19845 else if (lpfc_sli4_wq_put(wq, &wqe))
19846 fail_msg = " - Wq is full";
19848 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
19851 /* Failed means we can't issue and need to cancel */
19852 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
19853 "2822 IOCB failed %s iotag 0x%x "
19856 piocbq->iotag, piocbq->sli4_xritag);
19857 list_add_tail(&piocbq->list, &completions);
19859 spin_unlock_irqrestore(&pring->ring_lock, iflags);
19862 /* Cancel all the IOCBs that cannot be issued */
19863 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
19864 IOERR_SLI_ABORTED);
19870 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
19871 * @phba: Pointer to HBA context object.
19872 * @pwqe: Pointer to command WQE.
19873 * @sglq: Pointer to the scatter gather queue object.
19875 * This routine converts the bpl or bde that is in the WQE
19876 * to a sgl list for the sli4 hardware. The physical address
19877 * of the bpl/bde is converted back to a virtual address.
19878 * If the WQE contains a BPL then the list of BDE's is
19879 * converted to sli4_sge's. If the WQE contains a single
19880 * BDE then it is converted to a single sli_sge.
19881 * The WQE is still in cpu endianness so the contents of
19882 * the bpl can be used without byte swapping.
19884 * Returns valid XRI = Success, NO_XRI = Failure.
19887 lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
19888 struct lpfc_sglq *sglq)
19890 uint16_t xritag = NO_XRI;
19891 struct ulp_bde64 *bpl = NULL;
19892 struct ulp_bde64 bde;
19893 struct sli4_sge *sgl = NULL;
19894 struct lpfc_dmabuf *dmabuf;
19895 union lpfc_wqe128 *wqe;
19898 uint32_t offset = 0; /* accumulated offset in the sg request list */
19899 int inbound = 0; /* number of sg reply entries inbound from firmware */
19902 if (!pwqeq || !sglq)
19905 sgl = (struct sli4_sge *)sglq->sgl;
19907 pwqeq->iocb.ulpIoTag = pwqeq->iotag;
19909 cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
19910 if (cmd == CMD_XMIT_BLS_RSP64_WQE)
19911 return sglq->sli4_xritag;
19912 numBdes = pwqeq->rsvd2;
19914 /* The addrHigh and addrLow fields within the WQE
19915 * have not been byteswapped yet so there is no
19916 * need to swap them back.
19918 if (pwqeq->context3)
19919 dmabuf = (struct lpfc_dmabuf *)pwqeq->context3;
19923 bpl = (struct ulp_bde64 *)dmabuf->virt;
19927 for (i = 0; i < numBdes; i++) {
19928 /* Should already be byte swapped. */
19929 sgl->addr_hi = bpl->addrHigh;
19930 sgl->addr_lo = bpl->addrLow;
19932 sgl->word2 = le32_to_cpu(sgl->word2);
19933 if ((i+1) == numBdes)
19934 bf_set(lpfc_sli4_sge_last, sgl, 1);
19936 bf_set(lpfc_sli4_sge_last, sgl, 0);
19937 /* swap the size field back to the cpu so we
19938 * can assign it to the sgl.
19940 bde.tus.w = le32_to_cpu(bpl->tus.w);
19941 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
19942 /* The offsets in the sgl need to be accumulated
19943 * separately for the request and reply lists.
19944 * The request is always first, the reply follows.
19947 case CMD_GEN_REQUEST64_WQE:
19948 /* add up the reply sg entries */
19949 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
19951 /* first inbound? reset the offset */
19954 bf_set(lpfc_sli4_sge_offset, sgl, offset);
19955 bf_set(lpfc_sli4_sge_type, sgl,
19956 LPFC_SGE_TYPE_DATA);
19957 offset += bde.tus.f.bdeSize;
19959 case CMD_FCP_TRSP64_WQE:
19960 bf_set(lpfc_sli4_sge_offset, sgl, 0);
19961 bf_set(lpfc_sli4_sge_type, sgl,
19962 LPFC_SGE_TYPE_DATA);
19964 case CMD_FCP_TSEND64_WQE:
19965 case CMD_FCP_TRECEIVE64_WQE:
19966 bf_set(lpfc_sli4_sge_type, sgl,
19967 bpl->tus.f.bdeFlags);
19971 offset += bde.tus.f.bdeSize;
19972 bf_set(lpfc_sli4_sge_offset, sgl, offset);
19975 sgl->word2 = cpu_to_le32(sgl->word2);
19979 } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
19980 /* The addrHigh and addrLow fields of the BDE have not
19981 * been byteswapped yet so they need to be swapped
19982 * before putting them in the sgl.
19984 sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
19985 sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
19986 sgl->word2 = le32_to_cpu(sgl->word2);
19987 bf_set(lpfc_sli4_sge_last, sgl, 1);
19988 sgl->word2 = cpu_to_le32(sgl->word2);
19989 sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
19991 return sglq->sli4_xritag;
19995 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
19996 * @phba: Pointer to HBA context object.
19997 * @ring_number: Base sli ring number
19998 * @pwqe: Pointer to command WQE.
20001 lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
20002 struct lpfc_iocbq *pwqe)
20004 union lpfc_wqe128 *wqe = &pwqe->wqe;
20005 struct lpfc_async_xchg_ctx *ctxp;
20006 struct lpfc_queue *wq;
20007 struct lpfc_sglq *sglq;
20008 struct lpfc_sli_ring *pring;
20009 unsigned long iflags;
20012 /* NVME_LS and NVME_LS ABTS requests. */
20013 if (pwqe->iocb_flag & LPFC_IO_NVME_LS) {
20014 pring = phba->sli4_hba.nvmels_wq->pring;
20015 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
20017 sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
20019 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20022 pwqe->sli4_lxritag = sglq->sli4_lxritag;
20023 pwqe->sli4_xritag = sglq->sli4_xritag;
20024 if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
20025 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20028 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
20029 pwqe->sli4_xritag);
20030 ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
20032 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20036 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
20037 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20039 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
20043 /* NVME_FCREQ and NVME_ABTS requests */
20044 if (pwqe->iocb_flag & LPFC_IO_NVME) {
20045 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
20049 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
20051 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
20053 ret = lpfc_sli4_wq_put(wq, wqe);
20055 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20058 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
20059 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20061 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
20065 /* NVMET requests */
20066 if (pwqe->iocb_flag & LPFC_IO_NVMET) {
20067 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
20071 ctxp = pwqe->context2;
20072 sglq = ctxp->ctxbuf->sglq;
20073 if (pwqe->sli4_xritag == NO_XRI) {
20074 pwqe->sli4_lxritag = sglq->sli4_lxritag;
20075 pwqe->sli4_xritag = sglq->sli4_xritag;
20077 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
20078 pwqe->sli4_xritag);
20079 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
20081 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
20083 ret = lpfc_sli4_wq_put(wq, wqe);
20085 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20088 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
20089 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20091 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
20097 #ifdef LPFC_MXP_STAT
20099 * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
20100 * @phba: pointer to lpfc hba data structure.
20101 * @hwqid: belong to which HWQ.
20103 * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
20104 * 15 seconds after a test case is running.
20106 * The user should call lpfc_debugfs_multixripools_write before running a test
20107 * case to clear stat_snapshot_taken. Then the user starts a test case. During
20108 * test case is running, stat_snapshot_taken is incremented by 1 every time when
20109 * this routine is called from heartbeat timer. When stat_snapshot_taken is
20110 * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
20112 void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
20114 struct lpfc_sli4_hdw_queue *qp;
20115 struct lpfc_multixri_pool *multixri_pool;
20116 struct lpfc_pvt_pool *pvt_pool;
20117 struct lpfc_pbl_pool *pbl_pool;
20120 qp = &phba->sli4_hba.hdwq[hwqid];
20121 multixri_pool = qp->p_multixri_pool;
20122 if (!multixri_pool)
20125 if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
20126 pvt_pool = &qp->p_multixri_pool->pvt_pool;
20127 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20128 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
20130 multixri_pool->stat_pbl_count = pbl_pool->count;
20131 multixri_pool->stat_pvt_count = pvt_pool->count;
20132 multixri_pool->stat_busy_count = txcmplq_cnt;
20135 multixri_pool->stat_snapshot_taken++;
20140 * lpfc_adjust_pvt_pool_count - Adjust private pool count
20141 * @phba: pointer to lpfc hba data structure.
20142 * @hwqid: belong to which HWQ.
20144 * This routine moves some XRIs from private to public pool when private pool
20147 void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
20149 struct lpfc_multixri_pool *multixri_pool;
20151 u32 prev_io_req_count;
20153 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
20154 if (!multixri_pool)
20156 io_req_count = multixri_pool->io_req_count;
20157 prev_io_req_count = multixri_pool->prev_io_req_count;
20159 if (prev_io_req_count != io_req_count) {
20160 /* Private pool is busy */
20161 multixri_pool->prev_io_req_count = io_req_count;
20163 /* Private pool is not busy.
20164 * Move XRIs from private to public pool.
20166 lpfc_move_xri_pvt_to_pbl(phba, hwqid);
20171 * lpfc_adjust_high_watermark - Adjust high watermark
20172 * @phba: pointer to lpfc hba data structure.
20173 * @hwqid: belong to which HWQ.
20175 * This routine sets high watermark as number of outstanding XRIs,
20176 * but make sure the new value is between xri_limit/2 and xri_limit.
20178 void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
20186 struct lpfc_multixri_pool *multixri_pool;
20187 struct lpfc_sli4_hdw_queue *qp;
20189 qp = &phba->sli4_hba.hdwq[hwqid];
20190 multixri_pool = qp->p_multixri_pool;
20191 if (!multixri_pool)
20193 xri_limit = multixri_pool->xri_limit;
20195 watermark_max = xri_limit;
20196 watermark_min = xri_limit / 2;
20198 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
20199 abts_io_bufs = qp->abts_scsi_io_bufs;
20200 abts_io_bufs += qp->abts_nvme_io_bufs;
20202 new_watermark = txcmplq_cnt + abts_io_bufs;
20203 new_watermark = min(watermark_max, new_watermark);
20204 new_watermark = max(watermark_min, new_watermark);
20205 multixri_pool->pvt_pool.high_watermark = new_watermark;
20207 #ifdef LPFC_MXP_STAT
20208 multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
20214 * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
20215 * @phba: pointer to lpfc hba data structure.
20216 * @hwqid: belong to which HWQ.
20218 * This routine is called from hearbeat timer when pvt_pool is idle.
20219 * All free XRIs are moved from private to public pool on hwqid with 2 steps.
20220 * The first step moves (all - low_watermark) amount of XRIs.
20221 * The second step moves the rest of XRIs.
20223 void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
20225 struct lpfc_pbl_pool *pbl_pool;
20226 struct lpfc_pvt_pool *pvt_pool;
20227 struct lpfc_sli4_hdw_queue *qp;
20228 struct lpfc_io_buf *lpfc_ncmd;
20229 struct lpfc_io_buf *lpfc_ncmd_next;
20230 unsigned long iflag;
20231 struct list_head tmp_list;
20234 qp = &phba->sli4_hba.hdwq[hwqid];
20235 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20236 pvt_pool = &qp->p_multixri_pool->pvt_pool;
20239 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
20240 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
20242 if (pvt_pool->count > pvt_pool->low_watermark) {
20243 /* Step 1: move (all - low_watermark) from pvt_pool
20247 /* Move low watermark of bufs from pvt_pool to tmp_list */
20248 INIT_LIST_HEAD(&tmp_list);
20249 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
20250 &pvt_pool->list, list) {
20251 list_move_tail(&lpfc_ncmd->list, &tmp_list);
20253 if (tmp_count >= pvt_pool->low_watermark)
20257 /* Move all bufs from pvt_pool to pbl_pool */
20258 list_splice_init(&pvt_pool->list, &pbl_pool->list);
20260 /* Move all bufs from tmp_list to pvt_pool */
20261 list_splice(&tmp_list, &pvt_pool->list);
20263 pbl_pool->count += (pvt_pool->count - tmp_count);
20264 pvt_pool->count = tmp_count;
20266 /* Step 2: move the rest from pvt_pool to pbl_pool */
20267 list_splice_init(&pvt_pool->list, &pbl_pool->list);
20268 pbl_pool->count += pvt_pool->count;
20269 pvt_pool->count = 0;
20272 spin_unlock(&pvt_pool->lock);
20273 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20277 * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
20278 * @phba: pointer to lpfc hba data structure
20279 * @pbl_pool: specified public free XRI pool
20280 * @pvt_pool: specified private free XRI pool
20281 * @count: number of XRIs to move
20283 * This routine tries to move some free common bufs from the specified pbl_pool
20284 * to the specified pvt_pool. It might move less than count XRIs if there's not
20285 * enough in public pool.
20288 * true - if XRIs are successfully moved from the specified pbl_pool to the
20289 * specified pvt_pool
20290 * false - if the specified pbl_pool is empty or locked by someone else
20293 _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
20294 struct lpfc_pbl_pool *pbl_pool,
20295 struct lpfc_pvt_pool *pvt_pool, u32 count)
20297 struct lpfc_io_buf *lpfc_ncmd;
20298 struct lpfc_io_buf *lpfc_ncmd_next;
20299 unsigned long iflag;
20302 ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
20304 if (pbl_pool->count) {
20305 /* Move a batch of XRIs from public to private pool */
20306 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
20307 list_for_each_entry_safe(lpfc_ncmd,
20311 list_move_tail(&lpfc_ncmd->list,
20320 spin_unlock(&pvt_pool->lock);
20321 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20324 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20331 * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
20332 * @phba: pointer to lpfc hba data structure.
20333 * @hwqid: belong to which HWQ.
20334 * @count: number of XRIs to move
20336 * This routine tries to find some free common bufs in one of public pools with
20337 * Round Robin method. The search always starts from local hwqid, then the next
20338 * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
20339 * a batch of free common bufs are moved to private pool on hwqid.
20340 * It might move less than count XRIs if there's not enough in public pool.
20342 void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
20344 struct lpfc_multixri_pool *multixri_pool;
20345 struct lpfc_multixri_pool *next_multixri_pool;
20346 struct lpfc_pvt_pool *pvt_pool;
20347 struct lpfc_pbl_pool *pbl_pool;
20348 struct lpfc_sli4_hdw_queue *qp;
20353 qp = &phba->sli4_hba.hdwq[hwqid];
20354 multixri_pool = qp->p_multixri_pool;
20355 pvt_pool = &multixri_pool->pvt_pool;
20356 pbl_pool = &multixri_pool->pbl_pool;
20358 /* Check if local pbl_pool is available */
20359 ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
20361 #ifdef LPFC_MXP_STAT
20362 multixri_pool->local_pbl_hit_count++;
20367 hwq_count = phba->cfg_hdw_queue;
20369 /* Get the next hwqid which was found last time */
20370 next_hwqid = multixri_pool->rrb_next_hwqid;
20373 /* Go to next hwq */
20374 next_hwqid = (next_hwqid + 1) % hwq_count;
20376 next_multixri_pool =
20377 phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
20378 pbl_pool = &next_multixri_pool->pbl_pool;
20380 /* Check if the public free xri pool is available */
20381 ret = _lpfc_move_xri_pbl_to_pvt(
20382 phba, qp, pbl_pool, pvt_pool, count);
20384 /* Exit while-loop if success or all hwqid are checked */
20385 } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
20387 /* Starting point for the next time */
20388 multixri_pool->rrb_next_hwqid = next_hwqid;
20391 /* stats: all public pools are empty*/
20392 multixri_pool->pbl_empty_count++;
20395 #ifdef LPFC_MXP_STAT
20397 if (next_hwqid == hwqid)
20398 multixri_pool->local_pbl_hit_count++;
20400 multixri_pool->other_pbl_hit_count++;
20406 * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
20407 * @phba: pointer to lpfc hba data structure.
20408 * @qp: belong to which HWQ.
20410 * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
20413 void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
20415 struct lpfc_multixri_pool *multixri_pool;
20416 struct lpfc_pvt_pool *pvt_pool;
20418 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
20419 pvt_pool = &multixri_pool->pvt_pool;
20421 if (pvt_pool->count < pvt_pool->low_watermark)
20422 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
20426 * lpfc_release_io_buf - Return one IO buf back to free pool
20427 * @phba: pointer to lpfc hba data structure.
20428 * @lpfc_ncmd: IO buf to be returned.
20429 * @qp: belong to which HWQ.
20431 * This routine returns one IO buf back to free pool. If this is an urgent IO,
20432 * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
20433 * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
20434 * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to
20435 * lpfc_io_buf_list_put.
20437 void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
20438 struct lpfc_sli4_hdw_queue *qp)
20440 unsigned long iflag;
20441 struct lpfc_pbl_pool *pbl_pool;
20442 struct lpfc_pvt_pool *pvt_pool;
20443 struct lpfc_epd_pool *epd_pool;
20449 /* MUST zero fields if buffer is reused by another protocol */
20450 lpfc_ncmd->nvmeCmd = NULL;
20451 lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL;
20452 lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL;
20454 if (phba->cfg_xpsgl && !phba->nvmet_support &&
20455 !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
20456 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
20458 if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
20459 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
20461 if (phba->cfg_xri_rebalancing) {
20462 if (lpfc_ncmd->expedite) {
20463 /* Return to expedite pool */
20464 epd_pool = &phba->epd_pool;
20465 spin_lock_irqsave(&epd_pool->lock, iflag);
20466 list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
20468 spin_unlock_irqrestore(&epd_pool->lock, iflag);
20472 /* Avoid invalid access if an IO sneaks in and is being rejected
20473 * just _after_ xri pools are destroyed in lpfc_offline.
20474 * Nothing much can be done at this point.
20476 if (!qp->p_multixri_pool)
20479 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20480 pvt_pool = &qp->p_multixri_pool->pvt_pool;
20482 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
20483 abts_io_bufs = qp->abts_scsi_io_bufs;
20484 abts_io_bufs += qp->abts_nvme_io_bufs;
20486 xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
20487 xri_limit = qp->p_multixri_pool->xri_limit;
20489 #ifdef LPFC_MXP_STAT
20490 if (xri_owned <= xri_limit)
20491 qp->p_multixri_pool->below_limit_count++;
20493 qp->p_multixri_pool->above_limit_count++;
20496 /* XRI goes to either public or private free xri pool
20497 * based on watermark and xri_limit
20499 if ((pvt_pool->count < pvt_pool->low_watermark) ||
20500 (xri_owned < xri_limit &&
20501 pvt_pool->count < pvt_pool->high_watermark)) {
20502 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
20503 qp, free_pvt_pool);
20504 list_add_tail(&lpfc_ncmd->list,
20507 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
20509 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
20510 qp, free_pub_pool);
20511 list_add_tail(&lpfc_ncmd->list,
20514 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20517 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
20519 list_add_tail(&lpfc_ncmd->list,
20520 &qp->lpfc_io_buf_list_put);
20522 spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
20528 * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
20529 * @phba: pointer to lpfc hba data structure.
20530 * @pvt_pool: pointer to private pool data structure.
20531 * @ndlp: pointer to lpfc nodelist data structure.
20533 * This routine tries to get one free IO buf from private pool.
20536 * pointer to one free IO buf - if private pool is not empty
20537 * NULL - if private pool is empty
20539 static struct lpfc_io_buf *
20540 lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
20541 struct lpfc_sli4_hdw_queue *qp,
20542 struct lpfc_pvt_pool *pvt_pool,
20543 struct lpfc_nodelist *ndlp)
20545 struct lpfc_io_buf *lpfc_ncmd;
20546 struct lpfc_io_buf *lpfc_ncmd_next;
20547 unsigned long iflag;
20549 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
20550 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
20551 &pvt_pool->list, list) {
20552 if (lpfc_test_rrq_active(
20553 phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
20555 list_del(&lpfc_ncmd->list);
20557 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
20560 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
20566 * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
20567 * @phba: pointer to lpfc hba data structure.
20569 * This routine tries to get one free IO buf from expedite pool.
20572 * pointer to one free IO buf - if expedite pool is not empty
20573 * NULL - if expedite pool is empty
20575 static struct lpfc_io_buf *
20576 lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
20578 struct lpfc_io_buf *lpfc_ncmd;
20579 struct lpfc_io_buf *lpfc_ncmd_next;
20580 unsigned long iflag;
20581 struct lpfc_epd_pool *epd_pool;
20583 epd_pool = &phba->epd_pool;
20586 spin_lock_irqsave(&epd_pool->lock, iflag);
20587 if (epd_pool->count > 0) {
20588 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
20589 &epd_pool->list, list) {
20590 list_del(&lpfc_ncmd->list);
20595 spin_unlock_irqrestore(&epd_pool->lock, iflag);
20601 * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
20602 * @phba: pointer to lpfc hba data structure.
20603 * @ndlp: pointer to lpfc nodelist data structure.
20604 * @hwqid: belong to which HWQ
20605 * @expedite: 1 means this request is urgent.
20607 * This routine will do the following actions and then return a pointer to
20610 * 1. If private free xri count is empty, move some XRIs from public to
20612 * 2. Get one XRI from private free xri pool.
20613 * 3. If we fail to get one from pvt_pool and this is an expedite request,
20614 * get one free xri from expedite pool.
20616 * Note: ndlp is only used on SCSI side for RRQ testing.
20617 * The caller should pass NULL for ndlp on NVME side.
20620 * pointer to one free IO buf - if private pool is not empty
20621 * NULL - if private pool is empty
20623 static struct lpfc_io_buf *
20624 lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
20625 struct lpfc_nodelist *ndlp,
20626 int hwqid, int expedite)
20628 struct lpfc_sli4_hdw_queue *qp;
20629 struct lpfc_multixri_pool *multixri_pool;
20630 struct lpfc_pvt_pool *pvt_pool;
20631 struct lpfc_io_buf *lpfc_ncmd;
20633 qp = &phba->sli4_hba.hdwq[hwqid];
20635 multixri_pool = qp->p_multixri_pool;
20636 pvt_pool = &multixri_pool->pvt_pool;
20637 multixri_pool->io_req_count++;
20639 /* If pvt_pool is empty, move some XRIs from public to private pool */
20640 if (pvt_pool->count == 0)
20641 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
20643 /* Get one XRI from private free xri pool */
20644 lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
20647 lpfc_ncmd->hdwq = qp;
20648 lpfc_ncmd->hdwq_no = hwqid;
20649 } else if (expedite) {
20650 /* If we fail to get one from pvt_pool and this is an expedite
20651 * request, get one free xri from expedite pool.
20653 lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
20659 static inline struct lpfc_io_buf *
20660 lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
20662 struct lpfc_sli4_hdw_queue *qp;
20663 struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
20665 qp = &phba->sli4_hba.hdwq[idx];
20666 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
20667 &qp->lpfc_io_buf_list_get, list) {
20668 if (lpfc_test_rrq_active(phba, ndlp,
20669 lpfc_cmd->cur_iocbq.sli4_lxritag))
20672 if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
20675 list_del_init(&lpfc_cmd->list);
20677 lpfc_cmd->hdwq = qp;
20678 lpfc_cmd->hdwq_no = idx;
20685 * lpfc_get_io_buf - Get one IO buffer from free pool
20686 * @phba: The HBA for which this call is being executed.
20687 * @ndlp: pointer to lpfc nodelist data structure.
20688 * @hwqid: belong to which HWQ
20689 * @expedite: 1 means this request is urgent.
20691 * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
20692 * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
20693 * a IO buffer from head of @hdwq io_buf_list and returns to caller.
20695 * Note: ndlp is only used on SCSI side for RRQ testing.
20696 * The caller should pass NULL for ndlp on NVME side.
20700 * Pointer to lpfc_io_buf - Success
20702 struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
20703 struct lpfc_nodelist *ndlp,
20704 u32 hwqid, int expedite)
20706 struct lpfc_sli4_hdw_queue *qp;
20707 unsigned long iflag;
20708 struct lpfc_io_buf *lpfc_cmd;
20710 qp = &phba->sli4_hba.hdwq[hwqid];
20713 if (phba->cfg_xri_rebalancing)
20714 lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
20715 phba, ndlp, hwqid, expedite);
20717 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
20718 qp, alloc_xri_get);
20719 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
20720 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
20722 lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
20723 qp, alloc_xri_put);
20724 list_splice(&qp->lpfc_io_buf_list_put,
20725 &qp->lpfc_io_buf_list_get);
20726 qp->get_io_bufs += qp->put_io_bufs;
20727 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
20728 qp->put_io_bufs = 0;
20729 spin_unlock(&qp->io_buf_list_put_lock);
20730 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
20732 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
20734 spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
20741 * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
20742 * @phba: The HBA for which this call is being executed.
20743 * @lpfc_buf: IO buf structure to append the SGL chunk
20745 * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
20746 * and will allocate an SGL chunk if the pool is empty.
20750 * Pointer to sli4_hybrid_sgl - Success
20752 struct sli4_hybrid_sgl *
20753 lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
20755 struct sli4_hybrid_sgl *list_entry = NULL;
20756 struct sli4_hybrid_sgl *tmp = NULL;
20757 struct sli4_hybrid_sgl *allocated_sgl = NULL;
20758 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20759 struct list_head *buf_list = &hdwq->sgl_list;
20760 unsigned long iflags;
20762 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20764 if (likely(!list_empty(buf_list))) {
20765 /* break off 1 chunk from the sgl_list */
20766 list_for_each_entry_safe(list_entry, tmp,
20767 buf_list, list_node) {
20768 list_move_tail(&list_entry->list_node,
20769 &lpfc_buf->dma_sgl_xtra_list);
20773 /* allocate more */
20774 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20775 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
20776 cpu_to_node(hdwq->io_wq->chann));
20778 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20779 "8353 error kmalloc memory for HDWQ "
20781 lpfc_buf->hdwq_no, __func__);
20785 tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
20786 GFP_ATOMIC, &tmp->dma_phys_sgl);
20787 if (!tmp->dma_sgl) {
20788 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20789 "8354 error pool_alloc memory for HDWQ "
20791 lpfc_buf->hdwq_no, __func__);
20796 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20797 list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
20800 allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
20801 struct sli4_hybrid_sgl,
20804 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20806 return allocated_sgl;
20810 * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
20811 * @phba: The HBA for which this call is being executed.
20812 * @lpfc_buf: IO buf structure with the SGL chunk
20814 * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
20821 lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
20824 struct sli4_hybrid_sgl *list_entry = NULL;
20825 struct sli4_hybrid_sgl *tmp = NULL;
20826 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20827 struct list_head *buf_list = &hdwq->sgl_list;
20828 unsigned long iflags;
20830 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20832 if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
20833 list_for_each_entry_safe(list_entry, tmp,
20834 &lpfc_buf->dma_sgl_xtra_list,
20836 list_move_tail(&list_entry->list_node,
20843 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20848 * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
20849 * @phba: phba object
20850 * @hdwq: hdwq to cleanup sgl buff resources on
20852 * This routine frees all SGL chunks of hdwq SGL chunk pool.
20858 lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
20859 struct lpfc_sli4_hdw_queue *hdwq)
20861 struct list_head *buf_list = &hdwq->sgl_list;
20862 struct sli4_hybrid_sgl *list_entry = NULL;
20863 struct sli4_hybrid_sgl *tmp = NULL;
20864 unsigned long iflags;
20866 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20868 /* Free sgl pool */
20869 list_for_each_entry_safe(list_entry, tmp,
20870 buf_list, list_node) {
20871 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
20872 list_entry->dma_sgl,
20873 list_entry->dma_phys_sgl);
20874 list_del(&list_entry->list_node);
20878 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20882 * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
20883 * @phba: The HBA for which this call is being executed.
20884 * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
20886 * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
20887 * and will allocate an CMD/RSP buffer if the pool is empty.
20891 * Pointer to fcp_cmd_rsp_buf - Success
20893 struct fcp_cmd_rsp_buf *
20894 lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
20895 struct lpfc_io_buf *lpfc_buf)
20897 struct fcp_cmd_rsp_buf *list_entry = NULL;
20898 struct fcp_cmd_rsp_buf *tmp = NULL;
20899 struct fcp_cmd_rsp_buf *allocated_buf = NULL;
20900 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20901 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
20902 unsigned long iflags;
20904 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20906 if (likely(!list_empty(buf_list))) {
20907 /* break off 1 chunk from the list */
20908 list_for_each_entry_safe(list_entry, tmp,
20911 list_move_tail(&list_entry->list_node,
20912 &lpfc_buf->dma_cmd_rsp_list);
20916 /* allocate more */
20917 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20918 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
20919 cpu_to_node(hdwq->io_wq->chann));
20921 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20922 "8355 error kmalloc memory for HDWQ "
20924 lpfc_buf->hdwq_no, __func__);
20928 tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool,
20930 &tmp->fcp_cmd_rsp_dma_handle);
20932 if (!tmp->fcp_cmnd) {
20933 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
20934 "8356 error pool_alloc memory for HDWQ "
20936 lpfc_buf->hdwq_no, __func__);
20941 tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
20942 sizeof(struct fcp_cmnd));
20944 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20945 list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
20948 allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
20949 struct fcp_cmd_rsp_buf,
20952 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20954 return allocated_buf;
20958 * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
20959 * @phba: The HBA for which this call is being executed.
20960 * @lpfc_buf: IO buf structure with the CMD/RSP buf
20962 * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
20969 lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
20970 struct lpfc_io_buf *lpfc_buf)
20973 struct fcp_cmd_rsp_buf *list_entry = NULL;
20974 struct fcp_cmd_rsp_buf *tmp = NULL;
20975 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
20976 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
20977 unsigned long iflags;
20979 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
20981 if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
20982 list_for_each_entry_safe(list_entry, tmp,
20983 &lpfc_buf->dma_cmd_rsp_list,
20985 list_move_tail(&list_entry->list_node,
20992 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
20997 * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
20998 * @phba: phba object
20999 * @hdwq: hdwq to cleanup cmd rsp buff resources on
21001 * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
21007 lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
21008 struct lpfc_sli4_hdw_queue *hdwq)
21010 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
21011 struct fcp_cmd_rsp_buf *list_entry = NULL;
21012 struct fcp_cmd_rsp_buf *tmp = NULL;
21013 unsigned long iflags;
21015 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21017 /* Free cmd_rsp buf pool */
21018 list_for_each_entry_safe(list_entry, tmp,
21021 dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
21022 list_entry->fcp_cmnd,
21023 list_entry->fcp_cmd_rsp_dma_handle);
21024 list_del(&list_entry->list_node);
21028 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);