1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 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>
38 #include <linux/crash_dump.h>
40 #include <asm/set_memory.h>
46 #include "lpfc_sli4.h"
48 #include "lpfc_disc.h"
50 #include "lpfc_scsi.h"
51 #include "lpfc_nvme.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_logmsg.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_debugfs.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_version.h"
59 /* There are only four IOCB completion types. */
60 typedef enum _lpfc_iocb_type {
68 /* Provide function prototypes local to this module. */
69 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
71 static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
72 uint8_t *, uint32_t *);
73 static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *,
75 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
77 static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
78 struct hbq_dmabuf *dmabuf);
79 static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba,
80 struct lpfc_queue *cq, struct lpfc_cqe *cqe);
81 static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
83 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba,
84 struct lpfc_queue *eq,
85 struct lpfc_eqe *eqe);
86 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
87 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
88 static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q);
89 static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba,
90 struct lpfc_queue *cq,
91 struct lpfc_cqe *cqe);
93 union lpfc_wqe128 lpfc_iread_cmd_template;
94 union lpfc_wqe128 lpfc_iwrite_cmd_template;
95 union lpfc_wqe128 lpfc_icmnd_cmd_template;
98 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq)
103 /* Setup WQE templates for IOs */
104 void lpfc_wqe_cmd_template(void)
106 union lpfc_wqe128 *wqe;
109 wqe = &lpfc_iread_cmd_template;
110 memset(wqe, 0, sizeof(union lpfc_wqe128));
112 /* Word 0, 1, 2 - BDE is variable */
114 /* Word 3 - cmd_buff_len, payload_offset_len is zero */
116 /* Word 4 - total_xfer_len is variable */
118 /* Word 5 - is zero */
120 /* Word 6 - ctxt_tag, xri_tag is variable */
123 bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE);
124 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK);
125 bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3);
126 bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI);
128 /* Word 8 - abort_tag is variable */
130 /* Word 9 - reqtag is variable */
132 /* Word 10 - dbde, wqes is variable */
133 bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0);
134 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
135 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4);
136 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
137 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
139 /* Word 11 - pbde is variable */
140 bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, COMMAND_DATA_IN);
141 bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
142 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
144 /* Word 12 - is zero */
146 /* Word 13, 14, 15 - PBDE is variable */
148 /* IWRITE template */
149 wqe = &lpfc_iwrite_cmd_template;
150 memset(wqe, 0, sizeof(union lpfc_wqe128));
152 /* Word 0, 1, 2 - BDE is variable */
154 /* Word 3 - cmd_buff_len, payload_offset_len is zero */
156 /* Word 4 - total_xfer_len is variable */
158 /* Word 5 - initial_xfer_len is variable */
160 /* Word 6 - ctxt_tag, xri_tag is variable */
163 bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE);
164 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK);
165 bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3);
166 bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI);
168 /* Word 8 - abort_tag is variable */
170 /* Word 9 - reqtag is variable */
172 /* Word 10 - dbde, wqes is variable */
173 bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0);
174 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
175 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4);
176 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
177 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
179 /* Word 11 - pbde is variable */
180 bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, COMMAND_DATA_OUT);
181 bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
182 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
184 /* Word 12 - is zero */
186 /* Word 13, 14, 15 - PBDE is variable */
189 wqe = &lpfc_icmnd_cmd_template;
190 memset(wqe, 0, sizeof(union lpfc_wqe128));
192 /* Word 0, 1, 2 - BDE is variable */
194 /* Word 3 - payload_offset_len is variable */
196 /* Word 4, 5 - is zero */
198 /* Word 6 - ctxt_tag, xri_tag is variable */
201 bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE);
202 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
203 bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3);
204 bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI);
206 /* Word 8 - abort_tag is variable */
208 /* Word 9 - reqtag is variable */
210 /* Word 10 - dbde, wqes is variable */
211 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
212 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE);
213 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE);
214 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
215 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
218 bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, COMMAND_DATA_IN);
219 bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
220 bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0);
222 /* Word 12, 13, 14, 15 - is zero */
225 #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
227 * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
228 * @srcp: Source memory pointer.
229 * @destp: Destination memory pointer.
230 * @cnt: Number of words required to be copied.
231 * Must be a multiple of sizeof(uint64_t)
233 * This function is used for copying data between driver memory
234 * and the SLI WQ. This function also changes the endianness
235 * of each word if native endianness is different from SLI
236 * endianness. This function can be called with or without
240 lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
242 uint64_t *src = srcp;
243 uint64_t *dest = destp;
246 for (i = 0; i < (int)cnt; i += sizeof(uint64_t))
250 #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
254 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
255 * @q: The Work Queue to operate on.
256 * @wqe: The work Queue Entry to put on the Work queue.
258 * This routine will copy the contents of @wqe to the next available entry on
259 * the @q. This function will then ring the Work Queue Doorbell to signal the
260 * HBA to start processing the Work Queue Entry. This function returns 0 if
261 * successful. If no entries are available on @q then this function will return
263 * The caller is expected to hold the hbalock when calling this routine.
266 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe)
268 union lpfc_wqe *temp_wqe;
269 struct lpfc_register doorbell;
276 /* sanity check on queue memory */
280 temp_wqe = lpfc_sli4_qe(q, q->host_index);
282 /* If the host has not yet processed the next entry then we are done */
283 idx = ((q->host_index + 1) % q->entry_count);
284 if (idx == q->hba_index) {
289 /* set consumption flag every once in a while */
290 if (!((q->host_index + 1) % q->notify_interval))
291 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
293 bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
294 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
295 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
296 lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
297 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
298 /* write to DPP aperture taking advatage of Combined Writes */
299 tmp = (uint8_t *)temp_wqe;
301 for (i = 0; i < q->entry_size; i += sizeof(uint64_t))
302 __raw_writeq(*((uint64_t *)(tmp + i)),
305 for (i = 0; i < q->entry_size; i += sizeof(uint32_t))
306 __raw_writel(*((uint32_t *)(tmp + i)),
310 /* ensure WQE bcopy and DPP flushed before doorbell write */
313 /* Update the host index before invoking device */
314 host_index = q->host_index;
320 if (q->db_format == LPFC_DB_LIST_FORMAT) {
321 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
322 bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1);
323 bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1);
324 bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell,
326 bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell,
329 bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
330 bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
332 /* Leave bits <23:16> clear for if_type 6 dpp */
333 if_type = bf_get(lpfc_sli_intf_if_type,
334 &q->phba->sli4_hba.sli_intf);
335 if (if_type != LPFC_SLI_INTF_IF_TYPE_6)
336 bf_set(lpfc_wq_db_list_fm_index, &doorbell,
339 } else if (q->db_format == LPFC_DB_RING_FORMAT) {
340 bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
341 bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
345 writel(doorbell.word0, q->db_regaddr);
351 * lpfc_sli4_wq_release - Updates internal hba index for WQ
352 * @q: The Work Queue to operate on.
353 * @index: The index to advance the hba index to.
355 * This routine will update the HBA index of a queue to reflect consumption of
356 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
357 * an entry the host calls this function to update the queue's internal
361 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
363 /* sanity check on queue memory */
367 q->hba_index = index;
371 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
372 * @q: The Mailbox Queue to operate on.
373 * @mqe: The Mailbox Queue Entry to put on the Work queue.
375 * This routine will copy the contents of @mqe to the next available entry on
376 * the @q. This function will then ring the Work Queue Doorbell to signal the
377 * HBA to start processing the Work Queue Entry. This function returns 0 if
378 * successful. If no entries are available on @q then this function will return
380 * The caller is expected to hold the hbalock when calling this routine.
383 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
385 struct lpfc_mqe *temp_mqe;
386 struct lpfc_register doorbell;
388 /* sanity check on queue memory */
391 temp_mqe = lpfc_sli4_qe(q, q->host_index);
393 /* If the host has not yet processed the next entry then we are done */
394 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
396 lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
397 /* Save off the mailbox pointer for completion */
398 q->phba->mbox = (MAILBOX_t *)temp_mqe;
400 /* Update the host index before invoking device */
401 q->host_index = ((q->host_index + 1) % q->entry_count);
405 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
406 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
407 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
412 * lpfc_sli4_mq_release - Updates internal hba index for MQ
413 * @q: The Mailbox Queue to operate on.
415 * This routine will update the HBA index of a queue to reflect consumption of
416 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
417 * an entry the host calls this function to update the queue's internal
418 * pointers. This routine returns the number of entries that were consumed by
422 lpfc_sli4_mq_release(struct lpfc_queue *q)
424 /* sanity check on queue memory */
428 /* Clear the mailbox pointer for completion */
429 q->phba->mbox = NULL;
430 q->hba_index = ((q->hba_index + 1) % q->entry_count);
435 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
436 * @q: The Event Queue to get the first valid EQE from
438 * This routine will get the first valid Event Queue Entry from @q, update
439 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
440 * the Queue (no more work to do), or the Queue is full of EQEs that have been
441 * processed, but not popped back to the HBA then this routine will return NULL.
443 static struct lpfc_eqe *
444 lpfc_sli4_eq_get(struct lpfc_queue *q)
446 struct lpfc_eqe *eqe;
448 /* sanity check on queue memory */
451 eqe = lpfc_sli4_qe(q, q->host_index);
453 /* If the next EQE is not valid then we are done */
454 if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid)
458 * insert barrier for instruction interlock : data from the hardware
459 * must have the valid bit checked before it can be copied and acted
460 * upon. Speculative instructions were allowing a bcopy at the start
461 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
462 * after our return, to copy data before the valid bit check above
463 * was done. As such, some of the copied data was stale. The barrier
464 * ensures the check is before any data is copied.
471 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
472 * @q: The Event Queue to disable interrupts
476 lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
478 struct lpfc_register doorbell;
481 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
482 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
483 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
484 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
485 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
486 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
490 * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
491 * @q: The Event Queue to disable interrupts
495 lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q)
497 struct lpfc_register doorbell;
500 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
501 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
505 * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state
506 * @phba: adapter with EQ
507 * @q: The Event Queue that the host has completed processing for.
508 * @count: Number of elements that have been consumed
509 * @arm: Indicates whether the host wants to arms this CQ.
511 * This routine will notify the HBA, by ringing the doorbell, that count
512 * number of EQEs have been processed. The @arm parameter indicates whether
513 * the queue should be rearmed when ringing the doorbell.
516 lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
517 uint32_t count, bool arm)
519 struct lpfc_register doorbell;
521 /* sanity check on queue memory */
522 if (unlikely(!q || (count == 0 && !arm)))
525 /* ring doorbell for number popped */
528 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
529 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
531 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
532 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
533 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
534 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
535 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
536 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
537 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
538 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
539 readl(q->phba->sli4_hba.EQDBregaddr);
543 * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state
544 * @phba: adapter with EQ
545 * @q: The Event Queue that the host has completed processing for.
546 * @count: Number of elements that have been consumed
547 * @arm: Indicates whether the host wants to arms this CQ.
549 * This routine will notify the HBA, by ringing the doorbell, that count
550 * number of EQEs have been processed. The @arm parameter indicates whether
551 * the queue should be rearmed when ringing the doorbell.
554 lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
555 uint32_t count, bool arm)
557 struct lpfc_register doorbell;
559 /* sanity check on queue memory */
560 if (unlikely(!q || (count == 0 && !arm)))
563 /* ring doorbell for number popped */
566 bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1);
567 bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count);
568 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
569 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
570 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
571 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
572 readl(q->phba->sli4_hba.EQDBregaddr);
576 __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
577 struct lpfc_eqe *eqe)
579 if (!phba->sli4_hba.pc_sli4_params.eqav)
580 bf_set_le32(lpfc_eqe_valid, eqe, 0);
582 eq->host_index = ((eq->host_index + 1) % eq->entry_count);
584 /* if the index wrapped around, toggle the valid bit */
585 if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index)
586 eq->qe_valid = (eq->qe_valid) ? 0 : 1;
590 lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
592 struct lpfc_eqe *eqe = NULL;
593 u32 eq_count = 0, cq_count = 0;
594 struct lpfc_cqe *cqe = NULL;
595 struct lpfc_queue *cq = NULL, *childq = NULL;
598 /* walk all the EQ entries and drop on the floor */
599 eqe = lpfc_sli4_eq_get(eq);
601 /* Get the reference to the corresponding CQ */
602 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
605 list_for_each_entry(childq, &eq->child_list, list) {
606 if (childq->queue_id == cqid) {
611 /* If CQ is valid, iterate through it and drop all the CQEs */
613 cqe = lpfc_sli4_cq_get(cq);
615 __lpfc_sli4_consume_cqe(phba, cq, cqe);
617 cqe = lpfc_sli4_cq_get(cq);
619 /* Clear and re-arm the CQ */
620 phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count,
624 __lpfc_sli4_consume_eqe(phba, eq, eqe);
626 eqe = lpfc_sli4_eq_get(eq);
629 /* Clear and re-arm the EQ */
630 phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM);
634 lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq,
637 struct lpfc_eqe *eqe;
638 int count = 0, consumed = 0;
640 if (cmpxchg(&eq->queue_claimed, 0, 1) != 0)
643 eqe = lpfc_sli4_eq_get(eq);
645 lpfc_sli4_hba_handle_eqe(phba, eq, eqe);
646 __lpfc_sli4_consume_eqe(phba, eq, eqe);
649 if (!(++count % eq->max_proc_limit))
652 if (!(count % eq->notify_interval)) {
653 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed,
658 eqe = lpfc_sli4_eq_get(eq);
660 eq->EQ_processed += count;
662 /* Track the max number of EQEs processed in 1 intr */
663 if (count > eq->EQ_max_eqe)
664 eq->EQ_max_eqe = count;
666 xchg(&eq->queue_claimed, 0);
669 /* Always clear the EQ. */
670 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm);
676 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
677 * @q: The Completion Queue to get the first valid CQE from
679 * This routine will get the first valid Completion Queue Entry from @q, update
680 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
681 * the Queue (no more work to do), or the Queue is full of CQEs that have been
682 * processed, but not popped back to the HBA then this routine will return NULL.
684 static struct lpfc_cqe *
685 lpfc_sli4_cq_get(struct lpfc_queue *q)
687 struct lpfc_cqe *cqe;
689 /* sanity check on queue memory */
692 cqe = lpfc_sli4_qe(q, q->host_index);
694 /* If the next CQE is not valid then we are done */
695 if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid)
699 * insert barrier for instruction interlock : data from the hardware
700 * must have the valid bit checked before it can be copied and acted
701 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
702 * instructions allowing action on content before valid bit checked,
703 * add barrier here as well. May not be needed as "content" is a
704 * single 32-bit entity here (vs multi word structure for cq's).
711 __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
712 struct lpfc_cqe *cqe)
714 if (!phba->sli4_hba.pc_sli4_params.cqav)
715 bf_set_le32(lpfc_cqe_valid, cqe, 0);
717 cq->host_index = ((cq->host_index + 1) % cq->entry_count);
719 /* if the index wrapped around, toggle the valid bit */
720 if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index)
721 cq->qe_valid = (cq->qe_valid) ? 0 : 1;
725 * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state.
726 * @phba: the adapter with the CQ
727 * @q: The Completion Queue that the host has completed processing for.
728 * @count: the number of elements that were consumed
729 * @arm: Indicates whether the host wants to arms this CQ.
731 * This routine will notify the HBA, by ringing the doorbell, that the
732 * CQEs have been processed. The @arm parameter specifies whether the
733 * queue should be rearmed when ringing the doorbell.
736 lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
737 uint32_t count, bool arm)
739 struct lpfc_register doorbell;
741 /* sanity check on queue memory */
742 if (unlikely(!q || (count == 0 && !arm)))
745 /* ring doorbell for number popped */
748 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
749 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
750 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
751 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
752 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
753 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
754 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
758 * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state.
759 * @phba: the adapter with the CQ
760 * @q: The Completion Queue that the host has completed processing for.
761 * @count: the number of elements that were consumed
762 * @arm: Indicates whether the host wants to arms this CQ.
764 * This routine will notify the HBA, by ringing the doorbell, that the
765 * CQEs have been processed. The @arm parameter specifies whether the
766 * queue should be rearmed when ringing the doorbell.
769 lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
770 uint32_t count, bool arm)
772 struct lpfc_register doorbell;
774 /* sanity check on queue memory */
775 if (unlikely(!q || (count == 0 && !arm)))
778 /* ring doorbell for number popped */
781 bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1);
782 bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count);
783 bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id);
784 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
788 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
790 * This routine will copy the contents of @wqe to the next available entry on
791 * the @q. This function will then ring the Receive Queue Doorbell to signal the
792 * HBA to start processing the Receive Queue Entry. This function returns the
793 * index that the rqe was copied to if successful. If no entries are available
794 * on @q then this function will return -ENOMEM.
795 * The caller is expected to hold the hbalock when calling this routine.
798 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
799 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
801 struct lpfc_rqe *temp_hrqe;
802 struct lpfc_rqe *temp_drqe;
803 struct lpfc_register doorbell;
807 /* sanity check on queue memory */
808 if (unlikely(!hq) || unlikely(!dq))
810 hq_put_index = hq->host_index;
811 dq_put_index = dq->host_index;
812 temp_hrqe = lpfc_sli4_qe(hq, hq_put_index);
813 temp_drqe = lpfc_sli4_qe(dq, dq_put_index);
815 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
817 if (hq_put_index != dq_put_index)
819 /* If the host has not yet processed the next entry then we are done */
820 if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index)
822 lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
823 lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
825 /* Update the host index to point to the next slot */
826 hq->host_index = ((hq_put_index + 1) % hq->entry_count);
827 dq->host_index = ((dq_put_index + 1) % dq->entry_count);
830 /* Ring The Header Receive Queue Doorbell */
831 if (!(hq->host_index % hq->notify_interval)) {
833 if (hq->db_format == LPFC_DB_RING_FORMAT) {
834 bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
835 hq->notify_interval);
836 bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
837 } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
838 bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
839 hq->notify_interval);
840 bf_set(lpfc_rq_db_list_fm_index, &doorbell,
842 bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
846 writel(doorbell.word0, hq->db_regaddr);
852 * lpfc_sli4_rq_release - Updates internal hba index for RQ
854 * This routine will update the HBA index of a queue to reflect consumption of
855 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
856 * consumed an entry the host calls this function to update the queue's
857 * internal pointers. This routine returns the number of entries that were
858 * consumed by the HBA.
861 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
863 /* sanity check on queue memory */
864 if (unlikely(!hq) || unlikely(!dq))
867 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
869 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
870 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
875 * lpfc_cmd_iocb - Get next command iocb entry in the ring
876 * @phba: Pointer to HBA context object.
877 * @pring: Pointer to driver SLI ring object.
879 * This function returns pointer to next command iocb entry
880 * in the command ring. The caller must hold hbalock to prevent
881 * other threads consume the next command iocb.
882 * SLI-2/SLI-3 provide different sized iocbs.
884 static inline IOCB_t *
885 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
887 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
888 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
892 * lpfc_resp_iocb - Get next response iocb entry in the ring
893 * @phba: Pointer to HBA context object.
894 * @pring: Pointer to driver SLI ring object.
896 * This function returns pointer to next response iocb entry
897 * in the response ring. The caller must hold hbalock to make sure
898 * that no other thread consume the next response iocb.
899 * SLI-2/SLI-3 provide different sized iocbs.
901 static inline IOCB_t *
902 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
904 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
905 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
909 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
910 * @phba: Pointer to HBA context object.
912 * This function is called with hbalock held. This function
913 * allocates a new driver iocb object from the iocb pool. If the
914 * allocation is successful, it returns pointer to the newly
915 * allocated iocb object else it returns NULL.
918 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
920 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
921 struct lpfc_iocbq * iocbq = NULL;
923 lockdep_assert_held(&phba->hbalock);
925 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
928 if (phba->iocb_cnt > phba->iocb_max)
929 phba->iocb_max = phba->iocb_cnt;
934 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
935 * @phba: Pointer to HBA context object.
936 * @xritag: XRI value.
938 * This function clears the sglq pointer from the array of acive
939 * sglq's. The xritag that is passed in is used to index into the
940 * array. Before the xritag can be used it needs to be adjusted
941 * by subtracting the xribase.
943 * Returns sglq ponter = success, NULL = Failure.
946 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
948 struct lpfc_sglq *sglq;
950 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
951 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
956 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
957 * @phba: Pointer to HBA context object.
958 * @xritag: XRI value.
960 * This function returns the sglq pointer from the array of acive
961 * sglq's. The xritag that is passed in is used to index into the
962 * array. Before the xritag can be used it needs to be adjusted
963 * by subtracting the xribase.
965 * Returns sglq ponter = success, NULL = Failure.
968 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
970 struct lpfc_sglq *sglq;
972 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
977 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
978 * @phba: Pointer to HBA context object.
979 * @xritag: xri used in this exchange.
980 * @rrq: The RRQ to be cleared.
984 lpfc_clr_rrq_active(struct lpfc_hba *phba,
986 struct lpfc_node_rrq *rrq)
988 struct lpfc_nodelist *ndlp = NULL;
990 /* Lookup did to verify if did is still active on this vport */
992 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
997 if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
1000 rrq->rrq_stop_time = 0;
1003 mempool_free(rrq, phba->rrq_pool);
1007 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
1008 * @phba: Pointer to HBA context object.
1010 * This function is called with hbalock held. This function
1011 * Checks if stop_time (ratov from setting rrq active) has
1012 * been reached, if it has and the send_rrq flag is set then
1013 * it will call lpfc_send_rrq. If the send_rrq flag is not set
1014 * then it will just call the routine to clear the rrq and
1015 * free the rrq resource.
1016 * The timer is set to the next rrq that is going to expire before
1017 * leaving the routine.
1021 lpfc_handle_rrq_active(struct lpfc_hba *phba)
1023 struct lpfc_node_rrq *rrq;
1024 struct lpfc_node_rrq *nextrrq;
1025 unsigned long next_time;
1026 unsigned long iflags;
1027 LIST_HEAD(send_rrq);
1029 spin_lock_irqsave(&phba->hbalock, iflags);
1030 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1031 next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
1032 list_for_each_entry_safe(rrq, nextrrq,
1033 &phba->active_rrq_list, list) {
1034 if (time_after(jiffies, rrq->rrq_stop_time))
1035 list_move(&rrq->list, &send_rrq);
1036 else if (time_before(rrq->rrq_stop_time, next_time))
1037 next_time = rrq->rrq_stop_time;
1039 spin_unlock_irqrestore(&phba->hbalock, iflags);
1040 if ((!list_empty(&phba->active_rrq_list)) &&
1041 (!(phba->pport->load_flag & FC_UNLOADING)))
1042 mod_timer(&phba->rrq_tmr, next_time);
1043 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
1044 list_del(&rrq->list);
1045 if (!rrq->send_rrq) {
1046 /* this call will free the rrq */
1047 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1048 } else if (lpfc_send_rrq(phba, rrq)) {
1049 /* if we send the rrq then the completion handler
1050 * will clear the bit in the xribitmap.
1052 lpfc_clr_rrq_active(phba, rrq->xritag,
1059 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
1060 * @vport: Pointer to vport context object.
1061 * @xri: The xri used in the exchange.
1062 * @did: The targets DID for this exchange.
1064 * returns NULL = rrq not found in the phba->active_rrq_list.
1065 * rrq = rrq for this xri and target.
1067 struct lpfc_node_rrq *
1068 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
1070 struct lpfc_hba *phba = vport->phba;
1071 struct lpfc_node_rrq *rrq;
1072 struct lpfc_node_rrq *nextrrq;
1073 unsigned long iflags;
1075 if (phba->sli_rev != LPFC_SLI_REV4)
1077 spin_lock_irqsave(&phba->hbalock, iflags);
1078 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
1079 if (rrq->vport == vport && rrq->xritag == xri &&
1080 rrq->nlp_DID == did){
1081 list_del(&rrq->list);
1082 spin_unlock_irqrestore(&phba->hbalock, iflags);
1086 spin_unlock_irqrestore(&phba->hbalock, iflags);
1091 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
1092 * @vport: Pointer to vport context object.
1093 * @ndlp: Pointer to the lpfc_node_list structure.
1094 * If ndlp is NULL Remove all active RRQs for this vport from the
1095 * phba->active_rrq_list and clear the rrq.
1096 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
1099 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1102 struct lpfc_hba *phba = vport->phba;
1103 struct lpfc_node_rrq *rrq;
1104 struct lpfc_node_rrq *nextrrq;
1105 unsigned long iflags;
1106 LIST_HEAD(rrq_list);
1108 if (phba->sli_rev != LPFC_SLI_REV4)
1111 lpfc_sli4_vport_delete_els_xri_aborted(vport);
1112 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
1114 spin_lock_irqsave(&phba->hbalock, iflags);
1115 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
1116 if (rrq->vport != vport)
1119 if (!ndlp || ndlp == lpfc_findnode_did(vport, rrq->nlp_DID))
1120 list_move(&rrq->list, &rrq_list);
1123 spin_unlock_irqrestore(&phba->hbalock, iflags);
1125 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
1126 list_del(&rrq->list);
1127 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1132 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
1133 * @phba: Pointer to HBA context object.
1134 * @ndlp: Targets nodelist pointer for this exchange.
1135 * @xritag: the xri in the bitmap to test.
1137 * This function returns:
1138 * 0 = rrq not active for this xri
1139 * 1 = rrq is valid for this xri.
1142 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1147 if (!ndlp->active_rrqs_xri_bitmap)
1149 if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1156 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
1157 * @phba: Pointer to HBA context object.
1158 * @ndlp: nodelist pointer for this target.
1159 * @xritag: xri used in this exchange.
1160 * @rxid: Remote Exchange ID.
1161 * @send_rrq: Flag used to determine if we should send rrq els cmd.
1163 * This function takes the hbalock.
1164 * The active bit is always set in the active rrq xri_bitmap even
1165 * if there is no slot avaiable for the other rrq information.
1167 * returns 0 rrq actived for this xri
1168 * < 0 No memory or invalid ndlp.
1171 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1172 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
1174 unsigned long iflags;
1175 struct lpfc_node_rrq *rrq;
1181 if (!phba->cfg_enable_rrq)
1184 spin_lock_irqsave(&phba->hbalock, iflags);
1185 if (phba->pport->load_flag & FC_UNLOADING) {
1186 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1190 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
1193 if (!ndlp->active_rrqs_xri_bitmap)
1196 if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1199 spin_unlock_irqrestore(&phba->hbalock, iflags);
1200 rrq = mempool_alloc(phba->rrq_pool, GFP_ATOMIC);
1202 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1203 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
1204 " DID:0x%x Send:%d\n",
1205 xritag, rxid, ndlp->nlp_DID, send_rrq);
1208 if (phba->cfg_enable_rrq == 1)
1209 rrq->send_rrq = send_rrq;
1212 rrq->xritag = xritag;
1213 rrq->rrq_stop_time = jiffies +
1214 msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
1215 rrq->nlp_DID = ndlp->nlp_DID;
1216 rrq->vport = ndlp->vport;
1218 spin_lock_irqsave(&phba->hbalock, iflags);
1219 empty = list_empty(&phba->active_rrq_list);
1220 list_add_tail(&rrq->list, &phba->active_rrq_list);
1221 phba->hba_flag |= HBA_RRQ_ACTIVE;
1223 lpfc_worker_wake_up(phba);
1224 spin_unlock_irqrestore(&phba->hbalock, iflags);
1227 spin_unlock_irqrestore(&phba->hbalock, iflags);
1228 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1229 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
1230 " DID:0x%x Send:%d\n",
1231 xritag, rxid, ndlp->nlp_DID, send_rrq);
1236 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
1237 * @phba: Pointer to HBA context object.
1238 * @piocbq: Pointer to the iocbq.
1240 * The driver calls this function with either the nvme ls ring lock
1241 * or the fc els ring lock held depending on the iocb usage. This function
1242 * gets a new driver sglq object from the sglq list. If the list is not empty
1243 * then it is successful, it returns pointer to the newly allocated sglq
1244 * object else it returns NULL.
1246 static struct lpfc_sglq *
1247 __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1249 struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
1250 struct lpfc_sglq *sglq = NULL;
1251 struct lpfc_sglq *start_sglq = NULL;
1252 struct lpfc_io_buf *lpfc_cmd;
1253 struct lpfc_nodelist *ndlp;
1254 struct lpfc_sli_ring *pring = NULL;
1257 if (piocbq->iocb_flag & LPFC_IO_NVME_LS)
1258 pring = phba->sli4_hba.nvmels_wq->pring;
1260 pring = lpfc_phba_elsring(phba);
1262 lockdep_assert_held(&pring->ring_lock);
1264 if (piocbq->iocb_flag & LPFC_IO_FCP) {
1265 lpfc_cmd = (struct lpfc_io_buf *) piocbq->context1;
1266 ndlp = lpfc_cmd->rdata->pnode;
1267 } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) &&
1268 !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) {
1269 ndlp = piocbq->context_un.ndlp;
1270 } else if (piocbq->iocb_flag & LPFC_IO_LIBDFC) {
1271 if (piocbq->iocb_flag & LPFC_IO_LOOPBACK)
1274 ndlp = piocbq->context_un.ndlp;
1276 ndlp = piocbq->context1;
1279 spin_lock(&phba->sli4_hba.sgl_list_lock);
1280 list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
1285 if (ndlp && ndlp->active_rrqs_xri_bitmap &&
1286 test_bit(sglq->sli4_lxritag,
1287 ndlp->active_rrqs_xri_bitmap)) {
1288 /* This xri has an rrq outstanding for this DID.
1289 * put it back in the list and get another xri.
1291 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1293 list_remove_head(lpfc_els_sgl_list, sglq,
1294 struct lpfc_sglq, list);
1295 if (sglq == start_sglq) {
1296 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1304 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1305 sglq->state = SGL_ALLOCATED;
1307 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1312 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
1313 * @phba: Pointer to HBA context object.
1314 * @piocbq: Pointer to the iocbq.
1316 * This function is called with the sgl_list lock held. This function
1317 * gets a new driver sglq object from the sglq list. If the
1318 * list is not empty then it is successful, it returns pointer to the newly
1319 * allocated sglq object else it returns NULL.
1322 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1324 struct list_head *lpfc_nvmet_sgl_list;
1325 struct lpfc_sglq *sglq = NULL;
1327 lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
1329 lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
1331 list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
1334 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1335 sglq->state = SGL_ALLOCATED;
1340 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1341 * @phba: Pointer to HBA context object.
1343 * This function is called with no lock held. This function
1344 * allocates a new driver iocb object from the iocb pool. If the
1345 * allocation is successful, it returns pointer to the newly
1346 * allocated iocb object else it returns NULL.
1349 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
1351 struct lpfc_iocbq * iocbq = NULL;
1352 unsigned long iflags;
1354 spin_lock_irqsave(&phba->hbalock, iflags);
1355 iocbq = __lpfc_sli_get_iocbq(phba);
1356 spin_unlock_irqrestore(&phba->hbalock, iflags);
1361 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1362 * @phba: Pointer to HBA context object.
1363 * @iocbq: Pointer to driver iocb object.
1365 * This function is called to release the driver iocb object
1366 * to the iocb pool. The iotag in the iocb object
1367 * does not change for each use of the iocb object. This function
1368 * clears all other fields of the iocb object when it is freed.
1369 * The sqlq structure that holds the xritag and phys and virtual
1370 * mappings for the scatter gather list is retrieved from the
1371 * active array of sglq. The get of the sglq pointer also clears
1372 * the entry in the array. If the status of the IO indiactes that
1373 * this IO was aborted then the sglq entry it put on the
1374 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1375 * IO has good status or fails for any other reason then the sglq
1376 * entry is added to the free list (lpfc_els_sgl_list). The hbalock is
1377 * asserted held in the code path calling this routine.
1380 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1382 struct lpfc_sglq *sglq;
1383 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1384 unsigned long iflag = 0;
1385 struct lpfc_sli_ring *pring;
1387 if (iocbq->sli4_xritag == NO_XRI)
1390 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
1394 if (iocbq->iocb_flag & LPFC_IO_NVMET) {
1395 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1397 sglq->state = SGL_FREED;
1399 list_add_tail(&sglq->list,
1400 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1401 spin_unlock_irqrestore(
1402 &phba->sli4_hba.sgl_list_lock, iflag);
1406 if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) &&
1407 (sglq->state != SGL_XRI_ABORTED)) {
1408 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1411 /* Check if we can get a reference on ndlp */
1412 if (sglq->ndlp && !lpfc_nlp_get(sglq->ndlp))
1415 list_add(&sglq->list,
1416 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1417 spin_unlock_irqrestore(
1418 &phba->sli4_hba.sgl_list_lock, iflag);
1420 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1422 sglq->state = SGL_FREED;
1424 list_add_tail(&sglq->list,
1425 &phba->sli4_hba.lpfc_els_sgl_list);
1426 spin_unlock_irqrestore(
1427 &phba->sli4_hba.sgl_list_lock, iflag);
1428 pring = lpfc_phba_elsring(phba);
1429 /* Check if TXQ queue needs to be serviced */
1430 if (pring && (!list_empty(&pring->txq)))
1431 lpfc_worker_wake_up(phba);
1437 * Clean all volatile data fields, preserve iotag and node struct.
1439 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1440 iocbq->sli4_lxritag = NO_XRI;
1441 iocbq->sli4_xritag = NO_XRI;
1442 iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET |
1444 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1449 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1450 * @phba: Pointer to HBA context object.
1451 * @iocbq: Pointer to driver iocb object.
1453 * This function is called to release the driver iocb object to the
1454 * iocb pool. The iotag in the iocb object does not change for each
1455 * use of the iocb object. This function clears all other fields of
1456 * the iocb object when it is freed. The hbalock is asserted held in
1457 * the code path calling this routine.
1460 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1462 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1465 * Clean all volatile data fields, preserve iotag and node struct.
1467 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1468 iocbq->sli4_xritag = NO_XRI;
1469 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1473 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1474 * @phba: Pointer to HBA context object.
1475 * @iocbq: Pointer to driver iocb object.
1477 * This function is called with hbalock held to release driver
1478 * iocb object to the iocb pool. The iotag in the iocb object
1479 * does not change for each use of the iocb object. This function
1480 * clears all other fields of the iocb object when it is freed.
1483 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1485 lockdep_assert_held(&phba->hbalock);
1487 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1492 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1493 * @phba: Pointer to HBA context object.
1494 * @iocbq: Pointer to driver iocb object.
1496 * This function is called with no lock held to release the iocb to
1500 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1502 unsigned long iflags;
1505 * Clean all volatile data fields, preserve iotag and node struct.
1507 spin_lock_irqsave(&phba->hbalock, iflags);
1508 __lpfc_sli_release_iocbq(phba, iocbq);
1509 spin_unlock_irqrestore(&phba->hbalock, iflags);
1513 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1514 * @phba: Pointer to HBA context object.
1515 * @iocblist: List of IOCBs.
1516 * @ulpstatus: ULP status in IOCB command field.
1517 * @ulpWord4: ULP word-4 in IOCB command field.
1519 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1520 * on the list by invoking the complete callback function associated with the
1521 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1525 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1526 uint32_t ulpstatus, uint32_t ulpWord4)
1528 struct lpfc_iocbq *piocb;
1530 while (!list_empty(iocblist)) {
1531 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1532 if (piocb->wqe_cmpl) {
1533 if (piocb->iocb_flag & LPFC_IO_NVME)
1534 lpfc_nvme_cancel_iocb(phba, piocb,
1535 ulpstatus, ulpWord4);
1537 lpfc_sli_release_iocbq(phba, piocb);
1539 } else if (piocb->iocb_cmpl) {
1540 piocb->iocb.ulpStatus = ulpstatus;
1541 piocb->iocb.un.ulpWord[4] = ulpWord4;
1542 (piocb->iocb_cmpl) (phba, piocb, piocb);
1544 lpfc_sli_release_iocbq(phba, piocb);
1551 * lpfc_sli_iocb_cmd_type - Get the iocb type
1552 * @iocb_cmnd: iocb command code.
1554 * This function is called by ring event handler function to get the iocb type.
1555 * This function translates the iocb command to an iocb command type used to
1556 * decide the final disposition of each completed IOCB.
1557 * The function returns
1558 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1559 * LPFC_SOL_IOCB if it is a solicited iocb completion
1560 * LPFC_ABORT_IOCB if it is an abort iocb
1561 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1563 * The caller is not required to hold any lock.
1565 static lpfc_iocb_type
1566 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1568 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1570 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1573 switch (iocb_cmnd) {
1574 case CMD_XMIT_SEQUENCE_CR:
1575 case CMD_XMIT_SEQUENCE_CX:
1576 case CMD_XMIT_BCAST_CN:
1577 case CMD_XMIT_BCAST_CX:
1578 case CMD_ELS_REQUEST_CR:
1579 case CMD_ELS_REQUEST_CX:
1580 case CMD_CREATE_XRI_CR:
1581 case CMD_CREATE_XRI_CX:
1582 case CMD_GET_RPI_CN:
1583 case CMD_XMIT_ELS_RSP_CX:
1584 case CMD_GET_RPI_CR:
1585 case CMD_FCP_IWRITE_CR:
1586 case CMD_FCP_IWRITE_CX:
1587 case CMD_FCP_IREAD_CR:
1588 case CMD_FCP_IREAD_CX:
1589 case CMD_FCP_ICMND_CR:
1590 case CMD_FCP_ICMND_CX:
1591 case CMD_FCP_TSEND_CX:
1592 case CMD_FCP_TRSP_CX:
1593 case CMD_FCP_TRECEIVE_CX:
1594 case CMD_FCP_AUTO_TRSP_CX:
1595 case CMD_ADAPTER_MSG:
1596 case CMD_ADAPTER_DUMP:
1597 case CMD_XMIT_SEQUENCE64_CR:
1598 case CMD_XMIT_SEQUENCE64_CX:
1599 case CMD_XMIT_BCAST64_CN:
1600 case CMD_XMIT_BCAST64_CX:
1601 case CMD_ELS_REQUEST64_CR:
1602 case CMD_ELS_REQUEST64_CX:
1603 case CMD_FCP_IWRITE64_CR:
1604 case CMD_FCP_IWRITE64_CX:
1605 case CMD_FCP_IREAD64_CR:
1606 case CMD_FCP_IREAD64_CX:
1607 case CMD_FCP_ICMND64_CR:
1608 case CMD_FCP_ICMND64_CX:
1609 case CMD_FCP_TSEND64_CX:
1610 case CMD_FCP_TRSP64_CX:
1611 case CMD_FCP_TRECEIVE64_CX:
1612 case CMD_GEN_REQUEST64_CR:
1613 case CMD_GEN_REQUEST64_CX:
1614 case CMD_XMIT_ELS_RSP64_CX:
1615 case DSSCMD_IWRITE64_CR:
1616 case DSSCMD_IWRITE64_CX:
1617 case DSSCMD_IREAD64_CR:
1618 case DSSCMD_IREAD64_CX:
1619 case CMD_SEND_FRAME:
1620 type = LPFC_SOL_IOCB;
1622 case CMD_ABORT_XRI_CN:
1623 case CMD_ABORT_XRI_CX:
1624 case CMD_CLOSE_XRI_CN:
1625 case CMD_CLOSE_XRI_CX:
1626 case CMD_XRI_ABORTED_CX:
1627 case CMD_ABORT_MXRI64_CN:
1628 case CMD_XMIT_BLS_RSP64_CX:
1629 type = LPFC_ABORT_IOCB;
1631 case CMD_RCV_SEQUENCE_CX:
1632 case CMD_RCV_ELS_REQ_CX:
1633 case CMD_RCV_SEQUENCE64_CX:
1634 case CMD_RCV_ELS_REQ64_CX:
1635 case CMD_ASYNC_STATUS:
1636 case CMD_IOCB_RCV_SEQ64_CX:
1637 case CMD_IOCB_RCV_ELS64_CX:
1638 case CMD_IOCB_RCV_CONT64_CX:
1639 case CMD_IOCB_RET_XRI64_CX:
1640 type = LPFC_UNSOL_IOCB;
1642 case CMD_IOCB_XMIT_MSEQ64_CR:
1643 case CMD_IOCB_XMIT_MSEQ64_CX:
1644 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1645 case CMD_IOCB_RCV_ELS_LIST64_CX:
1646 case CMD_IOCB_CLOSE_EXTENDED_CN:
1647 case CMD_IOCB_ABORT_EXTENDED_CN:
1648 case CMD_IOCB_RET_HBQE64_CN:
1649 case CMD_IOCB_FCP_IBIDIR64_CR:
1650 case CMD_IOCB_FCP_IBIDIR64_CX:
1651 case CMD_IOCB_FCP_ITASKMGT64_CX:
1652 case CMD_IOCB_LOGENTRY_CN:
1653 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1654 printk("%s - Unhandled SLI-3 Command x%x\n",
1655 __func__, iocb_cmnd);
1656 type = LPFC_UNKNOWN_IOCB;
1659 type = LPFC_UNKNOWN_IOCB;
1667 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1668 * @phba: Pointer to HBA context object.
1670 * This function is called from SLI initialization code
1671 * to configure every ring of the HBA's SLI interface. The
1672 * caller is not required to hold any lock. This function issues
1673 * a config_ring mailbox command for each ring.
1674 * This function returns zero if successful else returns a negative
1678 lpfc_sli_ring_map(struct lpfc_hba *phba)
1680 struct lpfc_sli *psli = &phba->sli;
1685 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1689 phba->link_state = LPFC_INIT_MBX_CMDS;
1690 for (i = 0; i < psli->num_rings; i++) {
1691 lpfc_config_ring(phba, i, pmb);
1692 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1693 if (rc != MBX_SUCCESS) {
1694 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1695 "0446 Adapter failed to init (%d), "
1696 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1698 rc, pmbox->mbxCommand,
1699 pmbox->mbxStatus, i);
1700 phba->link_state = LPFC_HBA_ERROR;
1705 mempool_free(pmb, phba->mbox_mem_pool);
1710 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1711 * @phba: Pointer to HBA context object.
1712 * @pring: Pointer to driver SLI ring object.
1713 * @piocb: Pointer to the driver iocb object.
1715 * The driver calls this function with the hbalock held for SLI3 ports or
1716 * the ring lock held for SLI4 ports. The function adds the
1717 * new iocb to txcmplq of the given ring. This function always returns
1718 * 0. If this function is called for ELS ring, this function checks if
1719 * there is a vport associated with the ELS command. This function also
1720 * starts els_tmofunc timer if this is an ELS command.
1723 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1724 struct lpfc_iocbq *piocb)
1726 if (phba->sli_rev == LPFC_SLI_REV4)
1727 lockdep_assert_held(&pring->ring_lock);
1729 lockdep_assert_held(&phba->hbalock);
1733 list_add_tail(&piocb->list, &pring->txcmplq);
1734 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1735 pring->txcmplq_cnt++;
1737 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1738 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1739 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1740 BUG_ON(!piocb->vport);
1741 if (!(piocb->vport->load_flag & FC_UNLOADING))
1742 mod_timer(&piocb->vport->els_tmofunc,
1744 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1751 * lpfc_sli_ringtx_get - Get first element of the txq
1752 * @phba: Pointer to HBA context object.
1753 * @pring: Pointer to driver SLI ring object.
1755 * This function is called with hbalock held to get next
1756 * iocb in txq of the given ring. If there is any iocb in
1757 * the txq, the function returns first iocb in the list after
1758 * removing the iocb from the list, else it returns NULL.
1761 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1763 struct lpfc_iocbq *cmd_iocb;
1765 lockdep_assert_held(&phba->hbalock);
1767 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1772 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1773 * @phba: Pointer to HBA context object.
1774 * @pring: Pointer to driver SLI ring object.
1776 * This function is called with hbalock held and the caller must post the
1777 * iocb without releasing the lock. If the caller releases the lock,
1778 * iocb slot returned by the function is not guaranteed to be available.
1779 * The function returns pointer to the next available iocb slot if there
1780 * is available slot in the ring, else it returns NULL.
1781 * If the get index of the ring is ahead of the put index, the function
1782 * will post an error attention event to the worker thread to take the
1783 * HBA to offline state.
1786 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1788 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1789 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
1791 lockdep_assert_held(&phba->hbalock);
1793 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
1794 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
1795 pring->sli.sli3.next_cmdidx = 0;
1797 if (unlikely(pring->sli.sli3.local_getidx ==
1798 pring->sli.sli3.next_cmdidx)) {
1800 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
1802 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
1803 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1804 "0315 Ring %d issue: portCmdGet %d "
1805 "is bigger than cmd ring %d\n",
1807 pring->sli.sli3.local_getidx,
1810 phba->link_state = LPFC_HBA_ERROR;
1812 * All error attention handlers are posted to
1815 phba->work_ha |= HA_ERATT;
1816 phba->work_hs = HS_FFER3;
1818 lpfc_worker_wake_up(phba);
1823 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
1827 return lpfc_cmd_iocb(phba, pring);
1831 * lpfc_sli_next_iotag - Get an iotag for the iocb
1832 * @phba: Pointer to HBA context object.
1833 * @iocbq: Pointer to driver iocb object.
1835 * This function gets an iotag for the iocb. If there is no unused iotag and
1836 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1837 * array and assigns a new iotag.
1838 * The function returns the allocated iotag if successful, else returns zero.
1839 * Zero is not a valid iotag.
1840 * The caller is not required to hold any lock.
1843 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1845 struct lpfc_iocbq **new_arr;
1846 struct lpfc_iocbq **old_arr;
1848 struct lpfc_sli *psli = &phba->sli;
1851 spin_lock_irq(&phba->hbalock);
1852 iotag = psli->last_iotag;
1853 if(++iotag < psli->iocbq_lookup_len) {
1854 psli->last_iotag = iotag;
1855 psli->iocbq_lookup[iotag] = iocbq;
1856 spin_unlock_irq(&phba->hbalock);
1857 iocbq->iotag = iotag;
1859 } else if (psli->iocbq_lookup_len < (0xffff
1860 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
1861 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
1862 spin_unlock_irq(&phba->hbalock);
1863 new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
1866 spin_lock_irq(&phba->hbalock);
1867 old_arr = psli->iocbq_lookup;
1868 if (new_len <= psli->iocbq_lookup_len) {
1869 /* highly unprobable case */
1871 iotag = psli->last_iotag;
1872 if(++iotag < psli->iocbq_lookup_len) {
1873 psli->last_iotag = iotag;
1874 psli->iocbq_lookup[iotag] = iocbq;
1875 spin_unlock_irq(&phba->hbalock);
1876 iocbq->iotag = iotag;
1879 spin_unlock_irq(&phba->hbalock);
1882 if (psli->iocbq_lookup)
1883 memcpy(new_arr, old_arr,
1884 ((psli->last_iotag + 1) *
1885 sizeof (struct lpfc_iocbq *)));
1886 psli->iocbq_lookup = new_arr;
1887 psli->iocbq_lookup_len = new_len;
1888 psli->last_iotag = iotag;
1889 psli->iocbq_lookup[iotag] = iocbq;
1890 spin_unlock_irq(&phba->hbalock);
1891 iocbq->iotag = iotag;
1896 spin_unlock_irq(&phba->hbalock);
1898 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1899 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1906 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1907 * @phba: Pointer to HBA context object.
1908 * @pring: Pointer to driver SLI ring object.
1909 * @iocb: Pointer to iocb slot in the ring.
1910 * @nextiocb: Pointer to driver iocb object which need to be
1911 * posted to firmware.
1913 * This function is called to post a new iocb to the firmware. This
1914 * function copies the new iocb to ring iocb slot and updates the
1915 * ring pointers. It adds the new iocb to txcmplq if there is
1916 * a completion call back for this iocb else the function will free the
1917 * iocb object. The hbalock is asserted held in the code path calling
1921 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1922 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
1927 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
1930 if (pring->ringno == LPFC_ELS_RING) {
1931 lpfc_debugfs_slow_ring_trc(phba,
1932 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1933 *(((uint32_t *) &nextiocb->iocb) + 4),
1934 *(((uint32_t *) &nextiocb->iocb) + 6),
1935 *(((uint32_t *) &nextiocb->iocb) + 7));
1939 * Issue iocb command to adapter
1941 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
1943 pring->stats.iocb_cmd++;
1946 * If there is no completion routine to call, we can release the
1947 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1948 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1950 if (nextiocb->iocb_cmpl)
1951 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
1953 __lpfc_sli_release_iocbq(phba, nextiocb);
1956 * Let the HBA know what IOCB slot will be the next one the
1957 * driver will put a command into.
1959 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
1960 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
1964 * lpfc_sli_update_full_ring - Update the chip attention register
1965 * @phba: Pointer to HBA context object.
1966 * @pring: Pointer to driver SLI ring object.
1968 * The caller is not required to hold any lock for calling this function.
1969 * This function updates the chip attention bits for the ring to inform firmware
1970 * that there are pending work to be done for this ring and requests an
1971 * interrupt when there is space available in the ring. This function is
1972 * called when the driver is unable to post more iocbs to the ring due
1973 * to unavailability of space in the ring.
1976 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1978 int ringno = pring->ringno;
1980 pring->flag |= LPFC_CALL_RING_AVAILABLE;
1985 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1986 * The HBA will tell us when an IOCB entry is available.
1988 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
1989 readl(phba->CAregaddr); /* flush */
1991 pring->stats.iocb_cmd_full++;
1995 * lpfc_sli_update_ring - Update chip attention register
1996 * @phba: Pointer to HBA context object.
1997 * @pring: Pointer to driver SLI ring object.
1999 * This function updates the chip attention register bit for the
2000 * given ring to inform HBA that there is more work to be done
2001 * in this ring. The caller is not required to hold any lock.
2004 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2006 int ringno = pring->ringno;
2009 * Tell the HBA that there is work to do in this ring.
2011 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
2013 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
2014 readl(phba->CAregaddr); /* flush */
2019 * lpfc_sli_resume_iocb - Process iocbs in the txq
2020 * @phba: Pointer to HBA context object.
2021 * @pring: Pointer to driver SLI ring object.
2023 * This function is called with hbalock held to post pending iocbs
2024 * in the txq to the firmware. This function is called when driver
2025 * detects space available in the ring.
2028 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2031 struct lpfc_iocbq *nextiocb;
2033 lockdep_assert_held(&phba->hbalock);
2037 * (a) there is anything on the txq to send
2039 * (c) link attention events can be processed (fcp ring only)
2040 * (d) IOCB processing is not blocked by the outstanding mbox command.
2043 if (lpfc_is_link_up(phba) &&
2044 (!list_empty(&pring->txq)) &&
2045 (pring->ringno != LPFC_FCP_RING ||
2046 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
2048 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2049 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
2050 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2053 lpfc_sli_update_ring(phba, pring);
2055 lpfc_sli_update_full_ring(phba, pring);
2062 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
2063 * @phba: Pointer to HBA context object.
2064 * @hbqno: HBQ number.
2066 * This function is called with hbalock held to get the next
2067 * available slot for the given HBQ. If there is free slot
2068 * available for the HBQ it will return pointer to the next available
2069 * HBQ entry else it will return NULL.
2071 static struct lpfc_hbq_entry *
2072 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
2074 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2076 lockdep_assert_held(&phba->hbalock);
2078 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
2079 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
2080 hbqp->next_hbqPutIdx = 0;
2082 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
2083 uint32_t raw_index = phba->hbq_get[hbqno];
2084 uint32_t getidx = le32_to_cpu(raw_index);
2086 hbqp->local_hbqGetIdx = getidx;
2088 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
2089 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2090 "1802 HBQ %d: local_hbqGetIdx "
2091 "%u is > than hbqp->entry_count %u\n",
2092 hbqno, hbqp->local_hbqGetIdx,
2095 phba->link_state = LPFC_HBA_ERROR;
2099 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
2103 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
2108 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
2109 * @phba: Pointer to HBA context object.
2111 * This function is called with no lock held to free all the
2112 * hbq buffers while uninitializing the SLI interface. It also
2113 * frees the HBQ buffers returned by the firmware but not yet
2114 * processed by the upper layers.
2117 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
2119 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
2120 struct hbq_dmabuf *hbq_buf;
2121 unsigned long flags;
2124 hbq_count = lpfc_sli_hbq_count();
2125 /* Return all memory used by all HBQs */
2126 spin_lock_irqsave(&phba->hbalock, flags);
2127 for (i = 0; i < hbq_count; ++i) {
2128 list_for_each_entry_safe(dmabuf, next_dmabuf,
2129 &phba->hbqs[i].hbq_buffer_list, list) {
2130 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
2131 list_del(&hbq_buf->dbuf.list);
2132 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
2134 phba->hbqs[i].buffer_count = 0;
2137 /* Mark the HBQs not in use */
2138 phba->hbq_in_use = 0;
2139 spin_unlock_irqrestore(&phba->hbalock, flags);
2143 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
2144 * @phba: Pointer to HBA context object.
2145 * @hbqno: HBQ number.
2146 * @hbq_buf: Pointer to HBQ buffer.
2148 * This function is called with the hbalock held to post a
2149 * hbq buffer to the firmware. If the function finds an empty
2150 * slot in the HBQ, it will post the buffer. The function will return
2151 * pointer to the hbq entry if it successfully post the buffer
2152 * else it will return NULL.
2155 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
2156 struct hbq_dmabuf *hbq_buf)
2158 lockdep_assert_held(&phba->hbalock);
2159 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
2163 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
2164 * @phba: Pointer to HBA context object.
2165 * @hbqno: HBQ number.
2166 * @hbq_buf: Pointer to HBQ buffer.
2168 * This function is called with the hbalock held to post a hbq buffer to the
2169 * firmware. If the function finds an empty slot in the HBQ, it will post the
2170 * buffer and place it on the hbq_buffer_list. The function will return zero if
2171 * it successfully post the buffer else it will return an error.
2174 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
2175 struct hbq_dmabuf *hbq_buf)
2177 struct lpfc_hbq_entry *hbqe;
2178 dma_addr_t physaddr = hbq_buf->dbuf.phys;
2180 lockdep_assert_held(&phba->hbalock);
2181 /* Get next HBQ entry slot to use */
2182 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
2184 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2186 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
2187 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
2188 hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
2189 hbqe->bde.tus.f.bdeFlags = 0;
2190 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
2191 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
2193 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
2194 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
2196 readl(phba->hbq_put + hbqno);
2197 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
2204 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
2205 * @phba: Pointer to HBA context object.
2206 * @hbqno: HBQ number.
2207 * @hbq_buf: Pointer to HBQ buffer.
2209 * This function is called with the hbalock held to post an RQE to the SLI4
2210 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
2211 * the hbq_buffer_list and return zero, otherwise it will return an error.
2214 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
2215 struct hbq_dmabuf *hbq_buf)
2218 struct lpfc_rqe hrqe;
2219 struct lpfc_rqe drqe;
2220 struct lpfc_queue *hrq;
2221 struct lpfc_queue *drq;
2223 if (hbqno != LPFC_ELS_HBQ)
2225 hrq = phba->sli4_hba.hdr_rq;
2226 drq = phba->sli4_hba.dat_rq;
2228 lockdep_assert_held(&phba->hbalock);
2229 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
2230 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
2231 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
2232 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
2233 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
2236 hbq_buf->tag = (rc | (hbqno << 16));
2237 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
2241 /* HBQ for ELS and CT traffic. */
2242 static struct lpfc_hbq_init lpfc_els_hbq = {
2247 .ring_mask = (1 << LPFC_ELS_RING),
2254 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
2259 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
2260 * @phba: Pointer to HBA context object.
2261 * @hbqno: HBQ number.
2262 * @count: Number of HBQ buffers to be posted.
2264 * This function is called with no lock held to post more hbq buffers to the
2265 * given HBQ. The function returns the number of HBQ buffers successfully
2269 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
2271 uint32_t i, posted = 0;
2272 unsigned long flags;
2273 struct hbq_dmabuf *hbq_buffer;
2274 LIST_HEAD(hbq_buf_list);
2275 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
2278 if ((phba->hbqs[hbqno].buffer_count + count) >
2279 lpfc_hbq_defs[hbqno]->entry_count)
2280 count = lpfc_hbq_defs[hbqno]->entry_count -
2281 phba->hbqs[hbqno].buffer_count;
2284 /* Allocate HBQ entries */
2285 for (i = 0; i < count; i++) {
2286 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
2289 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
2291 /* Check whether HBQ is still in use */
2292 spin_lock_irqsave(&phba->hbalock, flags);
2293 if (!phba->hbq_in_use)
2295 while (!list_empty(&hbq_buf_list)) {
2296 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2298 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
2300 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
2301 phba->hbqs[hbqno].buffer_count++;
2304 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2306 spin_unlock_irqrestore(&phba->hbalock, flags);
2309 spin_unlock_irqrestore(&phba->hbalock, flags);
2310 while (!list_empty(&hbq_buf_list)) {
2311 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2313 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2319 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
2320 * @phba: Pointer to HBA context object.
2323 * This function posts more buffers to the HBQ. This function
2324 * is called with no lock held. The function returns the number of HBQ entries
2325 * successfully allocated.
2328 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
2330 if (phba->sli_rev == LPFC_SLI_REV4)
2333 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2334 lpfc_hbq_defs[qno]->add_count);
2338 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2339 * @phba: Pointer to HBA context object.
2340 * @qno: HBQ queue number.
2342 * This function is called from SLI initialization code path with
2343 * no lock held to post initial HBQ buffers to firmware. The
2344 * function returns the number of HBQ entries successfully allocated.
2347 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
2349 if (phba->sli_rev == LPFC_SLI_REV4)
2350 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2351 lpfc_hbq_defs[qno]->entry_count);
2353 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2354 lpfc_hbq_defs[qno]->init_count);
2358 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2360 * This function removes the first hbq buffer on an hbq list and returns a
2361 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2363 static struct hbq_dmabuf *
2364 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
2366 struct lpfc_dmabuf *d_buf;
2368 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
2371 return container_of(d_buf, struct hbq_dmabuf, dbuf);
2375 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2376 * @phba: Pointer to HBA context object.
2379 * This function removes the first RQ buffer on an RQ buffer list and returns a
2380 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2382 static struct rqb_dmabuf *
2383 lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
2385 struct lpfc_dmabuf *h_buf;
2386 struct lpfc_rqb *rqbp;
2389 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
2390 struct lpfc_dmabuf, list);
2393 rqbp->buffer_count--;
2394 return container_of(h_buf, struct rqb_dmabuf, hbuf);
2398 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2399 * @phba: Pointer to HBA context object.
2400 * @tag: Tag of the hbq buffer.
2402 * This function searches for the hbq buffer associated with the given tag in
2403 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2404 * otherwise it returns NULL.
2406 static struct hbq_dmabuf *
2407 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
2409 struct lpfc_dmabuf *d_buf;
2410 struct hbq_dmabuf *hbq_buf;
2414 if (hbqno >= LPFC_MAX_HBQS)
2417 spin_lock_irq(&phba->hbalock);
2418 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
2419 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2420 if (hbq_buf->tag == tag) {
2421 spin_unlock_irq(&phba->hbalock);
2425 spin_unlock_irq(&phba->hbalock);
2426 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2427 "1803 Bad hbq tag. Data: x%x x%x\n",
2428 tag, phba->hbqs[tag >> 16].buffer_count);
2433 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2434 * @phba: Pointer to HBA context object.
2435 * @hbq_buffer: Pointer to HBQ buffer.
2437 * This function is called with hbalock. This function gives back
2438 * the hbq buffer to firmware. If the HBQ does not have space to
2439 * post the buffer, it will free the buffer.
2442 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2447 hbqno = hbq_buffer->tag >> 16;
2448 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2449 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2454 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2455 * @mbxCommand: mailbox command code.
2457 * This function is called by the mailbox event handler function to verify
2458 * that the completed mailbox command is a legitimate mailbox command. If the
2459 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2460 * and the mailbox event handler will take the HBA offline.
2463 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2467 switch (mbxCommand) {
2471 case MBX_WRITE_VPARMS:
2472 case MBX_RUN_BIU_DIAG:
2475 case MBX_CONFIG_LINK:
2476 case MBX_CONFIG_RING:
2477 case MBX_RESET_RING:
2478 case MBX_READ_CONFIG:
2479 case MBX_READ_RCONFIG:
2480 case MBX_READ_SPARM:
2481 case MBX_READ_STATUS:
2485 case MBX_READ_LNK_STAT:
2487 case MBX_UNREG_LOGIN:
2489 case MBX_DUMP_MEMORY:
2490 case MBX_DUMP_CONTEXT:
2493 case MBX_UPDATE_CFG:
2495 case MBX_DEL_LD_ENTRY:
2496 case MBX_RUN_PROGRAM:
2498 case MBX_SET_VARIABLE:
2499 case MBX_UNREG_D_ID:
2500 case MBX_KILL_BOARD:
2501 case MBX_CONFIG_FARP:
2504 case MBX_RUN_BIU_DIAG64:
2505 case MBX_CONFIG_PORT:
2506 case MBX_READ_SPARM64:
2507 case MBX_READ_RPI64:
2508 case MBX_REG_LOGIN64:
2509 case MBX_READ_TOPOLOGY:
2512 case MBX_LOAD_EXP_ROM:
2513 case MBX_ASYNCEVT_ENABLE:
2517 case MBX_PORT_CAPABILITIES:
2518 case MBX_PORT_IOV_CONTROL:
2519 case MBX_SLI4_CONFIG:
2520 case MBX_SLI4_REQ_FTRS:
2522 case MBX_UNREG_FCFI:
2527 case MBX_RESUME_RPI:
2528 case MBX_READ_EVENT_LOG_STATUS:
2529 case MBX_READ_EVENT_LOG:
2530 case MBX_SECURITY_MGMT:
2532 case MBX_ACCESS_VDATA:
2543 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2544 * @phba: Pointer to HBA context object.
2545 * @pmboxq: Pointer to mailbox command.
2547 * This is completion handler function for mailbox commands issued from
2548 * lpfc_sli_issue_mbox_wait function. This function is called by the
2549 * mailbox event handler function with no lock held. This function
2550 * will wake up thread waiting on the wait queue pointed by context1
2554 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2556 unsigned long drvr_flag;
2557 struct completion *pmbox_done;
2560 * If pmbox_done is empty, the driver thread gave up waiting and
2561 * continued running.
2563 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2564 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2565 pmbox_done = (struct completion *)pmboxq->context3;
2567 complete(pmbox_done);
2568 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2573 __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2575 unsigned long iflags;
2577 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
2578 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
2579 spin_lock_irqsave(&ndlp->lock, iflags);
2580 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
2581 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
2582 spin_unlock_irqrestore(&ndlp->lock, iflags);
2584 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2588 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2589 * @phba: Pointer to HBA context object.
2590 * @pmb: Pointer to mailbox object.
2592 * This function is the default mailbox completion handler. It
2593 * frees the memory resources associated with the completed mailbox
2594 * command. If the completed command is a REG_LOGIN mailbox command,
2595 * this function will issue a UREG_LOGIN to re-claim the RPI.
2598 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2600 struct lpfc_vport *vport = pmb->vport;
2601 struct lpfc_dmabuf *mp;
2602 struct lpfc_nodelist *ndlp;
2603 struct Scsi_Host *shost;
2607 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
2610 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2615 * If a REG_LOGIN succeeded after node is destroyed or node
2616 * is in re-discovery driver need to cleanup the RPI.
2618 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2619 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2620 !pmb->u.mb.mbxStatus) {
2621 rpi = pmb->u.mb.un.varWords[0];
2622 vpi = pmb->u.mb.un.varRegLogin.vpi;
2623 if (phba->sli_rev == LPFC_SLI_REV4)
2624 vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
2625 lpfc_unreg_login(phba, vpi, rpi, pmb);
2627 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2628 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2629 if (rc != MBX_NOT_FINISHED)
2633 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2634 !(phba->pport->load_flag & FC_UNLOADING) &&
2635 !pmb->u.mb.mbxStatus) {
2636 shost = lpfc_shost_from_vport(vport);
2637 spin_lock_irq(shost->host_lock);
2638 vport->vpi_state |= LPFC_VPI_REGISTERED;
2639 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2640 spin_unlock_irq(shost->host_lock);
2643 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2644 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2646 pmb->ctx_buf = NULL;
2647 pmb->ctx_ndlp = NULL;
2650 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2651 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2653 /* Check to see if there are any deferred events to process */
2657 KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
2658 "1438 UNREG cmpl deferred mbox x%x "
2659 "on NPort x%x Data: x%x x%x %px x%x x%x\n",
2660 ndlp->nlp_rpi, ndlp->nlp_DID,
2661 ndlp->nlp_flag, ndlp->nlp_defer_did,
2662 ndlp, vport->load_flag, kref_read(&ndlp->kref));
2664 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2665 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
2666 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2667 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
2668 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2670 __lpfc_sli_rpi_release(vport, ndlp);
2673 /* The unreg_login mailbox is complete and had a
2674 * reference that has to be released. The PLOGI
2678 pmb->ctx_ndlp = NULL;
2682 /* Check security permission status on INIT_LINK mailbox command */
2683 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2684 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2685 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2686 "2860 SLI authentication is required "
2687 "for INIT_LINK but has not done yet\n");
2689 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2690 lpfc_sli4_mbox_cmd_free(phba, pmb);
2692 mempool_free(pmb, phba->mbox_mem_pool);
2695 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2696 * @phba: Pointer to HBA context object.
2697 * @pmb: Pointer to mailbox object.
2699 * This function is the unreg rpi mailbox completion handler. It
2700 * frees the memory resources associated with the completed mailbox
2701 * command. An additional reference is put on the ndlp to prevent
2702 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2703 * the unreg mailbox command completes, this routine puts the
2708 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2710 struct lpfc_vport *vport = pmb->vport;
2711 struct lpfc_nodelist *ndlp;
2713 ndlp = pmb->ctx_ndlp;
2714 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2715 if (phba->sli_rev == LPFC_SLI_REV4 &&
2716 (bf_get(lpfc_sli_intf_if_type,
2717 &phba->sli4_hba.sli_intf) >=
2718 LPFC_SLI_INTF_IF_TYPE_2)) {
2721 vport, KERN_INFO, LOG_MBOX | LOG_SLI,
2722 "0010 UNREG_LOGIN vpi:%x "
2723 "rpi:%x DID:%x defer x%x flg x%x "
2725 vport->vpi, ndlp->nlp_rpi,
2726 ndlp->nlp_DID, ndlp->nlp_defer_did,
2729 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2731 /* Check to see if there are any deferred
2734 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2735 (ndlp->nlp_defer_did !=
2736 NLP_EVT_NOTHING_PENDING)) {
2738 vport, KERN_INFO, LOG_DISCOVERY,
2739 "4111 UNREG cmpl deferred "
2741 "NPort x%x Data: x%x x%px\n",
2742 ndlp->nlp_rpi, ndlp->nlp_DID,
2743 ndlp->nlp_defer_did, ndlp);
2744 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2745 ndlp->nlp_defer_did =
2746 NLP_EVT_NOTHING_PENDING;
2747 lpfc_issue_els_plogi(
2748 vport, ndlp->nlp_DID, 0);
2750 __lpfc_sli_rpi_release(vport, ndlp);
2758 mempool_free(pmb, phba->mbox_mem_pool);
2762 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2763 * @phba: Pointer to HBA context object.
2765 * This function is called with no lock held. This function processes all
2766 * the completed mailbox commands and gives it to upper layers. The interrupt
2767 * service routine processes mailbox completion interrupt and adds completed
2768 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2769 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2770 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2771 * function returns the mailbox commands to the upper layer by calling the
2772 * completion handler function of each mailbox.
2775 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
2782 phba->sli.slistat.mbox_event++;
2784 /* Get all completed mailboxe buffers into the cmplq */
2785 spin_lock_irq(&phba->hbalock);
2786 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
2787 spin_unlock_irq(&phba->hbalock);
2789 /* Get a Mailbox buffer to setup mailbox commands for callback */
2791 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
2797 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
2799 lpfc_debugfs_disc_trc(pmb->vport,
2800 LPFC_DISC_TRC_MBOX_VPORT,
2801 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2802 (uint32_t)pmbox->mbxCommand,
2803 pmbox->un.varWords[0],
2804 pmbox->un.varWords[1]);
2807 lpfc_debugfs_disc_trc(phba->pport,
2809 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2810 (uint32_t)pmbox->mbxCommand,
2811 pmbox->un.varWords[0],
2812 pmbox->un.varWords[1]);
2817 * It is a fatal error if unknown mbox command completion.
2819 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
2821 /* Unknown mailbox command compl */
2822 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2823 "(%d):0323 Unknown Mailbox command "
2824 "x%x (x%x/x%x) Cmpl\n",
2825 pmb->vport ? pmb->vport->vpi :
2828 lpfc_sli_config_mbox_subsys_get(phba,
2830 lpfc_sli_config_mbox_opcode_get(phba,
2832 phba->link_state = LPFC_HBA_ERROR;
2833 phba->work_hs = HS_FFER3;
2834 lpfc_handle_eratt(phba);
2838 if (pmbox->mbxStatus) {
2839 phba->sli.slistat.mbox_stat_err++;
2840 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
2841 /* Mbox cmd cmpl error - RETRYing */
2842 lpfc_printf_log(phba, KERN_INFO,
2844 "(%d):0305 Mbox cmd cmpl "
2845 "error - RETRYing Data: x%x "
2846 "(x%x/x%x) x%x x%x x%x\n",
2847 pmb->vport ? pmb->vport->vpi :
2850 lpfc_sli_config_mbox_subsys_get(phba,
2852 lpfc_sli_config_mbox_opcode_get(phba,
2855 pmbox->un.varWords[0],
2856 pmb->vport ? pmb->vport->port_state :
2857 LPFC_VPORT_UNKNOWN);
2858 pmbox->mbxStatus = 0;
2859 pmbox->mbxOwner = OWN_HOST;
2860 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2861 if (rc != MBX_NOT_FINISHED)
2866 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2867 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2868 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
2869 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2871 pmb->vport ? pmb->vport->vpi : 0,
2873 lpfc_sli_config_mbox_subsys_get(phba, pmb),
2874 lpfc_sli_config_mbox_opcode_get(phba, pmb),
2876 *((uint32_t *) pmbox),
2877 pmbox->un.varWords[0],
2878 pmbox->un.varWords[1],
2879 pmbox->un.varWords[2],
2880 pmbox->un.varWords[3],
2881 pmbox->un.varWords[4],
2882 pmbox->un.varWords[5],
2883 pmbox->un.varWords[6],
2884 pmbox->un.varWords[7],
2885 pmbox->un.varWords[8],
2886 pmbox->un.varWords[9],
2887 pmbox->un.varWords[10]);
2890 pmb->mbox_cmpl(phba,pmb);
2896 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2897 * @phba: Pointer to HBA context object.
2898 * @pring: Pointer to driver SLI ring object.
2901 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2902 * is set in the tag the buffer is posted for a particular exchange,
2903 * the function will return the buffer without replacing the buffer.
2904 * If the buffer is for unsolicited ELS or CT traffic, this function
2905 * returns the buffer and also posts another buffer to the firmware.
2907 static struct lpfc_dmabuf *
2908 lpfc_sli_get_buff(struct lpfc_hba *phba,
2909 struct lpfc_sli_ring *pring,
2912 struct hbq_dmabuf *hbq_entry;
2914 if (tag & QUE_BUFTAG_BIT)
2915 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
2916 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
2919 return &hbq_entry->dbuf;
2923 * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer
2924 * containing a NVME LS request.
2925 * @phba: pointer to lpfc hba data structure.
2926 * @piocb: pointer to the iocbq struct representing the sequence starting
2929 * This routine initially validates the NVME LS, validates there is a login
2930 * with the port that sent the LS, and then calls the appropriate nvme host
2931 * or target LS request handler.
2934 lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
2936 struct lpfc_nodelist *ndlp;
2937 struct lpfc_dmabuf *d_buf;
2938 struct hbq_dmabuf *nvmebuf;
2939 struct fc_frame_header *fc_hdr;
2940 struct lpfc_async_xchg_ctx *axchg = NULL;
2941 char *failwhy = NULL;
2942 uint32_t oxid, sid, did, fctl, size;
2945 d_buf = piocb->context2;
2947 nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2948 fc_hdr = nvmebuf->hbuf.virt;
2949 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
2950 sid = sli4_sid_from_fc_hdr(fc_hdr);
2951 did = sli4_did_from_fc_hdr(fc_hdr);
2952 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
2953 fc_hdr->fh_f_ctl[1] << 8 |
2954 fc_hdr->fh_f_ctl[2]);
2955 size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
2957 lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n",
2960 if (phba->pport->load_flag & FC_UNLOADING) {
2961 failwhy = "Driver Unloading";
2962 } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
2963 failwhy = "NVME FC4 Disabled";
2964 } else if (!phba->nvmet_support && !phba->pport->localport) {
2965 failwhy = "No Localport";
2966 } else if (phba->nvmet_support && !phba->targetport) {
2967 failwhy = "No Targetport";
2968 } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) {
2969 failwhy = "Bad NVME LS R_CTL";
2970 } else if (unlikely((fctl & 0x00FF0000) !=
2971 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) {
2972 failwhy = "Bad NVME LS F_CTL";
2974 axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC);
2976 failwhy = "No CTX memory";
2979 if (unlikely(failwhy)) {
2980 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2981 "6154 Drop NVME LS: SID %06X OXID x%X: %s\n",
2982 sid, oxid, failwhy);
2986 /* validate the source of the LS is logged in */
2987 ndlp = lpfc_findnode_did(phba->pport, sid);
2989 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2990 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
2991 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
2992 "6216 NVME Unsol rcv: No ndlp: "
2993 "NPort_ID x%x oxid x%x\n",
3004 axchg->state = LPFC_NVME_STE_LS_RCV;
3005 axchg->entry_cnt = 1;
3006 axchg->rqb_buffer = (void *)nvmebuf;
3007 axchg->hdwq = &phba->sli4_hba.hdwq[0];
3008 axchg->payload = nvmebuf->dbuf.virt;
3009 INIT_LIST_HEAD(&axchg->list);
3011 if (phba->nvmet_support) {
3012 ret = lpfc_nvmet_handle_lsreq(phba, axchg);
3013 spin_lock_irq(&ndlp->lock);
3014 if (!ret && !(ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH)) {
3015 ndlp->fc4_xpt_flags |= NLP_XPT_HAS_HH;
3016 spin_unlock_irq(&ndlp->lock);
3018 /* This reference is a single occurrence to hold the
3019 * node valid until the nvmet transport calls
3022 if (!lpfc_nlp_get(ndlp))
3025 lpfc_printf_log(phba, KERN_ERR, LOG_NODE,
3026 "6206 NVMET unsol ls_req ndlp %p "
3027 "DID x%x xflags x%x refcnt %d\n",
3028 ndlp, ndlp->nlp_DID,
3029 ndlp->fc4_xpt_flags,
3030 kref_read(&ndlp->kref));
3032 spin_unlock_irq(&ndlp->lock);
3035 ret = lpfc_nvme_handle_lsreq(phba, axchg);
3038 /* if zero, LS was successfully handled. If non-zero, LS not handled */
3043 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3044 "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X "
3045 "NVMe%s handler failed %d\n",
3047 (phba->nvmet_support) ? "T" : "I", ret);
3049 /* recycle receive buffer */
3050 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
3052 /* If start of new exchange, abort it */
3053 if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX)))
3054 ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
3061 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
3062 * @phba: Pointer to HBA context object.
3063 * @pring: Pointer to driver SLI ring object.
3064 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
3065 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
3066 * @fch_type: the type for the first frame of the sequence.
3068 * This function is called with no lock held. This function uses the r_ctl and
3069 * type of the received sequence to find the correct callback function to call
3070 * to process the sequence.
3073 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3074 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
3081 lpfc_nvme_unsol_ls_handler(phba, saveq);
3087 /* unSolicited Responses */
3088 if (pring->prt[0].profile) {
3089 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
3090 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
3094 /* We must search, based on rctl / type
3095 for the right routine */
3096 for (i = 0; i < pring->num_mask; i++) {
3097 if ((pring->prt[i].rctl == fch_r_ctl) &&
3098 (pring->prt[i].type == fch_type)) {
3099 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
3100 (pring->prt[i].lpfc_sli_rcv_unsol_event)
3101 (phba, pring, saveq);
3109 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
3110 * @phba: Pointer to HBA context object.
3111 * @pring: Pointer to driver SLI ring object.
3112 * @saveq: Pointer to the unsolicited iocb.
3114 * This function is called with no lock held by the ring event handler
3115 * when there is an unsolicited iocb posted to the response ring by the
3116 * firmware. This function gets the buffer associated with the iocbs
3117 * and calls the event handler for the ring. This function handles both
3118 * qring buffers and hbq buffers.
3119 * When the function returns 1 the caller can free the iocb object otherwise
3120 * upper layer functions will free the iocb objects.
3123 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3124 struct lpfc_iocbq *saveq)
3128 uint32_t Rctl, Type;
3129 struct lpfc_iocbq *iocbq;
3130 struct lpfc_dmabuf *dmzbuf;
3132 irsp = &(saveq->iocb);
3134 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
3135 if (pring->lpfc_sli_rcv_async_status)
3136 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
3138 lpfc_printf_log(phba,
3141 "0316 Ring %d handler: unexpected "
3142 "ASYNC_STATUS iocb received evt_code "
3145 irsp->un.asyncstat.evt_code);
3149 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
3150 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
3151 if (irsp->ulpBdeCount > 0) {
3152 dmzbuf = lpfc_sli_get_buff(phba, pring,
3153 irsp->un.ulpWord[3]);
3154 lpfc_in_buf_free(phba, dmzbuf);
3157 if (irsp->ulpBdeCount > 1) {
3158 dmzbuf = lpfc_sli_get_buff(phba, pring,
3159 irsp->unsli3.sli3Words[3]);
3160 lpfc_in_buf_free(phba, dmzbuf);
3163 if (irsp->ulpBdeCount > 2) {
3164 dmzbuf = lpfc_sli_get_buff(phba, pring,
3165 irsp->unsli3.sli3Words[7]);
3166 lpfc_in_buf_free(phba, dmzbuf);
3172 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3173 if (irsp->ulpBdeCount != 0) {
3174 saveq->context2 = lpfc_sli_get_buff(phba, pring,
3175 irsp->un.ulpWord[3]);
3176 if (!saveq->context2)
3177 lpfc_printf_log(phba,
3180 "0341 Ring %d Cannot find buffer for "
3181 "an unsolicited iocb. tag 0x%x\n",
3183 irsp->un.ulpWord[3]);
3185 if (irsp->ulpBdeCount == 2) {
3186 saveq->context3 = lpfc_sli_get_buff(phba, pring,
3187 irsp->unsli3.sli3Words[7]);
3188 if (!saveq->context3)
3189 lpfc_printf_log(phba,
3192 "0342 Ring %d Cannot find buffer for an"
3193 " unsolicited iocb. tag 0x%x\n",
3195 irsp->unsli3.sli3Words[7]);
3197 list_for_each_entry(iocbq, &saveq->list, list) {
3198 irsp = &(iocbq->iocb);
3199 if (irsp->ulpBdeCount != 0) {
3200 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
3201 irsp->un.ulpWord[3]);
3202 if (!iocbq->context2)
3203 lpfc_printf_log(phba,
3206 "0343 Ring %d Cannot find "
3207 "buffer for an unsolicited iocb"
3208 ". tag 0x%x\n", pring->ringno,
3209 irsp->un.ulpWord[3]);
3211 if (irsp->ulpBdeCount == 2) {
3212 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
3213 irsp->unsli3.sli3Words[7]);
3214 if (!iocbq->context3)
3215 lpfc_printf_log(phba,
3218 "0344 Ring %d Cannot find "
3219 "buffer for an unsolicited "
3222 irsp->unsli3.sli3Words[7]);
3226 if (irsp->ulpBdeCount != 0 &&
3227 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
3228 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
3231 /* search continue save q for same XRI */
3232 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
3233 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
3234 saveq->iocb.unsli3.rcvsli3.ox_id) {
3235 list_add_tail(&saveq->list, &iocbq->list);
3241 list_add_tail(&saveq->clist,
3242 &pring->iocb_continue_saveq);
3243 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
3244 list_del_init(&iocbq->clist);
3246 irsp = &(saveq->iocb);
3250 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
3251 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
3252 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
3253 Rctl = FC_RCTL_ELS_REQ;
3256 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
3257 Rctl = w5p->hcsw.Rctl;
3258 Type = w5p->hcsw.Type;
3260 /* Firmware Workaround */
3261 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
3262 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
3263 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
3264 Rctl = FC_RCTL_ELS_REQ;
3266 w5p->hcsw.Rctl = Rctl;
3267 w5p->hcsw.Type = Type;
3271 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
3272 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3273 "0313 Ring %d handler: unexpected Rctl x%x "
3274 "Type x%x received\n",
3275 pring->ringno, Rctl, Type);
3281 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
3282 * @phba: Pointer to HBA context object.
3283 * @pring: Pointer to driver SLI ring object.
3284 * @prspiocb: Pointer to response iocb object.
3286 * This function looks up the iocb_lookup table to get the command iocb
3287 * corresponding to the given response iocb using the iotag of the
3288 * response iocb. The driver calls this function with the hbalock held
3289 * for SLI3 ports or the ring lock held for SLI4 ports.
3290 * This function returns the command iocb object if it finds the command
3291 * iocb else returns NULL.
3293 static struct lpfc_iocbq *
3294 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
3295 struct lpfc_sli_ring *pring,
3296 struct lpfc_iocbq *prspiocb)
3298 struct lpfc_iocbq *cmd_iocb = NULL;
3300 spinlock_t *temp_lock = NULL;
3301 unsigned long iflag = 0;
3303 if (phba->sli_rev == LPFC_SLI_REV4)
3304 temp_lock = &pring->ring_lock;
3306 temp_lock = &phba->hbalock;
3308 spin_lock_irqsave(temp_lock, iflag);
3309 iotag = prspiocb->iocb.ulpIoTag;
3311 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3312 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3313 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3314 /* remove from txcmpl queue list */
3315 list_del_init(&cmd_iocb->list);
3316 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3317 pring->txcmplq_cnt--;
3318 spin_unlock_irqrestore(temp_lock, iflag);
3323 spin_unlock_irqrestore(temp_lock, iflag);
3324 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3325 "0317 iotag x%x is out of "
3326 "range: max iotag x%x wd0 x%x\n",
3327 iotag, phba->sli.last_iotag,
3328 *(((uint32_t *) &prspiocb->iocb) + 7));
3333 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
3334 * @phba: Pointer to HBA context object.
3335 * @pring: Pointer to driver SLI ring object.
3338 * This function looks up the iocb_lookup table to get the command iocb
3339 * corresponding to the given iotag. The driver calls this function with
3340 * the ring lock held because this function is an SLI4 port only helper.
3341 * This function returns the command iocb object if it finds the command
3342 * iocb else returns NULL.
3344 static struct lpfc_iocbq *
3345 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
3346 struct lpfc_sli_ring *pring, uint16_t iotag)
3348 struct lpfc_iocbq *cmd_iocb = NULL;
3349 spinlock_t *temp_lock = NULL;
3350 unsigned long iflag = 0;
3352 if (phba->sli_rev == LPFC_SLI_REV4)
3353 temp_lock = &pring->ring_lock;
3355 temp_lock = &phba->hbalock;
3357 spin_lock_irqsave(temp_lock, iflag);
3358 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3359 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3360 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3361 /* remove from txcmpl queue list */
3362 list_del_init(&cmd_iocb->list);
3363 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3364 pring->txcmplq_cnt--;
3365 spin_unlock_irqrestore(temp_lock, iflag);
3370 spin_unlock_irqrestore(temp_lock, iflag);
3371 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3372 "0372 iotag x%x lookup error: max iotag (x%x) "
3374 iotag, phba->sli.last_iotag,
3375 cmd_iocb ? cmd_iocb->iocb_flag : 0xffff);
3380 * lpfc_sli_process_sol_iocb - process solicited iocb completion
3381 * @phba: Pointer to HBA context object.
3382 * @pring: Pointer to driver SLI ring object.
3383 * @saveq: Pointer to the response iocb to be processed.
3385 * This function is called by the ring event handler for non-fcp
3386 * rings when there is a new response iocb in the response ring.
3387 * The caller is not required to hold any locks. This function
3388 * gets the command iocb associated with the response iocb and
3389 * calls the completion handler for the command iocb. If there
3390 * is no completion handler, the function will free the resources
3391 * associated with command iocb. If the response iocb is for
3392 * an already aborted command iocb, the status of the completion
3393 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
3394 * This function always returns 1.
3397 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3398 struct lpfc_iocbq *saveq)
3400 struct lpfc_iocbq *cmdiocbp;
3402 unsigned long iflag;
3404 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
3406 if (cmdiocbp->iocb_cmpl) {
3408 * If an ELS command failed send an event to mgmt
3411 if (saveq->iocb.ulpStatus &&
3412 (pring->ringno == LPFC_ELS_RING) &&
3413 (cmdiocbp->iocb.ulpCommand ==
3414 CMD_ELS_REQUEST64_CR))
3415 lpfc_send_els_failure_event(phba,
3419 * Post all ELS completions to the worker thread.
3420 * All other are passed to the completion callback.
3422 if (pring->ringno == LPFC_ELS_RING) {
3423 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3424 (cmdiocbp->iocb_flag &
3425 LPFC_DRIVER_ABORTED)) {
3426 spin_lock_irqsave(&phba->hbalock,
3428 cmdiocbp->iocb_flag &=
3429 ~LPFC_DRIVER_ABORTED;
3430 spin_unlock_irqrestore(&phba->hbalock,
3432 saveq->iocb.ulpStatus =
3433 IOSTAT_LOCAL_REJECT;
3434 saveq->iocb.un.ulpWord[4] =
3437 /* Firmware could still be in progress
3438 * of DMAing payload, so don't free data
3439 * buffer till after a hbeat.
3441 spin_lock_irqsave(&phba->hbalock,
3443 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
3444 spin_unlock_irqrestore(&phba->hbalock,
3447 if (phba->sli_rev == LPFC_SLI_REV4) {
3448 if (saveq->iocb_flag &
3449 LPFC_EXCHANGE_BUSY) {
3450 /* Set cmdiocb flag for the
3451 * exchange busy so sgl (xri)
3452 * will not be released until
3453 * the abort xri is received
3457 &phba->hbalock, iflag);
3458 cmdiocbp->iocb_flag |=
3460 spin_unlock_irqrestore(
3461 &phba->hbalock, iflag);
3463 if (cmdiocbp->iocb_flag &
3464 LPFC_DRIVER_ABORTED) {
3466 * Clear LPFC_DRIVER_ABORTED
3467 * bit in case it was driver
3471 &phba->hbalock, iflag);
3472 cmdiocbp->iocb_flag &=
3473 ~LPFC_DRIVER_ABORTED;
3474 spin_unlock_irqrestore(
3475 &phba->hbalock, iflag);
3476 cmdiocbp->iocb.ulpStatus =
3477 IOSTAT_LOCAL_REJECT;
3478 cmdiocbp->iocb.un.ulpWord[4] =
3479 IOERR_ABORT_REQUESTED;
3481 * For SLI4, irsiocb contains
3482 * NO_XRI in sli_xritag, it
3483 * shall not affect releasing
3484 * sgl (xri) process.
3486 saveq->iocb.ulpStatus =
3487 IOSTAT_LOCAL_REJECT;
3488 saveq->iocb.un.ulpWord[4] =
3491 &phba->hbalock, iflag);
3493 LPFC_DELAY_MEM_FREE;
3494 spin_unlock_irqrestore(
3495 &phba->hbalock, iflag);
3499 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
3501 lpfc_sli_release_iocbq(phba, cmdiocbp);
3504 * Unknown initiating command based on the response iotag.
3505 * This could be the case on the ELS ring because of
3508 if (pring->ringno != LPFC_ELS_RING) {
3510 * Ring <ringno> handler: unexpected completion IoTag
3513 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3514 "0322 Ring %d handler: "
3515 "unexpected completion IoTag x%x "
3516 "Data: x%x x%x x%x x%x\n",
3518 saveq->iocb.ulpIoTag,
3519 saveq->iocb.ulpStatus,
3520 saveq->iocb.un.ulpWord[4],
3521 saveq->iocb.ulpCommand,
3522 saveq->iocb.ulpContext);
3530 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
3531 * @phba: Pointer to HBA context object.
3532 * @pring: Pointer to driver SLI ring object.
3534 * This function is called from the iocb ring event handlers when
3535 * put pointer is ahead of the get pointer for a ring. This function signal
3536 * an error attention condition to the worker thread and the worker
3537 * thread will transition the HBA to offline state.
3540 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3542 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3544 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3545 * rsp ring <portRspMax>
3547 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3548 "0312 Ring %d handler: portRspPut %d "
3549 "is bigger than rsp ring %d\n",
3550 pring->ringno, le32_to_cpu(pgp->rspPutInx),
3551 pring->sli.sli3.numRiocb);
3553 phba->link_state = LPFC_HBA_ERROR;
3556 * All error attention handlers are posted to
3559 phba->work_ha |= HA_ERATT;
3560 phba->work_hs = HS_FFER3;
3562 lpfc_worker_wake_up(phba);
3568 * lpfc_poll_eratt - Error attention polling timer timeout handler
3569 * @t: Context to fetch pointer to address of HBA context object from.
3571 * This function is invoked by the Error Attention polling timer when the
3572 * timer times out. It will check the SLI Error Attention register for
3573 * possible attention events. If so, it will post an Error Attention event
3574 * and wake up worker thread to process it. Otherwise, it will set up the
3575 * Error Attention polling timer for the next poll.
3577 void lpfc_poll_eratt(struct timer_list *t)
3579 struct lpfc_hba *phba;
3581 uint64_t sli_intr, cnt;
3583 phba = from_timer(phba, t, eratt_poll);
3585 /* Here we will also keep track of interrupts per sec of the hba */
3586 sli_intr = phba->sli.slistat.sli_intr;
3588 if (phba->sli.slistat.sli_prev_intr > sli_intr)
3589 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
3592 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
3594 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3595 do_div(cnt, phba->eratt_poll_interval);
3596 phba->sli.slistat.sli_ips = cnt;
3598 phba->sli.slistat.sli_prev_intr = sli_intr;
3600 /* Check chip HA register for error event */
3601 eratt = lpfc_sli_check_eratt(phba);
3604 /* Tell the worker thread there is work to do */
3605 lpfc_worker_wake_up(phba);
3607 /* Restart the timer for next eratt poll */
3608 mod_timer(&phba->eratt_poll,
3610 msecs_to_jiffies(1000 * phba->eratt_poll_interval));
3616 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3617 * @phba: Pointer to HBA context object.
3618 * @pring: Pointer to driver SLI ring object.
3619 * @mask: Host attention register mask for this ring.
3621 * This function is called from the interrupt context when there is a ring
3622 * event for the fcp ring. The caller does not hold any lock.
3623 * The function processes each response iocb in the response ring until it
3624 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3625 * LE bit set. The function will call the completion handler of the command iocb
3626 * if the response iocb indicates a completion for a command iocb or it is
3627 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3628 * function if this is an unsolicited iocb.
3629 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3630 * to check it explicitly.
3633 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
3634 struct lpfc_sli_ring *pring, uint32_t mask)
3636 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3637 IOCB_t *irsp = NULL;
3638 IOCB_t *entry = NULL;
3639 struct lpfc_iocbq *cmdiocbq = NULL;
3640 struct lpfc_iocbq rspiocbq;
3642 uint32_t portRspPut, portRspMax;
3644 lpfc_iocb_type type;
3645 unsigned long iflag;
3646 uint32_t rsp_cmpl = 0;
3648 spin_lock_irqsave(&phba->hbalock, iflag);
3649 pring->stats.iocb_event++;
3652 * The next available response entry should never exceed the maximum
3653 * entries. If it does, treat it as an adapter hardware error.
3655 portRspMax = pring->sli.sli3.numRiocb;
3656 portRspPut = le32_to_cpu(pgp->rspPutInx);
3657 if (unlikely(portRspPut >= portRspMax)) {
3658 lpfc_sli_rsp_pointers_error(phba, pring);
3659 spin_unlock_irqrestore(&phba->hbalock, iflag);
3662 if (phba->fcp_ring_in_use) {
3663 spin_unlock_irqrestore(&phba->hbalock, iflag);
3666 phba->fcp_ring_in_use = 1;
3669 while (pring->sli.sli3.rspidx != portRspPut) {
3671 * Fetch an entry off the ring and copy it into a local data
3672 * structure. The copy involves a byte-swap since the
3673 * network byte order and pci byte orders are different.
3675 entry = lpfc_resp_iocb(phba, pring);
3676 phba->last_completion_time = jiffies;
3678 if (++pring->sli.sli3.rspidx >= portRspMax)
3679 pring->sli.sli3.rspidx = 0;
3681 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
3682 (uint32_t *) &rspiocbq.iocb,
3683 phba->iocb_rsp_size);
3684 INIT_LIST_HEAD(&(rspiocbq.list));
3685 irsp = &rspiocbq.iocb;
3687 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
3688 pring->stats.iocb_rsp++;
3691 if (unlikely(irsp->ulpStatus)) {
3693 * If resource errors reported from HBA, reduce
3694 * queuedepths of the SCSI device.
3696 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3697 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3698 IOERR_NO_RESOURCES)) {
3699 spin_unlock_irqrestore(&phba->hbalock, iflag);
3700 phba->lpfc_rampdown_queue_depth(phba);
3701 spin_lock_irqsave(&phba->hbalock, iflag);
3704 /* Rsp ring <ringno> error: IOCB */
3705 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3706 "0336 Rsp Ring %d error: IOCB Data: "
3707 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3709 irsp->un.ulpWord[0],
3710 irsp->un.ulpWord[1],
3711 irsp->un.ulpWord[2],
3712 irsp->un.ulpWord[3],
3713 irsp->un.ulpWord[4],
3714 irsp->un.ulpWord[5],
3715 *(uint32_t *)&irsp->un1,
3716 *((uint32_t *)&irsp->un1 + 1));
3720 case LPFC_ABORT_IOCB:
3723 * Idle exchange closed via ABTS from port. No iocb
3724 * resources need to be recovered.
3726 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
3727 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3728 "0333 IOCB cmd 0x%x"
3729 " processed. Skipping"
3735 spin_unlock_irqrestore(&phba->hbalock, iflag);
3736 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3738 spin_lock_irqsave(&phba->hbalock, iflag);
3739 if (unlikely(!cmdiocbq))
3741 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3742 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3743 if (cmdiocbq->iocb_cmpl) {
3744 spin_unlock_irqrestore(&phba->hbalock, iflag);
3745 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
3747 spin_lock_irqsave(&phba->hbalock, iflag);
3750 case LPFC_UNSOL_IOCB:
3751 spin_unlock_irqrestore(&phba->hbalock, iflag);
3752 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
3753 spin_lock_irqsave(&phba->hbalock, iflag);
3756 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3757 char adaptermsg[LPFC_MAX_ADPTMSG];
3758 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3759 memcpy(&adaptermsg[0], (uint8_t *) irsp,
3761 dev_warn(&((phba->pcidev)->dev),
3763 phba->brd_no, adaptermsg);
3765 /* Unknown IOCB command */
3766 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3767 "0334 Unknown IOCB command "
3768 "Data: x%x, x%x x%x x%x x%x\n",
3769 type, irsp->ulpCommand,
3778 * The response IOCB has been processed. Update the ring
3779 * pointer in SLIM. If the port response put pointer has not
3780 * been updated, sync the pgp->rspPutInx and fetch the new port
3781 * response put pointer.
3783 writel(pring->sli.sli3.rspidx,
3784 &phba->host_gp[pring->ringno].rspGetInx);
3786 if (pring->sli.sli3.rspidx == portRspPut)
3787 portRspPut = le32_to_cpu(pgp->rspPutInx);
3790 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
3791 pring->stats.iocb_rsp_full++;
3792 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
3793 writel(status, phba->CAregaddr);
3794 readl(phba->CAregaddr);
3796 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
3797 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
3798 pring->stats.iocb_cmd_empty++;
3800 /* Force update of the local copy of cmdGetInx */
3801 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
3802 lpfc_sli_resume_iocb(phba, pring);
3804 if ((pring->lpfc_sli_cmd_available))
3805 (pring->lpfc_sli_cmd_available) (phba, pring);
3809 phba->fcp_ring_in_use = 0;
3810 spin_unlock_irqrestore(&phba->hbalock, iflag);
3815 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3816 * @phba: Pointer to HBA context object.
3817 * @pring: Pointer to driver SLI ring object.
3818 * @rspiocbp: Pointer to driver response IOCB object.
3820 * This function is called from the worker thread when there is a slow-path
3821 * response IOCB to process. This function chains all the response iocbs until
3822 * seeing the iocb with the LE bit set. The function will call
3823 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3824 * completion of a command iocb. The function will call the
3825 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3826 * The function frees the resources or calls the completion handler if this
3827 * iocb is an abort completion. The function returns NULL when the response
3828 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3829 * this function shall chain the iocb on to the iocb_continueq and return the
3830 * response iocb passed in.
3832 static struct lpfc_iocbq *
3833 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3834 struct lpfc_iocbq *rspiocbp)
3836 struct lpfc_iocbq *saveq;
3837 struct lpfc_iocbq *cmdiocbp;
3838 struct lpfc_iocbq *next_iocb;
3839 IOCB_t *irsp = NULL;
3840 uint32_t free_saveq;
3841 uint8_t iocb_cmd_type;
3842 lpfc_iocb_type type;
3843 unsigned long iflag;
3846 spin_lock_irqsave(&phba->hbalock, iflag);
3847 /* First add the response iocb to the countinueq list */
3848 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
3849 pring->iocb_continueq_cnt++;
3851 /* Now, determine whether the list is completed for processing */
3852 irsp = &rspiocbp->iocb;
3855 * By default, the driver expects to free all resources
3856 * associated with this iocb completion.
3859 saveq = list_get_first(&pring->iocb_continueq,
3860 struct lpfc_iocbq, list);
3861 irsp = &(saveq->iocb);
3862 list_del_init(&pring->iocb_continueq);
3863 pring->iocb_continueq_cnt = 0;
3865 pring->stats.iocb_rsp++;
3868 * If resource errors reported from HBA, reduce
3869 * queuedepths of the SCSI device.
3871 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3872 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3873 IOERR_NO_RESOURCES)) {
3874 spin_unlock_irqrestore(&phba->hbalock, iflag);
3875 phba->lpfc_rampdown_queue_depth(phba);
3876 spin_lock_irqsave(&phba->hbalock, iflag);
3879 if (irsp->ulpStatus) {
3880 /* Rsp ring <ringno> error: IOCB */
3881 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3882 "0328 Rsp Ring %d error: "
3887 "x%x x%x x%x x%x\n",
3889 irsp->un.ulpWord[0],
3890 irsp->un.ulpWord[1],
3891 irsp->un.ulpWord[2],
3892 irsp->un.ulpWord[3],
3893 irsp->un.ulpWord[4],
3894 irsp->un.ulpWord[5],
3895 *(((uint32_t *) irsp) + 6),
3896 *(((uint32_t *) irsp) + 7),
3897 *(((uint32_t *) irsp) + 8),
3898 *(((uint32_t *) irsp) + 9),
3899 *(((uint32_t *) irsp) + 10),
3900 *(((uint32_t *) irsp) + 11),
3901 *(((uint32_t *) irsp) + 12),
3902 *(((uint32_t *) irsp) + 13),
3903 *(((uint32_t *) irsp) + 14),
3904 *(((uint32_t *) irsp) + 15));
3908 * Fetch the IOCB command type and call the correct completion
3909 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3910 * get freed back to the lpfc_iocb_list by the discovery
3913 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
3914 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
3917 spin_unlock_irqrestore(&phba->hbalock, iflag);
3918 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
3919 spin_lock_irqsave(&phba->hbalock, iflag);
3922 case LPFC_UNSOL_IOCB:
3923 spin_unlock_irqrestore(&phba->hbalock, iflag);
3924 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
3925 spin_lock_irqsave(&phba->hbalock, iflag);
3930 case LPFC_ABORT_IOCB:
3932 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) {
3933 spin_unlock_irqrestore(&phba->hbalock, iflag);
3934 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
3936 spin_lock_irqsave(&phba->hbalock, iflag);
3939 /* Call the specified completion routine */
3940 if (cmdiocbp->iocb_cmpl) {
3941 spin_unlock_irqrestore(&phba->hbalock,
3943 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
3945 spin_lock_irqsave(&phba->hbalock,
3948 __lpfc_sli_release_iocbq(phba,
3953 case LPFC_UNKNOWN_IOCB:
3954 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
3955 char adaptermsg[LPFC_MAX_ADPTMSG];
3956 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
3957 memcpy(&adaptermsg[0], (uint8_t *)irsp,
3959 dev_warn(&((phba->pcidev)->dev),
3961 phba->brd_no, adaptermsg);
3963 /* Unknown IOCB command */
3964 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3965 "0335 Unknown IOCB "
3966 "command Data: x%x "
3977 list_for_each_entry_safe(rspiocbp, next_iocb,
3978 &saveq->list, list) {
3979 list_del_init(&rspiocbp->list);
3980 __lpfc_sli_release_iocbq(phba, rspiocbp);
3982 __lpfc_sli_release_iocbq(phba, saveq);
3986 spin_unlock_irqrestore(&phba->hbalock, iflag);
3991 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3992 * @phba: Pointer to HBA context object.
3993 * @pring: Pointer to driver SLI ring object.
3994 * @mask: Host attention register mask for this ring.
3996 * This routine wraps the actual slow_ring event process routine from the
3997 * API jump table function pointer from the lpfc_hba struct.
4000 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
4001 struct lpfc_sli_ring *pring, uint32_t mask)
4003 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
4007 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
4008 * @phba: Pointer to HBA context object.
4009 * @pring: Pointer to driver SLI ring object.
4010 * @mask: Host attention register mask for this ring.
4012 * This function is called from the worker thread when there is a ring event
4013 * for non-fcp rings. The caller does not hold any lock. The function will
4014 * remove each response iocb in the response ring and calls the handle
4015 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4018 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
4019 struct lpfc_sli_ring *pring, uint32_t mask)
4021 struct lpfc_pgp *pgp;
4023 IOCB_t *irsp = NULL;
4024 struct lpfc_iocbq *rspiocbp = NULL;
4025 uint32_t portRspPut, portRspMax;
4026 unsigned long iflag;
4029 pgp = &phba->port_gp[pring->ringno];
4030 spin_lock_irqsave(&phba->hbalock, iflag);
4031 pring->stats.iocb_event++;
4034 * The next available response entry should never exceed the maximum
4035 * entries. If it does, treat it as an adapter hardware error.
4037 portRspMax = pring->sli.sli3.numRiocb;
4038 portRspPut = le32_to_cpu(pgp->rspPutInx);
4039 if (portRspPut >= portRspMax) {
4041 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
4042 * rsp ring <portRspMax>
4044 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4045 "0303 Ring %d handler: portRspPut %d "
4046 "is bigger than rsp ring %d\n",
4047 pring->ringno, portRspPut, portRspMax);
4049 phba->link_state = LPFC_HBA_ERROR;
4050 spin_unlock_irqrestore(&phba->hbalock, iflag);
4052 phba->work_hs = HS_FFER3;
4053 lpfc_handle_eratt(phba);
4059 while (pring->sli.sli3.rspidx != portRspPut) {
4061 * Build a completion list and call the appropriate handler.
4062 * The process is to get the next available response iocb, get
4063 * a free iocb from the list, copy the response data into the
4064 * free iocb, insert to the continuation list, and update the
4065 * next response index to slim. This process makes response
4066 * iocb's in the ring available to DMA as fast as possible but
4067 * pays a penalty for a copy operation. Since the iocb is
4068 * only 32 bytes, this penalty is considered small relative to
4069 * the PCI reads for register values and a slim write. When
4070 * the ulpLe field is set, the entire Command has been
4073 entry = lpfc_resp_iocb(phba, pring);
4075 phba->last_completion_time = jiffies;
4076 rspiocbp = __lpfc_sli_get_iocbq(phba);
4077 if (rspiocbp == NULL) {
4078 printk(KERN_ERR "%s: out of buffers! Failing "
4079 "completion.\n", __func__);
4083 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
4084 phba->iocb_rsp_size);
4085 irsp = &rspiocbp->iocb;
4087 if (++pring->sli.sli3.rspidx >= portRspMax)
4088 pring->sli.sli3.rspidx = 0;
4090 if (pring->ringno == LPFC_ELS_RING) {
4091 lpfc_debugfs_slow_ring_trc(phba,
4092 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
4093 *(((uint32_t *) irsp) + 4),
4094 *(((uint32_t *) irsp) + 6),
4095 *(((uint32_t *) irsp) + 7));
4098 writel(pring->sli.sli3.rspidx,
4099 &phba->host_gp[pring->ringno].rspGetInx);
4101 spin_unlock_irqrestore(&phba->hbalock, iflag);
4102 /* Handle the response IOCB */
4103 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
4104 spin_lock_irqsave(&phba->hbalock, iflag);
4107 * If the port response put pointer has not been updated, sync
4108 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
4109 * response put pointer.
4111 if (pring->sli.sli3.rspidx == portRspPut) {
4112 portRspPut = le32_to_cpu(pgp->rspPutInx);
4114 } /* while (pring->sli.sli3.rspidx != portRspPut) */
4116 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
4117 /* At least one response entry has been freed */
4118 pring->stats.iocb_rsp_full++;
4119 /* SET RxRE_RSP in Chip Att register */
4120 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
4121 writel(status, phba->CAregaddr);
4122 readl(phba->CAregaddr); /* flush */
4124 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
4125 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
4126 pring->stats.iocb_cmd_empty++;
4128 /* Force update of the local copy of cmdGetInx */
4129 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
4130 lpfc_sli_resume_iocb(phba, pring);
4132 if ((pring->lpfc_sli_cmd_available))
4133 (pring->lpfc_sli_cmd_available) (phba, pring);
4137 spin_unlock_irqrestore(&phba->hbalock, iflag);
4142 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
4143 * @phba: Pointer to HBA context object.
4144 * @pring: Pointer to driver SLI ring object.
4145 * @mask: Host attention register mask for this ring.
4147 * This function is called from the worker thread when there is a pending
4148 * ELS response iocb on the driver internal slow-path response iocb worker
4149 * queue. The caller does not hold any lock. The function will remove each
4150 * response iocb from the response worker queue and calls the handle
4151 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4154 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
4155 struct lpfc_sli_ring *pring, uint32_t mask)
4157 struct lpfc_iocbq *irspiocbq;
4158 struct hbq_dmabuf *dmabuf;
4159 struct lpfc_cq_event *cq_event;
4160 unsigned long iflag;
4163 spin_lock_irqsave(&phba->hbalock, iflag);
4164 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
4165 spin_unlock_irqrestore(&phba->hbalock, iflag);
4166 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
4167 /* Get the response iocb from the head of work queue */
4168 spin_lock_irqsave(&phba->hbalock, iflag);
4169 list_remove_head(&phba->sli4_hba.sp_queue_event,
4170 cq_event, struct lpfc_cq_event, list);
4171 spin_unlock_irqrestore(&phba->hbalock, iflag);
4173 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
4174 case CQE_CODE_COMPL_WQE:
4175 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
4177 /* Translate ELS WCQE to response IOCBQ */
4178 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
4181 lpfc_sli_sp_handle_rspiocb(phba, pring,
4185 case CQE_CODE_RECEIVE:
4186 case CQE_CODE_RECEIVE_V1:
4187 dmabuf = container_of(cq_event, struct hbq_dmabuf,
4189 lpfc_sli4_handle_received_buffer(phba, dmabuf);
4196 /* Limit the number of events to 64 to avoid soft lockups */
4203 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
4204 * @phba: Pointer to HBA context object.
4205 * @pring: Pointer to driver SLI ring object.
4207 * This function aborts all iocbs in the given ring and frees all the iocb
4208 * objects in txq. This function issues an abort iocb for all the iocb commands
4209 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4210 * the return of this function. The caller is not required to hold any locks.
4213 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
4215 LIST_HEAD(completions);
4216 struct lpfc_iocbq *iocb, *next_iocb;
4218 if (pring->ringno == LPFC_ELS_RING) {
4219 lpfc_fabric_abort_hba(phba);
4222 /* Error everything on txq and txcmplq
4225 if (phba->sli_rev >= LPFC_SLI_REV4) {
4226 spin_lock_irq(&pring->ring_lock);
4227 list_splice_init(&pring->txq, &completions);
4229 spin_unlock_irq(&pring->ring_lock);
4231 spin_lock_irq(&phba->hbalock);
4232 /* Next issue ABTS for everything on the txcmplq */
4233 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
4234 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
4235 spin_unlock_irq(&phba->hbalock);
4237 spin_lock_irq(&phba->hbalock);
4238 list_splice_init(&pring->txq, &completions);
4241 /* Next issue ABTS for everything on the txcmplq */
4242 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
4243 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
4244 spin_unlock_irq(&phba->hbalock);
4246 /* Make sure HBA is alive */
4247 lpfc_issue_hb_tmo(phba);
4249 /* Cancel all the IOCBs from the completions list */
4250 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4255 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
4256 * @phba: Pointer to HBA context object.
4258 * This function aborts all iocbs in FCP rings and frees all the iocb
4259 * objects in txq. This function issues an abort iocb for all the iocb commands
4260 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4261 * the return of this function. The caller is not required to hold any locks.
4264 lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
4266 struct lpfc_sli *psli = &phba->sli;
4267 struct lpfc_sli_ring *pring;
4270 /* Look on all the FCP Rings for the iotag */
4271 if (phba->sli_rev >= LPFC_SLI_REV4) {
4272 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4273 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4274 lpfc_sli_abort_iocb_ring(phba, pring);
4277 pring = &psli->sli3_ring[LPFC_FCP_RING];
4278 lpfc_sli_abort_iocb_ring(phba, pring);
4283 * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
4284 * @phba: Pointer to HBA context object.
4286 * This function flushes all iocbs in the IO ring and frees all the iocb
4287 * objects in txq and txcmplq. This function will not issue abort iocbs
4288 * for all the iocb commands in txcmplq, they will just be returned with
4289 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
4290 * slot has been permanently disabled.
4293 lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
4297 struct lpfc_sli *psli = &phba->sli;
4298 struct lpfc_sli_ring *pring;
4300 struct lpfc_iocbq *piocb, *next_iocb;
4302 spin_lock_irq(&phba->hbalock);
4303 if (phba->hba_flag & HBA_IOQ_FLUSH ||
4304 !phba->sli4_hba.hdwq) {
4305 spin_unlock_irq(&phba->hbalock);
4308 /* Indicate the I/O queues are flushed */
4309 phba->hba_flag |= HBA_IOQ_FLUSH;
4310 spin_unlock_irq(&phba->hbalock);
4312 /* Look on all the FCP Rings for the iotag */
4313 if (phba->sli_rev >= LPFC_SLI_REV4) {
4314 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4315 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4317 spin_lock_irq(&pring->ring_lock);
4318 /* Retrieve everything on txq */
4319 list_splice_init(&pring->txq, &txq);
4320 list_for_each_entry_safe(piocb, next_iocb,
4321 &pring->txcmplq, list)
4322 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4323 /* Retrieve everything on the txcmplq */
4324 list_splice_init(&pring->txcmplq, &txcmplq);
4326 pring->txcmplq_cnt = 0;
4327 spin_unlock_irq(&pring->ring_lock);
4330 lpfc_sli_cancel_iocbs(phba, &txq,
4331 IOSTAT_LOCAL_REJECT,
4333 /* Flush the txcmpq */
4334 lpfc_sli_cancel_iocbs(phba, &txcmplq,
4335 IOSTAT_LOCAL_REJECT,
4339 pring = &psli->sli3_ring[LPFC_FCP_RING];
4341 spin_lock_irq(&phba->hbalock);
4342 /* Retrieve everything on txq */
4343 list_splice_init(&pring->txq, &txq);
4344 list_for_each_entry_safe(piocb, next_iocb,
4345 &pring->txcmplq, list)
4346 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4347 /* Retrieve everything on the txcmplq */
4348 list_splice_init(&pring->txcmplq, &txcmplq);
4350 pring->txcmplq_cnt = 0;
4351 spin_unlock_irq(&phba->hbalock);
4354 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
4356 /* Flush the txcmpq */
4357 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
4363 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
4364 * @phba: Pointer to HBA context object.
4365 * @mask: Bit mask to be checked.
4367 * This function reads the host status register and compares
4368 * with the provided bit mask to check if HBA completed
4369 * the restart. This function will wait in a loop for the
4370 * HBA to complete restart. If the HBA does not restart within
4371 * 15 iterations, the function will reset the HBA again. The
4372 * function returns 1 when HBA fail to restart otherwise returns
4376 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
4382 /* Read the HBA Host Status Register */
4383 if (lpfc_readl(phba->HSregaddr, &status))
4386 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
4389 * Check status register every 100ms for 5 retries, then every
4390 * 500ms for 5, then every 2.5 sec for 5, then reset board and
4391 * every 2.5 sec for 4.
4392 * Break our of the loop if errors occurred during init.
4394 while (((status & mask) != mask) &&
4395 !(status & HS_FFERM) &&
4407 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4408 lpfc_sli_brdrestart(phba);
4410 /* Read the HBA Host Status Register */
4411 if (lpfc_readl(phba->HSregaddr, &status)) {
4417 /* Check to see if any errors occurred during init */
4418 if ((status & HS_FFERM) || (i >= 20)) {
4419 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4420 "2751 Adapter failed to restart, "
4421 "status reg x%x, FW Data: A8 x%x AC x%x\n",
4423 readl(phba->MBslimaddr + 0xa8),
4424 readl(phba->MBslimaddr + 0xac));
4425 phba->link_state = LPFC_HBA_ERROR;
4433 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
4434 * @phba: Pointer to HBA context object.
4435 * @mask: Bit mask to be checked.
4437 * This function checks the host status register to check if HBA is
4438 * ready. This function will wait in a loop for the HBA to be ready
4439 * If the HBA is not ready , the function will will reset the HBA PCI
4440 * function again. The function returns 1 when HBA fail to be ready
4441 * otherwise returns zero.
4444 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
4449 /* Read the HBA Host Status Register */
4450 status = lpfc_sli4_post_status_check(phba);
4453 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4454 lpfc_sli_brdrestart(phba);
4455 status = lpfc_sli4_post_status_check(phba);
4458 /* Check to see if any errors occurred during init */
4460 phba->link_state = LPFC_HBA_ERROR;
4463 phba->sli4_hba.intr_enable = 0;
4469 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
4470 * @phba: Pointer to HBA context object.
4471 * @mask: Bit mask to be checked.
4473 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
4474 * from the API jump table function pointer from the lpfc_hba struct.
4477 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
4479 return phba->lpfc_sli_brdready(phba, mask);
4482 #define BARRIER_TEST_PATTERN (0xdeadbeef)
4485 * lpfc_reset_barrier - Make HBA ready for HBA reset
4486 * @phba: Pointer to HBA context object.
4488 * This function is called before resetting an HBA. This function is called
4489 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4491 void lpfc_reset_barrier(struct lpfc_hba *phba)
4493 uint32_t __iomem *resp_buf;
4494 uint32_t __iomem *mbox_buf;
4495 volatile uint32_t mbox;
4496 uint32_t hc_copy, ha_copy, resp_data;
4500 lockdep_assert_held(&phba->hbalock);
4502 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
4503 if (hdrtype != 0x80 ||
4504 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
4505 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
4509 * Tell the other part of the chip to suspend temporarily all
4512 resp_buf = phba->MBslimaddr;
4514 /* Disable the error attention */
4515 if (lpfc_readl(phba->HCregaddr, &hc_copy))
4517 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
4518 readl(phba->HCregaddr); /* flush */
4519 phba->link_flag |= LS_IGNORE_ERATT;
4521 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4523 if (ha_copy & HA_ERATT) {
4524 /* Clear Chip error bit */
4525 writel(HA_ERATT, phba->HAregaddr);
4526 phba->pport->stopped = 1;
4530 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
4531 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
4533 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
4534 mbox_buf = phba->MBslimaddr;
4535 writel(mbox, mbox_buf);
4537 for (i = 0; i < 50; i++) {
4538 if (lpfc_readl((resp_buf + 1), &resp_data))
4540 if (resp_data != ~(BARRIER_TEST_PATTERN))
4546 if (lpfc_readl((resp_buf + 1), &resp_data))
4548 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
4549 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
4550 phba->pport->stopped)
4556 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
4558 for (i = 0; i < 500; i++) {
4559 if (lpfc_readl(resp_buf, &resp_data))
4561 if (resp_data != mbox)
4570 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4572 if (!(ha_copy & HA_ERATT))
4578 if (readl(phba->HAregaddr) & HA_ERATT) {
4579 writel(HA_ERATT, phba->HAregaddr);
4580 phba->pport->stopped = 1;
4584 phba->link_flag &= ~LS_IGNORE_ERATT;
4585 writel(hc_copy, phba->HCregaddr);
4586 readl(phba->HCregaddr); /* flush */
4590 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4591 * @phba: Pointer to HBA context object.
4593 * This function issues a kill_board mailbox command and waits for
4594 * the error attention interrupt. This function is called for stopping
4595 * the firmware processing. The caller is not required to hold any
4596 * locks. This function calls lpfc_hba_down_post function to free
4597 * any pending commands after the kill. The function will return 1 when it
4598 * fails to kill the board else will return 0.
4601 lpfc_sli_brdkill(struct lpfc_hba *phba)
4603 struct lpfc_sli *psli;
4613 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4614 "0329 Kill HBA Data: x%x x%x\n",
4615 phba->pport->port_state, psli->sli_flag);
4617 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4621 /* Disable the error attention */
4622 spin_lock_irq(&phba->hbalock);
4623 if (lpfc_readl(phba->HCregaddr, &status)) {
4624 spin_unlock_irq(&phba->hbalock);
4625 mempool_free(pmb, phba->mbox_mem_pool);
4628 status &= ~HC_ERINT_ENA;
4629 writel(status, phba->HCregaddr);
4630 readl(phba->HCregaddr); /* flush */
4631 phba->link_flag |= LS_IGNORE_ERATT;
4632 spin_unlock_irq(&phba->hbalock);
4634 lpfc_kill_board(phba, pmb);
4635 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4636 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4638 if (retval != MBX_SUCCESS) {
4639 if (retval != MBX_BUSY)
4640 mempool_free(pmb, phba->mbox_mem_pool);
4641 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4642 "2752 KILL_BOARD command failed retval %d\n",
4644 spin_lock_irq(&phba->hbalock);
4645 phba->link_flag &= ~LS_IGNORE_ERATT;
4646 spin_unlock_irq(&phba->hbalock);
4650 spin_lock_irq(&phba->hbalock);
4651 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4652 spin_unlock_irq(&phba->hbalock);
4654 mempool_free(pmb, phba->mbox_mem_pool);
4656 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4657 * attention every 100ms for 3 seconds. If we don't get ERATT after
4658 * 3 seconds we still set HBA_ERROR state because the status of the
4659 * board is now undefined.
4661 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4663 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
4665 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4669 del_timer_sync(&psli->mbox_tmo);
4670 if (ha_copy & HA_ERATT) {
4671 writel(HA_ERATT, phba->HAregaddr);
4672 phba->pport->stopped = 1;
4674 spin_lock_irq(&phba->hbalock);
4675 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4676 psli->mbox_active = NULL;
4677 phba->link_flag &= ~LS_IGNORE_ERATT;
4678 spin_unlock_irq(&phba->hbalock);
4680 lpfc_hba_down_post(phba);
4681 phba->link_state = LPFC_HBA_ERROR;
4683 return ha_copy & HA_ERATT ? 0 : 1;
4687 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4688 * @phba: Pointer to HBA context object.
4690 * This function resets the HBA by writing HC_INITFF to the control
4691 * register. After the HBA resets, this function resets all the iocb ring
4692 * indices. This function disables PCI layer parity checking during
4694 * This function returns 0 always.
4695 * The caller is not required to hold any locks.
4698 lpfc_sli_brdreset(struct lpfc_hba *phba)
4700 struct lpfc_sli *psli;
4701 struct lpfc_sli_ring *pring;
4708 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4709 "0325 Reset HBA Data: x%x x%x\n",
4710 (phba->pport) ? phba->pport->port_state : 0,
4713 /* perform board reset */
4714 phba->fc_eventTag = 0;
4715 phba->link_events = 0;
4716 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
4718 phba->pport->fc_myDID = 0;
4719 phba->pport->fc_prevDID = 0;
4722 /* Turn off parity checking and serr during the physical reset */
4723 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
4726 pci_write_config_word(phba->pcidev, PCI_COMMAND,
4728 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4730 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
4732 /* Now toggle INITFF bit in the Host Control Register */
4733 writel(HC_INITFF, phba->HCregaddr);
4735 readl(phba->HCregaddr); /* flush */
4736 writel(0, phba->HCregaddr);
4737 readl(phba->HCregaddr); /* flush */
4739 /* Restore PCI cmd register */
4740 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4742 /* Initialize relevant SLI info */
4743 for (i = 0; i < psli->num_rings; i++) {
4744 pring = &psli->sli3_ring[i];
4746 pring->sli.sli3.rspidx = 0;
4747 pring->sli.sli3.next_cmdidx = 0;
4748 pring->sli.sli3.local_getidx = 0;
4749 pring->sli.sli3.cmdidx = 0;
4750 pring->missbufcnt = 0;
4753 phba->link_state = LPFC_WARM_START;
4758 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4759 * @phba: Pointer to HBA context object.
4761 * This function resets a SLI4 HBA. This function disables PCI layer parity
4762 * checking during resets the device. The caller is not required to hold
4765 * This function returns 0 on success else returns negative error code.
4768 lpfc_sli4_brdreset(struct lpfc_hba *phba)
4770 struct lpfc_sli *psli = &phba->sli;
4775 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4776 "0295 Reset HBA Data: x%x x%x x%x\n",
4777 phba->pport->port_state, psli->sli_flag,
4780 /* perform board reset */
4781 phba->fc_eventTag = 0;
4782 phba->link_events = 0;
4783 phba->pport->fc_myDID = 0;
4784 phba->pport->fc_prevDID = 0;
4786 spin_lock_irq(&phba->hbalock);
4787 psli->sli_flag &= ~(LPFC_PROCESS_LA);
4788 phba->fcf.fcf_flag = 0;
4789 spin_unlock_irq(&phba->hbalock);
4791 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4792 if (phba->hba_flag & HBA_FW_DUMP_OP) {
4793 phba->hba_flag &= ~HBA_FW_DUMP_OP;
4797 /* Now physically reset the device */
4798 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4799 "0389 Performing PCI function reset!\n");
4801 /* Turn off parity checking and serr during the physical reset */
4802 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
4803 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4804 "3205 PCI read Config failed\n");
4808 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
4809 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4811 /* Perform FCoE PCI function reset before freeing queue memory */
4812 rc = lpfc_pci_function_reset(phba);
4814 /* Restore PCI cmd register */
4815 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4821 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4822 * @phba: Pointer to HBA context object.
4824 * This function is called in the SLI initialization code path to
4825 * restart the HBA. The caller is not required to hold any lock.
4826 * This function writes MBX_RESTART mailbox command to the SLIM and
4827 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4828 * function to free any pending commands. The function enables
4829 * POST only during the first initialization. The function returns zero.
4830 * The function does not guarantee completion of MBX_RESTART mailbox
4831 * command before the return of this function.
4834 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
4837 struct lpfc_sli *psli;
4838 volatile uint32_t word0;
4839 void __iomem *to_slim;
4840 uint32_t hba_aer_enabled;
4842 spin_lock_irq(&phba->hbalock);
4844 /* Take PCIe device Advanced Error Reporting (AER) state */
4845 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4850 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4851 "0337 Restart HBA Data: x%x x%x\n",
4852 (phba->pport) ? phba->pport->port_state : 0,
4856 mb = (MAILBOX_t *) &word0;
4857 mb->mbxCommand = MBX_RESTART;
4860 lpfc_reset_barrier(phba);
4862 to_slim = phba->MBslimaddr;
4863 writel(*(uint32_t *) mb, to_slim);
4864 readl(to_slim); /* flush */
4866 /* Only skip post after fc_ffinit is completed */
4867 if (phba->pport && phba->pport->port_state)
4868 word0 = 1; /* This is really setting up word1 */
4870 word0 = 0; /* This is really setting up word1 */
4871 to_slim = phba->MBslimaddr + sizeof (uint32_t);
4872 writel(*(uint32_t *) mb, to_slim);
4873 readl(to_slim); /* flush */
4875 lpfc_sli_brdreset(phba);
4877 phba->pport->stopped = 0;
4878 phba->link_state = LPFC_INIT_START;
4880 spin_unlock_irq(&phba->hbalock);
4882 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4883 psli->stats_start = ktime_get_seconds();
4885 /* Give the INITFF and Post time to settle. */
4888 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4889 if (hba_aer_enabled)
4890 pci_disable_pcie_error_reporting(phba->pcidev);
4892 lpfc_hba_down_post(phba);
4898 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4899 * @phba: Pointer to HBA context object.
4901 * This function is called in the SLI initialization code path to restart
4902 * a SLI4 HBA. The caller is not required to hold any lock.
4903 * At the end of the function, it calls lpfc_hba_down_post function to
4904 * free any pending commands.
4907 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
4909 struct lpfc_sli *psli = &phba->sli;
4910 uint32_t hba_aer_enabled;
4914 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4915 "0296 Restart HBA Data: x%x x%x\n",
4916 phba->pport->port_state, psli->sli_flag);
4918 /* Take PCIe device Advanced Error Reporting (AER) state */
4919 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
4921 rc = lpfc_sli4_brdreset(phba);
4923 phba->link_state = LPFC_HBA_ERROR;
4924 goto hba_down_queue;
4927 spin_lock_irq(&phba->hbalock);
4928 phba->pport->stopped = 0;
4929 phba->link_state = LPFC_INIT_START;
4931 spin_unlock_irq(&phba->hbalock);
4933 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
4934 psli->stats_start = ktime_get_seconds();
4936 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4937 if (hba_aer_enabled)
4938 pci_disable_pcie_error_reporting(phba->pcidev);
4941 lpfc_hba_down_post(phba);
4942 lpfc_sli4_queue_destroy(phba);
4948 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4949 * @phba: Pointer to HBA context object.
4951 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4952 * API jump table function pointer from the lpfc_hba struct.
4955 lpfc_sli_brdrestart(struct lpfc_hba *phba)
4957 return phba->lpfc_sli_brdrestart(phba);
4961 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4962 * @phba: Pointer to HBA context object.
4964 * This function is called after a HBA restart to wait for successful
4965 * restart of the HBA. Successful restart of the HBA is indicated by
4966 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4967 * iteration, the function will restart the HBA again. The function returns
4968 * zero if HBA successfully restarted else returns negative error code.
4971 lpfc_sli_chipset_init(struct lpfc_hba *phba)
4973 uint32_t status, i = 0;
4975 /* Read the HBA Host Status Register */
4976 if (lpfc_readl(phba->HSregaddr, &status))
4979 /* Check status register to see what current state is */
4981 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
4983 /* Check every 10ms for 10 retries, then every 100ms for 90
4984 * retries, then every 1 sec for 50 retires for a total of
4985 * ~60 seconds before reset the board again and check every
4986 * 1 sec for 50 retries. The up to 60 seconds before the
4987 * board ready is required by the Falcon FIPS zeroization
4988 * complete, and any reset the board in between shall cause
4989 * restart of zeroization, further delay the board ready.
4992 /* Adapter failed to init, timeout, status reg
4994 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4995 "0436 Adapter failed to init, "
4996 "timeout, status reg x%x, "
4997 "FW Data: A8 x%x AC x%x\n", status,
4998 readl(phba->MBslimaddr + 0xa8),
4999 readl(phba->MBslimaddr + 0xac));
5000 phba->link_state = LPFC_HBA_ERROR;
5004 /* Check to see if any errors occurred during init */
5005 if (status & HS_FFERM) {
5006 /* ERROR: During chipset initialization */
5007 /* Adapter failed to init, chipset, status reg
5009 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5010 "0437 Adapter failed to init, "
5011 "chipset, status reg x%x, "
5012 "FW Data: A8 x%x AC x%x\n", status,
5013 readl(phba->MBslimaddr + 0xa8),
5014 readl(phba->MBslimaddr + 0xac));
5015 phba->link_state = LPFC_HBA_ERROR;
5028 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5029 lpfc_sli_brdrestart(phba);
5031 /* Read the HBA Host Status Register */
5032 if (lpfc_readl(phba->HSregaddr, &status))
5036 /* Check to see if any errors occurred during init */
5037 if (status & HS_FFERM) {
5038 /* ERROR: During chipset initialization */
5039 /* Adapter failed to init, chipset, status reg <status> */
5040 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5041 "0438 Adapter failed to init, chipset, "
5043 "FW Data: A8 x%x AC x%x\n", status,
5044 readl(phba->MBslimaddr + 0xa8),
5045 readl(phba->MBslimaddr + 0xac));
5046 phba->link_state = LPFC_HBA_ERROR;
5050 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
5052 /* Clear all interrupt enable conditions */
5053 writel(0, phba->HCregaddr);
5054 readl(phba->HCregaddr); /* flush */
5056 /* setup host attn register */
5057 writel(0xffffffff, phba->HAregaddr);
5058 readl(phba->HAregaddr); /* flush */
5063 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
5065 * This function calculates and returns the number of HBQs required to be
5069 lpfc_sli_hbq_count(void)
5071 return ARRAY_SIZE(lpfc_hbq_defs);
5075 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
5077 * This function adds the number of hbq entries in every HBQ to get
5078 * the total number of hbq entries required for the HBA and returns
5082 lpfc_sli_hbq_entry_count(void)
5084 int hbq_count = lpfc_sli_hbq_count();
5088 for (i = 0; i < hbq_count; ++i)
5089 count += lpfc_hbq_defs[i]->entry_count;
5094 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
5096 * This function calculates amount of memory required for all hbq entries
5097 * to be configured and returns the total memory required.
5100 lpfc_sli_hbq_size(void)
5102 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
5106 * lpfc_sli_hbq_setup - configure and initialize HBQs
5107 * @phba: Pointer to HBA context object.
5109 * This function is called during the SLI initialization to configure
5110 * all the HBQs and post buffers to the HBQ. The caller is not
5111 * required to hold any locks. This function will return zero if successful
5112 * else it will return negative error code.
5115 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
5117 int hbq_count = lpfc_sli_hbq_count();
5121 uint32_t hbq_entry_index;
5123 /* Get a Mailbox buffer to setup mailbox
5124 * commands for HBA initialization
5126 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5133 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
5134 phba->link_state = LPFC_INIT_MBX_CMDS;
5135 phba->hbq_in_use = 1;
5137 hbq_entry_index = 0;
5138 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
5139 phba->hbqs[hbqno].next_hbqPutIdx = 0;
5140 phba->hbqs[hbqno].hbqPutIdx = 0;
5141 phba->hbqs[hbqno].local_hbqGetIdx = 0;
5142 phba->hbqs[hbqno].entry_count =
5143 lpfc_hbq_defs[hbqno]->entry_count;
5144 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
5145 hbq_entry_index, pmb);
5146 hbq_entry_index += phba->hbqs[hbqno].entry_count;
5148 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
5149 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
5150 mbxStatus <status>, ring <num> */
5152 lpfc_printf_log(phba, KERN_ERR,
5153 LOG_SLI | LOG_VPORT,
5154 "1805 Adapter failed to init. "
5155 "Data: x%x x%x x%x\n",
5157 pmbox->mbxStatus, hbqno);
5159 phba->link_state = LPFC_HBA_ERROR;
5160 mempool_free(pmb, phba->mbox_mem_pool);
5164 phba->hbq_count = hbq_count;
5166 mempool_free(pmb, phba->mbox_mem_pool);
5168 /* Initially populate or replenish the HBQs */
5169 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
5170 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
5175 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
5176 * @phba: Pointer to HBA context object.
5178 * This function is called during the SLI initialization to configure
5179 * all the HBQs and post buffers to the HBQ. The caller is not
5180 * required to hold any locks. This function will return zero if successful
5181 * else it will return negative error code.
5184 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
5186 phba->hbq_in_use = 1;
5188 * Specific case when the MDS diagnostics is enabled and supported.
5189 * The receive buffer count is truncated to manage the incoming
5192 if (phba->cfg_enable_mds_diags && phba->mds_diags_support)
5193 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5194 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1;
5196 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5197 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
5198 phba->hbq_count = 1;
5199 lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
5200 /* Initially populate or replenish the HBQs */
5205 * lpfc_sli_config_port - Issue config port mailbox command
5206 * @phba: Pointer to HBA context object.
5207 * @sli_mode: sli mode - 2/3
5209 * This function is called by the sli initialization code path
5210 * to issue config_port mailbox command. This function restarts the
5211 * HBA firmware and issues a config_port mailbox command to configure
5212 * the SLI interface in the sli mode specified by sli_mode
5213 * variable. The caller is not required to hold any locks.
5214 * The function returns 0 if successful, else returns negative error
5218 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
5221 uint32_t resetcount = 0, rc = 0, done = 0;
5223 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5225 phba->link_state = LPFC_HBA_ERROR;
5229 phba->sli_rev = sli_mode;
5230 while (resetcount < 2 && !done) {
5231 spin_lock_irq(&phba->hbalock);
5232 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5233 spin_unlock_irq(&phba->hbalock);
5234 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5235 lpfc_sli_brdrestart(phba);
5236 rc = lpfc_sli_chipset_init(phba);
5240 spin_lock_irq(&phba->hbalock);
5241 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5242 spin_unlock_irq(&phba->hbalock);
5245 /* Call pre CONFIG_PORT mailbox command initialization. A
5246 * value of 0 means the call was successful. Any other
5247 * nonzero value is a failure, but if ERESTART is returned,
5248 * the driver may reset the HBA and try again.
5250 rc = lpfc_config_port_prep(phba);
5251 if (rc == -ERESTART) {
5252 phba->link_state = LPFC_LINK_UNKNOWN;
5257 phba->link_state = LPFC_INIT_MBX_CMDS;
5258 lpfc_config_port(phba, pmb);
5259 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
5260 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
5261 LPFC_SLI3_HBQ_ENABLED |
5262 LPFC_SLI3_CRP_ENABLED |
5263 LPFC_SLI3_DSS_ENABLED);
5264 if (rc != MBX_SUCCESS) {
5265 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5266 "0442 Adapter failed to init, mbxCmd x%x "
5267 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
5268 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
5269 spin_lock_irq(&phba->hbalock);
5270 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
5271 spin_unlock_irq(&phba->hbalock);
5274 /* Allow asynchronous mailbox command to go through */
5275 spin_lock_irq(&phba->hbalock);
5276 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5277 spin_unlock_irq(&phba->hbalock);
5280 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
5281 (pmb->u.mb.un.varCfgPort.gasabt == 0))
5282 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5283 "3110 Port did not grant ASABT\n");
5288 goto do_prep_failed;
5290 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
5291 if (!pmb->u.mb.un.varCfgPort.cMA) {
5293 goto do_prep_failed;
5295 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
5296 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
5297 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
5298 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
5299 phba->max_vpi : phba->max_vports;
5303 if (pmb->u.mb.un.varCfgPort.gerbm)
5304 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
5305 if (pmb->u.mb.un.varCfgPort.gcrp)
5306 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
5308 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
5309 phba->port_gp = phba->mbox->us.s3_pgp.port;
5311 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5312 if (pmb->u.mb.un.varCfgPort.gbg == 0) {
5313 phba->cfg_enable_bg = 0;
5314 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
5315 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5316 "0443 Adapter did not grant "
5321 phba->hbq_get = NULL;
5322 phba->port_gp = phba->mbox->us.s2.port;
5326 mempool_free(pmb, phba->mbox_mem_pool);
5332 * lpfc_sli_hba_setup - SLI initialization function
5333 * @phba: Pointer to HBA context object.
5335 * This function is the main SLI initialization function. This function
5336 * is called by the HBA initialization code, HBA reset code and HBA
5337 * error attention handler code. Caller is not required to hold any
5338 * locks. This function issues config_port mailbox command to configure
5339 * the SLI, setup iocb rings and HBQ rings. In the end the function
5340 * calls the config_port_post function to issue init_link mailbox
5341 * command and to start the discovery. The function will return zero
5342 * if successful, else it will return negative error code.
5345 lpfc_sli_hba_setup(struct lpfc_hba *phba)
5351 /* Enable ISR already does config_port because of config_msi mbx */
5352 if (phba->hba_flag & HBA_NEEDS_CFG_PORT) {
5353 rc = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
5356 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
5358 phba->fcp_embed_io = 0; /* SLI4 FC support only */
5360 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5361 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
5362 rc = pci_enable_pcie_error_reporting(phba->pcidev);
5364 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5365 "2709 This device supports "
5366 "Advanced Error Reporting (AER)\n");
5367 spin_lock_irq(&phba->hbalock);
5368 phba->hba_flag |= HBA_AER_ENABLED;
5369 spin_unlock_irq(&phba->hbalock);
5371 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5372 "2708 This device does not support "
5373 "Advanced Error Reporting (AER): %d\n",
5375 phba->cfg_aer_support = 0;
5379 if (phba->sli_rev == 3) {
5380 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
5381 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
5383 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
5384 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
5385 phba->sli3_options = 0;
5388 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5389 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
5390 phba->sli_rev, phba->max_vpi);
5391 rc = lpfc_sli_ring_map(phba);
5394 goto lpfc_sli_hba_setup_error;
5396 /* Initialize VPIs. */
5397 if (phba->sli_rev == LPFC_SLI_REV3) {
5399 * The VPI bitmask and physical ID array are allocated
5400 * and initialized once only - at driver load. A port
5401 * reset doesn't need to reinitialize this memory.
5403 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
5404 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
5405 phba->vpi_bmask = kcalloc(longs,
5406 sizeof(unsigned long),
5408 if (!phba->vpi_bmask) {
5410 goto lpfc_sli_hba_setup_error;
5413 phba->vpi_ids = kcalloc(phba->max_vpi + 1,
5416 if (!phba->vpi_ids) {
5417 kfree(phba->vpi_bmask);
5419 goto lpfc_sli_hba_setup_error;
5421 for (i = 0; i < phba->max_vpi; i++)
5422 phba->vpi_ids[i] = i;
5427 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5428 rc = lpfc_sli_hbq_setup(phba);
5430 goto lpfc_sli_hba_setup_error;
5432 spin_lock_irq(&phba->hbalock);
5433 phba->sli.sli_flag |= LPFC_PROCESS_LA;
5434 spin_unlock_irq(&phba->hbalock);
5436 rc = lpfc_config_port_post(phba);
5438 goto lpfc_sli_hba_setup_error;
5442 lpfc_sli_hba_setup_error:
5443 phba->link_state = LPFC_HBA_ERROR;
5444 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5445 "0445 Firmware initialization failed\n");
5450 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
5451 * @phba: Pointer to HBA context object.
5453 * This function issue a dump mailbox command to read config region
5454 * 23 and parse the records in the region and populate driver
5458 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
5460 LPFC_MBOXQ_t *mboxq;
5461 struct lpfc_dmabuf *mp;
5462 struct lpfc_mqe *mqe;
5463 uint32_t data_length;
5466 /* Program the default value of vlan_id and fc_map */
5467 phba->valid_vlan = 0;
5468 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5469 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5470 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5472 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5476 mqe = &mboxq->u.mqe;
5477 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
5479 goto out_free_mboxq;
5482 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
5483 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5485 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5486 "(%d):2571 Mailbox cmd x%x Status x%x "
5487 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5488 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5489 "CQ: x%x x%x x%x x%x\n",
5490 mboxq->vport ? mboxq->vport->vpi : 0,
5491 bf_get(lpfc_mqe_command, mqe),
5492 bf_get(lpfc_mqe_status, mqe),
5493 mqe->un.mb_words[0], mqe->un.mb_words[1],
5494 mqe->un.mb_words[2], mqe->un.mb_words[3],
5495 mqe->un.mb_words[4], mqe->un.mb_words[5],
5496 mqe->un.mb_words[6], mqe->un.mb_words[7],
5497 mqe->un.mb_words[8], mqe->un.mb_words[9],
5498 mqe->un.mb_words[10], mqe->un.mb_words[11],
5499 mqe->un.mb_words[12], mqe->un.mb_words[13],
5500 mqe->un.mb_words[14], mqe->un.mb_words[15],
5501 mqe->un.mb_words[16], mqe->un.mb_words[50],
5503 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5504 mboxq->mcqe.trailer);
5507 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5510 goto out_free_mboxq;
5512 data_length = mqe->un.mb_words[5];
5513 if (data_length > DMP_RGN23_SIZE) {
5514 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5517 goto out_free_mboxq;
5520 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
5521 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5526 mempool_free(mboxq, phba->mbox_mem_pool);
5531 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5532 * @phba: pointer to lpfc hba data structure.
5533 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5534 * @vpd: pointer to the memory to hold resulting port vpd data.
5535 * @vpd_size: On input, the number of bytes allocated to @vpd.
5536 * On output, the number of data bytes in @vpd.
5538 * This routine executes a READ_REV SLI4 mailbox command. In
5539 * addition, this routine gets the port vpd data.
5543 * -ENOMEM - could not allocated memory.
5546 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5547 uint8_t *vpd, uint32_t *vpd_size)
5551 struct lpfc_dmabuf *dmabuf;
5552 struct lpfc_mqe *mqe;
5554 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5559 * Get a DMA buffer for the vpd data resulting from the READ_REV
5562 dma_size = *vpd_size;
5563 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
5564 &dmabuf->phys, GFP_KERNEL);
5565 if (!dmabuf->virt) {
5571 * The SLI4 implementation of READ_REV conflicts at word1,
5572 * bits 31:16 and SLI4 adds vpd functionality not present
5573 * in SLI3. This code corrects the conflicts.
5575 lpfc_read_rev(phba, mboxq);
5576 mqe = &mboxq->u.mqe;
5577 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
5578 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
5579 mqe->un.read_rev.word1 &= 0x0000FFFF;
5580 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
5581 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
5583 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5585 dma_free_coherent(&phba->pcidev->dev, dma_size,
5586 dmabuf->virt, dmabuf->phys);
5592 * The available vpd length cannot be bigger than the
5593 * DMA buffer passed to the port. Catch the less than
5594 * case and update the caller's size.
5596 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
5597 *vpd_size = mqe->un.read_rev.avail_vpd_len;
5599 memcpy(vpd, dmabuf->virt, *vpd_size);
5601 dma_free_coherent(&phba->pcidev->dev, dma_size,
5602 dmabuf->virt, dmabuf->phys);
5608 * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
5609 * @phba: pointer to lpfc hba data structure.
5611 * This routine retrieves SLI4 device physical port name this PCI function
5616 * otherwise - failed to retrieve controller attributes
5619 lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
5621 LPFC_MBOXQ_t *mboxq;
5622 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
5623 struct lpfc_controller_attribute *cntl_attr;
5624 void *virtaddr = NULL;
5625 uint32_t alloclen, reqlen;
5626 uint32_t shdr_status, shdr_add_status;
5627 union lpfc_sli4_cfg_shdr *shdr;
5630 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5634 /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
5635 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
5636 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5637 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
5638 LPFC_SLI4_MBX_NEMBED);
5640 if (alloclen < reqlen) {
5641 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5642 "3084 Allocated DMA memory size (%d) is "
5643 "less than the requested DMA memory size "
5644 "(%d)\n", alloclen, reqlen);
5646 goto out_free_mboxq;
5648 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5649 virtaddr = mboxq->sge_array->addr[0];
5650 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
5651 shdr = &mbx_cntl_attr->cfg_shdr;
5652 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5653 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5654 if (shdr_status || shdr_add_status || rc) {
5655 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5656 "3085 Mailbox x%x (x%x/x%x) failed, "
5657 "rc:x%x, status:x%x, add_status:x%x\n",
5658 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5659 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5660 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5661 rc, shdr_status, shdr_add_status);
5663 goto out_free_mboxq;
5666 cntl_attr = &mbx_cntl_attr->cntl_attr;
5667 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
5668 phba->sli4_hba.lnk_info.lnk_tp =
5669 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
5670 phba->sli4_hba.lnk_info.lnk_no =
5671 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
5673 memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
5674 strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
5675 sizeof(phba->BIOSVersion));
5677 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5678 "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s\n",
5679 phba->sli4_hba.lnk_info.lnk_tp,
5680 phba->sli4_hba.lnk_info.lnk_no,
5683 if (rc != MBX_TIMEOUT) {
5684 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5685 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5687 mempool_free(mboxq, phba->mbox_mem_pool);
5693 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5694 * @phba: pointer to lpfc hba data structure.
5696 * This routine retrieves SLI4 device physical port name this PCI function
5701 * otherwise - failed to retrieve physical port name
5704 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
5706 LPFC_MBOXQ_t *mboxq;
5707 struct lpfc_mbx_get_port_name *get_port_name;
5708 uint32_t shdr_status, shdr_add_status;
5709 union lpfc_sli4_cfg_shdr *shdr;
5710 char cport_name = 0;
5713 /* We assume nothing at this point */
5714 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5715 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
5717 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5720 /* obtain link type and link number via READ_CONFIG */
5721 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5722 lpfc_sli4_read_config(phba);
5723 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
5724 goto retrieve_ppname;
5726 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5727 rc = lpfc_sli4_get_ctl_attr(phba);
5729 goto out_free_mboxq;
5732 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5733 LPFC_MBOX_OPCODE_GET_PORT_NAME,
5734 sizeof(struct lpfc_mbx_get_port_name) -
5735 sizeof(struct lpfc_sli4_cfg_mhdr),
5736 LPFC_SLI4_MBX_EMBED);
5737 get_port_name = &mboxq->u.mqe.un.get_port_name;
5738 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
5739 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
5740 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
5741 phba->sli4_hba.lnk_info.lnk_tp);
5742 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5743 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5744 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5745 if (shdr_status || shdr_add_status || rc) {
5746 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5747 "3087 Mailbox x%x (x%x/x%x) failed: "
5748 "rc:x%x, status:x%x, add_status:x%x\n",
5749 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5750 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5751 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5752 rc, shdr_status, shdr_add_status);
5754 goto out_free_mboxq;
5756 switch (phba->sli4_hba.lnk_info.lnk_no) {
5757 case LPFC_LINK_NUMBER_0:
5758 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
5759 &get_port_name->u.response);
5760 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5762 case LPFC_LINK_NUMBER_1:
5763 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
5764 &get_port_name->u.response);
5765 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5767 case LPFC_LINK_NUMBER_2:
5768 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
5769 &get_port_name->u.response);
5770 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5772 case LPFC_LINK_NUMBER_3:
5773 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
5774 &get_port_name->u.response);
5775 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
5781 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
5782 phba->Port[0] = cport_name;
5783 phba->Port[1] = '\0';
5784 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5785 "3091 SLI get port name: %s\n", phba->Port);
5789 if (rc != MBX_TIMEOUT) {
5790 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5791 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5793 mempool_free(mboxq, phba->mbox_mem_pool);
5799 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5800 * @phba: pointer to lpfc hba data structure.
5802 * This routine is called to explicitly arm the SLI4 device's completion and
5806 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
5809 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
5810 struct lpfc_sli4_hdw_queue *qp;
5811 struct lpfc_queue *eq;
5813 sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
5814 sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
5815 if (sli4_hba->nvmels_cq)
5816 sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
5819 if (sli4_hba->hdwq) {
5820 /* Loop thru all Hardware Queues */
5821 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
5822 qp = &sli4_hba->hdwq[qidx];
5823 /* ARM the corresponding CQ */
5824 sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
5828 /* Loop thru all IRQ vectors */
5829 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
5830 eq = sli4_hba->hba_eq_hdl[qidx].eq;
5831 /* ARM the corresponding EQ */
5832 sli4_hba->sli4_write_eq_db(phba, eq,
5833 0, LPFC_QUEUE_REARM);
5837 if (phba->nvmet_support) {
5838 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
5839 sli4_hba->sli4_write_cq_db(phba,
5840 sli4_hba->nvmet_cqset[qidx], 0,
5847 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5848 * @phba: Pointer to HBA context object.
5849 * @type: The resource extent type.
5850 * @extnt_count: buffer to hold port available extent count.
5851 * @extnt_size: buffer to hold element count per extent.
5853 * This function calls the port and retrievs the number of available
5854 * extents and their size for a particular extent type.
5856 * Returns: 0 if successful. Nonzero otherwise.
5859 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
5860 uint16_t *extnt_count, uint16_t *extnt_size)
5865 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
5868 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5872 /* Find out how many extents are available for this resource type */
5873 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
5874 sizeof(struct lpfc_sli4_cfg_mhdr));
5875 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5876 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
5877 length, LPFC_SLI4_MBX_EMBED);
5879 /* Send an extents count of 0 - the GET doesn't use it. */
5880 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
5881 LPFC_SLI4_MBX_EMBED);
5887 if (!phba->sli4_hba.intr_enable)
5888 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5890 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
5891 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5898 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
5899 if (bf_get(lpfc_mbox_hdr_status,
5900 &rsrc_info->header.cfg_shdr.response)) {
5901 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5902 "2930 Failed to get resource extents "
5903 "Status 0x%x Add'l Status 0x%x\n",
5904 bf_get(lpfc_mbox_hdr_status,
5905 &rsrc_info->header.cfg_shdr.response),
5906 bf_get(lpfc_mbox_hdr_add_status,
5907 &rsrc_info->header.cfg_shdr.response));
5912 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
5914 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
5917 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5918 "3162 Retrieved extents type-%d from port: count:%d, "
5919 "size:%d\n", type, *extnt_count, *extnt_size);
5922 mempool_free(mbox, phba->mbox_mem_pool);
5927 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5928 * @phba: Pointer to HBA context object.
5929 * @type: The extent type to check.
5931 * This function reads the current available extents from the port and checks
5932 * if the extent count or extent size has changed since the last access.
5933 * Callers use this routine post port reset to understand if there is a
5934 * extent reprovisioning requirement.
5937 * -Error: error indicates problem.
5938 * 1: Extent count or size has changed.
5942 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
5944 uint16_t curr_ext_cnt, rsrc_ext_cnt;
5945 uint16_t size_diff, rsrc_ext_size;
5947 struct lpfc_rsrc_blks *rsrc_entry;
5948 struct list_head *rsrc_blk_list = NULL;
5952 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
5959 case LPFC_RSC_TYPE_FCOE_RPI:
5960 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
5962 case LPFC_RSC_TYPE_FCOE_VPI:
5963 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
5965 case LPFC_RSC_TYPE_FCOE_XRI:
5966 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
5968 case LPFC_RSC_TYPE_FCOE_VFI:
5969 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
5975 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
5977 if (rsrc_entry->rsrc_size != rsrc_ext_size)
5981 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
5988 * lpfc_sli4_cfg_post_extnts -
5989 * @phba: Pointer to HBA context object.
5990 * @extnt_cnt: number of available extents.
5991 * @type: the extent type (rpi, xri, vfi, vpi).
5992 * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5993 * @mbox: pointer to the caller's allocated mailbox structure.
5995 * This function executes the extents allocation request. It also
5996 * takes care of the amount of memory needed to allocate or get the
5997 * allocated extents. It is the caller's responsibility to evaluate
6001 * -Error: Error value describes the condition found.
6005 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
6006 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
6011 uint32_t alloc_len, mbox_tmo;
6013 /* Calculate the total requested length of the dma memory */
6014 req_len = extnt_cnt * sizeof(uint16_t);
6017 * Calculate the size of an embedded mailbox. The uint32_t
6018 * accounts for extents-specific word.
6020 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
6024 * Presume the allocation and response will fit into an embedded
6025 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6027 *emb = LPFC_SLI4_MBX_EMBED;
6028 if (req_len > emb_len) {
6029 req_len = extnt_cnt * sizeof(uint16_t) +
6030 sizeof(union lpfc_sli4_cfg_shdr) +
6032 *emb = LPFC_SLI4_MBX_NEMBED;
6035 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6036 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
6038 if (alloc_len < req_len) {
6039 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6040 "2982 Allocated DMA memory size (x%x) is "
6041 "less than the requested DMA memory "
6042 "size (x%x)\n", alloc_len, req_len);
6045 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
6049 if (!phba->sli4_hba.intr_enable)
6050 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6052 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6053 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6062 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
6063 * @phba: Pointer to HBA context object.
6064 * @type: The resource extent type to allocate.
6066 * This function allocates the number of elements for the specified
6070 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
6073 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
6074 uint16_t rsrc_id, rsrc_start, j, k;
6077 unsigned long longs;
6078 unsigned long *bmask;
6079 struct lpfc_rsrc_blks *rsrc_blks;
6082 struct lpfc_id_range *id_array = NULL;
6083 void *virtaddr = NULL;
6084 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
6085 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
6086 struct list_head *ext_blk_list;
6088 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
6094 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
6095 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6096 "3009 No available Resource Extents "
6097 "for resource type 0x%x: Count: 0x%x, "
6098 "Size 0x%x\n", type, rsrc_cnt,
6103 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
6104 "2903 Post resource extents type-0x%x: "
6105 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
6107 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6111 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
6118 * Figure out where the response is located. Then get local pointers
6119 * to the response data. The port does not guarantee to respond to
6120 * all extents counts request so update the local variable with the
6121 * allocated count from the port.
6123 if (emb == LPFC_SLI4_MBX_EMBED) {
6124 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
6125 id_array = &rsrc_ext->u.rsp.id[0];
6126 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
6128 virtaddr = mbox->sge_array->addr[0];
6129 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6130 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6131 id_array = &n_rsrc->id;
6134 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
6135 rsrc_id_cnt = rsrc_cnt * rsrc_size;
6138 * Based on the resource size and count, correct the base and max
6141 length = sizeof(struct lpfc_rsrc_blks);
6143 case LPFC_RSC_TYPE_FCOE_RPI:
6144 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6145 sizeof(unsigned long),
6147 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6151 phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
6154 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6155 kfree(phba->sli4_hba.rpi_bmask);
6161 * The next_rpi was initialized with the maximum available
6162 * count but the port may allocate a smaller number. Catch
6163 * that case and update the next_rpi.
6165 phba->sli4_hba.next_rpi = rsrc_id_cnt;
6167 /* Initialize local ptrs for common extent processing later. */
6168 bmask = phba->sli4_hba.rpi_bmask;
6169 ids = phba->sli4_hba.rpi_ids;
6170 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
6172 case LPFC_RSC_TYPE_FCOE_VPI:
6173 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6175 if (unlikely(!phba->vpi_bmask)) {
6179 phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
6181 if (unlikely(!phba->vpi_ids)) {
6182 kfree(phba->vpi_bmask);
6187 /* Initialize local ptrs for common extent processing later. */
6188 bmask = phba->vpi_bmask;
6189 ids = phba->vpi_ids;
6190 ext_blk_list = &phba->lpfc_vpi_blk_list;
6192 case LPFC_RSC_TYPE_FCOE_XRI:
6193 phba->sli4_hba.xri_bmask = kcalloc(longs,
6194 sizeof(unsigned long),
6196 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6200 phba->sli4_hba.max_cfg_param.xri_used = 0;
6201 phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
6204 if (unlikely(!phba->sli4_hba.xri_ids)) {
6205 kfree(phba->sli4_hba.xri_bmask);
6210 /* Initialize local ptrs for common extent processing later. */
6211 bmask = phba->sli4_hba.xri_bmask;
6212 ids = phba->sli4_hba.xri_ids;
6213 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
6215 case LPFC_RSC_TYPE_FCOE_VFI:
6216 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6217 sizeof(unsigned long),
6219 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6223 phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
6226 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6227 kfree(phba->sli4_hba.vfi_bmask);
6232 /* Initialize local ptrs for common extent processing later. */
6233 bmask = phba->sli4_hba.vfi_bmask;
6234 ids = phba->sli4_hba.vfi_ids;
6235 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
6238 /* Unsupported Opcode. Fail call. */
6242 ext_blk_list = NULL;
6247 * Complete initializing the extent configuration with the
6248 * allocated ids assigned to this function. The bitmask serves
6249 * as an index into the array and manages the available ids. The
6250 * array just stores the ids communicated to the port via the wqes.
6252 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
6254 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
6257 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
6260 rsrc_blks = kzalloc(length, GFP_KERNEL);
6261 if (unlikely(!rsrc_blks)) {
6267 rsrc_blks->rsrc_start = rsrc_id;
6268 rsrc_blks->rsrc_size = rsrc_size;
6269 list_add_tail(&rsrc_blks->list, ext_blk_list);
6270 rsrc_start = rsrc_id;
6271 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
6272 phba->sli4_hba.io_xri_start = rsrc_start +
6273 lpfc_sli4_get_iocb_cnt(phba);
6276 while (rsrc_id < (rsrc_start + rsrc_size)) {
6281 /* Entire word processed. Get next word.*/
6286 lpfc_sli4_mbox_cmd_free(phba, mbox);
6293 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
6294 * @phba: Pointer to HBA context object.
6295 * @type: the extent's type.
6297 * This function deallocates all extents of a particular resource type.
6298 * SLI4 does not allow for deallocating a particular extent range. It
6299 * is the caller's responsibility to release all kernel memory resources.
6302 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
6305 uint32_t length, mbox_tmo = 0;
6307 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
6308 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
6310 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6315 * This function sends an embedded mailbox because it only sends the
6316 * the resource type. All extents of this type are released by the
6319 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
6320 sizeof(struct lpfc_sli4_cfg_mhdr));
6321 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6322 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
6323 length, LPFC_SLI4_MBX_EMBED);
6325 /* Send an extents count of 0 - the dealloc doesn't use it. */
6326 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6327 LPFC_SLI4_MBX_EMBED);
6332 if (!phba->sli4_hba.intr_enable)
6333 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6335 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6336 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6343 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
6344 if (bf_get(lpfc_mbox_hdr_status,
6345 &dealloc_rsrc->header.cfg_shdr.response)) {
6346 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6347 "2919 Failed to release resource extents "
6348 "for type %d - Status 0x%x Add'l Status 0x%x. "
6349 "Resource memory not released.\n",
6351 bf_get(lpfc_mbox_hdr_status,
6352 &dealloc_rsrc->header.cfg_shdr.response),
6353 bf_get(lpfc_mbox_hdr_add_status,
6354 &dealloc_rsrc->header.cfg_shdr.response));
6359 /* Release kernel memory resources for the specific type. */
6361 case LPFC_RSC_TYPE_FCOE_VPI:
6362 kfree(phba->vpi_bmask);
6363 kfree(phba->vpi_ids);
6364 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6365 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6366 &phba->lpfc_vpi_blk_list, list) {
6367 list_del_init(&rsrc_blk->list);
6370 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6372 case LPFC_RSC_TYPE_FCOE_XRI:
6373 kfree(phba->sli4_hba.xri_bmask);
6374 kfree(phba->sli4_hba.xri_ids);
6375 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6376 &phba->sli4_hba.lpfc_xri_blk_list, list) {
6377 list_del_init(&rsrc_blk->list);
6381 case LPFC_RSC_TYPE_FCOE_VFI:
6382 kfree(phba->sli4_hba.vfi_bmask);
6383 kfree(phba->sli4_hba.vfi_ids);
6384 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6385 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6386 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
6387 list_del_init(&rsrc_blk->list);
6391 case LPFC_RSC_TYPE_FCOE_RPI:
6392 /* RPI bitmask and physical id array are cleaned up earlier. */
6393 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6394 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
6395 list_del_init(&rsrc_blk->list);
6403 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6406 mempool_free(mbox, phba->mbox_mem_pool);
6411 lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
6416 len = sizeof(struct lpfc_mbx_set_feature) -
6417 sizeof(struct lpfc_sli4_cfg_mhdr);
6418 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6419 LPFC_MBOX_OPCODE_SET_FEATURES, len,
6420 LPFC_SLI4_MBX_EMBED);
6423 case LPFC_SET_UE_RECOVERY:
6424 bf_set(lpfc_mbx_set_feature_UER,
6425 &mbox->u.mqe.un.set_feature, 1);
6426 mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
6427 mbox->u.mqe.un.set_feature.param_len = 8;
6429 case LPFC_SET_MDS_DIAGS:
6430 bf_set(lpfc_mbx_set_feature_mds,
6431 &mbox->u.mqe.un.set_feature, 1);
6432 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
6433 &mbox->u.mqe.un.set_feature, 1);
6434 mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
6435 mbox->u.mqe.un.set_feature.param_len = 8;
6437 case LPFC_SET_DUAL_DUMP:
6438 bf_set(lpfc_mbx_set_feature_dd,
6439 &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP);
6440 bf_set(lpfc_mbx_set_feature_ddquery,
6441 &mbox->u.mqe.un.set_feature, 0);
6442 mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP;
6443 mbox->u.mqe.un.set_feature.param_len = 4;
6451 * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
6452 * @phba: Pointer to HBA context object.
6454 * Disable FW logging into host memory on the adapter. To
6455 * be done before reading logs from the host memory.
6458 lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
6460 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6462 spin_lock_irq(&phba->hbalock);
6463 ras_fwlog->state = INACTIVE;
6464 spin_unlock_irq(&phba->hbalock);
6466 /* Disable FW logging to host memory */
6467 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
6468 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
6470 /* Wait 10ms for firmware to stop using DMA buffer */
6471 usleep_range(10 * 1000, 20 * 1000);
6475 * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
6476 * @phba: Pointer to HBA context object.
6478 * This function is called to free memory allocated for RAS FW logging
6479 * support in the driver.
6482 lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
6484 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6485 struct lpfc_dmabuf *dmabuf, *next;
6487 if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
6488 list_for_each_entry_safe(dmabuf, next,
6489 &ras_fwlog->fwlog_buff_list,
6491 list_del(&dmabuf->list);
6492 dma_free_coherent(&phba->pcidev->dev,
6493 LPFC_RAS_MAX_ENTRY_SIZE,
6494 dmabuf->virt, dmabuf->phys);
6499 if (ras_fwlog->lwpd.virt) {
6500 dma_free_coherent(&phba->pcidev->dev,
6501 sizeof(uint32_t) * 2,
6502 ras_fwlog->lwpd.virt,
6503 ras_fwlog->lwpd.phys);
6504 ras_fwlog->lwpd.virt = NULL;
6507 spin_lock_irq(&phba->hbalock);
6508 ras_fwlog->state = INACTIVE;
6509 spin_unlock_irq(&phba->hbalock);
6513 * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
6514 * @phba: Pointer to HBA context object.
6515 * @fwlog_buff_count: Count of buffers to be created.
6517 * This routine DMA memory for Log Write Position Data[LPWD] and buffer
6518 * to update FW log is posted to the adapter.
6519 * Buffer count is calculated based on module param ras_fwlog_buffsize
6520 * Size of each buffer posted to FW is 64K.
6524 lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
6525 uint32_t fwlog_buff_count)
6527 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6528 struct lpfc_dmabuf *dmabuf;
6531 /* Initialize List */
6532 INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
6534 /* Allocate memory for the LWPD */
6535 ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
6536 sizeof(uint32_t) * 2,
6537 &ras_fwlog->lwpd.phys,
6539 if (!ras_fwlog->lwpd.virt) {
6540 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6541 "6185 LWPD Memory Alloc Failed\n");
6546 ras_fwlog->fw_buffcount = fwlog_buff_count;
6547 for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
6548 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
6552 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6553 "6186 Memory Alloc failed FW logging");
6557 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6558 LPFC_RAS_MAX_ENTRY_SIZE,
6559 &dmabuf->phys, GFP_KERNEL);
6560 if (!dmabuf->virt) {
6563 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6564 "6187 DMA Alloc Failed FW logging");
6567 dmabuf->buffer_tag = i;
6568 list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
6573 lpfc_sli4_ras_dma_free(phba);
6579 * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
6580 * @phba: pointer to lpfc hba data structure.
6581 * @pmb: pointer to the driver internal queue element for mailbox command.
6583 * Completion handler for driver's RAS MBX command to the device.
6586 lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6589 union lpfc_sli4_cfg_shdr *shdr;
6590 uint32_t shdr_status, shdr_add_status;
6591 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6595 shdr = (union lpfc_sli4_cfg_shdr *)
6596 &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
6597 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6598 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6600 if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
6601 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6602 "6188 FW LOG mailbox "
6603 "completed with status x%x add_status x%x,"
6604 " mbx status x%x\n",
6605 shdr_status, shdr_add_status, mb->mbxStatus);
6607 ras_fwlog->ras_hwsupport = false;
6611 spin_lock_irq(&phba->hbalock);
6612 ras_fwlog->state = ACTIVE;
6613 spin_unlock_irq(&phba->hbalock);
6614 mempool_free(pmb, phba->mbox_mem_pool);
6619 /* Free RAS DMA memory */
6620 lpfc_sli4_ras_dma_free(phba);
6621 mempool_free(pmb, phba->mbox_mem_pool);
6625 * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
6626 * @phba: pointer to lpfc hba data structure.
6627 * @fwlog_level: Logging verbosity level.
6628 * @fwlog_enable: Enable/Disable logging.
6630 * Initialize memory and post mailbox command to enable FW logging in host
6634 lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
6635 uint32_t fwlog_level,
6636 uint32_t fwlog_enable)
6638 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6639 struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
6640 struct lpfc_dmabuf *dmabuf;
6642 uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
6645 spin_lock_irq(&phba->hbalock);
6646 ras_fwlog->state = INACTIVE;
6647 spin_unlock_irq(&phba->hbalock);
6649 fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
6650 phba->cfg_ras_fwlog_buffsize);
6651 fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
6654 * If re-enabling FW logging support use earlier allocated
6655 * DMA buffers while posting MBX command.
6657 if (!ras_fwlog->lwpd.virt) {
6658 rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
6660 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6661 "6189 FW Log Memory Allocation Failed");
6666 /* Setup Mailbox command */
6667 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6669 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6670 "6190 RAS MBX Alloc Failed");
6675 ras_fwlog->fw_loglevel = fwlog_level;
6676 len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
6677 sizeof(struct lpfc_sli4_cfg_mhdr));
6679 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
6680 LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
6681 len, LPFC_SLI4_MBX_EMBED);
6683 mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
6684 bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
6686 bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
6687 ras_fwlog->fw_loglevel);
6688 bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
6689 ras_fwlog->fw_buffcount);
6690 bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
6691 LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
6693 /* Update DMA buffer address */
6694 list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
6695 memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
6697 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
6698 putPaddrLow(dmabuf->phys);
6700 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
6701 putPaddrHigh(dmabuf->phys);
6704 /* Update LPWD address */
6705 mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
6706 mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
6708 spin_lock_irq(&phba->hbalock);
6709 ras_fwlog->state = REG_INPROGRESS;
6710 spin_unlock_irq(&phba->hbalock);
6711 mbox->vport = phba->pport;
6712 mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
6714 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6716 if (rc == MBX_NOT_FINISHED) {
6717 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6718 "6191 FW-Log Mailbox failed. "
6719 "status %d mbxStatus : x%x", rc,
6720 bf_get(lpfc_mqe_status, &mbox->u.mqe));
6721 mempool_free(mbox, phba->mbox_mem_pool);
6728 lpfc_sli4_ras_dma_free(phba);
6734 * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
6735 * @phba: Pointer to HBA context object.
6737 * Check if RAS is supported on the adapter and initialize it.
6740 lpfc_sli4_ras_setup(struct lpfc_hba *phba)
6742 /* Check RAS FW Log needs to be enabled or not */
6743 if (lpfc_check_fwlog_support(phba))
6746 lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
6747 LPFC_RAS_ENABLE_LOGGING);
6751 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
6752 * @phba: Pointer to HBA context object.
6754 * This function allocates all SLI4 resource identifiers.
6757 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
6759 int i, rc, error = 0;
6760 uint16_t count, base;
6761 unsigned long longs;
6763 if (!phba->sli4_hba.rpi_hdrs_in_use)
6764 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
6765 if (phba->sli4_hba.extents_in_use) {
6767 * The port supports resource extents. The XRI, VPI, VFI, RPI
6768 * resource extent count must be read and allocated before
6769 * provisioning the resource id arrays.
6771 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
6772 LPFC_IDX_RSRC_RDY) {
6774 * Extent-based resources are set - the driver could
6775 * be in a port reset. Figure out if any corrective
6776 * actions need to be taken.
6778 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6779 LPFC_RSC_TYPE_FCOE_VFI);
6782 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6783 LPFC_RSC_TYPE_FCOE_VPI);
6786 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6787 LPFC_RSC_TYPE_FCOE_XRI);
6790 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
6791 LPFC_RSC_TYPE_FCOE_RPI);
6796 * It's possible that the number of resources
6797 * provided to this port instance changed between
6798 * resets. Detect this condition and reallocate
6799 * resources. Otherwise, there is no action.
6802 lpfc_printf_log(phba, KERN_INFO,
6803 LOG_MBOX | LOG_INIT,
6804 "2931 Detected extent resource "
6805 "change. Reallocating all "
6807 rc = lpfc_sli4_dealloc_extent(phba,
6808 LPFC_RSC_TYPE_FCOE_VFI);
6809 rc = lpfc_sli4_dealloc_extent(phba,
6810 LPFC_RSC_TYPE_FCOE_VPI);
6811 rc = lpfc_sli4_dealloc_extent(phba,
6812 LPFC_RSC_TYPE_FCOE_XRI);
6813 rc = lpfc_sli4_dealloc_extent(phba,
6814 LPFC_RSC_TYPE_FCOE_RPI);
6819 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
6823 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
6827 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
6831 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
6834 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6839 * The port does not support resource extents. The XRI, VPI,
6840 * VFI, RPI resource ids were determined from READ_CONFIG.
6841 * Just allocate the bitmasks and provision the resource id
6842 * arrays. If a port reset is active, the resources don't
6843 * need any action - just exit.
6845 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
6846 LPFC_IDX_RSRC_RDY) {
6847 lpfc_sli4_dealloc_resource_identifiers(phba);
6848 lpfc_sli4_remove_rpis(phba);
6851 count = phba->sli4_hba.max_cfg_param.max_rpi;
6853 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6854 "3279 Invalid provisioning of "
6859 base = phba->sli4_hba.max_cfg_param.rpi_base;
6860 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6861 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6862 sizeof(unsigned long),
6864 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6868 phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
6870 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6872 goto free_rpi_bmask;
6875 for (i = 0; i < count; i++)
6876 phba->sli4_hba.rpi_ids[i] = base + i;
6879 count = phba->sli4_hba.max_cfg_param.max_vpi;
6881 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6882 "3280 Invalid provisioning of "
6887 base = phba->sli4_hba.max_cfg_param.vpi_base;
6888 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6889 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6891 if (unlikely(!phba->vpi_bmask)) {
6895 phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
6897 if (unlikely(!phba->vpi_ids)) {
6899 goto free_vpi_bmask;
6902 for (i = 0; i < count; i++)
6903 phba->vpi_ids[i] = base + i;
6906 count = phba->sli4_hba.max_cfg_param.max_xri;
6908 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6909 "3281 Invalid provisioning of "
6914 base = phba->sli4_hba.max_cfg_param.xri_base;
6915 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6916 phba->sli4_hba.xri_bmask = kcalloc(longs,
6917 sizeof(unsigned long),
6919 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6923 phba->sli4_hba.max_cfg_param.xri_used = 0;
6924 phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
6926 if (unlikely(!phba->sli4_hba.xri_ids)) {
6928 goto free_xri_bmask;
6931 for (i = 0; i < count; i++)
6932 phba->sli4_hba.xri_ids[i] = base + i;
6935 count = phba->sli4_hba.max_cfg_param.max_vfi;
6937 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6938 "3282 Invalid provisioning of "
6943 base = phba->sli4_hba.max_cfg_param.vfi_base;
6944 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
6945 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6946 sizeof(unsigned long),
6948 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6952 phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
6954 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6956 goto free_vfi_bmask;
6959 for (i = 0; i < count; i++)
6960 phba->sli4_hba.vfi_ids[i] = base + i;
6963 * Mark all resources ready. An HBA reset doesn't need
6964 * to reset the initialization.
6966 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
6972 kfree(phba->sli4_hba.vfi_bmask);
6973 phba->sli4_hba.vfi_bmask = NULL;
6975 kfree(phba->sli4_hba.xri_ids);
6976 phba->sli4_hba.xri_ids = NULL;
6978 kfree(phba->sli4_hba.xri_bmask);
6979 phba->sli4_hba.xri_bmask = NULL;
6981 kfree(phba->vpi_ids);
6982 phba->vpi_ids = NULL;
6984 kfree(phba->vpi_bmask);
6985 phba->vpi_bmask = NULL;
6987 kfree(phba->sli4_hba.rpi_ids);
6988 phba->sli4_hba.rpi_ids = NULL;
6990 kfree(phba->sli4_hba.rpi_bmask);
6991 phba->sli4_hba.rpi_bmask = NULL;
6997 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6998 * @phba: Pointer to HBA context object.
7000 * This function allocates the number of elements for the specified
7004 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
7006 if (phba->sli4_hba.extents_in_use) {
7007 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
7008 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
7009 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
7010 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
7012 kfree(phba->vpi_bmask);
7013 phba->sli4_hba.max_cfg_param.vpi_used = 0;
7014 kfree(phba->vpi_ids);
7015 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7016 kfree(phba->sli4_hba.xri_bmask);
7017 kfree(phba->sli4_hba.xri_ids);
7018 kfree(phba->sli4_hba.vfi_bmask);
7019 kfree(phba->sli4_hba.vfi_ids);
7020 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7021 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7028 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
7029 * @phba: Pointer to HBA context object.
7030 * @type: The resource extent type.
7031 * @extnt_cnt: buffer to hold port extent count response
7032 * @extnt_size: buffer to hold port extent size response.
7034 * This function calls the port to read the host allocated extents
7035 * for a particular type.
7038 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
7039 uint16_t *extnt_cnt, uint16_t *extnt_size)
7043 uint16_t curr_blks = 0;
7044 uint32_t req_len, emb_len;
7045 uint32_t alloc_len, mbox_tmo;
7046 struct list_head *blk_list_head;
7047 struct lpfc_rsrc_blks *rsrc_blk;
7049 void *virtaddr = NULL;
7050 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
7051 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
7052 union lpfc_sli4_cfg_shdr *shdr;
7055 case LPFC_RSC_TYPE_FCOE_VPI:
7056 blk_list_head = &phba->lpfc_vpi_blk_list;
7058 case LPFC_RSC_TYPE_FCOE_XRI:
7059 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
7061 case LPFC_RSC_TYPE_FCOE_VFI:
7062 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
7064 case LPFC_RSC_TYPE_FCOE_RPI:
7065 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
7071 /* Count the number of extents currently allocatd for this type. */
7072 list_for_each_entry(rsrc_blk, blk_list_head, list) {
7073 if (curr_blks == 0) {
7075 * The GET_ALLOCATED mailbox does not return the size,
7076 * just the count. The size should be just the size
7077 * stored in the current allocated block and all sizes
7078 * for an extent type are the same so set the return
7081 *extnt_size = rsrc_blk->rsrc_size;
7087 * Calculate the size of an embedded mailbox. The uint32_t
7088 * accounts for extents-specific word.
7090 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
7094 * Presume the allocation and response will fit into an embedded
7095 * mailbox. If not true, reconfigure to a non-embedded mailbox.
7097 emb = LPFC_SLI4_MBX_EMBED;
7099 if (req_len > emb_len) {
7100 req_len = curr_blks * sizeof(uint16_t) +
7101 sizeof(union lpfc_sli4_cfg_shdr) +
7103 emb = LPFC_SLI4_MBX_NEMBED;
7106 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7109 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
7111 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7112 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
7114 if (alloc_len < req_len) {
7115 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7116 "2983 Allocated DMA memory size (x%x) is "
7117 "less than the requested DMA memory "
7118 "size (x%x)\n", alloc_len, req_len);
7122 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
7128 if (!phba->sli4_hba.intr_enable)
7129 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
7131 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
7132 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
7141 * Figure out where the response is located. Then get local pointers
7142 * to the response data. The port does not guarantee to respond to
7143 * all extents counts request so update the local variable with the
7144 * allocated count from the port.
7146 if (emb == LPFC_SLI4_MBX_EMBED) {
7147 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
7148 shdr = &rsrc_ext->header.cfg_shdr;
7149 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
7151 virtaddr = mbox->sge_array->addr[0];
7152 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
7153 shdr = &n_rsrc->cfg_shdr;
7154 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
7157 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
7158 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7159 "2984 Failed to read allocated resources "
7160 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
7162 bf_get(lpfc_mbox_hdr_status, &shdr->response),
7163 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
7168 lpfc_sli4_mbox_cmd_free(phba, mbox);
7173 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
7174 * @phba: pointer to lpfc hba data structure.
7175 * @sgl_list: linked link of sgl buffers to post
7176 * @cnt: number of linked list buffers
7178 * This routine walks the list of buffers that have been allocated and
7179 * repost them to the port by using SGL block post. This is needed after a
7180 * pci_function_reset/warm_start or start. It attempts to construct blocks
7181 * of buffer sgls which contains contiguous xris and uses the non-embedded
7182 * SGL block post mailbox commands to post them to the port. For single
7183 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
7184 * mailbox command for posting.
7186 * Returns: 0 = success, non-zero failure.
7189 lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
7190 struct list_head *sgl_list, int cnt)
7192 struct lpfc_sglq *sglq_entry = NULL;
7193 struct lpfc_sglq *sglq_entry_next = NULL;
7194 struct lpfc_sglq *sglq_entry_first = NULL;
7195 int status, total_cnt;
7196 int post_cnt = 0, num_posted = 0, block_cnt = 0;
7197 int last_xritag = NO_XRI;
7198 LIST_HEAD(prep_sgl_list);
7199 LIST_HEAD(blck_sgl_list);
7200 LIST_HEAD(allc_sgl_list);
7201 LIST_HEAD(post_sgl_list);
7202 LIST_HEAD(free_sgl_list);
7204 spin_lock_irq(&phba->hbalock);
7205 spin_lock(&phba->sli4_hba.sgl_list_lock);
7206 list_splice_init(sgl_list, &allc_sgl_list);
7207 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7208 spin_unlock_irq(&phba->hbalock);
7211 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
7212 &allc_sgl_list, list) {
7213 list_del_init(&sglq_entry->list);
7215 if ((last_xritag != NO_XRI) &&
7216 (sglq_entry->sli4_xritag != last_xritag + 1)) {
7217 /* a hole in xri block, form a sgl posting block */
7218 list_splice_init(&prep_sgl_list, &blck_sgl_list);
7219 post_cnt = block_cnt - 1;
7220 /* prepare list for next posting block */
7221 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7224 /* prepare list for next posting block */
7225 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7226 /* enough sgls for non-embed sgl mbox command */
7227 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
7228 list_splice_init(&prep_sgl_list,
7230 post_cnt = block_cnt;
7236 /* keep track of last sgl's xritag */
7237 last_xritag = sglq_entry->sli4_xritag;
7239 /* end of repost sgl list condition for buffers */
7240 if (num_posted == total_cnt) {
7241 if (post_cnt == 0) {
7242 list_splice_init(&prep_sgl_list,
7244 post_cnt = block_cnt;
7245 } else if (block_cnt == 1) {
7246 status = lpfc_sli4_post_sgl(phba,
7247 sglq_entry->phys, 0,
7248 sglq_entry->sli4_xritag);
7250 /* successful, put sgl to posted list */
7251 list_add_tail(&sglq_entry->list,
7254 /* Failure, put sgl to free list */
7255 lpfc_printf_log(phba, KERN_WARNING,
7257 "3159 Failed to post "
7258 "sgl, xritag:x%x\n",
7259 sglq_entry->sli4_xritag);
7260 list_add_tail(&sglq_entry->list,
7267 /* continue until a nembed page worth of sgls */
7271 /* post the buffer list sgls as a block */
7272 status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
7276 /* success, put sgl list to posted sgl list */
7277 list_splice_init(&blck_sgl_list, &post_sgl_list);
7279 /* Failure, put sgl list to free sgl list */
7280 sglq_entry_first = list_first_entry(&blck_sgl_list,
7283 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7284 "3160 Failed to post sgl-list, "
7286 sglq_entry_first->sli4_xritag,
7287 (sglq_entry_first->sli4_xritag +
7289 list_splice_init(&blck_sgl_list, &free_sgl_list);
7290 total_cnt -= post_cnt;
7293 /* don't reset xirtag due to hole in xri block */
7295 last_xritag = NO_XRI;
7297 /* reset sgl post count for next round of posting */
7301 /* free the sgls failed to post */
7302 lpfc_free_sgl_list(phba, &free_sgl_list);
7304 /* push sgls posted to the available list */
7305 if (!list_empty(&post_sgl_list)) {
7306 spin_lock_irq(&phba->hbalock);
7307 spin_lock(&phba->sli4_hba.sgl_list_lock);
7308 list_splice_init(&post_sgl_list, sgl_list);
7309 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7310 spin_unlock_irq(&phba->hbalock);
7312 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7313 "3161 Failure to post sgl to port.\n");
7317 /* return the number of XRIs actually posted */
7322 * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
7323 * @phba: pointer to lpfc hba data structure.
7325 * This routine walks the list of nvme buffers that have been allocated and
7326 * repost them to the port by using SGL block post. This is needed after a
7327 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
7328 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
7329 * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
7331 * Returns: 0 = success, non-zero failure.
7334 lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
7336 LIST_HEAD(post_nblist);
7337 int num_posted, rc = 0;
7339 /* get all NVME buffers need to repost to a local list */
7340 lpfc_io_buf_flush(phba, &post_nblist);
7342 /* post the list of nvme buffer sgls to port if available */
7343 if (!list_empty(&post_nblist)) {
7344 num_posted = lpfc_sli4_post_io_sgl_list(
7345 phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
7346 /* failed to post any nvme buffer, return error */
7347 if (num_posted == 0)
7354 lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
7358 len = sizeof(struct lpfc_mbx_set_host_data) -
7359 sizeof(struct lpfc_sli4_cfg_mhdr);
7360 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7361 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
7362 LPFC_SLI4_MBX_EMBED);
7364 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
7365 mbox->u.mqe.un.set_host_data.param_len =
7366 LPFC_HOST_OS_DRIVER_VERSION_SIZE;
7367 snprintf(mbox->u.mqe.un.set_host_data.data,
7368 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
7369 "Linux %s v"LPFC_DRIVER_VERSION,
7370 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
7374 lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7375 struct lpfc_queue *drq, int count, int idx)
7378 struct lpfc_rqe hrqe;
7379 struct lpfc_rqe drqe;
7380 struct lpfc_rqb *rqbp;
7381 unsigned long flags;
7382 struct rqb_dmabuf *rqb_buffer;
7383 LIST_HEAD(rqb_buf_list);
7386 for (i = 0; i < count; i++) {
7387 spin_lock_irqsave(&phba->hbalock, flags);
7388 /* IF RQ is already full, don't bother */
7389 if (rqbp->buffer_count + i >= rqbp->entry_count - 1) {
7390 spin_unlock_irqrestore(&phba->hbalock, flags);
7393 spin_unlock_irqrestore(&phba->hbalock, flags);
7395 rqb_buffer = rqbp->rqb_alloc_buffer(phba);
7398 rqb_buffer->hrq = hrq;
7399 rqb_buffer->drq = drq;
7400 rqb_buffer->idx = idx;
7401 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7404 spin_lock_irqsave(&phba->hbalock, flags);
7405 while (!list_empty(&rqb_buf_list)) {
7406 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7409 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7410 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7411 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7412 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7413 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7415 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7416 "6421 Cannot post to HRQ %d: %x %x %x "
7424 rqbp->rqb_free_buffer(phba, rqb_buffer);
7426 list_add_tail(&rqb_buffer->hbuf.list,
7427 &rqbp->rqb_buffer_list);
7428 rqbp->buffer_count++;
7431 spin_unlock_irqrestore(&phba->hbalock, flags);
7436 * lpfc_init_idle_stat_hb - Initialize idle_stat tracking
7437 * @phba: pointer to lpfc hba data structure.
7439 * This routine initializes the per-cq idle_stat to dynamically dictate
7440 * polling decisions.
7445 static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba)
7448 struct lpfc_sli4_hdw_queue *hdwq;
7449 struct lpfc_queue *cq;
7450 struct lpfc_idle_stat *idle_stat;
7453 for_each_present_cpu(i) {
7454 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
7457 /* Skip if we've already handled this cq's primary CPU */
7461 idle_stat = &phba->sli4_hba.idle_stat[i];
7463 idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1);
7464 idle_stat->prev_wall = wall;
7466 if (phba->nvmet_support)
7467 cq->poll_mode = LPFC_QUEUE_WORK;
7469 cq->poll_mode = LPFC_IRQ_POLL;
7472 if (!phba->nvmet_support)
7473 schedule_delayed_work(&phba->idle_stat_delay_work,
7474 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
7477 static void lpfc_sli4_dip(struct lpfc_hba *phba)
7481 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7482 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 ||
7483 if_type == LPFC_SLI_INTF_IF_TYPE_6) {
7484 struct lpfc_register reg_data;
7486 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7490 if (bf_get(lpfc_sliport_status_dip, ®_data))
7491 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7492 "2904 Firmware Dump Image Present"
7498 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
7499 * @phba: Pointer to HBA context object.
7501 * This function is the main SLI4 device initialization PCI function. This
7502 * function is called by the HBA initialization code, HBA reset code and
7503 * HBA error attention handler code. Caller is not required to hold any
7507 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
7509 int rc, i, cnt, len, dd;
7510 LPFC_MBOXQ_t *mboxq;
7511 struct lpfc_mqe *mqe;
7514 uint32_t ftr_rsp = 0;
7515 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
7516 struct lpfc_vport *vport = phba->pport;
7517 struct lpfc_dmabuf *mp;
7518 struct lpfc_rqb *rqbp;
7520 /* Perform a PCI function reset to start from clean */
7521 rc = lpfc_pci_function_reset(phba);
7525 /* Check the HBA Host Status Register for readyness */
7526 rc = lpfc_sli4_post_status_check(phba);
7530 spin_lock_irq(&phba->hbalock);
7531 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
7532 spin_unlock_irq(&phba->hbalock);
7535 lpfc_sli4_dip(phba);
7538 * Allocate a single mailbox container for initializing the
7541 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7545 /* Issue READ_REV to collect vpd and FW information. */
7546 vpd_size = SLI4_PAGE_SIZE;
7547 vpd = kzalloc(vpd_size, GFP_KERNEL);
7553 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
7559 mqe = &mboxq->u.mqe;
7560 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
7561 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
7562 phba->hba_flag |= HBA_FCOE_MODE;
7563 phba->fcp_embed_io = 0; /* SLI4 FC support only */
7565 phba->hba_flag &= ~HBA_FCOE_MODE;
7568 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
7570 phba->hba_flag |= HBA_FIP_SUPPORT;
7572 phba->hba_flag &= ~HBA_FIP_SUPPORT;
7574 phba->hba_flag &= ~HBA_IOQ_FLUSH;
7576 if (phba->sli_rev != LPFC_SLI_REV4) {
7577 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7578 "0376 READ_REV Error. SLI Level %d "
7579 "FCoE enabled %d\n",
7580 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
7587 * Continue initialization with default values even if driver failed
7588 * to read FCoE param config regions, only read parameters if the
7591 if (phba->hba_flag & HBA_FCOE_MODE &&
7592 lpfc_sli4_read_fcoe_params(phba))
7593 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
7594 "2570 Failed to read FCoE parameters\n");
7597 * Retrieve sli4 device physical port name, failure of doing it
7598 * is considered as non-fatal.
7600 rc = lpfc_sli4_retrieve_pport_name(phba);
7602 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7603 "3080 Successful retrieving SLI4 device "
7604 "physical port name: %s.\n", phba->Port);
7606 rc = lpfc_sli4_get_ctl_attr(phba);
7608 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7609 "8351 Successful retrieving SLI4 device "
7613 * Evaluate the read rev and vpd data. Populate the driver
7614 * state with the results. If this routine fails, the failure
7615 * is not fatal as the driver will use generic values.
7617 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
7618 if (unlikely(!rc)) {
7619 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7620 "0377 Error %d parsing vpd. "
7621 "Using defaults.\n", rc);
7626 /* Save information as VPD data */
7627 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
7628 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
7631 * This is because first G7 ASIC doesn't support the standard
7632 * 0x5a NVME cmd descriptor type/subtype
7634 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7635 LPFC_SLI_INTF_IF_TYPE_6) &&
7636 (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
7637 (phba->vpd.rev.smRev == 0) &&
7638 (phba->cfg_nvme_embed_cmd == 1))
7639 phba->cfg_nvme_embed_cmd = 0;
7641 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
7642 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
7644 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
7646 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
7648 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
7650 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
7651 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
7652 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
7653 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
7654 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
7655 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
7656 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
7657 "(%d):0380 READ_REV Status x%x "
7658 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
7659 mboxq->vport ? mboxq->vport->vpi : 0,
7660 bf_get(lpfc_mqe_status, mqe),
7661 phba->vpd.rev.opFwName,
7662 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
7663 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
7665 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7666 LPFC_SLI_INTF_IF_TYPE_0) {
7667 lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
7668 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7669 if (rc == MBX_SUCCESS) {
7670 phba->hba_flag |= HBA_RECOVERABLE_UE;
7671 /* Set 1Sec interval to detect UE */
7672 phba->eratt_poll_interval = 1;
7673 phba->sli4_hba.ue_to_sr = bf_get(
7674 lpfc_mbx_set_feature_UESR,
7675 &mboxq->u.mqe.un.set_feature);
7676 phba->sli4_hba.ue_to_rp = bf_get(
7677 lpfc_mbx_set_feature_UERP,
7678 &mboxq->u.mqe.un.set_feature);
7682 if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
7683 /* Enable MDS Diagnostics only if the SLI Port supports it */
7684 lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
7685 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7686 if (rc != MBX_SUCCESS)
7687 phba->mds_diags_support = 0;
7691 * Discover the port's supported feature set and match it against the
7694 lpfc_request_features(phba, mboxq);
7695 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7702 * The port must support FCP initiator mode as this is the
7703 * only mode running in the host.
7705 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
7706 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7707 "0378 No support for fcpi mode.\n");
7711 /* Performance Hints are ONLY for FCoE */
7712 if (phba->hba_flag & HBA_FCOE_MODE) {
7713 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
7714 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
7716 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
7720 * If the port cannot support the host's requested features
7721 * then turn off the global config parameters to disable the
7722 * feature in the driver. This is not a fatal error.
7724 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
7725 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
7726 phba->cfg_enable_bg = 0;
7727 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
7732 if (phba->max_vpi && phba->cfg_enable_npiv &&
7733 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
7737 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7738 "0379 Feature Mismatch Data: x%08x %08x "
7739 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
7740 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
7741 phba->cfg_enable_npiv, phba->max_vpi);
7742 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
7743 phba->cfg_enable_bg = 0;
7744 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
7745 phba->cfg_enable_npiv = 0;
7748 /* These SLI3 features are assumed in SLI4 */
7749 spin_lock_irq(&phba->hbalock);
7750 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
7751 spin_unlock_irq(&phba->hbalock);
7753 /* Always try to enable dual dump feature if we can */
7754 lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP);
7755 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7756 dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature);
7757 if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP))
7758 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7759 "6448 Dual Dump is enabled\n");
7761 lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT,
7762 "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, "
7764 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7765 lpfc_sli_config_mbox_subsys_get(
7767 lpfc_sli_config_mbox_opcode_get(
7771 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
7772 * calls depends on these resources to complete port setup.
7774 rc = lpfc_sli4_alloc_resource_identifiers(phba);
7776 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7777 "2920 Failed to alloc Resource IDs "
7782 lpfc_set_host_data(phba, mboxq);
7784 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7786 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
7787 "2134 Failed to set host os driver version %x",
7791 /* Read the port's service parameters. */
7792 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
7794 phba->link_state = LPFC_HBA_ERROR;
7799 mboxq->vport = vport;
7800 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7801 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
7802 if (rc == MBX_SUCCESS) {
7803 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
7808 * This memory was allocated by the lpfc_read_sparam routine. Release
7809 * it to the mbuf pool.
7811 lpfc_mbuf_free(phba, mp->virt, mp->phys);
7813 mboxq->ctx_buf = NULL;
7815 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7816 "0382 READ_SPARAM command failed "
7817 "status %d, mbxStatus x%x\n",
7818 rc, bf_get(lpfc_mqe_status, mqe));
7819 phba->link_state = LPFC_HBA_ERROR;
7824 lpfc_update_vport_wwn(vport);
7826 /* Update the fc_host data structures with new wwn. */
7827 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
7828 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
7830 /* Create all the SLI4 queues */
7831 rc = lpfc_sli4_queue_create(phba);
7833 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7834 "3089 Failed to allocate queues\n");
7838 /* Set up all the queues to the device */
7839 rc = lpfc_sli4_queue_setup(phba);
7841 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7842 "0381 Error %d during queue setup.\n ", rc);
7843 goto out_stop_timers;
7845 /* Initialize the driver internal SLI layer lists. */
7846 lpfc_sli4_setup(phba);
7847 lpfc_sli4_queue_init(phba);
7849 /* update host els xri-sgl sizes and mappings */
7850 rc = lpfc_sli4_els_sgl_update(phba);
7852 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7853 "1400 Failed to update xri-sgl size and "
7854 "mapping: %d\n", rc);
7855 goto out_destroy_queue;
7858 /* register the els sgl pool to the port */
7859 rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
7860 phba->sli4_hba.els_xri_cnt);
7861 if (unlikely(rc < 0)) {
7862 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7863 "0582 Error %d during els sgl post "
7866 goto out_destroy_queue;
7868 phba->sli4_hba.els_xri_cnt = rc;
7870 if (phba->nvmet_support) {
7871 /* update host nvmet xri-sgl sizes and mappings */
7872 rc = lpfc_sli4_nvmet_sgl_update(phba);
7874 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7875 "6308 Failed to update nvmet-sgl size "
7876 "and mapping: %d\n", rc);
7877 goto out_destroy_queue;
7880 /* register the nvmet sgl pool to the port */
7881 rc = lpfc_sli4_repost_sgl_list(
7883 &phba->sli4_hba.lpfc_nvmet_sgl_list,
7884 phba->sli4_hba.nvmet_xri_cnt);
7885 if (unlikely(rc < 0)) {
7886 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7887 "3117 Error %d during nvmet "
7890 goto out_destroy_queue;
7892 phba->sli4_hba.nvmet_xri_cnt = rc;
7894 /* We allocate an iocbq for every receive context SGL.
7895 * The additional allocation is for abort and ls handling.
7897 cnt = phba->sli4_hba.nvmet_xri_cnt +
7898 phba->sli4_hba.max_cfg_param.max_xri;
7900 /* update host common xri-sgl sizes and mappings */
7901 rc = lpfc_sli4_io_sgl_update(phba);
7903 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7904 "6082 Failed to update nvme-sgl size "
7905 "and mapping: %d\n", rc);
7906 goto out_destroy_queue;
7909 /* register the allocated common sgl pool to the port */
7910 rc = lpfc_sli4_repost_io_sgl_list(phba);
7912 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7913 "6116 Error %d during nvme sgl post "
7915 /* Some NVME buffers were moved to abort nvme list */
7916 /* A pci function reset will repost them */
7918 goto out_destroy_queue;
7920 /* Each lpfc_io_buf job structure has an iocbq element.
7921 * This cnt provides for abort, els, ct and ls requests.
7923 cnt = phba->sli4_hba.max_cfg_param.max_xri;
7926 if (!phba->sli.iocbq_lookup) {
7927 /* Initialize and populate the iocb list per host */
7928 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7929 "2821 initialize iocb list with %d entries\n",
7931 rc = lpfc_init_iocb_list(phba, cnt);
7933 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7934 "1413 Failed to init iocb list.\n");
7935 goto out_destroy_queue;
7939 if (phba->nvmet_support)
7940 lpfc_nvmet_create_targetport(phba);
7942 if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
7943 /* Post initial buffers to all RQs created */
7944 for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
7945 rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
7946 INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
7947 rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
7948 rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
7949 rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
7950 rqbp->buffer_count = 0;
7952 lpfc_post_rq_buffer(
7953 phba, phba->sli4_hba.nvmet_mrq_hdr[i],
7954 phba->sli4_hba.nvmet_mrq_data[i],
7955 phba->cfg_nvmet_mrq_post, i);
7959 /* Post the rpi header region to the device. */
7960 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
7962 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7963 "0393 Error %d during rpi post operation\n",
7966 goto out_destroy_queue;
7968 lpfc_sli4_node_prep(phba);
7970 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
7971 if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
7973 * The FC Port needs to register FCFI (index 0)
7975 lpfc_reg_fcfi(phba, mboxq);
7976 mboxq->vport = phba->pport;
7977 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7978 if (rc != MBX_SUCCESS)
7979 goto out_unset_queue;
7981 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
7982 &mboxq->u.mqe.un.reg_fcfi);
7984 /* We are a NVME Target mode with MRQ > 1 */
7986 /* First register the FCFI */
7987 lpfc_reg_fcfi_mrq(phba, mboxq, 0);
7988 mboxq->vport = phba->pport;
7989 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7990 if (rc != MBX_SUCCESS)
7991 goto out_unset_queue;
7993 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
7994 &mboxq->u.mqe.un.reg_fcfi_mrq);
7996 /* Next register the MRQs */
7997 lpfc_reg_fcfi_mrq(phba, mboxq, 1);
7998 mboxq->vport = phba->pport;
7999 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8000 if (rc != MBX_SUCCESS)
8001 goto out_unset_queue;
8004 /* Check if the port is configured to be disabled */
8005 lpfc_sli_read_link_ste(phba);
8008 /* Don't post more new bufs if repost already recovered
8011 if (phba->nvmet_support == 0) {
8012 if (phba->sli4_hba.io_xri_cnt == 0) {
8013 len = lpfc_new_io_buf(
8014 phba, phba->sli4_hba.io_xri_max);
8017 goto out_unset_queue;
8020 if (phba->cfg_xri_rebalancing)
8021 lpfc_create_multixri_pools(phba);
8024 phba->cfg_xri_rebalancing = 0;
8027 /* Allow asynchronous mailbox command to go through */
8028 spin_lock_irq(&phba->hbalock);
8029 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8030 spin_unlock_irq(&phba->hbalock);
8032 /* Post receive buffers to the device */
8033 lpfc_sli4_rb_setup(phba);
8035 /* Reset HBA FCF states after HBA reset */
8036 phba->fcf.fcf_flag = 0;
8037 phba->fcf.current_rec.flag = 0;
8039 /* Start the ELS watchdog timer */
8040 mod_timer(&vport->els_tmofunc,
8041 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
8043 /* Start heart beat timer */
8044 mod_timer(&phba->hb_tmofunc,
8045 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
8046 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
8047 phba->last_completion_time = jiffies;
8049 /* start eq_delay heartbeat */
8050 if (phba->cfg_auto_imax)
8051 queue_delayed_work(phba->wq, &phba->eq_delay_work,
8052 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
8054 /* start per phba idle_stat_delay heartbeat */
8055 lpfc_init_idle_stat_hb(phba);
8057 /* Start error attention (ERATT) polling timer */
8058 mod_timer(&phba->eratt_poll,
8059 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
8061 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
8062 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
8063 rc = pci_enable_pcie_error_reporting(phba->pcidev);
8065 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8066 "2829 This device supports "
8067 "Advanced Error Reporting (AER)\n");
8068 spin_lock_irq(&phba->hbalock);
8069 phba->hba_flag |= HBA_AER_ENABLED;
8070 spin_unlock_irq(&phba->hbalock);
8072 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8073 "2830 This device does not support "
8074 "Advanced Error Reporting (AER)\n");
8075 phba->cfg_aer_support = 0;
8081 * The port is ready, set the host's link state to LINK_DOWN
8082 * in preparation for link interrupts.
8084 spin_lock_irq(&phba->hbalock);
8085 phba->link_state = LPFC_LINK_DOWN;
8087 /* Check if physical ports are trunked */
8088 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
8089 phba->trunk_link.link0.state = LPFC_LINK_DOWN;
8090 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
8091 phba->trunk_link.link1.state = LPFC_LINK_DOWN;
8092 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
8093 phba->trunk_link.link2.state = LPFC_LINK_DOWN;
8094 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
8095 phba->trunk_link.link3.state = LPFC_LINK_DOWN;
8096 spin_unlock_irq(&phba->hbalock);
8098 /* Arm the CQs and then EQs on device */
8099 lpfc_sli4_arm_cqeq_intr(phba);
8101 /* Indicate device interrupt mode */
8102 phba->sli4_hba.intr_enable = 1;
8104 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
8105 (phba->hba_flag & LINK_DISABLED)) {
8106 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8107 "3103 Adapter Link is disabled.\n");
8108 lpfc_down_link(phba, mboxq);
8109 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8110 if (rc != MBX_SUCCESS) {
8111 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8112 "3104 Adapter failed to issue "
8113 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
8114 goto out_io_buff_free;
8116 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
8117 /* don't perform init_link on SLI4 FC port loopback test */
8118 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
8119 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
8121 goto out_io_buff_free;
8124 mempool_free(mboxq, phba->mbox_mem_pool);
8127 /* Free allocated IO Buffers */
8130 /* Unset all the queues set up in this routine when error out */
8131 lpfc_sli4_queue_unset(phba);
8133 lpfc_free_iocb_list(phba);
8134 lpfc_sli4_queue_destroy(phba);
8136 lpfc_stop_hba_timers(phba);
8138 mempool_free(mboxq, phba->mbox_mem_pool);
8143 * lpfc_mbox_timeout - Timeout call back function for mbox timer
8144 * @t: Context to fetch pointer to hba structure from.
8146 * This is the callback function for mailbox timer. The mailbox
8147 * timer is armed when a new mailbox command is issued and the timer
8148 * is deleted when the mailbox complete. The function is called by
8149 * the kernel timer code when a mailbox does not complete within
8150 * expected time. This function wakes up the worker thread to
8151 * process the mailbox timeout and returns. All the processing is
8152 * done by the worker thread function lpfc_mbox_timeout_handler.
8155 lpfc_mbox_timeout(struct timer_list *t)
8157 struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo);
8158 unsigned long iflag;
8159 uint32_t tmo_posted;
8161 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
8162 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
8164 phba->pport->work_port_events |= WORKER_MBOX_TMO;
8165 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
8168 lpfc_worker_wake_up(phba);
8173 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
8175 * @phba: Pointer to HBA context object.
8177 * This function checks if any mailbox completions are present on the mailbox
8181 lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
8185 struct lpfc_queue *mcq;
8186 struct lpfc_mcqe *mcqe;
8187 bool pending_completions = false;
8190 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
8193 /* Check for completions on mailbox completion queue */
8195 mcq = phba->sli4_hba.mbx_cq;
8196 idx = mcq->hba_index;
8197 qe_valid = mcq->qe_valid;
8198 while (bf_get_le32(lpfc_cqe_valid,
8199 (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
8200 mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
8201 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
8202 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
8203 pending_completions = true;
8206 idx = (idx + 1) % mcq->entry_count;
8207 if (mcq->hba_index == idx)
8210 /* if the index wrapped around, toggle the valid bit */
8211 if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
8212 qe_valid = (qe_valid) ? 0 : 1;
8214 return pending_completions;
8219 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
8221 * @phba: Pointer to HBA context object.
8223 * For sli4, it is possible to miss an interrupt. As such mbox completions
8224 * maybe missed causing erroneous mailbox timeouts to occur. This function
8225 * checks to see if mbox completions are on the mailbox completion queue
8226 * and will process all the completions associated with the eq for the
8227 * mailbox completion queue.
8230 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
8232 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
8234 struct lpfc_queue *fpeq = NULL;
8235 struct lpfc_queue *eq;
8238 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
8241 /* Find the EQ associated with the mbox CQ */
8242 if (sli4_hba->hdwq) {
8243 for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
8244 eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
8245 if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
8254 /* Turn off interrupts from this EQ */
8256 sli4_hba->sli4_eq_clr_intr(fpeq);
8258 /* Check to see if a mbox completion is pending */
8260 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
8263 * If a mbox completion is pending, process all the events on EQ
8264 * associated with the mbox completion queue (this could include
8265 * mailbox commands, async events, els commands, receive queue data
8270 /* process and rearm the EQ */
8271 lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
8273 /* Always clear and re-arm the EQ */
8274 sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
8276 return mbox_pending;
8281 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
8282 * @phba: Pointer to HBA context object.
8284 * This function is called from worker thread when a mailbox command times out.
8285 * The caller is not required to hold any locks. This function will reset the
8286 * HBA and recover all the pending commands.
8289 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
8291 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
8292 MAILBOX_t *mb = NULL;
8294 struct lpfc_sli *psli = &phba->sli;
8296 /* If the mailbox completed, process the completion */
8297 lpfc_sli4_process_missed_mbox_completions(phba);
8299 if (!(psli->sli_flag & LPFC_SLI_ACTIVE))
8304 /* Check the pmbox pointer first. There is a race condition
8305 * between the mbox timeout handler getting executed in the
8306 * worklist and the mailbox actually completing. When this
8307 * race condition occurs, the mbox_active will be NULL.
8309 spin_lock_irq(&phba->hbalock);
8310 if (pmbox == NULL) {
8311 lpfc_printf_log(phba, KERN_WARNING,
8313 "0353 Active Mailbox cleared - mailbox timeout "
8315 spin_unlock_irq(&phba->hbalock);
8319 /* Mbox cmd <mbxCommand> timeout */
8320 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8321 "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
8323 phba->pport->port_state,
8325 phba->sli.mbox_active);
8326 spin_unlock_irq(&phba->hbalock);
8328 /* Setting state unknown so lpfc_sli_abort_iocb_ring
8329 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
8330 * it to fail all outstanding SCSI IO.
8332 spin_lock_irq(&phba->pport->work_port_lock);
8333 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
8334 spin_unlock_irq(&phba->pport->work_port_lock);
8335 spin_lock_irq(&phba->hbalock);
8336 phba->link_state = LPFC_LINK_UNKNOWN;
8337 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
8338 spin_unlock_irq(&phba->hbalock);
8340 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8341 "0345 Resetting board due to mailbox timeout\n");
8343 /* Reset the HBA device */
8344 lpfc_reset_hba(phba);
8348 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
8349 * @phba: Pointer to HBA context object.
8350 * @pmbox: Pointer to mailbox object.
8351 * @flag: Flag indicating how the mailbox need to be processed.
8353 * This function is called by discovery code and HBA management code
8354 * to submit a mailbox command to firmware with SLI-3 interface spec. This
8355 * function gets the hbalock to protect the data structures.
8356 * The mailbox command can be submitted in polling mode, in which case
8357 * this function will wait in a polling loop for the completion of the
8359 * If the mailbox is submitted in no_wait mode (not polling) the
8360 * function will submit the command and returns immediately without waiting
8361 * for the mailbox completion. The no_wait is supported only when HBA
8362 * is in SLI2/SLI3 mode - interrupts are enabled.
8363 * The SLI interface allows only one mailbox pending at a time. If the
8364 * mailbox is issued in polling mode and there is already a mailbox
8365 * pending, then the function will return an error. If the mailbox is issued
8366 * in NO_WAIT mode and there is a mailbox pending already, the function
8367 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
8368 * The sli layer owns the mailbox object until the completion of mailbox
8369 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
8370 * return codes the caller owns the mailbox command after the return of
8374 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
8378 struct lpfc_sli *psli = &phba->sli;
8379 uint32_t status, evtctr;
8380 uint32_t ha_copy, hc_copy;
8382 unsigned long timeout;
8383 unsigned long drvr_flag = 0;
8384 uint32_t word0, ldata;
8385 void __iomem *to_slim;
8386 int processing_queue = 0;
8388 spin_lock_irqsave(&phba->hbalock, drvr_flag);
8390 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8391 /* processing mbox queue from intr_handler */
8392 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8393 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8396 processing_queue = 1;
8397 pmbox = lpfc_mbox_get(phba);
8399 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8404 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
8405 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
8407 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8408 lpfc_printf_log(phba, KERN_ERR,
8409 LOG_MBOX | LOG_VPORT,
8410 "1806 Mbox x%x failed. No vport\n",
8411 pmbox->u.mb.mbxCommand);
8413 goto out_not_finished;
8417 /* If the PCI channel is in offline state, do not post mbox. */
8418 if (unlikely(pci_channel_offline(phba->pcidev))) {
8419 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8420 goto out_not_finished;
8423 /* If HBA has a deferred error attention, fail the iocb. */
8424 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
8425 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8426 goto out_not_finished;
8432 status = MBX_SUCCESS;
8434 if (phba->link_state == LPFC_HBA_ERROR) {
8435 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8437 /* Mbox command <mbxCommand> cannot issue */
8438 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8439 "(%d):0311 Mailbox command x%x cannot "
8440 "issue Data: x%x x%x\n",
8441 pmbox->vport ? pmbox->vport->vpi : 0,
8442 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
8443 goto out_not_finished;
8446 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
8447 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
8448 !(hc_copy & HC_MBINT_ENA)) {
8449 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8450 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8451 "(%d):2528 Mailbox command x%x cannot "
8452 "issue Data: x%x x%x\n",
8453 pmbox->vport ? pmbox->vport->vpi : 0,
8454 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
8455 goto out_not_finished;
8459 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8460 /* Polling for a mbox command when another one is already active
8461 * is not allowed in SLI. Also, the driver must have established
8462 * SLI2 mode to queue and process multiple mbox commands.
8465 if (flag & MBX_POLL) {
8466 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8468 /* Mbox command <mbxCommand> cannot issue */
8469 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8470 "(%d):2529 Mailbox command x%x "
8471 "cannot issue Data: x%x x%x\n",
8472 pmbox->vport ? pmbox->vport->vpi : 0,
8473 pmbox->u.mb.mbxCommand,
8474 psli->sli_flag, flag);
8475 goto out_not_finished;
8478 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
8479 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8480 /* Mbox command <mbxCommand> cannot issue */
8481 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8482 "(%d):2530 Mailbox command x%x "
8483 "cannot issue Data: x%x x%x\n",
8484 pmbox->vport ? pmbox->vport->vpi : 0,
8485 pmbox->u.mb.mbxCommand,
8486 psli->sli_flag, flag);
8487 goto out_not_finished;
8490 /* Another mailbox command is still being processed, queue this
8491 * command to be processed later.
8493 lpfc_mbox_put(phba, pmbox);
8495 /* Mbox cmd issue - BUSY */
8496 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8497 "(%d):0308 Mbox cmd issue - BUSY Data: "
8498 "x%x x%x x%x x%x\n",
8499 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
8501 phba->pport ? phba->pport->port_state : 0xff,
8502 psli->sli_flag, flag);
8504 psli->slistat.mbox_busy++;
8505 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8508 lpfc_debugfs_disc_trc(pmbox->vport,
8509 LPFC_DISC_TRC_MBOX_VPORT,
8510 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
8511 (uint32_t)mbx->mbxCommand,
8512 mbx->un.varWords[0], mbx->un.varWords[1]);
8515 lpfc_debugfs_disc_trc(phba->pport,
8517 "MBOX Bsy: cmd:x%x mb:x%x x%x",
8518 (uint32_t)mbx->mbxCommand,
8519 mbx->un.varWords[0], mbx->un.varWords[1]);
8525 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8527 /* If we are not polling, we MUST be in SLI2 mode */
8528 if (flag != MBX_POLL) {
8529 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
8530 (mbx->mbxCommand != MBX_KILL_BOARD)) {
8531 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8532 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8533 /* Mbox command <mbxCommand> cannot issue */
8534 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8535 "(%d):2531 Mailbox command x%x "
8536 "cannot issue Data: x%x x%x\n",
8537 pmbox->vport ? pmbox->vport->vpi : 0,
8538 pmbox->u.mb.mbxCommand,
8539 psli->sli_flag, flag);
8540 goto out_not_finished;
8542 /* timeout active mbox command */
8543 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
8545 mod_timer(&psli->mbox_tmo, jiffies + timeout);
8548 /* Mailbox cmd <cmd> issue */
8549 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8550 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
8552 pmbox->vport ? pmbox->vport->vpi : 0,
8554 phba->pport ? phba->pport->port_state : 0xff,
8555 psli->sli_flag, flag);
8557 if (mbx->mbxCommand != MBX_HEARTBEAT) {
8559 lpfc_debugfs_disc_trc(pmbox->vport,
8560 LPFC_DISC_TRC_MBOX_VPORT,
8561 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8562 (uint32_t)mbx->mbxCommand,
8563 mbx->un.varWords[0], mbx->un.varWords[1]);
8566 lpfc_debugfs_disc_trc(phba->pport,
8568 "MBOX Send: cmd:x%x mb:x%x x%x",
8569 (uint32_t)mbx->mbxCommand,
8570 mbx->un.varWords[0], mbx->un.varWords[1]);
8574 psli->slistat.mbox_cmd++;
8575 evtctr = psli->slistat.mbox_event;
8577 /* next set own bit for the adapter and copy over command word */
8578 mbx->mbxOwner = OWN_CHIP;
8580 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8581 /* Populate mbox extension offset word. */
8582 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
8583 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
8584 = (uint8_t *)phba->mbox_ext
8585 - (uint8_t *)phba->mbox;
8588 /* Copy the mailbox extension data */
8589 if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
8590 lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
8591 (uint8_t *)phba->mbox_ext,
8592 pmbox->in_ext_byte_len);
8594 /* Copy command data to host SLIM area */
8595 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
8597 /* Populate mbox extension offset word. */
8598 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
8599 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
8600 = MAILBOX_HBA_EXT_OFFSET;
8602 /* Copy the mailbox extension data */
8603 if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
8604 lpfc_memcpy_to_slim(phba->MBslimaddr +
8605 MAILBOX_HBA_EXT_OFFSET,
8606 pmbox->ctx_buf, pmbox->in_ext_byte_len);
8608 if (mbx->mbxCommand == MBX_CONFIG_PORT)
8609 /* copy command data into host mbox for cmpl */
8610 lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
8613 /* First copy mbox command data to HBA SLIM, skip past first
8615 to_slim = phba->MBslimaddr + sizeof (uint32_t);
8616 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
8617 MAILBOX_CMD_SIZE - sizeof (uint32_t));
8619 /* Next copy over first word, with mbxOwner set */
8620 ldata = *((uint32_t *)mbx);
8621 to_slim = phba->MBslimaddr;
8622 writel(ldata, to_slim);
8623 readl(to_slim); /* flush */
8625 if (mbx->mbxCommand == MBX_CONFIG_PORT)
8626 /* switch over to host mailbox */
8627 psli->sli_flag |= LPFC_SLI_ACTIVE;
8634 /* Set up reference to mailbox command */
8635 psli->mbox_active = pmbox;
8636 /* Interrupt board to do it */
8637 writel(CA_MBATT, phba->CAregaddr);
8638 readl(phba->CAregaddr); /* flush */
8639 /* Don't wait for it to finish, just return */
8643 /* Set up null reference to mailbox command */
8644 psli->mbox_active = NULL;
8645 /* Interrupt board to do it */
8646 writel(CA_MBATT, phba->CAregaddr);
8647 readl(phba->CAregaddr); /* flush */
8649 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8650 /* First read mbox status word */
8651 word0 = *((uint32_t *)phba->mbox);
8652 word0 = le32_to_cpu(word0);
8654 /* First read mbox status word */
8655 if (lpfc_readl(phba->MBslimaddr, &word0)) {
8656 spin_unlock_irqrestore(&phba->hbalock,
8658 goto out_not_finished;
8662 /* Read the HBA Host Attention Register */
8663 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
8664 spin_unlock_irqrestore(&phba->hbalock,
8666 goto out_not_finished;
8668 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
8671 /* Wait for command to complete */
8672 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
8673 (!(ha_copy & HA_MBATT) &&
8674 (phba->link_state > LPFC_WARM_START))) {
8675 if (time_after(jiffies, timeout)) {
8676 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8677 spin_unlock_irqrestore(&phba->hbalock,
8679 goto out_not_finished;
8682 /* Check if we took a mbox interrupt while we were
8684 if (((word0 & OWN_CHIP) != OWN_CHIP)
8685 && (evtctr != psli->slistat.mbox_event))
8689 spin_unlock_irqrestore(&phba->hbalock,
8692 spin_lock_irqsave(&phba->hbalock, drvr_flag);
8695 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8696 /* First copy command data */
8697 word0 = *((uint32_t *)phba->mbox);
8698 word0 = le32_to_cpu(word0);
8699 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
8702 /* Check real SLIM for any errors */
8703 slimword0 = readl(phba->MBslimaddr);
8704 slimmb = (MAILBOX_t *) & slimword0;
8705 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
8706 && slimmb->mbxStatus) {
8713 /* First copy command data */
8714 word0 = readl(phba->MBslimaddr);
8716 /* Read the HBA Host Attention Register */
8717 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
8718 spin_unlock_irqrestore(&phba->hbalock,
8720 goto out_not_finished;
8724 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
8725 /* copy results back to user */
8726 lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
8728 /* Copy the mailbox extension data */
8729 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
8730 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
8732 pmbox->out_ext_byte_len);
8735 /* First copy command data */
8736 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
8738 /* Copy the mailbox extension data */
8739 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
8740 lpfc_memcpy_from_slim(
8743 MAILBOX_HBA_EXT_OFFSET,
8744 pmbox->out_ext_byte_len);
8748 writel(HA_MBATT, phba->HAregaddr);
8749 readl(phba->HAregaddr); /* flush */
8751 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
8752 status = mbx->mbxStatus;
8755 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
8759 if (processing_queue) {
8760 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
8761 lpfc_mbox_cmpl_put(phba, pmbox);
8763 return MBX_NOT_FINISHED;
8767 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
8768 * @phba: Pointer to HBA context object.
8770 * The function blocks the posting of SLI4 asynchronous mailbox commands from
8771 * the driver internal pending mailbox queue. It will then try to wait out the
8772 * possible outstanding mailbox command before return.
8775 * 0 - the outstanding mailbox command completed; otherwise, the wait for
8776 * the outstanding mailbox command timed out.
8779 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
8781 struct lpfc_sli *psli = &phba->sli;
8783 unsigned long timeout = 0;
8785 /* Mark the asynchronous mailbox command posting as blocked */
8786 spin_lock_irq(&phba->hbalock);
8787 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
8788 /* Determine how long we might wait for the active mailbox
8789 * command to be gracefully completed by firmware.
8791 if (phba->sli.mbox_active)
8792 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
8793 phba->sli.mbox_active) *
8795 spin_unlock_irq(&phba->hbalock);
8797 /* Make sure the mailbox is really active */
8799 lpfc_sli4_process_missed_mbox_completions(phba);
8801 /* Wait for the outstnading mailbox command to complete */
8802 while (phba->sli.mbox_active) {
8803 /* Check active mailbox complete status every 2ms */
8805 if (time_after(jiffies, timeout)) {
8806 /* Timeout, marked the outstanding cmd not complete */
8812 /* Can not cleanly block async mailbox command, fails it */
8814 spin_lock_irq(&phba->hbalock);
8815 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8816 spin_unlock_irq(&phba->hbalock);
8822 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
8823 * @phba: Pointer to HBA context object.
8825 * The function unblocks and resume posting of SLI4 asynchronous mailbox
8826 * commands from the driver internal pending mailbox queue. It makes sure
8827 * that there is no outstanding mailbox command before resuming posting
8828 * asynchronous mailbox commands. If, for any reason, there is outstanding
8829 * mailbox command, it will try to wait it out before resuming asynchronous
8830 * mailbox command posting.
8833 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
8835 struct lpfc_sli *psli = &phba->sli;
8837 spin_lock_irq(&phba->hbalock);
8838 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
8839 /* Asynchronous mailbox posting is not blocked, do nothing */
8840 spin_unlock_irq(&phba->hbalock);
8844 /* Outstanding synchronous mailbox command is guaranteed to be done,
8845 * successful or timeout, after timing-out the outstanding mailbox
8846 * command shall always be removed, so just unblock posting async
8847 * mailbox command and resume
8849 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8850 spin_unlock_irq(&phba->hbalock);
8852 /* wake up worker thread to post asynchronous mailbox command */
8853 lpfc_worker_wake_up(phba);
8857 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
8858 * @phba: Pointer to HBA context object.
8859 * @mboxq: Pointer to mailbox object.
8861 * The function waits for the bootstrap mailbox register ready bit from
8862 * port for twice the regular mailbox command timeout value.
8864 * 0 - no timeout on waiting for bootstrap mailbox register ready.
8865 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
8868 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8871 unsigned long timeout;
8872 struct lpfc_register bmbx_reg;
8874 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
8878 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
8879 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
8883 if (time_after(jiffies, timeout))
8884 return MBXERR_ERROR;
8885 } while (!db_ready);
8891 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
8892 * @phba: Pointer to HBA context object.
8893 * @mboxq: Pointer to mailbox object.
8895 * The function posts a mailbox to the port. The mailbox is expected
8896 * to be comletely filled in and ready for the port to operate on it.
8897 * This routine executes a synchronous completion operation on the
8898 * mailbox by polling for its completion.
8900 * The caller must not be holding any locks when calling this routine.
8903 * MBX_SUCCESS - mailbox posted successfully
8904 * Any of the MBX error values.
8907 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
8909 int rc = MBX_SUCCESS;
8910 unsigned long iflag;
8911 uint32_t mcqe_status;
8913 struct lpfc_sli *psli = &phba->sli;
8914 struct lpfc_mqe *mb = &mboxq->u.mqe;
8915 struct lpfc_bmbx_create *mbox_rgn;
8916 struct dma_address *dma_address;
8919 * Only one mailbox can be active to the bootstrap mailbox region
8920 * at a time and there is no queueing provided.
8922 spin_lock_irqsave(&phba->hbalock, iflag);
8923 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
8924 spin_unlock_irqrestore(&phba->hbalock, iflag);
8925 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8926 "(%d):2532 Mailbox command x%x (x%x/x%x) "
8927 "cannot issue Data: x%x x%x\n",
8928 mboxq->vport ? mboxq->vport->vpi : 0,
8929 mboxq->u.mb.mbxCommand,
8930 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
8931 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
8932 psli->sli_flag, MBX_POLL);
8933 return MBXERR_ERROR;
8935 /* The server grabs the token and owns it until release */
8936 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
8937 phba->sli.mbox_active = mboxq;
8938 spin_unlock_irqrestore(&phba->hbalock, iflag);
8940 /* wait for bootstrap mbox register for readyness */
8941 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8945 * Initialize the bootstrap memory region to avoid stale data areas
8946 * in the mailbox post. Then copy the caller's mailbox contents to
8947 * the bmbx mailbox region.
8949 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
8950 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
8951 lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
8952 sizeof(struct lpfc_mqe));
8954 /* Post the high mailbox dma address to the port and wait for ready. */
8955 dma_address = &phba->sli4_hba.bmbx.dma_address;
8956 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
8958 /* wait for bootstrap mbox register for hi-address write done */
8959 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8963 /* Post the low mailbox dma address to the port. */
8964 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
8966 /* wait for bootstrap mbox register for low address write done */
8967 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
8972 * Read the CQ to ensure the mailbox has completed.
8973 * If so, update the mailbox status so that the upper layers
8974 * can complete the request normally.
8976 lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
8977 sizeof(struct lpfc_mqe));
8978 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
8979 lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
8980 sizeof(struct lpfc_mcqe));
8981 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
8983 * When the CQE status indicates a failure and the mailbox status
8984 * indicates success then copy the CQE status into the mailbox status
8985 * (and prefix it with x4000).
8987 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
8988 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
8989 bf_set(lpfc_mqe_status, mb,
8990 (LPFC_MBX_ERROR_RANGE | mcqe_status));
8993 lpfc_sli4_swap_str(phba, mboxq);
8995 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8996 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
8997 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
8998 " x%x x%x CQ: x%x x%x x%x x%x\n",
8999 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
9000 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9001 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9002 bf_get(lpfc_mqe_status, mb),
9003 mb->un.mb_words[0], mb->un.mb_words[1],
9004 mb->un.mb_words[2], mb->un.mb_words[3],
9005 mb->un.mb_words[4], mb->un.mb_words[5],
9006 mb->un.mb_words[6], mb->un.mb_words[7],
9007 mb->un.mb_words[8], mb->un.mb_words[9],
9008 mb->un.mb_words[10], mb->un.mb_words[11],
9009 mb->un.mb_words[12], mboxq->mcqe.word0,
9010 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
9011 mboxq->mcqe.trailer);
9013 /* We are holding the token, no needed for lock when release */
9014 spin_lock_irqsave(&phba->hbalock, iflag);
9015 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9016 phba->sli.mbox_active = NULL;
9017 spin_unlock_irqrestore(&phba->hbalock, iflag);
9022 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
9023 * @phba: Pointer to HBA context object.
9024 * @mboxq: Pointer to mailbox object.
9025 * @flag: Flag indicating how the mailbox need to be processed.
9027 * This function is called by discovery code and HBA management code to submit
9028 * a mailbox command to firmware with SLI-4 interface spec.
9030 * Return codes the caller owns the mailbox command after the return of the
9034 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
9037 struct lpfc_sli *psli = &phba->sli;
9038 unsigned long iflags;
9041 /* dump from issue mailbox command if setup */
9042 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
9044 rc = lpfc_mbox_dev_check(phba);
9046 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9047 "(%d):2544 Mailbox command x%x (x%x/x%x) "
9048 "cannot issue Data: x%x x%x\n",
9049 mboxq->vport ? mboxq->vport->vpi : 0,
9050 mboxq->u.mb.mbxCommand,
9051 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9052 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9053 psli->sli_flag, flag);
9054 goto out_not_finished;
9057 /* Detect polling mode and jump to a handler */
9058 if (!phba->sli4_hba.intr_enable) {
9059 if (flag == MBX_POLL)
9060 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
9063 if (rc != MBX_SUCCESS)
9064 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
9065 "(%d):2541 Mailbox command x%x "
9066 "(x%x/x%x) failure: "
9067 "mqe_sta: x%x mcqe_sta: x%x/x%x "
9069 mboxq->vport ? mboxq->vport->vpi : 0,
9070 mboxq->u.mb.mbxCommand,
9071 lpfc_sli_config_mbox_subsys_get(phba,
9073 lpfc_sli_config_mbox_opcode_get(phba,
9075 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
9076 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
9077 bf_get(lpfc_mcqe_ext_status,
9079 psli->sli_flag, flag);
9081 } else if (flag == MBX_POLL) {
9082 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
9083 "(%d):2542 Try to issue mailbox command "
9084 "x%x (x%x/x%x) synchronously ahead of async "
9085 "mailbox command queue: x%x x%x\n",
9086 mboxq->vport ? mboxq->vport->vpi : 0,
9087 mboxq->u.mb.mbxCommand,
9088 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9089 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9090 psli->sli_flag, flag);
9091 /* Try to block the asynchronous mailbox posting */
9092 rc = lpfc_sli4_async_mbox_block(phba);
9094 /* Successfully blocked, now issue sync mbox cmd */
9095 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
9096 if (rc != MBX_SUCCESS)
9097 lpfc_printf_log(phba, KERN_WARNING,
9099 "(%d):2597 Sync Mailbox command "
9100 "x%x (x%x/x%x) failure: "
9101 "mqe_sta: x%x mcqe_sta: x%x/x%x "
9103 mboxq->vport ? mboxq->vport->vpi : 0,
9104 mboxq->u.mb.mbxCommand,
9105 lpfc_sli_config_mbox_subsys_get(phba,
9107 lpfc_sli_config_mbox_opcode_get(phba,
9109 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
9110 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
9111 bf_get(lpfc_mcqe_ext_status,
9113 psli->sli_flag, flag);
9114 /* Unblock the async mailbox posting afterward */
9115 lpfc_sli4_async_mbox_unblock(phba);
9120 /* Now, interrupt mode asynchronous mailbox command */
9121 rc = lpfc_mbox_cmd_check(phba, mboxq);
9123 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9124 "(%d):2543 Mailbox command x%x (x%x/x%x) "
9125 "cannot issue Data: x%x x%x\n",
9126 mboxq->vport ? mboxq->vport->vpi : 0,
9127 mboxq->u.mb.mbxCommand,
9128 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9129 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9130 psli->sli_flag, flag);
9131 goto out_not_finished;
9134 /* Put the mailbox command to the driver internal FIFO */
9135 psli->slistat.mbox_busy++;
9136 spin_lock_irqsave(&phba->hbalock, iflags);
9137 lpfc_mbox_put(phba, mboxq);
9138 spin_unlock_irqrestore(&phba->hbalock, iflags);
9139 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9140 "(%d):0354 Mbox cmd issue - Enqueue Data: "
9141 "x%x (x%x/x%x) x%x x%x x%x\n",
9142 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
9143 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
9144 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9145 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9146 phba->pport->port_state,
9147 psli->sli_flag, MBX_NOWAIT);
9148 /* Wake up worker thread to transport mailbox command from head */
9149 lpfc_worker_wake_up(phba);
9154 return MBX_NOT_FINISHED;
9158 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
9159 * @phba: Pointer to HBA context object.
9161 * This function is called by worker thread to send a mailbox command to
9162 * SLI4 HBA firmware.
9166 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
9168 struct lpfc_sli *psli = &phba->sli;
9169 LPFC_MBOXQ_t *mboxq;
9170 int rc = MBX_SUCCESS;
9171 unsigned long iflags;
9172 struct lpfc_mqe *mqe;
9175 /* Check interrupt mode before post async mailbox command */
9176 if (unlikely(!phba->sli4_hba.intr_enable))
9177 return MBX_NOT_FINISHED;
9179 /* Check for mailbox command service token */
9180 spin_lock_irqsave(&phba->hbalock, iflags);
9181 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
9182 spin_unlock_irqrestore(&phba->hbalock, iflags);
9183 return MBX_NOT_FINISHED;
9185 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9186 spin_unlock_irqrestore(&phba->hbalock, iflags);
9187 return MBX_NOT_FINISHED;
9189 if (unlikely(phba->sli.mbox_active)) {
9190 spin_unlock_irqrestore(&phba->hbalock, iflags);
9191 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9192 "0384 There is pending active mailbox cmd\n");
9193 return MBX_NOT_FINISHED;
9195 /* Take the mailbox command service token */
9196 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
9198 /* Get the next mailbox command from head of queue */
9199 mboxq = lpfc_mbox_get(phba);
9201 /* If no more mailbox command waiting for post, we're done */
9203 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9204 spin_unlock_irqrestore(&phba->hbalock, iflags);
9207 phba->sli.mbox_active = mboxq;
9208 spin_unlock_irqrestore(&phba->hbalock, iflags);
9210 /* Check device readiness for posting mailbox command */
9211 rc = lpfc_mbox_dev_check(phba);
9213 /* Driver clean routine will clean up pending mailbox */
9214 goto out_not_finished;
9216 /* Prepare the mbox command to be posted */
9217 mqe = &mboxq->u.mqe;
9218 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
9220 /* Start timer for the mbox_tmo and log some mailbox post messages */
9221 mod_timer(&psli->mbox_tmo, (jiffies +
9222 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
9224 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9225 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
9227 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
9228 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9229 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9230 phba->pport->port_state, psli->sli_flag);
9232 if (mbx_cmnd != MBX_HEARTBEAT) {
9234 lpfc_debugfs_disc_trc(mboxq->vport,
9235 LPFC_DISC_TRC_MBOX_VPORT,
9236 "MBOX Send vport: cmd:x%x mb:x%x x%x",
9237 mbx_cmnd, mqe->un.mb_words[0],
9238 mqe->un.mb_words[1]);
9240 lpfc_debugfs_disc_trc(phba->pport,
9242 "MBOX Send: cmd:x%x mb:x%x x%x",
9243 mbx_cmnd, mqe->un.mb_words[0],
9244 mqe->un.mb_words[1]);
9247 psli->slistat.mbox_cmd++;
9249 /* Post the mailbox command to the port */
9250 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
9251 if (rc != MBX_SUCCESS) {
9252 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9253 "(%d):2533 Mailbox command x%x (x%x/x%x) "
9254 "cannot issue Data: x%x x%x\n",
9255 mboxq->vport ? mboxq->vport->vpi : 0,
9256 mboxq->u.mb.mbxCommand,
9257 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9258 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9259 psli->sli_flag, MBX_NOWAIT);
9260 goto out_not_finished;
9266 spin_lock_irqsave(&phba->hbalock, iflags);
9267 if (phba->sli.mbox_active) {
9268 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9269 __lpfc_mbox_cmpl_put(phba, mboxq);
9270 /* Release the token */
9271 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9272 phba->sli.mbox_active = NULL;
9274 spin_unlock_irqrestore(&phba->hbalock, iflags);
9276 return MBX_NOT_FINISHED;
9280 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
9281 * @phba: Pointer to HBA context object.
9282 * @pmbox: Pointer to mailbox object.
9283 * @flag: Flag indicating how the mailbox need to be processed.
9285 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
9286 * the API jump table function pointer from the lpfc_hba struct.
9288 * Return codes the caller owns the mailbox command after the return of the
9292 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
9294 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
9298 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
9299 * @phba: The hba struct for which this call is being executed.
9300 * @dev_grp: The HBA PCI-Device group number.
9302 * This routine sets up the mbox interface API function jump table in @phba
9304 * Returns: 0 - success, -ENODEV - failure.
9307 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
9311 case LPFC_PCI_DEV_LP:
9312 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
9313 phba->lpfc_sli_handle_slow_ring_event =
9314 lpfc_sli_handle_slow_ring_event_s3;
9315 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
9316 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
9317 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
9319 case LPFC_PCI_DEV_OC:
9320 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
9321 phba->lpfc_sli_handle_slow_ring_event =
9322 lpfc_sli_handle_slow_ring_event_s4;
9323 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
9324 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
9325 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
9328 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9329 "1420 Invalid HBA PCI-device group: 0x%x\n",
9337 * __lpfc_sli_ringtx_put - Add an iocb to the txq
9338 * @phba: Pointer to HBA context object.
9339 * @pring: Pointer to driver SLI ring object.
9340 * @piocb: Pointer to address of newly added command iocb.
9342 * This function is called with hbalock held for SLI3 ports or
9343 * the ring lock held for SLI4 ports to add a command
9344 * iocb to the txq when SLI layer cannot submit the command iocb
9348 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9349 struct lpfc_iocbq *piocb)
9351 if (phba->sli_rev == LPFC_SLI_REV4)
9352 lockdep_assert_held(&pring->ring_lock);
9354 lockdep_assert_held(&phba->hbalock);
9355 /* Insert the caller's iocb in the txq tail for later processing. */
9356 list_add_tail(&piocb->list, &pring->txq);
9360 * lpfc_sli_next_iocb - Get the next iocb in the txq
9361 * @phba: Pointer to HBA context object.
9362 * @pring: Pointer to driver SLI ring object.
9363 * @piocb: Pointer to address of newly added command iocb.
9365 * This function is called with hbalock held before a new
9366 * iocb is submitted to the firmware. This function checks
9367 * txq to flush the iocbs in txq to Firmware before
9368 * submitting new iocbs to the Firmware.
9369 * If there are iocbs in the txq which need to be submitted
9370 * to firmware, lpfc_sli_next_iocb returns the first element
9371 * of the txq after dequeuing it from txq.
9372 * If there is no iocb in the txq then the function will return
9373 * *piocb and *piocb is set to NULL. Caller needs to check
9374 * *piocb to find if there are more commands in the txq.
9376 static struct lpfc_iocbq *
9377 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
9378 struct lpfc_iocbq **piocb)
9380 struct lpfc_iocbq * nextiocb;
9382 lockdep_assert_held(&phba->hbalock);
9384 nextiocb = lpfc_sli_ringtx_get(phba, pring);
9394 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
9395 * @phba: Pointer to HBA context object.
9396 * @ring_number: SLI ring number to issue iocb on.
9397 * @piocb: Pointer to command iocb.
9398 * @flag: Flag indicating if this command can be put into txq.
9400 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
9401 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
9402 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
9403 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
9404 * this function allows only iocbs for posting buffers. This function finds
9405 * next available slot in the command ring and posts the command to the
9406 * available slot and writes the port attention register to request HBA start
9407 * processing new iocb. If there is no slot available in the ring and
9408 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
9409 * the function returns IOCB_BUSY.
9411 * This function is called with hbalock held. The function will return success
9412 * after it successfully submit the iocb to firmware or after adding to the
9416 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
9417 struct lpfc_iocbq *piocb, uint32_t flag)
9419 struct lpfc_iocbq *nextiocb;
9421 struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
9423 lockdep_assert_held(&phba->hbalock);
9425 if (piocb->iocb_cmpl && (!piocb->vport) &&
9426 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
9427 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
9428 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9429 "1807 IOCB x%x failed. No vport\n",
9430 piocb->iocb.ulpCommand);
9436 /* If the PCI channel is in offline state, do not post iocbs. */
9437 if (unlikely(pci_channel_offline(phba->pcidev)))
9440 /* If HBA has a deferred error attention, fail the iocb. */
9441 if (unlikely(phba->hba_flag & DEFER_ERATT))
9445 * We should never get an IOCB if we are in a < LINK_DOWN state
9447 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
9451 * Check to see if we are blocking IOCB processing because of a
9452 * outstanding event.
9454 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
9457 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
9459 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
9460 * can be issued if the link is not up.
9462 switch (piocb->iocb.ulpCommand) {
9463 case CMD_GEN_REQUEST64_CR:
9464 case CMD_GEN_REQUEST64_CX:
9465 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
9466 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
9467 FC_RCTL_DD_UNSOL_CMD) ||
9468 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
9469 MENLO_TRANSPORT_TYPE))
9473 case CMD_QUE_RING_BUF_CN:
9474 case CMD_QUE_RING_BUF64_CN:
9476 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
9477 * completion, iocb_cmpl MUST be 0.
9479 if (piocb->iocb_cmpl)
9480 piocb->iocb_cmpl = NULL;
9482 case CMD_CREATE_XRI_CR:
9483 case CMD_CLOSE_XRI_CN:
9484 case CMD_CLOSE_XRI_CX:
9491 * For FCP commands, we must be in a state where we can process link
9494 } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
9495 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
9499 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
9500 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
9501 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
9504 lpfc_sli_update_ring(phba, pring);
9506 lpfc_sli_update_full_ring(phba, pring);
9509 return IOCB_SUCCESS;
9514 pring->stats.iocb_cmd_delay++;
9518 if (!(flag & SLI_IOCB_RET_IOCB)) {
9519 __lpfc_sli_ringtx_put(phba, pring, piocb);
9520 return IOCB_SUCCESS;
9527 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
9528 * @phba: Pointer to HBA context object.
9529 * @piocbq: Pointer to command iocb.
9530 * @sglq: Pointer to the scatter gather queue object.
9532 * This routine converts the bpl or bde that is in the IOCB
9533 * to a sgl list for the sli4 hardware. The physical address
9534 * of the bpl/bde is converted back to a virtual address.
9535 * If the IOCB contains a BPL then the list of BDE's is
9536 * converted to sli4_sge's. If the IOCB contains a single
9537 * BDE then it is converted to a single sli_sge.
9538 * The IOCB is still in cpu endianess so the contents of
9539 * the bpl can be used without byte swapping.
9541 * Returns valid XRI = Success, NO_XRI = Failure.
9544 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
9545 struct lpfc_sglq *sglq)
9547 uint16_t xritag = NO_XRI;
9548 struct ulp_bde64 *bpl = NULL;
9549 struct ulp_bde64 bde;
9550 struct sli4_sge *sgl = NULL;
9551 struct lpfc_dmabuf *dmabuf;
9555 uint32_t offset = 0; /* accumulated offset in the sg request list */
9556 int inbound = 0; /* number of sg reply entries inbound from firmware */
9558 if (!piocbq || !sglq)
9561 sgl = (struct sli4_sge *)sglq->sgl;
9562 icmd = &piocbq->iocb;
9563 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
9564 return sglq->sli4_xritag;
9565 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
9566 numBdes = icmd->un.genreq64.bdl.bdeSize /
9567 sizeof(struct ulp_bde64);
9568 /* The addrHigh and addrLow fields within the IOCB
9569 * have not been byteswapped yet so there is no
9570 * need to swap them back.
9572 if (piocbq->context3)
9573 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
9577 bpl = (struct ulp_bde64 *)dmabuf->virt;
9581 for (i = 0; i < numBdes; i++) {
9582 /* Should already be byte swapped. */
9583 sgl->addr_hi = bpl->addrHigh;
9584 sgl->addr_lo = bpl->addrLow;
9586 sgl->word2 = le32_to_cpu(sgl->word2);
9587 if ((i+1) == numBdes)
9588 bf_set(lpfc_sli4_sge_last, sgl, 1);
9590 bf_set(lpfc_sli4_sge_last, sgl, 0);
9591 /* swap the size field back to the cpu so we
9592 * can assign it to the sgl.
9594 bde.tus.w = le32_to_cpu(bpl->tus.w);
9595 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
9596 /* The offsets in the sgl need to be accumulated
9597 * separately for the request and reply lists.
9598 * The request is always first, the reply follows.
9600 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
9601 /* add up the reply sg entries */
9602 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
9604 /* first inbound? reset the offset */
9607 bf_set(lpfc_sli4_sge_offset, sgl, offset);
9608 bf_set(lpfc_sli4_sge_type, sgl,
9609 LPFC_SGE_TYPE_DATA);
9610 offset += bde.tus.f.bdeSize;
9612 sgl->word2 = cpu_to_le32(sgl->word2);
9616 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
9617 /* The addrHigh and addrLow fields of the BDE have not
9618 * been byteswapped yet so they need to be swapped
9619 * before putting them in the sgl.
9622 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
9624 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
9625 sgl->word2 = le32_to_cpu(sgl->word2);
9626 bf_set(lpfc_sli4_sge_last, sgl, 1);
9627 sgl->word2 = cpu_to_le32(sgl->word2);
9629 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
9631 return sglq->sli4_xritag;
9635 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
9636 * @phba: Pointer to HBA context object.
9637 * @iocbq: Pointer to command iocb.
9638 * @wqe: Pointer to the work queue entry.
9640 * This routine converts the iocb command to its Work Queue Entry
9641 * equivalent. The wqe pointer should not have any fields set when
9642 * this routine is called because it will memcpy over them.
9643 * This routine does not set the CQ_ID or the WQEC bits in the
9646 * Returns: 0 = Success, IOCB_ERROR = Failure.
9649 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
9650 union lpfc_wqe128 *wqe)
9652 uint32_t xmit_len = 0, total_len = 0;
9656 uint8_t command_type = ELS_COMMAND_NON_FIP;
9659 uint16_t abrt_iotag;
9660 struct lpfc_iocbq *abrtiocbq;
9661 struct ulp_bde64 *bpl = NULL;
9662 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
9664 struct ulp_bde64 bde;
9665 struct lpfc_nodelist *ndlp;
9669 fip = phba->hba_flag & HBA_FIP_SUPPORT;
9670 /* The fcp commands will set command type */
9671 if (iocbq->iocb_flag & LPFC_IO_FCP)
9672 command_type = FCP_COMMAND;
9673 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
9674 command_type = ELS_COMMAND_FIP;
9676 command_type = ELS_COMMAND_NON_FIP;
9678 if (phba->fcp_embed_io)
9679 memset(wqe, 0, sizeof(union lpfc_wqe128));
9680 /* Some of the fields are in the right position already */
9681 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
9682 /* The ct field has moved so reset */
9683 wqe->generic.wqe_com.word7 = 0;
9684 wqe->generic.wqe_com.word10 = 0;
9686 abort_tag = (uint32_t) iocbq->iotag;
9687 xritag = iocbq->sli4_xritag;
9688 /* words0-2 bpl convert bde */
9689 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
9690 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
9691 sizeof(struct ulp_bde64);
9692 bpl = (struct ulp_bde64 *)
9693 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
9697 /* Should already be byte swapped. */
9698 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
9699 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
9700 /* swap the size field back to the cpu so we
9701 * can assign it to the sgl.
9703 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
9704 xmit_len = wqe->generic.bde.tus.f.bdeSize;
9706 for (i = 0; i < numBdes; i++) {
9707 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
9708 total_len += bde.tus.f.bdeSize;
9711 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
9713 iocbq->iocb.ulpIoTag = iocbq->iotag;
9714 cmnd = iocbq->iocb.ulpCommand;
9716 switch (iocbq->iocb.ulpCommand) {
9717 case CMD_ELS_REQUEST64_CR:
9718 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
9719 ndlp = iocbq->context_un.ndlp;
9721 ndlp = (struct lpfc_nodelist *)iocbq->context1;
9722 if (!iocbq->iocb.ulpLe) {
9723 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9724 "2007 Only Limited Edition cmd Format"
9725 " supported 0x%x\n",
9726 iocbq->iocb.ulpCommand);
9730 wqe->els_req.payload_len = xmit_len;
9731 /* Els_reguest64 has a TMO */
9732 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
9733 iocbq->iocb.ulpTimeout);
9734 /* Need a VF for word 4 set the vf bit*/
9735 bf_set(els_req64_vf, &wqe->els_req, 0);
9736 /* And a VFID for word 12 */
9737 bf_set(els_req64_vfid, &wqe->els_req, 0);
9738 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
9739 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9740 iocbq->iocb.ulpContext);
9741 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
9742 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
9743 /* CCP CCPE PV PRI in word10 were set in the memcpy */
9744 if (command_type == ELS_COMMAND_FIP)
9745 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
9746 >> LPFC_FIP_ELS_ID_SHIFT);
9747 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
9748 iocbq->context2)->virt);
9749 if_type = bf_get(lpfc_sli_intf_if_type,
9750 &phba->sli4_hba.sli_intf);
9751 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
9752 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
9753 *pcmd == ELS_CMD_SCR ||
9754 *pcmd == ELS_CMD_RDF ||
9755 *pcmd == ELS_CMD_RSCN_XMT ||
9756 *pcmd == ELS_CMD_FDISC ||
9757 *pcmd == ELS_CMD_LOGO ||
9758 *pcmd == ELS_CMD_PLOGI)) {
9759 bf_set(els_req64_sp, &wqe->els_req, 1);
9760 bf_set(els_req64_sid, &wqe->els_req,
9761 iocbq->vport->fc_myDID);
9762 if ((*pcmd == ELS_CMD_FLOGI) &&
9763 !(phba->fc_topology ==
9764 LPFC_TOPOLOGY_LOOP))
9765 bf_set(els_req64_sid, &wqe->els_req, 0);
9766 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
9767 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9768 phba->vpi_ids[iocbq->vport->vpi]);
9769 } else if (pcmd && iocbq->context1) {
9770 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
9771 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
9772 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9775 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
9776 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
9777 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
9778 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
9779 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
9780 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
9781 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
9782 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
9783 wqe->els_req.max_response_payload_len = total_len - xmit_len;
9785 case CMD_XMIT_SEQUENCE64_CX:
9786 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
9787 iocbq->iocb.un.ulpWord[3]);
9788 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
9789 iocbq->iocb.unsli3.rcvsli3.ox_id);
9790 /* The entire sequence is transmitted for this IOCB */
9791 xmit_len = total_len;
9792 cmnd = CMD_XMIT_SEQUENCE64_CR;
9793 if (phba->link_flag & LS_LOOPBACK_MODE)
9794 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
9796 case CMD_XMIT_SEQUENCE64_CR:
9797 /* word3 iocb=io_tag32 wqe=reserved */
9798 wqe->xmit_sequence.rsvd3 = 0;
9799 /* word4 relative_offset memcpy */
9800 /* word5 r_ctl/df_ctl memcpy */
9801 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
9802 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
9803 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
9804 LPFC_WQE_IOD_WRITE);
9805 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
9806 LPFC_WQE_LENLOC_WORD12);
9807 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
9808 wqe->xmit_sequence.xmit_len = xmit_len;
9809 command_type = OTHER_COMMAND;
9811 case CMD_XMIT_BCAST64_CN:
9812 /* word3 iocb=iotag32 wqe=seq_payload_len */
9813 wqe->xmit_bcast64.seq_payload_len = xmit_len;
9814 /* word4 iocb=rsvd wqe=rsvd */
9815 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
9816 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
9817 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
9818 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
9819 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
9820 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
9821 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
9822 LPFC_WQE_LENLOC_WORD3);
9823 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
9825 case CMD_FCP_IWRITE64_CR:
9826 command_type = FCP_COMMAND_DATA_OUT;
9827 /* word3 iocb=iotag wqe=payload_offset_len */
9828 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9829 bf_set(payload_offset_len, &wqe->fcp_iwrite,
9830 xmit_len + sizeof(struct fcp_rsp));
9831 bf_set(cmd_buff_len, &wqe->fcp_iwrite,
9833 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9834 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9835 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
9836 iocbq->iocb.ulpFCP2Rcvy);
9837 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
9838 /* Always open the exchange */
9839 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
9840 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
9841 LPFC_WQE_LENLOC_WORD4);
9842 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
9843 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
9844 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9845 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
9846 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
9847 if (iocbq->priority) {
9848 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
9849 (iocbq->priority << 1));
9851 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
9852 (phba->cfg_XLanePriority << 1));
9855 /* Note, word 10 is already initialized to 0 */
9857 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9858 if (phba->cfg_enable_pbde)
9859 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1);
9861 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
9863 if (phba->fcp_embed_io) {
9864 struct lpfc_io_buf *lpfc_cmd;
9865 struct sli4_sge *sgl;
9866 struct fcp_cmnd *fcp_cmnd;
9869 /* 128 byte wqe support here */
9871 lpfc_cmd = iocbq->context1;
9872 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9873 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9875 /* Word 0-2 - FCP_CMND */
9876 wqe->generic.bde.tus.f.bdeFlags =
9877 BUFF_TYPE_BDE_IMMED;
9878 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9879 wqe->generic.bde.addrHigh = 0;
9880 wqe->generic.bde.addrLow = 88; /* Word 22 */
9882 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
9883 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
9885 /* Word 22-29 FCP CMND Payload */
9886 ptr = &wqe->words[22];
9887 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9890 case CMD_FCP_IREAD64_CR:
9891 /* word3 iocb=iotag wqe=payload_offset_len */
9892 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9893 bf_set(payload_offset_len, &wqe->fcp_iread,
9894 xmit_len + sizeof(struct fcp_rsp));
9895 bf_set(cmd_buff_len, &wqe->fcp_iread,
9897 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9898 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9899 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
9900 iocbq->iocb.ulpFCP2Rcvy);
9901 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
9902 /* Always open the exchange */
9903 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
9904 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
9905 LPFC_WQE_LENLOC_WORD4);
9906 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
9907 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
9908 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9909 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
9910 bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
9911 if (iocbq->priority) {
9912 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
9913 (iocbq->priority << 1));
9915 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
9916 (phba->cfg_XLanePriority << 1));
9919 /* Note, word 10 is already initialized to 0 */
9921 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9922 if (phba->cfg_enable_pbde)
9923 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1);
9925 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
9927 if (phba->fcp_embed_io) {
9928 struct lpfc_io_buf *lpfc_cmd;
9929 struct sli4_sge *sgl;
9930 struct fcp_cmnd *fcp_cmnd;
9933 /* 128 byte wqe support here */
9935 lpfc_cmd = iocbq->context1;
9936 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9937 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9939 /* Word 0-2 - FCP_CMND */
9940 wqe->generic.bde.tus.f.bdeFlags =
9941 BUFF_TYPE_BDE_IMMED;
9942 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
9943 wqe->generic.bde.addrHigh = 0;
9944 wqe->generic.bde.addrLow = 88; /* Word 22 */
9946 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
9947 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
9949 /* Word 22-29 FCP CMND Payload */
9950 ptr = &wqe->words[22];
9951 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
9954 case CMD_FCP_ICMND64_CR:
9955 /* word3 iocb=iotag wqe=payload_offset_len */
9956 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9957 bf_set(payload_offset_len, &wqe->fcp_icmd,
9958 xmit_len + sizeof(struct fcp_rsp));
9959 bf_set(cmd_buff_len, &wqe->fcp_icmd,
9961 /* word3 iocb=IO_TAG wqe=reserved */
9962 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
9963 /* Always open the exchange */
9964 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
9965 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
9966 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
9967 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
9968 LPFC_WQE_LENLOC_NONE);
9969 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
9970 iocbq->iocb.ulpFCP2Rcvy);
9971 if (iocbq->iocb_flag & LPFC_IO_OAS) {
9972 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
9973 bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
9974 if (iocbq->priority) {
9975 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
9976 (iocbq->priority << 1));
9978 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
9979 (phba->cfg_XLanePriority << 1));
9982 /* Note, word 10 is already initialized to 0 */
9984 if (phba->fcp_embed_io) {
9985 struct lpfc_io_buf *lpfc_cmd;
9986 struct sli4_sge *sgl;
9987 struct fcp_cmnd *fcp_cmnd;
9990 /* 128 byte wqe support here */
9992 lpfc_cmd = iocbq->context1;
9993 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
9994 fcp_cmnd = lpfc_cmd->fcp_cmnd;
9996 /* Word 0-2 - FCP_CMND */
9997 wqe->generic.bde.tus.f.bdeFlags =
9998 BUFF_TYPE_BDE_IMMED;
9999 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10000 wqe->generic.bde.addrHigh = 0;
10001 wqe->generic.bde.addrLow = 88; /* Word 22 */
10003 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
10004 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
10006 /* Word 22-29 FCP CMND Payload */
10007 ptr = &wqe->words[22];
10008 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10011 case CMD_GEN_REQUEST64_CR:
10012 /* For this command calculate the xmit length of the
10016 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
10017 sizeof(struct ulp_bde64);
10018 for (i = 0; i < numBdes; i++) {
10019 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
10020 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
10022 xmit_len += bde.tus.f.bdeSize;
10024 /* word3 iocb=IO_TAG wqe=request_payload_len */
10025 wqe->gen_req.request_payload_len = xmit_len;
10026 /* word4 iocb=parameter wqe=relative_offset memcpy */
10027 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
10028 /* word6 context tag copied in memcpy */
10029 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
10030 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
10031 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10032 "2015 Invalid CT %x command 0x%x\n",
10033 ct, iocbq->iocb.ulpCommand);
10036 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
10037 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
10038 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
10039 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
10040 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
10041 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
10042 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
10043 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
10044 wqe->gen_req.max_response_payload_len = total_len - xmit_len;
10045 command_type = OTHER_COMMAND;
10047 case CMD_XMIT_ELS_RSP64_CX:
10048 ndlp = (struct lpfc_nodelist *)iocbq->context1;
10049 /* words0-2 BDE memcpy */
10050 /* word3 iocb=iotag32 wqe=response_payload_len */
10051 wqe->xmit_els_rsp.response_payload_len = xmit_len;
10053 wqe->xmit_els_rsp.word4 = 0;
10054 /* word5 iocb=rsvd wge=did */
10055 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
10056 iocbq->iocb.un.xseq64.xmit_els_remoteID);
10058 if_type = bf_get(lpfc_sli_intf_if_type,
10059 &phba->sli4_hba.sli_intf);
10060 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10061 if (iocbq->vport->fc_flag & FC_PT2PT) {
10062 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
10063 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
10064 iocbq->vport->fc_myDID);
10065 if (iocbq->vport->fc_myDID == Fabric_DID) {
10066 bf_set(wqe_els_did,
10067 &wqe->xmit_els_rsp.wqe_dest, 0);
10071 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
10072 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
10073 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
10074 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
10075 iocbq->iocb.unsli3.rcvsli3.ox_id);
10076 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
10077 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
10078 phba->vpi_ids[iocbq->vport->vpi]);
10079 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
10080 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
10081 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
10082 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
10083 LPFC_WQE_LENLOC_WORD3);
10084 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
10085 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
10086 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
10087 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
10088 iocbq->context2)->virt);
10089 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
10090 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
10091 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
10092 iocbq->vport->fc_myDID);
10093 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
10094 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
10095 phba->vpi_ids[phba->pport->vpi]);
10097 command_type = OTHER_COMMAND;
10099 case CMD_CLOSE_XRI_CN:
10100 case CMD_ABORT_XRI_CN:
10101 case CMD_ABORT_XRI_CX:
10102 /* words 0-2 memcpy should be 0 rserved */
10103 /* port will send abts */
10104 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
10105 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
10106 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
10107 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
10111 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
10113 * The link is down, or the command was ELS_FIP
10114 * so the fw does not need to send abts
10117 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
10119 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
10120 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
10121 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
10122 wqe->abort_cmd.rsrvd5 = 0;
10123 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
10124 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
10125 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
10127 * The abort handler will send us CMD_ABORT_XRI_CN or
10128 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
10130 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
10131 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
10132 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
10133 LPFC_WQE_LENLOC_NONE);
10134 cmnd = CMD_ABORT_XRI_CX;
10135 command_type = OTHER_COMMAND;
10138 case CMD_XMIT_BLS_RSP64_CX:
10139 ndlp = (struct lpfc_nodelist *)iocbq->context1;
10140 /* As BLS ABTS RSP WQE is very different from other WQEs,
10141 * we re-construct this WQE here based on information in
10142 * iocbq from scratch.
10144 memset(wqe, 0, sizeof(*wqe));
10145 /* OX_ID is invariable to who sent ABTS to CT exchange */
10146 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
10147 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
10148 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
10149 LPFC_ABTS_UNSOL_INT) {
10150 /* ABTS sent by initiator to CT exchange, the
10151 * RX_ID field will be filled with the newly
10152 * allocated responder XRI.
10154 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
10155 iocbq->sli4_xritag);
10157 /* ABTS sent by responder to CT exchange, the
10158 * RX_ID field will be filled with the responder
10161 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
10162 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
10164 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
10165 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
10168 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
10170 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
10171 iocbq->iocb.ulpContext);
10172 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
10173 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
10174 phba->vpi_ids[phba->pport->vpi]);
10175 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
10176 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
10177 LPFC_WQE_LENLOC_NONE);
10178 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
10179 command_type = OTHER_COMMAND;
10180 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
10181 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
10182 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
10183 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
10184 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
10185 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
10186 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
10190 case CMD_SEND_FRAME:
10191 bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME);
10192 bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */
10193 bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */
10194 bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1);
10195 bf_set(wqe_xbl, &wqe->generic.wqe_com, 1);
10196 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
10197 bf_set(wqe_xc, &wqe->generic.wqe_com, 1);
10198 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA);
10199 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10200 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
10201 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
10203 case CMD_XRI_ABORTED_CX:
10204 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
10205 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
10206 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
10207 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
10208 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
10210 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10211 "2014 Invalid command 0x%x\n",
10212 iocbq->iocb.ulpCommand);
10216 if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
10217 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
10218 else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
10219 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
10220 else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
10221 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
10222 iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
10223 LPFC_IO_DIF_INSERT);
10224 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
10225 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
10226 wqe->generic.wqe_com.abort_tag = abort_tag;
10227 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
10228 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
10229 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
10230 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10235 * __lpfc_sli_issue_fcp_io_s3 - SLI3 device for sending fcp io iocb
10236 * @phba: Pointer to HBA context object.
10237 * @ring_number: SLI ring number to issue wqe on.
10238 * @piocb: Pointer to command iocb.
10239 * @flag: Flag indicating if this command can be put into txq.
10241 * __lpfc_sli_issue_fcp_io_s3 is wrapper function to invoke lockless func to
10242 * send an iocb command to an HBA with SLI-4 interface spec.
10244 * This function takes the hbalock before invoking the lockless version.
10245 * The function will return success after it successfully submit the wqe to
10246 * firmware or after adding to the txq.
10249 __lpfc_sli_issue_fcp_io_s3(struct lpfc_hba *phba, uint32_t ring_number,
10250 struct lpfc_iocbq *piocb, uint32_t flag)
10252 unsigned long iflags;
10255 spin_lock_irqsave(&phba->hbalock, iflags);
10256 rc = __lpfc_sli_issue_iocb_s3(phba, ring_number, piocb, flag);
10257 spin_unlock_irqrestore(&phba->hbalock, iflags);
10263 * __lpfc_sli_issue_fcp_io_s4 - SLI4 device for sending fcp io wqe
10264 * @phba: Pointer to HBA context object.
10265 * @ring_number: SLI ring number to issue wqe on.
10266 * @piocb: Pointer to command iocb.
10267 * @flag: Flag indicating if this command can be put into txq.
10269 * __lpfc_sli_issue_fcp_io_s4 is used by other functions in the driver to issue
10270 * an wqe command to an HBA with SLI-4 interface spec.
10272 * This function is a lockless version. The function will return success
10273 * after it successfully submit the wqe to firmware or after adding to the
10277 __lpfc_sli_issue_fcp_io_s4(struct lpfc_hba *phba, uint32_t ring_number,
10278 struct lpfc_iocbq *piocb, uint32_t flag)
10281 struct lpfc_io_buf *lpfc_cmd =
10282 (struct lpfc_io_buf *)piocb->context1;
10283 union lpfc_wqe128 *wqe = &piocb->wqe;
10284 struct sli4_sge *sgl;
10286 /* 128 byte wqe support here */
10287 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
10289 if (phba->fcp_embed_io) {
10290 struct fcp_cmnd *fcp_cmnd;
10293 fcp_cmnd = lpfc_cmd->fcp_cmnd;
10295 /* Word 0-2 - FCP_CMND */
10296 wqe->generic.bde.tus.f.bdeFlags =
10297 BUFF_TYPE_BDE_IMMED;
10298 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10299 wqe->generic.bde.addrHigh = 0;
10300 wqe->generic.bde.addrLow = 88; /* Word 22 */
10302 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
10303 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
10305 /* Word 22-29 FCP CMND Payload */
10306 ptr = &wqe->words[22];
10307 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10309 /* Word 0-2 - Inline BDE */
10310 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
10311 wqe->generic.bde.tus.f.bdeSize = sizeof(struct fcp_cmnd);
10312 wqe->generic.bde.addrHigh = sgl->addr_hi;
10313 wqe->generic.bde.addrLow = sgl->addr_lo;
10316 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
10317 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
10320 rc = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, piocb);
10325 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
10326 * @phba: Pointer to HBA context object.
10327 * @ring_number: SLI ring number to issue iocb on.
10328 * @piocb: Pointer to command iocb.
10329 * @flag: Flag indicating if this command can be put into txq.
10331 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
10332 * an iocb command to an HBA with SLI-4 interface spec.
10334 * This function is called with ringlock held. The function will return success
10335 * after it successfully submit the iocb to firmware or after adding to the
10339 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
10340 struct lpfc_iocbq *piocb, uint32_t flag)
10342 struct lpfc_sglq *sglq;
10343 union lpfc_wqe128 wqe;
10344 struct lpfc_queue *wq;
10345 struct lpfc_sli_ring *pring;
10348 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
10349 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
10350 wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
10352 wq = phba->sli4_hba.els_wq;
10355 /* Get corresponding ring */
10359 * The WQE can be either 64 or 128 bytes,
10362 lockdep_assert_held(&pring->ring_lock);
10364 if (piocb->sli4_xritag == NO_XRI) {
10365 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
10366 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
10369 if (!list_empty(&pring->txq)) {
10370 if (!(flag & SLI_IOCB_RET_IOCB)) {
10371 __lpfc_sli_ringtx_put(phba,
10373 return IOCB_SUCCESS;
10378 sglq = __lpfc_sli_get_els_sglq(phba, piocb);
10380 if (!(flag & SLI_IOCB_RET_IOCB)) {
10381 __lpfc_sli_ringtx_put(phba,
10384 return IOCB_SUCCESS;
10390 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
10391 /* These IO's already have an XRI and a mapped sgl. */
10396 * This is a continuation of a commandi,(CX) so this
10397 * sglq is on the active list
10399 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
10405 piocb->sli4_lxritag = sglq->sli4_lxritag;
10406 piocb->sli4_xritag = sglq->sli4_xritag;
10407 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
10411 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
10414 if (lpfc_sli4_wq_put(wq, &wqe))
10416 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
10422 * lpfc_sli_issue_fcp_io - Wrapper func for issuing fcp i/o
10424 * This routine wraps the actual fcp i/o function for issusing WQE for sli-4
10425 * or IOCB for sli-3 function.
10426 * pointer from the lpfc_hba struct.
10429 * IOCB_ERROR - Error
10430 * IOCB_SUCCESS - Success
10434 lpfc_sli_issue_fcp_io(struct lpfc_hba *phba, uint32_t ring_number,
10435 struct lpfc_iocbq *piocb, uint32_t flag)
10437 return phba->__lpfc_sli_issue_fcp_io(phba, ring_number, piocb, flag);
10441 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
10443 * This routine wraps the actual lockless version for issusing IOCB function
10444 * pointer from the lpfc_hba struct.
10447 * IOCB_ERROR - Error
10448 * IOCB_SUCCESS - Success
10452 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
10453 struct lpfc_iocbq *piocb, uint32_t flag)
10455 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10459 * lpfc_sli_api_table_setup - Set up sli api function jump table
10460 * @phba: The hba struct for which this call is being executed.
10461 * @dev_grp: The HBA PCI-Device group number.
10463 * This routine sets up the SLI interface API function jump table in @phba
10465 * Returns: 0 - success, -ENODEV - failure.
10468 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
10472 case LPFC_PCI_DEV_LP:
10473 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
10474 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
10475 phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s3;
10477 case LPFC_PCI_DEV_OC:
10478 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
10479 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
10480 phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s4;
10483 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10484 "1419 Invalid HBA PCI-device group: 0x%x\n",
10488 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
10493 * lpfc_sli4_calc_ring - Calculates which ring to use
10494 * @phba: Pointer to HBA context object.
10495 * @piocb: Pointer to command iocb.
10497 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
10498 * hba_wqidx, thus we need to calculate the corresponding ring.
10499 * Since ABORTS must go on the same WQ of the command they are
10500 * aborting, we use command's hba_wqidx.
10502 struct lpfc_sli_ring *
10503 lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
10505 struct lpfc_io_buf *lpfc_cmd;
10507 if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
10508 if (unlikely(!phba->sli4_hba.hdwq))
10511 * for abort iocb hba_wqidx should already
10512 * be setup based on what work queue we used.
10514 if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
10515 lpfc_cmd = (struct lpfc_io_buf *)piocb->context1;
10516 piocb->hba_wqidx = lpfc_cmd->hdwq_no;
10518 return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
10520 if (unlikely(!phba->sli4_hba.els_wq))
10522 piocb->hba_wqidx = 0;
10523 return phba->sli4_hba.els_wq->pring;
10528 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
10529 * @phba: Pointer to HBA context object.
10530 * @ring_number: Ring number
10531 * @piocb: Pointer to command iocb.
10532 * @flag: Flag indicating if this command can be put into txq.
10534 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
10535 * function. This function gets the hbalock and calls
10536 * __lpfc_sli_issue_iocb function and will return the error returned
10537 * by __lpfc_sli_issue_iocb function. This wrapper is used by
10538 * functions which do not hold hbalock.
10541 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
10542 struct lpfc_iocbq *piocb, uint32_t flag)
10544 struct lpfc_sli_ring *pring;
10545 struct lpfc_queue *eq;
10546 unsigned long iflags;
10549 if (phba->sli_rev == LPFC_SLI_REV4) {
10550 eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq;
10552 pring = lpfc_sli4_calc_ring(phba, piocb);
10553 if (unlikely(pring == NULL))
10556 spin_lock_irqsave(&pring->ring_lock, iflags);
10557 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10558 spin_unlock_irqrestore(&pring->ring_lock, iflags);
10560 lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH);
10562 /* For now, SLI2/3 will still use hbalock */
10563 spin_lock_irqsave(&phba->hbalock, iflags);
10564 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10565 spin_unlock_irqrestore(&phba->hbalock, iflags);
10571 * lpfc_extra_ring_setup - Extra ring setup function
10572 * @phba: Pointer to HBA context object.
10574 * This function is called while driver attaches with the
10575 * HBA to setup the extra ring. The extra ring is used
10576 * only when driver needs to support target mode functionality
10577 * or IP over FC functionalities.
10579 * This function is called with no lock held. SLI3 only.
10582 lpfc_extra_ring_setup( struct lpfc_hba *phba)
10584 struct lpfc_sli *psli;
10585 struct lpfc_sli_ring *pring;
10589 /* Adjust cmd/rsp ring iocb entries more evenly */
10591 /* Take some away from the FCP ring */
10592 pring = &psli->sli3_ring[LPFC_FCP_RING];
10593 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10594 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10595 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10596 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10598 /* and give them to the extra ring */
10599 pring = &psli->sli3_ring[LPFC_EXTRA_RING];
10601 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10602 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10603 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10604 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10606 /* Setup default profile for this ring */
10607 pring->iotag_max = 4096;
10608 pring->num_mask = 1;
10609 pring->prt[0].profile = 0; /* Mask 0 */
10610 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
10611 pring->prt[0].type = phba->cfg_multi_ring_type;
10612 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
10617 lpfc_sli_post_recovery_event(struct lpfc_hba *phba,
10618 struct lpfc_nodelist *ndlp)
10620 unsigned long iflags;
10621 struct lpfc_work_evt *evtp = &ndlp->recovery_evt;
10623 spin_lock_irqsave(&phba->hbalock, iflags);
10624 if (!list_empty(&evtp->evt_listp)) {
10625 spin_unlock_irqrestore(&phba->hbalock, iflags);
10629 /* Incrementing the reference count until the queued work is done. */
10630 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
10631 if (!evtp->evt_arg1) {
10632 spin_unlock_irqrestore(&phba->hbalock, iflags);
10635 evtp->evt = LPFC_EVT_RECOVER_PORT;
10636 list_add_tail(&evtp->evt_listp, &phba->work_list);
10637 spin_unlock_irqrestore(&phba->hbalock, iflags);
10639 lpfc_worker_wake_up(phba);
10642 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
10643 * @phba: Pointer to HBA context object.
10644 * @iocbq: Pointer to iocb object.
10646 * The async_event handler calls this routine when it receives
10647 * an ASYNC_STATUS_CN event from the port. The port generates
10648 * this event when an Abort Sequence request to an rport fails
10649 * twice in succession. The abort could be originated by the
10650 * driver or by the port. The ABTS could have been for an ELS
10651 * or FCP IO. The port only generates this event when an ABTS
10652 * fails to complete after one retry.
10655 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
10656 struct lpfc_iocbq *iocbq)
10658 struct lpfc_nodelist *ndlp = NULL;
10659 uint16_t rpi = 0, vpi = 0;
10660 struct lpfc_vport *vport = NULL;
10662 /* The rpi in the ulpContext is vport-sensitive. */
10663 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
10664 rpi = iocbq->iocb.ulpContext;
10666 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10667 "3092 Port generated ABTS async event "
10668 "on vpi %d rpi %d status 0x%x\n",
10669 vpi, rpi, iocbq->iocb.ulpStatus);
10671 vport = lpfc_find_vport_by_vpid(phba, vpi);
10674 ndlp = lpfc_findnode_rpi(vport, rpi);
10678 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
10679 lpfc_sli_abts_recover_port(vport, ndlp);
10683 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10684 "3095 Event Context not found, no "
10685 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
10686 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
10690 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
10691 * @phba: pointer to HBA context object.
10692 * @ndlp: nodelist pointer for the impacted rport.
10693 * @axri: pointer to the wcqe containing the failed exchange.
10695 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
10696 * port. The port generates this event when an abort exchange request to an
10697 * rport fails twice in succession with no reply. The abort could be originated
10698 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
10701 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
10702 struct lpfc_nodelist *ndlp,
10703 struct sli4_wcqe_xri_aborted *axri)
10705 uint32_t ext_status = 0;
10708 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
10709 "3115 Node Context not found, driver "
10710 "ignoring abts err event\n");
10714 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
10715 "3116 Port generated FCP XRI ABORT event on "
10716 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
10717 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
10718 bf_get(lpfc_wcqe_xa_xri, axri),
10719 bf_get(lpfc_wcqe_xa_status, axri),
10723 * Catch the ABTS protocol failure case. Older OCe FW releases returned
10724 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
10725 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
10727 ext_status = axri->parameter & IOERR_PARAM_MASK;
10728 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
10729 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
10730 lpfc_sli_post_recovery_event(phba, ndlp);
10734 * lpfc_sli_async_event_handler - ASYNC iocb handler function
10735 * @phba: Pointer to HBA context object.
10736 * @pring: Pointer to driver SLI ring object.
10737 * @iocbq: Pointer to iocb object.
10739 * This function is called by the slow ring event handler
10740 * function when there is an ASYNC event iocb in the ring.
10741 * This function is called with no lock held.
10742 * Currently this function handles only temperature related
10743 * ASYNC events. The function decodes the temperature sensor
10744 * event message and posts events for the management applications.
10747 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
10748 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
10752 struct temp_event temp_event_data;
10753 struct Scsi_Host *shost;
10756 icmd = &iocbq->iocb;
10757 evt_code = icmd->un.asyncstat.evt_code;
10759 switch (evt_code) {
10760 case ASYNC_TEMP_WARN:
10761 case ASYNC_TEMP_SAFE:
10762 temp_event_data.data = (uint32_t) icmd->ulpContext;
10763 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
10764 if (evt_code == ASYNC_TEMP_WARN) {
10765 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
10766 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10767 "0347 Adapter is very hot, please take "
10768 "corrective action. temperature : %d Celsius\n",
10769 (uint32_t) icmd->ulpContext);
10771 temp_event_data.event_code = LPFC_NORMAL_TEMP;
10772 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10773 "0340 Adapter temperature is OK now. "
10774 "temperature : %d Celsius\n",
10775 (uint32_t) icmd->ulpContext);
10778 /* Send temperature change event to applications */
10779 shost = lpfc_shost_from_vport(phba->pport);
10780 fc_host_post_vendor_event(shost, fc_get_event_number(),
10781 sizeof(temp_event_data), (char *) &temp_event_data,
10782 LPFC_NL_VENDOR_ID);
10784 case ASYNC_STATUS_CN:
10785 lpfc_sli_abts_err_handler(phba, iocbq);
10788 iocb_w = (uint32_t *) icmd;
10789 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10790 "0346 Ring %d handler: unexpected ASYNC_STATUS"
10792 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
10793 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
10794 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
10795 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
10796 pring->ringno, icmd->un.asyncstat.evt_code,
10797 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
10798 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
10799 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
10800 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
10808 * lpfc_sli4_setup - SLI ring setup function
10809 * @phba: Pointer to HBA context object.
10811 * lpfc_sli_setup sets up rings of the SLI interface with
10812 * number of iocbs per ring and iotags. This function is
10813 * called while driver attach to the HBA and before the
10814 * interrupts are enabled. So there is no need for locking.
10816 * This function always returns 0.
10819 lpfc_sli4_setup(struct lpfc_hba *phba)
10821 struct lpfc_sli_ring *pring;
10823 pring = phba->sli4_hba.els_wq->pring;
10824 pring->num_mask = LPFC_MAX_RING_MASK;
10825 pring->prt[0].profile = 0; /* Mask 0 */
10826 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
10827 pring->prt[0].type = FC_TYPE_ELS;
10828 pring->prt[0].lpfc_sli_rcv_unsol_event =
10829 lpfc_els_unsol_event;
10830 pring->prt[1].profile = 0; /* Mask 1 */
10831 pring->prt[1].rctl = FC_RCTL_ELS_REP;
10832 pring->prt[1].type = FC_TYPE_ELS;
10833 pring->prt[1].lpfc_sli_rcv_unsol_event =
10834 lpfc_els_unsol_event;
10835 pring->prt[2].profile = 0; /* Mask 2 */
10836 /* NameServer Inquiry */
10837 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
10839 pring->prt[2].type = FC_TYPE_CT;
10840 pring->prt[2].lpfc_sli_rcv_unsol_event =
10841 lpfc_ct_unsol_event;
10842 pring->prt[3].profile = 0; /* Mask 3 */
10843 /* NameServer response */
10844 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
10846 pring->prt[3].type = FC_TYPE_CT;
10847 pring->prt[3].lpfc_sli_rcv_unsol_event =
10848 lpfc_ct_unsol_event;
10853 * lpfc_sli_setup - SLI ring setup function
10854 * @phba: Pointer to HBA context object.
10856 * lpfc_sli_setup sets up rings of the SLI interface with
10857 * number of iocbs per ring and iotags. This function is
10858 * called while driver attach to the HBA and before the
10859 * interrupts are enabled. So there is no need for locking.
10861 * This function always returns 0. SLI3 only.
10864 lpfc_sli_setup(struct lpfc_hba *phba)
10866 int i, totiocbsize = 0;
10867 struct lpfc_sli *psli = &phba->sli;
10868 struct lpfc_sli_ring *pring;
10870 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
10871 psli->sli_flag = 0;
10873 psli->iocbq_lookup = NULL;
10874 psli->iocbq_lookup_len = 0;
10875 psli->last_iotag = 0;
10877 for (i = 0; i < psli->num_rings; i++) {
10878 pring = &psli->sli3_ring[i];
10880 case LPFC_FCP_RING: /* ring 0 - FCP */
10881 /* numCiocb and numRiocb are used in config_port */
10882 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
10883 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
10884 pring->sli.sli3.numCiocb +=
10885 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
10886 pring->sli.sli3.numRiocb +=
10887 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
10888 pring->sli.sli3.numCiocb +=
10889 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
10890 pring->sli.sli3.numRiocb +=
10891 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
10892 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10893 SLI3_IOCB_CMD_SIZE :
10894 SLI2_IOCB_CMD_SIZE;
10895 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10896 SLI3_IOCB_RSP_SIZE :
10897 SLI2_IOCB_RSP_SIZE;
10898 pring->iotag_ctr = 0;
10900 (phba->cfg_hba_queue_depth * 2);
10901 pring->fast_iotag = pring->iotag_max;
10902 pring->num_mask = 0;
10904 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
10905 /* numCiocb and numRiocb are used in config_port */
10906 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
10907 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
10908 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10909 SLI3_IOCB_CMD_SIZE :
10910 SLI2_IOCB_CMD_SIZE;
10911 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10912 SLI3_IOCB_RSP_SIZE :
10913 SLI2_IOCB_RSP_SIZE;
10914 pring->iotag_max = phba->cfg_hba_queue_depth;
10915 pring->num_mask = 0;
10917 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
10918 /* numCiocb and numRiocb are used in config_port */
10919 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
10920 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
10921 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
10922 SLI3_IOCB_CMD_SIZE :
10923 SLI2_IOCB_CMD_SIZE;
10924 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
10925 SLI3_IOCB_RSP_SIZE :
10926 SLI2_IOCB_RSP_SIZE;
10927 pring->fast_iotag = 0;
10928 pring->iotag_ctr = 0;
10929 pring->iotag_max = 4096;
10930 pring->lpfc_sli_rcv_async_status =
10931 lpfc_sli_async_event_handler;
10932 pring->num_mask = LPFC_MAX_RING_MASK;
10933 pring->prt[0].profile = 0; /* Mask 0 */
10934 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
10935 pring->prt[0].type = FC_TYPE_ELS;
10936 pring->prt[0].lpfc_sli_rcv_unsol_event =
10937 lpfc_els_unsol_event;
10938 pring->prt[1].profile = 0; /* Mask 1 */
10939 pring->prt[1].rctl = FC_RCTL_ELS_REP;
10940 pring->prt[1].type = FC_TYPE_ELS;
10941 pring->prt[1].lpfc_sli_rcv_unsol_event =
10942 lpfc_els_unsol_event;
10943 pring->prt[2].profile = 0; /* Mask 2 */
10944 /* NameServer Inquiry */
10945 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
10947 pring->prt[2].type = FC_TYPE_CT;
10948 pring->prt[2].lpfc_sli_rcv_unsol_event =
10949 lpfc_ct_unsol_event;
10950 pring->prt[3].profile = 0; /* Mask 3 */
10951 /* NameServer response */
10952 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
10954 pring->prt[3].type = FC_TYPE_CT;
10955 pring->prt[3].lpfc_sli_rcv_unsol_event =
10956 lpfc_ct_unsol_event;
10959 totiocbsize += (pring->sli.sli3.numCiocb *
10960 pring->sli.sli3.sizeCiocb) +
10961 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
10963 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
10964 /* Too many cmd / rsp ring entries in SLI2 SLIM */
10965 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
10966 "SLI2 SLIM Data: x%x x%lx\n",
10967 phba->brd_no, totiocbsize,
10968 (unsigned long) MAX_SLIM_IOCB_SIZE);
10970 if (phba->cfg_multi_ring_support == 2)
10971 lpfc_extra_ring_setup(phba);
10977 * lpfc_sli4_queue_init - Queue initialization function
10978 * @phba: Pointer to HBA context object.
10980 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
10981 * ring. This function also initializes ring indices of each ring.
10982 * This function is called during the initialization of the SLI
10983 * interface of an HBA.
10984 * This function is called with no lock held and always returns
10988 lpfc_sli4_queue_init(struct lpfc_hba *phba)
10990 struct lpfc_sli *psli;
10991 struct lpfc_sli_ring *pring;
10995 spin_lock_irq(&phba->hbalock);
10996 INIT_LIST_HEAD(&psli->mboxq);
10997 INIT_LIST_HEAD(&psli->mboxq_cmpl);
10998 /* Initialize list headers for txq and txcmplq as double linked lists */
10999 for (i = 0; i < phba->cfg_hdw_queue; i++) {
11000 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
11002 pring->ringno = LPFC_FCP_RING;
11003 pring->txcmplq_cnt = 0;
11004 INIT_LIST_HEAD(&pring->txq);
11005 INIT_LIST_HEAD(&pring->txcmplq);
11006 INIT_LIST_HEAD(&pring->iocb_continueq);
11007 spin_lock_init(&pring->ring_lock);
11009 pring = phba->sli4_hba.els_wq->pring;
11011 pring->ringno = LPFC_ELS_RING;
11012 pring->txcmplq_cnt = 0;
11013 INIT_LIST_HEAD(&pring->txq);
11014 INIT_LIST_HEAD(&pring->txcmplq);
11015 INIT_LIST_HEAD(&pring->iocb_continueq);
11016 spin_lock_init(&pring->ring_lock);
11018 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11019 pring = phba->sli4_hba.nvmels_wq->pring;
11021 pring->ringno = LPFC_ELS_RING;
11022 pring->txcmplq_cnt = 0;
11023 INIT_LIST_HEAD(&pring->txq);
11024 INIT_LIST_HEAD(&pring->txcmplq);
11025 INIT_LIST_HEAD(&pring->iocb_continueq);
11026 spin_lock_init(&pring->ring_lock);
11029 spin_unlock_irq(&phba->hbalock);
11033 * lpfc_sli_queue_init - Queue initialization function
11034 * @phba: Pointer to HBA context object.
11036 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
11037 * ring. This function also initializes ring indices of each ring.
11038 * This function is called during the initialization of the SLI
11039 * interface of an HBA.
11040 * This function is called with no lock held and always returns
11044 lpfc_sli_queue_init(struct lpfc_hba *phba)
11046 struct lpfc_sli *psli;
11047 struct lpfc_sli_ring *pring;
11051 spin_lock_irq(&phba->hbalock);
11052 INIT_LIST_HEAD(&psli->mboxq);
11053 INIT_LIST_HEAD(&psli->mboxq_cmpl);
11054 /* Initialize list headers for txq and txcmplq as double linked lists */
11055 for (i = 0; i < psli->num_rings; i++) {
11056 pring = &psli->sli3_ring[i];
11058 pring->sli.sli3.next_cmdidx = 0;
11059 pring->sli.sli3.local_getidx = 0;
11060 pring->sli.sli3.cmdidx = 0;
11061 INIT_LIST_HEAD(&pring->iocb_continueq);
11062 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
11063 INIT_LIST_HEAD(&pring->postbufq);
11065 INIT_LIST_HEAD(&pring->txq);
11066 INIT_LIST_HEAD(&pring->txcmplq);
11067 spin_lock_init(&pring->ring_lock);
11069 spin_unlock_irq(&phba->hbalock);
11073 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
11074 * @phba: Pointer to HBA context object.
11076 * This routine flushes the mailbox command subsystem. It will unconditionally
11077 * flush all the mailbox commands in the three possible stages in the mailbox
11078 * command sub-system: pending mailbox command queue; the outstanding mailbox
11079 * command; and completed mailbox command queue. It is caller's responsibility
11080 * to make sure that the driver is in the proper state to flush the mailbox
11081 * command sub-system. Namely, the posting of mailbox commands into the
11082 * pending mailbox command queue from the various clients must be stopped;
11083 * either the HBA is in a state that it will never works on the outstanding
11084 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
11085 * mailbox command has been completed.
11088 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
11090 LIST_HEAD(completions);
11091 struct lpfc_sli *psli = &phba->sli;
11093 unsigned long iflag;
11095 /* Disable softirqs, including timers from obtaining phba->hbalock */
11096 local_bh_disable();
11098 /* Flush all the mailbox commands in the mbox system */
11099 spin_lock_irqsave(&phba->hbalock, iflag);
11101 /* The pending mailbox command queue */
11102 list_splice_init(&phba->sli.mboxq, &completions);
11103 /* The outstanding active mailbox command */
11104 if (psli->mbox_active) {
11105 list_add_tail(&psli->mbox_active->list, &completions);
11106 psli->mbox_active = NULL;
11107 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11109 /* The completed mailbox command queue */
11110 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
11111 spin_unlock_irqrestore(&phba->hbalock, iflag);
11113 /* Enable softirqs again, done with phba->hbalock */
11116 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
11117 while (!list_empty(&completions)) {
11118 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
11119 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
11120 if (pmb->mbox_cmpl)
11121 pmb->mbox_cmpl(phba, pmb);
11126 * lpfc_sli_host_down - Vport cleanup function
11127 * @vport: Pointer to virtual port object.
11129 * lpfc_sli_host_down is called to clean up the resources
11130 * associated with a vport before destroying virtual
11131 * port data structures.
11132 * This function does following operations:
11133 * - Free discovery resources associated with this virtual
11135 * - Free iocbs associated with this virtual port in
11137 * - Send abort for all iocb commands associated with this
11138 * vport in txcmplq.
11140 * This function is called with no lock held and always returns 1.
11143 lpfc_sli_host_down(struct lpfc_vport *vport)
11145 LIST_HEAD(completions);
11146 struct lpfc_hba *phba = vport->phba;
11147 struct lpfc_sli *psli = &phba->sli;
11148 struct lpfc_queue *qp = NULL;
11149 struct lpfc_sli_ring *pring;
11150 struct lpfc_iocbq *iocb, *next_iocb;
11152 unsigned long flags = 0;
11153 uint16_t prev_pring_flag;
11155 lpfc_cleanup_discovery_resources(vport);
11157 spin_lock_irqsave(&phba->hbalock, flags);
11160 * Error everything on the txq since these iocbs
11161 * have not been given to the FW yet.
11162 * Also issue ABTS for everything on the txcmplq
11164 if (phba->sli_rev != LPFC_SLI_REV4) {
11165 for (i = 0; i < psli->num_rings; i++) {
11166 pring = &psli->sli3_ring[i];
11167 prev_pring_flag = pring->flag;
11168 /* Only slow rings */
11169 if (pring->ringno == LPFC_ELS_RING) {
11170 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11171 /* Set the lpfc data pending flag */
11172 set_bit(LPFC_DATA_READY, &phba->data_flags);
11174 list_for_each_entry_safe(iocb, next_iocb,
11175 &pring->txq, list) {
11176 if (iocb->vport != vport)
11178 list_move_tail(&iocb->list, &completions);
11180 list_for_each_entry_safe(iocb, next_iocb,
11181 &pring->txcmplq, list) {
11182 if (iocb->vport != vport)
11184 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
11187 pring->flag = prev_pring_flag;
11190 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11194 if (pring == phba->sli4_hba.els_wq->pring) {
11195 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11196 /* Set the lpfc data pending flag */
11197 set_bit(LPFC_DATA_READY, &phba->data_flags);
11199 prev_pring_flag = pring->flag;
11200 spin_lock(&pring->ring_lock);
11201 list_for_each_entry_safe(iocb, next_iocb,
11202 &pring->txq, list) {
11203 if (iocb->vport != vport)
11205 list_move_tail(&iocb->list, &completions);
11207 spin_unlock(&pring->ring_lock);
11208 list_for_each_entry_safe(iocb, next_iocb,
11209 &pring->txcmplq, list) {
11210 if (iocb->vport != vport)
11212 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
11215 pring->flag = prev_pring_flag;
11218 spin_unlock_irqrestore(&phba->hbalock, flags);
11220 /* Make sure HBA is alive */
11221 lpfc_issue_hb_tmo(phba);
11223 /* Cancel all the IOCBs from the completions list */
11224 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11230 * lpfc_sli_hba_down - Resource cleanup function for the HBA
11231 * @phba: Pointer to HBA context object.
11233 * This function cleans up all iocb, buffers, mailbox commands
11234 * while shutting down the HBA. This function is called with no
11235 * lock held and always returns 1.
11236 * This function does the following to cleanup driver resources:
11237 * - Free discovery resources for each virtual port
11238 * - Cleanup any pending fabric iocbs
11239 * - Iterate through the iocb txq and free each entry
11241 * - Free up any buffer posted to the HBA
11242 * - Free mailbox commands in the mailbox queue.
11245 lpfc_sli_hba_down(struct lpfc_hba *phba)
11247 LIST_HEAD(completions);
11248 struct lpfc_sli *psli = &phba->sli;
11249 struct lpfc_queue *qp = NULL;
11250 struct lpfc_sli_ring *pring;
11251 struct lpfc_dmabuf *buf_ptr;
11252 unsigned long flags = 0;
11255 /* Shutdown the mailbox command sub-system */
11256 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
11258 lpfc_hba_down_prep(phba);
11260 /* Disable softirqs, including timers from obtaining phba->hbalock */
11261 local_bh_disable();
11263 lpfc_fabric_abort_hba(phba);
11265 spin_lock_irqsave(&phba->hbalock, flags);
11268 * Error everything on the txq since these iocbs
11269 * have not been given to the FW yet.
11271 if (phba->sli_rev != LPFC_SLI_REV4) {
11272 for (i = 0; i < psli->num_rings; i++) {
11273 pring = &psli->sli3_ring[i];
11274 /* Only slow rings */
11275 if (pring->ringno == LPFC_ELS_RING) {
11276 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11277 /* Set the lpfc data pending flag */
11278 set_bit(LPFC_DATA_READY, &phba->data_flags);
11280 list_splice_init(&pring->txq, &completions);
11283 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11287 spin_lock(&pring->ring_lock);
11288 list_splice_init(&pring->txq, &completions);
11289 spin_unlock(&pring->ring_lock);
11290 if (pring == phba->sli4_hba.els_wq->pring) {
11291 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11292 /* Set the lpfc data pending flag */
11293 set_bit(LPFC_DATA_READY, &phba->data_flags);
11297 spin_unlock_irqrestore(&phba->hbalock, flags);
11299 /* Cancel all the IOCBs from the completions list */
11300 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11303 spin_lock_irqsave(&phba->hbalock, flags);
11304 list_splice_init(&phba->elsbuf, &completions);
11305 phba->elsbuf_cnt = 0;
11306 phba->elsbuf_prev_cnt = 0;
11307 spin_unlock_irqrestore(&phba->hbalock, flags);
11309 while (!list_empty(&completions)) {
11310 list_remove_head(&completions, buf_ptr,
11311 struct lpfc_dmabuf, list);
11312 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
11316 /* Enable softirqs again, done with phba->hbalock */
11319 /* Return any active mbox cmds */
11320 del_timer_sync(&psli->mbox_tmo);
11322 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
11323 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
11324 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
11330 * lpfc_sli_pcimem_bcopy - SLI memory copy function
11331 * @srcp: Source memory pointer.
11332 * @destp: Destination memory pointer.
11333 * @cnt: Number of words required to be copied.
11335 * This function is used for copying data between driver memory
11336 * and the SLI memory. This function also changes the endianness
11337 * of each word if native endianness is different from SLI
11338 * endianness. This function can be called with or without
11342 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
11344 uint32_t *src = srcp;
11345 uint32_t *dest = destp;
11349 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
11351 ldata = le32_to_cpu(ldata);
11360 * lpfc_sli_bemem_bcopy - SLI memory copy function
11361 * @srcp: Source memory pointer.
11362 * @destp: Destination memory pointer.
11363 * @cnt: Number of words required to be copied.
11365 * This function is used for copying data between a data structure
11366 * with big endian representation to local endianness.
11367 * This function can be called with or without lock.
11370 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
11372 uint32_t *src = srcp;
11373 uint32_t *dest = destp;
11377 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
11379 ldata = be32_to_cpu(ldata);
11387 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
11388 * @phba: Pointer to HBA context object.
11389 * @pring: Pointer to driver SLI ring object.
11390 * @mp: Pointer to driver buffer object.
11392 * This function is called with no lock held.
11393 * It always return zero after adding the buffer to the postbufq
11397 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11398 struct lpfc_dmabuf *mp)
11400 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
11402 spin_lock_irq(&phba->hbalock);
11403 list_add_tail(&mp->list, &pring->postbufq);
11404 pring->postbufq_cnt++;
11405 spin_unlock_irq(&phba->hbalock);
11410 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
11411 * @phba: Pointer to HBA context object.
11413 * When HBQ is enabled, buffers are searched based on tags. This function
11414 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
11415 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
11416 * does not conflict with tags of buffer posted for unsolicited events.
11417 * The function returns the allocated tag. The function is called with
11421 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
11423 spin_lock_irq(&phba->hbalock);
11424 phba->buffer_tag_count++;
11426 * Always set the QUE_BUFTAG_BIT to distiguish between
11427 * a tag assigned by HBQ.
11429 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
11430 spin_unlock_irq(&phba->hbalock);
11431 return phba->buffer_tag_count;
11435 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
11436 * @phba: Pointer to HBA context object.
11437 * @pring: Pointer to driver SLI ring object.
11438 * @tag: Buffer tag.
11440 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
11441 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
11442 * iocb is posted to the response ring with the tag of the buffer.
11443 * This function searches the pring->postbufq list using the tag
11444 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
11445 * iocb. If the buffer is found then lpfc_dmabuf object of the
11446 * buffer is returned to the caller else NULL is returned.
11447 * This function is called with no lock held.
11449 struct lpfc_dmabuf *
11450 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11453 struct lpfc_dmabuf *mp, *next_mp;
11454 struct list_head *slp = &pring->postbufq;
11456 /* Search postbufq, from the beginning, looking for a match on tag */
11457 spin_lock_irq(&phba->hbalock);
11458 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
11459 if (mp->buffer_tag == tag) {
11460 list_del_init(&mp->list);
11461 pring->postbufq_cnt--;
11462 spin_unlock_irq(&phba->hbalock);
11467 spin_unlock_irq(&phba->hbalock);
11468 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11469 "0402 Cannot find virtual addr for buffer tag on "
11470 "ring %d Data x%lx x%px x%px x%x\n",
11471 pring->ringno, (unsigned long) tag,
11472 slp->next, slp->prev, pring->postbufq_cnt);
11478 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
11479 * @phba: Pointer to HBA context object.
11480 * @pring: Pointer to driver SLI ring object.
11481 * @phys: DMA address of the buffer.
11483 * This function searches the buffer list using the dma_address
11484 * of unsolicited event to find the driver's lpfc_dmabuf object
11485 * corresponding to the dma_address. The function returns the
11486 * lpfc_dmabuf object if a buffer is found else it returns NULL.
11487 * This function is called by the ct and els unsolicited event
11488 * handlers to get the buffer associated with the unsolicited
11491 * This function is called with no lock held.
11493 struct lpfc_dmabuf *
11494 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11497 struct lpfc_dmabuf *mp, *next_mp;
11498 struct list_head *slp = &pring->postbufq;
11500 /* Search postbufq, from the beginning, looking for a match on phys */
11501 spin_lock_irq(&phba->hbalock);
11502 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
11503 if (mp->phys == phys) {
11504 list_del_init(&mp->list);
11505 pring->postbufq_cnt--;
11506 spin_unlock_irq(&phba->hbalock);
11511 spin_unlock_irq(&phba->hbalock);
11512 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11513 "0410 Cannot find virtual addr for mapped buf on "
11514 "ring %d Data x%llx x%px x%px x%x\n",
11515 pring->ringno, (unsigned long long)phys,
11516 slp->next, slp->prev, pring->postbufq_cnt);
11521 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
11522 * @phba: Pointer to HBA context object.
11523 * @cmdiocb: Pointer to driver command iocb object.
11524 * @rspiocb: Pointer to driver response iocb object.
11526 * This function is the completion handler for the abort iocbs for
11527 * ELS commands. This function is called from the ELS ring event
11528 * handler with no lock held. This function frees memory resources
11529 * associated with the abort iocb.
11532 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11533 struct lpfc_iocbq *rspiocb)
11535 IOCB_t *irsp = &rspiocb->iocb;
11536 uint16_t abort_iotag, abort_context;
11537 struct lpfc_iocbq *abort_iocb = NULL;
11539 if (irsp->ulpStatus) {
11542 * Assume that the port already completed and returned, or
11543 * will return the iocb. Just Log the message.
11545 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
11546 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
11548 spin_lock_irq(&phba->hbalock);
11549 if (phba->sli_rev < LPFC_SLI_REV4) {
11550 if (irsp->ulpCommand == CMD_ABORT_XRI_CX &&
11551 irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
11552 irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) {
11553 spin_unlock_irq(&phba->hbalock);
11556 if (abort_iotag != 0 &&
11557 abort_iotag <= phba->sli.last_iotag)
11559 phba->sli.iocbq_lookup[abort_iotag];
11561 /* For sli4 the abort_tag is the XRI,
11562 * so the abort routine puts the iotag of the iocb
11563 * being aborted in the context field of the abort
11566 abort_iocb = phba->sli.iocbq_lookup[abort_context];
11568 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
11569 "0327 Cannot abort els iocb x%px "
11570 "with tag %x context %x, abort status %x, "
11572 abort_iocb, abort_iotag, abort_context,
11573 irsp->ulpStatus, irsp->un.ulpWord[4]);
11575 spin_unlock_irq(&phba->hbalock);
11578 lpfc_sli_release_iocbq(phba, cmdiocb);
11583 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
11584 * @phba: Pointer to HBA context object.
11585 * @cmdiocb: Pointer to driver command iocb object.
11586 * @rspiocb: Pointer to driver response iocb object.
11588 * The function is called from SLI ring event handler with no
11589 * lock held. This function is the completion handler for ELS commands
11590 * which are aborted. The function frees memory resources used for
11591 * the aborted ELS commands.
11594 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11595 struct lpfc_iocbq *rspiocb)
11597 IOCB_t *irsp = &rspiocb->iocb;
11599 /* ELS cmd tag <ulpIoTag> completes */
11600 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
11601 "0139 Ignoring ELS cmd tag x%x completion Data: "
11603 irsp->ulpIoTag, irsp->ulpStatus,
11604 irsp->un.ulpWord[4], irsp->ulpTimeout);
11605 lpfc_nlp_put((struct lpfc_nodelist *)cmdiocb->context1);
11606 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
11607 lpfc_ct_free_iocb(phba, cmdiocb);
11609 lpfc_els_free_iocb(phba, cmdiocb);
11613 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
11614 * @phba: Pointer to HBA context object.
11615 * @pring: Pointer to driver SLI ring object.
11616 * @cmdiocb: Pointer to driver command iocb object.
11617 * @cmpl: completion function.
11619 * This function issues an abort iocb for the provided command iocb. In case
11620 * of unloading, the abort iocb will not be issued to commands on the ELS
11621 * ring. Instead, the callback function shall be changed to those commands
11622 * so that nothing happens when them finishes. This function is called with
11623 * hbalock held andno ring_lock held (SLI4). The function returns IOCB_SUCCESS
11624 * when the command iocb is an abort request.
11628 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
11629 struct lpfc_iocbq *cmdiocb, void *cmpl)
11631 struct lpfc_vport *vport = cmdiocb->vport;
11632 struct lpfc_iocbq *abtsiocbp;
11633 IOCB_t *icmd = NULL;
11634 IOCB_t *iabt = NULL;
11635 int retval = IOCB_ERROR;
11636 unsigned long iflags;
11637 struct lpfc_nodelist *ndlp;
11640 * There are certain command types we don't want to abort. And we
11641 * don't want to abort commands that are already in the process of
11644 icmd = &cmdiocb->iocb;
11645 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
11646 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
11647 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
11648 return IOCB_ABORTING;
11651 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
11652 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
11654 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
11659 * If we're unloading, don't abort iocb on the ELS ring, but change
11660 * the callback so that nothing happens when it finishes.
11662 if ((vport->load_flag & FC_UNLOADING) &&
11663 pring->ringno == LPFC_ELS_RING) {
11664 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
11665 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
11667 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
11671 /* issue ABTS for this IOCB based on iotag */
11672 abtsiocbp = __lpfc_sli_get_iocbq(phba);
11673 if (abtsiocbp == NULL)
11674 return IOCB_NORESOURCE;
11676 /* This signals the response to set the correct status
11677 * before calling the completion handler
11679 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
11681 iabt = &abtsiocbp->iocb;
11682 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
11683 iabt->un.acxri.abortContextTag = icmd->ulpContext;
11684 if (phba->sli_rev == LPFC_SLI_REV4) {
11685 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
11686 if (pring->ringno == LPFC_ELS_RING)
11687 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
11689 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
11690 if (pring->ringno == LPFC_ELS_RING) {
11691 ndlp = (struct lpfc_nodelist *)(cmdiocb->context1);
11692 iabt->un.acxri.abortContextTag = ndlp->nlp_rpi;
11696 iabt->ulpClass = icmd->ulpClass;
11698 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11699 abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
11700 if (cmdiocb->iocb_flag & LPFC_IO_FCP) {
11701 abtsiocbp->iocb_flag |= LPFC_IO_FCP;
11702 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
11704 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
11705 abtsiocbp->iocb_flag |= LPFC_IO_FOF;
11707 if (phba->link_state >= LPFC_LINK_UP)
11708 iabt->ulpCommand = CMD_ABORT_XRI_CN;
11710 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
11713 abtsiocbp->iocb_cmpl = cmpl;
11715 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
11716 abtsiocbp->vport = vport;
11718 if (phba->sli_rev == LPFC_SLI_REV4) {
11719 pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
11720 if (unlikely(pring == NULL))
11721 goto abort_iotag_exit;
11722 /* Note: both hbalock and ring_lock need to be set here */
11723 spin_lock_irqsave(&pring->ring_lock, iflags);
11724 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
11726 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11728 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
11734 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
11735 "0339 Abort xri x%x, original iotag x%x, "
11736 "abort cmd iotag x%x retval x%x\n",
11737 iabt->un.acxri.abortIoTag,
11738 iabt->un.acxri.abortContextTag,
11739 abtsiocbp->iotag, retval);
11742 cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
11743 __lpfc_sli_release_iocbq(phba, abtsiocbp);
11747 * Caller to this routine should check for IOCB_ERROR
11748 * and handle it properly. This routine no longer removes
11749 * iocb off txcmplq and call compl in case of IOCB_ERROR.
11755 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
11756 * @phba: pointer to lpfc HBA data structure.
11758 * This routine will abort all pending and outstanding iocbs to an HBA.
11761 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
11763 struct lpfc_sli *psli = &phba->sli;
11764 struct lpfc_sli_ring *pring;
11765 struct lpfc_queue *qp = NULL;
11768 if (phba->sli_rev != LPFC_SLI_REV4) {
11769 for (i = 0; i < psli->num_rings; i++) {
11770 pring = &psli->sli3_ring[i];
11771 lpfc_sli_abort_iocb_ring(phba, pring);
11775 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11779 lpfc_sli_abort_iocb_ring(phba, pring);
11784 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
11785 * @iocbq: Pointer to driver iocb object.
11786 * @vport: Pointer to driver virtual port object.
11787 * @tgt_id: SCSI ID of the target.
11788 * @lun_id: LUN ID of the scsi device.
11789 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
11791 * This function acts as an iocb filter for functions which abort or count
11792 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
11793 * 0 if the filtering criteria is met for the given iocb and will return
11794 * 1 if the filtering criteria is not met.
11795 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
11796 * given iocb is for the SCSI device specified by vport, tgt_id and
11797 * lun_id parameter.
11798 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
11799 * given iocb is for the SCSI target specified by vport and tgt_id
11801 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
11802 * given iocb is for the SCSI host associated with the given vport.
11803 * This function is called with no locks held.
11806 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
11807 uint16_t tgt_id, uint64_t lun_id,
11808 lpfc_ctx_cmd ctx_cmd)
11810 struct lpfc_io_buf *lpfc_cmd;
11813 if (!iocbq || iocbq->vport != vport)
11816 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
11817 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ))
11820 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
11822 if (lpfc_cmd->pCmd == NULL)
11827 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
11828 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
11829 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
11833 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
11834 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
11837 case LPFC_CTX_HOST:
11841 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
11842 __func__, ctx_cmd);
11850 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
11851 * @vport: Pointer to virtual port.
11852 * @tgt_id: SCSI ID of the target.
11853 * @lun_id: LUN ID of the scsi device.
11854 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11856 * This function returns number of FCP commands pending for the vport.
11857 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
11858 * commands pending on the vport associated with SCSI device specified
11859 * by tgt_id and lun_id parameters.
11860 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
11861 * commands pending on the vport associated with SCSI target specified
11862 * by tgt_id parameter.
11863 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
11864 * commands pending on the vport.
11865 * This function returns the number of iocbs which satisfy the filter.
11866 * This function is called without any lock held.
11869 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
11870 lpfc_ctx_cmd ctx_cmd)
11872 struct lpfc_hba *phba = vport->phba;
11873 struct lpfc_iocbq *iocbq;
11876 spin_lock_irq(&phba->hbalock);
11877 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
11878 iocbq = phba->sli.iocbq_lookup[i];
11880 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
11884 spin_unlock_irq(&phba->hbalock);
11890 * lpfc_sli4_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
11891 * @phba: Pointer to HBA context object
11892 * @cmdiocb: Pointer to command iocb object.
11893 * @wcqe: pointer to the complete wcqe
11895 * This function is called when an aborted FCP iocb completes. This
11896 * function is called by the ring event handler with no lock held.
11897 * This function frees the iocb. It is called for sli-4 adapters.
11900 lpfc_sli4_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11901 struct lpfc_wcqe_complete *wcqe)
11903 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11904 "3017 ABORT_XRI_CN completing on rpi x%x "
11905 "original iotag x%x, abort cmd iotag x%x "
11906 "status 0x%x, reason 0x%x\n",
11907 cmdiocb->iocb.un.acxri.abortContextTag,
11908 cmdiocb->iocb.un.acxri.abortIoTag,
11910 (bf_get(lpfc_wcqe_c_status, wcqe)
11911 & LPFC_IOCB_STATUS_MASK),
11913 lpfc_sli_release_iocbq(phba, cmdiocb);
11917 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
11918 * @phba: Pointer to HBA context object
11919 * @cmdiocb: Pointer to command iocb object.
11920 * @rspiocb: Pointer to response iocb object.
11922 * This function is called when an aborted FCP iocb completes. This
11923 * function is called by the ring event handler with no lock held.
11924 * This function frees the iocb.
11927 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
11928 struct lpfc_iocbq *rspiocb)
11930 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11931 "3096 ABORT_XRI_CN completing on rpi x%x "
11932 "original iotag x%x, abort cmd iotag x%x "
11933 "status 0x%x, reason 0x%x\n",
11934 cmdiocb->iocb.un.acxri.abortContextTag,
11935 cmdiocb->iocb.un.acxri.abortIoTag,
11936 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
11937 rspiocb->iocb.un.ulpWord[4]);
11938 lpfc_sli_release_iocbq(phba, cmdiocb);
11943 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
11944 * @vport: Pointer to virtual port.
11945 * @pring: Pointer to driver SLI ring object.
11946 * @tgt_id: SCSI ID of the target.
11947 * @lun_id: LUN ID of the scsi device.
11948 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11950 * This function sends an abort command for every SCSI command
11951 * associated with the given virtual port pending on the ring
11952 * filtered by lpfc_sli_validate_fcp_iocb function.
11953 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
11954 * FCP iocbs associated with lun specified by tgt_id and lun_id
11956 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
11957 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11958 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
11959 * FCP iocbs associated with virtual port.
11960 * This function returns number of iocbs it failed to abort.
11961 * This function is called with no locks held.
11964 lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
11965 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
11967 struct lpfc_hba *phba = vport->phba;
11968 struct lpfc_iocbq *iocbq;
11969 int errcnt = 0, ret_val = 0;
11970 unsigned long iflags;
11973 /* all I/Os are in process of being flushed */
11974 if (phba->hba_flag & HBA_IOQ_FLUSH)
11977 for (i = 1; i <= phba->sli.last_iotag; i++) {
11978 iocbq = phba->sli.iocbq_lookup[i];
11980 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
11984 spin_lock_irqsave(&phba->hbalock, iflags);
11985 ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocbq,
11986 lpfc_sli_abort_fcp_cmpl);
11987 spin_unlock_irqrestore(&phba->hbalock, iflags);
11988 if (ret_val != IOCB_SUCCESS)
11996 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
11997 * @vport: Pointer to virtual port.
11998 * @pring: Pointer to driver SLI ring object.
11999 * @tgt_id: SCSI ID of the target.
12000 * @lun_id: LUN ID of the scsi device.
12001 * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12003 * This function sends an abort command for every SCSI command
12004 * associated with the given virtual port pending on the ring
12005 * filtered by lpfc_sli_validate_fcp_iocb function.
12006 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
12007 * FCP iocbs associated with lun specified by tgt_id and lun_id
12009 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
12010 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
12011 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
12012 * FCP iocbs associated with virtual port.
12013 * This function returns number of iocbs it aborted .
12014 * This function is called with no locks held right after a taskmgmt
12018 lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
12019 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
12021 struct lpfc_hba *phba = vport->phba;
12022 struct lpfc_io_buf *lpfc_cmd;
12023 struct lpfc_iocbq *abtsiocbq;
12024 struct lpfc_nodelist *ndlp;
12025 struct lpfc_iocbq *iocbq;
12027 int sum, i, ret_val;
12028 unsigned long iflags;
12029 struct lpfc_sli_ring *pring_s4 = NULL;
12031 spin_lock_irqsave(&phba->hbalock, iflags);
12033 /* all I/Os are in process of being flushed */
12034 if (phba->hba_flag & HBA_IOQ_FLUSH) {
12035 spin_unlock_irqrestore(&phba->hbalock, iflags);
12040 for (i = 1; i <= phba->sli.last_iotag; i++) {
12041 iocbq = phba->sli.iocbq_lookup[i];
12043 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12047 /* Guard against IO completion being called at same time */
12048 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
12049 spin_lock(&lpfc_cmd->buf_lock);
12051 if (!lpfc_cmd->pCmd) {
12052 spin_unlock(&lpfc_cmd->buf_lock);
12056 if (phba->sli_rev == LPFC_SLI_REV4) {
12058 phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
12060 spin_unlock(&lpfc_cmd->buf_lock);
12063 /* Note: both hbalock and ring_lock must be set here */
12064 spin_lock(&pring_s4->ring_lock);
12068 * If the iocbq is already being aborted, don't take a second
12069 * action, but do count it.
12071 if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) ||
12072 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
12073 if (phba->sli_rev == LPFC_SLI_REV4)
12074 spin_unlock(&pring_s4->ring_lock);
12075 spin_unlock(&lpfc_cmd->buf_lock);
12079 /* issue ABTS for this IOCB based on iotag */
12080 abtsiocbq = __lpfc_sli_get_iocbq(phba);
12082 if (phba->sli_rev == LPFC_SLI_REV4)
12083 spin_unlock(&pring_s4->ring_lock);
12084 spin_unlock(&lpfc_cmd->buf_lock);
12088 icmd = &iocbq->iocb;
12089 abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
12090 abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
12091 if (phba->sli_rev == LPFC_SLI_REV4)
12092 abtsiocbq->iocb.un.acxri.abortIoTag =
12093 iocbq->sli4_xritag;
12095 abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
12096 abtsiocbq->iocb.ulpLe = 1;
12097 abtsiocbq->iocb.ulpClass = icmd->ulpClass;
12098 abtsiocbq->vport = vport;
12100 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
12101 abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
12102 if (iocbq->iocb_flag & LPFC_IO_FCP)
12103 abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
12104 if (iocbq->iocb_flag & LPFC_IO_FOF)
12105 abtsiocbq->iocb_flag |= LPFC_IO_FOF;
12107 ndlp = lpfc_cmd->rdata->pnode;
12109 if (lpfc_is_link_up(phba) &&
12110 (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
12111 abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
12113 abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
12115 /* Setup callback routine and issue the command. */
12116 abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
12119 * Indicate the IO is being aborted by the driver and set
12120 * the caller's flag into the aborted IO.
12122 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
12124 if (phba->sli_rev == LPFC_SLI_REV4) {
12125 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
12127 spin_unlock(&pring_s4->ring_lock);
12129 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
12133 spin_unlock(&lpfc_cmd->buf_lock);
12135 if (ret_val == IOCB_ERROR)
12136 __lpfc_sli_release_iocbq(phba, abtsiocbq);
12140 spin_unlock_irqrestore(&phba->hbalock, iflags);
12145 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
12146 * @phba: Pointer to HBA context object.
12147 * @cmdiocbq: Pointer to command iocb.
12148 * @rspiocbq: Pointer to response iocb.
12150 * This function is the completion handler for iocbs issued using
12151 * lpfc_sli_issue_iocb_wait function. This function is called by the
12152 * ring event handler function without any lock held. This function
12153 * can be called from both worker thread context and interrupt
12154 * context. This function also can be called from other thread which
12155 * cleans up the SLI layer objects.
12156 * This function copy the contents of the response iocb to the
12157 * response iocb memory object provided by the caller of
12158 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
12159 * sleeps for the iocb completion.
12162 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
12163 struct lpfc_iocbq *cmdiocbq,
12164 struct lpfc_iocbq *rspiocbq)
12166 wait_queue_head_t *pdone_q;
12167 unsigned long iflags;
12168 struct lpfc_io_buf *lpfc_cmd;
12170 spin_lock_irqsave(&phba->hbalock, iflags);
12171 if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
12174 * A time out has occurred for the iocb. If a time out
12175 * completion handler has been supplied, call it. Otherwise,
12176 * just free the iocbq.
12179 spin_unlock_irqrestore(&phba->hbalock, iflags);
12180 cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
12181 cmdiocbq->wait_iocb_cmpl = NULL;
12182 if (cmdiocbq->iocb_cmpl)
12183 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
12185 lpfc_sli_release_iocbq(phba, cmdiocbq);
12189 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
12190 if (cmdiocbq->context2 && rspiocbq)
12191 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
12192 &rspiocbq->iocb, sizeof(IOCB_t));
12194 /* Set the exchange busy flag for task management commands */
12195 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
12196 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
12197 lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
12199 if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY))
12200 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
12202 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
12205 pdone_q = cmdiocbq->context_un.wait_queue;
12208 spin_unlock_irqrestore(&phba->hbalock, iflags);
12213 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
12214 * @phba: Pointer to HBA context object..
12215 * @piocbq: Pointer to command iocb.
12216 * @flag: Flag to test.
12218 * This routine grabs the hbalock and then test the iocb_flag to
12219 * see if the passed in flag is set.
12221 * 1 if flag is set.
12222 * 0 if flag is not set.
12225 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
12226 struct lpfc_iocbq *piocbq, uint32_t flag)
12228 unsigned long iflags;
12231 spin_lock_irqsave(&phba->hbalock, iflags);
12232 ret = piocbq->iocb_flag & flag;
12233 spin_unlock_irqrestore(&phba->hbalock, iflags);
12239 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
12240 * @phba: Pointer to HBA context object..
12241 * @ring_number: Ring number
12242 * @piocb: Pointer to command iocb.
12243 * @prspiocbq: Pointer to response iocb.
12244 * @timeout: Timeout in number of seconds.
12246 * This function issues the iocb to firmware and waits for the
12247 * iocb to complete. The iocb_cmpl field of the shall be used
12248 * to handle iocbs which time out. If the field is NULL, the
12249 * function shall free the iocbq structure. If more clean up is
12250 * needed, the caller is expected to provide a completion function
12251 * that will provide the needed clean up. If the iocb command is
12252 * not completed within timeout seconds, the function will either
12253 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
12254 * completion function set in the iocb_cmpl field and then return
12255 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
12256 * resources if this function returns IOCB_TIMEDOUT.
12257 * The function waits for the iocb completion using an
12258 * non-interruptible wait.
12259 * This function will sleep while waiting for iocb completion.
12260 * So, this function should not be called from any context which
12261 * does not allow sleeping. Due to the same reason, this function
12262 * cannot be called with interrupt disabled.
12263 * This function assumes that the iocb completions occur while
12264 * this function sleep. So, this function cannot be called from
12265 * the thread which process iocb completion for this ring.
12266 * This function clears the iocb_flag of the iocb object before
12267 * issuing the iocb and the iocb completion handler sets this
12268 * flag and wakes this thread when the iocb completes.
12269 * The contents of the response iocb will be copied to prspiocbq
12270 * by the completion handler when the command completes.
12271 * This function returns IOCB_SUCCESS when success.
12272 * This function is called with no lock held.
12275 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
12276 uint32_t ring_number,
12277 struct lpfc_iocbq *piocb,
12278 struct lpfc_iocbq *prspiocbq,
12281 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
12282 long timeleft, timeout_req = 0;
12283 int retval = IOCB_SUCCESS;
12285 struct lpfc_iocbq *iocb;
12287 int txcmplq_cnt = 0;
12288 struct lpfc_sli_ring *pring;
12289 unsigned long iflags;
12290 bool iocb_completed = true;
12292 if (phba->sli_rev >= LPFC_SLI_REV4)
12293 pring = lpfc_sli4_calc_ring(phba, piocb);
12295 pring = &phba->sli.sli3_ring[ring_number];
12297 * If the caller has provided a response iocbq buffer, then context2
12298 * is NULL or its an error.
12301 if (piocb->context2)
12303 piocb->context2 = prspiocbq;
12306 piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
12307 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
12308 piocb->context_un.wait_queue = &done_q;
12309 piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
12311 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
12312 if (lpfc_readl(phba->HCregaddr, &creg_val))
12314 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
12315 writel(creg_val, phba->HCregaddr);
12316 readl(phba->HCregaddr); /* flush */
12319 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
12320 SLI_IOCB_RET_IOCB);
12321 if (retval == IOCB_SUCCESS) {
12322 timeout_req = msecs_to_jiffies(timeout * 1000);
12323 timeleft = wait_event_timeout(done_q,
12324 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
12326 spin_lock_irqsave(&phba->hbalock, iflags);
12327 if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
12330 * IOCB timed out. Inform the wake iocb wait
12331 * completion function and set local status
12334 iocb_completed = false;
12335 piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
12337 spin_unlock_irqrestore(&phba->hbalock, iflags);
12338 if (iocb_completed) {
12339 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12340 "0331 IOCB wake signaled\n");
12341 /* Note: we are not indicating if the IOCB has a success
12342 * status or not - that's for the caller to check.
12343 * IOCB_SUCCESS means just that the command was sent and
12344 * completed. Not that it completed successfully.
12346 } else if (timeleft == 0) {
12347 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12348 "0338 IOCB wait timeout error - no "
12349 "wake response Data x%x\n", timeout);
12350 retval = IOCB_TIMEDOUT;
12352 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12353 "0330 IOCB wake NOT set, "
12355 timeout, (timeleft / jiffies));
12356 retval = IOCB_TIMEDOUT;
12358 } else if (retval == IOCB_BUSY) {
12359 if (phba->cfg_log_verbose & LOG_SLI) {
12360 list_for_each_entry(iocb, &pring->txq, list) {
12363 list_for_each_entry(iocb, &pring->txcmplq, list) {
12366 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12367 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
12368 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
12372 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12373 "0332 IOCB wait issue failed, Data x%x\n",
12375 retval = IOCB_ERROR;
12378 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
12379 if (lpfc_readl(phba->HCregaddr, &creg_val))
12381 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
12382 writel(creg_val, phba->HCregaddr);
12383 readl(phba->HCregaddr); /* flush */
12387 piocb->context2 = NULL;
12389 piocb->context_un.wait_queue = NULL;
12390 piocb->iocb_cmpl = NULL;
12395 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
12396 * @phba: Pointer to HBA context object.
12397 * @pmboxq: Pointer to driver mailbox object.
12398 * @timeout: Timeout in number of seconds.
12400 * This function issues the mailbox to firmware and waits for the
12401 * mailbox command to complete. If the mailbox command is not
12402 * completed within timeout seconds, it returns MBX_TIMEOUT.
12403 * The function waits for the mailbox completion using an
12404 * interruptible wait. If the thread is woken up due to a
12405 * signal, MBX_TIMEOUT error is returned to the caller. Caller
12406 * should not free the mailbox resources, if this function returns
12408 * This function will sleep while waiting for mailbox completion.
12409 * So, this function should not be called from any context which
12410 * does not allow sleeping. Due to the same reason, this function
12411 * cannot be called with interrupt disabled.
12412 * This function assumes that the mailbox completion occurs while
12413 * this function sleep. So, this function cannot be called from
12414 * the worker thread which processes mailbox completion.
12415 * This function is called in the context of HBA management
12417 * This function returns MBX_SUCCESS when successful.
12418 * This function is called with no lock held.
12421 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
12424 struct completion mbox_done;
12426 unsigned long flag;
12428 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
12429 /* setup wake call as IOCB callback */
12430 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
12432 /* setup context3 field to pass wait_queue pointer to wake function */
12433 init_completion(&mbox_done);
12434 pmboxq->context3 = &mbox_done;
12435 /* now issue the command */
12436 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
12437 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
12438 wait_for_completion_timeout(&mbox_done,
12439 msecs_to_jiffies(timeout * 1000));
12441 spin_lock_irqsave(&phba->hbalock, flag);
12442 pmboxq->context3 = NULL;
12444 * if LPFC_MBX_WAKE flag is set the mailbox is completed
12445 * else do not free the resources.
12447 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
12448 retval = MBX_SUCCESS;
12450 retval = MBX_TIMEOUT;
12451 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12453 spin_unlock_irqrestore(&phba->hbalock, flag);
12459 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
12460 * @phba: Pointer to HBA context.
12461 * @mbx_action: Mailbox shutdown options.
12463 * This function is called to shutdown the driver's mailbox sub-system.
12464 * It first marks the mailbox sub-system is in a block state to prevent
12465 * the asynchronous mailbox command from issued off the pending mailbox
12466 * command queue. If the mailbox command sub-system shutdown is due to
12467 * HBA error conditions such as EEH or ERATT, this routine shall invoke
12468 * the mailbox sub-system flush routine to forcefully bring down the
12469 * mailbox sub-system. Otherwise, if it is due to normal condition (such
12470 * as with offline or HBA function reset), this routine will wait for the
12471 * outstanding mailbox command to complete before invoking the mailbox
12472 * sub-system flush routine to gracefully bring down mailbox sub-system.
12475 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
12477 struct lpfc_sli *psli = &phba->sli;
12478 unsigned long timeout;
12480 if (mbx_action == LPFC_MBX_NO_WAIT) {
12481 /* delay 100ms for port state */
12483 lpfc_sli_mbox_sys_flush(phba);
12486 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
12488 /* Disable softirqs, including timers from obtaining phba->hbalock */
12489 local_bh_disable();
12491 spin_lock_irq(&phba->hbalock);
12492 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
12494 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
12495 /* Determine how long we might wait for the active mailbox
12496 * command to be gracefully completed by firmware.
12498 if (phba->sli.mbox_active)
12499 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
12500 phba->sli.mbox_active) *
12502 spin_unlock_irq(&phba->hbalock);
12504 /* Enable softirqs again, done with phba->hbalock */
12507 while (phba->sli.mbox_active) {
12508 /* Check active mailbox complete status every 2ms */
12510 if (time_after(jiffies, timeout))
12511 /* Timeout, let the mailbox flush routine to
12512 * forcefully release active mailbox command
12517 spin_unlock_irq(&phba->hbalock);
12519 /* Enable softirqs again, done with phba->hbalock */
12523 lpfc_sli_mbox_sys_flush(phba);
12527 * lpfc_sli_eratt_read - read sli-3 error attention events
12528 * @phba: Pointer to HBA context.
12530 * This function is called to read the SLI3 device error attention registers
12531 * for possible error attention events. The caller must hold the hostlock
12532 * with spin_lock_irq().
12534 * This function returns 1 when there is Error Attention in the Host Attention
12535 * Register and returns 0 otherwise.
12538 lpfc_sli_eratt_read(struct lpfc_hba *phba)
12542 /* Read chip Host Attention (HA) register */
12543 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12546 if (ha_copy & HA_ERATT) {
12547 /* Read host status register to retrieve error event */
12548 if (lpfc_sli_read_hs(phba))
12551 /* Check if there is a deferred error condition is active */
12552 if ((HS_FFER1 & phba->work_hs) &&
12553 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
12554 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
12555 phba->hba_flag |= DEFER_ERATT;
12556 /* Clear all interrupt enable conditions */
12557 writel(0, phba->HCregaddr);
12558 readl(phba->HCregaddr);
12561 /* Set the driver HA work bitmap */
12562 phba->work_ha |= HA_ERATT;
12563 /* Indicate polling handles this ERATT */
12564 phba->hba_flag |= HBA_ERATT_HANDLED;
12570 /* Set the driver HS work bitmap */
12571 phba->work_hs |= UNPLUG_ERR;
12572 /* Set the driver HA work bitmap */
12573 phba->work_ha |= HA_ERATT;
12574 /* Indicate polling handles this ERATT */
12575 phba->hba_flag |= HBA_ERATT_HANDLED;
12580 * lpfc_sli4_eratt_read - read sli-4 error attention events
12581 * @phba: Pointer to HBA context.
12583 * This function is called to read the SLI4 device error attention registers
12584 * for possible error attention events. The caller must hold the hostlock
12585 * with spin_lock_irq().
12587 * This function returns 1 when there is Error Attention in the Host Attention
12588 * Register and returns 0 otherwise.
12591 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
12593 uint32_t uerr_sta_hi, uerr_sta_lo;
12594 uint32_t if_type, portsmphr;
12595 struct lpfc_register portstat_reg;
12598 * For now, use the SLI4 device internal unrecoverable error
12599 * registers for error attention. This can be changed later.
12601 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
12603 case LPFC_SLI_INTF_IF_TYPE_0:
12604 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
12606 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
12608 phba->work_hs |= UNPLUG_ERR;
12609 phba->work_ha |= HA_ERATT;
12610 phba->hba_flag |= HBA_ERATT_HANDLED;
12613 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
12614 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
12615 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12616 "1423 HBA Unrecoverable error: "
12617 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
12618 "ue_mask_lo_reg=0x%x, "
12619 "ue_mask_hi_reg=0x%x\n",
12620 uerr_sta_lo, uerr_sta_hi,
12621 phba->sli4_hba.ue_mask_lo,
12622 phba->sli4_hba.ue_mask_hi);
12623 phba->work_status[0] = uerr_sta_lo;
12624 phba->work_status[1] = uerr_sta_hi;
12625 phba->work_ha |= HA_ERATT;
12626 phba->hba_flag |= HBA_ERATT_HANDLED;
12630 case LPFC_SLI_INTF_IF_TYPE_2:
12631 case LPFC_SLI_INTF_IF_TYPE_6:
12632 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
12633 &portstat_reg.word0) ||
12634 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
12636 phba->work_hs |= UNPLUG_ERR;
12637 phba->work_ha |= HA_ERATT;
12638 phba->hba_flag |= HBA_ERATT_HANDLED;
12641 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
12642 phba->work_status[0] =
12643 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
12644 phba->work_status[1] =
12645 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
12646 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12647 "2885 Port Status Event: "
12648 "port status reg 0x%x, "
12649 "port smphr reg 0x%x, "
12650 "error 1=0x%x, error 2=0x%x\n",
12651 portstat_reg.word0,
12653 phba->work_status[0],
12654 phba->work_status[1]);
12655 phba->work_ha |= HA_ERATT;
12656 phba->hba_flag |= HBA_ERATT_HANDLED;
12660 case LPFC_SLI_INTF_IF_TYPE_1:
12662 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12663 "2886 HBA Error Attention on unsupported "
12664 "if type %d.", if_type);
12672 * lpfc_sli_check_eratt - check error attention events
12673 * @phba: Pointer to HBA context.
12675 * This function is called from timer soft interrupt context to check HBA's
12676 * error attention register bit for error attention events.
12678 * This function returns 1 when there is Error Attention in the Host Attention
12679 * Register and returns 0 otherwise.
12682 lpfc_sli_check_eratt(struct lpfc_hba *phba)
12686 /* If somebody is waiting to handle an eratt, don't process it
12687 * here. The brdkill function will do this.
12689 if (phba->link_flag & LS_IGNORE_ERATT)
12692 /* Check if interrupt handler handles this ERATT */
12693 spin_lock_irq(&phba->hbalock);
12694 if (phba->hba_flag & HBA_ERATT_HANDLED) {
12695 /* Interrupt handler has handled ERATT */
12696 spin_unlock_irq(&phba->hbalock);
12701 * If there is deferred error attention, do not check for error
12704 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12705 spin_unlock_irq(&phba->hbalock);
12709 /* If PCI channel is offline, don't process it */
12710 if (unlikely(pci_channel_offline(phba->pcidev))) {
12711 spin_unlock_irq(&phba->hbalock);
12715 switch (phba->sli_rev) {
12716 case LPFC_SLI_REV2:
12717 case LPFC_SLI_REV3:
12718 /* Read chip Host Attention (HA) register */
12719 ha_copy = lpfc_sli_eratt_read(phba);
12721 case LPFC_SLI_REV4:
12722 /* Read device Uncoverable Error (UERR) registers */
12723 ha_copy = lpfc_sli4_eratt_read(phba);
12726 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12727 "0299 Invalid SLI revision (%d)\n",
12732 spin_unlock_irq(&phba->hbalock);
12738 * lpfc_intr_state_check - Check device state for interrupt handling
12739 * @phba: Pointer to HBA context.
12741 * This inline routine checks whether a device or its PCI slot is in a state
12742 * that the interrupt should be handled.
12744 * This function returns 0 if the device or the PCI slot is in a state that
12745 * interrupt should be handled, otherwise -EIO.
12748 lpfc_intr_state_check(struct lpfc_hba *phba)
12750 /* If the pci channel is offline, ignore all the interrupts */
12751 if (unlikely(pci_channel_offline(phba->pcidev)))
12754 /* Update device level interrupt statistics */
12755 phba->sli.slistat.sli_intr++;
12757 /* Ignore all interrupts during initialization. */
12758 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
12765 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
12766 * @irq: Interrupt number.
12767 * @dev_id: The device context pointer.
12769 * This function is directly called from the PCI layer as an interrupt
12770 * service routine when device with SLI-3 interface spec is enabled with
12771 * MSI-X multi-message interrupt mode and there are slow-path events in
12772 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
12773 * interrupt mode, this function is called as part of the device-level
12774 * interrupt handler. When the PCI slot is in error recovery or the HBA
12775 * is undergoing initialization, the interrupt handler will not process
12776 * the interrupt. The link attention and ELS ring attention events are
12777 * handled by the worker thread. The interrupt handler signals the worker
12778 * thread and returns for these events. This function is called without
12779 * any lock held. It gets the hbalock to access and update SLI data
12782 * This function returns IRQ_HANDLED when interrupt is handled else it
12783 * returns IRQ_NONE.
12786 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
12788 struct lpfc_hba *phba;
12789 uint32_t ha_copy, hc_copy;
12790 uint32_t work_ha_copy;
12791 unsigned long status;
12792 unsigned long iflag;
12795 MAILBOX_t *mbox, *pmbox;
12796 struct lpfc_vport *vport;
12797 struct lpfc_nodelist *ndlp;
12798 struct lpfc_dmabuf *mp;
12803 * Get the driver's phba structure from the dev_id and
12804 * assume the HBA is not interrupting.
12806 phba = (struct lpfc_hba *)dev_id;
12808 if (unlikely(!phba))
12812 * Stuff needs to be attented to when this function is invoked as an
12813 * individual interrupt handler in MSI-X multi-message interrupt mode
12815 if (phba->intr_type == MSIX) {
12816 /* Check device state for handling interrupt */
12817 if (lpfc_intr_state_check(phba))
12819 /* Need to read HA REG for slow-path events */
12820 spin_lock_irqsave(&phba->hbalock, iflag);
12821 if (lpfc_readl(phba->HAregaddr, &ha_copy))
12823 /* If somebody is waiting to handle an eratt don't process it
12824 * here. The brdkill function will do this.
12826 if (phba->link_flag & LS_IGNORE_ERATT)
12827 ha_copy &= ~HA_ERATT;
12828 /* Check the need for handling ERATT in interrupt handler */
12829 if (ha_copy & HA_ERATT) {
12830 if (phba->hba_flag & HBA_ERATT_HANDLED)
12831 /* ERATT polling has handled ERATT */
12832 ha_copy &= ~HA_ERATT;
12834 /* Indicate interrupt handler handles ERATT */
12835 phba->hba_flag |= HBA_ERATT_HANDLED;
12839 * If there is deferred error attention, do not check for any
12842 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
12843 spin_unlock_irqrestore(&phba->hbalock, iflag);
12847 /* Clear up only attention source related to slow-path */
12848 if (lpfc_readl(phba->HCregaddr, &hc_copy))
12851 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
12852 HC_LAINT_ENA | HC_ERINT_ENA),
12854 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
12856 writel(hc_copy, phba->HCregaddr);
12857 readl(phba->HAregaddr); /* flush */
12858 spin_unlock_irqrestore(&phba->hbalock, iflag);
12860 ha_copy = phba->ha_copy;
12862 work_ha_copy = ha_copy & phba->work_ha_mask;
12864 if (work_ha_copy) {
12865 if (work_ha_copy & HA_LATT) {
12866 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
12868 * Turn off Link Attention interrupts
12869 * until CLEAR_LA done
12871 spin_lock_irqsave(&phba->hbalock, iflag);
12872 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
12873 if (lpfc_readl(phba->HCregaddr, &control))
12875 control &= ~HC_LAINT_ENA;
12876 writel(control, phba->HCregaddr);
12877 readl(phba->HCregaddr); /* flush */
12878 spin_unlock_irqrestore(&phba->hbalock, iflag);
12881 work_ha_copy &= ~HA_LATT;
12884 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
12886 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
12887 * the only slow ring.
12889 status = (work_ha_copy &
12890 (HA_RXMASK << (4*LPFC_ELS_RING)));
12891 status >>= (4*LPFC_ELS_RING);
12892 if (status & HA_RXMASK) {
12893 spin_lock_irqsave(&phba->hbalock, iflag);
12894 if (lpfc_readl(phba->HCregaddr, &control))
12897 lpfc_debugfs_slow_ring_trc(phba,
12898 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
12900 (uint32_t)phba->sli.slistat.sli_intr);
12902 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
12903 lpfc_debugfs_slow_ring_trc(phba,
12904 "ISR Disable ring:"
12905 "pwork:x%x hawork:x%x wait:x%x",
12906 phba->work_ha, work_ha_copy,
12907 (uint32_t)((unsigned long)
12908 &phba->work_waitq));
12911 ~(HC_R0INT_ENA << LPFC_ELS_RING);
12912 writel(control, phba->HCregaddr);
12913 readl(phba->HCregaddr); /* flush */
12916 lpfc_debugfs_slow_ring_trc(phba,
12917 "ISR slow ring: pwork:"
12918 "x%x hawork:x%x wait:x%x",
12919 phba->work_ha, work_ha_copy,
12920 (uint32_t)((unsigned long)
12921 &phba->work_waitq));
12923 spin_unlock_irqrestore(&phba->hbalock, iflag);
12926 spin_lock_irqsave(&phba->hbalock, iflag);
12927 if (work_ha_copy & HA_ERATT) {
12928 if (lpfc_sli_read_hs(phba))
12931 * Check if there is a deferred error condition
12934 if ((HS_FFER1 & phba->work_hs) &&
12935 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
12936 HS_FFER6 | HS_FFER7 | HS_FFER8) &
12938 phba->hba_flag |= DEFER_ERATT;
12939 /* Clear all interrupt enable conditions */
12940 writel(0, phba->HCregaddr);
12941 readl(phba->HCregaddr);
12945 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
12946 pmb = phba->sli.mbox_active;
12947 pmbox = &pmb->u.mb;
12949 vport = pmb->vport;
12951 /* First check out the status word */
12952 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
12953 if (pmbox->mbxOwner != OWN_HOST) {
12954 spin_unlock_irqrestore(&phba->hbalock, iflag);
12956 * Stray Mailbox Interrupt, mbxCommand <cmd>
12957 * mbxStatus <status>
12959 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12960 "(%d):0304 Stray Mailbox "
12961 "Interrupt mbxCommand x%x "
12963 (vport ? vport->vpi : 0),
12966 /* clear mailbox attention bit */
12967 work_ha_copy &= ~HA_MBATT;
12969 phba->sli.mbox_active = NULL;
12970 spin_unlock_irqrestore(&phba->hbalock, iflag);
12971 phba->last_completion_time = jiffies;
12972 del_timer(&phba->sli.mbox_tmo);
12973 if (pmb->mbox_cmpl) {
12974 lpfc_sli_pcimem_bcopy(mbox, pmbox,
12976 if (pmb->out_ext_byte_len &&
12978 lpfc_sli_pcimem_bcopy(
12981 pmb->out_ext_byte_len);
12983 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
12984 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
12986 lpfc_debugfs_disc_trc(vport,
12987 LPFC_DISC_TRC_MBOX_VPORT,
12988 "MBOX dflt rpi: : "
12989 "status:x%x rpi:x%x",
12990 (uint32_t)pmbox->mbxStatus,
12991 pmbox->un.varWords[0], 0);
12993 if (!pmbox->mbxStatus) {
12994 mp = (struct lpfc_dmabuf *)
12996 ndlp = (struct lpfc_nodelist *)
12999 /* Reg_LOGIN of dflt RPI was
13000 * successful. new lets get
13001 * rid of the RPI using the
13002 * same mbox buffer.
13004 lpfc_unreg_login(phba,
13006 pmbox->un.varWords[0],
13009 lpfc_mbx_cmpl_dflt_rpi;
13011 pmb->ctx_ndlp = ndlp;
13012 pmb->vport = vport;
13013 rc = lpfc_sli_issue_mbox(phba,
13016 if (rc != MBX_BUSY)
13017 lpfc_printf_log(phba,
13020 "0350 rc should have"
13021 "been MBX_BUSY\n");
13022 if (rc != MBX_NOT_FINISHED)
13023 goto send_current_mbox;
13027 &phba->pport->work_port_lock,
13029 phba->pport->work_port_events &=
13031 spin_unlock_irqrestore(
13032 &phba->pport->work_port_lock,
13035 /* Do NOT queue MBX_HEARTBEAT to the worker
13036 * thread for processing.
13038 if (pmbox->mbxCommand == MBX_HEARTBEAT) {
13039 /* Process mbox now */
13040 phba->sli.mbox_active = NULL;
13041 phba->sli.sli_flag &=
13042 ~LPFC_SLI_MBOX_ACTIVE;
13043 if (pmb->mbox_cmpl)
13044 pmb->mbox_cmpl(phba, pmb);
13046 /* Queue to worker thread to process */
13047 lpfc_mbox_cmpl_put(phba, pmb);
13051 spin_unlock_irqrestore(&phba->hbalock, iflag);
13053 if ((work_ha_copy & HA_MBATT) &&
13054 (phba->sli.mbox_active == NULL)) {
13056 /* Process next mailbox command if there is one */
13058 rc = lpfc_sli_issue_mbox(phba, NULL,
13060 } while (rc == MBX_NOT_FINISHED);
13061 if (rc != MBX_SUCCESS)
13062 lpfc_printf_log(phba, KERN_ERR,
13064 "0349 rc should be "
13068 spin_lock_irqsave(&phba->hbalock, iflag);
13069 phba->work_ha |= work_ha_copy;
13070 spin_unlock_irqrestore(&phba->hbalock, iflag);
13071 lpfc_worker_wake_up(phba);
13073 return IRQ_HANDLED;
13075 spin_unlock_irqrestore(&phba->hbalock, iflag);
13076 return IRQ_HANDLED;
13078 } /* lpfc_sli_sp_intr_handler */
13081 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
13082 * @irq: Interrupt number.
13083 * @dev_id: The device context pointer.
13085 * This function is directly called from the PCI layer as an interrupt
13086 * service routine when device with SLI-3 interface spec is enabled with
13087 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13088 * ring event in the HBA. However, when the device is enabled with either
13089 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13090 * device-level interrupt handler. When the PCI slot is in error recovery
13091 * or the HBA is undergoing initialization, the interrupt handler will not
13092 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13093 * the intrrupt context. This function is called without any lock held.
13094 * It gets the hbalock to access and update SLI data structures.
13096 * This function returns IRQ_HANDLED when interrupt is handled else it
13097 * returns IRQ_NONE.
13100 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
13102 struct lpfc_hba *phba;
13104 unsigned long status;
13105 unsigned long iflag;
13106 struct lpfc_sli_ring *pring;
13108 /* Get the driver's phba structure from the dev_id and
13109 * assume the HBA is not interrupting.
13111 phba = (struct lpfc_hba *) dev_id;
13113 if (unlikely(!phba))
13117 * Stuff needs to be attented to when this function is invoked as an
13118 * individual interrupt handler in MSI-X multi-message interrupt mode
13120 if (phba->intr_type == MSIX) {
13121 /* Check device state for handling interrupt */
13122 if (lpfc_intr_state_check(phba))
13124 /* Need to read HA REG for FCP ring and other ring events */
13125 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13126 return IRQ_HANDLED;
13127 /* Clear up only attention source related to fast-path */
13128 spin_lock_irqsave(&phba->hbalock, iflag);
13130 * If there is deferred error attention, do not check for
13133 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13134 spin_unlock_irqrestore(&phba->hbalock, iflag);
13137 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
13139 readl(phba->HAregaddr); /* flush */
13140 spin_unlock_irqrestore(&phba->hbalock, iflag);
13142 ha_copy = phba->ha_copy;
13145 * Process all events on FCP ring. Take the optimized path for FCP IO.
13147 ha_copy &= ~(phba->work_ha_mask);
13149 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
13150 status >>= (4*LPFC_FCP_RING);
13151 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
13152 if (status & HA_RXMASK)
13153 lpfc_sli_handle_fast_ring_event(phba, pring, status);
13155 if (phba->cfg_multi_ring_support == 2) {
13157 * Process all events on extra ring. Take the optimized path
13158 * for extra ring IO.
13160 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
13161 status >>= (4*LPFC_EXTRA_RING);
13162 if (status & HA_RXMASK) {
13163 lpfc_sli_handle_fast_ring_event(phba,
13164 &phba->sli.sli3_ring[LPFC_EXTRA_RING],
13168 return IRQ_HANDLED;
13169 } /* lpfc_sli_fp_intr_handler */
13172 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
13173 * @irq: Interrupt number.
13174 * @dev_id: The device context pointer.
13176 * This function is the HBA device-level interrupt handler to device with
13177 * SLI-3 interface spec, called from the PCI layer when either MSI or
13178 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
13179 * requires driver attention. This function invokes the slow-path interrupt
13180 * attention handling function and fast-path interrupt attention handling
13181 * function in turn to process the relevant HBA attention events. This
13182 * function is called without any lock held. It gets the hbalock to access
13183 * and update SLI data structures.
13185 * This function returns IRQ_HANDLED when interrupt is handled, else it
13186 * returns IRQ_NONE.
13189 lpfc_sli_intr_handler(int irq, void *dev_id)
13191 struct lpfc_hba *phba;
13192 irqreturn_t sp_irq_rc, fp_irq_rc;
13193 unsigned long status1, status2;
13197 * Get the driver's phba structure from the dev_id and
13198 * assume the HBA is not interrupting.
13200 phba = (struct lpfc_hba *) dev_id;
13202 if (unlikely(!phba))
13205 /* Check device state for handling interrupt */
13206 if (lpfc_intr_state_check(phba))
13209 spin_lock(&phba->hbalock);
13210 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
13211 spin_unlock(&phba->hbalock);
13212 return IRQ_HANDLED;
13215 if (unlikely(!phba->ha_copy)) {
13216 spin_unlock(&phba->hbalock);
13218 } else if (phba->ha_copy & HA_ERATT) {
13219 if (phba->hba_flag & HBA_ERATT_HANDLED)
13220 /* ERATT polling has handled ERATT */
13221 phba->ha_copy &= ~HA_ERATT;
13223 /* Indicate interrupt handler handles ERATT */
13224 phba->hba_flag |= HBA_ERATT_HANDLED;
13228 * If there is deferred error attention, do not check for any interrupt.
13230 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13231 spin_unlock(&phba->hbalock);
13235 /* Clear attention sources except link and error attentions */
13236 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
13237 spin_unlock(&phba->hbalock);
13238 return IRQ_HANDLED;
13240 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
13241 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
13243 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
13244 writel(hc_copy, phba->HCregaddr);
13245 readl(phba->HAregaddr); /* flush */
13246 spin_unlock(&phba->hbalock);
13249 * Invokes slow-path host attention interrupt handling as appropriate.
13252 /* status of events with mailbox and link attention */
13253 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
13255 /* status of events with ELS ring */
13256 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
13257 status2 >>= (4*LPFC_ELS_RING);
13259 if (status1 || (status2 & HA_RXMASK))
13260 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
13262 sp_irq_rc = IRQ_NONE;
13265 * Invoke fast-path host attention interrupt handling as appropriate.
13268 /* status of events with FCP ring */
13269 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
13270 status1 >>= (4*LPFC_FCP_RING);
13272 /* status of events with extra ring */
13273 if (phba->cfg_multi_ring_support == 2) {
13274 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
13275 status2 >>= (4*LPFC_EXTRA_RING);
13279 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
13280 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
13282 fp_irq_rc = IRQ_NONE;
13284 /* Return device-level interrupt handling status */
13285 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
13286 } /* lpfc_sli_intr_handler */
13289 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
13290 * @phba: pointer to lpfc hba data structure.
13292 * This routine is invoked by the worker thread to process all the pending
13293 * SLI4 els abort xri events.
13295 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
13297 struct lpfc_cq_event *cq_event;
13298 unsigned long iflags;
13300 /* First, declare the els xri abort event has been handled */
13301 spin_lock_irqsave(&phba->hbalock, iflags);
13302 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
13303 spin_unlock_irqrestore(&phba->hbalock, iflags);
13305 /* Now, handle all the els xri abort events */
13306 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
13307 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
13308 /* Get the first event from the head of the event queue */
13309 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
13310 cq_event, struct lpfc_cq_event, list);
13311 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
13313 /* Notify aborted XRI for ELS work queue */
13314 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
13316 /* Free the event processed back to the free pool */
13317 lpfc_sli4_cq_event_release(phba, cq_event);
13318 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
13321 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
13325 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
13326 * @phba: pointer to lpfc hba data structure
13327 * @pIocbIn: pointer to the rspiocbq
13328 * @pIocbOut: pointer to the cmdiocbq
13329 * @wcqe: pointer to the complete wcqe
13331 * This routine transfers the fields of a command iocbq to a response iocbq
13332 * by copying all the IOCB fields from command iocbq and transferring the
13333 * completion status information from the complete wcqe.
13336 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
13337 struct lpfc_iocbq *pIocbIn,
13338 struct lpfc_iocbq *pIocbOut,
13339 struct lpfc_wcqe_complete *wcqe)
13342 unsigned long iflags;
13343 uint32_t status, max_response;
13344 struct lpfc_dmabuf *dmabuf;
13345 struct ulp_bde64 *bpl, bde;
13346 size_t offset = offsetof(struct lpfc_iocbq, iocb);
13348 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
13349 sizeof(struct lpfc_iocbq) - offset);
13350 /* Map WCQE parameters into irspiocb parameters */
13351 status = bf_get(lpfc_wcqe_c_status, wcqe);
13352 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
13353 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
13354 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
13355 pIocbIn->iocb.un.fcpi.fcpi_parm =
13356 pIocbOut->iocb.un.fcpi.fcpi_parm -
13357 wcqe->total_data_placed;
13359 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
13361 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
13362 switch (pIocbOut->iocb.ulpCommand) {
13363 case CMD_ELS_REQUEST64_CR:
13364 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
13365 bpl = (struct ulp_bde64 *)dmabuf->virt;
13366 bde.tus.w = le32_to_cpu(bpl[1].tus.w);
13367 max_response = bde.tus.f.bdeSize;
13369 case CMD_GEN_REQUEST64_CR:
13371 if (!pIocbOut->context3)
13373 numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
13374 sizeof(struct ulp_bde64);
13375 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
13376 bpl = (struct ulp_bde64 *)dmabuf->virt;
13377 for (i = 0; i < numBdes; i++) {
13378 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
13379 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
13380 max_response += bde.tus.f.bdeSize;
13384 max_response = wcqe->total_data_placed;
13387 if (max_response < wcqe->total_data_placed)
13388 pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
13390 pIocbIn->iocb.un.genreq64.bdl.bdeSize =
13391 wcqe->total_data_placed;
13394 /* Convert BG errors for completion status */
13395 if (status == CQE_STATUS_DI_ERROR) {
13396 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
13398 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
13399 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
13401 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
13403 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
13404 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
13405 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13406 BGS_GUARD_ERR_MASK;
13407 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
13408 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13409 BGS_APPTAG_ERR_MASK;
13410 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
13411 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13412 BGS_REFTAG_ERR_MASK;
13414 /* Check to see if there was any good data before the error */
13415 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
13416 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13417 BGS_HI_WATER_MARK_PRESENT_MASK;
13418 pIocbIn->iocb.unsli3.sli3_bg.bghm =
13419 wcqe->total_data_placed;
13423 * Set ALL the error bits to indicate we don't know what
13424 * type of error it is.
13426 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
13427 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
13428 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
13429 BGS_GUARD_ERR_MASK);
13432 /* Pick up HBA exchange busy condition */
13433 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
13434 spin_lock_irqsave(&phba->hbalock, iflags);
13435 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
13436 spin_unlock_irqrestore(&phba->hbalock, iflags);
13441 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
13442 * @phba: Pointer to HBA context object.
13443 * @irspiocbq: Pointer to work-queue completion queue entry.
13445 * This routine handles an ELS work-queue completion event and construct
13446 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
13447 * discovery engine to handle.
13449 * Return: Pointer to the receive IOCBQ, NULL otherwise.
13451 static struct lpfc_iocbq *
13452 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
13453 struct lpfc_iocbq *irspiocbq)
13455 struct lpfc_sli_ring *pring;
13456 struct lpfc_iocbq *cmdiocbq;
13457 struct lpfc_wcqe_complete *wcqe;
13458 unsigned long iflags;
13460 pring = lpfc_phba_elsring(phba);
13461 if (unlikely(!pring))
13464 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
13465 pring->stats.iocb_event++;
13466 /* Look up the ELS command IOCB and create pseudo response IOCB */
13467 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
13468 bf_get(lpfc_wcqe_c_request_tag, wcqe));
13469 if (unlikely(!cmdiocbq)) {
13470 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13471 "0386 ELS complete with no corresponding "
13472 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
13473 wcqe->word0, wcqe->total_data_placed,
13474 wcqe->parameter, wcqe->word3);
13475 lpfc_sli_release_iocbq(phba, irspiocbq);
13479 spin_lock_irqsave(&pring->ring_lock, iflags);
13480 /* Put the iocb back on the txcmplq */
13481 lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
13482 spin_unlock_irqrestore(&pring->ring_lock, iflags);
13484 /* Fake the irspiocbq and copy necessary response information */
13485 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
13490 inline struct lpfc_cq_event *
13491 lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
13493 struct lpfc_cq_event *cq_event;
13495 /* Allocate a new internal CQ_EVENT entry */
13496 cq_event = lpfc_sli4_cq_event_alloc(phba);
13498 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13499 "0602 Failed to alloc CQ_EVENT entry\n");
13503 /* Move the CQE into the event */
13504 memcpy(&cq_event->cqe, entry, size);
13509 * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event
13510 * @phba: Pointer to HBA context object.
13511 * @mcqe: Pointer to mailbox completion queue entry.
13513 * This routine process a mailbox completion queue entry with asynchronous
13516 * Return: true if work posted to worker thread, otherwise false.
13519 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
13521 struct lpfc_cq_event *cq_event;
13522 unsigned long iflags;
13524 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13525 "0392 Async Event: word0:x%x, word1:x%x, "
13526 "word2:x%x, word3:x%x\n", mcqe->word0,
13527 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
13529 cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
13533 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
13534 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
13535 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
13537 /* Set the async event flag */
13538 spin_lock_irqsave(&phba->hbalock, iflags);
13539 phba->hba_flag |= ASYNC_EVENT;
13540 spin_unlock_irqrestore(&phba->hbalock, iflags);
13546 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
13547 * @phba: Pointer to HBA context object.
13548 * @mcqe: Pointer to mailbox completion queue entry.
13550 * This routine process a mailbox completion queue entry with mailbox
13551 * completion event.
13553 * Return: true if work posted to worker thread, otherwise false.
13556 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
13558 uint32_t mcqe_status;
13559 MAILBOX_t *mbox, *pmbox;
13560 struct lpfc_mqe *mqe;
13561 struct lpfc_vport *vport;
13562 struct lpfc_nodelist *ndlp;
13563 struct lpfc_dmabuf *mp;
13564 unsigned long iflags;
13566 bool workposted = false;
13569 /* If not a mailbox complete MCQE, out by checking mailbox consume */
13570 if (!bf_get(lpfc_trailer_completed, mcqe))
13571 goto out_no_mqe_complete;
13573 /* Get the reference to the active mbox command */
13574 spin_lock_irqsave(&phba->hbalock, iflags);
13575 pmb = phba->sli.mbox_active;
13576 if (unlikely(!pmb)) {
13577 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13578 "1832 No pending MBOX command to handle\n");
13579 spin_unlock_irqrestore(&phba->hbalock, iflags);
13580 goto out_no_mqe_complete;
13582 spin_unlock_irqrestore(&phba->hbalock, iflags);
13584 pmbox = (MAILBOX_t *)&pmb->u.mqe;
13586 vport = pmb->vport;
13588 /* Reset heartbeat timer */
13589 phba->last_completion_time = jiffies;
13590 del_timer(&phba->sli.mbox_tmo);
13592 /* Move mbox data to caller's mailbox region, do endian swapping */
13593 if (pmb->mbox_cmpl && mbox)
13594 lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
13597 * For mcqe errors, conditionally move a modified error code to
13598 * the mbox so that the error will not be missed.
13600 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
13601 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
13602 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
13603 bf_set(lpfc_mqe_status, mqe,
13604 (LPFC_MBX_ERROR_RANGE | mcqe_status));
13606 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
13607 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
13608 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
13609 "MBOX dflt rpi: status:x%x rpi:x%x",
13611 pmbox->un.varWords[0], 0);
13612 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
13613 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
13614 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
13615 /* Reg_LOGIN of dflt RPI was successful. Now lets get
13616 * RID of the PPI using the same mbox buffer.
13618 lpfc_unreg_login(phba, vport->vpi,
13619 pmbox->un.varWords[0], pmb);
13620 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
13623 /* No reference taken here. This is a default
13624 * RPI reg/immediate unreg cycle. The reference was
13625 * taken in the reg rpi path and is released when
13626 * this mailbox completes.
13628 pmb->ctx_ndlp = ndlp;
13629 pmb->vport = vport;
13630 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
13631 if (rc != MBX_BUSY)
13632 lpfc_printf_log(phba, KERN_ERR,
13635 "have been MBX_BUSY\n");
13636 if (rc != MBX_NOT_FINISHED)
13637 goto send_current_mbox;
13640 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
13641 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
13642 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
13644 /* Do NOT queue MBX_HEARTBEAT to the worker thread for processing. */
13645 if (pmbox->mbxCommand == MBX_HEARTBEAT) {
13646 spin_lock_irqsave(&phba->hbalock, iflags);
13647 /* Release the mailbox command posting token */
13648 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13649 phba->sli.mbox_active = NULL;
13650 if (bf_get(lpfc_trailer_consumed, mcqe))
13651 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13652 spin_unlock_irqrestore(&phba->hbalock, iflags);
13654 /* Post the next mbox command, if there is one */
13655 lpfc_sli4_post_async_mbox(phba);
13657 /* Process cmpl now */
13658 if (pmb->mbox_cmpl)
13659 pmb->mbox_cmpl(phba, pmb);
13663 /* There is mailbox completion work to queue to the worker thread */
13664 spin_lock_irqsave(&phba->hbalock, iflags);
13665 __lpfc_mbox_cmpl_put(phba, pmb);
13666 phba->work_ha |= HA_MBATT;
13667 spin_unlock_irqrestore(&phba->hbalock, iflags);
13671 spin_lock_irqsave(&phba->hbalock, iflags);
13672 /* Release the mailbox command posting token */
13673 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
13674 /* Setting active mailbox pointer need to be in sync to flag clear */
13675 phba->sli.mbox_active = NULL;
13676 if (bf_get(lpfc_trailer_consumed, mcqe))
13677 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13678 spin_unlock_irqrestore(&phba->hbalock, iflags);
13679 /* Wake up worker thread to post the next pending mailbox command */
13680 lpfc_worker_wake_up(phba);
13683 out_no_mqe_complete:
13684 spin_lock_irqsave(&phba->hbalock, iflags);
13685 if (bf_get(lpfc_trailer_consumed, mcqe))
13686 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
13687 spin_unlock_irqrestore(&phba->hbalock, iflags);
13692 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
13693 * @phba: Pointer to HBA context object.
13694 * @cq: Pointer to associated CQ
13695 * @cqe: Pointer to mailbox completion queue entry.
13697 * This routine process a mailbox completion queue entry, it invokes the
13698 * proper mailbox complete handling or asynchronous event handling routine
13699 * according to the MCQE's async bit.
13701 * Return: true if work posted to worker thread, otherwise false.
13704 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13705 struct lpfc_cqe *cqe)
13707 struct lpfc_mcqe mcqe;
13712 /* Copy the mailbox MCQE and convert endian order as needed */
13713 lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
13715 /* Invoke the proper event handling routine */
13716 if (!bf_get(lpfc_trailer_async, &mcqe))
13717 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
13719 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
13724 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
13725 * @phba: Pointer to HBA context object.
13726 * @cq: Pointer to associated CQ
13727 * @wcqe: Pointer to work-queue completion queue entry.
13729 * This routine handles an ELS work-queue completion event.
13731 * Return: true if work posted to worker thread, otherwise false.
13734 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13735 struct lpfc_wcqe_complete *wcqe)
13737 struct lpfc_iocbq *irspiocbq;
13738 unsigned long iflags;
13739 struct lpfc_sli_ring *pring = cq->pring;
13741 int txcmplq_cnt = 0;
13743 /* Check for response status */
13744 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
13745 /* Log the error status */
13746 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13747 "0357 ELS CQE error: status=x%x: "
13748 "CQE: %08x %08x %08x %08x\n",
13749 bf_get(lpfc_wcqe_c_status, wcqe),
13750 wcqe->word0, wcqe->total_data_placed,
13751 wcqe->parameter, wcqe->word3);
13754 /* Get an irspiocbq for later ELS response processing use */
13755 irspiocbq = lpfc_sli_get_iocbq(phba);
13757 if (!list_empty(&pring->txq))
13759 if (!list_empty(&pring->txcmplq))
13761 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13762 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
13763 "els_txcmplq_cnt=%d\n",
13764 txq_cnt, phba->iocb_cnt,
13769 /* Save off the slow-path queue event for work thread to process */
13770 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
13771 spin_lock_irqsave(&phba->hbalock, iflags);
13772 list_add_tail(&irspiocbq->cq_event.list,
13773 &phba->sli4_hba.sp_queue_event);
13774 phba->hba_flag |= HBA_SP_QUEUE_EVT;
13775 spin_unlock_irqrestore(&phba->hbalock, iflags);
13781 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
13782 * @phba: Pointer to HBA context object.
13783 * @wcqe: Pointer to work-queue completion queue entry.
13785 * This routine handles slow-path WQ entry consumed event by invoking the
13786 * proper WQ release routine to the slow-path WQ.
13789 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
13790 struct lpfc_wcqe_release *wcqe)
13792 /* sanity check on queue memory */
13793 if (unlikely(!phba->sli4_hba.els_wq))
13795 /* Check for the slow-path ELS work queue */
13796 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
13797 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
13798 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
13800 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
13801 "2579 Slow-path wqe consume event carries "
13802 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
13803 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
13804 phba->sli4_hba.els_wq->queue_id);
13808 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
13809 * @phba: Pointer to HBA context object.
13810 * @cq: Pointer to a WQ completion queue.
13811 * @wcqe: Pointer to work-queue completion queue entry.
13813 * This routine handles an XRI abort event.
13815 * Return: true if work posted to worker thread, otherwise false.
13818 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
13819 struct lpfc_queue *cq,
13820 struct sli4_wcqe_xri_aborted *wcqe)
13822 bool workposted = false;
13823 struct lpfc_cq_event *cq_event;
13824 unsigned long iflags;
13826 switch (cq->subtype) {
13828 lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
13829 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
13830 /* Notify aborted XRI for NVME work queue */
13831 if (phba->nvmet_support)
13832 lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
13834 workposted = false;
13836 case LPFC_NVME_LS: /* NVME LS uses ELS resources */
13838 cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe));
13840 workposted = false;
13843 cq_event->hdwq = cq->hdwq;
13844 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
13846 list_add_tail(&cq_event->list,
13847 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
13848 /* Set the els xri abort event flag */
13849 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
13850 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
13855 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13856 "0603 Invalid CQ subtype %d: "
13857 "%08x %08x %08x %08x\n",
13858 cq->subtype, wcqe->word0, wcqe->parameter,
13859 wcqe->word2, wcqe->word3);
13860 workposted = false;
13866 #define FC_RCTL_MDS_DIAGS 0xF4
13869 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
13870 * @phba: Pointer to HBA context object.
13871 * @rcqe: Pointer to receive-queue completion queue entry.
13873 * This routine process a receive-queue completion queue entry.
13875 * Return: true if work posted to worker thread, otherwise false.
13878 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
13880 bool workposted = false;
13881 struct fc_frame_header *fc_hdr;
13882 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
13883 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
13884 struct lpfc_nvmet_tgtport *tgtp;
13885 struct hbq_dmabuf *dma_buf;
13886 uint32_t status, rq_id;
13887 unsigned long iflags;
13889 /* sanity check on queue memory */
13890 if (unlikely(!hrq) || unlikely(!drq))
13893 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
13894 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
13896 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
13897 if (rq_id != hrq->queue_id)
13900 status = bf_get(lpfc_rcqe_status, rcqe);
13902 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
13903 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13904 "2537 Receive Frame Truncated!!\n");
13906 case FC_STATUS_RQ_SUCCESS:
13907 spin_lock_irqsave(&phba->hbalock, iflags);
13908 lpfc_sli4_rq_release(hrq, drq);
13909 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
13911 hrq->RQ_no_buf_found++;
13912 spin_unlock_irqrestore(&phba->hbalock, iflags);
13916 hrq->RQ_buf_posted--;
13917 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
13919 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
13921 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
13922 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
13923 spin_unlock_irqrestore(&phba->hbalock, iflags);
13924 /* Handle MDS Loopback frames */
13925 if (!(phba->pport->load_flag & FC_UNLOADING))
13926 lpfc_sli4_handle_mds_loopback(phba->pport,
13929 lpfc_in_buf_free(phba, &dma_buf->dbuf);
13933 /* save off the frame for the work thread to process */
13934 list_add_tail(&dma_buf->cq_event.list,
13935 &phba->sli4_hba.sp_queue_event);
13936 /* Frame received */
13937 phba->hba_flag |= HBA_SP_QUEUE_EVT;
13938 spin_unlock_irqrestore(&phba->hbalock, iflags);
13941 case FC_STATUS_INSUFF_BUF_FRM_DISC:
13942 if (phba->nvmet_support) {
13943 tgtp = phba->targetport->private;
13944 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13945 "6402 RQE Error x%x, posted %d err_cnt "
13947 status, hrq->RQ_buf_posted,
13948 hrq->RQ_no_posted_buf,
13949 atomic_read(&tgtp->rcv_fcp_cmd_in),
13950 atomic_read(&tgtp->rcv_fcp_cmd_out),
13951 atomic_read(&tgtp->xmt_fcp_release));
13955 case FC_STATUS_INSUFF_BUF_NEED_BUF:
13956 hrq->RQ_no_posted_buf++;
13957 /* Post more buffers if possible */
13958 spin_lock_irqsave(&phba->hbalock, iflags);
13959 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
13960 spin_unlock_irqrestore(&phba->hbalock, iflags);
13969 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
13970 * @phba: Pointer to HBA context object.
13971 * @cq: Pointer to the completion queue.
13972 * @cqe: Pointer to a completion queue entry.
13974 * This routine process a slow-path work-queue or receive queue completion queue
13977 * Return: true if work posted to worker thread, otherwise false.
13980 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
13981 struct lpfc_cqe *cqe)
13983 struct lpfc_cqe cqevt;
13984 bool workposted = false;
13986 /* Copy the work queue CQE and convert endian order if needed */
13987 lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
13989 /* Check and process for different type of WCQE and dispatch */
13990 switch (bf_get(lpfc_cqe_code, &cqevt)) {
13991 case CQE_CODE_COMPL_WQE:
13992 /* Process the WQ/RQ complete event */
13993 phba->last_completion_time = jiffies;
13994 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
13995 (struct lpfc_wcqe_complete *)&cqevt);
13997 case CQE_CODE_RELEASE_WQE:
13998 /* Process the WQ release event */
13999 lpfc_sli4_sp_handle_rel_wcqe(phba,
14000 (struct lpfc_wcqe_release *)&cqevt);
14002 case CQE_CODE_XRI_ABORTED:
14003 /* Process the WQ XRI abort event */
14004 phba->last_completion_time = jiffies;
14005 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
14006 (struct sli4_wcqe_xri_aborted *)&cqevt);
14008 case CQE_CODE_RECEIVE:
14009 case CQE_CODE_RECEIVE_V1:
14010 /* Process the RQ event */
14011 phba->last_completion_time = jiffies;
14012 workposted = lpfc_sli4_sp_handle_rcqe(phba,
14013 (struct lpfc_rcqe *)&cqevt);
14016 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14017 "0388 Not a valid WCQE code: x%x\n",
14018 bf_get(lpfc_cqe_code, &cqevt));
14025 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
14026 * @phba: Pointer to HBA context object.
14027 * @eqe: Pointer to fast-path event queue entry.
14028 * @speq: Pointer to slow-path event queue.
14030 * This routine process a event queue entry from the slow-path event queue.
14031 * It will check the MajorCode and MinorCode to determine this is for a
14032 * completion event on a completion queue, if not, an error shall be logged
14033 * and just return. Otherwise, it will get to the corresponding completion
14034 * queue and process all the entries on that completion queue, rearm the
14035 * completion queue, and then return.
14039 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
14040 struct lpfc_queue *speq)
14042 struct lpfc_queue *cq = NULL, *childq;
14046 /* Get the reference to the corresponding CQ */
14047 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
14049 list_for_each_entry(childq, &speq->child_list, list) {
14050 if (childq->queue_id == cqid) {
14055 if (unlikely(!cq)) {
14056 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
14057 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14058 "0365 Slow-path CQ identifier "
14059 "(%d) does not exist\n", cqid);
14063 /* Save EQ associated with this CQ */
14064 cq->assoc_qp = speq;
14066 if (is_kdump_kernel())
14067 ret = queue_work(phba->wq, &cq->spwork);
14069 ret = queue_work_on(cq->chann, phba->wq, &cq->spwork);
14072 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14073 "0390 Cannot schedule queue work "
14074 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
14075 cqid, cq->queue_id, raw_smp_processor_id());
14079 * __lpfc_sli4_process_cq - Process elements of a CQ
14080 * @phba: Pointer to HBA context object.
14081 * @cq: Pointer to CQ to be processed
14082 * @handler: Routine to process each cqe
14083 * @delay: Pointer to usdelay to set in case of rescheduling of the handler
14084 * @poll_mode: Polling mode we were called from
14086 * This routine processes completion queue entries in a CQ. While a valid
14087 * queue element is found, the handler is called. During processing checks
14088 * are made for periodic doorbell writes to let the hardware know of
14089 * element consumption.
14091 * If the max limit on cqes to process is hit, or there are no more valid
14092 * entries, the loop stops. If we processed a sufficient number of elements,
14093 * meaning there is sufficient load, rather than rearming and generating
14094 * another interrupt, a cq rescheduling delay will be set. A delay of 0
14095 * indicates no rescheduling.
14097 * Returns True if work scheduled, False otherwise.
14100 __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
14101 bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
14102 struct lpfc_cqe *), unsigned long *delay,
14103 enum lpfc_poll_mode poll_mode)
14105 struct lpfc_cqe *cqe;
14106 bool workposted = false;
14107 int count = 0, consumed = 0;
14110 /* default - no reschedule */
14113 if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
14114 goto rearm_and_exit;
14116 /* Process all the entries to the CQ */
14118 cqe = lpfc_sli4_cq_get(cq);
14120 workposted |= handler(phba, cq, cqe);
14121 __lpfc_sli4_consume_cqe(phba, cq, cqe);
14124 if (!(++count % cq->max_proc_limit))
14127 if (!(count % cq->notify_interval)) {
14128 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
14131 cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK;
14134 if (count == LPFC_NVMET_CQ_NOTIFY)
14135 cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
14137 cqe = lpfc_sli4_cq_get(cq);
14139 if (count >= phba->cfg_cq_poll_threshold) {
14144 /* Note: complete the irq_poll softirq before rearming CQ */
14145 if (poll_mode == LPFC_IRQ_POLL)
14146 irq_poll_complete(&cq->iop);
14148 /* Track the max number of CQEs processed in 1 EQ */
14149 if (count > cq->CQ_max_cqe)
14150 cq->CQ_max_cqe = count;
14152 cq->assoc_qp->EQ_cqe_cnt += count;
14154 /* Catch the no cq entry condition */
14155 if (unlikely(count == 0))
14156 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14157 "0369 No entry from completion queue "
14158 "qid=%d\n", cq->queue_id);
14160 xchg(&cq->queue_claimed, 0);
14163 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
14164 arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
14170 * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
14171 * @cq: pointer to CQ to process
14173 * This routine calls the cq processing routine with a handler specific
14174 * to the type of queue bound to it.
14176 * The CQ routine returns two values: the first is the calling status,
14177 * which indicates whether work was queued to the background discovery
14178 * thread. If true, the routine should wakeup the discovery thread;
14179 * the second is the delay parameter. If non-zero, rather than rearming
14180 * the CQ and yet another interrupt, the CQ handler should be queued so
14181 * that it is processed in a subsequent polling action. The value of
14182 * the delay indicates when to reschedule it.
14185 __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
14187 struct lpfc_hba *phba = cq->phba;
14188 unsigned long delay;
14189 bool workposted = false;
14192 /* Process and rearm the CQ */
14193 switch (cq->type) {
14195 workposted |= __lpfc_sli4_process_cq(phba, cq,
14196 lpfc_sli4_sp_handle_mcqe,
14197 &delay, LPFC_QUEUE_WORK);
14200 if (cq->subtype == LPFC_IO)
14201 workposted |= __lpfc_sli4_process_cq(phba, cq,
14202 lpfc_sli4_fp_handle_cqe,
14203 &delay, LPFC_QUEUE_WORK);
14205 workposted |= __lpfc_sli4_process_cq(phba, cq,
14206 lpfc_sli4_sp_handle_cqe,
14207 &delay, LPFC_QUEUE_WORK);
14210 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14211 "0370 Invalid completion queue type (%d)\n",
14217 if (is_kdump_kernel())
14218 ret = queue_delayed_work(phba->wq, &cq->sched_spwork,
14221 ret = queue_delayed_work_on(cq->chann, phba->wq,
14222 &cq->sched_spwork, delay);
14224 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14225 "0394 Cannot schedule queue work "
14226 "for cqid=%d on CPU %d\n",
14227 cq->queue_id, cq->chann);
14230 /* wake up worker thread if there are works to be done */
14232 lpfc_worker_wake_up(phba);
14236 * lpfc_sli4_sp_process_cq - slow-path work handler when started by
14238 * @work: pointer to work element
14240 * translates from the work handler and calls the slow-path handler.
14243 lpfc_sli4_sp_process_cq(struct work_struct *work)
14245 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
14247 __lpfc_sli4_sp_process_cq(cq);
14251 * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
14252 * @work: pointer to work element
14254 * translates from the work handler and calls the slow-path handler.
14257 lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
14259 struct lpfc_queue *cq = container_of(to_delayed_work(work),
14260 struct lpfc_queue, sched_spwork);
14262 __lpfc_sli4_sp_process_cq(cq);
14266 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
14267 * @phba: Pointer to HBA context object.
14268 * @cq: Pointer to associated CQ
14269 * @wcqe: Pointer to work-queue completion queue entry.
14271 * This routine process a fast-path work queue completion entry from fast-path
14272 * event queue for FCP command response completion.
14275 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14276 struct lpfc_wcqe_complete *wcqe)
14278 struct lpfc_sli_ring *pring = cq->pring;
14279 struct lpfc_iocbq *cmdiocbq;
14280 struct lpfc_iocbq irspiocbq;
14281 unsigned long iflags;
14283 /* Check for response status */
14284 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
14285 /* If resource errors reported from HBA, reduce queue
14286 * depth of the SCSI device.
14288 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
14289 IOSTAT_LOCAL_REJECT)) &&
14290 ((wcqe->parameter & IOERR_PARAM_MASK) ==
14291 IOERR_NO_RESOURCES))
14292 phba->lpfc_rampdown_queue_depth(phba);
14294 /* Log the cmpl status */
14295 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14296 "0373 FCP CQE cmpl: status=x%x: "
14297 "CQE: %08x %08x %08x %08x\n",
14298 bf_get(lpfc_wcqe_c_status, wcqe),
14299 wcqe->word0, wcqe->total_data_placed,
14300 wcqe->parameter, wcqe->word3);
14303 /* Look up the FCP command IOCB and create pseudo response IOCB */
14304 spin_lock_irqsave(&pring->ring_lock, iflags);
14305 pring->stats.iocb_event++;
14306 spin_unlock_irqrestore(&pring->ring_lock, iflags);
14307 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
14308 bf_get(lpfc_wcqe_c_request_tag, wcqe));
14309 if (unlikely(!cmdiocbq)) {
14310 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14311 "0374 FCP complete with no corresponding "
14312 "cmdiocb: iotag (%d)\n",
14313 bf_get(lpfc_wcqe_c_request_tag, wcqe));
14316 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
14317 cmdiocbq->isr_timestamp = cq->isr_timestamp;
14319 if (cmdiocbq->iocb_cmpl == NULL) {
14320 if (cmdiocbq->wqe_cmpl) {
14321 /* For FCP the flag is cleared in wqe_cmpl */
14322 if (!(cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
14323 cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
14324 spin_lock_irqsave(&phba->hbalock, iflags);
14325 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
14326 spin_unlock_irqrestore(&phba->hbalock, iflags);
14329 /* Pass the cmd_iocb and the wcqe to the upper layer */
14330 (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe);
14333 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14334 "0375 FCP cmdiocb not callback function "
14336 bf_get(lpfc_wcqe_c_request_tag, wcqe));
14340 /* Only SLI4 non-IO commands stil use IOCB */
14341 /* Fake the irspiocb and copy necessary response information */
14342 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
14344 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
14345 spin_lock_irqsave(&phba->hbalock, iflags);
14346 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
14347 spin_unlock_irqrestore(&phba->hbalock, iflags);
14350 /* Pass the cmd_iocb and the rsp state to the upper layer */
14351 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
14355 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
14356 * @phba: Pointer to HBA context object.
14357 * @cq: Pointer to completion queue.
14358 * @wcqe: Pointer to work-queue completion queue entry.
14360 * This routine handles an fast-path WQ entry consumed event by invoking the
14361 * proper WQ release routine to the slow-path WQ.
14364 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14365 struct lpfc_wcqe_release *wcqe)
14367 struct lpfc_queue *childwq;
14368 bool wqid_matched = false;
14371 /* Check for fast-path FCP work queue release */
14372 hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
14373 list_for_each_entry(childwq, &cq->child_list, list) {
14374 if (childwq->queue_id == hba_wqid) {
14375 lpfc_sli4_wq_release(childwq,
14376 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
14377 if (childwq->q_flag & HBA_NVMET_WQFULL)
14378 lpfc_nvmet_wqfull_process(phba, childwq);
14379 wqid_matched = true;
14383 /* Report warning log message if no match found */
14384 if (wqid_matched != true)
14385 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14386 "2580 Fast-path wqe consume event carries "
14387 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
14391 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
14392 * @phba: Pointer to HBA context object.
14393 * @cq: Pointer to completion queue.
14394 * @rcqe: Pointer to receive-queue completion queue entry.
14396 * This routine process a receive-queue completion queue entry.
14398 * Return: true if work posted to worker thread, otherwise false.
14401 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14402 struct lpfc_rcqe *rcqe)
14404 bool workposted = false;
14405 struct lpfc_queue *hrq;
14406 struct lpfc_queue *drq;
14407 struct rqb_dmabuf *dma_buf;
14408 struct fc_frame_header *fc_hdr;
14409 struct lpfc_nvmet_tgtport *tgtp;
14410 uint32_t status, rq_id;
14411 unsigned long iflags;
14412 uint32_t fctl, idx;
14414 if ((phba->nvmet_support == 0) ||
14415 (phba->sli4_hba.nvmet_cqset == NULL))
14418 idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
14419 hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
14420 drq = phba->sli4_hba.nvmet_mrq_data[idx];
14422 /* sanity check on queue memory */
14423 if (unlikely(!hrq) || unlikely(!drq))
14426 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
14427 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
14429 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
14431 if ((phba->nvmet_support == 0) ||
14432 (rq_id != hrq->queue_id))
14435 status = bf_get(lpfc_rcqe_status, rcqe);
14437 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
14438 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14439 "6126 Receive Frame Truncated!!\n");
14441 case FC_STATUS_RQ_SUCCESS:
14442 spin_lock_irqsave(&phba->hbalock, iflags);
14443 lpfc_sli4_rq_release(hrq, drq);
14444 dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
14446 hrq->RQ_no_buf_found++;
14447 spin_unlock_irqrestore(&phba->hbalock, iflags);
14450 spin_unlock_irqrestore(&phba->hbalock, iflags);
14452 hrq->RQ_buf_posted--;
14453 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
14455 /* Just some basic sanity checks on FCP Command frame */
14456 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
14457 fc_hdr->fh_f_ctl[1] << 8 |
14458 fc_hdr->fh_f_ctl[2]);
14460 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
14461 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
14462 (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
14465 if (fc_hdr->fh_type == FC_TYPE_FCP) {
14466 dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
14467 lpfc_nvmet_unsol_fcp_event(
14468 phba, idx, dma_buf, cq->isr_timestamp,
14469 cq->q_flag & HBA_NVMET_CQ_NOTIFY);
14473 lpfc_rq_buf_free(phba, &dma_buf->hbuf);
14475 case FC_STATUS_INSUFF_BUF_FRM_DISC:
14476 if (phba->nvmet_support) {
14477 tgtp = phba->targetport->private;
14478 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14479 "6401 RQE Error x%x, posted %d err_cnt "
14481 status, hrq->RQ_buf_posted,
14482 hrq->RQ_no_posted_buf,
14483 atomic_read(&tgtp->rcv_fcp_cmd_in),
14484 atomic_read(&tgtp->rcv_fcp_cmd_out),
14485 atomic_read(&tgtp->xmt_fcp_release));
14489 case FC_STATUS_INSUFF_BUF_NEED_BUF:
14490 hrq->RQ_no_posted_buf++;
14491 /* Post more buffers if possible */
14499 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
14500 * @phba: adapter with cq
14501 * @cq: Pointer to the completion queue.
14502 * @cqe: Pointer to fast-path completion queue entry.
14504 * This routine process a fast-path work queue completion entry from fast-path
14505 * event queue for FCP command response completion.
14507 * Return: true if work posted to worker thread, otherwise false.
14510 lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14511 struct lpfc_cqe *cqe)
14513 struct lpfc_wcqe_release wcqe;
14514 bool workposted = false;
14516 /* Copy the work queue CQE and convert endian order if needed */
14517 lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
14519 /* Check and process for different type of WCQE and dispatch */
14520 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
14521 case CQE_CODE_COMPL_WQE:
14522 case CQE_CODE_NVME_ERSP:
14524 /* Process the WQ complete event */
14525 phba->last_completion_time = jiffies;
14526 if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
14527 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
14528 (struct lpfc_wcqe_complete *)&wcqe);
14530 case CQE_CODE_RELEASE_WQE:
14531 cq->CQ_release_wqe++;
14532 /* Process the WQ release event */
14533 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
14534 (struct lpfc_wcqe_release *)&wcqe);
14536 case CQE_CODE_XRI_ABORTED:
14537 cq->CQ_xri_aborted++;
14538 /* Process the WQ XRI abort event */
14539 phba->last_completion_time = jiffies;
14540 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
14541 (struct sli4_wcqe_xri_aborted *)&wcqe);
14543 case CQE_CODE_RECEIVE_V1:
14544 case CQE_CODE_RECEIVE:
14545 phba->last_completion_time = jiffies;
14546 if (cq->subtype == LPFC_NVMET) {
14547 workposted = lpfc_sli4_nvmet_handle_rcqe(
14548 phba, cq, (struct lpfc_rcqe *)&wcqe);
14552 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14553 "0144 Not a valid CQE code: x%x\n",
14554 bf_get(lpfc_wcqe_c_code, &wcqe));
14561 * lpfc_sli4_sched_cq_work - Schedules cq work
14562 * @phba: Pointer to HBA context object.
14563 * @cq: Pointer to CQ
14566 * This routine checks the poll mode of the CQ corresponding to
14567 * cq->chann, then either schedules a softirq or queue_work to complete
14570 * queue_work path is taken if in NVMET mode, or if poll_mode is in
14571 * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken.
14574 static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba,
14575 struct lpfc_queue *cq, uint16_t cqid)
14579 switch (cq->poll_mode) {
14580 case LPFC_IRQ_POLL:
14581 irq_poll_sched(&cq->iop);
14583 case LPFC_QUEUE_WORK:
14585 if (is_kdump_kernel())
14586 ret = queue_work(phba->wq, &cq->irqwork);
14588 ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork);
14590 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14591 "0383 Cannot schedule queue work "
14592 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
14593 cqid, cq->queue_id,
14594 raw_smp_processor_id());
14599 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
14600 * @phba: Pointer to HBA context object.
14601 * @eq: Pointer to the queue structure.
14602 * @eqe: Pointer to fast-path event queue entry.
14604 * This routine process a event queue entry from the fast-path event queue.
14605 * It will check the MajorCode and MinorCode to determine this is for a
14606 * completion event on a completion queue, if not, an error shall be logged
14607 * and just return. Otherwise, it will get to the corresponding completion
14608 * queue and process all the entries on the completion queue, rearm the
14609 * completion queue, and then return.
14612 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
14613 struct lpfc_eqe *eqe)
14615 struct lpfc_queue *cq = NULL;
14616 uint32_t qidx = eq->hdwq;
14619 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
14620 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14621 "0366 Not a valid completion "
14622 "event: majorcode=x%x, minorcode=x%x\n",
14623 bf_get_le32(lpfc_eqe_major_code, eqe),
14624 bf_get_le32(lpfc_eqe_minor_code, eqe));
14628 /* Get the reference to the corresponding CQ */
14629 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
14631 /* Use the fast lookup method first */
14632 if (cqid <= phba->sli4_hba.cq_max) {
14633 cq = phba->sli4_hba.cq_lookup[cqid];
14638 /* Next check for NVMET completion */
14639 if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
14640 id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
14641 if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
14642 /* Process NVMET unsol rcv */
14643 cq = phba->sli4_hba.nvmet_cqset[cqid - id];
14648 if (phba->sli4_hba.nvmels_cq &&
14649 (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
14650 /* Process NVME unsol rcv */
14651 cq = phba->sli4_hba.nvmels_cq;
14654 /* Otherwise this is a Slow path event */
14656 lpfc_sli4_sp_handle_eqe(phba, eqe,
14657 phba->sli4_hba.hdwq[qidx].hba_eq);
14662 if (unlikely(cqid != cq->queue_id)) {
14663 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14664 "0368 Miss-matched fast-path completion "
14665 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
14666 cqid, cq->queue_id);
14671 #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
14672 if (phba->ktime_on)
14673 cq->isr_timestamp = ktime_get_ns();
14675 cq->isr_timestamp = 0;
14677 lpfc_sli4_sched_cq_work(phba, cq, cqid);
14681 * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
14682 * @cq: Pointer to CQ to be processed
14683 * @poll_mode: Enum lpfc_poll_state to determine poll mode
14685 * This routine calls the cq processing routine with the handler for
14688 * The CQ routine returns two values: the first is the calling status,
14689 * which indicates whether work was queued to the background discovery
14690 * thread. If true, the routine should wakeup the discovery thread;
14691 * the second is the delay parameter. If non-zero, rather than rearming
14692 * the CQ and yet another interrupt, the CQ handler should be queued so
14693 * that it is processed in a subsequent polling action. The value of
14694 * the delay indicates when to reschedule it.
14697 __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq,
14698 enum lpfc_poll_mode poll_mode)
14700 struct lpfc_hba *phba = cq->phba;
14701 unsigned long delay;
14702 bool workposted = false;
14705 /* process and rearm the CQ */
14706 workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
14707 &delay, poll_mode);
14710 if (is_kdump_kernel())
14711 ret = queue_delayed_work(phba->wq, &cq->sched_irqwork,
14714 ret = queue_delayed_work_on(cq->chann, phba->wq,
14715 &cq->sched_irqwork, delay);
14717 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14718 "0367 Cannot schedule queue work "
14719 "for cqid=%d on CPU %d\n",
14720 cq->queue_id, cq->chann);
14723 /* wake up worker thread if there are works to be done */
14725 lpfc_worker_wake_up(phba);
14729 * lpfc_sli4_hba_process_cq - fast-path work handler when started by
14731 * @work: pointer to work element
14733 * translates from the work handler and calls the fast-path handler.
14736 lpfc_sli4_hba_process_cq(struct work_struct *work)
14738 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
14740 __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
14744 * lpfc_sli4_hba_process_cq - fast-path work handler when started by timer
14745 * @work: pointer to work element
14747 * translates from the work handler and calls the fast-path handler.
14750 lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
14752 struct lpfc_queue *cq = container_of(to_delayed_work(work),
14753 struct lpfc_queue, sched_irqwork);
14755 __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
14759 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
14760 * @irq: Interrupt number.
14761 * @dev_id: The device context pointer.
14763 * This function is directly called from the PCI layer as an interrupt
14764 * service routine when device with SLI-4 interface spec is enabled with
14765 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
14766 * ring event in the HBA. However, when the device is enabled with either
14767 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
14768 * device-level interrupt handler. When the PCI slot is in error recovery
14769 * or the HBA is undergoing initialization, the interrupt handler will not
14770 * process the interrupt. The SCSI FCP fast-path ring event are handled in
14771 * the intrrupt context. This function is called without any lock held.
14772 * It gets the hbalock to access and update SLI data structures. Note that,
14773 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
14774 * equal to that of FCP CQ index.
14776 * The link attention and ELS ring attention events are handled
14777 * by the worker thread. The interrupt handler signals the worker thread
14778 * and returns for these events. This function is called without any lock
14779 * held. It gets the hbalock to access and update SLI data structures.
14781 * This function returns IRQ_HANDLED when interrupt is handled else it
14782 * returns IRQ_NONE.
14785 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
14787 struct lpfc_hba *phba;
14788 struct lpfc_hba_eq_hdl *hba_eq_hdl;
14789 struct lpfc_queue *fpeq;
14790 unsigned long iflag;
14793 struct lpfc_eq_intr_info *eqi;
14795 /* Get the driver's phba structure from the dev_id */
14796 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
14797 phba = hba_eq_hdl->phba;
14798 hba_eqidx = hba_eq_hdl->idx;
14800 if (unlikely(!phba))
14802 if (unlikely(!phba->sli4_hba.hdwq))
14805 /* Get to the EQ struct associated with this vector */
14806 fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
14807 if (unlikely(!fpeq))
14810 /* Check device state for handling interrupt */
14811 if (unlikely(lpfc_intr_state_check(phba))) {
14812 /* Check again for link_state with lock held */
14813 spin_lock_irqsave(&phba->hbalock, iflag);
14814 if (phba->link_state < LPFC_LINK_DOWN)
14815 /* Flush, clear interrupt, and rearm the EQ */
14816 lpfc_sli4_eqcq_flush(phba, fpeq);
14817 spin_unlock_irqrestore(&phba->hbalock, iflag);
14821 eqi = this_cpu_ptr(phba->sli4_hba.eq_info);
14824 fpeq->last_cpu = raw_smp_processor_id();
14826 if (eqi->icnt > LPFC_EQD_ISR_TRIGGER &&
14827 fpeq->q_flag & HBA_EQ_DELAY_CHK &&
14828 phba->cfg_auto_imax &&
14829 fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
14830 phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
14831 lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
14833 /* process and rearm the EQ */
14834 ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
14836 if (unlikely(ecount == 0)) {
14837 fpeq->EQ_no_entry++;
14838 if (phba->intr_type == MSIX)
14839 /* MSI-X treated interrupt served as no EQ share INT */
14840 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14841 "0358 MSI-X interrupt with no EQE\n");
14843 /* Non MSI-X treated on interrupt as EQ share INT */
14847 return IRQ_HANDLED;
14848 } /* lpfc_sli4_fp_intr_handler */
14851 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
14852 * @irq: Interrupt number.
14853 * @dev_id: The device context pointer.
14855 * This function is the device-level interrupt handler to device with SLI-4
14856 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
14857 * interrupt mode is enabled and there is an event in the HBA which requires
14858 * driver attention. This function invokes the slow-path interrupt attention
14859 * handling function and fast-path interrupt attention handling function in
14860 * turn to process the relevant HBA attention events. This function is called
14861 * without any lock held. It gets the hbalock to access and update SLI data
14864 * This function returns IRQ_HANDLED when interrupt is handled, else it
14865 * returns IRQ_NONE.
14868 lpfc_sli4_intr_handler(int irq, void *dev_id)
14870 struct lpfc_hba *phba;
14871 irqreturn_t hba_irq_rc;
14872 bool hba_handled = false;
14875 /* Get the driver's phba structure from the dev_id */
14876 phba = (struct lpfc_hba *)dev_id;
14878 if (unlikely(!phba))
14882 * Invoke fast-path host attention interrupt handling as appropriate.
14884 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
14885 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
14886 &phba->sli4_hba.hba_eq_hdl[qidx]);
14887 if (hba_irq_rc == IRQ_HANDLED)
14888 hba_handled |= true;
14891 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
14892 } /* lpfc_sli4_intr_handler */
14894 void lpfc_sli4_poll_hbtimer(struct timer_list *t)
14896 struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer);
14897 struct lpfc_queue *eq;
14902 list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list)
14903 i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH);
14904 if (!list_empty(&phba->poll_list))
14905 mod_timer(&phba->cpuhp_poll_timer,
14906 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
14911 inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path)
14913 struct lpfc_hba *phba = eq->phba;
14917 * Unlocking an irq is one of the entry point to check
14918 * for re-schedule, but we are good for io submission
14919 * path as midlayer does a get_cpu to glue us in. Flush
14920 * out the invalidate queue so we can see the updated
14925 if (READ_ONCE(eq->mode) == LPFC_EQ_POLL)
14926 /* We will not likely get the completion for the caller
14927 * during this iteration but i guess that's fine.
14928 * Future io's coming on this eq should be able to
14929 * pick it up. As for the case of single io's, they
14930 * will be handled through a sched from polling timer
14931 * function which is currently triggered every 1msec.
14933 i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM);
14938 static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq)
14940 struct lpfc_hba *phba = eq->phba;
14942 /* kickstart slowpath processing if needed */
14943 if (list_empty(&phba->poll_list))
14944 mod_timer(&phba->cpuhp_poll_timer,
14945 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
14947 list_add_rcu(&eq->_poll_list, &phba->poll_list);
14951 static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq)
14953 struct lpfc_hba *phba = eq->phba;
14955 /* Disable slowpath processing for this eq. Kick start the eq
14956 * by RE-ARMING the eq's ASAP
14958 list_del_rcu(&eq->_poll_list);
14961 if (list_empty(&phba->poll_list))
14962 del_timer_sync(&phba->cpuhp_poll_timer);
14965 void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba)
14967 struct lpfc_queue *eq, *next;
14969 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list)
14970 list_del(&eq->_poll_list);
14972 INIT_LIST_HEAD(&phba->poll_list);
14977 __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode)
14979 if (mode == eq->mode)
14982 * currently this function is only called during a hotplug
14983 * event and the cpu on which this function is executing
14984 * is going offline. By now the hotplug has instructed
14985 * the scheduler to remove this cpu from cpu active mask.
14986 * So we don't need to work about being put aside by the
14987 * scheduler for a high priority process. Yes, the inte-
14988 * rrupts could come but they are known to retire ASAP.
14991 /* Disable polling in the fastpath */
14992 WRITE_ONCE(eq->mode, mode);
14993 /* flush out the store buffer */
14997 * Add this eq to the polling list and start polling. For
14998 * a grace period both interrupt handler and poller will
14999 * try to process the eq _but_ that's fine. We have a
15000 * synchronization mechanism in place (queue_claimed) to
15001 * deal with it. This is just a draining phase for int-
15002 * errupt handler (not eq's) as we have guranteed through
15003 * barrier that all the CPUs have seen the new CQ_POLLED
15004 * state. which will effectively disable the REARMING of
15005 * the EQ. The whole idea is eq's die off eventually as
15006 * we are not rearming EQ's anymore.
15008 mode ? lpfc_sli4_add_to_poll_list(eq) :
15009 lpfc_sli4_remove_from_poll_list(eq);
15012 void lpfc_sli4_start_polling(struct lpfc_queue *eq)
15014 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL);
15017 void lpfc_sli4_stop_polling(struct lpfc_queue *eq)
15019 struct lpfc_hba *phba = eq->phba;
15021 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT);
15023 /* Kick start for the pending io's in h/w.
15024 * Once we switch back to interrupt processing on a eq
15025 * the io path completion will only arm eq's when it
15026 * receives a completion. But since eq's are in disa-
15027 * rmed state it doesn't receive a completion. This
15028 * creates a deadlock scenaro.
15030 phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM);
15034 * lpfc_sli4_queue_free - free a queue structure and associated memory
15035 * @queue: The queue structure to free.
15037 * This function frees a queue structure and the DMAable memory used for
15038 * the host resident queue. This function must be called after destroying the
15039 * queue on the HBA.
15042 lpfc_sli4_queue_free(struct lpfc_queue *queue)
15044 struct lpfc_dmabuf *dmabuf;
15049 if (!list_empty(&queue->wq_list))
15050 list_del(&queue->wq_list);
15052 while (!list_empty(&queue->page_list)) {
15053 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
15055 dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
15056 dmabuf->virt, dmabuf->phys);
15060 lpfc_free_rq_buffer(queue->phba, queue);
15061 kfree(queue->rqbp);
15064 if (!list_empty(&queue->cpu_list))
15065 list_del(&queue->cpu_list);
15072 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
15073 * @phba: The HBA that this queue is being created on.
15074 * @page_size: The size of a queue page
15075 * @entry_size: The size of each queue entry for this queue.
15076 * @entry_count: The number of entries that this queue will handle.
15077 * @cpu: The cpu that will primarily utilize this queue.
15079 * This function allocates a queue structure and the DMAable memory used for
15080 * the host resident queue. This function must be called before creating the
15081 * queue on the HBA.
15083 struct lpfc_queue *
15084 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
15085 uint32_t entry_size, uint32_t entry_count, int cpu)
15087 struct lpfc_queue *queue;
15088 struct lpfc_dmabuf *dmabuf;
15089 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15092 if (!phba->sli4_hba.pc_sli4_params.supported)
15093 hw_page_size = page_size;
15095 pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
15097 /* If needed, Adjust page count to match the max the adapter supports */
15098 if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
15099 pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
15101 queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
15102 GFP_KERNEL, cpu_to_node(cpu));
15106 INIT_LIST_HEAD(&queue->list);
15107 INIT_LIST_HEAD(&queue->_poll_list);
15108 INIT_LIST_HEAD(&queue->wq_list);
15109 INIT_LIST_HEAD(&queue->wqfull_list);
15110 INIT_LIST_HEAD(&queue->page_list);
15111 INIT_LIST_HEAD(&queue->child_list);
15112 INIT_LIST_HEAD(&queue->cpu_list);
15114 /* Set queue parameters now. If the system cannot provide memory
15115 * resources, the free routine needs to know what was allocated.
15117 queue->page_count = pgcnt;
15118 queue->q_pgs = (void **)&queue[1];
15119 queue->entry_cnt_per_pg = hw_page_size / entry_size;
15120 queue->entry_size = entry_size;
15121 queue->entry_count = entry_count;
15122 queue->page_size = hw_page_size;
15123 queue->phba = phba;
15125 for (x = 0; x < queue->page_count; x++) {
15126 dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
15127 dev_to_node(&phba->pcidev->dev));
15130 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
15131 hw_page_size, &dmabuf->phys,
15133 if (!dmabuf->virt) {
15137 dmabuf->buffer_tag = x;
15138 list_add_tail(&dmabuf->list, &queue->page_list);
15139 /* use lpfc_sli4_qe to index a paritcular entry in this page */
15140 queue->q_pgs[x] = dmabuf->virt;
15142 INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
15143 INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
15144 INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
15145 INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
15147 /* notify_interval will be set during q creation */
15151 lpfc_sli4_queue_free(queue);
15156 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
15157 * @phba: HBA structure that indicates port to create a queue on.
15158 * @pci_barset: PCI BAR set flag.
15160 * This function shall perform iomap of the specified PCI BAR address to host
15161 * memory address if not already done so and return it. The returned host
15162 * memory address can be NULL.
15164 static void __iomem *
15165 lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
15170 switch (pci_barset) {
15171 case WQ_PCI_BAR_0_AND_1:
15172 return phba->pci_bar0_memmap_p;
15173 case WQ_PCI_BAR_2_AND_3:
15174 return phba->pci_bar2_memmap_p;
15175 case WQ_PCI_BAR_4_AND_5:
15176 return phba->pci_bar4_memmap_p;
15184 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
15185 * @phba: HBA structure that EQs are on.
15186 * @startq: The starting EQ index to modify
15187 * @numq: The number of EQs (consecutive indexes) to modify
15188 * @usdelay: amount of delay
15190 * This function revises the EQ delay on 1 or more EQs. The EQ delay
15191 * is set either by writing to a register (if supported by the SLI Port)
15192 * or by mailbox command. The mailbox command allows several EQs to be
15195 * The @phba struct is used to send a mailbox command to HBA. The @startq
15196 * is used to get the starting EQ index to change. The @numq value is
15197 * used to specify how many consecutive EQ indexes, starting at EQ index,
15198 * are to be changed. This function is asynchronous and will wait for any
15199 * mailbox commands to finish before returning.
15201 * On success this function will return a zero. If unable to allocate
15202 * enough memory this function will return -ENOMEM. If a mailbox command
15203 * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
15204 * have had their delay multipler changed.
15207 lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
15208 uint32_t numq, uint32_t usdelay)
15210 struct lpfc_mbx_modify_eq_delay *eq_delay;
15211 LPFC_MBOXQ_t *mbox;
15212 struct lpfc_queue *eq;
15213 int cnt = 0, rc, length;
15214 uint32_t shdr_status, shdr_add_status;
15217 union lpfc_sli4_cfg_shdr *shdr;
15219 if (startq >= phba->cfg_irq_chann)
15222 if (usdelay > 0xFFFF) {
15223 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
15224 "6429 usdelay %d too large. Scaled down to "
15225 "0xFFFF.\n", usdelay);
15229 /* set values by EQ_DELAY register if supported */
15230 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
15231 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
15232 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
15236 lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
15244 /* Otherwise, set values by mailbox cmd */
15246 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15248 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15249 "6428 Failed allocating mailbox cmd buffer."
15250 " EQ delay was not set.\n");
15253 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
15254 sizeof(struct lpfc_sli4_cfg_mhdr));
15255 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15256 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
15257 length, LPFC_SLI4_MBX_EMBED);
15258 eq_delay = &mbox->u.mqe.un.eq_delay;
15260 /* Calculate delay multiper from maximum interrupt per second */
15261 dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
15264 if (dmult > LPFC_DMULT_MAX)
15265 dmult = LPFC_DMULT_MAX;
15267 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
15268 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
15271 eq->q_mode = usdelay;
15272 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
15273 eq_delay->u.request.eq[cnt].phase = 0;
15274 eq_delay->u.request.eq[cnt].delay_multi = dmult;
15279 eq_delay->u.request.num_eq = cnt;
15281 mbox->vport = phba->pport;
15282 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
15283 mbox->ctx_buf = NULL;
15284 mbox->ctx_ndlp = NULL;
15285 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15286 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
15287 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15288 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15289 if (shdr_status || shdr_add_status || rc) {
15290 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15291 "2512 MODIFY_EQ_DELAY mailbox failed with "
15292 "status x%x add_status x%x, mbx status x%x\n",
15293 shdr_status, shdr_add_status, rc);
15295 mempool_free(mbox, phba->mbox_mem_pool);
15300 * lpfc_eq_create - Create an Event Queue on the HBA
15301 * @phba: HBA structure that indicates port to create a queue on.
15302 * @eq: The queue structure to use to create the event queue.
15303 * @imax: The maximum interrupt per second limit.
15305 * This function creates an event queue, as detailed in @eq, on a port,
15306 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
15308 * The @phba struct is used to send mailbox command to HBA. The @eq struct
15309 * is used to get the entry count and entry size that are necessary to
15310 * determine the number of pages to allocate and use for this queue. This
15311 * function will send the EQ_CREATE mailbox command to the HBA to setup the
15312 * event queue. This function is asynchronous and will wait for the mailbox
15313 * command to finish before continuing.
15315 * On success this function will return a zero. If unable to allocate enough
15316 * memory this function will return -ENOMEM. If the queue create mailbox command
15317 * fails this function will return -ENXIO.
15320 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
15322 struct lpfc_mbx_eq_create *eq_create;
15323 LPFC_MBOXQ_t *mbox;
15324 int rc, length, status = 0;
15325 struct lpfc_dmabuf *dmabuf;
15326 uint32_t shdr_status, shdr_add_status;
15327 union lpfc_sli4_cfg_shdr *shdr;
15329 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15331 /* sanity check on queue memory */
15334 if (!phba->sli4_hba.pc_sli4_params.supported)
15335 hw_page_size = SLI4_PAGE_SIZE;
15337 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15340 length = (sizeof(struct lpfc_mbx_eq_create) -
15341 sizeof(struct lpfc_sli4_cfg_mhdr));
15342 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15343 LPFC_MBOX_OPCODE_EQ_CREATE,
15344 length, LPFC_SLI4_MBX_EMBED);
15345 eq_create = &mbox->u.mqe.un.eq_create;
15346 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
15347 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
15349 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
15351 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
15353 /* Use version 2 of CREATE_EQ if eqav is set */
15354 if (phba->sli4_hba.pc_sli4_params.eqav) {
15355 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15356 LPFC_Q_CREATE_VERSION_2);
15357 bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
15358 phba->sli4_hba.pc_sli4_params.eqav);
15361 /* don't setup delay multiplier using EQ_CREATE */
15363 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
15365 switch (eq->entry_count) {
15367 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15368 "0360 Unsupported EQ count. (%d)\n",
15370 if (eq->entry_count < 256) {
15374 fallthrough; /* otherwise default to smallest count */
15376 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
15380 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
15384 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
15388 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
15392 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
15396 list_for_each_entry(dmabuf, &eq->page_list, list) {
15397 memset(dmabuf->virt, 0, hw_page_size);
15398 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15399 putPaddrLow(dmabuf->phys);
15400 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15401 putPaddrHigh(dmabuf->phys);
15403 mbox->vport = phba->pport;
15404 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
15405 mbox->ctx_buf = NULL;
15406 mbox->ctx_ndlp = NULL;
15407 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15408 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15409 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15410 if (shdr_status || shdr_add_status || rc) {
15411 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15412 "2500 EQ_CREATE mailbox failed with "
15413 "status x%x add_status x%x, mbx status x%x\n",
15414 shdr_status, shdr_add_status, rc);
15417 eq->type = LPFC_EQ;
15418 eq->subtype = LPFC_NONE;
15419 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
15420 if (eq->queue_id == 0xFFFF)
15422 eq->host_index = 0;
15423 eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
15424 eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
15426 mempool_free(mbox, phba->mbox_mem_pool);
15430 static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget)
15432 struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop);
15434 __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL);
15440 * lpfc_cq_create - Create a Completion Queue on the HBA
15441 * @phba: HBA structure that indicates port to create a queue on.
15442 * @cq: The queue structure to use to create the completion queue.
15443 * @eq: The event queue to bind this completion queue to.
15444 * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
15445 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
15447 * This function creates a completion queue, as detailed in @wq, on a port,
15448 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
15450 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15451 * is used to get the entry count and entry size that are necessary to
15452 * determine the number of pages to allocate and use for this queue. The @eq
15453 * is used to indicate which event queue to bind this completion queue to. This
15454 * function will send the CQ_CREATE mailbox command to the HBA to setup the
15455 * completion queue. This function is asynchronous and will wait for the mailbox
15456 * command to finish before continuing.
15458 * On success this function will return a zero. If unable to allocate enough
15459 * memory this function will return -ENOMEM. If the queue create mailbox command
15460 * fails this function will return -ENXIO.
15463 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
15464 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
15466 struct lpfc_mbx_cq_create *cq_create;
15467 struct lpfc_dmabuf *dmabuf;
15468 LPFC_MBOXQ_t *mbox;
15469 int rc, length, status = 0;
15470 uint32_t shdr_status, shdr_add_status;
15471 union lpfc_sli4_cfg_shdr *shdr;
15473 /* sanity check on queue memory */
15477 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15480 length = (sizeof(struct lpfc_mbx_cq_create) -
15481 sizeof(struct lpfc_sli4_cfg_mhdr));
15482 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15483 LPFC_MBOX_OPCODE_CQ_CREATE,
15484 length, LPFC_SLI4_MBX_EMBED);
15485 cq_create = &mbox->u.mqe.un.cq_create;
15486 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
15487 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
15489 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
15490 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
15491 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15492 phba->sli4_hba.pc_sli4_params.cqv);
15493 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
15494 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
15495 (cq->page_size / SLI4_PAGE_SIZE));
15496 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
15498 bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
15499 phba->sli4_hba.pc_sli4_params.cqav);
15501 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
15504 switch (cq->entry_count) {
15507 if (phba->sli4_hba.pc_sli4_params.cqv ==
15508 LPFC_Q_CREATE_VERSION_2) {
15509 cq_create->u.request.context.lpfc_cq_context_count =
15511 bf_set(lpfc_cq_context_count,
15512 &cq_create->u.request.context,
15513 LPFC_CQ_CNT_WORD7);
15518 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15519 "0361 Unsupported CQ count: "
15520 "entry cnt %d sz %d pg cnt %d\n",
15521 cq->entry_count, cq->entry_size,
15523 if (cq->entry_count < 256) {
15527 fallthrough; /* otherwise default to smallest count */
15529 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
15533 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
15537 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
15541 list_for_each_entry(dmabuf, &cq->page_list, list) {
15542 memset(dmabuf->virt, 0, cq->page_size);
15543 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15544 putPaddrLow(dmabuf->phys);
15545 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15546 putPaddrHigh(dmabuf->phys);
15548 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15550 /* The IOCTL status is embedded in the mailbox subheader. */
15551 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15552 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15553 if (shdr_status || shdr_add_status || rc) {
15554 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15555 "2501 CQ_CREATE mailbox failed with "
15556 "status x%x add_status x%x, mbx status x%x\n",
15557 shdr_status, shdr_add_status, rc);
15561 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
15562 if (cq->queue_id == 0xFFFF) {
15566 /* link the cq onto the parent eq child list */
15567 list_add_tail(&cq->list, &eq->child_list);
15568 /* Set up completion queue's type and subtype */
15570 cq->subtype = subtype;
15571 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
15572 cq->assoc_qid = eq->queue_id;
15574 cq->host_index = 0;
15575 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
15576 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
15578 if (cq->queue_id > phba->sli4_hba.cq_max)
15579 phba->sli4_hba.cq_max = cq->queue_id;
15581 irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler);
15583 mempool_free(mbox, phba->mbox_mem_pool);
15588 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
15589 * @phba: HBA structure that indicates port to create a queue on.
15590 * @cqp: The queue structure array to use to create the completion queues.
15591 * @hdwq: The hardware queue array with the EQ to bind completion queues to.
15592 * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
15593 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
15595 * This function creates a set of completion queue, s to support MRQ
15596 * as detailed in @cqp, on a port,
15597 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
15599 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15600 * is used to get the entry count and entry size that are necessary to
15601 * determine the number of pages to allocate and use for this queue. The @eq
15602 * is used to indicate which event queue to bind this completion queue to. This
15603 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
15604 * completion queue. This function is asynchronous and will wait for the mailbox
15605 * command to finish before continuing.
15607 * On success this function will return a zero. If unable to allocate enough
15608 * memory this function will return -ENOMEM. If the queue create mailbox command
15609 * fails this function will return -ENXIO.
15612 lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
15613 struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
15616 struct lpfc_queue *cq;
15617 struct lpfc_queue *eq;
15618 struct lpfc_mbx_cq_create_set *cq_set;
15619 struct lpfc_dmabuf *dmabuf;
15620 LPFC_MBOXQ_t *mbox;
15621 int rc, length, alloclen, status = 0;
15622 int cnt, idx, numcq, page_idx = 0;
15623 uint32_t shdr_status, shdr_add_status;
15624 union lpfc_sli4_cfg_shdr *shdr;
15625 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15627 /* sanity check on queue memory */
15628 numcq = phba->cfg_nvmet_mrq;
15629 if (!cqp || !hdwq || !numcq)
15632 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15636 length = sizeof(struct lpfc_mbx_cq_create_set);
15637 length += ((numcq * cqp[0]->page_count) *
15638 sizeof(struct dma_address));
15639 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
15640 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
15641 LPFC_SLI4_MBX_NEMBED);
15642 if (alloclen < length) {
15643 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15644 "3098 Allocated DMA memory size (%d) is "
15645 "less than the requested DMA memory size "
15646 "(%d)\n", alloclen, length);
15650 cq_set = mbox->sge_array->addr[0];
15651 shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
15652 bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
15654 for (idx = 0; idx < numcq; idx++) {
15656 eq = hdwq[idx].hba_eq;
15661 if (!phba->sli4_hba.pc_sli4_params.supported)
15662 hw_page_size = cq->page_size;
15666 bf_set(lpfc_mbx_cq_create_set_page_size,
15667 &cq_set->u.request,
15668 (hw_page_size / SLI4_PAGE_SIZE));
15669 bf_set(lpfc_mbx_cq_create_set_num_pages,
15670 &cq_set->u.request, cq->page_count);
15671 bf_set(lpfc_mbx_cq_create_set_evt,
15672 &cq_set->u.request, 1);
15673 bf_set(lpfc_mbx_cq_create_set_valid,
15674 &cq_set->u.request, 1);
15675 bf_set(lpfc_mbx_cq_create_set_cqe_size,
15676 &cq_set->u.request, 0);
15677 bf_set(lpfc_mbx_cq_create_set_num_cq,
15678 &cq_set->u.request, numcq);
15679 bf_set(lpfc_mbx_cq_create_set_autovalid,
15680 &cq_set->u.request,
15681 phba->sli4_hba.pc_sli4_params.cqav);
15682 switch (cq->entry_count) {
15685 if (phba->sli4_hba.pc_sli4_params.cqv ==
15686 LPFC_Q_CREATE_VERSION_2) {
15687 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15688 &cq_set->u.request,
15690 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15691 &cq_set->u.request,
15692 LPFC_CQ_CNT_WORD7);
15697 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15698 "3118 Bad CQ count. (%d)\n",
15700 if (cq->entry_count < 256) {
15704 fallthrough; /* otherwise default to smallest */
15706 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15707 &cq_set->u.request, LPFC_CQ_CNT_256);
15710 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15711 &cq_set->u.request, LPFC_CQ_CNT_512);
15714 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
15715 &cq_set->u.request, LPFC_CQ_CNT_1024);
15718 bf_set(lpfc_mbx_cq_create_set_eq_id0,
15719 &cq_set->u.request, eq->queue_id);
15722 bf_set(lpfc_mbx_cq_create_set_eq_id1,
15723 &cq_set->u.request, eq->queue_id);
15726 bf_set(lpfc_mbx_cq_create_set_eq_id2,
15727 &cq_set->u.request, eq->queue_id);
15730 bf_set(lpfc_mbx_cq_create_set_eq_id3,
15731 &cq_set->u.request, eq->queue_id);
15734 bf_set(lpfc_mbx_cq_create_set_eq_id4,
15735 &cq_set->u.request, eq->queue_id);
15738 bf_set(lpfc_mbx_cq_create_set_eq_id5,
15739 &cq_set->u.request, eq->queue_id);
15742 bf_set(lpfc_mbx_cq_create_set_eq_id6,
15743 &cq_set->u.request, eq->queue_id);
15746 bf_set(lpfc_mbx_cq_create_set_eq_id7,
15747 &cq_set->u.request, eq->queue_id);
15750 bf_set(lpfc_mbx_cq_create_set_eq_id8,
15751 &cq_set->u.request, eq->queue_id);
15754 bf_set(lpfc_mbx_cq_create_set_eq_id9,
15755 &cq_set->u.request, eq->queue_id);
15758 bf_set(lpfc_mbx_cq_create_set_eq_id10,
15759 &cq_set->u.request, eq->queue_id);
15762 bf_set(lpfc_mbx_cq_create_set_eq_id11,
15763 &cq_set->u.request, eq->queue_id);
15766 bf_set(lpfc_mbx_cq_create_set_eq_id12,
15767 &cq_set->u.request, eq->queue_id);
15770 bf_set(lpfc_mbx_cq_create_set_eq_id13,
15771 &cq_set->u.request, eq->queue_id);
15774 bf_set(lpfc_mbx_cq_create_set_eq_id14,
15775 &cq_set->u.request, eq->queue_id);
15778 bf_set(lpfc_mbx_cq_create_set_eq_id15,
15779 &cq_set->u.request, eq->queue_id);
15783 /* link the cq onto the parent eq child list */
15784 list_add_tail(&cq->list, &eq->child_list);
15785 /* Set up completion queue's type and subtype */
15787 cq->subtype = subtype;
15788 cq->assoc_qid = eq->queue_id;
15790 cq->host_index = 0;
15791 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
15792 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
15797 list_for_each_entry(dmabuf, &cq->page_list, list) {
15798 memset(dmabuf->virt, 0, hw_page_size);
15799 cnt = page_idx + dmabuf->buffer_tag;
15800 cq_set->u.request.page[cnt].addr_lo =
15801 putPaddrLow(dmabuf->phys);
15802 cq_set->u.request.page[cnt].addr_hi =
15803 putPaddrHigh(dmabuf->phys);
15809 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
15811 /* The IOCTL status is embedded in the mailbox subheader. */
15812 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
15813 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
15814 if (shdr_status || shdr_add_status || rc) {
15815 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15816 "3119 CQ_CREATE_SET mailbox failed with "
15817 "status x%x add_status x%x, mbx status x%x\n",
15818 shdr_status, shdr_add_status, rc);
15822 rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
15823 if (rc == 0xFFFF) {
15828 for (idx = 0; idx < numcq; idx++) {
15830 cq->queue_id = rc + idx;
15831 if (cq->queue_id > phba->sli4_hba.cq_max)
15832 phba->sli4_hba.cq_max = cq->queue_id;
15836 lpfc_sli4_mbox_cmd_free(phba, mbox);
15841 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
15842 * @phba: HBA structure that indicates port to create a queue on.
15843 * @mq: The queue structure to use to create the mailbox queue.
15844 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
15845 * @cq: The completion queue to associate with this cq.
15847 * This function provides failback (fb) functionality when the
15848 * mq_create_ext fails on older FW generations. It's purpose is identical
15849 * to mq_create_ext otherwise.
15851 * This routine cannot fail as all attributes were previously accessed and
15852 * initialized in mq_create_ext.
15855 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
15856 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
15858 struct lpfc_mbx_mq_create *mq_create;
15859 struct lpfc_dmabuf *dmabuf;
15862 length = (sizeof(struct lpfc_mbx_mq_create) -
15863 sizeof(struct lpfc_sli4_cfg_mhdr));
15864 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15865 LPFC_MBOX_OPCODE_MQ_CREATE,
15866 length, LPFC_SLI4_MBX_EMBED);
15867 mq_create = &mbox->u.mqe.un.mq_create;
15868 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
15870 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
15872 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
15873 switch (mq->entry_count) {
15875 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15876 LPFC_MQ_RING_SIZE_16);
15879 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15880 LPFC_MQ_RING_SIZE_32);
15883 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15884 LPFC_MQ_RING_SIZE_64);
15887 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
15888 LPFC_MQ_RING_SIZE_128);
15891 list_for_each_entry(dmabuf, &mq->page_list, list) {
15892 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
15893 putPaddrLow(dmabuf->phys);
15894 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
15895 putPaddrHigh(dmabuf->phys);
15900 * lpfc_mq_create - Create a mailbox Queue on the HBA
15901 * @phba: HBA structure that indicates port to create a queue on.
15902 * @mq: The queue structure to use to create the mailbox queue.
15903 * @cq: The completion queue to associate with this cq.
15904 * @subtype: The queue's subtype.
15906 * This function creates a mailbox queue, as detailed in @mq, on a port,
15907 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
15909 * The @phba struct is used to send mailbox command to HBA. The @cq struct
15910 * is used to get the entry count and entry size that are necessary to
15911 * determine the number of pages to allocate and use for this queue. This
15912 * function will send the MQ_CREATE mailbox command to the HBA to setup the
15913 * mailbox queue. This function is asynchronous and will wait for the mailbox
15914 * command to finish before continuing.
15916 * On success this function will return a zero. If unable to allocate enough
15917 * memory this function will return -ENOMEM. If the queue create mailbox command
15918 * fails this function will return -ENXIO.
15921 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
15922 struct lpfc_queue *cq, uint32_t subtype)
15924 struct lpfc_mbx_mq_create *mq_create;
15925 struct lpfc_mbx_mq_create_ext *mq_create_ext;
15926 struct lpfc_dmabuf *dmabuf;
15927 LPFC_MBOXQ_t *mbox;
15928 int rc, length, status = 0;
15929 uint32_t shdr_status, shdr_add_status;
15930 union lpfc_sli4_cfg_shdr *shdr;
15931 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15933 /* sanity check on queue memory */
15936 if (!phba->sli4_hba.pc_sli4_params.supported)
15937 hw_page_size = SLI4_PAGE_SIZE;
15939 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15942 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
15943 sizeof(struct lpfc_sli4_cfg_mhdr));
15944 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15945 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
15946 length, LPFC_SLI4_MBX_EMBED);
15948 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
15949 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
15950 bf_set(lpfc_mbx_mq_create_ext_num_pages,
15951 &mq_create_ext->u.request, mq->page_count);
15952 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
15953 &mq_create_ext->u.request, 1);
15954 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
15955 &mq_create_ext->u.request, 1);
15956 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
15957 &mq_create_ext->u.request, 1);
15958 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
15959 &mq_create_ext->u.request, 1);
15960 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
15961 &mq_create_ext->u.request, 1);
15962 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
15963 bf_set(lpfc_mbox_hdr_version, &shdr->request,
15964 phba->sli4_hba.pc_sli4_params.mqv);
15965 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
15966 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
15969 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
15971 switch (mq->entry_count) {
15973 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15974 "0362 Unsupported MQ count. (%d)\n",
15976 if (mq->entry_count < 16) {
15980 fallthrough; /* otherwise default to smallest count */
15982 bf_set(lpfc_mq_context_ring_size,
15983 &mq_create_ext->u.request.context,
15984 LPFC_MQ_RING_SIZE_16);
15987 bf_set(lpfc_mq_context_ring_size,
15988 &mq_create_ext->u.request.context,
15989 LPFC_MQ_RING_SIZE_32);
15992 bf_set(lpfc_mq_context_ring_size,
15993 &mq_create_ext->u.request.context,
15994 LPFC_MQ_RING_SIZE_64);
15997 bf_set(lpfc_mq_context_ring_size,
15998 &mq_create_ext->u.request.context,
15999 LPFC_MQ_RING_SIZE_128);
16002 list_for_each_entry(dmabuf, &mq->page_list, list) {
16003 memset(dmabuf->virt, 0, hw_page_size);
16004 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
16005 putPaddrLow(dmabuf->phys);
16006 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
16007 putPaddrHigh(dmabuf->phys);
16009 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16010 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
16011 &mq_create_ext->u.response);
16012 if (rc != MBX_SUCCESS) {
16013 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16014 "2795 MQ_CREATE_EXT failed with "
16015 "status x%x. Failback to MQ_CREATE.\n",
16017 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
16018 mq_create = &mbox->u.mqe.un.mq_create;
16019 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16020 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
16021 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
16022 &mq_create->u.response);
16025 /* The IOCTL status is embedded in the mailbox subheader. */
16026 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16027 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16028 if (shdr_status || shdr_add_status || rc) {
16029 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16030 "2502 MQ_CREATE mailbox failed with "
16031 "status x%x add_status x%x, mbx status x%x\n",
16032 shdr_status, shdr_add_status, rc);
16036 if (mq->queue_id == 0xFFFF) {
16040 mq->type = LPFC_MQ;
16041 mq->assoc_qid = cq->queue_id;
16042 mq->subtype = subtype;
16043 mq->host_index = 0;
16046 /* link the mq onto the parent cq child list */
16047 list_add_tail(&mq->list, &cq->child_list);
16049 mempool_free(mbox, phba->mbox_mem_pool);
16054 * lpfc_wq_create - Create a Work Queue on the HBA
16055 * @phba: HBA structure that indicates port to create a queue on.
16056 * @wq: The queue structure to use to create the work queue.
16057 * @cq: The completion queue to bind this work queue to.
16058 * @subtype: The subtype of the work queue indicating its functionality.
16060 * This function creates a work queue, as detailed in @wq, on a port, described
16061 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
16063 * The @phba struct is used to send mailbox command to HBA. The @wq struct
16064 * is used to get the entry count and entry size that are necessary to
16065 * determine the number of pages to allocate and use for this queue. The @cq
16066 * is used to indicate which completion queue to bind this work queue to. This
16067 * function will send the WQ_CREATE mailbox command to the HBA to setup the
16068 * work queue. This function is asynchronous and will wait for the mailbox
16069 * command to finish before continuing.
16071 * On success this function will return a zero. If unable to allocate enough
16072 * memory this function will return -ENOMEM. If the queue create mailbox command
16073 * fails this function will return -ENXIO.
16076 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
16077 struct lpfc_queue *cq, uint32_t subtype)
16079 struct lpfc_mbx_wq_create *wq_create;
16080 struct lpfc_dmabuf *dmabuf;
16081 LPFC_MBOXQ_t *mbox;
16082 int rc, length, status = 0;
16083 uint32_t shdr_status, shdr_add_status;
16084 union lpfc_sli4_cfg_shdr *shdr;
16085 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16086 struct dma_address *page;
16087 void __iomem *bar_memmap_p;
16088 uint32_t db_offset;
16089 uint16_t pci_barset;
16090 uint8_t dpp_barset;
16091 uint32_t dpp_offset;
16092 uint8_t wq_create_version;
16094 unsigned long pg_addr;
16097 /* sanity check on queue memory */
16100 if (!phba->sli4_hba.pc_sli4_params.supported)
16101 hw_page_size = wq->page_size;
16103 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16106 length = (sizeof(struct lpfc_mbx_wq_create) -
16107 sizeof(struct lpfc_sli4_cfg_mhdr));
16108 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16109 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
16110 length, LPFC_SLI4_MBX_EMBED);
16111 wq_create = &mbox->u.mqe.un.wq_create;
16112 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
16113 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
16115 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
16118 /* wqv is the earliest version supported, NOT the latest */
16119 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16120 phba->sli4_hba.pc_sli4_params.wqv);
16122 if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
16123 (wq->page_size > SLI4_PAGE_SIZE))
16124 wq_create_version = LPFC_Q_CREATE_VERSION_1;
16126 wq_create_version = LPFC_Q_CREATE_VERSION_0;
16128 switch (wq_create_version) {
16129 case LPFC_Q_CREATE_VERSION_1:
16130 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
16132 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16133 LPFC_Q_CREATE_VERSION_1);
16135 switch (wq->entry_size) {
16138 bf_set(lpfc_mbx_wq_create_wqe_size,
16139 &wq_create->u.request_1,
16140 LPFC_WQ_WQE_SIZE_64);
16143 bf_set(lpfc_mbx_wq_create_wqe_size,
16144 &wq_create->u.request_1,
16145 LPFC_WQ_WQE_SIZE_128);
16148 /* Request DPP by default */
16149 bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
16150 bf_set(lpfc_mbx_wq_create_page_size,
16151 &wq_create->u.request_1,
16152 (wq->page_size / SLI4_PAGE_SIZE));
16153 page = wq_create->u.request_1.page;
16156 page = wq_create->u.request.page;
16160 list_for_each_entry(dmabuf, &wq->page_list, list) {
16161 memset(dmabuf->virt, 0, hw_page_size);
16162 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
16163 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
16166 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16167 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
16169 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16170 /* The IOCTL status is embedded in the mailbox subheader. */
16171 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16172 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16173 if (shdr_status || shdr_add_status || rc) {
16174 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16175 "2503 WQ_CREATE mailbox failed with "
16176 "status x%x add_status x%x, mbx status x%x\n",
16177 shdr_status, shdr_add_status, rc);
16182 if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
16183 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
16184 &wq_create->u.response);
16186 wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
16187 &wq_create->u.response_1);
16189 if (wq->queue_id == 0xFFFF) {
16194 wq->db_format = LPFC_DB_LIST_FORMAT;
16195 if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
16196 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
16197 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
16198 &wq_create->u.response);
16199 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
16200 (wq->db_format != LPFC_DB_RING_FORMAT)) {
16201 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16202 "3265 WQ[%d] doorbell format "
16203 "not supported: x%x\n",
16204 wq->queue_id, wq->db_format);
16208 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
16209 &wq_create->u.response);
16210 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16212 if (!bar_memmap_p) {
16213 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16214 "3263 WQ[%d] failed to memmap "
16215 "pci barset:x%x\n",
16216 wq->queue_id, pci_barset);
16220 db_offset = wq_create->u.response.doorbell_offset;
16221 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
16222 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
16223 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16224 "3252 WQ[%d] doorbell offset "
16225 "not supported: x%x\n",
16226 wq->queue_id, db_offset);
16230 wq->db_regaddr = bar_memmap_p + db_offset;
16231 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16232 "3264 WQ[%d]: barset:x%x, offset:x%x, "
16233 "format:x%x\n", wq->queue_id,
16234 pci_barset, db_offset, wq->db_format);
16236 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
16238 /* Check if DPP was honored by the firmware */
16239 wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
16240 &wq_create->u.response_1);
16241 if (wq->dpp_enable) {
16242 pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
16243 &wq_create->u.response_1);
16244 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16246 if (!bar_memmap_p) {
16247 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16248 "3267 WQ[%d] failed to memmap "
16249 "pci barset:x%x\n",
16250 wq->queue_id, pci_barset);
16254 db_offset = wq_create->u.response_1.doorbell_offset;
16255 wq->db_regaddr = bar_memmap_p + db_offset;
16256 wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
16257 &wq_create->u.response_1);
16258 dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
16259 &wq_create->u.response_1);
16260 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16262 if (!bar_memmap_p) {
16263 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16264 "3268 WQ[%d] failed to memmap "
16265 "pci barset:x%x\n",
16266 wq->queue_id, dpp_barset);
16270 dpp_offset = wq_create->u.response_1.dpp_offset;
16271 wq->dpp_regaddr = bar_memmap_p + dpp_offset;
16272 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16273 "3271 WQ[%d]: barset:x%x, offset:x%x, "
16274 "dpp_id:x%x dpp_barset:x%x "
16275 "dpp_offset:x%x\n",
16276 wq->queue_id, pci_barset, db_offset,
16277 wq->dpp_id, dpp_barset, dpp_offset);
16280 /* Enable combined writes for DPP aperture */
16281 pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
16282 rc = set_memory_wc(pg_addr, 1);
16284 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
16285 "3272 Cannot setup Combined "
16286 "Write on WQ[%d] - disable DPP\n",
16288 phba->cfg_enable_dpp = 0;
16291 phba->cfg_enable_dpp = 0;
16294 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
16296 wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
16297 if (wq->pring == NULL) {
16301 wq->type = LPFC_WQ;
16302 wq->assoc_qid = cq->queue_id;
16303 wq->subtype = subtype;
16304 wq->host_index = 0;
16306 wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
16308 /* link the wq onto the parent cq child list */
16309 list_add_tail(&wq->list, &cq->child_list);
16311 mempool_free(mbox, phba->mbox_mem_pool);
16316 * lpfc_rq_create - Create a Receive Queue on the HBA
16317 * @phba: HBA structure that indicates port to create a queue on.
16318 * @hrq: The queue structure to use to create the header receive queue.
16319 * @drq: The queue structure to use to create the data receive queue.
16320 * @cq: The completion queue to bind this work queue to.
16321 * @subtype: The subtype of the work queue indicating its functionality.
16323 * This function creates a receive buffer queue pair , as detailed in @hrq and
16324 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
16327 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
16328 * struct is used to get the entry count that is necessary to determine the
16329 * number of pages to use for this queue. The @cq is used to indicate which
16330 * completion queue to bind received buffers that are posted to these queues to.
16331 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
16332 * receive queue pair. This function is asynchronous and will wait for the
16333 * mailbox command to finish before continuing.
16335 * On success this function will return a zero. If unable to allocate enough
16336 * memory this function will return -ENOMEM. If the queue create mailbox command
16337 * fails this function will return -ENXIO.
16340 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
16341 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
16343 struct lpfc_mbx_rq_create *rq_create;
16344 struct lpfc_dmabuf *dmabuf;
16345 LPFC_MBOXQ_t *mbox;
16346 int rc, length, status = 0;
16347 uint32_t shdr_status, shdr_add_status;
16348 union lpfc_sli4_cfg_shdr *shdr;
16349 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16350 void __iomem *bar_memmap_p;
16351 uint32_t db_offset;
16352 uint16_t pci_barset;
16354 /* sanity check on queue memory */
16355 if (!hrq || !drq || !cq)
16357 if (!phba->sli4_hba.pc_sli4_params.supported)
16358 hw_page_size = SLI4_PAGE_SIZE;
16360 if (hrq->entry_count != drq->entry_count)
16362 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16365 length = (sizeof(struct lpfc_mbx_rq_create) -
16366 sizeof(struct lpfc_sli4_cfg_mhdr));
16367 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16368 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
16369 length, LPFC_SLI4_MBX_EMBED);
16370 rq_create = &mbox->u.mqe.un.rq_create;
16371 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
16372 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16373 phba->sli4_hba.pc_sli4_params.rqv);
16374 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
16375 bf_set(lpfc_rq_context_rqe_count_1,
16376 &rq_create->u.request.context,
16378 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
16379 bf_set(lpfc_rq_context_rqe_size,
16380 &rq_create->u.request.context,
16382 bf_set(lpfc_rq_context_page_size,
16383 &rq_create->u.request.context,
16384 LPFC_RQ_PAGE_SIZE_4096);
16386 switch (hrq->entry_count) {
16388 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16389 "2535 Unsupported RQ count. (%d)\n",
16391 if (hrq->entry_count < 512) {
16395 fallthrough; /* otherwise default to smallest count */
16397 bf_set(lpfc_rq_context_rqe_count,
16398 &rq_create->u.request.context,
16399 LPFC_RQ_RING_SIZE_512);
16402 bf_set(lpfc_rq_context_rqe_count,
16403 &rq_create->u.request.context,
16404 LPFC_RQ_RING_SIZE_1024);
16407 bf_set(lpfc_rq_context_rqe_count,
16408 &rq_create->u.request.context,
16409 LPFC_RQ_RING_SIZE_2048);
16412 bf_set(lpfc_rq_context_rqe_count,
16413 &rq_create->u.request.context,
16414 LPFC_RQ_RING_SIZE_4096);
16417 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
16418 LPFC_HDR_BUF_SIZE);
16420 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
16422 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
16424 list_for_each_entry(dmabuf, &hrq->page_list, list) {
16425 memset(dmabuf->virt, 0, hw_page_size);
16426 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16427 putPaddrLow(dmabuf->phys);
16428 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16429 putPaddrHigh(dmabuf->phys);
16431 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16432 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
16434 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16435 /* The IOCTL status is embedded in the mailbox subheader. */
16436 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16437 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16438 if (shdr_status || shdr_add_status || rc) {
16439 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16440 "2504 RQ_CREATE mailbox failed with "
16441 "status x%x add_status x%x, mbx status x%x\n",
16442 shdr_status, shdr_add_status, rc);
16446 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16447 if (hrq->queue_id == 0xFFFF) {
16452 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
16453 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
16454 &rq_create->u.response);
16455 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
16456 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
16457 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16458 "3262 RQ [%d] doorbell format not "
16459 "supported: x%x\n", hrq->queue_id,
16465 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
16466 &rq_create->u.response);
16467 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
16468 if (!bar_memmap_p) {
16469 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16470 "3269 RQ[%d] failed to memmap pci "
16471 "barset:x%x\n", hrq->queue_id,
16477 db_offset = rq_create->u.response.doorbell_offset;
16478 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
16479 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
16480 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16481 "3270 RQ[%d] doorbell offset not "
16482 "supported: x%x\n", hrq->queue_id,
16487 hrq->db_regaddr = bar_memmap_p + db_offset;
16488 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16489 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
16490 "format:x%x\n", hrq->queue_id, pci_barset,
16491 db_offset, hrq->db_format);
16493 hrq->db_format = LPFC_DB_RING_FORMAT;
16494 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16496 hrq->type = LPFC_HRQ;
16497 hrq->assoc_qid = cq->queue_id;
16498 hrq->subtype = subtype;
16499 hrq->host_index = 0;
16500 hrq->hba_index = 0;
16501 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16503 /* now create the data queue */
16504 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16505 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
16506 length, LPFC_SLI4_MBX_EMBED);
16507 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16508 phba->sli4_hba.pc_sli4_params.rqv);
16509 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
16510 bf_set(lpfc_rq_context_rqe_count_1,
16511 &rq_create->u.request.context, hrq->entry_count);
16512 if (subtype == LPFC_NVMET)
16513 rq_create->u.request.context.buffer_size =
16514 LPFC_NVMET_DATA_BUF_SIZE;
16516 rq_create->u.request.context.buffer_size =
16517 LPFC_DATA_BUF_SIZE;
16518 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
16520 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
16521 (PAGE_SIZE/SLI4_PAGE_SIZE));
16523 switch (drq->entry_count) {
16525 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16526 "2536 Unsupported RQ count. (%d)\n",
16528 if (drq->entry_count < 512) {
16532 fallthrough; /* otherwise default to smallest count */
16534 bf_set(lpfc_rq_context_rqe_count,
16535 &rq_create->u.request.context,
16536 LPFC_RQ_RING_SIZE_512);
16539 bf_set(lpfc_rq_context_rqe_count,
16540 &rq_create->u.request.context,
16541 LPFC_RQ_RING_SIZE_1024);
16544 bf_set(lpfc_rq_context_rqe_count,
16545 &rq_create->u.request.context,
16546 LPFC_RQ_RING_SIZE_2048);
16549 bf_set(lpfc_rq_context_rqe_count,
16550 &rq_create->u.request.context,
16551 LPFC_RQ_RING_SIZE_4096);
16554 if (subtype == LPFC_NVMET)
16555 bf_set(lpfc_rq_context_buf_size,
16556 &rq_create->u.request.context,
16557 LPFC_NVMET_DATA_BUF_SIZE);
16559 bf_set(lpfc_rq_context_buf_size,
16560 &rq_create->u.request.context,
16561 LPFC_DATA_BUF_SIZE);
16563 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
16565 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
16567 list_for_each_entry(dmabuf, &drq->page_list, list) {
16568 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16569 putPaddrLow(dmabuf->phys);
16570 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16571 putPaddrHigh(dmabuf->phys);
16573 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16574 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
16575 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16576 /* The IOCTL status is embedded in the mailbox subheader. */
16577 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
16578 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16579 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16580 if (shdr_status || shdr_add_status || rc) {
16584 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16585 if (drq->queue_id == 0xFFFF) {
16589 drq->type = LPFC_DRQ;
16590 drq->assoc_qid = cq->queue_id;
16591 drq->subtype = subtype;
16592 drq->host_index = 0;
16593 drq->hba_index = 0;
16594 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16596 /* link the header and data RQs onto the parent cq child list */
16597 list_add_tail(&hrq->list, &cq->child_list);
16598 list_add_tail(&drq->list, &cq->child_list);
16601 mempool_free(mbox, phba->mbox_mem_pool);
16606 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
16607 * @phba: HBA structure that indicates port to create a queue on.
16608 * @hrqp: The queue structure array to use to create the header receive queues.
16609 * @drqp: The queue structure array to use to create the data receive queues.
16610 * @cqp: The completion queue array to bind these receive queues to.
16611 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
16613 * This function creates a receive buffer queue pair , as detailed in @hrq and
16614 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
16617 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
16618 * struct is used to get the entry count that is necessary to determine the
16619 * number of pages to use for this queue. The @cq is used to indicate which
16620 * completion queue to bind received buffers that are posted to these queues to.
16621 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
16622 * receive queue pair. This function is asynchronous and will wait for the
16623 * mailbox command to finish before continuing.
16625 * On success this function will return a zero. If unable to allocate enough
16626 * memory this function will return -ENOMEM. If the queue create mailbox command
16627 * fails this function will return -ENXIO.
16630 lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
16631 struct lpfc_queue **drqp, struct lpfc_queue **cqp,
16634 struct lpfc_queue *hrq, *drq, *cq;
16635 struct lpfc_mbx_rq_create_v2 *rq_create;
16636 struct lpfc_dmabuf *dmabuf;
16637 LPFC_MBOXQ_t *mbox;
16638 int rc, length, alloclen, status = 0;
16639 int cnt, idx, numrq, page_idx = 0;
16640 uint32_t shdr_status, shdr_add_status;
16641 union lpfc_sli4_cfg_shdr *shdr;
16642 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16644 numrq = phba->cfg_nvmet_mrq;
16645 /* sanity check on array memory */
16646 if (!hrqp || !drqp || !cqp || !numrq)
16648 if (!phba->sli4_hba.pc_sli4_params.supported)
16649 hw_page_size = SLI4_PAGE_SIZE;
16651 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16655 length = sizeof(struct lpfc_mbx_rq_create_v2);
16656 length += ((2 * numrq * hrqp[0]->page_count) *
16657 sizeof(struct dma_address));
16659 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16660 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
16661 LPFC_SLI4_MBX_NEMBED);
16662 if (alloclen < length) {
16663 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16664 "3099 Allocated DMA memory size (%d) is "
16665 "less than the requested DMA memory size "
16666 "(%d)\n", alloclen, length);
16673 rq_create = mbox->sge_array->addr[0];
16674 shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
16676 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
16679 for (idx = 0; idx < numrq; idx++) {
16684 /* sanity check on queue memory */
16685 if (!hrq || !drq || !cq) {
16690 if (hrq->entry_count != drq->entry_count) {
16696 bf_set(lpfc_mbx_rq_create_num_pages,
16697 &rq_create->u.request,
16699 bf_set(lpfc_mbx_rq_create_rq_cnt,
16700 &rq_create->u.request, (numrq * 2));
16701 bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
16703 bf_set(lpfc_rq_context_base_cq,
16704 &rq_create->u.request.context,
16706 bf_set(lpfc_rq_context_data_size,
16707 &rq_create->u.request.context,
16708 LPFC_NVMET_DATA_BUF_SIZE);
16709 bf_set(lpfc_rq_context_hdr_size,
16710 &rq_create->u.request.context,
16711 LPFC_HDR_BUF_SIZE);
16712 bf_set(lpfc_rq_context_rqe_count_1,
16713 &rq_create->u.request.context,
16715 bf_set(lpfc_rq_context_rqe_size,
16716 &rq_create->u.request.context,
16718 bf_set(lpfc_rq_context_page_size,
16719 &rq_create->u.request.context,
16720 (PAGE_SIZE/SLI4_PAGE_SIZE));
16723 list_for_each_entry(dmabuf, &hrq->page_list, list) {
16724 memset(dmabuf->virt, 0, hw_page_size);
16725 cnt = page_idx + dmabuf->buffer_tag;
16726 rq_create->u.request.page[cnt].addr_lo =
16727 putPaddrLow(dmabuf->phys);
16728 rq_create->u.request.page[cnt].addr_hi =
16729 putPaddrHigh(dmabuf->phys);
16735 list_for_each_entry(dmabuf, &drq->page_list, list) {
16736 memset(dmabuf->virt, 0, hw_page_size);
16737 cnt = page_idx + dmabuf->buffer_tag;
16738 rq_create->u.request.page[cnt].addr_lo =
16739 putPaddrLow(dmabuf->phys);
16740 rq_create->u.request.page[cnt].addr_hi =
16741 putPaddrHigh(dmabuf->phys);
16746 hrq->db_format = LPFC_DB_RING_FORMAT;
16747 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16748 hrq->type = LPFC_HRQ;
16749 hrq->assoc_qid = cq->queue_id;
16750 hrq->subtype = subtype;
16751 hrq->host_index = 0;
16752 hrq->hba_index = 0;
16753 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16755 drq->db_format = LPFC_DB_RING_FORMAT;
16756 drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
16757 drq->type = LPFC_DRQ;
16758 drq->assoc_qid = cq->queue_id;
16759 drq->subtype = subtype;
16760 drq->host_index = 0;
16761 drq->hba_index = 0;
16762 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
16764 list_add_tail(&hrq->list, &cq->child_list);
16765 list_add_tail(&drq->list, &cq->child_list);
16768 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16769 /* The IOCTL status is embedded in the mailbox subheader. */
16770 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16771 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16772 if (shdr_status || shdr_add_status || rc) {
16773 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16774 "3120 RQ_CREATE mailbox failed with "
16775 "status x%x add_status x%x, mbx status x%x\n",
16776 shdr_status, shdr_add_status, rc);
16780 rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
16781 if (rc == 0xFFFF) {
16786 /* Initialize all RQs with associated queue id */
16787 for (idx = 0; idx < numrq; idx++) {
16789 hrq->queue_id = rc + (2 * idx);
16791 drq->queue_id = rc + (2 * idx) + 1;
16795 lpfc_sli4_mbox_cmd_free(phba, mbox);
16800 * lpfc_eq_destroy - Destroy an event Queue on the HBA
16801 * @phba: HBA structure that indicates port to destroy a queue on.
16802 * @eq: The queue structure associated with the queue to destroy.
16804 * This function destroys a queue, as detailed in @eq by sending an mailbox
16805 * command, specific to the type of queue, to the HBA.
16807 * The @eq struct is used to get the queue ID of the queue to destroy.
16809 * On success this function will return a zero. If the queue destroy mailbox
16810 * command fails this function will return -ENXIO.
16813 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
16815 LPFC_MBOXQ_t *mbox;
16816 int rc, length, status = 0;
16817 uint32_t shdr_status, shdr_add_status;
16818 union lpfc_sli4_cfg_shdr *shdr;
16820 /* sanity check on queue memory */
16824 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
16827 length = (sizeof(struct lpfc_mbx_eq_destroy) -
16828 sizeof(struct lpfc_sli4_cfg_mhdr));
16829 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16830 LPFC_MBOX_OPCODE_EQ_DESTROY,
16831 length, LPFC_SLI4_MBX_EMBED);
16832 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
16834 mbox->vport = eq->phba->pport;
16835 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16837 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
16838 /* The IOCTL status is embedded in the mailbox subheader. */
16839 shdr = (union lpfc_sli4_cfg_shdr *)
16840 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
16841 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16842 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16843 if (shdr_status || shdr_add_status || rc) {
16844 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16845 "2505 EQ_DESTROY mailbox failed with "
16846 "status x%x add_status x%x, mbx status x%x\n",
16847 shdr_status, shdr_add_status, rc);
16851 /* Remove eq from any list */
16852 list_del_init(&eq->list);
16853 mempool_free(mbox, eq->phba->mbox_mem_pool);
16858 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
16859 * @phba: HBA structure that indicates port to destroy a queue on.
16860 * @cq: The queue structure associated with the queue to destroy.
16862 * This function destroys a queue, as detailed in @cq by sending an mailbox
16863 * command, specific to the type of queue, to the HBA.
16865 * The @cq struct is used to get the queue ID of the queue to destroy.
16867 * On success this function will return a zero. If the queue destroy mailbox
16868 * command fails this function will return -ENXIO.
16871 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
16873 LPFC_MBOXQ_t *mbox;
16874 int rc, length, status = 0;
16875 uint32_t shdr_status, shdr_add_status;
16876 union lpfc_sli4_cfg_shdr *shdr;
16878 /* sanity check on queue memory */
16881 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
16884 length = (sizeof(struct lpfc_mbx_cq_destroy) -
16885 sizeof(struct lpfc_sli4_cfg_mhdr));
16886 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16887 LPFC_MBOX_OPCODE_CQ_DESTROY,
16888 length, LPFC_SLI4_MBX_EMBED);
16889 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
16891 mbox->vport = cq->phba->pport;
16892 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16893 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
16894 /* The IOCTL status is embedded in the mailbox subheader. */
16895 shdr = (union lpfc_sli4_cfg_shdr *)
16896 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
16897 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16898 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16899 if (shdr_status || shdr_add_status || rc) {
16900 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16901 "2506 CQ_DESTROY mailbox failed with "
16902 "status x%x add_status x%x, mbx status x%x\n",
16903 shdr_status, shdr_add_status, rc);
16906 /* Remove cq from any list */
16907 list_del_init(&cq->list);
16908 mempool_free(mbox, cq->phba->mbox_mem_pool);
16913 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
16914 * @phba: HBA structure that indicates port to destroy a queue on.
16915 * @mq: The queue structure associated with the queue to destroy.
16917 * This function destroys a queue, as detailed in @mq by sending an mailbox
16918 * command, specific to the type of queue, to the HBA.
16920 * The @mq struct is used to get the queue ID of the queue to destroy.
16922 * On success this function will return a zero. If the queue destroy mailbox
16923 * command fails this function will return -ENXIO.
16926 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
16928 LPFC_MBOXQ_t *mbox;
16929 int rc, length, status = 0;
16930 uint32_t shdr_status, shdr_add_status;
16931 union lpfc_sli4_cfg_shdr *shdr;
16933 /* sanity check on queue memory */
16936 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
16939 length = (sizeof(struct lpfc_mbx_mq_destroy) -
16940 sizeof(struct lpfc_sli4_cfg_mhdr));
16941 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16942 LPFC_MBOX_OPCODE_MQ_DESTROY,
16943 length, LPFC_SLI4_MBX_EMBED);
16944 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
16946 mbox->vport = mq->phba->pport;
16947 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16948 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
16949 /* The IOCTL status is embedded in the mailbox subheader. */
16950 shdr = (union lpfc_sli4_cfg_shdr *)
16951 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
16952 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16953 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16954 if (shdr_status || shdr_add_status || rc) {
16955 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16956 "2507 MQ_DESTROY mailbox failed with "
16957 "status x%x add_status x%x, mbx status x%x\n",
16958 shdr_status, shdr_add_status, rc);
16961 /* Remove mq from any list */
16962 list_del_init(&mq->list);
16963 mempool_free(mbox, mq->phba->mbox_mem_pool);
16968 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
16969 * @phba: HBA structure that indicates port to destroy a queue on.
16970 * @wq: The queue structure associated with the queue to destroy.
16972 * This function destroys a queue, as detailed in @wq by sending an mailbox
16973 * command, specific to the type of queue, to the HBA.
16975 * The @wq struct is used to get the queue ID of the queue to destroy.
16977 * On success this function will return a zero. If the queue destroy mailbox
16978 * command fails this function will return -ENXIO.
16981 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
16983 LPFC_MBOXQ_t *mbox;
16984 int rc, length, status = 0;
16985 uint32_t shdr_status, shdr_add_status;
16986 union lpfc_sli4_cfg_shdr *shdr;
16988 /* sanity check on queue memory */
16991 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
16994 length = (sizeof(struct lpfc_mbx_wq_destroy) -
16995 sizeof(struct lpfc_sli4_cfg_mhdr));
16996 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16997 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
16998 length, LPFC_SLI4_MBX_EMBED);
16999 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
17001 mbox->vport = wq->phba->pport;
17002 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17003 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
17004 shdr = (union lpfc_sli4_cfg_shdr *)
17005 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
17006 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17007 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17008 if (shdr_status || shdr_add_status || rc) {
17009 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17010 "2508 WQ_DESTROY mailbox failed with "
17011 "status x%x add_status x%x, mbx status x%x\n",
17012 shdr_status, shdr_add_status, rc);
17015 /* Remove wq from any list */
17016 list_del_init(&wq->list);
17019 mempool_free(mbox, wq->phba->mbox_mem_pool);
17024 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
17025 * @phba: HBA structure that indicates port to destroy a queue on.
17026 * @hrq: The queue structure associated with the queue to destroy.
17027 * @drq: The queue structure associated with the queue to destroy.
17029 * This function destroys a queue, as detailed in @rq by sending an mailbox
17030 * command, specific to the type of queue, to the HBA.
17032 * The @rq struct is used to get the queue ID of the queue to destroy.
17034 * On success this function will return a zero. If the queue destroy mailbox
17035 * command fails this function will return -ENXIO.
17038 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
17039 struct lpfc_queue *drq)
17041 LPFC_MBOXQ_t *mbox;
17042 int rc, length, status = 0;
17043 uint32_t shdr_status, shdr_add_status;
17044 union lpfc_sli4_cfg_shdr *shdr;
17046 /* sanity check on queue memory */
17049 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
17052 length = (sizeof(struct lpfc_mbx_rq_destroy) -
17053 sizeof(struct lpfc_sli4_cfg_mhdr));
17054 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17055 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
17056 length, LPFC_SLI4_MBX_EMBED);
17057 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
17059 mbox->vport = hrq->phba->pport;
17060 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17061 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
17062 /* The IOCTL status is embedded in the mailbox subheader. */
17063 shdr = (union lpfc_sli4_cfg_shdr *)
17064 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
17065 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17066 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17067 if (shdr_status || shdr_add_status || rc) {
17068 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17069 "2509 RQ_DESTROY mailbox failed with "
17070 "status x%x add_status x%x, mbx status x%x\n",
17071 shdr_status, shdr_add_status, rc);
17072 if (rc != MBX_TIMEOUT)
17073 mempool_free(mbox, hrq->phba->mbox_mem_pool);
17076 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
17078 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
17079 shdr = (union lpfc_sli4_cfg_shdr *)
17080 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
17081 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17082 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17083 if (shdr_status || shdr_add_status || rc) {
17084 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17085 "2510 RQ_DESTROY mailbox failed with "
17086 "status x%x add_status x%x, mbx status x%x\n",
17087 shdr_status, shdr_add_status, rc);
17090 list_del_init(&hrq->list);
17091 list_del_init(&drq->list);
17092 mempool_free(mbox, hrq->phba->mbox_mem_pool);
17097 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
17098 * @phba: The virtual port for which this call being executed.
17099 * @pdma_phys_addr0: Physical address of the 1st SGL page.
17100 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
17101 * @xritag: the xritag that ties this io to the SGL pages.
17103 * This routine will post the sgl pages for the IO that has the xritag
17104 * that is in the iocbq structure. The xritag is assigned during iocbq
17105 * creation and persists for as long as the driver is loaded.
17106 * if the caller has fewer than 256 scatter gather segments to map then
17107 * pdma_phys_addr1 should be 0.
17108 * If the caller needs to map more than 256 scatter gather segment then
17109 * pdma_phys_addr1 should be a valid physical address.
17110 * physical address for SGLs must be 64 byte aligned.
17111 * If you are going to map 2 SGL's then the first one must have 256 entries
17112 * the second sgl can have between 1 and 256 entries.
17116 * -ENXIO, -ENOMEM - Failure
17119 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
17120 dma_addr_t pdma_phys_addr0,
17121 dma_addr_t pdma_phys_addr1,
17124 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
17125 LPFC_MBOXQ_t *mbox;
17127 uint32_t shdr_status, shdr_add_status;
17129 union lpfc_sli4_cfg_shdr *shdr;
17131 if (xritag == NO_XRI) {
17132 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17133 "0364 Invalid param:\n");
17137 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17141 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17142 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
17143 sizeof(struct lpfc_mbx_post_sgl_pages) -
17144 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
17146 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
17147 &mbox->u.mqe.un.post_sgl_pages;
17148 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
17149 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
17151 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
17152 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
17153 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
17154 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
17156 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
17157 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
17158 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
17159 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
17160 if (!phba->sli4_hba.intr_enable)
17161 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17163 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17164 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17166 /* The IOCTL status is embedded in the mailbox subheader. */
17167 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
17168 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17169 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17170 if (rc != MBX_TIMEOUT)
17171 mempool_free(mbox, phba->mbox_mem_pool);
17172 if (shdr_status || shdr_add_status || rc) {
17173 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17174 "2511 POST_SGL mailbox failed with "
17175 "status x%x add_status x%x, mbx status x%x\n",
17176 shdr_status, shdr_add_status, rc);
17182 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
17183 * @phba: pointer to lpfc hba data structure.
17185 * This routine is invoked to post rpi header templates to the
17186 * HBA consistent with the SLI-4 interface spec. This routine
17187 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17188 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17191 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
17192 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
17195 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
17200 * Fetch the next logical xri. Because this index is logical,
17201 * the driver starts at 0 each time.
17203 spin_lock_irq(&phba->hbalock);
17204 xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
17205 phba->sli4_hba.max_cfg_param.max_xri, 0);
17206 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
17207 spin_unlock_irq(&phba->hbalock);
17210 set_bit(xri, phba->sli4_hba.xri_bmask);
17211 phba->sli4_hba.max_cfg_param.xri_used++;
17213 spin_unlock_irq(&phba->hbalock);
17218 * lpfc_sli4_free_xri - Release an xri for reuse.
17219 * @phba: pointer to lpfc hba data structure.
17220 * @xri: xri to release.
17222 * This routine is invoked to release an xri to the pool of
17223 * available rpis maintained by the driver.
17226 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
17228 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
17229 phba->sli4_hba.max_cfg_param.xri_used--;
17234 * lpfc_sli4_free_xri - Release an xri for reuse.
17235 * @phba: pointer to lpfc hba data structure.
17236 * @xri: xri to release.
17238 * This routine is invoked to release an xri to the pool of
17239 * available rpis maintained by the driver.
17242 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
17244 spin_lock_irq(&phba->hbalock);
17245 __lpfc_sli4_free_xri(phba, xri);
17246 spin_unlock_irq(&phba->hbalock);
17250 * lpfc_sli4_next_xritag - Get an xritag for the io
17251 * @phba: Pointer to HBA context object.
17253 * This function gets an xritag for the iocb. If there is no unused xritag
17254 * it will return 0xffff.
17255 * The function returns the allocated xritag if successful, else returns zero.
17256 * Zero is not a valid xritag.
17257 * The caller is not required to hold any lock.
17260 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
17262 uint16_t xri_index;
17264 xri_index = lpfc_sli4_alloc_xri(phba);
17265 if (xri_index == NO_XRI)
17266 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
17267 "2004 Failed to allocate XRI.last XRITAG is %d"
17268 " Max XRI is %d, Used XRI is %d\n",
17270 phba->sli4_hba.max_cfg_param.max_xri,
17271 phba->sli4_hba.max_cfg_param.xri_used);
17276 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
17277 * @phba: pointer to lpfc hba data structure.
17278 * @post_sgl_list: pointer to els sgl entry list.
17279 * @post_cnt: number of els sgl entries on the list.
17281 * This routine is invoked to post a block of driver's sgl pages to the
17282 * HBA using non-embedded mailbox command. No Lock is held. This routine
17283 * is only called when the driver is loading and after all IO has been
17287 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
17288 struct list_head *post_sgl_list,
17291 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
17292 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
17293 struct sgl_page_pairs *sgl_pg_pairs;
17295 LPFC_MBOXQ_t *mbox;
17296 uint32_t reqlen, alloclen, pg_pairs;
17298 uint16_t xritag_start = 0;
17300 uint32_t shdr_status, shdr_add_status;
17301 union lpfc_sli4_cfg_shdr *shdr;
17303 reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
17304 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
17305 if (reqlen > SLI4_PAGE_SIZE) {
17306 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17307 "2559 Block sgl registration required DMA "
17308 "size (%d) great than a page\n", reqlen);
17312 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17316 /* Allocate DMA memory and set up the non-embedded mailbox command */
17317 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17318 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
17319 LPFC_SLI4_MBX_NEMBED);
17321 if (alloclen < reqlen) {
17322 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17323 "0285 Allocated DMA memory size (%d) is "
17324 "less than the requested DMA memory "
17325 "size (%d)\n", alloclen, reqlen);
17326 lpfc_sli4_mbox_cmd_free(phba, mbox);
17329 /* Set up the SGL pages in the non-embedded DMA pages */
17330 viraddr = mbox->sge_array->addr[0];
17331 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
17332 sgl_pg_pairs = &sgl->sgl_pg_pairs;
17335 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
17336 /* Set up the sge entry */
17337 sgl_pg_pairs->sgl_pg0_addr_lo =
17338 cpu_to_le32(putPaddrLow(sglq_entry->phys));
17339 sgl_pg_pairs->sgl_pg0_addr_hi =
17340 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
17341 sgl_pg_pairs->sgl_pg1_addr_lo =
17342 cpu_to_le32(putPaddrLow(0));
17343 sgl_pg_pairs->sgl_pg1_addr_hi =
17344 cpu_to_le32(putPaddrHigh(0));
17346 /* Keep the first xritag on the list */
17348 xritag_start = sglq_entry->sli4_xritag;
17353 /* Complete initialization and perform endian conversion. */
17354 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
17355 bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
17356 sgl->word0 = cpu_to_le32(sgl->word0);
17358 if (!phba->sli4_hba.intr_enable)
17359 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17361 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17362 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17364 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
17365 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17366 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17367 if (rc != MBX_TIMEOUT)
17368 lpfc_sli4_mbox_cmd_free(phba, mbox);
17369 if (shdr_status || shdr_add_status || rc) {
17370 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17371 "2513 POST_SGL_BLOCK mailbox command failed "
17372 "status x%x add_status x%x mbx status x%x\n",
17373 shdr_status, shdr_add_status, rc);
17380 * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
17381 * @phba: pointer to lpfc hba data structure.
17382 * @nblist: pointer to nvme buffer list.
17383 * @count: number of scsi buffers on the list.
17385 * This routine is invoked to post a block of @count scsi sgl pages from a
17386 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
17391 lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
17394 struct lpfc_io_buf *lpfc_ncmd;
17395 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
17396 struct sgl_page_pairs *sgl_pg_pairs;
17398 LPFC_MBOXQ_t *mbox;
17399 uint32_t reqlen, alloclen, pg_pairs;
17401 uint16_t xritag_start = 0;
17403 uint32_t shdr_status, shdr_add_status;
17404 dma_addr_t pdma_phys_bpl1;
17405 union lpfc_sli4_cfg_shdr *shdr;
17407 /* Calculate the requested length of the dma memory */
17408 reqlen = count * sizeof(struct sgl_page_pairs) +
17409 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
17410 if (reqlen > SLI4_PAGE_SIZE) {
17411 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
17412 "6118 Block sgl registration required DMA "
17413 "size (%d) great than a page\n", reqlen);
17416 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17418 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17419 "6119 Failed to allocate mbox cmd memory\n");
17423 /* Allocate DMA memory and set up the non-embedded mailbox command */
17424 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17425 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
17426 reqlen, LPFC_SLI4_MBX_NEMBED);
17428 if (alloclen < reqlen) {
17429 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17430 "6120 Allocated DMA memory size (%d) is "
17431 "less than the requested DMA memory "
17432 "size (%d)\n", alloclen, reqlen);
17433 lpfc_sli4_mbox_cmd_free(phba, mbox);
17437 /* Get the first SGE entry from the non-embedded DMA memory */
17438 viraddr = mbox->sge_array->addr[0];
17440 /* Set up the SGL pages in the non-embedded DMA pages */
17441 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
17442 sgl_pg_pairs = &sgl->sgl_pg_pairs;
17445 list_for_each_entry(lpfc_ncmd, nblist, list) {
17446 /* Set up the sge entry */
17447 sgl_pg_pairs->sgl_pg0_addr_lo =
17448 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
17449 sgl_pg_pairs->sgl_pg0_addr_hi =
17450 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
17451 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
17452 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
17455 pdma_phys_bpl1 = 0;
17456 sgl_pg_pairs->sgl_pg1_addr_lo =
17457 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
17458 sgl_pg_pairs->sgl_pg1_addr_hi =
17459 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
17460 /* Keep the first xritag on the list */
17462 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
17466 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
17467 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
17468 /* Perform endian conversion if necessary */
17469 sgl->word0 = cpu_to_le32(sgl->word0);
17471 if (!phba->sli4_hba.intr_enable) {
17472 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17474 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17475 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17477 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
17478 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17479 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17480 if (rc != MBX_TIMEOUT)
17481 lpfc_sli4_mbox_cmd_free(phba, mbox);
17482 if (shdr_status || shdr_add_status || rc) {
17483 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17484 "6125 POST_SGL_BLOCK mailbox command failed "
17485 "status x%x add_status x%x mbx status x%x\n",
17486 shdr_status, shdr_add_status, rc);
17493 * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
17494 * @phba: pointer to lpfc hba data structure.
17495 * @post_nblist: pointer to the nvme buffer list.
17496 * @sb_count: number of nvme buffers.
17498 * This routine walks a list of nvme buffers that was passed in. It attempts
17499 * to construct blocks of nvme buffer sgls which contains contiguous xris and
17500 * uses the non-embedded SGL block post mailbox commands to post to the port.
17501 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
17502 * embedded SGL post mailbox command for posting. The @post_nblist passed in
17503 * must be local list, thus no lock is needed when manipulate the list.
17505 * Returns: 0 = failure, non-zero number of successfully posted buffers.
17508 lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
17509 struct list_head *post_nblist, int sb_count)
17511 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
17512 int status, sgl_size;
17513 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
17514 dma_addr_t pdma_phys_sgl1;
17515 int last_xritag = NO_XRI;
17517 LIST_HEAD(prep_nblist);
17518 LIST_HEAD(blck_nblist);
17519 LIST_HEAD(nvme_nblist);
17525 sgl_size = phba->cfg_sg_dma_buf_size;
17526 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
17527 list_del_init(&lpfc_ncmd->list);
17529 if ((last_xritag != NO_XRI) &&
17530 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
17531 /* a hole in xri block, form a sgl posting block */
17532 list_splice_init(&prep_nblist, &blck_nblist);
17533 post_cnt = block_cnt - 1;
17534 /* prepare list for next posting block */
17535 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
17538 /* prepare list for next posting block */
17539 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
17540 /* enough sgls for non-embed sgl mbox command */
17541 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
17542 list_splice_init(&prep_nblist, &blck_nblist);
17543 post_cnt = block_cnt;
17548 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
17550 /* end of repost sgl list condition for NVME buffers */
17551 if (num_posting == sb_count) {
17552 if (post_cnt == 0) {
17553 /* last sgl posting block */
17554 list_splice_init(&prep_nblist, &blck_nblist);
17555 post_cnt = block_cnt;
17556 } else if (block_cnt == 1) {
17557 /* last single sgl with non-contiguous xri */
17558 if (sgl_size > SGL_PAGE_SIZE)
17560 lpfc_ncmd->dma_phys_sgl +
17563 pdma_phys_sgl1 = 0;
17564 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
17565 status = lpfc_sli4_post_sgl(
17566 phba, lpfc_ncmd->dma_phys_sgl,
17567 pdma_phys_sgl1, cur_xritag);
17569 /* Post error. Buffer unavailable. */
17570 lpfc_ncmd->flags |=
17571 LPFC_SBUF_NOT_POSTED;
17573 /* Post success. Bffer available. */
17574 lpfc_ncmd->flags &=
17575 ~LPFC_SBUF_NOT_POSTED;
17576 lpfc_ncmd->status = IOSTAT_SUCCESS;
17579 /* success, put on NVME buffer sgl list */
17580 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
17584 /* continue until a nembed page worth of sgls */
17588 /* post block of NVME buffer list sgls */
17589 status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
17592 /* don't reset xirtag due to hole in xri block */
17593 if (block_cnt == 0)
17594 last_xritag = NO_XRI;
17596 /* reset NVME buffer post count for next round of posting */
17599 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
17600 while (!list_empty(&blck_nblist)) {
17601 list_remove_head(&blck_nblist, lpfc_ncmd,
17602 struct lpfc_io_buf, list);
17604 /* Post error. Mark buffer unavailable. */
17605 lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
17607 /* Post success, Mark buffer available. */
17608 lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
17609 lpfc_ncmd->status = IOSTAT_SUCCESS;
17612 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
17615 /* Push NVME buffers with sgl posted to the available list */
17616 lpfc_io_buf_replenish(phba, &nvme_nblist);
17622 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
17623 * @phba: pointer to lpfc_hba struct that the frame was received on
17624 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
17626 * This function checks the fields in the @fc_hdr to see if the FC frame is a
17627 * valid type of frame that the LPFC driver will handle. This function will
17628 * return a zero if the frame is a valid frame or a non zero value when the
17629 * frame does not pass the check.
17632 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
17634 /* make rctl_names static to save stack space */
17635 struct fc_vft_header *fc_vft_hdr;
17636 uint32_t *header = (uint32_t *) fc_hdr;
17638 #define FC_RCTL_MDS_DIAGS 0xF4
17640 switch (fc_hdr->fh_r_ctl) {
17641 case FC_RCTL_DD_UNCAT: /* uncategorized information */
17642 case FC_RCTL_DD_SOL_DATA: /* solicited data */
17643 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
17644 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
17645 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
17646 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
17647 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
17648 case FC_RCTL_DD_CMD_STATUS: /* command status */
17649 case FC_RCTL_ELS_REQ: /* extended link services request */
17650 case FC_RCTL_ELS_REP: /* extended link services reply */
17651 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
17652 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
17653 case FC_RCTL_BA_NOP: /* basic link service NOP */
17654 case FC_RCTL_BA_ABTS: /* basic link service abort */
17655 case FC_RCTL_BA_RMC: /* remove connection */
17656 case FC_RCTL_BA_ACC: /* basic accept */
17657 case FC_RCTL_BA_RJT: /* basic reject */
17658 case FC_RCTL_BA_PRMT:
17659 case FC_RCTL_ACK_1: /* acknowledge_1 */
17660 case FC_RCTL_ACK_0: /* acknowledge_0 */
17661 case FC_RCTL_P_RJT: /* port reject */
17662 case FC_RCTL_F_RJT: /* fabric reject */
17663 case FC_RCTL_P_BSY: /* port busy */
17664 case FC_RCTL_F_BSY: /* fabric busy to data frame */
17665 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
17666 case FC_RCTL_LCR: /* link credit reset */
17667 case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
17668 case FC_RCTL_END: /* end */
17670 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
17671 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
17672 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
17673 return lpfc_fc_frame_check(phba, fc_hdr);
17678 switch (fc_hdr->fh_type) {
17691 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
17692 "2538 Received frame rctl:x%x, type:x%x, "
17693 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
17694 fc_hdr->fh_r_ctl, fc_hdr->fh_type,
17695 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
17696 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
17697 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
17698 be32_to_cpu(header[6]));
17701 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
17702 "2539 Dropped frame rctl:x%x type:x%x\n",
17703 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
17708 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
17709 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
17711 * This function processes the FC header to retrieve the VFI from the VF
17712 * header, if one exists. This function will return the VFI if one exists
17713 * or 0 if no VSAN Header exists.
17716 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
17718 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
17720 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
17722 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
17726 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
17727 * @phba: Pointer to the HBA structure to search for the vport on
17728 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
17729 * @fcfi: The FC Fabric ID that the frame came from
17730 * @did: Destination ID to match against
17732 * This function searches the @phba for a vport that matches the content of the
17733 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
17734 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
17735 * returns the matching vport pointer or NULL if unable to match frame to a
17738 static struct lpfc_vport *
17739 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
17740 uint16_t fcfi, uint32_t did)
17742 struct lpfc_vport **vports;
17743 struct lpfc_vport *vport = NULL;
17746 if (did == Fabric_DID)
17747 return phba->pport;
17748 if ((phba->pport->fc_flag & FC_PT2PT) &&
17749 !(phba->link_state == LPFC_HBA_READY))
17750 return phba->pport;
17752 vports = lpfc_create_vport_work_array(phba);
17753 if (vports != NULL) {
17754 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
17755 if (phba->fcf.fcfi == fcfi &&
17756 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
17757 vports[i]->fc_myDID == did) {
17763 lpfc_destroy_vport_work_array(phba, vports);
17768 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
17769 * @vport: The vport to work on.
17771 * This function updates the receive sequence time stamp for this vport. The
17772 * receive sequence time stamp indicates the time that the last frame of the
17773 * the sequence that has been idle for the longest amount of time was received.
17774 * the driver uses this time stamp to indicate if any received sequences have
17778 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
17780 struct lpfc_dmabuf *h_buf;
17781 struct hbq_dmabuf *dmabuf = NULL;
17783 /* get the oldest sequence on the rcv list */
17784 h_buf = list_get_first(&vport->rcv_buffer_list,
17785 struct lpfc_dmabuf, list);
17788 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17789 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
17793 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
17794 * @vport: The vport that the received sequences were sent to.
17796 * This function cleans up all outstanding received sequences. This is called
17797 * by the driver when a link event or user action invalidates all the received
17801 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
17803 struct lpfc_dmabuf *h_buf, *hnext;
17804 struct lpfc_dmabuf *d_buf, *dnext;
17805 struct hbq_dmabuf *dmabuf = NULL;
17807 /* start with the oldest sequence on the rcv list */
17808 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
17809 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17810 list_del_init(&dmabuf->hbuf.list);
17811 list_for_each_entry_safe(d_buf, dnext,
17812 &dmabuf->dbuf.list, list) {
17813 list_del_init(&d_buf->list);
17814 lpfc_in_buf_free(vport->phba, d_buf);
17816 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
17821 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
17822 * @vport: The vport that the received sequences were sent to.
17824 * This function determines whether any received sequences have timed out by
17825 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
17826 * indicates that there is at least one timed out sequence this routine will
17827 * go through the received sequences one at a time from most inactive to most
17828 * active to determine which ones need to be cleaned up. Once it has determined
17829 * that a sequence needs to be cleaned up it will simply free up the resources
17830 * without sending an abort.
17833 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
17835 struct lpfc_dmabuf *h_buf, *hnext;
17836 struct lpfc_dmabuf *d_buf, *dnext;
17837 struct hbq_dmabuf *dmabuf = NULL;
17838 unsigned long timeout;
17839 int abort_count = 0;
17841 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
17842 vport->rcv_buffer_time_stamp);
17843 if (list_empty(&vport->rcv_buffer_list) ||
17844 time_before(jiffies, timeout))
17846 /* start with the oldest sequence on the rcv list */
17847 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
17848 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17849 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
17850 dmabuf->time_stamp);
17851 if (time_before(jiffies, timeout))
17854 list_del_init(&dmabuf->hbuf.list);
17855 list_for_each_entry_safe(d_buf, dnext,
17856 &dmabuf->dbuf.list, list) {
17857 list_del_init(&d_buf->list);
17858 lpfc_in_buf_free(vport->phba, d_buf);
17860 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
17863 lpfc_update_rcv_time_stamp(vport);
17867 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
17868 * @vport: pointer to a vitural port
17869 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
17871 * This function searches through the existing incomplete sequences that have
17872 * been sent to this @vport. If the frame matches one of the incomplete
17873 * sequences then the dbuf in the @dmabuf is added to the list of frames that
17874 * make up that sequence. If no sequence is found that matches this frame then
17875 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
17876 * This function returns a pointer to the first dmabuf in the sequence list that
17877 * the frame was linked to.
17879 static struct hbq_dmabuf *
17880 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
17882 struct fc_frame_header *new_hdr;
17883 struct fc_frame_header *temp_hdr;
17884 struct lpfc_dmabuf *d_buf;
17885 struct lpfc_dmabuf *h_buf;
17886 struct hbq_dmabuf *seq_dmabuf = NULL;
17887 struct hbq_dmabuf *temp_dmabuf = NULL;
17890 INIT_LIST_HEAD(&dmabuf->dbuf.list);
17891 dmabuf->time_stamp = jiffies;
17892 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17894 /* Use the hdr_buf to find the sequence that this frame belongs to */
17895 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
17896 temp_hdr = (struct fc_frame_header *)h_buf->virt;
17897 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
17898 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
17899 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
17901 /* found a pending sequence that matches this frame */
17902 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17907 * This indicates first frame received for this sequence.
17908 * Queue the buffer on the vport's rcv_buffer_list.
17910 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
17911 lpfc_update_rcv_time_stamp(vport);
17914 temp_hdr = seq_dmabuf->hbuf.virt;
17915 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
17916 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
17917 list_del_init(&seq_dmabuf->hbuf.list);
17918 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
17919 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
17920 lpfc_update_rcv_time_stamp(vport);
17923 /* move this sequence to the tail to indicate a young sequence */
17924 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
17925 seq_dmabuf->time_stamp = jiffies;
17926 lpfc_update_rcv_time_stamp(vport);
17927 if (list_empty(&seq_dmabuf->dbuf.list)) {
17928 temp_hdr = dmabuf->hbuf.virt;
17929 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
17932 /* find the correct place in the sequence to insert this frame */
17933 d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
17935 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
17936 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
17938 * If the frame's sequence count is greater than the frame on
17939 * the list then insert the frame right after this frame
17941 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
17942 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
17943 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
17948 if (&d_buf->list == &seq_dmabuf->dbuf.list)
17950 d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
17959 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
17960 * @vport: pointer to a vitural port
17961 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17963 * This function tries to abort from the partially assembed sequence, described
17964 * by the information from basic abbort @dmabuf. It checks to see whether such
17965 * partially assembled sequence held by the driver. If so, it shall free up all
17966 * the frames from the partially assembled sequence.
17969 * true -- if there is matching partially assembled sequence present and all
17970 * the frames freed with the sequence;
17971 * false -- if there is no matching partially assembled sequence present so
17972 * nothing got aborted in the lower layer driver
17975 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
17976 struct hbq_dmabuf *dmabuf)
17978 struct fc_frame_header *new_hdr;
17979 struct fc_frame_header *temp_hdr;
17980 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
17981 struct hbq_dmabuf *seq_dmabuf = NULL;
17983 /* Use the hdr_buf to find the sequence that matches this frame */
17984 INIT_LIST_HEAD(&dmabuf->dbuf.list);
17985 INIT_LIST_HEAD(&dmabuf->hbuf.list);
17986 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
17987 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
17988 temp_hdr = (struct fc_frame_header *)h_buf->virt;
17989 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
17990 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
17991 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
17993 /* found a pending sequence that matches this frame */
17994 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
17998 /* Free up all the frames from the partially assembled sequence */
18000 list_for_each_entry_safe(d_buf, n_buf,
18001 &seq_dmabuf->dbuf.list, list) {
18002 list_del_init(&d_buf->list);
18003 lpfc_in_buf_free(vport->phba, d_buf);
18011 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
18012 * @vport: pointer to a vitural port
18013 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18015 * This function tries to abort from the assembed sequence from upper level
18016 * protocol, described by the information from basic abbort @dmabuf. It
18017 * checks to see whether such pending context exists at upper level protocol.
18018 * If so, it shall clean up the pending context.
18021 * true -- if there is matching pending context of the sequence cleaned
18023 * false -- if there is no matching pending context of the sequence present
18027 lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
18029 struct lpfc_hba *phba = vport->phba;
18032 /* Accepting abort at ulp with SLI4 only */
18033 if (phba->sli_rev < LPFC_SLI_REV4)
18036 /* Register all caring upper level protocols to attend abort */
18037 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
18045 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
18046 * @phba: Pointer to HBA context object.
18047 * @cmd_iocbq: pointer to the command iocbq structure.
18048 * @rsp_iocbq: pointer to the response iocbq structure.
18050 * This function handles the sequence abort response iocb command complete
18051 * event. It properly releases the memory allocated to the sequence abort
18055 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
18056 struct lpfc_iocbq *cmd_iocbq,
18057 struct lpfc_iocbq *rsp_iocbq)
18059 struct lpfc_nodelist *ndlp;
18062 ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
18063 lpfc_nlp_put(ndlp);
18064 lpfc_nlp_not_used(ndlp);
18065 lpfc_sli_release_iocbq(phba, cmd_iocbq);
18068 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
18069 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
18070 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18071 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
18072 rsp_iocbq->iocb.ulpStatus,
18073 rsp_iocbq->iocb.un.ulpWord[4]);
18077 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
18078 * @phba: Pointer to HBA context object.
18079 * @xri: xri id in transaction.
18081 * This function validates the xri maps to the known range of XRIs allocated an
18082 * used by the driver.
18085 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
18090 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
18091 if (xri == phba->sli4_hba.xri_ids[i])
18098 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
18099 * @vport: pointer to a vitural port.
18100 * @fc_hdr: pointer to a FC frame header.
18101 * @aborted: was the partially assembled receive sequence successfully aborted
18103 * This function sends a basic response to a previous unsol sequence abort
18104 * event after aborting the sequence handling.
18107 lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
18108 struct fc_frame_header *fc_hdr, bool aborted)
18110 struct lpfc_hba *phba = vport->phba;
18111 struct lpfc_iocbq *ctiocb = NULL;
18112 struct lpfc_nodelist *ndlp;
18113 uint16_t oxid, rxid, xri, lxri;
18114 uint32_t sid, fctl;
18118 if (!lpfc_is_link_up(phba))
18121 sid = sli4_sid_from_fc_hdr(fc_hdr);
18122 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
18123 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
18125 ndlp = lpfc_findnode_did(vport, sid);
18127 ndlp = lpfc_nlp_init(vport, sid);
18129 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
18130 "1268 Failed to allocate ndlp for "
18131 "oxid:x%x SID:x%x\n", oxid, sid);
18134 /* Put ndlp onto pport node list */
18135 lpfc_enqueue_node(vport, ndlp);
18138 /* Allocate buffer for rsp iocb */
18139 ctiocb = lpfc_sli_get_iocbq(phba);
18143 /* Extract the F_CTL field from FC_HDR */
18144 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
18146 icmd = &ctiocb->iocb;
18147 icmd->un.xseq64.bdl.bdeSize = 0;
18148 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
18149 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
18150 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
18151 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
18153 /* Fill in the rest of iocb fields */
18154 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
18155 icmd->ulpBdeCount = 0;
18157 icmd->ulpClass = CLASS3;
18158 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
18159 ctiocb->context1 = lpfc_nlp_get(ndlp);
18160 if (!ctiocb->context1) {
18161 lpfc_sli_release_iocbq(phba, ctiocb);
18165 ctiocb->vport = phba->pport;
18166 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
18167 ctiocb->sli4_lxritag = NO_XRI;
18168 ctiocb->sli4_xritag = NO_XRI;
18170 if (fctl & FC_FC_EX_CTX)
18171 /* Exchange responder sent the abort so we
18177 lxri = lpfc_sli4_xri_inrange(phba, xri);
18178 if (lxri != NO_XRI)
18179 lpfc_set_rrq_active(phba, ndlp, lxri,
18180 (xri == oxid) ? rxid : oxid, 0);
18181 /* For BA_ABTS from exchange responder, if the logical xri with
18182 * the oxid maps to the FCP XRI range, the port no longer has
18183 * that exchange context, send a BLS_RJT. Override the IOCB for
18186 if ((fctl & FC_FC_EX_CTX) &&
18187 (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
18188 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
18189 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
18190 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
18191 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
18194 /* If BA_ABTS failed to abort a partially assembled receive sequence,
18195 * the driver no longer has that exchange, send a BLS_RJT. Override
18196 * the IOCB for a BA_RJT.
18198 if (aborted == false) {
18199 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
18200 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
18201 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
18202 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
18205 if (fctl & FC_FC_EX_CTX) {
18206 /* ABTS sent by responder to CT exchange, construction
18207 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
18208 * field and RX_ID from ABTS for RX_ID field.
18210 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
18212 /* ABTS sent by initiator to CT exchange, construction
18213 * of BA_ACC will need to allocate a new XRI as for the
18216 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
18218 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
18219 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
18221 /* Xmit CT abts response on exchange <xid> */
18222 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
18223 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
18224 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
18226 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
18227 if (rc == IOCB_ERROR) {
18228 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
18229 "2925 Failed to issue CT ABTS RSP x%x on "
18230 "xri x%x, Data x%x\n",
18231 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
18233 lpfc_nlp_put(ndlp);
18234 ctiocb->context1 = NULL;
18235 lpfc_sli_release_iocbq(phba, ctiocb);
18240 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
18241 * @vport: Pointer to the vport on which this sequence was received
18242 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18244 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
18245 * receive sequence is only partially assembed by the driver, it shall abort
18246 * the partially assembled frames for the sequence. Otherwise, if the
18247 * unsolicited receive sequence has been completely assembled and passed to
18248 * the Upper Layer Protocol (ULP), it then mark the per oxid status for the
18249 * unsolicited sequence has been aborted. After that, it will issue a basic
18250 * accept to accept the abort.
18253 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
18254 struct hbq_dmabuf *dmabuf)
18256 struct lpfc_hba *phba = vport->phba;
18257 struct fc_frame_header fc_hdr;
18261 /* Make a copy of fc_hdr before the dmabuf being released */
18262 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
18263 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
18265 if (fctl & FC_FC_EX_CTX) {
18266 /* ABTS by responder to exchange, no cleanup needed */
18269 /* ABTS by initiator to exchange, need to do cleanup */
18270 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
18271 if (aborted == false)
18272 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
18274 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18276 if (phba->nvmet_support) {
18277 lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
18281 /* Respond with BA_ACC or BA_RJT accordingly */
18282 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
18286 * lpfc_seq_complete - Indicates if a sequence is complete
18287 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18289 * This function checks the sequence, starting with the frame described by
18290 * @dmabuf, to see if all the frames associated with this sequence are present.
18291 * the frames associated with this sequence are linked to the @dmabuf using the
18292 * dbuf list. This function looks for two major things. 1) That the first frame
18293 * has a sequence count of zero. 2) There is a frame with last frame of sequence
18294 * set. 3) That there are no holes in the sequence count. The function will
18295 * return 1 when the sequence is complete, otherwise it will return 0.
18298 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
18300 struct fc_frame_header *hdr;
18301 struct lpfc_dmabuf *d_buf;
18302 struct hbq_dmabuf *seq_dmabuf;
18306 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18307 /* make sure first fame of sequence has a sequence count of zero */
18308 if (hdr->fh_seq_cnt != seq_count)
18310 fctl = (hdr->fh_f_ctl[0] << 16 |
18311 hdr->fh_f_ctl[1] << 8 |
18313 /* If last frame of sequence we can return success. */
18314 if (fctl & FC_FC_END_SEQ)
18316 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
18317 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
18318 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
18319 /* If there is a hole in the sequence count then fail. */
18320 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
18322 fctl = (hdr->fh_f_ctl[0] << 16 |
18323 hdr->fh_f_ctl[1] << 8 |
18325 /* If last frame of sequence we can return success. */
18326 if (fctl & FC_FC_END_SEQ)
18333 * lpfc_prep_seq - Prep sequence for ULP processing
18334 * @vport: Pointer to the vport on which this sequence was received
18335 * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence
18337 * This function takes a sequence, described by a list of frames, and creates
18338 * a list of iocbq structures to describe the sequence. This iocbq list will be
18339 * used to issue to the generic unsolicited sequence handler. This routine
18340 * returns a pointer to the first iocbq in the list. If the function is unable
18341 * to allocate an iocbq then it throw out the received frames that were not
18342 * able to be described and return a pointer to the first iocbq. If unable to
18343 * allocate any iocbqs (including the first) this function will return NULL.
18345 static struct lpfc_iocbq *
18346 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
18348 struct hbq_dmabuf *hbq_buf;
18349 struct lpfc_dmabuf *d_buf, *n_buf;
18350 struct lpfc_iocbq *first_iocbq, *iocbq;
18351 struct fc_frame_header *fc_hdr;
18353 uint32_t len, tot_len;
18354 struct ulp_bde64 *pbde;
18356 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
18357 /* remove from receive buffer list */
18358 list_del_init(&seq_dmabuf->hbuf.list);
18359 lpfc_update_rcv_time_stamp(vport);
18360 /* get the Remote Port's SID */
18361 sid = sli4_sid_from_fc_hdr(fc_hdr);
18363 /* Get an iocbq struct to fill in. */
18364 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
18366 /* Initialize the first IOCB. */
18367 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
18368 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
18369 first_iocbq->vport = vport;
18371 /* Check FC Header to see what TYPE of frame we are rcv'ing */
18372 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
18373 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
18374 first_iocbq->iocb.un.rcvels.parmRo =
18375 sli4_did_from_fc_hdr(fc_hdr);
18376 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
18378 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
18379 first_iocbq->iocb.ulpContext = NO_XRI;
18380 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
18381 be16_to_cpu(fc_hdr->fh_ox_id);
18382 /* iocbq is prepped for internal consumption. Physical vpi. */
18383 first_iocbq->iocb.unsli3.rcvsli3.vpi =
18384 vport->phba->vpi_ids[vport->vpi];
18385 /* put the first buffer into the first IOCBq */
18386 tot_len = bf_get(lpfc_rcqe_length,
18387 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
18389 first_iocbq->context2 = &seq_dmabuf->dbuf;
18390 first_iocbq->context3 = NULL;
18391 first_iocbq->iocb.ulpBdeCount = 1;
18392 if (tot_len > LPFC_DATA_BUF_SIZE)
18393 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
18394 LPFC_DATA_BUF_SIZE;
18396 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
18398 first_iocbq->iocb.un.rcvels.remoteID = sid;
18400 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
18402 iocbq = first_iocbq;
18404 * Each IOCBq can have two Buffers assigned, so go through the list
18405 * of buffers for this sequence and save two buffers in each IOCBq
18407 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
18409 lpfc_in_buf_free(vport->phba, d_buf);
18412 if (!iocbq->context3) {
18413 iocbq->context3 = d_buf;
18414 iocbq->iocb.ulpBdeCount++;
18415 /* We need to get the size out of the right CQE */
18416 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
18417 len = bf_get(lpfc_rcqe_length,
18418 &hbq_buf->cq_event.cqe.rcqe_cmpl);
18419 pbde = (struct ulp_bde64 *)
18420 &iocbq->iocb.unsli3.sli3Words[4];
18421 if (len > LPFC_DATA_BUF_SIZE)
18422 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
18424 pbde->tus.f.bdeSize = len;
18426 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
18429 iocbq = lpfc_sli_get_iocbq(vport->phba);
18432 first_iocbq->iocb.ulpStatus =
18433 IOSTAT_FCP_RSP_ERROR;
18434 first_iocbq->iocb.un.ulpWord[4] =
18435 IOERR_NO_RESOURCES;
18437 lpfc_in_buf_free(vport->phba, d_buf);
18440 /* We need to get the size out of the right CQE */
18441 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
18442 len = bf_get(lpfc_rcqe_length,
18443 &hbq_buf->cq_event.cqe.rcqe_cmpl);
18444 iocbq->context2 = d_buf;
18445 iocbq->context3 = NULL;
18446 iocbq->iocb.ulpBdeCount = 1;
18447 if (len > LPFC_DATA_BUF_SIZE)
18448 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
18449 LPFC_DATA_BUF_SIZE;
18451 iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
18454 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
18456 iocbq->iocb.un.rcvels.remoteID = sid;
18457 list_add_tail(&iocbq->list, &first_iocbq->list);
18460 /* Free the sequence's header buffer */
18462 lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf);
18464 return first_iocbq;
18468 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
18469 struct hbq_dmabuf *seq_dmabuf)
18471 struct fc_frame_header *fc_hdr;
18472 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
18473 struct lpfc_hba *phba = vport->phba;
18475 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
18476 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
18478 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18479 "2707 Ring %d handler: Failed to allocate "
18480 "iocb Rctl x%x Type x%x received\n",
18482 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
18485 if (!lpfc_complete_unsol_iocb(phba,
18486 phba->sli4_hba.els_wq->pring,
18487 iocbq, fc_hdr->fh_r_ctl,
18489 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18490 "2540 Ring %d handler: unexpected Rctl "
18491 "x%x Type x%x received\n",
18493 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
18495 /* Free iocb created in lpfc_prep_seq */
18496 list_for_each_entry_safe(curr_iocb, next_iocb,
18497 &iocbq->list, list) {
18498 list_del_init(&curr_iocb->list);
18499 lpfc_sli_release_iocbq(phba, curr_iocb);
18501 lpfc_sli_release_iocbq(phba, iocbq);
18505 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
18506 struct lpfc_iocbq *rspiocb)
18508 struct lpfc_dmabuf *pcmd = cmdiocb->context2;
18510 if (pcmd && pcmd->virt)
18511 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
18513 lpfc_sli_release_iocbq(phba, cmdiocb);
18514 lpfc_drain_txq(phba);
18518 lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
18519 struct hbq_dmabuf *dmabuf)
18521 struct fc_frame_header *fc_hdr;
18522 struct lpfc_hba *phba = vport->phba;
18523 struct lpfc_iocbq *iocbq = NULL;
18524 union lpfc_wqe *wqe;
18525 struct lpfc_dmabuf *pcmd = NULL;
18526 uint32_t frame_len;
18528 unsigned long iflags;
18530 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18531 frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
18533 /* Send the received frame back */
18534 iocbq = lpfc_sli_get_iocbq(phba);
18536 /* Queue cq event and wakeup worker thread to process it */
18537 spin_lock_irqsave(&phba->hbalock, iflags);
18538 list_add_tail(&dmabuf->cq_event.list,
18539 &phba->sli4_hba.sp_queue_event);
18540 phba->hba_flag |= HBA_SP_QUEUE_EVT;
18541 spin_unlock_irqrestore(&phba->hbalock, iflags);
18542 lpfc_worker_wake_up(phba);
18546 /* Allocate buffer for command payload */
18547 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
18549 pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
18551 if (!pcmd || !pcmd->virt)
18554 INIT_LIST_HEAD(&pcmd->list);
18556 /* copyin the payload */
18557 memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
18559 /* fill in BDE's for command */
18560 iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys);
18561 iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys);
18562 iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
18563 iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len;
18565 iocbq->context2 = pcmd;
18566 iocbq->vport = vport;
18567 iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
18568 iocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
18571 * Setup rest of the iocb as though it were a WQE
18572 * Build the SEND_FRAME WQE
18574 wqe = (union lpfc_wqe *)&iocbq->iocb;
18576 wqe->send_frame.frame_len = frame_len;
18577 wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr));
18578 wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1));
18579 wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2));
18580 wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3));
18581 wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4));
18582 wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5));
18584 iocbq->iocb.ulpCommand = CMD_SEND_FRAME;
18585 iocbq->iocb.ulpLe = 1;
18586 iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl;
18587 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
18588 if (rc == IOCB_ERROR)
18591 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18595 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
18596 "2023 Unable to process MDS loopback frame\n");
18597 if (pcmd && pcmd->virt)
18598 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
18601 lpfc_sli_release_iocbq(phba, iocbq);
18602 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18606 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
18607 * @phba: Pointer to HBA context object.
18608 * @dmabuf: Pointer to a dmabuf that describes the FC sequence.
18610 * This function is called with no lock held. This function processes all
18611 * the received buffers and gives it to upper layers when a received buffer
18612 * indicates that it is the final frame in the sequence. The interrupt
18613 * service routine processes received buffers at interrupt contexts.
18614 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
18615 * appropriate receive function when the final frame in a sequence is received.
18618 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
18619 struct hbq_dmabuf *dmabuf)
18621 struct hbq_dmabuf *seq_dmabuf;
18622 struct fc_frame_header *fc_hdr;
18623 struct lpfc_vport *vport;
18627 /* Process each received buffer */
18628 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18630 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
18631 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
18632 vport = phba->pport;
18633 /* Handle MDS Loopback frames */
18634 if (!(phba->pport->load_flag & FC_UNLOADING))
18635 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
18637 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18641 /* check to see if this a valid type of frame */
18642 if (lpfc_fc_frame_check(phba, fc_hdr)) {
18643 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18647 if ((bf_get(lpfc_cqe_code,
18648 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
18649 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
18650 &dmabuf->cq_event.cqe.rcqe_cmpl);
18652 fcfi = bf_get(lpfc_rcqe_fcf_id,
18653 &dmabuf->cq_event.cqe.rcqe_cmpl);
18655 if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
18656 vport = phba->pport;
18657 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
18658 "2023 MDS Loopback %d bytes\n",
18659 bf_get(lpfc_rcqe_length,
18660 &dmabuf->cq_event.cqe.rcqe_cmpl));
18661 /* Handle MDS Loopback frames */
18662 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
18666 /* d_id this frame is directed to */
18667 did = sli4_did_from_fc_hdr(fc_hdr);
18669 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
18671 /* throw out the frame */
18672 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18676 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
18677 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
18678 (did != Fabric_DID)) {
18680 * Throw out the frame if we are not pt2pt.
18681 * The pt2pt protocol allows for discovery frames
18682 * to be received without a registered VPI.
18684 if (!(vport->fc_flag & FC_PT2PT) ||
18685 (phba->link_state == LPFC_HBA_READY)) {
18686 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18691 /* Handle the basic abort sequence (BA_ABTS) event */
18692 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
18693 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
18697 /* Link this frame */
18698 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
18700 /* unable to add frame to vport - throw it out */
18701 lpfc_in_buf_free(phba, &dmabuf->dbuf);
18704 /* If not last frame in sequence continue processing frames. */
18705 if (!lpfc_seq_complete(seq_dmabuf))
18708 /* Send the complete sequence to the upper layer protocol */
18709 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
18713 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
18714 * @phba: pointer to lpfc hba data structure.
18716 * This routine is invoked to post rpi header templates to the
18717 * HBA consistent with the SLI-4 interface spec. This routine
18718 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
18719 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
18721 * This routine does not require any locks. It's usage is expected
18722 * to be driver load or reset recovery when the driver is
18727 * -EIO - The mailbox failed to complete successfully.
18728 * When this error occurs, the driver is not guaranteed
18729 * to have any rpi regions posted to the device and
18730 * must either attempt to repost the regions or take a
18734 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
18736 struct lpfc_rpi_hdr *rpi_page;
18740 /* SLI4 ports that support extents do not require RPI headers. */
18741 if (!phba->sli4_hba.rpi_hdrs_in_use)
18743 if (phba->sli4_hba.extents_in_use)
18746 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
18748 * Assign the rpi headers a physical rpi only if the driver
18749 * has not initialized those resources. A port reset only
18750 * needs the headers posted.
18752 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
18754 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
18756 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
18757 if (rc != MBX_SUCCESS) {
18758 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18759 "2008 Error %d posting all rpi "
18767 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
18768 LPFC_RPI_RSRC_RDY);
18773 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
18774 * @phba: pointer to lpfc hba data structure.
18775 * @rpi_page: pointer to the rpi memory region.
18777 * This routine is invoked to post a single rpi header to the
18778 * HBA consistent with the SLI-4 interface spec. This memory region
18779 * maps up to 64 rpi context regions.
18783 * -ENOMEM - No available memory
18784 * -EIO - The mailbox failed to complete successfully.
18787 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
18789 LPFC_MBOXQ_t *mboxq;
18790 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
18792 uint32_t shdr_status, shdr_add_status;
18793 union lpfc_sli4_cfg_shdr *shdr;
18795 /* SLI4 ports that support extents do not require RPI headers. */
18796 if (!phba->sli4_hba.rpi_hdrs_in_use)
18798 if (phba->sli4_hba.extents_in_use)
18801 /* The port is notified of the header region via a mailbox command. */
18802 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18804 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18805 "2001 Unable to allocate memory for issuing "
18806 "SLI_CONFIG_SPECIAL mailbox command\n");
18810 /* Post all rpi memory regions to the port. */
18811 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
18812 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
18813 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
18814 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
18815 sizeof(struct lpfc_sli4_cfg_mhdr),
18816 LPFC_SLI4_MBX_EMBED);
18819 /* Post the physical rpi to the port for this rpi header. */
18820 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
18821 rpi_page->start_rpi);
18822 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
18823 hdr_tmpl, rpi_page->page_count);
18825 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
18826 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
18827 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
18828 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
18829 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18830 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18831 if (rc != MBX_TIMEOUT)
18832 mempool_free(mboxq, phba->mbox_mem_pool);
18833 if (shdr_status || shdr_add_status || rc) {
18834 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18835 "2514 POST_RPI_HDR mailbox failed with "
18836 "status x%x add_status x%x, mbx status x%x\n",
18837 shdr_status, shdr_add_status, rc);
18841 * The next_rpi stores the next logical module-64 rpi value used
18842 * to post physical rpis in subsequent rpi postings.
18844 spin_lock_irq(&phba->hbalock);
18845 phba->sli4_hba.next_rpi = rpi_page->next_rpi;
18846 spin_unlock_irq(&phba->hbalock);
18852 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
18853 * @phba: pointer to lpfc hba data structure.
18855 * This routine is invoked to post rpi header templates to the
18856 * HBA consistent with the SLI-4 interface spec. This routine
18857 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
18858 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
18861 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
18862 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
18865 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
18868 uint16_t max_rpi, rpi_limit;
18869 uint16_t rpi_remaining, lrpi = 0;
18870 struct lpfc_rpi_hdr *rpi_hdr;
18871 unsigned long iflag;
18874 * Fetch the next logical rpi. Because this index is logical,
18875 * the driver starts at 0 each time.
18877 spin_lock_irqsave(&phba->hbalock, iflag);
18878 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
18879 rpi_limit = phba->sli4_hba.next_rpi;
18881 rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
18882 if (rpi >= rpi_limit)
18883 rpi = LPFC_RPI_ALLOC_ERROR;
18885 set_bit(rpi, phba->sli4_hba.rpi_bmask);
18886 phba->sli4_hba.max_cfg_param.rpi_used++;
18887 phba->sli4_hba.rpi_count++;
18889 lpfc_printf_log(phba, KERN_INFO,
18890 LOG_NODE | LOG_DISCOVERY,
18891 "0001 Allocated rpi:x%x max:x%x lim:x%x\n",
18892 (int) rpi, max_rpi, rpi_limit);
18895 * Don't try to allocate more rpi header regions if the device limit
18896 * has been exhausted.
18898 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
18899 (phba->sli4_hba.rpi_count >= max_rpi)) {
18900 spin_unlock_irqrestore(&phba->hbalock, iflag);
18905 * RPI header postings are not required for SLI4 ports capable of
18908 if (!phba->sli4_hba.rpi_hdrs_in_use) {
18909 spin_unlock_irqrestore(&phba->hbalock, iflag);
18914 * If the driver is running low on rpi resources, allocate another
18915 * page now. Note that the next_rpi value is used because
18916 * it represents how many are actually in use whereas max_rpi notes
18917 * how many are supported max by the device.
18919 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
18920 spin_unlock_irqrestore(&phba->hbalock, iflag);
18921 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
18922 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
18924 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18925 "2002 Error Could not grow rpi "
18928 lrpi = rpi_hdr->start_rpi;
18929 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
18930 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
18938 * lpfc_sli4_free_rpi - Release an rpi for reuse.
18939 * @phba: pointer to lpfc hba data structure.
18940 * @rpi: rpi to free
18942 * This routine is invoked to release an rpi to the pool of
18943 * available rpis maintained by the driver.
18946 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
18949 * if the rpi value indicates a prior unreg has already
18950 * been done, skip the unreg.
18952 if (rpi == LPFC_RPI_ALLOC_ERROR)
18955 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
18956 phba->sli4_hba.rpi_count--;
18957 phba->sli4_hba.max_cfg_param.rpi_used--;
18959 lpfc_printf_log(phba, KERN_INFO,
18960 LOG_NODE | LOG_DISCOVERY,
18961 "2016 rpi %x not inuse\n",
18967 * lpfc_sli4_free_rpi - Release an rpi for reuse.
18968 * @phba: pointer to lpfc hba data structure.
18969 * @rpi: rpi to free
18971 * This routine is invoked to release an rpi to the pool of
18972 * available rpis maintained by the driver.
18975 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
18977 spin_lock_irq(&phba->hbalock);
18978 __lpfc_sli4_free_rpi(phba, rpi);
18979 spin_unlock_irq(&phba->hbalock);
18983 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
18984 * @phba: pointer to lpfc hba data structure.
18986 * This routine is invoked to remove the memory region that
18987 * provided rpi via a bitmask.
18990 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
18992 kfree(phba->sli4_hba.rpi_bmask);
18993 kfree(phba->sli4_hba.rpi_ids);
18994 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
18998 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
18999 * @ndlp: pointer to lpfc nodelist data structure.
19000 * @cmpl: completion call-back.
19001 * @arg: data to load as MBox 'caller buffer information'
19003 * This routine is invoked to remove the memory region that
19004 * provided rpi via a bitmask.
19007 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
19008 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
19010 LPFC_MBOXQ_t *mboxq;
19011 struct lpfc_hba *phba = ndlp->phba;
19014 /* The port is notified of the header region via a mailbox command. */
19015 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19019 /* Post all rpi memory regions to the port. */
19020 lpfc_resume_rpi(mboxq, ndlp);
19022 mboxq->mbox_cmpl = cmpl;
19023 mboxq->ctx_buf = arg;
19024 mboxq->ctx_ndlp = ndlp;
19026 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19027 mboxq->vport = ndlp->vport;
19028 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19029 if (rc == MBX_NOT_FINISHED) {
19030 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19031 "2010 Resume RPI Mailbox failed "
19032 "status %d, mbxStatus x%x\n", rc,
19033 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
19034 mempool_free(mboxq, phba->mbox_mem_pool);
19041 * lpfc_sli4_init_vpi - Initialize a vpi with the port
19042 * @vport: Pointer to the vport for which the vpi is being initialized
19044 * This routine is invoked to activate a vpi with the port.
19048 * -Evalue otherwise
19051 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
19053 LPFC_MBOXQ_t *mboxq;
19055 int retval = MBX_SUCCESS;
19057 struct lpfc_hba *phba = vport->phba;
19058 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19061 lpfc_init_vpi(phba, mboxq, vport->vpi);
19062 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
19063 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
19064 if (rc != MBX_SUCCESS) {
19065 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
19066 "2022 INIT VPI Mailbox failed "
19067 "status %d, mbxStatus x%x\n", rc,
19068 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
19071 if (rc != MBX_TIMEOUT)
19072 mempool_free(mboxq, vport->phba->mbox_mem_pool);
19078 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
19079 * @phba: pointer to lpfc hba data structure.
19080 * @mboxq: Pointer to mailbox object.
19082 * This routine is invoked to manually add a single FCF record. The caller
19083 * must pass a completely initialized FCF_Record. This routine takes
19084 * care of the nonembedded mailbox operations.
19087 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
19090 union lpfc_sli4_cfg_shdr *shdr;
19091 uint32_t shdr_status, shdr_add_status;
19093 virt_addr = mboxq->sge_array->addr[0];
19094 /* The IOCTL status is embedded in the mailbox subheader. */
19095 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
19096 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
19097 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
19099 if ((shdr_status || shdr_add_status) &&
19100 (shdr_status != STATUS_FCF_IN_USE))
19101 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19102 "2558 ADD_FCF_RECORD mailbox failed with "
19103 "status x%x add_status x%x\n",
19104 shdr_status, shdr_add_status);
19106 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19110 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
19111 * @phba: pointer to lpfc hba data structure.
19112 * @fcf_record: pointer to the initialized fcf record to add.
19114 * This routine is invoked to manually add a single FCF record. The caller
19115 * must pass a completely initialized FCF_Record. This routine takes
19116 * care of the nonembedded mailbox operations.
19119 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
19122 LPFC_MBOXQ_t *mboxq;
19125 struct lpfc_mbx_sge sge;
19126 uint32_t alloc_len, req_len;
19129 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19131 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19132 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
19136 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
19139 /* Allocate DMA memory and set up the non-embedded mailbox command */
19140 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
19141 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
19142 req_len, LPFC_SLI4_MBX_NEMBED);
19143 if (alloc_len < req_len) {
19144 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19145 "2523 Allocated DMA memory size (x%x) is "
19146 "less than the requested DMA memory "
19147 "size (x%x)\n", alloc_len, req_len);
19148 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19153 * Get the first SGE entry from the non-embedded DMA memory. This
19154 * routine only uses a single SGE.
19156 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
19157 virt_addr = mboxq->sge_array->addr[0];
19159 * Configure the FCF record for FCFI 0. This is the driver's
19160 * hardcoded default and gets used in nonFIP mode.
19162 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
19163 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
19164 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
19167 * Copy the fcf_index and the FCF Record Data. The data starts after
19168 * the FCoE header plus word10. The data copy needs to be endian
19171 bytep += sizeof(uint32_t);
19172 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
19173 mboxq->vport = phba->pport;
19174 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
19175 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19176 if (rc == MBX_NOT_FINISHED) {
19177 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19178 "2515 ADD_FCF_RECORD mailbox failed with "
19179 "status 0x%x\n", rc);
19180 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19189 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
19190 * @phba: pointer to lpfc hba data structure.
19191 * @fcf_record: pointer to the fcf record to write the default data.
19192 * @fcf_index: FCF table entry index.
19194 * This routine is invoked to build the driver's default FCF record. The
19195 * values used are hardcoded. This routine handles memory initialization.
19199 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
19200 struct fcf_record *fcf_record,
19201 uint16_t fcf_index)
19203 memset(fcf_record, 0, sizeof(struct fcf_record));
19204 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
19205 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
19206 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
19207 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
19208 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
19209 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
19210 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
19211 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
19212 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
19213 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
19214 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
19215 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
19216 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
19217 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
19218 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
19219 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
19220 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
19221 /* Set the VLAN bit map */
19222 if (phba->valid_vlan) {
19223 fcf_record->vlan_bitmap[phba->vlan_id / 8]
19224 = 1 << (phba->vlan_id % 8);
19229 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
19230 * @phba: pointer to lpfc hba data structure.
19231 * @fcf_index: FCF table entry offset.
19233 * This routine is invoked to scan the entire FCF table by reading FCF
19234 * record and processing it one at a time starting from the @fcf_index
19235 * for initial FCF discovery or fast FCF failover rediscovery.
19237 * Return 0 if the mailbox command is submitted successfully, none 0
19241 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
19244 LPFC_MBOXQ_t *mboxq;
19246 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
19247 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
19248 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19250 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19251 "2000 Failed to allocate mbox for "
19254 goto fail_fcf_scan;
19256 /* Construct the read FCF record mailbox command */
19257 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
19260 goto fail_fcf_scan;
19262 /* Issue the mailbox command asynchronously */
19263 mboxq->vport = phba->pport;
19264 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
19266 spin_lock_irq(&phba->hbalock);
19267 phba->hba_flag |= FCF_TS_INPROG;
19268 spin_unlock_irq(&phba->hbalock);
19270 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19271 if (rc == MBX_NOT_FINISHED)
19274 /* Reset eligible FCF count for new scan */
19275 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
19276 phba->fcf.eligible_fcf_cnt = 0;
19282 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19283 /* FCF scan failed, clear FCF_TS_INPROG flag */
19284 spin_lock_irq(&phba->hbalock);
19285 phba->hba_flag &= ~FCF_TS_INPROG;
19286 spin_unlock_irq(&phba->hbalock);
19292 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
19293 * @phba: pointer to lpfc hba data structure.
19294 * @fcf_index: FCF table entry offset.
19296 * This routine is invoked to read an FCF record indicated by @fcf_index
19297 * and to use it for FLOGI roundrobin FCF failover.
19299 * Return 0 if the mailbox command is submitted successfully, none 0
19303 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
19306 LPFC_MBOXQ_t *mboxq;
19308 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19310 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
19311 "2763 Failed to allocate mbox for "
19314 goto fail_fcf_read;
19316 /* Construct the read FCF record mailbox command */
19317 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
19320 goto fail_fcf_read;
19322 /* Issue the mailbox command asynchronously */
19323 mboxq->vport = phba->pport;
19324 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
19325 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19326 if (rc == MBX_NOT_FINISHED)
19332 if (error && mboxq)
19333 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19338 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
19339 * @phba: pointer to lpfc hba data structure.
19340 * @fcf_index: FCF table entry offset.
19342 * This routine is invoked to read an FCF record indicated by @fcf_index to
19343 * determine whether it's eligible for FLOGI roundrobin failover list.
19345 * Return 0 if the mailbox command is submitted successfully, none 0
19349 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
19352 LPFC_MBOXQ_t *mboxq;
19354 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19356 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
19357 "2758 Failed to allocate mbox for "
19360 goto fail_fcf_read;
19362 /* Construct the read FCF record mailbox command */
19363 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
19366 goto fail_fcf_read;
19368 /* Issue the mailbox command asynchronously */
19369 mboxq->vport = phba->pport;
19370 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
19371 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19372 if (rc == MBX_NOT_FINISHED)
19378 if (error && mboxq)
19379 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19384 * lpfc_check_next_fcf_pri_level
19385 * @phba: pointer to the lpfc_hba struct for this port.
19386 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
19387 * routine when the rr_bmask is empty. The FCF indecies are put into the
19388 * rr_bmask based on their priority level. Starting from the highest priority
19389 * to the lowest. The most likely FCF candidate will be in the highest
19390 * priority group. When this routine is called it searches the fcf_pri list for
19391 * next lowest priority group and repopulates the rr_bmask with only those
19394 * 1=success 0=failure
19397 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
19399 uint16_t next_fcf_pri;
19400 uint16_t last_index;
19401 struct lpfc_fcf_pri *fcf_pri;
19405 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
19406 LPFC_SLI4_FCF_TBL_INDX_MAX);
19407 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19408 "3060 Last IDX %d\n", last_index);
19410 /* Verify the priority list has 2 or more entries */
19411 spin_lock_irq(&phba->hbalock);
19412 if (list_empty(&phba->fcf.fcf_pri_list) ||
19413 list_is_singular(&phba->fcf.fcf_pri_list)) {
19414 spin_unlock_irq(&phba->hbalock);
19415 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19416 "3061 Last IDX %d\n", last_index);
19417 return 0; /* Empty rr list */
19419 spin_unlock_irq(&phba->hbalock);
19423 * Clear the rr_bmask and set all of the bits that are at this
19426 memset(phba->fcf.fcf_rr_bmask, 0,
19427 sizeof(*phba->fcf.fcf_rr_bmask));
19428 spin_lock_irq(&phba->hbalock);
19429 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
19430 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
19433 * the 1st priority that has not FLOGI failed
19434 * will be the highest.
19437 next_fcf_pri = fcf_pri->fcf_rec.priority;
19438 spin_unlock_irq(&phba->hbalock);
19439 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
19440 rc = lpfc_sli4_fcf_rr_index_set(phba,
19441 fcf_pri->fcf_rec.fcf_index);
19445 spin_lock_irq(&phba->hbalock);
19448 * if next_fcf_pri was not set above and the list is not empty then
19449 * we have failed flogis on all of them. So reset flogi failed
19450 * and start at the beginning.
19452 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
19453 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
19454 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
19456 * the 1st priority that has not FLOGI failed
19457 * will be the highest.
19460 next_fcf_pri = fcf_pri->fcf_rec.priority;
19461 spin_unlock_irq(&phba->hbalock);
19462 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
19463 rc = lpfc_sli4_fcf_rr_index_set(phba,
19464 fcf_pri->fcf_rec.fcf_index);
19468 spin_lock_irq(&phba->hbalock);
19472 spin_unlock_irq(&phba->hbalock);
19477 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
19478 * @phba: pointer to lpfc hba data structure.
19480 * This routine is to get the next eligible FCF record index in a round
19481 * robin fashion. If the next eligible FCF record index equals to the
19482 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
19483 * shall be returned, otherwise, the next eligible FCF record's index
19484 * shall be returned.
19487 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
19489 uint16_t next_fcf_index;
19492 /* Search start from next bit of currently registered FCF index */
19493 next_fcf_index = phba->fcf.current_rec.fcf_indx;
19496 /* Determine the next fcf index to check */
19497 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
19498 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
19499 LPFC_SLI4_FCF_TBL_INDX_MAX,
19502 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
19503 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
19505 * If we have wrapped then we need to clear the bits that
19506 * have been tested so that we can detect when we should
19507 * change the priority level.
19509 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
19510 LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
19514 /* Check roundrobin failover list empty condition */
19515 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
19516 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
19518 * If next fcf index is not found check if there are lower
19519 * Priority level fcf's in the fcf_priority list.
19520 * Set up the rr_bmask with all of the avaiable fcf bits
19521 * at that level and continue the selection process.
19523 if (lpfc_check_next_fcf_pri_level(phba))
19524 goto initial_priority;
19525 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
19526 "2844 No roundrobin failover FCF available\n");
19528 return LPFC_FCOE_FCF_NEXT_NONE;
19531 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
19532 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
19533 LPFC_FCF_FLOGI_FAILED) {
19534 if (list_is_singular(&phba->fcf.fcf_pri_list))
19535 return LPFC_FCOE_FCF_NEXT_NONE;
19537 goto next_priority;
19540 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19541 "2845 Get next roundrobin failover FCF (x%x)\n",
19544 return next_fcf_index;
19548 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
19549 * @phba: pointer to lpfc hba data structure.
19550 * @fcf_index: index into the FCF table to 'set'
19552 * This routine sets the FCF record index in to the eligible bmask for
19553 * roundrobin failover search. It checks to make sure that the index
19554 * does not go beyond the range of the driver allocated bmask dimension
19555 * before setting the bit.
19557 * Returns 0 if the index bit successfully set, otherwise, it returns
19561 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
19563 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
19564 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19565 "2610 FCF (x%x) reached driver's book "
19566 "keeping dimension:x%x\n",
19567 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
19570 /* Set the eligible FCF record index bmask */
19571 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
19573 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19574 "2790 Set FCF (x%x) to roundrobin FCF failover "
19575 "bmask\n", fcf_index);
19581 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
19582 * @phba: pointer to lpfc hba data structure.
19583 * @fcf_index: index into the FCF table to 'clear'
19585 * This routine clears the FCF record index from the eligible bmask for
19586 * roundrobin failover search. It checks to make sure that the index
19587 * does not go beyond the range of the driver allocated bmask dimension
19588 * before clearing the bit.
19591 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
19593 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
19594 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
19595 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19596 "2762 FCF (x%x) reached driver's book "
19597 "keeping dimension:x%x\n",
19598 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
19601 /* Clear the eligible FCF record index bmask */
19602 spin_lock_irq(&phba->hbalock);
19603 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
19605 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
19606 list_del_init(&fcf_pri->list);
19610 spin_unlock_irq(&phba->hbalock);
19611 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
19613 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19614 "2791 Clear FCF (x%x) from roundrobin failover "
19615 "bmask\n", fcf_index);
19619 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
19620 * @phba: pointer to lpfc hba data structure.
19621 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
19623 * This routine is the completion routine for the rediscover FCF table mailbox
19624 * command. If the mailbox command returned failure, it will try to stop the
19625 * FCF rediscover wait timer.
19628 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
19630 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
19631 uint32_t shdr_status, shdr_add_status;
19633 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
19635 shdr_status = bf_get(lpfc_mbox_hdr_status,
19636 &redisc_fcf->header.cfg_shdr.response);
19637 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
19638 &redisc_fcf->header.cfg_shdr.response);
19639 if (shdr_status || shdr_add_status) {
19640 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
19641 "2746 Requesting for FCF rediscovery failed "
19642 "status x%x add_status x%x\n",
19643 shdr_status, shdr_add_status);
19644 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
19645 spin_lock_irq(&phba->hbalock);
19646 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
19647 spin_unlock_irq(&phba->hbalock);
19649 * CVL event triggered FCF rediscover request failed,
19650 * last resort to re-try current registered FCF entry.
19652 lpfc_retry_pport_discovery(phba);
19654 spin_lock_irq(&phba->hbalock);
19655 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
19656 spin_unlock_irq(&phba->hbalock);
19658 * DEAD FCF event triggered FCF rediscover request
19659 * failed, last resort to fail over as a link down
19660 * to FCF registration.
19662 lpfc_sli4_fcf_dead_failthrough(phba);
19665 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
19666 "2775 Start FCF rediscover quiescent timer\n");
19668 * Start FCF rediscovery wait timer for pending FCF
19669 * before rescan FCF record table.
19671 lpfc_fcf_redisc_wait_start_timer(phba);
19674 mempool_free(mbox, phba->mbox_mem_pool);
19678 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
19679 * @phba: pointer to lpfc hba data structure.
19681 * This routine is invoked to request for rediscovery of the entire FCF table
19685 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
19687 LPFC_MBOXQ_t *mbox;
19688 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
19691 /* Cancel retry delay timers to all vports before FCF rediscover */
19692 lpfc_cancel_all_vport_retry_delay_timer(phba);
19694 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19696 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19697 "2745 Failed to allocate mbox for "
19698 "requesting FCF rediscover.\n");
19702 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
19703 sizeof(struct lpfc_sli4_cfg_mhdr));
19704 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
19705 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
19706 length, LPFC_SLI4_MBX_EMBED);
19708 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
19709 /* Set count to 0 for invalidating the entire FCF database */
19710 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
19712 /* Issue the mailbox command asynchronously */
19713 mbox->vport = phba->pport;
19714 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
19715 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
19717 if (rc == MBX_NOT_FINISHED) {
19718 mempool_free(mbox, phba->mbox_mem_pool);
19725 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
19726 * @phba: pointer to lpfc hba data structure.
19728 * This function is the failover routine as a last resort to the FCF DEAD
19729 * event when driver failed to perform fast FCF failover.
19732 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
19734 uint32_t link_state;
19737 * Last resort as FCF DEAD event failover will treat this as
19738 * a link down, but save the link state because we don't want
19739 * it to be changed to Link Down unless it is already down.
19741 link_state = phba->link_state;
19742 lpfc_linkdown(phba);
19743 phba->link_state = link_state;
19745 /* Unregister FCF if no devices connected to it */
19746 lpfc_unregister_unused_fcf(phba);
19750 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
19751 * @phba: pointer to lpfc hba data structure.
19752 * @rgn23_data: pointer to configure region 23 data.
19754 * This function gets SLI3 port configure region 23 data through memory dump
19755 * mailbox command. When it successfully retrieves data, the size of the data
19756 * will be returned, otherwise, 0 will be returned.
19759 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
19761 LPFC_MBOXQ_t *pmb = NULL;
19763 uint32_t offset = 0;
19769 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19771 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19772 "2600 failed to allocate mailbox memory\n");
19778 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
19779 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
19781 if (rc != MBX_SUCCESS) {
19782 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
19783 "2601 failed to read config "
19784 "region 23, rc 0x%x Status 0x%x\n",
19785 rc, mb->mbxStatus);
19786 mb->un.varDmp.word_cnt = 0;
19789 * dump mem may return a zero when finished or we got a
19790 * mailbox error, either way we are done.
19792 if (mb->un.varDmp.word_cnt == 0)
19795 i = mb->un.varDmp.word_cnt * sizeof(uint32_t);
19796 if (offset + i > DMP_RGN23_SIZE)
19797 i = DMP_RGN23_SIZE - offset;
19798 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
19799 rgn23_data + offset, i);
19801 } while (offset < DMP_RGN23_SIZE);
19803 mempool_free(pmb, phba->mbox_mem_pool);
19808 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
19809 * @phba: pointer to lpfc hba data structure.
19810 * @rgn23_data: pointer to configure region 23 data.
19812 * This function gets SLI4 port configure region 23 data through memory dump
19813 * mailbox command. When it successfully retrieves data, the size of the data
19814 * will be returned, otherwise, 0 will be returned.
19817 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
19819 LPFC_MBOXQ_t *mboxq = NULL;
19820 struct lpfc_dmabuf *mp = NULL;
19821 struct lpfc_mqe *mqe;
19822 uint32_t data_length = 0;
19828 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19830 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19831 "3105 failed to allocate mailbox memory\n");
19835 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
19837 mqe = &mboxq->u.mqe;
19838 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
19839 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
19842 data_length = mqe->un.mb_words[5];
19843 if (data_length == 0)
19845 if (data_length > DMP_RGN23_SIZE) {
19849 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
19851 mempool_free(mboxq, phba->mbox_mem_pool);
19853 lpfc_mbuf_free(phba, mp->virt, mp->phys);
19856 return data_length;
19860 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
19861 * @phba: pointer to lpfc hba data structure.
19863 * This function read region 23 and parse TLV for port status to
19864 * decide if the user disaled the port. If the TLV indicates the
19865 * port is disabled, the hba_flag is set accordingly.
19868 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
19870 uint8_t *rgn23_data = NULL;
19871 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
19872 uint32_t offset = 0;
19874 /* Get adapter Region 23 data */
19875 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
19879 if (phba->sli_rev < LPFC_SLI_REV4)
19880 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
19882 if_type = bf_get(lpfc_sli_intf_if_type,
19883 &phba->sli4_hba.sli_intf);
19884 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
19886 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
19892 /* Check the region signature first */
19893 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
19894 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19895 "2619 Config region 23 has bad signature\n");
19900 /* Check the data structure version */
19901 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
19902 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19903 "2620 Config region 23 has bad version\n");
19908 /* Parse TLV entries in the region */
19909 while (offset < data_size) {
19910 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
19913 * If the TLV is not driver specific TLV or driver id is
19914 * not linux driver id, skip the record.
19916 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
19917 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
19918 (rgn23_data[offset + 3] != 0)) {
19919 offset += rgn23_data[offset + 1] * 4 + 4;
19923 /* Driver found a driver specific TLV in the config region */
19924 sub_tlv_len = rgn23_data[offset + 1] * 4;
19929 * Search for configured port state sub-TLV.
19931 while ((offset < data_size) &&
19932 (tlv_offset < sub_tlv_len)) {
19933 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
19938 if (rgn23_data[offset] != PORT_STE_TYPE) {
19939 offset += rgn23_data[offset + 1] * 4 + 4;
19940 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
19944 /* This HBA contains PORT_STE configured */
19945 if (!rgn23_data[offset + 2])
19946 phba->hba_flag |= LINK_DISABLED;
19958 * lpfc_wr_object - write an object to the firmware
19959 * @phba: HBA structure that indicates port to create a queue on.
19960 * @dmabuf_list: list of dmabufs to write to the port.
19961 * @size: the total byte value of the objects to write to the port.
19962 * @offset: the current offset to be used to start the transfer.
19964 * This routine will create a wr_object mailbox command to send to the port.
19965 * the mailbox command will be constructed using the dma buffers described in
19966 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
19967 * BDEs that the imbedded mailbox can support. The @offset variable will be
19968 * used to indicate the starting offset of the transfer and will also return
19969 * the offset after the write object mailbox has completed. @size is used to
19970 * determine the end of the object and whether the eof bit should be set.
19972 * Return 0 is successful and offset will contain the the new offset to use
19973 * for the next write.
19974 * Return negative value for error cases.
19977 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
19978 uint32_t size, uint32_t *offset)
19980 struct lpfc_mbx_wr_object *wr_object;
19981 LPFC_MBOXQ_t *mbox;
19983 uint32_t shdr_status, shdr_add_status, shdr_change_status, shdr_csf;
19985 struct lpfc_dmabuf *dmabuf;
19986 uint32_t written = 0;
19987 bool check_change_status = false;
19989 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19993 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
19994 LPFC_MBOX_OPCODE_WRITE_OBJECT,
19995 sizeof(struct lpfc_mbx_wr_object) -
19996 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
19998 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
19999 wr_object->u.request.write_offset = *offset;
20000 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
20001 wr_object->u.request.object_name[0] =
20002 cpu_to_le32(wr_object->u.request.object_name[0]);
20003 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
20004 list_for_each_entry(dmabuf, dmabuf_list, list) {
20005 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
20007 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
20008 wr_object->u.request.bde[i].addrHigh =
20009 putPaddrHigh(dmabuf->phys);
20010 if (written + SLI4_PAGE_SIZE >= size) {
20011 wr_object->u.request.bde[i].tus.f.bdeSize =
20013 written += (size - written);
20014 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
20015 bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
20016 check_change_status = true;
20018 wr_object->u.request.bde[i].tus.f.bdeSize =
20020 written += SLI4_PAGE_SIZE;
20024 wr_object->u.request.bde_count = i;
20025 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
20026 if (!phba->sli4_hba.intr_enable)
20027 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
20029 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
20030 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
20032 /* The IOCTL status is embedded in the mailbox subheader. */
20033 shdr_status = bf_get(lpfc_mbox_hdr_status,
20034 &wr_object->header.cfg_shdr.response);
20035 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
20036 &wr_object->header.cfg_shdr.response);
20037 if (check_change_status) {
20038 shdr_change_status = bf_get(lpfc_wr_object_change_status,
20039 &wr_object->u.response);
20041 if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET ||
20042 shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) {
20043 shdr_csf = bf_get(lpfc_wr_object_csf,
20044 &wr_object->u.response);
20046 shdr_change_status =
20047 LPFC_CHANGE_STATUS_PCI_RESET;
20050 switch (shdr_change_status) {
20051 case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
20052 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
20053 "3198 Firmware write complete: System "
20054 "reboot required to instantiate\n");
20056 case (LPFC_CHANGE_STATUS_FW_RESET):
20057 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
20058 "3199 Firmware write complete: Firmware"
20059 " reset required to instantiate\n");
20061 case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
20062 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
20063 "3200 Firmware write complete: Port "
20064 "Migration or PCI Reset required to "
20067 case (LPFC_CHANGE_STATUS_PCI_RESET):
20068 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
20069 "3201 Firmware write complete: PCI "
20070 "Reset required to instantiate\n");
20076 if (rc != MBX_TIMEOUT)
20077 mempool_free(mbox, phba->mbox_mem_pool);
20078 if (shdr_status || shdr_add_status || rc) {
20079 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20080 "3025 Write Object mailbox failed with "
20081 "status x%x add_status x%x, mbx status x%x\n",
20082 shdr_status, shdr_add_status, rc);
20084 *offset = shdr_add_status;
20086 *offset += wr_object->u.response.actual_write_length;
20091 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
20092 * @vport: pointer to vport data structure.
20094 * This function iterate through the mailboxq and clean up all REG_LOGIN
20095 * and REG_VPI mailbox commands associated with the vport. This function
20096 * is called when driver want to restart discovery of the vport due to
20097 * a Clear Virtual Link event.
20100 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
20102 struct lpfc_hba *phba = vport->phba;
20103 LPFC_MBOXQ_t *mb, *nextmb;
20104 struct lpfc_dmabuf *mp;
20105 struct lpfc_nodelist *ndlp;
20106 struct lpfc_nodelist *act_mbx_ndlp = NULL;
20107 LIST_HEAD(mbox_cmd_list);
20108 uint8_t restart_loop;
20110 /* Clean up internally queued mailbox commands with the vport */
20111 spin_lock_irq(&phba->hbalock);
20112 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
20113 if (mb->vport != vport)
20116 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
20117 (mb->u.mb.mbxCommand != MBX_REG_VPI))
20120 list_del(&mb->list);
20121 list_add_tail(&mb->list, &mbox_cmd_list);
20123 /* Clean up active mailbox command with the vport */
20124 mb = phba->sli.mbox_active;
20125 if (mb && (mb->vport == vport)) {
20126 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
20127 (mb->u.mb.mbxCommand == MBX_REG_VPI))
20128 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
20129 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
20130 act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
20131 /* Put reference count for delayed processing */
20132 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
20133 /* Unregister the RPI when mailbox complete */
20134 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
20137 /* Cleanup any mailbox completions which are not yet processed */
20140 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
20142 * If this mailox is already processed or it is
20143 * for another vport ignore it.
20145 if ((mb->vport != vport) ||
20146 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
20149 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
20150 (mb->u.mb.mbxCommand != MBX_REG_VPI))
20153 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
20154 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
20155 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
20156 /* Unregister the RPI when mailbox complete */
20157 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
20159 spin_unlock_irq(&phba->hbalock);
20160 spin_lock(&ndlp->lock);
20161 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
20162 spin_unlock(&ndlp->lock);
20163 spin_lock_irq(&phba->hbalock);
20167 } while (restart_loop);
20169 spin_unlock_irq(&phba->hbalock);
20171 /* Release the cleaned-up mailbox commands */
20172 while (!list_empty(&mbox_cmd_list)) {
20173 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
20174 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
20175 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
20177 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
20180 mb->ctx_buf = NULL;
20181 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
20182 mb->ctx_ndlp = NULL;
20184 spin_lock(&ndlp->lock);
20185 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
20186 spin_unlock(&ndlp->lock);
20187 lpfc_nlp_put(ndlp);
20190 mempool_free(mb, phba->mbox_mem_pool);
20193 /* Release the ndlp with the cleaned-up active mailbox command */
20194 if (act_mbx_ndlp) {
20195 spin_lock(&act_mbx_ndlp->lock);
20196 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
20197 spin_unlock(&act_mbx_ndlp->lock);
20198 lpfc_nlp_put(act_mbx_ndlp);
20203 * lpfc_drain_txq - Drain the txq
20204 * @phba: Pointer to HBA context object.
20206 * This function attempt to submit IOCBs on the txq
20207 * to the adapter. For SLI4 adapters, the txq contains
20208 * ELS IOCBs that have been deferred because the there
20209 * are no SGLs. This congestion can occur with large
20210 * vport counts during node discovery.
20214 lpfc_drain_txq(struct lpfc_hba *phba)
20216 LIST_HEAD(completions);
20217 struct lpfc_sli_ring *pring;
20218 struct lpfc_iocbq *piocbq = NULL;
20219 unsigned long iflags = 0;
20220 char *fail_msg = NULL;
20221 struct lpfc_sglq *sglq;
20222 union lpfc_wqe128 wqe;
20223 uint32_t txq_cnt = 0;
20224 struct lpfc_queue *wq;
20226 if (phba->link_flag & LS_MDS_LOOPBACK) {
20227 /* MDS WQE are posted only to first WQ*/
20228 wq = phba->sli4_hba.hdwq[0].io_wq;
20233 wq = phba->sli4_hba.els_wq;
20236 pring = lpfc_phba_elsring(phba);
20239 if (unlikely(!pring) || list_empty(&pring->txq))
20242 spin_lock_irqsave(&pring->ring_lock, iflags);
20243 list_for_each_entry(piocbq, &pring->txq, list) {
20247 if (txq_cnt > pring->txq_max)
20248 pring->txq_max = txq_cnt;
20250 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20252 while (!list_empty(&pring->txq)) {
20253 spin_lock_irqsave(&pring->ring_lock, iflags);
20255 piocbq = lpfc_sli_ringtx_get(phba, pring);
20257 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20258 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20259 "2823 txq empty and txq_cnt is %d\n ",
20263 sglq = __lpfc_sli_get_els_sglq(phba, piocbq);
20265 __lpfc_sli_ringtx_put(phba, pring, piocbq);
20266 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20271 /* The xri and iocb resources secured,
20272 * attempt to issue request
20274 piocbq->sli4_lxritag = sglq->sli4_lxritag;
20275 piocbq->sli4_xritag = sglq->sli4_xritag;
20276 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
20277 fail_msg = "to convert bpl to sgl";
20278 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
20279 fail_msg = "to convert iocb to wqe";
20280 else if (lpfc_sli4_wq_put(wq, &wqe))
20281 fail_msg = " - Wq is full";
20283 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
20286 /* Failed means we can't issue and need to cancel */
20287 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20288 "2822 IOCB failed %s iotag 0x%x "
20291 piocbq->iotag, piocbq->sli4_xritag);
20292 list_add_tail(&piocbq->list, &completions);
20294 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20297 /* Cancel all the IOCBs that cannot be issued */
20298 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
20299 IOERR_SLI_ABORTED);
20305 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
20306 * @phba: Pointer to HBA context object.
20307 * @pwqeq: Pointer to command WQE.
20308 * @sglq: Pointer to the scatter gather queue object.
20310 * This routine converts the bpl or bde that is in the WQE
20311 * to a sgl list for the sli4 hardware. The physical address
20312 * of the bpl/bde is converted back to a virtual address.
20313 * If the WQE contains a BPL then the list of BDE's is
20314 * converted to sli4_sge's. If the WQE contains a single
20315 * BDE then it is converted to a single sli_sge.
20316 * The WQE is still in cpu endianness so the contents of
20317 * the bpl can be used without byte swapping.
20319 * Returns valid XRI = Success, NO_XRI = Failure.
20322 lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
20323 struct lpfc_sglq *sglq)
20325 uint16_t xritag = NO_XRI;
20326 struct ulp_bde64 *bpl = NULL;
20327 struct ulp_bde64 bde;
20328 struct sli4_sge *sgl = NULL;
20329 struct lpfc_dmabuf *dmabuf;
20330 union lpfc_wqe128 *wqe;
20333 uint32_t offset = 0; /* accumulated offset in the sg request list */
20334 int inbound = 0; /* number of sg reply entries inbound from firmware */
20337 if (!pwqeq || !sglq)
20340 sgl = (struct sli4_sge *)sglq->sgl;
20342 pwqeq->iocb.ulpIoTag = pwqeq->iotag;
20344 cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
20345 if (cmd == CMD_XMIT_BLS_RSP64_WQE)
20346 return sglq->sli4_xritag;
20347 numBdes = pwqeq->rsvd2;
20349 /* The addrHigh and addrLow fields within the WQE
20350 * have not been byteswapped yet so there is no
20351 * need to swap them back.
20353 if (pwqeq->context3)
20354 dmabuf = (struct lpfc_dmabuf *)pwqeq->context3;
20358 bpl = (struct ulp_bde64 *)dmabuf->virt;
20362 for (i = 0; i < numBdes; i++) {
20363 /* Should already be byte swapped. */
20364 sgl->addr_hi = bpl->addrHigh;
20365 sgl->addr_lo = bpl->addrLow;
20367 sgl->word2 = le32_to_cpu(sgl->word2);
20368 if ((i+1) == numBdes)
20369 bf_set(lpfc_sli4_sge_last, sgl, 1);
20371 bf_set(lpfc_sli4_sge_last, sgl, 0);
20372 /* swap the size field back to the cpu so we
20373 * can assign it to the sgl.
20375 bde.tus.w = le32_to_cpu(bpl->tus.w);
20376 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
20377 /* The offsets in the sgl need to be accumulated
20378 * separately for the request and reply lists.
20379 * The request is always first, the reply follows.
20382 case CMD_GEN_REQUEST64_WQE:
20383 /* add up the reply sg entries */
20384 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
20386 /* first inbound? reset the offset */
20389 bf_set(lpfc_sli4_sge_offset, sgl, offset);
20390 bf_set(lpfc_sli4_sge_type, sgl,
20391 LPFC_SGE_TYPE_DATA);
20392 offset += bde.tus.f.bdeSize;
20394 case CMD_FCP_TRSP64_WQE:
20395 bf_set(lpfc_sli4_sge_offset, sgl, 0);
20396 bf_set(lpfc_sli4_sge_type, sgl,
20397 LPFC_SGE_TYPE_DATA);
20399 case CMD_FCP_TSEND64_WQE:
20400 case CMD_FCP_TRECEIVE64_WQE:
20401 bf_set(lpfc_sli4_sge_type, sgl,
20402 bpl->tus.f.bdeFlags);
20406 offset += bde.tus.f.bdeSize;
20407 bf_set(lpfc_sli4_sge_offset, sgl, offset);
20410 sgl->word2 = cpu_to_le32(sgl->word2);
20414 } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
20415 /* The addrHigh and addrLow fields of the BDE have not
20416 * been byteswapped yet so they need to be swapped
20417 * before putting them in the sgl.
20419 sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
20420 sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
20421 sgl->word2 = le32_to_cpu(sgl->word2);
20422 bf_set(lpfc_sli4_sge_last, sgl, 1);
20423 sgl->word2 = cpu_to_le32(sgl->word2);
20424 sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
20426 return sglq->sli4_xritag;
20430 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
20431 * @phba: Pointer to HBA context object.
20432 * @qp: Pointer to HDW queue.
20433 * @pwqe: Pointer to command WQE.
20436 lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
20437 struct lpfc_iocbq *pwqe)
20439 union lpfc_wqe128 *wqe = &pwqe->wqe;
20440 struct lpfc_async_xchg_ctx *ctxp;
20441 struct lpfc_queue *wq;
20442 struct lpfc_sglq *sglq;
20443 struct lpfc_sli_ring *pring;
20444 unsigned long iflags;
20447 /* NVME_LS and NVME_LS ABTS requests. */
20448 if (pwqe->iocb_flag & LPFC_IO_NVME_LS) {
20449 pring = phba->sli4_hba.nvmels_wq->pring;
20450 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
20452 sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
20454 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20457 pwqe->sli4_lxritag = sglq->sli4_lxritag;
20458 pwqe->sli4_xritag = sglq->sli4_xritag;
20459 if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
20460 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20463 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
20464 pwqe->sli4_xritag);
20465 ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
20467 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20471 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
20472 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20474 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
20478 /* NVME_FCREQ and NVME_ABTS requests */
20479 if (pwqe->iocb_flag & LPFC_IO_NVME ||
20480 pwqe->iocb_flag & LPFC_IO_FCP) {
20481 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
20485 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
20487 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
20489 ret = lpfc_sli4_wq_put(wq, wqe);
20491 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20494 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
20495 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20497 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
20501 /* NVMET requests */
20502 if (pwqe->iocb_flag & LPFC_IO_NVMET) {
20503 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
20507 ctxp = pwqe->context2;
20508 sglq = ctxp->ctxbuf->sglq;
20509 if (pwqe->sli4_xritag == NO_XRI) {
20510 pwqe->sli4_lxritag = sglq->sli4_lxritag;
20511 pwqe->sli4_xritag = sglq->sli4_xritag;
20513 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
20514 pwqe->sli4_xritag);
20515 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
20517 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
20519 ret = lpfc_sli4_wq_put(wq, wqe);
20521 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20524 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
20525 spin_unlock_irqrestore(&pring->ring_lock, iflags);
20527 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
20534 * lpfc_sli4_issue_abort_iotag - SLI-4 WQE init & issue for the Abort
20535 * @phba: Pointer to HBA context object.
20536 * @cmdiocb: Pointer to driver command iocb object.
20537 * @cmpl: completion function.
20539 * Fill the appropriate fields for the abort WQE and call
20540 * internal routine lpfc_sli4_issue_wqe to send the WQE
20541 * This function is called with hbalock held and no ring_lock held.
20543 * RETURNS 0 - SUCCESS
20547 lpfc_sli4_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
20550 struct lpfc_vport *vport = cmdiocb->vport;
20551 struct lpfc_iocbq *abtsiocb = NULL;
20552 union lpfc_wqe128 *abtswqe;
20553 struct lpfc_io_buf *lpfc_cmd;
20554 int retval = IOCB_ERROR;
20555 u16 xritag = cmdiocb->sli4_xritag;
20558 * The scsi command can not be in txq and it is in flight because the
20559 * pCmd is still pointing at the SCSI command we have to abort. There
20560 * is no need to search the txcmplq. Just send an abort to the FW.
20563 abtsiocb = __lpfc_sli_get_iocbq(phba);
20565 return WQE_NORESOURCE;
20567 /* Indicate the IO is being aborted by the driver. */
20568 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
20570 abtswqe = &abtsiocb->wqe;
20571 memset(abtswqe, 0, sizeof(*abtswqe));
20573 if (lpfc_is_link_up(phba))
20574 bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 1);
20576 bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 0);
20577 bf_set(abort_cmd_criteria, &abtswqe->abort_cmd, T_XRI_TAG);
20578 abtswqe->abort_cmd.rsrvd5 = 0;
20579 abtswqe->abort_cmd.wqe_com.abort_tag = xritag;
20580 bf_set(wqe_reqtag, &abtswqe->abort_cmd.wqe_com, abtsiocb->iotag);
20581 bf_set(wqe_cmnd, &abtswqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
20582 bf_set(wqe_xri_tag, &abtswqe->generic.wqe_com, 0);
20583 bf_set(wqe_qosd, &abtswqe->abort_cmd.wqe_com, 1);
20584 bf_set(wqe_lenloc, &abtswqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
20585 bf_set(wqe_cmd_type, &abtswqe->abort_cmd.wqe_com, OTHER_COMMAND);
20587 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
20588 abtsiocb->hba_wqidx = cmdiocb->hba_wqidx;
20589 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
20590 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
20591 abtsiocb->iocb_flag |= LPFC_IO_FCP;
20592 if (cmdiocb->iocb_flag & LPFC_IO_NVME)
20593 abtsiocb->iocb_flag |= LPFC_IO_NVME;
20594 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
20595 abtsiocb->iocb_flag |= LPFC_IO_FOF;
20596 abtsiocb->vport = vport;
20597 abtsiocb->wqe_cmpl = cmpl;
20599 lpfc_cmd = container_of(cmdiocb, struct lpfc_io_buf, cur_iocbq);
20600 retval = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, abtsiocb);
20602 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
20603 "0359 Abort xri x%x, original iotag x%x, "
20604 "abort cmd iotag x%x retval x%x\n",
20605 xritag, cmdiocb->iotag, abtsiocb->iotag, retval);
20608 cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
20609 __lpfc_sli_release_iocbq(phba, abtsiocb);
20615 #ifdef LPFC_MXP_STAT
20617 * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
20618 * @phba: pointer to lpfc hba data structure.
20619 * @hwqid: belong to which HWQ.
20621 * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
20622 * 15 seconds after a test case is running.
20624 * The user should call lpfc_debugfs_multixripools_write before running a test
20625 * case to clear stat_snapshot_taken. Then the user starts a test case. During
20626 * test case is running, stat_snapshot_taken is incremented by 1 every time when
20627 * this routine is called from heartbeat timer. When stat_snapshot_taken is
20628 * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
20630 void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
20632 struct lpfc_sli4_hdw_queue *qp;
20633 struct lpfc_multixri_pool *multixri_pool;
20634 struct lpfc_pvt_pool *pvt_pool;
20635 struct lpfc_pbl_pool *pbl_pool;
20638 qp = &phba->sli4_hba.hdwq[hwqid];
20639 multixri_pool = qp->p_multixri_pool;
20640 if (!multixri_pool)
20643 if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
20644 pvt_pool = &qp->p_multixri_pool->pvt_pool;
20645 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20646 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
20648 multixri_pool->stat_pbl_count = pbl_pool->count;
20649 multixri_pool->stat_pvt_count = pvt_pool->count;
20650 multixri_pool->stat_busy_count = txcmplq_cnt;
20653 multixri_pool->stat_snapshot_taken++;
20658 * lpfc_adjust_pvt_pool_count - Adjust private pool count
20659 * @phba: pointer to lpfc hba data structure.
20660 * @hwqid: belong to which HWQ.
20662 * This routine moves some XRIs from private to public pool when private pool
20665 void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
20667 struct lpfc_multixri_pool *multixri_pool;
20669 u32 prev_io_req_count;
20671 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
20672 if (!multixri_pool)
20674 io_req_count = multixri_pool->io_req_count;
20675 prev_io_req_count = multixri_pool->prev_io_req_count;
20677 if (prev_io_req_count != io_req_count) {
20678 /* Private pool is busy */
20679 multixri_pool->prev_io_req_count = io_req_count;
20681 /* Private pool is not busy.
20682 * Move XRIs from private to public pool.
20684 lpfc_move_xri_pvt_to_pbl(phba, hwqid);
20689 * lpfc_adjust_high_watermark - Adjust high watermark
20690 * @phba: pointer to lpfc hba data structure.
20691 * @hwqid: belong to which HWQ.
20693 * This routine sets high watermark as number of outstanding XRIs,
20694 * but make sure the new value is between xri_limit/2 and xri_limit.
20696 void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
20704 struct lpfc_multixri_pool *multixri_pool;
20705 struct lpfc_sli4_hdw_queue *qp;
20707 qp = &phba->sli4_hba.hdwq[hwqid];
20708 multixri_pool = qp->p_multixri_pool;
20709 if (!multixri_pool)
20711 xri_limit = multixri_pool->xri_limit;
20713 watermark_max = xri_limit;
20714 watermark_min = xri_limit / 2;
20716 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
20717 abts_io_bufs = qp->abts_scsi_io_bufs;
20718 abts_io_bufs += qp->abts_nvme_io_bufs;
20720 new_watermark = txcmplq_cnt + abts_io_bufs;
20721 new_watermark = min(watermark_max, new_watermark);
20722 new_watermark = max(watermark_min, new_watermark);
20723 multixri_pool->pvt_pool.high_watermark = new_watermark;
20725 #ifdef LPFC_MXP_STAT
20726 multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
20732 * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
20733 * @phba: pointer to lpfc hba data structure.
20734 * @hwqid: belong to which HWQ.
20736 * This routine is called from hearbeat timer when pvt_pool is idle.
20737 * All free XRIs are moved from private to public pool on hwqid with 2 steps.
20738 * The first step moves (all - low_watermark) amount of XRIs.
20739 * The second step moves the rest of XRIs.
20741 void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
20743 struct lpfc_pbl_pool *pbl_pool;
20744 struct lpfc_pvt_pool *pvt_pool;
20745 struct lpfc_sli4_hdw_queue *qp;
20746 struct lpfc_io_buf *lpfc_ncmd;
20747 struct lpfc_io_buf *lpfc_ncmd_next;
20748 unsigned long iflag;
20749 struct list_head tmp_list;
20752 qp = &phba->sli4_hba.hdwq[hwqid];
20753 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20754 pvt_pool = &qp->p_multixri_pool->pvt_pool;
20757 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
20758 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
20760 if (pvt_pool->count > pvt_pool->low_watermark) {
20761 /* Step 1: move (all - low_watermark) from pvt_pool
20765 /* Move low watermark of bufs from pvt_pool to tmp_list */
20766 INIT_LIST_HEAD(&tmp_list);
20767 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
20768 &pvt_pool->list, list) {
20769 list_move_tail(&lpfc_ncmd->list, &tmp_list);
20771 if (tmp_count >= pvt_pool->low_watermark)
20775 /* Move all bufs from pvt_pool to pbl_pool */
20776 list_splice_init(&pvt_pool->list, &pbl_pool->list);
20778 /* Move all bufs from tmp_list to pvt_pool */
20779 list_splice(&tmp_list, &pvt_pool->list);
20781 pbl_pool->count += (pvt_pool->count - tmp_count);
20782 pvt_pool->count = tmp_count;
20784 /* Step 2: move the rest from pvt_pool to pbl_pool */
20785 list_splice_init(&pvt_pool->list, &pbl_pool->list);
20786 pbl_pool->count += pvt_pool->count;
20787 pvt_pool->count = 0;
20790 spin_unlock(&pvt_pool->lock);
20791 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20795 * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
20796 * @phba: pointer to lpfc hba data structure
20797 * @qp: pointer to HDW queue
20798 * @pbl_pool: specified public free XRI pool
20799 * @pvt_pool: specified private free XRI pool
20800 * @count: number of XRIs to move
20802 * This routine tries to move some free common bufs from the specified pbl_pool
20803 * to the specified pvt_pool. It might move less than count XRIs if there's not
20804 * enough in public pool.
20807 * true - if XRIs are successfully moved from the specified pbl_pool to the
20808 * specified pvt_pool
20809 * false - if the specified pbl_pool is empty or locked by someone else
20812 _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
20813 struct lpfc_pbl_pool *pbl_pool,
20814 struct lpfc_pvt_pool *pvt_pool, u32 count)
20816 struct lpfc_io_buf *lpfc_ncmd;
20817 struct lpfc_io_buf *lpfc_ncmd_next;
20818 unsigned long iflag;
20821 ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
20823 if (pbl_pool->count) {
20824 /* Move a batch of XRIs from public to private pool */
20825 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
20826 list_for_each_entry_safe(lpfc_ncmd,
20830 list_move_tail(&lpfc_ncmd->list,
20839 spin_unlock(&pvt_pool->lock);
20840 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20843 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
20850 * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
20851 * @phba: pointer to lpfc hba data structure.
20852 * @hwqid: belong to which HWQ.
20853 * @count: number of XRIs to move
20855 * This routine tries to find some free common bufs in one of public pools with
20856 * Round Robin method. The search always starts from local hwqid, then the next
20857 * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
20858 * a batch of free common bufs are moved to private pool on hwqid.
20859 * It might move less than count XRIs if there's not enough in public pool.
20861 void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
20863 struct lpfc_multixri_pool *multixri_pool;
20864 struct lpfc_multixri_pool *next_multixri_pool;
20865 struct lpfc_pvt_pool *pvt_pool;
20866 struct lpfc_pbl_pool *pbl_pool;
20867 struct lpfc_sli4_hdw_queue *qp;
20872 qp = &phba->sli4_hba.hdwq[hwqid];
20873 multixri_pool = qp->p_multixri_pool;
20874 pvt_pool = &multixri_pool->pvt_pool;
20875 pbl_pool = &multixri_pool->pbl_pool;
20877 /* Check if local pbl_pool is available */
20878 ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
20880 #ifdef LPFC_MXP_STAT
20881 multixri_pool->local_pbl_hit_count++;
20886 hwq_count = phba->cfg_hdw_queue;
20888 /* Get the next hwqid which was found last time */
20889 next_hwqid = multixri_pool->rrb_next_hwqid;
20892 /* Go to next hwq */
20893 next_hwqid = (next_hwqid + 1) % hwq_count;
20895 next_multixri_pool =
20896 phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
20897 pbl_pool = &next_multixri_pool->pbl_pool;
20899 /* Check if the public free xri pool is available */
20900 ret = _lpfc_move_xri_pbl_to_pvt(
20901 phba, qp, pbl_pool, pvt_pool, count);
20903 /* Exit while-loop if success or all hwqid are checked */
20904 } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
20906 /* Starting point for the next time */
20907 multixri_pool->rrb_next_hwqid = next_hwqid;
20910 /* stats: all public pools are empty*/
20911 multixri_pool->pbl_empty_count++;
20914 #ifdef LPFC_MXP_STAT
20916 if (next_hwqid == hwqid)
20917 multixri_pool->local_pbl_hit_count++;
20919 multixri_pool->other_pbl_hit_count++;
20925 * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
20926 * @phba: pointer to lpfc hba data structure.
20927 * @hwqid: belong to which HWQ.
20929 * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
20932 void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
20934 struct lpfc_multixri_pool *multixri_pool;
20935 struct lpfc_pvt_pool *pvt_pool;
20937 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
20938 pvt_pool = &multixri_pool->pvt_pool;
20940 if (pvt_pool->count < pvt_pool->low_watermark)
20941 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
20945 * lpfc_release_io_buf - Return one IO buf back to free pool
20946 * @phba: pointer to lpfc hba data structure.
20947 * @lpfc_ncmd: IO buf to be returned.
20948 * @qp: belong to which HWQ.
20950 * This routine returns one IO buf back to free pool. If this is an urgent IO,
20951 * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
20952 * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
20953 * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to
20954 * lpfc_io_buf_list_put.
20956 void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
20957 struct lpfc_sli4_hdw_queue *qp)
20959 unsigned long iflag;
20960 struct lpfc_pbl_pool *pbl_pool;
20961 struct lpfc_pvt_pool *pvt_pool;
20962 struct lpfc_epd_pool *epd_pool;
20968 /* MUST zero fields if buffer is reused by another protocol */
20969 lpfc_ncmd->nvmeCmd = NULL;
20970 lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL;
20971 lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL;
20973 if (phba->cfg_xpsgl && !phba->nvmet_support &&
20974 !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
20975 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
20977 if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
20978 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
20980 if (phba->cfg_xri_rebalancing) {
20981 if (lpfc_ncmd->expedite) {
20982 /* Return to expedite pool */
20983 epd_pool = &phba->epd_pool;
20984 spin_lock_irqsave(&epd_pool->lock, iflag);
20985 list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
20987 spin_unlock_irqrestore(&epd_pool->lock, iflag);
20991 /* Avoid invalid access if an IO sneaks in and is being rejected
20992 * just _after_ xri pools are destroyed in lpfc_offline.
20993 * Nothing much can be done at this point.
20995 if (!qp->p_multixri_pool)
20998 pbl_pool = &qp->p_multixri_pool->pbl_pool;
20999 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21001 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21002 abts_io_bufs = qp->abts_scsi_io_bufs;
21003 abts_io_bufs += qp->abts_nvme_io_bufs;
21005 xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
21006 xri_limit = qp->p_multixri_pool->xri_limit;
21008 #ifdef LPFC_MXP_STAT
21009 if (xri_owned <= xri_limit)
21010 qp->p_multixri_pool->below_limit_count++;
21012 qp->p_multixri_pool->above_limit_count++;
21015 /* XRI goes to either public or private free xri pool
21016 * based on watermark and xri_limit
21018 if ((pvt_pool->count < pvt_pool->low_watermark) ||
21019 (xri_owned < xri_limit &&
21020 pvt_pool->count < pvt_pool->high_watermark)) {
21021 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
21022 qp, free_pvt_pool);
21023 list_add_tail(&lpfc_ncmd->list,
21026 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21028 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
21029 qp, free_pub_pool);
21030 list_add_tail(&lpfc_ncmd->list,
21033 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21036 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
21038 list_add_tail(&lpfc_ncmd->list,
21039 &qp->lpfc_io_buf_list_put);
21041 spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
21047 * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
21048 * @phba: pointer to lpfc hba data structure.
21049 * @qp: pointer to HDW queue
21050 * @pvt_pool: pointer to private pool data structure.
21051 * @ndlp: pointer to lpfc nodelist data structure.
21053 * This routine tries to get one free IO buf from private pool.
21056 * pointer to one free IO buf - if private pool is not empty
21057 * NULL - if private pool is empty
21059 static struct lpfc_io_buf *
21060 lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
21061 struct lpfc_sli4_hdw_queue *qp,
21062 struct lpfc_pvt_pool *pvt_pool,
21063 struct lpfc_nodelist *ndlp)
21065 struct lpfc_io_buf *lpfc_ncmd;
21066 struct lpfc_io_buf *lpfc_ncmd_next;
21067 unsigned long iflag;
21069 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
21070 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21071 &pvt_pool->list, list) {
21072 if (lpfc_test_rrq_active(
21073 phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
21075 list_del(&lpfc_ncmd->list);
21077 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21080 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21086 * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
21087 * @phba: pointer to lpfc hba data structure.
21089 * This routine tries to get one free IO buf from expedite pool.
21092 * pointer to one free IO buf - if expedite pool is not empty
21093 * NULL - if expedite pool is empty
21095 static struct lpfc_io_buf *
21096 lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
21098 struct lpfc_io_buf *lpfc_ncmd;
21099 struct lpfc_io_buf *lpfc_ncmd_next;
21100 unsigned long iflag;
21101 struct lpfc_epd_pool *epd_pool;
21103 epd_pool = &phba->epd_pool;
21106 spin_lock_irqsave(&epd_pool->lock, iflag);
21107 if (epd_pool->count > 0) {
21108 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21109 &epd_pool->list, list) {
21110 list_del(&lpfc_ncmd->list);
21115 spin_unlock_irqrestore(&epd_pool->lock, iflag);
21121 * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
21122 * @phba: pointer to lpfc hba data structure.
21123 * @ndlp: pointer to lpfc nodelist data structure.
21124 * @hwqid: belong to which HWQ
21125 * @expedite: 1 means this request is urgent.
21127 * This routine will do the following actions and then return a pointer to
21130 * 1. If private free xri count is empty, move some XRIs from public to
21132 * 2. Get one XRI from private free xri pool.
21133 * 3. If we fail to get one from pvt_pool and this is an expedite request,
21134 * get one free xri from expedite pool.
21136 * Note: ndlp is only used on SCSI side for RRQ testing.
21137 * The caller should pass NULL for ndlp on NVME side.
21140 * pointer to one free IO buf - if private pool is not empty
21141 * NULL - if private pool is empty
21143 static struct lpfc_io_buf *
21144 lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
21145 struct lpfc_nodelist *ndlp,
21146 int hwqid, int expedite)
21148 struct lpfc_sli4_hdw_queue *qp;
21149 struct lpfc_multixri_pool *multixri_pool;
21150 struct lpfc_pvt_pool *pvt_pool;
21151 struct lpfc_io_buf *lpfc_ncmd;
21153 qp = &phba->sli4_hba.hdwq[hwqid];
21155 multixri_pool = qp->p_multixri_pool;
21156 pvt_pool = &multixri_pool->pvt_pool;
21157 multixri_pool->io_req_count++;
21159 /* If pvt_pool is empty, move some XRIs from public to private pool */
21160 if (pvt_pool->count == 0)
21161 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
21163 /* Get one XRI from private free xri pool */
21164 lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
21167 lpfc_ncmd->hdwq = qp;
21168 lpfc_ncmd->hdwq_no = hwqid;
21169 } else if (expedite) {
21170 /* If we fail to get one from pvt_pool and this is an expedite
21171 * request, get one free xri from expedite pool.
21173 lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
21179 static inline struct lpfc_io_buf *
21180 lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
21182 struct lpfc_sli4_hdw_queue *qp;
21183 struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
21185 qp = &phba->sli4_hba.hdwq[idx];
21186 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
21187 &qp->lpfc_io_buf_list_get, list) {
21188 if (lpfc_test_rrq_active(phba, ndlp,
21189 lpfc_cmd->cur_iocbq.sli4_lxritag))
21192 if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
21195 list_del_init(&lpfc_cmd->list);
21197 lpfc_cmd->hdwq = qp;
21198 lpfc_cmd->hdwq_no = idx;
21205 * lpfc_get_io_buf - Get one IO buffer from free pool
21206 * @phba: The HBA for which this call is being executed.
21207 * @ndlp: pointer to lpfc nodelist data structure.
21208 * @hwqid: belong to which HWQ
21209 * @expedite: 1 means this request is urgent.
21211 * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
21212 * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
21213 * a IO buffer from head of @hdwq io_buf_list and returns to caller.
21215 * Note: ndlp is only used on SCSI side for RRQ testing.
21216 * The caller should pass NULL for ndlp on NVME side.
21220 * Pointer to lpfc_io_buf - Success
21222 struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
21223 struct lpfc_nodelist *ndlp,
21224 u32 hwqid, int expedite)
21226 struct lpfc_sli4_hdw_queue *qp;
21227 unsigned long iflag;
21228 struct lpfc_io_buf *lpfc_cmd;
21230 qp = &phba->sli4_hba.hdwq[hwqid];
21233 if (phba->cfg_xri_rebalancing)
21234 lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
21235 phba, ndlp, hwqid, expedite);
21237 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
21238 qp, alloc_xri_get);
21239 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
21240 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
21242 lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
21243 qp, alloc_xri_put);
21244 list_splice(&qp->lpfc_io_buf_list_put,
21245 &qp->lpfc_io_buf_list_get);
21246 qp->get_io_bufs += qp->put_io_bufs;
21247 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
21248 qp->put_io_bufs = 0;
21249 spin_unlock(&qp->io_buf_list_put_lock);
21250 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
21252 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
21254 spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
21261 * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
21262 * @phba: The HBA for which this call is being executed.
21263 * @lpfc_buf: IO buf structure to append the SGL chunk
21265 * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
21266 * and will allocate an SGL chunk if the pool is empty.
21270 * Pointer to sli4_hybrid_sgl - Success
21272 struct sli4_hybrid_sgl *
21273 lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
21275 struct sli4_hybrid_sgl *list_entry = NULL;
21276 struct sli4_hybrid_sgl *tmp = NULL;
21277 struct sli4_hybrid_sgl *allocated_sgl = NULL;
21278 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
21279 struct list_head *buf_list = &hdwq->sgl_list;
21280 unsigned long iflags;
21282 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21284 if (likely(!list_empty(buf_list))) {
21285 /* break off 1 chunk from the sgl_list */
21286 list_for_each_entry_safe(list_entry, tmp,
21287 buf_list, list_node) {
21288 list_move_tail(&list_entry->list_node,
21289 &lpfc_buf->dma_sgl_xtra_list);
21293 /* allocate more */
21294 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21295 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
21296 cpu_to_node(hdwq->io_wq->chann));
21298 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
21299 "8353 error kmalloc memory for HDWQ "
21301 lpfc_buf->hdwq_no, __func__);
21305 tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
21306 GFP_ATOMIC, &tmp->dma_phys_sgl);
21307 if (!tmp->dma_sgl) {
21308 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
21309 "8354 error pool_alloc memory for HDWQ "
21311 lpfc_buf->hdwq_no, __func__);
21316 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21317 list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
21320 allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
21321 struct sli4_hybrid_sgl,
21324 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21326 return allocated_sgl;
21330 * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
21331 * @phba: The HBA for which this call is being executed.
21332 * @lpfc_buf: IO buf structure with the SGL chunk
21334 * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
21341 lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
21344 struct sli4_hybrid_sgl *list_entry = NULL;
21345 struct sli4_hybrid_sgl *tmp = NULL;
21346 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
21347 struct list_head *buf_list = &hdwq->sgl_list;
21348 unsigned long iflags;
21350 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21352 if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
21353 list_for_each_entry_safe(list_entry, tmp,
21354 &lpfc_buf->dma_sgl_xtra_list,
21356 list_move_tail(&list_entry->list_node,
21363 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21368 * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
21369 * @phba: phba object
21370 * @hdwq: hdwq to cleanup sgl buff resources on
21372 * This routine frees all SGL chunks of hdwq SGL chunk pool.
21378 lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
21379 struct lpfc_sli4_hdw_queue *hdwq)
21381 struct list_head *buf_list = &hdwq->sgl_list;
21382 struct sli4_hybrid_sgl *list_entry = NULL;
21383 struct sli4_hybrid_sgl *tmp = NULL;
21384 unsigned long iflags;
21386 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21388 /* Free sgl pool */
21389 list_for_each_entry_safe(list_entry, tmp,
21390 buf_list, list_node) {
21391 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
21392 list_entry->dma_sgl,
21393 list_entry->dma_phys_sgl);
21394 list_del(&list_entry->list_node);
21398 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21402 * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
21403 * @phba: The HBA for which this call is being executed.
21404 * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
21406 * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
21407 * and will allocate an CMD/RSP buffer if the pool is empty.
21411 * Pointer to fcp_cmd_rsp_buf - Success
21413 struct fcp_cmd_rsp_buf *
21414 lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
21415 struct lpfc_io_buf *lpfc_buf)
21417 struct fcp_cmd_rsp_buf *list_entry = NULL;
21418 struct fcp_cmd_rsp_buf *tmp = NULL;
21419 struct fcp_cmd_rsp_buf *allocated_buf = NULL;
21420 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
21421 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
21422 unsigned long iflags;
21424 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21426 if (likely(!list_empty(buf_list))) {
21427 /* break off 1 chunk from the list */
21428 list_for_each_entry_safe(list_entry, tmp,
21431 list_move_tail(&list_entry->list_node,
21432 &lpfc_buf->dma_cmd_rsp_list);
21436 /* allocate more */
21437 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21438 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
21439 cpu_to_node(hdwq->io_wq->chann));
21441 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
21442 "8355 error kmalloc memory for HDWQ "
21444 lpfc_buf->hdwq_no, __func__);
21448 tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool,
21450 &tmp->fcp_cmd_rsp_dma_handle);
21452 if (!tmp->fcp_cmnd) {
21453 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
21454 "8356 error pool_alloc memory for HDWQ "
21456 lpfc_buf->hdwq_no, __func__);
21461 tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
21462 sizeof(struct fcp_cmnd));
21464 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21465 list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
21468 allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
21469 struct fcp_cmd_rsp_buf,
21472 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21474 return allocated_buf;
21478 * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
21479 * @phba: The HBA for which this call is being executed.
21480 * @lpfc_buf: IO buf structure with the CMD/RSP buf
21482 * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
21489 lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
21490 struct lpfc_io_buf *lpfc_buf)
21493 struct fcp_cmd_rsp_buf *list_entry = NULL;
21494 struct fcp_cmd_rsp_buf *tmp = NULL;
21495 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
21496 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
21497 unsigned long iflags;
21499 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21501 if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
21502 list_for_each_entry_safe(list_entry, tmp,
21503 &lpfc_buf->dma_cmd_rsp_list,
21505 list_move_tail(&list_entry->list_node,
21512 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
21517 * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
21518 * @phba: phba object
21519 * @hdwq: hdwq to cleanup cmd rsp buff resources on
21521 * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
21527 lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
21528 struct lpfc_sli4_hdw_queue *hdwq)
21530 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
21531 struct fcp_cmd_rsp_buf *list_entry = NULL;
21532 struct fcp_cmd_rsp_buf *tmp = NULL;
21533 unsigned long iflags;
21535 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
21537 /* Free cmd_rsp buf pool */
21538 list_for_each_entry_safe(list_entry, tmp,
21541 dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
21542 list_entry->fcp_cmnd,
21543 list_entry->fcp_cmd_rsp_dma_handle);
21544 list_del(&list_entry->list_node);
21548 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);