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 active
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 active
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 (!(unlikely(pci_channel_offline(phba->pcidev)))) &&
1408 sglq->state != SGL_XRI_ABORTED) {
1409 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1412 /* Check if we can get a reference on ndlp */
1413 if (sglq->ndlp && !lpfc_nlp_get(sglq->ndlp))
1416 list_add(&sglq->list,
1417 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1418 spin_unlock_irqrestore(
1419 &phba->sli4_hba.sgl_list_lock, iflag);
1421 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1423 sglq->state = SGL_FREED;
1425 list_add_tail(&sglq->list,
1426 &phba->sli4_hba.lpfc_els_sgl_list);
1427 spin_unlock_irqrestore(
1428 &phba->sli4_hba.sgl_list_lock, iflag);
1429 pring = lpfc_phba_elsring(phba);
1430 /* Check if TXQ queue needs to be serviced */
1431 if (pring && (!list_empty(&pring->txq)))
1432 lpfc_worker_wake_up(phba);
1438 * Clean all volatile data fields, preserve iotag and node struct.
1440 memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1441 iocbq->sli4_lxritag = NO_XRI;
1442 iocbq->sli4_xritag = NO_XRI;
1443 iocbq->iocb_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | LPFC_IO_CMF |
1445 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1450 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1451 * @phba: Pointer to HBA context object.
1452 * @iocbq: Pointer to driver iocb object.
1454 * This function is called to release the driver iocb object to the
1455 * iocb pool. The iotag in the iocb object does not change for each
1456 * use of the iocb object. This function clears all other fields of
1457 * the iocb object when it is freed. The hbalock is asserted held in
1458 * the code path calling this routine.
1461 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1463 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
1466 * Clean all volatile data fields, preserve iotag and node struct.
1468 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
1469 iocbq->sli4_xritag = NO_XRI;
1470 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1474 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1475 * @phba: Pointer to HBA context object.
1476 * @iocbq: Pointer to driver iocb object.
1478 * This function is called with hbalock held to release driver
1479 * iocb object to the iocb pool. The iotag in the iocb object
1480 * does not change for each use of the iocb object. This function
1481 * clears all other fields of the iocb object when it is freed.
1484 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1486 lockdep_assert_held(&phba->hbalock);
1488 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1493 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1494 * @phba: Pointer to HBA context object.
1495 * @iocbq: Pointer to driver iocb object.
1497 * This function is called with no lock held to release the iocb to
1501 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1503 unsigned long iflags;
1506 * Clean all volatile data fields, preserve iotag and node struct.
1508 spin_lock_irqsave(&phba->hbalock, iflags);
1509 __lpfc_sli_release_iocbq(phba, iocbq);
1510 spin_unlock_irqrestore(&phba->hbalock, iflags);
1514 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1515 * @phba: Pointer to HBA context object.
1516 * @iocblist: List of IOCBs.
1517 * @ulpstatus: ULP status in IOCB command field.
1518 * @ulpWord4: ULP word-4 in IOCB command field.
1520 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1521 * on the list by invoking the complete callback function associated with the
1522 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1526 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1527 uint32_t ulpstatus, uint32_t ulpWord4)
1529 struct lpfc_iocbq *piocb;
1531 while (!list_empty(iocblist)) {
1532 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1533 if (piocb->wqe_cmpl) {
1534 if (piocb->iocb_flag & LPFC_IO_NVME)
1535 lpfc_nvme_cancel_iocb(phba, piocb,
1536 ulpstatus, ulpWord4);
1538 lpfc_sli_release_iocbq(phba, piocb);
1540 } else if (piocb->iocb_cmpl) {
1541 piocb->iocb.ulpStatus = ulpstatus;
1542 piocb->iocb.un.ulpWord[4] = ulpWord4;
1543 (piocb->iocb_cmpl) (phba, piocb, piocb);
1545 lpfc_sli_release_iocbq(phba, piocb);
1552 * lpfc_sli_iocb_cmd_type - Get the iocb type
1553 * @iocb_cmnd: iocb command code.
1555 * This function is called by ring event handler function to get the iocb type.
1556 * This function translates the iocb command to an iocb command type used to
1557 * decide the final disposition of each completed IOCB.
1558 * The function returns
1559 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1560 * LPFC_SOL_IOCB if it is a solicited iocb completion
1561 * LPFC_ABORT_IOCB if it is an abort iocb
1562 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1564 * The caller is not required to hold any lock.
1566 static lpfc_iocb_type
1567 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1569 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1571 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1574 switch (iocb_cmnd) {
1575 case CMD_XMIT_SEQUENCE_CR:
1576 case CMD_XMIT_SEQUENCE_CX:
1577 case CMD_XMIT_BCAST_CN:
1578 case CMD_XMIT_BCAST_CX:
1579 case CMD_ELS_REQUEST_CR:
1580 case CMD_ELS_REQUEST_CX:
1581 case CMD_CREATE_XRI_CR:
1582 case CMD_CREATE_XRI_CX:
1583 case CMD_GET_RPI_CN:
1584 case CMD_XMIT_ELS_RSP_CX:
1585 case CMD_GET_RPI_CR:
1586 case CMD_FCP_IWRITE_CR:
1587 case CMD_FCP_IWRITE_CX:
1588 case CMD_FCP_IREAD_CR:
1589 case CMD_FCP_IREAD_CX:
1590 case CMD_FCP_ICMND_CR:
1591 case CMD_FCP_ICMND_CX:
1592 case CMD_FCP_TSEND_CX:
1593 case CMD_FCP_TRSP_CX:
1594 case CMD_FCP_TRECEIVE_CX:
1595 case CMD_FCP_AUTO_TRSP_CX:
1596 case CMD_ADAPTER_MSG:
1597 case CMD_ADAPTER_DUMP:
1598 case CMD_XMIT_SEQUENCE64_CR:
1599 case CMD_XMIT_SEQUENCE64_CX:
1600 case CMD_XMIT_BCAST64_CN:
1601 case CMD_XMIT_BCAST64_CX:
1602 case CMD_ELS_REQUEST64_CR:
1603 case CMD_ELS_REQUEST64_CX:
1604 case CMD_FCP_IWRITE64_CR:
1605 case CMD_FCP_IWRITE64_CX:
1606 case CMD_FCP_IREAD64_CR:
1607 case CMD_FCP_IREAD64_CX:
1608 case CMD_FCP_ICMND64_CR:
1609 case CMD_FCP_ICMND64_CX:
1610 case CMD_FCP_TSEND64_CX:
1611 case CMD_FCP_TRSP64_CX:
1612 case CMD_FCP_TRECEIVE64_CX:
1613 case CMD_GEN_REQUEST64_CR:
1614 case CMD_GEN_REQUEST64_CX:
1615 case CMD_XMIT_ELS_RSP64_CX:
1616 case DSSCMD_IWRITE64_CR:
1617 case DSSCMD_IWRITE64_CX:
1618 case DSSCMD_IREAD64_CR:
1619 case DSSCMD_IREAD64_CX:
1620 case CMD_SEND_FRAME:
1621 type = LPFC_SOL_IOCB;
1623 case CMD_ABORT_XRI_CN:
1624 case CMD_ABORT_XRI_CX:
1625 case CMD_CLOSE_XRI_CN:
1626 case CMD_CLOSE_XRI_CX:
1627 case CMD_XRI_ABORTED_CX:
1628 case CMD_ABORT_MXRI64_CN:
1629 case CMD_XMIT_BLS_RSP64_CX:
1630 type = LPFC_ABORT_IOCB;
1632 case CMD_RCV_SEQUENCE_CX:
1633 case CMD_RCV_ELS_REQ_CX:
1634 case CMD_RCV_SEQUENCE64_CX:
1635 case CMD_RCV_ELS_REQ64_CX:
1636 case CMD_ASYNC_STATUS:
1637 case CMD_IOCB_RCV_SEQ64_CX:
1638 case CMD_IOCB_RCV_ELS64_CX:
1639 case CMD_IOCB_RCV_CONT64_CX:
1640 case CMD_IOCB_RET_XRI64_CX:
1641 type = LPFC_UNSOL_IOCB;
1643 case CMD_IOCB_XMIT_MSEQ64_CR:
1644 case CMD_IOCB_XMIT_MSEQ64_CX:
1645 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1646 case CMD_IOCB_RCV_ELS_LIST64_CX:
1647 case CMD_IOCB_CLOSE_EXTENDED_CN:
1648 case CMD_IOCB_ABORT_EXTENDED_CN:
1649 case CMD_IOCB_RET_HBQE64_CN:
1650 case CMD_IOCB_FCP_IBIDIR64_CR:
1651 case CMD_IOCB_FCP_IBIDIR64_CX:
1652 case CMD_IOCB_FCP_ITASKMGT64_CX:
1653 case CMD_IOCB_LOGENTRY_CN:
1654 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1655 printk("%s - Unhandled SLI-3 Command x%x\n",
1656 __func__, iocb_cmnd);
1657 type = LPFC_UNKNOWN_IOCB;
1660 type = LPFC_UNKNOWN_IOCB;
1668 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1669 * @phba: Pointer to HBA context object.
1671 * This function is called from SLI initialization code
1672 * to configure every ring of the HBA's SLI interface. The
1673 * caller is not required to hold any lock. This function issues
1674 * a config_ring mailbox command for each ring.
1675 * This function returns zero if successful else returns a negative
1679 lpfc_sli_ring_map(struct lpfc_hba *phba)
1681 struct lpfc_sli *psli = &phba->sli;
1686 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1690 phba->link_state = LPFC_INIT_MBX_CMDS;
1691 for (i = 0; i < psli->num_rings; i++) {
1692 lpfc_config_ring(phba, i, pmb);
1693 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1694 if (rc != MBX_SUCCESS) {
1695 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1696 "0446 Adapter failed to init (%d), "
1697 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1699 rc, pmbox->mbxCommand,
1700 pmbox->mbxStatus, i);
1701 phba->link_state = LPFC_HBA_ERROR;
1706 mempool_free(pmb, phba->mbox_mem_pool);
1711 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1712 * @phba: Pointer to HBA context object.
1713 * @pring: Pointer to driver SLI ring object.
1714 * @piocb: Pointer to the driver iocb object.
1716 * The driver calls this function with the hbalock held for SLI3 ports or
1717 * the ring lock held for SLI4 ports. The function adds the
1718 * new iocb to txcmplq of the given ring. This function always returns
1719 * 0. If this function is called for ELS ring, this function checks if
1720 * there is a vport associated with the ELS command. This function also
1721 * starts els_tmofunc timer if this is an ELS command.
1724 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1725 struct lpfc_iocbq *piocb)
1727 if (phba->sli_rev == LPFC_SLI_REV4)
1728 lockdep_assert_held(&pring->ring_lock);
1730 lockdep_assert_held(&phba->hbalock);
1734 list_add_tail(&piocb->list, &pring->txcmplq);
1735 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1736 pring->txcmplq_cnt++;
1738 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1739 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1740 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1741 BUG_ON(!piocb->vport);
1742 if (!(piocb->vport->load_flag & FC_UNLOADING))
1743 mod_timer(&piocb->vport->els_tmofunc,
1745 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1752 * lpfc_sli_ringtx_get - Get first element of the txq
1753 * @phba: Pointer to HBA context object.
1754 * @pring: Pointer to driver SLI ring object.
1756 * This function is called with hbalock held to get next
1757 * iocb in txq of the given ring. If there is any iocb in
1758 * the txq, the function returns first iocb in the list after
1759 * removing the iocb from the list, else it returns NULL.
1762 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1764 struct lpfc_iocbq *cmd_iocb;
1766 lockdep_assert_held(&phba->hbalock);
1768 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1773 * lpfc_cmf_sync_cmpl - Process a CMF_SYNC_WQE cmpl
1774 * @phba: Pointer to HBA context object.
1775 * @cmdiocb: Pointer to driver command iocb object.
1776 * @cmf_cmpl: Pointer to completed WCQE.
1778 * This routine will inform the driver of any BW adjustments we need
1779 * to make. These changes will be picked up during the next CMF
1780 * timer interrupt. In addition, any BW changes will be logged
1781 * with LOG_CGN_MGMT.
1784 lpfc_cmf_sync_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1785 struct lpfc_wcqe_complete *cmf_cmpl)
1787 union lpfc_wqe128 *wqe;
1788 uint32_t status, info;
1789 uint64_t bw, bwdif, slop;
1790 uint64_t pcent, bwpcent;
1791 int asig, afpin, sigcnt, fpincnt;
1792 int wsigmax, wfpinmax, cg, tdp;
1795 /* First check for error */
1796 status = bf_get(lpfc_wcqe_c_status, cmf_cmpl);
1798 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1799 "6211 CMF_SYNC_WQE Error "
1800 "req_tag x%x status x%x hwstatus x%x "
1801 "tdatap x%x parm x%x\n",
1802 bf_get(lpfc_wcqe_c_request_tag, cmf_cmpl),
1803 bf_get(lpfc_wcqe_c_status, cmf_cmpl),
1804 bf_get(lpfc_wcqe_c_hw_status, cmf_cmpl),
1805 cmf_cmpl->total_data_placed,
1806 cmf_cmpl->parameter);
1810 /* Gather congestion information on a successful cmpl */
1811 info = cmf_cmpl->parameter;
1812 phba->cmf_active_info = info;
1814 /* See if firmware info count is valid or has changed */
1815 if (info > LPFC_MAX_CMF_INFO || phba->cmf_info_per_interval == info)
1818 phba->cmf_info_per_interval = info;
1820 tdp = bf_get(lpfc_wcqe_c_cmf_bw, cmf_cmpl);
1821 cg = bf_get(lpfc_wcqe_c_cmf_cg, cmf_cmpl);
1823 /* Get BW requirement from firmware */
1824 bw = (uint64_t)tdp * LPFC_CMF_BLK_SIZE;
1826 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1827 "6212 CMF_SYNC_WQE x%x: NULL bw\n",
1828 bf_get(lpfc_wcqe_c_request_tag, cmf_cmpl));
1832 /* Gather information needed for logging if a BW change is required */
1833 wqe = &cmdiocb->wqe;
1834 asig = bf_get(cmf_sync_asig, &wqe->cmf_sync);
1835 afpin = bf_get(cmf_sync_afpin, &wqe->cmf_sync);
1836 fpincnt = bf_get(cmf_sync_wfpincnt, &wqe->cmf_sync);
1837 sigcnt = bf_get(cmf_sync_wsigcnt, &wqe->cmf_sync);
1838 if (phba->cmf_max_bytes_per_interval != bw ||
1839 (asig || afpin || sigcnt || fpincnt)) {
1840 /* Are we increasing or decreasing BW */
1841 if (phba->cmf_max_bytes_per_interval < bw) {
1842 bwdif = bw - phba->cmf_max_bytes_per_interval;
1845 bwdif = phba->cmf_max_bytes_per_interval - bw;
1849 /* What is the change percentage */
1850 slop = div_u64(phba->cmf_link_byte_count, 200); /*For rounding*/
1851 pcent = div64_u64(bwdif * 100 + slop,
1852 phba->cmf_link_byte_count);
1853 bwpcent = div64_u64(bw * 100 + slop,
1854 phba->cmf_link_byte_count);
1856 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1857 "6237 BW Threshold %lld%% (%lld): "
1858 "%lld%% %s: Signal Alarm: cg:%d "
1860 bwpcent, bw, pcent, s, cg,
1861 phba->cmf_active_info);
1863 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1864 "6238 BW Threshold %lld%% (%lld): "
1865 "%lld%% %s: FPIN Alarm: cg:%d "
1867 bwpcent, bw, pcent, s, cg,
1868 phba->cmf_active_info);
1869 } else if (sigcnt) {
1870 wsigmax = bf_get(cmf_sync_wsigmax, &wqe->cmf_sync);
1871 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1872 "6239 BW Threshold %lld%% (%lld): "
1873 "%lld%% %s: Signal Warning: "
1874 "Cnt %d Max %d: cg:%d Info:%u\n",
1875 bwpcent, bw, pcent, s, sigcnt,
1876 wsigmax, cg, phba->cmf_active_info);
1877 } else if (fpincnt) {
1878 wfpinmax = bf_get(cmf_sync_wfpinmax, &wqe->cmf_sync);
1879 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1880 "6240 BW Threshold %lld%% (%lld): "
1881 "%lld%% %s: FPIN Warning: "
1882 "Cnt %d Max %d: cg:%d Info:%u\n",
1883 bwpcent, bw, pcent, s, fpincnt,
1884 wfpinmax, cg, phba->cmf_active_info);
1886 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1887 "6241 BW Threshold %lld%% (%lld): "
1888 "CMF %lld%% %s: cg:%d Info:%u\n",
1889 bwpcent, bw, pcent, s, cg,
1890 phba->cmf_active_info);
1893 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1894 "6246 Info Threshold %u\n", info);
1897 /* Save BW change to be picked up during next timer interrupt */
1898 phba->cmf_last_sync_bw = bw;
1900 lpfc_sli_release_iocbq(phba, cmdiocb);
1904 * lpfc_issue_cmf_sync_wqe - Issue a CMF_SYNC_WQE
1905 * @phba: Pointer to HBA context object.
1906 * @ms: ms to set in WQE interval, 0 means use init op
1907 * @total: Total rcv bytes for this interval
1909 * This routine is called every CMF timer interrupt. Its purpose is
1910 * to issue a CMF_SYNC_WQE to the firmware to inform it of any events
1911 * that may indicate we have congestion (FPINs or Signals). Upon
1912 * completion, the firmware will indicate any BW restrictions the
1913 * driver may need to take.
1916 lpfc_issue_cmf_sync_wqe(struct lpfc_hba *phba, u32 ms, u64 total)
1918 union lpfc_wqe128 *wqe;
1919 struct lpfc_iocbq *sync_buf;
1920 unsigned long iflags;
1922 u32 atot, wtot, max;
1924 /* First address any alarm / warning activity */
1925 atot = atomic_xchg(&phba->cgn_sync_alarm_cnt, 0);
1926 wtot = atomic_xchg(&phba->cgn_sync_warn_cnt, 0);
1928 /* ONLY Managed mode will send the CMF_SYNC_WQE to the HBA */
1929 if (phba->cmf_active_mode != LPFC_CFG_MANAGED ||
1930 phba->link_state == LPFC_LINK_DOWN)
1933 spin_lock_irqsave(&phba->hbalock, iflags);
1934 sync_buf = __lpfc_sli_get_iocbq(phba);
1936 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
1937 "6213 No available WQEs for CMF_SYNC_WQE\n");
1942 wqe = &sync_buf->wqe;
1944 /* WQEs are reused. Clear stale data and set key fields to zero */
1945 memset(wqe, 0, sizeof(*wqe));
1947 /* If this is the very first CMF_SYNC_WQE, issue an init operation */
1949 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1950 "6441 CMF Init %d - CMF_SYNC_WQE\n",
1952 bf_set(cmf_sync_op, &wqe->cmf_sync, 1); /* 1=init */
1953 bf_set(cmf_sync_interval, &wqe->cmf_sync, LPFC_CMF_INTERVAL);
1957 bf_set(cmf_sync_op, &wqe->cmf_sync, 0); /* 0=recalc */
1958 bf_set(cmf_sync_interval, &wqe->cmf_sync, ms);
1960 /* Check for alarms / warnings */
1962 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
1963 /* We hit an Signal alarm condition */
1964 bf_set(cmf_sync_asig, &wqe->cmf_sync, 1);
1966 /* We hit a FPIN alarm condition */
1967 bf_set(cmf_sync_afpin, &wqe->cmf_sync, 1);
1970 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
1971 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
1972 /* We hit an Signal warning condition */
1973 max = LPFC_SEC_TO_MSEC / lpfc_fabric_cgn_frequency *
1974 lpfc_acqe_cgn_frequency;
1975 bf_set(cmf_sync_wsigmax, &wqe->cmf_sync, max);
1976 bf_set(cmf_sync_wsigcnt, &wqe->cmf_sync, wtot);
1978 /* We hit a FPIN warning condition */
1979 bf_set(cmf_sync_wfpinmax, &wqe->cmf_sync, 1);
1980 bf_set(cmf_sync_wfpincnt, &wqe->cmf_sync, 1);
1984 /* Update total read blocks during previous timer interval */
1985 wqe->cmf_sync.read_bytes = (u32)(total / LPFC_CMF_BLK_SIZE);
1988 bf_set(cmf_sync_ver, &wqe->cmf_sync, LPFC_CMF_SYNC_VER);
1989 wqe->cmf_sync.event_tag = phba->fc_eventTag;
1990 bf_set(cmf_sync_cmnd, &wqe->cmf_sync, CMD_CMF_SYNC_WQE);
1992 /* Setup reqtag to match the wqe completion. */
1993 bf_set(cmf_sync_reqtag, &wqe->cmf_sync, sync_buf->iotag);
1995 bf_set(cmf_sync_qosd, &wqe->cmf_sync, 1);
1997 bf_set(cmf_sync_cmd_type, &wqe->cmf_sync, CMF_SYNC_COMMAND);
1998 bf_set(cmf_sync_wqec, &wqe->cmf_sync, 1);
1999 bf_set(cmf_sync_cqid, &wqe->cmf_sync, LPFC_WQE_CQ_ID_DEFAULT);
2001 sync_buf->vport = phba->pport;
2002 sync_buf->wqe_cmpl = lpfc_cmf_sync_cmpl;
2003 sync_buf->iocb_cmpl = NULL;
2004 sync_buf->context1 = NULL;
2005 sync_buf->context2 = NULL;
2006 sync_buf->context3 = NULL;
2007 sync_buf->sli4_xritag = NO_XRI;
2009 sync_buf->iocb_flag |= LPFC_IO_CMF;
2010 ret_val = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], sync_buf);
2012 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
2013 "6214 Cannot issue CMF_SYNC_WQE: x%x\n",
2016 spin_unlock_irqrestore(&phba->hbalock, iflags);
2021 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
2022 * @phba: Pointer to HBA context object.
2023 * @pring: Pointer to driver SLI ring object.
2025 * This function is called with hbalock held and the caller must post the
2026 * iocb without releasing the lock. If the caller releases the lock,
2027 * iocb slot returned by the function is not guaranteed to be available.
2028 * The function returns pointer to the next available iocb slot if there
2029 * is available slot in the ring, else it returns NULL.
2030 * If the get index of the ring is ahead of the put index, the function
2031 * will post an error attention event to the worker thread to take the
2032 * HBA to offline state.
2035 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2037 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2038 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
2040 lockdep_assert_held(&phba->hbalock);
2042 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
2043 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
2044 pring->sli.sli3.next_cmdidx = 0;
2046 if (unlikely(pring->sli.sli3.local_getidx ==
2047 pring->sli.sli3.next_cmdidx)) {
2049 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
2051 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
2052 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2053 "0315 Ring %d issue: portCmdGet %d "
2054 "is bigger than cmd ring %d\n",
2056 pring->sli.sli3.local_getidx,
2059 phba->link_state = LPFC_HBA_ERROR;
2061 * All error attention handlers are posted to
2064 phba->work_ha |= HA_ERATT;
2065 phba->work_hs = HS_FFER3;
2067 lpfc_worker_wake_up(phba);
2072 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
2076 return lpfc_cmd_iocb(phba, pring);
2080 * lpfc_sli_next_iotag - Get an iotag for the iocb
2081 * @phba: Pointer to HBA context object.
2082 * @iocbq: Pointer to driver iocb object.
2084 * This function gets an iotag for the iocb. If there is no unused iotag and
2085 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
2086 * array and assigns a new iotag.
2087 * The function returns the allocated iotag if successful, else returns zero.
2088 * Zero is not a valid iotag.
2089 * The caller is not required to hold any lock.
2092 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
2094 struct lpfc_iocbq **new_arr;
2095 struct lpfc_iocbq **old_arr;
2097 struct lpfc_sli *psli = &phba->sli;
2100 spin_lock_irq(&phba->hbalock);
2101 iotag = psli->last_iotag;
2102 if(++iotag < psli->iocbq_lookup_len) {
2103 psli->last_iotag = iotag;
2104 psli->iocbq_lookup[iotag] = iocbq;
2105 spin_unlock_irq(&phba->hbalock);
2106 iocbq->iotag = iotag;
2108 } else if (psli->iocbq_lookup_len < (0xffff
2109 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
2110 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
2111 spin_unlock_irq(&phba->hbalock);
2112 new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
2115 spin_lock_irq(&phba->hbalock);
2116 old_arr = psli->iocbq_lookup;
2117 if (new_len <= psli->iocbq_lookup_len) {
2118 /* highly unprobable case */
2120 iotag = psli->last_iotag;
2121 if(++iotag < psli->iocbq_lookup_len) {
2122 psli->last_iotag = iotag;
2123 psli->iocbq_lookup[iotag] = iocbq;
2124 spin_unlock_irq(&phba->hbalock);
2125 iocbq->iotag = iotag;
2128 spin_unlock_irq(&phba->hbalock);
2131 if (psli->iocbq_lookup)
2132 memcpy(new_arr, old_arr,
2133 ((psli->last_iotag + 1) *
2134 sizeof (struct lpfc_iocbq *)));
2135 psli->iocbq_lookup = new_arr;
2136 psli->iocbq_lookup_len = new_len;
2137 psli->last_iotag = iotag;
2138 psli->iocbq_lookup[iotag] = iocbq;
2139 spin_unlock_irq(&phba->hbalock);
2140 iocbq->iotag = iotag;
2145 spin_unlock_irq(&phba->hbalock);
2147 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2148 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
2155 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
2156 * @phba: Pointer to HBA context object.
2157 * @pring: Pointer to driver SLI ring object.
2158 * @iocb: Pointer to iocb slot in the ring.
2159 * @nextiocb: Pointer to driver iocb object which need to be
2160 * posted to firmware.
2162 * This function is called to post a new iocb to the firmware. This
2163 * function copies the new iocb to ring iocb slot and updates the
2164 * ring pointers. It adds the new iocb to txcmplq if there is
2165 * a completion call back for this iocb else the function will free the
2166 * iocb object. The hbalock is asserted held in the code path calling
2170 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2171 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
2176 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
2179 if (pring->ringno == LPFC_ELS_RING) {
2180 lpfc_debugfs_slow_ring_trc(phba,
2181 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2182 *(((uint32_t *) &nextiocb->iocb) + 4),
2183 *(((uint32_t *) &nextiocb->iocb) + 6),
2184 *(((uint32_t *) &nextiocb->iocb) + 7));
2188 * Issue iocb command to adapter
2190 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
2192 pring->stats.iocb_cmd++;
2195 * If there is no completion routine to call, we can release the
2196 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
2197 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
2199 if (nextiocb->iocb_cmpl)
2200 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
2202 __lpfc_sli_release_iocbq(phba, nextiocb);
2205 * Let the HBA know what IOCB slot will be the next one the
2206 * driver will put a command into.
2208 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
2209 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
2213 * lpfc_sli_update_full_ring - Update the chip attention register
2214 * @phba: Pointer to HBA context object.
2215 * @pring: Pointer to driver SLI ring object.
2217 * The caller is not required to hold any lock for calling this function.
2218 * This function updates the chip attention bits for the ring to inform firmware
2219 * that there are pending work to be done for this ring and requests an
2220 * interrupt when there is space available in the ring. This function is
2221 * called when the driver is unable to post more iocbs to the ring due
2222 * to unavailability of space in the ring.
2225 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2227 int ringno = pring->ringno;
2229 pring->flag |= LPFC_CALL_RING_AVAILABLE;
2234 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
2235 * The HBA will tell us when an IOCB entry is available.
2237 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
2238 readl(phba->CAregaddr); /* flush */
2240 pring->stats.iocb_cmd_full++;
2244 * lpfc_sli_update_ring - Update chip attention register
2245 * @phba: Pointer to HBA context object.
2246 * @pring: Pointer to driver SLI ring object.
2248 * This function updates the chip attention register bit for the
2249 * given ring to inform HBA that there is more work to be done
2250 * in this ring. The caller is not required to hold any lock.
2253 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2255 int ringno = pring->ringno;
2258 * Tell the HBA that there is work to do in this ring.
2260 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
2262 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
2263 readl(phba->CAregaddr); /* flush */
2268 * lpfc_sli_resume_iocb - Process iocbs in the txq
2269 * @phba: Pointer to HBA context object.
2270 * @pring: Pointer to driver SLI ring object.
2272 * This function is called with hbalock held to post pending iocbs
2273 * in the txq to the firmware. This function is called when driver
2274 * detects space available in the ring.
2277 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2280 struct lpfc_iocbq *nextiocb;
2282 lockdep_assert_held(&phba->hbalock);
2286 * (a) there is anything on the txq to send
2288 * (c) link attention events can be processed (fcp ring only)
2289 * (d) IOCB processing is not blocked by the outstanding mbox command.
2292 if (lpfc_is_link_up(phba) &&
2293 (!list_empty(&pring->txq)) &&
2294 (pring->ringno != LPFC_FCP_RING ||
2295 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
2297 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2298 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
2299 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2302 lpfc_sli_update_ring(phba, pring);
2304 lpfc_sli_update_full_ring(phba, pring);
2311 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
2312 * @phba: Pointer to HBA context object.
2313 * @hbqno: HBQ number.
2315 * This function is called with hbalock held to get the next
2316 * available slot for the given HBQ. If there is free slot
2317 * available for the HBQ it will return pointer to the next available
2318 * HBQ entry else it will return NULL.
2320 static struct lpfc_hbq_entry *
2321 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
2323 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2325 lockdep_assert_held(&phba->hbalock);
2327 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
2328 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
2329 hbqp->next_hbqPutIdx = 0;
2331 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
2332 uint32_t raw_index = phba->hbq_get[hbqno];
2333 uint32_t getidx = le32_to_cpu(raw_index);
2335 hbqp->local_hbqGetIdx = getidx;
2337 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
2338 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2339 "1802 HBQ %d: local_hbqGetIdx "
2340 "%u is > than hbqp->entry_count %u\n",
2341 hbqno, hbqp->local_hbqGetIdx,
2344 phba->link_state = LPFC_HBA_ERROR;
2348 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
2352 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
2357 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
2358 * @phba: Pointer to HBA context object.
2360 * This function is called with no lock held to free all the
2361 * hbq buffers while uninitializing the SLI interface. It also
2362 * frees the HBQ buffers returned by the firmware but not yet
2363 * processed by the upper layers.
2366 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
2368 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
2369 struct hbq_dmabuf *hbq_buf;
2370 unsigned long flags;
2373 hbq_count = lpfc_sli_hbq_count();
2374 /* Return all memory used by all HBQs */
2375 spin_lock_irqsave(&phba->hbalock, flags);
2376 for (i = 0; i < hbq_count; ++i) {
2377 list_for_each_entry_safe(dmabuf, next_dmabuf,
2378 &phba->hbqs[i].hbq_buffer_list, list) {
2379 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
2380 list_del(&hbq_buf->dbuf.list);
2381 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
2383 phba->hbqs[i].buffer_count = 0;
2386 /* Mark the HBQs not in use */
2387 phba->hbq_in_use = 0;
2388 spin_unlock_irqrestore(&phba->hbalock, flags);
2392 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
2393 * @phba: Pointer to HBA context object.
2394 * @hbqno: HBQ number.
2395 * @hbq_buf: Pointer to HBQ buffer.
2397 * This function is called with the hbalock held to post a
2398 * hbq buffer to the firmware. If the function finds an empty
2399 * slot in the HBQ, it will post the buffer. The function will return
2400 * pointer to the hbq entry if it successfully post the buffer
2401 * else it will return NULL.
2404 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
2405 struct hbq_dmabuf *hbq_buf)
2407 lockdep_assert_held(&phba->hbalock);
2408 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
2412 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
2413 * @phba: Pointer to HBA context object.
2414 * @hbqno: HBQ number.
2415 * @hbq_buf: Pointer to HBQ buffer.
2417 * This function is called with the hbalock held to post a hbq buffer to the
2418 * firmware. If the function finds an empty slot in the HBQ, it will post the
2419 * buffer and place it on the hbq_buffer_list. The function will return zero if
2420 * it successfully post the buffer else it will return an error.
2423 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
2424 struct hbq_dmabuf *hbq_buf)
2426 struct lpfc_hbq_entry *hbqe;
2427 dma_addr_t physaddr = hbq_buf->dbuf.phys;
2429 lockdep_assert_held(&phba->hbalock);
2430 /* Get next HBQ entry slot to use */
2431 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
2433 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2435 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
2436 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
2437 hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
2438 hbqe->bde.tus.f.bdeFlags = 0;
2439 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
2440 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
2442 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
2443 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
2445 readl(phba->hbq_put + hbqno);
2446 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
2453 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
2454 * @phba: Pointer to HBA context object.
2455 * @hbqno: HBQ number.
2456 * @hbq_buf: Pointer to HBQ buffer.
2458 * This function is called with the hbalock held to post an RQE to the SLI4
2459 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
2460 * the hbq_buffer_list and return zero, otherwise it will return an error.
2463 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
2464 struct hbq_dmabuf *hbq_buf)
2467 struct lpfc_rqe hrqe;
2468 struct lpfc_rqe drqe;
2469 struct lpfc_queue *hrq;
2470 struct lpfc_queue *drq;
2472 if (hbqno != LPFC_ELS_HBQ)
2474 hrq = phba->sli4_hba.hdr_rq;
2475 drq = phba->sli4_hba.dat_rq;
2477 lockdep_assert_held(&phba->hbalock);
2478 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
2479 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
2480 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
2481 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
2482 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
2485 hbq_buf->tag = (rc | (hbqno << 16));
2486 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
2490 /* HBQ for ELS and CT traffic. */
2491 static struct lpfc_hbq_init lpfc_els_hbq = {
2496 .ring_mask = (1 << LPFC_ELS_RING),
2503 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
2508 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
2509 * @phba: Pointer to HBA context object.
2510 * @hbqno: HBQ number.
2511 * @count: Number of HBQ buffers to be posted.
2513 * This function is called with no lock held to post more hbq buffers to the
2514 * given HBQ. The function returns the number of HBQ buffers successfully
2518 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
2520 uint32_t i, posted = 0;
2521 unsigned long flags;
2522 struct hbq_dmabuf *hbq_buffer;
2523 LIST_HEAD(hbq_buf_list);
2524 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
2527 if ((phba->hbqs[hbqno].buffer_count + count) >
2528 lpfc_hbq_defs[hbqno]->entry_count)
2529 count = lpfc_hbq_defs[hbqno]->entry_count -
2530 phba->hbqs[hbqno].buffer_count;
2533 /* Allocate HBQ entries */
2534 for (i = 0; i < count; i++) {
2535 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
2538 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
2540 /* Check whether HBQ is still in use */
2541 spin_lock_irqsave(&phba->hbalock, flags);
2542 if (!phba->hbq_in_use)
2544 while (!list_empty(&hbq_buf_list)) {
2545 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2547 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
2549 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
2550 phba->hbqs[hbqno].buffer_count++;
2553 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2555 spin_unlock_irqrestore(&phba->hbalock, flags);
2558 spin_unlock_irqrestore(&phba->hbalock, flags);
2559 while (!list_empty(&hbq_buf_list)) {
2560 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2562 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2568 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
2569 * @phba: Pointer to HBA context object.
2572 * This function posts more buffers to the HBQ. This function
2573 * is called with no lock held. The function returns the number of HBQ entries
2574 * successfully allocated.
2577 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
2579 if (phba->sli_rev == LPFC_SLI_REV4)
2582 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2583 lpfc_hbq_defs[qno]->add_count);
2587 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2588 * @phba: Pointer to HBA context object.
2589 * @qno: HBQ queue number.
2591 * This function is called from SLI initialization code path with
2592 * no lock held to post initial HBQ buffers to firmware. The
2593 * function returns the number of HBQ entries successfully allocated.
2596 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
2598 if (phba->sli_rev == LPFC_SLI_REV4)
2599 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2600 lpfc_hbq_defs[qno]->entry_count);
2602 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2603 lpfc_hbq_defs[qno]->init_count);
2607 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2609 * This function removes the first hbq buffer on an hbq list and returns a
2610 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2612 static struct hbq_dmabuf *
2613 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
2615 struct lpfc_dmabuf *d_buf;
2617 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
2620 return container_of(d_buf, struct hbq_dmabuf, dbuf);
2624 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2625 * @phba: Pointer to HBA context object.
2628 * This function removes the first RQ buffer on an RQ buffer list and returns a
2629 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2631 static struct rqb_dmabuf *
2632 lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
2634 struct lpfc_dmabuf *h_buf;
2635 struct lpfc_rqb *rqbp;
2638 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
2639 struct lpfc_dmabuf, list);
2642 rqbp->buffer_count--;
2643 return container_of(h_buf, struct rqb_dmabuf, hbuf);
2647 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2648 * @phba: Pointer to HBA context object.
2649 * @tag: Tag of the hbq buffer.
2651 * This function searches for the hbq buffer associated with the given tag in
2652 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2653 * otherwise it returns NULL.
2655 static struct hbq_dmabuf *
2656 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
2658 struct lpfc_dmabuf *d_buf;
2659 struct hbq_dmabuf *hbq_buf;
2663 if (hbqno >= LPFC_MAX_HBQS)
2666 spin_lock_irq(&phba->hbalock);
2667 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
2668 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2669 if (hbq_buf->tag == tag) {
2670 spin_unlock_irq(&phba->hbalock);
2674 spin_unlock_irq(&phba->hbalock);
2675 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2676 "1803 Bad hbq tag. Data: x%x x%x\n",
2677 tag, phba->hbqs[tag >> 16].buffer_count);
2682 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2683 * @phba: Pointer to HBA context object.
2684 * @hbq_buffer: Pointer to HBQ buffer.
2686 * This function is called with hbalock. This function gives back
2687 * the hbq buffer to firmware. If the HBQ does not have space to
2688 * post the buffer, it will free the buffer.
2691 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2696 hbqno = hbq_buffer->tag >> 16;
2697 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2698 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2703 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2704 * @mbxCommand: mailbox command code.
2706 * This function is called by the mailbox event handler function to verify
2707 * that the completed mailbox command is a legitimate mailbox command. If the
2708 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2709 * and the mailbox event handler will take the HBA offline.
2712 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2716 switch (mbxCommand) {
2720 case MBX_WRITE_VPARMS:
2721 case MBX_RUN_BIU_DIAG:
2724 case MBX_CONFIG_LINK:
2725 case MBX_CONFIG_RING:
2726 case MBX_RESET_RING:
2727 case MBX_READ_CONFIG:
2728 case MBX_READ_RCONFIG:
2729 case MBX_READ_SPARM:
2730 case MBX_READ_STATUS:
2734 case MBX_READ_LNK_STAT:
2736 case MBX_UNREG_LOGIN:
2738 case MBX_DUMP_MEMORY:
2739 case MBX_DUMP_CONTEXT:
2742 case MBX_UPDATE_CFG:
2744 case MBX_DEL_LD_ENTRY:
2745 case MBX_RUN_PROGRAM:
2747 case MBX_SET_VARIABLE:
2748 case MBX_UNREG_D_ID:
2749 case MBX_KILL_BOARD:
2750 case MBX_CONFIG_FARP:
2753 case MBX_RUN_BIU_DIAG64:
2754 case MBX_CONFIG_PORT:
2755 case MBX_READ_SPARM64:
2756 case MBX_READ_RPI64:
2757 case MBX_REG_LOGIN64:
2758 case MBX_READ_TOPOLOGY:
2761 case MBX_LOAD_EXP_ROM:
2762 case MBX_ASYNCEVT_ENABLE:
2766 case MBX_PORT_CAPABILITIES:
2767 case MBX_PORT_IOV_CONTROL:
2768 case MBX_SLI4_CONFIG:
2769 case MBX_SLI4_REQ_FTRS:
2771 case MBX_UNREG_FCFI:
2776 case MBX_RESUME_RPI:
2777 case MBX_READ_EVENT_LOG_STATUS:
2778 case MBX_READ_EVENT_LOG:
2779 case MBX_SECURITY_MGMT:
2781 case MBX_ACCESS_VDATA:
2792 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2793 * @phba: Pointer to HBA context object.
2794 * @pmboxq: Pointer to mailbox command.
2796 * This is completion handler function for mailbox commands issued from
2797 * lpfc_sli_issue_mbox_wait function. This function is called by the
2798 * mailbox event handler function with no lock held. This function
2799 * will wake up thread waiting on the wait queue pointed by context1
2803 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2805 unsigned long drvr_flag;
2806 struct completion *pmbox_done;
2809 * If pmbox_done is empty, the driver thread gave up waiting and
2810 * continued running.
2812 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2813 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2814 pmbox_done = (struct completion *)pmboxq->context3;
2816 complete(pmbox_done);
2817 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2822 __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2824 unsigned long iflags;
2826 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
2827 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
2828 spin_lock_irqsave(&ndlp->lock, iflags);
2829 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
2830 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
2831 spin_unlock_irqrestore(&ndlp->lock, iflags);
2833 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2837 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2838 * @phba: Pointer to HBA context object.
2839 * @pmb: Pointer to mailbox object.
2841 * This function is the default mailbox completion handler. It
2842 * frees the memory resources associated with the completed mailbox
2843 * command. If the completed command is a REG_LOGIN mailbox command,
2844 * this function will issue a UREG_LOGIN to re-claim the RPI.
2847 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2849 struct lpfc_vport *vport = pmb->vport;
2850 struct lpfc_dmabuf *mp;
2851 struct lpfc_nodelist *ndlp;
2852 struct Scsi_Host *shost;
2856 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
2859 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2864 * If a REG_LOGIN succeeded after node is destroyed or node
2865 * is in re-discovery driver need to cleanup the RPI.
2867 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2868 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2869 !pmb->u.mb.mbxStatus) {
2870 rpi = pmb->u.mb.un.varWords[0];
2871 vpi = pmb->u.mb.un.varRegLogin.vpi;
2872 if (phba->sli_rev == LPFC_SLI_REV4)
2873 vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
2874 lpfc_unreg_login(phba, vpi, rpi, pmb);
2876 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2877 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2878 if (rc != MBX_NOT_FINISHED)
2882 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2883 !(phba->pport->load_flag & FC_UNLOADING) &&
2884 !pmb->u.mb.mbxStatus) {
2885 shost = lpfc_shost_from_vport(vport);
2886 spin_lock_irq(shost->host_lock);
2887 vport->vpi_state |= LPFC_VPI_REGISTERED;
2888 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2889 spin_unlock_irq(shost->host_lock);
2892 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2893 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2895 pmb->ctx_buf = NULL;
2896 pmb->ctx_ndlp = NULL;
2899 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2900 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2902 /* Check to see if there are any deferred events to process */
2906 KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
2907 "1438 UNREG cmpl deferred mbox x%x "
2908 "on NPort x%x Data: x%x x%x x%px x%x x%x\n",
2909 ndlp->nlp_rpi, ndlp->nlp_DID,
2910 ndlp->nlp_flag, ndlp->nlp_defer_did,
2911 ndlp, vport->load_flag, kref_read(&ndlp->kref));
2913 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2914 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
2915 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2916 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
2917 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2919 __lpfc_sli_rpi_release(vport, ndlp);
2922 /* The unreg_login mailbox is complete and had a
2923 * reference that has to be released. The PLOGI
2927 pmb->ctx_ndlp = NULL;
2931 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
2932 if (pmb->u.mb.mbxCommand == MBX_RESUME_RPI) {
2933 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2937 /* Check security permission status on INIT_LINK mailbox command */
2938 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2939 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2940 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2941 "2860 SLI authentication is required "
2942 "for INIT_LINK but has not done yet\n");
2944 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2945 lpfc_sli4_mbox_cmd_free(phba, pmb);
2947 mempool_free(pmb, phba->mbox_mem_pool);
2950 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2951 * @phba: Pointer to HBA context object.
2952 * @pmb: Pointer to mailbox object.
2954 * This function is the unreg rpi mailbox completion handler. It
2955 * frees the memory resources associated with the completed mailbox
2956 * command. An additional reference is put on the ndlp to prevent
2957 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2958 * the unreg mailbox command completes, this routine puts the
2963 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2965 struct lpfc_vport *vport = pmb->vport;
2966 struct lpfc_nodelist *ndlp;
2968 ndlp = pmb->ctx_ndlp;
2969 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2970 if (phba->sli_rev == LPFC_SLI_REV4 &&
2971 (bf_get(lpfc_sli_intf_if_type,
2972 &phba->sli4_hba.sli_intf) >=
2973 LPFC_SLI_INTF_IF_TYPE_2)) {
2976 vport, KERN_INFO, LOG_MBOX | LOG_SLI,
2977 "0010 UNREG_LOGIN vpi:%x "
2978 "rpi:%x DID:%x defer x%x flg x%x "
2980 vport->vpi, ndlp->nlp_rpi,
2981 ndlp->nlp_DID, ndlp->nlp_defer_did,
2984 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2986 /* Check to see if there are any deferred
2989 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2990 (ndlp->nlp_defer_did !=
2991 NLP_EVT_NOTHING_PENDING)) {
2993 vport, KERN_INFO, LOG_DISCOVERY,
2994 "4111 UNREG cmpl deferred "
2996 "NPort x%x Data: x%x x%px\n",
2997 ndlp->nlp_rpi, ndlp->nlp_DID,
2998 ndlp->nlp_defer_did, ndlp);
2999 ndlp->nlp_flag &= ~NLP_UNREG_INP;
3000 ndlp->nlp_defer_did =
3001 NLP_EVT_NOTHING_PENDING;
3002 lpfc_issue_els_plogi(
3003 vport, ndlp->nlp_DID, 0);
3005 __lpfc_sli_rpi_release(vport, ndlp);
3012 mempool_free(pmb, phba->mbox_mem_pool);
3016 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
3017 * @phba: Pointer to HBA context object.
3019 * This function is called with no lock held. This function processes all
3020 * the completed mailbox commands and gives it to upper layers. The interrupt
3021 * service routine processes mailbox completion interrupt and adds completed
3022 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
3023 * Worker thread call lpfc_sli_handle_mb_event, which will return the
3024 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
3025 * function returns the mailbox commands to the upper layer by calling the
3026 * completion handler function of each mailbox.
3029 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
3036 phba->sli.slistat.mbox_event++;
3038 /* Get all completed mailboxe buffers into the cmplq */
3039 spin_lock_irq(&phba->hbalock);
3040 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
3041 spin_unlock_irq(&phba->hbalock);
3043 /* Get a Mailbox buffer to setup mailbox commands for callback */
3045 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
3051 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
3053 lpfc_debugfs_disc_trc(pmb->vport,
3054 LPFC_DISC_TRC_MBOX_VPORT,
3055 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
3056 (uint32_t)pmbox->mbxCommand,
3057 pmbox->un.varWords[0],
3058 pmbox->un.varWords[1]);
3061 lpfc_debugfs_disc_trc(phba->pport,
3063 "MBOX cmpl: cmd:x%x mb:x%x x%x",
3064 (uint32_t)pmbox->mbxCommand,
3065 pmbox->un.varWords[0],
3066 pmbox->un.varWords[1]);
3071 * It is a fatal error if unknown mbox command completion.
3073 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
3075 /* Unknown mailbox command compl */
3076 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3077 "(%d):0323 Unknown Mailbox command "
3078 "x%x (x%x/x%x) Cmpl\n",
3079 pmb->vport ? pmb->vport->vpi :
3082 lpfc_sli_config_mbox_subsys_get(phba,
3084 lpfc_sli_config_mbox_opcode_get(phba,
3086 phba->link_state = LPFC_HBA_ERROR;
3087 phba->work_hs = HS_FFER3;
3088 lpfc_handle_eratt(phba);
3092 if (pmbox->mbxStatus) {
3093 phba->sli.slistat.mbox_stat_err++;
3094 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
3095 /* Mbox cmd cmpl error - RETRYing */
3096 lpfc_printf_log(phba, KERN_INFO,
3098 "(%d):0305 Mbox cmd cmpl "
3099 "error - RETRYing Data: x%x "
3100 "(x%x/x%x) x%x x%x x%x\n",
3101 pmb->vport ? pmb->vport->vpi :
3104 lpfc_sli_config_mbox_subsys_get(phba,
3106 lpfc_sli_config_mbox_opcode_get(phba,
3109 pmbox->un.varWords[0],
3110 pmb->vport ? pmb->vport->port_state :
3111 LPFC_VPORT_UNKNOWN);
3112 pmbox->mbxStatus = 0;
3113 pmbox->mbxOwner = OWN_HOST;
3114 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3115 if (rc != MBX_NOT_FINISHED)
3120 /* Mailbox cmd <cmd> Cmpl <cmpl> */
3121 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
3122 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
3123 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
3125 pmb->vport ? pmb->vport->vpi : 0,
3127 lpfc_sli_config_mbox_subsys_get(phba, pmb),
3128 lpfc_sli_config_mbox_opcode_get(phba, pmb),
3130 *((uint32_t *) pmbox),
3131 pmbox->un.varWords[0],
3132 pmbox->un.varWords[1],
3133 pmbox->un.varWords[2],
3134 pmbox->un.varWords[3],
3135 pmbox->un.varWords[4],
3136 pmbox->un.varWords[5],
3137 pmbox->un.varWords[6],
3138 pmbox->un.varWords[7],
3139 pmbox->un.varWords[8],
3140 pmbox->un.varWords[9],
3141 pmbox->un.varWords[10]);
3144 pmb->mbox_cmpl(phba,pmb);
3150 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
3151 * @phba: Pointer to HBA context object.
3152 * @pring: Pointer to driver SLI ring object.
3155 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
3156 * is set in the tag the buffer is posted for a particular exchange,
3157 * the function will return the buffer without replacing the buffer.
3158 * If the buffer is for unsolicited ELS or CT traffic, this function
3159 * returns the buffer and also posts another buffer to the firmware.
3161 static struct lpfc_dmabuf *
3162 lpfc_sli_get_buff(struct lpfc_hba *phba,
3163 struct lpfc_sli_ring *pring,
3166 struct hbq_dmabuf *hbq_entry;
3168 if (tag & QUE_BUFTAG_BIT)
3169 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
3170 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
3173 return &hbq_entry->dbuf;
3177 * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer
3178 * containing a NVME LS request.
3179 * @phba: pointer to lpfc hba data structure.
3180 * @piocb: pointer to the iocbq struct representing the sequence starting
3183 * This routine initially validates the NVME LS, validates there is a login
3184 * with the port that sent the LS, and then calls the appropriate nvme host
3185 * or target LS request handler.
3188 lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
3190 struct lpfc_nodelist *ndlp;
3191 struct lpfc_dmabuf *d_buf;
3192 struct hbq_dmabuf *nvmebuf;
3193 struct fc_frame_header *fc_hdr;
3194 struct lpfc_async_xchg_ctx *axchg = NULL;
3195 char *failwhy = NULL;
3196 uint32_t oxid, sid, did, fctl, size;
3199 d_buf = piocb->context2;
3201 nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
3202 fc_hdr = nvmebuf->hbuf.virt;
3203 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
3204 sid = sli4_sid_from_fc_hdr(fc_hdr);
3205 did = sli4_did_from_fc_hdr(fc_hdr);
3206 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
3207 fc_hdr->fh_f_ctl[1] << 8 |
3208 fc_hdr->fh_f_ctl[2]);
3209 size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
3211 lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n",
3214 if (phba->pport->load_flag & FC_UNLOADING) {
3215 failwhy = "Driver Unloading";
3216 } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
3217 failwhy = "NVME FC4 Disabled";
3218 } else if (!phba->nvmet_support && !phba->pport->localport) {
3219 failwhy = "No Localport";
3220 } else if (phba->nvmet_support && !phba->targetport) {
3221 failwhy = "No Targetport";
3222 } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) {
3223 failwhy = "Bad NVME LS R_CTL";
3224 } else if (unlikely((fctl & 0x00FF0000) !=
3225 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) {
3226 failwhy = "Bad NVME LS F_CTL";
3228 axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC);
3230 failwhy = "No CTX memory";
3233 if (unlikely(failwhy)) {
3234 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3235 "6154 Drop NVME LS: SID %06X OXID x%X: %s\n",
3236 sid, oxid, failwhy);
3240 /* validate the source of the LS is logged in */
3241 ndlp = lpfc_findnode_did(phba->pport, sid);
3243 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3244 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
3245 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
3246 "6216 NVME Unsol rcv: No ndlp: "
3247 "NPort_ID x%x oxid x%x\n",
3258 axchg->state = LPFC_NVME_STE_LS_RCV;
3259 axchg->entry_cnt = 1;
3260 axchg->rqb_buffer = (void *)nvmebuf;
3261 axchg->hdwq = &phba->sli4_hba.hdwq[0];
3262 axchg->payload = nvmebuf->dbuf.virt;
3263 INIT_LIST_HEAD(&axchg->list);
3265 if (phba->nvmet_support) {
3266 ret = lpfc_nvmet_handle_lsreq(phba, axchg);
3267 spin_lock_irq(&ndlp->lock);
3268 if (!ret && !(ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH)) {
3269 ndlp->fc4_xpt_flags |= NLP_XPT_HAS_HH;
3270 spin_unlock_irq(&ndlp->lock);
3272 /* This reference is a single occurrence to hold the
3273 * node valid until the nvmet transport calls
3276 if (!lpfc_nlp_get(ndlp))
3279 lpfc_printf_log(phba, KERN_ERR, LOG_NODE,
3280 "6206 NVMET unsol ls_req ndlp x%px "
3281 "DID x%x xflags x%x refcnt %d\n",
3282 ndlp, ndlp->nlp_DID,
3283 ndlp->fc4_xpt_flags,
3284 kref_read(&ndlp->kref));
3286 spin_unlock_irq(&ndlp->lock);
3289 ret = lpfc_nvme_handle_lsreq(phba, axchg);
3292 /* if zero, LS was successfully handled. If non-zero, LS not handled */
3297 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3298 "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X "
3299 "NVMe%s handler failed %d\n",
3301 (phba->nvmet_support) ? "T" : "I", ret);
3303 /* recycle receive buffer */
3304 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
3306 /* If start of new exchange, abort it */
3307 if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX)))
3308 ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
3315 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
3316 * @phba: Pointer to HBA context object.
3317 * @pring: Pointer to driver SLI ring object.
3318 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
3319 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
3320 * @fch_type: the type for the first frame of the sequence.
3322 * This function is called with no lock held. This function uses the r_ctl and
3323 * type of the received sequence to find the correct callback function to call
3324 * to process the sequence.
3327 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3328 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
3335 lpfc_nvme_unsol_ls_handler(phba, saveq);
3341 /* unSolicited Responses */
3342 if (pring->prt[0].profile) {
3343 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
3344 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
3348 /* We must search, based on rctl / type
3349 for the right routine */
3350 for (i = 0; i < pring->num_mask; i++) {
3351 if ((pring->prt[i].rctl == fch_r_ctl) &&
3352 (pring->prt[i].type == fch_type)) {
3353 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
3354 (pring->prt[i].lpfc_sli_rcv_unsol_event)
3355 (phba, pring, saveq);
3363 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
3364 * @phba: Pointer to HBA context object.
3365 * @pring: Pointer to driver SLI ring object.
3366 * @saveq: Pointer to the unsolicited iocb.
3368 * This function is called with no lock held by the ring event handler
3369 * when there is an unsolicited iocb posted to the response ring by the
3370 * firmware. This function gets the buffer associated with the iocbs
3371 * and calls the event handler for the ring. This function handles both
3372 * qring buffers and hbq buffers.
3373 * When the function returns 1 the caller can free the iocb object otherwise
3374 * upper layer functions will free the iocb objects.
3377 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3378 struct lpfc_iocbq *saveq)
3382 uint32_t Rctl, Type;
3383 struct lpfc_iocbq *iocbq;
3384 struct lpfc_dmabuf *dmzbuf;
3386 irsp = &(saveq->iocb);
3388 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
3389 if (pring->lpfc_sli_rcv_async_status)
3390 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
3392 lpfc_printf_log(phba,
3395 "0316 Ring %d handler: unexpected "
3396 "ASYNC_STATUS iocb received evt_code "
3399 irsp->un.asyncstat.evt_code);
3403 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
3404 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
3405 if (irsp->ulpBdeCount > 0) {
3406 dmzbuf = lpfc_sli_get_buff(phba, pring,
3407 irsp->un.ulpWord[3]);
3408 lpfc_in_buf_free(phba, dmzbuf);
3411 if (irsp->ulpBdeCount > 1) {
3412 dmzbuf = lpfc_sli_get_buff(phba, pring,
3413 irsp->unsli3.sli3Words[3]);
3414 lpfc_in_buf_free(phba, dmzbuf);
3417 if (irsp->ulpBdeCount > 2) {
3418 dmzbuf = lpfc_sli_get_buff(phba, pring,
3419 irsp->unsli3.sli3Words[7]);
3420 lpfc_in_buf_free(phba, dmzbuf);
3426 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3427 if (irsp->ulpBdeCount != 0) {
3428 saveq->context2 = lpfc_sli_get_buff(phba, pring,
3429 irsp->un.ulpWord[3]);
3430 if (!saveq->context2)
3431 lpfc_printf_log(phba,
3434 "0341 Ring %d Cannot find buffer for "
3435 "an unsolicited iocb. tag 0x%x\n",
3437 irsp->un.ulpWord[3]);
3439 if (irsp->ulpBdeCount == 2) {
3440 saveq->context3 = lpfc_sli_get_buff(phba, pring,
3441 irsp->unsli3.sli3Words[7]);
3442 if (!saveq->context3)
3443 lpfc_printf_log(phba,
3446 "0342 Ring %d Cannot find buffer for an"
3447 " unsolicited iocb. tag 0x%x\n",
3449 irsp->unsli3.sli3Words[7]);
3451 list_for_each_entry(iocbq, &saveq->list, list) {
3452 irsp = &(iocbq->iocb);
3453 if (irsp->ulpBdeCount != 0) {
3454 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
3455 irsp->un.ulpWord[3]);
3456 if (!iocbq->context2)
3457 lpfc_printf_log(phba,
3460 "0343 Ring %d Cannot find "
3461 "buffer for an unsolicited iocb"
3462 ". tag 0x%x\n", pring->ringno,
3463 irsp->un.ulpWord[3]);
3465 if (irsp->ulpBdeCount == 2) {
3466 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
3467 irsp->unsli3.sli3Words[7]);
3468 if (!iocbq->context3)
3469 lpfc_printf_log(phba,
3472 "0344 Ring %d Cannot find "
3473 "buffer for an unsolicited "
3476 irsp->unsli3.sli3Words[7]);
3480 if (irsp->ulpBdeCount != 0 &&
3481 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
3482 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
3485 /* search continue save q for same XRI */
3486 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
3487 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
3488 saveq->iocb.unsli3.rcvsli3.ox_id) {
3489 list_add_tail(&saveq->list, &iocbq->list);
3495 list_add_tail(&saveq->clist,
3496 &pring->iocb_continue_saveq);
3497 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
3498 list_del_init(&iocbq->clist);
3500 irsp = &(saveq->iocb);
3504 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
3505 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
3506 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
3507 Rctl = FC_RCTL_ELS_REQ;
3510 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
3511 Rctl = w5p->hcsw.Rctl;
3512 Type = w5p->hcsw.Type;
3514 /* Firmware Workaround */
3515 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
3516 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
3517 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
3518 Rctl = FC_RCTL_ELS_REQ;
3520 w5p->hcsw.Rctl = Rctl;
3521 w5p->hcsw.Type = Type;
3525 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
3526 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3527 "0313 Ring %d handler: unexpected Rctl x%x "
3528 "Type x%x received\n",
3529 pring->ringno, Rctl, Type);
3535 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
3536 * @phba: Pointer to HBA context object.
3537 * @pring: Pointer to driver SLI ring object.
3538 * @prspiocb: Pointer to response iocb object.
3540 * This function looks up the iocb_lookup table to get the command iocb
3541 * corresponding to the given response iocb using the iotag of the
3542 * response iocb. The driver calls this function with the hbalock held
3543 * for SLI3 ports or the ring lock held for SLI4 ports.
3544 * This function returns the command iocb object if it finds the command
3545 * iocb else returns NULL.
3547 static struct lpfc_iocbq *
3548 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
3549 struct lpfc_sli_ring *pring,
3550 struct lpfc_iocbq *prspiocb)
3552 struct lpfc_iocbq *cmd_iocb = NULL;
3554 spinlock_t *temp_lock = NULL;
3555 unsigned long iflag = 0;
3557 if (phba->sli_rev == LPFC_SLI_REV4)
3558 temp_lock = &pring->ring_lock;
3560 temp_lock = &phba->hbalock;
3562 spin_lock_irqsave(temp_lock, iflag);
3563 iotag = prspiocb->iocb.ulpIoTag;
3565 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3566 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3567 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3568 /* remove from txcmpl queue list */
3569 list_del_init(&cmd_iocb->list);
3570 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3571 pring->txcmplq_cnt--;
3572 spin_unlock_irqrestore(temp_lock, iflag);
3577 spin_unlock_irqrestore(temp_lock, iflag);
3578 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3579 "0317 iotag x%x is out of "
3580 "range: max iotag x%x wd0 x%x\n",
3581 iotag, phba->sli.last_iotag,
3582 *(((uint32_t *) &prspiocb->iocb) + 7));
3587 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
3588 * @phba: Pointer to HBA context object.
3589 * @pring: Pointer to driver SLI ring object.
3592 * This function looks up the iocb_lookup table to get the command iocb
3593 * corresponding to the given iotag. The driver calls this function with
3594 * the ring lock held because this function is an SLI4 port only helper.
3595 * This function returns the command iocb object if it finds the command
3596 * iocb else returns NULL.
3598 static struct lpfc_iocbq *
3599 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
3600 struct lpfc_sli_ring *pring, uint16_t iotag)
3602 struct lpfc_iocbq *cmd_iocb = NULL;
3603 spinlock_t *temp_lock = NULL;
3604 unsigned long iflag = 0;
3606 if (phba->sli_rev == LPFC_SLI_REV4)
3607 temp_lock = &pring->ring_lock;
3609 temp_lock = &phba->hbalock;
3611 spin_lock_irqsave(temp_lock, iflag);
3612 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3613 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3614 if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) {
3615 /* remove from txcmpl queue list */
3616 list_del_init(&cmd_iocb->list);
3617 cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
3618 pring->txcmplq_cnt--;
3619 spin_unlock_irqrestore(temp_lock, iflag);
3624 spin_unlock_irqrestore(temp_lock, iflag);
3625 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3626 "0372 iotag x%x lookup error: max iotag (x%x) "
3628 iotag, phba->sli.last_iotag,
3629 cmd_iocb ? cmd_iocb->iocb_flag : 0xffff);
3634 * lpfc_sli_process_sol_iocb - process solicited iocb completion
3635 * @phba: Pointer to HBA context object.
3636 * @pring: Pointer to driver SLI ring object.
3637 * @saveq: Pointer to the response iocb to be processed.
3639 * This function is called by the ring event handler for non-fcp
3640 * rings when there is a new response iocb in the response ring.
3641 * The caller is not required to hold any locks. This function
3642 * gets the command iocb associated with the response iocb and
3643 * calls the completion handler for the command iocb. If there
3644 * is no completion handler, the function will free the resources
3645 * associated with command iocb. If the response iocb is for
3646 * an already aborted command iocb, the status of the completion
3647 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
3648 * This function always returns 1.
3651 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3652 struct lpfc_iocbq *saveq)
3654 struct lpfc_iocbq *cmdiocbp;
3656 unsigned long iflag;
3658 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
3660 if (cmdiocbp->iocb_cmpl) {
3662 * If an ELS command failed send an event to mgmt
3665 if (saveq->iocb.ulpStatus &&
3666 (pring->ringno == LPFC_ELS_RING) &&
3667 (cmdiocbp->iocb.ulpCommand ==
3668 CMD_ELS_REQUEST64_CR))
3669 lpfc_send_els_failure_event(phba,
3673 * Post all ELS completions to the worker thread.
3674 * All other are passed to the completion callback.
3676 if (pring->ringno == LPFC_ELS_RING) {
3677 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3678 (cmdiocbp->iocb_flag &
3679 LPFC_DRIVER_ABORTED)) {
3680 spin_lock_irqsave(&phba->hbalock,
3682 cmdiocbp->iocb_flag &=
3683 ~LPFC_DRIVER_ABORTED;
3684 spin_unlock_irqrestore(&phba->hbalock,
3686 saveq->iocb.ulpStatus =
3687 IOSTAT_LOCAL_REJECT;
3688 saveq->iocb.un.ulpWord[4] =
3691 /* Firmware could still be in progress
3692 * of DMAing payload, so don't free data
3693 * buffer till after a hbeat.
3695 spin_lock_irqsave(&phba->hbalock,
3697 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
3698 spin_unlock_irqrestore(&phba->hbalock,
3701 if (phba->sli_rev == LPFC_SLI_REV4) {
3702 if (saveq->iocb_flag &
3703 LPFC_EXCHANGE_BUSY) {
3704 /* Set cmdiocb flag for the
3705 * exchange busy so sgl (xri)
3706 * will not be released until
3707 * the abort xri is received
3711 &phba->hbalock, iflag);
3712 cmdiocbp->iocb_flag |=
3714 spin_unlock_irqrestore(
3715 &phba->hbalock, iflag);
3717 if (cmdiocbp->iocb_flag &
3718 LPFC_DRIVER_ABORTED) {
3720 * Clear LPFC_DRIVER_ABORTED
3721 * bit in case it was driver
3725 &phba->hbalock, iflag);
3726 cmdiocbp->iocb_flag &=
3727 ~LPFC_DRIVER_ABORTED;
3728 spin_unlock_irqrestore(
3729 &phba->hbalock, iflag);
3730 cmdiocbp->iocb.ulpStatus =
3731 IOSTAT_LOCAL_REJECT;
3732 cmdiocbp->iocb.un.ulpWord[4] =
3733 IOERR_ABORT_REQUESTED;
3735 * For SLI4, irsiocb contains
3736 * NO_XRI in sli_xritag, it
3737 * shall not affect releasing
3738 * sgl (xri) process.
3740 saveq->iocb.ulpStatus =
3741 IOSTAT_LOCAL_REJECT;
3742 saveq->iocb.un.ulpWord[4] =
3745 &phba->hbalock, iflag);
3747 LPFC_DELAY_MEM_FREE;
3748 spin_unlock_irqrestore(
3749 &phba->hbalock, iflag);
3753 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
3755 lpfc_sli_release_iocbq(phba, cmdiocbp);
3758 * Unknown initiating command based on the response iotag.
3759 * This could be the case on the ELS ring because of
3762 if (pring->ringno != LPFC_ELS_RING) {
3764 * Ring <ringno> handler: unexpected completion IoTag
3767 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3768 "0322 Ring %d handler: "
3769 "unexpected completion IoTag x%x "
3770 "Data: x%x x%x x%x x%x\n",
3772 saveq->iocb.ulpIoTag,
3773 saveq->iocb.ulpStatus,
3774 saveq->iocb.un.ulpWord[4],
3775 saveq->iocb.ulpCommand,
3776 saveq->iocb.ulpContext);
3784 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
3785 * @phba: Pointer to HBA context object.
3786 * @pring: Pointer to driver SLI ring object.
3788 * This function is called from the iocb ring event handlers when
3789 * put pointer is ahead of the get pointer for a ring. This function signal
3790 * an error attention condition to the worker thread and the worker
3791 * thread will transition the HBA to offline state.
3794 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3796 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3798 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3799 * rsp ring <portRspMax>
3801 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3802 "0312 Ring %d handler: portRspPut %d "
3803 "is bigger than rsp ring %d\n",
3804 pring->ringno, le32_to_cpu(pgp->rspPutInx),
3805 pring->sli.sli3.numRiocb);
3807 phba->link_state = LPFC_HBA_ERROR;
3810 * All error attention handlers are posted to
3813 phba->work_ha |= HA_ERATT;
3814 phba->work_hs = HS_FFER3;
3816 lpfc_worker_wake_up(phba);
3822 * lpfc_poll_eratt - Error attention polling timer timeout handler
3823 * @t: Context to fetch pointer to address of HBA context object from.
3825 * This function is invoked by the Error Attention polling timer when the
3826 * timer times out. It will check the SLI Error Attention register for
3827 * possible attention events. If so, it will post an Error Attention event
3828 * and wake up worker thread to process it. Otherwise, it will set up the
3829 * Error Attention polling timer for the next poll.
3831 void lpfc_poll_eratt(struct timer_list *t)
3833 struct lpfc_hba *phba;
3835 uint64_t sli_intr, cnt;
3837 phba = from_timer(phba, t, eratt_poll);
3839 /* Here we will also keep track of interrupts per sec of the hba */
3840 sli_intr = phba->sli.slistat.sli_intr;
3842 if (phba->sli.slistat.sli_prev_intr > sli_intr)
3843 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
3846 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
3848 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3849 do_div(cnt, phba->eratt_poll_interval);
3850 phba->sli.slistat.sli_ips = cnt;
3852 phba->sli.slistat.sli_prev_intr = sli_intr;
3854 /* Check chip HA register for error event */
3855 eratt = lpfc_sli_check_eratt(phba);
3858 /* Tell the worker thread there is work to do */
3859 lpfc_worker_wake_up(phba);
3861 /* Restart the timer for next eratt poll */
3862 mod_timer(&phba->eratt_poll,
3864 msecs_to_jiffies(1000 * phba->eratt_poll_interval));
3870 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3871 * @phba: Pointer to HBA context object.
3872 * @pring: Pointer to driver SLI ring object.
3873 * @mask: Host attention register mask for this ring.
3875 * This function is called from the interrupt context when there is a ring
3876 * event for the fcp ring. The caller does not hold any lock.
3877 * The function processes each response iocb in the response ring until it
3878 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3879 * LE bit set. The function will call the completion handler of the command iocb
3880 * if the response iocb indicates a completion for a command iocb or it is
3881 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3882 * function if this is an unsolicited iocb.
3883 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3884 * to check it explicitly.
3887 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
3888 struct lpfc_sli_ring *pring, uint32_t mask)
3890 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3891 IOCB_t *irsp = NULL;
3892 IOCB_t *entry = NULL;
3893 struct lpfc_iocbq *cmdiocbq = NULL;
3894 struct lpfc_iocbq rspiocbq;
3896 uint32_t portRspPut, portRspMax;
3898 lpfc_iocb_type type;
3899 unsigned long iflag;
3900 uint32_t rsp_cmpl = 0;
3902 spin_lock_irqsave(&phba->hbalock, iflag);
3903 pring->stats.iocb_event++;
3906 * The next available response entry should never exceed the maximum
3907 * entries. If it does, treat it as an adapter hardware error.
3909 portRspMax = pring->sli.sli3.numRiocb;
3910 portRspPut = le32_to_cpu(pgp->rspPutInx);
3911 if (unlikely(portRspPut >= portRspMax)) {
3912 lpfc_sli_rsp_pointers_error(phba, pring);
3913 spin_unlock_irqrestore(&phba->hbalock, iflag);
3916 if (phba->fcp_ring_in_use) {
3917 spin_unlock_irqrestore(&phba->hbalock, iflag);
3920 phba->fcp_ring_in_use = 1;
3923 while (pring->sli.sli3.rspidx != portRspPut) {
3925 * Fetch an entry off the ring and copy it into a local data
3926 * structure. The copy involves a byte-swap since the
3927 * network byte order and pci byte orders are different.
3929 entry = lpfc_resp_iocb(phba, pring);
3930 phba->last_completion_time = jiffies;
3932 if (++pring->sli.sli3.rspidx >= portRspMax)
3933 pring->sli.sli3.rspidx = 0;
3935 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
3936 (uint32_t *) &rspiocbq.iocb,
3937 phba->iocb_rsp_size);
3938 INIT_LIST_HEAD(&(rspiocbq.list));
3939 irsp = &rspiocbq.iocb;
3941 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
3942 pring->stats.iocb_rsp++;
3945 if (unlikely(irsp->ulpStatus)) {
3947 * If resource errors reported from HBA, reduce
3948 * queuedepths of the SCSI device.
3950 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3951 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3952 IOERR_NO_RESOURCES)) {
3953 spin_unlock_irqrestore(&phba->hbalock, iflag);
3954 phba->lpfc_rampdown_queue_depth(phba);
3955 spin_lock_irqsave(&phba->hbalock, iflag);
3958 /* Rsp ring <ringno> error: IOCB */
3959 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3960 "0336 Rsp Ring %d error: IOCB Data: "
3961 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3963 irsp->un.ulpWord[0],
3964 irsp->un.ulpWord[1],
3965 irsp->un.ulpWord[2],
3966 irsp->un.ulpWord[3],
3967 irsp->un.ulpWord[4],
3968 irsp->un.ulpWord[5],
3969 *(uint32_t *)&irsp->un1,
3970 *((uint32_t *)&irsp->un1 + 1));
3974 case LPFC_ABORT_IOCB:
3977 * Idle exchange closed via ABTS from port. No iocb
3978 * resources need to be recovered.
3980 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
3981 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3982 "0333 IOCB cmd 0x%x"
3983 " processed. Skipping"
3989 spin_unlock_irqrestore(&phba->hbalock, iflag);
3990 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
3992 spin_lock_irqsave(&phba->hbalock, iflag);
3993 if (unlikely(!cmdiocbq))
3995 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED)
3996 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
3997 if (cmdiocbq->iocb_cmpl) {
3998 spin_unlock_irqrestore(&phba->hbalock, iflag);
3999 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
4001 spin_lock_irqsave(&phba->hbalock, iflag);
4004 case LPFC_UNSOL_IOCB:
4005 spin_unlock_irqrestore(&phba->hbalock, iflag);
4006 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
4007 spin_lock_irqsave(&phba->hbalock, iflag);
4010 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
4011 char adaptermsg[LPFC_MAX_ADPTMSG];
4012 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
4013 memcpy(&adaptermsg[0], (uint8_t *) irsp,
4015 dev_warn(&((phba->pcidev)->dev),
4017 phba->brd_no, adaptermsg);
4019 /* Unknown IOCB command */
4020 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4021 "0334 Unknown IOCB command "
4022 "Data: x%x, x%x x%x x%x x%x\n",
4023 type, irsp->ulpCommand,
4032 * The response IOCB has been processed. Update the ring
4033 * pointer in SLIM. If the port response put pointer has not
4034 * been updated, sync the pgp->rspPutInx and fetch the new port
4035 * response put pointer.
4037 writel(pring->sli.sli3.rspidx,
4038 &phba->host_gp[pring->ringno].rspGetInx);
4040 if (pring->sli.sli3.rspidx == portRspPut)
4041 portRspPut = le32_to_cpu(pgp->rspPutInx);
4044 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
4045 pring->stats.iocb_rsp_full++;
4046 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
4047 writel(status, phba->CAregaddr);
4048 readl(phba->CAregaddr);
4050 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
4051 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
4052 pring->stats.iocb_cmd_empty++;
4054 /* Force update of the local copy of cmdGetInx */
4055 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
4056 lpfc_sli_resume_iocb(phba, pring);
4058 if ((pring->lpfc_sli_cmd_available))
4059 (pring->lpfc_sli_cmd_available) (phba, pring);
4063 phba->fcp_ring_in_use = 0;
4064 spin_unlock_irqrestore(&phba->hbalock, iflag);
4069 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
4070 * @phba: Pointer to HBA context object.
4071 * @pring: Pointer to driver SLI ring object.
4072 * @rspiocbp: Pointer to driver response IOCB object.
4074 * This function is called from the worker thread when there is a slow-path
4075 * response IOCB to process. This function chains all the response iocbs until
4076 * seeing the iocb with the LE bit set. The function will call
4077 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
4078 * completion of a command iocb. The function will call the
4079 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
4080 * The function frees the resources or calls the completion handler if this
4081 * iocb is an abort completion. The function returns NULL when the response
4082 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
4083 * this function shall chain the iocb on to the iocb_continueq and return the
4084 * response iocb passed in.
4086 static struct lpfc_iocbq *
4087 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4088 struct lpfc_iocbq *rspiocbp)
4090 struct lpfc_iocbq *saveq;
4091 struct lpfc_iocbq *cmdiocbp;
4092 struct lpfc_iocbq *next_iocb;
4093 IOCB_t *irsp = NULL;
4094 uint32_t free_saveq;
4095 uint8_t iocb_cmd_type;
4096 lpfc_iocb_type type;
4097 unsigned long iflag;
4100 spin_lock_irqsave(&phba->hbalock, iflag);
4101 /* First add the response iocb to the countinueq list */
4102 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
4103 pring->iocb_continueq_cnt++;
4105 /* Now, determine whether the list is completed for processing */
4106 irsp = &rspiocbp->iocb;
4109 * By default, the driver expects to free all resources
4110 * associated with this iocb completion.
4113 saveq = list_get_first(&pring->iocb_continueq,
4114 struct lpfc_iocbq, list);
4115 irsp = &(saveq->iocb);
4116 list_del_init(&pring->iocb_continueq);
4117 pring->iocb_continueq_cnt = 0;
4119 pring->stats.iocb_rsp++;
4122 * If resource errors reported from HBA, reduce
4123 * queuedepths of the SCSI device.
4125 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
4126 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
4127 IOERR_NO_RESOURCES)) {
4128 spin_unlock_irqrestore(&phba->hbalock, iflag);
4129 phba->lpfc_rampdown_queue_depth(phba);
4130 spin_lock_irqsave(&phba->hbalock, iflag);
4133 if (irsp->ulpStatus) {
4134 /* Rsp ring <ringno> error: IOCB */
4135 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4136 "0328 Rsp Ring %d error: "
4141 "x%x x%x x%x x%x\n",
4143 irsp->un.ulpWord[0],
4144 irsp->un.ulpWord[1],
4145 irsp->un.ulpWord[2],
4146 irsp->un.ulpWord[3],
4147 irsp->un.ulpWord[4],
4148 irsp->un.ulpWord[5],
4149 *(((uint32_t *) irsp) + 6),
4150 *(((uint32_t *) irsp) + 7),
4151 *(((uint32_t *) irsp) + 8),
4152 *(((uint32_t *) irsp) + 9),
4153 *(((uint32_t *) irsp) + 10),
4154 *(((uint32_t *) irsp) + 11),
4155 *(((uint32_t *) irsp) + 12),
4156 *(((uint32_t *) irsp) + 13),
4157 *(((uint32_t *) irsp) + 14),
4158 *(((uint32_t *) irsp) + 15));
4162 * Fetch the IOCB command type and call the correct completion
4163 * routine. Solicited and Unsolicited IOCBs on the ELS ring
4164 * get freed back to the lpfc_iocb_list by the discovery
4167 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
4168 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
4171 spin_unlock_irqrestore(&phba->hbalock, iflag);
4172 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
4173 spin_lock_irqsave(&phba->hbalock, iflag);
4176 case LPFC_UNSOL_IOCB:
4177 spin_unlock_irqrestore(&phba->hbalock, iflag);
4178 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
4179 spin_lock_irqsave(&phba->hbalock, iflag);
4184 case LPFC_ABORT_IOCB:
4186 if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) {
4187 spin_unlock_irqrestore(&phba->hbalock, iflag);
4188 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring,
4190 spin_lock_irqsave(&phba->hbalock, iflag);
4193 /* Call the specified completion routine */
4194 if (cmdiocbp->iocb_cmpl) {
4195 spin_unlock_irqrestore(&phba->hbalock,
4197 (cmdiocbp->iocb_cmpl)(phba, cmdiocbp,
4199 spin_lock_irqsave(&phba->hbalock,
4202 __lpfc_sli_release_iocbq(phba,
4207 case LPFC_UNKNOWN_IOCB:
4208 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
4209 char adaptermsg[LPFC_MAX_ADPTMSG];
4210 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
4211 memcpy(&adaptermsg[0], (uint8_t *)irsp,
4213 dev_warn(&((phba->pcidev)->dev),
4215 phba->brd_no, adaptermsg);
4217 /* Unknown IOCB command */
4218 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4219 "0335 Unknown IOCB "
4220 "command Data: x%x "
4231 list_for_each_entry_safe(rspiocbp, next_iocb,
4232 &saveq->list, list) {
4233 list_del_init(&rspiocbp->list);
4234 __lpfc_sli_release_iocbq(phba, rspiocbp);
4236 __lpfc_sli_release_iocbq(phba, saveq);
4240 spin_unlock_irqrestore(&phba->hbalock, iflag);
4245 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
4246 * @phba: Pointer to HBA context object.
4247 * @pring: Pointer to driver SLI ring object.
4248 * @mask: Host attention register mask for this ring.
4250 * This routine wraps the actual slow_ring event process routine from the
4251 * API jump table function pointer from the lpfc_hba struct.
4254 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
4255 struct lpfc_sli_ring *pring, uint32_t mask)
4257 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
4261 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
4262 * @phba: Pointer to HBA context object.
4263 * @pring: Pointer to driver SLI ring object.
4264 * @mask: Host attention register mask for this ring.
4266 * This function is called from the worker thread when there is a ring event
4267 * for non-fcp rings. The caller does not hold any lock. The function will
4268 * remove each response iocb in the response ring and calls the handle
4269 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4272 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
4273 struct lpfc_sli_ring *pring, uint32_t mask)
4275 struct lpfc_pgp *pgp;
4277 IOCB_t *irsp = NULL;
4278 struct lpfc_iocbq *rspiocbp = NULL;
4279 uint32_t portRspPut, portRspMax;
4280 unsigned long iflag;
4283 pgp = &phba->port_gp[pring->ringno];
4284 spin_lock_irqsave(&phba->hbalock, iflag);
4285 pring->stats.iocb_event++;
4288 * The next available response entry should never exceed the maximum
4289 * entries. If it does, treat it as an adapter hardware error.
4291 portRspMax = pring->sli.sli3.numRiocb;
4292 portRspPut = le32_to_cpu(pgp->rspPutInx);
4293 if (portRspPut >= portRspMax) {
4295 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
4296 * rsp ring <portRspMax>
4298 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4299 "0303 Ring %d handler: portRspPut %d "
4300 "is bigger than rsp ring %d\n",
4301 pring->ringno, portRspPut, portRspMax);
4303 phba->link_state = LPFC_HBA_ERROR;
4304 spin_unlock_irqrestore(&phba->hbalock, iflag);
4306 phba->work_hs = HS_FFER3;
4307 lpfc_handle_eratt(phba);
4313 while (pring->sli.sli3.rspidx != portRspPut) {
4315 * Build a completion list and call the appropriate handler.
4316 * The process is to get the next available response iocb, get
4317 * a free iocb from the list, copy the response data into the
4318 * free iocb, insert to the continuation list, and update the
4319 * next response index to slim. This process makes response
4320 * iocb's in the ring available to DMA as fast as possible but
4321 * pays a penalty for a copy operation. Since the iocb is
4322 * only 32 bytes, this penalty is considered small relative to
4323 * the PCI reads for register values and a slim write. When
4324 * the ulpLe field is set, the entire Command has been
4327 entry = lpfc_resp_iocb(phba, pring);
4329 phba->last_completion_time = jiffies;
4330 rspiocbp = __lpfc_sli_get_iocbq(phba);
4331 if (rspiocbp == NULL) {
4332 printk(KERN_ERR "%s: out of buffers! Failing "
4333 "completion.\n", __func__);
4337 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
4338 phba->iocb_rsp_size);
4339 irsp = &rspiocbp->iocb;
4341 if (++pring->sli.sli3.rspidx >= portRspMax)
4342 pring->sli.sli3.rspidx = 0;
4344 if (pring->ringno == LPFC_ELS_RING) {
4345 lpfc_debugfs_slow_ring_trc(phba,
4346 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
4347 *(((uint32_t *) irsp) + 4),
4348 *(((uint32_t *) irsp) + 6),
4349 *(((uint32_t *) irsp) + 7));
4352 writel(pring->sli.sli3.rspidx,
4353 &phba->host_gp[pring->ringno].rspGetInx);
4355 spin_unlock_irqrestore(&phba->hbalock, iflag);
4356 /* Handle the response IOCB */
4357 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
4358 spin_lock_irqsave(&phba->hbalock, iflag);
4361 * If the port response put pointer has not been updated, sync
4362 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
4363 * response put pointer.
4365 if (pring->sli.sli3.rspidx == portRspPut) {
4366 portRspPut = le32_to_cpu(pgp->rspPutInx);
4368 } /* while (pring->sli.sli3.rspidx != portRspPut) */
4370 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
4371 /* At least one response entry has been freed */
4372 pring->stats.iocb_rsp_full++;
4373 /* SET RxRE_RSP in Chip Att register */
4374 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
4375 writel(status, phba->CAregaddr);
4376 readl(phba->CAregaddr); /* flush */
4378 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
4379 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
4380 pring->stats.iocb_cmd_empty++;
4382 /* Force update of the local copy of cmdGetInx */
4383 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
4384 lpfc_sli_resume_iocb(phba, pring);
4386 if ((pring->lpfc_sli_cmd_available))
4387 (pring->lpfc_sli_cmd_available) (phba, pring);
4391 spin_unlock_irqrestore(&phba->hbalock, iflag);
4396 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
4397 * @phba: Pointer to HBA context object.
4398 * @pring: Pointer to driver SLI ring object.
4399 * @mask: Host attention register mask for this ring.
4401 * This function is called from the worker thread when there is a pending
4402 * ELS response iocb on the driver internal slow-path response iocb worker
4403 * queue. The caller does not hold any lock. The function will remove each
4404 * response iocb from the response worker queue and calls the handle
4405 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4408 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
4409 struct lpfc_sli_ring *pring, uint32_t mask)
4411 struct lpfc_iocbq *irspiocbq;
4412 struct hbq_dmabuf *dmabuf;
4413 struct lpfc_cq_event *cq_event;
4414 unsigned long iflag;
4417 spin_lock_irqsave(&phba->hbalock, iflag);
4418 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
4419 spin_unlock_irqrestore(&phba->hbalock, iflag);
4420 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
4421 /* Get the response iocb from the head of work queue */
4422 spin_lock_irqsave(&phba->hbalock, iflag);
4423 list_remove_head(&phba->sli4_hba.sp_queue_event,
4424 cq_event, struct lpfc_cq_event, list);
4425 spin_unlock_irqrestore(&phba->hbalock, iflag);
4427 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
4428 case CQE_CODE_COMPL_WQE:
4429 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
4431 /* Translate ELS WCQE to response IOCBQ */
4432 irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba,
4435 lpfc_sli_sp_handle_rspiocb(phba, pring,
4439 case CQE_CODE_RECEIVE:
4440 case CQE_CODE_RECEIVE_V1:
4441 dmabuf = container_of(cq_event, struct hbq_dmabuf,
4443 lpfc_sli4_handle_received_buffer(phba, dmabuf);
4450 /* Limit the number of events to 64 to avoid soft lockups */
4457 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
4458 * @phba: Pointer to HBA context object.
4459 * @pring: Pointer to driver SLI ring object.
4461 * This function aborts all iocbs in the given ring and frees all the iocb
4462 * objects in txq. This function issues an abort iocb for all the iocb commands
4463 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4464 * the return of this function. The caller is not required to hold any locks.
4467 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
4469 LIST_HEAD(completions);
4470 struct lpfc_iocbq *iocb, *next_iocb;
4472 if (pring->ringno == LPFC_ELS_RING) {
4473 lpfc_fabric_abort_hba(phba);
4476 /* Error everything on txq and txcmplq
4479 if (phba->sli_rev >= LPFC_SLI_REV4) {
4480 spin_lock_irq(&pring->ring_lock);
4481 list_splice_init(&pring->txq, &completions);
4483 spin_unlock_irq(&pring->ring_lock);
4485 spin_lock_irq(&phba->hbalock);
4486 /* Next issue ABTS for everything on the txcmplq */
4487 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
4488 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
4489 spin_unlock_irq(&phba->hbalock);
4491 spin_lock_irq(&phba->hbalock);
4492 list_splice_init(&pring->txq, &completions);
4495 /* Next issue ABTS for everything on the txcmplq */
4496 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
4497 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
4498 spin_unlock_irq(&phba->hbalock);
4500 /* Make sure HBA is alive */
4501 lpfc_issue_hb_tmo(phba);
4503 /* Cancel all the IOCBs from the completions list */
4504 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4509 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
4510 * @phba: Pointer to HBA context object.
4512 * This function aborts all iocbs in FCP rings and frees all the iocb
4513 * objects in txq. This function issues an abort iocb for all the iocb commands
4514 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4515 * the return of this function. The caller is not required to hold any locks.
4518 lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
4520 struct lpfc_sli *psli = &phba->sli;
4521 struct lpfc_sli_ring *pring;
4524 /* Look on all the FCP Rings for the iotag */
4525 if (phba->sli_rev >= LPFC_SLI_REV4) {
4526 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4527 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4528 lpfc_sli_abort_iocb_ring(phba, pring);
4531 pring = &psli->sli3_ring[LPFC_FCP_RING];
4532 lpfc_sli_abort_iocb_ring(phba, pring);
4537 * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
4538 * @phba: Pointer to HBA context object.
4540 * This function flushes all iocbs in the IO ring and frees all the iocb
4541 * objects in txq and txcmplq. This function will not issue abort iocbs
4542 * for all the iocb commands in txcmplq, they will just be returned with
4543 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
4544 * slot has been permanently disabled.
4547 lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
4551 struct lpfc_sli *psli = &phba->sli;
4552 struct lpfc_sli_ring *pring;
4554 struct lpfc_iocbq *piocb, *next_iocb;
4556 spin_lock_irq(&phba->hbalock);
4557 if (phba->hba_flag & HBA_IOQ_FLUSH ||
4558 !phba->sli4_hba.hdwq) {
4559 spin_unlock_irq(&phba->hbalock);
4562 /* Indicate the I/O queues are flushed */
4563 phba->hba_flag |= HBA_IOQ_FLUSH;
4564 spin_unlock_irq(&phba->hbalock);
4566 /* Look on all the FCP Rings for the iotag */
4567 if (phba->sli_rev >= LPFC_SLI_REV4) {
4568 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4569 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4571 spin_lock_irq(&pring->ring_lock);
4572 /* Retrieve everything on txq */
4573 list_splice_init(&pring->txq, &txq);
4574 list_for_each_entry_safe(piocb, next_iocb,
4575 &pring->txcmplq, list)
4576 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4577 /* Retrieve everything on the txcmplq */
4578 list_splice_init(&pring->txcmplq, &txcmplq);
4580 pring->txcmplq_cnt = 0;
4581 spin_unlock_irq(&pring->ring_lock);
4584 lpfc_sli_cancel_iocbs(phba, &txq,
4585 IOSTAT_LOCAL_REJECT,
4587 /* Flush the txcmplq */
4588 lpfc_sli_cancel_iocbs(phba, &txcmplq,
4589 IOSTAT_LOCAL_REJECT,
4591 if (unlikely(pci_channel_offline(phba->pcidev)))
4592 lpfc_sli4_io_xri_aborted(phba, NULL, 0);
4595 pring = &psli->sli3_ring[LPFC_FCP_RING];
4597 spin_lock_irq(&phba->hbalock);
4598 /* Retrieve everything on txq */
4599 list_splice_init(&pring->txq, &txq);
4600 list_for_each_entry_safe(piocb, next_iocb,
4601 &pring->txcmplq, list)
4602 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
4603 /* Retrieve everything on the txcmplq */
4604 list_splice_init(&pring->txcmplq, &txcmplq);
4606 pring->txcmplq_cnt = 0;
4607 spin_unlock_irq(&phba->hbalock);
4610 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
4612 /* Flush the txcmpq */
4613 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
4619 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
4620 * @phba: Pointer to HBA context object.
4621 * @mask: Bit mask to be checked.
4623 * This function reads the host status register and compares
4624 * with the provided bit mask to check if HBA completed
4625 * the restart. This function will wait in a loop for the
4626 * HBA to complete restart. If the HBA does not restart within
4627 * 15 iterations, the function will reset the HBA again. The
4628 * function returns 1 when HBA fail to restart otherwise returns
4632 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
4638 /* Read the HBA Host Status Register */
4639 if (lpfc_readl(phba->HSregaddr, &status))
4642 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
4645 * Check status register every 100ms for 5 retries, then every
4646 * 500ms for 5, then every 2.5 sec for 5, then reset board and
4647 * every 2.5 sec for 4.
4648 * Break our of the loop if errors occurred during init.
4650 while (((status & mask) != mask) &&
4651 !(status & HS_FFERM) &&
4663 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4664 lpfc_sli_brdrestart(phba);
4666 /* Read the HBA Host Status Register */
4667 if (lpfc_readl(phba->HSregaddr, &status)) {
4673 /* Check to see if any errors occurred during init */
4674 if ((status & HS_FFERM) || (i >= 20)) {
4675 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4676 "2751 Adapter failed to restart, "
4677 "status reg x%x, FW Data: A8 x%x AC x%x\n",
4679 readl(phba->MBslimaddr + 0xa8),
4680 readl(phba->MBslimaddr + 0xac));
4681 phba->link_state = LPFC_HBA_ERROR;
4689 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
4690 * @phba: Pointer to HBA context object.
4691 * @mask: Bit mask to be checked.
4693 * This function checks the host status register to check if HBA is
4694 * ready. This function will wait in a loop for the HBA to be ready
4695 * If the HBA is not ready , the function will will reset the HBA PCI
4696 * function again. The function returns 1 when HBA fail to be ready
4697 * otherwise returns zero.
4700 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
4705 /* Read the HBA Host Status Register */
4706 status = lpfc_sli4_post_status_check(phba);
4709 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4710 lpfc_sli_brdrestart(phba);
4711 status = lpfc_sli4_post_status_check(phba);
4714 /* Check to see if any errors occurred during init */
4716 phba->link_state = LPFC_HBA_ERROR;
4719 phba->sli4_hba.intr_enable = 0;
4721 phba->hba_flag &= ~HBA_SETUP;
4726 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
4727 * @phba: Pointer to HBA context object.
4728 * @mask: Bit mask to be checked.
4730 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
4731 * from the API jump table function pointer from the lpfc_hba struct.
4734 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
4736 return phba->lpfc_sli_brdready(phba, mask);
4739 #define BARRIER_TEST_PATTERN (0xdeadbeef)
4742 * lpfc_reset_barrier - Make HBA ready for HBA reset
4743 * @phba: Pointer to HBA context object.
4745 * This function is called before resetting an HBA. This function is called
4746 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4748 void lpfc_reset_barrier(struct lpfc_hba *phba)
4750 uint32_t __iomem *resp_buf;
4751 uint32_t __iomem *mbox_buf;
4752 volatile struct MAILBOX_word0 mbox;
4753 uint32_t hc_copy, ha_copy, resp_data;
4757 lockdep_assert_held(&phba->hbalock);
4759 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
4760 if (hdrtype != 0x80 ||
4761 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
4762 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
4766 * Tell the other part of the chip to suspend temporarily all
4769 resp_buf = phba->MBslimaddr;
4771 /* Disable the error attention */
4772 if (lpfc_readl(phba->HCregaddr, &hc_copy))
4774 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
4775 readl(phba->HCregaddr); /* flush */
4776 phba->link_flag |= LS_IGNORE_ERATT;
4778 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4780 if (ha_copy & HA_ERATT) {
4781 /* Clear Chip error bit */
4782 writel(HA_ERATT, phba->HAregaddr);
4783 phba->pport->stopped = 1;
4787 mbox.mbxCommand = MBX_KILL_BOARD;
4788 mbox.mbxOwner = OWN_CHIP;
4790 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
4791 mbox_buf = phba->MBslimaddr;
4792 writel(mbox.word0, mbox_buf);
4794 for (i = 0; i < 50; i++) {
4795 if (lpfc_readl((resp_buf + 1), &resp_data))
4797 if (resp_data != ~(BARRIER_TEST_PATTERN))
4803 if (lpfc_readl((resp_buf + 1), &resp_data))
4805 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
4806 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
4807 phba->pport->stopped)
4813 mbox.mbxOwner = OWN_HOST;
4815 for (i = 0; i < 500; i++) {
4816 if (lpfc_readl(resp_buf, &resp_data))
4818 if (resp_data != mbox.word0)
4827 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4829 if (!(ha_copy & HA_ERATT))
4835 if (readl(phba->HAregaddr) & HA_ERATT) {
4836 writel(HA_ERATT, phba->HAregaddr);
4837 phba->pport->stopped = 1;
4841 phba->link_flag &= ~LS_IGNORE_ERATT;
4842 writel(hc_copy, phba->HCregaddr);
4843 readl(phba->HCregaddr); /* flush */
4847 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4848 * @phba: Pointer to HBA context object.
4850 * This function issues a kill_board mailbox command and waits for
4851 * the error attention interrupt. This function is called for stopping
4852 * the firmware processing. The caller is not required to hold any
4853 * locks. This function calls lpfc_hba_down_post function to free
4854 * any pending commands after the kill. The function will return 1 when it
4855 * fails to kill the board else will return 0.
4858 lpfc_sli_brdkill(struct lpfc_hba *phba)
4860 struct lpfc_sli *psli;
4870 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4871 "0329 Kill HBA Data: x%x x%x\n",
4872 phba->pport->port_state, psli->sli_flag);
4874 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4878 /* Disable the error attention */
4879 spin_lock_irq(&phba->hbalock);
4880 if (lpfc_readl(phba->HCregaddr, &status)) {
4881 spin_unlock_irq(&phba->hbalock);
4882 mempool_free(pmb, phba->mbox_mem_pool);
4885 status &= ~HC_ERINT_ENA;
4886 writel(status, phba->HCregaddr);
4887 readl(phba->HCregaddr); /* flush */
4888 phba->link_flag |= LS_IGNORE_ERATT;
4889 spin_unlock_irq(&phba->hbalock);
4891 lpfc_kill_board(phba, pmb);
4892 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4893 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4895 if (retval != MBX_SUCCESS) {
4896 if (retval != MBX_BUSY)
4897 mempool_free(pmb, phba->mbox_mem_pool);
4898 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4899 "2752 KILL_BOARD command failed retval %d\n",
4901 spin_lock_irq(&phba->hbalock);
4902 phba->link_flag &= ~LS_IGNORE_ERATT;
4903 spin_unlock_irq(&phba->hbalock);
4907 spin_lock_irq(&phba->hbalock);
4908 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
4909 spin_unlock_irq(&phba->hbalock);
4911 mempool_free(pmb, phba->mbox_mem_pool);
4913 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4914 * attention every 100ms for 3 seconds. If we don't get ERATT after
4915 * 3 seconds we still set HBA_ERROR state because the status of the
4916 * board is now undefined.
4918 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4920 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
4922 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4926 del_timer_sync(&psli->mbox_tmo);
4927 if (ha_copy & HA_ERATT) {
4928 writel(HA_ERATT, phba->HAregaddr);
4929 phba->pport->stopped = 1;
4931 spin_lock_irq(&phba->hbalock);
4932 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4933 psli->mbox_active = NULL;
4934 phba->link_flag &= ~LS_IGNORE_ERATT;
4935 spin_unlock_irq(&phba->hbalock);
4937 lpfc_hba_down_post(phba);
4938 phba->link_state = LPFC_HBA_ERROR;
4940 return ha_copy & HA_ERATT ? 0 : 1;
4944 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4945 * @phba: Pointer to HBA context object.
4947 * This function resets the HBA by writing HC_INITFF to the control
4948 * register. After the HBA resets, this function resets all the iocb ring
4949 * indices. This function disables PCI layer parity checking during
4951 * This function returns 0 always.
4952 * The caller is not required to hold any locks.
4955 lpfc_sli_brdreset(struct lpfc_hba *phba)
4957 struct lpfc_sli *psli;
4958 struct lpfc_sli_ring *pring;
4965 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4966 "0325 Reset HBA Data: x%x x%x\n",
4967 (phba->pport) ? phba->pport->port_state : 0,
4970 /* perform board reset */
4971 phba->fc_eventTag = 0;
4972 phba->link_events = 0;
4973 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
4975 phba->pport->fc_myDID = 0;
4976 phba->pport->fc_prevDID = 0;
4979 /* Turn off parity checking and serr during the physical reset */
4980 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
4983 pci_write_config_word(phba->pcidev, PCI_COMMAND,
4985 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
4987 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
4989 /* Now toggle INITFF bit in the Host Control Register */
4990 writel(HC_INITFF, phba->HCregaddr);
4992 readl(phba->HCregaddr); /* flush */
4993 writel(0, phba->HCregaddr);
4994 readl(phba->HCregaddr); /* flush */
4996 /* Restore PCI cmd register */
4997 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
4999 /* Initialize relevant SLI info */
5000 for (i = 0; i < psli->num_rings; i++) {
5001 pring = &psli->sli3_ring[i];
5003 pring->sli.sli3.rspidx = 0;
5004 pring->sli.sli3.next_cmdidx = 0;
5005 pring->sli.sli3.local_getidx = 0;
5006 pring->sli.sli3.cmdidx = 0;
5007 pring->missbufcnt = 0;
5010 phba->link_state = LPFC_WARM_START;
5015 * lpfc_sli4_brdreset - Reset a sli-4 HBA
5016 * @phba: Pointer to HBA context object.
5018 * This function resets a SLI4 HBA. This function disables PCI layer parity
5019 * checking during resets the device. The caller is not required to hold
5022 * This function returns 0 on success else returns negative error code.
5025 lpfc_sli4_brdreset(struct lpfc_hba *phba)
5027 struct lpfc_sli *psli = &phba->sli;
5032 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5033 "0295 Reset HBA Data: x%x x%x x%x\n",
5034 phba->pport->port_state, psli->sli_flag,
5037 /* perform board reset */
5038 phba->fc_eventTag = 0;
5039 phba->link_events = 0;
5040 phba->pport->fc_myDID = 0;
5041 phba->pport->fc_prevDID = 0;
5042 phba->hba_flag &= ~HBA_SETUP;
5044 spin_lock_irq(&phba->hbalock);
5045 psli->sli_flag &= ~(LPFC_PROCESS_LA);
5046 phba->fcf.fcf_flag = 0;
5047 spin_unlock_irq(&phba->hbalock);
5049 /* Now physically reset the device */
5050 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5051 "0389 Performing PCI function reset!\n");
5053 /* Turn off parity checking and serr during the physical reset */
5054 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
5055 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5056 "3205 PCI read Config failed\n");
5060 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
5061 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
5063 /* Perform FCoE PCI function reset before freeing queue memory */
5064 rc = lpfc_pci_function_reset(phba);
5066 /* Restore PCI cmd register */
5067 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
5073 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
5074 * @phba: Pointer to HBA context object.
5076 * This function is called in the SLI initialization code path to
5077 * restart the HBA. The caller is not required to hold any lock.
5078 * This function writes MBX_RESTART mailbox command to the SLIM and
5079 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
5080 * function to free any pending commands. The function enables
5081 * POST only during the first initialization. The function returns zero.
5082 * The function does not guarantee completion of MBX_RESTART mailbox
5083 * command before the return of this function.
5086 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
5088 volatile struct MAILBOX_word0 mb;
5089 struct lpfc_sli *psli;
5090 void __iomem *to_slim;
5091 uint32_t hba_aer_enabled;
5093 spin_lock_irq(&phba->hbalock);
5095 /* Take PCIe device Advanced Error Reporting (AER) state */
5096 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
5101 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5102 "0337 Restart HBA Data: x%x x%x\n",
5103 (phba->pport) ? phba->pport->port_state : 0,
5107 mb.mbxCommand = MBX_RESTART;
5110 lpfc_reset_barrier(phba);
5112 to_slim = phba->MBslimaddr;
5113 writel(mb.word0, to_slim);
5114 readl(to_slim); /* flush */
5116 /* Only skip post after fc_ffinit is completed */
5117 if (phba->pport && phba->pport->port_state)
5118 mb.word0 = 1; /* This is really setting up word1 */
5120 mb.word0 = 0; /* This is really setting up word1 */
5121 to_slim = phba->MBslimaddr + sizeof (uint32_t);
5122 writel(mb.word0, to_slim);
5123 readl(to_slim); /* flush */
5125 lpfc_sli_brdreset(phba);
5127 phba->pport->stopped = 0;
5128 phba->link_state = LPFC_INIT_START;
5130 spin_unlock_irq(&phba->hbalock);
5132 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
5133 psli->stats_start = ktime_get_seconds();
5135 /* Give the INITFF and Post time to settle. */
5138 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
5139 if (hba_aer_enabled)
5140 pci_disable_pcie_error_reporting(phba->pcidev);
5142 lpfc_hba_down_post(phba);
5148 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
5149 * @phba: Pointer to HBA context object.
5151 * This function is called in the SLI initialization code path to restart
5152 * a SLI4 HBA. The caller is not required to hold any lock.
5153 * At the end of the function, it calls lpfc_hba_down_post function to
5154 * free any pending commands.
5157 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
5159 struct lpfc_sli *psli = &phba->sli;
5160 uint32_t hba_aer_enabled;
5164 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5165 "0296 Restart HBA Data: x%x x%x\n",
5166 phba->pport->port_state, psli->sli_flag);
5168 /* Take PCIe device Advanced Error Reporting (AER) state */
5169 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
5171 rc = lpfc_sli4_brdreset(phba);
5173 phba->link_state = LPFC_HBA_ERROR;
5174 goto hba_down_queue;
5177 spin_lock_irq(&phba->hbalock);
5178 phba->pport->stopped = 0;
5179 phba->link_state = LPFC_INIT_START;
5181 spin_unlock_irq(&phba->hbalock);
5183 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
5184 psli->stats_start = ktime_get_seconds();
5186 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
5187 if (hba_aer_enabled)
5188 pci_disable_pcie_error_reporting(phba->pcidev);
5191 lpfc_hba_down_post(phba);
5192 lpfc_sli4_queue_destroy(phba);
5198 * lpfc_sli_brdrestart - Wrapper func for restarting hba
5199 * @phba: Pointer to HBA context object.
5201 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
5202 * API jump table function pointer from the lpfc_hba struct.
5205 lpfc_sli_brdrestart(struct lpfc_hba *phba)
5207 return phba->lpfc_sli_brdrestart(phba);
5211 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
5212 * @phba: Pointer to HBA context object.
5214 * This function is called after a HBA restart to wait for successful
5215 * restart of the HBA. Successful restart of the HBA is indicated by
5216 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
5217 * iteration, the function will restart the HBA again. The function returns
5218 * zero if HBA successfully restarted else returns negative error code.
5221 lpfc_sli_chipset_init(struct lpfc_hba *phba)
5223 uint32_t status, i = 0;
5225 /* Read the HBA Host Status Register */
5226 if (lpfc_readl(phba->HSregaddr, &status))
5229 /* Check status register to see what current state is */
5231 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
5233 /* Check every 10ms for 10 retries, then every 100ms for 90
5234 * retries, then every 1 sec for 50 retires for a total of
5235 * ~60 seconds before reset the board again and check every
5236 * 1 sec for 50 retries. The up to 60 seconds before the
5237 * board ready is required by the Falcon FIPS zeroization
5238 * complete, and any reset the board in between shall cause
5239 * restart of zeroization, further delay the board ready.
5242 /* Adapter failed to init, timeout, status reg
5244 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5245 "0436 Adapter failed to init, "
5246 "timeout, status reg x%x, "
5247 "FW Data: A8 x%x AC x%x\n", status,
5248 readl(phba->MBslimaddr + 0xa8),
5249 readl(phba->MBslimaddr + 0xac));
5250 phba->link_state = LPFC_HBA_ERROR;
5254 /* Check to see if any errors occurred during init */
5255 if (status & HS_FFERM) {
5256 /* ERROR: During chipset initialization */
5257 /* Adapter failed to init, chipset, status reg
5259 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5260 "0437 Adapter failed to init, "
5261 "chipset, status reg x%x, "
5262 "FW Data: A8 x%x AC x%x\n", status,
5263 readl(phba->MBslimaddr + 0xa8),
5264 readl(phba->MBslimaddr + 0xac));
5265 phba->link_state = LPFC_HBA_ERROR;
5278 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5279 lpfc_sli_brdrestart(phba);
5281 /* Read the HBA Host Status Register */
5282 if (lpfc_readl(phba->HSregaddr, &status))
5286 /* Check to see if any errors occurred during init */
5287 if (status & HS_FFERM) {
5288 /* ERROR: During chipset initialization */
5289 /* Adapter failed to init, chipset, status reg <status> */
5290 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5291 "0438 Adapter failed to init, chipset, "
5293 "FW Data: A8 x%x AC x%x\n", status,
5294 readl(phba->MBslimaddr + 0xa8),
5295 readl(phba->MBslimaddr + 0xac));
5296 phba->link_state = LPFC_HBA_ERROR;
5300 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
5302 /* Clear all interrupt enable conditions */
5303 writel(0, phba->HCregaddr);
5304 readl(phba->HCregaddr); /* flush */
5306 /* setup host attn register */
5307 writel(0xffffffff, phba->HAregaddr);
5308 readl(phba->HAregaddr); /* flush */
5313 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
5315 * This function calculates and returns the number of HBQs required to be
5319 lpfc_sli_hbq_count(void)
5321 return ARRAY_SIZE(lpfc_hbq_defs);
5325 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
5327 * This function adds the number of hbq entries in every HBQ to get
5328 * the total number of hbq entries required for the HBA and returns
5332 lpfc_sli_hbq_entry_count(void)
5334 int hbq_count = lpfc_sli_hbq_count();
5338 for (i = 0; i < hbq_count; ++i)
5339 count += lpfc_hbq_defs[i]->entry_count;
5344 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
5346 * This function calculates amount of memory required for all hbq entries
5347 * to be configured and returns the total memory required.
5350 lpfc_sli_hbq_size(void)
5352 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
5356 * lpfc_sli_hbq_setup - configure and initialize HBQs
5357 * @phba: Pointer to HBA context object.
5359 * This function is called during the SLI initialization to configure
5360 * all the HBQs and post buffers to the HBQ. The caller is not
5361 * required to hold any locks. This function will return zero if successful
5362 * else it will return negative error code.
5365 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
5367 int hbq_count = lpfc_sli_hbq_count();
5371 uint32_t hbq_entry_index;
5373 /* Get a Mailbox buffer to setup mailbox
5374 * commands for HBA initialization
5376 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5383 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
5384 phba->link_state = LPFC_INIT_MBX_CMDS;
5385 phba->hbq_in_use = 1;
5387 hbq_entry_index = 0;
5388 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
5389 phba->hbqs[hbqno].next_hbqPutIdx = 0;
5390 phba->hbqs[hbqno].hbqPutIdx = 0;
5391 phba->hbqs[hbqno].local_hbqGetIdx = 0;
5392 phba->hbqs[hbqno].entry_count =
5393 lpfc_hbq_defs[hbqno]->entry_count;
5394 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
5395 hbq_entry_index, pmb);
5396 hbq_entry_index += phba->hbqs[hbqno].entry_count;
5398 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
5399 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
5400 mbxStatus <status>, ring <num> */
5402 lpfc_printf_log(phba, KERN_ERR,
5403 LOG_SLI | LOG_VPORT,
5404 "1805 Adapter failed to init. "
5405 "Data: x%x x%x x%x\n",
5407 pmbox->mbxStatus, hbqno);
5409 phba->link_state = LPFC_HBA_ERROR;
5410 mempool_free(pmb, phba->mbox_mem_pool);
5414 phba->hbq_count = hbq_count;
5416 mempool_free(pmb, phba->mbox_mem_pool);
5418 /* Initially populate or replenish the HBQs */
5419 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
5420 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
5425 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
5426 * @phba: Pointer to HBA context object.
5428 * This function is called during the SLI initialization to configure
5429 * all the HBQs and post buffers to the HBQ. The caller is not
5430 * required to hold any locks. This function will return zero if successful
5431 * else it will return negative error code.
5434 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
5436 phba->hbq_in_use = 1;
5438 * Specific case when the MDS diagnostics is enabled and supported.
5439 * The receive buffer count is truncated to manage the incoming
5442 if (phba->cfg_enable_mds_diags && phba->mds_diags_support)
5443 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5444 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1;
5446 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5447 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
5448 phba->hbq_count = 1;
5449 lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
5450 /* Initially populate or replenish the HBQs */
5455 * lpfc_sli_config_port - Issue config port mailbox command
5456 * @phba: Pointer to HBA context object.
5457 * @sli_mode: sli mode - 2/3
5459 * This function is called by the sli initialization code path
5460 * to issue config_port mailbox command. This function restarts the
5461 * HBA firmware and issues a config_port mailbox command to configure
5462 * the SLI interface in the sli mode specified by sli_mode
5463 * variable. The caller is not required to hold any locks.
5464 * The function returns 0 if successful, else returns negative error
5468 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
5471 uint32_t resetcount = 0, rc = 0, done = 0;
5473 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5475 phba->link_state = LPFC_HBA_ERROR;
5479 phba->sli_rev = sli_mode;
5480 while (resetcount < 2 && !done) {
5481 spin_lock_irq(&phba->hbalock);
5482 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5483 spin_unlock_irq(&phba->hbalock);
5484 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5485 lpfc_sli_brdrestart(phba);
5486 rc = lpfc_sli_chipset_init(phba);
5490 spin_lock_irq(&phba->hbalock);
5491 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5492 spin_unlock_irq(&phba->hbalock);
5495 /* Call pre CONFIG_PORT mailbox command initialization. A
5496 * value of 0 means the call was successful. Any other
5497 * nonzero value is a failure, but if ERESTART is returned,
5498 * the driver may reset the HBA and try again.
5500 rc = lpfc_config_port_prep(phba);
5501 if (rc == -ERESTART) {
5502 phba->link_state = LPFC_LINK_UNKNOWN;
5507 phba->link_state = LPFC_INIT_MBX_CMDS;
5508 lpfc_config_port(phba, pmb);
5509 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
5510 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
5511 LPFC_SLI3_HBQ_ENABLED |
5512 LPFC_SLI3_CRP_ENABLED |
5513 LPFC_SLI3_DSS_ENABLED);
5514 if (rc != MBX_SUCCESS) {
5515 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5516 "0442 Adapter failed to init, mbxCmd x%x "
5517 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
5518 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
5519 spin_lock_irq(&phba->hbalock);
5520 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
5521 spin_unlock_irq(&phba->hbalock);
5524 /* Allow asynchronous mailbox command to go through */
5525 spin_lock_irq(&phba->hbalock);
5526 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5527 spin_unlock_irq(&phba->hbalock);
5530 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
5531 (pmb->u.mb.un.varCfgPort.gasabt == 0))
5532 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5533 "3110 Port did not grant ASABT\n");
5538 goto do_prep_failed;
5540 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
5541 if (!pmb->u.mb.un.varCfgPort.cMA) {
5543 goto do_prep_failed;
5545 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
5546 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
5547 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
5548 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
5549 phba->max_vpi : phba->max_vports;
5553 if (pmb->u.mb.un.varCfgPort.gerbm)
5554 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
5555 if (pmb->u.mb.un.varCfgPort.gcrp)
5556 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
5558 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
5559 phba->port_gp = phba->mbox->us.s3_pgp.port;
5561 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5562 if (pmb->u.mb.un.varCfgPort.gbg == 0) {
5563 phba->cfg_enable_bg = 0;
5564 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
5565 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5566 "0443 Adapter did not grant "
5571 phba->hbq_get = NULL;
5572 phba->port_gp = phba->mbox->us.s2.port;
5576 mempool_free(pmb, phba->mbox_mem_pool);
5582 * lpfc_sli_hba_setup - SLI initialization function
5583 * @phba: Pointer to HBA context object.
5585 * This function is the main SLI initialization function. This function
5586 * is called by the HBA initialization code, HBA reset code and HBA
5587 * error attention handler code. Caller is not required to hold any
5588 * locks. This function issues config_port mailbox command to configure
5589 * the SLI, setup iocb rings and HBQ rings. In the end the function
5590 * calls the config_port_post function to issue init_link mailbox
5591 * command and to start the discovery. The function will return zero
5592 * if successful, else it will return negative error code.
5595 lpfc_sli_hba_setup(struct lpfc_hba *phba)
5601 /* Enable ISR already does config_port because of config_msi mbx */
5602 if (phba->hba_flag & HBA_NEEDS_CFG_PORT) {
5603 rc = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
5606 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
5608 phba->fcp_embed_io = 0; /* SLI4 FC support only */
5610 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5611 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
5612 rc = pci_enable_pcie_error_reporting(phba->pcidev);
5614 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5615 "2709 This device supports "
5616 "Advanced Error Reporting (AER)\n");
5617 spin_lock_irq(&phba->hbalock);
5618 phba->hba_flag |= HBA_AER_ENABLED;
5619 spin_unlock_irq(&phba->hbalock);
5621 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5622 "2708 This device does not support "
5623 "Advanced Error Reporting (AER): %d\n",
5625 phba->cfg_aer_support = 0;
5629 if (phba->sli_rev == 3) {
5630 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
5631 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
5633 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
5634 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
5635 phba->sli3_options = 0;
5638 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5639 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
5640 phba->sli_rev, phba->max_vpi);
5641 rc = lpfc_sli_ring_map(phba);
5644 goto lpfc_sli_hba_setup_error;
5646 /* Initialize VPIs. */
5647 if (phba->sli_rev == LPFC_SLI_REV3) {
5649 * The VPI bitmask and physical ID array are allocated
5650 * and initialized once only - at driver load. A port
5651 * reset doesn't need to reinitialize this memory.
5653 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
5654 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
5655 phba->vpi_bmask = kcalloc(longs,
5656 sizeof(unsigned long),
5658 if (!phba->vpi_bmask) {
5660 goto lpfc_sli_hba_setup_error;
5663 phba->vpi_ids = kcalloc(phba->max_vpi + 1,
5666 if (!phba->vpi_ids) {
5667 kfree(phba->vpi_bmask);
5669 goto lpfc_sli_hba_setup_error;
5671 for (i = 0; i < phba->max_vpi; i++)
5672 phba->vpi_ids[i] = i;
5677 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5678 rc = lpfc_sli_hbq_setup(phba);
5680 goto lpfc_sli_hba_setup_error;
5682 spin_lock_irq(&phba->hbalock);
5683 phba->sli.sli_flag |= LPFC_PROCESS_LA;
5684 spin_unlock_irq(&phba->hbalock);
5686 rc = lpfc_config_port_post(phba);
5688 goto lpfc_sli_hba_setup_error;
5692 lpfc_sli_hba_setup_error:
5693 phba->link_state = LPFC_HBA_ERROR;
5694 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5695 "0445 Firmware initialization failed\n");
5700 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
5701 * @phba: Pointer to HBA context object.
5703 * This function issue a dump mailbox command to read config region
5704 * 23 and parse the records in the region and populate driver
5708 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
5710 LPFC_MBOXQ_t *mboxq;
5711 struct lpfc_dmabuf *mp;
5712 struct lpfc_mqe *mqe;
5713 uint32_t data_length;
5716 /* Program the default value of vlan_id and fc_map */
5717 phba->valid_vlan = 0;
5718 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5719 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5720 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5722 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5726 mqe = &mboxq->u.mqe;
5727 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
5729 goto out_free_mboxq;
5732 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
5733 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5735 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5736 "(%d):2571 Mailbox cmd x%x Status x%x "
5737 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5738 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5739 "CQ: x%x x%x x%x x%x\n",
5740 mboxq->vport ? mboxq->vport->vpi : 0,
5741 bf_get(lpfc_mqe_command, mqe),
5742 bf_get(lpfc_mqe_status, mqe),
5743 mqe->un.mb_words[0], mqe->un.mb_words[1],
5744 mqe->un.mb_words[2], mqe->un.mb_words[3],
5745 mqe->un.mb_words[4], mqe->un.mb_words[5],
5746 mqe->un.mb_words[6], mqe->un.mb_words[7],
5747 mqe->un.mb_words[8], mqe->un.mb_words[9],
5748 mqe->un.mb_words[10], mqe->un.mb_words[11],
5749 mqe->un.mb_words[12], mqe->un.mb_words[13],
5750 mqe->un.mb_words[14], mqe->un.mb_words[15],
5751 mqe->un.mb_words[16], mqe->un.mb_words[50],
5753 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5754 mboxq->mcqe.trailer);
5757 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5760 goto out_free_mboxq;
5762 data_length = mqe->un.mb_words[5];
5763 if (data_length > DMP_RGN23_SIZE) {
5764 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5767 goto out_free_mboxq;
5770 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
5771 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5776 mempool_free(mboxq, phba->mbox_mem_pool);
5781 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5782 * @phba: pointer to lpfc hba data structure.
5783 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5784 * @vpd: pointer to the memory to hold resulting port vpd data.
5785 * @vpd_size: On input, the number of bytes allocated to @vpd.
5786 * On output, the number of data bytes in @vpd.
5788 * This routine executes a READ_REV SLI4 mailbox command. In
5789 * addition, this routine gets the port vpd data.
5793 * -ENOMEM - could not allocated memory.
5796 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5797 uint8_t *vpd, uint32_t *vpd_size)
5801 struct lpfc_dmabuf *dmabuf;
5802 struct lpfc_mqe *mqe;
5804 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5809 * Get a DMA buffer for the vpd data resulting from the READ_REV
5812 dma_size = *vpd_size;
5813 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
5814 &dmabuf->phys, GFP_KERNEL);
5815 if (!dmabuf->virt) {
5821 * The SLI4 implementation of READ_REV conflicts at word1,
5822 * bits 31:16 and SLI4 adds vpd functionality not present
5823 * in SLI3. This code corrects the conflicts.
5825 lpfc_read_rev(phba, mboxq);
5826 mqe = &mboxq->u.mqe;
5827 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
5828 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
5829 mqe->un.read_rev.word1 &= 0x0000FFFF;
5830 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
5831 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
5833 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5835 dma_free_coherent(&phba->pcidev->dev, dma_size,
5836 dmabuf->virt, dmabuf->phys);
5842 * The available vpd length cannot be bigger than the
5843 * DMA buffer passed to the port. Catch the less than
5844 * case and update the caller's size.
5846 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
5847 *vpd_size = mqe->un.read_rev.avail_vpd_len;
5849 memcpy(vpd, dmabuf->virt, *vpd_size);
5851 dma_free_coherent(&phba->pcidev->dev, dma_size,
5852 dmabuf->virt, dmabuf->phys);
5858 * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
5859 * @phba: pointer to lpfc hba data structure.
5861 * This routine retrieves SLI4 device physical port name this PCI function
5866 * otherwise - failed to retrieve controller attributes
5869 lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
5871 LPFC_MBOXQ_t *mboxq;
5872 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
5873 struct lpfc_controller_attribute *cntl_attr;
5874 void *virtaddr = NULL;
5875 uint32_t alloclen, reqlen;
5876 uint32_t shdr_status, shdr_add_status;
5877 union lpfc_sli4_cfg_shdr *shdr;
5880 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5884 /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
5885 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
5886 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5887 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
5888 LPFC_SLI4_MBX_NEMBED);
5890 if (alloclen < reqlen) {
5891 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5892 "3084 Allocated DMA memory size (%d) is "
5893 "less than the requested DMA memory size "
5894 "(%d)\n", alloclen, reqlen);
5896 goto out_free_mboxq;
5898 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5899 virtaddr = mboxq->sge_array->addr[0];
5900 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
5901 shdr = &mbx_cntl_attr->cfg_shdr;
5902 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5903 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5904 if (shdr_status || shdr_add_status || rc) {
5905 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5906 "3085 Mailbox x%x (x%x/x%x) failed, "
5907 "rc:x%x, status:x%x, add_status:x%x\n",
5908 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5909 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
5910 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
5911 rc, shdr_status, shdr_add_status);
5913 goto out_free_mboxq;
5916 cntl_attr = &mbx_cntl_attr->cntl_attr;
5917 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
5918 phba->sli4_hba.lnk_info.lnk_tp =
5919 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
5920 phba->sli4_hba.lnk_info.lnk_no =
5921 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
5922 phba->sli4_hba.flash_id = bf_get(lpfc_cntl_attr_flash_id, cntl_attr);
5923 phba->sli4_hba.asic_rev = bf_get(lpfc_cntl_attr_asic_rev, cntl_attr);
5925 memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
5926 strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
5927 sizeof(phba->BIOSVersion));
5929 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5930 "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s, "
5931 "flash_id: x%02x, asic_rev: x%02x\n",
5932 phba->sli4_hba.lnk_info.lnk_tp,
5933 phba->sli4_hba.lnk_info.lnk_no,
5934 phba->BIOSVersion, phba->sli4_hba.flash_id,
5935 phba->sli4_hba.asic_rev);
5937 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
5938 lpfc_sli4_mbox_cmd_free(phba, mboxq);
5940 mempool_free(mboxq, phba->mbox_mem_pool);
5945 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5946 * @phba: pointer to lpfc hba data structure.
5948 * This routine retrieves SLI4 device physical port name this PCI function
5953 * otherwise - failed to retrieve physical port name
5956 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
5958 LPFC_MBOXQ_t *mboxq;
5959 struct lpfc_mbx_get_port_name *get_port_name;
5960 uint32_t shdr_status, shdr_add_status;
5961 union lpfc_sli4_cfg_shdr *shdr;
5962 char cport_name = 0;
5965 /* We assume nothing at this point */
5966 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5967 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
5969 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5972 /* obtain link type and link number via READ_CONFIG */
5973 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
5974 lpfc_sli4_read_config(phba);
5975 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
5976 goto retrieve_ppname;
5978 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5979 rc = lpfc_sli4_get_ctl_attr(phba);
5981 goto out_free_mboxq;
5984 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5985 LPFC_MBOX_OPCODE_GET_PORT_NAME,
5986 sizeof(struct lpfc_mbx_get_port_name) -
5987 sizeof(struct lpfc_sli4_cfg_mhdr),
5988 LPFC_SLI4_MBX_EMBED);
5989 get_port_name = &mboxq->u.mqe.un.get_port_name;
5990 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
5991 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
5992 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
5993 phba->sli4_hba.lnk_info.lnk_tp);
5994 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5995 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5996 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5997 if (shdr_status || shdr_add_status || rc) {
5998 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
5999 "3087 Mailbox x%x (x%x/x%x) failed: "
6000 "rc:x%x, status:x%x, add_status:x%x\n",
6001 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6002 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
6003 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
6004 rc, shdr_status, shdr_add_status);
6006 goto out_free_mboxq;
6008 switch (phba->sli4_hba.lnk_info.lnk_no) {
6009 case LPFC_LINK_NUMBER_0:
6010 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
6011 &get_port_name->u.response);
6012 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6014 case LPFC_LINK_NUMBER_1:
6015 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
6016 &get_port_name->u.response);
6017 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6019 case LPFC_LINK_NUMBER_2:
6020 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
6021 &get_port_name->u.response);
6022 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6024 case LPFC_LINK_NUMBER_3:
6025 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
6026 &get_port_name->u.response);
6027 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6033 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
6034 phba->Port[0] = cport_name;
6035 phba->Port[1] = '\0';
6036 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6037 "3091 SLI get port name: %s\n", phba->Port);
6041 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
6042 lpfc_sli4_mbox_cmd_free(phba, mboxq);
6044 mempool_free(mboxq, phba->mbox_mem_pool);
6049 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
6050 * @phba: pointer to lpfc hba data structure.
6052 * This routine is called to explicitly arm the SLI4 device's completion and
6056 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
6059 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
6060 struct lpfc_sli4_hdw_queue *qp;
6061 struct lpfc_queue *eq;
6063 sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
6064 sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
6065 if (sli4_hba->nvmels_cq)
6066 sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
6069 if (sli4_hba->hdwq) {
6070 /* Loop thru all Hardware Queues */
6071 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
6072 qp = &sli4_hba->hdwq[qidx];
6073 /* ARM the corresponding CQ */
6074 sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
6078 /* Loop thru all IRQ vectors */
6079 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
6080 eq = sli4_hba->hba_eq_hdl[qidx].eq;
6081 /* ARM the corresponding EQ */
6082 sli4_hba->sli4_write_eq_db(phba, eq,
6083 0, LPFC_QUEUE_REARM);
6087 if (phba->nvmet_support) {
6088 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
6089 sli4_hba->sli4_write_cq_db(phba,
6090 sli4_hba->nvmet_cqset[qidx], 0,
6097 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
6098 * @phba: Pointer to HBA context object.
6099 * @type: The resource extent type.
6100 * @extnt_count: buffer to hold port available extent count.
6101 * @extnt_size: buffer to hold element count per extent.
6103 * This function calls the port and retrievs the number of available
6104 * extents and their size for a particular extent type.
6106 * Returns: 0 if successful. Nonzero otherwise.
6109 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
6110 uint16_t *extnt_count, uint16_t *extnt_size)
6115 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
6118 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6122 /* Find out how many extents are available for this resource type */
6123 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
6124 sizeof(struct lpfc_sli4_cfg_mhdr));
6125 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6126 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
6127 length, LPFC_SLI4_MBX_EMBED);
6129 /* Send an extents count of 0 - the GET doesn't use it. */
6130 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6131 LPFC_SLI4_MBX_EMBED);
6137 if (!phba->sli4_hba.intr_enable)
6138 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6140 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6141 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6148 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
6149 if (bf_get(lpfc_mbox_hdr_status,
6150 &rsrc_info->header.cfg_shdr.response)) {
6151 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6152 "2930 Failed to get resource extents "
6153 "Status 0x%x Add'l Status 0x%x\n",
6154 bf_get(lpfc_mbox_hdr_status,
6155 &rsrc_info->header.cfg_shdr.response),
6156 bf_get(lpfc_mbox_hdr_add_status,
6157 &rsrc_info->header.cfg_shdr.response));
6162 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
6164 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
6167 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6168 "3162 Retrieved extents type-%d from port: count:%d, "
6169 "size:%d\n", type, *extnt_count, *extnt_size);
6172 mempool_free(mbox, phba->mbox_mem_pool);
6177 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
6178 * @phba: Pointer to HBA context object.
6179 * @type: The extent type to check.
6181 * This function reads the current available extents from the port and checks
6182 * if the extent count or extent size has changed since the last access.
6183 * Callers use this routine post port reset to understand if there is a
6184 * extent reprovisioning requirement.
6187 * -Error: error indicates problem.
6188 * 1: Extent count or size has changed.
6192 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
6194 uint16_t curr_ext_cnt, rsrc_ext_cnt;
6195 uint16_t size_diff, rsrc_ext_size;
6197 struct lpfc_rsrc_blks *rsrc_entry;
6198 struct list_head *rsrc_blk_list = NULL;
6202 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
6209 case LPFC_RSC_TYPE_FCOE_RPI:
6210 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
6212 case LPFC_RSC_TYPE_FCOE_VPI:
6213 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
6215 case LPFC_RSC_TYPE_FCOE_XRI:
6216 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
6218 case LPFC_RSC_TYPE_FCOE_VFI:
6219 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
6225 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
6227 if (rsrc_entry->rsrc_size != rsrc_ext_size)
6231 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
6238 * lpfc_sli4_cfg_post_extnts -
6239 * @phba: Pointer to HBA context object.
6240 * @extnt_cnt: number of available extents.
6241 * @type: the extent type (rpi, xri, vfi, vpi).
6242 * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation.
6243 * @mbox: pointer to the caller's allocated mailbox structure.
6245 * This function executes the extents allocation request. It also
6246 * takes care of the amount of memory needed to allocate or get the
6247 * allocated extents. It is the caller's responsibility to evaluate
6251 * -Error: Error value describes the condition found.
6255 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
6256 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
6261 uint32_t alloc_len, mbox_tmo;
6263 /* Calculate the total requested length of the dma memory */
6264 req_len = extnt_cnt * sizeof(uint16_t);
6267 * Calculate the size of an embedded mailbox. The uint32_t
6268 * accounts for extents-specific word.
6270 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
6274 * Presume the allocation and response will fit into an embedded
6275 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6277 *emb = LPFC_SLI4_MBX_EMBED;
6278 if (req_len > emb_len) {
6279 req_len = extnt_cnt * sizeof(uint16_t) +
6280 sizeof(union lpfc_sli4_cfg_shdr) +
6282 *emb = LPFC_SLI4_MBX_NEMBED;
6285 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6286 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
6288 if (alloc_len < req_len) {
6289 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6290 "2982 Allocated DMA memory size (x%x) is "
6291 "less than the requested DMA memory "
6292 "size (x%x)\n", alloc_len, req_len);
6295 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
6299 if (!phba->sli4_hba.intr_enable)
6300 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6302 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6303 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6312 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
6313 * @phba: Pointer to HBA context object.
6314 * @type: The resource extent type to allocate.
6316 * This function allocates the number of elements for the specified
6320 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
6323 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
6324 uint16_t rsrc_id, rsrc_start, j, k;
6327 unsigned long longs;
6328 unsigned long *bmask;
6329 struct lpfc_rsrc_blks *rsrc_blks;
6332 struct lpfc_id_range *id_array = NULL;
6333 void *virtaddr = NULL;
6334 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
6335 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
6336 struct list_head *ext_blk_list;
6338 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
6344 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
6345 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6346 "3009 No available Resource Extents "
6347 "for resource type 0x%x: Count: 0x%x, "
6348 "Size 0x%x\n", type, rsrc_cnt,
6353 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
6354 "2903 Post resource extents type-0x%x: "
6355 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
6357 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6361 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
6368 * Figure out where the response is located. Then get local pointers
6369 * to the response data. The port does not guarantee to respond to
6370 * all extents counts request so update the local variable with the
6371 * allocated count from the port.
6373 if (emb == LPFC_SLI4_MBX_EMBED) {
6374 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
6375 id_array = &rsrc_ext->u.rsp.id[0];
6376 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
6378 virtaddr = mbox->sge_array->addr[0];
6379 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6380 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6381 id_array = &n_rsrc->id;
6384 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
6385 rsrc_id_cnt = rsrc_cnt * rsrc_size;
6388 * Based on the resource size and count, correct the base and max
6391 length = sizeof(struct lpfc_rsrc_blks);
6393 case LPFC_RSC_TYPE_FCOE_RPI:
6394 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6395 sizeof(unsigned long),
6397 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6401 phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
6404 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6405 kfree(phba->sli4_hba.rpi_bmask);
6411 * The next_rpi was initialized with the maximum available
6412 * count but the port may allocate a smaller number. Catch
6413 * that case and update the next_rpi.
6415 phba->sli4_hba.next_rpi = rsrc_id_cnt;
6417 /* Initialize local ptrs for common extent processing later. */
6418 bmask = phba->sli4_hba.rpi_bmask;
6419 ids = phba->sli4_hba.rpi_ids;
6420 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
6422 case LPFC_RSC_TYPE_FCOE_VPI:
6423 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6425 if (unlikely(!phba->vpi_bmask)) {
6429 phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
6431 if (unlikely(!phba->vpi_ids)) {
6432 kfree(phba->vpi_bmask);
6437 /* Initialize local ptrs for common extent processing later. */
6438 bmask = phba->vpi_bmask;
6439 ids = phba->vpi_ids;
6440 ext_blk_list = &phba->lpfc_vpi_blk_list;
6442 case LPFC_RSC_TYPE_FCOE_XRI:
6443 phba->sli4_hba.xri_bmask = kcalloc(longs,
6444 sizeof(unsigned long),
6446 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6450 phba->sli4_hba.max_cfg_param.xri_used = 0;
6451 phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
6454 if (unlikely(!phba->sli4_hba.xri_ids)) {
6455 kfree(phba->sli4_hba.xri_bmask);
6460 /* Initialize local ptrs for common extent processing later. */
6461 bmask = phba->sli4_hba.xri_bmask;
6462 ids = phba->sli4_hba.xri_ids;
6463 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
6465 case LPFC_RSC_TYPE_FCOE_VFI:
6466 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6467 sizeof(unsigned long),
6469 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6473 phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
6476 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6477 kfree(phba->sli4_hba.vfi_bmask);
6482 /* Initialize local ptrs for common extent processing later. */
6483 bmask = phba->sli4_hba.vfi_bmask;
6484 ids = phba->sli4_hba.vfi_ids;
6485 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
6488 /* Unsupported Opcode. Fail call. */
6492 ext_blk_list = NULL;
6497 * Complete initializing the extent configuration with the
6498 * allocated ids assigned to this function. The bitmask serves
6499 * as an index into the array and manages the available ids. The
6500 * array just stores the ids communicated to the port via the wqes.
6502 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
6504 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
6507 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
6510 rsrc_blks = kzalloc(length, GFP_KERNEL);
6511 if (unlikely(!rsrc_blks)) {
6517 rsrc_blks->rsrc_start = rsrc_id;
6518 rsrc_blks->rsrc_size = rsrc_size;
6519 list_add_tail(&rsrc_blks->list, ext_blk_list);
6520 rsrc_start = rsrc_id;
6521 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
6522 phba->sli4_hba.io_xri_start = rsrc_start +
6523 lpfc_sli4_get_iocb_cnt(phba);
6526 while (rsrc_id < (rsrc_start + rsrc_size)) {
6531 /* Entire word processed. Get next word.*/
6536 lpfc_sli4_mbox_cmd_free(phba, mbox);
6543 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
6544 * @phba: Pointer to HBA context object.
6545 * @type: the extent's type.
6547 * This function deallocates all extents of a particular resource type.
6548 * SLI4 does not allow for deallocating a particular extent range. It
6549 * is the caller's responsibility to release all kernel memory resources.
6552 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
6555 uint32_t length, mbox_tmo = 0;
6557 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
6558 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
6560 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6565 * This function sends an embedded mailbox because it only sends the
6566 * the resource type. All extents of this type are released by the
6569 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
6570 sizeof(struct lpfc_sli4_cfg_mhdr));
6571 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6572 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
6573 length, LPFC_SLI4_MBX_EMBED);
6575 /* Send an extents count of 0 - the dealloc doesn't use it. */
6576 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6577 LPFC_SLI4_MBX_EMBED);
6582 if (!phba->sli4_hba.intr_enable)
6583 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6585 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6586 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6593 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
6594 if (bf_get(lpfc_mbox_hdr_status,
6595 &dealloc_rsrc->header.cfg_shdr.response)) {
6596 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6597 "2919 Failed to release resource extents "
6598 "for type %d - Status 0x%x Add'l Status 0x%x. "
6599 "Resource memory not released.\n",
6601 bf_get(lpfc_mbox_hdr_status,
6602 &dealloc_rsrc->header.cfg_shdr.response),
6603 bf_get(lpfc_mbox_hdr_add_status,
6604 &dealloc_rsrc->header.cfg_shdr.response));
6609 /* Release kernel memory resources for the specific type. */
6611 case LPFC_RSC_TYPE_FCOE_VPI:
6612 kfree(phba->vpi_bmask);
6613 kfree(phba->vpi_ids);
6614 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6615 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6616 &phba->lpfc_vpi_blk_list, list) {
6617 list_del_init(&rsrc_blk->list);
6620 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6622 case LPFC_RSC_TYPE_FCOE_XRI:
6623 kfree(phba->sli4_hba.xri_bmask);
6624 kfree(phba->sli4_hba.xri_ids);
6625 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6626 &phba->sli4_hba.lpfc_xri_blk_list, list) {
6627 list_del_init(&rsrc_blk->list);
6631 case LPFC_RSC_TYPE_FCOE_VFI:
6632 kfree(phba->sli4_hba.vfi_bmask);
6633 kfree(phba->sli4_hba.vfi_ids);
6634 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6635 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6636 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
6637 list_del_init(&rsrc_blk->list);
6641 case LPFC_RSC_TYPE_FCOE_RPI:
6642 /* RPI bitmask and physical id array are cleaned up earlier. */
6643 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6644 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
6645 list_del_init(&rsrc_blk->list);
6653 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6656 mempool_free(mbox, phba->mbox_mem_pool);
6661 lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
6667 len = sizeof(struct lpfc_mbx_set_feature) -
6668 sizeof(struct lpfc_sli4_cfg_mhdr);
6669 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6670 LPFC_MBOX_OPCODE_SET_FEATURES, len,
6671 LPFC_SLI4_MBX_EMBED);
6674 case LPFC_SET_UE_RECOVERY:
6675 bf_set(lpfc_mbx_set_feature_UER,
6676 &mbox->u.mqe.un.set_feature, 1);
6677 mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
6678 mbox->u.mqe.un.set_feature.param_len = 8;
6680 case LPFC_SET_MDS_DIAGS:
6681 bf_set(lpfc_mbx_set_feature_mds,
6682 &mbox->u.mqe.un.set_feature, 1);
6683 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
6684 &mbox->u.mqe.un.set_feature, 1);
6685 mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
6686 mbox->u.mqe.un.set_feature.param_len = 8;
6688 case LPFC_SET_CGN_SIGNAL:
6689 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6692 sig_freq = phba->cgn_sig_freq;
6694 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6695 bf_set(lpfc_mbx_set_feature_CGN_alarm_freq,
6696 &mbox->u.mqe.un.set_feature, sig_freq);
6697 bf_set(lpfc_mbx_set_feature_CGN_warn_freq,
6698 &mbox->u.mqe.un.set_feature, sig_freq);
6701 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY)
6702 bf_set(lpfc_mbx_set_feature_CGN_warn_freq,
6703 &mbox->u.mqe.un.set_feature, sig_freq);
6705 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
6706 phba->cgn_reg_signal == EDC_CG_SIG_NOTSUPPORTED)
6709 sig_freq = lpfc_acqe_cgn_frequency;
6711 bf_set(lpfc_mbx_set_feature_CGN_acqe_freq,
6712 &mbox->u.mqe.un.set_feature, sig_freq);
6714 mbox->u.mqe.un.set_feature.feature = LPFC_SET_CGN_SIGNAL;
6715 mbox->u.mqe.un.set_feature.param_len = 12;
6717 case LPFC_SET_DUAL_DUMP:
6718 bf_set(lpfc_mbx_set_feature_dd,
6719 &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP);
6720 bf_set(lpfc_mbx_set_feature_ddquery,
6721 &mbox->u.mqe.un.set_feature, 0);
6722 mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP;
6723 mbox->u.mqe.un.set_feature.param_len = 4;
6725 case LPFC_SET_ENABLE_MI:
6726 mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_MI;
6727 mbox->u.mqe.un.set_feature.param_len = 4;
6728 bf_set(lpfc_mbx_set_feature_milunq, &mbox->u.mqe.un.set_feature,
6729 phba->pport->cfg_lun_queue_depth);
6730 bf_set(lpfc_mbx_set_feature_mi, &mbox->u.mqe.un.set_feature,
6731 phba->sli4_hba.pc_sli4_params.mi_ver);
6733 case LPFC_SET_ENABLE_CMF:
6734 bf_set(lpfc_mbx_set_feature_dd, &mbox->u.mqe.un.set_feature, 1);
6735 mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_CMF;
6736 mbox->u.mqe.un.set_feature.param_len = 4;
6737 bf_set(lpfc_mbx_set_feature_cmf,
6738 &mbox->u.mqe.un.set_feature, 1);
6745 * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
6746 * @phba: Pointer to HBA context object.
6748 * Disable FW logging into host memory on the adapter. To
6749 * be done before reading logs from the host memory.
6752 lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
6754 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6756 spin_lock_irq(&phba->hbalock);
6757 ras_fwlog->state = INACTIVE;
6758 spin_unlock_irq(&phba->hbalock);
6760 /* Disable FW logging to host memory */
6761 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
6762 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
6764 /* Wait 10ms for firmware to stop using DMA buffer */
6765 usleep_range(10 * 1000, 20 * 1000);
6769 * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
6770 * @phba: Pointer to HBA context object.
6772 * This function is called to free memory allocated for RAS FW logging
6773 * support in the driver.
6776 lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
6778 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6779 struct lpfc_dmabuf *dmabuf, *next;
6781 if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
6782 list_for_each_entry_safe(dmabuf, next,
6783 &ras_fwlog->fwlog_buff_list,
6785 list_del(&dmabuf->list);
6786 dma_free_coherent(&phba->pcidev->dev,
6787 LPFC_RAS_MAX_ENTRY_SIZE,
6788 dmabuf->virt, dmabuf->phys);
6793 if (ras_fwlog->lwpd.virt) {
6794 dma_free_coherent(&phba->pcidev->dev,
6795 sizeof(uint32_t) * 2,
6796 ras_fwlog->lwpd.virt,
6797 ras_fwlog->lwpd.phys);
6798 ras_fwlog->lwpd.virt = NULL;
6801 spin_lock_irq(&phba->hbalock);
6802 ras_fwlog->state = INACTIVE;
6803 spin_unlock_irq(&phba->hbalock);
6807 * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
6808 * @phba: Pointer to HBA context object.
6809 * @fwlog_buff_count: Count of buffers to be created.
6811 * This routine DMA memory for Log Write Position Data[LPWD] and buffer
6812 * to update FW log is posted to the adapter.
6813 * Buffer count is calculated based on module param ras_fwlog_buffsize
6814 * Size of each buffer posted to FW is 64K.
6818 lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
6819 uint32_t fwlog_buff_count)
6821 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6822 struct lpfc_dmabuf *dmabuf;
6825 /* Initialize List */
6826 INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
6828 /* Allocate memory for the LWPD */
6829 ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
6830 sizeof(uint32_t) * 2,
6831 &ras_fwlog->lwpd.phys,
6833 if (!ras_fwlog->lwpd.virt) {
6834 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6835 "6185 LWPD Memory Alloc Failed\n");
6840 ras_fwlog->fw_buffcount = fwlog_buff_count;
6841 for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
6842 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
6846 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6847 "6186 Memory Alloc failed FW logging");
6851 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6852 LPFC_RAS_MAX_ENTRY_SIZE,
6853 &dmabuf->phys, GFP_KERNEL);
6854 if (!dmabuf->virt) {
6857 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6858 "6187 DMA Alloc Failed FW logging");
6861 dmabuf->buffer_tag = i;
6862 list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
6867 lpfc_sli4_ras_dma_free(phba);
6873 * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
6874 * @phba: pointer to lpfc hba data structure.
6875 * @pmb: pointer to the driver internal queue element for mailbox command.
6877 * Completion handler for driver's RAS MBX command to the device.
6880 lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6883 union lpfc_sli4_cfg_shdr *shdr;
6884 uint32_t shdr_status, shdr_add_status;
6885 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6889 shdr = (union lpfc_sli4_cfg_shdr *)
6890 &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
6891 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6892 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6894 if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
6895 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6896 "6188 FW LOG mailbox "
6897 "completed with status x%x add_status x%x,"
6898 " mbx status x%x\n",
6899 shdr_status, shdr_add_status, mb->mbxStatus);
6901 ras_fwlog->ras_hwsupport = false;
6905 spin_lock_irq(&phba->hbalock);
6906 ras_fwlog->state = ACTIVE;
6907 spin_unlock_irq(&phba->hbalock);
6908 mempool_free(pmb, phba->mbox_mem_pool);
6913 /* Free RAS DMA memory */
6914 lpfc_sli4_ras_dma_free(phba);
6915 mempool_free(pmb, phba->mbox_mem_pool);
6919 * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
6920 * @phba: pointer to lpfc hba data structure.
6921 * @fwlog_level: Logging verbosity level.
6922 * @fwlog_enable: Enable/Disable logging.
6924 * Initialize memory and post mailbox command to enable FW logging in host
6928 lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
6929 uint32_t fwlog_level,
6930 uint32_t fwlog_enable)
6932 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6933 struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
6934 struct lpfc_dmabuf *dmabuf;
6936 uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
6939 spin_lock_irq(&phba->hbalock);
6940 ras_fwlog->state = INACTIVE;
6941 spin_unlock_irq(&phba->hbalock);
6943 fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
6944 phba->cfg_ras_fwlog_buffsize);
6945 fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
6948 * If re-enabling FW logging support use earlier allocated
6949 * DMA buffers while posting MBX command.
6951 if (!ras_fwlog->lwpd.virt) {
6952 rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
6954 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6955 "6189 FW Log Memory Allocation Failed");
6960 /* Setup Mailbox command */
6961 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6963 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6964 "6190 RAS MBX Alloc Failed");
6969 ras_fwlog->fw_loglevel = fwlog_level;
6970 len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
6971 sizeof(struct lpfc_sli4_cfg_mhdr));
6973 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
6974 LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
6975 len, LPFC_SLI4_MBX_EMBED);
6977 mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
6978 bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
6980 bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
6981 ras_fwlog->fw_loglevel);
6982 bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
6983 ras_fwlog->fw_buffcount);
6984 bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
6985 LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
6987 /* Update DMA buffer address */
6988 list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
6989 memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
6991 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
6992 putPaddrLow(dmabuf->phys);
6994 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
6995 putPaddrHigh(dmabuf->phys);
6998 /* Update LPWD address */
6999 mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
7000 mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
7002 spin_lock_irq(&phba->hbalock);
7003 ras_fwlog->state = REG_INPROGRESS;
7004 spin_unlock_irq(&phba->hbalock);
7005 mbox->vport = phba->pport;
7006 mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
7008 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7010 if (rc == MBX_NOT_FINISHED) {
7011 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7012 "6191 FW-Log Mailbox failed. "
7013 "status %d mbxStatus : x%x", rc,
7014 bf_get(lpfc_mqe_status, &mbox->u.mqe));
7015 mempool_free(mbox, phba->mbox_mem_pool);
7022 lpfc_sli4_ras_dma_free(phba);
7028 * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
7029 * @phba: Pointer to HBA context object.
7031 * Check if RAS is supported on the adapter and initialize it.
7034 lpfc_sli4_ras_setup(struct lpfc_hba *phba)
7036 /* Check RAS FW Log needs to be enabled or not */
7037 if (lpfc_check_fwlog_support(phba))
7040 lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
7041 LPFC_RAS_ENABLE_LOGGING);
7045 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
7046 * @phba: Pointer to HBA context object.
7048 * This function allocates all SLI4 resource identifiers.
7051 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
7053 int i, rc, error = 0;
7054 uint16_t count, base;
7055 unsigned long longs;
7057 if (!phba->sli4_hba.rpi_hdrs_in_use)
7058 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
7059 if (phba->sli4_hba.extents_in_use) {
7061 * The port supports resource extents. The XRI, VPI, VFI, RPI
7062 * resource extent count must be read and allocated before
7063 * provisioning the resource id arrays.
7065 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
7066 LPFC_IDX_RSRC_RDY) {
7068 * Extent-based resources are set - the driver could
7069 * be in a port reset. Figure out if any corrective
7070 * actions need to be taken.
7072 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7073 LPFC_RSC_TYPE_FCOE_VFI);
7076 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7077 LPFC_RSC_TYPE_FCOE_VPI);
7080 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7081 LPFC_RSC_TYPE_FCOE_XRI);
7084 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7085 LPFC_RSC_TYPE_FCOE_RPI);
7090 * It's possible that the number of resources
7091 * provided to this port instance changed between
7092 * resets. Detect this condition and reallocate
7093 * resources. Otherwise, there is no action.
7096 lpfc_printf_log(phba, KERN_INFO,
7097 LOG_MBOX | LOG_INIT,
7098 "2931 Detected extent resource "
7099 "change. Reallocating all "
7101 rc = lpfc_sli4_dealloc_extent(phba,
7102 LPFC_RSC_TYPE_FCOE_VFI);
7103 rc = lpfc_sli4_dealloc_extent(phba,
7104 LPFC_RSC_TYPE_FCOE_VPI);
7105 rc = lpfc_sli4_dealloc_extent(phba,
7106 LPFC_RSC_TYPE_FCOE_XRI);
7107 rc = lpfc_sli4_dealloc_extent(phba,
7108 LPFC_RSC_TYPE_FCOE_RPI);
7113 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
7117 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
7121 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
7125 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
7128 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
7133 * The port does not support resource extents. The XRI, VPI,
7134 * VFI, RPI resource ids were determined from READ_CONFIG.
7135 * Just allocate the bitmasks and provision the resource id
7136 * arrays. If a port reset is active, the resources don't
7137 * need any action - just exit.
7139 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
7140 LPFC_IDX_RSRC_RDY) {
7141 lpfc_sli4_dealloc_resource_identifiers(phba);
7142 lpfc_sli4_remove_rpis(phba);
7145 count = phba->sli4_hba.max_cfg_param.max_rpi;
7147 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7148 "3279 Invalid provisioning of "
7153 base = phba->sli4_hba.max_cfg_param.rpi_base;
7154 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7155 phba->sli4_hba.rpi_bmask = kcalloc(longs,
7156 sizeof(unsigned long),
7158 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
7162 phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
7164 if (unlikely(!phba->sli4_hba.rpi_ids)) {
7166 goto free_rpi_bmask;
7169 for (i = 0; i < count; i++)
7170 phba->sli4_hba.rpi_ids[i] = base + i;
7173 count = phba->sli4_hba.max_cfg_param.max_vpi;
7175 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7176 "3280 Invalid provisioning of "
7181 base = phba->sli4_hba.max_cfg_param.vpi_base;
7182 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7183 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
7185 if (unlikely(!phba->vpi_bmask)) {
7189 phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
7191 if (unlikely(!phba->vpi_ids)) {
7193 goto free_vpi_bmask;
7196 for (i = 0; i < count; i++)
7197 phba->vpi_ids[i] = base + i;
7200 count = phba->sli4_hba.max_cfg_param.max_xri;
7202 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7203 "3281 Invalid provisioning of "
7208 base = phba->sli4_hba.max_cfg_param.xri_base;
7209 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7210 phba->sli4_hba.xri_bmask = kcalloc(longs,
7211 sizeof(unsigned long),
7213 if (unlikely(!phba->sli4_hba.xri_bmask)) {
7217 phba->sli4_hba.max_cfg_param.xri_used = 0;
7218 phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
7220 if (unlikely(!phba->sli4_hba.xri_ids)) {
7222 goto free_xri_bmask;
7225 for (i = 0; i < count; i++)
7226 phba->sli4_hba.xri_ids[i] = base + i;
7229 count = phba->sli4_hba.max_cfg_param.max_vfi;
7231 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7232 "3282 Invalid provisioning of "
7237 base = phba->sli4_hba.max_cfg_param.vfi_base;
7238 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7239 phba->sli4_hba.vfi_bmask = kcalloc(longs,
7240 sizeof(unsigned long),
7242 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
7246 phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
7248 if (unlikely(!phba->sli4_hba.vfi_ids)) {
7250 goto free_vfi_bmask;
7253 for (i = 0; i < count; i++)
7254 phba->sli4_hba.vfi_ids[i] = base + i;
7257 * Mark all resources ready. An HBA reset doesn't need
7258 * to reset the initialization.
7260 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
7266 kfree(phba->sli4_hba.vfi_bmask);
7267 phba->sli4_hba.vfi_bmask = NULL;
7269 kfree(phba->sli4_hba.xri_ids);
7270 phba->sli4_hba.xri_ids = NULL;
7272 kfree(phba->sli4_hba.xri_bmask);
7273 phba->sli4_hba.xri_bmask = NULL;
7275 kfree(phba->vpi_ids);
7276 phba->vpi_ids = NULL;
7278 kfree(phba->vpi_bmask);
7279 phba->vpi_bmask = NULL;
7281 kfree(phba->sli4_hba.rpi_ids);
7282 phba->sli4_hba.rpi_ids = NULL;
7284 kfree(phba->sli4_hba.rpi_bmask);
7285 phba->sli4_hba.rpi_bmask = NULL;
7291 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
7292 * @phba: Pointer to HBA context object.
7294 * This function allocates the number of elements for the specified
7298 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
7300 if (phba->sli4_hba.extents_in_use) {
7301 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
7302 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
7303 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
7304 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
7306 kfree(phba->vpi_bmask);
7307 phba->sli4_hba.max_cfg_param.vpi_used = 0;
7308 kfree(phba->vpi_ids);
7309 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7310 kfree(phba->sli4_hba.xri_bmask);
7311 kfree(phba->sli4_hba.xri_ids);
7312 kfree(phba->sli4_hba.vfi_bmask);
7313 kfree(phba->sli4_hba.vfi_ids);
7314 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7315 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7322 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
7323 * @phba: Pointer to HBA context object.
7324 * @type: The resource extent type.
7325 * @extnt_cnt: buffer to hold port extent count response
7326 * @extnt_size: buffer to hold port extent size response.
7328 * This function calls the port to read the host allocated extents
7329 * for a particular type.
7332 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
7333 uint16_t *extnt_cnt, uint16_t *extnt_size)
7337 uint16_t curr_blks = 0;
7338 uint32_t req_len, emb_len;
7339 uint32_t alloc_len, mbox_tmo;
7340 struct list_head *blk_list_head;
7341 struct lpfc_rsrc_blks *rsrc_blk;
7343 void *virtaddr = NULL;
7344 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
7345 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
7346 union lpfc_sli4_cfg_shdr *shdr;
7349 case LPFC_RSC_TYPE_FCOE_VPI:
7350 blk_list_head = &phba->lpfc_vpi_blk_list;
7352 case LPFC_RSC_TYPE_FCOE_XRI:
7353 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
7355 case LPFC_RSC_TYPE_FCOE_VFI:
7356 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
7358 case LPFC_RSC_TYPE_FCOE_RPI:
7359 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
7365 /* Count the number of extents currently allocatd for this type. */
7366 list_for_each_entry(rsrc_blk, blk_list_head, list) {
7367 if (curr_blks == 0) {
7369 * The GET_ALLOCATED mailbox does not return the size,
7370 * just the count. The size should be just the size
7371 * stored in the current allocated block and all sizes
7372 * for an extent type are the same so set the return
7375 *extnt_size = rsrc_blk->rsrc_size;
7381 * Calculate the size of an embedded mailbox. The uint32_t
7382 * accounts for extents-specific word.
7384 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
7388 * Presume the allocation and response will fit into an embedded
7389 * mailbox. If not true, reconfigure to a non-embedded mailbox.
7391 emb = LPFC_SLI4_MBX_EMBED;
7393 if (req_len > emb_len) {
7394 req_len = curr_blks * sizeof(uint16_t) +
7395 sizeof(union lpfc_sli4_cfg_shdr) +
7397 emb = LPFC_SLI4_MBX_NEMBED;
7400 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7403 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
7405 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7406 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
7408 if (alloc_len < req_len) {
7409 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7410 "2983 Allocated DMA memory size (x%x) is "
7411 "less than the requested DMA memory "
7412 "size (x%x)\n", alloc_len, req_len);
7416 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
7422 if (!phba->sli4_hba.intr_enable)
7423 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
7425 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
7426 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
7435 * Figure out where the response is located. Then get local pointers
7436 * to the response data. The port does not guarantee to respond to
7437 * all extents counts request so update the local variable with the
7438 * allocated count from the port.
7440 if (emb == LPFC_SLI4_MBX_EMBED) {
7441 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
7442 shdr = &rsrc_ext->header.cfg_shdr;
7443 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
7445 virtaddr = mbox->sge_array->addr[0];
7446 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
7447 shdr = &n_rsrc->cfg_shdr;
7448 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
7451 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
7452 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7453 "2984 Failed to read allocated resources "
7454 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
7456 bf_get(lpfc_mbox_hdr_status, &shdr->response),
7457 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
7462 lpfc_sli4_mbox_cmd_free(phba, mbox);
7467 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
7468 * @phba: pointer to lpfc hba data structure.
7469 * @sgl_list: linked link of sgl buffers to post
7470 * @cnt: number of linked list buffers
7472 * This routine walks the list of buffers that have been allocated and
7473 * repost them to the port by using SGL block post. This is needed after a
7474 * pci_function_reset/warm_start or start. It attempts to construct blocks
7475 * of buffer sgls which contains contiguous xris and uses the non-embedded
7476 * SGL block post mailbox commands to post them to the port. For single
7477 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
7478 * mailbox command for posting.
7480 * Returns: 0 = success, non-zero failure.
7483 lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
7484 struct list_head *sgl_list, int cnt)
7486 struct lpfc_sglq *sglq_entry = NULL;
7487 struct lpfc_sglq *sglq_entry_next = NULL;
7488 struct lpfc_sglq *sglq_entry_first = NULL;
7489 int status, total_cnt;
7490 int post_cnt = 0, num_posted = 0, block_cnt = 0;
7491 int last_xritag = NO_XRI;
7492 LIST_HEAD(prep_sgl_list);
7493 LIST_HEAD(blck_sgl_list);
7494 LIST_HEAD(allc_sgl_list);
7495 LIST_HEAD(post_sgl_list);
7496 LIST_HEAD(free_sgl_list);
7498 spin_lock_irq(&phba->hbalock);
7499 spin_lock(&phba->sli4_hba.sgl_list_lock);
7500 list_splice_init(sgl_list, &allc_sgl_list);
7501 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7502 spin_unlock_irq(&phba->hbalock);
7505 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
7506 &allc_sgl_list, list) {
7507 list_del_init(&sglq_entry->list);
7509 if ((last_xritag != NO_XRI) &&
7510 (sglq_entry->sli4_xritag != last_xritag + 1)) {
7511 /* a hole in xri block, form a sgl posting block */
7512 list_splice_init(&prep_sgl_list, &blck_sgl_list);
7513 post_cnt = block_cnt - 1;
7514 /* prepare list for next posting block */
7515 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7518 /* prepare list for next posting block */
7519 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7520 /* enough sgls for non-embed sgl mbox command */
7521 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
7522 list_splice_init(&prep_sgl_list,
7524 post_cnt = block_cnt;
7530 /* keep track of last sgl's xritag */
7531 last_xritag = sglq_entry->sli4_xritag;
7533 /* end of repost sgl list condition for buffers */
7534 if (num_posted == total_cnt) {
7535 if (post_cnt == 0) {
7536 list_splice_init(&prep_sgl_list,
7538 post_cnt = block_cnt;
7539 } else if (block_cnt == 1) {
7540 status = lpfc_sli4_post_sgl(phba,
7541 sglq_entry->phys, 0,
7542 sglq_entry->sli4_xritag);
7544 /* successful, put sgl to posted list */
7545 list_add_tail(&sglq_entry->list,
7548 /* Failure, put sgl to free list */
7549 lpfc_printf_log(phba, KERN_WARNING,
7551 "3159 Failed to post "
7552 "sgl, xritag:x%x\n",
7553 sglq_entry->sli4_xritag);
7554 list_add_tail(&sglq_entry->list,
7561 /* continue until a nembed page worth of sgls */
7565 /* post the buffer list sgls as a block */
7566 status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
7570 /* success, put sgl list to posted sgl list */
7571 list_splice_init(&blck_sgl_list, &post_sgl_list);
7573 /* Failure, put sgl list to free sgl list */
7574 sglq_entry_first = list_first_entry(&blck_sgl_list,
7577 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7578 "3160 Failed to post sgl-list, "
7580 sglq_entry_first->sli4_xritag,
7581 (sglq_entry_first->sli4_xritag +
7583 list_splice_init(&blck_sgl_list, &free_sgl_list);
7584 total_cnt -= post_cnt;
7587 /* don't reset xirtag due to hole in xri block */
7589 last_xritag = NO_XRI;
7591 /* reset sgl post count for next round of posting */
7595 /* free the sgls failed to post */
7596 lpfc_free_sgl_list(phba, &free_sgl_list);
7598 /* push sgls posted to the available list */
7599 if (!list_empty(&post_sgl_list)) {
7600 spin_lock_irq(&phba->hbalock);
7601 spin_lock(&phba->sli4_hba.sgl_list_lock);
7602 list_splice_init(&post_sgl_list, sgl_list);
7603 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7604 spin_unlock_irq(&phba->hbalock);
7606 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7607 "3161 Failure to post sgl to port.\n");
7611 /* return the number of XRIs actually posted */
7616 * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
7617 * @phba: pointer to lpfc hba data structure.
7619 * This routine walks the list of nvme buffers that have been allocated and
7620 * repost them to the port by using SGL block post. This is needed after a
7621 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
7622 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
7623 * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
7625 * Returns: 0 = success, non-zero failure.
7628 lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
7630 LIST_HEAD(post_nblist);
7631 int num_posted, rc = 0;
7633 /* get all NVME buffers need to repost to a local list */
7634 lpfc_io_buf_flush(phba, &post_nblist);
7636 /* post the list of nvme buffer sgls to port if available */
7637 if (!list_empty(&post_nblist)) {
7638 num_posted = lpfc_sli4_post_io_sgl_list(
7639 phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
7640 /* failed to post any nvme buffer, return error */
7641 if (num_posted == 0)
7648 lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
7652 len = sizeof(struct lpfc_mbx_set_host_data) -
7653 sizeof(struct lpfc_sli4_cfg_mhdr);
7654 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7655 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
7656 LPFC_SLI4_MBX_EMBED);
7658 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
7659 mbox->u.mqe.un.set_host_data.param_len =
7660 LPFC_HOST_OS_DRIVER_VERSION_SIZE;
7661 snprintf(mbox->u.mqe.un.set_host_data.un.data,
7662 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
7663 "Linux %s v"LPFC_DRIVER_VERSION,
7664 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
7668 lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7669 struct lpfc_queue *drq, int count, int idx)
7672 struct lpfc_rqe hrqe;
7673 struct lpfc_rqe drqe;
7674 struct lpfc_rqb *rqbp;
7675 unsigned long flags;
7676 struct rqb_dmabuf *rqb_buffer;
7677 LIST_HEAD(rqb_buf_list);
7680 for (i = 0; i < count; i++) {
7681 spin_lock_irqsave(&phba->hbalock, flags);
7682 /* IF RQ is already full, don't bother */
7683 if (rqbp->buffer_count + i >= rqbp->entry_count - 1) {
7684 spin_unlock_irqrestore(&phba->hbalock, flags);
7687 spin_unlock_irqrestore(&phba->hbalock, flags);
7689 rqb_buffer = rqbp->rqb_alloc_buffer(phba);
7692 rqb_buffer->hrq = hrq;
7693 rqb_buffer->drq = drq;
7694 rqb_buffer->idx = idx;
7695 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7698 spin_lock_irqsave(&phba->hbalock, flags);
7699 while (!list_empty(&rqb_buf_list)) {
7700 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7703 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7704 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7705 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7706 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7707 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7709 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7710 "6421 Cannot post to HRQ %d: %x %x %x "
7718 rqbp->rqb_free_buffer(phba, rqb_buffer);
7720 list_add_tail(&rqb_buffer->hbuf.list,
7721 &rqbp->rqb_buffer_list);
7722 rqbp->buffer_count++;
7725 spin_unlock_irqrestore(&phba->hbalock, flags);
7730 lpfc_mbx_cmpl_cgn_set_ftrs(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7732 struct lpfc_vport *vport = pmb->vport;
7733 union lpfc_sli4_cfg_shdr *shdr;
7734 u32 shdr_status, shdr_add_status;
7737 /* Two outcomes. (1) Set featurs was successul and EDC negotiation
7738 * is done. (2) Mailbox failed and send FPIN support only.
7740 shdr = (union lpfc_sli4_cfg_shdr *)
7741 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7742 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7743 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7744 if (shdr_status || shdr_add_status || pmb->u.mb.mbxStatus) {
7745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
7746 "2516 CGN SET_FEATURE mbox failed with "
7747 "status x%x add_status x%x, mbx status x%x "
7748 "Reset Congestion to FPINs only\n",
7749 shdr_status, shdr_add_status,
7750 pmb->u.mb.mbxStatus);
7751 /* If there is a mbox error, move on to RDF */
7752 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
7753 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
7757 /* Zero out Congestion Signal ACQE counter */
7758 phba->cgn_acqe_cnt = 0;
7760 acqe = bf_get(lpfc_mbx_set_feature_CGN_acqe_freq,
7761 &pmb->u.mqe.un.set_feature);
7762 sig = bf_get(lpfc_mbx_set_feature_CGN_warn_freq,
7763 &pmb->u.mqe.un.set_feature);
7764 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7765 "4620 SET_FEATURES Success: Freq: %ds %dms "
7766 " Reg: x%x x%x\n", acqe, sig,
7767 phba->cgn_reg_signal, phba->cgn_reg_fpin);
7769 mempool_free(pmb, phba->mbox_mem_pool);
7771 /* Register for FPIN events from the fabric now that the
7772 * EDC common_set_features has completed.
7774 lpfc_issue_els_rdf(vport, 0);
7778 lpfc_config_cgn_signal(struct lpfc_hba *phba)
7780 LPFC_MBOXQ_t *mboxq;
7783 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7787 lpfc_set_features(phba, mboxq, LPFC_SET_CGN_SIGNAL);
7788 mboxq->vport = phba->pport;
7789 mboxq->mbox_cmpl = lpfc_mbx_cmpl_cgn_set_ftrs;
7791 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7792 "4621 SET_FEATURES: FREQ sig x%x acqe x%x: "
7794 phba->cgn_sig_freq, lpfc_acqe_cgn_frequency,
7795 phba->cgn_reg_signal, phba->cgn_reg_fpin);
7797 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
7798 if (rc == MBX_NOT_FINISHED)
7803 mempool_free(mboxq, phba->mbox_mem_pool);
7805 /* If there is a mbox error, move on to RDF */
7806 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
7807 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
7808 lpfc_issue_els_rdf(phba->pport, 0);
7813 * lpfc_init_idle_stat_hb - Initialize idle_stat tracking
7814 * @phba: pointer to lpfc hba data structure.
7816 * This routine initializes the per-cq idle_stat to dynamically dictate
7817 * polling decisions.
7822 static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba)
7825 struct lpfc_sli4_hdw_queue *hdwq;
7826 struct lpfc_queue *cq;
7827 struct lpfc_idle_stat *idle_stat;
7830 for_each_present_cpu(i) {
7831 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
7834 /* Skip if we've already handled this cq's primary CPU */
7838 idle_stat = &phba->sli4_hba.idle_stat[i];
7840 idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1);
7841 idle_stat->prev_wall = wall;
7843 if (phba->nvmet_support ||
7844 phba->cmf_active_mode != LPFC_CFG_OFF)
7845 cq->poll_mode = LPFC_QUEUE_WORK;
7847 cq->poll_mode = LPFC_IRQ_POLL;
7850 if (!phba->nvmet_support)
7851 schedule_delayed_work(&phba->idle_stat_delay_work,
7852 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
7855 static void lpfc_sli4_dip(struct lpfc_hba *phba)
7859 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7860 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 ||
7861 if_type == LPFC_SLI_INTF_IF_TYPE_6) {
7862 struct lpfc_register reg_data;
7864 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7868 if (bf_get(lpfc_sliport_status_dip, ®_data))
7869 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7870 "2904 Firmware Dump Image Present"
7876 * lpfc_cmf_setup - Initialize idle_stat tracking
7877 * @phba: Pointer to HBA context object.
7879 * This is called from HBA setup during driver load or when the HBA
7880 * comes online. this does all the initialization to support CMF and MI.
7883 lpfc_cmf_setup(struct lpfc_hba *phba)
7885 LPFC_MBOXQ_t *mboxq;
7886 struct lpfc_dmabuf *mp;
7887 struct lpfc_pc_sli4_params *sli4_params;
7888 int rc, cmf, mi_ver;
7890 rc = lpfc_sli4_refresh_params(phba);
7894 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7898 sli4_params = &phba->sli4_hba.pc_sli4_params;
7900 /* Are we forcing MI off via module parameter? */
7901 if (!phba->cfg_enable_mi)
7902 sli4_params->mi_ver = 0;
7904 /* Always try to enable MI feature if we can */
7905 if (sli4_params->mi_ver) {
7906 lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_MI);
7907 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7908 mi_ver = bf_get(lpfc_mbx_set_feature_mi,
7909 &mboxq->u.mqe.un.set_feature);
7911 if (rc == MBX_SUCCESS) {
7913 lpfc_printf_log(phba,
7914 KERN_WARNING, LOG_CGN_MGMT,
7915 "6215 MI is enabled\n");
7916 sli4_params->mi_ver = mi_ver;
7918 lpfc_printf_log(phba,
7919 KERN_WARNING, LOG_CGN_MGMT,
7920 "6338 MI is disabled\n");
7921 sli4_params->mi_ver = 0;
7924 /* mi_ver is already set from GET_SLI4_PARAMETERS */
7925 lpfc_printf_log(phba, KERN_INFO,
7926 LOG_CGN_MGMT | LOG_INIT,
7927 "6245 Enable MI Mailbox x%x (x%x/x%x) "
7928 "failed, rc:x%x mi:x%x\n",
7929 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7930 lpfc_sli_config_mbox_subsys_get
7932 lpfc_sli_config_mbox_opcode_get
7934 rc, sli4_params->mi_ver);
7937 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
7938 "6217 MI is disabled\n");
7941 /* Ensure FDMI is enabled for MI if enable_mi is set */
7942 if (sli4_params->mi_ver)
7943 phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT;
7945 /* Always try to enable CMF feature if we can */
7946 if (sli4_params->cmf) {
7947 lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_CMF);
7948 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7949 cmf = bf_get(lpfc_mbx_set_feature_cmf,
7950 &mboxq->u.mqe.un.set_feature);
7951 if (rc == MBX_SUCCESS && cmf) {
7952 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
7953 "6218 CMF is enabled: mode %d\n",
7954 phba->cmf_active_mode);
7956 lpfc_printf_log(phba, KERN_WARNING,
7957 LOG_CGN_MGMT | LOG_INIT,
7958 "6219 Enable CMF Mailbox x%x (x%x/x%x) "
7959 "failed, rc:x%x dd:x%x\n",
7960 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
7961 lpfc_sli_config_mbox_subsys_get
7963 lpfc_sli_config_mbox_opcode_get
7966 sli4_params->cmf = 0;
7967 phba->cmf_active_mode = LPFC_CFG_OFF;
7971 /* Allocate Congestion Information Buffer */
7973 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
7975 mp->virt = dma_alloc_coherent
7976 (&phba->pcidev->dev,
7977 sizeof(struct lpfc_cgn_info),
7978 &mp->phys, GFP_KERNEL);
7979 if (!mp || !mp->virt) {
7980 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7981 "2640 Failed to alloc memory "
7982 "for Congestion Info\n");
7984 sli4_params->cmf = 0;
7985 phba->cmf_active_mode = LPFC_CFG_OFF;
7990 /* initialize congestion buffer info */
7991 lpfc_init_congestion_buf(phba);
7992 lpfc_init_congestion_stat(phba);
7994 /* Zero out Congestion Signal counters */
7995 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
7996 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
7999 rc = lpfc_sli4_cgn_params_read(phba);
8001 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
8002 "6242 Error reading Cgn Params (%d)\n",
8004 /* Ensure CGN Mode is off */
8005 sli4_params->cmf = 0;
8007 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
8008 "6243 CGN Event empty object.\n");
8009 /* Ensure CGN Mode is off */
8010 sli4_params->cmf = 0;
8014 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
8015 "6220 CMF is disabled\n");
8018 /* Only register congestion buffer with firmware if BOTH
8019 * CMF and E2E are enabled.
8021 if (sli4_params->cmf && sli4_params->mi_ver) {
8022 rc = lpfc_reg_congestion_buf(phba);
8024 dma_free_coherent(&phba->pcidev->dev,
8025 sizeof(struct lpfc_cgn_info),
8026 phba->cgn_i->virt, phba->cgn_i->phys);
8029 /* Ensure CGN Mode is off */
8030 phba->cmf_active_mode = LPFC_CFG_OFF;
8034 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8035 "6470 Setup MI version %d CMF %d mode %d\n",
8036 sli4_params->mi_ver, sli4_params->cmf,
8037 phba->cmf_active_mode);
8039 mempool_free(mboxq, phba->mbox_mem_pool);
8041 /* Initialize atomic counters */
8042 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
8043 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
8044 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
8045 atomic_set(&phba->cgn_sync_warn_cnt, 0);
8046 atomic_set(&phba->cgn_driver_evt_cnt, 0);
8047 atomic_set(&phba->cgn_latency_evt_cnt, 0);
8048 atomic64_set(&phba->cgn_latency_evt, 0);
8050 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
8052 /* Allocate RX Monitor Buffer */
8053 if (!phba->rxtable) {
8054 phba->rxtable = kmalloc_array(LPFC_MAX_RXMONITOR_ENTRY,
8055 sizeof(struct rxtable_entry),
8057 if (!phba->rxtable) {
8058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8059 "2644 Failed to alloc memory "
8060 "for RX Monitor Buffer\n");
8064 atomic_set(&phba->rxtable_idx_head, 0);
8065 atomic_set(&phba->rxtable_idx_tail, 0);
8070 lpfc_set_host_tm(struct lpfc_hba *phba)
8072 LPFC_MBOXQ_t *mboxq;
8074 struct timespec64 cur_time;
8076 uint32_t month, day, year;
8077 uint32_t hour, minute, second;
8078 struct lpfc_mbx_set_host_date_time *tm;
8080 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8084 len = sizeof(struct lpfc_mbx_set_host_data) -
8085 sizeof(struct lpfc_sli4_cfg_mhdr);
8086 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8087 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
8088 LPFC_SLI4_MBX_EMBED);
8090 mboxq->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_DATE_TIME;
8091 mboxq->u.mqe.un.set_host_data.param_len =
8092 sizeof(struct lpfc_mbx_set_host_date_time);
8093 tm = &mboxq->u.mqe.un.set_host_data.un.tm;
8094 ktime_get_real_ts64(&cur_time);
8095 time64_to_tm(cur_time.tv_sec, 0, &broken);
8096 month = broken.tm_mon + 1;
8097 day = broken.tm_mday;
8098 year = broken.tm_year - 100;
8099 hour = broken.tm_hour;
8100 minute = broken.tm_min;
8101 second = broken.tm_sec;
8102 bf_set(lpfc_mbx_set_host_month, tm, month);
8103 bf_set(lpfc_mbx_set_host_day, tm, day);
8104 bf_set(lpfc_mbx_set_host_year, tm, year);
8105 bf_set(lpfc_mbx_set_host_hour, tm, hour);
8106 bf_set(lpfc_mbx_set_host_min, tm, minute);
8107 bf_set(lpfc_mbx_set_host_sec, tm, second);
8109 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8110 mempool_free(mboxq, phba->mbox_mem_pool);
8115 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
8116 * @phba: Pointer to HBA context object.
8118 * This function is the main SLI4 device initialization PCI function. This
8119 * function is called by the HBA initialization code, HBA reset code and
8120 * HBA error attention handler code. Caller is not required to hold any
8124 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
8126 int rc, i, cnt, len, dd;
8127 LPFC_MBOXQ_t *mboxq;
8128 struct lpfc_mqe *mqe;
8131 uint32_t ftr_rsp = 0;
8132 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
8133 struct lpfc_vport *vport = phba->pport;
8134 struct lpfc_dmabuf *mp;
8135 struct lpfc_rqb *rqbp;
8138 /* Perform a PCI function reset to start from clean */
8139 rc = lpfc_pci_function_reset(phba);
8143 /* Check the HBA Host Status Register for readyness */
8144 rc = lpfc_sli4_post_status_check(phba);
8148 spin_lock_irq(&phba->hbalock);
8149 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
8150 flg = phba->sli.sli_flag;
8151 spin_unlock_irq(&phba->hbalock);
8152 /* Allow a little time after setting SLI_ACTIVE for any polled
8153 * MBX commands to complete via BSG.
8155 for (i = 0; i < 50 && (flg & LPFC_SLI_MBOX_ACTIVE); i++) {
8157 spin_lock_irq(&phba->hbalock);
8158 flg = phba->sli.sli_flag;
8159 spin_unlock_irq(&phba->hbalock);
8163 lpfc_sli4_dip(phba);
8166 * Allocate a single mailbox container for initializing the
8169 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8173 /* Issue READ_REV to collect vpd and FW information. */
8174 vpd_size = SLI4_PAGE_SIZE;
8175 vpd = kzalloc(vpd_size, GFP_KERNEL);
8181 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
8187 mqe = &mboxq->u.mqe;
8188 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
8189 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
8190 phba->hba_flag |= HBA_FCOE_MODE;
8191 phba->fcp_embed_io = 0; /* SLI4 FC support only */
8193 phba->hba_flag &= ~HBA_FCOE_MODE;
8196 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
8198 phba->hba_flag |= HBA_FIP_SUPPORT;
8200 phba->hba_flag &= ~HBA_FIP_SUPPORT;
8202 phba->hba_flag &= ~HBA_IOQ_FLUSH;
8204 if (phba->sli_rev != LPFC_SLI_REV4) {
8205 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8206 "0376 READ_REV Error. SLI Level %d "
8207 "FCoE enabled %d\n",
8208 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
8214 rc = lpfc_set_host_tm(phba);
8215 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
8216 "6468 Set host date / time: Status x%x:\n", rc);
8219 * Continue initialization with default values even if driver failed
8220 * to read FCoE param config regions, only read parameters if the
8223 if (phba->hba_flag & HBA_FCOE_MODE &&
8224 lpfc_sli4_read_fcoe_params(phba))
8225 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
8226 "2570 Failed to read FCoE parameters\n");
8229 * Retrieve sli4 device physical port name, failure of doing it
8230 * is considered as non-fatal.
8232 rc = lpfc_sli4_retrieve_pport_name(phba);
8234 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8235 "3080 Successful retrieving SLI4 device "
8236 "physical port name: %s.\n", phba->Port);
8238 rc = lpfc_sli4_get_ctl_attr(phba);
8240 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8241 "8351 Successful retrieving SLI4 device "
8245 * Evaluate the read rev and vpd data. Populate the driver
8246 * state with the results. If this routine fails, the failure
8247 * is not fatal as the driver will use generic values.
8249 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
8250 if (unlikely(!rc)) {
8251 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8252 "0377 Error %d parsing vpd. "
8253 "Using defaults.\n", rc);
8258 /* Save information as VPD data */
8259 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
8260 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
8263 * This is because first G7 ASIC doesn't support the standard
8264 * 0x5a NVME cmd descriptor type/subtype
8266 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8267 LPFC_SLI_INTF_IF_TYPE_6) &&
8268 (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
8269 (phba->vpd.rev.smRev == 0) &&
8270 (phba->cfg_nvme_embed_cmd == 1))
8271 phba->cfg_nvme_embed_cmd = 0;
8273 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
8274 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
8276 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
8278 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
8280 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
8282 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
8283 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
8284 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
8285 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
8286 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
8287 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
8288 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8289 "(%d):0380 READ_REV Status x%x "
8290 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
8291 mboxq->vport ? mboxq->vport->vpi : 0,
8292 bf_get(lpfc_mqe_status, mqe),
8293 phba->vpd.rev.opFwName,
8294 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
8295 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
8297 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8298 LPFC_SLI_INTF_IF_TYPE_0) {
8299 lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
8300 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8301 if (rc == MBX_SUCCESS) {
8302 phba->hba_flag |= HBA_RECOVERABLE_UE;
8303 /* Set 1Sec interval to detect UE */
8304 phba->eratt_poll_interval = 1;
8305 phba->sli4_hba.ue_to_sr = bf_get(
8306 lpfc_mbx_set_feature_UESR,
8307 &mboxq->u.mqe.un.set_feature);
8308 phba->sli4_hba.ue_to_rp = bf_get(
8309 lpfc_mbx_set_feature_UERP,
8310 &mboxq->u.mqe.un.set_feature);
8314 if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
8315 /* Enable MDS Diagnostics only if the SLI Port supports it */
8316 lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
8317 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8318 if (rc != MBX_SUCCESS)
8319 phba->mds_diags_support = 0;
8323 * Discover the port's supported feature set and match it against the
8326 lpfc_request_features(phba, mboxq);
8327 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8333 /* Disable VMID if app header is not supported */
8334 if (phba->cfg_vmid_app_header && !(bf_get(lpfc_mbx_rq_ftr_rsp_ashdr,
8335 &mqe->un.req_ftrs))) {
8336 bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 0);
8337 phba->cfg_vmid_app_header = 0;
8338 lpfc_printf_log(phba, KERN_DEBUG, LOG_SLI,
8339 "1242 vmid feature not supported\n");
8343 * The port must support FCP initiator mode as this is the
8344 * only mode running in the host.
8346 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
8347 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8348 "0378 No support for fcpi mode.\n");
8352 /* Performance Hints are ONLY for FCoE */
8353 if (phba->hba_flag & HBA_FCOE_MODE) {
8354 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
8355 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
8357 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
8361 * If the port cannot support the host's requested features
8362 * then turn off the global config parameters to disable the
8363 * feature in the driver. This is not a fatal error.
8365 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8366 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
8367 phba->cfg_enable_bg = 0;
8368 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
8373 if (phba->max_vpi && phba->cfg_enable_npiv &&
8374 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
8378 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8379 "0379 Feature Mismatch Data: x%08x %08x "
8380 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
8381 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
8382 phba->cfg_enable_npiv, phba->max_vpi);
8383 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
8384 phba->cfg_enable_bg = 0;
8385 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
8386 phba->cfg_enable_npiv = 0;
8389 /* These SLI3 features are assumed in SLI4 */
8390 spin_lock_irq(&phba->hbalock);
8391 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
8392 spin_unlock_irq(&phba->hbalock);
8394 /* Always try to enable dual dump feature if we can */
8395 lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP);
8396 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8397 dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature);
8398 if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP))
8399 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8400 "6448 Dual Dump is enabled\n");
8402 lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT,
8403 "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, "
8405 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8406 lpfc_sli_config_mbox_subsys_get(
8408 lpfc_sli_config_mbox_opcode_get(
8412 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
8413 * calls depends on these resources to complete port setup.
8415 rc = lpfc_sli4_alloc_resource_identifiers(phba);
8417 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8418 "2920 Failed to alloc Resource IDs "
8423 lpfc_set_host_data(phba, mboxq);
8425 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8427 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8428 "2134 Failed to set host os driver version %x",
8432 /* Read the port's service parameters. */
8433 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
8435 phba->link_state = LPFC_HBA_ERROR;
8440 mboxq->vport = vport;
8441 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8442 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
8443 if (rc == MBX_SUCCESS) {
8444 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
8449 * This memory was allocated by the lpfc_read_sparam routine. Release
8450 * it to the mbuf pool.
8452 lpfc_mbuf_free(phba, mp->virt, mp->phys);
8454 mboxq->ctx_buf = NULL;
8456 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8457 "0382 READ_SPARAM command failed "
8458 "status %d, mbxStatus x%x\n",
8459 rc, bf_get(lpfc_mqe_status, mqe));
8460 phba->link_state = LPFC_HBA_ERROR;
8465 lpfc_update_vport_wwn(vport);
8467 /* Update the fc_host data structures with new wwn. */
8468 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
8469 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
8471 /* Create all the SLI4 queues */
8472 rc = lpfc_sli4_queue_create(phba);
8474 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8475 "3089 Failed to allocate queues\n");
8479 /* Set up all the queues to the device */
8480 rc = lpfc_sli4_queue_setup(phba);
8482 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8483 "0381 Error %d during queue setup.\n ", rc);
8484 goto out_stop_timers;
8486 /* Initialize the driver internal SLI layer lists. */
8487 lpfc_sli4_setup(phba);
8488 lpfc_sli4_queue_init(phba);
8490 /* update host els xri-sgl sizes and mappings */
8491 rc = lpfc_sli4_els_sgl_update(phba);
8493 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8494 "1400 Failed to update xri-sgl size and "
8495 "mapping: %d\n", rc);
8496 goto out_destroy_queue;
8499 /* register the els sgl pool to the port */
8500 rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
8501 phba->sli4_hba.els_xri_cnt);
8502 if (unlikely(rc < 0)) {
8503 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8504 "0582 Error %d during els sgl post "
8507 goto out_destroy_queue;
8509 phba->sli4_hba.els_xri_cnt = rc;
8511 if (phba->nvmet_support) {
8512 /* update host nvmet xri-sgl sizes and mappings */
8513 rc = lpfc_sli4_nvmet_sgl_update(phba);
8515 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8516 "6308 Failed to update nvmet-sgl size "
8517 "and mapping: %d\n", rc);
8518 goto out_destroy_queue;
8521 /* register the nvmet sgl pool to the port */
8522 rc = lpfc_sli4_repost_sgl_list(
8524 &phba->sli4_hba.lpfc_nvmet_sgl_list,
8525 phba->sli4_hba.nvmet_xri_cnt);
8526 if (unlikely(rc < 0)) {
8527 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8528 "3117 Error %d during nvmet "
8531 goto out_destroy_queue;
8533 phba->sli4_hba.nvmet_xri_cnt = rc;
8535 /* We allocate an iocbq for every receive context SGL.
8536 * The additional allocation is for abort and ls handling.
8538 cnt = phba->sli4_hba.nvmet_xri_cnt +
8539 phba->sli4_hba.max_cfg_param.max_xri;
8541 /* update host common xri-sgl sizes and mappings */
8542 rc = lpfc_sli4_io_sgl_update(phba);
8544 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8545 "6082 Failed to update nvme-sgl size "
8546 "and mapping: %d\n", rc);
8547 goto out_destroy_queue;
8550 /* register the allocated common sgl pool to the port */
8551 rc = lpfc_sli4_repost_io_sgl_list(phba);
8553 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8554 "6116 Error %d during nvme sgl post "
8556 /* Some NVME buffers were moved to abort nvme list */
8557 /* A pci function reset will repost them */
8559 goto out_destroy_queue;
8561 /* Each lpfc_io_buf job structure has an iocbq element.
8562 * This cnt provides for abort, els, ct and ls requests.
8564 cnt = phba->sli4_hba.max_cfg_param.max_xri;
8567 if (!phba->sli.iocbq_lookup) {
8568 /* Initialize and populate the iocb list per host */
8569 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8570 "2821 initialize iocb list with %d entries\n",
8572 rc = lpfc_init_iocb_list(phba, cnt);
8574 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8575 "1413 Failed to init iocb list.\n");
8576 goto out_destroy_queue;
8580 if (phba->nvmet_support)
8581 lpfc_nvmet_create_targetport(phba);
8583 if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
8584 /* Post initial buffers to all RQs created */
8585 for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
8586 rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
8587 INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
8588 rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
8589 rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
8590 rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
8591 rqbp->buffer_count = 0;
8593 lpfc_post_rq_buffer(
8594 phba, phba->sli4_hba.nvmet_mrq_hdr[i],
8595 phba->sli4_hba.nvmet_mrq_data[i],
8596 phba->cfg_nvmet_mrq_post, i);
8600 /* Post the rpi header region to the device. */
8601 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
8603 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8604 "0393 Error %d during rpi post operation\n",
8607 goto out_free_iocblist;
8609 lpfc_sli4_node_prep(phba);
8611 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
8612 if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
8614 * The FC Port needs to register FCFI (index 0)
8616 lpfc_reg_fcfi(phba, mboxq);
8617 mboxq->vport = phba->pport;
8618 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8619 if (rc != MBX_SUCCESS)
8620 goto out_unset_queue;
8622 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
8623 &mboxq->u.mqe.un.reg_fcfi);
8625 /* We are a NVME Target mode with MRQ > 1 */
8627 /* First register the FCFI */
8628 lpfc_reg_fcfi_mrq(phba, mboxq, 0);
8629 mboxq->vport = phba->pport;
8630 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8631 if (rc != MBX_SUCCESS)
8632 goto out_unset_queue;
8634 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
8635 &mboxq->u.mqe.un.reg_fcfi_mrq);
8637 /* Next register the MRQs */
8638 lpfc_reg_fcfi_mrq(phba, mboxq, 1);
8639 mboxq->vport = phba->pport;
8640 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8641 if (rc != MBX_SUCCESS)
8642 goto out_unset_queue;
8645 /* Check if the port is configured to be disabled */
8646 lpfc_sli_read_link_ste(phba);
8649 /* Don't post more new bufs if repost already recovered
8652 if (phba->nvmet_support == 0) {
8653 if (phba->sli4_hba.io_xri_cnt == 0) {
8654 len = lpfc_new_io_buf(
8655 phba, phba->sli4_hba.io_xri_max);
8658 goto out_unset_queue;
8661 if (phba->cfg_xri_rebalancing)
8662 lpfc_create_multixri_pools(phba);
8665 phba->cfg_xri_rebalancing = 0;
8668 /* Allow asynchronous mailbox command to go through */
8669 spin_lock_irq(&phba->hbalock);
8670 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
8671 spin_unlock_irq(&phba->hbalock);
8673 /* Post receive buffers to the device */
8674 lpfc_sli4_rb_setup(phba);
8676 /* Reset HBA FCF states after HBA reset */
8677 phba->fcf.fcf_flag = 0;
8678 phba->fcf.current_rec.flag = 0;
8680 /* Start the ELS watchdog timer */
8681 mod_timer(&vport->els_tmofunc,
8682 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
8684 /* Start heart beat timer */
8685 mod_timer(&phba->hb_tmofunc,
8686 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
8687 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
8688 phba->last_completion_time = jiffies;
8690 /* start eq_delay heartbeat */
8691 if (phba->cfg_auto_imax)
8692 queue_delayed_work(phba->wq, &phba->eq_delay_work,
8693 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
8695 /* start per phba idle_stat_delay heartbeat */
8696 lpfc_init_idle_stat_hb(phba);
8698 /* Start error attention (ERATT) polling timer */
8699 mod_timer(&phba->eratt_poll,
8700 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
8702 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
8703 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
8704 rc = pci_enable_pcie_error_reporting(phba->pcidev);
8706 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8707 "2829 This device supports "
8708 "Advanced Error Reporting (AER)\n");
8709 spin_lock_irq(&phba->hbalock);
8710 phba->hba_flag |= HBA_AER_ENABLED;
8711 spin_unlock_irq(&phba->hbalock);
8713 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8714 "2830 This device does not support "
8715 "Advanced Error Reporting (AER)\n");
8716 phba->cfg_aer_support = 0;
8722 * The port is ready, set the host's link state to LINK_DOWN
8723 * in preparation for link interrupts.
8725 spin_lock_irq(&phba->hbalock);
8726 phba->link_state = LPFC_LINK_DOWN;
8728 /* Check if physical ports are trunked */
8729 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
8730 phba->trunk_link.link0.state = LPFC_LINK_DOWN;
8731 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
8732 phba->trunk_link.link1.state = LPFC_LINK_DOWN;
8733 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
8734 phba->trunk_link.link2.state = LPFC_LINK_DOWN;
8735 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
8736 phba->trunk_link.link3.state = LPFC_LINK_DOWN;
8737 spin_unlock_irq(&phba->hbalock);
8739 /* Arm the CQs and then EQs on device */
8740 lpfc_sli4_arm_cqeq_intr(phba);
8742 /* Indicate device interrupt mode */
8743 phba->sli4_hba.intr_enable = 1;
8745 /* Setup CMF after HBA is initialized */
8746 lpfc_cmf_setup(phba);
8748 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
8749 (phba->hba_flag & LINK_DISABLED)) {
8750 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8751 "3103 Adapter Link is disabled.\n");
8752 lpfc_down_link(phba, mboxq);
8753 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8754 if (rc != MBX_SUCCESS) {
8755 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8756 "3104 Adapter failed to issue "
8757 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
8758 goto out_io_buff_free;
8760 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
8761 /* don't perform init_link on SLI4 FC port loopback test */
8762 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
8763 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
8765 goto out_io_buff_free;
8768 mempool_free(mboxq, phba->mbox_mem_pool);
8770 phba->hba_flag |= HBA_SETUP;
8774 /* Free allocated IO Buffers */
8777 /* Unset all the queues set up in this routine when error out */
8778 lpfc_sli4_queue_unset(phba);
8780 lpfc_free_iocb_list(phba);
8782 lpfc_sli4_queue_destroy(phba);
8784 lpfc_stop_hba_timers(phba);
8786 mempool_free(mboxq, phba->mbox_mem_pool);
8791 * lpfc_mbox_timeout - Timeout call back function for mbox timer
8792 * @t: Context to fetch pointer to hba structure from.
8794 * This is the callback function for mailbox timer. The mailbox
8795 * timer is armed when a new mailbox command is issued and the timer
8796 * is deleted when the mailbox complete. The function is called by
8797 * the kernel timer code when a mailbox does not complete within
8798 * expected time. This function wakes up the worker thread to
8799 * process the mailbox timeout and returns. All the processing is
8800 * done by the worker thread function lpfc_mbox_timeout_handler.
8803 lpfc_mbox_timeout(struct timer_list *t)
8805 struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo);
8806 unsigned long iflag;
8807 uint32_t tmo_posted;
8809 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
8810 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
8812 phba->pport->work_port_events |= WORKER_MBOX_TMO;
8813 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
8816 lpfc_worker_wake_up(phba);
8821 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
8823 * @phba: Pointer to HBA context object.
8825 * This function checks if any mailbox completions are present on the mailbox
8829 lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
8833 struct lpfc_queue *mcq;
8834 struct lpfc_mcqe *mcqe;
8835 bool pending_completions = false;
8838 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
8841 /* Check for completions on mailbox completion queue */
8843 mcq = phba->sli4_hba.mbx_cq;
8844 idx = mcq->hba_index;
8845 qe_valid = mcq->qe_valid;
8846 while (bf_get_le32(lpfc_cqe_valid,
8847 (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
8848 mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
8849 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
8850 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
8851 pending_completions = true;
8854 idx = (idx + 1) % mcq->entry_count;
8855 if (mcq->hba_index == idx)
8858 /* if the index wrapped around, toggle the valid bit */
8859 if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
8860 qe_valid = (qe_valid) ? 0 : 1;
8862 return pending_completions;
8867 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
8869 * @phba: Pointer to HBA context object.
8871 * For sli4, it is possible to miss an interrupt. As such mbox completions
8872 * maybe missed causing erroneous mailbox timeouts to occur. This function
8873 * checks to see if mbox completions are on the mailbox completion queue
8874 * and will process all the completions associated with the eq for the
8875 * mailbox completion queue.
8878 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
8880 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
8882 struct lpfc_queue *fpeq = NULL;
8883 struct lpfc_queue *eq;
8886 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
8889 /* Find the EQ associated with the mbox CQ */
8890 if (sli4_hba->hdwq) {
8891 for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
8892 eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
8893 if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
8902 /* Turn off interrupts from this EQ */
8904 sli4_hba->sli4_eq_clr_intr(fpeq);
8906 /* Check to see if a mbox completion is pending */
8908 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
8911 * If a mbox completion is pending, process all the events on EQ
8912 * associated with the mbox completion queue (this could include
8913 * mailbox commands, async events, els commands, receive queue data
8918 /* process and rearm the EQ */
8919 lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
8921 /* Always clear and re-arm the EQ */
8922 sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
8924 return mbox_pending;
8929 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
8930 * @phba: Pointer to HBA context object.
8932 * This function is called from worker thread when a mailbox command times out.
8933 * The caller is not required to hold any locks. This function will reset the
8934 * HBA and recover all the pending commands.
8937 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
8939 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
8940 MAILBOX_t *mb = NULL;
8942 struct lpfc_sli *psli = &phba->sli;
8944 /* If the mailbox completed, process the completion */
8945 lpfc_sli4_process_missed_mbox_completions(phba);
8947 if (!(psli->sli_flag & LPFC_SLI_ACTIVE))
8952 /* Check the pmbox pointer first. There is a race condition
8953 * between the mbox timeout handler getting executed in the
8954 * worklist and the mailbox actually completing. When this
8955 * race condition occurs, the mbox_active will be NULL.
8957 spin_lock_irq(&phba->hbalock);
8958 if (pmbox == NULL) {
8959 lpfc_printf_log(phba, KERN_WARNING,
8961 "0353 Active Mailbox cleared - mailbox timeout "
8963 spin_unlock_irq(&phba->hbalock);
8967 /* Mbox cmd <mbxCommand> timeout */
8968 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8969 "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
8971 phba->pport->port_state,
8973 phba->sli.mbox_active);
8974 spin_unlock_irq(&phba->hbalock);
8976 /* Setting state unknown so lpfc_sli_abort_iocb_ring
8977 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
8978 * it to fail all outstanding SCSI IO.
8980 spin_lock_irq(&phba->pport->work_port_lock);
8981 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
8982 spin_unlock_irq(&phba->pport->work_port_lock);
8983 spin_lock_irq(&phba->hbalock);
8984 phba->link_state = LPFC_LINK_UNKNOWN;
8985 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
8986 spin_unlock_irq(&phba->hbalock);
8988 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8989 "0345 Resetting board due to mailbox timeout\n");
8991 /* Reset the HBA device */
8992 lpfc_reset_hba(phba);
8996 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
8997 * @phba: Pointer to HBA context object.
8998 * @pmbox: Pointer to mailbox object.
8999 * @flag: Flag indicating how the mailbox need to be processed.
9001 * This function is called by discovery code and HBA management code
9002 * to submit a mailbox command to firmware with SLI-3 interface spec. This
9003 * function gets the hbalock to protect the data structures.
9004 * The mailbox command can be submitted in polling mode, in which case
9005 * this function will wait in a polling loop for the completion of the
9007 * If the mailbox is submitted in no_wait mode (not polling) the
9008 * function will submit the command and returns immediately without waiting
9009 * for the mailbox completion. The no_wait is supported only when HBA
9010 * is in SLI2/SLI3 mode - interrupts are enabled.
9011 * The SLI interface allows only one mailbox pending at a time. If the
9012 * mailbox is issued in polling mode and there is already a mailbox
9013 * pending, then the function will return an error. If the mailbox is issued
9014 * in NO_WAIT mode and there is a mailbox pending already, the function
9015 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
9016 * The sli layer owns the mailbox object until the completion of mailbox
9017 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
9018 * return codes the caller owns the mailbox command after the return of
9022 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
9026 struct lpfc_sli *psli = &phba->sli;
9027 uint32_t status, evtctr;
9028 uint32_t ha_copy, hc_copy;
9030 unsigned long timeout;
9031 unsigned long drvr_flag = 0;
9032 uint32_t word0, ldata;
9033 void __iomem *to_slim;
9034 int processing_queue = 0;
9036 spin_lock_irqsave(&phba->hbalock, drvr_flag);
9038 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9039 /* processing mbox queue from intr_handler */
9040 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
9041 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9044 processing_queue = 1;
9045 pmbox = lpfc_mbox_get(phba);
9047 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9052 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
9053 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
9055 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9056 lpfc_printf_log(phba, KERN_ERR,
9057 LOG_MBOX | LOG_VPORT,
9058 "1806 Mbox x%x failed. No vport\n",
9059 pmbox->u.mb.mbxCommand);
9061 goto out_not_finished;
9065 /* If the PCI channel is in offline state, do not post mbox. */
9066 if (unlikely(pci_channel_offline(phba->pcidev))) {
9067 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9068 goto out_not_finished;
9071 /* If HBA has a deferred error attention, fail the iocb. */
9072 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
9073 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9074 goto out_not_finished;
9080 status = MBX_SUCCESS;
9082 if (phba->link_state == LPFC_HBA_ERROR) {
9083 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9085 /* Mbox command <mbxCommand> cannot issue */
9086 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9087 "(%d):0311 Mailbox command x%x cannot "
9088 "issue Data: x%x x%x\n",
9089 pmbox->vport ? pmbox->vport->vpi : 0,
9090 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
9091 goto out_not_finished;
9094 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
9095 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
9096 !(hc_copy & HC_MBINT_ENA)) {
9097 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9098 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9099 "(%d):2528 Mailbox command x%x cannot "
9100 "issue Data: x%x x%x\n",
9101 pmbox->vport ? pmbox->vport->vpi : 0,
9102 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
9103 goto out_not_finished;
9107 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9108 /* Polling for a mbox command when another one is already active
9109 * is not allowed in SLI. Also, the driver must have established
9110 * SLI2 mode to queue and process multiple mbox commands.
9113 if (flag & MBX_POLL) {
9114 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9116 /* Mbox command <mbxCommand> cannot issue */
9117 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9118 "(%d):2529 Mailbox command x%x "
9119 "cannot issue Data: x%x x%x\n",
9120 pmbox->vport ? pmbox->vport->vpi : 0,
9121 pmbox->u.mb.mbxCommand,
9122 psli->sli_flag, flag);
9123 goto out_not_finished;
9126 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
9127 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9128 /* Mbox command <mbxCommand> cannot issue */
9129 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9130 "(%d):2530 Mailbox command x%x "
9131 "cannot issue Data: x%x x%x\n",
9132 pmbox->vport ? pmbox->vport->vpi : 0,
9133 pmbox->u.mb.mbxCommand,
9134 psli->sli_flag, flag);
9135 goto out_not_finished;
9138 /* Another mailbox command is still being processed, queue this
9139 * command to be processed later.
9141 lpfc_mbox_put(phba, pmbox);
9143 /* Mbox cmd issue - BUSY */
9144 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9145 "(%d):0308 Mbox cmd issue - BUSY Data: "
9146 "x%x x%x x%x x%x\n",
9147 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
9149 phba->pport ? phba->pport->port_state : 0xff,
9150 psli->sli_flag, flag);
9152 psli->slistat.mbox_busy++;
9153 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9156 lpfc_debugfs_disc_trc(pmbox->vport,
9157 LPFC_DISC_TRC_MBOX_VPORT,
9158 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
9159 (uint32_t)mbx->mbxCommand,
9160 mbx->un.varWords[0], mbx->un.varWords[1]);
9163 lpfc_debugfs_disc_trc(phba->pport,
9165 "MBOX Bsy: cmd:x%x mb:x%x x%x",
9166 (uint32_t)mbx->mbxCommand,
9167 mbx->un.varWords[0], mbx->un.varWords[1]);
9173 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
9175 /* If we are not polling, we MUST be in SLI2 mode */
9176 if (flag != MBX_POLL) {
9177 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
9178 (mbx->mbxCommand != MBX_KILL_BOARD)) {
9179 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9180 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9181 /* Mbox command <mbxCommand> cannot issue */
9182 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9183 "(%d):2531 Mailbox command x%x "
9184 "cannot issue Data: x%x x%x\n",
9185 pmbox->vport ? pmbox->vport->vpi : 0,
9186 pmbox->u.mb.mbxCommand,
9187 psli->sli_flag, flag);
9188 goto out_not_finished;
9190 /* timeout active mbox command */
9191 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
9193 mod_timer(&psli->mbox_tmo, jiffies + timeout);
9196 /* Mailbox cmd <cmd> issue */
9197 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9198 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
9200 pmbox->vport ? pmbox->vport->vpi : 0,
9202 phba->pport ? phba->pport->port_state : 0xff,
9203 psli->sli_flag, flag);
9205 if (mbx->mbxCommand != MBX_HEARTBEAT) {
9207 lpfc_debugfs_disc_trc(pmbox->vport,
9208 LPFC_DISC_TRC_MBOX_VPORT,
9209 "MBOX Send vport: cmd:x%x mb:x%x x%x",
9210 (uint32_t)mbx->mbxCommand,
9211 mbx->un.varWords[0], mbx->un.varWords[1]);
9214 lpfc_debugfs_disc_trc(phba->pport,
9216 "MBOX Send: cmd:x%x mb:x%x x%x",
9217 (uint32_t)mbx->mbxCommand,
9218 mbx->un.varWords[0], mbx->un.varWords[1]);
9222 psli->slistat.mbox_cmd++;
9223 evtctr = psli->slistat.mbox_event;
9225 /* next set own bit for the adapter and copy over command word */
9226 mbx->mbxOwner = OWN_CHIP;
9228 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9229 /* Populate mbox extension offset word. */
9230 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
9231 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
9232 = (uint8_t *)phba->mbox_ext
9233 - (uint8_t *)phba->mbox;
9236 /* Copy the mailbox extension data */
9237 if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
9238 lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
9239 (uint8_t *)phba->mbox_ext,
9240 pmbox->in_ext_byte_len);
9242 /* Copy command data to host SLIM area */
9243 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
9245 /* Populate mbox extension offset word. */
9246 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
9247 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
9248 = MAILBOX_HBA_EXT_OFFSET;
9250 /* Copy the mailbox extension data */
9251 if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
9252 lpfc_memcpy_to_slim(phba->MBslimaddr +
9253 MAILBOX_HBA_EXT_OFFSET,
9254 pmbox->ctx_buf, pmbox->in_ext_byte_len);
9256 if (mbx->mbxCommand == MBX_CONFIG_PORT)
9257 /* copy command data into host mbox for cmpl */
9258 lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
9261 /* First copy mbox command data to HBA SLIM, skip past first
9263 to_slim = phba->MBslimaddr + sizeof (uint32_t);
9264 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
9265 MAILBOX_CMD_SIZE - sizeof (uint32_t));
9267 /* Next copy over first word, with mbxOwner set */
9268 ldata = *((uint32_t *)mbx);
9269 to_slim = phba->MBslimaddr;
9270 writel(ldata, to_slim);
9271 readl(to_slim); /* flush */
9273 if (mbx->mbxCommand == MBX_CONFIG_PORT)
9274 /* switch over to host mailbox */
9275 psli->sli_flag |= LPFC_SLI_ACTIVE;
9282 /* Set up reference to mailbox command */
9283 psli->mbox_active = pmbox;
9284 /* Interrupt board to do it */
9285 writel(CA_MBATT, phba->CAregaddr);
9286 readl(phba->CAregaddr); /* flush */
9287 /* Don't wait for it to finish, just return */
9291 /* Set up null reference to mailbox command */
9292 psli->mbox_active = NULL;
9293 /* Interrupt board to do it */
9294 writel(CA_MBATT, phba->CAregaddr);
9295 readl(phba->CAregaddr); /* flush */
9297 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9298 /* First read mbox status word */
9299 word0 = *((uint32_t *)phba->mbox);
9300 word0 = le32_to_cpu(word0);
9302 /* First read mbox status word */
9303 if (lpfc_readl(phba->MBslimaddr, &word0)) {
9304 spin_unlock_irqrestore(&phba->hbalock,
9306 goto out_not_finished;
9310 /* Read the HBA Host Attention Register */
9311 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
9312 spin_unlock_irqrestore(&phba->hbalock,
9314 goto out_not_finished;
9316 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
9319 /* Wait for command to complete */
9320 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
9321 (!(ha_copy & HA_MBATT) &&
9322 (phba->link_state > LPFC_WARM_START))) {
9323 if (time_after(jiffies, timeout)) {
9324 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9325 spin_unlock_irqrestore(&phba->hbalock,
9327 goto out_not_finished;
9330 /* Check if we took a mbox interrupt while we were
9332 if (((word0 & OWN_CHIP) != OWN_CHIP)
9333 && (evtctr != psli->slistat.mbox_event))
9337 spin_unlock_irqrestore(&phba->hbalock,
9340 spin_lock_irqsave(&phba->hbalock, drvr_flag);
9343 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9344 /* First copy command data */
9345 word0 = *((uint32_t *)phba->mbox);
9346 word0 = le32_to_cpu(word0);
9347 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
9350 /* Check real SLIM for any errors */
9351 slimword0 = readl(phba->MBslimaddr);
9352 slimmb = (MAILBOX_t *) & slimword0;
9353 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
9354 && slimmb->mbxStatus) {
9361 /* First copy command data */
9362 word0 = readl(phba->MBslimaddr);
9364 /* Read the HBA Host Attention Register */
9365 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
9366 spin_unlock_irqrestore(&phba->hbalock,
9368 goto out_not_finished;
9372 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9373 /* copy results back to user */
9374 lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
9376 /* Copy the mailbox extension data */
9377 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
9378 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
9380 pmbox->out_ext_byte_len);
9383 /* First copy command data */
9384 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
9386 /* Copy the mailbox extension data */
9387 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
9388 lpfc_memcpy_from_slim(
9391 MAILBOX_HBA_EXT_OFFSET,
9392 pmbox->out_ext_byte_len);
9396 writel(HA_MBATT, phba->HAregaddr);
9397 readl(phba->HAregaddr); /* flush */
9399 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9400 status = mbx->mbxStatus;
9403 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9407 if (processing_queue) {
9408 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
9409 lpfc_mbox_cmpl_put(phba, pmbox);
9411 return MBX_NOT_FINISHED;
9415 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
9416 * @phba: Pointer to HBA context object.
9418 * The function blocks the posting of SLI4 asynchronous mailbox commands from
9419 * the driver internal pending mailbox queue. It will then try to wait out the
9420 * possible outstanding mailbox command before return.
9423 * 0 - the outstanding mailbox command completed; otherwise, the wait for
9424 * the outstanding mailbox command timed out.
9427 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
9429 struct lpfc_sli *psli = &phba->sli;
9430 LPFC_MBOXQ_t *mboxq;
9432 unsigned long timeout = 0;
9434 u8 cmd, subsys, opcode;
9436 /* Mark the asynchronous mailbox command posting as blocked */
9437 spin_lock_irq(&phba->hbalock);
9438 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9439 /* Determine how long we might wait for the active mailbox
9440 * command to be gracefully completed by firmware.
9442 if (phba->sli.mbox_active)
9443 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
9444 phba->sli.mbox_active) *
9446 spin_unlock_irq(&phba->hbalock);
9448 /* Make sure the mailbox is really active */
9450 lpfc_sli4_process_missed_mbox_completions(phba);
9452 /* Wait for the outstanding mailbox command to complete */
9453 while (phba->sli.mbox_active) {
9454 /* Check active mailbox complete status every 2ms */
9456 if (time_after(jiffies, timeout)) {
9457 /* Timeout, mark the outstanding cmd not complete */
9459 /* Sanity check sli.mbox_active has not completed or
9460 * cancelled from another context during last 2ms sleep,
9461 * so take hbalock to be sure before logging.
9463 spin_lock_irq(&phba->hbalock);
9464 if (phba->sli.mbox_active) {
9465 mboxq = phba->sli.mbox_active;
9466 cmd = mboxq->u.mb.mbxCommand;
9467 subsys = lpfc_sli_config_mbox_subsys_get(phba,
9469 opcode = lpfc_sli_config_mbox_opcode_get(phba,
9471 sli_flag = psli->sli_flag;
9472 spin_unlock_irq(&phba->hbalock);
9473 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9474 "2352 Mailbox command x%x "
9475 "(x%x/x%x) sli_flag x%x could "
9477 cmd, subsys, opcode,
9480 spin_unlock_irq(&phba->hbalock);
9488 /* Can not cleanly block async mailbox command, fails it */
9490 spin_lock_irq(&phba->hbalock);
9491 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
9492 spin_unlock_irq(&phba->hbalock);
9498 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
9499 * @phba: Pointer to HBA context object.
9501 * The function unblocks and resume posting of SLI4 asynchronous mailbox
9502 * commands from the driver internal pending mailbox queue. It makes sure
9503 * that there is no outstanding mailbox command before resuming posting
9504 * asynchronous mailbox commands. If, for any reason, there is outstanding
9505 * mailbox command, it will try to wait it out before resuming asynchronous
9506 * mailbox command posting.
9509 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
9511 struct lpfc_sli *psli = &phba->sli;
9513 spin_lock_irq(&phba->hbalock);
9514 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
9515 /* Asynchronous mailbox posting is not blocked, do nothing */
9516 spin_unlock_irq(&phba->hbalock);
9520 /* Outstanding synchronous mailbox command is guaranteed to be done,
9521 * successful or timeout, after timing-out the outstanding mailbox
9522 * command shall always be removed, so just unblock posting async
9523 * mailbox command and resume
9525 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
9526 spin_unlock_irq(&phba->hbalock);
9528 /* wake up worker thread to post asynchronous mailbox command */
9529 lpfc_worker_wake_up(phba);
9533 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
9534 * @phba: Pointer to HBA context object.
9535 * @mboxq: Pointer to mailbox object.
9537 * The function waits for the bootstrap mailbox register ready bit from
9538 * port for twice the regular mailbox command timeout value.
9540 * 0 - no timeout on waiting for bootstrap mailbox register ready.
9541 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
9544 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9547 unsigned long timeout;
9548 struct lpfc_register bmbx_reg;
9550 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
9554 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
9555 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
9559 if (time_after(jiffies, timeout))
9560 return MBXERR_ERROR;
9561 } while (!db_ready);
9567 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
9568 * @phba: Pointer to HBA context object.
9569 * @mboxq: Pointer to mailbox object.
9571 * The function posts a mailbox to the port. The mailbox is expected
9572 * to be comletely filled in and ready for the port to operate on it.
9573 * This routine executes a synchronous completion operation on the
9574 * mailbox by polling for its completion.
9576 * The caller must not be holding any locks when calling this routine.
9579 * MBX_SUCCESS - mailbox posted successfully
9580 * Any of the MBX error values.
9583 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9585 int rc = MBX_SUCCESS;
9586 unsigned long iflag;
9587 uint32_t mcqe_status;
9589 struct lpfc_sli *psli = &phba->sli;
9590 struct lpfc_mqe *mb = &mboxq->u.mqe;
9591 struct lpfc_bmbx_create *mbox_rgn;
9592 struct dma_address *dma_address;
9595 * Only one mailbox can be active to the bootstrap mailbox region
9596 * at a time and there is no queueing provided.
9598 spin_lock_irqsave(&phba->hbalock, iflag);
9599 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9600 spin_unlock_irqrestore(&phba->hbalock, iflag);
9601 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9602 "(%d):2532 Mailbox command x%x (x%x/x%x) "
9603 "cannot issue Data: x%x x%x\n",
9604 mboxq->vport ? mboxq->vport->vpi : 0,
9605 mboxq->u.mb.mbxCommand,
9606 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9607 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9608 psli->sli_flag, MBX_POLL);
9609 return MBXERR_ERROR;
9611 /* The server grabs the token and owns it until release */
9612 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
9613 phba->sli.mbox_active = mboxq;
9614 spin_unlock_irqrestore(&phba->hbalock, iflag);
9616 /* wait for bootstrap mbox register for readyness */
9617 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
9621 * Initialize the bootstrap memory region to avoid stale data areas
9622 * in the mailbox post. Then copy the caller's mailbox contents to
9623 * the bmbx mailbox region.
9625 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
9626 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
9627 lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
9628 sizeof(struct lpfc_mqe));
9630 /* Post the high mailbox dma address to the port and wait for ready. */
9631 dma_address = &phba->sli4_hba.bmbx.dma_address;
9632 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
9634 /* wait for bootstrap mbox register for hi-address write done */
9635 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
9639 /* Post the low mailbox dma address to the port. */
9640 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
9642 /* wait for bootstrap mbox register for low address write done */
9643 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
9648 * Read the CQ to ensure the mailbox has completed.
9649 * If so, update the mailbox status so that the upper layers
9650 * can complete the request normally.
9652 lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
9653 sizeof(struct lpfc_mqe));
9654 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
9655 lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
9656 sizeof(struct lpfc_mcqe));
9657 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
9659 * When the CQE status indicates a failure and the mailbox status
9660 * indicates success then copy the CQE status into the mailbox status
9661 * (and prefix it with x4000).
9663 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
9664 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
9665 bf_set(lpfc_mqe_status, mb,
9666 (LPFC_MBX_ERROR_RANGE | mcqe_status));
9669 lpfc_sli4_swap_str(phba, mboxq);
9671 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9672 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
9673 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
9674 " x%x x%x CQ: x%x x%x x%x x%x\n",
9675 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
9676 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9677 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9678 bf_get(lpfc_mqe_status, mb),
9679 mb->un.mb_words[0], mb->un.mb_words[1],
9680 mb->un.mb_words[2], mb->un.mb_words[3],
9681 mb->un.mb_words[4], mb->un.mb_words[5],
9682 mb->un.mb_words[6], mb->un.mb_words[7],
9683 mb->un.mb_words[8], mb->un.mb_words[9],
9684 mb->un.mb_words[10], mb->un.mb_words[11],
9685 mb->un.mb_words[12], mboxq->mcqe.word0,
9686 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
9687 mboxq->mcqe.trailer);
9689 /* We are holding the token, no needed for lock when release */
9690 spin_lock_irqsave(&phba->hbalock, iflag);
9691 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9692 phba->sli.mbox_active = NULL;
9693 spin_unlock_irqrestore(&phba->hbalock, iflag);
9698 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
9699 * @phba: Pointer to HBA context object.
9700 * @mboxq: Pointer to mailbox object.
9701 * @flag: Flag indicating how the mailbox need to be processed.
9703 * This function is called by discovery code and HBA management code to submit
9704 * a mailbox command to firmware with SLI-4 interface spec.
9706 * Return codes the caller owns the mailbox command after the return of the
9710 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
9713 struct lpfc_sli *psli = &phba->sli;
9714 unsigned long iflags;
9717 /* dump from issue mailbox command if setup */
9718 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
9720 rc = lpfc_mbox_dev_check(phba);
9722 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9723 "(%d):2544 Mailbox command x%x (x%x/x%x) "
9724 "cannot issue Data: x%x x%x\n",
9725 mboxq->vport ? mboxq->vport->vpi : 0,
9726 mboxq->u.mb.mbxCommand,
9727 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9728 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9729 psli->sli_flag, flag);
9730 goto out_not_finished;
9733 /* Detect polling mode and jump to a handler */
9734 if (!phba->sli4_hba.intr_enable) {
9735 if (flag == MBX_POLL)
9736 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
9739 if (rc != MBX_SUCCESS)
9740 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
9741 "(%d):2541 Mailbox command x%x "
9742 "(x%x/x%x) failure: "
9743 "mqe_sta: x%x mcqe_sta: x%x/x%x "
9745 mboxq->vport ? mboxq->vport->vpi : 0,
9746 mboxq->u.mb.mbxCommand,
9747 lpfc_sli_config_mbox_subsys_get(phba,
9749 lpfc_sli_config_mbox_opcode_get(phba,
9751 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
9752 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
9753 bf_get(lpfc_mcqe_ext_status,
9755 psli->sli_flag, flag);
9757 } else if (flag == MBX_POLL) {
9758 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
9759 "(%d):2542 Try to issue mailbox command "
9760 "x%x (x%x/x%x) synchronously ahead of async "
9761 "mailbox command queue: x%x x%x\n",
9762 mboxq->vport ? mboxq->vport->vpi : 0,
9763 mboxq->u.mb.mbxCommand,
9764 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9765 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9766 psli->sli_flag, flag);
9767 /* Try to block the asynchronous mailbox posting */
9768 rc = lpfc_sli4_async_mbox_block(phba);
9770 /* Successfully blocked, now issue sync mbox cmd */
9771 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
9772 if (rc != MBX_SUCCESS)
9773 lpfc_printf_log(phba, KERN_WARNING,
9775 "(%d):2597 Sync Mailbox command "
9776 "x%x (x%x/x%x) failure: "
9777 "mqe_sta: x%x mcqe_sta: x%x/x%x "
9779 mboxq->vport ? mboxq->vport->vpi : 0,
9780 mboxq->u.mb.mbxCommand,
9781 lpfc_sli_config_mbox_subsys_get(phba,
9783 lpfc_sli_config_mbox_opcode_get(phba,
9785 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
9786 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
9787 bf_get(lpfc_mcqe_ext_status,
9789 psli->sli_flag, flag);
9790 /* Unblock the async mailbox posting afterward */
9791 lpfc_sli4_async_mbox_unblock(phba);
9796 /* Now, interrupt mode asynchronous mailbox command */
9797 rc = lpfc_mbox_cmd_check(phba, mboxq);
9799 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9800 "(%d):2543 Mailbox command x%x (x%x/x%x) "
9801 "cannot issue Data: x%x x%x\n",
9802 mboxq->vport ? mboxq->vport->vpi : 0,
9803 mboxq->u.mb.mbxCommand,
9804 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9805 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9806 psli->sli_flag, flag);
9807 goto out_not_finished;
9810 /* Put the mailbox command to the driver internal FIFO */
9811 psli->slistat.mbox_busy++;
9812 spin_lock_irqsave(&phba->hbalock, iflags);
9813 lpfc_mbox_put(phba, mboxq);
9814 spin_unlock_irqrestore(&phba->hbalock, iflags);
9815 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9816 "(%d):0354 Mbox cmd issue - Enqueue Data: "
9817 "x%x (x%x/x%x) x%x x%x x%x\n",
9818 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
9819 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
9820 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9821 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9822 phba->pport->port_state,
9823 psli->sli_flag, MBX_NOWAIT);
9824 /* Wake up worker thread to transport mailbox command from head */
9825 lpfc_worker_wake_up(phba);
9830 return MBX_NOT_FINISHED;
9834 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
9835 * @phba: Pointer to HBA context object.
9837 * This function is called by worker thread to send a mailbox command to
9838 * SLI4 HBA firmware.
9842 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
9844 struct lpfc_sli *psli = &phba->sli;
9845 LPFC_MBOXQ_t *mboxq;
9846 int rc = MBX_SUCCESS;
9847 unsigned long iflags;
9848 struct lpfc_mqe *mqe;
9851 /* Check interrupt mode before post async mailbox command */
9852 if (unlikely(!phba->sli4_hba.intr_enable))
9853 return MBX_NOT_FINISHED;
9855 /* Check for mailbox command service token */
9856 spin_lock_irqsave(&phba->hbalock, iflags);
9857 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
9858 spin_unlock_irqrestore(&phba->hbalock, iflags);
9859 return MBX_NOT_FINISHED;
9861 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9862 spin_unlock_irqrestore(&phba->hbalock, iflags);
9863 return MBX_NOT_FINISHED;
9865 if (unlikely(phba->sli.mbox_active)) {
9866 spin_unlock_irqrestore(&phba->hbalock, iflags);
9867 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9868 "0384 There is pending active mailbox cmd\n");
9869 return MBX_NOT_FINISHED;
9871 /* Take the mailbox command service token */
9872 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
9874 /* Get the next mailbox command from head of queue */
9875 mboxq = lpfc_mbox_get(phba);
9877 /* If no more mailbox command waiting for post, we're done */
9879 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9880 spin_unlock_irqrestore(&phba->hbalock, iflags);
9883 phba->sli.mbox_active = mboxq;
9884 spin_unlock_irqrestore(&phba->hbalock, iflags);
9886 /* Check device readiness for posting mailbox command */
9887 rc = lpfc_mbox_dev_check(phba);
9889 /* Driver clean routine will clean up pending mailbox */
9890 goto out_not_finished;
9892 /* Prepare the mbox command to be posted */
9893 mqe = &mboxq->u.mqe;
9894 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
9896 /* Start timer for the mbox_tmo and log some mailbox post messages */
9897 mod_timer(&psli->mbox_tmo, (jiffies +
9898 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
9900 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9901 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
9903 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
9904 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9905 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9906 phba->pport->port_state, psli->sli_flag);
9908 if (mbx_cmnd != MBX_HEARTBEAT) {
9910 lpfc_debugfs_disc_trc(mboxq->vport,
9911 LPFC_DISC_TRC_MBOX_VPORT,
9912 "MBOX Send vport: cmd:x%x mb:x%x x%x",
9913 mbx_cmnd, mqe->un.mb_words[0],
9914 mqe->un.mb_words[1]);
9916 lpfc_debugfs_disc_trc(phba->pport,
9918 "MBOX Send: cmd:x%x mb:x%x x%x",
9919 mbx_cmnd, mqe->un.mb_words[0],
9920 mqe->un.mb_words[1]);
9923 psli->slistat.mbox_cmd++;
9925 /* Post the mailbox command to the port */
9926 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
9927 if (rc != MBX_SUCCESS) {
9928 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9929 "(%d):2533 Mailbox command x%x (x%x/x%x) "
9930 "cannot issue Data: x%x x%x\n",
9931 mboxq->vport ? mboxq->vport->vpi : 0,
9932 mboxq->u.mb.mbxCommand,
9933 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9934 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9935 psli->sli_flag, MBX_NOWAIT);
9936 goto out_not_finished;
9942 spin_lock_irqsave(&phba->hbalock, iflags);
9943 if (phba->sli.mbox_active) {
9944 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9945 __lpfc_mbox_cmpl_put(phba, mboxq);
9946 /* Release the token */
9947 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9948 phba->sli.mbox_active = NULL;
9950 spin_unlock_irqrestore(&phba->hbalock, iflags);
9952 return MBX_NOT_FINISHED;
9956 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
9957 * @phba: Pointer to HBA context object.
9958 * @pmbox: Pointer to mailbox object.
9959 * @flag: Flag indicating how the mailbox need to be processed.
9961 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
9962 * the API jump table function pointer from the lpfc_hba struct.
9964 * Return codes the caller owns the mailbox command after the return of the
9968 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
9970 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
9974 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
9975 * @phba: The hba struct for which this call is being executed.
9976 * @dev_grp: The HBA PCI-Device group number.
9978 * This routine sets up the mbox interface API function jump table in @phba
9980 * Returns: 0 - success, -ENODEV - failure.
9983 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
9987 case LPFC_PCI_DEV_LP:
9988 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
9989 phba->lpfc_sli_handle_slow_ring_event =
9990 lpfc_sli_handle_slow_ring_event_s3;
9991 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
9992 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
9993 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
9995 case LPFC_PCI_DEV_OC:
9996 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
9997 phba->lpfc_sli_handle_slow_ring_event =
9998 lpfc_sli_handle_slow_ring_event_s4;
9999 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
10000 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
10001 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
10004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10005 "1420 Invalid HBA PCI-device group: 0x%x\n",
10013 * __lpfc_sli_ringtx_put - Add an iocb to the txq
10014 * @phba: Pointer to HBA context object.
10015 * @pring: Pointer to driver SLI ring object.
10016 * @piocb: Pointer to address of newly added command iocb.
10018 * This function is called with hbalock held for SLI3 ports or
10019 * the ring lock held for SLI4 ports to add a command
10020 * iocb to the txq when SLI layer cannot submit the command iocb
10024 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10025 struct lpfc_iocbq *piocb)
10027 if (phba->sli_rev == LPFC_SLI_REV4)
10028 lockdep_assert_held(&pring->ring_lock);
10030 lockdep_assert_held(&phba->hbalock);
10031 /* Insert the caller's iocb in the txq tail for later processing. */
10032 list_add_tail(&piocb->list, &pring->txq);
10036 * lpfc_sli_next_iocb - Get the next iocb in the txq
10037 * @phba: Pointer to HBA context object.
10038 * @pring: Pointer to driver SLI ring object.
10039 * @piocb: Pointer to address of newly added command iocb.
10041 * This function is called with hbalock held before a new
10042 * iocb is submitted to the firmware. This function checks
10043 * txq to flush the iocbs in txq to Firmware before
10044 * submitting new iocbs to the Firmware.
10045 * If there are iocbs in the txq which need to be submitted
10046 * to firmware, lpfc_sli_next_iocb returns the first element
10047 * of the txq after dequeuing it from txq.
10048 * If there is no iocb in the txq then the function will return
10049 * *piocb and *piocb is set to NULL. Caller needs to check
10050 * *piocb to find if there are more commands in the txq.
10052 static struct lpfc_iocbq *
10053 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10054 struct lpfc_iocbq **piocb)
10056 struct lpfc_iocbq * nextiocb;
10058 lockdep_assert_held(&phba->hbalock);
10060 nextiocb = lpfc_sli_ringtx_get(phba, pring);
10070 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
10071 * @phba: Pointer to HBA context object.
10072 * @ring_number: SLI ring number to issue iocb on.
10073 * @piocb: Pointer to command iocb.
10074 * @flag: Flag indicating if this command can be put into txq.
10076 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
10077 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
10078 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
10079 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
10080 * this function allows only iocbs for posting buffers. This function finds
10081 * next available slot in the command ring and posts the command to the
10082 * available slot and writes the port attention register to request HBA start
10083 * processing new iocb. If there is no slot available in the ring and
10084 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
10085 * the function returns IOCB_BUSY.
10087 * This function is called with hbalock held. The function will return success
10088 * after it successfully submit the iocb to firmware or after adding to the
10092 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
10093 struct lpfc_iocbq *piocb, uint32_t flag)
10095 struct lpfc_iocbq *nextiocb;
10097 struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
10099 lockdep_assert_held(&phba->hbalock);
10101 if (piocb->iocb_cmpl && (!piocb->vport) &&
10102 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
10103 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
10104 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10105 "1807 IOCB x%x failed. No vport\n",
10106 piocb->iocb.ulpCommand);
10112 /* If the PCI channel is in offline state, do not post iocbs. */
10113 if (unlikely(pci_channel_offline(phba->pcidev)))
10116 /* If HBA has a deferred error attention, fail the iocb. */
10117 if (unlikely(phba->hba_flag & DEFER_ERATT))
10121 * We should never get an IOCB if we are in a < LINK_DOWN state
10123 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
10127 * Check to see if we are blocking IOCB processing because of a
10128 * outstanding event.
10130 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
10133 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
10135 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
10136 * can be issued if the link is not up.
10138 switch (piocb->iocb.ulpCommand) {
10139 case CMD_GEN_REQUEST64_CR:
10140 case CMD_GEN_REQUEST64_CX:
10141 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
10142 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
10143 FC_RCTL_DD_UNSOL_CMD) ||
10144 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
10145 MENLO_TRANSPORT_TYPE))
10149 case CMD_QUE_RING_BUF_CN:
10150 case CMD_QUE_RING_BUF64_CN:
10152 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
10153 * completion, iocb_cmpl MUST be 0.
10155 if (piocb->iocb_cmpl)
10156 piocb->iocb_cmpl = NULL;
10158 case CMD_CREATE_XRI_CR:
10159 case CMD_CLOSE_XRI_CN:
10160 case CMD_CLOSE_XRI_CX:
10167 * For FCP commands, we must be in a state where we can process link
10168 * attention events.
10170 } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
10171 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
10175 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
10176 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
10177 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
10180 lpfc_sli_update_ring(phba, pring);
10182 lpfc_sli_update_full_ring(phba, pring);
10185 return IOCB_SUCCESS;
10190 pring->stats.iocb_cmd_delay++;
10194 if (!(flag & SLI_IOCB_RET_IOCB)) {
10195 __lpfc_sli_ringtx_put(phba, pring, piocb);
10196 return IOCB_SUCCESS;
10203 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
10204 * @phba: Pointer to HBA context object.
10205 * @piocbq: Pointer to command iocb.
10206 * @sglq: Pointer to the scatter gather queue object.
10208 * This routine converts the bpl or bde that is in the IOCB
10209 * to a sgl list for the sli4 hardware. The physical address
10210 * of the bpl/bde is converted back to a virtual address.
10211 * If the IOCB contains a BPL then the list of BDE's is
10212 * converted to sli4_sge's. If the IOCB contains a single
10213 * BDE then it is converted to a single sli_sge.
10214 * The IOCB is still in cpu endianess so the contents of
10215 * the bpl can be used without byte swapping.
10217 * Returns valid XRI = Success, NO_XRI = Failure.
10220 lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
10221 struct lpfc_sglq *sglq)
10223 uint16_t xritag = NO_XRI;
10224 struct ulp_bde64 *bpl = NULL;
10225 struct ulp_bde64 bde;
10226 struct sli4_sge *sgl = NULL;
10227 struct lpfc_dmabuf *dmabuf;
10231 uint32_t offset = 0; /* accumulated offset in the sg request list */
10232 int inbound = 0; /* number of sg reply entries inbound from firmware */
10234 if (!piocbq || !sglq)
10237 sgl = (struct sli4_sge *)sglq->sgl;
10238 icmd = &piocbq->iocb;
10239 if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX)
10240 return sglq->sli4_xritag;
10241 if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
10242 numBdes = icmd->un.genreq64.bdl.bdeSize /
10243 sizeof(struct ulp_bde64);
10244 /* The addrHigh and addrLow fields within the IOCB
10245 * have not been byteswapped yet so there is no
10246 * need to swap them back.
10248 if (piocbq->context3)
10249 dmabuf = (struct lpfc_dmabuf *)piocbq->context3;
10253 bpl = (struct ulp_bde64 *)dmabuf->virt;
10257 for (i = 0; i < numBdes; i++) {
10258 /* Should already be byte swapped. */
10259 sgl->addr_hi = bpl->addrHigh;
10260 sgl->addr_lo = bpl->addrLow;
10262 sgl->word2 = le32_to_cpu(sgl->word2);
10263 if ((i+1) == numBdes)
10264 bf_set(lpfc_sli4_sge_last, sgl, 1);
10266 bf_set(lpfc_sli4_sge_last, sgl, 0);
10267 /* swap the size field back to the cpu so we
10268 * can assign it to the sgl.
10270 bde.tus.w = le32_to_cpu(bpl->tus.w);
10271 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
10272 /* The offsets in the sgl need to be accumulated
10273 * separately for the request and reply lists.
10274 * The request is always first, the reply follows.
10276 if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
10277 /* add up the reply sg entries */
10278 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
10280 /* first inbound? reset the offset */
10283 bf_set(lpfc_sli4_sge_offset, sgl, offset);
10284 bf_set(lpfc_sli4_sge_type, sgl,
10285 LPFC_SGE_TYPE_DATA);
10286 offset += bde.tus.f.bdeSize;
10288 sgl->word2 = cpu_to_le32(sgl->word2);
10292 } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) {
10293 /* The addrHigh and addrLow fields of the BDE have not
10294 * been byteswapped yet so they need to be swapped
10295 * before putting them in the sgl.
10298 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
10300 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
10301 sgl->word2 = le32_to_cpu(sgl->word2);
10302 bf_set(lpfc_sli4_sge_last, sgl, 1);
10303 sgl->word2 = cpu_to_le32(sgl->word2);
10305 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
10307 return sglq->sli4_xritag;
10311 * lpfc_sli4_iocb2wqe - Convert the IOCB to a work queue entry.
10312 * @phba: Pointer to HBA context object.
10313 * @iocbq: Pointer to command iocb.
10314 * @wqe: Pointer to the work queue entry.
10316 * This routine converts the iocb command to its Work Queue Entry
10317 * equivalent. The wqe pointer should not have any fields set when
10318 * this routine is called because it will memcpy over them.
10319 * This routine does not set the CQ_ID or the WQEC bits in the
10322 * Returns: 0 = Success, IOCB_ERROR = Failure.
10325 lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
10326 union lpfc_wqe128 *wqe)
10328 uint32_t xmit_len = 0, total_len = 0;
10331 uint32_t abort_tag;
10332 uint8_t command_type = ELS_COMMAND_NON_FIP;
10335 uint16_t abrt_iotag;
10336 struct lpfc_iocbq *abrtiocbq;
10337 struct ulp_bde64 *bpl = NULL;
10338 uint32_t els_id = LPFC_ELS_ID_DEFAULT;
10340 struct ulp_bde64 bde;
10341 struct lpfc_nodelist *ndlp;
10345 fip = phba->hba_flag & HBA_FIP_SUPPORT;
10346 /* The fcp commands will set command type */
10347 if (iocbq->iocb_flag & LPFC_IO_FCP)
10348 command_type = FCP_COMMAND;
10349 else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK))
10350 command_type = ELS_COMMAND_FIP;
10352 command_type = ELS_COMMAND_NON_FIP;
10354 if (phba->fcp_embed_io)
10355 memset(wqe, 0, sizeof(union lpfc_wqe128));
10356 /* Some of the fields are in the right position already */
10357 memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe));
10358 /* The ct field has moved so reset */
10359 wqe->generic.wqe_com.word7 = 0;
10360 wqe->generic.wqe_com.word10 = 0;
10362 abort_tag = (uint32_t) iocbq->iotag;
10363 xritag = iocbq->sli4_xritag;
10364 /* words0-2 bpl convert bde */
10365 if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) {
10366 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
10367 sizeof(struct ulp_bde64);
10368 bpl = (struct ulp_bde64 *)
10369 ((struct lpfc_dmabuf *)iocbq->context3)->virt;
10373 /* Should already be byte swapped. */
10374 wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh);
10375 wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow);
10376 /* swap the size field back to the cpu so we
10377 * can assign it to the sgl.
10379 wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w);
10380 xmit_len = wqe->generic.bde.tus.f.bdeSize;
10382 for (i = 0; i < numBdes; i++) {
10383 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
10384 total_len += bde.tus.f.bdeSize;
10387 xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize;
10389 iocbq->iocb.ulpIoTag = iocbq->iotag;
10390 cmnd = iocbq->iocb.ulpCommand;
10392 switch (iocbq->iocb.ulpCommand) {
10393 case CMD_ELS_REQUEST64_CR:
10394 if (iocbq->iocb_flag & LPFC_IO_LIBDFC)
10395 ndlp = iocbq->context_un.ndlp;
10397 ndlp = (struct lpfc_nodelist *)iocbq->context1;
10398 if (!iocbq->iocb.ulpLe) {
10399 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10400 "2007 Only Limited Edition cmd Format"
10401 " supported 0x%x\n",
10402 iocbq->iocb.ulpCommand);
10406 wqe->els_req.payload_len = xmit_len;
10407 /* Els_reguest64 has a TMO */
10408 bf_set(wqe_tmo, &wqe->els_req.wqe_com,
10409 iocbq->iocb.ulpTimeout);
10410 /* Need a VF for word 4 set the vf bit*/
10411 bf_set(els_req64_vf, &wqe->els_req, 0);
10412 /* And a VFID for word 12 */
10413 bf_set(els_req64_vfid, &wqe->els_req, 0);
10414 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
10415 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
10416 iocbq->iocb.ulpContext);
10417 bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
10418 bf_set(wqe_pu, &wqe->els_req.wqe_com, 0);
10419 /* CCP CCPE PV PRI in word10 were set in the memcpy */
10420 if (command_type == ELS_COMMAND_FIP)
10421 els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)
10422 >> LPFC_FIP_ELS_ID_SHIFT);
10423 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
10424 iocbq->context2)->virt);
10425 if_type = bf_get(lpfc_sli_intf_if_type,
10426 &phba->sli4_hba.sli_intf);
10427 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10428 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
10429 *pcmd == ELS_CMD_SCR ||
10430 *pcmd == ELS_CMD_RDF ||
10431 *pcmd == ELS_CMD_EDC ||
10432 *pcmd == ELS_CMD_RSCN_XMT ||
10433 *pcmd == ELS_CMD_FDISC ||
10434 *pcmd == ELS_CMD_LOGO ||
10435 *pcmd == ELS_CMD_QFPA ||
10436 *pcmd == ELS_CMD_UVEM ||
10437 *pcmd == ELS_CMD_PLOGI)) {
10438 bf_set(els_req64_sp, &wqe->els_req, 1);
10439 bf_set(els_req64_sid, &wqe->els_req,
10440 iocbq->vport->fc_myDID);
10441 if ((*pcmd == ELS_CMD_FLOGI) &&
10442 !(phba->fc_topology ==
10443 LPFC_TOPOLOGY_LOOP))
10444 bf_set(els_req64_sid, &wqe->els_req, 0);
10445 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
10446 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
10447 phba->vpi_ids[iocbq->vport->vpi]);
10448 } else if (pcmd && iocbq->context1) {
10449 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
10450 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
10451 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
10454 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
10455 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
10456 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
10457 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
10458 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
10459 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
10460 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
10461 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
10462 wqe->els_req.max_response_payload_len = total_len - xmit_len;
10464 case CMD_XMIT_SEQUENCE64_CX:
10465 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com,
10466 iocbq->iocb.un.ulpWord[3]);
10467 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com,
10468 iocbq->iocb.unsli3.rcvsli3.ox_id);
10469 /* The entire sequence is transmitted for this IOCB */
10470 xmit_len = total_len;
10471 cmnd = CMD_XMIT_SEQUENCE64_CR;
10472 if (phba->link_flag & LS_LOOPBACK_MODE)
10473 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
10475 case CMD_XMIT_SEQUENCE64_CR:
10476 /* word3 iocb=io_tag32 wqe=reserved */
10477 wqe->xmit_sequence.rsvd3 = 0;
10478 /* word4 relative_offset memcpy */
10479 /* word5 r_ctl/df_ctl memcpy */
10480 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
10481 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
10482 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
10483 LPFC_WQE_IOD_WRITE);
10484 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
10485 LPFC_WQE_LENLOC_WORD12);
10486 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
10487 wqe->xmit_sequence.xmit_len = xmit_len;
10488 command_type = OTHER_COMMAND;
10490 case CMD_XMIT_BCAST64_CN:
10491 /* word3 iocb=iotag32 wqe=seq_payload_len */
10492 wqe->xmit_bcast64.seq_payload_len = xmit_len;
10493 /* word4 iocb=rsvd wqe=rsvd */
10494 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
10495 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
10496 bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com,
10497 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
10498 bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1);
10499 bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE);
10500 bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com,
10501 LPFC_WQE_LENLOC_WORD3);
10502 bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0);
10504 case CMD_FCP_IWRITE64_CR:
10505 command_type = FCP_COMMAND_DATA_OUT;
10506 /* word3 iocb=iotag wqe=payload_offset_len */
10507 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
10508 bf_set(payload_offset_len, &wqe->fcp_iwrite,
10509 xmit_len + sizeof(struct fcp_rsp));
10510 bf_set(cmd_buff_len, &wqe->fcp_iwrite,
10512 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
10513 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
10514 bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com,
10515 iocbq->iocb.ulpFCP2Rcvy);
10516 bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS);
10517 /* Always open the exchange */
10518 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
10519 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com,
10520 LPFC_WQE_LENLOC_WORD4);
10521 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU);
10522 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1);
10523 if (iocbq->iocb_flag & LPFC_IO_OAS) {
10524 bf_set(wqe_oas, &wqe->fcp_iwrite.wqe_com, 1);
10525 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
10526 if (iocbq->priority) {
10527 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
10528 (iocbq->priority << 1));
10530 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
10531 (phba->cfg_XLanePriority << 1));
10534 /* Note, word 10 is already initialized to 0 */
10536 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
10537 if (phba->cfg_enable_pbde)
10538 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 1);
10540 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
10542 if (phba->fcp_embed_io) {
10543 struct lpfc_io_buf *lpfc_cmd;
10544 struct sli4_sge *sgl;
10545 struct fcp_cmnd *fcp_cmnd;
10548 /* 128 byte wqe support here */
10550 lpfc_cmd = iocbq->context1;
10551 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
10552 fcp_cmnd = lpfc_cmd->fcp_cmnd;
10554 /* Word 0-2 - FCP_CMND */
10555 wqe->generic.bde.tus.f.bdeFlags =
10556 BUFF_TYPE_BDE_IMMED;
10557 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10558 wqe->generic.bde.addrHigh = 0;
10559 wqe->generic.bde.addrLow = 88; /* Word 22 */
10561 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
10562 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
10564 /* Word 22-29 FCP CMND Payload */
10565 ptr = &wqe->words[22];
10566 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10569 case CMD_FCP_IREAD64_CR:
10570 /* word3 iocb=iotag wqe=payload_offset_len */
10571 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
10572 bf_set(payload_offset_len, &wqe->fcp_iread,
10573 xmit_len + sizeof(struct fcp_rsp));
10574 bf_set(cmd_buff_len, &wqe->fcp_iread,
10576 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
10577 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
10578 bf_set(wqe_erp, &wqe->fcp_iread.wqe_com,
10579 iocbq->iocb.ulpFCP2Rcvy);
10580 bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS);
10581 /* Always open the exchange */
10582 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
10583 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com,
10584 LPFC_WQE_LENLOC_WORD4);
10585 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU);
10586 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1);
10587 if (iocbq->iocb_flag & LPFC_IO_OAS) {
10588 bf_set(wqe_oas, &wqe->fcp_iread.wqe_com, 1);
10589 bf_set(wqe_ccpe, &wqe->fcp_iread.wqe_com, 1);
10590 if (iocbq->priority) {
10591 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
10592 (iocbq->priority << 1));
10594 bf_set(wqe_ccp, &wqe->fcp_iread.wqe_com,
10595 (phba->cfg_XLanePriority << 1));
10598 /* Note, word 10 is already initialized to 0 */
10600 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
10601 if (phba->cfg_enable_pbde)
10602 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 1);
10604 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
10606 if (phba->fcp_embed_io) {
10607 struct lpfc_io_buf *lpfc_cmd;
10608 struct sli4_sge *sgl;
10609 struct fcp_cmnd *fcp_cmnd;
10612 /* 128 byte wqe support here */
10614 lpfc_cmd = iocbq->context1;
10615 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
10616 fcp_cmnd = lpfc_cmd->fcp_cmnd;
10618 /* Word 0-2 - FCP_CMND */
10619 wqe->generic.bde.tus.f.bdeFlags =
10620 BUFF_TYPE_BDE_IMMED;
10621 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10622 wqe->generic.bde.addrHigh = 0;
10623 wqe->generic.bde.addrLow = 88; /* Word 22 */
10625 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
10626 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
10628 /* Word 22-29 FCP CMND Payload */
10629 ptr = &wqe->words[22];
10630 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10633 case CMD_FCP_ICMND64_CR:
10634 /* word3 iocb=iotag wqe=payload_offset_len */
10635 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
10636 bf_set(payload_offset_len, &wqe->fcp_icmd,
10637 xmit_len + sizeof(struct fcp_rsp));
10638 bf_set(cmd_buff_len, &wqe->fcp_icmd,
10640 /* word3 iocb=IO_TAG wqe=reserved */
10641 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
10642 /* Always open the exchange */
10643 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1);
10644 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE);
10645 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
10646 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com,
10647 LPFC_WQE_LENLOC_NONE);
10648 bf_set(wqe_erp, &wqe->fcp_icmd.wqe_com,
10649 iocbq->iocb.ulpFCP2Rcvy);
10650 if (iocbq->iocb_flag & LPFC_IO_OAS) {
10651 bf_set(wqe_oas, &wqe->fcp_icmd.wqe_com, 1);
10652 bf_set(wqe_ccpe, &wqe->fcp_icmd.wqe_com, 1);
10653 if (iocbq->priority) {
10654 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
10655 (iocbq->priority << 1));
10657 bf_set(wqe_ccp, &wqe->fcp_icmd.wqe_com,
10658 (phba->cfg_XLanePriority << 1));
10661 /* Note, word 10 is already initialized to 0 */
10663 if (phba->fcp_embed_io) {
10664 struct lpfc_io_buf *lpfc_cmd;
10665 struct sli4_sge *sgl;
10666 struct fcp_cmnd *fcp_cmnd;
10669 /* 128 byte wqe support here */
10671 lpfc_cmd = iocbq->context1;
10672 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
10673 fcp_cmnd = lpfc_cmd->fcp_cmnd;
10675 /* Word 0-2 - FCP_CMND */
10676 wqe->generic.bde.tus.f.bdeFlags =
10677 BUFF_TYPE_BDE_IMMED;
10678 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10679 wqe->generic.bde.addrHigh = 0;
10680 wqe->generic.bde.addrLow = 88; /* Word 22 */
10682 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
10683 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
10685 /* Word 22-29 FCP CMND Payload */
10686 ptr = &wqe->words[22];
10687 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10690 case CMD_GEN_REQUEST64_CR:
10691 /* For this command calculate the xmit length of the
10695 numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize /
10696 sizeof(struct ulp_bde64);
10697 for (i = 0; i < numBdes; i++) {
10698 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
10699 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
10701 xmit_len += bde.tus.f.bdeSize;
10703 /* word3 iocb=IO_TAG wqe=request_payload_len */
10704 wqe->gen_req.request_payload_len = xmit_len;
10705 /* word4 iocb=parameter wqe=relative_offset memcpy */
10706 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
10707 /* word6 context tag copied in memcpy */
10708 if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) {
10709 ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l);
10710 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10711 "2015 Invalid CT %x command 0x%x\n",
10712 ct, iocbq->iocb.ulpCommand);
10715 bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0);
10716 bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout);
10717 bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU);
10718 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
10719 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
10720 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
10721 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
10722 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
10723 wqe->gen_req.max_response_payload_len = total_len - xmit_len;
10724 command_type = OTHER_COMMAND;
10726 case CMD_XMIT_ELS_RSP64_CX:
10727 ndlp = (struct lpfc_nodelist *)iocbq->context1;
10728 /* words0-2 BDE memcpy */
10729 /* word3 iocb=iotag32 wqe=response_payload_len */
10730 wqe->xmit_els_rsp.response_payload_len = xmit_len;
10732 wqe->xmit_els_rsp.word4 = 0;
10733 /* word5 iocb=rsvd wge=did */
10734 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
10735 iocbq->iocb.un.xseq64.xmit_els_remoteID);
10737 if_type = bf_get(lpfc_sli_intf_if_type,
10738 &phba->sli4_hba.sli_intf);
10739 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
10740 if (iocbq->vport->fc_flag & FC_PT2PT) {
10741 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
10742 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
10743 iocbq->vport->fc_myDID);
10744 if (iocbq->vport->fc_myDID == Fabric_DID) {
10745 bf_set(wqe_els_did,
10746 &wqe->xmit_els_rsp.wqe_dest, 0);
10750 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com,
10751 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
10752 bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU);
10753 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
10754 iocbq->iocb.unsli3.rcvsli3.ox_id);
10755 if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l)
10756 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
10757 phba->vpi_ids[iocbq->vport->vpi]);
10758 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
10759 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
10760 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
10761 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
10762 LPFC_WQE_LENLOC_WORD3);
10763 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
10764 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
10765 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
10766 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
10767 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
10768 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
10769 iocbq->vport->fc_myDID);
10770 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
10771 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
10772 phba->vpi_ids[phba->pport->vpi]);
10774 command_type = OTHER_COMMAND;
10776 case CMD_CLOSE_XRI_CN:
10777 case CMD_ABORT_XRI_CN:
10778 case CMD_ABORT_XRI_CX:
10779 /* words 0-2 memcpy should be 0 rserved */
10780 /* port will send abts */
10781 abrt_iotag = iocbq->iocb.un.acxri.abortContextTag;
10782 if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) {
10783 abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag];
10784 fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK;
10788 if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip)
10790 * The link is down, or the command was ELS_FIP
10791 * so the fw does not need to send abts
10794 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
10796 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
10797 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
10798 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
10799 wqe->abort_cmd.rsrvd5 = 0;
10800 bf_set(wqe_ct, &wqe->abort_cmd.wqe_com,
10801 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
10802 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
10804 * The abort handler will send us CMD_ABORT_XRI_CN or
10805 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
10807 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
10808 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
10809 bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com,
10810 LPFC_WQE_LENLOC_NONE);
10811 cmnd = CMD_ABORT_XRI_CX;
10812 command_type = OTHER_COMMAND;
10815 case CMD_XMIT_BLS_RSP64_CX:
10816 ndlp = (struct lpfc_nodelist *)iocbq->context1;
10817 /* As BLS ABTS RSP WQE is very different from other WQEs,
10818 * we re-construct this WQE here based on information in
10819 * iocbq from scratch.
10821 memset(wqe, 0, sizeof(*wqe));
10822 /* OX_ID is invariable to who sent ABTS to CT exchange */
10823 bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp,
10824 bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp));
10825 if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) ==
10826 LPFC_ABTS_UNSOL_INT) {
10827 /* ABTS sent by initiator to CT exchange, the
10828 * RX_ID field will be filled with the newly
10829 * allocated responder XRI.
10831 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
10832 iocbq->sli4_xritag);
10834 /* ABTS sent by responder to CT exchange, the
10835 * RX_ID field will be filled with the responder
10838 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
10839 bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp));
10841 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
10842 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
10845 bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest,
10847 bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp,
10848 iocbq->iocb.ulpContext);
10849 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
10850 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
10851 phba->vpi_ids[phba->pport->vpi]);
10852 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
10853 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
10854 LPFC_WQE_LENLOC_NONE);
10855 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
10856 command_type = OTHER_COMMAND;
10857 if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) {
10858 bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp,
10859 bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp));
10860 bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp,
10861 bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp));
10862 bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp,
10863 bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp));
10867 case CMD_SEND_FRAME:
10868 bf_set(wqe_cmnd, &wqe->generic.wqe_com, CMD_SEND_FRAME);
10869 bf_set(wqe_sof, &wqe->generic.wqe_com, 0x2E); /* SOF byte */
10870 bf_set(wqe_eof, &wqe->generic.wqe_com, 0x41); /* EOF byte */
10871 bf_set(wqe_lenloc, &wqe->generic.wqe_com, 1);
10872 bf_set(wqe_xbl, &wqe->generic.wqe_com, 1);
10873 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
10874 bf_set(wqe_xc, &wqe->generic.wqe_com, 1);
10875 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, 0xA);
10876 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10877 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
10878 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
10880 case CMD_XRI_ABORTED_CX:
10881 case CMD_CREATE_XRI_CR: /* Do we expect to use this? */
10882 case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */
10883 case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */
10884 case CMD_FCP_TRSP64_CX: /* Target mode rcv */
10885 case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */
10887 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10888 "2014 Invalid command 0x%x\n",
10889 iocbq->iocb.ulpCommand);
10893 if (iocbq->iocb_flag & LPFC_IO_DIF_PASS)
10894 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_PASSTHRU);
10895 else if (iocbq->iocb_flag & LPFC_IO_DIF_STRIP)
10896 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_STRIP);
10897 else if (iocbq->iocb_flag & LPFC_IO_DIF_INSERT)
10898 bf_set(wqe_dif, &wqe->generic.wqe_com, LPFC_WQE_DIF_INSERT);
10899 iocbq->iocb_flag &= ~(LPFC_IO_DIF_PASS | LPFC_IO_DIF_STRIP |
10900 LPFC_IO_DIF_INSERT);
10901 bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag);
10902 bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag);
10903 wqe->generic.wqe_com.abort_tag = abort_tag;
10904 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
10905 bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd);
10906 bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass);
10907 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
10912 * __lpfc_sli_issue_fcp_io_s3 - SLI3 device for sending fcp io iocb
10913 * @phba: Pointer to HBA context object.
10914 * @ring_number: SLI ring number to issue wqe on.
10915 * @piocb: Pointer to command iocb.
10916 * @flag: Flag indicating if this command can be put into txq.
10918 * __lpfc_sli_issue_fcp_io_s3 is wrapper function to invoke lockless func to
10919 * send an iocb command to an HBA with SLI-4 interface spec.
10921 * This function takes the hbalock before invoking the lockless version.
10922 * The function will return success after it successfully submit the wqe to
10923 * firmware or after adding to the txq.
10926 __lpfc_sli_issue_fcp_io_s3(struct lpfc_hba *phba, uint32_t ring_number,
10927 struct lpfc_iocbq *piocb, uint32_t flag)
10929 unsigned long iflags;
10932 spin_lock_irqsave(&phba->hbalock, iflags);
10933 rc = __lpfc_sli_issue_iocb_s3(phba, ring_number, piocb, flag);
10934 spin_unlock_irqrestore(&phba->hbalock, iflags);
10940 * __lpfc_sli_issue_fcp_io_s4 - SLI4 device for sending fcp io wqe
10941 * @phba: Pointer to HBA context object.
10942 * @ring_number: SLI ring number to issue wqe on.
10943 * @piocb: Pointer to command iocb.
10944 * @flag: Flag indicating if this command can be put into txq.
10946 * __lpfc_sli_issue_fcp_io_s4 is used by other functions in the driver to issue
10947 * an wqe command to an HBA with SLI-4 interface spec.
10949 * This function is a lockless version. The function will return success
10950 * after it successfully submit the wqe to firmware or after adding to the
10954 __lpfc_sli_issue_fcp_io_s4(struct lpfc_hba *phba, uint32_t ring_number,
10955 struct lpfc_iocbq *piocb, uint32_t flag)
10958 struct lpfc_io_buf *lpfc_cmd =
10959 (struct lpfc_io_buf *)piocb->context1;
10960 union lpfc_wqe128 *wqe = &piocb->wqe;
10961 struct sli4_sge *sgl;
10963 /* 128 byte wqe support here */
10964 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
10966 if (phba->fcp_embed_io) {
10967 struct fcp_cmnd *fcp_cmnd;
10970 fcp_cmnd = lpfc_cmd->fcp_cmnd;
10972 /* Word 0-2 - FCP_CMND */
10973 wqe->generic.bde.tus.f.bdeFlags =
10974 BUFF_TYPE_BDE_IMMED;
10975 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10976 wqe->generic.bde.addrHigh = 0;
10977 wqe->generic.bde.addrLow = 88; /* Word 22 */
10979 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
10980 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
10982 /* Word 22-29 FCP CMND Payload */
10983 ptr = &wqe->words[22];
10984 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10986 /* Word 0-2 - Inline BDE */
10987 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
10988 wqe->generic.bde.tus.f.bdeSize = sizeof(struct fcp_cmnd);
10989 wqe->generic.bde.addrHigh = sgl->addr_hi;
10990 wqe->generic.bde.addrLow = sgl->addr_lo;
10993 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
10994 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
10997 /* add the VMID tags as per switch response */
10998 if (unlikely(piocb->iocb_flag & LPFC_IO_VMID)) {
10999 if (phba->pport->vmid_priority_tagging) {
11000 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
11001 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
11002 (piocb->vmid_tag.cs_ctl_vmid));
11004 bf_set(wqe_appid, &wqe->fcp_iwrite.wqe_com, 1);
11005 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
11006 wqe->words[31] = piocb->vmid_tag.app_id;
11009 rc = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, piocb);
11014 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
11015 * @phba: Pointer to HBA context object.
11016 * @ring_number: SLI ring number to issue iocb on.
11017 * @piocb: Pointer to command iocb.
11018 * @flag: Flag indicating if this command can be put into txq.
11020 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
11021 * an iocb command to an HBA with SLI-4 interface spec.
11023 * This function is called with ringlock held. The function will return success
11024 * after it successfully submit the iocb to firmware or after adding to the
11028 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
11029 struct lpfc_iocbq *piocb, uint32_t flag)
11031 struct lpfc_sglq *sglq;
11032 union lpfc_wqe128 wqe;
11033 struct lpfc_queue *wq;
11034 struct lpfc_sli_ring *pring;
11037 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
11038 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
11039 wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
11041 wq = phba->sli4_hba.els_wq;
11044 /* Get corresponding ring */
11048 * The WQE can be either 64 or 128 bytes,
11051 lockdep_assert_held(&pring->ring_lock);
11053 if (piocb->sli4_xritag == NO_XRI) {
11054 if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
11055 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
11058 if (!list_empty(&pring->txq)) {
11059 if (!(flag & SLI_IOCB_RET_IOCB)) {
11060 __lpfc_sli_ringtx_put(phba,
11062 return IOCB_SUCCESS;
11067 sglq = __lpfc_sli_get_els_sglq(phba, piocb);
11069 if (!(flag & SLI_IOCB_RET_IOCB)) {
11070 __lpfc_sli_ringtx_put(phba,
11073 return IOCB_SUCCESS;
11079 } else if (piocb->iocb_flag & LPFC_IO_FCP) {
11080 /* These IO's already have an XRI and a mapped sgl. */
11085 * This is a continuation of a commandi,(CX) so this
11086 * sglq is on the active list
11088 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
11094 piocb->sli4_lxritag = sglq->sli4_lxritag;
11095 piocb->sli4_xritag = sglq->sli4_xritag;
11096 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq))
11100 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
11103 if (lpfc_sli4_wq_put(wq, &wqe))
11105 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
11111 * lpfc_sli_issue_fcp_io - Wrapper func for issuing fcp i/o
11113 * This routine wraps the actual fcp i/o function for issusing WQE for sli-4
11114 * or IOCB for sli-3 function.
11115 * pointer from the lpfc_hba struct.
11118 * IOCB_ERROR - Error
11119 * IOCB_SUCCESS - Success
11123 lpfc_sli_issue_fcp_io(struct lpfc_hba *phba, uint32_t ring_number,
11124 struct lpfc_iocbq *piocb, uint32_t flag)
11126 return phba->__lpfc_sli_issue_fcp_io(phba, ring_number, piocb, flag);
11130 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
11132 * This routine wraps the actual lockless version for issusing IOCB function
11133 * pointer from the lpfc_hba struct.
11136 * IOCB_ERROR - Error
11137 * IOCB_SUCCESS - Success
11141 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
11142 struct lpfc_iocbq *piocb, uint32_t flag)
11144 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
11148 * lpfc_sli_api_table_setup - Set up sli api function jump table
11149 * @phba: The hba struct for which this call is being executed.
11150 * @dev_grp: The HBA PCI-Device group number.
11152 * This routine sets up the SLI interface API function jump table in @phba
11154 * Returns: 0 - success, -ENODEV - failure.
11157 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
11161 case LPFC_PCI_DEV_LP:
11162 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
11163 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
11164 phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s3;
11166 case LPFC_PCI_DEV_OC:
11167 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
11168 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
11169 phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s4;
11172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11173 "1419 Invalid HBA PCI-device group: 0x%x\n",
11177 phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq;
11182 * lpfc_sli4_calc_ring - Calculates which ring to use
11183 * @phba: Pointer to HBA context object.
11184 * @piocb: Pointer to command iocb.
11186 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
11187 * hba_wqidx, thus we need to calculate the corresponding ring.
11188 * Since ABORTS must go on the same WQ of the command they are
11189 * aborting, we use command's hba_wqidx.
11191 struct lpfc_sli_ring *
11192 lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
11194 struct lpfc_io_buf *lpfc_cmd;
11196 if (piocb->iocb_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
11197 if (unlikely(!phba->sli4_hba.hdwq))
11200 * for abort iocb hba_wqidx should already
11201 * be setup based on what work queue we used.
11203 if (!(piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
11204 lpfc_cmd = (struct lpfc_io_buf *)piocb->context1;
11205 piocb->hba_wqidx = lpfc_cmd->hdwq_no;
11207 return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
11209 if (unlikely(!phba->sli4_hba.els_wq))
11211 piocb->hba_wqidx = 0;
11212 return phba->sli4_hba.els_wq->pring;
11217 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
11218 * @phba: Pointer to HBA context object.
11219 * @ring_number: Ring number
11220 * @piocb: Pointer to command iocb.
11221 * @flag: Flag indicating if this command can be put into txq.
11223 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
11224 * function. This function gets the hbalock and calls
11225 * __lpfc_sli_issue_iocb function and will return the error returned
11226 * by __lpfc_sli_issue_iocb function. This wrapper is used by
11227 * functions which do not hold hbalock.
11230 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
11231 struct lpfc_iocbq *piocb, uint32_t flag)
11233 struct lpfc_sli_ring *pring;
11234 struct lpfc_queue *eq;
11235 unsigned long iflags;
11238 if (phba->sli_rev == LPFC_SLI_REV4) {
11239 eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq;
11241 pring = lpfc_sli4_calc_ring(phba, piocb);
11242 if (unlikely(pring == NULL))
11245 spin_lock_irqsave(&pring->ring_lock, iflags);
11246 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
11247 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11249 lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH);
11251 /* For now, SLI2/3 will still use hbalock */
11252 spin_lock_irqsave(&phba->hbalock, iflags);
11253 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
11254 spin_unlock_irqrestore(&phba->hbalock, iflags);
11260 * lpfc_extra_ring_setup - Extra ring setup function
11261 * @phba: Pointer to HBA context object.
11263 * This function is called while driver attaches with the
11264 * HBA to setup the extra ring. The extra ring is used
11265 * only when driver needs to support target mode functionality
11266 * or IP over FC functionalities.
11268 * This function is called with no lock held. SLI3 only.
11271 lpfc_extra_ring_setup( struct lpfc_hba *phba)
11273 struct lpfc_sli *psli;
11274 struct lpfc_sli_ring *pring;
11278 /* Adjust cmd/rsp ring iocb entries more evenly */
11280 /* Take some away from the FCP ring */
11281 pring = &psli->sli3_ring[LPFC_FCP_RING];
11282 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
11283 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
11284 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
11285 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
11287 /* and give them to the extra ring */
11288 pring = &psli->sli3_ring[LPFC_EXTRA_RING];
11290 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
11291 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
11292 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
11293 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
11295 /* Setup default profile for this ring */
11296 pring->iotag_max = 4096;
11297 pring->num_mask = 1;
11298 pring->prt[0].profile = 0; /* Mask 0 */
11299 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
11300 pring->prt[0].type = phba->cfg_multi_ring_type;
11301 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
11306 lpfc_sli_post_recovery_event(struct lpfc_hba *phba,
11307 struct lpfc_nodelist *ndlp)
11309 unsigned long iflags;
11310 struct lpfc_work_evt *evtp = &ndlp->recovery_evt;
11312 spin_lock_irqsave(&phba->hbalock, iflags);
11313 if (!list_empty(&evtp->evt_listp)) {
11314 spin_unlock_irqrestore(&phba->hbalock, iflags);
11318 /* Incrementing the reference count until the queued work is done. */
11319 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
11320 if (!evtp->evt_arg1) {
11321 spin_unlock_irqrestore(&phba->hbalock, iflags);
11324 evtp->evt = LPFC_EVT_RECOVER_PORT;
11325 list_add_tail(&evtp->evt_listp, &phba->work_list);
11326 spin_unlock_irqrestore(&phba->hbalock, iflags);
11328 lpfc_worker_wake_up(phba);
11331 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
11332 * @phba: Pointer to HBA context object.
11333 * @iocbq: Pointer to iocb object.
11335 * The async_event handler calls this routine when it receives
11336 * an ASYNC_STATUS_CN event from the port. The port generates
11337 * this event when an Abort Sequence request to an rport fails
11338 * twice in succession. The abort could be originated by the
11339 * driver or by the port. The ABTS could have been for an ELS
11340 * or FCP IO. The port only generates this event when an ABTS
11341 * fails to complete after one retry.
11344 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
11345 struct lpfc_iocbq *iocbq)
11347 struct lpfc_nodelist *ndlp = NULL;
11348 uint16_t rpi = 0, vpi = 0;
11349 struct lpfc_vport *vport = NULL;
11351 /* The rpi in the ulpContext is vport-sensitive. */
11352 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
11353 rpi = iocbq->iocb.ulpContext;
11355 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11356 "3092 Port generated ABTS async event "
11357 "on vpi %d rpi %d status 0x%x\n",
11358 vpi, rpi, iocbq->iocb.ulpStatus);
11360 vport = lpfc_find_vport_by_vpid(phba, vpi);
11363 ndlp = lpfc_findnode_rpi(vport, rpi);
11367 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
11368 lpfc_sli_abts_recover_port(vport, ndlp);
11372 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11373 "3095 Event Context not found, no "
11374 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
11375 iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus,
11379 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
11380 * @phba: pointer to HBA context object.
11381 * @ndlp: nodelist pointer for the impacted rport.
11382 * @axri: pointer to the wcqe containing the failed exchange.
11384 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
11385 * port. The port generates this event when an abort exchange request to an
11386 * rport fails twice in succession with no reply. The abort could be originated
11387 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
11390 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
11391 struct lpfc_nodelist *ndlp,
11392 struct sli4_wcqe_xri_aborted *axri)
11394 uint32_t ext_status = 0;
11397 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11398 "3115 Node Context not found, driver "
11399 "ignoring abts err event\n");
11403 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11404 "3116 Port generated FCP XRI ABORT event on "
11405 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
11406 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
11407 bf_get(lpfc_wcqe_xa_xri, axri),
11408 bf_get(lpfc_wcqe_xa_status, axri),
11412 * Catch the ABTS protocol failure case. Older OCe FW releases returned
11413 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
11414 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
11416 ext_status = axri->parameter & IOERR_PARAM_MASK;
11417 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
11418 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
11419 lpfc_sli_post_recovery_event(phba, ndlp);
11423 * lpfc_sli_async_event_handler - ASYNC iocb handler function
11424 * @phba: Pointer to HBA context object.
11425 * @pring: Pointer to driver SLI ring object.
11426 * @iocbq: Pointer to iocb object.
11428 * This function is called by the slow ring event handler
11429 * function when there is an ASYNC event iocb in the ring.
11430 * This function is called with no lock held.
11431 * Currently this function handles only temperature related
11432 * ASYNC events. The function decodes the temperature sensor
11433 * event message and posts events for the management applications.
11436 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
11437 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
11441 struct temp_event temp_event_data;
11442 struct Scsi_Host *shost;
11445 icmd = &iocbq->iocb;
11446 evt_code = icmd->un.asyncstat.evt_code;
11448 switch (evt_code) {
11449 case ASYNC_TEMP_WARN:
11450 case ASYNC_TEMP_SAFE:
11451 temp_event_data.data = (uint32_t) icmd->ulpContext;
11452 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
11453 if (evt_code == ASYNC_TEMP_WARN) {
11454 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
11455 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11456 "0347 Adapter is very hot, please take "
11457 "corrective action. temperature : %d Celsius\n",
11458 (uint32_t) icmd->ulpContext);
11460 temp_event_data.event_code = LPFC_NORMAL_TEMP;
11461 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11462 "0340 Adapter temperature is OK now. "
11463 "temperature : %d Celsius\n",
11464 (uint32_t) icmd->ulpContext);
11467 /* Send temperature change event to applications */
11468 shost = lpfc_shost_from_vport(phba->pport);
11469 fc_host_post_vendor_event(shost, fc_get_event_number(),
11470 sizeof(temp_event_data), (char *) &temp_event_data,
11471 LPFC_NL_VENDOR_ID);
11473 case ASYNC_STATUS_CN:
11474 lpfc_sli_abts_err_handler(phba, iocbq);
11477 iocb_w = (uint32_t *) icmd;
11478 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11479 "0346 Ring %d handler: unexpected ASYNC_STATUS"
11481 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
11482 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
11483 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
11484 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
11485 pring->ringno, icmd->un.asyncstat.evt_code,
11486 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
11487 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
11488 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
11489 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
11497 * lpfc_sli4_setup - SLI ring setup function
11498 * @phba: Pointer to HBA context object.
11500 * lpfc_sli_setup sets up rings of the SLI interface with
11501 * number of iocbs per ring and iotags. This function is
11502 * called while driver attach to the HBA and before the
11503 * interrupts are enabled. So there is no need for locking.
11505 * This function always returns 0.
11508 lpfc_sli4_setup(struct lpfc_hba *phba)
11510 struct lpfc_sli_ring *pring;
11512 pring = phba->sli4_hba.els_wq->pring;
11513 pring->num_mask = LPFC_MAX_RING_MASK;
11514 pring->prt[0].profile = 0; /* Mask 0 */
11515 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
11516 pring->prt[0].type = FC_TYPE_ELS;
11517 pring->prt[0].lpfc_sli_rcv_unsol_event =
11518 lpfc_els_unsol_event;
11519 pring->prt[1].profile = 0; /* Mask 1 */
11520 pring->prt[1].rctl = FC_RCTL_ELS_REP;
11521 pring->prt[1].type = FC_TYPE_ELS;
11522 pring->prt[1].lpfc_sli_rcv_unsol_event =
11523 lpfc_els_unsol_event;
11524 pring->prt[2].profile = 0; /* Mask 2 */
11525 /* NameServer Inquiry */
11526 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
11528 pring->prt[2].type = FC_TYPE_CT;
11529 pring->prt[2].lpfc_sli_rcv_unsol_event =
11530 lpfc_ct_unsol_event;
11531 pring->prt[3].profile = 0; /* Mask 3 */
11532 /* NameServer response */
11533 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
11535 pring->prt[3].type = FC_TYPE_CT;
11536 pring->prt[3].lpfc_sli_rcv_unsol_event =
11537 lpfc_ct_unsol_event;
11542 * lpfc_sli_setup - SLI ring setup function
11543 * @phba: Pointer to HBA context object.
11545 * lpfc_sli_setup sets up rings of the SLI interface with
11546 * number of iocbs per ring and iotags. This function is
11547 * called while driver attach to the HBA and before the
11548 * interrupts are enabled. So there is no need for locking.
11550 * This function always returns 0. SLI3 only.
11553 lpfc_sli_setup(struct lpfc_hba *phba)
11555 int i, totiocbsize = 0;
11556 struct lpfc_sli *psli = &phba->sli;
11557 struct lpfc_sli_ring *pring;
11559 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
11560 psli->sli_flag = 0;
11562 psli->iocbq_lookup = NULL;
11563 psli->iocbq_lookup_len = 0;
11564 psli->last_iotag = 0;
11566 for (i = 0; i < psli->num_rings; i++) {
11567 pring = &psli->sli3_ring[i];
11569 case LPFC_FCP_RING: /* ring 0 - FCP */
11570 /* numCiocb and numRiocb are used in config_port */
11571 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
11572 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
11573 pring->sli.sli3.numCiocb +=
11574 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
11575 pring->sli.sli3.numRiocb +=
11576 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
11577 pring->sli.sli3.numCiocb +=
11578 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
11579 pring->sli.sli3.numRiocb +=
11580 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
11581 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
11582 SLI3_IOCB_CMD_SIZE :
11583 SLI2_IOCB_CMD_SIZE;
11584 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
11585 SLI3_IOCB_RSP_SIZE :
11586 SLI2_IOCB_RSP_SIZE;
11587 pring->iotag_ctr = 0;
11589 (phba->cfg_hba_queue_depth * 2);
11590 pring->fast_iotag = pring->iotag_max;
11591 pring->num_mask = 0;
11593 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
11594 /* numCiocb and numRiocb are used in config_port */
11595 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
11596 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
11597 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
11598 SLI3_IOCB_CMD_SIZE :
11599 SLI2_IOCB_CMD_SIZE;
11600 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
11601 SLI3_IOCB_RSP_SIZE :
11602 SLI2_IOCB_RSP_SIZE;
11603 pring->iotag_max = phba->cfg_hba_queue_depth;
11604 pring->num_mask = 0;
11606 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
11607 /* numCiocb and numRiocb are used in config_port */
11608 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
11609 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
11610 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
11611 SLI3_IOCB_CMD_SIZE :
11612 SLI2_IOCB_CMD_SIZE;
11613 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
11614 SLI3_IOCB_RSP_SIZE :
11615 SLI2_IOCB_RSP_SIZE;
11616 pring->fast_iotag = 0;
11617 pring->iotag_ctr = 0;
11618 pring->iotag_max = 4096;
11619 pring->lpfc_sli_rcv_async_status =
11620 lpfc_sli_async_event_handler;
11621 pring->num_mask = LPFC_MAX_RING_MASK;
11622 pring->prt[0].profile = 0; /* Mask 0 */
11623 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
11624 pring->prt[0].type = FC_TYPE_ELS;
11625 pring->prt[0].lpfc_sli_rcv_unsol_event =
11626 lpfc_els_unsol_event;
11627 pring->prt[1].profile = 0; /* Mask 1 */
11628 pring->prt[1].rctl = FC_RCTL_ELS_REP;
11629 pring->prt[1].type = FC_TYPE_ELS;
11630 pring->prt[1].lpfc_sli_rcv_unsol_event =
11631 lpfc_els_unsol_event;
11632 pring->prt[2].profile = 0; /* Mask 2 */
11633 /* NameServer Inquiry */
11634 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
11636 pring->prt[2].type = FC_TYPE_CT;
11637 pring->prt[2].lpfc_sli_rcv_unsol_event =
11638 lpfc_ct_unsol_event;
11639 pring->prt[3].profile = 0; /* Mask 3 */
11640 /* NameServer response */
11641 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
11643 pring->prt[3].type = FC_TYPE_CT;
11644 pring->prt[3].lpfc_sli_rcv_unsol_event =
11645 lpfc_ct_unsol_event;
11648 totiocbsize += (pring->sli.sli3.numCiocb *
11649 pring->sli.sli3.sizeCiocb) +
11650 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
11652 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
11653 /* Too many cmd / rsp ring entries in SLI2 SLIM */
11654 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
11655 "SLI2 SLIM Data: x%x x%lx\n",
11656 phba->brd_no, totiocbsize,
11657 (unsigned long) MAX_SLIM_IOCB_SIZE);
11659 if (phba->cfg_multi_ring_support == 2)
11660 lpfc_extra_ring_setup(phba);
11666 * lpfc_sli4_queue_init - Queue initialization function
11667 * @phba: Pointer to HBA context object.
11669 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
11670 * ring. This function also initializes ring indices of each ring.
11671 * This function is called during the initialization of the SLI
11672 * interface of an HBA.
11673 * This function is called with no lock held and always returns
11677 lpfc_sli4_queue_init(struct lpfc_hba *phba)
11679 struct lpfc_sli *psli;
11680 struct lpfc_sli_ring *pring;
11684 spin_lock_irq(&phba->hbalock);
11685 INIT_LIST_HEAD(&psli->mboxq);
11686 INIT_LIST_HEAD(&psli->mboxq_cmpl);
11687 /* Initialize list headers for txq and txcmplq as double linked lists */
11688 for (i = 0; i < phba->cfg_hdw_queue; i++) {
11689 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
11691 pring->ringno = LPFC_FCP_RING;
11692 pring->txcmplq_cnt = 0;
11693 INIT_LIST_HEAD(&pring->txq);
11694 INIT_LIST_HEAD(&pring->txcmplq);
11695 INIT_LIST_HEAD(&pring->iocb_continueq);
11696 spin_lock_init(&pring->ring_lock);
11698 pring = phba->sli4_hba.els_wq->pring;
11700 pring->ringno = LPFC_ELS_RING;
11701 pring->txcmplq_cnt = 0;
11702 INIT_LIST_HEAD(&pring->txq);
11703 INIT_LIST_HEAD(&pring->txcmplq);
11704 INIT_LIST_HEAD(&pring->iocb_continueq);
11705 spin_lock_init(&pring->ring_lock);
11707 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11708 pring = phba->sli4_hba.nvmels_wq->pring;
11710 pring->ringno = LPFC_ELS_RING;
11711 pring->txcmplq_cnt = 0;
11712 INIT_LIST_HEAD(&pring->txq);
11713 INIT_LIST_HEAD(&pring->txcmplq);
11714 INIT_LIST_HEAD(&pring->iocb_continueq);
11715 spin_lock_init(&pring->ring_lock);
11718 spin_unlock_irq(&phba->hbalock);
11722 * lpfc_sli_queue_init - Queue initialization function
11723 * @phba: Pointer to HBA context object.
11725 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
11726 * ring. This function also initializes ring indices of each ring.
11727 * This function is called during the initialization of the SLI
11728 * interface of an HBA.
11729 * This function is called with no lock held and always returns
11733 lpfc_sli_queue_init(struct lpfc_hba *phba)
11735 struct lpfc_sli *psli;
11736 struct lpfc_sli_ring *pring;
11740 spin_lock_irq(&phba->hbalock);
11741 INIT_LIST_HEAD(&psli->mboxq);
11742 INIT_LIST_HEAD(&psli->mboxq_cmpl);
11743 /* Initialize list headers for txq and txcmplq as double linked lists */
11744 for (i = 0; i < psli->num_rings; i++) {
11745 pring = &psli->sli3_ring[i];
11747 pring->sli.sli3.next_cmdidx = 0;
11748 pring->sli.sli3.local_getidx = 0;
11749 pring->sli.sli3.cmdidx = 0;
11750 INIT_LIST_HEAD(&pring->iocb_continueq);
11751 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
11752 INIT_LIST_HEAD(&pring->postbufq);
11754 INIT_LIST_HEAD(&pring->txq);
11755 INIT_LIST_HEAD(&pring->txcmplq);
11756 spin_lock_init(&pring->ring_lock);
11758 spin_unlock_irq(&phba->hbalock);
11762 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
11763 * @phba: Pointer to HBA context object.
11765 * This routine flushes the mailbox command subsystem. It will unconditionally
11766 * flush all the mailbox commands in the three possible stages in the mailbox
11767 * command sub-system: pending mailbox command queue; the outstanding mailbox
11768 * command; and completed mailbox command queue. It is caller's responsibility
11769 * to make sure that the driver is in the proper state to flush the mailbox
11770 * command sub-system. Namely, the posting of mailbox commands into the
11771 * pending mailbox command queue from the various clients must be stopped;
11772 * either the HBA is in a state that it will never works on the outstanding
11773 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
11774 * mailbox command has been completed.
11777 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
11779 LIST_HEAD(completions);
11780 struct lpfc_sli *psli = &phba->sli;
11782 unsigned long iflag;
11784 /* Disable softirqs, including timers from obtaining phba->hbalock */
11785 local_bh_disable();
11787 /* Flush all the mailbox commands in the mbox system */
11788 spin_lock_irqsave(&phba->hbalock, iflag);
11790 /* The pending mailbox command queue */
11791 list_splice_init(&phba->sli.mboxq, &completions);
11792 /* The outstanding active mailbox command */
11793 if (psli->mbox_active) {
11794 list_add_tail(&psli->mbox_active->list, &completions);
11795 psli->mbox_active = NULL;
11796 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11798 /* The completed mailbox command queue */
11799 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
11800 spin_unlock_irqrestore(&phba->hbalock, iflag);
11802 /* Enable softirqs again, done with phba->hbalock */
11805 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
11806 while (!list_empty(&completions)) {
11807 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
11808 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
11809 if (pmb->mbox_cmpl)
11810 pmb->mbox_cmpl(phba, pmb);
11815 * lpfc_sli_host_down - Vport cleanup function
11816 * @vport: Pointer to virtual port object.
11818 * lpfc_sli_host_down is called to clean up the resources
11819 * associated with a vport before destroying virtual
11820 * port data structures.
11821 * This function does following operations:
11822 * - Free discovery resources associated with this virtual
11824 * - Free iocbs associated with this virtual port in
11826 * - Send abort for all iocb commands associated with this
11827 * vport in txcmplq.
11829 * This function is called with no lock held and always returns 1.
11832 lpfc_sli_host_down(struct lpfc_vport *vport)
11834 LIST_HEAD(completions);
11835 struct lpfc_hba *phba = vport->phba;
11836 struct lpfc_sli *psli = &phba->sli;
11837 struct lpfc_queue *qp = NULL;
11838 struct lpfc_sli_ring *pring;
11839 struct lpfc_iocbq *iocb, *next_iocb;
11841 unsigned long flags = 0;
11842 uint16_t prev_pring_flag;
11844 lpfc_cleanup_discovery_resources(vport);
11846 spin_lock_irqsave(&phba->hbalock, flags);
11849 * Error everything on the txq since these iocbs
11850 * have not been given to the FW yet.
11851 * Also issue ABTS for everything on the txcmplq
11853 if (phba->sli_rev != LPFC_SLI_REV4) {
11854 for (i = 0; i < psli->num_rings; i++) {
11855 pring = &psli->sli3_ring[i];
11856 prev_pring_flag = pring->flag;
11857 /* Only slow rings */
11858 if (pring->ringno == LPFC_ELS_RING) {
11859 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11860 /* Set the lpfc data pending flag */
11861 set_bit(LPFC_DATA_READY, &phba->data_flags);
11863 list_for_each_entry_safe(iocb, next_iocb,
11864 &pring->txq, list) {
11865 if (iocb->vport != vport)
11867 list_move_tail(&iocb->list, &completions);
11869 list_for_each_entry_safe(iocb, next_iocb,
11870 &pring->txcmplq, list) {
11871 if (iocb->vport != vport)
11873 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
11876 pring->flag = prev_pring_flag;
11879 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11883 if (pring == phba->sli4_hba.els_wq->pring) {
11884 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11885 /* Set the lpfc data pending flag */
11886 set_bit(LPFC_DATA_READY, &phba->data_flags);
11888 prev_pring_flag = pring->flag;
11889 spin_lock(&pring->ring_lock);
11890 list_for_each_entry_safe(iocb, next_iocb,
11891 &pring->txq, list) {
11892 if (iocb->vport != vport)
11894 list_move_tail(&iocb->list, &completions);
11896 spin_unlock(&pring->ring_lock);
11897 list_for_each_entry_safe(iocb, next_iocb,
11898 &pring->txcmplq, list) {
11899 if (iocb->vport != vport)
11901 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
11904 pring->flag = prev_pring_flag;
11907 spin_unlock_irqrestore(&phba->hbalock, flags);
11909 /* Make sure HBA is alive */
11910 lpfc_issue_hb_tmo(phba);
11912 /* Cancel all the IOCBs from the completions list */
11913 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11919 * lpfc_sli_hba_down - Resource cleanup function for the HBA
11920 * @phba: Pointer to HBA context object.
11922 * This function cleans up all iocb, buffers, mailbox commands
11923 * while shutting down the HBA. This function is called with no
11924 * lock held and always returns 1.
11925 * This function does the following to cleanup driver resources:
11926 * - Free discovery resources for each virtual port
11927 * - Cleanup any pending fabric iocbs
11928 * - Iterate through the iocb txq and free each entry
11930 * - Free up any buffer posted to the HBA
11931 * - Free mailbox commands in the mailbox queue.
11934 lpfc_sli_hba_down(struct lpfc_hba *phba)
11936 LIST_HEAD(completions);
11937 struct lpfc_sli *psli = &phba->sli;
11938 struct lpfc_queue *qp = NULL;
11939 struct lpfc_sli_ring *pring;
11940 struct lpfc_dmabuf *buf_ptr;
11941 unsigned long flags = 0;
11944 /* Shutdown the mailbox command sub-system */
11945 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
11947 lpfc_hba_down_prep(phba);
11949 /* Disable softirqs, including timers from obtaining phba->hbalock */
11950 local_bh_disable();
11952 lpfc_fabric_abort_hba(phba);
11954 spin_lock_irqsave(&phba->hbalock, flags);
11957 * Error everything on the txq since these iocbs
11958 * have not been given to the FW yet.
11960 if (phba->sli_rev != LPFC_SLI_REV4) {
11961 for (i = 0; i < psli->num_rings; i++) {
11962 pring = &psli->sli3_ring[i];
11963 /* Only slow rings */
11964 if (pring->ringno == LPFC_ELS_RING) {
11965 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11966 /* Set the lpfc data pending flag */
11967 set_bit(LPFC_DATA_READY, &phba->data_flags);
11969 list_splice_init(&pring->txq, &completions);
11972 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11976 spin_lock(&pring->ring_lock);
11977 list_splice_init(&pring->txq, &completions);
11978 spin_unlock(&pring->ring_lock);
11979 if (pring == phba->sli4_hba.els_wq->pring) {
11980 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11981 /* Set the lpfc data pending flag */
11982 set_bit(LPFC_DATA_READY, &phba->data_flags);
11986 spin_unlock_irqrestore(&phba->hbalock, flags);
11988 /* Cancel all the IOCBs from the completions list */
11989 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
11992 spin_lock_irqsave(&phba->hbalock, flags);
11993 list_splice_init(&phba->elsbuf, &completions);
11994 phba->elsbuf_cnt = 0;
11995 phba->elsbuf_prev_cnt = 0;
11996 spin_unlock_irqrestore(&phba->hbalock, flags);
11998 while (!list_empty(&completions)) {
11999 list_remove_head(&completions, buf_ptr,
12000 struct lpfc_dmabuf, list);
12001 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
12005 /* Enable softirqs again, done with phba->hbalock */
12008 /* Return any active mbox cmds */
12009 del_timer_sync(&psli->mbox_tmo);
12011 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
12012 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
12013 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
12019 * lpfc_sli_pcimem_bcopy - SLI memory copy function
12020 * @srcp: Source memory pointer.
12021 * @destp: Destination memory pointer.
12022 * @cnt: Number of words required to be copied.
12024 * This function is used for copying data between driver memory
12025 * and the SLI memory. This function also changes the endianness
12026 * of each word if native endianness is different from SLI
12027 * endianness. This function can be called with or without
12031 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
12033 uint32_t *src = srcp;
12034 uint32_t *dest = destp;
12038 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
12040 ldata = le32_to_cpu(ldata);
12049 * lpfc_sli_bemem_bcopy - SLI memory copy function
12050 * @srcp: Source memory pointer.
12051 * @destp: Destination memory pointer.
12052 * @cnt: Number of words required to be copied.
12054 * This function is used for copying data between a data structure
12055 * with big endian representation to local endianness.
12056 * This function can be called with or without lock.
12059 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
12061 uint32_t *src = srcp;
12062 uint32_t *dest = destp;
12066 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
12068 ldata = be32_to_cpu(ldata);
12076 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
12077 * @phba: Pointer to HBA context object.
12078 * @pring: Pointer to driver SLI ring object.
12079 * @mp: Pointer to driver buffer object.
12081 * This function is called with no lock held.
12082 * It always return zero after adding the buffer to the postbufq
12086 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12087 struct lpfc_dmabuf *mp)
12089 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
12091 spin_lock_irq(&phba->hbalock);
12092 list_add_tail(&mp->list, &pring->postbufq);
12093 pring->postbufq_cnt++;
12094 spin_unlock_irq(&phba->hbalock);
12099 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
12100 * @phba: Pointer to HBA context object.
12102 * When HBQ is enabled, buffers are searched based on tags. This function
12103 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
12104 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
12105 * does not conflict with tags of buffer posted for unsolicited events.
12106 * The function returns the allocated tag. The function is called with
12110 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
12112 spin_lock_irq(&phba->hbalock);
12113 phba->buffer_tag_count++;
12115 * Always set the QUE_BUFTAG_BIT to distiguish between
12116 * a tag assigned by HBQ.
12118 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
12119 spin_unlock_irq(&phba->hbalock);
12120 return phba->buffer_tag_count;
12124 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
12125 * @phba: Pointer to HBA context object.
12126 * @pring: Pointer to driver SLI ring object.
12127 * @tag: Buffer tag.
12129 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
12130 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
12131 * iocb is posted to the response ring with the tag of the buffer.
12132 * This function searches the pring->postbufq list using the tag
12133 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
12134 * iocb. If the buffer is found then lpfc_dmabuf object of the
12135 * buffer is returned to the caller else NULL is returned.
12136 * This function is called with no lock held.
12138 struct lpfc_dmabuf *
12139 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12142 struct lpfc_dmabuf *mp, *next_mp;
12143 struct list_head *slp = &pring->postbufq;
12145 /* Search postbufq, from the beginning, looking for a match on tag */
12146 spin_lock_irq(&phba->hbalock);
12147 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
12148 if (mp->buffer_tag == tag) {
12149 list_del_init(&mp->list);
12150 pring->postbufq_cnt--;
12151 spin_unlock_irq(&phba->hbalock);
12156 spin_unlock_irq(&phba->hbalock);
12157 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12158 "0402 Cannot find virtual addr for buffer tag on "
12159 "ring %d Data x%lx x%px x%px x%x\n",
12160 pring->ringno, (unsigned long) tag,
12161 slp->next, slp->prev, pring->postbufq_cnt);
12167 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
12168 * @phba: Pointer to HBA context object.
12169 * @pring: Pointer to driver SLI ring object.
12170 * @phys: DMA address of the buffer.
12172 * This function searches the buffer list using the dma_address
12173 * of unsolicited event to find the driver's lpfc_dmabuf object
12174 * corresponding to the dma_address. The function returns the
12175 * lpfc_dmabuf object if a buffer is found else it returns NULL.
12176 * This function is called by the ct and els unsolicited event
12177 * handlers to get the buffer associated with the unsolicited
12180 * This function is called with no lock held.
12182 struct lpfc_dmabuf *
12183 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12186 struct lpfc_dmabuf *mp, *next_mp;
12187 struct list_head *slp = &pring->postbufq;
12189 /* Search postbufq, from the beginning, looking for a match on phys */
12190 spin_lock_irq(&phba->hbalock);
12191 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
12192 if (mp->phys == phys) {
12193 list_del_init(&mp->list);
12194 pring->postbufq_cnt--;
12195 spin_unlock_irq(&phba->hbalock);
12200 spin_unlock_irq(&phba->hbalock);
12201 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12202 "0410 Cannot find virtual addr for mapped buf on "
12203 "ring %d Data x%llx x%px x%px x%x\n",
12204 pring->ringno, (unsigned long long)phys,
12205 slp->next, slp->prev, pring->postbufq_cnt);
12210 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
12211 * @phba: Pointer to HBA context object.
12212 * @cmdiocb: Pointer to driver command iocb object.
12213 * @rspiocb: Pointer to driver response iocb object.
12215 * This function is the completion handler for the abort iocbs for
12216 * ELS commands. This function is called from the ELS ring event
12217 * handler with no lock held. This function frees memory resources
12218 * associated with the abort iocb.
12221 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12222 struct lpfc_iocbq *rspiocb)
12224 IOCB_t *irsp = &rspiocb->iocb;
12225 uint16_t abort_iotag, abort_context;
12226 struct lpfc_iocbq *abort_iocb = NULL;
12228 if (irsp->ulpStatus) {
12231 * Assume that the port already completed and returned, or
12232 * will return the iocb. Just Log the message.
12234 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
12235 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
12237 spin_lock_irq(&phba->hbalock);
12238 if (phba->sli_rev < LPFC_SLI_REV4) {
12239 if (irsp->ulpCommand == CMD_ABORT_XRI_CX &&
12240 irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
12241 irsp->un.ulpWord[4] == IOERR_ABORT_REQUESTED) {
12242 spin_unlock_irq(&phba->hbalock);
12245 if (abort_iotag != 0 &&
12246 abort_iotag <= phba->sli.last_iotag)
12248 phba->sli.iocbq_lookup[abort_iotag];
12250 /* For sli4 the abort_tag is the XRI,
12251 * so the abort routine puts the iotag of the iocb
12252 * being aborted in the context field of the abort
12255 abort_iocb = phba->sli.iocbq_lookup[abort_context];
12257 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
12258 "0327 Cannot abort els iocb x%px "
12259 "with tag %x context %x, abort status %x, "
12261 abort_iocb, abort_iotag, abort_context,
12262 irsp->ulpStatus, irsp->un.ulpWord[4]);
12264 spin_unlock_irq(&phba->hbalock);
12267 lpfc_sli_release_iocbq(phba, cmdiocb);
12272 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
12273 * @phba: Pointer to HBA context object.
12274 * @cmdiocb: Pointer to driver command iocb object.
12275 * @rspiocb: Pointer to driver response iocb object.
12277 * The function is called from SLI ring event handler with no
12278 * lock held. This function is the completion handler for ELS commands
12279 * which are aborted. The function frees memory resources used for
12280 * the aborted ELS commands.
12283 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12284 struct lpfc_iocbq *rspiocb)
12286 struct lpfc_nodelist *ndlp = NULL;
12287 IOCB_t *irsp = &rspiocb->iocb;
12289 /* ELS cmd tag <ulpIoTag> completes */
12290 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
12291 "0139 Ignoring ELS cmd code x%x completion Data: "
12293 irsp->ulpIoTag, irsp->ulpStatus,
12294 irsp->un.ulpWord[4], irsp->ulpTimeout);
12296 * Deref the ndlp after free_iocb. sli_release_iocb will access the ndlp
12297 * if exchange is busy.
12299 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) {
12300 ndlp = cmdiocb->context_un.ndlp;
12301 lpfc_ct_free_iocb(phba, cmdiocb);
12303 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
12304 lpfc_els_free_iocb(phba, cmdiocb);
12307 lpfc_nlp_put(ndlp);
12311 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
12312 * @phba: Pointer to HBA context object.
12313 * @pring: Pointer to driver SLI ring object.
12314 * @cmdiocb: Pointer to driver command iocb object.
12315 * @cmpl: completion function.
12317 * This function issues an abort iocb for the provided command iocb. In case
12318 * of unloading, the abort iocb will not be issued to commands on the ELS
12319 * ring. Instead, the callback function shall be changed to those commands
12320 * so that nothing happens when them finishes. This function is called with
12321 * hbalock held andno ring_lock held (SLI4). The function returns IOCB_SUCCESS
12322 * when the command iocb is an abort request.
12326 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12327 struct lpfc_iocbq *cmdiocb, void *cmpl)
12329 struct lpfc_vport *vport = cmdiocb->vport;
12330 struct lpfc_iocbq *abtsiocbp;
12331 IOCB_t *icmd = NULL;
12332 IOCB_t *iabt = NULL;
12333 int retval = IOCB_ERROR;
12334 unsigned long iflags;
12335 struct lpfc_nodelist *ndlp;
12338 * There are certain command types we don't want to abort. And we
12339 * don't want to abort commands that are already in the process of
12342 icmd = &cmdiocb->iocb;
12343 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
12344 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
12345 cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED)
12346 return IOCB_ABORTING;
12349 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
12350 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
12352 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
12357 * If we're unloading, don't abort iocb on the ELS ring, but change
12358 * the callback so that nothing happens when it finishes.
12360 if ((vport->load_flag & FC_UNLOADING) &&
12361 pring->ringno == LPFC_ELS_RING) {
12362 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
12363 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
12365 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
12369 /* issue ABTS for this IOCB based on iotag */
12370 abtsiocbp = __lpfc_sli_get_iocbq(phba);
12371 if (abtsiocbp == NULL)
12372 return IOCB_NORESOURCE;
12374 /* This signals the response to set the correct status
12375 * before calling the completion handler
12377 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
12379 iabt = &abtsiocbp->iocb;
12380 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
12381 iabt->un.acxri.abortContextTag = icmd->ulpContext;
12382 if (phba->sli_rev == LPFC_SLI_REV4) {
12383 iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag;
12384 if (pring->ringno == LPFC_ELS_RING)
12385 iabt->un.acxri.abortContextTag = cmdiocb->iotag;
12387 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
12388 if (pring->ringno == LPFC_ELS_RING) {
12389 ndlp = (struct lpfc_nodelist *)(cmdiocb->context1);
12390 iabt->un.acxri.abortContextTag = ndlp->nlp_rpi;
12394 iabt->ulpClass = icmd->ulpClass;
12396 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
12397 abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
12398 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
12399 abtsiocbp->iocb_flag |= (LPFC_IO_FCP | LPFC_USE_FCPWQIDX);
12400 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
12401 abtsiocbp->iocb_flag |= LPFC_IO_FOF;
12403 if (phba->link_state < LPFC_LINK_UP ||
12404 (phba->sli_rev == LPFC_SLI_REV4 &&
12405 phba->sli4_hba.link_state.status == LPFC_FC_LA_TYPE_LINK_DOWN))
12406 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
12408 iabt->ulpCommand = CMD_ABORT_XRI_CN;
12411 abtsiocbp->iocb_cmpl = cmpl;
12413 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
12414 abtsiocbp->vport = vport;
12416 if (phba->sli_rev == LPFC_SLI_REV4) {
12417 pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
12418 if (unlikely(pring == NULL))
12419 goto abort_iotag_exit;
12420 /* Note: both hbalock and ring_lock need to be set here */
12421 spin_lock_irqsave(&pring->ring_lock, iflags);
12422 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
12424 spin_unlock_irqrestore(&pring->ring_lock, iflags);
12426 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
12432 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
12433 "0339 Abort xri x%x, original iotag x%x, "
12434 "abort cmd iotag x%x retval x%x\n",
12435 iabt->un.acxri.abortIoTag,
12436 iabt->un.acxri.abortContextTag,
12437 abtsiocbp->iotag, retval);
12440 cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
12441 __lpfc_sli_release_iocbq(phba, abtsiocbp);
12445 * Caller to this routine should check for IOCB_ERROR
12446 * and handle it properly. This routine no longer removes
12447 * iocb off txcmplq and call compl in case of IOCB_ERROR.
12453 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
12454 * @phba: pointer to lpfc HBA data structure.
12456 * This routine will abort all pending and outstanding iocbs to an HBA.
12459 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
12461 struct lpfc_sli *psli = &phba->sli;
12462 struct lpfc_sli_ring *pring;
12463 struct lpfc_queue *qp = NULL;
12466 if (phba->sli_rev != LPFC_SLI_REV4) {
12467 for (i = 0; i < psli->num_rings; i++) {
12468 pring = &psli->sli3_ring[i];
12469 lpfc_sli_abort_iocb_ring(phba, pring);
12473 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
12477 lpfc_sli_abort_iocb_ring(phba, pring);
12482 * lpfc_sli_validate_fcp_iocb_for_abort - filter iocbs appropriate for FCP aborts
12483 * @iocbq: Pointer to iocb object.
12484 * @vport: Pointer to driver virtual port object.
12486 * This function acts as an iocb filter for functions which abort FCP iocbs.
12489 * -ENODEV, if a null iocb or vport ptr is encountered
12490 * -EINVAL, if the iocb is not an FCP I/O, not on the TX cmpl queue, premarked as
12491 * driver already started the abort process, or is an abort iocb itself
12492 * 0, passes criteria for aborting the FCP I/O iocb
12495 lpfc_sli_validate_fcp_iocb_for_abort(struct lpfc_iocbq *iocbq,
12496 struct lpfc_vport *vport)
12498 IOCB_t *icmd = NULL;
12500 /* No null ptr vports */
12501 if (!iocbq || iocbq->vport != vport)
12504 /* iocb must be for FCP IO, already exists on the TX cmpl queue,
12505 * can't be premarked as driver aborted, nor be an ABORT iocb itself
12507 icmd = &iocbq->iocb;
12508 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
12509 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ) ||
12510 (iocbq->iocb_flag & LPFC_DRIVER_ABORTED) ||
12511 (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
12512 icmd->ulpCommand == CMD_CLOSE_XRI_CN))
12519 * lpfc_sli_validate_fcp_iocb - validate commands associated with a SCSI target
12520 * @iocbq: Pointer to driver iocb object.
12521 * @vport: Pointer to driver virtual port object.
12522 * @tgt_id: SCSI ID of the target.
12523 * @lun_id: LUN ID of the scsi device.
12524 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
12526 * This function acts as an iocb filter for validating a lun/SCSI target/SCSI
12530 * 0 if the filtering criteria is met for the given iocb and will return
12531 * 1 if the filtering criteria is not met.
12532 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
12533 * given iocb is for the SCSI device specified by vport, tgt_id and
12534 * lun_id parameter.
12535 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
12536 * given iocb is for the SCSI target specified by vport and tgt_id
12538 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
12539 * given iocb is for the SCSI host associated with the given vport.
12540 * This function is called with no locks held.
12543 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
12544 uint16_t tgt_id, uint64_t lun_id,
12545 lpfc_ctx_cmd ctx_cmd)
12547 struct lpfc_io_buf *lpfc_cmd;
12550 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
12552 if (lpfc_cmd->pCmd == NULL)
12557 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
12558 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
12559 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
12563 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
12564 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
12567 case LPFC_CTX_HOST:
12571 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
12572 __func__, ctx_cmd);
12580 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
12581 * @vport: Pointer to virtual port.
12582 * @tgt_id: SCSI ID of the target.
12583 * @lun_id: LUN ID of the scsi device.
12584 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12586 * This function returns number of FCP commands pending for the vport.
12587 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
12588 * commands pending on the vport associated with SCSI device specified
12589 * by tgt_id and lun_id parameters.
12590 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
12591 * commands pending on the vport associated with SCSI target specified
12592 * by tgt_id parameter.
12593 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
12594 * commands pending on the vport.
12595 * This function returns the number of iocbs which satisfy the filter.
12596 * This function is called without any lock held.
12599 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
12600 lpfc_ctx_cmd ctx_cmd)
12602 struct lpfc_hba *phba = vport->phba;
12603 struct lpfc_iocbq *iocbq;
12604 IOCB_t *icmd = NULL;
12606 unsigned long iflags;
12608 spin_lock_irqsave(&phba->hbalock, iflags);
12609 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
12610 iocbq = phba->sli.iocbq_lookup[i];
12612 if (!iocbq || iocbq->vport != vport)
12614 if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
12615 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ))
12618 /* Include counting outstanding aborts */
12619 icmd = &iocbq->iocb;
12620 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
12621 icmd->ulpCommand == CMD_CLOSE_XRI_CN) {
12626 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12630 spin_unlock_irqrestore(&phba->hbalock, iflags);
12636 * lpfc_sli4_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
12637 * @phba: Pointer to HBA context object
12638 * @cmdiocb: Pointer to command iocb object.
12639 * @wcqe: pointer to the complete wcqe
12641 * This function is called when an aborted FCP iocb completes. This
12642 * function is called by the ring event handler with no lock held.
12643 * This function frees the iocb. It is called for sli-4 adapters.
12646 lpfc_sli4_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12647 struct lpfc_wcqe_complete *wcqe)
12649 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12650 "3017 ABORT_XRI_CN completing on rpi x%x "
12651 "original iotag x%x, abort cmd iotag x%x "
12652 "status 0x%x, reason 0x%x\n",
12653 cmdiocb->iocb.un.acxri.abortContextTag,
12654 cmdiocb->iocb.un.acxri.abortIoTag,
12656 (bf_get(lpfc_wcqe_c_status, wcqe)
12657 & LPFC_IOCB_STATUS_MASK),
12659 lpfc_sli_release_iocbq(phba, cmdiocb);
12663 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
12664 * @phba: Pointer to HBA context object
12665 * @cmdiocb: Pointer to command iocb object.
12666 * @rspiocb: Pointer to response iocb object.
12668 * This function is called when an aborted FCP iocb completes. This
12669 * function is called by the ring event handler with no lock held.
12670 * This function frees the iocb.
12673 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12674 struct lpfc_iocbq *rspiocb)
12676 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12677 "3096 ABORT_XRI_CN completing on rpi x%x "
12678 "original iotag x%x, abort cmd iotag x%x "
12679 "status 0x%x, reason 0x%x\n",
12680 cmdiocb->iocb.un.acxri.abortContextTag,
12681 cmdiocb->iocb.un.acxri.abortIoTag,
12682 cmdiocb->iotag, rspiocb->iocb.ulpStatus,
12683 rspiocb->iocb.un.ulpWord[4]);
12684 lpfc_sli_release_iocbq(phba, cmdiocb);
12689 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
12690 * @vport: Pointer to virtual port.
12691 * @tgt_id: SCSI ID of the target.
12692 * @lun_id: LUN ID of the scsi device.
12693 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12695 * This function sends an abort command for every SCSI command
12696 * associated with the given virtual port pending on the ring
12697 * filtered by lpfc_sli_validate_fcp_iocb_for_abort and then
12698 * lpfc_sli_validate_fcp_iocb function. The ordering for validation before
12699 * submitting abort iocbs must be lpfc_sli_validate_fcp_iocb_for_abort
12700 * followed by lpfc_sli_validate_fcp_iocb.
12702 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
12703 * FCP iocbs associated with lun specified by tgt_id and lun_id
12705 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
12706 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
12707 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
12708 * FCP iocbs associated with virtual port.
12709 * The pring used for SLI3 is sli3_ring[LPFC_FCP_RING], for SLI4
12710 * lpfc_sli4_calc_ring is used.
12711 * This function returns number of iocbs it failed to abort.
12712 * This function is called with no locks held.
12715 lpfc_sli_abort_iocb(struct lpfc_vport *vport, u16 tgt_id, u64 lun_id,
12716 lpfc_ctx_cmd abort_cmd)
12718 struct lpfc_hba *phba = vport->phba;
12719 struct lpfc_sli_ring *pring = NULL;
12720 struct lpfc_iocbq *iocbq;
12721 int errcnt = 0, ret_val = 0;
12722 unsigned long iflags;
12724 void *fcp_cmpl = NULL;
12726 /* all I/Os are in process of being flushed */
12727 if (phba->hba_flag & HBA_IOQ_FLUSH)
12730 for (i = 1; i <= phba->sli.last_iotag; i++) {
12731 iocbq = phba->sli.iocbq_lookup[i];
12733 if (lpfc_sli_validate_fcp_iocb_for_abort(iocbq, vport))
12736 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12740 spin_lock_irqsave(&phba->hbalock, iflags);
12741 if (phba->sli_rev == LPFC_SLI_REV3) {
12742 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
12743 fcp_cmpl = lpfc_sli_abort_fcp_cmpl;
12744 } else if (phba->sli_rev == LPFC_SLI_REV4) {
12745 pring = lpfc_sli4_calc_ring(phba, iocbq);
12746 fcp_cmpl = lpfc_sli4_abort_fcp_cmpl;
12748 ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocbq,
12750 spin_unlock_irqrestore(&phba->hbalock, iflags);
12751 if (ret_val != IOCB_SUCCESS)
12759 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
12760 * @vport: Pointer to virtual port.
12761 * @pring: Pointer to driver SLI ring object.
12762 * @tgt_id: SCSI ID of the target.
12763 * @lun_id: LUN ID of the scsi device.
12764 * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12766 * This function sends an abort command for every SCSI command
12767 * associated with the given virtual port pending on the ring
12768 * filtered by lpfc_sli_validate_fcp_iocb_for_abort and then
12769 * lpfc_sli_validate_fcp_iocb function. The ordering for validation before
12770 * submitting abort iocbs must be lpfc_sli_validate_fcp_iocb_for_abort
12771 * followed by lpfc_sli_validate_fcp_iocb.
12773 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
12774 * FCP iocbs associated with lun specified by tgt_id and lun_id
12776 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
12777 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
12778 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
12779 * FCP iocbs associated with virtual port.
12780 * This function returns number of iocbs it aborted .
12781 * This function is called with no locks held right after a taskmgmt
12785 lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
12786 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
12788 struct lpfc_hba *phba = vport->phba;
12789 struct lpfc_io_buf *lpfc_cmd;
12790 struct lpfc_iocbq *abtsiocbq;
12791 struct lpfc_nodelist *ndlp;
12792 struct lpfc_iocbq *iocbq;
12794 int sum, i, ret_val;
12795 unsigned long iflags;
12796 struct lpfc_sli_ring *pring_s4 = NULL;
12798 spin_lock_irqsave(&phba->hbalock, iflags);
12800 /* all I/Os are in process of being flushed */
12801 if (phba->hba_flag & HBA_IOQ_FLUSH) {
12802 spin_unlock_irqrestore(&phba->hbalock, iflags);
12807 for (i = 1; i <= phba->sli.last_iotag; i++) {
12808 iocbq = phba->sli.iocbq_lookup[i];
12810 if (lpfc_sli_validate_fcp_iocb_for_abort(iocbq, vport))
12813 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12817 /* Guard against IO completion being called at same time */
12818 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
12819 spin_lock(&lpfc_cmd->buf_lock);
12821 if (!lpfc_cmd->pCmd) {
12822 spin_unlock(&lpfc_cmd->buf_lock);
12826 if (phba->sli_rev == LPFC_SLI_REV4) {
12828 phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
12830 spin_unlock(&lpfc_cmd->buf_lock);
12833 /* Note: both hbalock and ring_lock must be set here */
12834 spin_lock(&pring_s4->ring_lock);
12838 * If the iocbq is already being aborted, don't take a second
12839 * action, but do count it.
12841 if ((iocbq->iocb_flag & LPFC_DRIVER_ABORTED) ||
12842 !(iocbq->iocb_flag & LPFC_IO_ON_TXCMPLQ)) {
12843 if (phba->sli_rev == LPFC_SLI_REV4)
12844 spin_unlock(&pring_s4->ring_lock);
12845 spin_unlock(&lpfc_cmd->buf_lock);
12849 /* issue ABTS for this IOCB based on iotag */
12850 abtsiocbq = __lpfc_sli_get_iocbq(phba);
12852 if (phba->sli_rev == LPFC_SLI_REV4)
12853 spin_unlock(&pring_s4->ring_lock);
12854 spin_unlock(&lpfc_cmd->buf_lock);
12858 icmd = &iocbq->iocb;
12859 abtsiocbq->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
12860 abtsiocbq->iocb.un.acxri.abortContextTag = icmd->ulpContext;
12861 if (phba->sli_rev == LPFC_SLI_REV4)
12862 abtsiocbq->iocb.un.acxri.abortIoTag =
12863 iocbq->sli4_xritag;
12865 abtsiocbq->iocb.un.acxri.abortIoTag = icmd->ulpIoTag;
12866 abtsiocbq->iocb.ulpLe = 1;
12867 abtsiocbq->iocb.ulpClass = icmd->ulpClass;
12868 abtsiocbq->vport = vport;
12870 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
12871 abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
12872 if (iocbq->iocb_flag & LPFC_IO_FCP)
12873 abtsiocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
12874 if (iocbq->iocb_flag & LPFC_IO_FOF)
12875 abtsiocbq->iocb_flag |= LPFC_IO_FOF;
12877 ndlp = lpfc_cmd->rdata->pnode;
12879 if (lpfc_is_link_up(phba) &&
12880 (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE))
12881 abtsiocbq->iocb.ulpCommand = CMD_ABORT_XRI_CN;
12883 abtsiocbq->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
12885 /* Setup callback routine and issue the command. */
12886 abtsiocbq->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
12889 * Indicate the IO is being aborted by the driver and set
12890 * the caller's flag into the aborted IO.
12892 iocbq->iocb_flag |= LPFC_DRIVER_ABORTED;
12894 if (phba->sli_rev == LPFC_SLI_REV4) {
12895 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
12897 spin_unlock(&pring_s4->ring_lock);
12899 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
12903 spin_unlock(&lpfc_cmd->buf_lock);
12905 if (ret_val == IOCB_ERROR)
12906 __lpfc_sli_release_iocbq(phba, abtsiocbq);
12910 spin_unlock_irqrestore(&phba->hbalock, iflags);
12915 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
12916 * @phba: Pointer to HBA context object.
12917 * @cmdiocbq: Pointer to command iocb.
12918 * @rspiocbq: Pointer to response iocb.
12920 * This function is the completion handler for iocbs issued using
12921 * lpfc_sli_issue_iocb_wait function. This function is called by the
12922 * ring event handler function without any lock held. This function
12923 * can be called from both worker thread context and interrupt
12924 * context. This function also can be called from other thread which
12925 * cleans up the SLI layer objects.
12926 * This function copy the contents of the response iocb to the
12927 * response iocb memory object provided by the caller of
12928 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
12929 * sleeps for the iocb completion.
12932 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
12933 struct lpfc_iocbq *cmdiocbq,
12934 struct lpfc_iocbq *rspiocbq)
12936 wait_queue_head_t *pdone_q;
12937 unsigned long iflags;
12938 struct lpfc_io_buf *lpfc_cmd;
12940 spin_lock_irqsave(&phba->hbalock, iflags);
12941 if (cmdiocbq->iocb_flag & LPFC_IO_WAKE_TMO) {
12944 * A time out has occurred for the iocb. If a time out
12945 * completion handler has been supplied, call it. Otherwise,
12946 * just free the iocbq.
12949 spin_unlock_irqrestore(&phba->hbalock, iflags);
12950 cmdiocbq->iocb_cmpl = cmdiocbq->wait_iocb_cmpl;
12951 cmdiocbq->wait_iocb_cmpl = NULL;
12952 if (cmdiocbq->iocb_cmpl)
12953 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, NULL);
12955 lpfc_sli_release_iocbq(phba, cmdiocbq);
12959 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
12960 if (cmdiocbq->context2 && rspiocbq)
12961 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
12962 &rspiocbq->iocb, sizeof(IOCB_t));
12964 /* Set the exchange busy flag for task management commands */
12965 if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
12966 !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) {
12967 lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
12969 if (rspiocbq && (rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY))
12970 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
12972 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
12975 pdone_q = cmdiocbq->context_un.wait_queue;
12978 spin_unlock_irqrestore(&phba->hbalock, iflags);
12983 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
12984 * @phba: Pointer to HBA context object..
12985 * @piocbq: Pointer to command iocb.
12986 * @flag: Flag to test.
12988 * This routine grabs the hbalock and then test the iocb_flag to
12989 * see if the passed in flag is set.
12991 * 1 if flag is set.
12992 * 0 if flag is not set.
12995 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
12996 struct lpfc_iocbq *piocbq, uint32_t flag)
12998 unsigned long iflags;
13001 spin_lock_irqsave(&phba->hbalock, iflags);
13002 ret = piocbq->iocb_flag & flag;
13003 spin_unlock_irqrestore(&phba->hbalock, iflags);
13009 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
13010 * @phba: Pointer to HBA context object..
13011 * @ring_number: Ring number
13012 * @piocb: Pointer to command iocb.
13013 * @prspiocbq: Pointer to response iocb.
13014 * @timeout: Timeout in number of seconds.
13016 * This function issues the iocb to firmware and waits for the
13017 * iocb to complete. The iocb_cmpl field of the shall be used
13018 * to handle iocbs which time out. If the field is NULL, the
13019 * function shall free the iocbq structure. If more clean up is
13020 * needed, the caller is expected to provide a completion function
13021 * that will provide the needed clean up. If the iocb command is
13022 * not completed within timeout seconds, the function will either
13023 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
13024 * completion function set in the iocb_cmpl field and then return
13025 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
13026 * resources if this function returns IOCB_TIMEDOUT.
13027 * The function waits for the iocb completion using an
13028 * non-interruptible wait.
13029 * This function will sleep while waiting for iocb completion.
13030 * So, this function should not be called from any context which
13031 * does not allow sleeping. Due to the same reason, this function
13032 * cannot be called with interrupt disabled.
13033 * This function assumes that the iocb completions occur while
13034 * this function sleep. So, this function cannot be called from
13035 * the thread which process iocb completion for this ring.
13036 * This function clears the iocb_flag of the iocb object before
13037 * issuing the iocb and the iocb completion handler sets this
13038 * flag and wakes this thread when the iocb completes.
13039 * The contents of the response iocb will be copied to prspiocbq
13040 * by the completion handler when the command completes.
13041 * This function returns IOCB_SUCCESS when success.
13042 * This function is called with no lock held.
13045 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
13046 uint32_t ring_number,
13047 struct lpfc_iocbq *piocb,
13048 struct lpfc_iocbq *prspiocbq,
13051 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
13052 long timeleft, timeout_req = 0;
13053 int retval = IOCB_SUCCESS;
13055 struct lpfc_iocbq *iocb;
13057 int txcmplq_cnt = 0;
13058 struct lpfc_sli_ring *pring;
13059 unsigned long iflags;
13060 bool iocb_completed = true;
13062 if (phba->sli_rev >= LPFC_SLI_REV4)
13063 pring = lpfc_sli4_calc_ring(phba, piocb);
13065 pring = &phba->sli.sli3_ring[ring_number];
13067 * If the caller has provided a response iocbq buffer, then context2
13068 * is NULL or its an error.
13071 if (piocb->context2)
13073 piocb->context2 = prspiocbq;
13076 piocb->wait_iocb_cmpl = piocb->iocb_cmpl;
13077 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
13078 piocb->context_un.wait_queue = &done_q;
13079 piocb->iocb_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
13081 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
13082 if (lpfc_readl(phba->HCregaddr, &creg_val))
13084 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
13085 writel(creg_val, phba->HCregaddr);
13086 readl(phba->HCregaddr); /* flush */
13089 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
13090 SLI_IOCB_RET_IOCB);
13091 if (retval == IOCB_SUCCESS) {
13092 timeout_req = msecs_to_jiffies(timeout * 1000);
13093 timeleft = wait_event_timeout(done_q,
13094 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
13096 spin_lock_irqsave(&phba->hbalock, iflags);
13097 if (!(piocb->iocb_flag & LPFC_IO_WAKE)) {
13100 * IOCB timed out. Inform the wake iocb wait
13101 * completion function and set local status
13104 iocb_completed = false;
13105 piocb->iocb_flag |= LPFC_IO_WAKE_TMO;
13107 spin_unlock_irqrestore(&phba->hbalock, iflags);
13108 if (iocb_completed) {
13109 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13110 "0331 IOCB wake signaled\n");
13111 /* Note: we are not indicating if the IOCB has a success
13112 * status or not - that's for the caller to check.
13113 * IOCB_SUCCESS means just that the command was sent and
13114 * completed. Not that it completed successfully.
13116 } else if (timeleft == 0) {
13117 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13118 "0338 IOCB wait timeout error - no "
13119 "wake response Data x%x\n", timeout);
13120 retval = IOCB_TIMEDOUT;
13122 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13123 "0330 IOCB wake NOT set, "
13125 timeout, (timeleft / jiffies));
13126 retval = IOCB_TIMEDOUT;
13128 } else if (retval == IOCB_BUSY) {
13129 if (phba->cfg_log_verbose & LOG_SLI) {
13130 list_for_each_entry(iocb, &pring->txq, list) {
13133 list_for_each_entry(iocb, &pring->txcmplq, list) {
13136 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13137 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
13138 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
13142 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13143 "0332 IOCB wait issue failed, Data x%x\n",
13145 retval = IOCB_ERROR;
13148 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
13149 if (lpfc_readl(phba->HCregaddr, &creg_val))
13151 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
13152 writel(creg_val, phba->HCregaddr);
13153 readl(phba->HCregaddr); /* flush */
13157 piocb->context2 = NULL;
13159 piocb->context_un.wait_queue = NULL;
13160 piocb->iocb_cmpl = NULL;
13165 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
13166 * @phba: Pointer to HBA context object.
13167 * @pmboxq: Pointer to driver mailbox object.
13168 * @timeout: Timeout in number of seconds.
13170 * This function issues the mailbox to firmware and waits for the
13171 * mailbox command to complete. If the mailbox command is not
13172 * completed within timeout seconds, it returns MBX_TIMEOUT.
13173 * The function waits for the mailbox completion using an
13174 * interruptible wait. If the thread is woken up due to a
13175 * signal, MBX_TIMEOUT error is returned to the caller. Caller
13176 * should not free the mailbox resources, if this function returns
13178 * This function will sleep while waiting for mailbox completion.
13179 * So, this function should not be called from any context which
13180 * does not allow sleeping. Due to the same reason, this function
13181 * cannot be called with interrupt disabled.
13182 * This function assumes that the mailbox completion occurs while
13183 * this function sleep. So, this function cannot be called from
13184 * the worker thread which processes mailbox completion.
13185 * This function is called in the context of HBA management
13187 * This function returns MBX_SUCCESS when successful.
13188 * This function is called with no lock held.
13191 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
13194 struct completion mbox_done;
13196 unsigned long flag;
13198 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
13199 /* setup wake call as IOCB callback */
13200 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
13202 /* setup context3 field to pass wait_queue pointer to wake function */
13203 init_completion(&mbox_done);
13204 pmboxq->context3 = &mbox_done;
13205 /* now issue the command */
13206 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
13207 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
13208 wait_for_completion_timeout(&mbox_done,
13209 msecs_to_jiffies(timeout * 1000));
13211 spin_lock_irqsave(&phba->hbalock, flag);
13212 pmboxq->context3 = NULL;
13214 * if LPFC_MBX_WAKE flag is set the mailbox is completed
13215 * else do not free the resources.
13217 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
13218 retval = MBX_SUCCESS;
13220 retval = MBX_TIMEOUT;
13221 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13223 spin_unlock_irqrestore(&phba->hbalock, flag);
13229 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
13230 * @phba: Pointer to HBA context.
13231 * @mbx_action: Mailbox shutdown options.
13233 * This function is called to shutdown the driver's mailbox sub-system.
13234 * It first marks the mailbox sub-system is in a block state to prevent
13235 * the asynchronous mailbox command from issued off the pending mailbox
13236 * command queue. If the mailbox command sub-system shutdown is due to
13237 * HBA error conditions such as EEH or ERATT, this routine shall invoke
13238 * the mailbox sub-system flush routine to forcefully bring down the
13239 * mailbox sub-system. Otherwise, if it is due to normal condition (such
13240 * as with offline or HBA function reset), this routine will wait for the
13241 * outstanding mailbox command to complete before invoking the mailbox
13242 * sub-system flush routine to gracefully bring down mailbox sub-system.
13245 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
13247 struct lpfc_sli *psli = &phba->sli;
13248 unsigned long timeout;
13250 if (mbx_action == LPFC_MBX_NO_WAIT) {
13251 /* delay 100ms for port state */
13253 lpfc_sli_mbox_sys_flush(phba);
13256 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
13258 /* Disable softirqs, including timers from obtaining phba->hbalock */
13259 local_bh_disable();
13261 spin_lock_irq(&phba->hbalock);
13262 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13264 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
13265 /* Determine how long we might wait for the active mailbox
13266 * command to be gracefully completed by firmware.
13268 if (phba->sli.mbox_active)
13269 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
13270 phba->sli.mbox_active) *
13272 spin_unlock_irq(&phba->hbalock);
13274 /* Enable softirqs again, done with phba->hbalock */
13277 while (phba->sli.mbox_active) {
13278 /* Check active mailbox complete status every 2ms */
13280 if (time_after(jiffies, timeout))
13281 /* Timeout, let the mailbox flush routine to
13282 * forcefully release active mailbox command
13287 spin_unlock_irq(&phba->hbalock);
13289 /* Enable softirqs again, done with phba->hbalock */
13293 lpfc_sli_mbox_sys_flush(phba);
13297 * lpfc_sli_eratt_read - read sli-3 error attention events
13298 * @phba: Pointer to HBA context.
13300 * This function is called to read the SLI3 device error attention registers
13301 * for possible error attention events. The caller must hold the hostlock
13302 * with spin_lock_irq().
13304 * This function returns 1 when there is Error Attention in the Host Attention
13305 * Register and returns 0 otherwise.
13308 lpfc_sli_eratt_read(struct lpfc_hba *phba)
13312 /* Read chip Host Attention (HA) register */
13313 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13316 if (ha_copy & HA_ERATT) {
13317 /* Read host status register to retrieve error event */
13318 if (lpfc_sli_read_hs(phba))
13321 /* Check if there is a deferred error condition is active */
13322 if ((HS_FFER1 & phba->work_hs) &&
13323 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
13324 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
13325 phba->hba_flag |= DEFER_ERATT;
13326 /* Clear all interrupt enable conditions */
13327 writel(0, phba->HCregaddr);
13328 readl(phba->HCregaddr);
13331 /* Set the driver HA work bitmap */
13332 phba->work_ha |= HA_ERATT;
13333 /* Indicate polling handles this ERATT */
13334 phba->hba_flag |= HBA_ERATT_HANDLED;
13340 /* Set the driver HS work bitmap */
13341 phba->work_hs |= UNPLUG_ERR;
13342 /* Set the driver HA work bitmap */
13343 phba->work_ha |= HA_ERATT;
13344 /* Indicate polling handles this ERATT */
13345 phba->hba_flag |= HBA_ERATT_HANDLED;
13350 * lpfc_sli4_eratt_read - read sli-4 error attention events
13351 * @phba: Pointer to HBA context.
13353 * This function is called to read the SLI4 device error attention registers
13354 * for possible error attention events. The caller must hold the hostlock
13355 * with spin_lock_irq().
13357 * This function returns 1 when there is Error Attention in the Host Attention
13358 * Register and returns 0 otherwise.
13361 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
13363 uint32_t uerr_sta_hi, uerr_sta_lo;
13364 uint32_t if_type, portsmphr;
13365 struct lpfc_register portstat_reg;
13368 * For now, use the SLI4 device internal unrecoverable error
13369 * registers for error attention. This can be changed later.
13371 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
13373 case LPFC_SLI_INTF_IF_TYPE_0:
13374 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
13376 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
13378 phba->work_hs |= UNPLUG_ERR;
13379 phba->work_ha |= HA_ERATT;
13380 phba->hba_flag |= HBA_ERATT_HANDLED;
13383 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
13384 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
13385 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13386 "1423 HBA Unrecoverable error: "
13387 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
13388 "ue_mask_lo_reg=0x%x, "
13389 "ue_mask_hi_reg=0x%x\n",
13390 uerr_sta_lo, uerr_sta_hi,
13391 phba->sli4_hba.ue_mask_lo,
13392 phba->sli4_hba.ue_mask_hi);
13393 phba->work_status[0] = uerr_sta_lo;
13394 phba->work_status[1] = uerr_sta_hi;
13395 phba->work_ha |= HA_ERATT;
13396 phba->hba_flag |= HBA_ERATT_HANDLED;
13400 case LPFC_SLI_INTF_IF_TYPE_2:
13401 case LPFC_SLI_INTF_IF_TYPE_6:
13402 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
13403 &portstat_reg.word0) ||
13404 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
13406 phba->work_hs |= UNPLUG_ERR;
13407 phba->work_ha |= HA_ERATT;
13408 phba->hba_flag |= HBA_ERATT_HANDLED;
13411 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
13412 phba->work_status[0] =
13413 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
13414 phba->work_status[1] =
13415 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
13416 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13417 "2885 Port Status Event: "
13418 "port status reg 0x%x, "
13419 "port smphr reg 0x%x, "
13420 "error 1=0x%x, error 2=0x%x\n",
13421 portstat_reg.word0,
13423 phba->work_status[0],
13424 phba->work_status[1]);
13425 phba->work_ha |= HA_ERATT;
13426 phba->hba_flag |= HBA_ERATT_HANDLED;
13430 case LPFC_SLI_INTF_IF_TYPE_1:
13432 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13433 "2886 HBA Error Attention on unsupported "
13434 "if type %d.", if_type);
13442 * lpfc_sli_check_eratt - check error attention events
13443 * @phba: Pointer to HBA context.
13445 * This function is called from timer soft interrupt context to check HBA's
13446 * error attention register bit for error attention events.
13448 * This function returns 1 when there is Error Attention in the Host Attention
13449 * Register and returns 0 otherwise.
13452 lpfc_sli_check_eratt(struct lpfc_hba *phba)
13456 /* If somebody is waiting to handle an eratt, don't process it
13457 * here. The brdkill function will do this.
13459 if (phba->link_flag & LS_IGNORE_ERATT)
13462 /* Check if interrupt handler handles this ERATT */
13463 spin_lock_irq(&phba->hbalock);
13464 if (phba->hba_flag & HBA_ERATT_HANDLED) {
13465 /* Interrupt handler has handled ERATT */
13466 spin_unlock_irq(&phba->hbalock);
13471 * If there is deferred error attention, do not check for error
13474 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13475 spin_unlock_irq(&phba->hbalock);
13479 /* If PCI channel is offline, don't process it */
13480 if (unlikely(pci_channel_offline(phba->pcidev))) {
13481 spin_unlock_irq(&phba->hbalock);
13485 switch (phba->sli_rev) {
13486 case LPFC_SLI_REV2:
13487 case LPFC_SLI_REV3:
13488 /* Read chip Host Attention (HA) register */
13489 ha_copy = lpfc_sli_eratt_read(phba);
13491 case LPFC_SLI_REV4:
13492 /* Read device Uncoverable Error (UERR) registers */
13493 ha_copy = lpfc_sli4_eratt_read(phba);
13496 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13497 "0299 Invalid SLI revision (%d)\n",
13502 spin_unlock_irq(&phba->hbalock);
13508 * lpfc_intr_state_check - Check device state for interrupt handling
13509 * @phba: Pointer to HBA context.
13511 * This inline routine checks whether a device or its PCI slot is in a state
13512 * that the interrupt should be handled.
13514 * This function returns 0 if the device or the PCI slot is in a state that
13515 * interrupt should be handled, otherwise -EIO.
13518 lpfc_intr_state_check(struct lpfc_hba *phba)
13520 /* If the pci channel is offline, ignore all the interrupts */
13521 if (unlikely(pci_channel_offline(phba->pcidev)))
13524 /* Update device level interrupt statistics */
13525 phba->sli.slistat.sli_intr++;
13527 /* Ignore all interrupts during initialization. */
13528 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
13535 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
13536 * @irq: Interrupt number.
13537 * @dev_id: The device context pointer.
13539 * This function is directly called from the PCI layer as an interrupt
13540 * service routine when device with SLI-3 interface spec is enabled with
13541 * MSI-X multi-message interrupt mode and there are slow-path events in
13542 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
13543 * interrupt mode, this function is called as part of the device-level
13544 * interrupt handler. When the PCI slot is in error recovery or the HBA
13545 * is undergoing initialization, the interrupt handler will not process
13546 * the interrupt. The link attention and ELS ring attention events are
13547 * handled by the worker thread. The interrupt handler signals the worker
13548 * thread and returns for these events. This function is called without
13549 * any lock held. It gets the hbalock to access and update SLI data
13552 * This function returns IRQ_HANDLED when interrupt is handled else it
13553 * returns IRQ_NONE.
13556 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
13558 struct lpfc_hba *phba;
13559 uint32_t ha_copy, hc_copy;
13560 uint32_t work_ha_copy;
13561 unsigned long status;
13562 unsigned long iflag;
13565 MAILBOX_t *mbox, *pmbox;
13566 struct lpfc_vport *vport;
13567 struct lpfc_nodelist *ndlp;
13568 struct lpfc_dmabuf *mp;
13573 * Get the driver's phba structure from the dev_id and
13574 * assume the HBA is not interrupting.
13576 phba = (struct lpfc_hba *)dev_id;
13578 if (unlikely(!phba))
13582 * Stuff needs to be attented to when this function is invoked as an
13583 * individual interrupt handler in MSI-X multi-message interrupt mode
13585 if (phba->intr_type == MSIX) {
13586 /* Check device state for handling interrupt */
13587 if (lpfc_intr_state_check(phba))
13589 /* Need to read HA REG for slow-path events */
13590 spin_lock_irqsave(&phba->hbalock, iflag);
13591 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13593 /* If somebody is waiting to handle an eratt don't process it
13594 * here. The brdkill function will do this.
13596 if (phba->link_flag & LS_IGNORE_ERATT)
13597 ha_copy &= ~HA_ERATT;
13598 /* Check the need for handling ERATT in interrupt handler */
13599 if (ha_copy & HA_ERATT) {
13600 if (phba->hba_flag & HBA_ERATT_HANDLED)
13601 /* ERATT polling has handled ERATT */
13602 ha_copy &= ~HA_ERATT;
13604 /* Indicate interrupt handler handles ERATT */
13605 phba->hba_flag |= HBA_ERATT_HANDLED;
13609 * If there is deferred error attention, do not check for any
13612 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13613 spin_unlock_irqrestore(&phba->hbalock, iflag);
13617 /* Clear up only attention source related to slow-path */
13618 if (lpfc_readl(phba->HCregaddr, &hc_copy))
13621 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
13622 HC_LAINT_ENA | HC_ERINT_ENA),
13624 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
13626 writel(hc_copy, phba->HCregaddr);
13627 readl(phba->HAregaddr); /* flush */
13628 spin_unlock_irqrestore(&phba->hbalock, iflag);
13630 ha_copy = phba->ha_copy;
13632 work_ha_copy = ha_copy & phba->work_ha_mask;
13634 if (work_ha_copy) {
13635 if (work_ha_copy & HA_LATT) {
13636 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
13638 * Turn off Link Attention interrupts
13639 * until CLEAR_LA done
13641 spin_lock_irqsave(&phba->hbalock, iflag);
13642 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
13643 if (lpfc_readl(phba->HCregaddr, &control))
13645 control &= ~HC_LAINT_ENA;
13646 writel(control, phba->HCregaddr);
13647 readl(phba->HCregaddr); /* flush */
13648 spin_unlock_irqrestore(&phba->hbalock, iflag);
13651 work_ha_copy &= ~HA_LATT;
13654 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
13656 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
13657 * the only slow ring.
13659 status = (work_ha_copy &
13660 (HA_RXMASK << (4*LPFC_ELS_RING)));
13661 status >>= (4*LPFC_ELS_RING);
13662 if (status & HA_RXMASK) {
13663 spin_lock_irqsave(&phba->hbalock, iflag);
13664 if (lpfc_readl(phba->HCregaddr, &control))
13667 lpfc_debugfs_slow_ring_trc(phba,
13668 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
13670 (uint32_t)phba->sli.slistat.sli_intr);
13672 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
13673 lpfc_debugfs_slow_ring_trc(phba,
13674 "ISR Disable ring:"
13675 "pwork:x%x hawork:x%x wait:x%x",
13676 phba->work_ha, work_ha_copy,
13677 (uint32_t)((unsigned long)
13678 &phba->work_waitq));
13681 ~(HC_R0INT_ENA << LPFC_ELS_RING);
13682 writel(control, phba->HCregaddr);
13683 readl(phba->HCregaddr); /* flush */
13686 lpfc_debugfs_slow_ring_trc(phba,
13687 "ISR slow ring: pwork:"
13688 "x%x hawork:x%x wait:x%x",
13689 phba->work_ha, work_ha_copy,
13690 (uint32_t)((unsigned long)
13691 &phba->work_waitq));
13693 spin_unlock_irqrestore(&phba->hbalock, iflag);
13696 spin_lock_irqsave(&phba->hbalock, iflag);
13697 if (work_ha_copy & HA_ERATT) {
13698 if (lpfc_sli_read_hs(phba))
13701 * Check if there is a deferred error condition
13704 if ((HS_FFER1 & phba->work_hs) &&
13705 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
13706 HS_FFER6 | HS_FFER7 | HS_FFER8) &
13708 phba->hba_flag |= DEFER_ERATT;
13709 /* Clear all interrupt enable conditions */
13710 writel(0, phba->HCregaddr);
13711 readl(phba->HCregaddr);
13715 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
13716 pmb = phba->sli.mbox_active;
13717 pmbox = &pmb->u.mb;
13719 vport = pmb->vport;
13721 /* First check out the status word */
13722 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
13723 if (pmbox->mbxOwner != OWN_HOST) {
13724 spin_unlock_irqrestore(&phba->hbalock, iflag);
13726 * Stray Mailbox Interrupt, mbxCommand <cmd>
13727 * mbxStatus <status>
13729 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13730 "(%d):0304 Stray Mailbox "
13731 "Interrupt mbxCommand x%x "
13733 (vport ? vport->vpi : 0),
13736 /* clear mailbox attention bit */
13737 work_ha_copy &= ~HA_MBATT;
13739 phba->sli.mbox_active = NULL;
13740 spin_unlock_irqrestore(&phba->hbalock, iflag);
13741 phba->last_completion_time = jiffies;
13742 del_timer(&phba->sli.mbox_tmo);
13743 if (pmb->mbox_cmpl) {
13744 lpfc_sli_pcimem_bcopy(mbox, pmbox,
13746 if (pmb->out_ext_byte_len &&
13748 lpfc_sli_pcimem_bcopy(
13751 pmb->out_ext_byte_len);
13753 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
13754 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
13756 lpfc_debugfs_disc_trc(vport,
13757 LPFC_DISC_TRC_MBOX_VPORT,
13758 "MBOX dflt rpi: : "
13759 "status:x%x rpi:x%x",
13760 (uint32_t)pmbox->mbxStatus,
13761 pmbox->un.varWords[0], 0);
13763 if (!pmbox->mbxStatus) {
13764 mp = (struct lpfc_dmabuf *)
13766 ndlp = (struct lpfc_nodelist *)
13769 /* Reg_LOGIN of dflt RPI was
13770 * successful. new lets get
13771 * rid of the RPI using the
13772 * same mbox buffer.
13774 lpfc_unreg_login(phba,
13776 pmbox->un.varWords[0],
13779 lpfc_mbx_cmpl_dflt_rpi;
13781 pmb->ctx_ndlp = ndlp;
13782 pmb->vport = vport;
13783 rc = lpfc_sli_issue_mbox(phba,
13786 if (rc != MBX_BUSY)
13787 lpfc_printf_log(phba,
13790 "0350 rc should have"
13791 "been MBX_BUSY\n");
13792 if (rc != MBX_NOT_FINISHED)
13793 goto send_current_mbox;
13797 &phba->pport->work_port_lock,
13799 phba->pport->work_port_events &=
13801 spin_unlock_irqrestore(
13802 &phba->pport->work_port_lock,
13805 /* Do NOT queue MBX_HEARTBEAT to the worker
13806 * thread for processing.
13808 if (pmbox->mbxCommand == MBX_HEARTBEAT) {
13809 /* Process mbox now */
13810 phba->sli.mbox_active = NULL;
13811 phba->sli.sli_flag &=
13812 ~LPFC_SLI_MBOX_ACTIVE;
13813 if (pmb->mbox_cmpl)
13814 pmb->mbox_cmpl(phba, pmb);
13816 /* Queue to worker thread to process */
13817 lpfc_mbox_cmpl_put(phba, pmb);
13821 spin_unlock_irqrestore(&phba->hbalock, iflag);
13823 if ((work_ha_copy & HA_MBATT) &&
13824 (phba->sli.mbox_active == NULL)) {
13826 /* Process next mailbox command if there is one */
13828 rc = lpfc_sli_issue_mbox(phba, NULL,
13830 } while (rc == MBX_NOT_FINISHED);
13831 if (rc != MBX_SUCCESS)
13832 lpfc_printf_log(phba, KERN_ERR,
13834 "0349 rc should be "
13838 spin_lock_irqsave(&phba->hbalock, iflag);
13839 phba->work_ha |= work_ha_copy;
13840 spin_unlock_irqrestore(&phba->hbalock, iflag);
13841 lpfc_worker_wake_up(phba);
13843 return IRQ_HANDLED;
13845 spin_unlock_irqrestore(&phba->hbalock, iflag);
13846 return IRQ_HANDLED;
13848 } /* lpfc_sli_sp_intr_handler */
13851 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
13852 * @irq: Interrupt number.
13853 * @dev_id: The device context pointer.
13855 * This function is directly called from the PCI layer as an interrupt
13856 * service routine when device with SLI-3 interface spec is enabled with
13857 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13858 * ring event in the HBA. However, when the device is enabled with either
13859 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13860 * device-level interrupt handler. When the PCI slot is in error recovery
13861 * or the HBA is undergoing initialization, the interrupt handler will not
13862 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13863 * the intrrupt context. This function is called without any lock held.
13864 * It gets the hbalock to access and update SLI data structures.
13866 * This function returns IRQ_HANDLED when interrupt is handled else it
13867 * returns IRQ_NONE.
13870 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
13872 struct lpfc_hba *phba;
13874 unsigned long status;
13875 unsigned long iflag;
13876 struct lpfc_sli_ring *pring;
13878 /* Get the driver's phba structure from the dev_id and
13879 * assume the HBA is not interrupting.
13881 phba = (struct lpfc_hba *) dev_id;
13883 if (unlikely(!phba))
13887 * Stuff needs to be attented to when this function is invoked as an
13888 * individual interrupt handler in MSI-X multi-message interrupt mode
13890 if (phba->intr_type == MSIX) {
13891 /* Check device state for handling interrupt */
13892 if (lpfc_intr_state_check(phba))
13894 /* Need to read HA REG for FCP ring and other ring events */
13895 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13896 return IRQ_HANDLED;
13897 /* Clear up only attention source related to fast-path */
13898 spin_lock_irqsave(&phba->hbalock, iflag);
13900 * If there is deferred error attention, do not check for
13903 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13904 spin_unlock_irqrestore(&phba->hbalock, iflag);
13907 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
13909 readl(phba->HAregaddr); /* flush */
13910 spin_unlock_irqrestore(&phba->hbalock, iflag);
13912 ha_copy = phba->ha_copy;
13915 * Process all events on FCP ring. Take the optimized path for FCP IO.
13917 ha_copy &= ~(phba->work_ha_mask);
13919 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
13920 status >>= (4*LPFC_FCP_RING);
13921 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
13922 if (status & HA_RXMASK)
13923 lpfc_sli_handle_fast_ring_event(phba, pring, status);
13925 if (phba->cfg_multi_ring_support == 2) {
13927 * Process all events on extra ring. Take the optimized path
13928 * for extra ring IO.
13930 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
13931 status >>= (4*LPFC_EXTRA_RING);
13932 if (status & HA_RXMASK) {
13933 lpfc_sli_handle_fast_ring_event(phba,
13934 &phba->sli.sli3_ring[LPFC_EXTRA_RING],
13938 return IRQ_HANDLED;
13939 } /* lpfc_sli_fp_intr_handler */
13942 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
13943 * @irq: Interrupt number.
13944 * @dev_id: The device context pointer.
13946 * This function is the HBA device-level interrupt handler to device with
13947 * SLI-3 interface spec, called from the PCI layer when either MSI or
13948 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
13949 * requires driver attention. This function invokes the slow-path interrupt
13950 * attention handling function and fast-path interrupt attention handling
13951 * function in turn to process the relevant HBA attention events. This
13952 * function is called without any lock held. It gets the hbalock to access
13953 * and update SLI data structures.
13955 * This function returns IRQ_HANDLED when interrupt is handled, else it
13956 * returns IRQ_NONE.
13959 lpfc_sli_intr_handler(int irq, void *dev_id)
13961 struct lpfc_hba *phba;
13962 irqreturn_t sp_irq_rc, fp_irq_rc;
13963 unsigned long status1, status2;
13967 * Get the driver's phba structure from the dev_id and
13968 * assume the HBA is not interrupting.
13970 phba = (struct lpfc_hba *) dev_id;
13972 if (unlikely(!phba))
13975 /* Check device state for handling interrupt */
13976 if (lpfc_intr_state_check(phba))
13979 spin_lock(&phba->hbalock);
13980 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
13981 spin_unlock(&phba->hbalock);
13982 return IRQ_HANDLED;
13985 if (unlikely(!phba->ha_copy)) {
13986 spin_unlock(&phba->hbalock);
13988 } else if (phba->ha_copy & HA_ERATT) {
13989 if (phba->hba_flag & HBA_ERATT_HANDLED)
13990 /* ERATT polling has handled ERATT */
13991 phba->ha_copy &= ~HA_ERATT;
13993 /* Indicate interrupt handler handles ERATT */
13994 phba->hba_flag |= HBA_ERATT_HANDLED;
13998 * If there is deferred error attention, do not check for any interrupt.
14000 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
14001 spin_unlock(&phba->hbalock);
14005 /* Clear attention sources except link and error attentions */
14006 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
14007 spin_unlock(&phba->hbalock);
14008 return IRQ_HANDLED;
14010 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
14011 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
14013 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
14014 writel(hc_copy, phba->HCregaddr);
14015 readl(phba->HAregaddr); /* flush */
14016 spin_unlock(&phba->hbalock);
14019 * Invokes slow-path host attention interrupt handling as appropriate.
14022 /* status of events with mailbox and link attention */
14023 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
14025 /* status of events with ELS ring */
14026 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
14027 status2 >>= (4*LPFC_ELS_RING);
14029 if (status1 || (status2 & HA_RXMASK))
14030 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
14032 sp_irq_rc = IRQ_NONE;
14035 * Invoke fast-path host attention interrupt handling as appropriate.
14038 /* status of events with FCP ring */
14039 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
14040 status1 >>= (4*LPFC_FCP_RING);
14042 /* status of events with extra ring */
14043 if (phba->cfg_multi_ring_support == 2) {
14044 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
14045 status2 >>= (4*LPFC_EXTRA_RING);
14049 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
14050 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
14052 fp_irq_rc = IRQ_NONE;
14054 /* Return device-level interrupt handling status */
14055 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
14056 } /* lpfc_sli_intr_handler */
14059 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
14060 * @phba: pointer to lpfc hba data structure.
14062 * This routine is invoked by the worker thread to process all the pending
14063 * SLI4 els abort xri events.
14065 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
14067 struct lpfc_cq_event *cq_event;
14068 unsigned long iflags;
14070 /* First, declare the els xri abort event has been handled */
14071 spin_lock_irqsave(&phba->hbalock, iflags);
14072 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
14073 spin_unlock_irqrestore(&phba->hbalock, iflags);
14075 /* Now, handle all the els xri abort events */
14076 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
14077 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
14078 /* Get the first event from the head of the event queue */
14079 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
14080 cq_event, struct lpfc_cq_event, list);
14081 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
14083 /* Notify aborted XRI for ELS work queue */
14084 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
14086 /* Free the event processed back to the free pool */
14087 lpfc_sli4_cq_event_release(phba, cq_event);
14088 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
14091 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
14095 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
14096 * @phba: pointer to lpfc hba data structure
14097 * @pIocbIn: pointer to the rspiocbq
14098 * @pIocbOut: pointer to the cmdiocbq
14099 * @wcqe: pointer to the complete wcqe
14101 * This routine transfers the fields of a command iocbq to a response iocbq
14102 * by copying all the IOCB fields from command iocbq and transferring the
14103 * completion status information from the complete wcqe.
14106 lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
14107 struct lpfc_iocbq *pIocbIn,
14108 struct lpfc_iocbq *pIocbOut,
14109 struct lpfc_wcqe_complete *wcqe)
14112 unsigned long iflags;
14113 uint32_t status, max_response;
14114 struct lpfc_dmabuf *dmabuf;
14115 struct ulp_bde64 *bpl, bde;
14116 size_t offset = offsetof(struct lpfc_iocbq, iocb);
14118 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
14119 sizeof(struct lpfc_iocbq) - offset);
14120 /* Map WCQE parameters into irspiocb parameters */
14121 status = bf_get(lpfc_wcqe_c_status, wcqe);
14122 pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK);
14123 if (pIocbOut->iocb_flag & LPFC_IO_FCP)
14124 if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR)
14125 pIocbIn->iocb.un.fcpi.fcpi_parm =
14126 pIocbOut->iocb.un.fcpi.fcpi_parm -
14127 wcqe->total_data_placed;
14129 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
14131 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
14132 switch (pIocbOut->iocb.ulpCommand) {
14133 case CMD_ELS_REQUEST64_CR:
14134 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
14135 bpl = (struct ulp_bde64 *)dmabuf->virt;
14136 bde.tus.w = le32_to_cpu(bpl[1].tus.w);
14137 max_response = bde.tus.f.bdeSize;
14139 case CMD_GEN_REQUEST64_CR:
14141 if (!pIocbOut->context3)
14143 numBdes = pIocbOut->iocb.un.genreq64.bdl.bdeSize/
14144 sizeof(struct ulp_bde64);
14145 dmabuf = (struct lpfc_dmabuf *)pIocbOut->context3;
14146 bpl = (struct ulp_bde64 *)dmabuf->virt;
14147 for (i = 0; i < numBdes; i++) {
14148 bde.tus.w = le32_to_cpu(bpl[i].tus.w);
14149 if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64)
14150 max_response += bde.tus.f.bdeSize;
14154 max_response = wcqe->total_data_placed;
14157 if (max_response < wcqe->total_data_placed)
14158 pIocbIn->iocb.un.genreq64.bdl.bdeSize = max_response;
14160 pIocbIn->iocb.un.genreq64.bdl.bdeSize =
14161 wcqe->total_data_placed;
14164 /* Convert BG errors for completion status */
14165 if (status == CQE_STATUS_DI_ERROR) {
14166 pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
14168 if (bf_get(lpfc_wcqe_c_bg_edir, wcqe))
14169 pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED;
14171 pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED;
14173 pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0;
14174 if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */
14175 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
14176 BGS_GUARD_ERR_MASK;
14177 if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */
14178 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
14179 BGS_APPTAG_ERR_MASK;
14180 if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */
14181 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
14182 BGS_REFTAG_ERR_MASK;
14184 /* Check to see if there was any good data before the error */
14185 if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) {
14186 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
14187 BGS_HI_WATER_MARK_PRESENT_MASK;
14188 pIocbIn->iocb.unsli3.sli3_bg.bghm =
14189 wcqe->total_data_placed;
14193 * Set ALL the error bits to indicate we don't know what
14194 * type of error it is.
14196 if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat)
14197 pIocbIn->iocb.unsli3.sli3_bg.bgstat |=
14198 (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK |
14199 BGS_GUARD_ERR_MASK);
14202 /* Pick up HBA exchange busy condition */
14203 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
14204 spin_lock_irqsave(&phba->hbalock, iflags);
14205 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
14206 spin_unlock_irqrestore(&phba->hbalock, iflags);
14211 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
14212 * @phba: Pointer to HBA context object.
14213 * @irspiocbq: Pointer to work-queue completion queue entry.
14215 * This routine handles an ELS work-queue completion event and construct
14216 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
14217 * discovery engine to handle.
14219 * Return: Pointer to the receive IOCBQ, NULL otherwise.
14221 static struct lpfc_iocbq *
14222 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
14223 struct lpfc_iocbq *irspiocbq)
14225 struct lpfc_sli_ring *pring;
14226 struct lpfc_iocbq *cmdiocbq;
14227 struct lpfc_wcqe_complete *wcqe;
14228 unsigned long iflags;
14230 pring = lpfc_phba_elsring(phba);
14231 if (unlikely(!pring))
14234 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
14235 pring->stats.iocb_event++;
14236 /* Look up the ELS command IOCB and create pseudo response IOCB */
14237 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
14238 bf_get(lpfc_wcqe_c_request_tag, wcqe));
14239 if (unlikely(!cmdiocbq)) {
14240 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14241 "0386 ELS complete with no corresponding "
14242 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
14243 wcqe->word0, wcqe->total_data_placed,
14244 wcqe->parameter, wcqe->word3);
14245 lpfc_sli_release_iocbq(phba, irspiocbq);
14249 spin_lock_irqsave(&pring->ring_lock, iflags);
14250 /* Put the iocb back on the txcmplq */
14251 lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
14252 spin_unlock_irqrestore(&pring->ring_lock, iflags);
14254 /* Fake the irspiocbq and copy necessary response information */
14255 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
14260 inline struct lpfc_cq_event *
14261 lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
14263 struct lpfc_cq_event *cq_event;
14265 /* Allocate a new internal CQ_EVENT entry */
14266 cq_event = lpfc_sli4_cq_event_alloc(phba);
14268 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14269 "0602 Failed to alloc CQ_EVENT entry\n");
14273 /* Move the CQE into the event */
14274 memcpy(&cq_event->cqe, entry, size);
14279 * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event
14280 * @phba: Pointer to HBA context object.
14281 * @mcqe: Pointer to mailbox completion queue entry.
14283 * This routine process a mailbox completion queue entry with asynchronous
14286 * Return: true if work posted to worker thread, otherwise false.
14289 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
14291 struct lpfc_cq_event *cq_event;
14292 unsigned long iflags;
14294 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14295 "0392 Async Event: word0:x%x, word1:x%x, "
14296 "word2:x%x, word3:x%x\n", mcqe->word0,
14297 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
14299 cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
14303 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
14304 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
14305 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
14307 /* Set the async event flag */
14308 spin_lock_irqsave(&phba->hbalock, iflags);
14309 phba->hba_flag |= ASYNC_EVENT;
14310 spin_unlock_irqrestore(&phba->hbalock, iflags);
14316 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
14317 * @phba: Pointer to HBA context object.
14318 * @mcqe: Pointer to mailbox completion queue entry.
14320 * This routine process a mailbox completion queue entry with mailbox
14321 * completion event.
14323 * Return: true if work posted to worker thread, otherwise false.
14326 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
14328 uint32_t mcqe_status;
14329 MAILBOX_t *mbox, *pmbox;
14330 struct lpfc_mqe *mqe;
14331 struct lpfc_vport *vport;
14332 struct lpfc_nodelist *ndlp;
14333 struct lpfc_dmabuf *mp;
14334 unsigned long iflags;
14336 bool workposted = false;
14339 /* If not a mailbox complete MCQE, out by checking mailbox consume */
14340 if (!bf_get(lpfc_trailer_completed, mcqe))
14341 goto out_no_mqe_complete;
14343 /* Get the reference to the active mbox command */
14344 spin_lock_irqsave(&phba->hbalock, iflags);
14345 pmb = phba->sli.mbox_active;
14346 if (unlikely(!pmb)) {
14347 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14348 "1832 No pending MBOX command to handle\n");
14349 spin_unlock_irqrestore(&phba->hbalock, iflags);
14350 goto out_no_mqe_complete;
14352 spin_unlock_irqrestore(&phba->hbalock, iflags);
14354 pmbox = (MAILBOX_t *)&pmb->u.mqe;
14356 vport = pmb->vport;
14358 /* Reset heartbeat timer */
14359 phba->last_completion_time = jiffies;
14360 del_timer(&phba->sli.mbox_tmo);
14362 /* Move mbox data to caller's mailbox region, do endian swapping */
14363 if (pmb->mbox_cmpl && mbox)
14364 lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
14367 * For mcqe errors, conditionally move a modified error code to
14368 * the mbox so that the error will not be missed.
14370 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
14371 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
14372 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
14373 bf_set(lpfc_mqe_status, mqe,
14374 (LPFC_MBX_ERROR_RANGE | mcqe_status));
14376 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
14377 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
14378 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
14379 "MBOX dflt rpi: status:x%x rpi:x%x",
14381 pmbox->un.varWords[0], 0);
14382 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
14383 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
14384 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
14386 /* Reg_LOGIN of dflt RPI was successful. Mark the
14387 * node as having an UNREG_LOGIN in progress to stop
14388 * an unsolicited PLOGI from the same NPortId from
14389 * starting another mailbox transaction.
14391 spin_lock_irqsave(&ndlp->lock, iflags);
14392 ndlp->nlp_flag |= NLP_UNREG_INP;
14393 spin_unlock_irqrestore(&ndlp->lock, iflags);
14394 lpfc_unreg_login(phba, vport->vpi,
14395 pmbox->un.varWords[0], pmb);
14396 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
14399 /* No reference taken here. This is a default
14400 * RPI reg/immediate unreg cycle. The reference was
14401 * taken in the reg rpi path and is released when
14402 * this mailbox completes.
14404 pmb->ctx_ndlp = ndlp;
14405 pmb->vport = vport;
14406 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
14407 if (rc != MBX_BUSY)
14408 lpfc_printf_log(phba, KERN_ERR,
14411 "have been MBX_BUSY\n");
14412 if (rc != MBX_NOT_FINISHED)
14413 goto send_current_mbox;
14416 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
14417 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
14418 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
14420 /* Do NOT queue MBX_HEARTBEAT to the worker thread for processing. */
14421 if (pmbox->mbxCommand == MBX_HEARTBEAT) {
14422 spin_lock_irqsave(&phba->hbalock, iflags);
14423 /* Release the mailbox command posting token */
14424 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
14425 phba->sli.mbox_active = NULL;
14426 if (bf_get(lpfc_trailer_consumed, mcqe))
14427 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
14428 spin_unlock_irqrestore(&phba->hbalock, iflags);
14430 /* Post the next mbox command, if there is one */
14431 lpfc_sli4_post_async_mbox(phba);
14433 /* Process cmpl now */
14434 if (pmb->mbox_cmpl)
14435 pmb->mbox_cmpl(phba, pmb);
14439 /* There is mailbox completion work to queue to the worker thread */
14440 spin_lock_irqsave(&phba->hbalock, iflags);
14441 __lpfc_mbox_cmpl_put(phba, pmb);
14442 phba->work_ha |= HA_MBATT;
14443 spin_unlock_irqrestore(&phba->hbalock, iflags);
14447 spin_lock_irqsave(&phba->hbalock, iflags);
14448 /* Release the mailbox command posting token */
14449 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
14450 /* Setting active mailbox pointer need to be in sync to flag clear */
14451 phba->sli.mbox_active = NULL;
14452 if (bf_get(lpfc_trailer_consumed, mcqe))
14453 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
14454 spin_unlock_irqrestore(&phba->hbalock, iflags);
14455 /* Wake up worker thread to post the next pending mailbox command */
14456 lpfc_worker_wake_up(phba);
14459 out_no_mqe_complete:
14460 spin_lock_irqsave(&phba->hbalock, iflags);
14461 if (bf_get(lpfc_trailer_consumed, mcqe))
14462 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
14463 spin_unlock_irqrestore(&phba->hbalock, iflags);
14468 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
14469 * @phba: Pointer to HBA context object.
14470 * @cq: Pointer to associated CQ
14471 * @cqe: Pointer to mailbox completion queue entry.
14473 * This routine process a mailbox completion queue entry, it invokes the
14474 * proper mailbox complete handling or asynchronous event handling routine
14475 * according to the MCQE's async bit.
14477 * Return: true if work posted to worker thread, otherwise false.
14480 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14481 struct lpfc_cqe *cqe)
14483 struct lpfc_mcqe mcqe;
14488 /* Copy the mailbox MCQE and convert endian order as needed */
14489 lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
14491 /* Invoke the proper event handling routine */
14492 if (!bf_get(lpfc_trailer_async, &mcqe))
14493 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
14495 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
14500 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
14501 * @phba: Pointer to HBA context object.
14502 * @cq: Pointer to associated CQ
14503 * @wcqe: Pointer to work-queue completion queue entry.
14505 * This routine handles an ELS work-queue completion event.
14507 * Return: true if work posted to worker thread, otherwise false.
14510 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14511 struct lpfc_wcqe_complete *wcqe)
14513 struct lpfc_iocbq *irspiocbq;
14514 unsigned long iflags;
14515 struct lpfc_sli_ring *pring = cq->pring;
14517 int txcmplq_cnt = 0;
14519 /* Check for response status */
14520 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
14521 /* Log the error status */
14522 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14523 "0357 ELS CQE error: status=x%x: "
14524 "CQE: %08x %08x %08x %08x\n",
14525 bf_get(lpfc_wcqe_c_status, wcqe),
14526 wcqe->word0, wcqe->total_data_placed,
14527 wcqe->parameter, wcqe->word3);
14530 /* Get an irspiocbq for later ELS response processing use */
14531 irspiocbq = lpfc_sli_get_iocbq(phba);
14533 if (!list_empty(&pring->txq))
14535 if (!list_empty(&pring->txcmplq))
14537 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14538 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
14539 "els_txcmplq_cnt=%d\n",
14540 txq_cnt, phba->iocb_cnt,
14545 /* Save off the slow-path queue event for work thread to process */
14546 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
14547 spin_lock_irqsave(&phba->hbalock, iflags);
14548 list_add_tail(&irspiocbq->cq_event.list,
14549 &phba->sli4_hba.sp_queue_event);
14550 phba->hba_flag |= HBA_SP_QUEUE_EVT;
14551 spin_unlock_irqrestore(&phba->hbalock, iflags);
14557 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
14558 * @phba: Pointer to HBA context object.
14559 * @wcqe: Pointer to work-queue completion queue entry.
14561 * This routine handles slow-path WQ entry consumed event by invoking the
14562 * proper WQ release routine to the slow-path WQ.
14565 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
14566 struct lpfc_wcqe_release *wcqe)
14568 /* sanity check on queue memory */
14569 if (unlikely(!phba->sli4_hba.els_wq))
14571 /* Check for the slow-path ELS work queue */
14572 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
14573 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
14574 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
14576 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14577 "2579 Slow-path wqe consume event carries "
14578 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
14579 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
14580 phba->sli4_hba.els_wq->queue_id);
14584 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
14585 * @phba: Pointer to HBA context object.
14586 * @cq: Pointer to a WQ completion queue.
14587 * @wcqe: Pointer to work-queue completion queue entry.
14589 * This routine handles an XRI abort event.
14591 * Return: true if work posted to worker thread, otherwise false.
14594 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
14595 struct lpfc_queue *cq,
14596 struct sli4_wcqe_xri_aborted *wcqe)
14598 bool workposted = false;
14599 struct lpfc_cq_event *cq_event;
14600 unsigned long iflags;
14602 switch (cq->subtype) {
14604 lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
14605 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14606 /* Notify aborted XRI for NVME work queue */
14607 if (phba->nvmet_support)
14608 lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
14610 workposted = false;
14612 case LPFC_NVME_LS: /* NVME LS uses ELS resources */
14614 cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe));
14616 workposted = false;
14619 cq_event->hdwq = cq->hdwq;
14620 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
14622 list_add_tail(&cq_event->list,
14623 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
14624 /* Set the els xri abort event flag */
14625 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
14626 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
14631 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14632 "0603 Invalid CQ subtype %d: "
14633 "%08x %08x %08x %08x\n",
14634 cq->subtype, wcqe->word0, wcqe->parameter,
14635 wcqe->word2, wcqe->word3);
14636 workposted = false;
14642 #define FC_RCTL_MDS_DIAGS 0xF4
14645 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
14646 * @phba: Pointer to HBA context object.
14647 * @rcqe: Pointer to receive-queue completion queue entry.
14649 * This routine process a receive-queue completion queue entry.
14651 * Return: true if work posted to worker thread, otherwise false.
14654 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
14656 bool workposted = false;
14657 struct fc_frame_header *fc_hdr;
14658 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
14659 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
14660 struct lpfc_nvmet_tgtport *tgtp;
14661 struct hbq_dmabuf *dma_buf;
14662 uint32_t status, rq_id;
14663 unsigned long iflags;
14665 /* sanity check on queue memory */
14666 if (unlikely(!hrq) || unlikely(!drq))
14669 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
14670 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
14672 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
14673 if (rq_id != hrq->queue_id)
14676 status = bf_get(lpfc_rcqe_status, rcqe);
14678 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
14679 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14680 "2537 Receive Frame Truncated!!\n");
14682 case FC_STATUS_RQ_SUCCESS:
14683 spin_lock_irqsave(&phba->hbalock, iflags);
14684 lpfc_sli4_rq_release(hrq, drq);
14685 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
14687 hrq->RQ_no_buf_found++;
14688 spin_unlock_irqrestore(&phba->hbalock, iflags);
14692 hrq->RQ_buf_posted--;
14693 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
14695 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
14697 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
14698 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
14699 spin_unlock_irqrestore(&phba->hbalock, iflags);
14700 /* Handle MDS Loopback frames */
14701 if (!(phba->pport->load_flag & FC_UNLOADING))
14702 lpfc_sli4_handle_mds_loopback(phba->pport,
14705 lpfc_in_buf_free(phba, &dma_buf->dbuf);
14709 /* save off the frame for the work thread to process */
14710 list_add_tail(&dma_buf->cq_event.list,
14711 &phba->sli4_hba.sp_queue_event);
14712 /* Frame received */
14713 phba->hba_flag |= HBA_SP_QUEUE_EVT;
14714 spin_unlock_irqrestore(&phba->hbalock, iflags);
14717 case FC_STATUS_INSUFF_BUF_FRM_DISC:
14718 if (phba->nvmet_support) {
14719 tgtp = phba->targetport->private;
14720 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14721 "6402 RQE Error x%x, posted %d err_cnt "
14723 status, hrq->RQ_buf_posted,
14724 hrq->RQ_no_posted_buf,
14725 atomic_read(&tgtp->rcv_fcp_cmd_in),
14726 atomic_read(&tgtp->rcv_fcp_cmd_out),
14727 atomic_read(&tgtp->xmt_fcp_release));
14731 case FC_STATUS_INSUFF_BUF_NEED_BUF:
14732 hrq->RQ_no_posted_buf++;
14733 /* Post more buffers if possible */
14734 spin_lock_irqsave(&phba->hbalock, iflags);
14735 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
14736 spin_unlock_irqrestore(&phba->hbalock, iflags);
14745 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
14746 * @phba: Pointer to HBA context object.
14747 * @cq: Pointer to the completion queue.
14748 * @cqe: Pointer to a completion queue entry.
14750 * This routine process a slow-path work-queue or receive queue completion queue
14753 * Return: true if work posted to worker thread, otherwise false.
14756 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14757 struct lpfc_cqe *cqe)
14759 struct lpfc_cqe cqevt;
14760 bool workposted = false;
14762 /* Copy the work queue CQE and convert endian order if needed */
14763 lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
14765 /* Check and process for different type of WCQE and dispatch */
14766 switch (bf_get(lpfc_cqe_code, &cqevt)) {
14767 case CQE_CODE_COMPL_WQE:
14768 /* Process the WQ/RQ complete event */
14769 phba->last_completion_time = jiffies;
14770 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
14771 (struct lpfc_wcqe_complete *)&cqevt);
14773 case CQE_CODE_RELEASE_WQE:
14774 /* Process the WQ release event */
14775 lpfc_sli4_sp_handle_rel_wcqe(phba,
14776 (struct lpfc_wcqe_release *)&cqevt);
14778 case CQE_CODE_XRI_ABORTED:
14779 /* Process the WQ XRI abort event */
14780 phba->last_completion_time = jiffies;
14781 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
14782 (struct sli4_wcqe_xri_aborted *)&cqevt);
14784 case CQE_CODE_RECEIVE:
14785 case CQE_CODE_RECEIVE_V1:
14786 /* Process the RQ event */
14787 phba->last_completion_time = jiffies;
14788 workposted = lpfc_sli4_sp_handle_rcqe(phba,
14789 (struct lpfc_rcqe *)&cqevt);
14792 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14793 "0388 Not a valid WCQE code: x%x\n",
14794 bf_get(lpfc_cqe_code, &cqevt));
14801 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
14802 * @phba: Pointer to HBA context object.
14803 * @eqe: Pointer to fast-path event queue entry.
14804 * @speq: Pointer to slow-path event queue.
14806 * This routine process a event queue entry from the slow-path event queue.
14807 * It will check the MajorCode and MinorCode to determine this is for a
14808 * completion event on a completion queue, if not, an error shall be logged
14809 * and just return. Otherwise, it will get to the corresponding completion
14810 * queue and process all the entries on that completion queue, rearm the
14811 * completion queue, and then return.
14815 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
14816 struct lpfc_queue *speq)
14818 struct lpfc_queue *cq = NULL, *childq;
14822 /* Get the reference to the corresponding CQ */
14823 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
14825 list_for_each_entry(childq, &speq->child_list, list) {
14826 if (childq->queue_id == cqid) {
14831 if (unlikely(!cq)) {
14832 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
14833 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14834 "0365 Slow-path CQ identifier "
14835 "(%d) does not exist\n", cqid);
14839 /* Save EQ associated with this CQ */
14840 cq->assoc_qp = speq;
14842 if (is_kdump_kernel())
14843 ret = queue_work(phba->wq, &cq->spwork);
14845 ret = queue_work_on(cq->chann, phba->wq, &cq->spwork);
14848 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14849 "0390 Cannot schedule queue work "
14850 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
14851 cqid, cq->queue_id, raw_smp_processor_id());
14855 * __lpfc_sli4_process_cq - Process elements of a CQ
14856 * @phba: Pointer to HBA context object.
14857 * @cq: Pointer to CQ to be processed
14858 * @handler: Routine to process each cqe
14859 * @delay: Pointer to usdelay to set in case of rescheduling of the handler
14860 * @poll_mode: Polling mode we were called from
14862 * This routine processes completion queue entries in a CQ. While a valid
14863 * queue element is found, the handler is called. During processing checks
14864 * are made for periodic doorbell writes to let the hardware know of
14865 * element consumption.
14867 * If the max limit on cqes to process is hit, or there are no more valid
14868 * entries, the loop stops. If we processed a sufficient number of elements,
14869 * meaning there is sufficient load, rather than rearming and generating
14870 * another interrupt, a cq rescheduling delay will be set. A delay of 0
14871 * indicates no rescheduling.
14873 * Returns True if work scheduled, False otherwise.
14876 __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
14877 bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
14878 struct lpfc_cqe *), unsigned long *delay,
14879 enum lpfc_poll_mode poll_mode)
14881 struct lpfc_cqe *cqe;
14882 bool workposted = false;
14883 int count = 0, consumed = 0;
14886 /* default - no reschedule */
14889 if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
14890 goto rearm_and_exit;
14892 /* Process all the entries to the CQ */
14894 cqe = lpfc_sli4_cq_get(cq);
14896 workposted |= handler(phba, cq, cqe);
14897 __lpfc_sli4_consume_cqe(phba, cq, cqe);
14900 if (!(++count % cq->max_proc_limit))
14903 if (!(count % cq->notify_interval)) {
14904 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
14907 cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK;
14910 if (count == LPFC_NVMET_CQ_NOTIFY)
14911 cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
14913 cqe = lpfc_sli4_cq_get(cq);
14915 if (count >= phba->cfg_cq_poll_threshold) {
14920 /* Note: complete the irq_poll softirq before rearming CQ */
14921 if (poll_mode == LPFC_IRQ_POLL)
14922 irq_poll_complete(&cq->iop);
14924 /* Track the max number of CQEs processed in 1 EQ */
14925 if (count > cq->CQ_max_cqe)
14926 cq->CQ_max_cqe = count;
14928 cq->assoc_qp->EQ_cqe_cnt += count;
14930 /* Catch the no cq entry condition */
14931 if (unlikely(count == 0))
14932 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14933 "0369 No entry from completion queue "
14934 "qid=%d\n", cq->queue_id);
14936 xchg(&cq->queue_claimed, 0);
14939 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
14940 arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
14946 * __lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
14947 * @cq: pointer to CQ to process
14949 * This routine calls the cq processing routine with a handler specific
14950 * to the type of queue bound to it.
14952 * The CQ routine returns two values: the first is the calling status,
14953 * which indicates whether work was queued to the background discovery
14954 * thread. If true, the routine should wakeup the discovery thread;
14955 * the second is the delay parameter. If non-zero, rather than rearming
14956 * the CQ and yet another interrupt, the CQ handler should be queued so
14957 * that it is processed in a subsequent polling action. The value of
14958 * the delay indicates when to reschedule it.
14961 __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
14963 struct lpfc_hba *phba = cq->phba;
14964 unsigned long delay;
14965 bool workposted = false;
14968 /* Process and rearm the CQ */
14969 switch (cq->type) {
14971 workposted |= __lpfc_sli4_process_cq(phba, cq,
14972 lpfc_sli4_sp_handle_mcqe,
14973 &delay, LPFC_QUEUE_WORK);
14976 if (cq->subtype == LPFC_IO)
14977 workposted |= __lpfc_sli4_process_cq(phba, cq,
14978 lpfc_sli4_fp_handle_cqe,
14979 &delay, LPFC_QUEUE_WORK);
14981 workposted |= __lpfc_sli4_process_cq(phba, cq,
14982 lpfc_sli4_sp_handle_cqe,
14983 &delay, LPFC_QUEUE_WORK);
14986 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14987 "0370 Invalid completion queue type (%d)\n",
14993 if (is_kdump_kernel())
14994 ret = queue_delayed_work(phba->wq, &cq->sched_spwork,
14997 ret = queue_delayed_work_on(cq->chann, phba->wq,
14998 &cq->sched_spwork, delay);
15000 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15001 "0394 Cannot schedule queue work "
15002 "for cqid=%d on CPU %d\n",
15003 cq->queue_id, cq->chann);
15006 /* wake up worker thread if there are works to be done */
15008 lpfc_worker_wake_up(phba);
15012 * lpfc_sli4_sp_process_cq - slow-path work handler when started by
15014 * @work: pointer to work element
15016 * translates from the work handler and calls the slow-path handler.
15019 lpfc_sli4_sp_process_cq(struct work_struct *work)
15021 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
15023 __lpfc_sli4_sp_process_cq(cq);
15027 * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
15028 * @work: pointer to work element
15030 * translates from the work handler and calls the slow-path handler.
15033 lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
15035 struct lpfc_queue *cq = container_of(to_delayed_work(work),
15036 struct lpfc_queue, sched_spwork);
15038 __lpfc_sli4_sp_process_cq(cq);
15042 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
15043 * @phba: Pointer to HBA context object.
15044 * @cq: Pointer to associated CQ
15045 * @wcqe: Pointer to work-queue completion queue entry.
15047 * This routine process a fast-path work queue completion entry from fast-path
15048 * event queue for FCP command response completion.
15051 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15052 struct lpfc_wcqe_complete *wcqe)
15054 struct lpfc_sli_ring *pring = cq->pring;
15055 struct lpfc_iocbq *cmdiocbq;
15056 struct lpfc_iocbq irspiocbq;
15057 unsigned long iflags;
15059 /* Check for response status */
15060 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
15061 /* If resource errors reported from HBA, reduce queue
15062 * depth of the SCSI device.
15064 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
15065 IOSTAT_LOCAL_REJECT)) &&
15066 ((wcqe->parameter & IOERR_PARAM_MASK) ==
15067 IOERR_NO_RESOURCES))
15068 phba->lpfc_rampdown_queue_depth(phba);
15070 /* Log the cmpl status */
15071 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
15072 "0373 FCP CQE cmpl: status=x%x: "
15073 "CQE: %08x %08x %08x %08x\n",
15074 bf_get(lpfc_wcqe_c_status, wcqe),
15075 wcqe->word0, wcqe->total_data_placed,
15076 wcqe->parameter, wcqe->word3);
15079 /* Look up the FCP command IOCB and create pseudo response IOCB */
15080 spin_lock_irqsave(&pring->ring_lock, iflags);
15081 pring->stats.iocb_event++;
15082 spin_unlock_irqrestore(&pring->ring_lock, iflags);
15083 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
15084 bf_get(lpfc_wcqe_c_request_tag, wcqe));
15085 if (unlikely(!cmdiocbq)) {
15086 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15087 "0374 FCP complete with no corresponding "
15088 "cmdiocb: iotag (%d)\n",
15089 bf_get(lpfc_wcqe_c_request_tag, wcqe));
15092 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
15093 cmdiocbq->isr_timestamp = cq->isr_timestamp;
15095 if (cmdiocbq->iocb_cmpl == NULL) {
15096 if (cmdiocbq->wqe_cmpl) {
15097 /* For FCP the flag is cleared in wqe_cmpl */
15098 if (!(cmdiocbq->iocb_flag & LPFC_IO_FCP) &&
15099 cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
15100 spin_lock_irqsave(&phba->hbalock, iflags);
15101 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
15102 spin_unlock_irqrestore(&phba->hbalock, iflags);
15105 /* Pass the cmd_iocb and the wcqe to the upper layer */
15106 (cmdiocbq->wqe_cmpl)(phba, cmdiocbq, wcqe);
15109 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15110 "0375 FCP cmdiocb not callback function "
15112 bf_get(lpfc_wcqe_c_request_tag, wcqe));
15116 /* Only SLI4 non-IO commands stil use IOCB */
15117 /* Fake the irspiocb and copy necessary response information */
15118 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
15120 if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) {
15121 spin_lock_irqsave(&phba->hbalock, iflags);
15122 cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED;
15123 spin_unlock_irqrestore(&phba->hbalock, iflags);
15126 /* Pass the cmd_iocb and the rsp state to the upper layer */
15127 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
15131 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
15132 * @phba: Pointer to HBA context object.
15133 * @cq: Pointer to completion queue.
15134 * @wcqe: Pointer to work-queue completion queue entry.
15136 * This routine handles an fast-path WQ entry consumed event by invoking the
15137 * proper WQ release routine to the slow-path WQ.
15140 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15141 struct lpfc_wcqe_release *wcqe)
15143 struct lpfc_queue *childwq;
15144 bool wqid_matched = false;
15147 /* Check for fast-path FCP work queue release */
15148 hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
15149 list_for_each_entry(childwq, &cq->child_list, list) {
15150 if (childwq->queue_id == hba_wqid) {
15151 lpfc_sli4_wq_release(childwq,
15152 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
15153 if (childwq->q_flag & HBA_NVMET_WQFULL)
15154 lpfc_nvmet_wqfull_process(phba, childwq);
15155 wqid_matched = true;
15159 /* Report warning log message if no match found */
15160 if (wqid_matched != true)
15161 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15162 "2580 Fast-path wqe consume event carries "
15163 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
15167 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
15168 * @phba: Pointer to HBA context object.
15169 * @cq: Pointer to completion queue.
15170 * @rcqe: Pointer to receive-queue completion queue entry.
15172 * This routine process a receive-queue completion queue entry.
15174 * Return: true if work posted to worker thread, otherwise false.
15177 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15178 struct lpfc_rcqe *rcqe)
15180 bool workposted = false;
15181 struct lpfc_queue *hrq;
15182 struct lpfc_queue *drq;
15183 struct rqb_dmabuf *dma_buf;
15184 struct fc_frame_header *fc_hdr;
15185 struct lpfc_nvmet_tgtport *tgtp;
15186 uint32_t status, rq_id;
15187 unsigned long iflags;
15188 uint32_t fctl, idx;
15190 if ((phba->nvmet_support == 0) ||
15191 (phba->sli4_hba.nvmet_cqset == NULL))
15194 idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
15195 hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
15196 drq = phba->sli4_hba.nvmet_mrq_data[idx];
15198 /* sanity check on queue memory */
15199 if (unlikely(!hrq) || unlikely(!drq))
15202 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
15203 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
15205 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
15207 if ((phba->nvmet_support == 0) ||
15208 (rq_id != hrq->queue_id))
15211 status = bf_get(lpfc_rcqe_status, rcqe);
15213 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
15214 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15215 "6126 Receive Frame Truncated!!\n");
15217 case FC_STATUS_RQ_SUCCESS:
15218 spin_lock_irqsave(&phba->hbalock, iflags);
15219 lpfc_sli4_rq_release(hrq, drq);
15220 dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
15222 hrq->RQ_no_buf_found++;
15223 spin_unlock_irqrestore(&phba->hbalock, iflags);
15226 spin_unlock_irqrestore(&phba->hbalock, iflags);
15228 hrq->RQ_buf_posted--;
15229 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
15231 /* Just some basic sanity checks on FCP Command frame */
15232 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
15233 fc_hdr->fh_f_ctl[1] << 8 |
15234 fc_hdr->fh_f_ctl[2]);
15236 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
15237 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
15238 (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
15241 if (fc_hdr->fh_type == FC_TYPE_FCP) {
15242 dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
15243 lpfc_nvmet_unsol_fcp_event(
15244 phba, idx, dma_buf, cq->isr_timestamp,
15245 cq->q_flag & HBA_NVMET_CQ_NOTIFY);
15249 lpfc_rq_buf_free(phba, &dma_buf->hbuf);
15251 case FC_STATUS_INSUFF_BUF_FRM_DISC:
15252 if (phba->nvmet_support) {
15253 tgtp = phba->targetport->private;
15254 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15255 "6401 RQE Error x%x, posted %d err_cnt "
15257 status, hrq->RQ_buf_posted,
15258 hrq->RQ_no_posted_buf,
15259 atomic_read(&tgtp->rcv_fcp_cmd_in),
15260 atomic_read(&tgtp->rcv_fcp_cmd_out),
15261 atomic_read(&tgtp->xmt_fcp_release));
15265 case FC_STATUS_INSUFF_BUF_NEED_BUF:
15266 hrq->RQ_no_posted_buf++;
15267 /* Post more buffers if possible */
15275 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
15276 * @phba: adapter with cq
15277 * @cq: Pointer to the completion queue.
15278 * @cqe: Pointer to fast-path completion queue entry.
15280 * This routine process a fast-path work queue completion entry from fast-path
15281 * event queue for FCP command response completion.
15283 * Return: true if work posted to worker thread, otherwise false.
15286 lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15287 struct lpfc_cqe *cqe)
15289 struct lpfc_wcqe_release wcqe;
15290 bool workposted = false;
15292 /* Copy the work queue CQE and convert endian order if needed */
15293 lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
15295 /* Check and process for different type of WCQE and dispatch */
15296 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
15297 case CQE_CODE_COMPL_WQE:
15298 case CQE_CODE_NVME_ERSP:
15300 /* Process the WQ complete event */
15301 phba->last_completion_time = jiffies;
15302 if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
15303 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
15304 (struct lpfc_wcqe_complete *)&wcqe);
15306 case CQE_CODE_RELEASE_WQE:
15307 cq->CQ_release_wqe++;
15308 /* Process the WQ release event */
15309 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
15310 (struct lpfc_wcqe_release *)&wcqe);
15312 case CQE_CODE_XRI_ABORTED:
15313 cq->CQ_xri_aborted++;
15314 /* Process the WQ XRI abort event */
15315 phba->last_completion_time = jiffies;
15316 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
15317 (struct sli4_wcqe_xri_aborted *)&wcqe);
15319 case CQE_CODE_RECEIVE_V1:
15320 case CQE_CODE_RECEIVE:
15321 phba->last_completion_time = jiffies;
15322 if (cq->subtype == LPFC_NVMET) {
15323 workposted = lpfc_sli4_nvmet_handle_rcqe(
15324 phba, cq, (struct lpfc_rcqe *)&wcqe);
15328 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15329 "0144 Not a valid CQE code: x%x\n",
15330 bf_get(lpfc_wcqe_c_code, &wcqe));
15337 * lpfc_sli4_sched_cq_work - Schedules cq work
15338 * @phba: Pointer to HBA context object.
15339 * @cq: Pointer to CQ
15342 * This routine checks the poll mode of the CQ corresponding to
15343 * cq->chann, then either schedules a softirq or queue_work to complete
15346 * queue_work path is taken if in NVMET mode, or if poll_mode is in
15347 * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken.
15350 static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba,
15351 struct lpfc_queue *cq, uint16_t cqid)
15355 switch (cq->poll_mode) {
15356 case LPFC_IRQ_POLL:
15357 /* CGN mgmt is mutually exclusive from softirq processing */
15358 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
15359 irq_poll_sched(&cq->iop);
15363 case LPFC_QUEUE_WORK:
15365 if (is_kdump_kernel())
15366 ret = queue_work(phba->wq, &cq->irqwork);
15368 ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork);
15370 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15371 "0383 Cannot schedule queue work "
15372 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
15373 cqid, cq->queue_id,
15374 raw_smp_processor_id());
15379 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
15380 * @phba: Pointer to HBA context object.
15381 * @eq: Pointer to the queue structure.
15382 * @eqe: Pointer to fast-path event queue entry.
15384 * This routine process a event queue entry from the fast-path event queue.
15385 * It will check the MajorCode and MinorCode to determine this is for a
15386 * completion event on a completion queue, if not, an error shall be logged
15387 * and just return. Otherwise, it will get to the corresponding completion
15388 * queue and process all the entries on the completion queue, rearm the
15389 * completion queue, and then return.
15392 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
15393 struct lpfc_eqe *eqe)
15395 struct lpfc_queue *cq = NULL;
15396 uint32_t qidx = eq->hdwq;
15399 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
15400 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15401 "0366 Not a valid completion "
15402 "event: majorcode=x%x, minorcode=x%x\n",
15403 bf_get_le32(lpfc_eqe_major_code, eqe),
15404 bf_get_le32(lpfc_eqe_minor_code, eqe));
15408 /* Get the reference to the corresponding CQ */
15409 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
15411 /* Use the fast lookup method first */
15412 if (cqid <= phba->sli4_hba.cq_max) {
15413 cq = phba->sli4_hba.cq_lookup[cqid];
15418 /* Next check for NVMET completion */
15419 if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
15420 id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
15421 if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
15422 /* Process NVMET unsol rcv */
15423 cq = phba->sli4_hba.nvmet_cqset[cqid - id];
15428 if (phba->sli4_hba.nvmels_cq &&
15429 (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
15430 /* Process NVME unsol rcv */
15431 cq = phba->sli4_hba.nvmels_cq;
15434 /* Otherwise this is a Slow path event */
15436 lpfc_sli4_sp_handle_eqe(phba, eqe,
15437 phba->sli4_hba.hdwq[qidx].hba_eq);
15442 if (unlikely(cqid != cq->queue_id)) {
15443 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15444 "0368 Miss-matched fast-path completion "
15445 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
15446 cqid, cq->queue_id);
15451 #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
15452 if (phba->ktime_on)
15453 cq->isr_timestamp = ktime_get_ns();
15455 cq->isr_timestamp = 0;
15457 lpfc_sli4_sched_cq_work(phba, cq, cqid);
15461 * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
15462 * @cq: Pointer to CQ to be processed
15463 * @poll_mode: Enum lpfc_poll_state to determine poll mode
15465 * This routine calls the cq processing routine with the handler for
15468 * The CQ routine returns two values: the first is the calling status,
15469 * which indicates whether work was queued to the background discovery
15470 * thread. If true, the routine should wakeup the discovery thread;
15471 * the second is the delay parameter. If non-zero, rather than rearming
15472 * the CQ and yet another interrupt, the CQ handler should be queued so
15473 * that it is processed in a subsequent polling action. The value of
15474 * the delay indicates when to reschedule it.
15477 __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq,
15478 enum lpfc_poll_mode poll_mode)
15480 struct lpfc_hba *phba = cq->phba;
15481 unsigned long delay;
15482 bool workposted = false;
15485 /* process and rearm the CQ */
15486 workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
15487 &delay, poll_mode);
15490 if (is_kdump_kernel())
15491 ret = queue_delayed_work(phba->wq, &cq->sched_irqwork,
15494 ret = queue_delayed_work_on(cq->chann, phba->wq,
15495 &cq->sched_irqwork, delay);
15497 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15498 "0367 Cannot schedule queue work "
15499 "for cqid=%d on CPU %d\n",
15500 cq->queue_id, cq->chann);
15503 /* wake up worker thread if there are works to be done */
15505 lpfc_worker_wake_up(phba);
15509 * lpfc_sli4_hba_process_cq - fast-path work handler when started by
15511 * @work: pointer to work element
15513 * translates from the work handler and calls the fast-path handler.
15516 lpfc_sli4_hba_process_cq(struct work_struct *work)
15518 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
15520 __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
15524 * lpfc_sli4_dly_hba_process_cq - fast-path work handler when started by timer
15525 * @work: pointer to work element
15527 * translates from the work handler and calls the fast-path handler.
15530 lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
15532 struct lpfc_queue *cq = container_of(to_delayed_work(work),
15533 struct lpfc_queue, sched_irqwork);
15535 __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
15539 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
15540 * @irq: Interrupt number.
15541 * @dev_id: The device context pointer.
15543 * This function is directly called from the PCI layer as an interrupt
15544 * service routine when device with SLI-4 interface spec is enabled with
15545 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
15546 * ring event in the HBA. However, when the device is enabled with either
15547 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
15548 * device-level interrupt handler. When the PCI slot is in error recovery
15549 * or the HBA is undergoing initialization, the interrupt handler will not
15550 * process the interrupt. The SCSI FCP fast-path ring event are handled in
15551 * the intrrupt context. This function is called without any lock held.
15552 * It gets the hbalock to access and update SLI data structures. Note that,
15553 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
15554 * equal to that of FCP CQ index.
15556 * The link attention and ELS ring attention events are handled
15557 * by the worker thread. The interrupt handler signals the worker thread
15558 * and returns for these events. This function is called without any lock
15559 * held. It gets the hbalock to access and update SLI data structures.
15561 * This function returns IRQ_HANDLED when interrupt is handled else it
15562 * returns IRQ_NONE.
15565 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
15567 struct lpfc_hba *phba;
15568 struct lpfc_hba_eq_hdl *hba_eq_hdl;
15569 struct lpfc_queue *fpeq;
15570 unsigned long iflag;
15573 struct lpfc_eq_intr_info *eqi;
15575 /* Get the driver's phba structure from the dev_id */
15576 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
15577 phba = hba_eq_hdl->phba;
15578 hba_eqidx = hba_eq_hdl->idx;
15580 if (unlikely(!phba))
15582 if (unlikely(!phba->sli4_hba.hdwq))
15585 /* Get to the EQ struct associated with this vector */
15586 fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
15587 if (unlikely(!fpeq))
15590 /* Check device state for handling interrupt */
15591 if (unlikely(lpfc_intr_state_check(phba))) {
15592 /* Check again for link_state with lock held */
15593 spin_lock_irqsave(&phba->hbalock, iflag);
15594 if (phba->link_state < LPFC_LINK_DOWN)
15595 /* Flush, clear interrupt, and rearm the EQ */
15596 lpfc_sli4_eqcq_flush(phba, fpeq);
15597 spin_unlock_irqrestore(&phba->hbalock, iflag);
15601 eqi = this_cpu_ptr(phba->sli4_hba.eq_info);
15604 fpeq->last_cpu = raw_smp_processor_id();
15606 if (eqi->icnt > LPFC_EQD_ISR_TRIGGER &&
15607 fpeq->q_flag & HBA_EQ_DELAY_CHK &&
15608 phba->cfg_auto_imax &&
15609 fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
15610 phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
15611 lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
15613 /* process and rearm the EQ */
15614 ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
15616 if (unlikely(ecount == 0)) {
15617 fpeq->EQ_no_entry++;
15618 if (phba->intr_type == MSIX)
15619 /* MSI-X treated interrupt served as no EQ share INT */
15620 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15621 "0358 MSI-X interrupt with no EQE\n");
15623 /* Non MSI-X treated on interrupt as EQ share INT */
15627 return IRQ_HANDLED;
15628 } /* lpfc_sli4_hba_intr_handler */
15631 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
15632 * @irq: Interrupt number.
15633 * @dev_id: The device context pointer.
15635 * This function is the device-level interrupt handler to device with SLI-4
15636 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
15637 * interrupt mode is enabled and there is an event in the HBA which requires
15638 * driver attention. This function invokes the slow-path interrupt attention
15639 * handling function and fast-path interrupt attention handling function in
15640 * turn to process the relevant HBA attention events. This function is called
15641 * without any lock held. It gets the hbalock to access and update SLI data
15644 * This function returns IRQ_HANDLED when interrupt is handled, else it
15645 * returns IRQ_NONE.
15648 lpfc_sli4_intr_handler(int irq, void *dev_id)
15650 struct lpfc_hba *phba;
15651 irqreturn_t hba_irq_rc;
15652 bool hba_handled = false;
15655 /* Get the driver's phba structure from the dev_id */
15656 phba = (struct lpfc_hba *)dev_id;
15658 if (unlikely(!phba))
15662 * Invoke fast-path host attention interrupt handling as appropriate.
15664 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
15665 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
15666 &phba->sli4_hba.hba_eq_hdl[qidx]);
15667 if (hba_irq_rc == IRQ_HANDLED)
15668 hba_handled |= true;
15671 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
15672 } /* lpfc_sli4_intr_handler */
15674 void lpfc_sli4_poll_hbtimer(struct timer_list *t)
15676 struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer);
15677 struct lpfc_queue *eq;
15682 list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list)
15683 i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH);
15684 if (!list_empty(&phba->poll_list))
15685 mod_timer(&phba->cpuhp_poll_timer,
15686 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
15691 inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path)
15693 struct lpfc_hba *phba = eq->phba;
15697 * Unlocking an irq is one of the entry point to check
15698 * for re-schedule, but we are good for io submission
15699 * path as midlayer does a get_cpu to glue us in. Flush
15700 * out the invalidate queue so we can see the updated
15705 if (READ_ONCE(eq->mode) == LPFC_EQ_POLL)
15706 /* We will not likely get the completion for the caller
15707 * during this iteration but i guess that's fine.
15708 * Future io's coming on this eq should be able to
15709 * pick it up. As for the case of single io's, they
15710 * will be handled through a sched from polling timer
15711 * function which is currently triggered every 1msec.
15713 i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM);
15718 static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq)
15720 struct lpfc_hba *phba = eq->phba;
15722 /* kickstart slowpath processing if needed */
15723 if (list_empty(&phba->poll_list))
15724 mod_timer(&phba->cpuhp_poll_timer,
15725 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
15727 list_add_rcu(&eq->_poll_list, &phba->poll_list);
15731 static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq)
15733 struct lpfc_hba *phba = eq->phba;
15735 /* Disable slowpath processing for this eq. Kick start the eq
15736 * by RE-ARMING the eq's ASAP
15738 list_del_rcu(&eq->_poll_list);
15741 if (list_empty(&phba->poll_list))
15742 del_timer_sync(&phba->cpuhp_poll_timer);
15745 void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba)
15747 struct lpfc_queue *eq, *next;
15749 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list)
15750 list_del(&eq->_poll_list);
15752 INIT_LIST_HEAD(&phba->poll_list);
15757 __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode)
15759 if (mode == eq->mode)
15762 * currently this function is only called during a hotplug
15763 * event and the cpu on which this function is executing
15764 * is going offline. By now the hotplug has instructed
15765 * the scheduler to remove this cpu from cpu active mask.
15766 * So we don't need to work about being put aside by the
15767 * scheduler for a high priority process. Yes, the inte-
15768 * rrupts could come but they are known to retire ASAP.
15771 /* Disable polling in the fastpath */
15772 WRITE_ONCE(eq->mode, mode);
15773 /* flush out the store buffer */
15777 * Add this eq to the polling list and start polling. For
15778 * a grace period both interrupt handler and poller will
15779 * try to process the eq _but_ that's fine. We have a
15780 * synchronization mechanism in place (queue_claimed) to
15781 * deal with it. This is just a draining phase for int-
15782 * errupt handler (not eq's) as we have guranteed through
15783 * barrier that all the CPUs have seen the new CQ_POLLED
15784 * state. which will effectively disable the REARMING of
15785 * the EQ. The whole idea is eq's die off eventually as
15786 * we are not rearming EQ's anymore.
15788 mode ? lpfc_sli4_add_to_poll_list(eq) :
15789 lpfc_sli4_remove_from_poll_list(eq);
15792 void lpfc_sli4_start_polling(struct lpfc_queue *eq)
15794 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL);
15797 void lpfc_sli4_stop_polling(struct lpfc_queue *eq)
15799 struct lpfc_hba *phba = eq->phba;
15801 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT);
15803 /* Kick start for the pending io's in h/w.
15804 * Once we switch back to interrupt processing on a eq
15805 * the io path completion will only arm eq's when it
15806 * receives a completion. But since eq's are in disa-
15807 * rmed state it doesn't receive a completion. This
15808 * creates a deadlock scenaro.
15810 phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM);
15814 * lpfc_sli4_queue_free - free a queue structure and associated memory
15815 * @queue: The queue structure to free.
15817 * This function frees a queue structure and the DMAable memory used for
15818 * the host resident queue. This function must be called after destroying the
15819 * queue on the HBA.
15822 lpfc_sli4_queue_free(struct lpfc_queue *queue)
15824 struct lpfc_dmabuf *dmabuf;
15829 if (!list_empty(&queue->wq_list))
15830 list_del(&queue->wq_list);
15832 while (!list_empty(&queue->page_list)) {
15833 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
15835 dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
15836 dmabuf->virt, dmabuf->phys);
15840 lpfc_free_rq_buffer(queue->phba, queue);
15841 kfree(queue->rqbp);
15844 if (!list_empty(&queue->cpu_list))
15845 list_del(&queue->cpu_list);
15852 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
15853 * @phba: The HBA that this queue is being created on.
15854 * @page_size: The size of a queue page
15855 * @entry_size: The size of each queue entry for this queue.
15856 * @entry_count: The number of entries that this queue will handle.
15857 * @cpu: The cpu that will primarily utilize this queue.
15859 * This function allocates a queue structure and the DMAable memory used for
15860 * the host resident queue. This function must be called before creating the
15861 * queue on the HBA.
15863 struct lpfc_queue *
15864 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
15865 uint32_t entry_size, uint32_t entry_count, int cpu)
15867 struct lpfc_queue *queue;
15868 struct lpfc_dmabuf *dmabuf;
15869 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15872 if (!phba->sli4_hba.pc_sli4_params.supported)
15873 hw_page_size = page_size;
15875 pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
15877 /* If needed, Adjust page count to match the max the adapter supports */
15878 if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
15879 pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
15881 queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
15882 GFP_KERNEL, cpu_to_node(cpu));
15886 INIT_LIST_HEAD(&queue->list);
15887 INIT_LIST_HEAD(&queue->_poll_list);
15888 INIT_LIST_HEAD(&queue->wq_list);
15889 INIT_LIST_HEAD(&queue->wqfull_list);
15890 INIT_LIST_HEAD(&queue->page_list);
15891 INIT_LIST_HEAD(&queue->child_list);
15892 INIT_LIST_HEAD(&queue->cpu_list);
15894 /* Set queue parameters now. If the system cannot provide memory
15895 * resources, the free routine needs to know what was allocated.
15897 queue->page_count = pgcnt;
15898 queue->q_pgs = (void **)&queue[1];
15899 queue->entry_cnt_per_pg = hw_page_size / entry_size;
15900 queue->entry_size = entry_size;
15901 queue->entry_count = entry_count;
15902 queue->page_size = hw_page_size;
15903 queue->phba = phba;
15905 for (x = 0; x < queue->page_count; x++) {
15906 dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
15907 dev_to_node(&phba->pcidev->dev));
15910 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
15911 hw_page_size, &dmabuf->phys,
15913 if (!dmabuf->virt) {
15917 dmabuf->buffer_tag = x;
15918 list_add_tail(&dmabuf->list, &queue->page_list);
15919 /* use lpfc_sli4_qe to index a paritcular entry in this page */
15920 queue->q_pgs[x] = dmabuf->virt;
15922 INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
15923 INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
15924 INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
15925 INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
15927 /* notify_interval will be set during q creation */
15931 lpfc_sli4_queue_free(queue);
15936 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
15937 * @phba: HBA structure that indicates port to create a queue on.
15938 * @pci_barset: PCI BAR set flag.
15940 * This function shall perform iomap of the specified PCI BAR address to host
15941 * memory address if not already done so and return it. The returned host
15942 * memory address can be NULL.
15944 static void __iomem *
15945 lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
15950 switch (pci_barset) {
15951 case WQ_PCI_BAR_0_AND_1:
15952 return phba->pci_bar0_memmap_p;
15953 case WQ_PCI_BAR_2_AND_3:
15954 return phba->pci_bar2_memmap_p;
15955 case WQ_PCI_BAR_4_AND_5:
15956 return phba->pci_bar4_memmap_p;
15964 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
15965 * @phba: HBA structure that EQs are on.
15966 * @startq: The starting EQ index to modify
15967 * @numq: The number of EQs (consecutive indexes) to modify
15968 * @usdelay: amount of delay
15970 * This function revises the EQ delay on 1 or more EQs. The EQ delay
15971 * is set either by writing to a register (if supported by the SLI Port)
15972 * or by mailbox command. The mailbox command allows several EQs to be
15975 * The @phba struct is used to send a mailbox command to HBA. The @startq
15976 * is used to get the starting EQ index to change. The @numq value is
15977 * used to specify how many consecutive EQ indexes, starting at EQ index,
15978 * are to be changed. This function is asynchronous and will wait for any
15979 * mailbox commands to finish before returning.
15981 * On success this function will return a zero. If unable to allocate
15982 * enough memory this function will return -ENOMEM. If a mailbox command
15983 * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
15984 * have had their delay multipler changed.
15987 lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
15988 uint32_t numq, uint32_t usdelay)
15990 struct lpfc_mbx_modify_eq_delay *eq_delay;
15991 LPFC_MBOXQ_t *mbox;
15992 struct lpfc_queue *eq;
15993 int cnt = 0, rc, length;
15994 uint32_t shdr_status, shdr_add_status;
15997 union lpfc_sli4_cfg_shdr *shdr;
15999 if (startq >= phba->cfg_irq_chann)
16002 if (usdelay > 0xFFFF) {
16003 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
16004 "6429 usdelay %d too large. Scaled down to "
16005 "0xFFFF.\n", usdelay);
16009 /* set values by EQ_DELAY register if supported */
16010 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
16011 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
16012 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
16016 lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
16024 /* Otherwise, set values by mailbox cmd */
16026 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16028 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16029 "6428 Failed allocating mailbox cmd buffer."
16030 " EQ delay was not set.\n");
16033 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
16034 sizeof(struct lpfc_sli4_cfg_mhdr));
16035 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16036 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
16037 length, LPFC_SLI4_MBX_EMBED);
16038 eq_delay = &mbox->u.mqe.un.eq_delay;
16040 /* Calculate delay multiper from maximum interrupt per second */
16041 dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
16044 if (dmult > LPFC_DMULT_MAX)
16045 dmult = LPFC_DMULT_MAX;
16047 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
16048 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
16051 eq->q_mode = usdelay;
16052 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
16053 eq_delay->u.request.eq[cnt].phase = 0;
16054 eq_delay->u.request.eq[cnt].delay_multi = dmult;
16059 eq_delay->u.request.num_eq = cnt;
16061 mbox->vport = phba->pport;
16062 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16063 mbox->ctx_buf = NULL;
16064 mbox->ctx_ndlp = NULL;
16065 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16066 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
16067 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16068 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16069 if (shdr_status || shdr_add_status || rc) {
16070 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16071 "2512 MODIFY_EQ_DELAY mailbox failed with "
16072 "status x%x add_status x%x, mbx status x%x\n",
16073 shdr_status, shdr_add_status, rc);
16075 mempool_free(mbox, phba->mbox_mem_pool);
16080 * lpfc_eq_create - Create an Event Queue on the HBA
16081 * @phba: HBA structure that indicates port to create a queue on.
16082 * @eq: The queue structure to use to create the event queue.
16083 * @imax: The maximum interrupt per second limit.
16085 * This function creates an event queue, as detailed in @eq, on a port,
16086 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
16088 * The @phba struct is used to send mailbox command to HBA. The @eq struct
16089 * is used to get the entry count and entry size that are necessary to
16090 * determine the number of pages to allocate and use for this queue. This
16091 * function will send the EQ_CREATE mailbox command to the HBA to setup the
16092 * event queue. This function is asynchronous and will wait for the mailbox
16093 * command to finish before continuing.
16095 * On success this function will return a zero. If unable to allocate enough
16096 * memory this function will return -ENOMEM. If the queue create mailbox command
16097 * fails this function will return -ENXIO.
16100 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
16102 struct lpfc_mbx_eq_create *eq_create;
16103 LPFC_MBOXQ_t *mbox;
16104 int rc, length, status = 0;
16105 struct lpfc_dmabuf *dmabuf;
16106 uint32_t shdr_status, shdr_add_status;
16107 union lpfc_sli4_cfg_shdr *shdr;
16109 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16111 /* sanity check on queue memory */
16114 if (!phba->sli4_hba.pc_sli4_params.supported)
16115 hw_page_size = SLI4_PAGE_SIZE;
16117 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16120 length = (sizeof(struct lpfc_mbx_eq_create) -
16121 sizeof(struct lpfc_sli4_cfg_mhdr));
16122 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16123 LPFC_MBOX_OPCODE_EQ_CREATE,
16124 length, LPFC_SLI4_MBX_EMBED);
16125 eq_create = &mbox->u.mqe.un.eq_create;
16126 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
16127 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
16129 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
16131 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
16133 /* Use version 2 of CREATE_EQ if eqav is set */
16134 if (phba->sli4_hba.pc_sli4_params.eqav) {
16135 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16136 LPFC_Q_CREATE_VERSION_2);
16137 bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
16138 phba->sli4_hba.pc_sli4_params.eqav);
16141 /* don't setup delay multiplier using EQ_CREATE */
16143 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
16145 switch (eq->entry_count) {
16147 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16148 "0360 Unsupported EQ count. (%d)\n",
16150 if (eq->entry_count < 256) {
16154 fallthrough; /* otherwise default to smallest count */
16156 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16160 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16164 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16168 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16172 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16176 list_for_each_entry(dmabuf, &eq->page_list, list) {
16177 memset(dmabuf->virt, 0, hw_page_size);
16178 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16179 putPaddrLow(dmabuf->phys);
16180 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16181 putPaddrHigh(dmabuf->phys);
16183 mbox->vport = phba->pport;
16184 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16185 mbox->ctx_buf = NULL;
16186 mbox->ctx_ndlp = NULL;
16187 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16188 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16189 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16190 if (shdr_status || shdr_add_status || rc) {
16191 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16192 "2500 EQ_CREATE mailbox failed with "
16193 "status x%x add_status x%x, mbx status x%x\n",
16194 shdr_status, shdr_add_status, rc);
16197 eq->type = LPFC_EQ;
16198 eq->subtype = LPFC_NONE;
16199 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
16200 if (eq->queue_id == 0xFFFF)
16202 eq->host_index = 0;
16203 eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
16204 eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
16206 mempool_free(mbox, phba->mbox_mem_pool);
16210 static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget)
16212 struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop);
16214 __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL);
16220 * lpfc_cq_create - Create a Completion Queue on the HBA
16221 * @phba: HBA structure that indicates port to create a queue on.
16222 * @cq: The queue structure to use to create the completion queue.
16223 * @eq: The event queue to bind this completion queue to.
16224 * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
16225 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
16227 * This function creates a completion queue, as detailed in @wq, on a port,
16228 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
16230 * The @phba struct is used to send mailbox command to HBA. The @cq struct
16231 * is used to get the entry count and entry size that are necessary to
16232 * determine the number of pages to allocate and use for this queue. The @eq
16233 * is used to indicate which event queue to bind this completion queue to. This
16234 * function will send the CQ_CREATE mailbox command to the HBA to setup the
16235 * completion queue. This function is asynchronous and will wait for the mailbox
16236 * command to finish before continuing.
16238 * On success this function will return a zero. If unable to allocate enough
16239 * memory this function will return -ENOMEM. If the queue create mailbox command
16240 * fails this function will return -ENXIO.
16243 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
16244 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
16246 struct lpfc_mbx_cq_create *cq_create;
16247 struct lpfc_dmabuf *dmabuf;
16248 LPFC_MBOXQ_t *mbox;
16249 int rc, length, status = 0;
16250 uint32_t shdr_status, shdr_add_status;
16251 union lpfc_sli4_cfg_shdr *shdr;
16253 /* sanity check on queue memory */
16257 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16260 length = (sizeof(struct lpfc_mbx_cq_create) -
16261 sizeof(struct lpfc_sli4_cfg_mhdr));
16262 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16263 LPFC_MBOX_OPCODE_CQ_CREATE,
16264 length, LPFC_SLI4_MBX_EMBED);
16265 cq_create = &mbox->u.mqe.un.cq_create;
16266 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
16267 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
16269 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
16270 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
16271 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16272 phba->sli4_hba.pc_sli4_params.cqv);
16273 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
16274 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
16275 (cq->page_size / SLI4_PAGE_SIZE));
16276 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
16278 bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
16279 phba->sli4_hba.pc_sli4_params.cqav);
16281 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
16284 switch (cq->entry_count) {
16287 if (phba->sli4_hba.pc_sli4_params.cqv ==
16288 LPFC_Q_CREATE_VERSION_2) {
16289 cq_create->u.request.context.lpfc_cq_context_count =
16291 bf_set(lpfc_cq_context_count,
16292 &cq_create->u.request.context,
16293 LPFC_CQ_CNT_WORD7);
16298 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16299 "0361 Unsupported CQ count: "
16300 "entry cnt %d sz %d pg cnt %d\n",
16301 cq->entry_count, cq->entry_size,
16303 if (cq->entry_count < 256) {
16307 fallthrough; /* otherwise default to smallest count */
16309 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
16313 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
16317 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
16321 list_for_each_entry(dmabuf, &cq->page_list, list) {
16322 memset(dmabuf->virt, 0, cq->page_size);
16323 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16324 putPaddrLow(dmabuf->phys);
16325 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16326 putPaddrHigh(dmabuf->phys);
16328 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16330 /* The IOCTL status is embedded in the mailbox subheader. */
16331 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16332 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16333 if (shdr_status || shdr_add_status || rc) {
16334 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16335 "2501 CQ_CREATE mailbox failed with "
16336 "status x%x add_status x%x, mbx status x%x\n",
16337 shdr_status, shdr_add_status, rc);
16341 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
16342 if (cq->queue_id == 0xFFFF) {
16346 /* link the cq onto the parent eq child list */
16347 list_add_tail(&cq->list, &eq->child_list);
16348 /* Set up completion queue's type and subtype */
16350 cq->subtype = subtype;
16351 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
16352 cq->assoc_qid = eq->queue_id;
16354 cq->host_index = 0;
16355 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
16356 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
16358 if (cq->queue_id > phba->sli4_hba.cq_max)
16359 phba->sli4_hba.cq_max = cq->queue_id;
16361 irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler);
16363 mempool_free(mbox, phba->mbox_mem_pool);
16368 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
16369 * @phba: HBA structure that indicates port to create a queue on.
16370 * @cqp: The queue structure array to use to create the completion queues.
16371 * @hdwq: The hardware queue array with the EQ to bind completion queues to.
16372 * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
16373 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
16375 * This function creates a set of completion queue, s to support MRQ
16376 * as detailed in @cqp, on a port,
16377 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
16379 * The @phba struct is used to send mailbox command to HBA. The @cq struct
16380 * is used to get the entry count and entry size that are necessary to
16381 * determine the number of pages to allocate and use for this queue. The @eq
16382 * is used to indicate which event queue to bind this completion queue to. This
16383 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
16384 * completion queue. This function is asynchronous and will wait for the mailbox
16385 * command to finish before continuing.
16387 * On success this function will return a zero. If unable to allocate enough
16388 * memory this function will return -ENOMEM. If the queue create mailbox command
16389 * fails this function will return -ENXIO.
16392 lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
16393 struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
16396 struct lpfc_queue *cq;
16397 struct lpfc_queue *eq;
16398 struct lpfc_mbx_cq_create_set *cq_set;
16399 struct lpfc_dmabuf *dmabuf;
16400 LPFC_MBOXQ_t *mbox;
16401 int rc, length, alloclen, status = 0;
16402 int cnt, idx, numcq, page_idx = 0;
16403 uint32_t shdr_status, shdr_add_status;
16404 union lpfc_sli4_cfg_shdr *shdr;
16405 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16407 /* sanity check on queue memory */
16408 numcq = phba->cfg_nvmet_mrq;
16409 if (!cqp || !hdwq || !numcq)
16412 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16416 length = sizeof(struct lpfc_mbx_cq_create_set);
16417 length += ((numcq * cqp[0]->page_count) *
16418 sizeof(struct dma_address));
16419 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16420 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
16421 LPFC_SLI4_MBX_NEMBED);
16422 if (alloclen < length) {
16423 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16424 "3098 Allocated DMA memory size (%d) is "
16425 "less than the requested DMA memory size "
16426 "(%d)\n", alloclen, length);
16430 cq_set = mbox->sge_array->addr[0];
16431 shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
16432 bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
16434 for (idx = 0; idx < numcq; idx++) {
16436 eq = hdwq[idx].hba_eq;
16441 if (!phba->sli4_hba.pc_sli4_params.supported)
16442 hw_page_size = cq->page_size;
16446 bf_set(lpfc_mbx_cq_create_set_page_size,
16447 &cq_set->u.request,
16448 (hw_page_size / SLI4_PAGE_SIZE));
16449 bf_set(lpfc_mbx_cq_create_set_num_pages,
16450 &cq_set->u.request, cq->page_count);
16451 bf_set(lpfc_mbx_cq_create_set_evt,
16452 &cq_set->u.request, 1);
16453 bf_set(lpfc_mbx_cq_create_set_valid,
16454 &cq_set->u.request, 1);
16455 bf_set(lpfc_mbx_cq_create_set_cqe_size,
16456 &cq_set->u.request, 0);
16457 bf_set(lpfc_mbx_cq_create_set_num_cq,
16458 &cq_set->u.request, numcq);
16459 bf_set(lpfc_mbx_cq_create_set_autovalid,
16460 &cq_set->u.request,
16461 phba->sli4_hba.pc_sli4_params.cqav);
16462 switch (cq->entry_count) {
16465 if (phba->sli4_hba.pc_sli4_params.cqv ==
16466 LPFC_Q_CREATE_VERSION_2) {
16467 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16468 &cq_set->u.request,
16470 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16471 &cq_set->u.request,
16472 LPFC_CQ_CNT_WORD7);
16477 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16478 "3118 Bad CQ count. (%d)\n",
16480 if (cq->entry_count < 256) {
16484 fallthrough; /* otherwise default to smallest */
16486 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16487 &cq_set->u.request, LPFC_CQ_CNT_256);
16490 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16491 &cq_set->u.request, LPFC_CQ_CNT_512);
16494 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16495 &cq_set->u.request, LPFC_CQ_CNT_1024);
16498 bf_set(lpfc_mbx_cq_create_set_eq_id0,
16499 &cq_set->u.request, eq->queue_id);
16502 bf_set(lpfc_mbx_cq_create_set_eq_id1,
16503 &cq_set->u.request, eq->queue_id);
16506 bf_set(lpfc_mbx_cq_create_set_eq_id2,
16507 &cq_set->u.request, eq->queue_id);
16510 bf_set(lpfc_mbx_cq_create_set_eq_id3,
16511 &cq_set->u.request, eq->queue_id);
16514 bf_set(lpfc_mbx_cq_create_set_eq_id4,
16515 &cq_set->u.request, eq->queue_id);
16518 bf_set(lpfc_mbx_cq_create_set_eq_id5,
16519 &cq_set->u.request, eq->queue_id);
16522 bf_set(lpfc_mbx_cq_create_set_eq_id6,
16523 &cq_set->u.request, eq->queue_id);
16526 bf_set(lpfc_mbx_cq_create_set_eq_id7,
16527 &cq_set->u.request, eq->queue_id);
16530 bf_set(lpfc_mbx_cq_create_set_eq_id8,
16531 &cq_set->u.request, eq->queue_id);
16534 bf_set(lpfc_mbx_cq_create_set_eq_id9,
16535 &cq_set->u.request, eq->queue_id);
16538 bf_set(lpfc_mbx_cq_create_set_eq_id10,
16539 &cq_set->u.request, eq->queue_id);
16542 bf_set(lpfc_mbx_cq_create_set_eq_id11,
16543 &cq_set->u.request, eq->queue_id);
16546 bf_set(lpfc_mbx_cq_create_set_eq_id12,
16547 &cq_set->u.request, eq->queue_id);
16550 bf_set(lpfc_mbx_cq_create_set_eq_id13,
16551 &cq_set->u.request, eq->queue_id);
16554 bf_set(lpfc_mbx_cq_create_set_eq_id14,
16555 &cq_set->u.request, eq->queue_id);
16558 bf_set(lpfc_mbx_cq_create_set_eq_id15,
16559 &cq_set->u.request, eq->queue_id);
16563 /* link the cq onto the parent eq child list */
16564 list_add_tail(&cq->list, &eq->child_list);
16565 /* Set up completion queue's type and subtype */
16567 cq->subtype = subtype;
16568 cq->assoc_qid = eq->queue_id;
16570 cq->host_index = 0;
16571 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
16572 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
16577 list_for_each_entry(dmabuf, &cq->page_list, list) {
16578 memset(dmabuf->virt, 0, hw_page_size);
16579 cnt = page_idx + dmabuf->buffer_tag;
16580 cq_set->u.request.page[cnt].addr_lo =
16581 putPaddrLow(dmabuf->phys);
16582 cq_set->u.request.page[cnt].addr_hi =
16583 putPaddrHigh(dmabuf->phys);
16589 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16591 /* The IOCTL status is embedded in the mailbox subheader. */
16592 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16593 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16594 if (shdr_status || shdr_add_status || rc) {
16595 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16596 "3119 CQ_CREATE_SET mailbox failed with "
16597 "status x%x add_status x%x, mbx status x%x\n",
16598 shdr_status, shdr_add_status, rc);
16602 rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
16603 if (rc == 0xFFFF) {
16608 for (idx = 0; idx < numcq; idx++) {
16610 cq->queue_id = rc + idx;
16611 if (cq->queue_id > phba->sli4_hba.cq_max)
16612 phba->sli4_hba.cq_max = cq->queue_id;
16616 lpfc_sli4_mbox_cmd_free(phba, mbox);
16621 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
16622 * @phba: HBA structure that indicates port to create a queue on.
16623 * @mq: The queue structure to use to create the mailbox queue.
16624 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
16625 * @cq: The completion queue to associate with this cq.
16627 * This function provides failback (fb) functionality when the
16628 * mq_create_ext fails on older FW generations. It's purpose is identical
16629 * to mq_create_ext otherwise.
16631 * This routine cannot fail as all attributes were previously accessed and
16632 * initialized in mq_create_ext.
16635 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
16636 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
16638 struct lpfc_mbx_mq_create *mq_create;
16639 struct lpfc_dmabuf *dmabuf;
16642 length = (sizeof(struct lpfc_mbx_mq_create) -
16643 sizeof(struct lpfc_sli4_cfg_mhdr));
16644 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16645 LPFC_MBOX_OPCODE_MQ_CREATE,
16646 length, LPFC_SLI4_MBX_EMBED);
16647 mq_create = &mbox->u.mqe.un.mq_create;
16648 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
16650 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
16652 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
16653 switch (mq->entry_count) {
16655 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16656 LPFC_MQ_RING_SIZE_16);
16659 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16660 LPFC_MQ_RING_SIZE_32);
16663 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16664 LPFC_MQ_RING_SIZE_64);
16667 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16668 LPFC_MQ_RING_SIZE_128);
16671 list_for_each_entry(dmabuf, &mq->page_list, list) {
16672 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16673 putPaddrLow(dmabuf->phys);
16674 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16675 putPaddrHigh(dmabuf->phys);
16680 * lpfc_mq_create - Create a mailbox Queue on the HBA
16681 * @phba: HBA structure that indicates port to create a queue on.
16682 * @mq: The queue structure to use to create the mailbox queue.
16683 * @cq: The completion queue to associate with this cq.
16684 * @subtype: The queue's subtype.
16686 * This function creates a mailbox queue, as detailed in @mq, on a port,
16687 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
16689 * The @phba struct is used to send mailbox command to HBA. The @cq struct
16690 * is used to get the entry count and entry size that are necessary to
16691 * determine the number of pages to allocate and use for this queue. This
16692 * function will send the MQ_CREATE mailbox command to the HBA to setup the
16693 * mailbox queue. This function is asynchronous and will wait for the mailbox
16694 * command to finish before continuing.
16696 * On success this function will return a zero. If unable to allocate enough
16697 * memory this function will return -ENOMEM. If the queue create mailbox command
16698 * fails this function will return -ENXIO.
16701 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
16702 struct lpfc_queue *cq, uint32_t subtype)
16704 struct lpfc_mbx_mq_create *mq_create;
16705 struct lpfc_mbx_mq_create_ext *mq_create_ext;
16706 struct lpfc_dmabuf *dmabuf;
16707 LPFC_MBOXQ_t *mbox;
16708 int rc, length, status = 0;
16709 uint32_t shdr_status, shdr_add_status;
16710 union lpfc_sli4_cfg_shdr *shdr;
16711 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16713 /* sanity check on queue memory */
16716 if (!phba->sli4_hba.pc_sli4_params.supported)
16717 hw_page_size = SLI4_PAGE_SIZE;
16719 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16722 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
16723 sizeof(struct lpfc_sli4_cfg_mhdr));
16724 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16725 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
16726 length, LPFC_SLI4_MBX_EMBED);
16728 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
16729 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
16730 bf_set(lpfc_mbx_mq_create_ext_num_pages,
16731 &mq_create_ext->u.request, mq->page_count);
16732 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
16733 &mq_create_ext->u.request, 1);
16734 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
16735 &mq_create_ext->u.request, 1);
16736 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
16737 &mq_create_ext->u.request, 1);
16738 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
16739 &mq_create_ext->u.request, 1);
16740 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
16741 &mq_create_ext->u.request, 1);
16742 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
16743 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16744 phba->sli4_hba.pc_sli4_params.mqv);
16745 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
16746 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
16749 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
16751 switch (mq->entry_count) {
16753 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16754 "0362 Unsupported MQ count. (%d)\n",
16756 if (mq->entry_count < 16) {
16760 fallthrough; /* otherwise default to smallest count */
16762 bf_set(lpfc_mq_context_ring_size,
16763 &mq_create_ext->u.request.context,
16764 LPFC_MQ_RING_SIZE_16);
16767 bf_set(lpfc_mq_context_ring_size,
16768 &mq_create_ext->u.request.context,
16769 LPFC_MQ_RING_SIZE_32);
16772 bf_set(lpfc_mq_context_ring_size,
16773 &mq_create_ext->u.request.context,
16774 LPFC_MQ_RING_SIZE_64);
16777 bf_set(lpfc_mq_context_ring_size,
16778 &mq_create_ext->u.request.context,
16779 LPFC_MQ_RING_SIZE_128);
16782 list_for_each_entry(dmabuf, &mq->page_list, list) {
16783 memset(dmabuf->virt, 0, hw_page_size);
16784 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
16785 putPaddrLow(dmabuf->phys);
16786 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
16787 putPaddrHigh(dmabuf->phys);
16789 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16790 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
16791 &mq_create_ext->u.response);
16792 if (rc != MBX_SUCCESS) {
16793 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16794 "2795 MQ_CREATE_EXT failed with "
16795 "status x%x. Failback to MQ_CREATE.\n",
16797 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
16798 mq_create = &mbox->u.mqe.un.mq_create;
16799 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16800 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
16801 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
16802 &mq_create->u.response);
16805 /* The IOCTL status is embedded in the mailbox subheader. */
16806 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16807 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16808 if (shdr_status || shdr_add_status || rc) {
16809 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16810 "2502 MQ_CREATE mailbox failed with "
16811 "status x%x add_status x%x, mbx status x%x\n",
16812 shdr_status, shdr_add_status, rc);
16816 if (mq->queue_id == 0xFFFF) {
16820 mq->type = LPFC_MQ;
16821 mq->assoc_qid = cq->queue_id;
16822 mq->subtype = subtype;
16823 mq->host_index = 0;
16826 /* link the mq onto the parent cq child list */
16827 list_add_tail(&mq->list, &cq->child_list);
16829 mempool_free(mbox, phba->mbox_mem_pool);
16834 * lpfc_wq_create - Create a Work Queue on the HBA
16835 * @phba: HBA structure that indicates port to create a queue on.
16836 * @wq: The queue structure to use to create the work queue.
16837 * @cq: The completion queue to bind this work queue to.
16838 * @subtype: The subtype of the work queue indicating its functionality.
16840 * This function creates a work queue, as detailed in @wq, on a port, described
16841 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
16843 * The @phba struct is used to send mailbox command to HBA. The @wq struct
16844 * is used to get the entry count and entry size that are necessary to
16845 * determine the number of pages to allocate and use for this queue. The @cq
16846 * is used to indicate which completion queue to bind this work queue to. This
16847 * function will send the WQ_CREATE mailbox command to the HBA to setup the
16848 * work queue. This function is asynchronous and will wait for the mailbox
16849 * command to finish before continuing.
16851 * On success this function will return a zero. If unable to allocate enough
16852 * memory this function will return -ENOMEM. If the queue create mailbox command
16853 * fails this function will return -ENXIO.
16856 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
16857 struct lpfc_queue *cq, uint32_t subtype)
16859 struct lpfc_mbx_wq_create *wq_create;
16860 struct lpfc_dmabuf *dmabuf;
16861 LPFC_MBOXQ_t *mbox;
16862 int rc, length, status = 0;
16863 uint32_t shdr_status, shdr_add_status;
16864 union lpfc_sli4_cfg_shdr *shdr;
16865 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16866 struct dma_address *page;
16867 void __iomem *bar_memmap_p;
16868 uint32_t db_offset;
16869 uint16_t pci_barset;
16870 uint8_t dpp_barset;
16871 uint32_t dpp_offset;
16872 uint8_t wq_create_version;
16874 unsigned long pg_addr;
16877 /* sanity check on queue memory */
16880 if (!phba->sli4_hba.pc_sli4_params.supported)
16881 hw_page_size = wq->page_size;
16883 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16886 length = (sizeof(struct lpfc_mbx_wq_create) -
16887 sizeof(struct lpfc_sli4_cfg_mhdr));
16888 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16889 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
16890 length, LPFC_SLI4_MBX_EMBED);
16891 wq_create = &mbox->u.mqe.un.wq_create;
16892 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
16893 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
16895 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
16898 /* wqv is the earliest version supported, NOT the latest */
16899 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16900 phba->sli4_hba.pc_sli4_params.wqv);
16902 if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
16903 (wq->page_size > SLI4_PAGE_SIZE))
16904 wq_create_version = LPFC_Q_CREATE_VERSION_1;
16906 wq_create_version = LPFC_Q_CREATE_VERSION_0;
16908 switch (wq_create_version) {
16909 case LPFC_Q_CREATE_VERSION_1:
16910 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
16912 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16913 LPFC_Q_CREATE_VERSION_1);
16915 switch (wq->entry_size) {
16918 bf_set(lpfc_mbx_wq_create_wqe_size,
16919 &wq_create->u.request_1,
16920 LPFC_WQ_WQE_SIZE_64);
16923 bf_set(lpfc_mbx_wq_create_wqe_size,
16924 &wq_create->u.request_1,
16925 LPFC_WQ_WQE_SIZE_128);
16928 /* Request DPP by default */
16929 bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
16930 bf_set(lpfc_mbx_wq_create_page_size,
16931 &wq_create->u.request_1,
16932 (wq->page_size / SLI4_PAGE_SIZE));
16933 page = wq_create->u.request_1.page;
16936 page = wq_create->u.request.page;
16940 list_for_each_entry(dmabuf, &wq->page_list, list) {
16941 memset(dmabuf->virt, 0, hw_page_size);
16942 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
16943 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
16946 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16947 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
16949 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16950 /* The IOCTL status is embedded in the mailbox subheader. */
16951 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16952 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16953 if (shdr_status || shdr_add_status || rc) {
16954 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16955 "2503 WQ_CREATE mailbox failed with "
16956 "status x%x add_status x%x, mbx status x%x\n",
16957 shdr_status, shdr_add_status, rc);
16962 if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
16963 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
16964 &wq_create->u.response);
16966 wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
16967 &wq_create->u.response_1);
16969 if (wq->queue_id == 0xFFFF) {
16974 wq->db_format = LPFC_DB_LIST_FORMAT;
16975 if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
16976 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
16977 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
16978 &wq_create->u.response);
16979 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
16980 (wq->db_format != LPFC_DB_RING_FORMAT)) {
16981 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16982 "3265 WQ[%d] doorbell format "
16983 "not supported: x%x\n",
16984 wq->queue_id, wq->db_format);
16988 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
16989 &wq_create->u.response);
16990 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16992 if (!bar_memmap_p) {
16993 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16994 "3263 WQ[%d] failed to memmap "
16995 "pci barset:x%x\n",
16996 wq->queue_id, pci_barset);
17000 db_offset = wq_create->u.response.doorbell_offset;
17001 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
17002 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
17003 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17004 "3252 WQ[%d] doorbell offset "
17005 "not supported: x%x\n",
17006 wq->queue_id, db_offset);
17010 wq->db_regaddr = bar_memmap_p + db_offset;
17011 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
17012 "3264 WQ[%d]: barset:x%x, offset:x%x, "
17013 "format:x%x\n", wq->queue_id,
17014 pci_barset, db_offset, wq->db_format);
17016 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
17018 /* Check if DPP was honored by the firmware */
17019 wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
17020 &wq_create->u.response_1);
17021 if (wq->dpp_enable) {
17022 pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
17023 &wq_create->u.response_1);
17024 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
17026 if (!bar_memmap_p) {
17027 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17028 "3267 WQ[%d] failed to memmap "
17029 "pci barset:x%x\n",
17030 wq->queue_id, pci_barset);
17034 db_offset = wq_create->u.response_1.doorbell_offset;
17035 wq->db_regaddr = bar_memmap_p + db_offset;
17036 wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
17037 &wq_create->u.response_1);
17038 dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
17039 &wq_create->u.response_1);
17040 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
17042 if (!bar_memmap_p) {
17043 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17044 "3268 WQ[%d] failed to memmap "
17045 "pci barset:x%x\n",
17046 wq->queue_id, dpp_barset);
17050 dpp_offset = wq_create->u.response_1.dpp_offset;
17051 wq->dpp_regaddr = bar_memmap_p + dpp_offset;
17052 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
17053 "3271 WQ[%d]: barset:x%x, offset:x%x, "
17054 "dpp_id:x%x dpp_barset:x%x "
17055 "dpp_offset:x%x\n",
17056 wq->queue_id, pci_barset, db_offset,
17057 wq->dpp_id, dpp_barset, dpp_offset);
17060 /* Enable combined writes for DPP aperture */
17061 pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
17062 rc = set_memory_wc(pg_addr, 1);
17064 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17065 "3272 Cannot setup Combined "
17066 "Write on WQ[%d] - disable DPP\n",
17068 phba->cfg_enable_dpp = 0;
17071 phba->cfg_enable_dpp = 0;
17074 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
17076 wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
17077 if (wq->pring == NULL) {
17081 wq->type = LPFC_WQ;
17082 wq->assoc_qid = cq->queue_id;
17083 wq->subtype = subtype;
17084 wq->host_index = 0;
17086 wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
17088 /* link the wq onto the parent cq child list */
17089 list_add_tail(&wq->list, &cq->child_list);
17091 mempool_free(mbox, phba->mbox_mem_pool);
17096 * lpfc_rq_create - Create a Receive Queue on the HBA
17097 * @phba: HBA structure that indicates port to create a queue on.
17098 * @hrq: The queue structure to use to create the header receive queue.
17099 * @drq: The queue structure to use to create the data receive queue.
17100 * @cq: The completion queue to bind this work queue to.
17101 * @subtype: The subtype of the work queue indicating its functionality.
17103 * This function creates a receive buffer queue pair , as detailed in @hrq and
17104 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
17107 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
17108 * struct is used to get the entry count that is necessary to determine the
17109 * number of pages to use for this queue. The @cq is used to indicate which
17110 * completion queue to bind received buffers that are posted to these queues to.
17111 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
17112 * receive queue pair. This function is asynchronous and will wait for the
17113 * mailbox command to finish before continuing.
17115 * On success this function will return a zero. If unable to allocate enough
17116 * memory this function will return -ENOMEM. If the queue create mailbox command
17117 * fails this function will return -ENXIO.
17120 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
17121 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
17123 struct lpfc_mbx_rq_create *rq_create;
17124 struct lpfc_dmabuf *dmabuf;
17125 LPFC_MBOXQ_t *mbox;
17126 int rc, length, status = 0;
17127 uint32_t shdr_status, shdr_add_status;
17128 union lpfc_sli4_cfg_shdr *shdr;
17129 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
17130 void __iomem *bar_memmap_p;
17131 uint32_t db_offset;
17132 uint16_t pci_barset;
17134 /* sanity check on queue memory */
17135 if (!hrq || !drq || !cq)
17137 if (!phba->sli4_hba.pc_sli4_params.supported)
17138 hw_page_size = SLI4_PAGE_SIZE;
17140 if (hrq->entry_count != drq->entry_count)
17142 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17145 length = (sizeof(struct lpfc_mbx_rq_create) -
17146 sizeof(struct lpfc_sli4_cfg_mhdr));
17147 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17148 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
17149 length, LPFC_SLI4_MBX_EMBED);
17150 rq_create = &mbox->u.mqe.un.rq_create;
17151 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
17152 bf_set(lpfc_mbox_hdr_version, &shdr->request,
17153 phba->sli4_hba.pc_sli4_params.rqv);
17154 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
17155 bf_set(lpfc_rq_context_rqe_count_1,
17156 &rq_create->u.request.context,
17158 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
17159 bf_set(lpfc_rq_context_rqe_size,
17160 &rq_create->u.request.context,
17162 bf_set(lpfc_rq_context_page_size,
17163 &rq_create->u.request.context,
17164 LPFC_RQ_PAGE_SIZE_4096);
17166 switch (hrq->entry_count) {
17168 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17169 "2535 Unsupported RQ count. (%d)\n",
17171 if (hrq->entry_count < 512) {
17175 fallthrough; /* otherwise default to smallest count */
17177 bf_set(lpfc_rq_context_rqe_count,
17178 &rq_create->u.request.context,
17179 LPFC_RQ_RING_SIZE_512);
17182 bf_set(lpfc_rq_context_rqe_count,
17183 &rq_create->u.request.context,
17184 LPFC_RQ_RING_SIZE_1024);
17187 bf_set(lpfc_rq_context_rqe_count,
17188 &rq_create->u.request.context,
17189 LPFC_RQ_RING_SIZE_2048);
17192 bf_set(lpfc_rq_context_rqe_count,
17193 &rq_create->u.request.context,
17194 LPFC_RQ_RING_SIZE_4096);
17197 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
17198 LPFC_HDR_BUF_SIZE);
17200 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
17202 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
17204 list_for_each_entry(dmabuf, &hrq->page_list, list) {
17205 memset(dmabuf->virt, 0, hw_page_size);
17206 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
17207 putPaddrLow(dmabuf->phys);
17208 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
17209 putPaddrHigh(dmabuf->phys);
17211 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
17212 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
17214 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17215 /* The IOCTL status is embedded in the mailbox subheader. */
17216 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17217 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17218 if (shdr_status || shdr_add_status || rc) {
17219 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17220 "2504 RQ_CREATE mailbox failed with "
17221 "status x%x add_status x%x, mbx status x%x\n",
17222 shdr_status, shdr_add_status, rc);
17226 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
17227 if (hrq->queue_id == 0xFFFF) {
17232 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
17233 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
17234 &rq_create->u.response);
17235 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
17236 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
17237 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17238 "3262 RQ [%d] doorbell format not "
17239 "supported: x%x\n", hrq->queue_id,
17245 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
17246 &rq_create->u.response);
17247 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
17248 if (!bar_memmap_p) {
17249 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17250 "3269 RQ[%d] failed to memmap pci "
17251 "barset:x%x\n", hrq->queue_id,
17257 db_offset = rq_create->u.response.doorbell_offset;
17258 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
17259 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
17260 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17261 "3270 RQ[%d] doorbell offset not "
17262 "supported: x%x\n", hrq->queue_id,
17267 hrq->db_regaddr = bar_memmap_p + db_offset;
17268 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
17269 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
17270 "format:x%x\n", hrq->queue_id, pci_barset,
17271 db_offset, hrq->db_format);
17273 hrq->db_format = LPFC_DB_RING_FORMAT;
17274 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
17276 hrq->type = LPFC_HRQ;
17277 hrq->assoc_qid = cq->queue_id;
17278 hrq->subtype = subtype;
17279 hrq->host_index = 0;
17280 hrq->hba_index = 0;
17281 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17283 /* now create the data queue */
17284 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17285 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
17286 length, LPFC_SLI4_MBX_EMBED);
17287 bf_set(lpfc_mbox_hdr_version, &shdr->request,
17288 phba->sli4_hba.pc_sli4_params.rqv);
17289 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
17290 bf_set(lpfc_rq_context_rqe_count_1,
17291 &rq_create->u.request.context, hrq->entry_count);
17292 if (subtype == LPFC_NVMET)
17293 rq_create->u.request.context.buffer_size =
17294 LPFC_NVMET_DATA_BUF_SIZE;
17296 rq_create->u.request.context.buffer_size =
17297 LPFC_DATA_BUF_SIZE;
17298 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
17300 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
17301 (PAGE_SIZE/SLI4_PAGE_SIZE));
17303 switch (drq->entry_count) {
17305 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17306 "2536 Unsupported RQ count. (%d)\n",
17308 if (drq->entry_count < 512) {
17312 fallthrough; /* otherwise default to smallest count */
17314 bf_set(lpfc_rq_context_rqe_count,
17315 &rq_create->u.request.context,
17316 LPFC_RQ_RING_SIZE_512);
17319 bf_set(lpfc_rq_context_rqe_count,
17320 &rq_create->u.request.context,
17321 LPFC_RQ_RING_SIZE_1024);
17324 bf_set(lpfc_rq_context_rqe_count,
17325 &rq_create->u.request.context,
17326 LPFC_RQ_RING_SIZE_2048);
17329 bf_set(lpfc_rq_context_rqe_count,
17330 &rq_create->u.request.context,
17331 LPFC_RQ_RING_SIZE_4096);
17334 if (subtype == LPFC_NVMET)
17335 bf_set(lpfc_rq_context_buf_size,
17336 &rq_create->u.request.context,
17337 LPFC_NVMET_DATA_BUF_SIZE);
17339 bf_set(lpfc_rq_context_buf_size,
17340 &rq_create->u.request.context,
17341 LPFC_DATA_BUF_SIZE);
17343 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
17345 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
17347 list_for_each_entry(dmabuf, &drq->page_list, list) {
17348 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
17349 putPaddrLow(dmabuf->phys);
17350 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
17351 putPaddrHigh(dmabuf->phys);
17353 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
17354 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
17355 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17356 /* The IOCTL status is embedded in the mailbox subheader. */
17357 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
17358 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17359 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17360 if (shdr_status || shdr_add_status || rc) {
17364 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
17365 if (drq->queue_id == 0xFFFF) {
17369 drq->type = LPFC_DRQ;
17370 drq->assoc_qid = cq->queue_id;
17371 drq->subtype = subtype;
17372 drq->host_index = 0;
17373 drq->hba_index = 0;
17374 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17376 /* link the header and data RQs onto the parent cq child list */
17377 list_add_tail(&hrq->list, &cq->child_list);
17378 list_add_tail(&drq->list, &cq->child_list);
17381 mempool_free(mbox, phba->mbox_mem_pool);
17386 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
17387 * @phba: HBA structure that indicates port to create a queue on.
17388 * @hrqp: The queue structure array to use to create the header receive queues.
17389 * @drqp: The queue structure array to use to create the data receive queues.
17390 * @cqp: The completion queue array to bind these receive queues to.
17391 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
17393 * This function creates a receive buffer queue pair , as detailed in @hrq and
17394 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
17397 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
17398 * struct is used to get the entry count that is necessary to determine the
17399 * number of pages to use for this queue. The @cq is used to indicate which
17400 * completion queue to bind received buffers that are posted to these queues to.
17401 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
17402 * receive queue pair. This function is asynchronous and will wait for the
17403 * mailbox command to finish before continuing.
17405 * On success this function will return a zero. If unable to allocate enough
17406 * memory this function will return -ENOMEM. If the queue create mailbox command
17407 * fails this function will return -ENXIO.
17410 lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
17411 struct lpfc_queue **drqp, struct lpfc_queue **cqp,
17414 struct lpfc_queue *hrq, *drq, *cq;
17415 struct lpfc_mbx_rq_create_v2 *rq_create;
17416 struct lpfc_dmabuf *dmabuf;
17417 LPFC_MBOXQ_t *mbox;
17418 int rc, length, alloclen, status = 0;
17419 int cnt, idx, numrq, page_idx = 0;
17420 uint32_t shdr_status, shdr_add_status;
17421 union lpfc_sli4_cfg_shdr *shdr;
17422 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
17424 numrq = phba->cfg_nvmet_mrq;
17425 /* sanity check on array memory */
17426 if (!hrqp || !drqp || !cqp || !numrq)
17428 if (!phba->sli4_hba.pc_sli4_params.supported)
17429 hw_page_size = SLI4_PAGE_SIZE;
17431 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17435 length = sizeof(struct lpfc_mbx_rq_create_v2);
17436 length += ((2 * numrq * hrqp[0]->page_count) *
17437 sizeof(struct dma_address));
17439 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17440 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
17441 LPFC_SLI4_MBX_NEMBED);
17442 if (alloclen < length) {
17443 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17444 "3099 Allocated DMA memory size (%d) is "
17445 "less than the requested DMA memory size "
17446 "(%d)\n", alloclen, length);
17453 rq_create = mbox->sge_array->addr[0];
17454 shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
17456 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
17459 for (idx = 0; idx < numrq; idx++) {
17464 /* sanity check on queue memory */
17465 if (!hrq || !drq || !cq) {
17470 if (hrq->entry_count != drq->entry_count) {
17476 bf_set(lpfc_mbx_rq_create_num_pages,
17477 &rq_create->u.request,
17479 bf_set(lpfc_mbx_rq_create_rq_cnt,
17480 &rq_create->u.request, (numrq * 2));
17481 bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
17483 bf_set(lpfc_rq_context_base_cq,
17484 &rq_create->u.request.context,
17486 bf_set(lpfc_rq_context_data_size,
17487 &rq_create->u.request.context,
17488 LPFC_NVMET_DATA_BUF_SIZE);
17489 bf_set(lpfc_rq_context_hdr_size,
17490 &rq_create->u.request.context,
17491 LPFC_HDR_BUF_SIZE);
17492 bf_set(lpfc_rq_context_rqe_count_1,
17493 &rq_create->u.request.context,
17495 bf_set(lpfc_rq_context_rqe_size,
17496 &rq_create->u.request.context,
17498 bf_set(lpfc_rq_context_page_size,
17499 &rq_create->u.request.context,
17500 (PAGE_SIZE/SLI4_PAGE_SIZE));
17503 list_for_each_entry(dmabuf, &hrq->page_list, list) {
17504 memset(dmabuf->virt, 0, hw_page_size);
17505 cnt = page_idx + dmabuf->buffer_tag;
17506 rq_create->u.request.page[cnt].addr_lo =
17507 putPaddrLow(dmabuf->phys);
17508 rq_create->u.request.page[cnt].addr_hi =
17509 putPaddrHigh(dmabuf->phys);
17515 list_for_each_entry(dmabuf, &drq->page_list, list) {
17516 memset(dmabuf->virt, 0, hw_page_size);
17517 cnt = page_idx + dmabuf->buffer_tag;
17518 rq_create->u.request.page[cnt].addr_lo =
17519 putPaddrLow(dmabuf->phys);
17520 rq_create->u.request.page[cnt].addr_hi =
17521 putPaddrHigh(dmabuf->phys);
17526 hrq->db_format = LPFC_DB_RING_FORMAT;
17527 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
17528 hrq->type = LPFC_HRQ;
17529 hrq->assoc_qid = cq->queue_id;
17530 hrq->subtype = subtype;
17531 hrq->host_index = 0;
17532 hrq->hba_index = 0;
17533 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17535 drq->db_format = LPFC_DB_RING_FORMAT;
17536 drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
17537 drq->type = LPFC_DRQ;
17538 drq->assoc_qid = cq->queue_id;
17539 drq->subtype = subtype;
17540 drq->host_index = 0;
17541 drq->hba_index = 0;
17542 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17544 list_add_tail(&hrq->list, &cq->child_list);
17545 list_add_tail(&drq->list, &cq->child_list);
17548 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17549 /* The IOCTL status is embedded in the mailbox subheader. */
17550 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17551 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17552 if (shdr_status || shdr_add_status || rc) {
17553 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17554 "3120 RQ_CREATE mailbox failed with "
17555 "status x%x add_status x%x, mbx status x%x\n",
17556 shdr_status, shdr_add_status, rc);
17560 rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
17561 if (rc == 0xFFFF) {
17566 /* Initialize all RQs with associated queue id */
17567 for (idx = 0; idx < numrq; idx++) {
17569 hrq->queue_id = rc + (2 * idx);
17571 drq->queue_id = rc + (2 * idx) + 1;
17575 lpfc_sli4_mbox_cmd_free(phba, mbox);
17580 * lpfc_eq_destroy - Destroy an event Queue on the HBA
17581 * @phba: HBA structure that indicates port to destroy a queue on.
17582 * @eq: The queue structure associated with the queue to destroy.
17584 * This function destroys a queue, as detailed in @eq by sending an mailbox
17585 * command, specific to the type of queue, to the HBA.
17587 * The @eq struct is used to get the queue ID of the queue to destroy.
17589 * On success this function will return a zero. If the queue destroy mailbox
17590 * command fails this function will return -ENXIO.
17593 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
17595 LPFC_MBOXQ_t *mbox;
17596 int rc, length, status = 0;
17597 uint32_t shdr_status, shdr_add_status;
17598 union lpfc_sli4_cfg_shdr *shdr;
17600 /* sanity check on queue memory */
17604 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
17607 length = (sizeof(struct lpfc_mbx_eq_destroy) -
17608 sizeof(struct lpfc_sli4_cfg_mhdr));
17609 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17610 LPFC_MBOX_OPCODE_EQ_DESTROY,
17611 length, LPFC_SLI4_MBX_EMBED);
17612 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
17614 mbox->vport = eq->phba->pport;
17615 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17617 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
17618 /* The IOCTL status is embedded in the mailbox subheader. */
17619 shdr = (union lpfc_sli4_cfg_shdr *)
17620 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
17621 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17622 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17623 if (shdr_status || shdr_add_status || rc) {
17624 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17625 "2505 EQ_DESTROY mailbox failed with "
17626 "status x%x add_status x%x, mbx status x%x\n",
17627 shdr_status, shdr_add_status, rc);
17631 /* Remove eq from any list */
17632 list_del_init(&eq->list);
17633 mempool_free(mbox, eq->phba->mbox_mem_pool);
17638 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
17639 * @phba: HBA structure that indicates port to destroy a queue on.
17640 * @cq: The queue structure associated with the queue to destroy.
17642 * This function destroys a queue, as detailed in @cq by sending an mailbox
17643 * command, specific to the type of queue, to the HBA.
17645 * The @cq struct is used to get the queue ID of the queue to destroy.
17647 * On success this function will return a zero. If the queue destroy mailbox
17648 * command fails this function will return -ENXIO.
17651 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
17653 LPFC_MBOXQ_t *mbox;
17654 int rc, length, status = 0;
17655 uint32_t shdr_status, shdr_add_status;
17656 union lpfc_sli4_cfg_shdr *shdr;
17658 /* sanity check on queue memory */
17661 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
17664 length = (sizeof(struct lpfc_mbx_cq_destroy) -
17665 sizeof(struct lpfc_sli4_cfg_mhdr));
17666 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17667 LPFC_MBOX_OPCODE_CQ_DESTROY,
17668 length, LPFC_SLI4_MBX_EMBED);
17669 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
17671 mbox->vport = cq->phba->pport;
17672 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17673 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
17674 /* The IOCTL status is embedded in the mailbox subheader. */
17675 shdr = (union lpfc_sli4_cfg_shdr *)
17676 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
17677 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17678 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17679 if (shdr_status || shdr_add_status || rc) {
17680 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17681 "2506 CQ_DESTROY mailbox failed with "
17682 "status x%x add_status x%x, mbx status x%x\n",
17683 shdr_status, shdr_add_status, rc);
17686 /* Remove cq from any list */
17687 list_del_init(&cq->list);
17688 mempool_free(mbox, cq->phba->mbox_mem_pool);
17693 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
17694 * @phba: HBA structure that indicates port to destroy a queue on.
17695 * @mq: The queue structure associated with the queue to destroy.
17697 * This function destroys a queue, as detailed in @mq by sending an mailbox
17698 * command, specific to the type of queue, to the HBA.
17700 * The @mq struct is used to get the queue ID of the queue to destroy.
17702 * On success this function will return a zero. If the queue destroy mailbox
17703 * command fails this function will return -ENXIO.
17706 lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
17708 LPFC_MBOXQ_t *mbox;
17709 int rc, length, status = 0;
17710 uint32_t shdr_status, shdr_add_status;
17711 union lpfc_sli4_cfg_shdr *shdr;
17713 /* sanity check on queue memory */
17716 mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
17719 length = (sizeof(struct lpfc_mbx_mq_destroy) -
17720 sizeof(struct lpfc_sli4_cfg_mhdr));
17721 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17722 LPFC_MBOX_OPCODE_MQ_DESTROY,
17723 length, LPFC_SLI4_MBX_EMBED);
17724 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
17726 mbox->vport = mq->phba->pport;
17727 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17728 rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
17729 /* The IOCTL status is embedded in the mailbox subheader. */
17730 shdr = (union lpfc_sli4_cfg_shdr *)
17731 &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
17732 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17733 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17734 if (shdr_status || shdr_add_status || rc) {
17735 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17736 "2507 MQ_DESTROY mailbox failed with "
17737 "status x%x add_status x%x, mbx status x%x\n",
17738 shdr_status, shdr_add_status, rc);
17741 /* Remove mq from any list */
17742 list_del_init(&mq->list);
17743 mempool_free(mbox, mq->phba->mbox_mem_pool);
17748 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
17749 * @phba: HBA structure that indicates port to destroy a queue on.
17750 * @wq: The queue structure associated with the queue to destroy.
17752 * This function destroys a queue, as detailed in @wq by sending an mailbox
17753 * command, specific to the type of queue, to the HBA.
17755 * The @wq struct is used to get the queue ID of the queue to destroy.
17757 * On success this function will return a zero. If the queue destroy mailbox
17758 * command fails this function will return -ENXIO.
17761 lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
17763 LPFC_MBOXQ_t *mbox;
17764 int rc, length, status = 0;
17765 uint32_t shdr_status, shdr_add_status;
17766 union lpfc_sli4_cfg_shdr *shdr;
17768 /* sanity check on queue memory */
17771 mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
17774 length = (sizeof(struct lpfc_mbx_wq_destroy) -
17775 sizeof(struct lpfc_sli4_cfg_mhdr));
17776 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17777 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
17778 length, LPFC_SLI4_MBX_EMBED);
17779 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
17781 mbox->vport = wq->phba->pport;
17782 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17783 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
17784 shdr = (union lpfc_sli4_cfg_shdr *)
17785 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
17786 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17787 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17788 if (shdr_status || shdr_add_status || rc) {
17789 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17790 "2508 WQ_DESTROY mailbox failed with "
17791 "status x%x add_status x%x, mbx status x%x\n",
17792 shdr_status, shdr_add_status, rc);
17795 /* Remove wq from any list */
17796 list_del_init(&wq->list);
17799 mempool_free(mbox, wq->phba->mbox_mem_pool);
17804 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
17805 * @phba: HBA structure that indicates port to destroy a queue on.
17806 * @hrq: The queue structure associated with the queue to destroy.
17807 * @drq: The queue structure associated with the queue to destroy.
17809 * This function destroys a queue, as detailed in @rq by sending an mailbox
17810 * command, specific to the type of queue, to the HBA.
17812 * The @rq struct is used to get the queue ID of the queue to destroy.
17814 * On success this function will return a zero. If the queue destroy mailbox
17815 * command fails this function will return -ENXIO.
17818 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
17819 struct lpfc_queue *drq)
17821 LPFC_MBOXQ_t *mbox;
17822 int rc, length, status = 0;
17823 uint32_t shdr_status, shdr_add_status;
17824 union lpfc_sli4_cfg_shdr *shdr;
17826 /* sanity check on queue memory */
17829 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
17832 length = (sizeof(struct lpfc_mbx_rq_destroy) -
17833 sizeof(struct lpfc_sli4_cfg_mhdr));
17834 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17835 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
17836 length, LPFC_SLI4_MBX_EMBED);
17837 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
17839 mbox->vport = hrq->phba->pport;
17840 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17841 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
17842 /* The IOCTL status is embedded in the mailbox subheader. */
17843 shdr = (union lpfc_sli4_cfg_shdr *)
17844 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
17845 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17846 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17847 if (shdr_status || shdr_add_status || rc) {
17848 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17849 "2509 RQ_DESTROY mailbox failed with "
17850 "status x%x add_status x%x, mbx status x%x\n",
17851 shdr_status, shdr_add_status, rc);
17852 mempool_free(mbox, hrq->phba->mbox_mem_pool);
17855 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
17857 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
17858 shdr = (union lpfc_sli4_cfg_shdr *)
17859 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
17860 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17861 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17862 if (shdr_status || shdr_add_status || rc) {
17863 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17864 "2510 RQ_DESTROY mailbox failed with "
17865 "status x%x add_status x%x, mbx status x%x\n",
17866 shdr_status, shdr_add_status, rc);
17869 list_del_init(&hrq->list);
17870 list_del_init(&drq->list);
17871 mempool_free(mbox, hrq->phba->mbox_mem_pool);
17876 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
17877 * @phba: The virtual port for which this call being executed.
17878 * @pdma_phys_addr0: Physical address of the 1st SGL page.
17879 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
17880 * @xritag: the xritag that ties this io to the SGL pages.
17882 * This routine will post the sgl pages for the IO that has the xritag
17883 * that is in the iocbq structure. The xritag is assigned during iocbq
17884 * creation and persists for as long as the driver is loaded.
17885 * if the caller has fewer than 256 scatter gather segments to map then
17886 * pdma_phys_addr1 should be 0.
17887 * If the caller needs to map more than 256 scatter gather segment then
17888 * pdma_phys_addr1 should be a valid physical address.
17889 * physical address for SGLs must be 64 byte aligned.
17890 * If you are going to map 2 SGL's then the first one must have 256 entries
17891 * the second sgl can have between 1 and 256 entries.
17895 * -ENXIO, -ENOMEM - Failure
17898 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
17899 dma_addr_t pdma_phys_addr0,
17900 dma_addr_t pdma_phys_addr1,
17903 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
17904 LPFC_MBOXQ_t *mbox;
17906 uint32_t shdr_status, shdr_add_status;
17908 union lpfc_sli4_cfg_shdr *shdr;
17910 if (xritag == NO_XRI) {
17911 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17912 "0364 Invalid param:\n");
17916 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17920 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17921 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
17922 sizeof(struct lpfc_mbx_post_sgl_pages) -
17923 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
17925 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
17926 &mbox->u.mqe.un.post_sgl_pages;
17927 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
17928 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
17930 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
17931 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
17932 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
17933 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
17935 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
17936 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
17937 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
17938 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
17939 if (!phba->sli4_hba.intr_enable)
17940 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17942 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17943 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17945 /* The IOCTL status is embedded in the mailbox subheader. */
17946 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
17947 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17948 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17949 if (!phba->sli4_hba.intr_enable)
17950 mempool_free(mbox, phba->mbox_mem_pool);
17951 else if (rc != MBX_TIMEOUT)
17952 mempool_free(mbox, phba->mbox_mem_pool);
17953 if (shdr_status || shdr_add_status || rc) {
17954 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17955 "2511 POST_SGL mailbox failed with "
17956 "status x%x add_status x%x, mbx status x%x\n",
17957 shdr_status, shdr_add_status, rc);
17963 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
17964 * @phba: pointer to lpfc hba data structure.
17966 * This routine is invoked to post rpi header templates to the
17967 * HBA consistent with the SLI-4 interface spec. This routine
17968 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17969 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17972 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
17973 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
17976 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
17981 * Fetch the next logical xri. Because this index is logical,
17982 * the driver starts at 0 each time.
17984 spin_lock_irq(&phba->hbalock);
17985 xri = find_first_zero_bit(phba->sli4_hba.xri_bmask,
17986 phba->sli4_hba.max_cfg_param.max_xri);
17987 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
17988 spin_unlock_irq(&phba->hbalock);
17991 set_bit(xri, phba->sli4_hba.xri_bmask);
17992 phba->sli4_hba.max_cfg_param.xri_used++;
17994 spin_unlock_irq(&phba->hbalock);
17999 * __lpfc_sli4_free_xri - Release an xri for reuse.
18000 * @phba: pointer to lpfc hba data structure.
18001 * @xri: xri to release.
18003 * This routine is invoked to release an xri to the pool of
18004 * available rpis maintained by the driver.
18007 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
18009 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
18010 phba->sli4_hba.max_cfg_param.xri_used--;
18015 * lpfc_sli4_free_xri - Release an xri for reuse.
18016 * @phba: pointer to lpfc hba data structure.
18017 * @xri: xri to release.
18019 * This routine is invoked to release an xri to the pool of
18020 * available rpis maintained by the driver.
18023 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
18025 spin_lock_irq(&phba->hbalock);
18026 __lpfc_sli4_free_xri(phba, xri);
18027 spin_unlock_irq(&phba->hbalock);
18031 * lpfc_sli4_next_xritag - Get an xritag for the io
18032 * @phba: Pointer to HBA context object.
18034 * This function gets an xritag for the iocb. If there is no unused xritag
18035 * it will return 0xffff.
18036 * The function returns the allocated xritag if successful, else returns zero.
18037 * Zero is not a valid xritag.
18038 * The caller is not required to hold any lock.
18041 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
18043 uint16_t xri_index;
18045 xri_index = lpfc_sli4_alloc_xri(phba);
18046 if (xri_index == NO_XRI)
18047 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
18048 "2004 Failed to allocate XRI.last XRITAG is %d"
18049 " Max XRI is %d, Used XRI is %d\n",
18051 phba->sli4_hba.max_cfg_param.max_xri,
18052 phba->sli4_hba.max_cfg_param.xri_used);
18057 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
18058 * @phba: pointer to lpfc hba data structure.
18059 * @post_sgl_list: pointer to els sgl entry list.
18060 * @post_cnt: number of els sgl entries on the list.
18062 * This routine is invoked to post a block of driver's sgl pages to the
18063 * HBA using non-embedded mailbox command. No Lock is held. This routine
18064 * is only called when the driver is loading and after all IO has been
18068 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
18069 struct list_head *post_sgl_list,
18072 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
18073 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
18074 struct sgl_page_pairs *sgl_pg_pairs;
18076 LPFC_MBOXQ_t *mbox;
18077 uint32_t reqlen, alloclen, pg_pairs;
18079 uint16_t xritag_start = 0;
18081 uint32_t shdr_status, shdr_add_status;
18082 union lpfc_sli4_cfg_shdr *shdr;
18084 reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
18085 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
18086 if (reqlen > SLI4_PAGE_SIZE) {
18087 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18088 "2559 Block sgl registration required DMA "
18089 "size (%d) great than a page\n", reqlen);
18093 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18097 /* Allocate DMA memory and set up the non-embedded mailbox command */
18098 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
18099 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
18100 LPFC_SLI4_MBX_NEMBED);
18102 if (alloclen < reqlen) {
18103 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18104 "0285 Allocated DMA memory size (%d) is "
18105 "less than the requested DMA memory "
18106 "size (%d)\n", alloclen, reqlen);
18107 lpfc_sli4_mbox_cmd_free(phba, mbox);
18110 /* Set up the SGL pages in the non-embedded DMA pages */
18111 viraddr = mbox->sge_array->addr[0];
18112 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
18113 sgl_pg_pairs = &sgl->sgl_pg_pairs;
18116 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
18117 /* Set up the sge entry */
18118 sgl_pg_pairs->sgl_pg0_addr_lo =
18119 cpu_to_le32(putPaddrLow(sglq_entry->phys));
18120 sgl_pg_pairs->sgl_pg0_addr_hi =
18121 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
18122 sgl_pg_pairs->sgl_pg1_addr_lo =
18123 cpu_to_le32(putPaddrLow(0));
18124 sgl_pg_pairs->sgl_pg1_addr_hi =
18125 cpu_to_le32(putPaddrHigh(0));
18127 /* Keep the first xritag on the list */
18129 xritag_start = sglq_entry->sli4_xritag;
18134 /* Complete initialization and perform endian conversion. */
18135 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
18136 bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
18137 sgl->word0 = cpu_to_le32(sgl->word0);
18139 if (!phba->sli4_hba.intr_enable)
18140 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
18142 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
18143 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
18145 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
18146 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18147 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18148 if (!phba->sli4_hba.intr_enable)
18149 lpfc_sli4_mbox_cmd_free(phba, mbox);
18150 else if (rc != MBX_TIMEOUT)
18151 lpfc_sli4_mbox_cmd_free(phba, mbox);
18152 if (shdr_status || shdr_add_status || rc) {
18153 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18154 "2513 POST_SGL_BLOCK mailbox command failed "
18155 "status x%x add_status x%x mbx status x%x\n",
18156 shdr_status, shdr_add_status, rc);
18163 * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
18164 * @phba: pointer to lpfc hba data structure.
18165 * @nblist: pointer to nvme buffer list.
18166 * @count: number of scsi buffers on the list.
18168 * This routine is invoked to post a block of @count scsi sgl pages from a
18169 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
18174 lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
18177 struct lpfc_io_buf *lpfc_ncmd;
18178 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
18179 struct sgl_page_pairs *sgl_pg_pairs;
18181 LPFC_MBOXQ_t *mbox;
18182 uint32_t reqlen, alloclen, pg_pairs;
18184 uint16_t xritag_start = 0;
18186 uint32_t shdr_status, shdr_add_status;
18187 dma_addr_t pdma_phys_bpl1;
18188 union lpfc_sli4_cfg_shdr *shdr;
18190 /* Calculate the requested length of the dma memory */
18191 reqlen = count * sizeof(struct sgl_page_pairs) +
18192 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
18193 if (reqlen > SLI4_PAGE_SIZE) {
18194 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
18195 "6118 Block sgl registration required DMA "
18196 "size (%d) great than a page\n", reqlen);
18199 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18201 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18202 "6119 Failed to allocate mbox cmd memory\n");
18206 /* Allocate DMA memory and set up the non-embedded mailbox command */
18207 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
18208 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
18209 reqlen, LPFC_SLI4_MBX_NEMBED);
18211 if (alloclen < reqlen) {
18212 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18213 "6120 Allocated DMA memory size (%d) is "
18214 "less than the requested DMA memory "
18215 "size (%d)\n", alloclen, reqlen);
18216 lpfc_sli4_mbox_cmd_free(phba, mbox);
18220 /* Get the first SGE entry from the non-embedded DMA memory */
18221 viraddr = mbox->sge_array->addr[0];
18223 /* Set up the SGL pages in the non-embedded DMA pages */
18224 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
18225 sgl_pg_pairs = &sgl->sgl_pg_pairs;
18228 list_for_each_entry(lpfc_ncmd, nblist, list) {
18229 /* Set up the sge entry */
18230 sgl_pg_pairs->sgl_pg0_addr_lo =
18231 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
18232 sgl_pg_pairs->sgl_pg0_addr_hi =
18233 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
18234 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
18235 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
18238 pdma_phys_bpl1 = 0;
18239 sgl_pg_pairs->sgl_pg1_addr_lo =
18240 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
18241 sgl_pg_pairs->sgl_pg1_addr_hi =
18242 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
18243 /* Keep the first xritag on the list */
18245 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
18249 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
18250 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
18251 /* Perform endian conversion if necessary */
18252 sgl->word0 = cpu_to_le32(sgl->word0);
18254 if (!phba->sli4_hba.intr_enable) {
18255 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
18257 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
18258 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
18260 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
18261 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18262 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18263 if (!phba->sli4_hba.intr_enable)
18264 lpfc_sli4_mbox_cmd_free(phba, mbox);
18265 else if (rc != MBX_TIMEOUT)
18266 lpfc_sli4_mbox_cmd_free(phba, mbox);
18267 if (shdr_status || shdr_add_status || rc) {
18268 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18269 "6125 POST_SGL_BLOCK mailbox command failed "
18270 "status x%x add_status x%x mbx status x%x\n",
18271 shdr_status, shdr_add_status, rc);
18278 * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
18279 * @phba: pointer to lpfc hba data structure.
18280 * @post_nblist: pointer to the nvme buffer list.
18281 * @sb_count: number of nvme buffers.
18283 * This routine walks a list of nvme buffers that was passed in. It attempts
18284 * to construct blocks of nvme buffer sgls which contains contiguous xris and
18285 * uses the non-embedded SGL block post mailbox commands to post to the port.
18286 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
18287 * embedded SGL post mailbox command for posting. The @post_nblist passed in
18288 * must be local list, thus no lock is needed when manipulate the list.
18290 * Returns: 0 = failure, non-zero number of successfully posted buffers.
18293 lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
18294 struct list_head *post_nblist, int sb_count)
18296 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
18297 int status, sgl_size;
18298 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
18299 dma_addr_t pdma_phys_sgl1;
18300 int last_xritag = NO_XRI;
18302 LIST_HEAD(prep_nblist);
18303 LIST_HEAD(blck_nblist);
18304 LIST_HEAD(nvme_nblist);
18310 sgl_size = phba->cfg_sg_dma_buf_size;
18311 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
18312 list_del_init(&lpfc_ncmd->list);
18314 if ((last_xritag != NO_XRI) &&
18315 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
18316 /* a hole in xri block, form a sgl posting block */
18317 list_splice_init(&prep_nblist, &blck_nblist);
18318 post_cnt = block_cnt - 1;
18319 /* prepare list for next posting block */
18320 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
18323 /* prepare list for next posting block */
18324 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
18325 /* enough sgls for non-embed sgl mbox command */
18326 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
18327 list_splice_init(&prep_nblist, &blck_nblist);
18328 post_cnt = block_cnt;
18333 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
18335 /* end of repost sgl list condition for NVME buffers */
18336 if (num_posting == sb_count) {
18337 if (post_cnt == 0) {
18338 /* last sgl posting block */
18339 list_splice_init(&prep_nblist, &blck_nblist);
18340 post_cnt = block_cnt;
18341 } else if (block_cnt == 1) {
18342 /* last single sgl with non-contiguous xri */
18343 if (sgl_size > SGL_PAGE_SIZE)
18345 lpfc_ncmd->dma_phys_sgl +
18348 pdma_phys_sgl1 = 0;
18349 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
18350 status = lpfc_sli4_post_sgl(
18351 phba, lpfc_ncmd->dma_phys_sgl,
18352 pdma_phys_sgl1, cur_xritag);
18354 /* Post error. Buffer unavailable. */
18355 lpfc_ncmd->flags |=
18356 LPFC_SBUF_NOT_POSTED;
18358 /* Post success. Bffer available. */
18359 lpfc_ncmd->flags &=
18360 ~LPFC_SBUF_NOT_POSTED;
18361 lpfc_ncmd->status = IOSTAT_SUCCESS;
18364 /* success, put on NVME buffer sgl list */
18365 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
18369 /* continue until a nembed page worth of sgls */
18373 /* post block of NVME buffer list sgls */
18374 status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
18377 /* don't reset xirtag due to hole in xri block */
18378 if (block_cnt == 0)
18379 last_xritag = NO_XRI;
18381 /* reset NVME buffer post count for next round of posting */
18384 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
18385 while (!list_empty(&blck_nblist)) {
18386 list_remove_head(&blck_nblist, lpfc_ncmd,
18387 struct lpfc_io_buf, list);
18389 /* Post error. Mark buffer unavailable. */
18390 lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
18392 /* Post success, Mark buffer available. */
18393 lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
18394 lpfc_ncmd->status = IOSTAT_SUCCESS;
18397 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
18400 /* Push NVME buffers with sgl posted to the available list */
18401 lpfc_io_buf_replenish(phba, &nvme_nblist);
18407 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
18408 * @phba: pointer to lpfc_hba struct that the frame was received on
18409 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
18411 * This function checks the fields in the @fc_hdr to see if the FC frame is a
18412 * valid type of frame that the LPFC driver will handle. This function will
18413 * return a zero if the frame is a valid frame or a non zero value when the
18414 * frame does not pass the check.
18417 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
18419 /* make rctl_names static to save stack space */
18420 struct fc_vft_header *fc_vft_hdr;
18421 uint32_t *header = (uint32_t *) fc_hdr;
18423 #define FC_RCTL_MDS_DIAGS 0xF4
18425 switch (fc_hdr->fh_r_ctl) {
18426 case FC_RCTL_DD_UNCAT: /* uncategorized information */
18427 case FC_RCTL_DD_SOL_DATA: /* solicited data */
18428 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
18429 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
18430 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
18431 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
18432 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
18433 case FC_RCTL_DD_CMD_STATUS: /* command status */
18434 case FC_RCTL_ELS_REQ: /* extended link services request */
18435 case FC_RCTL_ELS_REP: /* extended link services reply */
18436 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
18437 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
18438 case FC_RCTL_BA_NOP: /* basic link service NOP */
18439 case FC_RCTL_BA_ABTS: /* basic link service abort */
18440 case FC_RCTL_BA_RMC: /* remove connection */
18441 case FC_RCTL_BA_ACC: /* basic accept */
18442 case FC_RCTL_BA_RJT: /* basic reject */
18443 case FC_RCTL_BA_PRMT:
18444 case FC_RCTL_ACK_1: /* acknowledge_1 */
18445 case FC_RCTL_ACK_0: /* acknowledge_0 */
18446 case FC_RCTL_P_RJT: /* port reject */
18447 case FC_RCTL_F_RJT: /* fabric reject */
18448 case FC_RCTL_P_BSY: /* port busy */
18449 case FC_RCTL_F_BSY: /* fabric busy to data frame */
18450 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
18451 case FC_RCTL_LCR: /* link credit reset */
18452 case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
18453 case FC_RCTL_END: /* end */
18455 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
18456 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
18457 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
18458 return lpfc_fc_frame_check(phba, fc_hdr);
18463 switch (fc_hdr->fh_type) {
18476 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
18477 "2538 Received frame rctl:x%x, type:x%x, "
18478 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
18479 fc_hdr->fh_r_ctl, fc_hdr->fh_type,
18480 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
18481 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
18482 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
18483 be32_to_cpu(header[6]));
18486 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
18487 "2539 Dropped frame rctl:x%x type:x%x\n",
18488 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
18493 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
18494 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
18496 * This function processes the FC header to retrieve the VFI from the VF
18497 * header, if one exists. This function will return the VFI if one exists
18498 * or 0 if no VSAN Header exists.
18501 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
18503 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
18505 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
18507 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
18511 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
18512 * @phba: Pointer to the HBA structure to search for the vport on
18513 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
18514 * @fcfi: The FC Fabric ID that the frame came from
18515 * @did: Destination ID to match against
18517 * This function searches the @phba for a vport that matches the content of the
18518 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
18519 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
18520 * returns the matching vport pointer or NULL if unable to match frame to a
18523 static struct lpfc_vport *
18524 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
18525 uint16_t fcfi, uint32_t did)
18527 struct lpfc_vport **vports;
18528 struct lpfc_vport *vport = NULL;
18531 if (did == Fabric_DID)
18532 return phba->pport;
18533 if ((phba->pport->fc_flag & FC_PT2PT) &&
18534 !(phba->link_state == LPFC_HBA_READY))
18535 return phba->pport;
18537 vports = lpfc_create_vport_work_array(phba);
18538 if (vports != NULL) {
18539 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
18540 if (phba->fcf.fcfi == fcfi &&
18541 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
18542 vports[i]->fc_myDID == did) {
18548 lpfc_destroy_vport_work_array(phba, vports);
18553 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
18554 * @vport: The vport to work on.
18556 * This function updates the receive sequence time stamp for this vport. The
18557 * receive sequence time stamp indicates the time that the last frame of the
18558 * the sequence that has been idle for the longest amount of time was received.
18559 * the driver uses this time stamp to indicate if any received sequences have
18563 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
18565 struct lpfc_dmabuf *h_buf;
18566 struct hbq_dmabuf *dmabuf = NULL;
18568 /* get the oldest sequence on the rcv list */
18569 h_buf = list_get_first(&vport->rcv_buffer_list,
18570 struct lpfc_dmabuf, list);
18573 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18574 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
18578 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
18579 * @vport: The vport that the received sequences were sent to.
18581 * This function cleans up all outstanding received sequences. This is called
18582 * by the driver when a link event or user action invalidates all the received
18586 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
18588 struct lpfc_dmabuf *h_buf, *hnext;
18589 struct lpfc_dmabuf *d_buf, *dnext;
18590 struct hbq_dmabuf *dmabuf = NULL;
18592 /* start with the oldest sequence on the rcv list */
18593 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
18594 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18595 list_del_init(&dmabuf->hbuf.list);
18596 list_for_each_entry_safe(d_buf, dnext,
18597 &dmabuf->dbuf.list, list) {
18598 list_del_init(&d_buf->list);
18599 lpfc_in_buf_free(vport->phba, d_buf);
18601 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
18606 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
18607 * @vport: The vport that the received sequences were sent to.
18609 * This function determines whether any received sequences have timed out by
18610 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
18611 * indicates that there is at least one timed out sequence this routine will
18612 * go through the received sequences one at a time from most inactive to most
18613 * active to determine which ones need to be cleaned up. Once it has determined
18614 * that a sequence needs to be cleaned up it will simply free up the resources
18615 * without sending an abort.
18618 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
18620 struct lpfc_dmabuf *h_buf, *hnext;
18621 struct lpfc_dmabuf *d_buf, *dnext;
18622 struct hbq_dmabuf *dmabuf = NULL;
18623 unsigned long timeout;
18624 int abort_count = 0;
18626 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
18627 vport->rcv_buffer_time_stamp);
18628 if (list_empty(&vport->rcv_buffer_list) ||
18629 time_before(jiffies, timeout))
18631 /* start with the oldest sequence on the rcv list */
18632 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
18633 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18634 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
18635 dmabuf->time_stamp);
18636 if (time_before(jiffies, timeout))
18639 list_del_init(&dmabuf->hbuf.list);
18640 list_for_each_entry_safe(d_buf, dnext,
18641 &dmabuf->dbuf.list, list) {
18642 list_del_init(&d_buf->list);
18643 lpfc_in_buf_free(vport->phba, d_buf);
18645 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
18648 lpfc_update_rcv_time_stamp(vport);
18652 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
18653 * @vport: pointer to a vitural port
18654 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
18656 * This function searches through the existing incomplete sequences that have
18657 * been sent to this @vport. If the frame matches one of the incomplete
18658 * sequences then the dbuf in the @dmabuf is added to the list of frames that
18659 * make up that sequence. If no sequence is found that matches this frame then
18660 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
18661 * This function returns a pointer to the first dmabuf in the sequence list that
18662 * the frame was linked to.
18664 static struct hbq_dmabuf *
18665 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
18667 struct fc_frame_header *new_hdr;
18668 struct fc_frame_header *temp_hdr;
18669 struct lpfc_dmabuf *d_buf;
18670 struct lpfc_dmabuf *h_buf;
18671 struct hbq_dmabuf *seq_dmabuf = NULL;
18672 struct hbq_dmabuf *temp_dmabuf = NULL;
18675 INIT_LIST_HEAD(&dmabuf->dbuf.list);
18676 dmabuf->time_stamp = jiffies;
18677 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18679 /* Use the hdr_buf to find the sequence that this frame belongs to */
18680 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
18681 temp_hdr = (struct fc_frame_header *)h_buf->virt;
18682 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
18683 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
18684 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
18686 /* found a pending sequence that matches this frame */
18687 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18692 * This indicates first frame received for this sequence.
18693 * Queue the buffer on the vport's rcv_buffer_list.
18695 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
18696 lpfc_update_rcv_time_stamp(vport);
18699 temp_hdr = seq_dmabuf->hbuf.virt;
18700 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
18701 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
18702 list_del_init(&seq_dmabuf->hbuf.list);
18703 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
18704 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
18705 lpfc_update_rcv_time_stamp(vport);
18708 /* move this sequence to the tail to indicate a young sequence */
18709 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
18710 seq_dmabuf->time_stamp = jiffies;
18711 lpfc_update_rcv_time_stamp(vport);
18712 if (list_empty(&seq_dmabuf->dbuf.list)) {
18713 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
18716 /* find the correct place in the sequence to insert this frame */
18717 d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
18719 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
18720 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
18722 * If the frame's sequence count is greater than the frame on
18723 * the list then insert the frame right after this frame
18725 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
18726 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
18727 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
18732 if (&d_buf->list == &seq_dmabuf->dbuf.list)
18734 d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
18743 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
18744 * @vport: pointer to a vitural port
18745 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18747 * This function tries to abort from the partially assembed sequence, described
18748 * by the information from basic abbort @dmabuf. It checks to see whether such
18749 * partially assembled sequence held by the driver. If so, it shall free up all
18750 * the frames from the partially assembled sequence.
18753 * true -- if there is matching partially assembled sequence present and all
18754 * the frames freed with the sequence;
18755 * false -- if there is no matching partially assembled sequence present so
18756 * nothing got aborted in the lower layer driver
18759 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
18760 struct hbq_dmabuf *dmabuf)
18762 struct fc_frame_header *new_hdr;
18763 struct fc_frame_header *temp_hdr;
18764 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
18765 struct hbq_dmabuf *seq_dmabuf = NULL;
18767 /* Use the hdr_buf to find the sequence that matches this frame */
18768 INIT_LIST_HEAD(&dmabuf->dbuf.list);
18769 INIT_LIST_HEAD(&dmabuf->hbuf.list);
18770 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18771 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
18772 temp_hdr = (struct fc_frame_header *)h_buf->virt;
18773 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
18774 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
18775 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
18777 /* found a pending sequence that matches this frame */
18778 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18782 /* Free up all the frames from the partially assembled sequence */
18784 list_for_each_entry_safe(d_buf, n_buf,
18785 &seq_dmabuf->dbuf.list, list) {
18786 list_del_init(&d_buf->list);
18787 lpfc_in_buf_free(vport->phba, d_buf);
18795 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
18796 * @vport: pointer to a vitural port
18797 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18799 * This function tries to abort from the assembed sequence from upper level
18800 * protocol, described by the information from basic abbort @dmabuf. It
18801 * checks to see whether such pending context exists at upper level protocol.
18802 * If so, it shall clean up the pending context.
18805 * true -- if there is matching pending context of the sequence cleaned
18807 * false -- if there is no matching pending context of the sequence present
18811 lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
18813 struct lpfc_hba *phba = vport->phba;
18816 /* Accepting abort at ulp with SLI4 only */
18817 if (phba->sli_rev < LPFC_SLI_REV4)
18820 /* Register all caring upper level protocols to attend abort */
18821 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
18829 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
18830 * @phba: Pointer to HBA context object.
18831 * @cmd_iocbq: pointer to the command iocbq structure.
18832 * @rsp_iocbq: pointer to the response iocbq structure.
18834 * This function handles the sequence abort response iocb command complete
18835 * event. It properly releases the memory allocated to the sequence abort
18839 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
18840 struct lpfc_iocbq *cmd_iocbq,
18841 struct lpfc_iocbq *rsp_iocbq)
18843 struct lpfc_nodelist *ndlp;
18846 ndlp = (struct lpfc_nodelist *)cmd_iocbq->context1;
18847 lpfc_nlp_put(ndlp);
18848 lpfc_sli_release_iocbq(phba, cmd_iocbq);
18851 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
18852 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
18853 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18854 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
18855 rsp_iocbq->iocb.ulpStatus,
18856 rsp_iocbq->iocb.un.ulpWord[4]);
18860 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
18861 * @phba: Pointer to HBA context object.
18862 * @xri: xri id in transaction.
18864 * This function validates the xri maps to the known range of XRIs allocated an
18865 * used by the driver.
18868 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
18873 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
18874 if (xri == phba->sli4_hba.xri_ids[i])
18881 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
18882 * @vport: pointer to a virtual port.
18883 * @fc_hdr: pointer to a FC frame header.
18884 * @aborted: was the partially assembled receive sequence successfully aborted
18886 * This function sends a basic response to a previous unsol sequence abort
18887 * event after aborting the sequence handling.
18890 lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
18891 struct fc_frame_header *fc_hdr, bool aborted)
18893 struct lpfc_hba *phba = vport->phba;
18894 struct lpfc_iocbq *ctiocb = NULL;
18895 struct lpfc_nodelist *ndlp;
18896 uint16_t oxid, rxid, xri, lxri;
18897 uint32_t sid, fctl;
18901 if (!lpfc_is_link_up(phba))
18904 sid = sli4_sid_from_fc_hdr(fc_hdr);
18905 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
18906 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
18908 ndlp = lpfc_findnode_did(vport, sid);
18910 ndlp = lpfc_nlp_init(vport, sid);
18912 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
18913 "1268 Failed to allocate ndlp for "
18914 "oxid:x%x SID:x%x\n", oxid, sid);
18917 /* Put ndlp onto pport node list */
18918 lpfc_enqueue_node(vport, ndlp);
18921 /* Allocate buffer for rsp iocb */
18922 ctiocb = lpfc_sli_get_iocbq(phba);
18926 /* Extract the F_CTL field from FC_HDR */
18927 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
18929 icmd = &ctiocb->iocb;
18930 icmd->un.xseq64.bdl.bdeSize = 0;
18931 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
18932 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
18933 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC;
18934 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS;
18936 /* Fill in the rest of iocb fields */
18937 icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX;
18938 icmd->ulpBdeCount = 0;
18940 icmd->ulpClass = CLASS3;
18941 icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
18942 ctiocb->context1 = lpfc_nlp_get(ndlp);
18943 if (!ctiocb->context1) {
18944 lpfc_sli_release_iocbq(phba, ctiocb);
18948 ctiocb->vport = phba->pport;
18949 ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
18950 ctiocb->sli4_lxritag = NO_XRI;
18951 ctiocb->sli4_xritag = NO_XRI;
18953 if (fctl & FC_FC_EX_CTX)
18954 /* Exchange responder sent the abort so we
18960 lxri = lpfc_sli4_xri_inrange(phba, xri);
18961 if (lxri != NO_XRI)
18962 lpfc_set_rrq_active(phba, ndlp, lxri,
18963 (xri == oxid) ? rxid : oxid, 0);
18964 /* For BA_ABTS from exchange responder, if the logical xri with
18965 * the oxid maps to the FCP XRI range, the port no longer has
18966 * that exchange context, send a BLS_RJT. Override the IOCB for
18969 if ((fctl & FC_FC_EX_CTX) &&
18970 (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
18971 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
18972 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
18973 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
18974 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
18977 /* If BA_ABTS failed to abort a partially assembled receive sequence,
18978 * the driver no longer has that exchange, send a BLS_RJT. Override
18979 * the IOCB for a BA_RJT.
18981 if (aborted == false) {
18982 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT;
18983 bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0);
18984 bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID);
18985 bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE);
18988 if (fctl & FC_FC_EX_CTX) {
18989 /* ABTS sent by responder to CT exchange, construction
18990 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
18991 * field and RX_ID from ABTS for RX_ID field.
18993 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP);
18995 /* ABTS sent by initiator to CT exchange, construction
18996 * of BA_ACC will need to allocate a new XRI as for the
18999 bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT);
19001 bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid);
19002 bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid);
19004 /* Xmit CT abts response on exchange <xid> */
19005 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
19006 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
19007 icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state);
19009 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
19010 if (rc == IOCB_ERROR) {
19011 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
19012 "2925 Failed to issue CT ABTS RSP x%x on "
19013 "xri x%x, Data x%x\n",
19014 icmd->un.xseq64.w5.hcsw.Rctl, oxid,
19016 lpfc_nlp_put(ndlp);
19017 ctiocb->context1 = NULL;
19018 lpfc_sli_release_iocbq(phba, ctiocb);
19023 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
19024 * @vport: Pointer to the vport on which this sequence was received
19025 * @dmabuf: pointer to a dmabuf that describes the FC sequence
19027 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
19028 * receive sequence is only partially assembed by the driver, it shall abort
19029 * the partially assembled frames for the sequence. Otherwise, if the
19030 * unsolicited receive sequence has been completely assembled and passed to
19031 * the Upper Layer Protocol (ULP), it then mark the per oxid status for the
19032 * unsolicited sequence has been aborted. After that, it will issue a basic
19033 * accept to accept the abort.
19036 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
19037 struct hbq_dmabuf *dmabuf)
19039 struct lpfc_hba *phba = vport->phba;
19040 struct fc_frame_header fc_hdr;
19044 /* Make a copy of fc_hdr before the dmabuf being released */
19045 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
19046 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
19048 if (fctl & FC_FC_EX_CTX) {
19049 /* ABTS by responder to exchange, no cleanup needed */
19052 /* ABTS by initiator to exchange, need to do cleanup */
19053 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
19054 if (aborted == false)
19055 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
19057 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19059 if (phba->nvmet_support) {
19060 lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
19064 /* Respond with BA_ACC or BA_RJT accordingly */
19065 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
19069 * lpfc_seq_complete - Indicates if a sequence is complete
19070 * @dmabuf: pointer to a dmabuf that describes the FC sequence
19072 * This function checks the sequence, starting with the frame described by
19073 * @dmabuf, to see if all the frames associated with this sequence are present.
19074 * the frames associated with this sequence are linked to the @dmabuf using the
19075 * dbuf list. This function looks for two major things. 1) That the first frame
19076 * has a sequence count of zero. 2) There is a frame with last frame of sequence
19077 * set. 3) That there are no holes in the sequence count. The function will
19078 * return 1 when the sequence is complete, otherwise it will return 0.
19081 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
19083 struct fc_frame_header *hdr;
19084 struct lpfc_dmabuf *d_buf;
19085 struct hbq_dmabuf *seq_dmabuf;
19089 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
19090 /* make sure first fame of sequence has a sequence count of zero */
19091 if (hdr->fh_seq_cnt != seq_count)
19093 fctl = (hdr->fh_f_ctl[0] << 16 |
19094 hdr->fh_f_ctl[1] << 8 |
19096 /* If last frame of sequence we can return success. */
19097 if (fctl & FC_FC_END_SEQ)
19099 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
19100 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
19101 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
19102 /* If there is a hole in the sequence count then fail. */
19103 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
19105 fctl = (hdr->fh_f_ctl[0] << 16 |
19106 hdr->fh_f_ctl[1] << 8 |
19108 /* If last frame of sequence we can return success. */
19109 if (fctl & FC_FC_END_SEQ)
19116 * lpfc_prep_seq - Prep sequence for ULP processing
19117 * @vport: Pointer to the vport on which this sequence was received
19118 * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence
19120 * This function takes a sequence, described by a list of frames, and creates
19121 * a list of iocbq structures to describe the sequence. This iocbq list will be
19122 * used to issue to the generic unsolicited sequence handler. This routine
19123 * returns a pointer to the first iocbq in the list. If the function is unable
19124 * to allocate an iocbq then it throw out the received frames that were not
19125 * able to be described and return a pointer to the first iocbq. If unable to
19126 * allocate any iocbqs (including the first) this function will return NULL.
19128 static struct lpfc_iocbq *
19129 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
19131 struct hbq_dmabuf *hbq_buf;
19132 struct lpfc_dmabuf *d_buf, *n_buf;
19133 struct lpfc_iocbq *first_iocbq, *iocbq;
19134 struct fc_frame_header *fc_hdr;
19136 uint32_t len, tot_len;
19137 struct ulp_bde64 *pbde;
19139 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
19140 /* remove from receive buffer list */
19141 list_del_init(&seq_dmabuf->hbuf.list);
19142 lpfc_update_rcv_time_stamp(vport);
19143 /* get the Remote Port's SID */
19144 sid = sli4_sid_from_fc_hdr(fc_hdr);
19146 /* Get an iocbq struct to fill in. */
19147 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
19149 /* Initialize the first IOCB. */
19150 first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0;
19151 first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS;
19152 first_iocbq->vport = vport;
19154 /* Check FC Header to see what TYPE of frame we are rcv'ing */
19155 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
19156 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX;
19157 first_iocbq->iocb.un.rcvels.parmRo =
19158 sli4_did_from_fc_hdr(fc_hdr);
19159 first_iocbq->iocb.ulpPU = PARM_NPIV_DID;
19161 first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX;
19162 first_iocbq->iocb.ulpContext = NO_XRI;
19163 first_iocbq->iocb.unsli3.rcvsli3.ox_id =
19164 be16_to_cpu(fc_hdr->fh_ox_id);
19165 /* iocbq is prepped for internal consumption. Physical vpi. */
19166 first_iocbq->iocb.unsli3.rcvsli3.vpi =
19167 vport->phba->vpi_ids[vport->vpi];
19168 /* put the first buffer into the first IOCBq */
19169 tot_len = bf_get(lpfc_rcqe_length,
19170 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
19172 first_iocbq->context2 = &seq_dmabuf->dbuf;
19173 first_iocbq->context3 = NULL;
19174 first_iocbq->iocb.ulpBdeCount = 1;
19175 if (tot_len > LPFC_DATA_BUF_SIZE)
19176 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize =
19177 LPFC_DATA_BUF_SIZE;
19179 first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = tot_len;
19181 first_iocbq->iocb.un.rcvels.remoteID = sid;
19183 first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
19185 iocbq = first_iocbq;
19187 * Each IOCBq can have two Buffers assigned, so go through the list
19188 * of buffers for this sequence and save two buffers in each IOCBq
19190 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
19192 lpfc_in_buf_free(vport->phba, d_buf);
19195 if (!iocbq->context3) {
19196 iocbq->context3 = d_buf;
19197 iocbq->iocb.ulpBdeCount++;
19198 /* We need to get the size out of the right CQE */
19199 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
19200 len = bf_get(lpfc_rcqe_length,
19201 &hbq_buf->cq_event.cqe.rcqe_cmpl);
19202 pbde = (struct ulp_bde64 *)
19203 &iocbq->iocb.unsli3.sli3Words[4];
19204 if (len > LPFC_DATA_BUF_SIZE)
19205 pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE;
19207 pbde->tus.f.bdeSize = len;
19209 iocbq->iocb.unsli3.rcvsli3.acc_len += len;
19212 iocbq = lpfc_sli_get_iocbq(vport->phba);
19215 first_iocbq->iocb.ulpStatus =
19216 IOSTAT_FCP_RSP_ERROR;
19217 first_iocbq->iocb.un.ulpWord[4] =
19218 IOERR_NO_RESOURCES;
19220 lpfc_in_buf_free(vport->phba, d_buf);
19223 /* We need to get the size out of the right CQE */
19224 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
19225 len = bf_get(lpfc_rcqe_length,
19226 &hbq_buf->cq_event.cqe.rcqe_cmpl);
19227 iocbq->context2 = d_buf;
19228 iocbq->context3 = NULL;
19229 iocbq->iocb.ulpBdeCount = 1;
19230 if (len > LPFC_DATA_BUF_SIZE)
19231 iocbq->iocb.un.cont64[0].tus.f.bdeSize =
19232 LPFC_DATA_BUF_SIZE;
19234 iocbq->iocb.un.cont64[0].tus.f.bdeSize = len;
19237 iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len;
19239 iocbq->iocb.un.rcvels.remoteID = sid;
19240 list_add_tail(&iocbq->list, &first_iocbq->list);
19243 /* Free the sequence's header buffer */
19245 lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf);
19247 return first_iocbq;
19251 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
19252 struct hbq_dmabuf *seq_dmabuf)
19254 struct fc_frame_header *fc_hdr;
19255 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
19256 struct lpfc_hba *phba = vport->phba;
19258 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
19259 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
19261 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19262 "2707 Ring %d handler: Failed to allocate "
19263 "iocb Rctl x%x Type x%x received\n",
19265 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
19268 if (!lpfc_complete_unsol_iocb(phba,
19269 phba->sli4_hba.els_wq->pring,
19270 iocbq, fc_hdr->fh_r_ctl,
19272 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19273 "2540 Ring %d handler: unexpected Rctl "
19274 "x%x Type x%x received\n",
19276 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
19278 /* Free iocb created in lpfc_prep_seq */
19279 list_for_each_entry_safe(curr_iocb, next_iocb,
19280 &iocbq->list, list) {
19281 list_del_init(&curr_iocb->list);
19282 lpfc_sli_release_iocbq(phba, curr_iocb);
19284 lpfc_sli_release_iocbq(phba, iocbq);
19288 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
19289 struct lpfc_iocbq *rspiocb)
19291 struct lpfc_dmabuf *pcmd = cmdiocb->context2;
19293 if (pcmd && pcmd->virt)
19294 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
19296 lpfc_sli_release_iocbq(phba, cmdiocb);
19297 lpfc_drain_txq(phba);
19301 lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
19302 struct hbq_dmabuf *dmabuf)
19304 struct fc_frame_header *fc_hdr;
19305 struct lpfc_hba *phba = vport->phba;
19306 struct lpfc_iocbq *iocbq = NULL;
19307 union lpfc_wqe *wqe;
19308 struct lpfc_dmabuf *pcmd = NULL;
19309 uint32_t frame_len;
19311 unsigned long iflags;
19313 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
19314 frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
19316 /* Send the received frame back */
19317 iocbq = lpfc_sli_get_iocbq(phba);
19319 /* Queue cq event and wakeup worker thread to process it */
19320 spin_lock_irqsave(&phba->hbalock, iflags);
19321 list_add_tail(&dmabuf->cq_event.list,
19322 &phba->sli4_hba.sp_queue_event);
19323 phba->hba_flag |= HBA_SP_QUEUE_EVT;
19324 spin_unlock_irqrestore(&phba->hbalock, iflags);
19325 lpfc_worker_wake_up(phba);
19329 /* Allocate buffer for command payload */
19330 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
19332 pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
19334 if (!pcmd || !pcmd->virt)
19337 INIT_LIST_HEAD(&pcmd->list);
19339 /* copyin the payload */
19340 memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
19342 /* fill in BDE's for command */
19343 iocbq->iocb.un.xseq64.bdl.addrHigh = putPaddrHigh(pcmd->phys);
19344 iocbq->iocb.un.xseq64.bdl.addrLow = putPaddrLow(pcmd->phys);
19345 iocbq->iocb.un.xseq64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
19346 iocbq->iocb.un.xseq64.bdl.bdeSize = frame_len;
19348 iocbq->context2 = pcmd;
19349 iocbq->vport = vport;
19350 iocbq->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
19351 iocbq->iocb_flag |= LPFC_USE_FCPWQIDX;
19354 * Setup rest of the iocb as though it were a WQE
19355 * Build the SEND_FRAME WQE
19357 wqe = (union lpfc_wqe *)&iocbq->iocb;
19359 wqe->send_frame.frame_len = frame_len;
19360 wqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((uint32_t *)fc_hdr));
19361 wqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((uint32_t *)fc_hdr + 1));
19362 wqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((uint32_t *)fc_hdr + 2));
19363 wqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((uint32_t *)fc_hdr + 3));
19364 wqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((uint32_t *)fc_hdr + 4));
19365 wqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((uint32_t *)fc_hdr + 5));
19367 iocbq->iocb.ulpCommand = CMD_SEND_FRAME;
19368 iocbq->iocb.ulpLe = 1;
19369 iocbq->iocb_cmpl = lpfc_sli4_mds_loopback_cmpl;
19370 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
19371 if (rc == IOCB_ERROR)
19374 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19378 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
19379 "2023 Unable to process MDS loopback frame\n");
19380 if (pcmd && pcmd->virt)
19381 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
19384 lpfc_sli_release_iocbq(phba, iocbq);
19385 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19389 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
19390 * @phba: Pointer to HBA context object.
19391 * @dmabuf: Pointer to a dmabuf that describes the FC sequence.
19393 * This function is called with no lock held. This function processes all
19394 * the received buffers and gives it to upper layers when a received buffer
19395 * indicates that it is the final frame in the sequence. The interrupt
19396 * service routine processes received buffers at interrupt contexts.
19397 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
19398 * appropriate receive function when the final frame in a sequence is received.
19401 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
19402 struct hbq_dmabuf *dmabuf)
19404 struct hbq_dmabuf *seq_dmabuf;
19405 struct fc_frame_header *fc_hdr;
19406 struct lpfc_vport *vport;
19410 /* Process each received buffer */
19411 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
19413 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
19414 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
19415 vport = phba->pport;
19416 /* Handle MDS Loopback frames */
19417 if (!(phba->pport->load_flag & FC_UNLOADING))
19418 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
19420 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19424 /* check to see if this a valid type of frame */
19425 if (lpfc_fc_frame_check(phba, fc_hdr)) {
19426 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19430 if ((bf_get(lpfc_cqe_code,
19431 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
19432 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
19433 &dmabuf->cq_event.cqe.rcqe_cmpl);
19435 fcfi = bf_get(lpfc_rcqe_fcf_id,
19436 &dmabuf->cq_event.cqe.rcqe_cmpl);
19438 if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
19439 vport = phba->pport;
19440 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
19441 "2023 MDS Loopback %d bytes\n",
19442 bf_get(lpfc_rcqe_length,
19443 &dmabuf->cq_event.cqe.rcqe_cmpl));
19444 /* Handle MDS Loopback frames */
19445 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
19449 /* d_id this frame is directed to */
19450 did = sli4_did_from_fc_hdr(fc_hdr);
19452 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
19454 /* throw out the frame */
19455 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19459 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
19460 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
19461 (did != Fabric_DID)) {
19463 * Throw out the frame if we are not pt2pt.
19464 * The pt2pt protocol allows for discovery frames
19465 * to be received without a registered VPI.
19467 if (!(vport->fc_flag & FC_PT2PT) ||
19468 (phba->link_state == LPFC_HBA_READY)) {
19469 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19474 /* Handle the basic abort sequence (BA_ABTS) event */
19475 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
19476 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
19480 /* Link this frame */
19481 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
19483 /* unable to add frame to vport - throw it out */
19484 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19487 /* If not last frame in sequence continue processing frames. */
19488 if (!lpfc_seq_complete(seq_dmabuf))
19491 /* Send the complete sequence to the upper layer protocol */
19492 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
19496 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
19497 * @phba: pointer to lpfc hba data structure.
19499 * This routine is invoked to post rpi header templates to the
19500 * HBA consistent with the SLI-4 interface spec. This routine
19501 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
19502 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
19504 * This routine does not require any locks. It's usage is expected
19505 * to be driver load or reset recovery when the driver is
19510 * -EIO - The mailbox failed to complete successfully.
19511 * When this error occurs, the driver is not guaranteed
19512 * to have any rpi regions posted to the device and
19513 * must either attempt to repost the regions or take a
19517 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
19519 struct lpfc_rpi_hdr *rpi_page;
19523 /* SLI4 ports that support extents do not require RPI headers. */
19524 if (!phba->sli4_hba.rpi_hdrs_in_use)
19526 if (phba->sli4_hba.extents_in_use)
19529 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
19531 * Assign the rpi headers a physical rpi only if the driver
19532 * has not initialized those resources. A port reset only
19533 * needs the headers posted.
19535 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
19537 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
19539 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
19540 if (rc != MBX_SUCCESS) {
19541 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19542 "2008 Error %d posting all rpi "
19550 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
19551 LPFC_RPI_RSRC_RDY);
19556 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
19557 * @phba: pointer to lpfc hba data structure.
19558 * @rpi_page: pointer to the rpi memory region.
19560 * This routine is invoked to post a single rpi header to the
19561 * HBA consistent with the SLI-4 interface spec. This memory region
19562 * maps up to 64 rpi context regions.
19566 * -ENOMEM - No available memory
19567 * -EIO - The mailbox failed to complete successfully.
19570 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
19572 LPFC_MBOXQ_t *mboxq;
19573 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
19575 uint32_t shdr_status, shdr_add_status;
19576 union lpfc_sli4_cfg_shdr *shdr;
19578 /* SLI4 ports that support extents do not require RPI headers. */
19579 if (!phba->sli4_hba.rpi_hdrs_in_use)
19581 if (phba->sli4_hba.extents_in_use)
19584 /* The port is notified of the header region via a mailbox command. */
19585 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19587 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19588 "2001 Unable to allocate memory for issuing "
19589 "SLI_CONFIG_SPECIAL mailbox command\n");
19593 /* Post all rpi memory regions to the port. */
19594 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
19595 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
19596 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
19597 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
19598 sizeof(struct lpfc_sli4_cfg_mhdr),
19599 LPFC_SLI4_MBX_EMBED);
19602 /* Post the physical rpi to the port for this rpi header. */
19603 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
19604 rpi_page->start_rpi);
19605 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
19606 hdr_tmpl, rpi_page->page_count);
19608 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
19609 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
19610 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
19611 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
19612 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
19613 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
19614 mempool_free(mboxq, phba->mbox_mem_pool);
19615 if (shdr_status || shdr_add_status || rc) {
19616 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19617 "2514 POST_RPI_HDR mailbox failed with "
19618 "status x%x add_status x%x, mbx status x%x\n",
19619 shdr_status, shdr_add_status, rc);
19623 * The next_rpi stores the next logical module-64 rpi value used
19624 * to post physical rpis in subsequent rpi postings.
19626 spin_lock_irq(&phba->hbalock);
19627 phba->sli4_hba.next_rpi = rpi_page->next_rpi;
19628 spin_unlock_irq(&phba->hbalock);
19634 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
19635 * @phba: pointer to lpfc hba data structure.
19637 * This routine is invoked to post rpi header templates to the
19638 * HBA consistent with the SLI-4 interface spec. This routine
19639 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
19640 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
19643 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
19644 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
19647 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
19650 uint16_t max_rpi, rpi_limit;
19651 uint16_t rpi_remaining, lrpi = 0;
19652 struct lpfc_rpi_hdr *rpi_hdr;
19653 unsigned long iflag;
19656 * Fetch the next logical rpi. Because this index is logical,
19657 * the driver starts at 0 each time.
19659 spin_lock_irqsave(&phba->hbalock, iflag);
19660 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
19661 rpi_limit = phba->sli4_hba.next_rpi;
19663 rpi = find_first_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit);
19664 if (rpi >= rpi_limit)
19665 rpi = LPFC_RPI_ALLOC_ERROR;
19667 set_bit(rpi, phba->sli4_hba.rpi_bmask);
19668 phba->sli4_hba.max_cfg_param.rpi_used++;
19669 phba->sli4_hba.rpi_count++;
19671 lpfc_printf_log(phba, KERN_INFO,
19672 LOG_NODE | LOG_DISCOVERY,
19673 "0001 Allocated rpi:x%x max:x%x lim:x%x\n",
19674 (int) rpi, max_rpi, rpi_limit);
19677 * Don't try to allocate more rpi header regions if the device limit
19678 * has been exhausted.
19680 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
19681 (phba->sli4_hba.rpi_count >= max_rpi)) {
19682 spin_unlock_irqrestore(&phba->hbalock, iflag);
19687 * RPI header postings are not required for SLI4 ports capable of
19690 if (!phba->sli4_hba.rpi_hdrs_in_use) {
19691 spin_unlock_irqrestore(&phba->hbalock, iflag);
19696 * If the driver is running low on rpi resources, allocate another
19697 * page now. Note that the next_rpi value is used because
19698 * it represents how many are actually in use whereas max_rpi notes
19699 * how many are supported max by the device.
19701 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
19702 spin_unlock_irqrestore(&phba->hbalock, iflag);
19703 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
19704 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
19706 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19707 "2002 Error Could not grow rpi "
19710 lrpi = rpi_hdr->start_rpi;
19711 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
19712 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
19720 * __lpfc_sli4_free_rpi - Release an rpi for reuse.
19721 * @phba: pointer to lpfc hba data structure.
19722 * @rpi: rpi to free
19724 * This routine is invoked to release an rpi to the pool of
19725 * available rpis maintained by the driver.
19728 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
19731 * if the rpi value indicates a prior unreg has already
19732 * been done, skip the unreg.
19734 if (rpi == LPFC_RPI_ALLOC_ERROR)
19737 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
19738 phba->sli4_hba.rpi_count--;
19739 phba->sli4_hba.max_cfg_param.rpi_used--;
19741 lpfc_printf_log(phba, KERN_INFO,
19742 LOG_NODE | LOG_DISCOVERY,
19743 "2016 rpi %x not inuse\n",
19749 * lpfc_sli4_free_rpi - Release an rpi for reuse.
19750 * @phba: pointer to lpfc hba data structure.
19751 * @rpi: rpi to free
19753 * This routine is invoked to release an rpi to the pool of
19754 * available rpis maintained by the driver.
19757 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
19759 spin_lock_irq(&phba->hbalock);
19760 __lpfc_sli4_free_rpi(phba, rpi);
19761 spin_unlock_irq(&phba->hbalock);
19765 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
19766 * @phba: pointer to lpfc hba data structure.
19768 * This routine is invoked to remove the memory region that
19769 * provided rpi via a bitmask.
19772 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
19774 kfree(phba->sli4_hba.rpi_bmask);
19775 kfree(phba->sli4_hba.rpi_ids);
19776 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
19780 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
19781 * @ndlp: pointer to lpfc nodelist data structure.
19782 * @cmpl: completion call-back.
19783 * @arg: data to load as MBox 'caller buffer information'
19785 * This routine is invoked to remove the memory region that
19786 * provided rpi via a bitmask.
19789 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
19790 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
19792 LPFC_MBOXQ_t *mboxq;
19793 struct lpfc_hba *phba = ndlp->phba;
19796 /* The port is notified of the header region via a mailbox command. */
19797 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19801 /* If cmpl assigned, then this nlp_get pairs with
19802 * lpfc_mbx_cmpl_resume_rpi.
19804 * Else cmpl is NULL, then this nlp_get pairs with
19805 * lpfc_sli_def_mbox_cmpl.
19807 if (!lpfc_nlp_get(ndlp)) {
19808 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19809 "2122 %s: Failed to get nlp ref\n",
19811 mempool_free(mboxq, phba->mbox_mem_pool);
19815 /* Post all rpi memory regions to the port. */
19816 lpfc_resume_rpi(mboxq, ndlp);
19818 mboxq->mbox_cmpl = cmpl;
19819 mboxq->ctx_buf = arg;
19821 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19822 mboxq->ctx_ndlp = ndlp;
19823 mboxq->vport = ndlp->vport;
19824 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19825 if (rc == MBX_NOT_FINISHED) {
19826 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19827 "2010 Resume RPI Mailbox failed "
19828 "status %d, mbxStatus x%x\n", rc,
19829 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
19830 lpfc_nlp_put(ndlp);
19831 mempool_free(mboxq, phba->mbox_mem_pool);
19838 * lpfc_sli4_init_vpi - Initialize a vpi with the port
19839 * @vport: Pointer to the vport for which the vpi is being initialized
19841 * This routine is invoked to activate a vpi with the port.
19845 * -Evalue otherwise
19848 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
19850 LPFC_MBOXQ_t *mboxq;
19852 int retval = MBX_SUCCESS;
19854 struct lpfc_hba *phba = vport->phba;
19855 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19858 lpfc_init_vpi(phba, mboxq, vport->vpi);
19859 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
19860 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
19861 if (rc != MBX_SUCCESS) {
19862 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
19863 "2022 INIT VPI Mailbox failed "
19864 "status %d, mbxStatus x%x\n", rc,
19865 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
19868 if (rc != MBX_TIMEOUT)
19869 mempool_free(mboxq, vport->phba->mbox_mem_pool);
19875 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
19876 * @phba: pointer to lpfc hba data structure.
19877 * @mboxq: Pointer to mailbox object.
19879 * This routine is invoked to manually add a single FCF record. The caller
19880 * must pass a completely initialized FCF_Record. This routine takes
19881 * care of the nonembedded mailbox operations.
19884 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
19887 union lpfc_sli4_cfg_shdr *shdr;
19888 uint32_t shdr_status, shdr_add_status;
19890 virt_addr = mboxq->sge_array->addr[0];
19891 /* The IOCTL status is embedded in the mailbox subheader. */
19892 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
19893 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
19894 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
19896 if ((shdr_status || shdr_add_status) &&
19897 (shdr_status != STATUS_FCF_IN_USE))
19898 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19899 "2558 ADD_FCF_RECORD mailbox failed with "
19900 "status x%x add_status x%x\n",
19901 shdr_status, shdr_add_status);
19903 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19907 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
19908 * @phba: pointer to lpfc hba data structure.
19909 * @fcf_record: pointer to the initialized fcf record to add.
19911 * This routine is invoked to manually add a single FCF record. The caller
19912 * must pass a completely initialized FCF_Record. This routine takes
19913 * care of the nonembedded mailbox operations.
19916 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
19919 LPFC_MBOXQ_t *mboxq;
19922 struct lpfc_mbx_sge sge;
19923 uint32_t alloc_len, req_len;
19926 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19928 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19929 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
19933 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
19936 /* Allocate DMA memory and set up the non-embedded mailbox command */
19937 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
19938 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
19939 req_len, LPFC_SLI4_MBX_NEMBED);
19940 if (alloc_len < req_len) {
19941 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19942 "2523 Allocated DMA memory size (x%x) is "
19943 "less than the requested DMA memory "
19944 "size (x%x)\n", alloc_len, req_len);
19945 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19950 * Get the first SGE entry from the non-embedded DMA memory. This
19951 * routine only uses a single SGE.
19953 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
19954 virt_addr = mboxq->sge_array->addr[0];
19956 * Configure the FCF record for FCFI 0. This is the driver's
19957 * hardcoded default and gets used in nonFIP mode.
19959 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
19960 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
19961 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
19964 * Copy the fcf_index and the FCF Record Data. The data starts after
19965 * the FCoE header plus word10. The data copy needs to be endian
19968 bytep += sizeof(uint32_t);
19969 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
19970 mboxq->vport = phba->pport;
19971 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
19972 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19973 if (rc == MBX_NOT_FINISHED) {
19974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19975 "2515 ADD_FCF_RECORD mailbox failed with "
19976 "status 0x%x\n", rc);
19977 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19986 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
19987 * @phba: pointer to lpfc hba data structure.
19988 * @fcf_record: pointer to the fcf record to write the default data.
19989 * @fcf_index: FCF table entry index.
19991 * This routine is invoked to build the driver's default FCF record. The
19992 * values used are hardcoded. This routine handles memory initialization.
19996 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
19997 struct fcf_record *fcf_record,
19998 uint16_t fcf_index)
20000 memset(fcf_record, 0, sizeof(struct fcf_record));
20001 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
20002 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
20003 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
20004 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
20005 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
20006 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
20007 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
20008 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
20009 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
20010 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
20011 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
20012 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
20013 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
20014 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
20015 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
20016 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
20017 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
20018 /* Set the VLAN bit map */
20019 if (phba->valid_vlan) {
20020 fcf_record->vlan_bitmap[phba->vlan_id / 8]
20021 = 1 << (phba->vlan_id % 8);
20026 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
20027 * @phba: pointer to lpfc hba data structure.
20028 * @fcf_index: FCF table entry offset.
20030 * This routine is invoked to scan the entire FCF table by reading FCF
20031 * record and processing it one at a time starting from the @fcf_index
20032 * for initial FCF discovery or fast FCF failover rediscovery.
20034 * Return 0 if the mailbox command is submitted successfully, none 0
20038 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
20041 LPFC_MBOXQ_t *mboxq;
20043 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
20044 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
20045 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20047 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20048 "2000 Failed to allocate mbox for "
20051 goto fail_fcf_scan;
20053 /* Construct the read FCF record mailbox command */
20054 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
20057 goto fail_fcf_scan;
20059 /* Issue the mailbox command asynchronously */
20060 mboxq->vport = phba->pport;
20061 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
20063 spin_lock_irq(&phba->hbalock);
20064 phba->hba_flag |= FCF_TS_INPROG;
20065 spin_unlock_irq(&phba->hbalock);
20067 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
20068 if (rc == MBX_NOT_FINISHED)
20071 /* Reset eligible FCF count for new scan */
20072 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
20073 phba->fcf.eligible_fcf_cnt = 0;
20079 lpfc_sli4_mbox_cmd_free(phba, mboxq);
20080 /* FCF scan failed, clear FCF_TS_INPROG flag */
20081 spin_lock_irq(&phba->hbalock);
20082 phba->hba_flag &= ~FCF_TS_INPROG;
20083 spin_unlock_irq(&phba->hbalock);
20089 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
20090 * @phba: pointer to lpfc hba data structure.
20091 * @fcf_index: FCF table entry offset.
20093 * This routine is invoked to read an FCF record indicated by @fcf_index
20094 * and to use it for FLOGI roundrobin FCF failover.
20096 * Return 0 if the mailbox command is submitted successfully, none 0
20100 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
20103 LPFC_MBOXQ_t *mboxq;
20105 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20107 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
20108 "2763 Failed to allocate mbox for "
20111 goto fail_fcf_read;
20113 /* Construct the read FCF record mailbox command */
20114 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
20117 goto fail_fcf_read;
20119 /* Issue the mailbox command asynchronously */
20120 mboxq->vport = phba->pport;
20121 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
20122 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
20123 if (rc == MBX_NOT_FINISHED)
20129 if (error && mboxq)
20130 lpfc_sli4_mbox_cmd_free(phba, mboxq);
20135 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
20136 * @phba: pointer to lpfc hba data structure.
20137 * @fcf_index: FCF table entry offset.
20139 * This routine is invoked to read an FCF record indicated by @fcf_index to
20140 * determine whether it's eligible for FLOGI roundrobin failover list.
20142 * Return 0 if the mailbox command is submitted successfully, none 0
20146 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
20149 LPFC_MBOXQ_t *mboxq;
20151 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20153 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
20154 "2758 Failed to allocate mbox for "
20157 goto fail_fcf_read;
20159 /* Construct the read FCF record mailbox command */
20160 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
20163 goto fail_fcf_read;
20165 /* Issue the mailbox command asynchronously */
20166 mboxq->vport = phba->pport;
20167 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
20168 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
20169 if (rc == MBX_NOT_FINISHED)
20175 if (error && mboxq)
20176 lpfc_sli4_mbox_cmd_free(phba, mboxq);
20181 * lpfc_check_next_fcf_pri_level
20182 * @phba: pointer to the lpfc_hba struct for this port.
20183 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
20184 * routine when the rr_bmask is empty. The FCF indecies are put into the
20185 * rr_bmask based on their priority level. Starting from the highest priority
20186 * to the lowest. The most likely FCF candidate will be in the highest
20187 * priority group. When this routine is called it searches the fcf_pri list for
20188 * next lowest priority group and repopulates the rr_bmask with only those
20191 * 1=success 0=failure
20194 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
20196 uint16_t next_fcf_pri;
20197 uint16_t last_index;
20198 struct lpfc_fcf_pri *fcf_pri;
20202 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
20203 LPFC_SLI4_FCF_TBL_INDX_MAX);
20204 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20205 "3060 Last IDX %d\n", last_index);
20207 /* Verify the priority list has 2 or more entries */
20208 spin_lock_irq(&phba->hbalock);
20209 if (list_empty(&phba->fcf.fcf_pri_list) ||
20210 list_is_singular(&phba->fcf.fcf_pri_list)) {
20211 spin_unlock_irq(&phba->hbalock);
20212 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20213 "3061 Last IDX %d\n", last_index);
20214 return 0; /* Empty rr list */
20216 spin_unlock_irq(&phba->hbalock);
20220 * Clear the rr_bmask and set all of the bits that are at this
20223 memset(phba->fcf.fcf_rr_bmask, 0,
20224 sizeof(*phba->fcf.fcf_rr_bmask));
20225 spin_lock_irq(&phba->hbalock);
20226 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
20227 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
20230 * the 1st priority that has not FLOGI failed
20231 * will be the highest.
20234 next_fcf_pri = fcf_pri->fcf_rec.priority;
20235 spin_unlock_irq(&phba->hbalock);
20236 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
20237 rc = lpfc_sli4_fcf_rr_index_set(phba,
20238 fcf_pri->fcf_rec.fcf_index);
20242 spin_lock_irq(&phba->hbalock);
20245 * if next_fcf_pri was not set above and the list is not empty then
20246 * we have failed flogis on all of them. So reset flogi failed
20247 * and start at the beginning.
20249 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
20250 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
20251 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
20253 * the 1st priority that has not FLOGI failed
20254 * will be the highest.
20257 next_fcf_pri = fcf_pri->fcf_rec.priority;
20258 spin_unlock_irq(&phba->hbalock);
20259 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
20260 rc = lpfc_sli4_fcf_rr_index_set(phba,
20261 fcf_pri->fcf_rec.fcf_index);
20265 spin_lock_irq(&phba->hbalock);
20269 spin_unlock_irq(&phba->hbalock);
20274 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
20275 * @phba: pointer to lpfc hba data structure.
20277 * This routine is to get the next eligible FCF record index in a round
20278 * robin fashion. If the next eligible FCF record index equals to the
20279 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
20280 * shall be returned, otherwise, the next eligible FCF record's index
20281 * shall be returned.
20284 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
20286 uint16_t next_fcf_index;
20289 /* Search start from next bit of currently registered FCF index */
20290 next_fcf_index = phba->fcf.current_rec.fcf_indx;
20293 /* Determine the next fcf index to check */
20294 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
20295 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
20296 LPFC_SLI4_FCF_TBL_INDX_MAX,
20299 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
20300 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
20302 * If we have wrapped then we need to clear the bits that
20303 * have been tested so that we can detect when we should
20304 * change the priority level.
20306 next_fcf_index = find_first_bit(phba->fcf.fcf_rr_bmask,
20307 LPFC_SLI4_FCF_TBL_INDX_MAX);
20311 /* Check roundrobin failover list empty condition */
20312 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
20313 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
20315 * If next fcf index is not found check if there are lower
20316 * Priority level fcf's in the fcf_priority list.
20317 * Set up the rr_bmask with all of the avaiable fcf bits
20318 * at that level and continue the selection process.
20320 if (lpfc_check_next_fcf_pri_level(phba))
20321 goto initial_priority;
20322 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
20323 "2844 No roundrobin failover FCF available\n");
20325 return LPFC_FCOE_FCF_NEXT_NONE;
20328 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
20329 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
20330 LPFC_FCF_FLOGI_FAILED) {
20331 if (list_is_singular(&phba->fcf.fcf_pri_list))
20332 return LPFC_FCOE_FCF_NEXT_NONE;
20334 goto next_priority;
20337 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20338 "2845 Get next roundrobin failover FCF (x%x)\n",
20341 return next_fcf_index;
20345 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
20346 * @phba: pointer to lpfc hba data structure.
20347 * @fcf_index: index into the FCF table to 'set'
20349 * This routine sets the FCF record index in to the eligible bmask for
20350 * roundrobin failover search. It checks to make sure that the index
20351 * does not go beyond the range of the driver allocated bmask dimension
20352 * before setting the bit.
20354 * Returns 0 if the index bit successfully set, otherwise, it returns
20358 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
20360 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
20361 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20362 "2610 FCF (x%x) reached driver's book "
20363 "keeping dimension:x%x\n",
20364 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
20367 /* Set the eligible FCF record index bmask */
20368 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
20370 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20371 "2790 Set FCF (x%x) to roundrobin FCF failover "
20372 "bmask\n", fcf_index);
20378 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
20379 * @phba: pointer to lpfc hba data structure.
20380 * @fcf_index: index into the FCF table to 'clear'
20382 * This routine clears the FCF record index from the eligible bmask for
20383 * roundrobin failover search. It checks to make sure that the index
20384 * does not go beyond the range of the driver allocated bmask dimension
20385 * before clearing the bit.
20388 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
20390 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
20391 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
20392 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20393 "2762 FCF (x%x) reached driver's book "
20394 "keeping dimension:x%x\n",
20395 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
20398 /* Clear the eligible FCF record index bmask */
20399 spin_lock_irq(&phba->hbalock);
20400 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
20402 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
20403 list_del_init(&fcf_pri->list);
20407 spin_unlock_irq(&phba->hbalock);
20408 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
20410 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20411 "2791 Clear FCF (x%x) from roundrobin failover "
20412 "bmask\n", fcf_index);
20416 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
20417 * @phba: pointer to lpfc hba data structure.
20418 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
20420 * This routine is the completion routine for the rediscover FCF table mailbox
20421 * command. If the mailbox command returned failure, it will try to stop the
20422 * FCF rediscover wait timer.
20425 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
20427 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
20428 uint32_t shdr_status, shdr_add_status;
20430 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
20432 shdr_status = bf_get(lpfc_mbox_hdr_status,
20433 &redisc_fcf->header.cfg_shdr.response);
20434 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
20435 &redisc_fcf->header.cfg_shdr.response);
20436 if (shdr_status || shdr_add_status) {
20437 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20438 "2746 Requesting for FCF rediscovery failed "
20439 "status x%x add_status x%x\n",
20440 shdr_status, shdr_add_status);
20441 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
20442 spin_lock_irq(&phba->hbalock);
20443 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
20444 spin_unlock_irq(&phba->hbalock);
20446 * CVL event triggered FCF rediscover request failed,
20447 * last resort to re-try current registered FCF entry.
20449 lpfc_retry_pport_discovery(phba);
20451 spin_lock_irq(&phba->hbalock);
20452 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
20453 spin_unlock_irq(&phba->hbalock);
20455 * DEAD FCF event triggered FCF rediscover request
20456 * failed, last resort to fail over as a link down
20457 * to FCF registration.
20459 lpfc_sli4_fcf_dead_failthrough(phba);
20462 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20463 "2775 Start FCF rediscover quiescent timer\n");
20465 * Start FCF rediscovery wait timer for pending FCF
20466 * before rescan FCF record table.
20468 lpfc_fcf_redisc_wait_start_timer(phba);
20471 mempool_free(mbox, phba->mbox_mem_pool);
20475 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
20476 * @phba: pointer to lpfc hba data structure.
20478 * This routine is invoked to request for rediscovery of the entire FCF table
20482 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
20484 LPFC_MBOXQ_t *mbox;
20485 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
20488 /* Cancel retry delay timers to all vports before FCF rediscover */
20489 lpfc_cancel_all_vport_retry_delay_timer(phba);
20491 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20493 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20494 "2745 Failed to allocate mbox for "
20495 "requesting FCF rediscover.\n");
20499 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
20500 sizeof(struct lpfc_sli4_cfg_mhdr));
20501 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
20502 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
20503 length, LPFC_SLI4_MBX_EMBED);
20505 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
20506 /* Set count to 0 for invalidating the entire FCF database */
20507 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
20509 /* Issue the mailbox command asynchronously */
20510 mbox->vport = phba->pport;
20511 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
20512 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
20514 if (rc == MBX_NOT_FINISHED) {
20515 mempool_free(mbox, phba->mbox_mem_pool);
20522 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
20523 * @phba: pointer to lpfc hba data structure.
20525 * This function is the failover routine as a last resort to the FCF DEAD
20526 * event when driver failed to perform fast FCF failover.
20529 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
20531 uint32_t link_state;
20534 * Last resort as FCF DEAD event failover will treat this as
20535 * a link down, but save the link state because we don't want
20536 * it to be changed to Link Down unless it is already down.
20538 link_state = phba->link_state;
20539 lpfc_linkdown(phba);
20540 phba->link_state = link_state;
20542 /* Unregister FCF if no devices connected to it */
20543 lpfc_unregister_unused_fcf(phba);
20547 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
20548 * @phba: pointer to lpfc hba data structure.
20549 * @rgn23_data: pointer to configure region 23 data.
20551 * This function gets SLI3 port configure region 23 data through memory dump
20552 * mailbox command. When it successfully retrieves data, the size of the data
20553 * will be returned, otherwise, 0 will be returned.
20556 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
20558 LPFC_MBOXQ_t *pmb = NULL;
20560 uint32_t offset = 0;
20566 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20568 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20569 "2600 failed to allocate mailbox memory\n");
20575 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
20576 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
20578 if (rc != MBX_SUCCESS) {
20579 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
20580 "2601 failed to read config "
20581 "region 23, rc 0x%x Status 0x%x\n",
20582 rc, mb->mbxStatus);
20583 mb->un.varDmp.word_cnt = 0;
20586 * dump mem may return a zero when finished or we got a
20587 * mailbox error, either way we are done.
20589 if (mb->un.varDmp.word_cnt == 0)
20592 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
20593 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
20595 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
20596 rgn23_data + offset,
20597 mb->un.varDmp.word_cnt);
20598 offset += mb->un.varDmp.word_cnt;
20599 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
20601 mempool_free(pmb, phba->mbox_mem_pool);
20606 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
20607 * @phba: pointer to lpfc hba data structure.
20608 * @rgn23_data: pointer to configure region 23 data.
20610 * This function gets SLI4 port configure region 23 data through memory dump
20611 * mailbox command. When it successfully retrieves data, the size of the data
20612 * will be returned, otherwise, 0 will be returned.
20615 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
20617 LPFC_MBOXQ_t *mboxq = NULL;
20618 struct lpfc_dmabuf *mp = NULL;
20619 struct lpfc_mqe *mqe;
20620 uint32_t data_length = 0;
20626 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20628 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20629 "3105 failed to allocate mailbox memory\n");
20633 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
20635 mqe = &mboxq->u.mqe;
20636 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
20637 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
20640 data_length = mqe->un.mb_words[5];
20641 if (data_length == 0)
20643 if (data_length > DMP_RGN23_SIZE) {
20647 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
20649 mempool_free(mboxq, phba->mbox_mem_pool);
20651 lpfc_mbuf_free(phba, mp->virt, mp->phys);
20654 return data_length;
20658 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
20659 * @phba: pointer to lpfc hba data structure.
20661 * This function read region 23 and parse TLV for port status to
20662 * decide if the user disaled the port. If the TLV indicates the
20663 * port is disabled, the hba_flag is set accordingly.
20666 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
20668 uint8_t *rgn23_data = NULL;
20669 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
20670 uint32_t offset = 0;
20672 /* Get adapter Region 23 data */
20673 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
20677 if (phba->sli_rev < LPFC_SLI_REV4)
20678 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
20680 if_type = bf_get(lpfc_sli_intf_if_type,
20681 &phba->sli4_hba.sli_intf);
20682 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
20684 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
20690 /* Check the region signature first */
20691 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
20692 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20693 "2619 Config region 23 has bad signature\n");
20698 /* Check the data structure version */
20699 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
20700 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20701 "2620 Config region 23 has bad version\n");
20706 /* Parse TLV entries in the region */
20707 while (offset < data_size) {
20708 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
20711 * If the TLV is not driver specific TLV or driver id is
20712 * not linux driver id, skip the record.
20714 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
20715 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
20716 (rgn23_data[offset + 3] != 0)) {
20717 offset += rgn23_data[offset + 1] * 4 + 4;
20721 /* Driver found a driver specific TLV in the config region */
20722 sub_tlv_len = rgn23_data[offset + 1] * 4;
20727 * Search for configured port state sub-TLV.
20729 while ((offset < data_size) &&
20730 (tlv_offset < sub_tlv_len)) {
20731 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
20736 if (rgn23_data[offset] != PORT_STE_TYPE) {
20737 offset += rgn23_data[offset + 1] * 4 + 4;
20738 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
20742 /* This HBA contains PORT_STE configured */
20743 if (!rgn23_data[offset + 2])
20744 phba->hba_flag |= LINK_DISABLED;
20756 * lpfc_log_fw_write_cmpl - logs firmware write completion status
20757 * @phba: pointer to lpfc hba data structure
20758 * @shdr_status: wr_object rsp's status field
20759 * @shdr_add_status: wr_object rsp's add_status field
20760 * @shdr_add_status_2: wr_object rsp's add_status_2 field
20761 * @shdr_change_status: wr_object rsp's change_status field
20762 * @shdr_csf: wr_object rsp's csf bit
20764 * This routine is intended to be called after a firmware write completes.
20765 * It will log next action items to be performed by the user to instantiate
20766 * the newly downloaded firmware or reason for incompatibility.
20769 lpfc_log_fw_write_cmpl(struct lpfc_hba *phba, u32 shdr_status,
20770 u32 shdr_add_status, u32 shdr_add_status_2,
20771 u32 shdr_change_status, u32 shdr_csf)
20773 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20774 "4198 %s: flash_id x%02x, asic_rev x%02x, "
20775 "status x%02x, add_status x%02x, add_status_2 x%02x, "
20776 "change_status x%02x, csf %01x\n", __func__,
20777 phba->sli4_hba.flash_id, phba->sli4_hba.asic_rev,
20778 shdr_status, shdr_add_status, shdr_add_status_2,
20779 shdr_change_status, shdr_csf);
20781 if (shdr_add_status == LPFC_ADD_STATUS_INCOMPAT_OBJ) {
20782 switch (shdr_add_status_2) {
20783 case LPFC_ADD_STATUS_2_INCOMPAT_FLASH:
20784 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
20785 "4199 Firmware write failed: "
20786 "image incompatible with flash x%02x\n",
20787 phba->sli4_hba.flash_id);
20789 case LPFC_ADD_STATUS_2_INCORRECT_ASIC:
20790 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
20791 "4200 Firmware write failed: "
20792 "image incompatible with ASIC "
20793 "architecture x%02x\n",
20794 phba->sli4_hba.asic_rev);
20797 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
20798 "4210 Firmware write failed: "
20799 "add_status_2 x%02x\n",
20800 shdr_add_status_2);
20803 } else if (!shdr_status && !shdr_add_status) {
20804 if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET ||
20805 shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) {
20807 shdr_change_status =
20808 LPFC_CHANGE_STATUS_PCI_RESET;
20811 switch (shdr_change_status) {
20812 case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
20813 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20814 "3198 Firmware write complete: System "
20815 "reboot required to instantiate\n");
20817 case (LPFC_CHANGE_STATUS_FW_RESET):
20818 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20819 "3199 Firmware write complete: "
20820 "Firmware reset required to "
20823 case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
20824 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20825 "3200 Firmware write complete: Port "
20826 "Migration or PCI Reset required to "
20829 case (LPFC_CHANGE_STATUS_PCI_RESET):
20830 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20831 "3201 Firmware write complete: PCI "
20832 "Reset required to instantiate\n");
20841 * lpfc_wr_object - write an object to the firmware
20842 * @phba: HBA structure that indicates port to create a queue on.
20843 * @dmabuf_list: list of dmabufs to write to the port.
20844 * @size: the total byte value of the objects to write to the port.
20845 * @offset: the current offset to be used to start the transfer.
20847 * This routine will create a wr_object mailbox command to send to the port.
20848 * the mailbox command will be constructed using the dma buffers described in
20849 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
20850 * BDEs that the imbedded mailbox can support. The @offset variable will be
20851 * used to indicate the starting offset of the transfer and will also return
20852 * the offset after the write object mailbox has completed. @size is used to
20853 * determine the end of the object and whether the eof bit should be set.
20855 * Return 0 is successful and offset will contain the the new offset to use
20856 * for the next write.
20857 * Return negative value for error cases.
20860 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
20861 uint32_t size, uint32_t *offset)
20863 struct lpfc_mbx_wr_object *wr_object;
20864 LPFC_MBOXQ_t *mbox;
20866 uint32_t shdr_status, shdr_add_status, shdr_add_status_2;
20867 uint32_t shdr_change_status = 0, shdr_csf = 0;
20869 struct lpfc_dmabuf *dmabuf;
20870 uint32_t written = 0;
20871 bool check_change_status = false;
20873 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20877 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
20878 LPFC_MBOX_OPCODE_WRITE_OBJECT,
20879 sizeof(struct lpfc_mbx_wr_object) -
20880 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
20882 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
20883 wr_object->u.request.write_offset = *offset;
20884 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
20885 wr_object->u.request.object_name[0] =
20886 cpu_to_le32(wr_object->u.request.object_name[0]);
20887 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
20888 list_for_each_entry(dmabuf, dmabuf_list, list) {
20889 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
20891 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
20892 wr_object->u.request.bde[i].addrHigh =
20893 putPaddrHigh(dmabuf->phys);
20894 if (written + SLI4_PAGE_SIZE >= size) {
20895 wr_object->u.request.bde[i].tus.f.bdeSize =
20897 written += (size - written);
20898 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
20899 bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
20900 check_change_status = true;
20902 wr_object->u.request.bde[i].tus.f.bdeSize =
20904 written += SLI4_PAGE_SIZE;
20908 wr_object->u.request.bde_count = i;
20909 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
20910 if (!phba->sli4_hba.intr_enable)
20911 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
20913 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
20914 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
20916 /* The IOCTL status is embedded in the mailbox subheader. */
20917 shdr_status = bf_get(lpfc_mbox_hdr_status,
20918 &wr_object->header.cfg_shdr.response);
20919 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
20920 &wr_object->header.cfg_shdr.response);
20921 shdr_add_status_2 = bf_get(lpfc_mbox_hdr_add_status_2,
20922 &wr_object->header.cfg_shdr.response);
20923 if (check_change_status) {
20924 shdr_change_status = bf_get(lpfc_wr_object_change_status,
20925 &wr_object->u.response);
20926 shdr_csf = bf_get(lpfc_wr_object_csf,
20927 &wr_object->u.response);
20930 if (!phba->sli4_hba.intr_enable)
20931 mempool_free(mbox, phba->mbox_mem_pool);
20932 else if (rc != MBX_TIMEOUT)
20933 mempool_free(mbox, phba->mbox_mem_pool);
20934 if (shdr_status || shdr_add_status || shdr_add_status_2 || rc) {
20935 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20936 "3025 Write Object mailbox failed with "
20937 "status x%x add_status x%x, add_status_2 x%x, "
20938 "mbx status x%x\n",
20939 shdr_status, shdr_add_status, shdr_add_status_2,
20942 *offset = shdr_add_status;
20944 *offset += wr_object->u.response.actual_write_length;
20947 if (rc || check_change_status)
20948 lpfc_log_fw_write_cmpl(phba, shdr_status, shdr_add_status,
20949 shdr_add_status_2, shdr_change_status,
20955 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
20956 * @vport: pointer to vport data structure.
20958 * This function iterate through the mailboxq and clean up all REG_LOGIN
20959 * and REG_VPI mailbox commands associated with the vport. This function
20960 * is called when driver want to restart discovery of the vport due to
20961 * a Clear Virtual Link event.
20964 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
20966 struct lpfc_hba *phba = vport->phba;
20967 LPFC_MBOXQ_t *mb, *nextmb;
20968 struct lpfc_dmabuf *mp;
20969 struct lpfc_nodelist *ndlp;
20970 struct lpfc_nodelist *act_mbx_ndlp = NULL;
20971 LIST_HEAD(mbox_cmd_list);
20972 uint8_t restart_loop;
20974 /* Clean up internally queued mailbox commands with the vport */
20975 spin_lock_irq(&phba->hbalock);
20976 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
20977 if (mb->vport != vport)
20980 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
20981 (mb->u.mb.mbxCommand != MBX_REG_VPI))
20984 list_move_tail(&mb->list, &mbox_cmd_list);
20986 /* Clean up active mailbox command with the vport */
20987 mb = phba->sli.mbox_active;
20988 if (mb && (mb->vport == vport)) {
20989 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
20990 (mb->u.mb.mbxCommand == MBX_REG_VPI))
20991 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
20992 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
20993 act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
20994 /* Put reference count for delayed processing */
20995 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
20996 /* Unregister the RPI when mailbox complete */
20997 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
21000 /* Cleanup any mailbox completions which are not yet processed */
21003 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
21005 * If this mailox is already processed or it is
21006 * for another vport ignore it.
21008 if ((mb->vport != vport) ||
21009 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
21012 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
21013 (mb->u.mb.mbxCommand != MBX_REG_VPI))
21016 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
21017 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
21018 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
21019 /* Unregister the RPI when mailbox complete */
21020 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
21022 spin_unlock_irq(&phba->hbalock);
21023 spin_lock(&ndlp->lock);
21024 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
21025 spin_unlock(&ndlp->lock);
21026 spin_lock_irq(&phba->hbalock);
21030 } while (restart_loop);
21032 spin_unlock_irq(&phba->hbalock);
21034 /* Release the cleaned-up mailbox commands */
21035 while (!list_empty(&mbox_cmd_list)) {
21036 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
21037 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
21038 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
21040 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
21043 mb->ctx_buf = NULL;
21044 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
21045 mb->ctx_ndlp = NULL;
21047 spin_lock(&ndlp->lock);
21048 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
21049 spin_unlock(&ndlp->lock);
21050 lpfc_nlp_put(ndlp);
21053 mempool_free(mb, phba->mbox_mem_pool);
21056 /* Release the ndlp with the cleaned-up active mailbox command */
21057 if (act_mbx_ndlp) {
21058 spin_lock(&act_mbx_ndlp->lock);
21059 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
21060 spin_unlock(&act_mbx_ndlp->lock);
21061 lpfc_nlp_put(act_mbx_ndlp);
21066 * lpfc_drain_txq - Drain the txq
21067 * @phba: Pointer to HBA context object.
21069 * This function attempt to submit IOCBs on the txq
21070 * to the adapter. For SLI4 adapters, the txq contains
21071 * ELS IOCBs that have been deferred because the there
21072 * are no SGLs. This congestion can occur with large
21073 * vport counts during node discovery.
21077 lpfc_drain_txq(struct lpfc_hba *phba)
21079 LIST_HEAD(completions);
21080 struct lpfc_sli_ring *pring;
21081 struct lpfc_iocbq *piocbq = NULL;
21082 unsigned long iflags = 0;
21083 char *fail_msg = NULL;
21084 struct lpfc_sglq *sglq;
21085 union lpfc_wqe128 wqe;
21086 uint32_t txq_cnt = 0;
21087 struct lpfc_queue *wq;
21089 if (phba->link_flag & LS_MDS_LOOPBACK) {
21090 /* MDS WQE are posted only to first WQ*/
21091 wq = phba->sli4_hba.hdwq[0].io_wq;
21096 wq = phba->sli4_hba.els_wq;
21099 pring = lpfc_phba_elsring(phba);
21102 if (unlikely(!pring) || list_empty(&pring->txq))
21105 spin_lock_irqsave(&pring->ring_lock, iflags);
21106 list_for_each_entry(piocbq, &pring->txq, list) {
21110 if (txq_cnt > pring->txq_max)
21111 pring->txq_max = txq_cnt;
21113 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21115 while (!list_empty(&pring->txq)) {
21116 spin_lock_irqsave(&pring->ring_lock, iflags);
21118 piocbq = lpfc_sli_ringtx_get(phba, pring);
21120 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21121 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
21122 "2823 txq empty and txq_cnt is %d\n ",
21126 sglq = __lpfc_sli_get_els_sglq(phba, piocbq);
21128 __lpfc_sli_ringtx_put(phba, pring, piocbq);
21129 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21134 /* The xri and iocb resources secured,
21135 * attempt to issue request
21137 piocbq->sli4_lxritag = sglq->sli4_lxritag;
21138 piocbq->sli4_xritag = sglq->sli4_xritag;
21139 if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq))
21140 fail_msg = "to convert bpl to sgl";
21141 else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe))
21142 fail_msg = "to convert iocb to wqe";
21143 else if (lpfc_sli4_wq_put(wq, &wqe))
21144 fail_msg = " - Wq is full";
21146 lpfc_sli_ringtxcmpl_put(phba, pring, piocbq);
21149 /* Failed means we can't issue and need to cancel */
21150 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
21151 "2822 IOCB failed %s iotag 0x%x "
21154 piocbq->iotag, piocbq->sli4_xritag);
21155 list_add_tail(&piocbq->list, &completions);
21158 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21161 /* Cancel all the IOCBs that cannot be issued */
21162 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
21163 IOERR_SLI_ABORTED);
21169 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
21170 * @phba: Pointer to HBA context object.
21171 * @pwqeq: Pointer to command WQE.
21172 * @sglq: Pointer to the scatter gather queue object.
21174 * This routine converts the bpl or bde that is in the WQE
21175 * to a sgl list for the sli4 hardware. The physical address
21176 * of the bpl/bde is converted back to a virtual address.
21177 * If the WQE contains a BPL then the list of BDE's is
21178 * converted to sli4_sge's. If the WQE contains a single
21179 * BDE then it is converted to a single sli_sge.
21180 * The WQE is still in cpu endianness so the contents of
21181 * the bpl can be used without byte swapping.
21183 * Returns valid XRI = Success, NO_XRI = Failure.
21186 lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
21187 struct lpfc_sglq *sglq)
21189 uint16_t xritag = NO_XRI;
21190 struct ulp_bde64 *bpl = NULL;
21191 struct ulp_bde64 bde;
21192 struct sli4_sge *sgl = NULL;
21193 struct lpfc_dmabuf *dmabuf;
21194 union lpfc_wqe128 *wqe;
21197 uint32_t offset = 0; /* accumulated offset in the sg request list */
21198 int inbound = 0; /* number of sg reply entries inbound from firmware */
21201 if (!pwqeq || !sglq)
21204 sgl = (struct sli4_sge *)sglq->sgl;
21206 pwqeq->iocb.ulpIoTag = pwqeq->iotag;
21208 cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
21209 if (cmd == CMD_XMIT_BLS_RSP64_WQE)
21210 return sglq->sli4_xritag;
21211 numBdes = pwqeq->rsvd2;
21213 /* The addrHigh and addrLow fields within the WQE
21214 * have not been byteswapped yet so there is no
21215 * need to swap them back.
21217 if (pwqeq->context3)
21218 dmabuf = (struct lpfc_dmabuf *)pwqeq->context3;
21222 bpl = (struct ulp_bde64 *)dmabuf->virt;
21226 for (i = 0; i < numBdes; i++) {
21227 /* Should already be byte swapped. */
21228 sgl->addr_hi = bpl->addrHigh;
21229 sgl->addr_lo = bpl->addrLow;
21231 sgl->word2 = le32_to_cpu(sgl->word2);
21232 if ((i+1) == numBdes)
21233 bf_set(lpfc_sli4_sge_last, sgl, 1);
21235 bf_set(lpfc_sli4_sge_last, sgl, 0);
21236 /* swap the size field back to the cpu so we
21237 * can assign it to the sgl.
21239 bde.tus.w = le32_to_cpu(bpl->tus.w);
21240 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
21241 /* The offsets in the sgl need to be accumulated
21242 * separately for the request and reply lists.
21243 * The request is always first, the reply follows.
21246 case CMD_GEN_REQUEST64_WQE:
21247 /* add up the reply sg entries */
21248 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
21250 /* first inbound? reset the offset */
21253 bf_set(lpfc_sli4_sge_offset, sgl, offset);
21254 bf_set(lpfc_sli4_sge_type, sgl,
21255 LPFC_SGE_TYPE_DATA);
21256 offset += bde.tus.f.bdeSize;
21258 case CMD_FCP_TRSP64_WQE:
21259 bf_set(lpfc_sli4_sge_offset, sgl, 0);
21260 bf_set(lpfc_sli4_sge_type, sgl,
21261 LPFC_SGE_TYPE_DATA);
21263 case CMD_FCP_TSEND64_WQE:
21264 case CMD_FCP_TRECEIVE64_WQE:
21265 bf_set(lpfc_sli4_sge_type, sgl,
21266 bpl->tus.f.bdeFlags);
21270 offset += bde.tus.f.bdeSize;
21271 bf_set(lpfc_sli4_sge_offset, sgl, offset);
21274 sgl->word2 = cpu_to_le32(sgl->word2);
21278 } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
21279 /* The addrHigh and addrLow fields of the BDE have not
21280 * been byteswapped yet so they need to be swapped
21281 * before putting them in the sgl.
21283 sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
21284 sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
21285 sgl->word2 = le32_to_cpu(sgl->word2);
21286 bf_set(lpfc_sli4_sge_last, sgl, 1);
21287 sgl->word2 = cpu_to_le32(sgl->word2);
21288 sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
21290 return sglq->sli4_xritag;
21294 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
21295 * @phba: Pointer to HBA context object.
21296 * @qp: Pointer to HDW queue.
21297 * @pwqe: Pointer to command WQE.
21300 lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
21301 struct lpfc_iocbq *pwqe)
21303 union lpfc_wqe128 *wqe = &pwqe->wqe;
21304 struct lpfc_async_xchg_ctx *ctxp;
21305 struct lpfc_queue *wq;
21306 struct lpfc_sglq *sglq;
21307 struct lpfc_sli_ring *pring;
21308 unsigned long iflags;
21311 /* NVME_LS and NVME_LS ABTS requests. */
21312 if (pwqe->iocb_flag & LPFC_IO_NVME_LS) {
21313 pring = phba->sli4_hba.nvmels_wq->pring;
21314 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
21316 sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
21318 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21321 pwqe->sli4_lxritag = sglq->sli4_lxritag;
21322 pwqe->sli4_xritag = sglq->sli4_xritag;
21323 if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
21324 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21327 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
21328 pwqe->sli4_xritag);
21329 ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
21331 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21335 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
21336 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21338 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
21342 /* NVME_FCREQ and NVME_ABTS requests */
21343 if (pwqe->iocb_flag & (LPFC_IO_NVME | LPFC_IO_FCP | LPFC_IO_CMF)) {
21344 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
21348 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
21350 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
21352 ret = lpfc_sli4_wq_put(wq, wqe);
21354 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21357 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
21358 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21360 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
21364 /* NVMET requests */
21365 if (pwqe->iocb_flag & LPFC_IO_NVMET) {
21366 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
21370 ctxp = pwqe->context2;
21371 sglq = ctxp->ctxbuf->sglq;
21372 if (pwqe->sli4_xritag == NO_XRI) {
21373 pwqe->sli4_lxritag = sglq->sli4_lxritag;
21374 pwqe->sli4_xritag = sglq->sli4_xritag;
21376 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
21377 pwqe->sli4_xritag);
21378 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
21380 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
21382 ret = lpfc_sli4_wq_put(wq, wqe);
21384 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21387 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
21388 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21390 lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
21397 * lpfc_sli4_issue_abort_iotag - SLI-4 WQE init & issue for the Abort
21398 * @phba: Pointer to HBA context object.
21399 * @cmdiocb: Pointer to driver command iocb object.
21400 * @cmpl: completion function.
21402 * Fill the appropriate fields for the abort WQE and call
21403 * internal routine lpfc_sli4_issue_wqe to send the WQE
21404 * This function is called with hbalock held and no ring_lock held.
21406 * RETURNS 0 - SUCCESS
21410 lpfc_sli4_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
21413 struct lpfc_vport *vport = cmdiocb->vport;
21414 struct lpfc_iocbq *abtsiocb = NULL;
21415 union lpfc_wqe128 *abtswqe;
21416 struct lpfc_io_buf *lpfc_cmd;
21417 int retval = IOCB_ERROR;
21418 u16 xritag = cmdiocb->sli4_xritag;
21421 * The scsi command can not be in txq and it is in flight because the
21422 * pCmd is still pointing at the SCSI command we have to abort. There
21423 * is no need to search the txcmplq. Just send an abort to the FW.
21426 abtsiocb = __lpfc_sli_get_iocbq(phba);
21428 return WQE_NORESOURCE;
21430 /* Indicate the IO is being aborted by the driver. */
21431 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
21433 abtswqe = &abtsiocb->wqe;
21434 memset(abtswqe, 0, sizeof(*abtswqe));
21436 if (!lpfc_is_link_up(phba))
21437 bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 1);
21438 bf_set(abort_cmd_criteria, &abtswqe->abort_cmd, T_XRI_TAG);
21439 abtswqe->abort_cmd.rsrvd5 = 0;
21440 abtswqe->abort_cmd.wqe_com.abort_tag = xritag;
21441 bf_set(wqe_reqtag, &abtswqe->abort_cmd.wqe_com, abtsiocb->iotag);
21442 bf_set(wqe_cmnd, &abtswqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
21443 bf_set(wqe_xri_tag, &abtswqe->generic.wqe_com, 0);
21444 bf_set(wqe_qosd, &abtswqe->abort_cmd.wqe_com, 1);
21445 bf_set(wqe_lenloc, &abtswqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
21446 bf_set(wqe_cmd_type, &abtswqe->abort_cmd.wqe_com, OTHER_COMMAND);
21448 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
21449 abtsiocb->hba_wqidx = cmdiocb->hba_wqidx;
21450 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
21451 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
21452 abtsiocb->iocb_flag |= LPFC_IO_FCP;
21453 if (cmdiocb->iocb_flag & LPFC_IO_NVME)
21454 abtsiocb->iocb_flag |= LPFC_IO_NVME;
21455 if (cmdiocb->iocb_flag & LPFC_IO_FOF)
21456 abtsiocb->iocb_flag |= LPFC_IO_FOF;
21457 abtsiocb->vport = vport;
21458 abtsiocb->wqe_cmpl = cmpl;
21460 lpfc_cmd = container_of(cmdiocb, struct lpfc_io_buf, cur_iocbq);
21461 retval = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, abtsiocb);
21463 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
21464 "0359 Abort xri x%x, original iotag x%x, "
21465 "abort cmd iotag x%x retval x%x\n",
21466 xritag, cmdiocb->iotag, abtsiocb->iotag, retval);
21469 cmdiocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
21470 __lpfc_sli_release_iocbq(phba, abtsiocb);
21476 #ifdef LPFC_MXP_STAT
21478 * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
21479 * @phba: pointer to lpfc hba data structure.
21480 * @hwqid: belong to which HWQ.
21482 * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
21483 * 15 seconds after a test case is running.
21485 * The user should call lpfc_debugfs_multixripools_write before running a test
21486 * case to clear stat_snapshot_taken. Then the user starts a test case. During
21487 * test case is running, stat_snapshot_taken is incremented by 1 every time when
21488 * this routine is called from heartbeat timer. When stat_snapshot_taken is
21489 * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
21491 void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
21493 struct lpfc_sli4_hdw_queue *qp;
21494 struct lpfc_multixri_pool *multixri_pool;
21495 struct lpfc_pvt_pool *pvt_pool;
21496 struct lpfc_pbl_pool *pbl_pool;
21499 qp = &phba->sli4_hba.hdwq[hwqid];
21500 multixri_pool = qp->p_multixri_pool;
21501 if (!multixri_pool)
21504 if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
21505 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21506 pbl_pool = &qp->p_multixri_pool->pbl_pool;
21507 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21509 multixri_pool->stat_pbl_count = pbl_pool->count;
21510 multixri_pool->stat_pvt_count = pvt_pool->count;
21511 multixri_pool->stat_busy_count = txcmplq_cnt;
21514 multixri_pool->stat_snapshot_taken++;
21519 * lpfc_adjust_pvt_pool_count - Adjust private pool count
21520 * @phba: pointer to lpfc hba data structure.
21521 * @hwqid: belong to which HWQ.
21523 * This routine moves some XRIs from private to public pool when private pool
21526 void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
21528 struct lpfc_multixri_pool *multixri_pool;
21530 u32 prev_io_req_count;
21532 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
21533 if (!multixri_pool)
21535 io_req_count = multixri_pool->io_req_count;
21536 prev_io_req_count = multixri_pool->prev_io_req_count;
21538 if (prev_io_req_count != io_req_count) {
21539 /* Private pool is busy */
21540 multixri_pool->prev_io_req_count = io_req_count;
21542 /* Private pool is not busy.
21543 * Move XRIs from private to public pool.
21545 lpfc_move_xri_pvt_to_pbl(phba, hwqid);
21550 * lpfc_adjust_high_watermark - Adjust high watermark
21551 * @phba: pointer to lpfc hba data structure.
21552 * @hwqid: belong to which HWQ.
21554 * This routine sets high watermark as number of outstanding XRIs,
21555 * but make sure the new value is between xri_limit/2 and xri_limit.
21557 void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
21565 struct lpfc_multixri_pool *multixri_pool;
21566 struct lpfc_sli4_hdw_queue *qp;
21568 qp = &phba->sli4_hba.hdwq[hwqid];
21569 multixri_pool = qp->p_multixri_pool;
21570 if (!multixri_pool)
21572 xri_limit = multixri_pool->xri_limit;
21574 watermark_max = xri_limit;
21575 watermark_min = xri_limit / 2;
21577 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21578 abts_io_bufs = qp->abts_scsi_io_bufs;
21579 abts_io_bufs += qp->abts_nvme_io_bufs;
21581 new_watermark = txcmplq_cnt + abts_io_bufs;
21582 new_watermark = min(watermark_max, new_watermark);
21583 new_watermark = max(watermark_min, new_watermark);
21584 multixri_pool->pvt_pool.high_watermark = new_watermark;
21586 #ifdef LPFC_MXP_STAT
21587 multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
21593 * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
21594 * @phba: pointer to lpfc hba data structure.
21595 * @hwqid: belong to which HWQ.
21597 * This routine is called from hearbeat timer when pvt_pool is idle.
21598 * All free XRIs are moved from private to public pool on hwqid with 2 steps.
21599 * The first step moves (all - low_watermark) amount of XRIs.
21600 * The second step moves the rest of XRIs.
21602 void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
21604 struct lpfc_pbl_pool *pbl_pool;
21605 struct lpfc_pvt_pool *pvt_pool;
21606 struct lpfc_sli4_hdw_queue *qp;
21607 struct lpfc_io_buf *lpfc_ncmd;
21608 struct lpfc_io_buf *lpfc_ncmd_next;
21609 unsigned long iflag;
21610 struct list_head tmp_list;
21613 qp = &phba->sli4_hba.hdwq[hwqid];
21614 pbl_pool = &qp->p_multixri_pool->pbl_pool;
21615 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21618 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
21619 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
21621 if (pvt_pool->count > pvt_pool->low_watermark) {
21622 /* Step 1: move (all - low_watermark) from pvt_pool
21626 /* Move low watermark of bufs from pvt_pool to tmp_list */
21627 INIT_LIST_HEAD(&tmp_list);
21628 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21629 &pvt_pool->list, list) {
21630 list_move_tail(&lpfc_ncmd->list, &tmp_list);
21632 if (tmp_count >= pvt_pool->low_watermark)
21636 /* Move all bufs from pvt_pool to pbl_pool */
21637 list_splice_init(&pvt_pool->list, &pbl_pool->list);
21639 /* Move all bufs from tmp_list to pvt_pool */
21640 list_splice(&tmp_list, &pvt_pool->list);
21642 pbl_pool->count += (pvt_pool->count - tmp_count);
21643 pvt_pool->count = tmp_count;
21645 /* Step 2: move the rest from pvt_pool to pbl_pool */
21646 list_splice_init(&pvt_pool->list, &pbl_pool->list);
21647 pbl_pool->count += pvt_pool->count;
21648 pvt_pool->count = 0;
21651 spin_unlock(&pvt_pool->lock);
21652 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21656 * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
21657 * @phba: pointer to lpfc hba data structure
21658 * @qp: pointer to HDW queue
21659 * @pbl_pool: specified public free XRI pool
21660 * @pvt_pool: specified private free XRI pool
21661 * @count: number of XRIs to move
21663 * This routine tries to move some free common bufs from the specified pbl_pool
21664 * to the specified pvt_pool. It might move less than count XRIs if there's not
21665 * enough in public pool.
21668 * true - if XRIs are successfully moved from the specified pbl_pool to the
21669 * specified pvt_pool
21670 * false - if the specified pbl_pool is empty or locked by someone else
21673 _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
21674 struct lpfc_pbl_pool *pbl_pool,
21675 struct lpfc_pvt_pool *pvt_pool, u32 count)
21677 struct lpfc_io_buf *lpfc_ncmd;
21678 struct lpfc_io_buf *lpfc_ncmd_next;
21679 unsigned long iflag;
21682 ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
21684 if (pbl_pool->count) {
21685 /* Move a batch of XRIs from public to private pool */
21686 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
21687 list_for_each_entry_safe(lpfc_ncmd,
21691 list_move_tail(&lpfc_ncmd->list,
21700 spin_unlock(&pvt_pool->lock);
21701 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21704 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21711 * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
21712 * @phba: pointer to lpfc hba data structure.
21713 * @hwqid: belong to which HWQ.
21714 * @count: number of XRIs to move
21716 * This routine tries to find some free common bufs in one of public pools with
21717 * Round Robin method. The search always starts from local hwqid, then the next
21718 * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
21719 * a batch of free common bufs are moved to private pool on hwqid.
21720 * It might move less than count XRIs if there's not enough in public pool.
21722 void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
21724 struct lpfc_multixri_pool *multixri_pool;
21725 struct lpfc_multixri_pool *next_multixri_pool;
21726 struct lpfc_pvt_pool *pvt_pool;
21727 struct lpfc_pbl_pool *pbl_pool;
21728 struct lpfc_sli4_hdw_queue *qp;
21733 qp = &phba->sli4_hba.hdwq[hwqid];
21734 multixri_pool = qp->p_multixri_pool;
21735 pvt_pool = &multixri_pool->pvt_pool;
21736 pbl_pool = &multixri_pool->pbl_pool;
21738 /* Check if local pbl_pool is available */
21739 ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
21741 #ifdef LPFC_MXP_STAT
21742 multixri_pool->local_pbl_hit_count++;
21747 hwq_count = phba->cfg_hdw_queue;
21749 /* Get the next hwqid which was found last time */
21750 next_hwqid = multixri_pool->rrb_next_hwqid;
21753 /* Go to next hwq */
21754 next_hwqid = (next_hwqid + 1) % hwq_count;
21756 next_multixri_pool =
21757 phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
21758 pbl_pool = &next_multixri_pool->pbl_pool;
21760 /* Check if the public free xri pool is available */
21761 ret = _lpfc_move_xri_pbl_to_pvt(
21762 phba, qp, pbl_pool, pvt_pool, count);
21764 /* Exit while-loop if success or all hwqid are checked */
21765 } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
21767 /* Starting point for the next time */
21768 multixri_pool->rrb_next_hwqid = next_hwqid;
21771 /* stats: all public pools are empty*/
21772 multixri_pool->pbl_empty_count++;
21775 #ifdef LPFC_MXP_STAT
21777 if (next_hwqid == hwqid)
21778 multixri_pool->local_pbl_hit_count++;
21780 multixri_pool->other_pbl_hit_count++;
21786 * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
21787 * @phba: pointer to lpfc hba data structure.
21788 * @hwqid: belong to which HWQ.
21790 * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
21793 void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
21795 struct lpfc_multixri_pool *multixri_pool;
21796 struct lpfc_pvt_pool *pvt_pool;
21798 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
21799 pvt_pool = &multixri_pool->pvt_pool;
21801 if (pvt_pool->count < pvt_pool->low_watermark)
21802 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
21806 * lpfc_release_io_buf - Return one IO buf back to free pool
21807 * @phba: pointer to lpfc hba data structure.
21808 * @lpfc_ncmd: IO buf to be returned.
21809 * @qp: belong to which HWQ.
21811 * This routine returns one IO buf back to free pool. If this is an urgent IO,
21812 * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
21813 * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
21814 * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to
21815 * lpfc_io_buf_list_put.
21817 void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
21818 struct lpfc_sli4_hdw_queue *qp)
21820 unsigned long iflag;
21821 struct lpfc_pbl_pool *pbl_pool;
21822 struct lpfc_pvt_pool *pvt_pool;
21823 struct lpfc_epd_pool *epd_pool;
21829 /* MUST zero fields if buffer is reused by another protocol */
21830 lpfc_ncmd->nvmeCmd = NULL;
21831 lpfc_ncmd->cur_iocbq.wqe_cmpl = NULL;
21832 lpfc_ncmd->cur_iocbq.iocb_cmpl = NULL;
21834 if (phba->cfg_xpsgl && !phba->nvmet_support &&
21835 !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
21836 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
21838 if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
21839 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
21841 if (phba->cfg_xri_rebalancing) {
21842 if (lpfc_ncmd->expedite) {
21843 /* Return to expedite pool */
21844 epd_pool = &phba->epd_pool;
21845 spin_lock_irqsave(&epd_pool->lock, iflag);
21846 list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
21848 spin_unlock_irqrestore(&epd_pool->lock, iflag);
21852 /* Avoid invalid access if an IO sneaks in and is being rejected
21853 * just _after_ xri pools are destroyed in lpfc_offline.
21854 * Nothing much can be done at this point.
21856 if (!qp->p_multixri_pool)
21859 pbl_pool = &qp->p_multixri_pool->pbl_pool;
21860 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21862 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21863 abts_io_bufs = qp->abts_scsi_io_bufs;
21864 abts_io_bufs += qp->abts_nvme_io_bufs;
21866 xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
21867 xri_limit = qp->p_multixri_pool->xri_limit;
21869 #ifdef LPFC_MXP_STAT
21870 if (xri_owned <= xri_limit)
21871 qp->p_multixri_pool->below_limit_count++;
21873 qp->p_multixri_pool->above_limit_count++;
21876 /* XRI goes to either public or private free xri pool
21877 * based on watermark and xri_limit
21879 if ((pvt_pool->count < pvt_pool->low_watermark) ||
21880 (xri_owned < xri_limit &&
21881 pvt_pool->count < pvt_pool->high_watermark)) {
21882 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
21883 qp, free_pvt_pool);
21884 list_add_tail(&lpfc_ncmd->list,
21887 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21889 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
21890 qp, free_pub_pool);
21891 list_add_tail(&lpfc_ncmd->list,
21894 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21897 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
21899 list_add_tail(&lpfc_ncmd->list,
21900 &qp->lpfc_io_buf_list_put);
21902 spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
21908 * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
21909 * @phba: pointer to lpfc hba data structure.
21910 * @qp: pointer to HDW queue
21911 * @pvt_pool: pointer to private pool data structure.
21912 * @ndlp: pointer to lpfc nodelist data structure.
21914 * This routine tries to get one free IO buf from private pool.
21917 * pointer to one free IO buf - if private pool is not empty
21918 * NULL - if private pool is empty
21920 static struct lpfc_io_buf *
21921 lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
21922 struct lpfc_sli4_hdw_queue *qp,
21923 struct lpfc_pvt_pool *pvt_pool,
21924 struct lpfc_nodelist *ndlp)
21926 struct lpfc_io_buf *lpfc_ncmd;
21927 struct lpfc_io_buf *lpfc_ncmd_next;
21928 unsigned long iflag;
21930 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
21931 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21932 &pvt_pool->list, list) {
21933 if (lpfc_test_rrq_active(
21934 phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
21936 list_del(&lpfc_ncmd->list);
21938 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21941 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21947 * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
21948 * @phba: pointer to lpfc hba data structure.
21950 * This routine tries to get one free IO buf from expedite pool.
21953 * pointer to one free IO buf - if expedite pool is not empty
21954 * NULL - if expedite pool is empty
21956 static struct lpfc_io_buf *
21957 lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
21959 struct lpfc_io_buf *lpfc_ncmd;
21960 struct lpfc_io_buf *lpfc_ncmd_next;
21961 unsigned long iflag;
21962 struct lpfc_epd_pool *epd_pool;
21964 epd_pool = &phba->epd_pool;
21967 spin_lock_irqsave(&epd_pool->lock, iflag);
21968 if (epd_pool->count > 0) {
21969 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21970 &epd_pool->list, list) {
21971 list_del(&lpfc_ncmd->list);
21976 spin_unlock_irqrestore(&epd_pool->lock, iflag);
21982 * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
21983 * @phba: pointer to lpfc hba data structure.
21984 * @ndlp: pointer to lpfc nodelist data structure.
21985 * @hwqid: belong to which HWQ
21986 * @expedite: 1 means this request is urgent.
21988 * This routine will do the following actions and then return a pointer to
21991 * 1. If private free xri count is empty, move some XRIs from public to
21993 * 2. Get one XRI from private free xri pool.
21994 * 3. If we fail to get one from pvt_pool and this is an expedite request,
21995 * get one free xri from expedite pool.
21997 * Note: ndlp is only used on SCSI side for RRQ testing.
21998 * The caller should pass NULL for ndlp on NVME side.
22001 * pointer to one free IO buf - if private pool is not empty
22002 * NULL - if private pool is empty
22004 static struct lpfc_io_buf *
22005 lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
22006 struct lpfc_nodelist *ndlp,
22007 int hwqid, int expedite)
22009 struct lpfc_sli4_hdw_queue *qp;
22010 struct lpfc_multixri_pool *multixri_pool;
22011 struct lpfc_pvt_pool *pvt_pool;
22012 struct lpfc_io_buf *lpfc_ncmd;
22014 qp = &phba->sli4_hba.hdwq[hwqid];
22017 lpfc_printf_log(phba, KERN_INFO,
22018 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
22019 "5556 NULL qp for hwqid x%x\n", hwqid);
22022 multixri_pool = qp->p_multixri_pool;
22023 if (!multixri_pool) {
22024 lpfc_printf_log(phba, KERN_INFO,
22025 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
22026 "5557 NULL multixri for hwqid x%x\n", hwqid);
22029 pvt_pool = &multixri_pool->pvt_pool;
22031 lpfc_printf_log(phba, KERN_INFO,
22032 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
22033 "5558 NULL pvt_pool for hwqid x%x\n", hwqid);
22036 multixri_pool->io_req_count++;
22038 /* If pvt_pool is empty, move some XRIs from public to private pool */
22039 if (pvt_pool->count == 0)
22040 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
22042 /* Get one XRI from private free xri pool */
22043 lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
22046 lpfc_ncmd->hdwq = qp;
22047 lpfc_ncmd->hdwq_no = hwqid;
22048 } else if (expedite) {
22049 /* If we fail to get one from pvt_pool and this is an expedite
22050 * request, get one free xri from expedite pool.
22052 lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
22058 static inline struct lpfc_io_buf *
22059 lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
22061 struct lpfc_sli4_hdw_queue *qp;
22062 struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
22064 qp = &phba->sli4_hba.hdwq[idx];
22065 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
22066 &qp->lpfc_io_buf_list_get, list) {
22067 if (lpfc_test_rrq_active(phba, ndlp,
22068 lpfc_cmd->cur_iocbq.sli4_lxritag))
22071 if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
22074 list_del_init(&lpfc_cmd->list);
22076 lpfc_cmd->hdwq = qp;
22077 lpfc_cmd->hdwq_no = idx;
22084 * lpfc_get_io_buf - Get one IO buffer from free pool
22085 * @phba: The HBA for which this call is being executed.
22086 * @ndlp: pointer to lpfc nodelist data structure.
22087 * @hwqid: belong to which HWQ
22088 * @expedite: 1 means this request is urgent.
22090 * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
22091 * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
22092 * a IO buffer from head of @hdwq io_buf_list and returns to caller.
22094 * Note: ndlp is only used on SCSI side for RRQ testing.
22095 * The caller should pass NULL for ndlp on NVME side.
22099 * Pointer to lpfc_io_buf - Success
22101 struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
22102 struct lpfc_nodelist *ndlp,
22103 u32 hwqid, int expedite)
22105 struct lpfc_sli4_hdw_queue *qp;
22106 unsigned long iflag;
22107 struct lpfc_io_buf *lpfc_cmd;
22109 qp = &phba->sli4_hba.hdwq[hwqid];
22112 lpfc_printf_log(phba, KERN_WARNING,
22113 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
22114 "5555 NULL qp for hwqid x%x\n", hwqid);
22118 if (phba->cfg_xri_rebalancing)
22119 lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
22120 phba, ndlp, hwqid, expedite);
22122 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
22123 qp, alloc_xri_get);
22124 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
22125 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
22127 lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
22128 qp, alloc_xri_put);
22129 list_splice(&qp->lpfc_io_buf_list_put,
22130 &qp->lpfc_io_buf_list_get);
22131 qp->get_io_bufs += qp->put_io_bufs;
22132 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
22133 qp->put_io_bufs = 0;
22134 spin_unlock(&qp->io_buf_list_put_lock);
22135 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
22137 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
22139 spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
22146 * lpfc_read_object - Retrieve object data from HBA
22147 * @phba: The HBA for which this call is being executed.
22148 * @rdobject: Pathname of object data we want to read.
22149 * @datap: Pointer to where data will be copied to.
22150 * @datasz: size of data area
22152 * This routine is limited to object sizes of LPFC_BPL_SIZE (1024) or less.
22153 * The data will be truncated if datasz is not large enough.
22154 * Version 1 is not supported with Embedded mbox cmd, so we must use version 0.
22155 * Returns the actual bytes read from the object.
22158 lpfc_read_object(struct lpfc_hba *phba, char *rdobject, uint32_t *datap,
22161 struct lpfc_mbx_read_object *read_object;
22162 LPFC_MBOXQ_t *mbox;
22163 int rc, length, eof, j, byte_cnt = 0;
22164 uint32_t shdr_status, shdr_add_status;
22165 union lpfc_sli4_cfg_shdr *shdr;
22166 struct lpfc_dmabuf *pcmd;
22167 u32 rd_object_name[LPFC_MBX_OBJECT_NAME_LEN_DW] = {0};
22169 /* sanity check on queue memory */
22173 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
22176 length = (sizeof(struct lpfc_mbx_read_object) -
22177 sizeof(struct lpfc_sli4_cfg_mhdr));
22178 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
22179 LPFC_MBOX_OPCODE_READ_OBJECT,
22180 length, LPFC_SLI4_MBX_EMBED);
22181 read_object = &mbox->u.mqe.un.read_object;
22182 shdr = (union lpfc_sli4_cfg_shdr *)&read_object->header.cfg_shdr;
22184 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_0);
22185 bf_set(lpfc_mbx_rd_object_rlen, &read_object->u.request, datasz);
22186 read_object->u.request.rd_object_offset = 0;
22187 read_object->u.request.rd_object_cnt = 1;
22189 memset((void *)read_object->u.request.rd_object_name, 0,
22191 scnprintf((char *)rd_object_name, sizeof(rd_object_name), rdobject);
22192 for (j = 0; j < strlen(rdobject); j++)
22193 read_object->u.request.rd_object_name[j] =
22194 cpu_to_le32(rd_object_name[j]);
22196 pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
22198 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
22199 if (!pcmd || !pcmd->virt) {
22201 mempool_free(mbox, phba->mbox_mem_pool);
22204 memset((void *)pcmd->virt, 0, LPFC_BPL_SIZE);
22205 read_object->u.request.rd_object_hbuf[0].pa_lo =
22206 putPaddrLow(pcmd->phys);
22207 read_object->u.request.rd_object_hbuf[0].pa_hi =
22208 putPaddrHigh(pcmd->phys);
22209 read_object->u.request.rd_object_hbuf[0].length = LPFC_BPL_SIZE;
22211 mbox->vport = phba->pport;
22212 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
22213 mbox->ctx_buf = NULL;
22214 mbox->ctx_ndlp = NULL;
22216 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
22217 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
22218 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
22220 if (shdr_status == STATUS_FAILED &&
22221 shdr_add_status == ADD_STATUS_INVALID_OBJECT_NAME) {
22222 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
22223 "4674 No port cfg file in FW.\n");
22224 byte_cnt = -ENOENT;
22225 } else if (shdr_status || shdr_add_status || rc) {
22226 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
22227 "2625 READ_OBJECT mailbox failed with "
22228 "status x%x add_status x%x, mbx status x%x\n",
22229 shdr_status, shdr_add_status, rc);
22233 length = read_object->u.response.rd_object_actual_rlen;
22234 eof = bf_get(lpfc_mbx_rd_object_eof, &read_object->u.response);
22235 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_CGN_MGMT,
22236 "2626 READ_OBJECT Success len %d:%d, EOF %d\n",
22237 length, datasz, eof);
22239 /* Detect the port config file exists but is empty */
22240 if (!length && eof) {
22246 lpfc_sli_pcimem_bcopy(pcmd->virt, datap, byte_cnt);
22250 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
22252 mempool_free(mbox, phba->mbox_mem_pool);
22257 * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
22258 * @phba: The HBA for which this call is being executed.
22259 * @lpfc_buf: IO buf structure to append the SGL chunk
22261 * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
22262 * and will allocate an SGL chunk if the pool is empty.
22266 * Pointer to sli4_hybrid_sgl - Success
22268 struct sli4_hybrid_sgl *
22269 lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
22271 struct sli4_hybrid_sgl *list_entry = NULL;
22272 struct sli4_hybrid_sgl *tmp = NULL;
22273 struct sli4_hybrid_sgl *allocated_sgl = NULL;
22274 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22275 struct list_head *buf_list = &hdwq->sgl_list;
22276 unsigned long iflags;
22278 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22280 if (likely(!list_empty(buf_list))) {
22281 /* break off 1 chunk from the sgl_list */
22282 list_for_each_entry_safe(list_entry, tmp,
22283 buf_list, list_node) {
22284 list_move_tail(&list_entry->list_node,
22285 &lpfc_buf->dma_sgl_xtra_list);
22289 /* allocate more */
22290 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22291 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
22292 cpu_to_node(hdwq->io_wq->chann));
22294 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22295 "8353 error kmalloc memory for HDWQ "
22297 lpfc_buf->hdwq_no, __func__);
22301 tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
22302 GFP_ATOMIC, &tmp->dma_phys_sgl);
22303 if (!tmp->dma_sgl) {
22304 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22305 "8354 error pool_alloc memory for HDWQ "
22307 lpfc_buf->hdwq_no, __func__);
22312 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22313 list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
22316 allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
22317 struct sli4_hybrid_sgl,
22320 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22322 return allocated_sgl;
22326 * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
22327 * @phba: The HBA for which this call is being executed.
22328 * @lpfc_buf: IO buf structure with the SGL chunk
22330 * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
22337 lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
22340 struct sli4_hybrid_sgl *list_entry = NULL;
22341 struct sli4_hybrid_sgl *tmp = NULL;
22342 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22343 struct list_head *buf_list = &hdwq->sgl_list;
22344 unsigned long iflags;
22346 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22348 if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
22349 list_for_each_entry_safe(list_entry, tmp,
22350 &lpfc_buf->dma_sgl_xtra_list,
22352 list_move_tail(&list_entry->list_node,
22359 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22364 * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
22365 * @phba: phba object
22366 * @hdwq: hdwq to cleanup sgl buff resources on
22368 * This routine frees all SGL chunks of hdwq SGL chunk pool.
22374 lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
22375 struct lpfc_sli4_hdw_queue *hdwq)
22377 struct list_head *buf_list = &hdwq->sgl_list;
22378 struct sli4_hybrid_sgl *list_entry = NULL;
22379 struct sli4_hybrid_sgl *tmp = NULL;
22380 unsigned long iflags;
22382 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22384 /* Free sgl pool */
22385 list_for_each_entry_safe(list_entry, tmp,
22386 buf_list, list_node) {
22387 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
22388 list_entry->dma_sgl,
22389 list_entry->dma_phys_sgl);
22390 list_del(&list_entry->list_node);
22394 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22398 * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
22399 * @phba: The HBA for which this call is being executed.
22400 * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
22402 * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
22403 * and will allocate an CMD/RSP buffer if the pool is empty.
22407 * Pointer to fcp_cmd_rsp_buf - Success
22409 struct fcp_cmd_rsp_buf *
22410 lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
22411 struct lpfc_io_buf *lpfc_buf)
22413 struct fcp_cmd_rsp_buf *list_entry = NULL;
22414 struct fcp_cmd_rsp_buf *tmp = NULL;
22415 struct fcp_cmd_rsp_buf *allocated_buf = NULL;
22416 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22417 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
22418 unsigned long iflags;
22420 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22422 if (likely(!list_empty(buf_list))) {
22423 /* break off 1 chunk from the list */
22424 list_for_each_entry_safe(list_entry, tmp,
22427 list_move_tail(&list_entry->list_node,
22428 &lpfc_buf->dma_cmd_rsp_list);
22432 /* allocate more */
22433 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22434 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
22435 cpu_to_node(hdwq->io_wq->chann));
22437 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22438 "8355 error kmalloc memory for HDWQ "
22440 lpfc_buf->hdwq_no, __func__);
22444 tmp->fcp_cmnd = dma_pool_alloc(phba->lpfc_cmd_rsp_buf_pool,
22446 &tmp->fcp_cmd_rsp_dma_handle);
22448 if (!tmp->fcp_cmnd) {
22449 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22450 "8356 error pool_alloc memory for HDWQ "
22452 lpfc_buf->hdwq_no, __func__);
22457 tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
22458 sizeof(struct fcp_cmnd));
22460 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22461 list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
22464 allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
22465 struct fcp_cmd_rsp_buf,
22468 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22470 return allocated_buf;
22474 * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
22475 * @phba: The HBA for which this call is being executed.
22476 * @lpfc_buf: IO buf structure with the CMD/RSP buf
22478 * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
22485 lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
22486 struct lpfc_io_buf *lpfc_buf)
22489 struct fcp_cmd_rsp_buf *list_entry = NULL;
22490 struct fcp_cmd_rsp_buf *tmp = NULL;
22491 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22492 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
22493 unsigned long iflags;
22495 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22497 if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
22498 list_for_each_entry_safe(list_entry, tmp,
22499 &lpfc_buf->dma_cmd_rsp_list,
22501 list_move_tail(&list_entry->list_node,
22508 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22513 * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
22514 * @phba: phba object
22515 * @hdwq: hdwq to cleanup cmd rsp buff resources on
22517 * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
22523 lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
22524 struct lpfc_sli4_hdw_queue *hdwq)
22526 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
22527 struct fcp_cmd_rsp_buf *list_entry = NULL;
22528 struct fcp_cmd_rsp_buf *tmp = NULL;
22529 unsigned long iflags;
22531 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22533 /* Free cmd_rsp buf pool */
22534 list_for_each_entry_safe(list_entry, tmp,
22537 dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
22538 list_entry->fcp_cmnd,
22539 list_entry->fcp_cmd_rsp_dma_handle);
22540 list_del(&list_entry->list_node);
22544 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);