1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/interrupt.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/lockdep.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
37 #include <linux/aer.h>
39 #include <asm/set_memory.h>
42 #include <linux/nvme-fc-driver.h>
47 #include "lpfc_sli4.h"
49 #include "lpfc_disc.h"
51 #include "lpfc_scsi.h"
52 #include "lpfc_nvme.h"
53 #include "lpfc_nvmet.h"
54 #include "lpfc_crtn.h"
55 #include "lpfc_logmsg.h"
56 #include "lpfc_compat.h"
57 #include "lpfc_debugfs.h"
58 #include "lpfc_vport.h"
59 #include "lpfc_version.h"
61 /* There are only four IOCB completion types. */
62 typedef enum _lpfc_iocb_type
{
70 /* Provide function prototypes local to this module. */
71 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
73 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
74 uint8_t *, uint32_t *);
75 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
77 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
79 static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport
*vport
,
80 struct hbq_dmabuf
*dmabuf
);
81 static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba
*, struct lpfc_queue
*,
83 static int lpfc_sli4_post_sgl_list(struct lpfc_hba
*, struct list_head
*,
85 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
,
86 struct lpfc_eqe
*eqe
, uint32_t qidx
);
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 int lpfc_sli4_abort_nvme_io(struct lpfc_hba
*phba
,
90 struct lpfc_sli_ring
*pring
,
91 struct lpfc_iocbq
*cmdiocb
);
94 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
99 #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
101 * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
102 * @srcp: Source memory pointer.
103 * @destp: Destination memory pointer.
104 * @cnt: Number of words required to be copied.
105 * Must be a multiple of sizeof(uint64_t)
107 * This function is used for copying data between driver memory
108 * and the SLI WQ. This function also changes the endianness
109 * of each word if native endianness is different from SLI
110 * endianness. This function can be called with or without
114 lpfc_sli4_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
116 uint64_t *src
= srcp
;
117 uint64_t *dest
= destp
;
120 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint64_t))
124 #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
128 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
129 * @q: The Work Queue to operate on.
130 * @wqe: The work Queue Entry to put on the Work queue.
132 * This routine will copy the contents of @wqe to the next available entry on
133 * the @q. This function will then ring the Work Queue Doorbell to signal the
134 * HBA to start processing the Work Queue Entry. This function returns 0 if
135 * successful. If no entries are available on @q then this function will return
137 * The caller is expected to hold the hbalock when calling this routine.
140 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe128
*wqe
)
142 union lpfc_wqe
*temp_wqe
;
143 struct lpfc_register doorbell
;
150 /* sanity check on queue memory */
153 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
155 /* If the host has not yet processed the next entry then we are done */
156 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
157 if (idx
== q
->hba_index
) {
162 /* set consumption flag every once in a while */
163 if (!((q
->host_index
+ 1) % q
->entry_repost
))
164 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
166 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 0);
167 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
168 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
169 lpfc_sli4_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
170 if (q
->dpp_enable
&& q
->phba
->cfg_enable_dpp
) {
171 /* write to DPP aperture taking advatage of Combined Writes */
172 tmp
= (uint8_t *)temp_wqe
;
174 for (i
= 0; i
< q
->entry_size
; i
+= sizeof(uint64_t))
175 __raw_writeq(*((uint64_t *)(tmp
+ i
)),
178 for (i
= 0; i
< q
->entry_size
; i
+= sizeof(uint32_t))
179 __raw_writel(*((uint32_t *)(tmp
+ i
)),
183 /* ensure WQE bcopy and DPP flushed before doorbell write */
186 /* Update the host index before invoking device */
187 host_index
= q
->host_index
;
193 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
194 if (q
->dpp_enable
&& q
->phba
->cfg_enable_dpp
) {
195 bf_set(lpfc_if6_wq_db_list_fm_num_posted
, &doorbell
, 1);
196 bf_set(lpfc_if6_wq_db_list_fm_dpp
, &doorbell
, 1);
197 bf_set(lpfc_if6_wq_db_list_fm_dpp_id
, &doorbell
,
199 bf_set(lpfc_if6_wq_db_list_fm_id
, &doorbell
,
202 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
203 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
205 /* Leave bits <23:16> clear for if_type 6 dpp */
206 if_type
= bf_get(lpfc_sli_intf_if_type
,
207 &q
->phba
->sli4_hba
.sli_intf
);
208 if (if_type
!= LPFC_SLI_INTF_IF_TYPE_6
)
209 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
,
212 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
213 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
214 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
218 writel(doorbell
.word0
, q
->db_regaddr
);
224 * lpfc_sli4_wq_release - Updates internal hba index for WQ
225 * @q: The Work Queue to operate on.
226 * @index: The index to advance the hba index to.
228 * This routine will update the HBA index of a queue to reflect consumption of
229 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
230 * an entry the host calls this function to update the queue's internal
231 * pointers. This routine returns the number of entries that were consumed by
235 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
237 uint32_t released
= 0;
239 /* sanity check on queue memory */
243 if (q
->hba_index
== index
)
246 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
248 } while (q
->hba_index
!= index
);
253 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
254 * @q: The Mailbox Queue to operate on.
255 * @wqe: The Mailbox Queue Entry to put on the Work queue.
257 * This routine will copy the contents of @mqe to the next available entry on
258 * the @q. This function will then ring the Work Queue Doorbell to signal the
259 * HBA to start processing the Work Queue Entry. This function returns 0 if
260 * successful. If no entries are available on @q then this function will return
262 * The caller is expected to hold the hbalock when calling this routine.
265 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
267 struct lpfc_mqe
*temp_mqe
;
268 struct lpfc_register doorbell
;
270 /* sanity check on queue memory */
273 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
275 /* If the host has not yet processed the next entry then we are done */
276 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
278 lpfc_sli4_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
279 /* Save off the mailbox pointer for completion */
280 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
282 /* Update the host index before invoking device */
283 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
287 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
288 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
289 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
294 * lpfc_sli4_mq_release - Updates internal hba index for MQ
295 * @q: The Mailbox Queue to operate on.
297 * This routine will update the HBA index of a queue to reflect consumption of
298 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
299 * an entry the host calls this function to update the queue's internal
300 * pointers. This routine returns the number of entries that were consumed by
304 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
306 /* sanity check on queue memory */
310 /* Clear the mailbox pointer for completion */
311 q
->phba
->mbox
= NULL
;
312 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
317 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
318 * @q: The Event Queue to get the first valid EQE from
320 * This routine will get the first valid Event Queue Entry from @q, update
321 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
322 * the Queue (no more work to do), or the Queue is full of EQEs that have been
323 * processed, but not popped back to the HBA then this routine will return NULL.
325 static struct lpfc_eqe
*
326 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
328 struct lpfc_hba
*phba
;
329 struct lpfc_eqe
*eqe
;
332 /* sanity check on queue memory */
336 eqe
= q
->qe
[q
->hba_index
].eqe
;
338 /* If the next EQE is not valid then we are done */
339 if (bf_get_le32(lpfc_eqe_valid
, eqe
) != q
->qe_valid
)
341 /* If the host has not yet processed the next entry then we are done */
342 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
343 if (idx
== q
->host_index
)
347 /* if the index wrapped around, toggle the valid bit */
348 if (phba
->sli4_hba
.pc_sli4_params
.eqav
&& !q
->hba_index
)
349 q
->qe_valid
= (q
->qe_valid
) ? 0 : 1;
353 * insert barrier for instruction interlock : data from the hardware
354 * must have the valid bit checked before it can be copied and acted
355 * upon. Speculative instructions were allowing a bcopy at the start
356 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
357 * after our return, to copy data before the valid bit check above
358 * was done. As such, some of the copied data was stale. The barrier
359 * ensures the check is before any data is copied.
366 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
367 * @q: The Event Queue to disable interrupts
371 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
373 struct lpfc_register doorbell
;
376 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
377 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
378 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
379 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
380 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
381 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQDBregaddr
);
385 * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
386 * @q: The Event Queue to disable interrupts
390 lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue
*q
)
392 struct lpfc_register doorbell
;
395 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
396 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
397 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
398 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
399 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
400 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQDBregaddr
);
404 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
405 * @q: The Event Queue that the host has completed processing for.
406 * @arm: Indicates whether the host wants to arms this CQ.
408 * This routine will mark all Event Queue Entries on @q, from the last
409 * known completed entry to the last entry that was processed, as completed
410 * by clearing the valid bit for each completion queue entry. Then it will
411 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
412 * The internal host index in the @q will be updated by this routine to indicate
413 * that the host has finished processing the entries. The @arm parameter
414 * indicates that the queue should be rearmed when ringing the doorbell.
416 * This function will return the number of EQEs that were popped.
419 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
421 uint32_t released
= 0;
422 struct lpfc_hba
*phba
;
423 struct lpfc_eqe
*temp_eqe
;
424 struct lpfc_register doorbell
;
426 /* sanity check on queue memory */
431 /* while there are valid entries */
432 while (q
->hba_index
!= q
->host_index
) {
433 if (!phba
->sli4_hba
.pc_sli4_params
.eqav
) {
434 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
435 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
438 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
440 if (unlikely(released
== 0 && !arm
))
443 /* ring doorbell for number popped */
446 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
447 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
449 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
450 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
451 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
452 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
453 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
454 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQDBregaddr
);
455 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
456 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
457 readl(q
->phba
->sli4_hba
.EQDBregaddr
);
462 * lpfc_sli4_if6_eq_release - Indicates the host has finished processing an EQ
463 * @q: The Event Queue that the host has completed processing for.
464 * @arm: Indicates whether the host wants to arms this CQ.
466 * This routine will mark all Event Queue Entries on @q, from the last
467 * known completed entry to the last entry that was processed, as completed
468 * by clearing the valid bit for each completion queue entry. Then it will
469 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
470 * The internal host index in the @q will be updated by this routine to indicate
471 * that the host has finished processing the entries. The @arm parameter
472 * indicates that the queue should be rearmed when ringing the doorbell.
474 * This function will return the number of EQEs that were popped.
477 lpfc_sli4_if6_eq_release(struct lpfc_queue
*q
, bool arm
)
479 uint32_t released
= 0;
480 struct lpfc_hba
*phba
;
481 struct lpfc_eqe
*temp_eqe
;
482 struct lpfc_register doorbell
;
484 /* sanity check on queue memory */
489 /* while there are valid entries */
490 while (q
->hba_index
!= q
->host_index
) {
491 if (!phba
->sli4_hba
.pc_sli4_params
.eqav
) {
492 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
493 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
496 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
498 if (unlikely(released
== 0 && !arm
))
501 /* ring doorbell for number popped */
504 bf_set(lpfc_if6_eq_doorbell_arm
, &doorbell
, 1);
505 bf_set(lpfc_if6_eq_doorbell_num_released
, &doorbell
, released
);
506 bf_set(lpfc_if6_eq_doorbell_eqid
, &doorbell
, q
->queue_id
);
507 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQDBregaddr
);
508 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
509 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
510 readl(q
->phba
->sli4_hba
.EQDBregaddr
);
515 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
516 * @q: The Completion Queue to get the first valid CQE from
518 * This routine will get the first valid Completion Queue Entry from @q, update
519 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
520 * the Queue (no more work to do), or the Queue is full of CQEs that have been
521 * processed, but not popped back to the HBA then this routine will return NULL.
523 static struct lpfc_cqe
*
524 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
526 struct lpfc_hba
*phba
;
527 struct lpfc_cqe
*cqe
;
530 /* sanity check on queue memory */
534 cqe
= q
->qe
[q
->hba_index
].cqe
;
536 /* If the next CQE is not valid then we are done */
537 if (bf_get_le32(lpfc_cqe_valid
, cqe
) != q
->qe_valid
)
539 /* If the host has not yet processed the next entry then we are done */
540 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
541 if (idx
== q
->host_index
)
545 /* if the index wrapped around, toggle the valid bit */
546 if (phba
->sli4_hba
.pc_sli4_params
.cqav
&& !q
->hba_index
)
547 q
->qe_valid
= (q
->qe_valid
) ? 0 : 1;
550 * insert barrier for instruction interlock : data from the hardware
551 * must have the valid bit checked before it can be copied and acted
552 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
553 * instructions allowing action on content before valid bit checked,
554 * add barrier here as well. May not be needed as "content" is a
555 * single 32-bit entity here (vs multi word structure for cq's).
562 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
563 * @q: The Completion Queue that the host has completed processing for.
564 * @arm: Indicates whether the host wants to arms this CQ.
566 * This routine will mark all Completion queue entries on @q, from the last
567 * known completed entry to the last entry that was processed, as completed
568 * by clearing the valid bit for each completion queue entry. Then it will
569 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
570 * The internal host index in the @q will be updated by this routine to indicate
571 * that the host has finished processing the entries. The @arm parameter
572 * indicates that the queue should be rearmed when ringing the doorbell.
574 * This function will return the number of CQEs that were released.
577 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
579 uint32_t released
= 0;
580 struct lpfc_hba
*phba
;
581 struct lpfc_cqe
*temp_qe
;
582 struct lpfc_register doorbell
;
584 /* sanity check on queue memory */
589 /* while there are valid entries */
590 while (q
->hba_index
!= q
->host_index
) {
591 if (!phba
->sli4_hba
.pc_sli4_params
.cqav
) {
592 temp_qe
= q
->qe
[q
->host_index
].cqe
;
593 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
596 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
598 if (unlikely(released
== 0 && !arm
))
601 /* ring doorbell for number popped */
604 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
605 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
606 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
607 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
608 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
609 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
610 writel(doorbell
.word0
, q
->phba
->sli4_hba
.CQDBregaddr
);
615 * lpfc_sli4_if6_cq_release - Indicates the host has finished processing a CQ
616 * @q: The Completion Queue that the host has completed processing for.
617 * @arm: Indicates whether the host wants to arms this CQ.
619 * This routine will mark all Completion queue entries on @q, from the last
620 * known completed entry to the last entry that was processed, as completed
621 * by clearing the valid bit for each completion queue entry. Then it will
622 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
623 * The internal host index in the @q will be updated by this routine to indicate
624 * that the host has finished processing the entries. The @arm parameter
625 * indicates that the queue should be rearmed when ringing the doorbell.
627 * This function will return the number of CQEs that were released.
630 lpfc_sli4_if6_cq_release(struct lpfc_queue
*q
, bool arm
)
632 uint32_t released
= 0;
633 struct lpfc_hba
*phba
;
634 struct lpfc_cqe
*temp_qe
;
635 struct lpfc_register doorbell
;
637 /* sanity check on queue memory */
642 /* while there are valid entries */
643 while (q
->hba_index
!= q
->host_index
) {
644 if (!phba
->sli4_hba
.pc_sli4_params
.cqav
) {
645 temp_qe
= q
->qe
[q
->host_index
].cqe
;
646 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
649 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
651 if (unlikely(released
== 0 && !arm
))
654 /* ring doorbell for number popped */
657 bf_set(lpfc_if6_cq_doorbell_arm
, &doorbell
, 1);
658 bf_set(lpfc_if6_cq_doorbell_num_released
, &doorbell
, released
);
659 bf_set(lpfc_if6_cq_doorbell_cqid
, &doorbell
, q
->queue_id
);
660 writel(doorbell
.word0
, q
->phba
->sli4_hba
.CQDBregaddr
);
665 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
666 * @q: The Header Receive Queue to operate on.
667 * @wqe: The Receive Queue Entry to put on the Receive queue.
669 * This routine will copy the contents of @wqe to the next available entry on
670 * the @q. This function will then ring the Receive Queue Doorbell to signal the
671 * HBA to start processing the Receive Queue Entry. This function returns the
672 * index that the rqe was copied to if successful. If no entries are available
673 * on @q then this function will return -ENOMEM.
674 * The caller is expected to hold the hbalock when calling this routine.
677 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
678 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
680 struct lpfc_rqe
*temp_hrqe
;
681 struct lpfc_rqe
*temp_drqe
;
682 struct lpfc_register doorbell
;
686 /* sanity check on queue memory */
687 if (unlikely(!hq
) || unlikely(!dq
))
689 hq_put_index
= hq
->host_index
;
690 dq_put_index
= dq
->host_index
;
691 temp_hrqe
= hq
->qe
[hq_put_index
].rqe
;
692 temp_drqe
= dq
->qe
[dq_put_index
].rqe
;
694 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
696 if (hq_put_index
!= dq_put_index
)
698 /* If the host has not yet processed the next entry then we are done */
699 if (((hq_put_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
701 lpfc_sli4_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
702 lpfc_sli4_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
704 /* Update the host index to point to the next slot */
705 hq
->host_index
= ((hq_put_index
+ 1) % hq
->entry_count
);
706 dq
->host_index
= ((dq_put_index
+ 1) % dq
->entry_count
);
709 /* Ring The Header Receive Queue Doorbell */
710 if (!(hq
->host_index
% hq
->entry_repost
)) {
712 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
713 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
715 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
716 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
717 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
719 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
721 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
725 writel(doorbell
.word0
, hq
->db_regaddr
);
731 * lpfc_sli4_rq_release - Updates internal hba index for RQ
732 * @q: The Header Receive Queue to operate on.
734 * This routine will update the HBA index of a queue to reflect consumption of
735 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
736 * consumed an entry the host calls this function to update the queue's
737 * internal pointers. This routine returns the number of entries that were
738 * consumed by the HBA.
741 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
743 /* sanity check on queue memory */
744 if (unlikely(!hq
) || unlikely(!dq
))
747 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
749 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
750 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
755 * lpfc_cmd_iocb - Get next command iocb entry in the ring
756 * @phba: Pointer to HBA context object.
757 * @pring: Pointer to driver SLI ring object.
759 * This function returns pointer to next command iocb entry
760 * in the command ring. The caller must hold hbalock to prevent
761 * other threads consume the next command iocb.
762 * SLI-2/SLI-3 provide different sized iocbs.
764 static inline IOCB_t
*
765 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
767 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
768 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
772 * lpfc_resp_iocb - Get next response iocb entry in the ring
773 * @phba: Pointer to HBA context object.
774 * @pring: Pointer to driver SLI ring object.
776 * This function returns pointer to next response iocb entry
777 * in the response ring. The caller must hold hbalock to make sure
778 * that no other thread consume the next response iocb.
779 * SLI-2/SLI-3 provide different sized iocbs.
781 static inline IOCB_t
*
782 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
784 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
785 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
789 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
790 * @phba: Pointer to HBA context object.
792 * This function is called with hbalock held. This function
793 * allocates a new driver iocb object from the iocb pool. If the
794 * allocation is successful, it returns pointer to the newly
795 * allocated iocb object else it returns NULL.
798 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
800 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
801 struct lpfc_iocbq
* iocbq
= NULL
;
803 lockdep_assert_held(&phba
->hbalock
);
805 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
808 if (phba
->iocb_cnt
> phba
->iocb_max
)
809 phba
->iocb_max
= phba
->iocb_cnt
;
814 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
815 * @phba: Pointer to HBA context object.
816 * @xritag: XRI value.
818 * This function clears the sglq pointer from the array of acive
819 * sglq's. The xritag that is passed in is used to index into the
820 * array. Before the xritag can be used it needs to be adjusted
821 * by subtracting the xribase.
823 * Returns sglq ponter = success, NULL = Failure.
826 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
828 struct lpfc_sglq
*sglq
;
830 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
831 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
836 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
837 * @phba: Pointer to HBA context object.
838 * @xritag: XRI value.
840 * This function returns the sglq pointer from the array of acive
841 * sglq's. The xritag that is passed in is used to index into the
842 * array. Before the xritag can be used it needs to be adjusted
843 * by subtracting the xribase.
845 * Returns sglq ponter = success, NULL = Failure.
848 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
850 struct lpfc_sglq
*sglq
;
852 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
857 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
858 * @phba: Pointer to HBA context object.
859 * @xritag: xri used in this exchange.
860 * @rrq: The RRQ to be cleared.
864 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
866 struct lpfc_node_rrq
*rrq
)
868 struct lpfc_nodelist
*ndlp
= NULL
;
870 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
871 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
873 /* The target DID could have been swapped (cable swap)
874 * we should use the ndlp from the findnode if it is
877 if ((!ndlp
) && rrq
->ndlp
)
883 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
)) {
886 rrq
->rrq_stop_time
= 0;
889 mempool_free(rrq
, phba
->rrq_pool
);
893 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
894 * @phba: Pointer to HBA context object.
896 * This function is called with hbalock held. This function
897 * Checks if stop_time (ratov from setting rrq active) has
898 * been reached, if it has and the send_rrq flag is set then
899 * it will call lpfc_send_rrq. If the send_rrq flag is not set
900 * then it will just call the routine to clear the rrq and
901 * free the rrq resource.
902 * The timer is set to the next rrq that is going to expire before
903 * leaving the routine.
907 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
909 struct lpfc_node_rrq
*rrq
;
910 struct lpfc_node_rrq
*nextrrq
;
911 unsigned long next_time
;
912 unsigned long iflags
;
915 spin_lock_irqsave(&phba
->hbalock
, iflags
);
916 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
917 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
918 list_for_each_entry_safe(rrq
, nextrrq
,
919 &phba
->active_rrq_list
, list
) {
920 if (time_after(jiffies
, rrq
->rrq_stop_time
))
921 list_move(&rrq
->list
, &send_rrq
);
922 else if (time_before(rrq
->rrq_stop_time
, next_time
))
923 next_time
= rrq
->rrq_stop_time
;
925 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
926 if ((!list_empty(&phba
->active_rrq_list
)) &&
927 (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
928 mod_timer(&phba
->rrq_tmr
, next_time
);
929 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
930 list_del(&rrq
->list
);
932 /* this call will free the rrq */
933 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
934 else if (lpfc_send_rrq(phba
, rrq
)) {
935 /* if we send the rrq then the completion handler
936 * will clear the bit in the xribitmap.
938 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
945 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
946 * @vport: Pointer to vport context object.
947 * @xri: The xri used in the exchange.
948 * @did: The targets DID for this exchange.
950 * returns NULL = rrq not found in the phba->active_rrq_list.
951 * rrq = rrq for this xri and target.
953 struct lpfc_node_rrq
*
954 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
956 struct lpfc_hba
*phba
= vport
->phba
;
957 struct lpfc_node_rrq
*rrq
;
958 struct lpfc_node_rrq
*nextrrq
;
959 unsigned long iflags
;
961 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
963 spin_lock_irqsave(&phba
->hbalock
, iflags
);
964 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
965 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
966 rrq
->nlp_DID
== did
){
967 list_del(&rrq
->list
);
968 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
972 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
977 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
978 * @vport: Pointer to vport context object.
979 * @ndlp: Pointer to the lpfc_node_list structure.
980 * If ndlp is NULL Remove all active RRQs for this vport from the
981 * phba->active_rrq_list and clear the rrq.
982 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
985 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
988 struct lpfc_hba
*phba
= vport
->phba
;
989 struct lpfc_node_rrq
*rrq
;
990 struct lpfc_node_rrq
*nextrrq
;
991 unsigned long iflags
;
994 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
997 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
998 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
1000 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1001 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
1002 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
1003 list_move(&rrq
->list
, &rrq_list
);
1004 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1006 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
1007 list_del(&rrq
->list
);
1008 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1013 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
1014 * @phba: Pointer to HBA context object.
1015 * @ndlp: Targets nodelist pointer for this exchange.
1016 * @xritag the xri in the bitmap to test.
1018 * This function is called with hbalock held. This function
1019 * returns 0 = rrq not active for this xri
1020 * 1 = rrq is valid for this xri.
1023 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
1026 lockdep_assert_held(&phba
->hbalock
);
1029 if (!ndlp
->active_rrqs_xri_bitmap
)
1031 if (test_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
1038 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
1039 * @phba: Pointer to HBA context object.
1040 * @ndlp: nodelist pointer for this target.
1041 * @xritag: xri used in this exchange.
1042 * @rxid: Remote Exchange ID.
1043 * @send_rrq: Flag used to determine if we should send rrq els cmd.
1045 * This function takes the hbalock.
1046 * The active bit is always set in the active rrq xri_bitmap even
1047 * if there is no slot avaiable for the other rrq information.
1049 * returns 0 rrq actived for this xri
1050 * < 0 No memory or invalid ndlp.
1053 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
1054 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
1056 unsigned long iflags
;
1057 struct lpfc_node_rrq
*rrq
;
1063 if (!phba
->cfg_enable_rrq
)
1066 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1067 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1068 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
1073 * set the active bit even if there is no mem available.
1075 if (NLP_CHK_FREE_REQ(ndlp
))
1078 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
1081 if (!ndlp
->active_rrqs_xri_bitmap
)
1084 if (test_and_set_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
1087 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1088 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
1090 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1091 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
1092 " DID:0x%x Send:%d\n",
1093 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
1096 if (phba
->cfg_enable_rrq
== 1)
1097 rrq
->send_rrq
= send_rrq
;
1100 rrq
->xritag
= xritag
;
1101 rrq
->rrq_stop_time
= jiffies
+
1102 msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
1104 rrq
->nlp_DID
= ndlp
->nlp_DID
;
1105 rrq
->vport
= ndlp
->vport
;
1107 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1108 empty
= list_empty(&phba
->active_rrq_list
);
1109 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
1110 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
1112 lpfc_worker_wake_up(phba
);
1113 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1116 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1117 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
1118 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
1119 " DID:0x%x Send:%d\n",
1120 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
1125 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
1126 * @phba: Pointer to HBA context object.
1127 * @piocb: Pointer to the iocbq.
1129 * This function is called with the ring lock held. This function
1130 * gets a new driver sglq object from the sglq list. If the
1131 * list is not empty then it is successful, it returns pointer to the newly
1132 * allocated sglq object else it returns NULL.
1134 static struct lpfc_sglq
*
1135 __lpfc_sli_get_els_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
1137 struct list_head
*lpfc_els_sgl_list
= &phba
->sli4_hba
.lpfc_els_sgl_list
;
1138 struct lpfc_sglq
*sglq
= NULL
;
1139 struct lpfc_sglq
*start_sglq
= NULL
;
1140 struct lpfc_scsi_buf
*lpfc_cmd
;
1141 struct lpfc_nodelist
*ndlp
;
1144 lockdep_assert_held(&phba
->hbalock
);
1146 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
1147 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
1148 ndlp
= lpfc_cmd
->rdata
->pnode
;
1149 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
1150 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
1151 ndlp
= piocbq
->context_un
.ndlp
;
1152 } else if (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
1153 if (piocbq
->iocb_flag
& LPFC_IO_LOOPBACK
)
1156 ndlp
= piocbq
->context_un
.ndlp
;
1158 ndlp
= piocbq
->context1
;
1161 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
1162 list_remove_head(lpfc_els_sgl_list
, sglq
, struct lpfc_sglq
, list
);
1167 if (ndlp
&& ndlp
->active_rrqs_xri_bitmap
&&
1168 test_bit(sglq
->sli4_lxritag
,
1169 ndlp
->active_rrqs_xri_bitmap
)) {
1170 /* This xri has an rrq outstanding for this DID.
1171 * put it back in the list and get another xri.
1173 list_add_tail(&sglq
->list
, lpfc_els_sgl_list
);
1175 list_remove_head(lpfc_els_sgl_list
, sglq
,
1176 struct lpfc_sglq
, list
);
1177 if (sglq
== start_sglq
) {
1178 list_add_tail(&sglq
->list
, lpfc_els_sgl_list
);
1186 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
1187 sglq
->state
= SGL_ALLOCATED
;
1189 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
1194 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
1195 * @phba: Pointer to HBA context object.
1196 * @piocb: Pointer to the iocbq.
1198 * This function is called with the sgl_list lock held. This function
1199 * gets a new driver sglq object from the sglq list. If the
1200 * list is not empty then it is successful, it returns pointer to the newly
1201 * allocated sglq object else it returns NULL.
1204 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
1206 struct list_head
*lpfc_nvmet_sgl_list
;
1207 struct lpfc_sglq
*sglq
= NULL
;
1209 lpfc_nvmet_sgl_list
= &phba
->sli4_hba
.lpfc_nvmet_sgl_list
;
1211 lockdep_assert_held(&phba
->sli4_hba
.sgl_list_lock
);
1213 list_remove_head(lpfc_nvmet_sgl_list
, sglq
, struct lpfc_sglq
, list
);
1216 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
1217 sglq
->state
= SGL_ALLOCATED
;
1222 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1223 * @phba: Pointer to HBA context object.
1225 * This function is called with no lock held. This function
1226 * allocates a new driver iocb object from the iocb pool. If the
1227 * allocation is successful, it returns pointer to the newly
1228 * allocated iocb object else it returns NULL.
1231 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
1233 struct lpfc_iocbq
* iocbq
= NULL
;
1234 unsigned long iflags
;
1236 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1237 iocbq
= __lpfc_sli_get_iocbq(phba
);
1238 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1243 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1244 * @phba: Pointer to HBA context object.
1245 * @iocbq: Pointer to driver iocb object.
1247 * This function is called with hbalock held to release driver
1248 * iocb object to the iocb pool. The iotag in the iocb object
1249 * does not change for each use of the iocb object. This function
1250 * clears all other fields of the iocb object when it is freed.
1251 * The sqlq structure that holds the xritag and phys and virtual
1252 * mappings for the scatter gather list is retrieved from the
1253 * active array of sglq. The get of the sglq pointer also clears
1254 * the entry in the array. If the status of the IO indiactes that
1255 * this IO was aborted then the sglq entry it put on the
1256 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1257 * IO has good status or fails for any other reason then the sglq
1258 * entry is added to the free list (lpfc_els_sgl_list).
1261 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1263 struct lpfc_sglq
*sglq
;
1264 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1265 unsigned long iflag
= 0;
1266 struct lpfc_sli_ring
*pring
;
1268 lockdep_assert_held(&phba
->hbalock
);
1270 if (iocbq
->sli4_xritag
== NO_XRI
)
1273 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1277 if (iocbq
->iocb_flag
& LPFC_IO_NVMET
) {
1278 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1280 sglq
->state
= SGL_FREED
;
1282 list_add_tail(&sglq
->list
,
1283 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
1284 spin_unlock_irqrestore(
1285 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1289 pring
= phba
->sli4_hba
.els_wq
->pring
;
1290 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1291 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1292 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1294 list_add(&sglq
->list
,
1295 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1296 spin_unlock_irqrestore(
1297 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1299 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1301 sglq
->state
= SGL_FREED
;
1303 list_add_tail(&sglq
->list
,
1304 &phba
->sli4_hba
.lpfc_els_sgl_list
);
1305 spin_unlock_irqrestore(
1306 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1308 /* Check if TXQ queue needs to be serviced */
1309 if (!list_empty(&pring
->txq
))
1310 lpfc_worker_wake_up(phba
);
1316 * Clean all volatile data fields, preserve iotag and node struct.
1318 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1319 iocbq
->sli4_lxritag
= NO_XRI
;
1320 iocbq
->sli4_xritag
= NO_XRI
;
1321 iocbq
->iocb_flag
&= ~(LPFC_IO_NVME
| LPFC_IO_NVMET
|
1323 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1328 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1329 * @phba: Pointer to HBA context object.
1330 * @iocbq: Pointer to driver iocb object.
1332 * This function is called with hbalock held to release driver
1333 * iocb object to the iocb pool. The iotag in the iocb object
1334 * does not change for each use of the iocb object. This function
1335 * clears all other fields of the iocb object when it is freed.
1338 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1340 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1342 lockdep_assert_held(&phba
->hbalock
);
1345 * Clean all volatile data fields, preserve iotag and node struct.
1347 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1348 iocbq
->sli4_xritag
= NO_XRI
;
1349 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1353 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1354 * @phba: Pointer to HBA context object.
1355 * @iocbq: Pointer to driver iocb object.
1357 * This function is called with hbalock held to release driver
1358 * iocb object to the iocb pool. The iotag in the iocb object
1359 * does not change for each use of the iocb object. This function
1360 * clears all other fields of the iocb object when it is freed.
1363 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1365 lockdep_assert_held(&phba
->hbalock
);
1367 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1372 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1373 * @phba: Pointer to HBA context object.
1374 * @iocbq: Pointer to driver iocb object.
1376 * This function is called with no lock held to release the iocb to
1380 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1382 unsigned long iflags
;
1385 * Clean all volatile data fields, preserve iotag and node struct.
1387 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1388 __lpfc_sli_release_iocbq(phba
, iocbq
);
1389 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1393 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1394 * @phba: Pointer to HBA context object.
1395 * @iocblist: List of IOCBs.
1396 * @ulpstatus: ULP status in IOCB command field.
1397 * @ulpWord4: ULP word-4 in IOCB command field.
1399 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1400 * on the list by invoking the complete callback function associated with the
1401 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1405 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1406 uint32_t ulpstatus
, uint32_t ulpWord4
)
1408 struct lpfc_iocbq
*piocb
;
1410 while (!list_empty(iocblist
)) {
1411 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1412 if (!piocb
->iocb_cmpl
)
1413 lpfc_sli_release_iocbq(phba
, piocb
);
1415 piocb
->iocb
.ulpStatus
= ulpstatus
;
1416 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1417 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1424 * lpfc_sli_iocb_cmd_type - Get the iocb type
1425 * @iocb_cmnd: iocb command code.
1427 * This function is called by ring event handler function to get the iocb type.
1428 * This function translates the iocb command to an iocb command type used to
1429 * decide the final disposition of each completed IOCB.
1430 * The function returns
1431 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1432 * LPFC_SOL_IOCB if it is a solicited iocb completion
1433 * LPFC_ABORT_IOCB if it is an abort iocb
1434 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1436 * The caller is not required to hold any lock.
1438 static lpfc_iocb_type
1439 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1441 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1443 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1446 switch (iocb_cmnd
) {
1447 case CMD_XMIT_SEQUENCE_CR
:
1448 case CMD_XMIT_SEQUENCE_CX
:
1449 case CMD_XMIT_BCAST_CN
:
1450 case CMD_XMIT_BCAST_CX
:
1451 case CMD_ELS_REQUEST_CR
:
1452 case CMD_ELS_REQUEST_CX
:
1453 case CMD_CREATE_XRI_CR
:
1454 case CMD_CREATE_XRI_CX
:
1455 case CMD_GET_RPI_CN
:
1456 case CMD_XMIT_ELS_RSP_CX
:
1457 case CMD_GET_RPI_CR
:
1458 case CMD_FCP_IWRITE_CR
:
1459 case CMD_FCP_IWRITE_CX
:
1460 case CMD_FCP_IREAD_CR
:
1461 case CMD_FCP_IREAD_CX
:
1462 case CMD_FCP_ICMND_CR
:
1463 case CMD_FCP_ICMND_CX
:
1464 case CMD_FCP_TSEND_CX
:
1465 case CMD_FCP_TRSP_CX
:
1466 case CMD_FCP_TRECEIVE_CX
:
1467 case CMD_FCP_AUTO_TRSP_CX
:
1468 case CMD_ADAPTER_MSG
:
1469 case CMD_ADAPTER_DUMP
:
1470 case CMD_XMIT_SEQUENCE64_CR
:
1471 case CMD_XMIT_SEQUENCE64_CX
:
1472 case CMD_XMIT_BCAST64_CN
:
1473 case CMD_XMIT_BCAST64_CX
:
1474 case CMD_ELS_REQUEST64_CR
:
1475 case CMD_ELS_REQUEST64_CX
:
1476 case CMD_FCP_IWRITE64_CR
:
1477 case CMD_FCP_IWRITE64_CX
:
1478 case CMD_FCP_IREAD64_CR
:
1479 case CMD_FCP_IREAD64_CX
:
1480 case CMD_FCP_ICMND64_CR
:
1481 case CMD_FCP_ICMND64_CX
:
1482 case CMD_FCP_TSEND64_CX
:
1483 case CMD_FCP_TRSP64_CX
:
1484 case CMD_FCP_TRECEIVE64_CX
:
1485 case CMD_GEN_REQUEST64_CR
:
1486 case CMD_GEN_REQUEST64_CX
:
1487 case CMD_XMIT_ELS_RSP64_CX
:
1488 case DSSCMD_IWRITE64_CR
:
1489 case DSSCMD_IWRITE64_CX
:
1490 case DSSCMD_IREAD64_CR
:
1491 case DSSCMD_IREAD64_CX
:
1492 type
= LPFC_SOL_IOCB
;
1494 case CMD_ABORT_XRI_CN
:
1495 case CMD_ABORT_XRI_CX
:
1496 case CMD_CLOSE_XRI_CN
:
1497 case CMD_CLOSE_XRI_CX
:
1498 case CMD_XRI_ABORTED_CX
:
1499 case CMD_ABORT_MXRI64_CN
:
1500 case CMD_XMIT_BLS_RSP64_CX
:
1501 type
= LPFC_ABORT_IOCB
;
1503 case CMD_RCV_SEQUENCE_CX
:
1504 case CMD_RCV_ELS_REQ_CX
:
1505 case CMD_RCV_SEQUENCE64_CX
:
1506 case CMD_RCV_ELS_REQ64_CX
:
1507 case CMD_ASYNC_STATUS
:
1508 case CMD_IOCB_RCV_SEQ64_CX
:
1509 case CMD_IOCB_RCV_ELS64_CX
:
1510 case CMD_IOCB_RCV_CONT64_CX
:
1511 case CMD_IOCB_RET_XRI64_CX
:
1512 type
= LPFC_UNSOL_IOCB
;
1514 case CMD_IOCB_XMIT_MSEQ64_CR
:
1515 case CMD_IOCB_XMIT_MSEQ64_CX
:
1516 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1517 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1518 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1519 case CMD_IOCB_ABORT_EXTENDED_CN
:
1520 case CMD_IOCB_RET_HBQE64_CN
:
1521 case CMD_IOCB_FCP_IBIDIR64_CR
:
1522 case CMD_IOCB_FCP_IBIDIR64_CX
:
1523 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1524 case CMD_IOCB_LOGENTRY_CN
:
1525 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1526 printk("%s - Unhandled SLI-3 Command x%x\n",
1527 __func__
, iocb_cmnd
);
1528 type
= LPFC_UNKNOWN_IOCB
;
1531 type
= LPFC_UNKNOWN_IOCB
;
1539 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1540 * @phba: Pointer to HBA context object.
1542 * This function is called from SLI initialization code
1543 * to configure every ring of the HBA's SLI interface. The
1544 * caller is not required to hold any lock. This function issues
1545 * a config_ring mailbox command for each ring.
1546 * This function returns zero if successful else returns a negative
1550 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1552 struct lpfc_sli
*psli
= &phba
->sli
;
1557 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1561 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1562 for (i
= 0; i
< psli
->num_rings
; i
++) {
1563 lpfc_config_ring(phba
, i
, pmb
);
1564 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1565 if (rc
!= MBX_SUCCESS
) {
1566 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1567 "0446 Adapter failed to init (%d), "
1568 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1570 rc
, pmbox
->mbxCommand
,
1571 pmbox
->mbxStatus
, i
);
1572 phba
->link_state
= LPFC_HBA_ERROR
;
1577 mempool_free(pmb
, phba
->mbox_mem_pool
);
1582 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1583 * @phba: Pointer to HBA context object.
1584 * @pring: Pointer to driver SLI ring object.
1585 * @piocb: Pointer to the driver iocb object.
1587 * This function is called with hbalock held. The function adds the
1588 * new iocb to txcmplq of the given ring. This function always returns
1589 * 0. If this function is called for ELS ring, this function checks if
1590 * there is a vport associated with the ELS command. This function also
1591 * starts els_tmofunc timer if this is an ELS command.
1594 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1595 struct lpfc_iocbq
*piocb
)
1597 lockdep_assert_held(&phba
->hbalock
);
1601 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1602 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1604 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1605 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1606 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1607 BUG_ON(!piocb
->vport
);
1608 if (!(piocb
->vport
->load_flag
& FC_UNLOADING
))
1609 mod_timer(&piocb
->vport
->els_tmofunc
,
1611 msecs_to_jiffies(1000 * (phba
->fc_ratov
<< 1)));
1618 * lpfc_sli_ringtx_get - Get first element of the txq
1619 * @phba: Pointer to HBA context object.
1620 * @pring: Pointer to driver SLI ring object.
1622 * This function is called with hbalock held to get next
1623 * iocb in txq of the given ring. If there is any iocb in
1624 * the txq, the function returns first iocb in the list after
1625 * removing the iocb from the list, else it returns NULL.
1628 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1630 struct lpfc_iocbq
*cmd_iocb
;
1632 lockdep_assert_held(&phba
->hbalock
);
1634 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1639 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1640 * @phba: Pointer to HBA context object.
1641 * @pring: Pointer to driver SLI ring object.
1643 * This function is called with hbalock held and the caller must post the
1644 * iocb without releasing the lock. If the caller releases the lock,
1645 * iocb slot returned by the function is not guaranteed to be available.
1646 * The function returns pointer to the next available iocb slot if there
1647 * is available slot in the ring, else it returns NULL.
1648 * If the get index of the ring is ahead of the put index, the function
1649 * will post an error attention event to the worker thread to take the
1650 * HBA to offline state.
1653 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1655 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1656 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1658 lockdep_assert_held(&phba
->hbalock
);
1660 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1661 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1662 pring
->sli
.sli3
.next_cmdidx
= 0;
1664 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1665 pring
->sli
.sli3
.next_cmdidx
)) {
1667 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1669 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1670 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1671 "0315 Ring %d issue: portCmdGet %d "
1672 "is bigger than cmd ring %d\n",
1674 pring
->sli
.sli3
.local_getidx
,
1677 phba
->link_state
= LPFC_HBA_ERROR
;
1679 * All error attention handlers are posted to
1682 phba
->work_ha
|= HA_ERATT
;
1683 phba
->work_hs
= HS_FFER3
;
1685 lpfc_worker_wake_up(phba
);
1690 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1694 return lpfc_cmd_iocb(phba
, pring
);
1698 * lpfc_sli_next_iotag - Get an iotag for the iocb
1699 * @phba: Pointer to HBA context object.
1700 * @iocbq: Pointer to driver iocb object.
1702 * This function gets an iotag for the iocb. If there is no unused iotag and
1703 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1704 * array and assigns a new iotag.
1705 * The function returns the allocated iotag if successful, else returns zero.
1706 * Zero is not a valid iotag.
1707 * The caller is not required to hold any lock.
1710 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1712 struct lpfc_iocbq
**new_arr
;
1713 struct lpfc_iocbq
**old_arr
;
1715 struct lpfc_sli
*psli
= &phba
->sli
;
1718 spin_lock_irq(&phba
->hbalock
);
1719 iotag
= psli
->last_iotag
;
1720 if(++iotag
< psli
->iocbq_lookup_len
) {
1721 psli
->last_iotag
= iotag
;
1722 psli
->iocbq_lookup
[iotag
] = iocbq
;
1723 spin_unlock_irq(&phba
->hbalock
);
1724 iocbq
->iotag
= iotag
;
1726 } else if (psli
->iocbq_lookup_len
< (0xffff
1727 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1728 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1729 spin_unlock_irq(&phba
->hbalock
);
1730 new_arr
= kcalloc(new_len
, sizeof(struct lpfc_iocbq
*),
1733 spin_lock_irq(&phba
->hbalock
);
1734 old_arr
= psli
->iocbq_lookup
;
1735 if (new_len
<= psli
->iocbq_lookup_len
) {
1736 /* highly unprobable case */
1738 iotag
= psli
->last_iotag
;
1739 if(++iotag
< psli
->iocbq_lookup_len
) {
1740 psli
->last_iotag
= iotag
;
1741 psli
->iocbq_lookup
[iotag
] = iocbq
;
1742 spin_unlock_irq(&phba
->hbalock
);
1743 iocbq
->iotag
= iotag
;
1746 spin_unlock_irq(&phba
->hbalock
);
1749 if (psli
->iocbq_lookup
)
1750 memcpy(new_arr
, old_arr
,
1751 ((psli
->last_iotag
+ 1) *
1752 sizeof (struct lpfc_iocbq
*)));
1753 psli
->iocbq_lookup
= new_arr
;
1754 psli
->iocbq_lookup_len
= new_len
;
1755 psli
->last_iotag
= iotag
;
1756 psli
->iocbq_lookup
[iotag
] = iocbq
;
1757 spin_unlock_irq(&phba
->hbalock
);
1758 iocbq
->iotag
= iotag
;
1763 spin_unlock_irq(&phba
->hbalock
);
1765 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1766 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1773 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1774 * @phba: Pointer to HBA context object.
1775 * @pring: Pointer to driver SLI ring object.
1776 * @iocb: Pointer to iocb slot in the ring.
1777 * @nextiocb: Pointer to driver iocb object which need to be
1778 * posted to firmware.
1780 * This function is called with hbalock held to post a new iocb to
1781 * the firmware. This function copies the new iocb to ring iocb slot and
1782 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1783 * a completion call back for this iocb else the function will free the
1787 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1788 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1790 lockdep_assert_held(&phba
->hbalock
);
1794 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1797 if (pring
->ringno
== LPFC_ELS_RING
) {
1798 lpfc_debugfs_slow_ring_trc(phba
,
1799 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1800 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1801 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1802 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1806 * Issue iocb command to adapter
1808 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1810 pring
->stats
.iocb_cmd
++;
1813 * If there is no completion routine to call, we can release the
1814 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1815 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1817 if (nextiocb
->iocb_cmpl
)
1818 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1820 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1823 * Let the HBA know what IOCB slot will be the next one the
1824 * driver will put a command into.
1826 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1827 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1831 * lpfc_sli_update_full_ring - Update the chip attention register
1832 * @phba: Pointer to HBA context object.
1833 * @pring: Pointer to driver SLI ring object.
1835 * The caller is not required to hold any lock for calling this function.
1836 * This function updates the chip attention bits for the ring to inform firmware
1837 * that there are pending work to be done for this ring and requests an
1838 * interrupt when there is space available in the ring. This function is
1839 * called when the driver is unable to post more iocbs to the ring due
1840 * to unavailability of space in the ring.
1843 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1845 int ringno
= pring
->ringno
;
1847 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1852 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1853 * The HBA will tell us when an IOCB entry is available.
1855 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1856 readl(phba
->CAregaddr
); /* flush */
1858 pring
->stats
.iocb_cmd_full
++;
1862 * lpfc_sli_update_ring - Update chip attention register
1863 * @phba: Pointer to HBA context object.
1864 * @pring: Pointer to driver SLI ring object.
1866 * This function updates the chip attention register bit for the
1867 * given ring to inform HBA that there is more work to be done
1868 * in this ring. The caller is not required to hold any lock.
1871 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1873 int ringno
= pring
->ringno
;
1876 * Tell the HBA that there is work to do in this ring.
1878 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1880 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1881 readl(phba
->CAregaddr
); /* flush */
1886 * lpfc_sli_resume_iocb - Process iocbs in the txq
1887 * @phba: Pointer to HBA context object.
1888 * @pring: Pointer to driver SLI ring object.
1890 * This function is called with hbalock held to post pending iocbs
1891 * in the txq to the firmware. This function is called when driver
1892 * detects space available in the ring.
1895 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1898 struct lpfc_iocbq
*nextiocb
;
1900 lockdep_assert_held(&phba
->hbalock
);
1904 * (a) there is anything on the txq to send
1906 * (c) link attention events can be processed (fcp ring only)
1907 * (d) IOCB processing is not blocked by the outstanding mbox command.
1910 if (lpfc_is_link_up(phba
) &&
1911 (!list_empty(&pring
->txq
)) &&
1912 (pring
->ringno
!= LPFC_FCP_RING
||
1913 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1915 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1916 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1917 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1920 lpfc_sli_update_ring(phba
, pring
);
1922 lpfc_sli_update_full_ring(phba
, pring
);
1929 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1930 * @phba: Pointer to HBA context object.
1931 * @hbqno: HBQ number.
1933 * This function is called with hbalock held to get the next
1934 * available slot for the given HBQ. If there is free slot
1935 * available for the HBQ it will return pointer to the next available
1936 * HBQ entry else it will return NULL.
1938 static struct lpfc_hbq_entry
*
1939 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1941 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1943 lockdep_assert_held(&phba
->hbalock
);
1945 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1946 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1947 hbqp
->next_hbqPutIdx
= 0;
1949 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1950 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1951 uint32_t getidx
= le32_to_cpu(raw_index
);
1953 hbqp
->local_hbqGetIdx
= getidx
;
1955 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1956 lpfc_printf_log(phba
, KERN_ERR
,
1957 LOG_SLI
| LOG_VPORT
,
1958 "1802 HBQ %d: local_hbqGetIdx "
1959 "%u is > than hbqp->entry_count %u\n",
1960 hbqno
, hbqp
->local_hbqGetIdx
,
1963 phba
->link_state
= LPFC_HBA_ERROR
;
1967 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1971 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1976 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1977 * @phba: Pointer to HBA context object.
1979 * This function is called with no lock held to free all the
1980 * hbq buffers while uninitializing the SLI interface. It also
1981 * frees the HBQ buffers returned by the firmware but not yet
1982 * processed by the upper layers.
1985 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1987 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1988 struct hbq_dmabuf
*hbq_buf
;
1989 unsigned long flags
;
1992 hbq_count
= lpfc_sli_hbq_count();
1993 /* Return all memory used by all HBQs */
1994 spin_lock_irqsave(&phba
->hbalock
, flags
);
1995 for (i
= 0; i
< hbq_count
; ++i
) {
1996 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1997 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1998 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1999 list_del(&hbq_buf
->dbuf
.list
);
2000 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
2002 phba
->hbqs
[i
].buffer_count
= 0;
2005 /* Mark the HBQs not in use */
2006 phba
->hbq_in_use
= 0;
2007 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2011 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
2012 * @phba: Pointer to HBA context object.
2013 * @hbqno: HBQ number.
2014 * @hbq_buf: Pointer to HBQ buffer.
2016 * This function is called with the hbalock held to post a
2017 * hbq buffer to the firmware. If the function finds an empty
2018 * slot in the HBQ, it will post the buffer. The function will return
2019 * pointer to the hbq entry if it successfully post the buffer
2020 * else it will return NULL.
2023 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
2024 struct hbq_dmabuf
*hbq_buf
)
2026 lockdep_assert_held(&phba
->hbalock
);
2027 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
2031 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
2032 * @phba: Pointer to HBA context object.
2033 * @hbqno: HBQ number.
2034 * @hbq_buf: Pointer to HBQ buffer.
2036 * This function is called with the hbalock held to post a hbq buffer to the
2037 * firmware. If the function finds an empty slot in the HBQ, it will post the
2038 * buffer and place it on the hbq_buffer_list. The function will return zero if
2039 * it successfully post the buffer else it will return an error.
2042 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
2043 struct hbq_dmabuf
*hbq_buf
)
2045 struct lpfc_hbq_entry
*hbqe
;
2046 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
2048 lockdep_assert_held(&phba
->hbalock
);
2049 /* Get next HBQ entry slot to use */
2050 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
2052 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
2054 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
2055 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
2056 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->total_size
;
2057 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
2058 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
2059 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
2061 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
2062 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
2064 readl(phba
->hbq_put
+ hbqno
);
2065 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
2072 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
2073 * @phba: Pointer to HBA context object.
2074 * @hbqno: HBQ number.
2075 * @hbq_buf: Pointer to HBQ buffer.
2077 * This function is called with the hbalock held to post an RQE to the SLI4
2078 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
2079 * the hbq_buffer_list and return zero, otherwise it will return an error.
2082 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
2083 struct hbq_dmabuf
*hbq_buf
)
2086 struct lpfc_rqe hrqe
;
2087 struct lpfc_rqe drqe
;
2088 struct lpfc_queue
*hrq
;
2089 struct lpfc_queue
*drq
;
2091 if (hbqno
!= LPFC_ELS_HBQ
)
2093 hrq
= phba
->sli4_hba
.hdr_rq
;
2094 drq
= phba
->sli4_hba
.dat_rq
;
2096 lockdep_assert_held(&phba
->hbalock
);
2097 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
2098 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
2099 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
2100 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
2101 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
2104 hbq_buf
->tag
= (rc
| (hbqno
<< 16));
2105 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
2109 /* HBQ for ELS and CT traffic. */
2110 static struct lpfc_hbq_init lpfc_els_hbq
= {
2115 .ring_mask
= (1 << LPFC_ELS_RING
),
2122 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
2127 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
2128 * @phba: Pointer to HBA context object.
2129 * @hbqno: HBQ number.
2130 * @count: Number of HBQ buffers to be posted.
2132 * This function is called with no lock held to post more hbq buffers to the
2133 * given HBQ. The function returns the number of HBQ buffers successfully
2137 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
2139 uint32_t i
, posted
= 0;
2140 unsigned long flags
;
2141 struct hbq_dmabuf
*hbq_buffer
;
2142 LIST_HEAD(hbq_buf_list
);
2143 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
2146 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
2147 lpfc_hbq_defs
[hbqno
]->entry_count
)
2148 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
2149 phba
->hbqs
[hbqno
].buffer_count
;
2152 /* Allocate HBQ entries */
2153 for (i
= 0; i
< count
; i
++) {
2154 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
2157 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
2159 /* Check whether HBQ is still in use */
2160 spin_lock_irqsave(&phba
->hbalock
, flags
);
2161 if (!phba
->hbq_in_use
)
2163 while (!list_empty(&hbq_buf_list
)) {
2164 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
2166 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
2168 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
2169 phba
->hbqs
[hbqno
].buffer_count
++;
2172 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2174 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2177 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2178 while (!list_empty(&hbq_buf_list
)) {
2179 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
2181 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2187 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
2188 * @phba: Pointer to HBA context object.
2191 * This function posts more buffers to the HBQ. This function
2192 * is called with no lock held. The function returns the number of HBQ entries
2193 * successfully allocated.
2196 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
2198 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2201 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2202 lpfc_hbq_defs
[qno
]->add_count
);
2206 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2207 * @phba: Pointer to HBA context object.
2208 * @qno: HBQ queue number.
2210 * This function is called from SLI initialization code path with
2211 * no lock held to post initial HBQ buffers to firmware. The
2212 * function returns the number of HBQ entries successfully allocated.
2215 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
2217 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2218 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2219 lpfc_hbq_defs
[qno
]->entry_count
);
2221 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2222 lpfc_hbq_defs
[qno
]->init_count
);
2226 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2227 * @phba: Pointer to HBA context object.
2228 * @hbqno: HBQ number.
2230 * This function removes the first hbq buffer on an hbq list and returns a
2231 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2233 static struct hbq_dmabuf
*
2234 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
2236 struct lpfc_dmabuf
*d_buf
;
2238 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
2241 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2245 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2246 * @phba: Pointer to HBA context object.
2247 * @hbqno: HBQ number.
2249 * This function removes the first RQ buffer on an RQ buffer list and returns a
2250 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2252 static struct rqb_dmabuf
*
2253 lpfc_sli_rqbuf_get(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
)
2255 struct lpfc_dmabuf
*h_buf
;
2256 struct lpfc_rqb
*rqbp
;
2259 list_remove_head(&rqbp
->rqb_buffer_list
, h_buf
,
2260 struct lpfc_dmabuf
, list
);
2263 rqbp
->buffer_count
--;
2264 return container_of(h_buf
, struct rqb_dmabuf
, hbuf
);
2268 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2269 * @phba: Pointer to HBA context object.
2270 * @tag: Tag of the hbq buffer.
2272 * This function searches for the hbq buffer associated with the given tag in
2273 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2274 * otherwise it returns NULL.
2276 static struct hbq_dmabuf
*
2277 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
2279 struct lpfc_dmabuf
*d_buf
;
2280 struct hbq_dmabuf
*hbq_buf
;
2284 if (hbqno
>= LPFC_MAX_HBQS
)
2287 spin_lock_irq(&phba
->hbalock
);
2288 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2289 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2290 if (hbq_buf
->tag
== tag
) {
2291 spin_unlock_irq(&phba
->hbalock
);
2295 spin_unlock_irq(&phba
->hbalock
);
2296 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2297 "1803 Bad hbq tag. Data: x%x x%x\n",
2298 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2303 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2304 * @phba: Pointer to HBA context object.
2305 * @hbq_buffer: Pointer to HBQ buffer.
2307 * This function is called with hbalock. This function gives back
2308 * the hbq buffer to firmware. If the HBQ does not have space to
2309 * post the buffer, it will free the buffer.
2312 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2317 hbqno
= hbq_buffer
->tag
>> 16;
2318 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2319 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2324 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2325 * @mbxCommand: mailbox command code.
2327 * This function is called by the mailbox event handler function to verify
2328 * that the completed mailbox command is a legitimate mailbox command. If the
2329 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2330 * and the mailbox event handler will take the HBA offline.
2333 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2337 switch (mbxCommand
) {
2341 case MBX_WRITE_VPARMS
:
2342 case MBX_RUN_BIU_DIAG
:
2345 case MBX_CONFIG_LINK
:
2346 case MBX_CONFIG_RING
:
2347 case MBX_RESET_RING
:
2348 case MBX_READ_CONFIG
:
2349 case MBX_READ_RCONFIG
:
2350 case MBX_READ_SPARM
:
2351 case MBX_READ_STATUS
:
2355 case MBX_READ_LNK_STAT
:
2357 case MBX_UNREG_LOGIN
:
2359 case MBX_DUMP_MEMORY
:
2360 case MBX_DUMP_CONTEXT
:
2363 case MBX_UPDATE_CFG
:
2365 case MBX_DEL_LD_ENTRY
:
2366 case MBX_RUN_PROGRAM
:
2368 case MBX_SET_VARIABLE
:
2369 case MBX_UNREG_D_ID
:
2370 case MBX_KILL_BOARD
:
2371 case MBX_CONFIG_FARP
:
2374 case MBX_RUN_BIU_DIAG64
:
2375 case MBX_CONFIG_PORT
:
2376 case MBX_READ_SPARM64
:
2377 case MBX_READ_RPI64
:
2378 case MBX_REG_LOGIN64
:
2379 case MBX_READ_TOPOLOGY
:
2382 case MBX_LOAD_EXP_ROM
:
2383 case MBX_ASYNCEVT_ENABLE
:
2387 case MBX_PORT_CAPABILITIES
:
2388 case MBX_PORT_IOV_CONTROL
:
2389 case MBX_SLI4_CONFIG
:
2390 case MBX_SLI4_REQ_FTRS
:
2392 case MBX_UNREG_FCFI
:
2397 case MBX_RESUME_RPI
:
2398 case MBX_READ_EVENT_LOG_STATUS
:
2399 case MBX_READ_EVENT_LOG
:
2400 case MBX_SECURITY_MGMT
:
2402 case MBX_ACCESS_VDATA
:
2413 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2414 * @phba: Pointer to HBA context object.
2415 * @pmboxq: Pointer to mailbox command.
2417 * This is completion handler function for mailbox commands issued from
2418 * lpfc_sli_issue_mbox_wait function. This function is called by the
2419 * mailbox event handler function with no lock held. This function
2420 * will wake up thread waiting on the wait queue pointed by context1
2424 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2426 unsigned long drvr_flag
;
2427 struct completion
*pmbox_done
;
2430 * If pmbox_done is empty, the driver thread gave up waiting and
2431 * continued running.
2433 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2434 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2435 pmbox_done
= (struct completion
*)pmboxq
->context3
;
2437 complete(pmbox_done
);
2438 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2444 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2445 * @phba: Pointer to HBA context object.
2446 * @pmb: Pointer to mailbox object.
2448 * This function is the default mailbox completion handler. It
2449 * frees the memory resources associated with the completed mailbox
2450 * command. If the completed command is a REG_LOGIN mailbox command,
2451 * this function will issue a UREG_LOGIN to re-claim the RPI.
2454 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2456 struct lpfc_vport
*vport
= pmb
->vport
;
2457 struct lpfc_dmabuf
*mp
;
2458 struct lpfc_nodelist
*ndlp
;
2459 struct Scsi_Host
*shost
;
2463 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2466 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2471 * If a REG_LOGIN succeeded after node is destroyed or node
2472 * is in re-discovery driver need to cleanup the RPI.
2474 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2475 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2476 !pmb
->u
.mb
.mbxStatus
) {
2477 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2478 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2479 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2481 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2482 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2483 if (rc
!= MBX_NOT_FINISHED
)
2487 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2488 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2489 !pmb
->u
.mb
.mbxStatus
) {
2490 shost
= lpfc_shost_from_vport(vport
);
2491 spin_lock_irq(shost
->host_lock
);
2492 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2493 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2494 spin_unlock_irq(shost
->host_lock
);
2497 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2498 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2500 pmb
->context2
= NULL
;
2503 /* Check security permission status on INIT_LINK mailbox command */
2504 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2505 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2506 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2507 "2860 SLI authentication is required "
2508 "for INIT_LINK but has not done yet\n");
2510 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2511 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2513 mempool_free(pmb
, phba
->mbox_mem_pool
);
2516 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2517 * @phba: Pointer to HBA context object.
2518 * @pmb: Pointer to mailbox object.
2520 * This function is the unreg rpi mailbox completion handler. It
2521 * frees the memory resources associated with the completed mailbox
2522 * command. An additional refrenece is put on the ndlp to prevent
2523 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2524 * the unreg mailbox command completes, this routine puts the
2529 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2531 struct lpfc_vport
*vport
= pmb
->vport
;
2532 struct lpfc_nodelist
*ndlp
;
2534 ndlp
= pmb
->context1
;
2535 if (pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) {
2536 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2537 (bf_get(lpfc_sli_intf_if_type
,
2538 &phba
->sli4_hba
.sli_intf
) >=
2539 LPFC_SLI_INTF_IF_TYPE_2
)) {
2541 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
2542 "0010 UNREG_LOGIN vpi:%x "
2543 "rpi:%x DID:%x map:%x %p\n",
2544 vport
->vpi
, ndlp
->nlp_rpi
,
2546 ndlp
->nlp_usg_map
, ndlp
);
2547 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2553 mempool_free(pmb
, phba
->mbox_mem_pool
);
2557 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2558 * @phba: Pointer to HBA context object.
2560 * This function is called with no lock held. This function processes all
2561 * the completed mailbox commands and gives it to upper layers. The interrupt
2562 * service routine processes mailbox completion interrupt and adds completed
2563 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2564 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2565 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2566 * function returns the mailbox commands to the upper layer by calling the
2567 * completion handler function of each mailbox.
2570 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2577 phba
->sli
.slistat
.mbox_event
++;
2579 /* Get all completed mailboxe buffers into the cmplq */
2580 spin_lock_irq(&phba
->hbalock
);
2581 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2582 spin_unlock_irq(&phba
->hbalock
);
2584 /* Get a Mailbox buffer to setup mailbox commands for callback */
2586 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2592 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2594 lpfc_debugfs_disc_trc(pmb
->vport
,
2595 LPFC_DISC_TRC_MBOX_VPORT
,
2596 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2597 (uint32_t)pmbox
->mbxCommand
,
2598 pmbox
->un
.varWords
[0],
2599 pmbox
->un
.varWords
[1]);
2602 lpfc_debugfs_disc_trc(phba
->pport
,
2604 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2605 (uint32_t)pmbox
->mbxCommand
,
2606 pmbox
->un
.varWords
[0],
2607 pmbox
->un
.varWords
[1]);
2612 * It is a fatal error if unknown mbox command completion.
2614 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2616 /* Unknown mailbox command compl */
2617 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2618 "(%d):0323 Unknown Mailbox command "
2619 "x%x (x%x/x%x) Cmpl\n",
2620 pmb
->vport
? pmb
->vport
->vpi
: 0,
2622 lpfc_sli_config_mbox_subsys_get(phba
,
2624 lpfc_sli_config_mbox_opcode_get(phba
,
2626 phba
->link_state
= LPFC_HBA_ERROR
;
2627 phba
->work_hs
= HS_FFER3
;
2628 lpfc_handle_eratt(phba
);
2632 if (pmbox
->mbxStatus
) {
2633 phba
->sli
.slistat
.mbox_stat_err
++;
2634 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2635 /* Mbox cmd cmpl error - RETRYing */
2636 lpfc_printf_log(phba
, KERN_INFO
,
2638 "(%d):0305 Mbox cmd cmpl "
2639 "error - RETRYing Data: x%x "
2640 "(x%x/x%x) x%x x%x x%x\n",
2641 pmb
->vport
? pmb
->vport
->vpi
: 0,
2643 lpfc_sli_config_mbox_subsys_get(phba
,
2645 lpfc_sli_config_mbox_opcode_get(phba
,
2648 pmbox
->un
.varWords
[0],
2649 pmb
->vport
->port_state
);
2650 pmbox
->mbxStatus
= 0;
2651 pmbox
->mbxOwner
= OWN_HOST
;
2652 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2653 if (rc
!= MBX_NOT_FINISHED
)
2658 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2659 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2660 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2661 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2663 pmb
->vport
? pmb
->vport
->vpi
: 0,
2665 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2666 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2668 *((uint32_t *) pmbox
),
2669 pmbox
->un
.varWords
[0],
2670 pmbox
->un
.varWords
[1],
2671 pmbox
->un
.varWords
[2],
2672 pmbox
->un
.varWords
[3],
2673 pmbox
->un
.varWords
[4],
2674 pmbox
->un
.varWords
[5],
2675 pmbox
->un
.varWords
[6],
2676 pmbox
->un
.varWords
[7],
2677 pmbox
->un
.varWords
[8],
2678 pmbox
->un
.varWords
[9],
2679 pmbox
->un
.varWords
[10]);
2682 pmb
->mbox_cmpl(phba
,pmb
);
2688 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2689 * @phba: Pointer to HBA context object.
2690 * @pring: Pointer to driver SLI ring object.
2693 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2694 * is set in the tag the buffer is posted for a particular exchange,
2695 * the function will return the buffer without replacing the buffer.
2696 * If the buffer is for unsolicited ELS or CT traffic, this function
2697 * returns the buffer and also posts another buffer to the firmware.
2699 static struct lpfc_dmabuf
*
2700 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2701 struct lpfc_sli_ring
*pring
,
2704 struct hbq_dmabuf
*hbq_entry
;
2706 if (tag
& QUE_BUFTAG_BIT
)
2707 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2708 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2711 return &hbq_entry
->dbuf
;
2715 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2716 * @phba: Pointer to HBA context object.
2717 * @pring: Pointer to driver SLI ring object.
2718 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2719 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2720 * @fch_type: the type for the first frame of the sequence.
2722 * This function is called with no lock held. This function uses the r_ctl and
2723 * type of the received sequence to find the correct callback function to call
2724 * to process the sequence.
2727 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2728 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2735 lpfc_nvmet_unsol_ls_event(phba
, pring
, saveq
);
2741 /* unSolicited Responses */
2742 if (pring
->prt
[0].profile
) {
2743 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2744 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2748 /* We must search, based on rctl / type
2749 for the right routine */
2750 for (i
= 0; i
< pring
->num_mask
; i
++) {
2751 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2752 (pring
->prt
[i
].type
== fch_type
)) {
2753 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2754 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2755 (phba
, pring
, saveq
);
2763 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2764 * @phba: Pointer to HBA context object.
2765 * @pring: Pointer to driver SLI ring object.
2766 * @saveq: Pointer to the unsolicited iocb.
2768 * This function is called with no lock held by the ring event handler
2769 * when there is an unsolicited iocb posted to the response ring by the
2770 * firmware. This function gets the buffer associated with the iocbs
2771 * and calls the event handler for the ring. This function handles both
2772 * qring buffers and hbq buffers.
2773 * When the function returns 1 the caller can free the iocb object otherwise
2774 * upper layer functions will free the iocb objects.
2777 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2778 struct lpfc_iocbq
*saveq
)
2782 uint32_t Rctl
, Type
;
2783 struct lpfc_iocbq
*iocbq
;
2784 struct lpfc_dmabuf
*dmzbuf
;
2786 irsp
= &(saveq
->iocb
);
2788 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2789 if (pring
->lpfc_sli_rcv_async_status
)
2790 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2792 lpfc_printf_log(phba
,
2795 "0316 Ring %d handler: unexpected "
2796 "ASYNC_STATUS iocb received evt_code "
2799 irsp
->un
.asyncstat
.evt_code
);
2803 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2804 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2805 if (irsp
->ulpBdeCount
> 0) {
2806 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2807 irsp
->un
.ulpWord
[3]);
2808 lpfc_in_buf_free(phba
, dmzbuf
);
2811 if (irsp
->ulpBdeCount
> 1) {
2812 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2813 irsp
->unsli3
.sli3Words
[3]);
2814 lpfc_in_buf_free(phba
, dmzbuf
);
2817 if (irsp
->ulpBdeCount
> 2) {
2818 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2819 irsp
->unsli3
.sli3Words
[7]);
2820 lpfc_in_buf_free(phba
, dmzbuf
);
2826 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2827 if (irsp
->ulpBdeCount
!= 0) {
2828 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2829 irsp
->un
.ulpWord
[3]);
2830 if (!saveq
->context2
)
2831 lpfc_printf_log(phba
,
2834 "0341 Ring %d Cannot find buffer for "
2835 "an unsolicited iocb. tag 0x%x\n",
2837 irsp
->un
.ulpWord
[3]);
2839 if (irsp
->ulpBdeCount
== 2) {
2840 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2841 irsp
->unsli3
.sli3Words
[7]);
2842 if (!saveq
->context3
)
2843 lpfc_printf_log(phba
,
2846 "0342 Ring %d Cannot find buffer for an"
2847 " unsolicited iocb. tag 0x%x\n",
2849 irsp
->unsli3
.sli3Words
[7]);
2851 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2852 irsp
= &(iocbq
->iocb
);
2853 if (irsp
->ulpBdeCount
!= 0) {
2854 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2855 irsp
->un
.ulpWord
[3]);
2856 if (!iocbq
->context2
)
2857 lpfc_printf_log(phba
,
2860 "0343 Ring %d Cannot find "
2861 "buffer for an unsolicited iocb"
2862 ". tag 0x%x\n", pring
->ringno
,
2863 irsp
->un
.ulpWord
[3]);
2865 if (irsp
->ulpBdeCount
== 2) {
2866 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2867 irsp
->unsli3
.sli3Words
[7]);
2868 if (!iocbq
->context3
)
2869 lpfc_printf_log(phba
,
2872 "0344 Ring %d Cannot find "
2873 "buffer for an unsolicited "
2876 irsp
->unsli3
.sli3Words
[7]);
2880 if (irsp
->ulpBdeCount
!= 0 &&
2881 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2882 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2885 /* search continue save q for same XRI */
2886 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2887 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2888 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2889 list_add_tail(&saveq
->list
, &iocbq
->list
);
2895 list_add_tail(&saveq
->clist
,
2896 &pring
->iocb_continue_saveq
);
2897 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2898 list_del_init(&iocbq
->clist
);
2900 irsp
= &(saveq
->iocb
);
2904 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2905 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2906 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2907 Rctl
= FC_RCTL_ELS_REQ
;
2910 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2911 Rctl
= w5p
->hcsw
.Rctl
;
2912 Type
= w5p
->hcsw
.Type
;
2914 /* Firmware Workaround */
2915 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2916 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2917 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2918 Rctl
= FC_RCTL_ELS_REQ
;
2920 w5p
->hcsw
.Rctl
= Rctl
;
2921 w5p
->hcsw
.Type
= Type
;
2925 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2926 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2927 "0313 Ring %d handler: unexpected Rctl x%x "
2928 "Type x%x received\n",
2929 pring
->ringno
, Rctl
, Type
);
2935 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2936 * @phba: Pointer to HBA context object.
2937 * @pring: Pointer to driver SLI ring object.
2938 * @prspiocb: Pointer to response iocb object.
2940 * This function looks up the iocb_lookup table to get the command iocb
2941 * corresponding to the given response iocb using the iotag of the
2942 * response iocb. This function is called with the hbalock held
2943 * for sli3 devices or the ring_lock for sli4 devices.
2944 * This function returns the command iocb object if it finds the command
2945 * iocb else returns NULL.
2947 static struct lpfc_iocbq
*
2948 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2949 struct lpfc_sli_ring
*pring
,
2950 struct lpfc_iocbq
*prspiocb
)
2952 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2954 lockdep_assert_held(&phba
->hbalock
);
2956 iotag
= prspiocb
->iocb
.ulpIoTag
;
2958 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2959 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2960 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2961 /* remove from txcmpl queue list */
2962 list_del_init(&cmd_iocb
->list
);
2963 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2968 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2969 "0317 iotag x%x is out of "
2970 "range: max iotag x%x wd0 x%x\n",
2971 iotag
, phba
->sli
.last_iotag
,
2972 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2977 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2978 * @phba: Pointer to HBA context object.
2979 * @pring: Pointer to driver SLI ring object.
2982 * This function looks up the iocb_lookup table to get the command iocb
2983 * corresponding to the given iotag. This function is called with the
2985 * This function returns the command iocb object if it finds the command
2986 * iocb else returns NULL.
2988 static struct lpfc_iocbq
*
2989 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2990 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2992 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2994 lockdep_assert_held(&phba
->hbalock
);
2995 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2996 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2997 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2998 /* remove from txcmpl queue list */
2999 list_del_init(&cmd_iocb
->list
);
3000 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
3005 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3006 "0372 iotag x%x lookup error: max iotag (x%x) "
3008 iotag
, phba
->sli
.last_iotag
,
3009 cmd_iocb
? cmd_iocb
->iocb_flag
: 0xffff);
3014 * lpfc_sli_process_sol_iocb - process solicited iocb completion
3015 * @phba: Pointer to HBA context object.
3016 * @pring: Pointer to driver SLI ring object.
3017 * @saveq: Pointer to the response iocb to be processed.
3019 * This function is called by the ring event handler for non-fcp
3020 * rings when there is a new response iocb in the response ring.
3021 * The caller is not required to hold any locks. This function
3022 * gets the command iocb associated with the response iocb and
3023 * calls the completion handler for the command iocb. If there
3024 * is no completion handler, the function will free the resources
3025 * associated with command iocb. If the response iocb is for
3026 * an already aborted command iocb, the status of the completion
3027 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
3028 * This function always returns 1.
3031 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3032 struct lpfc_iocbq
*saveq
)
3034 struct lpfc_iocbq
*cmdiocbp
;
3036 unsigned long iflag
;
3038 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
3039 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3040 spin_lock_irqsave(&pring
->ring_lock
, iflag
);
3042 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3043 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
3044 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3045 spin_unlock_irqrestore(&pring
->ring_lock
, iflag
);
3047 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3050 if (cmdiocbp
->iocb_cmpl
) {
3052 * If an ELS command failed send an event to mgmt
3055 if (saveq
->iocb
.ulpStatus
&&
3056 (pring
->ringno
== LPFC_ELS_RING
) &&
3057 (cmdiocbp
->iocb
.ulpCommand
==
3058 CMD_ELS_REQUEST64_CR
))
3059 lpfc_send_els_failure_event(phba
,
3063 * Post all ELS completions to the worker thread.
3064 * All other are passed to the completion callback.
3066 if (pring
->ringno
== LPFC_ELS_RING
) {
3067 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3068 (cmdiocbp
->iocb_flag
&
3069 LPFC_DRIVER_ABORTED
)) {
3070 spin_lock_irqsave(&phba
->hbalock
,
3072 cmdiocbp
->iocb_flag
&=
3073 ~LPFC_DRIVER_ABORTED
;
3074 spin_unlock_irqrestore(&phba
->hbalock
,
3076 saveq
->iocb
.ulpStatus
=
3077 IOSTAT_LOCAL_REJECT
;
3078 saveq
->iocb
.un
.ulpWord
[4] =
3081 /* Firmware could still be in progress
3082 * of DMAing payload, so don't free data
3083 * buffer till after a hbeat.
3085 spin_lock_irqsave(&phba
->hbalock
,
3087 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
3088 spin_unlock_irqrestore(&phba
->hbalock
,
3091 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3092 if (saveq
->iocb_flag
&
3093 LPFC_EXCHANGE_BUSY
) {
3094 /* Set cmdiocb flag for the
3095 * exchange busy so sgl (xri)
3096 * will not be released until
3097 * the abort xri is received
3101 &phba
->hbalock
, iflag
);
3102 cmdiocbp
->iocb_flag
|=
3104 spin_unlock_irqrestore(
3105 &phba
->hbalock
, iflag
);
3107 if (cmdiocbp
->iocb_flag
&
3108 LPFC_DRIVER_ABORTED
) {
3110 * Clear LPFC_DRIVER_ABORTED
3111 * bit in case it was driver
3115 &phba
->hbalock
, iflag
);
3116 cmdiocbp
->iocb_flag
&=
3117 ~LPFC_DRIVER_ABORTED
;
3118 spin_unlock_irqrestore(
3119 &phba
->hbalock
, iflag
);
3120 cmdiocbp
->iocb
.ulpStatus
=
3121 IOSTAT_LOCAL_REJECT
;
3122 cmdiocbp
->iocb
.un
.ulpWord
[4] =
3123 IOERR_ABORT_REQUESTED
;
3125 * For SLI4, irsiocb contains
3126 * NO_XRI in sli_xritag, it
3127 * shall not affect releasing
3128 * sgl (xri) process.
3130 saveq
->iocb
.ulpStatus
=
3131 IOSTAT_LOCAL_REJECT
;
3132 saveq
->iocb
.un
.ulpWord
[4] =
3135 &phba
->hbalock
, iflag
);
3137 LPFC_DELAY_MEM_FREE
;
3138 spin_unlock_irqrestore(
3139 &phba
->hbalock
, iflag
);
3143 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
3145 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
3148 * Unknown initiating command based on the response iotag.
3149 * This could be the case on the ELS ring because of
3152 if (pring
->ringno
!= LPFC_ELS_RING
) {
3154 * Ring <ringno> handler: unexpected completion IoTag
3157 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3158 "0322 Ring %d handler: "
3159 "unexpected completion IoTag x%x "
3160 "Data: x%x x%x x%x x%x\n",
3162 saveq
->iocb
.ulpIoTag
,
3163 saveq
->iocb
.ulpStatus
,
3164 saveq
->iocb
.un
.ulpWord
[4],
3165 saveq
->iocb
.ulpCommand
,
3166 saveq
->iocb
.ulpContext
);
3174 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
3175 * @phba: Pointer to HBA context object.
3176 * @pring: Pointer to driver SLI ring object.
3178 * This function is called from the iocb ring event handlers when
3179 * put pointer is ahead of the get pointer for a ring. This function signal
3180 * an error attention condition to the worker thread and the worker
3181 * thread will transition the HBA to offline state.
3184 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3186 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
3188 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3189 * rsp ring <portRspMax>
3191 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3192 "0312 Ring %d handler: portRspPut %d "
3193 "is bigger than rsp ring %d\n",
3194 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
3195 pring
->sli
.sli3
.numRiocb
);
3197 phba
->link_state
= LPFC_HBA_ERROR
;
3200 * All error attention handlers are posted to
3203 phba
->work_ha
|= HA_ERATT
;
3204 phba
->work_hs
= HS_FFER3
;
3206 lpfc_worker_wake_up(phba
);
3212 * lpfc_poll_eratt - Error attention polling timer timeout handler
3213 * @ptr: Pointer to address of HBA context object.
3215 * This function is invoked by the Error Attention polling timer when the
3216 * timer times out. It will check the SLI Error Attention register for
3217 * possible attention events. If so, it will post an Error Attention event
3218 * and wake up worker thread to process it. Otherwise, it will set up the
3219 * Error Attention polling timer for the next poll.
3221 void lpfc_poll_eratt(struct timer_list
*t
)
3223 struct lpfc_hba
*phba
;
3225 uint64_t sli_intr
, cnt
;
3227 phba
= from_timer(phba
, t
, eratt_poll
);
3229 /* Here we will also keep track of interrupts per sec of the hba */
3230 sli_intr
= phba
->sli
.slistat
.sli_intr
;
3232 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
3233 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
3236 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
3238 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3239 do_div(cnt
, phba
->eratt_poll_interval
);
3240 phba
->sli
.slistat
.sli_ips
= cnt
;
3242 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
3244 /* Check chip HA register for error event */
3245 eratt
= lpfc_sli_check_eratt(phba
);
3248 /* Tell the worker thread there is work to do */
3249 lpfc_worker_wake_up(phba
);
3251 /* Restart the timer for next eratt poll */
3252 mod_timer(&phba
->eratt_poll
,
3254 msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
3260 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3261 * @phba: Pointer to HBA context object.
3262 * @pring: Pointer to driver SLI ring object.
3263 * @mask: Host attention register mask for this ring.
3265 * This function is called from the interrupt context when there is a ring
3266 * event for the fcp ring. The caller does not hold any lock.
3267 * The function processes each response iocb in the response ring until it
3268 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3269 * LE bit set. The function will call the completion handler of the command iocb
3270 * if the response iocb indicates a completion for a command iocb or it is
3271 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3272 * function if this is an unsolicited iocb.
3273 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3274 * to check it explicitly.
3277 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
3278 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3280 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
3281 IOCB_t
*irsp
= NULL
;
3282 IOCB_t
*entry
= NULL
;
3283 struct lpfc_iocbq
*cmdiocbq
= NULL
;
3284 struct lpfc_iocbq rspiocbq
;
3286 uint32_t portRspPut
, portRspMax
;
3288 lpfc_iocb_type type
;
3289 unsigned long iflag
;
3290 uint32_t rsp_cmpl
= 0;
3292 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3293 pring
->stats
.iocb_event
++;
3296 * The next available response entry should never exceed the maximum
3297 * entries. If it does, treat it as an adapter hardware error.
3299 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3300 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3301 if (unlikely(portRspPut
>= portRspMax
)) {
3302 lpfc_sli_rsp_pointers_error(phba
, pring
);
3303 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3306 if (phba
->fcp_ring_in_use
) {
3307 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3310 phba
->fcp_ring_in_use
= 1;
3313 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3315 * Fetch an entry off the ring and copy it into a local data
3316 * structure. The copy involves a byte-swap since the
3317 * network byte order and pci byte orders are different.
3319 entry
= lpfc_resp_iocb(phba
, pring
);
3320 phba
->last_completion_time
= jiffies
;
3322 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3323 pring
->sli
.sli3
.rspidx
= 0;
3325 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
3326 (uint32_t *) &rspiocbq
.iocb
,
3327 phba
->iocb_rsp_size
);
3328 INIT_LIST_HEAD(&(rspiocbq
.list
));
3329 irsp
= &rspiocbq
.iocb
;
3331 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
3332 pring
->stats
.iocb_rsp
++;
3335 if (unlikely(irsp
->ulpStatus
)) {
3337 * If resource errors reported from HBA, reduce
3338 * queuedepths of the SCSI device.
3340 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3341 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3342 IOERR_NO_RESOURCES
)) {
3343 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3344 phba
->lpfc_rampdown_queue_depth(phba
);
3345 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3348 /* Rsp ring <ringno> error: IOCB */
3349 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3350 "0336 Rsp Ring %d error: IOCB Data: "
3351 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3353 irsp
->un
.ulpWord
[0],
3354 irsp
->un
.ulpWord
[1],
3355 irsp
->un
.ulpWord
[2],
3356 irsp
->un
.ulpWord
[3],
3357 irsp
->un
.ulpWord
[4],
3358 irsp
->un
.ulpWord
[5],
3359 *(uint32_t *)&irsp
->un1
,
3360 *((uint32_t *)&irsp
->un1
+ 1));
3364 case LPFC_ABORT_IOCB
:
3367 * Idle exchange closed via ABTS from port. No iocb
3368 * resources need to be recovered.
3370 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3371 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3372 "0333 IOCB cmd 0x%x"
3373 " processed. Skipping"
3379 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3381 if (unlikely(!cmdiocbq
))
3383 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3384 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3385 if (cmdiocbq
->iocb_cmpl
) {
3386 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3387 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3389 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3392 case LPFC_UNSOL_IOCB
:
3393 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3394 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3395 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3398 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3399 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3400 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3401 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3403 dev_warn(&((phba
->pcidev
)->dev
),
3405 phba
->brd_no
, adaptermsg
);
3407 /* Unknown IOCB command */
3408 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3409 "0334 Unknown IOCB command "
3410 "Data: x%x, x%x x%x x%x x%x\n",
3411 type
, irsp
->ulpCommand
,
3420 * The response IOCB has been processed. Update the ring
3421 * pointer in SLIM. If the port response put pointer has not
3422 * been updated, sync the pgp->rspPutInx and fetch the new port
3423 * response put pointer.
3425 writel(pring
->sli
.sli3
.rspidx
,
3426 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3428 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3429 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3432 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3433 pring
->stats
.iocb_rsp_full
++;
3434 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3435 writel(status
, phba
->CAregaddr
);
3436 readl(phba
->CAregaddr
);
3438 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3439 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3440 pring
->stats
.iocb_cmd_empty
++;
3442 /* Force update of the local copy of cmdGetInx */
3443 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3444 lpfc_sli_resume_iocb(phba
, pring
);
3446 if ((pring
->lpfc_sli_cmd_available
))
3447 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3451 phba
->fcp_ring_in_use
= 0;
3452 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3457 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3458 * @phba: Pointer to HBA context object.
3459 * @pring: Pointer to driver SLI ring object.
3460 * @rspiocbp: Pointer to driver response IOCB object.
3462 * This function is called from the worker thread when there is a slow-path
3463 * response IOCB to process. This function chains all the response iocbs until
3464 * seeing the iocb with the LE bit set. The function will call
3465 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3466 * completion of a command iocb. The function will call the
3467 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3468 * The function frees the resources or calls the completion handler if this
3469 * iocb is an abort completion. The function returns NULL when the response
3470 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3471 * this function shall chain the iocb on to the iocb_continueq and return the
3472 * response iocb passed in.
3474 static struct lpfc_iocbq
*
3475 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3476 struct lpfc_iocbq
*rspiocbp
)
3478 struct lpfc_iocbq
*saveq
;
3479 struct lpfc_iocbq
*cmdiocbp
;
3480 struct lpfc_iocbq
*next_iocb
;
3481 IOCB_t
*irsp
= NULL
;
3482 uint32_t free_saveq
;
3483 uint8_t iocb_cmd_type
;
3484 lpfc_iocb_type type
;
3485 unsigned long iflag
;
3488 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3489 /* First add the response iocb to the countinueq list */
3490 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3491 pring
->iocb_continueq_cnt
++;
3493 /* Now, determine whether the list is completed for processing */
3494 irsp
= &rspiocbp
->iocb
;
3497 * By default, the driver expects to free all resources
3498 * associated with this iocb completion.
3501 saveq
= list_get_first(&pring
->iocb_continueq
,
3502 struct lpfc_iocbq
, list
);
3503 irsp
= &(saveq
->iocb
);
3504 list_del_init(&pring
->iocb_continueq
);
3505 pring
->iocb_continueq_cnt
= 0;
3507 pring
->stats
.iocb_rsp
++;
3510 * If resource errors reported from HBA, reduce
3511 * queuedepths of the SCSI device.
3513 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3514 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3515 IOERR_NO_RESOURCES
)) {
3516 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3517 phba
->lpfc_rampdown_queue_depth(phba
);
3518 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3521 if (irsp
->ulpStatus
) {
3522 /* Rsp ring <ringno> error: IOCB */
3523 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3524 "0328 Rsp Ring %d error: "
3529 "x%x x%x x%x x%x\n",
3531 irsp
->un
.ulpWord
[0],
3532 irsp
->un
.ulpWord
[1],
3533 irsp
->un
.ulpWord
[2],
3534 irsp
->un
.ulpWord
[3],
3535 irsp
->un
.ulpWord
[4],
3536 irsp
->un
.ulpWord
[5],
3537 *(((uint32_t *) irsp
) + 6),
3538 *(((uint32_t *) irsp
) + 7),
3539 *(((uint32_t *) irsp
) + 8),
3540 *(((uint32_t *) irsp
) + 9),
3541 *(((uint32_t *) irsp
) + 10),
3542 *(((uint32_t *) irsp
) + 11),
3543 *(((uint32_t *) irsp
) + 12),
3544 *(((uint32_t *) irsp
) + 13),
3545 *(((uint32_t *) irsp
) + 14),
3546 *(((uint32_t *) irsp
) + 15));
3550 * Fetch the IOCB command type and call the correct completion
3551 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3552 * get freed back to the lpfc_iocb_list by the discovery
3555 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3556 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3559 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3560 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3561 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3564 case LPFC_UNSOL_IOCB
:
3565 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3566 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3567 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3572 case LPFC_ABORT_IOCB
:
3574 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3575 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3578 /* Call the specified completion routine */
3579 if (cmdiocbp
->iocb_cmpl
) {
3580 spin_unlock_irqrestore(&phba
->hbalock
,
3582 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3584 spin_lock_irqsave(&phba
->hbalock
,
3587 __lpfc_sli_release_iocbq(phba
,
3592 case LPFC_UNKNOWN_IOCB
:
3593 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3594 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3595 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3596 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3598 dev_warn(&((phba
->pcidev
)->dev
),
3600 phba
->brd_no
, adaptermsg
);
3602 /* Unknown IOCB command */
3603 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3604 "0335 Unknown IOCB "
3605 "command Data: x%x "
3616 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3617 &saveq
->list
, list
) {
3618 list_del_init(&rspiocbp
->list
);
3619 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3621 __lpfc_sli_release_iocbq(phba
, saveq
);
3625 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3630 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3631 * @phba: Pointer to HBA context object.
3632 * @pring: Pointer to driver SLI ring object.
3633 * @mask: Host attention register mask for this ring.
3635 * This routine wraps the actual slow_ring event process routine from the
3636 * API jump table function pointer from the lpfc_hba struct.
3639 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3640 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3642 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3646 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3647 * @phba: Pointer to HBA context object.
3648 * @pring: Pointer to driver SLI ring object.
3649 * @mask: Host attention register mask for this ring.
3651 * This function is called from the worker thread when there is a ring event
3652 * for non-fcp rings. The caller does not hold any lock. The function will
3653 * remove each response iocb in the response ring and calls the handle
3654 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3657 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3658 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3660 struct lpfc_pgp
*pgp
;
3662 IOCB_t
*irsp
= NULL
;
3663 struct lpfc_iocbq
*rspiocbp
= NULL
;
3664 uint32_t portRspPut
, portRspMax
;
3665 unsigned long iflag
;
3668 pgp
= &phba
->port_gp
[pring
->ringno
];
3669 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3670 pring
->stats
.iocb_event
++;
3673 * The next available response entry should never exceed the maximum
3674 * entries. If it does, treat it as an adapter hardware error.
3676 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3677 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3678 if (portRspPut
>= portRspMax
) {
3680 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3681 * rsp ring <portRspMax>
3683 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3684 "0303 Ring %d handler: portRspPut %d "
3685 "is bigger than rsp ring %d\n",
3686 pring
->ringno
, portRspPut
, portRspMax
);
3688 phba
->link_state
= LPFC_HBA_ERROR
;
3689 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3691 phba
->work_hs
= HS_FFER3
;
3692 lpfc_handle_eratt(phba
);
3698 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3700 * Build a completion list and call the appropriate handler.
3701 * The process is to get the next available response iocb, get
3702 * a free iocb from the list, copy the response data into the
3703 * free iocb, insert to the continuation list, and update the
3704 * next response index to slim. This process makes response
3705 * iocb's in the ring available to DMA as fast as possible but
3706 * pays a penalty for a copy operation. Since the iocb is
3707 * only 32 bytes, this penalty is considered small relative to
3708 * the PCI reads for register values and a slim write. When
3709 * the ulpLe field is set, the entire Command has been
3712 entry
= lpfc_resp_iocb(phba
, pring
);
3714 phba
->last_completion_time
= jiffies
;
3715 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3716 if (rspiocbp
== NULL
) {
3717 printk(KERN_ERR
"%s: out of buffers! Failing "
3718 "completion.\n", __func__
);
3722 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3723 phba
->iocb_rsp_size
);
3724 irsp
= &rspiocbp
->iocb
;
3726 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3727 pring
->sli
.sli3
.rspidx
= 0;
3729 if (pring
->ringno
== LPFC_ELS_RING
) {
3730 lpfc_debugfs_slow_ring_trc(phba
,
3731 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3732 *(((uint32_t *) irsp
) + 4),
3733 *(((uint32_t *) irsp
) + 6),
3734 *(((uint32_t *) irsp
) + 7));
3737 writel(pring
->sli
.sli3
.rspidx
,
3738 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3740 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3741 /* Handle the response IOCB */
3742 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3743 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3746 * If the port response put pointer has not been updated, sync
3747 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3748 * response put pointer.
3750 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3751 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3753 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3755 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3756 /* At least one response entry has been freed */
3757 pring
->stats
.iocb_rsp_full
++;
3758 /* SET RxRE_RSP in Chip Att register */
3759 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3760 writel(status
, phba
->CAregaddr
);
3761 readl(phba
->CAregaddr
); /* flush */
3763 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3764 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3765 pring
->stats
.iocb_cmd_empty
++;
3767 /* Force update of the local copy of cmdGetInx */
3768 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3769 lpfc_sli_resume_iocb(phba
, pring
);
3771 if ((pring
->lpfc_sli_cmd_available
))
3772 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3776 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3781 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3782 * @phba: Pointer to HBA context object.
3783 * @pring: Pointer to driver SLI ring object.
3784 * @mask: Host attention register mask for this ring.
3786 * This function is called from the worker thread when there is a pending
3787 * ELS response iocb on the driver internal slow-path response iocb worker
3788 * queue. The caller does not hold any lock. The function will remove each
3789 * response iocb from the response worker queue and calls the handle
3790 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3793 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3794 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3796 struct lpfc_iocbq
*irspiocbq
;
3797 struct hbq_dmabuf
*dmabuf
;
3798 struct lpfc_cq_event
*cq_event
;
3799 unsigned long iflag
;
3801 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3802 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3803 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3804 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3805 /* Get the response iocb from the head of work queue */
3806 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3807 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3808 cq_event
, struct lpfc_cq_event
, list
);
3809 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3811 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3812 case CQE_CODE_COMPL_WQE
:
3813 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3815 /* Translate ELS WCQE to response IOCBQ */
3816 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3819 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3822 case CQE_CODE_RECEIVE
:
3823 case CQE_CODE_RECEIVE_V1
:
3824 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3826 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3835 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3836 * @phba: Pointer to HBA context object.
3837 * @pring: Pointer to driver SLI ring object.
3839 * This function aborts all iocbs in the given ring and frees all the iocb
3840 * objects in txq. This function issues an abort iocb for all the iocb commands
3841 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3842 * the return of this function. The caller is not required to hold any locks.
3845 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3847 LIST_HEAD(completions
);
3848 struct lpfc_iocbq
*iocb
, *next_iocb
;
3850 if (pring
->ringno
== LPFC_ELS_RING
) {
3851 lpfc_fabric_abort_hba(phba
);
3854 /* Error everything on txq and txcmplq
3857 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3858 spin_lock_irq(&pring
->ring_lock
);
3859 list_splice_init(&pring
->txq
, &completions
);
3861 spin_unlock_irq(&pring
->ring_lock
);
3863 spin_lock_irq(&phba
->hbalock
);
3864 /* Next issue ABTS for everything on the txcmplq */
3865 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3866 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3867 spin_unlock_irq(&phba
->hbalock
);
3869 spin_lock_irq(&phba
->hbalock
);
3870 list_splice_init(&pring
->txq
, &completions
);
3873 /* Next issue ABTS for everything on the txcmplq */
3874 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3875 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3876 spin_unlock_irq(&phba
->hbalock
);
3879 /* Cancel all the IOCBs from the completions list */
3880 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3885 * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring
3886 * @phba: Pointer to HBA context object.
3887 * @pring: Pointer to driver SLI ring object.
3889 * This function aborts all iocbs in the given ring and frees all the iocb
3890 * objects in txq. This function issues an abort iocb for all the iocb commands
3891 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3892 * the return of this function. The caller is not required to hold any locks.
3895 lpfc_sli_abort_wqe_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3897 LIST_HEAD(completions
);
3898 struct lpfc_iocbq
*iocb
, *next_iocb
;
3900 if (pring
->ringno
== LPFC_ELS_RING
)
3901 lpfc_fabric_abort_hba(phba
);
3903 spin_lock_irq(&phba
->hbalock
);
3904 /* Next issue ABTS for everything on the txcmplq */
3905 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3906 lpfc_sli4_abort_nvme_io(phba
, pring
, iocb
);
3907 spin_unlock_irq(&phba
->hbalock
);
3912 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3913 * @phba: Pointer to HBA context object.
3914 * @pring: Pointer to driver SLI ring object.
3916 * This function aborts all iocbs in FCP rings and frees all the iocb
3917 * objects in txq. This function issues an abort iocb for all the iocb commands
3918 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3919 * the return of this function. The caller is not required to hold any locks.
3922 lpfc_sli_abort_fcp_rings(struct lpfc_hba
*phba
)
3924 struct lpfc_sli
*psli
= &phba
->sli
;
3925 struct lpfc_sli_ring
*pring
;
3928 /* Look on all the FCP Rings for the iotag */
3929 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3930 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3931 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
3932 lpfc_sli_abort_iocb_ring(phba
, pring
);
3935 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
3936 lpfc_sli_abort_iocb_ring(phba
, pring
);
3941 * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings
3942 * @phba: Pointer to HBA context object.
3944 * This function aborts all wqes in NVME rings. This function issues an
3945 * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in
3946 * the txcmplq is not guaranteed to complete before the return of this
3947 * function. The caller is not required to hold any locks.
3950 lpfc_sli_abort_nvme_rings(struct lpfc_hba
*phba
)
3952 struct lpfc_sli_ring
*pring
;
3955 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3958 /* Abort all IO on each NVME ring. */
3959 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
3960 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
3961 lpfc_sli_abort_wqe_ring(phba
, pring
);
3967 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3968 * @phba: Pointer to HBA context object.
3970 * This function flushes all iocbs in the fcp ring and frees all the iocb
3971 * objects in txq and txcmplq. This function will not issue abort iocbs
3972 * for all the iocb commands in txcmplq, they will just be returned with
3973 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3974 * slot has been permanently disabled.
3977 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3981 struct lpfc_sli
*psli
= &phba
->sli
;
3982 struct lpfc_sli_ring
*pring
;
3984 struct lpfc_iocbq
*piocb
, *next_iocb
;
3986 spin_lock_irq(&phba
->hbalock
);
3987 /* Indicate the I/O queues are flushed */
3988 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3989 spin_unlock_irq(&phba
->hbalock
);
3991 /* Look on all the FCP Rings for the iotag */
3992 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3993 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3994 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
3996 spin_lock_irq(&pring
->ring_lock
);
3997 /* Retrieve everything on txq */
3998 list_splice_init(&pring
->txq
, &txq
);
3999 list_for_each_entry_safe(piocb
, next_iocb
,
4000 &pring
->txcmplq
, list
)
4001 piocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
4002 /* Retrieve everything on the txcmplq */
4003 list_splice_init(&pring
->txcmplq
, &txcmplq
);
4005 pring
->txcmplq_cnt
= 0;
4006 spin_unlock_irq(&pring
->ring_lock
);
4009 lpfc_sli_cancel_iocbs(phba
, &txq
,
4010 IOSTAT_LOCAL_REJECT
,
4012 /* Flush the txcmpq */
4013 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
4014 IOSTAT_LOCAL_REJECT
,
4018 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
4020 spin_lock_irq(&phba
->hbalock
);
4021 /* Retrieve everything on txq */
4022 list_splice_init(&pring
->txq
, &txq
);
4023 list_for_each_entry_safe(piocb
, next_iocb
,
4024 &pring
->txcmplq
, list
)
4025 piocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
4026 /* Retrieve everything on the txcmplq */
4027 list_splice_init(&pring
->txcmplq
, &txcmplq
);
4029 pring
->txcmplq_cnt
= 0;
4030 spin_unlock_irq(&phba
->hbalock
);
4033 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
4035 /* Flush the txcmpq */
4036 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
4042 * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings
4043 * @phba: Pointer to HBA context object.
4045 * This function flushes all wqes in the nvme rings and frees all resources
4046 * in the txcmplq. This function does not issue abort wqes for the IO
4047 * commands in txcmplq, they will just be returned with
4048 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
4049 * slot has been permanently disabled.
4052 lpfc_sli_flush_nvme_rings(struct lpfc_hba
*phba
)
4055 struct lpfc_sli_ring
*pring
;
4057 struct lpfc_iocbq
*piocb
, *next_iocb
;
4059 if (phba
->sli_rev
< LPFC_SLI_REV4
)
4062 /* Hint to other driver operations that a flush is in progress. */
4063 spin_lock_irq(&phba
->hbalock
);
4064 phba
->hba_flag
|= HBA_NVME_IOQ_FLUSH
;
4065 spin_unlock_irq(&phba
->hbalock
);
4067 /* Cycle through all NVME rings and complete each IO with
4068 * a local driver reason code. This is a flush so no
4069 * abort exchange to FW.
4071 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
4072 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
4074 spin_lock_irq(&pring
->ring_lock
);
4075 list_for_each_entry_safe(piocb
, next_iocb
,
4076 &pring
->txcmplq
, list
)
4077 piocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
4078 /* Retrieve everything on the txcmplq */
4079 list_splice_init(&pring
->txcmplq
, &txcmplq
);
4080 pring
->txcmplq_cnt
= 0;
4081 spin_unlock_irq(&pring
->ring_lock
);
4083 /* Flush the txcmpq &&&PAE */
4084 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
4085 IOSTAT_LOCAL_REJECT
,
4091 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
4092 * @phba: Pointer to HBA context object.
4093 * @mask: Bit mask to be checked.
4095 * This function reads the host status register and compares
4096 * with the provided bit mask to check if HBA completed
4097 * the restart. This function will wait in a loop for the
4098 * HBA to complete restart. If the HBA does not restart within
4099 * 15 iterations, the function will reset the HBA again. The
4100 * function returns 1 when HBA fail to restart otherwise returns
4104 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
4110 /* Read the HBA Host Status Register */
4111 if (lpfc_readl(phba
->HSregaddr
, &status
))
4115 * Check status register every 100ms for 5 retries, then every
4116 * 500ms for 5, then every 2.5 sec for 5, then reset board and
4117 * every 2.5 sec for 4.
4118 * Break our of the loop if errors occurred during init.
4120 while (((status
& mask
) != mask
) &&
4121 !(status
& HS_FFERM
) &&
4133 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4134 lpfc_sli_brdrestart(phba
);
4136 /* Read the HBA Host Status Register */
4137 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
4143 /* Check to see if any errors occurred during init */
4144 if ((status
& HS_FFERM
) || (i
>= 20)) {
4145 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4146 "2751 Adapter failed to restart, "
4147 "status reg x%x, FW Data: A8 x%x AC x%x\n",
4149 readl(phba
->MBslimaddr
+ 0xa8),
4150 readl(phba
->MBslimaddr
+ 0xac));
4151 phba
->link_state
= LPFC_HBA_ERROR
;
4159 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
4160 * @phba: Pointer to HBA context object.
4161 * @mask: Bit mask to be checked.
4163 * This function checks the host status register to check if HBA is
4164 * ready. This function will wait in a loop for the HBA to be ready
4165 * If the HBA is not ready , the function will will reset the HBA PCI
4166 * function again. The function returns 1 when HBA fail to be ready
4167 * otherwise returns zero.
4170 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
4175 /* Read the HBA Host Status Register */
4176 status
= lpfc_sli4_post_status_check(phba
);
4179 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4180 lpfc_sli_brdrestart(phba
);
4181 status
= lpfc_sli4_post_status_check(phba
);
4184 /* Check to see if any errors occurred during init */
4186 phba
->link_state
= LPFC_HBA_ERROR
;
4189 phba
->sli4_hba
.intr_enable
= 0;
4195 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
4196 * @phba: Pointer to HBA context object.
4197 * @mask: Bit mask to be checked.
4199 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
4200 * from the API jump table function pointer from the lpfc_hba struct.
4203 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
4205 return phba
->lpfc_sli_brdready(phba
, mask
);
4208 #define BARRIER_TEST_PATTERN (0xdeadbeef)
4211 * lpfc_reset_barrier - Make HBA ready for HBA reset
4212 * @phba: Pointer to HBA context object.
4214 * This function is called before resetting an HBA. This function is called
4215 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4217 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
4219 uint32_t __iomem
*resp_buf
;
4220 uint32_t __iomem
*mbox_buf
;
4221 volatile uint32_t mbox
;
4222 uint32_t hc_copy
, ha_copy
, resp_data
;
4226 lockdep_assert_held(&phba
->hbalock
);
4228 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
4229 if (hdrtype
!= 0x80 ||
4230 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
4231 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
4235 * Tell the other part of the chip to suspend temporarily all
4238 resp_buf
= phba
->MBslimaddr
;
4240 /* Disable the error attention */
4241 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
4243 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
4244 readl(phba
->HCregaddr
); /* flush */
4245 phba
->link_flag
|= LS_IGNORE_ERATT
;
4247 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4249 if (ha_copy
& HA_ERATT
) {
4250 /* Clear Chip error bit */
4251 writel(HA_ERATT
, phba
->HAregaddr
);
4252 phba
->pport
->stopped
= 1;
4256 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
4257 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
4259 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
4260 mbox_buf
= phba
->MBslimaddr
;
4261 writel(mbox
, mbox_buf
);
4263 for (i
= 0; i
< 50; i
++) {
4264 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
4266 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
4272 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
4274 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
4275 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
4276 phba
->pport
->stopped
)
4282 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
4284 for (i
= 0; i
< 500; i
++) {
4285 if (lpfc_readl(resp_buf
, &resp_data
))
4287 if (resp_data
!= mbox
)
4296 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4298 if (!(ha_copy
& HA_ERATT
))
4304 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
4305 writel(HA_ERATT
, phba
->HAregaddr
);
4306 phba
->pport
->stopped
= 1;
4310 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4311 writel(hc_copy
, phba
->HCregaddr
);
4312 readl(phba
->HCregaddr
); /* flush */
4316 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4317 * @phba: Pointer to HBA context object.
4319 * This function issues a kill_board mailbox command and waits for
4320 * the error attention interrupt. This function is called for stopping
4321 * the firmware processing. The caller is not required to hold any
4322 * locks. This function calls lpfc_hba_down_post function to free
4323 * any pending commands after the kill. The function will return 1 when it
4324 * fails to kill the board else will return 0.
4327 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
4329 struct lpfc_sli
*psli
;
4339 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4340 "0329 Kill HBA Data: x%x x%x\n",
4341 phba
->pport
->port_state
, psli
->sli_flag
);
4343 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4347 /* Disable the error attention */
4348 spin_lock_irq(&phba
->hbalock
);
4349 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
4350 spin_unlock_irq(&phba
->hbalock
);
4351 mempool_free(pmb
, phba
->mbox_mem_pool
);
4354 status
&= ~HC_ERINT_ENA
;
4355 writel(status
, phba
->HCregaddr
);
4356 readl(phba
->HCregaddr
); /* flush */
4357 phba
->link_flag
|= LS_IGNORE_ERATT
;
4358 spin_unlock_irq(&phba
->hbalock
);
4360 lpfc_kill_board(phba
, pmb
);
4361 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4362 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4364 if (retval
!= MBX_SUCCESS
) {
4365 if (retval
!= MBX_BUSY
)
4366 mempool_free(pmb
, phba
->mbox_mem_pool
);
4367 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4368 "2752 KILL_BOARD command failed retval %d\n",
4370 spin_lock_irq(&phba
->hbalock
);
4371 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4372 spin_unlock_irq(&phba
->hbalock
);
4376 spin_lock_irq(&phba
->hbalock
);
4377 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
4378 spin_unlock_irq(&phba
->hbalock
);
4380 mempool_free(pmb
, phba
->mbox_mem_pool
);
4382 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4383 * attention every 100ms for 3 seconds. If we don't get ERATT after
4384 * 3 seconds we still set HBA_ERROR state because the status of the
4385 * board is now undefined.
4387 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4389 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
4391 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4395 del_timer_sync(&psli
->mbox_tmo
);
4396 if (ha_copy
& HA_ERATT
) {
4397 writel(HA_ERATT
, phba
->HAregaddr
);
4398 phba
->pport
->stopped
= 1;
4400 spin_lock_irq(&phba
->hbalock
);
4401 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4402 psli
->mbox_active
= NULL
;
4403 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4404 spin_unlock_irq(&phba
->hbalock
);
4406 lpfc_hba_down_post(phba
);
4407 phba
->link_state
= LPFC_HBA_ERROR
;
4409 return ha_copy
& HA_ERATT
? 0 : 1;
4413 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4414 * @phba: Pointer to HBA context object.
4416 * This function resets the HBA by writing HC_INITFF to the control
4417 * register. After the HBA resets, this function resets all the iocb ring
4418 * indices. This function disables PCI layer parity checking during
4420 * This function returns 0 always.
4421 * The caller is not required to hold any locks.
4424 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
4426 struct lpfc_sli
*psli
;
4427 struct lpfc_sli_ring
*pring
;
4434 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4435 "0325 Reset HBA Data: x%x x%x\n",
4436 (phba
->pport
) ? phba
->pport
->port_state
: 0,
4439 /* perform board reset */
4440 phba
->fc_eventTag
= 0;
4441 phba
->link_events
= 0;
4443 phba
->pport
->fc_myDID
= 0;
4444 phba
->pport
->fc_prevDID
= 0;
4447 /* Turn off parity checking and serr during the physical reset */
4448 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4449 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
4451 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4453 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
4455 /* Now toggle INITFF bit in the Host Control Register */
4456 writel(HC_INITFF
, phba
->HCregaddr
);
4458 readl(phba
->HCregaddr
); /* flush */
4459 writel(0, phba
->HCregaddr
);
4460 readl(phba
->HCregaddr
); /* flush */
4462 /* Restore PCI cmd register */
4463 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4465 /* Initialize relevant SLI info */
4466 for (i
= 0; i
< psli
->num_rings
; i
++) {
4467 pring
= &psli
->sli3_ring
[i
];
4469 pring
->sli
.sli3
.rspidx
= 0;
4470 pring
->sli
.sli3
.next_cmdidx
= 0;
4471 pring
->sli
.sli3
.local_getidx
= 0;
4472 pring
->sli
.sli3
.cmdidx
= 0;
4473 pring
->missbufcnt
= 0;
4476 phba
->link_state
= LPFC_WARM_START
;
4481 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4482 * @phba: Pointer to HBA context object.
4484 * This function resets a SLI4 HBA. This function disables PCI layer parity
4485 * checking during resets the device. The caller is not required to hold
4488 * This function returns 0 always.
4491 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
4493 struct lpfc_sli
*psli
= &phba
->sli
;
4498 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4499 "0295 Reset HBA Data: x%x x%x x%x\n",
4500 phba
->pport
->port_state
, psli
->sli_flag
,
4503 /* perform board reset */
4504 phba
->fc_eventTag
= 0;
4505 phba
->link_events
= 0;
4506 phba
->pport
->fc_myDID
= 0;
4507 phba
->pport
->fc_prevDID
= 0;
4509 spin_lock_irq(&phba
->hbalock
);
4510 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
4511 phba
->fcf
.fcf_flag
= 0;
4512 spin_unlock_irq(&phba
->hbalock
);
4514 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4515 if (phba
->hba_flag
& HBA_FW_DUMP_OP
) {
4516 phba
->hba_flag
&= ~HBA_FW_DUMP_OP
;
4520 /* Now physically reset the device */
4521 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4522 "0389 Performing PCI function reset!\n");
4524 /* Turn off parity checking and serr during the physical reset */
4525 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4526 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
4527 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4529 /* Perform FCoE PCI function reset before freeing queue memory */
4530 rc
= lpfc_pci_function_reset(phba
);
4532 /* Restore PCI cmd register */
4533 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4539 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4540 * @phba: Pointer to HBA context object.
4542 * This function is called in the SLI initialization code path to
4543 * restart the HBA. The caller is not required to hold any lock.
4544 * This function writes MBX_RESTART mailbox command to the SLIM and
4545 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4546 * function to free any pending commands. The function enables
4547 * POST only during the first initialization. The function returns zero.
4548 * The function does not guarantee completion of MBX_RESTART mailbox
4549 * command before the return of this function.
4552 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4555 struct lpfc_sli
*psli
;
4556 volatile uint32_t word0
;
4557 void __iomem
*to_slim
;
4558 uint32_t hba_aer_enabled
;
4560 spin_lock_irq(&phba
->hbalock
);
4562 /* Take PCIe device Advanced Error Reporting (AER) state */
4563 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4568 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4569 "0337 Restart HBA Data: x%x x%x\n",
4570 (phba
->pport
) ? phba
->pport
->port_state
: 0,
4574 mb
= (MAILBOX_t
*) &word0
;
4575 mb
->mbxCommand
= MBX_RESTART
;
4578 lpfc_reset_barrier(phba
);
4580 to_slim
= phba
->MBslimaddr
;
4581 writel(*(uint32_t *) mb
, to_slim
);
4582 readl(to_slim
); /* flush */
4584 /* Only skip post after fc_ffinit is completed */
4585 if (phba
->pport
&& phba
->pport
->port_state
)
4586 word0
= 1; /* This is really setting up word1 */
4588 word0
= 0; /* This is really setting up word1 */
4589 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4590 writel(*(uint32_t *) mb
, to_slim
);
4591 readl(to_slim
); /* flush */
4593 lpfc_sli_brdreset(phba
);
4595 phba
->pport
->stopped
= 0;
4596 phba
->link_state
= LPFC_INIT_START
;
4598 spin_unlock_irq(&phba
->hbalock
);
4600 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4601 psli
->stats_start
= ktime_get_seconds();
4603 /* Give the INITFF and Post time to settle. */
4606 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4607 if (hba_aer_enabled
)
4608 pci_disable_pcie_error_reporting(phba
->pcidev
);
4610 lpfc_hba_down_post(phba
);
4616 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4617 * @phba: Pointer to HBA context object.
4619 * This function is called in the SLI initialization code path to restart
4620 * a SLI4 HBA. The caller is not required to hold any lock.
4621 * At the end of the function, it calls lpfc_hba_down_post function to
4622 * free any pending commands.
4625 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4627 struct lpfc_sli
*psli
= &phba
->sli
;
4628 uint32_t hba_aer_enabled
;
4632 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4633 "0296 Restart HBA Data: x%x x%x\n",
4634 phba
->pport
->port_state
, psli
->sli_flag
);
4636 /* Take PCIe device Advanced Error Reporting (AER) state */
4637 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4639 rc
= lpfc_sli4_brdreset(phba
);
4641 spin_lock_irq(&phba
->hbalock
);
4642 phba
->pport
->stopped
= 0;
4643 phba
->link_state
= LPFC_INIT_START
;
4645 spin_unlock_irq(&phba
->hbalock
);
4647 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4648 psli
->stats_start
= ktime_get_seconds();
4650 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4651 if (hba_aer_enabled
)
4652 pci_disable_pcie_error_reporting(phba
->pcidev
);
4654 lpfc_hba_down_post(phba
);
4655 lpfc_sli4_queue_destroy(phba
);
4661 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4662 * @phba: Pointer to HBA context object.
4664 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4665 * API jump table function pointer from the lpfc_hba struct.
4668 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4670 return phba
->lpfc_sli_brdrestart(phba
);
4674 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4675 * @phba: Pointer to HBA context object.
4677 * This function is called after a HBA restart to wait for successful
4678 * restart of the HBA. Successful restart of the HBA is indicated by
4679 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4680 * iteration, the function will restart the HBA again. The function returns
4681 * zero if HBA successfully restarted else returns negative error code.
4684 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4686 uint32_t status
, i
= 0;
4688 /* Read the HBA Host Status Register */
4689 if (lpfc_readl(phba
->HSregaddr
, &status
))
4692 /* Check status register to see what current state is */
4694 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4696 /* Check every 10ms for 10 retries, then every 100ms for 90
4697 * retries, then every 1 sec for 50 retires for a total of
4698 * ~60 seconds before reset the board again and check every
4699 * 1 sec for 50 retries. The up to 60 seconds before the
4700 * board ready is required by the Falcon FIPS zeroization
4701 * complete, and any reset the board in between shall cause
4702 * restart of zeroization, further delay the board ready.
4705 /* Adapter failed to init, timeout, status reg
4707 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4708 "0436 Adapter failed to init, "
4709 "timeout, status reg x%x, "
4710 "FW Data: A8 x%x AC x%x\n", status
,
4711 readl(phba
->MBslimaddr
+ 0xa8),
4712 readl(phba
->MBslimaddr
+ 0xac));
4713 phba
->link_state
= LPFC_HBA_ERROR
;
4717 /* Check to see if any errors occurred during init */
4718 if (status
& HS_FFERM
) {
4719 /* ERROR: During chipset initialization */
4720 /* Adapter failed to init, chipset, status reg
4722 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4723 "0437 Adapter failed to init, "
4724 "chipset, status reg x%x, "
4725 "FW Data: A8 x%x AC x%x\n", status
,
4726 readl(phba
->MBslimaddr
+ 0xa8),
4727 readl(phba
->MBslimaddr
+ 0xac));
4728 phba
->link_state
= LPFC_HBA_ERROR
;
4741 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4742 lpfc_sli_brdrestart(phba
);
4744 /* Read the HBA Host Status Register */
4745 if (lpfc_readl(phba
->HSregaddr
, &status
))
4749 /* Check to see if any errors occurred during init */
4750 if (status
& HS_FFERM
) {
4751 /* ERROR: During chipset initialization */
4752 /* Adapter failed to init, chipset, status reg <status> */
4753 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4754 "0438 Adapter failed to init, chipset, "
4756 "FW Data: A8 x%x AC x%x\n", status
,
4757 readl(phba
->MBslimaddr
+ 0xa8),
4758 readl(phba
->MBslimaddr
+ 0xac));
4759 phba
->link_state
= LPFC_HBA_ERROR
;
4763 /* Clear all interrupt enable conditions */
4764 writel(0, phba
->HCregaddr
);
4765 readl(phba
->HCregaddr
); /* flush */
4767 /* setup host attn register */
4768 writel(0xffffffff, phba
->HAregaddr
);
4769 readl(phba
->HAregaddr
); /* flush */
4774 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4776 * This function calculates and returns the number of HBQs required to be
4780 lpfc_sli_hbq_count(void)
4782 return ARRAY_SIZE(lpfc_hbq_defs
);
4786 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4788 * This function adds the number of hbq entries in every HBQ to get
4789 * the total number of hbq entries required for the HBA and returns
4793 lpfc_sli_hbq_entry_count(void)
4795 int hbq_count
= lpfc_sli_hbq_count();
4799 for (i
= 0; i
< hbq_count
; ++i
)
4800 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4805 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4807 * This function calculates amount of memory required for all hbq entries
4808 * to be configured and returns the total memory required.
4811 lpfc_sli_hbq_size(void)
4813 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4817 * lpfc_sli_hbq_setup - configure and initialize HBQs
4818 * @phba: Pointer to HBA context object.
4820 * This function is called during the SLI initialization to configure
4821 * all the HBQs and post buffers to the HBQ. The caller is not
4822 * required to hold any locks. This function will return zero if successful
4823 * else it will return negative error code.
4826 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4828 int hbq_count
= lpfc_sli_hbq_count();
4832 uint32_t hbq_entry_index
;
4834 /* Get a Mailbox buffer to setup mailbox
4835 * commands for HBA initialization
4837 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4844 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4845 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4846 phba
->hbq_in_use
= 1;
4848 hbq_entry_index
= 0;
4849 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4850 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4851 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4852 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4853 phba
->hbqs
[hbqno
].entry_count
=
4854 lpfc_hbq_defs
[hbqno
]->entry_count
;
4855 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4856 hbq_entry_index
, pmb
);
4857 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4859 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4860 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4861 mbxStatus <status>, ring <num> */
4863 lpfc_printf_log(phba
, KERN_ERR
,
4864 LOG_SLI
| LOG_VPORT
,
4865 "1805 Adapter failed to init. "
4866 "Data: x%x x%x x%x\n",
4868 pmbox
->mbxStatus
, hbqno
);
4870 phba
->link_state
= LPFC_HBA_ERROR
;
4871 mempool_free(pmb
, phba
->mbox_mem_pool
);
4875 phba
->hbq_count
= hbq_count
;
4877 mempool_free(pmb
, phba
->mbox_mem_pool
);
4879 /* Initially populate or replenish the HBQs */
4880 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4881 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4886 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4887 * @phba: Pointer to HBA context object.
4889 * This function is called during the SLI initialization to configure
4890 * all the HBQs and post buffers to the HBQ. The caller is not
4891 * required to hold any locks. This function will return zero if successful
4892 * else it will return negative error code.
4895 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4897 phba
->hbq_in_use
= 1;
4898 phba
->hbqs
[LPFC_ELS_HBQ
].entry_count
=
4899 lpfc_hbq_defs
[LPFC_ELS_HBQ
]->entry_count
;
4900 phba
->hbq_count
= 1;
4901 lpfc_sli_hbqbuf_init_hbqs(phba
, LPFC_ELS_HBQ
);
4902 /* Initially populate or replenish the HBQs */
4907 * lpfc_sli_config_port - Issue config port mailbox command
4908 * @phba: Pointer to HBA context object.
4909 * @sli_mode: sli mode - 2/3
4911 * This function is called by the sli initialization code path
4912 * to issue config_port mailbox command. This function restarts the
4913 * HBA firmware and issues a config_port mailbox command to configure
4914 * the SLI interface in the sli mode specified by sli_mode
4915 * variable. The caller is not required to hold any locks.
4916 * The function returns 0 if successful, else returns negative error
4920 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4923 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4925 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4927 phba
->link_state
= LPFC_HBA_ERROR
;
4931 phba
->sli_rev
= sli_mode
;
4932 while (resetcount
< 2 && !done
) {
4933 spin_lock_irq(&phba
->hbalock
);
4934 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4935 spin_unlock_irq(&phba
->hbalock
);
4936 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4937 lpfc_sli_brdrestart(phba
);
4938 rc
= lpfc_sli_chipset_init(phba
);
4942 spin_lock_irq(&phba
->hbalock
);
4943 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4944 spin_unlock_irq(&phba
->hbalock
);
4947 /* Call pre CONFIG_PORT mailbox command initialization. A
4948 * value of 0 means the call was successful. Any other
4949 * nonzero value is a failure, but if ERESTART is returned,
4950 * the driver may reset the HBA and try again.
4952 rc
= lpfc_config_port_prep(phba
);
4953 if (rc
== -ERESTART
) {
4954 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4959 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4960 lpfc_config_port(phba
, pmb
);
4961 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4962 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4963 LPFC_SLI3_HBQ_ENABLED
|
4964 LPFC_SLI3_CRP_ENABLED
|
4965 LPFC_SLI3_BG_ENABLED
|
4966 LPFC_SLI3_DSS_ENABLED
);
4967 if (rc
!= MBX_SUCCESS
) {
4968 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4969 "0442 Adapter failed to init, mbxCmd x%x "
4970 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4971 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4972 spin_lock_irq(&phba
->hbalock
);
4973 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4974 spin_unlock_irq(&phba
->hbalock
);
4977 /* Allow asynchronous mailbox command to go through */
4978 spin_lock_irq(&phba
->hbalock
);
4979 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4980 spin_unlock_irq(&phba
->hbalock
);
4983 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4984 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4985 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4986 "3110 Port did not grant ASABT\n");
4991 goto do_prep_failed
;
4993 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4994 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4996 goto do_prep_failed
;
4998 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4999 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
5000 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
5001 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
5002 phba
->max_vpi
: phba
->max_vports
;
5006 phba
->fips_level
= 0;
5007 phba
->fips_spec_rev
= 0;
5008 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
5009 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
5010 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
5011 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
5012 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5013 "2850 Security Crypto Active. FIPS x%d "
5015 phba
->fips_level
, phba
->fips_spec_rev
);
5017 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
5018 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5019 "2856 Config Port Security Crypto "
5021 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
5023 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
5024 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
5025 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
5026 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
5028 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
5029 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
5031 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) {
5032 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
== 0) {
5033 phba
->cfg_enable_bg
= 0;
5034 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
5035 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5036 "0443 Adapter did not grant "
5041 phba
->hbq_get
= NULL
;
5042 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
5046 mempool_free(pmb
, phba
->mbox_mem_pool
);
5052 * lpfc_sli_hba_setup - SLI initialization function
5053 * @phba: Pointer to HBA context object.
5055 * This function is the main SLI initialization function. This function
5056 * is called by the HBA initialization code, HBA reset code and HBA
5057 * error attention handler code. Caller is not required to hold any
5058 * locks. This function issues config_port mailbox command to configure
5059 * the SLI, setup iocb rings and HBQ rings. In the end the function
5060 * calls the config_port_post function to issue init_link mailbox
5061 * command and to start the discovery. The function will return zero
5062 * if successful, else it will return negative error code.
5065 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
5071 switch (phba
->cfg_sli_mode
) {
5073 if (phba
->cfg_enable_npiv
) {
5074 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
5075 "1824 NPIV enabled: Override sli_mode "
5076 "parameter (%d) to auto (0).\n",
5077 phba
->cfg_sli_mode
);
5086 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
5087 "1819 Unrecognized sli_mode parameter: %d.\n",
5088 phba
->cfg_sli_mode
);
5092 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
5094 rc
= lpfc_sli_config_port(phba
, mode
);
5096 if (rc
&& phba
->cfg_sli_mode
== 3)
5097 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
5098 "1820 Unable to select SLI-3. "
5099 "Not supported by adapter.\n");
5100 if (rc
&& mode
!= 2)
5101 rc
= lpfc_sli_config_port(phba
, 2);
5102 else if (rc
&& mode
== 2)
5103 rc
= lpfc_sli_config_port(phba
, 3);
5105 goto lpfc_sli_hba_setup_error
;
5107 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
5108 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
5109 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
5111 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5112 "2709 This device supports "
5113 "Advanced Error Reporting (AER)\n");
5114 spin_lock_irq(&phba
->hbalock
);
5115 phba
->hba_flag
|= HBA_AER_ENABLED
;
5116 spin_unlock_irq(&phba
->hbalock
);
5118 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5119 "2708 This device does not support "
5120 "Advanced Error Reporting (AER): %d\n",
5122 phba
->cfg_aer_support
= 0;
5126 if (phba
->sli_rev
== 3) {
5127 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
5128 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
5130 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
5131 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
5132 phba
->sli3_options
= 0;
5135 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5136 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
5137 phba
->sli_rev
, phba
->max_vpi
);
5138 rc
= lpfc_sli_ring_map(phba
);
5141 goto lpfc_sli_hba_setup_error
;
5143 /* Initialize VPIs. */
5144 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
5146 * The VPI bitmask and physical ID array are allocated
5147 * and initialized once only - at driver load. A port
5148 * reset doesn't need to reinitialize this memory.
5150 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
5151 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
5152 phba
->vpi_bmask
= kcalloc(longs
,
5153 sizeof(unsigned long),
5155 if (!phba
->vpi_bmask
) {
5157 goto lpfc_sli_hba_setup_error
;
5160 phba
->vpi_ids
= kcalloc(phba
->max_vpi
+ 1,
5163 if (!phba
->vpi_ids
) {
5164 kfree(phba
->vpi_bmask
);
5166 goto lpfc_sli_hba_setup_error
;
5168 for (i
= 0; i
< phba
->max_vpi
; i
++)
5169 phba
->vpi_ids
[i
] = i
;
5174 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
5175 rc
= lpfc_sli_hbq_setup(phba
);
5177 goto lpfc_sli_hba_setup_error
;
5179 spin_lock_irq(&phba
->hbalock
);
5180 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
5181 spin_unlock_irq(&phba
->hbalock
);
5183 rc
= lpfc_config_port_post(phba
);
5185 goto lpfc_sli_hba_setup_error
;
5189 lpfc_sli_hba_setup_error
:
5190 phba
->link_state
= LPFC_HBA_ERROR
;
5191 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5192 "0445 Firmware initialization failed\n");
5197 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
5198 * @phba: Pointer to HBA context object.
5199 * @mboxq: mailbox pointer.
5200 * This function issue a dump mailbox command to read config region
5201 * 23 and parse the records in the region and populate driver
5205 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
5207 LPFC_MBOXQ_t
*mboxq
;
5208 struct lpfc_dmabuf
*mp
;
5209 struct lpfc_mqe
*mqe
;
5210 uint32_t data_length
;
5213 /* Program the default value of vlan_id and fc_map */
5214 phba
->valid_vlan
= 0;
5215 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
5216 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
5217 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
5219 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5223 mqe
= &mboxq
->u
.mqe
;
5224 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
5226 goto out_free_mboxq
;
5229 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
5230 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5232 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5233 "(%d):2571 Mailbox cmd x%x Status x%x "
5234 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5235 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5236 "CQ: x%x x%x x%x x%x\n",
5237 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5238 bf_get(lpfc_mqe_command
, mqe
),
5239 bf_get(lpfc_mqe_status
, mqe
),
5240 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
5241 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
5242 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
5243 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
5244 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
5245 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
5246 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
5247 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
5248 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
5250 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5251 mboxq
->mcqe
.trailer
);
5254 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5257 goto out_free_mboxq
;
5259 data_length
= mqe
->un
.mb_words
[5];
5260 if (data_length
> DMP_RGN23_SIZE
) {
5261 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5264 goto out_free_mboxq
;
5267 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
5268 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5273 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5278 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5279 * @phba: pointer to lpfc hba data structure.
5280 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5281 * @vpd: pointer to the memory to hold resulting port vpd data.
5282 * @vpd_size: On input, the number of bytes allocated to @vpd.
5283 * On output, the number of data bytes in @vpd.
5285 * This routine executes a READ_REV SLI4 mailbox command. In
5286 * addition, this routine gets the port vpd data.
5290 * -ENOMEM - could not allocated memory.
5293 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5294 uint8_t *vpd
, uint32_t *vpd_size
)
5298 struct lpfc_dmabuf
*dmabuf
;
5299 struct lpfc_mqe
*mqe
;
5301 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5306 * Get a DMA buffer for the vpd data resulting from the READ_REV
5309 dma_size
= *vpd_size
;
5310 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, dma_size
,
5311 &dmabuf
->phys
, GFP_KERNEL
);
5312 if (!dmabuf
->virt
) {
5318 * The SLI4 implementation of READ_REV conflicts at word1,
5319 * bits 31:16 and SLI4 adds vpd functionality not present
5320 * in SLI3. This code corrects the conflicts.
5322 lpfc_read_rev(phba
, mboxq
);
5323 mqe
= &mboxq
->u
.mqe
;
5324 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
5325 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
5326 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
5327 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
5328 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
5330 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5332 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
5333 dmabuf
->virt
, dmabuf
->phys
);
5339 * The available vpd length cannot be bigger than the
5340 * DMA buffer passed to the port. Catch the less than
5341 * case and update the caller's size.
5343 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
5344 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
5346 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
5348 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
5349 dmabuf
->virt
, dmabuf
->phys
);
5355 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5356 * @phba: pointer to lpfc hba data structure.
5358 * This routine retrieves SLI4 device physical port name this PCI function
5363 * otherwise - failed to retrieve physical port name
5366 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
5368 LPFC_MBOXQ_t
*mboxq
;
5369 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
5370 struct lpfc_controller_attribute
*cntl_attr
;
5371 struct lpfc_mbx_get_port_name
*get_port_name
;
5372 void *virtaddr
= NULL
;
5373 uint32_t alloclen
, reqlen
;
5374 uint32_t shdr_status
, shdr_add_status
;
5375 union lpfc_sli4_cfg_shdr
*shdr
;
5376 char cport_name
= 0;
5379 /* We assume nothing at this point */
5380 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
5381 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
5383 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5386 /* obtain link type and link number via READ_CONFIG */
5387 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
5388 lpfc_sli4_read_config(phba
);
5389 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
5390 goto retrieve_ppname
;
5392 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5393 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
5394 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5395 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
5396 LPFC_SLI4_MBX_NEMBED
);
5397 if (alloclen
< reqlen
) {
5398 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5399 "3084 Allocated DMA memory size (%d) is "
5400 "less than the requested DMA memory size "
5401 "(%d)\n", alloclen
, reqlen
);
5403 goto out_free_mboxq
;
5405 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5406 virtaddr
= mboxq
->sge_array
->addr
[0];
5407 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
5408 shdr
= &mbx_cntl_attr
->cfg_shdr
;
5409 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5410 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5411 if (shdr_status
|| shdr_add_status
|| rc
) {
5412 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5413 "3085 Mailbox x%x (x%x/x%x) failed, "
5414 "rc:x%x, status:x%x, add_status:x%x\n",
5415 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5416 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5417 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5418 rc
, shdr_status
, shdr_add_status
);
5420 goto out_free_mboxq
;
5422 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
5423 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
5424 phba
->sli4_hba
.lnk_info
.lnk_tp
=
5425 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
5426 phba
->sli4_hba
.lnk_info
.lnk_no
=
5427 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
5428 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5429 "3086 lnk_type:%d, lnk_numb:%d\n",
5430 phba
->sli4_hba
.lnk_info
.lnk_tp
,
5431 phba
->sli4_hba
.lnk_info
.lnk_no
);
5434 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5435 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
5436 sizeof(struct lpfc_mbx_get_port_name
) -
5437 sizeof(struct lpfc_sli4_cfg_mhdr
),
5438 LPFC_SLI4_MBX_EMBED
);
5439 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
5440 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
5441 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
5442 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
5443 phba
->sli4_hba
.lnk_info
.lnk_tp
);
5444 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5445 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5446 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5447 if (shdr_status
|| shdr_add_status
|| rc
) {
5448 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5449 "3087 Mailbox x%x (x%x/x%x) failed: "
5450 "rc:x%x, status:x%x, add_status:x%x\n",
5451 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5452 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5453 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5454 rc
, shdr_status
, shdr_add_status
);
5456 goto out_free_mboxq
;
5458 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
5459 case LPFC_LINK_NUMBER_0
:
5460 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
5461 &get_port_name
->u
.response
);
5462 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5464 case LPFC_LINK_NUMBER_1
:
5465 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
5466 &get_port_name
->u
.response
);
5467 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5469 case LPFC_LINK_NUMBER_2
:
5470 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
5471 &get_port_name
->u
.response
);
5472 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5474 case LPFC_LINK_NUMBER_3
:
5475 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
5476 &get_port_name
->u
.response
);
5477 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5483 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
5484 phba
->Port
[0] = cport_name
;
5485 phba
->Port
[1] = '\0';
5486 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5487 "3091 SLI get port name: %s\n", phba
->Port
);
5491 if (rc
!= MBX_TIMEOUT
) {
5492 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
5493 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
5495 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5501 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5502 * @phba: pointer to lpfc hba data structure.
5504 * This routine is called to explicitly arm the SLI4 device's completion and
5508 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
5511 struct lpfc_sli4_hba
*sli4_hba
= &phba
->sli4_hba
;
5513 sli4_hba
->sli4_cq_release(sli4_hba
->mbx_cq
, LPFC_QUEUE_REARM
);
5514 sli4_hba
->sli4_cq_release(sli4_hba
->els_cq
, LPFC_QUEUE_REARM
);
5515 if (sli4_hba
->nvmels_cq
)
5516 sli4_hba
->sli4_cq_release(sli4_hba
->nvmels_cq
,
5519 if (sli4_hba
->fcp_cq
)
5520 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
5521 sli4_hba
->sli4_cq_release(sli4_hba
->fcp_cq
[qidx
],
5524 if (sli4_hba
->nvme_cq
)
5525 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
5526 sli4_hba
->sli4_cq_release(sli4_hba
->nvme_cq
[qidx
],
5530 sli4_hba
->sli4_cq_release(sli4_hba
->oas_cq
, LPFC_QUEUE_REARM
);
5532 if (sli4_hba
->hba_eq
)
5533 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++)
5534 sli4_hba
->sli4_eq_release(sli4_hba
->hba_eq
[qidx
],
5537 if (phba
->nvmet_support
) {
5538 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++) {
5539 sli4_hba
->sli4_cq_release(
5540 sli4_hba
->nvmet_cqset
[qidx
],
5546 sli4_hba
->sli4_eq_release(sli4_hba
->fof_eq
, LPFC_QUEUE_REARM
);
5550 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5551 * @phba: Pointer to HBA context object.
5552 * @type: The resource extent type.
5553 * @extnt_count: buffer to hold port available extent count.
5554 * @extnt_size: buffer to hold element count per extent.
5556 * This function calls the port and retrievs the number of available
5557 * extents and their size for a particular extent type.
5559 * Returns: 0 if successful. Nonzero otherwise.
5562 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5563 uint16_t *extnt_count
, uint16_t *extnt_size
)
5568 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5571 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5575 /* Find out how many extents are available for this resource type */
5576 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5577 sizeof(struct lpfc_sli4_cfg_mhdr
));
5578 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5579 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5580 length
, LPFC_SLI4_MBX_EMBED
);
5582 /* Send an extents count of 0 - the GET doesn't use it. */
5583 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5584 LPFC_SLI4_MBX_EMBED
);
5590 if (!phba
->sli4_hba
.intr_enable
)
5591 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5593 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5594 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5601 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5602 if (bf_get(lpfc_mbox_hdr_status
,
5603 &rsrc_info
->header
.cfg_shdr
.response
)) {
5604 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5605 "2930 Failed to get resource extents "
5606 "Status 0x%x Add'l Status 0x%x\n",
5607 bf_get(lpfc_mbox_hdr_status
,
5608 &rsrc_info
->header
.cfg_shdr
.response
),
5609 bf_get(lpfc_mbox_hdr_add_status
,
5610 &rsrc_info
->header
.cfg_shdr
.response
));
5615 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5617 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5620 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5621 "3162 Retrieved extents type-%d from port: count:%d, "
5622 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5625 mempool_free(mbox
, phba
->mbox_mem_pool
);
5630 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5631 * @phba: Pointer to HBA context object.
5632 * @type: The extent type to check.
5634 * This function reads the current available extents from the port and checks
5635 * if the extent count or extent size has changed since the last access.
5636 * Callers use this routine post port reset to understand if there is a
5637 * extent reprovisioning requirement.
5640 * -Error: error indicates problem.
5641 * 1: Extent count or size has changed.
5645 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5647 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5648 uint16_t size_diff
, rsrc_ext_size
;
5650 struct lpfc_rsrc_blks
*rsrc_entry
;
5651 struct list_head
*rsrc_blk_list
= NULL
;
5655 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5662 case LPFC_RSC_TYPE_FCOE_RPI
:
5663 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5665 case LPFC_RSC_TYPE_FCOE_VPI
:
5666 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5668 case LPFC_RSC_TYPE_FCOE_XRI
:
5669 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5671 case LPFC_RSC_TYPE_FCOE_VFI
:
5672 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5678 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5680 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5684 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5691 * lpfc_sli4_cfg_post_extnts -
5692 * @phba: Pointer to HBA context object.
5693 * @extnt_cnt - number of available extents.
5694 * @type - the extent type (rpi, xri, vfi, vpi).
5695 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5696 * @mbox - pointer to the caller's allocated mailbox structure.
5698 * This function executes the extents allocation request. It also
5699 * takes care of the amount of memory needed to allocate or get the
5700 * allocated extents. It is the caller's responsibility to evaluate
5704 * -Error: Error value describes the condition found.
5708 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5709 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5714 uint32_t alloc_len
, mbox_tmo
;
5716 /* Calculate the total requested length of the dma memory */
5717 req_len
= extnt_cnt
* sizeof(uint16_t);
5720 * Calculate the size of an embedded mailbox. The uint32_t
5721 * accounts for extents-specific word.
5723 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5727 * Presume the allocation and response will fit into an embedded
5728 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5730 *emb
= LPFC_SLI4_MBX_EMBED
;
5731 if (req_len
> emb_len
) {
5732 req_len
= extnt_cnt
* sizeof(uint16_t) +
5733 sizeof(union lpfc_sli4_cfg_shdr
) +
5735 *emb
= LPFC_SLI4_MBX_NEMBED
;
5738 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5739 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5741 if (alloc_len
< req_len
) {
5742 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5743 "2982 Allocated DMA memory size (x%x) is "
5744 "less than the requested DMA memory "
5745 "size (x%x)\n", alloc_len
, req_len
);
5748 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5752 if (!phba
->sli4_hba
.intr_enable
)
5753 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5755 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5756 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5765 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5766 * @phba: Pointer to HBA context object.
5767 * @type: The resource extent type to allocate.
5769 * This function allocates the number of elements for the specified
5773 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5776 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5777 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5780 unsigned long longs
;
5781 unsigned long *bmask
;
5782 struct lpfc_rsrc_blks
*rsrc_blks
;
5785 struct lpfc_id_range
*id_array
= NULL
;
5786 void *virtaddr
= NULL
;
5787 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5788 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5789 struct list_head
*ext_blk_list
;
5791 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5797 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5798 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5799 "3009 No available Resource Extents "
5800 "for resource type 0x%x: Count: 0x%x, "
5801 "Size 0x%x\n", type
, rsrc_cnt
,
5806 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5807 "2903 Post resource extents type-0x%x: "
5808 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5810 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5814 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5821 * Figure out where the response is located. Then get local pointers
5822 * to the response data. The port does not guarantee to respond to
5823 * all extents counts request so update the local variable with the
5824 * allocated count from the port.
5826 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5827 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5828 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5829 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5831 virtaddr
= mbox
->sge_array
->addr
[0];
5832 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5833 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5834 id_array
= &n_rsrc
->id
;
5837 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5838 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5841 * Based on the resource size and count, correct the base and max
5844 length
= sizeof(struct lpfc_rsrc_blks
);
5846 case LPFC_RSC_TYPE_FCOE_RPI
:
5847 phba
->sli4_hba
.rpi_bmask
= kcalloc(longs
,
5848 sizeof(unsigned long),
5850 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5854 phba
->sli4_hba
.rpi_ids
= kcalloc(rsrc_id_cnt
,
5857 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5858 kfree(phba
->sli4_hba
.rpi_bmask
);
5864 * The next_rpi was initialized with the maximum available
5865 * count but the port may allocate a smaller number. Catch
5866 * that case and update the next_rpi.
5868 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5870 /* Initialize local ptrs for common extent processing later. */
5871 bmask
= phba
->sli4_hba
.rpi_bmask
;
5872 ids
= phba
->sli4_hba
.rpi_ids
;
5873 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5875 case LPFC_RSC_TYPE_FCOE_VPI
:
5876 phba
->vpi_bmask
= kcalloc(longs
, sizeof(unsigned long),
5878 if (unlikely(!phba
->vpi_bmask
)) {
5882 phba
->vpi_ids
= kcalloc(rsrc_id_cnt
, sizeof(uint16_t),
5884 if (unlikely(!phba
->vpi_ids
)) {
5885 kfree(phba
->vpi_bmask
);
5890 /* Initialize local ptrs for common extent processing later. */
5891 bmask
= phba
->vpi_bmask
;
5892 ids
= phba
->vpi_ids
;
5893 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5895 case LPFC_RSC_TYPE_FCOE_XRI
:
5896 phba
->sli4_hba
.xri_bmask
= kcalloc(longs
,
5897 sizeof(unsigned long),
5899 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5903 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5904 phba
->sli4_hba
.xri_ids
= kcalloc(rsrc_id_cnt
,
5907 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5908 kfree(phba
->sli4_hba
.xri_bmask
);
5913 /* Initialize local ptrs for common extent processing later. */
5914 bmask
= phba
->sli4_hba
.xri_bmask
;
5915 ids
= phba
->sli4_hba
.xri_ids
;
5916 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5918 case LPFC_RSC_TYPE_FCOE_VFI
:
5919 phba
->sli4_hba
.vfi_bmask
= kcalloc(longs
,
5920 sizeof(unsigned long),
5922 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5926 phba
->sli4_hba
.vfi_ids
= kcalloc(rsrc_id_cnt
,
5929 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5930 kfree(phba
->sli4_hba
.vfi_bmask
);
5935 /* Initialize local ptrs for common extent processing later. */
5936 bmask
= phba
->sli4_hba
.vfi_bmask
;
5937 ids
= phba
->sli4_hba
.vfi_ids
;
5938 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5941 /* Unsupported Opcode. Fail call. */
5945 ext_blk_list
= NULL
;
5950 * Complete initializing the extent configuration with the
5951 * allocated ids assigned to this function. The bitmask serves
5952 * as an index into the array and manages the available ids. The
5953 * array just stores the ids communicated to the port via the wqes.
5955 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5957 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5960 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5963 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5964 if (unlikely(!rsrc_blks
)) {
5970 rsrc_blks
->rsrc_start
= rsrc_id
;
5971 rsrc_blks
->rsrc_size
= rsrc_size
;
5972 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5973 rsrc_start
= rsrc_id
;
5974 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0)) {
5975 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5976 lpfc_sli4_get_iocb_cnt(phba
);
5977 phba
->sli4_hba
.nvme_xri_start
=
5978 phba
->sli4_hba
.scsi_xri_start
+
5979 phba
->sli4_hba
.scsi_xri_max
;
5982 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5987 /* Entire word processed. Get next word.*/
5992 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5999 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
6000 * @phba: Pointer to HBA context object.
6001 * @type: the extent's type.
6003 * This function deallocates all extents of a particular resource type.
6004 * SLI4 does not allow for deallocating a particular extent range. It
6005 * is the caller's responsibility to release all kernel memory resources.
6008 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
6011 uint32_t length
, mbox_tmo
= 0;
6013 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
6014 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
6016 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6021 * This function sends an embedded mailbox because it only sends the
6022 * the resource type. All extents of this type are released by the
6025 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
6026 sizeof(struct lpfc_sli4_cfg_mhdr
));
6027 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6028 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
6029 length
, LPFC_SLI4_MBX_EMBED
);
6031 /* Send an extents count of 0 - the dealloc doesn't use it. */
6032 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
6033 LPFC_SLI4_MBX_EMBED
);
6038 if (!phba
->sli4_hba
.intr_enable
)
6039 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6041 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
6042 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6049 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
6050 if (bf_get(lpfc_mbox_hdr_status
,
6051 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
6052 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
6053 "2919 Failed to release resource extents "
6054 "for type %d - Status 0x%x Add'l Status 0x%x. "
6055 "Resource memory not released.\n",
6057 bf_get(lpfc_mbox_hdr_status
,
6058 &dealloc_rsrc
->header
.cfg_shdr
.response
),
6059 bf_get(lpfc_mbox_hdr_add_status
,
6060 &dealloc_rsrc
->header
.cfg_shdr
.response
));
6065 /* Release kernel memory resources for the specific type. */
6067 case LPFC_RSC_TYPE_FCOE_VPI
:
6068 kfree(phba
->vpi_bmask
);
6069 kfree(phba
->vpi_ids
);
6070 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6071 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
6072 &phba
->lpfc_vpi_blk_list
, list
) {
6073 list_del_init(&rsrc_blk
->list
);
6076 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
6078 case LPFC_RSC_TYPE_FCOE_XRI
:
6079 kfree(phba
->sli4_hba
.xri_bmask
);
6080 kfree(phba
->sli4_hba
.xri_ids
);
6081 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
6082 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
6083 list_del_init(&rsrc_blk
->list
);
6087 case LPFC_RSC_TYPE_FCOE_VFI
:
6088 kfree(phba
->sli4_hba
.vfi_bmask
);
6089 kfree(phba
->sli4_hba
.vfi_ids
);
6090 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6091 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
6092 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
6093 list_del_init(&rsrc_blk
->list
);
6097 case LPFC_RSC_TYPE_FCOE_RPI
:
6098 /* RPI bitmask and physical id array are cleaned up earlier. */
6099 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
6100 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
6101 list_del_init(&rsrc_blk
->list
);
6109 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6112 mempool_free(mbox
, phba
->mbox_mem_pool
);
6117 lpfc_set_features(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
,
6122 len
= sizeof(struct lpfc_mbx_set_feature
) -
6123 sizeof(struct lpfc_sli4_cfg_mhdr
);
6124 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6125 LPFC_MBOX_OPCODE_SET_FEATURES
, len
,
6126 LPFC_SLI4_MBX_EMBED
);
6129 case LPFC_SET_UE_RECOVERY
:
6130 bf_set(lpfc_mbx_set_feature_UER
,
6131 &mbox
->u
.mqe
.un
.set_feature
, 1);
6132 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_UE_RECOVERY
;
6133 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
6135 case LPFC_SET_MDS_DIAGS
:
6136 bf_set(lpfc_mbx_set_feature_mds
,
6137 &mbox
->u
.mqe
.un
.set_feature
, 1);
6138 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk
,
6139 &mbox
->u
.mqe
.un
.set_feature
, 1);
6140 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_MDS_DIAGS
;
6141 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
6149 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
6150 * @phba: Pointer to HBA context object.
6152 * This function allocates all SLI4 resource identifiers.
6155 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
6157 int i
, rc
, error
= 0;
6158 uint16_t count
, base
;
6159 unsigned long longs
;
6161 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
6162 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
6163 if (phba
->sli4_hba
.extents_in_use
) {
6165 * The port supports resource extents. The XRI, VPI, VFI, RPI
6166 * resource extent count must be read and allocated before
6167 * provisioning the resource id arrays.
6169 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
6170 LPFC_IDX_RSRC_RDY
) {
6172 * Extent-based resources are set - the driver could
6173 * be in a port reset. Figure out if any corrective
6174 * actions need to be taken.
6176 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
6177 LPFC_RSC_TYPE_FCOE_VFI
);
6180 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
6181 LPFC_RSC_TYPE_FCOE_VPI
);
6184 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
6185 LPFC_RSC_TYPE_FCOE_XRI
);
6188 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
6189 LPFC_RSC_TYPE_FCOE_RPI
);
6194 * It's possible that the number of resources
6195 * provided to this port instance changed between
6196 * resets. Detect this condition and reallocate
6197 * resources. Otherwise, there is no action.
6200 lpfc_printf_log(phba
, KERN_INFO
,
6201 LOG_MBOX
| LOG_INIT
,
6202 "2931 Detected extent resource "
6203 "change. Reallocating all "
6205 rc
= lpfc_sli4_dealloc_extent(phba
,
6206 LPFC_RSC_TYPE_FCOE_VFI
);
6207 rc
= lpfc_sli4_dealloc_extent(phba
,
6208 LPFC_RSC_TYPE_FCOE_VPI
);
6209 rc
= lpfc_sli4_dealloc_extent(phba
,
6210 LPFC_RSC_TYPE_FCOE_XRI
);
6211 rc
= lpfc_sli4_dealloc_extent(phba
,
6212 LPFC_RSC_TYPE_FCOE_RPI
);
6217 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
6221 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
6225 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
6229 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
6232 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
6237 * The port does not support resource extents. The XRI, VPI,
6238 * VFI, RPI resource ids were determined from READ_CONFIG.
6239 * Just allocate the bitmasks and provision the resource id
6240 * arrays. If a port reset is active, the resources don't
6241 * need any action - just exit.
6243 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
6244 LPFC_IDX_RSRC_RDY
) {
6245 lpfc_sli4_dealloc_resource_identifiers(phba
);
6246 lpfc_sli4_remove_rpis(phba
);
6249 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
6251 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6252 "3279 Invalid provisioning of "
6257 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
6258 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6259 phba
->sli4_hba
.rpi_bmask
= kcalloc(longs
,
6260 sizeof(unsigned long),
6262 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
6266 phba
->sli4_hba
.rpi_ids
= kcalloc(count
, sizeof(uint16_t),
6268 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
6270 goto free_rpi_bmask
;
6273 for (i
= 0; i
< count
; i
++)
6274 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
6277 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
6279 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6280 "3280 Invalid provisioning of "
6285 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
6286 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6287 phba
->vpi_bmask
= kcalloc(longs
, sizeof(unsigned long),
6289 if (unlikely(!phba
->vpi_bmask
)) {
6293 phba
->vpi_ids
= kcalloc(count
, sizeof(uint16_t),
6295 if (unlikely(!phba
->vpi_ids
)) {
6297 goto free_vpi_bmask
;
6300 for (i
= 0; i
< count
; i
++)
6301 phba
->vpi_ids
[i
] = base
+ i
;
6304 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
6306 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6307 "3281 Invalid provisioning of "
6312 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
6313 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6314 phba
->sli4_hba
.xri_bmask
= kcalloc(longs
,
6315 sizeof(unsigned long),
6317 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
6321 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
6322 phba
->sli4_hba
.xri_ids
= kcalloc(count
, sizeof(uint16_t),
6324 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
6326 goto free_xri_bmask
;
6329 for (i
= 0; i
< count
; i
++)
6330 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
6333 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
6335 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6336 "3282 Invalid provisioning of "
6341 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
6342 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6343 phba
->sli4_hba
.vfi_bmask
= kcalloc(longs
,
6344 sizeof(unsigned long),
6346 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
6350 phba
->sli4_hba
.vfi_ids
= kcalloc(count
, sizeof(uint16_t),
6352 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
6354 goto free_vfi_bmask
;
6357 for (i
= 0; i
< count
; i
++)
6358 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
6361 * Mark all resources ready. An HBA reset doesn't need
6362 * to reset the initialization.
6364 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
6370 kfree(phba
->sli4_hba
.vfi_bmask
);
6371 phba
->sli4_hba
.vfi_bmask
= NULL
;
6373 kfree(phba
->sli4_hba
.xri_ids
);
6374 phba
->sli4_hba
.xri_ids
= NULL
;
6376 kfree(phba
->sli4_hba
.xri_bmask
);
6377 phba
->sli4_hba
.xri_bmask
= NULL
;
6379 kfree(phba
->vpi_ids
);
6380 phba
->vpi_ids
= NULL
;
6382 kfree(phba
->vpi_bmask
);
6383 phba
->vpi_bmask
= NULL
;
6385 kfree(phba
->sli4_hba
.rpi_ids
);
6386 phba
->sli4_hba
.rpi_ids
= NULL
;
6388 kfree(phba
->sli4_hba
.rpi_bmask
);
6389 phba
->sli4_hba
.rpi_bmask
= NULL
;
6395 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6396 * @phba: Pointer to HBA context object.
6398 * This function allocates the number of elements for the specified
6402 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
6404 if (phba
->sli4_hba
.extents_in_use
) {
6405 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
6406 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
6407 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
6408 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
6410 kfree(phba
->vpi_bmask
);
6411 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
6412 kfree(phba
->vpi_ids
);
6413 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6414 kfree(phba
->sli4_hba
.xri_bmask
);
6415 kfree(phba
->sli4_hba
.xri_ids
);
6416 kfree(phba
->sli4_hba
.vfi_bmask
);
6417 kfree(phba
->sli4_hba
.vfi_ids
);
6418 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6419 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6426 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6427 * @phba: Pointer to HBA context object.
6428 * @type: The resource extent type.
6429 * @extnt_count: buffer to hold port extent count response
6430 * @extnt_size: buffer to hold port extent size response.
6432 * This function calls the port to read the host allocated extents
6433 * for a particular type.
6436 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
6437 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
6441 uint16_t curr_blks
= 0;
6442 uint32_t req_len
, emb_len
;
6443 uint32_t alloc_len
, mbox_tmo
;
6444 struct list_head
*blk_list_head
;
6445 struct lpfc_rsrc_blks
*rsrc_blk
;
6447 void *virtaddr
= NULL
;
6448 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
6449 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
6450 union lpfc_sli4_cfg_shdr
*shdr
;
6453 case LPFC_RSC_TYPE_FCOE_VPI
:
6454 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
6456 case LPFC_RSC_TYPE_FCOE_XRI
:
6457 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
6459 case LPFC_RSC_TYPE_FCOE_VFI
:
6460 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
6462 case LPFC_RSC_TYPE_FCOE_RPI
:
6463 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
6469 /* Count the number of extents currently allocatd for this type. */
6470 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
6471 if (curr_blks
== 0) {
6473 * The GET_ALLOCATED mailbox does not return the size,
6474 * just the count. The size should be just the size
6475 * stored in the current allocated block and all sizes
6476 * for an extent type are the same so set the return
6479 *extnt_size
= rsrc_blk
->rsrc_size
;
6485 * Calculate the size of an embedded mailbox. The uint32_t
6486 * accounts for extents-specific word.
6488 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
6492 * Presume the allocation and response will fit into an embedded
6493 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6495 emb
= LPFC_SLI4_MBX_EMBED
;
6497 if (req_len
> emb_len
) {
6498 req_len
= curr_blks
* sizeof(uint16_t) +
6499 sizeof(union lpfc_sli4_cfg_shdr
) +
6501 emb
= LPFC_SLI4_MBX_NEMBED
;
6504 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6507 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
6509 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6510 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
6512 if (alloc_len
< req_len
) {
6513 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6514 "2983 Allocated DMA memory size (x%x) is "
6515 "less than the requested DMA memory "
6516 "size (x%x)\n", alloc_len
, req_len
);
6520 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
6526 if (!phba
->sli4_hba
.intr_enable
)
6527 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6529 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
6530 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6539 * Figure out where the response is located. Then get local pointers
6540 * to the response data. The port does not guarantee to respond to
6541 * all extents counts request so update the local variable with the
6542 * allocated count from the port.
6544 if (emb
== LPFC_SLI4_MBX_EMBED
) {
6545 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
6546 shdr
= &rsrc_ext
->header
.cfg_shdr
;
6547 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
6549 virtaddr
= mbox
->sge_array
->addr
[0];
6550 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
6551 shdr
= &n_rsrc
->cfg_shdr
;
6552 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
6555 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
6556 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
6557 "2984 Failed to read allocated resources "
6558 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6560 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
6561 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
6566 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
6571 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
6572 * @phba: pointer to lpfc hba data structure.
6573 * @pring: Pointer to driver SLI ring object.
6574 * @sgl_list: linked link of sgl buffers to post
6575 * @cnt: number of linked list buffers
6577 * This routine walks the list of buffers that have been allocated and
6578 * repost them to the port by using SGL block post. This is needed after a
6579 * pci_function_reset/warm_start or start. It attempts to construct blocks
6580 * of buffer sgls which contains contiguous xris and uses the non-embedded
6581 * SGL block post mailbox commands to post them to the port. For single
6582 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6583 * mailbox command for posting.
6585 * Returns: 0 = success, non-zero failure.
6588 lpfc_sli4_repost_sgl_list(struct lpfc_hba
*phba
,
6589 struct list_head
*sgl_list
, int cnt
)
6591 struct lpfc_sglq
*sglq_entry
= NULL
;
6592 struct lpfc_sglq
*sglq_entry_next
= NULL
;
6593 struct lpfc_sglq
*sglq_entry_first
= NULL
;
6594 int status
, total_cnt
;
6595 int post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
6596 int last_xritag
= NO_XRI
;
6597 LIST_HEAD(prep_sgl_list
);
6598 LIST_HEAD(blck_sgl_list
);
6599 LIST_HEAD(allc_sgl_list
);
6600 LIST_HEAD(post_sgl_list
);
6601 LIST_HEAD(free_sgl_list
);
6603 spin_lock_irq(&phba
->hbalock
);
6604 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6605 list_splice_init(sgl_list
, &allc_sgl_list
);
6606 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6607 spin_unlock_irq(&phba
->hbalock
);
6610 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6611 &allc_sgl_list
, list
) {
6612 list_del_init(&sglq_entry
->list
);
6614 if ((last_xritag
!= NO_XRI
) &&
6615 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6616 /* a hole in xri block, form a sgl posting block */
6617 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6618 post_cnt
= block_cnt
- 1;
6619 /* prepare list for next posting block */
6620 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6623 /* prepare list for next posting block */
6624 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6625 /* enough sgls for non-embed sgl mbox command */
6626 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6627 list_splice_init(&prep_sgl_list
,
6629 post_cnt
= block_cnt
;
6635 /* keep track of last sgl's xritag */
6636 last_xritag
= sglq_entry
->sli4_xritag
;
6638 /* end of repost sgl list condition for buffers */
6639 if (num_posted
== total_cnt
) {
6640 if (post_cnt
== 0) {
6641 list_splice_init(&prep_sgl_list
,
6643 post_cnt
= block_cnt
;
6644 } else if (block_cnt
== 1) {
6645 status
= lpfc_sli4_post_sgl(phba
,
6646 sglq_entry
->phys
, 0,
6647 sglq_entry
->sli4_xritag
);
6649 /* successful, put sgl to posted list */
6650 list_add_tail(&sglq_entry
->list
,
6653 /* Failure, put sgl to free list */
6654 lpfc_printf_log(phba
, KERN_WARNING
,
6656 "3159 Failed to post "
6657 "sgl, xritag:x%x\n",
6658 sglq_entry
->sli4_xritag
);
6659 list_add_tail(&sglq_entry
->list
,
6666 /* continue until a nembed page worth of sgls */
6670 /* post the buffer list sgls as a block */
6671 status
= lpfc_sli4_post_sgl_list(phba
, &blck_sgl_list
,
6675 /* success, put sgl list to posted sgl list */
6676 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6678 /* Failure, put sgl list to free sgl list */
6679 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6682 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6683 "3160 Failed to post sgl-list, "
6685 sglq_entry_first
->sli4_xritag
,
6686 (sglq_entry_first
->sli4_xritag
+
6688 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6689 total_cnt
-= post_cnt
;
6692 /* don't reset xirtag due to hole in xri block */
6694 last_xritag
= NO_XRI
;
6696 /* reset sgl post count for next round of posting */
6700 /* free the sgls failed to post */
6701 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6703 /* push sgls posted to the available list */
6704 if (!list_empty(&post_sgl_list
)) {
6705 spin_lock_irq(&phba
->hbalock
);
6706 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6707 list_splice_init(&post_sgl_list
, sgl_list
);
6708 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6709 spin_unlock_irq(&phba
->hbalock
);
6711 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6712 "3161 Failure to post sgl to port.\n");
6716 /* return the number of XRIs actually posted */
6721 lpfc_set_host_data(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
6725 len
= sizeof(struct lpfc_mbx_set_host_data
) -
6726 sizeof(struct lpfc_sli4_cfg_mhdr
);
6727 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6728 LPFC_MBOX_OPCODE_SET_HOST_DATA
, len
,
6729 LPFC_SLI4_MBX_EMBED
);
6731 mbox
->u
.mqe
.un
.set_host_data
.param_id
= LPFC_SET_HOST_OS_DRIVER_VERSION
;
6732 mbox
->u
.mqe
.un
.set_host_data
.param_len
=
6733 LPFC_HOST_OS_DRIVER_VERSION_SIZE
;
6734 snprintf(mbox
->u
.mqe
.un
.set_host_data
.data
,
6735 LPFC_HOST_OS_DRIVER_VERSION_SIZE
,
6736 "Linux %s v"LPFC_DRIVER_VERSION
,
6737 (phba
->hba_flag
& HBA_FCOE_MODE
) ? "FCoE" : "FC");
6741 lpfc_post_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
6742 struct lpfc_queue
*drq
, int count
, int idx
)
6745 struct lpfc_rqe hrqe
;
6746 struct lpfc_rqe drqe
;
6747 struct lpfc_rqb
*rqbp
;
6748 unsigned long flags
;
6749 struct rqb_dmabuf
*rqb_buffer
;
6750 LIST_HEAD(rqb_buf_list
);
6752 spin_lock_irqsave(&phba
->hbalock
, flags
);
6754 for (i
= 0; i
< count
; i
++) {
6755 /* IF RQ is already full, don't bother */
6756 if (rqbp
->buffer_count
+ i
>= rqbp
->entry_count
- 1)
6758 rqb_buffer
= rqbp
->rqb_alloc_buffer(phba
);
6761 rqb_buffer
->hrq
= hrq
;
6762 rqb_buffer
->drq
= drq
;
6763 rqb_buffer
->idx
= idx
;
6764 list_add_tail(&rqb_buffer
->hbuf
.list
, &rqb_buf_list
);
6766 while (!list_empty(&rqb_buf_list
)) {
6767 list_remove_head(&rqb_buf_list
, rqb_buffer
, struct rqb_dmabuf
,
6770 hrqe
.address_lo
= putPaddrLow(rqb_buffer
->hbuf
.phys
);
6771 hrqe
.address_hi
= putPaddrHigh(rqb_buffer
->hbuf
.phys
);
6772 drqe
.address_lo
= putPaddrLow(rqb_buffer
->dbuf
.phys
);
6773 drqe
.address_hi
= putPaddrHigh(rqb_buffer
->dbuf
.phys
);
6774 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
6776 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6777 "6421 Cannot post to HRQ %d: %x %x %x "
6785 rqbp
->rqb_free_buffer(phba
, rqb_buffer
);
6787 list_add_tail(&rqb_buffer
->hbuf
.list
,
6788 &rqbp
->rqb_buffer_list
);
6789 rqbp
->buffer_count
++;
6792 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6797 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
6798 * @phba: Pointer to HBA context object.
6800 * This function is the main SLI4 device initialization PCI function. This
6801 * function is called by the HBA initialization code, HBA reset code and
6802 * HBA error attention handler code. Caller is not required to hold any
6806 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6809 LPFC_MBOXQ_t
*mboxq
;
6810 struct lpfc_mqe
*mqe
;
6813 uint32_t ftr_rsp
= 0;
6814 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6815 struct lpfc_vport
*vport
= phba
->pport
;
6816 struct lpfc_dmabuf
*mp
;
6817 struct lpfc_rqb
*rqbp
;
6819 /* Perform a PCI function reset to start from clean */
6820 rc
= lpfc_pci_function_reset(phba
);
6824 /* Check the HBA Host Status Register for readyness */
6825 rc
= lpfc_sli4_post_status_check(phba
);
6829 spin_lock_irq(&phba
->hbalock
);
6830 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6831 spin_unlock_irq(&phba
->hbalock
);
6835 * Allocate a single mailbox container for initializing the
6838 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6842 /* Issue READ_REV to collect vpd and FW information. */
6843 vpd_size
= SLI4_PAGE_SIZE
;
6844 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6850 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6856 mqe
= &mboxq
->u
.mqe
;
6857 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6858 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
)) {
6859 phba
->hba_flag
|= HBA_FCOE_MODE
;
6860 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
6862 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6865 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6867 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6869 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6871 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6873 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6874 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6875 "0376 READ_REV Error. SLI Level %d "
6876 "FCoE enabled %d\n",
6877 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6884 * Continue initialization with default values even if driver failed
6885 * to read FCoE param config regions, only read parameters if the
6888 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6889 lpfc_sli4_read_fcoe_params(phba
))
6890 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6891 "2570 Failed to read FCoE parameters\n");
6894 * Retrieve sli4 device physical port name, failure of doing it
6895 * is considered as non-fatal.
6897 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6899 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6900 "3080 Successful retrieving SLI4 device "
6901 "physical port name: %s.\n", phba
->Port
);
6904 * Evaluate the read rev and vpd data. Populate the driver
6905 * state with the results. If this routine fails, the failure
6906 * is not fatal as the driver will use generic values.
6908 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6909 if (unlikely(!rc
)) {
6910 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6911 "0377 Error %d parsing vpd. "
6912 "Using defaults.\n", rc
);
6917 /* Save information as VPD data */
6918 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6919 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6922 * This is because first G7 ASIC doesn't support the standard
6923 * 0x5a NVME cmd descriptor type/subtype
6925 if ((bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6926 LPFC_SLI_INTF_IF_TYPE_6
) &&
6927 (phba
->vpd
.rev
.biuRev
== LPFC_G7_ASIC_1
) &&
6928 (phba
->vpd
.rev
.smRev
== 0) &&
6929 (phba
->cfg_nvme_embed_cmd
== 1))
6930 phba
->cfg_nvme_embed_cmd
= 0;
6932 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6933 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6935 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6937 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6939 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6941 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6942 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6943 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6944 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6945 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6946 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6947 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6948 "(%d):0380 READ_REV Status x%x "
6949 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6950 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6951 bf_get(lpfc_mqe_status
, mqe
),
6952 phba
->vpd
.rev
.opFwName
,
6953 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6954 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6956 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6957 rc
= (phba
->sli4_hba
.max_cfg_param
.max_xri
>> 3);
6958 if (phba
->pport
->cfg_lun_queue_depth
> rc
) {
6959 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6960 "3362 LUN queue depth changed from %d to %d\n",
6961 phba
->pport
->cfg_lun_queue_depth
, rc
);
6962 phba
->pport
->cfg_lun_queue_depth
= rc
;
6965 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6966 LPFC_SLI_INTF_IF_TYPE_0
) {
6967 lpfc_set_features(phba
, mboxq
, LPFC_SET_UE_RECOVERY
);
6968 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6969 if (rc
== MBX_SUCCESS
) {
6970 phba
->hba_flag
|= HBA_RECOVERABLE_UE
;
6971 /* Set 1Sec interval to detect UE */
6972 phba
->eratt_poll_interval
= 1;
6973 phba
->sli4_hba
.ue_to_sr
= bf_get(
6974 lpfc_mbx_set_feature_UESR
,
6975 &mboxq
->u
.mqe
.un
.set_feature
);
6976 phba
->sli4_hba
.ue_to_rp
= bf_get(
6977 lpfc_mbx_set_feature_UERP
,
6978 &mboxq
->u
.mqe
.un
.set_feature
);
6982 if (phba
->cfg_enable_mds_diags
&& phba
->mds_diags_support
) {
6983 /* Enable MDS Diagnostics only if the SLI Port supports it */
6984 lpfc_set_features(phba
, mboxq
, LPFC_SET_MDS_DIAGS
);
6985 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6986 if (rc
!= MBX_SUCCESS
)
6987 phba
->mds_diags_support
= 0;
6991 * Discover the port's supported feature set and match it against the
6994 lpfc_request_features(phba
, mboxq
);
6995 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7002 * The port must support FCP initiator mode as this is the
7003 * only mode running in the host.
7005 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
7006 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7007 "0378 No support for fcpi mode.\n");
7011 /* Performance Hints are ONLY for FCoE */
7012 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
7013 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
7014 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
7016 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
7020 * If the port cannot support the host's requested features
7021 * then turn off the global config parameters to disable the
7022 * feature in the driver. This is not a fatal error.
7024 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
) {
7025 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))) {
7026 phba
->cfg_enable_bg
= 0;
7027 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
7032 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
7033 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
7037 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7038 "0379 Feature Mismatch Data: x%08x %08x "
7039 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
7040 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
7041 phba
->cfg_enable_npiv
, phba
->max_vpi
);
7042 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
7043 phba
->cfg_enable_bg
= 0;
7044 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
7045 phba
->cfg_enable_npiv
= 0;
7048 /* These SLI3 features are assumed in SLI4 */
7049 spin_lock_irq(&phba
->hbalock
);
7050 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
7051 spin_unlock_irq(&phba
->hbalock
);
7054 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
7055 * calls depends on these resources to complete port setup.
7057 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
7059 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7060 "2920 Failed to alloc Resource IDs "
7065 lpfc_set_host_data(phba
, mboxq
);
7067 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7069 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7070 "2134 Failed to set host os driver version %x",
7074 /* Read the port's service parameters. */
7075 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
7077 phba
->link_state
= LPFC_HBA_ERROR
;
7082 mboxq
->vport
= vport
;
7083 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7084 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
7085 if (rc
== MBX_SUCCESS
) {
7086 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
7091 * This memory was allocated by the lpfc_read_sparam routine. Release
7092 * it to the mbuf pool.
7094 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
7096 mboxq
->context1
= NULL
;
7098 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7099 "0382 READ_SPARAM command failed "
7100 "status %d, mbxStatus x%x\n",
7101 rc
, bf_get(lpfc_mqe_status
, mqe
));
7102 phba
->link_state
= LPFC_HBA_ERROR
;
7107 lpfc_update_vport_wwn(vport
);
7109 /* Update the fc_host data structures with new wwn. */
7110 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
7111 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
7113 /* Create all the SLI4 queues */
7114 rc
= lpfc_sli4_queue_create(phba
);
7116 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7117 "3089 Failed to allocate queues\n");
7121 /* Set up all the queues to the device */
7122 rc
= lpfc_sli4_queue_setup(phba
);
7124 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7125 "0381 Error %d during queue setup.\n ", rc
);
7126 goto out_stop_timers
;
7128 /* Initialize the driver internal SLI layer lists. */
7129 lpfc_sli4_setup(phba
);
7130 lpfc_sli4_queue_init(phba
);
7132 /* update host els xri-sgl sizes and mappings */
7133 rc
= lpfc_sli4_els_sgl_update(phba
);
7135 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7136 "1400 Failed to update xri-sgl size and "
7137 "mapping: %d\n", rc
);
7138 goto out_destroy_queue
;
7141 /* register the els sgl pool to the port */
7142 rc
= lpfc_sli4_repost_sgl_list(phba
, &phba
->sli4_hba
.lpfc_els_sgl_list
,
7143 phba
->sli4_hba
.els_xri_cnt
);
7144 if (unlikely(rc
< 0)) {
7145 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7146 "0582 Error %d during els sgl post "
7149 goto out_destroy_queue
;
7151 phba
->sli4_hba
.els_xri_cnt
= rc
;
7153 if (phba
->nvmet_support
) {
7154 /* update host nvmet xri-sgl sizes and mappings */
7155 rc
= lpfc_sli4_nvmet_sgl_update(phba
);
7157 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7158 "6308 Failed to update nvmet-sgl size "
7159 "and mapping: %d\n", rc
);
7160 goto out_destroy_queue
;
7163 /* register the nvmet sgl pool to the port */
7164 rc
= lpfc_sli4_repost_sgl_list(
7166 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
,
7167 phba
->sli4_hba
.nvmet_xri_cnt
);
7168 if (unlikely(rc
< 0)) {
7169 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7170 "3117 Error %d during nvmet "
7173 goto out_destroy_queue
;
7175 phba
->sli4_hba
.nvmet_xri_cnt
= rc
;
7177 cnt
= phba
->cfg_iocb_cnt
* 1024;
7178 /* We need 1 iocbq for every SGL, for IO processing */
7179 cnt
+= phba
->sli4_hba
.nvmet_xri_cnt
;
7181 /* update host scsi xri-sgl sizes and mappings */
7182 rc
= lpfc_sli4_scsi_sgl_update(phba
);
7184 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7185 "6309 Failed to update scsi-sgl size "
7186 "and mapping: %d\n", rc
);
7187 goto out_destroy_queue
;
7190 /* update host nvme xri-sgl sizes and mappings */
7191 rc
= lpfc_sli4_nvme_sgl_update(phba
);
7193 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7194 "6082 Failed to update nvme-sgl size "
7195 "and mapping: %d\n", rc
);
7196 goto out_destroy_queue
;
7199 cnt
= phba
->cfg_iocb_cnt
* 1024;
7202 if (!phba
->sli
.iocbq_lookup
) {
7203 /* Initialize and populate the iocb list per host */
7204 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7205 "2821 initialize iocb list %d total %d\n",
7206 phba
->cfg_iocb_cnt
, cnt
);
7207 rc
= lpfc_init_iocb_list(phba
, cnt
);
7209 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7210 "1413 Failed to init iocb list.\n");
7211 goto out_destroy_queue
;
7215 if (phba
->nvmet_support
)
7216 lpfc_nvmet_create_targetport(phba
);
7218 if (phba
->nvmet_support
&& phba
->cfg_nvmet_mrq
) {
7219 /* Post initial buffers to all RQs created */
7220 for (i
= 0; i
< phba
->cfg_nvmet_mrq
; i
++) {
7221 rqbp
= phba
->sli4_hba
.nvmet_mrq_hdr
[i
]->rqbp
;
7222 INIT_LIST_HEAD(&rqbp
->rqb_buffer_list
);
7223 rqbp
->rqb_alloc_buffer
= lpfc_sli4_nvmet_alloc
;
7224 rqbp
->rqb_free_buffer
= lpfc_sli4_nvmet_free
;
7225 rqbp
->entry_count
= LPFC_NVMET_RQE_DEF_COUNT
;
7226 rqbp
->buffer_count
= 0;
7228 lpfc_post_rq_buffer(
7229 phba
, phba
->sli4_hba
.nvmet_mrq_hdr
[i
],
7230 phba
->sli4_hba
.nvmet_mrq_data
[i
],
7231 phba
->cfg_nvmet_mrq_post
, i
);
7235 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
7236 /* register the allocated scsi sgl pool to the port */
7237 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
7239 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7240 "0383 Error %d during scsi sgl post "
7242 /* Some Scsi buffers were moved to abort scsi list */
7243 /* A pci function reset will repost them */
7245 goto out_destroy_queue
;
7249 if ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) &&
7250 (phba
->nvmet_support
== 0)) {
7252 /* register the allocated nvme sgl pool to the port */
7253 rc
= lpfc_repost_nvme_sgl_list(phba
);
7255 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7256 "6116 Error %d during nvme sgl post "
7258 /* Some NVME buffers were moved to abort nvme list */
7259 /* A pci function reset will repost them */
7261 goto out_destroy_queue
;
7265 /* Post the rpi header region to the device. */
7266 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
7268 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7269 "0393 Error %d during rpi post operation\n",
7272 goto out_destroy_queue
;
7274 lpfc_sli4_node_prep(phba
);
7276 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
7277 if ((phba
->nvmet_support
== 0) || (phba
->cfg_nvmet_mrq
== 1)) {
7279 * The FC Port needs to register FCFI (index 0)
7281 lpfc_reg_fcfi(phba
, mboxq
);
7282 mboxq
->vport
= phba
->pport
;
7283 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7284 if (rc
!= MBX_SUCCESS
)
7285 goto out_unset_queue
;
7287 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
7288 &mboxq
->u
.mqe
.un
.reg_fcfi
);
7290 /* We are a NVME Target mode with MRQ > 1 */
7292 /* First register the FCFI */
7293 lpfc_reg_fcfi_mrq(phba
, mboxq
, 0);
7294 mboxq
->vport
= phba
->pport
;
7295 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7296 if (rc
!= MBX_SUCCESS
)
7297 goto out_unset_queue
;
7299 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_mrq_fcfi
,
7300 &mboxq
->u
.mqe
.un
.reg_fcfi_mrq
);
7302 /* Next register the MRQs */
7303 lpfc_reg_fcfi_mrq(phba
, mboxq
, 1);
7304 mboxq
->vport
= phba
->pport
;
7305 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7306 if (rc
!= MBX_SUCCESS
)
7307 goto out_unset_queue
;
7310 /* Check if the port is configured to be disabled */
7311 lpfc_sli_read_link_ste(phba
);
7314 /* Arm the CQs and then EQs on device */
7315 lpfc_sli4_arm_cqeq_intr(phba
);
7317 /* Indicate device interrupt mode */
7318 phba
->sli4_hba
.intr_enable
= 1;
7320 /* Allow asynchronous mailbox command to go through */
7321 spin_lock_irq(&phba
->hbalock
);
7322 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7323 spin_unlock_irq(&phba
->hbalock
);
7325 /* Post receive buffers to the device */
7326 lpfc_sli4_rb_setup(phba
);
7328 /* Reset HBA FCF states after HBA reset */
7329 phba
->fcf
.fcf_flag
= 0;
7330 phba
->fcf
.current_rec
.flag
= 0;
7332 /* Start the ELS watchdog timer */
7333 mod_timer(&vport
->els_tmofunc
,
7334 jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2)));
7336 /* Start heart beat timer */
7337 mod_timer(&phba
->hb_tmofunc
,
7338 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
7339 phba
->hb_outstanding
= 0;
7340 phba
->last_completion_time
= jiffies
;
7342 /* Start error attention (ERATT) polling timer */
7343 mod_timer(&phba
->eratt_poll
,
7344 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
7346 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
7347 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
7348 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
7350 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7351 "2829 This device supports "
7352 "Advanced Error Reporting (AER)\n");
7353 spin_lock_irq(&phba
->hbalock
);
7354 phba
->hba_flag
|= HBA_AER_ENABLED
;
7355 spin_unlock_irq(&phba
->hbalock
);
7357 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7358 "2830 This device does not support "
7359 "Advanced Error Reporting (AER)\n");
7360 phba
->cfg_aer_support
= 0;
7366 * The port is ready, set the host's link state to LINK_DOWN
7367 * in preparation for link interrupts.
7369 spin_lock_irq(&phba
->hbalock
);
7370 phba
->link_state
= LPFC_LINK_DOWN
;
7371 spin_unlock_irq(&phba
->hbalock
);
7372 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
7373 (phba
->hba_flag
& LINK_DISABLED
)) {
7374 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
7375 "3103 Adapter Link is disabled.\n");
7376 lpfc_down_link(phba
, mboxq
);
7377 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7378 if (rc
!= MBX_SUCCESS
) {
7379 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
7380 "3104 Adapter failed to issue "
7381 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
7382 goto out_unset_queue
;
7384 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
7385 /* don't perform init_link on SLI4 FC port loopback test */
7386 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
7387 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
7389 goto out_unset_queue
;
7392 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7395 /* Unset all the queues set up in this routine when error out */
7396 lpfc_sli4_queue_unset(phba
);
7398 lpfc_free_iocb_list(phba
);
7399 lpfc_sli4_queue_destroy(phba
);
7401 lpfc_stop_hba_timers(phba
);
7403 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7408 * lpfc_mbox_timeout - Timeout call back function for mbox timer
7409 * @ptr: context object - pointer to hba structure.
7411 * This is the callback function for mailbox timer. The mailbox
7412 * timer is armed when a new mailbox command is issued and the timer
7413 * is deleted when the mailbox complete. The function is called by
7414 * the kernel timer code when a mailbox does not complete within
7415 * expected time. This function wakes up the worker thread to
7416 * process the mailbox timeout and returns. All the processing is
7417 * done by the worker thread function lpfc_mbox_timeout_handler.
7420 lpfc_mbox_timeout(struct timer_list
*t
)
7422 struct lpfc_hba
*phba
= from_timer(phba
, t
, sli
.mbox_tmo
);
7423 unsigned long iflag
;
7424 uint32_t tmo_posted
;
7426 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
7427 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
7429 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
7430 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
7433 lpfc_worker_wake_up(phba
);
7438 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
7440 * @phba: Pointer to HBA context object.
7442 * This function checks if any mailbox completions are present on the mailbox
7446 lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
)
7450 struct lpfc_queue
*mcq
;
7451 struct lpfc_mcqe
*mcqe
;
7452 bool pending_completions
= false;
7455 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
7458 /* Check for completions on mailbox completion queue */
7460 mcq
= phba
->sli4_hba
.mbx_cq
;
7461 idx
= mcq
->hba_index
;
7462 qe_valid
= mcq
->qe_valid
;
7463 while (bf_get_le32(lpfc_cqe_valid
, mcq
->qe
[idx
].cqe
) == qe_valid
) {
7464 mcqe
= (struct lpfc_mcqe
*)mcq
->qe
[idx
].cqe
;
7465 if (bf_get_le32(lpfc_trailer_completed
, mcqe
) &&
7466 (!bf_get_le32(lpfc_trailer_async
, mcqe
))) {
7467 pending_completions
= true;
7470 idx
= (idx
+ 1) % mcq
->entry_count
;
7471 if (mcq
->hba_index
== idx
)
7474 /* if the index wrapped around, toggle the valid bit */
7475 if (phba
->sli4_hba
.pc_sli4_params
.cqav
&& !idx
)
7476 qe_valid
= (qe_valid
) ? 0 : 1;
7478 return pending_completions
;
7483 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
7485 * @phba: Pointer to HBA context object.
7487 * For sli4, it is possible to miss an interrupt. As such mbox completions
7488 * maybe missed causing erroneous mailbox timeouts to occur. This function
7489 * checks to see if mbox completions are on the mailbox completion queue
7490 * and will process all the completions associated with the eq for the
7491 * mailbox completion queue.
7494 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
)
7496 struct lpfc_sli4_hba
*sli4_hba
= &phba
->sli4_hba
;
7498 struct lpfc_queue
*fpeq
= NULL
;
7499 struct lpfc_eqe
*eqe
;
7502 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
7505 /* Find the eq associated with the mcq */
7507 if (sli4_hba
->hba_eq
)
7508 for (eqidx
= 0; eqidx
< phba
->io_channel_irqs
; eqidx
++)
7509 if (sli4_hba
->hba_eq
[eqidx
]->queue_id
==
7510 sli4_hba
->mbx_cq
->assoc_qid
) {
7511 fpeq
= sli4_hba
->hba_eq
[eqidx
];
7517 /* Turn off interrupts from this EQ */
7519 sli4_hba
->sli4_eq_clr_intr(fpeq
);
7521 /* Check to see if a mbox completion is pending */
7523 mbox_pending
= lpfc_sli4_mbox_completions_pending(phba
);
7526 * If a mbox completion is pending, process all the events on EQ
7527 * associated with the mbox completion queue (this could include
7528 * mailbox commands, async events, els commands, receive queue data
7533 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
7534 lpfc_sli4_hba_handle_eqe(phba
, eqe
, eqidx
);
7535 fpeq
->EQ_processed
++;
7538 /* Always clear and re-arm the EQ */
7540 sli4_hba
->sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
7542 return mbox_pending
;
7547 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
7548 * @phba: Pointer to HBA context object.
7550 * This function is called from worker thread when a mailbox command times out.
7551 * The caller is not required to hold any locks. This function will reset the
7552 * HBA and recover all the pending commands.
7555 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
7557 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
7558 MAILBOX_t
*mb
= NULL
;
7560 struct lpfc_sli
*psli
= &phba
->sli
;
7562 /* If the mailbox completed, process the completion and return */
7563 if (lpfc_sli4_process_missed_mbox_completions(phba
))
7568 /* Check the pmbox pointer first. There is a race condition
7569 * between the mbox timeout handler getting executed in the
7570 * worklist and the mailbox actually completing. When this
7571 * race condition occurs, the mbox_active will be NULL.
7573 spin_lock_irq(&phba
->hbalock
);
7574 if (pmbox
== NULL
) {
7575 lpfc_printf_log(phba
, KERN_WARNING
,
7577 "0353 Active Mailbox cleared - mailbox timeout "
7579 spin_unlock_irq(&phba
->hbalock
);
7583 /* Mbox cmd <mbxCommand> timeout */
7584 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7585 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
7587 phba
->pport
->port_state
,
7589 phba
->sli
.mbox_active
);
7590 spin_unlock_irq(&phba
->hbalock
);
7592 /* Setting state unknown so lpfc_sli_abort_iocb_ring
7593 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
7594 * it to fail all outstanding SCSI IO.
7596 spin_lock_irq(&phba
->pport
->work_port_lock
);
7597 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
7598 spin_unlock_irq(&phba
->pport
->work_port_lock
);
7599 spin_lock_irq(&phba
->hbalock
);
7600 phba
->link_state
= LPFC_LINK_UNKNOWN
;
7601 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
7602 spin_unlock_irq(&phba
->hbalock
);
7604 lpfc_sli_abort_fcp_rings(phba
);
7606 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7607 "0345 Resetting board due to mailbox timeout\n");
7609 /* Reset the HBA device */
7610 lpfc_reset_hba(phba
);
7614 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
7615 * @phba: Pointer to HBA context object.
7616 * @pmbox: Pointer to mailbox object.
7617 * @flag: Flag indicating how the mailbox need to be processed.
7619 * This function is called by discovery code and HBA management code
7620 * to submit a mailbox command to firmware with SLI-3 interface spec. This
7621 * function gets the hbalock to protect the data structures.
7622 * The mailbox command can be submitted in polling mode, in which case
7623 * this function will wait in a polling loop for the completion of the
7625 * If the mailbox is submitted in no_wait mode (not polling) the
7626 * function will submit the command and returns immediately without waiting
7627 * for the mailbox completion. The no_wait is supported only when HBA
7628 * is in SLI2/SLI3 mode - interrupts are enabled.
7629 * The SLI interface allows only one mailbox pending at a time. If the
7630 * mailbox is issued in polling mode and there is already a mailbox
7631 * pending, then the function will return an error. If the mailbox is issued
7632 * in NO_WAIT mode and there is a mailbox pending already, the function
7633 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
7634 * The sli layer owns the mailbox object until the completion of mailbox
7635 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
7636 * return codes the caller owns the mailbox command after the return of
7640 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
7644 struct lpfc_sli
*psli
= &phba
->sli
;
7645 uint32_t status
, evtctr
;
7646 uint32_t ha_copy
, hc_copy
;
7648 unsigned long timeout
;
7649 unsigned long drvr_flag
= 0;
7650 uint32_t word0
, ldata
;
7651 void __iomem
*to_slim
;
7652 int processing_queue
= 0;
7654 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7656 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7657 /* processing mbox queue from intr_handler */
7658 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7659 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7662 processing_queue
= 1;
7663 pmbox
= lpfc_mbox_get(phba
);
7665 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7670 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
7671 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
7673 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7674 lpfc_printf_log(phba
, KERN_ERR
,
7675 LOG_MBOX
| LOG_VPORT
,
7676 "1806 Mbox x%x failed. No vport\n",
7677 pmbox
->u
.mb
.mbxCommand
);
7679 goto out_not_finished
;
7683 /* If the PCI channel is in offline state, do not post mbox. */
7684 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7685 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7686 goto out_not_finished
;
7689 /* If HBA has a deferred error attention, fail the iocb. */
7690 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7691 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7692 goto out_not_finished
;
7698 status
= MBX_SUCCESS
;
7700 if (phba
->link_state
== LPFC_HBA_ERROR
) {
7701 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7703 /* Mbox command <mbxCommand> cannot issue */
7704 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7705 "(%d):0311 Mailbox command x%x cannot "
7706 "issue Data: x%x x%x\n",
7707 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7708 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7709 goto out_not_finished
;
7712 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
7713 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
7714 !(hc_copy
& HC_MBINT_ENA
)) {
7715 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7716 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7717 "(%d):2528 Mailbox command x%x cannot "
7718 "issue Data: x%x x%x\n",
7719 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7720 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7721 goto out_not_finished
;
7725 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7726 /* Polling for a mbox command when another one is already active
7727 * is not allowed in SLI. Also, the driver must have established
7728 * SLI2 mode to queue and process multiple mbox commands.
7731 if (flag
& MBX_POLL
) {
7732 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7734 /* Mbox command <mbxCommand> cannot issue */
7735 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7736 "(%d):2529 Mailbox command x%x "
7737 "cannot issue Data: x%x x%x\n",
7738 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7739 pmbox
->u
.mb
.mbxCommand
,
7740 psli
->sli_flag
, flag
);
7741 goto out_not_finished
;
7744 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
7745 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7746 /* Mbox command <mbxCommand> cannot issue */
7747 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7748 "(%d):2530 Mailbox command x%x "
7749 "cannot issue Data: x%x x%x\n",
7750 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7751 pmbox
->u
.mb
.mbxCommand
,
7752 psli
->sli_flag
, flag
);
7753 goto out_not_finished
;
7756 /* Another mailbox command is still being processed, queue this
7757 * command to be processed later.
7759 lpfc_mbox_put(phba
, pmbox
);
7761 /* Mbox cmd issue - BUSY */
7762 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7763 "(%d):0308 Mbox cmd issue - BUSY Data: "
7764 "x%x x%x x%x x%x\n",
7765 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
7767 phba
->pport
? phba
->pport
->port_state
: 0xff,
7768 psli
->sli_flag
, flag
);
7770 psli
->slistat
.mbox_busy
++;
7771 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7774 lpfc_debugfs_disc_trc(pmbox
->vport
,
7775 LPFC_DISC_TRC_MBOX_VPORT
,
7776 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
7777 (uint32_t)mbx
->mbxCommand
,
7778 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7781 lpfc_debugfs_disc_trc(phba
->pport
,
7783 "MBOX Bsy: cmd:x%x mb:x%x x%x",
7784 (uint32_t)mbx
->mbxCommand
,
7785 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7791 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7793 /* If we are not polling, we MUST be in SLI2 mode */
7794 if (flag
!= MBX_POLL
) {
7795 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
7796 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
7797 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7798 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7799 /* Mbox command <mbxCommand> cannot issue */
7800 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7801 "(%d):2531 Mailbox command x%x "
7802 "cannot issue Data: x%x x%x\n",
7803 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7804 pmbox
->u
.mb
.mbxCommand
,
7805 psli
->sli_flag
, flag
);
7806 goto out_not_finished
;
7808 /* timeout active mbox command */
7809 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7811 mod_timer(&psli
->mbox_tmo
, jiffies
+ timeout
);
7814 /* Mailbox cmd <cmd> issue */
7815 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7816 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
7818 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7820 phba
->pport
? phba
->pport
->port_state
: 0xff,
7821 psli
->sli_flag
, flag
);
7823 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
7825 lpfc_debugfs_disc_trc(pmbox
->vport
,
7826 LPFC_DISC_TRC_MBOX_VPORT
,
7827 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7828 (uint32_t)mbx
->mbxCommand
,
7829 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7832 lpfc_debugfs_disc_trc(phba
->pport
,
7834 "MBOX Send: cmd:x%x mb:x%x x%x",
7835 (uint32_t)mbx
->mbxCommand
,
7836 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7840 psli
->slistat
.mbox_cmd
++;
7841 evtctr
= psli
->slistat
.mbox_event
;
7843 /* next set own bit for the adapter and copy over command word */
7844 mbx
->mbxOwner
= OWN_CHIP
;
7846 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7847 /* Populate mbox extension offset word. */
7848 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
7849 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7850 = (uint8_t *)phba
->mbox_ext
7851 - (uint8_t *)phba
->mbox
;
7854 /* Copy the mailbox extension data */
7855 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7856 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
7857 (uint8_t *)phba
->mbox_ext
,
7858 pmbox
->in_ext_byte_len
);
7860 /* Copy command data to host SLIM area */
7861 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7863 /* Populate mbox extension offset word. */
7864 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
7865 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7866 = MAILBOX_HBA_EXT_OFFSET
;
7868 /* Copy the mailbox extension data */
7869 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
)
7870 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
7871 MAILBOX_HBA_EXT_OFFSET
,
7872 pmbox
->context2
, pmbox
->in_ext_byte_len
);
7874 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
)
7875 /* copy command data into host mbox for cmpl */
7876 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
,
7879 /* First copy mbox command data to HBA SLIM, skip past first
7881 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
7882 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
7883 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
7885 /* Next copy over first word, with mbxOwner set */
7886 ldata
= *((uint32_t *)mbx
);
7887 to_slim
= phba
->MBslimaddr
;
7888 writel(ldata
, to_slim
);
7889 readl(to_slim
); /* flush */
7891 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
)
7892 /* switch over to host mailbox */
7893 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
7900 /* Set up reference to mailbox command */
7901 psli
->mbox_active
= pmbox
;
7902 /* Interrupt board to do it */
7903 writel(CA_MBATT
, phba
->CAregaddr
);
7904 readl(phba
->CAregaddr
); /* flush */
7905 /* Don't wait for it to finish, just return */
7909 /* Set up null reference to mailbox command */
7910 psli
->mbox_active
= NULL
;
7911 /* Interrupt board to do it */
7912 writel(CA_MBATT
, phba
->CAregaddr
);
7913 readl(phba
->CAregaddr
); /* flush */
7915 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7916 /* First read mbox status word */
7917 word0
= *((uint32_t *)phba
->mbox
);
7918 word0
= le32_to_cpu(word0
);
7920 /* First read mbox status word */
7921 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
7922 spin_unlock_irqrestore(&phba
->hbalock
,
7924 goto out_not_finished
;
7928 /* Read the HBA Host Attention Register */
7929 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7930 spin_unlock_irqrestore(&phba
->hbalock
,
7932 goto out_not_finished
;
7934 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7937 /* Wait for command to complete */
7938 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
7939 (!(ha_copy
& HA_MBATT
) &&
7940 (phba
->link_state
> LPFC_WARM_START
))) {
7941 if (time_after(jiffies
, timeout
)) {
7942 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7943 spin_unlock_irqrestore(&phba
->hbalock
,
7945 goto out_not_finished
;
7948 /* Check if we took a mbox interrupt while we were
7950 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
7951 && (evtctr
!= psli
->slistat
.mbox_event
))
7955 spin_unlock_irqrestore(&phba
->hbalock
,
7958 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7961 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7962 /* First copy command data */
7963 word0
= *((uint32_t *)phba
->mbox
);
7964 word0
= le32_to_cpu(word0
);
7965 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7968 /* Check real SLIM for any errors */
7969 slimword0
= readl(phba
->MBslimaddr
);
7970 slimmb
= (MAILBOX_t
*) & slimword0
;
7971 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
7972 && slimmb
->mbxStatus
) {
7979 /* First copy command data */
7980 word0
= readl(phba
->MBslimaddr
);
7982 /* Read the HBA Host Attention Register */
7983 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7984 spin_unlock_irqrestore(&phba
->hbalock
,
7986 goto out_not_finished
;
7990 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7991 /* copy results back to user */
7992 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
,
7994 /* Copy the mailbox extension data */
7995 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7996 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7998 pmbox
->out_ext_byte_len
);
8001 /* First copy command data */
8002 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
8004 /* Copy the mailbox extension data */
8005 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
8006 lpfc_memcpy_from_slim(pmbox
->context2
,
8008 MAILBOX_HBA_EXT_OFFSET
,
8009 pmbox
->out_ext_byte_len
);
8013 writel(HA_MBATT
, phba
->HAregaddr
);
8014 readl(phba
->HAregaddr
); /* flush */
8016 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8017 status
= mbx
->mbxStatus
;
8020 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
8024 if (processing_queue
) {
8025 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8026 lpfc_mbox_cmpl_put(phba
, pmbox
);
8028 return MBX_NOT_FINISHED
;
8032 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
8033 * @phba: Pointer to HBA context object.
8035 * The function blocks the posting of SLI4 asynchronous mailbox commands from
8036 * the driver internal pending mailbox queue. It will then try to wait out the
8037 * possible outstanding mailbox command before return.
8040 * 0 - the outstanding mailbox command completed; otherwise, the wait for
8041 * the outstanding mailbox command timed out.
8044 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
8046 struct lpfc_sli
*psli
= &phba
->sli
;
8048 unsigned long timeout
= 0;
8050 /* Mark the asynchronous mailbox command posting as blocked */
8051 spin_lock_irq(&phba
->hbalock
);
8052 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
8053 /* Determine how long we might wait for the active mailbox
8054 * command to be gracefully completed by firmware.
8056 if (phba
->sli
.mbox_active
)
8057 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
8058 phba
->sli
.mbox_active
) *
8060 spin_unlock_irq(&phba
->hbalock
);
8062 /* Make sure the mailbox is really active */
8064 lpfc_sli4_process_missed_mbox_completions(phba
);
8066 /* Wait for the outstnading mailbox command to complete */
8067 while (phba
->sli
.mbox_active
) {
8068 /* Check active mailbox complete status every 2ms */
8070 if (time_after(jiffies
, timeout
)) {
8071 /* Timeout, marked the outstanding cmd not complete */
8077 /* Can not cleanly block async mailbox command, fails it */
8079 spin_lock_irq(&phba
->hbalock
);
8080 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
8081 spin_unlock_irq(&phba
->hbalock
);
8087 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
8088 * @phba: Pointer to HBA context object.
8090 * The function unblocks and resume posting of SLI4 asynchronous mailbox
8091 * commands from the driver internal pending mailbox queue. It makes sure
8092 * that there is no outstanding mailbox command before resuming posting
8093 * asynchronous mailbox commands. If, for any reason, there is outstanding
8094 * mailbox command, it will try to wait it out before resuming asynchronous
8095 * mailbox command posting.
8098 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
8100 struct lpfc_sli
*psli
= &phba
->sli
;
8102 spin_lock_irq(&phba
->hbalock
);
8103 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
8104 /* Asynchronous mailbox posting is not blocked, do nothing */
8105 spin_unlock_irq(&phba
->hbalock
);
8109 /* Outstanding synchronous mailbox command is guaranteed to be done,
8110 * successful or timeout, after timing-out the outstanding mailbox
8111 * command shall always be removed, so just unblock posting async
8112 * mailbox command and resume
8114 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
8115 spin_unlock_irq(&phba
->hbalock
);
8117 /* wake up worker thread to post asynchronlous mailbox command */
8118 lpfc_worker_wake_up(phba
);
8122 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
8123 * @phba: Pointer to HBA context object.
8124 * @mboxq: Pointer to mailbox object.
8126 * The function waits for the bootstrap mailbox register ready bit from
8127 * port for twice the regular mailbox command timeout value.
8129 * 0 - no timeout on waiting for bootstrap mailbox register ready.
8130 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
8133 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8136 unsigned long timeout
;
8137 struct lpfc_register bmbx_reg
;
8139 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
8143 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
8144 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
8148 if (time_after(jiffies
, timeout
))
8149 return MBXERR_ERROR
;
8150 } while (!db_ready
);
8156 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
8157 * @phba: Pointer to HBA context object.
8158 * @mboxq: Pointer to mailbox object.
8160 * The function posts a mailbox to the port. The mailbox is expected
8161 * to be comletely filled in and ready for the port to operate on it.
8162 * This routine executes a synchronous completion operation on the
8163 * mailbox by polling for its completion.
8165 * The caller must not be holding any locks when calling this routine.
8168 * MBX_SUCCESS - mailbox posted successfully
8169 * Any of the MBX error values.
8172 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8174 int rc
= MBX_SUCCESS
;
8175 unsigned long iflag
;
8176 uint32_t mcqe_status
;
8178 struct lpfc_sli
*psli
= &phba
->sli
;
8179 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
8180 struct lpfc_bmbx_create
*mbox_rgn
;
8181 struct dma_address
*dma_address
;
8184 * Only one mailbox can be active to the bootstrap mailbox region
8185 * at a time and there is no queueing provided.
8187 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8188 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8189 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8190 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8191 "(%d):2532 Mailbox command x%x (x%x/x%x) "
8192 "cannot issue Data: x%x x%x\n",
8193 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8194 mboxq
->u
.mb
.mbxCommand
,
8195 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8196 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8197 psli
->sli_flag
, MBX_POLL
);
8198 return MBXERR_ERROR
;
8200 /* The server grabs the token and owns it until release */
8201 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
8202 phba
->sli
.mbox_active
= mboxq
;
8203 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8205 /* wait for bootstrap mbox register for readyness */
8206 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
8211 * Initialize the bootstrap memory region to avoid stale data areas
8212 * in the mailbox post. Then copy the caller's mailbox contents to
8213 * the bmbx mailbox region.
8215 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
8216 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
8217 lpfc_sli4_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
8218 sizeof(struct lpfc_mqe
));
8220 /* Post the high mailbox dma address to the port and wait for ready. */
8221 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
8222 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
8224 /* wait for bootstrap mbox register for hi-address write done */
8225 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
8229 /* Post the low mailbox dma address to the port. */
8230 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
8232 /* wait for bootstrap mbox register for low address write done */
8233 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
8238 * Read the CQ to ensure the mailbox has completed.
8239 * If so, update the mailbox status so that the upper layers
8240 * can complete the request normally.
8242 lpfc_sli4_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
8243 sizeof(struct lpfc_mqe
));
8244 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
8245 lpfc_sli4_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
8246 sizeof(struct lpfc_mcqe
));
8247 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
8249 * When the CQE status indicates a failure and the mailbox status
8250 * indicates success then copy the CQE status into the mailbox status
8251 * (and prefix it with x4000).
8253 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
8254 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
8255 bf_set(lpfc_mqe_status
, mb
,
8256 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
8259 lpfc_sli4_swap_str(phba
, mboxq
);
8261 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8262 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
8263 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
8264 " x%x x%x CQ: x%x x%x x%x x%x\n",
8265 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
8266 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8267 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8268 bf_get(lpfc_mqe_status
, mb
),
8269 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
8270 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
8271 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
8272 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
8273 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
8274 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
8275 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
8276 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
8277 mboxq
->mcqe
.trailer
);
8279 /* We are holding the token, no needed for lock when release */
8280 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8281 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8282 phba
->sli
.mbox_active
= NULL
;
8283 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8288 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
8289 * @phba: Pointer to HBA context object.
8290 * @pmbox: Pointer to mailbox object.
8291 * @flag: Flag indicating how the mailbox need to be processed.
8293 * This function is called by discovery code and HBA management code to submit
8294 * a mailbox command to firmware with SLI-4 interface spec.
8296 * Return codes the caller owns the mailbox command after the return of the
8300 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
8303 struct lpfc_sli
*psli
= &phba
->sli
;
8304 unsigned long iflags
;
8307 /* dump from issue mailbox command if setup */
8308 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
8310 rc
= lpfc_mbox_dev_check(phba
);
8312 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8313 "(%d):2544 Mailbox command x%x (x%x/x%x) "
8314 "cannot issue Data: x%x x%x\n",
8315 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8316 mboxq
->u
.mb
.mbxCommand
,
8317 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8318 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8319 psli
->sli_flag
, flag
);
8320 goto out_not_finished
;
8323 /* Detect polling mode and jump to a handler */
8324 if (!phba
->sli4_hba
.intr_enable
) {
8325 if (flag
== MBX_POLL
)
8326 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
8329 if (rc
!= MBX_SUCCESS
)
8330 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
8331 "(%d):2541 Mailbox command x%x "
8332 "(x%x/x%x) failure: "
8333 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8335 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8336 mboxq
->u
.mb
.mbxCommand
,
8337 lpfc_sli_config_mbox_subsys_get(phba
,
8339 lpfc_sli_config_mbox_opcode_get(phba
,
8341 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
8342 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
8343 bf_get(lpfc_mcqe_ext_status
,
8345 psli
->sli_flag
, flag
);
8347 } else if (flag
== MBX_POLL
) {
8348 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
8349 "(%d):2542 Try to issue mailbox command "
8350 "x%x (x%x/x%x) synchronously ahead of async "
8351 "mailbox command queue: x%x x%x\n",
8352 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8353 mboxq
->u
.mb
.mbxCommand
,
8354 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8355 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8356 psli
->sli_flag
, flag
);
8357 /* Try to block the asynchronous mailbox posting */
8358 rc
= lpfc_sli4_async_mbox_block(phba
);
8360 /* Successfully blocked, now issue sync mbox cmd */
8361 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
8362 if (rc
!= MBX_SUCCESS
)
8363 lpfc_printf_log(phba
, KERN_WARNING
,
8365 "(%d):2597 Sync Mailbox command "
8366 "x%x (x%x/x%x) failure: "
8367 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8369 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8370 mboxq
->u
.mb
.mbxCommand
,
8371 lpfc_sli_config_mbox_subsys_get(phba
,
8373 lpfc_sli_config_mbox_opcode_get(phba
,
8375 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
8376 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
8377 bf_get(lpfc_mcqe_ext_status
,
8379 psli
->sli_flag
, flag
);
8380 /* Unblock the async mailbox posting afterward */
8381 lpfc_sli4_async_mbox_unblock(phba
);
8386 /* Now, interrupt mode asynchrous mailbox command */
8387 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
8389 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8390 "(%d):2543 Mailbox command x%x (x%x/x%x) "
8391 "cannot issue Data: x%x x%x\n",
8392 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8393 mboxq
->u
.mb
.mbxCommand
,
8394 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8395 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8396 psli
->sli_flag
, flag
);
8397 goto out_not_finished
;
8400 /* Put the mailbox command to the driver internal FIFO */
8401 psli
->slistat
.mbox_busy
++;
8402 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8403 lpfc_mbox_put(phba
, mboxq
);
8404 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8405 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8406 "(%d):0354 Mbox cmd issue - Enqueue Data: "
8407 "x%x (x%x/x%x) x%x x%x x%x\n",
8408 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
8409 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
8410 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8411 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8412 phba
->pport
->port_state
,
8413 psli
->sli_flag
, MBX_NOWAIT
);
8414 /* Wake up worker thread to transport mailbox command from head */
8415 lpfc_worker_wake_up(phba
);
8420 return MBX_NOT_FINISHED
;
8424 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
8425 * @phba: Pointer to HBA context object.
8427 * This function is called by worker thread to send a mailbox command to
8428 * SLI4 HBA firmware.
8432 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
8434 struct lpfc_sli
*psli
= &phba
->sli
;
8435 LPFC_MBOXQ_t
*mboxq
;
8436 int rc
= MBX_SUCCESS
;
8437 unsigned long iflags
;
8438 struct lpfc_mqe
*mqe
;
8441 /* Check interrupt mode before post async mailbox command */
8442 if (unlikely(!phba
->sli4_hba
.intr_enable
))
8443 return MBX_NOT_FINISHED
;
8445 /* Check for mailbox command service token */
8446 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8447 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
8448 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8449 return MBX_NOT_FINISHED
;
8451 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8452 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8453 return MBX_NOT_FINISHED
;
8455 if (unlikely(phba
->sli
.mbox_active
)) {
8456 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8457 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8458 "0384 There is pending active mailbox cmd\n");
8459 return MBX_NOT_FINISHED
;
8461 /* Take the mailbox command service token */
8462 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
8464 /* Get the next mailbox command from head of queue */
8465 mboxq
= lpfc_mbox_get(phba
);
8467 /* If no more mailbox command waiting for post, we're done */
8469 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8470 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8473 phba
->sli
.mbox_active
= mboxq
;
8474 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8476 /* Check device readiness for posting mailbox command */
8477 rc
= lpfc_mbox_dev_check(phba
);
8479 /* Driver clean routine will clean up pending mailbox */
8480 goto out_not_finished
;
8482 /* Prepare the mbox command to be posted */
8483 mqe
= &mboxq
->u
.mqe
;
8484 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
8486 /* Start timer for the mbox_tmo and log some mailbox post messages */
8487 mod_timer(&psli
->mbox_tmo
, (jiffies
+
8488 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba
, mboxq
))));
8490 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8491 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
8493 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
8494 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8495 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8496 phba
->pport
->port_state
, psli
->sli_flag
);
8498 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
8500 lpfc_debugfs_disc_trc(mboxq
->vport
,
8501 LPFC_DISC_TRC_MBOX_VPORT
,
8502 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8503 mbx_cmnd
, mqe
->un
.mb_words
[0],
8504 mqe
->un
.mb_words
[1]);
8506 lpfc_debugfs_disc_trc(phba
->pport
,
8508 "MBOX Send: cmd:x%x mb:x%x x%x",
8509 mbx_cmnd
, mqe
->un
.mb_words
[0],
8510 mqe
->un
.mb_words
[1]);
8513 psli
->slistat
.mbox_cmd
++;
8515 /* Post the mailbox command to the port */
8516 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
8517 if (rc
!= MBX_SUCCESS
) {
8518 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8519 "(%d):2533 Mailbox command x%x (x%x/x%x) "
8520 "cannot issue Data: x%x x%x\n",
8521 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8522 mboxq
->u
.mb
.mbxCommand
,
8523 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8524 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8525 psli
->sli_flag
, MBX_NOWAIT
);
8526 goto out_not_finished
;
8532 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8533 if (phba
->sli
.mbox_active
) {
8534 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8535 __lpfc_mbox_cmpl_put(phba
, mboxq
);
8536 /* Release the token */
8537 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8538 phba
->sli
.mbox_active
= NULL
;
8540 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8542 return MBX_NOT_FINISHED
;
8546 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
8547 * @phba: Pointer to HBA context object.
8548 * @pmbox: Pointer to mailbox object.
8549 * @flag: Flag indicating how the mailbox need to be processed.
8551 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
8552 * the API jump table function pointer from the lpfc_hba struct.
8554 * Return codes the caller owns the mailbox command after the return of the
8558 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
8560 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
8564 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
8565 * @phba: The hba struct for which this call is being executed.
8566 * @dev_grp: The HBA PCI-Device group number.
8568 * This routine sets up the mbox interface API function jump table in @phba
8570 * Returns: 0 - success, -ENODEV - failure.
8573 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8577 case LPFC_PCI_DEV_LP
:
8578 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
8579 phba
->lpfc_sli_handle_slow_ring_event
=
8580 lpfc_sli_handle_slow_ring_event_s3
;
8581 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
8582 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
8583 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
8585 case LPFC_PCI_DEV_OC
:
8586 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
8587 phba
->lpfc_sli_handle_slow_ring_event
=
8588 lpfc_sli_handle_slow_ring_event_s4
;
8589 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
8590 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
8591 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
8594 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8595 "1420 Invalid HBA PCI-device group: 0x%x\n",
8604 * __lpfc_sli_ringtx_put - Add an iocb to the txq
8605 * @phba: Pointer to HBA context object.
8606 * @pring: Pointer to driver SLI ring object.
8607 * @piocb: Pointer to address of newly added command iocb.
8609 * This function is called with hbalock held to add a command
8610 * iocb to the txq when SLI layer cannot submit the command iocb
8614 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8615 struct lpfc_iocbq
*piocb
)
8617 lockdep_assert_held(&phba
->hbalock
);
8618 /* Insert the caller's iocb in the txq tail for later processing. */
8619 list_add_tail(&piocb
->list
, &pring
->txq
);
8623 * lpfc_sli_next_iocb - Get the next iocb in the txq
8624 * @phba: Pointer to HBA context object.
8625 * @pring: Pointer to driver SLI ring object.
8626 * @piocb: Pointer to address of newly added command iocb.
8628 * This function is called with hbalock held before a new
8629 * iocb is submitted to the firmware. This function checks
8630 * txq to flush the iocbs in txq to Firmware before
8631 * submitting new iocbs to the Firmware.
8632 * If there are iocbs in the txq which need to be submitted
8633 * to firmware, lpfc_sli_next_iocb returns the first element
8634 * of the txq after dequeuing it from txq.
8635 * If there is no iocb in the txq then the function will return
8636 * *piocb and *piocb is set to NULL. Caller needs to check
8637 * *piocb to find if there are more commands in the txq.
8639 static struct lpfc_iocbq
*
8640 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8641 struct lpfc_iocbq
**piocb
)
8643 struct lpfc_iocbq
* nextiocb
;
8645 lockdep_assert_held(&phba
->hbalock
);
8647 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
8657 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
8658 * @phba: Pointer to HBA context object.
8659 * @ring_number: SLI ring number to issue iocb on.
8660 * @piocb: Pointer to command iocb.
8661 * @flag: Flag indicating if this command can be put into txq.
8663 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
8664 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
8665 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
8666 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
8667 * this function allows only iocbs for posting buffers. This function finds
8668 * next available slot in the command ring and posts the command to the
8669 * available slot and writes the port attention register to request HBA start
8670 * processing new iocb. If there is no slot available in the ring and
8671 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
8672 * the function returns IOCB_BUSY.
8674 * This function is called with hbalock held. The function will return success
8675 * after it successfully submit the iocb to firmware or after adding to the
8679 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
8680 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8682 struct lpfc_iocbq
*nextiocb
;
8684 struct lpfc_sli_ring
*pring
= &phba
->sli
.sli3_ring
[ring_number
];
8686 lockdep_assert_held(&phba
->hbalock
);
8688 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
8689 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
8690 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
8691 lpfc_printf_log(phba
, KERN_ERR
,
8692 LOG_SLI
| LOG_VPORT
,
8693 "1807 IOCB x%x failed. No vport\n",
8694 piocb
->iocb
.ulpCommand
);
8700 /* If the PCI channel is in offline state, do not post iocbs. */
8701 if (unlikely(pci_channel_offline(phba
->pcidev
)))
8704 /* If HBA has a deferred error attention, fail the iocb. */
8705 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
8709 * We should never get an IOCB if we are in a < LINK_DOWN state
8711 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
8715 * Check to see if we are blocking IOCB processing because of a
8716 * outstanding event.
8718 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
8721 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
8723 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
8724 * can be issued if the link is not up.
8726 switch (piocb
->iocb
.ulpCommand
) {
8727 case CMD_GEN_REQUEST64_CR
:
8728 case CMD_GEN_REQUEST64_CX
:
8729 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
8730 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
8731 FC_RCTL_DD_UNSOL_CMD
) ||
8732 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
8733 MENLO_TRANSPORT_TYPE
))
8737 case CMD_QUE_RING_BUF_CN
:
8738 case CMD_QUE_RING_BUF64_CN
:
8740 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
8741 * completion, iocb_cmpl MUST be 0.
8743 if (piocb
->iocb_cmpl
)
8744 piocb
->iocb_cmpl
= NULL
;
8746 case CMD_CREATE_XRI_CR
:
8747 case CMD_CLOSE_XRI_CN
:
8748 case CMD_CLOSE_XRI_CX
:
8755 * For FCP commands, we must be in a state where we can process link
8758 } else if (unlikely(pring
->ringno
== LPFC_FCP_RING
&&
8759 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
8763 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
8764 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
8765 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
8768 lpfc_sli_update_ring(phba
, pring
);
8770 lpfc_sli_update_full_ring(phba
, pring
);
8773 return IOCB_SUCCESS
;
8778 pring
->stats
.iocb_cmd_delay
++;
8782 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8783 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
8784 return IOCB_SUCCESS
;
8791 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
8792 * @phba: Pointer to HBA context object.
8793 * @piocb: Pointer to command iocb.
8794 * @sglq: Pointer to the scatter gather queue object.
8796 * This routine converts the bpl or bde that is in the IOCB
8797 * to a sgl list for the sli4 hardware. The physical address
8798 * of the bpl/bde is converted back to a virtual address.
8799 * If the IOCB contains a BPL then the list of BDE's is
8800 * converted to sli4_sge's. If the IOCB contains a single
8801 * BDE then it is converted to a single sli_sge.
8802 * The IOCB is still in cpu endianess so the contents of
8803 * the bpl can be used without byte swapping.
8805 * Returns valid XRI = Success, NO_XRI = Failure.
8808 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
8809 struct lpfc_sglq
*sglq
)
8811 uint16_t xritag
= NO_XRI
;
8812 struct ulp_bde64
*bpl
= NULL
;
8813 struct ulp_bde64 bde
;
8814 struct sli4_sge
*sgl
= NULL
;
8815 struct lpfc_dmabuf
*dmabuf
;
8819 uint32_t offset
= 0; /* accumulated offset in the sg request list */
8820 int inbound
= 0; /* number of sg reply entries inbound from firmware */
8822 if (!piocbq
|| !sglq
)
8825 sgl
= (struct sli4_sge
*)sglq
->sgl
;
8826 icmd
= &piocbq
->iocb
;
8827 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
8828 return sglq
->sli4_xritag
;
8829 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8830 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
8831 sizeof(struct ulp_bde64
);
8832 /* The addrHigh and addrLow fields within the IOCB
8833 * have not been byteswapped yet so there is no
8834 * need to swap them back.
8836 if (piocbq
->context3
)
8837 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
8841 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
8845 for (i
= 0; i
< numBdes
; i
++) {
8846 /* Should already be byte swapped. */
8847 sgl
->addr_hi
= bpl
->addrHigh
;
8848 sgl
->addr_lo
= bpl
->addrLow
;
8850 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8851 if ((i
+1) == numBdes
)
8852 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8854 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
8855 /* swap the size field back to the cpu so we
8856 * can assign it to the sgl.
8858 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8859 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
8860 /* The offsets in the sgl need to be accumulated
8861 * separately for the request and reply lists.
8862 * The request is always first, the reply follows.
8864 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
8865 /* add up the reply sg entries */
8866 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
8868 /* first inbound? reset the offset */
8871 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
8872 bf_set(lpfc_sli4_sge_type
, sgl
,
8873 LPFC_SGE_TYPE_DATA
);
8874 offset
+= bde
.tus
.f
.bdeSize
;
8876 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8880 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
8881 /* The addrHigh and addrLow fields of the BDE have not
8882 * been byteswapped yet so they need to be swapped
8883 * before putting them in the sgl.
8886 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
8888 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
8889 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8890 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8891 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8893 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
8895 return sglq
->sli4_xritag
;
8899 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8900 * @phba: Pointer to HBA context object.
8901 * @piocb: Pointer to command iocb.
8902 * @wqe: Pointer to the work queue entry.
8904 * This routine converts the iocb command to its Work Queue Entry
8905 * equivalent. The wqe pointer should not have any fields set when
8906 * this routine is called because it will memcpy over them.
8907 * This routine does not set the CQ_ID or the WQEC bits in the
8910 * Returns: 0 = Success, IOCB_ERROR = Failure.
8913 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
8914 union lpfc_wqe128
*wqe
)
8916 uint32_t xmit_len
= 0, total_len
= 0;
8920 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
8923 uint16_t abrt_iotag
;
8924 struct lpfc_iocbq
*abrtiocbq
;
8925 struct ulp_bde64
*bpl
= NULL
;
8926 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
8928 struct ulp_bde64 bde
;
8929 struct lpfc_nodelist
*ndlp
;
8933 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
8934 /* The fcp commands will set command type */
8935 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8936 command_type
= FCP_COMMAND
;
8937 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
8938 command_type
= ELS_COMMAND_FIP
;
8940 command_type
= ELS_COMMAND_NON_FIP
;
8942 if (phba
->fcp_embed_io
)
8943 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
8944 /* Some of the fields are in the right position already */
8945 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
8946 if (iocbq
->iocb
.ulpCommand
!= CMD_SEND_FRAME
) {
8947 /* The ct field has moved so reset */
8948 wqe
->generic
.wqe_com
.word7
= 0;
8949 wqe
->generic
.wqe_com
.word10
= 0;
8952 abort_tag
= (uint32_t) iocbq
->iotag
;
8953 xritag
= iocbq
->sli4_xritag
;
8954 /* words0-2 bpl convert bde */
8955 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8956 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8957 sizeof(struct ulp_bde64
);
8958 bpl
= (struct ulp_bde64
*)
8959 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
8963 /* Should already be byte swapped. */
8964 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
8965 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
8966 /* swap the size field back to the cpu so we
8967 * can assign it to the sgl.
8969 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8970 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
8972 for (i
= 0; i
< numBdes
; i
++) {
8973 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8974 total_len
+= bde
.tus
.f
.bdeSize
;
8977 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8979 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8980 cmnd
= iocbq
->iocb
.ulpCommand
;
8982 switch (iocbq
->iocb
.ulpCommand
) {
8983 case CMD_ELS_REQUEST64_CR
:
8984 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8985 ndlp
= iocbq
->context_un
.ndlp
;
8987 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8988 if (!iocbq
->iocb
.ulpLe
) {
8989 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8990 "2007 Only Limited Edition cmd Format"
8991 " supported 0x%x\n",
8992 iocbq
->iocb
.ulpCommand
);
8996 wqe
->els_req
.payload_len
= xmit_len
;
8997 /* Els_reguest64 has a TMO */
8998 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8999 iocbq
->iocb
.ulpTimeout
);
9000 /* Need a VF for word 4 set the vf bit*/
9001 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
9002 /* And a VFID for word 12 */
9003 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
9004 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
9005 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
9006 iocbq
->iocb
.ulpContext
);
9007 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
9008 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
9009 /* CCP CCPE PV PRI in word10 were set in the memcpy */
9010 if (command_type
== ELS_COMMAND_FIP
)
9011 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
9012 >> LPFC_FIP_ELS_ID_SHIFT
);
9013 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
9014 iocbq
->context2
)->virt
);
9015 if_type
= bf_get(lpfc_sli_intf_if_type
,
9016 &phba
->sli4_hba
.sli_intf
);
9017 if (if_type
>= LPFC_SLI_INTF_IF_TYPE_2
) {
9018 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
9019 *pcmd
== ELS_CMD_SCR
||
9020 *pcmd
== ELS_CMD_FDISC
||
9021 *pcmd
== ELS_CMD_LOGO
||
9022 *pcmd
== ELS_CMD_PLOGI
)) {
9023 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
9024 bf_set(els_req64_sid
, &wqe
->els_req
,
9025 iocbq
->vport
->fc_myDID
);
9026 if ((*pcmd
== ELS_CMD_FLOGI
) &&
9027 !(phba
->fc_topology
==
9028 LPFC_TOPOLOGY_LOOP
))
9029 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
9030 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
9031 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
9032 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
9033 } else if (pcmd
&& iocbq
->context1
) {
9034 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
9035 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
9036 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
9039 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
9040 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
9041 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
9042 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
9043 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
9044 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
9045 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
9046 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
9047 wqe
->els_req
.max_response_payload_len
= total_len
- xmit_len
;
9049 case CMD_XMIT_SEQUENCE64_CX
:
9050 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
9051 iocbq
->iocb
.un
.ulpWord
[3]);
9052 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
9053 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
9054 /* The entire sequence is transmitted for this IOCB */
9055 xmit_len
= total_len
;
9056 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
9057 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
9058 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
9059 case CMD_XMIT_SEQUENCE64_CR
:
9060 /* word3 iocb=io_tag32 wqe=reserved */
9061 wqe
->xmit_sequence
.rsvd3
= 0;
9062 /* word4 relative_offset memcpy */
9063 /* word5 r_ctl/df_ctl memcpy */
9064 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
9065 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
9066 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
9067 LPFC_WQE_IOD_WRITE
);
9068 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
9069 LPFC_WQE_LENLOC_WORD12
);
9070 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
9071 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
9072 command_type
= OTHER_COMMAND
;
9074 case CMD_XMIT_BCAST64_CN
:
9075 /* word3 iocb=iotag32 wqe=seq_payload_len */
9076 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
9077 /* word4 iocb=rsvd wqe=rsvd */
9078 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
9079 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
9080 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
9081 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9082 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
9083 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
9084 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
9085 LPFC_WQE_LENLOC_WORD3
);
9086 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
9088 case CMD_FCP_IWRITE64_CR
:
9089 command_type
= FCP_COMMAND_DATA_OUT
;
9090 /* word3 iocb=iotag wqe=payload_offset_len */
9091 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9092 bf_set(payload_offset_len
, &wqe
->fcp_iwrite
,
9093 xmit_len
+ sizeof(struct fcp_rsp
));
9094 bf_set(cmd_buff_len
, &wqe
->fcp_iwrite
,
9096 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9097 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9098 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
9099 iocbq
->iocb
.ulpFCP2Rcvy
);
9100 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
9101 /* Always open the exchange */
9102 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
9103 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
9104 LPFC_WQE_LENLOC_WORD4
);
9105 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
9106 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
9107 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
9108 bf_set(wqe_oas
, &wqe
->fcp_iwrite
.wqe_com
, 1);
9109 bf_set(wqe_ccpe
, &wqe
->fcp_iwrite
.wqe_com
, 1);
9110 if (iocbq
->priority
) {
9111 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
9112 (iocbq
->priority
<< 1));
9114 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
9115 (phba
->cfg_XLanePriority
<< 1));
9118 /* Note, word 10 is already initialized to 0 */
9120 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9121 if (phba
->cfg_enable_pbde
)
9122 bf_set(wqe_pbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
9124 bf_set(wqe_pbde
, &wqe
->fcp_iwrite
.wqe_com
, 0);
9126 if (phba
->fcp_embed_io
) {
9127 struct lpfc_scsi_buf
*lpfc_cmd
;
9128 struct sli4_sge
*sgl
;
9129 struct fcp_cmnd
*fcp_cmnd
;
9132 /* 128 byte wqe support here */
9134 lpfc_cmd
= iocbq
->context1
;
9135 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
9136 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
9138 /* Word 0-2 - FCP_CMND */
9139 wqe
->generic
.bde
.tus
.f
.bdeFlags
=
9140 BUFF_TYPE_BDE_IMMED
;
9141 wqe
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
9142 wqe
->generic
.bde
.addrHigh
= 0;
9143 wqe
->generic
.bde
.addrLow
= 88; /* Word 22 */
9145 bf_set(wqe_wqes
, &wqe
->fcp_iwrite
.wqe_com
, 1);
9146 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 0);
9148 /* Word 22-29 FCP CMND Payload */
9149 ptr
= &wqe
->words
[22];
9150 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
9153 case CMD_FCP_IREAD64_CR
:
9154 /* word3 iocb=iotag wqe=payload_offset_len */
9155 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9156 bf_set(payload_offset_len
, &wqe
->fcp_iread
,
9157 xmit_len
+ sizeof(struct fcp_rsp
));
9158 bf_set(cmd_buff_len
, &wqe
->fcp_iread
,
9160 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
9161 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
9162 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
9163 iocbq
->iocb
.ulpFCP2Rcvy
);
9164 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
9165 /* Always open the exchange */
9166 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
9167 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
9168 LPFC_WQE_LENLOC_WORD4
);
9169 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
9170 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
9171 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
9172 bf_set(wqe_oas
, &wqe
->fcp_iread
.wqe_com
, 1);
9173 bf_set(wqe_ccpe
, &wqe
->fcp_iread
.wqe_com
, 1);
9174 if (iocbq
->priority
) {
9175 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
9176 (iocbq
->priority
<< 1));
9178 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
9179 (phba
->cfg_XLanePriority
<< 1));
9182 /* Note, word 10 is already initialized to 0 */
9184 /* Don't set PBDE for Perf hints, just lpfc_enable_pbde */
9185 if (phba
->cfg_enable_pbde
)
9186 bf_set(wqe_pbde
, &wqe
->fcp_iread
.wqe_com
, 1);
9188 bf_set(wqe_pbde
, &wqe
->fcp_iread
.wqe_com
, 0);
9190 if (phba
->fcp_embed_io
) {
9191 struct lpfc_scsi_buf
*lpfc_cmd
;
9192 struct sli4_sge
*sgl
;
9193 struct fcp_cmnd
*fcp_cmnd
;
9196 /* 128 byte wqe support here */
9198 lpfc_cmd
= iocbq
->context1
;
9199 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
9200 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
9202 /* Word 0-2 - FCP_CMND */
9203 wqe
->generic
.bde
.tus
.f
.bdeFlags
=
9204 BUFF_TYPE_BDE_IMMED
;
9205 wqe
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
9206 wqe
->generic
.bde
.addrHigh
= 0;
9207 wqe
->generic
.bde
.addrLow
= 88; /* Word 22 */
9209 bf_set(wqe_wqes
, &wqe
->fcp_iread
.wqe_com
, 1);
9210 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 0);
9212 /* Word 22-29 FCP CMND Payload */
9213 ptr
= &wqe
->words
[22];
9214 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
9217 case CMD_FCP_ICMND64_CR
:
9218 /* word3 iocb=iotag wqe=payload_offset_len */
9219 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
9220 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
9221 xmit_len
+ sizeof(struct fcp_rsp
));
9222 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
,
9224 /* word3 iocb=IO_TAG wqe=reserved */
9225 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
9226 /* Always open the exchange */
9227 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
9228 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
9229 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
9230 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
9231 LPFC_WQE_LENLOC_NONE
);
9232 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
9233 iocbq
->iocb
.ulpFCP2Rcvy
);
9234 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
9235 bf_set(wqe_oas
, &wqe
->fcp_icmd
.wqe_com
, 1);
9236 bf_set(wqe_ccpe
, &wqe
->fcp_icmd
.wqe_com
, 1);
9237 if (iocbq
->priority
) {
9238 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
9239 (iocbq
->priority
<< 1));
9241 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
9242 (phba
->cfg_XLanePriority
<< 1));
9245 /* Note, word 10 is already initialized to 0 */
9247 if (phba
->fcp_embed_io
) {
9248 struct lpfc_scsi_buf
*lpfc_cmd
;
9249 struct sli4_sge
*sgl
;
9250 struct fcp_cmnd
*fcp_cmnd
;
9253 /* 128 byte wqe support here */
9255 lpfc_cmd
= iocbq
->context1
;
9256 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
9257 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
9259 /* Word 0-2 - FCP_CMND */
9260 wqe
->generic
.bde
.tus
.f
.bdeFlags
=
9261 BUFF_TYPE_BDE_IMMED
;
9262 wqe
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
9263 wqe
->generic
.bde
.addrHigh
= 0;
9264 wqe
->generic
.bde
.addrLow
= 88; /* Word 22 */
9266 bf_set(wqe_wqes
, &wqe
->fcp_icmd
.wqe_com
, 1);
9267 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 0);
9269 /* Word 22-29 FCP CMND Payload */
9270 ptr
= &wqe
->words
[22];
9271 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
9274 case CMD_GEN_REQUEST64_CR
:
9275 /* For this command calculate the xmit length of the
9279 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
9280 sizeof(struct ulp_bde64
);
9281 for (i
= 0; i
< numBdes
; i
++) {
9282 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
9283 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
9285 xmit_len
+= bde
.tus
.f
.bdeSize
;
9287 /* word3 iocb=IO_TAG wqe=request_payload_len */
9288 wqe
->gen_req
.request_payload_len
= xmit_len
;
9289 /* word4 iocb=parameter wqe=relative_offset memcpy */
9290 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
9291 /* word6 context tag copied in memcpy */
9292 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
9293 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
9294 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9295 "2015 Invalid CT %x command 0x%x\n",
9296 ct
, iocbq
->iocb
.ulpCommand
);
9299 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
9300 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
9301 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
9302 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
9303 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
9304 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
9305 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
9306 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
9307 wqe
->gen_req
.max_response_payload_len
= total_len
- xmit_len
;
9308 command_type
= OTHER_COMMAND
;
9310 case CMD_XMIT_ELS_RSP64_CX
:
9311 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
9312 /* words0-2 BDE memcpy */
9313 /* word3 iocb=iotag32 wqe=response_payload_len */
9314 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
9316 wqe
->xmit_els_rsp
.word4
= 0;
9317 /* word5 iocb=rsvd wge=did */
9318 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
9319 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
9321 if_type
= bf_get(lpfc_sli_intf_if_type
,
9322 &phba
->sli4_hba
.sli_intf
);
9323 if (if_type
>= LPFC_SLI_INTF_IF_TYPE_2
) {
9324 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
9325 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
9326 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
9327 iocbq
->vport
->fc_myDID
);
9328 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
9330 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
9334 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
9335 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9336 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
9337 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
9338 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
9339 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
9340 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
9341 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
9342 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9343 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
9344 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9345 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
9346 LPFC_WQE_LENLOC_WORD3
);
9347 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
9348 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
9349 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
9350 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
9351 iocbq
->context2
)->virt
);
9352 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
9353 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
9354 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
9355 iocbq
->vport
->fc_myDID
);
9356 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9357 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
9358 phba
->vpi_ids
[phba
->pport
->vpi
]);
9360 command_type
= OTHER_COMMAND
;
9362 case CMD_CLOSE_XRI_CN
:
9363 case CMD_ABORT_XRI_CN
:
9364 case CMD_ABORT_XRI_CX
:
9365 /* words 0-2 memcpy should be 0 rserved */
9366 /* port will send abts */
9367 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
9368 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
9369 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
9370 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
9374 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
9376 * The link is down, or the command was ELS_FIP
9377 * so the fw does not need to send abts
9380 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
9382 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
9383 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
9384 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
9385 wqe
->abort_cmd
.rsrvd5
= 0;
9386 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
9387 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9388 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
9390 * The abort handler will send us CMD_ABORT_XRI_CN or
9391 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
9393 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
9394 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
9395 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
9396 LPFC_WQE_LENLOC_NONE
);
9397 cmnd
= CMD_ABORT_XRI_CX
;
9398 command_type
= OTHER_COMMAND
;
9401 case CMD_XMIT_BLS_RSP64_CX
:
9402 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
9403 /* As BLS ABTS RSP WQE is very different from other WQEs,
9404 * we re-construct this WQE here based on information in
9405 * iocbq from scratch.
9407 memset(wqe
, 0, sizeof(union lpfc_wqe
));
9408 /* OX_ID is invariable to who sent ABTS to CT exchange */
9409 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
9410 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
9411 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
9412 LPFC_ABTS_UNSOL_INT
) {
9413 /* ABTS sent by initiator to CT exchange, the
9414 * RX_ID field will be filled with the newly
9415 * allocated responder XRI.
9417 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
9418 iocbq
->sli4_xritag
);
9420 /* ABTS sent by responder to CT exchange, the
9421 * RX_ID field will be filled with the responder
9424 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
9425 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
9427 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
9428 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
9431 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
9433 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
9434 iocbq
->iocb
.ulpContext
);
9435 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
9436 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
9437 phba
->vpi_ids
[phba
->pport
->vpi
]);
9438 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
9439 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
9440 LPFC_WQE_LENLOC_NONE
);
9441 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
9442 command_type
= OTHER_COMMAND
;
9443 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
9444 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
9445 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
9446 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
9447 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
9448 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
9449 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
9453 case CMD_SEND_FRAME
:
9454 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
9455 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
9457 case CMD_XRI_ABORTED_CX
:
9458 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
9459 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
9460 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
9461 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
9462 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
9464 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9465 "2014 Invalid command 0x%x\n",
9466 iocbq
->iocb
.ulpCommand
);
9471 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
9472 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
9473 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
9474 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
9475 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
9476 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
9477 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
9478 LPFC_IO_DIF_INSERT
);
9479 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
9480 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
9481 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
9482 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
9483 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
9484 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
9485 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
9490 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
9491 * @phba: Pointer to HBA context object.
9492 * @ring_number: SLI ring number to issue iocb on.
9493 * @piocb: Pointer to command iocb.
9494 * @flag: Flag indicating if this command can be put into txq.
9496 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
9497 * an iocb command to an HBA with SLI-4 interface spec.
9499 * This function is called with hbalock held. The function will return success
9500 * after it successfully submit the iocb to firmware or after adding to the
9504 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
9505 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9507 struct lpfc_sglq
*sglq
;
9508 union lpfc_wqe128 wqe
;
9509 struct lpfc_queue
*wq
;
9510 struct lpfc_sli_ring
*pring
;
9513 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
9514 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
9515 if (!phba
->cfg_fof
|| (!(piocb
->iocb_flag
& LPFC_IO_OAS
)))
9516 wq
= phba
->sli4_hba
.fcp_wq
[piocb
->hba_wqidx
];
9518 wq
= phba
->sli4_hba
.oas_wq
;
9520 wq
= phba
->sli4_hba
.els_wq
;
9523 /* Get corresponding ring */
9527 * The WQE can be either 64 or 128 bytes,
9530 lockdep_assert_held(&phba
->hbalock
);
9532 if (piocb
->sli4_xritag
== NO_XRI
) {
9533 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
9534 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
9537 if (!list_empty(&pring
->txq
)) {
9538 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
9539 __lpfc_sli_ringtx_put(phba
,
9541 return IOCB_SUCCESS
;
9546 sglq
= __lpfc_sli_get_els_sglq(phba
, piocb
);
9548 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
9549 __lpfc_sli_ringtx_put(phba
,
9552 return IOCB_SUCCESS
;
9558 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
)
9559 /* These IO's already have an XRI and a mapped sgl. */
9563 * This is a continuation of a commandi,(CX) so this
9564 * sglq is on the active list
9566 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
9572 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
9573 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
9574 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
9578 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
9581 if (lpfc_sli4_wq_put(wq
, &wqe
))
9583 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
9589 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
9591 * This routine wraps the actual lockless version for issusing IOCB function
9592 * pointer from the lpfc_hba struct.
9595 * IOCB_ERROR - Error
9596 * IOCB_SUCCESS - Success
9600 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9601 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9603 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9607 * lpfc_sli_api_table_setup - Set up sli api function jump table
9608 * @phba: The hba struct for which this call is being executed.
9609 * @dev_grp: The HBA PCI-Device group number.
9611 * This routine sets up the SLI interface API function jump table in @phba
9613 * Returns: 0 - success, -ENODEV - failure.
9616 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
9620 case LPFC_PCI_DEV_LP
:
9621 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
9622 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
9624 case LPFC_PCI_DEV_OC
:
9625 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
9626 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
9629 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9630 "1419 Invalid HBA PCI-device group: 0x%x\n",
9635 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
9640 * lpfc_sli4_calc_ring - Calculates which ring to use
9641 * @phba: Pointer to HBA context object.
9642 * @piocb: Pointer to command iocb.
9644 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
9645 * hba_wqidx, thus we need to calculate the corresponding ring.
9646 * Since ABORTS must go on the same WQ of the command they are
9647 * aborting, we use command's hba_wqidx.
9649 struct lpfc_sli_ring
*
9650 lpfc_sli4_calc_ring(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocb
)
9652 if (piocb
->iocb_flag
& (LPFC_IO_FCP
| LPFC_USE_FCPWQIDX
)) {
9653 if (!(phba
->cfg_fof
) ||
9654 (!(piocb
->iocb_flag
& LPFC_IO_FOF
))) {
9655 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
9658 * for abort iocb hba_wqidx should already
9659 * be setup based on what work queue we used.
9661 if (!(piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
9663 lpfc_sli4_scmd_to_wqidx_distr(phba
,
9665 piocb
->hba_wqidx
= piocb
->hba_wqidx
%
9666 phba
->cfg_fcp_io_channel
;
9668 return phba
->sli4_hba
.fcp_wq
[piocb
->hba_wqidx
]->pring
;
9670 if (unlikely(!phba
->sli4_hba
.oas_wq
))
9672 piocb
->hba_wqidx
= 0;
9673 return phba
->sli4_hba
.oas_wq
->pring
;
9676 if (unlikely(!phba
->sli4_hba
.els_wq
))
9678 piocb
->hba_wqidx
= 0;
9679 return phba
->sli4_hba
.els_wq
->pring
;
9684 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
9685 * @phba: Pointer to HBA context object.
9686 * @pring: Pointer to driver SLI ring object.
9687 * @piocb: Pointer to command iocb.
9688 * @flag: Flag indicating if this command can be put into txq.
9690 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
9691 * function. This function gets the hbalock and calls
9692 * __lpfc_sli_issue_iocb function and will return the error returned
9693 * by __lpfc_sli_issue_iocb function. This wrapper is used by
9694 * functions which do not hold hbalock.
9697 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9698 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9700 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
9701 struct lpfc_sli_ring
*pring
;
9702 struct lpfc_queue
*fpeq
;
9703 struct lpfc_eqe
*eqe
;
9704 unsigned long iflags
;
9707 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9708 pring
= lpfc_sli4_calc_ring(phba
, piocb
);
9709 if (unlikely(pring
== NULL
))
9712 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9713 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9714 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9716 if (lpfc_fcp_look_ahead
&& (piocb
->iocb_flag
& LPFC_IO_FCP
)) {
9717 idx
= piocb
->hba_wqidx
;
9718 hba_eq_hdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9720 if (atomic_dec_and_test(&hba_eq_hdl
->hba_eq_in_use
)) {
9722 /* Get associated EQ with this index */
9723 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
9725 /* Turn off interrupts from this EQ */
9726 phba
->sli4_hba
.sli4_eq_clr_intr(fpeq
);
9729 * Process all the events on FCP EQ
9731 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9732 lpfc_sli4_hba_handle_eqe(phba
,
9734 fpeq
->EQ_processed
++;
9737 /* Always clear and re-arm the EQ */
9738 phba
->sli4_hba
.sli4_eq_release(fpeq
,
9741 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
9744 /* For now, SLI2/3 will still use hbalock */
9745 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9746 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9747 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9753 * lpfc_extra_ring_setup - Extra ring setup function
9754 * @phba: Pointer to HBA context object.
9756 * This function is called while driver attaches with the
9757 * HBA to setup the extra ring. The extra ring is used
9758 * only when driver needs to support target mode functionality
9759 * or IP over FC functionalities.
9761 * This function is called with no lock held. SLI3 only.
9764 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
9766 struct lpfc_sli
*psli
;
9767 struct lpfc_sli_ring
*pring
;
9771 /* Adjust cmd/rsp ring iocb entries more evenly */
9773 /* Take some away from the FCP ring */
9774 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
9775 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9776 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9777 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9778 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9780 /* and give them to the extra ring */
9781 pring
= &psli
->sli3_ring
[LPFC_EXTRA_RING
];
9783 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9784 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9785 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9786 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9788 /* Setup default profile for this ring */
9789 pring
->iotag_max
= 4096;
9790 pring
->num_mask
= 1;
9791 pring
->prt
[0].profile
= 0; /* Mask 0 */
9792 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
9793 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
9794 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
9798 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
9799 * @phba: Pointer to HBA context object.
9800 * @iocbq: Pointer to iocb object.
9802 * The async_event handler calls this routine when it receives
9803 * an ASYNC_STATUS_CN event from the port. The port generates
9804 * this event when an Abort Sequence request to an rport fails
9805 * twice in succession. The abort could be originated by the
9806 * driver or by the port. The ABTS could have been for an ELS
9807 * or FCP IO. The port only generates this event when an ABTS
9808 * fails to complete after one retry.
9811 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
9812 struct lpfc_iocbq
*iocbq
)
9814 struct lpfc_nodelist
*ndlp
= NULL
;
9815 uint16_t rpi
= 0, vpi
= 0;
9816 struct lpfc_vport
*vport
= NULL
;
9818 /* The rpi in the ulpContext is vport-sensitive. */
9819 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
9820 rpi
= iocbq
->iocb
.ulpContext
;
9822 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9823 "3092 Port generated ABTS async event "
9824 "on vpi %d rpi %d status 0x%x\n",
9825 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
9827 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
9830 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
9831 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
9834 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
9835 lpfc_sli_abts_recover_port(vport
, ndlp
);
9839 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9840 "3095 Event Context not found, no "
9841 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
9842 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
9846 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
9847 * @phba: pointer to HBA context object.
9848 * @ndlp: nodelist pointer for the impacted rport.
9849 * @axri: pointer to the wcqe containing the failed exchange.
9851 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
9852 * port. The port generates this event when an abort exchange request to an
9853 * rport fails twice in succession with no reply. The abort could be originated
9854 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
9857 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
9858 struct lpfc_nodelist
*ndlp
,
9859 struct sli4_wcqe_xri_aborted
*axri
)
9861 struct lpfc_vport
*vport
;
9862 uint32_t ext_status
= 0;
9864 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
9865 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9866 "3115 Node Context not found, driver "
9867 "ignoring abts err event\n");
9871 vport
= ndlp
->vport
;
9872 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9873 "3116 Port generated FCP XRI ABORT event on "
9874 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
9875 ndlp
->vport
->vpi
, phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
],
9876 bf_get(lpfc_wcqe_xa_xri
, axri
),
9877 bf_get(lpfc_wcqe_xa_status
, axri
),
9881 * Catch the ABTS protocol failure case. Older OCe FW releases returned
9882 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
9883 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
9885 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
9886 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
9887 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
9888 lpfc_sli_abts_recover_port(vport
, ndlp
);
9892 * lpfc_sli_async_event_handler - ASYNC iocb handler function
9893 * @phba: Pointer to HBA context object.
9894 * @pring: Pointer to driver SLI ring object.
9895 * @iocbq: Pointer to iocb object.
9897 * This function is called by the slow ring event handler
9898 * function when there is an ASYNC event iocb in the ring.
9899 * This function is called with no lock held.
9900 * Currently this function handles only temperature related
9901 * ASYNC events. The function decodes the temperature sensor
9902 * event message and posts events for the management applications.
9905 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
9906 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
9910 struct temp_event temp_event_data
;
9911 struct Scsi_Host
*shost
;
9914 icmd
= &iocbq
->iocb
;
9915 evt_code
= icmd
->un
.asyncstat
.evt_code
;
9918 case ASYNC_TEMP_WARN
:
9919 case ASYNC_TEMP_SAFE
:
9920 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
9921 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
9922 if (evt_code
== ASYNC_TEMP_WARN
) {
9923 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
9924 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9925 "0347 Adapter is very hot, please take "
9926 "corrective action. temperature : %d Celsius\n",
9927 (uint32_t) icmd
->ulpContext
);
9929 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
9930 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9931 "0340 Adapter temperature is OK now. "
9932 "temperature : %d Celsius\n",
9933 (uint32_t) icmd
->ulpContext
);
9936 /* Send temperature change event to applications */
9937 shost
= lpfc_shost_from_vport(phba
->pport
);
9938 fc_host_post_vendor_event(shost
, fc_get_event_number(),
9939 sizeof(temp_event_data
), (char *) &temp_event_data
,
9942 case ASYNC_STATUS_CN
:
9943 lpfc_sli_abts_err_handler(phba
, iocbq
);
9946 iocb_w
= (uint32_t *) icmd
;
9947 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9948 "0346 Ring %d handler: unexpected ASYNC_STATUS"
9950 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9951 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9952 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9953 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
9954 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
9955 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
9956 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
9957 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
9958 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
9966 * lpfc_sli4_setup - SLI ring setup function
9967 * @phba: Pointer to HBA context object.
9969 * lpfc_sli_setup sets up rings of the SLI interface with
9970 * number of iocbs per ring and iotags. This function is
9971 * called while driver attach to the HBA and before the
9972 * interrupts are enabled. So there is no need for locking.
9974 * This function always returns 0.
9977 lpfc_sli4_setup(struct lpfc_hba
*phba
)
9979 struct lpfc_sli_ring
*pring
;
9981 pring
= phba
->sli4_hba
.els_wq
->pring
;
9982 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9983 pring
->prt
[0].profile
= 0; /* Mask 0 */
9984 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9985 pring
->prt
[0].type
= FC_TYPE_ELS
;
9986 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9987 lpfc_els_unsol_event
;
9988 pring
->prt
[1].profile
= 0; /* Mask 1 */
9989 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9990 pring
->prt
[1].type
= FC_TYPE_ELS
;
9991 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9992 lpfc_els_unsol_event
;
9993 pring
->prt
[2].profile
= 0; /* Mask 2 */
9994 /* NameServer Inquiry */
9995 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9997 pring
->prt
[2].type
= FC_TYPE_CT
;
9998 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9999 lpfc_ct_unsol_event
;
10000 pring
->prt
[3].profile
= 0; /* Mask 3 */
10001 /* NameServer response */
10002 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
10004 pring
->prt
[3].type
= FC_TYPE_CT
;
10005 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
10006 lpfc_ct_unsol_event
;
10011 * lpfc_sli_setup - SLI ring setup function
10012 * @phba: Pointer to HBA context object.
10014 * lpfc_sli_setup sets up rings of the SLI interface with
10015 * number of iocbs per ring and iotags. This function is
10016 * called while driver attach to the HBA and before the
10017 * interrupts are enabled. So there is no need for locking.
10019 * This function always returns 0. SLI3 only.
10022 lpfc_sli_setup(struct lpfc_hba
*phba
)
10024 int i
, totiocbsize
= 0;
10025 struct lpfc_sli
*psli
= &phba
->sli
;
10026 struct lpfc_sli_ring
*pring
;
10028 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
10029 psli
->sli_flag
= 0;
10031 psli
->iocbq_lookup
= NULL
;
10032 psli
->iocbq_lookup_len
= 0;
10033 psli
->last_iotag
= 0;
10035 for (i
= 0; i
< psli
->num_rings
; i
++) {
10036 pring
= &psli
->sli3_ring
[i
];
10038 case LPFC_FCP_RING
: /* ring 0 - FCP */
10039 /* numCiocb and numRiocb are used in config_port */
10040 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
10041 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
10042 pring
->sli
.sli3
.numCiocb
+=
10043 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
10044 pring
->sli
.sli3
.numRiocb
+=
10045 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
10046 pring
->sli
.sli3
.numCiocb
+=
10047 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
10048 pring
->sli
.sli3
.numRiocb
+=
10049 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
10050 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
10051 SLI3_IOCB_CMD_SIZE
:
10052 SLI2_IOCB_CMD_SIZE
;
10053 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
10054 SLI3_IOCB_RSP_SIZE
:
10055 SLI2_IOCB_RSP_SIZE
;
10056 pring
->iotag_ctr
= 0;
10058 (phba
->cfg_hba_queue_depth
* 2);
10059 pring
->fast_iotag
= pring
->iotag_max
;
10060 pring
->num_mask
= 0;
10062 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
10063 /* numCiocb and numRiocb are used in config_port */
10064 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
10065 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
10066 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
10067 SLI3_IOCB_CMD_SIZE
:
10068 SLI2_IOCB_CMD_SIZE
;
10069 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
10070 SLI3_IOCB_RSP_SIZE
:
10071 SLI2_IOCB_RSP_SIZE
;
10072 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
10073 pring
->num_mask
= 0;
10075 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
10076 /* numCiocb and numRiocb are used in config_port */
10077 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
10078 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
10079 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
10080 SLI3_IOCB_CMD_SIZE
:
10081 SLI2_IOCB_CMD_SIZE
;
10082 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
10083 SLI3_IOCB_RSP_SIZE
:
10084 SLI2_IOCB_RSP_SIZE
;
10085 pring
->fast_iotag
= 0;
10086 pring
->iotag_ctr
= 0;
10087 pring
->iotag_max
= 4096;
10088 pring
->lpfc_sli_rcv_async_status
=
10089 lpfc_sli_async_event_handler
;
10090 pring
->num_mask
= LPFC_MAX_RING_MASK
;
10091 pring
->prt
[0].profile
= 0; /* Mask 0 */
10092 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
10093 pring
->prt
[0].type
= FC_TYPE_ELS
;
10094 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
10095 lpfc_els_unsol_event
;
10096 pring
->prt
[1].profile
= 0; /* Mask 1 */
10097 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
10098 pring
->prt
[1].type
= FC_TYPE_ELS
;
10099 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
10100 lpfc_els_unsol_event
;
10101 pring
->prt
[2].profile
= 0; /* Mask 2 */
10102 /* NameServer Inquiry */
10103 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
10105 pring
->prt
[2].type
= FC_TYPE_CT
;
10106 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
10107 lpfc_ct_unsol_event
;
10108 pring
->prt
[3].profile
= 0; /* Mask 3 */
10109 /* NameServer response */
10110 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
10112 pring
->prt
[3].type
= FC_TYPE_CT
;
10113 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
10114 lpfc_ct_unsol_event
;
10117 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
10118 pring
->sli
.sli3
.sizeCiocb
) +
10119 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
10121 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
10122 /* Too many cmd / rsp ring entries in SLI2 SLIM */
10123 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
10124 "SLI2 SLIM Data: x%x x%lx\n",
10125 phba
->brd_no
, totiocbsize
,
10126 (unsigned long) MAX_SLIM_IOCB_SIZE
);
10128 if (phba
->cfg_multi_ring_support
== 2)
10129 lpfc_extra_ring_setup(phba
);
10135 * lpfc_sli4_queue_init - Queue initialization function
10136 * @phba: Pointer to HBA context object.
10138 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
10139 * ring. This function also initializes ring indices of each ring.
10140 * This function is called during the initialization of the SLI
10141 * interface of an HBA.
10142 * This function is called with no lock held and always returns
10146 lpfc_sli4_queue_init(struct lpfc_hba
*phba
)
10148 struct lpfc_sli
*psli
;
10149 struct lpfc_sli_ring
*pring
;
10153 spin_lock_irq(&phba
->hbalock
);
10154 INIT_LIST_HEAD(&psli
->mboxq
);
10155 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
10156 /* Initialize list headers for txq and txcmplq as double linked lists */
10157 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
10158 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
10160 pring
->ringno
= LPFC_FCP_RING
;
10161 INIT_LIST_HEAD(&pring
->txq
);
10162 INIT_LIST_HEAD(&pring
->txcmplq
);
10163 INIT_LIST_HEAD(&pring
->iocb_continueq
);
10164 spin_lock_init(&pring
->ring_lock
);
10166 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
10167 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
10169 pring
->ringno
= LPFC_FCP_RING
;
10170 INIT_LIST_HEAD(&pring
->txq
);
10171 INIT_LIST_HEAD(&pring
->txcmplq
);
10172 INIT_LIST_HEAD(&pring
->iocb_continueq
);
10173 spin_lock_init(&pring
->ring_lock
);
10175 pring
= phba
->sli4_hba
.els_wq
->pring
;
10177 pring
->ringno
= LPFC_ELS_RING
;
10178 INIT_LIST_HEAD(&pring
->txq
);
10179 INIT_LIST_HEAD(&pring
->txcmplq
);
10180 INIT_LIST_HEAD(&pring
->iocb_continueq
);
10181 spin_lock_init(&pring
->ring_lock
);
10183 if (phba
->cfg_nvme_io_channel
) {
10184 pring
= phba
->sli4_hba
.nvmels_wq
->pring
;
10186 pring
->ringno
= LPFC_ELS_RING
;
10187 INIT_LIST_HEAD(&pring
->txq
);
10188 INIT_LIST_HEAD(&pring
->txcmplq
);
10189 INIT_LIST_HEAD(&pring
->iocb_continueq
);
10190 spin_lock_init(&pring
->ring_lock
);
10193 if (phba
->cfg_fof
) {
10194 pring
= phba
->sli4_hba
.oas_wq
->pring
;
10196 pring
->ringno
= LPFC_FCP_RING
;
10197 INIT_LIST_HEAD(&pring
->txq
);
10198 INIT_LIST_HEAD(&pring
->txcmplq
);
10199 INIT_LIST_HEAD(&pring
->iocb_continueq
);
10200 spin_lock_init(&pring
->ring_lock
);
10203 spin_unlock_irq(&phba
->hbalock
);
10207 * lpfc_sli_queue_init - Queue initialization function
10208 * @phba: Pointer to HBA context object.
10210 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
10211 * ring. This function also initializes ring indices of each ring.
10212 * This function is called during the initialization of the SLI
10213 * interface of an HBA.
10214 * This function is called with no lock held and always returns
10218 lpfc_sli_queue_init(struct lpfc_hba
*phba
)
10220 struct lpfc_sli
*psli
;
10221 struct lpfc_sli_ring
*pring
;
10225 spin_lock_irq(&phba
->hbalock
);
10226 INIT_LIST_HEAD(&psli
->mboxq
);
10227 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
10228 /* Initialize list headers for txq and txcmplq as double linked lists */
10229 for (i
= 0; i
< psli
->num_rings
; i
++) {
10230 pring
= &psli
->sli3_ring
[i
];
10232 pring
->sli
.sli3
.next_cmdidx
= 0;
10233 pring
->sli
.sli3
.local_getidx
= 0;
10234 pring
->sli
.sli3
.cmdidx
= 0;
10235 INIT_LIST_HEAD(&pring
->iocb_continueq
);
10236 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
10237 INIT_LIST_HEAD(&pring
->postbufq
);
10239 INIT_LIST_HEAD(&pring
->txq
);
10240 INIT_LIST_HEAD(&pring
->txcmplq
);
10241 spin_lock_init(&pring
->ring_lock
);
10243 spin_unlock_irq(&phba
->hbalock
);
10247 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
10248 * @phba: Pointer to HBA context object.
10250 * This routine flushes the mailbox command subsystem. It will unconditionally
10251 * flush all the mailbox commands in the three possible stages in the mailbox
10252 * command sub-system: pending mailbox command queue; the outstanding mailbox
10253 * command; and completed mailbox command queue. It is caller's responsibility
10254 * to make sure that the driver is in the proper state to flush the mailbox
10255 * command sub-system. Namely, the posting of mailbox commands into the
10256 * pending mailbox command queue from the various clients must be stopped;
10257 * either the HBA is in a state that it will never works on the outstanding
10258 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
10259 * mailbox command has been completed.
10262 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
10264 LIST_HEAD(completions
);
10265 struct lpfc_sli
*psli
= &phba
->sli
;
10267 unsigned long iflag
;
10269 /* Flush all the mailbox commands in the mbox system */
10270 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10271 /* The pending mailbox command queue */
10272 list_splice_init(&phba
->sli
.mboxq
, &completions
);
10273 /* The outstanding active mailbox command */
10274 if (psli
->mbox_active
) {
10275 list_add_tail(&psli
->mbox_active
->list
, &completions
);
10276 psli
->mbox_active
= NULL
;
10277 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
10279 /* The completed mailbox command queue */
10280 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
10281 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10283 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
10284 while (!list_empty(&completions
)) {
10285 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
10286 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
10287 if (pmb
->mbox_cmpl
)
10288 pmb
->mbox_cmpl(phba
, pmb
);
10293 * lpfc_sli_host_down - Vport cleanup function
10294 * @vport: Pointer to virtual port object.
10296 * lpfc_sli_host_down is called to clean up the resources
10297 * associated with a vport before destroying virtual
10298 * port data structures.
10299 * This function does following operations:
10300 * - Free discovery resources associated with this virtual
10302 * - Free iocbs associated with this virtual port in
10304 * - Send abort for all iocb commands associated with this
10305 * vport in txcmplq.
10307 * This function is called with no lock held and always returns 1.
10310 lpfc_sli_host_down(struct lpfc_vport
*vport
)
10312 LIST_HEAD(completions
);
10313 struct lpfc_hba
*phba
= vport
->phba
;
10314 struct lpfc_sli
*psli
= &phba
->sli
;
10315 struct lpfc_queue
*qp
= NULL
;
10316 struct lpfc_sli_ring
*pring
;
10317 struct lpfc_iocbq
*iocb
, *next_iocb
;
10319 unsigned long flags
= 0;
10320 uint16_t prev_pring_flag
;
10322 lpfc_cleanup_discovery_resources(vport
);
10324 spin_lock_irqsave(&phba
->hbalock
, flags
);
10327 * Error everything on the txq since these iocbs
10328 * have not been given to the FW yet.
10329 * Also issue ABTS for everything on the txcmplq
10331 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10332 for (i
= 0; i
< psli
->num_rings
; i
++) {
10333 pring
= &psli
->sli3_ring
[i
];
10334 prev_pring_flag
= pring
->flag
;
10335 /* Only slow rings */
10336 if (pring
->ringno
== LPFC_ELS_RING
) {
10337 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10338 /* Set the lpfc data pending flag */
10339 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10341 list_for_each_entry_safe(iocb
, next_iocb
,
10342 &pring
->txq
, list
) {
10343 if (iocb
->vport
!= vport
)
10345 list_move_tail(&iocb
->list
, &completions
);
10347 list_for_each_entry_safe(iocb
, next_iocb
,
10348 &pring
->txcmplq
, list
) {
10349 if (iocb
->vport
!= vport
)
10351 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
10353 pring
->flag
= prev_pring_flag
;
10356 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10360 if (pring
== phba
->sli4_hba
.els_wq
->pring
) {
10361 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10362 /* Set the lpfc data pending flag */
10363 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10365 prev_pring_flag
= pring
->flag
;
10366 spin_lock_irq(&pring
->ring_lock
);
10367 list_for_each_entry_safe(iocb
, next_iocb
,
10368 &pring
->txq
, list
) {
10369 if (iocb
->vport
!= vport
)
10371 list_move_tail(&iocb
->list
, &completions
);
10373 spin_unlock_irq(&pring
->ring_lock
);
10374 list_for_each_entry_safe(iocb
, next_iocb
,
10375 &pring
->txcmplq
, list
) {
10376 if (iocb
->vport
!= vport
)
10378 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
10380 pring
->flag
= prev_pring_flag
;
10383 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10385 /* Cancel all the IOCBs from the completions list */
10386 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
10392 * lpfc_sli_hba_down - Resource cleanup function for the HBA
10393 * @phba: Pointer to HBA context object.
10395 * This function cleans up all iocb, buffers, mailbox commands
10396 * while shutting down the HBA. This function is called with no
10397 * lock held and always returns 1.
10398 * This function does the following to cleanup driver resources:
10399 * - Free discovery resources for each virtual port
10400 * - Cleanup any pending fabric iocbs
10401 * - Iterate through the iocb txq and free each entry
10403 * - Free up any buffer posted to the HBA
10404 * - Free mailbox commands in the mailbox queue.
10407 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
10409 LIST_HEAD(completions
);
10410 struct lpfc_sli
*psli
= &phba
->sli
;
10411 struct lpfc_queue
*qp
= NULL
;
10412 struct lpfc_sli_ring
*pring
;
10413 struct lpfc_dmabuf
*buf_ptr
;
10414 unsigned long flags
= 0;
10417 /* Shutdown the mailbox command sub-system */
10418 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
10420 lpfc_hba_down_prep(phba
);
10422 lpfc_fabric_abort_hba(phba
);
10424 spin_lock_irqsave(&phba
->hbalock
, flags
);
10427 * Error everything on the txq since these iocbs
10428 * have not been given to the FW yet.
10430 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10431 for (i
= 0; i
< psli
->num_rings
; i
++) {
10432 pring
= &psli
->sli3_ring
[i
];
10433 /* Only slow rings */
10434 if (pring
->ringno
== LPFC_ELS_RING
) {
10435 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10436 /* Set the lpfc data pending flag */
10437 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10439 list_splice_init(&pring
->txq
, &completions
);
10442 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10446 spin_lock_irq(&pring
->ring_lock
);
10447 list_splice_init(&pring
->txq
, &completions
);
10448 spin_unlock_irq(&pring
->ring_lock
);
10449 if (pring
== phba
->sli4_hba
.els_wq
->pring
) {
10450 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10451 /* Set the lpfc data pending flag */
10452 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10456 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10458 /* Cancel all the IOCBs from the completions list */
10459 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
10462 spin_lock_irqsave(&phba
->hbalock
, flags
);
10463 list_splice_init(&phba
->elsbuf
, &completions
);
10464 phba
->elsbuf_cnt
= 0;
10465 phba
->elsbuf_prev_cnt
= 0;
10466 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10468 while (!list_empty(&completions
)) {
10469 list_remove_head(&completions
, buf_ptr
,
10470 struct lpfc_dmabuf
, list
);
10471 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
10475 /* Return any active mbox cmds */
10476 del_timer_sync(&psli
->mbox_tmo
);
10478 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
10479 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
10480 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
10486 * lpfc_sli_pcimem_bcopy - SLI memory copy function
10487 * @srcp: Source memory pointer.
10488 * @destp: Destination memory pointer.
10489 * @cnt: Number of words required to be copied.
10491 * This function is used for copying data between driver memory
10492 * and the SLI memory. This function also changes the endianness
10493 * of each word if native endianness is different from SLI
10494 * endianness. This function can be called with or without
10498 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
10500 uint32_t *src
= srcp
;
10501 uint32_t *dest
= destp
;
10505 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
10507 ldata
= le32_to_cpu(ldata
);
10516 * lpfc_sli_bemem_bcopy - SLI memory copy function
10517 * @srcp: Source memory pointer.
10518 * @destp: Destination memory pointer.
10519 * @cnt: Number of words required to be copied.
10521 * This function is used for copying data between a data structure
10522 * with big endian representation to local endianness.
10523 * This function can be called with or without lock.
10526 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
10528 uint32_t *src
= srcp
;
10529 uint32_t *dest
= destp
;
10533 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
10535 ldata
= be32_to_cpu(ldata
);
10543 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
10544 * @phba: Pointer to HBA context object.
10545 * @pring: Pointer to driver SLI ring object.
10546 * @mp: Pointer to driver buffer object.
10548 * This function is called with no lock held.
10549 * It always return zero after adding the buffer to the postbufq
10553 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10554 struct lpfc_dmabuf
*mp
)
10556 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
10558 spin_lock_irq(&phba
->hbalock
);
10559 list_add_tail(&mp
->list
, &pring
->postbufq
);
10560 pring
->postbufq_cnt
++;
10561 spin_unlock_irq(&phba
->hbalock
);
10566 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
10567 * @phba: Pointer to HBA context object.
10569 * When HBQ is enabled, buffers are searched based on tags. This function
10570 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
10571 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
10572 * does not conflict with tags of buffer posted for unsolicited events.
10573 * The function returns the allocated tag. The function is called with
10577 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
10579 spin_lock_irq(&phba
->hbalock
);
10580 phba
->buffer_tag_count
++;
10582 * Always set the QUE_BUFTAG_BIT to distiguish between
10583 * a tag assigned by HBQ.
10585 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
10586 spin_unlock_irq(&phba
->hbalock
);
10587 return phba
->buffer_tag_count
;
10591 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
10592 * @phba: Pointer to HBA context object.
10593 * @pring: Pointer to driver SLI ring object.
10594 * @tag: Buffer tag.
10596 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
10597 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
10598 * iocb is posted to the response ring with the tag of the buffer.
10599 * This function searches the pring->postbufq list using the tag
10600 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
10601 * iocb. If the buffer is found then lpfc_dmabuf object of the
10602 * buffer is returned to the caller else NULL is returned.
10603 * This function is called with no lock held.
10605 struct lpfc_dmabuf
*
10606 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10609 struct lpfc_dmabuf
*mp
, *next_mp
;
10610 struct list_head
*slp
= &pring
->postbufq
;
10612 /* Search postbufq, from the beginning, looking for a match on tag */
10613 spin_lock_irq(&phba
->hbalock
);
10614 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
10615 if (mp
->buffer_tag
== tag
) {
10616 list_del_init(&mp
->list
);
10617 pring
->postbufq_cnt
--;
10618 spin_unlock_irq(&phba
->hbalock
);
10623 spin_unlock_irq(&phba
->hbalock
);
10624 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10625 "0402 Cannot find virtual addr for buffer tag on "
10626 "ring %d Data x%lx x%p x%p x%x\n",
10627 pring
->ringno
, (unsigned long) tag
,
10628 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
10634 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
10635 * @phba: Pointer to HBA context object.
10636 * @pring: Pointer to driver SLI ring object.
10637 * @phys: DMA address of the buffer.
10639 * This function searches the buffer list using the dma_address
10640 * of unsolicited event to find the driver's lpfc_dmabuf object
10641 * corresponding to the dma_address. The function returns the
10642 * lpfc_dmabuf object if a buffer is found else it returns NULL.
10643 * This function is called by the ct and els unsolicited event
10644 * handlers to get the buffer associated with the unsolicited
10647 * This function is called with no lock held.
10649 struct lpfc_dmabuf
*
10650 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10653 struct lpfc_dmabuf
*mp
, *next_mp
;
10654 struct list_head
*slp
= &pring
->postbufq
;
10656 /* Search postbufq, from the beginning, looking for a match on phys */
10657 spin_lock_irq(&phba
->hbalock
);
10658 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
10659 if (mp
->phys
== phys
) {
10660 list_del_init(&mp
->list
);
10661 pring
->postbufq_cnt
--;
10662 spin_unlock_irq(&phba
->hbalock
);
10667 spin_unlock_irq(&phba
->hbalock
);
10668 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10669 "0410 Cannot find virtual addr for mapped buf on "
10670 "ring %d Data x%llx x%p x%p x%x\n",
10671 pring
->ringno
, (unsigned long long)phys
,
10672 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
10677 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
10678 * @phba: Pointer to HBA context object.
10679 * @cmdiocb: Pointer to driver command iocb object.
10680 * @rspiocb: Pointer to driver response iocb object.
10682 * This function is the completion handler for the abort iocbs for
10683 * ELS commands. This function is called from the ELS ring event
10684 * handler with no lock held. This function frees memory resources
10685 * associated with the abort iocb.
10688 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10689 struct lpfc_iocbq
*rspiocb
)
10691 IOCB_t
*irsp
= &rspiocb
->iocb
;
10692 uint16_t abort_iotag
, abort_context
;
10693 struct lpfc_iocbq
*abort_iocb
= NULL
;
10695 if (irsp
->ulpStatus
) {
10698 * Assume that the port already completed and returned, or
10699 * will return the iocb. Just Log the message.
10701 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
10702 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
10704 spin_lock_irq(&phba
->hbalock
);
10705 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
10706 if (irsp
->ulpCommand
== CMD_ABORT_XRI_CX
&&
10707 irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
10708 irsp
->un
.ulpWord
[4] == IOERR_ABORT_REQUESTED
) {
10709 spin_unlock_irq(&phba
->hbalock
);
10712 if (abort_iotag
!= 0 &&
10713 abort_iotag
<= phba
->sli
.last_iotag
)
10715 phba
->sli
.iocbq_lookup
[abort_iotag
];
10717 /* For sli4 the abort_tag is the XRI,
10718 * so the abort routine puts the iotag of the iocb
10719 * being aborted in the context field of the abort
10722 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
10724 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
10725 "0327 Cannot abort els iocb %p "
10726 "with tag %x context %x, abort status %x, "
10728 abort_iocb
, abort_iotag
, abort_context
,
10729 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
10731 spin_unlock_irq(&phba
->hbalock
);
10734 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10739 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
10740 * @phba: Pointer to HBA context object.
10741 * @cmdiocb: Pointer to driver command iocb object.
10742 * @rspiocb: Pointer to driver response iocb object.
10744 * The function is called from SLI ring event handler with no
10745 * lock held. This function is the completion handler for ELS commands
10746 * which are aborted. The function frees memory resources used for
10747 * the aborted ELS commands.
10750 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10751 struct lpfc_iocbq
*rspiocb
)
10753 IOCB_t
*irsp
= &rspiocb
->iocb
;
10755 /* ELS cmd tag <ulpIoTag> completes */
10756 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
10757 "0139 Ignoring ELS cmd tag x%x completion Data: "
10759 irsp
->ulpIoTag
, irsp
->ulpStatus
,
10760 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
10761 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
10762 lpfc_ct_free_iocb(phba
, cmdiocb
);
10764 lpfc_els_free_iocb(phba
, cmdiocb
);
10769 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
10770 * @phba: Pointer to HBA context object.
10771 * @pring: Pointer to driver SLI ring object.
10772 * @cmdiocb: Pointer to driver command iocb object.
10774 * This function issues an abort iocb for the provided command iocb down to
10775 * the port. Other than the case the outstanding command iocb is an abort
10776 * request, this function issues abort out unconditionally. This function is
10777 * called with hbalock held. The function returns 0 when it fails due to
10778 * memory allocation failure or when the command iocb is an abort request.
10781 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10782 struct lpfc_iocbq
*cmdiocb
)
10784 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10785 struct lpfc_iocbq
*abtsiocbp
;
10786 IOCB_t
*icmd
= NULL
;
10787 IOCB_t
*iabt
= NULL
;
10789 unsigned long iflags
;
10790 struct lpfc_nodelist
*ndlp
;
10792 lockdep_assert_held(&phba
->hbalock
);
10795 * There are certain command types we don't want to abort. And we
10796 * don't want to abort commands that are already in the process of
10799 icmd
= &cmdiocb
->iocb
;
10800 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10801 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10802 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10805 /* issue ABTS for this IOCB based on iotag */
10806 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10807 if (abtsiocbp
== NULL
)
10810 /* This signals the response to set the correct status
10811 * before calling the completion handler
10813 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10815 iabt
= &abtsiocbp
->iocb
;
10816 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10817 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
10818 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10819 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
10820 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
10822 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
10823 if (pring
->ringno
== LPFC_ELS_RING
) {
10824 ndlp
= (struct lpfc_nodelist
*)(cmdiocb
->context1
);
10825 iabt
->un
.acxri
.abortContextTag
= ndlp
->nlp_rpi
;
10829 iabt
->ulpClass
= icmd
->ulpClass
;
10831 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10832 abtsiocbp
->hba_wqidx
= cmdiocb
->hba_wqidx
;
10833 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
10834 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10835 if (cmdiocb
->iocb_flag
& LPFC_IO_FOF
)
10836 abtsiocbp
->iocb_flag
|= LPFC_IO_FOF
;
10838 if (phba
->link_state
>= LPFC_LINK_UP
)
10839 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
10841 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
10843 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
10844 abtsiocbp
->vport
= vport
;
10846 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
10847 "0339 Abort xri x%x, original iotag x%x, "
10848 "abort cmd iotag x%x\n",
10849 iabt
->un
.acxri
.abortIoTag
,
10850 iabt
->un
.acxri
.abortContextTag
,
10853 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10854 pring
= lpfc_sli4_calc_ring(phba
, abtsiocbp
);
10855 if (unlikely(pring
== NULL
))
10857 /* Note: both hbalock and ring_lock need to be set here */
10858 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
10859 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10861 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
10863 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10868 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10871 * Caller to this routine should check for IOCB_ERROR
10872 * and handle it properly. This routine no longer removes
10873 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10879 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
10880 * @phba: Pointer to HBA context object.
10881 * @pring: Pointer to driver SLI ring object.
10882 * @cmdiocb: Pointer to driver command iocb object.
10884 * This function issues an abort iocb for the provided command iocb. In case
10885 * of unloading, the abort iocb will not be issued to commands on the ELS
10886 * ring. Instead, the callback function shall be changed to those commands
10887 * so that nothing happens when them finishes. This function is called with
10888 * hbalock held. The function returns 0 when the command iocb is an abort
10892 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10893 struct lpfc_iocbq
*cmdiocb
)
10895 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10896 int retval
= IOCB_ERROR
;
10897 IOCB_t
*icmd
= NULL
;
10899 lockdep_assert_held(&phba
->hbalock
);
10902 * There are certain command types we don't want to abort. And we
10903 * don't want to abort commands that are already in the process of
10906 icmd
= &cmdiocb
->iocb
;
10907 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10908 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10909 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10913 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10914 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10916 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10917 goto abort_iotag_exit
;
10921 * If we're unloading, don't abort iocb on the ELS ring, but change
10922 * the callback so that nothing happens when it finishes.
10924 if ((vport
->load_flag
& FC_UNLOADING
) &&
10925 (pring
->ringno
== LPFC_ELS_RING
)) {
10926 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10927 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10929 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10930 goto abort_iotag_exit
;
10933 /* Now, we try to issue the abort to the cmdiocb out */
10934 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
10938 * Caller to this routine should check for IOCB_ERROR
10939 * and handle it properly. This routine no longer removes
10940 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10946 * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb
10947 * @phba: Pointer to HBA context object.
10948 * @pring: Pointer to driver SLI ring object.
10949 * @cmdiocb: Pointer to driver command iocb object.
10951 * This function issues an abort iocb for the provided command iocb down to
10952 * the port. Other than the case the outstanding command iocb is an abort
10953 * request, this function issues abort out unconditionally. This function is
10954 * called with hbalock held. The function returns 0 when it fails due to
10955 * memory allocation failure or when the command iocb is an abort request.
10958 lpfc_sli4_abort_nvme_io(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10959 struct lpfc_iocbq
*cmdiocb
)
10961 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10962 struct lpfc_iocbq
*abtsiocbp
;
10963 union lpfc_wqe128
*abts_wqe
;
10967 * There are certain command types we don't want to abort. And we
10968 * don't want to abort commands that are already in the process of
10971 if (cmdiocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
10972 cmdiocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
||
10973 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10976 /* issue ABTS for this io based on iotag */
10977 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10978 if (abtsiocbp
== NULL
)
10981 /* This signals the response to set the correct status
10982 * before calling the completion handler
10984 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10986 /* Complete prepping the abort wqe and issue to the FW. */
10987 abts_wqe
= &abtsiocbp
->wqe
;
10988 bf_set(abort_cmd_ia
, &abts_wqe
->abort_cmd
, 0);
10989 bf_set(abort_cmd_criteria
, &abts_wqe
->abort_cmd
, T_XRI_TAG
);
10991 /* Explicitly set reserved fields to zero.*/
10992 abts_wqe
->abort_cmd
.rsrvd4
= 0;
10993 abts_wqe
->abort_cmd
.rsrvd5
= 0;
10995 /* WQE Common - word 6. Context is XRI tag. Set 0. */
10996 bf_set(wqe_xri_tag
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10997 bf_set(wqe_ctxt_tag
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
11000 bf_set(wqe_ct
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
11001 bf_set(wqe_cmnd
, &abts_wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
11002 bf_set(wqe_class
, &abts_wqe
->abort_cmd
.wqe_com
,
11003 cmdiocb
->iocb
.ulpClass
);
11005 /* word 8 - tell the FW to abort the IO associated with this
11006 * outstanding exchange ID.
11008 abts_wqe
->abort_cmd
.wqe_com
.abort_tag
= cmdiocb
->sli4_xritag
;
11010 /* word 9 - this is the iotag for the abts_wqe completion. */
11011 bf_set(wqe_reqtag
, &abts_wqe
->abort_cmd
.wqe_com
,
11015 bf_set(wqe_wqid
, &abts_wqe
->abort_cmd
.wqe_com
, cmdiocb
->hba_wqidx
);
11016 bf_set(wqe_qosd
, &abts_wqe
->abort_cmd
.wqe_com
, 1);
11017 bf_set(wqe_lenloc
, &abts_wqe
->abort_cmd
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
11020 bf_set(wqe_cmd_type
, &abts_wqe
->abort_cmd
.wqe_com
, OTHER_COMMAND
);
11021 bf_set(wqe_wqec
, &abts_wqe
->abort_cmd
.wqe_com
, 1);
11022 bf_set(wqe_cqid
, &abts_wqe
->abort_cmd
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
11024 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11025 abtsiocbp
->iocb_flag
|= LPFC_IO_NVME
;
11026 abtsiocbp
->vport
= vport
;
11027 abtsiocbp
->wqe_cmpl
= lpfc_nvme_abort_fcreq_cmpl
;
11028 retval
= lpfc_sli4_issue_wqe(phba
, LPFC_FCP_RING
, abtsiocbp
);
11030 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NVME
,
11031 "6147 Failed abts issue_wqe with status x%x "
11033 retval
, cmdiocb
->sli4_xritag
);
11034 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
11038 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NVME
,
11039 "6148 Drv Abort NVME Request Issued for "
11040 "ox_id x%x on reqtag x%x\n",
11041 cmdiocb
->sli4_xritag
,
11048 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
11049 * @phba: pointer to lpfc HBA data structure.
11051 * This routine will abort all pending and outstanding iocbs to an HBA.
11054 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
11056 struct lpfc_sli
*psli
= &phba
->sli
;
11057 struct lpfc_sli_ring
*pring
;
11058 struct lpfc_queue
*qp
= NULL
;
11061 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
11062 for (i
= 0; i
< psli
->num_rings
; i
++) {
11063 pring
= &psli
->sli3_ring
[i
];
11064 lpfc_sli_abort_iocb_ring(phba
, pring
);
11068 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
11072 lpfc_sli_abort_iocb_ring(phba
, pring
);
11077 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
11078 * @iocbq: Pointer to driver iocb object.
11079 * @vport: Pointer to driver virtual port object.
11080 * @tgt_id: SCSI ID of the target.
11081 * @lun_id: LUN ID of the scsi device.
11082 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
11084 * This function acts as an iocb filter for functions which abort or count
11085 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
11086 * 0 if the filtering criteria is met for the given iocb and will return
11087 * 1 if the filtering criteria is not met.
11088 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
11089 * given iocb is for the SCSI device specified by vport, tgt_id and
11090 * lun_id parameter.
11091 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
11092 * given iocb is for the SCSI target specified by vport and tgt_id
11094 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
11095 * given iocb is for the SCSI host associated with the given vport.
11096 * This function is called with no locks held.
11099 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
11100 uint16_t tgt_id
, uint64_t lun_id
,
11101 lpfc_ctx_cmd ctx_cmd
)
11103 struct lpfc_scsi_buf
*lpfc_cmd
;
11106 if (iocbq
->vport
!= vport
)
11109 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
) ||
11110 !(iocbq
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
))
11113 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
11115 if (lpfc_cmd
->pCmd
== NULL
)
11120 if ((lpfc_cmd
->rdata
) && (lpfc_cmd
->rdata
->pnode
) &&
11121 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
11122 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
11126 if ((lpfc_cmd
->rdata
) && (lpfc_cmd
->rdata
->pnode
) &&
11127 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
11130 case LPFC_CTX_HOST
:
11134 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
11135 __func__
, ctx_cmd
);
11143 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
11144 * @vport: Pointer to virtual port.
11145 * @tgt_id: SCSI ID of the target.
11146 * @lun_id: LUN ID of the scsi device.
11147 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11149 * This function returns number of FCP commands pending for the vport.
11150 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
11151 * commands pending on the vport associated with SCSI device specified
11152 * by tgt_id and lun_id parameters.
11153 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
11154 * commands pending on the vport associated with SCSI target specified
11155 * by tgt_id parameter.
11156 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
11157 * commands pending on the vport.
11158 * This function returns the number of iocbs which satisfy the filter.
11159 * This function is called without any lock held.
11162 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
11163 lpfc_ctx_cmd ctx_cmd
)
11165 struct lpfc_hba
*phba
= vport
->phba
;
11166 struct lpfc_iocbq
*iocbq
;
11169 spin_lock_irq(&phba
->hbalock
);
11170 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
11171 iocbq
= phba
->sli
.iocbq_lookup
[i
];
11173 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
11177 spin_unlock_irq(&phba
->hbalock
);
11183 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
11184 * @phba: Pointer to HBA context object
11185 * @cmdiocb: Pointer to command iocb object.
11186 * @rspiocb: Pointer to response iocb object.
11188 * This function is called when an aborted FCP iocb completes. This
11189 * function is called by the ring event handler with no lock held.
11190 * This function frees the iocb.
11193 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
11194 struct lpfc_iocbq
*rspiocb
)
11196 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11197 "3096 ABORT_XRI_CN completing on rpi x%x "
11198 "original iotag x%x, abort cmd iotag x%x "
11199 "status 0x%x, reason 0x%x\n",
11200 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
11201 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
11202 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
11203 rspiocb
->iocb
.un
.ulpWord
[4]);
11204 lpfc_sli_release_iocbq(phba
, cmdiocb
);
11209 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
11210 * @vport: Pointer to virtual port.
11211 * @pring: Pointer to driver SLI ring object.
11212 * @tgt_id: SCSI ID of the target.
11213 * @lun_id: LUN ID of the scsi device.
11214 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11216 * This function sends an abort command for every SCSI command
11217 * associated with the given virtual port pending on the ring
11218 * filtered by lpfc_sli_validate_fcp_iocb function.
11219 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
11220 * FCP iocbs associated with lun specified by tgt_id and lun_id
11222 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
11223 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11224 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
11225 * FCP iocbs associated with virtual port.
11226 * This function returns number of iocbs it failed to abort.
11227 * This function is called with no locks held.
11230 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
11231 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
11233 struct lpfc_hba
*phba
= vport
->phba
;
11234 struct lpfc_iocbq
*iocbq
;
11235 struct lpfc_iocbq
*abtsiocb
;
11236 struct lpfc_sli_ring
*pring_s4
;
11237 IOCB_t
*cmd
= NULL
;
11238 int errcnt
= 0, ret_val
= 0;
11241 /* all I/Os are in process of being flushed */
11242 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
)
11245 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
11246 iocbq
= phba
->sli
.iocbq_lookup
[i
];
11248 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
11253 * If the iocbq is already being aborted, don't take a second
11254 * action, but do count it.
11256 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
11259 /* issue ABTS for this IOCB based on iotag */
11260 abtsiocb
= lpfc_sli_get_iocbq(phba
);
11261 if (abtsiocb
== NULL
) {
11266 /* indicate the IO is being aborted by the driver. */
11267 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
11269 cmd
= &iocbq
->iocb
;
11270 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
11271 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
11272 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11273 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
11275 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
11276 abtsiocb
->iocb
.ulpLe
= 1;
11277 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
11278 abtsiocb
->vport
= vport
;
11280 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11281 abtsiocb
->hba_wqidx
= iocbq
->hba_wqidx
;
11282 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
11283 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
11284 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
11285 abtsiocb
->iocb_flag
|= LPFC_IO_FOF
;
11287 if (lpfc_is_link_up(phba
))
11288 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
11290 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
11292 /* Setup callback routine and issue the command. */
11293 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
11294 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11295 pring_s4
= lpfc_sli4_calc_ring(phba
, iocbq
);
11298 ret_val
= lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
11301 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
11303 if (ret_val
== IOCB_ERROR
) {
11304 lpfc_sli_release_iocbq(phba
, abtsiocb
);
11314 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
11315 * @vport: Pointer to virtual port.
11316 * @pring: Pointer to driver SLI ring object.
11317 * @tgt_id: SCSI ID of the target.
11318 * @lun_id: LUN ID of the scsi device.
11319 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11321 * This function sends an abort command for every SCSI command
11322 * associated with the given virtual port pending on the ring
11323 * filtered by lpfc_sli_validate_fcp_iocb function.
11324 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
11325 * FCP iocbs associated with lun specified by tgt_id and lun_id
11327 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
11328 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11329 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
11330 * FCP iocbs associated with virtual port.
11331 * This function returns number of iocbs it aborted .
11332 * This function is called with no locks held right after a taskmgmt
11336 lpfc_sli_abort_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
11337 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd cmd
)
11339 struct lpfc_hba
*phba
= vport
->phba
;
11340 struct lpfc_scsi_buf
*lpfc_cmd
;
11341 struct lpfc_iocbq
*abtsiocbq
;
11342 struct lpfc_nodelist
*ndlp
;
11343 struct lpfc_iocbq
*iocbq
;
11345 int sum
, i
, ret_val
;
11346 unsigned long iflags
;
11347 struct lpfc_sli_ring
*pring_s4
;
11349 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11351 /* all I/Os are in process of being flushed */
11352 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
11353 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11358 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
11359 iocbq
= phba
->sli
.iocbq_lookup
[i
];
11361 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
11366 * If the iocbq is already being aborted, don't take a second
11367 * action, but do count it.
11369 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
11372 /* issue ABTS for this IOCB based on iotag */
11373 abtsiocbq
= __lpfc_sli_get_iocbq(phba
);
11374 if (abtsiocbq
== NULL
)
11377 icmd
= &iocbq
->iocb
;
11378 abtsiocbq
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
11379 abtsiocbq
->iocb
.un
.acxri
.abortContextTag
= icmd
->ulpContext
;
11380 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11381 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
=
11382 iocbq
->sli4_xritag
;
11384 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
11385 abtsiocbq
->iocb
.ulpLe
= 1;
11386 abtsiocbq
->iocb
.ulpClass
= icmd
->ulpClass
;
11387 abtsiocbq
->vport
= vport
;
11389 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11390 abtsiocbq
->hba_wqidx
= iocbq
->hba_wqidx
;
11391 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
11392 abtsiocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
11393 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
11394 abtsiocbq
->iocb_flag
|= LPFC_IO_FOF
;
11396 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
11397 ndlp
= lpfc_cmd
->rdata
->pnode
;
11399 if (lpfc_is_link_up(phba
) &&
11400 (ndlp
&& ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
11401 abtsiocbq
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
11403 abtsiocbq
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
11405 /* Setup callback routine and issue the command. */
11406 abtsiocbq
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
11409 * Indicate the IO is being aborted by the driver and set
11410 * the caller's flag into the aborted IO.
11412 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
11414 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11415 pring_s4
= lpfc_sli4_calc_ring(phba
, abtsiocbq
);
11418 /* Note: both hbalock and ring_lock must be set here */
11419 spin_lock(&pring_s4
->ring_lock
);
11420 ret_val
= __lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
11422 spin_unlock(&pring_s4
->ring_lock
);
11424 ret_val
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
11429 if (ret_val
== IOCB_ERROR
)
11430 __lpfc_sli_release_iocbq(phba
, abtsiocbq
);
11434 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11439 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
11440 * @phba: Pointer to HBA context object.
11441 * @cmdiocbq: Pointer to command iocb.
11442 * @rspiocbq: Pointer to response iocb.
11444 * This function is the completion handler for iocbs issued using
11445 * lpfc_sli_issue_iocb_wait function. This function is called by the
11446 * ring event handler function without any lock held. This function
11447 * can be called from both worker thread context and interrupt
11448 * context. This function also can be called from other thread which
11449 * cleans up the SLI layer objects.
11450 * This function copy the contents of the response iocb to the
11451 * response iocb memory object provided by the caller of
11452 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
11453 * sleeps for the iocb completion.
11456 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
11457 struct lpfc_iocbq
*cmdiocbq
,
11458 struct lpfc_iocbq
*rspiocbq
)
11460 wait_queue_head_t
*pdone_q
;
11461 unsigned long iflags
;
11462 struct lpfc_scsi_buf
*lpfc_cmd
;
11464 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11465 if (cmdiocbq
->iocb_flag
& LPFC_IO_WAKE_TMO
) {
11468 * A time out has occurred for the iocb. If a time out
11469 * completion handler has been supplied, call it. Otherwise,
11470 * just free the iocbq.
11473 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11474 cmdiocbq
->iocb_cmpl
= cmdiocbq
->wait_iocb_cmpl
;
11475 cmdiocbq
->wait_iocb_cmpl
= NULL
;
11476 if (cmdiocbq
->iocb_cmpl
)
11477 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, NULL
);
11479 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
11483 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
11484 if (cmdiocbq
->context2
&& rspiocbq
)
11485 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
11486 &rspiocbq
->iocb
, sizeof(IOCB_t
));
11488 /* Set the exchange busy flag for task management commands */
11489 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
11490 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
11491 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
11493 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
11496 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
11499 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11504 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
11505 * @phba: Pointer to HBA context object..
11506 * @piocbq: Pointer to command iocb.
11507 * @flag: Flag to test.
11509 * This routine grabs the hbalock and then test the iocb_flag to
11510 * see if the passed in flag is set.
11512 * 1 if flag is set.
11513 * 0 if flag is not set.
11516 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
11517 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
11519 unsigned long iflags
;
11522 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11523 ret
= piocbq
->iocb_flag
& flag
;
11524 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11530 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
11531 * @phba: Pointer to HBA context object..
11532 * @pring: Pointer to sli ring.
11533 * @piocb: Pointer to command iocb.
11534 * @prspiocbq: Pointer to response iocb.
11535 * @timeout: Timeout in number of seconds.
11537 * This function issues the iocb to firmware and waits for the
11538 * iocb to complete. The iocb_cmpl field of the shall be used
11539 * to handle iocbs which time out. If the field is NULL, the
11540 * function shall free the iocbq structure. If more clean up is
11541 * needed, the caller is expected to provide a completion function
11542 * that will provide the needed clean up. If the iocb command is
11543 * not completed within timeout seconds, the function will either
11544 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
11545 * completion function set in the iocb_cmpl field and then return
11546 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
11547 * resources if this function returns IOCB_TIMEDOUT.
11548 * The function waits for the iocb completion using an
11549 * non-interruptible wait.
11550 * This function will sleep while waiting for iocb completion.
11551 * So, this function should not be called from any context which
11552 * does not allow sleeping. Due to the same reason, this function
11553 * cannot be called with interrupt disabled.
11554 * This function assumes that the iocb completions occur while
11555 * this function sleep. So, this function cannot be called from
11556 * the thread which process iocb completion for this ring.
11557 * This function clears the iocb_flag of the iocb object before
11558 * issuing the iocb and the iocb completion handler sets this
11559 * flag and wakes this thread when the iocb completes.
11560 * The contents of the response iocb will be copied to prspiocbq
11561 * by the completion handler when the command completes.
11562 * This function returns IOCB_SUCCESS when success.
11563 * This function is called with no lock held.
11566 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
11567 uint32_t ring_number
,
11568 struct lpfc_iocbq
*piocb
,
11569 struct lpfc_iocbq
*prspiocbq
,
11572 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
11573 long timeleft
, timeout_req
= 0;
11574 int retval
= IOCB_SUCCESS
;
11576 struct lpfc_iocbq
*iocb
;
11578 int txcmplq_cnt
= 0;
11579 struct lpfc_sli_ring
*pring
;
11580 unsigned long iflags
;
11581 bool iocb_completed
= true;
11583 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
11584 pring
= lpfc_sli4_calc_ring(phba
, piocb
);
11586 pring
= &phba
->sli
.sli3_ring
[ring_number
];
11588 * If the caller has provided a response iocbq buffer, then context2
11589 * is NULL or its an error.
11592 if (piocb
->context2
)
11594 piocb
->context2
= prspiocbq
;
11597 piocb
->wait_iocb_cmpl
= piocb
->iocb_cmpl
;
11598 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
11599 piocb
->context_un
.wait_queue
= &done_q
;
11600 piocb
->iocb_flag
&= ~(LPFC_IO_WAKE
| LPFC_IO_WAKE_TMO
);
11602 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
11603 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
11605 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
11606 writel(creg_val
, phba
->HCregaddr
);
11607 readl(phba
->HCregaddr
); /* flush */
11610 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
11611 SLI_IOCB_RET_IOCB
);
11612 if (retval
== IOCB_SUCCESS
) {
11613 timeout_req
= msecs_to_jiffies(timeout
* 1000);
11614 timeleft
= wait_event_timeout(done_q
,
11615 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
11617 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11618 if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
11621 * IOCB timed out. Inform the wake iocb wait
11622 * completion function and set local status
11625 iocb_completed
= false;
11626 piocb
->iocb_flag
|= LPFC_IO_WAKE_TMO
;
11628 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11629 if (iocb_completed
) {
11630 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11631 "0331 IOCB wake signaled\n");
11632 /* Note: we are not indicating if the IOCB has a success
11633 * status or not - that's for the caller to check.
11634 * IOCB_SUCCESS means just that the command was sent and
11635 * completed. Not that it completed successfully.
11637 } else if (timeleft
== 0) {
11638 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11639 "0338 IOCB wait timeout error - no "
11640 "wake response Data x%x\n", timeout
);
11641 retval
= IOCB_TIMEDOUT
;
11643 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11644 "0330 IOCB wake NOT set, "
11646 timeout
, (timeleft
/ jiffies
));
11647 retval
= IOCB_TIMEDOUT
;
11649 } else if (retval
== IOCB_BUSY
) {
11650 if (phba
->cfg_log_verbose
& LOG_SLI
) {
11651 list_for_each_entry(iocb
, &pring
->txq
, list
) {
11654 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
11657 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11658 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
11659 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
11663 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11664 "0332 IOCB wait issue failed, Data x%x\n",
11666 retval
= IOCB_ERROR
;
11669 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
11670 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
11672 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
11673 writel(creg_val
, phba
->HCregaddr
);
11674 readl(phba
->HCregaddr
); /* flush */
11678 piocb
->context2
= NULL
;
11680 piocb
->context_un
.wait_queue
= NULL
;
11681 piocb
->iocb_cmpl
= NULL
;
11686 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
11687 * @phba: Pointer to HBA context object.
11688 * @pmboxq: Pointer to driver mailbox object.
11689 * @timeout: Timeout in number of seconds.
11691 * This function issues the mailbox to firmware and waits for the
11692 * mailbox command to complete. If the mailbox command is not
11693 * completed within timeout seconds, it returns MBX_TIMEOUT.
11694 * The function waits for the mailbox completion using an
11695 * interruptible wait. If the thread is woken up due to a
11696 * signal, MBX_TIMEOUT error is returned to the caller. Caller
11697 * should not free the mailbox resources, if this function returns
11699 * This function will sleep while waiting for mailbox completion.
11700 * So, this function should not be called from any context which
11701 * does not allow sleeping. Due to the same reason, this function
11702 * cannot be called with interrupt disabled.
11703 * This function assumes that the mailbox completion occurs while
11704 * this function sleep. So, this function cannot be called from
11705 * the worker thread which processes mailbox completion.
11706 * This function is called in the context of HBA management
11708 * This function returns MBX_SUCCESS when successful.
11709 * This function is called with no lock held.
11712 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
11715 struct completion mbox_done
;
11717 unsigned long flag
;
11719 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
11720 /* setup wake call as IOCB callback */
11721 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
11723 /* setup context3 field to pass wait_queue pointer to wake function */
11724 init_completion(&mbox_done
);
11725 pmboxq
->context3
= &mbox_done
;
11726 /* now issue the command */
11727 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
11728 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
11729 wait_for_completion_timeout(&mbox_done
,
11730 msecs_to_jiffies(timeout
* 1000));
11732 spin_lock_irqsave(&phba
->hbalock
, flag
);
11733 pmboxq
->context3
= NULL
;
11735 * if LPFC_MBX_WAKE flag is set the mailbox is completed
11736 * else do not free the resources.
11738 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
11739 retval
= MBX_SUCCESS
;
11741 retval
= MBX_TIMEOUT
;
11742 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11744 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
11750 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
11751 * @phba: Pointer to HBA context.
11753 * This function is called to shutdown the driver's mailbox sub-system.
11754 * It first marks the mailbox sub-system is in a block state to prevent
11755 * the asynchronous mailbox command from issued off the pending mailbox
11756 * command queue. If the mailbox command sub-system shutdown is due to
11757 * HBA error conditions such as EEH or ERATT, this routine shall invoke
11758 * the mailbox sub-system flush routine to forcefully bring down the
11759 * mailbox sub-system. Otherwise, if it is due to normal condition (such
11760 * as with offline or HBA function reset), this routine will wait for the
11761 * outstanding mailbox command to complete before invoking the mailbox
11762 * sub-system flush routine to gracefully bring down mailbox sub-system.
11765 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
11767 struct lpfc_sli
*psli
= &phba
->sli
;
11768 unsigned long timeout
;
11770 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
11771 /* delay 100ms for port state */
11773 lpfc_sli_mbox_sys_flush(phba
);
11776 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
11778 spin_lock_irq(&phba
->hbalock
);
11779 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
11781 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
11782 /* Determine how long we might wait for the active mailbox
11783 * command to be gracefully completed by firmware.
11785 if (phba
->sli
.mbox_active
)
11786 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
11787 phba
->sli
.mbox_active
) *
11789 spin_unlock_irq(&phba
->hbalock
);
11791 while (phba
->sli
.mbox_active
) {
11792 /* Check active mailbox complete status every 2ms */
11794 if (time_after(jiffies
, timeout
))
11795 /* Timeout, let the mailbox flush routine to
11796 * forcefully release active mailbox command
11801 spin_unlock_irq(&phba
->hbalock
);
11803 lpfc_sli_mbox_sys_flush(phba
);
11807 * lpfc_sli_eratt_read - read sli-3 error attention events
11808 * @phba: Pointer to HBA context.
11810 * This function is called to read the SLI3 device error attention registers
11811 * for possible error attention events. The caller must hold the hostlock
11812 * with spin_lock_irq().
11814 * This function returns 1 when there is Error Attention in the Host Attention
11815 * Register and returns 0 otherwise.
11818 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
11822 /* Read chip Host Attention (HA) register */
11823 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11826 if (ha_copy
& HA_ERATT
) {
11827 /* Read host status register to retrieve error event */
11828 if (lpfc_sli_read_hs(phba
))
11831 /* Check if there is a deferred error condition is active */
11832 if ((HS_FFER1
& phba
->work_hs
) &&
11833 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11834 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
11835 phba
->hba_flag
|= DEFER_ERATT
;
11836 /* Clear all interrupt enable conditions */
11837 writel(0, phba
->HCregaddr
);
11838 readl(phba
->HCregaddr
);
11841 /* Set the driver HA work bitmap */
11842 phba
->work_ha
|= HA_ERATT
;
11843 /* Indicate polling handles this ERATT */
11844 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11850 /* Set the driver HS work bitmap */
11851 phba
->work_hs
|= UNPLUG_ERR
;
11852 /* Set the driver HA work bitmap */
11853 phba
->work_ha
|= HA_ERATT
;
11854 /* Indicate polling handles this ERATT */
11855 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11860 * lpfc_sli4_eratt_read - read sli-4 error attention events
11861 * @phba: Pointer to HBA context.
11863 * This function is called to read the SLI4 device error attention registers
11864 * for possible error attention events. The caller must hold the hostlock
11865 * with spin_lock_irq().
11867 * This function returns 1 when there is Error Attention in the Host Attention
11868 * Register and returns 0 otherwise.
11871 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
11873 uint32_t uerr_sta_hi
, uerr_sta_lo
;
11874 uint32_t if_type
, portsmphr
;
11875 struct lpfc_register portstat_reg
;
11878 * For now, use the SLI4 device internal unrecoverable error
11879 * registers for error attention. This can be changed later.
11881 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
11883 case LPFC_SLI_INTF_IF_TYPE_0
:
11884 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
11886 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
11888 phba
->work_hs
|= UNPLUG_ERR
;
11889 phba
->work_ha
|= HA_ERATT
;
11890 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11893 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
11894 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
11895 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11896 "1423 HBA Unrecoverable error: "
11897 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
11898 "ue_mask_lo_reg=0x%x, "
11899 "ue_mask_hi_reg=0x%x\n",
11900 uerr_sta_lo
, uerr_sta_hi
,
11901 phba
->sli4_hba
.ue_mask_lo
,
11902 phba
->sli4_hba
.ue_mask_hi
);
11903 phba
->work_status
[0] = uerr_sta_lo
;
11904 phba
->work_status
[1] = uerr_sta_hi
;
11905 phba
->work_ha
|= HA_ERATT
;
11906 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11910 case LPFC_SLI_INTF_IF_TYPE_2
:
11911 case LPFC_SLI_INTF_IF_TYPE_6
:
11912 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
11913 &portstat_reg
.word0
) ||
11914 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
11916 phba
->work_hs
|= UNPLUG_ERR
;
11917 phba
->work_ha
|= HA_ERATT
;
11918 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11921 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
11922 phba
->work_status
[0] =
11923 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
11924 phba
->work_status
[1] =
11925 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
11926 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11927 "2885 Port Status Event: "
11928 "port status reg 0x%x, "
11929 "port smphr reg 0x%x, "
11930 "error 1=0x%x, error 2=0x%x\n",
11931 portstat_reg
.word0
,
11933 phba
->work_status
[0],
11934 phba
->work_status
[1]);
11935 phba
->work_ha
|= HA_ERATT
;
11936 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11940 case LPFC_SLI_INTF_IF_TYPE_1
:
11942 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11943 "2886 HBA Error Attention on unsupported "
11944 "if type %d.", if_type
);
11952 * lpfc_sli_check_eratt - check error attention events
11953 * @phba: Pointer to HBA context.
11955 * This function is called from timer soft interrupt context to check HBA's
11956 * error attention register bit for error attention events.
11958 * This function returns 1 when there is Error Attention in the Host Attention
11959 * Register and returns 0 otherwise.
11962 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
11966 /* If somebody is waiting to handle an eratt, don't process it
11967 * here. The brdkill function will do this.
11969 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11972 /* Check if interrupt handler handles this ERATT */
11973 spin_lock_irq(&phba
->hbalock
);
11974 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
11975 /* Interrupt handler has handled ERATT */
11976 spin_unlock_irq(&phba
->hbalock
);
11981 * If there is deferred error attention, do not check for error
11984 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11985 spin_unlock_irq(&phba
->hbalock
);
11989 /* If PCI channel is offline, don't process it */
11990 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
11991 spin_unlock_irq(&phba
->hbalock
);
11995 switch (phba
->sli_rev
) {
11996 case LPFC_SLI_REV2
:
11997 case LPFC_SLI_REV3
:
11998 /* Read chip Host Attention (HA) register */
11999 ha_copy
= lpfc_sli_eratt_read(phba
);
12001 case LPFC_SLI_REV4
:
12002 /* Read device Uncoverable Error (UERR) registers */
12003 ha_copy
= lpfc_sli4_eratt_read(phba
);
12006 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12007 "0299 Invalid SLI revision (%d)\n",
12012 spin_unlock_irq(&phba
->hbalock
);
12018 * lpfc_intr_state_check - Check device state for interrupt handling
12019 * @phba: Pointer to HBA context.
12021 * This inline routine checks whether a device or its PCI slot is in a state
12022 * that the interrupt should be handled.
12024 * This function returns 0 if the device or the PCI slot is in a state that
12025 * interrupt should be handled, otherwise -EIO.
12028 lpfc_intr_state_check(struct lpfc_hba
*phba
)
12030 /* If the pci channel is offline, ignore all the interrupts */
12031 if (unlikely(pci_channel_offline(phba
->pcidev
)))
12034 /* Update device level interrupt statistics */
12035 phba
->sli
.slistat
.sli_intr
++;
12037 /* Ignore all interrupts during initialization. */
12038 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
12045 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
12046 * @irq: Interrupt number.
12047 * @dev_id: The device context pointer.
12049 * This function is directly called from the PCI layer as an interrupt
12050 * service routine when device with SLI-3 interface spec is enabled with
12051 * MSI-X multi-message interrupt mode and there are slow-path events in
12052 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
12053 * interrupt mode, this function is called as part of the device-level
12054 * interrupt handler. When the PCI slot is in error recovery or the HBA
12055 * is undergoing initialization, the interrupt handler will not process
12056 * the interrupt. The link attention and ELS ring attention events are
12057 * handled by the worker thread. The interrupt handler signals the worker
12058 * thread and returns for these events. This function is called without
12059 * any lock held. It gets the hbalock to access and update SLI data
12062 * This function returns IRQ_HANDLED when interrupt is handled else it
12063 * returns IRQ_NONE.
12066 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
12068 struct lpfc_hba
*phba
;
12069 uint32_t ha_copy
, hc_copy
;
12070 uint32_t work_ha_copy
;
12071 unsigned long status
;
12072 unsigned long iflag
;
12075 MAILBOX_t
*mbox
, *pmbox
;
12076 struct lpfc_vport
*vport
;
12077 struct lpfc_nodelist
*ndlp
;
12078 struct lpfc_dmabuf
*mp
;
12083 * Get the driver's phba structure from the dev_id and
12084 * assume the HBA is not interrupting.
12086 phba
= (struct lpfc_hba
*)dev_id
;
12088 if (unlikely(!phba
))
12092 * Stuff needs to be attented to when this function is invoked as an
12093 * individual interrupt handler in MSI-X multi-message interrupt mode
12095 if (phba
->intr_type
== MSIX
) {
12096 /* Check device state for handling interrupt */
12097 if (lpfc_intr_state_check(phba
))
12099 /* Need to read HA REG for slow-path events */
12100 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12101 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
12103 /* If somebody is waiting to handle an eratt don't process it
12104 * here. The brdkill function will do this.
12106 if (phba
->link_flag
& LS_IGNORE_ERATT
)
12107 ha_copy
&= ~HA_ERATT
;
12108 /* Check the need for handling ERATT in interrupt handler */
12109 if (ha_copy
& HA_ERATT
) {
12110 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
12111 /* ERATT polling has handled ERATT */
12112 ha_copy
&= ~HA_ERATT
;
12114 /* Indicate interrupt handler handles ERATT */
12115 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
12119 * If there is deferred error attention, do not check for any
12122 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12123 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12127 /* Clear up only attention source related to slow-path */
12128 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
12131 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
12132 HC_LAINT_ENA
| HC_ERINT_ENA
),
12134 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
12136 writel(hc_copy
, phba
->HCregaddr
);
12137 readl(phba
->HAregaddr
); /* flush */
12138 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12140 ha_copy
= phba
->ha_copy
;
12142 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
12144 if (work_ha_copy
) {
12145 if (work_ha_copy
& HA_LATT
) {
12146 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
12148 * Turn off Link Attention interrupts
12149 * until CLEAR_LA done
12151 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12152 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
12153 if (lpfc_readl(phba
->HCregaddr
, &control
))
12155 control
&= ~HC_LAINT_ENA
;
12156 writel(control
, phba
->HCregaddr
);
12157 readl(phba
->HCregaddr
); /* flush */
12158 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12161 work_ha_copy
&= ~HA_LATT
;
12164 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
12166 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
12167 * the only slow ring.
12169 status
= (work_ha_copy
&
12170 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
12171 status
>>= (4*LPFC_ELS_RING
);
12172 if (status
& HA_RXMASK
) {
12173 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12174 if (lpfc_readl(phba
->HCregaddr
, &control
))
12177 lpfc_debugfs_slow_ring_trc(phba
,
12178 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
12180 (uint32_t)phba
->sli
.slistat
.sli_intr
);
12182 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
12183 lpfc_debugfs_slow_ring_trc(phba
,
12184 "ISR Disable ring:"
12185 "pwork:x%x hawork:x%x wait:x%x",
12186 phba
->work_ha
, work_ha_copy
,
12187 (uint32_t)((unsigned long)
12188 &phba
->work_waitq
));
12191 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
12192 writel(control
, phba
->HCregaddr
);
12193 readl(phba
->HCregaddr
); /* flush */
12196 lpfc_debugfs_slow_ring_trc(phba
,
12197 "ISR slow ring: pwork:"
12198 "x%x hawork:x%x wait:x%x",
12199 phba
->work_ha
, work_ha_copy
,
12200 (uint32_t)((unsigned long)
12201 &phba
->work_waitq
));
12203 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12206 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12207 if (work_ha_copy
& HA_ERATT
) {
12208 if (lpfc_sli_read_hs(phba
))
12211 * Check if there is a deferred error condition
12214 if ((HS_FFER1
& phba
->work_hs
) &&
12215 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
12216 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
12218 phba
->hba_flag
|= DEFER_ERATT
;
12219 /* Clear all interrupt enable conditions */
12220 writel(0, phba
->HCregaddr
);
12221 readl(phba
->HCregaddr
);
12225 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
12226 pmb
= phba
->sli
.mbox_active
;
12227 pmbox
= &pmb
->u
.mb
;
12229 vport
= pmb
->vport
;
12231 /* First check out the status word */
12232 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
12233 if (pmbox
->mbxOwner
!= OWN_HOST
) {
12234 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12236 * Stray Mailbox Interrupt, mbxCommand <cmd>
12237 * mbxStatus <status>
12239 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12241 "(%d):0304 Stray Mailbox "
12242 "Interrupt mbxCommand x%x "
12244 (vport
? vport
->vpi
: 0),
12247 /* clear mailbox attention bit */
12248 work_ha_copy
&= ~HA_MBATT
;
12250 phba
->sli
.mbox_active
= NULL
;
12251 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12252 phba
->last_completion_time
= jiffies
;
12253 del_timer(&phba
->sli
.mbox_tmo
);
12254 if (pmb
->mbox_cmpl
) {
12255 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
12257 if (pmb
->out_ext_byte_len
&&
12259 lpfc_sli_pcimem_bcopy(
12262 pmb
->out_ext_byte_len
);
12264 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
12265 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
12267 lpfc_debugfs_disc_trc(vport
,
12268 LPFC_DISC_TRC_MBOX_VPORT
,
12269 "MBOX dflt rpi: : "
12270 "status:x%x rpi:x%x",
12271 (uint32_t)pmbox
->mbxStatus
,
12272 pmbox
->un
.varWords
[0], 0);
12274 if (!pmbox
->mbxStatus
) {
12275 mp
= (struct lpfc_dmabuf
*)
12277 ndlp
= (struct lpfc_nodelist
*)
12280 /* Reg_LOGIN of dflt RPI was
12281 * successful. new lets get
12282 * rid of the RPI using the
12283 * same mbox buffer.
12285 lpfc_unreg_login(phba
,
12287 pmbox
->un
.varWords
[0],
12290 lpfc_mbx_cmpl_dflt_rpi
;
12291 pmb
->context1
= mp
;
12292 pmb
->context2
= ndlp
;
12293 pmb
->vport
= vport
;
12294 rc
= lpfc_sli_issue_mbox(phba
,
12297 if (rc
!= MBX_BUSY
)
12298 lpfc_printf_log(phba
,
12300 LOG_MBOX
| LOG_SLI
,
12301 "0350 rc should have"
12302 "been MBX_BUSY\n");
12303 if (rc
!= MBX_NOT_FINISHED
)
12304 goto send_current_mbox
;
12308 &phba
->pport
->work_port_lock
,
12310 phba
->pport
->work_port_events
&=
12312 spin_unlock_irqrestore(
12313 &phba
->pport
->work_port_lock
,
12315 lpfc_mbox_cmpl_put(phba
, pmb
);
12318 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12320 if ((work_ha_copy
& HA_MBATT
) &&
12321 (phba
->sli
.mbox_active
== NULL
)) {
12323 /* Process next mailbox command if there is one */
12325 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
12327 } while (rc
== MBX_NOT_FINISHED
);
12328 if (rc
!= MBX_SUCCESS
)
12329 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12330 LOG_SLI
, "0349 rc should be "
12334 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12335 phba
->work_ha
|= work_ha_copy
;
12336 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12337 lpfc_worker_wake_up(phba
);
12339 return IRQ_HANDLED
;
12341 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12342 return IRQ_HANDLED
;
12344 } /* lpfc_sli_sp_intr_handler */
12347 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
12348 * @irq: Interrupt number.
12349 * @dev_id: The device context pointer.
12351 * This function is directly called from the PCI layer as an interrupt
12352 * service routine when device with SLI-3 interface spec is enabled with
12353 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12354 * ring event in the HBA. However, when the device is enabled with either
12355 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12356 * device-level interrupt handler. When the PCI slot is in error recovery
12357 * or the HBA is undergoing initialization, the interrupt handler will not
12358 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12359 * the intrrupt context. This function is called without any lock held.
12360 * It gets the hbalock to access and update SLI data structures.
12362 * This function returns IRQ_HANDLED when interrupt is handled else it
12363 * returns IRQ_NONE.
12366 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
12368 struct lpfc_hba
*phba
;
12370 unsigned long status
;
12371 unsigned long iflag
;
12372 struct lpfc_sli_ring
*pring
;
12374 /* Get the driver's phba structure from the dev_id and
12375 * assume the HBA is not interrupting.
12377 phba
= (struct lpfc_hba
*) dev_id
;
12379 if (unlikely(!phba
))
12383 * Stuff needs to be attented to when this function is invoked as an
12384 * individual interrupt handler in MSI-X multi-message interrupt mode
12386 if (phba
->intr_type
== MSIX
) {
12387 /* Check device state for handling interrupt */
12388 if (lpfc_intr_state_check(phba
))
12390 /* Need to read HA REG for FCP ring and other ring events */
12391 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
12392 return IRQ_HANDLED
;
12393 /* Clear up only attention source related to fast-path */
12394 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12396 * If there is deferred error attention, do not check for
12399 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12400 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12403 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
12405 readl(phba
->HAregaddr
); /* flush */
12406 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12408 ha_copy
= phba
->ha_copy
;
12411 * Process all events on FCP ring. Take the optimized path for FCP IO.
12413 ha_copy
&= ~(phba
->work_ha_mask
);
12415 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
12416 status
>>= (4*LPFC_FCP_RING
);
12417 pring
= &phba
->sli
.sli3_ring
[LPFC_FCP_RING
];
12418 if (status
& HA_RXMASK
)
12419 lpfc_sli_handle_fast_ring_event(phba
, pring
, status
);
12421 if (phba
->cfg_multi_ring_support
== 2) {
12423 * Process all events on extra ring. Take the optimized path
12424 * for extra ring IO.
12426 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
12427 status
>>= (4*LPFC_EXTRA_RING
);
12428 if (status
& HA_RXMASK
) {
12429 lpfc_sli_handle_fast_ring_event(phba
,
12430 &phba
->sli
.sli3_ring
[LPFC_EXTRA_RING
],
12434 return IRQ_HANDLED
;
12435 } /* lpfc_sli_fp_intr_handler */
12438 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
12439 * @irq: Interrupt number.
12440 * @dev_id: The device context pointer.
12442 * This function is the HBA device-level interrupt handler to device with
12443 * SLI-3 interface spec, called from the PCI layer when either MSI or
12444 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
12445 * requires driver attention. This function invokes the slow-path interrupt
12446 * attention handling function and fast-path interrupt attention handling
12447 * function in turn to process the relevant HBA attention events. This
12448 * function is called without any lock held. It gets the hbalock to access
12449 * and update SLI data structures.
12451 * This function returns IRQ_HANDLED when interrupt is handled, else it
12452 * returns IRQ_NONE.
12455 lpfc_sli_intr_handler(int irq
, void *dev_id
)
12457 struct lpfc_hba
*phba
;
12458 irqreturn_t sp_irq_rc
, fp_irq_rc
;
12459 unsigned long status1
, status2
;
12463 * Get the driver's phba structure from the dev_id and
12464 * assume the HBA is not interrupting.
12466 phba
= (struct lpfc_hba
*) dev_id
;
12468 if (unlikely(!phba
))
12471 /* Check device state for handling interrupt */
12472 if (lpfc_intr_state_check(phba
))
12475 spin_lock(&phba
->hbalock
);
12476 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
12477 spin_unlock(&phba
->hbalock
);
12478 return IRQ_HANDLED
;
12481 if (unlikely(!phba
->ha_copy
)) {
12482 spin_unlock(&phba
->hbalock
);
12484 } else if (phba
->ha_copy
& HA_ERATT
) {
12485 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
12486 /* ERATT polling has handled ERATT */
12487 phba
->ha_copy
&= ~HA_ERATT
;
12489 /* Indicate interrupt handler handles ERATT */
12490 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
12494 * If there is deferred error attention, do not check for any interrupt.
12496 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12497 spin_unlock(&phba
->hbalock
);
12501 /* Clear attention sources except link and error attentions */
12502 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
12503 spin_unlock(&phba
->hbalock
);
12504 return IRQ_HANDLED
;
12506 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
12507 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
12509 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
12510 writel(hc_copy
, phba
->HCregaddr
);
12511 readl(phba
->HAregaddr
); /* flush */
12512 spin_unlock(&phba
->hbalock
);
12515 * Invokes slow-path host attention interrupt handling as appropriate.
12518 /* status of events with mailbox and link attention */
12519 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
12521 /* status of events with ELS ring */
12522 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
12523 status2
>>= (4*LPFC_ELS_RING
);
12525 if (status1
|| (status2
& HA_RXMASK
))
12526 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
12528 sp_irq_rc
= IRQ_NONE
;
12531 * Invoke fast-path host attention interrupt handling as appropriate.
12534 /* status of events with FCP ring */
12535 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
12536 status1
>>= (4*LPFC_FCP_RING
);
12538 /* status of events with extra ring */
12539 if (phba
->cfg_multi_ring_support
== 2) {
12540 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
12541 status2
>>= (4*LPFC_EXTRA_RING
);
12545 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
12546 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
12548 fp_irq_rc
= IRQ_NONE
;
12550 /* Return device-level interrupt handling status */
12551 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
12552 } /* lpfc_sli_intr_handler */
12555 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
12556 * @phba: pointer to lpfc hba data structure.
12558 * This routine is invoked by the worker thread to process all the pending
12559 * SLI4 FCP abort XRI events.
12561 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
12563 struct lpfc_cq_event
*cq_event
;
12565 /* First, declare the fcp xri abort event has been handled */
12566 spin_lock_irq(&phba
->hbalock
);
12567 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
12568 spin_unlock_irq(&phba
->hbalock
);
12569 /* Now, handle all the fcp xri abort events */
12570 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
12571 /* Get the first event from the head of the event queue */
12572 spin_lock_irq(&phba
->hbalock
);
12573 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
12574 cq_event
, struct lpfc_cq_event
, list
);
12575 spin_unlock_irq(&phba
->hbalock
);
12576 /* Notify aborted XRI for FCP work queue */
12577 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
12578 /* Free the event processed back to the free pool */
12579 lpfc_sli4_cq_event_release(phba
, cq_event
);
12584 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12585 * @phba: pointer to lpfc hba data structure.
12587 * This routine is invoked by the worker thread to process all the pending
12588 * SLI4 els abort xri events.
12590 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
12592 struct lpfc_cq_event
*cq_event
;
12594 /* First, declare the els xri abort event has been handled */
12595 spin_lock_irq(&phba
->hbalock
);
12596 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
12597 spin_unlock_irq(&phba
->hbalock
);
12598 /* Now, handle all the els xri abort events */
12599 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
12600 /* Get the first event from the head of the event queue */
12601 spin_lock_irq(&phba
->hbalock
);
12602 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
12603 cq_event
, struct lpfc_cq_event
, list
);
12604 spin_unlock_irq(&phba
->hbalock
);
12605 /* Notify aborted XRI for ELS work queue */
12606 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
12607 /* Free the event processed back to the free pool */
12608 lpfc_sli4_cq_event_release(phba
, cq_event
);
12613 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
12614 * @phba: pointer to lpfc hba data structure
12615 * @pIocbIn: pointer to the rspiocbq
12616 * @pIocbOut: pointer to the cmdiocbq
12617 * @wcqe: pointer to the complete wcqe
12619 * This routine transfers the fields of a command iocbq to a response iocbq
12620 * by copying all the IOCB fields from command iocbq and transferring the
12621 * completion status information from the complete wcqe.
12624 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
12625 struct lpfc_iocbq
*pIocbIn
,
12626 struct lpfc_iocbq
*pIocbOut
,
12627 struct lpfc_wcqe_complete
*wcqe
)
12630 unsigned long iflags
;
12631 uint32_t status
, max_response
;
12632 struct lpfc_dmabuf
*dmabuf
;
12633 struct ulp_bde64
*bpl
, bde
;
12634 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
12636 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
12637 sizeof(struct lpfc_iocbq
) - offset
);
12638 /* Map WCQE parameters into irspiocb parameters */
12639 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
12640 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
12641 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
12642 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
12643 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
12644 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
12645 wcqe
->total_data_placed
;
12647 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
12649 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
12650 switch (pIocbOut
->iocb
.ulpCommand
) {
12651 case CMD_ELS_REQUEST64_CR
:
12652 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
12653 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
12654 bde
.tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
12655 max_response
= bde
.tus
.f
.bdeSize
;
12657 case CMD_GEN_REQUEST64_CR
:
12659 if (!pIocbOut
->context3
)
12661 numBdes
= pIocbOut
->iocb
.un
.genreq64
.bdl
.bdeSize
/
12662 sizeof(struct ulp_bde64
);
12663 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
12664 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
12665 for (i
= 0; i
< numBdes
; i
++) {
12666 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
12667 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
12668 max_response
+= bde
.tus
.f
.bdeSize
;
12672 max_response
= wcqe
->total_data_placed
;
12675 if (max_response
< wcqe
->total_data_placed
)
12676 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= max_response
;
12678 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
=
12679 wcqe
->total_data_placed
;
12682 /* Convert BG errors for completion status */
12683 if (status
== CQE_STATUS_DI_ERROR
) {
12684 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
12686 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
12687 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
12689 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
12691 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
12692 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
12693 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12694 BGS_GUARD_ERR_MASK
;
12695 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
12696 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12697 BGS_APPTAG_ERR_MASK
;
12698 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
12699 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12700 BGS_REFTAG_ERR_MASK
;
12702 /* Check to see if there was any good data before the error */
12703 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
12704 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12705 BGS_HI_WATER_MARK_PRESENT_MASK
;
12706 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
12707 wcqe
->total_data_placed
;
12711 * Set ALL the error bits to indicate we don't know what
12712 * type of error it is.
12714 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
12715 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12716 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
12717 BGS_GUARD_ERR_MASK
);
12720 /* Pick up HBA exchange busy condition */
12721 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
12722 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12723 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
12724 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12729 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
12730 * @phba: Pointer to HBA context object.
12731 * @wcqe: Pointer to work-queue completion queue entry.
12733 * This routine handles an ELS work-queue completion event and construct
12734 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
12735 * discovery engine to handle.
12737 * Return: Pointer to the receive IOCBQ, NULL otherwise.
12739 static struct lpfc_iocbq
*
12740 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
12741 struct lpfc_iocbq
*irspiocbq
)
12743 struct lpfc_sli_ring
*pring
;
12744 struct lpfc_iocbq
*cmdiocbq
;
12745 struct lpfc_wcqe_complete
*wcqe
;
12746 unsigned long iflags
;
12748 pring
= lpfc_phba_elsring(phba
);
12749 if (unlikely(!pring
))
12752 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
12753 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
12754 pring
->stats
.iocb_event
++;
12755 /* Look up the ELS command IOCB and create pseudo response IOCB */
12756 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
12757 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12758 if (unlikely(!cmdiocbq
)) {
12759 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12760 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12761 "0386 ELS complete with no corresponding "
12762 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
12763 wcqe
->word0
, wcqe
->total_data_placed
,
12764 wcqe
->parameter
, wcqe
->word3
);
12765 lpfc_sli_release_iocbq(phba
, irspiocbq
);
12769 /* Put the iocb back on the txcmplq */
12770 lpfc_sli_ringtxcmpl_put(phba
, pring
, cmdiocbq
);
12771 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12773 /* Fake the irspiocbq and copy necessary response information */
12774 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
12779 inline struct lpfc_cq_event
*
12780 lpfc_cq_event_setup(struct lpfc_hba
*phba
, void *entry
, int size
)
12782 struct lpfc_cq_event
*cq_event
;
12784 /* Allocate a new internal CQ_EVENT entry */
12785 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
12787 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12788 "0602 Failed to alloc CQ_EVENT entry\n");
12792 /* Move the CQE into the event */
12793 memcpy(&cq_event
->cqe
, entry
, size
);
12798 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
12799 * @phba: Pointer to HBA context object.
12800 * @cqe: Pointer to mailbox completion queue entry.
12802 * This routine process a mailbox completion queue entry with asynchrous
12805 * Return: true if work posted to worker thread, otherwise false.
12808 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
12810 struct lpfc_cq_event
*cq_event
;
12811 unsigned long iflags
;
12813 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
12814 "0392 Async Event: word0:x%x, word1:x%x, "
12815 "word2:x%x, word3:x%x\n", mcqe
->word0
,
12816 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
12818 cq_event
= lpfc_cq_event_setup(phba
, mcqe
, sizeof(struct lpfc_mcqe
));
12821 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12822 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
12823 /* Set the async event flag */
12824 phba
->hba_flag
|= ASYNC_EVENT
;
12825 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12831 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
12832 * @phba: Pointer to HBA context object.
12833 * @cqe: Pointer to mailbox completion queue entry.
12835 * This routine process a mailbox completion queue entry with mailbox
12836 * completion event.
12838 * Return: true if work posted to worker thread, otherwise false.
12841 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
12843 uint32_t mcqe_status
;
12844 MAILBOX_t
*mbox
, *pmbox
;
12845 struct lpfc_mqe
*mqe
;
12846 struct lpfc_vport
*vport
;
12847 struct lpfc_nodelist
*ndlp
;
12848 struct lpfc_dmabuf
*mp
;
12849 unsigned long iflags
;
12851 bool workposted
= false;
12854 /* If not a mailbox complete MCQE, out by checking mailbox consume */
12855 if (!bf_get(lpfc_trailer_completed
, mcqe
))
12856 goto out_no_mqe_complete
;
12858 /* Get the reference to the active mbox command */
12859 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12860 pmb
= phba
->sli
.mbox_active
;
12861 if (unlikely(!pmb
)) {
12862 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
12863 "1832 No pending MBOX command to handle\n");
12864 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12865 goto out_no_mqe_complete
;
12867 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12869 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
12871 vport
= pmb
->vport
;
12873 /* Reset heartbeat timer */
12874 phba
->last_completion_time
= jiffies
;
12875 del_timer(&phba
->sli
.mbox_tmo
);
12877 /* Move mbox data to caller's mailbox region, do endian swapping */
12878 if (pmb
->mbox_cmpl
&& mbox
)
12879 lpfc_sli4_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
12882 * For mcqe errors, conditionally move a modified error code to
12883 * the mbox so that the error will not be missed.
12885 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
12886 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
12887 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
12888 bf_set(lpfc_mqe_status
, mqe
,
12889 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
12891 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
12892 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
12893 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
12894 "MBOX dflt rpi: status:x%x rpi:x%x",
12896 pmbox
->un
.varWords
[0], 0);
12897 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
12898 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
12899 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
12900 /* Reg_LOGIN of dflt RPI was successful. Now lets get
12901 * RID of the PPI using the same mbox buffer.
12903 lpfc_unreg_login(phba
, vport
->vpi
,
12904 pmbox
->un
.varWords
[0], pmb
);
12905 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
12906 pmb
->context1
= mp
;
12907 pmb
->context2
= ndlp
;
12908 pmb
->vport
= vport
;
12909 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
12910 if (rc
!= MBX_BUSY
)
12911 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12912 LOG_SLI
, "0385 rc should "
12913 "have been MBX_BUSY\n");
12914 if (rc
!= MBX_NOT_FINISHED
)
12915 goto send_current_mbox
;
12918 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
12919 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
12920 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
12922 /* There is mailbox completion work to do */
12923 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12924 __lpfc_mbox_cmpl_put(phba
, pmb
);
12925 phba
->work_ha
|= HA_MBATT
;
12926 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12930 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12931 /* Release the mailbox command posting token */
12932 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
12933 /* Setting active mailbox pointer need to be in sync to flag clear */
12934 phba
->sli
.mbox_active
= NULL
;
12935 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12936 /* Wake up worker thread to post the next pending mailbox command */
12937 lpfc_worker_wake_up(phba
);
12938 out_no_mqe_complete
:
12939 if (bf_get(lpfc_trailer_consumed
, mcqe
))
12940 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
12945 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
12946 * @phba: Pointer to HBA context object.
12947 * @cqe: Pointer to mailbox completion queue entry.
12949 * This routine process a mailbox completion queue entry, it invokes the
12950 * proper mailbox complete handling or asynchrous event handling routine
12951 * according to the MCQE's async bit.
12953 * Return: true if work posted to worker thread, otherwise false.
12956 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
12958 struct lpfc_mcqe mcqe
;
12961 /* Copy the mailbox MCQE and convert endian order as needed */
12962 lpfc_sli4_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
12964 /* Invoke the proper event handling routine */
12965 if (!bf_get(lpfc_trailer_async
, &mcqe
))
12966 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
12968 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
12973 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
12974 * @phba: Pointer to HBA context object.
12975 * @cq: Pointer to associated CQ
12976 * @wcqe: Pointer to work-queue completion queue entry.
12978 * This routine handles an ELS work-queue completion event.
12980 * Return: true if work posted to worker thread, otherwise false.
12983 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12984 struct lpfc_wcqe_complete
*wcqe
)
12986 struct lpfc_iocbq
*irspiocbq
;
12987 unsigned long iflags
;
12988 struct lpfc_sli_ring
*pring
= cq
->pring
;
12990 int txcmplq_cnt
= 0;
12991 int fcp_txcmplq_cnt
= 0;
12993 /* Check for response status */
12994 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
12995 /* Log the error status */
12996 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
12997 "0357 ELS CQE error: status=x%x: "
12998 "CQE: %08x %08x %08x %08x\n",
12999 bf_get(lpfc_wcqe_c_status
, wcqe
),
13000 wcqe
->word0
, wcqe
->total_data_placed
,
13001 wcqe
->parameter
, wcqe
->word3
);
13004 /* Get an irspiocbq for later ELS response processing use */
13005 irspiocbq
= lpfc_sli_get_iocbq(phba
);
13007 if (!list_empty(&pring
->txq
))
13009 if (!list_empty(&pring
->txcmplq
))
13011 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13012 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
13013 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
13014 txq_cnt
, phba
->iocb_cnt
,
13020 /* Save off the slow-path queue event for work thread to process */
13021 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
13022 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13023 list_add_tail(&irspiocbq
->cq_event
.list
,
13024 &phba
->sli4_hba
.sp_queue_event
);
13025 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
13026 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13032 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
13033 * @phba: Pointer to HBA context object.
13034 * @wcqe: Pointer to work-queue completion queue entry.
13036 * This routine handles slow-path WQ entry consumed event by invoking the
13037 * proper WQ release routine to the slow-path WQ.
13040 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
13041 struct lpfc_wcqe_release
*wcqe
)
13043 /* sanity check on queue memory */
13044 if (unlikely(!phba
->sli4_hba
.els_wq
))
13046 /* Check for the slow-path ELS work queue */
13047 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
13048 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
13049 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
13051 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13052 "2579 Slow-path wqe consume event carries "
13053 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
13054 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
13055 phba
->sli4_hba
.els_wq
->queue_id
);
13059 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
13060 * @phba: Pointer to HBA context object.
13061 * @cq: Pointer to a WQ completion queue.
13062 * @wcqe: Pointer to work-queue completion queue entry.
13064 * This routine handles an XRI abort event.
13066 * Return: true if work posted to worker thread, otherwise false.
13069 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
13070 struct lpfc_queue
*cq
,
13071 struct sli4_wcqe_xri_aborted
*wcqe
)
13073 bool workposted
= false;
13074 struct lpfc_cq_event
*cq_event
;
13075 unsigned long iflags
;
13077 switch (cq
->subtype
) {
13079 cq_event
= lpfc_cq_event_setup(
13080 phba
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
13083 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13084 list_add_tail(&cq_event
->list
,
13085 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
13086 /* Set the fcp xri abort event flag */
13087 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
13088 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13091 case LPFC_NVME_LS
: /* NVME LS uses ELS resources */
13093 cq_event
= lpfc_cq_event_setup(
13094 phba
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
13097 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13098 list_add_tail(&cq_event
->list
,
13099 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
13100 /* Set the els xri abort event flag */
13101 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
13102 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13106 /* Notify aborted XRI for NVME work queue */
13107 if (phba
->nvmet_support
)
13108 lpfc_sli4_nvmet_xri_aborted(phba
, wcqe
);
13110 lpfc_sli4_nvme_xri_aborted(phba
, wcqe
);
13112 workposted
= false;
13115 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13116 "0603 Invalid CQ subtype %d: "
13117 "%08x %08x %08x %08x\n",
13118 cq
->subtype
, wcqe
->word0
, wcqe
->parameter
,
13119 wcqe
->word2
, wcqe
->word3
);
13120 workposted
= false;
13127 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
13128 * @phba: Pointer to HBA context object.
13129 * @rcqe: Pointer to receive-queue completion queue entry.
13131 * This routine process a receive-queue completion queue entry.
13133 * Return: true if work posted to worker thread, otherwise false.
13136 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
13138 bool workposted
= false;
13139 struct fc_frame_header
*fc_hdr
;
13140 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
13141 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
13142 struct lpfc_nvmet_tgtport
*tgtp
;
13143 struct hbq_dmabuf
*dma_buf
;
13144 uint32_t status
, rq_id
;
13145 unsigned long iflags
;
13147 /* sanity check on queue memory */
13148 if (unlikely(!hrq
) || unlikely(!drq
))
13151 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
13152 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
13154 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
13155 if (rq_id
!= hrq
->queue_id
)
13158 status
= bf_get(lpfc_rcqe_status
, rcqe
);
13160 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
13161 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13162 "2537 Receive Frame Truncated!!\n");
13163 case FC_STATUS_RQ_SUCCESS
:
13164 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13165 lpfc_sli4_rq_release(hrq
, drq
);
13166 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
13168 hrq
->RQ_no_buf_found
++;
13169 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13173 hrq
->RQ_buf_posted
--;
13174 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
13176 /* If a NVME LS event (type 0x28), treat it as Fast path */
13177 fc_hdr
= (struct fc_frame_header
*)dma_buf
->hbuf
.virt
;
13179 /* save off the frame for the word thread to process */
13180 list_add_tail(&dma_buf
->cq_event
.list
,
13181 &phba
->sli4_hba
.sp_queue_event
);
13182 /* Frame received */
13183 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
13184 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13187 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
13188 if (phba
->nvmet_support
) {
13189 tgtp
= phba
->targetport
->private;
13190 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_NVME
,
13191 "6402 RQE Error x%x, posted %d err_cnt "
13193 status
, hrq
->RQ_buf_posted
,
13194 hrq
->RQ_no_posted_buf
,
13195 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
13196 atomic_read(&tgtp
->rcv_fcp_cmd_out
),
13197 atomic_read(&tgtp
->xmt_fcp_release
));
13201 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
13202 hrq
->RQ_no_posted_buf
++;
13203 /* Post more buffers if possible */
13204 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13205 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
13206 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13215 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
13216 * @phba: Pointer to HBA context object.
13217 * @cq: Pointer to the completion queue.
13218 * @wcqe: Pointer to a completion queue entry.
13220 * This routine process a slow-path work-queue or receive queue completion queue
13223 * Return: true if work posted to worker thread, otherwise false.
13226 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13227 struct lpfc_cqe
*cqe
)
13229 struct lpfc_cqe cqevt
;
13230 bool workposted
= false;
13232 /* Copy the work queue CQE and convert endian order if needed */
13233 lpfc_sli4_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
13235 /* Check and process for different type of WCQE and dispatch */
13236 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
13237 case CQE_CODE_COMPL_WQE
:
13238 /* Process the WQ/RQ complete event */
13239 phba
->last_completion_time
= jiffies
;
13240 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
13241 (struct lpfc_wcqe_complete
*)&cqevt
);
13243 case CQE_CODE_RELEASE_WQE
:
13244 /* Process the WQ release event */
13245 lpfc_sli4_sp_handle_rel_wcqe(phba
,
13246 (struct lpfc_wcqe_release
*)&cqevt
);
13248 case CQE_CODE_XRI_ABORTED
:
13249 /* Process the WQ XRI abort event */
13250 phba
->last_completion_time
= jiffies
;
13251 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
13252 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
13254 case CQE_CODE_RECEIVE
:
13255 case CQE_CODE_RECEIVE_V1
:
13256 /* Process the RQ event */
13257 phba
->last_completion_time
= jiffies
;
13258 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
13259 (struct lpfc_rcqe
*)&cqevt
);
13262 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13263 "0388 Not a valid WCQE code: x%x\n",
13264 bf_get(lpfc_cqe_code
, &cqevt
));
13271 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
13272 * @phba: Pointer to HBA context object.
13273 * @eqe: Pointer to fast-path event queue entry.
13275 * This routine process a event queue entry from the slow-path event queue.
13276 * It will check the MajorCode and MinorCode to determine this is for a
13277 * completion event on a completion queue, if not, an error shall be logged
13278 * and just return. Otherwise, it will get to the corresponding completion
13279 * queue and process all the entries on that completion queue, rearm the
13280 * completion queue, and then return.
13284 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
13285 struct lpfc_queue
*speq
)
13287 struct lpfc_queue
*cq
= NULL
, *childq
;
13290 /* Get the reference to the corresponding CQ */
13291 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13293 list_for_each_entry(childq
, &speq
->child_list
, list
) {
13294 if (childq
->queue_id
== cqid
) {
13299 if (unlikely(!cq
)) {
13300 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
13301 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13302 "0365 Slow-path CQ identifier "
13303 "(%d) does not exist\n", cqid
);
13307 /* Save EQ associated with this CQ */
13308 cq
->assoc_qp
= speq
;
13310 if (!queue_work(phba
->wq
, &cq
->spwork
))
13311 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13312 "0390 Cannot schedule soft IRQ "
13313 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13314 cqid
, cq
->queue_id
, smp_processor_id());
13318 * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
13319 * @phba: Pointer to HBA context object.
13321 * This routine process a event queue entry from the slow-path event queue.
13322 * It will check the MajorCode and MinorCode to determine this is for a
13323 * completion event on a completion queue, if not, an error shall be logged
13324 * and just return. Otherwise, it will get to the corresponding completion
13325 * queue and process all the entries on that completion queue, rearm the
13326 * completion queue, and then return.
13330 lpfc_sli4_sp_process_cq(struct work_struct
*work
)
13332 struct lpfc_queue
*cq
=
13333 container_of(work
, struct lpfc_queue
, spwork
);
13334 struct lpfc_hba
*phba
= cq
->phba
;
13335 struct lpfc_cqe
*cqe
;
13336 bool workposted
= false;
13339 /* Process all the entries to the CQ */
13340 switch (cq
->type
) {
13342 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13343 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
13344 if (!(++ccount
% cq
->entry_repost
))
13350 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13351 if (cq
->subtype
== LPFC_FCP
||
13352 cq
->subtype
== LPFC_NVME
) {
13353 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13354 if (phba
->ktime_on
)
13355 cq
->isr_timestamp
= ktime_get_ns();
13357 cq
->isr_timestamp
= 0;
13359 workposted
|= lpfc_sli4_fp_handle_cqe(phba
, cq
,
13362 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
13365 if (!(++ccount
% cq
->entry_repost
))
13369 /* Track the max number of CQEs processed in 1 EQ */
13370 if (ccount
> cq
->CQ_max_cqe
)
13371 cq
->CQ_max_cqe
= ccount
;
13374 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13375 "0370 Invalid completion queue type (%d)\n",
13380 /* Catch the no cq entry condition, log an error */
13381 if (unlikely(ccount
== 0))
13382 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13383 "0371 No entry from the CQ: identifier "
13384 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
13386 /* In any case, flash and re-arm the RCQ */
13387 phba
->sli4_hba
.sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
13389 /* wake up worker thread if there are works to be done */
13391 lpfc_worker_wake_up(phba
);
13395 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
13396 * @phba: Pointer to HBA context object.
13397 * @cq: Pointer to associated CQ
13398 * @wcqe: Pointer to work-queue completion queue entry.
13400 * This routine process a fast-path work queue completion entry from fast-path
13401 * event queue for FCP command response completion.
13404 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13405 struct lpfc_wcqe_complete
*wcqe
)
13407 struct lpfc_sli_ring
*pring
= cq
->pring
;
13408 struct lpfc_iocbq
*cmdiocbq
;
13409 struct lpfc_iocbq irspiocbq
;
13410 unsigned long iflags
;
13412 /* Check for response status */
13413 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
13414 /* If resource errors reported from HBA, reduce queue
13415 * depth of the SCSI device.
13417 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
13418 IOSTAT_LOCAL_REJECT
)) &&
13419 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
13420 IOERR_NO_RESOURCES
))
13421 phba
->lpfc_rampdown_queue_depth(phba
);
13423 /* Log the error status */
13424 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
13425 "0373 FCP CQE error: status=x%x: "
13426 "CQE: %08x %08x %08x %08x\n",
13427 bf_get(lpfc_wcqe_c_status
, wcqe
),
13428 wcqe
->word0
, wcqe
->total_data_placed
,
13429 wcqe
->parameter
, wcqe
->word3
);
13432 /* Look up the FCP command IOCB and create pseudo response IOCB */
13433 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
13434 pring
->stats
.iocb_event
++;
13435 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
13436 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13437 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
13438 if (unlikely(!cmdiocbq
)) {
13439 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13440 "0374 FCP complete with no corresponding "
13441 "cmdiocb: iotag (%d)\n",
13442 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13445 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13446 cmdiocbq
->isr_timestamp
= cq
->isr_timestamp
;
13448 if (cmdiocbq
->iocb_cmpl
== NULL
) {
13449 if (cmdiocbq
->wqe_cmpl
) {
13450 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
13451 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13452 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
13453 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13456 /* Pass the cmd_iocb and the wcqe to the upper layer */
13457 (cmdiocbq
->wqe_cmpl
)(phba
, cmdiocbq
, wcqe
);
13460 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13461 "0375 FCP cmdiocb not callback function "
13463 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13467 /* Fake the irspiocb and copy necessary response information */
13468 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
13470 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
13471 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13472 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
13473 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13476 /* Pass the cmd_iocb and the rsp state to the upper layer */
13477 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
13481 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
13482 * @phba: Pointer to HBA context object.
13483 * @cq: Pointer to completion queue.
13484 * @wcqe: Pointer to work-queue completion queue entry.
13486 * This routine handles an fast-path WQ entry consumed event by invoking the
13487 * proper WQ release routine to the slow-path WQ.
13490 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13491 struct lpfc_wcqe_release
*wcqe
)
13493 struct lpfc_queue
*childwq
;
13494 bool wqid_matched
= false;
13497 /* Check for fast-path FCP work queue release */
13498 hba_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
13499 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
13500 if (childwq
->queue_id
== hba_wqid
) {
13501 lpfc_sli4_wq_release(childwq
,
13502 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
13503 if (childwq
->q_flag
& HBA_NVMET_WQFULL
)
13504 lpfc_nvmet_wqfull_process(phba
, childwq
);
13505 wqid_matched
= true;
13509 /* Report warning log message if no match found */
13510 if (wqid_matched
!= true)
13511 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13512 "2580 Fast-path wqe consume event carries "
13513 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid
);
13517 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
13518 * @phba: Pointer to HBA context object.
13519 * @rcqe: Pointer to receive-queue completion queue entry.
13521 * This routine process a receive-queue completion queue entry.
13523 * Return: true if work posted to worker thread, otherwise false.
13526 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13527 struct lpfc_rcqe
*rcqe
)
13529 bool workposted
= false;
13530 struct lpfc_queue
*hrq
;
13531 struct lpfc_queue
*drq
;
13532 struct rqb_dmabuf
*dma_buf
;
13533 struct fc_frame_header
*fc_hdr
;
13534 struct lpfc_nvmet_tgtport
*tgtp
;
13535 uint32_t status
, rq_id
;
13536 unsigned long iflags
;
13537 uint32_t fctl
, idx
;
13539 if ((phba
->nvmet_support
== 0) ||
13540 (phba
->sli4_hba
.nvmet_cqset
== NULL
))
13543 idx
= cq
->queue_id
- phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
;
13544 hrq
= phba
->sli4_hba
.nvmet_mrq_hdr
[idx
];
13545 drq
= phba
->sli4_hba
.nvmet_mrq_data
[idx
];
13547 /* sanity check on queue memory */
13548 if (unlikely(!hrq
) || unlikely(!drq
))
13551 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
13552 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
13554 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
13556 if ((phba
->nvmet_support
== 0) ||
13557 (rq_id
!= hrq
->queue_id
))
13560 status
= bf_get(lpfc_rcqe_status
, rcqe
);
13562 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
13563 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13564 "6126 Receive Frame Truncated!!\n");
13566 case FC_STATUS_RQ_SUCCESS
:
13567 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13568 lpfc_sli4_rq_release(hrq
, drq
);
13569 dma_buf
= lpfc_sli_rqbuf_get(phba
, hrq
);
13571 hrq
->RQ_no_buf_found
++;
13572 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13575 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13577 hrq
->RQ_buf_posted
--;
13578 fc_hdr
= (struct fc_frame_header
*)dma_buf
->hbuf
.virt
;
13580 /* Just some basic sanity checks on FCP Command frame */
13581 fctl
= (fc_hdr
->fh_f_ctl
[0] << 16 |
13582 fc_hdr
->fh_f_ctl
[1] << 8 |
13583 fc_hdr
->fh_f_ctl
[2]);
13585 (FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
)) !=
13586 (FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
)) ||
13587 (fc_hdr
->fh_seq_cnt
!= 0)) /* 0 byte swapped is still 0 */
13590 if (fc_hdr
->fh_type
== FC_TYPE_FCP
) {
13591 dma_buf
->bytes_recv
= bf_get(lpfc_rcqe_length
, rcqe
);
13592 lpfc_nvmet_unsol_fcp_event(
13593 phba
, idx
, dma_buf
,
13594 cq
->isr_timestamp
);
13598 lpfc_in_buf_free(phba
, &dma_buf
->dbuf
);
13600 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
13601 if (phba
->nvmet_support
) {
13602 tgtp
= phba
->targetport
->private;
13603 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_NVME
,
13604 "6401 RQE Error x%x, posted %d err_cnt "
13606 status
, hrq
->RQ_buf_posted
,
13607 hrq
->RQ_no_posted_buf
,
13608 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
13609 atomic_read(&tgtp
->rcv_fcp_cmd_out
),
13610 atomic_read(&tgtp
->xmt_fcp_release
));
13614 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
13615 hrq
->RQ_no_posted_buf
++;
13616 /* Post more buffers if possible */
13624 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
13625 * @cq: Pointer to the completion queue.
13626 * @eqe: Pointer to fast-path completion queue entry.
13628 * This routine process a fast-path work queue completion entry from fast-path
13629 * event queue for FCP command response completion.
13632 lpfc_sli4_fp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13633 struct lpfc_cqe
*cqe
)
13635 struct lpfc_wcqe_release wcqe
;
13636 bool workposted
= false;
13638 /* Copy the work queue CQE and convert endian order if needed */
13639 lpfc_sli4_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
13641 /* Check and process for different type of WCQE and dispatch */
13642 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
13643 case CQE_CODE_COMPL_WQE
:
13644 case CQE_CODE_NVME_ERSP
:
13646 /* Process the WQ complete event */
13647 phba
->last_completion_time
= jiffies
;
13648 if ((cq
->subtype
== LPFC_FCP
) || (cq
->subtype
== LPFC_NVME
))
13649 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
13650 (struct lpfc_wcqe_complete
*)&wcqe
);
13651 if (cq
->subtype
== LPFC_NVME_LS
)
13652 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
13653 (struct lpfc_wcqe_complete
*)&wcqe
);
13655 case CQE_CODE_RELEASE_WQE
:
13656 cq
->CQ_release_wqe
++;
13657 /* Process the WQ release event */
13658 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
13659 (struct lpfc_wcqe_release
*)&wcqe
);
13661 case CQE_CODE_XRI_ABORTED
:
13662 cq
->CQ_xri_aborted
++;
13663 /* Process the WQ XRI abort event */
13664 phba
->last_completion_time
= jiffies
;
13665 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
13666 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
13668 case CQE_CODE_RECEIVE_V1
:
13669 case CQE_CODE_RECEIVE
:
13670 phba
->last_completion_time
= jiffies
;
13671 if (cq
->subtype
== LPFC_NVMET
) {
13672 workposted
= lpfc_sli4_nvmet_handle_rcqe(
13673 phba
, cq
, (struct lpfc_rcqe
*)&wcqe
);
13677 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13678 "0144 Not a valid CQE code: x%x\n",
13679 bf_get(lpfc_wcqe_c_code
, &wcqe
));
13686 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
13687 * @phba: Pointer to HBA context object.
13688 * @eqe: Pointer to fast-path event queue entry.
13690 * This routine process a event queue entry from the fast-path event queue.
13691 * It will check the MajorCode and MinorCode to determine this is for a
13692 * completion event on a completion queue, if not, an error shall be logged
13693 * and just return. Otherwise, it will get to the corresponding completion
13694 * queue and process all the entries on the completion queue, rearm the
13695 * completion queue, and then return.
13698 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
13701 struct lpfc_queue
*cq
= NULL
;
13704 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
13705 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13706 "0366 Not a valid completion "
13707 "event: majorcode=x%x, minorcode=x%x\n",
13708 bf_get_le32(lpfc_eqe_major_code
, eqe
),
13709 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
13713 /* Get the reference to the corresponding CQ */
13714 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13716 if (phba
->cfg_nvmet_mrq
&& phba
->sli4_hba
.nvmet_cqset
) {
13717 id
= phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
;
13718 if ((cqid
>= id
) && (cqid
< (id
+ phba
->cfg_nvmet_mrq
))) {
13719 /* Process NVMET unsol rcv */
13720 cq
= phba
->sli4_hba
.nvmet_cqset
[cqid
- id
];
13725 if (phba
->sli4_hba
.nvme_cq_map
&&
13726 (cqid
== phba
->sli4_hba
.nvme_cq_map
[qidx
])) {
13727 /* Process NVME / NVMET command completion */
13728 cq
= phba
->sli4_hba
.nvme_cq
[qidx
];
13732 if (phba
->sli4_hba
.fcp_cq_map
&&
13733 (cqid
== phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
13734 /* Process FCP command completion */
13735 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
13739 if (phba
->sli4_hba
.nvmels_cq
&&
13740 (cqid
== phba
->sli4_hba
.nvmels_cq
->queue_id
)) {
13741 /* Process NVME unsol rcv */
13742 cq
= phba
->sli4_hba
.nvmels_cq
;
13745 /* Otherwise this is a Slow path event */
13747 lpfc_sli4_sp_handle_eqe(phba
, eqe
, phba
->sli4_hba
.hba_eq
[qidx
]);
13752 if (unlikely(cqid
!= cq
->queue_id
)) {
13753 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13754 "0368 Miss-matched fast-path completion "
13755 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
13756 cqid
, cq
->queue_id
);
13760 /* Save EQ associated with this CQ */
13761 cq
->assoc_qp
= phba
->sli4_hba
.hba_eq
[qidx
];
13763 if (!queue_work(phba
->wq
, &cq
->irqwork
))
13764 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13765 "0363 Cannot schedule soft IRQ "
13766 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13767 cqid
, cq
->queue_id
, smp_processor_id());
13771 * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
13772 * @phba: Pointer to HBA context object.
13773 * @eqe: Pointer to fast-path event queue entry.
13775 * This routine process a event queue entry from the fast-path event queue.
13776 * It will check the MajorCode and MinorCode to determine this is for a
13777 * completion event on a completion queue, if not, an error shall be logged
13778 * and just return. Otherwise, it will get to the corresponding completion
13779 * queue and process all the entries on the completion queue, rearm the
13780 * completion queue, and then return.
13783 lpfc_sli4_hba_process_cq(struct work_struct
*work
)
13785 struct lpfc_queue
*cq
=
13786 container_of(work
, struct lpfc_queue
, irqwork
);
13787 struct lpfc_hba
*phba
= cq
->phba
;
13788 struct lpfc_cqe
*cqe
;
13789 bool workposted
= false;
13792 /* Process all the entries to the CQ */
13793 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13794 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13795 if (phba
->ktime_on
)
13796 cq
->isr_timestamp
= ktime_get_ns();
13798 cq
->isr_timestamp
= 0;
13800 workposted
|= lpfc_sli4_fp_handle_cqe(phba
, cq
, cqe
);
13801 if (!(++ccount
% cq
->entry_repost
))
13805 /* Track the max number of CQEs processed in 1 EQ */
13806 if (ccount
> cq
->CQ_max_cqe
)
13807 cq
->CQ_max_cqe
= ccount
;
13808 cq
->assoc_qp
->EQ_cqe_cnt
+= ccount
;
13810 /* Catch the no cq entry condition */
13811 if (unlikely(ccount
== 0))
13812 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13813 "0369 No entry from fast-path completion "
13814 "queue fcpcqid=%d\n", cq
->queue_id
);
13816 /* In any case, flash and re-arm the CQ */
13817 phba
->sli4_hba
.sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
13819 /* wake up worker thread if there are works to be done */
13821 lpfc_worker_wake_up(phba
);
13825 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
13827 struct lpfc_eqe
*eqe
;
13829 /* walk all the EQ entries and drop on the floor */
13830 while ((eqe
= lpfc_sli4_eq_get(eq
)))
13833 /* Clear and re-arm the EQ */
13834 phba
->sli4_hba
.sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
13839 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
13841 * @phba: Pointer to HBA context object.
13842 * @eqe: Pointer to fast-path event queue entry.
13844 * This routine process a event queue entry from the Flash Optimized Fabric
13845 * event queue. It will check the MajorCode and MinorCode to determine this
13846 * is for a completion event on a completion queue, if not, an error shall be
13847 * logged and just return. Otherwise, it will get to the corresponding
13848 * completion queue and process all the entries on the completion queue, rearm
13849 * the completion queue, and then return.
13852 lpfc_sli4_fof_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
13854 struct lpfc_queue
*cq
;
13857 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
13858 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13859 "9147 Not a valid completion "
13860 "event: majorcode=x%x, minorcode=x%x\n",
13861 bf_get_le32(lpfc_eqe_major_code
, eqe
),
13862 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
13866 /* Get the reference to the corresponding CQ */
13867 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13869 /* Next check for OAS */
13870 cq
= phba
->sli4_hba
.oas_cq
;
13871 if (unlikely(!cq
)) {
13872 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
13873 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13874 "9148 OAS completion queue "
13875 "does not exist\n");
13879 if (unlikely(cqid
!= cq
->queue_id
)) {
13880 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13881 "9149 Miss-matched fast-path compl "
13882 "queue id: eqcqid=%d, fcpcqid=%d\n",
13883 cqid
, cq
->queue_id
);
13887 /* Save EQ associated with this CQ */
13888 cq
->assoc_qp
= phba
->sli4_hba
.fof_eq
;
13890 /* CQ work will be processed on CPU affinitized to this IRQ */
13891 if (!queue_work(phba
->wq
, &cq
->irqwork
))
13892 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13893 "0367 Cannot schedule soft IRQ "
13894 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13895 cqid
, cq
->queue_id
, smp_processor_id());
13899 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
13900 * @irq: Interrupt number.
13901 * @dev_id: The device context pointer.
13903 * This function is directly called from the PCI layer as an interrupt
13904 * service routine when device with SLI-4 interface spec is enabled with
13905 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
13906 * IOCB ring event in the HBA. However, when the device is enabled with either
13907 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13908 * device-level interrupt handler. When the PCI slot is in error recovery
13909 * or the HBA is undergoing initialization, the interrupt handler will not
13910 * process the interrupt. The Flash Optimized Fabric ring event are handled in
13911 * the intrrupt context. This function is called without any lock held.
13912 * It gets the hbalock to access and update SLI data structures. Note that,
13913 * the EQ to CQ are one-to-one map such that the EQ index is
13914 * equal to that of CQ index.
13916 * This function returns IRQ_HANDLED when interrupt is handled else it
13917 * returns IRQ_NONE.
13920 lpfc_sli4_fof_intr_handler(int irq
, void *dev_id
)
13922 struct lpfc_hba
*phba
;
13923 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
13924 struct lpfc_queue
*eq
;
13925 struct lpfc_eqe
*eqe
;
13926 unsigned long iflag
;
13929 /* Get the driver's phba structure from the dev_id */
13930 hba_eq_hdl
= (struct lpfc_hba_eq_hdl
*)dev_id
;
13931 phba
= hba_eq_hdl
->phba
;
13933 if (unlikely(!phba
))
13936 /* Get to the EQ struct associated with this vector */
13937 eq
= phba
->sli4_hba
.fof_eq
;
13941 /* Check device state for handling interrupt */
13942 if (unlikely(lpfc_intr_state_check(phba
))) {
13943 /* Check again for link_state with lock held */
13944 spin_lock_irqsave(&phba
->hbalock
, iflag
);
13945 if (phba
->link_state
< LPFC_LINK_DOWN
)
13946 /* Flush, clear interrupt, and rearm the EQ */
13947 lpfc_sli4_eq_flush(phba
, eq
);
13948 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
13953 * Process all the event on FCP fast-path EQ
13955 while ((eqe
= lpfc_sli4_eq_get(eq
))) {
13956 lpfc_sli4_fof_handle_eqe(phba
, eqe
);
13957 if (!(++ecount
% eq
->entry_repost
))
13959 eq
->EQ_processed
++;
13962 /* Track the max number of EQEs processed in 1 intr */
13963 if (ecount
> eq
->EQ_max_eqe
)
13964 eq
->EQ_max_eqe
= ecount
;
13967 if (unlikely(ecount
== 0)) {
13970 if (phba
->intr_type
== MSIX
)
13971 /* MSI-X treated interrupt served as no EQ share INT */
13972 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13973 "9145 MSI-X interrupt with no EQE\n");
13975 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13976 "9146 ISR interrupt with no EQE\n");
13977 /* Non MSI-X treated on interrupt as EQ share INT */
13981 /* Always clear and re-arm the fast-path EQ */
13982 phba
->sli4_hba
.sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
13983 return IRQ_HANDLED
;
13987 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
13988 * @irq: Interrupt number.
13989 * @dev_id: The device context pointer.
13991 * This function is directly called from the PCI layer as an interrupt
13992 * service routine when device with SLI-4 interface spec is enabled with
13993 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13994 * ring event in the HBA. However, when the device is enabled with either
13995 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13996 * device-level interrupt handler. When the PCI slot is in error recovery
13997 * or the HBA is undergoing initialization, the interrupt handler will not
13998 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13999 * the intrrupt context. This function is called without any lock held.
14000 * It gets the hbalock to access and update SLI data structures. Note that,
14001 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
14002 * equal to that of FCP CQ index.
14004 * The link attention and ELS ring attention events are handled
14005 * by the worker thread. The interrupt handler signals the worker thread
14006 * and returns for these events. This function is called without any lock
14007 * held. It gets the hbalock to access and update SLI data structures.
14009 * This function returns IRQ_HANDLED when interrupt is handled else it
14010 * returns IRQ_NONE.
14013 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
14015 struct lpfc_hba
*phba
;
14016 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
14017 struct lpfc_queue
*fpeq
;
14018 struct lpfc_eqe
*eqe
;
14019 unsigned long iflag
;
14023 /* Get the driver's phba structure from the dev_id */
14024 hba_eq_hdl
= (struct lpfc_hba_eq_hdl
*)dev_id
;
14025 phba
= hba_eq_hdl
->phba
;
14026 hba_eqidx
= hba_eq_hdl
->idx
;
14028 if (unlikely(!phba
))
14030 if (unlikely(!phba
->sli4_hba
.hba_eq
))
14033 /* Get to the EQ struct associated with this vector */
14034 fpeq
= phba
->sli4_hba
.hba_eq
[hba_eqidx
];
14035 if (unlikely(!fpeq
))
14038 if (lpfc_fcp_look_ahead
) {
14039 if (atomic_dec_and_test(&hba_eq_hdl
->hba_eq_in_use
))
14040 phba
->sli4_hba
.sli4_eq_clr_intr(fpeq
);
14042 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
14047 /* Check device state for handling interrupt */
14048 if (unlikely(lpfc_intr_state_check(phba
))) {
14049 /* Check again for link_state with lock held */
14050 spin_lock_irqsave(&phba
->hbalock
, iflag
);
14051 if (phba
->link_state
< LPFC_LINK_DOWN
)
14052 /* Flush, clear interrupt, and rearm the EQ */
14053 lpfc_sli4_eq_flush(phba
, fpeq
);
14054 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
14055 if (lpfc_fcp_look_ahead
)
14056 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
14061 * Process all the event on FCP fast-path EQ
14063 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
14064 lpfc_sli4_hba_handle_eqe(phba
, eqe
, hba_eqidx
);
14065 if (!(++ecount
% fpeq
->entry_repost
))
14067 fpeq
->EQ_processed
++;
14070 /* Track the max number of EQEs processed in 1 intr */
14071 if (ecount
> fpeq
->EQ_max_eqe
)
14072 fpeq
->EQ_max_eqe
= ecount
;
14074 /* Always clear and re-arm the fast-path EQ */
14075 phba
->sli4_hba
.sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
14077 if (unlikely(ecount
== 0)) {
14078 fpeq
->EQ_no_entry
++;
14080 if (lpfc_fcp_look_ahead
) {
14081 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
14085 if (phba
->intr_type
== MSIX
)
14086 /* MSI-X treated interrupt served as no EQ share INT */
14087 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
14088 "0358 MSI-X interrupt with no EQE\n");
14090 /* Non MSI-X treated on interrupt as EQ share INT */
14094 if (lpfc_fcp_look_ahead
)
14095 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
14097 return IRQ_HANDLED
;
14098 } /* lpfc_sli4_fp_intr_handler */
14101 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
14102 * @irq: Interrupt number.
14103 * @dev_id: The device context pointer.
14105 * This function is the device-level interrupt handler to device with SLI-4
14106 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
14107 * interrupt mode is enabled and there is an event in the HBA which requires
14108 * driver attention. This function invokes the slow-path interrupt attention
14109 * handling function and fast-path interrupt attention handling function in
14110 * turn to process the relevant HBA attention events. This function is called
14111 * without any lock held. It gets the hbalock to access and update SLI data
14114 * This function returns IRQ_HANDLED when interrupt is handled, else it
14115 * returns IRQ_NONE.
14118 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
14120 struct lpfc_hba
*phba
;
14121 irqreturn_t hba_irq_rc
;
14122 bool hba_handled
= false;
14125 /* Get the driver's phba structure from the dev_id */
14126 phba
= (struct lpfc_hba
*)dev_id
;
14128 if (unlikely(!phba
))
14132 * Invoke fast-path host attention interrupt handling as appropriate.
14134 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++) {
14135 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
14136 &phba
->sli4_hba
.hba_eq_hdl
[qidx
]);
14137 if (hba_irq_rc
== IRQ_HANDLED
)
14138 hba_handled
|= true;
14141 if (phba
->cfg_fof
) {
14142 hba_irq_rc
= lpfc_sli4_fof_intr_handler(irq
,
14143 &phba
->sli4_hba
.hba_eq_hdl
[qidx
]);
14144 if (hba_irq_rc
== IRQ_HANDLED
)
14145 hba_handled
|= true;
14148 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
14149 } /* lpfc_sli4_intr_handler */
14152 * lpfc_sli4_queue_free - free a queue structure and associated memory
14153 * @queue: The queue structure to free.
14155 * This function frees a queue structure and the DMAable memory used for
14156 * the host resident queue. This function must be called after destroying the
14157 * queue on the HBA.
14160 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
14162 struct lpfc_dmabuf
*dmabuf
;
14167 while (!list_empty(&queue
->page_list
)) {
14168 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
14170 dma_free_coherent(&queue
->phba
->pcidev
->dev
, queue
->page_size
,
14171 dmabuf
->virt
, dmabuf
->phys
);
14175 lpfc_free_rq_buffer(queue
->phba
, queue
);
14176 kfree(queue
->rqbp
);
14179 if (!list_empty(&queue
->wq_list
))
14180 list_del(&queue
->wq_list
);
14187 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
14188 * @phba: The HBA that this queue is being created on.
14189 * @page_size: The size of a queue page
14190 * @entry_size: The size of each queue entry for this queue.
14191 * @entry count: The number of entries that this queue will handle.
14193 * This function allocates a queue structure and the DMAable memory used for
14194 * the host resident queue. This function must be called before creating the
14195 * queue on the HBA.
14197 struct lpfc_queue
*
14198 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t page_size
,
14199 uint32_t entry_size
, uint32_t entry_count
)
14201 struct lpfc_queue
*queue
;
14202 struct lpfc_dmabuf
*dmabuf
;
14203 int x
, total_qe_count
;
14205 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14207 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14208 hw_page_size
= page_size
;
14210 queue
= kzalloc(sizeof(struct lpfc_queue
) +
14211 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
14214 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
14215 hw_page_size
))/hw_page_size
;
14217 /* If needed, Adjust page count to match the max the adapter supports */
14218 if (queue
->page_count
> phba
->sli4_hba
.pc_sli4_params
.wqpcnt
)
14219 queue
->page_count
= phba
->sli4_hba
.pc_sli4_params
.wqpcnt
;
14221 INIT_LIST_HEAD(&queue
->list
);
14222 INIT_LIST_HEAD(&queue
->wq_list
);
14223 INIT_LIST_HEAD(&queue
->wqfull_list
);
14224 INIT_LIST_HEAD(&queue
->page_list
);
14225 INIT_LIST_HEAD(&queue
->child_list
);
14227 /* Set queue parameters now. If the system cannot provide memory
14228 * resources, the free routine needs to know what was allocated.
14230 queue
->entry_size
= entry_size
;
14231 queue
->entry_count
= entry_count
;
14232 queue
->page_size
= hw_page_size
;
14233 queue
->phba
= phba
;
14235 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
14236 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
14239 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
14240 hw_page_size
, &dmabuf
->phys
,
14242 if (!dmabuf
->virt
) {
14246 dmabuf
->buffer_tag
= x
;
14247 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
14248 /* initialize queue's entry array */
14249 dma_pointer
= dmabuf
->virt
;
14250 for (; total_qe_count
< entry_count
&&
14251 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
14252 total_qe_count
++, dma_pointer
+= entry_size
) {
14253 queue
->qe
[total_qe_count
].address
= dma_pointer
;
14256 INIT_WORK(&queue
->irqwork
, lpfc_sli4_hba_process_cq
);
14257 INIT_WORK(&queue
->spwork
, lpfc_sli4_sp_process_cq
);
14259 /* entry_repost will be set during q creation */
14263 lpfc_sli4_queue_free(queue
);
14268 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
14269 * @phba: HBA structure that indicates port to create a queue on.
14270 * @pci_barset: PCI BAR set flag.
14272 * This function shall perform iomap of the specified PCI BAR address to host
14273 * memory address if not already done so and return it. The returned host
14274 * memory address can be NULL.
14276 static void __iomem
*
14277 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
14282 switch (pci_barset
) {
14283 case WQ_PCI_BAR_0_AND_1
:
14284 return phba
->pci_bar0_memmap_p
;
14285 case WQ_PCI_BAR_2_AND_3
:
14286 return phba
->pci_bar2_memmap_p
;
14287 case WQ_PCI_BAR_4_AND_5
:
14288 return phba
->pci_bar4_memmap_p
;
14296 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs
14297 * @phba: HBA structure that indicates port to create a queue on.
14298 * @startq: The starting FCP EQ to modify
14300 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
14301 * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be
14302 * updated in one mailbox command.
14304 * The @phba struct is used to send mailbox command to HBA. The @startq
14305 * is used to get the starting FCP EQ to change.
14306 * This function is asynchronous and will wait for the mailbox
14307 * command to finish before continuing.
14309 * On success this function will return a zero. If unable to allocate enough
14310 * memory this function will return -ENOMEM. If the queue create mailbox command
14311 * fails this function will return -ENXIO.
14314 lpfc_modify_hba_eq_delay(struct lpfc_hba
*phba
, uint32_t startq
,
14315 uint32_t numq
, uint32_t imax
)
14317 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
14318 LPFC_MBOXQ_t
*mbox
;
14319 struct lpfc_queue
*eq
;
14320 int cnt
, rc
, length
, status
= 0;
14321 uint32_t shdr_status
, shdr_add_status
;
14322 uint32_t result
, val
;
14324 union lpfc_sli4_cfg_shdr
*shdr
;
14327 if (startq
>= phba
->io_channel_irqs
)
14330 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14333 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
14334 sizeof(struct lpfc_sli4_cfg_mhdr
));
14335 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14336 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
14337 length
, LPFC_SLI4_MBX_EMBED
);
14338 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
14340 /* Calculate delay multiper from maximum interrupt per second */
14341 result
= imax
/ phba
->io_channel_irqs
;
14342 if (result
> LPFC_DMULT_CONST
|| result
== 0)
14345 dmult
= LPFC_DMULT_CONST
/result
- 1;
14346 if (dmult
> LPFC_DMULT_MAX
)
14347 dmult
= LPFC_DMULT_MAX
;
14350 for (qidx
= startq
; qidx
< phba
->io_channel_irqs
; qidx
++) {
14351 eq
= phba
->sli4_hba
.hba_eq
[qidx
];
14355 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
14356 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
14357 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
14360 /* q_mode is only used for auto_imax */
14361 if (phba
->sli
.sli_flag
& LPFC_SLI_USE_EQDR
) {
14362 /* Use EQ Delay Register method for q_mode */
14364 /* Convert for EQ Delay register */
14365 val
= phba
->cfg_fcp_imax
;
14367 /* First, interrupts per sec per EQ */
14368 val
= phba
->cfg_fcp_imax
/
14369 phba
->io_channel_irqs
;
14371 /* us delay between each interrupt */
14372 val
= LPFC_SEC_TO_USEC
/ val
;
14382 eq_delay
->u
.request
.num_eq
= cnt
;
14384 mbox
->vport
= phba
->pport
;
14385 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14386 mbox
->context1
= NULL
;
14387 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14388 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
14389 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14390 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14391 if (shdr_status
|| shdr_add_status
|| rc
) {
14392 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14393 "2512 MODIFY_EQ_DELAY mailbox failed with "
14394 "status x%x add_status x%x, mbx status x%x\n",
14395 shdr_status
, shdr_add_status
, rc
);
14398 mempool_free(mbox
, phba
->mbox_mem_pool
);
14403 * lpfc_eq_create - Create an Event Queue on the HBA
14404 * @phba: HBA structure that indicates port to create a queue on.
14405 * @eq: The queue structure to use to create the event queue.
14406 * @imax: The maximum interrupt per second limit.
14408 * This function creates an event queue, as detailed in @eq, on a port,
14409 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
14411 * The @phba struct is used to send mailbox command to HBA. The @eq struct
14412 * is used to get the entry count and entry size that are necessary to
14413 * determine the number of pages to allocate and use for this queue. This
14414 * function will send the EQ_CREATE mailbox command to the HBA to setup the
14415 * event queue. This function is asynchronous and will wait for the mailbox
14416 * command to finish before continuing.
14418 * On success this function will return a zero. If unable to allocate enough
14419 * memory this function will return -ENOMEM. If the queue create mailbox command
14420 * fails this function will return -ENXIO.
14423 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
14425 struct lpfc_mbx_eq_create
*eq_create
;
14426 LPFC_MBOXQ_t
*mbox
;
14427 int rc
, length
, status
= 0;
14428 struct lpfc_dmabuf
*dmabuf
;
14429 uint32_t shdr_status
, shdr_add_status
;
14430 union lpfc_sli4_cfg_shdr
*shdr
;
14432 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14434 /* sanity check on queue memory */
14437 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14438 hw_page_size
= SLI4_PAGE_SIZE
;
14440 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14443 length
= (sizeof(struct lpfc_mbx_eq_create
) -
14444 sizeof(struct lpfc_sli4_cfg_mhdr
));
14445 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14446 LPFC_MBOX_OPCODE_EQ_CREATE
,
14447 length
, LPFC_SLI4_MBX_EMBED
);
14448 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
14449 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
14450 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
14452 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
14454 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
14456 /* Use version 2 of CREATE_EQ if eqav is set */
14457 if (phba
->sli4_hba
.pc_sli4_params
.eqav
) {
14458 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14459 LPFC_Q_CREATE_VERSION_2
);
14460 bf_set(lpfc_eq_context_autovalid
, &eq_create
->u
.request
.context
,
14461 phba
->sli4_hba
.pc_sli4_params
.eqav
);
14464 /* don't setup delay multiplier using EQ_CREATE */
14466 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
14468 switch (eq
->entry_count
) {
14470 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14471 "0360 Unsupported EQ count. (%d)\n",
14473 if (eq
->entry_count
< 256)
14475 /* otherwise default to smallest count (drop through) */
14477 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14481 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14485 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14489 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14493 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14497 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
14498 memset(dmabuf
->virt
, 0, hw_page_size
);
14499 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14500 putPaddrLow(dmabuf
->phys
);
14501 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14502 putPaddrHigh(dmabuf
->phys
);
14504 mbox
->vport
= phba
->pport
;
14505 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14506 mbox
->context1
= NULL
;
14507 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14508 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14509 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14510 if (shdr_status
|| shdr_add_status
|| rc
) {
14511 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14512 "2500 EQ_CREATE mailbox failed with "
14513 "status x%x add_status x%x, mbx status x%x\n",
14514 shdr_status
, shdr_add_status
, rc
);
14517 eq
->type
= LPFC_EQ
;
14518 eq
->subtype
= LPFC_NONE
;
14519 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
14520 if (eq
->queue_id
== 0xFFFF)
14522 eq
->host_index
= 0;
14524 eq
->entry_repost
= LPFC_EQ_REPOST
;
14526 mempool_free(mbox
, phba
->mbox_mem_pool
);
14531 * lpfc_cq_create - Create a Completion Queue on the HBA
14532 * @phba: HBA structure that indicates port to create a queue on.
14533 * @cq: The queue structure to use to create the completion queue.
14534 * @eq: The event queue to bind this completion queue to.
14536 * This function creates a completion queue, as detailed in @wq, on a port,
14537 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
14539 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14540 * is used to get the entry count and entry size that are necessary to
14541 * determine the number of pages to allocate and use for this queue. The @eq
14542 * is used to indicate which event queue to bind this completion queue to. This
14543 * function will send the CQ_CREATE mailbox command to the HBA to setup the
14544 * completion queue. This function is asynchronous and will wait for the mailbox
14545 * command to finish before continuing.
14547 * On success this function will return a zero. If unable to allocate enough
14548 * memory this function will return -ENOMEM. If the queue create mailbox command
14549 * fails this function will return -ENXIO.
14552 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
14553 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
14555 struct lpfc_mbx_cq_create
*cq_create
;
14556 struct lpfc_dmabuf
*dmabuf
;
14557 LPFC_MBOXQ_t
*mbox
;
14558 int rc
, length
, status
= 0;
14559 uint32_t shdr_status
, shdr_add_status
;
14560 union lpfc_sli4_cfg_shdr
*shdr
;
14561 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14563 /* sanity check on queue memory */
14566 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14567 hw_page_size
= cq
->page_size
;
14569 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14572 length
= (sizeof(struct lpfc_mbx_cq_create
) -
14573 sizeof(struct lpfc_sli4_cfg_mhdr
));
14574 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14575 LPFC_MBOX_OPCODE_CQ_CREATE
,
14576 length
, LPFC_SLI4_MBX_EMBED
);
14577 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
14578 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
14579 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
14581 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
14582 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
14583 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14584 phba
->sli4_hba
.pc_sli4_params
.cqv
);
14585 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
14586 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
,
14587 (cq
->page_size
/ SLI4_PAGE_SIZE
));
14588 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
14590 bf_set(lpfc_cq_context_autovalid
, &cq_create
->u
.request
.context
,
14591 phba
->sli4_hba
.pc_sli4_params
.cqav
);
14593 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
14596 switch (cq
->entry_count
) {
14599 if (phba
->sli4_hba
.pc_sli4_params
.cqv
==
14600 LPFC_Q_CREATE_VERSION_2
) {
14601 cq_create
->u
.request
.context
.lpfc_cq_context_count
=
14603 bf_set(lpfc_cq_context_count
,
14604 &cq_create
->u
.request
.context
,
14605 LPFC_CQ_CNT_WORD7
);
14610 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14611 "0361 Unsupported CQ count: "
14612 "entry cnt %d sz %d pg cnt %d\n",
14613 cq
->entry_count
, cq
->entry_size
,
14615 if (cq
->entry_count
< 256) {
14619 /* otherwise default to smallest count (drop through) */
14621 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
14625 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
14629 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
14633 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
14634 memset(dmabuf
->virt
, 0, cq
->page_size
);
14635 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14636 putPaddrLow(dmabuf
->phys
);
14637 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14638 putPaddrHigh(dmabuf
->phys
);
14640 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14642 /* The IOCTL status is embedded in the mailbox subheader. */
14643 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14644 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14645 if (shdr_status
|| shdr_add_status
|| rc
) {
14646 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14647 "2501 CQ_CREATE mailbox failed with "
14648 "status x%x add_status x%x, mbx status x%x\n",
14649 shdr_status
, shdr_add_status
, rc
);
14653 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
14654 if (cq
->queue_id
== 0xFFFF) {
14658 /* link the cq onto the parent eq child list */
14659 list_add_tail(&cq
->list
, &eq
->child_list
);
14660 /* Set up completion queue's type and subtype */
14662 cq
->subtype
= subtype
;
14663 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
14664 cq
->assoc_qid
= eq
->queue_id
;
14665 cq
->host_index
= 0;
14667 cq
->entry_repost
= LPFC_CQ_REPOST
;
14670 mempool_free(mbox
, phba
->mbox_mem_pool
);
14675 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
14676 * @phba: HBA structure that indicates port to create a queue on.
14677 * @cqp: The queue structure array to use to create the completion queues.
14678 * @eqp: The event queue array to bind these completion queues to.
14680 * This function creates a set of completion queue, s to support MRQ
14681 * as detailed in @cqp, on a port,
14682 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
14684 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14685 * is used to get the entry count and entry size that are necessary to
14686 * determine the number of pages to allocate and use for this queue. The @eq
14687 * is used to indicate which event queue to bind this completion queue to. This
14688 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
14689 * completion queue. This function is asynchronous and will wait for the mailbox
14690 * command to finish before continuing.
14692 * On success this function will return a zero. If unable to allocate enough
14693 * memory this function will return -ENOMEM. If the queue create mailbox command
14694 * fails this function will return -ENXIO.
14697 lpfc_cq_create_set(struct lpfc_hba
*phba
, struct lpfc_queue
**cqp
,
14698 struct lpfc_queue
**eqp
, uint32_t type
, uint32_t subtype
)
14700 struct lpfc_queue
*cq
;
14701 struct lpfc_queue
*eq
;
14702 struct lpfc_mbx_cq_create_set
*cq_set
;
14703 struct lpfc_dmabuf
*dmabuf
;
14704 LPFC_MBOXQ_t
*mbox
;
14705 int rc
, length
, alloclen
, status
= 0;
14706 int cnt
, idx
, numcq
, page_idx
= 0;
14707 uint32_t shdr_status
, shdr_add_status
;
14708 union lpfc_sli4_cfg_shdr
*shdr
;
14709 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14711 /* sanity check on queue memory */
14712 numcq
= phba
->cfg_nvmet_mrq
;
14713 if (!cqp
|| !eqp
|| !numcq
)
14716 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14720 length
= sizeof(struct lpfc_mbx_cq_create_set
);
14721 length
+= ((numcq
* cqp
[0]->page_count
) *
14722 sizeof(struct dma_address
));
14723 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14724 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET
, length
,
14725 LPFC_SLI4_MBX_NEMBED
);
14726 if (alloclen
< length
) {
14727 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14728 "3098 Allocated DMA memory size (%d) is "
14729 "less than the requested DMA memory size "
14730 "(%d)\n", alloclen
, length
);
14734 cq_set
= mbox
->sge_array
->addr
[0];
14735 shdr
= (union lpfc_sli4_cfg_shdr
*)&cq_set
->cfg_shdr
;
14736 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, 0);
14738 for (idx
= 0; idx
< numcq
; idx
++) {
14745 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14746 hw_page_size
= cq
->page_size
;
14750 bf_set(lpfc_mbx_cq_create_set_page_size
,
14751 &cq_set
->u
.request
,
14752 (hw_page_size
/ SLI4_PAGE_SIZE
));
14753 bf_set(lpfc_mbx_cq_create_set_num_pages
,
14754 &cq_set
->u
.request
, cq
->page_count
);
14755 bf_set(lpfc_mbx_cq_create_set_evt
,
14756 &cq_set
->u
.request
, 1);
14757 bf_set(lpfc_mbx_cq_create_set_valid
,
14758 &cq_set
->u
.request
, 1);
14759 bf_set(lpfc_mbx_cq_create_set_cqe_size
,
14760 &cq_set
->u
.request
, 0);
14761 bf_set(lpfc_mbx_cq_create_set_num_cq
,
14762 &cq_set
->u
.request
, numcq
);
14763 bf_set(lpfc_mbx_cq_create_set_autovalid
,
14764 &cq_set
->u
.request
,
14765 phba
->sli4_hba
.pc_sli4_params
.cqav
);
14766 switch (cq
->entry_count
) {
14769 if (phba
->sli4_hba
.pc_sli4_params
.cqv
==
14770 LPFC_Q_CREATE_VERSION_2
) {
14771 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14772 &cq_set
->u
.request
,
14774 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14775 &cq_set
->u
.request
,
14776 LPFC_CQ_CNT_WORD7
);
14781 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14782 "3118 Bad CQ count. (%d)\n",
14784 if (cq
->entry_count
< 256) {
14788 /* otherwise default to smallest (drop thru) */
14790 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14791 &cq_set
->u
.request
, LPFC_CQ_CNT_256
);
14794 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14795 &cq_set
->u
.request
, LPFC_CQ_CNT_512
);
14798 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14799 &cq_set
->u
.request
, LPFC_CQ_CNT_1024
);
14802 bf_set(lpfc_mbx_cq_create_set_eq_id0
,
14803 &cq_set
->u
.request
, eq
->queue_id
);
14806 bf_set(lpfc_mbx_cq_create_set_eq_id1
,
14807 &cq_set
->u
.request
, eq
->queue_id
);
14810 bf_set(lpfc_mbx_cq_create_set_eq_id2
,
14811 &cq_set
->u
.request
, eq
->queue_id
);
14814 bf_set(lpfc_mbx_cq_create_set_eq_id3
,
14815 &cq_set
->u
.request
, eq
->queue_id
);
14818 bf_set(lpfc_mbx_cq_create_set_eq_id4
,
14819 &cq_set
->u
.request
, eq
->queue_id
);
14822 bf_set(lpfc_mbx_cq_create_set_eq_id5
,
14823 &cq_set
->u
.request
, eq
->queue_id
);
14826 bf_set(lpfc_mbx_cq_create_set_eq_id6
,
14827 &cq_set
->u
.request
, eq
->queue_id
);
14830 bf_set(lpfc_mbx_cq_create_set_eq_id7
,
14831 &cq_set
->u
.request
, eq
->queue_id
);
14834 bf_set(lpfc_mbx_cq_create_set_eq_id8
,
14835 &cq_set
->u
.request
, eq
->queue_id
);
14838 bf_set(lpfc_mbx_cq_create_set_eq_id9
,
14839 &cq_set
->u
.request
, eq
->queue_id
);
14842 bf_set(lpfc_mbx_cq_create_set_eq_id10
,
14843 &cq_set
->u
.request
, eq
->queue_id
);
14846 bf_set(lpfc_mbx_cq_create_set_eq_id11
,
14847 &cq_set
->u
.request
, eq
->queue_id
);
14850 bf_set(lpfc_mbx_cq_create_set_eq_id12
,
14851 &cq_set
->u
.request
, eq
->queue_id
);
14854 bf_set(lpfc_mbx_cq_create_set_eq_id13
,
14855 &cq_set
->u
.request
, eq
->queue_id
);
14858 bf_set(lpfc_mbx_cq_create_set_eq_id14
,
14859 &cq_set
->u
.request
, eq
->queue_id
);
14862 bf_set(lpfc_mbx_cq_create_set_eq_id15
,
14863 &cq_set
->u
.request
, eq
->queue_id
);
14867 /* link the cq onto the parent eq child list */
14868 list_add_tail(&cq
->list
, &eq
->child_list
);
14869 /* Set up completion queue's type and subtype */
14871 cq
->subtype
= subtype
;
14872 cq
->assoc_qid
= eq
->queue_id
;
14873 cq
->host_index
= 0;
14875 cq
->entry_repost
= LPFC_CQ_REPOST
;
14879 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
14880 memset(dmabuf
->virt
, 0, hw_page_size
);
14881 cnt
= page_idx
+ dmabuf
->buffer_tag
;
14882 cq_set
->u
.request
.page
[cnt
].addr_lo
=
14883 putPaddrLow(dmabuf
->phys
);
14884 cq_set
->u
.request
.page
[cnt
].addr_hi
=
14885 putPaddrHigh(dmabuf
->phys
);
14891 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14893 /* The IOCTL status is embedded in the mailbox subheader. */
14894 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14895 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14896 if (shdr_status
|| shdr_add_status
|| rc
) {
14897 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14898 "3119 CQ_CREATE_SET mailbox failed with "
14899 "status x%x add_status x%x, mbx status x%x\n",
14900 shdr_status
, shdr_add_status
, rc
);
14904 rc
= bf_get(lpfc_mbx_cq_create_set_base_id
, &cq_set
->u
.response
);
14905 if (rc
== 0xFFFF) {
14910 for (idx
= 0; idx
< numcq
; idx
++) {
14912 cq
->queue_id
= rc
+ idx
;
14916 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14921 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
14922 * @phba: HBA structure that indicates port to create a queue on.
14923 * @mq: The queue structure to use to create the mailbox queue.
14924 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
14925 * @cq: The completion queue to associate with this cq.
14927 * This function provides failback (fb) functionality when the
14928 * mq_create_ext fails on older FW generations. It's purpose is identical
14929 * to mq_create_ext otherwise.
14931 * This routine cannot fail as all attributes were previously accessed and
14932 * initialized in mq_create_ext.
14935 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
14936 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
14938 struct lpfc_mbx_mq_create
*mq_create
;
14939 struct lpfc_dmabuf
*dmabuf
;
14942 length
= (sizeof(struct lpfc_mbx_mq_create
) -
14943 sizeof(struct lpfc_sli4_cfg_mhdr
));
14944 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14945 LPFC_MBOX_OPCODE_MQ_CREATE
,
14946 length
, LPFC_SLI4_MBX_EMBED
);
14947 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
14948 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
14950 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
14952 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
14953 switch (mq
->entry_count
) {
14955 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14956 LPFC_MQ_RING_SIZE_16
);
14959 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14960 LPFC_MQ_RING_SIZE_32
);
14963 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14964 LPFC_MQ_RING_SIZE_64
);
14967 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14968 LPFC_MQ_RING_SIZE_128
);
14971 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
14972 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14973 putPaddrLow(dmabuf
->phys
);
14974 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14975 putPaddrHigh(dmabuf
->phys
);
14980 * lpfc_mq_create - Create a mailbox Queue on the HBA
14981 * @phba: HBA structure that indicates port to create a queue on.
14982 * @mq: The queue structure to use to create the mailbox queue.
14983 * @cq: The completion queue to associate with this cq.
14984 * @subtype: The queue's subtype.
14986 * This function creates a mailbox queue, as detailed in @mq, on a port,
14987 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
14989 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14990 * is used to get the entry count and entry size that are necessary to
14991 * determine the number of pages to allocate and use for this queue. This
14992 * function will send the MQ_CREATE mailbox command to the HBA to setup the
14993 * mailbox queue. This function is asynchronous and will wait for the mailbox
14994 * command to finish before continuing.
14996 * On success this function will return a zero. If unable to allocate enough
14997 * memory this function will return -ENOMEM. If the queue create mailbox command
14998 * fails this function will return -ENXIO.
15001 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
15002 struct lpfc_queue
*cq
, uint32_t subtype
)
15004 struct lpfc_mbx_mq_create
*mq_create
;
15005 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
15006 struct lpfc_dmabuf
*dmabuf
;
15007 LPFC_MBOXQ_t
*mbox
;
15008 int rc
, length
, status
= 0;
15009 uint32_t shdr_status
, shdr_add_status
;
15010 union lpfc_sli4_cfg_shdr
*shdr
;
15011 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15013 /* sanity check on queue memory */
15016 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15017 hw_page_size
= SLI4_PAGE_SIZE
;
15019 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15022 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
15023 sizeof(struct lpfc_sli4_cfg_mhdr
));
15024 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15025 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
15026 length
, LPFC_SLI4_MBX_EMBED
);
15028 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
15029 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
15030 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
15031 &mq_create_ext
->u
.request
, mq
->page_count
);
15032 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
15033 &mq_create_ext
->u
.request
, 1);
15034 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
15035 &mq_create_ext
->u
.request
, 1);
15036 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
15037 &mq_create_ext
->u
.request
, 1);
15038 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
15039 &mq_create_ext
->u
.request
, 1);
15040 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
15041 &mq_create_ext
->u
.request
, 1);
15042 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
15043 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15044 phba
->sli4_hba
.pc_sli4_params
.mqv
);
15045 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
15046 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
15049 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
15051 switch (mq
->entry_count
) {
15053 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15054 "0362 Unsupported MQ count. (%d)\n",
15056 if (mq
->entry_count
< 16) {
15060 /* otherwise default to smallest count (drop through) */
15062 bf_set(lpfc_mq_context_ring_size
,
15063 &mq_create_ext
->u
.request
.context
,
15064 LPFC_MQ_RING_SIZE_16
);
15067 bf_set(lpfc_mq_context_ring_size
,
15068 &mq_create_ext
->u
.request
.context
,
15069 LPFC_MQ_RING_SIZE_32
);
15072 bf_set(lpfc_mq_context_ring_size
,
15073 &mq_create_ext
->u
.request
.context
,
15074 LPFC_MQ_RING_SIZE_64
);
15077 bf_set(lpfc_mq_context_ring_size
,
15078 &mq_create_ext
->u
.request
.context
,
15079 LPFC_MQ_RING_SIZE_128
);
15082 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
15083 memset(dmabuf
->virt
, 0, hw_page_size
);
15084 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15085 putPaddrLow(dmabuf
->phys
);
15086 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15087 putPaddrHigh(dmabuf
->phys
);
15089 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15090 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
15091 &mq_create_ext
->u
.response
);
15092 if (rc
!= MBX_SUCCESS
) {
15093 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15094 "2795 MQ_CREATE_EXT failed with "
15095 "status x%x. Failback to MQ_CREATE.\n",
15097 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
15098 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
15099 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15100 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
15101 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
15102 &mq_create
->u
.response
);
15105 /* The IOCTL status is embedded in the mailbox subheader. */
15106 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15107 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15108 if (shdr_status
|| shdr_add_status
|| rc
) {
15109 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15110 "2502 MQ_CREATE mailbox failed with "
15111 "status x%x add_status x%x, mbx status x%x\n",
15112 shdr_status
, shdr_add_status
, rc
);
15116 if (mq
->queue_id
== 0xFFFF) {
15120 mq
->type
= LPFC_MQ
;
15121 mq
->assoc_qid
= cq
->queue_id
;
15122 mq
->subtype
= subtype
;
15123 mq
->host_index
= 0;
15125 mq
->entry_repost
= LPFC_MQ_REPOST
;
15127 /* link the mq onto the parent cq child list */
15128 list_add_tail(&mq
->list
, &cq
->child_list
);
15130 mempool_free(mbox
, phba
->mbox_mem_pool
);
15135 * lpfc_wq_create - Create a Work Queue on the HBA
15136 * @phba: HBA structure that indicates port to create a queue on.
15137 * @wq: The queue structure to use to create the work queue.
15138 * @cq: The completion queue to bind this work queue to.
15139 * @subtype: The subtype of the work queue indicating its functionality.
15141 * This function creates a work queue, as detailed in @wq, on a port, described
15142 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
15144 * The @phba struct is used to send mailbox command to HBA. The @wq struct
15145 * is used to get the entry count and entry size that are necessary to
15146 * determine the number of pages to allocate and use for this queue. The @cq
15147 * is used to indicate which completion queue to bind this work queue to. This
15148 * function will send the WQ_CREATE mailbox command to the HBA to setup the
15149 * work queue. This function is asynchronous and will wait for the mailbox
15150 * command to finish before continuing.
15152 * On success this function will return a zero. If unable to allocate enough
15153 * memory this function will return -ENOMEM. If the queue create mailbox command
15154 * fails this function will return -ENXIO.
15157 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
15158 struct lpfc_queue
*cq
, uint32_t subtype
)
15160 struct lpfc_mbx_wq_create
*wq_create
;
15161 struct lpfc_dmabuf
*dmabuf
;
15162 LPFC_MBOXQ_t
*mbox
;
15163 int rc
, length
, status
= 0;
15164 uint32_t shdr_status
, shdr_add_status
;
15165 union lpfc_sli4_cfg_shdr
*shdr
;
15166 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15167 struct dma_address
*page
;
15168 void __iomem
*bar_memmap_p
;
15169 uint32_t db_offset
;
15170 uint16_t pci_barset
;
15171 uint8_t dpp_barset
;
15172 uint32_t dpp_offset
;
15173 unsigned long pg_addr
;
15174 uint8_t wq_create_version
;
15176 /* sanity check on queue memory */
15179 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15180 hw_page_size
= wq
->page_size
;
15182 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15185 length
= (sizeof(struct lpfc_mbx_wq_create
) -
15186 sizeof(struct lpfc_sli4_cfg_mhdr
));
15187 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15188 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
15189 length
, LPFC_SLI4_MBX_EMBED
);
15190 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
15191 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
15192 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
15194 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
15197 /* wqv is the earliest version supported, NOT the latest */
15198 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15199 phba
->sli4_hba
.pc_sli4_params
.wqv
);
15201 if ((phba
->sli4_hba
.pc_sli4_params
.wqsize
& LPFC_WQ_SZ128_SUPPORT
) ||
15202 (wq
->page_size
> SLI4_PAGE_SIZE
))
15203 wq_create_version
= LPFC_Q_CREATE_VERSION_1
;
15205 wq_create_version
= LPFC_Q_CREATE_VERSION_0
;
15208 if (phba
->sli4_hba
.pc_sli4_params
.wqsize
& LPFC_WQ_SZ128_SUPPORT
)
15209 wq_create_version
= LPFC_Q_CREATE_VERSION_1
;
15211 wq_create_version
= LPFC_Q_CREATE_VERSION_0
;
15213 switch (wq_create_version
) {
15214 case LPFC_Q_CREATE_VERSION_1
:
15215 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
15217 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15218 LPFC_Q_CREATE_VERSION_1
);
15220 switch (wq
->entry_size
) {
15223 bf_set(lpfc_mbx_wq_create_wqe_size
,
15224 &wq_create
->u
.request_1
,
15225 LPFC_WQ_WQE_SIZE_64
);
15228 bf_set(lpfc_mbx_wq_create_wqe_size
,
15229 &wq_create
->u
.request_1
,
15230 LPFC_WQ_WQE_SIZE_128
);
15233 /* Request DPP by default */
15234 bf_set(lpfc_mbx_wq_create_dpp_req
, &wq_create
->u
.request_1
, 1);
15235 bf_set(lpfc_mbx_wq_create_page_size
,
15236 &wq_create
->u
.request_1
,
15237 (wq
->page_size
/ SLI4_PAGE_SIZE
));
15238 page
= wq_create
->u
.request_1
.page
;
15241 page
= wq_create
->u
.request
.page
;
15245 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
15246 memset(dmabuf
->virt
, 0, hw_page_size
);
15247 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
15248 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
15251 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15252 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
15254 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15255 /* The IOCTL status is embedded in the mailbox subheader. */
15256 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15257 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15258 if (shdr_status
|| shdr_add_status
|| rc
) {
15259 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15260 "2503 WQ_CREATE mailbox failed with "
15261 "status x%x add_status x%x, mbx status x%x\n",
15262 shdr_status
, shdr_add_status
, rc
);
15267 if (wq_create_version
== LPFC_Q_CREATE_VERSION_0
)
15268 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
,
15269 &wq_create
->u
.response
);
15271 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_v1_q_id
,
15272 &wq_create
->u
.response_1
);
15274 if (wq
->queue_id
== 0xFFFF) {
15279 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
15280 if (wq_create_version
== LPFC_Q_CREATE_VERSION_0
) {
15281 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
15282 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
15283 &wq_create
->u
.response
);
15284 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
15285 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
15286 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15287 "3265 WQ[%d] doorbell format "
15288 "not supported: x%x\n",
15289 wq
->queue_id
, wq
->db_format
);
15293 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
15294 &wq_create
->u
.response
);
15295 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
,
15297 if (!bar_memmap_p
) {
15298 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15299 "3263 WQ[%d] failed to memmap "
15300 "pci barset:x%x\n",
15301 wq
->queue_id
, pci_barset
);
15305 db_offset
= wq_create
->u
.response
.doorbell_offset
;
15306 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
15307 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
15308 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15309 "3252 WQ[%d] doorbell offset "
15310 "not supported: x%x\n",
15311 wq
->queue_id
, db_offset
);
15315 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15316 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15317 "3264 WQ[%d]: barset:x%x, offset:x%x, "
15318 "format:x%x\n", wq
->queue_id
,
15319 pci_barset
, db_offset
, wq
->db_format
);
15321 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
15323 /* Check if DPP was honored by the firmware */
15324 wq
->dpp_enable
= bf_get(lpfc_mbx_wq_create_dpp_rsp
,
15325 &wq_create
->u
.response_1
);
15326 if (wq
->dpp_enable
) {
15327 pci_barset
= bf_get(lpfc_mbx_wq_create_v1_bar_set
,
15328 &wq_create
->u
.response_1
);
15329 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
,
15331 if (!bar_memmap_p
) {
15332 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15333 "3267 WQ[%d] failed to memmap "
15334 "pci barset:x%x\n",
15335 wq
->queue_id
, pci_barset
);
15339 db_offset
= wq_create
->u
.response_1
.doorbell_offset
;
15340 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15341 wq
->dpp_id
= bf_get(lpfc_mbx_wq_create_dpp_id
,
15342 &wq_create
->u
.response_1
);
15343 dpp_barset
= bf_get(lpfc_mbx_wq_create_dpp_bar
,
15344 &wq_create
->u
.response_1
);
15345 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
,
15347 if (!bar_memmap_p
) {
15348 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15349 "3268 WQ[%d] failed to memmap "
15350 "pci barset:x%x\n",
15351 wq
->queue_id
, dpp_barset
);
15355 dpp_offset
= wq_create
->u
.response_1
.dpp_offset
;
15356 wq
->dpp_regaddr
= bar_memmap_p
+ dpp_offset
;
15357 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15358 "3271 WQ[%d]: barset:x%x, offset:x%x, "
15359 "dpp_id:x%x dpp_barset:x%x "
15360 "dpp_offset:x%x\n",
15361 wq
->queue_id
, pci_barset
, db_offset
,
15362 wq
->dpp_id
, dpp_barset
, dpp_offset
);
15364 /* Enable combined writes for DPP aperture */
15365 pg_addr
= (unsigned long)(wq
->dpp_regaddr
) & PAGE_MASK
;
15367 rc
= set_memory_wc(pg_addr
, 1);
15369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15370 "3272 Cannot setup Combined "
15371 "Write on WQ[%d] - disable DPP\n",
15373 phba
->cfg_enable_dpp
= 0;
15376 phba
->cfg_enable_dpp
= 0;
15379 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
15381 wq
->pring
= kzalloc(sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
15382 if (wq
->pring
== NULL
) {
15386 wq
->type
= LPFC_WQ
;
15387 wq
->assoc_qid
= cq
->queue_id
;
15388 wq
->subtype
= subtype
;
15389 wq
->host_index
= 0;
15391 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
15393 /* link the wq onto the parent cq child list */
15394 list_add_tail(&wq
->list
, &cq
->child_list
);
15396 mempool_free(mbox
, phba
->mbox_mem_pool
);
15401 * lpfc_rq_create - Create a Receive Queue on the HBA
15402 * @phba: HBA structure that indicates port to create a queue on.
15403 * @hrq: The queue structure to use to create the header receive queue.
15404 * @drq: The queue structure to use to create the data receive queue.
15405 * @cq: The completion queue to bind this work queue to.
15407 * This function creates a receive buffer queue pair , as detailed in @hrq and
15408 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15411 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15412 * struct is used to get the entry count that is necessary to determine the
15413 * number of pages to use for this queue. The @cq is used to indicate which
15414 * completion queue to bind received buffers that are posted to these queues to.
15415 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15416 * receive queue pair. This function is asynchronous and will wait for the
15417 * mailbox command to finish before continuing.
15419 * On success this function will return a zero. If unable to allocate enough
15420 * memory this function will return -ENOMEM. If the queue create mailbox command
15421 * fails this function will return -ENXIO.
15424 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
15425 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
15427 struct lpfc_mbx_rq_create
*rq_create
;
15428 struct lpfc_dmabuf
*dmabuf
;
15429 LPFC_MBOXQ_t
*mbox
;
15430 int rc
, length
, status
= 0;
15431 uint32_t shdr_status
, shdr_add_status
;
15432 union lpfc_sli4_cfg_shdr
*shdr
;
15433 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15434 void __iomem
*bar_memmap_p
;
15435 uint32_t db_offset
;
15436 uint16_t pci_barset
;
15438 /* sanity check on queue memory */
15439 if (!hrq
|| !drq
|| !cq
)
15441 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15442 hw_page_size
= SLI4_PAGE_SIZE
;
15444 if (hrq
->entry_count
!= drq
->entry_count
)
15446 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15449 length
= (sizeof(struct lpfc_mbx_rq_create
) -
15450 sizeof(struct lpfc_sli4_cfg_mhdr
));
15451 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15452 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
15453 length
, LPFC_SLI4_MBX_EMBED
);
15454 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
15455 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
15456 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15457 phba
->sli4_hba
.pc_sli4_params
.rqv
);
15458 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
15459 bf_set(lpfc_rq_context_rqe_count_1
,
15460 &rq_create
->u
.request
.context
,
15462 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
15463 bf_set(lpfc_rq_context_rqe_size
,
15464 &rq_create
->u
.request
.context
,
15466 bf_set(lpfc_rq_context_page_size
,
15467 &rq_create
->u
.request
.context
,
15468 LPFC_RQ_PAGE_SIZE_4096
);
15470 switch (hrq
->entry_count
) {
15472 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15473 "2535 Unsupported RQ count. (%d)\n",
15475 if (hrq
->entry_count
< 512) {
15479 /* otherwise default to smallest count (drop through) */
15481 bf_set(lpfc_rq_context_rqe_count
,
15482 &rq_create
->u
.request
.context
,
15483 LPFC_RQ_RING_SIZE_512
);
15486 bf_set(lpfc_rq_context_rqe_count
,
15487 &rq_create
->u
.request
.context
,
15488 LPFC_RQ_RING_SIZE_1024
);
15491 bf_set(lpfc_rq_context_rqe_count
,
15492 &rq_create
->u
.request
.context
,
15493 LPFC_RQ_RING_SIZE_2048
);
15496 bf_set(lpfc_rq_context_rqe_count
,
15497 &rq_create
->u
.request
.context
,
15498 LPFC_RQ_RING_SIZE_4096
);
15501 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
15502 LPFC_HDR_BUF_SIZE
);
15504 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
15506 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
15508 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
15509 memset(dmabuf
->virt
, 0, hw_page_size
);
15510 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15511 putPaddrLow(dmabuf
->phys
);
15512 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15513 putPaddrHigh(dmabuf
->phys
);
15515 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15516 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
15518 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15519 /* The IOCTL status is embedded in the mailbox subheader. */
15520 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15521 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15522 if (shdr_status
|| shdr_add_status
|| rc
) {
15523 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15524 "2504 RQ_CREATE mailbox failed with "
15525 "status x%x add_status x%x, mbx status x%x\n",
15526 shdr_status
, shdr_add_status
, rc
);
15530 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15531 if (hrq
->queue_id
== 0xFFFF) {
15536 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
15537 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
15538 &rq_create
->u
.response
);
15539 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
15540 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
15541 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15542 "3262 RQ [%d] doorbell format not "
15543 "supported: x%x\n", hrq
->queue_id
,
15549 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
15550 &rq_create
->u
.response
);
15551 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
15552 if (!bar_memmap_p
) {
15553 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15554 "3269 RQ[%d] failed to memmap pci "
15555 "barset:x%x\n", hrq
->queue_id
,
15561 db_offset
= rq_create
->u
.response
.doorbell_offset
;
15562 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
15563 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
15564 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15565 "3270 RQ[%d] doorbell offset not "
15566 "supported: x%x\n", hrq
->queue_id
,
15571 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15572 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15573 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
15574 "format:x%x\n", hrq
->queue_id
, pci_barset
,
15575 db_offset
, hrq
->db_format
);
15577 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
15578 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15580 hrq
->type
= LPFC_HRQ
;
15581 hrq
->assoc_qid
= cq
->queue_id
;
15582 hrq
->subtype
= subtype
;
15583 hrq
->host_index
= 0;
15584 hrq
->hba_index
= 0;
15585 hrq
->entry_repost
= LPFC_RQ_REPOST
;
15587 /* now create the data queue */
15588 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15589 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
15590 length
, LPFC_SLI4_MBX_EMBED
);
15591 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15592 phba
->sli4_hba
.pc_sli4_params
.rqv
);
15593 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
15594 bf_set(lpfc_rq_context_rqe_count_1
,
15595 &rq_create
->u
.request
.context
, hrq
->entry_count
);
15596 if (subtype
== LPFC_NVMET
)
15597 rq_create
->u
.request
.context
.buffer_size
=
15598 LPFC_NVMET_DATA_BUF_SIZE
;
15600 rq_create
->u
.request
.context
.buffer_size
=
15601 LPFC_DATA_BUF_SIZE
;
15602 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
15604 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
15605 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
15607 switch (drq
->entry_count
) {
15609 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15610 "2536 Unsupported RQ count. (%d)\n",
15612 if (drq
->entry_count
< 512) {
15616 /* otherwise default to smallest count (drop through) */
15618 bf_set(lpfc_rq_context_rqe_count
,
15619 &rq_create
->u
.request
.context
,
15620 LPFC_RQ_RING_SIZE_512
);
15623 bf_set(lpfc_rq_context_rqe_count
,
15624 &rq_create
->u
.request
.context
,
15625 LPFC_RQ_RING_SIZE_1024
);
15628 bf_set(lpfc_rq_context_rqe_count
,
15629 &rq_create
->u
.request
.context
,
15630 LPFC_RQ_RING_SIZE_2048
);
15633 bf_set(lpfc_rq_context_rqe_count
,
15634 &rq_create
->u
.request
.context
,
15635 LPFC_RQ_RING_SIZE_4096
);
15638 if (subtype
== LPFC_NVMET
)
15639 bf_set(lpfc_rq_context_buf_size
,
15640 &rq_create
->u
.request
.context
,
15641 LPFC_NVMET_DATA_BUF_SIZE
);
15643 bf_set(lpfc_rq_context_buf_size
,
15644 &rq_create
->u
.request
.context
,
15645 LPFC_DATA_BUF_SIZE
);
15647 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
15649 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
15651 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
15652 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15653 putPaddrLow(dmabuf
->phys
);
15654 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15655 putPaddrHigh(dmabuf
->phys
);
15657 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15658 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
15659 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15660 /* The IOCTL status is embedded in the mailbox subheader. */
15661 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
15662 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15663 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15664 if (shdr_status
|| shdr_add_status
|| rc
) {
15668 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15669 if (drq
->queue_id
== 0xFFFF) {
15673 drq
->type
= LPFC_DRQ
;
15674 drq
->assoc_qid
= cq
->queue_id
;
15675 drq
->subtype
= subtype
;
15676 drq
->host_index
= 0;
15677 drq
->hba_index
= 0;
15678 drq
->entry_repost
= LPFC_RQ_REPOST
;
15680 /* link the header and data RQs onto the parent cq child list */
15681 list_add_tail(&hrq
->list
, &cq
->child_list
);
15682 list_add_tail(&drq
->list
, &cq
->child_list
);
15685 mempool_free(mbox
, phba
->mbox_mem_pool
);
15690 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
15691 * @phba: HBA structure that indicates port to create a queue on.
15692 * @hrqp: The queue structure array to use to create the header receive queues.
15693 * @drqp: The queue structure array to use to create the data receive queues.
15694 * @cqp: The completion queue array to bind these receive queues to.
15696 * This function creates a receive buffer queue pair , as detailed in @hrq and
15697 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15700 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15701 * struct is used to get the entry count that is necessary to determine the
15702 * number of pages to use for this queue. The @cq is used to indicate which
15703 * completion queue to bind received buffers that are posted to these queues to.
15704 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15705 * receive queue pair. This function is asynchronous and will wait for the
15706 * mailbox command to finish before continuing.
15708 * On success this function will return a zero. If unable to allocate enough
15709 * memory this function will return -ENOMEM. If the queue create mailbox command
15710 * fails this function will return -ENXIO.
15713 lpfc_mrq_create(struct lpfc_hba
*phba
, struct lpfc_queue
**hrqp
,
15714 struct lpfc_queue
**drqp
, struct lpfc_queue
**cqp
,
15717 struct lpfc_queue
*hrq
, *drq
, *cq
;
15718 struct lpfc_mbx_rq_create_v2
*rq_create
;
15719 struct lpfc_dmabuf
*dmabuf
;
15720 LPFC_MBOXQ_t
*mbox
;
15721 int rc
, length
, alloclen
, status
= 0;
15722 int cnt
, idx
, numrq
, page_idx
= 0;
15723 uint32_t shdr_status
, shdr_add_status
;
15724 union lpfc_sli4_cfg_shdr
*shdr
;
15725 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15727 numrq
= phba
->cfg_nvmet_mrq
;
15728 /* sanity check on array memory */
15729 if (!hrqp
|| !drqp
|| !cqp
|| !numrq
)
15731 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15732 hw_page_size
= SLI4_PAGE_SIZE
;
15734 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15738 length
= sizeof(struct lpfc_mbx_rq_create_v2
);
15739 length
+= ((2 * numrq
* hrqp
[0]->page_count
) *
15740 sizeof(struct dma_address
));
15742 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15743 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
, length
,
15744 LPFC_SLI4_MBX_NEMBED
);
15745 if (alloclen
< length
) {
15746 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15747 "3099 Allocated DMA memory size (%d) is "
15748 "less than the requested DMA memory size "
15749 "(%d)\n", alloclen
, length
);
15756 rq_create
= mbox
->sge_array
->addr
[0];
15757 shdr
= (union lpfc_sli4_cfg_shdr
*)&rq_create
->cfg_shdr
;
15759 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_Q_CREATE_VERSION_2
);
15762 for (idx
= 0; idx
< numrq
; idx
++) {
15767 /* sanity check on queue memory */
15768 if (!hrq
|| !drq
|| !cq
) {
15773 if (hrq
->entry_count
!= drq
->entry_count
) {
15779 bf_set(lpfc_mbx_rq_create_num_pages
,
15780 &rq_create
->u
.request
,
15782 bf_set(lpfc_mbx_rq_create_rq_cnt
,
15783 &rq_create
->u
.request
, (numrq
* 2));
15784 bf_set(lpfc_mbx_rq_create_dnb
, &rq_create
->u
.request
,
15786 bf_set(lpfc_rq_context_base_cq
,
15787 &rq_create
->u
.request
.context
,
15789 bf_set(lpfc_rq_context_data_size
,
15790 &rq_create
->u
.request
.context
,
15791 LPFC_NVMET_DATA_BUF_SIZE
);
15792 bf_set(lpfc_rq_context_hdr_size
,
15793 &rq_create
->u
.request
.context
,
15794 LPFC_HDR_BUF_SIZE
);
15795 bf_set(lpfc_rq_context_rqe_count_1
,
15796 &rq_create
->u
.request
.context
,
15798 bf_set(lpfc_rq_context_rqe_size
,
15799 &rq_create
->u
.request
.context
,
15801 bf_set(lpfc_rq_context_page_size
,
15802 &rq_create
->u
.request
.context
,
15803 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
15806 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
15807 memset(dmabuf
->virt
, 0, hw_page_size
);
15808 cnt
= page_idx
+ dmabuf
->buffer_tag
;
15809 rq_create
->u
.request
.page
[cnt
].addr_lo
=
15810 putPaddrLow(dmabuf
->phys
);
15811 rq_create
->u
.request
.page
[cnt
].addr_hi
=
15812 putPaddrHigh(dmabuf
->phys
);
15818 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
15819 memset(dmabuf
->virt
, 0, hw_page_size
);
15820 cnt
= page_idx
+ dmabuf
->buffer_tag
;
15821 rq_create
->u
.request
.page
[cnt
].addr_lo
=
15822 putPaddrLow(dmabuf
->phys
);
15823 rq_create
->u
.request
.page
[cnt
].addr_hi
=
15824 putPaddrHigh(dmabuf
->phys
);
15829 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
15830 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15831 hrq
->type
= LPFC_HRQ
;
15832 hrq
->assoc_qid
= cq
->queue_id
;
15833 hrq
->subtype
= subtype
;
15834 hrq
->host_index
= 0;
15835 hrq
->hba_index
= 0;
15836 hrq
->entry_repost
= LPFC_RQ_REPOST
;
15838 drq
->db_format
= LPFC_DB_RING_FORMAT
;
15839 drq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15840 drq
->type
= LPFC_DRQ
;
15841 drq
->assoc_qid
= cq
->queue_id
;
15842 drq
->subtype
= subtype
;
15843 drq
->host_index
= 0;
15844 drq
->hba_index
= 0;
15845 drq
->entry_repost
= LPFC_RQ_REPOST
;
15847 list_add_tail(&hrq
->list
, &cq
->child_list
);
15848 list_add_tail(&drq
->list
, &cq
->child_list
);
15851 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15852 /* The IOCTL status is embedded in the mailbox subheader. */
15853 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15854 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15855 if (shdr_status
|| shdr_add_status
|| rc
) {
15856 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15857 "3120 RQ_CREATE mailbox failed with "
15858 "status x%x add_status x%x, mbx status x%x\n",
15859 shdr_status
, shdr_add_status
, rc
);
15863 rc
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15864 if (rc
== 0xFFFF) {
15869 /* Initialize all RQs with associated queue id */
15870 for (idx
= 0; idx
< numrq
; idx
++) {
15872 hrq
->queue_id
= rc
+ (2 * idx
);
15874 drq
->queue_id
= rc
+ (2 * idx
) + 1;
15878 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
15883 * lpfc_eq_destroy - Destroy an event Queue on the HBA
15884 * @eq: The queue structure associated with the queue to destroy.
15886 * This function destroys a queue, as detailed in @eq by sending an mailbox
15887 * command, specific to the type of queue, to the HBA.
15889 * The @eq struct is used to get the queue ID of the queue to destroy.
15891 * On success this function will return a zero. If the queue destroy mailbox
15892 * command fails this function will return -ENXIO.
15895 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
15897 LPFC_MBOXQ_t
*mbox
;
15898 int rc
, length
, status
= 0;
15899 uint32_t shdr_status
, shdr_add_status
;
15900 union lpfc_sli4_cfg_shdr
*shdr
;
15902 /* sanity check on queue memory */
15905 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15908 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
15909 sizeof(struct lpfc_sli4_cfg_mhdr
));
15910 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15911 LPFC_MBOX_OPCODE_EQ_DESTROY
,
15912 length
, LPFC_SLI4_MBX_EMBED
);
15913 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
15915 mbox
->vport
= eq
->phba
->pport
;
15916 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15918 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
15919 /* The IOCTL status is embedded in the mailbox subheader. */
15920 shdr
= (union lpfc_sli4_cfg_shdr
*)
15921 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
15922 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15923 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15924 if (shdr_status
|| shdr_add_status
|| rc
) {
15925 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15926 "2505 EQ_DESTROY mailbox failed with "
15927 "status x%x add_status x%x, mbx status x%x\n",
15928 shdr_status
, shdr_add_status
, rc
);
15932 /* Remove eq from any list */
15933 list_del_init(&eq
->list
);
15934 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
15939 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
15940 * @cq: The queue structure associated with the queue to destroy.
15942 * This function destroys a queue, as detailed in @cq by sending an mailbox
15943 * command, specific to the type of queue, to the HBA.
15945 * The @cq struct is used to get the queue ID of the queue to destroy.
15947 * On success this function will return a zero. If the queue destroy mailbox
15948 * command fails this function will return -ENXIO.
15951 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
15953 LPFC_MBOXQ_t
*mbox
;
15954 int rc
, length
, status
= 0;
15955 uint32_t shdr_status
, shdr_add_status
;
15956 union lpfc_sli4_cfg_shdr
*shdr
;
15958 /* sanity check on queue memory */
15961 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15964 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
15965 sizeof(struct lpfc_sli4_cfg_mhdr
));
15966 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15967 LPFC_MBOX_OPCODE_CQ_DESTROY
,
15968 length
, LPFC_SLI4_MBX_EMBED
);
15969 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
15971 mbox
->vport
= cq
->phba
->pport
;
15972 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15973 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
15974 /* The IOCTL status is embedded in the mailbox subheader. */
15975 shdr
= (union lpfc_sli4_cfg_shdr
*)
15976 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
15977 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15978 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15979 if (shdr_status
|| shdr_add_status
|| rc
) {
15980 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15981 "2506 CQ_DESTROY mailbox failed with "
15982 "status x%x add_status x%x, mbx status x%x\n",
15983 shdr_status
, shdr_add_status
, rc
);
15986 /* Remove cq from any list */
15987 list_del_init(&cq
->list
);
15988 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
15993 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
15994 * @qm: The queue structure associated with the queue to destroy.
15996 * This function destroys a queue, as detailed in @mq by sending an mailbox
15997 * command, specific to the type of queue, to the HBA.
15999 * The @mq struct is used to get the queue ID of the queue to destroy.
16001 * On success this function will return a zero. If the queue destroy mailbox
16002 * command fails this function will return -ENXIO.
16005 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
16007 LPFC_MBOXQ_t
*mbox
;
16008 int rc
, length
, status
= 0;
16009 uint32_t shdr_status
, shdr_add_status
;
16010 union lpfc_sli4_cfg_shdr
*shdr
;
16012 /* sanity check on queue memory */
16015 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
16018 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
16019 sizeof(struct lpfc_sli4_cfg_mhdr
));
16020 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
16021 LPFC_MBOX_OPCODE_MQ_DESTROY
,
16022 length
, LPFC_SLI4_MBX_EMBED
);
16023 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
16025 mbox
->vport
= mq
->phba
->pport
;
16026 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16027 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
16028 /* The IOCTL status is embedded in the mailbox subheader. */
16029 shdr
= (union lpfc_sli4_cfg_shdr
*)
16030 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
16031 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16032 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16033 if (shdr_status
|| shdr_add_status
|| rc
) {
16034 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16035 "2507 MQ_DESTROY mailbox failed with "
16036 "status x%x add_status x%x, mbx status x%x\n",
16037 shdr_status
, shdr_add_status
, rc
);
16040 /* Remove mq from any list */
16041 list_del_init(&mq
->list
);
16042 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
16047 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
16048 * @wq: The queue structure associated with the queue to destroy.
16050 * This function destroys a queue, as detailed in @wq by sending an mailbox
16051 * command, specific to the type of queue, to the HBA.
16053 * The @wq struct is used to get the queue ID of the queue to destroy.
16055 * On success this function will return a zero. If the queue destroy mailbox
16056 * command fails this function will return -ENXIO.
16059 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
16061 LPFC_MBOXQ_t
*mbox
;
16062 int rc
, length
, status
= 0;
16063 uint32_t shdr_status
, shdr_add_status
;
16064 union lpfc_sli4_cfg_shdr
*shdr
;
16066 /* sanity check on queue memory */
16069 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
16072 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
16073 sizeof(struct lpfc_sli4_cfg_mhdr
));
16074 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16075 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
16076 length
, LPFC_SLI4_MBX_EMBED
);
16077 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
16079 mbox
->vport
= wq
->phba
->pport
;
16080 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16081 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
16082 shdr
= (union lpfc_sli4_cfg_shdr
*)
16083 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
16084 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16085 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16086 if (shdr_status
|| shdr_add_status
|| rc
) {
16087 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16088 "2508 WQ_DESTROY mailbox failed with "
16089 "status x%x add_status x%x, mbx status x%x\n",
16090 shdr_status
, shdr_add_status
, rc
);
16093 /* Remove wq from any list */
16094 list_del_init(&wq
->list
);
16097 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
16102 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
16103 * @rq: The queue structure associated with the queue to destroy.
16105 * This function destroys a queue, as detailed in @rq by sending an mailbox
16106 * command, specific to the type of queue, to the HBA.
16108 * The @rq struct is used to get the queue ID of the queue to destroy.
16110 * On success this function will return a zero. If the queue destroy mailbox
16111 * command fails this function will return -ENXIO.
16114 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
16115 struct lpfc_queue
*drq
)
16117 LPFC_MBOXQ_t
*mbox
;
16118 int rc
, length
, status
= 0;
16119 uint32_t shdr_status
, shdr_add_status
;
16120 union lpfc_sli4_cfg_shdr
*shdr
;
16122 /* sanity check on queue memory */
16125 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
16128 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
16129 sizeof(struct lpfc_sli4_cfg_mhdr
));
16130 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16131 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
16132 length
, LPFC_SLI4_MBX_EMBED
);
16133 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
16135 mbox
->vport
= hrq
->phba
->pport
;
16136 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16137 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
16138 /* The IOCTL status is embedded in the mailbox subheader. */
16139 shdr
= (union lpfc_sli4_cfg_shdr
*)
16140 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
16141 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16142 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16143 if (shdr_status
|| shdr_add_status
|| rc
) {
16144 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16145 "2509 RQ_DESTROY mailbox failed with "
16146 "status x%x add_status x%x, mbx status x%x\n",
16147 shdr_status
, shdr_add_status
, rc
);
16148 if (rc
!= MBX_TIMEOUT
)
16149 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
16152 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
16154 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
16155 shdr
= (union lpfc_sli4_cfg_shdr
*)
16156 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
16157 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16158 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16159 if (shdr_status
|| shdr_add_status
|| rc
) {
16160 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16161 "2510 RQ_DESTROY mailbox failed with "
16162 "status x%x add_status x%x, mbx status x%x\n",
16163 shdr_status
, shdr_add_status
, rc
);
16166 list_del_init(&hrq
->list
);
16167 list_del_init(&drq
->list
);
16168 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
16173 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
16174 * @phba: The virtual port for which this call being executed.
16175 * @pdma_phys_addr0: Physical address of the 1st SGL page.
16176 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
16177 * @xritag: the xritag that ties this io to the SGL pages.
16179 * This routine will post the sgl pages for the IO that has the xritag
16180 * that is in the iocbq structure. The xritag is assigned during iocbq
16181 * creation and persists for as long as the driver is loaded.
16182 * if the caller has fewer than 256 scatter gather segments to map then
16183 * pdma_phys_addr1 should be 0.
16184 * If the caller needs to map more than 256 scatter gather segment then
16185 * pdma_phys_addr1 should be a valid physical address.
16186 * physical address for SGLs must be 64 byte aligned.
16187 * If you are going to map 2 SGL's then the first one must have 256 entries
16188 * the second sgl can have between 1 and 256 entries.
16192 * -ENXIO, -ENOMEM - Failure
16195 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
16196 dma_addr_t pdma_phys_addr0
,
16197 dma_addr_t pdma_phys_addr1
,
16200 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
16201 LPFC_MBOXQ_t
*mbox
;
16203 uint32_t shdr_status
, shdr_add_status
;
16205 union lpfc_sli4_cfg_shdr
*shdr
;
16207 if (xritag
== NO_XRI
) {
16208 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16209 "0364 Invalid param:\n");
16213 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16217 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16218 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
16219 sizeof(struct lpfc_mbx_post_sgl_pages
) -
16220 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
16222 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
16223 &mbox
->u
.mqe
.un
.post_sgl_pages
;
16224 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
16225 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
16227 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
16228 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
16229 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
16230 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
16232 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
16233 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
16234 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
16235 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
16236 if (!phba
->sli4_hba
.intr_enable
)
16237 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16239 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16240 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16242 /* The IOCTL status is embedded in the mailbox subheader. */
16243 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
16244 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16245 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16246 if (rc
!= MBX_TIMEOUT
)
16247 mempool_free(mbox
, phba
->mbox_mem_pool
);
16248 if (shdr_status
|| shdr_add_status
|| rc
) {
16249 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16250 "2511 POST_SGL mailbox failed with "
16251 "status x%x add_status x%x, mbx status x%x\n",
16252 shdr_status
, shdr_add_status
, rc
);
16258 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
16259 * @phba: pointer to lpfc hba data structure.
16261 * This routine is invoked to post rpi header templates to the
16262 * HBA consistent with the SLI-4 interface spec. This routine
16263 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
16264 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
16267 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
16268 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
16271 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
16276 * Fetch the next logical xri. Because this index is logical,
16277 * the driver starts at 0 each time.
16279 spin_lock_irq(&phba
->hbalock
);
16280 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
16281 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
16282 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
16283 spin_unlock_irq(&phba
->hbalock
);
16286 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
16287 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
16289 spin_unlock_irq(&phba
->hbalock
);
16294 * lpfc_sli4_free_xri - Release an xri for reuse.
16295 * @phba: pointer to lpfc hba data structure.
16297 * This routine is invoked to release an xri to the pool of
16298 * available rpis maintained by the driver.
16301 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
16303 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
16304 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
16309 * lpfc_sli4_free_xri - Release an xri for reuse.
16310 * @phba: pointer to lpfc hba data structure.
16312 * This routine is invoked to release an xri to the pool of
16313 * available rpis maintained by the driver.
16316 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
16318 spin_lock_irq(&phba
->hbalock
);
16319 __lpfc_sli4_free_xri(phba
, xri
);
16320 spin_unlock_irq(&phba
->hbalock
);
16324 * lpfc_sli4_next_xritag - Get an xritag for the io
16325 * @phba: Pointer to HBA context object.
16327 * This function gets an xritag for the iocb. If there is no unused xritag
16328 * it will return 0xffff.
16329 * The function returns the allocated xritag if successful, else returns zero.
16330 * Zero is not a valid xritag.
16331 * The caller is not required to hold any lock.
16334 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
16336 uint16_t xri_index
;
16338 xri_index
= lpfc_sli4_alloc_xri(phba
);
16339 if (xri_index
== NO_XRI
)
16340 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
16341 "2004 Failed to allocate XRI.last XRITAG is %d"
16342 " Max XRI is %d, Used XRI is %d\n",
16344 phba
->sli4_hba
.max_cfg_param
.max_xri
,
16345 phba
->sli4_hba
.max_cfg_param
.xri_used
);
16350 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
16351 * @phba: pointer to lpfc hba data structure.
16352 * @post_sgl_list: pointer to els sgl entry list.
16353 * @count: number of els sgl entries on the list.
16355 * This routine is invoked to post a block of driver's sgl pages to the
16356 * HBA using non-embedded mailbox command. No Lock is held. This routine
16357 * is only called when the driver is loading and after all IO has been
16361 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
,
16362 struct list_head
*post_sgl_list
,
16365 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
16366 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
16367 struct sgl_page_pairs
*sgl_pg_pairs
;
16369 LPFC_MBOXQ_t
*mbox
;
16370 uint32_t reqlen
, alloclen
, pg_pairs
;
16372 uint16_t xritag_start
= 0;
16374 uint32_t shdr_status
, shdr_add_status
;
16375 union lpfc_sli4_cfg_shdr
*shdr
;
16377 reqlen
= post_cnt
* sizeof(struct sgl_page_pairs
) +
16378 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
16379 if (reqlen
> SLI4_PAGE_SIZE
) {
16380 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16381 "2559 Block sgl registration required DMA "
16382 "size (%d) great than a page\n", reqlen
);
16386 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16390 /* Allocate DMA memory and set up the non-embedded mailbox command */
16391 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16392 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
16393 LPFC_SLI4_MBX_NEMBED
);
16395 if (alloclen
< reqlen
) {
16396 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16397 "0285 Allocated DMA memory size (%d) is "
16398 "less than the requested DMA memory "
16399 "size (%d)\n", alloclen
, reqlen
);
16400 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16403 /* Set up the SGL pages in the non-embedded DMA pages */
16404 viraddr
= mbox
->sge_array
->addr
[0];
16405 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
16406 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
16409 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
16410 /* Set up the sge entry */
16411 sgl_pg_pairs
->sgl_pg0_addr_lo
=
16412 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
16413 sgl_pg_pairs
->sgl_pg0_addr_hi
=
16414 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
16415 sgl_pg_pairs
->sgl_pg1_addr_lo
=
16416 cpu_to_le32(putPaddrLow(0));
16417 sgl_pg_pairs
->sgl_pg1_addr_hi
=
16418 cpu_to_le32(putPaddrHigh(0));
16420 /* Keep the first xritag on the list */
16422 xritag_start
= sglq_entry
->sli4_xritag
;
16427 /* Complete initialization and perform endian conversion. */
16428 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
16429 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, post_cnt
);
16430 sgl
->word0
= cpu_to_le32(sgl
->word0
);
16432 if (!phba
->sli4_hba
.intr_enable
)
16433 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16435 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16436 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16438 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
16439 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16440 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16441 if (rc
!= MBX_TIMEOUT
)
16442 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16443 if (shdr_status
|| shdr_add_status
|| rc
) {
16444 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16445 "2513 POST_SGL_BLOCK mailbox command failed "
16446 "status x%x add_status x%x mbx status x%x\n",
16447 shdr_status
, shdr_add_status
, rc
);
16454 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
16455 * @phba: pointer to lpfc hba data structure.
16456 * @sblist: pointer to scsi buffer list.
16457 * @count: number of scsi buffers on the list.
16459 * This routine is invoked to post a block of @count scsi sgl pages from a
16460 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
16465 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
16466 struct list_head
*sblist
,
16469 struct lpfc_scsi_buf
*psb
;
16470 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
16471 struct sgl_page_pairs
*sgl_pg_pairs
;
16473 LPFC_MBOXQ_t
*mbox
;
16474 uint32_t reqlen
, alloclen
, pg_pairs
;
16476 uint16_t xritag_start
= 0;
16478 uint32_t shdr_status
, shdr_add_status
;
16479 dma_addr_t pdma_phys_bpl1
;
16480 union lpfc_sli4_cfg_shdr
*shdr
;
16482 /* Calculate the requested length of the dma memory */
16483 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
16484 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
16485 if (reqlen
> SLI4_PAGE_SIZE
) {
16486 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
16487 "0217 Block sgl registration required DMA "
16488 "size (%d) great than a page\n", reqlen
);
16491 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16493 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16494 "0283 Failed to allocate mbox cmd memory\n");
16498 /* Allocate DMA memory and set up the non-embedded mailbox command */
16499 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16500 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
16501 LPFC_SLI4_MBX_NEMBED
);
16503 if (alloclen
< reqlen
) {
16504 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16505 "2561 Allocated DMA memory size (%d) is "
16506 "less than the requested DMA memory "
16507 "size (%d)\n", alloclen
, reqlen
);
16508 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16512 /* Get the first SGE entry from the non-embedded DMA memory */
16513 viraddr
= mbox
->sge_array
->addr
[0];
16515 /* Set up the SGL pages in the non-embedded DMA pages */
16516 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
16517 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
16520 list_for_each_entry(psb
, sblist
, list
) {
16521 /* Set up the sge entry */
16522 sgl_pg_pairs
->sgl_pg0_addr_lo
=
16523 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
16524 sgl_pg_pairs
->sgl_pg0_addr_hi
=
16525 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
16526 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
16527 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
16529 pdma_phys_bpl1
= 0;
16530 sgl_pg_pairs
->sgl_pg1_addr_lo
=
16531 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
16532 sgl_pg_pairs
->sgl_pg1_addr_hi
=
16533 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
16534 /* Keep the first xritag on the list */
16536 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
16540 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
16541 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
16542 /* Perform endian conversion if necessary */
16543 sgl
->word0
= cpu_to_le32(sgl
->word0
);
16545 if (!phba
->sli4_hba
.intr_enable
)
16546 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16548 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16549 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16551 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
16552 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16553 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16554 if (rc
!= MBX_TIMEOUT
)
16555 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16556 if (shdr_status
|| shdr_add_status
|| rc
) {
16557 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16558 "2564 POST_SGL_BLOCK mailbox command failed "
16559 "status x%x add_status x%x mbx status x%x\n",
16560 shdr_status
, shdr_add_status
, rc
);
16567 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
16568 * @phba: pointer to lpfc_hba struct that the frame was received on
16569 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16571 * This function checks the fields in the @fc_hdr to see if the FC frame is a
16572 * valid type of frame that the LPFC driver will handle. This function will
16573 * return a zero if the frame is a valid frame or a non zero value when the
16574 * frame does not pass the check.
16577 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
16579 /* make rctl_names static to save stack space */
16580 struct fc_vft_header
*fc_vft_hdr
;
16581 uint32_t *header
= (uint32_t *) fc_hdr
;
16583 #define FC_RCTL_MDS_DIAGS 0xF4
16585 switch (fc_hdr
->fh_r_ctl
) {
16586 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
16587 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
16588 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
16589 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
16590 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
16591 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
16592 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
16593 case FC_RCTL_DD_CMD_STATUS
: /* command status */
16594 case FC_RCTL_ELS_REQ
: /* extended link services request */
16595 case FC_RCTL_ELS_REP
: /* extended link services reply */
16596 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
16597 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
16598 case FC_RCTL_BA_NOP
: /* basic link service NOP */
16599 case FC_RCTL_BA_ABTS
: /* basic link service abort */
16600 case FC_RCTL_BA_RMC
: /* remove connection */
16601 case FC_RCTL_BA_ACC
: /* basic accept */
16602 case FC_RCTL_BA_RJT
: /* basic reject */
16603 case FC_RCTL_BA_PRMT
:
16604 case FC_RCTL_ACK_1
: /* acknowledge_1 */
16605 case FC_RCTL_ACK_0
: /* acknowledge_0 */
16606 case FC_RCTL_P_RJT
: /* port reject */
16607 case FC_RCTL_F_RJT
: /* fabric reject */
16608 case FC_RCTL_P_BSY
: /* port busy */
16609 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
16610 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
16611 case FC_RCTL_LCR
: /* link credit reset */
16612 case FC_RCTL_MDS_DIAGS
: /* MDS Diagnostics */
16613 case FC_RCTL_END
: /* end */
16615 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
16616 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
16617 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
16618 return lpfc_fc_frame_check(phba
, fc_hdr
);
16623 #define FC_TYPE_VENDOR_UNIQUE 0xFF
16625 switch (fc_hdr
->fh_type
) {
16631 case FC_TYPE_VENDOR_UNIQUE
:
16639 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
16640 "2538 Received frame rctl:x%x, type:x%x, "
16641 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
16642 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
,
16643 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
16644 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
16645 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]),
16646 be32_to_cpu(header
[6]));
16649 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
16650 "2539 Dropped frame rctl:x%x type:x%x\n",
16651 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
16656 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
16657 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16659 * This function processes the FC header to retrieve the VFI from the VF
16660 * header, if one exists. This function will return the VFI if one exists
16661 * or 0 if no VSAN Header exists.
16664 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
16666 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
16668 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
16670 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
16674 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
16675 * @phba: Pointer to the HBA structure to search for the vport on
16676 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16677 * @fcfi: The FC Fabric ID that the frame came from
16679 * This function searches the @phba for a vport that matches the content of the
16680 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
16681 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
16682 * returns the matching vport pointer or NULL if unable to match frame to a
16685 static struct lpfc_vport
*
16686 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
16687 uint16_t fcfi
, uint32_t did
)
16689 struct lpfc_vport
**vports
;
16690 struct lpfc_vport
*vport
= NULL
;
16693 if (did
== Fabric_DID
)
16694 return phba
->pport
;
16695 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
16696 !(phba
->link_state
== LPFC_HBA_READY
))
16697 return phba
->pport
;
16699 vports
= lpfc_create_vport_work_array(phba
);
16700 if (vports
!= NULL
) {
16701 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
16702 if (phba
->fcf
.fcfi
== fcfi
&&
16703 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
16704 vports
[i
]->fc_myDID
== did
) {
16710 lpfc_destroy_vport_work_array(phba
, vports
);
16715 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
16716 * @vport: The vport to work on.
16718 * This function updates the receive sequence time stamp for this vport. The
16719 * receive sequence time stamp indicates the time that the last frame of the
16720 * the sequence that has been idle for the longest amount of time was received.
16721 * the driver uses this time stamp to indicate if any received sequences have
16725 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
16727 struct lpfc_dmabuf
*h_buf
;
16728 struct hbq_dmabuf
*dmabuf
= NULL
;
16730 /* get the oldest sequence on the rcv list */
16731 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
16732 struct lpfc_dmabuf
, list
);
16735 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16736 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
16740 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
16741 * @vport: The vport that the received sequences were sent to.
16743 * This function cleans up all outstanding received sequences. This is called
16744 * by the driver when a link event or user action invalidates all the received
16748 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
16750 struct lpfc_dmabuf
*h_buf
, *hnext
;
16751 struct lpfc_dmabuf
*d_buf
, *dnext
;
16752 struct hbq_dmabuf
*dmabuf
= NULL
;
16754 /* start with the oldest sequence on the rcv list */
16755 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
16756 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16757 list_del_init(&dmabuf
->hbuf
.list
);
16758 list_for_each_entry_safe(d_buf
, dnext
,
16759 &dmabuf
->dbuf
.list
, list
) {
16760 list_del_init(&d_buf
->list
);
16761 lpfc_in_buf_free(vport
->phba
, d_buf
);
16763 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
16768 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
16769 * @vport: The vport that the received sequences were sent to.
16771 * This function determines whether any received sequences have timed out by
16772 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
16773 * indicates that there is at least one timed out sequence this routine will
16774 * go through the received sequences one at a time from most inactive to most
16775 * active to determine which ones need to be cleaned up. Once it has determined
16776 * that a sequence needs to be cleaned up it will simply free up the resources
16777 * without sending an abort.
16780 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
16782 struct lpfc_dmabuf
*h_buf
, *hnext
;
16783 struct lpfc_dmabuf
*d_buf
, *dnext
;
16784 struct hbq_dmabuf
*dmabuf
= NULL
;
16785 unsigned long timeout
;
16786 int abort_count
= 0;
16788 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
16789 vport
->rcv_buffer_time_stamp
);
16790 if (list_empty(&vport
->rcv_buffer_list
) ||
16791 time_before(jiffies
, timeout
))
16793 /* start with the oldest sequence on the rcv list */
16794 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
16795 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16796 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
16797 dmabuf
->time_stamp
);
16798 if (time_before(jiffies
, timeout
))
16801 list_del_init(&dmabuf
->hbuf
.list
);
16802 list_for_each_entry_safe(d_buf
, dnext
,
16803 &dmabuf
->dbuf
.list
, list
) {
16804 list_del_init(&d_buf
->list
);
16805 lpfc_in_buf_free(vport
->phba
, d_buf
);
16807 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
16810 lpfc_update_rcv_time_stamp(vport
);
16814 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
16815 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
16817 * This function searches through the existing incomplete sequences that have
16818 * been sent to this @vport. If the frame matches one of the incomplete
16819 * sequences then the dbuf in the @dmabuf is added to the list of frames that
16820 * make up that sequence. If no sequence is found that matches this frame then
16821 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
16822 * This function returns a pointer to the first dmabuf in the sequence list that
16823 * the frame was linked to.
16825 static struct hbq_dmabuf
*
16826 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
16828 struct fc_frame_header
*new_hdr
;
16829 struct fc_frame_header
*temp_hdr
;
16830 struct lpfc_dmabuf
*d_buf
;
16831 struct lpfc_dmabuf
*h_buf
;
16832 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
16833 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
16836 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
16837 dmabuf
->time_stamp
= jiffies
;
16838 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16840 /* Use the hdr_buf to find the sequence that this frame belongs to */
16841 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
16842 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
16843 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
16844 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
16845 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
16847 /* found a pending sequence that matches this frame */
16848 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16853 * This indicates first frame received for this sequence.
16854 * Queue the buffer on the vport's rcv_buffer_list.
16856 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16857 lpfc_update_rcv_time_stamp(vport
);
16860 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
16861 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
16862 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
16863 list_del_init(&seq_dmabuf
->hbuf
.list
);
16864 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16865 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
16866 lpfc_update_rcv_time_stamp(vport
);
16869 /* move this sequence to the tail to indicate a young sequence */
16870 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16871 seq_dmabuf
->time_stamp
= jiffies
;
16872 lpfc_update_rcv_time_stamp(vport
);
16873 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
16874 temp_hdr
= dmabuf
->hbuf
.virt
;
16875 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
16878 /* find the correct place in the sequence to insert this frame */
16879 d_buf
= list_entry(seq_dmabuf
->dbuf
.list
.prev
, typeof(*d_buf
), list
);
16881 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
16882 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
16884 * If the frame's sequence count is greater than the frame on
16885 * the list then insert the frame right after this frame
16887 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
16888 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
16889 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
16894 if (&d_buf
->list
== &seq_dmabuf
->dbuf
.list
)
16896 d_buf
= list_entry(d_buf
->list
.prev
, typeof(*d_buf
), list
);
16905 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
16906 * @vport: pointer to a vitural port
16907 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16909 * This function tries to abort from the partially assembed sequence, described
16910 * by the information from basic abbort @dmabuf. It checks to see whether such
16911 * partially assembled sequence held by the driver. If so, it shall free up all
16912 * the frames from the partially assembled sequence.
16915 * true -- if there is matching partially assembled sequence present and all
16916 * the frames freed with the sequence;
16917 * false -- if there is no matching partially assembled sequence present so
16918 * nothing got aborted in the lower layer driver
16921 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
16922 struct hbq_dmabuf
*dmabuf
)
16924 struct fc_frame_header
*new_hdr
;
16925 struct fc_frame_header
*temp_hdr
;
16926 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
16927 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
16929 /* Use the hdr_buf to find the sequence that matches this frame */
16930 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
16931 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
16932 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16933 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
16934 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
16935 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
16936 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
16937 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
16939 /* found a pending sequence that matches this frame */
16940 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16944 /* Free up all the frames from the partially assembled sequence */
16946 list_for_each_entry_safe(d_buf
, n_buf
,
16947 &seq_dmabuf
->dbuf
.list
, list
) {
16948 list_del_init(&d_buf
->list
);
16949 lpfc_in_buf_free(vport
->phba
, d_buf
);
16957 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
16958 * @vport: pointer to a vitural port
16959 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16961 * This function tries to abort from the assembed sequence from upper level
16962 * protocol, described by the information from basic abbort @dmabuf. It
16963 * checks to see whether such pending context exists at upper level protocol.
16964 * If so, it shall clean up the pending context.
16967 * true -- if there is matching pending context of the sequence cleaned
16969 * false -- if there is no matching pending context of the sequence present
16973 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
16975 struct lpfc_hba
*phba
= vport
->phba
;
16978 /* Accepting abort at ulp with SLI4 only */
16979 if (phba
->sli_rev
< LPFC_SLI_REV4
)
16982 /* Register all caring upper level protocols to attend abort */
16983 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
16991 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
16992 * @phba: Pointer to HBA context object.
16993 * @cmd_iocbq: pointer to the command iocbq structure.
16994 * @rsp_iocbq: pointer to the response iocbq structure.
16996 * This function handles the sequence abort response iocb command complete
16997 * event. It properly releases the memory allocated to the sequence abort
17001 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
17002 struct lpfc_iocbq
*cmd_iocbq
,
17003 struct lpfc_iocbq
*rsp_iocbq
)
17005 struct lpfc_nodelist
*ndlp
;
17008 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
17009 lpfc_nlp_put(ndlp
);
17010 lpfc_nlp_not_used(ndlp
);
17011 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
17014 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
17015 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
17016 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17017 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
17018 rsp_iocbq
->iocb
.ulpStatus
,
17019 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
17023 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
17024 * @phba: Pointer to HBA context object.
17025 * @xri: xri id in transaction.
17027 * This function validates the xri maps to the known range of XRIs allocated an
17028 * used by the driver.
17031 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
17036 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
17037 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
17044 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
17045 * @phba: Pointer to HBA context object.
17046 * @fc_hdr: pointer to a FC frame header.
17048 * This function sends a basic response to a previous unsol sequence abort
17049 * event after aborting the sequence handling.
17052 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
17053 struct fc_frame_header
*fc_hdr
, bool aborted
)
17055 struct lpfc_hba
*phba
= vport
->phba
;
17056 struct lpfc_iocbq
*ctiocb
= NULL
;
17057 struct lpfc_nodelist
*ndlp
;
17058 uint16_t oxid
, rxid
, xri
, lxri
;
17059 uint32_t sid
, fctl
;
17063 if (!lpfc_is_link_up(phba
))
17066 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
17067 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
17068 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
17070 ndlp
= lpfc_findnode_did(vport
, sid
);
17072 ndlp
= lpfc_nlp_init(vport
, sid
);
17074 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
17075 "1268 Failed to allocate ndlp for "
17076 "oxid:x%x SID:x%x\n", oxid
, sid
);
17079 /* Put ndlp onto pport node list */
17080 lpfc_enqueue_node(vport
, ndlp
);
17081 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
17082 /* re-setup ndlp without removing from node list */
17083 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
17085 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
17086 "3275 Failed to active ndlp found "
17087 "for oxid:x%x SID:x%x\n", oxid
, sid
);
17092 /* Allocate buffer for rsp iocb */
17093 ctiocb
= lpfc_sli_get_iocbq(phba
);
17097 /* Extract the F_CTL field from FC_HDR */
17098 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
17100 icmd
= &ctiocb
->iocb
;
17101 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
17102 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
17103 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
17104 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
17105 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
17107 /* Fill in the rest of iocb fields */
17108 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
17109 icmd
->ulpBdeCount
= 0;
17111 icmd
->ulpClass
= CLASS3
;
17112 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
17113 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
17115 ctiocb
->iocb_cmpl
= NULL
;
17116 ctiocb
->vport
= phba
->pport
;
17117 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
17118 ctiocb
->sli4_lxritag
= NO_XRI
;
17119 ctiocb
->sli4_xritag
= NO_XRI
;
17121 if (fctl
& FC_FC_EX_CTX
)
17122 /* Exchange responder sent the abort so we
17128 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
17129 if (lxri
!= NO_XRI
)
17130 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
17131 (xri
== oxid
) ? rxid
: oxid
, 0);
17132 /* For BA_ABTS from exchange responder, if the logical xri with
17133 * the oxid maps to the FCP XRI range, the port no longer has
17134 * that exchange context, send a BLS_RJT. Override the IOCB for
17137 if ((fctl
& FC_FC_EX_CTX
) &&
17138 (lxri
> lpfc_sli4_get_iocb_cnt(phba
))) {
17139 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
17140 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
17141 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
17142 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
17145 /* If BA_ABTS failed to abort a partially assembled receive sequence,
17146 * the driver no longer has that exchange, send a BLS_RJT. Override
17147 * the IOCB for a BA_RJT.
17149 if (aborted
== false) {
17150 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
17151 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
17152 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
17153 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
17156 if (fctl
& FC_FC_EX_CTX
) {
17157 /* ABTS sent by responder to CT exchange, construction
17158 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
17159 * field and RX_ID from ABTS for RX_ID field.
17161 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
17163 /* ABTS sent by initiator to CT exchange, construction
17164 * of BA_ACC will need to allocate a new XRI as for the
17167 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
17169 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
17170 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
17172 /* Xmit CT abts response on exchange <xid> */
17173 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
17174 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
17175 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
17177 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
17178 if (rc
== IOCB_ERROR
) {
17179 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
17180 "2925 Failed to issue CT ABTS RSP x%x on "
17181 "xri x%x, Data x%x\n",
17182 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
17184 lpfc_nlp_put(ndlp
);
17185 ctiocb
->context1
= NULL
;
17186 lpfc_sli_release_iocbq(phba
, ctiocb
);
17191 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
17192 * @vport: Pointer to the vport on which this sequence was received
17193 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17195 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
17196 * receive sequence is only partially assembed by the driver, it shall abort
17197 * the partially assembled frames for the sequence. Otherwise, if the
17198 * unsolicited receive sequence has been completely assembled and passed to
17199 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
17200 * unsolicited sequence has been aborted. After that, it will issue a basic
17201 * accept to accept the abort.
17204 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
17205 struct hbq_dmabuf
*dmabuf
)
17207 struct lpfc_hba
*phba
= vport
->phba
;
17208 struct fc_frame_header fc_hdr
;
17212 /* Make a copy of fc_hdr before the dmabuf being released */
17213 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
17214 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
17216 if (fctl
& FC_FC_EX_CTX
) {
17217 /* ABTS by responder to exchange, no cleanup needed */
17220 /* ABTS by initiator to exchange, need to do cleanup */
17221 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
17222 if (aborted
== false)
17223 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
17225 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17227 if (phba
->nvmet_support
) {
17228 lpfc_nvmet_rcv_unsol_abort(vport
, &fc_hdr
);
17232 /* Respond with BA_ACC or BA_RJT accordingly */
17233 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
17237 * lpfc_seq_complete - Indicates if a sequence is complete
17238 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17240 * This function checks the sequence, starting with the frame described by
17241 * @dmabuf, to see if all the frames associated with this sequence are present.
17242 * the frames associated with this sequence are linked to the @dmabuf using the
17243 * dbuf list. This function looks for two major things. 1) That the first frame
17244 * has a sequence count of zero. 2) There is a frame with last frame of sequence
17245 * set. 3) That there are no holes in the sequence count. The function will
17246 * return 1 when the sequence is complete, otherwise it will return 0.
17249 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
17251 struct fc_frame_header
*hdr
;
17252 struct lpfc_dmabuf
*d_buf
;
17253 struct hbq_dmabuf
*seq_dmabuf
;
17257 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17258 /* make sure first fame of sequence has a sequence count of zero */
17259 if (hdr
->fh_seq_cnt
!= seq_count
)
17261 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
17262 hdr
->fh_f_ctl
[1] << 8 |
17264 /* If last frame of sequence we can return success. */
17265 if (fctl
& FC_FC_END_SEQ
)
17267 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
17268 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17269 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
17270 /* If there is a hole in the sequence count then fail. */
17271 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
17273 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
17274 hdr
->fh_f_ctl
[1] << 8 |
17276 /* If last frame of sequence we can return success. */
17277 if (fctl
& FC_FC_END_SEQ
)
17284 * lpfc_prep_seq - Prep sequence for ULP processing
17285 * @vport: Pointer to the vport on which this sequence was received
17286 * @dmabuf: pointer to a dmabuf that describes the FC sequence
17288 * This function takes a sequence, described by a list of frames, and creates
17289 * a list of iocbq structures to describe the sequence. This iocbq list will be
17290 * used to issue to the generic unsolicited sequence handler. This routine
17291 * returns a pointer to the first iocbq in the list. If the function is unable
17292 * to allocate an iocbq then it throw out the received frames that were not
17293 * able to be described and return a pointer to the first iocbq. If unable to
17294 * allocate any iocbqs (including the first) this function will return NULL.
17296 static struct lpfc_iocbq
*
17297 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
17299 struct hbq_dmabuf
*hbq_buf
;
17300 struct lpfc_dmabuf
*d_buf
, *n_buf
;
17301 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
17302 struct fc_frame_header
*fc_hdr
;
17304 uint32_t len
, tot_len
;
17305 struct ulp_bde64
*pbde
;
17307 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
17308 /* remove from receive buffer list */
17309 list_del_init(&seq_dmabuf
->hbuf
.list
);
17310 lpfc_update_rcv_time_stamp(vport
);
17311 /* get the Remote Port's SID */
17312 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
17314 /* Get an iocbq struct to fill in. */
17315 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
17317 /* Initialize the first IOCB. */
17318 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
17319 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
17320 first_iocbq
->vport
= vport
;
17322 /* Check FC Header to see what TYPE of frame we are rcv'ing */
17323 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
17324 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
17325 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
17326 sli4_did_from_fc_hdr(fc_hdr
);
17327 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
17329 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
17330 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
17331 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
17332 be16_to_cpu(fc_hdr
->fh_ox_id
);
17333 /* iocbq is prepped for internal consumption. Physical vpi. */
17334 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
17335 vport
->phba
->vpi_ids
[vport
->vpi
];
17336 /* put the first buffer into the first IOCBq */
17337 tot_len
= bf_get(lpfc_rcqe_length
,
17338 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17340 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
17341 first_iocbq
->context3
= NULL
;
17342 first_iocbq
->iocb
.ulpBdeCount
= 1;
17343 if (tot_len
> LPFC_DATA_BUF_SIZE
)
17344 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
17345 LPFC_DATA_BUF_SIZE
;
17347 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= tot_len
;
17349 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
17351 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
17353 iocbq
= first_iocbq
;
17355 * Each IOCBq can have two Buffers assigned, so go through the list
17356 * of buffers for this sequence and save two buffers in each IOCBq
17358 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
17360 lpfc_in_buf_free(vport
->phba
, d_buf
);
17363 if (!iocbq
->context3
) {
17364 iocbq
->context3
= d_buf
;
17365 iocbq
->iocb
.ulpBdeCount
++;
17366 /* We need to get the size out of the right CQE */
17367 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17368 len
= bf_get(lpfc_rcqe_length
,
17369 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
17370 pbde
= (struct ulp_bde64
*)
17371 &iocbq
->iocb
.unsli3
.sli3Words
[4];
17372 if (len
> LPFC_DATA_BUF_SIZE
)
17373 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
17375 pbde
->tus
.f
.bdeSize
= len
;
17377 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
17380 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
17383 first_iocbq
->iocb
.ulpStatus
=
17384 IOSTAT_FCP_RSP_ERROR
;
17385 first_iocbq
->iocb
.un
.ulpWord
[4] =
17386 IOERR_NO_RESOURCES
;
17388 lpfc_in_buf_free(vport
->phba
, d_buf
);
17391 /* We need to get the size out of the right CQE */
17392 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17393 len
= bf_get(lpfc_rcqe_length
,
17394 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
17395 iocbq
->context2
= d_buf
;
17396 iocbq
->context3
= NULL
;
17397 iocbq
->iocb
.ulpBdeCount
= 1;
17398 if (len
> LPFC_DATA_BUF_SIZE
)
17399 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
17400 LPFC_DATA_BUF_SIZE
;
17402 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= len
;
17405 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
17407 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
17408 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
17411 return first_iocbq
;
17415 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
17416 struct hbq_dmabuf
*seq_dmabuf
)
17418 struct fc_frame_header
*fc_hdr
;
17419 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
17420 struct lpfc_hba
*phba
= vport
->phba
;
17422 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
17423 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
17425 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17426 "2707 Ring %d handler: Failed to allocate "
17427 "iocb Rctl x%x Type x%x received\n",
17429 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
17432 if (!lpfc_complete_unsol_iocb(phba
,
17433 phba
->sli4_hba
.els_wq
->pring
,
17434 iocbq
, fc_hdr
->fh_r_ctl
,
17436 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17437 "2540 Ring %d handler: unexpected Rctl "
17438 "x%x Type x%x received\n",
17440 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
17442 /* Free iocb created in lpfc_prep_seq */
17443 list_for_each_entry_safe(curr_iocb
, next_iocb
,
17444 &iocbq
->list
, list
) {
17445 list_del_init(&curr_iocb
->list
);
17446 lpfc_sli_release_iocbq(phba
, curr_iocb
);
17448 lpfc_sli_release_iocbq(phba
, iocbq
);
17452 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
17453 struct lpfc_iocbq
*rspiocb
)
17455 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
;
17457 if (pcmd
&& pcmd
->virt
)
17458 dma_pool_free(phba
->lpfc_drb_pool
, pcmd
->virt
, pcmd
->phys
);
17460 lpfc_sli_release_iocbq(phba
, cmdiocb
);
17464 lpfc_sli4_handle_mds_loopback(struct lpfc_vport
*vport
,
17465 struct hbq_dmabuf
*dmabuf
)
17467 struct fc_frame_header
*fc_hdr
;
17468 struct lpfc_hba
*phba
= vport
->phba
;
17469 struct lpfc_iocbq
*iocbq
= NULL
;
17470 union lpfc_wqe
*wqe
;
17471 struct lpfc_dmabuf
*pcmd
= NULL
;
17472 uint32_t frame_len
;
17475 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17476 frame_len
= bf_get(lpfc_rcqe_length
, &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17478 /* Send the received frame back */
17479 iocbq
= lpfc_sli_get_iocbq(phba
);
17483 /* Allocate buffer for command payload */
17484 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
17486 pcmd
->virt
= dma_pool_alloc(phba
->lpfc_drb_pool
, GFP_KERNEL
,
17488 if (!pcmd
|| !pcmd
->virt
)
17491 INIT_LIST_HEAD(&pcmd
->list
);
17493 /* copyin the payload */
17494 memcpy(pcmd
->virt
, dmabuf
->dbuf
.virt
, frame_len
);
17496 /* fill in BDE's for command */
17497 iocbq
->iocb
.un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pcmd
->phys
);
17498 iocbq
->iocb
.un
.xseq64
.bdl
.addrLow
= putPaddrLow(pcmd
->phys
);
17499 iocbq
->iocb
.un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
17500 iocbq
->iocb
.un
.xseq64
.bdl
.bdeSize
= frame_len
;
17502 iocbq
->context2
= pcmd
;
17503 iocbq
->vport
= vport
;
17504 iocbq
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
17505 iocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
17508 * Setup rest of the iocb as though it were a WQE
17509 * Build the SEND_FRAME WQE
17511 wqe
= (union lpfc_wqe
*)&iocbq
->iocb
;
17513 wqe
->send_frame
.frame_len
= frame_len
;
17514 wqe
->send_frame
.fc_hdr_wd0
= be32_to_cpu(*((uint32_t *)fc_hdr
));
17515 wqe
->send_frame
.fc_hdr_wd1
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 1));
17516 wqe
->send_frame
.fc_hdr_wd2
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 2));
17517 wqe
->send_frame
.fc_hdr_wd3
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 3));
17518 wqe
->send_frame
.fc_hdr_wd4
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 4));
17519 wqe
->send_frame
.fc_hdr_wd5
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 5));
17521 iocbq
->iocb
.ulpCommand
= CMD_SEND_FRAME
;
17522 iocbq
->iocb
.ulpLe
= 1;
17523 iocbq
->iocb_cmpl
= lpfc_sli4_mds_loopback_cmpl
;
17524 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocbq
, 0);
17525 if (rc
== IOCB_ERROR
)
17528 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17532 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
17533 "2023 Unable to process MDS loopback frame\n");
17534 if (pcmd
&& pcmd
->virt
)
17535 dma_pool_free(phba
->lpfc_drb_pool
, pcmd
->virt
, pcmd
->phys
);
17538 lpfc_sli_release_iocbq(phba
, iocbq
);
17539 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17543 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
17544 * @phba: Pointer to HBA context object.
17546 * This function is called with no lock held. This function processes all
17547 * the received buffers and gives it to upper layers when a received buffer
17548 * indicates that it is the final frame in the sequence. The interrupt
17549 * service routine processes received buffers at interrupt contexts.
17550 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
17551 * appropriate receive function when the final frame in a sequence is received.
17554 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
17555 struct hbq_dmabuf
*dmabuf
)
17557 struct hbq_dmabuf
*seq_dmabuf
;
17558 struct fc_frame_header
*fc_hdr
;
17559 struct lpfc_vport
*vport
;
17563 /* Process each received buffer */
17564 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17566 /* check to see if this a valid type of frame */
17567 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
17568 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17572 if ((bf_get(lpfc_cqe_code
,
17573 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
17574 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
17575 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17577 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
17578 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17580 if (fc_hdr
->fh_r_ctl
== 0xF4 && fc_hdr
->fh_type
== 0xFF) {
17581 vport
= phba
->pport
;
17582 /* Handle MDS Loopback frames */
17583 lpfc_sli4_handle_mds_loopback(vport
, dmabuf
);
17587 /* d_id this frame is directed to */
17588 did
= sli4_did_from_fc_hdr(fc_hdr
);
17590 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
, did
);
17592 /* throw out the frame */
17593 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17597 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
17598 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
17599 (did
!= Fabric_DID
)) {
17601 * Throw out the frame if we are not pt2pt.
17602 * The pt2pt protocol allows for discovery frames
17603 * to be received without a registered VPI.
17605 if (!(vport
->fc_flag
& FC_PT2PT
) ||
17606 (phba
->link_state
== LPFC_HBA_READY
)) {
17607 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17612 /* Handle the basic abort sequence (BA_ABTS) event */
17613 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
17614 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
17618 /* Link this frame */
17619 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
17621 /* unable to add frame to vport - throw it out */
17622 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17625 /* If not last frame in sequence continue processing frames. */
17626 if (!lpfc_seq_complete(seq_dmabuf
))
17629 /* Send the complete sequence to the upper layer protocol */
17630 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
17634 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
17635 * @phba: pointer to lpfc hba data structure.
17637 * This routine is invoked to post rpi header templates to the
17638 * HBA consistent with the SLI-4 interface spec. This routine
17639 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17640 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17642 * This routine does not require any locks. It's usage is expected
17643 * to be driver load or reset recovery when the driver is
17648 * -EIO - The mailbox failed to complete successfully.
17649 * When this error occurs, the driver is not guaranteed
17650 * to have any rpi regions posted to the device and
17651 * must either attempt to repost the regions or take a
17655 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
17657 struct lpfc_rpi_hdr
*rpi_page
;
17661 /* SLI4 ports that support extents do not require RPI headers. */
17662 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
17664 if (phba
->sli4_hba
.extents_in_use
)
17667 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
17669 * Assign the rpi headers a physical rpi only if the driver
17670 * has not initialized those resources. A port reset only
17671 * needs the headers posted.
17673 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
17675 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
17677 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
17678 if (rc
!= MBX_SUCCESS
) {
17679 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17680 "2008 Error %d posting all rpi "
17688 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
17689 LPFC_RPI_RSRC_RDY
);
17694 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
17695 * @phba: pointer to lpfc hba data structure.
17696 * @rpi_page: pointer to the rpi memory region.
17698 * This routine is invoked to post a single rpi header to the
17699 * HBA consistent with the SLI-4 interface spec. This memory region
17700 * maps up to 64 rpi context regions.
17704 * -ENOMEM - No available memory
17705 * -EIO - The mailbox failed to complete successfully.
17708 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
17710 LPFC_MBOXQ_t
*mboxq
;
17711 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
17713 uint32_t shdr_status
, shdr_add_status
;
17714 union lpfc_sli4_cfg_shdr
*shdr
;
17716 /* SLI4 ports that support extents do not require RPI headers. */
17717 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
17719 if (phba
->sli4_hba
.extents_in_use
)
17722 /* The port is notified of the header region via a mailbox command. */
17723 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17725 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17726 "2001 Unable to allocate memory for issuing "
17727 "SLI_CONFIG_SPECIAL mailbox command\n");
17731 /* Post all rpi memory regions to the port. */
17732 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
17733 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
17734 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
17735 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
17736 sizeof(struct lpfc_sli4_cfg_mhdr
),
17737 LPFC_SLI4_MBX_EMBED
);
17740 /* Post the physical rpi to the port for this rpi header. */
17741 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
17742 rpi_page
->start_rpi
);
17743 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
17744 hdr_tmpl
, rpi_page
->page_count
);
17746 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
17747 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
17748 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
17749 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
17750 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17751 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17752 if (rc
!= MBX_TIMEOUT
)
17753 mempool_free(mboxq
, phba
->mbox_mem_pool
);
17754 if (shdr_status
|| shdr_add_status
|| rc
) {
17755 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17756 "2514 POST_RPI_HDR mailbox failed with "
17757 "status x%x add_status x%x, mbx status x%x\n",
17758 shdr_status
, shdr_add_status
, rc
);
17762 * The next_rpi stores the next logical module-64 rpi value used
17763 * to post physical rpis in subsequent rpi postings.
17765 spin_lock_irq(&phba
->hbalock
);
17766 phba
->sli4_hba
.next_rpi
= rpi_page
->next_rpi
;
17767 spin_unlock_irq(&phba
->hbalock
);
17773 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
17774 * @phba: pointer to lpfc hba data structure.
17776 * This routine is invoked to post rpi header templates to the
17777 * HBA consistent with the SLI-4 interface spec. This routine
17778 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17779 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17782 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
17783 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
17786 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
17789 uint16_t max_rpi
, rpi_limit
;
17790 uint16_t rpi_remaining
, lrpi
= 0;
17791 struct lpfc_rpi_hdr
*rpi_hdr
;
17792 unsigned long iflag
;
17795 * Fetch the next logical rpi. Because this index is logical,
17796 * the driver starts at 0 each time.
17798 spin_lock_irqsave(&phba
->hbalock
, iflag
);
17799 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
17800 rpi_limit
= phba
->sli4_hba
.next_rpi
;
17802 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
17803 if (rpi
>= rpi_limit
)
17804 rpi
= LPFC_RPI_ALLOC_ERROR
;
17806 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
17807 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
17808 phba
->sli4_hba
.rpi_count
++;
17810 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
17811 "0001 rpi:%x max:%x lim:%x\n",
17812 (int) rpi
, max_rpi
, rpi_limit
);
17815 * Don't try to allocate more rpi header regions if the device limit
17816 * has been exhausted.
17818 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
17819 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
17820 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17825 * RPI header postings are not required for SLI4 ports capable of
17828 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
17829 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17834 * If the driver is running low on rpi resources, allocate another
17835 * page now. Note that the next_rpi value is used because
17836 * it represents how many are actually in use whereas max_rpi notes
17837 * how many are supported max by the device.
17839 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
17840 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17841 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
17842 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
17844 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17845 "2002 Error Could not grow rpi "
17848 lrpi
= rpi_hdr
->start_rpi
;
17849 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
17850 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
17858 * lpfc_sli4_free_rpi - Release an rpi for reuse.
17859 * @phba: pointer to lpfc hba data structure.
17861 * This routine is invoked to release an rpi to the pool of
17862 * available rpis maintained by the driver.
17865 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
17867 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
17868 phba
->sli4_hba
.rpi_count
--;
17869 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
17874 * lpfc_sli4_free_rpi - Release an rpi for reuse.
17875 * @phba: pointer to lpfc hba data structure.
17877 * This routine is invoked to release an rpi to the pool of
17878 * available rpis maintained by the driver.
17881 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
17883 spin_lock_irq(&phba
->hbalock
);
17884 __lpfc_sli4_free_rpi(phba
, rpi
);
17885 spin_unlock_irq(&phba
->hbalock
);
17889 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
17890 * @phba: pointer to lpfc hba data structure.
17892 * This routine is invoked to remove the memory region that
17893 * provided rpi via a bitmask.
17896 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
17898 kfree(phba
->sli4_hba
.rpi_bmask
);
17899 kfree(phba
->sli4_hba
.rpi_ids
);
17900 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
17904 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
17905 * @phba: pointer to lpfc hba data structure.
17907 * This routine is invoked to remove the memory region that
17908 * provided rpi via a bitmask.
17911 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
17912 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
17914 LPFC_MBOXQ_t
*mboxq
;
17915 struct lpfc_hba
*phba
= ndlp
->phba
;
17918 /* The port is notified of the header region via a mailbox command. */
17919 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17923 /* Post all rpi memory regions to the port. */
17924 lpfc_resume_rpi(mboxq
, ndlp
);
17926 mboxq
->mbox_cmpl
= cmpl
;
17927 mboxq
->context1
= arg
;
17928 mboxq
->context2
= ndlp
;
17930 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17931 mboxq
->vport
= ndlp
->vport
;
17932 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17933 if (rc
== MBX_NOT_FINISHED
) {
17934 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17935 "2010 Resume RPI Mailbox failed "
17936 "status %d, mbxStatus x%x\n", rc
,
17937 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
17938 mempool_free(mboxq
, phba
->mbox_mem_pool
);
17945 * lpfc_sli4_init_vpi - Initialize a vpi with the port
17946 * @vport: Pointer to the vport for which the vpi is being initialized
17948 * This routine is invoked to activate a vpi with the port.
17952 * -Evalue otherwise
17955 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
17957 LPFC_MBOXQ_t
*mboxq
;
17959 int retval
= MBX_SUCCESS
;
17961 struct lpfc_hba
*phba
= vport
->phba
;
17962 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17965 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
17966 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
17967 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
17968 if (rc
!= MBX_SUCCESS
) {
17969 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
17970 "2022 INIT VPI Mailbox failed "
17971 "status %d, mbxStatus x%x\n", rc
,
17972 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
17975 if (rc
!= MBX_TIMEOUT
)
17976 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
17982 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
17983 * @phba: pointer to lpfc hba data structure.
17984 * @mboxq: Pointer to mailbox object.
17986 * This routine is invoked to manually add a single FCF record. The caller
17987 * must pass a completely initialized FCF_Record. This routine takes
17988 * care of the nonembedded mailbox operations.
17991 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
17994 union lpfc_sli4_cfg_shdr
*shdr
;
17995 uint32_t shdr_status
, shdr_add_status
;
17997 virt_addr
= mboxq
->sge_array
->addr
[0];
17998 /* The IOCTL status is embedded in the mailbox subheader. */
17999 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
18000 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
18001 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
18003 if ((shdr_status
|| shdr_add_status
) &&
18004 (shdr_status
!= STATUS_FCF_IN_USE
))
18005 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18006 "2558 ADD_FCF_RECORD mailbox failed with "
18007 "status x%x add_status x%x\n",
18008 shdr_status
, shdr_add_status
);
18010 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
18014 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
18015 * @phba: pointer to lpfc hba data structure.
18016 * @fcf_record: pointer to the initialized fcf record to add.
18018 * This routine is invoked to manually add a single FCF record. The caller
18019 * must pass a completely initialized FCF_Record. This routine takes
18020 * care of the nonembedded mailbox operations.
18023 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
18026 LPFC_MBOXQ_t
*mboxq
;
18029 struct lpfc_mbx_sge sge
;
18030 uint32_t alloc_len
, req_len
;
18033 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18035 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18036 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
18040 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
18043 /* Allocate DMA memory and set up the non-embedded mailbox command */
18044 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
18045 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
18046 req_len
, LPFC_SLI4_MBX_NEMBED
);
18047 if (alloc_len
< req_len
) {
18048 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18049 "2523 Allocated DMA memory size (x%x) is "
18050 "less than the requested DMA memory "
18051 "size (x%x)\n", alloc_len
, req_len
);
18052 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
18057 * Get the first SGE entry from the non-embedded DMA memory. This
18058 * routine only uses a single SGE.
18060 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
18061 virt_addr
= mboxq
->sge_array
->addr
[0];
18063 * Configure the FCF record for FCFI 0. This is the driver's
18064 * hardcoded default and gets used in nonFIP mode.
18066 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
18067 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
18068 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
18071 * Copy the fcf_index and the FCF Record Data. The data starts after
18072 * the FCoE header plus word10. The data copy needs to be endian
18075 bytep
+= sizeof(uint32_t);
18076 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
18077 mboxq
->vport
= phba
->pport
;
18078 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
18079 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
18080 if (rc
== MBX_NOT_FINISHED
) {
18081 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18082 "2515 ADD_FCF_RECORD mailbox failed with "
18083 "status 0x%x\n", rc
);
18084 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
18093 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
18094 * @phba: pointer to lpfc hba data structure.
18095 * @fcf_record: pointer to the fcf record to write the default data.
18096 * @fcf_index: FCF table entry index.
18098 * This routine is invoked to build the driver's default FCF record. The
18099 * values used are hardcoded. This routine handles memory initialization.
18103 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
18104 struct fcf_record
*fcf_record
,
18105 uint16_t fcf_index
)
18107 memset(fcf_record
, 0, sizeof(struct fcf_record
));
18108 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
18109 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
18110 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
18111 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
18112 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
18113 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
18114 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
18115 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
18116 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
18117 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
18118 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
18119 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
18120 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
18121 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
18122 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
18123 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
18124 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
18125 /* Set the VLAN bit map */
18126 if (phba
->valid_vlan
) {
18127 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
18128 = 1 << (phba
->vlan_id
% 8);
18133 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
18134 * @phba: pointer to lpfc hba data structure.
18135 * @fcf_index: FCF table entry offset.
18137 * This routine is invoked to scan the entire FCF table by reading FCF
18138 * record and processing it one at a time starting from the @fcf_index
18139 * for initial FCF discovery or fast FCF failover rediscovery.
18141 * Return 0 if the mailbox command is submitted successfully, none 0
18145 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18148 LPFC_MBOXQ_t
*mboxq
;
18150 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
18151 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
18152 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18154 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18155 "2000 Failed to allocate mbox for "
18158 goto fail_fcf_scan
;
18160 /* Construct the read FCF record mailbox command */
18161 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
18164 goto fail_fcf_scan
;
18166 /* Issue the mailbox command asynchronously */
18167 mboxq
->vport
= phba
->pport
;
18168 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
18170 spin_lock_irq(&phba
->hbalock
);
18171 phba
->hba_flag
|= FCF_TS_INPROG
;
18172 spin_unlock_irq(&phba
->hbalock
);
18174 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
18175 if (rc
== MBX_NOT_FINISHED
)
18178 /* Reset eligible FCF count for new scan */
18179 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
18180 phba
->fcf
.eligible_fcf_cnt
= 0;
18186 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
18187 /* FCF scan failed, clear FCF_TS_INPROG flag */
18188 spin_lock_irq(&phba
->hbalock
);
18189 phba
->hba_flag
&= ~FCF_TS_INPROG
;
18190 spin_unlock_irq(&phba
->hbalock
);
18196 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
18197 * @phba: pointer to lpfc hba data structure.
18198 * @fcf_index: FCF table entry offset.
18200 * This routine is invoked to read an FCF record indicated by @fcf_index
18201 * and to use it for FLOGI roundrobin FCF failover.
18203 * Return 0 if the mailbox command is submitted successfully, none 0
18207 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18210 LPFC_MBOXQ_t
*mboxq
;
18212 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18214 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
18215 "2763 Failed to allocate mbox for "
18218 goto fail_fcf_read
;
18220 /* Construct the read FCF record mailbox command */
18221 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
18224 goto fail_fcf_read
;
18226 /* Issue the mailbox command asynchronously */
18227 mboxq
->vport
= phba
->pport
;
18228 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
18229 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
18230 if (rc
== MBX_NOT_FINISHED
)
18236 if (error
&& mboxq
)
18237 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
18242 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
18243 * @phba: pointer to lpfc hba data structure.
18244 * @fcf_index: FCF table entry offset.
18246 * This routine is invoked to read an FCF record indicated by @fcf_index to
18247 * determine whether it's eligible for FLOGI roundrobin failover list.
18249 * Return 0 if the mailbox command is submitted successfully, none 0
18253 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18256 LPFC_MBOXQ_t
*mboxq
;
18258 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18260 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
18261 "2758 Failed to allocate mbox for "
18264 goto fail_fcf_read
;
18266 /* Construct the read FCF record mailbox command */
18267 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
18270 goto fail_fcf_read
;
18272 /* Issue the mailbox command asynchronously */
18273 mboxq
->vport
= phba
->pport
;
18274 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
18275 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
18276 if (rc
== MBX_NOT_FINISHED
)
18282 if (error
&& mboxq
)
18283 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
18288 * lpfc_check_next_fcf_pri_level
18289 * phba pointer to the lpfc_hba struct for this port.
18290 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
18291 * routine when the rr_bmask is empty. The FCF indecies are put into the
18292 * rr_bmask based on their priority level. Starting from the highest priority
18293 * to the lowest. The most likely FCF candidate will be in the highest
18294 * priority group. When this routine is called it searches the fcf_pri list for
18295 * next lowest priority group and repopulates the rr_bmask with only those
18298 * 1=success 0=failure
18301 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
18303 uint16_t next_fcf_pri
;
18304 uint16_t last_index
;
18305 struct lpfc_fcf_pri
*fcf_pri
;
18309 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
18310 LPFC_SLI4_FCF_TBL_INDX_MAX
);
18311 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18312 "3060 Last IDX %d\n", last_index
);
18314 /* Verify the priority list has 2 or more entries */
18315 spin_lock_irq(&phba
->hbalock
);
18316 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
18317 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
18318 spin_unlock_irq(&phba
->hbalock
);
18319 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18320 "3061 Last IDX %d\n", last_index
);
18321 return 0; /* Empty rr list */
18323 spin_unlock_irq(&phba
->hbalock
);
18327 * Clear the rr_bmask and set all of the bits that are at this
18330 memset(phba
->fcf
.fcf_rr_bmask
, 0,
18331 sizeof(*phba
->fcf
.fcf_rr_bmask
));
18332 spin_lock_irq(&phba
->hbalock
);
18333 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
18334 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
18337 * the 1st priority that has not FLOGI failed
18338 * will be the highest.
18341 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
18342 spin_unlock_irq(&phba
->hbalock
);
18343 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
18344 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
18345 fcf_pri
->fcf_rec
.fcf_index
);
18349 spin_lock_irq(&phba
->hbalock
);
18352 * if next_fcf_pri was not set above and the list is not empty then
18353 * we have failed flogis on all of them. So reset flogi failed
18354 * and start at the beginning.
18356 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
18357 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
18358 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
18360 * the 1st priority that has not FLOGI failed
18361 * will be the highest.
18364 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
18365 spin_unlock_irq(&phba
->hbalock
);
18366 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
18367 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
18368 fcf_pri
->fcf_rec
.fcf_index
);
18372 spin_lock_irq(&phba
->hbalock
);
18376 spin_unlock_irq(&phba
->hbalock
);
18381 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
18382 * @phba: pointer to lpfc hba data structure.
18384 * This routine is to get the next eligible FCF record index in a round
18385 * robin fashion. If the next eligible FCF record index equals to the
18386 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
18387 * shall be returned, otherwise, the next eligible FCF record's index
18388 * shall be returned.
18391 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
18393 uint16_t next_fcf_index
;
18396 /* Search start from next bit of currently registered FCF index */
18397 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
18400 /* Determine the next fcf index to check */
18401 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
18402 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
18403 LPFC_SLI4_FCF_TBL_INDX_MAX
,
18406 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
18407 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18409 * If we have wrapped then we need to clear the bits that
18410 * have been tested so that we can detect when we should
18411 * change the priority level.
18413 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
18414 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
18418 /* Check roundrobin failover list empty condition */
18419 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
18420 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
18422 * If next fcf index is not found check if there are lower
18423 * Priority level fcf's in the fcf_priority list.
18424 * Set up the rr_bmask with all of the avaiable fcf bits
18425 * at that level and continue the selection process.
18427 if (lpfc_check_next_fcf_pri_level(phba
))
18428 goto initial_priority
;
18429 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
18430 "2844 No roundrobin failover FCF available\n");
18431 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
18432 return LPFC_FCOE_FCF_NEXT_NONE
;
18434 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
18435 "3063 Only FCF available idx %d, flag %x\n",
18437 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
18438 return next_fcf_index
;
18442 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
18443 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
18444 LPFC_FCF_FLOGI_FAILED
) {
18445 if (list_is_singular(&phba
->fcf
.fcf_pri_list
))
18446 return LPFC_FCOE_FCF_NEXT_NONE
;
18448 goto next_priority
;
18451 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18452 "2845 Get next roundrobin failover FCF (x%x)\n",
18455 return next_fcf_index
;
18459 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
18460 * @phba: pointer to lpfc hba data structure.
18462 * This routine sets the FCF record index in to the eligible bmask for
18463 * roundrobin failover search. It checks to make sure that the index
18464 * does not go beyond the range of the driver allocated bmask dimension
18465 * before setting the bit.
18467 * Returns 0 if the index bit successfully set, otherwise, it returns
18471 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18473 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18474 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18475 "2610 FCF (x%x) reached driver's book "
18476 "keeping dimension:x%x\n",
18477 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
18480 /* Set the eligible FCF record index bmask */
18481 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
18483 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18484 "2790 Set FCF (x%x) to roundrobin FCF failover "
18485 "bmask\n", fcf_index
);
18491 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
18492 * @phba: pointer to lpfc hba data structure.
18494 * This routine clears the FCF record index from the eligible bmask for
18495 * roundrobin failover search. It checks to make sure that the index
18496 * does not go beyond the range of the driver allocated bmask dimension
18497 * before clearing the bit.
18500 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18502 struct lpfc_fcf_pri
*fcf_pri
, *fcf_pri_next
;
18503 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18504 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18505 "2762 FCF (x%x) reached driver's book "
18506 "keeping dimension:x%x\n",
18507 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
18510 /* Clear the eligible FCF record index bmask */
18511 spin_lock_irq(&phba
->hbalock
);
18512 list_for_each_entry_safe(fcf_pri
, fcf_pri_next
, &phba
->fcf
.fcf_pri_list
,
18514 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
18515 list_del_init(&fcf_pri
->list
);
18519 spin_unlock_irq(&phba
->hbalock
);
18520 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
18522 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18523 "2791 Clear FCF (x%x) from roundrobin failover "
18524 "bmask\n", fcf_index
);
18528 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
18529 * @phba: pointer to lpfc hba data structure.
18531 * This routine is the completion routine for the rediscover FCF table mailbox
18532 * command. If the mailbox command returned failure, it will try to stop the
18533 * FCF rediscover wait timer.
18536 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
18538 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
18539 uint32_t shdr_status
, shdr_add_status
;
18541 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
18543 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
18544 &redisc_fcf
->header
.cfg_shdr
.response
);
18545 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
18546 &redisc_fcf
->header
.cfg_shdr
.response
);
18547 if (shdr_status
|| shdr_add_status
) {
18548 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18549 "2746 Requesting for FCF rediscovery failed "
18550 "status x%x add_status x%x\n",
18551 shdr_status
, shdr_add_status
);
18552 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
18553 spin_lock_irq(&phba
->hbalock
);
18554 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
18555 spin_unlock_irq(&phba
->hbalock
);
18557 * CVL event triggered FCF rediscover request failed,
18558 * last resort to re-try current registered FCF entry.
18560 lpfc_retry_pport_discovery(phba
);
18562 spin_lock_irq(&phba
->hbalock
);
18563 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
18564 spin_unlock_irq(&phba
->hbalock
);
18566 * DEAD FCF event triggered FCF rediscover request
18567 * failed, last resort to fail over as a link down
18568 * to FCF registration.
18570 lpfc_sli4_fcf_dead_failthrough(phba
);
18573 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18574 "2775 Start FCF rediscover quiescent timer\n");
18576 * Start FCF rediscovery wait timer for pending FCF
18577 * before rescan FCF record table.
18579 lpfc_fcf_redisc_wait_start_timer(phba
);
18582 mempool_free(mbox
, phba
->mbox_mem_pool
);
18586 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
18587 * @phba: pointer to lpfc hba data structure.
18589 * This routine is invoked to request for rediscovery of the entire FCF table
18593 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
18595 LPFC_MBOXQ_t
*mbox
;
18596 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
18599 /* Cancel retry delay timers to all vports before FCF rediscover */
18600 lpfc_cancel_all_vport_retry_delay_timer(phba
);
18602 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18604 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18605 "2745 Failed to allocate mbox for "
18606 "requesting FCF rediscover.\n");
18610 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
18611 sizeof(struct lpfc_sli4_cfg_mhdr
));
18612 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
18613 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
18614 length
, LPFC_SLI4_MBX_EMBED
);
18616 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
18617 /* Set count to 0 for invalidating the entire FCF database */
18618 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
18620 /* Issue the mailbox command asynchronously */
18621 mbox
->vport
= phba
->pport
;
18622 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
18623 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
18625 if (rc
== MBX_NOT_FINISHED
) {
18626 mempool_free(mbox
, phba
->mbox_mem_pool
);
18633 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
18634 * @phba: pointer to lpfc hba data structure.
18636 * This function is the failover routine as a last resort to the FCF DEAD
18637 * event when driver failed to perform fast FCF failover.
18640 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
18642 uint32_t link_state
;
18645 * Last resort as FCF DEAD event failover will treat this as
18646 * a link down, but save the link state because we don't want
18647 * it to be changed to Link Down unless it is already down.
18649 link_state
= phba
->link_state
;
18650 lpfc_linkdown(phba
);
18651 phba
->link_state
= link_state
;
18653 /* Unregister FCF if no devices connected to it */
18654 lpfc_unregister_unused_fcf(phba
);
18658 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
18659 * @phba: pointer to lpfc hba data structure.
18660 * @rgn23_data: pointer to configure region 23 data.
18662 * This function gets SLI3 port configure region 23 data through memory dump
18663 * mailbox command. When it successfully retrieves data, the size of the data
18664 * will be returned, otherwise, 0 will be returned.
18667 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
18669 LPFC_MBOXQ_t
*pmb
= NULL
;
18671 uint32_t offset
= 0;
18677 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18679 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18680 "2600 failed to allocate mailbox memory\n");
18686 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
18687 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
18689 if (rc
!= MBX_SUCCESS
) {
18690 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
18691 "2601 failed to read config "
18692 "region 23, rc 0x%x Status 0x%x\n",
18693 rc
, mb
->mbxStatus
);
18694 mb
->un
.varDmp
.word_cnt
= 0;
18697 * dump mem may return a zero when finished or we got a
18698 * mailbox error, either way we are done.
18700 if (mb
->un
.varDmp
.word_cnt
== 0)
18702 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
18703 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
18705 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
18706 rgn23_data
+ offset
,
18707 mb
->un
.varDmp
.word_cnt
);
18708 offset
+= mb
->un
.varDmp
.word_cnt
;
18709 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
18711 mempool_free(pmb
, phba
->mbox_mem_pool
);
18716 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
18717 * @phba: pointer to lpfc hba data structure.
18718 * @rgn23_data: pointer to configure region 23 data.
18720 * This function gets SLI4 port configure region 23 data through memory dump
18721 * mailbox command. When it successfully retrieves data, the size of the data
18722 * will be returned, otherwise, 0 will be returned.
18725 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
18727 LPFC_MBOXQ_t
*mboxq
= NULL
;
18728 struct lpfc_dmabuf
*mp
= NULL
;
18729 struct lpfc_mqe
*mqe
;
18730 uint32_t data_length
= 0;
18736 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18738 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18739 "3105 failed to allocate mailbox memory\n");
18743 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
18745 mqe
= &mboxq
->u
.mqe
;
18746 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
18747 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
18750 data_length
= mqe
->un
.mb_words
[5];
18751 if (data_length
== 0)
18753 if (data_length
> DMP_RGN23_SIZE
) {
18757 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
18759 mempool_free(mboxq
, phba
->mbox_mem_pool
);
18761 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
18764 return data_length
;
18768 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
18769 * @phba: pointer to lpfc hba data structure.
18771 * This function read region 23 and parse TLV for port status to
18772 * decide if the user disaled the port. If the TLV indicates the
18773 * port is disabled, the hba_flag is set accordingly.
18776 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
18778 uint8_t *rgn23_data
= NULL
;
18779 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
18780 uint32_t offset
= 0;
18782 /* Get adapter Region 23 data */
18783 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
18787 if (phba
->sli_rev
< LPFC_SLI_REV4
)
18788 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
18790 if_type
= bf_get(lpfc_sli_intf_if_type
,
18791 &phba
->sli4_hba
.sli_intf
);
18792 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
18794 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
18800 /* Check the region signature first */
18801 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
18802 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18803 "2619 Config region 23 has bad signature\n");
18808 /* Check the data structure version */
18809 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
18810 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18811 "2620 Config region 23 has bad version\n");
18816 /* Parse TLV entries in the region */
18817 while (offset
< data_size
) {
18818 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
18821 * If the TLV is not driver specific TLV or driver id is
18822 * not linux driver id, skip the record.
18824 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
18825 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
18826 (rgn23_data
[offset
+ 3] != 0)) {
18827 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18831 /* Driver found a driver specific TLV in the config region */
18832 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
18837 * Search for configured port state sub-TLV.
18839 while ((offset
< data_size
) &&
18840 (tlv_offset
< sub_tlv_len
)) {
18841 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
18846 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
18847 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18848 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18852 /* This HBA contains PORT_STE configured */
18853 if (!rgn23_data
[offset
+ 2])
18854 phba
->hba_flag
|= LINK_DISABLED
;
18866 * lpfc_wr_object - write an object to the firmware
18867 * @phba: HBA structure that indicates port to create a queue on.
18868 * @dmabuf_list: list of dmabufs to write to the port.
18869 * @size: the total byte value of the objects to write to the port.
18870 * @offset: the current offset to be used to start the transfer.
18872 * This routine will create a wr_object mailbox command to send to the port.
18873 * the mailbox command will be constructed using the dma buffers described in
18874 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
18875 * BDEs that the imbedded mailbox can support. The @offset variable will be
18876 * used to indicate the starting offset of the transfer and will also return
18877 * the offset after the write object mailbox has completed. @size is used to
18878 * determine the end of the object and whether the eof bit should be set.
18880 * Return 0 is successful and offset will contain the the new offset to use
18881 * for the next write.
18882 * Return negative value for error cases.
18885 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
18886 uint32_t size
, uint32_t *offset
)
18888 struct lpfc_mbx_wr_object
*wr_object
;
18889 LPFC_MBOXQ_t
*mbox
;
18891 uint32_t shdr_status
, shdr_add_status
;
18893 union lpfc_sli4_cfg_shdr
*shdr
;
18894 struct lpfc_dmabuf
*dmabuf
;
18895 uint32_t written
= 0;
18897 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18901 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
18902 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
18903 sizeof(struct lpfc_mbx_wr_object
) -
18904 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
18906 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
18907 wr_object
->u
.request
.write_offset
= *offset
;
18908 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
18909 wr_object
->u
.request
.object_name
[0] =
18910 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
18911 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
18912 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
18913 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
18915 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
18916 wr_object
->u
.request
.bde
[i
].addrHigh
=
18917 putPaddrHigh(dmabuf
->phys
);
18918 if (written
+ SLI4_PAGE_SIZE
>= size
) {
18919 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
18921 written
+= (size
- written
);
18922 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
18924 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
18926 written
+= SLI4_PAGE_SIZE
;
18930 wr_object
->u
.request
.bde_count
= i
;
18931 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
18932 if (!phba
->sli4_hba
.intr_enable
)
18933 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
18935 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
18936 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
18938 /* The IOCTL status is embedded in the mailbox subheader. */
18939 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
18940 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
18941 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
18942 if (rc
!= MBX_TIMEOUT
)
18943 mempool_free(mbox
, phba
->mbox_mem_pool
);
18944 if (shdr_status
|| shdr_add_status
|| rc
) {
18945 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18946 "3025 Write Object mailbox failed with "
18947 "status x%x add_status x%x, mbx status x%x\n",
18948 shdr_status
, shdr_add_status
, rc
);
18950 *offset
= shdr_add_status
;
18952 *offset
+= wr_object
->u
.response
.actual_write_length
;
18957 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
18958 * @vport: pointer to vport data structure.
18960 * This function iterate through the mailboxq and clean up all REG_LOGIN
18961 * and REG_VPI mailbox commands associated with the vport. This function
18962 * is called when driver want to restart discovery of the vport due to
18963 * a Clear Virtual Link event.
18966 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
18968 struct lpfc_hba
*phba
= vport
->phba
;
18969 LPFC_MBOXQ_t
*mb
, *nextmb
;
18970 struct lpfc_dmabuf
*mp
;
18971 struct lpfc_nodelist
*ndlp
;
18972 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
18973 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
18974 LIST_HEAD(mbox_cmd_list
);
18975 uint8_t restart_loop
;
18977 /* Clean up internally queued mailbox commands with the vport */
18978 spin_lock_irq(&phba
->hbalock
);
18979 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
18980 if (mb
->vport
!= vport
)
18983 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
18984 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
18987 list_del(&mb
->list
);
18988 list_add_tail(&mb
->list
, &mbox_cmd_list
);
18990 /* Clean up active mailbox command with the vport */
18991 mb
= phba
->sli
.mbox_active
;
18992 if (mb
&& (mb
->vport
== vport
)) {
18993 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
18994 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
18995 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
18996 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18997 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
18998 /* Put reference count for delayed processing */
18999 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
19000 /* Unregister the RPI when mailbox complete */
19001 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
19004 /* Cleanup any mailbox completions which are not yet processed */
19007 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
19009 * If this mailox is already processed or it is
19010 * for another vport ignore it.
19012 if ((mb
->vport
!= vport
) ||
19013 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
19016 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
19017 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
19020 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
19021 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
19022 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
19023 /* Unregister the RPI when mailbox complete */
19024 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
19026 spin_unlock_irq(&phba
->hbalock
);
19027 spin_lock(shost
->host_lock
);
19028 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
19029 spin_unlock(shost
->host_lock
);
19030 spin_lock_irq(&phba
->hbalock
);
19034 } while (restart_loop
);
19036 spin_unlock_irq(&phba
->hbalock
);
19038 /* Release the cleaned-up mailbox commands */
19039 while (!list_empty(&mbox_cmd_list
)) {
19040 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
19041 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
19042 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
19044 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
19047 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
19048 mb
->context2
= NULL
;
19050 spin_lock(shost
->host_lock
);
19051 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
19052 spin_unlock(shost
->host_lock
);
19053 lpfc_nlp_put(ndlp
);
19056 mempool_free(mb
, phba
->mbox_mem_pool
);
19059 /* Release the ndlp with the cleaned-up active mailbox command */
19060 if (act_mbx_ndlp
) {
19061 spin_lock(shost
->host_lock
);
19062 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
19063 spin_unlock(shost
->host_lock
);
19064 lpfc_nlp_put(act_mbx_ndlp
);
19069 * lpfc_drain_txq - Drain the txq
19070 * @phba: Pointer to HBA context object.
19072 * This function attempt to submit IOCBs on the txq
19073 * to the adapter. For SLI4 adapters, the txq contains
19074 * ELS IOCBs that have been deferred because the there
19075 * are no SGLs. This congestion can occur with large
19076 * vport counts during node discovery.
19080 lpfc_drain_txq(struct lpfc_hba
*phba
)
19082 LIST_HEAD(completions
);
19083 struct lpfc_sli_ring
*pring
;
19084 struct lpfc_iocbq
*piocbq
= NULL
;
19085 unsigned long iflags
= 0;
19086 char *fail_msg
= NULL
;
19087 struct lpfc_sglq
*sglq
;
19088 union lpfc_wqe128 wqe
;
19089 uint32_t txq_cnt
= 0;
19090 struct lpfc_queue
*wq
;
19092 if (phba
->link_flag
& LS_MDS_LOOPBACK
) {
19093 /* MDS WQE are posted only to first WQ*/
19094 wq
= phba
->sli4_hba
.fcp_wq
[0];
19099 wq
= phba
->sli4_hba
.els_wq
;
19102 pring
= lpfc_phba_elsring(phba
);
19105 if (unlikely(!pring
) || list_empty(&pring
->txq
))
19108 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19109 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
19113 if (txq_cnt
> pring
->txq_max
)
19114 pring
->txq_max
= txq_cnt
;
19116 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19118 while (!list_empty(&pring
->txq
)) {
19119 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19121 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
19123 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19124 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
19125 "2823 txq empty and txq_cnt is %d\n ",
19129 sglq
= __lpfc_sli_get_els_sglq(phba
, piocbq
);
19131 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
19132 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19137 /* The xri and iocb resources secured,
19138 * attempt to issue request
19140 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
19141 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
19142 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
19143 fail_msg
= "to convert bpl to sgl";
19144 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
19145 fail_msg
= "to convert iocb to wqe";
19146 else if (lpfc_sli4_wq_put(wq
, &wqe
))
19147 fail_msg
= " - Wq is full";
19149 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
19152 /* Failed means we can't issue and need to cancel */
19153 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
19154 "2822 IOCB failed %s iotag 0x%x "
19157 piocbq
->iotag
, piocbq
->sli4_xritag
);
19158 list_add_tail(&piocbq
->list
, &completions
);
19160 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19163 /* Cancel all the IOCBs that cannot be issued */
19164 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
19165 IOERR_SLI_ABORTED
);
19171 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
19172 * @phba: Pointer to HBA context object.
19173 * @pwqe: Pointer to command WQE.
19174 * @sglq: Pointer to the scatter gather queue object.
19176 * This routine converts the bpl or bde that is in the WQE
19177 * to a sgl list for the sli4 hardware. The physical address
19178 * of the bpl/bde is converted back to a virtual address.
19179 * If the WQE contains a BPL then the list of BDE's is
19180 * converted to sli4_sge's. If the WQE contains a single
19181 * BDE then it is converted to a single sli_sge.
19182 * The WQE is still in cpu endianness so the contents of
19183 * the bpl can be used without byte swapping.
19185 * Returns valid XRI = Success, NO_XRI = Failure.
19188 lpfc_wqe_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pwqeq
,
19189 struct lpfc_sglq
*sglq
)
19191 uint16_t xritag
= NO_XRI
;
19192 struct ulp_bde64
*bpl
= NULL
;
19193 struct ulp_bde64 bde
;
19194 struct sli4_sge
*sgl
= NULL
;
19195 struct lpfc_dmabuf
*dmabuf
;
19196 union lpfc_wqe128
*wqe
;
19199 uint32_t offset
= 0; /* accumulated offset in the sg request list */
19200 int inbound
= 0; /* number of sg reply entries inbound from firmware */
19203 if (!pwqeq
|| !sglq
)
19206 sgl
= (struct sli4_sge
*)sglq
->sgl
;
19208 pwqeq
->iocb
.ulpIoTag
= pwqeq
->iotag
;
19210 cmd
= bf_get(wqe_cmnd
, &wqe
->generic
.wqe_com
);
19211 if (cmd
== CMD_XMIT_BLS_RSP64_WQE
)
19212 return sglq
->sli4_xritag
;
19213 numBdes
= pwqeq
->rsvd2
;
19215 /* The addrHigh and addrLow fields within the WQE
19216 * have not been byteswapped yet so there is no
19217 * need to swap them back.
19219 if (pwqeq
->context3
)
19220 dmabuf
= (struct lpfc_dmabuf
*)pwqeq
->context3
;
19224 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
19228 for (i
= 0; i
< numBdes
; i
++) {
19229 /* Should already be byte swapped. */
19230 sgl
->addr_hi
= bpl
->addrHigh
;
19231 sgl
->addr_lo
= bpl
->addrLow
;
19233 sgl
->word2
= le32_to_cpu(sgl
->word2
);
19234 if ((i
+1) == numBdes
)
19235 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
19237 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
19238 /* swap the size field back to the cpu so we
19239 * can assign it to the sgl.
19241 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
19242 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
19243 /* The offsets in the sgl need to be accumulated
19244 * separately for the request and reply lists.
19245 * The request is always first, the reply follows.
19248 case CMD_GEN_REQUEST64_WQE
:
19249 /* add up the reply sg entries */
19250 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
19252 /* first inbound? reset the offset */
19255 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
19256 bf_set(lpfc_sli4_sge_type
, sgl
,
19257 LPFC_SGE_TYPE_DATA
);
19258 offset
+= bde
.tus
.f
.bdeSize
;
19260 case CMD_FCP_TRSP64_WQE
:
19261 bf_set(lpfc_sli4_sge_offset
, sgl
, 0);
19262 bf_set(lpfc_sli4_sge_type
, sgl
,
19263 LPFC_SGE_TYPE_DATA
);
19265 case CMD_FCP_TSEND64_WQE
:
19266 case CMD_FCP_TRECEIVE64_WQE
:
19267 bf_set(lpfc_sli4_sge_type
, sgl
,
19268 bpl
->tus
.f
.bdeFlags
);
19272 offset
+= bde
.tus
.f
.bdeSize
;
19273 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
19276 sgl
->word2
= cpu_to_le32(sgl
->word2
);
19280 } else if (wqe
->gen_req
.bde
.tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64
) {
19281 /* The addrHigh and addrLow fields of the BDE have not
19282 * been byteswapped yet so they need to be swapped
19283 * before putting them in the sgl.
19285 sgl
->addr_hi
= cpu_to_le32(wqe
->gen_req
.bde
.addrHigh
);
19286 sgl
->addr_lo
= cpu_to_le32(wqe
->gen_req
.bde
.addrLow
);
19287 sgl
->word2
= le32_to_cpu(sgl
->word2
);
19288 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
19289 sgl
->word2
= cpu_to_le32(sgl
->word2
);
19290 sgl
->sge_len
= cpu_to_le32(wqe
->gen_req
.bde
.tus
.f
.bdeSize
);
19292 return sglq
->sli4_xritag
;
19296 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
19297 * @phba: Pointer to HBA context object.
19298 * @ring_number: Base sli ring number
19299 * @pwqe: Pointer to command WQE.
19302 lpfc_sli4_issue_wqe(struct lpfc_hba
*phba
, uint32_t ring_number
,
19303 struct lpfc_iocbq
*pwqe
)
19305 union lpfc_wqe128
*wqe
= &pwqe
->wqe
;
19306 struct lpfc_nvmet_rcv_ctx
*ctxp
;
19307 struct lpfc_queue
*wq
;
19308 struct lpfc_sglq
*sglq
;
19309 struct lpfc_sli_ring
*pring
;
19310 unsigned long iflags
;
19313 /* NVME_LS and NVME_LS ABTS requests. */
19314 if (pwqe
->iocb_flag
& LPFC_IO_NVME_LS
) {
19315 pring
= phba
->sli4_hba
.nvmels_wq
->pring
;
19316 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19317 sglq
= __lpfc_sli_get_els_sglq(phba
, pwqe
);
19319 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19322 pwqe
->sli4_lxritag
= sglq
->sli4_lxritag
;
19323 pwqe
->sli4_xritag
= sglq
->sli4_xritag
;
19324 if (lpfc_wqe_bpl2sgl(phba
, pwqe
, sglq
) == NO_XRI
) {
19325 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19328 bf_set(wqe_xri_tag
, &pwqe
->wqe
.xmit_bls_rsp
.wqe_com
,
19329 pwqe
->sli4_xritag
);
19330 ret
= lpfc_sli4_wq_put(phba
->sli4_hba
.nvmels_wq
, wqe
);
19332 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19336 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
19337 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19341 /* NVME_FCREQ and NVME_ABTS requests */
19342 if (pwqe
->iocb_flag
& LPFC_IO_NVME
) {
19343 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19344 pring
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
]->pring
;
19346 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19347 wq
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
];
19348 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
,
19349 phba
->sli4_hba
.nvme_cq
[pwqe
->hba_wqidx
]->queue_id
);
19350 ret
= lpfc_sli4_wq_put(wq
, wqe
);
19352 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19355 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
19356 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19360 /* NVMET requests */
19361 if (pwqe
->iocb_flag
& LPFC_IO_NVMET
) {
19362 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19363 pring
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
]->pring
;
19365 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19366 ctxp
= pwqe
->context2
;
19367 sglq
= ctxp
->ctxbuf
->sglq
;
19368 if (pwqe
->sli4_xritag
== NO_XRI
) {
19369 pwqe
->sli4_lxritag
= sglq
->sli4_lxritag
;
19370 pwqe
->sli4_xritag
= sglq
->sli4_xritag
;
19372 bf_set(wqe_xri_tag
, &pwqe
->wqe
.xmit_bls_rsp
.wqe_com
,
19373 pwqe
->sli4_xritag
);
19374 wq
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
];
19375 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
,
19376 phba
->sli4_hba
.nvme_cq
[pwqe
->hba_wqidx
]->queue_id
);
19377 ret
= lpfc_sli4_wq_put(wq
, wqe
);
19379 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19382 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
19383 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);