2 /*******************************************************************
3 * This file is part of the Emulex Linux Device Driver for *
4 * Fibre Channel Host Bus Adapters. *
5 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
6 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
7 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
8 * EMULEX and SLI are trademarks of Emulex. *
10 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
12 * This program is free software; you can redistribute it and/or *
13 * modify it under the terms of version 2 of the GNU General *
14 * Public License as published by the Free Software Foundation. *
15 * This program is distributed in the hope that it will be useful. *
16 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
17 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
18 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
19 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
20 * TO BE LEGALLY INVALID. See the GNU General Public License for *
21 * more details, a copy of which can be found in the file COPYING *
22 * included with this package. *
23 *******************************************************************/
25 #include <linux/blkdev.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/lockdep.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_cmnd.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
38 #include <linux/aer.h>
40 #include <linux/nvme-fc-driver.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_logmsg.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_debugfs.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_version.h"
59 /* There are only four IOCB completion types. */
60 typedef enum _lpfc_iocb_type
{
68 /* Provide function prototypes local to this module. */
69 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
71 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
72 uint8_t *, uint32_t *);
73 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
75 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
77 static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport
*vport
,
78 struct hbq_dmabuf
*dmabuf
);
79 static int lpfc_sli4_fp_handle_cqe(struct lpfc_hba
*, struct lpfc_queue
*,
81 static int lpfc_sli4_post_sgl_list(struct lpfc_hba
*, struct list_head
*,
83 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
,
84 struct lpfc_eqe
*eqe
, uint32_t qidx
);
85 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
);
86 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
);
87 static int lpfc_sli4_abort_nvme_io(struct lpfc_hba
*phba
,
88 struct lpfc_sli_ring
*pring
,
89 struct lpfc_iocbq
*cmdiocb
);
92 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
98 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
99 * @q: The Work Queue to operate on.
100 * @wqe: The work Queue Entry to put on the Work queue.
102 * This routine will copy the contents of @wqe to the next available entry on
103 * the @q. This function will then ring the Work Queue Doorbell to signal the
104 * HBA to start processing the Work Queue Entry. This function returns 0 if
105 * successful. If no entries are available on @q then this function will return
107 * The caller is expected to hold the hbalock when calling this routine.
110 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
112 union lpfc_wqe
*temp_wqe
;
113 struct lpfc_register doorbell
;
117 /* sanity check on queue memory */
120 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
122 /* If the host has not yet processed the next entry then we are done */
123 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
124 if (idx
== q
->hba_index
) {
129 /* set consumption flag every once in a while */
130 if (!((q
->host_index
+ 1) % q
->entry_repost
))
131 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
132 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
133 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
134 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
135 /* ensure WQE bcopy flushed before doorbell write */
138 /* Update the host index before invoking device */
139 host_index
= q
->host_index
;
145 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
146 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
147 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
, host_index
);
148 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
149 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
150 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
151 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
155 writel(doorbell
.word0
, q
->db_regaddr
);
161 * lpfc_sli4_wq_release - Updates internal hba index for WQ
162 * @q: The Work Queue to operate on.
163 * @index: The index to advance the hba index to.
165 * This routine will update the HBA index of a queue to reflect consumption of
166 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
167 * an entry the host calls this function to update the queue's internal
168 * pointers. This routine returns the number of entries that were consumed by
172 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
174 uint32_t released
= 0;
176 /* sanity check on queue memory */
180 if (q
->hba_index
== index
)
183 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
185 } while (q
->hba_index
!= index
);
190 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
191 * @q: The Mailbox Queue to operate on.
192 * @wqe: The Mailbox Queue Entry to put on the Work queue.
194 * This routine will copy the contents of @mqe to the next available entry on
195 * the @q. This function will then ring the Work Queue Doorbell to signal the
196 * HBA to start processing the Work Queue Entry. This function returns 0 if
197 * successful. If no entries are available on @q then this function will return
199 * The caller is expected to hold the hbalock when calling this routine.
202 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
204 struct lpfc_mqe
*temp_mqe
;
205 struct lpfc_register doorbell
;
207 /* sanity check on queue memory */
210 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
212 /* If the host has not yet processed the next entry then we are done */
213 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
215 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
216 /* Save off the mailbox pointer for completion */
217 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
219 /* Update the host index before invoking device */
220 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
224 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
225 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
226 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
231 * lpfc_sli4_mq_release - Updates internal hba index for MQ
232 * @q: The Mailbox Queue to operate on.
234 * This routine will update the HBA index of a queue to reflect consumption of
235 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
236 * an entry the host calls this function to update the queue's internal
237 * pointers. This routine returns the number of entries that were consumed by
241 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
243 /* sanity check on queue memory */
247 /* Clear the mailbox pointer for completion */
248 q
->phba
->mbox
= NULL
;
249 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
254 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
255 * @q: The Event Queue to get the first valid EQE from
257 * This routine will get the first valid Event Queue Entry from @q, update
258 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
259 * the Queue (no more work to do), or the Queue is full of EQEs that have been
260 * processed, but not popped back to the HBA then this routine will return NULL.
262 static struct lpfc_eqe
*
263 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
265 struct lpfc_eqe
*eqe
;
268 /* sanity check on queue memory */
271 eqe
= q
->qe
[q
->hba_index
].eqe
;
273 /* If the next EQE is not valid then we are done */
274 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
276 /* If the host has not yet processed the next entry then we are done */
277 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
278 if (idx
== q
->host_index
)
284 * insert barrier for instruction interlock : data from the hardware
285 * must have the valid bit checked before it can be copied and acted
286 * upon. Speculative instructions were allowing a bcopy at the start
287 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
288 * after our return, to copy data before the valid bit check above
289 * was done. As such, some of the copied data was stale. The barrier
290 * ensures the check is before any data is copied.
297 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
298 * @q: The Event Queue to disable interrupts
302 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
304 struct lpfc_register doorbell
;
307 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
308 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
309 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
310 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
311 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
312 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
316 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
317 * @q: The Event Queue that the host has completed processing for.
318 * @arm: Indicates whether the host wants to arms this CQ.
320 * This routine will mark all Event Queue Entries on @q, from the last
321 * known completed entry to the last entry that was processed, as completed
322 * by clearing the valid bit for each completion queue entry. Then it will
323 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
324 * The internal host index in the @q will be updated by this routine to indicate
325 * that the host has finished processing the entries. The @arm parameter
326 * indicates that the queue should be rearmed when ringing the doorbell.
328 * This function will return the number of EQEs that were popped.
331 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
333 uint32_t released
= 0;
334 struct lpfc_eqe
*temp_eqe
;
335 struct lpfc_register doorbell
;
337 /* sanity check on queue memory */
341 /* while there are valid entries */
342 while (q
->hba_index
!= q
->host_index
) {
343 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
344 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
346 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
348 if (unlikely(released
== 0 && !arm
))
351 /* ring doorbell for number popped */
354 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
355 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
357 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
358 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
359 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
360 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
361 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
362 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
363 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
364 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
365 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
370 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
371 * @q: The Completion Queue to get the first valid CQE from
373 * This routine will get the first valid Completion Queue Entry from @q, update
374 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
375 * the Queue (no more work to do), or the Queue is full of CQEs that have been
376 * processed, but not popped back to the HBA then this routine will return NULL.
378 static struct lpfc_cqe
*
379 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
381 struct lpfc_cqe
*cqe
;
384 /* sanity check on queue memory */
388 /* If the next CQE is not valid then we are done */
389 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
391 /* If the host has not yet processed the next entry then we are done */
392 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
393 if (idx
== q
->host_index
)
396 cqe
= q
->qe
[q
->hba_index
].cqe
;
400 * insert barrier for instruction interlock : data from the hardware
401 * must have the valid bit checked before it can be copied and acted
402 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
403 * instructions allowing action on content before valid bit checked,
404 * add barrier here as well. May not be needed as "content" is a
405 * single 32-bit entity here (vs multi word structure for cq's).
412 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
413 * @q: The Completion Queue that the host has completed processing for.
414 * @arm: Indicates whether the host wants to arms this CQ.
416 * This routine will mark all Completion queue entries on @q, from the last
417 * known completed entry to the last entry that was processed, as completed
418 * by clearing the valid bit for each completion queue entry. Then it will
419 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
420 * The internal host index in the @q will be updated by this routine to indicate
421 * that the host has finished processing the entries. The @arm parameter
422 * indicates that the queue should be rearmed when ringing the doorbell.
424 * This function will return the number of CQEs that were released.
427 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
429 uint32_t released
= 0;
430 struct lpfc_cqe
*temp_qe
;
431 struct lpfc_register doorbell
;
433 /* sanity check on queue memory */
436 /* while there are valid entries */
437 while (q
->hba_index
!= q
->host_index
) {
438 temp_qe
= q
->qe
[q
->host_index
].cqe
;
439 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
441 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
443 if (unlikely(released
== 0 && !arm
))
446 /* ring doorbell for number popped */
449 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
450 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
451 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
452 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
453 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
454 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
455 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
460 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
461 * @q: The Header Receive Queue to operate on.
462 * @wqe: The Receive Queue Entry to put on the Receive queue.
464 * This routine will copy the contents of @wqe to the next available entry on
465 * the @q. This function will then ring the Receive Queue Doorbell to signal the
466 * HBA to start processing the Receive Queue Entry. This function returns the
467 * index that the rqe was copied to if successful. If no entries are available
468 * on @q then this function will return -ENOMEM.
469 * The caller is expected to hold the hbalock when calling this routine.
472 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
473 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
475 struct lpfc_rqe
*temp_hrqe
;
476 struct lpfc_rqe
*temp_drqe
;
477 struct lpfc_register doorbell
;
480 /* sanity check on queue memory */
481 if (unlikely(!hq
) || unlikely(!dq
))
483 put_index
= hq
->host_index
;
484 temp_hrqe
= hq
->qe
[put_index
].rqe
;
485 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
487 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
489 if (put_index
!= dq
->host_index
)
491 /* If the host has not yet processed the next entry then we are done */
492 if (((put_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
494 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
495 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
497 /* Update the host index to point to the next slot */
498 hq
->host_index
= ((put_index
+ 1) % hq
->entry_count
);
499 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
502 /* Ring The Header Receive Queue Doorbell */
503 if (!(hq
->host_index
% hq
->entry_repost
)) {
505 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
506 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
508 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
509 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
510 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
512 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
514 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
518 writel(doorbell
.word0
, hq
->db_regaddr
);
524 * lpfc_sli4_rq_release - Updates internal hba index for RQ
525 * @q: The Header Receive Queue to operate on.
527 * This routine will update the HBA index of a queue to reflect consumption of
528 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
529 * consumed an entry the host calls this function to update the queue's
530 * internal pointers. This routine returns the number of entries that were
531 * consumed by the HBA.
534 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
536 /* sanity check on queue memory */
537 if (unlikely(!hq
) || unlikely(!dq
))
540 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
542 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
543 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
548 * lpfc_cmd_iocb - Get next command iocb entry in the ring
549 * @phba: Pointer to HBA context object.
550 * @pring: Pointer to driver SLI ring object.
552 * This function returns pointer to next command iocb entry
553 * in the command ring. The caller must hold hbalock to prevent
554 * other threads consume the next command iocb.
555 * SLI-2/SLI-3 provide different sized iocbs.
557 static inline IOCB_t
*
558 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
560 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
561 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
565 * lpfc_resp_iocb - Get next response iocb entry in the ring
566 * @phba: Pointer to HBA context object.
567 * @pring: Pointer to driver SLI ring object.
569 * This function returns pointer to next response iocb entry
570 * in the response ring. The caller must hold hbalock to make sure
571 * that no other thread consume the next response iocb.
572 * SLI-2/SLI-3 provide different sized iocbs.
574 static inline IOCB_t
*
575 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
577 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
578 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
582 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
583 * @phba: Pointer to HBA context object.
585 * This function is called with hbalock held. This function
586 * allocates a new driver iocb object from the iocb pool. If the
587 * allocation is successful, it returns pointer to the newly
588 * allocated iocb object else it returns NULL.
591 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
593 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
594 struct lpfc_iocbq
* iocbq
= NULL
;
596 lockdep_assert_held(&phba
->hbalock
);
598 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
601 if (phba
->iocb_cnt
> phba
->iocb_max
)
602 phba
->iocb_max
= phba
->iocb_cnt
;
607 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
608 * @phba: Pointer to HBA context object.
609 * @xritag: XRI value.
611 * This function clears the sglq pointer from the array of acive
612 * sglq's. The xritag that is passed in is used to index into the
613 * array. Before the xritag can be used it needs to be adjusted
614 * by subtracting the xribase.
616 * Returns sglq ponter = success, NULL = Failure.
619 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
621 struct lpfc_sglq
*sglq
;
623 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
624 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
629 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
630 * @phba: Pointer to HBA context object.
631 * @xritag: XRI value.
633 * This function returns the sglq pointer from the array of acive
634 * sglq's. The xritag that is passed in is used to index into the
635 * array. Before the xritag can be used it needs to be adjusted
636 * by subtracting the xribase.
638 * Returns sglq ponter = success, NULL = Failure.
641 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
643 struct lpfc_sglq
*sglq
;
645 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
650 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
651 * @phba: Pointer to HBA context object.
652 * @xritag: xri used in this exchange.
653 * @rrq: The RRQ to be cleared.
657 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
659 struct lpfc_node_rrq
*rrq
)
661 struct lpfc_nodelist
*ndlp
= NULL
;
663 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
664 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
666 /* The target DID could have been swapped (cable swap)
667 * we should use the ndlp from the findnode if it is
670 if ((!ndlp
) && rrq
->ndlp
)
676 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
)) {
679 rrq
->rrq_stop_time
= 0;
682 mempool_free(rrq
, phba
->rrq_pool
);
686 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
687 * @phba: Pointer to HBA context object.
689 * This function is called with hbalock held. This function
690 * Checks if stop_time (ratov from setting rrq active) has
691 * been reached, if it has and the send_rrq flag is set then
692 * it will call lpfc_send_rrq. If the send_rrq flag is not set
693 * then it will just call the routine to clear the rrq and
694 * free the rrq resource.
695 * The timer is set to the next rrq that is going to expire before
696 * leaving the routine.
700 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
702 struct lpfc_node_rrq
*rrq
;
703 struct lpfc_node_rrq
*nextrrq
;
704 unsigned long next_time
;
705 unsigned long iflags
;
708 spin_lock_irqsave(&phba
->hbalock
, iflags
);
709 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
710 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
711 list_for_each_entry_safe(rrq
, nextrrq
,
712 &phba
->active_rrq_list
, list
) {
713 if (time_after(jiffies
, rrq
->rrq_stop_time
))
714 list_move(&rrq
->list
, &send_rrq
);
715 else if (time_before(rrq
->rrq_stop_time
, next_time
))
716 next_time
= rrq
->rrq_stop_time
;
718 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
719 if ((!list_empty(&phba
->active_rrq_list
)) &&
720 (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
721 mod_timer(&phba
->rrq_tmr
, next_time
);
722 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
723 list_del(&rrq
->list
);
725 /* this call will free the rrq */
726 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
727 else if (lpfc_send_rrq(phba
, rrq
)) {
728 /* if we send the rrq then the completion handler
729 * will clear the bit in the xribitmap.
731 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
738 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
739 * @vport: Pointer to vport context object.
740 * @xri: The xri used in the exchange.
741 * @did: The targets DID for this exchange.
743 * returns NULL = rrq not found in the phba->active_rrq_list.
744 * rrq = rrq for this xri and target.
746 struct lpfc_node_rrq
*
747 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
749 struct lpfc_hba
*phba
= vport
->phba
;
750 struct lpfc_node_rrq
*rrq
;
751 struct lpfc_node_rrq
*nextrrq
;
752 unsigned long iflags
;
754 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
756 spin_lock_irqsave(&phba
->hbalock
, iflags
);
757 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
758 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
759 rrq
->nlp_DID
== did
){
760 list_del(&rrq
->list
);
761 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
765 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
770 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
771 * @vport: Pointer to vport context object.
772 * @ndlp: Pointer to the lpfc_node_list structure.
773 * If ndlp is NULL Remove all active RRQs for this vport from the
774 * phba->active_rrq_list and clear the rrq.
775 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
778 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
781 struct lpfc_hba
*phba
= vport
->phba
;
782 struct lpfc_node_rrq
*rrq
;
783 struct lpfc_node_rrq
*nextrrq
;
784 unsigned long iflags
;
787 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
790 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
791 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
793 spin_lock_irqsave(&phba
->hbalock
, iflags
);
794 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
795 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
796 list_move(&rrq
->list
, &rrq_list
);
797 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
799 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
800 list_del(&rrq
->list
);
801 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
806 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
807 * @phba: Pointer to HBA context object.
808 * @ndlp: Targets nodelist pointer for this exchange.
809 * @xritag the xri in the bitmap to test.
811 * This function is called with hbalock held. This function
812 * returns 0 = rrq not active for this xri
813 * 1 = rrq is valid for this xri.
816 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
819 lockdep_assert_held(&phba
->hbalock
);
822 if (!ndlp
->active_rrqs_xri_bitmap
)
824 if (test_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
831 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
832 * @phba: Pointer to HBA context object.
833 * @ndlp: nodelist pointer for this target.
834 * @xritag: xri used in this exchange.
835 * @rxid: Remote Exchange ID.
836 * @send_rrq: Flag used to determine if we should send rrq els cmd.
838 * This function takes the hbalock.
839 * The active bit is always set in the active rrq xri_bitmap even
840 * if there is no slot avaiable for the other rrq information.
842 * returns 0 rrq actived for this xri
843 * < 0 No memory or invalid ndlp.
846 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
847 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
849 unsigned long iflags
;
850 struct lpfc_node_rrq
*rrq
;
856 if (!phba
->cfg_enable_rrq
)
859 spin_lock_irqsave(&phba
->hbalock
, iflags
);
860 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
861 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
866 * set the active bit even if there is no mem available.
868 if (NLP_CHK_FREE_REQ(ndlp
))
871 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
874 if (!ndlp
->active_rrqs_xri_bitmap
)
877 if (test_and_set_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
880 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
881 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
883 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
884 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
885 " DID:0x%x Send:%d\n",
886 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
889 if (phba
->cfg_enable_rrq
== 1)
890 rrq
->send_rrq
= send_rrq
;
893 rrq
->xritag
= xritag
;
894 rrq
->rrq_stop_time
= jiffies
+
895 msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
897 rrq
->nlp_DID
= ndlp
->nlp_DID
;
898 rrq
->vport
= ndlp
->vport
;
900 spin_lock_irqsave(&phba
->hbalock
, iflags
);
901 empty
= list_empty(&phba
->active_rrq_list
);
902 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
903 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
905 lpfc_worker_wake_up(phba
);
906 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
909 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
910 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
911 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
912 " DID:0x%x Send:%d\n",
913 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
918 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
919 * @phba: Pointer to HBA context object.
920 * @piocb: Pointer to the iocbq.
922 * This function is called with the ring lock held. This function
923 * gets a new driver sglq object from the sglq list. If the
924 * list is not empty then it is successful, it returns pointer to the newly
925 * allocated sglq object else it returns NULL.
927 static struct lpfc_sglq
*
928 __lpfc_sli_get_els_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
930 struct list_head
*lpfc_els_sgl_list
= &phba
->sli4_hba
.lpfc_els_sgl_list
;
931 struct lpfc_sglq
*sglq
= NULL
;
932 struct lpfc_sglq
*start_sglq
= NULL
;
933 struct lpfc_scsi_buf
*lpfc_cmd
;
934 struct lpfc_nodelist
*ndlp
;
937 lockdep_assert_held(&phba
->hbalock
);
939 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
940 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
941 ndlp
= lpfc_cmd
->rdata
->pnode
;
942 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
943 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
944 ndlp
= piocbq
->context_un
.ndlp
;
945 } else if (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
946 if (piocbq
->iocb_flag
& LPFC_IO_LOOPBACK
)
949 ndlp
= piocbq
->context_un
.ndlp
;
951 ndlp
= piocbq
->context1
;
954 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
955 list_remove_head(lpfc_els_sgl_list
, sglq
, struct lpfc_sglq
, list
);
960 if (ndlp
&& ndlp
->active_rrqs_xri_bitmap
&&
961 test_bit(sglq
->sli4_lxritag
,
962 ndlp
->active_rrqs_xri_bitmap
)) {
963 /* This xri has an rrq outstanding for this DID.
964 * put it back in the list and get another xri.
966 list_add_tail(&sglq
->list
, lpfc_els_sgl_list
);
968 list_remove_head(lpfc_els_sgl_list
, sglq
,
969 struct lpfc_sglq
, list
);
970 if (sglq
== start_sglq
) {
971 list_add_tail(&sglq
->list
, lpfc_els_sgl_list
);
979 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
980 sglq
->state
= SGL_ALLOCATED
;
982 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
987 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
988 * @phba: Pointer to HBA context object.
989 * @piocb: Pointer to the iocbq.
991 * This function is called with the sgl_list lock held. This function
992 * gets a new driver sglq object from the sglq list. If the
993 * list is not empty then it is successful, it returns pointer to the newly
994 * allocated sglq object else it returns NULL.
997 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
999 struct list_head
*lpfc_nvmet_sgl_list
;
1000 struct lpfc_sglq
*sglq
= NULL
;
1002 lpfc_nvmet_sgl_list
= &phba
->sli4_hba
.lpfc_nvmet_sgl_list
;
1004 lockdep_assert_held(&phba
->sli4_hba
.sgl_list_lock
);
1006 list_remove_head(lpfc_nvmet_sgl_list
, sglq
, struct lpfc_sglq
, list
);
1009 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
1010 sglq
->state
= SGL_ALLOCATED
;
1015 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1016 * @phba: Pointer to HBA context object.
1018 * This function is called with no lock held. This function
1019 * allocates a new driver iocb object from the iocb pool. If the
1020 * allocation is successful, it returns pointer to the newly
1021 * allocated iocb object else it returns NULL.
1024 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
1026 struct lpfc_iocbq
* iocbq
= NULL
;
1027 unsigned long iflags
;
1029 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1030 iocbq
= __lpfc_sli_get_iocbq(phba
);
1031 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1036 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1037 * @phba: Pointer to HBA context object.
1038 * @iocbq: Pointer to driver iocb object.
1040 * This function is called with hbalock held to release driver
1041 * iocb object to the iocb pool. The iotag in the iocb object
1042 * does not change for each use of the iocb object. This function
1043 * clears all other fields of the iocb object when it is freed.
1044 * The sqlq structure that holds the xritag and phys and virtual
1045 * mappings for the scatter gather list is retrieved from the
1046 * active array of sglq. The get of the sglq pointer also clears
1047 * the entry in the array. If the status of the IO indiactes that
1048 * this IO was aborted then the sglq entry it put on the
1049 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1050 * IO has good status or fails for any other reason then the sglq
1051 * entry is added to the free list (lpfc_els_sgl_list).
1054 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1056 struct lpfc_sglq
*sglq
;
1057 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1058 unsigned long iflag
= 0;
1059 struct lpfc_sli_ring
*pring
;
1061 lockdep_assert_held(&phba
->hbalock
);
1063 if (iocbq
->sli4_xritag
== NO_XRI
)
1066 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1070 if (iocbq
->iocb_flag
& LPFC_IO_NVMET
) {
1071 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1073 sglq
->state
= SGL_FREED
;
1075 list_add_tail(&sglq
->list
,
1076 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
1077 spin_unlock_irqrestore(
1078 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1082 pring
= phba
->sli4_hba
.els_wq
->pring
;
1083 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1084 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1085 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1087 list_add(&sglq
->list
,
1088 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1089 spin_unlock_irqrestore(
1090 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1092 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1094 sglq
->state
= SGL_FREED
;
1096 list_add_tail(&sglq
->list
,
1097 &phba
->sli4_hba
.lpfc_els_sgl_list
);
1098 spin_unlock_irqrestore(
1099 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1101 /* Check if TXQ queue needs to be serviced */
1102 if (!list_empty(&pring
->txq
))
1103 lpfc_worker_wake_up(phba
);
1109 * Clean all volatile data fields, preserve iotag and node struct.
1111 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1112 iocbq
->sli4_lxritag
= NO_XRI
;
1113 iocbq
->sli4_xritag
= NO_XRI
;
1114 iocbq
->iocb_flag
&= ~(LPFC_IO_NVME
| LPFC_IO_NVMET
|
1116 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1121 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1122 * @phba: Pointer to HBA context object.
1123 * @iocbq: Pointer to driver iocb object.
1125 * This function is called with hbalock held to release driver
1126 * iocb object to the iocb pool. The iotag in the iocb object
1127 * does not change for each use of the iocb object. This function
1128 * clears all other fields of the iocb object when it is freed.
1131 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1133 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1135 lockdep_assert_held(&phba
->hbalock
);
1138 * Clean all volatile data fields, preserve iotag and node struct.
1140 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1141 iocbq
->sli4_xritag
= NO_XRI
;
1142 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1146 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1147 * @phba: Pointer to HBA context object.
1148 * @iocbq: Pointer to driver iocb object.
1150 * This function is called with hbalock held to release driver
1151 * iocb object to the iocb pool. The iotag in the iocb object
1152 * does not change for each use of the iocb object. This function
1153 * clears all other fields of the iocb object when it is freed.
1156 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1158 lockdep_assert_held(&phba
->hbalock
);
1160 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1165 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1166 * @phba: Pointer to HBA context object.
1167 * @iocbq: Pointer to driver iocb object.
1169 * This function is called with no lock held to release the iocb to
1173 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1175 unsigned long iflags
;
1178 * Clean all volatile data fields, preserve iotag and node struct.
1180 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1181 __lpfc_sli_release_iocbq(phba
, iocbq
);
1182 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1186 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1187 * @phba: Pointer to HBA context object.
1188 * @iocblist: List of IOCBs.
1189 * @ulpstatus: ULP status in IOCB command field.
1190 * @ulpWord4: ULP word-4 in IOCB command field.
1192 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1193 * on the list by invoking the complete callback function associated with the
1194 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1198 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1199 uint32_t ulpstatus
, uint32_t ulpWord4
)
1201 struct lpfc_iocbq
*piocb
;
1203 while (!list_empty(iocblist
)) {
1204 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1205 if (!piocb
->iocb_cmpl
)
1206 lpfc_sli_release_iocbq(phba
, piocb
);
1208 piocb
->iocb
.ulpStatus
= ulpstatus
;
1209 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1210 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1217 * lpfc_sli_iocb_cmd_type - Get the iocb type
1218 * @iocb_cmnd: iocb command code.
1220 * This function is called by ring event handler function to get the iocb type.
1221 * This function translates the iocb command to an iocb command type used to
1222 * decide the final disposition of each completed IOCB.
1223 * The function returns
1224 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1225 * LPFC_SOL_IOCB if it is a solicited iocb completion
1226 * LPFC_ABORT_IOCB if it is an abort iocb
1227 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1229 * The caller is not required to hold any lock.
1231 static lpfc_iocb_type
1232 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1234 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1236 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1239 switch (iocb_cmnd
) {
1240 case CMD_XMIT_SEQUENCE_CR
:
1241 case CMD_XMIT_SEQUENCE_CX
:
1242 case CMD_XMIT_BCAST_CN
:
1243 case CMD_XMIT_BCAST_CX
:
1244 case CMD_ELS_REQUEST_CR
:
1245 case CMD_ELS_REQUEST_CX
:
1246 case CMD_CREATE_XRI_CR
:
1247 case CMD_CREATE_XRI_CX
:
1248 case CMD_GET_RPI_CN
:
1249 case CMD_XMIT_ELS_RSP_CX
:
1250 case CMD_GET_RPI_CR
:
1251 case CMD_FCP_IWRITE_CR
:
1252 case CMD_FCP_IWRITE_CX
:
1253 case CMD_FCP_IREAD_CR
:
1254 case CMD_FCP_IREAD_CX
:
1255 case CMD_FCP_ICMND_CR
:
1256 case CMD_FCP_ICMND_CX
:
1257 case CMD_FCP_TSEND_CX
:
1258 case CMD_FCP_TRSP_CX
:
1259 case CMD_FCP_TRECEIVE_CX
:
1260 case CMD_FCP_AUTO_TRSP_CX
:
1261 case CMD_ADAPTER_MSG
:
1262 case CMD_ADAPTER_DUMP
:
1263 case CMD_XMIT_SEQUENCE64_CR
:
1264 case CMD_XMIT_SEQUENCE64_CX
:
1265 case CMD_XMIT_BCAST64_CN
:
1266 case CMD_XMIT_BCAST64_CX
:
1267 case CMD_ELS_REQUEST64_CR
:
1268 case CMD_ELS_REQUEST64_CX
:
1269 case CMD_FCP_IWRITE64_CR
:
1270 case CMD_FCP_IWRITE64_CX
:
1271 case CMD_FCP_IREAD64_CR
:
1272 case CMD_FCP_IREAD64_CX
:
1273 case CMD_FCP_ICMND64_CR
:
1274 case CMD_FCP_ICMND64_CX
:
1275 case CMD_FCP_TSEND64_CX
:
1276 case CMD_FCP_TRSP64_CX
:
1277 case CMD_FCP_TRECEIVE64_CX
:
1278 case CMD_GEN_REQUEST64_CR
:
1279 case CMD_GEN_REQUEST64_CX
:
1280 case CMD_XMIT_ELS_RSP64_CX
:
1281 case DSSCMD_IWRITE64_CR
:
1282 case DSSCMD_IWRITE64_CX
:
1283 case DSSCMD_IREAD64_CR
:
1284 case DSSCMD_IREAD64_CX
:
1285 type
= LPFC_SOL_IOCB
;
1287 case CMD_ABORT_XRI_CN
:
1288 case CMD_ABORT_XRI_CX
:
1289 case CMD_CLOSE_XRI_CN
:
1290 case CMD_CLOSE_XRI_CX
:
1291 case CMD_XRI_ABORTED_CX
:
1292 case CMD_ABORT_MXRI64_CN
:
1293 case CMD_XMIT_BLS_RSP64_CX
:
1294 type
= LPFC_ABORT_IOCB
;
1296 case CMD_RCV_SEQUENCE_CX
:
1297 case CMD_RCV_ELS_REQ_CX
:
1298 case CMD_RCV_SEQUENCE64_CX
:
1299 case CMD_RCV_ELS_REQ64_CX
:
1300 case CMD_ASYNC_STATUS
:
1301 case CMD_IOCB_RCV_SEQ64_CX
:
1302 case CMD_IOCB_RCV_ELS64_CX
:
1303 case CMD_IOCB_RCV_CONT64_CX
:
1304 case CMD_IOCB_RET_XRI64_CX
:
1305 type
= LPFC_UNSOL_IOCB
;
1307 case CMD_IOCB_XMIT_MSEQ64_CR
:
1308 case CMD_IOCB_XMIT_MSEQ64_CX
:
1309 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1310 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1311 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1312 case CMD_IOCB_ABORT_EXTENDED_CN
:
1313 case CMD_IOCB_RET_HBQE64_CN
:
1314 case CMD_IOCB_FCP_IBIDIR64_CR
:
1315 case CMD_IOCB_FCP_IBIDIR64_CX
:
1316 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1317 case CMD_IOCB_LOGENTRY_CN
:
1318 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1319 printk("%s - Unhandled SLI-3 Command x%x\n",
1320 __func__
, iocb_cmnd
);
1321 type
= LPFC_UNKNOWN_IOCB
;
1324 type
= LPFC_UNKNOWN_IOCB
;
1332 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1333 * @phba: Pointer to HBA context object.
1335 * This function is called from SLI initialization code
1336 * to configure every ring of the HBA's SLI interface. The
1337 * caller is not required to hold any lock. This function issues
1338 * a config_ring mailbox command for each ring.
1339 * This function returns zero if successful else returns a negative
1343 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1345 struct lpfc_sli
*psli
= &phba
->sli
;
1350 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1354 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1355 for (i
= 0; i
< psli
->num_rings
; i
++) {
1356 lpfc_config_ring(phba
, i
, pmb
);
1357 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1358 if (rc
!= MBX_SUCCESS
) {
1359 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1360 "0446 Adapter failed to init (%d), "
1361 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1363 rc
, pmbox
->mbxCommand
,
1364 pmbox
->mbxStatus
, i
);
1365 phba
->link_state
= LPFC_HBA_ERROR
;
1370 mempool_free(pmb
, phba
->mbox_mem_pool
);
1375 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1376 * @phba: Pointer to HBA context object.
1377 * @pring: Pointer to driver SLI ring object.
1378 * @piocb: Pointer to the driver iocb object.
1380 * This function is called with hbalock held. The function adds the
1381 * new iocb to txcmplq of the given ring. This function always returns
1382 * 0. If this function is called for ELS ring, this function checks if
1383 * there is a vport associated with the ELS command. This function also
1384 * starts els_tmofunc timer if this is an ELS command.
1387 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1388 struct lpfc_iocbq
*piocb
)
1390 lockdep_assert_held(&phba
->hbalock
);
1394 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1395 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1397 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1398 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1399 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1400 BUG_ON(!piocb
->vport
);
1401 if (!(piocb
->vport
->load_flag
& FC_UNLOADING
))
1402 mod_timer(&piocb
->vport
->els_tmofunc
,
1404 msecs_to_jiffies(1000 * (phba
->fc_ratov
<< 1)));
1411 * lpfc_sli_ringtx_get - Get first element of the txq
1412 * @phba: Pointer to HBA context object.
1413 * @pring: Pointer to driver SLI ring object.
1415 * This function is called with hbalock held to get next
1416 * iocb in txq of the given ring. If there is any iocb in
1417 * the txq, the function returns first iocb in the list after
1418 * removing the iocb from the list, else it returns NULL.
1421 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1423 struct lpfc_iocbq
*cmd_iocb
;
1425 lockdep_assert_held(&phba
->hbalock
);
1427 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1432 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1433 * @phba: Pointer to HBA context object.
1434 * @pring: Pointer to driver SLI ring object.
1436 * This function is called with hbalock held and the caller must post the
1437 * iocb without releasing the lock. If the caller releases the lock,
1438 * iocb slot returned by the function is not guaranteed to be available.
1439 * The function returns pointer to the next available iocb slot if there
1440 * is available slot in the ring, else it returns NULL.
1441 * If the get index of the ring is ahead of the put index, the function
1442 * will post an error attention event to the worker thread to take the
1443 * HBA to offline state.
1446 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1448 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1449 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1451 lockdep_assert_held(&phba
->hbalock
);
1453 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1454 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1455 pring
->sli
.sli3
.next_cmdidx
= 0;
1457 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1458 pring
->sli
.sli3
.next_cmdidx
)) {
1460 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1462 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1463 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1464 "0315 Ring %d issue: portCmdGet %d "
1465 "is bigger than cmd ring %d\n",
1467 pring
->sli
.sli3
.local_getidx
,
1470 phba
->link_state
= LPFC_HBA_ERROR
;
1472 * All error attention handlers are posted to
1475 phba
->work_ha
|= HA_ERATT
;
1476 phba
->work_hs
= HS_FFER3
;
1478 lpfc_worker_wake_up(phba
);
1483 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1487 return lpfc_cmd_iocb(phba
, pring
);
1491 * lpfc_sli_next_iotag - Get an iotag for the iocb
1492 * @phba: Pointer to HBA context object.
1493 * @iocbq: Pointer to driver iocb object.
1495 * This function gets an iotag for the iocb. If there is no unused iotag and
1496 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1497 * array and assigns a new iotag.
1498 * The function returns the allocated iotag if successful, else returns zero.
1499 * Zero is not a valid iotag.
1500 * The caller is not required to hold any lock.
1503 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1505 struct lpfc_iocbq
**new_arr
;
1506 struct lpfc_iocbq
**old_arr
;
1508 struct lpfc_sli
*psli
= &phba
->sli
;
1511 spin_lock_irq(&phba
->hbalock
);
1512 iotag
= psli
->last_iotag
;
1513 if(++iotag
< psli
->iocbq_lookup_len
) {
1514 psli
->last_iotag
= iotag
;
1515 psli
->iocbq_lookup
[iotag
] = iocbq
;
1516 spin_unlock_irq(&phba
->hbalock
);
1517 iocbq
->iotag
= iotag
;
1519 } else if (psli
->iocbq_lookup_len
< (0xffff
1520 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1521 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1522 spin_unlock_irq(&phba
->hbalock
);
1523 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1526 spin_lock_irq(&phba
->hbalock
);
1527 old_arr
= psli
->iocbq_lookup
;
1528 if (new_len
<= psli
->iocbq_lookup_len
) {
1529 /* highly unprobable case */
1531 iotag
= psli
->last_iotag
;
1532 if(++iotag
< psli
->iocbq_lookup_len
) {
1533 psli
->last_iotag
= iotag
;
1534 psli
->iocbq_lookup
[iotag
] = iocbq
;
1535 spin_unlock_irq(&phba
->hbalock
);
1536 iocbq
->iotag
= iotag
;
1539 spin_unlock_irq(&phba
->hbalock
);
1542 if (psli
->iocbq_lookup
)
1543 memcpy(new_arr
, old_arr
,
1544 ((psli
->last_iotag
+ 1) *
1545 sizeof (struct lpfc_iocbq
*)));
1546 psli
->iocbq_lookup
= new_arr
;
1547 psli
->iocbq_lookup_len
= new_len
;
1548 psli
->last_iotag
= iotag
;
1549 psli
->iocbq_lookup
[iotag
] = iocbq
;
1550 spin_unlock_irq(&phba
->hbalock
);
1551 iocbq
->iotag
= iotag
;
1556 spin_unlock_irq(&phba
->hbalock
);
1558 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1559 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1566 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1567 * @phba: Pointer to HBA context object.
1568 * @pring: Pointer to driver SLI ring object.
1569 * @iocb: Pointer to iocb slot in the ring.
1570 * @nextiocb: Pointer to driver iocb object which need to be
1571 * posted to firmware.
1573 * This function is called with hbalock held to post a new iocb to
1574 * the firmware. This function copies the new iocb to ring iocb slot and
1575 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1576 * a completion call back for this iocb else the function will free the
1580 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1581 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1583 lockdep_assert_held(&phba
->hbalock
);
1587 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1590 if (pring
->ringno
== LPFC_ELS_RING
) {
1591 lpfc_debugfs_slow_ring_trc(phba
,
1592 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1593 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1594 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1595 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1599 * Issue iocb command to adapter
1601 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1603 pring
->stats
.iocb_cmd
++;
1606 * If there is no completion routine to call, we can release the
1607 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1608 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1610 if (nextiocb
->iocb_cmpl
)
1611 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1613 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1616 * Let the HBA know what IOCB slot will be the next one the
1617 * driver will put a command into.
1619 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1620 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1624 * lpfc_sli_update_full_ring - Update the chip attention register
1625 * @phba: Pointer to HBA context object.
1626 * @pring: Pointer to driver SLI ring object.
1628 * The caller is not required to hold any lock for calling this function.
1629 * This function updates the chip attention bits for the ring to inform firmware
1630 * that there are pending work to be done for this ring and requests an
1631 * interrupt when there is space available in the ring. This function is
1632 * called when the driver is unable to post more iocbs to the ring due
1633 * to unavailability of space in the ring.
1636 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1638 int ringno
= pring
->ringno
;
1640 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1645 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1646 * The HBA will tell us when an IOCB entry is available.
1648 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1649 readl(phba
->CAregaddr
); /* flush */
1651 pring
->stats
.iocb_cmd_full
++;
1655 * lpfc_sli_update_ring - Update chip attention register
1656 * @phba: Pointer to HBA context object.
1657 * @pring: Pointer to driver SLI ring object.
1659 * This function updates the chip attention register bit for the
1660 * given ring to inform HBA that there is more work to be done
1661 * in this ring. The caller is not required to hold any lock.
1664 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1666 int ringno
= pring
->ringno
;
1669 * Tell the HBA that there is work to do in this ring.
1671 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1673 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1674 readl(phba
->CAregaddr
); /* flush */
1679 * lpfc_sli_resume_iocb - Process iocbs in the txq
1680 * @phba: Pointer to HBA context object.
1681 * @pring: Pointer to driver SLI ring object.
1683 * This function is called with hbalock held to post pending iocbs
1684 * in the txq to the firmware. This function is called when driver
1685 * detects space available in the ring.
1688 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1691 struct lpfc_iocbq
*nextiocb
;
1693 lockdep_assert_held(&phba
->hbalock
);
1697 * (a) there is anything on the txq to send
1699 * (c) link attention events can be processed (fcp ring only)
1700 * (d) IOCB processing is not blocked by the outstanding mbox command.
1703 if (lpfc_is_link_up(phba
) &&
1704 (!list_empty(&pring
->txq
)) &&
1705 (pring
->ringno
!= LPFC_FCP_RING
||
1706 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1708 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1709 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1710 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1713 lpfc_sli_update_ring(phba
, pring
);
1715 lpfc_sli_update_full_ring(phba
, pring
);
1722 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1723 * @phba: Pointer to HBA context object.
1724 * @hbqno: HBQ number.
1726 * This function is called with hbalock held to get the next
1727 * available slot for the given HBQ. If there is free slot
1728 * available for the HBQ it will return pointer to the next available
1729 * HBQ entry else it will return NULL.
1731 static struct lpfc_hbq_entry
*
1732 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1734 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1736 lockdep_assert_held(&phba
->hbalock
);
1738 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1739 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1740 hbqp
->next_hbqPutIdx
= 0;
1742 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1743 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1744 uint32_t getidx
= le32_to_cpu(raw_index
);
1746 hbqp
->local_hbqGetIdx
= getidx
;
1748 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1749 lpfc_printf_log(phba
, KERN_ERR
,
1750 LOG_SLI
| LOG_VPORT
,
1751 "1802 HBQ %d: local_hbqGetIdx "
1752 "%u is > than hbqp->entry_count %u\n",
1753 hbqno
, hbqp
->local_hbqGetIdx
,
1756 phba
->link_state
= LPFC_HBA_ERROR
;
1760 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1764 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1769 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1770 * @phba: Pointer to HBA context object.
1772 * This function is called with no lock held to free all the
1773 * hbq buffers while uninitializing the SLI interface. It also
1774 * frees the HBQ buffers returned by the firmware but not yet
1775 * processed by the upper layers.
1778 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1780 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1781 struct hbq_dmabuf
*hbq_buf
;
1782 unsigned long flags
;
1785 hbq_count
= lpfc_sli_hbq_count();
1786 /* Return all memory used by all HBQs */
1787 spin_lock_irqsave(&phba
->hbalock
, flags
);
1788 for (i
= 0; i
< hbq_count
; ++i
) {
1789 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1790 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1791 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1792 list_del(&hbq_buf
->dbuf
.list
);
1793 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1795 phba
->hbqs
[i
].buffer_count
= 0;
1798 /* Mark the HBQs not in use */
1799 phba
->hbq_in_use
= 0;
1800 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1804 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1805 * @phba: Pointer to HBA context object.
1806 * @hbqno: HBQ number.
1807 * @hbq_buf: Pointer to HBQ buffer.
1809 * This function is called with the hbalock held to post a
1810 * hbq buffer to the firmware. If the function finds an empty
1811 * slot in the HBQ, it will post the buffer. The function will return
1812 * pointer to the hbq entry if it successfully post the buffer
1813 * else it will return NULL.
1816 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1817 struct hbq_dmabuf
*hbq_buf
)
1819 lockdep_assert_held(&phba
->hbalock
);
1820 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1824 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1825 * @phba: Pointer to HBA context object.
1826 * @hbqno: HBQ number.
1827 * @hbq_buf: Pointer to HBQ buffer.
1829 * This function is called with the hbalock held to post a hbq buffer to the
1830 * firmware. If the function finds an empty slot in the HBQ, it will post the
1831 * buffer and place it on the hbq_buffer_list. The function will return zero if
1832 * it successfully post the buffer else it will return an error.
1835 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1836 struct hbq_dmabuf
*hbq_buf
)
1838 struct lpfc_hbq_entry
*hbqe
;
1839 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1841 lockdep_assert_held(&phba
->hbalock
);
1842 /* Get next HBQ entry slot to use */
1843 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1845 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1847 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1848 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1849 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->total_size
;
1850 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1851 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1852 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1854 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1855 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1857 readl(phba
->hbq_put
+ hbqno
);
1858 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1865 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1866 * @phba: Pointer to HBA context object.
1867 * @hbqno: HBQ number.
1868 * @hbq_buf: Pointer to HBQ buffer.
1870 * This function is called with the hbalock held to post an RQE to the SLI4
1871 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1872 * the hbq_buffer_list and return zero, otherwise it will return an error.
1875 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1876 struct hbq_dmabuf
*hbq_buf
)
1879 struct lpfc_rqe hrqe
;
1880 struct lpfc_rqe drqe
;
1881 struct lpfc_queue
*hrq
;
1882 struct lpfc_queue
*drq
;
1884 if (hbqno
!= LPFC_ELS_HBQ
)
1886 hrq
= phba
->sli4_hba
.hdr_rq
;
1887 drq
= phba
->sli4_hba
.dat_rq
;
1889 lockdep_assert_held(&phba
->hbalock
);
1890 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1891 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1892 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1893 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1894 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
1897 hbq_buf
->tag
= (rc
| (hbqno
<< 16));
1898 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1902 /* HBQ for ELS and CT traffic. */
1903 static struct lpfc_hbq_init lpfc_els_hbq
= {
1908 .ring_mask
= (1 << LPFC_ELS_RING
),
1915 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1920 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1921 * @phba: Pointer to HBA context object.
1922 * @hbqno: HBQ number.
1923 * @count: Number of HBQ buffers to be posted.
1925 * This function is called with no lock held to post more hbq buffers to the
1926 * given HBQ. The function returns the number of HBQ buffers successfully
1930 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1932 uint32_t i
, posted
= 0;
1933 unsigned long flags
;
1934 struct hbq_dmabuf
*hbq_buffer
;
1935 LIST_HEAD(hbq_buf_list
);
1936 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1939 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1940 lpfc_hbq_defs
[hbqno
]->entry_count
)
1941 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1942 phba
->hbqs
[hbqno
].buffer_count
;
1945 /* Allocate HBQ entries */
1946 for (i
= 0; i
< count
; i
++) {
1947 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1950 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1952 /* Check whether HBQ is still in use */
1953 spin_lock_irqsave(&phba
->hbalock
, flags
);
1954 if (!phba
->hbq_in_use
)
1956 while (!list_empty(&hbq_buf_list
)) {
1957 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1959 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1961 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1962 phba
->hbqs
[hbqno
].buffer_count
++;
1965 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1967 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1970 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1971 while (!list_empty(&hbq_buf_list
)) {
1972 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1974 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1980 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1981 * @phba: Pointer to HBA context object.
1984 * This function posts more buffers to the HBQ. This function
1985 * is called with no lock held. The function returns the number of HBQ entries
1986 * successfully allocated.
1989 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1991 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1994 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1995 lpfc_hbq_defs
[qno
]->add_count
);
1999 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2000 * @phba: Pointer to HBA context object.
2001 * @qno: HBQ queue number.
2003 * This function is called from SLI initialization code path with
2004 * no lock held to post initial HBQ buffers to firmware. The
2005 * function returns the number of HBQ entries successfully allocated.
2008 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
2010 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2011 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2012 lpfc_hbq_defs
[qno
]->entry_count
);
2014 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2015 lpfc_hbq_defs
[qno
]->init_count
);
2019 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2020 * @phba: Pointer to HBA context object.
2021 * @hbqno: HBQ number.
2023 * This function removes the first hbq buffer on an hbq list and returns a
2024 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2026 static struct hbq_dmabuf
*
2027 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
2029 struct lpfc_dmabuf
*d_buf
;
2031 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
2034 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2038 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2039 * @phba: Pointer to HBA context object.
2040 * @hbqno: HBQ number.
2042 * This function removes the first RQ buffer on an RQ buffer list and returns a
2043 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2045 static struct rqb_dmabuf
*
2046 lpfc_sli_rqbuf_get(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
)
2048 struct lpfc_dmabuf
*h_buf
;
2049 struct lpfc_rqb
*rqbp
;
2052 list_remove_head(&rqbp
->rqb_buffer_list
, h_buf
,
2053 struct lpfc_dmabuf
, list
);
2056 rqbp
->buffer_count
--;
2057 return container_of(h_buf
, struct rqb_dmabuf
, hbuf
);
2061 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2062 * @phba: Pointer to HBA context object.
2063 * @tag: Tag of the hbq buffer.
2065 * This function searches for the hbq buffer associated with the given tag in
2066 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2067 * otherwise it returns NULL.
2069 static struct hbq_dmabuf
*
2070 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
2072 struct lpfc_dmabuf
*d_buf
;
2073 struct hbq_dmabuf
*hbq_buf
;
2077 if (hbqno
>= LPFC_MAX_HBQS
)
2080 spin_lock_irq(&phba
->hbalock
);
2081 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2082 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2083 if (hbq_buf
->tag
== tag
) {
2084 spin_unlock_irq(&phba
->hbalock
);
2088 spin_unlock_irq(&phba
->hbalock
);
2089 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2090 "1803 Bad hbq tag. Data: x%x x%x\n",
2091 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2096 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2097 * @phba: Pointer to HBA context object.
2098 * @hbq_buffer: Pointer to HBQ buffer.
2100 * This function is called with hbalock. This function gives back
2101 * the hbq buffer to firmware. If the HBQ does not have space to
2102 * post the buffer, it will free the buffer.
2105 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2110 hbqno
= hbq_buffer
->tag
>> 16;
2111 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2112 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2117 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2118 * @mbxCommand: mailbox command code.
2120 * This function is called by the mailbox event handler function to verify
2121 * that the completed mailbox command is a legitimate mailbox command. If the
2122 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2123 * and the mailbox event handler will take the HBA offline.
2126 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2130 switch (mbxCommand
) {
2134 case MBX_WRITE_VPARMS
:
2135 case MBX_RUN_BIU_DIAG
:
2138 case MBX_CONFIG_LINK
:
2139 case MBX_CONFIG_RING
:
2140 case MBX_RESET_RING
:
2141 case MBX_READ_CONFIG
:
2142 case MBX_READ_RCONFIG
:
2143 case MBX_READ_SPARM
:
2144 case MBX_READ_STATUS
:
2148 case MBX_READ_LNK_STAT
:
2150 case MBX_UNREG_LOGIN
:
2152 case MBX_DUMP_MEMORY
:
2153 case MBX_DUMP_CONTEXT
:
2156 case MBX_UPDATE_CFG
:
2158 case MBX_DEL_LD_ENTRY
:
2159 case MBX_RUN_PROGRAM
:
2161 case MBX_SET_VARIABLE
:
2162 case MBX_UNREG_D_ID
:
2163 case MBX_KILL_BOARD
:
2164 case MBX_CONFIG_FARP
:
2167 case MBX_RUN_BIU_DIAG64
:
2168 case MBX_CONFIG_PORT
:
2169 case MBX_READ_SPARM64
:
2170 case MBX_READ_RPI64
:
2171 case MBX_REG_LOGIN64
:
2172 case MBX_READ_TOPOLOGY
:
2175 case MBX_LOAD_EXP_ROM
:
2176 case MBX_ASYNCEVT_ENABLE
:
2180 case MBX_PORT_CAPABILITIES
:
2181 case MBX_PORT_IOV_CONTROL
:
2182 case MBX_SLI4_CONFIG
:
2183 case MBX_SLI4_REQ_FTRS
:
2185 case MBX_UNREG_FCFI
:
2190 case MBX_RESUME_RPI
:
2191 case MBX_READ_EVENT_LOG_STATUS
:
2192 case MBX_READ_EVENT_LOG
:
2193 case MBX_SECURITY_MGMT
:
2195 case MBX_ACCESS_VDATA
:
2206 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2207 * @phba: Pointer to HBA context object.
2208 * @pmboxq: Pointer to mailbox command.
2210 * This is completion handler function for mailbox commands issued from
2211 * lpfc_sli_issue_mbox_wait function. This function is called by the
2212 * mailbox event handler function with no lock held. This function
2213 * will wake up thread waiting on the wait queue pointed by context1
2217 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2219 wait_queue_head_t
*pdone_q
;
2220 unsigned long drvr_flag
;
2223 * If pdone_q is empty, the driver thread gave up waiting and
2224 * continued running.
2226 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2227 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2228 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2230 wake_up_interruptible(pdone_q
);
2231 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2237 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2238 * @phba: Pointer to HBA context object.
2239 * @pmb: Pointer to mailbox object.
2241 * This function is the default mailbox completion handler. It
2242 * frees the memory resources associated with the completed mailbox
2243 * command. If the completed command is a REG_LOGIN mailbox command,
2244 * this function will issue a UREG_LOGIN to re-claim the RPI.
2247 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2249 struct lpfc_vport
*vport
= pmb
->vport
;
2250 struct lpfc_dmabuf
*mp
;
2251 struct lpfc_nodelist
*ndlp
;
2252 struct Scsi_Host
*shost
;
2256 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2259 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2264 * If a REG_LOGIN succeeded after node is destroyed or node
2265 * is in re-discovery driver need to cleanup the RPI.
2267 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2268 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2269 !pmb
->u
.mb
.mbxStatus
) {
2270 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2271 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2272 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2274 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2275 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2276 if (rc
!= MBX_NOT_FINISHED
)
2280 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2281 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2282 !pmb
->u
.mb
.mbxStatus
) {
2283 shost
= lpfc_shost_from_vport(vport
);
2284 spin_lock_irq(shost
->host_lock
);
2285 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2286 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2287 spin_unlock_irq(shost
->host_lock
);
2290 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2291 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2293 pmb
->context2
= NULL
;
2296 /* Check security permission status on INIT_LINK mailbox command */
2297 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2298 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2299 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2300 "2860 SLI authentication is required "
2301 "for INIT_LINK but has not done yet\n");
2303 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2304 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2306 mempool_free(pmb
, phba
->mbox_mem_pool
);
2309 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2310 * @phba: Pointer to HBA context object.
2311 * @pmb: Pointer to mailbox object.
2313 * This function is the unreg rpi mailbox completion handler. It
2314 * frees the memory resources associated with the completed mailbox
2315 * command. An additional refrenece is put on the ndlp to prevent
2316 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2317 * the unreg mailbox command completes, this routine puts the
2322 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2324 struct lpfc_vport
*vport
= pmb
->vport
;
2325 struct lpfc_nodelist
*ndlp
;
2327 ndlp
= pmb
->context1
;
2328 if (pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) {
2329 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2330 (bf_get(lpfc_sli_intf_if_type
,
2331 &phba
->sli4_hba
.sli_intf
) ==
2332 LPFC_SLI_INTF_IF_TYPE_2
)) {
2334 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
2335 "0010 UNREG_LOGIN vpi:%x "
2336 "rpi:%x DID:%x map:%x %p\n",
2337 vport
->vpi
, ndlp
->nlp_rpi
,
2339 ndlp
->nlp_usg_map
, ndlp
);
2340 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2346 mempool_free(pmb
, phba
->mbox_mem_pool
);
2350 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2351 * @phba: Pointer to HBA context object.
2353 * This function is called with no lock held. This function processes all
2354 * the completed mailbox commands and gives it to upper layers. The interrupt
2355 * service routine processes mailbox completion interrupt and adds completed
2356 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2357 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2358 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2359 * function returns the mailbox commands to the upper layer by calling the
2360 * completion handler function of each mailbox.
2363 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2370 phba
->sli
.slistat
.mbox_event
++;
2372 /* Get all completed mailboxe buffers into the cmplq */
2373 spin_lock_irq(&phba
->hbalock
);
2374 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2375 spin_unlock_irq(&phba
->hbalock
);
2377 /* Get a Mailbox buffer to setup mailbox commands for callback */
2379 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2385 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2387 lpfc_debugfs_disc_trc(pmb
->vport
,
2388 LPFC_DISC_TRC_MBOX_VPORT
,
2389 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2390 (uint32_t)pmbox
->mbxCommand
,
2391 pmbox
->un
.varWords
[0],
2392 pmbox
->un
.varWords
[1]);
2395 lpfc_debugfs_disc_trc(phba
->pport
,
2397 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2398 (uint32_t)pmbox
->mbxCommand
,
2399 pmbox
->un
.varWords
[0],
2400 pmbox
->un
.varWords
[1]);
2405 * It is a fatal error if unknown mbox command completion.
2407 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2409 /* Unknown mailbox command compl */
2410 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2411 "(%d):0323 Unknown Mailbox command "
2412 "x%x (x%x/x%x) Cmpl\n",
2413 pmb
->vport
? pmb
->vport
->vpi
: 0,
2415 lpfc_sli_config_mbox_subsys_get(phba
,
2417 lpfc_sli_config_mbox_opcode_get(phba
,
2419 phba
->link_state
= LPFC_HBA_ERROR
;
2420 phba
->work_hs
= HS_FFER3
;
2421 lpfc_handle_eratt(phba
);
2425 if (pmbox
->mbxStatus
) {
2426 phba
->sli
.slistat
.mbox_stat_err
++;
2427 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2428 /* Mbox cmd cmpl error - RETRYing */
2429 lpfc_printf_log(phba
, KERN_INFO
,
2431 "(%d):0305 Mbox cmd cmpl "
2432 "error - RETRYing Data: x%x "
2433 "(x%x/x%x) x%x x%x x%x\n",
2434 pmb
->vport
? pmb
->vport
->vpi
: 0,
2436 lpfc_sli_config_mbox_subsys_get(phba
,
2438 lpfc_sli_config_mbox_opcode_get(phba
,
2441 pmbox
->un
.varWords
[0],
2442 pmb
->vport
->port_state
);
2443 pmbox
->mbxStatus
= 0;
2444 pmbox
->mbxOwner
= OWN_HOST
;
2445 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2446 if (rc
!= MBX_NOT_FINISHED
)
2451 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2452 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2453 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2454 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2456 pmb
->vport
? pmb
->vport
->vpi
: 0,
2458 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2459 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2461 *((uint32_t *) pmbox
),
2462 pmbox
->un
.varWords
[0],
2463 pmbox
->un
.varWords
[1],
2464 pmbox
->un
.varWords
[2],
2465 pmbox
->un
.varWords
[3],
2466 pmbox
->un
.varWords
[4],
2467 pmbox
->un
.varWords
[5],
2468 pmbox
->un
.varWords
[6],
2469 pmbox
->un
.varWords
[7],
2470 pmbox
->un
.varWords
[8],
2471 pmbox
->un
.varWords
[9],
2472 pmbox
->un
.varWords
[10]);
2475 pmb
->mbox_cmpl(phba
,pmb
);
2481 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2482 * @phba: Pointer to HBA context object.
2483 * @pring: Pointer to driver SLI ring object.
2486 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2487 * is set in the tag the buffer is posted for a particular exchange,
2488 * the function will return the buffer without replacing the buffer.
2489 * If the buffer is for unsolicited ELS or CT traffic, this function
2490 * returns the buffer and also posts another buffer to the firmware.
2492 static struct lpfc_dmabuf
*
2493 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2494 struct lpfc_sli_ring
*pring
,
2497 struct hbq_dmabuf
*hbq_entry
;
2499 if (tag
& QUE_BUFTAG_BIT
)
2500 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2501 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2504 return &hbq_entry
->dbuf
;
2508 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2509 * @phba: Pointer to HBA context object.
2510 * @pring: Pointer to driver SLI ring object.
2511 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2512 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2513 * @fch_type: the type for the first frame of the sequence.
2515 * This function is called with no lock held. This function uses the r_ctl and
2516 * type of the received sequence to find the correct callback function to call
2517 * to process the sequence.
2520 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2521 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2528 lpfc_nvmet_unsol_ls_event(phba
, pring
, saveq
);
2534 /* unSolicited Responses */
2535 if (pring
->prt
[0].profile
) {
2536 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2537 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2541 /* We must search, based on rctl / type
2542 for the right routine */
2543 for (i
= 0; i
< pring
->num_mask
; i
++) {
2544 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2545 (pring
->prt
[i
].type
== fch_type
)) {
2546 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2547 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2548 (phba
, pring
, saveq
);
2556 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2557 * @phba: Pointer to HBA context object.
2558 * @pring: Pointer to driver SLI ring object.
2559 * @saveq: Pointer to the unsolicited iocb.
2561 * This function is called with no lock held by the ring event handler
2562 * when there is an unsolicited iocb posted to the response ring by the
2563 * firmware. This function gets the buffer associated with the iocbs
2564 * and calls the event handler for the ring. This function handles both
2565 * qring buffers and hbq buffers.
2566 * When the function returns 1 the caller can free the iocb object otherwise
2567 * upper layer functions will free the iocb objects.
2570 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2571 struct lpfc_iocbq
*saveq
)
2575 uint32_t Rctl
, Type
;
2576 struct lpfc_iocbq
*iocbq
;
2577 struct lpfc_dmabuf
*dmzbuf
;
2579 irsp
= &(saveq
->iocb
);
2581 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2582 if (pring
->lpfc_sli_rcv_async_status
)
2583 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2585 lpfc_printf_log(phba
,
2588 "0316 Ring %d handler: unexpected "
2589 "ASYNC_STATUS iocb received evt_code "
2592 irsp
->un
.asyncstat
.evt_code
);
2596 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2597 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2598 if (irsp
->ulpBdeCount
> 0) {
2599 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2600 irsp
->un
.ulpWord
[3]);
2601 lpfc_in_buf_free(phba
, dmzbuf
);
2604 if (irsp
->ulpBdeCount
> 1) {
2605 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2606 irsp
->unsli3
.sli3Words
[3]);
2607 lpfc_in_buf_free(phba
, dmzbuf
);
2610 if (irsp
->ulpBdeCount
> 2) {
2611 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2612 irsp
->unsli3
.sli3Words
[7]);
2613 lpfc_in_buf_free(phba
, dmzbuf
);
2619 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2620 if (irsp
->ulpBdeCount
!= 0) {
2621 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2622 irsp
->un
.ulpWord
[3]);
2623 if (!saveq
->context2
)
2624 lpfc_printf_log(phba
,
2627 "0341 Ring %d Cannot find buffer for "
2628 "an unsolicited iocb. tag 0x%x\n",
2630 irsp
->un
.ulpWord
[3]);
2632 if (irsp
->ulpBdeCount
== 2) {
2633 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2634 irsp
->unsli3
.sli3Words
[7]);
2635 if (!saveq
->context3
)
2636 lpfc_printf_log(phba
,
2639 "0342 Ring %d Cannot find buffer for an"
2640 " unsolicited iocb. tag 0x%x\n",
2642 irsp
->unsli3
.sli3Words
[7]);
2644 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2645 irsp
= &(iocbq
->iocb
);
2646 if (irsp
->ulpBdeCount
!= 0) {
2647 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2648 irsp
->un
.ulpWord
[3]);
2649 if (!iocbq
->context2
)
2650 lpfc_printf_log(phba
,
2653 "0343 Ring %d Cannot find "
2654 "buffer for an unsolicited iocb"
2655 ". tag 0x%x\n", pring
->ringno
,
2656 irsp
->un
.ulpWord
[3]);
2658 if (irsp
->ulpBdeCount
== 2) {
2659 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2660 irsp
->unsli3
.sli3Words
[7]);
2661 if (!iocbq
->context3
)
2662 lpfc_printf_log(phba
,
2665 "0344 Ring %d Cannot find "
2666 "buffer for an unsolicited "
2669 irsp
->unsli3
.sli3Words
[7]);
2673 if (irsp
->ulpBdeCount
!= 0 &&
2674 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2675 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2678 /* search continue save q for same XRI */
2679 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2680 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2681 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2682 list_add_tail(&saveq
->list
, &iocbq
->list
);
2688 list_add_tail(&saveq
->clist
,
2689 &pring
->iocb_continue_saveq
);
2690 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2691 list_del_init(&iocbq
->clist
);
2693 irsp
= &(saveq
->iocb
);
2697 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2698 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2699 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2700 Rctl
= FC_RCTL_ELS_REQ
;
2703 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2704 Rctl
= w5p
->hcsw
.Rctl
;
2705 Type
= w5p
->hcsw
.Type
;
2707 /* Firmware Workaround */
2708 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2709 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2710 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2711 Rctl
= FC_RCTL_ELS_REQ
;
2713 w5p
->hcsw
.Rctl
= Rctl
;
2714 w5p
->hcsw
.Type
= Type
;
2718 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2719 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2720 "0313 Ring %d handler: unexpected Rctl x%x "
2721 "Type x%x received\n",
2722 pring
->ringno
, Rctl
, Type
);
2728 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2729 * @phba: Pointer to HBA context object.
2730 * @pring: Pointer to driver SLI ring object.
2731 * @prspiocb: Pointer to response iocb object.
2733 * This function looks up the iocb_lookup table to get the command iocb
2734 * corresponding to the given response iocb using the iotag of the
2735 * response iocb. This function is called with the hbalock held
2736 * for sli3 devices or the ring_lock for sli4 devices.
2737 * This function returns the command iocb object if it finds the command
2738 * iocb else returns NULL.
2740 static struct lpfc_iocbq
*
2741 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2742 struct lpfc_sli_ring
*pring
,
2743 struct lpfc_iocbq
*prspiocb
)
2745 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2747 lockdep_assert_held(&phba
->hbalock
);
2749 iotag
= prspiocb
->iocb
.ulpIoTag
;
2751 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2752 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2753 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2754 /* remove from txcmpl queue list */
2755 list_del_init(&cmd_iocb
->list
);
2756 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2761 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2762 "0317 iotag x%x is out of "
2763 "range: max iotag x%x wd0 x%x\n",
2764 iotag
, phba
->sli
.last_iotag
,
2765 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2770 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2771 * @phba: Pointer to HBA context object.
2772 * @pring: Pointer to driver SLI ring object.
2775 * This function looks up the iocb_lookup table to get the command iocb
2776 * corresponding to the given iotag. This function is called with the
2778 * This function returns the command iocb object if it finds the command
2779 * iocb else returns NULL.
2781 static struct lpfc_iocbq
*
2782 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2783 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2785 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2787 lockdep_assert_held(&phba
->hbalock
);
2788 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2789 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2790 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2791 /* remove from txcmpl queue list */
2792 list_del_init(&cmd_iocb
->list
);
2793 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2798 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2799 "0372 iotag x%x lookup error: max iotag (x%x) "
2801 iotag
, phba
->sli
.last_iotag
,
2802 cmd_iocb
? cmd_iocb
->iocb_flag
: 0xffff);
2807 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2808 * @phba: Pointer to HBA context object.
2809 * @pring: Pointer to driver SLI ring object.
2810 * @saveq: Pointer to the response iocb to be processed.
2812 * This function is called by the ring event handler for non-fcp
2813 * rings when there is a new response iocb in the response ring.
2814 * The caller is not required to hold any locks. This function
2815 * gets the command iocb associated with the response iocb and
2816 * calls the completion handler for the command iocb. If there
2817 * is no completion handler, the function will free the resources
2818 * associated with command iocb. If the response iocb is for
2819 * an already aborted command iocb, the status of the completion
2820 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2821 * This function always returns 1.
2824 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2825 struct lpfc_iocbq
*saveq
)
2827 struct lpfc_iocbq
*cmdiocbp
;
2829 unsigned long iflag
;
2831 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2832 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2833 spin_lock_irqsave(&pring
->ring_lock
, iflag
);
2835 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2836 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2837 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2838 spin_unlock_irqrestore(&pring
->ring_lock
, iflag
);
2840 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2843 if (cmdiocbp
->iocb_cmpl
) {
2845 * If an ELS command failed send an event to mgmt
2848 if (saveq
->iocb
.ulpStatus
&&
2849 (pring
->ringno
== LPFC_ELS_RING
) &&
2850 (cmdiocbp
->iocb
.ulpCommand
==
2851 CMD_ELS_REQUEST64_CR
))
2852 lpfc_send_els_failure_event(phba
,
2856 * Post all ELS completions to the worker thread.
2857 * All other are passed to the completion callback.
2859 if (pring
->ringno
== LPFC_ELS_RING
) {
2860 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2861 (cmdiocbp
->iocb_flag
&
2862 LPFC_DRIVER_ABORTED
)) {
2863 spin_lock_irqsave(&phba
->hbalock
,
2865 cmdiocbp
->iocb_flag
&=
2866 ~LPFC_DRIVER_ABORTED
;
2867 spin_unlock_irqrestore(&phba
->hbalock
,
2869 saveq
->iocb
.ulpStatus
=
2870 IOSTAT_LOCAL_REJECT
;
2871 saveq
->iocb
.un
.ulpWord
[4] =
2874 /* Firmware could still be in progress
2875 * of DMAing payload, so don't free data
2876 * buffer till after a hbeat.
2878 spin_lock_irqsave(&phba
->hbalock
,
2880 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2881 spin_unlock_irqrestore(&phba
->hbalock
,
2884 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2885 if (saveq
->iocb_flag
&
2886 LPFC_EXCHANGE_BUSY
) {
2887 /* Set cmdiocb flag for the
2888 * exchange busy so sgl (xri)
2889 * will not be released until
2890 * the abort xri is received
2894 &phba
->hbalock
, iflag
);
2895 cmdiocbp
->iocb_flag
|=
2897 spin_unlock_irqrestore(
2898 &phba
->hbalock
, iflag
);
2900 if (cmdiocbp
->iocb_flag
&
2901 LPFC_DRIVER_ABORTED
) {
2903 * Clear LPFC_DRIVER_ABORTED
2904 * bit in case it was driver
2908 &phba
->hbalock
, iflag
);
2909 cmdiocbp
->iocb_flag
&=
2910 ~LPFC_DRIVER_ABORTED
;
2911 spin_unlock_irqrestore(
2912 &phba
->hbalock
, iflag
);
2913 cmdiocbp
->iocb
.ulpStatus
=
2914 IOSTAT_LOCAL_REJECT
;
2915 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2916 IOERR_ABORT_REQUESTED
;
2918 * For SLI4, irsiocb contains
2919 * NO_XRI in sli_xritag, it
2920 * shall not affect releasing
2921 * sgl (xri) process.
2923 saveq
->iocb
.ulpStatus
=
2924 IOSTAT_LOCAL_REJECT
;
2925 saveq
->iocb
.un
.ulpWord
[4] =
2928 &phba
->hbalock
, iflag
);
2930 LPFC_DELAY_MEM_FREE
;
2931 spin_unlock_irqrestore(
2932 &phba
->hbalock
, iflag
);
2936 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2938 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2941 * Unknown initiating command based on the response iotag.
2942 * This could be the case on the ELS ring because of
2945 if (pring
->ringno
!= LPFC_ELS_RING
) {
2947 * Ring <ringno> handler: unexpected completion IoTag
2950 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2951 "0322 Ring %d handler: "
2952 "unexpected completion IoTag x%x "
2953 "Data: x%x x%x x%x x%x\n",
2955 saveq
->iocb
.ulpIoTag
,
2956 saveq
->iocb
.ulpStatus
,
2957 saveq
->iocb
.un
.ulpWord
[4],
2958 saveq
->iocb
.ulpCommand
,
2959 saveq
->iocb
.ulpContext
);
2967 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2968 * @phba: Pointer to HBA context object.
2969 * @pring: Pointer to driver SLI ring object.
2971 * This function is called from the iocb ring event handlers when
2972 * put pointer is ahead of the get pointer for a ring. This function signal
2973 * an error attention condition to the worker thread and the worker
2974 * thread will transition the HBA to offline state.
2977 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2979 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2981 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2982 * rsp ring <portRspMax>
2984 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2985 "0312 Ring %d handler: portRspPut %d "
2986 "is bigger than rsp ring %d\n",
2987 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2988 pring
->sli
.sli3
.numRiocb
);
2990 phba
->link_state
= LPFC_HBA_ERROR
;
2993 * All error attention handlers are posted to
2996 phba
->work_ha
|= HA_ERATT
;
2997 phba
->work_hs
= HS_FFER3
;
2999 lpfc_worker_wake_up(phba
);
3005 * lpfc_poll_eratt - Error attention polling timer timeout handler
3006 * @ptr: Pointer to address of HBA context object.
3008 * This function is invoked by the Error Attention polling timer when the
3009 * timer times out. It will check the SLI Error Attention register for
3010 * possible attention events. If so, it will post an Error Attention event
3011 * and wake up worker thread to process it. Otherwise, it will set up the
3012 * Error Attention polling timer for the next poll.
3014 void lpfc_poll_eratt(struct timer_list
*t
)
3016 struct lpfc_hba
*phba
;
3018 uint64_t sli_intr
, cnt
;
3020 phba
= from_timer(phba
, t
, eratt_poll
);
3022 /* Here we will also keep track of interrupts per sec of the hba */
3023 sli_intr
= phba
->sli
.slistat
.sli_intr
;
3025 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
3026 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
3029 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
3031 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3032 do_div(cnt
, phba
->eratt_poll_interval
);
3033 phba
->sli
.slistat
.sli_ips
= cnt
;
3035 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
3037 /* Check chip HA register for error event */
3038 eratt
= lpfc_sli_check_eratt(phba
);
3041 /* Tell the worker thread there is work to do */
3042 lpfc_worker_wake_up(phba
);
3044 /* Restart the timer for next eratt poll */
3045 mod_timer(&phba
->eratt_poll
,
3047 msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
3053 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3054 * @phba: Pointer to HBA context object.
3055 * @pring: Pointer to driver SLI ring object.
3056 * @mask: Host attention register mask for this ring.
3058 * This function is called from the interrupt context when there is a ring
3059 * event for the fcp ring. The caller does not hold any lock.
3060 * The function processes each response iocb in the response ring until it
3061 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3062 * LE bit set. The function will call the completion handler of the command iocb
3063 * if the response iocb indicates a completion for a command iocb or it is
3064 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3065 * function if this is an unsolicited iocb.
3066 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3067 * to check it explicitly.
3070 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
3071 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3073 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
3074 IOCB_t
*irsp
= NULL
;
3075 IOCB_t
*entry
= NULL
;
3076 struct lpfc_iocbq
*cmdiocbq
= NULL
;
3077 struct lpfc_iocbq rspiocbq
;
3079 uint32_t portRspPut
, portRspMax
;
3081 lpfc_iocb_type type
;
3082 unsigned long iflag
;
3083 uint32_t rsp_cmpl
= 0;
3085 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3086 pring
->stats
.iocb_event
++;
3089 * The next available response entry should never exceed the maximum
3090 * entries. If it does, treat it as an adapter hardware error.
3092 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3093 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3094 if (unlikely(portRspPut
>= portRspMax
)) {
3095 lpfc_sli_rsp_pointers_error(phba
, pring
);
3096 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3099 if (phba
->fcp_ring_in_use
) {
3100 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3103 phba
->fcp_ring_in_use
= 1;
3106 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3108 * Fetch an entry off the ring and copy it into a local data
3109 * structure. The copy involves a byte-swap since the
3110 * network byte order and pci byte orders are different.
3112 entry
= lpfc_resp_iocb(phba
, pring
);
3113 phba
->last_completion_time
= jiffies
;
3115 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3116 pring
->sli
.sli3
.rspidx
= 0;
3118 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
3119 (uint32_t *) &rspiocbq
.iocb
,
3120 phba
->iocb_rsp_size
);
3121 INIT_LIST_HEAD(&(rspiocbq
.list
));
3122 irsp
= &rspiocbq
.iocb
;
3124 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
3125 pring
->stats
.iocb_rsp
++;
3128 if (unlikely(irsp
->ulpStatus
)) {
3130 * If resource errors reported from HBA, reduce
3131 * queuedepths of the SCSI device.
3133 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3134 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3135 IOERR_NO_RESOURCES
)) {
3136 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3137 phba
->lpfc_rampdown_queue_depth(phba
);
3138 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3141 /* Rsp ring <ringno> error: IOCB */
3142 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3143 "0336 Rsp Ring %d error: IOCB Data: "
3144 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3146 irsp
->un
.ulpWord
[0],
3147 irsp
->un
.ulpWord
[1],
3148 irsp
->un
.ulpWord
[2],
3149 irsp
->un
.ulpWord
[3],
3150 irsp
->un
.ulpWord
[4],
3151 irsp
->un
.ulpWord
[5],
3152 *(uint32_t *)&irsp
->un1
,
3153 *((uint32_t *)&irsp
->un1
+ 1));
3157 case LPFC_ABORT_IOCB
:
3160 * Idle exchange closed via ABTS from port. No iocb
3161 * resources need to be recovered.
3163 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3164 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3165 "0333 IOCB cmd 0x%x"
3166 " processed. Skipping"
3172 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3174 if (unlikely(!cmdiocbq
))
3176 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3177 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3178 if (cmdiocbq
->iocb_cmpl
) {
3179 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3180 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3182 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3185 case LPFC_UNSOL_IOCB
:
3186 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3187 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3188 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3191 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3192 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3193 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3194 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3196 dev_warn(&((phba
->pcidev
)->dev
),
3198 phba
->brd_no
, adaptermsg
);
3200 /* Unknown IOCB command */
3201 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3202 "0334 Unknown IOCB command "
3203 "Data: x%x, x%x x%x x%x x%x\n",
3204 type
, irsp
->ulpCommand
,
3213 * The response IOCB has been processed. Update the ring
3214 * pointer in SLIM. If the port response put pointer has not
3215 * been updated, sync the pgp->rspPutInx and fetch the new port
3216 * response put pointer.
3218 writel(pring
->sli
.sli3
.rspidx
,
3219 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3221 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3222 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3225 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3226 pring
->stats
.iocb_rsp_full
++;
3227 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3228 writel(status
, phba
->CAregaddr
);
3229 readl(phba
->CAregaddr
);
3231 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3232 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3233 pring
->stats
.iocb_cmd_empty
++;
3235 /* Force update of the local copy of cmdGetInx */
3236 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3237 lpfc_sli_resume_iocb(phba
, pring
);
3239 if ((pring
->lpfc_sli_cmd_available
))
3240 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3244 phba
->fcp_ring_in_use
= 0;
3245 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3250 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3251 * @phba: Pointer to HBA context object.
3252 * @pring: Pointer to driver SLI ring object.
3253 * @rspiocbp: Pointer to driver response IOCB object.
3255 * This function is called from the worker thread when there is a slow-path
3256 * response IOCB to process. This function chains all the response iocbs until
3257 * seeing the iocb with the LE bit set. The function will call
3258 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3259 * completion of a command iocb. The function will call the
3260 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3261 * The function frees the resources or calls the completion handler if this
3262 * iocb is an abort completion. The function returns NULL when the response
3263 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3264 * this function shall chain the iocb on to the iocb_continueq and return the
3265 * response iocb passed in.
3267 static struct lpfc_iocbq
*
3268 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3269 struct lpfc_iocbq
*rspiocbp
)
3271 struct lpfc_iocbq
*saveq
;
3272 struct lpfc_iocbq
*cmdiocbp
;
3273 struct lpfc_iocbq
*next_iocb
;
3274 IOCB_t
*irsp
= NULL
;
3275 uint32_t free_saveq
;
3276 uint8_t iocb_cmd_type
;
3277 lpfc_iocb_type type
;
3278 unsigned long iflag
;
3281 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3282 /* First add the response iocb to the countinueq list */
3283 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3284 pring
->iocb_continueq_cnt
++;
3286 /* Now, determine whether the list is completed for processing */
3287 irsp
= &rspiocbp
->iocb
;
3290 * By default, the driver expects to free all resources
3291 * associated with this iocb completion.
3294 saveq
= list_get_first(&pring
->iocb_continueq
,
3295 struct lpfc_iocbq
, list
);
3296 irsp
= &(saveq
->iocb
);
3297 list_del_init(&pring
->iocb_continueq
);
3298 pring
->iocb_continueq_cnt
= 0;
3300 pring
->stats
.iocb_rsp
++;
3303 * If resource errors reported from HBA, reduce
3304 * queuedepths of the SCSI device.
3306 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3307 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3308 IOERR_NO_RESOURCES
)) {
3309 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3310 phba
->lpfc_rampdown_queue_depth(phba
);
3311 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3314 if (irsp
->ulpStatus
) {
3315 /* Rsp ring <ringno> error: IOCB */
3316 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3317 "0328 Rsp Ring %d error: "
3322 "x%x x%x x%x x%x\n",
3324 irsp
->un
.ulpWord
[0],
3325 irsp
->un
.ulpWord
[1],
3326 irsp
->un
.ulpWord
[2],
3327 irsp
->un
.ulpWord
[3],
3328 irsp
->un
.ulpWord
[4],
3329 irsp
->un
.ulpWord
[5],
3330 *(((uint32_t *) irsp
) + 6),
3331 *(((uint32_t *) irsp
) + 7),
3332 *(((uint32_t *) irsp
) + 8),
3333 *(((uint32_t *) irsp
) + 9),
3334 *(((uint32_t *) irsp
) + 10),
3335 *(((uint32_t *) irsp
) + 11),
3336 *(((uint32_t *) irsp
) + 12),
3337 *(((uint32_t *) irsp
) + 13),
3338 *(((uint32_t *) irsp
) + 14),
3339 *(((uint32_t *) irsp
) + 15));
3343 * Fetch the IOCB command type and call the correct completion
3344 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3345 * get freed back to the lpfc_iocb_list by the discovery
3348 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3349 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3352 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3353 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3354 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3357 case LPFC_UNSOL_IOCB
:
3358 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3359 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3360 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3365 case LPFC_ABORT_IOCB
:
3367 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3368 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3371 /* Call the specified completion routine */
3372 if (cmdiocbp
->iocb_cmpl
) {
3373 spin_unlock_irqrestore(&phba
->hbalock
,
3375 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3377 spin_lock_irqsave(&phba
->hbalock
,
3380 __lpfc_sli_release_iocbq(phba
,
3385 case LPFC_UNKNOWN_IOCB
:
3386 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3387 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3388 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3389 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3391 dev_warn(&((phba
->pcidev
)->dev
),
3393 phba
->brd_no
, adaptermsg
);
3395 /* Unknown IOCB command */
3396 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3397 "0335 Unknown IOCB "
3398 "command Data: x%x "
3409 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3410 &saveq
->list
, list
) {
3411 list_del_init(&rspiocbp
->list
);
3412 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3414 __lpfc_sli_release_iocbq(phba
, saveq
);
3418 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3423 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3424 * @phba: Pointer to HBA context object.
3425 * @pring: Pointer to driver SLI ring object.
3426 * @mask: Host attention register mask for this ring.
3428 * This routine wraps the actual slow_ring event process routine from the
3429 * API jump table function pointer from the lpfc_hba struct.
3432 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3433 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3435 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3439 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3440 * @phba: Pointer to HBA context object.
3441 * @pring: Pointer to driver SLI ring object.
3442 * @mask: Host attention register mask for this ring.
3444 * This function is called from the worker thread when there is a ring event
3445 * for non-fcp rings. The caller does not hold any lock. The function will
3446 * remove each response iocb in the response ring and calls the handle
3447 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3450 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3451 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3453 struct lpfc_pgp
*pgp
;
3455 IOCB_t
*irsp
= NULL
;
3456 struct lpfc_iocbq
*rspiocbp
= NULL
;
3457 uint32_t portRspPut
, portRspMax
;
3458 unsigned long iflag
;
3461 pgp
= &phba
->port_gp
[pring
->ringno
];
3462 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3463 pring
->stats
.iocb_event
++;
3466 * The next available response entry should never exceed the maximum
3467 * entries. If it does, treat it as an adapter hardware error.
3469 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3470 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3471 if (portRspPut
>= portRspMax
) {
3473 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3474 * rsp ring <portRspMax>
3476 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3477 "0303 Ring %d handler: portRspPut %d "
3478 "is bigger than rsp ring %d\n",
3479 pring
->ringno
, portRspPut
, portRspMax
);
3481 phba
->link_state
= LPFC_HBA_ERROR
;
3482 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3484 phba
->work_hs
= HS_FFER3
;
3485 lpfc_handle_eratt(phba
);
3491 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3493 * Build a completion list and call the appropriate handler.
3494 * The process is to get the next available response iocb, get
3495 * a free iocb from the list, copy the response data into the
3496 * free iocb, insert to the continuation list, and update the
3497 * next response index to slim. This process makes response
3498 * iocb's in the ring available to DMA as fast as possible but
3499 * pays a penalty for a copy operation. Since the iocb is
3500 * only 32 bytes, this penalty is considered small relative to
3501 * the PCI reads for register values and a slim write. When
3502 * the ulpLe field is set, the entire Command has been
3505 entry
= lpfc_resp_iocb(phba
, pring
);
3507 phba
->last_completion_time
= jiffies
;
3508 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3509 if (rspiocbp
== NULL
) {
3510 printk(KERN_ERR
"%s: out of buffers! Failing "
3511 "completion.\n", __func__
);
3515 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3516 phba
->iocb_rsp_size
);
3517 irsp
= &rspiocbp
->iocb
;
3519 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3520 pring
->sli
.sli3
.rspidx
= 0;
3522 if (pring
->ringno
== LPFC_ELS_RING
) {
3523 lpfc_debugfs_slow_ring_trc(phba
,
3524 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3525 *(((uint32_t *) irsp
) + 4),
3526 *(((uint32_t *) irsp
) + 6),
3527 *(((uint32_t *) irsp
) + 7));
3530 writel(pring
->sli
.sli3
.rspidx
,
3531 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3533 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3534 /* Handle the response IOCB */
3535 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3536 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3539 * If the port response put pointer has not been updated, sync
3540 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3541 * response put pointer.
3543 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3544 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3546 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3548 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3549 /* At least one response entry has been freed */
3550 pring
->stats
.iocb_rsp_full
++;
3551 /* SET RxRE_RSP in Chip Att register */
3552 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3553 writel(status
, phba
->CAregaddr
);
3554 readl(phba
->CAregaddr
); /* flush */
3556 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3557 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3558 pring
->stats
.iocb_cmd_empty
++;
3560 /* Force update of the local copy of cmdGetInx */
3561 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3562 lpfc_sli_resume_iocb(phba
, pring
);
3564 if ((pring
->lpfc_sli_cmd_available
))
3565 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3569 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3574 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3575 * @phba: Pointer to HBA context object.
3576 * @pring: Pointer to driver SLI ring object.
3577 * @mask: Host attention register mask for this ring.
3579 * This function is called from the worker thread when there is a pending
3580 * ELS response iocb on the driver internal slow-path response iocb worker
3581 * queue. The caller does not hold any lock. The function will remove each
3582 * response iocb from the response worker queue and calls the handle
3583 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3586 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3587 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3589 struct lpfc_iocbq
*irspiocbq
;
3590 struct hbq_dmabuf
*dmabuf
;
3591 struct lpfc_cq_event
*cq_event
;
3592 unsigned long iflag
;
3594 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3595 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3596 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3597 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3598 /* Get the response iocb from the head of work queue */
3599 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3600 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3601 cq_event
, struct lpfc_cq_event
, list
);
3602 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3604 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3605 case CQE_CODE_COMPL_WQE
:
3606 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3608 /* Translate ELS WCQE to response IOCBQ */
3609 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3612 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3615 case CQE_CODE_RECEIVE
:
3616 case CQE_CODE_RECEIVE_V1
:
3617 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3619 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3628 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3629 * @phba: Pointer to HBA context object.
3630 * @pring: Pointer to driver SLI ring object.
3632 * This function aborts all iocbs in the given ring and frees all the iocb
3633 * objects in txq. This function issues an abort iocb for all the iocb commands
3634 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3635 * the return of this function. The caller is not required to hold any locks.
3638 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3640 LIST_HEAD(completions
);
3641 struct lpfc_iocbq
*iocb
, *next_iocb
;
3643 if (pring
->ringno
== LPFC_ELS_RING
) {
3644 lpfc_fabric_abort_hba(phba
);
3647 /* Error everything on txq and txcmplq
3650 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3651 spin_lock_irq(&pring
->ring_lock
);
3652 list_splice_init(&pring
->txq
, &completions
);
3654 spin_unlock_irq(&pring
->ring_lock
);
3656 spin_lock_irq(&phba
->hbalock
);
3657 /* Next issue ABTS for everything on the txcmplq */
3658 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3659 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3660 spin_unlock_irq(&phba
->hbalock
);
3662 spin_lock_irq(&phba
->hbalock
);
3663 list_splice_init(&pring
->txq
, &completions
);
3666 /* Next issue ABTS for everything on the txcmplq */
3667 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3668 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3669 spin_unlock_irq(&phba
->hbalock
);
3672 /* Cancel all the IOCBs from the completions list */
3673 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3678 * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring
3679 * @phba: Pointer to HBA context object.
3680 * @pring: Pointer to driver SLI ring object.
3682 * This function aborts all iocbs in the given ring and frees all the iocb
3683 * objects in txq. This function issues an abort iocb for all the iocb commands
3684 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3685 * the return of this function. The caller is not required to hold any locks.
3688 lpfc_sli_abort_wqe_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3690 LIST_HEAD(completions
);
3691 struct lpfc_iocbq
*iocb
, *next_iocb
;
3693 if (pring
->ringno
== LPFC_ELS_RING
)
3694 lpfc_fabric_abort_hba(phba
);
3696 spin_lock_irq(&phba
->hbalock
);
3697 /* Next issue ABTS for everything on the txcmplq */
3698 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3699 lpfc_sli4_abort_nvme_io(phba
, pring
, iocb
);
3700 spin_unlock_irq(&phba
->hbalock
);
3705 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3706 * @phba: Pointer to HBA context object.
3707 * @pring: Pointer to driver SLI ring object.
3709 * This function aborts all iocbs in FCP rings and frees all the iocb
3710 * objects in txq. This function issues an abort iocb for all the iocb commands
3711 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3712 * the return of this function. The caller is not required to hold any locks.
3715 lpfc_sli_abort_fcp_rings(struct lpfc_hba
*phba
)
3717 struct lpfc_sli
*psli
= &phba
->sli
;
3718 struct lpfc_sli_ring
*pring
;
3721 /* Look on all the FCP Rings for the iotag */
3722 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3723 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3724 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
3725 lpfc_sli_abort_iocb_ring(phba
, pring
);
3728 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
3729 lpfc_sli_abort_iocb_ring(phba
, pring
);
3734 * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings
3735 * @phba: Pointer to HBA context object.
3737 * This function aborts all wqes in NVME rings. This function issues an
3738 * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in
3739 * the txcmplq is not guaranteed to complete before the return of this
3740 * function. The caller is not required to hold any locks.
3743 lpfc_sli_abort_nvme_rings(struct lpfc_hba
*phba
)
3745 struct lpfc_sli_ring
*pring
;
3748 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3751 /* Abort all IO on each NVME ring. */
3752 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
3753 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
3754 lpfc_sli_abort_wqe_ring(phba
, pring
);
3760 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3761 * @phba: Pointer to HBA context object.
3763 * This function flushes all iocbs in the fcp ring and frees all the iocb
3764 * objects in txq and txcmplq. This function will not issue abort iocbs
3765 * for all the iocb commands in txcmplq, they will just be returned with
3766 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3767 * slot has been permanently disabled.
3770 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3774 struct lpfc_sli
*psli
= &phba
->sli
;
3775 struct lpfc_sli_ring
*pring
;
3778 spin_lock_irq(&phba
->hbalock
);
3779 /* Indicate the I/O queues are flushed */
3780 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3781 spin_unlock_irq(&phba
->hbalock
);
3783 /* Look on all the FCP Rings for the iotag */
3784 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3785 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3786 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
3788 spin_lock_irq(&pring
->ring_lock
);
3789 /* Retrieve everything on txq */
3790 list_splice_init(&pring
->txq
, &txq
);
3791 /* Retrieve everything on the txcmplq */
3792 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3794 pring
->txcmplq_cnt
= 0;
3795 spin_unlock_irq(&pring
->ring_lock
);
3798 lpfc_sli_cancel_iocbs(phba
, &txq
,
3799 IOSTAT_LOCAL_REJECT
,
3801 /* Flush the txcmpq */
3802 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
3803 IOSTAT_LOCAL_REJECT
,
3807 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
3809 spin_lock_irq(&phba
->hbalock
);
3810 /* Retrieve everything on txq */
3811 list_splice_init(&pring
->txq
, &txq
);
3812 /* Retrieve everything on the txcmplq */
3813 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3815 pring
->txcmplq_cnt
= 0;
3816 spin_unlock_irq(&phba
->hbalock
);
3819 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3821 /* Flush the txcmpq */
3822 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3828 * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings
3829 * @phba: Pointer to HBA context object.
3831 * This function flushes all wqes in the nvme rings and frees all resources
3832 * in the txcmplq. This function does not issue abort wqes for the IO
3833 * commands in txcmplq, they will just be returned with
3834 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3835 * slot has been permanently disabled.
3838 lpfc_sli_flush_nvme_rings(struct lpfc_hba
*phba
)
3841 struct lpfc_sli_ring
*pring
;
3844 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3847 /* Hint to other driver operations that a flush is in progress. */
3848 spin_lock_irq(&phba
->hbalock
);
3849 phba
->hba_flag
|= HBA_NVME_IOQ_FLUSH
;
3850 spin_unlock_irq(&phba
->hbalock
);
3852 /* Cycle through all NVME rings and complete each IO with
3853 * a local driver reason code. This is a flush so no
3854 * abort exchange to FW.
3856 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
3857 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
3859 /* Retrieve everything on the txcmplq */
3860 spin_lock_irq(&pring
->ring_lock
);
3861 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3862 pring
->txcmplq_cnt
= 0;
3863 spin_unlock_irq(&pring
->ring_lock
);
3865 /* Flush the txcmpq &&&PAE */
3866 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
3867 IOSTAT_LOCAL_REJECT
,
3873 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3874 * @phba: Pointer to HBA context object.
3875 * @mask: Bit mask to be checked.
3877 * This function reads the host status register and compares
3878 * with the provided bit mask to check if HBA completed
3879 * the restart. This function will wait in a loop for the
3880 * HBA to complete restart. If the HBA does not restart within
3881 * 15 iterations, the function will reset the HBA again. The
3882 * function returns 1 when HBA fail to restart otherwise returns
3886 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3892 /* Read the HBA Host Status Register */
3893 if (lpfc_readl(phba
->HSregaddr
, &status
))
3897 * Check status register every 100ms for 5 retries, then every
3898 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3899 * every 2.5 sec for 4.
3900 * Break our of the loop if errors occurred during init.
3902 while (((status
& mask
) != mask
) &&
3903 !(status
& HS_FFERM
) &&
3915 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3916 lpfc_sli_brdrestart(phba
);
3918 /* Read the HBA Host Status Register */
3919 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3925 /* Check to see if any errors occurred during init */
3926 if ((status
& HS_FFERM
) || (i
>= 20)) {
3927 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3928 "2751 Adapter failed to restart, "
3929 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3931 readl(phba
->MBslimaddr
+ 0xa8),
3932 readl(phba
->MBslimaddr
+ 0xac));
3933 phba
->link_state
= LPFC_HBA_ERROR
;
3941 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3942 * @phba: Pointer to HBA context object.
3943 * @mask: Bit mask to be checked.
3945 * This function checks the host status register to check if HBA is
3946 * ready. This function will wait in a loop for the HBA to be ready
3947 * If the HBA is not ready , the function will will reset the HBA PCI
3948 * function again. The function returns 1 when HBA fail to be ready
3949 * otherwise returns zero.
3952 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3957 /* Read the HBA Host Status Register */
3958 status
= lpfc_sli4_post_status_check(phba
);
3961 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3962 lpfc_sli_brdrestart(phba
);
3963 status
= lpfc_sli4_post_status_check(phba
);
3966 /* Check to see if any errors occurred during init */
3968 phba
->link_state
= LPFC_HBA_ERROR
;
3971 phba
->sli4_hba
.intr_enable
= 0;
3977 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3978 * @phba: Pointer to HBA context object.
3979 * @mask: Bit mask to be checked.
3981 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3982 * from the API jump table function pointer from the lpfc_hba struct.
3985 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3987 return phba
->lpfc_sli_brdready(phba
, mask
);
3990 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3993 * lpfc_reset_barrier - Make HBA ready for HBA reset
3994 * @phba: Pointer to HBA context object.
3996 * This function is called before resetting an HBA. This function is called
3997 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3999 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
4001 uint32_t __iomem
*resp_buf
;
4002 uint32_t __iomem
*mbox_buf
;
4003 volatile uint32_t mbox
;
4004 uint32_t hc_copy
, ha_copy
, resp_data
;
4008 lockdep_assert_held(&phba
->hbalock
);
4010 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
4011 if (hdrtype
!= 0x80 ||
4012 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
4013 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
4017 * Tell the other part of the chip to suspend temporarily all
4020 resp_buf
= phba
->MBslimaddr
;
4022 /* Disable the error attention */
4023 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
4025 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
4026 readl(phba
->HCregaddr
); /* flush */
4027 phba
->link_flag
|= LS_IGNORE_ERATT
;
4029 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4031 if (ha_copy
& HA_ERATT
) {
4032 /* Clear Chip error bit */
4033 writel(HA_ERATT
, phba
->HAregaddr
);
4034 phba
->pport
->stopped
= 1;
4038 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
4039 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
4041 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
4042 mbox_buf
= phba
->MBslimaddr
;
4043 writel(mbox
, mbox_buf
);
4045 for (i
= 0; i
< 50; i
++) {
4046 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
4048 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
4054 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
4056 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
4057 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
4058 phba
->pport
->stopped
)
4064 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
4066 for (i
= 0; i
< 500; i
++) {
4067 if (lpfc_readl(resp_buf
, &resp_data
))
4069 if (resp_data
!= mbox
)
4078 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4080 if (!(ha_copy
& HA_ERATT
))
4086 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
4087 writel(HA_ERATT
, phba
->HAregaddr
);
4088 phba
->pport
->stopped
= 1;
4092 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4093 writel(hc_copy
, phba
->HCregaddr
);
4094 readl(phba
->HCregaddr
); /* flush */
4098 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4099 * @phba: Pointer to HBA context object.
4101 * This function issues a kill_board mailbox command and waits for
4102 * the error attention interrupt. This function is called for stopping
4103 * the firmware processing. The caller is not required to hold any
4104 * locks. This function calls lpfc_hba_down_post function to free
4105 * any pending commands after the kill. The function will return 1 when it
4106 * fails to kill the board else will return 0.
4109 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
4111 struct lpfc_sli
*psli
;
4121 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4122 "0329 Kill HBA Data: x%x x%x\n",
4123 phba
->pport
->port_state
, psli
->sli_flag
);
4125 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4129 /* Disable the error attention */
4130 spin_lock_irq(&phba
->hbalock
);
4131 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
4132 spin_unlock_irq(&phba
->hbalock
);
4133 mempool_free(pmb
, phba
->mbox_mem_pool
);
4136 status
&= ~HC_ERINT_ENA
;
4137 writel(status
, phba
->HCregaddr
);
4138 readl(phba
->HCregaddr
); /* flush */
4139 phba
->link_flag
|= LS_IGNORE_ERATT
;
4140 spin_unlock_irq(&phba
->hbalock
);
4142 lpfc_kill_board(phba
, pmb
);
4143 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4144 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4146 if (retval
!= MBX_SUCCESS
) {
4147 if (retval
!= MBX_BUSY
)
4148 mempool_free(pmb
, phba
->mbox_mem_pool
);
4149 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4150 "2752 KILL_BOARD command failed retval %d\n",
4152 spin_lock_irq(&phba
->hbalock
);
4153 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4154 spin_unlock_irq(&phba
->hbalock
);
4158 spin_lock_irq(&phba
->hbalock
);
4159 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
4160 spin_unlock_irq(&phba
->hbalock
);
4162 mempool_free(pmb
, phba
->mbox_mem_pool
);
4164 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4165 * attention every 100ms for 3 seconds. If we don't get ERATT after
4166 * 3 seconds we still set HBA_ERROR state because the status of the
4167 * board is now undefined.
4169 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4171 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
4173 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4177 del_timer_sync(&psli
->mbox_tmo
);
4178 if (ha_copy
& HA_ERATT
) {
4179 writel(HA_ERATT
, phba
->HAregaddr
);
4180 phba
->pport
->stopped
= 1;
4182 spin_lock_irq(&phba
->hbalock
);
4183 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4184 psli
->mbox_active
= NULL
;
4185 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4186 spin_unlock_irq(&phba
->hbalock
);
4188 lpfc_hba_down_post(phba
);
4189 phba
->link_state
= LPFC_HBA_ERROR
;
4191 return ha_copy
& HA_ERATT
? 0 : 1;
4195 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4196 * @phba: Pointer to HBA context object.
4198 * This function resets the HBA by writing HC_INITFF to the control
4199 * register. After the HBA resets, this function resets all the iocb ring
4200 * indices. This function disables PCI layer parity checking during
4202 * This function returns 0 always.
4203 * The caller is not required to hold any locks.
4206 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
4208 struct lpfc_sli
*psli
;
4209 struct lpfc_sli_ring
*pring
;
4216 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4217 "0325 Reset HBA Data: x%x x%x\n",
4218 (phba
->pport
) ? phba
->pport
->port_state
: 0,
4221 /* perform board reset */
4222 phba
->fc_eventTag
= 0;
4223 phba
->link_events
= 0;
4225 phba
->pport
->fc_myDID
= 0;
4226 phba
->pport
->fc_prevDID
= 0;
4229 /* Turn off parity checking and serr during the physical reset */
4230 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4231 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
4233 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4235 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
4237 /* Now toggle INITFF bit in the Host Control Register */
4238 writel(HC_INITFF
, phba
->HCregaddr
);
4240 readl(phba
->HCregaddr
); /* flush */
4241 writel(0, phba
->HCregaddr
);
4242 readl(phba
->HCregaddr
); /* flush */
4244 /* Restore PCI cmd register */
4245 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4247 /* Initialize relevant SLI info */
4248 for (i
= 0; i
< psli
->num_rings
; i
++) {
4249 pring
= &psli
->sli3_ring
[i
];
4251 pring
->sli
.sli3
.rspidx
= 0;
4252 pring
->sli
.sli3
.next_cmdidx
= 0;
4253 pring
->sli
.sli3
.local_getidx
= 0;
4254 pring
->sli
.sli3
.cmdidx
= 0;
4255 pring
->missbufcnt
= 0;
4258 phba
->link_state
= LPFC_WARM_START
;
4263 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4264 * @phba: Pointer to HBA context object.
4266 * This function resets a SLI4 HBA. This function disables PCI layer parity
4267 * checking during resets the device. The caller is not required to hold
4270 * This function returns 0 always.
4273 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
4275 struct lpfc_sli
*psli
= &phba
->sli
;
4280 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4281 "0295 Reset HBA Data: x%x x%x x%x\n",
4282 phba
->pport
->port_state
, psli
->sli_flag
,
4285 /* perform board reset */
4286 phba
->fc_eventTag
= 0;
4287 phba
->link_events
= 0;
4288 phba
->pport
->fc_myDID
= 0;
4289 phba
->pport
->fc_prevDID
= 0;
4291 spin_lock_irq(&phba
->hbalock
);
4292 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
4293 phba
->fcf
.fcf_flag
= 0;
4294 spin_unlock_irq(&phba
->hbalock
);
4296 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4297 if (phba
->hba_flag
& HBA_FW_DUMP_OP
) {
4298 phba
->hba_flag
&= ~HBA_FW_DUMP_OP
;
4302 /* Now physically reset the device */
4303 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4304 "0389 Performing PCI function reset!\n");
4306 /* Turn off parity checking and serr during the physical reset */
4307 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4308 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
4309 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4311 /* Perform FCoE PCI function reset before freeing queue memory */
4312 rc
= lpfc_pci_function_reset(phba
);
4314 /* Restore PCI cmd register */
4315 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4321 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4322 * @phba: Pointer to HBA context object.
4324 * This function is called in the SLI initialization code path to
4325 * restart the HBA. The caller is not required to hold any lock.
4326 * This function writes MBX_RESTART mailbox command to the SLIM and
4327 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4328 * function to free any pending commands. The function enables
4329 * POST only during the first initialization. The function returns zero.
4330 * The function does not guarantee completion of MBX_RESTART mailbox
4331 * command before the return of this function.
4334 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4337 struct lpfc_sli
*psli
;
4338 volatile uint32_t word0
;
4339 void __iomem
*to_slim
;
4340 uint32_t hba_aer_enabled
;
4342 spin_lock_irq(&phba
->hbalock
);
4344 /* Take PCIe device Advanced Error Reporting (AER) state */
4345 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4350 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4351 "0337 Restart HBA Data: x%x x%x\n",
4352 (phba
->pport
) ? phba
->pport
->port_state
: 0,
4356 mb
= (MAILBOX_t
*) &word0
;
4357 mb
->mbxCommand
= MBX_RESTART
;
4360 lpfc_reset_barrier(phba
);
4362 to_slim
= phba
->MBslimaddr
;
4363 writel(*(uint32_t *) mb
, to_slim
);
4364 readl(to_slim
); /* flush */
4366 /* Only skip post after fc_ffinit is completed */
4367 if (phba
->pport
&& phba
->pport
->port_state
)
4368 word0
= 1; /* This is really setting up word1 */
4370 word0
= 0; /* This is really setting up word1 */
4371 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4372 writel(*(uint32_t *) mb
, to_slim
);
4373 readl(to_slim
); /* flush */
4375 lpfc_sli_brdreset(phba
);
4377 phba
->pport
->stopped
= 0;
4378 phba
->link_state
= LPFC_INIT_START
;
4380 spin_unlock_irq(&phba
->hbalock
);
4382 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4383 psli
->stats_start
= get_seconds();
4385 /* Give the INITFF and Post time to settle. */
4388 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4389 if (hba_aer_enabled
)
4390 pci_disable_pcie_error_reporting(phba
->pcidev
);
4392 lpfc_hba_down_post(phba
);
4398 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4399 * @phba: Pointer to HBA context object.
4401 * This function is called in the SLI initialization code path to restart
4402 * a SLI4 HBA. The caller is not required to hold any lock.
4403 * At the end of the function, it calls lpfc_hba_down_post function to
4404 * free any pending commands.
4407 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4409 struct lpfc_sli
*psli
= &phba
->sli
;
4410 uint32_t hba_aer_enabled
;
4414 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4415 "0296 Restart HBA Data: x%x x%x\n",
4416 phba
->pport
->port_state
, psli
->sli_flag
);
4418 /* Take PCIe device Advanced Error Reporting (AER) state */
4419 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4421 rc
= lpfc_sli4_brdreset(phba
);
4423 spin_lock_irq(&phba
->hbalock
);
4424 phba
->pport
->stopped
= 0;
4425 phba
->link_state
= LPFC_INIT_START
;
4427 spin_unlock_irq(&phba
->hbalock
);
4429 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4430 psli
->stats_start
= get_seconds();
4432 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4433 if (hba_aer_enabled
)
4434 pci_disable_pcie_error_reporting(phba
->pcidev
);
4436 lpfc_hba_down_post(phba
);
4437 lpfc_sli4_queue_destroy(phba
);
4443 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4444 * @phba: Pointer to HBA context object.
4446 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4447 * API jump table function pointer from the lpfc_hba struct.
4450 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4452 return phba
->lpfc_sli_brdrestart(phba
);
4456 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4457 * @phba: Pointer to HBA context object.
4459 * This function is called after a HBA restart to wait for successful
4460 * restart of the HBA. Successful restart of the HBA is indicated by
4461 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4462 * iteration, the function will restart the HBA again. The function returns
4463 * zero if HBA successfully restarted else returns negative error code.
4466 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4468 uint32_t status
, i
= 0;
4470 /* Read the HBA Host Status Register */
4471 if (lpfc_readl(phba
->HSregaddr
, &status
))
4474 /* Check status register to see what current state is */
4476 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4478 /* Check every 10ms for 10 retries, then every 100ms for 90
4479 * retries, then every 1 sec for 50 retires for a total of
4480 * ~60 seconds before reset the board again and check every
4481 * 1 sec for 50 retries. The up to 60 seconds before the
4482 * board ready is required by the Falcon FIPS zeroization
4483 * complete, and any reset the board in between shall cause
4484 * restart of zeroization, further delay the board ready.
4487 /* Adapter failed to init, timeout, status reg
4489 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4490 "0436 Adapter failed to init, "
4491 "timeout, status reg x%x, "
4492 "FW Data: A8 x%x AC x%x\n", status
,
4493 readl(phba
->MBslimaddr
+ 0xa8),
4494 readl(phba
->MBslimaddr
+ 0xac));
4495 phba
->link_state
= LPFC_HBA_ERROR
;
4499 /* Check to see if any errors occurred during init */
4500 if (status
& HS_FFERM
) {
4501 /* ERROR: During chipset initialization */
4502 /* Adapter failed to init, chipset, status reg
4504 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4505 "0437 Adapter failed to init, "
4506 "chipset, status reg x%x, "
4507 "FW Data: A8 x%x AC x%x\n", status
,
4508 readl(phba
->MBslimaddr
+ 0xa8),
4509 readl(phba
->MBslimaddr
+ 0xac));
4510 phba
->link_state
= LPFC_HBA_ERROR
;
4523 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4524 lpfc_sli_brdrestart(phba
);
4526 /* Read the HBA Host Status Register */
4527 if (lpfc_readl(phba
->HSregaddr
, &status
))
4531 /* Check to see if any errors occurred during init */
4532 if (status
& HS_FFERM
) {
4533 /* ERROR: During chipset initialization */
4534 /* Adapter failed to init, chipset, status reg <status> */
4535 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4536 "0438 Adapter failed to init, chipset, "
4538 "FW Data: A8 x%x AC x%x\n", status
,
4539 readl(phba
->MBslimaddr
+ 0xa8),
4540 readl(phba
->MBslimaddr
+ 0xac));
4541 phba
->link_state
= LPFC_HBA_ERROR
;
4545 /* Clear all interrupt enable conditions */
4546 writel(0, phba
->HCregaddr
);
4547 readl(phba
->HCregaddr
); /* flush */
4549 /* setup host attn register */
4550 writel(0xffffffff, phba
->HAregaddr
);
4551 readl(phba
->HAregaddr
); /* flush */
4556 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4558 * This function calculates and returns the number of HBQs required to be
4562 lpfc_sli_hbq_count(void)
4564 return ARRAY_SIZE(lpfc_hbq_defs
);
4568 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4570 * This function adds the number of hbq entries in every HBQ to get
4571 * the total number of hbq entries required for the HBA and returns
4575 lpfc_sli_hbq_entry_count(void)
4577 int hbq_count
= lpfc_sli_hbq_count();
4581 for (i
= 0; i
< hbq_count
; ++i
)
4582 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4587 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4589 * This function calculates amount of memory required for all hbq entries
4590 * to be configured and returns the total memory required.
4593 lpfc_sli_hbq_size(void)
4595 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4599 * lpfc_sli_hbq_setup - configure and initialize HBQs
4600 * @phba: Pointer to HBA context object.
4602 * This function is called during the SLI initialization to configure
4603 * all the HBQs and post buffers to the HBQ. The caller is not
4604 * required to hold any locks. This function will return zero if successful
4605 * else it will return negative error code.
4608 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4610 int hbq_count
= lpfc_sli_hbq_count();
4614 uint32_t hbq_entry_index
;
4616 /* Get a Mailbox buffer to setup mailbox
4617 * commands for HBA initialization
4619 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4626 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4627 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4628 phba
->hbq_in_use
= 1;
4630 hbq_entry_index
= 0;
4631 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4632 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4633 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4634 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4635 phba
->hbqs
[hbqno
].entry_count
=
4636 lpfc_hbq_defs
[hbqno
]->entry_count
;
4637 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4638 hbq_entry_index
, pmb
);
4639 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4641 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4642 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4643 mbxStatus <status>, ring <num> */
4645 lpfc_printf_log(phba
, KERN_ERR
,
4646 LOG_SLI
| LOG_VPORT
,
4647 "1805 Adapter failed to init. "
4648 "Data: x%x x%x x%x\n",
4650 pmbox
->mbxStatus
, hbqno
);
4652 phba
->link_state
= LPFC_HBA_ERROR
;
4653 mempool_free(pmb
, phba
->mbox_mem_pool
);
4657 phba
->hbq_count
= hbq_count
;
4659 mempool_free(pmb
, phba
->mbox_mem_pool
);
4661 /* Initially populate or replenish the HBQs */
4662 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4663 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4668 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4669 * @phba: Pointer to HBA context object.
4671 * This function is called during the SLI initialization to configure
4672 * all the HBQs and post buffers to the HBQ. The caller is not
4673 * required to hold any locks. This function will return zero if successful
4674 * else it will return negative error code.
4677 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4679 phba
->hbq_in_use
= 1;
4680 phba
->hbqs
[LPFC_ELS_HBQ
].entry_count
=
4681 lpfc_hbq_defs
[LPFC_ELS_HBQ
]->entry_count
;
4682 phba
->hbq_count
= 1;
4683 lpfc_sli_hbqbuf_init_hbqs(phba
, LPFC_ELS_HBQ
);
4684 /* Initially populate or replenish the HBQs */
4689 * lpfc_sli_config_port - Issue config port mailbox command
4690 * @phba: Pointer to HBA context object.
4691 * @sli_mode: sli mode - 2/3
4693 * This function is called by the sli initialization code path
4694 * to issue config_port mailbox command. This function restarts the
4695 * HBA firmware and issues a config_port mailbox command to configure
4696 * the SLI interface in the sli mode specified by sli_mode
4697 * variable. The caller is not required to hold any locks.
4698 * The function returns 0 if successful, else returns negative error
4702 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4705 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4707 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4709 phba
->link_state
= LPFC_HBA_ERROR
;
4713 phba
->sli_rev
= sli_mode
;
4714 while (resetcount
< 2 && !done
) {
4715 spin_lock_irq(&phba
->hbalock
);
4716 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4717 spin_unlock_irq(&phba
->hbalock
);
4718 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4719 lpfc_sli_brdrestart(phba
);
4720 rc
= lpfc_sli_chipset_init(phba
);
4724 spin_lock_irq(&phba
->hbalock
);
4725 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4726 spin_unlock_irq(&phba
->hbalock
);
4729 /* Call pre CONFIG_PORT mailbox command initialization. A
4730 * value of 0 means the call was successful. Any other
4731 * nonzero value is a failure, but if ERESTART is returned,
4732 * the driver may reset the HBA and try again.
4734 rc
= lpfc_config_port_prep(phba
);
4735 if (rc
== -ERESTART
) {
4736 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4741 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4742 lpfc_config_port(phba
, pmb
);
4743 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4744 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4745 LPFC_SLI3_HBQ_ENABLED
|
4746 LPFC_SLI3_CRP_ENABLED
|
4747 LPFC_SLI3_BG_ENABLED
|
4748 LPFC_SLI3_DSS_ENABLED
);
4749 if (rc
!= MBX_SUCCESS
) {
4750 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4751 "0442 Adapter failed to init, mbxCmd x%x "
4752 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4753 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4754 spin_lock_irq(&phba
->hbalock
);
4755 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4756 spin_unlock_irq(&phba
->hbalock
);
4759 /* Allow asynchronous mailbox command to go through */
4760 spin_lock_irq(&phba
->hbalock
);
4761 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4762 spin_unlock_irq(&phba
->hbalock
);
4765 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4766 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4767 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4768 "3110 Port did not grant ASABT\n");
4773 goto do_prep_failed
;
4775 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4776 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4778 goto do_prep_failed
;
4780 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4781 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4782 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4783 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4784 phba
->max_vpi
: phba
->max_vports
;
4788 phba
->fips_level
= 0;
4789 phba
->fips_spec_rev
= 0;
4790 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4791 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4792 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4793 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4794 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4795 "2850 Security Crypto Active. FIPS x%d "
4797 phba
->fips_level
, phba
->fips_spec_rev
);
4799 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4800 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4801 "2856 Config Port Security Crypto "
4803 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4805 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4806 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4807 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4808 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4810 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4811 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4813 if (phba
->cfg_enable_bg
) {
4814 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4815 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4817 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4818 "0443 Adapter did not grant "
4822 phba
->hbq_get
= NULL
;
4823 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4827 mempool_free(pmb
, phba
->mbox_mem_pool
);
4833 * lpfc_sli_hba_setup - SLI initialization function
4834 * @phba: Pointer to HBA context object.
4836 * This function is the main SLI initialization function. This function
4837 * is called by the HBA initialization code, HBA reset code and HBA
4838 * error attention handler code. Caller is not required to hold any
4839 * locks. This function issues config_port mailbox command to configure
4840 * the SLI, setup iocb rings and HBQ rings. In the end the function
4841 * calls the config_port_post function to issue init_link mailbox
4842 * command and to start the discovery. The function will return zero
4843 * if successful, else it will return negative error code.
4846 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4852 switch (phba
->cfg_sli_mode
) {
4854 if (phba
->cfg_enable_npiv
) {
4855 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4856 "1824 NPIV enabled: Override sli_mode "
4857 "parameter (%d) to auto (0).\n",
4858 phba
->cfg_sli_mode
);
4867 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4868 "1819 Unrecognized sli_mode parameter: %d.\n",
4869 phba
->cfg_sli_mode
);
4873 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
4875 rc
= lpfc_sli_config_port(phba
, mode
);
4877 if (rc
&& phba
->cfg_sli_mode
== 3)
4878 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4879 "1820 Unable to select SLI-3. "
4880 "Not supported by adapter.\n");
4881 if (rc
&& mode
!= 2)
4882 rc
= lpfc_sli_config_port(phba
, 2);
4883 else if (rc
&& mode
== 2)
4884 rc
= lpfc_sli_config_port(phba
, 3);
4886 goto lpfc_sli_hba_setup_error
;
4888 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4889 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4890 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4892 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4893 "2709 This device supports "
4894 "Advanced Error Reporting (AER)\n");
4895 spin_lock_irq(&phba
->hbalock
);
4896 phba
->hba_flag
|= HBA_AER_ENABLED
;
4897 spin_unlock_irq(&phba
->hbalock
);
4899 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4900 "2708 This device does not support "
4901 "Advanced Error Reporting (AER): %d\n",
4903 phba
->cfg_aer_support
= 0;
4907 if (phba
->sli_rev
== 3) {
4908 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4909 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4911 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4912 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4913 phba
->sli3_options
= 0;
4916 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4917 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4918 phba
->sli_rev
, phba
->max_vpi
);
4919 rc
= lpfc_sli_ring_map(phba
);
4922 goto lpfc_sli_hba_setup_error
;
4924 /* Initialize VPIs. */
4925 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4927 * The VPI bitmask and physical ID array are allocated
4928 * and initialized once only - at driver load. A port
4929 * reset doesn't need to reinitialize this memory.
4931 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4932 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4933 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4935 if (!phba
->vpi_bmask
) {
4937 goto lpfc_sli_hba_setup_error
;
4940 phba
->vpi_ids
= kzalloc(
4941 (phba
->max_vpi
+1) * sizeof(uint16_t),
4943 if (!phba
->vpi_ids
) {
4944 kfree(phba
->vpi_bmask
);
4946 goto lpfc_sli_hba_setup_error
;
4948 for (i
= 0; i
< phba
->max_vpi
; i
++)
4949 phba
->vpi_ids
[i
] = i
;
4954 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4955 rc
= lpfc_sli_hbq_setup(phba
);
4957 goto lpfc_sli_hba_setup_error
;
4959 spin_lock_irq(&phba
->hbalock
);
4960 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4961 spin_unlock_irq(&phba
->hbalock
);
4963 rc
= lpfc_config_port_post(phba
);
4965 goto lpfc_sli_hba_setup_error
;
4969 lpfc_sli_hba_setup_error
:
4970 phba
->link_state
= LPFC_HBA_ERROR
;
4971 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4972 "0445 Firmware initialization failed\n");
4977 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4978 * @phba: Pointer to HBA context object.
4979 * @mboxq: mailbox pointer.
4980 * This function issue a dump mailbox command to read config region
4981 * 23 and parse the records in the region and populate driver
4985 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4987 LPFC_MBOXQ_t
*mboxq
;
4988 struct lpfc_dmabuf
*mp
;
4989 struct lpfc_mqe
*mqe
;
4990 uint32_t data_length
;
4993 /* Program the default value of vlan_id and fc_map */
4994 phba
->valid_vlan
= 0;
4995 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4996 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4997 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4999 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5003 mqe
= &mboxq
->u
.mqe
;
5004 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
5006 goto out_free_mboxq
;
5009 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
5010 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5012 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5013 "(%d):2571 Mailbox cmd x%x Status x%x "
5014 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5015 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5016 "CQ: x%x x%x x%x x%x\n",
5017 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5018 bf_get(lpfc_mqe_command
, mqe
),
5019 bf_get(lpfc_mqe_status
, mqe
),
5020 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
5021 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
5022 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
5023 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
5024 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
5025 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
5026 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
5027 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
5028 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
5030 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5031 mboxq
->mcqe
.trailer
);
5034 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5037 goto out_free_mboxq
;
5039 data_length
= mqe
->un
.mb_words
[5];
5040 if (data_length
> DMP_RGN23_SIZE
) {
5041 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5044 goto out_free_mboxq
;
5047 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
5048 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5053 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5058 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5059 * @phba: pointer to lpfc hba data structure.
5060 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5061 * @vpd: pointer to the memory to hold resulting port vpd data.
5062 * @vpd_size: On input, the number of bytes allocated to @vpd.
5063 * On output, the number of data bytes in @vpd.
5065 * This routine executes a READ_REV SLI4 mailbox command. In
5066 * addition, this routine gets the port vpd data.
5070 * -ENOMEM - could not allocated memory.
5073 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5074 uint8_t *vpd
, uint32_t *vpd_size
)
5078 struct lpfc_dmabuf
*dmabuf
;
5079 struct lpfc_mqe
*mqe
;
5081 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5086 * Get a DMA buffer for the vpd data resulting from the READ_REV
5089 dma_size
= *vpd_size
;
5090 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, dma_size
,
5091 &dmabuf
->phys
, GFP_KERNEL
);
5092 if (!dmabuf
->virt
) {
5098 * The SLI4 implementation of READ_REV conflicts at word1,
5099 * bits 31:16 and SLI4 adds vpd functionality not present
5100 * in SLI3. This code corrects the conflicts.
5102 lpfc_read_rev(phba
, mboxq
);
5103 mqe
= &mboxq
->u
.mqe
;
5104 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
5105 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
5106 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
5107 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
5108 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
5110 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5112 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
5113 dmabuf
->virt
, dmabuf
->phys
);
5119 * The available vpd length cannot be bigger than the
5120 * DMA buffer passed to the port. Catch the less than
5121 * case and update the caller's size.
5123 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
5124 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
5126 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
5128 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
5129 dmabuf
->virt
, dmabuf
->phys
);
5135 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5136 * @phba: pointer to lpfc hba data structure.
5138 * This routine retrieves SLI4 device physical port name this PCI function
5143 * otherwise - failed to retrieve physical port name
5146 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
5148 LPFC_MBOXQ_t
*mboxq
;
5149 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
5150 struct lpfc_controller_attribute
*cntl_attr
;
5151 struct lpfc_mbx_get_port_name
*get_port_name
;
5152 void *virtaddr
= NULL
;
5153 uint32_t alloclen
, reqlen
;
5154 uint32_t shdr_status
, shdr_add_status
;
5155 union lpfc_sli4_cfg_shdr
*shdr
;
5156 char cport_name
= 0;
5159 /* We assume nothing at this point */
5160 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
5161 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
5163 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5166 /* obtain link type and link number via READ_CONFIG */
5167 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
5168 lpfc_sli4_read_config(phba
);
5169 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
5170 goto retrieve_ppname
;
5172 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5173 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
5174 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5175 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
5176 LPFC_SLI4_MBX_NEMBED
);
5177 if (alloclen
< reqlen
) {
5178 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5179 "3084 Allocated DMA memory size (%d) is "
5180 "less than the requested DMA memory size "
5181 "(%d)\n", alloclen
, reqlen
);
5183 goto out_free_mboxq
;
5185 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5186 virtaddr
= mboxq
->sge_array
->addr
[0];
5187 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
5188 shdr
= &mbx_cntl_attr
->cfg_shdr
;
5189 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5190 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5191 if (shdr_status
|| shdr_add_status
|| rc
) {
5192 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5193 "3085 Mailbox x%x (x%x/x%x) failed, "
5194 "rc:x%x, status:x%x, add_status:x%x\n",
5195 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5196 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5197 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5198 rc
, shdr_status
, shdr_add_status
);
5200 goto out_free_mboxq
;
5202 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
5203 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
5204 phba
->sli4_hba
.lnk_info
.lnk_tp
=
5205 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
5206 phba
->sli4_hba
.lnk_info
.lnk_no
=
5207 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
5208 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5209 "3086 lnk_type:%d, lnk_numb:%d\n",
5210 phba
->sli4_hba
.lnk_info
.lnk_tp
,
5211 phba
->sli4_hba
.lnk_info
.lnk_no
);
5214 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5215 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
5216 sizeof(struct lpfc_mbx_get_port_name
) -
5217 sizeof(struct lpfc_sli4_cfg_mhdr
),
5218 LPFC_SLI4_MBX_EMBED
);
5219 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
5220 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
5221 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
5222 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
5223 phba
->sli4_hba
.lnk_info
.lnk_tp
);
5224 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5225 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5226 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5227 if (shdr_status
|| shdr_add_status
|| rc
) {
5228 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5229 "3087 Mailbox x%x (x%x/x%x) failed: "
5230 "rc:x%x, status:x%x, add_status:x%x\n",
5231 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5232 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5233 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5234 rc
, shdr_status
, shdr_add_status
);
5236 goto out_free_mboxq
;
5238 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
5239 case LPFC_LINK_NUMBER_0
:
5240 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
5241 &get_port_name
->u
.response
);
5242 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5244 case LPFC_LINK_NUMBER_1
:
5245 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
5246 &get_port_name
->u
.response
);
5247 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5249 case LPFC_LINK_NUMBER_2
:
5250 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
5251 &get_port_name
->u
.response
);
5252 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5254 case LPFC_LINK_NUMBER_3
:
5255 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
5256 &get_port_name
->u
.response
);
5257 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5263 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
5264 phba
->Port
[0] = cport_name
;
5265 phba
->Port
[1] = '\0';
5266 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5267 "3091 SLI get port name: %s\n", phba
->Port
);
5271 if (rc
!= MBX_TIMEOUT
) {
5272 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
5273 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
5275 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5281 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5282 * @phba: pointer to lpfc hba data structure.
5284 * This routine is called to explicitly arm the SLI4 device's completion and
5288 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
5292 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
5293 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
5294 if (phba
->sli4_hba
.nvmels_cq
)
5295 lpfc_sli4_cq_release(phba
->sli4_hba
.nvmels_cq
,
5298 if (phba
->sli4_hba
.fcp_cq
)
5299 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
5300 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[qidx
],
5303 if (phba
->sli4_hba
.nvme_cq
)
5304 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
5305 lpfc_sli4_cq_release(phba
->sli4_hba
.nvme_cq
[qidx
],
5309 lpfc_sli4_cq_release(phba
->sli4_hba
.oas_cq
, LPFC_QUEUE_REARM
);
5311 if (phba
->sli4_hba
.hba_eq
)
5312 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++)
5313 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[qidx
],
5316 if (phba
->nvmet_support
) {
5317 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++) {
5318 lpfc_sli4_cq_release(
5319 phba
->sli4_hba
.nvmet_cqset
[qidx
],
5325 lpfc_sli4_eq_release(phba
->sli4_hba
.fof_eq
, LPFC_QUEUE_REARM
);
5329 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5330 * @phba: Pointer to HBA context object.
5331 * @type: The resource extent type.
5332 * @extnt_count: buffer to hold port available extent count.
5333 * @extnt_size: buffer to hold element count per extent.
5335 * This function calls the port and retrievs the number of available
5336 * extents and their size for a particular extent type.
5338 * Returns: 0 if successful. Nonzero otherwise.
5341 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5342 uint16_t *extnt_count
, uint16_t *extnt_size
)
5347 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5350 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5354 /* Find out how many extents are available for this resource type */
5355 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5356 sizeof(struct lpfc_sli4_cfg_mhdr
));
5357 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5358 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5359 length
, LPFC_SLI4_MBX_EMBED
);
5361 /* Send an extents count of 0 - the GET doesn't use it. */
5362 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5363 LPFC_SLI4_MBX_EMBED
);
5369 if (!phba
->sli4_hba
.intr_enable
)
5370 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5372 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5373 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5380 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5381 if (bf_get(lpfc_mbox_hdr_status
,
5382 &rsrc_info
->header
.cfg_shdr
.response
)) {
5383 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5384 "2930 Failed to get resource extents "
5385 "Status 0x%x Add'l Status 0x%x\n",
5386 bf_get(lpfc_mbox_hdr_status
,
5387 &rsrc_info
->header
.cfg_shdr
.response
),
5388 bf_get(lpfc_mbox_hdr_add_status
,
5389 &rsrc_info
->header
.cfg_shdr
.response
));
5394 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5396 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5399 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5400 "3162 Retrieved extents type-%d from port: count:%d, "
5401 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5404 mempool_free(mbox
, phba
->mbox_mem_pool
);
5409 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5410 * @phba: Pointer to HBA context object.
5411 * @type: The extent type to check.
5413 * This function reads the current available extents from the port and checks
5414 * if the extent count or extent size has changed since the last access.
5415 * Callers use this routine post port reset to understand if there is a
5416 * extent reprovisioning requirement.
5419 * -Error: error indicates problem.
5420 * 1: Extent count or size has changed.
5424 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5426 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5427 uint16_t size_diff
, rsrc_ext_size
;
5429 struct lpfc_rsrc_blks
*rsrc_entry
;
5430 struct list_head
*rsrc_blk_list
= NULL
;
5434 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5441 case LPFC_RSC_TYPE_FCOE_RPI
:
5442 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5444 case LPFC_RSC_TYPE_FCOE_VPI
:
5445 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5447 case LPFC_RSC_TYPE_FCOE_XRI
:
5448 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5450 case LPFC_RSC_TYPE_FCOE_VFI
:
5451 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5457 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5459 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5463 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5470 * lpfc_sli4_cfg_post_extnts -
5471 * @phba: Pointer to HBA context object.
5472 * @extnt_cnt - number of available extents.
5473 * @type - the extent type (rpi, xri, vfi, vpi).
5474 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5475 * @mbox - pointer to the caller's allocated mailbox structure.
5477 * This function executes the extents allocation request. It also
5478 * takes care of the amount of memory needed to allocate or get the
5479 * allocated extents. It is the caller's responsibility to evaluate
5483 * -Error: Error value describes the condition found.
5487 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5488 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5493 uint32_t alloc_len
, mbox_tmo
;
5495 /* Calculate the total requested length of the dma memory */
5496 req_len
= extnt_cnt
* sizeof(uint16_t);
5499 * Calculate the size of an embedded mailbox. The uint32_t
5500 * accounts for extents-specific word.
5502 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5506 * Presume the allocation and response will fit into an embedded
5507 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5509 *emb
= LPFC_SLI4_MBX_EMBED
;
5510 if (req_len
> emb_len
) {
5511 req_len
= extnt_cnt
* sizeof(uint16_t) +
5512 sizeof(union lpfc_sli4_cfg_shdr
) +
5514 *emb
= LPFC_SLI4_MBX_NEMBED
;
5517 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5518 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5520 if (alloc_len
< req_len
) {
5521 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5522 "2982 Allocated DMA memory size (x%x) is "
5523 "less than the requested DMA memory "
5524 "size (x%x)\n", alloc_len
, req_len
);
5527 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5531 if (!phba
->sli4_hba
.intr_enable
)
5532 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5534 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5535 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5544 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5545 * @phba: Pointer to HBA context object.
5546 * @type: The resource extent type to allocate.
5548 * This function allocates the number of elements for the specified
5552 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5555 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5556 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5559 unsigned long longs
;
5560 unsigned long *bmask
;
5561 struct lpfc_rsrc_blks
*rsrc_blks
;
5564 struct lpfc_id_range
*id_array
= NULL
;
5565 void *virtaddr
= NULL
;
5566 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5567 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5568 struct list_head
*ext_blk_list
;
5570 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5576 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5577 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5578 "3009 No available Resource Extents "
5579 "for resource type 0x%x: Count: 0x%x, "
5580 "Size 0x%x\n", type
, rsrc_cnt
,
5585 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5586 "2903 Post resource extents type-0x%x: "
5587 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5589 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5593 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5600 * Figure out where the response is located. Then get local pointers
5601 * to the response data. The port does not guarantee to respond to
5602 * all extents counts request so update the local variable with the
5603 * allocated count from the port.
5605 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5606 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5607 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5608 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5610 virtaddr
= mbox
->sge_array
->addr
[0];
5611 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5612 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5613 id_array
= &n_rsrc
->id
;
5616 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5617 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5620 * Based on the resource size and count, correct the base and max
5623 length
= sizeof(struct lpfc_rsrc_blks
);
5625 case LPFC_RSC_TYPE_FCOE_RPI
:
5626 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5627 sizeof(unsigned long),
5629 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5633 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5636 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5637 kfree(phba
->sli4_hba
.rpi_bmask
);
5643 * The next_rpi was initialized with the maximum available
5644 * count but the port may allocate a smaller number. Catch
5645 * that case and update the next_rpi.
5647 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5649 /* Initialize local ptrs for common extent processing later. */
5650 bmask
= phba
->sli4_hba
.rpi_bmask
;
5651 ids
= phba
->sli4_hba
.rpi_ids
;
5652 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5654 case LPFC_RSC_TYPE_FCOE_VPI
:
5655 phba
->vpi_bmask
= kzalloc(longs
*
5656 sizeof(unsigned long),
5658 if (unlikely(!phba
->vpi_bmask
)) {
5662 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5665 if (unlikely(!phba
->vpi_ids
)) {
5666 kfree(phba
->vpi_bmask
);
5671 /* Initialize local ptrs for common extent processing later. */
5672 bmask
= phba
->vpi_bmask
;
5673 ids
= phba
->vpi_ids
;
5674 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5676 case LPFC_RSC_TYPE_FCOE_XRI
:
5677 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5678 sizeof(unsigned long),
5680 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5684 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5685 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5688 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5689 kfree(phba
->sli4_hba
.xri_bmask
);
5694 /* Initialize local ptrs for common extent processing later. */
5695 bmask
= phba
->sli4_hba
.xri_bmask
;
5696 ids
= phba
->sli4_hba
.xri_ids
;
5697 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5699 case LPFC_RSC_TYPE_FCOE_VFI
:
5700 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5701 sizeof(unsigned long),
5703 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5707 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5710 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5711 kfree(phba
->sli4_hba
.vfi_bmask
);
5716 /* Initialize local ptrs for common extent processing later. */
5717 bmask
= phba
->sli4_hba
.vfi_bmask
;
5718 ids
= phba
->sli4_hba
.vfi_ids
;
5719 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5722 /* Unsupported Opcode. Fail call. */
5726 ext_blk_list
= NULL
;
5731 * Complete initializing the extent configuration with the
5732 * allocated ids assigned to this function. The bitmask serves
5733 * as an index into the array and manages the available ids. The
5734 * array just stores the ids communicated to the port via the wqes.
5736 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5738 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5741 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5744 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5745 if (unlikely(!rsrc_blks
)) {
5751 rsrc_blks
->rsrc_start
= rsrc_id
;
5752 rsrc_blks
->rsrc_size
= rsrc_size
;
5753 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5754 rsrc_start
= rsrc_id
;
5755 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0)) {
5756 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5757 lpfc_sli4_get_iocb_cnt(phba
);
5758 phba
->sli4_hba
.nvme_xri_start
=
5759 phba
->sli4_hba
.scsi_xri_start
+
5760 phba
->sli4_hba
.scsi_xri_max
;
5763 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5768 /* Entire word processed. Get next word.*/
5773 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5780 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5781 * @phba: Pointer to HBA context object.
5782 * @type: the extent's type.
5784 * This function deallocates all extents of a particular resource type.
5785 * SLI4 does not allow for deallocating a particular extent range. It
5786 * is the caller's responsibility to release all kernel memory resources.
5789 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5792 uint32_t length
, mbox_tmo
= 0;
5794 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5795 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5797 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5802 * This function sends an embedded mailbox because it only sends the
5803 * the resource type. All extents of this type are released by the
5806 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5807 sizeof(struct lpfc_sli4_cfg_mhdr
));
5808 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5809 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5810 length
, LPFC_SLI4_MBX_EMBED
);
5812 /* Send an extents count of 0 - the dealloc doesn't use it. */
5813 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5814 LPFC_SLI4_MBX_EMBED
);
5819 if (!phba
->sli4_hba
.intr_enable
)
5820 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5822 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5823 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5830 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5831 if (bf_get(lpfc_mbox_hdr_status
,
5832 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5833 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5834 "2919 Failed to release resource extents "
5835 "for type %d - Status 0x%x Add'l Status 0x%x. "
5836 "Resource memory not released.\n",
5838 bf_get(lpfc_mbox_hdr_status
,
5839 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5840 bf_get(lpfc_mbox_hdr_add_status
,
5841 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5846 /* Release kernel memory resources for the specific type. */
5848 case LPFC_RSC_TYPE_FCOE_VPI
:
5849 kfree(phba
->vpi_bmask
);
5850 kfree(phba
->vpi_ids
);
5851 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5852 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5853 &phba
->lpfc_vpi_blk_list
, list
) {
5854 list_del_init(&rsrc_blk
->list
);
5857 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5859 case LPFC_RSC_TYPE_FCOE_XRI
:
5860 kfree(phba
->sli4_hba
.xri_bmask
);
5861 kfree(phba
->sli4_hba
.xri_ids
);
5862 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5863 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5864 list_del_init(&rsrc_blk
->list
);
5868 case LPFC_RSC_TYPE_FCOE_VFI
:
5869 kfree(phba
->sli4_hba
.vfi_bmask
);
5870 kfree(phba
->sli4_hba
.vfi_ids
);
5871 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5872 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5873 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5874 list_del_init(&rsrc_blk
->list
);
5878 case LPFC_RSC_TYPE_FCOE_RPI
:
5879 /* RPI bitmask and physical id array are cleaned up earlier. */
5880 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5881 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5882 list_del_init(&rsrc_blk
->list
);
5890 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5893 mempool_free(mbox
, phba
->mbox_mem_pool
);
5898 lpfc_set_features(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
,
5903 len
= sizeof(struct lpfc_mbx_set_feature
) -
5904 sizeof(struct lpfc_sli4_cfg_mhdr
);
5905 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5906 LPFC_MBOX_OPCODE_SET_FEATURES
, len
,
5907 LPFC_SLI4_MBX_EMBED
);
5910 case LPFC_SET_UE_RECOVERY
:
5911 bf_set(lpfc_mbx_set_feature_UER
,
5912 &mbox
->u
.mqe
.un
.set_feature
, 1);
5913 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_UE_RECOVERY
;
5914 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5916 case LPFC_SET_MDS_DIAGS
:
5917 bf_set(lpfc_mbx_set_feature_mds
,
5918 &mbox
->u
.mqe
.un
.set_feature
, 1);
5919 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk
,
5920 &mbox
->u
.mqe
.un
.set_feature
, 1);
5921 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_MDS_DIAGS
;
5922 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5930 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5931 * @phba: Pointer to HBA context object.
5933 * This function allocates all SLI4 resource identifiers.
5936 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5938 int i
, rc
, error
= 0;
5939 uint16_t count
, base
;
5940 unsigned long longs
;
5942 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5943 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5944 if (phba
->sli4_hba
.extents_in_use
) {
5946 * The port supports resource extents. The XRI, VPI, VFI, RPI
5947 * resource extent count must be read and allocated before
5948 * provisioning the resource id arrays.
5950 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5951 LPFC_IDX_RSRC_RDY
) {
5953 * Extent-based resources are set - the driver could
5954 * be in a port reset. Figure out if any corrective
5955 * actions need to be taken.
5957 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5958 LPFC_RSC_TYPE_FCOE_VFI
);
5961 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5962 LPFC_RSC_TYPE_FCOE_VPI
);
5965 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5966 LPFC_RSC_TYPE_FCOE_XRI
);
5969 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5970 LPFC_RSC_TYPE_FCOE_RPI
);
5975 * It's possible that the number of resources
5976 * provided to this port instance changed between
5977 * resets. Detect this condition and reallocate
5978 * resources. Otherwise, there is no action.
5981 lpfc_printf_log(phba
, KERN_INFO
,
5982 LOG_MBOX
| LOG_INIT
,
5983 "2931 Detected extent resource "
5984 "change. Reallocating all "
5986 rc
= lpfc_sli4_dealloc_extent(phba
,
5987 LPFC_RSC_TYPE_FCOE_VFI
);
5988 rc
= lpfc_sli4_dealloc_extent(phba
,
5989 LPFC_RSC_TYPE_FCOE_VPI
);
5990 rc
= lpfc_sli4_dealloc_extent(phba
,
5991 LPFC_RSC_TYPE_FCOE_XRI
);
5992 rc
= lpfc_sli4_dealloc_extent(phba
,
5993 LPFC_RSC_TYPE_FCOE_RPI
);
5998 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
6002 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
6006 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
6010 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
6013 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
6018 * The port does not support resource extents. The XRI, VPI,
6019 * VFI, RPI resource ids were determined from READ_CONFIG.
6020 * Just allocate the bitmasks and provision the resource id
6021 * arrays. If a port reset is active, the resources don't
6022 * need any action - just exit.
6024 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
6025 LPFC_IDX_RSRC_RDY
) {
6026 lpfc_sli4_dealloc_resource_identifiers(phba
);
6027 lpfc_sli4_remove_rpis(phba
);
6030 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
6032 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6033 "3279 Invalid provisioning of "
6038 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
6039 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6040 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
6041 sizeof(unsigned long),
6043 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
6047 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
6050 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
6052 goto free_rpi_bmask
;
6055 for (i
= 0; i
< count
; i
++)
6056 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
6059 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
6061 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6062 "3280 Invalid provisioning of "
6067 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
6068 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6069 phba
->vpi_bmask
= kzalloc(longs
*
6070 sizeof(unsigned long),
6072 if (unlikely(!phba
->vpi_bmask
)) {
6076 phba
->vpi_ids
= kzalloc(count
*
6079 if (unlikely(!phba
->vpi_ids
)) {
6081 goto free_vpi_bmask
;
6084 for (i
= 0; i
< count
; i
++)
6085 phba
->vpi_ids
[i
] = base
+ i
;
6088 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
6090 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6091 "3281 Invalid provisioning of "
6096 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
6097 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6098 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
6099 sizeof(unsigned long),
6101 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
6105 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
6106 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
6109 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
6111 goto free_xri_bmask
;
6114 for (i
= 0; i
< count
; i
++)
6115 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
6118 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
6120 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6121 "3282 Invalid provisioning of "
6126 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
6127 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6128 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
6129 sizeof(unsigned long),
6131 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
6135 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
6138 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
6140 goto free_vfi_bmask
;
6143 for (i
= 0; i
< count
; i
++)
6144 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
6147 * Mark all resources ready. An HBA reset doesn't need
6148 * to reset the initialization.
6150 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
6156 kfree(phba
->sli4_hba
.vfi_bmask
);
6157 phba
->sli4_hba
.vfi_bmask
= NULL
;
6159 kfree(phba
->sli4_hba
.xri_ids
);
6160 phba
->sli4_hba
.xri_ids
= NULL
;
6162 kfree(phba
->sli4_hba
.xri_bmask
);
6163 phba
->sli4_hba
.xri_bmask
= NULL
;
6165 kfree(phba
->vpi_ids
);
6166 phba
->vpi_ids
= NULL
;
6168 kfree(phba
->vpi_bmask
);
6169 phba
->vpi_bmask
= NULL
;
6171 kfree(phba
->sli4_hba
.rpi_ids
);
6172 phba
->sli4_hba
.rpi_ids
= NULL
;
6174 kfree(phba
->sli4_hba
.rpi_bmask
);
6175 phba
->sli4_hba
.rpi_bmask
= NULL
;
6181 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6182 * @phba: Pointer to HBA context object.
6184 * This function allocates the number of elements for the specified
6188 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
6190 if (phba
->sli4_hba
.extents_in_use
) {
6191 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
6192 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
6193 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
6194 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
6196 kfree(phba
->vpi_bmask
);
6197 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
6198 kfree(phba
->vpi_ids
);
6199 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6200 kfree(phba
->sli4_hba
.xri_bmask
);
6201 kfree(phba
->sli4_hba
.xri_ids
);
6202 kfree(phba
->sli4_hba
.vfi_bmask
);
6203 kfree(phba
->sli4_hba
.vfi_ids
);
6204 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6205 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6212 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6213 * @phba: Pointer to HBA context object.
6214 * @type: The resource extent type.
6215 * @extnt_count: buffer to hold port extent count response
6216 * @extnt_size: buffer to hold port extent size response.
6218 * This function calls the port to read the host allocated extents
6219 * for a particular type.
6222 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
6223 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
6227 uint16_t curr_blks
= 0;
6228 uint32_t req_len
, emb_len
;
6229 uint32_t alloc_len
, mbox_tmo
;
6230 struct list_head
*blk_list_head
;
6231 struct lpfc_rsrc_blks
*rsrc_blk
;
6233 void *virtaddr
= NULL
;
6234 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
6235 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
6236 union lpfc_sli4_cfg_shdr
*shdr
;
6239 case LPFC_RSC_TYPE_FCOE_VPI
:
6240 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
6242 case LPFC_RSC_TYPE_FCOE_XRI
:
6243 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
6245 case LPFC_RSC_TYPE_FCOE_VFI
:
6246 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
6248 case LPFC_RSC_TYPE_FCOE_RPI
:
6249 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
6255 /* Count the number of extents currently allocatd for this type. */
6256 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
6257 if (curr_blks
== 0) {
6259 * The GET_ALLOCATED mailbox does not return the size,
6260 * just the count. The size should be just the size
6261 * stored in the current allocated block and all sizes
6262 * for an extent type are the same so set the return
6265 *extnt_size
= rsrc_blk
->rsrc_size
;
6271 * Calculate the size of an embedded mailbox. The uint32_t
6272 * accounts for extents-specific word.
6274 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
6278 * Presume the allocation and response will fit into an embedded
6279 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6281 emb
= LPFC_SLI4_MBX_EMBED
;
6283 if (req_len
> emb_len
) {
6284 req_len
= curr_blks
* sizeof(uint16_t) +
6285 sizeof(union lpfc_sli4_cfg_shdr
) +
6287 emb
= LPFC_SLI4_MBX_NEMBED
;
6290 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6293 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
6295 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6296 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
6298 if (alloc_len
< req_len
) {
6299 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6300 "2983 Allocated DMA memory size (x%x) is "
6301 "less than the requested DMA memory "
6302 "size (x%x)\n", alloc_len
, req_len
);
6306 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
6312 if (!phba
->sli4_hba
.intr_enable
)
6313 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6315 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
6316 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6325 * Figure out where the response is located. Then get local pointers
6326 * to the response data. The port does not guarantee to respond to
6327 * all extents counts request so update the local variable with the
6328 * allocated count from the port.
6330 if (emb
== LPFC_SLI4_MBX_EMBED
) {
6331 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
6332 shdr
= &rsrc_ext
->header
.cfg_shdr
;
6333 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
6335 virtaddr
= mbox
->sge_array
->addr
[0];
6336 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
6337 shdr
= &n_rsrc
->cfg_shdr
;
6338 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
6341 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
6342 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
6343 "2984 Failed to read allocated resources "
6344 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6346 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
6347 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
6352 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
6357 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
6358 * @phba: pointer to lpfc hba data structure.
6359 * @pring: Pointer to driver SLI ring object.
6360 * @sgl_list: linked link of sgl buffers to post
6361 * @cnt: number of linked list buffers
6363 * This routine walks the list of buffers that have been allocated and
6364 * repost them to the port by using SGL block post. This is needed after a
6365 * pci_function_reset/warm_start or start. It attempts to construct blocks
6366 * of buffer sgls which contains contiguous xris and uses the non-embedded
6367 * SGL block post mailbox commands to post them to the port. For single
6368 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6369 * mailbox command for posting.
6371 * Returns: 0 = success, non-zero failure.
6374 lpfc_sli4_repost_sgl_list(struct lpfc_hba
*phba
,
6375 struct list_head
*sgl_list
, int cnt
)
6377 struct lpfc_sglq
*sglq_entry
= NULL
;
6378 struct lpfc_sglq
*sglq_entry_next
= NULL
;
6379 struct lpfc_sglq
*sglq_entry_first
= NULL
;
6380 int status
, total_cnt
;
6381 int post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
6382 int last_xritag
= NO_XRI
;
6383 LIST_HEAD(prep_sgl_list
);
6384 LIST_HEAD(blck_sgl_list
);
6385 LIST_HEAD(allc_sgl_list
);
6386 LIST_HEAD(post_sgl_list
);
6387 LIST_HEAD(free_sgl_list
);
6389 spin_lock_irq(&phba
->hbalock
);
6390 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6391 list_splice_init(sgl_list
, &allc_sgl_list
);
6392 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6393 spin_unlock_irq(&phba
->hbalock
);
6396 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6397 &allc_sgl_list
, list
) {
6398 list_del_init(&sglq_entry
->list
);
6400 if ((last_xritag
!= NO_XRI
) &&
6401 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6402 /* a hole in xri block, form a sgl posting block */
6403 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6404 post_cnt
= block_cnt
- 1;
6405 /* prepare list for next posting block */
6406 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6409 /* prepare list for next posting block */
6410 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6411 /* enough sgls for non-embed sgl mbox command */
6412 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6413 list_splice_init(&prep_sgl_list
,
6415 post_cnt
= block_cnt
;
6421 /* keep track of last sgl's xritag */
6422 last_xritag
= sglq_entry
->sli4_xritag
;
6424 /* end of repost sgl list condition for buffers */
6425 if (num_posted
== total_cnt
) {
6426 if (post_cnt
== 0) {
6427 list_splice_init(&prep_sgl_list
,
6429 post_cnt
= block_cnt
;
6430 } else if (block_cnt
== 1) {
6431 status
= lpfc_sli4_post_sgl(phba
,
6432 sglq_entry
->phys
, 0,
6433 sglq_entry
->sli4_xritag
);
6435 /* successful, put sgl to posted list */
6436 list_add_tail(&sglq_entry
->list
,
6439 /* Failure, put sgl to free list */
6440 lpfc_printf_log(phba
, KERN_WARNING
,
6442 "3159 Failed to post "
6443 "sgl, xritag:x%x\n",
6444 sglq_entry
->sli4_xritag
);
6445 list_add_tail(&sglq_entry
->list
,
6452 /* continue until a nembed page worth of sgls */
6456 /* post the buffer list sgls as a block */
6457 status
= lpfc_sli4_post_sgl_list(phba
, &blck_sgl_list
,
6461 /* success, put sgl list to posted sgl list */
6462 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6464 /* Failure, put sgl list to free sgl list */
6465 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6468 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6469 "3160 Failed to post sgl-list, "
6471 sglq_entry_first
->sli4_xritag
,
6472 (sglq_entry_first
->sli4_xritag
+
6474 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6475 total_cnt
-= post_cnt
;
6478 /* don't reset xirtag due to hole in xri block */
6480 last_xritag
= NO_XRI
;
6482 /* reset sgl post count for next round of posting */
6486 /* free the sgls failed to post */
6487 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6489 /* push sgls posted to the available list */
6490 if (!list_empty(&post_sgl_list
)) {
6491 spin_lock_irq(&phba
->hbalock
);
6492 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6493 list_splice_init(&post_sgl_list
, sgl_list
);
6494 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6495 spin_unlock_irq(&phba
->hbalock
);
6497 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6498 "3161 Failure to post sgl to port.\n");
6502 /* return the number of XRIs actually posted */
6507 lpfc_set_host_data(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
6511 len
= sizeof(struct lpfc_mbx_set_host_data
) -
6512 sizeof(struct lpfc_sli4_cfg_mhdr
);
6513 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6514 LPFC_MBOX_OPCODE_SET_HOST_DATA
, len
,
6515 LPFC_SLI4_MBX_EMBED
);
6517 mbox
->u
.mqe
.un
.set_host_data
.param_id
= LPFC_SET_HOST_OS_DRIVER_VERSION
;
6518 mbox
->u
.mqe
.un
.set_host_data
.param_len
=
6519 LPFC_HOST_OS_DRIVER_VERSION_SIZE
;
6520 snprintf(mbox
->u
.mqe
.un
.set_host_data
.data
,
6521 LPFC_HOST_OS_DRIVER_VERSION_SIZE
,
6522 "Linux %s v"LPFC_DRIVER_VERSION
,
6523 (phba
->hba_flag
& HBA_FCOE_MODE
) ? "FCoE" : "FC");
6527 lpfc_post_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
6528 struct lpfc_queue
*drq
, int count
, int idx
)
6531 struct lpfc_rqe hrqe
;
6532 struct lpfc_rqe drqe
;
6533 struct lpfc_rqb
*rqbp
;
6534 struct rqb_dmabuf
*rqb_buffer
;
6535 LIST_HEAD(rqb_buf_list
);
6538 for (i
= 0; i
< count
; i
++) {
6539 /* IF RQ is already full, don't bother */
6540 if (rqbp
->buffer_count
+ i
>= rqbp
->entry_count
- 1)
6542 rqb_buffer
= rqbp
->rqb_alloc_buffer(phba
);
6545 rqb_buffer
->hrq
= hrq
;
6546 rqb_buffer
->drq
= drq
;
6547 rqb_buffer
->idx
= idx
;
6548 list_add_tail(&rqb_buffer
->hbuf
.list
, &rqb_buf_list
);
6550 while (!list_empty(&rqb_buf_list
)) {
6551 list_remove_head(&rqb_buf_list
, rqb_buffer
, struct rqb_dmabuf
,
6554 hrqe
.address_lo
= putPaddrLow(rqb_buffer
->hbuf
.phys
);
6555 hrqe
.address_hi
= putPaddrHigh(rqb_buffer
->hbuf
.phys
);
6556 drqe
.address_lo
= putPaddrLow(rqb_buffer
->dbuf
.phys
);
6557 drqe
.address_hi
= putPaddrHigh(rqb_buffer
->dbuf
.phys
);
6558 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
6560 rqbp
->rqb_free_buffer(phba
, rqb_buffer
);
6562 list_add_tail(&rqb_buffer
->hbuf
.list
,
6563 &rqbp
->rqb_buffer_list
);
6564 rqbp
->buffer_count
++;
6571 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
6572 * @phba: Pointer to HBA context object.
6574 * This function is the main SLI4 device initialization PCI function. This
6575 * function is called by the HBA initialization code, HBA reset code and
6576 * HBA error attention handler code. Caller is not required to hold any
6580 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6583 LPFC_MBOXQ_t
*mboxq
;
6584 struct lpfc_mqe
*mqe
;
6587 uint32_t ftr_rsp
= 0;
6588 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6589 struct lpfc_vport
*vport
= phba
->pport
;
6590 struct lpfc_dmabuf
*mp
;
6591 struct lpfc_rqb
*rqbp
;
6593 /* Perform a PCI function reset to start from clean */
6594 rc
= lpfc_pci_function_reset(phba
);
6598 /* Check the HBA Host Status Register for readyness */
6599 rc
= lpfc_sli4_post_status_check(phba
);
6603 spin_lock_irq(&phba
->hbalock
);
6604 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6605 spin_unlock_irq(&phba
->hbalock
);
6609 * Allocate a single mailbox container for initializing the
6612 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6616 /* Issue READ_REV to collect vpd and FW information. */
6617 vpd_size
= SLI4_PAGE_SIZE
;
6618 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6624 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6630 mqe
= &mboxq
->u
.mqe
;
6631 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6632 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
)) {
6633 phba
->hba_flag
|= HBA_FCOE_MODE
;
6634 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
6636 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6639 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6641 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6643 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6645 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6647 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6648 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6649 "0376 READ_REV Error. SLI Level %d "
6650 "FCoE enabled %d\n",
6651 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6658 * Continue initialization with default values even if driver failed
6659 * to read FCoE param config regions, only read parameters if the
6662 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6663 lpfc_sli4_read_fcoe_params(phba
))
6664 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6665 "2570 Failed to read FCoE parameters\n");
6668 * Retrieve sli4 device physical port name, failure of doing it
6669 * is considered as non-fatal.
6671 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6673 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6674 "3080 Successful retrieving SLI4 device "
6675 "physical port name: %s.\n", phba
->Port
);
6678 * Evaluate the read rev and vpd data. Populate the driver
6679 * state with the results. If this routine fails, the failure
6680 * is not fatal as the driver will use generic values.
6682 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6683 if (unlikely(!rc
)) {
6684 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6685 "0377 Error %d parsing vpd. "
6686 "Using defaults.\n", rc
);
6691 /* Save information as VPD data */
6692 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6693 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6694 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6695 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6697 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6699 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6701 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6703 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6704 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6705 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6706 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6707 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6708 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6709 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6710 "(%d):0380 READ_REV Status x%x "
6711 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6712 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6713 bf_get(lpfc_mqe_status
, mqe
),
6714 phba
->vpd
.rev
.opFwName
,
6715 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6716 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6718 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6719 rc
= (phba
->sli4_hba
.max_cfg_param
.max_xri
>> 3);
6720 if (phba
->pport
->cfg_lun_queue_depth
> rc
) {
6721 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6722 "3362 LUN queue depth changed from %d to %d\n",
6723 phba
->pport
->cfg_lun_queue_depth
, rc
);
6724 phba
->pport
->cfg_lun_queue_depth
= rc
;
6727 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6728 LPFC_SLI_INTF_IF_TYPE_0
) {
6729 lpfc_set_features(phba
, mboxq
, LPFC_SET_UE_RECOVERY
);
6730 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6731 if (rc
== MBX_SUCCESS
) {
6732 phba
->hba_flag
|= HBA_RECOVERABLE_UE
;
6733 /* Set 1Sec interval to detect UE */
6734 phba
->eratt_poll_interval
= 1;
6735 phba
->sli4_hba
.ue_to_sr
= bf_get(
6736 lpfc_mbx_set_feature_UESR
,
6737 &mboxq
->u
.mqe
.un
.set_feature
);
6738 phba
->sli4_hba
.ue_to_rp
= bf_get(
6739 lpfc_mbx_set_feature_UERP
,
6740 &mboxq
->u
.mqe
.un
.set_feature
);
6744 if (phba
->cfg_enable_mds_diags
&& phba
->mds_diags_support
) {
6745 /* Enable MDS Diagnostics only if the SLI Port supports it */
6746 lpfc_set_features(phba
, mboxq
, LPFC_SET_MDS_DIAGS
);
6747 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6748 if (rc
!= MBX_SUCCESS
)
6749 phba
->mds_diags_support
= 0;
6753 * Discover the port's supported feature set and match it against the
6756 lpfc_request_features(phba
, mboxq
);
6757 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6764 * The port must support FCP initiator mode as this is the
6765 * only mode running in the host.
6767 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6768 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6769 "0378 No support for fcpi mode.\n");
6772 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6773 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6775 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6777 * If the port cannot support the host's requested features
6778 * then turn off the global config parameters to disable the
6779 * feature in the driver. This is not a fatal error.
6781 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6782 if (phba
->cfg_enable_bg
) {
6783 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6784 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6789 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6790 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6794 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6795 "0379 Feature Mismatch Data: x%08x %08x "
6796 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6797 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6798 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6799 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6800 phba
->cfg_enable_bg
= 0;
6801 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6802 phba
->cfg_enable_npiv
= 0;
6805 /* These SLI3 features are assumed in SLI4 */
6806 spin_lock_irq(&phba
->hbalock
);
6807 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6808 spin_unlock_irq(&phba
->hbalock
);
6811 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6812 * calls depends on these resources to complete port setup.
6814 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6816 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6817 "2920 Failed to alloc Resource IDs "
6822 lpfc_set_host_data(phba
, mboxq
);
6824 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6826 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6827 "2134 Failed to set host os driver version %x",
6831 /* Read the port's service parameters. */
6832 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6834 phba
->link_state
= LPFC_HBA_ERROR
;
6839 mboxq
->vport
= vport
;
6840 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6841 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6842 if (rc
== MBX_SUCCESS
) {
6843 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6848 * This memory was allocated by the lpfc_read_sparam routine. Release
6849 * it to the mbuf pool.
6851 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6853 mboxq
->context1
= NULL
;
6855 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6856 "0382 READ_SPARAM command failed "
6857 "status %d, mbxStatus x%x\n",
6858 rc
, bf_get(lpfc_mqe_status
, mqe
));
6859 phba
->link_state
= LPFC_HBA_ERROR
;
6864 lpfc_update_vport_wwn(vport
);
6866 /* Update the fc_host data structures with new wwn. */
6867 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6868 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6870 /* Create all the SLI4 queues */
6871 rc
= lpfc_sli4_queue_create(phba
);
6873 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6874 "3089 Failed to allocate queues\n");
6878 /* Set up all the queues to the device */
6879 rc
= lpfc_sli4_queue_setup(phba
);
6881 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6882 "0381 Error %d during queue setup.\n ", rc
);
6883 goto out_stop_timers
;
6885 /* Initialize the driver internal SLI layer lists. */
6886 lpfc_sli4_setup(phba
);
6887 lpfc_sli4_queue_init(phba
);
6889 /* update host els xri-sgl sizes and mappings */
6890 rc
= lpfc_sli4_els_sgl_update(phba
);
6892 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6893 "1400 Failed to update xri-sgl size and "
6894 "mapping: %d\n", rc
);
6895 goto out_destroy_queue
;
6898 /* register the els sgl pool to the port */
6899 rc
= lpfc_sli4_repost_sgl_list(phba
, &phba
->sli4_hba
.lpfc_els_sgl_list
,
6900 phba
->sli4_hba
.els_xri_cnt
);
6901 if (unlikely(rc
< 0)) {
6902 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6903 "0582 Error %d during els sgl post "
6906 goto out_destroy_queue
;
6908 phba
->sli4_hba
.els_xri_cnt
= rc
;
6910 if (phba
->nvmet_support
) {
6911 /* update host nvmet xri-sgl sizes and mappings */
6912 rc
= lpfc_sli4_nvmet_sgl_update(phba
);
6914 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6915 "6308 Failed to update nvmet-sgl size "
6916 "and mapping: %d\n", rc
);
6917 goto out_destroy_queue
;
6920 /* register the nvmet sgl pool to the port */
6921 rc
= lpfc_sli4_repost_sgl_list(
6923 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
,
6924 phba
->sli4_hba
.nvmet_xri_cnt
);
6925 if (unlikely(rc
< 0)) {
6926 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6927 "3117 Error %d during nvmet "
6930 goto out_destroy_queue
;
6932 phba
->sli4_hba
.nvmet_xri_cnt
= rc
;
6934 cnt
= phba
->cfg_iocb_cnt
* 1024;
6935 /* We need 1 iocbq for every SGL, for IO processing */
6936 cnt
+= phba
->sli4_hba
.nvmet_xri_cnt
;
6938 /* update host scsi xri-sgl sizes and mappings */
6939 rc
= lpfc_sli4_scsi_sgl_update(phba
);
6941 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6942 "6309 Failed to update scsi-sgl size "
6943 "and mapping: %d\n", rc
);
6944 goto out_destroy_queue
;
6947 /* update host nvme xri-sgl sizes and mappings */
6948 rc
= lpfc_sli4_nvme_sgl_update(phba
);
6950 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6951 "6082 Failed to update nvme-sgl size "
6952 "and mapping: %d\n", rc
);
6953 goto out_destroy_queue
;
6956 cnt
= phba
->cfg_iocb_cnt
* 1024;
6959 if (!phba
->sli
.iocbq_lookup
) {
6960 /* Initialize and populate the iocb list per host */
6961 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6962 "2821 initialize iocb list %d total %d\n",
6963 phba
->cfg_iocb_cnt
, cnt
);
6964 rc
= lpfc_init_iocb_list(phba
, cnt
);
6966 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6967 "1413 Failed to init iocb list.\n");
6968 goto out_destroy_queue
;
6972 if (phba
->nvmet_support
)
6973 lpfc_nvmet_create_targetport(phba
);
6975 if (phba
->nvmet_support
&& phba
->cfg_nvmet_mrq
) {
6976 /* Post initial buffers to all RQs created */
6977 for (i
= 0; i
< phba
->cfg_nvmet_mrq
; i
++) {
6978 rqbp
= phba
->sli4_hba
.nvmet_mrq_hdr
[i
]->rqbp
;
6979 INIT_LIST_HEAD(&rqbp
->rqb_buffer_list
);
6980 rqbp
->rqb_alloc_buffer
= lpfc_sli4_nvmet_alloc
;
6981 rqbp
->rqb_free_buffer
= lpfc_sli4_nvmet_free
;
6982 rqbp
->entry_count
= LPFC_NVMET_RQE_DEF_COUNT
;
6983 rqbp
->buffer_count
= 0;
6985 lpfc_post_rq_buffer(
6986 phba
, phba
->sli4_hba
.nvmet_mrq_hdr
[i
],
6987 phba
->sli4_hba
.nvmet_mrq_data
[i
],
6988 LPFC_NVMET_RQE_DEF_COUNT
, i
);
6992 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
6993 /* register the allocated scsi sgl pool to the port */
6994 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6996 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6997 "0383 Error %d during scsi sgl post "
6999 /* Some Scsi buffers were moved to abort scsi list */
7000 /* A pci function reset will repost them */
7002 goto out_destroy_queue
;
7006 if ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) &&
7007 (phba
->nvmet_support
== 0)) {
7009 /* register the allocated nvme sgl pool to the port */
7010 rc
= lpfc_repost_nvme_sgl_list(phba
);
7012 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7013 "6116 Error %d during nvme sgl post "
7015 /* Some NVME buffers were moved to abort nvme list */
7016 /* A pci function reset will repost them */
7018 goto out_destroy_queue
;
7022 /* Post the rpi header region to the device. */
7023 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
7025 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7026 "0393 Error %d during rpi post operation\n",
7029 goto out_destroy_queue
;
7031 lpfc_sli4_node_prep(phba
);
7033 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
7034 if ((phba
->nvmet_support
== 0) || (phba
->cfg_nvmet_mrq
== 1)) {
7036 * The FC Port needs to register FCFI (index 0)
7038 lpfc_reg_fcfi(phba
, mboxq
);
7039 mboxq
->vport
= phba
->pport
;
7040 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7041 if (rc
!= MBX_SUCCESS
)
7042 goto out_unset_queue
;
7044 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
7045 &mboxq
->u
.mqe
.un
.reg_fcfi
);
7047 /* We are a NVME Target mode with MRQ > 1 */
7049 /* First register the FCFI */
7050 lpfc_reg_fcfi_mrq(phba
, mboxq
, 0);
7051 mboxq
->vport
= phba
->pport
;
7052 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7053 if (rc
!= MBX_SUCCESS
)
7054 goto out_unset_queue
;
7056 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_mrq_fcfi
,
7057 &mboxq
->u
.mqe
.un
.reg_fcfi_mrq
);
7059 /* Next register the MRQs */
7060 lpfc_reg_fcfi_mrq(phba
, mboxq
, 1);
7061 mboxq
->vport
= phba
->pport
;
7062 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7063 if (rc
!= MBX_SUCCESS
)
7064 goto out_unset_queue
;
7067 /* Check if the port is configured to be disabled */
7068 lpfc_sli_read_link_ste(phba
);
7071 /* Arm the CQs and then EQs on device */
7072 lpfc_sli4_arm_cqeq_intr(phba
);
7074 /* Indicate device interrupt mode */
7075 phba
->sli4_hba
.intr_enable
= 1;
7077 /* Allow asynchronous mailbox command to go through */
7078 spin_lock_irq(&phba
->hbalock
);
7079 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7080 spin_unlock_irq(&phba
->hbalock
);
7082 /* Post receive buffers to the device */
7083 lpfc_sli4_rb_setup(phba
);
7085 /* Reset HBA FCF states after HBA reset */
7086 phba
->fcf
.fcf_flag
= 0;
7087 phba
->fcf
.current_rec
.flag
= 0;
7089 /* Start the ELS watchdog timer */
7090 mod_timer(&vport
->els_tmofunc
,
7091 jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2)));
7093 /* Start heart beat timer */
7094 mod_timer(&phba
->hb_tmofunc
,
7095 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
7096 phba
->hb_outstanding
= 0;
7097 phba
->last_completion_time
= jiffies
;
7099 /* Start error attention (ERATT) polling timer */
7100 mod_timer(&phba
->eratt_poll
,
7101 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
7103 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
7104 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
7105 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
7107 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7108 "2829 This device supports "
7109 "Advanced Error Reporting (AER)\n");
7110 spin_lock_irq(&phba
->hbalock
);
7111 phba
->hba_flag
|= HBA_AER_ENABLED
;
7112 spin_unlock_irq(&phba
->hbalock
);
7114 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7115 "2830 This device does not support "
7116 "Advanced Error Reporting (AER)\n");
7117 phba
->cfg_aer_support
= 0;
7123 * The port is ready, set the host's link state to LINK_DOWN
7124 * in preparation for link interrupts.
7126 spin_lock_irq(&phba
->hbalock
);
7127 phba
->link_state
= LPFC_LINK_DOWN
;
7128 spin_unlock_irq(&phba
->hbalock
);
7129 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
7130 (phba
->hba_flag
& LINK_DISABLED
)) {
7131 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
7132 "3103 Adapter Link is disabled.\n");
7133 lpfc_down_link(phba
, mboxq
);
7134 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7135 if (rc
!= MBX_SUCCESS
) {
7136 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
7137 "3104 Adapter failed to issue "
7138 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
7139 goto out_unset_queue
;
7141 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
7142 /* don't perform init_link on SLI4 FC port loopback test */
7143 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
7144 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
7146 goto out_unset_queue
;
7149 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7152 /* Unset all the queues set up in this routine when error out */
7153 lpfc_sli4_queue_unset(phba
);
7155 lpfc_free_iocb_list(phba
);
7156 lpfc_sli4_queue_destroy(phba
);
7158 lpfc_stop_hba_timers(phba
);
7160 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7165 * lpfc_mbox_timeout - Timeout call back function for mbox timer
7166 * @ptr: context object - pointer to hba structure.
7168 * This is the callback function for mailbox timer. The mailbox
7169 * timer is armed when a new mailbox command is issued and the timer
7170 * is deleted when the mailbox complete. The function is called by
7171 * the kernel timer code when a mailbox does not complete within
7172 * expected time. This function wakes up the worker thread to
7173 * process the mailbox timeout and returns. All the processing is
7174 * done by the worker thread function lpfc_mbox_timeout_handler.
7177 lpfc_mbox_timeout(struct timer_list
*t
)
7179 struct lpfc_hba
*phba
= from_timer(phba
, t
, sli
.mbox_tmo
);
7180 unsigned long iflag
;
7181 uint32_t tmo_posted
;
7183 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
7184 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
7186 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
7187 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
7190 lpfc_worker_wake_up(phba
);
7195 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
7197 * @phba: Pointer to HBA context object.
7199 * This function checks if any mailbox completions are present on the mailbox
7203 lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
)
7207 struct lpfc_queue
*mcq
;
7208 struct lpfc_mcqe
*mcqe
;
7209 bool pending_completions
= false;
7211 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
7214 /* Check for completions on mailbox completion queue */
7216 mcq
= phba
->sli4_hba
.mbx_cq
;
7217 idx
= mcq
->hba_index
;
7218 while (bf_get_le32(lpfc_cqe_valid
, mcq
->qe
[idx
].cqe
)) {
7219 mcqe
= (struct lpfc_mcqe
*)mcq
->qe
[idx
].cqe
;
7220 if (bf_get_le32(lpfc_trailer_completed
, mcqe
) &&
7221 (!bf_get_le32(lpfc_trailer_async
, mcqe
))) {
7222 pending_completions
= true;
7225 idx
= (idx
+ 1) % mcq
->entry_count
;
7226 if (mcq
->hba_index
== idx
)
7229 return pending_completions
;
7234 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
7236 * @phba: Pointer to HBA context object.
7238 * For sli4, it is possible to miss an interrupt. As such mbox completions
7239 * maybe missed causing erroneous mailbox timeouts to occur. This function
7240 * checks to see if mbox completions are on the mailbox completion queue
7241 * and will process all the completions associated with the eq for the
7242 * mailbox completion queue.
7245 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
)
7249 struct lpfc_queue
*fpeq
= NULL
;
7250 struct lpfc_eqe
*eqe
;
7253 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
7256 /* Find the eq associated with the mcq */
7258 if (phba
->sli4_hba
.hba_eq
)
7259 for (eqidx
= 0; eqidx
< phba
->io_channel_irqs
; eqidx
++)
7260 if (phba
->sli4_hba
.hba_eq
[eqidx
]->queue_id
==
7261 phba
->sli4_hba
.mbx_cq
->assoc_qid
) {
7262 fpeq
= phba
->sli4_hba
.hba_eq
[eqidx
];
7268 /* Turn off interrupts from this EQ */
7270 lpfc_sli4_eq_clr_intr(fpeq
);
7272 /* Check to see if a mbox completion is pending */
7274 mbox_pending
= lpfc_sli4_mbox_completions_pending(phba
);
7277 * If a mbox completion is pending, process all the events on EQ
7278 * associated with the mbox completion queue (this could include
7279 * mailbox commands, async events, els commands, receive queue data
7284 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
7285 lpfc_sli4_hba_handle_eqe(phba
, eqe
, eqidx
);
7286 fpeq
->EQ_processed
++;
7289 /* Always clear and re-arm the EQ */
7291 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
7293 return mbox_pending
;
7298 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
7299 * @phba: Pointer to HBA context object.
7301 * This function is called from worker thread when a mailbox command times out.
7302 * The caller is not required to hold any locks. This function will reset the
7303 * HBA and recover all the pending commands.
7306 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
7308 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
7309 MAILBOX_t
*mb
= NULL
;
7311 struct lpfc_sli
*psli
= &phba
->sli
;
7313 /* If the mailbox completed, process the completion and return */
7314 if (lpfc_sli4_process_missed_mbox_completions(phba
))
7319 /* Check the pmbox pointer first. There is a race condition
7320 * between the mbox timeout handler getting executed in the
7321 * worklist and the mailbox actually completing. When this
7322 * race condition occurs, the mbox_active will be NULL.
7324 spin_lock_irq(&phba
->hbalock
);
7325 if (pmbox
== NULL
) {
7326 lpfc_printf_log(phba
, KERN_WARNING
,
7328 "0353 Active Mailbox cleared - mailbox timeout "
7330 spin_unlock_irq(&phba
->hbalock
);
7334 /* Mbox cmd <mbxCommand> timeout */
7335 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7336 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
7338 phba
->pport
->port_state
,
7340 phba
->sli
.mbox_active
);
7341 spin_unlock_irq(&phba
->hbalock
);
7343 /* Setting state unknown so lpfc_sli_abort_iocb_ring
7344 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
7345 * it to fail all outstanding SCSI IO.
7347 spin_lock_irq(&phba
->pport
->work_port_lock
);
7348 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
7349 spin_unlock_irq(&phba
->pport
->work_port_lock
);
7350 spin_lock_irq(&phba
->hbalock
);
7351 phba
->link_state
= LPFC_LINK_UNKNOWN
;
7352 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
7353 spin_unlock_irq(&phba
->hbalock
);
7355 lpfc_sli_abort_fcp_rings(phba
);
7357 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7358 "0345 Resetting board due to mailbox timeout\n");
7360 /* Reset the HBA device */
7361 lpfc_reset_hba(phba
);
7365 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
7366 * @phba: Pointer to HBA context object.
7367 * @pmbox: Pointer to mailbox object.
7368 * @flag: Flag indicating how the mailbox need to be processed.
7370 * This function is called by discovery code and HBA management code
7371 * to submit a mailbox command to firmware with SLI-3 interface spec. This
7372 * function gets the hbalock to protect the data structures.
7373 * The mailbox command can be submitted in polling mode, in which case
7374 * this function will wait in a polling loop for the completion of the
7376 * If the mailbox is submitted in no_wait mode (not polling) the
7377 * function will submit the command and returns immediately without waiting
7378 * for the mailbox completion. The no_wait is supported only when HBA
7379 * is in SLI2/SLI3 mode - interrupts are enabled.
7380 * The SLI interface allows only one mailbox pending at a time. If the
7381 * mailbox is issued in polling mode and there is already a mailbox
7382 * pending, then the function will return an error. If the mailbox is issued
7383 * in NO_WAIT mode and there is a mailbox pending already, the function
7384 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
7385 * The sli layer owns the mailbox object until the completion of mailbox
7386 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
7387 * return codes the caller owns the mailbox command after the return of
7391 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
7395 struct lpfc_sli
*psli
= &phba
->sli
;
7396 uint32_t status
, evtctr
;
7397 uint32_t ha_copy
, hc_copy
;
7399 unsigned long timeout
;
7400 unsigned long drvr_flag
= 0;
7401 uint32_t word0
, ldata
;
7402 void __iomem
*to_slim
;
7403 int processing_queue
= 0;
7405 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7407 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7408 /* processing mbox queue from intr_handler */
7409 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7410 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7413 processing_queue
= 1;
7414 pmbox
= lpfc_mbox_get(phba
);
7416 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7421 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
7422 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
7424 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7425 lpfc_printf_log(phba
, KERN_ERR
,
7426 LOG_MBOX
| LOG_VPORT
,
7427 "1806 Mbox x%x failed. No vport\n",
7428 pmbox
->u
.mb
.mbxCommand
);
7430 goto out_not_finished
;
7434 /* If the PCI channel is in offline state, do not post mbox. */
7435 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7436 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7437 goto out_not_finished
;
7440 /* If HBA has a deferred error attention, fail the iocb. */
7441 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7442 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7443 goto out_not_finished
;
7449 status
= MBX_SUCCESS
;
7451 if (phba
->link_state
== LPFC_HBA_ERROR
) {
7452 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7454 /* Mbox command <mbxCommand> cannot issue */
7455 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7456 "(%d):0311 Mailbox command x%x cannot "
7457 "issue Data: x%x x%x\n",
7458 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7459 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7460 goto out_not_finished
;
7463 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
7464 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
7465 !(hc_copy
& HC_MBINT_ENA
)) {
7466 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7467 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7468 "(%d):2528 Mailbox command x%x cannot "
7469 "issue Data: x%x x%x\n",
7470 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7471 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7472 goto out_not_finished
;
7476 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7477 /* Polling for a mbox command when another one is already active
7478 * is not allowed in SLI. Also, the driver must have established
7479 * SLI2 mode to queue and process multiple mbox commands.
7482 if (flag
& MBX_POLL
) {
7483 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7485 /* Mbox command <mbxCommand> cannot issue */
7486 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7487 "(%d):2529 Mailbox command x%x "
7488 "cannot issue Data: x%x x%x\n",
7489 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7490 pmbox
->u
.mb
.mbxCommand
,
7491 psli
->sli_flag
, flag
);
7492 goto out_not_finished
;
7495 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
7496 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7497 /* Mbox command <mbxCommand> cannot issue */
7498 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7499 "(%d):2530 Mailbox command x%x "
7500 "cannot issue Data: x%x x%x\n",
7501 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7502 pmbox
->u
.mb
.mbxCommand
,
7503 psli
->sli_flag
, flag
);
7504 goto out_not_finished
;
7507 /* Another mailbox command is still being processed, queue this
7508 * command to be processed later.
7510 lpfc_mbox_put(phba
, pmbox
);
7512 /* Mbox cmd issue - BUSY */
7513 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7514 "(%d):0308 Mbox cmd issue - BUSY Data: "
7515 "x%x x%x x%x x%x\n",
7516 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
7518 phba
->pport
? phba
->pport
->port_state
: 0xff,
7519 psli
->sli_flag
, flag
);
7521 psli
->slistat
.mbox_busy
++;
7522 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7525 lpfc_debugfs_disc_trc(pmbox
->vport
,
7526 LPFC_DISC_TRC_MBOX_VPORT
,
7527 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
7528 (uint32_t)mbx
->mbxCommand
,
7529 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7532 lpfc_debugfs_disc_trc(phba
->pport
,
7534 "MBOX Bsy: cmd:x%x mb:x%x x%x",
7535 (uint32_t)mbx
->mbxCommand
,
7536 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7542 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7544 /* If we are not polling, we MUST be in SLI2 mode */
7545 if (flag
!= MBX_POLL
) {
7546 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
7547 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
7548 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7549 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7550 /* Mbox command <mbxCommand> cannot issue */
7551 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7552 "(%d):2531 Mailbox command x%x "
7553 "cannot issue Data: x%x x%x\n",
7554 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7555 pmbox
->u
.mb
.mbxCommand
,
7556 psli
->sli_flag
, flag
);
7557 goto out_not_finished
;
7559 /* timeout active mbox command */
7560 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7562 mod_timer(&psli
->mbox_tmo
, jiffies
+ timeout
);
7565 /* Mailbox cmd <cmd> issue */
7566 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7567 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
7569 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7571 phba
->pport
? phba
->pport
->port_state
: 0xff,
7572 psli
->sli_flag
, flag
);
7574 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
7576 lpfc_debugfs_disc_trc(pmbox
->vport
,
7577 LPFC_DISC_TRC_MBOX_VPORT
,
7578 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7579 (uint32_t)mbx
->mbxCommand
,
7580 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7583 lpfc_debugfs_disc_trc(phba
->pport
,
7585 "MBOX Send: cmd:x%x mb:x%x x%x",
7586 (uint32_t)mbx
->mbxCommand
,
7587 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7591 psli
->slistat
.mbox_cmd
++;
7592 evtctr
= psli
->slistat
.mbox_event
;
7594 /* next set own bit for the adapter and copy over command word */
7595 mbx
->mbxOwner
= OWN_CHIP
;
7597 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7598 /* Populate mbox extension offset word. */
7599 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
7600 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7601 = (uint8_t *)phba
->mbox_ext
7602 - (uint8_t *)phba
->mbox
;
7605 /* Copy the mailbox extension data */
7606 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7607 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
7608 (uint8_t *)phba
->mbox_ext
,
7609 pmbox
->in_ext_byte_len
);
7611 /* Copy command data to host SLIM area */
7612 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7614 /* Populate mbox extension offset word. */
7615 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
7616 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7617 = MAILBOX_HBA_EXT_OFFSET
;
7619 /* Copy the mailbox extension data */
7620 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
)
7621 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
7622 MAILBOX_HBA_EXT_OFFSET
,
7623 pmbox
->context2
, pmbox
->in_ext_byte_len
);
7625 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
)
7626 /* copy command data into host mbox for cmpl */
7627 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
,
7630 /* First copy mbox command data to HBA SLIM, skip past first
7632 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
7633 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
7634 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
7636 /* Next copy over first word, with mbxOwner set */
7637 ldata
= *((uint32_t *)mbx
);
7638 to_slim
= phba
->MBslimaddr
;
7639 writel(ldata
, to_slim
);
7640 readl(to_slim
); /* flush */
7642 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
)
7643 /* switch over to host mailbox */
7644 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
7651 /* Set up reference to mailbox command */
7652 psli
->mbox_active
= pmbox
;
7653 /* Interrupt board to do it */
7654 writel(CA_MBATT
, phba
->CAregaddr
);
7655 readl(phba
->CAregaddr
); /* flush */
7656 /* Don't wait for it to finish, just return */
7660 /* Set up null reference to mailbox command */
7661 psli
->mbox_active
= NULL
;
7662 /* Interrupt board to do it */
7663 writel(CA_MBATT
, phba
->CAregaddr
);
7664 readl(phba
->CAregaddr
); /* flush */
7666 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7667 /* First read mbox status word */
7668 word0
= *((uint32_t *)phba
->mbox
);
7669 word0
= le32_to_cpu(word0
);
7671 /* First read mbox status word */
7672 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
7673 spin_unlock_irqrestore(&phba
->hbalock
,
7675 goto out_not_finished
;
7679 /* Read the HBA Host Attention Register */
7680 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7681 spin_unlock_irqrestore(&phba
->hbalock
,
7683 goto out_not_finished
;
7685 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7688 /* Wait for command to complete */
7689 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
7690 (!(ha_copy
& HA_MBATT
) &&
7691 (phba
->link_state
> LPFC_WARM_START
))) {
7692 if (time_after(jiffies
, timeout
)) {
7693 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7694 spin_unlock_irqrestore(&phba
->hbalock
,
7696 goto out_not_finished
;
7699 /* Check if we took a mbox interrupt while we were
7701 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
7702 && (evtctr
!= psli
->slistat
.mbox_event
))
7706 spin_unlock_irqrestore(&phba
->hbalock
,
7709 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7712 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7713 /* First copy command data */
7714 word0
= *((uint32_t *)phba
->mbox
);
7715 word0
= le32_to_cpu(word0
);
7716 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7719 /* Check real SLIM for any errors */
7720 slimword0
= readl(phba
->MBslimaddr
);
7721 slimmb
= (MAILBOX_t
*) & slimword0
;
7722 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
7723 && slimmb
->mbxStatus
) {
7730 /* First copy command data */
7731 word0
= readl(phba
->MBslimaddr
);
7733 /* Read the HBA Host Attention Register */
7734 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7735 spin_unlock_irqrestore(&phba
->hbalock
,
7737 goto out_not_finished
;
7741 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7742 /* copy results back to user */
7743 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
,
7745 /* Copy the mailbox extension data */
7746 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7747 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7749 pmbox
->out_ext_byte_len
);
7752 /* First copy command data */
7753 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
7755 /* Copy the mailbox extension data */
7756 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7757 lpfc_memcpy_from_slim(pmbox
->context2
,
7759 MAILBOX_HBA_EXT_OFFSET
,
7760 pmbox
->out_ext_byte_len
);
7764 writel(HA_MBATT
, phba
->HAregaddr
);
7765 readl(phba
->HAregaddr
); /* flush */
7767 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7768 status
= mbx
->mbxStatus
;
7771 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7775 if (processing_queue
) {
7776 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7777 lpfc_mbox_cmpl_put(phba
, pmbox
);
7779 return MBX_NOT_FINISHED
;
7783 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7784 * @phba: Pointer to HBA context object.
7786 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7787 * the driver internal pending mailbox queue. It will then try to wait out the
7788 * possible outstanding mailbox command before return.
7791 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7792 * the outstanding mailbox command timed out.
7795 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7797 struct lpfc_sli
*psli
= &phba
->sli
;
7799 unsigned long timeout
= 0;
7801 /* Mark the asynchronous mailbox command posting as blocked */
7802 spin_lock_irq(&phba
->hbalock
);
7803 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7804 /* Determine how long we might wait for the active mailbox
7805 * command to be gracefully completed by firmware.
7807 if (phba
->sli
.mbox_active
)
7808 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7809 phba
->sli
.mbox_active
) *
7811 spin_unlock_irq(&phba
->hbalock
);
7813 /* Make sure the mailbox is really active */
7815 lpfc_sli4_process_missed_mbox_completions(phba
);
7817 /* Wait for the outstnading mailbox command to complete */
7818 while (phba
->sli
.mbox_active
) {
7819 /* Check active mailbox complete status every 2ms */
7821 if (time_after(jiffies
, timeout
)) {
7822 /* Timeout, marked the outstanding cmd not complete */
7828 /* Can not cleanly block async mailbox command, fails it */
7830 spin_lock_irq(&phba
->hbalock
);
7831 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7832 spin_unlock_irq(&phba
->hbalock
);
7838 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7839 * @phba: Pointer to HBA context object.
7841 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7842 * commands from the driver internal pending mailbox queue. It makes sure
7843 * that there is no outstanding mailbox command before resuming posting
7844 * asynchronous mailbox commands. If, for any reason, there is outstanding
7845 * mailbox command, it will try to wait it out before resuming asynchronous
7846 * mailbox command posting.
7849 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7851 struct lpfc_sli
*psli
= &phba
->sli
;
7853 spin_lock_irq(&phba
->hbalock
);
7854 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7855 /* Asynchronous mailbox posting is not blocked, do nothing */
7856 spin_unlock_irq(&phba
->hbalock
);
7860 /* Outstanding synchronous mailbox command is guaranteed to be done,
7861 * successful or timeout, after timing-out the outstanding mailbox
7862 * command shall always be removed, so just unblock posting async
7863 * mailbox command and resume
7865 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7866 spin_unlock_irq(&phba
->hbalock
);
7868 /* wake up worker thread to post asynchronlous mailbox command */
7869 lpfc_worker_wake_up(phba
);
7873 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7874 * @phba: Pointer to HBA context object.
7875 * @mboxq: Pointer to mailbox object.
7877 * The function waits for the bootstrap mailbox register ready bit from
7878 * port for twice the regular mailbox command timeout value.
7880 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7881 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7884 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7887 unsigned long timeout
;
7888 struct lpfc_register bmbx_reg
;
7890 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7894 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7895 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7899 if (time_after(jiffies
, timeout
))
7900 return MBXERR_ERROR
;
7901 } while (!db_ready
);
7907 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7908 * @phba: Pointer to HBA context object.
7909 * @mboxq: Pointer to mailbox object.
7911 * The function posts a mailbox to the port. The mailbox is expected
7912 * to be comletely filled in and ready for the port to operate on it.
7913 * This routine executes a synchronous completion operation on the
7914 * mailbox by polling for its completion.
7916 * The caller must not be holding any locks when calling this routine.
7919 * MBX_SUCCESS - mailbox posted successfully
7920 * Any of the MBX error values.
7923 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7925 int rc
= MBX_SUCCESS
;
7926 unsigned long iflag
;
7927 uint32_t mcqe_status
;
7929 struct lpfc_sli
*psli
= &phba
->sli
;
7930 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7931 struct lpfc_bmbx_create
*mbox_rgn
;
7932 struct dma_address
*dma_address
;
7935 * Only one mailbox can be active to the bootstrap mailbox region
7936 * at a time and there is no queueing provided.
7938 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7939 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7940 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7941 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7942 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7943 "cannot issue Data: x%x x%x\n",
7944 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7945 mboxq
->u
.mb
.mbxCommand
,
7946 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7947 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7948 psli
->sli_flag
, MBX_POLL
);
7949 return MBXERR_ERROR
;
7951 /* The server grabs the token and owns it until release */
7952 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7953 phba
->sli
.mbox_active
= mboxq
;
7954 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7956 /* wait for bootstrap mbox register for readyness */
7957 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7962 * Initialize the bootstrap memory region to avoid stale data areas
7963 * in the mailbox post. Then copy the caller's mailbox contents to
7964 * the bmbx mailbox region.
7966 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7967 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7968 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7969 sizeof(struct lpfc_mqe
));
7971 /* Post the high mailbox dma address to the port and wait for ready. */
7972 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7973 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7975 /* wait for bootstrap mbox register for hi-address write done */
7976 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7980 /* Post the low mailbox dma address to the port. */
7981 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7983 /* wait for bootstrap mbox register for low address write done */
7984 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7989 * Read the CQ to ensure the mailbox has completed.
7990 * If so, update the mailbox status so that the upper layers
7991 * can complete the request normally.
7993 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7994 sizeof(struct lpfc_mqe
));
7995 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7996 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7997 sizeof(struct lpfc_mcqe
));
7998 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
8000 * When the CQE status indicates a failure and the mailbox status
8001 * indicates success then copy the CQE status into the mailbox status
8002 * (and prefix it with x4000).
8004 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
8005 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
8006 bf_set(lpfc_mqe_status
, mb
,
8007 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
8010 lpfc_sli4_swap_str(phba
, mboxq
);
8012 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8013 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
8014 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
8015 " x%x x%x CQ: x%x x%x x%x x%x\n",
8016 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
8017 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8018 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8019 bf_get(lpfc_mqe_status
, mb
),
8020 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
8021 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
8022 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
8023 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
8024 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
8025 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
8026 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
8027 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
8028 mboxq
->mcqe
.trailer
);
8030 /* We are holding the token, no needed for lock when release */
8031 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8032 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8033 phba
->sli
.mbox_active
= NULL
;
8034 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8039 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
8040 * @phba: Pointer to HBA context object.
8041 * @pmbox: Pointer to mailbox object.
8042 * @flag: Flag indicating how the mailbox need to be processed.
8044 * This function is called by discovery code and HBA management code to submit
8045 * a mailbox command to firmware with SLI-4 interface spec.
8047 * Return codes the caller owns the mailbox command after the return of the
8051 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
8054 struct lpfc_sli
*psli
= &phba
->sli
;
8055 unsigned long iflags
;
8058 /* dump from issue mailbox command if setup */
8059 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
8061 rc
= lpfc_mbox_dev_check(phba
);
8063 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8064 "(%d):2544 Mailbox command x%x (x%x/x%x) "
8065 "cannot issue Data: x%x x%x\n",
8066 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8067 mboxq
->u
.mb
.mbxCommand
,
8068 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8069 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8070 psli
->sli_flag
, flag
);
8071 goto out_not_finished
;
8074 /* Detect polling mode and jump to a handler */
8075 if (!phba
->sli4_hba
.intr_enable
) {
8076 if (flag
== MBX_POLL
)
8077 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
8080 if (rc
!= MBX_SUCCESS
)
8081 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
8082 "(%d):2541 Mailbox command x%x "
8083 "(x%x/x%x) failure: "
8084 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8086 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8087 mboxq
->u
.mb
.mbxCommand
,
8088 lpfc_sli_config_mbox_subsys_get(phba
,
8090 lpfc_sli_config_mbox_opcode_get(phba
,
8092 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
8093 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
8094 bf_get(lpfc_mcqe_ext_status
,
8096 psli
->sli_flag
, flag
);
8098 } else if (flag
== MBX_POLL
) {
8099 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
8100 "(%d):2542 Try to issue mailbox command "
8101 "x%x (x%x/x%x) synchronously ahead of async"
8102 "mailbox command queue: x%x x%x\n",
8103 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8104 mboxq
->u
.mb
.mbxCommand
,
8105 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8106 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8107 psli
->sli_flag
, flag
);
8108 /* Try to block the asynchronous mailbox posting */
8109 rc
= lpfc_sli4_async_mbox_block(phba
);
8111 /* Successfully blocked, now issue sync mbox cmd */
8112 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
8113 if (rc
!= MBX_SUCCESS
)
8114 lpfc_printf_log(phba
, KERN_WARNING
,
8116 "(%d):2597 Sync Mailbox command "
8117 "x%x (x%x/x%x) failure: "
8118 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8120 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8121 mboxq
->u
.mb
.mbxCommand
,
8122 lpfc_sli_config_mbox_subsys_get(phba
,
8124 lpfc_sli_config_mbox_opcode_get(phba
,
8126 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
8127 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
8128 bf_get(lpfc_mcqe_ext_status
,
8130 psli
->sli_flag
, flag
);
8131 /* Unblock the async mailbox posting afterward */
8132 lpfc_sli4_async_mbox_unblock(phba
);
8137 /* Now, interrupt mode asynchrous mailbox command */
8138 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
8140 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8141 "(%d):2543 Mailbox command x%x (x%x/x%x) "
8142 "cannot issue Data: x%x x%x\n",
8143 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8144 mboxq
->u
.mb
.mbxCommand
,
8145 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8146 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8147 psli
->sli_flag
, flag
);
8148 goto out_not_finished
;
8151 /* Put the mailbox command to the driver internal FIFO */
8152 psli
->slistat
.mbox_busy
++;
8153 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8154 lpfc_mbox_put(phba
, mboxq
);
8155 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8156 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8157 "(%d):0354 Mbox cmd issue - Enqueue Data: "
8158 "x%x (x%x/x%x) x%x x%x x%x\n",
8159 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
8160 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
8161 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8162 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8163 phba
->pport
->port_state
,
8164 psli
->sli_flag
, MBX_NOWAIT
);
8165 /* Wake up worker thread to transport mailbox command from head */
8166 lpfc_worker_wake_up(phba
);
8171 return MBX_NOT_FINISHED
;
8175 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
8176 * @phba: Pointer to HBA context object.
8178 * This function is called by worker thread to send a mailbox command to
8179 * SLI4 HBA firmware.
8183 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
8185 struct lpfc_sli
*psli
= &phba
->sli
;
8186 LPFC_MBOXQ_t
*mboxq
;
8187 int rc
= MBX_SUCCESS
;
8188 unsigned long iflags
;
8189 struct lpfc_mqe
*mqe
;
8192 /* Check interrupt mode before post async mailbox command */
8193 if (unlikely(!phba
->sli4_hba
.intr_enable
))
8194 return MBX_NOT_FINISHED
;
8196 /* Check for mailbox command service token */
8197 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8198 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
8199 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8200 return MBX_NOT_FINISHED
;
8202 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8203 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8204 return MBX_NOT_FINISHED
;
8206 if (unlikely(phba
->sli
.mbox_active
)) {
8207 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8208 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8209 "0384 There is pending active mailbox cmd\n");
8210 return MBX_NOT_FINISHED
;
8212 /* Take the mailbox command service token */
8213 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
8215 /* Get the next mailbox command from head of queue */
8216 mboxq
= lpfc_mbox_get(phba
);
8218 /* If no more mailbox command waiting for post, we're done */
8220 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8221 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8224 phba
->sli
.mbox_active
= mboxq
;
8225 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8227 /* Check device readiness for posting mailbox command */
8228 rc
= lpfc_mbox_dev_check(phba
);
8230 /* Driver clean routine will clean up pending mailbox */
8231 goto out_not_finished
;
8233 /* Prepare the mbox command to be posted */
8234 mqe
= &mboxq
->u
.mqe
;
8235 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
8237 /* Start timer for the mbox_tmo and log some mailbox post messages */
8238 mod_timer(&psli
->mbox_tmo
, (jiffies
+
8239 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba
, mboxq
))));
8241 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8242 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
8244 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
8245 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8246 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8247 phba
->pport
->port_state
, psli
->sli_flag
);
8249 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
8251 lpfc_debugfs_disc_trc(mboxq
->vport
,
8252 LPFC_DISC_TRC_MBOX_VPORT
,
8253 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8254 mbx_cmnd
, mqe
->un
.mb_words
[0],
8255 mqe
->un
.mb_words
[1]);
8257 lpfc_debugfs_disc_trc(phba
->pport
,
8259 "MBOX Send: cmd:x%x mb:x%x x%x",
8260 mbx_cmnd
, mqe
->un
.mb_words
[0],
8261 mqe
->un
.mb_words
[1]);
8264 psli
->slistat
.mbox_cmd
++;
8266 /* Post the mailbox command to the port */
8267 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
8268 if (rc
!= MBX_SUCCESS
) {
8269 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8270 "(%d):2533 Mailbox command x%x (x%x/x%x) "
8271 "cannot issue Data: x%x x%x\n",
8272 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8273 mboxq
->u
.mb
.mbxCommand
,
8274 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8275 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8276 psli
->sli_flag
, MBX_NOWAIT
);
8277 goto out_not_finished
;
8283 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8284 if (phba
->sli
.mbox_active
) {
8285 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8286 __lpfc_mbox_cmpl_put(phba
, mboxq
);
8287 /* Release the token */
8288 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8289 phba
->sli
.mbox_active
= NULL
;
8291 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8293 return MBX_NOT_FINISHED
;
8297 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
8298 * @phba: Pointer to HBA context object.
8299 * @pmbox: Pointer to mailbox object.
8300 * @flag: Flag indicating how the mailbox need to be processed.
8302 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
8303 * the API jump table function pointer from the lpfc_hba struct.
8305 * Return codes the caller owns the mailbox command after the return of the
8309 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
8311 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
8315 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
8316 * @phba: The hba struct for which this call is being executed.
8317 * @dev_grp: The HBA PCI-Device group number.
8319 * This routine sets up the mbox interface API function jump table in @phba
8321 * Returns: 0 - success, -ENODEV - failure.
8324 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8328 case LPFC_PCI_DEV_LP
:
8329 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
8330 phba
->lpfc_sli_handle_slow_ring_event
=
8331 lpfc_sli_handle_slow_ring_event_s3
;
8332 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
8333 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
8334 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
8336 case LPFC_PCI_DEV_OC
:
8337 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
8338 phba
->lpfc_sli_handle_slow_ring_event
=
8339 lpfc_sli_handle_slow_ring_event_s4
;
8340 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
8341 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
8342 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
8345 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8346 "1420 Invalid HBA PCI-device group: 0x%x\n",
8355 * __lpfc_sli_ringtx_put - Add an iocb to the txq
8356 * @phba: Pointer to HBA context object.
8357 * @pring: Pointer to driver SLI ring object.
8358 * @piocb: Pointer to address of newly added command iocb.
8360 * This function is called with hbalock held to add a command
8361 * iocb to the txq when SLI layer cannot submit the command iocb
8365 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8366 struct lpfc_iocbq
*piocb
)
8368 lockdep_assert_held(&phba
->hbalock
);
8369 /* Insert the caller's iocb in the txq tail for later processing. */
8370 list_add_tail(&piocb
->list
, &pring
->txq
);
8374 * lpfc_sli_next_iocb - Get the next iocb in the txq
8375 * @phba: Pointer to HBA context object.
8376 * @pring: Pointer to driver SLI ring object.
8377 * @piocb: Pointer to address of newly added command iocb.
8379 * This function is called with hbalock held before a new
8380 * iocb is submitted to the firmware. This function checks
8381 * txq to flush the iocbs in txq to Firmware before
8382 * submitting new iocbs to the Firmware.
8383 * If there are iocbs in the txq which need to be submitted
8384 * to firmware, lpfc_sli_next_iocb returns the first element
8385 * of the txq after dequeuing it from txq.
8386 * If there is no iocb in the txq then the function will return
8387 * *piocb and *piocb is set to NULL. Caller needs to check
8388 * *piocb to find if there are more commands in the txq.
8390 static struct lpfc_iocbq
*
8391 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8392 struct lpfc_iocbq
**piocb
)
8394 struct lpfc_iocbq
* nextiocb
;
8396 lockdep_assert_held(&phba
->hbalock
);
8398 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
8408 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
8409 * @phba: Pointer to HBA context object.
8410 * @ring_number: SLI ring number to issue iocb on.
8411 * @piocb: Pointer to command iocb.
8412 * @flag: Flag indicating if this command can be put into txq.
8414 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
8415 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
8416 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
8417 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
8418 * this function allows only iocbs for posting buffers. This function finds
8419 * next available slot in the command ring and posts the command to the
8420 * available slot and writes the port attention register to request HBA start
8421 * processing new iocb. If there is no slot available in the ring and
8422 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
8423 * the function returns IOCB_BUSY.
8425 * This function is called with hbalock held. The function will return success
8426 * after it successfully submit the iocb to firmware or after adding to the
8430 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
8431 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8433 struct lpfc_iocbq
*nextiocb
;
8435 struct lpfc_sli_ring
*pring
= &phba
->sli
.sli3_ring
[ring_number
];
8437 lockdep_assert_held(&phba
->hbalock
);
8439 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
8440 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
8441 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
8442 lpfc_printf_log(phba
, KERN_ERR
,
8443 LOG_SLI
| LOG_VPORT
,
8444 "1807 IOCB x%x failed. No vport\n",
8445 piocb
->iocb
.ulpCommand
);
8451 /* If the PCI channel is in offline state, do not post iocbs. */
8452 if (unlikely(pci_channel_offline(phba
->pcidev
)))
8455 /* If HBA has a deferred error attention, fail the iocb. */
8456 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
8460 * We should never get an IOCB if we are in a < LINK_DOWN state
8462 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
8466 * Check to see if we are blocking IOCB processing because of a
8467 * outstanding event.
8469 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
8472 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
8474 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
8475 * can be issued if the link is not up.
8477 switch (piocb
->iocb
.ulpCommand
) {
8478 case CMD_GEN_REQUEST64_CR
:
8479 case CMD_GEN_REQUEST64_CX
:
8480 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
8481 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
8482 FC_RCTL_DD_UNSOL_CMD
) ||
8483 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
8484 MENLO_TRANSPORT_TYPE
))
8488 case CMD_QUE_RING_BUF_CN
:
8489 case CMD_QUE_RING_BUF64_CN
:
8491 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
8492 * completion, iocb_cmpl MUST be 0.
8494 if (piocb
->iocb_cmpl
)
8495 piocb
->iocb_cmpl
= NULL
;
8497 case CMD_CREATE_XRI_CR
:
8498 case CMD_CLOSE_XRI_CN
:
8499 case CMD_CLOSE_XRI_CX
:
8506 * For FCP commands, we must be in a state where we can process link
8509 } else if (unlikely(pring
->ringno
== LPFC_FCP_RING
&&
8510 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
8514 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
8515 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
8516 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
8519 lpfc_sli_update_ring(phba
, pring
);
8521 lpfc_sli_update_full_ring(phba
, pring
);
8524 return IOCB_SUCCESS
;
8529 pring
->stats
.iocb_cmd_delay
++;
8533 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8534 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
8535 return IOCB_SUCCESS
;
8542 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
8543 * @phba: Pointer to HBA context object.
8544 * @piocb: Pointer to command iocb.
8545 * @sglq: Pointer to the scatter gather queue object.
8547 * This routine converts the bpl or bde that is in the IOCB
8548 * to a sgl list for the sli4 hardware. The physical address
8549 * of the bpl/bde is converted back to a virtual address.
8550 * If the IOCB contains a BPL then the list of BDE's is
8551 * converted to sli4_sge's. If the IOCB contains a single
8552 * BDE then it is converted to a single sli_sge.
8553 * The IOCB is still in cpu endianess so the contents of
8554 * the bpl can be used without byte swapping.
8556 * Returns valid XRI = Success, NO_XRI = Failure.
8559 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
8560 struct lpfc_sglq
*sglq
)
8562 uint16_t xritag
= NO_XRI
;
8563 struct ulp_bde64
*bpl
= NULL
;
8564 struct ulp_bde64 bde
;
8565 struct sli4_sge
*sgl
= NULL
;
8566 struct lpfc_dmabuf
*dmabuf
;
8570 uint32_t offset
= 0; /* accumulated offset in the sg request list */
8571 int inbound
= 0; /* number of sg reply entries inbound from firmware */
8573 if (!piocbq
|| !sglq
)
8576 sgl
= (struct sli4_sge
*)sglq
->sgl
;
8577 icmd
= &piocbq
->iocb
;
8578 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
8579 return sglq
->sli4_xritag
;
8580 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8581 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
8582 sizeof(struct ulp_bde64
);
8583 /* The addrHigh and addrLow fields within the IOCB
8584 * have not been byteswapped yet so there is no
8585 * need to swap them back.
8587 if (piocbq
->context3
)
8588 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
8592 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
8596 for (i
= 0; i
< numBdes
; i
++) {
8597 /* Should already be byte swapped. */
8598 sgl
->addr_hi
= bpl
->addrHigh
;
8599 sgl
->addr_lo
= bpl
->addrLow
;
8601 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8602 if ((i
+1) == numBdes
)
8603 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8605 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
8606 /* swap the size field back to the cpu so we
8607 * can assign it to the sgl.
8609 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8610 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
8611 /* The offsets in the sgl need to be accumulated
8612 * separately for the request and reply lists.
8613 * The request is always first, the reply follows.
8615 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
8616 /* add up the reply sg entries */
8617 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
8619 /* first inbound? reset the offset */
8622 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
8623 bf_set(lpfc_sli4_sge_type
, sgl
,
8624 LPFC_SGE_TYPE_DATA
);
8625 offset
+= bde
.tus
.f
.bdeSize
;
8627 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8631 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
8632 /* The addrHigh and addrLow fields of the BDE have not
8633 * been byteswapped yet so they need to be swapped
8634 * before putting them in the sgl.
8637 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
8639 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
8640 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8641 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8642 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8644 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
8646 return sglq
->sli4_xritag
;
8650 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8651 * @phba: Pointer to HBA context object.
8652 * @piocb: Pointer to command iocb.
8653 * @wqe: Pointer to the work queue entry.
8655 * This routine converts the iocb command to its Work Queue Entry
8656 * equivalent. The wqe pointer should not have any fields set when
8657 * this routine is called because it will memcpy over them.
8658 * This routine does not set the CQ_ID or the WQEC bits in the
8661 * Returns: 0 = Success, IOCB_ERROR = Failure.
8664 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
8665 union lpfc_wqe
*wqe
)
8667 uint32_t xmit_len
= 0, total_len
= 0;
8671 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
8674 uint16_t abrt_iotag
;
8675 struct lpfc_iocbq
*abrtiocbq
;
8676 struct ulp_bde64
*bpl
= NULL
;
8677 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
8679 struct ulp_bde64 bde
;
8680 struct lpfc_nodelist
*ndlp
;
8684 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
8685 /* The fcp commands will set command type */
8686 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8687 command_type
= FCP_COMMAND
;
8688 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
8689 command_type
= ELS_COMMAND_FIP
;
8691 command_type
= ELS_COMMAND_NON_FIP
;
8693 if (phba
->fcp_embed_io
)
8694 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
8695 /* Some of the fields are in the right position already */
8696 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
8697 if (iocbq
->iocb
.ulpCommand
!= CMD_SEND_FRAME
) {
8698 /* The ct field has moved so reset */
8699 wqe
->generic
.wqe_com
.word7
= 0;
8700 wqe
->generic
.wqe_com
.word10
= 0;
8703 abort_tag
= (uint32_t) iocbq
->iotag
;
8704 xritag
= iocbq
->sli4_xritag
;
8705 /* words0-2 bpl convert bde */
8706 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8707 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8708 sizeof(struct ulp_bde64
);
8709 bpl
= (struct ulp_bde64
*)
8710 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
8714 /* Should already be byte swapped. */
8715 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
8716 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
8717 /* swap the size field back to the cpu so we
8718 * can assign it to the sgl.
8720 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8721 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
8723 for (i
= 0; i
< numBdes
; i
++) {
8724 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8725 total_len
+= bde
.tus
.f
.bdeSize
;
8728 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8730 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8731 cmnd
= iocbq
->iocb
.ulpCommand
;
8733 switch (iocbq
->iocb
.ulpCommand
) {
8734 case CMD_ELS_REQUEST64_CR
:
8735 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8736 ndlp
= iocbq
->context_un
.ndlp
;
8738 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8739 if (!iocbq
->iocb
.ulpLe
) {
8740 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8741 "2007 Only Limited Edition cmd Format"
8742 " supported 0x%x\n",
8743 iocbq
->iocb
.ulpCommand
);
8747 wqe
->els_req
.payload_len
= xmit_len
;
8748 /* Els_reguest64 has a TMO */
8749 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8750 iocbq
->iocb
.ulpTimeout
);
8751 /* Need a VF for word 4 set the vf bit*/
8752 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
8753 /* And a VFID for word 12 */
8754 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
8755 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8756 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8757 iocbq
->iocb
.ulpContext
);
8758 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
8759 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
8760 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8761 if (command_type
== ELS_COMMAND_FIP
)
8762 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
8763 >> LPFC_FIP_ELS_ID_SHIFT
);
8764 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8765 iocbq
->context2
)->virt
);
8766 if_type
= bf_get(lpfc_sli_intf_if_type
,
8767 &phba
->sli4_hba
.sli_intf
);
8768 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8769 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
8770 *pcmd
== ELS_CMD_SCR
||
8771 *pcmd
== ELS_CMD_FDISC
||
8772 *pcmd
== ELS_CMD_LOGO
||
8773 *pcmd
== ELS_CMD_PLOGI
)) {
8774 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8775 bf_set(els_req64_sid
, &wqe
->els_req
,
8776 iocbq
->vport
->fc_myDID
);
8777 if ((*pcmd
== ELS_CMD_FLOGI
) &&
8778 !(phba
->fc_topology
==
8779 LPFC_TOPOLOGY_LOOP
))
8780 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
8781 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8782 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8783 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8784 } else if (pcmd
&& iocbq
->context1
) {
8785 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
8786 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8787 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8790 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
8791 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8792 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
8793 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
8794 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8795 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
8796 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8797 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
8798 wqe
->els_req
.max_response_payload_len
= total_len
- xmit_len
;
8800 case CMD_XMIT_SEQUENCE64_CX
:
8801 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
8802 iocbq
->iocb
.un
.ulpWord
[3]);
8803 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
8804 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8805 /* The entire sequence is transmitted for this IOCB */
8806 xmit_len
= total_len
;
8807 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8808 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8809 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8810 case CMD_XMIT_SEQUENCE64_CR
:
8811 /* word3 iocb=io_tag32 wqe=reserved */
8812 wqe
->xmit_sequence
.rsvd3
= 0;
8813 /* word4 relative_offset memcpy */
8814 /* word5 r_ctl/df_ctl memcpy */
8815 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8816 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8817 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8818 LPFC_WQE_IOD_WRITE
);
8819 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8820 LPFC_WQE_LENLOC_WORD12
);
8821 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8822 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8823 command_type
= OTHER_COMMAND
;
8825 case CMD_XMIT_BCAST64_CN
:
8826 /* word3 iocb=iotag32 wqe=seq_payload_len */
8827 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8828 /* word4 iocb=rsvd wqe=rsvd */
8829 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8830 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8831 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8832 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8833 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8834 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8835 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8836 LPFC_WQE_LENLOC_WORD3
);
8837 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8839 case CMD_FCP_IWRITE64_CR
:
8840 command_type
= FCP_COMMAND_DATA_OUT
;
8841 /* word3 iocb=iotag wqe=payload_offset_len */
8842 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8843 bf_set(payload_offset_len
, &wqe
->fcp_iwrite
,
8844 xmit_len
+ sizeof(struct fcp_rsp
));
8845 bf_set(cmd_buff_len
, &wqe
->fcp_iwrite
,
8847 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8848 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8849 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8850 iocbq
->iocb
.ulpFCP2Rcvy
);
8851 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8852 /* Always open the exchange */
8853 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8854 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8855 LPFC_WQE_LENLOC_WORD4
);
8856 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8857 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8858 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8859 bf_set(wqe_oas
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8860 bf_set(wqe_ccpe
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8861 if (iocbq
->priority
) {
8862 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8863 (iocbq
->priority
<< 1));
8865 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8866 (phba
->cfg_XLanePriority
<< 1));
8869 /* Note, word 10 is already initialized to 0 */
8871 if (phba
->fcp_embed_io
) {
8872 struct lpfc_scsi_buf
*lpfc_cmd
;
8873 struct sli4_sge
*sgl
;
8874 union lpfc_wqe128
*wqe128
;
8875 struct fcp_cmnd
*fcp_cmnd
;
8878 /* 128 byte wqe support here */
8879 wqe128
= (union lpfc_wqe128
*)wqe
;
8881 lpfc_cmd
= iocbq
->context1
;
8882 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8883 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8885 /* Word 0-2 - FCP_CMND */
8886 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8887 BUFF_TYPE_BDE_IMMED
;
8888 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8889 wqe128
->generic
.bde
.addrHigh
= 0;
8890 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8892 bf_set(wqe_wqes
, &wqe128
->fcp_iwrite
.wqe_com
, 1);
8894 /* Word 22-29 FCP CMND Payload */
8895 ptr
= &wqe128
->words
[22];
8896 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8899 case CMD_FCP_IREAD64_CR
:
8900 /* word3 iocb=iotag wqe=payload_offset_len */
8901 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8902 bf_set(payload_offset_len
, &wqe
->fcp_iread
,
8903 xmit_len
+ sizeof(struct fcp_rsp
));
8904 bf_set(cmd_buff_len
, &wqe
->fcp_iread
,
8906 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8907 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8908 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8909 iocbq
->iocb
.ulpFCP2Rcvy
);
8910 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8911 /* Always open the exchange */
8912 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8913 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8914 LPFC_WQE_LENLOC_WORD4
);
8915 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8916 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8917 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8918 bf_set(wqe_oas
, &wqe
->fcp_iread
.wqe_com
, 1);
8919 bf_set(wqe_ccpe
, &wqe
->fcp_iread
.wqe_com
, 1);
8920 if (iocbq
->priority
) {
8921 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8922 (iocbq
->priority
<< 1));
8924 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8925 (phba
->cfg_XLanePriority
<< 1));
8928 /* Note, word 10 is already initialized to 0 */
8930 if (phba
->fcp_embed_io
) {
8931 struct lpfc_scsi_buf
*lpfc_cmd
;
8932 struct sli4_sge
*sgl
;
8933 union lpfc_wqe128
*wqe128
;
8934 struct fcp_cmnd
*fcp_cmnd
;
8937 /* 128 byte wqe support here */
8938 wqe128
= (union lpfc_wqe128
*)wqe
;
8940 lpfc_cmd
= iocbq
->context1
;
8941 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8942 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8944 /* Word 0-2 - FCP_CMND */
8945 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8946 BUFF_TYPE_BDE_IMMED
;
8947 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8948 wqe128
->generic
.bde
.addrHigh
= 0;
8949 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8951 bf_set(wqe_wqes
, &wqe128
->fcp_iread
.wqe_com
, 1);
8953 /* Word 22-29 FCP CMND Payload */
8954 ptr
= &wqe128
->words
[22];
8955 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8958 case CMD_FCP_ICMND64_CR
:
8959 /* word3 iocb=iotag wqe=payload_offset_len */
8960 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8961 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
8962 xmit_len
+ sizeof(struct fcp_rsp
));
8963 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
,
8965 /* word3 iocb=IO_TAG wqe=reserved */
8966 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8967 /* Always open the exchange */
8968 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8969 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8970 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8971 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8972 LPFC_WQE_LENLOC_NONE
);
8973 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
8974 iocbq
->iocb
.ulpFCP2Rcvy
);
8975 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8976 bf_set(wqe_oas
, &wqe
->fcp_icmd
.wqe_com
, 1);
8977 bf_set(wqe_ccpe
, &wqe
->fcp_icmd
.wqe_com
, 1);
8978 if (iocbq
->priority
) {
8979 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8980 (iocbq
->priority
<< 1));
8982 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8983 (phba
->cfg_XLanePriority
<< 1));
8986 /* Note, word 10 is already initialized to 0 */
8988 if (phba
->fcp_embed_io
) {
8989 struct lpfc_scsi_buf
*lpfc_cmd
;
8990 struct sli4_sge
*sgl
;
8991 union lpfc_wqe128
*wqe128
;
8992 struct fcp_cmnd
*fcp_cmnd
;
8995 /* 128 byte wqe support here */
8996 wqe128
= (union lpfc_wqe128
*)wqe
;
8998 lpfc_cmd
= iocbq
->context1
;
8999 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
9000 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
9002 /* Word 0-2 - FCP_CMND */
9003 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
9004 BUFF_TYPE_BDE_IMMED
;
9005 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
9006 wqe128
->generic
.bde
.addrHigh
= 0;
9007 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
9009 bf_set(wqe_wqes
, &wqe128
->fcp_icmd
.wqe_com
, 1);
9011 /* Word 22-29 FCP CMND Payload */
9012 ptr
= &wqe128
->words
[22];
9013 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
9016 case CMD_GEN_REQUEST64_CR
:
9017 /* For this command calculate the xmit length of the
9021 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
9022 sizeof(struct ulp_bde64
);
9023 for (i
= 0; i
< numBdes
; i
++) {
9024 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
9025 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
9027 xmit_len
+= bde
.tus
.f
.bdeSize
;
9029 /* word3 iocb=IO_TAG wqe=request_payload_len */
9030 wqe
->gen_req
.request_payload_len
= xmit_len
;
9031 /* word4 iocb=parameter wqe=relative_offset memcpy */
9032 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
9033 /* word6 context tag copied in memcpy */
9034 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
9035 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
9036 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9037 "2015 Invalid CT %x command 0x%x\n",
9038 ct
, iocbq
->iocb
.ulpCommand
);
9041 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
9042 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
9043 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
9044 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
9045 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
9046 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
9047 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
9048 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
9049 wqe
->gen_req
.max_response_payload_len
= total_len
- xmit_len
;
9050 command_type
= OTHER_COMMAND
;
9052 case CMD_XMIT_ELS_RSP64_CX
:
9053 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
9054 /* words0-2 BDE memcpy */
9055 /* word3 iocb=iotag32 wqe=response_payload_len */
9056 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
9058 wqe
->xmit_els_rsp
.word4
= 0;
9059 /* word5 iocb=rsvd wge=did */
9060 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
9061 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
9063 if_type
= bf_get(lpfc_sli_intf_if_type
,
9064 &phba
->sli4_hba
.sli_intf
);
9065 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
9066 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
9067 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
9068 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
9069 iocbq
->vport
->fc_myDID
);
9070 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
9072 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
9076 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
9077 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9078 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
9079 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
9080 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
9081 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
9082 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
9083 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
9084 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9085 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
9086 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9087 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
9088 LPFC_WQE_LENLOC_WORD3
);
9089 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
9090 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
9091 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
9092 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
9093 iocbq
->context2
)->virt
);
9094 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
9095 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
9096 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
9097 iocbq
->vport
->fc_myDID
);
9098 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9099 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
9100 phba
->vpi_ids
[phba
->pport
->vpi
]);
9102 command_type
= OTHER_COMMAND
;
9104 case CMD_CLOSE_XRI_CN
:
9105 case CMD_ABORT_XRI_CN
:
9106 case CMD_ABORT_XRI_CX
:
9107 /* words 0-2 memcpy should be 0 rserved */
9108 /* port will send abts */
9109 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
9110 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
9111 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
9112 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
9116 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
9118 * The link is down, or the command was ELS_FIP
9119 * so the fw does not need to send abts
9122 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
9124 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
9125 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
9126 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
9127 wqe
->abort_cmd
.rsrvd5
= 0;
9128 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
9129 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9130 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
9132 * The abort handler will send us CMD_ABORT_XRI_CN or
9133 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
9135 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
9136 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
9137 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
9138 LPFC_WQE_LENLOC_NONE
);
9139 cmnd
= CMD_ABORT_XRI_CX
;
9140 command_type
= OTHER_COMMAND
;
9143 case CMD_XMIT_BLS_RSP64_CX
:
9144 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
9145 /* As BLS ABTS RSP WQE is very different from other WQEs,
9146 * we re-construct this WQE here based on information in
9147 * iocbq from scratch.
9149 memset(wqe
, 0, sizeof(union lpfc_wqe
));
9150 /* OX_ID is invariable to who sent ABTS to CT exchange */
9151 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
9152 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
9153 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
9154 LPFC_ABTS_UNSOL_INT
) {
9155 /* ABTS sent by initiator to CT exchange, the
9156 * RX_ID field will be filled with the newly
9157 * allocated responder XRI.
9159 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
9160 iocbq
->sli4_xritag
);
9162 /* ABTS sent by responder to CT exchange, the
9163 * RX_ID field will be filled with the responder
9166 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
9167 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
9169 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
9170 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
9173 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
9175 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
9176 iocbq
->iocb
.ulpContext
);
9177 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
9178 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
9179 phba
->vpi_ids
[phba
->pport
->vpi
]);
9180 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
9181 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
9182 LPFC_WQE_LENLOC_NONE
);
9183 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
9184 command_type
= OTHER_COMMAND
;
9185 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
9186 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
9187 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
9188 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
9189 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
9190 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
9191 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
9195 case CMD_SEND_FRAME
:
9196 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
9197 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
9199 case CMD_XRI_ABORTED_CX
:
9200 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
9201 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
9202 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
9203 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
9204 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
9206 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9207 "2014 Invalid command 0x%x\n",
9208 iocbq
->iocb
.ulpCommand
);
9213 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
9214 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
9215 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
9216 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
9217 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
9218 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
9219 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
9220 LPFC_IO_DIF_INSERT
);
9221 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
9222 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
9223 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
9224 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
9225 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
9226 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
9227 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
9232 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
9233 * @phba: Pointer to HBA context object.
9234 * @ring_number: SLI ring number to issue iocb on.
9235 * @piocb: Pointer to command iocb.
9236 * @flag: Flag indicating if this command can be put into txq.
9238 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
9239 * an iocb command to an HBA with SLI-4 interface spec.
9241 * This function is called with hbalock held. The function will return success
9242 * after it successfully submit the iocb to firmware or after adding to the
9246 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
9247 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9249 struct lpfc_sglq
*sglq
;
9250 union lpfc_wqe
*wqe
;
9251 union lpfc_wqe128 wqe128
;
9252 struct lpfc_queue
*wq
;
9253 struct lpfc_sli_ring
*pring
;
9256 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
9257 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
9258 if (!phba
->cfg_fof
|| (!(piocb
->iocb_flag
& LPFC_IO_OAS
)))
9259 wq
= phba
->sli4_hba
.fcp_wq
[piocb
->hba_wqidx
];
9261 wq
= phba
->sli4_hba
.oas_wq
;
9263 wq
= phba
->sli4_hba
.els_wq
;
9266 /* Get corresponding ring */
9270 * The WQE can be either 64 or 128 bytes,
9271 * so allocate space on the stack assuming the largest.
9273 wqe
= (union lpfc_wqe
*)&wqe128
;
9275 lockdep_assert_held(&phba
->hbalock
);
9277 if (piocb
->sli4_xritag
== NO_XRI
) {
9278 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
9279 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
9282 if (!list_empty(&pring
->txq
)) {
9283 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
9284 __lpfc_sli_ringtx_put(phba
,
9286 return IOCB_SUCCESS
;
9291 sglq
= __lpfc_sli_get_els_sglq(phba
, piocb
);
9293 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
9294 __lpfc_sli_ringtx_put(phba
,
9297 return IOCB_SUCCESS
;
9303 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
)
9304 /* These IO's already have an XRI and a mapped sgl. */
9308 * This is a continuation of a commandi,(CX) so this
9309 * sglq is on the active list
9311 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
9317 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
9318 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
9319 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
9323 if (lpfc_sli4_iocb2wqe(phba
, piocb
, wqe
))
9326 if (lpfc_sli4_wq_put(wq
, wqe
))
9328 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
9334 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
9336 * This routine wraps the actual lockless version for issusing IOCB function
9337 * pointer from the lpfc_hba struct.
9340 * IOCB_ERROR - Error
9341 * IOCB_SUCCESS - Success
9345 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9346 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9348 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9352 * lpfc_sli_api_table_setup - Set up sli api function jump table
9353 * @phba: The hba struct for which this call is being executed.
9354 * @dev_grp: The HBA PCI-Device group number.
9356 * This routine sets up the SLI interface API function jump table in @phba
9358 * Returns: 0 - success, -ENODEV - failure.
9361 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
9365 case LPFC_PCI_DEV_LP
:
9366 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
9367 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
9369 case LPFC_PCI_DEV_OC
:
9370 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
9371 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
9374 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9375 "1419 Invalid HBA PCI-device group: 0x%x\n",
9380 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
9385 * lpfc_sli4_calc_ring - Calculates which ring to use
9386 * @phba: Pointer to HBA context object.
9387 * @piocb: Pointer to command iocb.
9389 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
9390 * hba_wqidx, thus we need to calculate the corresponding ring.
9391 * Since ABORTS must go on the same WQ of the command they are
9392 * aborting, we use command's hba_wqidx.
9394 struct lpfc_sli_ring
*
9395 lpfc_sli4_calc_ring(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocb
)
9397 if (piocb
->iocb_flag
& (LPFC_IO_FCP
| LPFC_USE_FCPWQIDX
)) {
9398 if (!(phba
->cfg_fof
) ||
9399 (!(piocb
->iocb_flag
& LPFC_IO_FOF
))) {
9400 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
9403 * for abort iocb hba_wqidx should already
9404 * be setup based on what work queue we used.
9406 if (!(piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
9408 lpfc_sli4_scmd_to_wqidx_distr(phba
,
9410 piocb
->hba_wqidx
= piocb
->hba_wqidx
%
9411 phba
->cfg_fcp_io_channel
;
9413 return phba
->sli4_hba
.fcp_wq
[piocb
->hba_wqidx
]->pring
;
9415 if (unlikely(!phba
->sli4_hba
.oas_wq
))
9417 piocb
->hba_wqidx
= 0;
9418 return phba
->sli4_hba
.oas_wq
->pring
;
9421 if (unlikely(!phba
->sli4_hba
.els_wq
))
9423 piocb
->hba_wqidx
= 0;
9424 return phba
->sli4_hba
.els_wq
->pring
;
9429 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
9430 * @phba: Pointer to HBA context object.
9431 * @pring: Pointer to driver SLI ring object.
9432 * @piocb: Pointer to command iocb.
9433 * @flag: Flag indicating if this command can be put into txq.
9435 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
9436 * function. This function gets the hbalock and calls
9437 * __lpfc_sli_issue_iocb function and will return the error returned
9438 * by __lpfc_sli_issue_iocb function. This wrapper is used by
9439 * functions which do not hold hbalock.
9442 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9443 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9445 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
9446 struct lpfc_sli_ring
*pring
;
9447 struct lpfc_queue
*fpeq
;
9448 struct lpfc_eqe
*eqe
;
9449 unsigned long iflags
;
9452 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9453 pring
= lpfc_sli4_calc_ring(phba
, piocb
);
9454 if (unlikely(pring
== NULL
))
9457 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9458 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9459 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9461 if (lpfc_fcp_look_ahead
&& (piocb
->iocb_flag
& LPFC_IO_FCP
)) {
9462 idx
= piocb
->hba_wqidx
;
9463 hba_eq_hdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9465 if (atomic_dec_and_test(&hba_eq_hdl
->hba_eq_in_use
)) {
9467 /* Get associated EQ with this index */
9468 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
9470 /* Turn off interrupts from this EQ */
9471 lpfc_sli4_eq_clr_intr(fpeq
);
9474 * Process all the events on FCP EQ
9476 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9477 lpfc_sli4_hba_handle_eqe(phba
,
9479 fpeq
->EQ_processed
++;
9482 /* Always clear and re-arm the EQ */
9483 lpfc_sli4_eq_release(fpeq
,
9486 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
9489 /* For now, SLI2/3 will still use hbalock */
9490 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9491 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9492 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9498 * lpfc_extra_ring_setup - Extra ring setup function
9499 * @phba: Pointer to HBA context object.
9501 * This function is called while driver attaches with the
9502 * HBA to setup the extra ring. The extra ring is used
9503 * only when driver needs to support target mode functionality
9504 * or IP over FC functionalities.
9506 * This function is called with no lock held. SLI3 only.
9509 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
9511 struct lpfc_sli
*psli
;
9512 struct lpfc_sli_ring
*pring
;
9516 /* Adjust cmd/rsp ring iocb entries more evenly */
9518 /* Take some away from the FCP ring */
9519 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
9520 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9521 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9522 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9523 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9525 /* and give them to the extra ring */
9526 pring
= &psli
->sli3_ring
[LPFC_EXTRA_RING
];
9528 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9529 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9530 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9531 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9533 /* Setup default profile for this ring */
9534 pring
->iotag_max
= 4096;
9535 pring
->num_mask
= 1;
9536 pring
->prt
[0].profile
= 0; /* Mask 0 */
9537 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
9538 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
9539 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
9543 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
9544 * @phba: Pointer to HBA context object.
9545 * @iocbq: Pointer to iocb object.
9547 * The async_event handler calls this routine when it receives
9548 * an ASYNC_STATUS_CN event from the port. The port generates
9549 * this event when an Abort Sequence request to an rport fails
9550 * twice in succession. The abort could be originated by the
9551 * driver or by the port. The ABTS could have been for an ELS
9552 * or FCP IO. The port only generates this event when an ABTS
9553 * fails to complete after one retry.
9556 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
9557 struct lpfc_iocbq
*iocbq
)
9559 struct lpfc_nodelist
*ndlp
= NULL
;
9560 uint16_t rpi
= 0, vpi
= 0;
9561 struct lpfc_vport
*vport
= NULL
;
9563 /* The rpi in the ulpContext is vport-sensitive. */
9564 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
9565 rpi
= iocbq
->iocb
.ulpContext
;
9567 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9568 "3092 Port generated ABTS async event "
9569 "on vpi %d rpi %d status 0x%x\n",
9570 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
9572 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
9575 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
9576 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
9579 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
9580 lpfc_sli_abts_recover_port(vport
, ndlp
);
9584 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9585 "3095 Event Context not found, no "
9586 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
9587 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
9591 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
9592 * @phba: pointer to HBA context object.
9593 * @ndlp: nodelist pointer for the impacted rport.
9594 * @axri: pointer to the wcqe containing the failed exchange.
9596 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
9597 * port. The port generates this event when an abort exchange request to an
9598 * rport fails twice in succession with no reply. The abort could be originated
9599 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
9602 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
9603 struct lpfc_nodelist
*ndlp
,
9604 struct sli4_wcqe_xri_aborted
*axri
)
9606 struct lpfc_vport
*vport
;
9607 uint32_t ext_status
= 0;
9609 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
9610 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9611 "3115 Node Context not found, driver "
9612 "ignoring abts err event\n");
9616 vport
= ndlp
->vport
;
9617 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9618 "3116 Port generated FCP XRI ABORT event on "
9619 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
9620 ndlp
->vport
->vpi
, phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
],
9621 bf_get(lpfc_wcqe_xa_xri
, axri
),
9622 bf_get(lpfc_wcqe_xa_status
, axri
),
9626 * Catch the ABTS protocol failure case. Older OCe FW releases returned
9627 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
9628 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
9630 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
9631 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
9632 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
9633 lpfc_sli_abts_recover_port(vport
, ndlp
);
9637 * lpfc_sli_async_event_handler - ASYNC iocb handler function
9638 * @phba: Pointer to HBA context object.
9639 * @pring: Pointer to driver SLI ring object.
9640 * @iocbq: Pointer to iocb object.
9642 * This function is called by the slow ring event handler
9643 * function when there is an ASYNC event iocb in the ring.
9644 * This function is called with no lock held.
9645 * Currently this function handles only temperature related
9646 * ASYNC events. The function decodes the temperature sensor
9647 * event message and posts events for the management applications.
9650 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
9651 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
9655 struct temp_event temp_event_data
;
9656 struct Scsi_Host
*shost
;
9659 icmd
= &iocbq
->iocb
;
9660 evt_code
= icmd
->un
.asyncstat
.evt_code
;
9663 case ASYNC_TEMP_WARN
:
9664 case ASYNC_TEMP_SAFE
:
9665 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
9666 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
9667 if (evt_code
== ASYNC_TEMP_WARN
) {
9668 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
9669 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9670 "0347 Adapter is very hot, please take "
9671 "corrective action. temperature : %d Celsius\n",
9672 (uint32_t) icmd
->ulpContext
);
9674 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
9675 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9676 "0340 Adapter temperature is OK now. "
9677 "temperature : %d Celsius\n",
9678 (uint32_t) icmd
->ulpContext
);
9681 /* Send temperature change event to applications */
9682 shost
= lpfc_shost_from_vport(phba
->pport
);
9683 fc_host_post_vendor_event(shost
, fc_get_event_number(),
9684 sizeof(temp_event_data
), (char *) &temp_event_data
,
9687 case ASYNC_STATUS_CN
:
9688 lpfc_sli_abts_err_handler(phba
, iocbq
);
9691 iocb_w
= (uint32_t *) icmd
;
9692 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9693 "0346 Ring %d handler: unexpected ASYNC_STATUS"
9695 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9696 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9697 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9698 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
9699 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
9700 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
9701 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
9702 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
9703 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
9711 * lpfc_sli4_setup - SLI ring setup function
9712 * @phba: Pointer to HBA context object.
9714 * lpfc_sli_setup sets up rings of the SLI interface with
9715 * number of iocbs per ring and iotags. This function is
9716 * called while driver attach to the HBA and before the
9717 * interrupts are enabled. So there is no need for locking.
9719 * This function always returns 0.
9722 lpfc_sli4_setup(struct lpfc_hba
*phba
)
9724 struct lpfc_sli_ring
*pring
;
9726 pring
= phba
->sli4_hba
.els_wq
->pring
;
9727 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9728 pring
->prt
[0].profile
= 0; /* Mask 0 */
9729 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9730 pring
->prt
[0].type
= FC_TYPE_ELS
;
9731 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9732 lpfc_els_unsol_event
;
9733 pring
->prt
[1].profile
= 0; /* Mask 1 */
9734 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9735 pring
->prt
[1].type
= FC_TYPE_ELS
;
9736 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9737 lpfc_els_unsol_event
;
9738 pring
->prt
[2].profile
= 0; /* Mask 2 */
9739 /* NameServer Inquiry */
9740 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9742 pring
->prt
[2].type
= FC_TYPE_CT
;
9743 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9744 lpfc_ct_unsol_event
;
9745 pring
->prt
[3].profile
= 0; /* Mask 3 */
9746 /* NameServer response */
9747 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9749 pring
->prt
[3].type
= FC_TYPE_CT
;
9750 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9751 lpfc_ct_unsol_event
;
9756 * lpfc_sli_setup - SLI ring setup function
9757 * @phba: Pointer to HBA context object.
9759 * lpfc_sli_setup sets up rings of the SLI interface with
9760 * number of iocbs per ring and iotags. This function is
9761 * called while driver attach to the HBA and before the
9762 * interrupts are enabled. So there is no need for locking.
9764 * This function always returns 0. SLI3 only.
9767 lpfc_sli_setup(struct lpfc_hba
*phba
)
9769 int i
, totiocbsize
= 0;
9770 struct lpfc_sli
*psli
= &phba
->sli
;
9771 struct lpfc_sli_ring
*pring
;
9773 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
9776 psli
->iocbq_lookup
= NULL
;
9777 psli
->iocbq_lookup_len
= 0;
9778 psli
->last_iotag
= 0;
9780 for (i
= 0; i
< psli
->num_rings
; i
++) {
9781 pring
= &psli
->sli3_ring
[i
];
9783 case LPFC_FCP_RING
: /* ring 0 - FCP */
9784 /* numCiocb and numRiocb are used in config_port */
9785 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
9786 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
9787 pring
->sli
.sli3
.numCiocb
+=
9788 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9789 pring
->sli
.sli3
.numRiocb
+=
9790 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9791 pring
->sli
.sli3
.numCiocb
+=
9792 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9793 pring
->sli
.sli3
.numRiocb
+=
9794 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9795 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9796 SLI3_IOCB_CMD_SIZE
:
9798 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9799 SLI3_IOCB_RSP_SIZE
:
9801 pring
->iotag_ctr
= 0;
9803 (phba
->cfg_hba_queue_depth
* 2);
9804 pring
->fast_iotag
= pring
->iotag_max
;
9805 pring
->num_mask
= 0;
9807 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
9808 /* numCiocb and numRiocb are used in config_port */
9809 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
9810 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
9811 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9812 SLI3_IOCB_CMD_SIZE
:
9814 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9815 SLI3_IOCB_RSP_SIZE
:
9817 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
9818 pring
->num_mask
= 0;
9820 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
9821 /* numCiocb and numRiocb are used in config_port */
9822 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
9823 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
9824 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9825 SLI3_IOCB_CMD_SIZE
:
9827 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9828 SLI3_IOCB_RSP_SIZE
:
9830 pring
->fast_iotag
= 0;
9831 pring
->iotag_ctr
= 0;
9832 pring
->iotag_max
= 4096;
9833 pring
->lpfc_sli_rcv_async_status
=
9834 lpfc_sli_async_event_handler
;
9835 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9836 pring
->prt
[0].profile
= 0; /* Mask 0 */
9837 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9838 pring
->prt
[0].type
= FC_TYPE_ELS
;
9839 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9840 lpfc_els_unsol_event
;
9841 pring
->prt
[1].profile
= 0; /* Mask 1 */
9842 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9843 pring
->prt
[1].type
= FC_TYPE_ELS
;
9844 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9845 lpfc_els_unsol_event
;
9846 pring
->prt
[2].profile
= 0; /* Mask 2 */
9847 /* NameServer Inquiry */
9848 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9850 pring
->prt
[2].type
= FC_TYPE_CT
;
9851 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9852 lpfc_ct_unsol_event
;
9853 pring
->prt
[3].profile
= 0; /* Mask 3 */
9854 /* NameServer response */
9855 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9857 pring
->prt
[3].type
= FC_TYPE_CT
;
9858 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9859 lpfc_ct_unsol_event
;
9862 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
9863 pring
->sli
.sli3
.sizeCiocb
) +
9864 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
9866 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
9867 /* Too many cmd / rsp ring entries in SLI2 SLIM */
9868 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
9869 "SLI2 SLIM Data: x%x x%lx\n",
9870 phba
->brd_no
, totiocbsize
,
9871 (unsigned long) MAX_SLIM_IOCB_SIZE
);
9873 if (phba
->cfg_multi_ring_support
== 2)
9874 lpfc_extra_ring_setup(phba
);
9880 * lpfc_sli4_queue_init - Queue initialization function
9881 * @phba: Pointer to HBA context object.
9883 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
9884 * ring. This function also initializes ring indices of each ring.
9885 * This function is called during the initialization of the SLI
9886 * interface of an HBA.
9887 * This function is called with no lock held and always returns
9891 lpfc_sli4_queue_init(struct lpfc_hba
*phba
)
9893 struct lpfc_sli
*psli
;
9894 struct lpfc_sli_ring
*pring
;
9898 spin_lock_irq(&phba
->hbalock
);
9899 INIT_LIST_HEAD(&psli
->mboxq
);
9900 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9901 /* Initialize list headers for txq and txcmplq as double linked lists */
9902 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
9903 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
9905 pring
->ringno
= LPFC_FCP_RING
;
9906 INIT_LIST_HEAD(&pring
->txq
);
9907 INIT_LIST_HEAD(&pring
->txcmplq
);
9908 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9909 spin_lock_init(&pring
->ring_lock
);
9911 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
9912 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
9914 pring
->ringno
= LPFC_FCP_RING
;
9915 INIT_LIST_HEAD(&pring
->txq
);
9916 INIT_LIST_HEAD(&pring
->txcmplq
);
9917 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9918 spin_lock_init(&pring
->ring_lock
);
9920 pring
= phba
->sli4_hba
.els_wq
->pring
;
9922 pring
->ringno
= LPFC_ELS_RING
;
9923 INIT_LIST_HEAD(&pring
->txq
);
9924 INIT_LIST_HEAD(&pring
->txcmplq
);
9925 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9926 spin_lock_init(&pring
->ring_lock
);
9928 if (phba
->cfg_nvme_io_channel
) {
9929 pring
= phba
->sli4_hba
.nvmels_wq
->pring
;
9931 pring
->ringno
= LPFC_ELS_RING
;
9932 INIT_LIST_HEAD(&pring
->txq
);
9933 INIT_LIST_HEAD(&pring
->txcmplq
);
9934 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9935 spin_lock_init(&pring
->ring_lock
);
9938 if (phba
->cfg_fof
) {
9939 pring
= phba
->sli4_hba
.oas_wq
->pring
;
9941 pring
->ringno
= LPFC_FCP_RING
;
9942 INIT_LIST_HEAD(&pring
->txq
);
9943 INIT_LIST_HEAD(&pring
->txcmplq
);
9944 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9945 spin_lock_init(&pring
->ring_lock
);
9948 spin_unlock_irq(&phba
->hbalock
);
9952 * lpfc_sli_queue_init - Queue initialization function
9953 * @phba: Pointer to HBA context object.
9955 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
9956 * ring. This function also initializes ring indices of each ring.
9957 * This function is called during the initialization of the SLI
9958 * interface of an HBA.
9959 * This function is called with no lock held and always returns
9963 lpfc_sli_queue_init(struct lpfc_hba
*phba
)
9965 struct lpfc_sli
*psli
;
9966 struct lpfc_sli_ring
*pring
;
9970 spin_lock_irq(&phba
->hbalock
);
9971 INIT_LIST_HEAD(&psli
->mboxq
);
9972 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9973 /* Initialize list headers for txq and txcmplq as double linked lists */
9974 for (i
= 0; i
< psli
->num_rings
; i
++) {
9975 pring
= &psli
->sli3_ring
[i
];
9977 pring
->sli
.sli3
.next_cmdidx
= 0;
9978 pring
->sli
.sli3
.local_getidx
= 0;
9979 pring
->sli
.sli3
.cmdidx
= 0;
9980 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9981 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
9982 INIT_LIST_HEAD(&pring
->postbufq
);
9984 INIT_LIST_HEAD(&pring
->txq
);
9985 INIT_LIST_HEAD(&pring
->txcmplq
);
9986 spin_lock_init(&pring
->ring_lock
);
9988 spin_unlock_irq(&phba
->hbalock
);
9992 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9993 * @phba: Pointer to HBA context object.
9995 * This routine flushes the mailbox command subsystem. It will unconditionally
9996 * flush all the mailbox commands in the three possible stages in the mailbox
9997 * command sub-system: pending mailbox command queue; the outstanding mailbox
9998 * command; and completed mailbox command queue. It is caller's responsibility
9999 * to make sure that the driver is in the proper state to flush the mailbox
10000 * command sub-system. Namely, the posting of mailbox commands into the
10001 * pending mailbox command queue from the various clients must be stopped;
10002 * either the HBA is in a state that it will never works on the outstanding
10003 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
10004 * mailbox command has been completed.
10007 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
10009 LIST_HEAD(completions
);
10010 struct lpfc_sli
*psli
= &phba
->sli
;
10012 unsigned long iflag
;
10014 /* Flush all the mailbox commands in the mbox system */
10015 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10016 /* The pending mailbox command queue */
10017 list_splice_init(&phba
->sli
.mboxq
, &completions
);
10018 /* The outstanding active mailbox command */
10019 if (psli
->mbox_active
) {
10020 list_add_tail(&psli
->mbox_active
->list
, &completions
);
10021 psli
->mbox_active
= NULL
;
10022 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
10024 /* The completed mailbox command queue */
10025 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
10026 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10028 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
10029 while (!list_empty(&completions
)) {
10030 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
10031 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
10032 if (pmb
->mbox_cmpl
)
10033 pmb
->mbox_cmpl(phba
, pmb
);
10038 * lpfc_sli_host_down - Vport cleanup function
10039 * @vport: Pointer to virtual port object.
10041 * lpfc_sli_host_down is called to clean up the resources
10042 * associated with a vport before destroying virtual
10043 * port data structures.
10044 * This function does following operations:
10045 * - Free discovery resources associated with this virtual
10047 * - Free iocbs associated with this virtual port in
10049 * - Send abort for all iocb commands associated with this
10050 * vport in txcmplq.
10052 * This function is called with no lock held and always returns 1.
10055 lpfc_sli_host_down(struct lpfc_vport
*vport
)
10057 LIST_HEAD(completions
);
10058 struct lpfc_hba
*phba
= vport
->phba
;
10059 struct lpfc_sli
*psli
= &phba
->sli
;
10060 struct lpfc_queue
*qp
= NULL
;
10061 struct lpfc_sli_ring
*pring
;
10062 struct lpfc_iocbq
*iocb
, *next_iocb
;
10064 unsigned long flags
= 0;
10065 uint16_t prev_pring_flag
;
10067 lpfc_cleanup_discovery_resources(vport
);
10069 spin_lock_irqsave(&phba
->hbalock
, flags
);
10072 * Error everything on the txq since these iocbs
10073 * have not been given to the FW yet.
10074 * Also issue ABTS for everything on the txcmplq
10076 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10077 for (i
= 0; i
< psli
->num_rings
; i
++) {
10078 pring
= &psli
->sli3_ring
[i
];
10079 prev_pring_flag
= pring
->flag
;
10080 /* Only slow rings */
10081 if (pring
->ringno
== LPFC_ELS_RING
) {
10082 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10083 /* Set the lpfc data pending flag */
10084 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10086 list_for_each_entry_safe(iocb
, next_iocb
,
10087 &pring
->txq
, list
) {
10088 if (iocb
->vport
!= vport
)
10090 list_move_tail(&iocb
->list
, &completions
);
10092 list_for_each_entry_safe(iocb
, next_iocb
,
10093 &pring
->txcmplq
, list
) {
10094 if (iocb
->vport
!= vport
)
10096 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
10098 pring
->flag
= prev_pring_flag
;
10101 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10105 if (pring
== phba
->sli4_hba
.els_wq
->pring
) {
10106 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10107 /* Set the lpfc data pending flag */
10108 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10110 prev_pring_flag
= pring
->flag
;
10111 spin_lock_irq(&pring
->ring_lock
);
10112 list_for_each_entry_safe(iocb
, next_iocb
,
10113 &pring
->txq
, list
) {
10114 if (iocb
->vport
!= vport
)
10116 list_move_tail(&iocb
->list
, &completions
);
10118 spin_unlock_irq(&pring
->ring_lock
);
10119 list_for_each_entry_safe(iocb
, next_iocb
,
10120 &pring
->txcmplq
, list
) {
10121 if (iocb
->vport
!= vport
)
10123 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
10125 pring
->flag
= prev_pring_flag
;
10128 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10130 /* Cancel all the IOCBs from the completions list */
10131 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
10137 * lpfc_sli_hba_down - Resource cleanup function for the HBA
10138 * @phba: Pointer to HBA context object.
10140 * This function cleans up all iocb, buffers, mailbox commands
10141 * while shutting down the HBA. This function is called with no
10142 * lock held and always returns 1.
10143 * This function does the following to cleanup driver resources:
10144 * - Free discovery resources for each virtual port
10145 * - Cleanup any pending fabric iocbs
10146 * - Iterate through the iocb txq and free each entry
10148 * - Free up any buffer posted to the HBA
10149 * - Free mailbox commands in the mailbox queue.
10152 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
10154 LIST_HEAD(completions
);
10155 struct lpfc_sli
*psli
= &phba
->sli
;
10156 struct lpfc_queue
*qp
= NULL
;
10157 struct lpfc_sli_ring
*pring
;
10158 struct lpfc_dmabuf
*buf_ptr
;
10159 unsigned long flags
= 0;
10162 /* Shutdown the mailbox command sub-system */
10163 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
10165 lpfc_hba_down_prep(phba
);
10167 lpfc_fabric_abort_hba(phba
);
10169 spin_lock_irqsave(&phba
->hbalock
, flags
);
10172 * Error everything on the txq since these iocbs
10173 * have not been given to the FW yet.
10175 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10176 for (i
= 0; i
< psli
->num_rings
; i
++) {
10177 pring
= &psli
->sli3_ring
[i
];
10178 /* Only slow rings */
10179 if (pring
->ringno
== LPFC_ELS_RING
) {
10180 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10181 /* Set the lpfc data pending flag */
10182 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10184 list_splice_init(&pring
->txq
, &completions
);
10187 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10191 spin_lock_irq(&pring
->ring_lock
);
10192 list_splice_init(&pring
->txq
, &completions
);
10193 spin_unlock_irq(&pring
->ring_lock
);
10194 if (pring
== phba
->sli4_hba
.els_wq
->pring
) {
10195 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10196 /* Set the lpfc data pending flag */
10197 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10201 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10203 /* Cancel all the IOCBs from the completions list */
10204 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
10207 spin_lock_irqsave(&phba
->hbalock
, flags
);
10208 list_splice_init(&phba
->elsbuf
, &completions
);
10209 phba
->elsbuf_cnt
= 0;
10210 phba
->elsbuf_prev_cnt
= 0;
10211 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10213 while (!list_empty(&completions
)) {
10214 list_remove_head(&completions
, buf_ptr
,
10215 struct lpfc_dmabuf
, list
);
10216 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
10220 /* Return any active mbox cmds */
10221 del_timer_sync(&psli
->mbox_tmo
);
10223 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
10224 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
10225 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
10231 * lpfc_sli_pcimem_bcopy - SLI memory copy function
10232 * @srcp: Source memory pointer.
10233 * @destp: Destination memory pointer.
10234 * @cnt: Number of words required to be copied.
10236 * This function is used for copying data between driver memory
10237 * and the SLI memory. This function also changes the endianness
10238 * of each word if native endianness is different from SLI
10239 * endianness. This function can be called with or without
10243 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
10245 uint32_t *src
= srcp
;
10246 uint32_t *dest
= destp
;
10250 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
10252 ldata
= le32_to_cpu(ldata
);
10261 * lpfc_sli_bemem_bcopy - SLI memory copy function
10262 * @srcp: Source memory pointer.
10263 * @destp: Destination memory pointer.
10264 * @cnt: Number of words required to be copied.
10266 * This function is used for copying data between a data structure
10267 * with big endian representation to local endianness.
10268 * This function can be called with or without lock.
10271 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
10273 uint32_t *src
= srcp
;
10274 uint32_t *dest
= destp
;
10278 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
10280 ldata
= be32_to_cpu(ldata
);
10288 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
10289 * @phba: Pointer to HBA context object.
10290 * @pring: Pointer to driver SLI ring object.
10291 * @mp: Pointer to driver buffer object.
10293 * This function is called with no lock held.
10294 * It always return zero after adding the buffer to the postbufq
10298 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10299 struct lpfc_dmabuf
*mp
)
10301 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
10303 spin_lock_irq(&phba
->hbalock
);
10304 list_add_tail(&mp
->list
, &pring
->postbufq
);
10305 pring
->postbufq_cnt
++;
10306 spin_unlock_irq(&phba
->hbalock
);
10311 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
10312 * @phba: Pointer to HBA context object.
10314 * When HBQ is enabled, buffers are searched based on tags. This function
10315 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
10316 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
10317 * does not conflict with tags of buffer posted for unsolicited events.
10318 * The function returns the allocated tag. The function is called with
10322 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
10324 spin_lock_irq(&phba
->hbalock
);
10325 phba
->buffer_tag_count
++;
10327 * Always set the QUE_BUFTAG_BIT to distiguish between
10328 * a tag assigned by HBQ.
10330 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
10331 spin_unlock_irq(&phba
->hbalock
);
10332 return phba
->buffer_tag_count
;
10336 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
10337 * @phba: Pointer to HBA context object.
10338 * @pring: Pointer to driver SLI ring object.
10339 * @tag: Buffer tag.
10341 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
10342 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
10343 * iocb is posted to the response ring with the tag of the buffer.
10344 * This function searches the pring->postbufq list using the tag
10345 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
10346 * iocb. If the buffer is found then lpfc_dmabuf object of the
10347 * buffer is returned to the caller else NULL is returned.
10348 * This function is called with no lock held.
10350 struct lpfc_dmabuf
*
10351 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10354 struct lpfc_dmabuf
*mp
, *next_mp
;
10355 struct list_head
*slp
= &pring
->postbufq
;
10357 /* Search postbufq, from the beginning, looking for a match on tag */
10358 spin_lock_irq(&phba
->hbalock
);
10359 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
10360 if (mp
->buffer_tag
== tag
) {
10361 list_del_init(&mp
->list
);
10362 pring
->postbufq_cnt
--;
10363 spin_unlock_irq(&phba
->hbalock
);
10368 spin_unlock_irq(&phba
->hbalock
);
10369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10370 "0402 Cannot find virtual addr for buffer tag on "
10371 "ring %d Data x%lx x%p x%p x%x\n",
10372 pring
->ringno
, (unsigned long) tag
,
10373 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
10379 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
10380 * @phba: Pointer to HBA context object.
10381 * @pring: Pointer to driver SLI ring object.
10382 * @phys: DMA address of the buffer.
10384 * This function searches the buffer list using the dma_address
10385 * of unsolicited event to find the driver's lpfc_dmabuf object
10386 * corresponding to the dma_address. The function returns the
10387 * lpfc_dmabuf object if a buffer is found else it returns NULL.
10388 * This function is called by the ct and els unsolicited event
10389 * handlers to get the buffer associated with the unsolicited
10392 * This function is called with no lock held.
10394 struct lpfc_dmabuf
*
10395 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10398 struct lpfc_dmabuf
*mp
, *next_mp
;
10399 struct list_head
*slp
= &pring
->postbufq
;
10401 /* Search postbufq, from the beginning, looking for a match on phys */
10402 spin_lock_irq(&phba
->hbalock
);
10403 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
10404 if (mp
->phys
== phys
) {
10405 list_del_init(&mp
->list
);
10406 pring
->postbufq_cnt
--;
10407 spin_unlock_irq(&phba
->hbalock
);
10412 spin_unlock_irq(&phba
->hbalock
);
10413 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10414 "0410 Cannot find virtual addr for mapped buf on "
10415 "ring %d Data x%llx x%p x%p x%x\n",
10416 pring
->ringno
, (unsigned long long)phys
,
10417 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
10422 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
10423 * @phba: Pointer to HBA context object.
10424 * @cmdiocb: Pointer to driver command iocb object.
10425 * @rspiocb: Pointer to driver response iocb object.
10427 * This function is the completion handler for the abort iocbs for
10428 * ELS commands. This function is called from the ELS ring event
10429 * handler with no lock held. This function frees memory resources
10430 * associated with the abort iocb.
10433 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10434 struct lpfc_iocbq
*rspiocb
)
10436 IOCB_t
*irsp
= &rspiocb
->iocb
;
10437 uint16_t abort_iotag
, abort_context
;
10438 struct lpfc_iocbq
*abort_iocb
= NULL
;
10440 if (irsp
->ulpStatus
) {
10443 * Assume that the port already completed and returned, or
10444 * will return the iocb. Just Log the message.
10446 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
10447 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
10449 spin_lock_irq(&phba
->hbalock
);
10450 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
10451 if (abort_iotag
!= 0 &&
10452 abort_iotag
<= phba
->sli
.last_iotag
)
10454 phba
->sli
.iocbq_lookup
[abort_iotag
];
10456 /* For sli4 the abort_tag is the XRI,
10457 * so the abort routine puts the iotag of the iocb
10458 * being aborted in the context field of the abort
10461 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
10463 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
10464 "0327 Cannot abort els iocb %p "
10465 "with tag %x context %x, abort status %x, "
10467 abort_iocb
, abort_iotag
, abort_context
,
10468 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
10470 spin_unlock_irq(&phba
->hbalock
);
10472 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10477 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
10478 * @phba: Pointer to HBA context object.
10479 * @cmdiocb: Pointer to driver command iocb object.
10480 * @rspiocb: Pointer to driver response iocb object.
10482 * The function is called from SLI ring event handler with no
10483 * lock held. This function is the completion handler for ELS commands
10484 * which are aborted. The function frees memory resources used for
10485 * the aborted ELS commands.
10488 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10489 struct lpfc_iocbq
*rspiocb
)
10491 IOCB_t
*irsp
= &rspiocb
->iocb
;
10493 /* ELS cmd tag <ulpIoTag> completes */
10494 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
10495 "0139 Ignoring ELS cmd tag x%x completion Data: "
10497 irsp
->ulpIoTag
, irsp
->ulpStatus
,
10498 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
10499 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
10500 lpfc_ct_free_iocb(phba
, cmdiocb
);
10502 lpfc_els_free_iocb(phba
, cmdiocb
);
10507 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
10508 * @phba: Pointer to HBA context object.
10509 * @pring: Pointer to driver SLI ring object.
10510 * @cmdiocb: Pointer to driver command iocb object.
10512 * This function issues an abort iocb for the provided command iocb down to
10513 * the port. Other than the case the outstanding command iocb is an abort
10514 * request, this function issues abort out unconditionally. This function is
10515 * called with hbalock held. The function returns 0 when it fails due to
10516 * memory allocation failure or when the command iocb is an abort request.
10519 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10520 struct lpfc_iocbq
*cmdiocb
)
10522 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10523 struct lpfc_iocbq
*abtsiocbp
;
10524 IOCB_t
*icmd
= NULL
;
10525 IOCB_t
*iabt
= NULL
;
10527 unsigned long iflags
;
10529 lockdep_assert_held(&phba
->hbalock
);
10532 * There are certain command types we don't want to abort. And we
10533 * don't want to abort commands that are already in the process of
10536 icmd
= &cmdiocb
->iocb
;
10537 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10538 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10539 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10542 /* issue ABTS for this IOCB based on iotag */
10543 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10544 if (abtsiocbp
== NULL
)
10547 /* This signals the response to set the correct status
10548 * before calling the completion handler
10550 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10552 iabt
= &abtsiocbp
->iocb
;
10553 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10554 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
10555 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10556 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
10557 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
10560 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
10562 iabt
->ulpClass
= icmd
->ulpClass
;
10564 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10565 abtsiocbp
->hba_wqidx
= cmdiocb
->hba_wqidx
;
10566 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
10567 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10568 if (cmdiocb
->iocb_flag
& LPFC_IO_FOF
)
10569 abtsiocbp
->iocb_flag
|= LPFC_IO_FOF
;
10571 if (phba
->link_state
>= LPFC_LINK_UP
)
10572 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
10574 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
10576 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
10577 abtsiocbp
->vport
= vport
;
10579 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
10580 "0339 Abort xri x%x, original iotag x%x, "
10581 "abort cmd iotag x%x\n",
10582 iabt
->un
.acxri
.abortIoTag
,
10583 iabt
->un
.acxri
.abortContextTag
,
10586 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10587 pring
= lpfc_sli4_calc_ring(phba
, abtsiocbp
);
10588 if (unlikely(pring
== NULL
))
10590 /* Note: both hbalock and ring_lock need to be set here */
10591 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
10592 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10594 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
10596 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10601 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10604 * Caller to this routine should check for IOCB_ERROR
10605 * and handle it properly. This routine no longer removes
10606 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10612 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
10613 * @phba: Pointer to HBA context object.
10614 * @pring: Pointer to driver SLI ring object.
10615 * @cmdiocb: Pointer to driver command iocb object.
10617 * This function issues an abort iocb for the provided command iocb. In case
10618 * of unloading, the abort iocb will not be issued to commands on the ELS
10619 * ring. Instead, the callback function shall be changed to those commands
10620 * so that nothing happens when them finishes. This function is called with
10621 * hbalock held. The function returns 0 when the command iocb is an abort
10625 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10626 struct lpfc_iocbq
*cmdiocb
)
10628 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10629 int retval
= IOCB_ERROR
;
10630 IOCB_t
*icmd
= NULL
;
10632 lockdep_assert_held(&phba
->hbalock
);
10635 * There are certain command types we don't want to abort. And we
10636 * don't want to abort commands that are already in the process of
10639 icmd
= &cmdiocb
->iocb
;
10640 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10641 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10642 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10646 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10647 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10649 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10650 goto abort_iotag_exit
;
10654 * If we're unloading, don't abort iocb on the ELS ring, but change
10655 * the callback so that nothing happens when it finishes.
10657 if ((vport
->load_flag
& FC_UNLOADING
) &&
10658 (pring
->ringno
== LPFC_ELS_RING
)) {
10659 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10660 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10662 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10663 goto abort_iotag_exit
;
10666 /* Now, we try to issue the abort to the cmdiocb out */
10667 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
10671 * Caller to this routine should check for IOCB_ERROR
10672 * and handle it properly. This routine no longer removes
10673 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10679 * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb
10680 * @phba: Pointer to HBA context object.
10681 * @pring: Pointer to driver SLI ring object.
10682 * @cmdiocb: Pointer to driver command iocb object.
10684 * This function issues an abort iocb for the provided command iocb down to
10685 * the port. Other than the case the outstanding command iocb is an abort
10686 * request, this function issues abort out unconditionally. This function is
10687 * called with hbalock held. The function returns 0 when it fails due to
10688 * memory allocation failure or when the command iocb is an abort request.
10691 lpfc_sli4_abort_nvme_io(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10692 struct lpfc_iocbq
*cmdiocb
)
10694 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10695 struct lpfc_iocbq
*abtsiocbp
;
10696 union lpfc_wqe
*abts_wqe
;
10700 * There are certain command types we don't want to abort. And we
10701 * don't want to abort commands that are already in the process of
10704 if (cmdiocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
10705 cmdiocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
||
10706 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10709 /* issue ABTS for this io based on iotag */
10710 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10711 if (abtsiocbp
== NULL
)
10714 /* This signals the response to set the correct status
10715 * before calling the completion handler
10717 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10719 /* Complete prepping the abort wqe and issue to the FW. */
10720 abts_wqe
= &abtsiocbp
->wqe
;
10721 bf_set(abort_cmd_ia
, &abts_wqe
->abort_cmd
, 0);
10722 bf_set(abort_cmd_criteria
, &abts_wqe
->abort_cmd
, T_XRI_TAG
);
10724 /* Explicitly set reserved fields to zero.*/
10725 abts_wqe
->abort_cmd
.rsrvd4
= 0;
10726 abts_wqe
->abort_cmd
.rsrvd5
= 0;
10728 /* WQE Common - word 6. Context is XRI tag. Set 0. */
10729 bf_set(wqe_xri_tag
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10730 bf_set(wqe_ctxt_tag
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10733 bf_set(wqe_ct
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10734 bf_set(wqe_cmnd
, &abts_wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
10735 bf_set(wqe_class
, &abts_wqe
->abort_cmd
.wqe_com
,
10736 cmdiocb
->iocb
.ulpClass
);
10738 /* word 8 - tell the FW to abort the IO associated with this
10739 * outstanding exchange ID.
10741 abts_wqe
->abort_cmd
.wqe_com
.abort_tag
= cmdiocb
->sli4_xritag
;
10743 /* word 9 - this is the iotag for the abts_wqe completion. */
10744 bf_set(wqe_reqtag
, &abts_wqe
->abort_cmd
.wqe_com
,
10748 bf_set(wqe_wqid
, &abts_wqe
->abort_cmd
.wqe_com
, cmdiocb
->hba_wqidx
);
10749 bf_set(wqe_qosd
, &abts_wqe
->abort_cmd
.wqe_com
, 1);
10750 bf_set(wqe_lenloc
, &abts_wqe
->abort_cmd
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
10753 bf_set(wqe_cmd_type
, &abts_wqe
->abort_cmd
.wqe_com
, OTHER_COMMAND
);
10754 bf_set(wqe_wqec
, &abts_wqe
->abort_cmd
.wqe_com
, 1);
10755 bf_set(wqe_cqid
, &abts_wqe
->abort_cmd
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
10757 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10758 abtsiocbp
->iocb_flag
|= LPFC_IO_NVME
;
10759 abtsiocbp
->vport
= vport
;
10760 abtsiocbp
->wqe_cmpl
= lpfc_nvme_abort_fcreq_cmpl
;
10761 retval
= lpfc_sli4_issue_wqe(phba
, LPFC_FCP_RING
, abtsiocbp
);
10763 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NVME
,
10764 "6147 Failed abts issue_wqe with status x%x "
10766 retval
, cmdiocb
->sli4_xritag
);
10767 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10771 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NVME
,
10772 "6148 Drv Abort NVME Request Issued for "
10773 "ox_id x%x on reqtag x%x\n",
10774 cmdiocb
->sli4_xritag
,
10781 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
10782 * @phba: pointer to lpfc HBA data structure.
10784 * This routine will abort all pending and outstanding iocbs to an HBA.
10787 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
10789 struct lpfc_sli
*psli
= &phba
->sli
;
10790 struct lpfc_sli_ring
*pring
;
10791 struct lpfc_queue
*qp
= NULL
;
10794 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10795 for (i
= 0; i
< psli
->num_rings
; i
++) {
10796 pring
= &psli
->sli3_ring
[i
];
10797 lpfc_sli_abort_iocb_ring(phba
, pring
);
10801 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10805 lpfc_sli_abort_iocb_ring(phba
, pring
);
10810 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
10811 * @iocbq: Pointer to driver iocb object.
10812 * @vport: Pointer to driver virtual port object.
10813 * @tgt_id: SCSI ID of the target.
10814 * @lun_id: LUN ID of the scsi device.
10815 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
10817 * This function acts as an iocb filter for functions which abort or count
10818 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
10819 * 0 if the filtering criteria is met for the given iocb and will return
10820 * 1 if the filtering criteria is not met.
10821 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
10822 * given iocb is for the SCSI device specified by vport, tgt_id and
10823 * lun_id parameter.
10824 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
10825 * given iocb is for the SCSI target specified by vport and tgt_id
10827 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
10828 * given iocb is for the SCSI host associated with the given vport.
10829 * This function is called with no locks held.
10832 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
10833 uint16_t tgt_id
, uint64_t lun_id
,
10834 lpfc_ctx_cmd ctx_cmd
)
10836 struct lpfc_scsi_buf
*lpfc_cmd
;
10839 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
10842 if (iocbq
->vport
!= vport
)
10845 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
10847 if (lpfc_cmd
->pCmd
== NULL
)
10852 if ((lpfc_cmd
->rdata
->pnode
) &&
10853 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
10854 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
10858 if ((lpfc_cmd
->rdata
->pnode
) &&
10859 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
10862 case LPFC_CTX_HOST
:
10866 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
10867 __func__
, ctx_cmd
);
10875 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
10876 * @vport: Pointer to virtual port.
10877 * @tgt_id: SCSI ID of the target.
10878 * @lun_id: LUN ID of the scsi device.
10879 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10881 * This function returns number of FCP commands pending for the vport.
10882 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
10883 * commands pending on the vport associated with SCSI device specified
10884 * by tgt_id and lun_id parameters.
10885 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
10886 * commands pending on the vport associated with SCSI target specified
10887 * by tgt_id parameter.
10888 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
10889 * commands pending on the vport.
10890 * This function returns the number of iocbs which satisfy the filter.
10891 * This function is called without any lock held.
10894 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
10895 lpfc_ctx_cmd ctx_cmd
)
10897 struct lpfc_hba
*phba
= vport
->phba
;
10898 struct lpfc_iocbq
*iocbq
;
10901 spin_lock_irq(&phba
->hbalock
);
10902 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
10903 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10905 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
10909 spin_unlock_irq(&phba
->hbalock
);
10915 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
10916 * @phba: Pointer to HBA context object
10917 * @cmdiocb: Pointer to command iocb object.
10918 * @rspiocb: Pointer to response iocb object.
10920 * This function is called when an aborted FCP iocb completes. This
10921 * function is called by the ring event handler with no lock held.
10922 * This function frees the iocb.
10925 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10926 struct lpfc_iocbq
*rspiocb
)
10928 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10929 "3096 ABORT_XRI_CN completing on rpi x%x "
10930 "original iotag x%x, abort cmd iotag x%x "
10931 "status 0x%x, reason 0x%x\n",
10932 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
10933 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
10934 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
10935 rspiocb
->iocb
.un
.ulpWord
[4]);
10936 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10941 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
10942 * @vport: Pointer to virtual port.
10943 * @pring: Pointer to driver SLI ring object.
10944 * @tgt_id: SCSI ID of the target.
10945 * @lun_id: LUN ID of the scsi device.
10946 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10948 * This function sends an abort command for every SCSI command
10949 * associated with the given virtual port pending on the ring
10950 * filtered by lpfc_sli_validate_fcp_iocb function.
10951 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
10952 * FCP iocbs associated with lun specified by tgt_id and lun_id
10954 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
10955 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10956 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
10957 * FCP iocbs associated with virtual port.
10958 * This function returns number of iocbs it failed to abort.
10959 * This function is called with no locks held.
10962 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
10963 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
10965 struct lpfc_hba
*phba
= vport
->phba
;
10966 struct lpfc_iocbq
*iocbq
;
10967 struct lpfc_iocbq
*abtsiocb
;
10968 struct lpfc_sli_ring
*pring_s4
;
10969 IOCB_t
*cmd
= NULL
;
10970 int errcnt
= 0, ret_val
= 0;
10973 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
10974 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10976 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
10981 * If the iocbq is already being aborted, don't take a second
10982 * action, but do count it.
10984 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
10987 /* issue ABTS for this IOCB based on iotag */
10988 abtsiocb
= lpfc_sli_get_iocbq(phba
);
10989 if (abtsiocb
== NULL
) {
10994 /* indicate the IO is being aborted by the driver. */
10995 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10997 cmd
= &iocbq
->iocb
;
10998 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10999 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
11000 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11001 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
11003 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
11004 abtsiocb
->iocb
.ulpLe
= 1;
11005 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
11006 abtsiocb
->vport
= vport
;
11008 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11009 abtsiocb
->hba_wqidx
= iocbq
->hba_wqidx
;
11010 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
11011 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
11012 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
11013 abtsiocb
->iocb_flag
|= LPFC_IO_FOF
;
11015 if (lpfc_is_link_up(phba
))
11016 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
11018 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
11020 /* Setup callback routine and issue the command. */
11021 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
11022 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11023 pring_s4
= lpfc_sli4_calc_ring(phba
, iocbq
);
11026 ret_val
= lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
11029 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
11031 if (ret_val
== IOCB_ERROR
) {
11032 lpfc_sli_release_iocbq(phba
, abtsiocb
);
11042 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
11043 * @vport: Pointer to virtual port.
11044 * @pring: Pointer to driver SLI ring object.
11045 * @tgt_id: SCSI ID of the target.
11046 * @lun_id: LUN ID of the scsi device.
11047 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11049 * This function sends an abort command for every SCSI command
11050 * associated with the given virtual port pending on the ring
11051 * filtered by lpfc_sli_validate_fcp_iocb function.
11052 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
11053 * FCP iocbs associated with lun specified by tgt_id and lun_id
11055 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
11056 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11057 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
11058 * FCP iocbs associated with virtual port.
11059 * This function returns number of iocbs it aborted .
11060 * This function is called with no locks held right after a taskmgmt
11064 lpfc_sli_abort_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
11065 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd cmd
)
11067 struct lpfc_hba
*phba
= vport
->phba
;
11068 struct lpfc_scsi_buf
*lpfc_cmd
;
11069 struct lpfc_iocbq
*abtsiocbq
;
11070 struct lpfc_nodelist
*ndlp
;
11071 struct lpfc_iocbq
*iocbq
;
11073 int sum
, i
, ret_val
;
11074 unsigned long iflags
;
11075 struct lpfc_sli_ring
*pring_s4
;
11077 spin_lock_irq(&phba
->hbalock
);
11079 /* all I/Os are in process of being flushed */
11080 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
11081 spin_unlock_irq(&phba
->hbalock
);
11086 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
11087 iocbq
= phba
->sli
.iocbq_lookup
[i
];
11089 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
11094 * If the iocbq is already being aborted, don't take a second
11095 * action, but do count it.
11097 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
11100 /* issue ABTS for this IOCB based on iotag */
11101 abtsiocbq
= __lpfc_sli_get_iocbq(phba
);
11102 if (abtsiocbq
== NULL
)
11105 icmd
= &iocbq
->iocb
;
11106 abtsiocbq
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
11107 abtsiocbq
->iocb
.un
.acxri
.abortContextTag
= icmd
->ulpContext
;
11108 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11109 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
=
11110 iocbq
->sli4_xritag
;
11112 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
11113 abtsiocbq
->iocb
.ulpLe
= 1;
11114 abtsiocbq
->iocb
.ulpClass
= icmd
->ulpClass
;
11115 abtsiocbq
->vport
= vport
;
11117 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11118 abtsiocbq
->hba_wqidx
= iocbq
->hba_wqidx
;
11119 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
11120 abtsiocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
11121 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
11122 abtsiocbq
->iocb_flag
|= LPFC_IO_FOF
;
11124 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
11125 ndlp
= lpfc_cmd
->rdata
->pnode
;
11127 if (lpfc_is_link_up(phba
) &&
11128 (ndlp
&& ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
11129 abtsiocbq
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
11131 abtsiocbq
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
11133 /* Setup callback routine and issue the command. */
11134 abtsiocbq
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
11137 * Indicate the IO is being aborted by the driver and set
11138 * the caller's flag into the aborted IO.
11140 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
11142 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11143 pring_s4
= lpfc_sli4_calc_ring(phba
, iocbq
);
11144 if (pring_s4
== NULL
)
11146 /* Note: both hbalock and ring_lock must be set here */
11147 spin_lock_irqsave(&pring_s4
->ring_lock
, iflags
);
11148 ret_val
= __lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
11150 spin_unlock_irqrestore(&pring_s4
->ring_lock
, iflags
);
11152 ret_val
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
11157 if (ret_val
== IOCB_ERROR
)
11158 __lpfc_sli_release_iocbq(phba
, abtsiocbq
);
11162 spin_unlock_irq(&phba
->hbalock
);
11167 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
11168 * @phba: Pointer to HBA context object.
11169 * @cmdiocbq: Pointer to command iocb.
11170 * @rspiocbq: Pointer to response iocb.
11172 * This function is the completion handler for iocbs issued using
11173 * lpfc_sli_issue_iocb_wait function. This function is called by the
11174 * ring event handler function without any lock held. This function
11175 * can be called from both worker thread context and interrupt
11176 * context. This function also can be called from other thread which
11177 * cleans up the SLI layer objects.
11178 * This function copy the contents of the response iocb to the
11179 * response iocb memory object provided by the caller of
11180 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
11181 * sleeps for the iocb completion.
11184 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
11185 struct lpfc_iocbq
*cmdiocbq
,
11186 struct lpfc_iocbq
*rspiocbq
)
11188 wait_queue_head_t
*pdone_q
;
11189 unsigned long iflags
;
11190 struct lpfc_scsi_buf
*lpfc_cmd
;
11192 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11193 if (cmdiocbq
->iocb_flag
& LPFC_IO_WAKE_TMO
) {
11196 * A time out has occurred for the iocb. If a time out
11197 * completion handler has been supplied, call it. Otherwise,
11198 * just free the iocbq.
11201 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11202 cmdiocbq
->iocb_cmpl
= cmdiocbq
->wait_iocb_cmpl
;
11203 cmdiocbq
->wait_iocb_cmpl
= NULL
;
11204 if (cmdiocbq
->iocb_cmpl
)
11205 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, NULL
);
11207 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
11211 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
11212 if (cmdiocbq
->context2
&& rspiocbq
)
11213 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
11214 &rspiocbq
->iocb
, sizeof(IOCB_t
));
11216 /* Set the exchange busy flag for task management commands */
11217 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
11218 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
11219 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
11221 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
11224 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
11227 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11232 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
11233 * @phba: Pointer to HBA context object..
11234 * @piocbq: Pointer to command iocb.
11235 * @flag: Flag to test.
11237 * This routine grabs the hbalock and then test the iocb_flag to
11238 * see if the passed in flag is set.
11240 * 1 if flag is set.
11241 * 0 if flag is not set.
11244 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
11245 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
11247 unsigned long iflags
;
11250 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11251 ret
= piocbq
->iocb_flag
& flag
;
11252 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11258 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
11259 * @phba: Pointer to HBA context object..
11260 * @pring: Pointer to sli ring.
11261 * @piocb: Pointer to command iocb.
11262 * @prspiocbq: Pointer to response iocb.
11263 * @timeout: Timeout in number of seconds.
11265 * This function issues the iocb to firmware and waits for the
11266 * iocb to complete. The iocb_cmpl field of the shall be used
11267 * to handle iocbs which time out. If the field is NULL, the
11268 * function shall free the iocbq structure. If more clean up is
11269 * needed, the caller is expected to provide a completion function
11270 * that will provide the needed clean up. If the iocb command is
11271 * not completed within timeout seconds, the function will either
11272 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
11273 * completion function set in the iocb_cmpl field and then return
11274 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
11275 * resources if this function returns IOCB_TIMEDOUT.
11276 * The function waits for the iocb completion using an
11277 * non-interruptible wait.
11278 * This function will sleep while waiting for iocb completion.
11279 * So, this function should not be called from any context which
11280 * does not allow sleeping. Due to the same reason, this function
11281 * cannot be called with interrupt disabled.
11282 * This function assumes that the iocb completions occur while
11283 * this function sleep. So, this function cannot be called from
11284 * the thread which process iocb completion for this ring.
11285 * This function clears the iocb_flag of the iocb object before
11286 * issuing the iocb and the iocb completion handler sets this
11287 * flag and wakes this thread when the iocb completes.
11288 * The contents of the response iocb will be copied to prspiocbq
11289 * by the completion handler when the command completes.
11290 * This function returns IOCB_SUCCESS when success.
11291 * This function is called with no lock held.
11294 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
11295 uint32_t ring_number
,
11296 struct lpfc_iocbq
*piocb
,
11297 struct lpfc_iocbq
*prspiocbq
,
11300 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
11301 long timeleft
, timeout_req
= 0;
11302 int retval
= IOCB_SUCCESS
;
11304 struct lpfc_iocbq
*iocb
;
11306 int txcmplq_cnt
= 0;
11307 struct lpfc_sli_ring
*pring
;
11308 unsigned long iflags
;
11309 bool iocb_completed
= true;
11311 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
11312 pring
= lpfc_sli4_calc_ring(phba
, piocb
);
11314 pring
= &phba
->sli
.sli3_ring
[ring_number
];
11316 * If the caller has provided a response iocbq buffer, then context2
11317 * is NULL or its an error.
11320 if (piocb
->context2
)
11322 piocb
->context2
= prspiocbq
;
11325 piocb
->wait_iocb_cmpl
= piocb
->iocb_cmpl
;
11326 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
11327 piocb
->context_un
.wait_queue
= &done_q
;
11328 piocb
->iocb_flag
&= ~(LPFC_IO_WAKE
| LPFC_IO_WAKE_TMO
);
11330 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
11331 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
11333 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
11334 writel(creg_val
, phba
->HCregaddr
);
11335 readl(phba
->HCregaddr
); /* flush */
11338 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
11339 SLI_IOCB_RET_IOCB
);
11340 if (retval
== IOCB_SUCCESS
) {
11341 timeout_req
= msecs_to_jiffies(timeout
* 1000);
11342 timeleft
= wait_event_timeout(done_q
,
11343 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
11345 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11346 if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
11349 * IOCB timed out. Inform the wake iocb wait
11350 * completion function and set local status
11353 iocb_completed
= false;
11354 piocb
->iocb_flag
|= LPFC_IO_WAKE_TMO
;
11356 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11357 if (iocb_completed
) {
11358 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11359 "0331 IOCB wake signaled\n");
11360 /* Note: we are not indicating if the IOCB has a success
11361 * status or not - that's for the caller to check.
11362 * IOCB_SUCCESS means just that the command was sent and
11363 * completed. Not that it completed successfully.
11365 } else if (timeleft
== 0) {
11366 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11367 "0338 IOCB wait timeout error - no "
11368 "wake response Data x%x\n", timeout
);
11369 retval
= IOCB_TIMEDOUT
;
11371 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11372 "0330 IOCB wake NOT set, "
11374 timeout
, (timeleft
/ jiffies
));
11375 retval
= IOCB_TIMEDOUT
;
11377 } else if (retval
== IOCB_BUSY
) {
11378 if (phba
->cfg_log_verbose
& LOG_SLI
) {
11379 list_for_each_entry(iocb
, &pring
->txq
, list
) {
11382 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
11385 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11386 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
11387 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
11391 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11392 "0332 IOCB wait issue failed, Data x%x\n",
11394 retval
= IOCB_ERROR
;
11397 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
11398 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
11400 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
11401 writel(creg_val
, phba
->HCregaddr
);
11402 readl(phba
->HCregaddr
); /* flush */
11406 piocb
->context2
= NULL
;
11408 piocb
->context_un
.wait_queue
= NULL
;
11409 piocb
->iocb_cmpl
= NULL
;
11414 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
11415 * @phba: Pointer to HBA context object.
11416 * @pmboxq: Pointer to driver mailbox object.
11417 * @timeout: Timeout in number of seconds.
11419 * This function issues the mailbox to firmware and waits for the
11420 * mailbox command to complete. If the mailbox command is not
11421 * completed within timeout seconds, it returns MBX_TIMEOUT.
11422 * The function waits for the mailbox completion using an
11423 * interruptible wait. If the thread is woken up due to a
11424 * signal, MBX_TIMEOUT error is returned to the caller. Caller
11425 * should not free the mailbox resources, if this function returns
11427 * This function will sleep while waiting for mailbox completion.
11428 * So, this function should not be called from any context which
11429 * does not allow sleeping. Due to the same reason, this function
11430 * cannot be called with interrupt disabled.
11431 * This function assumes that the mailbox completion occurs while
11432 * this function sleep. So, this function cannot be called from
11433 * the worker thread which processes mailbox completion.
11434 * This function is called in the context of HBA management
11436 * This function returns MBX_SUCCESS when successful.
11437 * This function is called with no lock held.
11440 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
11443 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
11444 MAILBOX_t
*mb
= NULL
;
11446 unsigned long flag
;
11448 /* The caller might set context1 for extended buffer */
11449 if (pmboxq
->context1
)
11450 mb
= (MAILBOX_t
*)pmboxq
->context1
;
11452 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
11453 /* setup wake call as IOCB callback */
11454 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
11455 /* setup context field to pass wait_queue pointer to wake function */
11456 pmboxq
->context1
= &done_q
;
11458 /* now issue the command */
11459 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
11460 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
11461 wait_event_interruptible_timeout(done_q
,
11462 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
11463 msecs_to_jiffies(timeout
* 1000));
11465 spin_lock_irqsave(&phba
->hbalock
, flag
);
11466 /* restore the possible extended buffer for free resource */
11467 pmboxq
->context1
= (uint8_t *)mb
;
11469 * if LPFC_MBX_WAKE flag is set the mailbox is completed
11470 * else do not free the resources.
11472 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
11473 retval
= MBX_SUCCESS
;
11475 retval
= MBX_TIMEOUT
;
11476 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11478 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
11480 /* restore the possible extended buffer for free resource */
11481 pmboxq
->context1
= (uint8_t *)mb
;
11488 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
11489 * @phba: Pointer to HBA context.
11491 * This function is called to shutdown the driver's mailbox sub-system.
11492 * It first marks the mailbox sub-system is in a block state to prevent
11493 * the asynchronous mailbox command from issued off the pending mailbox
11494 * command queue. If the mailbox command sub-system shutdown is due to
11495 * HBA error conditions such as EEH or ERATT, this routine shall invoke
11496 * the mailbox sub-system flush routine to forcefully bring down the
11497 * mailbox sub-system. Otherwise, if it is due to normal condition (such
11498 * as with offline or HBA function reset), this routine will wait for the
11499 * outstanding mailbox command to complete before invoking the mailbox
11500 * sub-system flush routine to gracefully bring down mailbox sub-system.
11503 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
11505 struct lpfc_sli
*psli
= &phba
->sli
;
11506 unsigned long timeout
;
11508 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
11509 /* delay 100ms for port state */
11511 lpfc_sli_mbox_sys_flush(phba
);
11514 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
11516 spin_lock_irq(&phba
->hbalock
);
11517 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
11519 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
11520 /* Determine how long we might wait for the active mailbox
11521 * command to be gracefully completed by firmware.
11523 if (phba
->sli
.mbox_active
)
11524 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
11525 phba
->sli
.mbox_active
) *
11527 spin_unlock_irq(&phba
->hbalock
);
11529 while (phba
->sli
.mbox_active
) {
11530 /* Check active mailbox complete status every 2ms */
11532 if (time_after(jiffies
, timeout
))
11533 /* Timeout, let the mailbox flush routine to
11534 * forcefully release active mailbox command
11539 spin_unlock_irq(&phba
->hbalock
);
11541 lpfc_sli_mbox_sys_flush(phba
);
11545 * lpfc_sli_eratt_read - read sli-3 error attention events
11546 * @phba: Pointer to HBA context.
11548 * This function is called to read the SLI3 device error attention registers
11549 * for possible error attention events. The caller must hold the hostlock
11550 * with spin_lock_irq().
11552 * This function returns 1 when there is Error Attention in the Host Attention
11553 * Register and returns 0 otherwise.
11556 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
11560 /* Read chip Host Attention (HA) register */
11561 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11564 if (ha_copy
& HA_ERATT
) {
11565 /* Read host status register to retrieve error event */
11566 if (lpfc_sli_read_hs(phba
))
11569 /* Check if there is a deferred error condition is active */
11570 if ((HS_FFER1
& phba
->work_hs
) &&
11571 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11572 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
11573 phba
->hba_flag
|= DEFER_ERATT
;
11574 /* Clear all interrupt enable conditions */
11575 writel(0, phba
->HCregaddr
);
11576 readl(phba
->HCregaddr
);
11579 /* Set the driver HA work bitmap */
11580 phba
->work_ha
|= HA_ERATT
;
11581 /* Indicate polling handles this ERATT */
11582 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11588 /* Set the driver HS work bitmap */
11589 phba
->work_hs
|= UNPLUG_ERR
;
11590 /* Set the driver HA work bitmap */
11591 phba
->work_ha
|= HA_ERATT
;
11592 /* Indicate polling handles this ERATT */
11593 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11598 * lpfc_sli4_eratt_read - read sli-4 error attention events
11599 * @phba: Pointer to HBA context.
11601 * This function is called to read the SLI4 device error attention registers
11602 * for possible error attention events. The caller must hold the hostlock
11603 * with spin_lock_irq().
11605 * This function returns 1 when there is Error Attention in the Host Attention
11606 * Register and returns 0 otherwise.
11609 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
11611 uint32_t uerr_sta_hi
, uerr_sta_lo
;
11612 uint32_t if_type
, portsmphr
;
11613 struct lpfc_register portstat_reg
;
11616 * For now, use the SLI4 device internal unrecoverable error
11617 * registers for error attention. This can be changed later.
11619 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
11621 case LPFC_SLI_INTF_IF_TYPE_0
:
11622 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
11624 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
11626 phba
->work_hs
|= UNPLUG_ERR
;
11627 phba
->work_ha
|= HA_ERATT
;
11628 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11631 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
11632 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
11633 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11634 "1423 HBA Unrecoverable error: "
11635 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
11636 "ue_mask_lo_reg=0x%x, "
11637 "ue_mask_hi_reg=0x%x\n",
11638 uerr_sta_lo
, uerr_sta_hi
,
11639 phba
->sli4_hba
.ue_mask_lo
,
11640 phba
->sli4_hba
.ue_mask_hi
);
11641 phba
->work_status
[0] = uerr_sta_lo
;
11642 phba
->work_status
[1] = uerr_sta_hi
;
11643 phba
->work_ha
|= HA_ERATT
;
11644 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11648 case LPFC_SLI_INTF_IF_TYPE_2
:
11649 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
11650 &portstat_reg
.word0
) ||
11651 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
11653 phba
->work_hs
|= UNPLUG_ERR
;
11654 phba
->work_ha
|= HA_ERATT
;
11655 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11658 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
11659 phba
->work_status
[0] =
11660 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
11661 phba
->work_status
[1] =
11662 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
11663 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11664 "2885 Port Status Event: "
11665 "port status reg 0x%x, "
11666 "port smphr reg 0x%x, "
11667 "error 1=0x%x, error 2=0x%x\n",
11668 portstat_reg
.word0
,
11670 phba
->work_status
[0],
11671 phba
->work_status
[1]);
11672 phba
->work_ha
|= HA_ERATT
;
11673 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11677 case LPFC_SLI_INTF_IF_TYPE_1
:
11679 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11680 "2886 HBA Error Attention on unsupported "
11681 "if type %d.", if_type
);
11689 * lpfc_sli_check_eratt - check error attention events
11690 * @phba: Pointer to HBA context.
11692 * This function is called from timer soft interrupt context to check HBA's
11693 * error attention register bit for error attention events.
11695 * This function returns 1 when there is Error Attention in the Host Attention
11696 * Register and returns 0 otherwise.
11699 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
11703 /* If somebody is waiting to handle an eratt, don't process it
11704 * here. The brdkill function will do this.
11706 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11709 /* Check if interrupt handler handles this ERATT */
11710 spin_lock_irq(&phba
->hbalock
);
11711 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
11712 /* Interrupt handler has handled ERATT */
11713 spin_unlock_irq(&phba
->hbalock
);
11718 * If there is deferred error attention, do not check for error
11721 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11722 spin_unlock_irq(&phba
->hbalock
);
11726 /* If PCI channel is offline, don't process it */
11727 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
11728 spin_unlock_irq(&phba
->hbalock
);
11732 switch (phba
->sli_rev
) {
11733 case LPFC_SLI_REV2
:
11734 case LPFC_SLI_REV3
:
11735 /* Read chip Host Attention (HA) register */
11736 ha_copy
= lpfc_sli_eratt_read(phba
);
11738 case LPFC_SLI_REV4
:
11739 /* Read device Uncoverable Error (UERR) registers */
11740 ha_copy
= lpfc_sli4_eratt_read(phba
);
11743 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11744 "0299 Invalid SLI revision (%d)\n",
11749 spin_unlock_irq(&phba
->hbalock
);
11755 * lpfc_intr_state_check - Check device state for interrupt handling
11756 * @phba: Pointer to HBA context.
11758 * This inline routine checks whether a device or its PCI slot is in a state
11759 * that the interrupt should be handled.
11761 * This function returns 0 if the device or the PCI slot is in a state that
11762 * interrupt should be handled, otherwise -EIO.
11765 lpfc_intr_state_check(struct lpfc_hba
*phba
)
11767 /* If the pci channel is offline, ignore all the interrupts */
11768 if (unlikely(pci_channel_offline(phba
->pcidev
)))
11771 /* Update device level interrupt statistics */
11772 phba
->sli
.slistat
.sli_intr
++;
11774 /* Ignore all interrupts during initialization. */
11775 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
11782 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
11783 * @irq: Interrupt number.
11784 * @dev_id: The device context pointer.
11786 * This function is directly called from the PCI layer as an interrupt
11787 * service routine when device with SLI-3 interface spec is enabled with
11788 * MSI-X multi-message interrupt mode and there are slow-path events in
11789 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11790 * interrupt mode, this function is called as part of the device-level
11791 * interrupt handler. When the PCI slot is in error recovery or the HBA
11792 * is undergoing initialization, the interrupt handler will not process
11793 * the interrupt. The link attention and ELS ring attention events are
11794 * handled by the worker thread. The interrupt handler signals the worker
11795 * thread and returns for these events. This function is called without
11796 * any lock held. It gets the hbalock to access and update SLI data
11799 * This function returns IRQ_HANDLED when interrupt is handled else it
11800 * returns IRQ_NONE.
11803 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
11805 struct lpfc_hba
*phba
;
11806 uint32_t ha_copy
, hc_copy
;
11807 uint32_t work_ha_copy
;
11808 unsigned long status
;
11809 unsigned long iflag
;
11812 MAILBOX_t
*mbox
, *pmbox
;
11813 struct lpfc_vport
*vport
;
11814 struct lpfc_nodelist
*ndlp
;
11815 struct lpfc_dmabuf
*mp
;
11820 * Get the driver's phba structure from the dev_id and
11821 * assume the HBA is not interrupting.
11823 phba
= (struct lpfc_hba
*)dev_id
;
11825 if (unlikely(!phba
))
11829 * Stuff needs to be attented to when this function is invoked as an
11830 * individual interrupt handler in MSI-X multi-message interrupt mode
11832 if (phba
->intr_type
== MSIX
) {
11833 /* Check device state for handling interrupt */
11834 if (lpfc_intr_state_check(phba
))
11836 /* Need to read HA REG for slow-path events */
11837 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11838 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11840 /* If somebody is waiting to handle an eratt don't process it
11841 * here. The brdkill function will do this.
11843 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11844 ha_copy
&= ~HA_ERATT
;
11845 /* Check the need for handling ERATT in interrupt handler */
11846 if (ha_copy
& HA_ERATT
) {
11847 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11848 /* ERATT polling has handled ERATT */
11849 ha_copy
&= ~HA_ERATT
;
11851 /* Indicate interrupt handler handles ERATT */
11852 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11856 * If there is deferred error attention, do not check for any
11859 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11860 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11864 /* Clear up only attention source related to slow-path */
11865 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
11868 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
11869 HC_LAINT_ENA
| HC_ERINT_ENA
),
11871 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
11873 writel(hc_copy
, phba
->HCregaddr
);
11874 readl(phba
->HAregaddr
); /* flush */
11875 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11877 ha_copy
= phba
->ha_copy
;
11879 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
11881 if (work_ha_copy
) {
11882 if (work_ha_copy
& HA_LATT
) {
11883 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
11885 * Turn off Link Attention interrupts
11886 * until CLEAR_LA done
11888 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11889 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
11890 if (lpfc_readl(phba
->HCregaddr
, &control
))
11892 control
&= ~HC_LAINT_ENA
;
11893 writel(control
, phba
->HCregaddr
);
11894 readl(phba
->HCregaddr
); /* flush */
11895 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11898 work_ha_copy
&= ~HA_LATT
;
11901 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
11903 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
11904 * the only slow ring.
11906 status
= (work_ha_copy
&
11907 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11908 status
>>= (4*LPFC_ELS_RING
);
11909 if (status
& HA_RXMASK
) {
11910 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11911 if (lpfc_readl(phba
->HCregaddr
, &control
))
11914 lpfc_debugfs_slow_ring_trc(phba
,
11915 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
11917 (uint32_t)phba
->sli
.slistat
.sli_intr
);
11919 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
11920 lpfc_debugfs_slow_ring_trc(phba
,
11921 "ISR Disable ring:"
11922 "pwork:x%x hawork:x%x wait:x%x",
11923 phba
->work_ha
, work_ha_copy
,
11924 (uint32_t)((unsigned long)
11925 &phba
->work_waitq
));
11928 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
11929 writel(control
, phba
->HCregaddr
);
11930 readl(phba
->HCregaddr
); /* flush */
11933 lpfc_debugfs_slow_ring_trc(phba
,
11934 "ISR slow ring: pwork:"
11935 "x%x hawork:x%x wait:x%x",
11936 phba
->work_ha
, work_ha_copy
,
11937 (uint32_t)((unsigned long)
11938 &phba
->work_waitq
));
11940 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11943 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11944 if (work_ha_copy
& HA_ERATT
) {
11945 if (lpfc_sli_read_hs(phba
))
11948 * Check if there is a deferred error condition
11951 if ((HS_FFER1
& phba
->work_hs
) &&
11952 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11953 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
11955 phba
->hba_flag
|= DEFER_ERATT
;
11956 /* Clear all interrupt enable conditions */
11957 writel(0, phba
->HCregaddr
);
11958 readl(phba
->HCregaddr
);
11962 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
11963 pmb
= phba
->sli
.mbox_active
;
11964 pmbox
= &pmb
->u
.mb
;
11966 vport
= pmb
->vport
;
11968 /* First check out the status word */
11969 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
11970 if (pmbox
->mbxOwner
!= OWN_HOST
) {
11971 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11973 * Stray Mailbox Interrupt, mbxCommand <cmd>
11974 * mbxStatus <status>
11976 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11978 "(%d):0304 Stray Mailbox "
11979 "Interrupt mbxCommand x%x "
11981 (vport
? vport
->vpi
: 0),
11984 /* clear mailbox attention bit */
11985 work_ha_copy
&= ~HA_MBATT
;
11987 phba
->sli
.mbox_active
= NULL
;
11988 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11989 phba
->last_completion_time
= jiffies
;
11990 del_timer(&phba
->sli
.mbox_tmo
);
11991 if (pmb
->mbox_cmpl
) {
11992 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
11994 if (pmb
->out_ext_byte_len
&&
11996 lpfc_sli_pcimem_bcopy(
11999 pmb
->out_ext_byte_len
);
12001 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
12002 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
12004 lpfc_debugfs_disc_trc(vport
,
12005 LPFC_DISC_TRC_MBOX_VPORT
,
12006 "MBOX dflt rpi: : "
12007 "status:x%x rpi:x%x",
12008 (uint32_t)pmbox
->mbxStatus
,
12009 pmbox
->un
.varWords
[0], 0);
12011 if (!pmbox
->mbxStatus
) {
12012 mp
= (struct lpfc_dmabuf
*)
12014 ndlp
= (struct lpfc_nodelist
*)
12017 /* Reg_LOGIN of dflt RPI was
12018 * successful. new lets get
12019 * rid of the RPI using the
12020 * same mbox buffer.
12022 lpfc_unreg_login(phba
,
12024 pmbox
->un
.varWords
[0],
12027 lpfc_mbx_cmpl_dflt_rpi
;
12028 pmb
->context1
= mp
;
12029 pmb
->context2
= ndlp
;
12030 pmb
->vport
= vport
;
12031 rc
= lpfc_sli_issue_mbox(phba
,
12034 if (rc
!= MBX_BUSY
)
12035 lpfc_printf_log(phba
,
12037 LOG_MBOX
| LOG_SLI
,
12038 "0350 rc should have"
12039 "been MBX_BUSY\n");
12040 if (rc
!= MBX_NOT_FINISHED
)
12041 goto send_current_mbox
;
12045 &phba
->pport
->work_port_lock
,
12047 phba
->pport
->work_port_events
&=
12049 spin_unlock_irqrestore(
12050 &phba
->pport
->work_port_lock
,
12052 lpfc_mbox_cmpl_put(phba
, pmb
);
12055 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12057 if ((work_ha_copy
& HA_MBATT
) &&
12058 (phba
->sli
.mbox_active
== NULL
)) {
12060 /* Process next mailbox command if there is one */
12062 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
12064 } while (rc
== MBX_NOT_FINISHED
);
12065 if (rc
!= MBX_SUCCESS
)
12066 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12067 LOG_SLI
, "0349 rc should be "
12071 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12072 phba
->work_ha
|= work_ha_copy
;
12073 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12074 lpfc_worker_wake_up(phba
);
12076 return IRQ_HANDLED
;
12078 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12079 return IRQ_HANDLED
;
12081 } /* lpfc_sli_sp_intr_handler */
12084 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
12085 * @irq: Interrupt number.
12086 * @dev_id: The device context pointer.
12088 * This function is directly called from the PCI layer as an interrupt
12089 * service routine when device with SLI-3 interface spec is enabled with
12090 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12091 * ring event in the HBA. However, when the device is enabled with either
12092 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12093 * device-level interrupt handler. When the PCI slot is in error recovery
12094 * or the HBA is undergoing initialization, the interrupt handler will not
12095 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12096 * the intrrupt context. This function is called without any lock held.
12097 * It gets the hbalock to access and update SLI data structures.
12099 * This function returns IRQ_HANDLED when interrupt is handled else it
12100 * returns IRQ_NONE.
12103 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
12105 struct lpfc_hba
*phba
;
12107 unsigned long status
;
12108 unsigned long iflag
;
12109 struct lpfc_sli_ring
*pring
;
12111 /* Get the driver's phba structure from the dev_id and
12112 * assume the HBA is not interrupting.
12114 phba
= (struct lpfc_hba
*) dev_id
;
12116 if (unlikely(!phba
))
12120 * Stuff needs to be attented to when this function is invoked as an
12121 * individual interrupt handler in MSI-X multi-message interrupt mode
12123 if (phba
->intr_type
== MSIX
) {
12124 /* Check device state for handling interrupt */
12125 if (lpfc_intr_state_check(phba
))
12127 /* Need to read HA REG for FCP ring and other ring events */
12128 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
12129 return IRQ_HANDLED
;
12130 /* Clear up only attention source related to fast-path */
12131 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12133 * If there is deferred error attention, do not check for
12136 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12137 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12140 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
12142 readl(phba
->HAregaddr
); /* flush */
12143 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12145 ha_copy
= phba
->ha_copy
;
12148 * Process all events on FCP ring. Take the optimized path for FCP IO.
12150 ha_copy
&= ~(phba
->work_ha_mask
);
12152 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
12153 status
>>= (4*LPFC_FCP_RING
);
12154 pring
= &phba
->sli
.sli3_ring
[LPFC_FCP_RING
];
12155 if (status
& HA_RXMASK
)
12156 lpfc_sli_handle_fast_ring_event(phba
, pring
, status
);
12158 if (phba
->cfg_multi_ring_support
== 2) {
12160 * Process all events on extra ring. Take the optimized path
12161 * for extra ring IO.
12163 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
12164 status
>>= (4*LPFC_EXTRA_RING
);
12165 if (status
& HA_RXMASK
) {
12166 lpfc_sli_handle_fast_ring_event(phba
,
12167 &phba
->sli
.sli3_ring
[LPFC_EXTRA_RING
],
12171 return IRQ_HANDLED
;
12172 } /* lpfc_sli_fp_intr_handler */
12175 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
12176 * @irq: Interrupt number.
12177 * @dev_id: The device context pointer.
12179 * This function is the HBA device-level interrupt handler to device with
12180 * SLI-3 interface spec, called from the PCI layer when either MSI or
12181 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
12182 * requires driver attention. This function invokes the slow-path interrupt
12183 * attention handling function and fast-path interrupt attention handling
12184 * function in turn to process the relevant HBA attention events. This
12185 * function is called without any lock held. It gets the hbalock to access
12186 * and update SLI data structures.
12188 * This function returns IRQ_HANDLED when interrupt is handled, else it
12189 * returns IRQ_NONE.
12192 lpfc_sli_intr_handler(int irq
, void *dev_id
)
12194 struct lpfc_hba
*phba
;
12195 irqreturn_t sp_irq_rc
, fp_irq_rc
;
12196 unsigned long status1
, status2
;
12200 * Get the driver's phba structure from the dev_id and
12201 * assume the HBA is not interrupting.
12203 phba
= (struct lpfc_hba
*) dev_id
;
12205 if (unlikely(!phba
))
12208 /* Check device state for handling interrupt */
12209 if (lpfc_intr_state_check(phba
))
12212 spin_lock(&phba
->hbalock
);
12213 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
12214 spin_unlock(&phba
->hbalock
);
12215 return IRQ_HANDLED
;
12218 if (unlikely(!phba
->ha_copy
)) {
12219 spin_unlock(&phba
->hbalock
);
12221 } else if (phba
->ha_copy
& HA_ERATT
) {
12222 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
12223 /* ERATT polling has handled ERATT */
12224 phba
->ha_copy
&= ~HA_ERATT
;
12226 /* Indicate interrupt handler handles ERATT */
12227 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
12231 * If there is deferred error attention, do not check for any interrupt.
12233 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12234 spin_unlock(&phba
->hbalock
);
12238 /* Clear attention sources except link and error attentions */
12239 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
12240 spin_unlock(&phba
->hbalock
);
12241 return IRQ_HANDLED
;
12243 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
12244 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
12246 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
12247 writel(hc_copy
, phba
->HCregaddr
);
12248 readl(phba
->HAregaddr
); /* flush */
12249 spin_unlock(&phba
->hbalock
);
12252 * Invokes slow-path host attention interrupt handling as appropriate.
12255 /* status of events with mailbox and link attention */
12256 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
12258 /* status of events with ELS ring */
12259 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
12260 status2
>>= (4*LPFC_ELS_RING
);
12262 if (status1
|| (status2
& HA_RXMASK
))
12263 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
12265 sp_irq_rc
= IRQ_NONE
;
12268 * Invoke fast-path host attention interrupt handling as appropriate.
12271 /* status of events with FCP ring */
12272 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
12273 status1
>>= (4*LPFC_FCP_RING
);
12275 /* status of events with extra ring */
12276 if (phba
->cfg_multi_ring_support
== 2) {
12277 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
12278 status2
>>= (4*LPFC_EXTRA_RING
);
12282 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
12283 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
12285 fp_irq_rc
= IRQ_NONE
;
12287 /* Return device-level interrupt handling status */
12288 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
12289 } /* lpfc_sli_intr_handler */
12292 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
12293 * @phba: pointer to lpfc hba data structure.
12295 * This routine is invoked by the worker thread to process all the pending
12296 * SLI4 FCP abort XRI events.
12298 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
12300 struct lpfc_cq_event
*cq_event
;
12302 /* First, declare the fcp xri abort event has been handled */
12303 spin_lock_irq(&phba
->hbalock
);
12304 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
12305 spin_unlock_irq(&phba
->hbalock
);
12306 /* Now, handle all the fcp xri abort events */
12307 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
12308 /* Get the first event from the head of the event queue */
12309 spin_lock_irq(&phba
->hbalock
);
12310 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
12311 cq_event
, struct lpfc_cq_event
, list
);
12312 spin_unlock_irq(&phba
->hbalock
);
12313 /* Notify aborted XRI for FCP work queue */
12314 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
12315 /* Free the event processed back to the free pool */
12316 lpfc_sli4_cq_event_release(phba
, cq_event
);
12321 * lpfc_sli4_nvme_xri_abort_event_proc - Process nvme xri abort event
12322 * @phba: pointer to lpfc hba data structure.
12324 * This routine is invoked by the worker thread to process all the pending
12325 * SLI4 NVME abort XRI events.
12327 void lpfc_sli4_nvme_xri_abort_event_proc(struct lpfc_hba
*phba
)
12329 struct lpfc_cq_event
*cq_event
;
12331 /* First, declare the fcp xri abort event has been handled */
12332 spin_lock_irq(&phba
->hbalock
);
12333 phba
->hba_flag
&= ~NVME_XRI_ABORT_EVENT
;
12334 spin_unlock_irq(&phba
->hbalock
);
12335 /* Now, handle all the fcp xri abort events */
12336 while (!list_empty(&phba
->sli4_hba
.sp_nvme_xri_aborted_work_queue
)) {
12337 /* Get the first event from the head of the event queue */
12338 spin_lock_irq(&phba
->hbalock
);
12339 list_remove_head(&phba
->sli4_hba
.sp_nvme_xri_aborted_work_queue
,
12340 cq_event
, struct lpfc_cq_event
, list
);
12341 spin_unlock_irq(&phba
->hbalock
);
12342 /* Notify aborted XRI for NVME work queue */
12343 if (phba
->nvmet_support
) {
12344 lpfc_sli4_nvmet_xri_aborted(phba
,
12345 &cq_event
->cqe
.wcqe_axri
);
12347 lpfc_sli4_nvme_xri_aborted(phba
,
12348 &cq_event
->cqe
.wcqe_axri
);
12350 /* Free the event processed back to the free pool */
12351 lpfc_sli4_cq_event_release(phba
, cq_event
);
12356 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12357 * @phba: pointer to lpfc hba data structure.
12359 * This routine is invoked by the worker thread to process all the pending
12360 * SLI4 els abort xri events.
12362 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
12364 struct lpfc_cq_event
*cq_event
;
12366 /* First, declare the els xri abort event has been handled */
12367 spin_lock_irq(&phba
->hbalock
);
12368 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
12369 spin_unlock_irq(&phba
->hbalock
);
12370 /* Now, handle all the els xri abort events */
12371 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
12372 /* Get the first event from the head of the event queue */
12373 spin_lock_irq(&phba
->hbalock
);
12374 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
12375 cq_event
, struct lpfc_cq_event
, list
);
12376 spin_unlock_irq(&phba
->hbalock
);
12377 /* Notify aborted XRI for ELS work queue */
12378 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
12379 /* Free the event processed back to the free pool */
12380 lpfc_sli4_cq_event_release(phba
, cq_event
);
12385 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
12386 * @phba: pointer to lpfc hba data structure
12387 * @pIocbIn: pointer to the rspiocbq
12388 * @pIocbOut: pointer to the cmdiocbq
12389 * @wcqe: pointer to the complete wcqe
12391 * This routine transfers the fields of a command iocbq to a response iocbq
12392 * by copying all the IOCB fields from command iocbq and transferring the
12393 * completion status information from the complete wcqe.
12396 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
12397 struct lpfc_iocbq
*pIocbIn
,
12398 struct lpfc_iocbq
*pIocbOut
,
12399 struct lpfc_wcqe_complete
*wcqe
)
12402 unsigned long iflags
;
12403 uint32_t status
, max_response
;
12404 struct lpfc_dmabuf
*dmabuf
;
12405 struct ulp_bde64
*bpl
, bde
;
12406 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
12408 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
12409 sizeof(struct lpfc_iocbq
) - offset
);
12410 /* Map WCQE parameters into irspiocb parameters */
12411 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
12412 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
12413 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
12414 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
12415 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
12416 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
12417 wcqe
->total_data_placed
;
12419 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
12421 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
12422 switch (pIocbOut
->iocb
.ulpCommand
) {
12423 case CMD_ELS_REQUEST64_CR
:
12424 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
12425 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
12426 bde
.tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
12427 max_response
= bde
.tus
.f
.bdeSize
;
12429 case CMD_GEN_REQUEST64_CR
:
12431 if (!pIocbOut
->context3
)
12433 numBdes
= pIocbOut
->iocb
.un
.genreq64
.bdl
.bdeSize
/
12434 sizeof(struct ulp_bde64
);
12435 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
12436 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
12437 for (i
= 0; i
< numBdes
; i
++) {
12438 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
12439 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
12440 max_response
+= bde
.tus
.f
.bdeSize
;
12444 max_response
= wcqe
->total_data_placed
;
12447 if (max_response
< wcqe
->total_data_placed
)
12448 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= max_response
;
12450 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
=
12451 wcqe
->total_data_placed
;
12454 /* Convert BG errors for completion status */
12455 if (status
== CQE_STATUS_DI_ERROR
) {
12456 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
12458 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
12459 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
12461 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
12463 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
12464 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
12465 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12466 BGS_GUARD_ERR_MASK
;
12467 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
12468 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12469 BGS_APPTAG_ERR_MASK
;
12470 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
12471 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12472 BGS_REFTAG_ERR_MASK
;
12474 /* Check to see if there was any good data before the error */
12475 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
12476 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12477 BGS_HI_WATER_MARK_PRESENT_MASK
;
12478 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
12479 wcqe
->total_data_placed
;
12483 * Set ALL the error bits to indicate we don't know what
12484 * type of error it is.
12486 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
12487 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12488 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
12489 BGS_GUARD_ERR_MASK
);
12492 /* Pick up HBA exchange busy condition */
12493 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
12494 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12495 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
12496 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12501 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
12502 * @phba: Pointer to HBA context object.
12503 * @wcqe: Pointer to work-queue completion queue entry.
12505 * This routine handles an ELS work-queue completion event and construct
12506 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
12507 * discovery engine to handle.
12509 * Return: Pointer to the receive IOCBQ, NULL otherwise.
12511 static struct lpfc_iocbq
*
12512 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
12513 struct lpfc_iocbq
*irspiocbq
)
12515 struct lpfc_sli_ring
*pring
;
12516 struct lpfc_iocbq
*cmdiocbq
;
12517 struct lpfc_wcqe_complete
*wcqe
;
12518 unsigned long iflags
;
12520 pring
= lpfc_phba_elsring(phba
);
12521 if (unlikely(!pring
))
12524 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
12525 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
12526 pring
->stats
.iocb_event
++;
12527 /* Look up the ELS command IOCB and create pseudo response IOCB */
12528 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
12529 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12530 if (unlikely(!cmdiocbq
)) {
12531 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12532 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12533 "0386 ELS complete with no corresponding "
12534 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
12535 wcqe
->word0
, wcqe
->total_data_placed
,
12536 wcqe
->parameter
, wcqe
->word3
);
12537 lpfc_sli_release_iocbq(phba
, irspiocbq
);
12541 /* Put the iocb back on the txcmplq */
12542 lpfc_sli_ringtxcmpl_put(phba
, pring
, cmdiocbq
);
12543 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12545 /* Fake the irspiocbq and copy necessary response information */
12546 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
12552 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
12553 * @phba: Pointer to HBA context object.
12554 * @cqe: Pointer to mailbox completion queue entry.
12556 * This routine process a mailbox completion queue entry with asynchrous
12559 * Return: true if work posted to worker thread, otherwise false.
12562 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
12564 struct lpfc_cq_event
*cq_event
;
12565 unsigned long iflags
;
12567 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
12568 "0392 Async Event: word0:x%x, word1:x%x, "
12569 "word2:x%x, word3:x%x\n", mcqe
->word0
,
12570 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
12572 /* Allocate a new internal CQ_EVENT entry */
12573 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
12575 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12576 "0394 Failed to allocate CQ_EVENT entry\n");
12580 /* Move the CQE into an asynchronous event entry */
12581 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
12582 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12583 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
12584 /* Set the async event flag */
12585 phba
->hba_flag
|= ASYNC_EVENT
;
12586 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12592 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
12593 * @phba: Pointer to HBA context object.
12594 * @cqe: Pointer to mailbox completion queue entry.
12596 * This routine process a mailbox completion queue entry with mailbox
12597 * completion event.
12599 * Return: true if work posted to worker thread, otherwise false.
12602 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
12604 uint32_t mcqe_status
;
12605 MAILBOX_t
*mbox
, *pmbox
;
12606 struct lpfc_mqe
*mqe
;
12607 struct lpfc_vport
*vport
;
12608 struct lpfc_nodelist
*ndlp
;
12609 struct lpfc_dmabuf
*mp
;
12610 unsigned long iflags
;
12612 bool workposted
= false;
12615 /* If not a mailbox complete MCQE, out by checking mailbox consume */
12616 if (!bf_get(lpfc_trailer_completed
, mcqe
))
12617 goto out_no_mqe_complete
;
12619 /* Get the reference to the active mbox command */
12620 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12621 pmb
= phba
->sli
.mbox_active
;
12622 if (unlikely(!pmb
)) {
12623 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
12624 "1832 No pending MBOX command to handle\n");
12625 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12626 goto out_no_mqe_complete
;
12628 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12630 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
12632 vport
= pmb
->vport
;
12634 /* Reset heartbeat timer */
12635 phba
->last_completion_time
= jiffies
;
12636 del_timer(&phba
->sli
.mbox_tmo
);
12638 /* Move mbox data to caller's mailbox region, do endian swapping */
12639 if (pmb
->mbox_cmpl
&& mbox
)
12640 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
12643 * For mcqe errors, conditionally move a modified error code to
12644 * the mbox so that the error will not be missed.
12646 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
12647 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
12648 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
12649 bf_set(lpfc_mqe_status
, mqe
,
12650 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
12652 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
12653 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
12654 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
12655 "MBOX dflt rpi: status:x%x rpi:x%x",
12657 pmbox
->un
.varWords
[0], 0);
12658 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
12659 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
12660 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
12661 /* Reg_LOGIN of dflt RPI was successful. Now lets get
12662 * RID of the PPI using the same mbox buffer.
12664 lpfc_unreg_login(phba
, vport
->vpi
,
12665 pmbox
->un
.varWords
[0], pmb
);
12666 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
12667 pmb
->context1
= mp
;
12668 pmb
->context2
= ndlp
;
12669 pmb
->vport
= vport
;
12670 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
12671 if (rc
!= MBX_BUSY
)
12672 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12673 LOG_SLI
, "0385 rc should "
12674 "have been MBX_BUSY\n");
12675 if (rc
!= MBX_NOT_FINISHED
)
12676 goto send_current_mbox
;
12679 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
12680 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
12681 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
12683 /* There is mailbox completion work to do */
12684 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12685 __lpfc_mbox_cmpl_put(phba
, pmb
);
12686 phba
->work_ha
|= HA_MBATT
;
12687 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12691 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12692 /* Release the mailbox command posting token */
12693 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
12694 /* Setting active mailbox pointer need to be in sync to flag clear */
12695 phba
->sli
.mbox_active
= NULL
;
12696 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12697 /* Wake up worker thread to post the next pending mailbox command */
12698 lpfc_worker_wake_up(phba
);
12699 out_no_mqe_complete
:
12700 if (bf_get(lpfc_trailer_consumed
, mcqe
))
12701 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
12706 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
12707 * @phba: Pointer to HBA context object.
12708 * @cqe: Pointer to mailbox completion queue entry.
12710 * This routine process a mailbox completion queue entry, it invokes the
12711 * proper mailbox complete handling or asynchrous event handling routine
12712 * according to the MCQE's async bit.
12714 * Return: true if work posted to worker thread, otherwise false.
12717 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
12719 struct lpfc_mcqe mcqe
;
12722 /* Copy the mailbox MCQE and convert endian order as needed */
12723 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
12725 /* Invoke the proper event handling routine */
12726 if (!bf_get(lpfc_trailer_async
, &mcqe
))
12727 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
12729 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
12734 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
12735 * @phba: Pointer to HBA context object.
12736 * @cq: Pointer to associated CQ
12737 * @wcqe: Pointer to work-queue completion queue entry.
12739 * This routine handles an ELS work-queue completion event.
12741 * Return: true if work posted to worker thread, otherwise false.
12744 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12745 struct lpfc_wcqe_complete
*wcqe
)
12747 struct lpfc_iocbq
*irspiocbq
;
12748 unsigned long iflags
;
12749 struct lpfc_sli_ring
*pring
= cq
->pring
;
12751 int txcmplq_cnt
= 0;
12752 int fcp_txcmplq_cnt
= 0;
12754 /* Get an irspiocbq for later ELS response processing use */
12755 irspiocbq
= lpfc_sli_get_iocbq(phba
);
12757 if (!list_empty(&pring
->txq
))
12759 if (!list_empty(&pring
->txcmplq
))
12761 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12762 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
12763 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
12764 txq_cnt
, phba
->iocb_cnt
,
12770 /* Save off the slow-path queue event for work thread to process */
12771 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
12772 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12773 list_add_tail(&irspiocbq
->cq_event
.list
,
12774 &phba
->sli4_hba
.sp_queue_event
);
12775 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12776 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12782 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
12783 * @phba: Pointer to HBA context object.
12784 * @wcqe: Pointer to work-queue completion queue entry.
12786 * This routine handles slow-path WQ entry consumed event by invoking the
12787 * proper WQ release routine to the slow-path WQ.
12790 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
12791 struct lpfc_wcqe_release
*wcqe
)
12793 /* sanity check on queue memory */
12794 if (unlikely(!phba
->sli4_hba
.els_wq
))
12796 /* Check for the slow-path ELS work queue */
12797 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
12798 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
12799 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
12801 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12802 "2579 Slow-path wqe consume event carries "
12803 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
12804 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
12805 phba
->sli4_hba
.els_wq
->queue_id
);
12809 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
12810 * @phba: Pointer to HBA context object.
12811 * @cq: Pointer to a WQ completion queue.
12812 * @wcqe: Pointer to work-queue completion queue entry.
12814 * This routine handles an XRI abort event.
12816 * Return: true if work posted to worker thread, otherwise false.
12819 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
12820 struct lpfc_queue
*cq
,
12821 struct sli4_wcqe_xri_aborted
*wcqe
)
12823 bool workposted
= false;
12824 struct lpfc_cq_event
*cq_event
;
12825 unsigned long iflags
;
12827 /* Allocate a new internal CQ_EVENT entry */
12828 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
12830 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12831 "0602 Failed to allocate CQ_EVENT entry\n");
12835 /* Move the CQE into the proper xri abort event list */
12836 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
12837 switch (cq
->subtype
) {
12839 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12840 list_add_tail(&cq_event
->list
,
12841 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
12842 /* Set the fcp xri abort event flag */
12843 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
12844 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12848 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12849 list_add_tail(&cq_event
->list
,
12850 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
12851 /* Set the els xri abort event flag */
12852 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
12853 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12857 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12858 list_add_tail(&cq_event
->list
,
12859 &phba
->sli4_hba
.sp_nvme_xri_aborted_work_queue
);
12860 /* Set the nvme xri abort event flag */
12861 phba
->hba_flag
|= NVME_XRI_ABORT_EVENT
;
12862 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12866 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12867 "0603 Invalid CQ subtype %d: "
12868 "%08x %08x %08x %08x\n",
12869 cq
->subtype
, wcqe
->word0
, wcqe
->parameter
,
12870 wcqe
->word2
, wcqe
->word3
);
12871 lpfc_sli4_cq_event_release(phba
, cq_event
);
12872 workposted
= false;
12879 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
12880 * @phba: Pointer to HBA context object.
12881 * @rcqe: Pointer to receive-queue completion queue entry.
12883 * This routine process a receive-queue completion queue entry.
12885 * Return: true if work posted to worker thread, otherwise false.
12888 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
12890 bool workposted
= false;
12891 struct fc_frame_header
*fc_hdr
;
12892 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
12893 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
12894 struct lpfc_nvmet_tgtport
*tgtp
;
12895 struct hbq_dmabuf
*dma_buf
;
12896 uint32_t status
, rq_id
;
12897 unsigned long iflags
;
12899 /* sanity check on queue memory */
12900 if (unlikely(!hrq
) || unlikely(!drq
))
12903 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
12904 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
12906 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
12907 if (rq_id
!= hrq
->queue_id
)
12910 status
= bf_get(lpfc_rcqe_status
, rcqe
);
12912 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
12913 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12914 "2537 Receive Frame Truncated!!\n");
12915 case FC_STATUS_RQ_SUCCESS
:
12916 lpfc_sli4_rq_release(hrq
, drq
);
12917 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12918 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
12920 hrq
->RQ_no_buf_found
++;
12921 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12925 hrq
->RQ_buf_posted
--;
12926 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
12928 /* If a NVME LS event (type 0x28), treat it as Fast path */
12929 fc_hdr
= (struct fc_frame_header
*)dma_buf
->hbuf
.virt
;
12931 /* save off the frame for the word thread to process */
12932 list_add_tail(&dma_buf
->cq_event
.list
,
12933 &phba
->sli4_hba
.sp_queue_event
);
12934 /* Frame received */
12935 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12936 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12939 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
12940 if (phba
->nvmet_support
) {
12941 tgtp
= phba
->targetport
->private;
12942 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_NVME
,
12943 "6402 RQE Error x%x, posted %d err_cnt "
12945 status
, hrq
->RQ_buf_posted
,
12946 hrq
->RQ_no_posted_buf
,
12947 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
12948 atomic_read(&tgtp
->rcv_fcp_cmd_out
),
12949 atomic_read(&tgtp
->xmt_fcp_release
));
12953 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
12954 hrq
->RQ_no_posted_buf
++;
12955 /* Post more buffers if possible */
12956 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12957 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
12958 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12967 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
12968 * @phba: Pointer to HBA context object.
12969 * @cq: Pointer to the completion queue.
12970 * @wcqe: Pointer to a completion queue entry.
12972 * This routine process a slow-path work-queue or receive queue completion queue
12975 * Return: true if work posted to worker thread, otherwise false.
12978 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12979 struct lpfc_cqe
*cqe
)
12981 struct lpfc_cqe cqevt
;
12982 bool workposted
= false;
12984 /* Copy the work queue CQE and convert endian order if needed */
12985 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
12987 /* Check and process for different type of WCQE and dispatch */
12988 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
12989 case CQE_CODE_COMPL_WQE
:
12990 /* Process the WQ/RQ complete event */
12991 phba
->last_completion_time
= jiffies
;
12992 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
12993 (struct lpfc_wcqe_complete
*)&cqevt
);
12995 case CQE_CODE_RELEASE_WQE
:
12996 /* Process the WQ release event */
12997 lpfc_sli4_sp_handle_rel_wcqe(phba
,
12998 (struct lpfc_wcqe_release
*)&cqevt
);
13000 case CQE_CODE_XRI_ABORTED
:
13001 /* Process the WQ XRI abort event */
13002 phba
->last_completion_time
= jiffies
;
13003 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
13004 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
13006 case CQE_CODE_RECEIVE
:
13007 case CQE_CODE_RECEIVE_V1
:
13008 /* Process the RQ event */
13009 phba
->last_completion_time
= jiffies
;
13010 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
13011 (struct lpfc_rcqe
*)&cqevt
);
13014 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13015 "0388 Not a valid WCQE code: x%x\n",
13016 bf_get(lpfc_cqe_code
, &cqevt
));
13023 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
13024 * @phba: Pointer to HBA context object.
13025 * @eqe: Pointer to fast-path event queue entry.
13027 * This routine process a event queue entry from the slow-path event queue.
13028 * It will check the MajorCode and MinorCode to determine this is for a
13029 * completion event on a completion queue, if not, an error shall be logged
13030 * and just return. Otherwise, it will get to the corresponding completion
13031 * queue and process all the entries on that completion queue, rearm the
13032 * completion queue, and then return.
13036 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
13037 struct lpfc_queue
*speq
)
13039 struct lpfc_queue
*cq
= NULL
, *childq
;
13042 /* Get the reference to the corresponding CQ */
13043 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13045 list_for_each_entry(childq
, &speq
->child_list
, list
) {
13046 if (childq
->queue_id
== cqid
) {
13051 if (unlikely(!cq
)) {
13052 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
13053 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13054 "0365 Slow-path CQ identifier "
13055 "(%d) does not exist\n", cqid
);
13059 /* Save EQ associated with this CQ */
13060 cq
->assoc_qp
= speq
;
13062 if (!queue_work(phba
->wq
, &cq
->spwork
))
13063 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13064 "0390 Cannot schedule soft IRQ "
13065 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13066 cqid
, cq
->queue_id
, smp_processor_id());
13070 * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
13071 * @phba: Pointer to HBA context object.
13073 * This routine process a event queue entry from the slow-path event queue.
13074 * It will check the MajorCode and MinorCode to determine this is for a
13075 * completion event on a completion queue, if not, an error shall be logged
13076 * and just return. Otherwise, it will get to the corresponding completion
13077 * queue and process all the entries on that completion queue, rearm the
13078 * completion queue, and then return.
13082 lpfc_sli4_sp_process_cq(struct work_struct
*work
)
13084 struct lpfc_queue
*cq
=
13085 container_of(work
, struct lpfc_queue
, spwork
);
13086 struct lpfc_hba
*phba
= cq
->phba
;
13087 struct lpfc_cqe
*cqe
;
13088 bool workposted
= false;
13091 /* Process all the entries to the CQ */
13092 switch (cq
->type
) {
13094 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13095 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
13096 if (!(++ccount
% cq
->entry_repost
))
13102 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13103 if (cq
->subtype
== LPFC_FCP
||
13104 cq
->subtype
== LPFC_NVME
) {
13105 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13106 if (phba
->ktime_on
)
13107 cq
->isr_timestamp
= ktime_get_ns();
13109 cq
->isr_timestamp
= 0;
13111 workposted
|= lpfc_sli4_fp_handle_cqe(phba
, cq
,
13114 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
13117 if (!(++ccount
% cq
->entry_repost
))
13121 /* Track the max number of CQEs processed in 1 EQ */
13122 if (ccount
> cq
->CQ_max_cqe
)
13123 cq
->CQ_max_cqe
= ccount
;
13126 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13127 "0370 Invalid completion queue type (%d)\n",
13132 /* Catch the no cq entry condition, log an error */
13133 if (unlikely(ccount
== 0))
13134 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13135 "0371 No entry from the CQ: identifier "
13136 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
13138 /* In any case, flash and re-arm the RCQ */
13139 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
13141 /* wake up worker thread if there are works to be done */
13143 lpfc_worker_wake_up(phba
);
13147 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
13148 * @phba: Pointer to HBA context object.
13149 * @cq: Pointer to associated CQ
13150 * @wcqe: Pointer to work-queue completion queue entry.
13152 * This routine process a fast-path work queue completion entry from fast-path
13153 * event queue for FCP command response completion.
13156 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13157 struct lpfc_wcqe_complete
*wcqe
)
13159 struct lpfc_sli_ring
*pring
= cq
->pring
;
13160 struct lpfc_iocbq
*cmdiocbq
;
13161 struct lpfc_iocbq irspiocbq
;
13162 unsigned long iflags
;
13164 /* Check for response status */
13165 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
13166 /* If resource errors reported from HBA, reduce queue
13167 * depth of the SCSI device.
13169 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
13170 IOSTAT_LOCAL_REJECT
)) &&
13171 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
13172 IOERR_NO_RESOURCES
))
13173 phba
->lpfc_rampdown_queue_depth(phba
);
13175 /* Log the error status */
13176 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13177 "0373 FCP complete error: status=x%x, "
13178 "hw_status=x%x, total_data_specified=%d, "
13179 "parameter=x%x, word3=x%x\n",
13180 bf_get(lpfc_wcqe_c_status
, wcqe
),
13181 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
13182 wcqe
->total_data_placed
, wcqe
->parameter
,
13186 /* Look up the FCP command IOCB and create pseudo response IOCB */
13187 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
13188 pring
->stats
.iocb_event
++;
13189 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
13190 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13191 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
13192 if (unlikely(!cmdiocbq
)) {
13193 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13194 "0374 FCP complete with no corresponding "
13195 "cmdiocb: iotag (%d)\n",
13196 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13199 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13200 cmdiocbq
->isr_timestamp
= cq
->isr_timestamp
;
13202 if (cmdiocbq
->iocb_cmpl
== NULL
) {
13203 if (cmdiocbq
->wqe_cmpl
) {
13204 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
13205 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13206 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
13207 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13210 /* Pass the cmd_iocb and the wcqe to the upper layer */
13211 (cmdiocbq
->wqe_cmpl
)(phba
, cmdiocbq
, wcqe
);
13214 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13215 "0375 FCP cmdiocb not callback function "
13217 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13221 /* Fake the irspiocb and copy necessary response information */
13222 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
13224 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
13225 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13226 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
13227 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13230 /* Pass the cmd_iocb and the rsp state to the upper layer */
13231 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
13235 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
13236 * @phba: Pointer to HBA context object.
13237 * @cq: Pointer to completion queue.
13238 * @wcqe: Pointer to work-queue completion queue entry.
13240 * This routine handles an fast-path WQ entry consumed event by invoking the
13241 * proper WQ release routine to the slow-path WQ.
13244 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13245 struct lpfc_wcqe_release
*wcqe
)
13247 struct lpfc_queue
*childwq
;
13248 bool wqid_matched
= false;
13251 /* Check for fast-path FCP work queue release */
13252 hba_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
13253 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
13254 if (childwq
->queue_id
== hba_wqid
) {
13255 lpfc_sli4_wq_release(childwq
,
13256 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
13257 wqid_matched
= true;
13261 /* Report warning log message if no match found */
13262 if (wqid_matched
!= true)
13263 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13264 "2580 Fast-path wqe consume event carries "
13265 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid
);
13269 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
13270 * @phba: Pointer to HBA context object.
13271 * @rcqe: Pointer to receive-queue completion queue entry.
13273 * This routine process a receive-queue completion queue entry.
13275 * Return: true if work posted to worker thread, otherwise false.
13278 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13279 struct lpfc_rcqe
*rcqe
)
13281 bool workposted
= false;
13282 struct lpfc_queue
*hrq
;
13283 struct lpfc_queue
*drq
;
13284 struct rqb_dmabuf
*dma_buf
;
13285 struct fc_frame_header
*fc_hdr
;
13286 struct lpfc_nvmet_tgtport
*tgtp
;
13287 uint32_t status
, rq_id
;
13288 unsigned long iflags
;
13289 uint32_t fctl
, idx
;
13291 if ((phba
->nvmet_support
== 0) ||
13292 (phba
->sli4_hba
.nvmet_cqset
== NULL
))
13295 idx
= cq
->queue_id
- phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
;
13296 hrq
= phba
->sli4_hba
.nvmet_mrq_hdr
[idx
];
13297 drq
= phba
->sli4_hba
.nvmet_mrq_data
[idx
];
13299 /* sanity check on queue memory */
13300 if (unlikely(!hrq
) || unlikely(!drq
))
13303 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
13304 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
13306 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
13308 if ((phba
->nvmet_support
== 0) ||
13309 (rq_id
!= hrq
->queue_id
))
13312 status
= bf_get(lpfc_rcqe_status
, rcqe
);
13314 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
13315 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13316 "6126 Receive Frame Truncated!!\n");
13318 case FC_STATUS_RQ_SUCCESS
:
13319 lpfc_sli4_rq_release(hrq
, drq
);
13320 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13321 dma_buf
= lpfc_sli_rqbuf_get(phba
, hrq
);
13323 hrq
->RQ_no_buf_found
++;
13324 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13327 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13329 hrq
->RQ_buf_posted
--;
13330 fc_hdr
= (struct fc_frame_header
*)dma_buf
->hbuf
.virt
;
13332 /* Just some basic sanity checks on FCP Command frame */
13333 fctl
= (fc_hdr
->fh_f_ctl
[0] << 16 |
13334 fc_hdr
->fh_f_ctl
[1] << 8 |
13335 fc_hdr
->fh_f_ctl
[2]);
13337 (FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
)) !=
13338 (FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
)) ||
13339 (fc_hdr
->fh_seq_cnt
!= 0)) /* 0 byte swapped is still 0 */
13342 if (fc_hdr
->fh_type
== FC_TYPE_FCP
) {
13343 dma_buf
->bytes_recv
= bf_get(lpfc_rcqe_length
, rcqe
);
13344 lpfc_nvmet_unsol_fcp_event(
13345 phba
, idx
, dma_buf
,
13346 cq
->isr_timestamp
);
13350 lpfc_in_buf_free(phba
, &dma_buf
->dbuf
);
13352 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
13353 if (phba
->nvmet_support
) {
13354 tgtp
= phba
->targetport
->private;
13355 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_NVME
,
13356 "6401 RQE Error x%x, posted %d err_cnt "
13358 status
, hrq
->RQ_buf_posted
,
13359 hrq
->RQ_no_posted_buf
,
13360 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
13361 atomic_read(&tgtp
->rcv_fcp_cmd_out
),
13362 atomic_read(&tgtp
->xmt_fcp_release
));
13366 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
13367 hrq
->RQ_no_posted_buf
++;
13368 /* Post more buffers if possible */
13376 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
13377 * @cq: Pointer to the completion queue.
13378 * @eqe: Pointer to fast-path completion queue entry.
13380 * This routine process a fast-path work queue completion entry from fast-path
13381 * event queue for FCP command response completion.
13384 lpfc_sli4_fp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13385 struct lpfc_cqe
*cqe
)
13387 struct lpfc_wcqe_release wcqe
;
13388 bool workposted
= false;
13390 /* Copy the work queue CQE and convert endian order if needed */
13391 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
13393 /* Check and process for different type of WCQE and dispatch */
13394 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
13395 case CQE_CODE_COMPL_WQE
:
13396 case CQE_CODE_NVME_ERSP
:
13398 /* Process the WQ complete event */
13399 phba
->last_completion_time
= jiffies
;
13400 if ((cq
->subtype
== LPFC_FCP
) || (cq
->subtype
== LPFC_NVME
))
13401 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
13402 (struct lpfc_wcqe_complete
*)&wcqe
);
13403 if (cq
->subtype
== LPFC_NVME_LS
)
13404 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
13405 (struct lpfc_wcqe_complete
*)&wcqe
);
13407 case CQE_CODE_RELEASE_WQE
:
13408 cq
->CQ_release_wqe
++;
13409 /* Process the WQ release event */
13410 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
13411 (struct lpfc_wcqe_release
*)&wcqe
);
13413 case CQE_CODE_XRI_ABORTED
:
13414 cq
->CQ_xri_aborted
++;
13415 /* Process the WQ XRI abort event */
13416 phba
->last_completion_time
= jiffies
;
13417 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
13418 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
13420 case CQE_CODE_RECEIVE_V1
:
13421 case CQE_CODE_RECEIVE
:
13422 phba
->last_completion_time
= jiffies
;
13423 if (cq
->subtype
== LPFC_NVMET
) {
13424 workposted
= lpfc_sli4_nvmet_handle_rcqe(
13425 phba
, cq
, (struct lpfc_rcqe
*)&wcqe
);
13429 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13430 "0144 Not a valid CQE code: x%x\n",
13431 bf_get(lpfc_wcqe_c_code
, &wcqe
));
13438 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
13439 * @phba: Pointer to HBA context object.
13440 * @eqe: Pointer to fast-path event queue entry.
13442 * This routine process a event queue entry from the fast-path event queue.
13443 * It will check the MajorCode and MinorCode to determine this is for a
13444 * completion event on a completion queue, if not, an error shall be logged
13445 * and just return. Otherwise, it will get to the corresponding completion
13446 * queue and process all the entries on the completion queue, rearm the
13447 * completion queue, and then return.
13450 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
13453 struct lpfc_queue
*cq
= NULL
;
13456 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
13457 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13458 "0366 Not a valid completion "
13459 "event: majorcode=x%x, minorcode=x%x\n",
13460 bf_get_le32(lpfc_eqe_major_code
, eqe
),
13461 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
13465 /* Get the reference to the corresponding CQ */
13466 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13468 if (phba
->cfg_nvmet_mrq
&& phba
->sli4_hba
.nvmet_cqset
) {
13469 id
= phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
;
13470 if ((cqid
>= id
) && (cqid
< (id
+ phba
->cfg_nvmet_mrq
))) {
13471 /* Process NVMET unsol rcv */
13472 cq
= phba
->sli4_hba
.nvmet_cqset
[cqid
- id
];
13477 if (phba
->sli4_hba
.nvme_cq_map
&&
13478 (cqid
== phba
->sli4_hba
.nvme_cq_map
[qidx
])) {
13479 /* Process NVME / NVMET command completion */
13480 cq
= phba
->sli4_hba
.nvme_cq
[qidx
];
13484 if (phba
->sli4_hba
.fcp_cq_map
&&
13485 (cqid
== phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
13486 /* Process FCP command completion */
13487 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
13491 if (phba
->sli4_hba
.nvmels_cq
&&
13492 (cqid
== phba
->sli4_hba
.nvmels_cq
->queue_id
)) {
13493 /* Process NVME unsol rcv */
13494 cq
= phba
->sli4_hba
.nvmels_cq
;
13497 /* Otherwise this is a Slow path event */
13499 lpfc_sli4_sp_handle_eqe(phba
, eqe
, phba
->sli4_hba
.hba_eq
[qidx
]);
13504 if (unlikely(cqid
!= cq
->queue_id
)) {
13505 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13506 "0368 Miss-matched fast-path completion "
13507 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
13508 cqid
, cq
->queue_id
);
13512 /* Save EQ associated with this CQ */
13513 cq
->assoc_qp
= phba
->sli4_hba
.hba_eq
[qidx
];
13515 if (!queue_work(phba
->wq
, &cq
->irqwork
))
13516 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13517 "0363 Cannot schedule soft IRQ "
13518 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13519 cqid
, cq
->queue_id
, smp_processor_id());
13523 * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
13524 * @phba: Pointer to HBA context object.
13525 * @eqe: Pointer to fast-path event queue entry.
13527 * This routine process a event queue entry from the fast-path event queue.
13528 * It will check the MajorCode and MinorCode to determine this is for a
13529 * completion event on a completion queue, if not, an error shall be logged
13530 * and just return. Otherwise, it will get to the corresponding completion
13531 * queue and process all the entries on the completion queue, rearm the
13532 * completion queue, and then return.
13535 lpfc_sli4_hba_process_cq(struct work_struct
*work
)
13537 struct lpfc_queue
*cq
=
13538 container_of(work
, struct lpfc_queue
, irqwork
);
13539 struct lpfc_hba
*phba
= cq
->phba
;
13540 struct lpfc_cqe
*cqe
;
13541 bool workposted
= false;
13544 /* Process all the entries to the CQ */
13545 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13546 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13547 if (phba
->ktime_on
)
13548 cq
->isr_timestamp
= ktime_get_ns();
13550 cq
->isr_timestamp
= 0;
13552 workposted
|= lpfc_sli4_fp_handle_cqe(phba
, cq
, cqe
);
13553 if (!(++ccount
% cq
->entry_repost
))
13557 /* Track the max number of CQEs processed in 1 EQ */
13558 if (ccount
> cq
->CQ_max_cqe
)
13559 cq
->CQ_max_cqe
= ccount
;
13560 cq
->assoc_qp
->EQ_cqe_cnt
+= ccount
;
13562 /* Catch the no cq entry condition */
13563 if (unlikely(ccount
== 0))
13564 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13565 "0369 No entry from fast-path completion "
13566 "queue fcpcqid=%d\n", cq
->queue_id
);
13568 /* In any case, flash and re-arm the CQ */
13569 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
13571 /* wake up worker thread if there are works to be done */
13573 lpfc_worker_wake_up(phba
);
13577 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
13579 struct lpfc_eqe
*eqe
;
13581 /* walk all the EQ entries and drop on the floor */
13582 while ((eqe
= lpfc_sli4_eq_get(eq
)))
13585 /* Clear and re-arm the EQ */
13586 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
13591 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
13593 * @phba: Pointer to HBA context object.
13594 * @eqe: Pointer to fast-path event queue entry.
13596 * This routine process a event queue entry from the Flash Optimized Fabric
13597 * event queue. It will check the MajorCode and MinorCode to determine this
13598 * is for a completion event on a completion queue, if not, an error shall be
13599 * logged and just return. Otherwise, it will get to the corresponding
13600 * completion queue and process all the entries on the completion queue, rearm
13601 * the completion queue, and then return.
13604 lpfc_sli4_fof_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
13606 struct lpfc_queue
*cq
;
13609 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
13610 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13611 "9147 Not a valid completion "
13612 "event: majorcode=x%x, minorcode=x%x\n",
13613 bf_get_le32(lpfc_eqe_major_code
, eqe
),
13614 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
13618 /* Get the reference to the corresponding CQ */
13619 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13621 /* Next check for OAS */
13622 cq
= phba
->sli4_hba
.oas_cq
;
13623 if (unlikely(!cq
)) {
13624 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
13625 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13626 "9148 OAS completion queue "
13627 "does not exist\n");
13631 if (unlikely(cqid
!= cq
->queue_id
)) {
13632 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13633 "9149 Miss-matched fast-path compl "
13634 "queue id: eqcqid=%d, fcpcqid=%d\n",
13635 cqid
, cq
->queue_id
);
13639 /* Save EQ associated with this CQ */
13640 cq
->assoc_qp
= phba
->sli4_hba
.fof_eq
;
13642 /* CQ work will be processed on CPU affinitized to this IRQ */
13643 if (!queue_work(phba
->wq
, &cq
->irqwork
))
13644 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13645 "0367 Cannot schedule soft IRQ "
13646 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13647 cqid
, cq
->queue_id
, smp_processor_id());
13651 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
13652 * @irq: Interrupt number.
13653 * @dev_id: The device context pointer.
13655 * This function is directly called from the PCI layer as an interrupt
13656 * service routine when device with SLI-4 interface spec is enabled with
13657 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
13658 * IOCB ring event in the HBA. However, when the device is enabled with either
13659 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13660 * device-level interrupt handler. When the PCI slot is in error recovery
13661 * or the HBA is undergoing initialization, the interrupt handler will not
13662 * process the interrupt. The Flash Optimized Fabric ring event are handled in
13663 * the intrrupt context. This function is called without any lock held.
13664 * It gets the hbalock to access and update SLI data structures. Note that,
13665 * the EQ to CQ are one-to-one map such that the EQ index is
13666 * equal to that of CQ index.
13668 * This function returns IRQ_HANDLED when interrupt is handled else it
13669 * returns IRQ_NONE.
13672 lpfc_sli4_fof_intr_handler(int irq
, void *dev_id
)
13674 struct lpfc_hba
*phba
;
13675 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
13676 struct lpfc_queue
*eq
;
13677 struct lpfc_eqe
*eqe
;
13678 unsigned long iflag
;
13681 /* Get the driver's phba structure from the dev_id */
13682 hba_eq_hdl
= (struct lpfc_hba_eq_hdl
*)dev_id
;
13683 phba
= hba_eq_hdl
->phba
;
13685 if (unlikely(!phba
))
13688 /* Get to the EQ struct associated with this vector */
13689 eq
= phba
->sli4_hba
.fof_eq
;
13693 /* Check device state for handling interrupt */
13694 if (unlikely(lpfc_intr_state_check(phba
))) {
13695 /* Check again for link_state with lock held */
13696 spin_lock_irqsave(&phba
->hbalock
, iflag
);
13697 if (phba
->link_state
< LPFC_LINK_DOWN
)
13698 /* Flush, clear interrupt, and rearm the EQ */
13699 lpfc_sli4_eq_flush(phba
, eq
);
13700 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
13705 * Process all the event on FCP fast-path EQ
13707 while ((eqe
= lpfc_sli4_eq_get(eq
))) {
13708 lpfc_sli4_fof_handle_eqe(phba
, eqe
);
13709 if (!(++ecount
% eq
->entry_repost
))
13711 eq
->EQ_processed
++;
13714 /* Track the max number of EQEs processed in 1 intr */
13715 if (ecount
> eq
->EQ_max_eqe
)
13716 eq
->EQ_max_eqe
= ecount
;
13719 if (unlikely(ecount
== 0)) {
13722 if (phba
->intr_type
== MSIX
)
13723 /* MSI-X treated interrupt served as no EQ share INT */
13724 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13725 "9145 MSI-X interrupt with no EQE\n");
13727 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13728 "9146 ISR interrupt with no EQE\n");
13729 /* Non MSI-X treated on interrupt as EQ share INT */
13733 /* Always clear and re-arm the fast-path EQ */
13734 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
13735 return IRQ_HANDLED
;
13739 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
13740 * @irq: Interrupt number.
13741 * @dev_id: The device context pointer.
13743 * This function is directly called from the PCI layer as an interrupt
13744 * service routine when device with SLI-4 interface spec is enabled with
13745 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13746 * ring event in the HBA. However, when the device is enabled with either
13747 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13748 * device-level interrupt handler. When the PCI slot is in error recovery
13749 * or the HBA is undergoing initialization, the interrupt handler will not
13750 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13751 * the intrrupt context. This function is called without any lock held.
13752 * It gets the hbalock to access and update SLI data structures. Note that,
13753 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
13754 * equal to that of FCP CQ index.
13756 * The link attention and ELS ring attention events are handled
13757 * by the worker thread. The interrupt handler signals the worker thread
13758 * and returns for these events. This function is called without any lock
13759 * held. It gets the hbalock to access and update SLI data structures.
13761 * This function returns IRQ_HANDLED when interrupt is handled else it
13762 * returns IRQ_NONE.
13765 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
13767 struct lpfc_hba
*phba
;
13768 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
13769 struct lpfc_queue
*fpeq
;
13770 struct lpfc_eqe
*eqe
;
13771 unsigned long iflag
;
13775 /* Get the driver's phba structure from the dev_id */
13776 hba_eq_hdl
= (struct lpfc_hba_eq_hdl
*)dev_id
;
13777 phba
= hba_eq_hdl
->phba
;
13778 hba_eqidx
= hba_eq_hdl
->idx
;
13780 if (unlikely(!phba
))
13782 if (unlikely(!phba
->sli4_hba
.hba_eq
))
13785 /* Get to the EQ struct associated with this vector */
13786 fpeq
= phba
->sli4_hba
.hba_eq
[hba_eqidx
];
13787 if (unlikely(!fpeq
))
13790 if (lpfc_fcp_look_ahead
) {
13791 if (atomic_dec_and_test(&hba_eq_hdl
->hba_eq_in_use
))
13792 lpfc_sli4_eq_clr_intr(fpeq
);
13794 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13799 /* Check device state for handling interrupt */
13800 if (unlikely(lpfc_intr_state_check(phba
))) {
13801 /* Check again for link_state with lock held */
13802 spin_lock_irqsave(&phba
->hbalock
, iflag
);
13803 if (phba
->link_state
< LPFC_LINK_DOWN
)
13804 /* Flush, clear interrupt, and rearm the EQ */
13805 lpfc_sli4_eq_flush(phba
, fpeq
);
13806 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
13807 if (lpfc_fcp_look_ahead
)
13808 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13813 * Process all the event on FCP fast-path EQ
13815 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
13816 lpfc_sli4_hba_handle_eqe(phba
, eqe
, hba_eqidx
);
13817 if (!(++ecount
% fpeq
->entry_repost
))
13819 fpeq
->EQ_processed
++;
13822 /* Track the max number of EQEs processed in 1 intr */
13823 if (ecount
> fpeq
->EQ_max_eqe
)
13824 fpeq
->EQ_max_eqe
= ecount
;
13826 /* Always clear and re-arm the fast-path EQ */
13827 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
13829 if (unlikely(ecount
== 0)) {
13830 fpeq
->EQ_no_entry
++;
13832 if (lpfc_fcp_look_ahead
) {
13833 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13837 if (phba
->intr_type
== MSIX
)
13838 /* MSI-X treated interrupt served as no EQ share INT */
13839 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13840 "0358 MSI-X interrupt with no EQE\n");
13842 /* Non MSI-X treated on interrupt as EQ share INT */
13846 if (lpfc_fcp_look_ahead
)
13847 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13849 return IRQ_HANDLED
;
13850 } /* lpfc_sli4_fp_intr_handler */
13853 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
13854 * @irq: Interrupt number.
13855 * @dev_id: The device context pointer.
13857 * This function is the device-level interrupt handler to device with SLI-4
13858 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
13859 * interrupt mode is enabled and there is an event in the HBA which requires
13860 * driver attention. This function invokes the slow-path interrupt attention
13861 * handling function and fast-path interrupt attention handling function in
13862 * turn to process the relevant HBA attention events. This function is called
13863 * without any lock held. It gets the hbalock to access and update SLI data
13866 * This function returns IRQ_HANDLED when interrupt is handled, else it
13867 * returns IRQ_NONE.
13870 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
13872 struct lpfc_hba
*phba
;
13873 irqreturn_t hba_irq_rc
;
13874 bool hba_handled
= false;
13877 /* Get the driver's phba structure from the dev_id */
13878 phba
= (struct lpfc_hba
*)dev_id
;
13880 if (unlikely(!phba
))
13884 * Invoke fast-path host attention interrupt handling as appropriate.
13886 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++) {
13887 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
13888 &phba
->sli4_hba
.hba_eq_hdl
[qidx
]);
13889 if (hba_irq_rc
== IRQ_HANDLED
)
13890 hba_handled
|= true;
13893 if (phba
->cfg_fof
) {
13894 hba_irq_rc
= lpfc_sli4_fof_intr_handler(irq
,
13895 &phba
->sli4_hba
.hba_eq_hdl
[qidx
]);
13896 if (hba_irq_rc
== IRQ_HANDLED
)
13897 hba_handled
|= true;
13900 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
13901 } /* lpfc_sli4_intr_handler */
13904 * lpfc_sli4_queue_free - free a queue structure and associated memory
13905 * @queue: The queue structure to free.
13907 * This function frees a queue structure and the DMAable memory used for
13908 * the host resident queue. This function must be called after destroying the
13909 * queue on the HBA.
13912 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
13914 struct lpfc_dmabuf
*dmabuf
;
13919 while (!list_empty(&queue
->page_list
)) {
13920 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
13922 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
13923 dmabuf
->virt
, dmabuf
->phys
);
13927 lpfc_free_rq_buffer(queue
->phba
, queue
);
13928 kfree(queue
->rqbp
);
13931 if (!list_empty(&queue
->wq_list
))
13932 list_del(&queue
->wq_list
);
13939 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
13940 * @phba: The HBA that this queue is being created on.
13941 * @entry_size: The size of each queue entry for this queue.
13942 * @entry count: The number of entries that this queue will handle.
13944 * This function allocates a queue structure and the DMAable memory used for
13945 * the host resident queue. This function must be called before creating the
13946 * queue on the HBA.
13948 struct lpfc_queue
*
13949 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
13950 uint32_t entry_count
)
13952 struct lpfc_queue
*queue
;
13953 struct lpfc_dmabuf
*dmabuf
;
13954 int x
, total_qe_count
;
13956 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13958 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13959 hw_page_size
= SLI4_PAGE_SIZE
;
13961 queue
= kzalloc(sizeof(struct lpfc_queue
) +
13962 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
13965 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
13966 hw_page_size
))/hw_page_size
;
13968 /* If needed, Adjust page count to match the max the adapter supports */
13969 if (queue
->page_count
> phba
->sli4_hba
.pc_sli4_params
.wqpcnt
)
13970 queue
->page_count
= phba
->sli4_hba
.pc_sli4_params
.wqpcnt
;
13972 INIT_LIST_HEAD(&queue
->list
);
13973 INIT_LIST_HEAD(&queue
->wq_list
);
13974 INIT_LIST_HEAD(&queue
->page_list
);
13975 INIT_LIST_HEAD(&queue
->child_list
);
13976 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
13977 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
13980 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
13981 hw_page_size
, &dmabuf
->phys
,
13983 if (!dmabuf
->virt
) {
13987 dmabuf
->buffer_tag
= x
;
13988 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
13989 /* initialize queue's entry array */
13990 dma_pointer
= dmabuf
->virt
;
13991 for (; total_qe_count
< entry_count
&&
13992 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
13993 total_qe_count
++, dma_pointer
+= entry_size
) {
13994 queue
->qe
[total_qe_count
].address
= dma_pointer
;
13997 queue
->entry_size
= entry_size
;
13998 queue
->entry_count
= entry_count
;
13999 queue
->phba
= phba
;
14000 INIT_WORK(&queue
->irqwork
, lpfc_sli4_hba_process_cq
);
14001 INIT_WORK(&queue
->spwork
, lpfc_sli4_sp_process_cq
);
14003 /* entry_repost will be set during q creation */
14007 lpfc_sli4_queue_free(queue
);
14012 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
14013 * @phba: HBA structure that indicates port to create a queue on.
14014 * @pci_barset: PCI BAR set flag.
14016 * This function shall perform iomap of the specified PCI BAR address to host
14017 * memory address if not already done so and return it. The returned host
14018 * memory address can be NULL.
14020 static void __iomem
*
14021 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
14026 switch (pci_barset
) {
14027 case WQ_PCI_BAR_0_AND_1
:
14028 return phba
->pci_bar0_memmap_p
;
14029 case WQ_PCI_BAR_2_AND_3
:
14030 return phba
->pci_bar2_memmap_p
;
14031 case WQ_PCI_BAR_4_AND_5
:
14032 return phba
->pci_bar4_memmap_p
;
14040 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs
14041 * @phba: HBA structure that indicates port to create a queue on.
14042 * @startq: The starting FCP EQ to modify
14044 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
14045 * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be
14046 * updated in one mailbox command.
14048 * The @phba struct is used to send mailbox command to HBA. The @startq
14049 * is used to get the starting FCP EQ to change.
14050 * This function is asynchronous and will wait for the mailbox
14051 * command to finish before continuing.
14053 * On success this function will return a zero. If unable to allocate enough
14054 * memory this function will return -ENOMEM. If the queue create mailbox command
14055 * fails this function will return -ENXIO.
14058 lpfc_modify_hba_eq_delay(struct lpfc_hba
*phba
, uint32_t startq
,
14059 uint32_t numq
, uint32_t imax
)
14061 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
14062 LPFC_MBOXQ_t
*mbox
;
14063 struct lpfc_queue
*eq
;
14064 int cnt
, rc
, length
, status
= 0;
14065 uint32_t shdr_status
, shdr_add_status
;
14066 uint32_t result
, val
;
14068 union lpfc_sli4_cfg_shdr
*shdr
;
14071 if (startq
>= phba
->io_channel_irqs
)
14074 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14077 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
14078 sizeof(struct lpfc_sli4_cfg_mhdr
));
14079 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14080 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
14081 length
, LPFC_SLI4_MBX_EMBED
);
14082 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
14084 /* Calculate delay multiper from maximum interrupt per second */
14085 result
= imax
/ phba
->io_channel_irqs
;
14086 if (result
> LPFC_DMULT_CONST
|| result
== 0)
14089 dmult
= LPFC_DMULT_CONST
/result
- 1;
14090 if (dmult
> LPFC_DMULT_MAX
)
14091 dmult
= LPFC_DMULT_MAX
;
14094 for (qidx
= startq
; qidx
< phba
->io_channel_irqs
; qidx
++) {
14095 eq
= phba
->sli4_hba
.hba_eq
[qidx
];
14099 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
14100 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
14101 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
14104 /* q_mode is only used for auto_imax */
14105 if (phba
->sli
.sli_flag
& LPFC_SLI_USE_EQDR
) {
14106 /* Use EQ Delay Register method for q_mode */
14108 /* Convert for EQ Delay register */
14109 val
= phba
->cfg_fcp_imax
;
14111 /* First, interrupts per sec per EQ */
14112 val
= phba
->cfg_fcp_imax
/
14113 phba
->io_channel_irqs
;
14115 /* us delay between each interrupt */
14116 val
= LPFC_SEC_TO_USEC
/ val
;
14126 eq_delay
->u
.request
.num_eq
= cnt
;
14128 mbox
->vport
= phba
->pport
;
14129 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14130 mbox
->context1
= NULL
;
14131 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14132 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
14133 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14134 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14135 if (shdr_status
|| shdr_add_status
|| rc
) {
14136 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14137 "2512 MODIFY_EQ_DELAY mailbox failed with "
14138 "status x%x add_status x%x, mbx status x%x\n",
14139 shdr_status
, shdr_add_status
, rc
);
14142 mempool_free(mbox
, phba
->mbox_mem_pool
);
14147 * lpfc_eq_create - Create an Event Queue on the HBA
14148 * @phba: HBA structure that indicates port to create a queue on.
14149 * @eq: The queue structure to use to create the event queue.
14150 * @imax: The maximum interrupt per second limit.
14152 * This function creates an event queue, as detailed in @eq, on a port,
14153 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
14155 * The @phba struct is used to send mailbox command to HBA. The @eq struct
14156 * is used to get the entry count and entry size that are necessary to
14157 * determine the number of pages to allocate and use for this queue. This
14158 * function will send the EQ_CREATE mailbox command to the HBA to setup the
14159 * event queue. This function is asynchronous and will wait for the mailbox
14160 * command to finish before continuing.
14162 * On success this function will return a zero. If unable to allocate enough
14163 * memory this function will return -ENOMEM. If the queue create mailbox command
14164 * fails this function will return -ENXIO.
14167 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
14169 struct lpfc_mbx_eq_create
*eq_create
;
14170 LPFC_MBOXQ_t
*mbox
;
14171 int rc
, length
, status
= 0;
14172 struct lpfc_dmabuf
*dmabuf
;
14173 uint32_t shdr_status
, shdr_add_status
;
14174 union lpfc_sli4_cfg_shdr
*shdr
;
14176 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14178 /* sanity check on queue memory */
14181 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14182 hw_page_size
= SLI4_PAGE_SIZE
;
14184 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14187 length
= (sizeof(struct lpfc_mbx_eq_create
) -
14188 sizeof(struct lpfc_sli4_cfg_mhdr
));
14189 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14190 LPFC_MBOX_OPCODE_EQ_CREATE
,
14191 length
, LPFC_SLI4_MBX_EMBED
);
14192 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
14193 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
14195 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
14197 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
14198 /* don't setup delay multiplier using EQ_CREATE */
14200 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
14202 switch (eq
->entry_count
) {
14204 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14205 "0360 Unsupported EQ count. (%d)\n",
14207 if (eq
->entry_count
< 256)
14209 /* otherwise default to smallest count (drop through) */
14211 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14215 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14219 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14223 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14227 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14231 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
14232 memset(dmabuf
->virt
, 0, hw_page_size
);
14233 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14234 putPaddrLow(dmabuf
->phys
);
14235 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14236 putPaddrHigh(dmabuf
->phys
);
14238 mbox
->vport
= phba
->pport
;
14239 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14240 mbox
->context1
= NULL
;
14241 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14242 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
14243 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14244 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14245 if (shdr_status
|| shdr_add_status
|| rc
) {
14246 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14247 "2500 EQ_CREATE mailbox failed with "
14248 "status x%x add_status x%x, mbx status x%x\n",
14249 shdr_status
, shdr_add_status
, rc
);
14252 eq
->type
= LPFC_EQ
;
14253 eq
->subtype
= LPFC_NONE
;
14254 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
14255 if (eq
->queue_id
== 0xFFFF)
14257 eq
->host_index
= 0;
14259 eq
->entry_repost
= LPFC_EQ_REPOST
;
14261 mempool_free(mbox
, phba
->mbox_mem_pool
);
14266 * lpfc_cq_create - Create a Completion Queue on the HBA
14267 * @phba: HBA structure that indicates port to create a queue on.
14268 * @cq: The queue structure to use to create the completion queue.
14269 * @eq: The event queue to bind this completion queue to.
14271 * This function creates a completion queue, as detailed in @wq, on a port,
14272 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
14274 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14275 * is used to get the entry count and entry size that are necessary to
14276 * determine the number of pages to allocate and use for this queue. The @eq
14277 * is used to indicate which event queue to bind this completion queue to. This
14278 * function will send the CQ_CREATE mailbox command to the HBA to setup the
14279 * completion queue. This function is asynchronous and will wait for the mailbox
14280 * command to finish before continuing.
14282 * On success this function will return a zero. If unable to allocate enough
14283 * memory this function will return -ENOMEM. If the queue create mailbox command
14284 * fails this function will return -ENXIO.
14287 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
14288 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
14290 struct lpfc_mbx_cq_create
*cq_create
;
14291 struct lpfc_dmabuf
*dmabuf
;
14292 LPFC_MBOXQ_t
*mbox
;
14293 int rc
, length
, status
= 0;
14294 uint32_t shdr_status
, shdr_add_status
;
14295 union lpfc_sli4_cfg_shdr
*shdr
;
14296 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14298 /* sanity check on queue memory */
14301 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14302 hw_page_size
= SLI4_PAGE_SIZE
;
14304 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14307 length
= (sizeof(struct lpfc_mbx_cq_create
) -
14308 sizeof(struct lpfc_sli4_cfg_mhdr
));
14309 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14310 LPFC_MBOX_OPCODE_CQ_CREATE
,
14311 length
, LPFC_SLI4_MBX_EMBED
);
14312 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
14313 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
14314 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
14316 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
14317 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
14318 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14319 phba
->sli4_hba
.pc_sli4_params
.cqv
);
14320 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
14321 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
14322 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
14323 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
14326 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
14329 switch (cq
->entry_count
) {
14331 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14332 "0361 Unsupported CQ count: "
14333 "entry cnt %d sz %d pg cnt %d\n",
14334 cq
->entry_count
, cq
->entry_size
,
14336 if (cq
->entry_count
< 256) {
14340 /* otherwise default to smallest count (drop through) */
14342 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
14346 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
14350 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
14354 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
14355 memset(dmabuf
->virt
, 0, hw_page_size
);
14356 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14357 putPaddrLow(dmabuf
->phys
);
14358 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14359 putPaddrHigh(dmabuf
->phys
);
14361 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14363 /* The IOCTL status is embedded in the mailbox subheader. */
14364 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14365 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14366 if (shdr_status
|| shdr_add_status
|| rc
) {
14367 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14368 "2501 CQ_CREATE mailbox failed with "
14369 "status x%x add_status x%x, mbx status x%x\n",
14370 shdr_status
, shdr_add_status
, rc
);
14374 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
14375 if (cq
->queue_id
== 0xFFFF) {
14379 /* link the cq onto the parent eq child list */
14380 list_add_tail(&cq
->list
, &eq
->child_list
);
14381 /* Set up completion queue's type and subtype */
14383 cq
->subtype
= subtype
;
14384 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
14385 cq
->assoc_qid
= eq
->queue_id
;
14386 cq
->host_index
= 0;
14388 cq
->entry_repost
= LPFC_CQ_REPOST
;
14391 mempool_free(mbox
, phba
->mbox_mem_pool
);
14396 * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
14397 * @phba: HBA structure that indicates port to create a queue on.
14398 * @cqp: The queue structure array to use to create the completion queues.
14399 * @eqp: The event queue array to bind these completion queues to.
14401 * This function creates a set of completion queue, s to support MRQ
14402 * as detailed in @cqp, on a port,
14403 * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
14405 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14406 * is used to get the entry count and entry size that are necessary to
14407 * determine the number of pages to allocate and use for this queue. The @eq
14408 * is used to indicate which event queue to bind this completion queue to. This
14409 * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
14410 * completion queue. This function is asynchronous and will wait for the mailbox
14411 * command to finish before continuing.
14413 * On success this function will return a zero. If unable to allocate enough
14414 * memory this function will return -ENOMEM. If the queue create mailbox command
14415 * fails this function will return -ENXIO.
14418 lpfc_cq_create_set(struct lpfc_hba
*phba
, struct lpfc_queue
**cqp
,
14419 struct lpfc_queue
**eqp
, uint32_t type
, uint32_t subtype
)
14421 struct lpfc_queue
*cq
;
14422 struct lpfc_queue
*eq
;
14423 struct lpfc_mbx_cq_create_set
*cq_set
;
14424 struct lpfc_dmabuf
*dmabuf
;
14425 LPFC_MBOXQ_t
*mbox
;
14426 int rc
, length
, alloclen
, status
= 0;
14427 int cnt
, idx
, numcq
, page_idx
= 0;
14428 uint32_t shdr_status
, shdr_add_status
;
14429 union lpfc_sli4_cfg_shdr
*shdr
;
14430 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14432 /* sanity check on queue memory */
14433 numcq
= phba
->cfg_nvmet_mrq
;
14434 if (!cqp
|| !eqp
|| !numcq
)
14436 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14437 hw_page_size
= SLI4_PAGE_SIZE
;
14439 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14443 length
= sizeof(struct lpfc_mbx_cq_create_set
);
14444 length
+= ((numcq
* cqp
[0]->page_count
) *
14445 sizeof(struct dma_address
));
14446 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14447 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET
, length
,
14448 LPFC_SLI4_MBX_NEMBED
);
14449 if (alloclen
< length
) {
14450 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14451 "3098 Allocated DMA memory size (%d) is "
14452 "less than the requested DMA memory size "
14453 "(%d)\n", alloclen
, length
);
14457 cq_set
= mbox
->sge_array
->addr
[0];
14458 shdr
= (union lpfc_sli4_cfg_shdr
*)&cq_set
->cfg_shdr
;
14459 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, 0);
14461 for (idx
= 0; idx
< numcq
; idx
++) {
14471 bf_set(lpfc_mbx_cq_create_set_page_size
,
14472 &cq_set
->u
.request
,
14473 (hw_page_size
/ SLI4_PAGE_SIZE
));
14474 bf_set(lpfc_mbx_cq_create_set_num_pages
,
14475 &cq_set
->u
.request
, cq
->page_count
);
14476 bf_set(lpfc_mbx_cq_create_set_evt
,
14477 &cq_set
->u
.request
, 1);
14478 bf_set(lpfc_mbx_cq_create_set_valid
,
14479 &cq_set
->u
.request
, 1);
14480 bf_set(lpfc_mbx_cq_create_set_cqe_size
,
14481 &cq_set
->u
.request
, 0);
14482 bf_set(lpfc_mbx_cq_create_set_num_cq
,
14483 &cq_set
->u
.request
, numcq
);
14484 switch (cq
->entry_count
) {
14486 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14487 "3118 Bad CQ count. (%d)\n",
14489 if (cq
->entry_count
< 256) {
14493 /* otherwise default to smallest (drop thru) */
14495 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14496 &cq_set
->u
.request
, LPFC_CQ_CNT_256
);
14499 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14500 &cq_set
->u
.request
, LPFC_CQ_CNT_512
);
14503 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14504 &cq_set
->u
.request
, LPFC_CQ_CNT_1024
);
14507 bf_set(lpfc_mbx_cq_create_set_eq_id0
,
14508 &cq_set
->u
.request
, eq
->queue_id
);
14511 bf_set(lpfc_mbx_cq_create_set_eq_id1
,
14512 &cq_set
->u
.request
, eq
->queue_id
);
14515 bf_set(lpfc_mbx_cq_create_set_eq_id2
,
14516 &cq_set
->u
.request
, eq
->queue_id
);
14519 bf_set(lpfc_mbx_cq_create_set_eq_id3
,
14520 &cq_set
->u
.request
, eq
->queue_id
);
14523 bf_set(lpfc_mbx_cq_create_set_eq_id4
,
14524 &cq_set
->u
.request
, eq
->queue_id
);
14527 bf_set(lpfc_mbx_cq_create_set_eq_id5
,
14528 &cq_set
->u
.request
, eq
->queue_id
);
14531 bf_set(lpfc_mbx_cq_create_set_eq_id6
,
14532 &cq_set
->u
.request
, eq
->queue_id
);
14535 bf_set(lpfc_mbx_cq_create_set_eq_id7
,
14536 &cq_set
->u
.request
, eq
->queue_id
);
14539 bf_set(lpfc_mbx_cq_create_set_eq_id8
,
14540 &cq_set
->u
.request
, eq
->queue_id
);
14543 bf_set(lpfc_mbx_cq_create_set_eq_id9
,
14544 &cq_set
->u
.request
, eq
->queue_id
);
14547 bf_set(lpfc_mbx_cq_create_set_eq_id10
,
14548 &cq_set
->u
.request
, eq
->queue_id
);
14551 bf_set(lpfc_mbx_cq_create_set_eq_id11
,
14552 &cq_set
->u
.request
, eq
->queue_id
);
14555 bf_set(lpfc_mbx_cq_create_set_eq_id12
,
14556 &cq_set
->u
.request
, eq
->queue_id
);
14559 bf_set(lpfc_mbx_cq_create_set_eq_id13
,
14560 &cq_set
->u
.request
, eq
->queue_id
);
14563 bf_set(lpfc_mbx_cq_create_set_eq_id14
,
14564 &cq_set
->u
.request
, eq
->queue_id
);
14567 bf_set(lpfc_mbx_cq_create_set_eq_id15
,
14568 &cq_set
->u
.request
, eq
->queue_id
);
14572 /* link the cq onto the parent eq child list */
14573 list_add_tail(&cq
->list
, &eq
->child_list
);
14574 /* Set up completion queue's type and subtype */
14576 cq
->subtype
= subtype
;
14577 cq
->assoc_qid
= eq
->queue_id
;
14578 cq
->host_index
= 0;
14580 cq
->entry_repost
= LPFC_CQ_REPOST
;
14583 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
14584 memset(dmabuf
->virt
, 0, hw_page_size
);
14585 cnt
= page_idx
+ dmabuf
->buffer_tag
;
14586 cq_set
->u
.request
.page
[cnt
].addr_lo
=
14587 putPaddrLow(dmabuf
->phys
);
14588 cq_set
->u
.request
.page
[cnt
].addr_hi
=
14589 putPaddrHigh(dmabuf
->phys
);
14595 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14597 /* The IOCTL status is embedded in the mailbox subheader. */
14598 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14599 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14600 if (shdr_status
|| shdr_add_status
|| rc
) {
14601 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14602 "3119 CQ_CREATE_SET mailbox failed with "
14603 "status x%x add_status x%x, mbx status x%x\n",
14604 shdr_status
, shdr_add_status
, rc
);
14608 rc
= bf_get(lpfc_mbx_cq_create_set_base_id
, &cq_set
->u
.response
);
14609 if (rc
== 0xFFFF) {
14614 for (idx
= 0; idx
< numcq
; idx
++) {
14616 cq
->queue_id
= rc
+ idx
;
14620 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14625 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
14626 * @phba: HBA structure that indicates port to create a queue on.
14627 * @mq: The queue structure to use to create the mailbox queue.
14628 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
14629 * @cq: The completion queue to associate with this cq.
14631 * This function provides failback (fb) functionality when the
14632 * mq_create_ext fails on older FW generations. It's purpose is identical
14633 * to mq_create_ext otherwise.
14635 * This routine cannot fail as all attributes were previously accessed and
14636 * initialized in mq_create_ext.
14639 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
14640 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
14642 struct lpfc_mbx_mq_create
*mq_create
;
14643 struct lpfc_dmabuf
*dmabuf
;
14646 length
= (sizeof(struct lpfc_mbx_mq_create
) -
14647 sizeof(struct lpfc_sli4_cfg_mhdr
));
14648 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14649 LPFC_MBOX_OPCODE_MQ_CREATE
,
14650 length
, LPFC_SLI4_MBX_EMBED
);
14651 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
14652 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
14654 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
14656 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
14657 switch (mq
->entry_count
) {
14659 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14660 LPFC_MQ_RING_SIZE_16
);
14663 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14664 LPFC_MQ_RING_SIZE_32
);
14667 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14668 LPFC_MQ_RING_SIZE_64
);
14671 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14672 LPFC_MQ_RING_SIZE_128
);
14675 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
14676 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14677 putPaddrLow(dmabuf
->phys
);
14678 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14679 putPaddrHigh(dmabuf
->phys
);
14684 * lpfc_mq_create - Create a mailbox Queue on the HBA
14685 * @phba: HBA structure that indicates port to create a queue on.
14686 * @mq: The queue structure to use to create the mailbox queue.
14687 * @cq: The completion queue to associate with this cq.
14688 * @subtype: The queue's subtype.
14690 * This function creates a mailbox queue, as detailed in @mq, on a port,
14691 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
14693 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14694 * is used to get the entry count and entry size that are necessary to
14695 * determine the number of pages to allocate and use for this queue. This
14696 * function will send the MQ_CREATE mailbox command to the HBA to setup the
14697 * mailbox queue. This function is asynchronous and will wait for the mailbox
14698 * command to finish before continuing.
14700 * On success this function will return a zero. If unable to allocate enough
14701 * memory this function will return -ENOMEM. If the queue create mailbox command
14702 * fails this function will return -ENXIO.
14705 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
14706 struct lpfc_queue
*cq
, uint32_t subtype
)
14708 struct lpfc_mbx_mq_create
*mq_create
;
14709 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
14710 struct lpfc_dmabuf
*dmabuf
;
14711 LPFC_MBOXQ_t
*mbox
;
14712 int rc
, length
, status
= 0;
14713 uint32_t shdr_status
, shdr_add_status
;
14714 union lpfc_sli4_cfg_shdr
*shdr
;
14715 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14717 /* sanity check on queue memory */
14720 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14721 hw_page_size
= SLI4_PAGE_SIZE
;
14723 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14726 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
14727 sizeof(struct lpfc_sli4_cfg_mhdr
));
14728 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14729 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
14730 length
, LPFC_SLI4_MBX_EMBED
);
14732 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
14733 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
14734 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
14735 &mq_create_ext
->u
.request
, mq
->page_count
);
14736 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
14737 &mq_create_ext
->u
.request
, 1);
14738 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
14739 &mq_create_ext
->u
.request
, 1);
14740 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
14741 &mq_create_ext
->u
.request
, 1);
14742 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
14743 &mq_create_ext
->u
.request
, 1);
14744 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
14745 &mq_create_ext
->u
.request
, 1);
14746 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
14747 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14748 phba
->sli4_hba
.pc_sli4_params
.mqv
);
14749 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
14750 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
14753 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
14755 switch (mq
->entry_count
) {
14757 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14758 "0362 Unsupported MQ count. (%d)\n",
14760 if (mq
->entry_count
< 16) {
14764 /* otherwise default to smallest count (drop through) */
14766 bf_set(lpfc_mq_context_ring_size
,
14767 &mq_create_ext
->u
.request
.context
,
14768 LPFC_MQ_RING_SIZE_16
);
14771 bf_set(lpfc_mq_context_ring_size
,
14772 &mq_create_ext
->u
.request
.context
,
14773 LPFC_MQ_RING_SIZE_32
);
14776 bf_set(lpfc_mq_context_ring_size
,
14777 &mq_create_ext
->u
.request
.context
,
14778 LPFC_MQ_RING_SIZE_64
);
14781 bf_set(lpfc_mq_context_ring_size
,
14782 &mq_create_ext
->u
.request
.context
,
14783 LPFC_MQ_RING_SIZE_128
);
14786 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
14787 memset(dmabuf
->virt
, 0, hw_page_size
);
14788 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14789 putPaddrLow(dmabuf
->phys
);
14790 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14791 putPaddrHigh(dmabuf
->phys
);
14793 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14794 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
14795 &mq_create_ext
->u
.response
);
14796 if (rc
!= MBX_SUCCESS
) {
14797 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
14798 "2795 MQ_CREATE_EXT failed with "
14799 "status x%x. Failback to MQ_CREATE.\n",
14801 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
14802 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
14803 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14804 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
14805 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
14806 &mq_create
->u
.response
);
14809 /* The IOCTL status is embedded in the mailbox subheader. */
14810 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14811 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14812 if (shdr_status
|| shdr_add_status
|| rc
) {
14813 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14814 "2502 MQ_CREATE mailbox failed with "
14815 "status x%x add_status x%x, mbx status x%x\n",
14816 shdr_status
, shdr_add_status
, rc
);
14820 if (mq
->queue_id
== 0xFFFF) {
14824 mq
->type
= LPFC_MQ
;
14825 mq
->assoc_qid
= cq
->queue_id
;
14826 mq
->subtype
= subtype
;
14827 mq
->host_index
= 0;
14829 mq
->entry_repost
= LPFC_MQ_REPOST
;
14831 /* link the mq onto the parent cq child list */
14832 list_add_tail(&mq
->list
, &cq
->child_list
);
14834 mempool_free(mbox
, phba
->mbox_mem_pool
);
14839 * lpfc_wq_create - Create a Work Queue on the HBA
14840 * @phba: HBA structure that indicates port to create a queue on.
14841 * @wq: The queue structure to use to create the work queue.
14842 * @cq: The completion queue to bind this work queue to.
14843 * @subtype: The subtype of the work queue indicating its functionality.
14845 * This function creates a work queue, as detailed in @wq, on a port, described
14846 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
14848 * The @phba struct is used to send mailbox command to HBA. The @wq struct
14849 * is used to get the entry count and entry size that are necessary to
14850 * determine the number of pages to allocate and use for this queue. The @cq
14851 * is used to indicate which completion queue to bind this work queue to. This
14852 * function will send the WQ_CREATE mailbox command to the HBA to setup the
14853 * work queue. This function is asynchronous and will wait for the mailbox
14854 * command to finish before continuing.
14856 * On success this function will return a zero. If unable to allocate enough
14857 * memory this function will return -ENOMEM. If the queue create mailbox command
14858 * fails this function will return -ENXIO.
14861 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
14862 struct lpfc_queue
*cq
, uint32_t subtype
)
14864 struct lpfc_mbx_wq_create
*wq_create
;
14865 struct lpfc_dmabuf
*dmabuf
;
14866 LPFC_MBOXQ_t
*mbox
;
14867 int rc
, length
, status
= 0;
14868 uint32_t shdr_status
, shdr_add_status
;
14869 union lpfc_sli4_cfg_shdr
*shdr
;
14870 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14871 struct dma_address
*page
;
14872 void __iomem
*bar_memmap_p
;
14873 uint32_t db_offset
;
14874 uint16_t pci_barset
;
14876 /* sanity check on queue memory */
14879 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14880 hw_page_size
= SLI4_PAGE_SIZE
;
14882 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14885 length
= (sizeof(struct lpfc_mbx_wq_create
) -
14886 sizeof(struct lpfc_sli4_cfg_mhdr
));
14887 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14888 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
14889 length
, LPFC_SLI4_MBX_EMBED
);
14890 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
14891 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
14892 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
14894 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
14897 /* wqv is the earliest version supported, NOT the latest */
14898 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14899 phba
->sli4_hba
.pc_sli4_params
.wqv
);
14901 switch (phba
->sli4_hba
.pc_sli4_params
.wqv
) {
14902 case LPFC_Q_CREATE_VERSION_0
:
14903 switch (wq
->entry_size
) {
14906 /* Nothing to do, version 0 ONLY supports 64 byte */
14907 page
= wq_create
->u
.request
.page
;
14910 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
14911 LPFC_WQ_SZ128_SUPPORT
)) {
14915 /* If we get here the HBA MUST also support V1 and
14918 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14919 LPFC_Q_CREATE_VERSION_1
);
14921 bf_set(lpfc_mbx_wq_create_wqe_count
,
14922 &wq_create
->u
.request_1
, wq
->entry_count
);
14923 bf_set(lpfc_mbx_wq_create_wqe_size
,
14924 &wq_create
->u
.request_1
,
14925 LPFC_WQ_WQE_SIZE_128
);
14926 bf_set(lpfc_mbx_wq_create_page_size
,
14927 &wq_create
->u
.request_1
,
14928 LPFC_WQ_PAGE_SIZE_4096
);
14929 page
= wq_create
->u
.request_1
.page
;
14933 case LPFC_Q_CREATE_VERSION_1
:
14934 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
14936 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14937 LPFC_Q_CREATE_VERSION_1
);
14939 switch (wq
->entry_size
) {
14942 bf_set(lpfc_mbx_wq_create_wqe_size
,
14943 &wq_create
->u
.request_1
,
14944 LPFC_WQ_WQE_SIZE_64
);
14947 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
14948 LPFC_WQ_SZ128_SUPPORT
)) {
14952 bf_set(lpfc_mbx_wq_create_wqe_size
,
14953 &wq_create
->u
.request_1
,
14954 LPFC_WQ_WQE_SIZE_128
);
14957 bf_set(lpfc_mbx_wq_create_page_size
,
14958 &wq_create
->u
.request_1
,
14959 LPFC_WQ_PAGE_SIZE_4096
);
14960 page
= wq_create
->u
.request_1
.page
;
14967 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
14968 memset(dmabuf
->virt
, 0, hw_page_size
);
14969 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
14970 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
14973 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
14974 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
14976 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14977 /* The IOCTL status is embedded in the mailbox subheader. */
14978 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14979 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14980 if (shdr_status
|| shdr_add_status
|| rc
) {
14981 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14982 "2503 WQ_CREATE mailbox failed with "
14983 "status x%x add_status x%x, mbx status x%x\n",
14984 shdr_status
, shdr_add_status
, rc
);
14988 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
14989 if (wq
->queue_id
== 0xFFFF) {
14993 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
14994 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
14995 &wq_create
->u
.response
);
14996 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
14997 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
14998 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14999 "3265 WQ[%d] doorbell format not "
15000 "supported: x%x\n", wq
->queue_id
,
15005 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
15006 &wq_create
->u
.response
);
15007 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
15008 if (!bar_memmap_p
) {
15009 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15010 "3263 WQ[%d] failed to memmap pci "
15011 "barset:x%x\n", wq
->queue_id
,
15016 db_offset
= wq_create
->u
.response
.doorbell_offset
;
15017 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
15018 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
15019 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15020 "3252 WQ[%d] doorbell offset not "
15021 "supported: x%x\n", wq
->queue_id
,
15026 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15027 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15028 "3264 WQ[%d]: barset:x%x, offset:x%x, "
15029 "format:x%x\n", wq
->queue_id
, pci_barset
,
15030 db_offset
, wq
->db_format
);
15032 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
15033 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
15035 wq
->pring
= kzalloc(sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
15036 if (wq
->pring
== NULL
) {
15040 wq
->type
= LPFC_WQ
;
15041 wq
->assoc_qid
= cq
->queue_id
;
15042 wq
->subtype
= subtype
;
15043 wq
->host_index
= 0;
15045 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
15047 /* link the wq onto the parent cq child list */
15048 list_add_tail(&wq
->list
, &cq
->child_list
);
15050 mempool_free(mbox
, phba
->mbox_mem_pool
);
15055 * lpfc_rq_create - Create a Receive Queue on the HBA
15056 * @phba: HBA structure that indicates port to create a queue on.
15057 * @hrq: The queue structure to use to create the header receive queue.
15058 * @drq: The queue structure to use to create the data receive queue.
15059 * @cq: The completion queue to bind this work queue to.
15061 * This function creates a receive buffer queue pair , as detailed in @hrq and
15062 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15065 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15066 * struct is used to get the entry count that is necessary to determine the
15067 * number of pages to use for this queue. The @cq is used to indicate which
15068 * completion queue to bind received buffers that are posted to these queues to.
15069 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15070 * receive queue pair. This function is asynchronous and will wait for the
15071 * mailbox command to finish before continuing.
15073 * On success this function will return a zero. If unable to allocate enough
15074 * memory this function will return -ENOMEM. If the queue create mailbox command
15075 * fails this function will return -ENXIO.
15078 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
15079 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
15081 struct lpfc_mbx_rq_create
*rq_create
;
15082 struct lpfc_dmabuf
*dmabuf
;
15083 LPFC_MBOXQ_t
*mbox
;
15084 int rc
, length
, status
= 0;
15085 uint32_t shdr_status
, shdr_add_status
;
15086 union lpfc_sli4_cfg_shdr
*shdr
;
15087 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15088 void __iomem
*bar_memmap_p
;
15089 uint32_t db_offset
;
15090 uint16_t pci_barset
;
15092 /* sanity check on queue memory */
15093 if (!hrq
|| !drq
|| !cq
)
15095 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15096 hw_page_size
= SLI4_PAGE_SIZE
;
15098 if (hrq
->entry_count
!= drq
->entry_count
)
15100 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15103 length
= (sizeof(struct lpfc_mbx_rq_create
) -
15104 sizeof(struct lpfc_sli4_cfg_mhdr
));
15105 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15106 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
15107 length
, LPFC_SLI4_MBX_EMBED
);
15108 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
15109 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
15110 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15111 phba
->sli4_hba
.pc_sli4_params
.rqv
);
15112 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
15113 bf_set(lpfc_rq_context_rqe_count_1
,
15114 &rq_create
->u
.request
.context
,
15116 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
15117 bf_set(lpfc_rq_context_rqe_size
,
15118 &rq_create
->u
.request
.context
,
15120 bf_set(lpfc_rq_context_page_size
,
15121 &rq_create
->u
.request
.context
,
15122 LPFC_RQ_PAGE_SIZE_4096
);
15124 switch (hrq
->entry_count
) {
15126 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15127 "2535 Unsupported RQ count. (%d)\n",
15129 if (hrq
->entry_count
< 512) {
15133 /* otherwise default to smallest count (drop through) */
15135 bf_set(lpfc_rq_context_rqe_count
,
15136 &rq_create
->u
.request
.context
,
15137 LPFC_RQ_RING_SIZE_512
);
15140 bf_set(lpfc_rq_context_rqe_count
,
15141 &rq_create
->u
.request
.context
,
15142 LPFC_RQ_RING_SIZE_1024
);
15145 bf_set(lpfc_rq_context_rqe_count
,
15146 &rq_create
->u
.request
.context
,
15147 LPFC_RQ_RING_SIZE_2048
);
15150 bf_set(lpfc_rq_context_rqe_count
,
15151 &rq_create
->u
.request
.context
,
15152 LPFC_RQ_RING_SIZE_4096
);
15155 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
15156 LPFC_HDR_BUF_SIZE
);
15158 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
15160 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
15162 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
15163 memset(dmabuf
->virt
, 0, hw_page_size
);
15164 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15165 putPaddrLow(dmabuf
->phys
);
15166 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15167 putPaddrHigh(dmabuf
->phys
);
15169 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15170 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
15172 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15173 /* The IOCTL status is embedded in the mailbox subheader. */
15174 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15175 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15176 if (shdr_status
|| shdr_add_status
|| rc
) {
15177 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15178 "2504 RQ_CREATE mailbox failed with "
15179 "status x%x add_status x%x, mbx status x%x\n",
15180 shdr_status
, shdr_add_status
, rc
);
15184 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15185 if (hrq
->queue_id
== 0xFFFF) {
15190 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
15191 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
15192 &rq_create
->u
.response
);
15193 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
15194 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
15195 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15196 "3262 RQ [%d] doorbell format not "
15197 "supported: x%x\n", hrq
->queue_id
,
15203 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
15204 &rq_create
->u
.response
);
15205 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
15206 if (!bar_memmap_p
) {
15207 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15208 "3269 RQ[%d] failed to memmap pci "
15209 "barset:x%x\n", hrq
->queue_id
,
15215 db_offset
= rq_create
->u
.response
.doorbell_offset
;
15216 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
15217 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
15218 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15219 "3270 RQ[%d] doorbell offset not "
15220 "supported: x%x\n", hrq
->queue_id
,
15225 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15226 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15227 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
15228 "format:x%x\n", hrq
->queue_id
, pci_barset
,
15229 db_offset
, hrq
->db_format
);
15231 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
15232 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15234 hrq
->type
= LPFC_HRQ
;
15235 hrq
->assoc_qid
= cq
->queue_id
;
15236 hrq
->subtype
= subtype
;
15237 hrq
->host_index
= 0;
15238 hrq
->hba_index
= 0;
15239 hrq
->entry_repost
= LPFC_RQ_REPOST
;
15241 /* now create the data queue */
15242 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15243 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
15244 length
, LPFC_SLI4_MBX_EMBED
);
15245 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15246 phba
->sli4_hba
.pc_sli4_params
.rqv
);
15247 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
15248 bf_set(lpfc_rq_context_rqe_count_1
,
15249 &rq_create
->u
.request
.context
, hrq
->entry_count
);
15250 if (subtype
== LPFC_NVMET
)
15251 rq_create
->u
.request
.context
.buffer_size
=
15252 LPFC_NVMET_DATA_BUF_SIZE
;
15254 rq_create
->u
.request
.context
.buffer_size
=
15255 LPFC_DATA_BUF_SIZE
;
15256 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
15258 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
15259 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
15261 switch (drq
->entry_count
) {
15263 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15264 "2536 Unsupported RQ count. (%d)\n",
15266 if (drq
->entry_count
< 512) {
15270 /* otherwise default to smallest count (drop through) */
15272 bf_set(lpfc_rq_context_rqe_count
,
15273 &rq_create
->u
.request
.context
,
15274 LPFC_RQ_RING_SIZE_512
);
15277 bf_set(lpfc_rq_context_rqe_count
,
15278 &rq_create
->u
.request
.context
,
15279 LPFC_RQ_RING_SIZE_1024
);
15282 bf_set(lpfc_rq_context_rqe_count
,
15283 &rq_create
->u
.request
.context
,
15284 LPFC_RQ_RING_SIZE_2048
);
15287 bf_set(lpfc_rq_context_rqe_count
,
15288 &rq_create
->u
.request
.context
,
15289 LPFC_RQ_RING_SIZE_4096
);
15292 if (subtype
== LPFC_NVMET
)
15293 bf_set(lpfc_rq_context_buf_size
,
15294 &rq_create
->u
.request
.context
,
15295 LPFC_NVMET_DATA_BUF_SIZE
);
15297 bf_set(lpfc_rq_context_buf_size
,
15298 &rq_create
->u
.request
.context
,
15299 LPFC_DATA_BUF_SIZE
);
15301 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
15303 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
15305 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
15306 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15307 putPaddrLow(dmabuf
->phys
);
15308 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15309 putPaddrHigh(dmabuf
->phys
);
15311 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15312 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
15313 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15314 /* The IOCTL status is embedded in the mailbox subheader. */
15315 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
15316 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15317 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15318 if (shdr_status
|| shdr_add_status
|| rc
) {
15322 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15323 if (drq
->queue_id
== 0xFFFF) {
15327 drq
->type
= LPFC_DRQ
;
15328 drq
->assoc_qid
= cq
->queue_id
;
15329 drq
->subtype
= subtype
;
15330 drq
->host_index
= 0;
15331 drq
->hba_index
= 0;
15332 drq
->entry_repost
= LPFC_RQ_REPOST
;
15334 /* link the header and data RQs onto the parent cq child list */
15335 list_add_tail(&hrq
->list
, &cq
->child_list
);
15336 list_add_tail(&drq
->list
, &cq
->child_list
);
15339 mempool_free(mbox
, phba
->mbox_mem_pool
);
15344 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
15345 * @phba: HBA structure that indicates port to create a queue on.
15346 * @hrqp: The queue structure array to use to create the header receive queues.
15347 * @drqp: The queue structure array to use to create the data receive queues.
15348 * @cqp: The completion queue array to bind these receive queues to.
15350 * This function creates a receive buffer queue pair , as detailed in @hrq and
15351 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15354 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15355 * struct is used to get the entry count that is necessary to determine the
15356 * number of pages to use for this queue. The @cq is used to indicate which
15357 * completion queue to bind received buffers that are posted to these queues to.
15358 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15359 * receive queue pair. This function is asynchronous and will wait for the
15360 * mailbox command to finish before continuing.
15362 * On success this function will return a zero. If unable to allocate enough
15363 * memory this function will return -ENOMEM. If the queue create mailbox command
15364 * fails this function will return -ENXIO.
15367 lpfc_mrq_create(struct lpfc_hba
*phba
, struct lpfc_queue
**hrqp
,
15368 struct lpfc_queue
**drqp
, struct lpfc_queue
**cqp
,
15371 struct lpfc_queue
*hrq
, *drq
, *cq
;
15372 struct lpfc_mbx_rq_create_v2
*rq_create
;
15373 struct lpfc_dmabuf
*dmabuf
;
15374 LPFC_MBOXQ_t
*mbox
;
15375 int rc
, length
, alloclen
, status
= 0;
15376 int cnt
, idx
, numrq
, page_idx
= 0;
15377 uint32_t shdr_status
, shdr_add_status
;
15378 union lpfc_sli4_cfg_shdr
*shdr
;
15379 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15381 numrq
= phba
->cfg_nvmet_mrq
;
15382 /* sanity check on array memory */
15383 if (!hrqp
|| !drqp
|| !cqp
|| !numrq
)
15385 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15386 hw_page_size
= SLI4_PAGE_SIZE
;
15388 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15392 length
= sizeof(struct lpfc_mbx_rq_create_v2
);
15393 length
+= ((2 * numrq
* hrqp
[0]->page_count
) *
15394 sizeof(struct dma_address
));
15396 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15397 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
, length
,
15398 LPFC_SLI4_MBX_NEMBED
);
15399 if (alloclen
< length
) {
15400 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15401 "3099 Allocated DMA memory size (%d) is "
15402 "less than the requested DMA memory size "
15403 "(%d)\n", alloclen
, length
);
15410 rq_create
= mbox
->sge_array
->addr
[0];
15411 shdr
= (union lpfc_sli4_cfg_shdr
*)&rq_create
->cfg_shdr
;
15413 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_Q_CREATE_VERSION_2
);
15416 for (idx
= 0; idx
< numrq
; idx
++) {
15421 /* sanity check on queue memory */
15422 if (!hrq
|| !drq
|| !cq
) {
15427 if (hrq
->entry_count
!= drq
->entry_count
) {
15433 bf_set(lpfc_mbx_rq_create_num_pages
,
15434 &rq_create
->u
.request
,
15436 bf_set(lpfc_mbx_rq_create_rq_cnt
,
15437 &rq_create
->u
.request
, (numrq
* 2));
15438 bf_set(lpfc_mbx_rq_create_dnb
, &rq_create
->u
.request
,
15440 bf_set(lpfc_rq_context_base_cq
,
15441 &rq_create
->u
.request
.context
,
15443 bf_set(lpfc_rq_context_data_size
,
15444 &rq_create
->u
.request
.context
,
15445 LPFC_NVMET_DATA_BUF_SIZE
);
15446 bf_set(lpfc_rq_context_hdr_size
,
15447 &rq_create
->u
.request
.context
,
15448 LPFC_HDR_BUF_SIZE
);
15449 bf_set(lpfc_rq_context_rqe_count_1
,
15450 &rq_create
->u
.request
.context
,
15452 bf_set(lpfc_rq_context_rqe_size
,
15453 &rq_create
->u
.request
.context
,
15455 bf_set(lpfc_rq_context_page_size
,
15456 &rq_create
->u
.request
.context
,
15457 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
15460 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
15461 memset(dmabuf
->virt
, 0, hw_page_size
);
15462 cnt
= page_idx
+ dmabuf
->buffer_tag
;
15463 rq_create
->u
.request
.page
[cnt
].addr_lo
=
15464 putPaddrLow(dmabuf
->phys
);
15465 rq_create
->u
.request
.page
[cnt
].addr_hi
=
15466 putPaddrHigh(dmabuf
->phys
);
15472 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
15473 memset(dmabuf
->virt
, 0, hw_page_size
);
15474 cnt
= page_idx
+ dmabuf
->buffer_tag
;
15475 rq_create
->u
.request
.page
[cnt
].addr_lo
=
15476 putPaddrLow(dmabuf
->phys
);
15477 rq_create
->u
.request
.page
[cnt
].addr_hi
=
15478 putPaddrHigh(dmabuf
->phys
);
15483 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
15484 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15485 hrq
->type
= LPFC_HRQ
;
15486 hrq
->assoc_qid
= cq
->queue_id
;
15487 hrq
->subtype
= subtype
;
15488 hrq
->host_index
= 0;
15489 hrq
->hba_index
= 0;
15490 hrq
->entry_repost
= LPFC_RQ_REPOST
;
15492 drq
->db_format
= LPFC_DB_RING_FORMAT
;
15493 drq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15494 drq
->type
= LPFC_DRQ
;
15495 drq
->assoc_qid
= cq
->queue_id
;
15496 drq
->subtype
= subtype
;
15497 drq
->host_index
= 0;
15498 drq
->hba_index
= 0;
15499 drq
->entry_repost
= LPFC_RQ_REPOST
;
15501 list_add_tail(&hrq
->list
, &cq
->child_list
);
15502 list_add_tail(&drq
->list
, &cq
->child_list
);
15505 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15506 /* The IOCTL status is embedded in the mailbox subheader. */
15507 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15508 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15509 if (shdr_status
|| shdr_add_status
|| rc
) {
15510 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15511 "3120 RQ_CREATE mailbox failed with "
15512 "status x%x add_status x%x, mbx status x%x\n",
15513 shdr_status
, shdr_add_status
, rc
);
15517 rc
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15518 if (rc
== 0xFFFF) {
15523 /* Initialize all RQs with associated queue id */
15524 for (idx
= 0; idx
< numrq
; idx
++) {
15526 hrq
->queue_id
= rc
+ (2 * idx
);
15528 drq
->queue_id
= rc
+ (2 * idx
) + 1;
15532 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
15537 * lpfc_eq_destroy - Destroy an event Queue on the HBA
15538 * @eq: The queue structure associated with the queue to destroy.
15540 * This function destroys a queue, as detailed in @eq by sending an mailbox
15541 * command, specific to the type of queue, to the HBA.
15543 * The @eq struct is used to get the queue ID of the queue to destroy.
15545 * On success this function will return a zero. If the queue destroy mailbox
15546 * command fails this function will return -ENXIO.
15549 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
15551 LPFC_MBOXQ_t
*mbox
;
15552 int rc
, length
, status
= 0;
15553 uint32_t shdr_status
, shdr_add_status
;
15554 union lpfc_sli4_cfg_shdr
*shdr
;
15556 /* sanity check on queue memory */
15559 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15562 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
15563 sizeof(struct lpfc_sli4_cfg_mhdr
));
15564 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15565 LPFC_MBOX_OPCODE_EQ_DESTROY
,
15566 length
, LPFC_SLI4_MBX_EMBED
);
15567 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
15569 mbox
->vport
= eq
->phba
->pport
;
15570 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15572 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
15573 /* The IOCTL status is embedded in the mailbox subheader. */
15574 shdr
= (union lpfc_sli4_cfg_shdr
*)
15575 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
15576 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15577 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15578 if (shdr_status
|| shdr_add_status
|| rc
) {
15579 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15580 "2505 EQ_DESTROY mailbox failed with "
15581 "status x%x add_status x%x, mbx status x%x\n",
15582 shdr_status
, shdr_add_status
, rc
);
15586 /* Remove eq from any list */
15587 list_del_init(&eq
->list
);
15588 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
15593 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
15594 * @cq: The queue structure associated with the queue to destroy.
15596 * This function destroys a queue, as detailed in @cq by sending an mailbox
15597 * command, specific to the type of queue, to the HBA.
15599 * The @cq struct is used to get the queue ID of the queue to destroy.
15601 * On success this function will return a zero. If the queue destroy mailbox
15602 * command fails this function will return -ENXIO.
15605 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
15607 LPFC_MBOXQ_t
*mbox
;
15608 int rc
, length
, status
= 0;
15609 uint32_t shdr_status
, shdr_add_status
;
15610 union lpfc_sli4_cfg_shdr
*shdr
;
15612 /* sanity check on queue memory */
15615 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15618 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
15619 sizeof(struct lpfc_sli4_cfg_mhdr
));
15620 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15621 LPFC_MBOX_OPCODE_CQ_DESTROY
,
15622 length
, LPFC_SLI4_MBX_EMBED
);
15623 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
15625 mbox
->vport
= cq
->phba
->pport
;
15626 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15627 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
15628 /* The IOCTL status is embedded in the mailbox subheader. */
15629 shdr
= (union lpfc_sli4_cfg_shdr
*)
15630 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
15631 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15632 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15633 if (shdr_status
|| shdr_add_status
|| rc
) {
15634 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15635 "2506 CQ_DESTROY mailbox failed with "
15636 "status x%x add_status x%x, mbx status x%x\n",
15637 shdr_status
, shdr_add_status
, rc
);
15640 /* Remove cq from any list */
15641 list_del_init(&cq
->list
);
15642 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
15647 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
15648 * @qm: The queue structure associated with the queue to destroy.
15650 * This function destroys a queue, as detailed in @mq by sending an mailbox
15651 * command, specific to the type of queue, to the HBA.
15653 * The @mq struct is used to get the queue ID of the queue to destroy.
15655 * On success this function will return a zero. If the queue destroy mailbox
15656 * command fails this function will return -ENXIO.
15659 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
15661 LPFC_MBOXQ_t
*mbox
;
15662 int rc
, length
, status
= 0;
15663 uint32_t shdr_status
, shdr_add_status
;
15664 union lpfc_sli4_cfg_shdr
*shdr
;
15666 /* sanity check on queue memory */
15669 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15672 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
15673 sizeof(struct lpfc_sli4_cfg_mhdr
));
15674 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15675 LPFC_MBOX_OPCODE_MQ_DESTROY
,
15676 length
, LPFC_SLI4_MBX_EMBED
);
15677 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
15679 mbox
->vport
= mq
->phba
->pport
;
15680 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15681 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
15682 /* The IOCTL status is embedded in the mailbox subheader. */
15683 shdr
= (union lpfc_sli4_cfg_shdr
*)
15684 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
15685 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15686 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15687 if (shdr_status
|| shdr_add_status
|| rc
) {
15688 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15689 "2507 MQ_DESTROY mailbox failed with "
15690 "status x%x add_status x%x, mbx status x%x\n",
15691 shdr_status
, shdr_add_status
, rc
);
15694 /* Remove mq from any list */
15695 list_del_init(&mq
->list
);
15696 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
15701 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
15702 * @wq: The queue structure associated with the queue to destroy.
15704 * This function destroys a queue, as detailed in @wq by sending an mailbox
15705 * command, specific to the type of queue, to the HBA.
15707 * The @wq struct is used to get the queue ID of the queue to destroy.
15709 * On success this function will return a zero. If the queue destroy mailbox
15710 * command fails this function will return -ENXIO.
15713 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
15715 LPFC_MBOXQ_t
*mbox
;
15716 int rc
, length
, status
= 0;
15717 uint32_t shdr_status
, shdr_add_status
;
15718 union lpfc_sli4_cfg_shdr
*shdr
;
15720 /* sanity check on queue memory */
15723 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15726 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
15727 sizeof(struct lpfc_sli4_cfg_mhdr
));
15728 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15729 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
15730 length
, LPFC_SLI4_MBX_EMBED
);
15731 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
15733 mbox
->vport
= wq
->phba
->pport
;
15734 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15735 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
15736 shdr
= (union lpfc_sli4_cfg_shdr
*)
15737 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
15738 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15739 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15740 if (shdr_status
|| shdr_add_status
|| rc
) {
15741 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15742 "2508 WQ_DESTROY mailbox failed with "
15743 "status x%x add_status x%x, mbx status x%x\n",
15744 shdr_status
, shdr_add_status
, rc
);
15747 /* Remove wq from any list */
15748 list_del_init(&wq
->list
);
15751 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
15756 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
15757 * @rq: The queue structure associated with the queue to destroy.
15759 * This function destroys a queue, as detailed in @rq by sending an mailbox
15760 * command, specific to the type of queue, to the HBA.
15762 * The @rq struct is used to get the queue ID of the queue to destroy.
15764 * On success this function will return a zero. If the queue destroy mailbox
15765 * command fails this function will return -ENXIO.
15768 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
15769 struct lpfc_queue
*drq
)
15771 LPFC_MBOXQ_t
*mbox
;
15772 int rc
, length
, status
= 0;
15773 uint32_t shdr_status
, shdr_add_status
;
15774 union lpfc_sli4_cfg_shdr
*shdr
;
15776 /* sanity check on queue memory */
15779 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15782 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
15783 sizeof(struct lpfc_sli4_cfg_mhdr
));
15784 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15785 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
15786 length
, LPFC_SLI4_MBX_EMBED
);
15787 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
15789 mbox
->vport
= hrq
->phba
->pport
;
15790 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15791 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
15792 /* The IOCTL status is embedded in the mailbox subheader. */
15793 shdr
= (union lpfc_sli4_cfg_shdr
*)
15794 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
15795 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15796 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15797 if (shdr_status
|| shdr_add_status
|| rc
) {
15798 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15799 "2509 RQ_DESTROY mailbox failed with "
15800 "status x%x add_status x%x, mbx status x%x\n",
15801 shdr_status
, shdr_add_status
, rc
);
15802 if (rc
!= MBX_TIMEOUT
)
15803 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
15806 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
15808 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
15809 shdr
= (union lpfc_sli4_cfg_shdr
*)
15810 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
15811 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15812 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15813 if (shdr_status
|| shdr_add_status
|| rc
) {
15814 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15815 "2510 RQ_DESTROY mailbox failed with "
15816 "status x%x add_status x%x, mbx status x%x\n",
15817 shdr_status
, shdr_add_status
, rc
);
15820 list_del_init(&hrq
->list
);
15821 list_del_init(&drq
->list
);
15822 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
15827 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
15828 * @phba: The virtual port for which this call being executed.
15829 * @pdma_phys_addr0: Physical address of the 1st SGL page.
15830 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
15831 * @xritag: the xritag that ties this io to the SGL pages.
15833 * This routine will post the sgl pages for the IO that has the xritag
15834 * that is in the iocbq structure. The xritag is assigned during iocbq
15835 * creation and persists for as long as the driver is loaded.
15836 * if the caller has fewer than 256 scatter gather segments to map then
15837 * pdma_phys_addr1 should be 0.
15838 * If the caller needs to map more than 256 scatter gather segment then
15839 * pdma_phys_addr1 should be a valid physical address.
15840 * physical address for SGLs must be 64 byte aligned.
15841 * If you are going to map 2 SGL's then the first one must have 256 entries
15842 * the second sgl can have between 1 and 256 entries.
15846 * -ENXIO, -ENOMEM - Failure
15849 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
15850 dma_addr_t pdma_phys_addr0
,
15851 dma_addr_t pdma_phys_addr1
,
15854 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
15855 LPFC_MBOXQ_t
*mbox
;
15857 uint32_t shdr_status
, shdr_add_status
;
15859 union lpfc_sli4_cfg_shdr
*shdr
;
15861 if (xritag
== NO_XRI
) {
15862 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15863 "0364 Invalid param:\n");
15867 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15871 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15872 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
15873 sizeof(struct lpfc_mbx_post_sgl_pages
) -
15874 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15876 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
15877 &mbox
->u
.mqe
.un
.post_sgl_pages
;
15878 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
15879 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
15881 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
15882 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
15883 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
15884 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
15886 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
15887 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
15888 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
15889 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
15890 if (!phba
->sli4_hba
.intr_enable
)
15891 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15893 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15894 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15896 /* The IOCTL status is embedded in the mailbox subheader. */
15897 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
15898 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15899 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15900 if (rc
!= MBX_TIMEOUT
)
15901 mempool_free(mbox
, phba
->mbox_mem_pool
);
15902 if (shdr_status
|| shdr_add_status
|| rc
) {
15903 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15904 "2511 POST_SGL mailbox failed with "
15905 "status x%x add_status x%x, mbx status x%x\n",
15906 shdr_status
, shdr_add_status
, rc
);
15912 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
15913 * @phba: pointer to lpfc hba data structure.
15915 * This routine is invoked to post rpi header templates to the
15916 * HBA consistent with the SLI-4 interface spec. This routine
15917 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15918 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15921 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
15922 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15925 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
15930 * Fetch the next logical xri. Because this index is logical,
15931 * the driver starts at 0 each time.
15933 spin_lock_irq(&phba
->hbalock
);
15934 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
15935 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
15936 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
15937 spin_unlock_irq(&phba
->hbalock
);
15940 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
15941 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
15943 spin_unlock_irq(&phba
->hbalock
);
15948 * lpfc_sli4_free_xri - Release an xri for reuse.
15949 * @phba: pointer to lpfc hba data structure.
15951 * This routine is invoked to release an xri to the pool of
15952 * available rpis maintained by the driver.
15955 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
15957 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
15958 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
15963 * lpfc_sli4_free_xri - Release an xri for reuse.
15964 * @phba: pointer to lpfc hba data structure.
15966 * This routine is invoked to release an xri to the pool of
15967 * available rpis maintained by the driver.
15970 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
15972 spin_lock_irq(&phba
->hbalock
);
15973 __lpfc_sli4_free_xri(phba
, xri
);
15974 spin_unlock_irq(&phba
->hbalock
);
15978 * lpfc_sli4_next_xritag - Get an xritag for the io
15979 * @phba: Pointer to HBA context object.
15981 * This function gets an xritag for the iocb. If there is no unused xritag
15982 * it will return 0xffff.
15983 * The function returns the allocated xritag if successful, else returns zero.
15984 * Zero is not a valid xritag.
15985 * The caller is not required to hold any lock.
15988 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
15990 uint16_t xri_index
;
15992 xri_index
= lpfc_sli4_alloc_xri(phba
);
15993 if (xri_index
== NO_XRI
)
15994 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
15995 "2004 Failed to allocate XRI.last XRITAG is %d"
15996 " Max XRI is %d, Used XRI is %d\n",
15998 phba
->sli4_hba
.max_cfg_param
.max_xri
,
15999 phba
->sli4_hba
.max_cfg_param
.xri_used
);
16004 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
16005 * @phba: pointer to lpfc hba data structure.
16006 * @post_sgl_list: pointer to els sgl entry list.
16007 * @count: number of els sgl entries on the list.
16009 * This routine is invoked to post a block of driver's sgl pages to the
16010 * HBA using non-embedded mailbox command. No Lock is held. This routine
16011 * is only called when the driver is loading and after all IO has been
16015 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
,
16016 struct list_head
*post_sgl_list
,
16019 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
16020 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
16021 struct sgl_page_pairs
*sgl_pg_pairs
;
16023 LPFC_MBOXQ_t
*mbox
;
16024 uint32_t reqlen
, alloclen
, pg_pairs
;
16026 uint16_t xritag_start
= 0;
16028 uint32_t shdr_status
, shdr_add_status
;
16029 union lpfc_sli4_cfg_shdr
*shdr
;
16031 reqlen
= post_cnt
* sizeof(struct sgl_page_pairs
) +
16032 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
16033 if (reqlen
> SLI4_PAGE_SIZE
) {
16034 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16035 "2559 Block sgl registration required DMA "
16036 "size (%d) great than a page\n", reqlen
);
16040 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16044 /* Allocate DMA memory and set up the non-embedded mailbox command */
16045 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16046 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
16047 LPFC_SLI4_MBX_NEMBED
);
16049 if (alloclen
< reqlen
) {
16050 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16051 "0285 Allocated DMA memory size (%d) is "
16052 "less than the requested DMA memory "
16053 "size (%d)\n", alloclen
, reqlen
);
16054 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16057 /* Set up the SGL pages in the non-embedded DMA pages */
16058 viraddr
= mbox
->sge_array
->addr
[0];
16059 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
16060 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
16063 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
16064 /* Set up the sge entry */
16065 sgl_pg_pairs
->sgl_pg0_addr_lo
=
16066 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
16067 sgl_pg_pairs
->sgl_pg0_addr_hi
=
16068 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
16069 sgl_pg_pairs
->sgl_pg1_addr_lo
=
16070 cpu_to_le32(putPaddrLow(0));
16071 sgl_pg_pairs
->sgl_pg1_addr_hi
=
16072 cpu_to_le32(putPaddrHigh(0));
16074 /* Keep the first xritag on the list */
16076 xritag_start
= sglq_entry
->sli4_xritag
;
16081 /* Complete initialization and perform endian conversion. */
16082 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
16083 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, post_cnt
);
16084 sgl
->word0
= cpu_to_le32(sgl
->word0
);
16086 if (!phba
->sli4_hba
.intr_enable
)
16087 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16089 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16090 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16092 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
16093 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16094 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16095 if (rc
!= MBX_TIMEOUT
)
16096 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16097 if (shdr_status
|| shdr_add_status
|| rc
) {
16098 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16099 "2513 POST_SGL_BLOCK mailbox command failed "
16100 "status x%x add_status x%x mbx status x%x\n",
16101 shdr_status
, shdr_add_status
, rc
);
16108 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
16109 * @phba: pointer to lpfc hba data structure.
16110 * @sblist: pointer to scsi buffer list.
16111 * @count: number of scsi buffers on the list.
16113 * This routine is invoked to post a block of @count scsi sgl pages from a
16114 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
16119 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
16120 struct list_head
*sblist
,
16123 struct lpfc_scsi_buf
*psb
;
16124 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
16125 struct sgl_page_pairs
*sgl_pg_pairs
;
16127 LPFC_MBOXQ_t
*mbox
;
16128 uint32_t reqlen
, alloclen
, pg_pairs
;
16130 uint16_t xritag_start
= 0;
16132 uint32_t shdr_status
, shdr_add_status
;
16133 dma_addr_t pdma_phys_bpl1
;
16134 union lpfc_sli4_cfg_shdr
*shdr
;
16136 /* Calculate the requested length of the dma memory */
16137 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
16138 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
16139 if (reqlen
> SLI4_PAGE_SIZE
) {
16140 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
16141 "0217 Block sgl registration required DMA "
16142 "size (%d) great than a page\n", reqlen
);
16145 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16147 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16148 "0283 Failed to allocate mbox cmd memory\n");
16152 /* Allocate DMA memory and set up the non-embedded mailbox command */
16153 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16154 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
16155 LPFC_SLI4_MBX_NEMBED
);
16157 if (alloclen
< reqlen
) {
16158 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16159 "2561 Allocated DMA memory size (%d) is "
16160 "less than the requested DMA memory "
16161 "size (%d)\n", alloclen
, reqlen
);
16162 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16166 /* Get the first SGE entry from the non-embedded DMA memory */
16167 viraddr
= mbox
->sge_array
->addr
[0];
16169 /* Set up the SGL pages in the non-embedded DMA pages */
16170 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
16171 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
16174 list_for_each_entry(psb
, sblist
, list
) {
16175 /* Set up the sge entry */
16176 sgl_pg_pairs
->sgl_pg0_addr_lo
=
16177 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
16178 sgl_pg_pairs
->sgl_pg0_addr_hi
=
16179 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
16180 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
16181 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
16183 pdma_phys_bpl1
= 0;
16184 sgl_pg_pairs
->sgl_pg1_addr_lo
=
16185 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
16186 sgl_pg_pairs
->sgl_pg1_addr_hi
=
16187 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
16188 /* Keep the first xritag on the list */
16190 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
16194 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
16195 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
16196 /* Perform endian conversion if necessary */
16197 sgl
->word0
= cpu_to_le32(sgl
->word0
);
16199 if (!phba
->sli4_hba
.intr_enable
)
16200 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16202 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16203 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16205 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
16206 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16207 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16208 if (rc
!= MBX_TIMEOUT
)
16209 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16210 if (shdr_status
|| shdr_add_status
|| rc
) {
16211 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16212 "2564 POST_SGL_BLOCK mailbox command failed "
16213 "status x%x add_status x%x mbx status x%x\n",
16214 shdr_status
, shdr_add_status
, rc
);
16221 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
16222 * @phba: pointer to lpfc_hba struct that the frame was received on
16223 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16225 * This function checks the fields in the @fc_hdr to see if the FC frame is a
16226 * valid type of frame that the LPFC driver will handle. This function will
16227 * return a zero if the frame is a valid frame or a non zero value when the
16228 * frame does not pass the check.
16231 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
16233 /* make rctl_names static to save stack space */
16234 struct fc_vft_header
*fc_vft_hdr
;
16235 uint32_t *header
= (uint32_t *) fc_hdr
;
16237 #define FC_RCTL_MDS_DIAGS 0xF4
16239 switch (fc_hdr
->fh_r_ctl
) {
16240 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
16241 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
16242 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
16243 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
16244 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
16245 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
16246 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
16247 case FC_RCTL_DD_CMD_STATUS
: /* command status */
16248 case FC_RCTL_ELS_REQ
: /* extended link services request */
16249 case FC_RCTL_ELS_REP
: /* extended link services reply */
16250 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
16251 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
16252 case FC_RCTL_BA_NOP
: /* basic link service NOP */
16253 case FC_RCTL_BA_ABTS
: /* basic link service abort */
16254 case FC_RCTL_BA_RMC
: /* remove connection */
16255 case FC_RCTL_BA_ACC
: /* basic accept */
16256 case FC_RCTL_BA_RJT
: /* basic reject */
16257 case FC_RCTL_BA_PRMT
:
16258 case FC_RCTL_ACK_1
: /* acknowledge_1 */
16259 case FC_RCTL_ACK_0
: /* acknowledge_0 */
16260 case FC_RCTL_P_RJT
: /* port reject */
16261 case FC_RCTL_F_RJT
: /* fabric reject */
16262 case FC_RCTL_P_BSY
: /* port busy */
16263 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
16264 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
16265 case FC_RCTL_LCR
: /* link credit reset */
16266 case FC_RCTL_MDS_DIAGS
: /* MDS Diagnostics */
16267 case FC_RCTL_END
: /* end */
16269 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
16270 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
16271 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
16272 return lpfc_fc_frame_check(phba
, fc_hdr
);
16277 #define FC_TYPE_VENDOR_UNIQUE 0xFF
16279 switch (fc_hdr
->fh_type
) {
16285 case FC_TYPE_VENDOR_UNIQUE
:
16293 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
16294 "2538 Received frame rctl:x%x, type:x%x, "
16295 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
16296 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
,
16297 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
16298 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
16299 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]),
16300 be32_to_cpu(header
[6]));
16303 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
16304 "2539 Dropped frame rctl:x%x type:x%x\n",
16305 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
16310 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
16311 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16313 * This function processes the FC header to retrieve the VFI from the VF
16314 * header, if one exists. This function will return the VFI if one exists
16315 * or 0 if no VSAN Header exists.
16318 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
16320 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
16322 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
16324 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
16328 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
16329 * @phba: Pointer to the HBA structure to search for the vport on
16330 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16331 * @fcfi: The FC Fabric ID that the frame came from
16333 * This function searches the @phba for a vport that matches the content of the
16334 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
16335 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
16336 * returns the matching vport pointer or NULL if unable to match frame to a
16339 static struct lpfc_vport
*
16340 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
16341 uint16_t fcfi
, uint32_t did
)
16343 struct lpfc_vport
**vports
;
16344 struct lpfc_vport
*vport
= NULL
;
16347 if (did
== Fabric_DID
)
16348 return phba
->pport
;
16349 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
16350 !(phba
->link_state
== LPFC_HBA_READY
))
16351 return phba
->pport
;
16353 vports
= lpfc_create_vport_work_array(phba
);
16354 if (vports
!= NULL
) {
16355 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
16356 if (phba
->fcf
.fcfi
== fcfi
&&
16357 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
16358 vports
[i
]->fc_myDID
== did
) {
16364 lpfc_destroy_vport_work_array(phba
, vports
);
16369 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
16370 * @vport: The vport to work on.
16372 * This function updates the receive sequence time stamp for this vport. The
16373 * receive sequence time stamp indicates the time that the last frame of the
16374 * the sequence that has been idle for the longest amount of time was received.
16375 * the driver uses this time stamp to indicate if any received sequences have
16379 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
16381 struct lpfc_dmabuf
*h_buf
;
16382 struct hbq_dmabuf
*dmabuf
= NULL
;
16384 /* get the oldest sequence on the rcv list */
16385 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
16386 struct lpfc_dmabuf
, list
);
16389 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16390 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
16394 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
16395 * @vport: The vport that the received sequences were sent to.
16397 * This function cleans up all outstanding received sequences. This is called
16398 * by the driver when a link event or user action invalidates all the received
16402 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
16404 struct lpfc_dmabuf
*h_buf
, *hnext
;
16405 struct lpfc_dmabuf
*d_buf
, *dnext
;
16406 struct hbq_dmabuf
*dmabuf
= NULL
;
16408 /* start with the oldest sequence on the rcv list */
16409 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
16410 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16411 list_del_init(&dmabuf
->hbuf
.list
);
16412 list_for_each_entry_safe(d_buf
, dnext
,
16413 &dmabuf
->dbuf
.list
, list
) {
16414 list_del_init(&d_buf
->list
);
16415 lpfc_in_buf_free(vport
->phba
, d_buf
);
16417 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
16422 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
16423 * @vport: The vport that the received sequences were sent to.
16425 * This function determines whether any received sequences have timed out by
16426 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
16427 * indicates that there is at least one timed out sequence this routine will
16428 * go through the received sequences one at a time from most inactive to most
16429 * active to determine which ones need to be cleaned up. Once it has determined
16430 * that a sequence needs to be cleaned up it will simply free up the resources
16431 * without sending an abort.
16434 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
16436 struct lpfc_dmabuf
*h_buf
, *hnext
;
16437 struct lpfc_dmabuf
*d_buf
, *dnext
;
16438 struct hbq_dmabuf
*dmabuf
= NULL
;
16439 unsigned long timeout
;
16440 int abort_count
= 0;
16442 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
16443 vport
->rcv_buffer_time_stamp
);
16444 if (list_empty(&vport
->rcv_buffer_list
) ||
16445 time_before(jiffies
, timeout
))
16447 /* start with the oldest sequence on the rcv list */
16448 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
16449 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16450 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
16451 dmabuf
->time_stamp
);
16452 if (time_before(jiffies
, timeout
))
16455 list_del_init(&dmabuf
->hbuf
.list
);
16456 list_for_each_entry_safe(d_buf
, dnext
,
16457 &dmabuf
->dbuf
.list
, list
) {
16458 list_del_init(&d_buf
->list
);
16459 lpfc_in_buf_free(vport
->phba
, d_buf
);
16461 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
16464 lpfc_update_rcv_time_stamp(vport
);
16468 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
16469 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
16471 * This function searches through the existing incomplete sequences that have
16472 * been sent to this @vport. If the frame matches one of the incomplete
16473 * sequences then the dbuf in the @dmabuf is added to the list of frames that
16474 * make up that sequence. If no sequence is found that matches this frame then
16475 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
16476 * This function returns a pointer to the first dmabuf in the sequence list that
16477 * the frame was linked to.
16479 static struct hbq_dmabuf
*
16480 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
16482 struct fc_frame_header
*new_hdr
;
16483 struct fc_frame_header
*temp_hdr
;
16484 struct lpfc_dmabuf
*d_buf
;
16485 struct lpfc_dmabuf
*h_buf
;
16486 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
16487 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
16490 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
16491 dmabuf
->time_stamp
= jiffies
;
16492 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16494 /* Use the hdr_buf to find the sequence that this frame belongs to */
16495 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
16496 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
16497 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
16498 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
16499 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
16501 /* found a pending sequence that matches this frame */
16502 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16507 * This indicates first frame received for this sequence.
16508 * Queue the buffer on the vport's rcv_buffer_list.
16510 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16511 lpfc_update_rcv_time_stamp(vport
);
16514 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
16515 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
16516 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
16517 list_del_init(&seq_dmabuf
->hbuf
.list
);
16518 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16519 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
16520 lpfc_update_rcv_time_stamp(vport
);
16523 /* move this sequence to the tail to indicate a young sequence */
16524 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16525 seq_dmabuf
->time_stamp
= jiffies
;
16526 lpfc_update_rcv_time_stamp(vport
);
16527 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
16528 temp_hdr
= dmabuf
->hbuf
.virt
;
16529 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
16532 /* find the correct place in the sequence to insert this frame */
16533 d_buf
= list_entry(seq_dmabuf
->dbuf
.list
.prev
, typeof(*d_buf
), list
);
16535 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
16536 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
16538 * If the frame's sequence count is greater than the frame on
16539 * the list then insert the frame right after this frame
16541 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
16542 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
16543 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
16548 if (&d_buf
->list
== &seq_dmabuf
->dbuf
.list
)
16550 d_buf
= list_entry(d_buf
->list
.prev
, typeof(*d_buf
), list
);
16559 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
16560 * @vport: pointer to a vitural port
16561 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16563 * This function tries to abort from the partially assembed sequence, described
16564 * by the information from basic abbort @dmabuf. It checks to see whether such
16565 * partially assembled sequence held by the driver. If so, it shall free up all
16566 * the frames from the partially assembled sequence.
16569 * true -- if there is matching partially assembled sequence present and all
16570 * the frames freed with the sequence;
16571 * false -- if there is no matching partially assembled sequence present so
16572 * nothing got aborted in the lower layer driver
16575 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
16576 struct hbq_dmabuf
*dmabuf
)
16578 struct fc_frame_header
*new_hdr
;
16579 struct fc_frame_header
*temp_hdr
;
16580 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
16581 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
16583 /* Use the hdr_buf to find the sequence that matches this frame */
16584 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
16585 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
16586 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16587 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
16588 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
16589 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
16590 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
16591 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
16593 /* found a pending sequence that matches this frame */
16594 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16598 /* Free up all the frames from the partially assembled sequence */
16600 list_for_each_entry_safe(d_buf
, n_buf
,
16601 &seq_dmabuf
->dbuf
.list
, list
) {
16602 list_del_init(&d_buf
->list
);
16603 lpfc_in_buf_free(vport
->phba
, d_buf
);
16611 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
16612 * @vport: pointer to a vitural port
16613 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16615 * This function tries to abort from the assembed sequence from upper level
16616 * protocol, described by the information from basic abbort @dmabuf. It
16617 * checks to see whether such pending context exists at upper level protocol.
16618 * If so, it shall clean up the pending context.
16621 * true -- if there is matching pending context of the sequence cleaned
16623 * false -- if there is no matching pending context of the sequence present
16627 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
16629 struct lpfc_hba
*phba
= vport
->phba
;
16632 /* Accepting abort at ulp with SLI4 only */
16633 if (phba
->sli_rev
< LPFC_SLI_REV4
)
16636 /* Register all caring upper level protocols to attend abort */
16637 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
16645 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
16646 * @phba: Pointer to HBA context object.
16647 * @cmd_iocbq: pointer to the command iocbq structure.
16648 * @rsp_iocbq: pointer to the response iocbq structure.
16650 * This function handles the sequence abort response iocb command complete
16651 * event. It properly releases the memory allocated to the sequence abort
16655 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
16656 struct lpfc_iocbq
*cmd_iocbq
,
16657 struct lpfc_iocbq
*rsp_iocbq
)
16659 struct lpfc_nodelist
*ndlp
;
16662 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
16663 lpfc_nlp_put(ndlp
);
16664 lpfc_nlp_not_used(ndlp
);
16665 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
16668 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
16669 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
16670 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16671 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
16672 rsp_iocbq
->iocb
.ulpStatus
,
16673 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
16677 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
16678 * @phba: Pointer to HBA context object.
16679 * @xri: xri id in transaction.
16681 * This function validates the xri maps to the known range of XRIs allocated an
16682 * used by the driver.
16685 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
16690 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
16691 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
16698 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
16699 * @phba: Pointer to HBA context object.
16700 * @fc_hdr: pointer to a FC frame header.
16702 * This function sends a basic response to a previous unsol sequence abort
16703 * event after aborting the sequence handling.
16706 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
16707 struct fc_frame_header
*fc_hdr
, bool aborted
)
16709 struct lpfc_hba
*phba
= vport
->phba
;
16710 struct lpfc_iocbq
*ctiocb
= NULL
;
16711 struct lpfc_nodelist
*ndlp
;
16712 uint16_t oxid
, rxid
, xri
, lxri
;
16713 uint32_t sid
, fctl
;
16717 if (!lpfc_is_link_up(phba
))
16720 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
16721 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
16722 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
16724 ndlp
= lpfc_findnode_did(vport
, sid
);
16726 ndlp
= lpfc_nlp_init(vport
, sid
);
16728 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
16729 "1268 Failed to allocate ndlp for "
16730 "oxid:x%x SID:x%x\n", oxid
, sid
);
16733 /* Put ndlp onto pport node list */
16734 lpfc_enqueue_node(vport
, ndlp
);
16735 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
16736 /* re-setup ndlp without removing from node list */
16737 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
16739 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
16740 "3275 Failed to active ndlp found "
16741 "for oxid:x%x SID:x%x\n", oxid
, sid
);
16746 /* Allocate buffer for rsp iocb */
16747 ctiocb
= lpfc_sli_get_iocbq(phba
);
16751 /* Extract the F_CTL field from FC_HDR */
16752 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
16754 icmd
= &ctiocb
->iocb
;
16755 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
16756 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
16757 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
16758 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
16759 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
16761 /* Fill in the rest of iocb fields */
16762 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
16763 icmd
->ulpBdeCount
= 0;
16765 icmd
->ulpClass
= CLASS3
;
16766 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
16767 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
16769 ctiocb
->iocb_cmpl
= NULL
;
16770 ctiocb
->vport
= phba
->pport
;
16771 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
16772 ctiocb
->sli4_lxritag
= NO_XRI
;
16773 ctiocb
->sli4_xritag
= NO_XRI
;
16775 if (fctl
& FC_FC_EX_CTX
)
16776 /* Exchange responder sent the abort so we
16782 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
16783 if (lxri
!= NO_XRI
)
16784 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
16785 (xri
== oxid
) ? rxid
: oxid
, 0);
16786 /* For BA_ABTS from exchange responder, if the logical xri with
16787 * the oxid maps to the FCP XRI range, the port no longer has
16788 * that exchange context, send a BLS_RJT. Override the IOCB for
16791 if ((fctl
& FC_FC_EX_CTX
) &&
16792 (lxri
> lpfc_sli4_get_iocb_cnt(phba
))) {
16793 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
16794 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
16795 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
16796 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
16799 /* If BA_ABTS failed to abort a partially assembled receive sequence,
16800 * the driver no longer has that exchange, send a BLS_RJT. Override
16801 * the IOCB for a BA_RJT.
16803 if (aborted
== false) {
16804 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
16805 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
16806 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
16807 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
16810 if (fctl
& FC_FC_EX_CTX
) {
16811 /* ABTS sent by responder to CT exchange, construction
16812 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
16813 * field and RX_ID from ABTS for RX_ID field.
16815 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
16817 /* ABTS sent by initiator to CT exchange, construction
16818 * of BA_ACC will need to allocate a new XRI as for the
16821 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
16823 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
16824 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
16826 /* Xmit CT abts response on exchange <xid> */
16827 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
16828 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
16829 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
16831 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
16832 if (rc
== IOCB_ERROR
) {
16833 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
16834 "2925 Failed to issue CT ABTS RSP x%x on "
16835 "xri x%x, Data x%x\n",
16836 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
16838 lpfc_nlp_put(ndlp
);
16839 ctiocb
->context1
= NULL
;
16840 lpfc_sli_release_iocbq(phba
, ctiocb
);
16845 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
16846 * @vport: Pointer to the vport on which this sequence was received
16847 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16849 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
16850 * receive sequence is only partially assembed by the driver, it shall abort
16851 * the partially assembled frames for the sequence. Otherwise, if the
16852 * unsolicited receive sequence has been completely assembled and passed to
16853 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
16854 * unsolicited sequence has been aborted. After that, it will issue a basic
16855 * accept to accept the abort.
16858 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
16859 struct hbq_dmabuf
*dmabuf
)
16861 struct lpfc_hba
*phba
= vport
->phba
;
16862 struct fc_frame_header fc_hdr
;
16866 /* Make a copy of fc_hdr before the dmabuf being released */
16867 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
16868 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
16870 if (fctl
& FC_FC_EX_CTX
) {
16871 /* ABTS by responder to exchange, no cleanup needed */
16874 /* ABTS by initiator to exchange, need to do cleanup */
16875 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
16876 if (aborted
== false)
16877 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
16879 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
16881 if (phba
->nvmet_support
) {
16882 lpfc_nvmet_rcv_unsol_abort(vport
, &fc_hdr
);
16886 /* Respond with BA_ACC or BA_RJT accordingly */
16887 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
16891 * lpfc_seq_complete - Indicates if a sequence is complete
16892 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16894 * This function checks the sequence, starting with the frame described by
16895 * @dmabuf, to see if all the frames associated with this sequence are present.
16896 * the frames associated with this sequence are linked to the @dmabuf using the
16897 * dbuf list. This function looks for two major things. 1) That the first frame
16898 * has a sequence count of zero. 2) There is a frame with last frame of sequence
16899 * set. 3) That there are no holes in the sequence count. The function will
16900 * return 1 when the sequence is complete, otherwise it will return 0.
16903 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
16905 struct fc_frame_header
*hdr
;
16906 struct lpfc_dmabuf
*d_buf
;
16907 struct hbq_dmabuf
*seq_dmabuf
;
16911 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16912 /* make sure first fame of sequence has a sequence count of zero */
16913 if (hdr
->fh_seq_cnt
!= seq_count
)
16915 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
16916 hdr
->fh_f_ctl
[1] << 8 |
16918 /* If last frame of sequence we can return success. */
16919 if (fctl
& FC_FC_END_SEQ
)
16921 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
16922 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
16923 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
16924 /* If there is a hole in the sequence count then fail. */
16925 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
16927 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
16928 hdr
->fh_f_ctl
[1] << 8 |
16930 /* If last frame of sequence we can return success. */
16931 if (fctl
& FC_FC_END_SEQ
)
16938 * lpfc_prep_seq - Prep sequence for ULP processing
16939 * @vport: Pointer to the vport on which this sequence was received
16940 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16942 * This function takes a sequence, described by a list of frames, and creates
16943 * a list of iocbq structures to describe the sequence. This iocbq list will be
16944 * used to issue to the generic unsolicited sequence handler. This routine
16945 * returns a pointer to the first iocbq in the list. If the function is unable
16946 * to allocate an iocbq then it throw out the received frames that were not
16947 * able to be described and return a pointer to the first iocbq. If unable to
16948 * allocate any iocbqs (including the first) this function will return NULL.
16950 static struct lpfc_iocbq
*
16951 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
16953 struct hbq_dmabuf
*hbq_buf
;
16954 struct lpfc_dmabuf
*d_buf
, *n_buf
;
16955 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
16956 struct fc_frame_header
*fc_hdr
;
16958 uint32_t len
, tot_len
;
16959 struct ulp_bde64
*pbde
;
16961 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
16962 /* remove from receive buffer list */
16963 list_del_init(&seq_dmabuf
->hbuf
.list
);
16964 lpfc_update_rcv_time_stamp(vport
);
16965 /* get the Remote Port's SID */
16966 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
16968 /* Get an iocbq struct to fill in. */
16969 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
16971 /* Initialize the first IOCB. */
16972 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
16973 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
16974 first_iocbq
->vport
= vport
;
16976 /* Check FC Header to see what TYPE of frame we are rcv'ing */
16977 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
16978 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
16979 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
16980 sli4_did_from_fc_hdr(fc_hdr
);
16981 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
16983 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
16984 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
16985 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
16986 be16_to_cpu(fc_hdr
->fh_ox_id
);
16987 /* iocbq is prepped for internal consumption. Physical vpi. */
16988 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
16989 vport
->phba
->vpi_ids
[vport
->vpi
];
16990 /* put the first buffer into the first IOCBq */
16991 tot_len
= bf_get(lpfc_rcqe_length
,
16992 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
16994 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
16995 first_iocbq
->context3
= NULL
;
16996 first_iocbq
->iocb
.ulpBdeCount
= 1;
16997 if (tot_len
> LPFC_DATA_BUF_SIZE
)
16998 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
16999 LPFC_DATA_BUF_SIZE
;
17001 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= tot_len
;
17003 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
17005 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
17007 iocbq
= first_iocbq
;
17009 * Each IOCBq can have two Buffers assigned, so go through the list
17010 * of buffers for this sequence and save two buffers in each IOCBq
17012 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
17014 lpfc_in_buf_free(vport
->phba
, d_buf
);
17017 if (!iocbq
->context3
) {
17018 iocbq
->context3
= d_buf
;
17019 iocbq
->iocb
.ulpBdeCount
++;
17020 /* We need to get the size out of the right CQE */
17021 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17022 len
= bf_get(lpfc_rcqe_length
,
17023 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
17024 pbde
= (struct ulp_bde64
*)
17025 &iocbq
->iocb
.unsli3
.sli3Words
[4];
17026 if (len
> LPFC_DATA_BUF_SIZE
)
17027 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
17029 pbde
->tus
.f
.bdeSize
= len
;
17031 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
17034 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
17037 first_iocbq
->iocb
.ulpStatus
=
17038 IOSTAT_FCP_RSP_ERROR
;
17039 first_iocbq
->iocb
.un
.ulpWord
[4] =
17040 IOERR_NO_RESOURCES
;
17042 lpfc_in_buf_free(vport
->phba
, d_buf
);
17045 /* We need to get the size out of the right CQE */
17046 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17047 len
= bf_get(lpfc_rcqe_length
,
17048 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
17049 iocbq
->context2
= d_buf
;
17050 iocbq
->context3
= NULL
;
17051 iocbq
->iocb
.ulpBdeCount
= 1;
17052 if (len
> LPFC_DATA_BUF_SIZE
)
17053 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
17054 LPFC_DATA_BUF_SIZE
;
17056 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= len
;
17059 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
17061 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
17062 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
17065 return first_iocbq
;
17069 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
17070 struct hbq_dmabuf
*seq_dmabuf
)
17072 struct fc_frame_header
*fc_hdr
;
17073 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
17074 struct lpfc_hba
*phba
= vport
->phba
;
17076 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
17077 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
17079 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17080 "2707 Ring %d handler: Failed to allocate "
17081 "iocb Rctl x%x Type x%x received\n",
17083 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
17086 if (!lpfc_complete_unsol_iocb(phba
,
17087 phba
->sli4_hba
.els_wq
->pring
,
17088 iocbq
, fc_hdr
->fh_r_ctl
,
17090 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17091 "2540 Ring %d handler: unexpected Rctl "
17092 "x%x Type x%x received\n",
17094 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
17096 /* Free iocb created in lpfc_prep_seq */
17097 list_for_each_entry_safe(curr_iocb
, next_iocb
,
17098 &iocbq
->list
, list
) {
17099 list_del_init(&curr_iocb
->list
);
17100 lpfc_sli_release_iocbq(phba
, curr_iocb
);
17102 lpfc_sli_release_iocbq(phba
, iocbq
);
17106 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
17107 struct lpfc_iocbq
*rspiocb
)
17109 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
;
17111 if (pcmd
&& pcmd
->virt
)
17112 dma_pool_free(phba
->lpfc_drb_pool
, pcmd
->virt
, pcmd
->phys
);
17114 lpfc_sli_release_iocbq(phba
, cmdiocb
);
17118 lpfc_sli4_handle_mds_loopback(struct lpfc_vport
*vport
,
17119 struct hbq_dmabuf
*dmabuf
)
17121 struct fc_frame_header
*fc_hdr
;
17122 struct lpfc_hba
*phba
= vport
->phba
;
17123 struct lpfc_iocbq
*iocbq
= NULL
;
17124 union lpfc_wqe
*wqe
;
17125 struct lpfc_dmabuf
*pcmd
= NULL
;
17126 uint32_t frame_len
;
17129 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17130 frame_len
= bf_get(lpfc_rcqe_length
, &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17132 /* Send the received frame back */
17133 iocbq
= lpfc_sli_get_iocbq(phba
);
17137 /* Allocate buffer for command payload */
17138 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
17140 pcmd
->virt
= dma_pool_alloc(phba
->lpfc_drb_pool
, GFP_KERNEL
,
17142 if (!pcmd
|| !pcmd
->virt
)
17145 INIT_LIST_HEAD(&pcmd
->list
);
17147 /* copyin the payload */
17148 memcpy(pcmd
->virt
, dmabuf
->dbuf
.virt
, frame_len
);
17150 /* fill in BDE's for command */
17151 iocbq
->iocb
.un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pcmd
->phys
);
17152 iocbq
->iocb
.un
.xseq64
.bdl
.addrLow
= putPaddrLow(pcmd
->phys
);
17153 iocbq
->iocb
.un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
17154 iocbq
->iocb
.un
.xseq64
.bdl
.bdeSize
= frame_len
;
17156 iocbq
->context2
= pcmd
;
17157 iocbq
->vport
= vport
;
17158 iocbq
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
17159 iocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
17162 * Setup rest of the iocb as though it were a WQE
17163 * Build the SEND_FRAME WQE
17165 wqe
= (union lpfc_wqe
*)&iocbq
->iocb
;
17167 wqe
->send_frame
.frame_len
= frame_len
;
17168 wqe
->send_frame
.fc_hdr_wd0
= be32_to_cpu(*((uint32_t *)fc_hdr
));
17169 wqe
->send_frame
.fc_hdr_wd1
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 1));
17170 wqe
->send_frame
.fc_hdr_wd2
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 2));
17171 wqe
->send_frame
.fc_hdr_wd3
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 3));
17172 wqe
->send_frame
.fc_hdr_wd4
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 4));
17173 wqe
->send_frame
.fc_hdr_wd5
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 5));
17175 iocbq
->iocb
.ulpCommand
= CMD_SEND_FRAME
;
17176 iocbq
->iocb
.ulpLe
= 1;
17177 iocbq
->iocb_cmpl
= lpfc_sli4_mds_loopback_cmpl
;
17178 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocbq
, 0);
17179 if (rc
== IOCB_ERROR
)
17182 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17186 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
17187 "2023 Unable to process MDS loopback frame\n");
17188 if (pcmd
&& pcmd
->virt
)
17189 dma_pool_free(phba
->lpfc_drb_pool
, pcmd
->virt
, pcmd
->phys
);
17192 lpfc_sli_release_iocbq(phba
, iocbq
);
17193 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17197 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
17198 * @phba: Pointer to HBA context object.
17200 * This function is called with no lock held. This function processes all
17201 * the received buffers and gives it to upper layers when a received buffer
17202 * indicates that it is the final frame in the sequence. The interrupt
17203 * service routine processes received buffers at interrupt contexts.
17204 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
17205 * appropriate receive function when the final frame in a sequence is received.
17208 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
17209 struct hbq_dmabuf
*dmabuf
)
17211 struct hbq_dmabuf
*seq_dmabuf
;
17212 struct fc_frame_header
*fc_hdr
;
17213 struct lpfc_vport
*vport
;
17217 /* Process each received buffer */
17218 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17220 /* check to see if this a valid type of frame */
17221 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
17222 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17226 if ((bf_get(lpfc_cqe_code
,
17227 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
17228 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
17229 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17231 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
17232 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17234 if (fc_hdr
->fh_r_ctl
== 0xF4 && fc_hdr
->fh_type
== 0xFF) {
17235 vport
= phba
->pport
;
17236 /* Handle MDS Loopback frames */
17237 lpfc_sli4_handle_mds_loopback(vport
, dmabuf
);
17241 /* d_id this frame is directed to */
17242 did
= sli4_did_from_fc_hdr(fc_hdr
);
17244 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
, did
);
17246 /* throw out the frame */
17247 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17251 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
17252 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
17253 (did
!= Fabric_DID
)) {
17255 * Throw out the frame if we are not pt2pt.
17256 * The pt2pt protocol allows for discovery frames
17257 * to be received without a registered VPI.
17259 if (!(vport
->fc_flag
& FC_PT2PT
) ||
17260 (phba
->link_state
== LPFC_HBA_READY
)) {
17261 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17266 /* Handle the basic abort sequence (BA_ABTS) event */
17267 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
17268 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
17272 /* Link this frame */
17273 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
17275 /* unable to add frame to vport - throw it out */
17276 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17279 /* If not last frame in sequence continue processing frames. */
17280 if (!lpfc_seq_complete(seq_dmabuf
))
17283 /* Send the complete sequence to the upper layer protocol */
17284 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
17288 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
17289 * @phba: pointer to lpfc hba data structure.
17291 * This routine is invoked to post rpi header templates to the
17292 * HBA consistent with the SLI-4 interface spec. This routine
17293 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17294 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17296 * This routine does not require any locks. It's usage is expected
17297 * to be driver load or reset recovery when the driver is
17302 * -EIO - The mailbox failed to complete successfully.
17303 * When this error occurs, the driver is not guaranteed
17304 * to have any rpi regions posted to the device and
17305 * must either attempt to repost the regions or take a
17309 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
17311 struct lpfc_rpi_hdr
*rpi_page
;
17315 /* SLI4 ports that support extents do not require RPI headers. */
17316 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
17318 if (phba
->sli4_hba
.extents_in_use
)
17321 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
17323 * Assign the rpi headers a physical rpi only if the driver
17324 * has not initialized those resources. A port reset only
17325 * needs the headers posted.
17327 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
17329 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
17331 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
17332 if (rc
!= MBX_SUCCESS
) {
17333 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17334 "2008 Error %d posting all rpi "
17342 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
17343 LPFC_RPI_RSRC_RDY
);
17348 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
17349 * @phba: pointer to lpfc hba data structure.
17350 * @rpi_page: pointer to the rpi memory region.
17352 * This routine is invoked to post a single rpi header to the
17353 * HBA consistent with the SLI-4 interface spec. This memory region
17354 * maps up to 64 rpi context regions.
17358 * -ENOMEM - No available memory
17359 * -EIO - The mailbox failed to complete successfully.
17362 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
17364 LPFC_MBOXQ_t
*mboxq
;
17365 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
17367 uint32_t shdr_status
, shdr_add_status
;
17368 union lpfc_sli4_cfg_shdr
*shdr
;
17370 /* SLI4 ports that support extents do not require RPI headers. */
17371 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
17373 if (phba
->sli4_hba
.extents_in_use
)
17376 /* The port is notified of the header region via a mailbox command. */
17377 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17379 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17380 "2001 Unable to allocate memory for issuing "
17381 "SLI_CONFIG_SPECIAL mailbox command\n");
17385 /* Post all rpi memory regions to the port. */
17386 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
17387 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
17388 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
17389 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
17390 sizeof(struct lpfc_sli4_cfg_mhdr
),
17391 LPFC_SLI4_MBX_EMBED
);
17394 /* Post the physical rpi to the port for this rpi header. */
17395 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
17396 rpi_page
->start_rpi
);
17397 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
17398 hdr_tmpl
, rpi_page
->page_count
);
17400 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
17401 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
17402 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
17403 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
17404 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17405 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17406 if (rc
!= MBX_TIMEOUT
)
17407 mempool_free(mboxq
, phba
->mbox_mem_pool
);
17408 if (shdr_status
|| shdr_add_status
|| rc
) {
17409 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17410 "2514 POST_RPI_HDR mailbox failed with "
17411 "status x%x add_status x%x, mbx status x%x\n",
17412 shdr_status
, shdr_add_status
, rc
);
17416 * The next_rpi stores the next logical module-64 rpi value used
17417 * to post physical rpis in subsequent rpi postings.
17419 spin_lock_irq(&phba
->hbalock
);
17420 phba
->sli4_hba
.next_rpi
= rpi_page
->next_rpi
;
17421 spin_unlock_irq(&phba
->hbalock
);
17427 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
17428 * @phba: pointer to lpfc hba data structure.
17430 * This routine is invoked to post rpi header templates to the
17431 * HBA consistent with the SLI-4 interface spec. This routine
17432 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17433 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17436 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
17437 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
17440 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
17443 uint16_t max_rpi
, rpi_limit
;
17444 uint16_t rpi_remaining
, lrpi
= 0;
17445 struct lpfc_rpi_hdr
*rpi_hdr
;
17446 unsigned long iflag
;
17449 * Fetch the next logical rpi. Because this index is logical,
17450 * the driver starts at 0 each time.
17452 spin_lock_irqsave(&phba
->hbalock
, iflag
);
17453 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
17454 rpi_limit
= phba
->sli4_hba
.next_rpi
;
17456 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
17457 if (rpi
>= rpi_limit
)
17458 rpi
= LPFC_RPI_ALLOC_ERROR
;
17460 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
17461 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
17462 phba
->sli4_hba
.rpi_count
++;
17464 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
17465 "0001 rpi:%x max:%x lim:%x\n",
17466 (int) rpi
, max_rpi
, rpi_limit
);
17469 * Don't try to allocate more rpi header regions if the device limit
17470 * has been exhausted.
17472 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
17473 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
17474 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17479 * RPI header postings are not required for SLI4 ports capable of
17482 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
17483 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17488 * If the driver is running low on rpi resources, allocate another
17489 * page now. Note that the next_rpi value is used because
17490 * it represents how many are actually in use whereas max_rpi notes
17491 * how many are supported max by the device.
17493 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
17494 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17495 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
17496 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
17498 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17499 "2002 Error Could not grow rpi "
17502 lrpi
= rpi_hdr
->start_rpi
;
17503 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
17504 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
17512 * lpfc_sli4_free_rpi - Release an rpi for reuse.
17513 * @phba: pointer to lpfc hba data structure.
17515 * This routine is invoked to release an rpi to the pool of
17516 * available rpis maintained by the driver.
17519 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
17521 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
17522 phba
->sli4_hba
.rpi_count
--;
17523 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
17528 * lpfc_sli4_free_rpi - Release an rpi for reuse.
17529 * @phba: pointer to lpfc hba data structure.
17531 * This routine is invoked to release an rpi to the pool of
17532 * available rpis maintained by the driver.
17535 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
17537 spin_lock_irq(&phba
->hbalock
);
17538 __lpfc_sli4_free_rpi(phba
, rpi
);
17539 spin_unlock_irq(&phba
->hbalock
);
17543 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
17544 * @phba: pointer to lpfc hba data structure.
17546 * This routine is invoked to remove the memory region that
17547 * provided rpi via a bitmask.
17550 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
17552 kfree(phba
->sli4_hba
.rpi_bmask
);
17553 kfree(phba
->sli4_hba
.rpi_ids
);
17554 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
17558 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
17559 * @phba: pointer to lpfc hba data structure.
17561 * This routine is invoked to remove the memory region that
17562 * provided rpi via a bitmask.
17565 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
17566 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
17568 LPFC_MBOXQ_t
*mboxq
;
17569 struct lpfc_hba
*phba
= ndlp
->phba
;
17572 /* The port is notified of the header region via a mailbox command. */
17573 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17577 /* Post all rpi memory regions to the port. */
17578 lpfc_resume_rpi(mboxq
, ndlp
);
17580 mboxq
->mbox_cmpl
= cmpl
;
17581 mboxq
->context1
= arg
;
17582 mboxq
->context2
= ndlp
;
17584 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17585 mboxq
->vport
= ndlp
->vport
;
17586 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17587 if (rc
== MBX_NOT_FINISHED
) {
17588 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17589 "2010 Resume RPI Mailbox failed "
17590 "status %d, mbxStatus x%x\n", rc
,
17591 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
17592 mempool_free(mboxq
, phba
->mbox_mem_pool
);
17599 * lpfc_sli4_init_vpi - Initialize a vpi with the port
17600 * @vport: Pointer to the vport for which the vpi is being initialized
17602 * This routine is invoked to activate a vpi with the port.
17606 * -Evalue otherwise
17609 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
17611 LPFC_MBOXQ_t
*mboxq
;
17613 int retval
= MBX_SUCCESS
;
17615 struct lpfc_hba
*phba
= vport
->phba
;
17616 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17619 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
17620 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
17621 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
17622 if (rc
!= MBX_SUCCESS
) {
17623 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
17624 "2022 INIT VPI Mailbox failed "
17625 "status %d, mbxStatus x%x\n", rc
,
17626 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
17629 if (rc
!= MBX_TIMEOUT
)
17630 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
17636 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
17637 * @phba: pointer to lpfc hba data structure.
17638 * @mboxq: Pointer to mailbox object.
17640 * This routine is invoked to manually add a single FCF record. The caller
17641 * must pass a completely initialized FCF_Record. This routine takes
17642 * care of the nonembedded mailbox operations.
17645 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
17648 union lpfc_sli4_cfg_shdr
*shdr
;
17649 uint32_t shdr_status
, shdr_add_status
;
17651 virt_addr
= mboxq
->sge_array
->addr
[0];
17652 /* The IOCTL status is embedded in the mailbox subheader. */
17653 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
17654 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17655 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17657 if ((shdr_status
|| shdr_add_status
) &&
17658 (shdr_status
!= STATUS_FCF_IN_USE
))
17659 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17660 "2558 ADD_FCF_RECORD mailbox failed with "
17661 "status x%x add_status x%x\n",
17662 shdr_status
, shdr_add_status
);
17664 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17668 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
17669 * @phba: pointer to lpfc hba data structure.
17670 * @fcf_record: pointer to the initialized fcf record to add.
17672 * This routine is invoked to manually add a single FCF record. The caller
17673 * must pass a completely initialized FCF_Record. This routine takes
17674 * care of the nonembedded mailbox operations.
17677 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
17680 LPFC_MBOXQ_t
*mboxq
;
17683 struct lpfc_mbx_sge sge
;
17684 uint32_t alloc_len
, req_len
;
17687 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17689 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17690 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
17694 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
17697 /* Allocate DMA memory and set up the non-embedded mailbox command */
17698 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
17699 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
17700 req_len
, LPFC_SLI4_MBX_NEMBED
);
17701 if (alloc_len
< req_len
) {
17702 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17703 "2523 Allocated DMA memory size (x%x) is "
17704 "less than the requested DMA memory "
17705 "size (x%x)\n", alloc_len
, req_len
);
17706 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17711 * Get the first SGE entry from the non-embedded DMA memory. This
17712 * routine only uses a single SGE.
17714 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
17715 virt_addr
= mboxq
->sge_array
->addr
[0];
17717 * Configure the FCF record for FCFI 0. This is the driver's
17718 * hardcoded default and gets used in nonFIP mode.
17720 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
17721 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
17722 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
17725 * Copy the fcf_index and the FCF Record Data. The data starts after
17726 * the FCoE header plus word10. The data copy needs to be endian
17729 bytep
+= sizeof(uint32_t);
17730 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
17731 mboxq
->vport
= phba
->pport
;
17732 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
17733 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17734 if (rc
== MBX_NOT_FINISHED
) {
17735 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17736 "2515 ADD_FCF_RECORD mailbox failed with "
17737 "status 0x%x\n", rc
);
17738 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17747 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
17748 * @phba: pointer to lpfc hba data structure.
17749 * @fcf_record: pointer to the fcf record to write the default data.
17750 * @fcf_index: FCF table entry index.
17752 * This routine is invoked to build the driver's default FCF record. The
17753 * values used are hardcoded. This routine handles memory initialization.
17757 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
17758 struct fcf_record
*fcf_record
,
17759 uint16_t fcf_index
)
17761 memset(fcf_record
, 0, sizeof(struct fcf_record
));
17762 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
17763 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
17764 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
17765 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
17766 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
17767 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
17768 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
17769 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
17770 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
17771 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
17772 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
17773 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
17774 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
17775 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
17776 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
17777 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
17778 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
17779 /* Set the VLAN bit map */
17780 if (phba
->valid_vlan
) {
17781 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
17782 = 1 << (phba
->vlan_id
% 8);
17787 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
17788 * @phba: pointer to lpfc hba data structure.
17789 * @fcf_index: FCF table entry offset.
17791 * This routine is invoked to scan the entire FCF table by reading FCF
17792 * record and processing it one at a time starting from the @fcf_index
17793 * for initial FCF discovery or fast FCF failover rediscovery.
17795 * Return 0 if the mailbox command is submitted successfully, none 0
17799 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
17802 LPFC_MBOXQ_t
*mboxq
;
17804 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
17805 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
17806 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17808 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17809 "2000 Failed to allocate mbox for "
17812 goto fail_fcf_scan
;
17814 /* Construct the read FCF record mailbox command */
17815 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
17818 goto fail_fcf_scan
;
17820 /* Issue the mailbox command asynchronously */
17821 mboxq
->vport
= phba
->pport
;
17822 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
17824 spin_lock_irq(&phba
->hbalock
);
17825 phba
->hba_flag
|= FCF_TS_INPROG
;
17826 spin_unlock_irq(&phba
->hbalock
);
17828 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17829 if (rc
== MBX_NOT_FINISHED
)
17832 /* Reset eligible FCF count for new scan */
17833 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
17834 phba
->fcf
.eligible_fcf_cnt
= 0;
17840 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17841 /* FCF scan failed, clear FCF_TS_INPROG flag */
17842 spin_lock_irq(&phba
->hbalock
);
17843 phba
->hba_flag
&= ~FCF_TS_INPROG
;
17844 spin_unlock_irq(&phba
->hbalock
);
17850 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
17851 * @phba: pointer to lpfc hba data structure.
17852 * @fcf_index: FCF table entry offset.
17854 * This routine is invoked to read an FCF record indicated by @fcf_index
17855 * and to use it for FLOGI roundrobin FCF failover.
17857 * Return 0 if the mailbox command is submitted successfully, none 0
17861 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
17864 LPFC_MBOXQ_t
*mboxq
;
17866 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17868 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
17869 "2763 Failed to allocate mbox for "
17872 goto fail_fcf_read
;
17874 /* Construct the read FCF record mailbox command */
17875 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
17878 goto fail_fcf_read
;
17880 /* Issue the mailbox command asynchronously */
17881 mboxq
->vport
= phba
->pport
;
17882 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
17883 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17884 if (rc
== MBX_NOT_FINISHED
)
17890 if (error
&& mboxq
)
17891 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17896 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
17897 * @phba: pointer to lpfc hba data structure.
17898 * @fcf_index: FCF table entry offset.
17900 * This routine is invoked to read an FCF record indicated by @fcf_index to
17901 * determine whether it's eligible for FLOGI roundrobin failover list.
17903 * Return 0 if the mailbox command is submitted successfully, none 0
17907 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
17910 LPFC_MBOXQ_t
*mboxq
;
17912 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17914 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
17915 "2758 Failed to allocate mbox for "
17918 goto fail_fcf_read
;
17920 /* Construct the read FCF record mailbox command */
17921 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
17924 goto fail_fcf_read
;
17926 /* Issue the mailbox command asynchronously */
17927 mboxq
->vport
= phba
->pport
;
17928 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
17929 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17930 if (rc
== MBX_NOT_FINISHED
)
17936 if (error
&& mboxq
)
17937 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17942 * lpfc_check_next_fcf_pri_level
17943 * phba pointer to the lpfc_hba struct for this port.
17944 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
17945 * routine when the rr_bmask is empty. The FCF indecies are put into the
17946 * rr_bmask based on their priority level. Starting from the highest priority
17947 * to the lowest. The most likely FCF candidate will be in the highest
17948 * priority group. When this routine is called it searches the fcf_pri list for
17949 * next lowest priority group and repopulates the rr_bmask with only those
17952 * 1=success 0=failure
17955 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
17957 uint16_t next_fcf_pri
;
17958 uint16_t last_index
;
17959 struct lpfc_fcf_pri
*fcf_pri
;
17963 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
17964 LPFC_SLI4_FCF_TBL_INDX_MAX
);
17965 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
17966 "3060 Last IDX %d\n", last_index
);
17968 /* Verify the priority list has 2 or more entries */
17969 spin_lock_irq(&phba
->hbalock
);
17970 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
17971 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
17972 spin_unlock_irq(&phba
->hbalock
);
17973 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
17974 "3061 Last IDX %d\n", last_index
);
17975 return 0; /* Empty rr list */
17977 spin_unlock_irq(&phba
->hbalock
);
17981 * Clear the rr_bmask and set all of the bits that are at this
17984 memset(phba
->fcf
.fcf_rr_bmask
, 0,
17985 sizeof(*phba
->fcf
.fcf_rr_bmask
));
17986 spin_lock_irq(&phba
->hbalock
);
17987 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
17988 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
17991 * the 1st priority that has not FLOGI failed
17992 * will be the highest.
17995 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
17996 spin_unlock_irq(&phba
->hbalock
);
17997 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
17998 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
17999 fcf_pri
->fcf_rec
.fcf_index
);
18003 spin_lock_irq(&phba
->hbalock
);
18006 * if next_fcf_pri was not set above and the list is not empty then
18007 * we have failed flogis on all of them. So reset flogi failed
18008 * and start at the beginning.
18010 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
18011 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
18012 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
18014 * the 1st priority that has not FLOGI failed
18015 * will be the highest.
18018 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
18019 spin_unlock_irq(&phba
->hbalock
);
18020 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
18021 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
18022 fcf_pri
->fcf_rec
.fcf_index
);
18026 spin_lock_irq(&phba
->hbalock
);
18030 spin_unlock_irq(&phba
->hbalock
);
18035 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
18036 * @phba: pointer to lpfc hba data structure.
18038 * This routine is to get the next eligible FCF record index in a round
18039 * robin fashion. If the next eligible FCF record index equals to the
18040 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
18041 * shall be returned, otherwise, the next eligible FCF record's index
18042 * shall be returned.
18045 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
18047 uint16_t next_fcf_index
;
18050 /* Search start from next bit of currently registered FCF index */
18051 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
18054 /* Determine the next fcf index to check */
18055 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
18056 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
18057 LPFC_SLI4_FCF_TBL_INDX_MAX
,
18060 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
18061 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18063 * If we have wrapped then we need to clear the bits that
18064 * have been tested so that we can detect when we should
18065 * change the priority level.
18067 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
18068 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
18072 /* Check roundrobin failover list empty condition */
18073 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
18074 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
18076 * If next fcf index is not found check if there are lower
18077 * Priority level fcf's in the fcf_priority list.
18078 * Set up the rr_bmask with all of the avaiable fcf bits
18079 * at that level and continue the selection process.
18081 if (lpfc_check_next_fcf_pri_level(phba
))
18082 goto initial_priority
;
18083 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
18084 "2844 No roundrobin failover FCF available\n");
18085 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
18086 return LPFC_FCOE_FCF_NEXT_NONE
;
18088 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
18089 "3063 Only FCF available idx %d, flag %x\n",
18091 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
18092 return next_fcf_index
;
18096 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
18097 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
18098 LPFC_FCF_FLOGI_FAILED
) {
18099 if (list_is_singular(&phba
->fcf
.fcf_pri_list
))
18100 return LPFC_FCOE_FCF_NEXT_NONE
;
18102 goto next_priority
;
18105 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18106 "2845 Get next roundrobin failover FCF (x%x)\n",
18109 return next_fcf_index
;
18113 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
18114 * @phba: pointer to lpfc hba data structure.
18116 * This routine sets the FCF record index in to the eligible bmask for
18117 * roundrobin failover search. It checks to make sure that the index
18118 * does not go beyond the range of the driver allocated bmask dimension
18119 * before setting the bit.
18121 * Returns 0 if the index bit successfully set, otherwise, it returns
18125 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18127 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18128 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18129 "2610 FCF (x%x) reached driver's book "
18130 "keeping dimension:x%x\n",
18131 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
18134 /* Set the eligible FCF record index bmask */
18135 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
18137 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18138 "2790 Set FCF (x%x) to roundrobin FCF failover "
18139 "bmask\n", fcf_index
);
18145 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
18146 * @phba: pointer to lpfc hba data structure.
18148 * This routine clears the FCF record index from the eligible bmask for
18149 * roundrobin failover search. It checks to make sure that the index
18150 * does not go beyond the range of the driver allocated bmask dimension
18151 * before clearing the bit.
18154 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18156 struct lpfc_fcf_pri
*fcf_pri
, *fcf_pri_next
;
18157 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18158 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18159 "2762 FCF (x%x) reached driver's book "
18160 "keeping dimension:x%x\n",
18161 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
18164 /* Clear the eligible FCF record index bmask */
18165 spin_lock_irq(&phba
->hbalock
);
18166 list_for_each_entry_safe(fcf_pri
, fcf_pri_next
, &phba
->fcf
.fcf_pri_list
,
18168 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
18169 list_del_init(&fcf_pri
->list
);
18173 spin_unlock_irq(&phba
->hbalock
);
18174 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
18176 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18177 "2791 Clear FCF (x%x) from roundrobin failover "
18178 "bmask\n", fcf_index
);
18182 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
18183 * @phba: pointer to lpfc hba data structure.
18185 * This routine is the completion routine for the rediscover FCF table mailbox
18186 * command. If the mailbox command returned failure, it will try to stop the
18187 * FCF rediscover wait timer.
18190 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
18192 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
18193 uint32_t shdr_status
, shdr_add_status
;
18195 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
18197 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
18198 &redisc_fcf
->header
.cfg_shdr
.response
);
18199 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
18200 &redisc_fcf
->header
.cfg_shdr
.response
);
18201 if (shdr_status
|| shdr_add_status
) {
18202 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18203 "2746 Requesting for FCF rediscovery failed "
18204 "status x%x add_status x%x\n",
18205 shdr_status
, shdr_add_status
);
18206 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
18207 spin_lock_irq(&phba
->hbalock
);
18208 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
18209 spin_unlock_irq(&phba
->hbalock
);
18211 * CVL event triggered FCF rediscover request failed,
18212 * last resort to re-try current registered FCF entry.
18214 lpfc_retry_pport_discovery(phba
);
18216 spin_lock_irq(&phba
->hbalock
);
18217 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
18218 spin_unlock_irq(&phba
->hbalock
);
18220 * DEAD FCF event triggered FCF rediscover request
18221 * failed, last resort to fail over as a link down
18222 * to FCF registration.
18224 lpfc_sli4_fcf_dead_failthrough(phba
);
18227 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18228 "2775 Start FCF rediscover quiescent timer\n");
18230 * Start FCF rediscovery wait timer for pending FCF
18231 * before rescan FCF record table.
18233 lpfc_fcf_redisc_wait_start_timer(phba
);
18236 mempool_free(mbox
, phba
->mbox_mem_pool
);
18240 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
18241 * @phba: pointer to lpfc hba data structure.
18243 * This routine is invoked to request for rediscovery of the entire FCF table
18247 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
18249 LPFC_MBOXQ_t
*mbox
;
18250 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
18253 /* Cancel retry delay timers to all vports before FCF rediscover */
18254 lpfc_cancel_all_vport_retry_delay_timer(phba
);
18256 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18258 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18259 "2745 Failed to allocate mbox for "
18260 "requesting FCF rediscover.\n");
18264 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
18265 sizeof(struct lpfc_sli4_cfg_mhdr
));
18266 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
18267 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
18268 length
, LPFC_SLI4_MBX_EMBED
);
18270 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
18271 /* Set count to 0 for invalidating the entire FCF database */
18272 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
18274 /* Issue the mailbox command asynchronously */
18275 mbox
->vport
= phba
->pport
;
18276 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
18277 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
18279 if (rc
== MBX_NOT_FINISHED
) {
18280 mempool_free(mbox
, phba
->mbox_mem_pool
);
18287 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
18288 * @phba: pointer to lpfc hba data structure.
18290 * This function is the failover routine as a last resort to the FCF DEAD
18291 * event when driver failed to perform fast FCF failover.
18294 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
18296 uint32_t link_state
;
18299 * Last resort as FCF DEAD event failover will treat this as
18300 * a link down, but save the link state because we don't want
18301 * it to be changed to Link Down unless it is already down.
18303 link_state
= phba
->link_state
;
18304 lpfc_linkdown(phba
);
18305 phba
->link_state
= link_state
;
18307 /* Unregister FCF if no devices connected to it */
18308 lpfc_unregister_unused_fcf(phba
);
18312 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
18313 * @phba: pointer to lpfc hba data structure.
18314 * @rgn23_data: pointer to configure region 23 data.
18316 * This function gets SLI3 port configure region 23 data through memory dump
18317 * mailbox command. When it successfully retrieves data, the size of the data
18318 * will be returned, otherwise, 0 will be returned.
18321 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
18323 LPFC_MBOXQ_t
*pmb
= NULL
;
18325 uint32_t offset
= 0;
18331 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18333 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18334 "2600 failed to allocate mailbox memory\n");
18340 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
18341 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
18343 if (rc
!= MBX_SUCCESS
) {
18344 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
18345 "2601 failed to read config "
18346 "region 23, rc 0x%x Status 0x%x\n",
18347 rc
, mb
->mbxStatus
);
18348 mb
->un
.varDmp
.word_cnt
= 0;
18351 * dump mem may return a zero when finished or we got a
18352 * mailbox error, either way we are done.
18354 if (mb
->un
.varDmp
.word_cnt
== 0)
18356 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
18357 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
18359 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
18360 rgn23_data
+ offset
,
18361 mb
->un
.varDmp
.word_cnt
);
18362 offset
+= mb
->un
.varDmp
.word_cnt
;
18363 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
18365 mempool_free(pmb
, phba
->mbox_mem_pool
);
18370 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
18371 * @phba: pointer to lpfc hba data structure.
18372 * @rgn23_data: pointer to configure region 23 data.
18374 * This function gets SLI4 port configure region 23 data through memory dump
18375 * mailbox command. When it successfully retrieves data, the size of the data
18376 * will be returned, otherwise, 0 will be returned.
18379 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
18381 LPFC_MBOXQ_t
*mboxq
= NULL
;
18382 struct lpfc_dmabuf
*mp
= NULL
;
18383 struct lpfc_mqe
*mqe
;
18384 uint32_t data_length
= 0;
18390 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18392 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18393 "3105 failed to allocate mailbox memory\n");
18397 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
18399 mqe
= &mboxq
->u
.mqe
;
18400 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
18401 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
18404 data_length
= mqe
->un
.mb_words
[5];
18405 if (data_length
== 0)
18407 if (data_length
> DMP_RGN23_SIZE
) {
18411 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
18413 mempool_free(mboxq
, phba
->mbox_mem_pool
);
18415 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
18418 return data_length
;
18422 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
18423 * @phba: pointer to lpfc hba data structure.
18425 * This function read region 23 and parse TLV for port status to
18426 * decide if the user disaled the port. If the TLV indicates the
18427 * port is disabled, the hba_flag is set accordingly.
18430 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
18432 uint8_t *rgn23_data
= NULL
;
18433 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
18434 uint32_t offset
= 0;
18436 /* Get adapter Region 23 data */
18437 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
18441 if (phba
->sli_rev
< LPFC_SLI_REV4
)
18442 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
18444 if_type
= bf_get(lpfc_sli_intf_if_type
,
18445 &phba
->sli4_hba
.sli_intf
);
18446 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
18448 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
18454 /* Check the region signature first */
18455 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
18456 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18457 "2619 Config region 23 has bad signature\n");
18462 /* Check the data structure version */
18463 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
18464 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18465 "2620 Config region 23 has bad version\n");
18470 /* Parse TLV entries in the region */
18471 while (offset
< data_size
) {
18472 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
18475 * If the TLV is not driver specific TLV or driver id is
18476 * not linux driver id, skip the record.
18478 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
18479 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
18480 (rgn23_data
[offset
+ 3] != 0)) {
18481 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18485 /* Driver found a driver specific TLV in the config region */
18486 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
18491 * Search for configured port state sub-TLV.
18493 while ((offset
< data_size
) &&
18494 (tlv_offset
< sub_tlv_len
)) {
18495 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
18500 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
18501 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18502 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18506 /* This HBA contains PORT_STE configured */
18507 if (!rgn23_data
[offset
+ 2])
18508 phba
->hba_flag
|= LINK_DISABLED
;
18520 * lpfc_wr_object - write an object to the firmware
18521 * @phba: HBA structure that indicates port to create a queue on.
18522 * @dmabuf_list: list of dmabufs to write to the port.
18523 * @size: the total byte value of the objects to write to the port.
18524 * @offset: the current offset to be used to start the transfer.
18526 * This routine will create a wr_object mailbox command to send to the port.
18527 * the mailbox command will be constructed using the dma buffers described in
18528 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
18529 * BDEs that the imbedded mailbox can support. The @offset variable will be
18530 * used to indicate the starting offset of the transfer and will also return
18531 * the offset after the write object mailbox has completed. @size is used to
18532 * determine the end of the object and whether the eof bit should be set.
18534 * Return 0 is successful and offset will contain the the new offset to use
18535 * for the next write.
18536 * Return negative value for error cases.
18539 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
18540 uint32_t size
, uint32_t *offset
)
18542 struct lpfc_mbx_wr_object
*wr_object
;
18543 LPFC_MBOXQ_t
*mbox
;
18545 uint32_t shdr_status
, shdr_add_status
;
18547 union lpfc_sli4_cfg_shdr
*shdr
;
18548 struct lpfc_dmabuf
*dmabuf
;
18549 uint32_t written
= 0;
18551 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18555 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
18556 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
18557 sizeof(struct lpfc_mbx_wr_object
) -
18558 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
18560 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
18561 wr_object
->u
.request
.write_offset
= *offset
;
18562 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
18563 wr_object
->u
.request
.object_name
[0] =
18564 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
18565 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
18566 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
18567 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
18569 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
18570 wr_object
->u
.request
.bde
[i
].addrHigh
=
18571 putPaddrHigh(dmabuf
->phys
);
18572 if (written
+ SLI4_PAGE_SIZE
>= size
) {
18573 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
18575 written
+= (size
- written
);
18576 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
18578 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
18580 written
+= SLI4_PAGE_SIZE
;
18584 wr_object
->u
.request
.bde_count
= i
;
18585 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
18586 if (!phba
->sli4_hba
.intr_enable
)
18587 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
18589 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
18590 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
18592 /* The IOCTL status is embedded in the mailbox subheader. */
18593 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
18594 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
18595 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
18596 if (rc
!= MBX_TIMEOUT
)
18597 mempool_free(mbox
, phba
->mbox_mem_pool
);
18598 if (shdr_status
|| shdr_add_status
|| rc
) {
18599 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18600 "3025 Write Object mailbox failed with "
18601 "status x%x add_status x%x, mbx status x%x\n",
18602 shdr_status
, shdr_add_status
, rc
);
18605 *offset
+= wr_object
->u
.response
.actual_write_length
;
18610 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
18611 * @vport: pointer to vport data structure.
18613 * This function iterate through the mailboxq and clean up all REG_LOGIN
18614 * and REG_VPI mailbox commands associated with the vport. This function
18615 * is called when driver want to restart discovery of the vport due to
18616 * a Clear Virtual Link event.
18619 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
18621 struct lpfc_hba
*phba
= vport
->phba
;
18622 LPFC_MBOXQ_t
*mb
, *nextmb
;
18623 struct lpfc_dmabuf
*mp
;
18624 struct lpfc_nodelist
*ndlp
;
18625 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
18626 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
18627 LIST_HEAD(mbox_cmd_list
);
18628 uint8_t restart_loop
;
18630 /* Clean up internally queued mailbox commands with the vport */
18631 spin_lock_irq(&phba
->hbalock
);
18632 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
18633 if (mb
->vport
!= vport
)
18636 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
18637 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
18640 list_del(&mb
->list
);
18641 list_add_tail(&mb
->list
, &mbox_cmd_list
);
18643 /* Clean up active mailbox command with the vport */
18644 mb
= phba
->sli
.mbox_active
;
18645 if (mb
&& (mb
->vport
== vport
)) {
18646 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
18647 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
18648 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
18649 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18650 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
18651 /* Put reference count for delayed processing */
18652 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
18653 /* Unregister the RPI when mailbox complete */
18654 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
18657 /* Cleanup any mailbox completions which are not yet processed */
18660 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
18662 * If this mailox is already processed or it is
18663 * for another vport ignore it.
18665 if ((mb
->vport
!= vport
) ||
18666 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
18669 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
18670 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
18673 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
18674 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18675 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
18676 /* Unregister the RPI when mailbox complete */
18677 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
18679 spin_unlock_irq(&phba
->hbalock
);
18680 spin_lock(shost
->host_lock
);
18681 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
18682 spin_unlock(shost
->host_lock
);
18683 spin_lock_irq(&phba
->hbalock
);
18687 } while (restart_loop
);
18689 spin_unlock_irq(&phba
->hbalock
);
18691 /* Release the cleaned-up mailbox commands */
18692 while (!list_empty(&mbox_cmd_list
)) {
18693 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
18694 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18695 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
18697 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
18700 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
18701 mb
->context2
= NULL
;
18703 spin_lock(shost
->host_lock
);
18704 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
18705 spin_unlock(shost
->host_lock
);
18706 lpfc_nlp_put(ndlp
);
18709 mempool_free(mb
, phba
->mbox_mem_pool
);
18712 /* Release the ndlp with the cleaned-up active mailbox command */
18713 if (act_mbx_ndlp
) {
18714 spin_lock(shost
->host_lock
);
18715 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
18716 spin_unlock(shost
->host_lock
);
18717 lpfc_nlp_put(act_mbx_ndlp
);
18722 * lpfc_drain_txq - Drain the txq
18723 * @phba: Pointer to HBA context object.
18725 * This function attempt to submit IOCBs on the txq
18726 * to the adapter. For SLI4 adapters, the txq contains
18727 * ELS IOCBs that have been deferred because the there
18728 * are no SGLs. This congestion can occur with large
18729 * vport counts during node discovery.
18733 lpfc_drain_txq(struct lpfc_hba
*phba
)
18735 LIST_HEAD(completions
);
18736 struct lpfc_sli_ring
*pring
;
18737 struct lpfc_iocbq
*piocbq
= NULL
;
18738 unsigned long iflags
= 0;
18739 char *fail_msg
= NULL
;
18740 struct lpfc_sglq
*sglq
;
18741 union lpfc_wqe128 wqe128
;
18742 union lpfc_wqe
*wqe
= (union lpfc_wqe
*) &wqe128
;
18743 uint32_t txq_cnt
= 0;
18745 pring
= lpfc_phba_elsring(phba
);
18746 if (unlikely(!pring
))
18749 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18750 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
18754 if (txq_cnt
> pring
->txq_max
)
18755 pring
->txq_max
= txq_cnt
;
18757 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18759 while (!list_empty(&pring
->txq
)) {
18760 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18762 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
18764 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18765 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18766 "2823 txq empty and txq_cnt is %d\n ",
18770 sglq
= __lpfc_sli_get_els_sglq(phba
, piocbq
);
18772 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
18773 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18778 /* The xri and iocb resources secured,
18779 * attempt to issue request
18781 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
18782 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
18783 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
18784 fail_msg
= "to convert bpl to sgl";
18785 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, wqe
))
18786 fail_msg
= "to convert iocb to wqe";
18787 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, wqe
))
18788 fail_msg
= " - Wq is full";
18790 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
18793 /* Failed means we can't issue and need to cancel */
18794 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18795 "2822 IOCB failed %s iotag 0x%x "
18798 piocbq
->iotag
, piocbq
->sli4_xritag
);
18799 list_add_tail(&piocbq
->list
, &completions
);
18801 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18804 /* Cancel all the IOCBs that cannot be issued */
18805 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
18806 IOERR_SLI_ABORTED
);
18812 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
18813 * @phba: Pointer to HBA context object.
18814 * @pwqe: Pointer to command WQE.
18815 * @sglq: Pointer to the scatter gather queue object.
18817 * This routine converts the bpl or bde that is in the WQE
18818 * to a sgl list for the sli4 hardware. The physical address
18819 * of the bpl/bde is converted back to a virtual address.
18820 * If the WQE contains a BPL then the list of BDE's is
18821 * converted to sli4_sge's. If the WQE contains a single
18822 * BDE then it is converted to a single sli_sge.
18823 * The WQE is still in cpu endianness so the contents of
18824 * the bpl can be used without byte swapping.
18826 * Returns valid XRI = Success, NO_XRI = Failure.
18829 lpfc_wqe_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pwqeq
,
18830 struct lpfc_sglq
*sglq
)
18832 uint16_t xritag
= NO_XRI
;
18833 struct ulp_bde64
*bpl
= NULL
;
18834 struct ulp_bde64 bde
;
18835 struct sli4_sge
*sgl
= NULL
;
18836 struct lpfc_dmabuf
*dmabuf
;
18837 union lpfc_wqe
*wqe
;
18840 uint32_t offset
= 0; /* accumulated offset in the sg request list */
18841 int inbound
= 0; /* number of sg reply entries inbound from firmware */
18844 if (!pwqeq
|| !sglq
)
18847 sgl
= (struct sli4_sge
*)sglq
->sgl
;
18849 pwqeq
->iocb
.ulpIoTag
= pwqeq
->iotag
;
18851 cmd
= bf_get(wqe_cmnd
, &wqe
->generic
.wqe_com
);
18852 if (cmd
== CMD_XMIT_BLS_RSP64_WQE
)
18853 return sglq
->sli4_xritag
;
18854 numBdes
= pwqeq
->rsvd2
;
18856 /* The addrHigh and addrLow fields within the WQE
18857 * have not been byteswapped yet so there is no
18858 * need to swap them back.
18860 if (pwqeq
->context3
)
18861 dmabuf
= (struct lpfc_dmabuf
*)pwqeq
->context3
;
18865 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
18869 for (i
= 0; i
< numBdes
; i
++) {
18870 /* Should already be byte swapped. */
18871 sgl
->addr_hi
= bpl
->addrHigh
;
18872 sgl
->addr_lo
= bpl
->addrLow
;
18874 sgl
->word2
= le32_to_cpu(sgl
->word2
);
18875 if ((i
+1) == numBdes
)
18876 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
18878 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
18879 /* swap the size field back to the cpu so we
18880 * can assign it to the sgl.
18882 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
18883 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
18884 /* The offsets in the sgl need to be accumulated
18885 * separately for the request and reply lists.
18886 * The request is always first, the reply follows.
18889 case CMD_GEN_REQUEST64_WQE
:
18890 /* add up the reply sg entries */
18891 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
18893 /* first inbound? reset the offset */
18896 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
18897 bf_set(lpfc_sli4_sge_type
, sgl
,
18898 LPFC_SGE_TYPE_DATA
);
18899 offset
+= bde
.tus
.f
.bdeSize
;
18901 case CMD_FCP_TRSP64_WQE
:
18902 bf_set(lpfc_sli4_sge_offset
, sgl
, 0);
18903 bf_set(lpfc_sli4_sge_type
, sgl
,
18904 LPFC_SGE_TYPE_DATA
);
18906 case CMD_FCP_TSEND64_WQE
:
18907 case CMD_FCP_TRECEIVE64_WQE
:
18908 bf_set(lpfc_sli4_sge_type
, sgl
,
18909 bpl
->tus
.f
.bdeFlags
);
18913 offset
+= bde
.tus
.f
.bdeSize
;
18914 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
18917 sgl
->word2
= cpu_to_le32(sgl
->word2
);
18921 } else if (wqe
->gen_req
.bde
.tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64
) {
18922 /* The addrHigh and addrLow fields of the BDE have not
18923 * been byteswapped yet so they need to be swapped
18924 * before putting them in the sgl.
18926 sgl
->addr_hi
= cpu_to_le32(wqe
->gen_req
.bde
.addrHigh
);
18927 sgl
->addr_lo
= cpu_to_le32(wqe
->gen_req
.bde
.addrLow
);
18928 sgl
->word2
= le32_to_cpu(sgl
->word2
);
18929 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
18930 sgl
->word2
= cpu_to_le32(sgl
->word2
);
18931 sgl
->sge_len
= cpu_to_le32(wqe
->gen_req
.bde
.tus
.f
.bdeSize
);
18933 return sglq
->sli4_xritag
;
18937 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
18938 * @phba: Pointer to HBA context object.
18939 * @ring_number: Base sli ring number
18940 * @pwqe: Pointer to command WQE.
18943 lpfc_sli4_issue_wqe(struct lpfc_hba
*phba
, uint32_t ring_number
,
18944 struct lpfc_iocbq
*pwqe
)
18946 union lpfc_wqe
*wqe
= &pwqe
->wqe
;
18947 struct lpfc_nvmet_rcv_ctx
*ctxp
;
18948 struct lpfc_queue
*wq
;
18949 struct lpfc_sglq
*sglq
;
18950 struct lpfc_sli_ring
*pring
;
18951 unsigned long iflags
;
18954 /* NVME_LS and NVME_LS ABTS requests. */
18955 if (pwqe
->iocb_flag
& LPFC_IO_NVME_LS
) {
18956 pring
= phba
->sli4_hba
.nvmels_wq
->pring
;
18957 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18958 sglq
= __lpfc_sli_get_els_sglq(phba
, pwqe
);
18960 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18963 pwqe
->sli4_lxritag
= sglq
->sli4_lxritag
;
18964 pwqe
->sli4_xritag
= sglq
->sli4_xritag
;
18965 if (lpfc_wqe_bpl2sgl(phba
, pwqe
, sglq
) == NO_XRI
) {
18966 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18969 bf_set(wqe_xri_tag
, &pwqe
->wqe
.xmit_bls_rsp
.wqe_com
,
18970 pwqe
->sli4_xritag
);
18971 ret
= lpfc_sli4_wq_put(phba
->sli4_hba
.nvmels_wq
, wqe
);
18973 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18977 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
18978 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18982 /* NVME_FCREQ and NVME_ABTS requests */
18983 if (pwqe
->iocb_flag
& LPFC_IO_NVME
) {
18984 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
18985 pring
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
]->pring
;
18987 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18988 wq
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
];
18989 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
,
18990 phba
->sli4_hba
.nvme_cq
[pwqe
->hba_wqidx
]->queue_id
);
18991 ret
= lpfc_sli4_wq_put(wq
, wqe
);
18993 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18996 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
18997 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19001 /* NVMET requests */
19002 if (pwqe
->iocb_flag
& LPFC_IO_NVMET
) {
19003 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19004 pring
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
]->pring
;
19006 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19007 ctxp
= pwqe
->context2
;
19008 sglq
= ctxp
->ctxbuf
->sglq
;
19009 if (pwqe
->sli4_xritag
== NO_XRI
) {
19010 pwqe
->sli4_lxritag
= sglq
->sli4_lxritag
;
19011 pwqe
->sli4_xritag
= sglq
->sli4_xritag
;
19013 bf_set(wqe_xri_tag
, &pwqe
->wqe
.xmit_bls_rsp
.wqe_com
,
19014 pwqe
->sli4_xritag
);
19015 wq
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
];
19016 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
,
19017 phba
->sli4_hba
.nvme_cq
[pwqe
->hba_wqidx
]->queue_id
);
19018 ret
= lpfc_sli4_wq_put(wq
, wqe
);
19020 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19023 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
19024 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);