1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 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 *
74 lpfc_sli4_els_preprocess_rspiocbq(struct lpfc_hba *phba,
75 struct lpfc_iocbq *rspiocbq);
76 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
78 static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
79 struct hbq_dmabuf *dmabuf);
80 static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba,
81 struct lpfc_queue *cq, struct lpfc_cqe *cqe);
82 static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
84 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba,
85 struct lpfc_queue *eq,
86 struct lpfc_eqe *eqe);
87 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
88 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
89 static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q);
90 static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba,
91 struct lpfc_queue *cq,
92 struct lpfc_cqe *cqe);
93 static uint16_t lpfc_wqe_bpl2sgl(struct lpfc_hba *phba,
94 struct lpfc_iocbq *pwqeq,
95 struct lpfc_sglq *sglq);
97 union lpfc_wqe128 lpfc_iread_cmd_template;
98 union lpfc_wqe128 lpfc_iwrite_cmd_template;
99 union lpfc_wqe128 lpfc_icmnd_cmd_template;
101 /* Setup WQE templates for IOs */
102 void lpfc_wqe_cmd_template(void)
104 union lpfc_wqe128 *wqe;
107 wqe = &lpfc_iread_cmd_template;
108 memset(wqe, 0, sizeof(union lpfc_wqe128));
110 /* Word 0, 1, 2 - BDE is variable */
112 /* Word 3 - cmd_buff_len, payload_offset_len is zero */
114 /* Word 4 - total_xfer_len is variable */
116 /* Word 5 - is zero */
118 /* Word 6 - ctxt_tag, xri_tag is variable */
121 bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE);
122 bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK);
123 bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3);
124 bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI);
126 /* Word 8 - abort_tag is variable */
128 /* Word 9 - reqtag is variable */
130 /* Word 10 - dbde, wqes is variable */
131 bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0);
132 bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
133 bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4);
134 bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
135 bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
137 /* Word 11 - pbde is variable */
138 bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, COMMAND_DATA_IN);
139 bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
140 bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
142 /* Word 12 - is zero */
144 /* Word 13, 14, 15 - PBDE is variable */
146 /* IWRITE template */
147 wqe = &lpfc_iwrite_cmd_template;
148 memset(wqe, 0, sizeof(union lpfc_wqe128));
150 /* Word 0, 1, 2 - BDE is variable */
152 /* Word 3 - cmd_buff_len, payload_offset_len is zero */
154 /* Word 4 - total_xfer_len is variable */
156 /* Word 5 - initial_xfer_len is variable */
158 /* Word 6 - ctxt_tag, xri_tag is variable */
161 bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE);
162 bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK);
163 bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3);
164 bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI);
166 /* Word 8 - abort_tag is variable */
168 /* Word 9 - reqtag is variable */
170 /* Word 10 - dbde, wqes is variable */
171 bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0);
172 bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
173 bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4);
174 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
175 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
177 /* Word 11 - pbde is variable */
178 bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, COMMAND_DATA_OUT);
179 bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
180 bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
182 /* Word 12 - is zero */
184 /* Word 13, 14, 15 - PBDE is variable */
187 wqe = &lpfc_icmnd_cmd_template;
188 memset(wqe, 0, sizeof(union lpfc_wqe128));
190 /* Word 0, 1, 2 - BDE is variable */
192 /* Word 3 - payload_offset_len is variable */
194 /* Word 4, 5 - is zero */
196 /* Word 6 - ctxt_tag, xri_tag is variable */
199 bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE);
200 bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
201 bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3);
202 bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI);
204 /* Word 8 - abort_tag is variable */
206 /* Word 9 - reqtag is variable */
208 /* Word 10 - dbde, wqes is variable */
209 bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
210 bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE);
211 bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE);
212 bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
213 bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
216 bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, COMMAND_DATA_IN);
217 bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
218 bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0);
220 /* Word 12, 13, 14, 15 - is zero */
223 #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
225 * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
226 * @srcp: Source memory pointer.
227 * @destp: Destination memory pointer.
228 * @cnt: Number of words required to be copied.
229 * Must be a multiple of sizeof(uint64_t)
231 * This function is used for copying data between driver memory
232 * and the SLI WQ. This function also changes the endianness
233 * of each word if native endianness is different from SLI
234 * endianness. This function can be called with or without
238 lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
240 uint64_t *src = srcp;
241 uint64_t *dest = destp;
244 for (i = 0; i < (int)cnt; i += sizeof(uint64_t))
248 #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
252 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
253 * @q: The Work Queue to operate on.
254 * @wqe: The work Queue Entry to put on the Work queue.
256 * This routine will copy the contents of @wqe to the next available entry on
257 * the @q. This function will then ring the Work Queue Doorbell to signal the
258 * HBA to start processing the Work Queue Entry. This function returns 0 if
259 * successful. If no entries are available on @q then this function will return
261 * The caller is expected to hold the hbalock when calling this routine.
264 lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe)
266 union lpfc_wqe *temp_wqe;
267 struct lpfc_register doorbell;
274 /* sanity check on queue memory */
278 temp_wqe = lpfc_sli4_qe(q, q->host_index);
280 /* If the host has not yet processed the next entry then we are done */
281 idx = ((q->host_index + 1) % q->entry_count);
282 if (idx == q->hba_index) {
287 /* set consumption flag every once in a while */
288 if (!((q->host_index + 1) % q->notify_interval))
289 bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
291 bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
292 if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
293 bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
294 lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
295 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
296 /* write to DPP aperture taking advatage of Combined Writes */
297 tmp = (uint8_t *)temp_wqe;
299 for (i = 0; i < q->entry_size; i += sizeof(uint64_t))
300 __raw_writeq(*((uint64_t *)(tmp + i)),
303 for (i = 0; i < q->entry_size; i += sizeof(uint32_t))
304 __raw_writel(*((uint32_t *)(tmp + i)),
308 /* ensure WQE bcopy and DPP flushed before doorbell write */
311 /* Update the host index before invoking device */
312 host_index = q->host_index;
318 if (q->db_format == LPFC_DB_LIST_FORMAT) {
319 if (q->dpp_enable && q->phba->cfg_enable_dpp) {
320 bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1);
321 bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1);
322 bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell,
324 bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell,
327 bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
328 bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
330 /* Leave bits <23:16> clear for if_type 6 dpp */
331 if_type = bf_get(lpfc_sli_intf_if_type,
332 &q->phba->sli4_hba.sli_intf);
333 if (if_type != LPFC_SLI_INTF_IF_TYPE_6)
334 bf_set(lpfc_wq_db_list_fm_index, &doorbell,
337 } else if (q->db_format == LPFC_DB_RING_FORMAT) {
338 bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
339 bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
343 writel(doorbell.word0, q->db_regaddr);
349 * lpfc_sli4_wq_release - Updates internal hba index for WQ
350 * @q: The Work Queue to operate on.
351 * @index: The index to advance the hba index to.
353 * This routine will update the HBA index of a queue to reflect consumption of
354 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
355 * an entry the host calls this function to update the queue's internal
359 lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
361 /* sanity check on queue memory */
365 q->hba_index = index;
369 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
370 * @q: The Mailbox Queue to operate on.
371 * @mqe: The Mailbox Queue Entry to put on the Work queue.
373 * This routine will copy the contents of @mqe to the next available entry on
374 * the @q. This function will then ring the Work Queue Doorbell to signal the
375 * HBA to start processing the Work Queue Entry. This function returns 0 if
376 * successful. If no entries are available on @q then this function will return
378 * The caller is expected to hold the hbalock when calling this routine.
381 lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
383 struct lpfc_mqe *temp_mqe;
384 struct lpfc_register doorbell;
386 /* sanity check on queue memory */
389 temp_mqe = lpfc_sli4_qe(q, q->host_index);
391 /* If the host has not yet processed the next entry then we are done */
392 if (((q->host_index + 1) % q->entry_count) == q->hba_index)
394 lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
395 /* Save off the mailbox pointer for completion */
396 q->phba->mbox = (MAILBOX_t *)temp_mqe;
398 /* Update the host index before invoking device */
399 q->host_index = ((q->host_index + 1) % q->entry_count);
403 bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
404 bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
405 writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
410 * lpfc_sli4_mq_release - Updates internal hba index for MQ
411 * @q: The Mailbox Queue to operate on.
413 * This routine will update the HBA index of a queue to reflect consumption of
414 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
415 * an entry the host calls this function to update the queue's internal
416 * pointers. This routine returns the number of entries that were consumed by
420 lpfc_sli4_mq_release(struct lpfc_queue *q)
422 /* sanity check on queue memory */
426 /* Clear the mailbox pointer for completion */
427 q->phba->mbox = NULL;
428 q->hba_index = ((q->hba_index + 1) % q->entry_count);
433 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
434 * @q: The Event Queue to get the first valid EQE from
436 * This routine will get the first valid Event Queue Entry from @q, update
437 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
438 * the Queue (no more work to do), or the Queue is full of EQEs that have been
439 * processed, but not popped back to the HBA then this routine will return NULL.
441 static struct lpfc_eqe *
442 lpfc_sli4_eq_get(struct lpfc_queue *q)
444 struct lpfc_eqe *eqe;
446 /* sanity check on queue memory */
449 eqe = lpfc_sli4_qe(q, q->host_index);
451 /* If the next EQE is not valid then we are done */
452 if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid)
456 * insert barrier for instruction interlock : data from the hardware
457 * must have the valid bit checked before it can be copied and acted
458 * upon. Speculative instructions were allowing a bcopy at the start
459 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
460 * after our return, to copy data before the valid bit check above
461 * was done. As such, some of the copied data was stale. The barrier
462 * ensures the check is before any data is copied.
469 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
470 * @q: The Event Queue to disable interrupts
474 lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
476 struct lpfc_register doorbell;
479 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
480 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
481 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
482 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
483 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
484 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
488 * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
489 * @q: The Event Queue to disable interrupts
493 lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q)
495 struct lpfc_register doorbell;
498 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
499 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
503 * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state
504 * @phba: adapter with EQ
505 * @q: The Event Queue that the host has completed processing for.
506 * @count: Number of elements that have been consumed
507 * @arm: Indicates whether the host wants to arms this CQ.
509 * This routine will notify the HBA, by ringing the doorbell, that count
510 * number of EQEs have been processed. The @arm parameter indicates whether
511 * the queue should be rearmed when ringing the doorbell.
514 lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
515 uint32_t count, bool arm)
517 struct lpfc_register doorbell;
519 /* sanity check on queue memory */
520 if (unlikely(!q || (count == 0 && !arm)))
523 /* ring doorbell for number popped */
526 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
527 bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
529 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
530 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
531 bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
532 (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
533 bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
534 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
535 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
536 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
537 readl(q->phba->sli4_hba.EQDBregaddr);
541 * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state
542 * @phba: adapter with EQ
543 * @q: The Event Queue that the host has completed processing for.
544 * @count: Number of elements that have been consumed
545 * @arm: Indicates whether the host wants to arms this CQ.
547 * This routine will notify the HBA, by ringing the doorbell, that count
548 * number of EQEs have been processed. The @arm parameter indicates whether
549 * the queue should be rearmed when ringing the doorbell.
552 lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
553 uint32_t count, bool arm)
555 struct lpfc_register doorbell;
557 /* sanity check on queue memory */
558 if (unlikely(!q || (count == 0 && !arm)))
561 /* ring doorbell for number popped */
564 bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1);
565 bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count);
566 bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
567 writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
568 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
569 if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
570 readl(q->phba->sli4_hba.EQDBregaddr);
574 __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
575 struct lpfc_eqe *eqe)
577 if (!phba->sli4_hba.pc_sli4_params.eqav)
578 bf_set_le32(lpfc_eqe_valid, eqe, 0);
580 eq->host_index = ((eq->host_index + 1) % eq->entry_count);
582 /* if the index wrapped around, toggle the valid bit */
583 if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index)
584 eq->qe_valid = (eq->qe_valid) ? 0 : 1;
588 lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
590 struct lpfc_eqe *eqe = NULL;
591 u32 eq_count = 0, cq_count = 0;
592 struct lpfc_cqe *cqe = NULL;
593 struct lpfc_queue *cq = NULL, *childq = NULL;
596 /* walk all the EQ entries and drop on the floor */
597 eqe = lpfc_sli4_eq_get(eq);
599 /* Get the reference to the corresponding CQ */
600 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
603 list_for_each_entry(childq, &eq->child_list, list) {
604 if (childq->queue_id == cqid) {
609 /* If CQ is valid, iterate through it and drop all the CQEs */
611 cqe = lpfc_sli4_cq_get(cq);
613 __lpfc_sli4_consume_cqe(phba, cq, cqe);
615 cqe = lpfc_sli4_cq_get(cq);
617 /* Clear and re-arm the CQ */
618 phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count,
622 __lpfc_sli4_consume_eqe(phba, eq, eqe);
624 eqe = lpfc_sli4_eq_get(eq);
627 /* Clear and re-arm the EQ */
628 phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM);
632 lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq,
635 struct lpfc_eqe *eqe;
636 int count = 0, consumed = 0;
638 if (cmpxchg(&eq->queue_claimed, 0, 1) != 0)
641 eqe = lpfc_sli4_eq_get(eq);
643 lpfc_sli4_hba_handle_eqe(phba, eq, eqe);
644 __lpfc_sli4_consume_eqe(phba, eq, eqe);
647 if (!(++count % eq->max_proc_limit))
650 if (!(count % eq->notify_interval)) {
651 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed,
656 eqe = lpfc_sli4_eq_get(eq);
658 eq->EQ_processed += count;
660 /* Track the max number of EQEs processed in 1 intr */
661 if (count > eq->EQ_max_eqe)
662 eq->EQ_max_eqe = count;
664 xchg(&eq->queue_claimed, 0);
667 /* Always clear the EQ. */
668 phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm);
674 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
675 * @q: The Completion Queue to get the first valid CQE from
677 * This routine will get the first valid Completion Queue Entry from @q, update
678 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
679 * the Queue (no more work to do), or the Queue is full of CQEs that have been
680 * processed, but not popped back to the HBA then this routine will return NULL.
682 static struct lpfc_cqe *
683 lpfc_sli4_cq_get(struct lpfc_queue *q)
685 struct lpfc_cqe *cqe;
687 /* sanity check on queue memory */
690 cqe = lpfc_sli4_qe(q, q->host_index);
692 /* If the next CQE is not valid then we are done */
693 if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid)
697 * insert barrier for instruction interlock : data from the hardware
698 * must have the valid bit checked before it can be copied and acted
699 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
700 * instructions allowing action on content before valid bit checked,
701 * add barrier here as well. May not be needed as "content" is a
702 * single 32-bit entity here (vs multi word structure for cq's).
709 __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
710 struct lpfc_cqe *cqe)
712 if (!phba->sli4_hba.pc_sli4_params.cqav)
713 bf_set_le32(lpfc_cqe_valid, cqe, 0);
715 cq->host_index = ((cq->host_index + 1) % cq->entry_count);
717 /* if the index wrapped around, toggle the valid bit */
718 if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index)
719 cq->qe_valid = (cq->qe_valid) ? 0 : 1;
723 * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state.
724 * @phba: the adapter with the CQ
725 * @q: The Completion Queue that the host has completed processing for.
726 * @count: the number of elements that were consumed
727 * @arm: Indicates whether the host wants to arms this CQ.
729 * This routine will notify the HBA, by ringing the doorbell, that the
730 * CQEs have been processed. The @arm parameter specifies whether the
731 * queue should be rearmed when ringing the doorbell.
734 lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
735 uint32_t count, bool arm)
737 struct lpfc_register doorbell;
739 /* sanity check on queue memory */
740 if (unlikely(!q || (count == 0 && !arm)))
743 /* ring doorbell for number popped */
746 bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
747 bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
748 bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
749 bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
750 (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
751 bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
752 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
756 * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state.
757 * @phba: the adapter with the CQ
758 * @q: The Completion Queue that the host has completed processing for.
759 * @count: the number of elements that were consumed
760 * @arm: Indicates whether the host wants to arms this CQ.
762 * This routine will notify the HBA, by ringing the doorbell, that the
763 * CQEs have been processed. The @arm parameter specifies whether the
764 * queue should be rearmed when ringing the doorbell.
767 lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
768 uint32_t count, bool arm)
770 struct lpfc_register doorbell;
772 /* sanity check on queue memory */
773 if (unlikely(!q || (count == 0 && !arm)))
776 /* ring doorbell for number popped */
779 bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1);
780 bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count);
781 bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id);
782 writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
786 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
788 * This routine will copy the contents of @wqe to the next available entry on
789 * the @q. This function will then ring the Receive Queue Doorbell to signal the
790 * HBA to start processing the Receive Queue Entry. This function returns the
791 * index that the rqe was copied to if successful. If no entries are available
792 * on @q then this function will return -ENOMEM.
793 * The caller is expected to hold the hbalock when calling this routine.
796 lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
797 struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
799 struct lpfc_rqe *temp_hrqe;
800 struct lpfc_rqe *temp_drqe;
801 struct lpfc_register doorbell;
805 /* sanity check on queue memory */
806 if (unlikely(!hq) || unlikely(!dq))
808 hq_put_index = hq->host_index;
809 dq_put_index = dq->host_index;
810 temp_hrqe = lpfc_sli4_qe(hq, hq_put_index);
811 temp_drqe = lpfc_sli4_qe(dq, dq_put_index);
813 if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
815 if (hq_put_index != dq_put_index)
817 /* If the host has not yet processed the next entry then we are done */
818 if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index)
820 lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
821 lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
823 /* Update the host index to point to the next slot */
824 hq->host_index = ((hq_put_index + 1) % hq->entry_count);
825 dq->host_index = ((dq_put_index + 1) % dq->entry_count);
828 /* Ring The Header Receive Queue Doorbell */
829 if (!(hq->host_index % hq->notify_interval)) {
831 if (hq->db_format == LPFC_DB_RING_FORMAT) {
832 bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
833 hq->notify_interval);
834 bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
835 } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
836 bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
837 hq->notify_interval);
838 bf_set(lpfc_rq_db_list_fm_index, &doorbell,
840 bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
844 writel(doorbell.word0, hq->db_regaddr);
850 * lpfc_sli4_rq_release - Updates internal hba index for RQ
852 * This routine will update the HBA index of a queue to reflect consumption of
853 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
854 * consumed an entry the host calls this function to update the queue's
855 * internal pointers. This routine returns the number of entries that were
856 * consumed by the HBA.
859 lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
861 /* sanity check on queue memory */
862 if (unlikely(!hq) || unlikely(!dq))
865 if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
867 hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
868 dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
873 * lpfc_cmd_iocb - Get next command iocb entry in the ring
874 * @phba: Pointer to HBA context object.
875 * @pring: Pointer to driver SLI ring object.
877 * This function returns pointer to next command iocb entry
878 * in the command ring. The caller must hold hbalock to prevent
879 * other threads consume the next command iocb.
880 * SLI-2/SLI-3 provide different sized iocbs.
882 static inline IOCB_t *
883 lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
885 return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
886 pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
890 * lpfc_resp_iocb - Get next response iocb entry in the ring
891 * @phba: Pointer to HBA context object.
892 * @pring: Pointer to driver SLI ring object.
894 * This function returns pointer to next response iocb entry
895 * in the response ring. The caller must hold hbalock to make sure
896 * that no other thread consume the next response iocb.
897 * SLI-2/SLI-3 provide different sized iocbs.
899 static inline IOCB_t *
900 lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
902 return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
903 pring->sli.sli3.rspidx * phba->iocb_rsp_size);
907 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
908 * @phba: Pointer to HBA context object.
910 * This function is called with hbalock held. This function
911 * allocates a new driver iocb object from the iocb pool. If the
912 * allocation is successful, it returns pointer to the newly
913 * allocated iocb object else it returns NULL.
916 __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
918 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
919 struct lpfc_iocbq * iocbq = NULL;
921 lockdep_assert_held(&phba->hbalock);
923 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
926 if (phba->iocb_cnt > phba->iocb_max)
927 phba->iocb_max = phba->iocb_cnt;
932 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
933 * @phba: Pointer to HBA context object.
934 * @xritag: XRI value.
936 * This function clears the sglq pointer from the array of active
937 * sglq's. The xritag that is passed in is used to index into the
938 * array. Before the xritag can be used it needs to be adjusted
939 * by subtracting the xribase.
941 * Returns sglq ponter = success, NULL = Failure.
944 __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
946 struct lpfc_sglq *sglq;
948 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
949 phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
954 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
955 * @phba: Pointer to HBA context object.
956 * @xritag: XRI value.
958 * This function returns the sglq pointer from the array of active
959 * sglq's. The xritag that is passed in is used to index into the
960 * array. Before the xritag can be used it needs to be adjusted
961 * by subtracting the xribase.
963 * Returns sglq ponter = success, NULL = Failure.
966 __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
968 struct lpfc_sglq *sglq;
970 sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
975 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
976 * @phba: Pointer to HBA context object.
977 * @xritag: xri used in this exchange.
978 * @rrq: The RRQ to be cleared.
982 lpfc_clr_rrq_active(struct lpfc_hba *phba,
984 struct lpfc_node_rrq *rrq)
986 struct lpfc_nodelist *ndlp = NULL;
988 /* Lookup did to verify if did is still active on this vport */
990 ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
995 if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
998 rrq->rrq_stop_time = 0;
1001 mempool_free(rrq, phba->rrq_pool);
1005 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
1006 * @phba: Pointer to HBA context object.
1008 * This function is called with hbalock held. This function
1009 * Checks if stop_time (ratov from setting rrq active) has
1010 * been reached, if it has and the send_rrq flag is set then
1011 * it will call lpfc_send_rrq. If the send_rrq flag is not set
1012 * then it will just call the routine to clear the rrq and
1013 * free the rrq resource.
1014 * The timer is set to the next rrq that is going to expire before
1015 * leaving the routine.
1019 lpfc_handle_rrq_active(struct lpfc_hba *phba)
1021 struct lpfc_node_rrq *rrq;
1022 struct lpfc_node_rrq *nextrrq;
1023 unsigned long next_time;
1024 unsigned long iflags;
1025 LIST_HEAD(send_rrq);
1027 spin_lock_irqsave(&phba->hbalock, iflags);
1028 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1029 next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
1030 list_for_each_entry_safe(rrq, nextrrq,
1031 &phba->active_rrq_list, list) {
1032 if (time_after(jiffies, rrq->rrq_stop_time))
1033 list_move(&rrq->list, &send_rrq);
1034 else if (time_before(rrq->rrq_stop_time, next_time))
1035 next_time = rrq->rrq_stop_time;
1037 spin_unlock_irqrestore(&phba->hbalock, iflags);
1038 if ((!list_empty(&phba->active_rrq_list)) &&
1039 (!(phba->pport->load_flag & FC_UNLOADING)))
1040 mod_timer(&phba->rrq_tmr, next_time);
1041 list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
1042 list_del(&rrq->list);
1043 if (!rrq->send_rrq) {
1044 /* this call will free the rrq */
1045 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1046 } else if (lpfc_send_rrq(phba, rrq)) {
1047 /* if we send the rrq then the completion handler
1048 * will clear the bit in the xribitmap.
1050 lpfc_clr_rrq_active(phba, rrq->xritag,
1057 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
1058 * @vport: Pointer to vport context object.
1059 * @xri: The xri used in the exchange.
1060 * @did: The targets DID for this exchange.
1062 * returns NULL = rrq not found in the phba->active_rrq_list.
1063 * rrq = rrq for this xri and target.
1065 struct lpfc_node_rrq *
1066 lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
1068 struct lpfc_hba *phba = vport->phba;
1069 struct lpfc_node_rrq *rrq;
1070 struct lpfc_node_rrq *nextrrq;
1071 unsigned long iflags;
1073 if (phba->sli_rev != LPFC_SLI_REV4)
1075 spin_lock_irqsave(&phba->hbalock, iflags);
1076 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
1077 if (rrq->vport == vport && rrq->xritag == xri &&
1078 rrq->nlp_DID == did){
1079 list_del(&rrq->list);
1080 spin_unlock_irqrestore(&phba->hbalock, iflags);
1084 spin_unlock_irqrestore(&phba->hbalock, iflags);
1089 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
1090 * @vport: Pointer to vport context object.
1091 * @ndlp: Pointer to the lpfc_node_list structure.
1092 * If ndlp is NULL Remove all active RRQs for this vport from the
1093 * phba->active_rrq_list and clear the rrq.
1094 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
1097 lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1100 struct lpfc_hba *phba = vport->phba;
1101 struct lpfc_node_rrq *rrq;
1102 struct lpfc_node_rrq *nextrrq;
1103 unsigned long iflags;
1104 LIST_HEAD(rrq_list);
1106 if (phba->sli_rev != LPFC_SLI_REV4)
1109 lpfc_sli4_vport_delete_els_xri_aborted(vport);
1110 lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
1112 spin_lock_irqsave(&phba->hbalock, iflags);
1113 list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
1114 if (rrq->vport != vport)
1117 if (!ndlp || ndlp == lpfc_findnode_did(vport, rrq->nlp_DID))
1118 list_move(&rrq->list, &rrq_list);
1121 spin_unlock_irqrestore(&phba->hbalock, iflags);
1123 list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
1124 list_del(&rrq->list);
1125 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1130 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
1131 * @phba: Pointer to HBA context object.
1132 * @ndlp: Targets nodelist pointer for this exchange.
1133 * @xritag: the xri in the bitmap to test.
1135 * This function returns:
1136 * 0 = rrq not active for this xri
1137 * 1 = rrq is valid for this xri.
1140 lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1145 if (!ndlp->active_rrqs_xri_bitmap)
1147 if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1154 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
1155 * @phba: Pointer to HBA context object.
1156 * @ndlp: nodelist pointer for this target.
1157 * @xritag: xri used in this exchange.
1158 * @rxid: Remote Exchange ID.
1159 * @send_rrq: Flag used to determine if we should send rrq els cmd.
1161 * This function takes the hbalock.
1162 * The active bit is always set in the active rrq xri_bitmap even
1163 * if there is no slot avaiable for the other rrq information.
1165 * returns 0 rrq actived for this xri
1166 * < 0 No memory or invalid ndlp.
1169 lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1170 uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
1172 unsigned long iflags;
1173 struct lpfc_node_rrq *rrq;
1179 if (!phba->cfg_enable_rrq)
1182 spin_lock_irqsave(&phba->hbalock, iflags);
1183 if (phba->pport->load_flag & FC_UNLOADING) {
1184 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
1188 if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
1191 if (!ndlp->active_rrqs_xri_bitmap)
1194 if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
1197 spin_unlock_irqrestore(&phba->hbalock, iflags);
1198 rrq = mempool_alloc(phba->rrq_pool, GFP_ATOMIC);
1200 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1201 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
1202 " DID:0x%x Send:%d\n",
1203 xritag, rxid, ndlp->nlp_DID, send_rrq);
1206 if (phba->cfg_enable_rrq == 1)
1207 rrq->send_rrq = send_rrq;
1210 rrq->xritag = xritag;
1211 rrq->rrq_stop_time = jiffies +
1212 msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
1213 rrq->nlp_DID = ndlp->nlp_DID;
1214 rrq->vport = ndlp->vport;
1216 spin_lock_irqsave(&phba->hbalock, iflags);
1217 empty = list_empty(&phba->active_rrq_list);
1218 list_add_tail(&rrq->list, &phba->active_rrq_list);
1219 phba->hba_flag |= HBA_RRQ_ACTIVE;
1221 lpfc_worker_wake_up(phba);
1222 spin_unlock_irqrestore(&phba->hbalock, iflags);
1225 spin_unlock_irqrestore(&phba->hbalock, iflags);
1226 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1227 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
1228 " DID:0x%x Send:%d\n",
1229 xritag, rxid, ndlp->nlp_DID, send_rrq);
1234 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
1235 * @phba: Pointer to HBA context object.
1236 * @piocbq: Pointer to the iocbq.
1238 * The driver calls this function with either the nvme ls ring lock
1239 * or the fc els ring lock held depending on the iocb usage. This function
1240 * gets a new driver sglq object from the sglq list. If the list is not empty
1241 * then it is successful, it returns pointer to the newly allocated sglq
1242 * object else it returns NULL.
1244 static struct lpfc_sglq *
1245 __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1247 struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
1248 struct lpfc_sglq *sglq = NULL;
1249 struct lpfc_sglq *start_sglq = NULL;
1250 struct lpfc_io_buf *lpfc_cmd;
1251 struct lpfc_nodelist *ndlp;
1255 cmnd = get_job_cmnd(phba, piocbq);
1257 if (piocbq->cmd_flag & LPFC_IO_FCP) {
1258 lpfc_cmd = piocbq->io_buf;
1259 ndlp = lpfc_cmd->rdata->pnode;
1260 } else if ((cmnd == CMD_GEN_REQUEST64_CR) &&
1261 !(piocbq->cmd_flag & LPFC_IO_LIBDFC)) {
1262 ndlp = piocbq->ndlp;
1263 } else if (piocbq->cmd_flag & LPFC_IO_LIBDFC) {
1264 if (piocbq->cmd_flag & LPFC_IO_LOOPBACK)
1267 ndlp = piocbq->ndlp;
1269 ndlp = piocbq->ndlp;
1272 spin_lock(&phba->sli4_hba.sgl_list_lock);
1273 list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
1278 if (ndlp && ndlp->active_rrqs_xri_bitmap &&
1279 test_bit(sglq->sli4_lxritag,
1280 ndlp->active_rrqs_xri_bitmap)) {
1281 /* This xri has an rrq outstanding for this DID.
1282 * put it back in the list and get another xri.
1284 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1286 list_remove_head(lpfc_els_sgl_list, sglq,
1287 struct lpfc_sglq, list);
1288 if (sglq == start_sglq) {
1289 list_add_tail(&sglq->list, lpfc_els_sgl_list);
1297 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1298 sglq->state = SGL_ALLOCATED;
1300 spin_unlock(&phba->sli4_hba.sgl_list_lock);
1305 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
1306 * @phba: Pointer to HBA context object.
1307 * @piocbq: Pointer to the iocbq.
1309 * This function is called with the sgl_list lock held. This function
1310 * gets a new driver sglq object from the sglq list. If the
1311 * list is not empty then it is successful, it returns pointer to the newly
1312 * allocated sglq object else it returns NULL.
1315 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
1317 struct list_head *lpfc_nvmet_sgl_list;
1318 struct lpfc_sglq *sglq = NULL;
1320 lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
1322 lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
1324 list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
1327 phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
1328 sglq->state = SGL_ALLOCATED;
1333 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1334 * @phba: Pointer to HBA context object.
1336 * This function is called with no lock held. This function
1337 * allocates a new driver iocb object from the iocb pool. If the
1338 * allocation is successful, it returns pointer to the newly
1339 * allocated iocb object else it returns NULL.
1342 lpfc_sli_get_iocbq(struct lpfc_hba *phba)
1344 struct lpfc_iocbq * iocbq = NULL;
1345 unsigned long iflags;
1347 spin_lock_irqsave(&phba->hbalock, iflags);
1348 iocbq = __lpfc_sli_get_iocbq(phba);
1349 spin_unlock_irqrestore(&phba->hbalock, iflags);
1354 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1355 * @phba: Pointer to HBA context object.
1356 * @iocbq: Pointer to driver iocb object.
1358 * This function is called to release the driver iocb object
1359 * to the iocb pool. The iotag in the iocb object
1360 * does not change for each use of the iocb object. This function
1361 * clears all other fields of the iocb object when it is freed.
1362 * The sqlq structure that holds the xritag and phys and virtual
1363 * mappings for the scatter gather list is retrieved from the
1364 * active array of sglq. The get of the sglq pointer also clears
1365 * the entry in the array. If the status of the IO indiactes that
1366 * this IO was aborted then the sglq entry it put on the
1367 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1368 * IO has good status or fails for any other reason then the sglq
1369 * entry is added to the free list (lpfc_els_sgl_list). The hbalock is
1370 * asserted held in the code path calling this routine.
1373 __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1375 struct lpfc_sglq *sglq;
1376 unsigned long iflag = 0;
1377 struct lpfc_sli_ring *pring;
1379 if (iocbq->sli4_xritag == NO_XRI)
1382 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
1386 if (iocbq->cmd_flag & LPFC_IO_NVMET) {
1387 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1389 sglq->state = SGL_FREED;
1391 list_add_tail(&sglq->list,
1392 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1393 spin_unlock_irqrestore(
1394 &phba->sli4_hba.sgl_list_lock, iflag);
1398 if ((iocbq->cmd_flag & LPFC_EXCHANGE_BUSY) &&
1399 (!(unlikely(pci_channel_offline(phba->pcidev)))) &&
1400 sglq->state != SGL_XRI_ABORTED) {
1401 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1404 /* Check if we can get a reference on ndlp */
1405 if (sglq->ndlp && !lpfc_nlp_get(sglq->ndlp))
1408 list_add(&sglq->list,
1409 &phba->sli4_hba.lpfc_abts_els_sgl_list);
1410 spin_unlock_irqrestore(
1411 &phba->sli4_hba.sgl_list_lock, iflag);
1413 spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
1415 sglq->state = SGL_FREED;
1417 list_add_tail(&sglq->list,
1418 &phba->sli4_hba.lpfc_els_sgl_list);
1419 spin_unlock_irqrestore(
1420 &phba->sli4_hba.sgl_list_lock, iflag);
1421 pring = lpfc_phba_elsring(phba);
1422 /* Check if TXQ queue needs to be serviced */
1423 if (pring && (!list_empty(&pring->txq)))
1424 lpfc_worker_wake_up(phba);
1430 * Clean all volatile data fields, preserve iotag and node struct.
1432 memset_startat(iocbq, 0, wqe);
1433 iocbq->sli4_lxritag = NO_XRI;
1434 iocbq->sli4_xritag = NO_XRI;
1435 iocbq->cmd_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | LPFC_IO_CMF |
1437 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1442 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1443 * @phba: Pointer to HBA context object.
1444 * @iocbq: Pointer to driver iocb object.
1446 * This function is called to release the driver iocb object to the
1447 * iocb pool. The iotag in the iocb object does not change for each
1448 * use of the iocb object. This function clears all other fields of
1449 * the iocb object when it is freed. The hbalock is asserted held in
1450 * the code path calling this routine.
1453 __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1457 * Clean all volatile data fields, preserve iotag and node struct.
1459 memset_startat(iocbq, 0, iocb);
1460 iocbq->sli4_xritag = NO_XRI;
1461 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
1465 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1466 * @phba: Pointer to HBA context object.
1467 * @iocbq: Pointer to driver iocb object.
1469 * This function is called with hbalock held to release driver
1470 * iocb object to the iocb pool. The iotag in the iocb object
1471 * does not change for each use of the iocb object. This function
1472 * clears all other fields of the iocb object when it is freed.
1475 __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1477 lockdep_assert_held(&phba->hbalock);
1479 phba->__lpfc_sli_release_iocbq(phba, iocbq);
1484 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1485 * @phba: Pointer to HBA context object.
1486 * @iocbq: Pointer to driver iocb object.
1488 * This function is called with no lock held to release the iocb to
1492 lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1494 unsigned long iflags;
1497 * Clean all volatile data fields, preserve iotag and node struct.
1499 spin_lock_irqsave(&phba->hbalock, iflags);
1500 __lpfc_sli_release_iocbq(phba, iocbq);
1501 spin_unlock_irqrestore(&phba->hbalock, iflags);
1505 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1506 * @phba: Pointer to HBA context object.
1507 * @iocblist: List of IOCBs.
1508 * @ulpstatus: ULP status in IOCB command field.
1509 * @ulpWord4: ULP word-4 in IOCB command field.
1511 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1512 * on the list by invoking the complete callback function associated with the
1513 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1517 lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
1518 uint32_t ulpstatus, uint32_t ulpWord4)
1520 struct lpfc_iocbq *piocb;
1522 while (!list_empty(iocblist)) {
1523 list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
1524 if (piocb->cmd_cmpl) {
1525 if (piocb->cmd_flag & LPFC_IO_NVME) {
1526 lpfc_nvme_cancel_iocb(phba, piocb,
1527 ulpstatus, ulpWord4);
1529 if (phba->sli_rev == LPFC_SLI_REV4) {
1530 bf_set(lpfc_wcqe_c_status,
1531 &piocb->wcqe_cmpl, ulpstatus);
1532 piocb->wcqe_cmpl.parameter = ulpWord4;
1534 piocb->iocb.ulpStatus = ulpstatus;
1535 piocb->iocb.un.ulpWord[4] = ulpWord4;
1537 (piocb->cmd_cmpl) (phba, piocb, piocb);
1540 lpfc_sli_release_iocbq(phba, piocb);
1547 * lpfc_sli_iocb_cmd_type - Get the iocb type
1548 * @iocb_cmnd: iocb command code.
1550 * This function is called by ring event handler function to get the iocb type.
1551 * This function translates the iocb command to an iocb command type used to
1552 * decide the final disposition of each completed IOCB.
1553 * The function returns
1554 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1555 * LPFC_SOL_IOCB if it is a solicited iocb completion
1556 * LPFC_ABORT_IOCB if it is an abort iocb
1557 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1559 * The caller is not required to hold any lock.
1561 static lpfc_iocb_type
1562 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
1564 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
1566 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
1569 switch (iocb_cmnd) {
1570 case CMD_XMIT_SEQUENCE_CR:
1571 case CMD_XMIT_SEQUENCE_CX:
1572 case CMD_XMIT_BCAST_CN:
1573 case CMD_XMIT_BCAST_CX:
1574 case CMD_ELS_REQUEST_CR:
1575 case CMD_ELS_REQUEST_CX:
1576 case CMD_CREATE_XRI_CR:
1577 case CMD_CREATE_XRI_CX:
1578 case CMD_GET_RPI_CN:
1579 case CMD_XMIT_ELS_RSP_CX:
1580 case CMD_GET_RPI_CR:
1581 case CMD_FCP_IWRITE_CR:
1582 case CMD_FCP_IWRITE_CX:
1583 case CMD_FCP_IREAD_CR:
1584 case CMD_FCP_IREAD_CX:
1585 case CMD_FCP_ICMND_CR:
1586 case CMD_FCP_ICMND_CX:
1587 case CMD_FCP_TSEND_CX:
1588 case CMD_FCP_TRSP_CX:
1589 case CMD_FCP_TRECEIVE_CX:
1590 case CMD_FCP_AUTO_TRSP_CX:
1591 case CMD_ADAPTER_MSG:
1592 case CMD_ADAPTER_DUMP:
1593 case CMD_XMIT_SEQUENCE64_CR:
1594 case CMD_XMIT_SEQUENCE64_CX:
1595 case CMD_XMIT_BCAST64_CN:
1596 case CMD_XMIT_BCAST64_CX:
1597 case CMD_ELS_REQUEST64_CR:
1598 case CMD_ELS_REQUEST64_CX:
1599 case CMD_FCP_IWRITE64_CR:
1600 case CMD_FCP_IWRITE64_CX:
1601 case CMD_FCP_IREAD64_CR:
1602 case CMD_FCP_IREAD64_CX:
1603 case CMD_FCP_ICMND64_CR:
1604 case CMD_FCP_ICMND64_CX:
1605 case CMD_FCP_TSEND64_CX:
1606 case CMD_FCP_TRSP64_CX:
1607 case CMD_FCP_TRECEIVE64_CX:
1608 case CMD_GEN_REQUEST64_CR:
1609 case CMD_GEN_REQUEST64_CX:
1610 case CMD_XMIT_ELS_RSP64_CX:
1611 case DSSCMD_IWRITE64_CR:
1612 case DSSCMD_IWRITE64_CX:
1613 case DSSCMD_IREAD64_CR:
1614 case DSSCMD_IREAD64_CX:
1615 case CMD_SEND_FRAME:
1616 type = LPFC_SOL_IOCB;
1618 case CMD_ABORT_XRI_CN:
1619 case CMD_ABORT_XRI_CX:
1620 case CMD_CLOSE_XRI_CN:
1621 case CMD_CLOSE_XRI_CX:
1622 case CMD_XRI_ABORTED_CX:
1623 case CMD_ABORT_MXRI64_CN:
1624 case CMD_XMIT_BLS_RSP64_CX:
1625 type = LPFC_ABORT_IOCB;
1627 case CMD_RCV_SEQUENCE_CX:
1628 case CMD_RCV_ELS_REQ_CX:
1629 case CMD_RCV_SEQUENCE64_CX:
1630 case CMD_RCV_ELS_REQ64_CX:
1631 case CMD_ASYNC_STATUS:
1632 case CMD_IOCB_RCV_SEQ64_CX:
1633 case CMD_IOCB_RCV_ELS64_CX:
1634 case CMD_IOCB_RCV_CONT64_CX:
1635 case CMD_IOCB_RET_XRI64_CX:
1636 type = LPFC_UNSOL_IOCB;
1638 case CMD_IOCB_XMIT_MSEQ64_CR:
1639 case CMD_IOCB_XMIT_MSEQ64_CX:
1640 case CMD_IOCB_RCV_SEQ_LIST64_CX:
1641 case CMD_IOCB_RCV_ELS_LIST64_CX:
1642 case CMD_IOCB_CLOSE_EXTENDED_CN:
1643 case CMD_IOCB_ABORT_EXTENDED_CN:
1644 case CMD_IOCB_RET_HBQE64_CN:
1645 case CMD_IOCB_FCP_IBIDIR64_CR:
1646 case CMD_IOCB_FCP_IBIDIR64_CX:
1647 case CMD_IOCB_FCP_ITASKMGT64_CX:
1648 case CMD_IOCB_LOGENTRY_CN:
1649 case CMD_IOCB_LOGENTRY_ASYNC_CN:
1650 printk("%s - Unhandled SLI-3 Command x%x\n",
1651 __func__, iocb_cmnd);
1652 type = LPFC_UNKNOWN_IOCB;
1655 type = LPFC_UNKNOWN_IOCB;
1663 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1664 * @phba: Pointer to HBA context object.
1666 * This function is called from SLI initialization code
1667 * to configure every ring of the HBA's SLI interface. The
1668 * caller is not required to hold any lock. This function issues
1669 * a config_ring mailbox command for each ring.
1670 * This function returns zero if successful else returns a negative
1674 lpfc_sli_ring_map(struct lpfc_hba *phba)
1676 struct lpfc_sli *psli = &phba->sli;
1681 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1685 phba->link_state = LPFC_INIT_MBX_CMDS;
1686 for (i = 0; i < psli->num_rings; i++) {
1687 lpfc_config_ring(phba, i, pmb);
1688 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1689 if (rc != MBX_SUCCESS) {
1690 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1691 "0446 Adapter failed to init (%d), "
1692 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1694 rc, pmbox->mbxCommand,
1695 pmbox->mbxStatus, i);
1696 phba->link_state = LPFC_HBA_ERROR;
1701 mempool_free(pmb, phba->mbox_mem_pool);
1706 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1707 * @phba: Pointer to HBA context object.
1708 * @pring: Pointer to driver SLI ring object.
1709 * @piocb: Pointer to the driver iocb object.
1711 * The driver calls this function with the hbalock held for SLI3 ports or
1712 * the ring lock held for SLI4 ports. The function adds the
1713 * new iocb to txcmplq of the given ring. This function always returns
1714 * 0. If this function is called for ELS ring, this function checks if
1715 * there is a vport associated with the ELS command. This function also
1716 * starts els_tmofunc timer if this is an ELS command.
1719 lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1720 struct lpfc_iocbq *piocb)
1722 u32 ulp_command = 0;
1725 ulp_command = get_job_cmnd(phba, piocb);
1727 list_add_tail(&piocb->list, &pring->txcmplq);
1728 piocb->cmd_flag |= LPFC_IO_ON_TXCMPLQ;
1729 pring->txcmplq_cnt++;
1730 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1731 (ulp_command != CMD_ABORT_XRI_WQE) &&
1732 (ulp_command != CMD_ABORT_XRI_CN) &&
1733 (ulp_command != CMD_CLOSE_XRI_CN)) {
1734 BUG_ON(!piocb->vport);
1735 if (!(piocb->vport->load_flag & FC_UNLOADING))
1736 mod_timer(&piocb->vport->els_tmofunc,
1738 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1745 * lpfc_sli_ringtx_get - Get first element of the txq
1746 * @phba: Pointer to HBA context object.
1747 * @pring: Pointer to driver SLI ring object.
1749 * This function is called with hbalock held to get next
1750 * iocb in txq of the given ring. If there is any iocb in
1751 * the txq, the function returns first iocb in the list after
1752 * removing the iocb from the list, else it returns NULL.
1755 lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1757 struct lpfc_iocbq *cmd_iocb;
1759 lockdep_assert_held(&phba->hbalock);
1761 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
1766 * lpfc_cmf_sync_cmpl - Process a CMF_SYNC_WQE cmpl
1767 * @phba: Pointer to HBA context object.
1768 * @cmdiocb: Pointer to driver command iocb object.
1769 * @rspiocb: Pointer to driver response iocb object.
1771 * This routine will inform the driver of any BW adjustments we need
1772 * to make. These changes will be picked up during the next CMF
1773 * timer interrupt. In addition, any BW changes will be logged
1774 * with LOG_CGN_MGMT.
1777 lpfc_cmf_sync_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1778 struct lpfc_iocbq *rspiocb)
1780 union lpfc_wqe128 *wqe;
1781 uint32_t status, info;
1782 struct lpfc_wcqe_complete *wcqe = &rspiocb->wcqe_cmpl;
1783 uint64_t bw, bwdif, slop;
1784 uint64_t pcent, bwpcent;
1785 int asig, afpin, sigcnt, fpincnt;
1786 int wsigmax, wfpinmax, cg, tdp;
1789 /* First check for error */
1790 status = bf_get(lpfc_wcqe_c_status, wcqe);
1792 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1793 "6211 CMF_SYNC_WQE Error "
1794 "req_tag x%x status x%x hwstatus x%x "
1795 "tdatap x%x parm x%x\n",
1796 bf_get(lpfc_wcqe_c_request_tag, wcqe),
1797 bf_get(lpfc_wcqe_c_status, wcqe),
1798 bf_get(lpfc_wcqe_c_hw_status, wcqe),
1799 wcqe->total_data_placed,
1804 /* Gather congestion information on a successful cmpl */
1805 info = wcqe->parameter;
1806 phba->cmf_active_info = info;
1808 /* See if firmware info count is valid or has changed */
1809 if (info > LPFC_MAX_CMF_INFO || phba->cmf_info_per_interval == info)
1812 phba->cmf_info_per_interval = info;
1814 tdp = bf_get(lpfc_wcqe_c_cmf_bw, wcqe);
1815 cg = bf_get(lpfc_wcqe_c_cmf_cg, wcqe);
1817 /* Get BW requirement from firmware */
1818 bw = (uint64_t)tdp * LPFC_CMF_BLK_SIZE;
1820 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1821 "6212 CMF_SYNC_WQE x%x: NULL bw\n",
1822 bf_get(lpfc_wcqe_c_request_tag, wcqe));
1826 /* Gather information needed for logging if a BW change is required */
1827 wqe = &cmdiocb->wqe;
1828 asig = bf_get(cmf_sync_asig, &wqe->cmf_sync);
1829 afpin = bf_get(cmf_sync_afpin, &wqe->cmf_sync);
1830 fpincnt = bf_get(cmf_sync_wfpincnt, &wqe->cmf_sync);
1831 sigcnt = bf_get(cmf_sync_wsigcnt, &wqe->cmf_sync);
1832 if (phba->cmf_max_bytes_per_interval != bw ||
1833 (asig || afpin || sigcnt || fpincnt)) {
1834 /* Are we increasing or decreasing BW */
1835 if (phba->cmf_max_bytes_per_interval < bw) {
1836 bwdif = bw - phba->cmf_max_bytes_per_interval;
1839 bwdif = phba->cmf_max_bytes_per_interval - bw;
1843 /* What is the change percentage */
1844 slop = div_u64(phba->cmf_link_byte_count, 200); /*For rounding*/
1845 pcent = div64_u64(bwdif * 100 + slop,
1846 phba->cmf_link_byte_count);
1847 bwpcent = div64_u64(bw * 100 + slop,
1848 phba->cmf_link_byte_count);
1849 /* Because of bytes adjustment due to shorter timer in
1850 * lpfc_cmf_timer() the cmf_link_byte_count can be shorter and
1851 * may seem like BW is above 100%.
1856 if (phba->cmf_max_bytes_per_interval < bw &&
1858 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1859 "6208 Congestion bandwidth "
1860 "limits removed\n");
1861 else if ((phba->cmf_max_bytes_per_interval > bw) &&
1862 ((bwpcent + pcent) <= 100) && ((bwpcent + pcent) > 95))
1863 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1864 "6209 Congestion bandwidth "
1865 "limits in effect\n");
1868 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1869 "6237 BW Threshold %lld%% (%lld): "
1870 "%lld%% %s: Signal Alarm: cg:%d "
1872 bwpcent, bw, pcent, s, cg,
1873 phba->cmf_active_info);
1875 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1876 "6238 BW Threshold %lld%% (%lld): "
1877 "%lld%% %s: FPIN Alarm: cg:%d "
1879 bwpcent, bw, pcent, s, cg,
1880 phba->cmf_active_info);
1881 } else if (sigcnt) {
1882 wsigmax = bf_get(cmf_sync_wsigmax, &wqe->cmf_sync);
1883 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1884 "6239 BW Threshold %lld%% (%lld): "
1885 "%lld%% %s: Signal Warning: "
1886 "Cnt %d Max %d: cg:%d Info:%u\n",
1887 bwpcent, bw, pcent, s, sigcnt,
1888 wsigmax, cg, phba->cmf_active_info);
1889 } else if (fpincnt) {
1890 wfpinmax = bf_get(cmf_sync_wfpinmax, &wqe->cmf_sync);
1891 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1892 "6240 BW Threshold %lld%% (%lld): "
1893 "%lld%% %s: FPIN Warning: "
1894 "Cnt %d Max %d: cg:%d Info:%u\n",
1895 bwpcent, bw, pcent, s, fpincnt,
1896 wfpinmax, cg, phba->cmf_active_info);
1898 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1899 "6241 BW Threshold %lld%% (%lld): "
1900 "CMF %lld%% %s: cg:%d Info:%u\n",
1901 bwpcent, bw, pcent, s, cg,
1902 phba->cmf_active_info);
1905 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1906 "6246 Info Threshold %u\n", info);
1909 /* Save BW change to be picked up during next timer interrupt */
1910 phba->cmf_last_sync_bw = bw;
1912 lpfc_sli_release_iocbq(phba, cmdiocb);
1916 * lpfc_issue_cmf_sync_wqe - Issue a CMF_SYNC_WQE
1917 * @phba: Pointer to HBA context object.
1918 * @ms: ms to set in WQE interval, 0 means use init op
1919 * @total: Total rcv bytes for this interval
1921 * This routine is called every CMF timer interrupt. Its purpose is
1922 * to issue a CMF_SYNC_WQE to the firmware to inform it of any events
1923 * that may indicate we have congestion (FPINs or Signals). Upon
1924 * completion, the firmware will indicate any BW restrictions the
1925 * driver may need to take.
1928 lpfc_issue_cmf_sync_wqe(struct lpfc_hba *phba, u32 ms, u64 total)
1930 union lpfc_wqe128 *wqe;
1931 struct lpfc_iocbq *sync_buf;
1932 unsigned long iflags;
1934 u32 atot, wtot, max;
1935 u16 warn_sync_period = 0;
1937 /* First address any alarm / warning activity */
1938 atot = atomic_xchg(&phba->cgn_sync_alarm_cnt, 0);
1939 wtot = atomic_xchg(&phba->cgn_sync_warn_cnt, 0);
1941 /* ONLY Managed mode will send the CMF_SYNC_WQE to the HBA */
1942 if (phba->cmf_active_mode != LPFC_CFG_MANAGED ||
1943 phba->link_state == LPFC_LINK_DOWN)
1946 spin_lock_irqsave(&phba->hbalock, iflags);
1947 sync_buf = __lpfc_sli_get_iocbq(phba);
1949 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
1950 "6244 No available WQEs for CMF_SYNC_WQE\n");
1955 wqe = &sync_buf->wqe;
1957 /* WQEs are reused. Clear stale data and set key fields to zero */
1958 memset(wqe, 0, sizeof(*wqe));
1960 /* If this is the very first CMF_SYNC_WQE, issue an init operation */
1962 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
1963 "6441 CMF Init %d - CMF_SYNC_WQE\n",
1965 bf_set(cmf_sync_op, &wqe->cmf_sync, 1); /* 1=init */
1966 bf_set(cmf_sync_interval, &wqe->cmf_sync, LPFC_CMF_INTERVAL);
1970 bf_set(cmf_sync_op, &wqe->cmf_sync, 0); /* 0=recalc */
1971 bf_set(cmf_sync_interval, &wqe->cmf_sync, ms);
1973 /* Check for alarms / warnings */
1975 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
1976 /* We hit an Signal alarm condition */
1977 bf_set(cmf_sync_asig, &wqe->cmf_sync, 1);
1979 /* We hit a FPIN alarm condition */
1980 bf_set(cmf_sync_afpin, &wqe->cmf_sync, 1);
1983 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
1984 phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
1985 /* We hit an Signal warning condition */
1986 max = LPFC_SEC_TO_MSEC / lpfc_fabric_cgn_frequency *
1987 lpfc_acqe_cgn_frequency;
1988 bf_set(cmf_sync_wsigmax, &wqe->cmf_sync, max);
1989 bf_set(cmf_sync_wsigcnt, &wqe->cmf_sync, wtot);
1990 warn_sync_period = lpfc_acqe_cgn_frequency;
1992 /* We hit a FPIN warning condition */
1993 bf_set(cmf_sync_wfpinmax, &wqe->cmf_sync, 1);
1994 bf_set(cmf_sync_wfpincnt, &wqe->cmf_sync, 1);
1995 if (phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ)
1997 LPFC_MSECS_TO_SECS(phba->cgn_fpin_frequency);
2001 /* Update total read blocks during previous timer interval */
2002 wqe->cmf_sync.read_bytes = (u32)(total / LPFC_CMF_BLK_SIZE);
2005 bf_set(cmf_sync_ver, &wqe->cmf_sync, LPFC_CMF_SYNC_VER);
2006 wqe->cmf_sync.event_tag = phba->fc_eventTag;
2007 bf_set(cmf_sync_cmnd, &wqe->cmf_sync, CMD_CMF_SYNC_WQE);
2009 /* Setup reqtag to match the wqe completion. */
2010 bf_set(cmf_sync_reqtag, &wqe->cmf_sync, sync_buf->iotag);
2012 bf_set(cmf_sync_qosd, &wqe->cmf_sync, 1);
2013 bf_set(cmf_sync_period, &wqe->cmf_sync, warn_sync_period);
2015 bf_set(cmf_sync_cmd_type, &wqe->cmf_sync, CMF_SYNC_COMMAND);
2016 bf_set(cmf_sync_wqec, &wqe->cmf_sync, 1);
2017 bf_set(cmf_sync_cqid, &wqe->cmf_sync, LPFC_WQE_CQ_ID_DEFAULT);
2019 sync_buf->vport = phba->pport;
2020 sync_buf->cmd_cmpl = lpfc_cmf_sync_cmpl;
2021 sync_buf->cmd_dmabuf = NULL;
2022 sync_buf->rsp_dmabuf = NULL;
2023 sync_buf->bpl_dmabuf = NULL;
2024 sync_buf->sli4_xritag = NO_XRI;
2026 sync_buf->cmd_flag |= LPFC_IO_CMF;
2027 ret_val = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], sync_buf);
2029 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
2030 "6214 Cannot issue CMF_SYNC_WQE: x%x\n",
2032 __lpfc_sli_release_iocbq(phba, sync_buf);
2035 spin_unlock_irqrestore(&phba->hbalock, iflags);
2040 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
2041 * @phba: Pointer to HBA context object.
2042 * @pring: Pointer to driver SLI ring object.
2044 * This function is called with hbalock held and the caller must post the
2045 * iocb without releasing the lock. If the caller releases the lock,
2046 * iocb slot returned by the function is not guaranteed to be available.
2047 * The function returns pointer to the next available iocb slot if there
2048 * is available slot in the ring, else it returns NULL.
2049 * If the get index of the ring is ahead of the put index, the function
2050 * will post an error attention event to the worker thread to take the
2051 * HBA to offline state.
2054 lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2056 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
2057 uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
2059 lockdep_assert_held(&phba->hbalock);
2061 if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
2062 (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
2063 pring->sli.sli3.next_cmdidx = 0;
2065 if (unlikely(pring->sli.sli3.local_getidx ==
2066 pring->sli.sli3.next_cmdidx)) {
2068 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
2070 if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
2071 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2072 "0315 Ring %d issue: portCmdGet %d "
2073 "is bigger than cmd ring %d\n",
2075 pring->sli.sli3.local_getidx,
2078 phba->link_state = LPFC_HBA_ERROR;
2080 * All error attention handlers are posted to
2083 phba->work_ha |= HA_ERATT;
2084 phba->work_hs = HS_FFER3;
2086 lpfc_worker_wake_up(phba);
2091 if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
2095 return lpfc_cmd_iocb(phba, pring);
2099 * lpfc_sli_next_iotag - Get an iotag for the iocb
2100 * @phba: Pointer to HBA context object.
2101 * @iocbq: Pointer to driver iocb object.
2103 * This function gets an iotag for the iocb. If there is no unused iotag and
2104 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
2105 * array and assigns a new iotag.
2106 * The function returns the allocated iotag if successful, else returns zero.
2107 * Zero is not a valid iotag.
2108 * The caller is not required to hold any lock.
2111 lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
2113 struct lpfc_iocbq **new_arr;
2114 struct lpfc_iocbq **old_arr;
2116 struct lpfc_sli *psli = &phba->sli;
2119 spin_lock_irq(&phba->hbalock);
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;
2127 } else if (psli->iocbq_lookup_len < (0xffff
2128 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
2129 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
2130 spin_unlock_irq(&phba->hbalock);
2131 new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
2134 spin_lock_irq(&phba->hbalock);
2135 old_arr = psli->iocbq_lookup;
2136 if (new_len <= psli->iocbq_lookup_len) {
2137 /* highly unprobable case */
2139 iotag = psli->last_iotag;
2140 if(++iotag < psli->iocbq_lookup_len) {
2141 psli->last_iotag = iotag;
2142 psli->iocbq_lookup[iotag] = iocbq;
2143 spin_unlock_irq(&phba->hbalock);
2144 iocbq->iotag = iotag;
2147 spin_unlock_irq(&phba->hbalock);
2150 if (psli->iocbq_lookup)
2151 memcpy(new_arr, old_arr,
2152 ((psli->last_iotag + 1) *
2153 sizeof (struct lpfc_iocbq *)));
2154 psli->iocbq_lookup = new_arr;
2155 psli->iocbq_lookup_len = new_len;
2156 psli->last_iotag = iotag;
2157 psli->iocbq_lookup[iotag] = iocbq;
2158 spin_unlock_irq(&phba->hbalock);
2159 iocbq->iotag = iotag;
2164 spin_unlock_irq(&phba->hbalock);
2166 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2167 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
2174 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
2175 * @phba: Pointer to HBA context object.
2176 * @pring: Pointer to driver SLI ring object.
2177 * @iocb: Pointer to iocb slot in the ring.
2178 * @nextiocb: Pointer to driver iocb object which need to be
2179 * posted to firmware.
2181 * This function is called to post a new iocb to the firmware. This
2182 * function copies the new iocb to ring iocb slot and updates the
2183 * ring pointers. It adds the new iocb to txcmplq if there is
2184 * a completion call back for this iocb else the function will free the
2185 * iocb object. The hbalock is asserted held in the code path calling
2189 lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2190 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
2195 nextiocb->iocb.ulpIoTag = (nextiocb->cmd_cmpl) ? nextiocb->iotag : 0;
2198 if (pring->ringno == LPFC_ELS_RING) {
2199 lpfc_debugfs_slow_ring_trc(phba,
2200 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2201 *(((uint32_t *) &nextiocb->iocb) + 4),
2202 *(((uint32_t *) &nextiocb->iocb) + 6),
2203 *(((uint32_t *) &nextiocb->iocb) + 7));
2207 * Issue iocb command to adapter
2209 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
2211 pring->stats.iocb_cmd++;
2214 * If there is no completion routine to call, we can release the
2215 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
2216 * that have no rsp ring completion, cmd_cmpl MUST be NULL.
2218 if (nextiocb->cmd_cmpl)
2219 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
2221 __lpfc_sli_release_iocbq(phba, nextiocb);
2224 * Let the HBA know what IOCB slot will be the next one the
2225 * driver will put a command into.
2227 pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
2228 writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
2232 * lpfc_sli_update_full_ring - Update the chip attention register
2233 * @phba: Pointer to HBA context object.
2234 * @pring: Pointer to driver SLI ring object.
2236 * The caller is not required to hold any lock for calling this function.
2237 * This function updates the chip attention bits for the ring to inform firmware
2238 * that there are pending work to be done for this ring and requests an
2239 * interrupt when there is space available in the ring. This function is
2240 * called when the driver is unable to post more iocbs to the ring due
2241 * to unavailability of space in the ring.
2244 lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2246 int ringno = pring->ringno;
2248 pring->flag |= LPFC_CALL_RING_AVAILABLE;
2253 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
2254 * The HBA will tell us when an IOCB entry is available.
2256 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
2257 readl(phba->CAregaddr); /* flush */
2259 pring->stats.iocb_cmd_full++;
2263 * lpfc_sli_update_ring - Update chip attention register
2264 * @phba: Pointer to HBA context object.
2265 * @pring: Pointer to driver SLI ring object.
2267 * This function updates the chip attention register bit for the
2268 * given ring to inform HBA that there is more work to be done
2269 * in this ring. The caller is not required to hold any lock.
2272 lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2274 int ringno = pring->ringno;
2277 * Tell the HBA that there is work to do in this ring.
2279 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
2281 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
2282 readl(phba->CAregaddr); /* flush */
2287 * lpfc_sli_resume_iocb - Process iocbs in the txq
2288 * @phba: Pointer to HBA context object.
2289 * @pring: Pointer to driver SLI ring object.
2291 * This function is called with hbalock held to post pending iocbs
2292 * in the txq to the firmware. This function is called when driver
2293 * detects space available in the ring.
2296 lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2299 struct lpfc_iocbq *nextiocb;
2301 lockdep_assert_held(&phba->hbalock);
2305 * (a) there is anything on the txq to send
2307 * (c) link attention events can be processed (fcp ring only)
2308 * (d) IOCB processing is not blocked by the outstanding mbox command.
2311 if (lpfc_is_link_up(phba) &&
2312 (!list_empty(&pring->txq)) &&
2313 (pring->ringno != LPFC_FCP_RING ||
2314 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
2316 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2317 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
2318 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
2321 lpfc_sli_update_ring(phba, pring);
2323 lpfc_sli_update_full_ring(phba, pring);
2330 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
2331 * @phba: Pointer to HBA context object.
2332 * @hbqno: HBQ number.
2334 * This function is called with hbalock held to get the next
2335 * available slot for the given HBQ. If there is free slot
2336 * available for the HBQ it will return pointer to the next available
2337 * HBQ entry else it will return NULL.
2339 static struct lpfc_hbq_entry *
2340 lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
2342 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2344 lockdep_assert_held(&phba->hbalock);
2346 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
2347 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
2348 hbqp->next_hbqPutIdx = 0;
2350 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
2351 uint32_t raw_index = phba->hbq_get[hbqno];
2352 uint32_t getidx = le32_to_cpu(raw_index);
2354 hbqp->local_hbqGetIdx = getidx;
2356 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
2357 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2358 "1802 HBQ %d: local_hbqGetIdx "
2359 "%u is > than hbqp->entry_count %u\n",
2360 hbqno, hbqp->local_hbqGetIdx,
2363 phba->link_state = LPFC_HBA_ERROR;
2367 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
2371 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
2376 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
2377 * @phba: Pointer to HBA context object.
2379 * This function is called with no lock held to free all the
2380 * hbq buffers while uninitializing the SLI interface. It also
2381 * frees the HBQ buffers returned by the firmware but not yet
2382 * processed by the upper layers.
2385 lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
2387 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
2388 struct hbq_dmabuf *hbq_buf;
2389 unsigned long flags;
2392 hbq_count = lpfc_sli_hbq_count();
2393 /* Return all memory used by all HBQs */
2394 spin_lock_irqsave(&phba->hbalock, flags);
2395 for (i = 0; i < hbq_count; ++i) {
2396 list_for_each_entry_safe(dmabuf, next_dmabuf,
2397 &phba->hbqs[i].hbq_buffer_list, list) {
2398 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
2399 list_del(&hbq_buf->dbuf.list);
2400 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
2402 phba->hbqs[i].buffer_count = 0;
2405 /* Mark the HBQs not in use */
2406 phba->hbq_in_use = 0;
2407 spin_unlock_irqrestore(&phba->hbalock, flags);
2411 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
2412 * @phba: Pointer to HBA context object.
2413 * @hbqno: HBQ number.
2414 * @hbq_buf: Pointer to HBQ buffer.
2416 * This function is called with the hbalock held to post a
2417 * hbq buffer to the firmware. If the function finds an empty
2418 * slot in the HBQ, it will post the buffer. The function will return
2419 * pointer to the hbq entry if it successfully post the buffer
2420 * else it will return NULL.
2423 lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
2424 struct hbq_dmabuf *hbq_buf)
2426 lockdep_assert_held(&phba->hbalock);
2427 return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
2431 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
2432 * @phba: Pointer to HBA context object.
2433 * @hbqno: HBQ number.
2434 * @hbq_buf: Pointer to HBQ buffer.
2436 * This function is called with the hbalock held to post a hbq buffer to the
2437 * firmware. If the function finds an empty slot in the HBQ, it will post the
2438 * buffer and place it on the hbq_buffer_list. The function will return zero if
2439 * it successfully post the buffer else it will return an error.
2442 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
2443 struct hbq_dmabuf *hbq_buf)
2445 struct lpfc_hbq_entry *hbqe;
2446 dma_addr_t physaddr = hbq_buf->dbuf.phys;
2448 lockdep_assert_held(&phba->hbalock);
2449 /* Get next HBQ entry slot to use */
2450 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
2452 struct hbq_s *hbqp = &phba->hbqs[hbqno];
2454 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
2455 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
2456 hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
2457 hbqe->bde.tus.f.bdeFlags = 0;
2458 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
2459 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
2461 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
2462 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
2464 readl(phba->hbq_put + hbqno);
2465 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
2472 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
2473 * @phba: Pointer to HBA context object.
2474 * @hbqno: HBQ number.
2475 * @hbq_buf: Pointer to HBQ buffer.
2477 * This function is called with the hbalock held to post an RQE to the SLI4
2478 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
2479 * the hbq_buffer_list and return zero, otherwise it will return an error.
2482 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
2483 struct hbq_dmabuf *hbq_buf)
2486 struct lpfc_rqe hrqe;
2487 struct lpfc_rqe drqe;
2488 struct lpfc_queue *hrq;
2489 struct lpfc_queue *drq;
2491 if (hbqno != LPFC_ELS_HBQ)
2493 hrq = phba->sli4_hba.hdr_rq;
2494 drq = phba->sli4_hba.dat_rq;
2496 lockdep_assert_held(&phba->hbalock);
2497 hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
2498 hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
2499 drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
2500 drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
2501 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
2504 hbq_buf->tag = (rc | (hbqno << 16));
2505 list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
2509 /* HBQ for ELS and CT traffic. */
2510 static struct lpfc_hbq_init lpfc_els_hbq = {
2515 .ring_mask = (1 << LPFC_ELS_RING),
2522 struct lpfc_hbq_init *lpfc_hbq_defs[] = {
2527 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
2528 * @phba: Pointer to HBA context object.
2529 * @hbqno: HBQ number.
2530 * @count: Number of HBQ buffers to be posted.
2532 * This function is called with no lock held to post more hbq buffers to the
2533 * given HBQ. The function returns the number of HBQ buffers successfully
2537 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
2539 uint32_t i, posted = 0;
2540 unsigned long flags;
2541 struct hbq_dmabuf *hbq_buffer;
2542 LIST_HEAD(hbq_buf_list);
2543 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
2546 if ((phba->hbqs[hbqno].buffer_count + count) >
2547 lpfc_hbq_defs[hbqno]->entry_count)
2548 count = lpfc_hbq_defs[hbqno]->entry_count -
2549 phba->hbqs[hbqno].buffer_count;
2552 /* Allocate HBQ entries */
2553 for (i = 0; i < count; i++) {
2554 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
2557 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
2559 /* Check whether HBQ is still in use */
2560 spin_lock_irqsave(&phba->hbalock, flags);
2561 if (!phba->hbq_in_use)
2563 while (!list_empty(&hbq_buf_list)) {
2564 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2566 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
2568 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
2569 phba->hbqs[hbqno].buffer_count++;
2572 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2574 spin_unlock_irqrestore(&phba->hbalock, flags);
2577 spin_unlock_irqrestore(&phba->hbalock, flags);
2578 while (!list_empty(&hbq_buf_list)) {
2579 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
2581 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2587 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
2588 * @phba: Pointer to HBA context object.
2591 * This function posts more buffers to the HBQ. This function
2592 * is called with no lock held. The function returns the number of HBQ entries
2593 * successfully allocated.
2596 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
2598 if (phba->sli_rev == LPFC_SLI_REV4)
2601 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2602 lpfc_hbq_defs[qno]->add_count);
2606 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2607 * @phba: Pointer to HBA context object.
2608 * @qno: HBQ queue number.
2610 * This function is called from SLI initialization code path with
2611 * no lock held to post initial HBQ buffers to firmware. The
2612 * function returns the number of HBQ entries successfully allocated.
2615 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
2617 if (phba->sli_rev == LPFC_SLI_REV4)
2618 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2619 lpfc_hbq_defs[qno]->entry_count);
2621 return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
2622 lpfc_hbq_defs[qno]->init_count);
2626 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2628 * This function removes the first hbq buffer on an hbq list and returns a
2629 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2631 static struct hbq_dmabuf *
2632 lpfc_sli_hbqbuf_get(struct list_head *rb_list)
2634 struct lpfc_dmabuf *d_buf;
2636 list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
2639 return container_of(d_buf, struct hbq_dmabuf, dbuf);
2643 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2644 * @phba: Pointer to HBA context object.
2647 * This function removes the first RQ buffer on an RQ buffer list and returns a
2648 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2650 static struct rqb_dmabuf *
2651 lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
2653 struct lpfc_dmabuf *h_buf;
2654 struct lpfc_rqb *rqbp;
2657 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
2658 struct lpfc_dmabuf, list);
2661 rqbp->buffer_count--;
2662 return container_of(h_buf, struct rqb_dmabuf, hbuf);
2666 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2667 * @phba: Pointer to HBA context object.
2668 * @tag: Tag of the hbq buffer.
2670 * This function searches for the hbq buffer associated with the given tag in
2671 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2672 * otherwise it returns NULL.
2674 static struct hbq_dmabuf *
2675 lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
2677 struct lpfc_dmabuf *d_buf;
2678 struct hbq_dmabuf *hbq_buf;
2682 if (hbqno >= LPFC_MAX_HBQS)
2685 spin_lock_irq(&phba->hbalock);
2686 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
2687 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
2688 if (hbq_buf->tag == tag) {
2689 spin_unlock_irq(&phba->hbalock);
2693 spin_unlock_irq(&phba->hbalock);
2694 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2695 "1803 Bad hbq tag. Data: x%x x%x\n",
2696 tag, phba->hbqs[tag >> 16].buffer_count);
2701 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2702 * @phba: Pointer to HBA context object.
2703 * @hbq_buffer: Pointer to HBQ buffer.
2705 * This function is called with hbalock. This function gives back
2706 * the hbq buffer to firmware. If the HBQ does not have space to
2707 * post the buffer, it will free the buffer.
2710 lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
2715 hbqno = hbq_buffer->tag >> 16;
2716 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
2717 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
2722 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2723 * @mbxCommand: mailbox command code.
2725 * This function is called by the mailbox event handler function to verify
2726 * that the completed mailbox command is a legitimate mailbox command. If the
2727 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2728 * and the mailbox event handler will take the HBA offline.
2731 lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
2735 switch (mbxCommand) {
2739 case MBX_WRITE_VPARMS:
2740 case MBX_RUN_BIU_DIAG:
2743 case MBX_CONFIG_LINK:
2744 case MBX_CONFIG_RING:
2745 case MBX_RESET_RING:
2746 case MBX_READ_CONFIG:
2747 case MBX_READ_RCONFIG:
2748 case MBX_READ_SPARM:
2749 case MBX_READ_STATUS:
2753 case MBX_READ_LNK_STAT:
2755 case MBX_UNREG_LOGIN:
2757 case MBX_DUMP_MEMORY:
2758 case MBX_DUMP_CONTEXT:
2761 case MBX_UPDATE_CFG:
2763 case MBX_DEL_LD_ENTRY:
2764 case MBX_RUN_PROGRAM:
2766 case MBX_SET_VARIABLE:
2767 case MBX_UNREG_D_ID:
2768 case MBX_KILL_BOARD:
2769 case MBX_CONFIG_FARP:
2772 case MBX_RUN_BIU_DIAG64:
2773 case MBX_CONFIG_PORT:
2774 case MBX_READ_SPARM64:
2775 case MBX_READ_RPI64:
2776 case MBX_REG_LOGIN64:
2777 case MBX_READ_TOPOLOGY:
2780 case MBX_LOAD_EXP_ROM:
2781 case MBX_ASYNCEVT_ENABLE:
2785 case MBX_PORT_CAPABILITIES:
2786 case MBX_PORT_IOV_CONTROL:
2787 case MBX_SLI4_CONFIG:
2788 case MBX_SLI4_REQ_FTRS:
2790 case MBX_UNREG_FCFI:
2795 case MBX_RESUME_RPI:
2796 case MBX_READ_EVENT_LOG_STATUS:
2797 case MBX_READ_EVENT_LOG:
2798 case MBX_SECURITY_MGMT:
2800 case MBX_ACCESS_VDATA:
2811 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2812 * @phba: Pointer to HBA context object.
2813 * @pmboxq: Pointer to mailbox command.
2815 * This is completion handler function for mailbox commands issued from
2816 * lpfc_sli_issue_mbox_wait function. This function is called by the
2817 * mailbox event handler function with no lock held. This function
2818 * will wake up thread waiting on the wait queue pointed by context1
2822 lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2824 unsigned long drvr_flag;
2825 struct completion *pmbox_done;
2828 * If pmbox_done is empty, the driver thread gave up waiting and
2829 * continued running.
2831 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
2832 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2833 pmbox_done = (struct completion *)pmboxq->context3;
2835 complete(pmbox_done);
2836 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2841 __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2843 unsigned long iflags;
2845 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
2846 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
2847 spin_lock_irqsave(&ndlp->lock, iflags);
2848 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
2849 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
2850 spin_unlock_irqrestore(&ndlp->lock, iflags);
2852 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2856 lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2858 __lpfc_sli_rpi_release(vport, ndlp);
2862 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2863 * @phba: Pointer to HBA context object.
2864 * @pmb: Pointer to mailbox object.
2866 * This function is the default mailbox completion handler. It
2867 * frees the memory resources associated with the completed mailbox
2868 * command. If the completed command is a REG_LOGIN mailbox command,
2869 * this function will issue a UREG_LOGIN to re-claim the RPI.
2872 lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2874 struct lpfc_vport *vport = pmb->vport;
2875 struct lpfc_dmabuf *mp;
2876 struct lpfc_nodelist *ndlp;
2877 struct Scsi_Host *shost;
2882 * If a REG_LOGIN succeeded after node is destroyed or node
2883 * is in re-discovery driver need to cleanup the RPI.
2885 if (!(phba->pport->load_flag & FC_UNLOADING) &&
2886 pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
2887 !pmb->u.mb.mbxStatus) {
2888 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
2890 pmb->ctx_buf = NULL;
2891 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2894 rpi = pmb->u.mb.un.varWords[0];
2895 vpi = pmb->u.mb.un.varRegLogin.vpi;
2896 if (phba->sli_rev == LPFC_SLI_REV4)
2897 vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
2898 lpfc_unreg_login(phba, vpi, rpi, pmb);
2900 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2901 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2902 if (rc != MBX_NOT_FINISHED)
2906 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
2907 !(phba->pport->load_flag & FC_UNLOADING) &&
2908 !pmb->u.mb.mbxStatus) {
2909 shost = lpfc_shost_from_vport(vport);
2910 spin_lock_irq(shost->host_lock);
2911 vport->vpi_state |= LPFC_VPI_REGISTERED;
2912 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2913 spin_unlock_irq(shost->host_lock);
2916 if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
2917 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2921 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2922 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2924 /* Check to see if there are any deferred events to process */
2928 KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
2929 "1438 UNREG cmpl deferred mbox x%x "
2930 "on NPort x%x Data: x%x x%x x%px x%x x%x\n",
2931 ndlp->nlp_rpi, ndlp->nlp_DID,
2932 ndlp->nlp_flag, ndlp->nlp_defer_did,
2933 ndlp, vport->load_flag, kref_read(&ndlp->kref));
2935 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2936 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
2937 ndlp->nlp_flag &= ~NLP_UNREG_INP;
2938 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
2939 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2941 __lpfc_sli_rpi_release(vport, ndlp);
2944 /* The unreg_login mailbox is complete and had a
2945 * reference that has to be released. The PLOGI
2949 pmb->ctx_ndlp = NULL;
2953 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
2954 if (pmb->u.mb.mbxCommand == MBX_RESUME_RPI) {
2955 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
2959 /* Check security permission status on INIT_LINK mailbox command */
2960 if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
2961 (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
2962 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2963 "2860 SLI authentication is required "
2964 "for INIT_LINK but has not done yet\n");
2966 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
2967 lpfc_sli4_mbox_cmd_free(phba, pmb);
2969 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
2972 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2973 * @phba: Pointer to HBA context object.
2974 * @pmb: Pointer to mailbox object.
2976 * This function is the unreg rpi mailbox completion handler. It
2977 * frees the memory resources associated with the completed mailbox
2978 * command. An additional reference is put on the ndlp to prevent
2979 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2980 * the unreg mailbox command completes, this routine puts the
2985 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2987 struct lpfc_vport *vport = pmb->vport;
2988 struct lpfc_nodelist *ndlp;
2990 ndlp = pmb->ctx_ndlp;
2991 if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
2992 if (phba->sli_rev == LPFC_SLI_REV4 &&
2993 (bf_get(lpfc_sli_intf_if_type,
2994 &phba->sli4_hba.sli_intf) >=
2995 LPFC_SLI_INTF_IF_TYPE_2)) {
2998 vport, KERN_INFO, LOG_MBOX | LOG_SLI,
2999 "0010 UNREG_LOGIN vpi:%x "
3000 "rpi:%x DID:%x defer x%x flg x%x "
3002 vport->vpi, ndlp->nlp_rpi,
3003 ndlp->nlp_DID, ndlp->nlp_defer_did,
3006 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3008 /* Check to see if there are any deferred
3011 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
3012 (ndlp->nlp_defer_did !=
3013 NLP_EVT_NOTHING_PENDING)) {
3015 vport, KERN_INFO, LOG_DISCOVERY,
3016 "4111 UNREG cmpl deferred "
3018 "NPort x%x Data: x%x x%px\n",
3019 ndlp->nlp_rpi, ndlp->nlp_DID,
3020 ndlp->nlp_defer_did, ndlp);
3021 ndlp->nlp_flag &= ~NLP_UNREG_INP;
3022 ndlp->nlp_defer_did =
3023 NLP_EVT_NOTHING_PENDING;
3024 lpfc_issue_els_plogi(
3025 vport, ndlp->nlp_DID, 0);
3027 __lpfc_sli_rpi_release(vport, ndlp);
3034 mempool_free(pmb, phba->mbox_mem_pool);
3038 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
3039 * @phba: Pointer to HBA context object.
3041 * This function is called with no lock held. This function processes all
3042 * the completed mailbox commands and gives it to upper layers. The interrupt
3043 * service routine processes mailbox completion interrupt and adds completed
3044 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
3045 * Worker thread call lpfc_sli_handle_mb_event, which will return the
3046 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
3047 * function returns the mailbox commands to the upper layer by calling the
3048 * completion handler function of each mailbox.
3051 lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
3058 phba->sli.slistat.mbox_event++;
3060 /* Get all completed mailboxe buffers into the cmplq */
3061 spin_lock_irq(&phba->hbalock);
3062 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
3063 spin_unlock_irq(&phba->hbalock);
3065 /* Get a Mailbox buffer to setup mailbox commands for callback */
3067 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
3073 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
3075 lpfc_debugfs_disc_trc(pmb->vport,
3076 LPFC_DISC_TRC_MBOX_VPORT,
3077 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
3078 (uint32_t)pmbox->mbxCommand,
3079 pmbox->un.varWords[0],
3080 pmbox->un.varWords[1]);
3083 lpfc_debugfs_disc_trc(phba->pport,
3085 "MBOX cmpl: cmd:x%x mb:x%x x%x",
3086 (uint32_t)pmbox->mbxCommand,
3087 pmbox->un.varWords[0],
3088 pmbox->un.varWords[1]);
3093 * It is a fatal error if unknown mbox command completion.
3095 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
3097 /* Unknown mailbox command compl */
3098 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3099 "(%d):0323 Unknown Mailbox command "
3100 "x%x (x%x/x%x) Cmpl\n",
3101 pmb->vport ? pmb->vport->vpi :
3104 lpfc_sli_config_mbox_subsys_get(phba,
3106 lpfc_sli_config_mbox_opcode_get(phba,
3108 phba->link_state = LPFC_HBA_ERROR;
3109 phba->work_hs = HS_FFER3;
3110 lpfc_handle_eratt(phba);
3114 if (pmbox->mbxStatus) {
3115 phba->sli.slistat.mbox_stat_err++;
3116 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
3117 /* Mbox cmd cmpl error - RETRYing */
3118 lpfc_printf_log(phba, KERN_INFO,
3120 "(%d):0305 Mbox cmd cmpl "
3121 "error - RETRYing Data: x%x "
3122 "(x%x/x%x) x%x x%x x%x\n",
3123 pmb->vport ? pmb->vport->vpi :
3126 lpfc_sli_config_mbox_subsys_get(phba,
3128 lpfc_sli_config_mbox_opcode_get(phba,
3131 pmbox->un.varWords[0],
3132 pmb->vport ? pmb->vport->port_state :
3133 LPFC_VPORT_UNKNOWN);
3134 pmbox->mbxStatus = 0;
3135 pmbox->mbxOwner = OWN_HOST;
3136 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
3137 if (rc != MBX_NOT_FINISHED)
3142 /* Mailbox cmd <cmd> Cmpl <cmpl> */
3143 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
3144 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
3145 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
3147 pmb->vport ? pmb->vport->vpi : 0,
3149 lpfc_sli_config_mbox_subsys_get(phba, pmb),
3150 lpfc_sli_config_mbox_opcode_get(phba, pmb),
3152 *((uint32_t *) pmbox),
3153 pmbox->un.varWords[0],
3154 pmbox->un.varWords[1],
3155 pmbox->un.varWords[2],
3156 pmbox->un.varWords[3],
3157 pmbox->un.varWords[4],
3158 pmbox->un.varWords[5],
3159 pmbox->un.varWords[6],
3160 pmbox->un.varWords[7],
3161 pmbox->un.varWords[8],
3162 pmbox->un.varWords[9],
3163 pmbox->un.varWords[10]);
3166 pmb->mbox_cmpl(phba,pmb);
3172 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
3173 * @phba: Pointer to HBA context object.
3174 * @pring: Pointer to driver SLI ring object.
3177 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
3178 * is set in the tag the buffer is posted for a particular exchange,
3179 * the function will return the buffer without replacing the buffer.
3180 * If the buffer is for unsolicited ELS or CT traffic, this function
3181 * returns the buffer and also posts another buffer to the firmware.
3183 static struct lpfc_dmabuf *
3184 lpfc_sli_get_buff(struct lpfc_hba *phba,
3185 struct lpfc_sli_ring *pring,
3188 struct hbq_dmabuf *hbq_entry;
3190 if (tag & QUE_BUFTAG_BIT)
3191 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
3192 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
3195 return &hbq_entry->dbuf;
3199 * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer
3200 * containing a NVME LS request.
3201 * @phba: pointer to lpfc hba data structure.
3202 * @piocb: pointer to the iocbq struct representing the sequence starting
3205 * This routine initially validates the NVME LS, validates there is a login
3206 * with the port that sent the LS, and then calls the appropriate nvme host
3207 * or target LS request handler.
3210 lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
3212 struct lpfc_nodelist *ndlp;
3213 struct lpfc_dmabuf *d_buf;
3214 struct hbq_dmabuf *nvmebuf;
3215 struct fc_frame_header *fc_hdr;
3216 struct lpfc_async_xchg_ctx *axchg = NULL;
3217 char *failwhy = NULL;
3218 uint32_t oxid, sid, did, fctl, size;
3221 d_buf = piocb->cmd_dmabuf;
3223 nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
3224 fc_hdr = nvmebuf->hbuf.virt;
3225 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
3226 sid = sli4_sid_from_fc_hdr(fc_hdr);
3227 did = sli4_did_from_fc_hdr(fc_hdr);
3228 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
3229 fc_hdr->fh_f_ctl[1] << 8 |
3230 fc_hdr->fh_f_ctl[2]);
3231 size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
3233 lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n",
3236 if (phba->pport->load_flag & FC_UNLOADING) {
3237 failwhy = "Driver Unloading";
3238 } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
3239 failwhy = "NVME FC4 Disabled";
3240 } else if (!phba->nvmet_support && !phba->pport->localport) {
3241 failwhy = "No Localport";
3242 } else if (phba->nvmet_support && !phba->targetport) {
3243 failwhy = "No Targetport";
3244 } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) {
3245 failwhy = "Bad NVME LS R_CTL";
3246 } else if (unlikely((fctl & 0x00FF0000) !=
3247 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) {
3248 failwhy = "Bad NVME LS F_CTL";
3250 axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC);
3252 failwhy = "No CTX memory";
3255 if (unlikely(failwhy)) {
3256 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3257 "6154 Drop NVME LS: SID %06X OXID x%X: %s\n",
3258 sid, oxid, failwhy);
3262 /* validate the source of the LS is logged in */
3263 ndlp = lpfc_findnode_did(phba->pport, sid);
3265 ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3266 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
3267 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
3268 "6216 NVME Unsol rcv: No ndlp: "
3269 "NPort_ID x%x oxid x%x\n",
3280 axchg->state = LPFC_NVME_STE_LS_RCV;
3281 axchg->entry_cnt = 1;
3282 axchg->rqb_buffer = (void *)nvmebuf;
3283 axchg->hdwq = &phba->sli4_hba.hdwq[0];
3284 axchg->payload = nvmebuf->dbuf.virt;
3285 INIT_LIST_HEAD(&axchg->list);
3287 if (phba->nvmet_support) {
3288 ret = lpfc_nvmet_handle_lsreq(phba, axchg);
3289 spin_lock_irq(&ndlp->lock);
3290 if (!ret && !(ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH)) {
3291 ndlp->fc4_xpt_flags |= NLP_XPT_HAS_HH;
3292 spin_unlock_irq(&ndlp->lock);
3294 /* This reference is a single occurrence to hold the
3295 * node valid until the nvmet transport calls
3298 if (!lpfc_nlp_get(ndlp))
3301 lpfc_printf_log(phba, KERN_ERR, LOG_NODE,
3302 "6206 NVMET unsol ls_req ndlp x%px "
3303 "DID x%x xflags x%x refcnt %d\n",
3304 ndlp, ndlp->nlp_DID,
3305 ndlp->fc4_xpt_flags,
3306 kref_read(&ndlp->kref));
3308 spin_unlock_irq(&ndlp->lock);
3311 ret = lpfc_nvme_handle_lsreq(phba, axchg);
3314 /* if zero, LS was successfully handled. If non-zero, LS not handled */
3319 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3320 "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X "
3321 "NVMe%s handler failed %d\n",
3323 (phba->nvmet_support) ? "T" : "I", ret);
3325 /* recycle receive buffer */
3326 lpfc_in_buf_free(phba, &nvmebuf->dbuf);
3328 /* If start of new exchange, abort it */
3329 if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX)))
3330 ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
3337 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
3338 * @phba: Pointer to HBA context object.
3339 * @pring: Pointer to driver SLI ring object.
3340 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
3341 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
3342 * @fch_type: the type for the first frame of the sequence.
3344 * This function is called with no lock held. This function uses the r_ctl and
3345 * type of the received sequence to find the correct callback function to call
3346 * to process the sequence.
3349 lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3350 struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
3357 lpfc_nvme_unsol_ls_handler(phba, saveq);
3363 /* unSolicited Responses */
3364 if (pring->prt[0].profile) {
3365 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
3366 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
3370 /* We must search, based on rctl / type
3371 for the right routine */
3372 for (i = 0; i < pring->num_mask; i++) {
3373 if ((pring->prt[i].rctl == fch_r_ctl) &&
3374 (pring->prt[i].type == fch_type)) {
3375 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
3376 (pring->prt[i].lpfc_sli_rcv_unsol_event)
3377 (phba, pring, saveq);
3385 lpfc_sli_prep_unsol_wqe(struct lpfc_hba *phba,
3386 struct lpfc_iocbq *saveq)
3389 union lpfc_wqe128 *wqe;
3392 irsp = &saveq->iocb;
3395 /* Fill wcqe with the IOCB status fields */
3396 bf_set(lpfc_wcqe_c_status, &saveq->wcqe_cmpl, irsp->ulpStatus);
3397 saveq->wcqe_cmpl.word3 = irsp->ulpBdeCount;
3398 saveq->wcqe_cmpl.parameter = irsp->un.ulpWord[4];
3399 saveq->wcqe_cmpl.total_data_placed = irsp->unsli3.rcvsli3.acc_len;
3402 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, irsp->un.rcvels.parmRo);
3404 /* rx-id of the response frame */
3405 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, irsp->ulpContext);
3407 /* ox-id of the frame */
3408 bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
3409 irsp->unsli3.rcvsli3.ox_id);
3412 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
3413 irsp->un.rcvels.remoteID);
3415 /* unsol data len */
3416 for (i = 0; i < irsp->ulpBdeCount; i++) {
3417 struct lpfc_hbq_entry *hbqe = NULL;
3419 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3421 hbqe = (struct lpfc_hbq_entry *)
3422 &irsp->un.ulpWord[0];
3423 saveq->wqe.gen_req.bde.tus.f.bdeSize =
3424 hbqe->bde.tus.f.bdeSize;
3425 } else if (i == 1) {
3426 hbqe = (struct lpfc_hbq_entry *)
3427 &irsp->unsli3.sli3Words[4];
3428 saveq->unsol_rcv_len = hbqe->bde.tus.f.bdeSize;
3435 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
3436 * @phba: Pointer to HBA context object.
3437 * @pring: Pointer to driver SLI ring object.
3438 * @saveq: Pointer to the unsolicited iocb.
3440 * This function is called with no lock held by the ring event handler
3441 * when there is an unsolicited iocb posted to the response ring by the
3442 * firmware. This function gets the buffer associated with the iocbs
3443 * and calls the event handler for the ring. This function handles both
3444 * qring buffers and hbq buffers.
3445 * When the function returns 1 the caller can free the iocb object otherwise
3446 * upper layer functions will free the iocb objects.
3449 lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3450 struct lpfc_iocbq *saveq)
3455 uint32_t Rctl, Type;
3456 struct lpfc_iocbq *iocbq;
3457 struct lpfc_dmabuf *dmzbuf;
3459 irsp = &saveq->iocb;
3460 saveq->vport = phba->pport;
3462 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
3463 if (pring->lpfc_sli_rcv_async_status)
3464 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
3466 lpfc_printf_log(phba,
3469 "0316 Ring %d handler: unexpected "
3470 "ASYNC_STATUS iocb received evt_code "
3473 irsp->un.asyncstat.evt_code);
3477 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
3478 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
3479 if (irsp->ulpBdeCount > 0) {
3480 dmzbuf = lpfc_sli_get_buff(phba, pring,
3481 irsp->un.ulpWord[3]);
3482 lpfc_in_buf_free(phba, dmzbuf);
3485 if (irsp->ulpBdeCount > 1) {
3486 dmzbuf = lpfc_sli_get_buff(phba, pring,
3487 irsp->unsli3.sli3Words[3]);
3488 lpfc_in_buf_free(phba, dmzbuf);
3491 if (irsp->ulpBdeCount > 2) {
3492 dmzbuf = lpfc_sli_get_buff(phba, pring,
3493 irsp->unsli3.sli3Words[7]);
3494 lpfc_in_buf_free(phba, dmzbuf);
3500 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3501 if (irsp->ulpBdeCount != 0) {
3502 saveq->cmd_dmabuf = lpfc_sli_get_buff(phba, pring,
3503 irsp->un.ulpWord[3]);
3504 if (!saveq->cmd_dmabuf)
3505 lpfc_printf_log(phba,
3508 "0341 Ring %d Cannot find buffer for "
3509 "an unsolicited iocb. tag 0x%x\n",
3511 irsp->un.ulpWord[3]);
3513 if (irsp->ulpBdeCount == 2) {
3514 saveq->bpl_dmabuf = lpfc_sli_get_buff(phba, pring,
3515 irsp->unsli3.sli3Words[7]);
3516 if (!saveq->bpl_dmabuf)
3517 lpfc_printf_log(phba,
3520 "0342 Ring %d Cannot find buffer for an"
3521 " unsolicited iocb. tag 0x%x\n",
3523 irsp->unsli3.sli3Words[7]);
3525 list_for_each_entry(iocbq, &saveq->list, list) {
3526 irsp = &iocbq->iocb;
3527 if (irsp->ulpBdeCount != 0) {
3528 iocbq->cmd_dmabuf = lpfc_sli_get_buff(phba,
3530 irsp->un.ulpWord[3]);
3531 if (!iocbq->cmd_dmabuf)
3532 lpfc_printf_log(phba,
3535 "0343 Ring %d Cannot find "
3536 "buffer for an unsolicited iocb"
3537 ". tag 0x%x\n", pring->ringno,
3538 irsp->un.ulpWord[3]);
3540 if (irsp->ulpBdeCount == 2) {
3541 iocbq->bpl_dmabuf = lpfc_sli_get_buff(phba,
3543 irsp->unsli3.sli3Words[7]);
3544 if (!iocbq->bpl_dmabuf)
3545 lpfc_printf_log(phba,
3548 "0344 Ring %d Cannot find "
3549 "buffer for an unsolicited "
3552 irsp->unsli3.sli3Words[7]);
3556 paddr = getPaddr(irsp->un.cont64[0].addrHigh,
3557 irsp->un.cont64[0].addrLow);
3558 saveq->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring,
3560 if (irsp->ulpBdeCount == 2) {
3561 paddr = getPaddr(irsp->un.cont64[1].addrHigh,
3562 irsp->un.cont64[1].addrLow);
3563 saveq->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba,
3569 if (irsp->ulpBdeCount != 0 &&
3570 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
3571 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
3574 /* search continue save q for same XRI */
3575 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
3576 if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
3577 saveq->iocb.unsli3.rcvsli3.ox_id) {
3578 list_add_tail(&saveq->list, &iocbq->list);
3584 list_add_tail(&saveq->clist,
3585 &pring->iocb_continue_saveq);
3587 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
3588 list_del_init(&iocbq->clist);
3590 irsp = &saveq->iocb;
3595 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
3596 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
3597 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
3598 Rctl = FC_RCTL_ELS_REQ;
3601 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
3602 Rctl = w5p->hcsw.Rctl;
3603 Type = w5p->hcsw.Type;
3605 /* Firmware Workaround */
3606 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
3607 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
3608 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
3609 Rctl = FC_RCTL_ELS_REQ;
3611 w5p->hcsw.Rctl = Rctl;
3612 w5p->hcsw.Type = Type;
3616 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3617 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
3618 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
3619 if (irsp->unsli3.rcvsli3.vpi == 0xffff)
3620 saveq->vport = phba->pport;
3622 saveq->vport = lpfc_find_vport_by_vpid(phba,
3623 irsp->unsli3.rcvsli3.vpi);
3626 /* Prepare WQE with Unsol frame */
3627 lpfc_sli_prep_unsol_wqe(phba, saveq);
3629 if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
3630 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3631 "0313 Ring %d handler: unexpected Rctl x%x "
3632 "Type x%x received\n",
3633 pring->ringno, Rctl, Type);
3639 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
3640 * @phba: Pointer to HBA context object.
3641 * @pring: Pointer to driver SLI ring object.
3642 * @prspiocb: Pointer to response iocb object.
3644 * This function looks up the iocb_lookup table to get the command iocb
3645 * corresponding to the given response iocb using the iotag of the
3646 * response iocb. The driver calls this function with the hbalock held
3647 * for SLI3 ports or the ring lock held for SLI4 ports.
3648 * This function returns the command iocb object if it finds the command
3649 * iocb else returns NULL.
3651 static struct lpfc_iocbq *
3652 lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
3653 struct lpfc_sli_ring *pring,
3654 struct lpfc_iocbq *prspiocb)
3656 struct lpfc_iocbq *cmd_iocb = NULL;
3659 if (phba->sli_rev == LPFC_SLI_REV4)
3660 iotag = get_wqe_reqtag(prspiocb);
3662 iotag = prspiocb->iocb.ulpIoTag;
3664 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3665 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3666 if (cmd_iocb->cmd_flag & LPFC_IO_ON_TXCMPLQ) {
3667 /* remove from txcmpl queue list */
3668 list_del_init(&cmd_iocb->list);
3669 cmd_iocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
3670 pring->txcmplq_cnt--;
3675 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3676 "0317 iotag x%x is out of "
3677 "range: max iotag x%x\n",
3678 iotag, phba->sli.last_iotag);
3683 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
3684 * @phba: Pointer to HBA context object.
3685 * @pring: Pointer to driver SLI ring object.
3688 * This function looks up the iocb_lookup table to get the command iocb
3689 * corresponding to the given iotag. The driver calls this function with
3690 * the ring lock held because this function is an SLI4 port only helper.
3691 * This function returns the command iocb object if it finds the command
3692 * iocb else returns NULL.
3694 static struct lpfc_iocbq *
3695 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
3696 struct lpfc_sli_ring *pring, uint16_t iotag)
3698 struct lpfc_iocbq *cmd_iocb = NULL;
3700 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
3701 cmd_iocb = phba->sli.iocbq_lookup[iotag];
3702 if (cmd_iocb->cmd_flag & LPFC_IO_ON_TXCMPLQ) {
3703 /* remove from txcmpl queue list */
3704 list_del_init(&cmd_iocb->list);
3705 cmd_iocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
3706 pring->txcmplq_cnt--;
3711 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3712 "0372 iotag x%x lookup error: max iotag (x%x) "
3714 iotag, phba->sli.last_iotag,
3715 cmd_iocb ? cmd_iocb->cmd_flag : 0xffff);
3720 * lpfc_sli_process_sol_iocb - process solicited iocb completion
3721 * @phba: Pointer to HBA context object.
3722 * @pring: Pointer to driver SLI ring object.
3723 * @saveq: Pointer to the response iocb to be processed.
3725 * This function is called by the ring event handler for non-fcp
3726 * rings when there is a new response iocb in the response ring.
3727 * The caller is not required to hold any locks. This function
3728 * gets the command iocb associated with the response iocb and
3729 * calls the completion handler for the command iocb. If there
3730 * is no completion handler, the function will free the resources
3731 * associated with command iocb. If the response iocb is for
3732 * an already aborted command iocb, the status of the completion
3733 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
3734 * This function always returns 1.
3737 lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3738 struct lpfc_iocbq *saveq)
3740 struct lpfc_iocbq *cmdiocbp;
3741 unsigned long iflag;
3742 u32 ulp_command, ulp_status, ulp_word4, ulp_context, iotag;
3744 if (phba->sli_rev == LPFC_SLI_REV4)
3745 spin_lock_irqsave(&pring->ring_lock, iflag);
3747 spin_lock_irqsave(&phba->hbalock, iflag);
3748 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
3749 if (phba->sli_rev == LPFC_SLI_REV4)
3750 spin_unlock_irqrestore(&pring->ring_lock, iflag);
3752 spin_unlock_irqrestore(&phba->hbalock, iflag);
3754 ulp_command = get_job_cmnd(phba, saveq);
3755 ulp_status = get_job_ulpstatus(phba, saveq);
3756 ulp_word4 = get_job_word4(phba, saveq);
3757 ulp_context = get_job_ulpcontext(phba, saveq);
3758 if (phba->sli_rev == LPFC_SLI_REV4)
3759 iotag = get_wqe_reqtag(saveq);
3761 iotag = saveq->iocb.ulpIoTag;
3764 ulp_command = get_job_cmnd(phba, cmdiocbp);
3765 if (cmdiocbp->cmd_cmpl) {
3767 * If an ELS command failed send an event to mgmt
3771 (pring->ringno == LPFC_ELS_RING) &&
3772 (ulp_command == CMD_ELS_REQUEST64_CR))
3773 lpfc_send_els_failure_event(phba,
3777 * Post all ELS completions to the worker thread.
3778 * All other are passed to the completion callback.
3780 if (pring->ringno == LPFC_ELS_RING) {
3781 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3782 (cmdiocbp->cmd_flag &
3783 LPFC_DRIVER_ABORTED)) {
3784 spin_lock_irqsave(&phba->hbalock,
3786 cmdiocbp->cmd_flag &=
3787 ~LPFC_DRIVER_ABORTED;
3788 spin_unlock_irqrestore(&phba->hbalock,
3790 saveq->iocb.ulpStatus =
3791 IOSTAT_LOCAL_REJECT;
3792 saveq->iocb.un.ulpWord[4] =
3795 /* Firmware could still be in progress
3796 * of DMAing payload, so don't free data
3797 * buffer till after a hbeat.
3799 spin_lock_irqsave(&phba->hbalock,
3801 saveq->cmd_flag |= LPFC_DELAY_MEM_FREE;
3802 spin_unlock_irqrestore(&phba->hbalock,
3805 if (phba->sli_rev == LPFC_SLI_REV4) {
3806 if (saveq->cmd_flag &
3807 LPFC_EXCHANGE_BUSY) {
3808 /* Set cmdiocb flag for the
3809 * exchange busy so sgl (xri)
3810 * will not be released until
3811 * the abort xri is received
3815 &phba->hbalock, iflag);
3816 cmdiocbp->cmd_flag |=
3818 spin_unlock_irqrestore(
3819 &phba->hbalock, iflag);
3821 if (cmdiocbp->cmd_flag &
3822 LPFC_DRIVER_ABORTED) {
3824 * Clear LPFC_DRIVER_ABORTED
3825 * bit in case it was driver
3829 &phba->hbalock, iflag);
3830 cmdiocbp->cmd_flag &=
3831 ~LPFC_DRIVER_ABORTED;
3832 spin_unlock_irqrestore(
3833 &phba->hbalock, iflag);
3834 set_job_ulpstatus(cmdiocbp,
3835 IOSTAT_LOCAL_REJECT);
3836 set_job_ulpword4(cmdiocbp,
3837 IOERR_ABORT_REQUESTED);
3839 * For SLI4, irspiocb contains
3840 * NO_XRI in sli_xritag, it
3841 * shall not affect releasing
3842 * sgl (xri) process.
3844 set_job_ulpstatus(saveq,
3845 IOSTAT_LOCAL_REJECT);
3846 set_job_ulpword4(saveq,
3849 &phba->hbalock, iflag);
3851 LPFC_DELAY_MEM_FREE;
3852 spin_unlock_irqrestore(
3853 &phba->hbalock, iflag);
3857 cmdiocbp->cmd_cmpl(phba, cmdiocbp, saveq);
3859 lpfc_sli_release_iocbq(phba, cmdiocbp);
3862 * Unknown initiating command based on the response iotag.
3863 * This could be the case on the ELS ring because of
3866 if (pring->ringno != LPFC_ELS_RING) {
3868 * Ring <ringno> handler: unexpected completion IoTag
3871 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3872 "0322 Ring %d handler: "
3873 "unexpected completion IoTag x%x "
3874 "Data: x%x x%x x%x x%x\n",
3875 pring->ringno, iotag, ulp_status,
3876 ulp_word4, ulp_command, ulp_context);
3884 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
3885 * @phba: Pointer to HBA context object.
3886 * @pring: Pointer to driver SLI ring object.
3888 * This function is called from the iocb ring event handlers when
3889 * put pointer is ahead of the get pointer for a ring. This function signal
3890 * an error attention condition to the worker thread and the worker
3891 * thread will transition the HBA to offline state.
3894 lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
3896 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3898 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3899 * rsp ring <portRspMax>
3901 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3902 "0312 Ring %d handler: portRspPut %d "
3903 "is bigger than rsp ring %d\n",
3904 pring->ringno, le32_to_cpu(pgp->rspPutInx),
3905 pring->sli.sli3.numRiocb);
3907 phba->link_state = LPFC_HBA_ERROR;
3910 * All error attention handlers are posted to
3913 phba->work_ha |= HA_ERATT;
3914 phba->work_hs = HS_FFER3;
3916 lpfc_worker_wake_up(phba);
3922 * lpfc_poll_eratt - Error attention polling timer timeout handler
3923 * @t: Context to fetch pointer to address of HBA context object from.
3925 * This function is invoked by the Error Attention polling timer when the
3926 * timer times out. It will check the SLI Error Attention register for
3927 * possible attention events. If so, it will post an Error Attention event
3928 * and wake up worker thread to process it. Otherwise, it will set up the
3929 * Error Attention polling timer for the next poll.
3931 void lpfc_poll_eratt(struct timer_list *t)
3933 struct lpfc_hba *phba;
3935 uint64_t sli_intr, cnt;
3937 phba = from_timer(phba, t, eratt_poll);
3939 /* Here we will also keep track of interrupts per sec of the hba */
3940 sli_intr = phba->sli.slistat.sli_intr;
3942 if (phba->sli.slistat.sli_prev_intr > sli_intr)
3943 cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
3946 cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
3948 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3949 do_div(cnt, phba->eratt_poll_interval);
3950 phba->sli.slistat.sli_ips = cnt;
3952 phba->sli.slistat.sli_prev_intr = sli_intr;
3954 /* Check chip HA register for error event */
3955 eratt = lpfc_sli_check_eratt(phba);
3958 /* Tell the worker thread there is work to do */
3959 lpfc_worker_wake_up(phba);
3961 /* Restart the timer for next eratt poll */
3962 mod_timer(&phba->eratt_poll,
3964 msecs_to_jiffies(1000 * phba->eratt_poll_interval));
3970 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3971 * @phba: Pointer to HBA context object.
3972 * @pring: Pointer to driver SLI ring object.
3973 * @mask: Host attention register mask for this ring.
3975 * This function is called from the interrupt context when there is a ring
3976 * event for the fcp ring. The caller does not hold any lock.
3977 * The function processes each response iocb in the response ring until it
3978 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3979 * LE bit set. The function will call the completion handler of the command iocb
3980 * if the response iocb indicates a completion for a command iocb or it is
3981 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3982 * function if this is an unsolicited iocb.
3983 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3984 * to check it explicitly.
3987 lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
3988 struct lpfc_sli_ring *pring, uint32_t mask)
3990 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
3991 IOCB_t *irsp = NULL;
3992 IOCB_t *entry = NULL;
3993 struct lpfc_iocbq *cmdiocbq = NULL;
3994 struct lpfc_iocbq rspiocbq;
3996 uint32_t portRspPut, portRspMax;
3998 lpfc_iocb_type type;
3999 unsigned long iflag;
4000 uint32_t rsp_cmpl = 0;
4002 spin_lock_irqsave(&phba->hbalock, iflag);
4003 pring->stats.iocb_event++;
4006 * The next available response entry should never exceed the maximum
4007 * entries. If it does, treat it as an adapter hardware error.
4009 portRspMax = pring->sli.sli3.numRiocb;
4010 portRspPut = le32_to_cpu(pgp->rspPutInx);
4011 if (unlikely(portRspPut >= portRspMax)) {
4012 lpfc_sli_rsp_pointers_error(phba, pring);
4013 spin_unlock_irqrestore(&phba->hbalock, iflag);
4016 if (phba->fcp_ring_in_use) {
4017 spin_unlock_irqrestore(&phba->hbalock, iflag);
4020 phba->fcp_ring_in_use = 1;
4023 while (pring->sli.sli3.rspidx != portRspPut) {
4025 * Fetch an entry off the ring and copy it into a local data
4026 * structure. The copy involves a byte-swap since the
4027 * network byte order and pci byte orders are different.
4029 entry = lpfc_resp_iocb(phba, pring);
4030 phba->last_completion_time = jiffies;
4032 if (++pring->sli.sli3.rspidx >= portRspMax)
4033 pring->sli.sli3.rspidx = 0;
4035 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
4036 (uint32_t *) &rspiocbq.iocb,
4037 phba->iocb_rsp_size);
4038 INIT_LIST_HEAD(&(rspiocbq.list));
4039 irsp = &rspiocbq.iocb;
4041 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
4042 pring->stats.iocb_rsp++;
4045 if (unlikely(irsp->ulpStatus)) {
4047 * If resource errors reported from HBA, reduce
4048 * queuedepths of the SCSI device.
4050 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
4051 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
4052 IOERR_NO_RESOURCES)) {
4053 spin_unlock_irqrestore(&phba->hbalock, iflag);
4054 phba->lpfc_rampdown_queue_depth(phba);
4055 spin_lock_irqsave(&phba->hbalock, iflag);
4058 /* Rsp ring <ringno> error: IOCB */
4059 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4060 "0336 Rsp Ring %d error: IOCB Data: "
4061 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
4063 irsp->un.ulpWord[0],
4064 irsp->un.ulpWord[1],
4065 irsp->un.ulpWord[2],
4066 irsp->un.ulpWord[3],
4067 irsp->un.ulpWord[4],
4068 irsp->un.ulpWord[5],
4069 *(uint32_t *)&irsp->un1,
4070 *((uint32_t *)&irsp->un1 + 1));
4074 case LPFC_ABORT_IOCB:
4077 * Idle exchange closed via ABTS from port. No iocb
4078 * resources need to be recovered.
4080 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
4081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4082 "0333 IOCB cmd 0x%x"
4083 " processed. Skipping"
4089 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
4091 if (unlikely(!cmdiocbq))
4093 if (cmdiocbq->cmd_flag & LPFC_DRIVER_ABORTED)
4094 cmdiocbq->cmd_flag &= ~LPFC_DRIVER_ABORTED;
4095 if (cmdiocbq->cmd_cmpl) {
4096 spin_unlock_irqrestore(&phba->hbalock, iflag);
4097 cmdiocbq->cmd_cmpl(phba, cmdiocbq, &rspiocbq);
4098 spin_lock_irqsave(&phba->hbalock, iflag);
4101 case LPFC_UNSOL_IOCB:
4102 spin_unlock_irqrestore(&phba->hbalock, iflag);
4103 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
4104 spin_lock_irqsave(&phba->hbalock, iflag);
4107 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
4108 char adaptermsg[LPFC_MAX_ADPTMSG];
4109 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
4110 memcpy(&adaptermsg[0], (uint8_t *) irsp,
4112 dev_warn(&((phba->pcidev)->dev),
4114 phba->brd_no, adaptermsg);
4116 /* Unknown IOCB command */
4117 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4118 "0334 Unknown IOCB command "
4119 "Data: x%x, x%x x%x x%x x%x\n",
4120 type, irsp->ulpCommand,
4129 * The response IOCB has been processed. Update the ring
4130 * pointer in SLIM. If the port response put pointer has not
4131 * been updated, sync the pgp->rspPutInx and fetch the new port
4132 * response put pointer.
4134 writel(pring->sli.sli3.rspidx,
4135 &phba->host_gp[pring->ringno].rspGetInx);
4137 if (pring->sli.sli3.rspidx == portRspPut)
4138 portRspPut = le32_to_cpu(pgp->rspPutInx);
4141 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
4142 pring->stats.iocb_rsp_full++;
4143 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
4144 writel(status, phba->CAregaddr);
4145 readl(phba->CAregaddr);
4147 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
4148 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
4149 pring->stats.iocb_cmd_empty++;
4151 /* Force update of the local copy of cmdGetInx */
4152 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
4153 lpfc_sli_resume_iocb(phba, pring);
4155 if ((pring->lpfc_sli_cmd_available))
4156 (pring->lpfc_sli_cmd_available) (phba, pring);
4160 phba->fcp_ring_in_use = 0;
4161 spin_unlock_irqrestore(&phba->hbalock, iflag);
4166 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
4167 * @phba: Pointer to HBA context object.
4168 * @pring: Pointer to driver SLI ring object.
4169 * @rspiocbp: Pointer to driver response IOCB object.
4171 * This function is called from the worker thread when there is a slow-path
4172 * response IOCB to process. This function chains all the response iocbs until
4173 * seeing the iocb with the LE bit set. The function will call
4174 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
4175 * completion of a command iocb. The function will call the
4176 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
4177 * The function frees the resources or calls the completion handler if this
4178 * iocb is an abort completion. The function returns NULL when the response
4179 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
4180 * this function shall chain the iocb on to the iocb_continueq and return the
4181 * response iocb passed in.
4183 static struct lpfc_iocbq *
4184 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4185 struct lpfc_iocbq *rspiocbp)
4187 struct lpfc_iocbq *saveq;
4188 struct lpfc_iocbq *cmdiocb;
4189 struct lpfc_iocbq *next_iocb;
4191 uint32_t free_saveq;
4193 lpfc_iocb_type type;
4194 unsigned long iflag;
4195 u32 ulp_status = get_job_ulpstatus(phba, rspiocbp);
4196 u32 ulp_word4 = get_job_word4(phba, rspiocbp);
4197 u32 ulp_command = get_job_cmnd(phba, rspiocbp);
4200 spin_lock_irqsave(&phba->hbalock, iflag);
4201 /* First add the response iocb to the countinueq list */
4202 list_add_tail(&rspiocbp->list, &pring->iocb_continueq);
4203 pring->iocb_continueq_cnt++;
4206 * By default, the driver expects to free all resources
4207 * associated with this iocb completion.
4210 saveq = list_get_first(&pring->iocb_continueq,
4211 struct lpfc_iocbq, list);
4212 list_del_init(&pring->iocb_continueq);
4213 pring->iocb_continueq_cnt = 0;
4215 pring->stats.iocb_rsp++;
4218 * If resource errors reported from HBA, reduce
4219 * queuedepths of the SCSI device.
4221 if (ulp_status == IOSTAT_LOCAL_REJECT &&
4222 ((ulp_word4 & IOERR_PARAM_MASK) ==
4223 IOERR_NO_RESOURCES)) {
4224 spin_unlock_irqrestore(&phba->hbalock, iflag);
4225 phba->lpfc_rampdown_queue_depth(phba);
4226 spin_lock_irqsave(&phba->hbalock, iflag);
4230 /* Rsp ring <ringno> error: IOCB */
4231 if (phba->sli_rev < LPFC_SLI_REV4) {
4232 irsp = &rspiocbp->iocb;
4233 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4234 "0328 Rsp Ring %d error: ulp_status x%x "
4236 "x%08x x%08x x%08x x%08x "
4237 "x%08x x%08x x%08x x%08x "
4238 "x%08x x%08x x%08x x%08x "
4239 "x%08x x%08x x%08x x%08x\n",
4240 pring->ringno, ulp_status,
4241 get_job_ulpword(rspiocbp, 0),
4242 get_job_ulpword(rspiocbp, 1),
4243 get_job_ulpword(rspiocbp, 2),
4244 get_job_ulpword(rspiocbp, 3),
4245 get_job_ulpword(rspiocbp, 4),
4246 get_job_ulpword(rspiocbp, 5),
4247 *(((uint32_t *)irsp) + 6),
4248 *(((uint32_t *)irsp) + 7),
4249 *(((uint32_t *)irsp) + 8),
4250 *(((uint32_t *)irsp) + 9),
4251 *(((uint32_t *)irsp) + 10),
4252 *(((uint32_t *)irsp) + 11),
4253 *(((uint32_t *)irsp) + 12),
4254 *(((uint32_t *)irsp) + 13),
4255 *(((uint32_t *)irsp) + 14),
4256 *(((uint32_t *)irsp) + 15));
4258 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4259 "0321 Rsp Ring %d error: "
4261 "x%x x%x x%x x%x\n",
4263 rspiocbp->wcqe_cmpl.word0,
4264 rspiocbp->wcqe_cmpl.total_data_placed,
4265 rspiocbp->wcqe_cmpl.parameter,
4266 rspiocbp->wcqe_cmpl.word3);
4272 * Fetch the iocb command type and call the correct completion
4273 * routine. Solicited and Unsolicited IOCBs on the ELS ring
4274 * get freed back to the lpfc_iocb_list by the discovery
4277 cmd_type = ulp_command & CMD_IOCB_MASK;
4278 type = lpfc_sli_iocb_cmd_type(cmd_type);
4281 spin_unlock_irqrestore(&phba->hbalock, iflag);
4282 rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
4283 spin_lock_irqsave(&phba->hbalock, iflag);
4285 case LPFC_UNSOL_IOCB:
4286 spin_unlock_irqrestore(&phba->hbalock, iflag);
4287 rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
4288 spin_lock_irqsave(&phba->hbalock, iflag);
4292 case LPFC_ABORT_IOCB:
4294 if (ulp_command != CMD_XRI_ABORTED_CX)
4295 cmdiocb = lpfc_sli_iocbq_lookup(phba, pring,
4298 /* Call the specified completion routine */
4299 if (cmdiocb->cmd_cmpl) {
4300 spin_unlock_irqrestore(&phba->hbalock, iflag);
4301 cmdiocb->cmd_cmpl(phba, cmdiocb, saveq);
4302 spin_lock_irqsave(&phba->hbalock, iflag);
4304 __lpfc_sli_release_iocbq(phba, cmdiocb);
4308 case LPFC_UNKNOWN_IOCB:
4309 if (ulp_command == CMD_ADAPTER_MSG) {
4310 char adaptermsg[LPFC_MAX_ADPTMSG];
4312 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
4313 memcpy(&adaptermsg[0], (uint8_t *)&rspiocbp->wqe,
4315 dev_warn(&((phba->pcidev)->dev),
4317 phba->brd_no, adaptermsg);
4319 /* Unknown command */
4320 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4321 "0335 Unknown IOCB "
4322 "command Data: x%x "
4326 get_wqe_reqtag(rspiocbp),
4327 get_job_ulpcontext(phba, rspiocbp));
4333 list_for_each_entry_safe(rspiocbp, next_iocb,
4334 &saveq->list, list) {
4335 list_del_init(&rspiocbp->list);
4336 __lpfc_sli_release_iocbq(phba, rspiocbp);
4338 __lpfc_sli_release_iocbq(phba, saveq);
4341 spin_unlock_irqrestore(&phba->hbalock, iflag);
4346 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
4347 * @phba: Pointer to HBA context object.
4348 * @pring: Pointer to driver SLI ring object.
4349 * @mask: Host attention register mask for this ring.
4351 * This routine wraps the actual slow_ring event process routine from the
4352 * API jump table function pointer from the lpfc_hba struct.
4355 lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
4356 struct lpfc_sli_ring *pring, uint32_t mask)
4358 phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
4362 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
4363 * @phba: Pointer to HBA context object.
4364 * @pring: Pointer to driver SLI ring object.
4365 * @mask: Host attention register mask for this ring.
4367 * This function is called from the worker thread when there is a ring event
4368 * for non-fcp rings. The caller does not hold any lock. The function will
4369 * remove each response iocb in the response ring and calls the handle
4370 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4373 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
4374 struct lpfc_sli_ring *pring, uint32_t mask)
4376 struct lpfc_pgp *pgp;
4378 IOCB_t *irsp = NULL;
4379 struct lpfc_iocbq *rspiocbp = NULL;
4380 uint32_t portRspPut, portRspMax;
4381 unsigned long iflag;
4384 pgp = &phba->port_gp[pring->ringno];
4385 spin_lock_irqsave(&phba->hbalock, iflag);
4386 pring->stats.iocb_event++;
4389 * The next available response entry should never exceed the maximum
4390 * entries. If it does, treat it as an adapter hardware error.
4392 portRspMax = pring->sli.sli3.numRiocb;
4393 portRspPut = le32_to_cpu(pgp->rspPutInx);
4394 if (portRspPut >= portRspMax) {
4396 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
4397 * rsp ring <portRspMax>
4399 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4400 "0303 Ring %d handler: portRspPut %d "
4401 "is bigger than rsp ring %d\n",
4402 pring->ringno, portRspPut, portRspMax);
4404 phba->link_state = LPFC_HBA_ERROR;
4405 spin_unlock_irqrestore(&phba->hbalock, iflag);
4407 phba->work_hs = HS_FFER3;
4408 lpfc_handle_eratt(phba);
4414 while (pring->sli.sli3.rspidx != portRspPut) {
4416 * Build a completion list and call the appropriate handler.
4417 * The process is to get the next available response iocb, get
4418 * a free iocb from the list, copy the response data into the
4419 * free iocb, insert to the continuation list, and update the
4420 * next response index to slim. This process makes response
4421 * iocb's in the ring available to DMA as fast as possible but
4422 * pays a penalty for a copy operation. Since the iocb is
4423 * only 32 bytes, this penalty is considered small relative to
4424 * the PCI reads for register values and a slim write. When
4425 * the ulpLe field is set, the entire Command has been
4428 entry = lpfc_resp_iocb(phba, pring);
4430 phba->last_completion_time = jiffies;
4431 rspiocbp = __lpfc_sli_get_iocbq(phba);
4432 if (rspiocbp == NULL) {
4433 printk(KERN_ERR "%s: out of buffers! Failing "
4434 "completion.\n", __func__);
4438 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
4439 phba->iocb_rsp_size);
4440 irsp = &rspiocbp->iocb;
4442 if (++pring->sli.sli3.rspidx >= portRspMax)
4443 pring->sli.sli3.rspidx = 0;
4445 if (pring->ringno == LPFC_ELS_RING) {
4446 lpfc_debugfs_slow_ring_trc(phba,
4447 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
4448 *(((uint32_t *) irsp) + 4),
4449 *(((uint32_t *) irsp) + 6),
4450 *(((uint32_t *) irsp) + 7));
4453 writel(pring->sli.sli3.rspidx,
4454 &phba->host_gp[pring->ringno].rspGetInx);
4456 spin_unlock_irqrestore(&phba->hbalock, iflag);
4457 /* Handle the response IOCB */
4458 rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
4459 spin_lock_irqsave(&phba->hbalock, iflag);
4462 * If the port response put pointer has not been updated, sync
4463 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
4464 * response put pointer.
4466 if (pring->sli.sli3.rspidx == portRspPut) {
4467 portRspPut = le32_to_cpu(pgp->rspPutInx);
4469 } /* while (pring->sli.sli3.rspidx != portRspPut) */
4471 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
4472 /* At least one response entry has been freed */
4473 pring->stats.iocb_rsp_full++;
4474 /* SET RxRE_RSP in Chip Att register */
4475 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
4476 writel(status, phba->CAregaddr);
4477 readl(phba->CAregaddr); /* flush */
4479 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
4480 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
4481 pring->stats.iocb_cmd_empty++;
4483 /* Force update of the local copy of cmdGetInx */
4484 pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
4485 lpfc_sli_resume_iocb(phba, pring);
4487 if ((pring->lpfc_sli_cmd_available))
4488 (pring->lpfc_sli_cmd_available) (phba, pring);
4492 spin_unlock_irqrestore(&phba->hbalock, iflag);
4497 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
4498 * @phba: Pointer to HBA context object.
4499 * @pring: Pointer to driver SLI ring object.
4500 * @mask: Host attention register mask for this ring.
4502 * This function is called from the worker thread when there is a pending
4503 * ELS response iocb on the driver internal slow-path response iocb worker
4504 * queue. The caller does not hold any lock. The function will remove each
4505 * response iocb from the response worker queue and calls the handle
4506 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
4509 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
4510 struct lpfc_sli_ring *pring, uint32_t mask)
4512 struct lpfc_iocbq *irspiocbq;
4513 struct hbq_dmabuf *dmabuf;
4514 struct lpfc_cq_event *cq_event;
4515 unsigned long iflag;
4518 spin_lock_irqsave(&phba->hbalock, iflag);
4519 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
4520 spin_unlock_irqrestore(&phba->hbalock, iflag);
4521 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
4522 /* Get the response iocb from the head of work queue */
4523 spin_lock_irqsave(&phba->hbalock, iflag);
4524 list_remove_head(&phba->sli4_hba.sp_queue_event,
4525 cq_event, struct lpfc_cq_event, list);
4526 spin_unlock_irqrestore(&phba->hbalock, iflag);
4528 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
4529 case CQE_CODE_COMPL_WQE:
4530 irspiocbq = container_of(cq_event, struct lpfc_iocbq,
4532 /* Translate ELS WCQE to response IOCBQ */
4533 irspiocbq = lpfc_sli4_els_preprocess_rspiocbq(phba,
4536 lpfc_sli_sp_handle_rspiocb(phba, pring,
4540 case CQE_CODE_RECEIVE:
4541 case CQE_CODE_RECEIVE_V1:
4542 dmabuf = container_of(cq_event, struct hbq_dmabuf,
4544 lpfc_sli4_handle_received_buffer(phba, dmabuf);
4551 /* Limit the number of events to 64 to avoid soft lockups */
4558 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
4559 * @phba: Pointer to HBA context object.
4560 * @pring: Pointer to driver SLI ring object.
4562 * This function aborts all iocbs in the given ring and frees all the iocb
4563 * objects in txq. This function issues an abort iocb for all the iocb commands
4564 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4565 * the return of this function. The caller is not required to hold any locks.
4568 lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
4570 LIST_HEAD(tx_completions);
4571 LIST_HEAD(txcmplq_completions);
4572 struct lpfc_iocbq *iocb, *next_iocb;
4575 if (pring->ringno == LPFC_ELS_RING) {
4576 lpfc_fabric_abort_hba(phba);
4578 offline = pci_channel_offline(phba->pcidev);
4580 /* Error everything on txq and txcmplq
4583 if (phba->sli_rev >= LPFC_SLI_REV4) {
4584 spin_lock_irq(&pring->ring_lock);
4585 list_splice_init(&pring->txq, &tx_completions);
4589 list_splice_init(&pring->txcmplq,
4590 &txcmplq_completions);
4592 /* Next issue ABTS for everything on the txcmplq */
4593 list_for_each_entry_safe(iocb, next_iocb,
4594 &pring->txcmplq, list)
4595 lpfc_sli_issue_abort_iotag(phba, pring,
4598 spin_unlock_irq(&pring->ring_lock);
4600 spin_lock_irq(&phba->hbalock);
4601 list_splice_init(&pring->txq, &tx_completions);
4605 list_splice_init(&pring->txcmplq, &txcmplq_completions);
4607 /* Next issue ABTS for everything on the txcmplq */
4608 list_for_each_entry_safe(iocb, next_iocb,
4609 &pring->txcmplq, list)
4610 lpfc_sli_issue_abort_iotag(phba, pring,
4613 spin_unlock_irq(&phba->hbalock);
4617 /* Cancel all the IOCBs from the completions list */
4618 lpfc_sli_cancel_iocbs(phba, &txcmplq_completions,
4619 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
4621 /* Make sure HBA is alive */
4622 lpfc_issue_hb_tmo(phba);
4624 /* Cancel all the IOCBs from the completions list */
4625 lpfc_sli_cancel_iocbs(phba, &tx_completions, IOSTAT_LOCAL_REJECT,
4630 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
4631 * @phba: Pointer to HBA context object.
4633 * This function aborts all iocbs in FCP rings and frees all the iocb
4634 * objects in txq. This function issues an abort iocb for all the iocb commands
4635 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
4636 * the return of this function. The caller is not required to hold any locks.
4639 lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
4641 struct lpfc_sli *psli = &phba->sli;
4642 struct lpfc_sli_ring *pring;
4645 /* Look on all the FCP Rings for the iotag */
4646 if (phba->sli_rev >= LPFC_SLI_REV4) {
4647 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4648 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4649 lpfc_sli_abort_iocb_ring(phba, pring);
4652 pring = &psli->sli3_ring[LPFC_FCP_RING];
4653 lpfc_sli_abort_iocb_ring(phba, pring);
4658 * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
4659 * @phba: Pointer to HBA context object.
4661 * This function flushes all iocbs in the IO ring and frees all the iocb
4662 * objects in txq and txcmplq. This function will not issue abort iocbs
4663 * for all the iocb commands in txcmplq, they will just be returned with
4664 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
4665 * slot has been permanently disabled.
4668 lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
4672 struct lpfc_sli *psli = &phba->sli;
4673 struct lpfc_sli_ring *pring;
4675 struct lpfc_iocbq *piocb, *next_iocb;
4677 spin_lock_irq(&phba->hbalock);
4678 /* Indicate the I/O queues are flushed */
4679 phba->hba_flag |= HBA_IOQ_FLUSH;
4680 spin_unlock_irq(&phba->hbalock);
4682 /* Look on all the FCP Rings for the iotag */
4683 if (phba->sli_rev >= LPFC_SLI_REV4) {
4684 for (i = 0; i < phba->cfg_hdw_queue; i++) {
4685 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
4687 spin_lock_irq(&pring->ring_lock);
4688 /* Retrieve everything on txq */
4689 list_splice_init(&pring->txq, &txq);
4690 list_for_each_entry_safe(piocb, next_iocb,
4691 &pring->txcmplq, list)
4692 piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
4693 /* Retrieve everything on the txcmplq */
4694 list_splice_init(&pring->txcmplq, &txcmplq);
4696 pring->txcmplq_cnt = 0;
4697 spin_unlock_irq(&pring->ring_lock);
4700 lpfc_sli_cancel_iocbs(phba, &txq,
4701 IOSTAT_LOCAL_REJECT,
4703 /* Flush the txcmplq */
4704 lpfc_sli_cancel_iocbs(phba, &txcmplq,
4705 IOSTAT_LOCAL_REJECT,
4707 if (unlikely(pci_channel_offline(phba->pcidev)))
4708 lpfc_sli4_io_xri_aborted(phba, NULL, 0);
4711 pring = &psli->sli3_ring[LPFC_FCP_RING];
4713 spin_lock_irq(&phba->hbalock);
4714 /* Retrieve everything on txq */
4715 list_splice_init(&pring->txq, &txq);
4716 list_for_each_entry_safe(piocb, next_iocb,
4717 &pring->txcmplq, list)
4718 piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
4719 /* Retrieve everything on the txcmplq */
4720 list_splice_init(&pring->txcmplq, &txcmplq);
4722 pring->txcmplq_cnt = 0;
4723 spin_unlock_irq(&phba->hbalock);
4726 lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
4728 /* Flush the txcmpq */
4729 lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
4735 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
4736 * @phba: Pointer to HBA context object.
4737 * @mask: Bit mask to be checked.
4739 * This function reads the host status register and compares
4740 * with the provided bit mask to check if HBA completed
4741 * the restart. This function will wait in a loop for the
4742 * HBA to complete restart. If the HBA does not restart within
4743 * 15 iterations, the function will reset the HBA again. The
4744 * function returns 1 when HBA fail to restart otherwise returns
4748 lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
4754 /* Read the HBA Host Status Register */
4755 if (lpfc_readl(phba->HSregaddr, &status))
4758 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
4761 * Check status register every 100ms for 5 retries, then every
4762 * 500ms for 5, then every 2.5 sec for 5, then reset board and
4763 * every 2.5 sec for 4.
4764 * Break our of the loop if errors occurred during init.
4766 while (((status & mask) != mask) &&
4767 !(status & HS_FFERM) &&
4779 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4780 lpfc_sli_brdrestart(phba);
4782 /* Read the HBA Host Status Register */
4783 if (lpfc_readl(phba->HSregaddr, &status)) {
4789 /* Check to see if any errors occurred during init */
4790 if ((status & HS_FFERM) || (i >= 20)) {
4791 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4792 "2751 Adapter failed to restart, "
4793 "status reg x%x, FW Data: A8 x%x AC x%x\n",
4795 readl(phba->MBslimaddr + 0xa8),
4796 readl(phba->MBslimaddr + 0xac));
4797 phba->link_state = LPFC_HBA_ERROR;
4805 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
4806 * @phba: Pointer to HBA context object.
4807 * @mask: Bit mask to be checked.
4809 * This function checks the host status register to check if HBA is
4810 * ready. This function will wait in a loop for the HBA to be ready
4811 * If the HBA is not ready , the function will will reset the HBA PCI
4812 * function again. The function returns 1 when HBA fail to be ready
4813 * otherwise returns zero.
4816 lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
4821 /* Read the HBA Host Status Register */
4822 status = lpfc_sli4_post_status_check(phba);
4825 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4826 lpfc_sli_brdrestart(phba);
4827 status = lpfc_sli4_post_status_check(phba);
4830 /* Check to see if any errors occurred during init */
4832 phba->link_state = LPFC_HBA_ERROR;
4835 phba->sli4_hba.intr_enable = 0;
4837 phba->hba_flag &= ~HBA_SETUP;
4842 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
4843 * @phba: Pointer to HBA context object.
4844 * @mask: Bit mask to be checked.
4846 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
4847 * from the API jump table function pointer from the lpfc_hba struct.
4850 lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
4852 return phba->lpfc_sli_brdready(phba, mask);
4855 #define BARRIER_TEST_PATTERN (0xdeadbeef)
4858 * lpfc_reset_barrier - Make HBA ready for HBA reset
4859 * @phba: Pointer to HBA context object.
4861 * This function is called before resetting an HBA. This function is called
4862 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4864 void lpfc_reset_barrier(struct lpfc_hba *phba)
4866 uint32_t __iomem *resp_buf;
4867 uint32_t __iomem *mbox_buf;
4868 volatile struct MAILBOX_word0 mbox;
4869 uint32_t hc_copy, ha_copy, resp_data;
4873 lockdep_assert_held(&phba->hbalock);
4875 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
4876 if (hdrtype != 0x80 ||
4877 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
4878 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
4882 * Tell the other part of the chip to suspend temporarily all
4885 resp_buf = phba->MBslimaddr;
4887 /* Disable the error attention */
4888 if (lpfc_readl(phba->HCregaddr, &hc_copy))
4890 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
4891 readl(phba->HCregaddr); /* flush */
4892 phba->link_flag |= LS_IGNORE_ERATT;
4894 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4896 if (ha_copy & HA_ERATT) {
4897 /* Clear Chip error bit */
4898 writel(HA_ERATT, phba->HAregaddr);
4899 phba->pport->stopped = 1;
4903 mbox.mbxCommand = MBX_KILL_BOARD;
4904 mbox.mbxOwner = OWN_CHIP;
4906 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
4907 mbox_buf = phba->MBslimaddr;
4908 writel(mbox.word0, mbox_buf);
4910 for (i = 0; i < 50; i++) {
4911 if (lpfc_readl((resp_buf + 1), &resp_data))
4913 if (resp_data != ~(BARRIER_TEST_PATTERN))
4919 if (lpfc_readl((resp_buf + 1), &resp_data))
4921 if (resp_data != ~(BARRIER_TEST_PATTERN)) {
4922 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
4923 phba->pport->stopped)
4929 mbox.mbxOwner = OWN_HOST;
4931 for (i = 0; i < 500; i++) {
4932 if (lpfc_readl(resp_buf, &resp_data))
4934 if (resp_data != mbox.word0)
4943 if (lpfc_readl(phba->HAregaddr, &ha_copy))
4945 if (!(ha_copy & HA_ERATT))
4951 if (readl(phba->HAregaddr) & HA_ERATT) {
4952 writel(HA_ERATT, phba->HAregaddr);
4953 phba->pport->stopped = 1;
4957 phba->link_flag &= ~LS_IGNORE_ERATT;
4958 writel(hc_copy, phba->HCregaddr);
4959 readl(phba->HCregaddr); /* flush */
4963 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4964 * @phba: Pointer to HBA context object.
4966 * This function issues a kill_board mailbox command and waits for
4967 * the error attention interrupt. This function is called for stopping
4968 * the firmware processing. The caller is not required to hold any
4969 * locks. This function calls lpfc_hba_down_post function to free
4970 * any pending commands after the kill. The function will return 1 when it
4971 * fails to kill the board else will return 0.
4974 lpfc_sli_brdkill(struct lpfc_hba *phba)
4976 struct lpfc_sli *psli;
4986 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4987 "0329 Kill HBA Data: x%x x%x\n",
4988 phba->pport->port_state, psli->sli_flag);
4990 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4994 /* Disable the error attention */
4995 spin_lock_irq(&phba->hbalock);
4996 if (lpfc_readl(phba->HCregaddr, &status)) {
4997 spin_unlock_irq(&phba->hbalock);
4998 mempool_free(pmb, phba->mbox_mem_pool);
5001 status &= ~HC_ERINT_ENA;
5002 writel(status, phba->HCregaddr);
5003 readl(phba->HCregaddr); /* flush */
5004 phba->link_flag |= LS_IGNORE_ERATT;
5005 spin_unlock_irq(&phba->hbalock);
5007 lpfc_kill_board(phba, pmb);
5008 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5009 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
5011 if (retval != MBX_SUCCESS) {
5012 if (retval != MBX_BUSY)
5013 mempool_free(pmb, phba->mbox_mem_pool);
5014 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5015 "2752 KILL_BOARD command failed retval %d\n",
5017 spin_lock_irq(&phba->hbalock);
5018 phba->link_flag &= ~LS_IGNORE_ERATT;
5019 spin_unlock_irq(&phba->hbalock);
5023 spin_lock_irq(&phba->hbalock);
5024 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
5025 spin_unlock_irq(&phba->hbalock);
5027 mempool_free(pmb, phba->mbox_mem_pool);
5029 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
5030 * attention every 100ms for 3 seconds. If we don't get ERATT after
5031 * 3 seconds we still set HBA_ERROR state because the status of the
5032 * board is now undefined.
5034 if (lpfc_readl(phba->HAregaddr, &ha_copy))
5036 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
5038 if (lpfc_readl(phba->HAregaddr, &ha_copy))
5042 del_timer_sync(&psli->mbox_tmo);
5043 if (ha_copy & HA_ERATT) {
5044 writel(HA_ERATT, phba->HAregaddr);
5045 phba->pport->stopped = 1;
5047 spin_lock_irq(&phba->hbalock);
5048 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5049 psli->mbox_active = NULL;
5050 phba->link_flag &= ~LS_IGNORE_ERATT;
5051 spin_unlock_irq(&phba->hbalock);
5053 lpfc_hba_down_post(phba);
5054 phba->link_state = LPFC_HBA_ERROR;
5056 return ha_copy & HA_ERATT ? 0 : 1;
5060 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
5061 * @phba: Pointer to HBA context object.
5063 * This function resets the HBA by writing HC_INITFF to the control
5064 * register. After the HBA resets, this function resets all the iocb ring
5065 * indices. This function disables PCI layer parity checking during
5067 * This function returns 0 always.
5068 * The caller is not required to hold any locks.
5071 lpfc_sli_brdreset(struct lpfc_hba *phba)
5073 struct lpfc_sli *psli;
5074 struct lpfc_sli_ring *pring;
5081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5082 "0325 Reset HBA Data: x%x x%x\n",
5083 (phba->pport) ? phba->pport->port_state : 0,
5086 /* perform board reset */
5087 phba->fc_eventTag = 0;
5088 phba->link_events = 0;
5089 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
5091 phba->pport->fc_myDID = 0;
5092 phba->pport->fc_prevDID = 0;
5095 /* Turn off parity checking and serr during the physical reset */
5096 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
5099 pci_write_config_word(phba->pcidev, PCI_COMMAND,
5101 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
5103 psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
5105 /* Now toggle INITFF bit in the Host Control Register */
5106 writel(HC_INITFF, phba->HCregaddr);
5108 readl(phba->HCregaddr); /* flush */
5109 writel(0, phba->HCregaddr);
5110 readl(phba->HCregaddr); /* flush */
5112 /* Restore PCI cmd register */
5113 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
5115 /* Initialize relevant SLI info */
5116 for (i = 0; i < psli->num_rings; i++) {
5117 pring = &psli->sli3_ring[i];
5119 pring->sli.sli3.rspidx = 0;
5120 pring->sli.sli3.next_cmdidx = 0;
5121 pring->sli.sli3.local_getidx = 0;
5122 pring->sli.sli3.cmdidx = 0;
5123 pring->missbufcnt = 0;
5126 phba->link_state = LPFC_WARM_START;
5131 * lpfc_sli4_brdreset - Reset a sli-4 HBA
5132 * @phba: Pointer to HBA context object.
5134 * This function resets a SLI4 HBA. This function disables PCI layer parity
5135 * checking during resets the device. The caller is not required to hold
5138 * This function returns 0 on success else returns negative error code.
5141 lpfc_sli4_brdreset(struct lpfc_hba *phba)
5143 struct lpfc_sli *psli = &phba->sli;
5148 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5149 "0295 Reset HBA Data: x%x x%x x%x\n",
5150 phba->pport->port_state, psli->sli_flag,
5153 /* perform board reset */
5154 phba->fc_eventTag = 0;
5155 phba->link_events = 0;
5156 phba->pport->fc_myDID = 0;
5157 phba->pport->fc_prevDID = 0;
5158 phba->hba_flag &= ~HBA_SETUP;
5160 spin_lock_irq(&phba->hbalock);
5161 psli->sli_flag &= ~(LPFC_PROCESS_LA);
5162 phba->fcf.fcf_flag = 0;
5163 spin_unlock_irq(&phba->hbalock);
5165 /* Now physically reset the device */
5166 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5167 "0389 Performing PCI function reset!\n");
5169 /* Turn off parity checking and serr during the physical reset */
5170 if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
5171 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5172 "3205 PCI read Config failed\n");
5176 pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
5177 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
5179 /* Perform FCoE PCI function reset before freeing queue memory */
5180 rc = lpfc_pci_function_reset(phba);
5182 /* Restore PCI cmd register */
5183 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
5189 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
5190 * @phba: Pointer to HBA context object.
5192 * This function is called in the SLI initialization code path to
5193 * restart the HBA. The caller is not required to hold any lock.
5194 * This function writes MBX_RESTART mailbox command to the SLIM and
5195 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
5196 * function to free any pending commands. The function enables
5197 * POST only during the first initialization. The function returns zero.
5198 * The function does not guarantee completion of MBX_RESTART mailbox
5199 * command before the return of this function.
5202 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
5204 volatile struct MAILBOX_word0 mb;
5205 struct lpfc_sli *psli;
5206 void __iomem *to_slim;
5207 uint32_t hba_aer_enabled;
5209 spin_lock_irq(&phba->hbalock);
5211 /* Take PCIe device Advanced Error Reporting (AER) state */
5212 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
5217 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5218 "0337 Restart HBA Data: x%x x%x\n",
5219 (phba->pport) ? phba->pport->port_state : 0,
5223 mb.mbxCommand = MBX_RESTART;
5226 lpfc_reset_barrier(phba);
5228 to_slim = phba->MBslimaddr;
5229 writel(mb.word0, to_slim);
5230 readl(to_slim); /* flush */
5232 /* Only skip post after fc_ffinit is completed */
5233 if (phba->pport && phba->pport->port_state)
5234 mb.word0 = 1; /* This is really setting up word1 */
5236 mb.word0 = 0; /* This is really setting up word1 */
5237 to_slim = phba->MBslimaddr + sizeof (uint32_t);
5238 writel(mb.word0, to_slim);
5239 readl(to_slim); /* flush */
5241 lpfc_sli_brdreset(phba);
5243 phba->pport->stopped = 0;
5244 phba->link_state = LPFC_INIT_START;
5246 spin_unlock_irq(&phba->hbalock);
5248 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
5249 psli->stats_start = ktime_get_seconds();
5251 /* Give the INITFF and Post time to settle. */
5254 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
5255 if (hba_aer_enabled)
5256 pci_disable_pcie_error_reporting(phba->pcidev);
5258 lpfc_hba_down_post(phba);
5264 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
5265 * @phba: Pointer to HBA context object.
5267 * This function is called in the SLI initialization code path to restart
5268 * a SLI4 HBA. The caller is not required to hold any lock.
5269 * At the end of the function, it calls lpfc_hba_down_post function to
5270 * free any pending commands.
5273 lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
5275 struct lpfc_sli *psli = &phba->sli;
5276 uint32_t hba_aer_enabled;
5280 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5281 "0296 Restart HBA Data: x%x x%x\n",
5282 phba->pport->port_state, psli->sli_flag);
5284 /* Take PCIe device Advanced Error Reporting (AER) state */
5285 hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
5287 rc = lpfc_sli4_brdreset(phba);
5289 phba->link_state = LPFC_HBA_ERROR;
5290 goto hba_down_queue;
5293 spin_lock_irq(&phba->hbalock);
5294 phba->pport->stopped = 0;
5295 phba->link_state = LPFC_INIT_START;
5297 /* Preserve FA-PWWN expectation */
5298 phba->sli4_hba.fawwpn_flag &= LPFC_FAWWPN_FABRIC;
5299 spin_unlock_irq(&phba->hbalock);
5301 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
5302 psli->stats_start = ktime_get_seconds();
5304 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
5305 if (hba_aer_enabled)
5306 pci_disable_pcie_error_reporting(phba->pcidev);
5309 lpfc_hba_down_post(phba);
5310 lpfc_sli4_queue_destroy(phba);
5316 * lpfc_sli_brdrestart - Wrapper func for restarting hba
5317 * @phba: Pointer to HBA context object.
5319 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
5320 * API jump table function pointer from the lpfc_hba struct.
5323 lpfc_sli_brdrestart(struct lpfc_hba *phba)
5325 return phba->lpfc_sli_brdrestart(phba);
5329 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
5330 * @phba: Pointer to HBA context object.
5332 * This function is called after a HBA restart to wait for successful
5333 * restart of the HBA. Successful restart of the HBA is indicated by
5334 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
5335 * iteration, the function will restart the HBA again. The function returns
5336 * zero if HBA successfully restarted else returns negative error code.
5339 lpfc_sli_chipset_init(struct lpfc_hba *phba)
5341 uint32_t status, i = 0;
5343 /* Read the HBA Host Status Register */
5344 if (lpfc_readl(phba->HSregaddr, &status))
5347 /* Check status register to see what current state is */
5349 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
5351 /* Check every 10ms for 10 retries, then every 100ms for 90
5352 * retries, then every 1 sec for 50 retires for a total of
5353 * ~60 seconds before reset the board again and check every
5354 * 1 sec for 50 retries. The up to 60 seconds before the
5355 * board ready is required by the Falcon FIPS zeroization
5356 * complete, and any reset the board in between shall cause
5357 * restart of zeroization, further delay the board ready.
5360 /* Adapter failed to init, timeout, status reg
5362 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5363 "0436 Adapter failed to init, "
5364 "timeout, status reg x%x, "
5365 "FW Data: A8 x%x AC x%x\n", status,
5366 readl(phba->MBslimaddr + 0xa8),
5367 readl(phba->MBslimaddr + 0xac));
5368 phba->link_state = LPFC_HBA_ERROR;
5372 /* Check to see if any errors occurred during init */
5373 if (status & HS_FFERM) {
5374 /* ERROR: During chipset initialization */
5375 /* Adapter failed to init, chipset, status reg
5377 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5378 "0437 Adapter failed to init, "
5379 "chipset, status reg x%x, "
5380 "FW Data: A8 x%x AC x%x\n", status,
5381 readl(phba->MBslimaddr + 0xa8),
5382 readl(phba->MBslimaddr + 0xac));
5383 phba->link_state = LPFC_HBA_ERROR;
5396 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5397 lpfc_sli_brdrestart(phba);
5399 /* Read the HBA Host Status Register */
5400 if (lpfc_readl(phba->HSregaddr, &status))
5404 /* Check to see if any errors occurred during init */
5405 if (status & HS_FFERM) {
5406 /* ERROR: During chipset initialization */
5407 /* Adapter failed to init, chipset, status reg <status> */
5408 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5409 "0438 Adapter failed to init, chipset, "
5411 "FW Data: A8 x%x AC x%x\n", status,
5412 readl(phba->MBslimaddr + 0xa8),
5413 readl(phba->MBslimaddr + 0xac));
5414 phba->link_state = LPFC_HBA_ERROR;
5418 phba->hba_flag |= HBA_NEEDS_CFG_PORT;
5420 /* Clear all interrupt enable conditions */
5421 writel(0, phba->HCregaddr);
5422 readl(phba->HCregaddr); /* flush */
5424 /* setup host attn register */
5425 writel(0xffffffff, phba->HAregaddr);
5426 readl(phba->HAregaddr); /* flush */
5431 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
5433 * This function calculates and returns the number of HBQs required to be
5437 lpfc_sli_hbq_count(void)
5439 return ARRAY_SIZE(lpfc_hbq_defs);
5443 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
5445 * This function adds the number of hbq entries in every HBQ to get
5446 * the total number of hbq entries required for the HBA and returns
5450 lpfc_sli_hbq_entry_count(void)
5452 int hbq_count = lpfc_sli_hbq_count();
5456 for (i = 0; i < hbq_count; ++i)
5457 count += lpfc_hbq_defs[i]->entry_count;
5462 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
5464 * This function calculates amount of memory required for all hbq entries
5465 * to be configured and returns the total memory required.
5468 lpfc_sli_hbq_size(void)
5470 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
5474 * lpfc_sli_hbq_setup - configure and initialize HBQs
5475 * @phba: Pointer to HBA context object.
5477 * This function is called during the SLI initialization to configure
5478 * all the HBQs and post buffers to the HBQ. The caller is not
5479 * required to hold any locks. This function will return zero if successful
5480 * else it will return negative error code.
5483 lpfc_sli_hbq_setup(struct lpfc_hba *phba)
5485 int hbq_count = lpfc_sli_hbq_count();
5489 uint32_t hbq_entry_index;
5491 /* Get a Mailbox buffer to setup mailbox
5492 * commands for HBA initialization
5494 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5501 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
5502 phba->link_state = LPFC_INIT_MBX_CMDS;
5503 phba->hbq_in_use = 1;
5505 hbq_entry_index = 0;
5506 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
5507 phba->hbqs[hbqno].next_hbqPutIdx = 0;
5508 phba->hbqs[hbqno].hbqPutIdx = 0;
5509 phba->hbqs[hbqno].local_hbqGetIdx = 0;
5510 phba->hbqs[hbqno].entry_count =
5511 lpfc_hbq_defs[hbqno]->entry_count;
5512 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
5513 hbq_entry_index, pmb);
5514 hbq_entry_index += phba->hbqs[hbqno].entry_count;
5516 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
5517 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
5518 mbxStatus <status>, ring <num> */
5520 lpfc_printf_log(phba, KERN_ERR,
5521 LOG_SLI | LOG_VPORT,
5522 "1805 Adapter failed to init. "
5523 "Data: x%x x%x x%x\n",
5525 pmbox->mbxStatus, hbqno);
5527 phba->link_state = LPFC_HBA_ERROR;
5528 mempool_free(pmb, phba->mbox_mem_pool);
5532 phba->hbq_count = hbq_count;
5534 mempool_free(pmb, phba->mbox_mem_pool);
5536 /* Initially populate or replenish the HBQs */
5537 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
5538 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
5543 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
5544 * @phba: Pointer to HBA context object.
5546 * This function is called during the SLI initialization to configure
5547 * all the HBQs and post buffers to the HBQ. The caller is not
5548 * required to hold any locks. This function will return zero if successful
5549 * else it will return negative error code.
5552 lpfc_sli4_rb_setup(struct lpfc_hba *phba)
5554 phba->hbq_in_use = 1;
5556 * Specific case when the MDS diagnostics is enabled and supported.
5557 * The receive buffer count is truncated to manage the incoming
5560 if (phba->cfg_enable_mds_diags && phba->mds_diags_support)
5561 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5562 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1;
5564 phba->hbqs[LPFC_ELS_HBQ].entry_count =
5565 lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
5566 phba->hbq_count = 1;
5567 lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
5568 /* Initially populate or replenish the HBQs */
5573 * lpfc_sli_config_port - Issue config port mailbox command
5574 * @phba: Pointer to HBA context object.
5575 * @sli_mode: sli mode - 2/3
5577 * This function is called by the sli initialization code path
5578 * to issue config_port mailbox command. This function restarts the
5579 * HBA firmware and issues a config_port mailbox command to configure
5580 * the SLI interface in the sli mode specified by sli_mode
5581 * variable. The caller is not required to hold any locks.
5582 * The function returns 0 if successful, else returns negative error
5586 lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
5589 uint32_t resetcount = 0, rc = 0, done = 0;
5591 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5593 phba->link_state = LPFC_HBA_ERROR;
5597 phba->sli_rev = sli_mode;
5598 while (resetcount < 2 && !done) {
5599 spin_lock_irq(&phba->hbalock);
5600 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
5601 spin_unlock_irq(&phba->hbalock);
5602 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5603 lpfc_sli_brdrestart(phba);
5604 rc = lpfc_sli_chipset_init(phba);
5608 spin_lock_irq(&phba->hbalock);
5609 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
5610 spin_unlock_irq(&phba->hbalock);
5613 /* Call pre CONFIG_PORT mailbox command initialization. A
5614 * value of 0 means the call was successful. Any other
5615 * nonzero value is a failure, but if ERESTART is returned,
5616 * the driver may reset the HBA and try again.
5618 rc = lpfc_config_port_prep(phba);
5619 if (rc == -ERESTART) {
5620 phba->link_state = LPFC_LINK_UNKNOWN;
5625 phba->link_state = LPFC_INIT_MBX_CMDS;
5626 lpfc_config_port(phba, pmb);
5627 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
5628 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
5629 LPFC_SLI3_HBQ_ENABLED |
5630 LPFC_SLI3_CRP_ENABLED |
5631 LPFC_SLI3_DSS_ENABLED);
5632 if (rc != MBX_SUCCESS) {
5633 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5634 "0442 Adapter failed to init, mbxCmd x%x "
5635 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
5636 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
5637 spin_lock_irq(&phba->hbalock);
5638 phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
5639 spin_unlock_irq(&phba->hbalock);
5642 /* Allow asynchronous mailbox command to go through */
5643 spin_lock_irq(&phba->hbalock);
5644 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
5645 spin_unlock_irq(&phba->hbalock);
5648 if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
5649 (pmb->u.mb.un.varCfgPort.gasabt == 0))
5650 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5651 "3110 Port did not grant ASABT\n");
5656 goto do_prep_failed;
5658 if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
5659 if (!pmb->u.mb.un.varCfgPort.cMA) {
5661 goto do_prep_failed;
5663 if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
5664 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
5665 phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
5666 phba->max_vports = (phba->max_vpi > phba->max_vports) ?
5667 phba->max_vpi : phba->max_vports;
5671 if (pmb->u.mb.un.varCfgPort.gerbm)
5672 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
5673 if (pmb->u.mb.un.varCfgPort.gcrp)
5674 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
5676 phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
5677 phba->port_gp = phba->mbox->us.s3_pgp.port;
5679 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
5680 if (pmb->u.mb.un.varCfgPort.gbg == 0) {
5681 phba->cfg_enable_bg = 0;
5682 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
5683 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5684 "0443 Adapter did not grant "
5689 phba->hbq_get = NULL;
5690 phba->port_gp = phba->mbox->us.s2.port;
5694 mempool_free(pmb, phba->mbox_mem_pool);
5700 * lpfc_sli_hba_setup - SLI initialization function
5701 * @phba: Pointer to HBA context object.
5703 * This function is the main SLI initialization function. This function
5704 * is called by the HBA initialization code, HBA reset code and HBA
5705 * error attention handler code. Caller is not required to hold any
5706 * locks. This function issues config_port mailbox command to configure
5707 * the SLI, setup iocb rings and HBQ rings. In the end the function
5708 * calls the config_port_post function to issue init_link mailbox
5709 * command and to start the discovery. The function will return zero
5710 * if successful, else it will return negative error code.
5713 lpfc_sli_hba_setup(struct lpfc_hba *phba)
5719 /* Enable ISR already does config_port because of config_msi mbx */
5720 if (phba->hba_flag & HBA_NEEDS_CFG_PORT) {
5721 rc = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
5724 phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
5726 phba->fcp_embed_io = 0; /* SLI4 FC support only */
5728 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5729 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
5730 rc = pci_enable_pcie_error_reporting(phba->pcidev);
5732 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5733 "2709 This device supports "
5734 "Advanced Error Reporting (AER)\n");
5735 spin_lock_irq(&phba->hbalock);
5736 phba->hba_flag |= HBA_AER_ENABLED;
5737 spin_unlock_irq(&phba->hbalock);
5739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5740 "2708 This device does not support "
5741 "Advanced Error Reporting (AER): %d\n",
5743 phba->cfg_aer_support = 0;
5747 if (phba->sli_rev == 3) {
5748 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
5749 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
5751 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
5752 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
5753 phba->sli3_options = 0;
5756 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5757 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
5758 phba->sli_rev, phba->max_vpi);
5759 rc = lpfc_sli_ring_map(phba);
5762 goto lpfc_sli_hba_setup_error;
5764 /* Initialize VPIs. */
5765 if (phba->sli_rev == LPFC_SLI_REV3) {
5767 * The VPI bitmask and physical ID array are allocated
5768 * and initialized once only - at driver load. A port
5769 * reset doesn't need to reinitialize this memory.
5771 if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
5772 longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
5773 phba->vpi_bmask = kcalloc(longs,
5774 sizeof(unsigned long),
5776 if (!phba->vpi_bmask) {
5778 goto lpfc_sli_hba_setup_error;
5781 phba->vpi_ids = kcalloc(phba->max_vpi + 1,
5784 if (!phba->vpi_ids) {
5785 kfree(phba->vpi_bmask);
5787 goto lpfc_sli_hba_setup_error;
5789 for (i = 0; i < phba->max_vpi; i++)
5790 phba->vpi_ids[i] = i;
5795 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
5796 rc = lpfc_sli_hbq_setup(phba);
5798 goto lpfc_sli_hba_setup_error;
5800 spin_lock_irq(&phba->hbalock);
5801 phba->sli.sli_flag |= LPFC_PROCESS_LA;
5802 spin_unlock_irq(&phba->hbalock);
5804 rc = lpfc_config_port_post(phba);
5806 goto lpfc_sli_hba_setup_error;
5810 lpfc_sli_hba_setup_error:
5811 phba->link_state = LPFC_HBA_ERROR;
5812 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5813 "0445 Firmware initialization failed\n");
5818 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
5819 * @phba: Pointer to HBA context object.
5821 * This function issue a dump mailbox command to read config region
5822 * 23 and parse the records in the region and populate driver
5826 lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
5828 LPFC_MBOXQ_t *mboxq;
5829 struct lpfc_dmabuf *mp;
5830 struct lpfc_mqe *mqe;
5831 uint32_t data_length;
5834 /* Program the default value of vlan_id and fc_map */
5835 phba->valid_vlan = 0;
5836 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5837 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5838 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5840 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5844 mqe = &mboxq->u.mqe;
5845 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
5847 goto out_free_mboxq;
5850 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
5851 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5853 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
5854 "(%d):2571 Mailbox cmd x%x Status x%x "
5855 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5856 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5857 "CQ: x%x x%x x%x x%x\n",
5858 mboxq->vport ? mboxq->vport->vpi : 0,
5859 bf_get(lpfc_mqe_command, mqe),
5860 bf_get(lpfc_mqe_status, mqe),
5861 mqe->un.mb_words[0], mqe->un.mb_words[1],
5862 mqe->un.mb_words[2], mqe->un.mb_words[3],
5863 mqe->un.mb_words[4], mqe->un.mb_words[5],
5864 mqe->un.mb_words[6], mqe->un.mb_words[7],
5865 mqe->un.mb_words[8], mqe->un.mb_words[9],
5866 mqe->un.mb_words[10], mqe->un.mb_words[11],
5867 mqe->un.mb_words[12], mqe->un.mb_words[13],
5868 mqe->un.mb_words[14], mqe->un.mb_words[15],
5869 mqe->un.mb_words[16], mqe->un.mb_words[50],
5871 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
5872 mboxq->mcqe.trailer);
5876 goto out_free_mboxq;
5878 data_length = mqe->un.mb_words[5];
5879 if (data_length > DMP_RGN23_SIZE) {
5881 goto out_free_mboxq;
5884 lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
5888 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
5893 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5894 * @phba: pointer to lpfc hba data structure.
5895 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5896 * @vpd: pointer to the memory to hold resulting port vpd data.
5897 * @vpd_size: On input, the number of bytes allocated to @vpd.
5898 * On output, the number of data bytes in @vpd.
5900 * This routine executes a READ_REV SLI4 mailbox command. In
5901 * addition, this routine gets the port vpd data.
5905 * -ENOMEM - could not allocated memory.
5908 lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
5909 uint8_t *vpd, uint32_t *vpd_size)
5913 struct lpfc_dmabuf *dmabuf;
5914 struct lpfc_mqe *mqe;
5916 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
5921 * Get a DMA buffer for the vpd data resulting from the READ_REV
5924 dma_size = *vpd_size;
5925 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
5926 &dmabuf->phys, GFP_KERNEL);
5927 if (!dmabuf->virt) {
5933 * The SLI4 implementation of READ_REV conflicts at word1,
5934 * bits 31:16 and SLI4 adds vpd functionality not present
5935 * in SLI3. This code corrects the conflicts.
5937 lpfc_read_rev(phba, mboxq);
5938 mqe = &mboxq->u.mqe;
5939 mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
5940 mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
5941 mqe->un.read_rev.word1 &= 0x0000FFFF;
5942 bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
5943 bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
5945 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5947 dma_free_coherent(&phba->pcidev->dev, dma_size,
5948 dmabuf->virt, dmabuf->phys);
5954 * The available vpd length cannot be bigger than the
5955 * DMA buffer passed to the port. Catch the less than
5956 * case and update the caller's size.
5958 if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
5959 *vpd_size = mqe->un.read_rev.avail_vpd_len;
5961 memcpy(vpd, dmabuf->virt, *vpd_size);
5963 dma_free_coherent(&phba->pcidev->dev, dma_size,
5964 dmabuf->virt, dmabuf->phys);
5970 * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
5971 * @phba: pointer to lpfc hba data structure.
5973 * This routine retrieves SLI4 device physical port name this PCI function
5978 * otherwise - failed to retrieve controller attributes
5981 lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
5983 LPFC_MBOXQ_t *mboxq;
5984 struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
5985 struct lpfc_controller_attribute *cntl_attr;
5986 void *virtaddr = NULL;
5987 uint32_t alloclen, reqlen;
5988 uint32_t shdr_status, shdr_add_status;
5989 union lpfc_sli4_cfg_shdr *shdr;
5992 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5996 /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
5997 reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
5998 alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5999 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
6000 LPFC_SLI4_MBX_NEMBED);
6002 if (alloclen < reqlen) {
6003 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6004 "3084 Allocated DMA memory size (%d) is "
6005 "less than the requested DMA memory size "
6006 "(%d)\n", alloclen, reqlen);
6008 goto out_free_mboxq;
6010 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6011 virtaddr = mboxq->sge_array->addr[0];
6012 mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
6013 shdr = &mbx_cntl_attr->cfg_shdr;
6014 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6015 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6016 if (shdr_status || shdr_add_status || rc) {
6017 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6018 "3085 Mailbox x%x (x%x/x%x) failed, "
6019 "rc:x%x, status:x%x, add_status:x%x\n",
6020 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6021 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
6022 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
6023 rc, shdr_status, shdr_add_status);
6025 goto out_free_mboxq;
6028 cntl_attr = &mbx_cntl_attr->cntl_attr;
6029 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
6030 phba->sli4_hba.lnk_info.lnk_tp =
6031 bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
6032 phba->sli4_hba.lnk_info.lnk_no =
6033 bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
6034 phba->sli4_hba.flash_id = bf_get(lpfc_cntl_attr_flash_id, cntl_attr);
6035 phba->sli4_hba.asic_rev = bf_get(lpfc_cntl_attr_asic_rev, cntl_attr);
6037 memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
6038 strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
6039 sizeof(phba->BIOSVersion));
6041 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6042 "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s, "
6043 "flash_id: x%02x, asic_rev: x%02x\n",
6044 phba->sli4_hba.lnk_info.lnk_tp,
6045 phba->sli4_hba.lnk_info.lnk_no,
6046 phba->BIOSVersion, phba->sli4_hba.flash_id,
6047 phba->sli4_hba.asic_rev);
6049 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
6050 lpfc_sli4_mbox_cmd_free(phba, mboxq);
6052 mempool_free(mboxq, phba->mbox_mem_pool);
6057 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
6058 * @phba: pointer to lpfc hba data structure.
6060 * This routine retrieves SLI4 device physical port name this PCI function
6065 * otherwise - failed to retrieve physical port name
6068 lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
6070 LPFC_MBOXQ_t *mboxq;
6071 struct lpfc_mbx_get_port_name *get_port_name;
6072 uint32_t shdr_status, shdr_add_status;
6073 union lpfc_sli4_cfg_shdr *shdr;
6074 char cport_name = 0;
6077 /* We assume nothing at this point */
6078 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
6079 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
6081 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6084 /* obtain link type and link number via READ_CONFIG */
6085 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
6086 lpfc_sli4_read_config(phba);
6088 if (phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG)
6089 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
6091 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
6092 goto retrieve_ppname;
6094 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
6095 rc = lpfc_sli4_get_ctl_attr(phba);
6097 goto out_free_mboxq;
6100 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
6101 LPFC_MBOX_OPCODE_GET_PORT_NAME,
6102 sizeof(struct lpfc_mbx_get_port_name) -
6103 sizeof(struct lpfc_sli4_cfg_mhdr),
6104 LPFC_SLI4_MBX_EMBED);
6105 get_port_name = &mboxq->u.mqe.un.get_port_name;
6106 shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
6107 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
6108 bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
6109 phba->sli4_hba.lnk_info.lnk_tp);
6110 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6111 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6112 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6113 if (shdr_status || shdr_add_status || rc) {
6114 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
6115 "3087 Mailbox x%x (x%x/x%x) failed: "
6116 "rc:x%x, status:x%x, add_status:x%x\n",
6117 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6118 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
6119 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
6120 rc, shdr_status, shdr_add_status);
6122 goto out_free_mboxq;
6124 switch (phba->sli4_hba.lnk_info.lnk_no) {
6125 case LPFC_LINK_NUMBER_0:
6126 cport_name = bf_get(lpfc_mbx_get_port_name_name0,
6127 &get_port_name->u.response);
6128 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6130 case LPFC_LINK_NUMBER_1:
6131 cport_name = bf_get(lpfc_mbx_get_port_name_name1,
6132 &get_port_name->u.response);
6133 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6135 case LPFC_LINK_NUMBER_2:
6136 cport_name = bf_get(lpfc_mbx_get_port_name_name2,
6137 &get_port_name->u.response);
6138 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6140 case LPFC_LINK_NUMBER_3:
6141 cport_name = bf_get(lpfc_mbx_get_port_name_name3,
6142 &get_port_name->u.response);
6143 phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
6149 if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
6150 phba->Port[0] = cport_name;
6151 phba->Port[1] = '\0';
6152 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6153 "3091 SLI get port name: %s\n", phba->Port);
6157 if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
6158 lpfc_sli4_mbox_cmd_free(phba, mboxq);
6160 mempool_free(mboxq, phba->mbox_mem_pool);
6165 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
6166 * @phba: pointer to lpfc hba data structure.
6168 * This routine is called to explicitly arm the SLI4 device's completion and
6172 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
6175 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
6176 struct lpfc_sli4_hdw_queue *qp;
6177 struct lpfc_queue *eq;
6179 sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
6180 sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
6181 if (sli4_hba->nvmels_cq)
6182 sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
6185 if (sli4_hba->hdwq) {
6186 /* Loop thru all Hardware Queues */
6187 for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
6188 qp = &sli4_hba->hdwq[qidx];
6189 /* ARM the corresponding CQ */
6190 sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
6194 /* Loop thru all IRQ vectors */
6195 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
6196 eq = sli4_hba->hba_eq_hdl[qidx].eq;
6197 /* ARM the corresponding EQ */
6198 sli4_hba->sli4_write_eq_db(phba, eq,
6199 0, LPFC_QUEUE_REARM);
6203 if (phba->nvmet_support) {
6204 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
6205 sli4_hba->sli4_write_cq_db(phba,
6206 sli4_hba->nvmet_cqset[qidx], 0,
6213 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
6214 * @phba: Pointer to HBA context object.
6215 * @type: The resource extent type.
6216 * @extnt_count: buffer to hold port available extent count.
6217 * @extnt_size: buffer to hold element count per extent.
6219 * This function calls the port and retrievs the number of available
6220 * extents and their size for a particular extent type.
6222 * Returns: 0 if successful. Nonzero otherwise.
6225 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
6226 uint16_t *extnt_count, uint16_t *extnt_size)
6231 struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
6237 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6241 /* Find out how many extents are available for this resource type */
6242 length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
6243 sizeof(struct lpfc_sli4_cfg_mhdr));
6244 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6245 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
6246 length, LPFC_SLI4_MBX_EMBED);
6248 /* Send an extents count of 0 - the GET doesn't use it. */
6249 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6250 LPFC_SLI4_MBX_EMBED);
6256 if (!phba->sli4_hba.intr_enable)
6257 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6259 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6260 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6267 rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
6268 if (bf_get(lpfc_mbox_hdr_status,
6269 &rsrc_info->header.cfg_shdr.response)) {
6270 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6271 "2930 Failed to get resource extents "
6272 "Status 0x%x Add'l Status 0x%x\n",
6273 bf_get(lpfc_mbox_hdr_status,
6274 &rsrc_info->header.cfg_shdr.response),
6275 bf_get(lpfc_mbox_hdr_add_status,
6276 &rsrc_info->header.cfg_shdr.response));
6281 *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
6283 *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
6286 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
6287 "3162 Retrieved extents type-%d from port: count:%d, "
6288 "size:%d\n", type, *extnt_count, *extnt_size);
6291 mempool_free(mbox, phba->mbox_mem_pool);
6296 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
6297 * @phba: Pointer to HBA context object.
6298 * @type: The extent type to check.
6300 * This function reads the current available extents from the port and checks
6301 * if the extent count or extent size has changed since the last access.
6302 * Callers use this routine post port reset to understand if there is a
6303 * extent reprovisioning requirement.
6306 * -Error: error indicates problem.
6307 * 1: Extent count or size has changed.
6311 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
6313 uint16_t curr_ext_cnt, rsrc_ext_cnt;
6314 uint16_t size_diff, rsrc_ext_size;
6316 struct lpfc_rsrc_blks *rsrc_entry;
6317 struct list_head *rsrc_blk_list = NULL;
6321 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
6328 case LPFC_RSC_TYPE_FCOE_RPI:
6329 rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
6331 case LPFC_RSC_TYPE_FCOE_VPI:
6332 rsrc_blk_list = &phba->lpfc_vpi_blk_list;
6334 case LPFC_RSC_TYPE_FCOE_XRI:
6335 rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
6337 case LPFC_RSC_TYPE_FCOE_VFI:
6338 rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
6344 list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
6346 if (rsrc_entry->rsrc_size != rsrc_ext_size)
6350 if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
6357 * lpfc_sli4_cfg_post_extnts -
6358 * @phba: Pointer to HBA context object.
6359 * @extnt_cnt: number of available extents.
6360 * @type: the extent type (rpi, xri, vfi, vpi).
6361 * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation.
6362 * @mbox: pointer to the caller's allocated mailbox structure.
6364 * This function executes the extents allocation request. It also
6365 * takes care of the amount of memory needed to allocate or get the
6366 * allocated extents. It is the caller's responsibility to evaluate
6370 * -Error: Error value describes the condition found.
6374 lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
6375 uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
6380 uint32_t alloc_len, mbox_tmo;
6382 /* Calculate the total requested length of the dma memory */
6383 req_len = extnt_cnt * sizeof(uint16_t);
6386 * Calculate the size of an embedded mailbox. The uint32_t
6387 * accounts for extents-specific word.
6389 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
6393 * Presume the allocation and response will fit into an embedded
6394 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6396 *emb = LPFC_SLI4_MBX_EMBED;
6397 if (req_len > emb_len) {
6398 req_len = extnt_cnt * sizeof(uint16_t) +
6399 sizeof(union lpfc_sli4_cfg_shdr) +
6401 *emb = LPFC_SLI4_MBX_NEMBED;
6404 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6405 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
6407 if (alloc_len < req_len) {
6408 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6409 "2982 Allocated DMA memory size (x%x) is "
6410 "less than the requested DMA memory "
6411 "size (x%x)\n", alloc_len, req_len);
6414 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
6418 if (!phba->sli4_hba.intr_enable)
6419 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6421 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6422 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6431 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
6432 * @phba: Pointer to HBA context object.
6433 * @type: The resource extent type to allocate.
6435 * This function allocates the number of elements for the specified
6439 lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
6442 uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
6443 uint16_t rsrc_id, rsrc_start, j, k;
6446 unsigned long longs;
6447 unsigned long *bmask;
6448 struct lpfc_rsrc_blks *rsrc_blks;
6451 struct lpfc_id_range *id_array = NULL;
6452 void *virtaddr = NULL;
6453 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
6454 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
6455 struct list_head *ext_blk_list;
6457 rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
6463 if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
6464 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6465 "3009 No available Resource Extents "
6466 "for resource type 0x%x: Count: 0x%x, "
6467 "Size 0x%x\n", type, rsrc_cnt,
6472 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
6473 "2903 Post resource extents type-0x%x: "
6474 "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
6476 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6480 rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
6487 * Figure out where the response is located. Then get local pointers
6488 * to the response data. The port does not guarantee to respond to
6489 * all extents counts request so update the local variable with the
6490 * allocated count from the port.
6492 if (emb == LPFC_SLI4_MBX_EMBED) {
6493 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
6494 id_array = &rsrc_ext->u.rsp.id[0];
6495 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
6497 virtaddr = mbox->sge_array->addr[0];
6498 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
6499 rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
6500 id_array = &n_rsrc->id;
6503 longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
6504 rsrc_id_cnt = rsrc_cnt * rsrc_size;
6507 * Based on the resource size and count, correct the base and max
6510 length = sizeof(struct lpfc_rsrc_blks);
6512 case LPFC_RSC_TYPE_FCOE_RPI:
6513 phba->sli4_hba.rpi_bmask = kcalloc(longs,
6514 sizeof(unsigned long),
6516 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
6520 phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
6523 if (unlikely(!phba->sli4_hba.rpi_ids)) {
6524 kfree(phba->sli4_hba.rpi_bmask);
6530 * The next_rpi was initialized with the maximum available
6531 * count but the port may allocate a smaller number. Catch
6532 * that case and update the next_rpi.
6534 phba->sli4_hba.next_rpi = rsrc_id_cnt;
6536 /* Initialize local ptrs for common extent processing later. */
6537 bmask = phba->sli4_hba.rpi_bmask;
6538 ids = phba->sli4_hba.rpi_ids;
6539 ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
6541 case LPFC_RSC_TYPE_FCOE_VPI:
6542 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
6544 if (unlikely(!phba->vpi_bmask)) {
6548 phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
6550 if (unlikely(!phba->vpi_ids)) {
6551 kfree(phba->vpi_bmask);
6556 /* Initialize local ptrs for common extent processing later. */
6557 bmask = phba->vpi_bmask;
6558 ids = phba->vpi_ids;
6559 ext_blk_list = &phba->lpfc_vpi_blk_list;
6561 case LPFC_RSC_TYPE_FCOE_XRI:
6562 phba->sli4_hba.xri_bmask = kcalloc(longs,
6563 sizeof(unsigned long),
6565 if (unlikely(!phba->sli4_hba.xri_bmask)) {
6569 phba->sli4_hba.max_cfg_param.xri_used = 0;
6570 phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
6573 if (unlikely(!phba->sli4_hba.xri_ids)) {
6574 kfree(phba->sli4_hba.xri_bmask);
6579 /* Initialize local ptrs for common extent processing later. */
6580 bmask = phba->sli4_hba.xri_bmask;
6581 ids = phba->sli4_hba.xri_ids;
6582 ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
6584 case LPFC_RSC_TYPE_FCOE_VFI:
6585 phba->sli4_hba.vfi_bmask = kcalloc(longs,
6586 sizeof(unsigned long),
6588 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
6592 phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
6595 if (unlikely(!phba->sli4_hba.vfi_ids)) {
6596 kfree(phba->sli4_hba.vfi_bmask);
6601 /* Initialize local ptrs for common extent processing later. */
6602 bmask = phba->sli4_hba.vfi_bmask;
6603 ids = phba->sli4_hba.vfi_ids;
6604 ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
6607 /* Unsupported Opcode. Fail call. */
6611 ext_blk_list = NULL;
6616 * Complete initializing the extent configuration with the
6617 * allocated ids assigned to this function. The bitmask serves
6618 * as an index into the array and manages the available ids. The
6619 * array just stores the ids communicated to the port via the wqes.
6621 for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
6623 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
6626 rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
6629 rsrc_blks = kzalloc(length, GFP_KERNEL);
6630 if (unlikely(!rsrc_blks)) {
6636 rsrc_blks->rsrc_start = rsrc_id;
6637 rsrc_blks->rsrc_size = rsrc_size;
6638 list_add_tail(&rsrc_blks->list, ext_blk_list);
6639 rsrc_start = rsrc_id;
6640 if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
6641 phba->sli4_hba.io_xri_start = rsrc_start +
6642 lpfc_sli4_get_iocb_cnt(phba);
6645 while (rsrc_id < (rsrc_start + rsrc_size)) {
6650 /* Entire word processed. Get next word.*/
6655 lpfc_sli4_mbox_cmd_free(phba, mbox);
6662 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
6663 * @phba: Pointer to HBA context object.
6664 * @type: the extent's type.
6666 * This function deallocates all extents of a particular resource type.
6667 * SLI4 does not allow for deallocating a particular extent range. It
6668 * is the caller's responsibility to release all kernel memory resources.
6671 lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
6674 uint32_t length, mbox_tmo = 0;
6676 struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
6677 struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
6679 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6684 * This function sends an embedded mailbox because it only sends the
6685 * the resource type. All extents of this type are released by the
6688 length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
6689 sizeof(struct lpfc_sli4_cfg_mhdr));
6690 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6691 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
6692 length, LPFC_SLI4_MBX_EMBED);
6694 /* Send an extents count of 0 - the dealloc doesn't use it. */
6695 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
6696 LPFC_SLI4_MBX_EMBED);
6701 if (!phba->sli4_hba.intr_enable)
6702 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
6704 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
6705 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
6712 dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
6713 if (bf_get(lpfc_mbox_hdr_status,
6714 &dealloc_rsrc->header.cfg_shdr.response)) {
6715 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6716 "2919 Failed to release resource extents "
6717 "for type %d - Status 0x%x Add'l Status 0x%x. "
6718 "Resource memory not released.\n",
6720 bf_get(lpfc_mbox_hdr_status,
6721 &dealloc_rsrc->header.cfg_shdr.response),
6722 bf_get(lpfc_mbox_hdr_add_status,
6723 &dealloc_rsrc->header.cfg_shdr.response));
6728 /* Release kernel memory resources for the specific type. */
6730 case LPFC_RSC_TYPE_FCOE_VPI:
6731 kfree(phba->vpi_bmask);
6732 kfree(phba->vpi_ids);
6733 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6734 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6735 &phba->lpfc_vpi_blk_list, list) {
6736 list_del_init(&rsrc_blk->list);
6739 phba->sli4_hba.max_cfg_param.vpi_used = 0;
6741 case LPFC_RSC_TYPE_FCOE_XRI:
6742 kfree(phba->sli4_hba.xri_bmask);
6743 kfree(phba->sli4_hba.xri_ids);
6744 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6745 &phba->sli4_hba.lpfc_xri_blk_list, list) {
6746 list_del_init(&rsrc_blk->list);
6750 case LPFC_RSC_TYPE_FCOE_VFI:
6751 kfree(phba->sli4_hba.vfi_bmask);
6752 kfree(phba->sli4_hba.vfi_ids);
6753 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6754 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6755 &phba->sli4_hba.lpfc_vfi_blk_list, list) {
6756 list_del_init(&rsrc_blk->list);
6760 case LPFC_RSC_TYPE_FCOE_RPI:
6761 /* RPI bitmask and physical id array are cleaned up earlier. */
6762 list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
6763 &phba->sli4_hba.lpfc_rpi_blk_list, list) {
6764 list_del_init(&rsrc_blk->list);
6772 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
6775 mempool_free(mbox, phba->mbox_mem_pool);
6780 lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
6786 len = sizeof(struct lpfc_mbx_set_feature) -
6787 sizeof(struct lpfc_sli4_cfg_mhdr);
6788 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6789 LPFC_MBOX_OPCODE_SET_FEATURES, len,
6790 LPFC_SLI4_MBX_EMBED);
6793 case LPFC_SET_UE_RECOVERY:
6794 bf_set(lpfc_mbx_set_feature_UER,
6795 &mbox->u.mqe.un.set_feature, 1);
6796 mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
6797 mbox->u.mqe.un.set_feature.param_len = 8;
6799 case LPFC_SET_MDS_DIAGS:
6800 bf_set(lpfc_mbx_set_feature_mds,
6801 &mbox->u.mqe.un.set_feature, 1);
6802 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
6803 &mbox->u.mqe.un.set_feature, 1);
6804 mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
6805 mbox->u.mqe.un.set_feature.param_len = 8;
6807 case LPFC_SET_CGN_SIGNAL:
6808 if (phba->cmf_active_mode == LPFC_CFG_OFF)
6811 sig_freq = phba->cgn_sig_freq;
6813 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
6814 bf_set(lpfc_mbx_set_feature_CGN_alarm_freq,
6815 &mbox->u.mqe.un.set_feature, sig_freq);
6816 bf_set(lpfc_mbx_set_feature_CGN_warn_freq,
6817 &mbox->u.mqe.un.set_feature, sig_freq);
6820 if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY)
6821 bf_set(lpfc_mbx_set_feature_CGN_warn_freq,
6822 &mbox->u.mqe.un.set_feature, sig_freq);
6824 if (phba->cmf_active_mode == LPFC_CFG_OFF ||
6825 phba->cgn_reg_signal == EDC_CG_SIG_NOTSUPPORTED)
6828 sig_freq = lpfc_acqe_cgn_frequency;
6830 bf_set(lpfc_mbx_set_feature_CGN_acqe_freq,
6831 &mbox->u.mqe.un.set_feature, sig_freq);
6833 mbox->u.mqe.un.set_feature.feature = LPFC_SET_CGN_SIGNAL;
6834 mbox->u.mqe.un.set_feature.param_len = 12;
6836 case LPFC_SET_DUAL_DUMP:
6837 bf_set(lpfc_mbx_set_feature_dd,
6838 &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP);
6839 bf_set(lpfc_mbx_set_feature_ddquery,
6840 &mbox->u.mqe.un.set_feature, 0);
6841 mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP;
6842 mbox->u.mqe.un.set_feature.param_len = 4;
6844 case LPFC_SET_ENABLE_MI:
6845 mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_MI;
6846 mbox->u.mqe.un.set_feature.param_len = 4;
6847 bf_set(lpfc_mbx_set_feature_milunq, &mbox->u.mqe.un.set_feature,
6848 phba->pport->cfg_lun_queue_depth);
6849 bf_set(lpfc_mbx_set_feature_mi, &mbox->u.mqe.un.set_feature,
6850 phba->sli4_hba.pc_sli4_params.mi_ver);
6852 case LPFC_SET_LD_SIGNAL:
6853 mbox->u.mqe.un.set_feature.feature = LPFC_SET_LD_SIGNAL;
6854 mbox->u.mqe.un.set_feature.param_len = 16;
6855 bf_set(lpfc_mbx_set_feature_lds_qry,
6856 &mbox->u.mqe.un.set_feature, LPFC_QUERY_LDS_OP);
6858 case LPFC_SET_ENABLE_CMF:
6859 mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_CMF;
6860 mbox->u.mqe.un.set_feature.param_len = 4;
6861 bf_set(lpfc_mbx_set_feature_cmf,
6862 &mbox->u.mqe.un.set_feature, 1);
6869 * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
6870 * @phba: Pointer to HBA context object.
6872 * Disable FW logging into host memory on the adapter. To
6873 * be done before reading logs from the host memory.
6876 lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
6878 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6880 spin_lock_irq(&phba->hbalock);
6881 ras_fwlog->state = INACTIVE;
6882 spin_unlock_irq(&phba->hbalock);
6884 /* Disable FW logging to host memory */
6885 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
6886 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
6888 /* Wait 10ms for firmware to stop using DMA buffer */
6889 usleep_range(10 * 1000, 20 * 1000);
6893 * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
6894 * @phba: Pointer to HBA context object.
6896 * This function is called to free memory allocated for RAS FW logging
6897 * support in the driver.
6900 lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
6902 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6903 struct lpfc_dmabuf *dmabuf, *next;
6905 if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
6906 list_for_each_entry_safe(dmabuf, next,
6907 &ras_fwlog->fwlog_buff_list,
6909 list_del(&dmabuf->list);
6910 dma_free_coherent(&phba->pcidev->dev,
6911 LPFC_RAS_MAX_ENTRY_SIZE,
6912 dmabuf->virt, dmabuf->phys);
6917 if (ras_fwlog->lwpd.virt) {
6918 dma_free_coherent(&phba->pcidev->dev,
6919 sizeof(uint32_t) * 2,
6920 ras_fwlog->lwpd.virt,
6921 ras_fwlog->lwpd.phys);
6922 ras_fwlog->lwpd.virt = NULL;
6925 spin_lock_irq(&phba->hbalock);
6926 ras_fwlog->state = INACTIVE;
6927 spin_unlock_irq(&phba->hbalock);
6931 * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
6932 * @phba: Pointer to HBA context object.
6933 * @fwlog_buff_count: Count of buffers to be created.
6935 * This routine DMA memory for Log Write Position Data[LPWD] and buffer
6936 * to update FW log is posted to the adapter.
6937 * Buffer count is calculated based on module param ras_fwlog_buffsize
6938 * Size of each buffer posted to FW is 64K.
6942 lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
6943 uint32_t fwlog_buff_count)
6945 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
6946 struct lpfc_dmabuf *dmabuf;
6949 /* Initialize List */
6950 INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
6952 /* Allocate memory for the LWPD */
6953 ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
6954 sizeof(uint32_t) * 2,
6955 &ras_fwlog->lwpd.phys,
6957 if (!ras_fwlog->lwpd.virt) {
6958 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6959 "6185 LWPD Memory Alloc Failed\n");
6964 ras_fwlog->fw_buffcount = fwlog_buff_count;
6965 for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
6966 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
6970 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6971 "6186 Memory Alloc failed FW logging");
6975 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
6976 LPFC_RAS_MAX_ENTRY_SIZE,
6977 &dmabuf->phys, GFP_KERNEL);
6978 if (!dmabuf->virt) {
6981 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6982 "6187 DMA Alloc Failed FW logging");
6985 dmabuf->buffer_tag = i;
6986 list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
6991 lpfc_sli4_ras_dma_free(phba);
6997 * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
6998 * @phba: pointer to lpfc hba data structure.
6999 * @pmb: pointer to the driver internal queue element for mailbox command.
7001 * Completion handler for driver's RAS MBX command to the device.
7004 lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7007 union lpfc_sli4_cfg_shdr *shdr;
7008 uint32_t shdr_status, shdr_add_status;
7009 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
7013 shdr = (union lpfc_sli4_cfg_shdr *)
7014 &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
7015 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7016 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7018 if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
7019 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7020 "6188 FW LOG mailbox "
7021 "completed with status x%x add_status x%x,"
7022 " mbx status x%x\n",
7023 shdr_status, shdr_add_status, mb->mbxStatus);
7025 ras_fwlog->ras_hwsupport = false;
7029 spin_lock_irq(&phba->hbalock);
7030 ras_fwlog->state = ACTIVE;
7031 spin_unlock_irq(&phba->hbalock);
7032 mempool_free(pmb, phba->mbox_mem_pool);
7037 /* Free RAS DMA memory */
7038 lpfc_sli4_ras_dma_free(phba);
7039 mempool_free(pmb, phba->mbox_mem_pool);
7043 * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
7044 * @phba: pointer to lpfc hba data structure.
7045 * @fwlog_level: Logging verbosity level.
7046 * @fwlog_enable: Enable/Disable logging.
7048 * Initialize memory and post mailbox command to enable FW logging in host
7052 lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
7053 uint32_t fwlog_level,
7054 uint32_t fwlog_enable)
7056 struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
7057 struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
7058 struct lpfc_dmabuf *dmabuf;
7060 uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
7063 spin_lock_irq(&phba->hbalock);
7064 ras_fwlog->state = INACTIVE;
7065 spin_unlock_irq(&phba->hbalock);
7067 fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
7068 phba->cfg_ras_fwlog_buffsize);
7069 fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
7072 * If re-enabling FW logging support use earlier allocated
7073 * DMA buffers while posting MBX command.
7075 if (!ras_fwlog->lwpd.virt) {
7076 rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
7078 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7079 "6189 FW Log Memory Allocation Failed");
7084 /* Setup Mailbox command */
7085 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7087 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7088 "6190 RAS MBX Alloc Failed");
7093 ras_fwlog->fw_loglevel = fwlog_level;
7094 len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
7095 sizeof(struct lpfc_sli4_cfg_mhdr));
7097 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
7098 LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
7099 len, LPFC_SLI4_MBX_EMBED);
7101 mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
7102 bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
7104 bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
7105 ras_fwlog->fw_loglevel);
7106 bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
7107 ras_fwlog->fw_buffcount);
7108 bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
7109 LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
7111 /* Update DMA buffer address */
7112 list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
7113 memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
7115 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
7116 putPaddrLow(dmabuf->phys);
7118 mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
7119 putPaddrHigh(dmabuf->phys);
7122 /* Update LPWD address */
7123 mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
7124 mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
7126 spin_lock_irq(&phba->hbalock);
7127 ras_fwlog->state = REG_INPROGRESS;
7128 spin_unlock_irq(&phba->hbalock);
7129 mbox->vport = phba->pport;
7130 mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
7132 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7134 if (rc == MBX_NOT_FINISHED) {
7135 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7136 "6191 FW-Log Mailbox failed. "
7137 "status %d mbxStatus : x%x", rc,
7138 bf_get(lpfc_mqe_status, &mbox->u.mqe));
7139 mempool_free(mbox, phba->mbox_mem_pool);
7146 lpfc_sli4_ras_dma_free(phba);
7152 * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
7153 * @phba: Pointer to HBA context object.
7155 * Check if RAS is supported on the adapter and initialize it.
7158 lpfc_sli4_ras_setup(struct lpfc_hba *phba)
7160 /* Check RAS FW Log needs to be enabled or not */
7161 if (lpfc_check_fwlog_support(phba))
7164 lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
7165 LPFC_RAS_ENABLE_LOGGING);
7169 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
7170 * @phba: Pointer to HBA context object.
7172 * This function allocates all SLI4 resource identifiers.
7175 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
7177 int i, rc, error = 0;
7178 uint16_t count, base;
7179 unsigned long longs;
7181 if (!phba->sli4_hba.rpi_hdrs_in_use)
7182 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
7183 if (phba->sli4_hba.extents_in_use) {
7185 * The port supports resource extents. The XRI, VPI, VFI, RPI
7186 * resource extent count must be read and allocated before
7187 * provisioning the resource id arrays.
7189 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
7190 LPFC_IDX_RSRC_RDY) {
7192 * Extent-based resources are set - the driver could
7193 * be in a port reset. Figure out if any corrective
7194 * actions need to be taken.
7196 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7197 LPFC_RSC_TYPE_FCOE_VFI);
7200 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7201 LPFC_RSC_TYPE_FCOE_VPI);
7204 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7205 LPFC_RSC_TYPE_FCOE_XRI);
7208 rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
7209 LPFC_RSC_TYPE_FCOE_RPI);
7214 * It's possible that the number of resources
7215 * provided to this port instance changed between
7216 * resets. Detect this condition and reallocate
7217 * resources. Otherwise, there is no action.
7220 lpfc_printf_log(phba, KERN_INFO,
7221 LOG_MBOX | LOG_INIT,
7222 "2931 Detected extent resource "
7223 "change. Reallocating all "
7225 rc = lpfc_sli4_dealloc_extent(phba,
7226 LPFC_RSC_TYPE_FCOE_VFI);
7227 rc = lpfc_sli4_dealloc_extent(phba,
7228 LPFC_RSC_TYPE_FCOE_VPI);
7229 rc = lpfc_sli4_dealloc_extent(phba,
7230 LPFC_RSC_TYPE_FCOE_XRI);
7231 rc = lpfc_sli4_dealloc_extent(phba,
7232 LPFC_RSC_TYPE_FCOE_RPI);
7237 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
7241 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
7245 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
7249 rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
7252 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
7257 * The port does not support resource extents. The XRI, VPI,
7258 * VFI, RPI resource ids were determined from READ_CONFIG.
7259 * Just allocate the bitmasks and provision the resource id
7260 * arrays. If a port reset is active, the resources don't
7261 * need any action - just exit.
7263 if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
7264 LPFC_IDX_RSRC_RDY) {
7265 lpfc_sli4_dealloc_resource_identifiers(phba);
7266 lpfc_sli4_remove_rpis(phba);
7269 count = phba->sli4_hba.max_cfg_param.max_rpi;
7271 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7272 "3279 Invalid provisioning of "
7277 base = phba->sli4_hba.max_cfg_param.rpi_base;
7278 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7279 phba->sli4_hba.rpi_bmask = kcalloc(longs,
7280 sizeof(unsigned long),
7282 if (unlikely(!phba->sli4_hba.rpi_bmask)) {
7286 phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
7288 if (unlikely(!phba->sli4_hba.rpi_ids)) {
7290 goto free_rpi_bmask;
7293 for (i = 0; i < count; i++)
7294 phba->sli4_hba.rpi_ids[i] = base + i;
7297 count = phba->sli4_hba.max_cfg_param.max_vpi;
7299 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7300 "3280 Invalid provisioning of "
7305 base = phba->sli4_hba.max_cfg_param.vpi_base;
7306 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7307 phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
7309 if (unlikely(!phba->vpi_bmask)) {
7313 phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
7315 if (unlikely(!phba->vpi_ids)) {
7317 goto free_vpi_bmask;
7320 for (i = 0; i < count; i++)
7321 phba->vpi_ids[i] = base + i;
7324 count = phba->sli4_hba.max_cfg_param.max_xri;
7326 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7327 "3281 Invalid provisioning of "
7332 base = phba->sli4_hba.max_cfg_param.xri_base;
7333 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7334 phba->sli4_hba.xri_bmask = kcalloc(longs,
7335 sizeof(unsigned long),
7337 if (unlikely(!phba->sli4_hba.xri_bmask)) {
7341 phba->sli4_hba.max_cfg_param.xri_used = 0;
7342 phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
7344 if (unlikely(!phba->sli4_hba.xri_ids)) {
7346 goto free_xri_bmask;
7349 for (i = 0; i < count; i++)
7350 phba->sli4_hba.xri_ids[i] = base + i;
7353 count = phba->sli4_hba.max_cfg_param.max_vfi;
7355 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7356 "3282 Invalid provisioning of "
7361 base = phba->sli4_hba.max_cfg_param.vfi_base;
7362 longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
7363 phba->sli4_hba.vfi_bmask = kcalloc(longs,
7364 sizeof(unsigned long),
7366 if (unlikely(!phba->sli4_hba.vfi_bmask)) {
7370 phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
7372 if (unlikely(!phba->sli4_hba.vfi_ids)) {
7374 goto free_vfi_bmask;
7377 for (i = 0; i < count; i++)
7378 phba->sli4_hba.vfi_ids[i] = base + i;
7381 * Mark all resources ready. An HBA reset doesn't need
7382 * to reset the initialization.
7384 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
7390 kfree(phba->sli4_hba.vfi_bmask);
7391 phba->sli4_hba.vfi_bmask = NULL;
7393 kfree(phba->sli4_hba.xri_ids);
7394 phba->sli4_hba.xri_ids = NULL;
7396 kfree(phba->sli4_hba.xri_bmask);
7397 phba->sli4_hba.xri_bmask = NULL;
7399 kfree(phba->vpi_ids);
7400 phba->vpi_ids = NULL;
7402 kfree(phba->vpi_bmask);
7403 phba->vpi_bmask = NULL;
7405 kfree(phba->sli4_hba.rpi_ids);
7406 phba->sli4_hba.rpi_ids = NULL;
7408 kfree(phba->sli4_hba.rpi_bmask);
7409 phba->sli4_hba.rpi_bmask = NULL;
7415 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
7416 * @phba: Pointer to HBA context object.
7418 * This function allocates the number of elements for the specified
7422 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
7424 if (phba->sli4_hba.extents_in_use) {
7425 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
7426 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
7427 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
7428 lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
7430 kfree(phba->vpi_bmask);
7431 phba->sli4_hba.max_cfg_param.vpi_used = 0;
7432 kfree(phba->vpi_ids);
7433 bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7434 kfree(phba->sli4_hba.xri_bmask);
7435 kfree(phba->sli4_hba.xri_ids);
7436 kfree(phba->sli4_hba.vfi_bmask);
7437 kfree(phba->sli4_hba.vfi_ids);
7438 bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7439 bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
7446 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
7447 * @phba: Pointer to HBA context object.
7448 * @type: The resource extent type.
7449 * @extnt_cnt: buffer to hold port extent count response
7450 * @extnt_size: buffer to hold port extent size response.
7452 * This function calls the port to read the host allocated extents
7453 * for a particular type.
7456 lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
7457 uint16_t *extnt_cnt, uint16_t *extnt_size)
7461 uint16_t curr_blks = 0;
7462 uint32_t req_len, emb_len;
7463 uint32_t alloc_len, mbox_tmo;
7464 struct list_head *blk_list_head;
7465 struct lpfc_rsrc_blks *rsrc_blk;
7467 void *virtaddr = NULL;
7468 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
7469 struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
7470 union lpfc_sli4_cfg_shdr *shdr;
7473 case LPFC_RSC_TYPE_FCOE_VPI:
7474 blk_list_head = &phba->lpfc_vpi_blk_list;
7476 case LPFC_RSC_TYPE_FCOE_XRI:
7477 blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
7479 case LPFC_RSC_TYPE_FCOE_VFI:
7480 blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
7482 case LPFC_RSC_TYPE_FCOE_RPI:
7483 blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
7489 /* Count the number of extents currently allocatd for this type. */
7490 list_for_each_entry(rsrc_blk, blk_list_head, list) {
7491 if (curr_blks == 0) {
7493 * The GET_ALLOCATED mailbox does not return the size,
7494 * just the count. The size should be just the size
7495 * stored in the current allocated block and all sizes
7496 * for an extent type are the same so set the return
7499 *extnt_size = rsrc_blk->rsrc_size;
7505 * Calculate the size of an embedded mailbox. The uint32_t
7506 * accounts for extents-specific word.
7508 emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
7512 * Presume the allocation and response will fit into an embedded
7513 * mailbox. If not true, reconfigure to a non-embedded mailbox.
7515 emb = LPFC_SLI4_MBX_EMBED;
7517 if (req_len > emb_len) {
7518 req_len = curr_blks * sizeof(uint16_t) +
7519 sizeof(union lpfc_sli4_cfg_shdr) +
7521 emb = LPFC_SLI4_MBX_NEMBED;
7524 mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7527 memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
7529 alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7530 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
7532 if (alloc_len < req_len) {
7533 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7534 "2983 Allocated DMA memory size (x%x) is "
7535 "less than the requested DMA memory "
7536 "size (x%x)\n", alloc_len, req_len);
7540 rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
7546 if (!phba->sli4_hba.intr_enable)
7547 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
7549 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
7550 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
7559 * Figure out where the response is located. Then get local pointers
7560 * to the response data. The port does not guarantee to respond to
7561 * all extents counts request so update the local variable with the
7562 * allocated count from the port.
7564 if (emb == LPFC_SLI4_MBX_EMBED) {
7565 rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
7566 shdr = &rsrc_ext->header.cfg_shdr;
7567 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
7569 virtaddr = mbox->sge_array->addr[0];
7570 n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
7571 shdr = &n_rsrc->cfg_shdr;
7572 *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
7575 if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
7576 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7577 "2984 Failed to read allocated resources "
7578 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
7580 bf_get(lpfc_mbox_hdr_status, &shdr->response),
7581 bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
7586 lpfc_sli4_mbox_cmd_free(phba, mbox);
7591 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
7592 * @phba: pointer to lpfc hba data structure.
7593 * @sgl_list: linked link of sgl buffers to post
7594 * @cnt: number of linked list buffers
7596 * This routine walks the list of buffers that have been allocated and
7597 * repost them to the port by using SGL block post. This is needed after a
7598 * pci_function_reset/warm_start or start. It attempts to construct blocks
7599 * of buffer sgls which contains contiguous xris and uses the non-embedded
7600 * SGL block post mailbox commands to post them to the port. For single
7601 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
7602 * mailbox command for posting.
7604 * Returns: 0 = success, non-zero failure.
7607 lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
7608 struct list_head *sgl_list, int cnt)
7610 struct lpfc_sglq *sglq_entry = NULL;
7611 struct lpfc_sglq *sglq_entry_next = NULL;
7612 struct lpfc_sglq *sglq_entry_first = NULL;
7613 int status, total_cnt;
7614 int post_cnt = 0, num_posted = 0, block_cnt = 0;
7615 int last_xritag = NO_XRI;
7616 LIST_HEAD(prep_sgl_list);
7617 LIST_HEAD(blck_sgl_list);
7618 LIST_HEAD(allc_sgl_list);
7619 LIST_HEAD(post_sgl_list);
7620 LIST_HEAD(free_sgl_list);
7622 spin_lock_irq(&phba->hbalock);
7623 spin_lock(&phba->sli4_hba.sgl_list_lock);
7624 list_splice_init(sgl_list, &allc_sgl_list);
7625 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7626 spin_unlock_irq(&phba->hbalock);
7629 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
7630 &allc_sgl_list, list) {
7631 list_del_init(&sglq_entry->list);
7633 if ((last_xritag != NO_XRI) &&
7634 (sglq_entry->sli4_xritag != last_xritag + 1)) {
7635 /* a hole in xri block, form a sgl posting block */
7636 list_splice_init(&prep_sgl_list, &blck_sgl_list);
7637 post_cnt = block_cnt - 1;
7638 /* prepare list for next posting block */
7639 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7642 /* prepare list for next posting block */
7643 list_add_tail(&sglq_entry->list, &prep_sgl_list);
7644 /* enough sgls for non-embed sgl mbox command */
7645 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
7646 list_splice_init(&prep_sgl_list,
7648 post_cnt = block_cnt;
7654 /* keep track of last sgl's xritag */
7655 last_xritag = sglq_entry->sli4_xritag;
7657 /* end of repost sgl list condition for buffers */
7658 if (num_posted == total_cnt) {
7659 if (post_cnt == 0) {
7660 list_splice_init(&prep_sgl_list,
7662 post_cnt = block_cnt;
7663 } else if (block_cnt == 1) {
7664 status = lpfc_sli4_post_sgl(phba,
7665 sglq_entry->phys, 0,
7666 sglq_entry->sli4_xritag);
7668 /* successful, put sgl to posted list */
7669 list_add_tail(&sglq_entry->list,
7672 /* Failure, put sgl to free list */
7673 lpfc_printf_log(phba, KERN_WARNING,
7675 "3159 Failed to post "
7676 "sgl, xritag:x%x\n",
7677 sglq_entry->sli4_xritag);
7678 list_add_tail(&sglq_entry->list,
7685 /* continue until a nembed page worth of sgls */
7689 /* post the buffer list sgls as a block */
7690 status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
7694 /* success, put sgl list to posted sgl list */
7695 list_splice_init(&blck_sgl_list, &post_sgl_list);
7697 /* Failure, put sgl list to free sgl list */
7698 sglq_entry_first = list_first_entry(&blck_sgl_list,
7701 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7702 "3160 Failed to post sgl-list, "
7704 sglq_entry_first->sli4_xritag,
7705 (sglq_entry_first->sli4_xritag +
7707 list_splice_init(&blck_sgl_list, &free_sgl_list);
7708 total_cnt -= post_cnt;
7711 /* don't reset xirtag due to hole in xri block */
7713 last_xritag = NO_XRI;
7715 /* reset sgl post count for next round of posting */
7719 /* free the sgls failed to post */
7720 lpfc_free_sgl_list(phba, &free_sgl_list);
7722 /* push sgls posted to the available list */
7723 if (!list_empty(&post_sgl_list)) {
7724 spin_lock_irq(&phba->hbalock);
7725 spin_lock(&phba->sli4_hba.sgl_list_lock);
7726 list_splice_init(&post_sgl_list, sgl_list);
7727 spin_unlock(&phba->sli4_hba.sgl_list_lock);
7728 spin_unlock_irq(&phba->hbalock);
7730 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7731 "3161 Failure to post sgl to port.\n");
7735 /* return the number of XRIs actually posted */
7740 * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
7741 * @phba: pointer to lpfc hba data structure.
7743 * This routine walks the list of nvme buffers that have been allocated and
7744 * repost them to the port by using SGL block post. This is needed after a
7745 * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
7746 * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
7747 * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
7749 * Returns: 0 = success, non-zero failure.
7752 lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
7754 LIST_HEAD(post_nblist);
7755 int num_posted, rc = 0;
7757 /* get all NVME buffers need to repost to a local list */
7758 lpfc_io_buf_flush(phba, &post_nblist);
7760 /* post the list of nvme buffer sgls to port if available */
7761 if (!list_empty(&post_nblist)) {
7762 num_posted = lpfc_sli4_post_io_sgl_list(
7763 phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
7764 /* failed to post any nvme buffer, return error */
7765 if (num_posted == 0)
7772 lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
7776 len = sizeof(struct lpfc_mbx_set_host_data) -
7777 sizeof(struct lpfc_sli4_cfg_mhdr);
7778 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
7779 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
7780 LPFC_SLI4_MBX_EMBED);
7782 mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
7783 mbox->u.mqe.un.set_host_data.param_len =
7784 LPFC_HOST_OS_DRIVER_VERSION_SIZE;
7785 snprintf(mbox->u.mqe.un.set_host_data.un.data,
7786 LPFC_HOST_OS_DRIVER_VERSION_SIZE,
7787 "Linux %s v"LPFC_DRIVER_VERSION,
7788 (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
7792 lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7793 struct lpfc_queue *drq, int count, int idx)
7796 struct lpfc_rqe hrqe;
7797 struct lpfc_rqe drqe;
7798 struct lpfc_rqb *rqbp;
7799 unsigned long flags;
7800 struct rqb_dmabuf *rqb_buffer;
7801 LIST_HEAD(rqb_buf_list);
7804 for (i = 0; i < count; i++) {
7805 spin_lock_irqsave(&phba->hbalock, flags);
7806 /* IF RQ is already full, don't bother */
7807 if (rqbp->buffer_count + i >= rqbp->entry_count - 1) {
7808 spin_unlock_irqrestore(&phba->hbalock, flags);
7811 spin_unlock_irqrestore(&phba->hbalock, flags);
7813 rqb_buffer = rqbp->rqb_alloc_buffer(phba);
7816 rqb_buffer->hrq = hrq;
7817 rqb_buffer->drq = drq;
7818 rqb_buffer->idx = idx;
7819 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7822 spin_lock_irqsave(&phba->hbalock, flags);
7823 while (!list_empty(&rqb_buf_list)) {
7824 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7827 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7828 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7829 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7830 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7831 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7833 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7834 "6421 Cannot post to HRQ %d: %x %x %x "
7842 rqbp->rqb_free_buffer(phba, rqb_buffer);
7844 list_add_tail(&rqb_buffer->hbuf.list,
7845 &rqbp->rqb_buffer_list);
7846 rqbp->buffer_count++;
7849 spin_unlock_irqrestore(&phba->hbalock, flags);
7854 lpfc_mbx_cmpl_read_lds_params(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7856 union lpfc_sli4_cfg_shdr *shdr;
7857 u32 shdr_status, shdr_add_status;
7859 shdr = (union lpfc_sli4_cfg_shdr *)
7860 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7861 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7862 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7863 if (shdr_status || shdr_add_status || pmb->u.mb.mbxStatus) {
7864 lpfc_printf_log(phba, KERN_INFO, LOG_LDS_EVENT | LOG_MBOX,
7865 "4622 SET_FEATURE (x%x) mbox failed, "
7866 "status x%x add_status x%x, mbx status x%x\n",
7867 LPFC_SET_LD_SIGNAL, shdr_status,
7868 shdr_add_status, pmb->u.mb.mbxStatus);
7869 phba->degrade_activate_threshold = 0;
7870 phba->degrade_deactivate_threshold = 0;
7871 phba->fec_degrade_interval = 0;
7875 phba->degrade_activate_threshold = pmb->u.mqe.un.set_feature.word7;
7876 phba->degrade_deactivate_threshold = pmb->u.mqe.un.set_feature.word8;
7877 phba->fec_degrade_interval = pmb->u.mqe.un.set_feature.word10;
7879 lpfc_printf_log(phba, KERN_INFO, LOG_LDS_EVENT,
7880 "4624 Success: da x%x dd x%x interval x%x\n",
7881 phba->degrade_activate_threshold,
7882 phba->degrade_deactivate_threshold,
7883 phba->fec_degrade_interval);
7885 mempool_free(pmb, phba->mbox_mem_pool);
7889 lpfc_read_lds_params(struct lpfc_hba *phba)
7891 LPFC_MBOXQ_t *mboxq;
7894 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7898 lpfc_set_features(phba, mboxq, LPFC_SET_LD_SIGNAL);
7899 mboxq->vport = phba->pport;
7900 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_lds_params;
7901 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
7902 if (rc == MBX_NOT_FINISHED) {
7903 mempool_free(mboxq, phba->mbox_mem_pool);
7910 lpfc_mbx_cmpl_cgn_set_ftrs(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7912 struct lpfc_vport *vport = pmb->vport;
7913 union lpfc_sli4_cfg_shdr *shdr;
7914 u32 shdr_status, shdr_add_status;
7917 /* Two outcomes. (1) Set featurs was successul and EDC negotiation
7918 * is done. (2) Mailbox failed and send FPIN support only.
7920 shdr = (union lpfc_sli4_cfg_shdr *)
7921 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7922 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7923 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
7924 if (shdr_status || shdr_add_status || pmb->u.mb.mbxStatus) {
7925 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
7926 "2516 CGN SET_FEATURE mbox failed with "
7927 "status x%x add_status x%x, mbx status x%x "
7928 "Reset Congestion to FPINs only\n",
7929 shdr_status, shdr_add_status,
7930 pmb->u.mb.mbxStatus);
7931 /* If there is a mbox error, move on to RDF */
7932 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
7933 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
7937 /* Zero out Congestion Signal ACQE counter */
7938 phba->cgn_acqe_cnt = 0;
7940 acqe = bf_get(lpfc_mbx_set_feature_CGN_acqe_freq,
7941 &pmb->u.mqe.un.set_feature);
7942 sig = bf_get(lpfc_mbx_set_feature_CGN_warn_freq,
7943 &pmb->u.mqe.un.set_feature);
7944 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7945 "4620 SET_FEATURES Success: Freq: %ds %dms "
7946 " Reg: x%x x%x\n", acqe, sig,
7947 phba->cgn_reg_signal, phba->cgn_reg_fpin);
7949 mempool_free(pmb, phba->mbox_mem_pool);
7951 /* Register for FPIN events from the fabric now that the
7952 * EDC common_set_features has completed.
7954 lpfc_issue_els_rdf(vport, 0);
7958 lpfc_config_cgn_signal(struct lpfc_hba *phba)
7960 LPFC_MBOXQ_t *mboxq;
7963 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7967 lpfc_set_features(phba, mboxq, LPFC_SET_CGN_SIGNAL);
7968 mboxq->vport = phba->pport;
7969 mboxq->mbox_cmpl = lpfc_mbx_cmpl_cgn_set_ftrs;
7971 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
7972 "4621 SET_FEATURES: FREQ sig x%x acqe x%x: "
7974 phba->cgn_sig_freq, lpfc_acqe_cgn_frequency,
7975 phba->cgn_reg_signal, phba->cgn_reg_fpin);
7977 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
7978 if (rc == MBX_NOT_FINISHED)
7983 mempool_free(mboxq, phba->mbox_mem_pool);
7985 /* If there is a mbox error, move on to RDF */
7986 phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
7987 phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
7988 lpfc_issue_els_rdf(phba->pport, 0);
7993 * lpfc_init_idle_stat_hb - Initialize idle_stat tracking
7994 * @phba: pointer to lpfc hba data structure.
7996 * This routine initializes the per-cq idle_stat to dynamically dictate
7997 * polling decisions.
8002 static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba)
8005 struct lpfc_sli4_hdw_queue *hdwq;
8006 struct lpfc_queue *cq;
8007 struct lpfc_idle_stat *idle_stat;
8010 for_each_present_cpu(i) {
8011 hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
8014 /* Skip if we've already handled this cq's primary CPU */
8018 idle_stat = &phba->sli4_hba.idle_stat[i];
8020 idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1);
8021 idle_stat->prev_wall = wall;
8023 if (phba->nvmet_support ||
8024 phba->cmf_active_mode != LPFC_CFG_OFF)
8025 cq->poll_mode = LPFC_QUEUE_WORK;
8027 cq->poll_mode = LPFC_IRQ_POLL;
8030 if (!phba->nvmet_support)
8031 schedule_delayed_work(&phba->idle_stat_delay_work,
8032 msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
8035 static void lpfc_sli4_dip(struct lpfc_hba *phba)
8039 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8040 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 ||
8041 if_type == LPFC_SLI_INTF_IF_TYPE_6) {
8042 struct lpfc_register reg_data;
8044 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
8048 if (bf_get(lpfc_sliport_status_dip, ®_data))
8049 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8050 "2904 Firmware Dump Image Present"
8056 * lpfc_rx_monitor_create_ring - Initialize ring buffer for rx_monitor
8057 * @rx_monitor: Pointer to lpfc_rx_info_monitor object
8058 * @entries: Number of rx_info_entry objects to allocate in ring
8062 * ENOMEM - Failure to kmalloc
8064 int lpfc_rx_monitor_create_ring(struct lpfc_rx_info_monitor *rx_monitor,
8067 rx_monitor->ring = kmalloc_array(entries, sizeof(struct rx_info_entry),
8069 if (!rx_monitor->ring)
8072 rx_monitor->head_idx = 0;
8073 rx_monitor->tail_idx = 0;
8074 spin_lock_init(&rx_monitor->lock);
8075 rx_monitor->entries = entries;
8081 * lpfc_rx_monitor_destroy_ring - Free ring buffer for rx_monitor
8082 * @rx_monitor: Pointer to lpfc_rx_info_monitor object
8084 void lpfc_rx_monitor_destroy_ring(struct lpfc_rx_info_monitor *rx_monitor)
8086 spin_lock(&rx_monitor->lock);
8087 kfree(rx_monitor->ring);
8088 rx_monitor->ring = NULL;
8089 rx_monitor->entries = 0;
8090 rx_monitor->head_idx = 0;
8091 rx_monitor->tail_idx = 0;
8092 spin_unlock(&rx_monitor->lock);
8096 * lpfc_rx_monitor_record - Insert an entry into rx_monitor's ring
8097 * @rx_monitor: Pointer to lpfc_rx_info_monitor object
8098 * @entry: Pointer to rx_info_entry
8100 * Used to insert an rx_info_entry into rx_monitor's ring. Note that this is a
8101 * deep copy of rx_info_entry not a shallow copy of the rx_info_entry ptr.
8103 * This is called from lpfc_cmf_timer, which is in timer/softirq context.
8105 * In cases of old data overflow, we do a best effort of FIFO order.
8107 void lpfc_rx_monitor_record(struct lpfc_rx_info_monitor *rx_monitor,
8108 struct rx_info_entry *entry)
8110 struct rx_info_entry *ring = rx_monitor->ring;
8111 u32 *head_idx = &rx_monitor->head_idx;
8112 u32 *tail_idx = &rx_monitor->tail_idx;
8113 spinlock_t *ring_lock = &rx_monitor->lock;
8114 u32 ring_size = rx_monitor->entries;
8116 spin_lock(ring_lock);
8117 memcpy(&ring[*tail_idx], entry, sizeof(*entry));
8118 *tail_idx = (*tail_idx + 1) % ring_size;
8120 /* Best effort of FIFO saved data */
8121 if (*tail_idx == *head_idx)
8122 *head_idx = (*head_idx + 1) % ring_size;
8124 spin_unlock(ring_lock);
8128 * lpfc_rx_monitor_report - Read out rx_monitor's ring
8129 * @phba: Pointer to lpfc_hba object
8130 * @rx_monitor: Pointer to lpfc_rx_info_monitor object
8131 * @buf: Pointer to char buffer that will contain rx monitor info data
8132 * @buf_len: Length buf including null char
8133 * @max_read_entries: Maximum number of entries to read out of ring
8135 * Used to dump/read what's in rx_monitor's ring buffer.
8137 * If buf is NULL || buf_len == 0, then it is implied that we want to log the
8138 * information to kmsg instead of filling out buf.
8141 * Number of entries read out of the ring
8143 u32 lpfc_rx_monitor_report(struct lpfc_hba *phba,
8144 struct lpfc_rx_info_monitor *rx_monitor, char *buf,
8145 u32 buf_len, u32 max_read_entries)
8147 struct rx_info_entry *ring = rx_monitor->ring;
8148 struct rx_info_entry *entry;
8149 u32 *head_idx = &rx_monitor->head_idx;
8150 u32 *tail_idx = &rx_monitor->tail_idx;
8151 spinlock_t *ring_lock = &rx_monitor->lock;
8152 u32 ring_size = rx_monitor->entries;
8154 char tmp[DBG_LOG_STR_SZ] = {0};
8155 bool log_to_kmsg = (!buf || !buf_len) ? true : false;
8158 /* clear the buffer to be sure */
8159 memset(buf, 0, buf_len);
8161 scnprintf(buf, buf_len, "\t%-16s%-16s%-16s%-16s%-8s%-8s%-8s"
8162 "%-8s%-8s%-8s%-16s\n",
8163 "MaxBPI", "Tot_Data_CMF",
8164 "Tot_Data_Cmd", "Tot_Data_Cmpl",
8165 "Lat(us)", "Avg_IO", "Max_IO", "Bsy",
8166 "IO_cnt", "Info", "BWutil(ms)");
8169 /* Needs to be _irq because record is called from timer interrupt
8172 spin_lock_irq(ring_lock);
8173 while (*head_idx != *tail_idx) {
8174 entry = &ring[*head_idx];
8176 /* Read out this entry's data. */
8178 /* If !log_to_kmsg, then store to buf. */
8179 scnprintf(tmp, sizeof(tmp),
8180 "%03d:\t%-16llu%-16llu%-16llu%-16llu%-8llu"
8181 "%-8llu%-8llu%-8u%-8u%-8u%u(%u)\n",
8182 *head_idx, entry->max_bytes_per_interval,
8183 entry->cmf_bytes, entry->total_bytes,
8184 entry->rcv_bytes, entry->avg_io_latency,
8185 entry->avg_io_size, entry->max_read_cnt,
8186 entry->cmf_busy, entry->io_cnt,
8187 entry->cmf_info, entry->timer_utilization,
8188 entry->timer_interval);
8190 /* Check for buffer overflow */
8191 if ((strlen(buf) + strlen(tmp)) >= buf_len)
8194 /* Append entry's data to buffer */
8195 strlcat(buf, tmp, buf_len);
8197 lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
8198 "4410 %02u: MBPI %llu Xmit %llu "
8199 "Cmpl %llu Lat %llu ASz %llu Info %02u "
8200 "BWUtil %u Int %u slot %u\n",
8201 cnt, entry->max_bytes_per_interval,
8202 entry->total_bytes, entry->rcv_bytes,
8203 entry->avg_io_latency,
8204 entry->avg_io_size, entry->cmf_info,
8205 entry->timer_utilization,
8206 entry->timer_interval, *head_idx);
8209 *head_idx = (*head_idx + 1) % ring_size;
8211 /* Don't feed more than max_read_entries */
8213 if (cnt >= max_read_entries)
8216 spin_unlock_irq(ring_lock);
8222 * lpfc_cmf_setup - Initialize idle_stat tracking
8223 * @phba: Pointer to HBA context object.
8225 * This is called from HBA setup during driver load or when the HBA
8226 * comes online. this does all the initialization to support CMF and MI.
8229 lpfc_cmf_setup(struct lpfc_hba *phba)
8231 LPFC_MBOXQ_t *mboxq;
8232 struct lpfc_dmabuf *mp;
8233 struct lpfc_pc_sli4_params *sli4_params;
8234 int rc, cmf, mi_ver;
8236 rc = lpfc_sli4_refresh_params(phba);
8240 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8244 sli4_params = &phba->sli4_hba.pc_sli4_params;
8246 /* Always try to enable MI feature if we can */
8247 if (sli4_params->mi_ver) {
8248 lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_MI);
8249 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8250 mi_ver = bf_get(lpfc_mbx_set_feature_mi,
8251 &mboxq->u.mqe.un.set_feature);
8253 if (rc == MBX_SUCCESS) {
8255 lpfc_printf_log(phba,
8256 KERN_WARNING, LOG_CGN_MGMT,
8257 "6215 MI is enabled\n");
8258 sli4_params->mi_ver = mi_ver;
8260 lpfc_printf_log(phba,
8261 KERN_WARNING, LOG_CGN_MGMT,
8262 "6338 MI is disabled\n");
8263 sli4_params->mi_ver = 0;
8266 /* mi_ver is already set from GET_SLI4_PARAMETERS */
8267 lpfc_printf_log(phba, KERN_INFO,
8268 LOG_CGN_MGMT | LOG_INIT,
8269 "6245 Enable MI Mailbox x%x (x%x/x%x) "
8270 "failed, rc:x%x mi:x%x\n",
8271 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8272 lpfc_sli_config_mbox_subsys_get
8274 lpfc_sli_config_mbox_opcode_get
8276 rc, sli4_params->mi_ver);
8279 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
8280 "6217 MI is disabled\n");
8283 /* Ensure FDMI is enabled for MI if enable_mi is set */
8284 if (sli4_params->mi_ver)
8285 phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT;
8287 /* Always try to enable CMF feature if we can */
8288 if (sli4_params->cmf) {
8289 lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_CMF);
8290 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8291 cmf = bf_get(lpfc_mbx_set_feature_cmf,
8292 &mboxq->u.mqe.un.set_feature);
8293 if (rc == MBX_SUCCESS && cmf) {
8294 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
8295 "6218 CMF is enabled: mode %d\n",
8296 phba->cmf_active_mode);
8298 lpfc_printf_log(phba, KERN_WARNING,
8299 LOG_CGN_MGMT | LOG_INIT,
8300 "6219 Enable CMF Mailbox x%x (x%x/x%x) "
8301 "failed, rc:x%x dd:x%x\n",
8302 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8303 lpfc_sli_config_mbox_subsys_get
8305 lpfc_sli_config_mbox_opcode_get
8308 sli4_params->cmf = 0;
8309 phba->cmf_active_mode = LPFC_CFG_OFF;
8313 /* Allocate Congestion Information Buffer */
8315 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
8317 mp->virt = dma_alloc_coherent
8318 (&phba->pcidev->dev,
8319 sizeof(struct lpfc_cgn_info),
8320 &mp->phys, GFP_KERNEL);
8321 if (!mp || !mp->virt) {
8322 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8323 "2640 Failed to alloc memory "
8324 "for Congestion Info\n");
8326 sli4_params->cmf = 0;
8327 phba->cmf_active_mode = LPFC_CFG_OFF;
8332 /* initialize congestion buffer info */
8333 lpfc_init_congestion_buf(phba);
8334 lpfc_init_congestion_stat(phba);
8336 /* Zero out Congestion Signal counters */
8337 atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
8338 atomic64_set(&phba->cgn_acqe_stat.warn, 0);
8341 rc = lpfc_sli4_cgn_params_read(phba);
8343 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
8344 "6242 Error reading Cgn Params (%d)\n",
8346 /* Ensure CGN Mode is off */
8347 sli4_params->cmf = 0;
8349 lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
8350 "6243 CGN Event empty object.\n");
8351 /* Ensure CGN Mode is off */
8352 sli4_params->cmf = 0;
8356 lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
8357 "6220 CMF is disabled\n");
8360 /* Only register congestion buffer with firmware if BOTH
8361 * CMF and E2E are enabled.
8363 if (sli4_params->cmf && sli4_params->mi_ver) {
8364 rc = lpfc_reg_congestion_buf(phba);
8366 dma_free_coherent(&phba->pcidev->dev,
8367 sizeof(struct lpfc_cgn_info),
8368 phba->cgn_i->virt, phba->cgn_i->phys);
8371 /* Ensure CGN Mode is off */
8372 phba->cmf_active_mode = LPFC_CFG_OFF;
8373 sli4_params->cmf = 0;
8377 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8378 "6470 Setup MI version %d CMF %d mode %d\n",
8379 sli4_params->mi_ver, sli4_params->cmf,
8380 phba->cmf_active_mode);
8382 mempool_free(mboxq, phba->mbox_mem_pool);
8384 /* Initialize atomic counters */
8385 atomic_set(&phba->cgn_fabric_warn_cnt, 0);
8386 atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
8387 atomic_set(&phba->cgn_sync_alarm_cnt, 0);
8388 atomic_set(&phba->cgn_sync_warn_cnt, 0);
8389 atomic_set(&phba->cgn_driver_evt_cnt, 0);
8390 atomic_set(&phba->cgn_latency_evt_cnt, 0);
8391 atomic64_set(&phba->cgn_latency_evt, 0);
8393 phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
8395 /* Allocate RX Monitor Buffer */
8396 if (!phba->rx_monitor) {
8397 phba->rx_monitor = kzalloc(sizeof(*phba->rx_monitor),
8400 if (!phba->rx_monitor) {
8401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8402 "2644 Failed to alloc memory "
8403 "for RX Monitor Buffer\n");
8407 /* Instruct the rx_monitor object to instantiate its ring */
8408 if (lpfc_rx_monitor_create_ring(phba->rx_monitor,
8409 LPFC_MAX_RXMONITOR_ENTRY)) {
8410 kfree(phba->rx_monitor);
8411 phba->rx_monitor = NULL;
8412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8413 "2645 Failed to alloc memory "
8414 "for RX Monitor's Ring\n");
8423 lpfc_set_host_tm(struct lpfc_hba *phba)
8425 LPFC_MBOXQ_t *mboxq;
8427 struct timespec64 cur_time;
8429 uint32_t month, day, year;
8430 uint32_t hour, minute, second;
8431 struct lpfc_mbx_set_host_date_time *tm;
8433 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8437 len = sizeof(struct lpfc_mbx_set_host_data) -
8438 sizeof(struct lpfc_sli4_cfg_mhdr);
8439 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8440 LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
8441 LPFC_SLI4_MBX_EMBED);
8443 mboxq->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_DATE_TIME;
8444 mboxq->u.mqe.un.set_host_data.param_len =
8445 sizeof(struct lpfc_mbx_set_host_date_time);
8446 tm = &mboxq->u.mqe.un.set_host_data.un.tm;
8447 ktime_get_real_ts64(&cur_time);
8448 time64_to_tm(cur_time.tv_sec, 0, &broken);
8449 month = broken.tm_mon + 1;
8450 day = broken.tm_mday;
8451 year = broken.tm_year - 100;
8452 hour = broken.tm_hour;
8453 minute = broken.tm_min;
8454 second = broken.tm_sec;
8455 bf_set(lpfc_mbx_set_host_month, tm, month);
8456 bf_set(lpfc_mbx_set_host_day, tm, day);
8457 bf_set(lpfc_mbx_set_host_year, tm, year);
8458 bf_set(lpfc_mbx_set_host_hour, tm, hour);
8459 bf_set(lpfc_mbx_set_host_min, tm, minute);
8460 bf_set(lpfc_mbx_set_host_sec, tm, second);
8462 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8463 mempool_free(mboxq, phba->mbox_mem_pool);
8468 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
8469 * @phba: Pointer to HBA context object.
8471 * This function is the main SLI4 device initialization PCI function. This
8472 * function is called by the HBA initialization code, HBA reset code and
8473 * HBA error attention handler code. Caller is not required to hold any
8477 lpfc_sli4_hba_setup(struct lpfc_hba *phba)
8479 int rc, i, cnt, len, dd;
8480 LPFC_MBOXQ_t *mboxq;
8481 struct lpfc_mqe *mqe;
8484 uint32_t ftr_rsp = 0;
8485 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
8486 struct lpfc_vport *vport = phba->pport;
8487 struct lpfc_dmabuf *mp;
8488 struct lpfc_rqb *rqbp;
8491 /* Perform a PCI function reset to start from clean */
8492 rc = lpfc_pci_function_reset(phba);
8496 /* Check the HBA Host Status Register for readyness */
8497 rc = lpfc_sli4_post_status_check(phba);
8501 spin_lock_irq(&phba->hbalock);
8502 phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
8503 flg = phba->sli.sli_flag;
8504 spin_unlock_irq(&phba->hbalock);
8505 /* Allow a little time after setting SLI_ACTIVE for any polled
8506 * MBX commands to complete via BSG.
8508 for (i = 0; i < 50 && (flg & LPFC_SLI_MBOX_ACTIVE); i++) {
8510 spin_lock_irq(&phba->hbalock);
8511 flg = phba->sli.sli_flag;
8512 spin_unlock_irq(&phba->hbalock);
8516 lpfc_sli4_dip(phba);
8519 * Allocate a single mailbox container for initializing the
8522 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8526 /* Issue READ_REV to collect vpd and FW information. */
8527 vpd_size = SLI4_PAGE_SIZE;
8528 vpd = kzalloc(vpd_size, GFP_KERNEL);
8534 rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
8540 mqe = &mboxq->u.mqe;
8541 phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
8542 if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
8543 phba->hba_flag |= HBA_FCOE_MODE;
8544 phba->fcp_embed_io = 0; /* SLI4 FC support only */
8546 phba->hba_flag &= ~HBA_FCOE_MODE;
8549 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
8551 phba->hba_flag |= HBA_FIP_SUPPORT;
8553 phba->hba_flag &= ~HBA_FIP_SUPPORT;
8555 phba->hba_flag &= ~HBA_IOQ_FLUSH;
8557 if (phba->sli_rev != LPFC_SLI_REV4) {
8558 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8559 "0376 READ_REV Error. SLI Level %d "
8560 "FCoE enabled %d\n",
8561 phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
8567 rc = lpfc_set_host_tm(phba);
8568 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
8569 "6468 Set host date / time: Status x%x:\n", rc);
8572 * Continue initialization with default values even if driver failed
8573 * to read FCoE param config regions, only read parameters if the
8576 if (phba->hba_flag & HBA_FCOE_MODE &&
8577 lpfc_sli4_read_fcoe_params(phba))
8578 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
8579 "2570 Failed to read FCoE parameters\n");
8582 * Retrieve sli4 device physical port name, failure of doing it
8583 * is considered as non-fatal.
8585 rc = lpfc_sli4_retrieve_pport_name(phba);
8587 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8588 "3080 Successful retrieving SLI4 device "
8589 "physical port name: %s.\n", phba->Port);
8591 rc = lpfc_sli4_get_ctl_attr(phba);
8593 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8594 "8351 Successful retrieving SLI4 device "
8598 * Evaluate the read rev and vpd data. Populate the driver
8599 * state with the results. If this routine fails, the failure
8600 * is not fatal as the driver will use generic values.
8602 rc = lpfc_parse_vpd(phba, vpd, vpd_size);
8603 if (unlikely(!rc)) {
8604 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8605 "0377 Error %d parsing vpd. "
8606 "Using defaults.\n", rc);
8611 /* Save information as VPD data */
8612 phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
8613 phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
8616 * This is because first G7 ASIC doesn't support the standard
8617 * 0x5a NVME cmd descriptor type/subtype
8619 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8620 LPFC_SLI_INTF_IF_TYPE_6) &&
8621 (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
8622 (phba->vpd.rev.smRev == 0) &&
8623 (phba->cfg_nvme_embed_cmd == 1))
8624 phba->cfg_nvme_embed_cmd = 0;
8626 phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
8627 phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
8629 phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
8631 phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
8633 phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
8635 phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
8636 memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
8637 phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
8638 memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
8639 phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
8640 memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
8641 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
8642 "(%d):0380 READ_REV Status x%x "
8643 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
8644 mboxq->vport ? mboxq->vport->vpi : 0,
8645 bf_get(lpfc_mqe_status, mqe),
8646 phba->vpd.rev.opFwName,
8647 phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
8648 phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
8650 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
8651 LPFC_SLI_INTF_IF_TYPE_0) {
8652 lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
8653 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8654 if (rc == MBX_SUCCESS) {
8655 phba->hba_flag |= HBA_RECOVERABLE_UE;
8656 /* Set 1Sec interval to detect UE */
8657 phba->eratt_poll_interval = 1;
8658 phba->sli4_hba.ue_to_sr = bf_get(
8659 lpfc_mbx_set_feature_UESR,
8660 &mboxq->u.mqe.un.set_feature);
8661 phba->sli4_hba.ue_to_rp = bf_get(
8662 lpfc_mbx_set_feature_UERP,
8663 &mboxq->u.mqe.un.set_feature);
8667 if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
8668 /* Enable MDS Diagnostics only if the SLI Port supports it */
8669 lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
8670 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8671 if (rc != MBX_SUCCESS)
8672 phba->mds_diags_support = 0;
8676 * Discover the port's supported feature set and match it against the
8679 lpfc_request_features(phba, mboxq);
8680 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8686 /* Disable VMID if app header is not supported */
8687 if (phba->cfg_vmid_app_header && !(bf_get(lpfc_mbx_rq_ftr_rsp_ashdr,
8688 &mqe->un.req_ftrs))) {
8689 bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 0);
8690 phba->cfg_vmid_app_header = 0;
8691 lpfc_printf_log(phba, KERN_DEBUG, LOG_SLI,
8692 "1242 vmid feature not supported\n");
8696 * The port must support FCP initiator mode as this is the
8697 * only mode running in the host.
8699 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
8700 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8701 "0378 No support for fcpi mode.\n");
8705 /* Performance Hints are ONLY for FCoE */
8706 if (phba->hba_flag & HBA_FCOE_MODE) {
8707 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
8708 phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
8710 phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
8714 * If the port cannot support the host's requested features
8715 * then turn off the global config parameters to disable the
8716 * feature in the driver. This is not a fatal error.
8718 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
8719 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
8720 phba->cfg_enable_bg = 0;
8721 phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
8726 if (phba->max_vpi && phba->cfg_enable_npiv &&
8727 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
8731 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8732 "0379 Feature Mismatch Data: x%08x %08x "
8733 "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
8734 mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
8735 phba->cfg_enable_npiv, phba->max_vpi);
8736 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
8737 phba->cfg_enable_bg = 0;
8738 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
8739 phba->cfg_enable_npiv = 0;
8742 /* These SLI3 features are assumed in SLI4 */
8743 spin_lock_irq(&phba->hbalock);
8744 phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
8745 spin_unlock_irq(&phba->hbalock);
8747 /* Always try to enable dual dump feature if we can */
8748 lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP);
8749 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8750 dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature);
8751 if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP))
8752 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8753 "6448 Dual Dump is enabled\n");
8755 lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT,
8756 "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, "
8758 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
8759 lpfc_sli_config_mbox_subsys_get(
8761 lpfc_sli_config_mbox_opcode_get(
8765 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
8766 * calls depends on these resources to complete port setup.
8768 rc = lpfc_sli4_alloc_resource_identifiers(phba);
8770 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8771 "2920 Failed to alloc Resource IDs "
8776 lpfc_set_host_data(phba, mboxq);
8778 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8780 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
8781 "2134 Failed to set host os driver version %x",
8785 /* Read the port's service parameters. */
8786 rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
8788 phba->link_state = LPFC_HBA_ERROR;
8793 mboxq->vport = vport;
8794 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8795 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
8796 if (rc == MBX_SUCCESS) {
8797 memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
8802 * This memory was allocated by the lpfc_read_sparam routine but is
8803 * no longer needed. It is released and ctx_buf NULLed to prevent
8804 * unintended pointer access as the mbox is reused.
8806 lpfc_mbuf_free(phba, mp->virt, mp->phys);
8808 mboxq->ctx_buf = NULL;
8810 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8811 "0382 READ_SPARAM command failed "
8812 "status %d, mbxStatus x%x\n",
8813 rc, bf_get(lpfc_mqe_status, mqe));
8814 phba->link_state = LPFC_HBA_ERROR;
8819 lpfc_update_vport_wwn(vport);
8821 /* Update the fc_host data structures with new wwn. */
8822 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
8823 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
8825 /* Create all the SLI4 queues */
8826 rc = lpfc_sli4_queue_create(phba);
8828 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8829 "3089 Failed to allocate queues\n");
8833 /* Set up all the queues to the device */
8834 rc = lpfc_sli4_queue_setup(phba);
8836 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8837 "0381 Error %d during queue setup.\n ", rc);
8838 goto out_stop_timers;
8840 /* Initialize the driver internal SLI layer lists. */
8841 lpfc_sli4_setup(phba);
8842 lpfc_sli4_queue_init(phba);
8844 /* update host els xri-sgl sizes and mappings */
8845 rc = lpfc_sli4_els_sgl_update(phba);
8847 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8848 "1400 Failed to update xri-sgl size and "
8849 "mapping: %d\n", rc);
8850 goto out_destroy_queue;
8853 /* register the els sgl pool to the port */
8854 rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
8855 phba->sli4_hba.els_xri_cnt);
8856 if (unlikely(rc < 0)) {
8857 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8858 "0582 Error %d during els sgl post "
8861 goto out_destroy_queue;
8863 phba->sli4_hba.els_xri_cnt = rc;
8865 if (phba->nvmet_support) {
8866 /* update host nvmet xri-sgl sizes and mappings */
8867 rc = lpfc_sli4_nvmet_sgl_update(phba);
8869 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8870 "6308 Failed to update nvmet-sgl size "
8871 "and mapping: %d\n", rc);
8872 goto out_destroy_queue;
8875 /* register the nvmet sgl pool to the port */
8876 rc = lpfc_sli4_repost_sgl_list(
8878 &phba->sli4_hba.lpfc_nvmet_sgl_list,
8879 phba->sli4_hba.nvmet_xri_cnt);
8880 if (unlikely(rc < 0)) {
8881 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8882 "3117 Error %d during nvmet "
8885 goto out_destroy_queue;
8887 phba->sli4_hba.nvmet_xri_cnt = rc;
8889 /* We allocate an iocbq for every receive context SGL.
8890 * The additional allocation is for abort and ls handling.
8892 cnt = phba->sli4_hba.nvmet_xri_cnt +
8893 phba->sli4_hba.max_cfg_param.max_xri;
8895 /* update host common xri-sgl sizes and mappings */
8896 rc = lpfc_sli4_io_sgl_update(phba);
8898 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8899 "6082 Failed to update nvme-sgl size "
8900 "and mapping: %d\n", rc);
8901 goto out_destroy_queue;
8904 /* register the allocated common sgl pool to the port */
8905 rc = lpfc_sli4_repost_io_sgl_list(phba);
8907 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8908 "6116 Error %d during nvme sgl post "
8910 /* Some NVME buffers were moved to abort nvme list */
8911 /* A pci function reset will repost them */
8913 goto out_destroy_queue;
8915 /* Each lpfc_io_buf job structure has an iocbq element.
8916 * This cnt provides for abort, els, ct and ls requests.
8918 cnt = phba->sli4_hba.max_cfg_param.max_xri;
8921 if (!phba->sli.iocbq_lookup) {
8922 /* Initialize and populate the iocb list per host */
8923 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8924 "2821 initialize iocb list with %d entries\n",
8926 rc = lpfc_init_iocb_list(phba, cnt);
8928 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8929 "1413 Failed to init iocb list.\n");
8930 goto out_destroy_queue;
8934 if (phba->nvmet_support)
8935 lpfc_nvmet_create_targetport(phba);
8937 if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
8938 /* Post initial buffers to all RQs created */
8939 for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
8940 rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
8941 INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
8942 rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
8943 rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
8944 rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
8945 rqbp->buffer_count = 0;
8947 lpfc_post_rq_buffer(
8948 phba, phba->sli4_hba.nvmet_mrq_hdr[i],
8949 phba->sli4_hba.nvmet_mrq_data[i],
8950 phba->cfg_nvmet_mrq_post, i);
8954 /* Post the rpi header region to the device. */
8955 rc = lpfc_sli4_post_all_rpi_hdrs(phba);
8957 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
8958 "0393 Error %d during rpi post operation\n",
8961 goto out_free_iocblist;
8963 lpfc_sli4_node_prep(phba);
8965 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
8966 if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
8968 * The FC Port needs to register FCFI (index 0)
8970 lpfc_reg_fcfi(phba, mboxq);
8971 mboxq->vport = phba->pport;
8972 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8973 if (rc != MBX_SUCCESS)
8974 goto out_unset_queue;
8976 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
8977 &mboxq->u.mqe.un.reg_fcfi);
8979 /* We are a NVME Target mode with MRQ > 1 */
8981 /* First register the FCFI */
8982 lpfc_reg_fcfi_mrq(phba, mboxq, 0);
8983 mboxq->vport = phba->pport;
8984 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8985 if (rc != MBX_SUCCESS)
8986 goto out_unset_queue;
8988 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
8989 &mboxq->u.mqe.un.reg_fcfi_mrq);
8991 /* Next register the MRQs */
8992 lpfc_reg_fcfi_mrq(phba, mboxq, 1);
8993 mboxq->vport = phba->pport;
8994 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8995 if (rc != MBX_SUCCESS)
8996 goto out_unset_queue;
8999 /* Check if the port is configured to be disabled */
9000 lpfc_sli_read_link_ste(phba);
9003 /* Don't post more new bufs if repost already recovered
9006 if (phba->nvmet_support == 0) {
9007 if (phba->sli4_hba.io_xri_cnt == 0) {
9008 len = lpfc_new_io_buf(
9009 phba, phba->sli4_hba.io_xri_max);
9012 goto out_unset_queue;
9015 if (phba->cfg_xri_rebalancing)
9016 lpfc_create_multixri_pools(phba);
9019 phba->cfg_xri_rebalancing = 0;
9022 /* Allow asynchronous mailbox command to go through */
9023 spin_lock_irq(&phba->hbalock);
9024 phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
9025 spin_unlock_irq(&phba->hbalock);
9027 /* Post receive buffers to the device */
9028 lpfc_sli4_rb_setup(phba);
9030 /* Reset HBA FCF states after HBA reset */
9031 phba->fcf.fcf_flag = 0;
9032 phba->fcf.current_rec.flag = 0;
9034 /* Start the ELS watchdog timer */
9035 mod_timer(&vport->els_tmofunc,
9036 jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
9038 /* Start heart beat timer */
9039 mod_timer(&phba->hb_tmofunc,
9040 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
9041 phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
9042 phba->last_completion_time = jiffies;
9044 /* start eq_delay heartbeat */
9045 if (phba->cfg_auto_imax)
9046 queue_delayed_work(phba->wq, &phba->eq_delay_work,
9047 msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
9049 /* start per phba idle_stat_delay heartbeat */
9050 lpfc_init_idle_stat_hb(phba);
9052 /* Start error attention (ERATT) polling timer */
9053 mod_timer(&phba->eratt_poll,
9054 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
9056 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
9057 if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
9058 rc = pci_enable_pcie_error_reporting(phba->pcidev);
9060 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9061 "2829 This device supports "
9062 "Advanced Error Reporting (AER)\n");
9063 spin_lock_irq(&phba->hbalock);
9064 phba->hba_flag |= HBA_AER_ENABLED;
9065 spin_unlock_irq(&phba->hbalock);
9067 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9068 "2830 This device does not support "
9069 "Advanced Error Reporting (AER)\n");
9070 phba->cfg_aer_support = 0;
9076 * The port is ready, set the host's link state to LINK_DOWN
9077 * in preparation for link interrupts.
9079 spin_lock_irq(&phba->hbalock);
9080 phba->link_state = LPFC_LINK_DOWN;
9082 /* Check if physical ports are trunked */
9083 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
9084 phba->trunk_link.link0.state = LPFC_LINK_DOWN;
9085 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
9086 phba->trunk_link.link1.state = LPFC_LINK_DOWN;
9087 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
9088 phba->trunk_link.link2.state = LPFC_LINK_DOWN;
9089 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
9090 phba->trunk_link.link3.state = LPFC_LINK_DOWN;
9091 spin_unlock_irq(&phba->hbalock);
9093 /* Arm the CQs and then EQs on device */
9094 lpfc_sli4_arm_cqeq_intr(phba);
9096 /* Indicate device interrupt mode */
9097 phba->sli4_hba.intr_enable = 1;
9099 /* Setup CMF after HBA is initialized */
9100 lpfc_cmf_setup(phba);
9102 if (!(phba->hba_flag & HBA_FCOE_MODE) &&
9103 (phba->hba_flag & LINK_DISABLED)) {
9104 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9105 "3103 Adapter Link is disabled.\n");
9106 lpfc_down_link(phba, mboxq);
9107 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9108 if (rc != MBX_SUCCESS) {
9109 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9110 "3104 Adapter failed to issue "
9111 "DOWN_LINK mbox cmd, rc:x%x\n", rc);
9112 goto out_io_buff_free;
9114 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
9115 /* don't perform init_link on SLI4 FC port loopback test */
9116 if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
9117 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
9119 goto out_io_buff_free;
9122 mempool_free(mboxq, phba->mbox_mem_pool);
9124 /* Enable RAS FW log support */
9125 lpfc_sli4_ras_setup(phba);
9127 phba->hba_flag |= HBA_SETUP;
9131 /* Free allocated IO Buffers */
9134 /* Unset all the queues set up in this routine when error out */
9135 lpfc_sli4_queue_unset(phba);
9137 lpfc_free_iocb_list(phba);
9139 lpfc_sli4_queue_destroy(phba);
9141 lpfc_stop_hba_timers(phba);
9143 mempool_free(mboxq, phba->mbox_mem_pool);
9148 * lpfc_mbox_timeout - Timeout call back function for mbox timer
9149 * @t: Context to fetch pointer to hba structure from.
9151 * This is the callback function for mailbox timer. The mailbox
9152 * timer is armed when a new mailbox command is issued and the timer
9153 * is deleted when the mailbox complete. The function is called by
9154 * the kernel timer code when a mailbox does not complete within
9155 * expected time. This function wakes up the worker thread to
9156 * process the mailbox timeout and returns. All the processing is
9157 * done by the worker thread function lpfc_mbox_timeout_handler.
9160 lpfc_mbox_timeout(struct timer_list *t)
9162 struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo);
9163 unsigned long iflag;
9164 uint32_t tmo_posted;
9166 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
9167 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
9169 phba->pport->work_port_events |= WORKER_MBOX_TMO;
9170 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
9173 lpfc_worker_wake_up(phba);
9178 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
9180 * @phba: Pointer to HBA context object.
9182 * This function checks if any mailbox completions are present on the mailbox
9186 lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
9190 struct lpfc_queue *mcq;
9191 struct lpfc_mcqe *mcqe;
9192 bool pending_completions = false;
9195 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
9198 /* Check for completions on mailbox completion queue */
9200 mcq = phba->sli4_hba.mbx_cq;
9201 idx = mcq->hba_index;
9202 qe_valid = mcq->qe_valid;
9203 while (bf_get_le32(lpfc_cqe_valid,
9204 (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
9205 mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
9206 if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
9207 (!bf_get_le32(lpfc_trailer_async, mcqe))) {
9208 pending_completions = true;
9211 idx = (idx + 1) % mcq->entry_count;
9212 if (mcq->hba_index == idx)
9215 /* if the index wrapped around, toggle the valid bit */
9216 if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
9217 qe_valid = (qe_valid) ? 0 : 1;
9219 return pending_completions;
9224 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
9226 * @phba: Pointer to HBA context object.
9228 * For sli4, it is possible to miss an interrupt. As such mbox completions
9229 * maybe missed causing erroneous mailbox timeouts to occur. This function
9230 * checks to see if mbox completions are on the mailbox completion queue
9231 * and will process all the completions associated with the eq for the
9232 * mailbox completion queue.
9235 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
9237 struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
9239 struct lpfc_queue *fpeq = NULL;
9240 struct lpfc_queue *eq;
9243 if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
9246 /* Find the EQ associated with the mbox CQ */
9247 if (sli4_hba->hdwq) {
9248 for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
9249 eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
9250 if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
9259 /* Turn off interrupts from this EQ */
9261 sli4_hba->sli4_eq_clr_intr(fpeq);
9263 /* Check to see if a mbox completion is pending */
9265 mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
9268 * If a mbox completion is pending, process all the events on EQ
9269 * associated with the mbox completion queue (this could include
9270 * mailbox commands, async events, els commands, receive queue data
9275 /* process and rearm the EQ */
9276 lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
9278 /* Always clear and re-arm the EQ */
9279 sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
9281 return mbox_pending;
9286 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
9287 * @phba: Pointer to HBA context object.
9289 * This function is called from worker thread when a mailbox command times out.
9290 * The caller is not required to hold any locks. This function will reset the
9291 * HBA and recover all the pending commands.
9294 lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
9296 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
9297 MAILBOX_t *mb = NULL;
9299 struct lpfc_sli *psli = &phba->sli;
9301 /* If the mailbox completed, process the completion */
9302 lpfc_sli4_process_missed_mbox_completions(phba);
9304 if (!(psli->sli_flag & LPFC_SLI_ACTIVE))
9309 /* Check the pmbox pointer first. There is a race condition
9310 * between the mbox timeout handler getting executed in the
9311 * worklist and the mailbox actually completing. When this
9312 * race condition occurs, the mbox_active will be NULL.
9314 spin_lock_irq(&phba->hbalock);
9315 if (pmbox == NULL) {
9316 lpfc_printf_log(phba, KERN_WARNING,
9318 "0353 Active Mailbox cleared - mailbox timeout "
9320 spin_unlock_irq(&phba->hbalock);
9324 /* Mbox cmd <mbxCommand> timeout */
9325 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9326 "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
9328 phba->pport->port_state,
9330 phba->sli.mbox_active);
9331 spin_unlock_irq(&phba->hbalock);
9333 /* Setting state unknown so lpfc_sli_abort_iocb_ring
9334 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
9335 * it to fail all outstanding SCSI IO.
9337 spin_lock_irq(&phba->pport->work_port_lock);
9338 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
9339 spin_unlock_irq(&phba->pport->work_port_lock);
9340 spin_lock_irq(&phba->hbalock);
9341 phba->link_state = LPFC_LINK_UNKNOWN;
9342 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
9343 spin_unlock_irq(&phba->hbalock);
9345 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9346 "0345 Resetting board due to mailbox timeout\n");
9348 /* Reset the HBA device */
9349 lpfc_reset_hba(phba);
9353 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
9354 * @phba: Pointer to HBA context object.
9355 * @pmbox: Pointer to mailbox object.
9356 * @flag: Flag indicating how the mailbox need to be processed.
9358 * This function is called by discovery code and HBA management code
9359 * to submit a mailbox command to firmware with SLI-3 interface spec. This
9360 * function gets the hbalock to protect the data structures.
9361 * The mailbox command can be submitted in polling mode, in which case
9362 * this function will wait in a polling loop for the completion of the
9364 * If the mailbox is submitted in no_wait mode (not polling) the
9365 * function will submit the command and returns immediately without waiting
9366 * for the mailbox completion. The no_wait is supported only when HBA
9367 * is in SLI2/SLI3 mode - interrupts are enabled.
9368 * The SLI interface allows only one mailbox pending at a time. If the
9369 * mailbox is issued in polling mode and there is already a mailbox
9370 * pending, then the function will return an error. If the mailbox is issued
9371 * in NO_WAIT mode and there is a mailbox pending already, the function
9372 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
9373 * The sli layer owns the mailbox object until the completion of mailbox
9374 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
9375 * return codes the caller owns the mailbox command after the return of
9379 lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
9383 struct lpfc_sli *psli = &phba->sli;
9384 uint32_t status, evtctr;
9385 uint32_t ha_copy, hc_copy;
9387 unsigned long timeout;
9388 unsigned long drvr_flag = 0;
9389 uint32_t word0, ldata;
9390 void __iomem *to_slim;
9391 int processing_queue = 0;
9393 spin_lock_irqsave(&phba->hbalock, drvr_flag);
9395 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9396 /* processing mbox queue from intr_handler */
9397 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
9398 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9401 processing_queue = 1;
9402 pmbox = lpfc_mbox_get(phba);
9404 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9409 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
9410 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
9412 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9413 lpfc_printf_log(phba, KERN_ERR,
9414 LOG_MBOX | LOG_VPORT,
9415 "1806 Mbox x%x failed. No vport\n",
9416 pmbox->u.mb.mbxCommand);
9418 goto out_not_finished;
9422 /* If the PCI channel is in offline state, do not post mbox. */
9423 if (unlikely(pci_channel_offline(phba->pcidev))) {
9424 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9425 goto out_not_finished;
9428 /* If HBA has a deferred error attention, fail the iocb. */
9429 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
9430 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9431 goto out_not_finished;
9437 status = MBX_SUCCESS;
9439 if (phba->link_state == LPFC_HBA_ERROR) {
9440 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9442 /* Mbox command <mbxCommand> cannot issue */
9443 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9444 "(%d):0311 Mailbox command x%x cannot "
9445 "issue Data: x%x x%x\n",
9446 pmbox->vport ? pmbox->vport->vpi : 0,
9447 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
9448 goto out_not_finished;
9451 if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
9452 if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
9453 !(hc_copy & HC_MBINT_ENA)) {
9454 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9455 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9456 "(%d):2528 Mailbox command x%x cannot "
9457 "issue Data: x%x x%x\n",
9458 pmbox->vport ? pmbox->vport->vpi : 0,
9459 pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
9460 goto out_not_finished;
9464 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9465 /* Polling for a mbox command when another one is already active
9466 * is not allowed in SLI. Also, the driver must have established
9467 * SLI2 mode to queue and process multiple mbox commands.
9470 if (flag & MBX_POLL) {
9471 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9473 /* Mbox command <mbxCommand> cannot issue */
9474 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9475 "(%d):2529 Mailbox command x%x "
9476 "cannot issue Data: x%x x%x\n",
9477 pmbox->vport ? pmbox->vport->vpi : 0,
9478 pmbox->u.mb.mbxCommand,
9479 psli->sli_flag, flag);
9480 goto out_not_finished;
9483 if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
9484 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9485 /* Mbox command <mbxCommand> cannot issue */
9486 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9487 "(%d):2530 Mailbox command x%x "
9488 "cannot issue Data: x%x x%x\n",
9489 pmbox->vport ? pmbox->vport->vpi : 0,
9490 pmbox->u.mb.mbxCommand,
9491 psli->sli_flag, flag);
9492 goto out_not_finished;
9495 /* Another mailbox command is still being processed, queue this
9496 * command to be processed later.
9498 lpfc_mbox_put(phba, pmbox);
9500 /* Mbox cmd issue - BUSY */
9501 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9502 "(%d):0308 Mbox cmd issue - BUSY Data: "
9503 "x%x x%x x%x x%x\n",
9504 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
9506 phba->pport ? phba->pport->port_state : 0xff,
9507 psli->sli_flag, flag);
9509 psli->slistat.mbox_busy++;
9510 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9513 lpfc_debugfs_disc_trc(pmbox->vport,
9514 LPFC_DISC_TRC_MBOX_VPORT,
9515 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
9516 (uint32_t)mbx->mbxCommand,
9517 mbx->un.varWords[0], mbx->un.varWords[1]);
9520 lpfc_debugfs_disc_trc(phba->pport,
9522 "MBOX Bsy: cmd:x%x mb:x%x x%x",
9523 (uint32_t)mbx->mbxCommand,
9524 mbx->un.varWords[0], mbx->un.varWords[1]);
9530 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
9532 /* If we are not polling, we MUST be in SLI2 mode */
9533 if (flag != MBX_POLL) {
9534 if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
9535 (mbx->mbxCommand != MBX_KILL_BOARD)) {
9536 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9537 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9538 /* Mbox command <mbxCommand> cannot issue */
9539 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9540 "(%d):2531 Mailbox command x%x "
9541 "cannot issue Data: x%x x%x\n",
9542 pmbox->vport ? pmbox->vport->vpi : 0,
9543 pmbox->u.mb.mbxCommand,
9544 psli->sli_flag, flag);
9545 goto out_not_finished;
9547 /* timeout active mbox command */
9548 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
9550 mod_timer(&psli->mbox_tmo, jiffies + timeout);
9553 /* Mailbox cmd <cmd> issue */
9554 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
9555 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
9557 pmbox->vport ? pmbox->vport->vpi : 0,
9559 phba->pport ? phba->pport->port_state : 0xff,
9560 psli->sli_flag, flag);
9562 if (mbx->mbxCommand != MBX_HEARTBEAT) {
9564 lpfc_debugfs_disc_trc(pmbox->vport,
9565 LPFC_DISC_TRC_MBOX_VPORT,
9566 "MBOX Send vport: cmd:x%x mb:x%x x%x",
9567 (uint32_t)mbx->mbxCommand,
9568 mbx->un.varWords[0], mbx->un.varWords[1]);
9571 lpfc_debugfs_disc_trc(phba->pport,
9573 "MBOX Send: cmd:x%x mb:x%x x%x",
9574 (uint32_t)mbx->mbxCommand,
9575 mbx->un.varWords[0], mbx->un.varWords[1]);
9579 psli->slistat.mbox_cmd++;
9580 evtctr = psli->slistat.mbox_event;
9582 /* next set own bit for the adapter and copy over command word */
9583 mbx->mbxOwner = OWN_CHIP;
9585 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9586 /* Populate mbox extension offset word. */
9587 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
9588 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
9589 = (uint8_t *)phba->mbox_ext
9590 - (uint8_t *)phba->mbox;
9593 /* Copy the mailbox extension data */
9594 if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
9595 lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
9596 (uint8_t *)phba->mbox_ext,
9597 pmbox->in_ext_byte_len);
9599 /* Copy command data to host SLIM area */
9600 lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
9602 /* Populate mbox extension offset word. */
9603 if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
9604 *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
9605 = MAILBOX_HBA_EXT_OFFSET;
9607 /* Copy the mailbox extension data */
9608 if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
9609 lpfc_memcpy_to_slim(phba->MBslimaddr +
9610 MAILBOX_HBA_EXT_OFFSET,
9611 pmbox->ctx_buf, pmbox->in_ext_byte_len);
9613 if (mbx->mbxCommand == MBX_CONFIG_PORT)
9614 /* copy command data into host mbox for cmpl */
9615 lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
9618 /* First copy mbox command data to HBA SLIM, skip past first
9620 to_slim = phba->MBslimaddr + sizeof (uint32_t);
9621 lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
9622 MAILBOX_CMD_SIZE - sizeof (uint32_t));
9624 /* Next copy over first word, with mbxOwner set */
9625 ldata = *((uint32_t *)mbx);
9626 to_slim = phba->MBslimaddr;
9627 writel(ldata, to_slim);
9628 readl(to_slim); /* flush */
9630 if (mbx->mbxCommand == MBX_CONFIG_PORT)
9631 /* switch over to host mailbox */
9632 psli->sli_flag |= LPFC_SLI_ACTIVE;
9639 /* Set up reference to mailbox command */
9640 psli->mbox_active = pmbox;
9641 /* Interrupt board to do it */
9642 writel(CA_MBATT, phba->CAregaddr);
9643 readl(phba->CAregaddr); /* flush */
9644 /* Don't wait for it to finish, just return */
9648 /* Set up null reference to mailbox command */
9649 psli->mbox_active = NULL;
9650 /* Interrupt board to do it */
9651 writel(CA_MBATT, phba->CAregaddr);
9652 readl(phba->CAregaddr); /* flush */
9654 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9655 /* First read mbox status word */
9656 word0 = *((uint32_t *)phba->mbox);
9657 word0 = le32_to_cpu(word0);
9659 /* First read mbox status word */
9660 if (lpfc_readl(phba->MBslimaddr, &word0)) {
9661 spin_unlock_irqrestore(&phba->hbalock,
9663 goto out_not_finished;
9667 /* Read the HBA Host Attention Register */
9668 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
9669 spin_unlock_irqrestore(&phba->hbalock,
9671 goto out_not_finished;
9673 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
9676 /* Wait for command to complete */
9677 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
9678 (!(ha_copy & HA_MBATT) &&
9679 (phba->link_state > LPFC_WARM_START))) {
9680 if (time_after(jiffies, timeout)) {
9681 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9682 spin_unlock_irqrestore(&phba->hbalock,
9684 goto out_not_finished;
9687 /* Check if we took a mbox interrupt while we were
9689 if (((word0 & OWN_CHIP) != OWN_CHIP)
9690 && (evtctr != psli->slistat.mbox_event))
9694 spin_unlock_irqrestore(&phba->hbalock,
9697 spin_lock_irqsave(&phba->hbalock, drvr_flag);
9700 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9701 /* First copy command data */
9702 word0 = *((uint32_t *)phba->mbox);
9703 word0 = le32_to_cpu(word0);
9704 if (mbx->mbxCommand == MBX_CONFIG_PORT) {
9707 /* Check real SLIM for any errors */
9708 slimword0 = readl(phba->MBslimaddr);
9709 slimmb = (MAILBOX_t *) & slimword0;
9710 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
9711 && slimmb->mbxStatus) {
9718 /* First copy command data */
9719 word0 = readl(phba->MBslimaddr);
9721 /* Read the HBA Host Attention Register */
9722 if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
9723 spin_unlock_irqrestore(&phba->hbalock,
9725 goto out_not_finished;
9729 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
9730 /* copy results back to user */
9731 lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
9733 /* Copy the mailbox extension data */
9734 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
9735 lpfc_sli_pcimem_bcopy(phba->mbox_ext,
9737 pmbox->out_ext_byte_len);
9740 /* First copy command data */
9741 lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
9743 /* Copy the mailbox extension data */
9744 if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
9745 lpfc_memcpy_from_slim(
9748 MAILBOX_HBA_EXT_OFFSET,
9749 pmbox->out_ext_byte_len);
9753 writel(HA_MBATT, phba->HAregaddr);
9754 readl(phba->HAregaddr); /* flush */
9756 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9757 status = mbx->mbxStatus;
9760 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
9764 if (processing_queue) {
9765 pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
9766 lpfc_mbox_cmpl_put(phba, pmbox);
9768 return MBX_NOT_FINISHED;
9772 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
9773 * @phba: Pointer to HBA context object.
9775 * The function blocks the posting of SLI4 asynchronous mailbox commands from
9776 * the driver internal pending mailbox queue. It will then try to wait out the
9777 * possible outstanding mailbox command before return.
9780 * 0 - the outstanding mailbox command completed; otherwise, the wait for
9781 * the outstanding mailbox command timed out.
9784 lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
9786 struct lpfc_sli *psli = &phba->sli;
9787 LPFC_MBOXQ_t *mboxq;
9789 unsigned long timeout = 0;
9791 u8 cmd, subsys, opcode;
9793 /* Mark the asynchronous mailbox command posting as blocked */
9794 spin_lock_irq(&phba->hbalock);
9795 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9796 /* Determine how long we might wait for the active mailbox
9797 * command to be gracefully completed by firmware.
9799 if (phba->sli.mbox_active)
9800 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
9801 phba->sli.mbox_active) *
9803 spin_unlock_irq(&phba->hbalock);
9805 /* Make sure the mailbox is really active */
9807 lpfc_sli4_process_missed_mbox_completions(phba);
9809 /* Wait for the outstanding mailbox command to complete */
9810 while (phba->sli.mbox_active) {
9811 /* Check active mailbox complete status every 2ms */
9813 if (time_after(jiffies, timeout)) {
9814 /* Timeout, mark the outstanding cmd not complete */
9816 /* Sanity check sli.mbox_active has not completed or
9817 * cancelled from another context during last 2ms sleep,
9818 * so take hbalock to be sure before logging.
9820 spin_lock_irq(&phba->hbalock);
9821 if (phba->sli.mbox_active) {
9822 mboxq = phba->sli.mbox_active;
9823 cmd = mboxq->u.mb.mbxCommand;
9824 subsys = lpfc_sli_config_mbox_subsys_get(phba,
9826 opcode = lpfc_sli_config_mbox_opcode_get(phba,
9828 sli_flag = psli->sli_flag;
9829 spin_unlock_irq(&phba->hbalock);
9830 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9831 "2352 Mailbox command x%x "
9832 "(x%x/x%x) sli_flag x%x could "
9834 cmd, subsys, opcode,
9837 spin_unlock_irq(&phba->hbalock);
9845 /* Can not cleanly block async mailbox command, fails it */
9847 spin_lock_irq(&phba->hbalock);
9848 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
9849 spin_unlock_irq(&phba->hbalock);
9855 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
9856 * @phba: Pointer to HBA context object.
9858 * The function unblocks and resume posting of SLI4 asynchronous mailbox
9859 * commands from the driver internal pending mailbox queue. It makes sure
9860 * that there is no outstanding mailbox command before resuming posting
9861 * asynchronous mailbox commands. If, for any reason, there is outstanding
9862 * mailbox command, it will try to wait it out before resuming asynchronous
9863 * mailbox command posting.
9866 lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
9868 struct lpfc_sli *psli = &phba->sli;
9870 spin_lock_irq(&phba->hbalock);
9871 if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
9872 /* Asynchronous mailbox posting is not blocked, do nothing */
9873 spin_unlock_irq(&phba->hbalock);
9877 /* Outstanding synchronous mailbox command is guaranteed to be done,
9878 * successful or timeout, after timing-out the outstanding mailbox
9879 * command shall always be removed, so just unblock posting async
9880 * mailbox command and resume
9882 psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
9883 spin_unlock_irq(&phba->hbalock);
9885 /* wake up worker thread to post asynchronous mailbox command */
9886 lpfc_worker_wake_up(phba);
9890 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
9891 * @phba: Pointer to HBA context object.
9892 * @mboxq: Pointer to mailbox object.
9894 * The function waits for the bootstrap mailbox register ready bit from
9895 * port for twice the regular mailbox command timeout value.
9897 * 0 - no timeout on waiting for bootstrap mailbox register ready.
9898 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
9901 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9904 unsigned long timeout;
9905 struct lpfc_register bmbx_reg;
9907 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
9911 bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
9912 db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
9916 if (time_after(jiffies, timeout))
9917 return MBXERR_ERROR;
9918 } while (!db_ready);
9924 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
9925 * @phba: Pointer to HBA context object.
9926 * @mboxq: Pointer to mailbox object.
9928 * The function posts a mailbox to the port. The mailbox is expected
9929 * to be comletely filled in and ready for the port to operate on it.
9930 * This routine executes a synchronous completion operation on the
9931 * mailbox by polling for its completion.
9933 * The caller must not be holding any locks when calling this routine.
9936 * MBX_SUCCESS - mailbox posted successfully
9937 * Any of the MBX error values.
9940 lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9942 int rc = MBX_SUCCESS;
9943 unsigned long iflag;
9944 uint32_t mcqe_status;
9946 struct lpfc_sli *psli = &phba->sli;
9947 struct lpfc_mqe *mb = &mboxq->u.mqe;
9948 struct lpfc_bmbx_create *mbox_rgn;
9949 struct dma_address *dma_address;
9952 * Only one mailbox can be active to the bootstrap mailbox region
9953 * at a time and there is no queueing provided.
9955 spin_lock_irqsave(&phba->hbalock, iflag);
9956 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9957 spin_unlock_irqrestore(&phba->hbalock, iflag);
9958 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9959 "(%d):2532 Mailbox command x%x (x%x/x%x) "
9960 "cannot issue Data: x%x x%x\n",
9961 mboxq->vport ? mboxq->vport->vpi : 0,
9962 mboxq->u.mb.mbxCommand,
9963 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
9964 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
9965 psli->sli_flag, MBX_POLL);
9966 return MBXERR_ERROR;
9968 /* The server grabs the token and owns it until release */
9969 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
9970 phba->sli.mbox_active = mboxq;
9971 spin_unlock_irqrestore(&phba->hbalock, iflag);
9973 /* wait for bootstrap mbox register for readyness */
9974 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
9978 * Initialize the bootstrap memory region to avoid stale data areas
9979 * in the mailbox post. Then copy the caller's mailbox contents to
9980 * the bmbx mailbox region.
9982 mbx_cmnd = bf_get(lpfc_mqe_command, mb);
9983 memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
9984 lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
9985 sizeof(struct lpfc_mqe));
9987 /* Post the high mailbox dma address to the port and wait for ready. */
9988 dma_address = &phba->sli4_hba.bmbx.dma_address;
9989 writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
9991 /* wait for bootstrap mbox register for hi-address write done */
9992 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
9996 /* Post the low mailbox dma address to the port. */
9997 writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
9999 /* wait for bootstrap mbox register for low address write done */
10000 rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
10005 * Read the CQ to ensure the mailbox has completed.
10006 * If so, update the mailbox status so that the upper layers
10007 * can complete the request normally.
10009 lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
10010 sizeof(struct lpfc_mqe));
10011 mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
10012 lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
10013 sizeof(struct lpfc_mcqe));
10014 mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
10016 * When the CQE status indicates a failure and the mailbox status
10017 * indicates success then copy the CQE status into the mailbox status
10018 * (and prefix it with x4000).
10020 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
10021 if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
10022 bf_set(lpfc_mqe_status, mb,
10023 (LPFC_MBX_ERROR_RANGE | mcqe_status));
10026 lpfc_sli4_swap_str(phba, mboxq);
10028 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
10029 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
10030 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
10031 " x%x x%x CQ: x%x x%x x%x x%x\n",
10032 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
10033 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10034 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10035 bf_get(lpfc_mqe_status, mb),
10036 mb->un.mb_words[0], mb->un.mb_words[1],
10037 mb->un.mb_words[2], mb->un.mb_words[3],
10038 mb->un.mb_words[4], mb->un.mb_words[5],
10039 mb->un.mb_words[6], mb->un.mb_words[7],
10040 mb->un.mb_words[8], mb->un.mb_words[9],
10041 mb->un.mb_words[10], mb->un.mb_words[11],
10042 mb->un.mb_words[12], mboxq->mcqe.word0,
10043 mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
10044 mboxq->mcqe.trailer);
10046 /* We are holding the token, no needed for lock when release */
10047 spin_lock_irqsave(&phba->hbalock, iflag);
10048 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10049 phba->sli.mbox_active = NULL;
10050 spin_unlock_irqrestore(&phba->hbalock, iflag);
10055 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
10056 * @phba: Pointer to HBA context object.
10057 * @mboxq: Pointer to mailbox object.
10058 * @flag: Flag indicating how the mailbox need to be processed.
10060 * This function is called by discovery code and HBA management code to submit
10061 * a mailbox command to firmware with SLI-4 interface spec.
10063 * Return codes the caller owns the mailbox command after the return of the
10067 lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
10070 struct lpfc_sli *psli = &phba->sli;
10071 unsigned long iflags;
10074 /* dump from issue mailbox command if setup */
10075 lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
10077 rc = lpfc_mbox_dev_check(phba);
10078 if (unlikely(rc)) {
10079 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10080 "(%d):2544 Mailbox command x%x (x%x/x%x) "
10081 "cannot issue Data: x%x x%x\n",
10082 mboxq->vport ? mboxq->vport->vpi : 0,
10083 mboxq->u.mb.mbxCommand,
10084 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10085 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10086 psli->sli_flag, flag);
10087 goto out_not_finished;
10090 /* Detect polling mode and jump to a handler */
10091 if (!phba->sli4_hba.intr_enable) {
10092 if (flag == MBX_POLL)
10093 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
10096 if (rc != MBX_SUCCESS)
10097 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
10098 "(%d):2541 Mailbox command x%x "
10099 "(x%x/x%x) failure: "
10100 "mqe_sta: x%x mcqe_sta: x%x/x%x "
10102 mboxq->vport ? mboxq->vport->vpi : 0,
10103 mboxq->u.mb.mbxCommand,
10104 lpfc_sli_config_mbox_subsys_get(phba,
10106 lpfc_sli_config_mbox_opcode_get(phba,
10108 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
10109 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
10110 bf_get(lpfc_mcqe_ext_status,
10112 psli->sli_flag, flag);
10114 } else if (flag == MBX_POLL) {
10115 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
10116 "(%d):2542 Try to issue mailbox command "
10117 "x%x (x%x/x%x) synchronously ahead of async "
10118 "mailbox command queue: x%x x%x\n",
10119 mboxq->vport ? mboxq->vport->vpi : 0,
10120 mboxq->u.mb.mbxCommand,
10121 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10122 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10123 psli->sli_flag, flag);
10124 /* Try to block the asynchronous mailbox posting */
10125 rc = lpfc_sli4_async_mbox_block(phba);
10127 /* Successfully blocked, now issue sync mbox cmd */
10128 rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
10129 if (rc != MBX_SUCCESS)
10130 lpfc_printf_log(phba, KERN_WARNING,
10131 LOG_MBOX | LOG_SLI,
10132 "(%d):2597 Sync Mailbox command "
10133 "x%x (x%x/x%x) failure: "
10134 "mqe_sta: x%x mcqe_sta: x%x/x%x "
10136 mboxq->vport ? mboxq->vport->vpi : 0,
10137 mboxq->u.mb.mbxCommand,
10138 lpfc_sli_config_mbox_subsys_get(phba,
10140 lpfc_sli_config_mbox_opcode_get(phba,
10142 bf_get(lpfc_mqe_status, &mboxq->u.mqe),
10143 bf_get(lpfc_mcqe_status, &mboxq->mcqe),
10144 bf_get(lpfc_mcqe_ext_status,
10146 psli->sli_flag, flag);
10147 /* Unblock the async mailbox posting afterward */
10148 lpfc_sli4_async_mbox_unblock(phba);
10153 /* Now, interrupt mode asynchronous mailbox command */
10154 rc = lpfc_mbox_cmd_check(phba, mboxq);
10156 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10157 "(%d):2543 Mailbox command x%x (x%x/x%x) "
10158 "cannot issue Data: x%x x%x\n",
10159 mboxq->vport ? mboxq->vport->vpi : 0,
10160 mboxq->u.mb.mbxCommand,
10161 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10162 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10163 psli->sli_flag, flag);
10164 goto out_not_finished;
10167 /* Put the mailbox command to the driver internal FIFO */
10168 psli->slistat.mbox_busy++;
10169 spin_lock_irqsave(&phba->hbalock, iflags);
10170 lpfc_mbox_put(phba, mboxq);
10171 spin_unlock_irqrestore(&phba->hbalock, iflags);
10172 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
10173 "(%d):0354 Mbox cmd issue - Enqueue Data: "
10174 "x%x (x%x/x%x) x%x x%x x%x\n",
10175 mboxq->vport ? mboxq->vport->vpi : 0xffffff,
10176 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
10177 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10178 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10179 phba->pport->port_state,
10180 psli->sli_flag, MBX_NOWAIT);
10181 /* Wake up worker thread to transport mailbox command from head */
10182 lpfc_worker_wake_up(phba);
10187 return MBX_NOT_FINISHED;
10191 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
10192 * @phba: Pointer to HBA context object.
10194 * This function is called by worker thread to send a mailbox command to
10195 * SLI4 HBA firmware.
10199 lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
10201 struct lpfc_sli *psli = &phba->sli;
10202 LPFC_MBOXQ_t *mboxq;
10203 int rc = MBX_SUCCESS;
10204 unsigned long iflags;
10205 struct lpfc_mqe *mqe;
10208 /* Check interrupt mode before post async mailbox command */
10209 if (unlikely(!phba->sli4_hba.intr_enable))
10210 return MBX_NOT_FINISHED;
10212 /* Check for mailbox command service token */
10213 spin_lock_irqsave(&phba->hbalock, iflags);
10214 if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
10215 spin_unlock_irqrestore(&phba->hbalock, iflags);
10216 return MBX_NOT_FINISHED;
10218 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10219 spin_unlock_irqrestore(&phba->hbalock, iflags);
10220 return MBX_NOT_FINISHED;
10222 if (unlikely(phba->sli.mbox_active)) {
10223 spin_unlock_irqrestore(&phba->hbalock, iflags);
10224 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10225 "0384 There is pending active mailbox cmd\n");
10226 return MBX_NOT_FINISHED;
10228 /* Take the mailbox command service token */
10229 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
10231 /* Get the next mailbox command from head of queue */
10232 mboxq = lpfc_mbox_get(phba);
10234 /* If no more mailbox command waiting for post, we're done */
10236 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10237 spin_unlock_irqrestore(&phba->hbalock, iflags);
10238 return MBX_SUCCESS;
10240 phba->sli.mbox_active = mboxq;
10241 spin_unlock_irqrestore(&phba->hbalock, iflags);
10243 /* Check device readiness for posting mailbox command */
10244 rc = lpfc_mbox_dev_check(phba);
10246 /* Driver clean routine will clean up pending mailbox */
10247 goto out_not_finished;
10249 /* Prepare the mbox command to be posted */
10250 mqe = &mboxq->u.mqe;
10251 mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
10253 /* Start timer for the mbox_tmo and log some mailbox post messages */
10254 mod_timer(&psli->mbox_tmo, (jiffies +
10255 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
10257 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
10258 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
10260 mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
10261 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10262 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10263 phba->pport->port_state, psli->sli_flag);
10265 if (mbx_cmnd != MBX_HEARTBEAT) {
10266 if (mboxq->vport) {
10267 lpfc_debugfs_disc_trc(mboxq->vport,
10268 LPFC_DISC_TRC_MBOX_VPORT,
10269 "MBOX Send vport: cmd:x%x mb:x%x x%x",
10270 mbx_cmnd, mqe->un.mb_words[0],
10271 mqe->un.mb_words[1]);
10273 lpfc_debugfs_disc_trc(phba->pport,
10274 LPFC_DISC_TRC_MBOX,
10275 "MBOX Send: cmd:x%x mb:x%x x%x",
10276 mbx_cmnd, mqe->un.mb_words[0],
10277 mqe->un.mb_words[1]);
10280 psli->slistat.mbox_cmd++;
10282 /* Post the mailbox command to the port */
10283 rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
10284 if (rc != MBX_SUCCESS) {
10285 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10286 "(%d):2533 Mailbox command x%x (x%x/x%x) "
10287 "cannot issue Data: x%x x%x\n",
10288 mboxq->vport ? mboxq->vport->vpi : 0,
10289 mboxq->u.mb.mbxCommand,
10290 lpfc_sli_config_mbox_subsys_get(phba, mboxq),
10291 lpfc_sli_config_mbox_opcode_get(phba, mboxq),
10292 psli->sli_flag, MBX_NOWAIT);
10293 goto out_not_finished;
10299 spin_lock_irqsave(&phba->hbalock, iflags);
10300 if (phba->sli.mbox_active) {
10301 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10302 __lpfc_mbox_cmpl_put(phba, mboxq);
10303 /* Release the token */
10304 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10305 phba->sli.mbox_active = NULL;
10307 spin_unlock_irqrestore(&phba->hbalock, iflags);
10309 return MBX_NOT_FINISHED;
10313 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
10314 * @phba: Pointer to HBA context object.
10315 * @pmbox: Pointer to mailbox object.
10316 * @flag: Flag indicating how the mailbox need to be processed.
10318 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
10319 * the API jump table function pointer from the lpfc_hba struct.
10321 * Return codes the caller owns the mailbox command after the return of the
10325 lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
10327 return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
10331 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
10332 * @phba: The hba struct for which this call is being executed.
10333 * @dev_grp: The HBA PCI-Device group number.
10335 * This routine sets up the mbox interface API function jump table in @phba
10337 * Returns: 0 - success, -ENODEV - failure.
10340 lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
10344 case LPFC_PCI_DEV_LP:
10345 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
10346 phba->lpfc_sli_handle_slow_ring_event =
10347 lpfc_sli_handle_slow_ring_event_s3;
10348 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
10349 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
10350 phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
10352 case LPFC_PCI_DEV_OC:
10353 phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
10354 phba->lpfc_sli_handle_slow_ring_event =
10355 lpfc_sli_handle_slow_ring_event_s4;
10356 phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
10357 phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
10358 phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
10361 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10362 "1420 Invalid HBA PCI-device group: 0x%x\n",
10370 * __lpfc_sli_ringtx_put - Add an iocb to the txq
10371 * @phba: Pointer to HBA context object.
10372 * @pring: Pointer to driver SLI ring object.
10373 * @piocb: Pointer to address of newly added command iocb.
10375 * This function is called with hbalock held for SLI3 ports or
10376 * the ring lock held for SLI4 ports to add a command
10377 * iocb to the txq when SLI layer cannot submit the command iocb
10381 __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10382 struct lpfc_iocbq *piocb)
10384 if (phba->sli_rev == LPFC_SLI_REV4)
10385 lockdep_assert_held(&pring->ring_lock);
10387 lockdep_assert_held(&phba->hbalock);
10388 /* Insert the caller's iocb in the txq tail for later processing. */
10389 list_add_tail(&piocb->list, &pring->txq);
10393 * lpfc_sli_next_iocb - Get the next iocb in the txq
10394 * @phba: Pointer to HBA context object.
10395 * @pring: Pointer to driver SLI ring object.
10396 * @piocb: Pointer to address of newly added command iocb.
10398 * This function is called with hbalock held before a new
10399 * iocb is submitted to the firmware. This function checks
10400 * txq to flush the iocbs in txq to Firmware before
10401 * submitting new iocbs to the Firmware.
10402 * If there are iocbs in the txq which need to be submitted
10403 * to firmware, lpfc_sli_next_iocb returns the first element
10404 * of the txq after dequeuing it from txq.
10405 * If there is no iocb in the txq then the function will return
10406 * *piocb and *piocb is set to NULL. Caller needs to check
10407 * *piocb to find if there are more commands in the txq.
10409 static struct lpfc_iocbq *
10410 lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
10411 struct lpfc_iocbq **piocb)
10413 struct lpfc_iocbq * nextiocb;
10415 lockdep_assert_held(&phba->hbalock);
10417 nextiocb = lpfc_sli_ringtx_get(phba, pring);
10427 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
10428 * @phba: Pointer to HBA context object.
10429 * @ring_number: SLI ring number to issue iocb on.
10430 * @piocb: Pointer to command iocb.
10431 * @flag: Flag indicating if this command can be put into txq.
10433 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
10434 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
10435 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
10436 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
10437 * this function allows only iocbs for posting buffers. This function finds
10438 * next available slot in the command ring and posts the command to the
10439 * available slot and writes the port attention register to request HBA start
10440 * processing new iocb. If there is no slot available in the ring and
10441 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
10442 * the function returns IOCB_BUSY.
10444 * This function is called with hbalock held. The function will return success
10445 * after it successfully submit the iocb to firmware or after adding to the
10449 __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
10450 struct lpfc_iocbq *piocb, uint32_t flag)
10452 struct lpfc_iocbq *nextiocb;
10454 struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
10456 lockdep_assert_held(&phba->hbalock);
10458 if (piocb->cmd_cmpl && (!piocb->vport) &&
10459 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
10460 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
10461 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10462 "1807 IOCB x%x failed. No vport\n",
10463 piocb->iocb.ulpCommand);
10469 /* If the PCI channel is in offline state, do not post iocbs. */
10470 if (unlikely(pci_channel_offline(phba->pcidev)))
10473 /* If HBA has a deferred error attention, fail the iocb. */
10474 if (unlikely(phba->hba_flag & DEFER_ERATT))
10478 * We should never get an IOCB if we are in a < LINK_DOWN state
10480 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
10484 * Check to see if we are blocking IOCB processing because of a
10485 * outstanding event.
10487 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
10490 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
10492 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
10493 * can be issued if the link is not up.
10495 switch (piocb->iocb.ulpCommand) {
10496 case CMD_QUE_RING_BUF_CN:
10497 case CMD_QUE_RING_BUF64_CN:
10499 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
10500 * completion, cmd_cmpl MUST be 0.
10502 if (piocb->cmd_cmpl)
10503 piocb->cmd_cmpl = NULL;
10505 case CMD_CREATE_XRI_CR:
10506 case CMD_CLOSE_XRI_CN:
10507 case CMD_CLOSE_XRI_CX:
10514 * For FCP commands, we must be in a state where we can process link
10515 * attention events.
10517 } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
10518 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
10522 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
10523 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
10524 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
10527 lpfc_sli_update_ring(phba, pring);
10529 lpfc_sli_update_full_ring(phba, pring);
10532 return IOCB_SUCCESS;
10537 pring->stats.iocb_cmd_delay++;
10541 if (!(flag & SLI_IOCB_RET_IOCB)) {
10542 __lpfc_sli_ringtx_put(phba, pring, piocb);
10543 return IOCB_SUCCESS;
10550 * __lpfc_sli_issue_fcp_io_s3 - SLI3 device for sending fcp io iocb
10551 * @phba: Pointer to HBA context object.
10552 * @ring_number: SLI ring number to issue wqe on.
10553 * @piocb: Pointer to command iocb.
10554 * @flag: Flag indicating if this command can be put into txq.
10556 * __lpfc_sli_issue_fcp_io_s3 is wrapper function to invoke lockless func to
10557 * send an iocb command to an HBA with SLI-3 interface spec.
10559 * This function takes the hbalock before invoking the lockless version.
10560 * The function will return success after it successfully submit the wqe to
10561 * firmware or after adding to the txq.
10564 __lpfc_sli_issue_fcp_io_s3(struct lpfc_hba *phba, uint32_t ring_number,
10565 struct lpfc_iocbq *piocb, uint32_t flag)
10567 unsigned long iflags;
10570 spin_lock_irqsave(&phba->hbalock, iflags);
10571 rc = __lpfc_sli_issue_iocb_s3(phba, ring_number, piocb, flag);
10572 spin_unlock_irqrestore(&phba->hbalock, iflags);
10578 * __lpfc_sli_issue_fcp_io_s4 - SLI4 device for sending fcp io wqe
10579 * @phba: Pointer to HBA context object.
10580 * @ring_number: SLI ring number to issue wqe on.
10581 * @piocb: Pointer to command iocb.
10582 * @flag: Flag indicating if this command can be put into txq.
10584 * __lpfc_sli_issue_fcp_io_s4 is used by other functions in the driver to issue
10585 * an wqe command to an HBA with SLI-4 interface spec.
10587 * This function is a lockless version. The function will return success
10588 * after it successfully submit the wqe to firmware or after adding to the
10592 __lpfc_sli_issue_fcp_io_s4(struct lpfc_hba *phba, uint32_t ring_number,
10593 struct lpfc_iocbq *piocb, uint32_t flag)
10595 struct lpfc_io_buf *lpfc_cmd = piocb->io_buf;
10597 lpfc_prep_embed_io(phba, lpfc_cmd);
10598 return lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, piocb);
10602 lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
10604 struct lpfc_iocbq *piocb = &lpfc_cmd->cur_iocbq;
10605 union lpfc_wqe128 *wqe = &lpfc_cmd->cur_iocbq.wqe;
10606 struct sli4_sge *sgl;
10608 /* 128 byte wqe support here */
10609 sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
10611 if (phba->fcp_embed_io) {
10612 struct fcp_cmnd *fcp_cmnd;
10615 fcp_cmnd = lpfc_cmd->fcp_cmnd;
10617 /* Word 0-2 - FCP_CMND */
10618 wqe->generic.bde.tus.f.bdeFlags =
10619 BUFF_TYPE_BDE_IMMED;
10620 wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
10621 wqe->generic.bde.addrHigh = 0;
10622 wqe->generic.bde.addrLow = 88; /* Word 22 */
10624 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
10625 bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
10627 /* Word 22-29 FCP CMND Payload */
10628 ptr = &wqe->words[22];
10629 memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
10631 /* Word 0-2 - Inline BDE */
10632 wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
10633 wqe->generic.bde.tus.f.bdeSize = sizeof(struct fcp_cmnd);
10634 wqe->generic.bde.addrHigh = sgl->addr_hi;
10635 wqe->generic.bde.addrLow = sgl->addr_lo;
10638 bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
10639 bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
10642 /* add the VMID tags as per switch response */
10643 if (unlikely(piocb->cmd_flag & LPFC_IO_VMID)) {
10644 if (phba->pport->vmid_flag & LPFC_VMID_TYPE_PRIO) {
10645 bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
10646 bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
10647 (piocb->vmid_tag.cs_ctl_vmid));
10648 } else if (phba->cfg_vmid_app_header) {
10649 bf_set(wqe_appid, &wqe->fcp_iwrite.wqe_com, 1);
10650 bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
10651 wqe->words[31] = piocb->vmid_tag.app_id;
10657 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
10658 * @phba: Pointer to HBA context object.
10659 * @ring_number: SLI ring number to issue iocb on.
10660 * @piocb: Pointer to command iocb.
10661 * @flag: Flag indicating if this command can be put into txq.
10663 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
10664 * an iocb command to an HBA with SLI-4 interface spec.
10666 * This function is called with ringlock held. The function will return success
10667 * after it successfully submit the iocb to firmware or after adding to the
10671 __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
10672 struct lpfc_iocbq *piocb, uint32_t flag)
10674 struct lpfc_sglq *sglq;
10675 union lpfc_wqe128 *wqe;
10676 struct lpfc_queue *wq;
10677 struct lpfc_sli_ring *pring;
10678 u32 ulp_command = get_job_cmnd(phba, piocb);
10681 if ((piocb->cmd_flag & LPFC_IO_FCP) ||
10682 (piocb->cmd_flag & LPFC_USE_FCPWQIDX)) {
10683 wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
10685 wq = phba->sli4_hba.els_wq;
10688 /* Get corresponding ring */
10692 * The WQE can be either 64 or 128 bytes,
10695 lockdep_assert_held(&pring->ring_lock);
10697 if (piocb->sli4_xritag == NO_XRI) {
10698 if (ulp_command == CMD_ABORT_XRI_CX)
10701 sglq = __lpfc_sli_get_els_sglq(phba, piocb);
10703 if (!(flag & SLI_IOCB_RET_IOCB)) {
10704 __lpfc_sli_ringtx_put(phba,
10707 return IOCB_SUCCESS;
10713 } else if (piocb->cmd_flag & LPFC_IO_FCP) {
10714 /* These IO's already have an XRI and a mapped sgl. */
10719 * This is a continuation of a commandi,(CX) so this
10720 * sglq is on the active list
10722 sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
10728 piocb->sli4_lxritag = sglq->sli4_lxritag;
10729 piocb->sli4_xritag = sglq->sli4_xritag;
10731 /* ABTS sent by initiator to CT exchange, the
10732 * RX_ID field will be filled with the newly
10733 * allocated responder XRI.
10735 if (ulp_command == CMD_XMIT_BLS_RSP64_CX &&
10736 piocb->abort_bls == LPFC_ABTS_UNSOL_INT)
10737 bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
10738 piocb->sli4_xritag);
10740 bf_set(wqe_xri_tag, &wqe->generic.wqe_com,
10741 piocb->sli4_xritag);
10743 if (lpfc_wqe_bpl2sgl(phba, piocb, sglq) == NO_XRI)
10747 if (lpfc_sli4_wq_put(wq, wqe))
10750 lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
10756 * lpfc_sli_issue_fcp_io - Wrapper func for issuing fcp i/o
10758 * This routine wraps the actual fcp i/o function for issusing WQE for sli-4
10759 * or IOCB for sli-3 function.
10760 * pointer from the lpfc_hba struct.
10763 * IOCB_ERROR - Error
10764 * IOCB_SUCCESS - Success
10768 lpfc_sli_issue_fcp_io(struct lpfc_hba *phba, uint32_t ring_number,
10769 struct lpfc_iocbq *piocb, uint32_t flag)
10771 return phba->__lpfc_sli_issue_fcp_io(phba, ring_number, piocb, flag);
10775 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
10777 * This routine wraps the actual lockless version for issusing IOCB function
10778 * pointer from the lpfc_hba struct.
10781 * IOCB_ERROR - Error
10782 * IOCB_SUCCESS - Success
10786 __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
10787 struct lpfc_iocbq *piocb, uint32_t flag)
10789 return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
10793 __lpfc_sli_prep_els_req_rsp_s3(struct lpfc_iocbq *cmdiocbq,
10794 struct lpfc_vport *vport,
10795 struct lpfc_dmabuf *bmp, u16 cmd_size, u32 did,
10796 u32 elscmd, u8 tmo, u8 expect_rsp)
10798 struct lpfc_hba *phba = vport->phba;
10801 cmd = &cmdiocbq->iocb;
10802 memset(cmd, 0, sizeof(*cmd));
10804 cmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
10805 cmd->un.elsreq64.bdl.addrLow = putPaddrLow(bmp->phys);
10806 cmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
10809 cmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
10810 cmd->un.elsreq64.remoteID = did; /* DID */
10811 cmd->ulpCommand = CMD_ELS_REQUEST64_CR;
10812 cmd->ulpTimeout = tmo;
10814 cmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
10815 cmd->un.genreq64.xmit_els_remoteID = did; /* DID */
10816 cmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
10817 cmd->ulpPU = PARM_NPIV_DID;
10819 cmd->ulpBdeCount = 1;
10821 cmd->ulpClass = CLASS3;
10823 /* If we have NPIV enabled, we want to send ELS traffic by VPI. */
10824 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
10826 cmd->un.elsreq64.myID = vport->fc_myDID;
10828 /* For ELS_REQUEST64_CR, use the VPI by default */
10829 cmd->ulpContext = phba->vpi_ids[vport->vpi];
10833 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
10834 if (elscmd == ELS_CMD_ECHO)
10835 cmd->ulpCt_l = 0; /* context = invalid RPI */
10837 cmd->ulpCt_l = 1; /* context = VPI */
10842 __lpfc_sli_prep_els_req_rsp_s4(struct lpfc_iocbq *cmdiocbq,
10843 struct lpfc_vport *vport,
10844 struct lpfc_dmabuf *bmp, u16 cmd_size, u32 did,
10845 u32 elscmd, u8 tmo, u8 expect_rsp)
10847 struct lpfc_hba *phba = vport->phba;
10848 union lpfc_wqe128 *wqe;
10849 struct ulp_bde64_le *bde;
10852 wqe = &cmdiocbq->wqe;
10853 memset(wqe, 0, sizeof(*wqe));
10855 /* Word 0 - 2 BDE */
10856 bde = (struct ulp_bde64_le *)&wqe->generic.bde;
10857 bde->addr_low = cpu_to_le32(putPaddrLow(bmp->phys));
10858 bde->addr_high = cpu_to_le32(putPaddrHigh(bmp->phys));
10859 bde->type_size = cpu_to_le32(cmd_size);
10860 bde->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
10863 bf_set(wqe_cmnd, &wqe->els_req.wqe_com, CMD_ELS_REQUEST64_WQE);
10865 /* Transfer length */
10866 wqe->els_req.payload_len = cmd_size;
10867 wqe->els_req.max_response_payload_len = FCELSSIZE;
10870 bf_set(wqe_els_did, &wqe->els_req.wqe_dest, did);
10872 /* Word 11 - ELS_ID */
10874 case ELS_CMD_PLOGI:
10875 els_id = LPFC_ELS_ID_PLOGI;
10877 case ELS_CMD_FLOGI:
10878 els_id = LPFC_ELS_ID_FLOGI;
10881 els_id = LPFC_ELS_ID_LOGO;
10883 case ELS_CMD_FDISC:
10884 if (!vport->fc_myDID) {
10885 els_id = LPFC_ELS_ID_FDISC;
10890 els_id = LPFC_ELS_ID_DEFAULT;
10894 bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
10897 bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, did);
10899 /* Transfer length */
10900 wqe->xmit_els_rsp.response_payload_len = cmd_size;
10902 bf_set(wqe_cmnd, &wqe->xmit_els_rsp.wqe_com,
10903 CMD_XMIT_ELS_RSP64_WQE);
10906 bf_set(wqe_tmo, &wqe->generic.wqe_com, tmo);
10907 bf_set(wqe_reqtag, &wqe->generic.wqe_com, cmdiocbq->iotag);
10908 bf_set(wqe_class, &wqe->generic.wqe_com, CLASS3);
10910 /* If we have NPIV enabled, we want to send ELS traffic by VPI.
10911 * For SLI4, since the driver controls VPIs we also want to include
10912 * all ELS pt2pt protocol traffic as well.
10914 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
10915 (vport->fc_flag & FC_PT2PT)) {
10917 bf_set(els_req64_sid, &wqe->els_req, vport->fc_myDID);
10919 /* For ELS_REQUEST64_WQE, use the VPI by default */
10920 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
10921 phba->vpi_ids[vport->vpi]);
10924 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
10925 if (elscmd == ELS_CMD_ECHO)
10926 bf_set(wqe_ct, &wqe->generic.wqe_com, 0);
10928 bf_set(wqe_ct, &wqe->generic.wqe_com, 1);
10933 lpfc_sli_prep_els_req_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
10934 struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
10935 u16 cmd_size, u32 did, u32 elscmd, u8 tmo,
10938 phba->__lpfc_sli_prep_els_req_rsp(cmdiocbq, vport, bmp, cmd_size, did,
10939 elscmd, tmo, expect_rsp);
10943 __lpfc_sli_prep_gen_req_s3(struct lpfc_iocbq *cmdiocbq, struct lpfc_dmabuf *bmp,
10944 u16 rpi, u32 num_entry, u8 tmo)
10948 cmd = &cmdiocbq->iocb;
10949 memset(cmd, 0, sizeof(*cmd));
10951 cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
10952 cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
10953 cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
10954 cmd->un.genreq64.bdl.bdeSize = num_entry * sizeof(struct ulp_bde64);
10956 cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
10957 cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
10958 cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
10960 cmd->ulpContext = rpi;
10961 cmd->ulpClass = CLASS3;
10962 cmd->ulpCommand = CMD_GEN_REQUEST64_CR;
10963 cmd->ulpBdeCount = 1;
10965 cmd->ulpOwner = OWN_CHIP;
10966 cmd->ulpTimeout = tmo;
10970 __lpfc_sli_prep_gen_req_s4(struct lpfc_iocbq *cmdiocbq, struct lpfc_dmabuf *bmp,
10971 u16 rpi, u32 num_entry, u8 tmo)
10973 union lpfc_wqe128 *cmdwqe;
10974 struct ulp_bde64_le *bde, *bpl;
10975 u32 xmit_len = 0, total_len = 0, size, type, i;
10977 cmdwqe = &cmdiocbq->wqe;
10978 memset(cmdwqe, 0, sizeof(*cmdwqe));
10980 /* Calculate total_len and xmit_len */
10981 bpl = (struct ulp_bde64_le *)bmp->virt;
10982 for (i = 0; i < num_entry; i++) {
10983 size = le32_to_cpu(bpl[i].type_size) & ULP_BDE64_SIZE_MASK;
10986 for (i = 0; i < num_entry; i++) {
10987 size = le32_to_cpu(bpl[i].type_size) & ULP_BDE64_SIZE_MASK;
10988 type = le32_to_cpu(bpl[i].type_size) & ULP_BDE64_TYPE_MASK;
10989 if (type != ULP_BDE64_TYPE_BDE_64)
10995 bde = (struct ulp_bde64_le *)&cmdwqe->generic.bde;
10996 bde->addr_low = bpl->addr_low;
10997 bde->addr_high = bpl->addr_high;
10998 bde->type_size = cpu_to_le32(xmit_len);
10999 bde->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
11002 cmdwqe->gen_req.request_payload_len = xmit_len;
11005 bf_set(wqe_type, &cmdwqe->gen_req.wge_ctl, FC_TYPE_CT);
11006 bf_set(wqe_rctl, &cmdwqe->gen_req.wge_ctl, FC_RCTL_DD_UNSOL_CTL);
11007 bf_set(wqe_si, &cmdwqe->gen_req.wge_ctl, 1);
11008 bf_set(wqe_la, &cmdwqe->gen_req.wge_ctl, 1);
11011 bf_set(wqe_ctxt_tag, &cmdwqe->gen_req.wqe_com, rpi);
11014 bf_set(wqe_tmo, &cmdwqe->gen_req.wqe_com, tmo);
11015 bf_set(wqe_class, &cmdwqe->gen_req.wqe_com, CLASS3);
11016 bf_set(wqe_cmnd, &cmdwqe->gen_req.wqe_com, CMD_GEN_REQUEST64_CR);
11017 bf_set(wqe_ct, &cmdwqe->gen_req.wqe_com, SLI4_CT_RPI);
11020 cmdwqe->gen_req.max_response_payload_len = total_len - xmit_len;
11024 lpfc_sli_prep_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
11025 struct lpfc_dmabuf *bmp, u16 rpi, u32 num_entry, u8 tmo)
11027 phba->__lpfc_sli_prep_gen_req(cmdiocbq, bmp, rpi, num_entry, tmo);
11031 __lpfc_sli_prep_xmit_seq64_s3(struct lpfc_iocbq *cmdiocbq,
11032 struct lpfc_dmabuf *bmp, u16 rpi, u16 ox_id,
11033 u32 num_entry, u8 rctl, u8 last_seq, u8 cr_cx_cmd)
11037 icmd = &cmdiocbq->iocb;
11038 memset(icmd, 0, sizeof(*icmd));
11040 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
11041 icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys);
11042 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
11043 icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
11044 icmd->un.xseq64.w5.hcsw.Fctl = LA;
11046 icmd->un.xseq64.w5.hcsw.Fctl |= LS;
11047 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
11048 icmd->un.xseq64.w5.hcsw.Rctl = rctl;
11049 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
11051 icmd->ulpBdeCount = 1;
11053 icmd->ulpClass = CLASS3;
11055 switch (cr_cx_cmd) {
11056 case CMD_XMIT_SEQUENCE64_CR:
11057 icmd->ulpContext = rpi;
11058 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR;
11060 case CMD_XMIT_SEQUENCE64_CX:
11061 icmd->ulpContext = ox_id;
11062 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
11070 __lpfc_sli_prep_xmit_seq64_s4(struct lpfc_iocbq *cmdiocbq,
11071 struct lpfc_dmabuf *bmp, u16 rpi, u16 ox_id,
11072 u32 full_size, u8 rctl, u8 last_seq, u8 cr_cx_cmd)
11074 union lpfc_wqe128 *wqe;
11075 struct ulp_bde64 *bpl;
11077 wqe = &cmdiocbq->wqe;
11078 memset(wqe, 0, sizeof(*wqe));
11081 bpl = (struct ulp_bde64 *)bmp->virt;
11082 wqe->xmit_sequence.bde.addrHigh = bpl->addrHigh;
11083 wqe->xmit_sequence.bde.addrLow = bpl->addrLow;
11084 wqe->xmit_sequence.bde.tus.w = bpl->tus.w;
11087 bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, last_seq);
11088 bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 1);
11089 bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0);
11090 bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, rctl);
11091 bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_CT);
11094 bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, rpi);
11096 bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com,
11097 CMD_XMIT_SEQUENCE64_WQE);
11100 bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3);
11103 bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ox_id);
11106 if (cmdiocbq->cmd_flag & (LPFC_IO_LIBDFC | LPFC_IO_LOOPBACK))
11107 wqe->xmit_sequence.xmit_len = full_size;
11109 wqe->xmit_sequence.xmit_len =
11110 wqe->xmit_sequence.bde.tus.f.bdeSize;
11114 lpfc_sli_prep_xmit_seq64(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
11115 struct lpfc_dmabuf *bmp, u16 rpi, u16 ox_id,
11116 u32 num_entry, u8 rctl, u8 last_seq, u8 cr_cx_cmd)
11118 phba->__lpfc_sli_prep_xmit_seq64(cmdiocbq, bmp, rpi, ox_id, num_entry,
11119 rctl, last_seq, cr_cx_cmd);
11123 __lpfc_sli_prep_abort_xri_s3(struct lpfc_iocbq *cmdiocbq, u16 ulp_context,
11124 u16 iotag, u8 ulp_class, u16 cqid, bool ia,
11127 IOCB_t *icmd = NULL;
11129 icmd = &cmdiocbq->iocb;
11130 memset(icmd, 0, sizeof(*icmd));
11133 icmd->un.acxri.abortContextTag = ulp_context;
11134 icmd->un.acxri.abortIoTag = iotag;
11138 icmd->ulpCommand = CMD_CLOSE_XRI_CN;
11141 icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
11144 icmd->ulpClass = ulp_class;
11145 icmd->ulpCommand = CMD_ABORT_XRI_CN;
11153 __lpfc_sli_prep_abort_xri_s4(struct lpfc_iocbq *cmdiocbq, u16 ulp_context,
11154 u16 iotag, u8 ulp_class, u16 cqid, bool ia,
11157 union lpfc_wqe128 *wqe;
11159 wqe = &cmdiocbq->wqe;
11160 memset(wqe, 0, sizeof(*wqe));
11163 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
11165 bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
11167 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
11170 bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_WQE);
11173 wqe->abort_cmd.wqe_com.abort_tag = ulp_context;
11176 bf_set(wqe_reqtag, &wqe->abort_cmd.wqe_com, iotag);
11179 bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
11183 bf_set(wqe_wqec, &wqe->abort_cmd.wqe_com, 1);
11184 bf_set(wqe_cqid, &wqe->abort_cmd.wqe_com, cqid);
11185 bf_set(wqe_cmd_type, &wqe->abort_cmd.wqe_com, OTHER_COMMAND);
11189 lpfc_sli_prep_abort_xri(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
11190 u16 ulp_context, u16 iotag, u8 ulp_class, u16 cqid,
11191 bool ia, bool wqec)
11193 phba->__lpfc_sli_prep_abort_xri(cmdiocbq, ulp_context, iotag, ulp_class,
11198 * lpfc_sli_api_table_setup - Set up sli api function jump table
11199 * @phba: The hba struct for which this call is being executed.
11200 * @dev_grp: The HBA PCI-Device group number.
11202 * This routine sets up the SLI interface API function jump table in @phba
11204 * Returns: 0 - success, -ENODEV - failure.
11207 lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
11211 case LPFC_PCI_DEV_LP:
11212 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
11213 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
11214 phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s3;
11215 phba->__lpfc_sli_prep_els_req_rsp = __lpfc_sli_prep_els_req_rsp_s3;
11216 phba->__lpfc_sli_prep_gen_req = __lpfc_sli_prep_gen_req_s3;
11217 phba->__lpfc_sli_prep_xmit_seq64 = __lpfc_sli_prep_xmit_seq64_s3;
11218 phba->__lpfc_sli_prep_abort_xri = __lpfc_sli_prep_abort_xri_s3;
11220 case LPFC_PCI_DEV_OC:
11221 phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
11222 phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
11223 phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s4;
11224 phba->__lpfc_sli_prep_els_req_rsp = __lpfc_sli_prep_els_req_rsp_s4;
11225 phba->__lpfc_sli_prep_gen_req = __lpfc_sli_prep_gen_req_s4;
11226 phba->__lpfc_sli_prep_xmit_seq64 = __lpfc_sli_prep_xmit_seq64_s4;
11227 phba->__lpfc_sli_prep_abort_xri = __lpfc_sli_prep_abort_xri_s4;
11230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11231 "1419 Invalid HBA PCI-device group: 0x%x\n",
11239 * lpfc_sli4_calc_ring - Calculates which ring to use
11240 * @phba: Pointer to HBA context object.
11241 * @piocb: Pointer to command iocb.
11243 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
11244 * hba_wqidx, thus we need to calculate the corresponding ring.
11245 * Since ABORTS must go on the same WQ of the command they are
11246 * aborting, we use command's hba_wqidx.
11248 struct lpfc_sli_ring *
11249 lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
11251 struct lpfc_io_buf *lpfc_cmd;
11253 if (piocb->cmd_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
11254 if (unlikely(!phba->sli4_hba.hdwq))
11257 * for abort iocb hba_wqidx should already
11258 * be setup based on what work queue we used.
11260 if (!(piocb->cmd_flag & LPFC_USE_FCPWQIDX)) {
11261 lpfc_cmd = piocb->io_buf;
11262 piocb->hba_wqidx = lpfc_cmd->hdwq_no;
11264 return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
11266 if (unlikely(!phba->sli4_hba.els_wq))
11268 piocb->hba_wqidx = 0;
11269 return phba->sli4_hba.els_wq->pring;
11273 inline void lpfc_sli4_poll_eq(struct lpfc_queue *eq)
11275 struct lpfc_hba *phba = eq->phba;
11278 * Unlocking an irq is one of the entry point to check
11279 * for re-schedule, but we are good for io submission
11280 * path as midlayer does a get_cpu to glue us in. Flush
11281 * out the invalidate queue so we can see the updated
11286 if (READ_ONCE(eq->mode) == LPFC_EQ_POLL)
11287 /* We will not likely get the completion for the caller
11288 * during this iteration but i guess that's fine.
11289 * Future io's coming on this eq should be able to
11290 * pick it up. As for the case of single io's, they
11291 * will be handled through a sched from polling timer
11292 * function which is currently triggered every 1msec.
11294 lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM);
11298 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
11299 * @phba: Pointer to HBA context object.
11300 * @ring_number: Ring number
11301 * @piocb: Pointer to command iocb.
11302 * @flag: Flag indicating if this command can be put into txq.
11304 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
11305 * function. This function gets the hbalock and calls
11306 * __lpfc_sli_issue_iocb function and will return the error returned
11307 * by __lpfc_sli_issue_iocb function. This wrapper is used by
11308 * functions which do not hold hbalock.
11311 lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
11312 struct lpfc_iocbq *piocb, uint32_t flag)
11314 struct lpfc_sli_ring *pring;
11315 struct lpfc_queue *eq;
11316 unsigned long iflags;
11319 /* If the PCI channel is in offline state, do not post iocbs. */
11320 if (unlikely(pci_channel_offline(phba->pcidev)))
11323 if (phba->sli_rev == LPFC_SLI_REV4) {
11324 lpfc_sli_prep_wqe(phba, piocb);
11326 eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq;
11328 pring = lpfc_sli4_calc_ring(phba, piocb);
11329 if (unlikely(pring == NULL))
11332 spin_lock_irqsave(&pring->ring_lock, iflags);
11333 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
11334 spin_unlock_irqrestore(&pring->ring_lock, iflags);
11336 lpfc_sli4_poll_eq(eq);
11338 /* For now, SLI2/3 will still use hbalock */
11339 spin_lock_irqsave(&phba->hbalock, iflags);
11340 rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
11341 spin_unlock_irqrestore(&phba->hbalock, iflags);
11347 * lpfc_extra_ring_setup - Extra ring setup function
11348 * @phba: Pointer to HBA context object.
11350 * This function is called while driver attaches with the
11351 * HBA to setup the extra ring. The extra ring is used
11352 * only when driver needs to support target mode functionality
11353 * or IP over FC functionalities.
11355 * This function is called with no lock held. SLI3 only.
11358 lpfc_extra_ring_setup( struct lpfc_hba *phba)
11360 struct lpfc_sli *psli;
11361 struct lpfc_sli_ring *pring;
11365 /* Adjust cmd/rsp ring iocb entries more evenly */
11367 /* Take some away from the FCP ring */
11368 pring = &psli->sli3_ring[LPFC_FCP_RING];
11369 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
11370 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
11371 pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
11372 pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
11374 /* and give them to the extra ring */
11375 pring = &psli->sli3_ring[LPFC_EXTRA_RING];
11377 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
11378 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
11379 pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
11380 pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
11382 /* Setup default profile for this ring */
11383 pring->iotag_max = 4096;
11384 pring->num_mask = 1;
11385 pring->prt[0].profile = 0; /* Mask 0 */
11386 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
11387 pring->prt[0].type = phba->cfg_multi_ring_type;
11388 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
11393 lpfc_sli_post_recovery_event(struct lpfc_hba *phba,
11394 struct lpfc_nodelist *ndlp)
11396 unsigned long iflags;
11397 struct lpfc_work_evt *evtp = &ndlp->recovery_evt;
11399 spin_lock_irqsave(&phba->hbalock, iflags);
11400 if (!list_empty(&evtp->evt_listp)) {
11401 spin_unlock_irqrestore(&phba->hbalock, iflags);
11405 /* Incrementing the reference count until the queued work is done. */
11406 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
11407 if (!evtp->evt_arg1) {
11408 spin_unlock_irqrestore(&phba->hbalock, iflags);
11411 evtp->evt = LPFC_EVT_RECOVER_PORT;
11412 list_add_tail(&evtp->evt_listp, &phba->work_list);
11413 spin_unlock_irqrestore(&phba->hbalock, iflags);
11415 lpfc_worker_wake_up(phba);
11418 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
11419 * @phba: Pointer to HBA context object.
11420 * @iocbq: Pointer to iocb object.
11422 * The async_event handler calls this routine when it receives
11423 * an ASYNC_STATUS_CN event from the port. The port generates
11424 * this event when an Abort Sequence request to an rport fails
11425 * twice in succession. The abort could be originated by the
11426 * driver or by the port. The ABTS could have been for an ELS
11427 * or FCP IO. The port only generates this event when an ABTS
11428 * fails to complete after one retry.
11431 lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
11432 struct lpfc_iocbq *iocbq)
11434 struct lpfc_nodelist *ndlp = NULL;
11435 uint16_t rpi = 0, vpi = 0;
11436 struct lpfc_vport *vport = NULL;
11438 /* The rpi in the ulpContext is vport-sensitive. */
11439 vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
11440 rpi = iocbq->iocb.ulpContext;
11442 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11443 "3092 Port generated ABTS async event "
11444 "on vpi %d rpi %d status 0x%x\n",
11445 vpi, rpi, iocbq->iocb.ulpStatus);
11447 vport = lpfc_find_vport_by_vpid(phba, vpi);
11450 ndlp = lpfc_findnode_rpi(vport, rpi);
11454 if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
11455 lpfc_sli_abts_recover_port(vport, ndlp);
11459 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11460 "3095 Event Context not found, no "
11461 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
11462 vpi, rpi, iocbq->iocb.ulpStatus,
11463 iocbq->iocb.ulpContext);
11466 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
11467 * @phba: pointer to HBA context object.
11468 * @ndlp: nodelist pointer for the impacted rport.
11469 * @axri: pointer to the wcqe containing the failed exchange.
11471 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
11472 * port. The port generates this event when an abort exchange request to an
11473 * rport fails twice in succession with no reply. The abort could be originated
11474 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
11477 lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
11478 struct lpfc_nodelist *ndlp,
11479 struct sli4_wcqe_xri_aborted *axri)
11481 uint32_t ext_status = 0;
11484 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
11485 "3115 Node Context not found, driver "
11486 "ignoring abts err event\n");
11490 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
11491 "3116 Port generated FCP XRI ABORT event on "
11492 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
11493 ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
11494 bf_get(lpfc_wcqe_xa_xri, axri),
11495 bf_get(lpfc_wcqe_xa_status, axri),
11499 * Catch the ABTS protocol failure case. Older OCe FW releases returned
11500 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
11501 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
11503 ext_status = axri->parameter & IOERR_PARAM_MASK;
11504 if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
11505 ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
11506 lpfc_sli_post_recovery_event(phba, ndlp);
11510 * lpfc_sli_async_event_handler - ASYNC iocb handler function
11511 * @phba: Pointer to HBA context object.
11512 * @pring: Pointer to driver SLI ring object.
11513 * @iocbq: Pointer to iocb object.
11515 * This function is called by the slow ring event handler
11516 * function when there is an ASYNC event iocb in the ring.
11517 * This function is called with no lock held.
11518 * Currently this function handles only temperature related
11519 * ASYNC events. The function decodes the temperature sensor
11520 * event message and posts events for the management applications.
11523 lpfc_sli_async_event_handler(struct lpfc_hba * phba,
11524 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
11528 struct temp_event temp_event_data;
11529 struct Scsi_Host *shost;
11532 icmd = &iocbq->iocb;
11533 evt_code = icmd->un.asyncstat.evt_code;
11535 switch (evt_code) {
11536 case ASYNC_TEMP_WARN:
11537 case ASYNC_TEMP_SAFE:
11538 temp_event_data.data = (uint32_t) icmd->ulpContext;
11539 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
11540 if (evt_code == ASYNC_TEMP_WARN) {
11541 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
11542 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11543 "0347 Adapter is very hot, please take "
11544 "corrective action. temperature : %d Celsius\n",
11545 (uint32_t) icmd->ulpContext);
11547 temp_event_data.event_code = LPFC_NORMAL_TEMP;
11548 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11549 "0340 Adapter temperature is OK now. "
11550 "temperature : %d Celsius\n",
11551 (uint32_t) icmd->ulpContext);
11554 /* Send temperature change event to applications */
11555 shost = lpfc_shost_from_vport(phba->pport);
11556 fc_host_post_vendor_event(shost, fc_get_event_number(),
11557 sizeof(temp_event_data), (char *) &temp_event_data,
11558 LPFC_NL_VENDOR_ID);
11560 case ASYNC_STATUS_CN:
11561 lpfc_sli_abts_err_handler(phba, iocbq);
11564 iocb_w = (uint32_t *) icmd;
11565 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
11566 "0346 Ring %d handler: unexpected ASYNC_STATUS"
11568 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
11569 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
11570 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
11571 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
11572 pring->ringno, icmd->un.asyncstat.evt_code,
11573 iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
11574 iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
11575 iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
11576 iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
11584 * lpfc_sli4_setup - SLI ring setup function
11585 * @phba: Pointer to HBA context object.
11587 * lpfc_sli_setup sets up rings of the SLI interface with
11588 * number of iocbs per ring and iotags. This function is
11589 * called while driver attach to the HBA and before the
11590 * interrupts are enabled. So there is no need for locking.
11592 * This function always returns 0.
11595 lpfc_sli4_setup(struct lpfc_hba *phba)
11597 struct lpfc_sli_ring *pring;
11599 pring = phba->sli4_hba.els_wq->pring;
11600 pring->num_mask = LPFC_MAX_RING_MASK;
11601 pring->prt[0].profile = 0; /* Mask 0 */
11602 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
11603 pring->prt[0].type = FC_TYPE_ELS;
11604 pring->prt[0].lpfc_sli_rcv_unsol_event =
11605 lpfc_els_unsol_event;
11606 pring->prt[1].profile = 0; /* Mask 1 */
11607 pring->prt[1].rctl = FC_RCTL_ELS_REP;
11608 pring->prt[1].type = FC_TYPE_ELS;
11609 pring->prt[1].lpfc_sli_rcv_unsol_event =
11610 lpfc_els_unsol_event;
11611 pring->prt[2].profile = 0; /* Mask 2 */
11612 /* NameServer Inquiry */
11613 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
11615 pring->prt[2].type = FC_TYPE_CT;
11616 pring->prt[2].lpfc_sli_rcv_unsol_event =
11617 lpfc_ct_unsol_event;
11618 pring->prt[3].profile = 0; /* Mask 3 */
11619 /* NameServer response */
11620 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
11622 pring->prt[3].type = FC_TYPE_CT;
11623 pring->prt[3].lpfc_sli_rcv_unsol_event =
11624 lpfc_ct_unsol_event;
11629 * lpfc_sli_setup - SLI ring setup function
11630 * @phba: Pointer to HBA context object.
11632 * lpfc_sli_setup sets up rings of the SLI interface with
11633 * number of iocbs per ring and iotags. This function is
11634 * called while driver attach to the HBA and before the
11635 * interrupts are enabled. So there is no need for locking.
11637 * This function always returns 0. SLI3 only.
11640 lpfc_sli_setup(struct lpfc_hba *phba)
11642 int i, totiocbsize = 0;
11643 struct lpfc_sli *psli = &phba->sli;
11644 struct lpfc_sli_ring *pring;
11646 psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
11647 psli->sli_flag = 0;
11649 psli->iocbq_lookup = NULL;
11650 psli->iocbq_lookup_len = 0;
11651 psli->last_iotag = 0;
11653 for (i = 0; i < psli->num_rings; i++) {
11654 pring = &psli->sli3_ring[i];
11656 case LPFC_FCP_RING: /* ring 0 - FCP */
11657 /* numCiocb and numRiocb are used in config_port */
11658 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
11659 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
11660 pring->sli.sli3.numCiocb +=
11661 SLI2_IOCB_CMD_R1XTRA_ENTRIES;
11662 pring->sli.sli3.numRiocb +=
11663 SLI2_IOCB_RSP_R1XTRA_ENTRIES;
11664 pring->sli.sli3.numCiocb +=
11665 SLI2_IOCB_CMD_R3XTRA_ENTRIES;
11666 pring->sli.sli3.numRiocb +=
11667 SLI2_IOCB_RSP_R3XTRA_ENTRIES;
11668 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
11669 SLI3_IOCB_CMD_SIZE :
11670 SLI2_IOCB_CMD_SIZE;
11671 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
11672 SLI3_IOCB_RSP_SIZE :
11673 SLI2_IOCB_RSP_SIZE;
11674 pring->iotag_ctr = 0;
11676 (phba->cfg_hba_queue_depth * 2);
11677 pring->fast_iotag = pring->iotag_max;
11678 pring->num_mask = 0;
11680 case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
11681 /* numCiocb and numRiocb are used in config_port */
11682 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
11683 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
11684 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
11685 SLI3_IOCB_CMD_SIZE :
11686 SLI2_IOCB_CMD_SIZE;
11687 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
11688 SLI3_IOCB_RSP_SIZE :
11689 SLI2_IOCB_RSP_SIZE;
11690 pring->iotag_max = phba->cfg_hba_queue_depth;
11691 pring->num_mask = 0;
11693 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
11694 /* numCiocb and numRiocb are used in config_port */
11695 pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
11696 pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
11697 pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
11698 SLI3_IOCB_CMD_SIZE :
11699 SLI2_IOCB_CMD_SIZE;
11700 pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
11701 SLI3_IOCB_RSP_SIZE :
11702 SLI2_IOCB_RSP_SIZE;
11703 pring->fast_iotag = 0;
11704 pring->iotag_ctr = 0;
11705 pring->iotag_max = 4096;
11706 pring->lpfc_sli_rcv_async_status =
11707 lpfc_sli_async_event_handler;
11708 pring->num_mask = LPFC_MAX_RING_MASK;
11709 pring->prt[0].profile = 0; /* Mask 0 */
11710 pring->prt[0].rctl = FC_RCTL_ELS_REQ;
11711 pring->prt[0].type = FC_TYPE_ELS;
11712 pring->prt[0].lpfc_sli_rcv_unsol_event =
11713 lpfc_els_unsol_event;
11714 pring->prt[1].profile = 0; /* Mask 1 */
11715 pring->prt[1].rctl = FC_RCTL_ELS_REP;
11716 pring->prt[1].type = FC_TYPE_ELS;
11717 pring->prt[1].lpfc_sli_rcv_unsol_event =
11718 lpfc_els_unsol_event;
11719 pring->prt[2].profile = 0; /* Mask 2 */
11720 /* NameServer Inquiry */
11721 pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
11723 pring->prt[2].type = FC_TYPE_CT;
11724 pring->prt[2].lpfc_sli_rcv_unsol_event =
11725 lpfc_ct_unsol_event;
11726 pring->prt[3].profile = 0; /* Mask 3 */
11727 /* NameServer response */
11728 pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
11730 pring->prt[3].type = FC_TYPE_CT;
11731 pring->prt[3].lpfc_sli_rcv_unsol_event =
11732 lpfc_ct_unsol_event;
11735 totiocbsize += (pring->sli.sli3.numCiocb *
11736 pring->sli.sli3.sizeCiocb) +
11737 (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
11739 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
11740 /* Too many cmd / rsp ring entries in SLI2 SLIM */
11741 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
11742 "SLI2 SLIM Data: x%x x%lx\n",
11743 phba->brd_no, totiocbsize,
11744 (unsigned long) MAX_SLIM_IOCB_SIZE);
11746 if (phba->cfg_multi_ring_support == 2)
11747 lpfc_extra_ring_setup(phba);
11753 * lpfc_sli4_queue_init - Queue initialization function
11754 * @phba: Pointer to HBA context object.
11756 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
11757 * ring. This function also initializes ring indices of each ring.
11758 * This function is called during the initialization of the SLI
11759 * interface of an HBA.
11760 * This function is called with no lock held and always returns
11764 lpfc_sli4_queue_init(struct lpfc_hba *phba)
11766 struct lpfc_sli *psli;
11767 struct lpfc_sli_ring *pring;
11771 spin_lock_irq(&phba->hbalock);
11772 INIT_LIST_HEAD(&psli->mboxq);
11773 INIT_LIST_HEAD(&psli->mboxq_cmpl);
11774 /* Initialize list headers for txq and txcmplq as double linked lists */
11775 for (i = 0; i < phba->cfg_hdw_queue; i++) {
11776 pring = phba->sli4_hba.hdwq[i].io_wq->pring;
11778 pring->ringno = LPFC_FCP_RING;
11779 pring->txcmplq_cnt = 0;
11780 INIT_LIST_HEAD(&pring->txq);
11781 INIT_LIST_HEAD(&pring->txcmplq);
11782 INIT_LIST_HEAD(&pring->iocb_continueq);
11783 spin_lock_init(&pring->ring_lock);
11785 pring = phba->sli4_hba.els_wq->pring;
11787 pring->ringno = LPFC_ELS_RING;
11788 pring->txcmplq_cnt = 0;
11789 INIT_LIST_HEAD(&pring->txq);
11790 INIT_LIST_HEAD(&pring->txcmplq);
11791 INIT_LIST_HEAD(&pring->iocb_continueq);
11792 spin_lock_init(&pring->ring_lock);
11794 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
11795 pring = phba->sli4_hba.nvmels_wq->pring;
11797 pring->ringno = LPFC_ELS_RING;
11798 pring->txcmplq_cnt = 0;
11799 INIT_LIST_HEAD(&pring->txq);
11800 INIT_LIST_HEAD(&pring->txcmplq);
11801 INIT_LIST_HEAD(&pring->iocb_continueq);
11802 spin_lock_init(&pring->ring_lock);
11805 spin_unlock_irq(&phba->hbalock);
11809 * lpfc_sli_queue_init - Queue initialization function
11810 * @phba: Pointer to HBA context object.
11812 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
11813 * ring. This function also initializes ring indices of each ring.
11814 * This function is called during the initialization of the SLI
11815 * interface of an HBA.
11816 * This function is called with no lock held and always returns
11820 lpfc_sli_queue_init(struct lpfc_hba *phba)
11822 struct lpfc_sli *psli;
11823 struct lpfc_sli_ring *pring;
11827 spin_lock_irq(&phba->hbalock);
11828 INIT_LIST_HEAD(&psli->mboxq);
11829 INIT_LIST_HEAD(&psli->mboxq_cmpl);
11830 /* Initialize list headers for txq and txcmplq as double linked lists */
11831 for (i = 0; i < psli->num_rings; i++) {
11832 pring = &psli->sli3_ring[i];
11834 pring->sli.sli3.next_cmdidx = 0;
11835 pring->sli.sli3.local_getidx = 0;
11836 pring->sli.sli3.cmdidx = 0;
11837 INIT_LIST_HEAD(&pring->iocb_continueq);
11838 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
11839 INIT_LIST_HEAD(&pring->postbufq);
11841 INIT_LIST_HEAD(&pring->txq);
11842 INIT_LIST_HEAD(&pring->txcmplq);
11843 spin_lock_init(&pring->ring_lock);
11845 spin_unlock_irq(&phba->hbalock);
11849 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
11850 * @phba: Pointer to HBA context object.
11852 * This routine flushes the mailbox command subsystem. It will unconditionally
11853 * flush all the mailbox commands in the three possible stages in the mailbox
11854 * command sub-system: pending mailbox command queue; the outstanding mailbox
11855 * command; and completed mailbox command queue. It is caller's responsibility
11856 * to make sure that the driver is in the proper state to flush the mailbox
11857 * command sub-system. Namely, the posting of mailbox commands into the
11858 * pending mailbox command queue from the various clients must be stopped;
11859 * either the HBA is in a state that it will never works on the outstanding
11860 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
11861 * mailbox command has been completed.
11864 lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
11866 LIST_HEAD(completions);
11867 struct lpfc_sli *psli = &phba->sli;
11869 unsigned long iflag;
11871 /* Disable softirqs, including timers from obtaining phba->hbalock */
11872 local_bh_disable();
11874 /* Flush all the mailbox commands in the mbox system */
11875 spin_lock_irqsave(&phba->hbalock, iflag);
11877 /* The pending mailbox command queue */
11878 list_splice_init(&phba->sli.mboxq, &completions);
11879 /* The outstanding active mailbox command */
11880 if (psli->mbox_active) {
11881 list_add_tail(&psli->mbox_active->list, &completions);
11882 psli->mbox_active = NULL;
11883 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
11885 /* The completed mailbox command queue */
11886 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
11887 spin_unlock_irqrestore(&phba->hbalock, iflag);
11889 /* Enable softirqs again, done with phba->hbalock */
11892 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
11893 while (!list_empty(&completions)) {
11894 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
11895 pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
11896 if (pmb->mbox_cmpl)
11897 pmb->mbox_cmpl(phba, pmb);
11902 * lpfc_sli_host_down - Vport cleanup function
11903 * @vport: Pointer to virtual port object.
11905 * lpfc_sli_host_down is called to clean up the resources
11906 * associated with a vport before destroying virtual
11907 * port data structures.
11908 * This function does following operations:
11909 * - Free discovery resources associated with this virtual
11911 * - Free iocbs associated with this virtual port in
11913 * - Send abort for all iocb commands associated with this
11914 * vport in txcmplq.
11916 * This function is called with no lock held and always returns 1.
11919 lpfc_sli_host_down(struct lpfc_vport *vport)
11921 LIST_HEAD(completions);
11922 struct lpfc_hba *phba = vport->phba;
11923 struct lpfc_sli *psli = &phba->sli;
11924 struct lpfc_queue *qp = NULL;
11925 struct lpfc_sli_ring *pring;
11926 struct lpfc_iocbq *iocb, *next_iocb;
11928 unsigned long flags = 0;
11929 uint16_t prev_pring_flag;
11931 lpfc_cleanup_discovery_resources(vport);
11933 spin_lock_irqsave(&phba->hbalock, flags);
11936 * Error everything on the txq since these iocbs
11937 * have not been given to the FW yet.
11938 * Also issue ABTS for everything on the txcmplq
11940 if (phba->sli_rev != LPFC_SLI_REV4) {
11941 for (i = 0; i < psli->num_rings; i++) {
11942 pring = &psli->sli3_ring[i];
11943 prev_pring_flag = pring->flag;
11944 /* Only slow rings */
11945 if (pring->ringno == LPFC_ELS_RING) {
11946 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11947 /* Set the lpfc data pending flag */
11948 set_bit(LPFC_DATA_READY, &phba->data_flags);
11950 list_for_each_entry_safe(iocb, next_iocb,
11951 &pring->txq, list) {
11952 if (iocb->vport != vport)
11954 list_move_tail(&iocb->list, &completions);
11956 list_for_each_entry_safe(iocb, next_iocb,
11957 &pring->txcmplq, list) {
11958 if (iocb->vport != vport)
11960 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
11963 pring->flag = prev_pring_flag;
11966 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
11970 if (pring == phba->sli4_hba.els_wq->pring) {
11971 pring->flag |= LPFC_DEFERRED_RING_EVENT;
11972 /* Set the lpfc data pending flag */
11973 set_bit(LPFC_DATA_READY, &phba->data_flags);
11975 prev_pring_flag = pring->flag;
11976 spin_lock(&pring->ring_lock);
11977 list_for_each_entry_safe(iocb, next_iocb,
11978 &pring->txq, list) {
11979 if (iocb->vport != vport)
11981 list_move_tail(&iocb->list, &completions);
11983 spin_unlock(&pring->ring_lock);
11984 list_for_each_entry_safe(iocb, next_iocb,
11985 &pring->txcmplq, list) {
11986 if (iocb->vport != vport)
11988 lpfc_sli_issue_abort_iotag(phba, pring, iocb,
11991 pring->flag = prev_pring_flag;
11994 spin_unlock_irqrestore(&phba->hbalock, flags);
11996 /* Make sure HBA is alive */
11997 lpfc_issue_hb_tmo(phba);
11999 /* Cancel all the IOCBs from the completions list */
12000 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
12006 * lpfc_sli_hba_down - Resource cleanup function for the HBA
12007 * @phba: Pointer to HBA context object.
12009 * This function cleans up all iocb, buffers, mailbox commands
12010 * while shutting down the HBA. This function is called with no
12011 * lock held and always returns 1.
12012 * This function does the following to cleanup driver resources:
12013 * - Free discovery resources for each virtual port
12014 * - Cleanup any pending fabric iocbs
12015 * - Iterate through the iocb txq and free each entry
12017 * - Free up any buffer posted to the HBA
12018 * - Free mailbox commands in the mailbox queue.
12021 lpfc_sli_hba_down(struct lpfc_hba *phba)
12023 LIST_HEAD(completions);
12024 struct lpfc_sli *psli = &phba->sli;
12025 struct lpfc_queue *qp = NULL;
12026 struct lpfc_sli_ring *pring;
12027 struct lpfc_dmabuf *buf_ptr;
12028 unsigned long flags = 0;
12031 /* Shutdown the mailbox command sub-system */
12032 lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
12034 lpfc_hba_down_prep(phba);
12036 /* Disable softirqs, including timers from obtaining phba->hbalock */
12037 local_bh_disable();
12039 lpfc_fabric_abort_hba(phba);
12041 spin_lock_irqsave(&phba->hbalock, flags);
12044 * Error everything on the txq since these iocbs
12045 * have not been given to the FW yet.
12047 if (phba->sli_rev != LPFC_SLI_REV4) {
12048 for (i = 0; i < psli->num_rings; i++) {
12049 pring = &psli->sli3_ring[i];
12050 /* Only slow rings */
12051 if (pring->ringno == LPFC_ELS_RING) {
12052 pring->flag |= LPFC_DEFERRED_RING_EVENT;
12053 /* Set the lpfc data pending flag */
12054 set_bit(LPFC_DATA_READY, &phba->data_flags);
12056 list_splice_init(&pring->txq, &completions);
12059 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
12063 spin_lock(&pring->ring_lock);
12064 list_splice_init(&pring->txq, &completions);
12065 spin_unlock(&pring->ring_lock);
12066 if (pring == phba->sli4_hba.els_wq->pring) {
12067 pring->flag |= LPFC_DEFERRED_RING_EVENT;
12068 /* Set the lpfc data pending flag */
12069 set_bit(LPFC_DATA_READY, &phba->data_flags);
12073 spin_unlock_irqrestore(&phba->hbalock, flags);
12075 /* Cancel all the IOCBs from the completions list */
12076 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
12079 spin_lock_irqsave(&phba->hbalock, flags);
12080 list_splice_init(&phba->elsbuf, &completions);
12081 phba->elsbuf_cnt = 0;
12082 phba->elsbuf_prev_cnt = 0;
12083 spin_unlock_irqrestore(&phba->hbalock, flags);
12085 while (!list_empty(&completions)) {
12086 list_remove_head(&completions, buf_ptr,
12087 struct lpfc_dmabuf, list);
12088 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
12092 /* Enable softirqs again, done with phba->hbalock */
12095 /* Return any active mbox cmds */
12096 del_timer_sync(&psli->mbox_tmo);
12098 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
12099 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
12100 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
12106 * lpfc_sli_pcimem_bcopy - SLI memory copy function
12107 * @srcp: Source memory pointer.
12108 * @destp: Destination memory pointer.
12109 * @cnt: Number of words required to be copied.
12111 * This function is used for copying data between driver memory
12112 * and the SLI memory. This function also changes the endianness
12113 * of each word if native endianness is different from SLI
12114 * endianness. This function can be called with or without
12118 lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
12120 uint32_t *src = srcp;
12121 uint32_t *dest = destp;
12125 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
12127 ldata = le32_to_cpu(ldata);
12136 * lpfc_sli_bemem_bcopy - SLI memory copy function
12137 * @srcp: Source memory pointer.
12138 * @destp: Destination memory pointer.
12139 * @cnt: Number of words required to be copied.
12141 * This function is used for copying data between a data structure
12142 * with big endian representation to local endianness.
12143 * This function can be called with or without lock.
12146 lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
12148 uint32_t *src = srcp;
12149 uint32_t *dest = destp;
12153 for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
12155 ldata = be32_to_cpu(ldata);
12163 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
12164 * @phba: Pointer to HBA context object.
12165 * @pring: Pointer to driver SLI ring object.
12166 * @mp: Pointer to driver buffer object.
12168 * This function is called with no lock held.
12169 * It always return zero after adding the buffer to the postbufq
12173 lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12174 struct lpfc_dmabuf *mp)
12176 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
12178 spin_lock_irq(&phba->hbalock);
12179 list_add_tail(&mp->list, &pring->postbufq);
12180 pring->postbufq_cnt++;
12181 spin_unlock_irq(&phba->hbalock);
12186 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
12187 * @phba: Pointer to HBA context object.
12189 * When HBQ is enabled, buffers are searched based on tags. This function
12190 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
12191 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
12192 * does not conflict with tags of buffer posted for unsolicited events.
12193 * The function returns the allocated tag. The function is called with
12197 lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
12199 spin_lock_irq(&phba->hbalock);
12200 phba->buffer_tag_count++;
12202 * Always set the QUE_BUFTAG_BIT to distiguish between
12203 * a tag assigned by HBQ.
12205 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
12206 spin_unlock_irq(&phba->hbalock);
12207 return phba->buffer_tag_count;
12211 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
12212 * @phba: Pointer to HBA context object.
12213 * @pring: Pointer to driver SLI ring object.
12214 * @tag: Buffer tag.
12216 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
12217 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
12218 * iocb is posted to the response ring with the tag of the buffer.
12219 * This function searches the pring->postbufq list using the tag
12220 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
12221 * iocb. If the buffer is found then lpfc_dmabuf object of the
12222 * buffer is returned to the caller else NULL is returned.
12223 * This function is called with no lock held.
12225 struct lpfc_dmabuf *
12226 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12229 struct lpfc_dmabuf *mp, *next_mp;
12230 struct list_head *slp = &pring->postbufq;
12232 /* Search postbufq, from the beginning, looking for a match on tag */
12233 spin_lock_irq(&phba->hbalock);
12234 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
12235 if (mp->buffer_tag == tag) {
12236 list_del_init(&mp->list);
12237 pring->postbufq_cnt--;
12238 spin_unlock_irq(&phba->hbalock);
12243 spin_unlock_irq(&phba->hbalock);
12244 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12245 "0402 Cannot find virtual addr for buffer tag on "
12246 "ring %d Data x%lx x%px x%px x%x\n",
12247 pring->ringno, (unsigned long) tag,
12248 slp->next, slp->prev, pring->postbufq_cnt);
12254 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
12255 * @phba: Pointer to HBA context object.
12256 * @pring: Pointer to driver SLI ring object.
12257 * @phys: DMA address of the buffer.
12259 * This function searches the buffer list using the dma_address
12260 * of unsolicited event to find the driver's lpfc_dmabuf object
12261 * corresponding to the dma_address. The function returns the
12262 * lpfc_dmabuf object if a buffer is found else it returns NULL.
12263 * This function is called by the ct and els unsolicited event
12264 * handlers to get the buffer associated with the unsolicited
12267 * This function is called with no lock held.
12269 struct lpfc_dmabuf *
12270 lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12273 struct lpfc_dmabuf *mp, *next_mp;
12274 struct list_head *slp = &pring->postbufq;
12276 /* Search postbufq, from the beginning, looking for a match on phys */
12277 spin_lock_irq(&phba->hbalock);
12278 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
12279 if (mp->phys == phys) {
12280 list_del_init(&mp->list);
12281 pring->postbufq_cnt--;
12282 spin_unlock_irq(&phba->hbalock);
12287 spin_unlock_irq(&phba->hbalock);
12288 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
12289 "0410 Cannot find virtual addr for mapped buf on "
12290 "ring %d Data x%llx x%px x%px x%x\n",
12291 pring->ringno, (unsigned long long)phys,
12292 slp->next, slp->prev, pring->postbufq_cnt);
12297 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
12298 * @phba: Pointer to HBA context object.
12299 * @cmdiocb: Pointer to driver command iocb object.
12300 * @rspiocb: Pointer to driver response iocb object.
12302 * This function is the completion handler for the abort iocbs for
12303 * ELS commands. This function is called from the ELS ring event
12304 * handler with no lock held. This function frees memory resources
12305 * associated with the abort iocb.
12308 lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12309 struct lpfc_iocbq *rspiocb)
12311 u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
12312 u32 ulp_word4 = get_job_word4(phba, rspiocb);
12313 u8 cmnd = get_job_cmnd(phba, cmdiocb);
12317 * Assume that the port already completed and returned, or
12318 * will return the iocb. Just Log the message.
12320 if (phba->sli_rev < LPFC_SLI_REV4) {
12321 if (cmnd == CMD_ABORT_XRI_CX &&
12322 ulp_status == IOSTAT_LOCAL_REJECT &&
12323 ulp_word4 == IOERR_ABORT_REQUESTED) {
12328 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
12329 "0327 Cannot abort els iocb x%px "
12330 "with io cmd xri %x abort tag : x%x, "
12331 "abort status %x abort code %x\n",
12332 cmdiocb, get_job_abtsiotag(phba, cmdiocb),
12333 (phba->sli_rev == LPFC_SLI_REV4) ?
12334 get_wqe_reqtag(cmdiocb) :
12335 cmdiocb->iocb.un.acxri.abortContextTag,
12336 ulp_status, ulp_word4);
12340 lpfc_sli_release_iocbq(phba, cmdiocb);
12345 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
12346 * @phba: Pointer to HBA context object.
12347 * @cmdiocb: Pointer to driver command iocb object.
12348 * @rspiocb: Pointer to driver response iocb object.
12350 * The function is called from SLI ring event handler with no
12351 * lock held. This function is the completion handler for ELS commands
12352 * which are aborted. The function frees memory resources used for
12353 * the aborted ELS commands.
12356 lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12357 struct lpfc_iocbq *rspiocb)
12359 struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
12361 LPFC_MBOXQ_t *mbox;
12362 u32 ulp_command, ulp_status, ulp_word4, iotag;
12364 ulp_command = get_job_cmnd(phba, cmdiocb);
12365 ulp_status = get_job_ulpstatus(phba, rspiocb);
12366 ulp_word4 = get_job_word4(phba, rspiocb);
12368 if (phba->sli_rev == LPFC_SLI_REV4) {
12369 iotag = get_wqe_reqtag(cmdiocb);
12371 irsp = &rspiocb->iocb;
12372 iotag = irsp->ulpIoTag;
12374 /* It is possible a PLOGI_RJT for NPIV ports to get aborted.
12375 * The MBX_REG_LOGIN64 mbox command is freed back to the
12376 * mbox_mem_pool here.
12378 if (cmdiocb->context_un.mbox) {
12379 mbox = cmdiocb->context_un.mbox;
12380 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
12381 cmdiocb->context_un.mbox = NULL;
12385 /* ELS cmd tag <ulpIoTag> completes */
12386 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
12387 "0139 Ignoring ELS cmd code x%x completion Data: "
12388 "x%x x%x x%x x%px\n",
12389 ulp_command, ulp_status, ulp_word4, iotag,
12392 * Deref the ndlp after free_iocb. sli_release_iocb will access the ndlp
12393 * if exchange is busy.
12395 if (ulp_command == CMD_GEN_REQUEST64_CR)
12396 lpfc_ct_free_iocb(phba, cmdiocb);
12398 lpfc_els_free_iocb(phba, cmdiocb);
12400 lpfc_nlp_put(ndlp);
12404 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
12405 * @phba: Pointer to HBA context object.
12406 * @pring: Pointer to driver SLI ring object.
12407 * @cmdiocb: Pointer to driver command iocb object.
12408 * @cmpl: completion function.
12410 * This function issues an abort iocb for the provided command iocb. In case
12411 * of unloading, the abort iocb will not be issued to commands on the ELS
12412 * ring. Instead, the callback function shall be changed to those commands
12413 * so that nothing happens when them finishes. This function is called with
12414 * hbalock held andno ring_lock held (SLI4). The function returns IOCB_SUCCESS
12415 * when the command iocb is an abort request.
12419 lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
12420 struct lpfc_iocbq *cmdiocb, void *cmpl)
12422 struct lpfc_vport *vport = cmdiocb->vport;
12423 struct lpfc_iocbq *abtsiocbp;
12424 int retval = IOCB_ERROR;
12425 unsigned long iflags;
12426 struct lpfc_nodelist *ndlp = NULL;
12427 u32 ulp_command = get_job_cmnd(phba, cmdiocb);
12428 u16 ulp_context, iotag;
12432 * There are certain command types we don't want to abort. And we
12433 * don't want to abort commands that are already in the process of
12436 if (ulp_command == CMD_ABORT_XRI_WQE ||
12437 ulp_command == CMD_ABORT_XRI_CN ||
12438 ulp_command == CMD_CLOSE_XRI_CN ||
12439 cmdiocb->cmd_flag & LPFC_DRIVER_ABORTED)
12440 return IOCB_ABORTING;
12443 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC)
12444 cmdiocb->fabric_cmd_cmpl = lpfc_ignore_els_cmpl;
12446 cmdiocb->cmd_cmpl = lpfc_ignore_els_cmpl;
12451 * If we're unloading, don't abort iocb on the ELS ring, but change
12452 * the callback so that nothing happens when it finishes.
12454 if ((vport->load_flag & FC_UNLOADING) &&
12455 pring->ringno == LPFC_ELS_RING) {
12456 if (cmdiocb->cmd_flag & LPFC_IO_FABRIC)
12457 cmdiocb->fabric_cmd_cmpl = lpfc_ignore_els_cmpl;
12459 cmdiocb->cmd_cmpl = lpfc_ignore_els_cmpl;
12463 /* issue ABTS for this IOCB based on iotag */
12464 abtsiocbp = __lpfc_sli_get_iocbq(phba);
12465 if (abtsiocbp == NULL)
12466 return IOCB_NORESOURCE;
12468 /* This signals the response to set the correct status
12469 * before calling the completion handler
12471 cmdiocb->cmd_flag |= LPFC_DRIVER_ABORTED;
12473 if (phba->sli_rev == LPFC_SLI_REV4) {
12474 ulp_context = cmdiocb->sli4_xritag;
12475 iotag = abtsiocbp->iotag;
12477 iotag = cmdiocb->iocb.ulpIoTag;
12478 if (pring->ringno == LPFC_ELS_RING) {
12479 ndlp = cmdiocb->ndlp;
12480 ulp_context = ndlp->nlp_rpi;
12482 ulp_context = cmdiocb->iocb.ulpContext;
12486 if (phba->link_state < LPFC_LINK_UP ||
12487 (phba->sli_rev == LPFC_SLI_REV4 &&
12488 phba->sli4_hba.link_state.status == LPFC_FC_LA_TYPE_LINK_DOWN) ||
12489 (phba->link_flag & LS_EXTERNAL_LOOPBACK))
12494 lpfc_sli_prep_abort_xri(phba, abtsiocbp, ulp_context, iotag,
12495 cmdiocb->iocb.ulpClass,
12496 LPFC_WQE_CQ_ID_DEFAULT, ia, false);
12498 abtsiocbp->vport = vport;
12500 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
12501 abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
12502 if (cmdiocb->cmd_flag & LPFC_IO_FCP)
12503 abtsiocbp->cmd_flag |= (LPFC_IO_FCP | LPFC_USE_FCPWQIDX);
12505 if (cmdiocb->cmd_flag & LPFC_IO_FOF)
12506 abtsiocbp->cmd_flag |= LPFC_IO_FOF;
12509 abtsiocbp->cmd_cmpl = cmpl;
12511 abtsiocbp->cmd_cmpl = lpfc_sli_abort_els_cmpl;
12512 abtsiocbp->vport = vport;
12514 if (phba->sli_rev == LPFC_SLI_REV4) {
12515 pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
12516 if (unlikely(pring == NULL))
12517 goto abort_iotag_exit;
12518 /* Note: both hbalock and ring_lock need to be set here */
12519 spin_lock_irqsave(&pring->ring_lock, iflags);
12520 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
12522 spin_unlock_irqrestore(&pring->ring_lock, iflags);
12524 retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
12530 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
12531 "0339 Abort IO XRI x%x, Original iotag x%x, "
12532 "abort tag x%x Cmdjob : x%px Abortjob : x%px "
12534 ulp_context, (phba->sli_rev == LPFC_SLI_REV4) ?
12535 cmdiocb->iotag : iotag, iotag, cmdiocb, abtsiocbp,
12538 cmdiocb->cmd_flag &= ~LPFC_DRIVER_ABORTED;
12539 __lpfc_sli_release_iocbq(phba, abtsiocbp);
12543 * Caller to this routine should check for IOCB_ERROR
12544 * and handle it properly. This routine no longer removes
12545 * iocb off txcmplq and call compl in case of IOCB_ERROR.
12551 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
12552 * @phba: pointer to lpfc HBA data structure.
12554 * This routine will abort all pending and outstanding iocbs to an HBA.
12557 lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
12559 struct lpfc_sli *psli = &phba->sli;
12560 struct lpfc_sli_ring *pring;
12561 struct lpfc_queue *qp = NULL;
12564 if (phba->sli_rev != LPFC_SLI_REV4) {
12565 for (i = 0; i < psli->num_rings; i++) {
12566 pring = &psli->sli3_ring[i];
12567 lpfc_sli_abort_iocb_ring(phba, pring);
12571 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
12575 lpfc_sli_abort_iocb_ring(phba, pring);
12580 * lpfc_sli_validate_fcp_iocb_for_abort - filter iocbs appropriate for FCP aborts
12581 * @iocbq: Pointer to iocb object.
12582 * @vport: Pointer to driver virtual port object.
12584 * This function acts as an iocb filter for functions which abort FCP iocbs.
12587 * -ENODEV, if a null iocb or vport ptr is encountered
12588 * -EINVAL, if the iocb is not an FCP I/O, not on the TX cmpl queue, premarked as
12589 * driver already started the abort process, or is an abort iocb itself
12590 * 0, passes criteria for aborting the FCP I/O iocb
12593 lpfc_sli_validate_fcp_iocb_for_abort(struct lpfc_iocbq *iocbq,
12594 struct lpfc_vport *vport)
12598 /* No null ptr vports */
12599 if (!iocbq || iocbq->vport != vport)
12602 /* iocb must be for FCP IO, already exists on the TX cmpl queue,
12603 * can't be premarked as driver aborted, nor be an ABORT iocb itself
12605 ulp_command = get_job_cmnd(vport->phba, iocbq);
12606 if (!(iocbq->cmd_flag & LPFC_IO_FCP) ||
12607 !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ) ||
12608 (iocbq->cmd_flag & LPFC_DRIVER_ABORTED) ||
12609 (ulp_command == CMD_ABORT_XRI_CN ||
12610 ulp_command == CMD_CLOSE_XRI_CN ||
12611 ulp_command == CMD_ABORT_XRI_WQE))
12618 * lpfc_sli_validate_fcp_iocb - validate commands associated with a SCSI target
12619 * @iocbq: Pointer to driver iocb object.
12620 * @vport: Pointer to driver virtual port object.
12621 * @tgt_id: SCSI ID of the target.
12622 * @lun_id: LUN ID of the scsi device.
12623 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
12625 * This function acts as an iocb filter for validating a lun/SCSI target/SCSI
12629 * 0 if the filtering criteria is met for the given iocb and will return
12630 * 1 if the filtering criteria is not met.
12631 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
12632 * given iocb is for the SCSI device specified by vport, tgt_id and
12633 * lun_id parameter.
12634 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
12635 * given iocb is for the SCSI target specified by vport and tgt_id
12637 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
12638 * given iocb is for the SCSI host associated with the given vport.
12639 * This function is called with no locks held.
12642 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
12643 uint16_t tgt_id, uint64_t lun_id,
12644 lpfc_ctx_cmd ctx_cmd)
12646 struct lpfc_io_buf *lpfc_cmd;
12649 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
12651 if (lpfc_cmd->pCmd == NULL)
12656 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
12657 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
12658 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
12662 if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
12663 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
12666 case LPFC_CTX_HOST:
12670 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
12671 __func__, ctx_cmd);
12679 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
12680 * @vport: Pointer to virtual port.
12681 * @tgt_id: SCSI ID of the target.
12682 * @lun_id: LUN ID of the scsi device.
12683 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12685 * This function returns number of FCP commands pending for the vport.
12686 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
12687 * commands pending on the vport associated with SCSI device specified
12688 * by tgt_id and lun_id parameters.
12689 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
12690 * commands pending on the vport associated with SCSI target specified
12691 * by tgt_id parameter.
12692 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
12693 * commands pending on the vport.
12694 * This function returns the number of iocbs which satisfy the filter.
12695 * This function is called without any lock held.
12698 lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
12699 lpfc_ctx_cmd ctx_cmd)
12701 struct lpfc_hba *phba = vport->phba;
12702 struct lpfc_iocbq *iocbq;
12704 unsigned long iflags;
12707 spin_lock_irqsave(&phba->hbalock, iflags);
12708 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
12709 iocbq = phba->sli.iocbq_lookup[i];
12711 if (!iocbq || iocbq->vport != vport)
12713 if (!(iocbq->cmd_flag & LPFC_IO_FCP) ||
12714 !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ))
12717 /* Include counting outstanding aborts */
12718 ulp_command = get_job_cmnd(phba, iocbq);
12719 if (ulp_command == CMD_ABORT_XRI_CN ||
12720 ulp_command == CMD_CLOSE_XRI_CN ||
12721 ulp_command == CMD_ABORT_XRI_WQE) {
12726 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12730 spin_unlock_irqrestore(&phba->hbalock, iflags);
12736 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
12737 * @phba: Pointer to HBA context object
12738 * @cmdiocb: Pointer to command iocb object.
12739 * @rspiocb: Pointer to response iocb object.
12741 * This function is called when an aborted FCP iocb completes. This
12742 * function is called by the ring event handler with no lock held.
12743 * This function frees the iocb.
12746 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
12747 struct lpfc_iocbq *rspiocb)
12749 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
12750 "3096 ABORT_XRI_CX completing on rpi x%x "
12751 "original iotag x%x, abort cmd iotag x%x "
12752 "status 0x%x, reason 0x%x\n",
12753 (phba->sli_rev == LPFC_SLI_REV4) ?
12754 cmdiocb->sli4_xritag :
12755 cmdiocb->iocb.un.acxri.abortContextTag,
12756 get_job_abtsiotag(phba, cmdiocb),
12757 cmdiocb->iotag, get_job_ulpstatus(phba, rspiocb),
12758 get_job_word4(phba, rspiocb));
12759 lpfc_sli_release_iocbq(phba, cmdiocb);
12764 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
12765 * @vport: Pointer to virtual port.
12766 * @tgt_id: SCSI ID of the target.
12767 * @lun_id: LUN ID of the scsi device.
12768 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12770 * This function sends an abort command for every SCSI command
12771 * associated with the given virtual port pending on the ring
12772 * filtered by lpfc_sli_validate_fcp_iocb_for_abort and then
12773 * lpfc_sli_validate_fcp_iocb function. The ordering for validation before
12774 * submitting abort iocbs must be lpfc_sli_validate_fcp_iocb_for_abort
12775 * followed by lpfc_sli_validate_fcp_iocb.
12777 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
12778 * FCP iocbs associated with lun specified by tgt_id and lun_id
12780 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
12781 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
12782 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
12783 * FCP iocbs associated with virtual port.
12784 * The pring used for SLI3 is sli3_ring[LPFC_FCP_RING], for SLI4
12785 * lpfc_sli4_calc_ring is used.
12786 * This function returns number of iocbs it failed to abort.
12787 * This function is called with no locks held.
12790 lpfc_sli_abort_iocb(struct lpfc_vport *vport, u16 tgt_id, u64 lun_id,
12791 lpfc_ctx_cmd abort_cmd)
12793 struct lpfc_hba *phba = vport->phba;
12794 struct lpfc_sli_ring *pring = NULL;
12795 struct lpfc_iocbq *iocbq;
12796 int errcnt = 0, ret_val = 0;
12797 unsigned long iflags;
12800 /* all I/Os are in process of being flushed */
12801 if (phba->hba_flag & HBA_IOQ_FLUSH)
12804 for (i = 1; i <= phba->sli.last_iotag; i++) {
12805 iocbq = phba->sli.iocbq_lookup[i];
12807 if (lpfc_sli_validate_fcp_iocb_for_abort(iocbq, vport))
12810 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12814 spin_lock_irqsave(&phba->hbalock, iflags);
12815 if (phba->sli_rev == LPFC_SLI_REV3) {
12816 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
12817 } else if (phba->sli_rev == LPFC_SLI_REV4) {
12818 pring = lpfc_sli4_calc_ring(phba, iocbq);
12820 ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocbq,
12821 lpfc_sli_abort_fcp_cmpl);
12822 spin_unlock_irqrestore(&phba->hbalock, iflags);
12823 if (ret_val != IOCB_SUCCESS)
12831 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
12832 * @vport: Pointer to virtual port.
12833 * @pring: Pointer to driver SLI ring object.
12834 * @tgt_id: SCSI ID of the target.
12835 * @lun_id: LUN ID of the scsi device.
12836 * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
12838 * This function sends an abort command for every SCSI command
12839 * associated with the given virtual port pending on the ring
12840 * filtered by lpfc_sli_validate_fcp_iocb_for_abort and then
12841 * lpfc_sli_validate_fcp_iocb function. The ordering for validation before
12842 * submitting abort iocbs must be lpfc_sli_validate_fcp_iocb_for_abort
12843 * followed by lpfc_sli_validate_fcp_iocb.
12845 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
12846 * FCP iocbs associated with lun specified by tgt_id and lun_id
12848 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
12849 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
12850 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
12851 * FCP iocbs associated with virtual port.
12852 * This function returns number of iocbs it aborted .
12853 * This function is called with no locks held right after a taskmgmt
12857 lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
12858 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
12860 struct lpfc_hba *phba = vport->phba;
12861 struct lpfc_io_buf *lpfc_cmd;
12862 struct lpfc_iocbq *abtsiocbq;
12863 struct lpfc_nodelist *ndlp = NULL;
12864 struct lpfc_iocbq *iocbq;
12865 int sum, i, ret_val;
12866 unsigned long iflags;
12867 struct lpfc_sli_ring *pring_s4 = NULL;
12868 u16 ulp_context, iotag, cqid = LPFC_WQE_CQ_ID_DEFAULT;
12871 spin_lock_irqsave(&phba->hbalock, iflags);
12873 /* all I/Os are in process of being flushed */
12874 if (phba->hba_flag & HBA_IOQ_FLUSH) {
12875 spin_unlock_irqrestore(&phba->hbalock, iflags);
12880 for (i = 1; i <= phba->sli.last_iotag; i++) {
12881 iocbq = phba->sli.iocbq_lookup[i];
12883 if (lpfc_sli_validate_fcp_iocb_for_abort(iocbq, vport))
12886 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
12890 /* Guard against IO completion being called at same time */
12891 lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
12892 spin_lock(&lpfc_cmd->buf_lock);
12894 if (!lpfc_cmd->pCmd) {
12895 spin_unlock(&lpfc_cmd->buf_lock);
12899 if (phba->sli_rev == LPFC_SLI_REV4) {
12901 phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
12903 spin_unlock(&lpfc_cmd->buf_lock);
12906 /* Note: both hbalock and ring_lock must be set here */
12907 spin_lock(&pring_s4->ring_lock);
12911 * If the iocbq is already being aborted, don't take a second
12912 * action, but do count it.
12914 if ((iocbq->cmd_flag & LPFC_DRIVER_ABORTED) ||
12915 !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ)) {
12916 if (phba->sli_rev == LPFC_SLI_REV4)
12917 spin_unlock(&pring_s4->ring_lock);
12918 spin_unlock(&lpfc_cmd->buf_lock);
12922 /* issue ABTS for this IOCB based on iotag */
12923 abtsiocbq = __lpfc_sli_get_iocbq(phba);
12925 if (phba->sli_rev == LPFC_SLI_REV4)
12926 spin_unlock(&pring_s4->ring_lock);
12927 spin_unlock(&lpfc_cmd->buf_lock);
12931 if (phba->sli_rev == LPFC_SLI_REV4) {
12932 iotag = abtsiocbq->iotag;
12933 ulp_context = iocbq->sli4_xritag;
12934 cqid = lpfc_cmd->hdwq->io_cq_map;
12936 iotag = iocbq->iocb.ulpIoTag;
12937 if (pring->ringno == LPFC_ELS_RING) {
12938 ndlp = iocbq->ndlp;
12939 ulp_context = ndlp->nlp_rpi;
12941 ulp_context = iocbq->iocb.ulpContext;
12945 ndlp = lpfc_cmd->rdata->pnode;
12947 if (lpfc_is_link_up(phba) &&
12948 (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE) &&
12949 !(phba->link_flag & LS_EXTERNAL_LOOPBACK))
12954 lpfc_sli_prep_abort_xri(phba, abtsiocbq, ulp_context, iotag,
12955 iocbq->iocb.ulpClass, cqid,
12958 abtsiocbq->vport = vport;
12960 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
12961 abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
12962 if (iocbq->cmd_flag & LPFC_IO_FCP)
12963 abtsiocbq->cmd_flag |= LPFC_USE_FCPWQIDX;
12964 if (iocbq->cmd_flag & LPFC_IO_FOF)
12965 abtsiocbq->cmd_flag |= LPFC_IO_FOF;
12967 /* Setup callback routine and issue the command. */
12968 abtsiocbq->cmd_cmpl = lpfc_sli_abort_fcp_cmpl;
12971 * Indicate the IO is being aborted by the driver and set
12972 * the caller's flag into the aborted IO.
12974 iocbq->cmd_flag |= LPFC_DRIVER_ABORTED;
12976 if (phba->sli_rev == LPFC_SLI_REV4) {
12977 ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
12979 spin_unlock(&pring_s4->ring_lock);
12981 ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
12985 spin_unlock(&lpfc_cmd->buf_lock);
12987 if (ret_val == IOCB_ERROR)
12988 __lpfc_sli_release_iocbq(phba, abtsiocbq);
12992 spin_unlock_irqrestore(&phba->hbalock, iflags);
12997 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
12998 * @phba: Pointer to HBA context object.
12999 * @cmdiocbq: Pointer to command iocb.
13000 * @rspiocbq: Pointer to response iocb.
13002 * This function is the completion handler for iocbs issued using
13003 * lpfc_sli_issue_iocb_wait function. This function is called by the
13004 * ring event handler function without any lock held. This function
13005 * can be called from both worker thread context and interrupt
13006 * context. This function also can be called from other thread which
13007 * cleans up the SLI layer objects.
13008 * This function copy the contents of the response iocb to the
13009 * response iocb memory object provided by the caller of
13010 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
13011 * sleeps for the iocb completion.
13014 lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
13015 struct lpfc_iocbq *cmdiocbq,
13016 struct lpfc_iocbq *rspiocbq)
13018 wait_queue_head_t *pdone_q;
13019 unsigned long iflags;
13020 struct lpfc_io_buf *lpfc_cmd;
13021 size_t offset = offsetof(struct lpfc_iocbq, wqe);
13023 spin_lock_irqsave(&phba->hbalock, iflags);
13024 if (cmdiocbq->cmd_flag & LPFC_IO_WAKE_TMO) {
13027 * A time out has occurred for the iocb. If a time out
13028 * completion handler has been supplied, call it. Otherwise,
13029 * just free the iocbq.
13032 spin_unlock_irqrestore(&phba->hbalock, iflags);
13033 cmdiocbq->cmd_cmpl = cmdiocbq->wait_cmd_cmpl;
13034 cmdiocbq->wait_cmd_cmpl = NULL;
13035 if (cmdiocbq->cmd_cmpl)
13036 cmdiocbq->cmd_cmpl(phba, cmdiocbq, NULL);
13038 lpfc_sli_release_iocbq(phba, cmdiocbq);
13042 /* Copy the contents of the local rspiocb into the caller's buffer. */
13043 cmdiocbq->cmd_flag |= LPFC_IO_WAKE;
13044 if (cmdiocbq->rsp_iocb && rspiocbq)
13045 memcpy((char *)cmdiocbq->rsp_iocb + offset,
13046 (char *)rspiocbq + offset, sizeof(*rspiocbq) - offset);
13048 /* Set the exchange busy flag for task management commands */
13049 if ((cmdiocbq->cmd_flag & LPFC_IO_FCP) &&
13050 !(cmdiocbq->cmd_flag & LPFC_IO_LIBDFC)) {
13051 lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
13053 if (rspiocbq && (rspiocbq->cmd_flag & LPFC_EXCHANGE_BUSY))
13054 lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
13056 lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
13059 pdone_q = cmdiocbq->context_un.wait_queue;
13062 spin_unlock_irqrestore(&phba->hbalock, iflags);
13067 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
13068 * @phba: Pointer to HBA context object..
13069 * @piocbq: Pointer to command iocb.
13070 * @flag: Flag to test.
13072 * This routine grabs the hbalock and then test the cmd_flag to
13073 * see if the passed in flag is set.
13075 * 1 if flag is set.
13076 * 0 if flag is not set.
13079 lpfc_chk_iocb_flg(struct lpfc_hba *phba,
13080 struct lpfc_iocbq *piocbq, uint32_t flag)
13082 unsigned long iflags;
13085 spin_lock_irqsave(&phba->hbalock, iflags);
13086 ret = piocbq->cmd_flag & flag;
13087 spin_unlock_irqrestore(&phba->hbalock, iflags);
13093 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
13094 * @phba: Pointer to HBA context object..
13095 * @ring_number: Ring number
13096 * @piocb: Pointer to command iocb.
13097 * @prspiocbq: Pointer to response iocb.
13098 * @timeout: Timeout in number of seconds.
13100 * This function issues the iocb to firmware and waits for the
13101 * iocb to complete. The cmd_cmpl field of the shall be used
13102 * to handle iocbs which time out. If the field is NULL, the
13103 * function shall free the iocbq structure. If more clean up is
13104 * needed, the caller is expected to provide a completion function
13105 * that will provide the needed clean up. If the iocb command is
13106 * not completed within timeout seconds, the function will either
13107 * free the iocbq structure (if cmd_cmpl == NULL) or execute the
13108 * completion function set in the cmd_cmpl field and then return
13109 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
13110 * resources if this function returns IOCB_TIMEDOUT.
13111 * The function waits for the iocb completion using an
13112 * non-interruptible wait.
13113 * This function will sleep while waiting for iocb completion.
13114 * So, this function should not be called from any context which
13115 * does not allow sleeping. Due to the same reason, this function
13116 * cannot be called with interrupt disabled.
13117 * This function assumes that the iocb completions occur while
13118 * this function sleep. So, this function cannot be called from
13119 * the thread which process iocb completion for this ring.
13120 * This function clears the cmd_flag of the iocb object before
13121 * issuing the iocb and the iocb completion handler sets this
13122 * flag and wakes this thread when the iocb completes.
13123 * The contents of the response iocb will be copied to prspiocbq
13124 * by the completion handler when the command completes.
13125 * This function returns IOCB_SUCCESS when success.
13126 * This function is called with no lock held.
13129 lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
13130 uint32_t ring_number,
13131 struct lpfc_iocbq *piocb,
13132 struct lpfc_iocbq *prspiocbq,
13135 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
13136 long timeleft, timeout_req = 0;
13137 int retval = IOCB_SUCCESS;
13139 struct lpfc_iocbq *iocb;
13141 int txcmplq_cnt = 0;
13142 struct lpfc_sli_ring *pring;
13143 unsigned long iflags;
13144 bool iocb_completed = true;
13146 if (phba->sli_rev >= LPFC_SLI_REV4) {
13147 lpfc_sli_prep_wqe(phba, piocb);
13149 pring = lpfc_sli4_calc_ring(phba, piocb);
13151 pring = &phba->sli.sli3_ring[ring_number];
13153 * If the caller has provided a response iocbq buffer, then rsp_iocb
13154 * is NULL or its an error.
13157 if (piocb->rsp_iocb)
13159 piocb->rsp_iocb = prspiocbq;
13162 piocb->wait_cmd_cmpl = piocb->cmd_cmpl;
13163 piocb->cmd_cmpl = lpfc_sli_wake_iocb_wait;
13164 piocb->context_un.wait_queue = &done_q;
13165 piocb->cmd_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
13167 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
13168 if (lpfc_readl(phba->HCregaddr, &creg_val))
13170 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
13171 writel(creg_val, phba->HCregaddr);
13172 readl(phba->HCregaddr); /* flush */
13175 retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
13176 SLI_IOCB_RET_IOCB);
13177 if (retval == IOCB_SUCCESS) {
13178 timeout_req = msecs_to_jiffies(timeout * 1000);
13179 timeleft = wait_event_timeout(done_q,
13180 lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
13182 spin_lock_irqsave(&phba->hbalock, iflags);
13183 if (!(piocb->cmd_flag & LPFC_IO_WAKE)) {
13186 * IOCB timed out. Inform the wake iocb wait
13187 * completion function and set local status
13190 iocb_completed = false;
13191 piocb->cmd_flag |= LPFC_IO_WAKE_TMO;
13193 spin_unlock_irqrestore(&phba->hbalock, iflags);
13194 if (iocb_completed) {
13195 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13196 "0331 IOCB wake signaled\n");
13197 /* Note: we are not indicating if the IOCB has a success
13198 * status or not - that's for the caller to check.
13199 * IOCB_SUCCESS means just that the command was sent and
13200 * completed. Not that it completed successfully.
13202 } else if (timeleft == 0) {
13203 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13204 "0338 IOCB wait timeout error - no "
13205 "wake response Data x%x\n", timeout);
13206 retval = IOCB_TIMEDOUT;
13208 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13209 "0330 IOCB wake NOT set, "
13211 timeout, (timeleft / jiffies));
13212 retval = IOCB_TIMEDOUT;
13214 } else if (retval == IOCB_BUSY) {
13215 if (phba->cfg_log_verbose & LOG_SLI) {
13216 list_for_each_entry(iocb, &pring->txq, list) {
13219 list_for_each_entry(iocb, &pring->txcmplq, list) {
13222 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13223 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
13224 phba->iocb_cnt, txq_cnt, txcmplq_cnt);
13228 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
13229 "0332 IOCB wait issue failed, Data x%x\n",
13231 retval = IOCB_ERROR;
13234 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
13235 if (lpfc_readl(phba->HCregaddr, &creg_val))
13237 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
13238 writel(creg_val, phba->HCregaddr);
13239 readl(phba->HCregaddr); /* flush */
13243 piocb->rsp_iocb = NULL;
13245 piocb->context_un.wait_queue = NULL;
13246 piocb->cmd_cmpl = NULL;
13251 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
13252 * @phba: Pointer to HBA context object.
13253 * @pmboxq: Pointer to driver mailbox object.
13254 * @timeout: Timeout in number of seconds.
13256 * This function issues the mailbox to firmware and waits for the
13257 * mailbox command to complete. If the mailbox command is not
13258 * completed within timeout seconds, it returns MBX_TIMEOUT.
13259 * The function waits for the mailbox completion using an
13260 * interruptible wait. If the thread is woken up due to a
13261 * signal, MBX_TIMEOUT error is returned to the caller. Caller
13262 * should not free the mailbox resources, if this function returns
13264 * This function will sleep while waiting for mailbox completion.
13265 * So, this function should not be called from any context which
13266 * does not allow sleeping. Due to the same reason, this function
13267 * cannot be called with interrupt disabled.
13268 * This function assumes that the mailbox completion occurs while
13269 * this function sleep. So, this function cannot be called from
13270 * the worker thread which processes mailbox completion.
13271 * This function is called in the context of HBA management
13273 * This function returns MBX_SUCCESS when successful.
13274 * This function is called with no lock held.
13277 lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
13280 struct completion mbox_done;
13282 unsigned long flag;
13284 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
13285 /* setup wake call as IOCB callback */
13286 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
13288 /* setup context3 field to pass wait_queue pointer to wake function */
13289 init_completion(&mbox_done);
13290 pmboxq->context3 = &mbox_done;
13291 /* now issue the command */
13292 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
13293 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
13294 wait_for_completion_timeout(&mbox_done,
13295 msecs_to_jiffies(timeout * 1000));
13297 spin_lock_irqsave(&phba->hbalock, flag);
13298 pmboxq->context3 = NULL;
13300 * if LPFC_MBX_WAKE flag is set the mailbox is completed
13301 * else do not free the resources.
13303 if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
13304 retval = MBX_SUCCESS;
13306 retval = MBX_TIMEOUT;
13307 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
13309 spin_unlock_irqrestore(&phba->hbalock, flag);
13315 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
13316 * @phba: Pointer to HBA context.
13317 * @mbx_action: Mailbox shutdown options.
13319 * This function is called to shutdown the driver's mailbox sub-system.
13320 * It first marks the mailbox sub-system is in a block state to prevent
13321 * the asynchronous mailbox command from issued off the pending mailbox
13322 * command queue. If the mailbox command sub-system shutdown is due to
13323 * HBA error conditions such as EEH or ERATT, this routine shall invoke
13324 * the mailbox sub-system flush routine to forcefully bring down the
13325 * mailbox sub-system. Otherwise, if it is due to normal condition (such
13326 * as with offline or HBA function reset), this routine will wait for the
13327 * outstanding mailbox command to complete before invoking the mailbox
13328 * sub-system flush routine to gracefully bring down mailbox sub-system.
13331 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
13333 struct lpfc_sli *psli = &phba->sli;
13334 unsigned long timeout;
13336 if (mbx_action == LPFC_MBX_NO_WAIT) {
13337 /* delay 100ms for port state */
13339 lpfc_sli_mbox_sys_flush(phba);
13342 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
13344 /* Disable softirqs, including timers from obtaining phba->hbalock */
13345 local_bh_disable();
13347 spin_lock_irq(&phba->hbalock);
13348 psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
13350 if (psli->sli_flag & LPFC_SLI_ACTIVE) {
13351 /* Determine how long we might wait for the active mailbox
13352 * command to be gracefully completed by firmware.
13354 if (phba->sli.mbox_active)
13355 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
13356 phba->sli.mbox_active) *
13358 spin_unlock_irq(&phba->hbalock);
13360 /* Enable softirqs again, done with phba->hbalock */
13363 while (phba->sli.mbox_active) {
13364 /* Check active mailbox complete status every 2ms */
13366 if (time_after(jiffies, timeout))
13367 /* Timeout, let the mailbox flush routine to
13368 * forcefully release active mailbox command
13373 spin_unlock_irq(&phba->hbalock);
13375 /* Enable softirqs again, done with phba->hbalock */
13379 lpfc_sli_mbox_sys_flush(phba);
13383 * lpfc_sli_eratt_read - read sli-3 error attention events
13384 * @phba: Pointer to HBA context.
13386 * This function is called to read the SLI3 device error attention registers
13387 * for possible error attention events. The caller must hold the hostlock
13388 * with spin_lock_irq().
13390 * This function returns 1 when there is Error Attention in the Host Attention
13391 * Register and returns 0 otherwise.
13394 lpfc_sli_eratt_read(struct lpfc_hba *phba)
13398 /* Read chip Host Attention (HA) register */
13399 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13402 if (ha_copy & HA_ERATT) {
13403 /* Read host status register to retrieve error event */
13404 if (lpfc_sli_read_hs(phba))
13407 /* Check if there is a deferred error condition is active */
13408 if ((HS_FFER1 & phba->work_hs) &&
13409 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
13410 HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
13411 phba->hba_flag |= DEFER_ERATT;
13412 /* Clear all interrupt enable conditions */
13413 writel(0, phba->HCregaddr);
13414 readl(phba->HCregaddr);
13417 /* Set the driver HA work bitmap */
13418 phba->work_ha |= HA_ERATT;
13419 /* Indicate polling handles this ERATT */
13420 phba->hba_flag |= HBA_ERATT_HANDLED;
13426 /* Set the driver HS work bitmap */
13427 phba->work_hs |= UNPLUG_ERR;
13428 /* Set the driver HA work bitmap */
13429 phba->work_ha |= HA_ERATT;
13430 /* Indicate polling handles this ERATT */
13431 phba->hba_flag |= HBA_ERATT_HANDLED;
13436 * lpfc_sli4_eratt_read - read sli-4 error attention events
13437 * @phba: Pointer to HBA context.
13439 * This function is called to read the SLI4 device error attention registers
13440 * for possible error attention events. The caller must hold the hostlock
13441 * with spin_lock_irq().
13443 * This function returns 1 when there is Error Attention in the Host Attention
13444 * Register and returns 0 otherwise.
13447 lpfc_sli4_eratt_read(struct lpfc_hba *phba)
13449 uint32_t uerr_sta_hi, uerr_sta_lo;
13450 uint32_t if_type, portsmphr;
13451 struct lpfc_register portstat_reg;
13455 * For now, use the SLI4 device internal unrecoverable error
13456 * registers for error attention. This can be changed later.
13458 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
13460 case LPFC_SLI_INTF_IF_TYPE_0:
13461 if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
13463 lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
13465 phba->work_hs |= UNPLUG_ERR;
13466 phba->work_ha |= HA_ERATT;
13467 phba->hba_flag |= HBA_ERATT_HANDLED;
13470 if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
13471 (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
13472 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13473 "1423 HBA Unrecoverable error: "
13474 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
13475 "ue_mask_lo_reg=0x%x, "
13476 "ue_mask_hi_reg=0x%x\n",
13477 uerr_sta_lo, uerr_sta_hi,
13478 phba->sli4_hba.ue_mask_lo,
13479 phba->sli4_hba.ue_mask_hi);
13480 phba->work_status[0] = uerr_sta_lo;
13481 phba->work_status[1] = uerr_sta_hi;
13482 phba->work_ha |= HA_ERATT;
13483 phba->hba_flag |= HBA_ERATT_HANDLED;
13487 case LPFC_SLI_INTF_IF_TYPE_2:
13488 case LPFC_SLI_INTF_IF_TYPE_6:
13489 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
13490 &portstat_reg.word0) ||
13491 lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
13493 phba->work_hs |= UNPLUG_ERR;
13494 phba->work_ha |= HA_ERATT;
13495 phba->hba_flag |= HBA_ERATT_HANDLED;
13498 if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
13499 phba->work_status[0] =
13500 readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
13501 phba->work_status[1] =
13502 readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
13503 logmask = LOG_TRACE_EVENT;
13504 if (phba->work_status[0] ==
13505 SLIPORT_ERR1_REG_ERR_CODE_2 &&
13506 phba->work_status[1] == SLIPORT_ERR2_REG_FW_RESTART)
13508 lpfc_printf_log(phba, KERN_ERR, logmask,
13509 "2885 Port Status Event: "
13510 "port status reg 0x%x, "
13511 "port smphr reg 0x%x, "
13512 "error 1=0x%x, error 2=0x%x\n",
13513 portstat_reg.word0,
13515 phba->work_status[0],
13516 phba->work_status[1]);
13517 phba->work_ha |= HA_ERATT;
13518 phba->hba_flag |= HBA_ERATT_HANDLED;
13522 case LPFC_SLI_INTF_IF_TYPE_1:
13524 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13525 "2886 HBA Error Attention on unsupported "
13526 "if type %d.", if_type);
13534 * lpfc_sli_check_eratt - check error attention events
13535 * @phba: Pointer to HBA context.
13537 * This function is called from timer soft interrupt context to check HBA's
13538 * error attention register bit for error attention events.
13540 * This function returns 1 when there is Error Attention in the Host Attention
13541 * Register and returns 0 otherwise.
13544 lpfc_sli_check_eratt(struct lpfc_hba *phba)
13548 /* If somebody is waiting to handle an eratt, don't process it
13549 * here. The brdkill function will do this.
13551 if (phba->link_flag & LS_IGNORE_ERATT)
13554 /* Check if interrupt handler handles this ERATT */
13555 spin_lock_irq(&phba->hbalock);
13556 if (phba->hba_flag & HBA_ERATT_HANDLED) {
13557 /* Interrupt handler has handled ERATT */
13558 spin_unlock_irq(&phba->hbalock);
13563 * If there is deferred error attention, do not check for error
13566 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13567 spin_unlock_irq(&phba->hbalock);
13571 /* If PCI channel is offline, don't process it */
13572 if (unlikely(pci_channel_offline(phba->pcidev))) {
13573 spin_unlock_irq(&phba->hbalock);
13577 switch (phba->sli_rev) {
13578 case LPFC_SLI_REV2:
13579 case LPFC_SLI_REV3:
13580 /* Read chip Host Attention (HA) register */
13581 ha_copy = lpfc_sli_eratt_read(phba);
13583 case LPFC_SLI_REV4:
13584 /* Read device Uncoverable Error (UERR) registers */
13585 ha_copy = lpfc_sli4_eratt_read(phba);
13588 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13589 "0299 Invalid SLI revision (%d)\n",
13594 spin_unlock_irq(&phba->hbalock);
13600 * lpfc_intr_state_check - Check device state for interrupt handling
13601 * @phba: Pointer to HBA context.
13603 * This inline routine checks whether a device or its PCI slot is in a state
13604 * that the interrupt should be handled.
13606 * This function returns 0 if the device or the PCI slot is in a state that
13607 * interrupt should be handled, otherwise -EIO.
13610 lpfc_intr_state_check(struct lpfc_hba *phba)
13612 /* If the pci channel is offline, ignore all the interrupts */
13613 if (unlikely(pci_channel_offline(phba->pcidev)))
13616 /* Update device level interrupt statistics */
13617 phba->sli.slistat.sli_intr++;
13619 /* Ignore all interrupts during initialization. */
13620 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
13627 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
13628 * @irq: Interrupt number.
13629 * @dev_id: The device context pointer.
13631 * This function is directly called from the PCI layer as an interrupt
13632 * service routine when device with SLI-3 interface spec is enabled with
13633 * MSI-X multi-message interrupt mode and there are slow-path events in
13634 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
13635 * interrupt mode, this function is called as part of the device-level
13636 * interrupt handler. When the PCI slot is in error recovery or the HBA
13637 * is undergoing initialization, the interrupt handler will not process
13638 * the interrupt. The link attention and ELS ring attention events are
13639 * handled by the worker thread. The interrupt handler signals the worker
13640 * thread and returns for these events. This function is called without
13641 * any lock held. It gets the hbalock to access and update SLI data
13644 * This function returns IRQ_HANDLED when interrupt is handled else it
13645 * returns IRQ_NONE.
13648 lpfc_sli_sp_intr_handler(int irq, void *dev_id)
13650 struct lpfc_hba *phba;
13651 uint32_t ha_copy, hc_copy;
13652 uint32_t work_ha_copy;
13653 unsigned long status;
13654 unsigned long iflag;
13657 MAILBOX_t *mbox, *pmbox;
13658 struct lpfc_vport *vport;
13659 struct lpfc_nodelist *ndlp;
13660 struct lpfc_dmabuf *mp;
13665 * Get the driver's phba structure from the dev_id and
13666 * assume the HBA is not interrupting.
13668 phba = (struct lpfc_hba *)dev_id;
13670 if (unlikely(!phba))
13674 * Stuff needs to be attented to when this function is invoked as an
13675 * individual interrupt handler in MSI-X multi-message interrupt mode
13677 if (phba->intr_type == MSIX) {
13678 /* Check device state for handling interrupt */
13679 if (lpfc_intr_state_check(phba))
13681 /* Need to read HA REG for slow-path events */
13682 spin_lock_irqsave(&phba->hbalock, iflag);
13683 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13685 /* If somebody is waiting to handle an eratt don't process it
13686 * here. The brdkill function will do this.
13688 if (phba->link_flag & LS_IGNORE_ERATT)
13689 ha_copy &= ~HA_ERATT;
13690 /* Check the need for handling ERATT in interrupt handler */
13691 if (ha_copy & HA_ERATT) {
13692 if (phba->hba_flag & HBA_ERATT_HANDLED)
13693 /* ERATT polling has handled ERATT */
13694 ha_copy &= ~HA_ERATT;
13696 /* Indicate interrupt handler handles ERATT */
13697 phba->hba_flag |= HBA_ERATT_HANDLED;
13701 * If there is deferred error attention, do not check for any
13704 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13705 spin_unlock_irqrestore(&phba->hbalock, iflag);
13709 /* Clear up only attention source related to slow-path */
13710 if (lpfc_readl(phba->HCregaddr, &hc_copy))
13713 writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
13714 HC_LAINT_ENA | HC_ERINT_ENA),
13716 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
13718 writel(hc_copy, phba->HCregaddr);
13719 readl(phba->HAregaddr); /* flush */
13720 spin_unlock_irqrestore(&phba->hbalock, iflag);
13722 ha_copy = phba->ha_copy;
13724 work_ha_copy = ha_copy & phba->work_ha_mask;
13726 if (work_ha_copy) {
13727 if (work_ha_copy & HA_LATT) {
13728 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
13730 * Turn off Link Attention interrupts
13731 * until CLEAR_LA done
13733 spin_lock_irqsave(&phba->hbalock, iflag);
13734 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
13735 if (lpfc_readl(phba->HCregaddr, &control))
13737 control &= ~HC_LAINT_ENA;
13738 writel(control, phba->HCregaddr);
13739 readl(phba->HCregaddr); /* flush */
13740 spin_unlock_irqrestore(&phba->hbalock, iflag);
13743 work_ha_copy &= ~HA_LATT;
13746 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
13748 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
13749 * the only slow ring.
13751 status = (work_ha_copy &
13752 (HA_RXMASK << (4*LPFC_ELS_RING)));
13753 status >>= (4*LPFC_ELS_RING);
13754 if (status & HA_RXMASK) {
13755 spin_lock_irqsave(&phba->hbalock, iflag);
13756 if (lpfc_readl(phba->HCregaddr, &control))
13759 lpfc_debugfs_slow_ring_trc(phba,
13760 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
13762 (uint32_t)phba->sli.slistat.sli_intr);
13764 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
13765 lpfc_debugfs_slow_ring_trc(phba,
13766 "ISR Disable ring:"
13767 "pwork:x%x hawork:x%x wait:x%x",
13768 phba->work_ha, work_ha_copy,
13769 (uint32_t)((unsigned long)
13770 &phba->work_waitq));
13773 ~(HC_R0INT_ENA << LPFC_ELS_RING);
13774 writel(control, phba->HCregaddr);
13775 readl(phba->HCregaddr); /* flush */
13778 lpfc_debugfs_slow_ring_trc(phba,
13779 "ISR slow ring: pwork:"
13780 "x%x hawork:x%x wait:x%x",
13781 phba->work_ha, work_ha_copy,
13782 (uint32_t)((unsigned long)
13783 &phba->work_waitq));
13785 spin_unlock_irqrestore(&phba->hbalock, iflag);
13788 spin_lock_irqsave(&phba->hbalock, iflag);
13789 if (work_ha_copy & HA_ERATT) {
13790 if (lpfc_sli_read_hs(phba))
13793 * Check if there is a deferred error condition
13796 if ((HS_FFER1 & phba->work_hs) &&
13797 ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
13798 HS_FFER6 | HS_FFER7 | HS_FFER8) &
13800 phba->hba_flag |= DEFER_ERATT;
13801 /* Clear all interrupt enable conditions */
13802 writel(0, phba->HCregaddr);
13803 readl(phba->HCregaddr);
13807 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
13808 pmb = phba->sli.mbox_active;
13809 pmbox = &pmb->u.mb;
13811 vport = pmb->vport;
13813 /* First check out the status word */
13814 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
13815 if (pmbox->mbxOwner != OWN_HOST) {
13816 spin_unlock_irqrestore(&phba->hbalock, iflag);
13818 * Stray Mailbox Interrupt, mbxCommand <cmd>
13819 * mbxStatus <status>
13821 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
13822 "(%d):0304 Stray Mailbox "
13823 "Interrupt mbxCommand x%x "
13825 (vport ? vport->vpi : 0),
13828 /* clear mailbox attention bit */
13829 work_ha_copy &= ~HA_MBATT;
13831 phba->sli.mbox_active = NULL;
13832 spin_unlock_irqrestore(&phba->hbalock, iflag);
13833 phba->last_completion_time = jiffies;
13834 del_timer(&phba->sli.mbox_tmo);
13835 if (pmb->mbox_cmpl) {
13836 lpfc_sli_pcimem_bcopy(mbox, pmbox,
13838 if (pmb->out_ext_byte_len &&
13840 lpfc_sli_pcimem_bcopy(
13843 pmb->out_ext_byte_len);
13845 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
13846 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
13848 lpfc_debugfs_disc_trc(vport,
13849 LPFC_DISC_TRC_MBOX_VPORT,
13850 "MBOX dflt rpi: : "
13851 "status:x%x rpi:x%x",
13852 (uint32_t)pmbox->mbxStatus,
13853 pmbox->un.varWords[0], 0);
13855 if (!pmbox->mbxStatus) {
13856 mp = (struct lpfc_dmabuf *)
13858 ndlp = (struct lpfc_nodelist *)
13861 /* Reg_LOGIN of dflt RPI was
13862 * successful. new lets get
13863 * rid of the RPI using the
13864 * same mbox buffer.
13866 lpfc_unreg_login(phba,
13868 pmbox->un.varWords[0],
13871 lpfc_mbx_cmpl_dflt_rpi;
13873 pmb->ctx_ndlp = ndlp;
13874 pmb->vport = vport;
13875 rc = lpfc_sli_issue_mbox(phba,
13878 if (rc != MBX_BUSY)
13879 lpfc_printf_log(phba,
13882 "0350 rc should have"
13883 "been MBX_BUSY\n");
13884 if (rc != MBX_NOT_FINISHED)
13885 goto send_current_mbox;
13889 &phba->pport->work_port_lock,
13891 phba->pport->work_port_events &=
13893 spin_unlock_irqrestore(
13894 &phba->pport->work_port_lock,
13897 /* Do NOT queue MBX_HEARTBEAT to the worker
13898 * thread for processing.
13900 if (pmbox->mbxCommand == MBX_HEARTBEAT) {
13901 /* Process mbox now */
13902 phba->sli.mbox_active = NULL;
13903 phba->sli.sli_flag &=
13904 ~LPFC_SLI_MBOX_ACTIVE;
13905 if (pmb->mbox_cmpl)
13906 pmb->mbox_cmpl(phba, pmb);
13908 /* Queue to worker thread to process */
13909 lpfc_mbox_cmpl_put(phba, pmb);
13913 spin_unlock_irqrestore(&phba->hbalock, iflag);
13915 if ((work_ha_copy & HA_MBATT) &&
13916 (phba->sli.mbox_active == NULL)) {
13918 /* Process next mailbox command if there is one */
13920 rc = lpfc_sli_issue_mbox(phba, NULL,
13922 } while (rc == MBX_NOT_FINISHED);
13923 if (rc != MBX_SUCCESS)
13924 lpfc_printf_log(phba, KERN_ERR,
13926 "0349 rc should be "
13930 spin_lock_irqsave(&phba->hbalock, iflag);
13931 phba->work_ha |= work_ha_copy;
13932 spin_unlock_irqrestore(&phba->hbalock, iflag);
13933 lpfc_worker_wake_up(phba);
13935 return IRQ_HANDLED;
13937 spin_unlock_irqrestore(&phba->hbalock, iflag);
13938 return IRQ_HANDLED;
13940 } /* lpfc_sli_sp_intr_handler */
13943 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
13944 * @irq: Interrupt number.
13945 * @dev_id: The device context pointer.
13947 * This function is directly called from the PCI layer as an interrupt
13948 * service routine when device with SLI-3 interface spec is enabled with
13949 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13950 * ring event in the HBA. However, when the device is enabled with either
13951 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13952 * device-level interrupt handler. When the PCI slot is in error recovery
13953 * or the HBA is undergoing initialization, the interrupt handler will not
13954 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13955 * the intrrupt context. This function is called without any lock held.
13956 * It gets the hbalock to access and update SLI data structures.
13958 * This function returns IRQ_HANDLED when interrupt is handled else it
13959 * returns IRQ_NONE.
13962 lpfc_sli_fp_intr_handler(int irq, void *dev_id)
13964 struct lpfc_hba *phba;
13966 unsigned long status;
13967 unsigned long iflag;
13968 struct lpfc_sli_ring *pring;
13970 /* Get the driver's phba structure from the dev_id and
13971 * assume the HBA is not interrupting.
13973 phba = (struct lpfc_hba *) dev_id;
13975 if (unlikely(!phba))
13979 * Stuff needs to be attented to when this function is invoked as an
13980 * individual interrupt handler in MSI-X multi-message interrupt mode
13982 if (phba->intr_type == MSIX) {
13983 /* Check device state for handling interrupt */
13984 if (lpfc_intr_state_check(phba))
13986 /* Need to read HA REG for FCP ring and other ring events */
13987 if (lpfc_readl(phba->HAregaddr, &ha_copy))
13988 return IRQ_HANDLED;
13989 /* Clear up only attention source related to fast-path */
13990 spin_lock_irqsave(&phba->hbalock, iflag);
13992 * If there is deferred error attention, do not check for
13995 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
13996 spin_unlock_irqrestore(&phba->hbalock, iflag);
13999 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
14001 readl(phba->HAregaddr); /* flush */
14002 spin_unlock_irqrestore(&phba->hbalock, iflag);
14004 ha_copy = phba->ha_copy;
14007 * Process all events on FCP ring. Take the optimized path for FCP IO.
14009 ha_copy &= ~(phba->work_ha_mask);
14011 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
14012 status >>= (4*LPFC_FCP_RING);
14013 pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
14014 if (status & HA_RXMASK)
14015 lpfc_sli_handle_fast_ring_event(phba, pring, status);
14017 if (phba->cfg_multi_ring_support == 2) {
14019 * Process all events on extra ring. Take the optimized path
14020 * for extra ring IO.
14022 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
14023 status >>= (4*LPFC_EXTRA_RING);
14024 if (status & HA_RXMASK) {
14025 lpfc_sli_handle_fast_ring_event(phba,
14026 &phba->sli.sli3_ring[LPFC_EXTRA_RING],
14030 return IRQ_HANDLED;
14031 } /* lpfc_sli_fp_intr_handler */
14034 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
14035 * @irq: Interrupt number.
14036 * @dev_id: The device context pointer.
14038 * This function is the HBA device-level interrupt handler to device with
14039 * SLI-3 interface spec, called from the PCI layer when either MSI or
14040 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
14041 * requires driver attention. This function invokes the slow-path interrupt
14042 * attention handling function and fast-path interrupt attention handling
14043 * function in turn to process the relevant HBA attention events. This
14044 * function is called without any lock held. It gets the hbalock to access
14045 * and update SLI data structures.
14047 * This function returns IRQ_HANDLED when interrupt is handled, else it
14048 * returns IRQ_NONE.
14051 lpfc_sli_intr_handler(int irq, void *dev_id)
14053 struct lpfc_hba *phba;
14054 irqreturn_t sp_irq_rc, fp_irq_rc;
14055 unsigned long status1, status2;
14059 * Get the driver's phba structure from the dev_id and
14060 * assume the HBA is not interrupting.
14062 phba = (struct lpfc_hba *) dev_id;
14064 if (unlikely(!phba))
14067 /* Check device state for handling interrupt */
14068 if (lpfc_intr_state_check(phba))
14071 spin_lock(&phba->hbalock);
14072 if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
14073 spin_unlock(&phba->hbalock);
14074 return IRQ_HANDLED;
14077 if (unlikely(!phba->ha_copy)) {
14078 spin_unlock(&phba->hbalock);
14080 } else if (phba->ha_copy & HA_ERATT) {
14081 if (phba->hba_flag & HBA_ERATT_HANDLED)
14082 /* ERATT polling has handled ERATT */
14083 phba->ha_copy &= ~HA_ERATT;
14085 /* Indicate interrupt handler handles ERATT */
14086 phba->hba_flag |= HBA_ERATT_HANDLED;
14090 * If there is deferred error attention, do not check for any interrupt.
14092 if (unlikely(phba->hba_flag & DEFER_ERATT)) {
14093 spin_unlock(&phba->hbalock);
14097 /* Clear attention sources except link and error attentions */
14098 if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
14099 spin_unlock(&phba->hbalock);
14100 return IRQ_HANDLED;
14102 writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
14103 | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
14105 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
14106 writel(hc_copy, phba->HCregaddr);
14107 readl(phba->HAregaddr); /* flush */
14108 spin_unlock(&phba->hbalock);
14111 * Invokes slow-path host attention interrupt handling as appropriate.
14114 /* status of events with mailbox and link attention */
14115 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
14117 /* status of events with ELS ring */
14118 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
14119 status2 >>= (4*LPFC_ELS_RING);
14121 if (status1 || (status2 & HA_RXMASK))
14122 sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
14124 sp_irq_rc = IRQ_NONE;
14127 * Invoke fast-path host attention interrupt handling as appropriate.
14130 /* status of events with FCP ring */
14131 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
14132 status1 >>= (4*LPFC_FCP_RING);
14134 /* status of events with extra ring */
14135 if (phba->cfg_multi_ring_support == 2) {
14136 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
14137 status2 >>= (4*LPFC_EXTRA_RING);
14141 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
14142 fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
14144 fp_irq_rc = IRQ_NONE;
14146 /* Return device-level interrupt handling status */
14147 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
14148 } /* lpfc_sli_intr_handler */
14151 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
14152 * @phba: pointer to lpfc hba data structure.
14154 * This routine is invoked by the worker thread to process all the pending
14155 * SLI4 els abort xri events.
14157 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
14159 struct lpfc_cq_event *cq_event;
14160 unsigned long iflags;
14162 /* First, declare the els xri abort event has been handled */
14163 spin_lock_irqsave(&phba->hbalock, iflags);
14164 phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
14165 spin_unlock_irqrestore(&phba->hbalock, iflags);
14167 /* Now, handle all the els xri abort events */
14168 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
14169 while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
14170 /* Get the first event from the head of the event queue */
14171 list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
14172 cq_event, struct lpfc_cq_event, list);
14173 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
14175 /* Notify aborted XRI for ELS work queue */
14176 lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
14178 /* Free the event processed back to the free pool */
14179 lpfc_sli4_cq_event_release(phba, cq_event);
14180 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
14183 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
14187 * lpfc_sli4_els_preprocess_rspiocbq - Get response iocbq from els wcqe
14188 * @phba: Pointer to HBA context object.
14189 * @irspiocbq: Pointer to work-queue completion queue entry.
14191 * This routine handles an ELS work-queue completion event and construct
14192 * a pseudo response ELS IOCBQ from the SLI4 ELS WCQE for the common
14193 * discovery engine to handle.
14195 * Return: Pointer to the receive IOCBQ, NULL otherwise.
14197 static struct lpfc_iocbq *
14198 lpfc_sli4_els_preprocess_rspiocbq(struct lpfc_hba *phba,
14199 struct lpfc_iocbq *irspiocbq)
14201 struct lpfc_sli_ring *pring;
14202 struct lpfc_iocbq *cmdiocbq;
14203 struct lpfc_wcqe_complete *wcqe;
14204 unsigned long iflags;
14206 pring = lpfc_phba_elsring(phba);
14207 if (unlikely(!pring))
14210 wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
14211 spin_lock_irqsave(&pring->ring_lock, iflags);
14212 pring->stats.iocb_event++;
14213 /* Look up the ELS command IOCB and create pseudo response IOCB */
14214 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
14215 bf_get(lpfc_wcqe_c_request_tag, wcqe));
14216 if (unlikely(!cmdiocbq)) {
14217 spin_unlock_irqrestore(&pring->ring_lock, iflags);
14218 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14219 "0386 ELS complete with no corresponding "
14220 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
14221 wcqe->word0, wcqe->total_data_placed,
14222 wcqe->parameter, wcqe->word3);
14223 lpfc_sli_release_iocbq(phba, irspiocbq);
14227 memcpy(&irspiocbq->wqe, &cmdiocbq->wqe, sizeof(union lpfc_wqe128));
14228 memcpy(&irspiocbq->wcqe_cmpl, wcqe, sizeof(*wcqe));
14230 /* Put the iocb back on the txcmplq */
14231 lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
14232 spin_unlock_irqrestore(&pring->ring_lock, iflags);
14234 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
14235 spin_lock_irqsave(&phba->hbalock, iflags);
14236 irspiocbq->cmd_flag |= LPFC_EXCHANGE_BUSY;
14237 spin_unlock_irqrestore(&phba->hbalock, iflags);
14243 inline struct lpfc_cq_event *
14244 lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
14246 struct lpfc_cq_event *cq_event;
14248 /* Allocate a new internal CQ_EVENT entry */
14249 cq_event = lpfc_sli4_cq_event_alloc(phba);
14251 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14252 "0602 Failed to alloc CQ_EVENT entry\n");
14256 /* Move the CQE into the event */
14257 memcpy(&cq_event->cqe, entry, size);
14262 * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event
14263 * @phba: Pointer to HBA context object.
14264 * @mcqe: Pointer to mailbox completion queue entry.
14266 * This routine process a mailbox completion queue entry with asynchronous
14269 * Return: true if work posted to worker thread, otherwise false.
14272 lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
14274 struct lpfc_cq_event *cq_event;
14275 unsigned long iflags;
14277 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14278 "0392 Async Event: word0:x%x, word1:x%x, "
14279 "word2:x%x, word3:x%x\n", mcqe->word0,
14280 mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
14282 cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
14286 spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
14287 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
14288 spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
14290 /* Set the async event flag */
14291 spin_lock_irqsave(&phba->hbalock, iflags);
14292 phba->hba_flag |= ASYNC_EVENT;
14293 spin_unlock_irqrestore(&phba->hbalock, iflags);
14299 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
14300 * @phba: Pointer to HBA context object.
14301 * @mcqe: Pointer to mailbox completion queue entry.
14303 * This routine process a mailbox completion queue entry with mailbox
14304 * completion event.
14306 * Return: true if work posted to worker thread, otherwise false.
14309 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
14311 uint32_t mcqe_status;
14312 MAILBOX_t *mbox, *pmbox;
14313 struct lpfc_mqe *mqe;
14314 struct lpfc_vport *vport;
14315 struct lpfc_nodelist *ndlp;
14316 struct lpfc_dmabuf *mp;
14317 unsigned long iflags;
14319 bool workposted = false;
14322 /* If not a mailbox complete MCQE, out by checking mailbox consume */
14323 if (!bf_get(lpfc_trailer_completed, mcqe))
14324 goto out_no_mqe_complete;
14326 /* Get the reference to the active mbox command */
14327 spin_lock_irqsave(&phba->hbalock, iflags);
14328 pmb = phba->sli.mbox_active;
14329 if (unlikely(!pmb)) {
14330 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14331 "1832 No pending MBOX command to handle\n");
14332 spin_unlock_irqrestore(&phba->hbalock, iflags);
14333 goto out_no_mqe_complete;
14335 spin_unlock_irqrestore(&phba->hbalock, iflags);
14337 pmbox = (MAILBOX_t *)&pmb->u.mqe;
14339 vport = pmb->vport;
14341 /* Reset heartbeat timer */
14342 phba->last_completion_time = jiffies;
14343 del_timer(&phba->sli.mbox_tmo);
14345 /* Move mbox data to caller's mailbox region, do endian swapping */
14346 if (pmb->mbox_cmpl && mbox)
14347 lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
14350 * For mcqe errors, conditionally move a modified error code to
14351 * the mbox so that the error will not be missed.
14353 mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
14354 if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
14355 if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
14356 bf_set(lpfc_mqe_status, mqe,
14357 (LPFC_MBX_ERROR_RANGE | mcqe_status));
14359 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
14360 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
14361 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
14362 "MBOX dflt rpi: status:x%x rpi:x%x",
14364 pmbox->un.varWords[0], 0);
14365 if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
14366 mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
14367 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
14369 /* Reg_LOGIN of dflt RPI was successful. Mark the
14370 * node as having an UNREG_LOGIN in progress to stop
14371 * an unsolicited PLOGI from the same NPortId from
14372 * starting another mailbox transaction.
14374 spin_lock_irqsave(&ndlp->lock, iflags);
14375 ndlp->nlp_flag |= NLP_UNREG_INP;
14376 spin_unlock_irqrestore(&ndlp->lock, iflags);
14377 lpfc_unreg_login(phba, vport->vpi,
14378 pmbox->un.varWords[0], pmb);
14379 pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
14382 /* No reference taken here. This is a default
14383 * RPI reg/immediate unreg cycle. The reference was
14384 * taken in the reg rpi path and is released when
14385 * this mailbox completes.
14387 pmb->ctx_ndlp = ndlp;
14388 pmb->vport = vport;
14389 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
14390 if (rc != MBX_BUSY)
14391 lpfc_printf_log(phba, KERN_ERR,
14394 "have been MBX_BUSY\n");
14395 if (rc != MBX_NOT_FINISHED)
14396 goto send_current_mbox;
14399 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
14400 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
14401 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
14403 /* Do NOT queue MBX_HEARTBEAT to the worker thread for processing. */
14404 if (pmbox->mbxCommand == MBX_HEARTBEAT) {
14405 spin_lock_irqsave(&phba->hbalock, iflags);
14406 /* Release the mailbox command posting token */
14407 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
14408 phba->sli.mbox_active = NULL;
14409 if (bf_get(lpfc_trailer_consumed, mcqe))
14410 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
14411 spin_unlock_irqrestore(&phba->hbalock, iflags);
14413 /* Post the next mbox command, if there is one */
14414 lpfc_sli4_post_async_mbox(phba);
14416 /* Process cmpl now */
14417 if (pmb->mbox_cmpl)
14418 pmb->mbox_cmpl(phba, pmb);
14422 /* There is mailbox completion work to queue to the worker thread */
14423 spin_lock_irqsave(&phba->hbalock, iflags);
14424 __lpfc_mbox_cmpl_put(phba, pmb);
14425 phba->work_ha |= HA_MBATT;
14426 spin_unlock_irqrestore(&phba->hbalock, iflags);
14430 spin_lock_irqsave(&phba->hbalock, iflags);
14431 /* Release the mailbox command posting token */
14432 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
14433 /* Setting active mailbox pointer need to be in sync to flag clear */
14434 phba->sli.mbox_active = NULL;
14435 if (bf_get(lpfc_trailer_consumed, mcqe))
14436 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
14437 spin_unlock_irqrestore(&phba->hbalock, iflags);
14438 /* Wake up worker thread to post the next pending mailbox command */
14439 lpfc_worker_wake_up(phba);
14442 out_no_mqe_complete:
14443 spin_lock_irqsave(&phba->hbalock, iflags);
14444 if (bf_get(lpfc_trailer_consumed, mcqe))
14445 lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
14446 spin_unlock_irqrestore(&phba->hbalock, iflags);
14451 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
14452 * @phba: Pointer to HBA context object.
14453 * @cq: Pointer to associated CQ
14454 * @cqe: Pointer to mailbox completion queue entry.
14456 * This routine process a mailbox completion queue entry, it invokes the
14457 * proper mailbox complete handling or asynchronous event handling routine
14458 * according to the MCQE's async bit.
14460 * Return: true if work posted to worker thread, otherwise false.
14463 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14464 struct lpfc_cqe *cqe)
14466 struct lpfc_mcqe mcqe;
14471 /* Copy the mailbox MCQE and convert endian order as needed */
14472 lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
14474 /* Invoke the proper event handling routine */
14475 if (!bf_get(lpfc_trailer_async, &mcqe))
14476 workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
14478 workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
14483 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
14484 * @phba: Pointer to HBA context object.
14485 * @cq: Pointer to associated CQ
14486 * @wcqe: Pointer to work-queue completion queue entry.
14488 * This routine handles an ELS work-queue completion event.
14490 * Return: true if work posted to worker thread, otherwise false.
14493 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14494 struct lpfc_wcqe_complete *wcqe)
14496 struct lpfc_iocbq *irspiocbq;
14497 unsigned long iflags;
14498 struct lpfc_sli_ring *pring = cq->pring;
14500 int txcmplq_cnt = 0;
14502 /* Check for response status */
14503 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
14504 /* Log the error status */
14505 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14506 "0357 ELS CQE error: status=x%x: "
14507 "CQE: %08x %08x %08x %08x\n",
14508 bf_get(lpfc_wcqe_c_status, wcqe),
14509 wcqe->word0, wcqe->total_data_placed,
14510 wcqe->parameter, wcqe->word3);
14513 /* Get an irspiocbq for later ELS response processing use */
14514 irspiocbq = lpfc_sli_get_iocbq(phba);
14516 if (!list_empty(&pring->txq))
14518 if (!list_empty(&pring->txcmplq))
14520 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14521 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
14522 "els_txcmplq_cnt=%d\n",
14523 txq_cnt, phba->iocb_cnt,
14528 /* Save off the slow-path queue event for work thread to process */
14529 memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
14530 spin_lock_irqsave(&phba->hbalock, iflags);
14531 list_add_tail(&irspiocbq->cq_event.list,
14532 &phba->sli4_hba.sp_queue_event);
14533 phba->hba_flag |= HBA_SP_QUEUE_EVT;
14534 spin_unlock_irqrestore(&phba->hbalock, iflags);
14540 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
14541 * @phba: Pointer to HBA context object.
14542 * @wcqe: Pointer to work-queue completion queue entry.
14544 * This routine handles slow-path WQ entry consumed event by invoking the
14545 * proper WQ release routine to the slow-path WQ.
14548 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
14549 struct lpfc_wcqe_release *wcqe)
14551 /* sanity check on queue memory */
14552 if (unlikely(!phba->sli4_hba.els_wq))
14554 /* Check for the slow-path ELS work queue */
14555 if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
14556 lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
14557 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
14559 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
14560 "2579 Slow-path wqe consume event carries "
14561 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
14562 bf_get(lpfc_wcqe_r_wqe_index, wcqe),
14563 phba->sli4_hba.els_wq->queue_id);
14567 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
14568 * @phba: Pointer to HBA context object.
14569 * @cq: Pointer to a WQ completion queue.
14570 * @wcqe: Pointer to work-queue completion queue entry.
14572 * This routine handles an XRI abort event.
14574 * Return: true if work posted to worker thread, otherwise false.
14577 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
14578 struct lpfc_queue *cq,
14579 struct sli4_wcqe_xri_aborted *wcqe)
14581 bool workposted = false;
14582 struct lpfc_cq_event *cq_event;
14583 unsigned long iflags;
14585 switch (cq->subtype) {
14587 lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
14588 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
14589 /* Notify aborted XRI for NVME work queue */
14590 if (phba->nvmet_support)
14591 lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
14593 workposted = false;
14595 case LPFC_NVME_LS: /* NVME LS uses ELS resources */
14597 cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe));
14599 workposted = false;
14602 cq_event->hdwq = cq->hdwq;
14603 spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
14605 list_add_tail(&cq_event->list,
14606 &phba->sli4_hba.sp_els_xri_aborted_work_queue);
14607 /* Set the els xri abort event flag */
14608 phba->hba_flag |= ELS_XRI_ABORT_EVENT;
14609 spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
14614 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14615 "0603 Invalid CQ subtype %d: "
14616 "%08x %08x %08x %08x\n",
14617 cq->subtype, wcqe->word0, wcqe->parameter,
14618 wcqe->word2, wcqe->word3);
14619 workposted = false;
14625 #define FC_RCTL_MDS_DIAGS 0xF4
14628 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
14629 * @phba: Pointer to HBA context object.
14630 * @rcqe: Pointer to receive-queue completion queue entry.
14632 * This routine process a receive-queue completion queue entry.
14634 * Return: true if work posted to worker thread, otherwise false.
14637 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
14639 bool workposted = false;
14640 struct fc_frame_header *fc_hdr;
14641 struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
14642 struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
14643 struct lpfc_nvmet_tgtport *tgtp;
14644 struct hbq_dmabuf *dma_buf;
14645 uint32_t status, rq_id;
14646 unsigned long iflags;
14648 /* sanity check on queue memory */
14649 if (unlikely(!hrq) || unlikely(!drq))
14652 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
14653 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
14655 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
14656 if (rq_id != hrq->queue_id)
14659 status = bf_get(lpfc_rcqe_status, rcqe);
14661 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
14662 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14663 "2537 Receive Frame Truncated!!\n");
14665 case FC_STATUS_RQ_SUCCESS:
14666 spin_lock_irqsave(&phba->hbalock, iflags);
14667 lpfc_sli4_rq_release(hrq, drq);
14668 dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
14670 hrq->RQ_no_buf_found++;
14671 spin_unlock_irqrestore(&phba->hbalock, iflags);
14675 hrq->RQ_buf_posted--;
14676 memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
14678 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
14680 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
14681 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
14682 spin_unlock_irqrestore(&phba->hbalock, iflags);
14683 /* Handle MDS Loopback frames */
14684 if (!(phba->pport->load_flag & FC_UNLOADING))
14685 lpfc_sli4_handle_mds_loopback(phba->pport,
14688 lpfc_in_buf_free(phba, &dma_buf->dbuf);
14692 /* save off the frame for the work thread to process */
14693 list_add_tail(&dma_buf->cq_event.list,
14694 &phba->sli4_hba.sp_queue_event);
14695 /* Frame received */
14696 phba->hba_flag |= HBA_SP_QUEUE_EVT;
14697 spin_unlock_irqrestore(&phba->hbalock, iflags);
14700 case FC_STATUS_INSUFF_BUF_FRM_DISC:
14701 if (phba->nvmet_support) {
14702 tgtp = phba->targetport->private;
14703 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14704 "6402 RQE Error x%x, posted %d err_cnt "
14706 status, hrq->RQ_buf_posted,
14707 hrq->RQ_no_posted_buf,
14708 atomic_read(&tgtp->rcv_fcp_cmd_in),
14709 atomic_read(&tgtp->rcv_fcp_cmd_out),
14710 atomic_read(&tgtp->xmt_fcp_release));
14714 case FC_STATUS_INSUFF_BUF_NEED_BUF:
14715 hrq->RQ_no_posted_buf++;
14716 /* Post more buffers if possible */
14717 spin_lock_irqsave(&phba->hbalock, iflags);
14718 phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
14719 spin_unlock_irqrestore(&phba->hbalock, iflags);
14728 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
14729 * @phba: Pointer to HBA context object.
14730 * @cq: Pointer to the completion queue.
14731 * @cqe: Pointer to a completion queue entry.
14733 * This routine process a slow-path work-queue or receive queue completion queue
14736 * Return: true if work posted to worker thread, otherwise false.
14739 lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
14740 struct lpfc_cqe *cqe)
14742 struct lpfc_cqe cqevt;
14743 bool workposted = false;
14745 /* Copy the work queue CQE and convert endian order if needed */
14746 lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
14748 /* Check and process for different type of WCQE and dispatch */
14749 switch (bf_get(lpfc_cqe_code, &cqevt)) {
14750 case CQE_CODE_COMPL_WQE:
14751 /* Process the WQ/RQ complete event */
14752 phba->last_completion_time = jiffies;
14753 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
14754 (struct lpfc_wcqe_complete *)&cqevt);
14756 case CQE_CODE_RELEASE_WQE:
14757 /* Process the WQ release event */
14758 lpfc_sli4_sp_handle_rel_wcqe(phba,
14759 (struct lpfc_wcqe_release *)&cqevt);
14761 case CQE_CODE_XRI_ABORTED:
14762 /* Process the WQ XRI abort event */
14763 phba->last_completion_time = jiffies;
14764 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
14765 (struct sli4_wcqe_xri_aborted *)&cqevt);
14767 case CQE_CODE_RECEIVE:
14768 case CQE_CODE_RECEIVE_V1:
14769 /* Process the RQ event */
14770 phba->last_completion_time = jiffies;
14771 workposted = lpfc_sli4_sp_handle_rcqe(phba,
14772 (struct lpfc_rcqe *)&cqevt);
14775 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14776 "0388 Not a valid WCQE code: x%x\n",
14777 bf_get(lpfc_cqe_code, &cqevt));
14784 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
14785 * @phba: Pointer to HBA context object.
14786 * @eqe: Pointer to fast-path event queue entry.
14787 * @speq: Pointer to slow-path event queue.
14789 * This routine process a event queue entry from the slow-path event queue.
14790 * It will check the MajorCode and MinorCode to determine this is for a
14791 * completion event on a completion queue, if not, an error shall be logged
14792 * and just return. Otherwise, it will get to the corresponding completion
14793 * queue and process all the entries on that completion queue, rearm the
14794 * completion queue, and then return.
14798 lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
14799 struct lpfc_queue *speq)
14801 struct lpfc_queue *cq = NULL, *childq;
14805 /* Get the reference to the corresponding CQ */
14806 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
14808 list_for_each_entry(childq, &speq->child_list, list) {
14809 if (childq->queue_id == cqid) {
14814 if (unlikely(!cq)) {
14815 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
14816 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14817 "0365 Slow-path CQ identifier "
14818 "(%d) does not exist\n", cqid);
14822 /* Save EQ associated with this CQ */
14823 cq->assoc_qp = speq;
14825 if (is_kdump_kernel())
14826 ret = queue_work(phba->wq, &cq->spwork);
14828 ret = queue_work_on(cq->chann, phba->wq, &cq->spwork);
14831 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14832 "0390 Cannot schedule queue work "
14833 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
14834 cqid, cq->queue_id, raw_smp_processor_id());
14838 * __lpfc_sli4_process_cq - Process elements of a CQ
14839 * @phba: Pointer to HBA context object.
14840 * @cq: Pointer to CQ to be processed
14841 * @handler: Routine to process each cqe
14842 * @delay: Pointer to usdelay to set in case of rescheduling of the handler
14843 * @poll_mode: Polling mode we were called from
14845 * This routine processes completion queue entries in a CQ. While a valid
14846 * queue element is found, the handler is called. During processing checks
14847 * are made for periodic doorbell writes to let the hardware know of
14848 * element consumption.
14850 * If the max limit on cqes to process is hit, or there are no more valid
14851 * entries, the loop stops. If we processed a sufficient number of elements,
14852 * meaning there is sufficient load, rather than rearming and generating
14853 * another interrupt, a cq rescheduling delay will be set. A delay of 0
14854 * indicates no rescheduling.
14856 * Returns True if work scheduled, False otherwise.
14859 __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
14860 bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
14861 struct lpfc_cqe *), unsigned long *delay,
14862 enum lpfc_poll_mode poll_mode)
14864 struct lpfc_cqe *cqe;
14865 bool workposted = false;
14866 int count = 0, consumed = 0;
14869 /* default - no reschedule */
14872 if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
14873 goto rearm_and_exit;
14875 /* Process all the entries to the CQ */
14877 cqe = lpfc_sli4_cq_get(cq);
14879 workposted |= handler(phba, cq, cqe);
14880 __lpfc_sli4_consume_cqe(phba, cq, cqe);
14883 if (!(++count % cq->max_proc_limit))
14886 if (!(count % cq->notify_interval)) {
14887 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
14890 cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK;
14893 if (count == LPFC_NVMET_CQ_NOTIFY)
14894 cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
14896 cqe = lpfc_sli4_cq_get(cq);
14898 if (count >= phba->cfg_cq_poll_threshold) {
14903 /* Note: complete the irq_poll softirq before rearming CQ */
14904 if (poll_mode == LPFC_IRQ_POLL)
14905 irq_poll_complete(&cq->iop);
14907 /* Track the max number of CQEs processed in 1 EQ */
14908 if (count > cq->CQ_max_cqe)
14909 cq->CQ_max_cqe = count;
14911 cq->assoc_qp->EQ_cqe_cnt += count;
14913 /* Catch the no cq entry condition */
14914 if (unlikely(count == 0))
14915 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
14916 "0369 No entry from completion queue "
14917 "qid=%d\n", cq->queue_id);
14919 xchg(&cq->queue_claimed, 0);
14922 phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
14923 arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
14929 * __lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
14930 * @cq: pointer to CQ to process
14932 * This routine calls the cq processing routine with a handler specific
14933 * to the type of queue bound to it.
14935 * The CQ routine returns two values: the first is the calling status,
14936 * which indicates whether work was queued to the background discovery
14937 * thread. If true, the routine should wakeup the discovery thread;
14938 * the second is the delay parameter. If non-zero, rather than rearming
14939 * the CQ and yet another interrupt, the CQ handler should be queued so
14940 * that it is processed in a subsequent polling action. The value of
14941 * the delay indicates when to reschedule it.
14944 __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
14946 struct lpfc_hba *phba = cq->phba;
14947 unsigned long delay;
14948 bool workposted = false;
14951 /* Process and rearm the CQ */
14952 switch (cq->type) {
14954 workposted |= __lpfc_sli4_process_cq(phba, cq,
14955 lpfc_sli4_sp_handle_mcqe,
14956 &delay, LPFC_QUEUE_WORK);
14959 if (cq->subtype == LPFC_IO)
14960 workposted |= __lpfc_sli4_process_cq(phba, cq,
14961 lpfc_sli4_fp_handle_cqe,
14962 &delay, LPFC_QUEUE_WORK);
14964 workposted |= __lpfc_sli4_process_cq(phba, cq,
14965 lpfc_sli4_sp_handle_cqe,
14966 &delay, LPFC_QUEUE_WORK);
14969 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14970 "0370 Invalid completion queue type (%d)\n",
14976 if (is_kdump_kernel())
14977 ret = queue_delayed_work(phba->wq, &cq->sched_spwork,
14980 ret = queue_delayed_work_on(cq->chann, phba->wq,
14981 &cq->sched_spwork, delay);
14983 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
14984 "0394 Cannot schedule queue work "
14985 "for cqid=%d on CPU %d\n",
14986 cq->queue_id, cq->chann);
14989 /* wake up worker thread if there are works to be done */
14991 lpfc_worker_wake_up(phba);
14995 * lpfc_sli4_sp_process_cq - slow-path work handler when started by
14997 * @work: pointer to work element
14999 * translates from the work handler and calls the slow-path handler.
15002 lpfc_sli4_sp_process_cq(struct work_struct *work)
15004 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
15006 __lpfc_sli4_sp_process_cq(cq);
15010 * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
15011 * @work: pointer to work element
15013 * translates from the work handler and calls the slow-path handler.
15016 lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
15018 struct lpfc_queue *cq = container_of(to_delayed_work(work),
15019 struct lpfc_queue, sched_spwork);
15021 __lpfc_sli4_sp_process_cq(cq);
15025 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
15026 * @phba: Pointer to HBA context object.
15027 * @cq: Pointer to associated CQ
15028 * @wcqe: Pointer to work-queue completion queue entry.
15030 * This routine process a fast-path work queue completion entry from fast-path
15031 * event queue for FCP command response completion.
15034 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15035 struct lpfc_wcqe_complete *wcqe)
15037 struct lpfc_sli_ring *pring = cq->pring;
15038 struct lpfc_iocbq *cmdiocbq;
15039 unsigned long iflags;
15041 /* Check for response status */
15042 if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
15043 /* If resource errors reported from HBA, reduce queue
15044 * depth of the SCSI device.
15046 if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
15047 IOSTAT_LOCAL_REJECT)) &&
15048 ((wcqe->parameter & IOERR_PARAM_MASK) ==
15049 IOERR_NO_RESOURCES))
15050 phba->lpfc_rampdown_queue_depth(phba);
15052 /* Log the cmpl status */
15053 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
15054 "0373 FCP CQE cmpl: status=x%x: "
15055 "CQE: %08x %08x %08x %08x\n",
15056 bf_get(lpfc_wcqe_c_status, wcqe),
15057 wcqe->word0, wcqe->total_data_placed,
15058 wcqe->parameter, wcqe->word3);
15061 /* Look up the FCP command IOCB and create pseudo response IOCB */
15062 spin_lock_irqsave(&pring->ring_lock, iflags);
15063 pring->stats.iocb_event++;
15064 cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
15065 bf_get(lpfc_wcqe_c_request_tag, wcqe));
15066 spin_unlock_irqrestore(&pring->ring_lock, iflags);
15067 if (unlikely(!cmdiocbq)) {
15068 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15069 "0374 FCP complete with no corresponding "
15070 "cmdiocb: iotag (%d)\n",
15071 bf_get(lpfc_wcqe_c_request_tag, wcqe));
15074 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
15075 cmdiocbq->isr_timestamp = cq->isr_timestamp;
15077 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
15078 spin_lock_irqsave(&phba->hbalock, iflags);
15079 cmdiocbq->cmd_flag |= LPFC_EXCHANGE_BUSY;
15080 spin_unlock_irqrestore(&phba->hbalock, iflags);
15083 if (cmdiocbq->cmd_cmpl) {
15084 /* For FCP the flag is cleared in cmd_cmpl */
15085 if (!(cmdiocbq->cmd_flag & LPFC_IO_FCP) &&
15086 cmdiocbq->cmd_flag & LPFC_DRIVER_ABORTED) {
15087 spin_lock_irqsave(&phba->hbalock, iflags);
15088 cmdiocbq->cmd_flag &= ~LPFC_DRIVER_ABORTED;
15089 spin_unlock_irqrestore(&phba->hbalock, iflags);
15092 /* Pass the cmd_iocb and the wcqe to the upper layer */
15093 memcpy(&cmdiocbq->wcqe_cmpl, wcqe,
15094 sizeof(struct lpfc_wcqe_complete));
15095 cmdiocbq->cmd_cmpl(phba, cmdiocbq, cmdiocbq);
15097 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15098 "0375 FCP cmdiocb not callback function "
15100 bf_get(lpfc_wcqe_c_request_tag, wcqe));
15105 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
15106 * @phba: Pointer to HBA context object.
15107 * @cq: Pointer to completion queue.
15108 * @wcqe: Pointer to work-queue completion queue entry.
15110 * This routine handles an fast-path WQ entry consumed event by invoking the
15111 * proper WQ release routine to the slow-path WQ.
15114 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15115 struct lpfc_wcqe_release *wcqe)
15117 struct lpfc_queue *childwq;
15118 bool wqid_matched = false;
15121 /* Check for fast-path FCP work queue release */
15122 hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
15123 list_for_each_entry(childwq, &cq->child_list, list) {
15124 if (childwq->queue_id == hba_wqid) {
15125 lpfc_sli4_wq_release(childwq,
15126 bf_get(lpfc_wcqe_r_wqe_index, wcqe));
15127 if (childwq->q_flag & HBA_NVMET_WQFULL)
15128 lpfc_nvmet_wqfull_process(phba, childwq);
15129 wqid_matched = true;
15133 /* Report warning log message if no match found */
15134 if (wqid_matched != true)
15135 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15136 "2580 Fast-path wqe consume event carries "
15137 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
15141 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
15142 * @phba: Pointer to HBA context object.
15143 * @cq: Pointer to completion queue.
15144 * @rcqe: Pointer to receive-queue completion queue entry.
15146 * This routine process a receive-queue completion queue entry.
15148 * Return: true if work posted to worker thread, otherwise false.
15151 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15152 struct lpfc_rcqe *rcqe)
15154 bool workposted = false;
15155 struct lpfc_queue *hrq;
15156 struct lpfc_queue *drq;
15157 struct rqb_dmabuf *dma_buf;
15158 struct fc_frame_header *fc_hdr;
15159 struct lpfc_nvmet_tgtport *tgtp;
15160 uint32_t status, rq_id;
15161 unsigned long iflags;
15162 uint32_t fctl, idx;
15164 if ((phba->nvmet_support == 0) ||
15165 (phba->sli4_hba.nvmet_cqset == NULL))
15168 idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
15169 hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
15170 drq = phba->sli4_hba.nvmet_mrq_data[idx];
15172 /* sanity check on queue memory */
15173 if (unlikely(!hrq) || unlikely(!drq))
15176 if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
15177 rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
15179 rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
15181 if ((phba->nvmet_support == 0) ||
15182 (rq_id != hrq->queue_id))
15185 status = bf_get(lpfc_rcqe_status, rcqe);
15187 case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
15188 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15189 "6126 Receive Frame Truncated!!\n");
15191 case FC_STATUS_RQ_SUCCESS:
15192 spin_lock_irqsave(&phba->hbalock, iflags);
15193 lpfc_sli4_rq_release(hrq, drq);
15194 dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
15196 hrq->RQ_no_buf_found++;
15197 spin_unlock_irqrestore(&phba->hbalock, iflags);
15200 spin_unlock_irqrestore(&phba->hbalock, iflags);
15202 hrq->RQ_buf_posted--;
15203 fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
15205 /* Just some basic sanity checks on FCP Command frame */
15206 fctl = (fc_hdr->fh_f_ctl[0] << 16 |
15207 fc_hdr->fh_f_ctl[1] << 8 |
15208 fc_hdr->fh_f_ctl[2]);
15210 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
15211 (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
15212 (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
15215 if (fc_hdr->fh_type == FC_TYPE_FCP) {
15216 dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
15217 lpfc_nvmet_unsol_fcp_event(
15218 phba, idx, dma_buf, cq->isr_timestamp,
15219 cq->q_flag & HBA_NVMET_CQ_NOTIFY);
15223 lpfc_rq_buf_free(phba, &dma_buf->hbuf);
15225 case FC_STATUS_INSUFF_BUF_FRM_DISC:
15226 if (phba->nvmet_support) {
15227 tgtp = phba->targetport->private;
15228 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15229 "6401 RQE Error x%x, posted %d err_cnt "
15231 status, hrq->RQ_buf_posted,
15232 hrq->RQ_no_posted_buf,
15233 atomic_read(&tgtp->rcv_fcp_cmd_in),
15234 atomic_read(&tgtp->rcv_fcp_cmd_out),
15235 atomic_read(&tgtp->xmt_fcp_release));
15239 case FC_STATUS_INSUFF_BUF_NEED_BUF:
15240 hrq->RQ_no_posted_buf++;
15241 /* Post more buffers if possible */
15249 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
15250 * @phba: adapter with cq
15251 * @cq: Pointer to the completion queue.
15252 * @cqe: Pointer to fast-path completion queue entry.
15254 * This routine process a fast-path work queue completion entry from fast-path
15255 * event queue for FCP command response completion.
15257 * Return: true if work posted to worker thread, otherwise false.
15260 lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
15261 struct lpfc_cqe *cqe)
15263 struct lpfc_wcqe_release wcqe;
15264 bool workposted = false;
15266 /* Copy the work queue CQE and convert endian order if needed */
15267 lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
15269 /* Check and process for different type of WCQE and dispatch */
15270 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
15271 case CQE_CODE_COMPL_WQE:
15272 case CQE_CODE_NVME_ERSP:
15274 /* Process the WQ complete event */
15275 phba->last_completion_time = jiffies;
15276 if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
15277 lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
15278 (struct lpfc_wcqe_complete *)&wcqe);
15280 case CQE_CODE_RELEASE_WQE:
15281 cq->CQ_release_wqe++;
15282 /* Process the WQ release event */
15283 lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
15284 (struct lpfc_wcqe_release *)&wcqe);
15286 case CQE_CODE_XRI_ABORTED:
15287 cq->CQ_xri_aborted++;
15288 /* Process the WQ XRI abort event */
15289 phba->last_completion_time = jiffies;
15290 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
15291 (struct sli4_wcqe_xri_aborted *)&wcqe);
15293 case CQE_CODE_RECEIVE_V1:
15294 case CQE_CODE_RECEIVE:
15295 phba->last_completion_time = jiffies;
15296 if (cq->subtype == LPFC_NVMET) {
15297 workposted = lpfc_sli4_nvmet_handle_rcqe(
15298 phba, cq, (struct lpfc_rcqe *)&wcqe);
15302 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15303 "0144 Not a valid CQE code: x%x\n",
15304 bf_get(lpfc_wcqe_c_code, &wcqe));
15311 * lpfc_sli4_sched_cq_work - Schedules cq work
15312 * @phba: Pointer to HBA context object.
15313 * @cq: Pointer to CQ
15316 * This routine checks the poll mode of the CQ corresponding to
15317 * cq->chann, then either schedules a softirq or queue_work to complete
15320 * queue_work path is taken if in NVMET mode, or if poll_mode is in
15321 * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken.
15324 static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba,
15325 struct lpfc_queue *cq, uint16_t cqid)
15329 switch (cq->poll_mode) {
15330 case LPFC_IRQ_POLL:
15331 /* CGN mgmt is mutually exclusive from softirq processing */
15332 if (phba->cmf_active_mode == LPFC_CFG_OFF) {
15333 irq_poll_sched(&cq->iop);
15337 case LPFC_QUEUE_WORK:
15339 if (is_kdump_kernel())
15340 ret = queue_work(phba->wq, &cq->irqwork);
15342 ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork);
15344 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15345 "0383 Cannot schedule queue work "
15346 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
15347 cqid, cq->queue_id,
15348 raw_smp_processor_id());
15353 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
15354 * @phba: Pointer to HBA context object.
15355 * @eq: Pointer to the queue structure.
15356 * @eqe: Pointer to fast-path event queue entry.
15358 * This routine process a event queue entry from the fast-path event queue.
15359 * It will check the MajorCode and MinorCode to determine this is for a
15360 * completion event on a completion queue, if not, an error shall be logged
15361 * and just return. Otherwise, it will get to the corresponding completion
15362 * queue and process all the entries on the completion queue, rearm the
15363 * completion queue, and then return.
15366 lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
15367 struct lpfc_eqe *eqe)
15369 struct lpfc_queue *cq = NULL;
15370 uint32_t qidx = eq->hdwq;
15373 if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
15374 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15375 "0366 Not a valid completion "
15376 "event: majorcode=x%x, minorcode=x%x\n",
15377 bf_get_le32(lpfc_eqe_major_code, eqe),
15378 bf_get_le32(lpfc_eqe_minor_code, eqe));
15382 /* Get the reference to the corresponding CQ */
15383 cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
15385 /* Use the fast lookup method first */
15386 if (cqid <= phba->sli4_hba.cq_max) {
15387 cq = phba->sli4_hba.cq_lookup[cqid];
15392 /* Next check for NVMET completion */
15393 if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
15394 id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
15395 if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
15396 /* Process NVMET unsol rcv */
15397 cq = phba->sli4_hba.nvmet_cqset[cqid - id];
15402 if (phba->sli4_hba.nvmels_cq &&
15403 (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
15404 /* Process NVME unsol rcv */
15405 cq = phba->sli4_hba.nvmels_cq;
15408 /* Otherwise this is a Slow path event */
15410 lpfc_sli4_sp_handle_eqe(phba, eqe,
15411 phba->sli4_hba.hdwq[qidx].hba_eq);
15416 if (unlikely(cqid != cq->queue_id)) {
15417 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15418 "0368 Miss-matched fast-path completion "
15419 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
15420 cqid, cq->queue_id);
15425 #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
15426 if (phba->ktime_on)
15427 cq->isr_timestamp = ktime_get_ns();
15429 cq->isr_timestamp = 0;
15431 lpfc_sli4_sched_cq_work(phba, cq, cqid);
15435 * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
15436 * @cq: Pointer to CQ to be processed
15437 * @poll_mode: Enum lpfc_poll_state to determine poll mode
15439 * This routine calls the cq processing routine with the handler for
15442 * The CQ routine returns two values: the first is the calling status,
15443 * which indicates whether work was queued to the background discovery
15444 * thread. If true, the routine should wakeup the discovery thread;
15445 * the second is the delay parameter. If non-zero, rather than rearming
15446 * the CQ and yet another interrupt, the CQ handler should be queued so
15447 * that it is processed in a subsequent polling action. The value of
15448 * the delay indicates when to reschedule it.
15451 __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq,
15452 enum lpfc_poll_mode poll_mode)
15454 struct lpfc_hba *phba = cq->phba;
15455 unsigned long delay;
15456 bool workposted = false;
15459 /* process and rearm the CQ */
15460 workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
15461 &delay, poll_mode);
15464 if (is_kdump_kernel())
15465 ret = queue_delayed_work(phba->wq, &cq->sched_irqwork,
15468 ret = queue_delayed_work_on(cq->chann, phba->wq,
15469 &cq->sched_irqwork, delay);
15471 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15472 "0367 Cannot schedule queue work "
15473 "for cqid=%d on CPU %d\n",
15474 cq->queue_id, cq->chann);
15477 /* wake up worker thread if there are works to be done */
15479 lpfc_worker_wake_up(phba);
15483 * lpfc_sli4_hba_process_cq - fast-path work handler when started by
15485 * @work: pointer to work element
15487 * translates from the work handler and calls the fast-path handler.
15490 lpfc_sli4_hba_process_cq(struct work_struct *work)
15492 struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
15494 __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
15498 * lpfc_sli4_dly_hba_process_cq - fast-path work handler when started by timer
15499 * @work: pointer to work element
15501 * translates from the work handler and calls the fast-path handler.
15504 lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
15506 struct lpfc_queue *cq = container_of(to_delayed_work(work),
15507 struct lpfc_queue, sched_irqwork);
15509 __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
15513 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
15514 * @irq: Interrupt number.
15515 * @dev_id: The device context pointer.
15517 * This function is directly called from the PCI layer as an interrupt
15518 * service routine when device with SLI-4 interface spec is enabled with
15519 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
15520 * ring event in the HBA. However, when the device is enabled with either
15521 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
15522 * device-level interrupt handler. When the PCI slot is in error recovery
15523 * or the HBA is undergoing initialization, the interrupt handler will not
15524 * process the interrupt. The SCSI FCP fast-path ring event are handled in
15525 * the intrrupt context. This function is called without any lock held.
15526 * It gets the hbalock to access and update SLI data structures. Note that,
15527 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
15528 * equal to that of FCP CQ index.
15530 * The link attention and ELS ring attention events are handled
15531 * by the worker thread. The interrupt handler signals the worker thread
15532 * and returns for these events. This function is called without any lock
15533 * held. It gets the hbalock to access and update SLI data structures.
15535 * This function returns IRQ_HANDLED when interrupt is handled else it
15536 * returns IRQ_NONE.
15539 lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
15541 struct lpfc_hba *phba;
15542 struct lpfc_hba_eq_hdl *hba_eq_hdl;
15543 struct lpfc_queue *fpeq;
15544 unsigned long iflag;
15547 struct lpfc_eq_intr_info *eqi;
15549 /* Get the driver's phba structure from the dev_id */
15550 hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
15551 phba = hba_eq_hdl->phba;
15552 hba_eqidx = hba_eq_hdl->idx;
15554 if (unlikely(!phba))
15556 if (unlikely(!phba->sli4_hba.hdwq))
15559 /* Get to the EQ struct associated with this vector */
15560 fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
15561 if (unlikely(!fpeq))
15564 /* Check device state for handling interrupt */
15565 if (unlikely(lpfc_intr_state_check(phba))) {
15566 /* Check again for link_state with lock held */
15567 spin_lock_irqsave(&phba->hbalock, iflag);
15568 if (phba->link_state < LPFC_LINK_DOWN)
15569 /* Flush, clear interrupt, and rearm the EQ */
15570 lpfc_sli4_eqcq_flush(phba, fpeq);
15571 spin_unlock_irqrestore(&phba->hbalock, iflag);
15575 eqi = this_cpu_ptr(phba->sli4_hba.eq_info);
15578 fpeq->last_cpu = raw_smp_processor_id();
15580 if (eqi->icnt > LPFC_EQD_ISR_TRIGGER &&
15581 fpeq->q_flag & HBA_EQ_DELAY_CHK &&
15582 phba->cfg_auto_imax &&
15583 fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
15584 phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
15585 lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
15587 /* process and rearm the EQ */
15588 ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
15590 if (unlikely(ecount == 0)) {
15591 fpeq->EQ_no_entry++;
15592 if (phba->intr_type == MSIX)
15593 /* MSI-X treated interrupt served as no EQ share INT */
15594 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
15595 "0358 MSI-X interrupt with no EQE\n");
15597 /* Non MSI-X treated on interrupt as EQ share INT */
15601 return IRQ_HANDLED;
15602 } /* lpfc_sli4_hba_intr_handler */
15605 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
15606 * @irq: Interrupt number.
15607 * @dev_id: The device context pointer.
15609 * This function is the device-level interrupt handler to device with SLI-4
15610 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
15611 * interrupt mode is enabled and there is an event in the HBA which requires
15612 * driver attention. This function invokes the slow-path interrupt attention
15613 * handling function and fast-path interrupt attention handling function in
15614 * turn to process the relevant HBA attention events. This function is called
15615 * without any lock held. It gets the hbalock to access and update SLI data
15618 * This function returns IRQ_HANDLED when interrupt is handled, else it
15619 * returns IRQ_NONE.
15622 lpfc_sli4_intr_handler(int irq, void *dev_id)
15624 struct lpfc_hba *phba;
15625 irqreturn_t hba_irq_rc;
15626 bool hba_handled = false;
15629 /* Get the driver's phba structure from the dev_id */
15630 phba = (struct lpfc_hba *)dev_id;
15632 if (unlikely(!phba))
15636 * Invoke fast-path host attention interrupt handling as appropriate.
15638 for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
15639 hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
15640 &phba->sli4_hba.hba_eq_hdl[qidx]);
15641 if (hba_irq_rc == IRQ_HANDLED)
15642 hba_handled |= true;
15645 return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
15646 } /* lpfc_sli4_intr_handler */
15648 void lpfc_sli4_poll_hbtimer(struct timer_list *t)
15650 struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer);
15651 struct lpfc_queue *eq;
15655 list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list)
15656 lpfc_sli4_poll_eq(eq);
15657 if (!list_empty(&phba->poll_list))
15658 mod_timer(&phba->cpuhp_poll_timer,
15659 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
15664 static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq)
15666 struct lpfc_hba *phba = eq->phba;
15668 /* kickstart slowpath processing if needed */
15669 if (list_empty(&phba->poll_list))
15670 mod_timer(&phba->cpuhp_poll_timer,
15671 jiffies + msecs_to_jiffies(LPFC_POLL_HB));
15673 list_add_rcu(&eq->_poll_list, &phba->poll_list);
15677 static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq)
15679 struct lpfc_hba *phba = eq->phba;
15681 /* Disable slowpath processing for this eq. Kick start the eq
15682 * by RE-ARMING the eq's ASAP
15684 list_del_rcu(&eq->_poll_list);
15687 if (list_empty(&phba->poll_list))
15688 del_timer_sync(&phba->cpuhp_poll_timer);
15691 void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba)
15693 struct lpfc_queue *eq, *next;
15695 list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list)
15696 list_del(&eq->_poll_list);
15698 INIT_LIST_HEAD(&phba->poll_list);
15703 __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode)
15705 if (mode == eq->mode)
15708 * currently this function is only called during a hotplug
15709 * event and the cpu on which this function is executing
15710 * is going offline. By now the hotplug has instructed
15711 * the scheduler to remove this cpu from cpu active mask.
15712 * So we don't need to work about being put aside by the
15713 * scheduler for a high priority process. Yes, the inte-
15714 * rrupts could come but they are known to retire ASAP.
15717 /* Disable polling in the fastpath */
15718 WRITE_ONCE(eq->mode, mode);
15719 /* flush out the store buffer */
15723 * Add this eq to the polling list and start polling. For
15724 * a grace period both interrupt handler and poller will
15725 * try to process the eq _but_ that's fine. We have a
15726 * synchronization mechanism in place (queue_claimed) to
15727 * deal with it. This is just a draining phase for int-
15728 * errupt handler (not eq's) as we have guranteed through
15729 * barrier that all the CPUs have seen the new CQ_POLLED
15730 * state. which will effectively disable the REARMING of
15731 * the EQ. The whole idea is eq's die off eventually as
15732 * we are not rearming EQ's anymore.
15734 mode ? lpfc_sli4_add_to_poll_list(eq) :
15735 lpfc_sli4_remove_from_poll_list(eq);
15738 void lpfc_sli4_start_polling(struct lpfc_queue *eq)
15740 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL);
15743 void lpfc_sli4_stop_polling(struct lpfc_queue *eq)
15745 struct lpfc_hba *phba = eq->phba;
15747 __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT);
15749 /* Kick start for the pending io's in h/w.
15750 * Once we switch back to interrupt processing on a eq
15751 * the io path completion will only arm eq's when it
15752 * receives a completion. But since eq's are in disa-
15753 * rmed state it doesn't receive a completion. This
15754 * creates a deadlock scenaro.
15756 phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM);
15760 * lpfc_sli4_queue_free - free a queue structure and associated memory
15761 * @queue: The queue structure to free.
15763 * This function frees a queue structure and the DMAable memory used for
15764 * the host resident queue. This function must be called after destroying the
15765 * queue on the HBA.
15768 lpfc_sli4_queue_free(struct lpfc_queue *queue)
15770 struct lpfc_dmabuf *dmabuf;
15775 if (!list_empty(&queue->wq_list))
15776 list_del(&queue->wq_list);
15778 while (!list_empty(&queue->page_list)) {
15779 list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
15781 dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
15782 dmabuf->virt, dmabuf->phys);
15786 lpfc_free_rq_buffer(queue->phba, queue);
15787 kfree(queue->rqbp);
15790 if (!list_empty(&queue->cpu_list))
15791 list_del(&queue->cpu_list);
15798 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
15799 * @phba: The HBA that this queue is being created on.
15800 * @page_size: The size of a queue page
15801 * @entry_size: The size of each queue entry for this queue.
15802 * @entry_count: The number of entries that this queue will handle.
15803 * @cpu: The cpu that will primarily utilize this queue.
15805 * This function allocates a queue structure and the DMAable memory used for
15806 * the host resident queue. This function must be called before creating the
15807 * queue on the HBA.
15809 struct lpfc_queue *
15810 lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
15811 uint32_t entry_size, uint32_t entry_count, int cpu)
15813 struct lpfc_queue *queue;
15814 struct lpfc_dmabuf *dmabuf;
15815 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
15818 if (!phba->sli4_hba.pc_sli4_params.supported)
15819 hw_page_size = page_size;
15821 pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
15823 /* If needed, Adjust page count to match the max the adapter supports */
15824 if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
15825 pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
15827 queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
15828 GFP_KERNEL, cpu_to_node(cpu));
15832 INIT_LIST_HEAD(&queue->list);
15833 INIT_LIST_HEAD(&queue->_poll_list);
15834 INIT_LIST_HEAD(&queue->wq_list);
15835 INIT_LIST_HEAD(&queue->wqfull_list);
15836 INIT_LIST_HEAD(&queue->page_list);
15837 INIT_LIST_HEAD(&queue->child_list);
15838 INIT_LIST_HEAD(&queue->cpu_list);
15840 /* Set queue parameters now. If the system cannot provide memory
15841 * resources, the free routine needs to know what was allocated.
15843 queue->page_count = pgcnt;
15844 queue->q_pgs = (void **)&queue[1];
15845 queue->entry_cnt_per_pg = hw_page_size / entry_size;
15846 queue->entry_size = entry_size;
15847 queue->entry_count = entry_count;
15848 queue->page_size = hw_page_size;
15849 queue->phba = phba;
15851 for (x = 0; x < queue->page_count; x++) {
15852 dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
15853 dev_to_node(&phba->pcidev->dev));
15856 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
15857 hw_page_size, &dmabuf->phys,
15859 if (!dmabuf->virt) {
15863 dmabuf->buffer_tag = x;
15864 list_add_tail(&dmabuf->list, &queue->page_list);
15865 /* use lpfc_sli4_qe to index a paritcular entry in this page */
15866 queue->q_pgs[x] = dmabuf->virt;
15868 INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
15869 INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
15870 INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
15871 INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
15873 /* notify_interval will be set during q creation */
15877 lpfc_sli4_queue_free(queue);
15882 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
15883 * @phba: HBA structure that indicates port to create a queue on.
15884 * @pci_barset: PCI BAR set flag.
15886 * This function shall perform iomap of the specified PCI BAR address to host
15887 * memory address if not already done so and return it. The returned host
15888 * memory address can be NULL.
15890 static void __iomem *
15891 lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
15896 switch (pci_barset) {
15897 case WQ_PCI_BAR_0_AND_1:
15898 return phba->pci_bar0_memmap_p;
15899 case WQ_PCI_BAR_2_AND_3:
15900 return phba->pci_bar2_memmap_p;
15901 case WQ_PCI_BAR_4_AND_5:
15902 return phba->pci_bar4_memmap_p;
15910 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
15911 * @phba: HBA structure that EQs are on.
15912 * @startq: The starting EQ index to modify
15913 * @numq: The number of EQs (consecutive indexes) to modify
15914 * @usdelay: amount of delay
15916 * This function revises the EQ delay on 1 or more EQs. The EQ delay
15917 * is set either by writing to a register (if supported by the SLI Port)
15918 * or by mailbox command. The mailbox command allows several EQs to be
15921 * The @phba struct is used to send a mailbox command to HBA. The @startq
15922 * is used to get the starting EQ index to change. The @numq value is
15923 * used to specify how many consecutive EQ indexes, starting at EQ index,
15924 * are to be changed. This function is asynchronous and will wait for any
15925 * mailbox commands to finish before returning.
15927 * On success this function will return a zero. If unable to allocate
15928 * enough memory this function will return -ENOMEM. If a mailbox command
15929 * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
15930 * have had their delay multipler changed.
15933 lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
15934 uint32_t numq, uint32_t usdelay)
15936 struct lpfc_mbx_modify_eq_delay *eq_delay;
15937 LPFC_MBOXQ_t *mbox;
15938 struct lpfc_queue *eq;
15939 int cnt = 0, rc, length;
15940 uint32_t shdr_status, shdr_add_status;
15943 union lpfc_sli4_cfg_shdr *shdr;
15945 if (startq >= phba->cfg_irq_chann)
15948 if (usdelay > 0xFFFF) {
15949 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
15950 "6429 usdelay %d too large. Scaled down to "
15951 "0xFFFF.\n", usdelay);
15955 /* set values by EQ_DELAY register if supported */
15956 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
15957 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
15958 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
15962 lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
15970 /* Otherwise, set values by mailbox cmd */
15972 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
15974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
15975 "6428 Failed allocating mailbox cmd buffer."
15976 " EQ delay was not set.\n");
15979 length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
15980 sizeof(struct lpfc_sli4_cfg_mhdr));
15981 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
15982 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
15983 length, LPFC_SLI4_MBX_EMBED);
15984 eq_delay = &mbox->u.mqe.un.eq_delay;
15986 /* Calculate delay multiper from maximum interrupt per second */
15987 dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
15990 if (dmult > LPFC_DMULT_MAX)
15991 dmult = LPFC_DMULT_MAX;
15993 for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
15994 eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
15997 eq->q_mode = usdelay;
15998 eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
15999 eq_delay->u.request.eq[cnt].phase = 0;
16000 eq_delay->u.request.eq[cnt].delay_multi = dmult;
16005 eq_delay->u.request.num_eq = cnt;
16007 mbox->vport = phba->pport;
16008 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16009 mbox->ctx_ndlp = NULL;
16010 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16011 shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
16012 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16013 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16014 if (shdr_status || shdr_add_status || rc) {
16015 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16016 "2512 MODIFY_EQ_DELAY mailbox failed with "
16017 "status x%x add_status x%x, mbx status x%x\n",
16018 shdr_status, shdr_add_status, rc);
16020 mempool_free(mbox, phba->mbox_mem_pool);
16025 * lpfc_eq_create - Create an Event Queue on the HBA
16026 * @phba: HBA structure that indicates port to create a queue on.
16027 * @eq: The queue structure to use to create the event queue.
16028 * @imax: The maximum interrupt per second limit.
16030 * This function creates an event queue, as detailed in @eq, on a port,
16031 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
16033 * The @phba struct is used to send mailbox command to HBA. The @eq struct
16034 * is used to get the entry count and entry size that are necessary to
16035 * determine the number of pages to allocate and use for this queue. This
16036 * function will send the EQ_CREATE mailbox command to the HBA to setup the
16037 * event queue. This function is asynchronous and will wait for the mailbox
16038 * command to finish before continuing.
16040 * On success this function will return a zero. If unable to allocate enough
16041 * memory this function will return -ENOMEM. If the queue create mailbox command
16042 * fails this function will return -ENXIO.
16045 lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
16047 struct lpfc_mbx_eq_create *eq_create;
16048 LPFC_MBOXQ_t *mbox;
16049 int rc, length, status = 0;
16050 struct lpfc_dmabuf *dmabuf;
16051 uint32_t shdr_status, shdr_add_status;
16052 union lpfc_sli4_cfg_shdr *shdr;
16054 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16056 /* sanity check on queue memory */
16059 if (!phba->sli4_hba.pc_sli4_params.supported)
16060 hw_page_size = SLI4_PAGE_SIZE;
16062 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16065 length = (sizeof(struct lpfc_mbx_eq_create) -
16066 sizeof(struct lpfc_sli4_cfg_mhdr));
16067 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16068 LPFC_MBOX_OPCODE_EQ_CREATE,
16069 length, LPFC_SLI4_MBX_EMBED);
16070 eq_create = &mbox->u.mqe.un.eq_create;
16071 shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
16072 bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
16074 bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
16076 bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
16078 /* Use version 2 of CREATE_EQ if eqav is set */
16079 if (phba->sli4_hba.pc_sli4_params.eqav) {
16080 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16081 LPFC_Q_CREATE_VERSION_2);
16082 bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
16083 phba->sli4_hba.pc_sli4_params.eqav);
16086 /* don't setup delay multiplier using EQ_CREATE */
16088 bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
16090 switch (eq->entry_count) {
16092 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16093 "0360 Unsupported EQ count. (%d)\n",
16095 if (eq->entry_count < 256) {
16099 fallthrough; /* otherwise default to smallest count */
16101 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16105 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16109 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16113 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16117 bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
16121 list_for_each_entry(dmabuf, &eq->page_list, list) {
16122 memset(dmabuf->virt, 0, hw_page_size);
16123 eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16124 putPaddrLow(dmabuf->phys);
16125 eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16126 putPaddrHigh(dmabuf->phys);
16128 mbox->vport = phba->pport;
16129 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
16130 mbox->ctx_buf = NULL;
16131 mbox->ctx_ndlp = NULL;
16132 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16133 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16134 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16135 if (shdr_status || shdr_add_status || rc) {
16136 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16137 "2500 EQ_CREATE mailbox failed with "
16138 "status x%x add_status x%x, mbx status x%x\n",
16139 shdr_status, shdr_add_status, rc);
16142 eq->type = LPFC_EQ;
16143 eq->subtype = LPFC_NONE;
16144 eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
16145 if (eq->queue_id == 0xFFFF)
16147 eq->host_index = 0;
16148 eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
16149 eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
16151 mempool_free(mbox, phba->mbox_mem_pool);
16155 static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget)
16157 struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop);
16159 __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL);
16165 * lpfc_cq_create - Create a Completion Queue on the HBA
16166 * @phba: HBA structure that indicates port to create a queue on.
16167 * @cq: The queue structure to use to create the completion queue.
16168 * @eq: The event queue to bind this completion queue to.
16169 * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
16170 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
16172 * This function creates a completion queue, as detailed in @wq, on a port,
16173 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
16175 * The @phba struct is used to send mailbox command to HBA. The @cq struct
16176 * is used to get the entry count and entry size that are necessary to
16177 * determine the number of pages to allocate and use for this queue. The @eq
16178 * is used to indicate which event queue to bind this completion queue to. This
16179 * function will send the CQ_CREATE mailbox command to the HBA to setup the
16180 * completion queue. This function is asynchronous and will wait for the mailbox
16181 * command to finish before continuing.
16183 * On success this function will return a zero. If unable to allocate enough
16184 * memory this function will return -ENOMEM. If the queue create mailbox command
16185 * fails this function will return -ENXIO.
16188 lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
16189 struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
16191 struct lpfc_mbx_cq_create *cq_create;
16192 struct lpfc_dmabuf *dmabuf;
16193 LPFC_MBOXQ_t *mbox;
16194 int rc, length, status = 0;
16195 uint32_t shdr_status, shdr_add_status;
16196 union lpfc_sli4_cfg_shdr *shdr;
16198 /* sanity check on queue memory */
16202 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16205 length = (sizeof(struct lpfc_mbx_cq_create) -
16206 sizeof(struct lpfc_sli4_cfg_mhdr));
16207 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16208 LPFC_MBOX_OPCODE_CQ_CREATE,
16209 length, LPFC_SLI4_MBX_EMBED);
16210 cq_create = &mbox->u.mqe.un.cq_create;
16211 shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
16212 bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
16214 bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
16215 bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
16216 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16217 phba->sli4_hba.pc_sli4_params.cqv);
16218 if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
16219 bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
16220 (cq->page_size / SLI4_PAGE_SIZE));
16221 bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
16223 bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
16224 phba->sli4_hba.pc_sli4_params.cqav);
16226 bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
16229 switch (cq->entry_count) {
16232 if (phba->sli4_hba.pc_sli4_params.cqv ==
16233 LPFC_Q_CREATE_VERSION_2) {
16234 cq_create->u.request.context.lpfc_cq_context_count =
16236 bf_set(lpfc_cq_context_count,
16237 &cq_create->u.request.context,
16238 LPFC_CQ_CNT_WORD7);
16243 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16244 "0361 Unsupported CQ count: "
16245 "entry cnt %d sz %d pg cnt %d\n",
16246 cq->entry_count, cq->entry_size,
16248 if (cq->entry_count < 256) {
16252 fallthrough; /* otherwise default to smallest count */
16254 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
16258 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
16262 bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
16266 list_for_each_entry(dmabuf, &cq->page_list, list) {
16267 memset(dmabuf->virt, 0, cq->page_size);
16268 cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16269 putPaddrLow(dmabuf->phys);
16270 cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16271 putPaddrHigh(dmabuf->phys);
16273 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16275 /* The IOCTL status is embedded in the mailbox subheader. */
16276 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16277 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16278 if (shdr_status || shdr_add_status || rc) {
16279 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16280 "2501 CQ_CREATE mailbox failed with "
16281 "status x%x add_status x%x, mbx status x%x\n",
16282 shdr_status, shdr_add_status, rc);
16286 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
16287 if (cq->queue_id == 0xFFFF) {
16291 /* link the cq onto the parent eq child list */
16292 list_add_tail(&cq->list, &eq->child_list);
16293 /* Set up completion queue's type and subtype */
16295 cq->subtype = subtype;
16296 cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
16297 cq->assoc_qid = eq->queue_id;
16299 cq->host_index = 0;
16300 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
16301 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
16303 if (cq->queue_id > phba->sli4_hba.cq_max)
16304 phba->sli4_hba.cq_max = cq->queue_id;
16306 irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler);
16308 mempool_free(mbox, phba->mbox_mem_pool);
16313 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
16314 * @phba: HBA structure that indicates port to create a queue on.
16315 * @cqp: The queue structure array to use to create the completion queues.
16316 * @hdwq: The hardware queue array with the EQ to bind completion queues to.
16317 * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
16318 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
16320 * This function creates a set of completion queue, s to support MRQ
16321 * as detailed in @cqp, on a port,
16322 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
16324 * The @phba struct is used to send mailbox command to HBA. The @cq struct
16325 * is used to get the entry count and entry size that are necessary to
16326 * determine the number of pages to allocate and use for this queue. The @eq
16327 * is used to indicate which event queue to bind this completion queue to. This
16328 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
16329 * completion queue. This function is asynchronous and will wait for the mailbox
16330 * command to finish before continuing.
16332 * On success this function will return a zero. If unable to allocate enough
16333 * memory this function will return -ENOMEM. If the queue create mailbox command
16334 * fails this function will return -ENXIO.
16337 lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
16338 struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
16341 struct lpfc_queue *cq;
16342 struct lpfc_queue *eq;
16343 struct lpfc_mbx_cq_create_set *cq_set;
16344 struct lpfc_dmabuf *dmabuf;
16345 LPFC_MBOXQ_t *mbox;
16346 int rc, length, alloclen, status = 0;
16347 int cnt, idx, numcq, page_idx = 0;
16348 uint32_t shdr_status, shdr_add_status;
16349 union lpfc_sli4_cfg_shdr *shdr;
16350 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16352 /* sanity check on queue memory */
16353 numcq = phba->cfg_nvmet_mrq;
16354 if (!cqp || !hdwq || !numcq)
16357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16361 length = sizeof(struct lpfc_mbx_cq_create_set);
16362 length += ((numcq * cqp[0]->page_count) *
16363 sizeof(struct dma_address));
16364 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16365 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
16366 LPFC_SLI4_MBX_NEMBED);
16367 if (alloclen < length) {
16368 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16369 "3098 Allocated DMA memory size (%d) is "
16370 "less than the requested DMA memory size "
16371 "(%d)\n", alloclen, length);
16375 cq_set = mbox->sge_array->addr[0];
16376 shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
16377 bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
16379 for (idx = 0; idx < numcq; idx++) {
16381 eq = hdwq[idx].hba_eq;
16386 if (!phba->sli4_hba.pc_sli4_params.supported)
16387 hw_page_size = cq->page_size;
16391 bf_set(lpfc_mbx_cq_create_set_page_size,
16392 &cq_set->u.request,
16393 (hw_page_size / SLI4_PAGE_SIZE));
16394 bf_set(lpfc_mbx_cq_create_set_num_pages,
16395 &cq_set->u.request, cq->page_count);
16396 bf_set(lpfc_mbx_cq_create_set_evt,
16397 &cq_set->u.request, 1);
16398 bf_set(lpfc_mbx_cq_create_set_valid,
16399 &cq_set->u.request, 1);
16400 bf_set(lpfc_mbx_cq_create_set_cqe_size,
16401 &cq_set->u.request, 0);
16402 bf_set(lpfc_mbx_cq_create_set_num_cq,
16403 &cq_set->u.request, numcq);
16404 bf_set(lpfc_mbx_cq_create_set_autovalid,
16405 &cq_set->u.request,
16406 phba->sli4_hba.pc_sli4_params.cqav);
16407 switch (cq->entry_count) {
16410 if (phba->sli4_hba.pc_sli4_params.cqv ==
16411 LPFC_Q_CREATE_VERSION_2) {
16412 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16413 &cq_set->u.request,
16415 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16416 &cq_set->u.request,
16417 LPFC_CQ_CNT_WORD7);
16422 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16423 "3118 Bad CQ count. (%d)\n",
16425 if (cq->entry_count < 256) {
16429 fallthrough; /* otherwise default to smallest */
16431 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16432 &cq_set->u.request, LPFC_CQ_CNT_256);
16435 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16436 &cq_set->u.request, LPFC_CQ_CNT_512);
16439 bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
16440 &cq_set->u.request, LPFC_CQ_CNT_1024);
16443 bf_set(lpfc_mbx_cq_create_set_eq_id0,
16444 &cq_set->u.request, eq->queue_id);
16447 bf_set(lpfc_mbx_cq_create_set_eq_id1,
16448 &cq_set->u.request, eq->queue_id);
16451 bf_set(lpfc_mbx_cq_create_set_eq_id2,
16452 &cq_set->u.request, eq->queue_id);
16455 bf_set(lpfc_mbx_cq_create_set_eq_id3,
16456 &cq_set->u.request, eq->queue_id);
16459 bf_set(lpfc_mbx_cq_create_set_eq_id4,
16460 &cq_set->u.request, eq->queue_id);
16463 bf_set(lpfc_mbx_cq_create_set_eq_id5,
16464 &cq_set->u.request, eq->queue_id);
16467 bf_set(lpfc_mbx_cq_create_set_eq_id6,
16468 &cq_set->u.request, eq->queue_id);
16471 bf_set(lpfc_mbx_cq_create_set_eq_id7,
16472 &cq_set->u.request, eq->queue_id);
16475 bf_set(lpfc_mbx_cq_create_set_eq_id8,
16476 &cq_set->u.request, eq->queue_id);
16479 bf_set(lpfc_mbx_cq_create_set_eq_id9,
16480 &cq_set->u.request, eq->queue_id);
16483 bf_set(lpfc_mbx_cq_create_set_eq_id10,
16484 &cq_set->u.request, eq->queue_id);
16487 bf_set(lpfc_mbx_cq_create_set_eq_id11,
16488 &cq_set->u.request, eq->queue_id);
16491 bf_set(lpfc_mbx_cq_create_set_eq_id12,
16492 &cq_set->u.request, eq->queue_id);
16495 bf_set(lpfc_mbx_cq_create_set_eq_id13,
16496 &cq_set->u.request, eq->queue_id);
16499 bf_set(lpfc_mbx_cq_create_set_eq_id14,
16500 &cq_set->u.request, eq->queue_id);
16503 bf_set(lpfc_mbx_cq_create_set_eq_id15,
16504 &cq_set->u.request, eq->queue_id);
16508 /* link the cq onto the parent eq child list */
16509 list_add_tail(&cq->list, &eq->child_list);
16510 /* Set up completion queue's type and subtype */
16512 cq->subtype = subtype;
16513 cq->assoc_qid = eq->queue_id;
16515 cq->host_index = 0;
16516 cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
16517 cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
16522 list_for_each_entry(dmabuf, &cq->page_list, list) {
16523 memset(dmabuf->virt, 0, hw_page_size);
16524 cnt = page_idx + dmabuf->buffer_tag;
16525 cq_set->u.request.page[cnt].addr_lo =
16526 putPaddrLow(dmabuf->phys);
16527 cq_set->u.request.page[cnt].addr_hi =
16528 putPaddrHigh(dmabuf->phys);
16534 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16536 /* The IOCTL status is embedded in the mailbox subheader. */
16537 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16538 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16539 if (shdr_status || shdr_add_status || rc) {
16540 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16541 "3119 CQ_CREATE_SET mailbox failed with "
16542 "status x%x add_status x%x, mbx status x%x\n",
16543 shdr_status, shdr_add_status, rc);
16547 rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
16548 if (rc == 0xFFFF) {
16553 for (idx = 0; idx < numcq; idx++) {
16555 cq->queue_id = rc + idx;
16556 if (cq->queue_id > phba->sli4_hba.cq_max)
16557 phba->sli4_hba.cq_max = cq->queue_id;
16561 lpfc_sli4_mbox_cmd_free(phba, mbox);
16566 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
16567 * @phba: HBA structure that indicates port to create a queue on.
16568 * @mq: The queue structure to use to create the mailbox queue.
16569 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
16570 * @cq: The completion queue to associate with this cq.
16572 * This function provides failback (fb) functionality when the
16573 * mq_create_ext fails on older FW generations. It's purpose is identical
16574 * to mq_create_ext otherwise.
16576 * This routine cannot fail as all attributes were previously accessed and
16577 * initialized in mq_create_ext.
16580 lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
16581 LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
16583 struct lpfc_mbx_mq_create *mq_create;
16584 struct lpfc_dmabuf *dmabuf;
16587 length = (sizeof(struct lpfc_mbx_mq_create) -
16588 sizeof(struct lpfc_sli4_cfg_mhdr));
16589 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16590 LPFC_MBOX_OPCODE_MQ_CREATE,
16591 length, LPFC_SLI4_MBX_EMBED);
16592 mq_create = &mbox->u.mqe.un.mq_create;
16593 bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
16595 bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
16597 bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
16598 switch (mq->entry_count) {
16600 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16601 LPFC_MQ_RING_SIZE_16);
16604 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16605 LPFC_MQ_RING_SIZE_32);
16608 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16609 LPFC_MQ_RING_SIZE_64);
16612 bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
16613 LPFC_MQ_RING_SIZE_128);
16616 list_for_each_entry(dmabuf, &mq->page_list, list) {
16617 mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
16618 putPaddrLow(dmabuf->phys);
16619 mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
16620 putPaddrHigh(dmabuf->phys);
16625 * lpfc_mq_create - Create a mailbox Queue on the HBA
16626 * @phba: HBA structure that indicates port to create a queue on.
16627 * @mq: The queue structure to use to create the mailbox queue.
16628 * @cq: The completion queue to associate with this cq.
16629 * @subtype: The queue's subtype.
16631 * This function creates a mailbox queue, as detailed in @mq, on a port,
16632 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
16634 * The @phba struct is used to send mailbox command to HBA. The @cq struct
16635 * is used to get the entry count and entry size that are necessary to
16636 * determine the number of pages to allocate and use for this queue. This
16637 * function will send the MQ_CREATE mailbox command to the HBA to setup the
16638 * mailbox queue. This function is asynchronous and will wait for the mailbox
16639 * command to finish before continuing.
16641 * On success this function will return a zero. If unable to allocate enough
16642 * memory this function will return -ENOMEM. If the queue create mailbox command
16643 * fails this function will return -ENXIO.
16646 lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
16647 struct lpfc_queue *cq, uint32_t subtype)
16649 struct lpfc_mbx_mq_create *mq_create;
16650 struct lpfc_mbx_mq_create_ext *mq_create_ext;
16651 struct lpfc_dmabuf *dmabuf;
16652 LPFC_MBOXQ_t *mbox;
16653 int rc, length, status = 0;
16654 uint32_t shdr_status, shdr_add_status;
16655 union lpfc_sli4_cfg_shdr *shdr;
16656 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16658 /* sanity check on queue memory */
16661 if (!phba->sli4_hba.pc_sli4_params.supported)
16662 hw_page_size = SLI4_PAGE_SIZE;
16664 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16667 length = (sizeof(struct lpfc_mbx_mq_create_ext) -
16668 sizeof(struct lpfc_sli4_cfg_mhdr));
16669 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
16670 LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
16671 length, LPFC_SLI4_MBX_EMBED);
16673 mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
16674 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
16675 bf_set(lpfc_mbx_mq_create_ext_num_pages,
16676 &mq_create_ext->u.request, mq->page_count);
16677 bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
16678 &mq_create_ext->u.request, 1);
16679 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
16680 &mq_create_ext->u.request, 1);
16681 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
16682 &mq_create_ext->u.request, 1);
16683 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
16684 &mq_create_ext->u.request, 1);
16685 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
16686 &mq_create_ext->u.request, 1);
16687 bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
16688 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16689 phba->sli4_hba.pc_sli4_params.mqv);
16690 if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
16691 bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
16694 bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
16696 switch (mq->entry_count) {
16698 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16699 "0362 Unsupported MQ count. (%d)\n",
16701 if (mq->entry_count < 16) {
16705 fallthrough; /* otherwise default to smallest count */
16707 bf_set(lpfc_mq_context_ring_size,
16708 &mq_create_ext->u.request.context,
16709 LPFC_MQ_RING_SIZE_16);
16712 bf_set(lpfc_mq_context_ring_size,
16713 &mq_create_ext->u.request.context,
16714 LPFC_MQ_RING_SIZE_32);
16717 bf_set(lpfc_mq_context_ring_size,
16718 &mq_create_ext->u.request.context,
16719 LPFC_MQ_RING_SIZE_64);
16722 bf_set(lpfc_mq_context_ring_size,
16723 &mq_create_ext->u.request.context,
16724 LPFC_MQ_RING_SIZE_128);
16727 list_for_each_entry(dmabuf, &mq->page_list, list) {
16728 memset(dmabuf->virt, 0, hw_page_size);
16729 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
16730 putPaddrLow(dmabuf->phys);
16731 mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
16732 putPaddrHigh(dmabuf->phys);
16734 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16735 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
16736 &mq_create_ext->u.response);
16737 if (rc != MBX_SUCCESS) {
16738 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16739 "2795 MQ_CREATE_EXT failed with "
16740 "status x%x. Failback to MQ_CREATE.\n",
16742 lpfc_mq_create_fb_init(phba, mq, mbox, cq);
16743 mq_create = &mbox->u.mqe.un.mq_create;
16744 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16745 shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
16746 mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
16747 &mq_create->u.response);
16750 /* The IOCTL status is embedded in the mailbox subheader. */
16751 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16752 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16753 if (shdr_status || shdr_add_status || rc) {
16754 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16755 "2502 MQ_CREATE mailbox failed with "
16756 "status x%x add_status x%x, mbx status x%x\n",
16757 shdr_status, shdr_add_status, rc);
16761 if (mq->queue_id == 0xFFFF) {
16765 mq->type = LPFC_MQ;
16766 mq->assoc_qid = cq->queue_id;
16767 mq->subtype = subtype;
16768 mq->host_index = 0;
16771 /* link the mq onto the parent cq child list */
16772 list_add_tail(&mq->list, &cq->child_list);
16774 mempool_free(mbox, phba->mbox_mem_pool);
16779 * lpfc_wq_create - Create a Work Queue on the HBA
16780 * @phba: HBA structure that indicates port to create a queue on.
16781 * @wq: The queue structure to use to create the work queue.
16782 * @cq: The completion queue to bind this work queue to.
16783 * @subtype: The subtype of the work queue indicating its functionality.
16785 * This function creates a work queue, as detailed in @wq, on a port, described
16786 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
16788 * The @phba struct is used to send mailbox command to HBA. The @wq struct
16789 * is used to get the entry count and entry size that are necessary to
16790 * determine the number of pages to allocate and use for this queue. The @cq
16791 * is used to indicate which completion queue to bind this work queue to. This
16792 * function will send the WQ_CREATE mailbox command to the HBA to setup the
16793 * work queue. This function is asynchronous and will wait for the mailbox
16794 * command to finish before continuing.
16796 * On success this function will return a zero. If unable to allocate enough
16797 * memory this function will return -ENOMEM. If the queue create mailbox command
16798 * fails this function will return -ENXIO.
16801 lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
16802 struct lpfc_queue *cq, uint32_t subtype)
16804 struct lpfc_mbx_wq_create *wq_create;
16805 struct lpfc_dmabuf *dmabuf;
16806 LPFC_MBOXQ_t *mbox;
16807 int rc, length, status = 0;
16808 uint32_t shdr_status, shdr_add_status;
16809 union lpfc_sli4_cfg_shdr *shdr;
16810 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
16811 struct dma_address *page;
16812 void __iomem *bar_memmap_p;
16813 uint32_t db_offset;
16814 uint16_t pci_barset;
16815 uint8_t dpp_barset;
16816 uint32_t dpp_offset;
16817 uint8_t wq_create_version;
16819 unsigned long pg_addr;
16822 /* sanity check on queue memory */
16825 if (!phba->sli4_hba.pc_sli4_params.supported)
16826 hw_page_size = wq->page_size;
16828 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
16831 length = (sizeof(struct lpfc_mbx_wq_create) -
16832 sizeof(struct lpfc_sli4_cfg_mhdr));
16833 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
16834 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
16835 length, LPFC_SLI4_MBX_EMBED);
16836 wq_create = &mbox->u.mqe.un.wq_create;
16837 shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
16838 bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
16840 bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
16843 /* wqv is the earliest version supported, NOT the latest */
16844 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16845 phba->sli4_hba.pc_sli4_params.wqv);
16847 if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
16848 (wq->page_size > SLI4_PAGE_SIZE))
16849 wq_create_version = LPFC_Q_CREATE_VERSION_1;
16851 wq_create_version = LPFC_Q_CREATE_VERSION_0;
16853 switch (wq_create_version) {
16854 case LPFC_Q_CREATE_VERSION_1:
16855 bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
16857 bf_set(lpfc_mbox_hdr_version, &shdr->request,
16858 LPFC_Q_CREATE_VERSION_1);
16860 switch (wq->entry_size) {
16863 bf_set(lpfc_mbx_wq_create_wqe_size,
16864 &wq_create->u.request_1,
16865 LPFC_WQ_WQE_SIZE_64);
16868 bf_set(lpfc_mbx_wq_create_wqe_size,
16869 &wq_create->u.request_1,
16870 LPFC_WQ_WQE_SIZE_128);
16873 /* Request DPP by default */
16874 bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
16875 bf_set(lpfc_mbx_wq_create_page_size,
16876 &wq_create->u.request_1,
16877 (wq->page_size / SLI4_PAGE_SIZE));
16878 page = wq_create->u.request_1.page;
16881 page = wq_create->u.request.page;
16885 list_for_each_entry(dmabuf, &wq->page_list, list) {
16886 memset(dmabuf->virt, 0, hw_page_size);
16887 page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
16888 page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
16891 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
16892 bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
16894 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
16895 /* The IOCTL status is embedded in the mailbox subheader. */
16896 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
16897 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
16898 if (shdr_status || shdr_add_status || rc) {
16899 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16900 "2503 WQ_CREATE mailbox failed with "
16901 "status x%x add_status x%x, mbx status x%x\n",
16902 shdr_status, shdr_add_status, rc);
16907 if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
16908 wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
16909 &wq_create->u.response);
16911 wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
16912 &wq_create->u.response_1);
16914 if (wq->queue_id == 0xFFFF) {
16919 wq->db_format = LPFC_DB_LIST_FORMAT;
16920 if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
16921 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
16922 wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
16923 &wq_create->u.response);
16924 if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
16925 (wq->db_format != LPFC_DB_RING_FORMAT)) {
16926 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16927 "3265 WQ[%d] doorbell format "
16928 "not supported: x%x\n",
16929 wq->queue_id, wq->db_format);
16933 pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
16934 &wq_create->u.response);
16935 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16937 if (!bar_memmap_p) {
16938 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16939 "3263 WQ[%d] failed to memmap "
16940 "pci barset:x%x\n",
16941 wq->queue_id, pci_barset);
16945 db_offset = wq_create->u.response.doorbell_offset;
16946 if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
16947 (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
16948 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16949 "3252 WQ[%d] doorbell offset "
16950 "not supported: x%x\n",
16951 wq->queue_id, db_offset);
16955 wq->db_regaddr = bar_memmap_p + db_offset;
16956 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16957 "3264 WQ[%d]: barset:x%x, offset:x%x, "
16958 "format:x%x\n", wq->queue_id,
16959 pci_barset, db_offset, wq->db_format);
16961 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
16963 /* Check if DPP was honored by the firmware */
16964 wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
16965 &wq_create->u.response_1);
16966 if (wq->dpp_enable) {
16967 pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
16968 &wq_create->u.response_1);
16969 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16971 if (!bar_memmap_p) {
16972 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16973 "3267 WQ[%d] failed to memmap "
16974 "pci barset:x%x\n",
16975 wq->queue_id, pci_barset);
16979 db_offset = wq_create->u.response_1.doorbell_offset;
16980 wq->db_regaddr = bar_memmap_p + db_offset;
16981 wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
16982 &wq_create->u.response_1);
16983 dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
16984 &wq_create->u.response_1);
16985 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
16987 if (!bar_memmap_p) {
16988 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
16989 "3268 WQ[%d] failed to memmap "
16990 "pci barset:x%x\n",
16991 wq->queue_id, dpp_barset);
16995 dpp_offset = wq_create->u.response_1.dpp_offset;
16996 wq->dpp_regaddr = bar_memmap_p + dpp_offset;
16997 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
16998 "3271 WQ[%d]: barset:x%x, offset:x%x, "
16999 "dpp_id:x%x dpp_barset:x%x "
17000 "dpp_offset:x%x\n",
17001 wq->queue_id, pci_barset, db_offset,
17002 wq->dpp_id, dpp_barset, dpp_offset);
17005 /* Enable combined writes for DPP aperture */
17006 pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
17007 rc = set_memory_wc(pg_addr, 1);
17009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
17010 "3272 Cannot setup Combined "
17011 "Write on WQ[%d] - disable DPP\n",
17013 phba->cfg_enable_dpp = 0;
17016 phba->cfg_enable_dpp = 0;
17019 wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
17021 wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
17022 if (wq->pring == NULL) {
17026 wq->type = LPFC_WQ;
17027 wq->assoc_qid = cq->queue_id;
17028 wq->subtype = subtype;
17029 wq->host_index = 0;
17031 wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
17033 /* link the wq onto the parent cq child list */
17034 list_add_tail(&wq->list, &cq->child_list);
17036 mempool_free(mbox, phba->mbox_mem_pool);
17041 * lpfc_rq_create - Create a Receive Queue on the HBA
17042 * @phba: HBA structure that indicates port to create a queue on.
17043 * @hrq: The queue structure to use to create the header receive queue.
17044 * @drq: The queue structure to use to create the data receive queue.
17045 * @cq: The completion queue to bind this work queue to.
17046 * @subtype: The subtype of the work queue indicating its functionality.
17048 * This function creates a receive buffer queue pair , as detailed in @hrq and
17049 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
17052 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
17053 * struct is used to get the entry count that is necessary to determine the
17054 * number of pages to use for this queue. The @cq is used to indicate which
17055 * completion queue to bind received buffers that are posted to these queues to.
17056 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
17057 * receive queue pair. This function is asynchronous and will wait for the
17058 * mailbox command to finish before continuing.
17060 * On success this function will return a zero. If unable to allocate enough
17061 * memory this function will return -ENOMEM. If the queue create mailbox command
17062 * fails this function will return -ENXIO.
17065 lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
17066 struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
17068 struct lpfc_mbx_rq_create *rq_create;
17069 struct lpfc_dmabuf *dmabuf;
17070 LPFC_MBOXQ_t *mbox;
17071 int rc, length, status = 0;
17072 uint32_t shdr_status, shdr_add_status;
17073 union lpfc_sli4_cfg_shdr *shdr;
17074 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
17075 void __iomem *bar_memmap_p;
17076 uint32_t db_offset;
17077 uint16_t pci_barset;
17079 /* sanity check on queue memory */
17080 if (!hrq || !drq || !cq)
17082 if (!phba->sli4_hba.pc_sli4_params.supported)
17083 hw_page_size = SLI4_PAGE_SIZE;
17085 if (hrq->entry_count != drq->entry_count)
17087 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17090 length = (sizeof(struct lpfc_mbx_rq_create) -
17091 sizeof(struct lpfc_sli4_cfg_mhdr));
17092 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17093 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
17094 length, LPFC_SLI4_MBX_EMBED);
17095 rq_create = &mbox->u.mqe.un.rq_create;
17096 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
17097 bf_set(lpfc_mbox_hdr_version, &shdr->request,
17098 phba->sli4_hba.pc_sli4_params.rqv);
17099 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
17100 bf_set(lpfc_rq_context_rqe_count_1,
17101 &rq_create->u.request.context,
17103 rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
17104 bf_set(lpfc_rq_context_rqe_size,
17105 &rq_create->u.request.context,
17107 bf_set(lpfc_rq_context_page_size,
17108 &rq_create->u.request.context,
17109 LPFC_RQ_PAGE_SIZE_4096);
17111 switch (hrq->entry_count) {
17113 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17114 "2535 Unsupported RQ count. (%d)\n",
17116 if (hrq->entry_count < 512) {
17120 fallthrough; /* otherwise default to smallest count */
17122 bf_set(lpfc_rq_context_rqe_count,
17123 &rq_create->u.request.context,
17124 LPFC_RQ_RING_SIZE_512);
17127 bf_set(lpfc_rq_context_rqe_count,
17128 &rq_create->u.request.context,
17129 LPFC_RQ_RING_SIZE_1024);
17132 bf_set(lpfc_rq_context_rqe_count,
17133 &rq_create->u.request.context,
17134 LPFC_RQ_RING_SIZE_2048);
17137 bf_set(lpfc_rq_context_rqe_count,
17138 &rq_create->u.request.context,
17139 LPFC_RQ_RING_SIZE_4096);
17142 bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
17143 LPFC_HDR_BUF_SIZE);
17145 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
17147 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
17149 list_for_each_entry(dmabuf, &hrq->page_list, list) {
17150 memset(dmabuf->virt, 0, hw_page_size);
17151 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
17152 putPaddrLow(dmabuf->phys);
17153 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
17154 putPaddrHigh(dmabuf->phys);
17156 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
17157 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
17159 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17160 /* The IOCTL status is embedded in the mailbox subheader. */
17161 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17162 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17163 if (shdr_status || shdr_add_status || rc) {
17164 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17165 "2504 RQ_CREATE mailbox failed with "
17166 "status x%x add_status x%x, mbx status x%x\n",
17167 shdr_status, shdr_add_status, rc);
17171 hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
17172 if (hrq->queue_id == 0xFFFF) {
17177 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
17178 hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
17179 &rq_create->u.response);
17180 if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
17181 (hrq->db_format != LPFC_DB_RING_FORMAT)) {
17182 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17183 "3262 RQ [%d] doorbell format not "
17184 "supported: x%x\n", hrq->queue_id,
17190 pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
17191 &rq_create->u.response);
17192 bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
17193 if (!bar_memmap_p) {
17194 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17195 "3269 RQ[%d] failed to memmap pci "
17196 "barset:x%x\n", hrq->queue_id,
17202 db_offset = rq_create->u.response.doorbell_offset;
17203 if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
17204 (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
17205 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17206 "3270 RQ[%d] doorbell offset not "
17207 "supported: x%x\n", hrq->queue_id,
17212 hrq->db_regaddr = bar_memmap_p + db_offset;
17213 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
17214 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
17215 "format:x%x\n", hrq->queue_id, pci_barset,
17216 db_offset, hrq->db_format);
17218 hrq->db_format = LPFC_DB_RING_FORMAT;
17219 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
17221 hrq->type = LPFC_HRQ;
17222 hrq->assoc_qid = cq->queue_id;
17223 hrq->subtype = subtype;
17224 hrq->host_index = 0;
17225 hrq->hba_index = 0;
17226 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17228 /* now create the data queue */
17229 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17230 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
17231 length, LPFC_SLI4_MBX_EMBED);
17232 bf_set(lpfc_mbox_hdr_version, &shdr->request,
17233 phba->sli4_hba.pc_sli4_params.rqv);
17234 if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
17235 bf_set(lpfc_rq_context_rqe_count_1,
17236 &rq_create->u.request.context, hrq->entry_count);
17237 if (subtype == LPFC_NVMET)
17238 rq_create->u.request.context.buffer_size =
17239 LPFC_NVMET_DATA_BUF_SIZE;
17241 rq_create->u.request.context.buffer_size =
17242 LPFC_DATA_BUF_SIZE;
17243 bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
17245 bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
17246 (PAGE_SIZE/SLI4_PAGE_SIZE));
17248 switch (drq->entry_count) {
17250 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17251 "2536 Unsupported RQ count. (%d)\n",
17253 if (drq->entry_count < 512) {
17257 fallthrough; /* otherwise default to smallest count */
17259 bf_set(lpfc_rq_context_rqe_count,
17260 &rq_create->u.request.context,
17261 LPFC_RQ_RING_SIZE_512);
17264 bf_set(lpfc_rq_context_rqe_count,
17265 &rq_create->u.request.context,
17266 LPFC_RQ_RING_SIZE_1024);
17269 bf_set(lpfc_rq_context_rqe_count,
17270 &rq_create->u.request.context,
17271 LPFC_RQ_RING_SIZE_2048);
17274 bf_set(lpfc_rq_context_rqe_count,
17275 &rq_create->u.request.context,
17276 LPFC_RQ_RING_SIZE_4096);
17279 if (subtype == LPFC_NVMET)
17280 bf_set(lpfc_rq_context_buf_size,
17281 &rq_create->u.request.context,
17282 LPFC_NVMET_DATA_BUF_SIZE);
17284 bf_set(lpfc_rq_context_buf_size,
17285 &rq_create->u.request.context,
17286 LPFC_DATA_BUF_SIZE);
17288 bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
17290 bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
17292 list_for_each_entry(dmabuf, &drq->page_list, list) {
17293 rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
17294 putPaddrLow(dmabuf->phys);
17295 rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
17296 putPaddrHigh(dmabuf->phys);
17298 if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
17299 bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
17300 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17301 /* The IOCTL status is embedded in the mailbox subheader. */
17302 shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
17303 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17304 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17305 if (shdr_status || shdr_add_status || rc) {
17309 drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
17310 if (drq->queue_id == 0xFFFF) {
17314 drq->type = LPFC_DRQ;
17315 drq->assoc_qid = cq->queue_id;
17316 drq->subtype = subtype;
17317 drq->host_index = 0;
17318 drq->hba_index = 0;
17319 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17321 /* link the header and data RQs onto the parent cq child list */
17322 list_add_tail(&hrq->list, &cq->child_list);
17323 list_add_tail(&drq->list, &cq->child_list);
17326 mempool_free(mbox, phba->mbox_mem_pool);
17331 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
17332 * @phba: HBA structure that indicates port to create a queue on.
17333 * @hrqp: The queue structure array to use to create the header receive queues.
17334 * @drqp: The queue structure array to use to create the data receive queues.
17335 * @cqp: The completion queue array to bind these receive queues to.
17336 * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
17338 * This function creates a receive buffer queue pair , as detailed in @hrq and
17339 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
17342 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
17343 * struct is used to get the entry count that is necessary to determine the
17344 * number of pages to use for this queue. The @cq is used to indicate which
17345 * completion queue to bind received buffers that are posted to these queues to.
17346 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
17347 * receive queue pair. This function is asynchronous and will wait for the
17348 * mailbox command to finish before continuing.
17350 * On success this function will return a zero. If unable to allocate enough
17351 * memory this function will return -ENOMEM. If the queue create mailbox command
17352 * fails this function will return -ENXIO.
17355 lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
17356 struct lpfc_queue **drqp, struct lpfc_queue **cqp,
17359 struct lpfc_queue *hrq, *drq, *cq;
17360 struct lpfc_mbx_rq_create_v2 *rq_create;
17361 struct lpfc_dmabuf *dmabuf;
17362 LPFC_MBOXQ_t *mbox;
17363 int rc, length, alloclen, status = 0;
17364 int cnt, idx, numrq, page_idx = 0;
17365 uint32_t shdr_status, shdr_add_status;
17366 union lpfc_sli4_cfg_shdr *shdr;
17367 uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
17369 numrq = phba->cfg_nvmet_mrq;
17370 /* sanity check on array memory */
17371 if (!hrqp || !drqp || !cqp || !numrq)
17373 if (!phba->sli4_hba.pc_sli4_params.supported)
17374 hw_page_size = SLI4_PAGE_SIZE;
17376 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17380 length = sizeof(struct lpfc_mbx_rq_create_v2);
17381 length += ((2 * numrq * hrqp[0]->page_count) *
17382 sizeof(struct dma_address));
17384 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17385 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
17386 LPFC_SLI4_MBX_NEMBED);
17387 if (alloclen < length) {
17388 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17389 "3099 Allocated DMA memory size (%d) is "
17390 "less than the requested DMA memory size "
17391 "(%d)\n", alloclen, length);
17398 rq_create = mbox->sge_array->addr[0];
17399 shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
17401 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
17404 for (idx = 0; idx < numrq; idx++) {
17409 /* sanity check on queue memory */
17410 if (!hrq || !drq || !cq) {
17415 if (hrq->entry_count != drq->entry_count) {
17421 bf_set(lpfc_mbx_rq_create_num_pages,
17422 &rq_create->u.request,
17424 bf_set(lpfc_mbx_rq_create_rq_cnt,
17425 &rq_create->u.request, (numrq * 2));
17426 bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
17428 bf_set(lpfc_rq_context_base_cq,
17429 &rq_create->u.request.context,
17431 bf_set(lpfc_rq_context_data_size,
17432 &rq_create->u.request.context,
17433 LPFC_NVMET_DATA_BUF_SIZE);
17434 bf_set(lpfc_rq_context_hdr_size,
17435 &rq_create->u.request.context,
17436 LPFC_HDR_BUF_SIZE);
17437 bf_set(lpfc_rq_context_rqe_count_1,
17438 &rq_create->u.request.context,
17440 bf_set(lpfc_rq_context_rqe_size,
17441 &rq_create->u.request.context,
17443 bf_set(lpfc_rq_context_page_size,
17444 &rq_create->u.request.context,
17445 (PAGE_SIZE/SLI4_PAGE_SIZE));
17448 list_for_each_entry(dmabuf, &hrq->page_list, list) {
17449 memset(dmabuf->virt, 0, hw_page_size);
17450 cnt = page_idx + dmabuf->buffer_tag;
17451 rq_create->u.request.page[cnt].addr_lo =
17452 putPaddrLow(dmabuf->phys);
17453 rq_create->u.request.page[cnt].addr_hi =
17454 putPaddrHigh(dmabuf->phys);
17460 list_for_each_entry(dmabuf, &drq->page_list, list) {
17461 memset(dmabuf->virt, 0, hw_page_size);
17462 cnt = page_idx + dmabuf->buffer_tag;
17463 rq_create->u.request.page[cnt].addr_lo =
17464 putPaddrLow(dmabuf->phys);
17465 rq_create->u.request.page[cnt].addr_hi =
17466 putPaddrHigh(dmabuf->phys);
17471 hrq->db_format = LPFC_DB_RING_FORMAT;
17472 hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
17473 hrq->type = LPFC_HRQ;
17474 hrq->assoc_qid = cq->queue_id;
17475 hrq->subtype = subtype;
17476 hrq->host_index = 0;
17477 hrq->hba_index = 0;
17478 hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17480 drq->db_format = LPFC_DB_RING_FORMAT;
17481 drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
17482 drq->type = LPFC_DRQ;
17483 drq->assoc_qid = cq->queue_id;
17484 drq->subtype = subtype;
17485 drq->host_index = 0;
17486 drq->hba_index = 0;
17487 drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
17489 list_add_tail(&hrq->list, &cq->child_list);
17490 list_add_tail(&drq->list, &cq->child_list);
17493 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17494 /* The IOCTL status is embedded in the mailbox subheader. */
17495 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17496 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17497 if (shdr_status || shdr_add_status || rc) {
17498 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17499 "3120 RQ_CREATE mailbox failed with "
17500 "status x%x add_status x%x, mbx status x%x\n",
17501 shdr_status, shdr_add_status, rc);
17505 rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
17506 if (rc == 0xFFFF) {
17511 /* Initialize all RQs with associated queue id */
17512 for (idx = 0; idx < numrq; idx++) {
17514 hrq->queue_id = rc + (2 * idx);
17516 drq->queue_id = rc + (2 * idx) + 1;
17520 lpfc_sli4_mbox_cmd_free(phba, mbox);
17525 * lpfc_eq_destroy - Destroy an event Queue on the HBA
17526 * @phba: HBA structure that indicates port to destroy a queue on.
17527 * @eq: The queue structure associated with the queue to destroy.
17529 * This function destroys a queue, as detailed in @eq by sending an mailbox
17530 * command, specific to the type of queue, to the HBA.
17532 * The @eq struct is used to get the queue ID of the queue to destroy.
17534 * On success this function will return a zero. If the queue destroy mailbox
17535 * command fails this function will return -ENXIO.
17538 lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
17540 LPFC_MBOXQ_t *mbox;
17541 int rc, length, status = 0;
17542 uint32_t shdr_status, shdr_add_status;
17543 union lpfc_sli4_cfg_shdr *shdr;
17545 /* sanity check on queue memory */
17549 mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
17552 length = (sizeof(struct lpfc_mbx_eq_destroy) -
17553 sizeof(struct lpfc_sli4_cfg_mhdr));
17554 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17555 LPFC_MBOX_OPCODE_EQ_DESTROY,
17556 length, LPFC_SLI4_MBX_EMBED);
17557 bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
17559 mbox->vport = eq->phba->pport;
17560 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17562 rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
17563 /* The IOCTL status is embedded in the mailbox subheader. */
17564 shdr = (union lpfc_sli4_cfg_shdr *)
17565 &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
17566 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17567 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17568 if (shdr_status || shdr_add_status || rc) {
17569 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17570 "2505 EQ_DESTROY mailbox failed with "
17571 "status x%x add_status x%x, mbx status x%x\n",
17572 shdr_status, shdr_add_status, rc);
17576 /* Remove eq from any list */
17577 list_del_init(&eq->list);
17578 mempool_free(mbox, eq->phba->mbox_mem_pool);
17583 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
17584 * @phba: HBA structure that indicates port to destroy a queue on.
17585 * @cq: The queue structure associated with the queue to destroy.
17587 * This function destroys a queue, as detailed in @cq by sending an mailbox
17588 * command, specific to the type of queue, to the HBA.
17590 * The @cq struct is used to get the queue ID of the queue to destroy.
17592 * On success this function will return a zero. If the queue destroy mailbox
17593 * command fails this function will return -ENXIO.
17596 lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
17598 LPFC_MBOXQ_t *mbox;
17599 int rc, length, status = 0;
17600 uint32_t shdr_status, shdr_add_status;
17601 union lpfc_sli4_cfg_shdr *shdr;
17603 /* sanity check on queue memory */
17606 mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
17609 length = (sizeof(struct lpfc_mbx_cq_destroy) -
17610 sizeof(struct lpfc_sli4_cfg_mhdr));
17611 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17612 LPFC_MBOX_OPCODE_CQ_DESTROY,
17613 length, LPFC_SLI4_MBX_EMBED);
17614 bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
17616 mbox->vport = cq->phba->pport;
17617 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17618 rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
17619 /* The IOCTL status is embedded in the mailbox subheader. */
17620 shdr = (union lpfc_sli4_cfg_shdr *)
17621 &mbox->u.mqe.un.wq_create.header.cfg_shdr;
17622 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17623 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17624 if (shdr_status || shdr_add_status || rc) {
17625 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17626 "2506 CQ_DESTROY mailbox failed with "
17627 "status x%x add_status x%x, mbx status x%x\n",
17628 shdr_status, shdr_add_status, rc);
17631 /* Remove cq from any list */
17632 list_del_init(&cq->list);
17633 mempool_free(mbox, cq->phba->mbox_mem_pool);
17638 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
17639 * @phba: HBA structure that indicates port to destroy a queue on.
17640 * @mq: The queue structure associated with the queue to destroy.
17642 * This function destroys a queue, as detailed in @mq by sending an mailbox
17643 * command, specific to the type of queue, to the HBA.
17645 * The @mq 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_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
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(mq->phba->mbox_mem_pool, GFP_KERNEL);
17664 length = (sizeof(struct lpfc_mbx_mq_destroy) -
17665 sizeof(struct lpfc_sli4_cfg_mhdr));
17666 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
17667 LPFC_MBOX_OPCODE_MQ_DESTROY,
17668 length, LPFC_SLI4_MBX_EMBED);
17669 bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
17671 mbox->vport = mq->phba->pport;
17672 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17673 rc = lpfc_sli_issue_mbox(mq->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.mq_destroy.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 "2507 MQ_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 mq from any list */
17687 list_del_init(&mq->list);
17688 mempool_free(mbox, mq->phba->mbox_mem_pool);
17693 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
17694 * @phba: HBA structure that indicates port to destroy a queue on.
17695 * @wq: The queue structure associated with the queue to destroy.
17697 * This function destroys a queue, as detailed in @wq by sending an mailbox
17698 * command, specific to the type of queue, to the HBA.
17700 * The @wq 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_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
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(wq->phba->mbox_mem_pool, GFP_KERNEL);
17719 length = (sizeof(struct lpfc_mbx_wq_destroy) -
17720 sizeof(struct lpfc_sli4_cfg_mhdr));
17721 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17722 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
17723 length, LPFC_SLI4_MBX_EMBED);
17724 bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
17726 mbox->vport = wq->phba->pport;
17727 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17728 rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
17729 shdr = (union lpfc_sli4_cfg_shdr *)
17730 &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
17731 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17732 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17733 if (shdr_status || shdr_add_status || rc) {
17734 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17735 "2508 WQ_DESTROY mailbox failed with "
17736 "status x%x add_status x%x, mbx status x%x\n",
17737 shdr_status, shdr_add_status, rc);
17740 /* Remove wq from any list */
17741 list_del_init(&wq->list);
17744 mempool_free(mbox, wq->phba->mbox_mem_pool);
17749 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
17750 * @phba: HBA structure that indicates port to destroy a queue on.
17751 * @hrq: The queue structure associated with the queue to destroy.
17752 * @drq: The queue structure associated with the queue to destroy.
17754 * This function destroys a queue, as detailed in @rq by sending an mailbox
17755 * command, specific to the type of queue, to the HBA.
17757 * The @rq struct is used to get the queue ID of the queue to destroy.
17759 * On success this function will return a zero. If the queue destroy mailbox
17760 * command fails this function will return -ENXIO.
17763 lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
17764 struct lpfc_queue *drq)
17766 LPFC_MBOXQ_t *mbox;
17767 int rc, length, status = 0;
17768 uint32_t shdr_status, shdr_add_status;
17769 union lpfc_sli4_cfg_shdr *shdr;
17771 /* sanity check on queue memory */
17774 mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
17777 length = (sizeof(struct lpfc_mbx_rq_destroy) -
17778 sizeof(struct lpfc_sli4_cfg_mhdr));
17779 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17780 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
17781 length, LPFC_SLI4_MBX_EMBED);
17782 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
17784 mbox->vport = hrq->phba->pport;
17785 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
17786 rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
17787 /* The IOCTL status is embedded in the mailbox subheader. */
17788 shdr = (union lpfc_sli4_cfg_shdr *)
17789 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
17790 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17791 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17792 if (shdr_status || shdr_add_status || rc) {
17793 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17794 "2509 RQ_DESTROY mailbox failed with "
17795 "status x%x add_status x%x, mbx status x%x\n",
17796 shdr_status, shdr_add_status, rc);
17797 mempool_free(mbox, hrq->phba->mbox_mem_pool);
17800 bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
17802 rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
17803 shdr = (union lpfc_sli4_cfg_shdr *)
17804 &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
17805 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17806 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17807 if (shdr_status || shdr_add_status || rc) {
17808 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17809 "2510 RQ_DESTROY mailbox failed with "
17810 "status x%x add_status x%x, mbx status x%x\n",
17811 shdr_status, shdr_add_status, rc);
17814 list_del_init(&hrq->list);
17815 list_del_init(&drq->list);
17816 mempool_free(mbox, hrq->phba->mbox_mem_pool);
17821 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
17822 * @phba: The virtual port for which this call being executed.
17823 * @pdma_phys_addr0: Physical address of the 1st SGL page.
17824 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
17825 * @xritag: the xritag that ties this io to the SGL pages.
17827 * This routine will post the sgl pages for the IO that has the xritag
17828 * that is in the iocbq structure. The xritag is assigned during iocbq
17829 * creation and persists for as long as the driver is loaded.
17830 * if the caller has fewer than 256 scatter gather segments to map then
17831 * pdma_phys_addr1 should be 0.
17832 * If the caller needs to map more than 256 scatter gather segment then
17833 * pdma_phys_addr1 should be a valid physical address.
17834 * physical address for SGLs must be 64 byte aligned.
17835 * If you are going to map 2 SGL's then the first one must have 256 entries
17836 * the second sgl can have between 1 and 256 entries.
17840 * -ENXIO, -ENOMEM - Failure
17843 lpfc_sli4_post_sgl(struct lpfc_hba *phba,
17844 dma_addr_t pdma_phys_addr0,
17845 dma_addr_t pdma_phys_addr1,
17848 struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
17849 LPFC_MBOXQ_t *mbox;
17851 uint32_t shdr_status, shdr_add_status;
17853 union lpfc_sli4_cfg_shdr *shdr;
17855 if (xritag == NO_XRI) {
17856 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17857 "0364 Invalid param:\n");
17861 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
17865 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
17866 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
17867 sizeof(struct lpfc_mbx_post_sgl_pages) -
17868 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
17870 post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
17871 &mbox->u.mqe.un.post_sgl_pages;
17872 bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
17873 bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
17875 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
17876 cpu_to_le32(putPaddrLow(pdma_phys_addr0));
17877 post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
17878 cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
17880 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
17881 cpu_to_le32(putPaddrLow(pdma_phys_addr1));
17882 post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
17883 cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
17884 if (!phba->sli4_hba.intr_enable)
17885 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
17887 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
17888 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
17890 /* The IOCTL status is embedded in the mailbox subheader. */
17891 shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
17892 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
17893 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
17894 if (!phba->sli4_hba.intr_enable)
17895 mempool_free(mbox, phba->mbox_mem_pool);
17896 else if (rc != MBX_TIMEOUT)
17897 mempool_free(mbox, phba->mbox_mem_pool);
17898 if (shdr_status || shdr_add_status || rc) {
17899 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
17900 "2511 POST_SGL mailbox failed with "
17901 "status x%x add_status x%x, mbx status x%x\n",
17902 shdr_status, shdr_add_status, rc);
17908 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
17909 * @phba: pointer to lpfc hba data structure.
17911 * This routine is invoked to post rpi header templates to the
17912 * HBA consistent with the SLI-4 interface spec. This routine
17913 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17914 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17917 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
17918 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
17921 lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
17926 * Fetch the next logical xri. Because this index is logical,
17927 * the driver starts at 0 each time.
17929 spin_lock_irq(&phba->hbalock);
17930 xri = find_first_zero_bit(phba->sli4_hba.xri_bmask,
17931 phba->sli4_hba.max_cfg_param.max_xri);
17932 if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
17933 spin_unlock_irq(&phba->hbalock);
17936 set_bit(xri, phba->sli4_hba.xri_bmask);
17937 phba->sli4_hba.max_cfg_param.xri_used++;
17939 spin_unlock_irq(&phba->hbalock);
17944 * __lpfc_sli4_free_xri - Release an xri for reuse.
17945 * @phba: pointer to lpfc hba data structure.
17946 * @xri: xri to release.
17948 * This routine is invoked to release an xri to the pool of
17949 * available rpis maintained by the driver.
17952 __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
17954 if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
17955 phba->sli4_hba.max_cfg_param.xri_used--;
17960 * lpfc_sli4_free_xri - Release an xri for reuse.
17961 * @phba: pointer to lpfc hba data structure.
17962 * @xri: xri to release.
17964 * This routine is invoked to release an xri to the pool of
17965 * available rpis maintained by the driver.
17968 lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
17970 spin_lock_irq(&phba->hbalock);
17971 __lpfc_sli4_free_xri(phba, xri);
17972 spin_unlock_irq(&phba->hbalock);
17976 * lpfc_sli4_next_xritag - Get an xritag for the io
17977 * @phba: Pointer to HBA context object.
17979 * This function gets an xritag for the iocb. If there is no unused xritag
17980 * it will return 0xffff.
17981 * The function returns the allocated xritag if successful, else returns zero.
17982 * Zero is not a valid xritag.
17983 * The caller is not required to hold any lock.
17986 lpfc_sli4_next_xritag(struct lpfc_hba *phba)
17988 uint16_t xri_index;
17990 xri_index = lpfc_sli4_alloc_xri(phba);
17991 if (xri_index == NO_XRI)
17992 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
17993 "2004 Failed to allocate XRI.last XRITAG is %d"
17994 " Max XRI is %d, Used XRI is %d\n",
17996 phba->sli4_hba.max_cfg_param.max_xri,
17997 phba->sli4_hba.max_cfg_param.xri_used);
18002 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
18003 * @phba: pointer to lpfc hba data structure.
18004 * @post_sgl_list: pointer to els sgl entry list.
18005 * @post_cnt: number of els sgl entries on the list.
18007 * This routine is invoked to post a block of driver's sgl pages to the
18008 * HBA using non-embedded mailbox command. No Lock is held. This routine
18009 * is only called when the driver is loading and after all IO has been
18013 lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
18014 struct list_head *post_sgl_list,
18017 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
18018 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
18019 struct sgl_page_pairs *sgl_pg_pairs;
18021 LPFC_MBOXQ_t *mbox;
18022 uint32_t reqlen, alloclen, pg_pairs;
18024 uint16_t xritag_start = 0;
18026 uint32_t shdr_status, shdr_add_status;
18027 union lpfc_sli4_cfg_shdr *shdr;
18029 reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
18030 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
18031 if (reqlen > SLI4_PAGE_SIZE) {
18032 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18033 "2559 Block sgl registration required DMA "
18034 "size (%d) great than a page\n", reqlen);
18038 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18042 /* Allocate DMA memory and set up the non-embedded mailbox command */
18043 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
18044 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
18045 LPFC_SLI4_MBX_NEMBED);
18047 if (alloclen < reqlen) {
18048 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18049 "0285 Allocated DMA memory size (%d) is "
18050 "less than the requested DMA memory "
18051 "size (%d)\n", alloclen, reqlen);
18052 lpfc_sli4_mbox_cmd_free(phba, mbox);
18055 /* Set up the SGL pages in the non-embedded DMA pages */
18056 viraddr = mbox->sge_array->addr[0];
18057 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
18058 sgl_pg_pairs = &sgl->sgl_pg_pairs;
18061 list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
18062 /* Set up the sge entry */
18063 sgl_pg_pairs->sgl_pg0_addr_lo =
18064 cpu_to_le32(putPaddrLow(sglq_entry->phys));
18065 sgl_pg_pairs->sgl_pg0_addr_hi =
18066 cpu_to_le32(putPaddrHigh(sglq_entry->phys));
18067 sgl_pg_pairs->sgl_pg1_addr_lo =
18068 cpu_to_le32(putPaddrLow(0));
18069 sgl_pg_pairs->sgl_pg1_addr_hi =
18070 cpu_to_le32(putPaddrHigh(0));
18072 /* Keep the first xritag on the list */
18074 xritag_start = sglq_entry->sli4_xritag;
18079 /* Complete initialization and perform endian conversion. */
18080 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
18081 bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
18082 sgl->word0 = cpu_to_le32(sgl->word0);
18084 if (!phba->sli4_hba.intr_enable)
18085 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
18087 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
18088 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
18090 shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
18091 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18092 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18093 if (!phba->sli4_hba.intr_enable)
18094 lpfc_sli4_mbox_cmd_free(phba, mbox);
18095 else if (rc != MBX_TIMEOUT)
18096 lpfc_sli4_mbox_cmd_free(phba, mbox);
18097 if (shdr_status || shdr_add_status || rc) {
18098 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18099 "2513 POST_SGL_BLOCK mailbox command failed "
18100 "status x%x add_status x%x mbx status x%x\n",
18101 shdr_status, shdr_add_status, rc);
18108 * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
18109 * @phba: pointer to lpfc hba data structure.
18110 * @nblist: pointer to nvme buffer list.
18111 * @count: number of scsi buffers on the list.
18113 * This routine is invoked to post a block of @count scsi sgl pages from a
18114 * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
18119 lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
18122 struct lpfc_io_buf *lpfc_ncmd;
18123 struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
18124 struct sgl_page_pairs *sgl_pg_pairs;
18126 LPFC_MBOXQ_t *mbox;
18127 uint32_t reqlen, alloclen, pg_pairs;
18129 uint16_t xritag_start = 0;
18131 uint32_t shdr_status, shdr_add_status;
18132 dma_addr_t pdma_phys_bpl1;
18133 union lpfc_sli4_cfg_shdr *shdr;
18135 /* Calculate the requested length of the dma memory */
18136 reqlen = count * sizeof(struct sgl_page_pairs) +
18137 sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
18138 if (reqlen > SLI4_PAGE_SIZE) {
18139 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
18140 "6118 Block sgl registration required DMA "
18141 "size (%d) great than a page\n", reqlen);
18144 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
18146 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18147 "6119 Failed to allocate mbox cmd memory\n");
18151 /* Allocate DMA memory and set up the non-embedded mailbox command */
18152 alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
18153 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
18154 reqlen, LPFC_SLI4_MBX_NEMBED);
18156 if (alloclen < reqlen) {
18157 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18158 "6120 Allocated DMA memory size (%d) is "
18159 "less than the requested DMA memory "
18160 "size (%d)\n", alloclen, reqlen);
18161 lpfc_sli4_mbox_cmd_free(phba, mbox);
18165 /* Get the first SGE entry from the non-embedded DMA memory */
18166 viraddr = mbox->sge_array->addr[0];
18168 /* Set up the SGL pages in the non-embedded DMA pages */
18169 sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
18170 sgl_pg_pairs = &sgl->sgl_pg_pairs;
18173 list_for_each_entry(lpfc_ncmd, nblist, list) {
18174 /* Set up the sge entry */
18175 sgl_pg_pairs->sgl_pg0_addr_lo =
18176 cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
18177 sgl_pg_pairs->sgl_pg0_addr_hi =
18178 cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
18179 if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
18180 pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
18183 pdma_phys_bpl1 = 0;
18184 sgl_pg_pairs->sgl_pg1_addr_lo =
18185 cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
18186 sgl_pg_pairs->sgl_pg1_addr_hi =
18187 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
18188 /* Keep the first xritag on the list */
18190 xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
18194 bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
18195 bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
18196 /* Perform endian conversion if necessary */
18197 sgl->word0 = cpu_to_le32(sgl->word0);
18199 if (!phba->sli4_hba.intr_enable) {
18200 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
18202 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
18203 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
18205 shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
18206 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
18207 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
18208 if (!phba->sli4_hba.intr_enable)
18209 lpfc_sli4_mbox_cmd_free(phba, mbox);
18210 else if (rc != MBX_TIMEOUT)
18211 lpfc_sli4_mbox_cmd_free(phba, mbox);
18212 if (shdr_status || shdr_add_status || rc) {
18213 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18214 "6125 POST_SGL_BLOCK mailbox command failed "
18215 "status x%x add_status x%x mbx status x%x\n",
18216 shdr_status, shdr_add_status, rc);
18223 * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
18224 * @phba: pointer to lpfc hba data structure.
18225 * @post_nblist: pointer to the nvme buffer list.
18226 * @sb_count: number of nvme buffers.
18228 * This routine walks a list of nvme buffers that was passed in. It attempts
18229 * to construct blocks of nvme buffer sgls which contains contiguous xris and
18230 * uses the non-embedded SGL block post mailbox commands to post to the port.
18231 * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
18232 * embedded SGL post mailbox command for posting. The @post_nblist passed in
18233 * must be local list, thus no lock is needed when manipulate the list.
18235 * Returns: 0 = failure, non-zero number of successfully posted buffers.
18238 lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
18239 struct list_head *post_nblist, int sb_count)
18241 struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
18242 int status, sgl_size;
18243 int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
18244 dma_addr_t pdma_phys_sgl1;
18245 int last_xritag = NO_XRI;
18247 LIST_HEAD(prep_nblist);
18248 LIST_HEAD(blck_nblist);
18249 LIST_HEAD(nvme_nblist);
18255 sgl_size = phba->cfg_sg_dma_buf_size;
18256 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
18257 list_del_init(&lpfc_ncmd->list);
18259 if ((last_xritag != NO_XRI) &&
18260 (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
18261 /* a hole in xri block, form a sgl posting block */
18262 list_splice_init(&prep_nblist, &blck_nblist);
18263 post_cnt = block_cnt - 1;
18264 /* prepare list for next posting block */
18265 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
18268 /* prepare list for next posting block */
18269 list_add_tail(&lpfc_ncmd->list, &prep_nblist);
18270 /* enough sgls for non-embed sgl mbox command */
18271 if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
18272 list_splice_init(&prep_nblist, &blck_nblist);
18273 post_cnt = block_cnt;
18278 last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
18280 /* end of repost sgl list condition for NVME buffers */
18281 if (num_posting == sb_count) {
18282 if (post_cnt == 0) {
18283 /* last sgl posting block */
18284 list_splice_init(&prep_nblist, &blck_nblist);
18285 post_cnt = block_cnt;
18286 } else if (block_cnt == 1) {
18287 /* last single sgl with non-contiguous xri */
18288 if (sgl_size > SGL_PAGE_SIZE)
18290 lpfc_ncmd->dma_phys_sgl +
18293 pdma_phys_sgl1 = 0;
18294 cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
18295 status = lpfc_sli4_post_sgl(
18296 phba, lpfc_ncmd->dma_phys_sgl,
18297 pdma_phys_sgl1, cur_xritag);
18299 /* Post error. Buffer unavailable. */
18300 lpfc_ncmd->flags |=
18301 LPFC_SBUF_NOT_POSTED;
18303 /* Post success. Bffer available. */
18304 lpfc_ncmd->flags &=
18305 ~LPFC_SBUF_NOT_POSTED;
18306 lpfc_ncmd->status = IOSTAT_SUCCESS;
18309 /* success, put on NVME buffer sgl list */
18310 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
18314 /* continue until a nembed page worth of sgls */
18318 /* post block of NVME buffer list sgls */
18319 status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
18322 /* don't reset xirtag due to hole in xri block */
18323 if (block_cnt == 0)
18324 last_xritag = NO_XRI;
18326 /* reset NVME buffer post count for next round of posting */
18329 /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
18330 while (!list_empty(&blck_nblist)) {
18331 list_remove_head(&blck_nblist, lpfc_ncmd,
18332 struct lpfc_io_buf, list);
18334 /* Post error. Mark buffer unavailable. */
18335 lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
18337 /* Post success, Mark buffer available. */
18338 lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
18339 lpfc_ncmd->status = IOSTAT_SUCCESS;
18342 list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
18345 /* Push NVME buffers with sgl posted to the available list */
18346 lpfc_io_buf_replenish(phba, &nvme_nblist);
18352 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
18353 * @phba: pointer to lpfc_hba struct that the frame was received on
18354 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
18356 * This function checks the fields in the @fc_hdr to see if the FC frame is a
18357 * valid type of frame that the LPFC driver will handle. This function will
18358 * return a zero if the frame is a valid frame or a non zero value when the
18359 * frame does not pass the check.
18362 lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
18364 /* make rctl_names static to save stack space */
18365 struct fc_vft_header *fc_vft_hdr;
18366 uint32_t *header = (uint32_t *) fc_hdr;
18368 #define FC_RCTL_MDS_DIAGS 0xF4
18370 switch (fc_hdr->fh_r_ctl) {
18371 case FC_RCTL_DD_UNCAT: /* uncategorized information */
18372 case FC_RCTL_DD_SOL_DATA: /* solicited data */
18373 case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
18374 case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
18375 case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
18376 case FC_RCTL_DD_DATA_DESC: /* data descriptor */
18377 case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
18378 case FC_RCTL_DD_CMD_STATUS: /* command status */
18379 case FC_RCTL_ELS_REQ: /* extended link services request */
18380 case FC_RCTL_ELS_REP: /* extended link services reply */
18381 case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
18382 case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
18383 case FC_RCTL_BA_ABTS: /* basic link service abort */
18384 case FC_RCTL_BA_RMC: /* remove connection */
18385 case FC_RCTL_BA_ACC: /* basic accept */
18386 case FC_RCTL_BA_RJT: /* basic reject */
18387 case FC_RCTL_BA_PRMT:
18388 case FC_RCTL_ACK_1: /* acknowledge_1 */
18389 case FC_RCTL_ACK_0: /* acknowledge_0 */
18390 case FC_RCTL_P_RJT: /* port reject */
18391 case FC_RCTL_F_RJT: /* fabric reject */
18392 case FC_RCTL_P_BSY: /* port busy */
18393 case FC_RCTL_F_BSY: /* fabric busy to data frame */
18394 case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
18395 case FC_RCTL_LCR: /* link credit reset */
18396 case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
18397 case FC_RCTL_END: /* end */
18399 case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
18400 fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
18401 fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
18402 return lpfc_fc_frame_check(phba, fc_hdr);
18403 case FC_RCTL_BA_NOP: /* basic link service NOP */
18408 switch (fc_hdr->fh_type) {
18421 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
18422 "2538 Received frame rctl:x%x, type:x%x, "
18423 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
18424 fc_hdr->fh_r_ctl, fc_hdr->fh_type,
18425 be32_to_cpu(header[0]), be32_to_cpu(header[1]),
18426 be32_to_cpu(header[2]), be32_to_cpu(header[3]),
18427 be32_to_cpu(header[4]), be32_to_cpu(header[5]),
18428 be32_to_cpu(header[6]));
18431 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
18432 "2539 Dropped frame rctl:x%x type:x%x\n",
18433 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
18438 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
18439 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
18441 * This function processes the FC header to retrieve the VFI from the VF
18442 * header, if one exists. This function will return the VFI if one exists
18443 * or 0 if no VSAN Header exists.
18446 lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
18448 struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
18450 if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
18452 return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
18456 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
18457 * @phba: Pointer to the HBA structure to search for the vport on
18458 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
18459 * @fcfi: The FC Fabric ID that the frame came from
18460 * @did: Destination ID to match against
18462 * This function searches the @phba for a vport that matches the content of the
18463 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
18464 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
18465 * returns the matching vport pointer or NULL if unable to match frame to a
18468 static struct lpfc_vport *
18469 lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
18470 uint16_t fcfi, uint32_t did)
18472 struct lpfc_vport **vports;
18473 struct lpfc_vport *vport = NULL;
18476 if (did == Fabric_DID)
18477 return phba->pport;
18478 if ((phba->pport->fc_flag & FC_PT2PT) &&
18479 !(phba->link_state == LPFC_HBA_READY))
18480 return phba->pport;
18482 vports = lpfc_create_vport_work_array(phba);
18483 if (vports != NULL) {
18484 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
18485 if (phba->fcf.fcfi == fcfi &&
18486 vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
18487 vports[i]->fc_myDID == did) {
18493 lpfc_destroy_vport_work_array(phba, vports);
18498 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
18499 * @vport: The vport to work on.
18501 * This function updates the receive sequence time stamp for this vport. The
18502 * receive sequence time stamp indicates the time that the last frame of the
18503 * the sequence that has been idle for the longest amount of time was received.
18504 * the driver uses this time stamp to indicate if any received sequences have
18508 lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
18510 struct lpfc_dmabuf *h_buf;
18511 struct hbq_dmabuf *dmabuf = NULL;
18513 /* get the oldest sequence on the rcv list */
18514 h_buf = list_get_first(&vport->rcv_buffer_list,
18515 struct lpfc_dmabuf, list);
18518 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18519 vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
18523 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
18524 * @vport: The vport that the received sequences were sent to.
18526 * This function cleans up all outstanding received sequences. This is called
18527 * by the driver when a link event or user action invalidates all the received
18531 lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
18533 struct lpfc_dmabuf *h_buf, *hnext;
18534 struct lpfc_dmabuf *d_buf, *dnext;
18535 struct hbq_dmabuf *dmabuf = NULL;
18537 /* start with the oldest sequence on the rcv list */
18538 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
18539 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18540 list_del_init(&dmabuf->hbuf.list);
18541 list_for_each_entry_safe(d_buf, dnext,
18542 &dmabuf->dbuf.list, list) {
18543 list_del_init(&d_buf->list);
18544 lpfc_in_buf_free(vport->phba, d_buf);
18546 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
18551 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
18552 * @vport: The vport that the received sequences were sent to.
18554 * This function determines whether any received sequences have timed out by
18555 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
18556 * indicates that there is at least one timed out sequence this routine will
18557 * go through the received sequences one at a time from most inactive to most
18558 * active to determine which ones need to be cleaned up. Once it has determined
18559 * that a sequence needs to be cleaned up it will simply free up the resources
18560 * without sending an abort.
18563 lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
18565 struct lpfc_dmabuf *h_buf, *hnext;
18566 struct lpfc_dmabuf *d_buf, *dnext;
18567 struct hbq_dmabuf *dmabuf = NULL;
18568 unsigned long timeout;
18569 int abort_count = 0;
18571 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
18572 vport->rcv_buffer_time_stamp);
18573 if (list_empty(&vport->rcv_buffer_list) ||
18574 time_before(jiffies, timeout))
18576 /* start with the oldest sequence on the rcv list */
18577 list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
18578 dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18579 timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
18580 dmabuf->time_stamp);
18581 if (time_before(jiffies, timeout))
18584 list_del_init(&dmabuf->hbuf.list);
18585 list_for_each_entry_safe(d_buf, dnext,
18586 &dmabuf->dbuf.list, list) {
18587 list_del_init(&d_buf->list);
18588 lpfc_in_buf_free(vport->phba, d_buf);
18590 lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
18593 lpfc_update_rcv_time_stamp(vport);
18597 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
18598 * @vport: pointer to a vitural port
18599 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
18601 * This function searches through the existing incomplete sequences that have
18602 * been sent to this @vport. If the frame matches one of the incomplete
18603 * sequences then the dbuf in the @dmabuf is added to the list of frames that
18604 * make up that sequence. If no sequence is found that matches this frame then
18605 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
18606 * This function returns a pointer to the first dmabuf in the sequence list that
18607 * the frame was linked to.
18609 static struct hbq_dmabuf *
18610 lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
18612 struct fc_frame_header *new_hdr;
18613 struct fc_frame_header *temp_hdr;
18614 struct lpfc_dmabuf *d_buf;
18615 struct lpfc_dmabuf *h_buf;
18616 struct hbq_dmabuf *seq_dmabuf = NULL;
18617 struct hbq_dmabuf *temp_dmabuf = NULL;
18620 INIT_LIST_HEAD(&dmabuf->dbuf.list);
18621 dmabuf->time_stamp = jiffies;
18622 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18624 /* Use the hdr_buf to find the sequence that this frame belongs to */
18625 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
18626 temp_hdr = (struct fc_frame_header *)h_buf->virt;
18627 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
18628 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
18629 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
18631 /* found a pending sequence that matches this frame */
18632 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18637 * This indicates first frame received for this sequence.
18638 * Queue the buffer on the vport's rcv_buffer_list.
18640 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
18641 lpfc_update_rcv_time_stamp(vport);
18644 temp_hdr = seq_dmabuf->hbuf.virt;
18645 if (be16_to_cpu(new_hdr->fh_seq_cnt) <
18646 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
18647 list_del_init(&seq_dmabuf->hbuf.list);
18648 list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
18649 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
18650 lpfc_update_rcv_time_stamp(vport);
18653 /* move this sequence to the tail to indicate a young sequence */
18654 list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
18655 seq_dmabuf->time_stamp = jiffies;
18656 lpfc_update_rcv_time_stamp(vport);
18657 if (list_empty(&seq_dmabuf->dbuf.list)) {
18658 list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
18661 /* find the correct place in the sequence to insert this frame */
18662 d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
18664 temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
18665 temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
18667 * If the frame's sequence count is greater than the frame on
18668 * the list then insert the frame right after this frame
18670 if (be16_to_cpu(new_hdr->fh_seq_cnt) >
18671 be16_to_cpu(temp_hdr->fh_seq_cnt)) {
18672 list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
18677 if (&d_buf->list == &seq_dmabuf->dbuf.list)
18679 d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
18688 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
18689 * @vport: pointer to a vitural port
18690 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18692 * This function tries to abort from the partially assembed sequence, described
18693 * by the information from basic abbort @dmabuf. It checks to see whether such
18694 * partially assembled sequence held by the driver. If so, it shall free up all
18695 * the frames from the partially assembled sequence.
18698 * true -- if there is matching partially assembled sequence present and all
18699 * the frames freed with the sequence;
18700 * false -- if there is no matching partially assembled sequence present so
18701 * nothing got aborted in the lower layer driver
18704 lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
18705 struct hbq_dmabuf *dmabuf)
18707 struct fc_frame_header *new_hdr;
18708 struct fc_frame_header *temp_hdr;
18709 struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
18710 struct hbq_dmabuf *seq_dmabuf = NULL;
18712 /* Use the hdr_buf to find the sequence that matches this frame */
18713 INIT_LIST_HEAD(&dmabuf->dbuf.list);
18714 INIT_LIST_HEAD(&dmabuf->hbuf.list);
18715 new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
18716 list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
18717 temp_hdr = (struct fc_frame_header *)h_buf->virt;
18718 if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
18719 (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
18720 (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
18722 /* found a pending sequence that matches this frame */
18723 seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
18727 /* Free up all the frames from the partially assembled sequence */
18729 list_for_each_entry_safe(d_buf, n_buf,
18730 &seq_dmabuf->dbuf.list, list) {
18731 list_del_init(&d_buf->list);
18732 lpfc_in_buf_free(vport->phba, d_buf);
18740 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
18741 * @vport: pointer to a vitural port
18742 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18744 * This function tries to abort from the assembed sequence from upper level
18745 * protocol, described by the information from basic abbort @dmabuf. It
18746 * checks to see whether such pending context exists at upper level protocol.
18747 * If so, it shall clean up the pending context.
18750 * true -- if there is matching pending context of the sequence cleaned
18752 * false -- if there is no matching pending context of the sequence present
18756 lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
18758 struct lpfc_hba *phba = vport->phba;
18761 /* Accepting abort at ulp with SLI4 only */
18762 if (phba->sli_rev < LPFC_SLI_REV4)
18765 /* Register all caring upper level protocols to attend abort */
18766 handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
18774 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
18775 * @phba: Pointer to HBA context object.
18776 * @cmd_iocbq: pointer to the command iocbq structure.
18777 * @rsp_iocbq: pointer to the response iocbq structure.
18779 * This function handles the sequence abort response iocb command complete
18780 * event. It properly releases the memory allocated to the sequence abort
18784 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
18785 struct lpfc_iocbq *cmd_iocbq,
18786 struct lpfc_iocbq *rsp_iocbq)
18789 lpfc_nlp_put(cmd_iocbq->ndlp);
18790 lpfc_sli_release_iocbq(phba, cmd_iocbq);
18793 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
18794 if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
18795 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
18796 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
18797 get_job_ulpstatus(phba, rsp_iocbq),
18798 get_job_word4(phba, rsp_iocbq));
18802 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
18803 * @phba: Pointer to HBA context object.
18804 * @xri: xri id in transaction.
18806 * This function validates the xri maps to the known range of XRIs allocated an
18807 * used by the driver.
18810 lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
18815 for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
18816 if (xri == phba->sli4_hba.xri_ids[i])
18823 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
18824 * @vport: pointer to a virtual port.
18825 * @fc_hdr: pointer to a FC frame header.
18826 * @aborted: was the partially assembled receive sequence successfully aborted
18828 * This function sends a basic response to a previous unsol sequence abort
18829 * event after aborting the sequence handling.
18832 lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
18833 struct fc_frame_header *fc_hdr, bool aborted)
18835 struct lpfc_hba *phba = vport->phba;
18836 struct lpfc_iocbq *ctiocb = NULL;
18837 struct lpfc_nodelist *ndlp;
18838 uint16_t oxid, rxid, xri, lxri;
18839 uint32_t sid, fctl;
18840 union lpfc_wqe128 *icmd;
18843 if (!lpfc_is_link_up(phba))
18846 sid = sli4_sid_from_fc_hdr(fc_hdr);
18847 oxid = be16_to_cpu(fc_hdr->fh_ox_id);
18848 rxid = be16_to_cpu(fc_hdr->fh_rx_id);
18850 ndlp = lpfc_findnode_did(vport, sid);
18852 ndlp = lpfc_nlp_init(vport, sid);
18854 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
18855 "1268 Failed to allocate ndlp for "
18856 "oxid:x%x SID:x%x\n", oxid, sid);
18859 /* Put ndlp onto pport node list */
18860 lpfc_enqueue_node(vport, ndlp);
18863 /* Allocate buffer for rsp iocb */
18864 ctiocb = lpfc_sli_get_iocbq(phba);
18868 icmd = &ctiocb->wqe;
18870 /* Extract the F_CTL field from FC_HDR */
18871 fctl = sli4_fctl_from_fc_hdr(fc_hdr);
18873 ctiocb->ndlp = lpfc_nlp_get(ndlp);
18874 if (!ctiocb->ndlp) {
18875 lpfc_sli_release_iocbq(phba, ctiocb);
18879 ctiocb->vport = phba->pport;
18880 ctiocb->cmd_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
18881 ctiocb->sli4_lxritag = NO_XRI;
18882 ctiocb->sli4_xritag = NO_XRI;
18883 ctiocb->abort_rctl = FC_RCTL_BA_ACC;
18885 if (fctl & FC_FC_EX_CTX)
18886 /* Exchange responder sent the abort so we
18892 lxri = lpfc_sli4_xri_inrange(phba, xri);
18893 if (lxri != NO_XRI)
18894 lpfc_set_rrq_active(phba, ndlp, lxri,
18895 (xri == oxid) ? rxid : oxid, 0);
18896 /* For BA_ABTS from exchange responder, if the logical xri with
18897 * the oxid maps to the FCP XRI range, the port no longer has
18898 * that exchange context, send a BLS_RJT. Override the IOCB for
18901 if ((fctl & FC_FC_EX_CTX) &&
18902 (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
18903 ctiocb->abort_rctl = FC_RCTL_BA_RJT;
18904 bf_set(xmit_bls_rsp64_rjt_vspec, &icmd->xmit_bls_rsp, 0);
18905 bf_set(xmit_bls_rsp64_rjt_expc, &icmd->xmit_bls_rsp,
18906 FC_BA_RJT_INV_XID);
18907 bf_set(xmit_bls_rsp64_rjt_rsnc, &icmd->xmit_bls_rsp,
18911 /* If BA_ABTS failed to abort a partially assembled receive sequence,
18912 * the driver no longer has that exchange, send a BLS_RJT. Override
18913 * the IOCB for a BA_RJT.
18915 if (aborted == false) {
18916 ctiocb->abort_rctl = FC_RCTL_BA_RJT;
18917 bf_set(xmit_bls_rsp64_rjt_vspec, &icmd->xmit_bls_rsp, 0);
18918 bf_set(xmit_bls_rsp64_rjt_expc, &icmd->xmit_bls_rsp,
18919 FC_BA_RJT_INV_XID);
18920 bf_set(xmit_bls_rsp64_rjt_rsnc, &icmd->xmit_bls_rsp,
18924 if (fctl & FC_FC_EX_CTX) {
18925 /* ABTS sent by responder to CT exchange, construction
18926 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
18927 * field and RX_ID from ABTS for RX_ID field.
18929 ctiocb->abort_bls = LPFC_ABTS_UNSOL_RSP;
18930 bf_set(xmit_bls_rsp64_rxid, &icmd->xmit_bls_rsp, rxid);
18932 /* ABTS sent by initiator to CT exchange, construction
18933 * of BA_ACC will need to allocate a new XRI as for the
18936 ctiocb->abort_bls = LPFC_ABTS_UNSOL_INT;
18939 /* OX_ID is invariable to who sent ABTS to CT exchange */
18940 bf_set(xmit_bls_rsp64_oxid, &icmd->xmit_bls_rsp, oxid);
18941 bf_set(xmit_bls_rsp64_oxid, &icmd->xmit_bls_rsp, rxid);
18944 bf_set(wqe_els_did, &icmd->xmit_bls_rsp.wqe_dest,
18946 bf_set(xmit_bls_rsp64_temprpi, &icmd->xmit_bls_rsp,
18947 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
18948 bf_set(wqe_cmnd, &icmd->generic.wqe_com, CMD_XMIT_BLS_RSP64_CX);
18950 /* Xmit CT abts response on exchange <xid> */
18951 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
18952 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
18953 ctiocb->abort_rctl, oxid, phba->link_state);
18955 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
18956 if (rc == IOCB_ERROR) {
18957 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
18958 "2925 Failed to issue CT ABTS RSP x%x on "
18959 "xri x%x, Data x%x\n",
18960 ctiocb->abort_rctl, oxid,
18962 lpfc_nlp_put(ndlp);
18963 ctiocb->ndlp = NULL;
18964 lpfc_sli_release_iocbq(phba, ctiocb);
18969 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
18970 * @vport: Pointer to the vport on which this sequence was received
18971 * @dmabuf: pointer to a dmabuf that describes the FC sequence
18973 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
18974 * receive sequence is only partially assembed by the driver, it shall abort
18975 * the partially assembled frames for the sequence. Otherwise, if the
18976 * unsolicited receive sequence has been completely assembled and passed to
18977 * the Upper Layer Protocol (ULP), it then mark the per oxid status for the
18978 * unsolicited sequence has been aborted. After that, it will issue a basic
18979 * accept to accept the abort.
18982 lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
18983 struct hbq_dmabuf *dmabuf)
18985 struct lpfc_hba *phba = vport->phba;
18986 struct fc_frame_header fc_hdr;
18990 /* Make a copy of fc_hdr before the dmabuf being released */
18991 memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
18992 fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
18994 if (fctl & FC_FC_EX_CTX) {
18995 /* ABTS by responder to exchange, no cleanup needed */
18998 /* ABTS by initiator to exchange, need to do cleanup */
18999 aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
19000 if (aborted == false)
19001 aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
19003 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19005 if (phba->nvmet_support) {
19006 lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
19010 /* Respond with BA_ACC or BA_RJT accordingly */
19011 lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
19015 * lpfc_seq_complete - Indicates if a sequence is complete
19016 * @dmabuf: pointer to a dmabuf that describes the FC sequence
19018 * This function checks the sequence, starting with the frame described by
19019 * @dmabuf, to see if all the frames associated with this sequence are present.
19020 * the frames associated with this sequence are linked to the @dmabuf using the
19021 * dbuf list. This function looks for two major things. 1) That the first frame
19022 * has a sequence count of zero. 2) There is a frame with last frame of sequence
19023 * set. 3) That there are no holes in the sequence count. The function will
19024 * return 1 when the sequence is complete, otherwise it will return 0.
19027 lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
19029 struct fc_frame_header *hdr;
19030 struct lpfc_dmabuf *d_buf;
19031 struct hbq_dmabuf *seq_dmabuf;
19035 hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
19036 /* make sure first fame of sequence has a sequence count of zero */
19037 if (hdr->fh_seq_cnt != seq_count)
19039 fctl = (hdr->fh_f_ctl[0] << 16 |
19040 hdr->fh_f_ctl[1] << 8 |
19042 /* If last frame of sequence we can return success. */
19043 if (fctl & FC_FC_END_SEQ)
19045 list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
19046 seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
19047 hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
19048 /* If there is a hole in the sequence count then fail. */
19049 if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
19051 fctl = (hdr->fh_f_ctl[0] << 16 |
19052 hdr->fh_f_ctl[1] << 8 |
19054 /* If last frame of sequence we can return success. */
19055 if (fctl & FC_FC_END_SEQ)
19062 * lpfc_prep_seq - Prep sequence for ULP processing
19063 * @vport: Pointer to the vport on which this sequence was received
19064 * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence
19066 * This function takes a sequence, described by a list of frames, and creates
19067 * a list of iocbq structures to describe the sequence. This iocbq list will be
19068 * used to issue to the generic unsolicited sequence handler. This routine
19069 * returns a pointer to the first iocbq in the list. If the function is unable
19070 * to allocate an iocbq then it throw out the received frames that were not
19071 * able to be described and return a pointer to the first iocbq. If unable to
19072 * allocate any iocbqs (including the first) this function will return NULL.
19074 static struct lpfc_iocbq *
19075 lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
19077 struct hbq_dmabuf *hbq_buf;
19078 struct lpfc_dmabuf *d_buf, *n_buf;
19079 struct lpfc_iocbq *first_iocbq, *iocbq;
19080 struct fc_frame_header *fc_hdr;
19082 uint32_t len, tot_len;
19084 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
19085 /* remove from receive buffer list */
19086 list_del_init(&seq_dmabuf->hbuf.list);
19087 lpfc_update_rcv_time_stamp(vport);
19088 /* get the Remote Port's SID */
19089 sid = sli4_sid_from_fc_hdr(fc_hdr);
19091 /* Get an iocbq struct to fill in. */
19092 first_iocbq = lpfc_sli_get_iocbq(vport->phba);
19094 /* Initialize the first IOCB. */
19095 first_iocbq->wcqe_cmpl.total_data_placed = 0;
19096 bf_set(lpfc_wcqe_c_status, &first_iocbq->wcqe_cmpl,
19098 first_iocbq->vport = vport;
19100 /* Check FC Header to see what TYPE of frame we are rcv'ing */
19101 if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
19102 bf_set(els_rsp64_sid, &first_iocbq->wqe.xmit_els_rsp,
19103 sli4_did_from_fc_hdr(fc_hdr));
19106 bf_set(wqe_ctxt_tag, &first_iocbq->wqe.xmit_els_rsp.wqe_com,
19108 bf_set(wqe_rcvoxid, &first_iocbq->wqe.xmit_els_rsp.wqe_com,
19109 be16_to_cpu(fc_hdr->fh_ox_id));
19111 /* put the first buffer into the first iocb */
19112 tot_len = bf_get(lpfc_rcqe_length,
19113 &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
19115 first_iocbq->cmd_dmabuf = &seq_dmabuf->dbuf;
19116 first_iocbq->bpl_dmabuf = NULL;
19117 /* Keep track of the BDE count */
19118 first_iocbq->wcqe_cmpl.word3 = 1;
19120 if (tot_len > LPFC_DATA_BUF_SIZE)
19121 first_iocbq->wqe.gen_req.bde.tus.f.bdeSize =
19122 LPFC_DATA_BUF_SIZE;
19124 first_iocbq->wqe.gen_req.bde.tus.f.bdeSize = tot_len;
19126 first_iocbq->wcqe_cmpl.total_data_placed = tot_len;
19127 bf_set(wqe_els_did, &first_iocbq->wqe.xmit_els_rsp.wqe_dest,
19130 iocbq = first_iocbq;
19132 * Each IOCBq can have two Buffers assigned, so go through the list
19133 * of buffers for this sequence and save two buffers in each IOCBq
19135 list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
19137 lpfc_in_buf_free(vport->phba, d_buf);
19140 if (!iocbq->bpl_dmabuf) {
19141 iocbq->bpl_dmabuf = d_buf;
19142 iocbq->wcqe_cmpl.word3++;
19143 /* We need to get the size out of the right CQE */
19144 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
19145 len = bf_get(lpfc_rcqe_length,
19146 &hbq_buf->cq_event.cqe.rcqe_cmpl);
19147 iocbq->unsol_rcv_len = len;
19148 iocbq->wcqe_cmpl.total_data_placed += len;
19151 iocbq = lpfc_sli_get_iocbq(vport->phba);
19154 bf_set(lpfc_wcqe_c_status,
19155 &first_iocbq->wcqe_cmpl,
19157 first_iocbq->wcqe_cmpl.parameter =
19158 IOERR_NO_RESOURCES;
19160 lpfc_in_buf_free(vport->phba, d_buf);
19163 /* We need to get the size out of the right CQE */
19164 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
19165 len = bf_get(lpfc_rcqe_length,
19166 &hbq_buf->cq_event.cqe.rcqe_cmpl);
19167 iocbq->cmd_dmabuf = d_buf;
19168 iocbq->bpl_dmabuf = NULL;
19169 iocbq->wcqe_cmpl.word3 = 1;
19171 if (len > LPFC_DATA_BUF_SIZE)
19172 iocbq->wqe.xmit_els_rsp.bde.tus.f.bdeSize =
19173 LPFC_DATA_BUF_SIZE;
19175 iocbq->wqe.xmit_els_rsp.bde.tus.f.bdeSize =
19179 iocbq->wcqe_cmpl.total_data_placed = tot_len;
19180 bf_set(wqe_els_did, &iocbq->wqe.xmit_els_rsp.wqe_dest,
19182 list_add_tail(&iocbq->list, &first_iocbq->list);
19185 /* Free the sequence's header buffer */
19187 lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf);
19189 return first_iocbq;
19193 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
19194 struct hbq_dmabuf *seq_dmabuf)
19196 struct fc_frame_header *fc_hdr;
19197 struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
19198 struct lpfc_hba *phba = vport->phba;
19200 fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
19201 iocbq = lpfc_prep_seq(vport, seq_dmabuf);
19203 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19204 "2707 Ring %d handler: Failed to allocate "
19205 "iocb Rctl x%x Type x%x received\n",
19207 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
19210 if (!lpfc_complete_unsol_iocb(phba,
19211 phba->sli4_hba.els_wq->pring,
19212 iocbq, fc_hdr->fh_r_ctl,
19213 fc_hdr->fh_type)) {
19214 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19215 "2540 Ring %d handler: unexpected Rctl "
19216 "x%x Type x%x received\n",
19218 fc_hdr->fh_r_ctl, fc_hdr->fh_type);
19219 lpfc_in_buf_free(phba, &seq_dmabuf->dbuf);
19222 /* Free iocb created in lpfc_prep_seq */
19223 list_for_each_entry_safe(curr_iocb, next_iocb,
19224 &iocbq->list, list) {
19225 list_del_init(&curr_iocb->list);
19226 lpfc_sli_release_iocbq(phba, curr_iocb);
19228 lpfc_sli_release_iocbq(phba, iocbq);
19232 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
19233 struct lpfc_iocbq *rspiocb)
19235 struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
19237 if (pcmd && pcmd->virt)
19238 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
19240 lpfc_sli_release_iocbq(phba, cmdiocb);
19241 lpfc_drain_txq(phba);
19245 lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
19246 struct hbq_dmabuf *dmabuf)
19248 struct fc_frame_header *fc_hdr;
19249 struct lpfc_hba *phba = vport->phba;
19250 struct lpfc_iocbq *iocbq = NULL;
19251 union lpfc_wqe128 *pwqe;
19252 struct lpfc_dmabuf *pcmd = NULL;
19253 uint32_t frame_len;
19255 unsigned long iflags;
19257 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
19258 frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
19260 /* Send the received frame back */
19261 iocbq = lpfc_sli_get_iocbq(phba);
19263 /* Queue cq event and wakeup worker thread to process it */
19264 spin_lock_irqsave(&phba->hbalock, iflags);
19265 list_add_tail(&dmabuf->cq_event.list,
19266 &phba->sli4_hba.sp_queue_event);
19267 phba->hba_flag |= HBA_SP_QUEUE_EVT;
19268 spin_unlock_irqrestore(&phba->hbalock, iflags);
19269 lpfc_worker_wake_up(phba);
19273 /* Allocate buffer for command payload */
19274 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
19276 pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
19278 if (!pcmd || !pcmd->virt)
19281 INIT_LIST_HEAD(&pcmd->list);
19283 /* copyin the payload */
19284 memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
19286 iocbq->cmd_dmabuf = pcmd;
19287 iocbq->vport = vport;
19288 iocbq->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK;
19289 iocbq->cmd_flag |= LPFC_USE_FCPWQIDX;
19290 iocbq->num_bdes = 0;
19292 pwqe = &iocbq->wqe;
19293 /* fill in BDE's for command */
19294 pwqe->gen_req.bde.addrHigh = putPaddrHigh(pcmd->phys);
19295 pwqe->gen_req.bde.addrLow = putPaddrLow(pcmd->phys);
19296 pwqe->gen_req.bde.tus.f.bdeSize = frame_len;
19297 pwqe->gen_req.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
19299 pwqe->send_frame.frame_len = frame_len;
19300 pwqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((__be32 *)fc_hdr));
19301 pwqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((__be32 *)fc_hdr + 1));
19302 pwqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((__be32 *)fc_hdr + 2));
19303 pwqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((__be32 *)fc_hdr + 3));
19304 pwqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((__be32 *)fc_hdr + 4));
19305 pwqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((__be32 *)fc_hdr + 5));
19307 pwqe->generic.wqe_com.word7 = 0;
19308 pwqe->generic.wqe_com.word10 = 0;
19310 bf_set(wqe_cmnd, &pwqe->generic.wqe_com, CMD_SEND_FRAME);
19311 bf_set(wqe_sof, &pwqe->generic.wqe_com, 0x2E); /* SOF byte */
19312 bf_set(wqe_eof, &pwqe->generic.wqe_com, 0x41); /* EOF byte */
19313 bf_set(wqe_lenloc, &pwqe->generic.wqe_com, 1);
19314 bf_set(wqe_xbl, &pwqe->generic.wqe_com, 1);
19315 bf_set(wqe_dbde, &pwqe->generic.wqe_com, 1);
19316 bf_set(wqe_xc, &pwqe->generic.wqe_com, 1);
19317 bf_set(wqe_cmd_type, &pwqe->generic.wqe_com, 0xA);
19318 bf_set(wqe_cqid, &pwqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
19319 bf_set(wqe_xri_tag, &pwqe->generic.wqe_com, iocbq->sli4_xritag);
19320 bf_set(wqe_reqtag, &pwqe->generic.wqe_com, iocbq->iotag);
19321 bf_set(wqe_class, &pwqe->generic.wqe_com, CLASS3);
19322 pwqe->generic.wqe_com.abort_tag = iocbq->iotag;
19324 iocbq->cmd_cmpl = lpfc_sli4_mds_loopback_cmpl;
19326 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
19327 if (rc == IOCB_ERROR)
19330 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19334 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
19335 "2023 Unable to process MDS loopback frame\n");
19336 if (pcmd && pcmd->virt)
19337 dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
19340 lpfc_sli_release_iocbq(phba, iocbq);
19341 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19345 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
19346 * @phba: Pointer to HBA context object.
19347 * @dmabuf: Pointer to a dmabuf that describes the FC sequence.
19349 * This function is called with no lock held. This function processes all
19350 * the received buffers and gives it to upper layers when a received buffer
19351 * indicates that it is the final frame in the sequence. The interrupt
19352 * service routine processes received buffers at interrupt contexts.
19353 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
19354 * appropriate receive function when the final frame in a sequence is received.
19357 lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
19358 struct hbq_dmabuf *dmabuf)
19360 struct hbq_dmabuf *seq_dmabuf;
19361 struct fc_frame_header *fc_hdr;
19362 struct lpfc_vport *vport;
19366 /* Process each received buffer */
19367 fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
19369 if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
19370 fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
19371 vport = phba->pport;
19372 /* Handle MDS Loopback frames */
19373 if (!(phba->pport->load_flag & FC_UNLOADING))
19374 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
19376 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19380 /* check to see if this a valid type of frame */
19381 if (lpfc_fc_frame_check(phba, fc_hdr)) {
19382 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19386 if ((bf_get(lpfc_cqe_code,
19387 &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
19388 fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
19389 &dmabuf->cq_event.cqe.rcqe_cmpl);
19391 fcfi = bf_get(lpfc_rcqe_fcf_id,
19392 &dmabuf->cq_event.cqe.rcqe_cmpl);
19394 if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
19395 vport = phba->pport;
19396 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
19397 "2023 MDS Loopback %d bytes\n",
19398 bf_get(lpfc_rcqe_length,
19399 &dmabuf->cq_event.cqe.rcqe_cmpl));
19400 /* Handle MDS Loopback frames */
19401 lpfc_sli4_handle_mds_loopback(vport, dmabuf);
19405 /* d_id this frame is directed to */
19406 did = sli4_did_from_fc_hdr(fc_hdr);
19408 vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
19410 /* throw out the frame */
19411 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19415 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
19416 if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
19417 (did != Fabric_DID)) {
19419 * Throw out the frame if we are not pt2pt.
19420 * The pt2pt protocol allows for discovery frames
19421 * to be received without a registered VPI.
19423 if (!(vport->fc_flag & FC_PT2PT) ||
19424 (phba->link_state == LPFC_HBA_READY)) {
19425 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19430 /* Handle the basic abort sequence (BA_ABTS) event */
19431 if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
19432 lpfc_sli4_handle_unsol_abort(vport, dmabuf);
19436 /* Link this frame */
19437 seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
19439 /* unable to add frame to vport - throw it out */
19440 lpfc_in_buf_free(phba, &dmabuf->dbuf);
19443 /* If not last frame in sequence continue processing frames. */
19444 if (!lpfc_seq_complete(seq_dmabuf))
19447 /* Send the complete sequence to the upper layer protocol */
19448 lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
19452 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
19453 * @phba: pointer to lpfc hba data structure.
19455 * This routine is invoked to post rpi header templates to the
19456 * HBA consistent with the SLI-4 interface spec. This routine
19457 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
19458 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
19460 * This routine does not require any locks. It's usage is expected
19461 * to be driver load or reset recovery when the driver is
19466 * -EIO - The mailbox failed to complete successfully.
19467 * When this error occurs, the driver is not guaranteed
19468 * to have any rpi regions posted to the device and
19469 * must either attempt to repost the regions or take a
19473 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
19475 struct lpfc_rpi_hdr *rpi_page;
19479 /* SLI4 ports that support extents do not require RPI headers. */
19480 if (!phba->sli4_hba.rpi_hdrs_in_use)
19482 if (phba->sli4_hba.extents_in_use)
19485 list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
19487 * Assign the rpi headers a physical rpi only if the driver
19488 * has not initialized those resources. A port reset only
19489 * needs the headers posted.
19491 if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
19493 rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
19495 rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
19496 if (rc != MBX_SUCCESS) {
19497 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19498 "2008 Error %d posting all rpi "
19506 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
19507 LPFC_RPI_RSRC_RDY);
19512 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
19513 * @phba: pointer to lpfc hba data structure.
19514 * @rpi_page: pointer to the rpi memory region.
19516 * This routine is invoked to post a single rpi header to the
19517 * HBA consistent with the SLI-4 interface spec. This memory region
19518 * maps up to 64 rpi context regions.
19522 * -ENOMEM - No available memory
19523 * -EIO - The mailbox failed to complete successfully.
19526 lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
19528 LPFC_MBOXQ_t *mboxq;
19529 struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
19531 uint32_t shdr_status, shdr_add_status;
19532 union lpfc_sli4_cfg_shdr *shdr;
19534 /* SLI4 ports that support extents do not require RPI headers. */
19535 if (!phba->sli4_hba.rpi_hdrs_in_use)
19537 if (phba->sli4_hba.extents_in_use)
19540 /* The port is notified of the header region via a mailbox command. */
19541 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19543 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19544 "2001 Unable to allocate memory for issuing "
19545 "SLI_CONFIG_SPECIAL mailbox command\n");
19549 /* Post all rpi memory regions to the port. */
19550 hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
19551 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
19552 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
19553 sizeof(struct lpfc_mbx_post_hdr_tmpl) -
19554 sizeof(struct lpfc_sli4_cfg_mhdr),
19555 LPFC_SLI4_MBX_EMBED);
19558 /* Post the physical rpi to the port for this rpi header. */
19559 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
19560 rpi_page->start_rpi);
19561 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
19562 hdr_tmpl, rpi_page->page_count);
19564 hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
19565 hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
19566 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
19567 shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
19568 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
19569 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
19570 mempool_free(mboxq, phba->mbox_mem_pool);
19571 if (shdr_status || shdr_add_status || rc) {
19572 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19573 "2514 POST_RPI_HDR mailbox failed with "
19574 "status x%x add_status x%x, mbx status x%x\n",
19575 shdr_status, shdr_add_status, rc);
19579 * The next_rpi stores the next logical module-64 rpi value used
19580 * to post physical rpis in subsequent rpi postings.
19582 spin_lock_irq(&phba->hbalock);
19583 phba->sli4_hba.next_rpi = rpi_page->next_rpi;
19584 spin_unlock_irq(&phba->hbalock);
19590 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
19591 * @phba: pointer to lpfc hba data structure.
19593 * This routine is invoked to post rpi header templates to the
19594 * HBA consistent with the SLI-4 interface spec. This routine
19595 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
19596 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
19599 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
19600 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
19603 lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
19606 uint16_t max_rpi, rpi_limit;
19607 uint16_t rpi_remaining, lrpi = 0;
19608 struct lpfc_rpi_hdr *rpi_hdr;
19609 unsigned long iflag;
19612 * Fetch the next logical rpi. Because this index is logical,
19613 * the driver starts at 0 each time.
19615 spin_lock_irqsave(&phba->hbalock, iflag);
19616 max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
19617 rpi_limit = phba->sli4_hba.next_rpi;
19619 rpi = find_first_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit);
19620 if (rpi >= rpi_limit)
19621 rpi = LPFC_RPI_ALLOC_ERROR;
19623 set_bit(rpi, phba->sli4_hba.rpi_bmask);
19624 phba->sli4_hba.max_cfg_param.rpi_used++;
19625 phba->sli4_hba.rpi_count++;
19627 lpfc_printf_log(phba, KERN_INFO,
19628 LOG_NODE | LOG_DISCOVERY,
19629 "0001 Allocated rpi:x%x max:x%x lim:x%x\n",
19630 (int) rpi, max_rpi, rpi_limit);
19633 * Don't try to allocate more rpi header regions if the device limit
19634 * has been exhausted.
19636 if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
19637 (phba->sli4_hba.rpi_count >= max_rpi)) {
19638 spin_unlock_irqrestore(&phba->hbalock, iflag);
19643 * RPI header postings are not required for SLI4 ports capable of
19646 if (!phba->sli4_hba.rpi_hdrs_in_use) {
19647 spin_unlock_irqrestore(&phba->hbalock, iflag);
19652 * If the driver is running low on rpi resources, allocate another
19653 * page now. Note that the next_rpi value is used because
19654 * it represents how many are actually in use whereas max_rpi notes
19655 * how many are supported max by the device.
19657 rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
19658 spin_unlock_irqrestore(&phba->hbalock, iflag);
19659 if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
19660 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
19662 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19663 "2002 Error Could not grow rpi "
19666 lrpi = rpi_hdr->start_rpi;
19667 rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
19668 lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
19676 * __lpfc_sli4_free_rpi - Release an rpi for reuse.
19677 * @phba: pointer to lpfc hba data structure.
19678 * @rpi: rpi to free
19680 * This routine is invoked to release an rpi to the pool of
19681 * available rpis maintained by the driver.
19684 __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
19687 * if the rpi value indicates a prior unreg has already
19688 * been done, skip the unreg.
19690 if (rpi == LPFC_RPI_ALLOC_ERROR)
19693 if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
19694 phba->sli4_hba.rpi_count--;
19695 phba->sli4_hba.max_cfg_param.rpi_used--;
19697 lpfc_printf_log(phba, KERN_INFO,
19698 LOG_NODE | LOG_DISCOVERY,
19699 "2016 rpi %x not inuse\n",
19705 * lpfc_sli4_free_rpi - Release an rpi for reuse.
19706 * @phba: pointer to lpfc hba data structure.
19707 * @rpi: rpi to free
19709 * This routine is invoked to release an rpi to the pool of
19710 * available rpis maintained by the driver.
19713 lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
19715 spin_lock_irq(&phba->hbalock);
19716 __lpfc_sli4_free_rpi(phba, rpi);
19717 spin_unlock_irq(&phba->hbalock);
19721 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
19722 * @phba: pointer to lpfc hba data structure.
19724 * This routine is invoked to remove the memory region that
19725 * provided rpi via a bitmask.
19728 lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
19730 kfree(phba->sli4_hba.rpi_bmask);
19731 kfree(phba->sli4_hba.rpi_ids);
19732 bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
19736 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
19737 * @ndlp: pointer to lpfc nodelist data structure.
19738 * @cmpl: completion call-back.
19739 * @arg: data to load as MBox 'caller buffer information'
19741 * This routine is invoked to remove the memory region that
19742 * provided rpi via a bitmask.
19745 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
19746 void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
19748 LPFC_MBOXQ_t *mboxq;
19749 struct lpfc_hba *phba = ndlp->phba;
19752 /* The port is notified of the header region via a mailbox command. */
19753 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19757 /* If cmpl assigned, then this nlp_get pairs with
19758 * lpfc_mbx_cmpl_resume_rpi.
19760 * Else cmpl is NULL, then this nlp_get pairs with
19761 * lpfc_sli_def_mbox_cmpl.
19763 if (!lpfc_nlp_get(ndlp)) {
19764 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19765 "2122 %s: Failed to get nlp ref\n",
19767 mempool_free(mboxq, phba->mbox_mem_pool);
19771 /* Post all rpi memory regions to the port. */
19772 lpfc_resume_rpi(mboxq, ndlp);
19774 mboxq->mbox_cmpl = cmpl;
19775 mboxq->ctx_buf = arg;
19777 mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
19778 mboxq->ctx_ndlp = ndlp;
19779 mboxq->vport = ndlp->vport;
19780 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19781 if (rc == MBX_NOT_FINISHED) {
19782 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19783 "2010 Resume RPI Mailbox failed "
19784 "status %d, mbxStatus x%x\n", rc,
19785 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
19786 lpfc_nlp_put(ndlp);
19787 mempool_free(mboxq, phba->mbox_mem_pool);
19794 * lpfc_sli4_init_vpi - Initialize a vpi with the port
19795 * @vport: Pointer to the vport for which the vpi is being initialized
19797 * This routine is invoked to activate a vpi with the port.
19801 * -Evalue otherwise
19804 lpfc_sli4_init_vpi(struct lpfc_vport *vport)
19806 LPFC_MBOXQ_t *mboxq;
19808 int retval = MBX_SUCCESS;
19810 struct lpfc_hba *phba = vport->phba;
19811 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19814 lpfc_init_vpi(phba, mboxq, vport->vpi);
19815 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
19816 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
19817 if (rc != MBX_SUCCESS) {
19818 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
19819 "2022 INIT VPI Mailbox failed "
19820 "status %d, mbxStatus x%x\n", rc,
19821 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
19824 if (rc != MBX_TIMEOUT)
19825 mempool_free(mboxq, vport->phba->mbox_mem_pool);
19831 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
19832 * @phba: pointer to lpfc hba data structure.
19833 * @mboxq: Pointer to mailbox object.
19835 * This routine is invoked to manually add a single FCF record. The caller
19836 * must pass a completely initialized FCF_Record. This routine takes
19837 * care of the nonembedded mailbox operations.
19840 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
19843 union lpfc_sli4_cfg_shdr *shdr;
19844 uint32_t shdr_status, shdr_add_status;
19846 virt_addr = mboxq->sge_array->addr[0];
19847 /* The IOCTL status is embedded in the mailbox subheader. */
19848 shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
19849 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
19850 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
19852 if ((shdr_status || shdr_add_status) &&
19853 (shdr_status != STATUS_FCF_IN_USE))
19854 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19855 "2558 ADD_FCF_RECORD mailbox failed with "
19856 "status x%x add_status x%x\n",
19857 shdr_status, shdr_add_status);
19859 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19863 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
19864 * @phba: pointer to lpfc hba data structure.
19865 * @fcf_record: pointer to the initialized fcf record to add.
19867 * This routine is invoked to manually add a single FCF record. The caller
19868 * must pass a completely initialized FCF_Record. This routine takes
19869 * care of the nonembedded mailbox operations.
19872 lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
19875 LPFC_MBOXQ_t *mboxq;
19878 struct lpfc_mbx_sge sge;
19879 uint32_t alloc_len, req_len;
19882 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
19884 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19885 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
19889 req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
19892 /* Allocate DMA memory and set up the non-embedded mailbox command */
19893 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
19894 LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
19895 req_len, LPFC_SLI4_MBX_NEMBED);
19896 if (alloc_len < req_len) {
19897 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19898 "2523 Allocated DMA memory size (x%x) is "
19899 "less than the requested DMA memory "
19900 "size (x%x)\n", alloc_len, req_len);
19901 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19906 * Get the first SGE entry from the non-embedded DMA memory. This
19907 * routine only uses a single SGE.
19909 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
19910 virt_addr = mboxq->sge_array->addr[0];
19912 * Configure the FCF record for FCFI 0. This is the driver's
19913 * hardcoded default and gets used in nonFIP mode.
19915 fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
19916 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
19917 lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
19920 * Copy the fcf_index and the FCF Record Data. The data starts after
19921 * the FCoE header plus word10. The data copy needs to be endian
19924 bytep += sizeof(uint32_t);
19925 lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
19926 mboxq->vport = phba->pport;
19927 mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
19928 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
19929 if (rc == MBX_NOT_FINISHED) {
19930 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
19931 "2515 ADD_FCF_RECORD mailbox failed with "
19932 "status 0x%x\n", rc);
19933 lpfc_sli4_mbox_cmd_free(phba, mboxq);
19942 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
19943 * @phba: pointer to lpfc hba data structure.
19944 * @fcf_record: pointer to the fcf record to write the default data.
19945 * @fcf_index: FCF table entry index.
19947 * This routine is invoked to build the driver's default FCF record. The
19948 * values used are hardcoded. This routine handles memory initialization.
19952 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
19953 struct fcf_record *fcf_record,
19954 uint16_t fcf_index)
19956 memset(fcf_record, 0, sizeof(struct fcf_record));
19957 fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
19958 fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
19959 fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
19960 bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
19961 bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
19962 bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
19963 bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
19964 bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
19965 bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
19966 bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
19967 bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
19968 bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
19969 bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
19970 bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
19971 bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
19972 bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
19973 LPFC_FCF_FPMA | LPFC_FCF_SPMA);
19974 /* Set the VLAN bit map */
19975 if (phba->valid_vlan) {
19976 fcf_record->vlan_bitmap[phba->vlan_id / 8]
19977 = 1 << (phba->vlan_id % 8);
19982 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
19983 * @phba: pointer to lpfc hba data structure.
19984 * @fcf_index: FCF table entry offset.
19986 * This routine is invoked to scan the entire FCF table by reading FCF
19987 * record and processing it one at a time starting from the @fcf_index
19988 * for initial FCF discovery or fast FCF failover rediscovery.
19990 * Return 0 if the mailbox command is submitted successfully, none 0
19994 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
19997 LPFC_MBOXQ_t *mboxq;
19999 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
20000 phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
20001 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20003 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20004 "2000 Failed to allocate mbox for "
20007 goto fail_fcf_scan;
20009 /* Construct the read FCF record mailbox command */
20010 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
20013 goto fail_fcf_scan;
20015 /* Issue the mailbox command asynchronously */
20016 mboxq->vport = phba->pport;
20017 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
20019 spin_lock_irq(&phba->hbalock);
20020 phba->hba_flag |= FCF_TS_INPROG;
20021 spin_unlock_irq(&phba->hbalock);
20023 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
20024 if (rc == MBX_NOT_FINISHED)
20027 /* Reset eligible FCF count for new scan */
20028 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
20029 phba->fcf.eligible_fcf_cnt = 0;
20035 lpfc_sli4_mbox_cmd_free(phba, mboxq);
20036 /* FCF scan failed, clear FCF_TS_INPROG flag */
20037 spin_lock_irq(&phba->hbalock);
20038 phba->hba_flag &= ~FCF_TS_INPROG;
20039 spin_unlock_irq(&phba->hbalock);
20045 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
20046 * @phba: pointer to lpfc hba data structure.
20047 * @fcf_index: FCF table entry offset.
20049 * This routine is invoked to read an FCF record indicated by @fcf_index
20050 * and to use it for FLOGI roundrobin FCF failover.
20052 * Return 0 if the mailbox command is submitted successfully, none 0
20056 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
20059 LPFC_MBOXQ_t *mboxq;
20061 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20063 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
20064 "2763 Failed to allocate mbox for "
20067 goto fail_fcf_read;
20069 /* Construct the read FCF record mailbox command */
20070 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
20073 goto fail_fcf_read;
20075 /* Issue the mailbox command asynchronously */
20076 mboxq->vport = phba->pport;
20077 mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
20078 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
20079 if (rc == MBX_NOT_FINISHED)
20085 if (error && mboxq)
20086 lpfc_sli4_mbox_cmd_free(phba, mboxq);
20091 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
20092 * @phba: pointer to lpfc hba data structure.
20093 * @fcf_index: FCF table entry offset.
20095 * This routine is invoked to read an FCF record indicated by @fcf_index to
20096 * determine whether it's eligible for FLOGI roundrobin failover list.
20098 * Return 0 if the mailbox command is submitted successfully, none 0
20102 lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
20105 LPFC_MBOXQ_t *mboxq;
20107 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20109 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
20110 "2758 Failed to allocate mbox for "
20113 goto fail_fcf_read;
20115 /* Construct the read FCF record mailbox command */
20116 rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
20119 goto fail_fcf_read;
20121 /* Issue the mailbox command asynchronously */
20122 mboxq->vport = phba->pport;
20123 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
20124 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
20125 if (rc == MBX_NOT_FINISHED)
20131 if (error && mboxq)
20132 lpfc_sli4_mbox_cmd_free(phba, mboxq);
20137 * lpfc_check_next_fcf_pri_level
20138 * @phba: pointer to the lpfc_hba struct for this port.
20139 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
20140 * routine when the rr_bmask is empty. The FCF indecies are put into the
20141 * rr_bmask based on their priority level. Starting from the highest priority
20142 * to the lowest. The most likely FCF candidate will be in the highest
20143 * priority group. When this routine is called it searches the fcf_pri list for
20144 * next lowest priority group and repopulates the rr_bmask with only those
20147 * 1=success 0=failure
20150 lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
20152 uint16_t next_fcf_pri;
20153 uint16_t last_index;
20154 struct lpfc_fcf_pri *fcf_pri;
20158 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
20159 LPFC_SLI4_FCF_TBL_INDX_MAX);
20160 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20161 "3060 Last IDX %d\n", last_index);
20163 /* Verify the priority list has 2 or more entries */
20164 spin_lock_irq(&phba->hbalock);
20165 if (list_empty(&phba->fcf.fcf_pri_list) ||
20166 list_is_singular(&phba->fcf.fcf_pri_list)) {
20167 spin_unlock_irq(&phba->hbalock);
20168 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20169 "3061 Last IDX %d\n", last_index);
20170 return 0; /* Empty rr list */
20172 spin_unlock_irq(&phba->hbalock);
20176 * Clear the rr_bmask and set all of the bits that are at this
20179 memset(phba->fcf.fcf_rr_bmask, 0,
20180 sizeof(*phba->fcf.fcf_rr_bmask));
20181 spin_lock_irq(&phba->hbalock);
20182 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
20183 if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
20186 * the 1st priority that has not FLOGI failed
20187 * will be the highest.
20190 next_fcf_pri = fcf_pri->fcf_rec.priority;
20191 spin_unlock_irq(&phba->hbalock);
20192 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
20193 rc = lpfc_sli4_fcf_rr_index_set(phba,
20194 fcf_pri->fcf_rec.fcf_index);
20198 spin_lock_irq(&phba->hbalock);
20201 * if next_fcf_pri was not set above and the list is not empty then
20202 * we have failed flogis on all of them. So reset flogi failed
20203 * and start at the beginning.
20205 if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
20206 list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
20207 fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
20209 * the 1st priority that has not FLOGI failed
20210 * will be the highest.
20213 next_fcf_pri = fcf_pri->fcf_rec.priority;
20214 spin_unlock_irq(&phba->hbalock);
20215 if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
20216 rc = lpfc_sli4_fcf_rr_index_set(phba,
20217 fcf_pri->fcf_rec.fcf_index);
20221 spin_lock_irq(&phba->hbalock);
20225 spin_unlock_irq(&phba->hbalock);
20230 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
20231 * @phba: pointer to lpfc hba data structure.
20233 * This routine is to get the next eligible FCF record index in a round
20234 * robin fashion. If the next eligible FCF record index equals to the
20235 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
20236 * shall be returned, otherwise, the next eligible FCF record's index
20237 * shall be returned.
20240 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
20242 uint16_t next_fcf_index;
20245 /* Search start from next bit of currently registered FCF index */
20246 next_fcf_index = phba->fcf.current_rec.fcf_indx;
20249 /* Determine the next fcf index to check */
20250 next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
20251 next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
20252 LPFC_SLI4_FCF_TBL_INDX_MAX,
20255 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
20256 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
20258 * If we have wrapped then we need to clear the bits that
20259 * have been tested so that we can detect when we should
20260 * change the priority level.
20262 next_fcf_index = find_first_bit(phba->fcf.fcf_rr_bmask,
20263 LPFC_SLI4_FCF_TBL_INDX_MAX);
20267 /* Check roundrobin failover list empty condition */
20268 if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
20269 next_fcf_index == phba->fcf.current_rec.fcf_indx) {
20271 * If next fcf index is not found check if there are lower
20272 * Priority level fcf's in the fcf_priority list.
20273 * Set up the rr_bmask with all of the avaiable fcf bits
20274 * at that level and continue the selection process.
20276 if (lpfc_check_next_fcf_pri_level(phba))
20277 goto initial_priority;
20278 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
20279 "2844 No roundrobin failover FCF available\n");
20281 return LPFC_FCOE_FCF_NEXT_NONE;
20284 if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
20285 phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
20286 LPFC_FCF_FLOGI_FAILED) {
20287 if (list_is_singular(&phba->fcf.fcf_pri_list))
20288 return LPFC_FCOE_FCF_NEXT_NONE;
20290 goto next_priority;
20293 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20294 "2845 Get next roundrobin failover FCF (x%x)\n",
20297 return next_fcf_index;
20301 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
20302 * @phba: pointer to lpfc hba data structure.
20303 * @fcf_index: index into the FCF table to 'set'
20305 * This routine sets the FCF record index in to the eligible bmask for
20306 * roundrobin failover search. It checks to make sure that the index
20307 * does not go beyond the range of the driver allocated bmask dimension
20308 * before setting the bit.
20310 * Returns 0 if the index bit successfully set, otherwise, it returns
20314 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
20316 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
20317 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20318 "2610 FCF (x%x) reached driver's book "
20319 "keeping dimension:x%x\n",
20320 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
20323 /* Set the eligible FCF record index bmask */
20324 set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
20326 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20327 "2790 Set FCF (x%x) to roundrobin FCF failover "
20328 "bmask\n", fcf_index);
20334 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
20335 * @phba: pointer to lpfc hba data structure.
20336 * @fcf_index: index into the FCF table to 'clear'
20338 * This routine clears the FCF record index from the eligible bmask for
20339 * roundrobin failover search. It checks to make sure that the index
20340 * does not go beyond the range of the driver allocated bmask dimension
20341 * before clearing the bit.
20344 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
20346 struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
20347 if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
20348 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20349 "2762 FCF (x%x) reached driver's book "
20350 "keeping dimension:x%x\n",
20351 fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
20354 /* Clear the eligible FCF record index bmask */
20355 spin_lock_irq(&phba->hbalock);
20356 list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
20358 if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
20359 list_del_init(&fcf_pri->list);
20363 spin_unlock_irq(&phba->hbalock);
20364 clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
20366 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20367 "2791 Clear FCF (x%x) from roundrobin failover "
20368 "bmask\n", fcf_index);
20372 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
20373 * @phba: pointer to lpfc hba data structure.
20374 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
20376 * This routine is the completion routine for the rediscover FCF table mailbox
20377 * command. If the mailbox command returned failure, it will try to stop the
20378 * FCF rediscover wait timer.
20381 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
20383 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
20384 uint32_t shdr_status, shdr_add_status;
20386 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
20388 shdr_status = bf_get(lpfc_mbox_hdr_status,
20389 &redisc_fcf->header.cfg_shdr.response);
20390 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
20391 &redisc_fcf->header.cfg_shdr.response);
20392 if (shdr_status || shdr_add_status) {
20393 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
20394 "2746 Requesting for FCF rediscovery failed "
20395 "status x%x add_status x%x\n",
20396 shdr_status, shdr_add_status);
20397 if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
20398 spin_lock_irq(&phba->hbalock);
20399 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
20400 spin_unlock_irq(&phba->hbalock);
20402 * CVL event triggered FCF rediscover request failed,
20403 * last resort to re-try current registered FCF entry.
20405 lpfc_retry_pport_discovery(phba);
20407 spin_lock_irq(&phba->hbalock);
20408 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
20409 spin_unlock_irq(&phba->hbalock);
20411 * DEAD FCF event triggered FCF rediscover request
20412 * failed, last resort to fail over as a link down
20413 * to FCF registration.
20415 lpfc_sli4_fcf_dead_failthrough(phba);
20418 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
20419 "2775 Start FCF rediscover quiescent timer\n");
20421 * Start FCF rediscovery wait timer for pending FCF
20422 * before rescan FCF record table.
20424 lpfc_fcf_redisc_wait_start_timer(phba);
20427 mempool_free(mbox, phba->mbox_mem_pool);
20431 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
20432 * @phba: pointer to lpfc hba data structure.
20434 * This routine is invoked to request for rediscovery of the entire FCF table
20438 lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
20440 LPFC_MBOXQ_t *mbox;
20441 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
20444 /* Cancel retry delay timers to all vports before FCF rediscover */
20445 lpfc_cancel_all_vport_retry_delay_timer(phba);
20447 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20449 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20450 "2745 Failed to allocate mbox for "
20451 "requesting FCF rediscover.\n");
20455 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
20456 sizeof(struct lpfc_sli4_cfg_mhdr));
20457 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
20458 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
20459 length, LPFC_SLI4_MBX_EMBED);
20461 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
20462 /* Set count to 0 for invalidating the entire FCF database */
20463 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
20465 /* Issue the mailbox command asynchronously */
20466 mbox->vport = phba->pport;
20467 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
20468 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
20470 if (rc == MBX_NOT_FINISHED) {
20471 mempool_free(mbox, phba->mbox_mem_pool);
20478 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
20479 * @phba: pointer to lpfc hba data structure.
20481 * This function is the failover routine as a last resort to the FCF DEAD
20482 * event when driver failed to perform fast FCF failover.
20485 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
20487 uint32_t link_state;
20490 * Last resort as FCF DEAD event failover will treat this as
20491 * a link down, but save the link state because we don't want
20492 * it to be changed to Link Down unless it is already down.
20494 link_state = phba->link_state;
20495 lpfc_linkdown(phba);
20496 phba->link_state = link_state;
20498 /* Unregister FCF if no devices connected to it */
20499 lpfc_unregister_unused_fcf(phba);
20503 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
20504 * @phba: pointer to lpfc hba data structure.
20505 * @rgn23_data: pointer to configure region 23 data.
20507 * This function gets SLI3 port configure region 23 data through memory dump
20508 * mailbox command. When it successfully retrieves data, the size of the data
20509 * will be returned, otherwise, 0 will be returned.
20512 lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
20514 LPFC_MBOXQ_t *pmb = NULL;
20516 uint32_t offset = 0;
20522 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20524 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20525 "2600 failed to allocate mailbox memory\n");
20531 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
20532 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
20534 if (rc != MBX_SUCCESS) {
20535 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
20536 "2601 failed to read config "
20537 "region 23, rc 0x%x Status 0x%x\n",
20538 rc, mb->mbxStatus);
20539 mb->un.varDmp.word_cnt = 0;
20542 * dump mem may return a zero when finished or we got a
20543 * mailbox error, either way we are done.
20545 if (mb->un.varDmp.word_cnt == 0)
20548 if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
20549 mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
20551 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
20552 rgn23_data + offset,
20553 mb->un.varDmp.word_cnt);
20554 offset += mb->un.varDmp.word_cnt;
20555 } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
20557 mempool_free(pmb, phba->mbox_mem_pool);
20562 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
20563 * @phba: pointer to lpfc hba data structure.
20564 * @rgn23_data: pointer to configure region 23 data.
20566 * This function gets SLI4 port configure region 23 data through memory dump
20567 * mailbox command. When it successfully retrieves data, the size of the data
20568 * will be returned, otherwise, 0 will be returned.
20571 lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
20573 LPFC_MBOXQ_t *mboxq = NULL;
20574 struct lpfc_dmabuf *mp = NULL;
20575 struct lpfc_mqe *mqe;
20576 uint32_t data_length = 0;
20582 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20584 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20585 "3105 failed to allocate mailbox memory\n");
20589 if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
20591 mqe = &mboxq->u.mqe;
20592 mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
20593 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
20596 data_length = mqe->un.mb_words[5];
20597 if (data_length == 0)
20599 if (data_length > DMP_RGN23_SIZE) {
20603 lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
20605 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
20606 return data_length;
20610 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
20611 * @phba: pointer to lpfc hba data structure.
20613 * This function read region 23 and parse TLV for port status to
20614 * decide if the user disaled the port. If the TLV indicates the
20615 * port is disabled, the hba_flag is set accordingly.
20618 lpfc_sli_read_link_ste(struct lpfc_hba *phba)
20620 uint8_t *rgn23_data = NULL;
20621 uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
20622 uint32_t offset = 0;
20624 /* Get adapter Region 23 data */
20625 rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
20629 if (phba->sli_rev < LPFC_SLI_REV4)
20630 data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
20632 if_type = bf_get(lpfc_sli_intf_if_type,
20633 &phba->sli4_hba.sli_intf);
20634 if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
20636 data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
20642 /* Check the region signature first */
20643 if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
20644 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20645 "2619 Config region 23 has bad signature\n");
20650 /* Check the data structure version */
20651 if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
20652 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20653 "2620 Config region 23 has bad version\n");
20658 /* Parse TLV entries in the region */
20659 while (offset < data_size) {
20660 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
20663 * If the TLV is not driver specific TLV or driver id is
20664 * not linux driver id, skip the record.
20666 if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
20667 (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
20668 (rgn23_data[offset + 3] != 0)) {
20669 offset += rgn23_data[offset + 1] * 4 + 4;
20673 /* Driver found a driver specific TLV in the config region */
20674 sub_tlv_len = rgn23_data[offset + 1] * 4;
20679 * Search for configured port state sub-TLV.
20681 while ((offset < data_size) &&
20682 (tlv_offset < sub_tlv_len)) {
20683 if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
20688 if (rgn23_data[offset] != PORT_STE_TYPE) {
20689 offset += rgn23_data[offset + 1] * 4 + 4;
20690 tlv_offset += rgn23_data[offset + 1] * 4 + 4;
20694 /* This HBA contains PORT_STE configured */
20695 if (!rgn23_data[offset + 2])
20696 phba->hba_flag |= LINK_DISABLED;
20708 * lpfc_log_fw_write_cmpl - logs firmware write completion status
20709 * @phba: pointer to lpfc hba data structure
20710 * @shdr_status: wr_object rsp's status field
20711 * @shdr_add_status: wr_object rsp's add_status field
20712 * @shdr_add_status_2: wr_object rsp's add_status_2 field
20713 * @shdr_change_status: wr_object rsp's change_status field
20714 * @shdr_csf: wr_object rsp's csf bit
20716 * This routine is intended to be called after a firmware write completes.
20717 * It will log next action items to be performed by the user to instantiate
20718 * the newly downloaded firmware or reason for incompatibility.
20721 lpfc_log_fw_write_cmpl(struct lpfc_hba *phba, u32 shdr_status,
20722 u32 shdr_add_status, u32 shdr_add_status_2,
20723 u32 shdr_change_status, u32 shdr_csf)
20725 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20726 "4198 %s: flash_id x%02x, asic_rev x%02x, "
20727 "status x%02x, add_status x%02x, add_status_2 x%02x, "
20728 "change_status x%02x, csf %01x\n", __func__,
20729 phba->sli4_hba.flash_id, phba->sli4_hba.asic_rev,
20730 shdr_status, shdr_add_status, shdr_add_status_2,
20731 shdr_change_status, shdr_csf);
20733 if (shdr_add_status == LPFC_ADD_STATUS_INCOMPAT_OBJ) {
20734 switch (shdr_add_status_2) {
20735 case LPFC_ADD_STATUS_2_INCOMPAT_FLASH:
20736 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
20737 "4199 Firmware write failed: "
20738 "image incompatible with flash x%02x\n",
20739 phba->sli4_hba.flash_id);
20741 case LPFC_ADD_STATUS_2_INCORRECT_ASIC:
20742 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
20743 "4200 Firmware write failed: "
20744 "image incompatible with ASIC "
20745 "architecture x%02x\n",
20746 phba->sli4_hba.asic_rev);
20749 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
20750 "4210 Firmware write failed: "
20751 "add_status_2 x%02x\n",
20752 shdr_add_status_2);
20755 } else if (!shdr_status && !shdr_add_status) {
20756 if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET ||
20757 shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) {
20759 shdr_change_status =
20760 LPFC_CHANGE_STATUS_PCI_RESET;
20763 switch (shdr_change_status) {
20764 case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
20765 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20766 "3198 Firmware write complete: System "
20767 "reboot required to instantiate\n");
20769 case (LPFC_CHANGE_STATUS_FW_RESET):
20770 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20771 "3199 Firmware write complete: "
20772 "Firmware reset required to "
20775 case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
20776 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20777 "3200 Firmware write complete: Port "
20778 "Migration or PCI Reset required to "
20781 case (LPFC_CHANGE_STATUS_PCI_RESET):
20782 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
20783 "3201 Firmware write complete: PCI "
20784 "Reset required to instantiate\n");
20793 * lpfc_wr_object - write an object to the firmware
20794 * @phba: HBA structure that indicates port to create a queue on.
20795 * @dmabuf_list: list of dmabufs to write to the port.
20796 * @size: the total byte value of the objects to write to the port.
20797 * @offset: the current offset to be used to start the transfer.
20799 * This routine will create a wr_object mailbox command to send to the port.
20800 * the mailbox command will be constructed using the dma buffers described in
20801 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
20802 * BDEs that the imbedded mailbox can support. The @offset variable will be
20803 * used to indicate the starting offset of the transfer and will also return
20804 * the offset after the write object mailbox has completed. @size is used to
20805 * determine the end of the object and whether the eof bit should be set.
20807 * Return 0 is successful and offset will contain the new offset to use
20808 * for the next write.
20809 * Return negative value for error cases.
20812 lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
20813 uint32_t size, uint32_t *offset)
20815 struct lpfc_mbx_wr_object *wr_object;
20816 LPFC_MBOXQ_t *mbox;
20818 int mbox_status = 0;
20819 uint32_t shdr_status, shdr_add_status, shdr_add_status_2;
20820 uint32_t shdr_change_status = 0, shdr_csf = 0;
20822 struct lpfc_dmabuf *dmabuf;
20823 uint32_t written = 0;
20824 bool check_change_status = false;
20826 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
20830 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
20831 LPFC_MBOX_OPCODE_WRITE_OBJECT,
20832 sizeof(struct lpfc_mbx_wr_object) -
20833 sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
20835 wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
20836 wr_object->u.request.write_offset = *offset;
20837 sprintf((uint8_t *)wr_object->u.request.object_name, "/");
20838 wr_object->u.request.object_name[0] =
20839 cpu_to_le32(wr_object->u.request.object_name[0]);
20840 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
20841 list_for_each_entry(dmabuf, dmabuf_list, list) {
20842 if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
20844 wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
20845 wr_object->u.request.bde[i].addrHigh =
20846 putPaddrHigh(dmabuf->phys);
20847 if (written + SLI4_PAGE_SIZE >= size) {
20848 wr_object->u.request.bde[i].tus.f.bdeSize =
20850 written += (size - written);
20851 bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
20852 bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
20853 check_change_status = true;
20855 wr_object->u.request.bde[i].tus.f.bdeSize =
20857 written += SLI4_PAGE_SIZE;
20861 wr_object->u.request.bde_count = i;
20862 bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
20863 if (!phba->sli4_hba.intr_enable)
20864 mbox_status = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
20866 mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
20867 mbox_status = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
20870 /* The mbox status needs to be maintained to detect MBOX_TIMEOUT. */
20873 /* The IOCTL status is embedded in the mailbox subheader. */
20874 shdr_status = bf_get(lpfc_mbox_hdr_status,
20875 &wr_object->header.cfg_shdr.response);
20876 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
20877 &wr_object->header.cfg_shdr.response);
20878 shdr_add_status_2 = bf_get(lpfc_mbox_hdr_add_status_2,
20879 &wr_object->header.cfg_shdr.response);
20880 if (check_change_status) {
20881 shdr_change_status = bf_get(lpfc_wr_object_change_status,
20882 &wr_object->u.response);
20883 shdr_csf = bf_get(lpfc_wr_object_csf,
20884 &wr_object->u.response);
20887 if (shdr_status || shdr_add_status || shdr_add_status_2 || rc) {
20888 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
20889 "3025 Write Object mailbox failed with "
20890 "status x%x add_status x%x, add_status_2 x%x, "
20891 "mbx status x%x\n",
20892 shdr_status, shdr_add_status, shdr_add_status_2,
20895 *offset = shdr_add_status;
20897 *offset += wr_object->u.response.actual_write_length;
20900 if (rc || check_change_status)
20901 lpfc_log_fw_write_cmpl(phba, shdr_status, shdr_add_status,
20902 shdr_add_status_2, shdr_change_status,
20905 if (!phba->sli4_hba.intr_enable)
20906 mempool_free(mbox, phba->mbox_mem_pool);
20907 else if (mbox_status != MBX_TIMEOUT)
20908 mempool_free(mbox, phba->mbox_mem_pool);
20914 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
20915 * @vport: pointer to vport data structure.
20917 * This function iterate through the mailboxq and clean up all REG_LOGIN
20918 * and REG_VPI mailbox commands associated with the vport. This function
20919 * is called when driver want to restart discovery of the vport due to
20920 * a Clear Virtual Link event.
20923 lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
20925 struct lpfc_hba *phba = vport->phba;
20926 LPFC_MBOXQ_t *mb, *nextmb;
20927 struct lpfc_nodelist *ndlp;
20928 struct lpfc_nodelist *act_mbx_ndlp = NULL;
20929 LIST_HEAD(mbox_cmd_list);
20930 uint8_t restart_loop;
20932 /* Clean up internally queued mailbox commands with the vport */
20933 spin_lock_irq(&phba->hbalock);
20934 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
20935 if (mb->vport != vport)
20938 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
20939 (mb->u.mb.mbxCommand != MBX_REG_VPI))
20942 list_move_tail(&mb->list, &mbox_cmd_list);
20944 /* Clean up active mailbox command with the vport */
20945 mb = phba->sli.mbox_active;
20946 if (mb && (mb->vport == vport)) {
20947 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
20948 (mb->u.mb.mbxCommand == MBX_REG_VPI))
20949 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
20950 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
20951 act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
20953 /* This reference is local to this routine. The
20954 * reference is removed at routine exit.
20956 act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
20958 /* Unregister the RPI when mailbox complete */
20959 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
20962 /* Cleanup any mailbox completions which are not yet processed */
20965 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
20967 * If this mailox is already processed or it is
20968 * for another vport ignore it.
20970 if ((mb->vport != vport) ||
20971 (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
20974 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
20975 (mb->u.mb.mbxCommand != MBX_REG_VPI))
20978 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
20979 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
20980 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
20981 /* Unregister the RPI when mailbox complete */
20982 mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
20984 spin_unlock_irq(&phba->hbalock);
20985 spin_lock(&ndlp->lock);
20986 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
20987 spin_unlock(&ndlp->lock);
20988 spin_lock_irq(&phba->hbalock);
20992 } while (restart_loop);
20994 spin_unlock_irq(&phba->hbalock);
20996 /* Release the cleaned-up mailbox commands */
20997 while (!list_empty(&mbox_cmd_list)) {
20998 list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
20999 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
21000 ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
21001 mb->ctx_ndlp = NULL;
21003 spin_lock(&ndlp->lock);
21004 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
21005 spin_unlock(&ndlp->lock);
21006 lpfc_nlp_put(ndlp);
21009 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_UNLOCKED);
21012 /* Release the ndlp with the cleaned-up active mailbox command */
21013 if (act_mbx_ndlp) {
21014 spin_lock(&act_mbx_ndlp->lock);
21015 act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
21016 spin_unlock(&act_mbx_ndlp->lock);
21017 lpfc_nlp_put(act_mbx_ndlp);
21022 * lpfc_drain_txq - Drain the txq
21023 * @phba: Pointer to HBA context object.
21025 * This function attempt to submit IOCBs on the txq
21026 * to the adapter. For SLI4 adapters, the txq contains
21027 * ELS IOCBs that have been deferred because the there
21028 * are no SGLs. This congestion can occur with large
21029 * vport counts during node discovery.
21033 lpfc_drain_txq(struct lpfc_hba *phba)
21035 LIST_HEAD(completions);
21036 struct lpfc_sli_ring *pring;
21037 struct lpfc_iocbq *piocbq = NULL;
21038 unsigned long iflags = 0;
21039 char *fail_msg = NULL;
21040 uint32_t txq_cnt = 0;
21041 struct lpfc_queue *wq;
21044 if (phba->link_flag & LS_MDS_LOOPBACK) {
21045 /* MDS WQE are posted only to first WQ*/
21046 wq = phba->sli4_hba.hdwq[0].io_wq;
21051 wq = phba->sli4_hba.els_wq;
21054 pring = lpfc_phba_elsring(phba);
21057 if (unlikely(!pring) || list_empty(&pring->txq))
21060 spin_lock_irqsave(&pring->ring_lock, iflags);
21061 list_for_each_entry(piocbq, &pring->txq, list) {
21065 if (txq_cnt > pring->txq_max)
21066 pring->txq_max = txq_cnt;
21068 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21070 while (!list_empty(&pring->txq)) {
21071 spin_lock_irqsave(&pring->ring_lock, iflags);
21073 piocbq = lpfc_sli_ringtx_get(phba, pring);
21075 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21076 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
21077 "2823 txq empty and txq_cnt is %d\n ",
21083 ret = __lpfc_sli_issue_iocb(phba, pring->ringno, piocbq, 0);
21085 if (ret && ret != IOCB_BUSY) {
21086 fail_msg = " - Cannot send IO ";
21087 piocbq->cmd_flag &= ~LPFC_DRIVER_ABORTED;
21090 piocbq->cmd_flag |= LPFC_DRIVER_ABORTED;
21091 /* Failed means we can't issue and need to cancel */
21092 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
21093 "2822 IOCB failed %s iotag 0x%x "
21094 "xri 0x%x %d flg x%x\n",
21095 fail_msg, piocbq->iotag,
21096 piocbq->sli4_xritag, ret,
21098 list_add_tail(&piocbq->list, &completions);
21101 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21102 if (txq_cnt == 0 || ret == IOCB_BUSY)
21105 /* Cancel all the IOCBs that cannot be issued */
21106 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
21107 IOERR_SLI_ABORTED);
21113 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
21114 * @phba: Pointer to HBA context object.
21115 * @pwqeq: Pointer to command WQE.
21116 * @sglq: Pointer to the scatter gather queue object.
21118 * This routine converts the bpl or bde that is in the WQE
21119 * to a sgl list for the sli4 hardware. The physical address
21120 * of the bpl/bde is converted back to a virtual address.
21121 * If the WQE contains a BPL then the list of BDE's is
21122 * converted to sli4_sge's. If the WQE contains a single
21123 * BDE then it is converted to a single sli_sge.
21124 * The WQE is still in cpu endianness so the contents of
21125 * the bpl can be used without byte swapping.
21127 * Returns valid XRI = Success, NO_XRI = Failure.
21130 lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
21131 struct lpfc_sglq *sglq)
21133 uint16_t xritag = NO_XRI;
21134 struct ulp_bde64 *bpl = NULL;
21135 struct ulp_bde64 bde;
21136 struct sli4_sge *sgl = NULL;
21137 struct lpfc_dmabuf *dmabuf;
21138 union lpfc_wqe128 *wqe;
21141 uint32_t offset = 0; /* accumulated offset in the sg request list */
21142 int inbound = 0; /* number of sg reply entries inbound from firmware */
21145 if (!pwqeq || !sglq)
21148 sgl = (struct sli4_sge *)sglq->sgl;
21150 pwqeq->iocb.ulpIoTag = pwqeq->iotag;
21152 cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
21153 if (cmd == CMD_XMIT_BLS_RSP64_WQE)
21154 return sglq->sli4_xritag;
21155 numBdes = pwqeq->num_bdes;
21157 /* The addrHigh and addrLow fields within the WQE
21158 * have not been byteswapped yet so there is no
21159 * need to swap them back.
21161 if (pwqeq->bpl_dmabuf)
21162 dmabuf = pwqeq->bpl_dmabuf;
21166 bpl = (struct ulp_bde64 *)dmabuf->virt;
21170 for (i = 0; i < numBdes; i++) {
21171 /* Should already be byte swapped. */
21172 sgl->addr_hi = bpl->addrHigh;
21173 sgl->addr_lo = bpl->addrLow;
21175 sgl->word2 = le32_to_cpu(sgl->word2);
21176 if ((i+1) == numBdes)
21177 bf_set(lpfc_sli4_sge_last, sgl, 1);
21179 bf_set(lpfc_sli4_sge_last, sgl, 0);
21180 /* swap the size field back to the cpu so we
21181 * can assign it to the sgl.
21183 bde.tus.w = le32_to_cpu(bpl->tus.w);
21184 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
21185 /* The offsets in the sgl need to be accumulated
21186 * separately for the request and reply lists.
21187 * The request is always first, the reply follows.
21190 case CMD_GEN_REQUEST64_WQE:
21191 /* add up the reply sg entries */
21192 if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
21194 /* first inbound? reset the offset */
21197 bf_set(lpfc_sli4_sge_offset, sgl, offset);
21198 bf_set(lpfc_sli4_sge_type, sgl,
21199 LPFC_SGE_TYPE_DATA);
21200 offset += bde.tus.f.bdeSize;
21202 case CMD_FCP_TRSP64_WQE:
21203 bf_set(lpfc_sli4_sge_offset, sgl, 0);
21204 bf_set(lpfc_sli4_sge_type, sgl,
21205 LPFC_SGE_TYPE_DATA);
21207 case CMD_FCP_TSEND64_WQE:
21208 case CMD_FCP_TRECEIVE64_WQE:
21209 bf_set(lpfc_sli4_sge_type, sgl,
21210 bpl->tus.f.bdeFlags);
21214 offset += bde.tus.f.bdeSize;
21215 bf_set(lpfc_sli4_sge_offset, sgl, offset);
21218 sgl->word2 = cpu_to_le32(sgl->word2);
21222 } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
21223 /* The addrHigh and addrLow fields of the BDE have not
21224 * been byteswapped yet so they need to be swapped
21225 * before putting them in the sgl.
21227 sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
21228 sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
21229 sgl->word2 = le32_to_cpu(sgl->word2);
21230 bf_set(lpfc_sli4_sge_last, sgl, 1);
21231 sgl->word2 = cpu_to_le32(sgl->word2);
21232 sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
21234 return sglq->sli4_xritag;
21238 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
21239 * @phba: Pointer to HBA context object.
21240 * @qp: Pointer to HDW queue.
21241 * @pwqe: Pointer to command WQE.
21244 lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
21245 struct lpfc_iocbq *pwqe)
21247 union lpfc_wqe128 *wqe = &pwqe->wqe;
21248 struct lpfc_async_xchg_ctx *ctxp;
21249 struct lpfc_queue *wq;
21250 struct lpfc_sglq *sglq;
21251 struct lpfc_sli_ring *pring;
21252 unsigned long iflags;
21255 /* NVME_LS and NVME_LS ABTS requests. */
21256 if (pwqe->cmd_flag & LPFC_IO_NVME_LS) {
21257 pring = phba->sli4_hba.nvmels_wq->pring;
21258 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
21260 sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
21262 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21265 pwqe->sli4_lxritag = sglq->sli4_lxritag;
21266 pwqe->sli4_xritag = sglq->sli4_xritag;
21267 if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
21268 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21271 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
21272 pwqe->sli4_xritag);
21273 ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
21275 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21279 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
21280 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21282 lpfc_sli4_poll_eq(qp->hba_eq);
21286 /* NVME_FCREQ and NVME_ABTS requests */
21287 if (pwqe->cmd_flag & (LPFC_IO_NVME | LPFC_IO_FCP | LPFC_IO_CMF)) {
21288 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
21292 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
21294 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
21296 ret = lpfc_sli4_wq_put(wq, wqe);
21298 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21301 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
21302 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21304 lpfc_sli4_poll_eq(qp->hba_eq);
21308 /* NVMET requests */
21309 if (pwqe->cmd_flag & LPFC_IO_NVMET) {
21310 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
21314 ctxp = pwqe->context_un.axchg;
21315 sglq = ctxp->ctxbuf->sglq;
21316 if (pwqe->sli4_xritag == NO_XRI) {
21317 pwqe->sli4_lxritag = sglq->sli4_lxritag;
21318 pwqe->sli4_xritag = sglq->sli4_xritag;
21320 bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
21321 pwqe->sli4_xritag);
21322 bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
21324 lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
21326 ret = lpfc_sli4_wq_put(wq, wqe);
21328 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21331 lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
21332 spin_unlock_irqrestore(&pring->ring_lock, iflags);
21334 lpfc_sli4_poll_eq(qp->hba_eq);
21341 * lpfc_sli4_issue_abort_iotag - SLI-4 WQE init & issue for the Abort
21342 * @phba: Pointer to HBA context object.
21343 * @cmdiocb: Pointer to driver command iocb object.
21344 * @cmpl: completion function.
21346 * Fill the appropriate fields for the abort WQE and call
21347 * internal routine lpfc_sli4_issue_wqe to send the WQE
21348 * This function is called with hbalock held and no ring_lock held.
21350 * RETURNS 0 - SUCCESS
21354 lpfc_sli4_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
21357 struct lpfc_vport *vport = cmdiocb->vport;
21358 struct lpfc_iocbq *abtsiocb = NULL;
21359 union lpfc_wqe128 *abtswqe;
21360 struct lpfc_io_buf *lpfc_cmd;
21361 int retval = IOCB_ERROR;
21362 u16 xritag = cmdiocb->sli4_xritag;
21365 * The scsi command can not be in txq and it is in flight because the
21366 * pCmd is still pointing at the SCSI command we have to abort. There
21367 * is no need to search the txcmplq. Just send an abort to the FW.
21370 abtsiocb = __lpfc_sli_get_iocbq(phba);
21372 return WQE_NORESOURCE;
21374 /* Indicate the IO is being aborted by the driver. */
21375 cmdiocb->cmd_flag |= LPFC_DRIVER_ABORTED;
21377 abtswqe = &abtsiocb->wqe;
21378 memset(abtswqe, 0, sizeof(*abtswqe));
21380 if (!lpfc_is_link_up(phba) || (phba->link_flag & LS_EXTERNAL_LOOPBACK))
21381 bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 1);
21382 bf_set(abort_cmd_criteria, &abtswqe->abort_cmd, T_XRI_TAG);
21383 abtswqe->abort_cmd.rsrvd5 = 0;
21384 abtswqe->abort_cmd.wqe_com.abort_tag = xritag;
21385 bf_set(wqe_reqtag, &abtswqe->abort_cmd.wqe_com, abtsiocb->iotag);
21386 bf_set(wqe_cmnd, &abtswqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
21387 bf_set(wqe_xri_tag, &abtswqe->generic.wqe_com, 0);
21388 bf_set(wqe_qosd, &abtswqe->abort_cmd.wqe_com, 1);
21389 bf_set(wqe_lenloc, &abtswqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
21390 bf_set(wqe_cmd_type, &abtswqe->abort_cmd.wqe_com, OTHER_COMMAND);
21392 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
21393 abtsiocb->hba_wqidx = cmdiocb->hba_wqidx;
21394 abtsiocb->cmd_flag |= LPFC_USE_FCPWQIDX;
21395 if (cmdiocb->cmd_flag & LPFC_IO_FCP)
21396 abtsiocb->cmd_flag |= LPFC_IO_FCP;
21397 if (cmdiocb->cmd_flag & LPFC_IO_NVME)
21398 abtsiocb->cmd_flag |= LPFC_IO_NVME;
21399 if (cmdiocb->cmd_flag & LPFC_IO_FOF)
21400 abtsiocb->cmd_flag |= LPFC_IO_FOF;
21401 abtsiocb->vport = vport;
21402 abtsiocb->cmd_cmpl = cmpl;
21404 lpfc_cmd = container_of(cmdiocb, struct lpfc_io_buf, cur_iocbq);
21405 retval = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, abtsiocb);
21407 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
21408 "0359 Abort xri x%x, original iotag x%x, "
21409 "abort cmd iotag x%x retval x%x\n",
21410 xritag, cmdiocb->iotag, abtsiocb->iotag, retval);
21413 cmdiocb->cmd_flag &= ~LPFC_DRIVER_ABORTED;
21414 __lpfc_sli_release_iocbq(phba, abtsiocb);
21420 #ifdef LPFC_MXP_STAT
21422 * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
21423 * @phba: pointer to lpfc hba data structure.
21424 * @hwqid: belong to which HWQ.
21426 * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
21427 * 15 seconds after a test case is running.
21429 * The user should call lpfc_debugfs_multixripools_write before running a test
21430 * case to clear stat_snapshot_taken. Then the user starts a test case. During
21431 * test case is running, stat_snapshot_taken is incremented by 1 every time when
21432 * this routine is called from heartbeat timer. When stat_snapshot_taken is
21433 * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
21435 void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
21437 struct lpfc_sli4_hdw_queue *qp;
21438 struct lpfc_multixri_pool *multixri_pool;
21439 struct lpfc_pvt_pool *pvt_pool;
21440 struct lpfc_pbl_pool *pbl_pool;
21443 qp = &phba->sli4_hba.hdwq[hwqid];
21444 multixri_pool = qp->p_multixri_pool;
21445 if (!multixri_pool)
21448 if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
21449 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21450 pbl_pool = &qp->p_multixri_pool->pbl_pool;
21451 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21453 multixri_pool->stat_pbl_count = pbl_pool->count;
21454 multixri_pool->stat_pvt_count = pvt_pool->count;
21455 multixri_pool->stat_busy_count = txcmplq_cnt;
21458 multixri_pool->stat_snapshot_taken++;
21463 * lpfc_adjust_pvt_pool_count - Adjust private pool count
21464 * @phba: pointer to lpfc hba data structure.
21465 * @hwqid: belong to which HWQ.
21467 * This routine moves some XRIs from private to public pool when private pool
21470 void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
21472 struct lpfc_multixri_pool *multixri_pool;
21474 u32 prev_io_req_count;
21476 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
21477 if (!multixri_pool)
21479 io_req_count = multixri_pool->io_req_count;
21480 prev_io_req_count = multixri_pool->prev_io_req_count;
21482 if (prev_io_req_count != io_req_count) {
21483 /* Private pool is busy */
21484 multixri_pool->prev_io_req_count = io_req_count;
21486 /* Private pool is not busy.
21487 * Move XRIs from private to public pool.
21489 lpfc_move_xri_pvt_to_pbl(phba, hwqid);
21494 * lpfc_adjust_high_watermark - Adjust high watermark
21495 * @phba: pointer to lpfc hba data structure.
21496 * @hwqid: belong to which HWQ.
21498 * This routine sets high watermark as number of outstanding XRIs,
21499 * but make sure the new value is between xri_limit/2 and xri_limit.
21501 void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
21509 struct lpfc_multixri_pool *multixri_pool;
21510 struct lpfc_sli4_hdw_queue *qp;
21512 qp = &phba->sli4_hba.hdwq[hwqid];
21513 multixri_pool = qp->p_multixri_pool;
21514 if (!multixri_pool)
21516 xri_limit = multixri_pool->xri_limit;
21518 watermark_max = xri_limit;
21519 watermark_min = xri_limit / 2;
21521 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21522 abts_io_bufs = qp->abts_scsi_io_bufs;
21523 abts_io_bufs += qp->abts_nvme_io_bufs;
21525 new_watermark = txcmplq_cnt + abts_io_bufs;
21526 new_watermark = min(watermark_max, new_watermark);
21527 new_watermark = max(watermark_min, new_watermark);
21528 multixri_pool->pvt_pool.high_watermark = new_watermark;
21530 #ifdef LPFC_MXP_STAT
21531 multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
21537 * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
21538 * @phba: pointer to lpfc hba data structure.
21539 * @hwqid: belong to which HWQ.
21541 * This routine is called from hearbeat timer when pvt_pool is idle.
21542 * All free XRIs are moved from private to public pool on hwqid with 2 steps.
21543 * The first step moves (all - low_watermark) amount of XRIs.
21544 * The second step moves the rest of XRIs.
21546 void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
21548 struct lpfc_pbl_pool *pbl_pool;
21549 struct lpfc_pvt_pool *pvt_pool;
21550 struct lpfc_sli4_hdw_queue *qp;
21551 struct lpfc_io_buf *lpfc_ncmd;
21552 struct lpfc_io_buf *lpfc_ncmd_next;
21553 unsigned long iflag;
21554 struct list_head tmp_list;
21557 qp = &phba->sli4_hba.hdwq[hwqid];
21558 pbl_pool = &qp->p_multixri_pool->pbl_pool;
21559 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21562 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
21563 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
21565 if (pvt_pool->count > pvt_pool->low_watermark) {
21566 /* Step 1: move (all - low_watermark) from pvt_pool
21570 /* Move low watermark of bufs from pvt_pool to tmp_list */
21571 INIT_LIST_HEAD(&tmp_list);
21572 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21573 &pvt_pool->list, list) {
21574 list_move_tail(&lpfc_ncmd->list, &tmp_list);
21576 if (tmp_count >= pvt_pool->low_watermark)
21580 /* Move all bufs from pvt_pool to pbl_pool */
21581 list_splice_init(&pvt_pool->list, &pbl_pool->list);
21583 /* Move all bufs from tmp_list to pvt_pool */
21584 list_splice(&tmp_list, &pvt_pool->list);
21586 pbl_pool->count += (pvt_pool->count - tmp_count);
21587 pvt_pool->count = tmp_count;
21589 /* Step 2: move the rest from pvt_pool to pbl_pool */
21590 list_splice_init(&pvt_pool->list, &pbl_pool->list);
21591 pbl_pool->count += pvt_pool->count;
21592 pvt_pool->count = 0;
21595 spin_unlock(&pvt_pool->lock);
21596 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21600 * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
21601 * @phba: pointer to lpfc hba data structure
21602 * @qp: pointer to HDW queue
21603 * @pbl_pool: specified public free XRI pool
21604 * @pvt_pool: specified private free XRI pool
21605 * @count: number of XRIs to move
21607 * This routine tries to move some free common bufs from the specified pbl_pool
21608 * to the specified pvt_pool. It might move less than count XRIs if there's not
21609 * enough in public pool.
21612 * true - if XRIs are successfully moved from the specified pbl_pool to the
21613 * specified pvt_pool
21614 * false - if the specified pbl_pool is empty or locked by someone else
21617 _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
21618 struct lpfc_pbl_pool *pbl_pool,
21619 struct lpfc_pvt_pool *pvt_pool, u32 count)
21621 struct lpfc_io_buf *lpfc_ncmd;
21622 struct lpfc_io_buf *lpfc_ncmd_next;
21623 unsigned long iflag;
21626 ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
21628 if (pbl_pool->count) {
21629 /* Move a batch of XRIs from public to private pool */
21630 lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
21631 list_for_each_entry_safe(lpfc_ncmd,
21635 list_move_tail(&lpfc_ncmd->list,
21644 spin_unlock(&pvt_pool->lock);
21645 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21648 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21655 * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
21656 * @phba: pointer to lpfc hba data structure.
21657 * @hwqid: belong to which HWQ.
21658 * @count: number of XRIs to move
21660 * This routine tries to find some free common bufs in one of public pools with
21661 * Round Robin method. The search always starts from local hwqid, then the next
21662 * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
21663 * a batch of free common bufs are moved to private pool on hwqid.
21664 * It might move less than count XRIs if there's not enough in public pool.
21666 void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
21668 struct lpfc_multixri_pool *multixri_pool;
21669 struct lpfc_multixri_pool *next_multixri_pool;
21670 struct lpfc_pvt_pool *pvt_pool;
21671 struct lpfc_pbl_pool *pbl_pool;
21672 struct lpfc_sli4_hdw_queue *qp;
21677 qp = &phba->sli4_hba.hdwq[hwqid];
21678 multixri_pool = qp->p_multixri_pool;
21679 pvt_pool = &multixri_pool->pvt_pool;
21680 pbl_pool = &multixri_pool->pbl_pool;
21682 /* Check if local pbl_pool is available */
21683 ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
21685 #ifdef LPFC_MXP_STAT
21686 multixri_pool->local_pbl_hit_count++;
21691 hwq_count = phba->cfg_hdw_queue;
21693 /* Get the next hwqid which was found last time */
21694 next_hwqid = multixri_pool->rrb_next_hwqid;
21697 /* Go to next hwq */
21698 next_hwqid = (next_hwqid + 1) % hwq_count;
21700 next_multixri_pool =
21701 phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
21702 pbl_pool = &next_multixri_pool->pbl_pool;
21704 /* Check if the public free xri pool is available */
21705 ret = _lpfc_move_xri_pbl_to_pvt(
21706 phba, qp, pbl_pool, pvt_pool, count);
21708 /* Exit while-loop if success or all hwqid are checked */
21709 } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
21711 /* Starting point for the next time */
21712 multixri_pool->rrb_next_hwqid = next_hwqid;
21715 /* stats: all public pools are empty*/
21716 multixri_pool->pbl_empty_count++;
21719 #ifdef LPFC_MXP_STAT
21721 if (next_hwqid == hwqid)
21722 multixri_pool->local_pbl_hit_count++;
21724 multixri_pool->other_pbl_hit_count++;
21730 * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
21731 * @phba: pointer to lpfc hba data structure.
21732 * @hwqid: belong to which HWQ.
21734 * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
21737 void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
21739 struct lpfc_multixri_pool *multixri_pool;
21740 struct lpfc_pvt_pool *pvt_pool;
21742 multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
21743 pvt_pool = &multixri_pool->pvt_pool;
21745 if (pvt_pool->count < pvt_pool->low_watermark)
21746 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
21750 * lpfc_release_io_buf - Return one IO buf back to free pool
21751 * @phba: pointer to lpfc hba data structure.
21752 * @lpfc_ncmd: IO buf to be returned.
21753 * @qp: belong to which HWQ.
21755 * This routine returns one IO buf back to free pool. If this is an urgent IO,
21756 * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
21757 * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
21758 * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to
21759 * lpfc_io_buf_list_put.
21761 void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
21762 struct lpfc_sli4_hdw_queue *qp)
21764 unsigned long iflag;
21765 struct lpfc_pbl_pool *pbl_pool;
21766 struct lpfc_pvt_pool *pvt_pool;
21767 struct lpfc_epd_pool *epd_pool;
21773 /* MUST zero fields if buffer is reused by another protocol */
21774 lpfc_ncmd->nvmeCmd = NULL;
21775 lpfc_ncmd->cur_iocbq.cmd_cmpl = NULL;
21777 if (phba->cfg_xpsgl && !phba->nvmet_support &&
21778 !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
21779 lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
21781 if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
21782 lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
21784 if (phba->cfg_xri_rebalancing) {
21785 if (lpfc_ncmd->expedite) {
21786 /* Return to expedite pool */
21787 epd_pool = &phba->epd_pool;
21788 spin_lock_irqsave(&epd_pool->lock, iflag);
21789 list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
21791 spin_unlock_irqrestore(&epd_pool->lock, iflag);
21795 /* Avoid invalid access if an IO sneaks in and is being rejected
21796 * just _after_ xri pools are destroyed in lpfc_offline.
21797 * Nothing much can be done at this point.
21799 if (!qp->p_multixri_pool)
21802 pbl_pool = &qp->p_multixri_pool->pbl_pool;
21803 pvt_pool = &qp->p_multixri_pool->pvt_pool;
21805 txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
21806 abts_io_bufs = qp->abts_scsi_io_bufs;
21807 abts_io_bufs += qp->abts_nvme_io_bufs;
21809 xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
21810 xri_limit = qp->p_multixri_pool->xri_limit;
21812 #ifdef LPFC_MXP_STAT
21813 if (xri_owned <= xri_limit)
21814 qp->p_multixri_pool->below_limit_count++;
21816 qp->p_multixri_pool->above_limit_count++;
21819 /* XRI goes to either public or private free xri pool
21820 * based on watermark and xri_limit
21822 if ((pvt_pool->count < pvt_pool->low_watermark) ||
21823 (xri_owned < xri_limit &&
21824 pvt_pool->count < pvt_pool->high_watermark)) {
21825 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
21826 qp, free_pvt_pool);
21827 list_add_tail(&lpfc_ncmd->list,
21830 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21832 lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
21833 qp, free_pub_pool);
21834 list_add_tail(&lpfc_ncmd->list,
21837 spin_unlock_irqrestore(&pbl_pool->lock, iflag);
21840 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
21842 list_add_tail(&lpfc_ncmd->list,
21843 &qp->lpfc_io_buf_list_put);
21845 spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
21851 * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
21852 * @phba: pointer to lpfc hba data structure.
21853 * @qp: pointer to HDW queue
21854 * @pvt_pool: pointer to private pool data structure.
21855 * @ndlp: pointer to lpfc nodelist data structure.
21857 * This routine tries to get one free IO buf from private pool.
21860 * pointer to one free IO buf - if private pool is not empty
21861 * NULL - if private pool is empty
21863 static struct lpfc_io_buf *
21864 lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
21865 struct lpfc_sli4_hdw_queue *qp,
21866 struct lpfc_pvt_pool *pvt_pool,
21867 struct lpfc_nodelist *ndlp)
21869 struct lpfc_io_buf *lpfc_ncmd;
21870 struct lpfc_io_buf *lpfc_ncmd_next;
21871 unsigned long iflag;
21873 lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
21874 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21875 &pvt_pool->list, list) {
21876 if (lpfc_test_rrq_active(
21877 phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
21879 list_del(&lpfc_ncmd->list);
21881 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21884 spin_unlock_irqrestore(&pvt_pool->lock, iflag);
21890 * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
21891 * @phba: pointer to lpfc hba data structure.
21893 * This routine tries to get one free IO buf from expedite pool.
21896 * pointer to one free IO buf - if expedite pool is not empty
21897 * NULL - if expedite pool is empty
21899 static struct lpfc_io_buf *
21900 lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
21902 struct lpfc_io_buf *lpfc_ncmd;
21903 struct lpfc_io_buf *lpfc_ncmd_next;
21904 unsigned long iflag;
21905 struct lpfc_epd_pool *epd_pool;
21907 epd_pool = &phba->epd_pool;
21910 spin_lock_irqsave(&epd_pool->lock, iflag);
21911 if (epd_pool->count > 0) {
21912 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
21913 &epd_pool->list, list) {
21914 list_del(&lpfc_ncmd->list);
21919 spin_unlock_irqrestore(&epd_pool->lock, iflag);
21925 * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
21926 * @phba: pointer to lpfc hba data structure.
21927 * @ndlp: pointer to lpfc nodelist data structure.
21928 * @hwqid: belong to which HWQ
21929 * @expedite: 1 means this request is urgent.
21931 * This routine will do the following actions and then return a pointer to
21934 * 1. If private free xri count is empty, move some XRIs from public to
21936 * 2. Get one XRI from private free xri pool.
21937 * 3. If we fail to get one from pvt_pool and this is an expedite request,
21938 * get one free xri from expedite pool.
21940 * Note: ndlp is only used on SCSI side for RRQ testing.
21941 * The caller should pass NULL for ndlp on NVME side.
21944 * pointer to one free IO buf - if private pool is not empty
21945 * NULL - if private pool is empty
21947 static struct lpfc_io_buf *
21948 lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
21949 struct lpfc_nodelist *ndlp,
21950 int hwqid, int expedite)
21952 struct lpfc_sli4_hdw_queue *qp;
21953 struct lpfc_multixri_pool *multixri_pool;
21954 struct lpfc_pvt_pool *pvt_pool;
21955 struct lpfc_io_buf *lpfc_ncmd;
21957 qp = &phba->sli4_hba.hdwq[hwqid];
21960 lpfc_printf_log(phba, KERN_INFO,
21961 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
21962 "5556 NULL qp for hwqid x%x\n", hwqid);
21965 multixri_pool = qp->p_multixri_pool;
21966 if (!multixri_pool) {
21967 lpfc_printf_log(phba, KERN_INFO,
21968 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
21969 "5557 NULL multixri for hwqid x%x\n", hwqid);
21972 pvt_pool = &multixri_pool->pvt_pool;
21974 lpfc_printf_log(phba, KERN_INFO,
21975 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
21976 "5558 NULL pvt_pool for hwqid x%x\n", hwqid);
21979 multixri_pool->io_req_count++;
21981 /* If pvt_pool is empty, move some XRIs from public to private pool */
21982 if (pvt_pool->count == 0)
21983 lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
21985 /* Get one XRI from private free xri pool */
21986 lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
21989 lpfc_ncmd->hdwq = qp;
21990 lpfc_ncmd->hdwq_no = hwqid;
21991 } else if (expedite) {
21992 /* If we fail to get one from pvt_pool and this is an expedite
21993 * request, get one free xri from expedite pool.
21995 lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
22001 static inline struct lpfc_io_buf *
22002 lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
22004 struct lpfc_sli4_hdw_queue *qp;
22005 struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
22007 qp = &phba->sli4_hba.hdwq[idx];
22008 list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
22009 &qp->lpfc_io_buf_list_get, list) {
22010 if (lpfc_test_rrq_active(phba, ndlp,
22011 lpfc_cmd->cur_iocbq.sli4_lxritag))
22014 if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
22017 list_del_init(&lpfc_cmd->list);
22019 lpfc_cmd->hdwq = qp;
22020 lpfc_cmd->hdwq_no = idx;
22027 * lpfc_get_io_buf - Get one IO buffer from free pool
22028 * @phba: The HBA for which this call is being executed.
22029 * @ndlp: pointer to lpfc nodelist data structure.
22030 * @hwqid: belong to which HWQ
22031 * @expedite: 1 means this request is urgent.
22033 * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
22034 * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
22035 * a IO buffer from head of @hdwq io_buf_list and returns to caller.
22037 * Note: ndlp is only used on SCSI side for RRQ testing.
22038 * The caller should pass NULL for ndlp on NVME side.
22042 * Pointer to lpfc_io_buf - Success
22044 struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
22045 struct lpfc_nodelist *ndlp,
22046 u32 hwqid, int expedite)
22048 struct lpfc_sli4_hdw_queue *qp;
22049 unsigned long iflag;
22050 struct lpfc_io_buf *lpfc_cmd;
22052 qp = &phba->sli4_hba.hdwq[hwqid];
22055 lpfc_printf_log(phba, KERN_WARNING,
22056 LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
22057 "5555 NULL qp for hwqid x%x\n", hwqid);
22061 if (phba->cfg_xri_rebalancing)
22062 lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
22063 phba, ndlp, hwqid, expedite);
22065 lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
22066 qp, alloc_xri_get);
22067 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
22068 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
22070 lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
22071 qp, alloc_xri_put);
22072 list_splice(&qp->lpfc_io_buf_list_put,
22073 &qp->lpfc_io_buf_list_get);
22074 qp->get_io_bufs += qp->put_io_bufs;
22075 INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
22076 qp->put_io_bufs = 0;
22077 spin_unlock(&qp->io_buf_list_put_lock);
22078 if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
22080 lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
22082 spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
22089 * lpfc_read_object - Retrieve object data from HBA
22090 * @phba: The HBA for which this call is being executed.
22091 * @rdobject: Pathname of object data we want to read.
22092 * @datap: Pointer to where data will be copied to.
22093 * @datasz: size of data area
22095 * This routine is limited to object sizes of LPFC_BPL_SIZE (1024) or less.
22096 * The data will be truncated if datasz is not large enough.
22097 * Version 1 is not supported with Embedded mbox cmd, so we must use version 0.
22098 * Returns the actual bytes read from the object.
22101 lpfc_read_object(struct lpfc_hba *phba, char *rdobject, uint32_t *datap,
22104 struct lpfc_mbx_read_object *read_object;
22105 LPFC_MBOXQ_t *mbox;
22106 int rc, length, eof, j, byte_cnt = 0;
22107 uint32_t shdr_status, shdr_add_status;
22108 union lpfc_sli4_cfg_shdr *shdr;
22109 struct lpfc_dmabuf *pcmd;
22110 u32 rd_object_name[LPFC_MBX_OBJECT_NAME_LEN_DW] = {0};
22112 /* sanity check on queue memory */
22116 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
22119 length = (sizeof(struct lpfc_mbx_read_object) -
22120 sizeof(struct lpfc_sli4_cfg_mhdr));
22121 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
22122 LPFC_MBOX_OPCODE_READ_OBJECT,
22123 length, LPFC_SLI4_MBX_EMBED);
22124 read_object = &mbox->u.mqe.un.read_object;
22125 shdr = (union lpfc_sli4_cfg_shdr *)&read_object->header.cfg_shdr;
22127 bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_0);
22128 bf_set(lpfc_mbx_rd_object_rlen, &read_object->u.request, datasz);
22129 read_object->u.request.rd_object_offset = 0;
22130 read_object->u.request.rd_object_cnt = 1;
22132 memset((void *)read_object->u.request.rd_object_name, 0,
22134 scnprintf((char *)rd_object_name, sizeof(rd_object_name), rdobject);
22135 for (j = 0; j < strlen(rdobject); j++)
22136 read_object->u.request.rd_object_name[j] =
22137 cpu_to_le32(rd_object_name[j]);
22139 pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
22141 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
22142 if (!pcmd || !pcmd->virt) {
22144 mempool_free(mbox, phba->mbox_mem_pool);
22147 memset((void *)pcmd->virt, 0, LPFC_BPL_SIZE);
22148 read_object->u.request.rd_object_hbuf[0].pa_lo =
22149 putPaddrLow(pcmd->phys);
22150 read_object->u.request.rd_object_hbuf[0].pa_hi =
22151 putPaddrHigh(pcmd->phys);
22152 read_object->u.request.rd_object_hbuf[0].length = LPFC_BPL_SIZE;
22154 mbox->vport = phba->pport;
22155 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
22156 mbox->ctx_ndlp = NULL;
22158 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
22159 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
22160 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
22162 if (shdr_status == STATUS_FAILED &&
22163 shdr_add_status == ADD_STATUS_INVALID_OBJECT_NAME) {
22164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
22165 "4674 No port cfg file in FW.\n");
22166 byte_cnt = -ENOENT;
22167 } else if (shdr_status || shdr_add_status || rc) {
22168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
22169 "2625 READ_OBJECT mailbox failed with "
22170 "status x%x add_status x%x, mbx status x%x\n",
22171 shdr_status, shdr_add_status, rc);
22175 length = read_object->u.response.rd_object_actual_rlen;
22176 eof = bf_get(lpfc_mbx_rd_object_eof, &read_object->u.response);
22177 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_CGN_MGMT,
22178 "2626 READ_OBJECT Success len %d:%d, EOF %d\n",
22179 length, datasz, eof);
22181 /* Detect the port config file exists but is empty */
22182 if (!length && eof) {
22188 lpfc_sli_pcimem_bcopy(pcmd->virt, datap, byte_cnt);
22192 /* This is an embedded SLI4 mailbox with an external buffer allocated.
22193 * Free the pcmd and then cleanup with the correct routine.
22195 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
22197 lpfc_sli4_mbox_cmd_free(phba, mbox);
22202 * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
22203 * @phba: The HBA for which this call is being executed.
22204 * @lpfc_buf: IO buf structure to append the SGL chunk
22206 * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
22207 * and will allocate an SGL chunk if the pool is empty.
22211 * Pointer to sli4_hybrid_sgl - Success
22213 struct sli4_hybrid_sgl *
22214 lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
22216 struct sli4_hybrid_sgl *list_entry = NULL;
22217 struct sli4_hybrid_sgl *tmp = NULL;
22218 struct sli4_hybrid_sgl *allocated_sgl = NULL;
22219 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22220 struct list_head *buf_list = &hdwq->sgl_list;
22221 unsigned long iflags;
22223 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22225 if (likely(!list_empty(buf_list))) {
22226 /* break off 1 chunk from the sgl_list */
22227 list_for_each_entry_safe(list_entry, tmp,
22228 buf_list, list_node) {
22229 list_move_tail(&list_entry->list_node,
22230 &lpfc_buf->dma_sgl_xtra_list);
22234 /* allocate more */
22235 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22236 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
22237 cpu_to_node(hdwq->io_wq->chann));
22239 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22240 "8353 error kmalloc memory for HDWQ "
22242 lpfc_buf->hdwq_no, __func__);
22246 tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
22247 GFP_ATOMIC, &tmp->dma_phys_sgl);
22248 if (!tmp->dma_sgl) {
22249 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22250 "8354 error pool_alloc memory for HDWQ "
22252 lpfc_buf->hdwq_no, __func__);
22257 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22258 list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
22261 allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
22262 struct sli4_hybrid_sgl,
22265 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22267 return allocated_sgl;
22271 * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
22272 * @phba: The HBA for which this call is being executed.
22273 * @lpfc_buf: IO buf structure with the SGL chunk
22275 * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
22282 lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
22285 struct sli4_hybrid_sgl *list_entry = NULL;
22286 struct sli4_hybrid_sgl *tmp = NULL;
22287 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22288 struct list_head *buf_list = &hdwq->sgl_list;
22289 unsigned long iflags;
22291 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22293 if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
22294 list_for_each_entry_safe(list_entry, tmp,
22295 &lpfc_buf->dma_sgl_xtra_list,
22297 list_move_tail(&list_entry->list_node,
22304 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22309 * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
22310 * @phba: phba object
22311 * @hdwq: hdwq to cleanup sgl buff resources on
22313 * This routine frees all SGL chunks of hdwq SGL chunk pool.
22319 lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
22320 struct lpfc_sli4_hdw_queue *hdwq)
22322 struct list_head *buf_list = &hdwq->sgl_list;
22323 struct sli4_hybrid_sgl *list_entry = NULL;
22324 struct sli4_hybrid_sgl *tmp = NULL;
22325 unsigned long iflags;
22327 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22329 /* Free sgl pool */
22330 list_for_each_entry_safe(list_entry, tmp,
22331 buf_list, list_node) {
22332 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
22333 list_entry->dma_sgl,
22334 list_entry->dma_phys_sgl);
22335 list_del(&list_entry->list_node);
22339 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22343 * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
22344 * @phba: The HBA for which this call is being executed.
22345 * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
22347 * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
22348 * and will allocate an CMD/RSP buffer if the pool is empty.
22352 * Pointer to fcp_cmd_rsp_buf - Success
22354 struct fcp_cmd_rsp_buf *
22355 lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
22356 struct lpfc_io_buf *lpfc_buf)
22358 struct fcp_cmd_rsp_buf *list_entry = NULL;
22359 struct fcp_cmd_rsp_buf *tmp = NULL;
22360 struct fcp_cmd_rsp_buf *allocated_buf = NULL;
22361 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22362 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
22363 unsigned long iflags;
22365 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22367 if (likely(!list_empty(buf_list))) {
22368 /* break off 1 chunk from the list */
22369 list_for_each_entry_safe(list_entry, tmp,
22372 list_move_tail(&list_entry->list_node,
22373 &lpfc_buf->dma_cmd_rsp_list);
22377 /* allocate more */
22378 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22379 tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
22380 cpu_to_node(hdwq->io_wq->chann));
22382 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22383 "8355 error kmalloc memory for HDWQ "
22385 lpfc_buf->hdwq_no, __func__);
22389 tmp->fcp_cmnd = dma_pool_zalloc(phba->lpfc_cmd_rsp_buf_pool,
22391 &tmp->fcp_cmd_rsp_dma_handle);
22393 if (!tmp->fcp_cmnd) {
22394 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
22395 "8356 error pool_alloc memory for HDWQ "
22397 lpfc_buf->hdwq_no, __func__);
22402 tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
22403 sizeof(struct fcp_cmnd));
22405 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22406 list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
22409 allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
22410 struct fcp_cmd_rsp_buf,
22413 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22415 return allocated_buf;
22419 * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
22420 * @phba: The HBA for which this call is being executed.
22421 * @lpfc_buf: IO buf structure with the CMD/RSP buf
22423 * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
22430 lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
22431 struct lpfc_io_buf *lpfc_buf)
22434 struct fcp_cmd_rsp_buf *list_entry = NULL;
22435 struct fcp_cmd_rsp_buf *tmp = NULL;
22436 struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
22437 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
22438 unsigned long iflags;
22440 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22442 if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
22443 list_for_each_entry_safe(list_entry, tmp,
22444 &lpfc_buf->dma_cmd_rsp_list,
22446 list_move_tail(&list_entry->list_node,
22453 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22458 * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
22459 * @phba: phba object
22460 * @hdwq: hdwq to cleanup cmd rsp buff resources on
22462 * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
22468 lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
22469 struct lpfc_sli4_hdw_queue *hdwq)
22471 struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
22472 struct fcp_cmd_rsp_buf *list_entry = NULL;
22473 struct fcp_cmd_rsp_buf *tmp = NULL;
22474 unsigned long iflags;
22476 spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
22478 /* Free cmd_rsp buf pool */
22479 list_for_each_entry_safe(list_entry, tmp,
22482 dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
22483 list_entry->fcp_cmnd,
22484 list_entry->fcp_cmd_rsp_dma_handle);
22485 list_del(&list_entry->list_node);
22489 spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
22493 * lpfc_sli_prep_wqe - Prepare WQE for the command to be posted
22494 * @phba: phba object
22495 * @job: job entry of the command to be posted.
22497 * Fill the common fields of the wqe for each of the command.
22503 lpfc_sli_prep_wqe(struct lpfc_hba *phba, struct lpfc_iocbq *job)
22508 u32 fip, abort_tag;
22509 struct lpfc_nodelist *ndlp = NULL;
22510 union lpfc_wqe128 *wqe = &job->wqe;
22511 u8 command_type = ELS_COMMAND_NON_FIP;
22513 fip = phba->hba_flag & HBA_FIP_SUPPORT;
22514 /* The fcp commands will set command type */
22515 if (job->cmd_flag & LPFC_IO_FCP)
22516 command_type = FCP_COMMAND;
22517 else if (fip && (job->cmd_flag & LPFC_FIP_ELS_ID_MASK))
22518 command_type = ELS_COMMAND_FIP;
22520 command_type = ELS_COMMAND_NON_FIP;
22522 abort_tag = job->iotag;
22523 cmnd = bf_get(wqe_cmnd, &wqe->els_req.wqe_com);
22526 case CMD_ELS_REQUEST64_WQE:
22529 if_type = bf_get(lpfc_sli_intf_if_type,
22530 &phba->sli4_hba.sli_intf);
22531 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
22532 pcmd = (u32 *)job->cmd_dmabuf->virt;
22533 if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
22534 *pcmd == ELS_CMD_SCR ||
22535 *pcmd == ELS_CMD_RDF ||
22536 *pcmd == ELS_CMD_EDC ||
22537 *pcmd == ELS_CMD_RSCN_XMT ||
22538 *pcmd == ELS_CMD_FDISC ||
22539 *pcmd == ELS_CMD_LOGO ||
22540 *pcmd == ELS_CMD_QFPA ||
22541 *pcmd == ELS_CMD_UVEM ||
22542 *pcmd == ELS_CMD_PLOGI)) {
22543 bf_set(els_req64_sp, &wqe->els_req, 1);
22544 bf_set(els_req64_sid, &wqe->els_req,
22545 job->vport->fc_myDID);
22547 if ((*pcmd == ELS_CMD_FLOGI) &&
22548 !(phba->fc_topology ==
22549 LPFC_TOPOLOGY_LOOP))
22550 bf_set(els_req64_sid, &wqe->els_req, 0);
22552 bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
22553 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
22554 phba->vpi_ids[job->vport->vpi]);
22556 bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
22557 bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
22558 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
22562 bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
22563 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
22565 bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
22566 bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
22567 bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
22568 bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
22569 bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
22571 case CMD_XMIT_ELS_RSP64_WQE:
22575 wqe->xmit_els_rsp.word4 = 0;
22577 if_type = bf_get(lpfc_sli_intf_if_type,
22578 &phba->sli4_hba.sli_intf);
22579 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
22580 if (job->vport->fc_flag & FC_PT2PT) {
22581 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
22582 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
22583 job->vport->fc_myDID);
22584 if (job->vport->fc_myDID == Fabric_DID) {
22585 bf_set(wqe_els_did,
22586 &wqe->xmit_els_rsp.wqe_dest, 0);
22591 bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
22592 bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
22593 bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
22594 bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
22595 LPFC_WQE_LENLOC_WORD3);
22596 bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
22598 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
22599 bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
22600 bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
22601 job->vport->fc_myDID);
22602 bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
22605 if (phba->sli_rev == LPFC_SLI_REV4) {
22606 bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
22607 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
22609 if (bf_get(wqe_ct, &wqe->xmit_els_rsp.wqe_com))
22610 bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
22611 phba->vpi_ids[job->vport->vpi]);
22613 command_type = OTHER_COMMAND;
22615 case CMD_GEN_REQUEST64_WQE:
22617 bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
22618 bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
22619 bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
22620 bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
22621 bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
22622 command_type = OTHER_COMMAND;
22624 case CMD_XMIT_SEQUENCE64_WQE:
22625 if (phba->link_flag & LS_LOOPBACK_MODE)
22626 bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
22628 wqe->xmit_sequence.rsvd3 = 0;
22629 bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
22630 bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
22631 bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
22632 LPFC_WQE_IOD_WRITE);
22633 bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
22634 LPFC_WQE_LENLOC_WORD12);
22635 bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
22636 command_type = OTHER_COMMAND;
22638 case CMD_XMIT_BLS_RSP64_WQE:
22639 bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
22640 bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
22641 bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
22642 bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
22643 phba->vpi_ids[phba->pport->vpi]);
22644 bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
22645 bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
22646 LPFC_WQE_LENLOC_NONE);
22647 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
22648 command_type = OTHER_COMMAND;
22650 case CMD_FCP_ICMND64_WQE: /* task mgmt commands */
22651 case CMD_ABORT_XRI_WQE: /* abort iotag */
22652 case CMD_SEND_FRAME: /* mds loopback */
22653 /* cases already formatted for sli4 wqe - no chgs necessary */
22657 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
22658 "6207 Invalid command 0x%x\n",
22663 wqe->generic.wqe_com.abort_tag = abort_tag;
22664 bf_set(wqe_reqtag, &wqe->generic.wqe_com, job->iotag);
22665 bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
22666 bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);