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);
133 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 0);
134 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
135 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
136 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
137 /* ensure WQE bcopy flushed before doorbell write */
140 /* Update the host index before invoking device */
141 host_index
= q
->host_index
;
147 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
148 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
149 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
, host_index
);
150 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
151 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
152 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
153 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
157 writel(doorbell
.word0
, q
->db_regaddr
);
163 * lpfc_sli4_wq_release - Updates internal hba index for WQ
164 * @q: The Work Queue to operate on.
165 * @index: The index to advance the hba index to.
167 * This routine will update the HBA index of a queue to reflect consumption of
168 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
169 * an entry the host calls this function to update the queue's internal
170 * pointers. This routine returns the number of entries that were consumed by
174 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
176 uint32_t released
= 0;
178 /* sanity check on queue memory */
182 if (q
->hba_index
== index
)
185 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
187 } while (q
->hba_index
!= index
);
192 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
193 * @q: The Mailbox Queue to operate on.
194 * @wqe: The Mailbox Queue Entry to put on the Work queue.
196 * This routine will copy the contents of @mqe to the next available entry on
197 * the @q. This function will then ring the Work Queue Doorbell to signal the
198 * HBA to start processing the Work Queue Entry. This function returns 0 if
199 * successful. If no entries are available on @q then this function will return
201 * The caller is expected to hold the hbalock when calling this routine.
204 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
206 struct lpfc_mqe
*temp_mqe
;
207 struct lpfc_register doorbell
;
209 /* sanity check on queue memory */
212 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
214 /* If the host has not yet processed the next entry then we are done */
215 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
217 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
218 /* Save off the mailbox pointer for completion */
219 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
221 /* Update the host index before invoking device */
222 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
226 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
227 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
228 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
233 * lpfc_sli4_mq_release - Updates internal hba index for MQ
234 * @q: The Mailbox Queue to operate on.
236 * This routine will update the HBA index of a queue to reflect consumption of
237 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
238 * an entry the host calls this function to update the queue's internal
239 * pointers. This routine returns the number of entries that were consumed by
243 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
245 /* sanity check on queue memory */
249 /* Clear the mailbox pointer for completion */
250 q
->phba
->mbox
= NULL
;
251 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
256 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
257 * @q: The Event Queue to get the first valid EQE from
259 * This routine will get the first valid Event Queue Entry from @q, update
260 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
261 * the Queue (no more work to do), or the Queue is full of EQEs that have been
262 * processed, but not popped back to the HBA then this routine will return NULL.
264 static struct lpfc_eqe
*
265 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
267 struct lpfc_eqe
*eqe
;
270 /* sanity check on queue memory */
273 eqe
= q
->qe
[q
->hba_index
].eqe
;
275 /* If the next EQE is not valid then we are done */
276 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
278 /* If the host has not yet processed the next entry then we are done */
279 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
280 if (idx
== q
->host_index
)
286 * insert barrier for instruction interlock : data from the hardware
287 * must have the valid bit checked before it can be copied and acted
288 * upon. Speculative instructions were allowing a bcopy at the start
289 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
290 * after our return, to copy data before the valid bit check above
291 * was done. As such, some of the copied data was stale. The barrier
292 * ensures the check is before any data is copied.
299 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
300 * @q: The Event Queue to disable interrupts
304 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
306 struct lpfc_register doorbell
;
309 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
310 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
311 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
312 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
313 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
314 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
318 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
319 * @q: The Event Queue that the host has completed processing for.
320 * @arm: Indicates whether the host wants to arms this CQ.
322 * This routine will mark all Event Queue Entries on @q, from the last
323 * known completed entry to the last entry that was processed, as completed
324 * by clearing the valid bit for each completion queue entry. Then it will
325 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
326 * The internal host index in the @q will be updated by this routine to indicate
327 * that the host has finished processing the entries. The @arm parameter
328 * indicates that the queue should be rearmed when ringing the doorbell.
330 * This function will return the number of EQEs that were popped.
333 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
335 uint32_t released
= 0;
336 struct lpfc_eqe
*temp_eqe
;
337 struct lpfc_register doorbell
;
339 /* sanity check on queue memory */
343 /* while there are valid entries */
344 while (q
->hba_index
!= q
->host_index
) {
345 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
346 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
348 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
350 if (unlikely(released
== 0 && !arm
))
353 /* ring doorbell for number popped */
356 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
357 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
359 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
360 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
361 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
362 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
363 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
364 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
365 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
366 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
367 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
372 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
373 * @q: The Completion Queue to get the first valid CQE from
375 * This routine will get the first valid Completion Queue Entry from @q, update
376 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
377 * the Queue (no more work to do), or the Queue is full of CQEs that have been
378 * processed, but not popped back to the HBA then this routine will return NULL.
380 static struct lpfc_cqe
*
381 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
383 struct lpfc_cqe
*cqe
;
386 /* sanity check on queue memory */
390 /* If the next CQE is not valid then we are done */
391 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
393 /* If the host has not yet processed the next entry then we are done */
394 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
395 if (idx
== q
->host_index
)
398 cqe
= q
->qe
[q
->hba_index
].cqe
;
402 * insert barrier for instruction interlock : data from the hardware
403 * must have the valid bit checked before it can be copied and acted
404 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
405 * instructions allowing action on content before valid bit checked,
406 * add barrier here as well. May not be needed as "content" is a
407 * single 32-bit entity here (vs multi word structure for cq's).
414 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
415 * @q: The Completion Queue that the host has completed processing for.
416 * @arm: Indicates whether the host wants to arms this CQ.
418 * This routine will mark all Completion queue entries on @q, from the last
419 * known completed entry to the last entry that was processed, as completed
420 * by clearing the valid bit for each completion queue entry. Then it will
421 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
422 * The internal host index in the @q will be updated by this routine to indicate
423 * that the host has finished processing the entries. The @arm parameter
424 * indicates that the queue should be rearmed when ringing the doorbell.
426 * This function will return the number of CQEs that were released.
429 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
431 uint32_t released
= 0;
432 struct lpfc_cqe
*temp_qe
;
433 struct lpfc_register doorbell
;
435 /* sanity check on queue memory */
438 /* while there are valid entries */
439 while (q
->hba_index
!= q
->host_index
) {
440 temp_qe
= q
->qe
[q
->host_index
].cqe
;
441 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
443 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
445 if (unlikely(released
== 0 && !arm
))
448 /* ring doorbell for number popped */
451 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
452 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
453 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
454 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
455 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
456 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
457 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
462 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
463 * @q: The Header Receive Queue to operate on.
464 * @wqe: The Receive Queue Entry to put on the Receive queue.
466 * This routine will copy the contents of @wqe to the next available entry on
467 * the @q. This function will then ring the Receive Queue Doorbell to signal the
468 * HBA to start processing the Receive Queue Entry. This function returns the
469 * index that the rqe was copied to if successful. If no entries are available
470 * on @q then this function will return -ENOMEM.
471 * The caller is expected to hold the hbalock when calling this routine.
474 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
475 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
477 struct lpfc_rqe
*temp_hrqe
;
478 struct lpfc_rqe
*temp_drqe
;
479 struct lpfc_register doorbell
;
483 /* sanity check on queue memory */
484 if (unlikely(!hq
) || unlikely(!dq
))
486 hq_put_index
= hq
->host_index
;
487 dq_put_index
= dq
->host_index
;
488 temp_hrqe
= hq
->qe
[hq_put_index
].rqe
;
489 temp_drqe
= dq
->qe
[dq_put_index
].rqe
;
491 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
493 if (hq_put_index
!= dq_put_index
)
495 /* If the host has not yet processed the next entry then we are done */
496 if (((hq_put_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
498 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
499 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
501 /* Update the host index to point to the next slot */
502 hq
->host_index
= ((hq_put_index
+ 1) % hq
->entry_count
);
503 dq
->host_index
= ((dq_put_index
+ 1) % dq
->entry_count
);
506 /* Ring The Header Receive Queue Doorbell */
507 if (!(hq
->host_index
% hq
->entry_repost
)) {
509 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
510 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
512 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
513 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
514 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
516 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
518 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
522 writel(doorbell
.word0
, hq
->db_regaddr
);
528 * lpfc_sli4_rq_release - Updates internal hba index for RQ
529 * @q: The Header Receive Queue to operate on.
531 * This routine will update the HBA index of a queue to reflect consumption of
532 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
533 * consumed an entry the host calls this function to update the queue's
534 * internal pointers. This routine returns the number of entries that were
535 * consumed by the HBA.
538 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
540 /* sanity check on queue memory */
541 if (unlikely(!hq
) || unlikely(!dq
))
544 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
546 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
547 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
552 * lpfc_cmd_iocb - Get next command iocb entry in the ring
553 * @phba: Pointer to HBA context object.
554 * @pring: Pointer to driver SLI ring object.
556 * This function returns pointer to next command iocb entry
557 * in the command ring. The caller must hold hbalock to prevent
558 * other threads consume the next command iocb.
559 * SLI-2/SLI-3 provide different sized iocbs.
561 static inline IOCB_t
*
562 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
564 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
565 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
569 * lpfc_resp_iocb - Get next response iocb entry in the ring
570 * @phba: Pointer to HBA context object.
571 * @pring: Pointer to driver SLI ring object.
573 * This function returns pointer to next response iocb entry
574 * in the response ring. The caller must hold hbalock to make sure
575 * that no other thread consume the next response iocb.
576 * SLI-2/SLI-3 provide different sized iocbs.
578 static inline IOCB_t
*
579 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
581 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
582 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
586 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
587 * @phba: Pointer to HBA context object.
589 * This function is called with hbalock held. This function
590 * allocates a new driver iocb object from the iocb pool. If the
591 * allocation is successful, it returns pointer to the newly
592 * allocated iocb object else it returns NULL.
595 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
597 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
598 struct lpfc_iocbq
* iocbq
= NULL
;
600 lockdep_assert_held(&phba
->hbalock
);
602 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
605 if (phba
->iocb_cnt
> phba
->iocb_max
)
606 phba
->iocb_max
= phba
->iocb_cnt
;
611 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
612 * @phba: Pointer to HBA context object.
613 * @xritag: XRI value.
615 * This function clears the sglq pointer from the array of acive
616 * sglq's. The xritag that is passed in is used to index into the
617 * array. Before the xritag can be used it needs to be adjusted
618 * by subtracting the xribase.
620 * Returns sglq ponter = success, NULL = Failure.
623 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
625 struct lpfc_sglq
*sglq
;
627 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
628 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
633 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
634 * @phba: Pointer to HBA context object.
635 * @xritag: XRI value.
637 * This function returns the sglq pointer from the array of acive
638 * sglq's. The xritag that is passed in is used to index into the
639 * array. Before the xritag can be used it needs to be adjusted
640 * by subtracting the xribase.
642 * Returns sglq ponter = success, NULL = Failure.
645 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
647 struct lpfc_sglq
*sglq
;
649 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
654 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
655 * @phba: Pointer to HBA context object.
656 * @xritag: xri used in this exchange.
657 * @rrq: The RRQ to be cleared.
661 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
663 struct lpfc_node_rrq
*rrq
)
665 struct lpfc_nodelist
*ndlp
= NULL
;
667 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
668 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
670 /* The target DID could have been swapped (cable swap)
671 * we should use the ndlp from the findnode if it is
674 if ((!ndlp
) && rrq
->ndlp
)
680 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
)) {
683 rrq
->rrq_stop_time
= 0;
686 mempool_free(rrq
, phba
->rrq_pool
);
690 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
691 * @phba: Pointer to HBA context object.
693 * This function is called with hbalock held. This function
694 * Checks if stop_time (ratov from setting rrq active) has
695 * been reached, if it has and the send_rrq flag is set then
696 * it will call lpfc_send_rrq. If the send_rrq flag is not set
697 * then it will just call the routine to clear the rrq and
698 * free the rrq resource.
699 * The timer is set to the next rrq that is going to expire before
700 * leaving the routine.
704 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
706 struct lpfc_node_rrq
*rrq
;
707 struct lpfc_node_rrq
*nextrrq
;
708 unsigned long next_time
;
709 unsigned long iflags
;
712 spin_lock_irqsave(&phba
->hbalock
, iflags
);
713 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
714 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
715 list_for_each_entry_safe(rrq
, nextrrq
,
716 &phba
->active_rrq_list
, list
) {
717 if (time_after(jiffies
, rrq
->rrq_stop_time
))
718 list_move(&rrq
->list
, &send_rrq
);
719 else if (time_before(rrq
->rrq_stop_time
, next_time
))
720 next_time
= rrq
->rrq_stop_time
;
722 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
723 if ((!list_empty(&phba
->active_rrq_list
)) &&
724 (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
725 mod_timer(&phba
->rrq_tmr
, next_time
);
726 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
727 list_del(&rrq
->list
);
729 /* this call will free the rrq */
730 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
731 else if (lpfc_send_rrq(phba
, rrq
)) {
732 /* if we send the rrq then the completion handler
733 * will clear the bit in the xribitmap.
735 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
742 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
743 * @vport: Pointer to vport context object.
744 * @xri: The xri used in the exchange.
745 * @did: The targets DID for this exchange.
747 * returns NULL = rrq not found in the phba->active_rrq_list.
748 * rrq = rrq for this xri and target.
750 struct lpfc_node_rrq
*
751 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
753 struct lpfc_hba
*phba
= vport
->phba
;
754 struct lpfc_node_rrq
*rrq
;
755 struct lpfc_node_rrq
*nextrrq
;
756 unsigned long iflags
;
758 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
760 spin_lock_irqsave(&phba
->hbalock
, iflags
);
761 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
762 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
763 rrq
->nlp_DID
== did
){
764 list_del(&rrq
->list
);
765 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
769 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
774 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
775 * @vport: Pointer to vport context object.
776 * @ndlp: Pointer to the lpfc_node_list structure.
777 * If ndlp is NULL Remove all active RRQs for this vport from the
778 * phba->active_rrq_list and clear the rrq.
779 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
782 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
785 struct lpfc_hba
*phba
= vport
->phba
;
786 struct lpfc_node_rrq
*rrq
;
787 struct lpfc_node_rrq
*nextrrq
;
788 unsigned long iflags
;
791 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
794 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
795 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
797 spin_lock_irqsave(&phba
->hbalock
, iflags
);
798 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
799 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
800 list_move(&rrq
->list
, &rrq_list
);
801 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
803 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
804 list_del(&rrq
->list
);
805 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
810 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
811 * @phba: Pointer to HBA context object.
812 * @ndlp: Targets nodelist pointer for this exchange.
813 * @xritag the xri in the bitmap to test.
815 * This function is called with hbalock held. This function
816 * returns 0 = rrq not active for this xri
817 * 1 = rrq is valid for this xri.
820 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
823 lockdep_assert_held(&phba
->hbalock
);
826 if (!ndlp
->active_rrqs_xri_bitmap
)
828 if (test_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
835 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
836 * @phba: Pointer to HBA context object.
837 * @ndlp: nodelist pointer for this target.
838 * @xritag: xri used in this exchange.
839 * @rxid: Remote Exchange ID.
840 * @send_rrq: Flag used to determine if we should send rrq els cmd.
842 * This function takes the hbalock.
843 * The active bit is always set in the active rrq xri_bitmap even
844 * if there is no slot avaiable for the other rrq information.
846 * returns 0 rrq actived for this xri
847 * < 0 No memory or invalid ndlp.
850 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
851 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
853 unsigned long iflags
;
854 struct lpfc_node_rrq
*rrq
;
860 if (!phba
->cfg_enable_rrq
)
863 spin_lock_irqsave(&phba
->hbalock
, iflags
);
864 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
865 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
870 * set the active bit even if there is no mem available.
872 if (NLP_CHK_FREE_REQ(ndlp
))
875 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
878 if (!ndlp
->active_rrqs_xri_bitmap
)
881 if (test_and_set_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
884 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
885 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
887 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
888 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
889 " DID:0x%x Send:%d\n",
890 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
893 if (phba
->cfg_enable_rrq
== 1)
894 rrq
->send_rrq
= send_rrq
;
897 rrq
->xritag
= xritag
;
898 rrq
->rrq_stop_time
= jiffies
+
899 msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
901 rrq
->nlp_DID
= ndlp
->nlp_DID
;
902 rrq
->vport
= ndlp
->vport
;
904 spin_lock_irqsave(&phba
->hbalock
, iflags
);
905 empty
= list_empty(&phba
->active_rrq_list
);
906 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
907 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
909 lpfc_worker_wake_up(phba
);
910 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
913 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
914 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
915 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
916 " DID:0x%x Send:%d\n",
917 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
922 * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
923 * @phba: Pointer to HBA context object.
924 * @piocb: Pointer to the iocbq.
926 * This function is called with the ring lock held. This function
927 * gets a new driver sglq object from the sglq list. If the
928 * list is not empty then it is successful, it returns pointer to the newly
929 * allocated sglq object else it returns NULL.
931 static struct lpfc_sglq
*
932 __lpfc_sli_get_els_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
934 struct list_head
*lpfc_els_sgl_list
= &phba
->sli4_hba
.lpfc_els_sgl_list
;
935 struct lpfc_sglq
*sglq
= NULL
;
936 struct lpfc_sglq
*start_sglq
= NULL
;
937 struct lpfc_scsi_buf
*lpfc_cmd
;
938 struct lpfc_nodelist
*ndlp
;
941 lockdep_assert_held(&phba
->hbalock
);
943 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
944 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
945 ndlp
= lpfc_cmd
->rdata
->pnode
;
946 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
947 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
948 ndlp
= piocbq
->context_un
.ndlp
;
949 } else if (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
950 if (piocbq
->iocb_flag
& LPFC_IO_LOOPBACK
)
953 ndlp
= piocbq
->context_un
.ndlp
;
955 ndlp
= piocbq
->context1
;
958 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
959 list_remove_head(lpfc_els_sgl_list
, sglq
, struct lpfc_sglq
, list
);
964 if (ndlp
&& ndlp
->active_rrqs_xri_bitmap
&&
965 test_bit(sglq
->sli4_lxritag
,
966 ndlp
->active_rrqs_xri_bitmap
)) {
967 /* This xri has an rrq outstanding for this DID.
968 * put it back in the list and get another xri.
970 list_add_tail(&sglq
->list
, lpfc_els_sgl_list
);
972 list_remove_head(lpfc_els_sgl_list
, sglq
,
973 struct lpfc_sglq
, list
);
974 if (sglq
== start_sglq
) {
975 list_add_tail(&sglq
->list
, lpfc_els_sgl_list
);
983 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
984 sglq
->state
= SGL_ALLOCATED
;
986 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
991 * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
992 * @phba: Pointer to HBA context object.
993 * @piocb: Pointer to the iocbq.
995 * This function is called with the sgl_list lock held. This function
996 * gets a new driver sglq object from the sglq list. If the
997 * list is not empty then it is successful, it returns pointer to the newly
998 * allocated sglq object else it returns NULL.
1001 __lpfc_sli_get_nvmet_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
1003 struct list_head
*lpfc_nvmet_sgl_list
;
1004 struct lpfc_sglq
*sglq
= NULL
;
1006 lpfc_nvmet_sgl_list
= &phba
->sli4_hba
.lpfc_nvmet_sgl_list
;
1008 lockdep_assert_held(&phba
->sli4_hba
.sgl_list_lock
);
1010 list_remove_head(lpfc_nvmet_sgl_list
, sglq
, struct lpfc_sglq
, list
);
1013 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
1014 sglq
->state
= SGL_ALLOCATED
;
1019 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
1020 * @phba: Pointer to HBA context object.
1022 * This function is called with no lock held. This function
1023 * allocates a new driver iocb object from the iocb pool. If the
1024 * allocation is successful, it returns pointer to the newly
1025 * allocated iocb object else it returns NULL.
1028 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
1030 struct lpfc_iocbq
* iocbq
= NULL
;
1031 unsigned long iflags
;
1033 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1034 iocbq
= __lpfc_sli_get_iocbq(phba
);
1035 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1040 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
1041 * @phba: Pointer to HBA context object.
1042 * @iocbq: Pointer to driver iocb object.
1044 * This function is called with hbalock held to release driver
1045 * iocb object to the iocb pool. The iotag in the iocb object
1046 * does not change for each use of the iocb object. This function
1047 * clears all other fields of the iocb object when it is freed.
1048 * The sqlq structure that holds the xritag and phys and virtual
1049 * mappings for the scatter gather list is retrieved from the
1050 * active array of sglq. The get of the sglq pointer also clears
1051 * the entry in the array. If the status of the IO indiactes that
1052 * this IO was aborted then the sglq entry it put on the
1053 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1054 * IO has good status or fails for any other reason then the sglq
1055 * entry is added to the free list (lpfc_els_sgl_list).
1058 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1060 struct lpfc_sglq
*sglq
;
1061 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1062 unsigned long iflag
= 0;
1063 struct lpfc_sli_ring
*pring
;
1065 lockdep_assert_held(&phba
->hbalock
);
1067 if (iocbq
->sli4_xritag
== NO_XRI
)
1070 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1074 if (iocbq
->iocb_flag
& LPFC_IO_NVMET
) {
1075 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1077 sglq
->state
= SGL_FREED
;
1079 list_add_tail(&sglq
->list
,
1080 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
);
1081 spin_unlock_irqrestore(
1082 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1086 pring
= phba
->sli4_hba
.els_wq
->pring
;
1087 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1088 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1089 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1091 list_add(&sglq
->list
,
1092 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1093 spin_unlock_irqrestore(
1094 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1096 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
,
1098 sglq
->state
= SGL_FREED
;
1100 list_add_tail(&sglq
->list
,
1101 &phba
->sli4_hba
.lpfc_els_sgl_list
);
1102 spin_unlock_irqrestore(
1103 &phba
->sli4_hba
.sgl_list_lock
, iflag
);
1105 /* Check if TXQ queue needs to be serviced */
1106 if (!list_empty(&pring
->txq
))
1107 lpfc_worker_wake_up(phba
);
1113 * Clean all volatile data fields, preserve iotag and node struct.
1115 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1116 iocbq
->sli4_lxritag
= NO_XRI
;
1117 iocbq
->sli4_xritag
= NO_XRI
;
1118 iocbq
->iocb_flag
&= ~(LPFC_IO_NVME
| LPFC_IO_NVMET
|
1120 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1125 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1126 * @phba: Pointer to HBA context object.
1127 * @iocbq: Pointer to driver iocb object.
1129 * This function is called with hbalock held to release driver
1130 * iocb object to the iocb pool. The iotag in the iocb object
1131 * does not change for each use of the iocb object. This function
1132 * clears all other fields of the iocb object when it is freed.
1135 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1137 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1139 lockdep_assert_held(&phba
->hbalock
);
1142 * Clean all volatile data fields, preserve iotag and node struct.
1144 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1145 iocbq
->sli4_xritag
= NO_XRI
;
1146 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1150 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1151 * @phba: Pointer to HBA context object.
1152 * @iocbq: Pointer to driver iocb object.
1154 * This function is called with hbalock held to release driver
1155 * iocb object to the iocb pool. The iotag in the iocb object
1156 * does not change for each use of the iocb object. This function
1157 * clears all other fields of the iocb object when it is freed.
1160 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1162 lockdep_assert_held(&phba
->hbalock
);
1164 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1169 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1170 * @phba: Pointer to HBA context object.
1171 * @iocbq: Pointer to driver iocb object.
1173 * This function is called with no lock held to release the iocb to
1177 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1179 unsigned long iflags
;
1182 * Clean all volatile data fields, preserve iotag and node struct.
1184 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1185 __lpfc_sli_release_iocbq(phba
, iocbq
);
1186 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1190 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1191 * @phba: Pointer to HBA context object.
1192 * @iocblist: List of IOCBs.
1193 * @ulpstatus: ULP status in IOCB command field.
1194 * @ulpWord4: ULP word-4 in IOCB command field.
1196 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1197 * on the list by invoking the complete callback function associated with the
1198 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1202 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1203 uint32_t ulpstatus
, uint32_t ulpWord4
)
1205 struct lpfc_iocbq
*piocb
;
1207 while (!list_empty(iocblist
)) {
1208 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1209 if (!piocb
->iocb_cmpl
)
1210 lpfc_sli_release_iocbq(phba
, piocb
);
1212 piocb
->iocb
.ulpStatus
= ulpstatus
;
1213 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1214 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1221 * lpfc_sli_iocb_cmd_type - Get the iocb type
1222 * @iocb_cmnd: iocb command code.
1224 * This function is called by ring event handler function to get the iocb type.
1225 * This function translates the iocb command to an iocb command type used to
1226 * decide the final disposition of each completed IOCB.
1227 * The function returns
1228 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1229 * LPFC_SOL_IOCB if it is a solicited iocb completion
1230 * LPFC_ABORT_IOCB if it is an abort iocb
1231 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1233 * The caller is not required to hold any lock.
1235 static lpfc_iocb_type
1236 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1238 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1240 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1243 switch (iocb_cmnd
) {
1244 case CMD_XMIT_SEQUENCE_CR
:
1245 case CMD_XMIT_SEQUENCE_CX
:
1246 case CMD_XMIT_BCAST_CN
:
1247 case CMD_XMIT_BCAST_CX
:
1248 case CMD_ELS_REQUEST_CR
:
1249 case CMD_ELS_REQUEST_CX
:
1250 case CMD_CREATE_XRI_CR
:
1251 case CMD_CREATE_XRI_CX
:
1252 case CMD_GET_RPI_CN
:
1253 case CMD_XMIT_ELS_RSP_CX
:
1254 case CMD_GET_RPI_CR
:
1255 case CMD_FCP_IWRITE_CR
:
1256 case CMD_FCP_IWRITE_CX
:
1257 case CMD_FCP_IREAD_CR
:
1258 case CMD_FCP_IREAD_CX
:
1259 case CMD_FCP_ICMND_CR
:
1260 case CMD_FCP_ICMND_CX
:
1261 case CMD_FCP_TSEND_CX
:
1262 case CMD_FCP_TRSP_CX
:
1263 case CMD_FCP_TRECEIVE_CX
:
1264 case CMD_FCP_AUTO_TRSP_CX
:
1265 case CMD_ADAPTER_MSG
:
1266 case CMD_ADAPTER_DUMP
:
1267 case CMD_XMIT_SEQUENCE64_CR
:
1268 case CMD_XMIT_SEQUENCE64_CX
:
1269 case CMD_XMIT_BCAST64_CN
:
1270 case CMD_XMIT_BCAST64_CX
:
1271 case CMD_ELS_REQUEST64_CR
:
1272 case CMD_ELS_REQUEST64_CX
:
1273 case CMD_FCP_IWRITE64_CR
:
1274 case CMD_FCP_IWRITE64_CX
:
1275 case CMD_FCP_IREAD64_CR
:
1276 case CMD_FCP_IREAD64_CX
:
1277 case CMD_FCP_ICMND64_CR
:
1278 case CMD_FCP_ICMND64_CX
:
1279 case CMD_FCP_TSEND64_CX
:
1280 case CMD_FCP_TRSP64_CX
:
1281 case CMD_FCP_TRECEIVE64_CX
:
1282 case CMD_GEN_REQUEST64_CR
:
1283 case CMD_GEN_REQUEST64_CX
:
1284 case CMD_XMIT_ELS_RSP64_CX
:
1285 case DSSCMD_IWRITE64_CR
:
1286 case DSSCMD_IWRITE64_CX
:
1287 case DSSCMD_IREAD64_CR
:
1288 case DSSCMD_IREAD64_CX
:
1289 type
= LPFC_SOL_IOCB
;
1291 case CMD_ABORT_XRI_CN
:
1292 case CMD_ABORT_XRI_CX
:
1293 case CMD_CLOSE_XRI_CN
:
1294 case CMD_CLOSE_XRI_CX
:
1295 case CMD_XRI_ABORTED_CX
:
1296 case CMD_ABORT_MXRI64_CN
:
1297 case CMD_XMIT_BLS_RSP64_CX
:
1298 type
= LPFC_ABORT_IOCB
;
1300 case CMD_RCV_SEQUENCE_CX
:
1301 case CMD_RCV_ELS_REQ_CX
:
1302 case CMD_RCV_SEQUENCE64_CX
:
1303 case CMD_RCV_ELS_REQ64_CX
:
1304 case CMD_ASYNC_STATUS
:
1305 case CMD_IOCB_RCV_SEQ64_CX
:
1306 case CMD_IOCB_RCV_ELS64_CX
:
1307 case CMD_IOCB_RCV_CONT64_CX
:
1308 case CMD_IOCB_RET_XRI64_CX
:
1309 type
= LPFC_UNSOL_IOCB
;
1311 case CMD_IOCB_XMIT_MSEQ64_CR
:
1312 case CMD_IOCB_XMIT_MSEQ64_CX
:
1313 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1314 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1315 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1316 case CMD_IOCB_ABORT_EXTENDED_CN
:
1317 case CMD_IOCB_RET_HBQE64_CN
:
1318 case CMD_IOCB_FCP_IBIDIR64_CR
:
1319 case CMD_IOCB_FCP_IBIDIR64_CX
:
1320 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1321 case CMD_IOCB_LOGENTRY_CN
:
1322 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1323 printk("%s - Unhandled SLI-3 Command x%x\n",
1324 __func__
, iocb_cmnd
);
1325 type
= LPFC_UNKNOWN_IOCB
;
1328 type
= LPFC_UNKNOWN_IOCB
;
1336 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1337 * @phba: Pointer to HBA context object.
1339 * This function is called from SLI initialization code
1340 * to configure every ring of the HBA's SLI interface. The
1341 * caller is not required to hold any lock. This function issues
1342 * a config_ring mailbox command for each ring.
1343 * This function returns zero if successful else returns a negative
1347 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1349 struct lpfc_sli
*psli
= &phba
->sli
;
1354 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1358 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1359 for (i
= 0; i
< psli
->num_rings
; i
++) {
1360 lpfc_config_ring(phba
, i
, pmb
);
1361 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1362 if (rc
!= MBX_SUCCESS
) {
1363 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1364 "0446 Adapter failed to init (%d), "
1365 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1367 rc
, pmbox
->mbxCommand
,
1368 pmbox
->mbxStatus
, i
);
1369 phba
->link_state
= LPFC_HBA_ERROR
;
1374 mempool_free(pmb
, phba
->mbox_mem_pool
);
1379 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1380 * @phba: Pointer to HBA context object.
1381 * @pring: Pointer to driver SLI ring object.
1382 * @piocb: Pointer to the driver iocb object.
1384 * This function is called with hbalock held. The function adds the
1385 * new iocb to txcmplq of the given ring. This function always returns
1386 * 0. If this function is called for ELS ring, this function checks if
1387 * there is a vport associated with the ELS command. This function also
1388 * starts els_tmofunc timer if this is an ELS command.
1391 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1392 struct lpfc_iocbq
*piocb
)
1394 lockdep_assert_held(&phba
->hbalock
);
1398 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1399 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1401 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1402 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1403 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1404 BUG_ON(!piocb
->vport
);
1405 if (!(piocb
->vport
->load_flag
& FC_UNLOADING
))
1406 mod_timer(&piocb
->vport
->els_tmofunc
,
1408 msecs_to_jiffies(1000 * (phba
->fc_ratov
<< 1)));
1415 * lpfc_sli_ringtx_get - Get first element of the txq
1416 * @phba: Pointer to HBA context object.
1417 * @pring: Pointer to driver SLI ring object.
1419 * This function is called with hbalock held to get next
1420 * iocb in txq of the given ring. If there is any iocb in
1421 * the txq, the function returns first iocb in the list after
1422 * removing the iocb from the list, else it returns NULL.
1425 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1427 struct lpfc_iocbq
*cmd_iocb
;
1429 lockdep_assert_held(&phba
->hbalock
);
1431 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1436 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1437 * @phba: Pointer to HBA context object.
1438 * @pring: Pointer to driver SLI ring object.
1440 * This function is called with hbalock held and the caller must post the
1441 * iocb without releasing the lock. If the caller releases the lock,
1442 * iocb slot returned by the function is not guaranteed to be available.
1443 * The function returns pointer to the next available iocb slot if there
1444 * is available slot in the ring, else it returns NULL.
1445 * If the get index of the ring is ahead of the put index, the function
1446 * will post an error attention event to the worker thread to take the
1447 * HBA to offline state.
1450 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1452 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1453 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1455 lockdep_assert_held(&phba
->hbalock
);
1457 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1458 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1459 pring
->sli
.sli3
.next_cmdidx
= 0;
1461 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1462 pring
->sli
.sli3
.next_cmdidx
)) {
1464 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1466 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1467 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1468 "0315 Ring %d issue: portCmdGet %d "
1469 "is bigger than cmd ring %d\n",
1471 pring
->sli
.sli3
.local_getidx
,
1474 phba
->link_state
= LPFC_HBA_ERROR
;
1476 * All error attention handlers are posted to
1479 phba
->work_ha
|= HA_ERATT
;
1480 phba
->work_hs
= HS_FFER3
;
1482 lpfc_worker_wake_up(phba
);
1487 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1491 return lpfc_cmd_iocb(phba
, pring
);
1495 * lpfc_sli_next_iotag - Get an iotag for the iocb
1496 * @phba: Pointer to HBA context object.
1497 * @iocbq: Pointer to driver iocb object.
1499 * This function gets an iotag for the iocb. If there is no unused iotag and
1500 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1501 * array and assigns a new iotag.
1502 * The function returns the allocated iotag if successful, else returns zero.
1503 * Zero is not a valid iotag.
1504 * The caller is not required to hold any lock.
1507 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1509 struct lpfc_iocbq
**new_arr
;
1510 struct lpfc_iocbq
**old_arr
;
1512 struct lpfc_sli
*psli
= &phba
->sli
;
1515 spin_lock_irq(&phba
->hbalock
);
1516 iotag
= psli
->last_iotag
;
1517 if(++iotag
< psli
->iocbq_lookup_len
) {
1518 psli
->last_iotag
= iotag
;
1519 psli
->iocbq_lookup
[iotag
] = iocbq
;
1520 spin_unlock_irq(&phba
->hbalock
);
1521 iocbq
->iotag
= iotag
;
1523 } else if (psli
->iocbq_lookup_len
< (0xffff
1524 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1525 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1526 spin_unlock_irq(&phba
->hbalock
);
1527 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1530 spin_lock_irq(&phba
->hbalock
);
1531 old_arr
= psli
->iocbq_lookup
;
1532 if (new_len
<= psli
->iocbq_lookup_len
) {
1533 /* highly unprobable case */
1535 iotag
= psli
->last_iotag
;
1536 if(++iotag
< psli
->iocbq_lookup_len
) {
1537 psli
->last_iotag
= iotag
;
1538 psli
->iocbq_lookup
[iotag
] = iocbq
;
1539 spin_unlock_irq(&phba
->hbalock
);
1540 iocbq
->iotag
= iotag
;
1543 spin_unlock_irq(&phba
->hbalock
);
1546 if (psli
->iocbq_lookup
)
1547 memcpy(new_arr
, old_arr
,
1548 ((psli
->last_iotag
+ 1) *
1549 sizeof (struct lpfc_iocbq
*)));
1550 psli
->iocbq_lookup
= new_arr
;
1551 psli
->iocbq_lookup_len
= new_len
;
1552 psli
->last_iotag
= iotag
;
1553 psli
->iocbq_lookup
[iotag
] = iocbq
;
1554 spin_unlock_irq(&phba
->hbalock
);
1555 iocbq
->iotag
= iotag
;
1560 spin_unlock_irq(&phba
->hbalock
);
1562 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1563 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1570 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1571 * @phba: Pointer to HBA context object.
1572 * @pring: Pointer to driver SLI ring object.
1573 * @iocb: Pointer to iocb slot in the ring.
1574 * @nextiocb: Pointer to driver iocb object which need to be
1575 * posted to firmware.
1577 * This function is called with hbalock held to post a new iocb to
1578 * the firmware. This function copies the new iocb to ring iocb slot and
1579 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1580 * a completion call back for this iocb else the function will free the
1584 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1585 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1587 lockdep_assert_held(&phba
->hbalock
);
1591 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1594 if (pring
->ringno
== LPFC_ELS_RING
) {
1595 lpfc_debugfs_slow_ring_trc(phba
,
1596 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1597 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1598 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1599 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1603 * Issue iocb command to adapter
1605 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1607 pring
->stats
.iocb_cmd
++;
1610 * If there is no completion routine to call, we can release the
1611 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1612 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1614 if (nextiocb
->iocb_cmpl
)
1615 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1617 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1620 * Let the HBA know what IOCB slot will be the next one the
1621 * driver will put a command into.
1623 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1624 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1628 * lpfc_sli_update_full_ring - Update the chip attention register
1629 * @phba: Pointer to HBA context object.
1630 * @pring: Pointer to driver SLI ring object.
1632 * The caller is not required to hold any lock for calling this function.
1633 * This function updates the chip attention bits for the ring to inform firmware
1634 * that there are pending work to be done for this ring and requests an
1635 * interrupt when there is space available in the ring. This function is
1636 * called when the driver is unable to post more iocbs to the ring due
1637 * to unavailability of space in the ring.
1640 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1642 int ringno
= pring
->ringno
;
1644 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1649 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1650 * The HBA will tell us when an IOCB entry is available.
1652 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1653 readl(phba
->CAregaddr
); /* flush */
1655 pring
->stats
.iocb_cmd_full
++;
1659 * lpfc_sli_update_ring - Update chip attention register
1660 * @phba: Pointer to HBA context object.
1661 * @pring: Pointer to driver SLI ring object.
1663 * This function updates the chip attention register bit for the
1664 * given ring to inform HBA that there is more work to be done
1665 * in this ring. The caller is not required to hold any lock.
1668 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1670 int ringno
= pring
->ringno
;
1673 * Tell the HBA that there is work to do in this ring.
1675 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1677 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1678 readl(phba
->CAregaddr
); /* flush */
1683 * lpfc_sli_resume_iocb - Process iocbs in the txq
1684 * @phba: Pointer to HBA context object.
1685 * @pring: Pointer to driver SLI ring object.
1687 * This function is called with hbalock held to post pending iocbs
1688 * in the txq to the firmware. This function is called when driver
1689 * detects space available in the ring.
1692 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1695 struct lpfc_iocbq
*nextiocb
;
1697 lockdep_assert_held(&phba
->hbalock
);
1701 * (a) there is anything on the txq to send
1703 * (c) link attention events can be processed (fcp ring only)
1704 * (d) IOCB processing is not blocked by the outstanding mbox command.
1707 if (lpfc_is_link_up(phba
) &&
1708 (!list_empty(&pring
->txq
)) &&
1709 (pring
->ringno
!= LPFC_FCP_RING
||
1710 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1712 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1713 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1714 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1717 lpfc_sli_update_ring(phba
, pring
);
1719 lpfc_sli_update_full_ring(phba
, pring
);
1726 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1727 * @phba: Pointer to HBA context object.
1728 * @hbqno: HBQ number.
1730 * This function is called with hbalock held to get the next
1731 * available slot for the given HBQ. If there is free slot
1732 * available for the HBQ it will return pointer to the next available
1733 * HBQ entry else it will return NULL.
1735 static struct lpfc_hbq_entry
*
1736 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1738 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1740 lockdep_assert_held(&phba
->hbalock
);
1742 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1743 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1744 hbqp
->next_hbqPutIdx
= 0;
1746 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1747 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1748 uint32_t getidx
= le32_to_cpu(raw_index
);
1750 hbqp
->local_hbqGetIdx
= getidx
;
1752 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1753 lpfc_printf_log(phba
, KERN_ERR
,
1754 LOG_SLI
| LOG_VPORT
,
1755 "1802 HBQ %d: local_hbqGetIdx "
1756 "%u is > than hbqp->entry_count %u\n",
1757 hbqno
, hbqp
->local_hbqGetIdx
,
1760 phba
->link_state
= LPFC_HBA_ERROR
;
1764 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1768 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1773 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1774 * @phba: Pointer to HBA context object.
1776 * This function is called with no lock held to free all the
1777 * hbq buffers while uninitializing the SLI interface. It also
1778 * frees the HBQ buffers returned by the firmware but not yet
1779 * processed by the upper layers.
1782 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1784 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1785 struct hbq_dmabuf
*hbq_buf
;
1786 unsigned long flags
;
1789 hbq_count
= lpfc_sli_hbq_count();
1790 /* Return all memory used by all HBQs */
1791 spin_lock_irqsave(&phba
->hbalock
, flags
);
1792 for (i
= 0; i
< hbq_count
; ++i
) {
1793 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1794 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1795 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1796 list_del(&hbq_buf
->dbuf
.list
);
1797 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1799 phba
->hbqs
[i
].buffer_count
= 0;
1802 /* Mark the HBQs not in use */
1803 phba
->hbq_in_use
= 0;
1804 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1808 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1809 * @phba: Pointer to HBA context object.
1810 * @hbqno: HBQ number.
1811 * @hbq_buf: Pointer to HBQ buffer.
1813 * This function is called with the hbalock held to post a
1814 * hbq buffer to the firmware. If the function finds an empty
1815 * slot in the HBQ, it will post the buffer. The function will return
1816 * pointer to the hbq entry if it successfully post the buffer
1817 * else it will return NULL.
1820 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1821 struct hbq_dmabuf
*hbq_buf
)
1823 lockdep_assert_held(&phba
->hbalock
);
1824 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1828 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1829 * @phba: Pointer to HBA context object.
1830 * @hbqno: HBQ number.
1831 * @hbq_buf: Pointer to HBQ buffer.
1833 * This function is called with the hbalock held to post a hbq buffer to the
1834 * firmware. If the function finds an empty slot in the HBQ, it will post the
1835 * buffer and place it on the hbq_buffer_list. The function will return zero if
1836 * it successfully post the buffer else it will return an error.
1839 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1840 struct hbq_dmabuf
*hbq_buf
)
1842 struct lpfc_hbq_entry
*hbqe
;
1843 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1845 lockdep_assert_held(&phba
->hbalock
);
1846 /* Get next HBQ entry slot to use */
1847 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1849 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1851 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1852 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1853 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->total_size
;
1854 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1855 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1856 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1858 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1859 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1861 readl(phba
->hbq_put
+ hbqno
);
1862 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1869 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1870 * @phba: Pointer to HBA context object.
1871 * @hbqno: HBQ number.
1872 * @hbq_buf: Pointer to HBQ buffer.
1874 * This function is called with the hbalock held to post an RQE to the SLI4
1875 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1876 * the hbq_buffer_list and return zero, otherwise it will return an error.
1879 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1880 struct hbq_dmabuf
*hbq_buf
)
1883 struct lpfc_rqe hrqe
;
1884 struct lpfc_rqe drqe
;
1885 struct lpfc_queue
*hrq
;
1886 struct lpfc_queue
*drq
;
1888 if (hbqno
!= LPFC_ELS_HBQ
)
1890 hrq
= phba
->sli4_hba
.hdr_rq
;
1891 drq
= phba
->sli4_hba
.dat_rq
;
1893 lockdep_assert_held(&phba
->hbalock
);
1894 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1895 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1896 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1897 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1898 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
1901 hbq_buf
->tag
= (rc
| (hbqno
<< 16));
1902 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1906 /* HBQ for ELS and CT traffic. */
1907 static struct lpfc_hbq_init lpfc_els_hbq
= {
1912 .ring_mask
= (1 << LPFC_ELS_RING
),
1919 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1924 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1925 * @phba: Pointer to HBA context object.
1926 * @hbqno: HBQ number.
1927 * @count: Number of HBQ buffers to be posted.
1929 * This function is called with no lock held to post more hbq buffers to the
1930 * given HBQ. The function returns the number of HBQ buffers successfully
1934 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1936 uint32_t i
, posted
= 0;
1937 unsigned long flags
;
1938 struct hbq_dmabuf
*hbq_buffer
;
1939 LIST_HEAD(hbq_buf_list
);
1940 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1943 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1944 lpfc_hbq_defs
[hbqno
]->entry_count
)
1945 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1946 phba
->hbqs
[hbqno
].buffer_count
;
1949 /* Allocate HBQ entries */
1950 for (i
= 0; i
< count
; i
++) {
1951 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1954 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1956 /* Check whether HBQ is still in use */
1957 spin_lock_irqsave(&phba
->hbalock
, flags
);
1958 if (!phba
->hbq_in_use
)
1960 while (!list_empty(&hbq_buf_list
)) {
1961 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1963 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1965 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1966 phba
->hbqs
[hbqno
].buffer_count
++;
1969 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1971 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1974 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1975 while (!list_empty(&hbq_buf_list
)) {
1976 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1978 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1984 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1985 * @phba: Pointer to HBA context object.
1988 * This function posts more buffers to the HBQ. This function
1989 * is called with no lock held. The function returns the number of HBQ entries
1990 * successfully allocated.
1993 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1995 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1998 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1999 lpfc_hbq_defs
[qno
]->add_count
);
2003 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
2004 * @phba: Pointer to HBA context object.
2005 * @qno: HBQ queue number.
2007 * This function is called from SLI initialization code path with
2008 * no lock held to post initial HBQ buffers to firmware. The
2009 * function returns the number of HBQ entries successfully allocated.
2012 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
2014 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2015 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2016 lpfc_hbq_defs
[qno
]->entry_count
);
2018 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
2019 lpfc_hbq_defs
[qno
]->init_count
);
2023 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
2024 * @phba: Pointer to HBA context object.
2025 * @hbqno: HBQ number.
2027 * This function removes the first hbq buffer on an hbq list and returns a
2028 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2030 static struct hbq_dmabuf
*
2031 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
2033 struct lpfc_dmabuf
*d_buf
;
2035 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
2038 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2042 * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
2043 * @phba: Pointer to HBA context object.
2044 * @hbqno: HBQ number.
2046 * This function removes the first RQ buffer on an RQ buffer list and returns a
2047 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
2049 static struct rqb_dmabuf
*
2050 lpfc_sli_rqbuf_get(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
)
2052 struct lpfc_dmabuf
*h_buf
;
2053 struct lpfc_rqb
*rqbp
;
2056 list_remove_head(&rqbp
->rqb_buffer_list
, h_buf
,
2057 struct lpfc_dmabuf
, list
);
2060 rqbp
->buffer_count
--;
2061 return container_of(h_buf
, struct rqb_dmabuf
, hbuf
);
2065 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
2066 * @phba: Pointer to HBA context object.
2067 * @tag: Tag of the hbq buffer.
2069 * This function searches for the hbq buffer associated with the given tag in
2070 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2071 * otherwise it returns NULL.
2073 static struct hbq_dmabuf
*
2074 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
2076 struct lpfc_dmabuf
*d_buf
;
2077 struct hbq_dmabuf
*hbq_buf
;
2081 if (hbqno
>= LPFC_MAX_HBQS
)
2084 spin_lock_irq(&phba
->hbalock
);
2085 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2086 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2087 if (hbq_buf
->tag
== tag
) {
2088 spin_unlock_irq(&phba
->hbalock
);
2092 spin_unlock_irq(&phba
->hbalock
);
2093 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2094 "1803 Bad hbq tag. Data: x%x x%x\n",
2095 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2100 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2101 * @phba: Pointer to HBA context object.
2102 * @hbq_buffer: Pointer to HBQ buffer.
2104 * This function is called with hbalock. This function gives back
2105 * the hbq buffer to firmware. If the HBQ does not have space to
2106 * post the buffer, it will free the buffer.
2109 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2114 hbqno
= hbq_buffer
->tag
>> 16;
2115 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2116 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2121 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2122 * @mbxCommand: mailbox command code.
2124 * This function is called by the mailbox event handler function to verify
2125 * that the completed mailbox command is a legitimate mailbox command. If the
2126 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2127 * and the mailbox event handler will take the HBA offline.
2130 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2134 switch (mbxCommand
) {
2138 case MBX_WRITE_VPARMS
:
2139 case MBX_RUN_BIU_DIAG
:
2142 case MBX_CONFIG_LINK
:
2143 case MBX_CONFIG_RING
:
2144 case MBX_RESET_RING
:
2145 case MBX_READ_CONFIG
:
2146 case MBX_READ_RCONFIG
:
2147 case MBX_READ_SPARM
:
2148 case MBX_READ_STATUS
:
2152 case MBX_READ_LNK_STAT
:
2154 case MBX_UNREG_LOGIN
:
2156 case MBX_DUMP_MEMORY
:
2157 case MBX_DUMP_CONTEXT
:
2160 case MBX_UPDATE_CFG
:
2162 case MBX_DEL_LD_ENTRY
:
2163 case MBX_RUN_PROGRAM
:
2165 case MBX_SET_VARIABLE
:
2166 case MBX_UNREG_D_ID
:
2167 case MBX_KILL_BOARD
:
2168 case MBX_CONFIG_FARP
:
2171 case MBX_RUN_BIU_DIAG64
:
2172 case MBX_CONFIG_PORT
:
2173 case MBX_READ_SPARM64
:
2174 case MBX_READ_RPI64
:
2175 case MBX_REG_LOGIN64
:
2176 case MBX_READ_TOPOLOGY
:
2179 case MBX_LOAD_EXP_ROM
:
2180 case MBX_ASYNCEVT_ENABLE
:
2184 case MBX_PORT_CAPABILITIES
:
2185 case MBX_PORT_IOV_CONTROL
:
2186 case MBX_SLI4_CONFIG
:
2187 case MBX_SLI4_REQ_FTRS
:
2189 case MBX_UNREG_FCFI
:
2194 case MBX_RESUME_RPI
:
2195 case MBX_READ_EVENT_LOG_STATUS
:
2196 case MBX_READ_EVENT_LOG
:
2197 case MBX_SECURITY_MGMT
:
2199 case MBX_ACCESS_VDATA
:
2210 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2211 * @phba: Pointer to HBA context object.
2212 * @pmboxq: Pointer to mailbox command.
2214 * This is completion handler function for mailbox commands issued from
2215 * lpfc_sli_issue_mbox_wait function. This function is called by the
2216 * mailbox event handler function with no lock held. This function
2217 * will wake up thread waiting on the wait queue pointed by context1
2221 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2223 wait_queue_head_t
*pdone_q
;
2224 unsigned long drvr_flag
;
2227 * If pdone_q is empty, the driver thread gave up waiting and
2228 * continued running.
2230 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2231 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2232 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2234 wake_up_interruptible(pdone_q
);
2235 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2241 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2242 * @phba: Pointer to HBA context object.
2243 * @pmb: Pointer to mailbox object.
2245 * This function is the default mailbox completion handler. It
2246 * frees the memory resources associated with the completed mailbox
2247 * command. If the completed command is a REG_LOGIN mailbox command,
2248 * this function will issue a UREG_LOGIN to re-claim the RPI.
2251 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2253 struct lpfc_vport
*vport
= pmb
->vport
;
2254 struct lpfc_dmabuf
*mp
;
2255 struct lpfc_nodelist
*ndlp
;
2256 struct Scsi_Host
*shost
;
2260 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2263 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2268 * If a REG_LOGIN succeeded after node is destroyed or node
2269 * is in re-discovery driver need to cleanup the RPI.
2271 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2272 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2273 !pmb
->u
.mb
.mbxStatus
) {
2274 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2275 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2276 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2278 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2279 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2280 if (rc
!= MBX_NOT_FINISHED
)
2284 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2285 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2286 !pmb
->u
.mb
.mbxStatus
) {
2287 shost
= lpfc_shost_from_vport(vport
);
2288 spin_lock_irq(shost
->host_lock
);
2289 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2290 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2291 spin_unlock_irq(shost
->host_lock
);
2294 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2295 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2297 pmb
->context2
= NULL
;
2300 /* Check security permission status on INIT_LINK mailbox command */
2301 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2302 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2303 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2304 "2860 SLI authentication is required "
2305 "for INIT_LINK but has not done yet\n");
2307 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2308 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2310 mempool_free(pmb
, phba
->mbox_mem_pool
);
2313 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2314 * @phba: Pointer to HBA context object.
2315 * @pmb: Pointer to mailbox object.
2317 * This function is the unreg rpi mailbox completion handler. It
2318 * frees the memory resources associated with the completed mailbox
2319 * command. An additional refrenece is put on the ndlp to prevent
2320 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2321 * the unreg mailbox command completes, this routine puts the
2326 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2328 struct lpfc_vport
*vport
= pmb
->vport
;
2329 struct lpfc_nodelist
*ndlp
;
2331 ndlp
= pmb
->context1
;
2332 if (pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) {
2333 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2334 (bf_get(lpfc_sli_intf_if_type
,
2335 &phba
->sli4_hba
.sli_intf
) ==
2336 LPFC_SLI_INTF_IF_TYPE_2
)) {
2338 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
2339 "0010 UNREG_LOGIN vpi:%x "
2340 "rpi:%x DID:%x map:%x %p\n",
2341 vport
->vpi
, ndlp
->nlp_rpi
,
2343 ndlp
->nlp_usg_map
, ndlp
);
2344 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2350 mempool_free(pmb
, phba
->mbox_mem_pool
);
2354 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2355 * @phba: Pointer to HBA context object.
2357 * This function is called with no lock held. This function processes all
2358 * the completed mailbox commands and gives it to upper layers. The interrupt
2359 * service routine processes mailbox completion interrupt and adds completed
2360 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2361 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2362 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2363 * function returns the mailbox commands to the upper layer by calling the
2364 * completion handler function of each mailbox.
2367 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2374 phba
->sli
.slistat
.mbox_event
++;
2376 /* Get all completed mailboxe buffers into the cmplq */
2377 spin_lock_irq(&phba
->hbalock
);
2378 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2379 spin_unlock_irq(&phba
->hbalock
);
2381 /* Get a Mailbox buffer to setup mailbox commands for callback */
2383 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2389 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2391 lpfc_debugfs_disc_trc(pmb
->vport
,
2392 LPFC_DISC_TRC_MBOX_VPORT
,
2393 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2394 (uint32_t)pmbox
->mbxCommand
,
2395 pmbox
->un
.varWords
[0],
2396 pmbox
->un
.varWords
[1]);
2399 lpfc_debugfs_disc_trc(phba
->pport
,
2401 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2402 (uint32_t)pmbox
->mbxCommand
,
2403 pmbox
->un
.varWords
[0],
2404 pmbox
->un
.varWords
[1]);
2409 * It is a fatal error if unknown mbox command completion.
2411 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2413 /* Unknown mailbox command compl */
2414 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2415 "(%d):0323 Unknown Mailbox command "
2416 "x%x (x%x/x%x) Cmpl\n",
2417 pmb
->vport
? pmb
->vport
->vpi
: 0,
2419 lpfc_sli_config_mbox_subsys_get(phba
,
2421 lpfc_sli_config_mbox_opcode_get(phba
,
2423 phba
->link_state
= LPFC_HBA_ERROR
;
2424 phba
->work_hs
= HS_FFER3
;
2425 lpfc_handle_eratt(phba
);
2429 if (pmbox
->mbxStatus
) {
2430 phba
->sli
.slistat
.mbox_stat_err
++;
2431 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2432 /* Mbox cmd cmpl error - RETRYing */
2433 lpfc_printf_log(phba
, KERN_INFO
,
2435 "(%d):0305 Mbox cmd cmpl "
2436 "error - RETRYing Data: x%x "
2437 "(x%x/x%x) x%x x%x x%x\n",
2438 pmb
->vport
? pmb
->vport
->vpi
: 0,
2440 lpfc_sli_config_mbox_subsys_get(phba
,
2442 lpfc_sli_config_mbox_opcode_get(phba
,
2445 pmbox
->un
.varWords
[0],
2446 pmb
->vport
->port_state
);
2447 pmbox
->mbxStatus
= 0;
2448 pmbox
->mbxOwner
= OWN_HOST
;
2449 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2450 if (rc
!= MBX_NOT_FINISHED
)
2455 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2456 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2457 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2458 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2460 pmb
->vport
? pmb
->vport
->vpi
: 0,
2462 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2463 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2465 *((uint32_t *) pmbox
),
2466 pmbox
->un
.varWords
[0],
2467 pmbox
->un
.varWords
[1],
2468 pmbox
->un
.varWords
[2],
2469 pmbox
->un
.varWords
[3],
2470 pmbox
->un
.varWords
[4],
2471 pmbox
->un
.varWords
[5],
2472 pmbox
->un
.varWords
[6],
2473 pmbox
->un
.varWords
[7],
2474 pmbox
->un
.varWords
[8],
2475 pmbox
->un
.varWords
[9],
2476 pmbox
->un
.varWords
[10]);
2479 pmb
->mbox_cmpl(phba
,pmb
);
2485 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2486 * @phba: Pointer to HBA context object.
2487 * @pring: Pointer to driver SLI ring object.
2490 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2491 * is set in the tag the buffer is posted for a particular exchange,
2492 * the function will return the buffer without replacing the buffer.
2493 * If the buffer is for unsolicited ELS or CT traffic, this function
2494 * returns the buffer and also posts another buffer to the firmware.
2496 static struct lpfc_dmabuf
*
2497 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2498 struct lpfc_sli_ring
*pring
,
2501 struct hbq_dmabuf
*hbq_entry
;
2503 if (tag
& QUE_BUFTAG_BIT
)
2504 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2505 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2508 return &hbq_entry
->dbuf
;
2512 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2513 * @phba: Pointer to HBA context object.
2514 * @pring: Pointer to driver SLI ring object.
2515 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2516 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2517 * @fch_type: the type for the first frame of the sequence.
2519 * This function is called with no lock held. This function uses the r_ctl and
2520 * type of the received sequence to find the correct callback function to call
2521 * to process the sequence.
2524 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2525 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2532 lpfc_nvmet_unsol_ls_event(phba
, pring
, saveq
);
2538 /* unSolicited Responses */
2539 if (pring
->prt
[0].profile
) {
2540 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2541 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2545 /* We must search, based on rctl / type
2546 for the right routine */
2547 for (i
= 0; i
< pring
->num_mask
; i
++) {
2548 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2549 (pring
->prt
[i
].type
== fch_type
)) {
2550 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2551 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2552 (phba
, pring
, saveq
);
2560 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2561 * @phba: Pointer to HBA context object.
2562 * @pring: Pointer to driver SLI ring object.
2563 * @saveq: Pointer to the unsolicited iocb.
2565 * This function is called with no lock held by the ring event handler
2566 * when there is an unsolicited iocb posted to the response ring by the
2567 * firmware. This function gets the buffer associated with the iocbs
2568 * and calls the event handler for the ring. This function handles both
2569 * qring buffers and hbq buffers.
2570 * When the function returns 1 the caller can free the iocb object otherwise
2571 * upper layer functions will free the iocb objects.
2574 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2575 struct lpfc_iocbq
*saveq
)
2579 uint32_t Rctl
, Type
;
2580 struct lpfc_iocbq
*iocbq
;
2581 struct lpfc_dmabuf
*dmzbuf
;
2583 irsp
= &(saveq
->iocb
);
2585 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2586 if (pring
->lpfc_sli_rcv_async_status
)
2587 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2589 lpfc_printf_log(phba
,
2592 "0316 Ring %d handler: unexpected "
2593 "ASYNC_STATUS iocb received evt_code "
2596 irsp
->un
.asyncstat
.evt_code
);
2600 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2601 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2602 if (irsp
->ulpBdeCount
> 0) {
2603 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2604 irsp
->un
.ulpWord
[3]);
2605 lpfc_in_buf_free(phba
, dmzbuf
);
2608 if (irsp
->ulpBdeCount
> 1) {
2609 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2610 irsp
->unsli3
.sli3Words
[3]);
2611 lpfc_in_buf_free(phba
, dmzbuf
);
2614 if (irsp
->ulpBdeCount
> 2) {
2615 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2616 irsp
->unsli3
.sli3Words
[7]);
2617 lpfc_in_buf_free(phba
, dmzbuf
);
2623 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2624 if (irsp
->ulpBdeCount
!= 0) {
2625 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2626 irsp
->un
.ulpWord
[3]);
2627 if (!saveq
->context2
)
2628 lpfc_printf_log(phba
,
2631 "0341 Ring %d Cannot find buffer for "
2632 "an unsolicited iocb. tag 0x%x\n",
2634 irsp
->un
.ulpWord
[3]);
2636 if (irsp
->ulpBdeCount
== 2) {
2637 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2638 irsp
->unsli3
.sli3Words
[7]);
2639 if (!saveq
->context3
)
2640 lpfc_printf_log(phba
,
2643 "0342 Ring %d Cannot find buffer for an"
2644 " unsolicited iocb. tag 0x%x\n",
2646 irsp
->unsli3
.sli3Words
[7]);
2648 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2649 irsp
= &(iocbq
->iocb
);
2650 if (irsp
->ulpBdeCount
!= 0) {
2651 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2652 irsp
->un
.ulpWord
[3]);
2653 if (!iocbq
->context2
)
2654 lpfc_printf_log(phba
,
2657 "0343 Ring %d Cannot find "
2658 "buffer for an unsolicited iocb"
2659 ". tag 0x%x\n", pring
->ringno
,
2660 irsp
->un
.ulpWord
[3]);
2662 if (irsp
->ulpBdeCount
== 2) {
2663 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2664 irsp
->unsli3
.sli3Words
[7]);
2665 if (!iocbq
->context3
)
2666 lpfc_printf_log(phba
,
2669 "0344 Ring %d Cannot find "
2670 "buffer for an unsolicited "
2673 irsp
->unsli3
.sli3Words
[7]);
2677 if (irsp
->ulpBdeCount
!= 0 &&
2678 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2679 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2682 /* search continue save q for same XRI */
2683 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2684 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2685 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2686 list_add_tail(&saveq
->list
, &iocbq
->list
);
2692 list_add_tail(&saveq
->clist
,
2693 &pring
->iocb_continue_saveq
);
2694 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2695 list_del_init(&iocbq
->clist
);
2697 irsp
= &(saveq
->iocb
);
2701 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2702 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2703 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2704 Rctl
= FC_RCTL_ELS_REQ
;
2707 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2708 Rctl
= w5p
->hcsw
.Rctl
;
2709 Type
= w5p
->hcsw
.Type
;
2711 /* Firmware Workaround */
2712 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2713 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2714 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2715 Rctl
= FC_RCTL_ELS_REQ
;
2717 w5p
->hcsw
.Rctl
= Rctl
;
2718 w5p
->hcsw
.Type
= Type
;
2722 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2723 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2724 "0313 Ring %d handler: unexpected Rctl x%x "
2725 "Type x%x received\n",
2726 pring
->ringno
, Rctl
, Type
);
2732 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2733 * @phba: Pointer to HBA context object.
2734 * @pring: Pointer to driver SLI ring object.
2735 * @prspiocb: Pointer to response iocb object.
2737 * This function looks up the iocb_lookup table to get the command iocb
2738 * corresponding to the given response iocb using the iotag of the
2739 * response iocb. This function is called with the hbalock held
2740 * for sli3 devices or the ring_lock for sli4 devices.
2741 * This function returns the command iocb object if it finds the command
2742 * iocb else returns NULL.
2744 static struct lpfc_iocbq
*
2745 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2746 struct lpfc_sli_ring
*pring
,
2747 struct lpfc_iocbq
*prspiocb
)
2749 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2751 lockdep_assert_held(&phba
->hbalock
);
2753 iotag
= prspiocb
->iocb
.ulpIoTag
;
2755 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2756 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2757 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2758 /* remove from txcmpl queue list */
2759 list_del_init(&cmd_iocb
->list
);
2760 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2765 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2766 "0317 iotag x%x is out of "
2767 "range: max iotag x%x wd0 x%x\n",
2768 iotag
, phba
->sli
.last_iotag
,
2769 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2774 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2775 * @phba: Pointer to HBA context object.
2776 * @pring: Pointer to driver SLI ring object.
2779 * This function looks up the iocb_lookup table to get the command iocb
2780 * corresponding to the given iotag. This function is called with the
2782 * This function returns the command iocb object if it finds the command
2783 * iocb else returns NULL.
2785 static struct lpfc_iocbq
*
2786 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2787 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2789 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2791 lockdep_assert_held(&phba
->hbalock
);
2792 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2793 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2794 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2795 /* remove from txcmpl queue list */
2796 list_del_init(&cmd_iocb
->list
);
2797 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2802 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2803 "0372 iotag x%x lookup error: max iotag (x%x) "
2805 iotag
, phba
->sli
.last_iotag
,
2806 cmd_iocb
? cmd_iocb
->iocb_flag
: 0xffff);
2811 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2812 * @phba: Pointer to HBA context object.
2813 * @pring: Pointer to driver SLI ring object.
2814 * @saveq: Pointer to the response iocb to be processed.
2816 * This function is called by the ring event handler for non-fcp
2817 * rings when there is a new response iocb in the response ring.
2818 * The caller is not required to hold any locks. This function
2819 * gets the command iocb associated with the response iocb and
2820 * calls the completion handler for the command iocb. If there
2821 * is no completion handler, the function will free the resources
2822 * associated with command iocb. If the response iocb is for
2823 * an already aborted command iocb, the status of the completion
2824 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2825 * This function always returns 1.
2828 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2829 struct lpfc_iocbq
*saveq
)
2831 struct lpfc_iocbq
*cmdiocbp
;
2833 unsigned long iflag
;
2835 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2836 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2837 spin_lock_irqsave(&pring
->ring_lock
, iflag
);
2839 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2840 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2841 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2842 spin_unlock_irqrestore(&pring
->ring_lock
, iflag
);
2844 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2847 if (cmdiocbp
->iocb_cmpl
) {
2849 * If an ELS command failed send an event to mgmt
2852 if (saveq
->iocb
.ulpStatus
&&
2853 (pring
->ringno
== LPFC_ELS_RING
) &&
2854 (cmdiocbp
->iocb
.ulpCommand
==
2855 CMD_ELS_REQUEST64_CR
))
2856 lpfc_send_els_failure_event(phba
,
2860 * Post all ELS completions to the worker thread.
2861 * All other are passed to the completion callback.
2863 if (pring
->ringno
== LPFC_ELS_RING
) {
2864 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2865 (cmdiocbp
->iocb_flag
&
2866 LPFC_DRIVER_ABORTED
)) {
2867 spin_lock_irqsave(&phba
->hbalock
,
2869 cmdiocbp
->iocb_flag
&=
2870 ~LPFC_DRIVER_ABORTED
;
2871 spin_unlock_irqrestore(&phba
->hbalock
,
2873 saveq
->iocb
.ulpStatus
=
2874 IOSTAT_LOCAL_REJECT
;
2875 saveq
->iocb
.un
.ulpWord
[4] =
2878 /* Firmware could still be in progress
2879 * of DMAing payload, so don't free data
2880 * buffer till after a hbeat.
2882 spin_lock_irqsave(&phba
->hbalock
,
2884 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2885 spin_unlock_irqrestore(&phba
->hbalock
,
2888 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2889 if (saveq
->iocb_flag
&
2890 LPFC_EXCHANGE_BUSY
) {
2891 /* Set cmdiocb flag for the
2892 * exchange busy so sgl (xri)
2893 * will not be released until
2894 * the abort xri is received
2898 &phba
->hbalock
, iflag
);
2899 cmdiocbp
->iocb_flag
|=
2901 spin_unlock_irqrestore(
2902 &phba
->hbalock
, iflag
);
2904 if (cmdiocbp
->iocb_flag
&
2905 LPFC_DRIVER_ABORTED
) {
2907 * Clear LPFC_DRIVER_ABORTED
2908 * bit in case it was driver
2912 &phba
->hbalock
, iflag
);
2913 cmdiocbp
->iocb_flag
&=
2914 ~LPFC_DRIVER_ABORTED
;
2915 spin_unlock_irqrestore(
2916 &phba
->hbalock
, iflag
);
2917 cmdiocbp
->iocb
.ulpStatus
=
2918 IOSTAT_LOCAL_REJECT
;
2919 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2920 IOERR_ABORT_REQUESTED
;
2922 * For SLI4, irsiocb contains
2923 * NO_XRI in sli_xritag, it
2924 * shall not affect releasing
2925 * sgl (xri) process.
2927 saveq
->iocb
.ulpStatus
=
2928 IOSTAT_LOCAL_REJECT
;
2929 saveq
->iocb
.un
.ulpWord
[4] =
2932 &phba
->hbalock
, iflag
);
2934 LPFC_DELAY_MEM_FREE
;
2935 spin_unlock_irqrestore(
2936 &phba
->hbalock
, iflag
);
2940 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2942 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2945 * Unknown initiating command based on the response iotag.
2946 * This could be the case on the ELS ring because of
2949 if (pring
->ringno
!= LPFC_ELS_RING
) {
2951 * Ring <ringno> handler: unexpected completion IoTag
2954 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2955 "0322 Ring %d handler: "
2956 "unexpected completion IoTag x%x "
2957 "Data: x%x x%x x%x x%x\n",
2959 saveq
->iocb
.ulpIoTag
,
2960 saveq
->iocb
.ulpStatus
,
2961 saveq
->iocb
.un
.ulpWord
[4],
2962 saveq
->iocb
.ulpCommand
,
2963 saveq
->iocb
.ulpContext
);
2971 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2972 * @phba: Pointer to HBA context object.
2973 * @pring: Pointer to driver SLI ring object.
2975 * This function is called from the iocb ring event handlers when
2976 * put pointer is ahead of the get pointer for a ring. This function signal
2977 * an error attention condition to the worker thread and the worker
2978 * thread will transition the HBA to offline state.
2981 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2983 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2985 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2986 * rsp ring <portRspMax>
2988 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2989 "0312 Ring %d handler: portRspPut %d "
2990 "is bigger than rsp ring %d\n",
2991 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2992 pring
->sli
.sli3
.numRiocb
);
2994 phba
->link_state
= LPFC_HBA_ERROR
;
2997 * All error attention handlers are posted to
3000 phba
->work_ha
|= HA_ERATT
;
3001 phba
->work_hs
= HS_FFER3
;
3003 lpfc_worker_wake_up(phba
);
3009 * lpfc_poll_eratt - Error attention polling timer timeout handler
3010 * @ptr: Pointer to address of HBA context object.
3012 * This function is invoked by the Error Attention polling timer when the
3013 * timer times out. It will check the SLI Error Attention register for
3014 * possible attention events. If so, it will post an Error Attention event
3015 * and wake up worker thread to process it. Otherwise, it will set up the
3016 * Error Attention polling timer for the next poll.
3018 void lpfc_poll_eratt(struct timer_list
*t
)
3020 struct lpfc_hba
*phba
;
3022 uint64_t sli_intr
, cnt
;
3024 phba
= from_timer(phba
, t
, eratt_poll
);
3026 /* Here we will also keep track of interrupts per sec of the hba */
3027 sli_intr
= phba
->sli
.slistat
.sli_intr
;
3029 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
3030 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
3033 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
3035 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
3036 do_div(cnt
, phba
->eratt_poll_interval
);
3037 phba
->sli
.slistat
.sli_ips
= cnt
;
3039 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
3041 /* Check chip HA register for error event */
3042 eratt
= lpfc_sli_check_eratt(phba
);
3045 /* Tell the worker thread there is work to do */
3046 lpfc_worker_wake_up(phba
);
3048 /* Restart the timer for next eratt poll */
3049 mod_timer(&phba
->eratt_poll
,
3051 msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
3057 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
3058 * @phba: Pointer to HBA context object.
3059 * @pring: Pointer to driver SLI ring object.
3060 * @mask: Host attention register mask for this ring.
3062 * This function is called from the interrupt context when there is a ring
3063 * event for the fcp ring. The caller does not hold any lock.
3064 * The function processes each response iocb in the response ring until it
3065 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
3066 * LE bit set. The function will call the completion handler of the command iocb
3067 * if the response iocb indicates a completion for a command iocb or it is
3068 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
3069 * function if this is an unsolicited iocb.
3070 * This routine presumes LPFC_FCP_RING handling and doesn't bother
3071 * to check it explicitly.
3074 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
3075 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3077 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
3078 IOCB_t
*irsp
= NULL
;
3079 IOCB_t
*entry
= NULL
;
3080 struct lpfc_iocbq
*cmdiocbq
= NULL
;
3081 struct lpfc_iocbq rspiocbq
;
3083 uint32_t portRspPut
, portRspMax
;
3085 lpfc_iocb_type type
;
3086 unsigned long iflag
;
3087 uint32_t rsp_cmpl
= 0;
3089 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3090 pring
->stats
.iocb_event
++;
3093 * The next available response entry should never exceed the maximum
3094 * entries. If it does, treat it as an adapter hardware error.
3096 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3097 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3098 if (unlikely(portRspPut
>= portRspMax
)) {
3099 lpfc_sli_rsp_pointers_error(phba
, pring
);
3100 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3103 if (phba
->fcp_ring_in_use
) {
3104 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3107 phba
->fcp_ring_in_use
= 1;
3110 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3112 * Fetch an entry off the ring and copy it into a local data
3113 * structure. The copy involves a byte-swap since the
3114 * network byte order and pci byte orders are different.
3116 entry
= lpfc_resp_iocb(phba
, pring
);
3117 phba
->last_completion_time
= jiffies
;
3119 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3120 pring
->sli
.sli3
.rspidx
= 0;
3122 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
3123 (uint32_t *) &rspiocbq
.iocb
,
3124 phba
->iocb_rsp_size
);
3125 INIT_LIST_HEAD(&(rspiocbq
.list
));
3126 irsp
= &rspiocbq
.iocb
;
3128 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
3129 pring
->stats
.iocb_rsp
++;
3132 if (unlikely(irsp
->ulpStatus
)) {
3134 * If resource errors reported from HBA, reduce
3135 * queuedepths of the SCSI device.
3137 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3138 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3139 IOERR_NO_RESOURCES
)) {
3140 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3141 phba
->lpfc_rampdown_queue_depth(phba
);
3142 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3145 /* Rsp ring <ringno> error: IOCB */
3146 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3147 "0336 Rsp Ring %d error: IOCB Data: "
3148 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3150 irsp
->un
.ulpWord
[0],
3151 irsp
->un
.ulpWord
[1],
3152 irsp
->un
.ulpWord
[2],
3153 irsp
->un
.ulpWord
[3],
3154 irsp
->un
.ulpWord
[4],
3155 irsp
->un
.ulpWord
[5],
3156 *(uint32_t *)&irsp
->un1
,
3157 *((uint32_t *)&irsp
->un1
+ 1));
3161 case LPFC_ABORT_IOCB
:
3164 * Idle exchange closed via ABTS from port. No iocb
3165 * resources need to be recovered.
3167 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3168 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3169 "0333 IOCB cmd 0x%x"
3170 " processed. Skipping"
3176 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3178 if (unlikely(!cmdiocbq
))
3180 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3181 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3182 if (cmdiocbq
->iocb_cmpl
) {
3183 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3184 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3186 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3189 case LPFC_UNSOL_IOCB
:
3190 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3191 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3192 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3195 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3196 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3197 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3198 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3200 dev_warn(&((phba
->pcidev
)->dev
),
3202 phba
->brd_no
, adaptermsg
);
3204 /* Unknown IOCB command */
3205 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3206 "0334 Unknown IOCB command "
3207 "Data: x%x, x%x x%x x%x x%x\n",
3208 type
, irsp
->ulpCommand
,
3217 * The response IOCB has been processed. Update the ring
3218 * pointer in SLIM. If the port response put pointer has not
3219 * been updated, sync the pgp->rspPutInx and fetch the new port
3220 * response put pointer.
3222 writel(pring
->sli
.sli3
.rspidx
,
3223 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3225 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3226 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3229 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3230 pring
->stats
.iocb_rsp_full
++;
3231 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3232 writel(status
, phba
->CAregaddr
);
3233 readl(phba
->CAregaddr
);
3235 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3236 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3237 pring
->stats
.iocb_cmd_empty
++;
3239 /* Force update of the local copy of cmdGetInx */
3240 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3241 lpfc_sli_resume_iocb(phba
, pring
);
3243 if ((pring
->lpfc_sli_cmd_available
))
3244 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3248 phba
->fcp_ring_in_use
= 0;
3249 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3254 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3255 * @phba: Pointer to HBA context object.
3256 * @pring: Pointer to driver SLI ring object.
3257 * @rspiocbp: Pointer to driver response IOCB object.
3259 * This function is called from the worker thread when there is a slow-path
3260 * response IOCB to process. This function chains all the response iocbs until
3261 * seeing the iocb with the LE bit set. The function will call
3262 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3263 * completion of a command iocb. The function will call the
3264 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3265 * The function frees the resources or calls the completion handler if this
3266 * iocb is an abort completion. The function returns NULL when the response
3267 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3268 * this function shall chain the iocb on to the iocb_continueq and return the
3269 * response iocb passed in.
3271 static struct lpfc_iocbq
*
3272 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3273 struct lpfc_iocbq
*rspiocbp
)
3275 struct lpfc_iocbq
*saveq
;
3276 struct lpfc_iocbq
*cmdiocbp
;
3277 struct lpfc_iocbq
*next_iocb
;
3278 IOCB_t
*irsp
= NULL
;
3279 uint32_t free_saveq
;
3280 uint8_t iocb_cmd_type
;
3281 lpfc_iocb_type type
;
3282 unsigned long iflag
;
3285 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3286 /* First add the response iocb to the countinueq list */
3287 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3288 pring
->iocb_continueq_cnt
++;
3290 /* Now, determine whether the list is completed for processing */
3291 irsp
= &rspiocbp
->iocb
;
3294 * By default, the driver expects to free all resources
3295 * associated with this iocb completion.
3298 saveq
= list_get_first(&pring
->iocb_continueq
,
3299 struct lpfc_iocbq
, list
);
3300 irsp
= &(saveq
->iocb
);
3301 list_del_init(&pring
->iocb_continueq
);
3302 pring
->iocb_continueq_cnt
= 0;
3304 pring
->stats
.iocb_rsp
++;
3307 * If resource errors reported from HBA, reduce
3308 * queuedepths of the SCSI device.
3310 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3311 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3312 IOERR_NO_RESOURCES
)) {
3313 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3314 phba
->lpfc_rampdown_queue_depth(phba
);
3315 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3318 if (irsp
->ulpStatus
) {
3319 /* Rsp ring <ringno> error: IOCB */
3320 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3321 "0328 Rsp Ring %d error: "
3326 "x%x x%x x%x x%x\n",
3328 irsp
->un
.ulpWord
[0],
3329 irsp
->un
.ulpWord
[1],
3330 irsp
->un
.ulpWord
[2],
3331 irsp
->un
.ulpWord
[3],
3332 irsp
->un
.ulpWord
[4],
3333 irsp
->un
.ulpWord
[5],
3334 *(((uint32_t *) irsp
) + 6),
3335 *(((uint32_t *) irsp
) + 7),
3336 *(((uint32_t *) irsp
) + 8),
3337 *(((uint32_t *) irsp
) + 9),
3338 *(((uint32_t *) irsp
) + 10),
3339 *(((uint32_t *) irsp
) + 11),
3340 *(((uint32_t *) irsp
) + 12),
3341 *(((uint32_t *) irsp
) + 13),
3342 *(((uint32_t *) irsp
) + 14),
3343 *(((uint32_t *) irsp
) + 15));
3347 * Fetch the IOCB command type and call the correct completion
3348 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3349 * get freed back to the lpfc_iocb_list by the discovery
3352 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3353 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3356 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3357 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3358 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3361 case LPFC_UNSOL_IOCB
:
3362 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3363 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3364 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3369 case LPFC_ABORT_IOCB
:
3371 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3372 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3375 /* Call the specified completion routine */
3376 if (cmdiocbp
->iocb_cmpl
) {
3377 spin_unlock_irqrestore(&phba
->hbalock
,
3379 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3381 spin_lock_irqsave(&phba
->hbalock
,
3384 __lpfc_sli_release_iocbq(phba
,
3389 case LPFC_UNKNOWN_IOCB
:
3390 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3391 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3392 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3393 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3395 dev_warn(&((phba
->pcidev
)->dev
),
3397 phba
->brd_no
, adaptermsg
);
3399 /* Unknown IOCB command */
3400 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3401 "0335 Unknown IOCB "
3402 "command Data: x%x "
3413 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3414 &saveq
->list
, list
) {
3415 list_del_init(&rspiocbp
->list
);
3416 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3418 __lpfc_sli_release_iocbq(phba
, saveq
);
3422 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3427 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3428 * @phba: Pointer to HBA context object.
3429 * @pring: Pointer to driver SLI ring object.
3430 * @mask: Host attention register mask for this ring.
3432 * This routine wraps the actual slow_ring event process routine from the
3433 * API jump table function pointer from the lpfc_hba struct.
3436 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3437 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3439 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3443 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3444 * @phba: Pointer to HBA context object.
3445 * @pring: Pointer to driver SLI ring object.
3446 * @mask: Host attention register mask for this ring.
3448 * This function is called from the worker thread when there is a ring event
3449 * for non-fcp rings. The caller does not hold any lock. The function will
3450 * remove each response iocb in the response ring and calls the handle
3451 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3454 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3455 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3457 struct lpfc_pgp
*pgp
;
3459 IOCB_t
*irsp
= NULL
;
3460 struct lpfc_iocbq
*rspiocbp
= NULL
;
3461 uint32_t portRspPut
, portRspMax
;
3462 unsigned long iflag
;
3465 pgp
= &phba
->port_gp
[pring
->ringno
];
3466 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3467 pring
->stats
.iocb_event
++;
3470 * The next available response entry should never exceed the maximum
3471 * entries. If it does, treat it as an adapter hardware error.
3473 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3474 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3475 if (portRspPut
>= portRspMax
) {
3477 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3478 * rsp ring <portRspMax>
3480 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3481 "0303 Ring %d handler: portRspPut %d "
3482 "is bigger than rsp ring %d\n",
3483 pring
->ringno
, portRspPut
, portRspMax
);
3485 phba
->link_state
= LPFC_HBA_ERROR
;
3486 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3488 phba
->work_hs
= HS_FFER3
;
3489 lpfc_handle_eratt(phba
);
3495 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3497 * Build a completion list and call the appropriate handler.
3498 * The process is to get the next available response iocb, get
3499 * a free iocb from the list, copy the response data into the
3500 * free iocb, insert to the continuation list, and update the
3501 * next response index to slim. This process makes response
3502 * iocb's in the ring available to DMA as fast as possible but
3503 * pays a penalty for a copy operation. Since the iocb is
3504 * only 32 bytes, this penalty is considered small relative to
3505 * the PCI reads for register values and a slim write. When
3506 * the ulpLe field is set, the entire Command has been
3509 entry
= lpfc_resp_iocb(phba
, pring
);
3511 phba
->last_completion_time
= jiffies
;
3512 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3513 if (rspiocbp
== NULL
) {
3514 printk(KERN_ERR
"%s: out of buffers! Failing "
3515 "completion.\n", __func__
);
3519 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3520 phba
->iocb_rsp_size
);
3521 irsp
= &rspiocbp
->iocb
;
3523 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3524 pring
->sli
.sli3
.rspidx
= 0;
3526 if (pring
->ringno
== LPFC_ELS_RING
) {
3527 lpfc_debugfs_slow_ring_trc(phba
,
3528 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3529 *(((uint32_t *) irsp
) + 4),
3530 *(((uint32_t *) irsp
) + 6),
3531 *(((uint32_t *) irsp
) + 7));
3534 writel(pring
->sli
.sli3
.rspidx
,
3535 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3537 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3538 /* Handle the response IOCB */
3539 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3540 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3543 * If the port response put pointer has not been updated, sync
3544 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3545 * response put pointer.
3547 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3548 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3550 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3552 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3553 /* At least one response entry has been freed */
3554 pring
->stats
.iocb_rsp_full
++;
3555 /* SET RxRE_RSP in Chip Att register */
3556 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3557 writel(status
, phba
->CAregaddr
);
3558 readl(phba
->CAregaddr
); /* flush */
3560 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3561 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3562 pring
->stats
.iocb_cmd_empty
++;
3564 /* Force update of the local copy of cmdGetInx */
3565 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3566 lpfc_sli_resume_iocb(phba
, pring
);
3568 if ((pring
->lpfc_sli_cmd_available
))
3569 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3573 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3578 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3579 * @phba: Pointer to HBA context object.
3580 * @pring: Pointer to driver SLI ring object.
3581 * @mask: Host attention register mask for this ring.
3583 * This function is called from the worker thread when there is a pending
3584 * ELS response iocb on the driver internal slow-path response iocb worker
3585 * queue. The caller does not hold any lock. The function will remove each
3586 * response iocb from the response worker queue and calls the handle
3587 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3590 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3591 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3593 struct lpfc_iocbq
*irspiocbq
;
3594 struct hbq_dmabuf
*dmabuf
;
3595 struct lpfc_cq_event
*cq_event
;
3596 unsigned long iflag
;
3598 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3599 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3600 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3601 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3602 /* Get the response iocb from the head of work queue */
3603 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3604 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3605 cq_event
, struct lpfc_cq_event
, list
);
3606 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3608 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3609 case CQE_CODE_COMPL_WQE
:
3610 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3612 /* Translate ELS WCQE to response IOCBQ */
3613 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3616 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3619 case CQE_CODE_RECEIVE
:
3620 case CQE_CODE_RECEIVE_V1
:
3621 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3623 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3632 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3633 * @phba: Pointer to HBA context object.
3634 * @pring: Pointer to driver SLI ring object.
3636 * This function aborts all iocbs in the given ring and frees all the iocb
3637 * objects in txq. This function issues an abort iocb for all the iocb commands
3638 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3639 * the return of this function. The caller is not required to hold any locks.
3642 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3644 LIST_HEAD(completions
);
3645 struct lpfc_iocbq
*iocb
, *next_iocb
;
3647 if (pring
->ringno
== LPFC_ELS_RING
) {
3648 lpfc_fabric_abort_hba(phba
);
3651 /* Error everything on txq and txcmplq
3654 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3655 spin_lock_irq(&pring
->ring_lock
);
3656 list_splice_init(&pring
->txq
, &completions
);
3658 spin_unlock_irq(&pring
->ring_lock
);
3660 spin_lock_irq(&phba
->hbalock
);
3661 /* Next issue ABTS for everything on the txcmplq */
3662 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3663 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3664 spin_unlock_irq(&phba
->hbalock
);
3666 spin_lock_irq(&phba
->hbalock
);
3667 list_splice_init(&pring
->txq
, &completions
);
3670 /* Next issue ABTS for everything on the txcmplq */
3671 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3672 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3673 spin_unlock_irq(&phba
->hbalock
);
3676 /* Cancel all the IOCBs from the completions list */
3677 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3682 * lpfc_sli_abort_wqe_ring - Abort all iocbs in the ring
3683 * @phba: Pointer to HBA context object.
3684 * @pring: Pointer to driver SLI ring object.
3686 * This function aborts all iocbs in the given ring and frees all the iocb
3687 * objects in txq. This function issues an abort iocb for all the iocb commands
3688 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3689 * the return of this function. The caller is not required to hold any locks.
3692 lpfc_sli_abort_wqe_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3694 LIST_HEAD(completions
);
3695 struct lpfc_iocbq
*iocb
, *next_iocb
;
3697 if (pring
->ringno
== LPFC_ELS_RING
)
3698 lpfc_fabric_abort_hba(phba
);
3700 spin_lock_irq(&phba
->hbalock
);
3701 /* Next issue ABTS for everything on the txcmplq */
3702 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3703 lpfc_sli4_abort_nvme_io(phba
, pring
, iocb
);
3704 spin_unlock_irq(&phba
->hbalock
);
3709 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3710 * @phba: Pointer to HBA context object.
3711 * @pring: Pointer to driver SLI ring object.
3713 * This function aborts all iocbs in FCP rings and frees all the iocb
3714 * objects in txq. This function issues an abort iocb for all the iocb commands
3715 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3716 * the return of this function. The caller is not required to hold any locks.
3719 lpfc_sli_abort_fcp_rings(struct lpfc_hba
*phba
)
3721 struct lpfc_sli
*psli
= &phba
->sli
;
3722 struct lpfc_sli_ring
*pring
;
3725 /* Look on all the FCP Rings for the iotag */
3726 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3727 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3728 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
3729 lpfc_sli_abort_iocb_ring(phba
, pring
);
3732 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
3733 lpfc_sli_abort_iocb_ring(phba
, pring
);
3738 * lpfc_sli_abort_nvme_rings - Abort all wqes in all NVME rings
3739 * @phba: Pointer to HBA context object.
3741 * This function aborts all wqes in NVME rings. This function issues an
3742 * abort wqe for all the outstanding IO commands in txcmplq. The iocbs in
3743 * the txcmplq is not guaranteed to complete before the return of this
3744 * function. The caller is not required to hold any locks.
3747 lpfc_sli_abort_nvme_rings(struct lpfc_hba
*phba
)
3749 struct lpfc_sli_ring
*pring
;
3752 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3755 /* Abort all IO on each NVME ring. */
3756 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
3757 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
3758 lpfc_sli_abort_wqe_ring(phba
, pring
);
3764 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3765 * @phba: Pointer to HBA context object.
3767 * This function flushes all iocbs in the fcp ring and frees all the iocb
3768 * objects in txq and txcmplq. This function will not issue abort iocbs
3769 * for all the iocb commands in txcmplq, they will just be returned with
3770 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3771 * slot has been permanently disabled.
3774 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3778 struct lpfc_sli
*psli
= &phba
->sli
;
3779 struct lpfc_sli_ring
*pring
;
3782 spin_lock_irq(&phba
->hbalock
);
3783 /* Indicate the I/O queues are flushed */
3784 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3785 spin_unlock_irq(&phba
->hbalock
);
3787 /* Look on all the FCP Rings for the iotag */
3788 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3789 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3790 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
3792 spin_lock_irq(&pring
->ring_lock
);
3793 /* Retrieve everything on txq */
3794 list_splice_init(&pring
->txq
, &txq
);
3795 /* Retrieve everything on the txcmplq */
3796 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3798 pring
->txcmplq_cnt
= 0;
3799 spin_unlock_irq(&pring
->ring_lock
);
3802 lpfc_sli_cancel_iocbs(phba
, &txq
,
3803 IOSTAT_LOCAL_REJECT
,
3805 /* Flush the txcmpq */
3806 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
3807 IOSTAT_LOCAL_REJECT
,
3811 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
3813 spin_lock_irq(&phba
->hbalock
);
3814 /* Retrieve everything on txq */
3815 list_splice_init(&pring
->txq
, &txq
);
3816 /* Retrieve everything on the txcmplq */
3817 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3819 pring
->txcmplq_cnt
= 0;
3820 spin_unlock_irq(&phba
->hbalock
);
3823 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3825 /* Flush the txcmpq */
3826 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3832 * lpfc_sli_flush_nvme_rings - flush all wqes in the nvme rings
3833 * @phba: Pointer to HBA context object.
3835 * This function flushes all wqes in the nvme rings and frees all resources
3836 * in the txcmplq. This function does not issue abort wqes for the IO
3837 * commands in txcmplq, they will just be returned with
3838 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3839 * slot has been permanently disabled.
3842 lpfc_sli_flush_nvme_rings(struct lpfc_hba
*phba
)
3845 struct lpfc_sli_ring
*pring
;
3848 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3851 /* Hint to other driver operations that a flush is in progress. */
3852 spin_lock_irq(&phba
->hbalock
);
3853 phba
->hba_flag
|= HBA_NVME_IOQ_FLUSH
;
3854 spin_unlock_irq(&phba
->hbalock
);
3856 /* Cycle through all NVME rings and complete each IO with
3857 * a local driver reason code. This is a flush so no
3858 * abort exchange to FW.
3860 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
3861 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
3863 /* Retrieve everything on the txcmplq */
3864 spin_lock_irq(&pring
->ring_lock
);
3865 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3866 pring
->txcmplq_cnt
= 0;
3867 spin_unlock_irq(&pring
->ring_lock
);
3869 /* Flush the txcmpq &&&PAE */
3870 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
3871 IOSTAT_LOCAL_REJECT
,
3877 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3878 * @phba: Pointer to HBA context object.
3879 * @mask: Bit mask to be checked.
3881 * This function reads the host status register and compares
3882 * with the provided bit mask to check if HBA completed
3883 * the restart. This function will wait in a loop for the
3884 * HBA to complete restart. If the HBA does not restart within
3885 * 15 iterations, the function will reset the HBA again. The
3886 * function returns 1 when HBA fail to restart otherwise returns
3890 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3896 /* Read the HBA Host Status Register */
3897 if (lpfc_readl(phba
->HSregaddr
, &status
))
3901 * Check status register every 100ms for 5 retries, then every
3902 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3903 * every 2.5 sec for 4.
3904 * Break our of the loop if errors occurred during init.
3906 while (((status
& mask
) != mask
) &&
3907 !(status
& HS_FFERM
) &&
3919 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3920 lpfc_sli_brdrestart(phba
);
3922 /* Read the HBA Host Status Register */
3923 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3929 /* Check to see if any errors occurred during init */
3930 if ((status
& HS_FFERM
) || (i
>= 20)) {
3931 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3932 "2751 Adapter failed to restart, "
3933 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3935 readl(phba
->MBslimaddr
+ 0xa8),
3936 readl(phba
->MBslimaddr
+ 0xac));
3937 phba
->link_state
= LPFC_HBA_ERROR
;
3945 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3946 * @phba: Pointer to HBA context object.
3947 * @mask: Bit mask to be checked.
3949 * This function checks the host status register to check if HBA is
3950 * ready. This function will wait in a loop for the HBA to be ready
3951 * If the HBA is not ready , the function will will reset the HBA PCI
3952 * function again. The function returns 1 when HBA fail to be ready
3953 * otherwise returns zero.
3956 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3961 /* Read the HBA Host Status Register */
3962 status
= lpfc_sli4_post_status_check(phba
);
3965 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3966 lpfc_sli_brdrestart(phba
);
3967 status
= lpfc_sli4_post_status_check(phba
);
3970 /* Check to see if any errors occurred during init */
3972 phba
->link_state
= LPFC_HBA_ERROR
;
3975 phba
->sli4_hba
.intr_enable
= 0;
3981 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3982 * @phba: Pointer to HBA context object.
3983 * @mask: Bit mask to be checked.
3985 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3986 * from the API jump table function pointer from the lpfc_hba struct.
3989 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3991 return phba
->lpfc_sli_brdready(phba
, mask
);
3994 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3997 * lpfc_reset_barrier - Make HBA ready for HBA reset
3998 * @phba: Pointer to HBA context object.
4000 * This function is called before resetting an HBA. This function is called
4001 * with hbalock held and requests HBA to quiesce DMAs before a reset.
4003 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
4005 uint32_t __iomem
*resp_buf
;
4006 uint32_t __iomem
*mbox_buf
;
4007 volatile uint32_t mbox
;
4008 uint32_t hc_copy
, ha_copy
, resp_data
;
4012 lockdep_assert_held(&phba
->hbalock
);
4014 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
4015 if (hdrtype
!= 0x80 ||
4016 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
4017 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
4021 * Tell the other part of the chip to suspend temporarily all
4024 resp_buf
= phba
->MBslimaddr
;
4026 /* Disable the error attention */
4027 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
4029 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
4030 readl(phba
->HCregaddr
); /* flush */
4031 phba
->link_flag
|= LS_IGNORE_ERATT
;
4033 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4035 if (ha_copy
& HA_ERATT
) {
4036 /* Clear Chip error bit */
4037 writel(HA_ERATT
, phba
->HAregaddr
);
4038 phba
->pport
->stopped
= 1;
4042 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
4043 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
4045 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
4046 mbox_buf
= phba
->MBslimaddr
;
4047 writel(mbox
, mbox_buf
);
4049 for (i
= 0; i
< 50; i
++) {
4050 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
4052 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
4058 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
4060 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
4061 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
4062 phba
->pport
->stopped
)
4068 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
4070 for (i
= 0; i
< 500; i
++) {
4071 if (lpfc_readl(resp_buf
, &resp_data
))
4073 if (resp_data
!= mbox
)
4082 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4084 if (!(ha_copy
& HA_ERATT
))
4090 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
4091 writel(HA_ERATT
, phba
->HAregaddr
);
4092 phba
->pport
->stopped
= 1;
4096 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4097 writel(hc_copy
, phba
->HCregaddr
);
4098 readl(phba
->HCregaddr
); /* flush */
4102 * lpfc_sli_brdkill - Issue a kill_board mailbox command
4103 * @phba: Pointer to HBA context object.
4105 * This function issues a kill_board mailbox command and waits for
4106 * the error attention interrupt. This function is called for stopping
4107 * the firmware processing. The caller is not required to hold any
4108 * locks. This function calls lpfc_hba_down_post function to free
4109 * any pending commands after the kill. The function will return 1 when it
4110 * fails to kill the board else will return 0.
4113 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
4115 struct lpfc_sli
*psli
;
4125 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4126 "0329 Kill HBA Data: x%x x%x\n",
4127 phba
->pport
->port_state
, psli
->sli_flag
);
4129 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4133 /* Disable the error attention */
4134 spin_lock_irq(&phba
->hbalock
);
4135 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
4136 spin_unlock_irq(&phba
->hbalock
);
4137 mempool_free(pmb
, phba
->mbox_mem_pool
);
4140 status
&= ~HC_ERINT_ENA
;
4141 writel(status
, phba
->HCregaddr
);
4142 readl(phba
->HCregaddr
); /* flush */
4143 phba
->link_flag
|= LS_IGNORE_ERATT
;
4144 spin_unlock_irq(&phba
->hbalock
);
4146 lpfc_kill_board(phba
, pmb
);
4147 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4148 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
4150 if (retval
!= MBX_SUCCESS
) {
4151 if (retval
!= MBX_BUSY
)
4152 mempool_free(pmb
, phba
->mbox_mem_pool
);
4153 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4154 "2752 KILL_BOARD command failed retval %d\n",
4156 spin_lock_irq(&phba
->hbalock
);
4157 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4158 spin_unlock_irq(&phba
->hbalock
);
4162 spin_lock_irq(&phba
->hbalock
);
4163 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
4164 spin_unlock_irq(&phba
->hbalock
);
4166 mempool_free(pmb
, phba
->mbox_mem_pool
);
4168 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
4169 * attention every 100ms for 3 seconds. If we don't get ERATT after
4170 * 3 seconds we still set HBA_ERROR state because the status of the
4171 * board is now undefined.
4173 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4175 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
4177 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
4181 del_timer_sync(&psli
->mbox_tmo
);
4182 if (ha_copy
& HA_ERATT
) {
4183 writel(HA_ERATT
, phba
->HAregaddr
);
4184 phba
->pport
->stopped
= 1;
4186 spin_lock_irq(&phba
->hbalock
);
4187 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4188 psli
->mbox_active
= NULL
;
4189 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4190 spin_unlock_irq(&phba
->hbalock
);
4192 lpfc_hba_down_post(phba
);
4193 phba
->link_state
= LPFC_HBA_ERROR
;
4195 return ha_copy
& HA_ERATT
? 0 : 1;
4199 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4200 * @phba: Pointer to HBA context object.
4202 * This function resets the HBA by writing HC_INITFF to the control
4203 * register. After the HBA resets, this function resets all the iocb ring
4204 * indices. This function disables PCI layer parity checking during
4206 * This function returns 0 always.
4207 * The caller is not required to hold any locks.
4210 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
4212 struct lpfc_sli
*psli
;
4213 struct lpfc_sli_ring
*pring
;
4220 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4221 "0325 Reset HBA Data: x%x x%x\n",
4222 (phba
->pport
) ? phba
->pport
->port_state
: 0,
4225 /* perform board reset */
4226 phba
->fc_eventTag
= 0;
4227 phba
->link_events
= 0;
4229 phba
->pport
->fc_myDID
= 0;
4230 phba
->pport
->fc_prevDID
= 0;
4233 /* Turn off parity checking and serr during the physical reset */
4234 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4235 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
4237 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4239 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
4241 /* Now toggle INITFF bit in the Host Control Register */
4242 writel(HC_INITFF
, phba
->HCregaddr
);
4244 readl(phba
->HCregaddr
); /* flush */
4245 writel(0, phba
->HCregaddr
);
4246 readl(phba
->HCregaddr
); /* flush */
4248 /* Restore PCI cmd register */
4249 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4251 /* Initialize relevant SLI info */
4252 for (i
= 0; i
< psli
->num_rings
; i
++) {
4253 pring
= &psli
->sli3_ring
[i
];
4255 pring
->sli
.sli3
.rspidx
= 0;
4256 pring
->sli
.sli3
.next_cmdidx
= 0;
4257 pring
->sli
.sli3
.local_getidx
= 0;
4258 pring
->sli
.sli3
.cmdidx
= 0;
4259 pring
->missbufcnt
= 0;
4262 phba
->link_state
= LPFC_WARM_START
;
4267 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4268 * @phba: Pointer to HBA context object.
4270 * This function resets a SLI4 HBA. This function disables PCI layer parity
4271 * checking during resets the device. The caller is not required to hold
4274 * This function returns 0 always.
4277 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
4279 struct lpfc_sli
*psli
= &phba
->sli
;
4284 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4285 "0295 Reset HBA Data: x%x x%x x%x\n",
4286 phba
->pport
->port_state
, psli
->sli_flag
,
4289 /* perform board reset */
4290 phba
->fc_eventTag
= 0;
4291 phba
->link_events
= 0;
4292 phba
->pport
->fc_myDID
= 0;
4293 phba
->pport
->fc_prevDID
= 0;
4295 spin_lock_irq(&phba
->hbalock
);
4296 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
4297 phba
->fcf
.fcf_flag
= 0;
4298 spin_unlock_irq(&phba
->hbalock
);
4300 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4301 if (phba
->hba_flag
& HBA_FW_DUMP_OP
) {
4302 phba
->hba_flag
&= ~HBA_FW_DUMP_OP
;
4306 /* Now physically reset the device */
4307 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4308 "0389 Performing PCI function reset!\n");
4310 /* Turn off parity checking and serr during the physical reset */
4311 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4312 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
4313 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4315 /* Perform FCoE PCI function reset before freeing queue memory */
4316 rc
= lpfc_pci_function_reset(phba
);
4318 /* Restore PCI cmd register */
4319 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4325 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4326 * @phba: Pointer to HBA context object.
4328 * This function is called in the SLI initialization code path to
4329 * restart the HBA. The caller is not required to hold any lock.
4330 * This function writes MBX_RESTART mailbox command to the SLIM and
4331 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4332 * function to free any pending commands. The function enables
4333 * POST only during the first initialization. The function returns zero.
4334 * The function does not guarantee completion of MBX_RESTART mailbox
4335 * command before the return of this function.
4338 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4341 struct lpfc_sli
*psli
;
4342 volatile uint32_t word0
;
4343 void __iomem
*to_slim
;
4344 uint32_t hba_aer_enabled
;
4346 spin_lock_irq(&phba
->hbalock
);
4348 /* Take PCIe device Advanced Error Reporting (AER) state */
4349 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4354 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4355 "0337 Restart HBA Data: x%x x%x\n",
4356 (phba
->pport
) ? phba
->pport
->port_state
: 0,
4360 mb
= (MAILBOX_t
*) &word0
;
4361 mb
->mbxCommand
= MBX_RESTART
;
4364 lpfc_reset_barrier(phba
);
4366 to_slim
= phba
->MBslimaddr
;
4367 writel(*(uint32_t *) mb
, to_slim
);
4368 readl(to_slim
); /* flush */
4370 /* Only skip post after fc_ffinit is completed */
4371 if (phba
->pport
&& phba
->pport
->port_state
)
4372 word0
= 1; /* This is really setting up word1 */
4374 word0
= 0; /* This is really setting up word1 */
4375 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4376 writel(*(uint32_t *) mb
, to_slim
);
4377 readl(to_slim
); /* flush */
4379 lpfc_sli_brdreset(phba
);
4381 phba
->pport
->stopped
= 0;
4382 phba
->link_state
= LPFC_INIT_START
;
4384 spin_unlock_irq(&phba
->hbalock
);
4386 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4387 psli
->stats_start
= get_seconds();
4389 /* Give the INITFF and Post time to settle. */
4392 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4393 if (hba_aer_enabled
)
4394 pci_disable_pcie_error_reporting(phba
->pcidev
);
4396 lpfc_hba_down_post(phba
);
4402 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4403 * @phba: Pointer to HBA context object.
4405 * This function is called in the SLI initialization code path to restart
4406 * a SLI4 HBA. The caller is not required to hold any lock.
4407 * At the end of the function, it calls lpfc_hba_down_post function to
4408 * free any pending commands.
4411 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4413 struct lpfc_sli
*psli
= &phba
->sli
;
4414 uint32_t hba_aer_enabled
;
4418 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4419 "0296 Restart HBA Data: x%x x%x\n",
4420 phba
->pport
->port_state
, psli
->sli_flag
);
4422 /* Take PCIe device Advanced Error Reporting (AER) state */
4423 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4425 rc
= lpfc_sli4_brdreset(phba
);
4427 spin_lock_irq(&phba
->hbalock
);
4428 phba
->pport
->stopped
= 0;
4429 phba
->link_state
= LPFC_INIT_START
;
4431 spin_unlock_irq(&phba
->hbalock
);
4433 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4434 psli
->stats_start
= get_seconds();
4436 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4437 if (hba_aer_enabled
)
4438 pci_disable_pcie_error_reporting(phba
->pcidev
);
4440 lpfc_hba_down_post(phba
);
4441 lpfc_sli4_queue_destroy(phba
);
4447 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4448 * @phba: Pointer to HBA context object.
4450 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4451 * API jump table function pointer from the lpfc_hba struct.
4454 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4456 return phba
->lpfc_sli_brdrestart(phba
);
4460 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4461 * @phba: Pointer to HBA context object.
4463 * This function is called after a HBA restart to wait for successful
4464 * restart of the HBA. Successful restart of the HBA is indicated by
4465 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4466 * iteration, the function will restart the HBA again. The function returns
4467 * zero if HBA successfully restarted else returns negative error code.
4470 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4472 uint32_t status
, i
= 0;
4474 /* Read the HBA Host Status Register */
4475 if (lpfc_readl(phba
->HSregaddr
, &status
))
4478 /* Check status register to see what current state is */
4480 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4482 /* Check every 10ms for 10 retries, then every 100ms for 90
4483 * retries, then every 1 sec for 50 retires for a total of
4484 * ~60 seconds before reset the board again and check every
4485 * 1 sec for 50 retries. The up to 60 seconds before the
4486 * board ready is required by the Falcon FIPS zeroization
4487 * complete, and any reset the board in between shall cause
4488 * restart of zeroization, further delay the board ready.
4491 /* Adapter failed to init, timeout, status reg
4493 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4494 "0436 Adapter failed to init, "
4495 "timeout, status reg x%x, "
4496 "FW Data: A8 x%x AC x%x\n", status
,
4497 readl(phba
->MBslimaddr
+ 0xa8),
4498 readl(phba
->MBslimaddr
+ 0xac));
4499 phba
->link_state
= LPFC_HBA_ERROR
;
4503 /* Check to see if any errors occurred during init */
4504 if (status
& HS_FFERM
) {
4505 /* ERROR: During chipset initialization */
4506 /* Adapter failed to init, chipset, status reg
4508 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4509 "0437 Adapter failed to init, "
4510 "chipset, status reg x%x, "
4511 "FW Data: A8 x%x AC x%x\n", status
,
4512 readl(phba
->MBslimaddr
+ 0xa8),
4513 readl(phba
->MBslimaddr
+ 0xac));
4514 phba
->link_state
= LPFC_HBA_ERROR
;
4527 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4528 lpfc_sli_brdrestart(phba
);
4530 /* Read the HBA Host Status Register */
4531 if (lpfc_readl(phba
->HSregaddr
, &status
))
4535 /* Check to see if any errors occurred during init */
4536 if (status
& HS_FFERM
) {
4537 /* ERROR: During chipset initialization */
4538 /* Adapter failed to init, chipset, status reg <status> */
4539 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4540 "0438 Adapter failed to init, chipset, "
4542 "FW Data: A8 x%x AC x%x\n", status
,
4543 readl(phba
->MBslimaddr
+ 0xa8),
4544 readl(phba
->MBslimaddr
+ 0xac));
4545 phba
->link_state
= LPFC_HBA_ERROR
;
4549 /* Clear all interrupt enable conditions */
4550 writel(0, phba
->HCregaddr
);
4551 readl(phba
->HCregaddr
); /* flush */
4553 /* setup host attn register */
4554 writel(0xffffffff, phba
->HAregaddr
);
4555 readl(phba
->HAregaddr
); /* flush */
4560 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4562 * This function calculates and returns the number of HBQs required to be
4566 lpfc_sli_hbq_count(void)
4568 return ARRAY_SIZE(lpfc_hbq_defs
);
4572 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4574 * This function adds the number of hbq entries in every HBQ to get
4575 * the total number of hbq entries required for the HBA and returns
4579 lpfc_sli_hbq_entry_count(void)
4581 int hbq_count
= lpfc_sli_hbq_count();
4585 for (i
= 0; i
< hbq_count
; ++i
)
4586 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4591 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4593 * This function calculates amount of memory required for all hbq entries
4594 * to be configured and returns the total memory required.
4597 lpfc_sli_hbq_size(void)
4599 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4603 * lpfc_sli_hbq_setup - configure and initialize HBQs
4604 * @phba: Pointer to HBA context object.
4606 * This function is called during the SLI initialization to configure
4607 * all the HBQs and post buffers to the HBQ. The caller is not
4608 * required to hold any locks. This function will return zero if successful
4609 * else it will return negative error code.
4612 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4614 int hbq_count
= lpfc_sli_hbq_count();
4618 uint32_t hbq_entry_index
;
4620 /* Get a Mailbox buffer to setup mailbox
4621 * commands for HBA initialization
4623 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4630 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4631 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4632 phba
->hbq_in_use
= 1;
4634 hbq_entry_index
= 0;
4635 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4636 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4637 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4638 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4639 phba
->hbqs
[hbqno
].entry_count
=
4640 lpfc_hbq_defs
[hbqno
]->entry_count
;
4641 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4642 hbq_entry_index
, pmb
);
4643 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4645 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4646 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4647 mbxStatus <status>, ring <num> */
4649 lpfc_printf_log(phba
, KERN_ERR
,
4650 LOG_SLI
| LOG_VPORT
,
4651 "1805 Adapter failed to init. "
4652 "Data: x%x x%x x%x\n",
4654 pmbox
->mbxStatus
, hbqno
);
4656 phba
->link_state
= LPFC_HBA_ERROR
;
4657 mempool_free(pmb
, phba
->mbox_mem_pool
);
4661 phba
->hbq_count
= hbq_count
;
4663 mempool_free(pmb
, phba
->mbox_mem_pool
);
4665 /* Initially populate or replenish the HBQs */
4666 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4667 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4672 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4673 * @phba: Pointer to HBA context object.
4675 * This function is called during the SLI initialization to configure
4676 * all the HBQs and post buffers to the HBQ. The caller is not
4677 * required to hold any locks. This function will return zero if successful
4678 * else it will return negative error code.
4681 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4683 phba
->hbq_in_use
= 1;
4684 phba
->hbqs
[LPFC_ELS_HBQ
].entry_count
=
4685 lpfc_hbq_defs
[LPFC_ELS_HBQ
]->entry_count
;
4686 phba
->hbq_count
= 1;
4687 lpfc_sli_hbqbuf_init_hbqs(phba
, LPFC_ELS_HBQ
);
4688 /* Initially populate or replenish the HBQs */
4693 * lpfc_sli_config_port - Issue config port mailbox command
4694 * @phba: Pointer to HBA context object.
4695 * @sli_mode: sli mode - 2/3
4697 * This function is called by the sli initialization code path
4698 * to issue config_port mailbox command. This function restarts the
4699 * HBA firmware and issues a config_port mailbox command to configure
4700 * the SLI interface in the sli mode specified by sli_mode
4701 * variable. The caller is not required to hold any locks.
4702 * The function returns 0 if successful, else returns negative error
4706 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4709 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4711 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4713 phba
->link_state
= LPFC_HBA_ERROR
;
4717 phba
->sli_rev
= sli_mode
;
4718 while (resetcount
< 2 && !done
) {
4719 spin_lock_irq(&phba
->hbalock
);
4720 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4721 spin_unlock_irq(&phba
->hbalock
);
4722 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4723 lpfc_sli_brdrestart(phba
);
4724 rc
= lpfc_sli_chipset_init(phba
);
4728 spin_lock_irq(&phba
->hbalock
);
4729 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4730 spin_unlock_irq(&phba
->hbalock
);
4733 /* Call pre CONFIG_PORT mailbox command initialization. A
4734 * value of 0 means the call was successful. Any other
4735 * nonzero value is a failure, but if ERESTART is returned,
4736 * the driver may reset the HBA and try again.
4738 rc
= lpfc_config_port_prep(phba
);
4739 if (rc
== -ERESTART
) {
4740 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4745 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4746 lpfc_config_port(phba
, pmb
);
4747 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4748 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4749 LPFC_SLI3_HBQ_ENABLED
|
4750 LPFC_SLI3_CRP_ENABLED
|
4751 LPFC_SLI3_BG_ENABLED
|
4752 LPFC_SLI3_DSS_ENABLED
);
4753 if (rc
!= MBX_SUCCESS
) {
4754 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4755 "0442 Adapter failed to init, mbxCmd x%x "
4756 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4757 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4758 spin_lock_irq(&phba
->hbalock
);
4759 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4760 spin_unlock_irq(&phba
->hbalock
);
4763 /* Allow asynchronous mailbox command to go through */
4764 spin_lock_irq(&phba
->hbalock
);
4765 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4766 spin_unlock_irq(&phba
->hbalock
);
4769 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4770 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4771 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4772 "3110 Port did not grant ASABT\n");
4777 goto do_prep_failed
;
4779 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4780 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4782 goto do_prep_failed
;
4784 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4785 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4786 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4787 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4788 phba
->max_vpi
: phba
->max_vports
;
4792 phba
->fips_level
= 0;
4793 phba
->fips_spec_rev
= 0;
4794 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4795 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4796 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4797 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4798 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4799 "2850 Security Crypto Active. FIPS x%d "
4801 phba
->fips_level
, phba
->fips_spec_rev
);
4803 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4804 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4805 "2856 Config Port Security Crypto "
4807 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4809 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4810 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4811 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4812 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4814 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4815 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4817 if (phba
->cfg_enable_bg
) {
4818 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4819 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4821 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4822 "0443 Adapter did not grant "
4826 phba
->hbq_get
= NULL
;
4827 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4831 mempool_free(pmb
, phba
->mbox_mem_pool
);
4837 * lpfc_sli_hba_setup - SLI initialization function
4838 * @phba: Pointer to HBA context object.
4840 * This function is the main SLI initialization function. This function
4841 * is called by the HBA initialization code, HBA reset code and HBA
4842 * error attention handler code. Caller is not required to hold any
4843 * locks. This function issues config_port mailbox command to configure
4844 * the SLI, setup iocb rings and HBQ rings. In the end the function
4845 * calls the config_port_post function to issue init_link mailbox
4846 * command and to start the discovery. The function will return zero
4847 * if successful, else it will return negative error code.
4850 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4856 switch (phba
->cfg_sli_mode
) {
4858 if (phba
->cfg_enable_npiv
) {
4859 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4860 "1824 NPIV enabled: Override sli_mode "
4861 "parameter (%d) to auto (0).\n",
4862 phba
->cfg_sli_mode
);
4871 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4872 "1819 Unrecognized sli_mode parameter: %d.\n",
4873 phba
->cfg_sli_mode
);
4877 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
4879 rc
= lpfc_sli_config_port(phba
, mode
);
4881 if (rc
&& phba
->cfg_sli_mode
== 3)
4882 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4883 "1820 Unable to select SLI-3. "
4884 "Not supported by adapter.\n");
4885 if (rc
&& mode
!= 2)
4886 rc
= lpfc_sli_config_port(phba
, 2);
4887 else if (rc
&& mode
== 2)
4888 rc
= lpfc_sli_config_port(phba
, 3);
4890 goto lpfc_sli_hba_setup_error
;
4892 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4893 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4894 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4896 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4897 "2709 This device supports "
4898 "Advanced Error Reporting (AER)\n");
4899 spin_lock_irq(&phba
->hbalock
);
4900 phba
->hba_flag
|= HBA_AER_ENABLED
;
4901 spin_unlock_irq(&phba
->hbalock
);
4903 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4904 "2708 This device does not support "
4905 "Advanced Error Reporting (AER): %d\n",
4907 phba
->cfg_aer_support
= 0;
4911 if (phba
->sli_rev
== 3) {
4912 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4913 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4915 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4916 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4917 phba
->sli3_options
= 0;
4920 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4921 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4922 phba
->sli_rev
, phba
->max_vpi
);
4923 rc
= lpfc_sli_ring_map(phba
);
4926 goto lpfc_sli_hba_setup_error
;
4928 /* Initialize VPIs. */
4929 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4931 * The VPI bitmask and physical ID array are allocated
4932 * and initialized once only - at driver load. A port
4933 * reset doesn't need to reinitialize this memory.
4935 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4936 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4937 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4939 if (!phba
->vpi_bmask
) {
4941 goto lpfc_sli_hba_setup_error
;
4944 phba
->vpi_ids
= kzalloc(
4945 (phba
->max_vpi
+1) * sizeof(uint16_t),
4947 if (!phba
->vpi_ids
) {
4948 kfree(phba
->vpi_bmask
);
4950 goto lpfc_sli_hba_setup_error
;
4952 for (i
= 0; i
< phba
->max_vpi
; i
++)
4953 phba
->vpi_ids
[i
] = i
;
4958 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4959 rc
= lpfc_sli_hbq_setup(phba
);
4961 goto lpfc_sli_hba_setup_error
;
4963 spin_lock_irq(&phba
->hbalock
);
4964 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4965 spin_unlock_irq(&phba
->hbalock
);
4967 rc
= lpfc_config_port_post(phba
);
4969 goto lpfc_sli_hba_setup_error
;
4973 lpfc_sli_hba_setup_error
:
4974 phba
->link_state
= LPFC_HBA_ERROR
;
4975 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4976 "0445 Firmware initialization failed\n");
4981 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4982 * @phba: Pointer to HBA context object.
4983 * @mboxq: mailbox pointer.
4984 * This function issue a dump mailbox command to read config region
4985 * 23 and parse the records in the region and populate driver
4989 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4991 LPFC_MBOXQ_t
*mboxq
;
4992 struct lpfc_dmabuf
*mp
;
4993 struct lpfc_mqe
*mqe
;
4994 uint32_t data_length
;
4997 /* Program the default value of vlan_id and fc_map */
4998 phba
->valid_vlan
= 0;
4999 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
5000 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
5001 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
5003 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5007 mqe
= &mboxq
->u
.mqe
;
5008 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
5010 goto out_free_mboxq
;
5013 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
5014 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5016 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
5017 "(%d):2571 Mailbox cmd x%x Status x%x "
5018 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5019 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
5020 "CQ: x%x x%x x%x x%x\n",
5021 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
5022 bf_get(lpfc_mqe_command
, mqe
),
5023 bf_get(lpfc_mqe_status
, mqe
),
5024 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
5025 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
5026 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
5027 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
5028 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
5029 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
5030 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
5031 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
5032 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
5034 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
5035 mboxq
->mcqe
.trailer
);
5038 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5041 goto out_free_mboxq
;
5043 data_length
= mqe
->un
.mb_words
[5];
5044 if (data_length
> DMP_RGN23_SIZE
) {
5045 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5048 goto out_free_mboxq
;
5051 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
5052 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5057 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5062 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
5063 * @phba: pointer to lpfc hba data structure.
5064 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
5065 * @vpd: pointer to the memory to hold resulting port vpd data.
5066 * @vpd_size: On input, the number of bytes allocated to @vpd.
5067 * On output, the number of data bytes in @vpd.
5069 * This routine executes a READ_REV SLI4 mailbox command. In
5070 * addition, this routine gets the port vpd data.
5074 * -ENOMEM - could not allocated memory.
5077 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
5078 uint8_t *vpd
, uint32_t *vpd_size
)
5082 struct lpfc_dmabuf
*dmabuf
;
5083 struct lpfc_mqe
*mqe
;
5085 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5090 * Get a DMA buffer for the vpd data resulting from the READ_REV
5093 dma_size
= *vpd_size
;
5094 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, dma_size
,
5095 &dmabuf
->phys
, GFP_KERNEL
);
5096 if (!dmabuf
->virt
) {
5102 * The SLI4 implementation of READ_REV conflicts at word1,
5103 * bits 31:16 and SLI4 adds vpd functionality not present
5104 * in SLI3. This code corrects the conflicts.
5106 lpfc_read_rev(phba
, mboxq
);
5107 mqe
= &mboxq
->u
.mqe
;
5108 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
5109 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
5110 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
5111 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
5112 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
5114 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5116 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
5117 dmabuf
->virt
, dmabuf
->phys
);
5123 * The available vpd length cannot be bigger than the
5124 * DMA buffer passed to the port. Catch the less than
5125 * case and update the caller's size.
5127 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
5128 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
5130 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
5132 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
5133 dmabuf
->virt
, dmabuf
->phys
);
5139 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
5140 * @phba: pointer to lpfc hba data structure.
5142 * This routine retrieves SLI4 device physical port name this PCI function
5147 * otherwise - failed to retrieve physical port name
5150 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
5152 LPFC_MBOXQ_t
*mboxq
;
5153 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
5154 struct lpfc_controller_attribute
*cntl_attr
;
5155 struct lpfc_mbx_get_port_name
*get_port_name
;
5156 void *virtaddr
= NULL
;
5157 uint32_t alloclen
, reqlen
;
5158 uint32_t shdr_status
, shdr_add_status
;
5159 union lpfc_sli4_cfg_shdr
*shdr
;
5160 char cport_name
= 0;
5163 /* We assume nothing at this point */
5164 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
5165 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
5167 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5170 /* obtain link type and link number via READ_CONFIG */
5171 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
5172 lpfc_sli4_read_config(phba
);
5173 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
5174 goto retrieve_ppname
;
5176 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
5177 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
5178 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5179 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
5180 LPFC_SLI4_MBX_NEMBED
);
5181 if (alloclen
< reqlen
) {
5182 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5183 "3084 Allocated DMA memory size (%d) is "
5184 "less than the requested DMA memory size "
5185 "(%d)\n", alloclen
, reqlen
);
5187 goto out_free_mboxq
;
5189 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5190 virtaddr
= mboxq
->sge_array
->addr
[0];
5191 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
5192 shdr
= &mbx_cntl_attr
->cfg_shdr
;
5193 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5194 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5195 if (shdr_status
|| shdr_add_status
|| rc
) {
5196 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5197 "3085 Mailbox x%x (x%x/x%x) failed, "
5198 "rc:x%x, status:x%x, add_status:x%x\n",
5199 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5200 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5201 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5202 rc
, shdr_status
, shdr_add_status
);
5204 goto out_free_mboxq
;
5206 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
5207 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
5208 phba
->sli4_hba
.lnk_info
.lnk_tp
=
5209 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
5210 phba
->sli4_hba
.lnk_info
.lnk_no
=
5211 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
5212 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5213 "3086 lnk_type:%d, lnk_numb:%d\n",
5214 phba
->sli4_hba
.lnk_info
.lnk_tp
,
5215 phba
->sli4_hba
.lnk_info
.lnk_no
);
5218 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5219 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
5220 sizeof(struct lpfc_mbx_get_port_name
) -
5221 sizeof(struct lpfc_sli4_cfg_mhdr
),
5222 LPFC_SLI4_MBX_EMBED
);
5223 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
5224 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
5225 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
5226 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
5227 phba
->sli4_hba
.lnk_info
.lnk_tp
);
5228 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5229 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5230 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5231 if (shdr_status
|| shdr_add_status
|| rc
) {
5232 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5233 "3087 Mailbox x%x (x%x/x%x) failed: "
5234 "rc:x%x, status:x%x, add_status:x%x\n",
5235 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5236 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5237 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5238 rc
, shdr_status
, shdr_add_status
);
5240 goto out_free_mboxq
;
5242 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
5243 case LPFC_LINK_NUMBER_0
:
5244 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
5245 &get_port_name
->u
.response
);
5246 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5248 case LPFC_LINK_NUMBER_1
:
5249 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
5250 &get_port_name
->u
.response
);
5251 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5253 case LPFC_LINK_NUMBER_2
:
5254 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
5255 &get_port_name
->u
.response
);
5256 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5258 case LPFC_LINK_NUMBER_3
:
5259 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
5260 &get_port_name
->u
.response
);
5261 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5267 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
5268 phba
->Port
[0] = cport_name
;
5269 phba
->Port
[1] = '\0';
5270 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5271 "3091 SLI get port name: %s\n", phba
->Port
);
5275 if (rc
!= MBX_TIMEOUT
) {
5276 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
5277 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
5279 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5285 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5286 * @phba: pointer to lpfc hba data structure.
5288 * This routine is called to explicitly arm the SLI4 device's completion and
5292 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
5296 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
5297 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
5298 if (phba
->sli4_hba
.nvmels_cq
)
5299 lpfc_sli4_cq_release(phba
->sli4_hba
.nvmels_cq
,
5302 if (phba
->sli4_hba
.fcp_cq
)
5303 for (qidx
= 0; qidx
< phba
->cfg_fcp_io_channel
; qidx
++)
5304 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[qidx
],
5307 if (phba
->sli4_hba
.nvme_cq
)
5308 for (qidx
= 0; qidx
< phba
->cfg_nvme_io_channel
; qidx
++)
5309 lpfc_sli4_cq_release(phba
->sli4_hba
.nvme_cq
[qidx
],
5313 lpfc_sli4_cq_release(phba
->sli4_hba
.oas_cq
, LPFC_QUEUE_REARM
);
5315 if (phba
->sli4_hba
.hba_eq
)
5316 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++)
5317 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[qidx
],
5320 if (phba
->nvmet_support
) {
5321 for (qidx
= 0; qidx
< phba
->cfg_nvmet_mrq
; qidx
++) {
5322 lpfc_sli4_cq_release(
5323 phba
->sli4_hba
.nvmet_cqset
[qidx
],
5329 lpfc_sli4_eq_release(phba
->sli4_hba
.fof_eq
, LPFC_QUEUE_REARM
);
5333 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5334 * @phba: Pointer to HBA context object.
5335 * @type: The resource extent type.
5336 * @extnt_count: buffer to hold port available extent count.
5337 * @extnt_size: buffer to hold element count per extent.
5339 * This function calls the port and retrievs the number of available
5340 * extents and their size for a particular extent type.
5342 * Returns: 0 if successful. Nonzero otherwise.
5345 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5346 uint16_t *extnt_count
, uint16_t *extnt_size
)
5351 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5354 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5358 /* Find out how many extents are available for this resource type */
5359 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5360 sizeof(struct lpfc_sli4_cfg_mhdr
));
5361 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5362 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5363 length
, LPFC_SLI4_MBX_EMBED
);
5365 /* Send an extents count of 0 - the GET doesn't use it. */
5366 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5367 LPFC_SLI4_MBX_EMBED
);
5373 if (!phba
->sli4_hba
.intr_enable
)
5374 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5376 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5377 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5384 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5385 if (bf_get(lpfc_mbox_hdr_status
,
5386 &rsrc_info
->header
.cfg_shdr
.response
)) {
5387 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5388 "2930 Failed to get resource extents "
5389 "Status 0x%x Add'l Status 0x%x\n",
5390 bf_get(lpfc_mbox_hdr_status
,
5391 &rsrc_info
->header
.cfg_shdr
.response
),
5392 bf_get(lpfc_mbox_hdr_add_status
,
5393 &rsrc_info
->header
.cfg_shdr
.response
));
5398 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5400 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5403 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5404 "3162 Retrieved extents type-%d from port: count:%d, "
5405 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5408 mempool_free(mbox
, phba
->mbox_mem_pool
);
5413 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5414 * @phba: Pointer to HBA context object.
5415 * @type: The extent type to check.
5417 * This function reads the current available extents from the port and checks
5418 * if the extent count or extent size has changed since the last access.
5419 * Callers use this routine post port reset to understand if there is a
5420 * extent reprovisioning requirement.
5423 * -Error: error indicates problem.
5424 * 1: Extent count or size has changed.
5428 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5430 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5431 uint16_t size_diff
, rsrc_ext_size
;
5433 struct lpfc_rsrc_blks
*rsrc_entry
;
5434 struct list_head
*rsrc_blk_list
= NULL
;
5438 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5445 case LPFC_RSC_TYPE_FCOE_RPI
:
5446 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5448 case LPFC_RSC_TYPE_FCOE_VPI
:
5449 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5451 case LPFC_RSC_TYPE_FCOE_XRI
:
5452 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5454 case LPFC_RSC_TYPE_FCOE_VFI
:
5455 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5461 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5463 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5467 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5474 * lpfc_sli4_cfg_post_extnts -
5475 * @phba: Pointer to HBA context object.
5476 * @extnt_cnt - number of available extents.
5477 * @type - the extent type (rpi, xri, vfi, vpi).
5478 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5479 * @mbox - pointer to the caller's allocated mailbox structure.
5481 * This function executes the extents allocation request. It also
5482 * takes care of the amount of memory needed to allocate or get the
5483 * allocated extents. It is the caller's responsibility to evaluate
5487 * -Error: Error value describes the condition found.
5491 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5492 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5497 uint32_t alloc_len
, mbox_tmo
;
5499 /* Calculate the total requested length of the dma memory */
5500 req_len
= extnt_cnt
* sizeof(uint16_t);
5503 * Calculate the size of an embedded mailbox. The uint32_t
5504 * accounts for extents-specific word.
5506 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5510 * Presume the allocation and response will fit into an embedded
5511 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5513 *emb
= LPFC_SLI4_MBX_EMBED
;
5514 if (req_len
> emb_len
) {
5515 req_len
= extnt_cnt
* sizeof(uint16_t) +
5516 sizeof(union lpfc_sli4_cfg_shdr
) +
5518 *emb
= LPFC_SLI4_MBX_NEMBED
;
5521 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5522 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5524 if (alloc_len
< req_len
) {
5525 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5526 "2982 Allocated DMA memory size (x%x) is "
5527 "less than the requested DMA memory "
5528 "size (x%x)\n", alloc_len
, req_len
);
5531 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5535 if (!phba
->sli4_hba
.intr_enable
)
5536 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5538 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5539 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5548 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5549 * @phba: Pointer to HBA context object.
5550 * @type: The resource extent type to allocate.
5552 * This function allocates the number of elements for the specified
5556 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5559 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5560 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5563 unsigned long longs
;
5564 unsigned long *bmask
;
5565 struct lpfc_rsrc_blks
*rsrc_blks
;
5568 struct lpfc_id_range
*id_array
= NULL
;
5569 void *virtaddr
= NULL
;
5570 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5571 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5572 struct list_head
*ext_blk_list
;
5574 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5580 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5581 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5582 "3009 No available Resource Extents "
5583 "for resource type 0x%x: Count: 0x%x, "
5584 "Size 0x%x\n", type
, rsrc_cnt
,
5589 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5590 "2903 Post resource extents type-0x%x: "
5591 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5593 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5597 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5604 * Figure out where the response is located. Then get local pointers
5605 * to the response data. The port does not guarantee to respond to
5606 * all extents counts request so update the local variable with the
5607 * allocated count from the port.
5609 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5610 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5611 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5612 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5614 virtaddr
= mbox
->sge_array
->addr
[0];
5615 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5616 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5617 id_array
= &n_rsrc
->id
;
5620 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5621 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5624 * Based on the resource size and count, correct the base and max
5627 length
= sizeof(struct lpfc_rsrc_blks
);
5629 case LPFC_RSC_TYPE_FCOE_RPI
:
5630 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5631 sizeof(unsigned long),
5633 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5637 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5640 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5641 kfree(phba
->sli4_hba
.rpi_bmask
);
5647 * The next_rpi was initialized with the maximum available
5648 * count but the port may allocate a smaller number. Catch
5649 * that case and update the next_rpi.
5651 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5653 /* Initialize local ptrs for common extent processing later. */
5654 bmask
= phba
->sli4_hba
.rpi_bmask
;
5655 ids
= phba
->sli4_hba
.rpi_ids
;
5656 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5658 case LPFC_RSC_TYPE_FCOE_VPI
:
5659 phba
->vpi_bmask
= kzalloc(longs
*
5660 sizeof(unsigned long),
5662 if (unlikely(!phba
->vpi_bmask
)) {
5666 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5669 if (unlikely(!phba
->vpi_ids
)) {
5670 kfree(phba
->vpi_bmask
);
5675 /* Initialize local ptrs for common extent processing later. */
5676 bmask
= phba
->vpi_bmask
;
5677 ids
= phba
->vpi_ids
;
5678 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5680 case LPFC_RSC_TYPE_FCOE_XRI
:
5681 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5682 sizeof(unsigned long),
5684 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5688 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5689 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5692 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5693 kfree(phba
->sli4_hba
.xri_bmask
);
5698 /* Initialize local ptrs for common extent processing later. */
5699 bmask
= phba
->sli4_hba
.xri_bmask
;
5700 ids
= phba
->sli4_hba
.xri_ids
;
5701 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5703 case LPFC_RSC_TYPE_FCOE_VFI
:
5704 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5705 sizeof(unsigned long),
5707 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5711 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5714 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5715 kfree(phba
->sli4_hba
.vfi_bmask
);
5720 /* Initialize local ptrs for common extent processing later. */
5721 bmask
= phba
->sli4_hba
.vfi_bmask
;
5722 ids
= phba
->sli4_hba
.vfi_ids
;
5723 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5726 /* Unsupported Opcode. Fail call. */
5730 ext_blk_list
= NULL
;
5735 * Complete initializing the extent configuration with the
5736 * allocated ids assigned to this function. The bitmask serves
5737 * as an index into the array and manages the available ids. The
5738 * array just stores the ids communicated to the port via the wqes.
5740 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5742 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5745 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5748 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5749 if (unlikely(!rsrc_blks
)) {
5755 rsrc_blks
->rsrc_start
= rsrc_id
;
5756 rsrc_blks
->rsrc_size
= rsrc_size
;
5757 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5758 rsrc_start
= rsrc_id
;
5759 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0)) {
5760 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5761 lpfc_sli4_get_iocb_cnt(phba
);
5762 phba
->sli4_hba
.nvme_xri_start
=
5763 phba
->sli4_hba
.scsi_xri_start
+
5764 phba
->sli4_hba
.scsi_xri_max
;
5767 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5772 /* Entire word processed. Get next word.*/
5777 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5784 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5785 * @phba: Pointer to HBA context object.
5786 * @type: the extent's type.
5788 * This function deallocates all extents of a particular resource type.
5789 * SLI4 does not allow for deallocating a particular extent range. It
5790 * is the caller's responsibility to release all kernel memory resources.
5793 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5796 uint32_t length
, mbox_tmo
= 0;
5798 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5799 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5801 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5806 * This function sends an embedded mailbox because it only sends the
5807 * the resource type. All extents of this type are released by the
5810 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5811 sizeof(struct lpfc_sli4_cfg_mhdr
));
5812 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5813 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5814 length
, LPFC_SLI4_MBX_EMBED
);
5816 /* Send an extents count of 0 - the dealloc doesn't use it. */
5817 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5818 LPFC_SLI4_MBX_EMBED
);
5823 if (!phba
->sli4_hba
.intr_enable
)
5824 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5826 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5827 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5834 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5835 if (bf_get(lpfc_mbox_hdr_status
,
5836 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5837 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5838 "2919 Failed to release resource extents "
5839 "for type %d - Status 0x%x Add'l Status 0x%x. "
5840 "Resource memory not released.\n",
5842 bf_get(lpfc_mbox_hdr_status
,
5843 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5844 bf_get(lpfc_mbox_hdr_add_status
,
5845 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5850 /* Release kernel memory resources for the specific type. */
5852 case LPFC_RSC_TYPE_FCOE_VPI
:
5853 kfree(phba
->vpi_bmask
);
5854 kfree(phba
->vpi_ids
);
5855 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5856 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5857 &phba
->lpfc_vpi_blk_list
, list
) {
5858 list_del_init(&rsrc_blk
->list
);
5861 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5863 case LPFC_RSC_TYPE_FCOE_XRI
:
5864 kfree(phba
->sli4_hba
.xri_bmask
);
5865 kfree(phba
->sli4_hba
.xri_ids
);
5866 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5867 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5868 list_del_init(&rsrc_blk
->list
);
5872 case LPFC_RSC_TYPE_FCOE_VFI
:
5873 kfree(phba
->sli4_hba
.vfi_bmask
);
5874 kfree(phba
->sli4_hba
.vfi_ids
);
5875 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5876 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5877 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5878 list_del_init(&rsrc_blk
->list
);
5882 case LPFC_RSC_TYPE_FCOE_RPI
:
5883 /* RPI bitmask and physical id array are cleaned up earlier. */
5884 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5885 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5886 list_del_init(&rsrc_blk
->list
);
5894 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5897 mempool_free(mbox
, phba
->mbox_mem_pool
);
5902 lpfc_set_features(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
,
5907 len
= sizeof(struct lpfc_mbx_set_feature
) -
5908 sizeof(struct lpfc_sli4_cfg_mhdr
);
5909 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5910 LPFC_MBOX_OPCODE_SET_FEATURES
, len
,
5911 LPFC_SLI4_MBX_EMBED
);
5914 case LPFC_SET_UE_RECOVERY
:
5915 bf_set(lpfc_mbx_set_feature_UER
,
5916 &mbox
->u
.mqe
.un
.set_feature
, 1);
5917 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_UE_RECOVERY
;
5918 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5920 case LPFC_SET_MDS_DIAGS
:
5921 bf_set(lpfc_mbx_set_feature_mds
,
5922 &mbox
->u
.mqe
.un
.set_feature
, 1);
5923 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk
,
5924 &mbox
->u
.mqe
.un
.set_feature
, 1);
5925 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_MDS_DIAGS
;
5926 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5934 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5935 * @phba: Pointer to HBA context object.
5937 * This function allocates all SLI4 resource identifiers.
5940 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5942 int i
, rc
, error
= 0;
5943 uint16_t count
, base
;
5944 unsigned long longs
;
5946 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5947 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5948 if (phba
->sli4_hba
.extents_in_use
) {
5950 * The port supports resource extents. The XRI, VPI, VFI, RPI
5951 * resource extent count must be read and allocated before
5952 * provisioning the resource id arrays.
5954 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5955 LPFC_IDX_RSRC_RDY
) {
5957 * Extent-based resources are set - the driver could
5958 * be in a port reset. Figure out if any corrective
5959 * actions need to be taken.
5961 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5962 LPFC_RSC_TYPE_FCOE_VFI
);
5965 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5966 LPFC_RSC_TYPE_FCOE_VPI
);
5969 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5970 LPFC_RSC_TYPE_FCOE_XRI
);
5973 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5974 LPFC_RSC_TYPE_FCOE_RPI
);
5979 * It's possible that the number of resources
5980 * provided to this port instance changed between
5981 * resets. Detect this condition and reallocate
5982 * resources. Otherwise, there is no action.
5985 lpfc_printf_log(phba
, KERN_INFO
,
5986 LOG_MBOX
| LOG_INIT
,
5987 "2931 Detected extent resource "
5988 "change. Reallocating all "
5990 rc
= lpfc_sli4_dealloc_extent(phba
,
5991 LPFC_RSC_TYPE_FCOE_VFI
);
5992 rc
= lpfc_sli4_dealloc_extent(phba
,
5993 LPFC_RSC_TYPE_FCOE_VPI
);
5994 rc
= lpfc_sli4_dealloc_extent(phba
,
5995 LPFC_RSC_TYPE_FCOE_XRI
);
5996 rc
= lpfc_sli4_dealloc_extent(phba
,
5997 LPFC_RSC_TYPE_FCOE_RPI
);
6002 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
6006 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
6010 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
6014 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
6017 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
6022 * The port does not support resource extents. The XRI, VPI,
6023 * VFI, RPI resource ids were determined from READ_CONFIG.
6024 * Just allocate the bitmasks and provision the resource id
6025 * arrays. If a port reset is active, the resources don't
6026 * need any action - just exit.
6028 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
6029 LPFC_IDX_RSRC_RDY
) {
6030 lpfc_sli4_dealloc_resource_identifiers(phba
);
6031 lpfc_sli4_remove_rpis(phba
);
6034 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
6036 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6037 "3279 Invalid provisioning of "
6042 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
6043 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6044 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
6045 sizeof(unsigned long),
6047 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
6051 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
6054 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
6056 goto free_rpi_bmask
;
6059 for (i
= 0; i
< count
; i
++)
6060 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
6063 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
6065 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6066 "3280 Invalid provisioning of "
6071 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
6072 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6073 phba
->vpi_bmask
= kzalloc(longs
*
6074 sizeof(unsigned long),
6076 if (unlikely(!phba
->vpi_bmask
)) {
6080 phba
->vpi_ids
= kzalloc(count
*
6083 if (unlikely(!phba
->vpi_ids
)) {
6085 goto free_vpi_bmask
;
6088 for (i
= 0; i
< count
; i
++)
6089 phba
->vpi_ids
[i
] = base
+ i
;
6092 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
6094 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6095 "3281 Invalid provisioning of "
6100 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
6101 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6102 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
6103 sizeof(unsigned long),
6105 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
6109 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
6110 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
6113 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
6115 goto free_xri_bmask
;
6118 for (i
= 0; i
< count
; i
++)
6119 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
6122 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
6124 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6125 "3282 Invalid provisioning of "
6130 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
6131 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
6132 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
6133 sizeof(unsigned long),
6135 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
6139 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
6142 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
6144 goto free_vfi_bmask
;
6147 for (i
= 0; i
< count
; i
++)
6148 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
6151 * Mark all resources ready. An HBA reset doesn't need
6152 * to reset the initialization.
6154 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
6160 kfree(phba
->sli4_hba
.vfi_bmask
);
6161 phba
->sli4_hba
.vfi_bmask
= NULL
;
6163 kfree(phba
->sli4_hba
.xri_ids
);
6164 phba
->sli4_hba
.xri_ids
= NULL
;
6166 kfree(phba
->sli4_hba
.xri_bmask
);
6167 phba
->sli4_hba
.xri_bmask
= NULL
;
6169 kfree(phba
->vpi_ids
);
6170 phba
->vpi_ids
= NULL
;
6172 kfree(phba
->vpi_bmask
);
6173 phba
->vpi_bmask
= NULL
;
6175 kfree(phba
->sli4_hba
.rpi_ids
);
6176 phba
->sli4_hba
.rpi_ids
= NULL
;
6178 kfree(phba
->sli4_hba
.rpi_bmask
);
6179 phba
->sli4_hba
.rpi_bmask
= NULL
;
6185 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
6186 * @phba: Pointer to HBA context object.
6188 * This function allocates the number of elements for the specified
6192 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
6194 if (phba
->sli4_hba
.extents_in_use
) {
6195 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
6196 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
6197 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
6198 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
6200 kfree(phba
->vpi_bmask
);
6201 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
6202 kfree(phba
->vpi_ids
);
6203 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6204 kfree(phba
->sli4_hba
.xri_bmask
);
6205 kfree(phba
->sli4_hba
.xri_ids
);
6206 kfree(phba
->sli4_hba
.vfi_bmask
);
6207 kfree(phba
->sli4_hba
.vfi_ids
);
6208 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6209 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6216 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6217 * @phba: Pointer to HBA context object.
6218 * @type: The resource extent type.
6219 * @extnt_count: buffer to hold port extent count response
6220 * @extnt_size: buffer to hold port extent size response.
6222 * This function calls the port to read the host allocated extents
6223 * for a particular type.
6226 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
6227 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
6231 uint16_t curr_blks
= 0;
6232 uint32_t req_len
, emb_len
;
6233 uint32_t alloc_len
, mbox_tmo
;
6234 struct list_head
*blk_list_head
;
6235 struct lpfc_rsrc_blks
*rsrc_blk
;
6237 void *virtaddr
= NULL
;
6238 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
6239 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
6240 union lpfc_sli4_cfg_shdr
*shdr
;
6243 case LPFC_RSC_TYPE_FCOE_VPI
:
6244 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
6246 case LPFC_RSC_TYPE_FCOE_XRI
:
6247 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
6249 case LPFC_RSC_TYPE_FCOE_VFI
:
6250 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
6252 case LPFC_RSC_TYPE_FCOE_RPI
:
6253 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
6259 /* Count the number of extents currently allocatd for this type. */
6260 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
6261 if (curr_blks
== 0) {
6263 * The GET_ALLOCATED mailbox does not return the size,
6264 * just the count. The size should be just the size
6265 * stored in the current allocated block and all sizes
6266 * for an extent type are the same so set the return
6269 *extnt_size
= rsrc_blk
->rsrc_size
;
6275 * Calculate the size of an embedded mailbox. The uint32_t
6276 * accounts for extents-specific word.
6278 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
6282 * Presume the allocation and response will fit into an embedded
6283 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6285 emb
= LPFC_SLI4_MBX_EMBED
;
6287 if (req_len
> emb_len
) {
6288 req_len
= curr_blks
* sizeof(uint16_t) +
6289 sizeof(union lpfc_sli4_cfg_shdr
) +
6291 emb
= LPFC_SLI4_MBX_NEMBED
;
6294 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6297 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
6299 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6300 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
6302 if (alloc_len
< req_len
) {
6303 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6304 "2983 Allocated DMA memory size (x%x) is "
6305 "less than the requested DMA memory "
6306 "size (x%x)\n", alloc_len
, req_len
);
6310 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
6316 if (!phba
->sli4_hba
.intr_enable
)
6317 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6319 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
6320 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6329 * Figure out where the response is located. Then get local pointers
6330 * to the response data. The port does not guarantee to respond to
6331 * all extents counts request so update the local variable with the
6332 * allocated count from the port.
6334 if (emb
== LPFC_SLI4_MBX_EMBED
) {
6335 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
6336 shdr
= &rsrc_ext
->header
.cfg_shdr
;
6337 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
6339 virtaddr
= mbox
->sge_array
->addr
[0];
6340 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
6341 shdr
= &n_rsrc
->cfg_shdr
;
6342 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
6345 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
6346 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
6347 "2984 Failed to read allocated resources "
6348 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6350 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
6351 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
6356 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
6361 * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
6362 * @phba: pointer to lpfc hba data structure.
6363 * @pring: Pointer to driver SLI ring object.
6364 * @sgl_list: linked link of sgl buffers to post
6365 * @cnt: number of linked list buffers
6367 * This routine walks the list of buffers that have been allocated and
6368 * repost them to the port by using SGL block post. This is needed after a
6369 * pci_function_reset/warm_start or start. It attempts to construct blocks
6370 * of buffer sgls which contains contiguous xris and uses the non-embedded
6371 * SGL block post mailbox commands to post them to the port. For single
6372 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6373 * mailbox command for posting.
6375 * Returns: 0 = success, non-zero failure.
6378 lpfc_sli4_repost_sgl_list(struct lpfc_hba
*phba
,
6379 struct list_head
*sgl_list
, int cnt
)
6381 struct lpfc_sglq
*sglq_entry
= NULL
;
6382 struct lpfc_sglq
*sglq_entry_next
= NULL
;
6383 struct lpfc_sglq
*sglq_entry_first
= NULL
;
6384 int status
, total_cnt
;
6385 int post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
6386 int last_xritag
= NO_XRI
;
6387 LIST_HEAD(prep_sgl_list
);
6388 LIST_HEAD(blck_sgl_list
);
6389 LIST_HEAD(allc_sgl_list
);
6390 LIST_HEAD(post_sgl_list
);
6391 LIST_HEAD(free_sgl_list
);
6393 spin_lock_irq(&phba
->hbalock
);
6394 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6395 list_splice_init(sgl_list
, &allc_sgl_list
);
6396 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6397 spin_unlock_irq(&phba
->hbalock
);
6400 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6401 &allc_sgl_list
, list
) {
6402 list_del_init(&sglq_entry
->list
);
6404 if ((last_xritag
!= NO_XRI
) &&
6405 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6406 /* a hole in xri block, form a sgl posting block */
6407 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6408 post_cnt
= block_cnt
- 1;
6409 /* prepare list for next posting block */
6410 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6413 /* prepare list for next posting block */
6414 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6415 /* enough sgls for non-embed sgl mbox command */
6416 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6417 list_splice_init(&prep_sgl_list
,
6419 post_cnt
= block_cnt
;
6425 /* keep track of last sgl's xritag */
6426 last_xritag
= sglq_entry
->sli4_xritag
;
6428 /* end of repost sgl list condition for buffers */
6429 if (num_posted
== total_cnt
) {
6430 if (post_cnt
== 0) {
6431 list_splice_init(&prep_sgl_list
,
6433 post_cnt
= block_cnt
;
6434 } else if (block_cnt
== 1) {
6435 status
= lpfc_sli4_post_sgl(phba
,
6436 sglq_entry
->phys
, 0,
6437 sglq_entry
->sli4_xritag
);
6439 /* successful, put sgl to posted list */
6440 list_add_tail(&sglq_entry
->list
,
6443 /* Failure, put sgl to free list */
6444 lpfc_printf_log(phba
, KERN_WARNING
,
6446 "3159 Failed to post "
6447 "sgl, xritag:x%x\n",
6448 sglq_entry
->sli4_xritag
);
6449 list_add_tail(&sglq_entry
->list
,
6456 /* continue until a nembed page worth of sgls */
6460 /* post the buffer list sgls as a block */
6461 status
= lpfc_sli4_post_sgl_list(phba
, &blck_sgl_list
,
6465 /* success, put sgl list to posted sgl list */
6466 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6468 /* Failure, put sgl list to free sgl list */
6469 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6472 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6473 "3160 Failed to post sgl-list, "
6475 sglq_entry_first
->sli4_xritag
,
6476 (sglq_entry_first
->sli4_xritag
+
6478 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6479 total_cnt
-= post_cnt
;
6482 /* don't reset xirtag due to hole in xri block */
6484 last_xritag
= NO_XRI
;
6486 /* reset sgl post count for next round of posting */
6490 /* free the sgls failed to post */
6491 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6493 /* push sgls posted to the available list */
6494 if (!list_empty(&post_sgl_list
)) {
6495 spin_lock_irq(&phba
->hbalock
);
6496 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
6497 list_splice_init(&post_sgl_list
, sgl_list
);
6498 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
6499 spin_unlock_irq(&phba
->hbalock
);
6501 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6502 "3161 Failure to post sgl to port.\n");
6506 /* return the number of XRIs actually posted */
6511 lpfc_set_host_data(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
6515 len
= sizeof(struct lpfc_mbx_set_host_data
) -
6516 sizeof(struct lpfc_sli4_cfg_mhdr
);
6517 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6518 LPFC_MBOX_OPCODE_SET_HOST_DATA
, len
,
6519 LPFC_SLI4_MBX_EMBED
);
6521 mbox
->u
.mqe
.un
.set_host_data
.param_id
= LPFC_SET_HOST_OS_DRIVER_VERSION
;
6522 mbox
->u
.mqe
.un
.set_host_data
.param_len
=
6523 LPFC_HOST_OS_DRIVER_VERSION_SIZE
;
6524 snprintf(mbox
->u
.mqe
.un
.set_host_data
.data
,
6525 LPFC_HOST_OS_DRIVER_VERSION_SIZE
,
6526 "Linux %s v"LPFC_DRIVER_VERSION
,
6527 (phba
->hba_flag
& HBA_FCOE_MODE
) ? "FCoE" : "FC");
6531 lpfc_post_rq_buffer(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
6532 struct lpfc_queue
*drq
, int count
, int idx
)
6535 struct lpfc_rqe hrqe
;
6536 struct lpfc_rqe drqe
;
6537 struct lpfc_rqb
*rqbp
;
6538 struct rqb_dmabuf
*rqb_buffer
;
6539 LIST_HEAD(rqb_buf_list
);
6542 for (i
= 0; i
< count
; i
++) {
6543 /* IF RQ is already full, don't bother */
6544 if (rqbp
->buffer_count
+ i
>= rqbp
->entry_count
- 1)
6546 rqb_buffer
= rqbp
->rqb_alloc_buffer(phba
);
6549 rqb_buffer
->hrq
= hrq
;
6550 rqb_buffer
->drq
= drq
;
6551 rqb_buffer
->idx
= idx
;
6552 list_add_tail(&rqb_buffer
->hbuf
.list
, &rqb_buf_list
);
6554 while (!list_empty(&rqb_buf_list
)) {
6555 list_remove_head(&rqb_buf_list
, rqb_buffer
, struct rqb_dmabuf
,
6558 hrqe
.address_lo
= putPaddrLow(rqb_buffer
->hbuf
.phys
);
6559 hrqe
.address_hi
= putPaddrHigh(rqb_buffer
->hbuf
.phys
);
6560 drqe
.address_lo
= putPaddrLow(rqb_buffer
->dbuf
.phys
);
6561 drqe
.address_hi
= putPaddrHigh(rqb_buffer
->dbuf
.phys
);
6562 rc
= lpfc_sli4_rq_put(hrq
, drq
, &hrqe
, &drqe
);
6564 rqbp
->rqb_free_buffer(phba
, rqb_buffer
);
6566 list_add_tail(&rqb_buffer
->hbuf
.list
,
6567 &rqbp
->rqb_buffer_list
);
6568 rqbp
->buffer_count
++;
6575 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
6576 * @phba: Pointer to HBA context object.
6578 * This function is the main SLI4 device initialization PCI function. This
6579 * function is called by the HBA initialization code, HBA reset code and
6580 * HBA error attention handler code. Caller is not required to hold any
6584 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6587 LPFC_MBOXQ_t
*mboxq
;
6588 struct lpfc_mqe
*mqe
;
6591 uint32_t ftr_rsp
= 0;
6592 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6593 struct lpfc_vport
*vport
= phba
->pport
;
6594 struct lpfc_dmabuf
*mp
;
6595 struct lpfc_rqb
*rqbp
;
6597 /* Perform a PCI function reset to start from clean */
6598 rc
= lpfc_pci_function_reset(phba
);
6602 /* Check the HBA Host Status Register for readyness */
6603 rc
= lpfc_sli4_post_status_check(phba
);
6607 spin_lock_irq(&phba
->hbalock
);
6608 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6609 spin_unlock_irq(&phba
->hbalock
);
6613 * Allocate a single mailbox container for initializing the
6616 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6620 /* Issue READ_REV to collect vpd and FW information. */
6621 vpd_size
= SLI4_PAGE_SIZE
;
6622 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6628 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6634 mqe
= &mboxq
->u
.mqe
;
6635 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6636 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
)) {
6637 phba
->hba_flag
|= HBA_FCOE_MODE
;
6638 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
6640 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6643 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6645 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6647 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6649 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6651 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6652 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6653 "0376 READ_REV Error. SLI Level %d "
6654 "FCoE enabled %d\n",
6655 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6662 * Continue initialization with default values even if driver failed
6663 * to read FCoE param config regions, only read parameters if the
6666 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6667 lpfc_sli4_read_fcoe_params(phba
))
6668 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6669 "2570 Failed to read FCoE parameters\n");
6672 * Retrieve sli4 device physical port name, failure of doing it
6673 * is considered as non-fatal.
6675 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6677 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6678 "3080 Successful retrieving SLI4 device "
6679 "physical port name: %s.\n", phba
->Port
);
6682 * Evaluate the read rev and vpd data. Populate the driver
6683 * state with the results. If this routine fails, the failure
6684 * is not fatal as the driver will use generic values.
6686 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6687 if (unlikely(!rc
)) {
6688 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6689 "0377 Error %d parsing vpd. "
6690 "Using defaults.\n", rc
);
6695 /* Save information as VPD data */
6696 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6697 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6698 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6699 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6701 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6703 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6705 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6707 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6708 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6709 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6710 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6711 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6712 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6713 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6714 "(%d):0380 READ_REV Status x%x "
6715 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6716 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6717 bf_get(lpfc_mqe_status
, mqe
),
6718 phba
->vpd
.rev
.opFwName
,
6719 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6720 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6722 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6723 rc
= (phba
->sli4_hba
.max_cfg_param
.max_xri
>> 3);
6724 if (phba
->pport
->cfg_lun_queue_depth
> rc
) {
6725 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6726 "3362 LUN queue depth changed from %d to %d\n",
6727 phba
->pport
->cfg_lun_queue_depth
, rc
);
6728 phba
->pport
->cfg_lun_queue_depth
= rc
;
6731 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6732 LPFC_SLI_INTF_IF_TYPE_0
) {
6733 lpfc_set_features(phba
, mboxq
, LPFC_SET_UE_RECOVERY
);
6734 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6735 if (rc
== MBX_SUCCESS
) {
6736 phba
->hba_flag
|= HBA_RECOVERABLE_UE
;
6737 /* Set 1Sec interval to detect UE */
6738 phba
->eratt_poll_interval
= 1;
6739 phba
->sli4_hba
.ue_to_sr
= bf_get(
6740 lpfc_mbx_set_feature_UESR
,
6741 &mboxq
->u
.mqe
.un
.set_feature
);
6742 phba
->sli4_hba
.ue_to_rp
= bf_get(
6743 lpfc_mbx_set_feature_UERP
,
6744 &mboxq
->u
.mqe
.un
.set_feature
);
6748 if (phba
->cfg_enable_mds_diags
&& phba
->mds_diags_support
) {
6749 /* Enable MDS Diagnostics only if the SLI Port supports it */
6750 lpfc_set_features(phba
, mboxq
, LPFC_SET_MDS_DIAGS
);
6751 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6752 if (rc
!= MBX_SUCCESS
)
6753 phba
->mds_diags_support
= 0;
6757 * Discover the port's supported feature set and match it against the
6760 lpfc_request_features(phba
, mboxq
);
6761 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6768 * The port must support FCP initiator mode as this is the
6769 * only mode running in the host.
6771 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6772 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6773 "0378 No support for fcpi mode.\n");
6776 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6777 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6779 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6781 * If the port cannot support the host's requested features
6782 * then turn off the global config parameters to disable the
6783 * feature in the driver. This is not a fatal error.
6785 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6786 if (phba
->cfg_enable_bg
) {
6787 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6788 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6793 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6794 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6798 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6799 "0379 Feature Mismatch Data: x%08x %08x "
6800 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6801 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6802 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6803 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6804 phba
->cfg_enable_bg
= 0;
6805 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6806 phba
->cfg_enable_npiv
= 0;
6809 /* These SLI3 features are assumed in SLI4 */
6810 spin_lock_irq(&phba
->hbalock
);
6811 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6812 spin_unlock_irq(&phba
->hbalock
);
6815 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6816 * calls depends on these resources to complete port setup.
6818 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6820 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6821 "2920 Failed to alloc Resource IDs "
6826 lpfc_set_host_data(phba
, mboxq
);
6828 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6830 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6831 "2134 Failed to set host os driver version %x",
6835 /* Read the port's service parameters. */
6836 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6838 phba
->link_state
= LPFC_HBA_ERROR
;
6843 mboxq
->vport
= vport
;
6844 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6845 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6846 if (rc
== MBX_SUCCESS
) {
6847 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6852 * This memory was allocated by the lpfc_read_sparam routine. Release
6853 * it to the mbuf pool.
6855 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6857 mboxq
->context1
= NULL
;
6859 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6860 "0382 READ_SPARAM command failed "
6861 "status %d, mbxStatus x%x\n",
6862 rc
, bf_get(lpfc_mqe_status
, mqe
));
6863 phba
->link_state
= LPFC_HBA_ERROR
;
6868 lpfc_update_vport_wwn(vport
);
6870 /* Update the fc_host data structures with new wwn. */
6871 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6872 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6874 /* Create all the SLI4 queues */
6875 rc
= lpfc_sli4_queue_create(phba
);
6877 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6878 "3089 Failed to allocate queues\n");
6882 /* Set up all the queues to the device */
6883 rc
= lpfc_sli4_queue_setup(phba
);
6885 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6886 "0381 Error %d during queue setup.\n ", rc
);
6887 goto out_stop_timers
;
6889 /* Initialize the driver internal SLI layer lists. */
6890 lpfc_sli4_setup(phba
);
6891 lpfc_sli4_queue_init(phba
);
6893 /* update host els xri-sgl sizes and mappings */
6894 rc
= lpfc_sli4_els_sgl_update(phba
);
6896 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6897 "1400 Failed to update xri-sgl size and "
6898 "mapping: %d\n", rc
);
6899 goto out_destroy_queue
;
6902 /* register the els sgl pool to the port */
6903 rc
= lpfc_sli4_repost_sgl_list(phba
, &phba
->sli4_hba
.lpfc_els_sgl_list
,
6904 phba
->sli4_hba
.els_xri_cnt
);
6905 if (unlikely(rc
< 0)) {
6906 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6907 "0582 Error %d during els sgl post "
6910 goto out_destroy_queue
;
6912 phba
->sli4_hba
.els_xri_cnt
= rc
;
6914 if (phba
->nvmet_support
) {
6915 /* update host nvmet xri-sgl sizes and mappings */
6916 rc
= lpfc_sli4_nvmet_sgl_update(phba
);
6918 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6919 "6308 Failed to update nvmet-sgl size "
6920 "and mapping: %d\n", rc
);
6921 goto out_destroy_queue
;
6924 /* register the nvmet sgl pool to the port */
6925 rc
= lpfc_sli4_repost_sgl_list(
6927 &phba
->sli4_hba
.lpfc_nvmet_sgl_list
,
6928 phba
->sli4_hba
.nvmet_xri_cnt
);
6929 if (unlikely(rc
< 0)) {
6930 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6931 "3117 Error %d during nvmet "
6934 goto out_destroy_queue
;
6936 phba
->sli4_hba
.nvmet_xri_cnt
= rc
;
6938 cnt
= phba
->cfg_iocb_cnt
* 1024;
6939 /* We need 1 iocbq for every SGL, for IO processing */
6940 cnt
+= phba
->sli4_hba
.nvmet_xri_cnt
;
6942 /* update host scsi xri-sgl sizes and mappings */
6943 rc
= lpfc_sli4_scsi_sgl_update(phba
);
6945 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6946 "6309 Failed to update scsi-sgl size "
6947 "and mapping: %d\n", rc
);
6948 goto out_destroy_queue
;
6951 /* update host nvme xri-sgl sizes and mappings */
6952 rc
= lpfc_sli4_nvme_sgl_update(phba
);
6954 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6955 "6082 Failed to update nvme-sgl size "
6956 "and mapping: %d\n", rc
);
6957 goto out_destroy_queue
;
6960 cnt
= phba
->cfg_iocb_cnt
* 1024;
6963 if (!phba
->sli
.iocbq_lookup
) {
6964 /* Initialize and populate the iocb list per host */
6965 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6966 "2821 initialize iocb list %d total %d\n",
6967 phba
->cfg_iocb_cnt
, cnt
);
6968 rc
= lpfc_init_iocb_list(phba
, cnt
);
6970 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6971 "1413 Failed to init iocb list.\n");
6972 goto out_destroy_queue
;
6976 if (phba
->nvmet_support
)
6977 lpfc_nvmet_create_targetport(phba
);
6979 if (phba
->nvmet_support
&& phba
->cfg_nvmet_mrq
) {
6980 /* Post initial buffers to all RQs created */
6981 for (i
= 0; i
< phba
->cfg_nvmet_mrq
; i
++) {
6982 rqbp
= phba
->sli4_hba
.nvmet_mrq_hdr
[i
]->rqbp
;
6983 INIT_LIST_HEAD(&rqbp
->rqb_buffer_list
);
6984 rqbp
->rqb_alloc_buffer
= lpfc_sli4_nvmet_alloc
;
6985 rqbp
->rqb_free_buffer
= lpfc_sli4_nvmet_free
;
6986 rqbp
->entry_count
= LPFC_NVMET_RQE_DEF_COUNT
;
6987 rqbp
->buffer_count
= 0;
6989 lpfc_post_rq_buffer(
6990 phba
, phba
->sli4_hba
.nvmet_mrq_hdr
[i
],
6991 phba
->sli4_hba
.nvmet_mrq_data
[i
],
6992 LPFC_NVMET_RQE_DEF_COUNT
, i
);
6996 if (phba
->cfg_enable_fc4_type
& LPFC_ENABLE_FCP
) {
6997 /* register the allocated scsi sgl pool to the port */
6998 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
7000 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7001 "0383 Error %d during scsi sgl post "
7003 /* Some Scsi buffers were moved to abort scsi list */
7004 /* A pci function reset will repost them */
7006 goto out_destroy_queue
;
7010 if ((phba
->cfg_enable_fc4_type
& LPFC_ENABLE_NVME
) &&
7011 (phba
->nvmet_support
== 0)) {
7013 /* register the allocated nvme sgl pool to the port */
7014 rc
= lpfc_repost_nvme_sgl_list(phba
);
7016 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7017 "6116 Error %d during nvme sgl post "
7019 /* Some NVME buffers were moved to abort nvme list */
7020 /* A pci function reset will repost them */
7022 goto out_destroy_queue
;
7026 /* Post the rpi header region to the device. */
7027 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
7029 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7030 "0393 Error %d during rpi post operation\n",
7033 goto out_destroy_queue
;
7035 lpfc_sli4_node_prep(phba
);
7037 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
7038 if ((phba
->nvmet_support
== 0) || (phba
->cfg_nvmet_mrq
== 1)) {
7040 * The FC Port needs to register FCFI (index 0)
7042 lpfc_reg_fcfi(phba
, mboxq
);
7043 mboxq
->vport
= phba
->pport
;
7044 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7045 if (rc
!= MBX_SUCCESS
)
7046 goto out_unset_queue
;
7048 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
7049 &mboxq
->u
.mqe
.un
.reg_fcfi
);
7051 /* We are a NVME Target mode with MRQ > 1 */
7053 /* First register the FCFI */
7054 lpfc_reg_fcfi_mrq(phba
, mboxq
, 0);
7055 mboxq
->vport
= phba
->pport
;
7056 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7057 if (rc
!= MBX_SUCCESS
)
7058 goto out_unset_queue
;
7060 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_mrq_fcfi
,
7061 &mboxq
->u
.mqe
.un
.reg_fcfi_mrq
);
7063 /* Next register the MRQs */
7064 lpfc_reg_fcfi_mrq(phba
, mboxq
, 1);
7065 mboxq
->vport
= phba
->pport
;
7066 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7067 if (rc
!= MBX_SUCCESS
)
7068 goto out_unset_queue
;
7071 /* Check if the port is configured to be disabled */
7072 lpfc_sli_read_link_ste(phba
);
7075 /* Arm the CQs and then EQs on device */
7076 lpfc_sli4_arm_cqeq_intr(phba
);
7078 /* Indicate device interrupt mode */
7079 phba
->sli4_hba
.intr_enable
= 1;
7081 /* Allow asynchronous mailbox command to go through */
7082 spin_lock_irq(&phba
->hbalock
);
7083 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7084 spin_unlock_irq(&phba
->hbalock
);
7086 /* Post receive buffers to the device */
7087 lpfc_sli4_rb_setup(phba
);
7089 /* Reset HBA FCF states after HBA reset */
7090 phba
->fcf
.fcf_flag
= 0;
7091 phba
->fcf
.current_rec
.flag
= 0;
7093 /* Start the ELS watchdog timer */
7094 mod_timer(&vport
->els_tmofunc
,
7095 jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2)));
7097 /* Start heart beat timer */
7098 mod_timer(&phba
->hb_tmofunc
,
7099 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
7100 phba
->hb_outstanding
= 0;
7101 phba
->last_completion_time
= jiffies
;
7103 /* Start error attention (ERATT) polling timer */
7104 mod_timer(&phba
->eratt_poll
,
7105 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
7107 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
7108 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
7109 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
7111 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7112 "2829 This device supports "
7113 "Advanced Error Reporting (AER)\n");
7114 spin_lock_irq(&phba
->hbalock
);
7115 phba
->hba_flag
|= HBA_AER_ENABLED
;
7116 spin_unlock_irq(&phba
->hbalock
);
7118 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7119 "2830 This device does not support "
7120 "Advanced Error Reporting (AER)\n");
7121 phba
->cfg_aer_support
= 0;
7127 * The port is ready, set the host's link state to LINK_DOWN
7128 * in preparation for link interrupts.
7130 spin_lock_irq(&phba
->hbalock
);
7131 phba
->link_state
= LPFC_LINK_DOWN
;
7132 spin_unlock_irq(&phba
->hbalock
);
7133 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
7134 (phba
->hba_flag
& LINK_DISABLED
)) {
7135 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
7136 "3103 Adapter Link is disabled.\n");
7137 lpfc_down_link(phba
, mboxq
);
7138 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7139 if (rc
!= MBX_SUCCESS
) {
7140 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
7141 "3104 Adapter failed to issue "
7142 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
7143 goto out_unset_queue
;
7145 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
7146 /* don't perform init_link on SLI4 FC port loopback test */
7147 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
7148 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
7150 goto out_unset_queue
;
7153 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7156 /* Unset all the queues set up in this routine when error out */
7157 lpfc_sli4_queue_unset(phba
);
7159 lpfc_free_iocb_list(phba
);
7160 lpfc_sli4_queue_destroy(phba
);
7162 lpfc_stop_hba_timers(phba
);
7164 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7169 * lpfc_mbox_timeout - Timeout call back function for mbox timer
7170 * @ptr: context object - pointer to hba structure.
7172 * This is the callback function for mailbox timer. The mailbox
7173 * timer is armed when a new mailbox command is issued and the timer
7174 * is deleted when the mailbox complete. The function is called by
7175 * the kernel timer code when a mailbox does not complete within
7176 * expected time. This function wakes up the worker thread to
7177 * process the mailbox timeout and returns. All the processing is
7178 * done by the worker thread function lpfc_mbox_timeout_handler.
7181 lpfc_mbox_timeout(struct timer_list
*t
)
7183 struct lpfc_hba
*phba
= from_timer(phba
, t
, sli
.mbox_tmo
);
7184 unsigned long iflag
;
7185 uint32_t tmo_posted
;
7187 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
7188 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
7190 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
7191 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
7194 lpfc_worker_wake_up(phba
);
7199 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
7201 * @phba: Pointer to HBA context object.
7203 * This function checks if any mailbox completions are present on the mailbox
7207 lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
)
7211 struct lpfc_queue
*mcq
;
7212 struct lpfc_mcqe
*mcqe
;
7213 bool pending_completions
= false;
7215 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
7218 /* Check for completions on mailbox completion queue */
7220 mcq
= phba
->sli4_hba
.mbx_cq
;
7221 idx
= mcq
->hba_index
;
7222 while (bf_get_le32(lpfc_cqe_valid
, mcq
->qe
[idx
].cqe
)) {
7223 mcqe
= (struct lpfc_mcqe
*)mcq
->qe
[idx
].cqe
;
7224 if (bf_get_le32(lpfc_trailer_completed
, mcqe
) &&
7225 (!bf_get_le32(lpfc_trailer_async
, mcqe
))) {
7226 pending_completions
= true;
7229 idx
= (idx
+ 1) % mcq
->entry_count
;
7230 if (mcq
->hba_index
== idx
)
7233 return pending_completions
;
7238 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
7240 * @phba: Pointer to HBA context object.
7242 * For sli4, it is possible to miss an interrupt. As such mbox completions
7243 * maybe missed causing erroneous mailbox timeouts to occur. This function
7244 * checks to see if mbox completions are on the mailbox completion queue
7245 * and will process all the completions associated with the eq for the
7246 * mailbox completion queue.
7249 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
)
7253 struct lpfc_queue
*fpeq
= NULL
;
7254 struct lpfc_eqe
*eqe
;
7257 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
7260 /* Find the eq associated with the mcq */
7262 if (phba
->sli4_hba
.hba_eq
)
7263 for (eqidx
= 0; eqidx
< phba
->io_channel_irqs
; eqidx
++)
7264 if (phba
->sli4_hba
.hba_eq
[eqidx
]->queue_id
==
7265 phba
->sli4_hba
.mbx_cq
->assoc_qid
) {
7266 fpeq
= phba
->sli4_hba
.hba_eq
[eqidx
];
7272 /* Turn off interrupts from this EQ */
7274 lpfc_sli4_eq_clr_intr(fpeq
);
7276 /* Check to see if a mbox completion is pending */
7278 mbox_pending
= lpfc_sli4_mbox_completions_pending(phba
);
7281 * If a mbox completion is pending, process all the events on EQ
7282 * associated with the mbox completion queue (this could include
7283 * mailbox commands, async events, els commands, receive queue data
7288 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
7289 lpfc_sli4_hba_handle_eqe(phba
, eqe
, eqidx
);
7290 fpeq
->EQ_processed
++;
7293 /* Always clear and re-arm the EQ */
7295 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
7297 return mbox_pending
;
7302 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
7303 * @phba: Pointer to HBA context object.
7305 * This function is called from worker thread when a mailbox command times out.
7306 * The caller is not required to hold any locks. This function will reset the
7307 * HBA and recover all the pending commands.
7310 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
7312 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
7313 MAILBOX_t
*mb
= NULL
;
7315 struct lpfc_sli
*psli
= &phba
->sli
;
7317 /* If the mailbox completed, process the completion and return */
7318 if (lpfc_sli4_process_missed_mbox_completions(phba
))
7323 /* Check the pmbox pointer first. There is a race condition
7324 * between the mbox timeout handler getting executed in the
7325 * worklist and the mailbox actually completing. When this
7326 * race condition occurs, the mbox_active will be NULL.
7328 spin_lock_irq(&phba
->hbalock
);
7329 if (pmbox
== NULL
) {
7330 lpfc_printf_log(phba
, KERN_WARNING
,
7332 "0353 Active Mailbox cleared - mailbox timeout "
7334 spin_unlock_irq(&phba
->hbalock
);
7338 /* Mbox cmd <mbxCommand> timeout */
7339 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7340 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
7342 phba
->pport
->port_state
,
7344 phba
->sli
.mbox_active
);
7345 spin_unlock_irq(&phba
->hbalock
);
7347 /* Setting state unknown so lpfc_sli_abort_iocb_ring
7348 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
7349 * it to fail all outstanding SCSI IO.
7351 spin_lock_irq(&phba
->pport
->work_port_lock
);
7352 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
7353 spin_unlock_irq(&phba
->pport
->work_port_lock
);
7354 spin_lock_irq(&phba
->hbalock
);
7355 phba
->link_state
= LPFC_LINK_UNKNOWN
;
7356 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
7357 spin_unlock_irq(&phba
->hbalock
);
7359 lpfc_sli_abort_fcp_rings(phba
);
7361 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7362 "0345 Resetting board due to mailbox timeout\n");
7364 /* Reset the HBA device */
7365 lpfc_reset_hba(phba
);
7369 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
7370 * @phba: Pointer to HBA context object.
7371 * @pmbox: Pointer to mailbox object.
7372 * @flag: Flag indicating how the mailbox need to be processed.
7374 * This function is called by discovery code and HBA management code
7375 * to submit a mailbox command to firmware with SLI-3 interface spec. This
7376 * function gets the hbalock to protect the data structures.
7377 * The mailbox command can be submitted in polling mode, in which case
7378 * this function will wait in a polling loop for the completion of the
7380 * If the mailbox is submitted in no_wait mode (not polling) the
7381 * function will submit the command and returns immediately without waiting
7382 * for the mailbox completion. The no_wait is supported only when HBA
7383 * is in SLI2/SLI3 mode - interrupts are enabled.
7384 * The SLI interface allows only one mailbox pending at a time. If the
7385 * mailbox is issued in polling mode and there is already a mailbox
7386 * pending, then the function will return an error. If the mailbox is issued
7387 * in NO_WAIT mode and there is a mailbox pending already, the function
7388 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
7389 * The sli layer owns the mailbox object until the completion of mailbox
7390 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
7391 * return codes the caller owns the mailbox command after the return of
7395 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
7399 struct lpfc_sli
*psli
= &phba
->sli
;
7400 uint32_t status
, evtctr
;
7401 uint32_t ha_copy
, hc_copy
;
7403 unsigned long timeout
;
7404 unsigned long drvr_flag
= 0;
7405 uint32_t word0
, ldata
;
7406 void __iomem
*to_slim
;
7407 int processing_queue
= 0;
7409 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7411 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7412 /* processing mbox queue from intr_handler */
7413 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7414 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7417 processing_queue
= 1;
7418 pmbox
= lpfc_mbox_get(phba
);
7420 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7425 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
7426 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
7428 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7429 lpfc_printf_log(phba
, KERN_ERR
,
7430 LOG_MBOX
| LOG_VPORT
,
7431 "1806 Mbox x%x failed. No vport\n",
7432 pmbox
->u
.mb
.mbxCommand
);
7434 goto out_not_finished
;
7438 /* If the PCI channel is in offline state, do not post mbox. */
7439 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7440 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7441 goto out_not_finished
;
7444 /* If HBA has a deferred error attention, fail the iocb. */
7445 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7446 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7447 goto out_not_finished
;
7453 status
= MBX_SUCCESS
;
7455 if (phba
->link_state
== LPFC_HBA_ERROR
) {
7456 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7458 /* Mbox command <mbxCommand> cannot issue */
7459 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7460 "(%d):0311 Mailbox command x%x cannot "
7461 "issue Data: x%x x%x\n",
7462 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7463 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7464 goto out_not_finished
;
7467 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
7468 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
7469 !(hc_copy
& HC_MBINT_ENA
)) {
7470 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7471 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7472 "(%d):2528 Mailbox command x%x cannot "
7473 "issue Data: x%x x%x\n",
7474 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7475 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7476 goto out_not_finished
;
7480 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7481 /* Polling for a mbox command when another one is already active
7482 * is not allowed in SLI. Also, the driver must have established
7483 * SLI2 mode to queue and process multiple mbox commands.
7486 if (flag
& MBX_POLL
) {
7487 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7489 /* Mbox command <mbxCommand> cannot issue */
7490 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7491 "(%d):2529 Mailbox command x%x "
7492 "cannot issue Data: x%x x%x\n",
7493 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7494 pmbox
->u
.mb
.mbxCommand
,
7495 psli
->sli_flag
, flag
);
7496 goto out_not_finished
;
7499 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
7500 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7501 /* Mbox command <mbxCommand> cannot issue */
7502 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7503 "(%d):2530 Mailbox command x%x "
7504 "cannot issue Data: x%x x%x\n",
7505 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7506 pmbox
->u
.mb
.mbxCommand
,
7507 psli
->sli_flag
, flag
);
7508 goto out_not_finished
;
7511 /* Another mailbox command is still being processed, queue this
7512 * command to be processed later.
7514 lpfc_mbox_put(phba
, pmbox
);
7516 /* Mbox cmd issue - BUSY */
7517 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7518 "(%d):0308 Mbox cmd issue - BUSY Data: "
7519 "x%x x%x x%x x%x\n",
7520 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
7522 phba
->pport
? phba
->pport
->port_state
: 0xff,
7523 psli
->sli_flag
, flag
);
7525 psli
->slistat
.mbox_busy
++;
7526 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7529 lpfc_debugfs_disc_trc(pmbox
->vport
,
7530 LPFC_DISC_TRC_MBOX_VPORT
,
7531 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
7532 (uint32_t)mbx
->mbxCommand
,
7533 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7536 lpfc_debugfs_disc_trc(phba
->pport
,
7538 "MBOX Bsy: cmd:x%x mb:x%x x%x",
7539 (uint32_t)mbx
->mbxCommand
,
7540 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7546 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7548 /* If we are not polling, we MUST be in SLI2 mode */
7549 if (flag
!= MBX_POLL
) {
7550 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
7551 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
7552 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7553 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7554 /* Mbox command <mbxCommand> cannot issue */
7555 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7556 "(%d):2531 Mailbox command x%x "
7557 "cannot issue Data: x%x x%x\n",
7558 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7559 pmbox
->u
.mb
.mbxCommand
,
7560 psli
->sli_flag
, flag
);
7561 goto out_not_finished
;
7563 /* timeout active mbox command */
7564 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7566 mod_timer(&psli
->mbox_tmo
, jiffies
+ timeout
);
7569 /* Mailbox cmd <cmd> issue */
7570 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7571 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
7573 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7575 phba
->pport
? phba
->pport
->port_state
: 0xff,
7576 psli
->sli_flag
, flag
);
7578 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
7580 lpfc_debugfs_disc_trc(pmbox
->vport
,
7581 LPFC_DISC_TRC_MBOX_VPORT
,
7582 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7583 (uint32_t)mbx
->mbxCommand
,
7584 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7587 lpfc_debugfs_disc_trc(phba
->pport
,
7589 "MBOX Send: cmd:x%x mb:x%x x%x",
7590 (uint32_t)mbx
->mbxCommand
,
7591 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7595 psli
->slistat
.mbox_cmd
++;
7596 evtctr
= psli
->slistat
.mbox_event
;
7598 /* next set own bit for the adapter and copy over command word */
7599 mbx
->mbxOwner
= OWN_CHIP
;
7601 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7602 /* Populate mbox extension offset word. */
7603 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
7604 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7605 = (uint8_t *)phba
->mbox_ext
7606 - (uint8_t *)phba
->mbox
;
7609 /* Copy the mailbox extension data */
7610 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7611 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
7612 (uint8_t *)phba
->mbox_ext
,
7613 pmbox
->in_ext_byte_len
);
7615 /* Copy command data to host SLIM area */
7616 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7618 /* Populate mbox extension offset word. */
7619 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
7620 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7621 = MAILBOX_HBA_EXT_OFFSET
;
7623 /* Copy the mailbox extension data */
7624 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
)
7625 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
7626 MAILBOX_HBA_EXT_OFFSET
,
7627 pmbox
->context2
, pmbox
->in_ext_byte_len
);
7629 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
)
7630 /* copy command data into host mbox for cmpl */
7631 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
,
7634 /* First copy mbox command data to HBA SLIM, skip past first
7636 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
7637 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
7638 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
7640 /* Next copy over first word, with mbxOwner set */
7641 ldata
= *((uint32_t *)mbx
);
7642 to_slim
= phba
->MBslimaddr
;
7643 writel(ldata
, to_slim
);
7644 readl(to_slim
); /* flush */
7646 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
)
7647 /* switch over to host mailbox */
7648 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
7655 /* Set up reference to mailbox command */
7656 psli
->mbox_active
= pmbox
;
7657 /* Interrupt board to do it */
7658 writel(CA_MBATT
, phba
->CAregaddr
);
7659 readl(phba
->CAregaddr
); /* flush */
7660 /* Don't wait for it to finish, just return */
7664 /* Set up null reference to mailbox command */
7665 psli
->mbox_active
= NULL
;
7666 /* Interrupt board to do it */
7667 writel(CA_MBATT
, phba
->CAregaddr
);
7668 readl(phba
->CAregaddr
); /* flush */
7670 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7671 /* First read mbox status word */
7672 word0
= *((uint32_t *)phba
->mbox
);
7673 word0
= le32_to_cpu(word0
);
7675 /* First read mbox status word */
7676 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
7677 spin_unlock_irqrestore(&phba
->hbalock
,
7679 goto out_not_finished
;
7683 /* Read the HBA Host Attention Register */
7684 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7685 spin_unlock_irqrestore(&phba
->hbalock
,
7687 goto out_not_finished
;
7689 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7692 /* Wait for command to complete */
7693 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
7694 (!(ha_copy
& HA_MBATT
) &&
7695 (phba
->link_state
> LPFC_WARM_START
))) {
7696 if (time_after(jiffies
, timeout
)) {
7697 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7698 spin_unlock_irqrestore(&phba
->hbalock
,
7700 goto out_not_finished
;
7703 /* Check if we took a mbox interrupt while we were
7705 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
7706 && (evtctr
!= psli
->slistat
.mbox_event
))
7710 spin_unlock_irqrestore(&phba
->hbalock
,
7713 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7716 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7717 /* First copy command data */
7718 word0
= *((uint32_t *)phba
->mbox
);
7719 word0
= le32_to_cpu(word0
);
7720 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7723 /* Check real SLIM for any errors */
7724 slimword0
= readl(phba
->MBslimaddr
);
7725 slimmb
= (MAILBOX_t
*) & slimword0
;
7726 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
7727 && slimmb
->mbxStatus
) {
7734 /* First copy command data */
7735 word0
= readl(phba
->MBslimaddr
);
7737 /* Read the HBA Host Attention Register */
7738 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7739 spin_unlock_irqrestore(&phba
->hbalock
,
7741 goto out_not_finished
;
7745 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7746 /* copy results back to user */
7747 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
,
7749 /* Copy the mailbox extension data */
7750 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7751 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7753 pmbox
->out_ext_byte_len
);
7756 /* First copy command data */
7757 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
7759 /* Copy the mailbox extension data */
7760 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7761 lpfc_memcpy_from_slim(pmbox
->context2
,
7763 MAILBOX_HBA_EXT_OFFSET
,
7764 pmbox
->out_ext_byte_len
);
7768 writel(HA_MBATT
, phba
->HAregaddr
);
7769 readl(phba
->HAregaddr
); /* flush */
7771 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7772 status
= mbx
->mbxStatus
;
7775 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7779 if (processing_queue
) {
7780 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7781 lpfc_mbox_cmpl_put(phba
, pmbox
);
7783 return MBX_NOT_FINISHED
;
7787 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7788 * @phba: Pointer to HBA context object.
7790 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7791 * the driver internal pending mailbox queue. It will then try to wait out the
7792 * possible outstanding mailbox command before return.
7795 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7796 * the outstanding mailbox command timed out.
7799 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7801 struct lpfc_sli
*psli
= &phba
->sli
;
7803 unsigned long timeout
= 0;
7805 /* Mark the asynchronous mailbox command posting as blocked */
7806 spin_lock_irq(&phba
->hbalock
);
7807 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7808 /* Determine how long we might wait for the active mailbox
7809 * command to be gracefully completed by firmware.
7811 if (phba
->sli
.mbox_active
)
7812 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7813 phba
->sli
.mbox_active
) *
7815 spin_unlock_irq(&phba
->hbalock
);
7817 /* Make sure the mailbox is really active */
7819 lpfc_sli4_process_missed_mbox_completions(phba
);
7821 /* Wait for the outstnading mailbox command to complete */
7822 while (phba
->sli
.mbox_active
) {
7823 /* Check active mailbox complete status every 2ms */
7825 if (time_after(jiffies
, timeout
)) {
7826 /* Timeout, marked the outstanding cmd not complete */
7832 /* Can not cleanly block async mailbox command, fails it */
7834 spin_lock_irq(&phba
->hbalock
);
7835 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7836 spin_unlock_irq(&phba
->hbalock
);
7842 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7843 * @phba: Pointer to HBA context object.
7845 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7846 * commands from the driver internal pending mailbox queue. It makes sure
7847 * that there is no outstanding mailbox command before resuming posting
7848 * asynchronous mailbox commands. If, for any reason, there is outstanding
7849 * mailbox command, it will try to wait it out before resuming asynchronous
7850 * mailbox command posting.
7853 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7855 struct lpfc_sli
*psli
= &phba
->sli
;
7857 spin_lock_irq(&phba
->hbalock
);
7858 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7859 /* Asynchronous mailbox posting is not blocked, do nothing */
7860 spin_unlock_irq(&phba
->hbalock
);
7864 /* Outstanding synchronous mailbox command is guaranteed to be done,
7865 * successful or timeout, after timing-out the outstanding mailbox
7866 * command shall always be removed, so just unblock posting async
7867 * mailbox command and resume
7869 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7870 spin_unlock_irq(&phba
->hbalock
);
7872 /* wake up worker thread to post asynchronlous mailbox command */
7873 lpfc_worker_wake_up(phba
);
7877 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7878 * @phba: Pointer to HBA context object.
7879 * @mboxq: Pointer to mailbox object.
7881 * The function waits for the bootstrap mailbox register ready bit from
7882 * port for twice the regular mailbox command timeout value.
7884 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7885 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7888 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7891 unsigned long timeout
;
7892 struct lpfc_register bmbx_reg
;
7894 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7898 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7899 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7903 if (time_after(jiffies
, timeout
))
7904 return MBXERR_ERROR
;
7905 } while (!db_ready
);
7911 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7912 * @phba: Pointer to HBA context object.
7913 * @mboxq: Pointer to mailbox object.
7915 * The function posts a mailbox to the port. The mailbox is expected
7916 * to be comletely filled in and ready for the port to operate on it.
7917 * This routine executes a synchronous completion operation on the
7918 * mailbox by polling for its completion.
7920 * The caller must not be holding any locks when calling this routine.
7923 * MBX_SUCCESS - mailbox posted successfully
7924 * Any of the MBX error values.
7927 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7929 int rc
= MBX_SUCCESS
;
7930 unsigned long iflag
;
7931 uint32_t mcqe_status
;
7933 struct lpfc_sli
*psli
= &phba
->sli
;
7934 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7935 struct lpfc_bmbx_create
*mbox_rgn
;
7936 struct dma_address
*dma_address
;
7939 * Only one mailbox can be active to the bootstrap mailbox region
7940 * at a time and there is no queueing provided.
7942 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7943 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7944 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7945 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7946 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7947 "cannot issue Data: x%x x%x\n",
7948 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7949 mboxq
->u
.mb
.mbxCommand
,
7950 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7951 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7952 psli
->sli_flag
, MBX_POLL
);
7953 return MBXERR_ERROR
;
7955 /* The server grabs the token and owns it until release */
7956 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7957 phba
->sli
.mbox_active
= mboxq
;
7958 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7960 /* wait for bootstrap mbox register for readyness */
7961 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7966 * Initialize the bootstrap memory region to avoid stale data areas
7967 * in the mailbox post. Then copy the caller's mailbox contents to
7968 * the bmbx mailbox region.
7970 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7971 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7972 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7973 sizeof(struct lpfc_mqe
));
7975 /* Post the high mailbox dma address to the port and wait for ready. */
7976 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7977 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7979 /* wait for bootstrap mbox register for hi-address write done */
7980 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7984 /* Post the low mailbox dma address to the port. */
7985 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7987 /* wait for bootstrap mbox register for low address write done */
7988 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7993 * Read the CQ to ensure the mailbox has completed.
7994 * If so, update the mailbox status so that the upper layers
7995 * can complete the request normally.
7997 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7998 sizeof(struct lpfc_mqe
));
7999 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
8000 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
8001 sizeof(struct lpfc_mcqe
));
8002 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
8004 * When the CQE status indicates a failure and the mailbox status
8005 * indicates success then copy the CQE status into the mailbox status
8006 * (and prefix it with x4000).
8008 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
8009 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
8010 bf_set(lpfc_mqe_status
, mb
,
8011 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
8014 lpfc_sli4_swap_str(phba
, mboxq
);
8016 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8017 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
8018 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
8019 " x%x x%x CQ: x%x x%x x%x x%x\n",
8020 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
8021 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8022 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8023 bf_get(lpfc_mqe_status
, mb
),
8024 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
8025 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
8026 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
8027 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
8028 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
8029 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
8030 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
8031 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
8032 mboxq
->mcqe
.trailer
);
8034 /* We are holding the token, no needed for lock when release */
8035 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8036 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8037 phba
->sli
.mbox_active
= NULL
;
8038 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8043 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
8044 * @phba: Pointer to HBA context object.
8045 * @pmbox: Pointer to mailbox object.
8046 * @flag: Flag indicating how the mailbox need to be processed.
8048 * This function is called by discovery code and HBA management code to submit
8049 * a mailbox command to firmware with SLI-4 interface spec.
8051 * Return codes the caller owns the mailbox command after the return of the
8055 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
8058 struct lpfc_sli
*psli
= &phba
->sli
;
8059 unsigned long iflags
;
8062 /* dump from issue mailbox command if setup */
8063 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
8065 rc
= lpfc_mbox_dev_check(phba
);
8067 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8068 "(%d):2544 Mailbox command x%x (x%x/x%x) "
8069 "cannot issue Data: x%x x%x\n",
8070 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8071 mboxq
->u
.mb
.mbxCommand
,
8072 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8073 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8074 psli
->sli_flag
, flag
);
8075 goto out_not_finished
;
8078 /* Detect polling mode and jump to a handler */
8079 if (!phba
->sli4_hba
.intr_enable
) {
8080 if (flag
== MBX_POLL
)
8081 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
8084 if (rc
!= MBX_SUCCESS
)
8085 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
8086 "(%d):2541 Mailbox command x%x "
8087 "(x%x/x%x) failure: "
8088 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8090 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8091 mboxq
->u
.mb
.mbxCommand
,
8092 lpfc_sli_config_mbox_subsys_get(phba
,
8094 lpfc_sli_config_mbox_opcode_get(phba
,
8096 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
8097 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
8098 bf_get(lpfc_mcqe_ext_status
,
8100 psli
->sli_flag
, flag
);
8102 } else if (flag
== MBX_POLL
) {
8103 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
8104 "(%d):2542 Try to issue mailbox command "
8105 "x%x (x%x/x%x) synchronously ahead of async"
8106 "mailbox command queue: x%x x%x\n",
8107 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8108 mboxq
->u
.mb
.mbxCommand
,
8109 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8110 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8111 psli
->sli_flag
, flag
);
8112 /* Try to block the asynchronous mailbox posting */
8113 rc
= lpfc_sli4_async_mbox_block(phba
);
8115 /* Successfully blocked, now issue sync mbox cmd */
8116 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
8117 if (rc
!= MBX_SUCCESS
)
8118 lpfc_printf_log(phba
, KERN_WARNING
,
8120 "(%d):2597 Sync Mailbox command "
8121 "x%x (x%x/x%x) failure: "
8122 "mqe_sta: x%x mcqe_sta: x%x/x%x "
8124 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8125 mboxq
->u
.mb
.mbxCommand
,
8126 lpfc_sli_config_mbox_subsys_get(phba
,
8128 lpfc_sli_config_mbox_opcode_get(phba
,
8130 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
8131 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
8132 bf_get(lpfc_mcqe_ext_status
,
8134 psli
->sli_flag
, flag
);
8135 /* Unblock the async mailbox posting afterward */
8136 lpfc_sli4_async_mbox_unblock(phba
);
8141 /* Now, interrupt mode asynchrous mailbox command */
8142 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
8144 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8145 "(%d):2543 Mailbox command x%x (x%x/x%x) "
8146 "cannot issue Data: x%x x%x\n",
8147 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8148 mboxq
->u
.mb
.mbxCommand
,
8149 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8150 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8151 psli
->sli_flag
, flag
);
8152 goto out_not_finished
;
8155 /* Put the mailbox command to the driver internal FIFO */
8156 psli
->slistat
.mbox_busy
++;
8157 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8158 lpfc_mbox_put(phba
, mboxq
);
8159 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8160 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8161 "(%d):0354 Mbox cmd issue - Enqueue Data: "
8162 "x%x (x%x/x%x) x%x x%x x%x\n",
8163 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
8164 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
8165 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8166 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8167 phba
->pport
->port_state
,
8168 psli
->sli_flag
, MBX_NOWAIT
);
8169 /* Wake up worker thread to transport mailbox command from head */
8170 lpfc_worker_wake_up(phba
);
8175 return MBX_NOT_FINISHED
;
8179 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
8180 * @phba: Pointer to HBA context object.
8182 * This function is called by worker thread to send a mailbox command to
8183 * SLI4 HBA firmware.
8187 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
8189 struct lpfc_sli
*psli
= &phba
->sli
;
8190 LPFC_MBOXQ_t
*mboxq
;
8191 int rc
= MBX_SUCCESS
;
8192 unsigned long iflags
;
8193 struct lpfc_mqe
*mqe
;
8196 /* Check interrupt mode before post async mailbox command */
8197 if (unlikely(!phba
->sli4_hba
.intr_enable
))
8198 return MBX_NOT_FINISHED
;
8200 /* Check for mailbox command service token */
8201 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8202 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
8203 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8204 return MBX_NOT_FINISHED
;
8206 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8207 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8208 return MBX_NOT_FINISHED
;
8210 if (unlikely(phba
->sli
.mbox_active
)) {
8211 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8212 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8213 "0384 There is pending active mailbox cmd\n");
8214 return MBX_NOT_FINISHED
;
8216 /* Take the mailbox command service token */
8217 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
8219 /* Get the next mailbox command from head of queue */
8220 mboxq
= lpfc_mbox_get(phba
);
8222 /* If no more mailbox command waiting for post, we're done */
8224 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8225 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8228 phba
->sli
.mbox_active
= mboxq
;
8229 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8231 /* Check device readiness for posting mailbox command */
8232 rc
= lpfc_mbox_dev_check(phba
);
8234 /* Driver clean routine will clean up pending mailbox */
8235 goto out_not_finished
;
8237 /* Prepare the mbox command to be posted */
8238 mqe
= &mboxq
->u
.mqe
;
8239 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
8241 /* Start timer for the mbox_tmo and log some mailbox post messages */
8242 mod_timer(&psli
->mbox_tmo
, (jiffies
+
8243 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba
, mboxq
))));
8245 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
8246 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
8248 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
8249 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8250 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8251 phba
->pport
->port_state
, psli
->sli_flag
);
8253 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
8255 lpfc_debugfs_disc_trc(mboxq
->vport
,
8256 LPFC_DISC_TRC_MBOX_VPORT
,
8257 "MBOX Send vport: cmd:x%x mb:x%x x%x",
8258 mbx_cmnd
, mqe
->un
.mb_words
[0],
8259 mqe
->un
.mb_words
[1]);
8261 lpfc_debugfs_disc_trc(phba
->pport
,
8263 "MBOX Send: cmd:x%x mb:x%x x%x",
8264 mbx_cmnd
, mqe
->un
.mb_words
[0],
8265 mqe
->un
.mb_words
[1]);
8268 psli
->slistat
.mbox_cmd
++;
8270 /* Post the mailbox command to the port */
8271 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
8272 if (rc
!= MBX_SUCCESS
) {
8273 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
8274 "(%d):2533 Mailbox command x%x (x%x/x%x) "
8275 "cannot issue Data: x%x x%x\n",
8276 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
8277 mboxq
->u
.mb
.mbxCommand
,
8278 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
8279 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
8280 psli
->sli_flag
, MBX_NOWAIT
);
8281 goto out_not_finished
;
8287 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8288 if (phba
->sli
.mbox_active
) {
8289 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8290 __lpfc_mbox_cmpl_put(phba
, mboxq
);
8291 /* Release the token */
8292 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8293 phba
->sli
.mbox_active
= NULL
;
8295 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8297 return MBX_NOT_FINISHED
;
8301 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
8302 * @phba: Pointer to HBA context object.
8303 * @pmbox: Pointer to mailbox object.
8304 * @flag: Flag indicating how the mailbox need to be processed.
8306 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
8307 * the API jump table function pointer from the lpfc_hba struct.
8309 * Return codes the caller owns the mailbox command after the return of the
8313 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
8315 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
8319 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
8320 * @phba: The hba struct for which this call is being executed.
8321 * @dev_grp: The HBA PCI-Device group number.
8323 * This routine sets up the mbox interface API function jump table in @phba
8325 * Returns: 0 - success, -ENODEV - failure.
8328 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8332 case LPFC_PCI_DEV_LP
:
8333 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
8334 phba
->lpfc_sli_handle_slow_ring_event
=
8335 lpfc_sli_handle_slow_ring_event_s3
;
8336 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
8337 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
8338 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
8340 case LPFC_PCI_DEV_OC
:
8341 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
8342 phba
->lpfc_sli_handle_slow_ring_event
=
8343 lpfc_sli_handle_slow_ring_event_s4
;
8344 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
8345 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
8346 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
8349 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8350 "1420 Invalid HBA PCI-device group: 0x%x\n",
8359 * __lpfc_sli_ringtx_put - Add an iocb to the txq
8360 * @phba: Pointer to HBA context object.
8361 * @pring: Pointer to driver SLI ring object.
8362 * @piocb: Pointer to address of newly added command iocb.
8364 * This function is called with hbalock held to add a command
8365 * iocb to the txq when SLI layer cannot submit the command iocb
8369 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8370 struct lpfc_iocbq
*piocb
)
8372 lockdep_assert_held(&phba
->hbalock
);
8373 /* Insert the caller's iocb in the txq tail for later processing. */
8374 list_add_tail(&piocb
->list
, &pring
->txq
);
8378 * lpfc_sli_next_iocb - Get the next iocb in the txq
8379 * @phba: Pointer to HBA context object.
8380 * @pring: Pointer to driver SLI ring object.
8381 * @piocb: Pointer to address of newly added command iocb.
8383 * This function is called with hbalock held before a new
8384 * iocb is submitted to the firmware. This function checks
8385 * txq to flush the iocbs in txq to Firmware before
8386 * submitting new iocbs to the Firmware.
8387 * If there are iocbs in the txq which need to be submitted
8388 * to firmware, lpfc_sli_next_iocb returns the first element
8389 * of the txq after dequeuing it from txq.
8390 * If there is no iocb in the txq then the function will return
8391 * *piocb and *piocb is set to NULL. Caller needs to check
8392 * *piocb to find if there are more commands in the txq.
8394 static struct lpfc_iocbq
*
8395 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8396 struct lpfc_iocbq
**piocb
)
8398 struct lpfc_iocbq
* nextiocb
;
8400 lockdep_assert_held(&phba
->hbalock
);
8402 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
8412 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
8413 * @phba: Pointer to HBA context object.
8414 * @ring_number: SLI ring number to issue iocb on.
8415 * @piocb: Pointer to command iocb.
8416 * @flag: Flag indicating if this command can be put into txq.
8418 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
8419 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
8420 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
8421 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
8422 * this function allows only iocbs for posting buffers. This function finds
8423 * next available slot in the command ring and posts the command to the
8424 * available slot and writes the port attention register to request HBA start
8425 * processing new iocb. If there is no slot available in the ring and
8426 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
8427 * the function returns IOCB_BUSY.
8429 * This function is called with hbalock held. The function will return success
8430 * after it successfully submit the iocb to firmware or after adding to the
8434 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
8435 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8437 struct lpfc_iocbq
*nextiocb
;
8439 struct lpfc_sli_ring
*pring
= &phba
->sli
.sli3_ring
[ring_number
];
8441 lockdep_assert_held(&phba
->hbalock
);
8443 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
8444 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
8445 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
8446 lpfc_printf_log(phba
, KERN_ERR
,
8447 LOG_SLI
| LOG_VPORT
,
8448 "1807 IOCB x%x failed. No vport\n",
8449 piocb
->iocb
.ulpCommand
);
8455 /* If the PCI channel is in offline state, do not post iocbs. */
8456 if (unlikely(pci_channel_offline(phba
->pcidev
)))
8459 /* If HBA has a deferred error attention, fail the iocb. */
8460 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
8464 * We should never get an IOCB if we are in a < LINK_DOWN state
8466 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
8470 * Check to see if we are blocking IOCB processing because of a
8471 * outstanding event.
8473 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
8476 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
8478 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
8479 * can be issued if the link is not up.
8481 switch (piocb
->iocb
.ulpCommand
) {
8482 case CMD_GEN_REQUEST64_CR
:
8483 case CMD_GEN_REQUEST64_CX
:
8484 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
8485 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
8486 FC_RCTL_DD_UNSOL_CMD
) ||
8487 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
8488 MENLO_TRANSPORT_TYPE
))
8492 case CMD_QUE_RING_BUF_CN
:
8493 case CMD_QUE_RING_BUF64_CN
:
8495 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
8496 * completion, iocb_cmpl MUST be 0.
8498 if (piocb
->iocb_cmpl
)
8499 piocb
->iocb_cmpl
= NULL
;
8501 case CMD_CREATE_XRI_CR
:
8502 case CMD_CLOSE_XRI_CN
:
8503 case CMD_CLOSE_XRI_CX
:
8510 * For FCP commands, we must be in a state where we can process link
8513 } else if (unlikely(pring
->ringno
== LPFC_FCP_RING
&&
8514 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
8518 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
8519 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
8520 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
8523 lpfc_sli_update_ring(phba
, pring
);
8525 lpfc_sli_update_full_ring(phba
, pring
);
8528 return IOCB_SUCCESS
;
8533 pring
->stats
.iocb_cmd_delay
++;
8537 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8538 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
8539 return IOCB_SUCCESS
;
8546 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
8547 * @phba: Pointer to HBA context object.
8548 * @piocb: Pointer to command iocb.
8549 * @sglq: Pointer to the scatter gather queue object.
8551 * This routine converts the bpl or bde that is in the IOCB
8552 * to a sgl list for the sli4 hardware. The physical address
8553 * of the bpl/bde is converted back to a virtual address.
8554 * If the IOCB contains a BPL then the list of BDE's is
8555 * converted to sli4_sge's. If the IOCB contains a single
8556 * BDE then it is converted to a single sli_sge.
8557 * The IOCB is still in cpu endianess so the contents of
8558 * the bpl can be used without byte swapping.
8560 * Returns valid XRI = Success, NO_XRI = Failure.
8563 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
8564 struct lpfc_sglq
*sglq
)
8566 uint16_t xritag
= NO_XRI
;
8567 struct ulp_bde64
*bpl
= NULL
;
8568 struct ulp_bde64 bde
;
8569 struct sli4_sge
*sgl
= NULL
;
8570 struct lpfc_dmabuf
*dmabuf
;
8574 uint32_t offset
= 0; /* accumulated offset in the sg request list */
8575 int inbound
= 0; /* number of sg reply entries inbound from firmware */
8577 if (!piocbq
|| !sglq
)
8580 sgl
= (struct sli4_sge
*)sglq
->sgl
;
8581 icmd
= &piocbq
->iocb
;
8582 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
8583 return sglq
->sli4_xritag
;
8584 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8585 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
8586 sizeof(struct ulp_bde64
);
8587 /* The addrHigh and addrLow fields within the IOCB
8588 * have not been byteswapped yet so there is no
8589 * need to swap them back.
8591 if (piocbq
->context3
)
8592 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
8596 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
8600 for (i
= 0; i
< numBdes
; i
++) {
8601 /* Should already be byte swapped. */
8602 sgl
->addr_hi
= bpl
->addrHigh
;
8603 sgl
->addr_lo
= bpl
->addrLow
;
8605 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8606 if ((i
+1) == numBdes
)
8607 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8609 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
8610 /* swap the size field back to the cpu so we
8611 * can assign it to the sgl.
8613 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8614 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
8615 /* The offsets in the sgl need to be accumulated
8616 * separately for the request and reply lists.
8617 * The request is always first, the reply follows.
8619 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
8620 /* add up the reply sg entries */
8621 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
8623 /* first inbound? reset the offset */
8626 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
8627 bf_set(lpfc_sli4_sge_type
, sgl
,
8628 LPFC_SGE_TYPE_DATA
);
8629 offset
+= bde
.tus
.f
.bdeSize
;
8631 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8635 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
8636 /* The addrHigh and addrLow fields of the BDE have not
8637 * been byteswapped yet so they need to be swapped
8638 * before putting them in the sgl.
8641 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
8643 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
8644 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8645 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8646 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8648 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
8650 return sglq
->sli4_xritag
;
8654 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8655 * @phba: Pointer to HBA context object.
8656 * @piocb: Pointer to command iocb.
8657 * @wqe: Pointer to the work queue entry.
8659 * This routine converts the iocb command to its Work Queue Entry
8660 * equivalent. The wqe pointer should not have any fields set when
8661 * this routine is called because it will memcpy over them.
8662 * This routine does not set the CQ_ID or the WQEC bits in the
8665 * Returns: 0 = Success, IOCB_ERROR = Failure.
8668 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
8669 union lpfc_wqe
*wqe
)
8671 uint32_t xmit_len
= 0, total_len
= 0;
8675 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
8678 uint16_t abrt_iotag
;
8679 struct lpfc_iocbq
*abrtiocbq
;
8680 struct ulp_bde64
*bpl
= NULL
;
8681 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
8683 struct ulp_bde64 bde
;
8684 struct lpfc_nodelist
*ndlp
;
8688 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
8689 /* The fcp commands will set command type */
8690 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8691 command_type
= FCP_COMMAND
;
8692 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
8693 command_type
= ELS_COMMAND_FIP
;
8695 command_type
= ELS_COMMAND_NON_FIP
;
8697 if (phba
->fcp_embed_io
)
8698 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
8699 /* Some of the fields are in the right position already */
8700 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
8701 if (iocbq
->iocb
.ulpCommand
!= CMD_SEND_FRAME
) {
8702 /* The ct field has moved so reset */
8703 wqe
->generic
.wqe_com
.word7
= 0;
8704 wqe
->generic
.wqe_com
.word10
= 0;
8707 abort_tag
= (uint32_t) iocbq
->iotag
;
8708 xritag
= iocbq
->sli4_xritag
;
8709 /* words0-2 bpl convert bde */
8710 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8711 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8712 sizeof(struct ulp_bde64
);
8713 bpl
= (struct ulp_bde64
*)
8714 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
8718 /* Should already be byte swapped. */
8719 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
8720 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
8721 /* swap the size field back to the cpu so we
8722 * can assign it to the sgl.
8724 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8725 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
8727 for (i
= 0; i
< numBdes
; i
++) {
8728 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8729 total_len
+= bde
.tus
.f
.bdeSize
;
8732 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8734 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8735 cmnd
= iocbq
->iocb
.ulpCommand
;
8737 switch (iocbq
->iocb
.ulpCommand
) {
8738 case CMD_ELS_REQUEST64_CR
:
8739 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8740 ndlp
= iocbq
->context_un
.ndlp
;
8742 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8743 if (!iocbq
->iocb
.ulpLe
) {
8744 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8745 "2007 Only Limited Edition cmd Format"
8746 " supported 0x%x\n",
8747 iocbq
->iocb
.ulpCommand
);
8751 wqe
->els_req
.payload_len
= xmit_len
;
8752 /* Els_reguest64 has a TMO */
8753 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8754 iocbq
->iocb
.ulpTimeout
);
8755 /* Need a VF for word 4 set the vf bit*/
8756 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
8757 /* And a VFID for word 12 */
8758 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
8759 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8760 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8761 iocbq
->iocb
.ulpContext
);
8762 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
8763 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
8764 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8765 if (command_type
== ELS_COMMAND_FIP
)
8766 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
8767 >> LPFC_FIP_ELS_ID_SHIFT
);
8768 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8769 iocbq
->context2
)->virt
);
8770 if_type
= bf_get(lpfc_sli_intf_if_type
,
8771 &phba
->sli4_hba
.sli_intf
);
8772 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8773 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
8774 *pcmd
== ELS_CMD_SCR
||
8775 *pcmd
== ELS_CMD_FDISC
||
8776 *pcmd
== ELS_CMD_LOGO
||
8777 *pcmd
== ELS_CMD_PLOGI
)) {
8778 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8779 bf_set(els_req64_sid
, &wqe
->els_req
,
8780 iocbq
->vport
->fc_myDID
);
8781 if ((*pcmd
== ELS_CMD_FLOGI
) &&
8782 !(phba
->fc_topology
==
8783 LPFC_TOPOLOGY_LOOP
))
8784 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
8785 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8786 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8787 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8788 } else if (pcmd
&& iocbq
->context1
) {
8789 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
8790 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8791 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8794 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
8795 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8796 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
8797 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
8798 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8799 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
8800 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8801 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
8802 wqe
->els_req
.max_response_payload_len
= total_len
- xmit_len
;
8804 case CMD_XMIT_SEQUENCE64_CX
:
8805 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
8806 iocbq
->iocb
.un
.ulpWord
[3]);
8807 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
8808 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8809 /* The entire sequence is transmitted for this IOCB */
8810 xmit_len
= total_len
;
8811 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8812 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8813 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8814 case CMD_XMIT_SEQUENCE64_CR
:
8815 /* word3 iocb=io_tag32 wqe=reserved */
8816 wqe
->xmit_sequence
.rsvd3
= 0;
8817 /* word4 relative_offset memcpy */
8818 /* word5 r_ctl/df_ctl memcpy */
8819 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8820 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8821 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8822 LPFC_WQE_IOD_WRITE
);
8823 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8824 LPFC_WQE_LENLOC_WORD12
);
8825 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8826 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8827 command_type
= OTHER_COMMAND
;
8829 case CMD_XMIT_BCAST64_CN
:
8830 /* word3 iocb=iotag32 wqe=seq_payload_len */
8831 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8832 /* word4 iocb=rsvd wqe=rsvd */
8833 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8834 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8835 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8836 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8837 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8838 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8839 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8840 LPFC_WQE_LENLOC_WORD3
);
8841 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8843 case CMD_FCP_IWRITE64_CR
:
8844 command_type
= FCP_COMMAND_DATA_OUT
;
8845 /* word3 iocb=iotag wqe=payload_offset_len */
8846 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8847 bf_set(payload_offset_len
, &wqe
->fcp_iwrite
,
8848 xmit_len
+ sizeof(struct fcp_rsp
));
8849 bf_set(cmd_buff_len
, &wqe
->fcp_iwrite
,
8851 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8852 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8853 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8854 iocbq
->iocb
.ulpFCP2Rcvy
);
8855 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8856 /* Always open the exchange */
8857 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8858 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8859 LPFC_WQE_LENLOC_WORD4
);
8860 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8861 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8862 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8863 bf_set(wqe_oas
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8864 bf_set(wqe_ccpe
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8865 if (iocbq
->priority
) {
8866 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8867 (iocbq
->priority
<< 1));
8869 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8870 (phba
->cfg_XLanePriority
<< 1));
8873 /* Note, word 10 is already initialized to 0 */
8875 if (phba
->fcp_embed_io
) {
8876 struct lpfc_scsi_buf
*lpfc_cmd
;
8877 struct sli4_sge
*sgl
;
8878 union lpfc_wqe128
*wqe128
;
8879 struct fcp_cmnd
*fcp_cmnd
;
8882 /* 128 byte wqe support here */
8883 wqe128
= (union lpfc_wqe128
*)wqe
;
8885 lpfc_cmd
= iocbq
->context1
;
8886 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8887 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8889 /* Word 0-2 - FCP_CMND */
8890 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8891 BUFF_TYPE_BDE_IMMED
;
8892 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8893 wqe128
->generic
.bde
.addrHigh
= 0;
8894 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8896 bf_set(wqe_wqes
, &wqe128
->fcp_iwrite
.wqe_com
, 1);
8898 /* Word 22-29 FCP CMND Payload */
8899 ptr
= &wqe128
->words
[22];
8900 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8903 case CMD_FCP_IREAD64_CR
:
8904 /* word3 iocb=iotag wqe=payload_offset_len */
8905 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8906 bf_set(payload_offset_len
, &wqe
->fcp_iread
,
8907 xmit_len
+ sizeof(struct fcp_rsp
));
8908 bf_set(cmd_buff_len
, &wqe
->fcp_iread
,
8910 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8911 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8912 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8913 iocbq
->iocb
.ulpFCP2Rcvy
);
8914 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8915 /* Always open the exchange */
8916 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8917 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8918 LPFC_WQE_LENLOC_WORD4
);
8919 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8920 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8921 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8922 bf_set(wqe_oas
, &wqe
->fcp_iread
.wqe_com
, 1);
8923 bf_set(wqe_ccpe
, &wqe
->fcp_iread
.wqe_com
, 1);
8924 if (iocbq
->priority
) {
8925 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8926 (iocbq
->priority
<< 1));
8928 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8929 (phba
->cfg_XLanePriority
<< 1));
8932 /* Note, word 10 is already initialized to 0 */
8934 if (phba
->fcp_embed_io
) {
8935 struct lpfc_scsi_buf
*lpfc_cmd
;
8936 struct sli4_sge
*sgl
;
8937 union lpfc_wqe128
*wqe128
;
8938 struct fcp_cmnd
*fcp_cmnd
;
8941 /* 128 byte wqe support here */
8942 wqe128
= (union lpfc_wqe128
*)wqe
;
8944 lpfc_cmd
= iocbq
->context1
;
8945 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8946 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8948 /* Word 0-2 - FCP_CMND */
8949 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8950 BUFF_TYPE_BDE_IMMED
;
8951 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8952 wqe128
->generic
.bde
.addrHigh
= 0;
8953 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8955 bf_set(wqe_wqes
, &wqe128
->fcp_iread
.wqe_com
, 1);
8957 /* Word 22-29 FCP CMND Payload */
8958 ptr
= &wqe128
->words
[22];
8959 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8962 case CMD_FCP_ICMND64_CR
:
8963 /* word3 iocb=iotag wqe=payload_offset_len */
8964 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8965 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
8966 xmit_len
+ sizeof(struct fcp_rsp
));
8967 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
,
8969 /* word3 iocb=IO_TAG wqe=reserved */
8970 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8971 /* Always open the exchange */
8972 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8973 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8974 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8975 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8976 LPFC_WQE_LENLOC_NONE
);
8977 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
8978 iocbq
->iocb
.ulpFCP2Rcvy
);
8979 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8980 bf_set(wqe_oas
, &wqe
->fcp_icmd
.wqe_com
, 1);
8981 bf_set(wqe_ccpe
, &wqe
->fcp_icmd
.wqe_com
, 1);
8982 if (iocbq
->priority
) {
8983 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8984 (iocbq
->priority
<< 1));
8986 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8987 (phba
->cfg_XLanePriority
<< 1));
8990 /* Note, word 10 is already initialized to 0 */
8992 if (phba
->fcp_embed_io
) {
8993 struct lpfc_scsi_buf
*lpfc_cmd
;
8994 struct sli4_sge
*sgl
;
8995 union lpfc_wqe128
*wqe128
;
8996 struct fcp_cmnd
*fcp_cmnd
;
8999 /* 128 byte wqe support here */
9000 wqe128
= (union lpfc_wqe128
*)wqe
;
9002 lpfc_cmd
= iocbq
->context1
;
9003 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
9004 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
9006 /* Word 0-2 - FCP_CMND */
9007 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
9008 BUFF_TYPE_BDE_IMMED
;
9009 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
9010 wqe128
->generic
.bde
.addrHigh
= 0;
9011 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
9013 bf_set(wqe_wqes
, &wqe128
->fcp_icmd
.wqe_com
, 1);
9015 /* Word 22-29 FCP CMND Payload */
9016 ptr
= &wqe128
->words
[22];
9017 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
9020 case CMD_GEN_REQUEST64_CR
:
9021 /* For this command calculate the xmit length of the
9025 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
9026 sizeof(struct ulp_bde64
);
9027 for (i
= 0; i
< numBdes
; i
++) {
9028 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
9029 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
9031 xmit_len
+= bde
.tus
.f
.bdeSize
;
9033 /* word3 iocb=IO_TAG wqe=request_payload_len */
9034 wqe
->gen_req
.request_payload_len
= xmit_len
;
9035 /* word4 iocb=parameter wqe=relative_offset memcpy */
9036 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
9037 /* word6 context tag copied in memcpy */
9038 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
9039 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
9040 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9041 "2015 Invalid CT %x command 0x%x\n",
9042 ct
, iocbq
->iocb
.ulpCommand
);
9045 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
9046 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
9047 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
9048 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
9049 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
9050 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
9051 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
9052 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
9053 wqe
->gen_req
.max_response_payload_len
= total_len
- xmit_len
;
9054 command_type
= OTHER_COMMAND
;
9056 case CMD_XMIT_ELS_RSP64_CX
:
9057 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
9058 /* words0-2 BDE memcpy */
9059 /* word3 iocb=iotag32 wqe=response_payload_len */
9060 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
9062 wqe
->xmit_els_rsp
.word4
= 0;
9063 /* word5 iocb=rsvd wge=did */
9064 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
9065 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
9067 if_type
= bf_get(lpfc_sli_intf_if_type
,
9068 &phba
->sli4_hba
.sli_intf
);
9069 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
9070 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
9071 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
9072 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
9073 iocbq
->vport
->fc_myDID
);
9074 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
9076 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
9080 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
9081 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9082 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
9083 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
9084 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
9085 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
9086 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
9087 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
9088 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9089 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
9090 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9091 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
9092 LPFC_WQE_LENLOC_WORD3
);
9093 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
9094 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
9095 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
9096 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
9097 iocbq
->context2
)->virt
);
9098 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
9099 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
9100 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
9101 iocbq
->vport
->fc_myDID
);
9102 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
9103 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
9104 phba
->vpi_ids
[phba
->pport
->vpi
]);
9106 command_type
= OTHER_COMMAND
;
9108 case CMD_CLOSE_XRI_CN
:
9109 case CMD_ABORT_XRI_CN
:
9110 case CMD_ABORT_XRI_CX
:
9111 /* words 0-2 memcpy should be 0 rserved */
9112 /* port will send abts */
9113 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
9114 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
9115 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
9116 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
9120 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
9122 * The link is down, or the command was ELS_FIP
9123 * so the fw does not need to send abts
9126 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
9128 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
9129 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
9130 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
9131 wqe
->abort_cmd
.rsrvd5
= 0;
9132 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
9133 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
9134 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
9136 * The abort handler will send us CMD_ABORT_XRI_CN or
9137 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
9139 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
9140 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
9141 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
9142 LPFC_WQE_LENLOC_NONE
);
9143 cmnd
= CMD_ABORT_XRI_CX
;
9144 command_type
= OTHER_COMMAND
;
9147 case CMD_XMIT_BLS_RSP64_CX
:
9148 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
9149 /* As BLS ABTS RSP WQE is very different from other WQEs,
9150 * we re-construct this WQE here based on information in
9151 * iocbq from scratch.
9153 memset(wqe
, 0, sizeof(union lpfc_wqe
));
9154 /* OX_ID is invariable to who sent ABTS to CT exchange */
9155 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
9156 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
9157 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
9158 LPFC_ABTS_UNSOL_INT
) {
9159 /* ABTS sent by initiator to CT exchange, the
9160 * RX_ID field will be filled with the newly
9161 * allocated responder XRI.
9163 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
9164 iocbq
->sli4_xritag
);
9166 /* ABTS sent by responder to CT exchange, the
9167 * RX_ID field will be filled with the responder
9170 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
9171 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
9173 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
9174 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
9177 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
9179 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
9180 iocbq
->iocb
.ulpContext
);
9181 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
9182 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
9183 phba
->vpi_ids
[phba
->pport
->vpi
]);
9184 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
9185 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
9186 LPFC_WQE_LENLOC_NONE
);
9187 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
9188 command_type
= OTHER_COMMAND
;
9189 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
9190 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
9191 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
9192 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
9193 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
9194 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
9195 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
9199 case CMD_SEND_FRAME
:
9200 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
9201 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
9203 case CMD_XRI_ABORTED_CX
:
9204 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
9205 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
9206 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
9207 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
9208 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
9210 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9211 "2014 Invalid command 0x%x\n",
9212 iocbq
->iocb
.ulpCommand
);
9217 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
9218 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
9219 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
9220 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
9221 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
9222 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
9223 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
9224 LPFC_IO_DIF_INSERT
);
9225 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
9226 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
9227 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
9228 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
9229 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
9230 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
9231 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
9236 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
9237 * @phba: Pointer to HBA context object.
9238 * @ring_number: SLI ring number to issue iocb on.
9239 * @piocb: Pointer to command iocb.
9240 * @flag: Flag indicating if this command can be put into txq.
9242 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
9243 * an iocb command to an HBA with SLI-4 interface spec.
9245 * This function is called with hbalock held. The function will return success
9246 * after it successfully submit the iocb to firmware or after adding to the
9250 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
9251 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9253 struct lpfc_sglq
*sglq
;
9254 union lpfc_wqe
*wqe
;
9255 union lpfc_wqe128 wqe128
;
9256 struct lpfc_queue
*wq
;
9257 struct lpfc_sli_ring
*pring
;
9260 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
9261 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
9262 if (!phba
->cfg_fof
|| (!(piocb
->iocb_flag
& LPFC_IO_OAS
)))
9263 wq
= phba
->sli4_hba
.fcp_wq
[piocb
->hba_wqidx
];
9265 wq
= phba
->sli4_hba
.oas_wq
;
9267 wq
= phba
->sli4_hba
.els_wq
;
9270 /* Get corresponding ring */
9274 * The WQE can be either 64 or 128 bytes,
9275 * so allocate space on the stack assuming the largest.
9277 wqe
= (union lpfc_wqe
*)&wqe128
;
9279 lockdep_assert_held(&phba
->hbalock
);
9281 if (piocb
->sli4_xritag
== NO_XRI
) {
9282 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
9283 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
9286 if (!list_empty(&pring
->txq
)) {
9287 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
9288 __lpfc_sli_ringtx_put(phba
,
9290 return IOCB_SUCCESS
;
9295 sglq
= __lpfc_sli_get_els_sglq(phba
, piocb
);
9297 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
9298 __lpfc_sli_ringtx_put(phba
,
9301 return IOCB_SUCCESS
;
9307 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
)
9308 /* These IO's already have an XRI and a mapped sgl. */
9312 * This is a continuation of a commandi,(CX) so this
9313 * sglq is on the active list
9315 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
9321 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
9322 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
9323 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
9327 if (lpfc_sli4_iocb2wqe(phba
, piocb
, wqe
))
9330 if (lpfc_sli4_wq_put(wq
, wqe
))
9332 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
9338 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
9340 * This routine wraps the actual lockless version for issusing IOCB function
9341 * pointer from the lpfc_hba struct.
9344 * IOCB_ERROR - Error
9345 * IOCB_SUCCESS - Success
9349 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9350 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9352 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9356 * lpfc_sli_api_table_setup - Set up sli api function jump table
9357 * @phba: The hba struct for which this call is being executed.
9358 * @dev_grp: The HBA PCI-Device group number.
9360 * This routine sets up the SLI interface API function jump table in @phba
9362 * Returns: 0 - success, -ENODEV - failure.
9365 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
9369 case LPFC_PCI_DEV_LP
:
9370 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
9371 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
9373 case LPFC_PCI_DEV_OC
:
9374 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
9375 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
9378 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9379 "1419 Invalid HBA PCI-device group: 0x%x\n",
9384 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
9389 * lpfc_sli4_calc_ring - Calculates which ring to use
9390 * @phba: Pointer to HBA context object.
9391 * @piocb: Pointer to command iocb.
9393 * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
9394 * hba_wqidx, thus we need to calculate the corresponding ring.
9395 * Since ABORTS must go on the same WQ of the command they are
9396 * aborting, we use command's hba_wqidx.
9398 struct lpfc_sli_ring
*
9399 lpfc_sli4_calc_ring(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocb
)
9401 if (piocb
->iocb_flag
& (LPFC_IO_FCP
| LPFC_USE_FCPWQIDX
)) {
9402 if (!(phba
->cfg_fof
) ||
9403 (!(piocb
->iocb_flag
& LPFC_IO_FOF
))) {
9404 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
9407 * for abort iocb hba_wqidx should already
9408 * be setup based on what work queue we used.
9410 if (!(piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
9412 lpfc_sli4_scmd_to_wqidx_distr(phba
,
9414 piocb
->hba_wqidx
= piocb
->hba_wqidx
%
9415 phba
->cfg_fcp_io_channel
;
9417 return phba
->sli4_hba
.fcp_wq
[piocb
->hba_wqidx
]->pring
;
9419 if (unlikely(!phba
->sli4_hba
.oas_wq
))
9421 piocb
->hba_wqidx
= 0;
9422 return phba
->sli4_hba
.oas_wq
->pring
;
9425 if (unlikely(!phba
->sli4_hba
.els_wq
))
9427 piocb
->hba_wqidx
= 0;
9428 return phba
->sli4_hba
.els_wq
->pring
;
9433 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
9434 * @phba: Pointer to HBA context object.
9435 * @pring: Pointer to driver SLI ring object.
9436 * @piocb: Pointer to command iocb.
9437 * @flag: Flag indicating if this command can be put into txq.
9439 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
9440 * function. This function gets the hbalock and calls
9441 * __lpfc_sli_issue_iocb function and will return the error returned
9442 * by __lpfc_sli_issue_iocb function. This wrapper is used by
9443 * functions which do not hold hbalock.
9446 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9447 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9449 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
9450 struct lpfc_sli_ring
*pring
;
9451 struct lpfc_queue
*fpeq
;
9452 struct lpfc_eqe
*eqe
;
9453 unsigned long iflags
;
9456 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9457 pring
= lpfc_sli4_calc_ring(phba
, piocb
);
9458 if (unlikely(pring
== NULL
))
9461 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9462 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9463 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9465 if (lpfc_fcp_look_ahead
&& (piocb
->iocb_flag
& LPFC_IO_FCP
)) {
9466 idx
= piocb
->hba_wqidx
;
9467 hba_eq_hdl
= &phba
->sli4_hba
.hba_eq_hdl
[idx
];
9469 if (atomic_dec_and_test(&hba_eq_hdl
->hba_eq_in_use
)) {
9471 /* Get associated EQ with this index */
9472 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
9474 /* Turn off interrupts from this EQ */
9475 lpfc_sli4_eq_clr_intr(fpeq
);
9478 * Process all the events on FCP EQ
9480 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9481 lpfc_sli4_hba_handle_eqe(phba
,
9483 fpeq
->EQ_processed
++;
9486 /* Always clear and re-arm the EQ */
9487 lpfc_sli4_eq_release(fpeq
,
9490 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
9493 /* For now, SLI2/3 will still use hbalock */
9494 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9495 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9496 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9502 * lpfc_extra_ring_setup - Extra ring setup function
9503 * @phba: Pointer to HBA context object.
9505 * This function is called while driver attaches with the
9506 * HBA to setup the extra ring. The extra ring is used
9507 * only when driver needs to support target mode functionality
9508 * or IP over FC functionalities.
9510 * This function is called with no lock held. SLI3 only.
9513 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
9515 struct lpfc_sli
*psli
;
9516 struct lpfc_sli_ring
*pring
;
9520 /* Adjust cmd/rsp ring iocb entries more evenly */
9522 /* Take some away from the FCP ring */
9523 pring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
9524 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9525 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9526 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9527 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9529 /* and give them to the extra ring */
9530 pring
= &psli
->sli3_ring
[LPFC_EXTRA_RING
];
9532 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9533 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9534 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9535 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9537 /* Setup default profile for this ring */
9538 pring
->iotag_max
= 4096;
9539 pring
->num_mask
= 1;
9540 pring
->prt
[0].profile
= 0; /* Mask 0 */
9541 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
9542 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
9543 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
9547 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
9548 * @phba: Pointer to HBA context object.
9549 * @iocbq: Pointer to iocb object.
9551 * The async_event handler calls this routine when it receives
9552 * an ASYNC_STATUS_CN event from the port. The port generates
9553 * this event when an Abort Sequence request to an rport fails
9554 * twice in succession. The abort could be originated by the
9555 * driver or by the port. The ABTS could have been for an ELS
9556 * or FCP IO. The port only generates this event when an ABTS
9557 * fails to complete after one retry.
9560 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
9561 struct lpfc_iocbq
*iocbq
)
9563 struct lpfc_nodelist
*ndlp
= NULL
;
9564 uint16_t rpi
= 0, vpi
= 0;
9565 struct lpfc_vport
*vport
= NULL
;
9567 /* The rpi in the ulpContext is vport-sensitive. */
9568 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
9569 rpi
= iocbq
->iocb
.ulpContext
;
9571 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9572 "3092 Port generated ABTS async event "
9573 "on vpi %d rpi %d status 0x%x\n",
9574 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
9576 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
9579 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
9580 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
9583 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
9584 lpfc_sli_abts_recover_port(vport
, ndlp
);
9588 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9589 "3095 Event Context not found, no "
9590 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
9591 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
9595 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
9596 * @phba: pointer to HBA context object.
9597 * @ndlp: nodelist pointer for the impacted rport.
9598 * @axri: pointer to the wcqe containing the failed exchange.
9600 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
9601 * port. The port generates this event when an abort exchange request to an
9602 * rport fails twice in succession with no reply. The abort could be originated
9603 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
9606 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
9607 struct lpfc_nodelist
*ndlp
,
9608 struct sli4_wcqe_xri_aborted
*axri
)
9610 struct lpfc_vport
*vport
;
9611 uint32_t ext_status
= 0;
9613 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
9614 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9615 "3115 Node Context not found, driver "
9616 "ignoring abts err event\n");
9620 vport
= ndlp
->vport
;
9621 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9622 "3116 Port generated FCP XRI ABORT event on "
9623 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
9624 ndlp
->vport
->vpi
, phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
],
9625 bf_get(lpfc_wcqe_xa_xri
, axri
),
9626 bf_get(lpfc_wcqe_xa_status
, axri
),
9630 * Catch the ABTS protocol failure case. Older OCe FW releases returned
9631 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
9632 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
9634 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
9635 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
9636 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
9637 lpfc_sli_abts_recover_port(vport
, ndlp
);
9641 * lpfc_sli_async_event_handler - ASYNC iocb handler function
9642 * @phba: Pointer to HBA context object.
9643 * @pring: Pointer to driver SLI ring object.
9644 * @iocbq: Pointer to iocb object.
9646 * This function is called by the slow ring event handler
9647 * function when there is an ASYNC event iocb in the ring.
9648 * This function is called with no lock held.
9649 * Currently this function handles only temperature related
9650 * ASYNC events. The function decodes the temperature sensor
9651 * event message and posts events for the management applications.
9654 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
9655 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
9659 struct temp_event temp_event_data
;
9660 struct Scsi_Host
*shost
;
9663 icmd
= &iocbq
->iocb
;
9664 evt_code
= icmd
->un
.asyncstat
.evt_code
;
9667 case ASYNC_TEMP_WARN
:
9668 case ASYNC_TEMP_SAFE
:
9669 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
9670 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
9671 if (evt_code
== ASYNC_TEMP_WARN
) {
9672 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
9673 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9674 "0347 Adapter is very hot, please take "
9675 "corrective action. temperature : %d Celsius\n",
9676 (uint32_t) icmd
->ulpContext
);
9678 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
9679 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9680 "0340 Adapter temperature is OK now. "
9681 "temperature : %d Celsius\n",
9682 (uint32_t) icmd
->ulpContext
);
9685 /* Send temperature change event to applications */
9686 shost
= lpfc_shost_from_vport(phba
->pport
);
9687 fc_host_post_vendor_event(shost
, fc_get_event_number(),
9688 sizeof(temp_event_data
), (char *) &temp_event_data
,
9691 case ASYNC_STATUS_CN
:
9692 lpfc_sli_abts_err_handler(phba
, iocbq
);
9695 iocb_w
= (uint32_t *) icmd
;
9696 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9697 "0346 Ring %d handler: unexpected ASYNC_STATUS"
9699 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9700 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9701 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9702 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
9703 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
9704 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
9705 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
9706 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
9707 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
9715 * lpfc_sli4_setup - SLI ring setup function
9716 * @phba: Pointer to HBA context object.
9718 * lpfc_sli_setup sets up rings of the SLI interface with
9719 * number of iocbs per ring and iotags. This function is
9720 * called while driver attach to the HBA and before the
9721 * interrupts are enabled. So there is no need for locking.
9723 * This function always returns 0.
9726 lpfc_sli4_setup(struct lpfc_hba
*phba
)
9728 struct lpfc_sli_ring
*pring
;
9730 pring
= phba
->sli4_hba
.els_wq
->pring
;
9731 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9732 pring
->prt
[0].profile
= 0; /* Mask 0 */
9733 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9734 pring
->prt
[0].type
= FC_TYPE_ELS
;
9735 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9736 lpfc_els_unsol_event
;
9737 pring
->prt
[1].profile
= 0; /* Mask 1 */
9738 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9739 pring
->prt
[1].type
= FC_TYPE_ELS
;
9740 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9741 lpfc_els_unsol_event
;
9742 pring
->prt
[2].profile
= 0; /* Mask 2 */
9743 /* NameServer Inquiry */
9744 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9746 pring
->prt
[2].type
= FC_TYPE_CT
;
9747 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9748 lpfc_ct_unsol_event
;
9749 pring
->prt
[3].profile
= 0; /* Mask 3 */
9750 /* NameServer response */
9751 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9753 pring
->prt
[3].type
= FC_TYPE_CT
;
9754 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9755 lpfc_ct_unsol_event
;
9760 * lpfc_sli_setup - SLI ring setup function
9761 * @phba: Pointer to HBA context object.
9763 * lpfc_sli_setup sets up rings of the SLI interface with
9764 * number of iocbs per ring and iotags. This function is
9765 * called while driver attach to the HBA and before the
9766 * interrupts are enabled. So there is no need for locking.
9768 * This function always returns 0. SLI3 only.
9771 lpfc_sli_setup(struct lpfc_hba
*phba
)
9773 int i
, totiocbsize
= 0;
9774 struct lpfc_sli
*psli
= &phba
->sli
;
9775 struct lpfc_sli_ring
*pring
;
9777 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
9780 psli
->iocbq_lookup
= NULL
;
9781 psli
->iocbq_lookup_len
= 0;
9782 psli
->last_iotag
= 0;
9784 for (i
= 0; i
< psli
->num_rings
; i
++) {
9785 pring
= &psli
->sli3_ring
[i
];
9787 case LPFC_FCP_RING
: /* ring 0 - FCP */
9788 /* numCiocb and numRiocb are used in config_port */
9789 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
9790 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
9791 pring
->sli
.sli3
.numCiocb
+=
9792 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9793 pring
->sli
.sli3
.numRiocb
+=
9794 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9795 pring
->sli
.sli3
.numCiocb
+=
9796 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9797 pring
->sli
.sli3
.numRiocb
+=
9798 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9799 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9800 SLI3_IOCB_CMD_SIZE
:
9802 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9803 SLI3_IOCB_RSP_SIZE
:
9805 pring
->iotag_ctr
= 0;
9807 (phba
->cfg_hba_queue_depth
* 2);
9808 pring
->fast_iotag
= pring
->iotag_max
;
9809 pring
->num_mask
= 0;
9811 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
9812 /* numCiocb and numRiocb are used in config_port */
9813 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
9814 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
9815 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9816 SLI3_IOCB_CMD_SIZE
:
9818 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9819 SLI3_IOCB_RSP_SIZE
:
9821 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
9822 pring
->num_mask
= 0;
9824 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
9825 /* numCiocb and numRiocb are used in config_port */
9826 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
9827 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
9828 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9829 SLI3_IOCB_CMD_SIZE
:
9831 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9832 SLI3_IOCB_RSP_SIZE
:
9834 pring
->fast_iotag
= 0;
9835 pring
->iotag_ctr
= 0;
9836 pring
->iotag_max
= 4096;
9837 pring
->lpfc_sli_rcv_async_status
=
9838 lpfc_sli_async_event_handler
;
9839 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9840 pring
->prt
[0].profile
= 0; /* Mask 0 */
9841 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9842 pring
->prt
[0].type
= FC_TYPE_ELS
;
9843 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9844 lpfc_els_unsol_event
;
9845 pring
->prt
[1].profile
= 0; /* Mask 1 */
9846 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9847 pring
->prt
[1].type
= FC_TYPE_ELS
;
9848 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9849 lpfc_els_unsol_event
;
9850 pring
->prt
[2].profile
= 0; /* Mask 2 */
9851 /* NameServer Inquiry */
9852 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9854 pring
->prt
[2].type
= FC_TYPE_CT
;
9855 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9856 lpfc_ct_unsol_event
;
9857 pring
->prt
[3].profile
= 0; /* Mask 3 */
9858 /* NameServer response */
9859 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9861 pring
->prt
[3].type
= FC_TYPE_CT
;
9862 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9863 lpfc_ct_unsol_event
;
9866 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
9867 pring
->sli
.sli3
.sizeCiocb
) +
9868 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
9870 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
9871 /* Too many cmd / rsp ring entries in SLI2 SLIM */
9872 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
9873 "SLI2 SLIM Data: x%x x%lx\n",
9874 phba
->brd_no
, totiocbsize
,
9875 (unsigned long) MAX_SLIM_IOCB_SIZE
);
9877 if (phba
->cfg_multi_ring_support
== 2)
9878 lpfc_extra_ring_setup(phba
);
9884 * lpfc_sli4_queue_init - Queue initialization function
9885 * @phba: Pointer to HBA context object.
9887 * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
9888 * ring. This function also initializes ring indices of each ring.
9889 * This function is called during the initialization of the SLI
9890 * interface of an HBA.
9891 * This function is called with no lock held and always returns
9895 lpfc_sli4_queue_init(struct lpfc_hba
*phba
)
9897 struct lpfc_sli
*psli
;
9898 struct lpfc_sli_ring
*pring
;
9902 spin_lock_irq(&phba
->hbalock
);
9903 INIT_LIST_HEAD(&psli
->mboxq
);
9904 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9905 /* Initialize list headers for txq and txcmplq as double linked lists */
9906 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
9907 pring
= phba
->sli4_hba
.fcp_wq
[i
]->pring
;
9909 pring
->ringno
= LPFC_FCP_RING
;
9910 INIT_LIST_HEAD(&pring
->txq
);
9911 INIT_LIST_HEAD(&pring
->txcmplq
);
9912 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9913 spin_lock_init(&pring
->ring_lock
);
9915 for (i
= 0; i
< phba
->cfg_nvme_io_channel
; i
++) {
9916 pring
= phba
->sli4_hba
.nvme_wq
[i
]->pring
;
9918 pring
->ringno
= LPFC_FCP_RING
;
9919 INIT_LIST_HEAD(&pring
->txq
);
9920 INIT_LIST_HEAD(&pring
->txcmplq
);
9921 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9922 spin_lock_init(&pring
->ring_lock
);
9924 pring
= phba
->sli4_hba
.els_wq
->pring
;
9926 pring
->ringno
= LPFC_ELS_RING
;
9927 INIT_LIST_HEAD(&pring
->txq
);
9928 INIT_LIST_HEAD(&pring
->txcmplq
);
9929 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9930 spin_lock_init(&pring
->ring_lock
);
9932 if (phba
->cfg_nvme_io_channel
) {
9933 pring
= phba
->sli4_hba
.nvmels_wq
->pring
;
9935 pring
->ringno
= LPFC_ELS_RING
;
9936 INIT_LIST_HEAD(&pring
->txq
);
9937 INIT_LIST_HEAD(&pring
->txcmplq
);
9938 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9939 spin_lock_init(&pring
->ring_lock
);
9942 if (phba
->cfg_fof
) {
9943 pring
= phba
->sli4_hba
.oas_wq
->pring
;
9945 pring
->ringno
= LPFC_FCP_RING
;
9946 INIT_LIST_HEAD(&pring
->txq
);
9947 INIT_LIST_HEAD(&pring
->txcmplq
);
9948 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9949 spin_lock_init(&pring
->ring_lock
);
9952 spin_unlock_irq(&phba
->hbalock
);
9956 * lpfc_sli_queue_init - Queue initialization function
9957 * @phba: Pointer to HBA context object.
9959 * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
9960 * ring. This function also initializes ring indices of each ring.
9961 * This function is called during the initialization of the SLI
9962 * interface of an HBA.
9963 * This function is called with no lock held and always returns
9967 lpfc_sli_queue_init(struct lpfc_hba
*phba
)
9969 struct lpfc_sli
*psli
;
9970 struct lpfc_sli_ring
*pring
;
9974 spin_lock_irq(&phba
->hbalock
);
9975 INIT_LIST_HEAD(&psli
->mboxq
);
9976 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9977 /* Initialize list headers for txq and txcmplq as double linked lists */
9978 for (i
= 0; i
< psli
->num_rings
; i
++) {
9979 pring
= &psli
->sli3_ring
[i
];
9981 pring
->sli
.sli3
.next_cmdidx
= 0;
9982 pring
->sli
.sli3
.local_getidx
= 0;
9983 pring
->sli
.sli3
.cmdidx
= 0;
9984 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9985 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
9986 INIT_LIST_HEAD(&pring
->postbufq
);
9988 INIT_LIST_HEAD(&pring
->txq
);
9989 INIT_LIST_HEAD(&pring
->txcmplq
);
9990 spin_lock_init(&pring
->ring_lock
);
9992 spin_unlock_irq(&phba
->hbalock
);
9996 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9997 * @phba: Pointer to HBA context object.
9999 * This routine flushes the mailbox command subsystem. It will unconditionally
10000 * flush all the mailbox commands in the three possible stages in the mailbox
10001 * command sub-system: pending mailbox command queue; the outstanding mailbox
10002 * command; and completed mailbox command queue. It is caller's responsibility
10003 * to make sure that the driver is in the proper state to flush the mailbox
10004 * command sub-system. Namely, the posting of mailbox commands into the
10005 * pending mailbox command queue from the various clients must be stopped;
10006 * either the HBA is in a state that it will never works on the outstanding
10007 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
10008 * mailbox command has been completed.
10011 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
10013 LIST_HEAD(completions
);
10014 struct lpfc_sli
*psli
= &phba
->sli
;
10016 unsigned long iflag
;
10018 /* Flush all the mailbox commands in the mbox system */
10019 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10020 /* The pending mailbox command queue */
10021 list_splice_init(&phba
->sli
.mboxq
, &completions
);
10022 /* The outstanding active mailbox command */
10023 if (psli
->mbox_active
) {
10024 list_add_tail(&psli
->mbox_active
->list
, &completions
);
10025 psli
->mbox_active
= NULL
;
10026 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
10028 /* The completed mailbox command queue */
10029 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
10030 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10032 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
10033 while (!list_empty(&completions
)) {
10034 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
10035 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
10036 if (pmb
->mbox_cmpl
)
10037 pmb
->mbox_cmpl(phba
, pmb
);
10042 * lpfc_sli_host_down - Vport cleanup function
10043 * @vport: Pointer to virtual port object.
10045 * lpfc_sli_host_down is called to clean up the resources
10046 * associated with a vport before destroying virtual
10047 * port data structures.
10048 * This function does following operations:
10049 * - Free discovery resources associated with this virtual
10051 * - Free iocbs associated with this virtual port in
10053 * - Send abort for all iocb commands associated with this
10054 * vport in txcmplq.
10056 * This function is called with no lock held and always returns 1.
10059 lpfc_sli_host_down(struct lpfc_vport
*vport
)
10061 LIST_HEAD(completions
);
10062 struct lpfc_hba
*phba
= vport
->phba
;
10063 struct lpfc_sli
*psli
= &phba
->sli
;
10064 struct lpfc_queue
*qp
= NULL
;
10065 struct lpfc_sli_ring
*pring
;
10066 struct lpfc_iocbq
*iocb
, *next_iocb
;
10068 unsigned long flags
= 0;
10069 uint16_t prev_pring_flag
;
10071 lpfc_cleanup_discovery_resources(vport
);
10073 spin_lock_irqsave(&phba
->hbalock
, flags
);
10076 * Error everything on the txq since these iocbs
10077 * have not been given to the FW yet.
10078 * Also issue ABTS for everything on the txcmplq
10080 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10081 for (i
= 0; i
< psli
->num_rings
; i
++) {
10082 pring
= &psli
->sli3_ring
[i
];
10083 prev_pring_flag
= pring
->flag
;
10084 /* Only slow rings */
10085 if (pring
->ringno
== LPFC_ELS_RING
) {
10086 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10087 /* Set the lpfc data pending flag */
10088 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10090 list_for_each_entry_safe(iocb
, next_iocb
,
10091 &pring
->txq
, list
) {
10092 if (iocb
->vport
!= vport
)
10094 list_move_tail(&iocb
->list
, &completions
);
10096 list_for_each_entry_safe(iocb
, next_iocb
,
10097 &pring
->txcmplq
, list
) {
10098 if (iocb
->vport
!= vport
)
10100 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
10102 pring
->flag
= prev_pring_flag
;
10105 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10109 if (pring
== phba
->sli4_hba
.els_wq
->pring
) {
10110 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10111 /* Set the lpfc data pending flag */
10112 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10114 prev_pring_flag
= pring
->flag
;
10115 spin_lock_irq(&pring
->ring_lock
);
10116 list_for_each_entry_safe(iocb
, next_iocb
,
10117 &pring
->txq
, list
) {
10118 if (iocb
->vport
!= vport
)
10120 list_move_tail(&iocb
->list
, &completions
);
10122 spin_unlock_irq(&pring
->ring_lock
);
10123 list_for_each_entry_safe(iocb
, next_iocb
,
10124 &pring
->txcmplq
, list
) {
10125 if (iocb
->vport
!= vport
)
10127 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
10129 pring
->flag
= prev_pring_flag
;
10132 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10134 /* Cancel all the IOCBs from the completions list */
10135 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
10141 * lpfc_sli_hba_down - Resource cleanup function for the HBA
10142 * @phba: Pointer to HBA context object.
10144 * This function cleans up all iocb, buffers, mailbox commands
10145 * while shutting down the HBA. This function is called with no
10146 * lock held and always returns 1.
10147 * This function does the following to cleanup driver resources:
10148 * - Free discovery resources for each virtual port
10149 * - Cleanup any pending fabric iocbs
10150 * - Iterate through the iocb txq and free each entry
10152 * - Free up any buffer posted to the HBA
10153 * - Free mailbox commands in the mailbox queue.
10156 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
10158 LIST_HEAD(completions
);
10159 struct lpfc_sli
*psli
= &phba
->sli
;
10160 struct lpfc_queue
*qp
= NULL
;
10161 struct lpfc_sli_ring
*pring
;
10162 struct lpfc_dmabuf
*buf_ptr
;
10163 unsigned long flags
= 0;
10166 /* Shutdown the mailbox command sub-system */
10167 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
10169 lpfc_hba_down_prep(phba
);
10171 lpfc_fabric_abort_hba(phba
);
10173 spin_lock_irqsave(&phba
->hbalock
, flags
);
10176 * Error everything on the txq since these iocbs
10177 * have not been given to the FW yet.
10179 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10180 for (i
= 0; i
< psli
->num_rings
; i
++) {
10181 pring
= &psli
->sli3_ring
[i
];
10182 /* Only slow rings */
10183 if (pring
->ringno
== LPFC_ELS_RING
) {
10184 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10185 /* Set the lpfc data pending flag */
10186 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10188 list_splice_init(&pring
->txq
, &completions
);
10191 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10195 spin_lock_irq(&pring
->ring_lock
);
10196 list_splice_init(&pring
->txq
, &completions
);
10197 spin_unlock_irq(&pring
->ring_lock
);
10198 if (pring
== phba
->sli4_hba
.els_wq
->pring
) {
10199 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
10200 /* Set the lpfc data pending flag */
10201 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
10205 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10207 /* Cancel all the IOCBs from the completions list */
10208 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
10211 spin_lock_irqsave(&phba
->hbalock
, flags
);
10212 list_splice_init(&phba
->elsbuf
, &completions
);
10213 phba
->elsbuf_cnt
= 0;
10214 phba
->elsbuf_prev_cnt
= 0;
10215 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
10217 while (!list_empty(&completions
)) {
10218 list_remove_head(&completions
, buf_ptr
,
10219 struct lpfc_dmabuf
, list
);
10220 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
10224 /* Return any active mbox cmds */
10225 del_timer_sync(&psli
->mbox_tmo
);
10227 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
10228 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
10229 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
10235 * lpfc_sli_pcimem_bcopy - SLI memory copy function
10236 * @srcp: Source memory pointer.
10237 * @destp: Destination memory pointer.
10238 * @cnt: Number of words required to be copied.
10240 * This function is used for copying data between driver memory
10241 * and the SLI memory. This function also changes the endianness
10242 * of each word if native endianness is different from SLI
10243 * endianness. This function can be called with or without
10247 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
10249 uint32_t *src
= srcp
;
10250 uint32_t *dest
= destp
;
10254 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
10256 ldata
= le32_to_cpu(ldata
);
10265 * lpfc_sli_bemem_bcopy - SLI memory copy function
10266 * @srcp: Source memory pointer.
10267 * @destp: Destination memory pointer.
10268 * @cnt: Number of words required to be copied.
10270 * This function is used for copying data between a data structure
10271 * with big endian representation to local endianness.
10272 * This function can be called with or without lock.
10275 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
10277 uint32_t *src
= srcp
;
10278 uint32_t *dest
= destp
;
10282 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
10284 ldata
= be32_to_cpu(ldata
);
10292 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
10293 * @phba: Pointer to HBA context object.
10294 * @pring: Pointer to driver SLI ring object.
10295 * @mp: Pointer to driver buffer object.
10297 * This function is called with no lock held.
10298 * It always return zero after adding the buffer to the postbufq
10302 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10303 struct lpfc_dmabuf
*mp
)
10305 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
10307 spin_lock_irq(&phba
->hbalock
);
10308 list_add_tail(&mp
->list
, &pring
->postbufq
);
10309 pring
->postbufq_cnt
++;
10310 spin_unlock_irq(&phba
->hbalock
);
10315 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
10316 * @phba: Pointer to HBA context object.
10318 * When HBQ is enabled, buffers are searched based on tags. This function
10319 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
10320 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
10321 * does not conflict with tags of buffer posted for unsolicited events.
10322 * The function returns the allocated tag. The function is called with
10326 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
10328 spin_lock_irq(&phba
->hbalock
);
10329 phba
->buffer_tag_count
++;
10331 * Always set the QUE_BUFTAG_BIT to distiguish between
10332 * a tag assigned by HBQ.
10334 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
10335 spin_unlock_irq(&phba
->hbalock
);
10336 return phba
->buffer_tag_count
;
10340 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
10341 * @phba: Pointer to HBA context object.
10342 * @pring: Pointer to driver SLI ring object.
10343 * @tag: Buffer tag.
10345 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
10346 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
10347 * iocb is posted to the response ring with the tag of the buffer.
10348 * This function searches the pring->postbufq list using the tag
10349 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
10350 * iocb. If the buffer is found then lpfc_dmabuf object of the
10351 * buffer is returned to the caller else NULL is returned.
10352 * This function is called with no lock held.
10354 struct lpfc_dmabuf
*
10355 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10358 struct lpfc_dmabuf
*mp
, *next_mp
;
10359 struct list_head
*slp
= &pring
->postbufq
;
10361 /* Search postbufq, from the beginning, looking for a match on tag */
10362 spin_lock_irq(&phba
->hbalock
);
10363 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
10364 if (mp
->buffer_tag
== tag
) {
10365 list_del_init(&mp
->list
);
10366 pring
->postbufq_cnt
--;
10367 spin_unlock_irq(&phba
->hbalock
);
10372 spin_unlock_irq(&phba
->hbalock
);
10373 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10374 "0402 Cannot find virtual addr for buffer tag on "
10375 "ring %d Data x%lx x%p x%p x%x\n",
10376 pring
->ringno
, (unsigned long) tag
,
10377 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
10383 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
10384 * @phba: Pointer to HBA context object.
10385 * @pring: Pointer to driver SLI ring object.
10386 * @phys: DMA address of the buffer.
10388 * This function searches the buffer list using the dma_address
10389 * of unsolicited event to find the driver's lpfc_dmabuf object
10390 * corresponding to the dma_address. The function returns the
10391 * lpfc_dmabuf object if a buffer is found else it returns NULL.
10392 * This function is called by the ct and els unsolicited event
10393 * handlers to get the buffer associated with the unsolicited
10396 * This function is called with no lock held.
10398 struct lpfc_dmabuf
*
10399 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10402 struct lpfc_dmabuf
*mp
, *next_mp
;
10403 struct list_head
*slp
= &pring
->postbufq
;
10405 /* Search postbufq, from the beginning, looking for a match on phys */
10406 spin_lock_irq(&phba
->hbalock
);
10407 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
10408 if (mp
->phys
== phys
) {
10409 list_del_init(&mp
->list
);
10410 pring
->postbufq_cnt
--;
10411 spin_unlock_irq(&phba
->hbalock
);
10416 spin_unlock_irq(&phba
->hbalock
);
10417 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10418 "0410 Cannot find virtual addr for mapped buf on "
10419 "ring %d Data x%llx x%p x%p x%x\n",
10420 pring
->ringno
, (unsigned long long)phys
,
10421 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
10426 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
10427 * @phba: Pointer to HBA context object.
10428 * @cmdiocb: Pointer to driver command iocb object.
10429 * @rspiocb: Pointer to driver response iocb object.
10431 * This function is the completion handler for the abort iocbs for
10432 * ELS commands. This function is called from the ELS ring event
10433 * handler with no lock held. This function frees memory resources
10434 * associated with the abort iocb.
10437 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10438 struct lpfc_iocbq
*rspiocb
)
10440 IOCB_t
*irsp
= &rspiocb
->iocb
;
10441 uint16_t abort_iotag
, abort_context
;
10442 struct lpfc_iocbq
*abort_iocb
= NULL
;
10444 if (irsp
->ulpStatus
) {
10447 * Assume that the port already completed and returned, or
10448 * will return the iocb. Just Log the message.
10450 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
10451 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
10453 spin_lock_irq(&phba
->hbalock
);
10454 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
10455 if (abort_iotag
!= 0 &&
10456 abort_iotag
<= phba
->sli
.last_iotag
)
10458 phba
->sli
.iocbq_lookup
[abort_iotag
];
10460 /* For sli4 the abort_tag is the XRI,
10461 * so the abort routine puts the iotag of the iocb
10462 * being aborted in the context field of the abort
10465 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
10467 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
10468 "0327 Cannot abort els iocb %p "
10469 "with tag %x context %x, abort status %x, "
10471 abort_iocb
, abort_iotag
, abort_context
,
10472 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
10474 spin_unlock_irq(&phba
->hbalock
);
10476 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10481 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
10482 * @phba: Pointer to HBA context object.
10483 * @cmdiocb: Pointer to driver command iocb object.
10484 * @rspiocb: Pointer to driver response iocb object.
10486 * The function is called from SLI ring event handler with no
10487 * lock held. This function is the completion handler for ELS commands
10488 * which are aborted. The function frees memory resources used for
10489 * the aborted ELS commands.
10492 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10493 struct lpfc_iocbq
*rspiocb
)
10495 IOCB_t
*irsp
= &rspiocb
->iocb
;
10497 /* ELS cmd tag <ulpIoTag> completes */
10498 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
10499 "0139 Ignoring ELS cmd tag x%x completion Data: "
10501 irsp
->ulpIoTag
, irsp
->ulpStatus
,
10502 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
10503 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
10504 lpfc_ct_free_iocb(phba
, cmdiocb
);
10506 lpfc_els_free_iocb(phba
, cmdiocb
);
10511 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
10512 * @phba: Pointer to HBA context object.
10513 * @pring: Pointer to driver SLI ring object.
10514 * @cmdiocb: Pointer to driver command iocb object.
10516 * This function issues an abort iocb for the provided command iocb down to
10517 * the port. Other than the case the outstanding command iocb is an abort
10518 * request, this function issues abort out unconditionally. This function is
10519 * called with hbalock held. The function returns 0 when it fails due to
10520 * memory allocation failure or when the command iocb is an abort request.
10523 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10524 struct lpfc_iocbq
*cmdiocb
)
10526 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10527 struct lpfc_iocbq
*abtsiocbp
;
10528 IOCB_t
*icmd
= NULL
;
10529 IOCB_t
*iabt
= NULL
;
10531 unsigned long iflags
;
10533 lockdep_assert_held(&phba
->hbalock
);
10536 * There are certain command types we don't want to abort. And we
10537 * don't want to abort commands that are already in the process of
10540 icmd
= &cmdiocb
->iocb
;
10541 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10542 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10543 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10546 /* issue ABTS for this IOCB based on iotag */
10547 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10548 if (abtsiocbp
== NULL
)
10551 /* This signals the response to set the correct status
10552 * before calling the completion handler
10554 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10556 iabt
= &abtsiocbp
->iocb
;
10557 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10558 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
10559 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10560 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
10561 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
10564 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
10566 iabt
->ulpClass
= icmd
->ulpClass
;
10568 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10569 abtsiocbp
->hba_wqidx
= cmdiocb
->hba_wqidx
;
10570 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
10571 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10572 if (cmdiocb
->iocb_flag
& LPFC_IO_FOF
)
10573 abtsiocbp
->iocb_flag
|= LPFC_IO_FOF
;
10575 if (phba
->link_state
>= LPFC_LINK_UP
)
10576 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
10578 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
10580 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
10581 abtsiocbp
->vport
= vport
;
10583 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
10584 "0339 Abort xri x%x, original iotag x%x, "
10585 "abort cmd iotag x%x\n",
10586 iabt
->un
.acxri
.abortIoTag
,
10587 iabt
->un
.acxri
.abortContextTag
,
10590 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10591 pring
= lpfc_sli4_calc_ring(phba
, abtsiocbp
);
10592 if (unlikely(pring
== NULL
))
10594 /* Note: both hbalock and ring_lock need to be set here */
10595 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
10596 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10598 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
10600 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10605 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10608 * Caller to this routine should check for IOCB_ERROR
10609 * and handle it properly. This routine no longer removes
10610 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10616 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
10617 * @phba: Pointer to HBA context object.
10618 * @pring: Pointer to driver SLI ring object.
10619 * @cmdiocb: Pointer to driver command iocb object.
10621 * This function issues an abort iocb for the provided command iocb. In case
10622 * of unloading, the abort iocb will not be issued to commands on the ELS
10623 * ring. Instead, the callback function shall be changed to those commands
10624 * so that nothing happens when them finishes. This function is called with
10625 * hbalock held. The function returns 0 when the command iocb is an abort
10629 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10630 struct lpfc_iocbq
*cmdiocb
)
10632 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10633 int retval
= IOCB_ERROR
;
10634 IOCB_t
*icmd
= NULL
;
10636 lockdep_assert_held(&phba
->hbalock
);
10639 * There are certain command types we don't want to abort. And we
10640 * don't want to abort commands that are already in the process of
10643 icmd
= &cmdiocb
->iocb
;
10644 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10645 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10646 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10650 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10651 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10653 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10654 goto abort_iotag_exit
;
10658 * If we're unloading, don't abort iocb on the ELS ring, but change
10659 * the callback so that nothing happens when it finishes.
10661 if ((vport
->load_flag
& FC_UNLOADING
) &&
10662 (pring
->ringno
== LPFC_ELS_RING
)) {
10663 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10664 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10666 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10667 goto abort_iotag_exit
;
10670 /* Now, we try to issue the abort to the cmdiocb out */
10671 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
10675 * Caller to this routine should check for IOCB_ERROR
10676 * and handle it properly. This routine no longer removes
10677 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10683 * lpfc_sli4_abort_nvme_io - Issue abort for a command iocb
10684 * @phba: Pointer to HBA context object.
10685 * @pring: Pointer to driver SLI ring object.
10686 * @cmdiocb: Pointer to driver command iocb object.
10688 * This function issues an abort iocb for the provided command iocb down to
10689 * the port. Other than the case the outstanding command iocb is an abort
10690 * request, this function issues abort out unconditionally. This function is
10691 * called with hbalock held. The function returns 0 when it fails due to
10692 * memory allocation failure or when the command iocb is an abort request.
10695 lpfc_sli4_abort_nvme_io(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10696 struct lpfc_iocbq
*cmdiocb
)
10698 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10699 struct lpfc_iocbq
*abtsiocbp
;
10700 union lpfc_wqe
*abts_wqe
;
10704 * There are certain command types we don't want to abort. And we
10705 * don't want to abort commands that are already in the process of
10708 if (cmdiocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
10709 cmdiocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
||
10710 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10713 /* issue ABTS for this io based on iotag */
10714 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
10715 if (abtsiocbp
== NULL
)
10718 /* This signals the response to set the correct status
10719 * before calling the completion handler
10721 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10723 /* Complete prepping the abort wqe and issue to the FW. */
10724 abts_wqe
= &abtsiocbp
->wqe
;
10725 bf_set(abort_cmd_ia
, &abts_wqe
->abort_cmd
, 0);
10726 bf_set(abort_cmd_criteria
, &abts_wqe
->abort_cmd
, T_XRI_TAG
);
10728 /* Explicitly set reserved fields to zero.*/
10729 abts_wqe
->abort_cmd
.rsrvd4
= 0;
10730 abts_wqe
->abort_cmd
.rsrvd5
= 0;
10732 /* WQE Common - word 6. Context is XRI tag. Set 0. */
10733 bf_set(wqe_xri_tag
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10734 bf_set(wqe_ctxt_tag
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10737 bf_set(wqe_ct
, &abts_wqe
->abort_cmd
.wqe_com
, 0);
10738 bf_set(wqe_cmnd
, &abts_wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
10739 bf_set(wqe_class
, &abts_wqe
->abort_cmd
.wqe_com
,
10740 cmdiocb
->iocb
.ulpClass
);
10742 /* word 8 - tell the FW to abort the IO associated with this
10743 * outstanding exchange ID.
10745 abts_wqe
->abort_cmd
.wqe_com
.abort_tag
= cmdiocb
->sli4_xritag
;
10747 /* word 9 - this is the iotag for the abts_wqe completion. */
10748 bf_set(wqe_reqtag
, &abts_wqe
->abort_cmd
.wqe_com
,
10752 bf_set(wqe_wqid
, &abts_wqe
->abort_cmd
.wqe_com
, cmdiocb
->hba_wqidx
);
10753 bf_set(wqe_qosd
, &abts_wqe
->abort_cmd
.wqe_com
, 1);
10754 bf_set(wqe_lenloc
, &abts_wqe
->abort_cmd
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
10757 bf_set(wqe_cmd_type
, &abts_wqe
->abort_cmd
.wqe_com
, OTHER_COMMAND
);
10758 bf_set(wqe_wqec
, &abts_wqe
->abort_cmd
.wqe_com
, 1);
10759 bf_set(wqe_cqid
, &abts_wqe
->abort_cmd
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
10761 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10762 abtsiocbp
->iocb_flag
|= LPFC_IO_NVME
;
10763 abtsiocbp
->vport
= vport
;
10764 abtsiocbp
->wqe_cmpl
= lpfc_nvme_abort_fcreq_cmpl
;
10765 retval
= lpfc_sli4_issue_wqe(phba
, LPFC_FCP_RING
, abtsiocbp
);
10767 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NVME
,
10768 "6147 Failed abts issue_wqe with status x%x "
10770 retval
, cmdiocb
->sli4_xritag
);
10771 lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10775 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NVME
,
10776 "6148 Drv Abort NVME Request Issued for "
10777 "ox_id x%x on reqtag x%x\n",
10778 cmdiocb
->sli4_xritag
,
10785 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
10786 * @phba: pointer to lpfc HBA data structure.
10788 * This routine will abort all pending and outstanding iocbs to an HBA.
10791 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
10793 struct lpfc_sli
*psli
= &phba
->sli
;
10794 struct lpfc_sli_ring
*pring
;
10795 struct lpfc_queue
*qp
= NULL
;
10798 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
10799 for (i
= 0; i
< psli
->num_rings
; i
++) {
10800 pring
= &psli
->sli3_ring
[i
];
10801 lpfc_sli_abort_iocb_ring(phba
, pring
);
10805 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
10809 lpfc_sli_abort_iocb_ring(phba
, pring
);
10814 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
10815 * @iocbq: Pointer to driver iocb object.
10816 * @vport: Pointer to driver virtual port object.
10817 * @tgt_id: SCSI ID of the target.
10818 * @lun_id: LUN ID of the scsi device.
10819 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
10821 * This function acts as an iocb filter for functions which abort or count
10822 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
10823 * 0 if the filtering criteria is met for the given iocb and will return
10824 * 1 if the filtering criteria is not met.
10825 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
10826 * given iocb is for the SCSI device specified by vport, tgt_id and
10827 * lun_id parameter.
10828 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
10829 * given iocb is for the SCSI target specified by vport and tgt_id
10831 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
10832 * given iocb is for the SCSI host associated with the given vport.
10833 * This function is called with no locks held.
10836 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
10837 uint16_t tgt_id
, uint64_t lun_id
,
10838 lpfc_ctx_cmd ctx_cmd
)
10840 struct lpfc_scsi_buf
*lpfc_cmd
;
10843 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
10846 if (iocbq
->vport
!= vport
)
10849 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
10851 if (lpfc_cmd
->pCmd
== NULL
)
10856 if ((lpfc_cmd
->rdata
->pnode
) &&
10857 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
10858 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
10862 if ((lpfc_cmd
->rdata
->pnode
) &&
10863 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
10866 case LPFC_CTX_HOST
:
10870 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
10871 __func__
, ctx_cmd
);
10879 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
10880 * @vport: Pointer to virtual port.
10881 * @tgt_id: SCSI ID of the target.
10882 * @lun_id: LUN ID of the scsi device.
10883 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10885 * This function returns number of FCP commands pending for the vport.
10886 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
10887 * commands pending on the vport associated with SCSI device specified
10888 * by tgt_id and lun_id parameters.
10889 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
10890 * commands pending on the vport associated with SCSI target specified
10891 * by tgt_id parameter.
10892 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
10893 * commands pending on the vport.
10894 * This function returns the number of iocbs which satisfy the filter.
10895 * This function is called without any lock held.
10898 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
10899 lpfc_ctx_cmd ctx_cmd
)
10901 struct lpfc_hba
*phba
= vport
->phba
;
10902 struct lpfc_iocbq
*iocbq
;
10905 spin_lock_irq(&phba
->hbalock
);
10906 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
10907 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10909 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
10913 spin_unlock_irq(&phba
->hbalock
);
10919 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
10920 * @phba: Pointer to HBA context object
10921 * @cmdiocb: Pointer to command iocb object.
10922 * @rspiocb: Pointer to response iocb object.
10924 * This function is called when an aborted FCP iocb completes. This
10925 * function is called by the ring event handler with no lock held.
10926 * This function frees the iocb.
10929 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10930 struct lpfc_iocbq
*rspiocb
)
10932 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10933 "3096 ABORT_XRI_CN completing on rpi x%x "
10934 "original iotag x%x, abort cmd iotag x%x "
10935 "status 0x%x, reason 0x%x\n",
10936 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
10937 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
10938 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
10939 rspiocb
->iocb
.un
.ulpWord
[4]);
10940 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10945 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
10946 * @vport: Pointer to virtual port.
10947 * @pring: Pointer to driver SLI ring object.
10948 * @tgt_id: SCSI ID of the target.
10949 * @lun_id: LUN ID of the scsi device.
10950 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10952 * This function sends an abort command for every SCSI command
10953 * associated with the given virtual port pending on the ring
10954 * filtered by lpfc_sli_validate_fcp_iocb function.
10955 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
10956 * FCP iocbs associated with lun specified by tgt_id and lun_id
10958 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
10959 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10960 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
10961 * FCP iocbs associated with virtual port.
10962 * This function returns number of iocbs it failed to abort.
10963 * This function is called with no locks held.
10966 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
10967 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
10969 struct lpfc_hba
*phba
= vport
->phba
;
10970 struct lpfc_iocbq
*iocbq
;
10971 struct lpfc_iocbq
*abtsiocb
;
10972 struct lpfc_sli_ring
*pring_s4
;
10973 IOCB_t
*cmd
= NULL
;
10974 int errcnt
= 0, ret_val
= 0;
10977 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
10978 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10980 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
10985 * If the iocbq is already being aborted, don't take a second
10986 * action, but do count it.
10988 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
10991 /* issue ABTS for this IOCB based on iotag */
10992 abtsiocb
= lpfc_sli_get_iocbq(phba
);
10993 if (abtsiocb
== NULL
) {
10998 /* indicate the IO is being aborted by the driver. */
10999 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
11001 cmd
= &iocbq
->iocb
;
11002 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
11003 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
11004 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11005 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
11007 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
11008 abtsiocb
->iocb
.ulpLe
= 1;
11009 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
11010 abtsiocb
->vport
= vport
;
11012 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11013 abtsiocb
->hba_wqidx
= iocbq
->hba_wqidx
;
11014 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
11015 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
11016 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
11017 abtsiocb
->iocb_flag
|= LPFC_IO_FOF
;
11019 if (lpfc_is_link_up(phba
))
11020 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
11022 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
11024 /* Setup callback routine and issue the command. */
11025 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
11026 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11027 pring_s4
= lpfc_sli4_calc_ring(phba
, iocbq
);
11030 ret_val
= lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
11033 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
11035 if (ret_val
== IOCB_ERROR
) {
11036 lpfc_sli_release_iocbq(phba
, abtsiocb
);
11046 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
11047 * @vport: Pointer to virtual port.
11048 * @pring: Pointer to driver SLI ring object.
11049 * @tgt_id: SCSI ID of the target.
11050 * @lun_id: LUN ID of the scsi device.
11051 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
11053 * This function sends an abort command for every SCSI command
11054 * associated with the given virtual port pending on the ring
11055 * filtered by lpfc_sli_validate_fcp_iocb function.
11056 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
11057 * FCP iocbs associated with lun specified by tgt_id and lun_id
11059 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
11060 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
11061 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
11062 * FCP iocbs associated with virtual port.
11063 * This function returns number of iocbs it aborted .
11064 * This function is called with no locks held right after a taskmgmt
11068 lpfc_sli_abort_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
11069 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd cmd
)
11071 struct lpfc_hba
*phba
= vport
->phba
;
11072 struct lpfc_scsi_buf
*lpfc_cmd
;
11073 struct lpfc_iocbq
*abtsiocbq
;
11074 struct lpfc_nodelist
*ndlp
;
11075 struct lpfc_iocbq
*iocbq
;
11077 int sum
, i
, ret_val
;
11078 unsigned long iflags
;
11079 struct lpfc_sli_ring
*pring_s4
;
11081 spin_lock_irq(&phba
->hbalock
);
11083 /* all I/Os are in process of being flushed */
11084 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
11085 spin_unlock_irq(&phba
->hbalock
);
11090 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
11091 iocbq
= phba
->sli
.iocbq_lookup
[i
];
11093 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
11098 * If the iocbq is already being aborted, don't take a second
11099 * action, but do count it.
11101 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
11104 /* issue ABTS for this IOCB based on iotag */
11105 abtsiocbq
= __lpfc_sli_get_iocbq(phba
);
11106 if (abtsiocbq
== NULL
)
11109 icmd
= &iocbq
->iocb
;
11110 abtsiocbq
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
11111 abtsiocbq
->iocb
.un
.acxri
.abortContextTag
= icmd
->ulpContext
;
11112 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11113 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
=
11114 iocbq
->sli4_xritag
;
11116 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
11117 abtsiocbq
->iocb
.ulpLe
= 1;
11118 abtsiocbq
->iocb
.ulpClass
= icmd
->ulpClass
;
11119 abtsiocbq
->vport
= vport
;
11121 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
11122 abtsiocbq
->hba_wqidx
= iocbq
->hba_wqidx
;
11123 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
11124 abtsiocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
11125 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
11126 abtsiocbq
->iocb_flag
|= LPFC_IO_FOF
;
11128 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
11129 ndlp
= lpfc_cmd
->rdata
->pnode
;
11131 if (lpfc_is_link_up(phba
) &&
11132 (ndlp
&& ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
11133 abtsiocbq
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
11135 abtsiocbq
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
11137 /* Setup callback routine and issue the command. */
11138 abtsiocbq
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
11141 * Indicate the IO is being aborted by the driver and set
11142 * the caller's flag into the aborted IO.
11144 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
11146 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11147 pring_s4
= lpfc_sli4_calc_ring(phba
, iocbq
);
11148 if (pring_s4
== NULL
)
11150 /* Note: both hbalock and ring_lock must be set here */
11151 spin_lock_irqsave(&pring_s4
->ring_lock
, iflags
);
11152 ret_val
= __lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
11154 spin_unlock_irqrestore(&pring_s4
->ring_lock
, iflags
);
11156 ret_val
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
11161 if (ret_val
== IOCB_ERROR
)
11162 __lpfc_sli_release_iocbq(phba
, abtsiocbq
);
11166 spin_unlock_irq(&phba
->hbalock
);
11171 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
11172 * @phba: Pointer to HBA context object.
11173 * @cmdiocbq: Pointer to command iocb.
11174 * @rspiocbq: Pointer to response iocb.
11176 * This function is the completion handler for iocbs issued using
11177 * lpfc_sli_issue_iocb_wait function. This function is called by the
11178 * ring event handler function without any lock held. This function
11179 * can be called from both worker thread context and interrupt
11180 * context. This function also can be called from other thread which
11181 * cleans up the SLI layer objects.
11182 * This function copy the contents of the response iocb to the
11183 * response iocb memory object provided by the caller of
11184 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
11185 * sleeps for the iocb completion.
11188 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
11189 struct lpfc_iocbq
*cmdiocbq
,
11190 struct lpfc_iocbq
*rspiocbq
)
11192 wait_queue_head_t
*pdone_q
;
11193 unsigned long iflags
;
11194 struct lpfc_scsi_buf
*lpfc_cmd
;
11196 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11197 if (cmdiocbq
->iocb_flag
& LPFC_IO_WAKE_TMO
) {
11200 * A time out has occurred for the iocb. If a time out
11201 * completion handler has been supplied, call it. Otherwise,
11202 * just free the iocbq.
11205 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11206 cmdiocbq
->iocb_cmpl
= cmdiocbq
->wait_iocb_cmpl
;
11207 cmdiocbq
->wait_iocb_cmpl
= NULL
;
11208 if (cmdiocbq
->iocb_cmpl
)
11209 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, NULL
);
11211 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
11215 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
11216 if (cmdiocbq
->context2
&& rspiocbq
)
11217 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
11218 &rspiocbq
->iocb
, sizeof(IOCB_t
));
11220 /* Set the exchange busy flag for task management commands */
11221 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
11222 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
11223 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
11225 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
11228 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
11231 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11236 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
11237 * @phba: Pointer to HBA context object..
11238 * @piocbq: Pointer to command iocb.
11239 * @flag: Flag to test.
11241 * This routine grabs the hbalock and then test the iocb_flag to
11242 * see if the passed in flag is set.
11244 * 1 if flag is set.
11245 * 0 if flag is not set.
11248 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
11249 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
11251 unsigned long iflags
;
11254 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11255 ret
= piocbq
->iocb_flag
& flag
;
11256 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11262 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
11263 * @phba: Pointer to HBA context object..
11264 * @pring: Pointer to sli ring.
11265 * @piocb: Pointer to command iocb.
11266 * @prspiocbq: Pointer to response iocb.
11267 * @timeout: Timeout in number of seconds.
11269 * This function issues the iocb to firmware and waits for the
11270 * iocb to complete. The iocb_cmpl field of the shall be used
11271 * to handle iocbs which time out. If the field is NULL, the
11272 * function shall free the iocbq structure. If more clean up is
11273 * needed, the caller is expected to provide a completion function
11274 * that will provide the needed clean up. If the iocb command is
11275 * not completed within timeout seconds, the function will either
11276 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
11277 * completion function set in the iocb_cmpl field and then return
11278 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
11279 * resources if this function returns IOCB_TIMEDOUT.
11280 * The function waits for the iocb completion using an
11281 * non-interruptible wait.
11282 * This function will sleep while waiting for iocb completion.
11283 * So, this function should not be called from any context which
11284 * does not allow sleeping. Due to the same reason, this function
11285 * cannot be called with interrupt disabled.
11286 * This function assumes that the iocb completions occur while
11287 * this function sleep. So, this function cannot be called from
11288 * the thread which process iocb completion for this ring.
11289 * This function clears the iocb_flag of the iocb object before
11290 * issuing the iocb and the iocb completion handler sets this
11291 * flag and wakes this thread when the iocb completes.
11292 * The contents of the response iocb will be copied to prspiocbq
11293 * by the completion handler when the command completes.
11294 * This function returns IOCB_SUCCESS when success.
11295 * This function is called with no lock held.
11298 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
11299 uint32_t ring_number
,
11300 struct lpfc_iocbq
*piocb
,
11301 struct lpfc_iocbq
*prspiocbq
,
11304 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
11305 long timeleft
, timeout_req
= 0;
11306 int retval
= IOCB_SUCCESS
;
11308 struct lpfc_iocbq
*iocb
;
11310 int txcmplq_cnt
= 0;
11311 struct lpfc_sli_ring
*pring
;
11312 unsigned long iflags
;
11313 bool iocb_completed
= true;
11315 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
11316 pring
= lpfc_sli4_calc_ring(phba
, piocb
);
11318 pring
= &phba
->sli
.sli3_ring
[ring_number
];
11320 * If the caller has provided a response iocbq buffer, then context2
11321 * is NULL or its an error.
11324 if (piocb
->context2
)
11326 piocb
->context2
= prspiocbq
;
11329 piocb
->wait_iocb_cmpl
= piocb
->iocb_cmpl
;
11330 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
11331 piocb
->context_un
.wait_queue
= &done_q
;
11332 piocb
->iocb_flag
&= ~(LPFC_IO_WAKE
| LPFC_IO_WAKE_TMO
);
11334 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
11335 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
11337 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
11338 writel(creg_val
, phba
->HCregaddr
);
11339 readl(phba
->HCregaddr
); /* flush */
11342 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
11343 SLI_IOCB_RET_IOCB
);
11344 if (retval
== IOCB_SUCCESS
) {
11345 timeout_req
= msecs_to_jiffies(timeout
* 1000);
11346 timeleft
= wait_event_timeout(done_q
,
11347 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
11349 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11350 if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
11353 * IOCB timed out. Inform the wake iocb wait
11354 * completion function and set local status
11357 iocb_completed
= false;
11358 piocb
->iocb_flag
|= LPFC_IO_WAKE_TMO
;
11360 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11361 if (iocb_completed
) {
11362 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11363 "0331 IOCB wake signaled\n");
11364 /* Note: we are not indicating if the IOCB has a success
11365 * status or not - that's for the caller to check.
11366 * IOCB_SUCCESS means just that the command was sent and
11367 * completed. Not that it completed successfully.
11369 } else if (timeleft
== 0) {
11370 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11371 "0338 IOCB wait timeout error - no "
11372 "wake response Data x%x\n", timeout
);
11373 retval
= IOCB_TIMEDOUT
;
11375 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11376 "0330 IOCB wake NOT set, "
11378 timeout
, (timeleft
/ jiffies
));
11379 retval
= IOCB_TIMEDOUT
;
11381 } else if (retval
== IOCB_BUSY
) {
11382 if (phba
->cfg_log_verbose
& LOG_SLI
) {
11383 list_for_each_entry(iocb
, &pring
->txq
, list
) {
11386 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
11389 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11390 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
11391 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
11395 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11396 "0332 IOCB wait issue failed, Data x%x\n",
11398 retval
= IOCB_ERROR
;
11401 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
11402 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
11404 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
11405 writel(creg_val
, phba
->HCregaddr
);
11406 readl(phba
->HCregaddr
); /* flush */
11410 piocb
->context2
= NULL
;
11412 piocb
->context_un
.wait_queue
= NULL
;
11413 piocb
->iocb_cmpl
= NULL
;
11418 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
11419 * @phba: Pointer to HBA context object.
11420 * @pmboxq: Pointer to driver mailbox object.
11421 * @timeout: Timeout in number of seconds.
11423 * This function issues the mailbox to firmware and waits for the
11424 * mailbox command to complete. If the mailbox command is not
11425 * completed within timeout seconds, it returns MBX_TIMEOUT.
11426 * The function waits for the mailbox completion using an
11427 * interruptible wait. If the thread is woken up due to a
11428 * signal, MBX_TIMEOUT error is returned to the caller. Caller
11429 * should not free the mailbox resources, if this function returns
11431 * This function will sleep while waiting for mailbox completion.
11432 * So, this function should not be called from any context which
11433 * does not allow sleeping. Due to the same reason, this function
11434 * cannot be called with interrupt disabled.
11435 * This function assumes that the mailbox completion occurs while
11436 * this function sleep. So, this function cannot be called from
11437 * the worker thread which processes mailbox completion.
11438 * This function is called in the context of HBA management
11440 * This function returns MBX_SUCCESS when successful.
11441 * This function is called with no lock held.
11444 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
11447 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
11448 MAILBOX_t
*mb
= NULL
;
11450 unsigned long flag
;
11452 /* The caller might set context1 for extended buffer */
11453 if (pmboxq
->context1
)
11454 mb
= (MAILBOX_t
*)pmboxq
->context1
;
11456 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
11457 /* setup wake call as IOCB callback */
11458 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
11459 /* setup context field to pass wait_queue pointer to wake function */
11460 pmboxq
->context1
= &done_q
;
11462 /* now issue the command */
11463 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
11464 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
11465 wait_event_interruptible_timeout(done_q
,
11466 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
11467 msecs_to_jiffies(timeout
* 1000));
11469 spin_lock_irqsave(&phba
->hbalock
, flag
);
11470 /* restore the possible extended buffer for free resource */
11471 pmboxq
->context1
= (uint8_t *)mb
;
11473 * if LPFC_MBX_WAKE flag is set the mailbox is completed
11474 * else do not free the resources.
11476 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
11477 retval
= MBX_SUCCESS
;
11479 retval
= MBX_TIMEOUT
;
11480 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
11482 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
11484 /* restore the possible extended buffer for free resource */
11485 pmboxq
->context1
= (uint8_t *)mb
;
11492 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
11493 * @phba: Pointer to HBA context.
11495 * This function is called to shutdown the driver's mailbox sub-system.
11496 * It first marks the mailbox sub-system is in a block state to prevent
11497 * the asynchronous mailbox command from issued off the pending mailbox
11498 * command queue. If the mailbox command sub-system shutdown is due to
11499 * HBA error conditions such as EEH or ERATT, this routine shall invoke
11500 * the mailbox sub-system flush routine to forcefully bring down the
11501 * mailbox sub-system. Otherwise, if it is due to normal condition (such
11502 * as with offline or HBA function reset), this routine will wait for the
11503 * outstanding mailbox command to complete before invoking the mailbox
11504 * sub-system flush routine to gracefully bring down mailbox sub-system.
11507 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
11509 struct lpfc_sli
*psli
= &phba
->sli
;
11510 unsigned long timeout
;
11512 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
11513 /* delay 100ms for port state */
11515 lpfc_sli_mbox_sys_flush(phba
);
11518 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
11520 spin_lock_irq(&phba
->hbalock
);
11521 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
11523 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
11524 /* Determine how long we might wait for the active mailbox
11525 * command to be gracefully completed by firmware.
11527 if (phba
->sli
.mbox_active
)
11528 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
11529 phba
->sli
.mbox_active
) *
11531 spin_unlock_irq(&phba
->hbalock
);
11533 while (phba
->sli
.mbox_active
) {
11534 /* Check active mailbox complete status every 2ms */
11536 if (time_after(jiffies
, timeout
))
11537 /* Timeout, let the mailbox flush routine to
11538 * forcefully release active mailbox command
11543 spin_unlock_irq(&phba
->hbalock
);
11545 lpfc_sli_mbox_sys_flush(phba
);
11549 * lpfc_sli_eratt_read - read sli-3 error attention events
11550 * @phba: Pointer to HBA context.
11552 * This function is called to read the SLI3 device error attention registers
11553 * for possible error attention events. The caller must hold the hostlock
11554 * with spin_lock_irq().
11556 * This function returns 1 when there is Error Attention in the Host Attention
11557 * Register and returns 0 otherwise.
11560 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
11564 /* Read chip Host Attention (HA) register */
11565 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11568 if (ha_copy
& HA_ERATT
) {
11569 /* Read host status register to retrieve error event */
11570 if (lpfc_sli_read_hs(phba
))
11573 /* Check if there is a deferred error condition is active */
11574 if ((HS_FFER1
& phba
->work_hs
) &&
11575 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11576 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
11577 phba
->hba_flag
|= DEFER_ERATT
;
11578 /* Clear all interrupt enable conditions */
11579 writel(0, phba
->HCregaddr
);
11580 readl(phba
->HCregaddr
);
11583 /* Set the driver HA work bitmap */
11584 phba
->work_ha
|= HA_ERATT
;
11585 /* Indicate polling handles this ERATT */
11586 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11592 /* Set the driver HS work bitmap */
11593 phba
->work_hs
|= UNPLUG_ERR
;
11594 /* Set the driver HA work bitmap */
11595 phba
->work_ha
|= HA_ERATT
;
11596 /* Indicate polling handles this ERATT */
11597 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11602 * lpfc_sli4_eratt_read - read sli-4 error attention events
11603 * @phba: Pointer to HBA context.
11605 * This function is called to read the SLI4 device error attention registers
11606 * for possible error attention events. The caller must hold the hostlock
11607 * with spin_lock_irq().
11609 * This function returns 1 when there is Error Attention in the Host Attention
11610 * Register and returns 0 otherwise.
11613 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
11615 uint32_t uerr_sta_hi
, uerr_sta_lo
;
11616 uint32_t if_type
, portsmphr
;
11617 struct lpfc_register portstat_reg
;
11620 * For now, use the SLI4 device internal unrecoverable error
11621 * registers for error attention. This can be changed later.
11623 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
11625 case LPFC_SLI_INTF_IF_TYPE_0
:
11626 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
11628 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
11630 phba
->work_hs
|= UNPLUG_ERR
;
11631 phba
->work_ha
|= HA_ERATT
;
11632 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11635 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
11636 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
11637 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11638 "1423 HBA Unrecoverable error: "
11639 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
11640 "ue_mask_lo_reg=0x%x, "
11641 "ue_mask_hi_reg=0x%x\n",
11642 uerr_sta_lo
, uerr_sta_hi
,
11643 phba
->sli4_hba
.ue_mask_lo
,
11644 phba
->sli4_hba
.ue_mask_hi
);
11645 phba
->work_status
[0] = uerr_sta_lo
;
11646 phba
->work_status
[1] = uerr_sta_hi
;
11647 phba
->work_ha
|= HA_ERATT
;
11648 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11652 case LPFC_SLI_INTF_IF_TYPE_2
:
11653 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
11654 &portstat_reg
.word0
) ||
11655 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
11657 phba
->work_hs
|= UNPLUG_ERR
;
11658 phba
->work_ha
|= HA_ERATT
;
11659 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11662 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
11663 phba
->work_status
[0] =
11664 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
11665 phba
->work_status
[1] =
11666 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
11667 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11668 "2885 Port Status Event: "
11669 "port status reg 0x%x, "
11670 "port smphr reg 0x%x, "
11671 "error 1=0x%x, error 2=0x%x\n",
11672 portstat_reg
.word0
,
11674 phba
->work_status
[0],
11675 phba
->work_status
[1]);
11676 phba
->work_ha
|= HA_ERATT
;
11677 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11681 case LPFC_SLI_INTF_IF_TYPE_1
:
11683 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11684 "2886 HBA Error Attention on unsupported "
11685 "if type %d.", if_type
);
11693 * lpfc_sli_check_eratt - check error attention events
11694 * @phba: Pointer to HBA context.
11696 * This function is called from timer soft interrupt context to check HBA's
11697 * error attention register bit for error attention events.
11699 * This function returns 1 when there is Error Attention in the Host Attention
11700 * Register and returns 0 otherwise.
11703 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
11707 /* If somebody is waiting to handle an eratt, don't process it
11708 * here. The brdkill function will do this.
11710 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11713 /* Check if interrupt handler handles this ERATT */
11714 spin_lock_irq(&phba
->hbalock
);
11715 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
11716 /* Interrupt handler has handled ERATT */
11717 spin_unlock_irq(&phba
->hbalock
);
11722 * If there is deferred error attention, do not check for error
11725 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11726 spin_unlock_irq(&phba
->hbalock
);
11730 /* If PCI channel is offline, don't process it */
11731 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
11732 spin_unlock_irq(&phba
->hbalock
);
11736 switch (phba
->sli_rev
) {
11737 case LPFC_SLI_REV2
:
11738 case LPFC_SLI_REV3
:
11739 /* Read chip Host Attention (HA) register */
11740 ha_copy
= lpfc_sli_eratt_read(phba
);
11742 case LPFC_SLI_REV4
:
11743 /* Read device Uncoverable Error (UERR) registers */
11744 ha_copy
= lpfc_sli4_eratt_read(phba
);
11747 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11748 "0299 Invalid SLI revision (%d)\n",
11753 spin_unlock_irq(&phba
->hbalock
);
11759 * lpfc_intr_state_check - Check device state for interrupt handling
11760 * @phba: Pointer to HBA context.
11762 * This inline routine checks whether a device or its PCI slot is in a state
11763 * that the interrupt should be handled.
11765 * This function returns 0 if the device or the PCI slot is in a state that
11766 * interrupt should be handled, otherwise -EIO.
11769 lpfc_intr_state_check(struct lpfc_hba
*phba
)
11771 /* If the pci channel is offline, ignore all the interrupts */
11772 if (unlikely(pci_channel_offline(phba
->pcidev
)))
11775 /* Update device level interrupt statistics */
11776 phba
->sli
.slistat
.sli_intr
++;
11778 /* Ignore all interrupts during initialization. */
11779 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
11786 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
11787 * @irq: Interrupt number.
11788 * @dev_id: The device context pointer.
11790 * This function is directly called from the PCI layer as an interrupt
11791 * service routine when device with SLI-3 interface spec is enabled with
11792 * MSI-X multi-message interrupt mode and there are slow-path events in
11793 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11794 * interrupt mode, this function is called as part of the device-level
11795 * interrupt handler. When the PCI slot is in error recovery or the HBA
11796 * is undergoing initialization, the interrupt handler will not process
11797 * the interrupt. The link attention and ELS ring attention events are
11798 * handled by the worker thread. The interrupt handler signals the worker
11799 * thread and returns for these events. This function is called without
11800 * any lock held. It gets the hbalock to access and update SLI data
11803 * This function returns IRQ_HANDLED when interrupt is handled else it
11804 * returns IRQ_NONE.
11807 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
11809 struct lpfc_hba
*phba
;
11810 uint32_t ha_copy
, hc_copy
;
11811 uint32_t work_ha_copy
;
11812 unsigned long status
;
11813 unsigned long iflag
;
11816 MAILBOX_t
*mbox
, *pmbox
;
11817 struct lpfc_vport
*vport
;
11818 struct lpfc_nodelist
*ndlp
;
11819 struct lpfc_dmabuf
*mp
;
11824 * Get the driver's phba structure from the dev_id and
11825 * assume the HBA is not interrupting.
11827 phba
= (struct lpfc_hba
*)dev_id
;
11829 if (unlikely(!phba
))
11833 * Stuff needs to be attented to when this function is invoked as an
11834 * individual interrupt handler in MSI-X multi-message interrupt mode
11836 if (phba
->intr_type
== MSIX
) {
11837 /* Check device state for handling interrupt */
11838 if (lpfc_intr_state_check(phba
))
11840 /* Need to read HA REG for slow-path events */
11841 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11842 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11844 /* If somebody is waiting to handle an eratt don't process it
11845 * here. The brdkill function will do this.
11847 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11848 ha_copy
&= ~HA_ERATT
;
11849 /* Check the need for handling ERATT in interrupt handler */
11850 if (ha_copy
& HA_ERATT
) {
11851 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11852 /* ERATT polling has handled ERATT */
11853 ha_copy
&= ~HA_ERATT
;
11855 /* Indicate interrupt handler handles ERATT */
11856 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11860 * If there is deferred error attention, do not check for any
11863 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11864 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11868 /* Clear up only attention source related to slow-path */
11869 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
11872 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
11873 HC_LAINT_ENA
| HC_ERINT_ENA
),
11875 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
11877 writel(hc_copy
, phba
->HCregaddr
);
11878 readl(phba
->HAregaddr
); /* flush */
11879 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11881 ha_copy
= phba
->ha_copy
;
11883 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
11885 if (work_ha_copy
) {
11886 if (work_ha_copy
& HA_LATT
) {
11887 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
11889 * Turn off Link Attention interrupts
11890 * until CLEAR_LA done
11892 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11893 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
11894 if (lpfc_readl(phba
->HCregaddr
, &control
))
11896 control
&= ~HC_LAINT_ENA
;
11897 writel(control
, phba
->HCregaddr
);
11898 readl(phba
->HCregaddr
); /* flush */
11899 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11902 work_ha_copy
&= ~HA_LATT
;
11905 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
11907 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
11908 * the only slow ring.
11910 status
= (work_ha_copy
&
11911 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11912 status
>>= (4*LPFC_ELS_RING
);
11913 if (status
& HA_RXMASK
) {
11914 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11915 if (lpfc_readl(phba
->HCregaddr
, &control
))
11918 lpfc_debugfs_slow_ring_trc(phba
,
11919 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
11921 (uint32_t)phba
->sli
.slistat
.sli_intr
);
11923 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
11924 lpfc_debugfs_slow_ring_trc(phba
,
11925 "ISR Disable ring:"
11926 "pwork:x%x hawork:x%x wait:x%x",
11927 phba
->work_ha
, work_ha_copy
,
11928 (uint32_t)((unsigned long)
11929 &phba
->work_waitq
));
11932 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
11933 writel(control
, phba
->HCregaddr
);
11934 readl(phba
->HCregaddr
); /* flush */
11937 lpfc_debugfs_slow_ring_trc(phba
,
11938 "ISR slow ring: pwork:"
11939 "x%x hawork:x%x wait:x%x",
11940 phba
->work_ha
, work_ha_copy
,
11941 (uint32_t)((unsigned long)
11942 &phba
->work_waitq
));
11944 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11947 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11948 if (work_ha_copy
& HA_ERATT
) {
11949 if (lpfc_sli_read_hs(phba
))
11952 * Check if there is a deferred error condition
11955 if ((HS_FFER1
& phba
->work_hs
) &&
11956 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11957 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
11959 phba
->hba_flag
|= DEFER_ERATT
;
11960 /* Clear all interrupt enable conditions */
11961 writel(0, phba
->HCregaddr
);
11962 readl(phba
->HCregaddr
);
11966 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
11967 pmb
= phba
->sli
.mbox_active
;
11968 pmbox
= &pmb
->u
.mb
;
11970 vport
= pmb
->vport
;
11972 /* First check out the status word */
11973 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
11974 if (pmbox
->mbxOwner
!= OWN_HOST
) {
11975 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11977 * Stray Mailbox Interrupt, mbxCommand <cmd>
11978 * mbxStatus <status>
11980 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11982 "(%d):0304 Stray Mailbox "
11983 "Interrupt mbxCommand x%x "
11985 (vport
? vport
->vpi
: 0),
11988 /* clear mailbox attention bit */
11989 work_ha_copy
&= ~HA_MBATT
;
11991 phba
->sli
.mbox_active
= NULL
;
11992 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11993 phba
->last_completion_time
= jiffies
;
11994 del_timer(&phba
->sli
.mbox_tmo
);
11995 if (pmb
->mbox_cmpl
) {
11996 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
11998 if (pmb
->out_ext_byte_len
&&
12000 lpfc_sli_pcimem_bcopy(
12003 pmb
->out_ext_byte_len
);
12005 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
12006 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
12008 lpfc_debugfs_disc_trc(vport
,
12009 LPFC_DISC_TRC_MBOX_VPORT
,
12010 "MBOX dflt rpi: : "
12011 "status:x%x rpi:x%x",
12012 (uint32_t)pmbox
->mbxStatus
,
12013 pmbox
->un
.varWords
[0], 0);
12015 if (!pmbox
->mbxStatus
) {
12016 mp
= (struct lpfc_dmabuf
*)
12018 ndlp
= (struct lpfc_nodelist
*)
12021 /* Reg_LOGIN of dflt RPI was
12022 * successful. new lets get
12023 * rid of the RPI using the
12024 * same mbox buffer.
12026 lpfc_unreg_login(phba
,
12028 pmbox
->un
.varWords
[0],
12031 lpfc_mbx_cmpl_dflt_rpi
;
12032 pmb
->context1
= mp
;
12033 pmb
->context2
= ndlp
;
12034 pmb
->vport
= vport
;
12035 rc
= lpfc_sli_issue_mbox(phba
,
12038 if (rc
!= MBX_BUSY
)
12039 lpfc_printf_log(phba
,
12041 LOG_MBOX
| LOG_SLI
,
12042 "0350 rc should have"
12043 "been MBX_BUSY\n");
12044 if (rc
!= MBX_NOT_FINISHED
)
12045 goto send_current_mbox
;
12049 &phba
->pport
->work_port_lock
,
12051 phba
->pport
->work_port_events
&=
12053 spin_unlock_irqrestore(
12054 &phba
->pport
->work_port_lock
,
12056 lpfc_mbox_cmpl_put(phba
, pmb
);
12059 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12061 if ((work_ha_copy
& HA_MBATT
) &&
12062 (phba
->sli
.mbox_active
== NULL
)) {
12064 /* Process next mailbox command if there is one */
12066 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
12068 } while (rc
== MBX_NOT_FINISHED
);
12069 if (rc
!= MBX_SUCCESS
)
12070 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12071 LOG_SLI
, "0349 rc should be "
12075 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12076 phba
->work_ha
|= work_ha_copy
;
12077 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12078 lpfc_worker_wake_up(phba
);
12080 return IRQ_HANDLED
;
12082 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12083 return IRQ_HANDLED
;
12085 } /* lpfc_sli_sp_intr_handler */
12088 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
12089 * @irq: Interrupt number.
12090 * @dev_id: The device context pointer.
12092 * This function is directly called from the PCI layer as an interrupt
12093 * service routine when device with SLI-3 interface spec is enabled with
12094 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12095 * ring event in the HBA. However, when the device is enabled with either
12096 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12097 * device-level interrupt handler. When the PCI slot is in error recovery
12098 * or the HBA is undergoing initialization, the interrupt handler will not
12099 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12100 * the intrrupt context. This function is called without any lock held.
12101 * It gets the hbalock to access and update SLI data structures.
12103 * This function returns IRQ_HANDLED when interrupt is handled else it
12104 * returns IRQ_NONE.
12107 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
12109 struct lpfc_hba
*phba
;
12111 unsigned long status
;
12112 unsigned long iflag
;
12113 struct lpfc_sli_ring
*pring
;
12115 /* Get the driver's phba structure from the dev_id and
12116 * assume the HBA is not interrupting.
12118 phba
= (struct lpfc_hba
*) dev_id
;
12120 if (unlikely(!phba
))
12124 * Stuff needs to be attented to when this function is invoked as an
12125 * individual interrupt handler in MSI-X multi-message interrupt mode
12127 if (phba
->intr_type
== MSIX
) {
12128 /* Check device state for handling interrupt */
12129 if (lpfc_intr_state_check(phba
))
12131 /* Need to read HA REG for FCP ring and other ring events */
12132 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
12133 return IRQ_HANDLED
;
12134 /* Clear up only attention source related to fast-path */
12135 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12137 * If there is deferred error attention, do not check for
12140 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12141 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12144 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
12146 readl(phba
->HAregaddr
); /* flush */
12147 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12149 ha_copy
= phba
->ha_copy
;
12152 * Process all events on FCP ring. Take the optimized path for FCP IO.
12154 ha_copy
&= ~(phba
->work_ha_mask
);
12156 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
12157 status
>>= (4*LPFC_FCP_RING
);
12158 pring
= &phba
->sli
.sli3_ring
[LPFC_FCP_RING
];
12159 if (status
& HA_RXMASK
)
12160 lpfc_sli_handle_fast_ring_event(phba
, pring
, status
);
12162 if (phba
->cfg_multi_ring_support
== 2) {
12164 * Process all events on extra ring. Take the optimized path
12165 * for extra ring IO.
12167 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
12168 status
>>= (4*LPFC_EXTRA_RING
);
12169 if (status
& HA_RXMASK
) {
12170 lpfc_sli_handle_fast_ring_event(phba
,
12171 &phba
->sli
.sli3_ring
[LPFC_EXTRA_RING
],
12175 return IRQ_HANDLED
;
12176 } /* lpfc_sli_fp_intr_handler */
12179 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
12180 * @irq: Interrupt number.
12181 * @dev_id: The device context pointer.
12183 * This function is the HBA device-level interrupt handler to device with
12184 * SLI-3 interface spec, called from the PCI layer when either MSI or
12185 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
12186 * requires driver attention. This function invokes the slow-path interrupt
12187 * attention handling function and fast-path interrupt attention handling
12188 * function in turn to process the relevant HBA attention events. This
12189 * function is called without any lock held. It gets the hbalock to access
12190 * and update SLI data structures.
12192 * This function returns IRQ_HANDLED when interrupt is handled, else it
12193 * returns IRQ_NONE.
12196 lpfc_sli_intr_handler(int irq
, void *dev_id
)
12198 struct lpfc_hba
*phba
;
12199 irqreturn_t sp_irq_rc
, fp_irq_rc
;
12200 unsigned long status1
, status2
;
12204 * Get the driver's phba structure from the dev_id and
12205 * assume the HBA is not interrupting.
12207 phba
= (struct lpfc_hba
*) dev_id
;
12209 if (unlikely(!phba
))
12212 /* Check device state for handling interrupt */
12213 if (lpfc_intr_state_check(phba
))
12216 spin_lock(&phba
->hbalock
);
12217 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
12218 spin_unlock(&phba
->hbalock
);
12219 return IRQ_HANDLED
;
12222 if (unlikely(!phba
->ha_copy
)) {
12223 spin_unlock(&phba
->hbalock
);
12225 } else if (phba
->ha_copy
& HA_ERATT
) {
12226 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
12227 /* ERATT polling has handled ERATT */
12228 phba
->ha_copy
&= ~HA_ERATT
;
12230 /* Indicate interrupt handler handles ERATT */
12231 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
12235 * If there is deferred error attention, do not check for any interrupt.
12237 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
12238 spin_unlock(&phba
->hbalock
);
12242 /* Clear attention sources except link and error attentions */
12243 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
12244 spin_unlock(&phba
->hbalock
);
12245 return IRQ_HANDLED
;
12247 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
12248 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
12250 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
12251 writel(hc_copy
, phba
->HCregaddr
);
12252 readl(phba
->HAregaddr
); /* flush */
12253 spin_unlock(&phba
->hbalock
);
12256 * Invokes slow-path host attention interrupt handling as appropriate.
12259 /* status of events with mailbox and link attention */
12260 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
12262 /* status of events with ELS ring */
12263 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
12264 status2
>>= (4*LPFC_ELS_RING
);
12266 if (status1
|| (status2
& HA_RXMASK
))
12267 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
12269 sp_irq_rc
= IRQ_NONE
;
12272 * Invoke fast-path host attention interrupt handling as appropriate.
12275 /* status of events with FCP ring */
12276 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
12277 status1
>>= (4*LPFC_FCP_RING
);
12279 /* status of events with extra ring */
12280 if (phba
->cfg_multi_ring_support
== 2) {
12281 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
12282 status2
>>= (4*LPFC_EXTRA_RING
);
12286 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
12287 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
12289 fp_irq_rc
= IRQ_NONE
;
12291 /* Return device-level interrupt handling status */
12292 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
12293 } /* lpfc_sli_intr_handler */
12296 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
12297 * @phba: pointer to lpfc hba data structure.
12299 * This routine is invoked by the worker thread to process all the pending
12300 * SLI4 FCP abort XRI events.
12302 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
12304 struct lpfc_cq_event
*cq_event
;
12306 /* First, declare the fcp xri abort event has been handled */
12307 spin_lock_irq(&phba
->hbalock
);
12308 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
12309 spin_unlock_irq(&phba
->hbalock
);
12310 /* Now, handle all the fcp xri abort events */
12311 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
12312 /* Get the first event from the head of the event queue */
12313 spin_lock_irq(&phba
->hbalock
);
12314 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
12315 cq_event
, struct lpfc_cq_event
, list
);
12316 spin_unlock_irq(&phba
->hbalock
);
12317 /* Notify aborted XRI for FCP work queue */
12318 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
12319 /* Free the event processed back to the free pool */
12320 lpfc_sli4_cq_event_release(phba
, cq_event
);
12325 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
12326 * @phba: pointer to lpfc hba data structure.
12328 * This routine is invoked by the worker thread to process all the pending
12329 * SLI4 els abort xri events.
12331 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
12333 struct lpfc_cq_event
*cq_event
;
12335 /* First, declare the els xri abort event has been handled */
12336 spin_lock_irq(&phba
->hbalock
);
12337 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
12338 spin_unlock_irq(&phba
->hbalock
);
12339 /* Now, handle all the els xri abort events */
12340 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
12341 /* Get the first event from the head of the event queue */
12342 spin_lock_irq(&phba
->hbalock
);
12343 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
12344 cq_event
, struct lpfc_cq_event
, list
);
12345 spin_unlock_irq(&phba
->hbalock
);
12346 /* Notify aborted XRI for ELS work queue */
12347 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
12348 /* Free the event processed back to the free pool */
12349 lpfc_sli4_cq_event_release(phba
, cq_event
);
12354 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
12355 * @phba: pointer to lpfc hba data structure
12356 * @pIocbIn: pointer to the rspiocbq
12357 * @pIocbOut: pointer to the cmdiocbq
12358 * @wcqe: pointer to the complete wcqe
12360 * This routine transfers the fields of a command iocbq to a response iocbq
12361 * by copying all the IOCB fields from command iocbq and transferring the
12362 * completion status information from the complete wcqe.
12365 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
12366 struct lpfc_iocbq
*pIocbIn
,
12367 struct lpfc_iocbq
*pIocbOut
,
12368 struct lpfc_wcqe_complete
*wcqe
)
12371 unsigned long iflags
;
12372 uint32_t status
, max_response
;
12373 struct lpfc_dmabuf
*dmabuf
;
12374 struct ulp_bde64
*bpl
, bde
;
12375 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
12377 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
12378 sizeof(struct lpfc_iocbq
) - offset
);
12379 /* Map WCQE parameters into irspiocb parameters */
12380 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
12381 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
12382 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
12383 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
12384 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
12385 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
12386 wcqe
->total_data_placed
;
12388 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
12390 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
12391 switch (pIocbOut
->iocb
.ulpCommand
) {
12392 case CMD_ELS_REQUEST64_CR
:
12393 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
12394 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
12395 bde
.tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
12396 max_response
= bde
.tus
.f
.bdeSize
;
12398 case CMD_GEN_REQUEST64_CR
:
12400 if (!pIocbOut
->context3
)
12402 numBdes
= pIocbOut
->iocb
.un
.genreq64
.bdl
.bdeSize
/
12403 sizeof(struct ulp_bde64
);
12404 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
12405 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
12406 for (i
= 0; i
< numBdes
; i
++) {
12407 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
12408 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
12409 max_response
+= bde
.tus
.f
.bdeSize
;
12413 max_response
= wcqe
->total_data_placed
;
12416 if (max_response
< wcqe
->total_data_placed
)
12417 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= max_response
;
12419 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
=
12420 wcqe
->total_data_placed
;
12423 /* Convert BG errors for completion status */
12424 if (status
== CQE_STATUS_DI_ERROR
) {
12425 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
12427 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
12428 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
12430 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
12432 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
12433 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
12434 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12435 BGS_GUARD_ERR_MASK
;
12436 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
12437 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12438 BGS_APPTAG_ERR_MASK
;
12439 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
12440 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12441 BGS_REFTAG_ERR_MASK
;
12443 /* Check to see if there was any good data before the error */
12444 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
12445 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12446 BGS_HI_WATER_MARK_PRESENT_MASK
;
12447 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
12448 wcqe
->total_data_placed
;
12452 * Set ALL the error bits to indicate we don't know what
12453 * type of error it is.
12455 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
12456 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
12457 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
12458 BGS_GUARD_ERR_MASK
);
12461 /* Pick up HBA exchange busy condition */
12462 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
12463 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12464 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
12465 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12470 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
12471 * @phba: Pointer to HBA context object.
12472 * @wcqe: Pointer to work-queue completion queue entry.
12474 * This routine handles an ELS work-queue completion event and construct
12475 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
12476 * discovery engine to handle.
12478 * Return: Pointer to the receive IOCBQ, NULL otherwise.
12480 static struct lpfc_iocbq
*
12481 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
12482 struct lpfc_iocbq
*irspiocbq
)
12484 struct lpfc_sli_ring
*pring
;
12485 struct lpfc_iocbq
*cmdiocbq
;
12486 struct lpfc_wcqe_complete
*wcqe
;
12487 unsigned long iflags
;
12489 pring
= lpfc_phba_elsring(phba
);
12490 if (unlikely(!pring
))
12493 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
12494 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
12495 pring
->stats
.iocb_event
++;
12496 /* Look up the ELS command IOCB and create pseudo response IOCB */
12497 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
12498 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12499 if (unlikely(!cmdiocbq
)) {
12500 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12501 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12502 "0386 ELS complete with no corresponding "
12503 "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
12504 wcqe
->word0
, wcqe
->total_data_placed
,
12505 wcqe
->parameter
, wcqe
->word3
);
12506 lpfc_sli_release_iocbq(phba
, irspiocbq
);
12510 /* Put the iocb back on the txcmplq */
12511 lpfc_sli_ringtxcmpl_put(phba
, pring
, cmdiocbq
);
12512 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12514 /* Fake the irspiocbq and copy necessary response information */
12515 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
12520 inline struct lpfc_cq_event
*
12521 lpfc_cq_event_setup(struct lpfc_hba
*phba
, void *entry
, int size
)
12523 struct lpfc_cq_event
*cq_event
;
12525 /* Allocate a new internal CQ_EVENT entry */
12526 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
12528 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12529 "0602 Failed to alloc CQ_EVENT entry\n");
12533 /* Move the CQE into the event */
12534 memcpy(&cq_event
->cqe
, entry
, size
);
12539 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
12540 * @phba: Pointer to HBA context object.
12541 * @cqe: Pointer to mailbox completion queue entry.
12543 * This routine process a mailbox completion queue entry with asynchrous
12546 * Return: true if work posted to worker thread, otherwise false.
12549 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
12551 struct lpfc_cq_event
*cq_event
;
12552 unsigned long iflags
;
12554 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
12555 "0392 Async Event: word0:x%x, word1:x%x, "
12556 "word2:x%x, word3:x%x\n", mcqe
->word0
,
12557 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
12559 cq_event
= lpfc_cq_event_setup(phba
, mcqe
, sizeof(struct lpfc_mcqe
));
12562 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12563 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
12564 /* Set the async event flag */
12565 phba
->hba_flag
|= ASYNC_EVENT
;
12566 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12572 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
12573 * @phba: Pointer to HBA context object.
12574 * @cqe: Pointer to mailbox completion queue entry.
12576 * This routine process a mailbox completion queue entry with mailbox
12577 * completion event.
12579 * Return: true if work posted to worker thread, otherwise false.
12582 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
12584 uint32_t mcqe_status
;
12585 MAILBOX_t
*mbox
, *pmbox
;
12586 struct lpfc_mqe
*mqe
;
12587 struct lpfc_vport
*vport
;
12588 struct lpfc_nodelist
*ndlp
;
12589 struct lpfc_dmabuf
*mp
;
12590 unsigned long iflags
;
12592 bool workposted
= false;
12595 /* If not a mailbox complete MCQE, out by checking mailbox consume */
12596 if (!bf_get(lpfc_trailer_completed
, mcqe
))
12597 goto out_no_mqe_complete
;
12599 /* Get the reference to the active mbox command */
12600 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12601 pmb
= phba
->sli
.mbox_active
;
12602 if (unlikely(!pmb
)) {
12603 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
12604 "1832 No pending MBOX command to handle\n");
12605 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12606 goto out_no_mqe_complete
;
12608 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12610 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
12612 vport
= pmb
->vport
;
12614 /* Reset heartbeat timer */
12615 phba
->last_completion_time
= jiffies
;
12616 del_timer(&phba
->sli
.mbox_tmo
);
12618 /* Move mbox data to caller's mailbox region, do endian swapping */
12619 if (pmb
->mbox_cmpl
&& mbox
)
12620 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
12623 * For mcqe errors, conditionally move a modified error code to
12624 * the mbox so that the error will not be missed.
12626 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
12627 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
12628 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
12629 bf_set(lpfc_mqe_status
, mqe
,
12630 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
12632 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
12633 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
12634 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
12635 "MBOX dflt rpi: status:x%x rpi:x%x",
12637 pmbox
->un
.varWords
[0], 0);
12638 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
12639 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
12640 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
12641 /* Reg_LOGIN of dflt RPI was successful. Now lets get
12642 * RID of the PPI using the same mbox buffer.
12644 lpfc_unreg_login(phba
, vport
->vpi
,
12645 pmbox
->un
.varWords
[0], pmb
);
12646 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
12647 pmb
->context1
= mp
;
12648 pmb
->context2
= ndlp
;
12649 pmb
->vport
= vport
;
12650 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
12651 if (rc
!= MBX_BUSY
)
12652 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
12653 LOG_SLI
, "0385 rc should "
12654 "have been MBX_BUSY\n");
12655 if (rc
!= MBX_NOT_FINISHED
)
12656 goto send_current_mbox
;
12659 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
12660 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
12661 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
12663 /* There is mailbox completion work to do */
12664 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12665 __lpfc_mbox_cmpl_put(phba
, pmb
);
12666 phba
->work_ha
|= HA_MBATT
;
12667 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12671 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12672 /* Release the mailbox command posting token */
12673 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
12674 /* Setting active mailbox pointer need to be in sync to flag clear */
12675 phba
->sli
.mbox_active
= NULL
;
12676 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12677 /* Wake up worker thread to post the next pending mailbox command */
12678 lpfc_worker_wake_up(phba
);
12679 out_no_mqe_complete
:
12680 if (bf_get(lpfc_trailer_consumed
, mcqe
))
12681 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
12686 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
12687 * @phba: Pointer to HBA context object.
12688 * @cqe: Pointer to mailbox completion queue entry.
12690 * This routine process a mailbox completion queue entry, it invokes the
12691 * proper mailbox complete handling or asynchrous event handling routine
12692 * according to the MCQE's async bit.
12694 * Return: true if work posted to worker thread, otherwise false.
12697 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
12699 struct lpfc_mcqe mcqe
;
12702 /* Copy the mailbox MCQE and convert endian order as needed */
12703 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
12705 /* Invoke the proper event handling routine */
12706 if (!bf_get(lpfc_trailer_async
, &mcqe
))
12707 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
12709 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
12714 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
12715 * @phba: Pointer to HBA context object.
12716 * @cq: Pointer to associated CQ
12717 * @wcqe: Pointer to work-queue completion queue entry.
12719 * This routine handles an ELS work-queue completion event.
12721 * Return: true if work posted to worker thread, otherwise false.
12724 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12725 struct lpfc_wcqe_complete
*wcqe
)
12727 struct lpfc_iocbq
*irspiocbq
;
12728 unsigned long iflags
;
12729 struct lpfc_sli_ring
*pring
= cq
->pring
;
12731 int txcmplq_cnt
= 0;
12732 int fcp_txcmplq_cnt
= 0;
12734 /* Get an irspiocbq for later ELS response processing use */
12735 irspiocbq
= lpfc_sli_get_iocbq(phba
);
12737 if (!list_empty(&pring
->txq
))
12739 if (!list_empty(&pring
->txcmplq
))
12741 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12742 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
12743 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
12744 txq_cnt
, phba
->iocb_cnt
,
12750 /* Save off the slow-path queue event for work thread to process */
12751 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
12752 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12753 list_add_tail(&irspiocbq
->cq_event
.list
,
12754 &phba
->sli4_hba
.sp_queue_event
);
12755 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12756 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12762 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
12763 * @phba: Pointer to HBA context object.
12764 * @wcqe: Pointer to work-queue completion queue entry.
12766 * This routine handles slow-path WQ entry consumed event by invoking the
12767 * proper WQ release routine to the slow-path WQ.
12770 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
12771 struct lpfc_wcqe_release
*wcqe
)
12773 /* sanity check on queue memory */
12774 if (unlikely(!phba
->sli4_hba
.els_wq
))
12776 /* Check for the slow-path ELS work queue */
12777 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
12778 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
12779 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
12781 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12782 "2579 Slow-path wqe consume event carries "
12783 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
12784 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
12785 phba
->sli4_hba
.els_wq
->queue_id
);
12789 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
12790 * @phba: Pointer to HBA context object.
12791 * @cq: Pointer to a WQ completion queue.
12792 * @wcqe: Pointer to work-queue completion queue entry.
12794 * This routine handles an XRI abort event.
12796 * Return: true if work posted to worker thread, otherwise false.
12799 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
12800 struct lpfc_queue
*cq
,
12801 struct sli4_wcqe_xri_aborted
*wcqe
)
12803 bool workposted
= false;
12804 struct lpfc_cq_event
*cq_event
;
12805 unsigned long iflags
;
12807 switch (cq
->subtype
) {
12809 cq_event
= lpfc_cq_event_setup(
12810 phba
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
12813 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12814 list_add_tail(&cq_event
->list
,
12815 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
12816 /* Set the fcp xri abort event flag */
12817 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
12818 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12821 case LPFC_NVME_LS
: /* NVME LS uses ELS resources */
12823 cq_event
= lpfc_cq_event_setup(
12824 phba
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
12827 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12828 list_add_tail(&cq_event
->list
,
12829 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
12830 /* Set the els xri abort event flag */
12831 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
12832 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12836 /* Notify aborted XRI for NVME work queue */
12837 if (phba
->nvmet_support
)
12838 lpfc_sli4_nvmet_xri_aborted(phba
, wcqe
);
12840 lpfc_sli4_nvme_xri_aborted(phba
, wcqe
);
12842 workposted
= false;
12845 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12846 "0603 Invalid CQ subtype %d: "
12847 "%08x %08x %08x %08x\n",
12848 cq
->subtype
, wcqe
->word0
, wcqe
->parameter
,
12849 wcqe
->word2
, wcqe
->word3
);
12850 workposted
= false;
12857 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
12858 * @phba: Pointer to HBA context object.
12859 * @rcqe: Pointer to receive-queue completion queue entry.
12861 * This routine process a receive-queue completion queue entry.
12863 * Return: true if work posted to worker thread, otherwise false.
12866 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
12868 bool workposted
= false;
12869 struct fc_frame_header
*fc_hdr
;
12870 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
12871 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
12872 struct lpfc_nvmet_tgtport
*tgtp
;
12873 struct hbq_dmabuf
*dma_buf
;
12874 uint32_t status
, rq_id
;
12875 unsigned long iflags
;
12877 /* sanity check on queue memory */
12878 if (unlikely(!hrq
) || unlikely(!drq
))
12881 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
12882 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
12884 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
12885 if (rq_id
!= hrq
->queue_id
)
12888 status
= bf_get(lpfc_rcqe_status
, rcqe
);
12890 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
12891 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12892 "2537 Receive Frame Truncated!!\n");
12893 case FC_STATUS_RQ_SUCCESS
:
12894 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12895 lpfc_sli4_rq_release(hrq
, drq
);
12896 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
12898 hrq
->RQ_no_buf_found
++;
12899 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12903 hrq
->RQ_buf_posted
--;
12904 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
12906 /* If a NVME LS event (type 0x28), treat it as Fast path */
12907 fc_hdr
= (struct fc_frame_header
*)dma_buf
->hbuf
.virt
;
12909 /* save off the frame for the word thread to process */
12910 list_add_tail(&dma_buf
->cq_event
.list
,
12911 &phba
->sli4_hba
.sp_queue_event
);
12912 /* Frame received */
12913 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12914 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12917 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
12918 if (phba
->nvmet_support
) {
12919 tgtp
= phba
->targetport
->private;
12920 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_NVME
,
12921 "6402 RQE Error x%x, posted %d err_cnt "
12923 status
, hrq
->RQ_buf_posted
,
12924 hrq
->RQ_no_posted_buf
,
12925 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
12926 atomic_read(&tgtp
->rcv_fcp_cmd_out
),
12927 atomic_read(&tgtp
->xmt_fcp_release
));
12931 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
12932 hrq
->RQ_no_posted_buf
++;
12933 /* Post more buffers if possible */
12934 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12935 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
12936 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12945 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
12946 * @phba: Pointer to HBA context object.
12947 * @cq: Pointer to the completion queue.
12948 * @wcqe: Pointer to a completion queue entry.
12950 * This routine process a slow-path work-queue or receive queue completion queue
12953 * Return: true if work posted to worker thread, otherwise false.
12956 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12957 struct lpfc_cqe
*cqe
)
12959 struct lpfc_cqe cqevt
;
12960 bool workposted
= false;
12962 /* Copy the work queue CQE and convert endian order if needed */
12963 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
12965 /* Check and process for different type of WCQE and dispatch */
12966 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
12967 case CQE_CODE_COMPL_WQE
:
12968 /* Process the WQ/RQ complete event */
12969 phba
->last_completion_time
= jiffies
;
12970 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
12971 (struct lpfc_wcqe_complete
*)&cqevt
);
12973 case CQE_CODE_RELEASE_WQE
:
12974 /* Process the WQ release event */
12975 lpfc_sli4_sp_handle_rel_wcqe(phba
,
12976 (struct lpfc_wcqe_release
*)&cqevt
);
12978 case CQE_CODE_XRI_ABORTED
:
12979 /* Process the WQ XRI abort event */
12980 phba
->last_completion_time
= jiffies
;
12981 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
12982 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
12984 case CQE_CODE_RECEIVE
:
12985 case CQE_CODE_RECEIVE_V1
:
12986 /* Process the RQ event */
12987 phba
->last_completion_time
= jiffies
;
12988 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
12989 (struct lpfc_rcqe
*)&cqevt
);
12992 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12993 "0388 Not a valid WCQE code: x%x\n",
12994 bf_get(lpfc_cqe_code
, &cqevt
));
13001 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
13002 * @phba: Pointer to HBA context object.
13003 * @eqe: Pointer to fast-path event queue entry.
13005 * This routine process a event queue entry from the slow-path event queue.
13006 * It will check the MajorCode and MinorCode to determine this is for a
13007 * completion event on a completion queue, if not, an error shall be logged
13008 * and just return. Otherwise, it will get to the corresponding completion
13009 * queue and process all the entries on that completion queue, rearm the
13010 * completion queue, and then return.
13014 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
13015 struct lpfc_queue
*speq
)
13017 struct lpfc_queue
*cq
= NULL
, *childq
;
13020 /* Get the reference to the corresponding CQ */
13021 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13023 list_for_each_entry(childq
, &speq
->child_list
, list
) {
13024 if (childq
->queue_id
== cqid
) {
13029 if (unlikely(!cq
)) {
13030 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
13031 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13032 "0365 Slow-path CQ identifier "
13033 "(%d) does not exist\n", cqid
);
13037 /* Save EQ associated with this CQ */
13038 cq
->assoc_qp
= speq
;
13040 if (!queue_work(phba
->wq
, &cq
->spwork
))
13041 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13042 "0390 Cannot schedule soft IRQ "
13043 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13044 cqid
, cq
->queue_id
, smp_processor_id());
13048 * lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
13049 * @phba: Pointer to HBA context object.
13051 * This routine process a event queue entry from the slow-path event queue.
13052 * It will check the MajorCode and MinorCode to determine this is for a
13053 * completion event on a completion queue, if not, an error shall be logged
13054 * and just return. Otherwise, it will get to the corresponding completion
13055 * queue and process all the entries on that completion queue, rearm the
13056 * completion queue, and then return.
13060 lpfc_sli4_sp_process_cq(struct work_struct
*work
)
13062 struct lpfc_queue
*cq
=
13063 container_of(work
, struct lpfc_queue
, spwork
);
13064 struct lpfc_hba
*phba
= cq
->phba
;
13065 struct lpfc_cqe
*cqe
;
13066 bool workposted
= false;
13069 /* Process all the entries to the CQ */
13070 switch (cq
->type
) {
13072 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13073 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
13074 if (!(++ccount
% cq
->entry_repost
))
13080 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13081 if (cq
->subtype
== LPFC_FCP
||
13082 cq
->subtype
== LPFC_NVME
) {
13083 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13084 if (phba
->ktime_on
)
13085 cq
->isr_timestamp
= ktime_get_ns();
13087 cq
->isr_timestamp
= 0;
13089 workposted
|= lpfc_sli4_fp_handle_cqe(phba
, cq
,
13092 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
13095 if (!(++ccount
% cq
->entry_repost
))
13099 /* Track the max number of CQEs processed in 1 EQ */
13100 if (ccount
> cq
->CQ_max_cqe
)
13101 cq
->CQ_max_cqe
= ccount
;
13104 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13105 "0370 Invalid completion queue type (%d)\n",
13110 /* Catch the no cq entry condition, log an error */
13111 if (unlikely(ccount
== 0))
13112 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13113 "0371 No entry from the CQ: identifier "
13114 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
13116 /* In any case, flash and re-arm the RCQ */
13117 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
13119 /* wake up worker thread if there are works to be done */
13121 lpfc_worker_wake_up(phba
);
13125 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
13126 * @phba: Pointer to HBA context object.
13127 * @cq: Pointer to associated CQ
13128 * @wcqe: Pointer to work-queue completion queue entry.
13130 * This routine process a fast-path work queue completion entry from fast-path
13131 * event queue for FCP command response completion.
13134 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13135 struct lpfc_wcqe_complete
*wcqe
)
13137 struct lpfc_sli_ring
*pring
= cq
->pring
;
13138 struct lpfc_iocbq
*cmdiocbq
;
13139 struct lpfc_iocbq irspiocbq
;
13140 unsigned long iflags
;
13142 /* Check for response status */
13143 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
13144 /* If resource errors reported from HBA, reduce queue
13145 * depth of the SCSI device.
13147 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
13148 IOSTAT_LOCAL_REJECT
)) &&
13149 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
13150 IOERR_NO_RESOURCES
))
13151 phba
->lpfc_rampdown_queue_depth(phba
);
13153 /* Log the error status */
13154 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13155 "0373 FCP complete error: status=x%x, "
13156 "hw_status=x%x, total_data_specified=%d, "
13157 "parameter=x%x, word3=x%x\n",
13158 bf_get(lpfc_wcqe_c_status
, wcqe
),
13159 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
13160 wcqe
->total_data_placed
, wcqe
->parameter
,
13164 /* Look up the FCP command IOCB and create pseudo response IOCB */
13165 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
13166 pring
->stats
.iocb_event
++;
13167 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
13168 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13169 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
13170 if (unlikely(!cmdiocbq
)) {
13171 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13172 "0374 FCP complete with no corresponding "
13173 "cmdiocb: iotag (%d)\n",
13174 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13177 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13178 cmdiocbq
->isr_timestamp
= cq
->isr_timestamp
;
13180 if (cmdiocbq
->iocb_cmpl
== NULL
) {
13181 if (cmdiocbq
->wqe_cmpl
) {
13182 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
13183 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13184 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
13185 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13188 /* Pass the cmd_iocb and the wcqe to the upper layer */
13189 (cmdiocbq
->wqe_cmpl
)(phba
, cmdiocbq
, wcqe
);
13192 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13193 "0375 FCP cmdiocb not callback function "
13195 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
13199 /* Fake the irspiocb and copy necessary response information */
13200 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
13202 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
13203 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13204 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
13205 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13208 /* Pass the cmd_iocb and the rsp state to the upper layer */
13209 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
13213 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
13214 * @phba: Pointer to HBA context object.
13215 * @cq: Pointer to completion queue.
13216 * @wcqe: Pointer to work-queue completion queue entry.
13218 * This routine handles an fast-path WQ entry consumed event by invoking the
13219 * proper WQ release routine to the slow-path WQ.
13222 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13223 struct lpfc_wcqe_release
*wcqe
)
13225 struct lpfc_queue
*childwq
;
13226 bool wqid_matched
= false;
13229 /* Check for fast-path FCP work queue release */
13230 hba_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
13231 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
13232 if (childwq
->queue_id
== hba_wqid
) {
13233 lpfc_sli4_wq_release(childwq
,
13234 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
13235 if (childwq
->q_flag
& HBA_NVMET_WQFULL
)
13236 lpfc_nvmet_wqfull_process(phba
, childwq
);
13237 wqid_matched
= true;
13241 /* Report warning log message if no match found */
13242 if (wqid_matched
!= true)
13243 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13244 "2580 Fast-path wqe consume event carries "
13245 "miss-matched qid: wcqe-qid=x%x\n", hba_wqid
);
13249 * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
13250 * @phba: Pointer to HBA context object.
13251 * @rcqe: Pointer to receive-queue completion queue entry.
13253 * This routine process a receive-queue completion queue entry.
13255 * Return: true if work posted to worker thread, otherwise false.
13258 lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13259 struct lpfc_rcqe
*rcqe
)
13261 bool workposted
= false;
13262 struct lpfc_queue
*hrq
;
13263 struct lpfc_queue
*drq
;
13264 struct rqb_dmabuf
*dma_buf
;
13265 struct fc_frame_header
*fc_hdr
;
13266 struct lpfc_nvmet_tgtport
*tgtp
;
13267 uint32_t status
, rq_id
;
13268 unsigned long iflags
;
13269 uint32_t fctl
, idx
;
13271 if ((phba
->nvmet_support
== 0) ||
13272 (phba
->sli4_hba
.nvmet_cqset
== NULL
))
13275 idx
= cq
->queue_id
- phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
;
13276 hrq
= phba
->sli4_hba
.nvmet_mrq_hdr
[idx
];
13277 drq
= phba
->sli4_hba
.nvmet_mrq_data
[idx
];
13279 /* sanity check on queue memory */
13280 if (unlikely(!hrq
) || unlikely(!drq
))
13283 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
13284 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
13286 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
13288 if ((phba
->nvmet_support
== 0) ||
13289 (rq_id
!= hrq
->queue_id
))
13292 status
= bf_get(lpfc_rcqe_status
, rcqe
);
13294 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
13295 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13296 "6126 Receive Frame Truncated!!\n");
13298 case FC_STATUS_RQ_SUCCESS
:
13299 spin_lock_irqsave(&phba
->hbalock
, iflags
);
13300 lpfc_sli4_rq_release(hrq
, drq
);
13301 dma_buf
= lpfc_sli_rqbuf_get(phba
, hrq
);
13303 hrq
->RQ_no_buf_found
++;
13304 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13307 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
13309 hrq
->RQ_buf_posted
--;
13310 fc_hdr
= (struct fc_frame_header
*)dma_buf
->hbuf
.virt
;
13312 /* Just some basic sanity checks on FCP Command frame */
13313 fctl
= (fc_hdr
->fh_f_ctl
[0] << 16 |
13314 fc_hdr
->fh_f_ctl
[1] << 8 |
13315 fc_hdr
->fh_f_ctl
[2]);
13317 (FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
)) !=
13318 (FC_FC_FIRST_SEQ
| FC_FC_END_SEQ
| FC_FC_SEQ_INIT
)) ||
13319 (fc_hdr
->fh_seq_cnt
!= 0)) /* 0 byte swapped is still 0 */
13322 if (fc_hdr
->fh_type
== FC_TYPE_FCP
) {
13323 dma_buf
->bytes_recv
= bf_get(lpfc_rcqe_length
, rcqe
);
13324 lpfc_nvmet_unsol_fcp_event(
13325 phba
, idx
, dma_buf
,
13326 cq
->isr_timestamp
);
13330 lpfc_in_buf_free(phba
, &dma_buf
->dbuf
);
13332 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
13333 if (phba
->nvmet_support
) {
13334 tgtp
= phba
->targetport
->private;
13335 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_NVME
,
13336 "6401 RQE Error x%x, posted %d err_cnt "
13338 status
, hrq
->RQ_buf_posted
,
13339 hrq
->RQ_no_posted_buf
,
13340 atomic_read(&tgtp
->rcv_fcp_cmd_in
),
13341 atomic_read(&tgtp
->rcv_fcp_cmd_out
),
13342 atomic_read(&tgtp
->xmt_fcp_release
));
13346 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
13347 hrq
->RQ_no_posted_buf
++;
13348 /* Post more buffers if possible */
13356 * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
13357 * @cq: Pointer to the completion queue.
13358 * @eqe: Pointer to fast-path completion queue entry.
13360 * This routine process a fast-path work queue completion entry from fast-path
13361 * event queue for FCP command response completion.
13364 lpfc_sli4_fp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13365 struct lpfc_cqe
*cqe
)
13367 struct lpfc_wcqe_release wcqe
;
13368 bool workposted
= false;
13370 /* Copy the work queue CQE and convert endian order if needed */
13371 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
13373 /* Check and process for different type of WCQE and dispatch */
13374 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
13375 case CQE_CODE_COMPL_WQE
:
13376 case CQE_CODE_NVME_ERSP
:
13378 /* Process the WQ complete event */
13379 phba
->last_completion_time
= jiffies
;
13380 if ((cq
->subtype
== LPFC_FCP
) || (cq
->subtype
== LPFC_NVME
))
13381 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
13382 (struct lpfc_wcqe_complete
*)&wcqe
);
13383 if (cq
->subtype
== LPFC_NVME_LS
)
13384 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
13385 (struct lpfc_wcqe_complete
*)&wcqe
);
13387 case CQE_CODE_RELEASE_WQE
:
13388 cq
->CQ_release_wqe
++;
13389 /* Process the WQ release event */
13390 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
13391 (struct lpfc_wcqe_release
*)&wcqe
);
13393 case CQE_CODE_XRI_ABORTED
:
13394 cq
->CQ_xri_aborted
++;
13395 /* Process the WQ XRI abort event */
13396 phba
->last_completion_time
= jiffies
;
13397 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
13398 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
13400 case CQE_CODE_RECEIVE_V1
:
13401 case CQE_CODE_RECEIVE
:
13402 phba
->last_completion_time
= jiffies
;
13403 if (cq
->subtype
== LPFC_NVMET
) {
13404 workposted
= lpfc_sli4_nvmet_handle_rcqe(
13405 phba
, cq
, (struct lpfc_rcqe
*)&wcqe
);
13409 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13410 "0144 Not a valid CQE code: x%x\n",
13411 bf_get(lpfc_wcqe_c_code
, &wcqe
));
13418 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
13419 * @phba: Pointer to HBA context object.
13420 * @eqe: Pointer to fast-path event queue entry.
13422 * This routine process a event queue entry from the fast-path event queue.
13423 * It will check the MajorCode and MinorCode to determine this is for a
13424 * completion event on a completion queue, if not, an error shall be logged
13425 * and just return. Otherwise, it will get to the corresponding completion
13426 * queue and process all the entries on the completion queue, rearm the
13427 * completion queue, and then return.
13430 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
13433 struct lpfc_queue
*cq
= NULL
;
13436 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
13437 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13438 "0366 Not a valid completion "
13439 "event: majorcode=x%x, minorcode=x%x\n",
13440 bf_get_le32(lpfc_eqe_major_code
, eqe
),
13441 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
13445 /* Get the reference to the corresponding CQ */
13446 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13448 if (phba
->cfg_nvmet_mrq
&& phba
->sli4_hba
.nvmet_cqset
) {
13449 id
= phba
->sli4_hba
.nvmet_cqset
[0]->queue_id
;
13450 if ((cqid
>= id
) && (cqid
< (id
+ phba
->cfg_nvmet_mrq
))) {
13451 /* Process NVMET unsol rcv */
13452 cq
= phba
->sli4_hba
.nvmet_cqset
[cqid
- id
];
13457 if (phba
->sli4_hba
.nvme_cq_map
&&
13458 (cqid
== phba
->sli4_hba
.nvme_cq_map
[qidx
])) {
13459 /* Process NVME / NVMET command completion */
13460 cq
= phba
->sli4_hba
.nvme_cq
[qidx
];
13464 if (phba
->sli4_hba
.fcp_cq_map
&&
13465 (cqid
== phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
13466 /* Process FCP command completion */
13467 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
13471 if (phba
->sli4_hba
.nvmels_cq
&&
13472 (cqid
== phba
->sli4_hba
.nvmels_cq
->queue_id
)) {
13473 /* Process NVME unsol rcv */
13474 cq
= phba
->sli4_hba
.nvmels_cq
;
13477 /* Otherwise this is a Slow path event */
13479 lpfc_sli4_sp_handle_eqe(phba
, eqe
, phba
->sli4_hba
.hba_eq
[qidx
]);
13484 if (unlikely(cqid
!= cq
->queue_id
)) {
13485 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13486 "0368 Miss-matched fast-path completion "
13487 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
13488 cqid
, cq
->queue_id
);
13492 /* Save EQ associated with this CQ */
13493 cq
->assoc_qp
= phba
->sli4_hba
.hba_eq
[qidx
];
13495 if (!queue_work(phba
->wq
, &cq
->irqwork
))
13496 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13497 "0363 Cannot schedule soft IRQ "
13498 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13499 cqid
, cq
->queue_id
, smp_processor_id());
13503 * lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
13504 * @phba: Pointer to HBA context object.
13505 * @eqe: Pointer to fast-path event queue entry.
13507 * This routine process a event queue entry from the fast-path event queue.
13508 * It will check the MajorCode and MinorCode to determine this is for a
13509 * completion event on a completion queue, if not, an error shall be logged
13510 * and just return. Otherwise, it will get to the corresponding completion
13511 * queue and process all the entries on the completion queue, rearm the
13512 * completion queue, and then return.
13515 lpfc_sli4_hba_process_cq(struct work_struct
*work
)
13517 struct lpfc_queue
*cq
=
13518 container_of(work
, struct lpfc_queue
, irqwork
);
13519 struct lpfc_hba
*phba
= cq
->phba
;
13520 struct lpfc_cqe
*cqe
;
13521 bool workposted
= false;
13524 /* Process all the entries to the CQ */
13525 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
13526 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
13527 if (phba
->ktime_on
)
13528 cq
->isr_timestamp
= ktime_get_ns();
13530 cq
->isr_timestamp
= 0;
13532 workposted
|= lpfc_sli4_fp_handle_cqe(phba
, cq
, cqe
);
13533 if (!(++ccount
% cq
->entry_repost
))
13537 /* Track the max number of CQEs processed in 1 EQ */
13538 if (ccount
> cq
->CQ_max_cqe
)
13539 cq
->CQ_max_cqe
= ccount
;
13540 cq
->assoc_qp
->EQ_cqe_cnt
+= ccount
;
13542 /* Catch the no cq entry condition */
13543 if (unlikely(ccount
== 0))
13544 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13545 "0369 No entry from fast-path completion "
13546 "queue fcpcqid=%d\n", cq
->queue_id
);
13548 /* In any case, flash and re-arm the CQ */
13549 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
13551 /* wake up worker thread if there are works to be done */
13553 lpfc_worker_wake_up(phba
);
13557 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
13559 struct lpfc_eqe
*eqe
;
13561 /* walk all the EQ entries and drop on the floor */
13562 while ((eqe
= lpfc_sli4_eq_get(eq
)))
13565 /* Clear and re-arm the EQ */
13566 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
13571 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
13573 * @phba: Pointer to HBA context object.
13574 * @eqe: Pointer to fast-path event queue entry.
13576 * This routine process a event queue entry from the Flash Optimized Fabric
13577 * event queue. It will check the MajorCode and MinorCode to determine this
13578 * is for a completion event on a completion queue, if not, an error shall be
13579 * logged and just return. Otherwise, it will get to the corresponding
13580 * completion queue and process all the entries on the completion queue, rearm
13581 * the completion queue, and then return.
13584 lpfc_sli4_fof_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
13586 struct lpfc_queue
*cq
;
13589 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
13590 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13591 "9147 Not a valid completion "
13592 "event: majorcode=x%x, minorcode=x%x\n",
13593 bf_get_le32(lpfc_eqe_major_code
, eqe
),
13594 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
13598 /* Get the reference to the corresponding CQ */
13599 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
13601 /* Next check for OAS */
13602 cq
= phba
->sli4_hba
.oas_cq
;
13603 if (unlikely(!cq
)) {
13604 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
13605 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13606 "9148 OAS completion queue "
13607 "does not exist\n");
13611 if (unlikely(cqid
!= cq
->queue_id
)) {
13612 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13613 "9149 Miss-matched fast-path compl "
13614 "queue id: eqcqid=%d, fcpcqid=%d\n",
13615 cqid
, cq
->queue_id
);
13619 /* Save EQ associated with this CQ */
13620 cq
->assoc_qp
= phba
->sli4_hba
.fof_eq
;
13622 /* CQ work will be processed on CPU affinitized to this IRQ */
13623 if (!queue_work(phba
->wq
, &cq
->irqwork
))
13624 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13625 "0367 Cannot schedule soft IRQ "
13626 "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
13627 cqid
, cq
->queue_id
, smp_processor_id());
13631 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
13632 * @irq: Interrupt number.
13633 * @dev_id: The device context pointer.
13635 * This function is directly called from the PCI layer as an interrupt
13636 * service routine when device with SLI-4 interface spec is enabled with
13637 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
13638 * IOCB ring event in the HBA. However, when the device is enabled with either
13639 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13640 * device-level interrupt handler. When the PCI slot is in error recovery
13641 * or the HBA is undergoing initialization, the interrupt handler will not
13642 * process the interrupt. The Flash Optimized Fabric ring event are handled in
13643 * the intrrupt context. This function is called without any lock held.
13644 * It gets the hbalock to access and update SLI data structures. Note that,
13645 * the EQ to CQ are one-to-one map such that the EQ index is
13646 * equal to that of CQ index.
13648 * This function returns IRQ_HANDLED when interrupt is handled else it
13649 * returns IRQ_NONE.
13652 lpfc_sli4_fof_intr_handler(int irq
, void *dev_id
)
13654 struct lpfc_hba
*phba
;
13655 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
13656 struct lpfc_queue
*eq
;
13657 struct lpfc_eqe
*eqe
;
13658 unsigned long iflag
;
13661 /* Get the driver's phba structure from the dev_id */
13662 hba_eq_hdl
= (struct lpfc_hba_eq_hdl
*)dev_id
;
13663 phba
= hba_eq_hdl
->phba
;
13665 if (unlikely(!phba
))
13668 /* Get to the EQ struct associated with this vector */
13669 eq
= phba
->sli4_hba
.fof_eq
;
13673 /* Check device state for handling interrupt */
13674 if (unlikely(lpfc_intr_state_check(phba
))) {
13675 /* Check again for link_state with lock held */
13676 spin_lock_irqsave(&phba
->hbalock
, iflag
);
13677 if (phba
->link_state
< LPFC_LINK_DOWN
)
13678 /* Flush, clear interrupt, and rearm the EQ */
13679 lpfc_sli4_eq_flush(phba
, eq
);
13680 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
13685 * Process all the event on FCP fast-path EQ
13687 while ((eqe
= lpfc_sli4_eq_get(eq
))) {
13688 lpfc_sli4_fof_handle_eqe(phba
, eqe
);
13689 if (!(++ecount
% eq
->entry_repost
))
13691 eq
->EQ_processed
++;
13694 /* Track the max number of EQEs processed in 1 intr */
13695 if (ecount
> eq
->EQ_max_eqe
)
13696 eq
->EQ_max_eqe
= ecount
;
13699 if (unlikely(ecount
== 0)) {
13702 if (phba
->intr_type
== MSIX
)
13703 /* MSI-X treated interrupt served as no EQ share INT */
13704 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13705 "9145 MSI-X interrupt with no EQE\n");
13707 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13708 "9146 ISR interrupt with no EQE\n");
13709 /* Non MSI-X treated on interrupt as EQ share INT */
13713 /* Always clear and re-arm the fast-path EQ */
13714 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
13715 return IRQ_HANDLED
;
13719 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
13720 * @irq: Interrupt number.
13721 * @dev_id: The device context pointer.
13723 * This function is directly called from the PCI layer as an interrupt
13724 * service routine when device with SLI-4 interface spec is enabled with
13725 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
13726 * ring event in the HBA. However, when the device is enabled with either
13727 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
13728 * device-level interrupt handler. When the PCI slot is in error recovery
13729 * or the HBA is undergoing initialization, the interrupt handler will not
13730 * process the interrupt. The SCSI FCP fast-path ring event are handled in
13731 * the intrrupt context. This function is called without any lock held.
13732 * It gets the hbalock to access and update SLI data structures. Note that,
13733 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
13734 * equal to that of FCP CQ index.
13736 * The link attention and ELS ring attention events are handled
13737 * by the worker thread. The interrupt handler signals the worker thread
13738 * and returns for these events. This function is called without any lock
13739 * held. It gets the hbalock to access and update SLI data structures.
13741 * This function returns IRQ_HANDLED when interrupt is handled else it
13742 * returns IRQ_NONE.
13745 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
13747 struct lpfc_hba
*phba
;
13748 struct lpfc_hba_eq_hdl
*hba_eq_hdl
;
13749 struct lpfc_queue
*fpeq
;
13750 struct lpfc_eqe
*eqe
;
13751 unsigned long iflag
;
13755 /* Get the driver's phba structure from the dev_id */
13756 hba_eq_hdl
= (struct lpfc_hba_eq_hdl
*)dev_id
;
13757 phba
= hba_eq_hdl
->phba
;
13758 hba_eqidx
= hba_eq_hdl
->idx
;
13760 if (unlikely(!phba
))
13762 if (unlikely(!phba
->sli4_hba
.hba_eq
))
13765 /* Get to the EQ struct associated with this vector */
13766 fpeq
= phba
->sli4_hba
.hba_eq
[hba_eqidx
];
13767 if (unlikely(!fpeq
))
13770 if (lpfc_fcp_look_ahead
) {
13771 if (atomic_dec_and_test(&hba_eq_hdl
->hba_eq_in_use
))
13772 lpfc_sli4_eq_clr_intr(fpeq
);
13774 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13779 /* Check device state for handling interrupt */
13780 if (unlikely(lpfc_intr_state_check(phba
))) {
13781 /* Check again for link_state with lock held */
13782 spin_lock_irqsave(&phba
->hbalock
, iflag
);
13783 if (phba
->link_state
< LPFC_LINK_DOWN
)
13784 /* Flush, clear interrupt, and rearm the EQ */
13785 lpfc_sli4_eq_flush(phba
, fpeq
);
13786 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
13787 if (lpfc_fcp_look_ahead
)
13788 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13793 * Process all the event on FCP fast-path EQ
13795 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
13796 lpfc_sli4_hba_handle_eqe(phba
, eqe
, hba_eqidx
);
13797 if (!(++ecount
% fpeq
->entry_repost
))
13799 fpeq
->EQ_processed
++;
13802 /* Track the max number of EQEs processed in 1 intr */
13803 if (ecount
> fpeq
->EQ_max_eqe
)
13804 fpeq
->EQ_max_eqe
= ecount
;
13806 /* Always clear and re-arm the fast-path EQ */
13807 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
13809 if (unlikely(ecount
== 0)) {
13810 fpeq
->EQ_no_entry
++;
13812 if (lpfc_fcp_look_ahead
) {
13813 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13817 if (phba
->intr_type
== MSIX
)
13818 /* MSI-X treated interrupt served as no EQ share INT */
13819 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13820 "0358 MSI-X interrupt with no EQE\n");
13822 /* Non MSI-X treated on interrupt as EQ share INT */
13826 if (lpfc_fcp_look_ahead
)
13827 atomic_inc(&hba_eq_hdl
->hba_eq_in_use
);
13829 return IRQ_HANDLED
;
13830 } /* lpfc_sli4_fp_intr_handler */
13833 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
13834 * @irq: Interrupt number.
13835 * @dev_id: The device context pointer.
13837 * This function is the device-level interrupt handler to device with SLI-4
13838 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
13839 * interrupt mode is enabled and there is an event in the HBA which requires
13840 * driver attention. This function invokes the slow-path interrupt attention
13841 * handling function and fast-path interrupt attention handling function in
13842 * turn to process the relevant HBA attention events. This function is called
13843 * without any lock held. It gets the hbalock to access and update SLI data
13846 * This function returns IRQ_HANDLED when interrupt is handled, else it
13847 * returns IRQ_NONE.
13850 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
13852 struct lpfc_hba
*phba
;
13853 irqreturn_t hba_irq_rc
;
13854 bool hba_handled
= false;
13857 /* Get the driver's phba structure from the dev_id */
13858 phba
= (struct lpfc_hba
*)dev_id
;
13860 if (unlikely(!phba
))
13864 * Invoke fast-path host attention interrupt handling as appropriate.
13866 for (qidx
= 0; qidx
< phba
->io_channel_irqs
; qidx
++) {
13867 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
13868 &phba
->sli4_hba
.hba_eq_hdl
[qidx
]);
13869 if (hba_irq_rc
== IRQ_HANDLED
)
13870 hba_handled
|= true;
13873 if (phba
->cfg_fof
) {
13874 hba_irq_rc
= lpfc_sli4_fof_intr_handler(irq
,
13875 &phba
->sli4_hba
.hba_eq_hdl
[qidx
]);
13876 if (hba_irq_rc
== IRQ_HANDLED
)
13877 hba_handled
|= true;
13880 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
13881 } /* lpfc_sli4_intr_handler */
13884 * lpfc_sli4_queue_free - free a queue structure and associated memory
13885 * @queue: The queue structure to free.
13887 * This function frees a queue structure and the DMAable memory used for
13888 * the host resident queue. This function must be called after destroying the
13889 * queue on the HBA.
13892 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
13894 struct lpfc_dmabuf
*dmabuf
;
13899 while (!list_empty(&queue
->page_list
)) {
13900 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
13902 dma_free_coherent(&queue
->phba
->pcidev
->dev
, queue
->page_size
,
13903 dmabuf
->virt
, dmabuf
->phys
);
13907 lpfc_free_rq_buffer(queue
->phba
, queue
);
13908 kfree(queue
->rqbp
);
13911 if (!list_empty(&queue
->wq_list
))
13912 list_del(&queue
->wq_list
);
13919 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
13920 * @phba: The HBA that this queue is being created on.
13921 * @page_size: The size of a queue page
13922 * @entry_size: The size of each queue entry for this queue.
13923 * @entry count: The number of entries that this queue will handle.
13925 * This function allocates a queue structure and the DMAable memory used for
13926 * the host resident queue. This function must be called before creating the
13927 * queue on the HBA.
13929 struct lpfc_queue
*
13930 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t page_size
,
13931 uint32_t entry_size
, uint32_t entry_count
)
13933 struct lpfc_queue
*queue
;
13934 struct lpfc_dmabuf
*dmabuf
;
13935 int x
, total_qe_count
;
13937 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13939 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13940 hw_page_size
= page_size
;
13942 queue
= kzalloc(sizeof(struct lpfc_queue
) +
13943 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
13946 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
13947 hw_page_size
))/hw_page_size
;
13949 /* If needed, Adjust page count to match the max the adapter supports */
13950 if (queue
->page_count
> phba
->sli4_hba
.pc_sli4_params
.wqpcnt
)
13951 queue
->page_count
= phba
->sli4_hba
.pc_sli4_params
.wqpcnt
;
13953 INIT_LIST_HEAD(&queue
->list
);
13954 INIT_LIST_HEAD(&queue
->wq_list
);
13955 INIT_LIST_HEAD(&queue
->wqfull_list
);
13956 INIT_LIST_HEAD(&queue
->page_list
);
13957 INIT_LIST_HEAD(&queue
->child_list
);
13959 /* Set queue parameters now. If the system cannot provide memory
13960 * resources, the free routine needs to know what was allocated.
13962 queue
->entry_size
= entry_size
;
13963 queue
->entry_count
= entry_count
;
13964 queue
->page_size
= hw_page_size
;
13965 queue
->phba
= phba
;
13967 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
13968 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
13971 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
13972 hw_page_size
, &dmabuf
->phys
,
13974 if (!dmabuf
->virt
) {
13978 dmabuf
->buffer_tag
= x
;
13979 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
13980 /* initialize queue's entry array */
13981 dma_pointer
= dmabuf
->virt
;
13982 for (; total_qe_count
< entry_count
&&
13983 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
13984 total_qe_count
++, dma_pointer
+= entry_size
) {
13985 queue
->qe
[total_qe_count
].address
= dma_pointer
;
13988 INIT_WORK(&queue
->irqwork
, lpfc_sli4_hba_process_cq
);
13989 INIT_WORK(&queue
->spwork
, lpfc_sli4_sp_process_cq
);
13991 /* entry_repost will be set during q creation */
13995 lpfc_sli4_queue_free(queue
);
14000 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
14001 * @phba: HBA structure that indicates port to create a queue on.
14002 * @pci_barset: PCI BAR set flag.
14004 * This function shall perform iomap of the specified PCI BAR address to host
14005 * memory address if not already done so and return it. The returned host
14006 * memory address can be NULL.
14008 static void __iomem
*
14009 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
14014 switch (pci_barset
) {
14015 case WQ_PCI_BAR_0_AND_1
:
14016 return phba
->pci_bar0_memmap_p
;
14017 case WQ_PCI_BAR_2_AND_3
:
14018 return phba
->pci_bar2_memmap_p
;
14019 case WQ_PCI_BAR_4_AND_5
:
14020 return phba
->pci_bar4_memmap_p
;
14028 * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on FCP EQs
14029 * @phba: HBA structure that indicates port to create a queue on.
14030 * @startq: The starting FCP EQ to modify
14032 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
14033 * The command allows up to LPFC_MAX_EQ_DELAY_EQID_CNT EQ ID's to be
14034 * updated in one mailbox command.
14036 * The @phba struct is used to send mailbox command to HBA. The @startq
14037 * is used to get the starting FCP EQ to change.
14038 * This function is asynchronous and will wait for the mailbox
14039 * command to finish before continuing.
14041 * On success this function will return a zero. If unable to allocate enough
14042 * memory this function will return -ENOMEM. If the queue create mailbox command
14043 * fails this function will return -ENXIO.
14046 lpfc_modify_hba_eq_delay(struct lpfc_hba
*phba
, uint32_t startq
,
14047 uint32_t numq
, uint32_t imax
)
14049 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
14050 LPFC_MBOXQ_t
*mbox
;
14051 struct lpfc_queue
*eq
;
14052 int cnt
, rc
, length
, status
= 0;
14053 uint32_t shdr_status
, shdr_add_status
;
14054 uint32_t result
, val
;
14056 union lpfc_sli4_cfg_shdr
*shdr
;
14059 if (startq
>= phba
->io_channel_irqs
)
14062 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14065 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
14066 sizeof(struct lpfc_sli4_cfg_mhdr
));
14067 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14068 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
14069 length
, LPFC_SLI4_MBX_EMBED
);
14070 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
14072 /* Calculate delay multiper from maximum interrupt per second */
14073 result
= imax
/ phba
->io_channel_irqs
;
14074 if (result
> LPFC_DMULT_CONST
|| result
== 0)
14077 dmult
= LPFC_DMULT_CONST
/result
- 1;
14078 if (dmult
> LPFC_DMULT_MAX
)
14079 dmult
= LPFC_DMULT_MAX
;
14082 for (qidx
= startq
; qidx
< phba
->io_channel_irqs
; qidx
++) {
14083 eq
= phba
->sli4_hba
.hba_eq
[qidx
];
14087 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
14088 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
14089 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
14092 /* q_mode is only used for auto_imax */
14093 if (phba
->sli
.sli_flag
& LPFC_SLI_USE_EQDR
) {
14094 /* Use EQ Delay Register method for q_mode */
14096 /* Convert for EQ Delay register */
14097 val
= phba
->cfg_fcp_imax
;
14099 /* First, interrupts per sec per EQ */
14100 val
= phba
->cfg_fcp_imax
/
14101 phba
->io_channel_irqs
;
14103 /* us delay between each interrupt */
14104 val
= LPFC_SEC_TO_USEC
/ val
;
14114 eq_delay
->u
.request
.num_eq
= cnt
;
14116 mbox
->vport
= phba
->pport
;
14117 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14118 mbox
->context1
= NULL
;
14119 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14120 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
14121 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14122 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14123 if (shdr_status
|| shdr_add_status
|| rc
) {
14124 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14125 "2512 MODIFY_EQ_DELAY mailbox failed with "
14126 "status x%x add_status x%x, mbx status x%x\n",
14127 shdr_status
, shdr_add_status
, rc
);
14130 mempool_free(mbox
, phba
->mbox_mem_pool
);
14135 * lpfc_eq_create - Create an Event Queue on the HBA
14136 * @phba: HBA structure that indicates port to create a queue on.
14137 * @eq: The queue structure to use to create the event queue.
14138 * @imax: The maximum interrupt per second limit.
14140 * This function creates an event queue, as detailed in @eq, on a port,
14141 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
14143 * The @phba struct is used to send mailbox command to HBA. The @eq struct
14144 * is used to get the entry count and entry size that are necessary to
14145 * determine the number of pages to allocate and use for this queue. This
14146 * function will send the EQ_CREATE mailbox command to the HBA to setup the
14147 * event queue. This function is asynchronous and will wait for the mailbox
14148 * command to finish before continuing.
14150 * On success this function will return a zero. If unable to allocate enough
14151 * memory this function will return -ENOMEM. If the queue create mailbox command
14152 * fails this function will return -ENXIO.
14155 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
14157 struct lpfc_mbx_eq_create
*eq_create
;
14158 LPFC_MBOXQ_t
*mbox
;
14159 int rc
, length
, status
= 0;
14160 struct lpfc_dmabuf
*dmabuf
;
14161 uint32_t shdr_status
, shdr_add_status
;
14162 union lpfc_sli4_cfg_shdr
*shdr
;
14164 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14166 /* sanity check on queue memory */
14169 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14170 hw_page_size
= SLI4_PAGE_SIZE
;
14172 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14175 length
= (sizeof(struct lpfc_mbx_eq_create
) -
14176 sizeof(struct lpfc_sli4_cfg_mhdr
));
14177 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14178 LPFC_MBOX_OPCODE_EQ_CREATE
,
14179 length
, LPFC_SLI4_MBX_EMBED
);
14180 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
14181 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
14183 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
14185 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
14186 /* don't setup delay multiplier using EQ_CREATE */
14188 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
14190 switch (eq
->entry_count
) {
14192 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14193 "0360 Unsupported EQ count. (%d)\n",
14195 if (eq
->entry_count
< 256)
14197 /* otherwise default to smallest count (drop through) */
14199 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14203 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
14207 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
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 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
14220 memset(dmabuf
->virt
, 0, hw_page_size
);
14221 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14222 putPaddrLow(dmabuf
->phys
);
14223 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14224 putPaddrHigh(dmabuf
->phys
);
14226 mbox
->vport
= phba
->pport
;
14227 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14228 mbox
->context1
= NULL
;
14229 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14230 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
14231 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14232 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14233 if (shdr_status
|| shdr_add_status
|| rc
) {
14234 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14235 "2500 EQ_CREATE mailbox failed with "
14236 "status x%x add_status x%x, mbx status x%x\n",
14237 shdr_status
, shdr_add_status
, rc
);
14240 eq
->type
= LPFC_EQ
;
14241 eq
->subtype
= LPFC_NONE
;
14242 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
14243 if (eq
->queue_id
== 0xFFFF)
14245 eq
->host_index
= 0;
14247 eq
->entry_repost
= LPFC_EQ_REPOST
;
14249 mempool_free(mbox
, phba
->mbox_mem_pool
);
14254 * lpfc_cq_create - Create a Completion Queue on the HBA
14255 * @phba: HBA structure that indicates port to create a queue on.
14256 * @cq: The queue structure to use to create the completion queue.
14257 * @eq: The event queue to bind this completion queue to.
14259 * This function creates a completion queue, as detailed in @wq, on a port,
14260 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
14262 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14263 * is used to get the entry count and entry size that are necessary to
14264 * determine the number of pages to allocate and use for this queue. The @eq
14265 * is used to indicate which event queue to bind this completion queue to. This
14266 * function will send the CQ_CREATE mailbox command to the HBA to setup the
14267 * completion queue. This function is asynchronous and will wait for the mailbox
14268 * command to finish before continuing.
14270 * On success this function will return a zero. If unable to allocate enough
14271 * memory this function will return -ENOMEM. If the queue create mailbox command
14272 * fails this function will return -ENXIO.
14275 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
14276 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
14278 struct lpfc_mbx_cq_create
*cq_create
;
14279 struct lpfc_dmabuf
*dmabuf
;
14280 LPFC_MBOXQ_t
*mbox
;
14281 int rc
, length
, status
= 0;
14282 uint32_t shdr_status
, shdr_add_status
;
14283 union lpfc_sli4_cfg_shdr
*shdr
;
14284 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14286 /* sanity check on queue memory */
14289 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14290 hw_page_size
= cq
->page_size
;
14292 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14295 length
= (sizeof(struct lpfc_mbx_cq_create
) -
14296 sizeof(struct lpfc_sli4_cfg_mhdr
));
14297 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14298 LPFC_MBOX_OPCODE_CQ_CREATE
,
14299 length
, LPFC_SLI4_MBX_EMBED
);
14300 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
14301 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
14302 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
14304 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
14305 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
14306 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14307 phba
->sli4_hba
.pc_sli4_params
.cqv
);
14308 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
14309 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
,
14310 (cq
->page_size
/ SLI4_PAGE_SIZE
));
14311 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
14314 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
14317 switch (cq
->entry_count
) {
14320 if (phba
->sli4_hba
.pc_sli4_params
.cqv
==
14321 LPFC_Q_CREATE_VERSION_2
) {
14322 cq_create
->u
.request
.context
.lpfc_cq_context_count
=
14324 bf_set(lpfc_cq_context_count
,
14325 &cq_create
->u
.request
.context
,
14326 LPFC_CQ_CNT_WORD7
);
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, cq
->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
)
14437 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14441 length
= sizeof(struct lpfc_mbx_cq_create_set
);
14442 length
+= ((numcq
* cqp
[0]->page_count
) *
14443 sizeof(struct dma_address
));
14444 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14445 LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET
, length
,
14446 LPFC_SLI4_MBX_NEMBED
);
14447 if (alloclen
< length
) {
14448 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14449 "3098 Allocated DMA memory size (%d) is "
14450 "less than the requested DMA memory size "
14451 "(%d)\n", alloclen
, length
);
14455 cq_set
= mbox
->sge_array
->addr
[0];
14456 shdr
= (union lpfc_sli4_cfg_shdr
*)&cq_set
->cfg_shdr
;
14457 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, 0);
14459 for (idx
= 0; idx
< numcq
; idx
++) {
14466 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14467 hw_page_size
= cq
->page_size
;
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
) {
14487 if (phba
->sli4_hba
.pc_sli4_params
.cqv
==
14488 LPFC_Q_CREATE_VERSION_2
) {
14489 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14490 &cq_set
->u
.request
,
14492 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14493 &cq_set
->u
.request
,
14494 LPFC_CQ_CNT_WORD7
);
14499 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14500 "3118 Bad CQ count. (%d)\n",
14502 if (cq
->entry_count
< 256) {
14506 /* otherwise default to smallest (drop thru) */
14508 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14509 &cq_set
->u
.request
, LPFC_CQ_CNT_256
);
14512 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14513 &cq_set
->u
.request
, LPFC_CQ_CNT_512
);
14516 bf_set(lpfc_mbx_cq_create_set_cqe_cnt
,
14517 &cq_set
->u
.request
, LPFC_CQ_CNT_1024
);
14520 bf_set(lpfc_mbx_cq_create_set_eq_id0
,
14521 &cq_set
->u
.request
, eq
->queue_id
);
14524 bf_set(lpfc_mbx_cq_create_set_eq_id1
,
14525 &cq_set
->u
.request
, eq
->queue_id
);
14528 bf_set(lpfc_mbx_cq_create_set_eq_id2
,
14529 &cq_set
->u
.request
, eq
->queue_id
);
14532 bf_set(lpfc_mbx_cq_create_set_eq_id3
,
14533 &cq_set
->u
.request
, eq
->queue_id
);
14536 bf_set(lpfc_mbx_cq_create_set_eq_id4
,
14537 &cq_set
->u
.request
, eq
->queue_id
);
14540 bf_set(lpfc_mbx_cq_create_set_eq_id5
,
14541 &cq_set
->u
.request
, eq
->queue_id
);
14544 bf_set(lpfc_mbx_cq_create_set_eq_id6
,
14545 &cq_set
->u
.request
, eq
->queue_id
);
14548 bf_set(lpfc_mbx_cq_create_set_eq_id7
,
14549 &cq_set
->u
.request
, eq
->queue_id
);
14552 bf_set(lpfc_mbx_cq_create_set_eq_id8
,
14553 &cq_set
->u
.request
, eq
->queue_id
);
14556 bf_set(lpfc_mbx_cq_create_set_eq_id9
,
14557 &cq_set
->u
.request
, eq
->queue_id
);
14560 bf_set(lpfc_mbx_cq_create_set_eq_id10
,
14561 &cq_set
->u
.request
, eq
->queue_id
);
14564 bf_set(lpfc_mbx_cq_create_set_eq_id11
,
14565 &cq_set
->u
.request
, eq
->queue_id
);
14568 bf_set(lpfc_mbx_cq_create_set_eq_id12
,
14569 &cq_set
->u
.request
, eq
->queue_id
);
14572 bf_set(lpfc_mbx_cq_create_set_eq_id13
,
14573 &cq_set
->u
.request
, eq
->queue_id
);
14576 bf_set(lpfc_mbx_cq_create_set_eq_id14
,
14577 &cq_set
->u
.request
, eq
->queue_id
);
14580 bf_set(lpfc_mbx_cq_create_set_eq_id15
,
14581 &cq_set
->u
.request
, eq
->queue_id
);
14585 /* link the cq onto the parent eq child list */
14586 list_add_tail(&cq
->list
, &eq
->child_list
);
14587 /* Set up completion queue's type and subtype */
14589 cq
->subtype
= subtype
;
14590 cq
->assoc_qid
= eq
->queue_id
;
14591 cq
->host_index
= 0;
14593 cq
->entry_repost
= LPFC_CQ_REPOST
;
14597 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
14598 memset(dmabuf
->virt
, 0, hw_page_size
);
14599 cnt
= page_idx
+ dmabuf
->buffer_tag
;
14600 cq_set
->u
.request
.page
[cnt
].addr_lo
=
14601 putPaddrLow(dmabuf
->phys
);
14602 cq_set
->u
.request
.page
[cnt
].addr_hi
=
14603 putPaddrHigh(dmabuf
->phys
);
14609 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14611 /* The IOCTL status is embedded in the mailbox subheader. */
14612 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14613 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14614 if (shdr_status
|| shdr_add_status
|| rc
) {
14615 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14616 "3119 CQ_CREATE_SET mailbox failed with "
14617 "status x%x add_status x%x, mbx status x%x\n",
14618 shdr_status
, shdr_add_status
, rc
);
14622 rc
= bf_get(lpfc_mbx_cq_create_set_base_id
, &cq_set
->u
.response
);
14623 if (rc
== 0xFFFF) {
14628 for (idx
= 0; idx
< numcq
; idx
++) {
14630 cq
->queue_id
= rc
+ idx
;
14634 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14639 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
14640 * @phba: HBA structure that indicates port to create a queue on.
14641 * @mq: The queue structure to use to create the mailbox queue.
14642 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
14643 * @cq: The completion queue to associate with this cq.
14645 * This function provides failback (fb) functionality when the
14646 * mq_create_ext fails on older FW generations. It's purpose is identical
14647 * to mq_create_ext otherwise.
14649 * This routine cannot fail as all attributes were previously accessed and
14650 * initialized in mq_create_ext.
14653 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
14654 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
14656 struct lpfc_mbx_mq_create
*mq_create
;
14657 struct lpfc_dmabuf
*dmabuf
;
14660 length
= (sizeof(struct lpfc_mbx_mq_create
) -
14661 sizeof(struct lpfc_sli4_cfg_mhdr
));
14662 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14663 LPFC_MBOX_OPCODE_MQ_CREATE
,
14664 length
, LPFC_SLI4_MBX_EMBED
);
14665 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
14666 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
14668 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
14670 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
14671 switch (mq
->entry_count
) {
14673 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14674 LPFC_MQ_RING_SIZE_16
);
14677 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14678 LPFC_MQ_RING_SIZE_32
);
14681 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14682 LPFC_MQ_RING_SIZE_64
);
14685 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
14686 LPFC_MQ_RING_SIZE_128
);
14689 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
14690 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14691 putPaddrLow(dmabuf
->phys
);
14692 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14693 putPaddrHigh(dmabuf
->phys
);
14698 * lpfc_mq_create - Create a mailbox Queue on the HBA
14699 * @phba: HBA structure that indicates port to create a queue on.
14700 * @mq: The queue structure to use to create the mailbox queue.
14701 * @cq: The completion queue to associate with this cq.
14702 * @subtype: The queue's subtype.
14704 * This function creates a mailbox queue, as detailed in @mq, on a port,
14705 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
14707 * The @phba struct is used to send mailbox command to HBA. The @cq struct
14708 * is used to get the entry count and entry size that are necessary to
14709 * determine the number of pages to allocate and use for this queue. This
14710 * function will send the MQ_CREATE mailbox command to the HBA to setup the
14711 * mailbox queue. This function is asynchronous and will wait for the mailbox
14712 * command to finish before continuing.
14714 * On success this function will return a zero. If unable to allocate enough
14715 * memory this function will return -ENOMEM. If the queue create mailbox command
14716 * fails this function will return -ENXIO.
14719 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
14720 struct lpfc_queue
*cq
, uint32_t subtype
)
14722 struct lpfc_mbx_mq_create
*mq_create
;
14723 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
14724 struct lpfc_dmabuf
*dmabuf
;
14725 LPFC_MBOXQ_t
*mbox
;
14726 int rc
, length
, status
= 0;
14727 uint32_t shdr_status
, shdr_add_status
;
14728 union lpfc_sli4_cfg_shdr
*shdr
;
14729 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14731 /* sanity check on queue memory */
14734 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14735 hw_page_size
= SLI4_PAGE_SIZE
;
14737 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14740 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
14741 sizeof(struct lpfc_sli4_cfg_mhdr
));
14742 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14743 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
14744 length
, LPFC_SLI4_MBX_EMBED
);
14746 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
14747 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
14748 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
14749 &mq_create_ext
->u
.request
, mq
->page_count
);
14750 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
14751 &mq_create_ext
->u
.request
, 1);
14752 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
14753 &mq_create_ext
->u
.request
, 1);
14754 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
14755 &mq_create_ext
->u
.request
, 1);
14756 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
14757 &mq_create_ext
->u
.request
, 1);
14758 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
14759 &mq_create_ext
->u
.request
, 1);
14760 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
14761 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14762 phba
->sli4_hba
.pc_sli4_params
.mqv
);
14763 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
14764 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
14767 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
14769 switch (mq
->entry_count
) {
14771 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14772 "0362 Unsupported MQ count. (%d)\n",
14774 if (mq
->entry_count
< 16) {
14778 /* otherwise default to smallest count (drop through) */
14780 bf_set(lpfc_mq_context_ring_size
,
14781 &mq_create_ext
->u
.request
.context
,
14782 LPFC_MQ_RING_SIZE_16
);
14785 bf_set(lpfc_mq_context_ring_size
,
14786 &mq_create_ext
->u
.request
.context
,
14787 LPFC_MQ_RING_SIZE_32
);
14790 bf_set(lpfc_mq_context_ring_size
,
14791 &mq_create_ext
->u
.request
.context
,
14792 LPFC_MQ_RING_SIZE_64
);
14795 bf_set(lpfc_mq_context_ring_size
,
14796 &mq_create_ext
->u
.request
.context
,
14797 LPFC_MQ_RING_SIZE_128
);
14800 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
14801 memset(dmabuf
->virt
, 0, hw_page_size
);
14802 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14803 putPaddrLow(dmabuf
->phys
);
14804 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14805 putPaddrHigh(dmabuf
->phys
);
14807 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14808 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
14809 &mq_create_ext
->u
.response
);
14810 if (rc
!= MBX_SUCCESS
) {
14811 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
14812 "2795 MQ_CREATE_EXT failed with "
14813 "status x%x. Failback to MQ_CREATE.\n",
14815 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
14816 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
14817 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14818 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
14819 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
14820 &mq_create
->u
.response
);
14823 /* The IOCTL status is embedded in the mailbox subheader. */
14824 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14825 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14826 if (shdr_status
|| shdr_add_status
|| rc
) {
14827 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14828 "2502 MQ_CREATE mailbox failed with "
14829 "status x%x add_status x%x, mbx status x%x\n",
14830 shdr_status
, shdr_add_status
, rc
);
14834 if (mq
->queue_id
== 0xFFFF) {
14838 mq
->type
= LPFC_MQ
;
14839 mq
->assoc_qid
= cq
->queue_id
;
14840 mq
->subtype
= subtype
;
14841 mq
->host_index
= 0;
14843 mq
->entry_repost
= LPFC_MQ_REPOST
;
14845 /* link the mq onto the parent cq child list */
14846 list_add_tail(&mq
->list
, &cq
->child_list
);
14848 mempool_free(mbox
, phba
->mbox_mem_pool
);
14853 * lpfc_wq_create - Create a Work Queue on the HBA
14854 * @phba: HBA structure that indicates port to create a queue on.
14855 * @wq: The queue structure to use to create the work queue.
14856 * @cq: The completion queue to bind this work queue to.
14857 * @subtype: The subtype of the work queue indicating its functionality.
14859 * This function creates a work queue, as detailed in @wq, on a port, described
14860 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
14862 * The @phba struct is used to send mailbox command to HBA. The @wq struct
14863 * is used to get the entry count and entry size that are necessary to
14864 * determine the number of pages to allocate and use for this queue. The @cq
14865 * is used to indicate which completion queue to bind this work queue to. This
14866 * function will send the WQ_CREATE mailbox command to the HBA to setup the
14867 * work queue. This function is asynchronous and will wait for the mailbox
14868 * command to finish before continuing.
14870 * On success this function will return a zero. If unable to allocate enough
14871 * memory this function will return -ENOMEM. If the queue create mailbox command
14872 * fails this function will return -ENXIO.
14875 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
14876 struct lpfc_queue
*cq
, uint32_t subtype
)
14878 struct lpfc_mbx_wq_create
*wq_create
;
14879 struct lpfc_dmabuf
*dmabuf
;
14880 LPFC_MBOXQ_t
*mbox
;
14881 int rc
, length
, status
= 0;
14882 uint32_t shdr_status
, shdr_add_status
;
14883 union lpfc_sli4_cfg_shdr
*shdr
;
14884 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
14885 struct dma_address
*page
;
14886 void __iomem
*bar_memmap_p
;
14887 uint32_t db_offset
;
14888 uint16_t pci_barset
;
14889 uint8_t wq_create_version
;
14891 /* sanity check on queue memory */
14894 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
14895 hw_page_size
= wq
->page_size
;
14897 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14900 length
= (sizeof(struct lpfc_mbx_wq_create
) -
14901 sizeof(struct lpfc_sli4_cfg_mhdr
));
14902 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14903 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
14904 length
, LPFC_SLI4_MBX_EMBED
);
14905 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
14906 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
14907 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
14909 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
14912 /* wqv is the earliest version supported, NOT the latest */
14913 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14914 phba
->sli4_hba
.pc_sli4_params
.wqv
);
14916 if ((phba
->sli4_hba
.pc_sli4_params
.wqsize
& LPFC_WQ_SZ128_SUPPORT
) ||
14917 (wq
->page_size
> SLI4_PAGE_SIZE
))
14918 wq_create_version
= LPFC_Q_CREATE_VERSION_1
;
14920 wq_create_version
= LPFC_Q_CREATE_VERSION_0
;
14922 switch (wq_create_version
) {
14923 case LPFC_Q_CREATE_VERSION_0
:
14924 switch (wq
->entry_size
) {
14927 /* Nothing to do, version 0 ONLY supports 64 byte */
14928 page
= wq_create
->u
.request
.page
;
14931 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
14932 LPFC_WQ_SZ128_SUPPORT
)) {
14936 /* If we get here the HBA MUST also support V1 and
14939 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14940 LPFC_Q_CREATE_VERSION_1
);
14942 bf_set(lpfc_mbx_wq_create_wqe_count
,
14943 &wq_create
->u
.request_1
, wq
->entry_count
);
14944 bf_set(lpfc_mbx_wq_create_wqe_size
,
14945 &wq_create
->u
.request_1
,
14946 LPFC_WQ_WQE_SIZE_128
);
14947 bf_set(lpfc_mbx_wq_create_page_size
,
14948 &wq_create
->u
.request_1
,
14949 LPFC_WQ_PAGE_SIZE_4096
);
14950 page
= wq_create
->u
.request_1
.page
;
14954 case LPFC_Q_CREATE_VERSION_1
:
14955 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
14957 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14958 LPFC_Q_CREATE_VERSION_1
);
14960 switch (wq
->entry_size
) {
14963 bf_set(lpfc_mbx_wq_create_wqe_size
,
14964 &wq_create
->u
.request_1
,
14965 LPFC_WQ_WQE_SIZE_64
);
14968 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
14969 LPFC_WQ_SZ128_SUPPORT
)) {
14973 bf_set(lpfc_mbx_wq_create_wqe_size
,
14974 &wq_create
->u
.request_1
,
14975 LPFC_WQ_WQE_SIZE_128
);
14978 bf_set(lpfc_mbx_wq_create_page_size
,
14979 &wq_create
->u
.request_1
,
14980 (wq
->page_size
/ SLI4_PAGE_SIZE
));
14981 page
= wq_create
->u
.request_1
.page
;
14988 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
14989 memset(dmabuf
->virt
, 0, hw_page_size
);
14990 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
14991 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
14994 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
14995 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
14997 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14998 /* The IOCTL status is embedded in the mailbox subheader. */
14999 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15000 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15001 if (shdr_status
|| shdr_add_status
|| rc
) {
15002 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15003 "2503 WQ_CREATE mailbox failed with "
15004 "status x%x add_status x%x, mbx status x%x\n",
15005 shdr_status
, shdr_add_status
, rc
);
15009 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
15010 if (wq
->queue_id
== 0xFFFF) {
15014 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
15015 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
15016 &wq_create
->u
.response
);
15017 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
15018 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
15019 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15020 "3265 WQ[%d] doorbell format not "
15021 "supported: x%x\n", wq
->queue_id
,
15026 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
15027 &wq_create
->u
.response
);
15028 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
15029 if (!bar_memmap_p
) {
15030 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15031 "3263 WQ[%d] failed to memmap pci "
15032 "barset:x%x\n", wq
->queue_id
,
15037 db_offset
= wq_create
->u
.response
.doorbell_offset
;
15038 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
15039 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
15040 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15041 "3252 WQ[%d] doorbell offset not "
15042 "supported: x%x\n", wq
->queue_id
,
15047 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15048 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15049 "3264 WQ[%d]: barset:x%x, offset:x%x, "
15050 "format:x%x\n", wq
->queue_id
, pci_barset
,
15051 db_offset
, wq
->db_format
);
15053 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
15054 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
15056 wq
->pring
= kzalloc(sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
15057 if (wq
->pring
== NULL
) {
15061 wq
->type
= LPFC_WQ
;
15062 wq
->assoc_qid
= cq
->queue_id
;
15063 wq
->subtype
= subtype
;
15064 wq
->host_index
= 0;
15066 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
15068 /* link the wq onto the parent cq child list */
15069 list_add_tail(&wq
->list
, &cq
->child_list
);
15071 mempool_free(mbox
, phba
->mbox_mem_pool
);
15076 * lpfc_rq_create - Create a Receive Queue on the HBA
15077 * @phba: HBA structure that indicates port to create a queue on.
15078 * @hrq: The queue structure to use to create the header receive queue.
15079 * @drq: The queue structure to use to create the data receive queue.
15080 * @cq: The completion queue to bind this work queue to.
15082 * This function creates a receive buffer queue pair , as detailed in @hrq and
15083 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15086 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15087 * struct is used to get the entry count that is necessary to determine the
15088 * number of pages to use for this queue. The @cq is used to indicate which
15089 * completion queue to bind received buffers that are posted to these queues to.
15090 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15091 * receive queue pair. This function is asynchronous and will wait for the
15092 * mailbox command to finish before continuing.
15094 * On success this function will return a zero. If unable to allocate enough
15095 * memory this function will return -ENOMEM. If the queue create mailbox command
15096 * fails this function will return -ENXIO.
15099 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
15100 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
15102 struct lpfc_mbx_rq_create
*rq_create
;
15103 struct lpfc_dmabuf
*dmabuf
;
15104 LPFC_MBOXQ_t
*mbox
;
15105 int rc
, length
, status
= 0;
15106 uint32_t shdr_status
, shdr_add_status
;
15107 union lpfc_sli4_cfg_shdr
*shdr
;
15108 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15109 void __iomem
*bar_memmap_p
;
15110 uint32_t db_offset
;
15111 uint16_t pci_barset
;
15113 /* sanity check on queue memory */
15114 if (!hrq
|| !drq
|| !cq
)
15116 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15117 hw_page_size
= SLI4_PAGE_SIZE
;
15119 if (hrq
->entry_count
!= drq
->entry_count
)
15121 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15124 length
= (sizeof(struct lpfc_mbx_rq_create
) -
15125 sizeof(struct lpfc_sli4_cfg_mhdr
));
15126 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15127 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
15128 length
, LPFC_SLI4_MBX_EMBED
);
15129 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
15130 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
15131 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15132 phba
->sli4_hba
.pc_sli4_params
.rqv
);
15133 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
15134 bf_set(lpfc_rq_context_rqe_count_1
,
15135 &rq_create
->u
.request
.context
,
15137 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
15138 bf_set(lpfc_rq_context_rqe_size
,
15139 &rq_create
->u
.request
.context
,
15141 bf_set(lpfc_rq_context_page_size
,
15142 &rq_create
->u
.request
.context
,
15143 LPFC_RQ_PAGE_SIZE_4096
);
15145 switch (hrq
->entry_count
) {
15147 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15148 "2535 Unsupported RQ count. (%d)\n",
15150 if (hrq
->entry_count
< 512) {
15154 /* otherwise default to smallest count (drop through) */
15156 bf_set(lpfc_rq_context_rqe_count
,
15157 &rq_create
->u
.request
.context
,
15158 LPFC_RQ_RING_SIZE_512
);
15161 bf_set(lpfc_rq_context_rqe_count
,
15162 &rq_create
->u
.request
.context
,
15163 LPFC_RQ_RING_SIZE_1024
);
15166 bf_set(lpfc_rq_context_rqe_count
,
15167 &rq_create
->u
.request
.context
,
15168 LPFC_RQ_RING_SIZE_2048
);
15171 bf_set(lpfc_rq_context_rqe_count
,
15172 &rq_create
->u
.request
.context
,
15173 LPFC_RQ_RING_SIZE_4096
);
15176 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
15177 LPFC_HDR_BUF_SIZE
);
15179 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
15181 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
15183 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
15184 memset(dmabuf
->virt
, 0, hw_page_size
);
15185 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15186 putPaddrLow(dmabuf
->phys
);
15187 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15188 putPaddrHigh(dmabuf
->phys
);
15190 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15191 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
15193 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15194 /* The IOCTL status is embedded in the mailbox subheader. */
15195 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15196 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15197 if (shdr_status
|| shdr_add_status
|| rc
) {
15198 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15199 "2504 RQ_CREATE mailbox failed with "
15200 "status x%x add_status x%x, mbx status x%x\n",
15201 shdr_status
, shdr_add_status
, rc
);
15205 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15206 if (hrq
->queue_id
== 0xFFFF) {
15211 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
15212 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
15213 &rq_create
->u
.response
);
15214 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
15215 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
15216 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15217 "3262 RQ [%d] doorbell format not "
15218 "supported: x%x\n", hrq
->queue_id
,
15224 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
15225 &rq_create
->u
.response
);
15226 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
15227 if (!bar_memmap_p
) {
15228 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15229 "3269 RQ[%d] failed to memmap pci "
15230 "barset:x%x\n", hrq
->queue_id
,
15236 db_offset
= rq_create
->u
.response
.doorbell_offset
;
15237 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
15238 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
15239 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15240 "3270 RQ[%d] doorbell offset not "
15241 "supported: x%x\n", hrq
->queue_id
,
15246 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
15247 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15248 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
15249 "format:x%x\n", hrq
->queue_id
, pci_barset
,
15250 db_offset
, hrq
->db_format
);
15252 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
15253 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15255 hrq
->type
= LPFC_HRQ
;
15256 hrq
->assoc_qid
= cq
->queue_id
;
15257 hrq
->subtype
= subtype
;
15258 hrq
->host_index
= 0;
15259 hrq
->hba_index
= 0;
15260 hrq
->entry_repost
= LPFC_RQ_REPOST
;
15262 /* now create the data queue */
15263 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15264 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
15265 length
, LPFC_SLI4_MBX_EMBED
);
15266 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
15267 phba
->sli4_hba
.pc_sli4_params
.rqv
);
15268 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
15269 bf_set(lpfc_rq_context_rqe_count_1
,
15270 &rq_create
->u
.request
.context
, hrq
->entry_count
);
15271 if (subtype
== LPFC_NVMET
)
15272 rq_create
->u
.request
.context
.buffer_size
=
15273 LPFC_NVMET_DATA_BUF_SIZE
;
15275 rq_create
->u
.request
.context
.buffer_size
=
15276 LPFC_DATA_BUF_SIZE
;
15277 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
15279 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
15280 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
15282 switch (drq
->entry_count
) {
15284 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15285 "2536 Unsupported RQ count. (%d)\n",
15287 if (drq
->entry_count
< 512) {
15291 /* otherwise default to smallest count (drop through) */
15293 bf_set(lpfc_rq_context_rqe_count
,
15294 &rq_create
->u
.request
.context
,
15295 LPFC_RQ_RING_SIZE_512
);
15298 bf_set(lpfc_rq_context_rqe_count
,
15299 &rq_create
->u
.request
.context
,
15300 LPFC_RQ_RING_SIZE_1024
);
15303 bf_set(lpfc_rq_context_rqe_count
,
15304 &rq_create
->u
.request
.context
,
15305 LPFC_RQ_RING_SIZE_2048
);
15308 bf_set(lpfc_rq_context_rqe_count
,
15309 &rq_create
->u
.request
.context
,
15310 LPFC_RQ_RING_SIZE_4096
);
15313 if (subtype
== LPFC_NVMET
)
15314 bf_set(lpfc_rq_context_buf_size
,
15315 &rq_create
->u
.request
.context
,
15316 LPFC_NVMET_DATA_BUF_SIZE
);
15318 bf_set(lpfc_rq_context_buf_size
,
15319 &rq_create
->u
.request
.context
,
15320 LPFC_DATA_BUF_SIZE
);
15322 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
15324 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
15326 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
15327 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
15328 putPaddrLow(dmabuf
->phys
);
15329 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
15330 putPaddrHigh(dmabuf
->phys
);
15332 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
15333 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
15334 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15335 /* The IOCTL status is embedded in the mailbox subheader. */
15336 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
15337 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15338 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15339 if (shdr_status
|| shdr_add_status
|| rc
) {
15343 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15344 if (drq
->queue_id
== 0xFFFF) {
15348 drq
->type
= LPFC_DRQ
;
15349 drq
->assoc_qid
= cq
->queue_id
;
15350 drq
->subtype
= subtype
;
15351 drq
->host_index
= 0;
15352 drq
->hba_index
= 0;
15353 drq
->entry_repost
= LPFC_RQ_REPOST
;
15355 /* link the header and data RQs onto the parent cq child list */
15356 list_add_tail(&hrq
->list
, &cq
->child_list
);
15357 list_add_tail(&drq
->list
, &cq
->child_list
);
15360 mempool_free(mbox
, phba
->mbox_mem_pool
);
15365 * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
15366 * @phba: HBA structure that indicates port to create a queue on.
15367 * @hrqp: The queue structure array to use to create the header receive queues.
15368 * @drqp: The queue structure array to use to create the data receive queues.
15369 * @cqp: The completion queue array to bind these receive queues to.
15371 * This function creates a receive buffer queue pair , as detailed in @hrq and
15372 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
15375 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
15376 * struct is used to get the entry count that is necessary to determine the
15377 * number of pages to use for this queue. The @cq is used to indicate which
15378 * completion queue to bind received buffers that are posted to these queues to.
15379 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
15380 * receive queue pair. This function is asynchronous and will wait for the
15381 * mailbox command to finish before continuing.
15383 * On success this function will return a zero. If unable to allocate enough
15384 * memory this function will return -ENOMEM. If the queue create mailbox command
15385 * fails this function will return -ENXIO.
15388 lpfc_mrq_create(struct lpfc_hba
*phba
, struct lpfc_queue
**hrqp
,
15389 struct lpfc_queue
**drqp
, struct lpfc_queue
**cqp
,
15392 struct lpfc_queue
*hrq
, *drq
, *cq
;
15393 struct lpfc_mbx_rq_create_v2
*rq_create
;
15394 struct lpfc_dmabuf
*dmabuf
;
15395 LPFC_MBOXQ_t
*mbox
;
15396 int rc
, length
, alloclen
, status
= 0;
15397 int cnt
, idx
, numrq
, page_idx
= 0;
15398 uint32_t shdr_status
, shdr_add_status
;
15399 union lpfc_sli4_cfg_shdr
*shdr
;
15400 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
15402 numrq
= phba
->cfg_nvmet_mrq
;
15403 /* sanity check on array memory */
15404 if (!hrqp
|| !drqp
|| !cqp
|| !numrq
)
15406 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
15407 hw_page_size
= SLI4_PAGE_SIZE
;
15409 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15413 length
= sizeof(struct lpfc_mbx_rq_create_v2
);
15414 length
+= ((2 * numrq
* hrqp
[0]->page_count
) *
15415 sizeof(struct dma_address
));
15417 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15418 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
, length
,
15419 LPFC_SLI4_MBX_NEMBED
);
15420 if (alloclen
< length
) {
15421 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15422 "3099 Allocated DMA memory size (%d) is "
15423 "less than the requested DMA memory size "
15424 "(%d)\n", alloclen
, length
);
15431 rq_create
= mbox
->sge_array
->addr
[0];
15432 shdr
= (union lpfc_sli4_cfg_shdr
*)&rq_create
->cfg_shdr
;
15434 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_Q_CREATE_VERSION_2
);
15437 for (idx
= 0; idx
< numrq
; idx
++) {
15442 /* sanity check on queue memory */
15443 if (!hrq
|| !drq
|| !cq
) {
15448 if (hrq
->entry_count
!= drq
->entry_count
) {
15454 bf_set(lpfc_mbx_rq_create_num_pages
,
15455 &rq_create
->u
.request
,
15457 bf_set(lpfc_mbx_rq_create_rq_cnt
,
15458 &rq_create
->u
.request
, (numrq
* 2));
15459 bf_set(lpfc_mbx_rq_create_dnb
, &rq_create
->u
.request
,
15461 bf_set(lpfc_rq_context_base_cq
,
15462 &rq_create
->u
.request
.context
,
15464 bf_set(lpfc_rq_context_data_size
,
15465 &rq_create
->u
.request
.context
,
15466 LPFC_NVMET_DATA_BUF_SIZE
);
15467 bf_set(lpfc_rq_context_hdr_size
,
15468 &rq_create
->u
.request
.context
,
15469 LPFC_HDR_BUF_SIZE
);
15470 bf_set(lpfc_rq_context_rqe_count_1
,
15471 &rq_create
->u
.request
.context
,
15473 bf_set(lpfc_rq_context_rqe_size
,
15474 &rq_create
->u
.request
.context
,
15476 bf_set(lpfc_rq_context_page_size
,
15477 &rq_create
->u
.request
.context
,
15478 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
15481 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
15482 memset(dmabuf
->virt
, 0, hw_page_size
);
15483 cnt
= page_idx
+ dmabuf
->buffer_tag
;
15484 rq_create
->u
.request
.page
[cnt
].addr_lo
=
15485 putPaddrLow(dmabuf
->phys
);
15486 rq_create
->u
.request
.page
[cnt
].addr_hi
=
15487 putPaddrHigh(dmabuf
->phys
);
15493 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
15494 memset(dmabuf
->virt
, 0, hw_page_size
);
15495 cnt
= page_idx
+ dmabuf
->buffer_tag
;
15496 rq_create
->u
.request
.page
[cnt
].addr_lo
=
15497 putPaddrLow(dmabuf
->phys
);
15498 rq_create
->u
.request
.page
[cnt
].addr_hi
=
15499 putPaddrHigh(dmabuf
->phys
);
15504 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
15505 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15506 hrq
->type
= LPFC_HRQ
;
15507 hrq
->assoc_qid
= cq
->queue_id
;
15508 hrq
->subtype
= subtype
;
15509 hrq
->host_index
= 0;
15510 hrq
->hba_index
= 0;
15511 hrq
->entry_repost
= LPFC_RQ_REPOST
;
15513 drq
->db_format
= LPFC_DB_RING_FORMAT
;
15514 drq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
15515 drq
->type
= LPFC_DRQ
;
15516 drq
->assoc_qid
= cq
->queue_id
;
15517 drq
->subtype
= subtype
;
15518 drq
->host_index
= 0;
15519 drq
->hba_index
= 0;
15520 drq
->entry_repost
= LPFC_RQ_REPOST
;
15522 list_add_tail(&hrq
->list
, &cq
->child_list
);
15523 list_add_tail(&drq
->list
, &cq
->child_list
);
15526 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15527 /* The IOCTL status is embedded in the mailbox subheader. */
15528 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15529 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15530 if (shdr_status
|| shdr_add_status
|| rc
) {
15531 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15532 "3120 RQ_CREATE mailbox failed with "
15533 "status x%x add_status x%x, mbx status x%x\n",
15534 shdr_status
, shdr_add_status
, rc
);
15538 rc
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
15539 if (rc
== 0xFFFF) {
15544 /* Initialize all RQs with associated queue id */
15545 for (idx
= 0; idx
< numrq
; idx
++) {
15547 hrq
->queue_id
= rc
+ (2 * idx
);
15549 drq
->queue_id
= rc
+ (2 * idx
) + 1;
15553 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
15558 * lpfc_eq_destroy - Destroy an event Queue on the HBA
15559 * @eq: The queue structure associated with the queue to destroy.
15561 * This function destroys a queue, as detailed in @eq by sending an mailbox
15562 * command, specific to the type of queue, to the HBA.
15564 * The @eq struct is used to get the queue ID of the queue to destroy.
15566 * On success this function will return a zero. If the queue destroy mailbox
15567 * command fails this function will return -ENXIO.
15570 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
15572 LPFC_MBOXQ_t
*mbox
;
15573 int rc
, length
, status
= 0;
15574 uint32_t shdr_status
, shdr_add_status
;
15575 union lpfc_sli4_cfg_shdr
*shdr
;
15577 /* sanity check on queue memory */
15580 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15583 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
15584 sizeof(struct lpfc_sli4_cfg_mhdr
));
15585 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15586 LPFC_MBOX_OPCODE_EQ_DESTROY
,
15587 length
, LPFC_SLI4_MBX_EMBED
);
15588 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
15590 mbox
->vport
= eq
->phba
->pport
;
15591 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15593 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
15594 /* The IOCTL status is embedded in the mailbox subheader. */
15595 shdr
= (union lpfc_sli4_cfg_shdr
*)
15596 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
15597 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15598 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15599 if (shdr_status
|| shdr_add_status
|| rc
) {
15600 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15601 "2505 EQ_DESTROY mailbox failed with "
15602 "status x%x add_status x%x, mbx status x%x\n",
15603 shdr_status
, shdr_add_status
, rc
);
15607 /* Remove eq from any list */
15608 list_del_init(&eq
->list
);
15609 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
15614 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
15615 * @cq: The queue structure associated with the queue to destroy.
15617 * This function destroys a queue, as detailed in @cq by sending an mailbox
15618 * command, specific to the type of queue, to the HBA.
15620 * The @cq struct is used to get the queue ID of the queue to destroy.
15622 * On success this function will return a zero. If the queue destroy mailbox
15623 * command fails this function will return -ENXIO.
15626 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
15628 LPFC_MBOXQ_t
*mbox
;
15629 int rc
, length
, status
= 0;
15630 uint32_t shdr_status
, shdr_add_status
;
15631 union lpfc_sli4_cfg_shdr
*shdr
;
15633 /* sanity check on queue memory */
15636 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15639 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
15640 sizeof(struct lpfc_sli4_cfg_mhdr
));
15641 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15642 LPFC_MBOX_OPCODE_CQ_DESTROY
,
15643 length
, LPFC_SLI4_MBX_EMBED
);
15644 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
15646 mbox
->vport
= cq
->phba
->pport
;
15647 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15648 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
15649 /* The IOCTL status is embedded in the mailbox subheader. */
15650 shdr
= (union lpfc_sli4_cfg_shdr
*)
15651 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
15652 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15653 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15654 if (shdr_status
|| shdr_add_status
|| rc
) {
15655 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15656 "2506 CQ_DESTROY mailbox failed with "
15657 "status x%x add_status x%x, mbx status x%x\n",
15658 shdr_status
, shdr_add_status
, rc
);
15661 /* Remove cq from any list */
15662 list_del_init(&cq
->list
);
15663 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
15668 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
15669 * @qm: The queue structure associated with the queue to destroy.
15671 * This function destroys a queue, as detailed in @mq by sending an mailbox
15672 * command, specific to the type of queue, to the HBA.
15674 * The @mq struct is used to get the queue ID of the queue to destroy.
15676 * On success this function will return a zero. If the queue destroy mailbox
15677 * command fails this function will return -ENXIO.
15680 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
15682 LPFC_MBOXQ_t
*mbox
;
15683 int rc
, length
, status
= 0;
15684 uint32_t shdr_status
, shdr_add_status
;
15685 union lpfc_sli4_cfg_shdr
*shdr
;
15687 /* sanity check on queue memory */
15690 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15693 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
15694 sizeof(struct lpfc_sli4_cfg_mhdr
));
15695 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
15696 LPFC_MBOX_OPCODE_MQ_DESTROY
,
15697 length
, LPFC_SLI4_MBX_EMBED
);
15698 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
15700 mbox
->vport
= mq
->phba
->pport
;
15701 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15702 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
15703 /* The IOCTL status is embedded in the mailbox subheader. */
15704 shdr
= (union lpfc_sli4_cfg_shdr
*)
15705 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
15706 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15707 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15708 if (shdr_status
|| shdr_add_status
|| rc
) {
15709 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15710 "2507 MQ_DESTROY mailbox failed with "
15711 "status x%x add_status x%x, mbx status x%x\n",
15712 shdr_status
, shdr_add_status
, rc
);
15715 /* Remove mq from any list */
15716 list_del_init(&mq
->list
);
15717 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
15722 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
15723 * @wq: The queue structure associated with the queue to destroy.
15725 * This function destroys a queue, as detailed in @wq by sending an mailbox
15726 * command, specific to the type of queue, to the HBA.
15728 * The @wq struct is used to get the queue ID of the queue to destroy.
15730 * On success this function will return a zero. If the queue destroy mailbox
15731 * command fails this function will return -ENXIO.
15734 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
15736 LPFC_MBOXQ_t
*mbox
;
15737 int rc
, length
, status
= 0;
15738 uint32_t shdr_status
, shdr_add_status
;
15739 union lpfc_sli4_cfg_shdr
*shdr
;
15741 /* sanity check on queue memory */
15744 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15747 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
15748 sizeof(struct lpfc_sli4_cfg_mhdr
));
15749 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15750 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
15751 length
, LPFC_SLI4_MBX_EMBED
);
15752 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
15754 mbox
->vport
= wq
->phba
->pport
;
15755 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15756 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
15757 shdr
= (union lpfc_sli4_cfg_shdr
*)
15758 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
15759 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15760 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15761 if (shdr_status
|| shdr_add_status
|| rc
) {
15762 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15763 "2508 WQ_DESTROY mailbox failed with "
15764 "status x%x add_status x%x, mbx status x%x\n",
15765 shdr_status
, shdr_add_status
, rc
);
15768 /* Remove wq from any list */
15769 list_del_init(&wq
->list
);
15772 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
15777 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
15778 * @rq: The queue structure associated with the queue to destroy.
15780 * This function destroys a queue, as detailed in @rq by sending an mailbox
15781 * command, specific to the type of queue, to the HBA.
15783 * The @rq struct is used to get the queue ID of the queue to destroy.
15785 * On success this function will return a zero. If the queue destroy mailbox
15786 * command fails this function will return -ENXIO.
15789 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
15790 struct lpfc_queue
*drq
)
15792 LPFC_MBOXQ_t
*mbox
;
15793 int rc
, length
, status
= 0;
15794 uint32_t shdr_status
, shdr_add_status
;
15795 union lpfc_sli4_cfg_shdr
*shdr
;
15797 /* sanity check on queue memory */
15800 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
15803 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
15804 sizeof(struct lpfc_sli4_cfg_mhdr
));
15805 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15806 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
15807 length
, LPFC_SLI4_MBX_EMBED
);
15808 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
15810 mbox
->vport
= hrq
->phba
->pport
;
15811 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15812 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
15813 /* The IOCTL status is embedded in the mailbox subheader. */
15814 shdr
= (union lpfc_sli4_cfg_shdr
*)
15815 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
15816 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15817 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15818 if (shdr_status
|| shdr_add_status
|| rc
) {
15819 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15820 "2509 RQ_DESTROY mailbox failed with "
15821 "status x%x add_status x%x, mbx status x%x\n",
15822 shdr_status
, shdr_add_status
, rc
);
15823 if (rc
!= MBX_TIMEOUT
)
15824 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
15827 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
15829 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
15830 shdr
= (union lpfc_sli4_cfg_shdr
*)
15831 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
15832 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15833 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15834 if (shdr_status
|| shdr_add_status
|| rc
) {
15835 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15836 "2510 RQ_DESTROY mailbox failed with "
15837 "status x%x add_status x%x, mbx status x%x\n",
15838 shdr_status
, shdr_add_status
, rc
);
15841 list_del_init(&hrq
->list
);
15842 list_del_init(&drq
->list
);
15843 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
15848 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
15849 * @phba: The virtual port for which this call being executed.
15850 * @pdma_phys_addr0: Physical address of the 1st SGL page.
15851 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
15852 * @xritag: the xritag that ties this io to the SGL pages.
15854 * This routine will post the sgl pages for the IO that has the xritag
15855 * that is in the iocbq structure. The xritag is assigned during iocbq
15856 * creation and persists for as long as the driver is loaded.
15857 * if the caller has fewer than 256 scatter gather segments to map then
15858 * pdma_phys_addr1 should be 0.
15859 * If the caller needs to map more than 256 scatter gather segment then
15860 * pdma_phys_addr1 should be a valid physical address.
15861 * physical address for SGLs must be 64 byte aligned.
15862 * If you are going to map 2 SGL's then the first one must have 256 entries
15863 * the second sgl can have between 1 and 256 entries.
15867 * -ENXIO, -ENOMEM - Failure
15870 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
15871 dma_addr_t pdma_phys_addr0
,
15872 dma_addr_t pdma_phys_addr1
,
15875 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
15876 LPFC_MBOXQ_t
*mbox
;
15878 uint32_t shdr_status
, shdr_add_status
;
15880 union lpfc_sli4_cfg_shdr
*shdr
;
15882 if (xritag
== NO_XRI
) {
15883 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15884 "0364 Invalid param:\n");
15888 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15892 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15893 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
15894 sizeof(struct lpfc_mbx_post_sgl_pages
) -
15895 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
15897 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
15898 &mbox
->u
.mqe
.un
.post_sgl_pages
;
15899 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
15900 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
15902 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
15903 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
15904 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
15905 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
15907 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
15908 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
15909 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
15910 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
15911 if (!phba
->sli4_hba
.intr_enable
)
15912 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
15914 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
15915 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
15917 /* The IOCTL status is embedded in the mailbox subheader. */
15918 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
15919 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15920 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15921 if (rc
!= MBX_TIMEOUT
)
15922 mempool_free(mbox
, phba
->mbox_mem_pool
);
15923 if (shdr_status
|| shdr_add_status
|| rc
) {
15924 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15925 "2511 POST_SGL mailbox failed with "
15926 "status x%x add_status x%x, mbx status x%x\n",
15927 shdr_status
, shdr_add_status
, rc
);
15933 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
15934 * @phba: pointer to lpfc hba data structure.
15936 * This routine is invoked to post rpi header templates to the
15937 * HBA consistent with the SLI-4 interface spec. This routine
15938 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15939 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15942 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
15943 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15946 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
15951 * Fetch the next logical xri. Because this index is logical,
15952 * the driver starts at 0 each time.
15954 spin_lock_irq(&phba
->hbalock
);
15955 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
15956 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
15957 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
15958 spin_unlock_irq(&phba
->hbalock
);
15961 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
15962 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
15964 spin_unlock_irq(&phba
->hbalock
);
15969 * lpfc_sli4_free_xri - Release an xri for reuse.
15970 * @phba: pointer to lpfc hba data structure.
15972 * This routine is invoked to release an xri to the pool of
15973 * available rpis maintained by the driver.
15976 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
15978 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
15979 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
15984 * lpfc_sli4_free_xri - Release an xri for reuse.
15985 * @phba: pointer to lpfc hba data structure.
15987 * This routine is invoked to release an xri to the pool of
15988 * available rpis maintained by the driver.
15991 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
15993 spin_lock_irq(&phba
->hbalock
);
15994 __lpfc_sli4_free_xri(phba
, xri
);
15995 spin_unlock_irq(&phba
->hbalock
);
15999 * lpfc_sli4_next_xritag - Get an xritag for the io
16000 * @phba: Pointer to HBA context object.
16002 * This function gets an xritag for the iocb. If there is no unused xritag
16003 * it will return 0xffff.
16004 * The function returns the allocated xritag if successful, else returns zero.
16005 * Zero is not a valid xritag.
16006 * The caller is not required to hold any lock.
16009 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
16011 uint16_t xri_index
;
16013 xri_index
= lpfc_sli4_alloc_xri(phba
);
16014 if (xri_index
== NO_XRI
)
16015 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
16016 "2004 Failed to allocate XRI.last XRITAG is %d"
16017 " Max XRI is %d, Used XRI is %d\n",
16019 phba
->sli4_hba
.max_cfg_param
.max_xri
,
16020 phba
->sli4_hba
.max_cfg_param
.xri_used
);
16025 * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
16026 * @phba: pointer to lpfc hba data structure.
16027 * @post_sgl_list: pointer to els sgl entry list.
16028 * @count: number of els sgl entries on the list.
16030 * This routine is invoked to post a block of driver's sgl pages to the
16031 * HBA using non-embedded mailbox command. No Lock is held. This routine
16032 * is only called when the driver is loading and after all IO has been
16036 lpfc_sli4_post_sgl_list(struct lpfc_hba
*phba
,
16037 struct list_head
*post_sgl_list
,
16040 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
16041 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
16042 struct sgl_page_pairs
*sgl_pg_pairs
;
16044 LPFC_MBOXQ_t
*mbox
;
16045 uint32_t reqlen
, alloclen
, pg_pairs
;
16047 uint16_t xritag_start
= 0;
16049 uint32_t shdr_status
, shdr_add_status
;
16050 union lpfc_sli4_cfg_shdr
*shdr
;
16052 reqlen
= post_cnt
* sizeof(struct sgl_page_pairs
) +
16053 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
16054 if (reqlen
> SLI4_PAGE_SIZE
) {
16055 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16056 "2559 Block sgl registration required DMA "
16057 "size (%d) great than a page\n", reqlen
);
16061 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16065 /* Allocate DMA memory and set up the non-embedded mailbox command */
16066 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16067 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
16068 LPFC_SLI4_MBX_NEMBED
);
16070 if (alloclen
< reqlen
) {
16071 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16072 "0285 Allocated DMA memory size (%d) is "
16073 "less than the requested DMA memory "
16074 "size (%d)\n", alloclen
, reqlen
);
16075 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16078 /* Set up the SGL pages in the non-embedded DMA pages */
16079 viraddr
= mbox
->sge_array
->addr
[0];
16080 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
16081 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
16084 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
16085 /* Set up the sge entry */
16086 sgl_pg_pairs
->sgl_pg0_addr_lo
=
16087 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
16088 sgl_pg_pairs
->sgl_pg0_addr_hi
=
16089 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
16090 sgl_pg_pairs
->sgl_pg1_addr_lo
=
16091 cpu_to_le32(putPaddrLow(0));
16092 sgl_pg_pairs
->sgl_pg1_addr_hi
=
16093 cpu_to_le32(putPaddrHigh(0));
16095 /* Keep the first xritag on the list */
16097 xritag_start
= sglq_entry
->sli4_xritag
;
16102 /* Complete initialization and perform endian conversion. */
16103 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
16104 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, post_cnt
);
16105 sgl
->word0
= cpu_to_le32(sgl
->word0
);
16107 if (!phba
->sli4_hba
.intr_enable
)
16108 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16110 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16111 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16113 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
16114 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16115 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16116 if (rc
!= MBX_TIMEOUT
)
16117 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16118 if (shdr_status
|| shdr_add_status
|| rc
) {
16119 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16120 "2513 POST_SGL_BLOCK mailbox command failed "
16121 "status x%x add_status x%x mbx status x%x\n",
16122 shdr_status
, shdr_add_status
, rc
);
16129 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
16130 * @phba: pointer to lpfc hba data structure.
16131 * @sblist: pointer to scsi buffer list.
16132 * @count: number of scsi buffers on the list.
16134 * This routine is invoked to post a block of @count scsi sgl pages from a
16135 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
16140 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
16141 struct list_head
*sblist
,
16144 struct lpfc_scsi_buf
*psb
;
16145 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
16146 struct sgl_page_pairs
*sgl_pg_pairs
;
16148 LPFC_MBOXQ_t
*mbox
;
16149 uint32_t reqlen
, alloclen
, pg_pairs
;
16151 uint16_t xritag_start
= 0;
16153 uint32_t shdr_status
, shdr_add_status
;
16154 dma_addr_t pdma_phys_bpl1
;
16155 union lpfc_sli4_cfg_shdr
*shdr
;
16157 /* Calculate the requested length of the dma memory */
16158 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
16159 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
16160 if (reqlen
> SLI4_PAGE_SIZE
) {
16161 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
16162 "0217 Block sgl registration required DMA "
16163 "size (%d) great than a page\n", reqlen
);
16166 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16168 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16169 "0283 Failed to allocate mbox cmd memory\n");
16173 /* Allocate DMA memory and set up the non-embedded mailbox command */
16174 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16175 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
16176 LPFC_SLI4_MBX_NEMBED
);
16178 if (alloclen
< reqlen
) {
16179 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16180 "2561 Allocated DMA memory size (%d) is "
16181 "less than the requested DMA memory "
16182 "size (%d)\n", alloclen
, reqlen
);
16183 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16187 /* Get the first SGE entry from the non-embedded DMA memory */
16188 viraddr
= mbox
->sge_array
->addr
[0];
16190 /* Set up the SGL pages in the non-embedded DMA pages */
16191 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
16192 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
16195 list_for_each_entry(psb
, sblist
, list
) {
16196 /* Set up the sge entry */
16197 sgl_pg_pairs
->sgl_pg0_addr_lo
=
16198 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
16199 sgl_pg_pairs
->sgl_pg0_addr_hi
=
16200 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
16201 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
16202 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
16204 pdma_phys_bpl1
= 0;
16205 sgl_pg_pairs
->sgl_pg1_addr_lo
=
16206 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
16207 sgl_pg_pairs
->sgl_pg1_addr_hi
=
16208 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
16209 /* Keep the first xritag on the list */
16211 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
16215 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
16216 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
16217 /* Perform endian conversion if necessary */
16218 sgl
->word0
= cpu_to_le32(sgl
->word0
);
16220 if (!phba
->sli4_hba
.intr_enable
)
16221 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16223 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16224 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16226 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
16227 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16228 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16229 if (rc
!= MBX_TIMEOUT
)
16230 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
16231 if (shdr_status
|| shdr_add_status
|| rc
) {
16232 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16233 "2564 POST_SGL_BLOCK mailbox command failed "
16234 "status x%x add_status x%x mbx status x%x\n",
16235 shdr_status
, shdr_add_status
, rc
);
16242 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
16243 * @phba: pointer to lpfc_hba struct that the frame was received on
16244 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16246 * This function checks the fields in the @fc_hdr to see if the FC frame is a
16247 * valid type of frame that the LPFC driver will handle. This function will
16248 * return a zero if the frame is a valid frame or a non zero value when the
16249 * frame does not pass the check.
16252 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
16254 /* make rctl_names static to save stack space */
16255 struct fc_vft_header
*fc_vft_hdr
;
16256 uint32_t *header
= (uint32_t *) fc_hdr
;
16258 #define FC_RCTL_MDS_DIAGS 0xF4
16260 switch (fc_hdr
->fh_r_ctl
) {
16261 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
16262 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
16263 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
16264 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
16265 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
16266 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
16267 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
16268 case FC_RCTL_DD_CMD_STATUS
: /* command status */
16269 case FC_RCTL_ELS_REQ
: /* extended link services request */
16270 case FC_RCTL_ELS_REP
: /* extended link services reply */
16271 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
16272 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
16273 case FC_RCTL_BA_NOP
: /* basic link service NOP */
16274 case FC_RCTL_BA_ABTS
: /* basic link service abort */
16275 case FC_RCTL_BA_RMC
: /* remove connection */
16276 case FC_RCTL_BA_ACC
: /* basic accept */
16277 case FC_RCTL_BA_RJT
: /* basic reject */
16278 case FC_RCTL_BA_PRMT
:
16279 case FC_RCTL_ACK_1
: /* acknowledge_1 */
16280 case FC_RCTL_ACK_0
: /* acknowledge_0 */
16281 case FC_RCTL_P_RJT
: /* port reject */
16282 case FC_RCTL_F_RJT
: /* fabric reject */
16283 case FC_RCTL_P_BSY
: /* port busy */
16284 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
16285 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
16286 case FC_RCTL_LCR
: /* link credit reset */
16287 case FC_RCTL_MDS_DIAGS
: /* MDS Diagnostics */
16288 case FC_RCTL_END
: /* end */
16290 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
16291 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
16292 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
16293 return lpfc_fc_frame_check(phba
, fc_hdr
);
16298 #define FC_TYPE_VENDOR_UNIQUE 0xFF
16300 switch (fc_hdr
->fh_type
) {
16306 case FC_TYPE_VENDOR_UNIQUE
:
16314 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
16315 "2538 Received frame rctl:x%x, type:x%x, "
16316 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
16317 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
,
16318 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
16319 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
16320 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]),
16321 be32_to_cpu(header
[6]));
16324 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
16325 "2539 Dropped frame rctl:x%x type:x%x\n",
16326 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
16331 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
16332 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16334 * This function processes the FC header to retrieve the VFI from the VF
16335 * header, if one exists. This function will return the VFI if one exists
16336 * or 0 if no VSAN Header exists.
16339 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
16341 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
16343 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
16345 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
16349 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
16350 * @phba: Pointer to the HBA structure to search for the vport on
16351 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
16352 * @fcfi: The FC Fabric ID that the frame came from
16354 * This function searches the @phba for a vport that matches the content of the
16355 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
16356 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
16357 * returns the matching vport pointer or NULL if unable to match frame to a
16360 static struct lpfc_vport
*
16361 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
16362 uint16_t fcfi
, uint32_t did
)
16364 struct lpfc_vport
**vports
;
16365 struct lpfc_vport
*vport
= NULL
;
16368 if (did
== Fabric_DID
)
16369 return phba
->pport
;
16370 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
16371 !(phba
->link_state
== LPFC_HBA_READY
))
16372 return phba
->pport
;
16374 vports
= lpfc_create_vport_work_array(phba
);
16375 if (vports
!= NULL
) {
16376 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
16377 if (phba
->fcf
.fcfi
== fcfi
&&
16378 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
16379 vports
[i
]->fc_myDID
== did
) {
16385 lpfc_destroy_vport_work_array(phba
, vports
);
16390 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
16391 * @vport: The vport to work on.
16393 * This function updates the receive sequence time stamp for this vport. The
16394 * receive sequence time stamp indicates the time that the last frame of the
16395 * the sequence that has been idle for the longest amount of time was received.
16396 * the driver uses this time stamp to indicate if any received sequences have
16400 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
16402 struct lpfc_dmabuf
*h_buf
;
16403 struct hbq_dmabuf
*dmabuf
= NULL
;
16405 /* get the oldest sequence on the rcv list */
16406 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
16407 struct lpfc_dmabuf
, list
);
16410 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16411 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
16415 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
16416 * @vport: The vport that the received sequences were sent to.
16418 * This function cleans up all outstanding received sequences. This is called
16419 * by the driver when a link event or user action invalidates all the received
16423 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
16425 struct lpfc_dmabuf
*h_buf
, *hnext
;
16426 struct lpfc_dmabuf
*d_buf
, *dnext
;
16427 struct hbq_dmabuf
*dmabuf
= NULL
;
16429 /* start with the oldest sequence on the rcv list */
16430 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
16431 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16432 list_del_init(&dmabuf
->hbuf
.list
);
16433 list_for_each_entry_safe(d_buf
, dnext
,
16434 &dmabuf
->dbuf
.list
, list
) {
16435 list_del_init(&d_buf
->list
);
16436 lpfc_in_buf_free(vport
->phba
, d_buf
);
16438 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
16443 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
16444 * @vport: The vport that the received sequences were sent to.
16446 * This function determines whether any received sequences have timed out by
16447 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
16448 * indicates that there is at least one timed out sequence this routine will
16449 * go through the received sequences one at a time from most inactive to most
16450 * active to determine which ones need to be cleaned up. Once it has determined
16451 * that a sequence needs to be cleaned up it will simply free up the resources
16452 * without sending an abort.
16455 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
16457 struct lpfc_dmabuf
*h_buf
, *hnext
;
16458 struct lpfc_dmabuf
*d_buf
, *dnext
;
16459 struct hbq_dmabuf
*dmabuf
= NULL
;
16460 unsigned long timeout
;
16461 int abort_count
= 0;
16463 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
16464 vport
->rcv_buffer_time_stamp
);
16465 if (list_empty(&vport
->rcv_buffer_list
) ||
16466 time_before(jiffies
, timeout
))
16468 /* start with the oldest sequence on the rcv list */
16469 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
16470 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16471 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
16472 dmabuf
->time_stamp
);
16473 if (time_before(jiffies
, timeout
))
16476 list_del_init(&dmabuf
->hbuf
.list
);
16477 list_for_each_entry_safe(d_buf
, dnext
,
16478 &dmabuf
->dbuf
.list
, list
) {
16479 list_del_init(&d_buf
->list
);
16480 lpfc_in_buf_free(vport
->phba
, d_buf
);
16482 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
16485 lpfc_update_rcv_time_stamp(vport
);
16489 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
16490 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
16492 * This function searches through the existing incomplete sequences that have
16493 * been sent to this @vport. If the frame matches one of the incomplete
16494 * sequences then the dbuf in the @dmabuf is added to the list of frames that
16495 * make up that sequence. If no sequence is found that matches this frame then
16496 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
16497 * This function returns a pointer to the first dmabuf in the sequence list that
16498 * the frame was linked to.
16500 static struct hbq_dmabuf
*
16501 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
16503 struct fc_frame_header
*new_hdr
;
16504 struct fc_frame_header
*temp_hdr
;
16505 struct lpfc_dmabuf
*d_buf
;
16506 struct lpfc_dmabuf
*h_buf
;
16507 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
16508 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
16511 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
16512 dmabuf
->time_stamp
= jiffies
;
16513 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16515 /* Use the hdr_buf to find the sequence that this frame belongs to */
16516 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
16517 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
16518 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
16519 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
16520 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
16522 /* found a pending sequence that matches this frame */
16523 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16528 * This indicates first frame received for this sequence.
16529 * Queue the buffer on the vport's rcv_buffer_list.
16531 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16532 lpfc_update_rcv_time_stamp(vport
);
16535 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
16536 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
16537 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
16538 list_del_init(&seq_dmabuf
->hbuf
.list
);
16539 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16540 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
16541 lpfc_update_rcv_time_stamp(vport
);
16544 /* move this sequence to the tail to indicate a young sequence */
16545 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
16546 seq_dmabuf
->time_stamp
= jiffies
;
16547 lpfc_update_rcv_time_stamp(vport
);
16548 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
16549 temp_hdr
= dmabuf
->hbuf
.virt
;
16550 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
16553 /* find the correct place in the sequence to insert this frame */
16554 d_buf
= list_entry(seq_dmabuf
->dbuf
.list
.prev
, typeof(*d_buf
), list
);
16556 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
16557 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
16559 * If the frame's sequence count is greater than the frame on
16560 * the list then insert the frame right after this frame
16562 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
16563 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
16564 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
16569 if (&d_buf
->list
== &seq_dmabuf
->dbuf
.list
)
16571 d_buf
= list_entry(d_buf
->list
.prev
, typeof(*d_buf
), list
);
16580 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
16581 * @vport: pointer to a vitural port
16582 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16584 * This function tries to abort from the partially assembed sequence, described
16585 * by the information from basic abbort @dmabuf. It checks to see whether such
16586 * partially assembled sequence held by the driver. If so, it shall free up all
16587 * the frames from the partially assembled sequence.
16590 * true -- if there is matching partially assembled sequence present and all
16591 * the frames freed with the sequence;
16592 * false -- if there is no matching partially assembled sequence present so
16593 * nothing got aborted in the lower layer driver
16596 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
16597 struct hbq_dmabuf
*dmabuf
)
16599 struct fc_frame_header
*new_hdr
;
16600 struct fc_frame_header
*temp_hdr
;
16601 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
16602 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
16604 /* Use the hdr_buf to find the sequence that matches this frame */
16605 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
16606 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
16607 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16608 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
16609 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
16610 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
16611 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
16612 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
16614 /* found a pending sequence that matches this frame */
16615 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
16619 /* Free up all the frames from the partially assembled sequence */
16621 list_for_each_entry_safe(d_buf
, n_buf
,
16622 &seq_dmabuf
->dbuf
.list
, list
) {
16623 list_del_init(&d_buf
->list
);
16624 lpfc_in_buf_free(vport
->phba
, d_buf
);
16632 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
16633 * @vport: pointer to a vitural port
16634 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16636 * This function tries to abort from the assembed sequence from upper level
16637 * protocol, described by the information from basic abbort @dmabuf. It
16638 * checks to see whether such pending context exists at upper level protocol.
16639 * If so, it shall clean up the pending context.
16642 * true -- if there is matching pending context of the sequence cleaned
16644 * false -- if there is no matching pending context of the sequence present
16648 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
16650 struct lpfc_hba
*phba
= vport
->phba
;
16653 /* Accepting abort at ulp with SLI4 only */
16654 if (phba
->sli_rev
< LPFC_SLI_REV4
)
16657 /* Register all caring upper level protocols to attend abort */
16658 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
16666 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
16667 * @phba: Pointer to HBA context object.
16668 * @cmd_iocbq: pointer to the command iocbq structure.
16669 * @rsp_iocbq: pointer to the response iocbq structure.
16671 * This function handles the sequence abort response iocb command complete
16672 * event. It properly releases the memory allocated to the sequence abort
16676 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
16677 struct lpfc_iocbq
*cmd_iocbq
,
16678 struct lpfc_iocbq
*rsp_iocbq
)
16680 struct lpfc_nodelist
*ndlp
;
16683 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
16684 lpfc_nlp_put(ndlp
);
16685 lpfc_nlp_not_used(ndlp
);
16686 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
16689 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
16690 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
16691 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16692 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
16693 rsp_iocbq
->iocb
.ulpStatus
,
16694 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
16698 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
16699 * @phba: Pointer to HBA context object.
16700 * @xri: xri id in transaction.
16702 * This function validates the xri maps to the known range of XRIs allocated an
16703 * used by the driver.
16706 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
16711 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
16712 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
16719 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
16720 * @phba: Pointer to HBA context object.
16721 * @fc_hdr: pointer to a FC frame header.
16723 * This function sends a basic response to a previous unsol sequence abort
16724 * event after aborting the sequence handling.
16727 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
16728 struct fc_frame_header
*fc_hdr
, bool aborted
)
16730 struct lpfc_hba
*phba
= vport
->phba
;
16731 struct lpfc_iocbq
*ctiocb
= NULL
;
16732 struct lpfc_nodelist
*ndlp
;
16733 uint16_t oxid
, rxid
, xri
, lxri
;
16734 uint32_t sid
, fctl
;
16738 if (!lpfc_is_link_up(phba
))
16741 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
16742 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
16743 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
16745 ndlp
= lpfc_findnode_did(vport
, sid
);
16747 ndlp
= lpfc_nlp_init(vport
, sid
);
16749 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
16750 "1268 Failed to allocate ndlp for "
16751 "oxid:x%x SID:x%x\n", oxid
, sid
);
16754 /* Put ndlp onto pport node list */
16755 lpfc_enqueue_node(vport
, ndlp
);
16756 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
16757 /* re-setup ndlp without removing from node list */
16758 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
16760 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
16761 "3275 Failed to active ndlp found "
16762 "for oxid:x%x SID:x%x\n", oxid
, sid
);
16767 /* Allocate buffer for rsp iocb */
16768 ctiocb
= lpfc_sli_get_iocbq(phba
);
16772 /* Extract the F_CTL field from FC_HDR */
16773 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
16775 icmd
= &ctiocb
->iocb
;
16776 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
16777 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
16778 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
16779 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
16780 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
16782 /* Fill in the rest of iocb fields */
16783 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
16784 icmd
->ulpBdeCount
= 0;
16786 icmd
->ulpClass
= CLASS3
;
16787 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
16788 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
16790 ctiocb
->iocb_cmpl
= NULL
;
16791 ctiocb
->vport
= phba
->pport
;
16792 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
16793 ctiocb
->sli4_lxritag
= NO_XRI
;
16794 ctiocb
->sli4_xritag
= NO_XRI
;
16796 if (fctl
& FC_FC_EX_CTX
)
16797 /* Exchange responder sent the abort so we
16803 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
16804 if (lxri
!= NO_XRI
)
16805 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
16806 (xri
== oxid
) ? rxid
: oxid
, 0);
16807 /* For BA_ABTS from exchange responder, if the logical xri with
16808 * the oxid maps to the FCP XRI range, the port no longer has
16809 * that exchange context, send a BLS_RJT. Override the IOCB for
16812 if ((fctl
& FC_FC_EX_CTX
) &&
16813 (lxri
> lpfc_sli4_get_iocb_cnt(phba
))) {
16814 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
16815 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
16816 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
16817 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
16820 /* If BA_ABTS failed to abort a partially assembled receive sequence,
16821 * the driver no longer has that exchange, send a BLS_RJT. Override
16822 * the IOCB for a BA_RJT.
16824 if (aborted
== false) {
16825 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
16826 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
16827 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
16828 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
16831 if (fctl
& FC_FC_EX_CTX
) {
16832 /* ABTS sent by responder to CT exchange, construction
16833 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
16834 * field and RX_ID from ABTS for RX_ID field.
16836 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
16838 /* ABTS sent by initiator to CT exchange, construction
16839 * of BA_ACC will need to allocate a new XRI as for the
16842 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
16844 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
16845 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
16847 /* Xmit CT abts response on exchange <xid> */
16848 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
16849 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
16850 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
16852 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
16853 if (rc
== IOCB_ERROR
) {
16854 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
16855 "2925 Failed to issue CT ABTS RSP x%x on "
16856 "xri x%x, Data x%x\n",
16857 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
16859 lpfc_nlp_put(ndlp
);
16860 ctiocb
->context1
= NULL
;
16861 lpfc_sli_release_iocbq(phba
, ctiocb
);
16866 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
16867 * @vport: Pointer to the vport on which this sequence was received
16868 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16870 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
16871 * receive sequence is only partially assembed by the driver, it shall abort
16872 * the partially assembled frames for the sequence. Otherwise, if the
16873 * unsolicited receive sequence has been completely assembled and passed to
16874 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
16875 * unsolicited sequence has been aborted. After that, it will issue a basic
16876 * accept to accept the abort.
16879 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
16880 struct hbq_dmabuf
*dmabuf
)
16882 struct lpfc_hba
*phba
= vport
->phba
;
16883 struct fc_frame_header fc_hdr
;
16887 /* Make a copy of fc_hdr before the dmabuf being released */
16888 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
16889 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
16891 if (fctl
& FC_FC_EX_CTX
) {
16892 /* ABTS by responder to exchange, no cleanup needed */
16895 /* ABTS by initiator to exchange, need to do cleanup */
16896 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
16897 if (aborted
== false)
16898 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
16900 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
16902 if (phba
->nvmet_support
) {
16903 lpfc_nvmet_rcv_unsol_abort(vport
, &fc_hdr
);
16907 /* Respond with BA_ACC or BA_RJT accordingly */
16908 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
16912 * lpfc_seq_complete - Indicates if a sequence is complete
16913 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16915 * This function checks the sequence, starting with the frame described by
16916 * @dmabuf, to see if all the frames associated with this sequence are present.
16917 * the frames associated with this sequence are linked to the @dmabuf using the
16918 * dbuf list. This function looks for two major things. 1) That the first frame
16919 * has a sequence count of zero. 2) There is a frame with last frame of sequence
16920 * set. 3) That there are no holes in the sequence count. The function will
16921 * return 1 when the sequence is complete, otherwise it will return 0.
16924 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
16926 struct fc_frame_header
*hdr
;
16927 struct lpfc_dmabuf
*d_buf
;
16928 struct hbq_dmabuf
*seq_dmabuf
;
16932 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
16933 /* make sure first fame of sequence has a sequence count of zero */
16934 if (hdr
->fh_seq_cnt
!= seq_count
)
16936 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
16937 hdr
->fh_f_ctl
[1] << 8 |
16939 /* If last frame of sequence we can return success. */
16940 if (fctl
& FC_FC_END_SEQ
)
16942 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
16943 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
16944 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
16945 /* If there is a hole in the sequence count then fail. */
16946 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
16948 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
16949 hdr
->fh_f_ctl
[1] << 8 |
16951 /* If last frame of sequence we can return success. */
16952 if (fctl
& FC_FC_END_SEQ
)
16959 * lpfc_prep_seq - Prep sequence for ULP processing
16960 * @vport: Pointer to the vport on which this sequence was received
16961 * @dmabuf: pointer to a dmabuf that describes the FC sequence
16963 * This function takes a sequence, described by a list of frames, and creates
16964 * a list of iocbq structures to describe the sequence. This iocbq list will be
16965 * used to issue to the generic unsolicited sequence handler. This routine
16966 * returns a pointer to the first iocbq in the list. If the function is unable
16967 * to allocate an iocbq then it throw out the received frames that were not
16968 * able to be described and return a pointer to the first iocbq. If unable to
16969 * allocate any iocbqs (including the first) this function will return NULL.
16971 static struct lpfc_iocbq
*
16972 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
16974 struct hbq_dmabuf
*hbq_buf
;
16975 struct lpfc_dmabuf
*d_buf
, *n_buf
;
16976 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
16977 struct fc_frame_header
*fc_hdr
;
16979 uint32_t len
, tot_len
;
16980 struct ulp_bde64
*pbde
;
16982 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
16983 /* remove from receive buffer list */
16984 list_del_init(&seq_dmabuf
->hbuf
.list
);
16985 lpfc_update_rcv_time_stamp(vport
);
16986 /* get the Remote Port's SID */
16987 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
16989 /* Get an iocbq struct to fill in. */
16990 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
16992 /* Initialize the first IOCB. */
16993 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
16994 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
16995 first_iocbq
->vport
= vport
;
16997 /* Check FC Header to see what TYPE of frame we are rcv'ing */
16998 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
16999 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
17000 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
17001 sli4_did_from_fc_hdr(fc_hdr
);
17002 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
17004 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
17005 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
17006 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
17007 be16_to_cpu(fc_hdr
->fh_ox_id
);
17008 /* iocbq is prepped for internal consumption. Physical vpi. */
17009 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
17010 vport
->phba
->vpi_ids
[vport
->vpi
];
17011 /* put the first buffer into the first IOCBq */
17012 tot_len
= bf_get(lpfc_rcqe_length
,
17013 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17015 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
17016 first_iocbq
->context3
= NULL
;
17017 first_iocbq
->iocb
.ulpBdeCount
= 1;
17018 if (tot_len
> LPFC_DATA_BUF_SIZE
)
17019 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
17020 LPFC_DATA_BUF_SIZE
;
17022 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= tot_len
;
17024 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
17026 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
17028 iocbq
= first_iocbq
;
17030 * Each IOCBq can have two Buffers assigned, so go through the list
17031 * of buffers for this sequence and save two buffers in each IOCBq
17033 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
17035 lpfc_in_buf_free(vport
->phba
, d_buf
);
17038 if (!iocbq
->context3
) {
17039 iocbq
->context3
= d_buf
;
17040 iocbq
->iocb
.ulpBdeCount
++;
17041 /* We need to get the size out of the right CQE */
17042 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17043 len
= bf_get(lpfc_rcqe_length
,
17044 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
17045 pbde
= (struct ulp_bde64
*)
17046 &iocbq
->iocb
.unsli3
.sli3Words
[4];
17047 if (len
> LPFC_DATA_BUF_SIZE
)
17048 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
17050 pbde
->tus
.f
.bdeSize
= len
;
17052 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
17055 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
17058 first_iocbq
->iocb
.ulpStatus
=
17059 IOSTAT_FCP_RSP_ERROR
;
17060 first_iocbq
->iocb
.un
.ulpWord
[4] =
17061 IOERR_NO_RESOURCES
;
17063 lpfc_in_buf_free(vport
->phba
, d_buf
);
17066 /* We need to get the size out of the right CQE */
17067 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
17068 len
= bf_get(lpfc_rcqe_length
,
17069 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
17070 iocbq
->context2
= d_buf
;
17071 iocbq
->context3
= NULL
;
17072 iocbq
->iocb
.ulpBdeCount
= 1;
17073 if (len
> LPFC_DATA_BUF_SIZE
)
17074 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
17075 LPFC_DATA_BUF_SIZE
;
17077 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= len
;
17080 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
17082 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
17083 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
17086 return first_iocbq
;
17090 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
17091 struct hbq_dmabuf
*seq_dmabuf
)
17093 struct fc_frame_header
*fc_hdr
;
17094 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
17095 struct lpfc_hba
*phba
= vport
->phba
;
17097 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
17098 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
17100 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17101 "2707 Ring %d handler: Failed to allocate "
17102 "iocb Rctl x%x Type x%x received\n",
17104 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
17107 if (!lpfc_complete_unsol_iocb(phba
,
17108 phba
->sli4_hba
.els_wq
->pring
,
17109 iocbq
, fc_hdr
->fh_r_ctl
,
17111 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17112 "2540 Ring %d handler: unexpected Rctl "
17113 "x%x Type x%x received\n",
17115 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
17117 /* Free iocb created in lpfc_prep_seq */
17118 list_for_each_entry_safe(curr_iocb
, next_iocb
,
17119 &iocbq
->list
, list
) {
17120 list_del_init(&curr_iocb
->list
);
17121 lpfc_sli_release_iocbq(phba
, curr_iocb
);
17123 lpfc_sli_release_iocbq(phba
, iocbq
);
17127 lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
17128 struct lpfc_iocbq
*rspiocb
)
17130 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
;
17132 if (pcmd
&& pcmd
->virt
)
17133 dma_pool_free(phba
->lpfc_drb_pool
, pcmd
->virt
, pcmd
->phys
);
17135 lpfc_sli_release_iocbq(phba
, cmdiocb
);
17139 lpfc_sli4_handle_mds_loopback(struct lpfc_vport
*vport
,
17140 struct hbq_dmabuf
*dmabuf
)
17142 struct fc_frame_header
*fc_hdr
;
17143 struct lpfc_hba
*phba
= vport
->phba
;
17144 struct lpfc_iocbq
*iocbq
= NULL
;
17145 union lpfc_wqe
*wqe
;
17146 struct lpfc_dmabuf
*pcmd
= NULL
;
17147 uint32_t frame_len
;
17150 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17151 frame_len
= bf_get(lpfc_rcqe_length
, &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17153 /* Send the received frame back */
17154 iocbq
= lpfc_sli_get_iocbq(phba
);
17158 /* Allocate buffer for command payload */
17159 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
17161 pcmd
->virt
= dma_pool_alloc(phba
->lpfc_drb_pool
, GFP_KERNEL
,
17163 if (!pcmd
|| !pcmd
->virt
)
17166 INIT_LIST_HEAD(&pcmd
->list
);
17168 /* copyin the payload */
17169 memcpy(pcmd
->virt
, dmabuf
->dbuf
.virt
, frame_len
);
17171 /* fill in BDE's for command */
17172 iocbq
->iocb
.un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pcmd
->phys
);
17173 iocbq
->iocb
.un
.xseq64
.bdl
.addrLow
= putPaddrLow(pcmd
->phys
);
17174 iocbq
->iocb
.un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BDE_64
;
17175 iocbq
->iocb
.un
.xseq64
.bdl
.bdeSize
= frame_len
;
17177 iocbq
->context2
= pcmd
;
17178 iocbq
->vport
= vport
;
17179 iocbq
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
17180 iocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
17183 * Setup rest of the iocb as though it were a WQE
17184 * Build the SEND_FRAME WQE
17186 wqe
= (union lpfc_wqe
*)&iocbq
->iocb
;
17188 wqe
->send_frame
.frame_len
= frame_len
;
17189 wqe
->send_frame
.fc_hdr_wd0
= be32_to_cpu(*((uint32_t *)fc_hdr
));
17190 wqe
->send_frame
.fc_hdr_wd1
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 1));
17191 wqe
->send_frame
.fc_hdr_wd2
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 2));
17192 wqe
->send_frame
.fc_hdr_wd3
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 3));
17193 wqe
->send_frame
.fc_hdr_wd4
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 4));
17194 wqe
->send_frame
.fc_hdr_wd5
= be32_to_cpu(*((uint32_t *)fc_hdr
+ 5));
17196 iocbq
->iocb
.ulpCommand
= CMD_SEND_FRAME
;
17197 iocbq
->iocb
.ulpLe
= 1;
17198 iocbq
->iocb_cmpl
= lpfc_sli4_mds_loopback_cmpl
;
17199 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocbq
, 0);
17200 if (rc
== IOCB_ERROR
)
17203 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17207 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
17208 "2023 Unable to process MDS loopback frame\n");
17209 if (pcmd
&& pcmd
->virt
)
17210 dma_pool_free(phba
->lpfc_drb_pool
, pcmd
->virt
, pcmd
->phys
);
17213 lpfc_sli_release_iocbq(phba
, iocbq
);
17214 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17218 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
17219 * @phba: Pointer to HBA context object.
17221 * This function is called with no lock held. This function processes all
17222 * the received buffers and gives it to upper layers when a received buffer
17223 * indicates that it is the final frame in the sequence. The interrupt
17224 * service routine processes received buffers at interrupt contexts.
17225 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
17226 * appropriate receive function when the final frame in a sequence is received.
17229 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
17230 struct hbq_dmabuf
*dmabuf
)
17232 struct hbq_dmabuf
*seq_dmabuf
;
17233 struct fc_frame_header
*fc_hdr
;
17234 struct lpfc_vport
*vport
;
17238 /* Process each received buffer */
17239 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
17241 /* check to see if this a valid type of frame */
17242 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
17243 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17247 if ((bf_get(lpfc_cqe_code
,
17248 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
17249 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
17250 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17252 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
17253 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
17255 if (fc_hdr
->fh_r_ctl
== 0xF4 && fc_hdr
->fh_type
== 0xFF) {
17256 vport
= phba
->pport
;
17257 /* Handle MDS Loopback frames */
17258 lpfc_sli4_handle_mds_loopback(vport
, dmabuf
);
17262 /* d_id this frame is directed to */
17263 did
= sli4_did_from_fc_hdr(fc_hdr
);
17265 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
, did
);
17267 /* throw out the frame */
17268 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17272 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
17273 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
17274 (did
!= Fabric_DID
)) {
17276 * Throw out the frame if we are not pt2pt.
17277 * The pt2pt protocol allows for discovery frames
17278 * to be received without a registered VPI.
17280 if (!(vport
->fc_flag
& FC_PT2PT
) ||
17281 (phba
->link_state
== LPFC_HBA_READY
)) {
17282 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17287 /* Handle the basic abort sequence (BA_ABTS) event */
17288 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
17289 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
17293 /* Link this frame */
17294 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
17296 /* unable to add frame to vport - throw it out */
17297 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
17300 /* If not last frame in sequence continue processing frames. */
17301 if (!lpfc_seq_complete(seq_dmabuf
))
17304 /* Send the complete sequence to the upper layer protocol */
17305 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
17309 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
17310 * @phba: pointer to lpfc hba data structure.
17312 * This routine is invoked to post rpi header templates to the
17313 * HBA consistent with the SLI-4 interface spec. This routine
17314 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17315 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17317 * This routine does not require any locks. It's usage is expected
17318 * to be driver load or reset recovery when the driver is
17323 * -EIO - The mailbox failed to complete successfully.
17324 * When this error occurs, the driver is not guaranteed
17325 * to have any rpi regions posted to the device and
17326 * must either attempt to repost the regions or take a
17330 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
17332 struct lpfc_rpi_hdr
*rpi_page
;
17336 /* SLI4 ports that support extents do not require RPI headers. */
17337 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
17339 if (phba
->sli4_hba
.extents_in_use
)
17342 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
17344 * Assign the rpi headers a physical rpi only if the driver
17345 * has not initialized those resources. A port reset only
17346 * needs the headers posted.
17348 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
17350 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
17352 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
17353 if (rc
!= MBX_SUCCESS
) {
17354 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17355 "2008 Error %d posting all rpi "
17363 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
17364 LPFC_RPI_RSRC_RDY
);
17369 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
17370 * @phba: pointer to lpfc hba data structure.
17371 * @rpi_page: pointer to the rpi memory region.
17373 * This routine is invoked to post a single rpi header to the
17374 * HBA consistent with the SLI-4 interface spec. This memory region
17375 * maps up to 64 rpi context regions.
17379 * -ENOMEM - No available memory
17380 * -EIO - The mailbox failed to complete successfully.
17383 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
17385 LPFC_MBOXQ_t
*mboxq
;
17386 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
17388 uint32_t shdr_status
, shdr_add_status
;
17389 union lpfc_sli4_cfg_shdr
*shdr
;
17391 /* SLI4 ports that support extents do not require RPI headers. */
17392 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
17394 if (phba
->sli4_hba
.extents_in_use
)
17397 /* The port is notified of the header region via a mailbox command. */
17398 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17400 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17401 "2001 Unable to allocate memory for issuing "
17402 "SLI_CONFIG_SPECIAL mailbox command\n");
17406 /* Post all rpi memory regions to the port. */
17407 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
17408 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
17409 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
17410 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
17411 sizeof(struct lpfc_sli4_cfg_mhdr
),
17412 LPFC_SLI4_MBX_EMBED
);
17415 /* Post the physical rpi to the port for this rpi header. */
17416 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
17417 rpi_page
->start_rpi
);
17418 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
17419 hdr_tmpl
, rpi_page
->page_count
);
17421 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
17422 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
17423 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
17424 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
17425 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17426 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17427 if (rc
!= MBX_TIMEOUT
)
17428 mempool_free(mboxq
, phba
->mbox_mem_pool
);
17429 if (shdr_status
|| shdr_add_status
|| rc
) {
17430 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17431 "2514 POST_RPI_HDR mailbox failed with "
17432 "status x%x add_status x%x, mbx status x%x\n",
17433 shdr_status
, shdr_add_status
, rc
);
17437 * The next_rpi stores the next logical module-64 rpi value used
17438 * to post physical rpis in subsequent rpi postings.
17440 spin_lock_irq(&phba
->hbalock
);
17441 phba
->sli4_hba
.next_rpi
= rpi_page
->next_rpi
;
17442 spin_unlock_irq(&phba
->hbalock
);
17448 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
17449 * @phba: pointer to lpfc hba data structure.
17451 * This routine is invoked to post rpi header templates to the
17452 * HBA consistent with the SLI-4 interface spec. This routine
17453 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
17454 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
17457 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
17458 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
17461 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
17464 uint16_t max_rpi
, rpi_limit
;
17465 uint16_t rpi_remaining
, lrpi
= 0;
17466 struct lpfc_rpi_hdr
*rpi_hdr
;
17467 unsigned long iflag
;
17470 * Fetch the next logical rpi. Because this index is logical,
17471 * the driver starts at 0 each time.
17473 spin_lock_irqsave(&phba
->hbalock
, iflag
);
17474 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
17475 rpi_limit
= phba
->sli4_hba
.next_rpi
;
17477 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
17478 if (rpi
>= rpi_limit
)
17479 rpi
= LPFC_RPI_ALLOC_ERROR
;
17481 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
17482 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
17483 phba
->sli4_hba
.rpi_count
++;
17485 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
17486 "0001 rpi:%x max:%x lim:%x\n",
17487 (int) rpi
, max_rpi
, rpi_limit
);
17490 * Don't try to allocate more rpi header regions if the device limit
17491 * has been exhausted.
17493 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
17494 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
17495 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17500 * RPI header postings are not required for SLI4 ports capable of
17503 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
17504 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17509 * If the driver is running low on rpi resources, allocate another
17510 * page now. Note that the next_rpi value is used because
17511 * it represents how many are actually in use whereas max_rpi notes
17512 * how many are supported max by the device.
17514 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
17515 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
17516 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
17517 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
17519 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17520 "2002 Error Could not grow rpi "
17523 lrpi
= rpi_hdr
->start_rpi
;
17524 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
17525 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
17533 * lpfc_sli4_free_rpi - Release an rpi for reuse.
17534 * @phba: pointer to lpfc hba data structure.
17536 * This routine is invoked to release an rpi to the pool of
17537 * available rpis maintained by the driver.
17540 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
17542 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
17543 phba
->sli4_hba
.rpi_count
--;
17544 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
17549 * lpfc_sli4_free_rpi - Release an rpi for reuse.
17550 * @phba: pointer to lpfc hba data structure.
17552 * This routine is invoked to release an rpi to the pool of
17553 * available rpis maintained by the driver.
17556 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
17558 spin_lock_irq(&phba
->hbalock
);
17559 __lpfc_sli4_free_rpi(phba
, rpi
);
17560 spin_unlock_irq(&phba
->hbalock
);
17564 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
17565 * @phba: pointer to lpfc hba data structure.
17567 * This routine is invoked to remove the memory region that
17568 * provided rpi via a bitmask.
17571 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
17573 kfree(phba
->sli4_hba
.rpi_bmask
);
17574 kfree(phba
->sli4_hba
.rpi_ids
);
17575 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
17579 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
17580 * @phba: pointer to lpfc hba data structure.
17582 * This routine is invoked to remove the memory region that
17583 * provided rpi via a bitmask.
17586 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
17587 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
17589 LPFC_MBOXQ_t
*mboxq
;
17590 struct lpfc_hba
*phba
= ndlp
->phba
;
17593 /* The port is notified of the header region via a mailbox command. */
17594 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17598 /* Post all rpi memory regions to the port. */
17599 lpfc_resume_rpi(mboxq
, ndlp
);
17601 mboxq
->mbox_cmpl
= cmpl
;
17602 mboxq
->context1
= arg
;
17603 mboxq
->context2
= ndlp
;
17605 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17606 mboxq
->vport
= ndlp
->vport
;
17607 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17608 if (rc
== MBX_NOT_FINISHED
) {
17609 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17610 "2010 Resume RPI Mailbox failed "
17611 "status %d, mbxStatus x%x\n", rc
,
17612 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
17613 mempool_free(mboxq
, phba
->mbox_mem_pool
);
17620 * lpfc_sli4_init_vpi - Initialize a vpi with the port
17621 * @vport: Pointer to the vport for which the vpi is being initialized
17623 * This routine is invoked to activate a vpi with the port.
17627 * -Evalue otherwise
17630 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
17632 LPFC_MBOXQ_t
*mboxq
;
17634 int retval
= MBX_SUCCESS
;
17636 struct lpfc_hba
*phba
= vport
->phba
;
17637 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17640 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
17641 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
17642 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
17643 if (rc
!= MBX_SUCCESS
) {
17644 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
17645 "2022 INIT VPI Mailbox failed "
17646 "status %d, mbxStatus x%x\n", rc
,
17647 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
17650 if (rc
!= MBX_TIMEOUT
)
17651 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
17657 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
17658 * @phba: pointer to lpfc hba data structure.
17659 * @mboxq: Pointer to mailbox object.
17661 * This routine is invoked to manually add a single FCF record. The caller
17662 * must pass a completely initialized FCF_Record. This routine takes
17663 * care of the nonembedded mailbox operations.
17666 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
17669 union lpfc_sli4_cfg_shdr
*shdr
;
17670 uint32_t shdr_status
, shdr_add_status
;
17672 virt_addr
= mboxq
->sge_array
->addr
[0];
17673 /* The IOCTL status is embedded in the mailbox subheader. */
17674 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
17675 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17676 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17678 if ((shdr_status
|| shdr_add_status
) &&
17679 (shdr_status
!= STATUS_FCF_IN_USE
))
17680 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17681 "2558 ADD_FCF_RECORD mailbox failed with "
17682 "status x%x add_status x%x\n",
17683 shdr_status
, shdr_add_status
);
17685 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17689 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
17690 * @phba: pointer to lpfc hba data structure.
17691 * @fcf_record: pointer to the initialized fcf record to add.
17693 * This routine is invoked to manually add a single FCF record. The caller
17694 * must pass a completely initialized FCF_Record. This routine takes
17695 * care of the nonembedded mailbox operations.
17698 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
17701 LPFC_MBOXQ_t
*mboxq
;
17704 struct lpfc_mbx_sge sge
;
17705 uint32_t alloc_len
, req_len
;
17708 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17710 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17711 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
17715 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
17718 /* Allocate DMA memory and set up the non-embedded mailbox command */
17719 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
17720 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
17721 req_len
, LPFC_SLI4_MBX_NEMBED
);
17722 if (alloc_len
< req_len
) {
17723 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17724 "2523 Allocated DMA memory size (x%x) is "
17725 "less than the requested DMA memory "
17726 "size (x%x)\n", alloc_len
, req_len
);
17727 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17732 * Get the first SGE entry from the non-embedded DMA memory. This
17733 * routine only uses a single SGE.
17735 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
17736 virt_addr
= mboxq
->sge_array
->addr
[0];
17738 * Configure the FCF record for FCFI 0. This is the driver's
17739 * hardcoded default and gets used in nonFIP mode.
17741 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
17742 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
17743 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
17746 * Copy the fcf_index and the FCF Record Data. The data starts after
17747 * the FCoE header plus word10. The data copy needs to be endian
17750 bytep
+= sizeof(uint32_t);
17751 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
17752 mboxq
->vport
= phba
->pport
;
17753 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
17754 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17755 if (rc
== MBX_NOT_FINISHED
) {
17756 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17757 "2515 ADD_FCF_RECORD mailbox failed with "
17758 "status 0x%x\n", rc
);
17759 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17768 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
17769 * @phba: pointer to lpfc hba data structure.
17770 * @fcf_record: pointer to the fcf record to write the default data.
17771 * @fcf_index: FCF table entry index.
17773 * This routine is invoked to build the driver's default FCF record. The
17774 * values used are hardcoded. This routine handles memory initialization.
17778 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
17779 struct fcf_record
*fcf_record
,
17780 uint16_t fcf_index
)
17782 memset(fcf_record
, 0, sizeof(struct fcf_record
));
17783 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
17784 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
17785 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
17786 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
17787 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
17788 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
17789 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
17790 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
17791 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
17792 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
17793 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
17794 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
17795 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
17796 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
17797 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
17798 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
17799 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
17800 /* Set the VLAN bit map */
17801 if (phba
->valid_vlan
) {
17802 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
17803 = 1 << (phba
->vlan_id
% 8);
17808 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
17809 * @phba: pointer to lpfc hba data structure.
17810 * @fcf_index: FCF table entry offset.
17812 * This routine is invoked to scan the entire FCF table by reading FCF
17813 * record and processing it one at a time starting from the @fcf_index
17814 * for initial FCF discovery or fast FCF failover rediscovery.
17816 * Return 0 if the mailbox command is submitted successfully, none 0
17820 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
17823 LPFC_MBOXQ_t
*mboxq
;
17825 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
17826 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
17827 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17829 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17830 "2000 Failed to allocate mbox for "
17833 goto fail_fcf_scan
;
17835 /* Construct the read FCF record mailbox command */
17836 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
17839 goto fail_fcf_scan
;
17841 /* Issue the mailbox command asynchronously */
17842 mboxq
->vport
= phba
->pport
;
17843 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
17845 spin_lock_irq(&phba
->hbalock
);
17846 phba
->hba_flag
|= FCF_TS_INPROG
;
17847 spin_unlock_irq(&phba
->hbalock
);
17849 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17850 if (rc
== MBX_NOT_FINISHED
)
17853 /* Reset eligible FCF count for new scan */
17854 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
17855 phba
->fcf
.eligible_fcf_cnt
= 0;
17861 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17862 /* FCF scan failed, clear FCF_TS_INPROG flag */
17863 spin_lock_irq(&phba
->hbalock
);
17864 phba
->hba_flag
&= ~FCF_TS_INPROG
;
17865 spin_unlock_irq(&phba
->hbalock
);
17871 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
17872 * @phba: pointer to lpfc hba data structure.
17873 * @fcf_index: FCF table entry offset.
17875 * This routine is invoked to read an FCF record indicated by @fcf_index
17876 * and to use it for FLOGI roundrobin FCF failover.
17878 * Return 0 if the mailbox command is submitted successfully, none 0
17882 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
17885 LPFC_MBOXQ_t
*mboxq
;
17887 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17889 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
17890 "2763 Failed to allocate mbox for "
17893 goto fail_fcf_read
;
17895 /* Construct the read FCF record mailbox command */
17896 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
17899 goto fail_fcf_read
;
17901 /* Issue the mailbox command asynchronously */
17902 mboxq
->vport
= phba
->pport
;
17903 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
17904 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17905 if (rc
== MBX_NOT_FINISHED
)
17911 if (error
&& mboxq
)
17912 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17917 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
17918 * @phba: pointer to lpfc hba data structure.
17919 * @fcf_index: FCF table entry offset.
17921 * This routine is invoked to read an FCF record indicated by @fcf_index to
17922 * determine whether it's eligible for FLOGI roundrobin failover list.
17924 * Return 0 if the mailbox command is submitted successfully, none 0
17928 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
17931 LPFC_MBOXQ_t
*mboxq
;
17933 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17935 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
17936 "2758 Failed to allocate mbox for "
17939 goto fail_fcf_read
;
17941 /* Construct the read FCF record mailbox command */
17942 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
17945 goto fail_fcf_read
;
17947 /* Issue the mailbox command asynchronously */
17948 mboxq
->vport
= phba
->pport
;
17949 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
17950 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
17951 if (rc
== MBX_NOT_FINISHED
)
17957 if (error
&& mboxq
)
17958 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
17963 * lpfc_check_next_fcf_pri_level
17964 * phba pointer to the lpfc_hba struct for this port.
17965 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
17966 * routine when the rr_bmask is empty. The FCF indecies are put into the
17967 * rr_bmask based on their priority level. Starting from the highest priority
17968 * to the lowest. The most likely FCF candidate will be in the highest
17969 * priority group. When this routine is called it searches the fcf_pri list for
17970 * next lowest priority group and repopulates the rr_bmask with only those
17973 * 1=success 0=failure
17976 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
17978 uint16_t next_fcf_pri
;
17979 uint16_t last_index
;
17980 struct lpfc_fcf_pri
*fcf_pri
;
17984 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
17985 LPFC_SLI4_FCF_TBL_INDX_MAX
);
17986 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
17987 "3060 Last IDX %d\n", last_index
);
17989 /* Verify the priority list has 2 or more entries */
17990 spin_lock_irq(&phba
->hbalock
);
17991 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
17992 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
17993 spin_unlock_irq(&phba
->hbalock
);
17994 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
17995 "3061 Last IDX %d\n", last_index
);
17996 return 0; /* Empty rr list */
17998 spin_unlock_irq(&phba
->hbalock
);
18002 * Clear the rr_bmask and set all of the bits that are at this
18005 memset(phba
->fcf
.fcf_rr_bmask
, 0,
18006 sizeof(*phba
->fcf
.fcf_rr_bmask
));
18007 spin_lock_irq(&phba
->hbalock
);
18008 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
18009 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
18012 * the 1st priority that has not FLOGI failed
18013 * will be the highest.
18016 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
18017 spin_unlock_irq(&phba
->hbalock
);
18018 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
18019 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
18020 fcf_pri
->fcf_rec
.fcf_index
);
18024 spin_lock_irq(&phba
->hbalock
);
18027 * if next_fcf_pri was not set above and the list is not empty then
18028 * we have failed flogis on all of them. So reset flogi failed
18029 * and start at the beginning.
18031 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
18032 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
18033 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
18035 * the 1st priority that has not FLOGI failed
18036 * will be the highest.
18039 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
18040 spin_unlock_irq(&phba
->hbalock
);
18041 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
18042 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
18043 fcf_pri
->fcf_rec
.fcf_index
);
18047 spin_lock_irq(&phba
->hbalock
);
18051 spin_unlock_irq(&phba
->hbalock
);
18056 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
18057 * @phba: pointer to lpfc hba data structure.
18059 * This routine is to get the next eligible FCF record index in a round
18060 * robin fashion. If the next eligible FCF record index equals to the
18061 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
18062 * shall be returned, otherwise, the next eligible FCF record's index
18063 * shall be returned.
18066 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
18068 uint16_t next_fcf_index
;
18071 /* Search start from next bit of currently registered FCF index */
18072 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
18075 /* Determine the next fcf index to check */
18076 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
18077 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
18078 LPFC_SLI4_FCF_TBL_INDX_MAX
,
18081 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
18082 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18084 * If we have wrapped then we need to clear the bits that
18085 * have been tested so that we can detect when we should
18086 * change the priority level.
18088 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
18089 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
18093 /* Check roundrobin failover list empty condition */
18094 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
18095 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
18097 * If next fcf index is not found check if there are lower
18098 * Priority level fcf's in the fcf_priority list.
18099 * Set up the rr_bmask with all of the avaiable fcf bits
18100 * at that level and continue the selection process.
18102 if (lpfc_check_next_fcf_pri_level(phba
))
18103 goto initial_priority
;
18104 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
18105 "2844 No roundrobin failover FCF available\n");
18106 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
18107 return LPFC_FCOE_FCF_NEXT_NONE
;
18109 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
18110 "3063 Only FCF available idx %d, flag %x\n",
18112 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
18113 return next_fcf_index
;
18117 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
18118 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
18119 LPFC_FCF_FLOGI_FAILED
) {
18120 if (list_is_singular(&phba
->fcf
.fcf_pri_list
))
18121 return LPFC_FCOE_FCF_NEXT_NONE
;
18123 goto next_priority
;
18126 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18127 "2845 Get next roundrobin failover FCF (x%x)\n",
18130 return next_fcf_index
;
18134 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
18135 * @phba: pointer to lpfc hba data structure.
18137 * This routine sets the FCF record index in to the eligible bmask for
18138 * roundrobin failover search. It checks to make sure that the index
18139 * does not go beyond the range of the driver allocated bmask dimension
18140 * before setting the bit.
18142 * Returns 0 if the index bit successfully set, otherwise, it returns
18146 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18148 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18149 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18150 "2610 FCF (x%x) reached driver's book "
18151 "keeping dimension:x%x\n",
18152 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
18155 /* Set the eligible FCF record index bmask */
18156 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
18158 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18159 "2790 Set FCF (x%x) to roundrobin FCF failover "
18160 "bmask\n", fcf_index
);
18166 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
18167 * @phba: pointer to lpfc hba data structure.
18169 * This routine clears the FCF record index from the eligible bmask for
18170 * roundrobin failover search. It checks to make sure that the index
18171 * does not go beyond the range of the driver allocated bmask dimension
18172 * before clearing the bit.
18175 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
18177 struct lpfc_fcf_pri
*fcf_pri
, *fcf_pri_next
;
18178 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
18179 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18180 "2762 FCF (x%x) reached driver's book "
18181 "keeping dimension:x%x\n",
18182 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
18185 /* Clear the eligible FCF record index bmask */
18186 spin_lock_irq(&phba
->hbalock
);
18187 list_for_each_entry_safe(fcf_pri
, fcf_pri_next
, &phba
->fcf
.fcf_pri_list
,
18189 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
18190 list_del_init(&fcf_pri
->list
);
18194 spin_unlock_irq(&phba
->hbalock
);
18195 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
18197 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18198 "2791 Clear FCF (x%x) from roundrobin failover "
18199 "bmask\n", fcf_index
);
18203 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
18204 * @phba: pointer to lpfc hba data structure.
18206 * This routine is the completion routine for the rediscover FCF table mailbox
18207 * command. If the mailbox command returned failure, it will try to stop the
18208 * FCF rediscover wait timer.
18211 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
18213 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
18214 uint32_t shdr_status
, shdr_add_status
;
18216 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
18218 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
18219 &redisc_fcf
->header
.cfg_shdr
.response
);
18220 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
18221 &redisc_fcf
->header
.cfg_shdr
.response
);
18222 if (shdr_status
|| shdr_add_status
) {
18223 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
18224 "2746 Requesting for FCF rediscovery failed "
18225 "status x%x add_status x%x\n",
18226 shdr_status
, shdr_add_status
);
18227 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
18228 spin_lock_irq(&phba
->hbalock
);
18229 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
18230 spin_unlock_irq(&phba
->hbalock
);
18232 * CVL event triggered FCF rediscover request failed,
18233 * last resort to re-try current registered FCF entry.
18235 lpfc_retry_pport_discovery(phba
);
18237 spin_lock_irq(&phba
->hbalock
);
18238 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
18239 spin_unlock_irq(&phba
->hbalock
);
18241 * DEAD FCF event triggered FCF rediscover request
18242 * failed, last resort to fail over as a link down
18243 * to FCF registration.
18245 lpfc_sli4_fcf_dead_failthrough(phba
);
18248 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
18249 "2775 Start FCF rediscover quiescent timer\n");
18251 * Start FCF rediscovery wait timer for pending FCF
18252 * before rescan FCF record table.
18254 lpfc_fcf_redisc_wait_start_timer(phba
);
18257 mempool_free(mbox
, phba
->mbox_mem_pool
);
18261 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
18262 * @phba: pointer to lpfc hba data structure.
18264 * This routine is invoked to request for rediscovery of the entire FCF table
18268 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
18270 LPFC_MBOXQ_t
*mbox
;
18271 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
18274 /* Cancel retry delay timers to all vports before FCF rediscover */
18275 lpfc_cancel_all_vport_retry_delay_timer(phba
);
18277 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18279 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18280 "2745 Failed to allocate mbox for "
18281 "requesting FCF rediscover.\n");
18285 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
18286 sizeof(struct lpfc_sli4_cfg_mhdr
));
18287 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
18288 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
18289 length
, LPFC_SLI4_MBX_EMBED
);
18291 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
18292 /* Set count to 0 for invalidating the entire FCF database */
18293 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
18295 /* Issue the mailbox command asynchronously */
18296 mbox
->vport
= phba
->pport
;
18297 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
18298 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
18300 if (rc
== MBX_NOT_FINISHED
) {
18301 mempool_free(mbox
, phba
->mbox_mem_pool
);
18308 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
18309 * @phba: pointer to lpfc hba data structure.
18311 * This function is the failover routine as a last resort to the FCF DEAD
18312 * event when driver failed to perform fast FCF failover.
18315 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
18317 uint32_t link_state
;
18320 * Last resort as FCF DEAD event failover will treat this as
18321 * a link down, but save the link state because we don't want
18322 * it to be changed to Link Down unless it is already down.
18324 link_state
= phba
->link_state
;
18325 lpfc_linkdown(phba
);
18326 phba
->link_state
= link_state
;
18328 /* Unregister FCF if no devices connected to it */
18329 lpfc_unregister_unused_fcf(phba
);
18333 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
18334 * @phba: pointer to lpfc hba data structure.
18335 * @rgn23_data: pointer to configure region 23 data.
18337 * This function gets SLI3 port configure region 23 data through memory dump
18338 * mailbox command. When it successfully retrieves data, the size of the data
18339 * will be returned, otherwise, 0 will be returned.
18342 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
18344 LPFC_MBOXQ_t
*pmb
= NULL
;
18346 uint32_t offset
= 0;
18352 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18354 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18355 "2600 failed to allocate mailbox memory\n");
18361 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
18362 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
18364 if (rc
!= MBX_SUCCESS
) {
18365 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
18366 "2601 failed to read config "
18367 "region 23, rc 0x%x Status 0x%x\n",
18368 rc
, mb
->mbxStatus
);
18369 mb
->un
.varDmp
.word_cnt
= 0;
18372 * dump mem may return a zero when finished or we got a
18373 * mailbox error, either way we are done.
18375 if (mb
->un
.varDmp
.word_cnt
== 0)
18377 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
18378 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
18380 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
18381 rgn23_data
+ offset
,
18382 mb
->un
.varDmp
.word_cnt
);
18383 offset
+= mb
->un
.varDmp
.word_cnt
;
18384 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
18386 mempool_free(pmb
, phba
->mbox_mem_pool
);
18391 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
18392 * @phba: pointer to lpfc hba data structure.
18393 * @rgn23_data: pointer to configure region 23 data.
18395 * This function gets SLI4 port configure region 23 data through memory dump
18396 * mailbox command. When it successfully retrieves data, the size of the data
18397 * will be returned, otherwise, 0 will be returned.
18400 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
18402 LPFC_MBOXQ_t
*mboxq
= NULL
;
18403 struct lpfc_dmabuf
*mp
= NULL
;
18404 struct lpfc_mqe
*mqe
;
18405 uint32_t data_length
= 0;
18411 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18413 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18414 "3105 failed to allocate mailbox memory\n");
18418 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
18420 mqe
= &mboxq
->u
.mqe
;
18421 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
18422 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
18425 data_length
= mqe
->un
.mb_words
[5];
18426 if (data_length
== 0)
18428 if (data_length
> DMP_RGN23_SIZE
) {
18432 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
18434 mempool_free(mboxq
, phba
->mbox_mem_pool
);
18436 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
18439 return data_length
;
18443 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
18444 * @phba: pointer to lpfc hba data structure.
18446 * This function read region 23 and parse TLV for port status to
18447 * decide if the user disaled the port. If the TLV indicates the
18448 * port is disabled, the hba_flag is set accordingly.
18451 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
18453 uint8_t *rgn23_data
= NULL
;
18454 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
18455 uint32_t offset
= 0;
18457 /* Get adapter Region 23 data */
18458 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
18462 if (phba
->sli_rev
< LPFC_SLI_REV4
)
18463 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
18465 if_type
= bf_get(lpfc_sli_intf_if_type
,
18466 &phba
->sli4_hba
.sli_intf
);
18467 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
18469 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
18475 /* Check the region signature first */
18476 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
18477 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18478 "2619 Config region 23 has bad signature\n");
18483 /* Check the data structure version */
18484 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
18485 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18486 "2620 Config region 23 has bad version\n");
18491 /* Parse TLV entries in the region */
18492 while (offset
< data_size
) {
18493 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
18496 * If the TLV is not driver specific TLV or driver id is
18497 * not linux driver id, skip the record.
18499 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
18500 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
18501 (rgn23_data
[offset
+ 3] != 0)) {
18502 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18506 /* Driver found a driver specific TLV in the config region */
18507 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
18512 * Search for configured port state sub-TLV.
18514 while ((offset
< data_size
) &&
18515 (tlv_offset
< sub_tlv_len
)) {
18516 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
18521 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
18522 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18523 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
18527 /* This HBA contains PORT_STE configured */
18528 if (!rgn23_data
[offset
+ 2])
18529 phba
->hba_flag
|= LINK_DISABLED
;
18541 * lpfc_wr_object - write an object to the firmware
18542 * @phba: HBA structure that indicates port to create a queue on.
18543 * @dmabuf_list: list of dmabufs to write to the port.
18544 * @size: the total byte value of the objects to write to the port.
18545 * @offset: the current offset to be used to start the transfer.
18547 * This routine will create a wr_object mailbox command to send to the port.
18548 * the mailbox command will be constructed using the dma buffers described in
18549 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
18550 * BDEs that the imbedded mailbox can support. The @offset variable will be
18551 * used to indicate the starting offset of the transfer and will also return
18552 * the offset after the write object mailbox has completed. @size is used to
18553 * determine the end of the object and whether the eof bit should be set.
18555 * Return 0 is successful and offset will contain the the new offset to use
18556 * for the next write.
18557 * Return negative value for error cases.
18560 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
18561 uint32_t size
, uint32_t *offset
)
18563 struct lpfc_mbx_wr_object
*wr_object
;
18564 LPFC_MBOXQ_t
*mbox
;
18566 uint32_t shdr_status
, shdr_add_status
;
18568 union lpfc_sli4_cfg_shdr
*shdr
;
18569 struct lpfc_dmabuf
*dmabuf
;
18570 uint32_t written
= 0;
18572 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
18576 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
18577 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
18578 sizeof(struct lpfc_mbx_wr_object
) -
18579 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
18581 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
18582 wr_object
->u
.request
.write_offset
= *offset
;
18583 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
18584 wr_object
->u
.request
.object_name
[0] =
18585 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
18586 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
18587 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
18588 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
18590 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
18591 wr_object
->u
.request
.bde
[i
].addrHigh
=
18592 putPaddrHigh(dmabuf
->phys
);
18593 if (written
+ SLI4_PAGE_SIZE
>= size
) {
18594 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
18596 written
+= (size
- written
);
18597 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
18599 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
18601 written
+= SLI4_PAGE_SIZE
;
18605 wr_object
->u
.request
.bde_count
= i
;
18606 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
18607 if (!phba
->sli4_hba
.intr_enable
)
18608 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
18610 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
18611 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
18613 /* The IOCTL status is embedded in the mailbox subheader. */
18614 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
18615 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
18616 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
18617 if (rc
!= MBX_TIMEOUT
)
18618 mempool_free(mbox
, phba
->mbox_mem_pool
);
18619 if (shdr_status
|| shdr_add_status
|| rc
) {
18620 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
18621 "3025 Write Object mailbox failed with "
18622 "status x%x add_status x%x, mbx status x%x\n",
18623 shdr_status
, shdr_add_status
, rc
);
18626 *offset
+= wr_object
->u
.response
.actual_write_length
;
18631 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
18632 * @vport: pointer to vport data structure.
18634 * This function iterate through the mailboxq and clean up all REG_LOGIN
18635 * and REG_VPI mailbox commands associated with the vport. This function
18636 * is called when driver want to restart discovery of the vport due to
18637 * a Clear Virtual Link event.
18640 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
18642 struct lpfc_hba
*phba
= vport
->phba
;
18643 LPFC_MBOXQ_t
*mb
, *nextmb
;
18644 struct lpfc_dmabuf
*mp
;
18645 struct lpfc_nodelist
*ndlp
;
18646 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
18647 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
18648 LIST_HEAD(mbox_cmd_list
);
18649 uint8_t restart_loop
;
18651 /* Clean up internally queued mailbox commands with the vport */
18652 spin_lock_irq(&phba
->hbalock
);
18653 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
18654 if (mb
->vport
!= vport
)
18657 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
18658 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
18661 list_del(&mb
->list
);
18662 list_add_tail(&mb
->list
, &mbox_cmd_list
);
18664 /* Clean up active mailbox command with the vport */
18665 mb
= phba
->sli
.mbox_active
;
18666 if (mb
&& (mb
->vport
== vport
)) {
18667 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
18668 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
18669 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
18670 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18671 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
18672 /* Put reference count for delayed processing */
18673 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
18674 /* Unregister the RPI when mailbox complete */
18675 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
18678 /* Cleanup any mailbox completions which are not yet processed */
18681 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
18683 * If this mailox is already processed or it is
18684 * for another vport ignore it.
18686 if ((mb
->vport
!= vport
) ||
18687 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
18690 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
18691 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
18694 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
18695 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18696 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
18697 /* Unregister the RPI when mailbox complete */
18698 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
18700 spin_unlock_irq(&phba
->hbalock
);
18701 spin_lock(shost
->host_lock
);
18702 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
18703 spin_unlock(shost
->host_lock
);
18704 spin_lock_irq(&phba
->hbalock
);
18708 } while (restart_loop
);
18710 spin_unlock_irq(&phba
->hbalock
);
18712 /* Release the cleaned-up mailbox commands */
18713 while (!list_empty(&mbox_cmd_list
)) {
18714 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
18715 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
18716 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
18718 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
18721 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
18722 mb
->context2
= NULL
;
18724 spin_lock(shost
->host_lock
);
18725 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
18726 spin_unlock(shost
->host_lock
);
18727 lpfc_nlp_put(ndlp
);
18730 mempool_free(mb
, phba
->mbox_mem_pool
);
18733 /* Release the ndlp with the cleaned-up active mailbox command */
18734 if (act_mbx_ndlp
) {
18735 spin_lock(shost
->host_lock
);
18736 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
18737 spin_unlock(shost
->host_lock
);
18738 lpfc_nlp_put(act_mbx_ndlp
);
18743 * lpfc_drain_txq - Drain the txq
18744 * @phba: Pointer to HBA context object.
18746 * This function attempt to submit IOCBs on the txq
18747 * to the adapter. For SLI4 adapters, the txq contains
18748 * ELS IOCBs that have been deferred because the there
18749 * are no SGLs. This congestion can occur with large
18750 * vport counts during node discovery.
18754 lpfc_drain_txq(struct lpfc_hba
*phba
)
18756 LIST_HEAD(completions
);
18757 struct lpfc_sli_ring
*pring
;
18758 struct lpfc_iocbq
*piocbq
= NULL
;
18759 unsigned long iflags
= 0;
18760 char *fail_msg
= NULL
;
18761 struct lpfc_sglq
*sglq
;
18762 union lpfc_wqe128 wqe128
;
18763 union lpfc_wqe
*wqe
= (union lpfc_wqe
*) &wqe128
;
18764 uint32_t txq_cnt
= 0;
18766 pring
= lpfc_phba_elsring(phba
);
18767 if (unlikely(!pring
))
18770 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18771 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
18775 if (txq_cnt
> pring
->txq_max
)
18776 pring
->txq_max
= txq_cnt
;
18778 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18780 while (!list_empty(&pring
->txq
)) {
18781 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18783 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
18785 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18786 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18787 "2823 txq empty and txq_cnt is %d\n ",
18791 sglq
= __lpfc_sli_get_els_sglq(phba
, piocbq
);
18793 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
18794 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18799 /* The xri and iocb resources secured,
18800 * attempt to issue request
18802 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
18803 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
18804 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
18805 fail_msg
= "to convert bpl to sgl";
18806 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, wqe
))
18807 fail_msg
= "to convert iocb to wqe";
18808 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, wqe
))
18809 fail_msg
= " - Wq is full";
18811 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
18814 /* Failed means we can't issue and need to cancel */
18815 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
18816 "2822 IOCB failed %s iotag 0x%x "
18819 piocbq
->iotag
, piocbq
->sli4_xritag
);
18820 list_add_tail(&piocbq
->list
, &completions
);
18822 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18825 /* Cancel all the IOCBs that cannot be issued */
18826 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
18827 IOERR_SLI_ABORTED
);
18833 * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
18834 * @phba: Pointer to HBA context object.
18835 * @pwqe: Pointer to command WQE.
18836 * @sglq: Pointer to the scatter gather queue object.
18838 * This routine converts the bpl or bde that is in the WQE
18839 * to a sgl list for the sli4 hardware. The physical address
18840 * of the bpl/bde is converted back to a virtual address.
18841 * If the WQE contains a BPL then the list of BDE's is
18842 * converted to sli4_sge's. If the WQE contains a single
18843 * BDE then it is converted to a single sli_sge.
18844 * The WQE is still in cpu endianness so the contents of
18845 * the bpl can be used without byte swapping.
18847 * Returns valid XRI = Success, NO_XRI = Failure.
18850 lpfc_wqe_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*pwqeq
,
18851 struct lpfc_sglq
*sglq
)
18853 uint16_t xritag
= NO_XRI
;
18854 struct ulp_bde64
*bpl
= NULL
;
18855 struct ulp_bde64 bde
;
18856 struct sli4_sge
*sgl
= NULL
;
18857 struct lpfc_dmabuf
*dmabuf
;
18858 union lpfc_wqe
*wqe
;
18861 uint32_t offset
= 0; /* accumulated offset in the sg request list */
18862 int inbound
= 0; /* number of sg reply entries inbound from firmware */
18865 if (!pwqeq
|| !sglq
)
18868 sgl
= (struct sli4_sge
*)sglq
->sgl
;
18870 pwqeq
->iocb
.ulpIoTag
= pwqeq
->iotag
;
18872 cmd
= bf_get(wqe_cmnd
, &wqe
->generic
.wqe_com
);
18873 if (cmd
== CMD_XMIT_BLS_RSP64_WQE
)
18874 return sglq
->sli4_xritag
;
18875 numBdes
= pwqeq
->rsvd2
;
18877 /* The addrHigh and addrLow fields within the WQE
18878 * have not been byteswapped yet so there is no
18879 * need to swap them back.
18881 if (pwqeq
->context3
)
18882 dmabuf
= (struct lpfc_dmabuf
*)pwqeq
->context3
;
18886 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
18890 for (i
= 0; i
< numBdes
; i
++) {
18891 /* Should already be byte swapped. */
18892 sgl
->addr_hi
= bpl
->addrHigh
;
18893 sgl
->addr_lo
= bpl
->addrLow
;
18895 sgl
->word2
= le32_to_cpu(sgl
->word2
);
18896 if ((i
+1) == numBdes
)
18897 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
18899 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
18900 /* swap the size field back to the cpu so we
18901 * can assign it to the sgl.
18903 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
18904 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
18905 /* The offsets in the sgl need to be accumulated
18906 * separately for the request and reply lists.
18907 * The request is always first, the reply follows.
18910 case CMD_GEN_REQUEST64_WQE
:
18911 /* add up the reply sg entries */
18912 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
18914 /* first inbound? reset the offset */
18917 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
18918 bf_set(lpfc_sli4_sge_type
, sgl
,
18919 LPFC_SGE_TYPE_DATA
);
18920 offset
+= bde
.tus
.f
.bdeSize
;
18922 case CMD_FCP_TRSP64_WQE
:
18923 bf_set(lpfc_sli4_sge_offset
, sgl
, 0);
18924 bf_set(lpfc_sli4_sge_type
, sgl
,
18925 LPFC_SGE_TYPE_DATA
);
18927 case CMD_FCP_TSEND64_WQE
:
18928 case CMD_FCP_TRECEIVE64_WQE
:
18929 bf_set(lpfc_sli4_sge_type
, sgl
,
18930 bpl
->tus
.f
.bdeFlags
);
18934 offset
+= bde
.tus
.f
.bdeSize
;
18935 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
18938 sgl
->word2
= cpu_to_le32(sgl
->word2
);
18942 } else if (wqe
->gen_req
.bde
.tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64
) {
18943 /* The addrHigh and addrLow fields of the BDE have not
18944 * been byteswapped yet so they need to be swapped
18945 * before putting them in the sgl.
18947 sgl
->addr_hi
= cpu_to_le32(wqe
->gen_req
.bde
.addrHigh
);
18948 sgl
->addr_lo
= cpu_to_le32(wqe
->gen_req
.bde
.addrLow
);
18949 sgl
->word2
= le32_to_cpu(sgl
->word2
);
18950 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
18951 sgl
->word2
= cpu_to_le32(sgl
->word2
);
18952 sgl
->sge_len
= cpu_to_le32(wqe
->gen_req
.bde
.tus
.f
.bdeSize
);
18954 return sglq
->sli4_xritag
;
18958 * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
18959 * @phba: Pointer to HBA context object.
18960 * @ring_number: Base sli ring number
18961 * @pwqe: Pointer to command WQE.
18964 lpfc_sli4_issue_wqe(struct lpfc_hba
*phba
, uint32_t ring_number
,
18965 struct lpfc_iocbq
*pwqe
)
18967 union lpfc_wqe
*wqe
= &pwqe
->wqe
;
18968 struct lpfc_nvmet_rcv_ctx
*ctxp
;
18969 struct lpfc_queue
*wq
;
18970 struct lpfc_sglq
*sglq
;
18971 struct lpfc_sli_ring
*pring
;
18972 unsigned long iflags
;
18975 /* NVME_LS and NVME_LS ABTS requests. */
18976 if (pwqe
->iocb_flag
& LPFC_IO_NVME_LS
) {
18977 pring
= phba
->sli4_hba
.nvmels_wq
->pring
;
18978 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
18979 sglq
= __lpfc_sli_get_els_sglq(phba
, pwqe
);
18981 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18984 pwqe
->sli4_lxritag
= sglq
->sli4_lxritag
;
18985 pwqe
->sli4_xritag
= sglq
->sli4_xritag
;
18986 if (lpfc_wqe_bpl2sgl(phba
, pwqe
, sglq
) == NO_XRI
) {
18987 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18990 bf_set(wqe_xri_tag
, &pwqe
->wqe
.xmit_bls_rsp
.wqe_com
,
18991 pwqe
->sli4_xritag
);
18992 ret
= lpfc_sli4_wq_put(phba
->sli4_hba
.nvmels_wq
, wqe
);
18994 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
18998 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
18999 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19003 /* NVME_FCREQ and NVME_ABTS requests */
19004 if (pwqe
->iocb_flag
& LPFC_IO_NVME
) {
19005 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19006 pring
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
]->pring
;
19008 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19009 wq
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
];
19010 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
,
19011 phba
->sli4_hba
.nvme_cq
[pwqe
->hba_wqidx
]->queue_id
);
19012 ret
= lpfc_sli4_wq_put(wq
, wqe
);
19014 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19017 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
19018 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19022 /* NVMET requests */
19023 if (pwqe
->iocb_flag
& LPFC_IO_NVMET
) {
19024 /* Get the IO distribution (hba_wqidx) for WQ assignment. */
19025 pring
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
]->pring
;
19027 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
19028 ctxp
= pwqe
->context2
;
19029 sglq
= ctxp
->ctxbuf
->sglq
;
19030 if (pwqe
->sli4_xritag
== NO_XRI
) {
19031 pwqe
->sli4_lxritag
= sglq
->sli4_lxritag
;
19032 pwqe
->sli4_xritag
= sglq
->sli4_xritag
;
19034 bf_set(wqe_xri_tag
, &pwqe
->wqe
.xmit_bls_rsp
.wqe_com
,
19035 pwqe
->sli4_xritag
);
19036 wq
= phba
->sli4_hba
.nvme_wq
[pwqe
->hba_wqidx
];
19037 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
,
19038 phba
->sli4_hba
.nvme_cq
[pwqe
->hba_wqidx
]->queue_id
);
19039 ret
= lpfc_sli4_wq_put(wq
, wqe
);
19041 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
19044 lpfc_sli_ringtxcmpl_put(phba
, pring
, pwqe
);
19045 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);