1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/lockdep.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_cmnd.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/fc/fc_fs.h>
35 #include <linux/aer.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_debugfs.h"
49 #include "lpfc_vport.h"
51 /* There are only four IOCB completion types. */
52 typedef enum _lpfc_iocb_type
{
60 /* Provide function prototypes local to this module. */
61 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
63 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
64 uint8_t *, uint32_t *);
65 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
67 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
69 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*, struct lpfc_queue
*,
71 static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*, struct list_head
*,
73 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*, struct lpfc_eqe
*,
75 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
);
76 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
);
79 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
85 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
86 * @q: The Work Queue to operate on.
87 * @wqe: The work Queue Entry to put on the Work queue.
89 * This routine will copy the contents of @wqe to the next available entry on
90 * the @q. This function will then ring the Work Queue Doorbell to signal the
91 * HBA to start processing the Work Queue Entry. This function returns 0 if
92 * successful. If no entries are available on @q then this function will return
94 * The caller is expected to hold the hbalock when calling this routine.
97 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
99 union lpfc_wqe
*temp_wqe
;
100 struct lpfc_register doorbell
;
104 /* sanity check on queue memory */
107 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
109 /* If the host has not yet processed the next entry then we are done */
110 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
111 if (idx
== q
->hba_index
) {
116 /* set consumption flag every once in a while */
117 if (!((q
->host_index
+ 1) % q
->entry_repost
))
118 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
119 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
120 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
121 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
123 /* Update the host index before invoking device */
124 host_index
= q
->host_index
;
130 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
131 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
132 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
, host_index
);
133 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
134 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
135 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
136 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
140 writel(doorbell
.word0
, q
->db_regaddr
);
146 * lpfc_sli4_wq_release - Updates internal hba index for WQ
147 * @q: The Work Queue to operate on.
148 * @index: The index to advance the hba index to.
150 * This routine will update the HBA index of a queue to reflect consumption of
151 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
152 * an entry the host calls this function to update the queue's internal
153 * pointers. This routine returns the number of entries that were consumed by
157 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
159 uint32_t released
= 0;
161 /* sanity check on queue memory */
165 if (q
->hba_index
== index
)
168 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
170 } while (q
->hba_index
!= index
);
175 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
176 * @q: The Mailbox Queue to operate on.
177 * @wqe: The Mailbox Queue Entry to put on the Work queue.
179 * This routine will copy the contents of @mqe to the next available entry on
180 * the @q. This function will then ring the Work Queue Doorbell to signal the
181 * HBA to start processing the Work Queue Entry. This function returns 0 if
182 * successful. If no entries are available on @q then this function will return
184 * The caller is expected to hold the hbalock when calling this routine.
187 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
189 struct lpfc_mqe
*temp_mqe
;
190 struct lpfc_register doorbell
;
192 /* sanity check on queue memory */
195 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
197 /* If the host has not yet processed the next entry then we are done */
198 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
200 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
201 /* Save off the mailbox pointer for completion */
202 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
204 /* Update the host index before invoking device */
205 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
209 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
210 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
211 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
216 * lpfc_sli4_mq_release - Updates internal hba index for MQ
217 * @q: The Mailbox Queue to operate on.
219 * This routine will update the HBA index of a queue to reflect consumption of
220 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
221 * an entry the host calls this function to update the queue's internal
222 * pointers. This routine returns the number of entries that were consumed by
226 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
228 /* sanity check on queue memory */
232 /* Clear the mailbox pointer for completion */
233 q
->phba
->mbox
= NULL
;
234 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
239 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
240 * @q: The Event Queue to get the first valid EQE from
242 * This routine will get the first valid Event Queue Entry from @q, update
243 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
244 * the Queue (no more work to do), or the Queue is full of EQEs that have been
245 * processed, but not popped back to the HBA then this routine will return NULL.
247 static struct lpfc_eqe
*
248 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
250 struct lpfc_eqe
*eqe
;
253 /* sanity check on queue memory */
256 eqe
= q
->qe
[q
->hba_index
].eqe
;
258 /* If the next EQE is not valid then we are done */
259 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
261 /* If the host has not yet processed the next entry then we are done */
262 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
263 if (idx
== q
->host_index
)
269 * insert barrier for instruction interlock : data from the hardware
270 * must have the valid bit checked before it can be copied and acted
271 * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
272 * instructions allowing action on content before valid bit checked,
273 * add barrier here as well. May not be needed as "content" is a
274 * single 32-bit entity here (vs multi word structure for cq's).
281 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
282 * @q: The Event Queue to disable interrupts
286 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
288 struct lpfc_register doorbell
;
291 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
292 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
293 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
294 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
295 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
296 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
300 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
301 * @q: The Event Queue that the host has completed processing for.
302 * @arm: Indicates whether the host wants to arms this CQ.
304 * This routine will mark all Event Queue Entries on @q, from the last
305 * known completed entry to the last entry that was processed, as completed
306 * by clearing the valid bit for each completion queue entry. Then it will
307 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
308 * The internal host index in the @q will be updated by this routine to indicate
309 * that the host has finished processing the entries. The @arm parameter
310 * indicates that the queue should be rearmed when ringing the doorbell.
312 * This function will return the number of EQEs that were popped.
315 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
317 uint32_t released
= 0;
318 struct lpfc_eqe
*temp_eqe
;
319 struct lpfc_register doorbell
;
321 /* sanity check on queue memory */
325 /* while there are valid entries */
326 while (q
->hba_index
!= q
->host_index
) {
327 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
328 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
330 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
332 if (unlikely(released
== 0 && !arm
))
335 /* ring doorbell for number popped */
338 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
339 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
341 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
342 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
343 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
344 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
345 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
346 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
347 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
348 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
349 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
354 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
355 * @q: The Completion Queue to get the first valid CQE from
357 * This routine will get the first valid Completion Queue Entry from @q, update
358 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
359 * the Queue (no more work to do), or the Queue is full of CQEs that have been
360 * processed, but not popped back to the HBA then this routine will return NULL.
362 static struct lpfc_cqe
*
363 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
365 struct lpfc_cqe
*cqe
;
368 /* sanity check on queue memory */
372 /* If the next CQE is not valid then we are done */
373 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
375 /* If the host has not yet processed the next entry then we are done */
376 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
377 if (idx
== q
->host_index
)
380 cqe
= q
->qe
[q
->hba_index
].cqe
;
384 * insert barrier for instruction interlock : data from the hardware
385 * must have the valid bit checked before it can be copied and acted
386 * upon. Speculative instructions were allowing a bcopy at the start
387 * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
388 * after our return, to copy data before the valid bit check above
389 * was done. As such, some of the copied data was stale. The barrier
390 * ensures the check is before any data is copied.
397 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
398 * @q: The Completion Queue that the host has completed processing for.
399 * @arm: Indicates whether the host wants to arms this CQ.
401 * This routine will mark all Completion queue entries on @q, from the last
402 * known completed entry to the last entry that was processed, as completed
403 * by clearing the valid bit for each completion queue entry. Then it will
404 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
405 * The internal host index in the @q will be updated by this routine to indicate
406 * that the host has finished processing the entries. The @arm parameter
407 * indicates that the queue should be rearmed when ringing the doorbell.
409 * This function will return the number of CQEs that were released.
412 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
414 uint32_t released
= 0;
415 struct lpfc_cqe
*temp_qe
;
416 struct lpfc_register doorbell
;
418 /* sanity check on queue memory */
421 /* while there are valid entries */
422 while (q
->hba_index
!= q
->host_index
) {
423 temp_qe
= q
->qe
[q
->host_index
].cqe
;
424 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
426 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
428 if (unlikely(released
== 0 && !arm
))
431 /* ring doorbell for number popped */
434 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
435 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
436 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
437 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
438 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
439 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
440 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
445 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
446 * @q: The Header Receive Queue to operate on.
447 * @wqe: The Receive Queue Entry to put on the Receive queue.
449 * This routine will copy the contents of @wqe to the next available entry on
450 * the @q. This function will then ring the Receive Queue Doorbell to signal the
451 * HBA to start processing the Receive Queue Entry. This function returns the
452 * index that the rqe was copied to if successful. If no entries are available
453 * on @q then this function will return -ENOMEM.
454 * The caller is expected to hold the hbalock when calling this routine.
457 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
458 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
460 struct lpfc_rqe
*temp_hrqe
;
461 struct lpfc_rqe
*temp_drqe
;
462 struct lpfc_register doorbell
;
465 /* sanity check on queue memory */
466 if (unlikely(!hq
) || unlikely(!dq
))
468 put_index
= hq
->host_index
;
469 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
470 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
472 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
474 if (hq
->host_index
!= dq
->host_index
)
476 /* If the host has not yet processed the next entry then we are done */
477 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
479 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
480 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
482 /* Update the host index to point to the next slot */
483 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
484 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
486 /* Ring The Header Receive Queue Doorbell */
487 if (!(hq
->host_index
% hq
->entry_repost
)) {
489 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
490 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
492 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
493 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
494 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
496 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
498 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
502 writel(doorbell
.word0
, hq
->db_regaddr
);
508 * lpfc_sli4_rq_release - Updates internal hba index for RQ
509 * @q: The Header Receive Queue to operate on.
511 * This routine will update the HBA index of a queue to reflect consumption of
512 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
513 * consumed an entry the host calls this function to update the queue's
514 * internal pointers. This routine returns the number of entries that were
515 * consumed by the HBA.
518 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
520 /* sanity check on queue memory */
521 if (unlikely(!hq
) || unlikely(!dq
))
524 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
526 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
527 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
532 * lpfc_cmd_iocb - Get next command iocb entry in the ring
533 * @phba: Pointer to HBA context object.
534 * @pring: Pointer to driver SLI ring object.
536 * This function returns pointer to next command iocb entry
537 * in the command ring. The caller must hold hbalock to prevent
538 * other threads consume the next command iocb.
539 * SLI-2/SLI-3 provide different sized iocbs.
541 static inline IOCB_t
*
542 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
544 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
545 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
549 * lpfc_resp_iocb - Get next response iocb entry in the ring
550 * @phba: Pointer to HBA context object.
551 * @pring: Pointer to driver SLI ring object.
553 * This function returns pointer to next response iocb entry
554 * in the response ring. The caller must hold hbalock to make sure
555 * that no other thread consume the next response iocb.
556 * SLI-2/SLI-3 provide different sized iocbs.
558 static inline IOCB_t
*
559 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
561 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
562 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
566 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
567 * @phba: Pointer to HBA context object.
569 * This function is called with hbalock held. This function
570 * allocates a new driver iocb object from the iocb pool. If the
571 * allocation is successful, it returns pointer to the newly
572 * allocated iocb object else it returns NULL.
575 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
577 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
578 struct lpfc_iocbq
* iocbq
= NULL
;
580 lockdep_assert_held(&phba
->hbalock
);
582 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
585 if (phba
->iocb_cnt
> phba
->iocb_max
)
586 phba
->iocb_max
= phba
->iocb_cnt
;
591 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
592 * @phba: Pointer to HBA context object.
593 * @xritag: XRI value.
595 * This function clears the sglq pointer from the array of acive
596 * sglq's. The xritag that is passed in is used to index into the
597 * array. Before the xritag can be used it needs to be adjusted
598 * by subtracting the xribase.
600 * Returns sglq ponter = success, NULL = Failure.
602 static struct lpfc_sglq
*
603 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
605 struct lpfc_sglq
*sglq
;
607 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
608 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
613 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
614 * @phba: Pointer to HBA context object.
615 * @xritag: XRI value.
617 * This function returns the sglq pointer from the array of acive
618 * sglq's. The xritag that is passed in is used to index into the
619 * array. Before the xritag can be used it needs to be adjusted
620 * by subtracting the xribase.
622 * Returns sglq ponter = success, NULL = Failure.
625 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
627 struct lpfc_sglq
*sglq
;
629 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
634 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
635 * @phba: Pointer to HBA context object.
636 * @xritag: xri used in this exchange.
637 * @rrq: The RRQ to be cleared.
641 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
643 struct lpfc_node_rrq
*rrq
)
645 struct lpfc_nodelist
*ndlp
= NULL
;
647 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
648 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
650 /* The target DID could have been swapped (cable swap)
651 * we should use the ndlp from the findnode if it is
654 if ((!ndlp
) && rrq
->ndlp
)
660 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
)) {
663 rrq
->rrq_stop_time
= 0;
666 mempool_free(rrq
, phba
->rrq_pool
);
670 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
671 * @phba: Pointer to HBA context object.
673 * This function is called with hbalock held. This function
674 * Checks if stop_time (ratov from setting rrq active) has
675 * been reached, if it has and the send_rrq flag is set then
676 * it will call lpfc_send_rrq. If the send_rrq flag is not set
677 * then it will just call the routine to clear the rrq and
678 * free the rrq resource.
679 * The timer is set to the next rrq that is going to expire before
680 * leaving the routine.
684 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
686 struct lpfc_node_rrq
*rrq
;
687 struct lpfc_node_rrq
*nextrrq
;
688 unsigned long next_time
;
689 unsigned long iflags
;
692 spin_lock_irqsave(&phba
->hbalock
, iflags
);
693 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
694 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
695 list_for_each_entry_safe(rrq
, nextrrq
,
696 &phba
->active_rrq_list
, list
) {
697 if (time_after(jiffies
, rrq
->rrq_stop_time
))
698 list_move(&rrq
->list
, &send_rrq
);
699 else if (time_before(rrq
->rrq_stop_time
, next_time
))
700 next_time
= rrq
->rrq_stop_time
;
702 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
703 if ((!list_empty(&phba
->active_rrq_list
)) &&
704 (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
705 mod_timer(&phba
->rrq_tmr
, next_time
);
706 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
707 list_del(&rrq
->list
);
709 /* this call will free the rrq */
710 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
711 else if (lpfc_send_rrq(phba
, rrq
)) {
712 /* if we send the rrq then the completion handler
713 * will clear the bit in the xribitmap.
715 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
722 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
723 * @vport: Pointer to vport context object.
724 * @xri: The xri used in the exchange.
725 * @did: The targets DID for this exchange.
727 * returns NULL = rrq not found in the phba->active_rrq_list.
728 * rrq = rrq for this xri and target.
730 struct lpfc_node_rrq
*
731 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
733 struct lpfc_hba
*phba
= vport
->phba
;
734 struct lpfc_node_rrq
*rrq
;
735 struct lpfc_node_rrq
*nextrrq
;
736 unsigned long iflags
;
738 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
740 spin_lock_irqsave(&phba
->hbalock
, iflags
);
741 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
742 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
743 rrq
->nlp_DID
== did
){
744 list_del(&rrq
->list
);
745 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
749 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
754 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
755 * @vport: Pointer to vport context object.
756 * @ndlp: Pointer to the lpfc_node_list structure.
757 * If ndlp is NULL Remove all active RRQs for this vport from the
758 * phba->active_rrq_list and clear the rrq.
759 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
762 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
765 struct lpfc_hba
*phba
= vport
->phba
;
766 struct lpfc_node_rrq
*rrq
;
767 struct lpfc_node_rrq
*nextrrq
;
768 unsigned long iflags
;
771 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
774 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
775 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
777 spin_lock_irqsave(&phba
->hbalock
, iflags
);
778 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
779 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
780 list_move(&rrq
->list
, &rrq_list
);
781 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
783 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
784 list_del(&rrq
->list
);
785 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
790 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
791 * @phba: Pointer to HBA context object.
792 * @ndlp: Targets nodelist pointer for this exchange.
793 * @xritag the xri in the bitmap to test.
795 * This function is called with hbalock held. This function
796 * returns 0 = rrq not active for this xri
797 * 1 = rrq is valid for this xri.
800 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
803 lockdep_assert_held(&phba
->hbalock
);
806 if (!ndlp
->active_rrqs_xri_bitmap
)
808 if (test_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
815 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
816 * @phba: Pointer to HBA context object.
817 * @ndlp: nodelist pointer for this target.
818 * @xritag: xri used in this exchange.
819 * @rxid: Remote Exchange ID.
820 * @send_rrq: Flag used to determine if we should send rrq els cmd.
822 * This function takes the hbalock.
823 * The active bit is always set in the active rrq xri_bitmap even
824 * if there is no slot avaiable for the other rrq information.
826 * returns 0 rrq actived for this xri
827 * < 0 No memory or invalid ndlp.
830 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
831 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
833 unsigned long iflags
;
834 struct lpfc_node_rrq
*rrq
;
840 if (!phba
->cfg_enable_rrq
)
843 spin_lock_irqsave(&phba
->hbalock
, iflags
);
844 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
845 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
850 * set the active bit even if there is no mem available.
852 if (NLP_CHK_FREE_REQ(ndlp
))
855 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
858 if (!ndlp
->active_rrqs_xri_bitmap
)
861 if (test_and_set_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
864 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
865 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
867 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
868 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
869 " DID:0x%x Send:%d\n",
870 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
873 if (phba
->cfg_enable_rrq
== 1)
874 rrq
->send_rrq
= send_rrq
;
877 rrq
->xritag
= xritag
;
878 rrq
->rrq_stop_time
= jiffies
+
879 msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
881 rrq
->nlp_DID
= ndlp
->nlp_DID
;
882 rrq
->vport
= ndlp
->vport
;
884 spin_lock_irqsave(&phba
->hbalock
, iflags
);
885 empty
= list_empty(&phba
->active_rrq_list
);
886 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
887 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
889 lpfc_worker_wake_up(phba
);
890 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
893 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
894 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
895 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
896 " DID:0x%x Send:%d\n",
897 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
902 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
903 * @phba: Pointer to HBA context object.
904 * @piocb: Pointer to the iocbq.
906 * This function is called with the ring lock held. This function
907 * gets a new driver sglq object from the sglq list. If the
908 * list is not empty then it is successful, it returns pointer to the newly
909 * allocated sglq object else it returns NULL.
911 static struct lpfc_sglq
*
912 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
914 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
915 struct lpfc_sglq
*sglq
= NULL
;
916 struct lpfc_sglq
*start_sglq
= NULL
;
917 struct lpfc_scsi_buf
*lpfc_cmd
;
918 struct lpfc_nodelist
*ndlp
;
921 lockdep_assert_held(&phba
->hbalock
);
923 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
924 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
925 ndlp
= lpfc_cmd
->rdata
->pnode
;
926 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
927 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
928 ndlp
= piocbq
->context_un
.ndlp
;
929 } else if (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
) {
930 if (piocbq
->iocb_flag
& LPFC_IO_LOOPBACK
)
933 ndlp
= piocbq
->context_un
.ndlp
;
935 ndlp
= piocbq
->context1
;
938 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
943 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_lxritag
)) {
944 /* This xri has an rrq outstanding for this DID.
945 * put it back in the list and get another xri.
947 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
949 list_remove_head(lpfc_sgl_list
, sglq
,
950 struct lpfc_sglq
, list
);
951 if (sglq
== start_sglq
) {
959 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
960 sglq
->state
= SGL_ALLOCATED
;
966 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
967 * @phba: Pointer to HBA context object.
969 * This function is called with no lock held. This function
970 * allocates a new driver iocb object from the iocb pool. If the
971 * allocation is successful, it returns pointer to the newly
972 * allocated iocb object else it returns NULL.
975 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
977 struct lpfc_iocbq
* iocbq
= NULL
;
978 unsigned long iflags
;
980 spin_lock_irqsave(&phba
->hbalock
, iflags
);
981 iocbq
= __lpfc_sli_get_iocbq(phba
);
982 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
987 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
988 * @phba: Pointer to HBA context object.
989 * @iocbq: Pointer to driver iocb object.
991 * This function is called with hbalock held to release driver
992 * iocb object to the iocb pool. The iotag in the iocb object
993 * does not change for each use of the iocb object. This function
994 * clears all other fields of the iocb object when it is freed.
995 * The sqlq structure that holds the xritag and phys and virtual
996 * mappings for the scatter gather list is retrieved from the
997 * active array of sglq. The get of the sglq pointer also clears
998 * the entry in the array. If the status of the IO indiactes that
999 * this IO was aborted then the sglq entry it put on the
1000 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1001 * IO has good status or fails for any other reason then the sglq
1002 * entry is added to the free list (lpfc_sgl_list).
1005 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1007 struct lpfc_sglq
*sglq
;
1008 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1009 unsigned long iflag
= 0;
1010 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1012 lockdep_assert_held(&phba
->hbalock
);
1014 if (iocbq
->sli4_xritag
== NO_XRI
)
1017 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1021 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1022 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1023 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
1025 list_add(&sglq
->list
,
1026 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1027 spin_unlock_irqrestore(
1028 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
1030 spin_lock_irqsave(&pring
->ring_lock
, iflag
);
1031 sglq
->state
= SGL_FREED
;
1033 list_add_tail(&sglq
->list
,
1034 &phba
->sli4_hba
.lpfc_sgl_list
);
1035 spin_unlock_irqrestore(&pring
->ring_lock
, iflag
);
1037 /* Check if TXQ queue needs to be serviced */
1038 if (!list_empty(&pring
->txq
))
1039 lpfc_worker_wake_up(phba
);
1045 * Clean all volatile data fields, preserve iotag and node struct.
1047 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1048 iocbq
->sli4_lxritag
= NO_XRI
;
1049 iocbq
->sli4_xritag
= NO_XRI
;
1050 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1055 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1056 * @phba: Pointer to HBA context object.
1057 * @iocbq: Pointer to driver iocb object.
1059 * This function is called with hbalock held to release driver
1060 * iocb object to the iocb pool. The iotag in the iocb object
1061 * does not change for each use of the iocb object. This function
1062 * clears all other fields of the iocb object when it is freed.
1065 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1067 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1069 lockdep_assert_held(&phba
->hbalock
);
1072 * Clean all volatile data fields, preserve iotag and node struct.
1074 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1075 iocbq
->sli4_xritag
= NO_XRI
;
1076 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1080 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1081 * @phba: Pointer to HBA context object.
1082 * @iocbq: Pointer to driver iocb object.
1084 * This function is called with hbalock held to release driver
1085 * iocb object to the iocb pool. The iotag in the iocb object
1086 * does not change for each use of the iocb object. This function
1087 * clears all other fields of the iocb object when it is freed.
1090 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1092 lockdep_assert_held(&phba
->hbalock
);
1094 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1099 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1100 * @phba: Pointer to HBA context object.
1101 * @iocbq: Pointer to driver iocb object.
1103 * This function is called with no lock held to release the iocb to
1107 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1109 unsigned long iflags
;
1112 * Clean all volatile data fields, preserve iotag and node struct.
1114 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1115 __lpfc_sli_release_iocbq(phba
, iocbq
);
1116 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1120 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1121 * @phba: Pointer to HBA context object.
1122 * @iocblist: List of IOCBs.
1123 * @ulpstatus: ULP status in IOCB command field.
1124 * @ulpWord4: ULP word-4 in IOCB command field.
1126 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1127 * on the list by invoking the complete callback function associated with the
1128 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1132 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1133 uint32_t ulpstatus
, uint32_t ulpWord4
)
1135 struct lpfc_iocbq
*piocb
;
1137 while (!list_empty(iocblist
)) {
1138 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1139 if (!piocb
->iocb_cmpl
)
1140 lpfc_sli_release_iocbq(phba
, piocb
);
1142 piocb
->iocb
.ulpStatus
= ulpstatus
;
1143 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1144 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1151 * lpfc_sli_iocb_cmd_type - Get the iocb type
1152 * @iocb_cmnd: iocb command code.
1154 * This function is called by ring event handler function to get the iocb type.
1155 * This function translates the iocb command to an iocb command type used to
1156 * decide the final disposition of each completed IOCB.
1157 * The function returns
1158 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1159 * LPFC_SOL_IOCB if it is a solicited iocb completion
1160 * LPFC_ABORT_IOCB if it is an abort iocb
1161 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1163 * The caller is not required to hold any lock.
1165 static lpfc_iocb_type
1166 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1168 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1170 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1173 switch (iocb_cmnd
) {
1174 case CMD_XMIT_SEQUENCE_CR
:
1175 case CMD_XMIT_SEQUENCE_CX
:
1176 case CMD_XMIT_BCAST_CN
:
1177 case CMD_XMIT_BCAST_CX
:
1178 case CMD_ELS_REQUEST_CR
:
1179 case CMD_ELS_REQUEST_CX
:
1180 case CMD_CREATE_XRI_CR
:
1181 case CMD_CREATE_XRI_CX
:
1182 case CMD_GET_RPI_CN
:
1183 case CMD_XMIT_ELS_RSP_CX
:
1184 case CMD_GET_RPI_CR
:
1185 case CMD_FCP_IWRITE_CR
:
1186 case CMD_FCP_IWRITE_CX
:
1187 case CMD_FCP_IREAD_CR
:
1188 case CMD_FCP_IREAD_CX
:
1189 case CMD_FCP_ICMND_CR
:
1190 case CMD_FCP_ICMND_CX
:
1191 case CMD_FCP_TSEND_CX
:
1192 case CMD_FCP_TRSP_CX
:
1193 case CMD_FCP_TRECEIVE_CX
:
1194 case CMD_FCP_AUTO_TRSP_CX
:
1195 case CMD_ADAPTER_MSG
:
1196 case CMD_ADAPTER_DUMP
:
1197 case CMD_XMIT_SEQUENCE64_CR
:
1198 case CMD_XMIT_SEQUENCE64_CX
:
1199 case CMD_XMIT_BCAST64_CN
:
1200 case CMD_XMIT_BCAST64_CX
:
1201 case CMD_ELS_REQUEST64_CR
:
1202 case CMD_ELS_REQUEST64_CX
:
1203 case CMD_FCP_IWRITE64_CR
:
1204 case CMD_FCP_IWRITE64_CX
:
1205 case CMD_FCP_IREAD64_CR
:
1206 case CMD_FCP_IREAD64_CX
:
1207 case CMD_FCP_ICMND64_CR
:
1208 case CMD_FCP_ICMND64_CX
:
1209 case CMD_FCP_TSEND64_CX
:
1210 case CMD_FCP_TRSP64_CX
:
1211 case CMD_FCP_TRECEIVE64_CX
:
1212 case CMD_GEN_REQUEST64_CR
:
1213 case CMD_GEN_REQUEST64_CX
:
1214 case CMD_XMIT_ELS_RSP64_CX
:
1215 case DSSCMD_IWRITE64_CR
:
1216 case DSSCMD_IWRITE64_CX
:
1217 case DSSCMD_IREAD64_CR
:
1218 case DSSCMD_IREAD64_CX
:
1219 type
= LPFC_SOL_IOCB
;
1221 case CMD_ABORT_XRI_CN
:
1222 case CMD_ABORT_XRI_CX
:
1223 case CMD_CLOSE_XRI_CN
:
1224 case CMD_CLOSE_XRI_CX
:
1225 case CMD_XRI_ABORTED_CX
:
1226 case CMD_ABORT_MXRI64_CN
:
1227 case CMD_XMIT_BLS_RSP64_CX
:
1228 type
= LPFC_ABORT_IOCB
;
1230 case CMD_RCV_SEQUENCE_CX
:
1231 case CMD_RCV_ELS_REQ_CX
:
1232 case CMD_RCV_SEQUENCE64_CX
:
1233 case CMD_RCV_ELS_REQ64_CX
:
1234 case CMD_ASYNC_STATUS
:
1235 case CMD_IOCB_RCV_SEQ64_CX
:
1236 case CMD_IOCB_RCV_ELS64_CX
:
1237 case CMD_IOCB_RCV_CONT64_CX
:
1238 case CMD_IOCB_RET_XRI64_CX
:
1239 type
= LPFC_UNSOL_IOCB
;
1241 case CMD_IOCB_XMIT_MSEQ64_CR
:
1242 case CMD_IOCB_XMIT_MSEQ64_CX
:
1243 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1244 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1245 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1246 case CMD_IOCB_ABORT_EXTENDED_CN
:
1247 case CMD_IOCB_RET_HBQE64_CN
:
1248 case CMD_IOCB_FCP_IBIDIR64_CR
:
1249 case CMD_IOCB_FCP_IBIDIR64_CX
:
1250 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1251 case CMD_IOCB_LOGENTRY_CN
:
1252 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1253 printk("%s - Unhandled SLI-3 Command x%x\n",
1254 __func__
, iocb_cmnd
);
1255 type
= LPFC_UNKNOWN_IOCB
;
1258 type
= LPFC_UNKNOWN_IOCB
;
1266 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1267 * @phba: Pointer to HBA context object.
1269 * This function is called from SLI initialization code
1270 * to configure every ring of the HBA's SLI interface. The
1271 * caller is not required to hold any lock. This function issues
1272 * a config_ring mailbox command for each ring.
1273 * This function returns zero if successful else returns a negative
1277 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1279 struct lpfc_sli
*psli
= &phba
->sli
;
1284 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1288 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1289 for (i
= 0; i
< psli
->num_rings
; i
++) {
1290 lpfc_config_ring(phba
, i
, pmb
);
1291 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1292 if (rc
!= MBX_SUCCESS
) {
1293 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1294 "0446 Adapter failed to init (%d), "
1295 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1297 rc
, pmbox
->mbxCommand
,
1298 pmbox
->mbxStatus
, i
);
1299 phba
->link_state
= LPFC_HBA_ERROR
;
1304 mempool_free(pmb
, phba
->mbox_mem_pool
);
1309 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1310 * @phba: Pointer to HBA context object.
1311 * @pring: Pointer to driver SLI ring object.
1312 * @piocb: Pointer to the driver iocb object.
1314 * This function is called with hbalock held. The function adds the
1315 * new iocb to txcmplq of the given ring. This function always returns
1316 * 0. If this function is called for ELS ring, this function checks if
1317 * there is a vport associated with the ELS command. This function also
1318 * starts els_tmofunc timer if this is an ELS command.
1321 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1322 struct lpfc_iocbq
*piocb
)
1324 lockdep_assert_held(&phba
->hbalock
);
1328 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1329 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1331 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1332 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1333 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1334 BUG_ON(!piocb
->vport
);
1335 if (!(piocb
->vport
->load_flag
& FC_UNLOADING
))
1336 mod_timer(&piocb
->vport
->els_tmofunc
,
1338 msecs_to_jiffies(1000 * (phba
->fc_ratov
<< 1)));
1345 * lpfc_sli_ringtx_get - Get first element of the txq
1346 * @phba: Pointer to HBA context object.
1347 * @pring: Pointer to driver SLI ring object.
1349 * This function is called with hbalock held to get next
1350 * iocb in txq of the given ring. If there is any iocb in
1351 * the txq, the function returns first iocb in the list after
1352 * removing the iocb from the list, else it returns NULL.
1355 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1357 struct lpfc_iocbq
*cmd_iocb
;
1359 lockdep_assert_held(&phba
->hbalock
);
1361 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1366 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1367 * @phba: Pointer to HBA context object.
1368 * @pring: Pointer to driver SLI ring object.
1370 * This function is called with hbalock held and the caller must post the
1371 * iocb without releasing the lock. If the caller releases the lock,
1372 * iocb slot returned by the function is not guaranteed to be available.
1373 * The function returns pointer to the next available iocb slot if there
1374 * is available slot in the ring, else it returns NULL.
1375 * If the get index of the ring is ahead of the put index, the function
1376 * will post an error attention event to the worker thread to take the
1377 * HBA to offline state.
1380 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1382 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1383 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1385 lockdep_assert_held(&phba
->hbalock
);
1387 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1388 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1389 pring
->sli
.sli3
.next_cmdidx
= 0;
1391 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1392 pring
->sli
.sli3
.next_cmdidx
)) {
1394 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1396 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1397 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1398 "0315 Ring %d issue: portCmdGet %d "
1399 "is bigger than cmd ring %d\n",
1401 pring
->sli
.sli3
.local_getidx
,
1404 phba
->link_state
= LPFC_HBA_ERROR
;
1406 * All error attention handlers are posted to
1409 phba
->work_ha
|= HA_ERATT
;
1410 phba
->work_hs
= HS_FFER3
;
1412 lpfc_worker_wake_up(phba
);
1417 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1421 return lpfc_cmd_iocb(phba
, pring
);
1425 * lpfc_sli_next_iotag - Get an iotag for the iocb
1426 * @phba: Pointer to HBA context object.
1427 * @iocbq: Pointer to driver iocb object.
1429 * This function gets an iotag for the iocb. If there is no unused iotag and
1430 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1431 * array and assigns a new iotag.
1432 * The function returns the allocated iotag if successful, else returns zero.
1433 * Zero is not a valid iotag.
1434 * The caller is not required to hold any lock.
1437 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1439 struct lpfc_iocbq
**new_arr
;
1440 struct lpfc_iocbq
**old_arr
;
1442 struct lpfc_sli
*psli
= &phba
->sli
;
1445 spin_lock_irq(&phba
->hbalock
);
1446 iotag
= psli
->last_iotag
;
1447 if(++iotag
< psli
->iocbq_lookup_len
) {
1448 psli
->last_iotag
= iotag
;
1449 psli
->iocbq_lookup
[iotag
] = iocbq
;
1450 spin_unlock_irq(&phba
->hbalock
);
1451 iocbq
->iotag
= iotag
;
1453 } else if (psli
->iocbq_lookup_len
< (0xffff
1454 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1455 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1456 spin_unlock_irq(&phba
->hbalock
);
1457 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1460 spin_lock_irq(&phba
->hbalock
);
1461 old_arr
= psli
->iocbq_lookup
;
1462 if (new_len
<= psli
->iocbq_lookup_len
) {
1463 /* highly unprobable case */
1465 iotag
= psli
->last_iotag
;
1466 if(++iotag
< psli
->iocbq_lookup_len
) {
1467 psli
->last_iotag
= iotag
;
1468 psli
->iocbq_lookup
[iotag
] = iocbq
;
1469 spin_unlock_irq(&phba
->hbalock
);
1470 iocbq
->iotag
= iotag
;
1473 spin_unlock_irq(&phba
->hbalock
);
1476 if (psli
->iocbq_lookup
)
1477 memcpy(new_arr
, old_arr
,
1478 ((psli
->last_iotag
+ 1) *
1479 sizeof (struct lpfc_iocbq
*)));
1480 psli
->iocbq_lookup
= new_arr
;
1481 psli
->iocbq_lookup_len
= new_len
;
1482 psli
->last_iotag
= iotag
;
1483 psli
->iocbq_lookup
[iotag
] = iocbq
;
1484 spin_unlock_irq(&phba
->hbalock
);
1485 iocbq
->iotag
= iotag
;
1490 spin_unlock_irq(&phba
->hbalock
);
1492 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1493 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1500 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1501 * @phba: Pointer to HBA context object.
1502 * @pring: Pointer to driver SLI ring object.
1503 * @iocb: Pointer to iocb slot in the ring.
1504 * @nextiocb: Pointer to driver iocb object which need to be
1505 * posted to firmware.
1507 * This function is called with hbalock held to post a new iocb to
1508 * the firmware. This function copies the new iocb to ring iocb slot and
1509 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1510 * a completion call back for this iocb else the function will free the
1514 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1515 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1517 lockdep_assert_held(&phba
->hbalock
);
1521 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1524 if (pring
->ringno
== LPFC_ELS_RING
) {
1525 lpfc_debugfs_slow_ring_trc(phba
,
1526 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1527 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1528 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1529 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1533 * Issue iocb command to adapter
1535 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1537 pring
->stats
.iocb_cmd
++;
1540 * If there is no completion routine to call, we can release the
1541 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1542 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1544 if (nextiocb
->iocb_cmpl
)
1545 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1547 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1550 * Let the HBA know what IOCB slot will be the next one the
1551 * driver will put a command into.
1553 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1554 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1558 * lpfc_sli_update_full_ring - Update the chip attention register
1559 * @phba: Pointer to HBA context object.
1560 * @pring: Pointer to driver SLI ring object.
1562 * The caller is not required to hold any lock for calling this function.
1563 * This function updates the chip attention bits for the ring to inform firmware
1564 * that there are pending work to be done for this ring and requests an
1565 * interrupt when there is space available in the ring. This function is
1566 * called when the driver is unable to post more iocbs to the ring due
1567 * to unavailability of space in the ring.
1570 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1572 int ringno
= pring
->ringno
;
1574 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1579 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1580 * The HBA will tell us when an IOCB entry is available.
1582 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1583 readl(phba
->CAregaddr
); /* flush */
1585 pring
->stats
.iocb_cmd_full
++;
1589 * lpfc_sli_update_ring - Update chip attention register
1590 * @phba: Pointer to HBA context object.
1591 * @pring: Pointer to driver SLI ring object.
1593 * This function updates the chip attention register bit for the
1594 * given ring to inform HBA that there is more work to be done
1595 * in this ring. The caller is not required to hold any lock.
1598 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1600 int ringno
= pring
->ringno
;
1603 * Tell the HBA that there is work to do in this ring.
1605 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1607 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1608 readl(phba
->CAregaddr
); /* flush */
1613 * lpfc_sli_resume_iocb - Process iocbs in the txq
1614 * @phba: Pointer to HBA context object.
1615 * @pring: Pointer to driver SLI ring object.
1617 * This function is called with hbalock held to post pending iocbs
1618 * in the txq to the firmware. This function is called when driver
1619 * detects space available in the ring.
1622 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1625 struct lpfc_iocbq
*nextiocb
;
1627 lockdep_assert_held(&phba
->hbalock
);
1631 * (a) there is anything on the txq to send
1633 * (c) link attention events can be processed (fcp ring only)
1634 * (d) IOCB processing is not blocked by the outstanding mbox command.
1637 if (lpfc_is_link_up(phba
) &&
1638 (!list_empty(&pring
->txq
)) &&
1639 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1640 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1642 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1643 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1644 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1647 lpfc_sli_update_ring(phba
, pring
);
1649 lpfc_sli_update_full_ring(phba
, pring
);
1656 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1657 * @phba: Pointer to HBA context object.
1658 * @hbqno: HBQ number.
1660 * This function is called with hbalock held to get the next
1661 * available slot for the given HBQ. If there is free slot
1662 * available for the HBQ it will return pointer to the next available
1663 * HBQ entry else it will return NULL.
1665 static struct lpfc_hbq_entry
*
1666 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1668 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1670 lockdep_assert_held(&phba
->hbalock
);
1672 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1673 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1674 hbqp
->next_hbqPutIdx
= 0;
1676 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1677 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1678 uint32_t getidx
= le32_to_cpu(raw_index
);
1680 hbqp
->local_hbqGetIdx
= getidx
;
1682 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1683 lpfc_printf_log(phba
, KERN_ERR
,
1684 LOG_SLI
| LOG_VPORT
,
1685 "1802 HBQ %d: local_hbqGetIdx "
1686 "%u is > than hbqp->entry_count %u\n",
1687 hbqno
, hbqp
->local_hbqGetIdx
,
1690 phba
->link_state
= LPFC_HBA_ERROR
;
1694 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1698 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1703 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1704 * @phba: Pointer to HBA context object.
1706 * This function is called with no lock held to free all the
1707 * hbq buffers while uninitializing the SLI interface. It also
1708 * frees the HBQ buffers returned by the firmware but not yet
1709 * processed by the upper layers.
1712 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1714 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1715 struct hbq_dmabuf
*hbq_buf
;
1716 unsigned long flags
;
1720 hbq_count
= lpfc_sli_hbq_count();
1721 /* Return all memory used by all HBQs */
1722 spin_lock_irqsave(&phba
->hbalock
, flags
);
1723 for (i
= 0; i
< hbq_count
; ++i
) {
1724 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1725 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1726 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1727 list_del(&hbq_buf
->dbuf
.list
);
1728 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1730 phba
->hbqs
[i
].buffer_count
= 0;
1732 /* Return all HBQ buffer that are in-fly */
1733 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1735 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1736 list_del(&hbq_buf
->dbuf
.list
);
1737 if (hbq_buf
->tag
== -1) {
1738 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1741 hbqno
= hbq_buf
->tag
>> 16;
1742 if (hbqno
>= LPFC_MAX_HBQS
)
1743 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1746 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1751 /* Mark the HBQs not in use */
1752 phba
->hbq_in_use
= 0;
1753 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1757 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1758 * @phba: Pointer to HBA context object.
1759 * @hbqno: HBQ number.
1760 * @hbq_buf: Pointer to HBQ buffer.
1762 * This function is called with the hbalock held to post a
1763 * hbq buffer to the firmware. If the function finds an empty
1764 * slot in the HBQ, it will post the buffer. The function will return
1765 * pointer to the hbq entry if it successfully post the buffer
1766 * else it will return NULL.
1769 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1770 struct hbq_dmabuf
*hbq_buf
)
1772 lockdep_assert_held(&phba
->hbalock
);
1773 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1777 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1778 * @phba: Pointer to HBA context object.
1779 * @hbqno: HBQ number.
1780 * @hbq_buf: Pointer to HBQ buffer.
1782 * This function is called with the hbalock held to post a hbq buffer to the
1783 * firmware. If the function finds an empty slot in the HBQ, it will post the
1784 * buffer and place it on the hbq_buffer_list. The function will return zero if
1785 * it successfully post the buffer else it will return an error.
1788 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1789 struct hbq_dmabuf
*hbq_buf
)
1791 struct lpfc_hbq_entry
*hbqe
;
1792 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1794 lockdep_assert_held(&phba
->hbalock
);
1795 /* Get next HBQ entry slot to use */
1796 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1798 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1800 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1801 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1802 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1803 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1804 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1805 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1807 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1808 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1810 readl(phba
->hbq_put
+ hbqno
);
1811 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1818 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1819 * @phba: Pointer to HBA context object.
1820 * @hbqno: HBQ number.
1821 * @hbq_buf: Pointer to HBQ buffer.
1823 * This function is called with the hbalock held to post an RQE to the SLI4
1824 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1825 * the hbq_buffer_list and return zero, otherwise it will return an error.
1828 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1829 struct hbq_dmabuf
*hbq_buf
)
1832 struct lpfc_rqe hrqe
;
1833 struct lpfc_rqe drqe
;
1835 lockdep_assert_held(&phba
->hbalock
);
1836 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1837 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1838 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1839 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1840 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1845 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1849 /* HBQ for ELS and CT traffic. */
1850 static struct lpfc_hbq_init lpfc_els_hbq
= {
1855 .ring_mask
= (1 << LPFC_ELS_RING
),
1861 /* HBQ for the extra ring if needed */
1862 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1867 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1874 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1880 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1881 * @phba: Pointer to HBA context object.
1882 * @hbqno: HBQ number.
1883 * @count: Number of HBQ buffers to be posted.
1885 * This function is called with no lock held to post more hbq buffers to the
1886 * given HBQ. The function returns the number of HBQ buffers successfully
1890 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1892 uint32_t i
, posted
= 0;
1893 unsigned long flags
;
1894 struct hbq_dmabuf
*hbq_buffer
;
1895 LIST_HEAD(hbq_buf_list
);
1896 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1899 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1900 lpfc_hbq_defs
[hbqno
]->entry_count
)
1901 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1902 phba
->hbqs
[hbqno
].buffer_count
;
1905 /* Allocate HBQ entries */
1906 for (i
= 0; i
< count
; i
++) {
1907 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1910 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1912 /* Check whether HBQ is still in use */
1913 spin_lock_irqsave(&phba
->hbalock
, flags
);
1914 if (!phba
->hbq_in_use
)
1916 while (!list_empty(&hbq_buf_list
)) {
1917 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1919 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1921 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1922 phba
->hbqs
[hbqno
].buffer_count
++;
1925 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1927 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1930 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1931 while (!list_empty(&hbq_buf_list
)) {
1932 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1934 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1940 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1941 * @phba: Pointer to HBA context object.
1944 * This function posts more buffers to the HBQ. This function
1945 * is called with no lock held. The function returns the number of HBQ entries
1946 * successfully allocated.
1949 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1951 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1954 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1955 lpfc_hbq_defs
[qno
]->add_count
);
1959 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1960 * @phba: Pointer to HBA context object.
1961 * @qno: HBQ queue number.
1963 * This function is called from SLI initialization code path with
1964 * no lock held to post initial HBQ buffers to firmware. The
1965 * function returns the number of HBQ entries successfully allocated.
1968 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1970 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1971 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1972 lpfc_hbq_defs
[qno
]->entry_count
);
1974 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1975 lpfc_hbq_defs
[qno
]->init_count
);
1979 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1980 * @phba: Pointer to HBA context object.
1981 * @hbqno: HBQ number.
1983 * This function removes the first hbq buffer on an hbq list and returns a
1984 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1986 static struct hbq_dmabuf
*
1987 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1989 struct lpfc_dmabuf
*d_buf
;
1991 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1994 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1998 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1999 * @phba: Pointer to HBA context object.
2000 * @tag: Tag of the hbq buffer.
2002 * This function searches for the hbq buffer associated with the given tag in
2003 * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
2004 * otherwise it returns NULL.
2006 static struct hbq_dmabuf
*
2007 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
2009 struct lpfc_dmabuf
*d_buf
;
2010 struct hbq_dmabuf
*hbq_buf
;
2014 if (hbqno
>= LPFC_MAX_HBQS
)
2017 spin_lock_irq(&phba
->hbalock
);
2018 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2019 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2020 if (hbq_buf
->tag
== tag
) {
2021 spin_unlock_irq(&phba
->hbalock
);
2025 spin_unlock_irq(&phba
->hbalock
);
2026 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2027 "1803 Bad hbq tag. Data: x%x x%x\n",
2028 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2033 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2034 * @phba: Pointer to HBA context object.
2035 * @hbq_buffer: Pointer to HBQ buffer.
2037 * This function is called with hbalock. This function gives back
2038 * the hbq buffer to firmware. If the HBQ does not have space to
2039 * post the buffer, it will free the buffer.
2042 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2047 hbqno
= hbq_buffer
->tag
>> 16;
2048 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2049 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2054 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2055 * @mbxCommand: mailbox command code.
2057 * This function is called by the mailbox event handler function to verify
2058 * that the completed mailbox command is a legitimate mailbox command. If the
2059 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2060 * and the mailbox event handler will take the HBA offline.
2063 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2067 switch (mbxCommand
) {
2071 case MBX_WRITE_VPARMS
:
2072 case MBX_RUN_BIU_DIAG
:
2075 case MBX_CONFIG_LINK
:
2076 case MBX_CONFIG_RING
:
2077 case MBX_RESET_RING
:
2078 case MBX_READ_CONFIG
:
2079 case MBX_READ_RCONFIG
:
2080 case MBX_READ_SPARM
:
2081 case MBX_READ_STATUS
:
2085 case MBX_READ_LNK_STAT
:
2087 case MBX_UNREG_LOGIN
:
2089 case MBX_DUMP_MEMORY
:
2090 case MBX_DUMP_CONTEXT
:
2093 case MBX_UPDATE_CFG
:
2095 case MBX_DEL_LD_ENTRY
:
2096 case MBX_RUN_PROGRAM
:
2098 case MBX_SET_VARIABLE
:
2099 case MBX_UNREG_D_ID
:
2100 case MBX_KILL_BOARD
:
2101 case MBX_CONFIG_FARP
:
2104 case MBX_RUN_BIU_DIAG64
:
2105 case MBX_CONFIG_PORT
:
2106 case MBX_READ_SPARM64
:
2107 case MBX_READ_RPI64
:
2108 case MBX_REG_LOGIN64
:
2109 case MBX_READ_TOPOLOGY
:
2112 case MBX_LOAD_EXP_ROM
:
2113 case MBX_ASYNCEVT_ENABLE
:
2117 case MBX_PORT_CAPABILITIES
:
2118 case MBX_PORT_IOV_CONTROL
:
2119 case MBX_SLI4_CONFIG
:
2120 case MBX_SLI4_REQ_FTRS
:
2122 case MBX_UNREG_FCFI
:
2127 case MBX_RESUME_RPI
:
2128 case MBX_READ_EVENT_LOG_STATUS
:
2129 case MBX_READ_EVENT_LOG
:
2130 case MBX_SECURITY_MGMT
:
2132 case MBX_ACCESS_VDATA
:
2143 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2144 * @phba: Pointer to HBA context object.
2145 * @pmboxq: Pointer to mailbox command.
2147 * This is completion handler function for mailbox commands issued from
2148 * lpfc_sli_issue_mbox_wait function. This function is called by the
2149 * mailbox event handler function with no lock held. This function
2150 * will wake up thread waiting on the wait queue pointed by context1
2154 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2156 wait_queue_head_t
*pdone_q
;
2157 unsigned long drvr_flag
;
2160 * If pdone_q is empty, the driver thread gave up waiting and
2161 * continued running.
2163 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2164 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2165 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2167 wake_up_interruptible(pdone_q
);
2168 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2174 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2175 * @phba: Pointer to HBA context object.
2176 * @pmb: Pointer to mailbox object.
2178 * This function is the default mailbox completion handler. It
2179 * frees the memory resources associated with the completed mailbox
2180 * command. If the completed command is a REG_LOGIN mailbox command,
2181 * this function will issue a UREG_LOGIN to re-claim the RPI.
2184 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2186 struct lpfc_vport
*vport
= pmb
->vport
;
2187 struct lpfc_dmabuf
*mp
;
2188 struct lpfc_nodelist
*ndlp
;
2189 struct Scsi_Host
*shost
;
2193 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2196 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2201 * If a REG_LOGIN succeeded after node is destroyed or node
2202 * is in re-discovery driver need to cleanup the RPI.
2204 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2205 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2206 !pmb
->u
.mb
.mbxStatus
) {
2207 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2208 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2209 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2211 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2212 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2213 if (rc
!= MBX_NOT_FINISHED
)
2217 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2218 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2219 !pmb
->u
.mb
.mbxStatus
) {
2220 shost
= lpfc_shost_from_vport(vport
);
2221 spin_lock_irq(shost
->host_lock
);
2222 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2223 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2224 spin_unlock_irq(shost
->host_lock
);
2227 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2228 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2230 pmb
->context2
= NULL
;
2233 /* Check security permission status on INIT_LINK mailbox command */
2234 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2235 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2236 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2237 "2860 SLI authentication is required "
2238 "for INIT_LINK but has not done yet\n");
2240 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2241 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2243 mempool_free(pmb
, phba
->mbox_mem_pool
);
2246 * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
2247 * @phba: Pointer to HBA context object.
2248 * @pmb: Pointer to mailbox object.
2250 * This function is the unreg rpi mailbox completion handler. It
2251 * frees the memory resources associated with the completed mailbox
2252 * command. An additional refrenece is put on the ndlp to prevent
2253 * lpfc_nlp_release from freeing the rpi bit in the bitmask before
2254 * the unreg mailbox command completes, this routine puts the
2259 lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2261 struct lpfc_vport
*vport
= pmb
->vport
;
2262 struct lpfc_nodelist
*ndlp
;
2264 ndlp
= pmb
->context1
;
2265 if (pmb
->u
.mb
.mbxCommand
== MBX_UNREG_LOGIN
) {
2266 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2267 (bf_get(lpfc_sli_intf_if_type
,
2268 &phba
->sli4_hba
.sli_intf
) ==
2269 LPFC_SLI_INTF_IF_TYPE_2
)) {
2271 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
2272 "0010 UNREG_LOGIN vpi:%x "
2273 "rpi:%x DID:%x map:%x %p\n",
2274 vport
->vpi
, ndlp
->nlp_rpi
,
2276 ndlp
->nlp_usg_map
, ndlp
);
2277 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2283 mempool_free(pmb
, phba
->mbox_mem_pool
);
2287 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2288 * @phba: Pointer to HBA context object.
2290 * This function is called with no lock held. This function processes all
2291 * the completed mailbox commands and gives it to upper layers. The interrupt
2292 * service routine processes mailbox completion interrupt and adds completed
2293 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2294 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2295 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2296 * function returns the mailbox commands to the upper layer by calling the
2297 * completion handler function of each mailbox.
2300 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2307 phba
->sli
.slistat
.mbox_event
++;
2309 /* Get all completed mailboxe buffers into the cmplq */
2310 spin_lock_irq(&phba
->hbalock
);
2311 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2312 spin_unlock_irq(&phba
->hbalock
);
2314 /* Get a Mailbox buffer to setup mailbox commands for callback */
2316 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2322 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2324 lpfc_debugfs_disc_trc(pmb
->vport
,
2325 LPFC_DISC_TRC_MBOX_VPORT
,
2326 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2327 (uint32_t)pmbox
->mbxCommand
,
2328 pmbox
->un
.varWords
[0],
2329 pmbox
->un
.varWords
[1]);
2332 lpfc_debugfs_disc_trc(phba
->pport
,
2334 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2335 (uint32_t)pmbox
->mbxCommand
,
2336 pmbox
->un
.varWords
[0],
2337 pmbox
->un
.varWords
[1]);
2342 * It is a fatal error if unknown mbox command completion.
2344 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2346 /* Unknown mailbox command compl */
2347 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2348 "(%d):0323 Unknown Mailbox command "
2349 "x%x (x%x/x%x) Cmpl\n",
2350 pmb
->vport
? pmb
->vport
->vpi
: 0,
2352 lpfc_sli_config_mbox_subsys_get(phba
,
2354 lpfc_sli_config_mbox_opcode_get(phba
,
2356 phba
->link_state
= LPFC_HBA_ERROR
;
2357 phba
->work_hs
= HS_FFER3
;
2358 lpfc_handle_eratt(phba
);
2362 if (pmbox
->mbxStatus
) {
2363 phba
->sli
.slistat
.mbox_stat_err
++;
2364 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2365 /* Mbox cmd cmpl error - RETRYing */
2366 lpfc_printf_log(phba
, KERN_INFO
,
2368 "(%d):0305 Mbox cmd cmpl "
2369 "error - RETRYing Data: x%x "
2370 "(x%x/x%x) x%x x%x x%x\n",
2371 pmb
->vport
? pmb
->vport
->vpi
: 0,
2373 lpfc_sli_config_mbox_subsys_get(phba
,
2375 lpfc_sli_config_mbox_opcode_get(phba
,
2378 pmbox
->un
.varWords
[0],
2379 pmb
->vport
->port_state
);
2380 pmbox
->mbxStatus
= 0;
2381 pmbox
->mbxOwner
= OWN_HOST
;
2382 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2383 if (rc
!= MBX_NOT_FINISHED
)
2388 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2389 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2390 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2391 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2393 pmb
->vport
? pmb
->vport
->vpi
: 0,
2395 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2396 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2398 *((uint32_t *) pmbox
),
2399 pmbox
->un
.varWords
[0],
2400 pmbox
->un
.varWords
[1],
2401 pmbox
->un
.varWords
[2],
2402 pmbox
->un
.varWords
[3],
2403 pmbox
->un
.varWords
[4],
2404 pmbox
->un
.varWords
[5],
2405 pmbox
->un
.varWords
[6],
2406 pmbox
->un
.varWords
[7],
2407 pmbox
->un
.varWords
[8],
2408 pmbox
->un
.varWords
[9],
2409 pmbox
->un
.varWords
[10]);
2412 pmb
->mbox_cmpl(phba
,pmb
);
2418 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2419 * @phba: Pointer to HBA context object.
2420 * @pring: Pointer to driver SLI ring object.
2423 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2424 * is set in the tag the buffer is posted for a particular exchange,
2425 * the function will return the buffer without replacing the buffer.
2426 * If the buffer is for unsolicited ELS or CT traffic, this function
2427 * returns the buffer and also posts another buffer to the firmware.
2429 static struct lpfc_dmabuf
*
2430 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2431 struct lpfc_sli_ring
*pring
,
2434 struct hbq_dmabuf
*hbq_entry
;
2436 if (tag
& QUE_BUFTAG_BIT
)
2437 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2438 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2441 return &hbq_entry
->dbuf
;
2445 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2446 * @phba: Pointer to HBA context object.
2447 * @pring: Pointer to driver SLI ring object.
2448 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2449 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2450 * @fch_type: the type for the first frame of the sequence.
2452 * This function is called with no lock held. This function uses the r_ctl and
2453 * type of the received sequence to find the correct callback function to call
2454 * to process the sequence.
2457 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2458 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2463 /* unSolicited Responses */
2464 if (pring
->prt
[0].profile
) {
2465 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2466 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2470 /* We must search, based on rctl / type
2471 for the right routine */
2472 for (i
= 0; i
< pring
->num_mask
; i
++) {
2473 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2474 (pring
->prt
[i
].type
== fch_type
)) {
2475 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2476 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2477 (phba
, pring
, saveq
);
2485 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2486 * @phba: Pointer to HBA context object.
2487 * @pring: Pointer to driver SLI ring object.
2488 * @saveq: Pointer to the unsolicited iocb.
2490 * This function is called with no lock held by the ring event handler
2491 * when there is an unsolicited iocb posted to the response ring by the
2492 * firmware. This function gets the buffer associated with the iocbs
2493 * and calls the event handler for the ring. This function handles both
2494 * qring buffers and hbq buffers.
2495 * When the function returns 1 the caller can free the iocb object otherwise
2496 * upper layer functions will free the iocb objects.
2499 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2500 struct lpfc_iocbq
*saveq
)
2504 uint32_t Rctl
, Type
;
2505 struct lpfc_iocbq
*iocbq
;
2506 struct lpfc_dmabuf
*dmzbuf
;
2508 irsp
= &(saveq
->iocb
);
2510 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2511 if (pring
->lpfc_sli_rcv_async_status
)
2512 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2514 lpfc_printf_log(phba
,
2517 "0316 Ring %d handler: unexpected "
2518 "ASYNC_STATUS iocb received evt_code "
2521 irsp
->un
.asyncstat
.evt_code
);
2525 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2526 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2527 if (irsp
->ulpBdeCount
> 0) {
2528 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2529 irsp
->un
.ulpWord
[3]);
2530 lpfc_in_buf_free(phba
, dmzbuf
);
2533 if (irsp
->ulpBdeCount
> 1) {
2534 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2535 irsp
->unsli3
.sli3Words
[3]);
2536 lpfc_in_buf_free(phba
, dmzbuf
);
2539 if (irsp
->ulpBdeCount
> 2) {
2540 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2541 irsp
->unsli3
.sli3Words
[7]);
2542 lpfc_in_buf_free(phba
, dmzbuf
);
2548 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2549 if (irsp
->ulpBdeCount
!= 0) {
2550 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2551 irsp
->un
.ulpWord
[3]);
2552 if (!saveq
->context2
)
2553 lpfc_printf_log(phba
,
2556 "0341 Ring %d Cannot find buffer for "
2557 "an unsolicited iocb. tag 0x%x\n",
2559 irsp
->un
.ulpWord
[3]);
2561 if (irsp
->ulpBdeCount
== 2) {
2562 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2563 irsp
->unsli3
.sli3Words
[7]);
2564 if (!saveq
->context3
)
2565 lpfc_printf_log(phba
,
2568 "0342 Ring %d Cannot find buffer for an"
2569 " unsolicited iocb. tag 0x%x\n",
2571 irsp
->unsli3
.sli3Words
[7]);
2573 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2574 irsp
= &(iocbq
->iocb
);
2575 if (irsp
->ulpBdeCount
!= 0) {
2576 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2577 irsp
->un
.ulpWord
[3]);
2578 if (!iocbq
->context2
)
2579 lpfc_printf_log(phba
,
2582 "0343 Ring %d Cannot find "
2583 "buffer for an unsolicited iocb"
2584 ". tag 0x%x\n", pring
->ringno
,
2585 irsp
->un
.ulpWord
[3]);
2587 if (irsp
->ulpBdeCount
== 2) {
2588 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2589 irsp
->unsli3
.sli3Words
[7]);
2590 if (!iocbq
->context3
)
2591 lpfc_printf_log(phba
,
2594 "0344 Ring %d Cannot find "
2595 "buffer for an unsolicited "
2598 irsp
->unsli3
.sli3Words
[7]);
2602 if (irsp
->ulpBdeCount
!= 0 &&
2603 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2604 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2607 /* search continue save q for same XRI */
2608 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2609 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2610 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2611 list_add_tail(&saveq
->list
, &iocbq
->list
);
2617 list_add_tail(&saveq
->clist
,
2618 &pring
->iocb_continue_saveq
);
2619 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2620 list_del_init(&iocbq
->clist
);
2622 irsp
= &(saveq
->iocb
);
2626 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2627 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2628 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2629 Rctl
= FC_RCTL_ELS_REQ
;
2632 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2633 Rctl
= w5p
->hcsw
.Rctl
;
2634 Type
= w5p
->hcsw
.Type
;
2636 /* Firmware Workaround */
2637 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2638 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2639 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2640 Rctl
= FC_RCTL_ELS_REQ
;
2642 w5p
->hcsw
.Rctl
= Rctl
;
2643 w5p
->hcsw
.Type
= Type
;
2647 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2648 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2649 "0313 Ring %d handler: unexpected Rctl x%x "
2650 "Type x%x received\n",
2651 pring
->ringno
, Rctl
, Type
);
2657 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2658 * @phba: Pointer to HBA context object.
2659 * @pring: Pointer to driver SLI ring object.
2660 * @prspiocb: Pointer to response iocb object.
2662 * This function looks up the iocb_lookup table to get the command iocb
2663 * corresponding to the given response iocb using the iotag of the
2664 * response iocb. This function is called with the hbalock held.
2665 * This function returns the command iocb object if it finds the command
2666 * iocb else returns NULL.
2668 static struct lpfc_iocbq
*
2669 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2670 struct lpfc_sli_ring
*pring
,
2671 struct lpfc_iocbq
*prspiocb
)
2673 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2675 lockdep_assert_held(&phba
->hbalock
);
2677 iotag
= prspiocb
->iocb
.ulpIoTag
;
2679 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2680 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2681 list_del_init(&cmd_iocb
->list
);
2682 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2683 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2688 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2689 "0317 iotag x%x is out off "
2690 "range: max iotag x%x wd0 x%x\n",
2691 iotag
, phba
->sli
.last_iotag
,
2692 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2697 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2698 * @phba: Pointer to HBA context object.
2699 * @pring: Pointer to driver SLI ring object.
2702 * This function looks up the iocb_lookup table to get the command iocb
2703 * corresponding to the given iotag. This function is called with the
2705 * This function returns the command iocb object if it finds the command
2706 * iocb else returns NULL.
2708 static struct lpfc_iocbq
*
2709 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2710 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2712 struct lpfc_iocbq
*cmd_iocb
;
2714 lockdep_assert_held(&phba
->hbalock
);
2715 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2716 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2717 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2718 /* remove from txcmpl queue list */
2719 list_del_init(&cmd_iocb
->list
);
2720 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2724 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2725 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2726 iotag
, phba
->sli
.last_iotag
);
2731 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2732 * @phba: Pointer to HBA context object.
2733 * @pring: Pointer to driver SLI ring object.
2734 * @saveq: Pointer to the response iocb to be processed.
2736 * This function is called by the ring event handler for non-fcp
2737 * rings when there is a new response iocb in the response ring.
2738 * The caller is not required to hold any locks. This function
2739 * gets the command iocb associated with the response iocb and
2740 * calls the completion handler for the command iocb. If there
2741 * is no completion handler, the function will free the resources
2742 * associated with command iocb. If the response iocb is for
2743 * an already aborted command iocb, the status of the completion
2744 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2745 * This function always returns 1.
2748 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2749 struct lpfc_iocbq
*saveq
)
2751 struct lpfc_iocbq
*cmdiocbp
;
2753 unsigned long iflag
;
2755 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2756 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2757 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2758 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2761 if (cmdiocbp
->iocb_cmpl
) {
2763 * If an ELS command failed send an event to mgmt
2766 if (saveq
->iocb
.ulpStatus
&&
2767 (pring
->ringno
== LPFC_ELS_RING
) &&
2768 (cmdiocbp
->iocb
.ulpCommand
==
2769 CMD_ELS_REQUEST64_CR
))
2770 lpfc_send_els_failure_event(phba
,
2774 * Post all ELS completions to the worker thread.
2775 * All other are passed to the completion callback.
2777 if (pring
->ringno
== LPFC_ELS_RING
) {
2778 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2779 (cmdiocbp
->iocb_flag
&
2780 LPFC_DRIVER_ABORTED
)) {
2781 spin_lock_irqsave(&phba
->hbalock
,
2783 cmdiocbp
->iocb_flag
&=
2784 ~LPFC_DRIVER_ABORTED
;
2785 spin_unlock_irqrestore(&phba
->hbalock
,
2787 saveq
->iocb
.ulpStatus
=
2788 IOSTAT_LOCAL_REJECT
;
2789 saveq
->iocb
.un
.ulpWord
[4] =
2792 /* Firmware could still be in progress
2793 * of DMAing payload, so don't free data
2794 * buffer till after a hbeat.
2796 spin_lock_irqsave(&phba
->hbalock
,
2798 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2799 spin_unlock_irqrestore(&phba
->hbalock
,
2802 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2803 if (saveq
->iocb_flag
&
2804 LPFC_EXCHANGE_BUSY
) {
2805 /* Set cmdiocb flag for the
2806 * exchange busy so sgl (xri)
2807 * will not be released until
2808 * the abort xri is received
2812 &phba
->hbalock
, iflag
);
2813 cmdiocbp
->iocb_flag
|=
2815 spin_unlock_irqrestore(
2816 &phba
->hbalock
, iflag
);
2818 if (cmdiocbp
->iocb_flag
&
2819 LPFC_DRIVER_ABORTED
) {
2821 * Clear LPFC_DRIVER_ABORTED
2822 * bit in case it was driver
2826 &phba
->hbalock
, iflag
);
2827 cmdiocbp
->iocb_flag
&=
2828 ~LPFC_DRIVER_ABORTED
;
2829 spin_unlock_irqrestore(
2830 &phba
->hbalock
, iflag
);
2831 cmdiocbp
->iocb
.ulpStatus
=
2832 IOSTAT_LOCAL_REJECT
;
2833 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2834 IOERR_ABORT_REQUESTED
;
2836 * For SLI4, irsiocb contains
2837 * NO_XRI in sli_xritag, it
2838 * shall not affect releasing
2839 * sgl (xri) process.
2841 saveq
->iocb
.ulpStatus
=
2842 IOSTAT_LOCAL_REJECT
;
2843 saveq
->iocb
.un
.ulpWord
[4] =
2846 &phba
->hbalock
, iflag
);
2848 LPFC_DELAY_MEM_FREE
;
2849 spin_unlock_irqrestore(
2850 &phba
->hbalock
, iflag
);
2854 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2856 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2859 * Unknown initiating command based on the response iotag.
2860 * This could be the case on the ELS ring because of
2863 if (pring
->ringno
!= LPFC_ELS_RING
) {
2865 * Ring <ringno> handler: unexpected completion IoTag
2868 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2869 "0322 Ring %d handler: "
2870 "unexpected completion IoTag x%x "
2871 "Data: x%x x%x x%x x%x\n",
2873 saveq
->iocb
.ulpIoTag
,
2874 saveq
->iocb
.ulpStatus
,
2875 saveq
->iocb
.un
.ulpWord
[4],
2876 saveq
->iocb
.ulpCommand
,
2877 saveq
->iocb
.ulpContext
);
2885 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2886 * @phba: Pointer to HBA context object.
2887 * @pring: Pointer to driver SLI ring object.
2889 * This function is called from the iocb ring event handlers when
2890 * put pointer is ahead of the get pointer for a ring. This function signal
2891 * an error attention condition to the worker thread and the worker
2892 * thread will transition the HBA to offline state.
2895 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2897 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2899 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2900 * rsp ring <portRspMax>
2902 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2903 "0312 Ring %d handler: portRspPut %d "
2904 "is bigger than rsp ring %d\n",
2905 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2906 pring
->sli
.sli3
.numRiocb
);
2908 phba
->link_state
= LPFC_HBA_ERROR
;
2911 * All error attention handlers are posted to
2914 phba
->work_ha
|= HA_ERATT
;
2915 phba
->work_hs
= HS_FFER3
;
2917 lpfc_worker_wake_up(phba
);
2923 * lpfc_poll_eratt - Error attention polling timer timeout handler
2924 * @ptr: Pointer to address of HBA context object.
2926 * This function is invoked by the Error Attention polling timer when the
2927 * timer times out. It will check the SLI Error Attention register for
2928 * possible attention events. If so, it will post an Error Attention event
2929 * and wake up worker thread to process it. Otherwise, it will set up the
2930 * Error Attention polling timer for the next poll.
2932 void lpfc_poll_eratt(unsigned long ptr
)
2934 struct lpfc_hba
*phba
;
2936 uint64_t sli_intr
, cnt
;
2938 phba
= (struct lpfc_hba
*)ptr
;
2940 /* Here we will also keep track of interrupts per sec of the hba */
2941 sli_intr
= phba
->sli
.slistat
.sli_intr
;
2943 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
2944 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
2947 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
2949 /* 64-bit integer division not supported on 32-bit x86 - use do_div */
2950 do_div(cnt
, phba
->eratt_poll_interval
);
2951 phba
->sli
.slistat
.sli_ips
= cnt
;
2953 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
2955 /* Check chip HA register for error event */
2956 eratt
= lpfc_sli_check_eratt(phba
);
2959 /* Tell the worker thread there is work to do */
2960 lpfc_worker_wake_up(phba
);
2962 /* Restart the timer for next eratt poll */
2963 mod_timer(&phba
->eratt_poll
,
2965 msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
2971 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2972 * @phba: Pointer to HBA context object.
2973 * @pring: Pointer to driver SLI ring object.
2974 * @mask: Host attention register mask for this ring.
2976 * This function is called from the interrupt context when there is a ring
2977 * event for the fcp ring. The caller does not hold any lock.
2978 * The function processes each response iocb in the response ring until it
2979 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2980 * LE bit set. The function will call the completion handler of the command iocb
2981 * if the response iocb indicates a completion for a command iocb or it is
2982 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2983 * function if this is an unsolicited iocb.
2984 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2985 * to check it explicitly.
2988 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2989 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2991 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2992 IOCB_t
*irsp
= NULL
;
2993 IOCB_t
*entry
= NULL
;
2994 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2995 struct lpfc_iocbq rspiocbq
;
2997 uint32_t portRspPut
, portRspMax
;
2999 lpfc_iocb_type type
;
3000 unsigned long iflag
;
3001 uint32_t rsp_cmpl
= 0;
3003 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3004 pring
->stats
.iocb_event
++;
3007 * The next available response entry should never exceed the maximum
3008 * entries. If it does, treat it as an adapter hardware error.
3010 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3011 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3012 if (unlikely(portRspPut
>= portRspMax
)) {
3013 lpfc_sli_rsp_pointers_error(phba
, pring
);
3014 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3017 if (phba
->fcp_ring_in_use
) {
3018 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3021 phba
->fcp_ring_in_use
= 1;
3024 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3026 * Fetch an entry off the ring and copy it into a local data
3027 * structure. The copy involves a byte-swap since the
3028 * network byte order and pci byte orders are different.
3030 entry
= lpfc_resp_iocb(phba
, pring
);
3031 phba
->last_completion_time
= jiffies
;
3033 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3034 pring
->sli
.sli3
.rspidx
= 0;
3036 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
3037 (uint32_t *) &rspiocbq
.iocb
,
3038 phba
->iocb_rsp_size
);
3039 INIT_LIST_HEAD(&(rspiocbq
.list
));
3040 irsp
= &rspiocbq
.iocb
;
3042 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
3043 pring
->stats
.iocb_rsp
++;
3046 if (unlikely(irsp
->ulpStatus
)) {
3048 * If resource errors reported from HBA, reduce
3049 * queuedepths of the SCSI device.
3051 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3052 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3053 IOERR_NO_RESOURCES
)) {
3054 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3055 phba
->lpfc_rampdown_queue_depth(phba
);
3056 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3059 /* Rsp ring <ringno> error: IOCB */
3060 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3061 "0336 Rsp Ring %d error: IOCB Data: "
3062 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3064 irsp
->un
.ulpWord
[0],
3065 irsp
->un
.ulpWord
[1],
3066 irsp
->un
.ulpWord
[2],
3067 irsp
->un
.ulpWord
[3],
3068 irsp
->un
.ulpWord
[4],
3069 irsp
->un
.ulpWord
[5],
3070 *(uint32_t *)&irsp
->un1
,
3071 *((uint32_t *)&irsp
->un1
+ 1));
3075 case LPFC_ABORT_IOCB
:
3078 * Idle exchange closed via ABTS from port. No iocb
3079 * resources need to be recovered.
3081 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3082 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3083 "0333 IOCB cmd 0x%x"
3084 " processed. Skipping"
3090 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3092 if (unlikely(!cmdiocbq
))
3094 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3095 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3096 if (cmdiocbq
->iocb_cmpl
) {
3097 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3098 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3100 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3103 case LPFC_UNSOL_IOCB
:
3104 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3105 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3106 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3109 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3110 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3111 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3112 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3114 dev_warn(&((phba
->pcidev
)->dev
),
3116 phba
->brd_no
, adaptermsg
);
3118 /* Unknown IOCB command */
3119 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3120 "0334 Unknown IOCB command "
3121 "Data: x%x, x%x x%x x%x x%x\n",
3122 type
, irsp
->ulpCommand
,
3131 * The response IOCB has been processed. Update the ring
3132 * pointer in SLIM. If the port response put pointer has not
3133 * been updated, sync the pgp->rspPutInx and fetch the new port
3134 * response put pointer.
3136 writel(pring
->sli
.sli3
.rspidx
,
3137 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3139 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3140 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3143 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3144 pring
->stats
.iocb_rsp_full
++;
3145 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3146 writel(status
, phba
->CAregaddr
);
3147 readl(phba
->CAregaddr
);
3149 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3150 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3151 pring
->stats
.iocb_cmd_empty
++;
3153 /* Force update of the local copy of cmdGetInx */
3154 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3155 lpfc_sli_resume_iocb(phba
, pring
);
3157 if ((pring
->lpfc_sli_cmd_available
))
3158 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3162 phba
->fcp_ring_in_use
= 0;
3163 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3168 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3169 * @phba: Pointer to HBA context object.
3170 * @pring: Pointer to driver SLI ring object.
3171 * @rspiocbp: Pointer to driver response IOCB object.
3173 * This function is called from the worker thread when there is a slow-path
3174 * response IOCB to process. This function chains all the response iocbs until
3175 * seeing the iocb with the LE bit set. The function will call
3176 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3177 * completion of a command iocb. The function will call the
3178 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3179 * The function frees the resources or calls the completion handler if this
3180 * iocb is an abort completion. The function returns NULL when the response
3181 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3182 * this function shall chain the iocb on to the iocb_continueq and return the
3183 * response iocb passed in.
3185 static struct lpfc_iocbq
*
3186 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3187 struct lpfc_iocbq
*rspiocbp
)
3189 struct lpfc_iocbq
*saveq
;
3190 struct lpfc_iocbq
*cmdiocbp
;
3191 struct lpfc_iocbq
*next_iocb
;
3192 IOCB_t
*irsp
= NULL
;
3193 uint32_t free_saveq
;
3194 uint8_t iocb_cmd_type
;
3195 lpfc_iocb_type type
;
3196 unsigned long iflag
;
3199 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3200 /* First add the response iocb to the countinueq list */
3201 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3202 pring
->iocb_continueq_cnt
++;
3204 /* Now, determine whether the list is completed for processing */
3205 irsp
= &rspiocbp
->iocb
;
3208 * By default, the driver expects to free all resources
3209 * associated with this iocb completion.
3212 saveq
= list_get_first(&pring
->iocb_continueq
,
3213 struct lpfc_iocbq
, list
);
3214 irsp
= &(saveq
->iocb
);
3215 list_del_init(&pring
->iocb_continueq
);
3216 pring
->iocb_continueq_cnt
= 0;
3218 pring
->stats
.iocb_rsp
++;
3221 * If resource errors reported from HBA, reduce
3222 * queuedepths of the SCSI device.
3224 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3225 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3226 IOERR_NO_RESOURCES
)) {
3227 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3228 phba
->lpfc_rampdown_queue_depth(phba
);
3229 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3232 if (irsp
->ulpStatus
) {
3233 /* Rsp ring <ringno> error: IOCB */
3234 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3235 "0328 Rsp Ring %d error: "
3240 "x%x x%x x%x x%x\n",
3242 irsp
->un
.ulpWord
[0],
3243 irsp
->un
.ulpWord
[1],
3244 irsp
->un
.ulpWord
[2],
3245 irsp
->un
.ulpWord
[3],
3246 irsp
->un
.ulpWord
[4],
3247 irsp
->un
.ulpWord
[5],
3248 *(((uint32_t *) irsp
) + 6),
3249 *(((uint32_t *) irsp
) + 7),
3250 *(((uint32_t *) irsp
) + 8),
3251 *(((uint32_t *) irsp
) + 9),
3252 *(((uint32_t *) irsp
) + 10),
3253 *(((uint32_t *) irsp
) + 11),
3254 *(((uint32_t *) irsp
) + 12),
3255 *(((uint32_t *) irsp
) + 13),
3256 *(((uint32_t *) irsp
) + 14),
3257 *(((uint32_t *) irsp
) + 15));
3261 * Fetch the IOCB command type and call the correct completion
3262 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3263 * get freed back to the lpfc_iocb_list by the discovery
3266 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3267 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3270 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3271 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3272 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3275 case LPFC_UNSOL_IOCB
:
3276 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3277 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3278 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3283 case LPFC_ABORT_IOCB
:
3285 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3286 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3289 /* Call the specified completion routine */
3290 if (cmdiocbp
->iocb_cmpl
) {
3291 spin_unlock_irqrestore(&phba
->hbalock
,
3293 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3295 spin_lock_irqsave(&phba
->hbalock
,
3298 __lpfc_sli_release_iocbq(phba
,
3303 case LPFC_UNKNOWN_IOCB
:
3304 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3305 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3306 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3307 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3309 dev_warn(&((phba
->pcidev
)->dev
),
3311 phba
->brd_no
, adaptermsg
);
3313 /* Unknown IOCB command */
3314 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3315 "0335 Unknown IOCB "
3316 "command Data: x%x "
3327 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3328 &saveq
->list
, list
) {
3329 list_del_init(&rspiocbp
->list
);
3330 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3332 __lpfc_sli_release_iocbq(phba
, saveq
);
3336 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3341 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3342 * @phba: Pointer to HBA context object.
3343 * @pring: Pointer to driver SLI ring object.
3344 * @mask: Host attention register mask for this ring.
3346 * This routine wraps the actual slow_ring event process routine from the
3347 * API jump table function pointer from the lpfc_hba struct.
3350 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3351 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3353 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3357 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3358 * @phba: Pointer to HBA context object.
3359 * @pring: Pointer to driver SLI ring object.
3360 * @mask: Host attention register mask for this ring.
3362 * This function is called from the worker thread when there is a ring event
3363 * for non-fcp rings. The caller does not hold any lock. The function will
3364 * remove each response iocb in the response ring and calls the handle
3365 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3368 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3369 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3371 struct lpfc_pgp
*pgp
;
3373 IOCB_t
*irsp
= NULL
;
3374 struct lpfc_iocbq
*rspiocbp
= NULL
;
3375 uint32_t portRspPut
, portRspMax
;
3376 unsigned long iflag
;
3379 pgp
= &phba
->port_gp
[pring
->ringno
];
3380 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3381 pring
->stats
.iocb_event
++;
3384 * The next available response entry should never exceed the maximum
3385 * entries. If it does, treat it as an adapter hardware error.
3387 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3388 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3389 if (portRspPut
>= portRspMax
) {
3391 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3392 * rsp ring <portRspMax>
3394 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3395 "0303 Ring %d handler: portRspPut %d "
3396 "is bigger than rsp ring %d\n",
3397 pring
->ringno
, portRspPut
, portRspMax
);
3399 phba
->link_state
= LPFC_HBA_ERROR
;
3400 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3402 phba
->work_hs
= HS_FFER3
;
3403 lpfc_handle_eratt(phba
);
3409 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3411 * Build a completion list and call the appropriate handler.
3412 * The process is to get the next available response iocb, get
3413 * a free iocb from the list, copy the response data into the
3414 * free iocb, insert to the continuation list, and update the
3415 * next response index to slim. This process makes response
3416 * iocb's in the ring available to DMA as fast as possible but
3417 * pays a penalty for a copy operation. Since the iocb is
3418 * only 32 bytes, this penalty is considered small relative to
3419 * the PCI reads for register values and a slim write. When
3420 * the ulpLe field is set, the entire Command has been
3423 entry
= lpfc_resp_iocb(phba
, pring
);
3425 phba
->last_completion_time
= jiffies
;
3426 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3427 if (rspiocbp
== NULL
) {
3428 printk(KERN_ERR
"%s: out of buffers! Failing "
3429 "completion.\n", __func__
);
3433 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3434 phba
->iocb_rsp_size
);
3435 irsp
= &rspiocbp
->iocb
;
3437 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3438 pring
->sli
.sli3
.rspidx
= 0;
3440 if (pring
->ringno
== LPFC_ELS_RING
) {
3441 lpfc_debugfs_slow_ring_trc(phba
,
3442 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3443 *(((uint32_t *) irsp
) + 4),
3444 *(((uint32_t *) irsp
) + 6),
3445 *(((uint32_t *) irsp
) + 7));
3448 writel(pring
->sli
.sli3
.rspidx
,
3449 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3451 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3452 /* Handle the response IOCB */
3453 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3454 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3457 * If the port response put pointer has not been updated, sync
3458 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3459 * response put pointer.
3461 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3462 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3464 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3466 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3467 /* At least one response entry has been freed */
3468 pring
->stats
.iocb_rsp_full
++;
3469 /* SET RxRE_RSP in Chip Att register */
3470 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3471 writel(status
, phba
->CAregaddr
);
3472 readl(phba
->CAregaddr
); /* flush */
3474 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3475 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3476 pring
->stats
.iocb_cmd_empty
++;
3478 /* Force update of the local copy of cmdGetInx */
3479 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3480 lpfc_sli_resume_iocb(phba
, pring
);
3482 if ((pring
->lpfc_sli_cmd_available
))
3483 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3487 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3492 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3493 * @phba: Pointer to HBA context object.
3494 * @pring: Pointer to driver SLI ring object.
3495 * @mask: Host attention register mask for this ring.
3497 * This function is called from the worker thread when there is a pending
3498 * ELS response iocb on the driver internal slow-path response iocb worker
3499 * queue. The caller does not hold any lock. The function will remove each
3500 * response iocb from the response worker queue and calls the handle
3501 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3504 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3505 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3507 struct lpfc_iocbq
*irspiocbq
;
3508 struct hbq_dmabuf
*dmabuf
;
3509 struct lpfc_cq_event
*cq_event
;
3510 unsigned long iflag
;
3512 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3513 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3514 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3515 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3516 /* Get the response iocb from the head of work queue */
3517 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3518 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3519 cq_event
, struct lpfc_cq_event
, list
);
3520 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3522 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3523 case CQE_CODE_COMPL_WQE
:
3524 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3526 /* Translate ELS WCQE to response IOCBQ */
3527 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3530 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3533 case CQE_CODE_RECEIVE
:
3534 case CQE_CODE_RECEIVE_V1
:
3535 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3537 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3546 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3547 * @phba: Pointer to HBA context object.
3548 * @pring: Pointer to driver SLI ring object.
3550 * This function aborts all iocbs in the given ring and frees all the iocb
3551 * objects in txq. This function issues an abort iocb for all the iocb commands
3552 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3553 * the return of this function. The caller is not required to hold any locks.
3556 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3558 LIST_HEAD(completions
);
3559 struct lpfc_iocbq
*iocb
, *next_iocb
;
3561 if (pring
->ringno
== LPFC_ELS_RING
) {
3562 lpfc_fabric_abort_hba(phba
);
3565 /* Error everything on txq and txcmplq
3568 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3569 spin_lock_irq(&pring
->ring_lock
);
3570 list_splice_init(&pring
->txq
, &completions
);
3572 spin_unlock_irq(&pring
->ring_lock
);
3574 spin_lock_irq(&phba
->hbalock
);
3575 /* Next issue ABTS for everything on the txcmplq */
3576 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3577 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3578 spin_unlock_irq(&phba
->hbalock
);
3580 spin_lock_irq(&phba
->hbalock
);
3581 list_splice_init(&pring
->txq
, &completions
);
3584 /* Next issue ABTS for everything on the txcmplq */
3585 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3586 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3587 spin_unlock_irq(&phba
->hbalock
);
3590 /* Cancel all the IOCBs from the completions list */
3591 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3596 * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
3597 * @phba: Pointer to HBA context object.
3598 * @pring: Pointer to driver SLI ring object.
3600 * This function aborts all iocbs in FCP rings and frees all the iocb
3601 * objects in txq. This function issues an abort iocb for all the iocb commands
3602 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3603 * the return of this function. The caller is not required to hold any locks.
3606 lpfc_sli_abort_fcp_rings(struct lpfc_hba
*phba
)
3608 struct lpfc_sli
*psli
= &phba
->sli
;
3609 struct lpfc_sli_ring
*pring
;
3612 /* Look on all the FCP Rings for the iotag */
3613 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3614 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3615 pring
= &psli
->ring
[i
+ MAX_SLI3_CONFIGURED_RINGS
];
3616 lpfc_sli_abort_iocb_ring(phba
, pring
);
3619 pring
= &psli
->ring
[psli
->fcp_ring
];
3620 lpfc_sli_abort_iocb_ring(phba
, pring
);
3626 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3627 * @phba: Pointer to HBA context object.
3629 * This function flushes all iocbs in the fcp ring and frees all the iocb
3630 * objects in txq and txcmplq. This function will not issue abort iocbs
3631 * for all the iocb commands in txcmplq, they will just be returned with
3632 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3633 * slot has been permanently disabled.
3636 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3640 struct lpfc_sli
*psli
= &phba
->sli
;
3641 struct lpfc_sli_ring
*pring
;
3644 spin_lock_irq(&phba
->hbalock
);
3645 /* Indicate the I/O queues are flushed */
3646 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3647 spin_unlock_irq(&phba
->hbalock
);
3649 /* Look on all the FCP Rings for the iotag */
3650 if (phba
->sli_rev
>= LPFC_SLI_REV4
) {
3651 for (i
= 0; i
< phba
->cfg_fcp_io_channel
; i
++) {
3652 pring
= &psli
->ring
[i
+ MAX_SLI3_CONFIGURED_RINGS
];
3654 spin_lock_irq(&pring
->ring_lock
);
3655 /* Retrieve everything on txq */
3656 list_splice_init(&pring
->txq
, &txq
);
3657 /* Retrieve everything on the txcmplq */
3658 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3660 pring
->txcmplq_cnt
= 0;
3661 spin_unlock_irq(&pring
->ring_lock
);
3664 lpfc_sli_cancel_iocbs(phba
, &txq
,
3665 IOSTAT_LOCAL_REJECT
,
3667 /* Flush the txcmpq */
3668 lpfc_sli_cancel_iocbs(phba
, &txcmplq
,
3669 IOSTAT_LOCAL_REJECT
,
3673 pring
= &psli
->ring
[psli
->fcp_ring
];
3675 spin_lock_irq(&phba
->hbalock
);
3676 /* Retrieve everything on txq */
3677 list_splice_init(&pring
->txq
, &txq
);
3678 /* Retrieve everything on the txcmplq */
3679 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3681 pring
->txcmplq_cnt
= 0;
3682 spin_unlock_irq(&phba
->hbalock
);
3685 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3687 /* Flush the txcmpq */
3688 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3694 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3695 * @phba: Pointer to HBA context object.
3696 * @mask: Bit mask to be checked.
3698 * This function reads the host status register and compares
3699 * with the provided bit mask to check if HBA completed
3700 * the restart. This function will wait in a loop for the
3701 * HBA to complete restart. If the HBA does not restart within
3702 * 15 iterations, the function will reset the HBA again. The
3703 * function returns 1 when HBA fail to restart otherwise returns
3707 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3713 /* Read the HBA Host Status Register */
3714 if (lpfc_readl(phba
->HSregaddr
, &status
))
3718 * Check status register every 100ms for 5 retries, then every
3719 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3720 * every 2.5 sec for 4.
3721 * Break our of the loop if errors occurred during init.
3723 while (((status
& mask
) != mask
) &&
3724 !(status
& HS_FFERM
) &&
3736 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3737 lpfc_sli_brdrestart(phba
);
3739 /* Read the HBA Host Status Register */
3740 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3746 /* Check to see if any errors occurred during init */
3747 if ((status
& HS_FFERM
) || (i
>= 20)) {
3748 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3749 "2751 Adapter failed to restart, "
3750 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3752 readl(phba
->MBslimaddr
+ 0xa8),
3753 readl(phba
->MBslimaddr
+ 0xac));
3754 phba
->link_state
= LPFC_HBA_ERROR
;
3762 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3763 * @phba: Pointer to HBA context object.
3764 * @mask: Bit mask to be checked.
3766 * This function checks the host status register to check if HBA is
3767 * ready. This function will wait in a loop for the HBA to be ready
3768 * If the HBA is not ready , the function will will reset the HBA PCI
3769 * function again. The function returns 1 when HBA fail to be ready
3770 * otherwise returns zero.
3773 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3778 /* Read the HBA Host Status Register */
3779 status
= lpfc_sli4_post_status_check(phba
);
3782 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3783 lpfc_sli_brdrestart(phba
);
3784 status
= lpfc_sli4_post_status_check(phba
);
3787 /* Check to see if any errors occurred during init */
3789 phba
->link_state
= LPFC_HBA_ERROR
;
3792 phba
->sli4_hba
.intr_enable
= 0;
3798 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3799 * @phba: Pointer to HBA context object.
3800 * @mask: Bit mask to be checked.
3802 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3803 * from the API jump table function pointer from the lpfc_hba struct.
3806 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3808 return phba
->lpfc_sli_brdready(phba
, mask
);
3811 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3814 * lpfc_reset_barrier - Make HBA ready for HBA reset
3815 * @phba: Pointer to HBA context object.
3817 * This function is called before resetting an HBA. This function is called
3818 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3820 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3822 uint32_t __iomem
*resp_buf
;
3823 uint32_t __iomem
*mbox_buf
;
3824 volatile uint32_t mbox
;
3825 uint32_t hc_copy
, ha_copy
, resp_data
;
3829 lockdep_assert_held(&phba
->hbalock
);
3831 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3832 if (hdrtype
!= 0x80 ||
3833 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3834 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3838 * Tell the other part of the chip to suspend temporarily all
3841 resp_buf
= phba
->MBslimaddr
;
3843 /* Disable the error attention */
3844 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3846 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3847 readl(phba
->HCregaddr
); /* flush */
3848 phba
->link_flag
|= LS_IGNORE_ERATT
;
3850 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3852 if (ha_copy
& HA_ERATT
) {
3853 /* Clear Chip error bit */
3854 writel(HA_ERATT
, phba
->HAregaddr
);
3855 phba
->pport
->stopped
= 1;
3859 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3860 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3862 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3863 mbox_buf
= phba
->MBslimaddr
;
3864 writel(mbox
, mbox_buf
);
3866 for (i
= 0; i
< 50; i
++) {
3867 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3869 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3875 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3877 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3878 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3879 phba
->pport
->stopped
)
3885 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3887 for (i
= 0; i
< 500; i
++) {
3888 if (lpfc_readl(resp_buf
, &resp_data
))
3890 if (resp_data
!= mbox
)
3899 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3901 if (!(ha_copy
& HA_ERATT
))
3907 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3908 writel(HA_ERATT
, phba
->HAregaddr
);
3909 phba
->pport
->stopped
= 1;
3913 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3914 writel(hc_copy
, phba
->HCregaddr
);
3915 readl(phba
->HCregaddr
); /* flush */
3919 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3920 * @phba: Pointer to HBA context object.
3922 * This function issues a kill_board mailbox command and waits for
3923 * the error attention interrupt. This function is called for stopping
3924 * the firmware processing. The caller is not required to hold any
3925 * locks. This function calls lpfc_hba_down_post function to free
3926 * any pending commands after the kill. The function will return 1 when it
3927 * fails to kill the board else will return 0.
3930 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3932 struct lpfc_sli
*psli
;
3942 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3943 "0329 Kill HBA Data: x%x x%x\n",
3944 phba
->pport
->port_state
, psli
->sli_flag
);
3946 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3950 /* Disable the error attention */
3951 spin_lock_irq(&phba
->hbalock
);
3952 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3953 spin_unlock_irq(&phba
->hbalock
);
3954 mempool_free(pmb
, phba
->mbox_mem_pool
);
3957 status
&= ~HC_ERINT_ENA
;
3958 writel(status
, phba
->HCregaddr
);
3959 readl(phba
->HCregaddr
); /* flush */
3960 phba
->link_flag
|= LS_IGNORE_ERATT
;
3961 spin_unlock_irq(&phba
->hbalock
);
3963 lpfc_kill_board(phba
, pmb
);
3964 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3965 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3967 if (retval
!= MBX_SUCCESS
) {
3968 if (retval
!= MBX_BUSY
)
3969 mempool_free(pmb
, phba
->mbox_mem_pool
);
3970 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3971 "2752 KILL_BOARD command failed retval %d\n",
3973 spin_lock_irq(&phba
->hbalock
);
3974 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3975 spin_unlock_irq(&phba
->hbalock
);
3979 spin_lock_irq(&phba
->hbalock
);
3980 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3981 spin_unlock_irq(&phba
->hbalock
);
3983 mempool_free(pmb
, phba
->mbox_mem_pool
);
3985 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3986 * attention every 100ms for 3 seconds. If we don't get ERATT after
3987 * 3 seconds we still set HBA_ERROR state because the status of the
3988 * board is now undefined.
3990 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3992 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3994 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3998 del_timer_sync(&psli
->mbox_tmo
);
3999 if (ha_copy
& HA_ERATT
) {
4000 writel(HA_ERATT
, phba
->HAregaddr
);
4001 phba
->pport
->stopped
= 1;
4003 spin_lock_irq(&phba
->hbalock
);
4004 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4005 psli
->mbox_active
= NULL
;
4006 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
4007 spin_unlock_irq(&phba
->hbalock
);
4009 lpfc_hba_down_post(phba
);
4010 phba
->link_state
= LPFC_HBA_ERROR
;
4012 return ha_copy
& HA_ERATT
? 0 : 1;
4016 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
4017 * @phba: Pointer to HBA context object.
4019 * This function resets the HBA by writing HC_INITFF to the control
4020 * register. After the HBA resets, this function resets all the iocb ring
4021 * indices. This function disables PCI layer parity checking during
4023 * This function returns 0 always.
4024 * The caller is not required to hold any locks.
4027 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
4029 struct lpfc_sli
*psli
;
4030 struct lpfc_sli_ring
*pring
;
4037 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4038 "0325 Reset HBA Data: x%x x%x\n",
4039 phba
->pport
->port_state
, psli
->sli_flag
);
4041 /* perform board reset */
4042 phba
->fc_eventTag
= 0;
4043 phba
->link_events
= 0;
4044 phba
->pport
->fc_myDID
= 0;
4045 phba
->pport
->fc_prevDID
= 0;
4047 /* Turn off parity checking and serr during the physical reset */
4048 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4049 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
4051 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4053 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
4055 /* Now toggle INITFF bit in the Host Control Register */
4056 writel(HC_INITFF
, phba
->HCregaddr
);
4058 readl(phba
->HCregaddr
); /* flush */
4059 writel(0, phba
->HCregaddr
);
4060 readl(phba
->HCregaddr
); /* flush */
4062 /* Restore PCI cmd register */
4063 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4065 /* Initialize relevant SLI info */
4066 for (i
= 0; i
< psli
->num_rings
; i
++) {
4067 pring
= &psli
->ring
[i
];
4069 pring
->sli
.sli3
.rspidx
= 0;
4070 pring
->sli
.sli3
.next_cmdidx
= 0;
4071 pring
->sli
.sli3
.local_getidx
= 0;
4072 pring
->sli
.sli3
.cmdidx
= 0;
4073 pring
->missbufcnt
= 0;
4076 phba
->link_state
= LPFC_WARM_START
;
4081 * lpfc_sli4_brdreset - Reset a sli-4 HBA
4082 * @phba: Pointer to HBA context object.
4084 * This function resets a SLI4 HBA. This function disables PCI layer parity
4085 * checking during resets the device. The caller is not required to hold
4088 * This function returns 0 always.
4091 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
4093 struct lpfc_sli
*psli
= &phba
->sli
;
4098 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4099 "0295 Reset HBA Data: x%x x%x x%x\n",
4100 phba
->pport
->port_state
, psli
->sli_flag
,
4103 /* perform board reset */
4104 phba
->fc_eventTag
= 0;
4105 phba
->link_events
= 0;
4106 phba
->pport
->fc_myDID
= 0;
4107 phba
->pport
->fc_prevDID
= 0;
4109 spin_lock_irq(&phba
->hbalock
);
4110 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
4111 phba
->fcf
.fcf_flag
= 0;
4112 spin_unlock_irq(&phba
->hbalock
);
4114 /* SLI4 INTF 2: if FW dump is being taken skip INIT_PORT */
4115 if (phba
->hba_flag
& HBA_FW_DUMP_OP
) {
4116 phba
->hba_flag
&= ~HBA_FW_DUMP_OP
;
4120 /* Now physically reset the device */
4121 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4122 "0389 Performing PCI function reset!\n");
4124 /* Turn off parity checking and serr during the physical reset */
4125 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
4126 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
4127 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
4129 /* Perform FCoE PCI function reset before freeing queue memory */
4130 rc
= lpfc_pci_function_reset(phba
);
4131 lpfc_sli4_queue_destroy(phba
);
4133 /* Restore PCI cmd register */
4134 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4140 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4141 * @phba: Pointer to HBA context object.
4143 * This function is called in the SLI initialization code path to
4144 * restart the HBA. The caller is not required to hold any lock.
4145 * This function writes MBX_RESTART mailbox command to the SLIM and
4146 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4147 * function to free any pending commands. The function enables
4148 * POST only during the first initialization. The function returns zero.
4149 * The function does not guarantee completion of MBX_RESTART mailbox
4150 * command before the return of this function.
4153 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4156 struct lpfc_sli
*psli
;
4157 volatile uint32_t word0
;
4158 void __iomem
*to_slim
;
4159 uint32_t hba_aer_enabled
;
4161 spin_lock_irq(&phba
->hbalock
);
4163 /* Take PCIe device Advanced Error Reporting (AER) state */
4164 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4169 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4170 "0337 Restart HBA Data: x%x x%x\n",
4171 phba
->pport
->port_state
, psli
->sli_flag
);
4174 mb
= (MAILBOX_t
*) &word0
;
4175 mb
->mbxCommand
= MBX_RESTART
;
4178 lpfc_reset_barrier(phba
);
4180 to_slim
= phba
->MBslimaddr
;
4181 writel(*(uint32_t *) mb
, to_slim
);
4182 readl(to_slim
); /* flush */
4184 /* Only skip post after fc_ffinit is completed */
4185 if (phba
->pport
->port_state
)
4186 word0
= 1; /* This is really setting up word1 */
4188 word0
= 0; /* This is really setting up word1 */
4189 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4190 writel(*(uint32_t *) mb
, to_slim
);
4191 readl(to_slim
); /* flush */
4193 lpfc_sli_brdreset(phba
);
4194 phba
->pport
->stopped
= 0;
4195 phba
->link_state
= LPFC_INIT_START
;
4197 spin_unlock_irq(&phba
->hbalock
);
4199 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4200 psli
->stats_start
= get_seconds();
4202 /* Give the INITFF and Post time to settle. */
4205 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4206 if (hba_aer_enabled
)
4207 pci_disable_pcie_error_reporting(phba
->pcidev
);
4209 lpfc_hba_down_post(phba
);
4215 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4216 * @phba: Pointer to HBA context object.
4218 * This function is called in the SLI initialization code path to restart
4219 * a SLI4 HBA. The caller is not required to hold any lock.
4220 * At the end of the function, it calls lpfc_hba_down_post function to
4221 * free any pending commands.
4224 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4226 struct lpfc_sli
*psli
= &phba
->sli
;
4227 uint32_t hba_aer_enabled
;
4231 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4232 "0296 Restart HBA Data: x%x x%x\n",
4233 phba
->pport
->port_state
, psli
->sli_flag
);
4235 /* Take PCIe device Advanced Error Reporting (AER) state */
4236 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4238 rc
= lpfc_sli4_brdreset(phba
);
4240 spin_lock_irq(&phba
->hbalock
);
4241 phba
->pport
->stopped
= 0;
4242 phba
->link_state
= LPFC_INIT_START
;
4244 spin_unlock_irq(&phba
->hbalock
);
4246 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4247 psli
->stats_start
= get_seconds();
4249 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4250 if (hba_aer_enabled
)
4251 pci_disable_pcie_error_reporting(phba
->pcidev
);
4253 lpfc_hba_down_post(phba
);
4259 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4260 * @phba: Pointer to HBA context object.
4262 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4263 * API jump table function pointer from the lpfc_hba struct.
4266 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4268 return phba
->lpfc_sli_brdrestart(phba
);
4272 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4273 * @phba: Pointer to HBA context object.
4275 * This function is called after a HBA restart to wait for successful
4276 * restart of the HBA. Successful restart of the HBA is indicated by
4277 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4278 * iteration, the function will restart the HBA again. The function returns
4279 * zero if HBA successfully restarted else returns negative error code.
4282 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4284 uint32_t status
, i
= 0;
4286 /* Read the HBA Host Status Register */
4287 if (lpfc_readl(phba
->HSregaddr
, &status
))
4290 /* Check status register to see what current state is */
4292 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4294 /* Check every 10ms for 10 retries, then every 100ms for 90
4295 * retries, then every 1 sec for 50 retires for a total of
4296 * ~60 seconds before reset the board again and check every
4297 * 1 sec for 50 retries. The up to 60 seconds before the
4298 * board ready is required by the Falcon FIPS zeroization
4299 * complete, and any reset the board in between shall cause
4300 * restart of zeroization, further delay the board ready.
4303 /* Adapter failed to init, timeout, status reg
4305 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4306 "0436 Adapter failed to init, "
4307 "timeout, status reg x%x, "
4308 "FW Data: A8 x%x AC x%x\n", status
,
4309 readl(phba
->MBslimaddr
+ 0xa8),
4310 readl(phba
->MBslimaddr
+ 0xac));
4311 phba
->link_state
= LPFC_HBA_ERROR
;
4315 /* Check to see if any errors occurred during init */
4316 if (status
& HS_FFERM
) {
4317 /* ERROR: During chipset initialization */
4318 /* Adapter failed to init, chipset, status reg
4320 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4321 "0437 Adapter failed to init, "
4322 "chipset, status reg x%x, "
4323 "FW Data: A8 x%x AC x%x\n", status
,
4324 readl(phba
->MBslimaddr
+ 0xa8),
4325 readl(phba
->MBslimaddr
+ 0xac));
4326 phba
->link_state
= LPFC_HBA_ERROR
;
4339 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4340 lpfc_sli_brdrestart(phba
);
4342 /* Read the HBA Host Status Register */
4343 if (lpfc_readl(phba
->HSregaddr
, &status
))
4347 /* Check to see if any errors occurred during init */
4348 if (status
& HS_FFERM
) {
4349 /* ERROR: During chipset initialization */
4350 /* Adapter failed to init, chipset, status reg <status> */
4351 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4352 "0438 Adapter failed to init, chipset, "
4354 "FW Data: A8 x%x AC x%x\n", status
,
4355 readl(phba
->MBslimaddr
+ 0xa8),
4356 readl(phba
->MBslimaddr
+ 0xac));
4357 phba
->link_state
= LPFC_HBA_ERROR
;
4361 /* Clear all interrupt enable conditions */
4362 writel(0, phba
->HCregaddr
);
4363 readl(phba
->HCregaddr
); /* flush */
4365 /* setup host attn register */
4366 writel(0xffffffff, phba
->HAregaddr
);
4367 readl(phba
->HAregaddr
); /* flush */
4372 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4374 * This function calculates and returns the number of HBQs required to be
4378 lpfc_sli_hbq_count(void)
4380 return ARRAY_SIZE(lpfc_hbq_defs
);
4384 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4386 * This function adds the number of hbq entries in every HBQ to get
4387 * the total number of hbq entries required for the HBA and returns
4391 lpfc_sli_hbq_entry_count(void)
4393 int hbq_count
= lpfc_sli_hbq_count();
4397 for (i
= 0; i
< hbq_count
; ++i
)
4398 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4403 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4405 * This function calculates amount of memory required for all hbq entries
4406 * to be configured and returns the total memory required.
4409 lpfc_sli_hbq_size(void)
4411 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4415 * lpfc_sli_hbq_setup - configure and initialize HBQs
4416 * @phba: Pointer to HBA context object.
4418 * This function is called during the SLI initialization to configure
4419 * all the HBQs and post buffers to the HBQ. The caller is not
4420 * required to hold any locks. This function will return zero if successful
4421 * else it will return negative error code.
4424 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4426 int hbq_count
= lpfc_sli_hbq_count();
4430 uint32_t hbq_entry_index
;
4432 /* Get a Mailbox buffer to setup mailbox
4433 * commands for HBA initialization
4435 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4442 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4443 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4444 phba
->hbq_in_use
= 1;
4446 hbq_entry_index
= 0;
4447 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4448 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4449 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4450 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4451 phba
->hbqs
[hbqno
].entry_count
=
4452 lpfc_hbq_defs
[hbqno
]->entry_count
;
4453 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4454 hbq_entry_index
, pmb
);
4455 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4457 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4458 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4459 mbxStatus <status>, ring <num> */
4461 lpfc_printf_log(phba
, KERN_ERR
,
4462 LOG_SLI
| LOG_VPORT
,
4463 "1805 Adapter failed to init. "
4464 "Data: x%x x%x x%x\n",
4466 pmbox
->mbxStatus
, hbqno
);
4468 phba
->link_state
= LPFC_HBA_ERROR
;
4469 mempool_free(pmb
, phba
->mbox_mem_pool
);
4473 phba
->hbq_count
= hbq_count
;
4475 mempool_free(pmb
, phba
->mbox_mem_pool
);
4477 /* Initially populate or replenish the HBQs */
4478 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4479 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4484 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4485 * @phba: Pointer to HBA context object.
4487 * This function is called during the SLI initialization to configure
4488 * all the HBQs and post buffers to the HBQ. The caller is not
4489 * required to hold any locks. This function will return zero if successful
4490 * else it will return negative error code.
4493 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4495 phba
->hbq_in_use
= 1;
4496 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4497 phba
->hbq_count
= 1;
4498 /* Initially populate or replenish the HBQs */
4499 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4504 * lpfc_sli_config_port - Issue config port mailbox command
4505 * @phba: Pointer to HBA context object.
4506 * @sli_mode: sli mode - 2/3
4508 * This function is called by the sli intialization code path
4509 * to issue config_port mailbox command. This function restarts the
4510 * HBA firmware and issues a config_port mailbox command to configure
4511 * the SLI interface in the sli mode specified by sli_mode
4512 * variable. The caller is not required to hold any locks.
4513 * The function returns 0 if successful, else returns negative error
4517 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4520 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4522 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4524 phba
->link_state
= LPFC_HBA_ERROR
;
4528 phba
->sli_rev
= sli_mode
;
4529 while (resetcount
< 2 && !done
) {
4530 spin_lock_irq(&phba
->hbalock
);
4531 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4532 spin_unlock_irq(&phba
->hbalock
);
4533 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4534 lpfc_sli_brdrestart(phba
);
4535 rc
= lpfc_sli_chipset_init(phba
);
4539 spin_lock_irq(&phba
->hbalock
);
4540 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4541 spin_unlock_irq(&phba
->hbalock
);
4544 /* Call pre CONFIG_PORT mailbox command initialization. A
4545 * value of 0 means the call was successful. Any other
4546 * nonzero value is a failure, but if ERESTART is returned,
4547 * the driver may reset the HBA and try again.
4549 rc
= lpfc_config_port_prep(phba
);
4550 if (rc
== -ERESTART
) {
4551 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4556 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4557 lpfc_config_port(phba
, pmb
);
4558 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4559 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4560 LPFC_SLI3_HBQ_ENABLED
|
4561 LPFC_SLI3_CRP_ENABLED
|
4562 LPFC_SLI3_BG_ENABLED
|
4563 LPFC_SLI3_DSS_ENABLED
);
4564 if (rc
!= MBX_SUCCESS
) {
4565 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4566 "0442 Adapter failed to init, mbxCmd x%x "
4567 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4568 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4569 spin_lock_irq(&phba
->hbalock
);
4570 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4571 spin_unlock_irq(&phba
->hbalock
);
4574 /* Allow asynchronous mailbox command to go through */
4575 spin_lock_irq(&phba
->hbalock
);
4576 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4577 spin_unlock_irq(&phba
->hbalock
);
4580 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4581 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4582 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4583 "3110 Port did not grant ASABT\n");
4588 goto do_prep_failed
;
4590 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4591 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4593 goto do_prep_failed
;
4595 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4596 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4597 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4598 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4599 phba
->max_vpi
: phba
->max_vports
;
4603 phba
->fips_level
= 0;
4604 phba
->fips_spec_rev
= 0;
4605 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4606 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4607 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4608 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4609 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4610 "2850 Security Crypto Active. FIPS x%d "
4612 phba
->fips_level
, phba
->fips_spec_rev
);
4614 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4615 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4616 "2856 Config Port Security Crypto "
4618 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4620 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4621 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4622 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4623 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4625 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4626 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4628 if (phba
->cfg_enable_bg
) {
4629 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4630 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4632 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4633 "0443 Adapter did not grant "
4637 phba
->hbq_get
= NULL
;
4638 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4642 mempool_free(pmb
, phba
->mbox_mem_pool
);
4648 * lpfc_sli_hba_setup - SLI intialization function
4649 * @phba: Pointer to HBA context object.
4651 * This function is the main SLI intialization function. This function
4652 * is called by the HBA intialization code, HBA reset code and HBA
4653 * error attention handler code. Caller is not required to hold any
4654 * locks. This function issues config_port mailbox command to configure
4655 * the SLI, setup iocb rings and HBQ rings. In the end the function
4656 * calls the config_port_post function to issue init_link mailbox
4657 * command and to start the discovery. The function will return zero
4658 * if successful, else it will return negative error code.
4661 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4667 switch (phba
->cfg_sli_mode
) {
4669 if (phba
->cfg_enable_npiv
) {
4670 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4671 "1824 NPIV enabled: Override sli_mode "
4672 "parameter (%d) to auto (0).\n",
4673 phba
->cfg_sli_mode
);
4682 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4683 "1819 Unrecognized sli_mode parameter: %d.\n",
4684 phba
->cfg_sli_mode
);
4688 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
4690 rc
= lpfc_sli_config_port(phba
, mode
);
4692 if (rc
&& phba
->cfg_sli_mode
== 3)
4693 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4694 "1820 Unable to select SLI-3. "
4695 "Not supported by adapter.\n");
4696 if (rc
&& mode
!= 2)
4697 rc
= lpfc_sli_config_port(phba
, 2);
4698 else if (rc
&& mode
== 2)
4699 rc
= lpfc_sli_config_port(phba
, 3);
4701 goto lpfc_sli_hba_setup_error
;
4703 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4704 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4705 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4707 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4708 "2709 This device supports "
4709 "Advanced Error Reporting (AER)\n");
4710 spin_lock_irq(&phba
->hbalock
);
4711 phba
->hba_flag
|= HBA_AER_ENABLED
;
4712 spin_unlock_irq(&phba
->hbalock
);
4714 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4715 "2708 This device does not support "
4716 "Advanced Error Reporting (AER): %d\n",
4718 phba
->cfg_aer_support
= 0;
4722 if (phba
->sli_rev
== 3) {
4723 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4724 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4726 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4727 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4728 phba
->sli3_options
= 0;
4731 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4732 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4733 phba
->sli_rev
, phba
->max_vpi
);
4734 rc
= lpfc_sli_ring_map(phba
);
4737 goto lpfc_sli_hba_setup_error
;
4739 /* Initialize VPIs. */
4740 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4742 * The VPI bitmask and physical ID array are allocated
4743 * and initialized once only - at driver load. A port
4744 * reset doesn't need to reinitialize this memory.
4746 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4747 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4748 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4750 if (!phba
->vpi_bmask
) {
4752 goto lpfc_sli_hba_setup_error
;
4755 phba
->vpi_ids
= kzalloc(
4756 (phba
->max_vpi
+1) * sizeof(uint16_t),
4758 if (!phba
->vpi_ids
) {
4759 kfree(phba
->vpi_bmask
);
4761 goto lpfc_sli_hba_setup_error
;
4763 for (i
= 0; i
< phba
->max_vpi
; i
++)
4764 phba
->vpi_ids
[i
] = i
;
4769 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4770 rc
= lpfc_sli_hbq_setup(phba
);
4772 goto lpfc_sli_hba_setup_error
;
4774 spin_lock_irq(&phba
->hbalock
);
4775 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4776 spin_unlock_irq(&phba
->hbalock
);
4778 rc
= lpfc_config_port_post(phba
);
4780 goto lpfc_sli_hba_setup_error
;
4784 lpfc_sli_hba_setup_error
:
4785 phba
->link_state
= LPFC_HBA_ERROR
;
4786 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4787 "0445 Firmware initialization failed\n");
4792 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4793 * @phba: Pointer to HBA context object.
4794 * @mboxq: mailbox pointer.
4795 * This function issue a dump mailbox command to read config region
4796 * 23 and parse the records in the region and populate driver
4800 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4802 LPFC_MBOXQ_t
*mboxq
;
4803 struct lpfc_dmabuf
*mp
;
4804 struct lpfc_mqe
*mqe
;
4805 uint32_t data_length
;
4808 /* Program the default value of vlan_id and fc_map */
4809 phba
->valid_vlan
= 0;
4810 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4811 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4812 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4814 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4818 mqe
= &mboxq
->u
.mqe
;
4819 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4821 goto out_free_mboxq
;
4824 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4825 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4827 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4828 "(%d):2571 Mailbox cmd x%x Status x%x "
4829 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4830 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4831 "CQ: x%x x%x x%x x%x\n",
4832 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4833 bf_get(lpfc_mqe_command
, mqe
),
4834 bf_get(lpfc_mqe_status
, mqe
),
4835 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4836 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4837 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4838 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4839 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4840 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4841 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4842 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4843 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4845 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4846 mboxq
->mcqe
.trailer
);
4849 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4852 goto out_free_mboxq
;
4854 data_length
= mqe
->un
.mb_words
[5];
4855 if (data_length
> DMP_RGN23_SIZE
) {
4856 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4859 goto out_free_mboxq
;
4862 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4863 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4868 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4873 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4874 * @phba: pointer to lpfc hba data structure.
4875 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4876 * @vpd: pointer to the memory to hold resulting port vpd data.
4877 * @vpd_size: On input, the number of bytes allocated to @vpd.
4878 * On output, the number of data bytes in @vpd.
4880 * This routine executes a READ_REV SLI4 mailbox command. In
4881 * addition, this routine gets the port vpd data.
4885 * -ENOMEM - could not allocated memory.
4888 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4889 uint8_t *vpd
, uint32_t *vpd_size
)
4893 struct lpfc_dmabuf
*dmabuf
;
4894 struct lpfc_mqe
*mqe
;
4896 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4901 * Get a DMA buffer for the vpd data resulting from the READ_REV
4904 dma_size
= *vpd_size
;
4905 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
, dma_size
,
4906 &dmabuf
->phys
, GFP_KERNEL
);
4907 if (!dmabuf
->virt
) {
4913 * The SLI4 implementation of READ_REV conflicts at word1,
4914 * bits 31:16 and SLI4 adds vpd functionality not present
4915 * in SLI3. This code corrects the conflicts.
4917 lpfc_read_rev(phba
, mboxq
);
4918 mqe
= &mboxq
->u
.mqe
;
4919 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4920 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4921 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4922 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4923 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4925 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4927 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4928 dmabuf
->virt
, dmabuf
->phys
);
4934 * The available vpd length cannot be bigger than the
4935 * DMA buffer passed to the port. Catch the less than
4936 * case and update the caller's size.
4938 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4939 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4941 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4943 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4944 dmabuf
->virt
, dmabuf
->phys
);
4950 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4951 * @phba: pointer to lpfc hba data structure.
4953 * This routine retrieves SLI4 device physical port name this PCI function
4958 * otherwise - failed to retrieve physical port name
4961 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4963 LPFC_MBOXQ_t
*mboxq
;
4964 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4965 struct lpfc_controller_attribute
*cntl_attr
;
4966 struct lpfc_mbx_get_port_name
*get_port_name
;
4967 void *virtaddr
= NULL
;
4968 uint32_t alloclen
, reqlen
;
4969 uint32_t shdr_status
, shdr_add_status
;
4970 union lpfc_sli4_cfg_shdr
*shdr
;
4971 char cport_name
= 0;
4974 /* We assume nothing at this point */
4975 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4976 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4978 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4981 /* obtain link type and link number via READ_CONFIG */
4982 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4983 lpfc_sli4_read_config(phba
);
4984 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4985 goto retrieve_ppname
;
4987 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4988 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4989 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4990 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4991 LPFC_SLI4_MBX_NEMBED
);
4992 if (alloclen
< reqlen
) {
4993 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4994 "3084 Allocated DMA memory size (%d) is "
4995 "less than the requested DMA memory size "
4996 "(%d)\n", alloclen
, reqlen
);
4998 goto out_free_mboxq
;
5000 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5001 virtaddr
= mboxq
->sge_array
->addr
[0];
5002 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
5003 shdr
= &mbx_cntl_attr
->cfg_shdr
;
5004 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5005 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5006 if (shdr_status
|| shdr_add_status
|| rc
) {
5007 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5008 "3085 Mailbox x%x (x%x/x%x) failed, "
5009 "rc:x%x, status:x%x, add_status:x%x\n",
5010 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5011 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5012 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5013 rc
, shdr_status
, shdr_add_status
);
5015 goto out_free_mboxq
;
5017 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
5018 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
5019 phba
->sli4_hba
.lnk_info
.lnk_tp
=
5020 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
5021 phba
->sli4_hba
.lnk_info
.lnk_no
=
5022 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
5023 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5024 "3086 lnk_type:%d, lnk_numb:%d\n",
5025 phba
->sli4_hba
.lnk_info
.lnk_tp
,
5026 phba
->sli4_hba
.lnk_info
.lnk_no
);
5029 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5030 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
5031 sizeof(struct lpfc_mbx_get_port_name
) -
5032 sizeof(struct lpfc_sli4_cfg_mhdr
),
5033 LPFC_SLI4_MBX_EMBED
);
5034 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
5035 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
5036 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
5037 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
5038 phba
->sli4_hba
.lnk_info
.lnk_tp
);
5039 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5040 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5041 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5042 if (shdr_status
|| shdr_add_status
|| rc
) {
5043 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
5044 "3087 Mailbox x%x (x%x/x%x) failed: "
5045 "rc:x%x, status:x%x, add_status:x%x\n",
5046 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
5047 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
5048 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
5049 rc
, shdr_status
, shdr_add_status
);
5051 goto out_free_mboxq
;
5053 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
5054 case LPFC_LINK_NUMBER_0
:
5055 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
5056 &get_port_name
->u
.response
);
5057 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5059 case LPFC_LINK_NUMBER_1
:
5060 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
5061 &get_port_name
->u
.response
);
5062 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5064 case LPFC_LINK_NUMBER_2
:
5065 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
5066 &get_port_name
->u
.response
);
5067 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5069 case LPFC_LINK_NUMBER_3
:
5070 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
5071 &get_port_name
->u
.response
);
5072 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
5078 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
5079 phba
->Port
[0] = cport_name
;
5080 phba
->Port
[1] = '\0';
5081 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5082 "3091 SLI get port name: %s\n", phba
->Port
);
5086 if (rc
!= MBX_TIMEOUT
) {
5087 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
5088 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
5090 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5096 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
5097 * @phba: pointer to lpfc hba data structure.
5099 * This routine is called to explicitly arm the SLI4 device's completion and
5103 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
5107 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
5108 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
5110 if (phba
->sli4_hba
.fcp_cq
) {
5112 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
5114 } while (++fcp_eqidx
< phba
->cfg_fcp_io_channel
);
5118 lpfc_sli4_cq_release(phba
->sli4_hba
.oas_cq
, LPFC_QUEUE_REARM
);
5120 if (phba
->sli4_hba
.hba_eq
) {
5121 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
5123 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
5128 lpfc_sli4_eq_release(phba
->sli4_hba
.fof_eq
, LPFC_QUEUE_REARM
);
5132 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
5133 * @phba: Pointer to HBA context object.
5134 * @type: The resource extent type.
5135 * @extnt_count: buffer to hold port available extent count.
5136 * @extnt_size: buffer to hold element count per extent.
5138 * This function calls the port and retrievs the number of available
5139 * extents and their size for a particular extent type.
5141 * Returns: 0 if successful. Nonzero otherwise.
5144 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5145 uint16_t *extnt_count
, uint16_t *extnt_size
)
5150 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5153 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5157 /* Find out how many extents are available for this resource type */
5158 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5159 sizeof(struct lpfc_sli4_cfg_mhdr
));
5160 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5161 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5162 length
, LPFC_SLI4_MBX_EMBED
);
5164 /* Send an extents count of 0 - the GET doesn't use it. */
5165 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5166 LPFC_SLI4_MBX_EMBED
);
5172 if (!phba
->sli4_hba
.intr_enable
)
5173 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5175 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5176 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5183 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5184 if (bf_get(lpfc_mbox_hdr_status
,
5185 &rsrc_info
->header
.cfg_shdr
.response
)) {
5186 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5187 "2930 Failed to get resource extents "
5188 "Status 0x%x Add'l Status 0x%x\n",
5189 bf_get(lpfc_mbox_hdr_status
,
5190 &rsrc_info
->header
.cfg_shdr
.response
),
5191 bf_get(lpfc_mbox_hdr_add_status
,
5192 &rsrc_info
->header
.cfg_shdr
.response
));
5197 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5199 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5202 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5203 "3162 Retrieved extents type-%d from port: count:%d, "
5204 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5207 mempool_free(mbox
, phba
->mbox_mem_pool
);
5212 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5213 * @phba: Pointer to HBA context object.
5214 * @type: The extent type to check.
5216 * This function reads the current available extents from the port and checks
5217 * if the extent count or extent size has changed since the last access.
5218 * Callers use this routine post port reset to understand if there is a
5219 * extent reprovisioning requirement.
5222 * -Error: error indicates problem.
5223 * 1: Extent count or size has changed.
5227 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5229 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5230 uint16_t size_diff
, rsrc_ext_size
;
5232 struct lpfc_rsrc_blks
*rsrc_entry
;
5233 struct list_head
*rsrc_blk_list
= NULL
;
5237 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5244 case LPFC_RSC_TYPE_FCOE_RPI
:
5245 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5247 case LPFC_RSC_TYPE_FCOE_VPI
:
5248 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5250 case LPFC_RSC_TYPE_FCOE_XRI
:
5251 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5253 case LPFC_RSC_TYPE_FCOE_VFI
:
5254 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5260 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5262 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5266 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5273 * lpfc_sli4_cfg_post_extnts -
5274 * @phba: Pointer to HBA context object.
5275 * @extnt_cnt - number of available extents.
5276 * @type - the extent type (rpi, xri, vfi, vpi).
5277 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5278 * @mbox - pointer to the caller's allocated mailbox structure.
5280 * This function executes the extents allocation request. It also
5281 * takes care of the amount of memory needed to allocate or get the
5282 * allocated extents. It is the caller's responsibility to evaluate
5286 * -Error: Error value describes the condition found.
5290 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5291 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5296 uint32_t alloc_len
, mbox_tmo
;
5298 /* Calculate the total requested length of the dma memory */
5299 req_len
= extnt_cnt
* sizeof(uint16_t);
5302 * Calculate the size of an embedded mailbox. The uint32_t
5303 * accounts for extents-specific word.
5305 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5309 * Presume the allocation and response will fit into an embedded
5310 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5312 *emb
= LPFC_SLI4_MBX_EMBED
;
5313 if (req_len
> emb_len
) {
5314 req_len
= extnt_cnt
* sizeof(uint16_t) +
5315 sizeof(union lpfc_sli4_cfg_shdr
) +
5317 *emb
= LPFC_SLI4_MBX_NEMBED
;
5320 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5321 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5323 if (alloc_len
< req_len
) {
5324 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5325 "2982 Allocated DMA memory size (x%x) is "
5326 "less than the requested DMA memory "
5327 "size (x%x)\n", alloc_len
, req_len
);
5330 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5334 if (!phba
->sli4_hba
.intr_enable
)
5335 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5337 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5338 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5347 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5348 * @phba: Pointer to HBA context object.
5349 * @type: The resource extent type to allocate.
5351 * This function allocates the number of elements for the specified
5355 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5358 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5359 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5362 unsigned long longs
;
5363 unsigned long *bmask
;
5364 struct lpfc_rsrc_blks
*rsrc_blks
;
5367 struct lpfc_id_range
*id_array
= NULL
;
5368 void *virtaddr
= NULL
;
5369 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5370 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5371 struct list_head
*ext_blk_list
;
5373 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5379 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5380 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5381 "3009 No available Resource Extents "
5382 "for resource type 0x%x: Count: 0x%x, "
5383 "Size 0x%x\n", type
, rsrc_cnt
,
5388 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5389 "2903 Post resource extents type-0x%x: "
5390 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5392 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5396 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5403 * Figure out where the response is located. Then get local pointers
5404 * to the response data. The port does not guarantee to respond to
5405 * all extents counts request so update the local variable with the
5406 * allocated count from the port.
5408 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5409 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5410 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5411 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5413 virtaddr
= mbox
->sge_array
->addr
[0];
5414 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5415 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5416 id_array
= &n_rsrc
->id
;
5419 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5420 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5423 * Based on the resource size and count, correct the base and max
5426 length
= sizeof(struct lpfc_rsrc_blks
);
5428 case LPFC_RSC_TYPE_FCOE_RPI
:
5429 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5430 sizeof(unsigned long),
5432 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5436 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5439 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5440 kfree(phba
->sli4_hba
.rpi_bmask
);
5446 * The next_rpi was initialized with the maximum available
5447 * count but the port may allocate a smaller number. Catch
5448 * that case and update the next_rpi.
5450 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5452 /* Initialize local ptrs for common extent processing later. */
5453 bmask
= phba
->sli4_hba
.rpi_bmask
;
5454 ids
= phba
->sli4_hba
.rpi_ids
;
5455 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5457 case LPFC_RSC_TYPE_FCOE_VPI
:
5458 phba
->vpi_bmask
= kzalloc(longs
*
5459 sizeof(unsigned long),
5461 if (unlikely(!phba
->vpi_bmask
)) {
5465 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5468 if (unlikely(!phba
->vpi_ids
)) {
5469 kfree(phba
->vpi_bmask
);
5474 /* Initialize local ptrs for common extent processing later. */
5475 bmask
= phba
->vpi_bmask
;
5476 ids
= phba
->vpi_ids
;
5477 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5479 case LPFC_RSC_TYPE_FCOE_XRI
:
5480 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5481 sizeof(unsigned long),
5483 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5487 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5488 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5491 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5492 kfree(phba
->sli4_hba
.xri_bmask
);
5497 /* Initialize local ptrs for common extent processing later. */
5498 bmask
= phba
->sli4_hba
.xri_bmask
;
5499 ids
= phba
->sli4_hba
.xri_ids
;
5500 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5502 case LPFC_RSC_TYPE_FCOE_VFI
:
5503 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5504 sizeof(unsigned long),
5506 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5510 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5513 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5514 kfree(phba
->sli4_hba
.vfi_bmask
);
5519 /* Initialize local ptrs for common extent processing later. */
5520 bmask
= phba
->sli4_hba
.vfi_bmask
;
5521 ids
= phba
->sli4_hba
.vfi_ids
;
5522 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5525 /* Unsupported Opcode. Fail call. */
5529 ext_blk_list
= NULL
;
5534 * Complete initializing the extent configuration with the
5535 * allocated ids assigned to this function. The bitmask serves
5536 * as an index into the array and manages the available ids. The
5537 * array just stores the ids communicated to the port via the wqes.
5539 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5541 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5544 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5547 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5548 if (unlikely(!rsrc_blks
)) {
5554 rsrc_blks
->rsrc_start
= rsrc_id
;
5555 rsrc_blks
->rsrc_size
= rsrc_size
;
5556 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5557 rsrc_start
= rsrc_id
;
5558 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5559 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5560 lpfc_sli4_get_els_iocb_cnt(phba
);
5562 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5567 /* Entire word processed. Get next word.*/
5572 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5577 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5578 * @phba: Pointer to HBA context object.
5579 * @type: the extent's type.
5581 * This function deallocates all extents of a particular resource type.
5582 * SLI4 does not allow for deallocating a particular extent range. It
5583 * is the caller's responsibility to release all kernel memory resources.
5586 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5589 uint32_t length
, mbox_tmo
= 0;
5591 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5592 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5594 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5599 * This function sends an embedded mailbox because it only sends the
5600 * the resource type. All extents of this type are released by the
5603 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5604 sizeof(struct lpfc_sli4_cfg_mhdr
));
5605 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5606 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5607 length
, LPFC_SLI4_MBX_EMBED
);
5609 /* Send an extents count of 0 - the dealloc doesn't use it. */
5610 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5611 LPFC_SLI4_MBX_EMBED
);
5616 if (!phba
->sli4_hba
.intr_enable
)
5617 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5619 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5620 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5627 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5628 if (bf_get(lpfc_mbox_hdr_status
,
5629 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5630 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5631 "2919 Failed to release resource extents "
5632 "for type %d - Status 0x%x Add'l Status 0x%x. "
5633 "Resource memory not released.\n",
5635 bf_get(lpfc_mbox_hdr_status
,
5636 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5637 bf_get(lpfc_mbox_hdr_add_status
,
5638 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5643 /* Release kernel memory resources for the specific type. */
5645 case LPFC_RSC_TYPE_FCOE_VPI
:
5646 kfree(phba
->vpi_bmask
);
5647 kfree(phba
->vpi_ids
);
5648 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5649 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5650 &phba
->lpfc_vpi_blk_list
, list
) {
5651 list_del_init(&rsrc_blk
->list
);
5654 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5656 case LPFC_RSC_TYPE_FCOE_XRI
:
5657 kfree(phba
->sli4_hba
.xri_bmask
);
5658 kfree(phba
->sli4_hba
.xri_ids
);
5659 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5660 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5661 list_del_init(&rsrc_blk
->list
);
5665 case LPFC_RSC_TYPE_FCOE_VFI
:
5666 kfree(phba
->sli4_hba
.vfi_bmask
);
5667 kfree(phba
->sli4_hba
.vfi_ids
);
5668 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5669 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5670 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5671 list_del_init(&rsrc_blk
->list
);
5675 case LPFC_RSC_TYPE_FCOE_RPI
:
5676 /* RPI bitmask and physical id array are cleaned up earlier. */
5677 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5678 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5679 list_del_init(&rsrc_blk
->list
);
5687 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5690 mempool_free(mbox
, phba
->mbox_mem_pool
);
5695 lpfc_set_features(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
,
5700 len
= sizeof(struct lpfc_mbx_set_feature
) -
5701 sizeof(struct lpfc_sli4_cfg_mhdr
);
5702 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5703 LPFC_MBOX_OPCODE_SET_FEATURES
, len
,
5704 LPFC_SLI4_MBX_EMBED
);
5707 case LPFC_SET_UE_RECOVERY
:
5708 bf_set(lpfc_mbx_set_feature_UER
,
5709 &mbox
->u
.mqe
.un
.set_feature
, 1);
5710 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_UE_RECOVERY
;
5711 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5713 case LPFC_SET_MDS_DIAGS
:
5714 bf_set(lpfc_mbx_set_feature_mds
,
5715 &mbox
->u
.mqe
.un
.set_feature
, 1);
5716 bf_set(lpfc_mbx_set_feature_mds_deep_loopbk
,
5717 &mbox
->u
.mqe
.un
.set_feature
, 0);
5718 mbox
->u
.mqe
.un
.set_feature
.feature
= LPFC_SET_MDS_DIAGS
;
5719 mbox
->u
.mqe
.un
.set_feature
.param_len
= 8;
5727 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5728 * @phba: Pointer to HBA context object.
5730 * This function allocates all SLI4 resource identifiers.
5733 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5735 int i
, rc
, error
= 0;
5736 uint16_t count
, base
;
5737 unsigned long longs
;
5739 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5740 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5741 if (phba
->sli4_hba
.extents_in_use
) {
5743 * The port supports resource extents. The XRI, VPI, VFI, RPI
5744 * resource extent count must be read and allocated before
5745 * provisioning the resource id arrays.
5747 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5748 LPFC_IDX_RSRC_RDY
) {
5750 * Extent-based resources are set - the driver could
5751 * be in a port reset. Figure out if any corrective
5752 * actions need to be taken.
5754 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5755 LPFC_RSC_TYPE_FCOE_VFI
);
5758 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5759 LPFC_RSC_TYPE_FCOE_VPI
);
5762 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5763 LPFC_RSC_TYPE_FCOE_XRI
);
5766 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5767 LPFC_RSC_TYPE_FCOE_RPI
);
5772 * It's possible that the number of resources
5773 * provided to this port instance changed between
5774 * resets. Detect this condition and reallocate
5775 * resources. Otherwise, there is no action.
5778 lpfc_printf_log(phba
, KERN_INFO
,
5779 LOG_MBOX
| LOG_INIT
,
5780 "2931 Detected extent resource "
5781 "change. Reallocating all "
5783 rc
= lpfc_sli4_dealloc_extent(phba
,
5784 LPFC_RSC_TYPE_FCOE_VFI
);
5785 rc
= lpfc_sli4_dealloc_extent(phba
,
5786 LPFC_RSC_TYPE_FCOE_VPI
);
5787 rc
= lpfc_sli4_dealloc_extent(phba
,
5788 LPFC_RSC_TYPE_FCOE_XRI
);
5789 rc
= lpfc_sli4_dealloc_extent(phba
,
5790 LPFC_RSC_TYPE_FCOE_RPI
);
5795 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5799 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5803 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5807 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5810 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5815 * The port does not support resource extents. The XRI, VPI,
5816 * VFI, RPI resource ids were determined from READ_CONFIG.
5817 * Just allocate the bitmasks and provision the resource id
5818 * arrays. If a port reset is active, the resources don't
5819 * need any action - just exit.
5821 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5822 LPFC_IDX_RSRC_RDY
) {
5823 lpfc_sli4_dealloc_resource_identifiers(phba
);
5824 lpfc_sli4_remove_rpis(phba
);
5827 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5829 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5830 "3279 Invalid provisioning of "
5835 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5836 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5837 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5838 sizeof(unsigned long),
5840 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5844 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5847 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5849 goto free_rpi_bmask
;
5852 for (i
= 0; i
< count
; i
++)
5853 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5856 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5858 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5859 "3280 Invalid provisioning of "
5864 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5865 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5866 phba
->vpi_bmask
= kzalloc(longs
*
5867 sizeof(unsigned long),
5869 if (unlikely(!phba
->vpi_bmask
)) {
5873 phba
->vpi_ids
= kzalloc(count
*
5876 if (unlikely(!phba
->vpi_ids
)) {
5878 goto free_vpi_bmask
;
5881 for (i
= 0; i
< count
; i
++)
5882 phba
->vpi_ids
[i
] = base
+ i
;
5885 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5887 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5888 "3281 Invalid provisioning of "
5893 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5894 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5895 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5896 sizeof(unsigned long),
5898 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5902 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5903 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5906 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5908 goto free_xri_bmask
;
5911 for (i
= 0; i
< count
; i
++)
5912 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5915 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5917 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5918 "3282 Invalid provisioning of "
5923 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5924 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5925 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5926 sizeof(unsigned long),
5928 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5932 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5935 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5937 goto free_vfi_bmask
;
5940 for (i
= 0; i
< count
; i
++)
5941 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5944 * Mark all resources ready. An HBA reset doesn't need
5945 * to reset the initialization.
5947 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5953 kfree(phba
->sli4_hba
.vfi_bmask
);
5955 kfree(phba
->sli4_hba
.xri_ids
);
5957 kfree(phba
->sli4_hba
.xri_bmask
);
5959 kfree(phba
->vpi_ids
);
5961 kfree(phba
->vpi_bmask
);
5963 kfree(phba
->sli4_hba
.rpi_ids
);
5965 kfree(phba
->sli4_hba
.rpi_bmask
);
5971 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5972 * @phba: Pointer to HBA context object.
5974 * This function allocates the number of elements for the specified
5978 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5980 if (phba
->sli4_hba
.extents_in_use
) {
5981 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5982 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5983 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5984 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5986 kfree(phba
->vpi_bmask
);
5987 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5988 kfree(phba
->vpi_ids
);
5989 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5990 kfree(phba
->sli4_hba
.xri_bmask
);
5991 kfree(phba
->sli4_hba
.xri_ids
);
5992 kfree(phba
->sli4_hba
.vfi_bmask
);
5993 kfree(phba
->sli4_hba
.vfi_ids
);
5994 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5995 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
6002 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
6003 * @phba: Pointer to HBA context object.
6004 * @type: The resource extent type.
6005 * @extnt_count: buffer to hold port extent count response
6006 * @extnt_size: buffer to hold port extent size response.
6008 * This function calls the port to read the host allocated extents
6009 * for a particular type.
6012 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
6013 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
6017 uint16_t curr_blks
= 0;
6018 uint32_t req_len
, emb_len
;
6019 uint32_t alloc_len
, mbox_tmo
;
6020 struct list_head
*blk_list_head
;
6021 struct lpfc_rsrc_blks
*rsrc_blk
;
6023 void *virtaddr
= NULL
;
6024 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
6025 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
6026 union lpfc_sli4_cfg_shdr
*shdr
;
6029 case LPFC_RSC_TYPE_FCOE_VPI
:
6030 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
6032 case LPFC_RSC_TYPE_FCOE_XRI
:
6033 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
6035 case LPFC_RSC_TYPE_FCOE_VFI
:
6036 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
6038 case LPFC_RSC_TYPE_FCOE_RPI
:
6039 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
6045 /* Count the number of extents currently allocatd for this type. */
6046 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
6047 if (curr_blks
== 0) {
6049 * The GET_ALLOCATED mailbox does not return the size,
6050 * just the count. The size should be just the size
6051 * stored in the current allocated block and all sizes
6052 * for an extent type are the same so set the return
6055 *extnt_size
= rsrc_blk
->rsrc_size
;
6061 * Calculate the size of an embedded mailbox. The uint32_t
6062 * accounts for extents-specific word.
6064 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
6068 * Presume the allocation and response will fit into an embedded
6069 * mailbox. If not true, reconfigure to a non-embedded mailbox.
6071 emb
= LPFC_SLI4_MBX_EMBED
;
6073 if (req_len
> emb_len
) {
6074 req_len
= curr_blks
* sizeof(uint16_t) +
6075 sizeof(union lpfc_sli4_cfg_shdr
) +
6077 emb
= LPFC_SLI4_MBX_NEMBED
;
6080 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6083 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
6085 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6086 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
6088 if (alloc_len
< req_len
) {
6089 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6090 "2983 Allocated DMA memory size (x%x) is "
6091 "less than the requested DMA memory "
6092 "size (x%x)\n", alloc_len
, req_len
);
6096 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
6102 if (!phba
->sli4_hba
.intr_enable
)
6103 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6105 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
6106 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6115 * Figure out where the response is located. Then get local pointers
6116 * to the response data. The port does not guarantee to respond to
6117 * all extents counts request so update the local variable with the
6118 * allocated count from the port.
6120 if (emb
== LPFC_SLI4_MBX_EMBED
) {
6121 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
6122 shdr
= &rsrc_ext
->header
.cfg_shdr
;
6123 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
6125 virtaddr
= mbox
->sge_array
->addr
[0];
6126 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
6127 shdr
= &n_rsrc
->cfg_shdr
;
6128 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
6131 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
6132 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
6133 "2984 Failed to read allocated resources "
6134 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
6136 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
6137 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
6142 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
6147 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
6148 * @phba: pointer to lpfc hba data structure.
6150 * This routine walks the list of els buffers that have been allocated and
6151 * repost them to the port by using SGL block post. This is needed after a
6152 * pci_function_reset/warm_start or start. It attempts to construct blocks
6153 * of els buffer sgls which contains contiguous xris and uses the non-embedded
6154 * SGL block post mailbox commands to post them to the port. For single els
6155 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
6156 * mailbox command for posting.
6158 * Returns: 0 = success, non-zero failure.
6161 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
6163 struct lpfc_sglq
*sglq_entry
= NULL
;
6164 struct lpfc_sglq
*sglq_entry_next
= NULL
;
6165 struct lpfc_sglq
*sglq_entry_first
= NULL
;
6166 int status
, total_cnt
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
6167 int last_xritag
= NO_XRI
;
6168 struct lpfc_sli_ring
*pring
;
6169 LIST_HEAD(prep_sgl_list
);
6170 LIST_HEAD(blck_sgl_list
);
6171 LIST_HEAD(allc_sgl_list
);
6172 LIST_HEAD(post_sgl_list
);
6173 LIST_HEAD(free_sgl_list
);
6175 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6176 spin_lock_irq(&phba
->hbalock
);
6177 spin_lock(&pring
->ring_lock
);
6178 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
6179 spin_unlock(&pring
->ring_lock
);
6180 spin_unlock_irq(&phba
->hbalock
);
6182 total_cnt
= phba
->sli4_hba
.els_xri_cnt
;
6183 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6184 &allc_sgl_list
, list
) {
6185 list_del_init(&sglq_entry
->list
);
6187 if ((last_xritag
!= NO_XRI
) &&
6188 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6189 /* a hole in xri block, form a sgl posting block */
6190 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6191 post_cnt
= block_cnt
- 1;
6192 /* prepare list for next posting block */
6193 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6196 /* prepare list for next posting block */
6197 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6198 /* enough sgls for non-embed sgl mbox command */
6199 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6200 list_splice_init(&prep_sgl_list
,
6202 post_cnt
= block_cnt
;
6208 /* keep track of last sgl's xritag */
6209 last_xritag
= sglq_entry
->sli4_xritag
;
6211 /* end of repost sgl list condition for els buffers */
6212 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
6213 if (post_cnt
== 0) {
6214 list_splice_init(&prep_sgl_list
,
6216 post_cnt
= block_cnt
;
6217 } else if (block_cnt
== 1) {
6218 status
= lpfc_sli4_post_sgl(phba
,
6219 sglq_entry
->phys
, 0,
6220 sglq_entry
->sli4_xritag
);
6222 /* successful, put sgl to posted list */
6223 list_add_tail(&sglq_entry
->list
,
6226 /* Failure, put sgl to free list */
6227 lpfc_printf_log(phba
, KERN_WARNING
,
6229 "3159 Failed to post els "
6230 "sgl, xritag:x%x\n",
6231 sglq_entry
->sli4_xritag
);
6232 list_add_tail(&sglq_entry
->list
,
6239 /* continue until a nembed page worth of sgls */
6243 /* post the els buffer list sgls as a block */
6244 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
6248 /* success, put sgl list to posted sgl list */
6249 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6251 /* Failure, put sgl list to free sgl list */
6252 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6255 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6256 "3160 Failed to post els sgl-list, "
6258 sglq_entry_first
->sli4_xritag
,
6259 (sglq_entry_first
->sli4_xritag
+
6261 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6262 total_cnt
-= post_cnt
;
6265 /* don't reset xirtag due to hole in xri block */
6267 last_xritag
= NO_XRI
;
6269 /* reset els sgl post count for next round of posting */
6272 /* update the number of XRIs posted for ELS */
6273 phba
->sli4_hba
.els_xri_cnt
= total_cnt
;
6275 /* free the els sgls failed to post */
6276 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6278 /* push els sgls posted to the availble list */
6279 if (!list_empty(&post_sgl_list
)) {
6280 spin_lock_irq(&phba
->hbalock
);
6281 spin_lock(&pring
->ring_lock
);
6282 list_splice_init(&post_sgl_list
,
6283 &phba
->sli4_hba
.lpfc_sgl_list
);
6284 spin_unlock(&pring
->ring_lock
);
6285 spin_unlock_irq(&phba
->hbalock
);
6287 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6288 "3161 Failure to post els sgl to port.\n");
6295 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6296 * @phba: Pointer to HBA context object.
6298 * This function is the main SLI4 device intialization PCI function. This
6299 * function is called by the HBA intialization code, HBA reset code and
6300 * HBA error attention handler code. Caller is not required to hold any
6304 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6307 LPFC_MBOXQ_t
*mboxq
;
6308 struct lpfc_mqe
*mqe
;
6311 uint32_t ftr_rsp
= 0;
6312 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6313 struct lpfc_vport
*vport
= phba
->pport
;
6314 struct lpfc_dmabuf
*mp
;
6316 /* Perform a PCI function reset to start from clean */
6317 rc
= lpfc_pci_function_reset(phba
);
6321 /* Check the HBA Host Status Register for readyness */
6322 rc
= lpfc_sli4_post_status_check(phba
);
6326 spin_lock_irq(&phba
->hbalock
);
6327 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6328 spin_unlock_irq(&phba
->hbalock
);
6332 * Allocate a single mailbox container for initializing the
6335 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6339 /* Issue READ_REV to collect vpd and FW information. */
6340 vpd_size
= SLI4_PAGE_SIZE
;
6341 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6347 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6353 mqe
= &mboxq
->u
.mqe
;
6354 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6355 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
)) {
6356 phba
->hba_flag
|= HBA_FCOE_MODE
;
6357 phba
->fcp_embed_io
= 0; /* SLI4 FC support only */
6359 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6362 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6364 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6366 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6368 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6370 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6371 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6372 "0376 READ_REV Error. SLI Level %d "
6373 "FCoE enabled %d\n",
6374 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6381 * Continue initialization with default values even if driver failed
6382 * to read FCoE param config regions, only read parameters if the
6385 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6386 lpfc_sli4_read_fcoe_params(phba
))
6387 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6388 "2570 Failed to read FCoE parameters\n");
6391 * Retrieve sli4 device physical port name, failure of doing it
6392 * is considered as non-fatal.
6394 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6396 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6397 "3080 Successful retrieving SLI4 device "
6398 "physical port name: %s.\n", phba
->Port
);
6401 * Evaluate the read rev and vpd data. Populate the driver
6402 * state with the results. If this routine fails, the failure
6403 * is not fatal as the driver will use generic values.
6405 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6406 if (unlikely(!rc
)) {
6407 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6408 "0377 Error %d parsing vpd. "
6409 "Using defaults.\n", rc
);
6414 /* Save information as VPD data */
6415 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6416 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6417 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6418 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6420 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6422 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6424 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6426 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6427 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6428 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6429 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6430 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6431 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6432 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6433 "(%d):0380 READ_REV Status x%x "
6434 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6435 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6436 bf_get(lpfc_mqe_status
, mqe
),
6437 phba
->vpd
.rev
.opFwName
,
6438 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6439 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6441 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6442 rc
= (phba
->sli4_hba
.max_cfg_param
.max_xri
>> 3);
6443 if (phba
->pport
->cfg_lun_queue_depth
> rc
) {
6444 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6445 "3362 LUN queue depth changed from %d to %d\n",
6446 phba
->pport
->cfg_lun_queue_depth
, rc
);
6447 phba
->pport
->cfg_lun_queue_depth
= rc
;
6450 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
6451 LPFC_SLI_INTF_IF_TYPE_0
) {
6452 lpfc_set_features(phba
, mboxq
, LPFC_SET_UE_RECOVERY
);
6453 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6454 if (rc
== MBX_SUCCESS
) {
6455 phba
->hba_flag
|= HBA_RECOVERABLE_UE
;
6456 /* Set 1Sec interval to detect UE */
6457 phba
->eratt_poll_interval
= 1;
6458 phba
->sli4_hba
.ue_to_sr
= bf_get(
6459 lpfc_mbx_set_feature_UESR
,
6460 &mboxq
->u
.mqe
.un
.set_feature
);
6461 phba
->sli4_hba
.ue_to_rp
= bf_get(
6462 lpfc_mbx_set_feature_UERP
,
6463 &mboxq
->u
.mqe
.un
.set_feature
);
6467 if (phba
->cfg_enable_mds_diags
&& phba
->mds_diags_support
) {
6468 /* Enable MDS Diagnostics only if the SLI Port supports it */
6469 lpfc_set_features(phba
, mboxq
, LPFC_SET_MDS_DIAGS
);
6470 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6471 if (rc
!= MBX_SUCCESS
)
6472 phba
->mds_diags_support
= 0;
6476 * Discover the port's supported feature set and match it against the
6479 lpfc_request_features(phba
, mboxq
);
6480 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6487 * The port must support FCP initiator mode as this is the
6488 * only mode running in the host.
6490 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6491 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6492 "0378 No support for fcpi mode.\n");
6495 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6496 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6498 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6500 * If the port cannot support the host's requested features
6501 * then turn off the global config parameters to disable the
6502 * feature in the driver. This is not a fatal error.
6504 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6505 if (phba
->cfg_enable_bg
) {
6506 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6507 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6512 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6513 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6517 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6518 "0379 Feature Mismatch Data: x%08x %08x "
6519 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6520 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6521 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6522 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6523 phba
->cfg_enable_bg
= 0;
6524 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6525 phba
->cfg_enable_npiv
= 0;
6528 /* These SLI3 features are assumed in SLI4 */
6529 spin_lock_irq(&phba
->hbalock
);
6530 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6531 spin_unlock_irq(&phba
->hbalock
);
6534 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6535 * calls depends on these resources to complete port setup.
6537 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6539 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6540 "2920 Failed to alloc Resource IDs "
6545 /* Read the port's service parameters. */
6546 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6548 phba
->link_state
= LPFC_HBA_ERROR
;
6553 mboxq
->vport
= vport
;
6554 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6555 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6556 if (rc
== MBX_SUCCESS
) {
6557 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6562 * This memory was allocated by the lpfc_read_sparam routine. Release
6563 * it to the mbuf pool.
6565 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6567 mboxq
->context1
= NULL
;
6569 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6570 "0382 READ_SPARAM command failed "
6571 "status %d, mbxStatus x%x\n",
6572 rc
, bf_get(lpfc_mqe_status
, mqe
));
6573 phba
->link_state
= LPFC_HBA_ERROR
;
6578 lpfc_update_vport_wwn(vport
);
6580 /* Update the fc_host data structures with new wwn. */
6581 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6582 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6584 /* update host els and scsi xri-sgl sizes and mappings */
6585 rc
= lpfc_sli4_xri_sgl_update(phba
);
6587 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6588 "1400 Failed to update xri-sgl size and "
6589 "mapping: %d\n", rc
);
6593 /* register the els sgl pool to the port */
6594 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6596 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6597 "0582 Error %d during els sgl post "
6603 /* register the allocated scsi sgl pool to the port */
6604 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6606 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6607 "0383 Error %d during scsi sgl post "
6609 /* Some Scsi buffers were moved to the abort scsi list */
6610 /* A pci function reset will repost them */
6615 /* Post the rpi header region to the device. */
6616 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6618 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6619 "0393 Error %d during rpi post operation\n",
6624 lpfc_sli4_node_prep(phba
);
6626 /* Create all the SLI4 queues */
6627 rc
= lpfc_sli4_queue_create(phba
);
6629 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6630 "3089 Failed to allocate queues\n");
6632 goto out_stop_timers
;
6634 /* Set up all the queues to the device */
6635 rc
= lpfc_sli4_queue_setup(phba
);
6637 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6638 "0381 Error %d during queue setup.\n ", rc
);
6639 goto out_destroy_queue
;
6642 /* Arm the CQs and then EQs on device */
6643 lpfc_sli4_arm_cqeq_intr(phba
);
6645 /* Indicate device interrupt mode */
6646 phba
->sli4_hba
.intr_enable
= 1;
6648 /* Allow asynchronous mailbox command to go through */
6649 spin_lock_irq(&phba
->hbalock
);
6650 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6651 spin_unlock_irq(&phba
->hbalock
);
6653 /* Post receive buffers to the device */
6654 lpfc_sli4_rb_setup(phba
);
6656 /* Reset HBA FCF states after HBA reset */
6657 phba
->fcf
.fcf_flag
= 0;
6658 phba
->fcf
.current_rec
.flag
= 0;
6660 /* Start the ELS watchdog timer */
6661 mod_timer(&vport
->els_tmofunc
,
6662 jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2)));
6664 /* Start heart beat timer */
6665 mod_timer(&phba
->hb_tmofunc
,
6666 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
6667 phba
->hb_outstanding
= 0;
6668 phba
->last_completion_time
= jiffies
;
6670 /* Start error attention (ERATT) polling timer */
6671 mod_timer(&phba
->eratt_poll
,
6672 jiffies
+ msecs_to_jiffies(1000 * phba
->eratt_poll_interval
));
6674 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6675 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6676 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6678 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6679 "2829 This device supports "
6680 "Advanced Error Reporting (AER)\n");
6681 spin_lock_irq(&phba
->hbalock
);
6682 phba
->hba_flag
|= HBA_AER_ENABLED
;
6683 spin_unlock_irq(&phba
->hbalock
);
6685 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6686 "2830 This device does not support "
6687 "Advanced Error Reporting (AER)\n");
6688 phba
->cfg_aer_support
= 0;
6693 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6695 * The FC Port needs to register FCFI (index 0)
6697 lpfc_reg_fcfi(phba
, mboxq
);
6698 mboxq
->vport
= phba
->pport
;
6699 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6700 if (rc
!= MBX_SUCCESS
)
6701 goto out_unset_queue
;
6703 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6704 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6706 /* Check if the port is configured to be disabled */
6707 lpfc_sli_read_link_ste(phba
);
6711 * The port is ready, set the host's link state to LINK_DOWN
6712 * in preparation for link interrupts.
6714 spin_lock_irq(&phba
->hbalock
);
6715 phba
->link_state
= LPFC_LINK_DOWN
;
6716 spin_unlock_irq(&phba
->hbalock
);
6717 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6718 (phba
->hba_flag
& LINK_DISABLED
)) {
6719 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6720 "3103 Adapter Link is disabled.\n");
6721 lpfc_down_link(phba
, mboxq
);
6722 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6723 if (rc
!= MBX_SUCCESS
) {
6724 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6725 "3104 Adapter failed to issue "
6726 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6727 goto out_unset_queue
;
6729 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6730 /* don't perform init_link on SLI4 FC port loopback test */
6731 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6732 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6734 goto out_unset_queue
;
6737 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6740 /* Unset all the queues set up in this routine when error out */
6741 lpfc_sli4_queue_unset(phba
);
6743 lpfc_sli4_queue_destroy(phba
);
6745 lpfc_stop_hba_timers(phba
);
6747 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6752 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6753 * @ptr: context object - pointer to hba structure.
6755 * This is the callback function for mailbox timer. The mailbox
6756 * timer is armed when a new mailbox command is issued and the timer
6757 * is deleted when the mailbox complete. The function is called by
6758 * the kernel timer code when a mailbox does not complete within
6759 * expected time. This function wakes up the worker thread to
6760 * process the mailbox timeout and returns. All the processing is
6761 * done by the worker thread function lpfc_mbox_timeout_handler.
6764 lpfc_mbox_timeout(unsigned long ptr
)
6766 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6767 unsigned long iflag
;
6768 uint32_t tmo_posted
;
6770 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6771 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6773 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6774 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6777 lpfc_worker_wake_up(phba
);
6782 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
6784 * @phba: Pointer to HBA context object.
6786 * This function checks if any mailbox completions are present on the mailbox
6790 lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
)
6794 struct lpfc_queue
*mcq
;
6795 struct lpfc_mcqe
*mcqe
;
6796 bool pending_completions
= false;
6798 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
6801 /* Check for completions on mailbox completion queue */
6803 mcq
= phba
->sli4_hba
.mbx_cq
;
6804 idx
= mcq
->hba_index
;
6805 while (bf_get_le32(lpfc_cqe_valid
, mcq
->qe
[idx
].cqe
)) {
6806 mcqe
= (struct lpfc_mcqe
*)mcq
->qe
[idx
].cqe
;
6807 if (bf_get_le32(lpfc_trailer_completed
, mcqe
) &&
6808 (!bf_get_le32(lpfc_trailer_async
, mcqe
))) {
6809 pending_completions
= true;
6812 idx
= (idx
+ 1) % mcq
->entry_count
;
6813 if (mcq
->hba_index
== idx
)
6816 return pending_completions
;
6821 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
6823 * @phba: Pointer to HBA context object.
6825 * For sli4, it is possible to miss an interrupt. As such mbox completions
6826 * maybe missed causing erroneous mailbox timeouts to occur. This function
6827 * checks to see if mbox completions are on the mailbox completion queue
6828 * and will process all the completions associated with the eq for the
6829 * mailbox completion queue.
6832 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
)
6836 struct lpfc_queue
*fpeq
= NULL
;
6837 struct lpfc_eqe
*eqe
;
6840 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
6843 /* Find the eq associated with the mcq */
6845 if (phba
->sli4_hba
.hba_eq
)
6846 for (eqidx
= 0; eqidx
< phba
->cfg_fcp_io_channel
; eqidx
++)
6847 if (phba
->sli4_hba
.hba_eq
[eqidx
]->queue_id
==
6848 phba
->sli4_hba
.mbx_cq
->assoc_qid
) {
6849 fpeq
= phba
->sli4_hba
.hba_eq
[eqidx
];
6855 /* Turn off interrupts from this EQ */
6857 lpfc_sli4_eq_clr_intr(fpeq
);
6859 /* Check to see if a mbox completion is pending */
6861 mbox_pending
= lpfc_sli4_mbox_completions_pending(phba
);
6864 * If a mbox completion is pending, process all the events on EQ
6865 * associated with the mbox completion queue (this could include
6866 * mailbox commands, async events, els commands, receive queue data
6871 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
6872 lpfc_sli4_hba_handle_eqe(phba
, eqe
, eqidx
);
6873 fpeq
->EQ_processed
++;
6876 /* Always clear and re-arm the EQ */
6878 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
6880 return mbox_pending
;
6885 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6886 * @phba: Pointer to HBA context object.
6888 * This function is called from worker thread when a mailbox command times out.
6889 * The caller is not required to hold any locks. This function will reset the
6890 * HBA and recover all the pending commands.
6893 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6895 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6896 MAILBOX_t
*mb
= NULL
;
6898 struct lpfc_sli
*psli
= &phba
->sli
;
6900 /* If the mailbox completed, process the completion and return */
6901 if (lpfc_sli4_process_missed_mbox_completions(phba
))
6906 /* Check the pmbox pointer first. There is a race condition
6907 * between the mbox timeout handler getting executed in the
6908 * worklist and the mailbox actually completing. When this
6909 * race condition occurs, the mbox_active will be NULL.
6911 spin_lock_irq(&phba
->hbalock
);
6912 if (pmbox
== NULL
) {
6913 lpfc_printf_log(phba
, KERN_WARNING
,
6915 "0353 Active Mailbox cleared - mailbox timeout "
6917 spin_unlock_irq(&phba
->hbalock
);
6921 /* Mbox cmd <mbxCommand> timeout */
6922 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6923 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6925 phba
->pport
->port_state
,
6927 phba
->sli
.mbox_active
);
6928 spin_unlock_irq(&phba
->hbalock
);
6930 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6931 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6932 * it to fail all outstanding SCSI IO.
6934 spin_lock_irq(&phba
->pport
->work_port_lock
);
6935 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6936 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6937 spin_lock_irq(&phba
->hbalock
);
6938 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6939 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6940 spin_unlock_irq(&phba
->hbalock
);
6942 lpfc_sli_abort_fcp_rings(phba
);
6944 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6945 "0345 Resetting board due to mailbox timeout\n");
6947 /* Reset the HBA device */
6948 lpfc_reset_hba(phba
);
6952 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6953 * @phba: Pointer to HBA context object.
6954 * @pmbox: Pointer to mailbox object.
6955 * @flag: Flag indicating how the mailbox need to be processed.
6957 * This function is called by discovery code and HBA management code
6958 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6959 * function gets the hbalock to protect the data structures.
6960 * The mailbox command can be submitted in polling mode, in which case
6961 * this function will wait in a polling loop for the completion of the
6963 * If the mailbox is submitted in no_wait mode (not polling) the
6964 * function will submit the command and returns immediately without waiting
6965 * for the mailbox completion. The no_wait is supported only when HBA
6966 * is in SLI2/SLI3 mode - interrupts are enabled.
6967 * The SLI interface allows only one mailbox pending at a time. If the
6968 * mailbox is issued in polling mode and there is already a mailbox
6969 * pending, then the function will return an error. If the mailbox is issued
6970 * in NO_WAIT mode and there is a mailbox pending already, the function
6971 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6972 * The sli layer owns the mailbox object until the completion of mailbox
6973 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6974 * return codes the caller owns the mailbox command after the return of
6978 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6982 struct lpfc_sli
*psli
= &phba
->sli
;
6983 uint32_t status
, evtctr
;
6984 uint32_t ha_copy
, hc_copy
;
6986 unsigned long timeout
;
6987 unsigned long drvr_flag
= 0;
6988 uint32_t word0
, ldata
;
6989 void __iomem
*to_slim
;
6990 int processing_queue
= 0;
6992 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6994 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6995 /* processing mbox queue from intr_handler */
6996 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6997 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7000 processing_queue
= 1;
7001 pmbox
= lpfc_mbox_get(phba
);
7003 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7008 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
7009 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
7011 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7012 lpfc_printf_log(phba
, KERN_ERR
,
7013 LOG_MBOX
| LOG_VPORT
,
7014 "1806 Mbox x%x failed. No vport\n",
7015 pmbox
->u
.mb
.mbxCommand
);
7017 goto out_not_finished
;
7021 /* If the PCI channel is in offline state, do not post mbox. */
7022 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
7023 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7024 goto out_not_finished
;
7027 /* If HBA has a deferred error attention, fail the iocb. */
7028 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
7029 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7030 goto out_not_finished
;
7036 status
= MBX_SUCCESS
;
7038 if (phba
->link_state
== LPFC_HBA_ERROR
) {
7039 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7041 /* Mbox command <mbxCommand> cannot issue */
7042 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7043 "(%d):0311 Mailbox command x%x cannot "
7044 "issue Data: x%x x%x\n",
7045 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7046 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7047 goto out_not_finished
;
7050 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
7051 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
7052 !(hc_copy
& HC_MBINT_ENA
)) {
7053 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7054 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7055 "(%d):2528 Mailbox command x%x cannot "
7056 "issue Data: x%x x%x\n",
7057 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7058 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
7059 goto out_not_finished
;
7063 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7064 /* Polling for a mbox command when another one is already active
7065 * is not allowed in SLI. Also, the driver must have established
7066 * SLI2 mode to queue and process multiple mbox commands.
7069 if (flag
& MBX_POLL
) {
7070 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7072 /* Mbox command <mbxCommand> cannot issue */
7073 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7074 "(%d):2529 Mailbox command x%x "
7075 "cannot issue Data: x%x x%x\n",
7076 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7077 pmbox
->u
.mb
.mbxCommand
,
7078 psli
->sli_flag
, flag
);
7079 goto out_not_finished
;
7082 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
7083 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7084 /* Mbox command <mbxCommand> cannot issue */
7085 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7086 "(%d):2530 Mailbox command x%x "
7087 "cannot issue Data: x%x x%x\n",
7088 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7089 pmbox
->u
.mb
.mbxCommand
,
7090 psli
->sli_flag
, flag
);
7091 goto out_not_finished
;
7094 /* Another mailbox command is still being processed, queue this
7095 * command to be processed later.
7097 lpfc_mbox_put(phba
, pmbox
);
7099 /* Mbox cmd issue - BUSY */
7100 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7101 "(%d):0308 Mbox cmd issue - BUSY Data: "
7102 "x%x x%x x%x x%x\n",
7103 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
7104 mbx
->mbxCommand
, phba
->pport
->port_state
,
7105 psli
->sli_flag
, flag
);
7107 psli
->slistat
.mbox_busy
++;
7108 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7111 lpfc_debugfs_disc_trc(pmbox
->vport
,
7112 LPFC_DISC_TRC_MBOX_VPORT
,
7113 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
7114 (uint32_t)mbx
->mbxCommand
,
7115 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7118 lpfc_debugfs_disc_trc(phba
->pport
,
7120 "MBOX Bsy: cmd:x%x mb:x%x x%x",
7121 (uint32_t)mbx
->mbxCommand
,
7122 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7128 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7130 /* If we are not polling, we MUST be in SLI2 mode */
7131 if (flag
!= MBX_POLL
) {
7132 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
7133 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
7134 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7135 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7136 /* Mbox command <mbxCommand> cannot issue */
7137 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7138 "(%d):2531 Mailbox command x%x "
7139 "cannot issue Data: x%x x%x\n",
7140 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7141 pmbox
->u
.mb
.mbxCommand
,
7142 psli
->sli_flag
, flag
);
7143 goto out_not_finished
;
7145 /* timeout active mbox command */
7146 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7148 mod_timer(&psli
->mbox_tmo
, jiffies
+ timeout
);
7151 /* Mailbox cmd <cmd> issue */
7152 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7153 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
7155 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
7156 mbx
->mbxCommand
, phba
->pport
->port_state
,
7157 psli
->sli_flag
, flag
);
7159 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
7161 lpfc_debugfs_disc_trc(pmbox
->vport
,
7162 LPFC_DISC_TRC_MBOX_VPORT
,
7163 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7164 (uint32_t)mbx
->mbxCommand
,
7165 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7168 lpfc_debugfs_disc_trc(phba
->pport
,
7170 "MBOX Send: cmd:x%x mb:x%x x%x",
7171 (uint32_t)mbx
->mbxCommand
,
7172 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
7176 psli
->slistat
.mbox_cmd
++;
7177 evtctr
= psli
->slistat
.mbox_event
;
7179 /* next set own bit for the adapter and copy over command word */
7180 mbx
->mbxOwner
= OWN_CHIP
;
7182 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7183 /* Populate mbox extension offset word. */
7184 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
7185 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7186 = (uint8_t *)phba
->mbox_ext
7187 - (uint8_t *)phba
->mbox
;
7190 /* Copy the mailbox extension data */
7191 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7192 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
7193 (uint8_t *)phba
->mbox_ext
,
7194 pmbox
->in_ext_byte_len
);
7196 /* Copy command data to host SLIM area */
7197 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7199 /* Populate mbox extension offset word. */
7200 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
7201 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
7202 = MAILBOX_HBA_EXT_OFFSET
;
7204 /* Copy the mailbox extension data */
7205 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7206 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
7207 MAILBOX_HBA_EXT_OFFSET
,
7208 pmbox
->context2
, pmbox
->in_ext_byte_len
);
7211 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7212 /* copy command data into host mbox for cmpl */
7213 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7216 /* First copy mbox command data to HBA SLIM, skip past first
7218 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
7219 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
7220 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
7222 /* Next copy over first word, with mbxOwner set */
7223 ldata
= *((uint32_t *)mbx
);
7224 to_slim
= phba
->MBslimaddr
;
7225 writel(ldata
, to_slim
);
7226 readl(to_slim
); /* flush */
7228 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7229 /* switch over to host mailbox */
7230 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
7238 /* Set up reference to mailbox command */
7239 psli
->mbox_active
= pmbox
;
7240 /* Interrupt board to do it */
7241 writel(CA_MBATT
, phba
->CAregaddr
);
7242 readl(phba
->CAregaddr
); /* flush */
7243 /* Don't wait for it to finish, just return */
7247 /* Set up null reference to mailbox command */
7248 psli
->mbox_active
= NULL
;
7249 /* Interrupt board to do it */
7250 writel(CA_MBATT
, phba
->CAregaddr
);
7251 readl(phba
->CAregaddr
); /* flush */
7253 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7254 /* First read mbox status word */
7255 word0
= *((uint32_t *)phba
->mbox
);
7256 word0
= le32_to_cpu(word0
);
7258 /* First read mbox status word */
7259 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
7260 spin_unlock_irqrestore(&phba
->hbalock
,
7262 goto out_not_finished
;
7266 /* Read the HBA Host Attention Register */
7267 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7268 spin_unlock_irqrestore(&phba
->hbalock
,
7270 goto out_not_finished
;
7272 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7275 /* Wait for command to complete */
7276 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
7277 (!(ha_copy
& HA_MBATT
) &&
7278 (phba
->link_state
> LPFC_WARM_START
))) {
7279 if (time_after(jiffies
, timeout
)) {
7280 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7281 spin_unlock_irqrestore(&phba
->hbalock
,
7283 goto out_not_finished
;
7286 /* Check if we took a mbox interrupt while we were
7288 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
7289 && (evtctr
!= psli
->slistat
.mbox_event
))
7293 spin_unlock_irqrestore(&phba
->hbalock
,
7296 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7299 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7300 /* First copy command data */
7301 word0
= *((uint32_t *)phba
->mbox
);
7302 word0
= le32_to_cpu(word0
);
7303 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7306 /* Check real SLIM for any errors */
7307 slimword0
= readl(phba
->MBslimaddr
);
7308 slimmb
= (MAILBOX_t
*) & slimword0
;
7309 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
7310 && slimmb
->mbxStatus
) {
7317 /* First copy command data */
7318 word0
= readl(phba
->MBslimaddr
);
7320 /* Read the HBA Host Attention Register */
7321 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7322 spin_unlock_irqrestore(&phba
->hbalock
,
7324 goto out_not_finished
;
7328 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7329 /* copy results back to user */
7330 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
, MAILBOX_CMD_SIZE
);
7331 /* Copy the mailbox extension data */
7332 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7333 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7335 pmbox
->out_ext_byte_len
);
7338 /* First copy command data */
7339 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
7341 /* Copy the mailbox extension data */
7342 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7343 lpfc_memcpy_from_slim(pmbox
->context2
,
7345 MAILBOX_HBA_EXT_OFFSET
,
7346 pmbox
->out_ext_byte_len
);
7350 writel(HA_MBATT
, phba
->HAregaddr
);
7351 readl(phba
->HAregaddr
); /* flush */
7353 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7354 status
= mbx
->mbxStatus
;
7357 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7361 if (processing_queue
) {
7362 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7363 lpfc_mbox_cmpl_put(phba
, pmbox
);
7365 return MBX_NOT_FINISHED
;
7369 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7370 * @phba: Pointer to HBA context object.
7372 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7373 * the driver internal pending mailbox queue. It will then try to wait out the
7374 * possible outstanding mailbox command before return.
7377 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7378 * the outstanding mailbox command timed out.
7381 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7383 struct lpfc_sli
*psli
= &phba
->sli
;
7385 unsigned long timeout
= 0;
7387 /* Mark the asynchronous mailbox command posting as blocked */
7388 spin_lock_irq(&phba
->hbalock
);
7389 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7390 /* Determine how long we might wait for the active mailbox
7391 * command to be gracefully completed by firmware.
7393 if (phba
->sli
.mbox_active
)
7394 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7395 phba
->sli
.mbox_active
) *
7397 spin_unlock_irq(&phba
->hbalock
);
7399 /* Make sure the mailbox is really active */
7401 lpfc_sli4_process_missed_mbox_completions(phba
);
7403 /* Wait for the outstnading mailbox command to complete */
7404 while (phba
->sli
.mbox_active
) {
7405 /* Check active mailbox complete status every 2ms */
7407 if (time_after(jiffies
, timeout
)) {
7408 /* Timeout, marked the outstanding cmd not complete */
7414 /* Can not cleanly block async mailbox command, fails it */
7416 spin_lock_irq(&phba
->hbalock
);
7417 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7418 spin_unlock_irq(&phba
->hbalock
);
7424 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7425 * @phba: Pointer to HBA context object.
7427 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7428 * commands from the driver internal pending mailbox queue. It makes sure
7429 * that there is no outstanding mailbox command before resuming posting
7430 * asynchronous mailbox commands. If, for any reason, there is outstanding
7431 * mailbox command, it will try to wait it out before resuming asynchronous
7432 * mailbox command posting.
7435 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7437 struct lpfc_sli
*psli
= &phba
->sli
;
7439 spin_lock_irq(&phba
->hbalock
);
7440 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7441 /* Asynchronous mailbox posting is not blocked, do nothing */
7442 spin_unlock_irq(&phba
->hbalock
);
7446 /* Outstanding synchronous mailbox command is guaranteed to be done,
7447 * successful or timeout, after timing-out the outstanding mailbox
7448 * command shall always be removed, so just unblock posting async
7449 * mailbox command and resume
7451 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7452 spin_unlock_irq(&phba
->hbalock
);
7454 /* wake up worker thread to post asynchronlous mailbox command */
7455 lpfc_worker_wake_up(phba
);
7459 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7460 * @phba: Pointer to HBA context object.
7461 * @mboxq: Pointer to mailbox object.
7463 * The function waits for the bootstrap mailbox register ready bit from
7464 * port for twice the regular mailbox command timeout value.
7466 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7467 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7470 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7473 unsigned long timeout
;
7474 struct lpfc_register bmbx_reg
;
7476 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7480 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7481 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7485 if (time_after(jiffies
, timeout
))
7486 return MBXERR_ERROR
;
7487 } while (!db_ready
);
7493 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7494 * @phba: Pointer to HBA context object.
7495 * @mboxq: Pointer to mailbox object.
7497 * The function posts a mailbox to the port. The mailbox is expected
7498 * to be comletely filled in and ready for the port to operate on it.
7499 * This routine executes a synchronous completion operation on the
7500 * mailbox by polling for its completion.
7502 * The caller must not be holding any locks when calling this routine.
7505 * MBX_SUCCESS - mailbox posted successfully
7506 * Any of the MBX error values.
7509 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7511 int rc
= MBX_SUCCESS
;
7512 unsigned long iflag
;
7513 uint32_t mcqe_status
;
7515 struct lpfc_sli
*psli
= &phba
->sli
;
7516 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7517 struct lpfc_bmbx_create
*mbox_rgn
;
7518 struct dma_address
*dma_address
;
7521 * Only one mailbox can be active to the bootstrap mailbox region
7522 * at a time and there is no queueing provided.
7524 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7525 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7526 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7527 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7528 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7529 "cannot issue Data: x%x x%x\n",
7530 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7531 mboxq
->u
.mb
.mbxCommand
,
7532 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7533 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7534 psli
->sli_flag
, MBX_POLL
);
7535 return MBXERR_ERROR
;
7537 /* The server grabs the token and owns it until release */
7538 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7539 phba
->sli
.mbox_active
= mboxq
;
7540 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7542 /* wait for bootstrap mbox register for readyness */
7543 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7548 * Initialize the bootstrap memory region to avoid stale data areas
7549 * in the mailbox post. Then copy the caller's mailbox contents to
7550 * the bmbx mailbox region.
7552 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7553 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7554 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7555 sizeof(struct lpfc_mqe
));
7557 /* Post the high mailbox dma address to the port and wait for ready. */
7558 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7559 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7561 /* wait for bootstrap mbox register for hi-address write done */
7562 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7566 /* Post the low mailbox dma address to the port. */
7567 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7569 /* wait for bootstrap mbox register for low address write done */
7570 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7575 * Read the CQ to ensure the mailbox has completed.
7576 * If so, update the mailbox status so that the upper layers
7577 * can complete the request normally.
7579 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7580 sizeof(struct lpfc_mqe
));
7581 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7582 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7583 sizeof(struct lpfc_mcqe
));
7584 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7586 * When the CQE status indicates a failure and the mailbox status
7587 * indicates success then copy the CQE status into the mailbox status
7588 * (and prefix it with x4000).
7590 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7591 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7592 bf_set(lpfc_mqe_status
, mb
,
7593 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7596 lpfc_sli4_swap_str(phba
, mboxq
);
7598 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7599 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7600 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7601 " x%x x%x CQ: x%x x%x x%x x%x\n",
7602 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7603 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7604 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7605 bf_get(lpfc_mqe_status
, mb
),
7606 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7607 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7608 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7609 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7610 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7611 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7612 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7613 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7614 mboxq
->mcqe
.trailer
);
7616 /* We are holding the token, no needed for lock when release */
7617 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7618 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7619 phba
->sli
.mbox_active
= NULL
;
7620 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7625 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7626 * @phba: Pointer to HBA context object.
7627 * @pmbox: Pointer to mailbox object.
7628 * @flag: Flag indicating how the mailbox need to be processed.
7630 * This function is called by discovery code and HBA management code to submit
7631 * a mailbox command to firmware with SLI-4 interface spec.
7633 * Return codes the caller owns the mailbox command after the return of the
7637 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7640 struct lpfc_sli
*psli
= &phba
->sli
;
7641 unsigned long iflags
;
7644 /* dump from issue mailbox command if setup */
7645 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7647 rc
= lpfc_mbox_dev_check(phba
);
7649 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7650 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7651 "cannot issue Data: x%x x%x\n",
7652 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7653 mboxq
->u
.mb
.mbxCommand
,
7654 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7655 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7656 psli
->sli_flag
, flag
);
7657 goto out_not_finished
;
7660 /* Detect polling mode and jump to a handler */
7661 if (!phba
->sli4_hba
.intr_enable
) {
7662 if (flag
== MBX_POLL
)
7663 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7666 if (rc
!= MBX_SUCCESS
)
7667 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7668 "(%d):2541 Mailbox command x%x "
7669 "(x%x/x%x) failure: "
7670 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7672 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7673 mboxq
->u
.mb
.mbxCommand
,
7674 lpfc_sli_config_mbox_subsys_get(phba
,
7676 lpfc_sli_config_mbox_opcode_get(phba
,
7678 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7679 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7680 bf_get(lpfc_mcqe_ext_status
,
7682 psli
->sli_flag
, flag
);
7684 } else if (flag
== MBX_POLL
) {
7685 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7686 "(%d):2542 Try to issue mailbox command "
7687 "x%x (x%x/x%x) synchronously ahead of async"
7688 "mailbox command queue: x%x x%x\n",
7689 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7690 mboxq
->u
.mb
.mbxCommand
,
7691 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7692 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7693 psli
->sli_flag
, flag
);
7694 /* Try to block the asynchronous mailbox posting */
7695 rc
= lpfc_sli4_async_mbox_block(phba
);
7697 /* Successfully blocked, now issue sync mbox cmd */
7698 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7699 if (rc
!= MBX_SUCCESS
)
7700 lpfc_printf_log(phba
, KERN_WARNING
,
7702 "(%d):2597 Sync Mailbox command "
7703 "x%x (x%x/x%x) failure: "
7704 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7706 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7707 mboxq
->u
.mb
.mbxCommand
,
7708 lpfc_sli_config_mbox_subsys_get(phba
,
7710 lpfc_sli_config_mbox_opcode_get(phba
,
7712 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7713 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7714 bf_get(lpfc_mcqe_ext_status
,
7716 psli
->sli_flag
, flag
);
7717 /* Unblock the async mailbox posting afterward */
7718 lpfc_sli4_async_mbox_unblock(phba
);
7723 /* Now, interrupt mode asynchrous mailbox command */
7724 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7726 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7727 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7728 "cannot issue Data: x%x x%x\n",
7729 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7730 mboxq
->u
.mb
.mbxCommand
,
7731 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7732 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7733 psli
->sli_flag
, flag
);
7734 goto out_not_finished
;
7737 /* Put the mailbox command to the driver internal FIFO */
7738 psli
->slistat
.mbox_busy
++;
7739 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7740 lpfc_mbox_put(phba
, mboxq
);
7741 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7742 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7743 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7744 "x%x (x%x/x%x) x%x x%x x%x\n",
7745 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7746 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7747 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7748 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7749 phba
->pport
->port_state
,
7750 psli
->sli_flag
, MBX_NOWAIT
);
7751 /* Wake up worker thread to transport mailbox command from head */
7752 lpfc_worker_wake_up(phba
);
7757 return MBX_NOT_FINISHED
;
7761 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7762 * @phba: Pointer to HBA context object.
7764 * This function is called by worker thread to send a mailbox command to
7765 * SLI4 HBA firmware.
7769 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7771 struct lpfc_sli
*psli
= &phba
->sli
;
7772 LPFC_MBOXQ_t
*mboxq
;
7773 int rc
= MBX_SUCCESS
;
7774 unsigned long iflags
;
7775 struct lpfc_mqe
*mqe
;
7778 /* Check interrupt mode before post async mailbox command */
7779 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7780 return MBX_NOT_FINISHED
;
7782 /* Check for mailbox command service token */
7783 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7784 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7785 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7786 return MBX_NOT_FINISHED
;
7788 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7789 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7790 return MBX_NOT_FINISHED
;
7792 if (unlikely(phba
->sli
.mbox_active
)) {
7793 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7794 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7795 "0384 There is pending active mailbox cmd\n");
7796 return MBX_NOT_FINISHED
;
7798 /* Take the mailbox command service token */
7799 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7801 /* Get the next mailbox command from head of queue */
7802 mboxq
= lpfc_mbox_get(phba
);
7804 /* If no more mailbox command waiting for post, we're done */
7806 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7807 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7810 phba
->sli
.mbox_active
= mboxq
;
7811 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7813 /* Check device readiness for posting mailbox command */
7814 rc
= lpfc_mbox_dev_check(phba
);
7816 /* Driver clean routine will clean up pending mailbox */
7817 goto out_not_finished
;
7819 /* Prepare the mbox command to be posted */
7820 mqe
= &mboxq
->u
.mqe
;
7821 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7823 /* Start timer for the mbox_tmo and log some mailbox post messages */
7824 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7825 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba
, mboxq
))));
7827 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7828 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7830 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7831 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7832 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7833 phba
->pport
->port_state
, psli
->sli_flag
);
7835 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7837 lpfc_debugfs_disc_trc(mboxq
->vport
,
7838 LPFC_DISC_TRC_MBOX_VPORT
,
7839 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7840 mbx_cmnd
, mqe
->un
.mb_words
[0],
7841 mqe
->un
.mb_words
[1]);
7843 lpfc_debugfs_disc_trc(phba
->pport
,
7845 "MBOX Send: cmd:x%x mb:x%x x%x",
7846 mbx_cmnd
, mqe
->un
.mb_words
[0],
7847 mqe
->un
.mb_words
[1]);
7850 psli
->slistat
.mbox_cmd
++;
7852 /* Post the mailbox command to the port */
7853 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7854 if (rc
!= MBX_SUCCESS
) {
7855 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7856 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7857 "cannot issue Data: x%x x%x\n",
7858 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7859 mboxq
->u
.mb
.mbxCommand
,
7860 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7861 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7862 psli
->sli_flag
, MBX_NOWAIT
);
7863 goto out_not_finished
;
7869 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7870 if (phba
->sli
.mbox_active
) {
7871 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7872 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7873 /* Release the token */
7874 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7875 phba
->sli
.mbox_active
= NULL
;
7877 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7879 return MBX_NOT_FINISHED
;
7883 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7884 * @phba: Pointer to HBA context object.
7885 * @pmbox: Pointer to mailbox object.
7886 * @flag: Flag indicating how the mailbox need to be processed.
7888 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7889 * the API jump table function pointer from the lpfc_hba struct.
7891 * Return codes the caller owns the mailbox command after the return of the
7895 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7897 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7901 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7902 * @phba: The hba struct for which this call is being executed.
7903 * @dev_grp: The HBA PCI-Device group number.
7905 * This routine sets up the mbox interface API function jump table in @phba
7907 * Returns: 0 - success, -ENODEV - failure.
7910 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7914 case LPFC_PCI_DEV_LP
:
7915 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7916 phba
->lpfc_sli_handle_slow_ring_event
=
7917 lpfc_sli_handle_slow_ring_event_s3
;
7918 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7919 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7920 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7922 case LPFC_PCI_DEV_OC
:
7923 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7924 phba
->lpfc_sli_handle_slow_ring_event
=
7925 lpfc_sli_handle_slow_ring_event_s4
;
7926 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7927 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7928 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7931 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7932 "1420 Invalid HBA PCI-device group: 0x%x\n",
7941 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7942 * @phba: Pointer to HBA context object.
7943 * @pring: Pointer to driver SLI ring object.
7944 * @piocb: Pointer to address of newly added command iocb.
7946 * This function is called with hbalock held to add a command
7947 * iocb to the txq when SLI layer cannot submit the command iocb
7951 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7952 struct lpfc_iocbq
*piocb
)
7954 lockdep_assert_held(&phba
->hbalock
);
7955 /* Insert the caller's iocb in the txq tail for later processing. */
7956 list_add_tail(&piocb
->list
, &pring
->txq
);
7960 * lpfc_sli_next_iocb - Get the next iocb in the txq
7961 * @phba: Pointer to HBA context object.
7962 * @pring: Pointer to driver SLI ring object.
7963 * @piocb: Pointer to address of newly added command iocb.
7965 * This function is called with hbalock held before a new
7966 * iocb is submitted to the firmware. This function checks
7967 * txq to flush the iocbs in txq to Firmware before
7968 * submitting new iocbs to the Firmware.
7969 * If there are iocbs in the txq which need to be submitted
7970 * to firmware, lpfc_sli_next_iocb returns the first element
7971 * of the txq after dequeuing it from txq.
7972 * If there is no iocb in the txq then the function will return
7973 * *piocb and *piocb is set to NULL. Caller needs to check
7974 * *piocb to find if there are more commands in the txq.
7976 static struct lpfc_iocbq
*
7977 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7978 struct lpfc_iocbq
**piocb
)
7980 struct lpfc_iocbq
* nextiocb
;
7982 lockdep_assert_held(&phba
->hbalock
);
7984 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7994 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7995 * @phba: Pointer to HBA context object.
7996 * @ring_number: SLI ring number to issue iocb on.
7997 * @piocb: Pointer to command iocb.
7998 * @flag: Flag indicating if this command can be put into txq.
8000 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
8001 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
8002 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
8003 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
8004 * this function allows only iocbs for posting buffers. This function finds
8005 * next available slot in the command ring and posts the command to the
8006 * available slot and writes the port attention register to request HBA start
8007 * processing new iocb. If there is no slot available in the ring and
8008 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
8009 * the function returns IOCB_BUSY.
8011 * This function is called with hbalock held. The function will return success
8012 * after it successfully submit the iocb to firmware or after adding to the
8016 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
8017 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8019 struct lpfc_iocbq
*nextiocb
;
8021 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8023 lockdep_assert_held(&phba
->hbalock
);
8025 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
8026 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
8027 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
8028 lpfc_printf_log(phba
, KERN_ERR
,
8029 LOG_SLI
| LOG_VPORT
,
8030 "1807 IOCB x%x failed. No vport\n",
8031 piocb
->iocb
.ulpCommand
);
8037 /* If the PCI channel is in offline state, do not post iocbs. */
8038 if (unlikely(pci_channel_offline(phba
->pcidev
)))
8041 /* If HBA has a deferred error attention, fail the iocb. */
8042 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
8046 * We should never get an IOCB if we are in a < LINK_DOWN state
8048 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
8052 * Check to see if we are blocking IOCB processing because of a
8053 * outstanding event.
8055 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
8058 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
8060 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
8061 * can be issued if the link is not up.
8063 switch (piocb
->iocb
.ulpCommand
) {
8064 case CMD_GEN_REQUEST64_CR
:
8065 case CMD_GEN_REQUEST64_CX
:
8066 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
8067 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
8068 FC_RCTL_DD_UNSOL_CMD
) ||
8069 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
8070 MENLO_TRANSPORT_TYPE
))
8074 case CMD_QUE_RING_BUF_CN
:
8075 case CMD_QUE_RING_BUF64_CN
:
8077 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
8078 * completion, iocb_cmpl MUST be 0.
8080 if (piocb
->iocb_cmpl
)
8081 piocb
->iocb_cmpl
= NULL
;
8083 case CMD_CREATE_XRI_CR
:
8084 case CMD_CLOSE_XRI_CN
:
8085 case CMD_CLOSE_XRI_CX
:
8092 * For FCP commands, we must be in a state where we can process link
8095 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
8096 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
8100 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
8101 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
8102 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
8105 lpfc_sli_update_ring(phba
, pring
);
8107 lpfc_sli_update_full_ring(phba
, pring
);
8110 return IOCB_SUCCESS
;
8115 pring
->stats
.iocb_cmd_delay
++;
8119 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8120 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
8121 return IOCB_SUCCESS
;
8128 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
8129 * @phba: Pointer to HBA context object.
8130 * @piocb: Pointer to command iocb.
8131 * @sglq: Pointer to the scatter gather queue object.
8133 * This routine converts the bpl or bde that is in the IOCB
8134 * to a sgl list for the sli4 hardware. The physical address
8135 * of the bpl/bde is converted back to a virtual address.
8136 * If the IOCB contains a BPL then the list of BDE's is
8137 * converted to sli4_sge's. If the IOCB contains a single
8138 * BDE then it is converted to a single sli_sge.
8139 * The IOCB is still in cpu endianess so the contents of
8140 * the bpl can be used without byte swapping.
8142 * Returns valid XRI = Success, NO_XRI = Failure.
8145 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
8146 struct lpfc_sglq
*sglq
)
8148 uint16_t xritag
= NO_XRI
;
8149 struct ulp_bde64
*bpl
= NULL
;
8150 struct ulp_bde64 bde
;
8151 struct sli4_sge
*sgl
= NULL
;
8152 struct lpfc_dmabuf
*dmabuf
;
8156 uint32_t offset
= 0; /* accumulated offset in the sg request list */
8157 int inbound
= 0; /* number of sg reply entries inbound from firmware */
8159 if (!piocbq
|| !sglq
)
8162 sgl
= (struct sli4_sge
*)sglq
->sgl
;
8163 icmd
= &piocbq
->iocb
;
8164 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
8165 return sglq
->sli4_xritag
;
8166 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8167 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
8168 sizeof(struct ulp_bde64
);
8169 /* The addrHigh and addrLow fields within the IOCB
8170 * have not been byteswapped yet so there is no
8171 * need to swap them back.
8173 if (piocbq
->context3
)
8174 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
8178 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
8182 for (i
= 0; i
< numBdes
; i
++) {
8183 /* Should already be byte swapped. */
8184 sgl
->addr_hi
= bpl
->addrHigh
;
8185 sgl
->addr_lo
= bpl
->addrLow
;
8187 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8188 if ((i
+1) == numBdes
)
8189 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8191 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
8192 /* swap the size field back to the cpu so we
8193 * can assign it to the sgl.
8195 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8196 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
8197 /* The offsets in the sgl need to be accumulated
8198 * separately for the request and reply lists.
8199 * The request is always first, the reply follows.
8201 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
8202 /* add up the reply sg entries */
8203 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
8205 /* first inbound? reset the offset */
8208 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
8209 bf_set(lpfc_sli4_sge_type
, sgl
,
8210 LPFC_SGE_TYPE_DATA
);
8211 offset
+= bde
.tus
.f
.bdeSize
;
8213 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8217 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
8218 /* The addrHigh and addrLow fields of the BDE have not
8219 * been byteswapped yet so they need to be swapped
8220 * before putting them in the sgl.
8223 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
8225 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
8226 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8227 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8228 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8230 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
8232 return sglq
->sli4_xritag
;
8236 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8237 * @phba: Pointer to HBA context object.
8238 * @piocb: Pointer to command iocb.
8239 * @wqe: Pointer to the work queue entry.
8241 * This routine converts the iocb command to its Work Queue Entry
8242 * equivalent. The wqe pointer should not have any fields set when
8243 * this routine is called because it will memcpy over them.
8244 * This routine does not set the CQ_ID or the WQEC bits in the
8247 * Returns: 0 = Success, IOCB_ERROR = Failure.
8250 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
8251 union lpfc_wqe
*wqe
)
8253 uint32_t xmit_len
= 0, total_len
= 0;
8257 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
8260 uint16_t abrt_iotag
;
8261 struct lpfc_iocbq
*abrtiocbq
;
8262 struct ulp_bde64
*bpl
= NULL
;
8263 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
8265 struct ulp_bde64 bde
;
8266 struct lpfc_nodelist
*ndlp
;
8270 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
8271 /* The fcp commands will set command type */
8272 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8273 command_type
= FCP_COMMAND
;
8274 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
8275 command_type
= ELS_COMMAND_FIP
;
8277 command_type
= ELS_COMMAND_NON_FIP
;
8279 if (phba
->fcp_embed_io
)
8280 memset(wqe
, 0, sizeof(union lpfc_wqe128
));
8281 /* Some of the fields are in the right position already */
8282 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
8283 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
8284 wqe
->generic
.wqe_com
.word10
= 0;
8286 abort_tag
= (uint32_t) iocbq
->iotag
;
8287 xritag
= iocbq
->sli4_xritag
;
8288 /* words0-2 bpl convert bde */
8289 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8290 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8291 sizeof(struct ulp_bde64
);
8292 bpl
= (struct ulp_bde64
*)
8293 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
8297 /* Should already be byte swapped. */
8298 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
8299 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
8300 /* swap the size field back to the cpu so we
8301 * can assign it to the sgl.
8303 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8304 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
8306 for (i
= 0; i
< numBdes
; i
++) {
8307 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8308 total_len
+= bde
.tus
.f
.bdeSize
;
8311 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8313 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8314 cmnd
= iocbq
->iocb
.ulpCommand
;
8316 switch (iocbq
->iocb
.ulpCommand
) {
8317 case CMD_ELS_REQUEST64_CR
:
8318 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8319 ndlp
= iocbq
->context_un
.ndlp
;
8321 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8322 if (!iocbq
->iocb
.ulpLe
) {
8323 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8324 "2007 Only Limited Edition cmd Format"
8325 " supported 0x%x\n",
8326 iocbq
->iocb
.ulpCommand
);
8330 wqe
->els_req
.payload_len
= xmit_len
;
8331 /* Els_reguest64 has a TMO */
8332 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8333 iocbq
->iocb
.ulpTimeout
);
8334 /* Need a VF for word 4 set the vf bit*/
8335 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
8336 /* And a VFID for word 12 */
8337 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
8338 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8339 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8340 iocbq
->iocb
.ulpContext
);
8341 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
8342 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
8343 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8344 if (command_type
== ELS_COMMAND_FIP
)
8345 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
8346 >> LPFC_FIP_ELS_ID_SHIFT
);
8347 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8348 iocbq
->context2
)->virt
);
8349 if_type
= bf_get(lpfc_sli_intf_if_type
,
8350 &phba
->sli4_hba
.sli_intf
);
8351 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8352 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
8353 *pcmd
== ELS_CMD_SCR
||
8354 *pcmd
== ELS_CMD_FDISC
||
8355 *pcmd
== ELS_CMD_LOGO
||
8356 *pcmd
== ELS_CMD_PLOGI
)) {
8357 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8358 bf_set(els_req64_sid
, &wqe
->els_req
,
8359 iocbq
->vport
->fc_myDID
);
8360 if ((*pcmd
== ELS_CMD_FLOGI
) &&
8361 !(phba
->fc_topology
==
8362 LPFC_TOPOLOGY_LOOP
))
8363 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
8364 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8365 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8366 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8367 } else if (pcmd
&& iocbq
->context1
) {
8368 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
8369 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8370 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8373 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
8374 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8375 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
8376 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
8377 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8378 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
8379 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8380 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
8381 wqe
->els_req
.max_response_payload_len
= total_len
- xmit_len
;
8383 case CMD_XMIT_SEQUENCE64_CX
:
8384 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
8385 iocbq
->iocb
.un
.ulpWord
[3]);
8386 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
8387 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8388 /* The entire sequence is transmitted for this IOCB */
8389 xmit_len
= total_len
;
8390 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8391 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8392 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8393 case CMD_XMIT_SEQUENCE64_CR
:
8394 /* word3 iocb=io_tag32 wqe=reserved */
8395 wqe
->xmit_sequence
.rsvd3
= 0;
8396 /* word4 relative_offset memcpy */
8397 /* word5 r_ctl/df_ctl memcpy */
8398 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8399 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8400 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8401 LPFC_WQE_IOD_WRITE
);
8402 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8403 LPFC_WQE_LENLOC_WORD12
);
8404 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8405 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8406 command_type
= OTHER_COMMAND
;
8408 case CMD_XMIT_BCAST64_CN
:
8409 /* word3 iocb=iotag32 wqe=seq_payload_len */
8410 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8411 /* word4 iocb=rsvd wqe=rsvd */
8412 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8413 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8414 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8415 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8416 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8417 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8418 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8419 LPFC_WQE_LENLOC_WORD3
);
8420 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8422 case CMD_FCP_IWRITE64_CR
:
8423 command_type
= FCP_COMMAND_DATA_OUT
;
8424 /* word3 iocb=iotag wqe=payload_offset_len */
8425 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8426 bf_set(payload_offset_len
, &wqe
->fcp_iwrite
,
8427 xmit_len
+ sizeof(struct fcp_rsp
));
8428 bf_set(cmd_buff_len
, &wqe
->fcp_iwrite
,
8430 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8431 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8432 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8433 iocbq
->iocb
.ulpFCP2Rcvy
);
8434 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8435 /* Always open the exchange */
8436 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8437 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8438 LPFC_WQE_LENLOC_WORD4
);
8439 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8440 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8441 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8442 bf_set(wqe_oas
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8443 bf_set(wqe_ccpe
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8444 if (iocbq
->priority
) {
8445 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8446 (iocbq
->priority
<< 1));
8448 bf_set(wqe_ccp
, &wqe
->fcp_iwrite
.wqe_com
,
8449 (phba
->cfg_XLanePriority
<< 1));
8452 /* Note, word 10 is already initialized to 0 */
8454 if (phba
->fcp_embed_io
) {
8455 struct lpfc_scsi_buf
*lpfc_cmd
;
8456 struct sli4_sge
*sgl
;
8457 union lpfc_wqe128
*wqe128
;
8458 struct fcp_cmnd
*fcp_cmnd
;
8461 /* 128 byte wqe support here */
8462 wqe128
= (union lpfc_wqe128
*)wqe
;
8464 lpfc_cmd
= iocbq
->context1
;
8465 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8466 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8468 /* Word 0-2 - FCP_CMND */
8469 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8470 BUFF_TYPE_BDE_IMMED
;
8471 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8472 wqe128
->generic
.bde
.addrHigh
= 0;
8473 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8475 bf_set(wqe_wqes
, &wqe128
->fcp_iwrite
.wqe_com
, 1);
8477 /* Word 22-29 FCP CMND Payload */
8478 ptr
= &wqe128
->words
[22];
8479 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8482 case CMD_FCP_IREAD64_CR
:
8483 /* word3 iocb=iotag wqe=payload_offset_len */
8484 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8485 bf_set(payload_offset_len
, &wqe
->fcp_iread
,
8486 xmit_len
+ sizeof(struct fcp_rsp
));
8487 bf_set(cmd_buff_len
, &wqe
->fcp_iread
,
8489 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8490 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8491 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8492 iocbq
->iocb
.ulpFCP2Rcvy
);
8493 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8494 /* Always open the exchange */
8495 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8496 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8497 LPFC_WQE_LENLOC_WORD4
);
8498 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8499 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8500 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8501 bf_set(wqe_oas
, &wqe
->fcp_iread
.wqe_com
, 1);
8502 bf_set(wqe_ccpe
, &wqe
->fcp_iread
.wqe_com
, 1);
8503 if (iocbq
->priority
) {
8504 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8505 (iocbq
->priority
<< 1));
8507 bf_set(wqe_ccp
, &wqe
->fcp_iread
.wqe_com
,
8508 (phba
->cfg_XLanePriority
<< 1));
8511 /* Note, word 10 is already initialized to 0 */
8513 if (phba
->fcp_embed_io
) {
8514 struct lpfc_scsi_buf
*lpfc_cmd
;
8515 struct sli4_sge
*sgl
;
8516 union lpfc_wqe128
*wqe128
;
8517 struct fcp_cmnd
*fcp_cmnd
;
8520 /* 128 byte wqe support here */
8521 wqe128
= (union lpfc_wqe128
*)wqe
;
8523 lpfc_cmd
= iocbq
->context1
;
8524 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8525 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8527 /* Word 0-2 - FCP_CMND */
8528 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8529 BUFF_TYPE_BDE_IMMED
;
8530 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8531 wqe128
->generic
.bde
.addrHigh
= 0;
8532 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8534 bf_set(wqe_wqes
, &wqe128
->fcp_iread
.wqe_com
, 1);
8536 /* Word 22-29 FCP CMND Payload */
8537 ptr
= &wqe128
->words
[22];
8538 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8541 case CMD_FCP_ICMND64_CR
:
8542 /* word3 iocb=iotag wqe=payload_offset_len */
8543 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8544 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
8545 xmit_len
+ sizeof(struct fcp_rsp
));
8546 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
,
8548 /* word3 iocb=IO_TAG wqe=reserved */
8549 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8550 /* Always open the exchange */
8551 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8552 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8553 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8554 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8555 LPFC_WQE_LENLOC_NONE
);
8556 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
8557 iocbq
->iocb
.ulpFCP2Rcvy
);
8558 if (iocbq
->iocb_flag
& LPFC_IO_OAS
) {
8559 bf_set(wqe_oas
, &wqe
->fcp_icmd
.wqe_com
, 1);
8560 bf_set(wqe_ccpe
, &wqe
->fcp_icmd
.wqe_com
, 1);
8561 if (iocbq
->priority
) {
8562 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8563 (iocbq
->priority
<< 1));
8565 bf_set(wqe_ccp
, &wqe
->fcp_icmd
.wqe_com
,
8566 (phba
->cfg_XLanePriority
<< 1));
8569 /* Note, word 10 is already initialized to 0 */
8571 if (phba
->fcp_embed_io
) {
8572 struct lpfc_scsi_buf
*lpfc_cmd
;
8573 struct sli4_sge
*sgl
;
8574 union lpfc_wqe128
*wqe128
;
8575 struct fcp_cmnd
*fcp_cmnd
;
8578 /* 128 byte wqe support here */
8579 wqe128
= (union lpfc_wqe128
*)wqe
;
8581 lpfc_cmd
= iocbq
->context1
;
8582 sgl
= (struct sli4_sge
*)lpfc_cmd
->fcp_bpl
;
8583 fcp_cmnd
= lpfc_cmd
->fcp_cmnd
;
8585 /* Word 0-2 - FCP_CMND */
8586 wqe128
->generic
.bde
.tus
.f
.bdeFlags
=
8587 BUFF_TYPE_BDE_IMMED
;
8588 wqe128
->generic
.bde
.tus
.f
.bdeSize
= sgl
->sge_len
;
8589 wqe128
->generic
.bde
.addrHigh
= 0;
8590 wqe128
->generic
.bde
.addrLow
= 88; /* Word 22 */
8592 bf_set(wqe_wqes
, &wqe128
->fcp_icmd
.wqe_com
, 1);
8594 /* Word 22-29 FCP CMND Payload */
8595 ptr
= &wqe128
->words
[22];
8596 memcpy(ptr
, fcp_cmnd
, sizeof(struct fcp_cmnd
));
8599 case CMD_GEN_REQUEST64_CR
:
8600 /* For this command calculate the xmit length of the
8604 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8605 sizeof(struct ulp_bde64
);
8606 for (i
= 0; i
< numBdes
; i
++) {
8607 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8608 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8610 xmit_len
+= bde
.tus
.f
.bdeSize
;
8612 /* word3 iocb=IO_TAG wqe=request_payload_len */
8613 wqe
->gen_req
.request_payload_len
= xmit_len
;
8614 /* word4 iocb=parameter wqe=relative_offset memcpy */
8615 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8616 /* word6 context tag copied in memcpy */
8617 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8618 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8619 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8620 "2015 Invalid CT %x command 0x%x\n",
8621 ct
, iocbq
->iocb
.ulpCommand
);
8624 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8625 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8626 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8627 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8628 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8629 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8630 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8631 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8632 wqe
->gen_req
.max_response_payload_len
= total_len
- xmit_len
;
8633 command_type
= OTHER_COMMAND
;
8635 case CMD_XMIT_ELS_RSP64_CX
:
8636 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8637 /* words0-2 BDE memcpy */
8638 /* word3 iocb=iotag32 wqe=response_payload_len */
8639 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8641 wqe
->xmit_els_rsp
.word4
= 0;
8642 /* word5 iocb=rsvd wge=did */
8643 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8644 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
8646 if_type
= bf_get(lpfc_sli_intf_if_type
,
8647 &phba
->sli4_hba
.sli_intf
);
8648 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8649 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
8650 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8651 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8652 iocbq
->vport
->fc_myDID
);
8653 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
8655 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
8659 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8660 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8661 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8662 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8663 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8664 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8665 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8666 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8667 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8668 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8669 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8670 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8671 LPFC_WQE_LENLOC_WORD3
);
8672 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8673 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8674 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8675 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8676 iocbq
->context2
)->virt
);
8677 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8678 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8679 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8680 iocbq
->vport
->fc_myDID
);
8681 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8682 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8683 phba
->vpi_ids
[phba
->pport
->vpi
]);
8685 command_type
= OTHER_COMMAND
;
8687 case CMD_CLOSE_XRI_CN
:
8688 case CMD_ABORT_XRI_CN
:
8689 case CMD_ABORT_XRI_CX
:
8690 /* words 0-2 memcpy should be 0 rserved */
8691 /* port will send abts */
8692 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8693 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8694 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8695 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8699 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8701 * The link is down, or the command was ELS_FIP
8702 * so the fw does not need to send abts
8705 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8707 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8708 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8709 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8710 wqe
->abort_cmd
.rsrvd5
= 0;
8711 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8712 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8713 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8715 * The abort handler will send us CMD_ABORT_XRI_CN or
8716 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8718 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8719 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8720 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8721 LPFC_WQE_LENLOC_NONE
);
8722 cmnd
= CMD_ABORT_XRI_CX
;
8723 command_type
= OTHER_COMMAND
;
8726 case CMD_XMIT_BLS_RSP64_CX
:
8727 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8728 /* As BLS ABTS RSP WQE is very different from other WQEs,
8729 * we re-construct this WQE here based on information in
8730 * iocbq from scratch.
8732 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8733 /* OX_ID is invariable to who sent ABTS to CT exchange */
8734 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8735 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8736 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8737 LPFC_ABTS_UNSOL_INT
) {
8738 /* ABTS sent by initiator to CT exchange, the
8739 * RX_ID field will be filled with the newly
8740 * allocated responder XRI.
8742 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8743 iocbq
->sli4_xritag
);
8745 /* ABTS sent by responder to CT exchange, the
8746 * RX_ID field will be filled with the responder
8749 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8750 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8752 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8753 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8756 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8758 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8759 iocbq
->iocb
.ulpContext
);
8760 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8761 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8762 phba
->vpi_ids
[phba
->pport
->vpi
]);
8763 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8764 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8765 LPFC_WQE_LENLOC_NONE
);
8766 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8767 command_type
= OTHER_COMMAND
;
8768 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8769 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8770 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8771 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8772 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8773 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8774 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8778 case CMD_XRI_ABORTED_CX
:
8779 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8780 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8781 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8782 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8783 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8785 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8786 "2014 Invalid command 0x%x\n",
8787 iocbq
->iocb
.ulpCommand
);
8792 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
8793 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
8794 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
8795 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
8796 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
8797 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
8798 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
8799 LPFC_IO_DIF_INSERT
);
8800 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8801 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8802 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8803 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8804 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8805 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8806 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8811 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8812 * @phba: Pointer to HBA context object.
8813 * @ring_number: SLI ring number to issue iocb on.
8814 * @piocb: Pointer to command iocb.
8815 * @flag: Flag indicating if this command can be put into txq.
8817 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8818 * an iocb command to an HBA with SLI-4 interface spec.
8820 * This function is called with hbalock held. The function will return success
8821 * after it successfully submit the iocb to firmware or after adding to the
8825 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8826 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8828 struct lpfc_sglq
*sglq
;
8829 union lpfc_wqe
*wqe
;
8830 union lpfc_wqe128 wqe128
;
8831 struct lpfc_queue
*wq
;
8832 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8834 lockdep_assert_held(&phba
->hbalock
);
8837 * The WQE can be either 64 or 128 bytes,
8838 * so allocate space on the stack assuming the largest.
8840 wqe
= (union lpfc_wqe
*)&wqe128
;
8842 if (piocb
->sli4_xritag
== NO_XRI
) {
8843 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8844 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8847 if (!list_empty(&pring
->txq
)) {
8848 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8849 __lpfc_sli_ringtx_put(phba
,
8851 return IOCB_SUCCESS
;
8856 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8858 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8859 __lpfc_sli_ringtx_put(phba
,
8862 return IOCB_SUCCESS
;
8868 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8869 /* These IO's already have an XRI and a mapped sgl. */
8873 * This is a continuation of a commandi,(CX) so this
8874 * sglq is on the active list
8876 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
8882 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8883 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8884 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8888 if (lpfc_sli4_iocb2wqe(phba
, piocb
, wqe
))
8891 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8892 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8893 if (!phba
->cfg_fof
|| (!(piocb
->iocb_flag
& LPFC_IO_OAS
))) {
8894 wq
= phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
];
8896 wq
= phba
->sli4_hba
.oas_wq
;
8898 if (lpfc_sli4_wq_put(wq
, wqe
))
8901 if (unlikely(!phba
->sli4_hba
.els_wq
))
8903 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, wqe
))
8906 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8912 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8914 * This routine wraps the actual lockless version for issusing IOCB function
8915 * pointer from the lpfc_hba struct.
8918 * IOCB_ERROR - Error
8919 * IOCB_SUCCESS - Success
8923 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8924 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8926 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8930 * lpfc_sli_api_table_setup - Set up sli api function jump table
8931 * @phba: The hba struct for which this call is being executed.
8932 * @dev_grp: The HBA PCI-Device group number.
8934 * This routine sets up the SLI interface API function jump table in @phba
8936 * Returns: 0 - success, -ENODEV - failure.
8939 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8943 case LPFC_PCI_DEV_LP
:
8944 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8945 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8947 case LPFC_PCI_DEV_OC
:
8948 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8949 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8952 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8953 "1419 Invalid HBA PCI-device group: 0x%x\n",
8958 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8963 * lpfc_sli_calc_ring - Calculates which ring to use
8964 * @phba: Pointer to HBA context object.
8965 * @ring_number: Initial ring
8966 * @piocb: Pointer to command iocb.
8968 * For SLI4, FCP IO can deferred to one fo many WQs, based on
8969 * fcp_wqidx, thus we need to calculate the corresponding ring.
8970 * Since ABORTS must go on the same WQ of the command they are
8971 * aborting, we use command's fcp_wqidx.
8974 lpfc_sli_calc_ring(struct lpfc_hba
*phba
, uint32_t ring_number
,
8975 struct lpfc_iocbq
*piocb
)
8977 if (phba
->sli_rev
< LPFC_SLI_REV4
)
8980 if (piocb
->iocb_flag
& (LPFC_IO_FCP
| LPFC_USE_FCPWQIDX
)) {
8981 if (!(phba
->cfg_fof
) ||
8982 (!(piocb
->iocb_flag
& LPFC_IO_FOF
))) {
8983 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8984 return LPFC_HBA_ERROR
;
8986 * for abort iocb fcp_wqidx should already
8987 * be setup based on what work queue we used.
8989 if (!(piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
))
8991 lpfc_sli4_scmd_to_wqidx_distr(phba
,
8993 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+
8996 if (unlikely(!phba
->sli4_hba
.oas_wq
))
8997 return LPFC_HBA_ERROR
;
8998 piocb
->fcp_wqidx
= 0;
8999 ring_number
= LPFC_FCP_OAS_RING
;
9006 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
9007 * @phba: Pointer to HBA context object.
9008 * @pring: Pointer to driver SLI ring object.
9009 * @piocb: Pointer to command iocb.
9010 * @flag: Flag indicating if this command can be put into txq.
9012 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
9013 * function. This function gets the hbalock and calls
9014 * __lpfc_sli_issue_iocb function and will return the error returned
9015 * by __lpfc_sli_issue_iocb function. This wrapper is used by
9016 * functions which do not hold hbalock.
9019 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
9020 struct lpfc_iocbq
*piocb
, uint32_t flag
)
9022 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
9023 struct lpfc_sli_ring
*pring
;
9024 struct lpfc_queue
*fpeq
;
9025 struct lpfc_eqe
*eqe
;
9026 unsigned long iflags
;
9029 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9030 ring_number
= lpfc_sli_calc_ring(phba
, ring_number
, piocb
);
9031 if (unlikely(ring_number
== LPFC_HBA_ERROR
))
9033 idx
= piocb
->fcp_wqidx
;
9035 pring
= &phba
->sli
.ring
[ring_number
];
9036 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9037 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9038 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9040 if (lpfc_fcp_look_ahead
&& (piocb
->iocb_flag
& LPFC_IO_FCP
)) {
9041 fcp_eq_hdl
= &phba
->sli4_hba
.fcp_eq_hdl
[idx
];
9043 if (atomic_dec_and_test(&fcp_eq_hdl
->
9046 /* Get associated EQ with this index */
9047 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
9049 /* Turn off interrupts from this EQ */
9050 lpfc_sli4_eq_clr_intr(fpeq
);
9053 * Process all the events on FCP EQ
9055 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
9056 lpfc_sli4_hba_handle_eqe(phba
,
9058 fpeq
->EQ_processed
++;
9061 /* Always clear and re-arm the EQ */
9062 lpfc_sli4_eq_release(fpeq
,
9065 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
9068 /* For now, SLI2/3 will still use hbalock */
9069 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9070 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
9071 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9077 * lpfc_extra_ring_setup - Extra ring setup function
9078 * @phba: Pointer to HBA context object.
9080 * This function is called while driver attaches with the
9081 * HBA to setup the extra ring. The extra ring is used
9082 * only when driver needs to support target mode functionality
9083 * or IP over FC functionalities.
9085 * This function is called with no lock held.
9088 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
9090 struct lpfc_sli
*psli
;
9091 struct lpfc_sli_ring
*pring
;
9095 /* Adjust cmd/rsp ring iocb entries more evenly */
9097 /* Take some away from the FCP ring */
9098 pring
= &psli
->ring
[psli
->fcp_ring
];
9099 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9100 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9101 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9102 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9104 /* and give them to the extra ring */
9105 pring
= &psli
->ring
[psli
->extra_ring
];
9107 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9108 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9109 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9110 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9112 /* Setup default profile for this ring */
9113 pring
->iotag_max
= 4096;
9114 pring
->num_mask
= 1;
9115 pring
->prt
[0].profile
= 0; /* Mask 0 */
9116 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
9117 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
9118 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
9122 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
9123 * @phba: Pointer to HBA context object.
9124 * @iocbq: Pointer to iocb object.
9126 * The async_event handler calls this routine when it receives
9127 * an ASYNC_STATUS_CN event from the port. The port generates
9128 * this event when an Abort Sequence request to an rport fails
9129 * twice in succession. The abort could be originated by the
9130 * driver or by the port. The ABTS could have been for an ELS
9131 * or FCP IO. The port only generates this event when an ABTS
9132 * fails to complete after one retry.
9135 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
9136 struct lpfc_iocbq
*iocbq
)
9138 struct lpfc_nodelist
*ndlp
= NULL
;
9139 uint16_t rpi
= 0, vpi
= 0;
9140 struct lpfc_vport
*vport
= NULL
;
9142 /* The rpi in the ulpContext is vport-sensitive. */
9143 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
9144 rpi
= iocbq
->iocb
.ulpContext
;
9146 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9147 "3092 Port generated ABTS async event "
9148 "on vpi %d rpi %d status 0x%x\n",
9149 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
9151 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
9154 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
9155 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
9158 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
9159 lpfc_sli_abts_recover_port(vport
, ndlp
);
9163 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9164 "3095 Event Context not found, no "
9165 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
9166 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
9170 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
9171 * @phba: pointer to HBA context object.
9172 * @ndlp: nodelist pointer for the impacted rport.
9173 * @axri: pointer to the wcqe containing the failed exchange.
9175 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
9176 * port. The port generates this event when an abort exchange request to an
9177 * rport fails twice in succession with no reply. The abort could be originated
9178 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
9181 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
9182 struct lpfc_nodelist
*ndlp
,
9183 struct sli4_wcqe_xri_aborted
*axri
)
9185 struct lpfc_vport
*vport
;
9186 uint32_t ext_status
= 0;
9188 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
9189 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9190 "3115 Node Context not found, driver "
9191 "ignoring abts err event\n");
9195 vport
= ndlp
->vport
;
9196 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
9197 "3116 Port generated FCP XRI ABORT event on "
9198 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
9199 ndlp
->vport
->vpi
, phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
],
9200 bf_get(lpfc_wcqe_xa_xri
, axri
),
9201 bf_get(lpfc_wcqe_xa_status
, axri
),
9205 * Catch the ABTS protocol failure case. Older OCe FW releases returned
9206 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
9207 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
9209 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
9210 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
9211 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
9212 lpfc_sli_abts_recover_port(vport
, ndlp
);
9216 * lpfc_sli_async_event_handler - ASYNC iocb handler function
9217 * @phba: Pointer to HBA context object.
9218 * @pring: Pointer to driver SLI ring object.
9219 * @iocbq: Pointer to iocb object.
9221 * This function is called by the slow ring event handler
9222 * function when there is an ASYNC event iocb in the ring.
9223 * This function is called with no lock held.
9224 * Currently this function handles only temperature related
9225 * ASYNC events. The function decodes the temperature sensor
9226 * event message and posts events for the management applications.
9229 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
9230 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
9234 struct temp_event temp_event_data
;
9235 struct Scsi_Host
*shost
;
9238 icmd
= &iocbq
->iocb
;
9239 evt_code
= icmd
->un
.asyncstat
.evt_code
;
9242 case ASYNC_TEMP_WARN
:
9243 case ASYNC_TEMP_SAFE
:
9244 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
9245 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
9246 if (evt_code
== ASYNC_TEMP_WARN
) {
9247 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
9248 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9249 "0347 Adapter is very hot, please take "
9250 "corrective action. temperature : %d Celsius\n",
9251 (uint32_t) icmd
->ulpContext
);
9253 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
9254 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
9255 "0340 Adapter temperature is OK now. "
9256 "temperature : %d Celsius\n",
9257 (uint32_t) icmd
->ulpContext
);
9260 /* Send temperature change event to applications */
9261 shost
= lpfc_shost_from_vport(phba
->pport
);
9262 fc_host_post_vendor_event(shost
, fc_get_event_number(),
9263 sizeof(temp_event_data
), (char *) &temp_event_data
,
9266 case ASYNC_STATUS_CN
:
9267 lpfc_sli_abts_err_handler(phba
, iocbq
);
9270 iocb_w
= (uint32_t *) icmd
;
9271 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
9272 "0346 Ring %d handler: unexpected ASYNC_STATUS"
9274 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
9275 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
9276 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
9277 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
9278 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
9279 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
9280 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
9281 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
9282 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
9290 * lpfc_sli_setup - SLI ring setup function
9291 * @phba: Pointer to HBA context object.
9293 * lpfc_sli_setup sets up rings of the SLI interface with
9294 * number of iocbs per ring and iotags. This function is
9295 * called while driver attach to the HBA and before the
9296 * interrupts are enabled. So there is no need for locking.
9298 * This function always returns 0.
9301 lpfc_sli_setup(struct lpfc_hba
*phba
)
9303 int i
, totiocbsize
= 0;
9304 struct lpfc_sli
*psli
= &phba
->sli
;
9305 struct lpfc_sli_ring
*pring
;
9307 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
9308 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9309 psli
->num_rings
+= phba
->cfg_fcp_io_channel
;
9311 psli
->fcp_ring
= LPFC_FCP_RING
;
9312 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
9313 psli
->extra_ring
= LPFC_EXTRA_RING
;
9315 psli
->iocbq_lookup
= NULL
;
9316 psli
->iocbq_lookup_len
= 0;
9317 psli
->last_iotag
= 0;
9319 for (i
= 0; i
< psli
->num_rings
; i
++) {
9320 pring
= &psli
->ring
[i
];
9322 case LPFC_FCP_RING
: /* ring 0 - FCP */
9323 /* numCiocb and numRiocb are used in config_port */
9324 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
9325 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
9326 pring
->sli
.sli3
.numCiocb
+=
9327 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
9328 pring
->sli
.sli3
.numRiocb
+=
9329 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
9330 pring
->sli
.sli3
.numCiocb
+=
9331 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
9332 pring
->sli
.sli3
.numRiocb
+=
9333 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
9334 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9335 SLI3_IOCB_CMD_SIZE
:
9337 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9338 SLI3_IOCB_RSP_SIZE
:
9340 pring
->iotag_ctr
= 0;
9342 (phba
->cfg_hba_queue_depth
* 2);
9343 pring
->fast_iotag
= pring
->iotag_max
;
9344 pring
->num_mask
= 0;
9346 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
9347 /* numCiocb and numRiocb are used in config_port */
9348 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
9349 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
9350 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9351 SLI3_IOCB_CMD_SIZE
:
9353 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9354 SLI3_IOCB_RSP_SIZE
:
9356 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
9357 pring
->num_mask
= 0;
9359 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
9360 /* numCiocb and numRiocb are used in config_port */
9361 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
9362 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
9363 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9364 SLI3_IOCB_CMD_SIZE
:
9366 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9367 SLI3_IOCB_RSP_SIZE
:
9369 pring
->fast_iotag
= 0;
9370 pring
->iotag_ctr
= 0;
9371 pring
->iotag_max
= 4096;
9372 pring
->lpfc_sli_rcv_async_status
=
9373 lpfc_sli_async_event_handler
;
9374 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9375 pring
->prt
[0].profile
= 0; /* Mask 0 */
9376 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9377 pring
->prt
[0].type
= FC_TYPE_ELS
;
9378 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9379 lpfc_els_unsol_event
;
9380 pring
->prt
[1].profile
= 0; /* Mask 1 */
9381 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9382 pring
->prt
[1].type
= FC_TYPE_ELS
;
9383 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9384 lpfc_els_unsol_event
;
9385 pring
->prt
[2].profile
= 0; /* Mask 2 */
9386 /* NameServer Inquiry */
9387 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9389 pring
->prt
[2].type
= FC_TYPE_CT
;
9390 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9391 lpfc_ct_unsol_event
;
9392 pring
->prt
[3].profile
= 0; /* Mask 3 */
9393 /* NameServer response */
9394 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9396 pring
->prt
[3].type
= FC_TYPE_CT
;
9397 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9398 lpfc_ct_unsol_event
;
9401 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
9402 pring
->sli
.sli3
.sizeCiocb
) +
9403 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
9405 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
9406 /* Too many cmd / rsp ring entries in SLI2 SLIM */
9407 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
9408 "SLI2 SLIM Data: x%x x%lx\n",
9409 phba
->brd_no
, totiocbsize
,
9410 (unsigned long) MAX_SLIM_IOCB_SIZE
);
9412 if (phba
->cfg_multi_ring_support
== 2)
9413 lpfc_extra_ring_setup(phba
);
9419 * lpfc_sli_queue_setup - Queue initialization function
9420 * @phba: Pointer to HBA context object.
9422 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
9423 * ring. This function also initializes ring indices of each ring.
9424 * This function is called during the initialization of the SLI
9425 * interface of an HBA.
9426 * This function is called with no lock held and always returns
9430 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
9432 struct lpfc_sli
*psli
;
9433 struct lpfc_sli_ring
*pring
;
9437 spin_lock_irq(&phba
->hbalock
);
9438 INIT_LIST_HEAD(&psli
->mboxq
);
9439 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9440 /* Initialize list headers for txq and txcmplq as double linked lists */
9441 for (i
= 0; i
< psli
->num_rings
; i
++) {
9442 pring
= &psli
->ring
[i
];
9444 pring
->sli
.sli3
.next_cmdidx
= 0;
9445 pring
->sli
.sli3
.local_getidx
= 0;
9446 pring
->sli
.sli3
.cmdidx
= 0;
9448 INIT_LIST_HEAD(&pring
->txq
);
9449 INIT_LIST_HEAD(&pring
->txcmplq
);
9450 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9451 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
9452 INIT_LIST_HEAD(&pring
->postbufq
);
9453 spin_lock_init(&pring
->ring_lock
);
9455 spin_unlock_irq(&phba
->hbalock
);
9460 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9461 * @phba: Pointer to HBA context object.
9463 * This routine flushes the mailbox command subsystem. It will unconditionally
9464 * flush all the mailbox commands in the three possible stages in the mailbox
9465 * command sub-system: pending mailbox command queue; the outstanding mailbox
9466 * command; and completed mailbox command queue. It is caller's responsibility
9467 * to make sure that the driver is in the proper state to flush the mailbox
9468 * command sub-system. Namely, the posting of mailbox commands into the
9469 * pending mailbox command queue from the various clients must be stopped;
9470 * either the HBA is in a state that it will never works on the outstanding
9471 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
9472 * mailbox command has been completed.
9475 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
9477 LIST_HEAD(completions
);
9478 struct lpfc_sli
*psli
= &phba
->sli
;
9480 unsigned long iflag
;
9482 /* Flush all the mailbox commands in the mbox system */
9483 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9484 /* The pending mailbox command queue */
9485 list_splice_init(&phba
->sli
.mboxq
, &completions
);
9486 /* The outstanding active mailbox command */
9487 if (psli
->mbox_active
) {
9488 list_add_tail(&psli
->mbox_active
->list
, &completions
);
9489 psli
->mbox_active
= NULL
;
9490 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9492 /* The completed mailbox command queue */
9493 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
9494 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9496 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
9497 while (!list_empty(&completions
)) {
9498 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
9499 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
9501 pmb
->mbox_cmpl(phba
, pmb
);
9506 * lpfc_sli_host_down - Vport cleanup function
9507 * @vport: Pointer to virtual port object.
9509 * lpfc_sli_host_down is called to clean up the resources
9510 * associated with a vport before destroying virtual
9511 * port data structures.
9512 * This function does following operations:
9513 * - Free discovery resources associated with this virtual
9515 * - Free iocbs associated with this virtual port in
9517 * - Send abort for all iocb commands associated with this
9520 * This function is called with no lock held and always returns 1.
9523 lpfc_sli_host_down(struct lpfc_vport
*vport
)
9525 LIST_HEAD(completions
);
9526 struct lpfc_hba
*phba
= vport
->phba
;
9527 struct lpfc_sli
*psli
= &phba
->sli
;
9528 struct lpfc_sli_ring
*pring
;
9529 struct lpfc_iocbq
*iocb
, *next_iocb
;
9531 unsigned long flags
= 0;
9532 uint16_t prev_pring_flag
;
9534 lpfc_cleanup_discovery_resources(vport
);
9536 spin_lock_irqsave(&phba
->hbalock
, flags
);
9537 for (i
= 0; i
< psli
->num_rings
; i
++) {
9538 pring
= &psli
->ring
[i
];
9539 prev_pring_flag
= pring
->flag
;
9540 /* Only slow rings */
9541 if (pring
->ringno
== LPFC_ELS_RING
) {
9542 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9543 /* Set the lpfc data pending flag */
9544 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9547 * Error everything on the txq since these iocbs have not been
9548 * given to the FW yet.
9550 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
9551 if (iocb
->vport
!= vport
)
9553 list_move_tail(&iocb
->list
, &completions
);
9556 /* Next issue ABTS for everything on the txcmplq */
9557 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
9559 if (iocb
->vport
!= vport
)
9561 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
9564 pring
->flag
= prev_pring_flag
;
9567 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9569 /* Cancel all the IOCBs from the completions list */
9570 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9576 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9577 * @phba: Pointer to HBA context object.
9579 * This function cleans up all iocb, buffers, mailbox commands
9580 * while shutting down the HBA. This function is called with no
9581 * lock held and always returns 1.
9582 * This function does the following to cleanup driver resources:
9583 * - Free discovery resources for each virtual port
9584 * - Cleanup any pending fabric iocbs
9585 * - Iterate through the iocb txq and free each entry
9587 * - Free up any buffer posted to the HBA
9588 * - Free mailbox commands in the mailbox queue.
9591 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
9593 LIST_HEAD(completions
);
9594 struct lpfc_sli
*psli
= &phba
->sli
;
9595 struct lpfc_sli_ring
*pring
;
9596 struct lpfc_dmabuf
*buf_ptr
;
9597 unsigned long flags
= 0;
9600 /* Shutdown the mailbox command sub-system */
9601 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
9603 lpfc_hba_down_prep(phba
);
9605 lpfc_fabric_abort_hba(phba
);
9607 spin_lock_irqsave(&phba
->hbalock
, flags
);
9608 for (i
= 0; i
< psli
->num_rings
; i
++) {
9609 pring
= &psli
->ring
[i
];
9610 /* Only slow rings */
9611 if (pring
->ringno
== LPFC_ELS_RING
) {
9612 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9613 /* Set the lpfc data pending flag */
9614 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9618 * Error everything on the txq since these iocbs have not been
9619 * given to the FW yet.
9621 list_splice_init(&pring
->txq
, &completions
);
9623 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9625 /* Cancel all the IOCBs from the completions list */
9626 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9629 spin_lock_irqsave(&phba
->hbalock
, flags
);
9630 list_splice_init(&phba
->elsbuf
, &completions
);
9631 phba
->elsbuf_cnt
= 0;
9632 phba
->elsbuf_prev_cnt
= 0;
9633 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9635 while (!list_empty(&completions
)) {
9636 list_remove_head(&completions
, buf_ptr
,
9637 struct lpfc_dmabuf
, list
);
9638 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
9642 /* Return any active mbox cmds */
9643 del_timer_sync(&psli
->mbox_tmo
);
9645 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
9646 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9647 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9653 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9654 * @srcp: Source memory pointer.
9655 * @destp: Destination memory pointer.
9656 * @cnt: Number of words required to be copied.
9658 * This function is used for copying data between driver memory
9659 * and the SLI memory. This function also changes the endianness
9660 * of each word if native endianness is different from SLI
9661 * endianness. This function can be called with or without
9665 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9667 uint32_t *src
= srcp
;
9668 uint32_t *dest
= destp
;
9672 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9674 ldata
= le32_to_cpu(ldata
);
9683 * lpfc_sli_bemem_bcopy - SLI memory copy function
9684 * @srcp: Source memory pointer.
9685 * @destp: Destination memory pointer.
9686 * @cnt: Number of words required to be copied.
9688 * This function is used for copying data between a data structure
9689 * with big endian representation to local endianness.
9690 * This function can be called with or without lock.
9693 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9695 uint32_t *src
= srcp
;
9696 uint32_t *dest
= destp
;
9700 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9702 ldata
= be32_to_cpu(ldata
);
9710 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9711 * @phba: Pointer to HBA context object.
9712 * @pring: Pointer to driver SLI ring object.
9713 * @mp: Pointer to driver buffer object.
9715 * This function is called with no lock held.
9716 * It always return zero after adding the buffer to the postbufq
9720 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9721 struct lpfc_dmabuf
*mp
)
9723 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9725 spin_lock_irq(&phba
->hbalock
);
9726 list_add_tail(&mp
->list
, &pring
->postbufq
);
9727 pring
->postbufq_cnt
++;
9728 spin_unlock_irq(&phba
->hbalock
);
9733 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9734 * @phba: Pointer to HBA context object.
9736 * When HBQ is enabled, buffers are searched based on tags. This function
9737 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9738 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9739 * does not conflict with tags of buffer posted for unsolicited events.
9740 * The function returns the allocated tag. The function is called with
9744 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9746 spin_lock_irq(&phba
->hbalock
);
9747 phba
->buffer_tag_count
++;
9749 * Always set the QUE_BUFTAG_BIT to distiguish between
9750 * a tag assigned by HBQ.
9752 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9753 spin_unlock_irq(&phba
->hbalock
);
9754 return phba
->buffer_tag_count
;
9758 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9759 * @phba: Pointer to HBA context object.
9760 * @pring: Pointer to driver SLI ring object.
9763 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9764 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9765 * iocb is posted to the response ring with the tag of the buffer.
9766 * This function searches the pring->postbufq list using the tag
9767 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9768 * iocb. If the buffer is found then lpfc_dmabuf object of the
9769 * buffer is returned to the caller else NULL is returned.
9770 * This function is called with no lock held.
9772 struct lpfc_dmabuf
*
9773 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9776 struct lpfc_dmabuf
*mp
, *next_mp
;
9777 struct list_head
*slp
= &pring
->postbufq
;
9779 /* Search postbufq, from the beginning, looking for a match on tag */
9780 spin_lock_irq(&phba
->hbalock
);
9781 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9782 if (mp
->buffer_tag
== tag
) {
9783 list_del_init(&mp
->list
);
9784 pring
->postbufq_cnt
--;
9785 spin_unlock_irq(&phba
->hbalock
);
9790 spin_unlock_irq(&phba
->hbalock
);
9791 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9792 "0402 Cannot find virtual addr for buffer tag on "
9793 "ring %d Data x%lx x%p x%p x%x\n",
9794 pring
->ringno
, (unsigned long) tag
,
9795 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9801 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9802 * @phba: Pointer to HBA context object.
9803 * @pring: Pointer to driver SLI ring object.
9804 * @phys: DMA address of the buffer.
9806 * This function searches the buffer list using the dma_address
9807 * of unsolicited event to find the driver's lpfc_dmabuf object
9808 * corresponding to the dma_address. The function returns the
9809 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9810 * This function is called by the ct and els unsolicited event
9811 * handlers to get the buffer associated with the unsolicited
9814 * This function is called with no lock held.
9816 struct lpfc_dmabuf
*
9817 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9820 struct lpfc_dmabuf
*mp
, *next_mp
;
9821 struct list_head
*slp
= &pring
->postbufq
;
9823 /* Search postbufq, from the beginning, looking for a match on phys */
9824 spin_lock_irq(&phba
->hbalock
);
9825 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9826 if (mp
->phys
== phys
) {
9827 list_del_init(&mp
->list
);
9828 pring
->postbufq_cnt
--;
9829 spin_unlock_irq(&phba
->hbalock
);
9834 spin_unlock_irq(&phba
->hbalock
);
9835 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9836 "0410 Cannot find virtual addr for mapped buf on "
9837 "ring %d Data x%llx x%p x%p x%x\n",
9838 pring
->ringno
, (unsigned long long)phys
,
9839 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9844 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9845 * @phba: Pointer to HBA context object.
9846 * @cmdiocb: Pointer to driver command iocb object.
9847 * @rspiocb: Pointer to driver response iocb object.
9849 * This function is the completion handler for the abort iocbs for
9850 * ELS commands. This function is called from the ELS ring event
9851 * handler with no lock held. This function frees memory resources
9852 * associated with the abort iocb.
9855 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9856 struct lpfc_iocbq
*rspiocb
)
9858 IOCB_t
*irsp
= &rspiocb
->iocb
;
9859 uint16_t abort_iotag
, abort_context
;
9860 struct lpfc_iocbq
*abort_iocb
= NULL
;
9862 if (irsp
->ulpStatus
) {
9865 * Assume that the port already completed and returned, or
9866 * will return the iocb. Just Log the message.
9868 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9869 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9871 spin_lock_irq(&phba
->hbalock
);
9872 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9873 if (abort_iotag
!= 0 &&
9874 abort_iotag
<= phba
->sli
.last_iotag
)
9876 phba
->sli
.iocbq_lookup
[abort_iotag
];
9878 /* For sli4 the abort_tag is the XRI,
9879 * so the abort routine puts the iotag of the iocb
9880 * being aborted in the context field of the abort
9883 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9885 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9886 "0327 Cannot abort els iocb %p "
9887 "with tag %x context %x, abort status %x, "
9889 abort_iocb
, abort_iotag
, abort_context
,
9890 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9892 spin_unlock_irq(&phba
->hbalock
);
9894 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9899 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9900 * @phba: Pointer to HBA context object.
9901 * @cmdiocb: Pointer to driver command iocb object.
9902 * @rspiocb: Pointer to driver response iocb object.
9904 * The function is called from SLI ring event handler with no
9905 * lock held. This function is the completion handler for ELS commands
9906 * which are aborted. The function frees memory resources used for
9907 * the aborted ELS commands.
9910 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9911 struct lpfc_iocbq
*rspiocb
)
9913 IOCB_t
*irsp
= &rspiocb
->iocb
;
9915 /* ELS cmd tag <ulpIoTag> completes */
9916 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9917 "0139 Ignoring ELS cmd tag x%x completion Data: "
9919 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9920 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9921 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9922 lpfc_ct_free_iocb(phba
, cmdiocb
);
9924 lpfc_els_free_iocb(phba
, cmdiocb
);
9929 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9930 * @phba: Pointer to HBA context object.
9931 * @pring: Pointer to driver SLI ring object.
9932 * @cmdiocb: Pointer to driver command iocb object.
9934 * This function issues an abort iocb for the provided command iocb down to
9935 * the port. Other than the case the outstanding command iocb is an abort
9936 * request, this function issues abort out unconditionally. This function is
9937 * called with hbalock held. The function returns 0 when it fails due to
9938 * memory allocation failure or when the command iocb is an abort request.
9941 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9942 struct lpfc_iocbq
*cmdiocb
)
9944 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9945 struct lpfc_iocbq
*abtsiocbp
;
9946 IOCB_t
*icmd
= NULL
;
9947 IOCB_t
*iabt
= NULL
;
9950 unsigned long iflags
;
9952 lockdep_assert_held(&phba
->hbalock
);
9955 * There are certain command types we don't want to abort. And we
9956 * don't want to abort commands that are already in the process of
9959 icmd
= &cmdiocb
->iocb
;
9960 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9961 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9962 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9965 /* issue ABTS for this IOCB based on iotag */
9966 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9967 if (abtsiocbp
== NULL
)
9970 /* This signals the response to set the correct status
9971 * before calling the completion handler
9973 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9975 iabt
= &abtsiocbp
->iocb
;
9976 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9977 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9978 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9979 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9980 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9983 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9985 iabt
->ulpClass
= icmd
->ulpClass
;
9987 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9988 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9989 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9990 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9991 if (cmdiocb
->iocb_flag
& LPFC_IO_FOF
)
9992 abtsiocbp
->iocb_flag
|= LPFC_IO_FOF
;
9994 if (phba
->link_state
>= LPFC_LINK_UP
)
9995 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9997 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9999 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
10001 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
10002 "0339 Abort xri x%x, original iotag x%x, "
10003 "abort cmd iotag x%x\n",
10004 iabt
->un
.acxri
.abortIoTag
,
10005 iabt
->un
.acxri
.abortContextTag
,
10008 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10010 lpfc_sli_calc_ring(phba
, pring
->ringno
, abtsiocbp
);
10011 if (unlikely(ring_number
== LPFC_HBA_ERROR
))
10013 pring
= &phba
->sli
.ring
[ring_number
];
10014 /* Note: both hbalock and ring_lock need to be set here */
10015 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
10016 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10018 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
10020 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10025 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
10028 * Caller to this routine should check for IOCB_ERROR
10029 * and handle it properly. This routine no longer removes
10030 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10036 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
10037 * @phba: Pointer to HBA context object.
10038 * @pring: Pointer to driver SLI ring object.
10039 * @cmdiocb: Pointer to driver command iocb object.
10041 * This function issues an abort iocb for the provided command iocb. In case
10042 * of unloading, the abort iocb will not be issued to commands on the ELS
10043 * ring. Instead, the callback function shall be changed to those commands
10044 * so that nothing happens when them finishes. This function is called with
10045 * hbalock held. The function returns 0 when the command iocb is an abort
10049 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10050 struct lpfc_iocbq
*cmdiocb
)
10052 struct lpfc_vport
*vport
= cmdiocb
->vport
;
10053 int retval
= IOCB_ERROR
;
10054 IOCB_t
*icmd
= NULL
;
10056 lockdep_assert_held(&phba
->hbalock
);
10059 * There are certain command types we don't want to abort. And we
10060 * don't want to abort commands that are already in the process of
10063 icmd
= &cmdiocb
->iocb
;
10064 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
10065 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
10066 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
10070 * If we're unloading, don't abort iocb on the ELS ring, but change
10071 * the callback so that nothing happens when it finishes.
10073 if ((vport
->load_flag
& FC_UNLOADING
) &&
10074 (pring
->ringno
== LPFC_ELS_RING
)) {
10075 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
10076 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
10078 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
10079 goto abort_iotag_exit
;
10082 /* Now, we try to issue the abort to the cmdiocb out */
10083 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
10087 * Caller to this routine should check for IOCB_ERROR
10088 * and handle it properly. This routine no longer removes
10089 * iocb off txcmplq and call compl in case of IOCB_ERROR.
10095 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
10096 * @phba: pointer to lpfc HBA data structure.
10098 * This routine will abort all pending and outstanding iocbs to an HBA.
10101 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
10103 struct lpfc_sli
*psli
= &phba
->sli
;
10104 struct lpfc_sli_ring
*pring
;
10107 for (i
= 0; i
< psli
->num_rings
; i
++) {
10108 pring
= &psli
->ring
[i
];
10109 lpfc_sli_abort_iocb_ring(phba
, pring
);
10114 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
10115 * @iocbq: Pointer to driver iocb object.
10116 * @vport: Pointer to driver virtual port object.
10117 * @tgt_id: SCSI ID of the target.
10118 * @lun_id: LUN ID of the scsi device.
10119 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
10121 * This function acts as an iocb filter for functions which abort or count
10122 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
10123 * 0 if the filtering criteria is met for the given iocb and will return
10124 * 1 if the filtering criteria is not met.
10125 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
10126 * given iocb is for the SCSI device specified by vport, tgt_id and
10127 * lun_id parameter.
10128 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
10129 * given iocb is for the SCSI target specified by vport and tgt_id
10131 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
10132 * given iocb is for the SCSI host associated with the given vport.
10133 * This function is called with no locks held.
10136 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
10137 uint16_t tgt_id
, uint64_t lun_id
,
10138 lpfc_ctx_cmd ctx_cmd
)
10140 struct lpfc_scsi_buf
*lpfc_cmd
;
10143 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
10146 if (iocbq
->vport
!= vport
)
10149 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
10151 if (lpfc_cmd
->pCmd
== NULL
)
10156 if ((lpfc_cmd
->rdata
->pnode
) &&
10157 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
10158 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
10162 if ((lpfc_cmd
->rdata
->pnode
) &&
10163 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
10166 case LPFC_CTX_HOST
:
10170 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
10171 __func__
, ctx_cmd
);
10179 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
10180 * @vport: Pointer to virtual port.
10181 * @tgt_id: SCSI ID of the target.
10182 * @lun_id: LUN ID of the scsi device.
10183 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10185 * This function returns number of FCP commands pending for the vport.
10186 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
10187 * commands pending on the vport associated with SCSI device specified
10188 * by tgt_id and lun_id parameters.
10189 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
10190 * commands pending on the vport associated with SCSI target specified
10191 * by tgt_id parameter.
10192 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
10193 * commands pending on the vport.
10194 * This function returns the number of iocbs which satisfy the filter.
10195 * This function is called without any lock held.
10198 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
10199 lpfc_ctx_cmd ctx_cmd
)
10201 struct lpfc_hba
*phba
= vport
->phba
;
10202 struct lpfc_iocbq
*iocbq
;
10205 spin_lock_irq(&phba
->hbalock
);
10206 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
10207 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10209 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
10213 spin_unlock_irq(&phba
->hbalock
);
10219 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
10220 * @phba: Pointer to HBA context object
10221 * @cmdiocb: Pointer to command iocb object.
10222 * @rspiocb: Pointer to response iocb object.
10224 * This function is called when an aborted FCP iocb completes. This
10225 * function is called by the ring event handler with no lock held.
10226 * This function frees the iocb.
10229 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
10230 struct lpfc_iocbq
*rspiocb
)
10232 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10233 "3096 ABORT_XRI_CN completing on rpi x%x "
10234 "original iotag x%x, abort cmd iotag x%x "
10235 "status 0x%x, reason 0x%x\n",
10236 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
10237 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
10238 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
10239 rspiocb
->iocb
.un
.ulpWord
[4]);
10240 lpfc_sli_release_iocbq(phba
, cmdiocb
);
10245 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
10246 * @vport: Pointer to virtual port.
10247 * @pring: Pointer to driver SLI ring object.
10248 * @tgt_id: SCSI ID of the target.
10249 * @lun_id: LUN ID of the scsi device.
10250 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10252 * This function sends an abort command for every SCSI command
10253 * associated with the given virtual port pending on the ring
10254 * filtered by lpfc_sli_validate_fcp_iocb function.
10255 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
10256 * FCP iocbs associated with lun specified by tgt_id and lun_id
10258 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
10259 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10260 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
10261 * FCP iocbs associated with virtual port.
10262 * This function returns number of iocbs it failed to abort.
10263 * This function is called with no locks held.
10266 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
10267 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
10269 struct lpfc_hba
*phba
= vport
->phba
;
10270 struct lpfc_iocbq
*iocbq
;
10271 struct lpfc_iocbq
*abtsiocb
;
10272 IOCB_t
*cmd
= NULL
;
10273 int errcnt
= 0, ret_val
= 0;
10276 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
10277 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10279 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
10284 * If the iocbq is already being aborted, don't take a second
10285 * action, but do count it.
10287 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
10290 /* issue ABTS for this IOCB based on iotag */
10291 abtsiocb
= lpfc_sli_get_iocbq(phba
);
10292 if (abtsiocb
== NULL
) {
10297 /* indicate the IO is being aborted by the driver. */
10298 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10300 cmd
= &iocbq
->iocb
;
10301 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10302 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
10303 if (phba
->sli_rev
== LPFC_SLI_REV4
)
10304 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
10306 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
10307 abtsiocb
->iocb
.ulpLe
= 1;
10308 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
10309 abtsiocb
->vport
= vport
;
10311 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10312 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
10313 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
10314 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10315 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
10316 abtsiocb
->iocb_flag
|= LPFC_IO_FOF
;
10318 if (lpfc_is_link_up(phba
))
10319 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
10321 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
10323 /* Setup callback routine and issue the command. */
10324 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
10325 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10327 if (ret_val
== IOCB_ERROR
) {
10328 lpfc_sli_release_iocbq(phba
, abtsiocb
);
10338 * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
10339 * @vport: Pointer to virtual port.
10340 * @pring: Pointer to driver SLI ring object.
10341 * @tgt_id: SCSI ID of the target.
10342 * @lun_id: LUN ID of the scsi device.
10343 * @taskmgmt_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
10345 * This function sends an abort command for every SCSI command
10346 * associated with the given virtual port pending on the ring
10347 * filtered by lpfc_sli_validate_fcp_iocb function.
10348 * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
10349 * FCP iocbs associated with lun specified by tgt_id and lun_id
10351 * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
10352 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
10353 * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
10354 * FCP iocbs associated with virtual port.
10355 * This function returns number of iocbs it aborted .
10356 * This function is called with no locks held right after a taskmgmt
10360 lpfc_sli_abort_taskmgmt(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
10361 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd cmd
)
10363 struct lpfc_hba
*phba
= vport
->phba
;
10364 struct lpfc_scsi_buf
*lpfc_cmd
;
10365 struct lpfc_iocbq
*abtsiocbq
;
10366 struct lpfc_nodelist
*ndlp
;
10367 struct lpfc_iocbq
*iocbq
;
10369 int sum
, i
, ret_val
;
10370 unsigned long iflags
;
10371 struct lpfc_sli_ring
*pring_s4
;
10372 uint32_t ring_number
;
10374 spin_lock_irq(&phba
->hbalock
);
10376 /* all I/Os are in process of being flushed */
10377 if (phba
->hba_flag
& HBA_FCP_IOQ_FLUSH
) {
10378 spin_unlock_irq(&phba
->hbalock
);
10383 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
10384 iocbq
= phba
->sli
.iocbq_lookup
[i
];
10386 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
10391 * If the iocbq is already being aborted, don't take a second
10392 * action, but do count it.
10394 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
10397 /* issue ABTS for this IOCB based on iotag */
10398 abtsiocbq
= __lpfc_sli_get_iocbq(phba
);
10399 if (abtsiocbq
== NULL
)
10402 icmd
= &iocbq
->iocb
;
10403 abtsiocbq
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
10404 abtsiocbq
->iocb
.un
.acxri
.abortContextTag
= icmd
->ulpContext
;
10405 if (phba
->sli_rev
== LPFC_SLI_REV4
)
10406 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
=
10407 iocbq
->sli4_xritag
;
10409 abtsiocbq
->iocb
.un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
10410 abtsiocbq
->iocb
.ulpLe
= 1;
10411 abtsiocbq
->iocb
.ulpClass
= icmd
->ulpClass
;
10412 abtsiocbq
->vport
= vport
;
10414 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
10415 abtsiocbq
->fcp_wqidx
= iocbq
->fcp_wqidx
;
10416 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
10417 abtsiocbq
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
10418 if (iocbq
->iocb_flag
& LPFC_IO_FOF
)
10419 abtsiocbq
->iocb_flag
|= LPFC_IO_FOF
;
10421 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
10422 ndlp
= lpfc_cmd
->rdata
->pnode
;
10424 if (lpfc_is_link_up(phba
) &&
10425 (ndlp
&& ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
10426 abtsiocbq
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
10428 abtsiocbq
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
10430 /* Setup callback routine and issue the command. */
10431 abtsiocbq
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
10434 * Indicate the IO is being aborted by the driver and set
10435 * the caller's flag into the aborted IO.
10437 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
10439 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
10440 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+
10442 pring_s4
= &phba
->sli
.ring
[ring_number
];
10443 /* Note: both hbalock and ring_lock must be set here */
10444 spin_lock_irqsave(&pring_s4
->ring_lock
, iflags
);
10445 ret_val
= __lpfc_sli_issue_iocb(phba
, pring_s4
->ringno
,
10447 spin_unlock_irqrestore(&pring_s4
->ring_lock
, iflags
);
10449 ret_val
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10454 if (ret_val
== IOCB_ERROR
)
10455 __lpfc_sli_release_iocbq(phba
, abtsiocbq
);
10459 spin_unlock_irq(&phba
->hbalock
);
10464 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
10465 * @phba: Pointer to HBA context object.
10466 * @cmdiocbq: Pointer to command iocb.
10467 * @rspiocbq: Pointer to response iocb.
10469 * This function is the completion handler for iocbs issued using
10470 * lpfc_sli_issue_iocb_wait function. This function is called by the
10471 * ring event handler function without any lock held. This function
10472 * can be called from both worker thread context and interrupt
10473 * context. This function also can be called from other thread which
10474 * cleans up the SLI layer objects.
10475 * This function copy the contents of the response iocb to the
10476 * response iocb memory object provided by the caller of
10477 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
10478 * sleeps for the iocb completion.
10481 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
10482 struct lpfc_iocbq
*cmdiocbq
,
10483 struct lpfc_iocbq
*rspiocbq
)
10485 wait_queue_head_t
*pdone_q
;
10486 unsigned long iflags
;
10487 struct lpfc_scsi_buf
*lpfc_cmd
;
10489 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10490 if (cmdiocbq
->iocb_flag
& LPFC_IO_WAKE_TMO
) {
10493 * A time out has occurred for the iocb. If a time out
10494 * completion handler has been supplied, call it. Otherwise,
10495 * just free the iocbq.
10498 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10499 cmdiocbq
->iocb_cmpl
= cmdiocbq
->wait_iocb_cmpl
;
10500 cmdiocbq
->wait_iocb_cmpl
= NULL
;
10501 if (cmdiocbq
->iocb_cmpl
)
10502 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, NULL
);
10504 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
10508 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
10509 if (cmdiocbq
->context2
&& rspiocbq
)
10510 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
10511 &rspiocbq
->iocb
, sizeof(IOCB_t
));
10513 /* Set the exchange busy flag for task management commands */
10514 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
10515 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
10516 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
10518 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
10521 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
10524 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10529 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
10530 * @phba: Pointer to HBA context object..
10531 * @piocbq: Pointer to command iocb.
10532 * @flag: Flag to test.
10534 * This routine grabs the hbalock and then test the iocb_flag to
10535 * see if the passed in flag is set.
10537 * 1 if flag is set.
10538 * 0 if flag is not set.
10541 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
10542 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
10544 unsigned long iflags
;
10547 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10548 ret
= piocbq
->iocb_flag
& flag
;
10549 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10555 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
10556 * @phba: Pointer to HBA context object..
10557 * @pring: Pointer to sli ring.
10558 * @piocb: Pointer to command iocb.
10559 * @prspiocbq: Pointer to response iocb.
10560 * @timeout: Timeout in number of seconds.
10562 * This function issues the iocb to firmware and waits for the
10563 * iocb to complete. The iocb_cmpl field of the shall be used
10564 * to handle iocbs which time out. If the field is NULL, the
10565 * function shall free the iocbq structure. If more clean up is
10566 * needed, the caller is expected to provide a completion function
10567 * that will provide the needed clean up. If the iocb command is
10568 * not completed within timeout seconds, the function will either
10569 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
10570 * completion function set in the iocb_cmpl field and then return
10571 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
10572 * resources if this function returns IOCB_TIMEDOUT.
10573 * The function waits for the iocb completion using an
10574 * non-interruptible wait.
10575 * This function will sleep while waiting for iocb completion.
10576 * So, this function should not be called from any context which
10577 * does not allow sleeping. Due to the same reason, this function
10578 * cannot be called with interrupt disabled.
10579 * This function assumes that the iocb completions occur while
10580 * this function sleep. So, this function cannot be called from
10581 * the thread which process iocb completion for this ring.
10582 * This function clears the iocb_flag of the iocb object before
10583 * issuing the iocb and the iocb completion handler sets this
10584 * flag and wakes this thread when the iocb completes.
10585 * The contents of the response iocb will be copied to prspiocbq
10586 * by the completion handler when the command completes.
10587 * This function returns IOCB_SUCCESS when success.
10588 * This function is called with no lock held.
10591 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
10592 uint32_t ring_number
,
10593 struct lpfc_iocbq
*piocb
,
10594 struct lpfc_iocbq
*prspiocbq
,
10597 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10598 long timeleft
, timeout_req
= 0;
10599 int retval
= IOCB_SUCCESS
;
10601 struct lpfc_iocbq
*iocb
;
10603 int txcmplq_cnt
= 0;
10604 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10605 unsigned long iflags
;
10606 bool iocb_completed
= true;
10609 * If the caller has provided a response iocbq buffer, then context2
10610 * is NULL or its an error.
10613 if (piocb
->context2
)
10615 piocb
->context2
= prspiocbq
;
10618 piocb
->wait_iocb_cmpl
= piocb
->iocb_cmpl
;
10619 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
10620 piocb
->context_un
.wait_queue
= &done_q
;
10621 piocb
->iocb_flag
&= ~(LPFC_IO_WAKE
| LPFC_IO_WAKE_TMO
);
10623 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10624 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10626 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
10627 writel(creg_val
, phba
->HCregaddr
);
10628 readl(phba
->HCregaddr
); /* flush */
10631 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
10632 SLI_IOCB_RET_IOCB
);
10633 if (retval
== IOCB_SUCCESS
) {
10634 timeout_req
= msecs_to_jiffies(timeout
* 1000);
10635 timeleft
= wait_event_timeout(done_q
,
10636 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
10638 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10639 if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
10642 * IOCB timed out. Inform the wake iocb wait
10643 * completion function and set local status
10646 iocb_completed
= false;
10647 piocb
->iocb_flag
|= LPFC_IO_WAKE_TMO
;
10649 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10650 if (iocb_completed
) {
10651 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10652 "0331 IOCB wake signaled\n");
10653 /* Note: we are not indicating if the IOCB has a success
10654 * status or not - that's for the caller to check.
10655 * IOCB_SUCCESS means just that the command was sent and
10656 * completed. Not that it completed successfully.
10658 } else if (timeleft
== 0) {
10659 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10660 "0338 IOCB wait timeout error - no "
10661 "wake response Data x%x\n", timeout
);
10662 retval
= IOCB_TIMEDOUT
;
10664 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10665 "0330 IOCB wake NOT set, "
10667 timeout
, (timeleft
/ jiffies
));
10668 retval
= IOCB_TIMEDOUT
;
10670 } else if (retval
== IOCB_BUSY
) {
10671 if (phba
->cfg_log_verbose
& LOG_SLI
) {
10672 list_for_each_entry(iocb
, &pring
->txq
, list
) {
10675 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
10678 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10679 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
10680 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
10684 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10685 "0332 IOCB wait issue failed, Data x%x\n",
10687 retval
= IOCB_ERROR
;
10690 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10691 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10693 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
10694 writel(creg_val
, phba
->HCregaddr
);
10695 readl(phba
->HCregaddr
); /* flush */
10699 piocb
->context2
= NULL
;
10701 piocb
->context_un
.wait_queue
= NULL
;
10702 piocb
->iocb_cmpl
= NULL
;
10707 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
10708 * @phba: Pointer to HBA context object.
10709 * @pmboxq: Pointer to driver mailbox object.
10710 * @timeout: Timeout in number of seconds.
10712 * This function issues the mailbox to firmware and waits for the
10713 * mailbox command to complete. If the mailbox command is not
10714 * completed within timeout seconds, it returns MBX_TIMEOUT.
10715 * The function waits for the mailbox completion using an
10716 * interruptible wait. If the thread is woken up due to a
10717 * signal, MBX_TIMEOUT error is returned to the caller. Caller
10718 * should not free the mailbox resources, if this function returns
10720 * This function will sleep while waiting for mailbox completion.
10721 * So, this function should not be called from any context which
10722 * does not allow sleeping. Due to the same reason, this function
10723 * cannot be called with interrupt disabled.
10724 * This function assumes that the mailbox completion occurs while
10725 * this function sleep. So, this function cannot be called from
10726 * the worker thread which processes mailbox completion.
10727 * This function is called in the context of HBA management
10729 * This function returns MBX_SUCCESS when successful.
10730 * This function is called with no lock held.
10733 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
10736 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10737 MAILBOX_t
*mb
= NULL
;
10739 unsigned long flag
;
10741 /* The caller might set context1 for extended buffer */
10742 if (pmboxq
->context1
)
10743 mb
= (MAILBOX_t
*)pmboxq
->context1
;
10745 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
10746 /* setup wake call as IOCB callback */
10747 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
10748 /* setup context field to pass wait_queue pointer to wake function */
10749 pmboxq
->context1
= &done_q
;
10751 /* now issue the command */
10752 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
10753 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
10754 wait_event_interruptible_timeout(done_q
,
10755 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
10756 msecs_to_jiffies(timeout
* 1000));
10758 spin_lock_irqsave(&phba
->hbalock
, flag
);
10759 /* restore the possible extended buffer for free resource */
10760 pmboxq
->context1
= (uint8_t *)mb
;
10762 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10763 * else do not free the resources.
10765 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
10766 retval
= MBX_SUCCESS
;
10768 retval
= MBX_TIMEOUT
;
10769 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10771 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
10773 /* restore the possible extended buffer for free resource */
10774 pmboxq
->context1
= (uint8_t *)mb
;
10781 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10782 * @phba: Pointer to HBA context.
10784 * This function is called to shutdown the driver's mailbox sub-system.
10785 * It first marks the mailbox sub-system is in a block state to prevent
10786 * the asynchronous mailbox command from issued off the pending mailbox
10787 * command queue. If the mailbox command sub-system shutdown is due to
10788 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10789 * the mailbox sub-system flush routine to forcefully bring down the
10790 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10791 * as with offline or HBA function reset), this routine will wait for the
10792 * outstanding mailbox command to complete before invoking the mailbox
10793 * sub-system flush routine to gracefully bring down mailbox sub-system.
10796 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
10798 struct lpfc_sli
*psli
= &phba
->sli
;
10799 unsigned long timeout
;
10801 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
10802 /* delay 100ms for port state */
10804 lpfc_sli_mbox_sys_flush(phba
);
10807 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
10809 spin_lock_irq(&phba
->hbalock
);
10810 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10812 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
10813 /* Determine how long we might wait for the active mailbox
10814 * command to be gracefully completed by firmware.
10816 if (phba
->sli
.mbox_active
)
10817 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
10818 phba
->sli
.mbox_active
) *
10820 spin_unlock_irq(&phba
->hbalock
);
10822 while (phba
->sli
.mbox_active
) {
10823 /* Check active mailbox complete status every 2ms */
10825 if (time_after(jiffies
, timeout
))
10826 /* Timeout, let the mailbox flush routine to
10827 * forcefully release active mailbox command
10832 spin_unlock_irq(&phba
->hbalock
);
10834 lpfc_sli_mbox_sys_flush(phba
);
10838 * lpfc_sli_eratt_read - read sli-3 error attention events
10839 * @phba: Pointer to HBA context.
10841 * This function is called to read the SLI3 device error attention registers
10842 * for possible error attention events. The caller must hold the hostlock
10843 * with spin_lock_irq().
10845 * This function returns 1 when there is Error Attention in the Host Attention
10846 * Register and returns 0 otherwise.
10849 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10853 /* Read chip Host Attention (HA) register */
10854 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10857 if (ha_copy
& HA_ERATT
) {
10858 /* Read host status register to retrieve error event */
10859 if (lpfc_sli_read_hs(phba
))
10862 /* Check if there is a deferred error condition is active */
10863 if ((HS_FFER1
& phba
->work_hs
) &&
10864 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10865 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10866 phba
->hba_flag
|= DEFER_ERATT
;
10867 /* Clear all interrupt enable conditions */
10868 writel(0, phba
->HCregaddr
);
10869 readl(phba
->HCregaddr
);
10872 /* Set the driver HA work bitmap */
10873 phba
->work_ha
|= HA_ERATT
;
10874 /* Indicate polling handles this ERATT */
10875 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10881 /* Set the driver HS work bitmap */
10882 phba
->work_hs
|= UNPLUG_ERR
;
10883 /* Set the driver HA work bitmap */
10884 phba
->work_ha
|= HA_ERATT
;
10885 /* Indicate polling handles this ERATT */
10886 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10891 * lpfc_sli4_eratt_read - read sli-4 error attention events
10892 * @phba: Pointer to HBA context.
10894 * This function is called to read the SLI4 device error attention registers
10895 * for possible error attention events. The caller must hold the hostlock
10896 * with spin_lock_irq().
10898 * This function returns 1 when there is Error Attention in the Host Attention
10899 * Register and returns 0 otherwise.
10902 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10904 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10905 uint32_t if_type
, portsmphr
;
10906 struct lpfc_register portstat_reg
;
10909 * For now, use the SLI4 device internal unrecoverable error
10910 * registers for error attention. This can be changed later.
10912 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10914 case LPFC_SLI_INTF_IF_TYPE_0
:
10915 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10917 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10919 phba
->work_hs
|= UNPLUG_ERR
;
10920 phba
->work_ha
|= HA_ERATT
;
10921 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10924 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10925 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10926 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10927 "1423 HBA Unrecoverable error: "
10928 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10929 "ue_mask_lo_reg=0x%x, "
10930 "ue_mask_hi_reg=0x%x\n",
10931 uerr_sta_lo
, uerr_sta_hi
,
10932 phba
->sli4_hba
.ue_mask_lo
,
10933 phba
->sli4_hba
.ue_mask_hi
);
10934 phba
->work_status
[0] = uerr_sta_lo
;
10935 phba
->work_status
[1] = uerr_sta_hi
;
10936 phba
->work_ha
|= HA_ERATT
;
10937 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10941 case LPFC_SLI_INTF_IF_TYPE_2
:
10942 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10943 &portstat_reg
.word0
) ||
10944 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10946 phba
->work_hs
|= UNPLUG_ERR
;
10947 phba
->work_ha
|= HA_ERATT
;
10948 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10951 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10952 phba
->work_status
[0] =
10953 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10954 phba
->work_status
[1] =
10955 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10956 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10957 "2885 Port Status Event: "
10958 "port status reg 0x%x, "
10959 "port smphr reg 0x%x, "
10960 "error 1=0x%x, error 2=0x%x\n",
10961 portstat_reg
.word0
,
10963 phba
->work_status
[0],
10964 phba
->work_status
[1]);
10965 phba
->work_ha
|= HA_ERATT
;
10966 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10970 case LPFC_SLI_INTF_IF_TYPE_1
:
10972 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10973 "2886 HBA Error Attention on unsupported "
10974 "if type %d.", if_type
);
10982 * lpfc_sli_check_eratt - check error attention events
10983 * @phba: Pointer to HBA context.
10985 * This function is called from timer soft interrupt context to check HBA's
10986 * error attention register bit for error attention events.
10988 * This function returns 1 when there is Error Attention in the Host Attention
10989 * Register and returns 0 otherwise.
10992 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10996 /* If somebody is waiting to handle an eratt, don't process it
10997 * here. The brdkill function will do this.
10999 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11002 /* Check if interrupt handler handles this ERATT */
11003 spin_lock_irq(&phba
->hbalock
);
11004 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
11005 /* Interrupt handler has handled ERATT */
11006 spin_unlock_irq(&phba
->hbalock
);
11011 * If there is deferred error attention, do not check for error
11014 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11015 spin_unlock_irq(&phba
->hbalock
);
11019 /* If PCI channel is offline, don't process it */
11020 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
11021 spin_unlock_irq(&phba
->hbalock
);
11025 switch (phba
->sli_rev
) {
11026 case LPFC_SLI_REV2
:
11027 case LPFC_SLI_REV3
:
11028 /* Read chip Host Attention (HA) register */
11029 ha_copy
= lpfc_sli_eratt_read(phba
);
11031 case LPFC_SLI_REV4
:
11032 /* Read device Uncoverable Error (UERR) registers */
11033 ha_copy
= lpfc_sli4_eratt_read(phba
);
11036 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
11037 "0299 Invalid SLI revision (%d)\n",
11042 spin_unlock_irq(&phba
->hbalock
);
11048 * lpfc_intr_state_check - Check device state for interrupt handling
11049 * @phba: Pointer to HBA context.
11051 * This inline routine checks whether a device or its PCI slot is in a state
11052 * that the interrupt should be handled.
11054 * This function returns 0 if the device or the PCI slot is in a state that
11055 * interrupt should be handled, otherwise -EIO.
11058 lpfc_intr_state_check(struct lpfc_hba
*phba
)
11060 /* If the pci channel is offline, ignore all the interrupts */
11061 if (unlikely(pci_channel_offline(phba
->pcidev
)))
11064 /* Update device level interrupt statistics */
11065 phba
->sli
.slistat
.sli_intr
++;
11067 /* Ignore all interrupts during initialization. */
11068 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
11075 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
11076 * @irq: Interrupt number.
11077 * @dev_id: The device context pointer.
11079 * This function is directly called from the PCI layer as an interrupt
11080 * service routine when device with SLI-3 interface spec is enabled with
11081 * MSI-X multi-message interrupt mode and there are slow-path events in
11082 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
11083 * interrupt mode, this function is called as part of the device-level
11084 * interrupt handler. When the PCI slot is in error recovery or the HBA
11085 * is undergoing initialization, the interrupt handler will not process
11086 * the interrupt. The link attention and ELS ring attention events are
11087 * handled by the worker thread. The interrupt handler signals the worker
11088 * thread and returns for these events. This function is called without
11089 * any lock held. It gets the hbalock to access and update SLI data
11092 * This function returns IRQ_HANDLED when interrupt is handled else it
11093 * returns IRQ_NONE.
11096 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
11098 struct lpfc_hba
*phba
;
11099 uint32_t ha_copy
, hc_copy
;
11100 uint32_t work_ha_copy
;
11101 unsigned long status
;
11102 unsigned long iflag
;
11105 MAILBOX_t
*mbox
, *pmbox
;
11106 struct lpfc_vport
*vport
;
11107 struct lpfc_nodelist
*ndlp
;
11108 struct lpfc_dmabuf
*mp
;
11113 * Get the driver's phba structure from the dev_id and
11114 * assume the HBA is not interrupting.
11116 phba
= (struct lpfc_hba
*)dev_id
;
11118 if (unlikely(!phba
))
11122 * Stuff needs to be attented to when this function is invoked as an
11123 * individual interrupt handler in MSI-X multi-message interrupt mode
11125 if (phba
->intr_type
== MSIX
) {
11126 /* Check device state for handling interrupt */
11127 if (lpfc_intr_state_check(phba
))
11129 /* Need to read HA REG for slow-path events */
11130 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11131 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11133 /* If somebody is waiting to handle an eratt don't process it
11134 * here. The brdkill function will do this.
11136 if (phba
->link_flag
& LS_IGNORE_ERATT
)
11137 ha_copy
&= ~HA_ERATT
;
11138 /* Check the need for handling ERATT in interrupt handler */
11139 if (ha_copy
& HA_ERATT
) {
11140 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11141 /* ERATT polling has handled ERATT */
11142 ha_copy
&= ~HA_ERATT
;
11144 /* Indicate interrupt handler handles ERATT */
11145 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11149 * If there is deferred error attention, do not check for any
11152 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11153 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11157 /* Clear up only attention source related to slow-path */
11158 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
11161 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
11162 HC_LAINT_ENA
| HC_ERINT_ENA
),
11164 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
11166 writel(hc_copy
, phba
->HCregaddr
);
11167 readl(phba
->HAregaddr
); /* flush */
11168 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11170 ha_copy
= phba
->ha_copy
;
11172 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
11174 if (work_ha_copy
) {
11175 if (work_ha_copy
& HA_LATT
) {
11176 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
11178 * Turn off Link Attention interrupts
11179 * until CLEAR_LA done
11181 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11182 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
11183 if (lpfc_readl(phba
->HCregaddr
, &control
))
11185 control
&= ~HC_LAINT_ENA
;
11186 writel(control
, phba
->HCregaddr
);
11187 readl(phba
->HCregaddr
); /* flush */
11188 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11191 work_ha_copy
&= ~HA_LATT
;
11194 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
11196 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
11197 * the only slow ring.
11199 status
= (work_ha_copy
&
11200 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11201 status
>>= (4*LPFC_ELS_RING
);
11202 if (status
& HA_RXMASK
) {
11203 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11204 if (lpfc_readl(phba
->HCregaddr
, &control
))
11207 lpfc_debugfs_slow_ring_trc(phba
,
11208 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
11210 (uint32_t)phba
->sli
.slistat
.sli_intr
);
11212 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
11213 lpfc_debugfs_slow_ring_trc(phba
,
11214 "ISR Disable ring:"
11215 "pwork:x%x hawork:x%x wait:x%x",
11216 phba
->work_ha
, work_ha_copy
,
11217 (uint32_t)((unsigned long)
11218 &phba
->work_waitq
));
11221 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
11222 writel(control
, phba
->HCregaddr
);
11223 readl(phba
->HCregaddr
); /* flush */
11226 lpfc_debugfs_slow_ring_trc(phba
,
11227 "ISR slow ring: pwork:"
11228 "x%x hawork:x%x wait:x%x",
11229 phba
->work_ha
, work_ha_copy
,
11230 (uint32_t)((unsigned long)
11231 &phba
->work_waitq
));
11233 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11236 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11237 if (work_ha_copy
& HA_ERATT
) {
11238 if (lpfc_sli_read_hs(phba
))
11241 * Check if there is a deferred error condition
11244 if ((HS_FFER1
& phba
->work_hs
) &&
11245 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
11246 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
11248 phba
->hba_flag
|= DEFER_ERATT
;
11249 /* Clear all interrupt enable conditions */
11250 writel(0, phba
->HCregaddr
);
11251 readl(phba
->HCregaddr
);
11255 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
11256 pmb
= phba
->sli
.mbox_active
;
11257 pmbox
= &pmb
->u
.mb
;
11259 vport
= pmb
->vport
;
11261 /* First check out the status word */
11262 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
11263 if (pmbox
->mbxOwner
!= OWN_HOST
) {
11264 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11266 * Stray Mailbox Interrupt, mbxCommand <cmd>
11267 * mbxStatus <status>
11269 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11271 "(%d):0304 Stray Mailbox "
11272 "Interrupt mbxCommand x%x "
11274 (vport
? vport
->vpi
: 0),
11277 /* clear mailbox attention bit */
11278 work_ha_copy
&= ~HA_MBATT
;
11280 phba
->sli
.mbox_active
= NULL
;
11281 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11282 phba
->last_completion_time
= jiffies
;
11283 del_timer(&phba
->sli
.mbox_tmo
);
11284 if (pmb
->mbox_cmpl
) {
11285 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
11287 if (pmb
->out_ext_byte_len
&&
11289 lpfc_sli_pcimem_bcopy(
11292 pmb
->out_ext_byte_len
);
11294 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11295 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11297 lpfc_debugfs_disc_trc(vport
,
11298 LPFC_DISC_TRC_MBOX_VPORT
,
11299 "MBOX dflt rpi: : "
11300 "status:x%x rpi:x%x",
11301 (uint32_t)pmbox
->mbxStatus
,
11302 pmbox
->un
.varWords
[0], 0);
11304 if (!pmbox
->mbxStatus
) {
11305 mp
= (struct lpfc_dmabuf
*)
11307 ndlp
= (struct lpfc_nodelist
*)
11310 /* Reg_LOGIN of dflt RPI was
11311 * successful. new lets get
11312 * rid of the RPI using the
11313 * same mbox buffer.
11315 lpfc_unreg_login(phba
,
11317 pmbox
->un
.varWords
[0],
11320 lpfc_mbx_cmpl_dflt_rpi
;
11321 pmb
->context1
= mp
;
11322 pmb
->context2
= ndlp
;
11323 pmb
->vport
= vport
;
11324 rc
= lpfc_sli_issue_mbox(phba
,
11327 if (rc
!= MBX_BUSY
)
11328 lpfc_printf_log(phba
,
11330 LOG_MBOX
| LOG_SLI
,
11331 "0350 rc should have"
11332 "been MBX_BUSY\n");
11333 if (rc
!= MBX_NOT_FINISHED
)
11334 goto send_current_mbox
;
11338 &phba
->pport
->work_port_lock
,
11340 phba
->pport
->work_port_events
&=
11342 spin_unlock_irqrestore(
11343 &phba
->pport
->work_port_lock
,
11345 lpfc_mbox_cmpl_put(phba
, pmb
);
11348 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11350 if ((work_ha_copy
& HA_MBATT
) &&
11351 (phba
->sli
.mbox_active
== NULL
)) {
11353 /* Process next mailbox command if there is one */
11355 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
11357 } while (rc
== MBX_NOT_FINISHED
);
11358 if (rc
!= MBX_SUCCESS
)
11359 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11360 LOG_SLI
, "0349 rc should be "
11364 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11365 phba
->work_ha
|= work_ha_copy
;
11366 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11367 lpfc_worker_wake_up(phba
);
11369 return IRQ_HANDLED
;
11371 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11372 return IRQ_HANDLED
;
11374 } /* lpfc_sli_sp_intr_handler */
11377 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
11378 * @irq: Interrupt number.
11379 * @dev_id: The device context pointer.
11381 * This function is directly called from the PCI layer as an interrupt
11382 * service routine when device with SLI-3 interface spec is enabled with
11383 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11384 * ring event in the HBA. However, when the device is enabled with either
11385 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11386 * device-level interrupt handler. When the PCI slot is in error recovery
11387 * or the HBA is undergoing initialization, the interrupt handler will not
11388 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11389 * the intrrupt context. This function is called without any lock held.
11390 * It gets the hbalock to access and update SLI data structures.
11392 * This function returns IRQ_HANDLED when interrupt is handled else it
11393 * returns IRQ_NONE.
11396 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
11398 struct lpfc_hba
*phba
;
11400 unsigned long status
;
11401 unsigned long iflag
;
11403 /* Get the driver's phba structure from the dev_id and
11404 * assume the HBA is not interrupting.
11406 phba
= (struct lpfc_hba
*) dev_id
;
11408 if (unlikely(!phba
))
11412 * Stuff needs to be attented to when this function is invoked as an
11413 * individual interrupt handler in MSI-X multi-message interrupt mode
11415 if (phba
->intr_type
== MSIX
) {
11416 /* Check device state for handling interrupt */
11417 if (lpfc_intr_state_check(phba
))
11419 /* Need to read HA REG for FCP ring and other ring events */
11420 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
11421 return IRQ_HANDLED
;
11422 /* Clear up only attention source related to fast-path */
11423 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11425 * If there is deferred error attention, do not check for
11428 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11429 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11432 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
11434 readl(phba
->HAregaddr
); /* flush */
11435 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11437 ha_copy
= phba
->ha_copy
;
11440 * Process all events on FCP ring. Take the optimized path for FCP IO.
11442 ha_copy
&= ~(phba
->work_ha_mask
);
11444 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
11445 status
>>= (4*LPFC_FCP_RING
);
11446 if (status
& HA_RXMASK
)
11447 lpfc_sli_handle_fast_ring_event(phba
,
11448 &phba
->sli
.ring
[LPFC_FCP_RING
],
11451 if (phba
->cfg_multi_ring_support
== 2) {
11453 * Process all events on extra ring. Take the optimized path
11454 * for extra ring IO.
11456 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
11457 status
>>= (4*LPFC_EXTRA_RING
);
11458 if (status
& HA_RXMASK
) {
11459 lpfc_sli_handle_fast_ring_event(phba
,
11460 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
11464 return IRQ_HANDLED
;
11465 } /* lpfc_sli_fp_intr_handler */
11468 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
11469 * @irq: Interrupt number.
11470 * @dev_id: The device context pointer.
11472 * This function is the HBA device-level interrupt handler to device with
11473 * SLI-3 interface spec, called from the PCI layer when either MSI or
11474 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
11475 * requires driver attention. This function invokes the slow-path interrupt
11476 * attention handling function and fast-path interrupt attention handling
11477 * function in turn to process the relevant HBA attention events. This
11478 * function is called without any lock held. It gets the hbalock to access
11479 * and update SLI data structures.
11481 * This function returns IRQ_HANDLED when interrupt is handled, else it
11482 * returns IRQ_NONE.
11485 lpfc_sli_intr_handler(int irq
, void *dev_id
)
11487 struct lpfc_hba
*phba
;
11488 irqreturn_t sp_irq_rc
, fp_irq_rc
;
11489 unsigned long status1
, status2
;
11493 * Get the driver's phba structure from the dev_id and
11494 * assume the HBA is not interrupting.
11496 phba
= (struct lpfc_hba
*) dev_id
;
11498 if (unlikely(!phba
))
11501 /* Check device state for handling interrupt */
11502 if (lpfc_intr_state_check(phba
))
11505 spin_lock(&phba
->hbalock
);
11506 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
11507 spin_unlock(&phba
->hbalock
);
11508 return IRQ_HANDLED
;
11511 if (unlikely(!phba
->ha_copy
)) {
11512 spin_unlock(&phba
->hbalock
);
11514 } else if (phba
->ha_copy
& HA_ERATT
) {
11515 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11516 /* ERATT polling has handled ERATT */
11517 phba
->ha_copy
&= ~HA_ERATT
;
11519 /* Indicate interrupt handler handles ERATT */
11520 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11524 * If there is deferred error attention, do not check for any interrupt.
11526 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11527 spin_unlock(&phba
->hbalock
);
11531 /* Clear attention sources except link and error attentions */
11532 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
11533 spin_unlock(&phba
->hbalock
);
11534 return IRQ_HANDLED
;
11536 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
11537 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
11539 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
11540 writel(hc_copy
, phba
->HCregaddr
);
11541 readl(phba
->HAregaddr
); /* flush */
11542 spin_unlock(&phba
->hbalock
);
11545 * Invokes slow-path host attention interrupt handling as appropriate.
11548 /* status of events with mailbox and link attention */
11549 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
11551 /* status of events with ELS ring */
11552 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11553 status2
>>= (4*LPFC_ELS_RING
);
11555 if (status1
|| (status2
& HA_RXMASK
))
11556 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
11558 sp_irq_rc
= IRQ_NONE
;
11561 * Invoke fast-path host attention interrupt handling as appropriate.
11564 /* status of events with FCP ring */
11565 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
11566 status1
>>= (4*LPFC_FCP_RING
);
11568 /* status of events with extra ring */
11569 if (phba
->cfg_multi_ring_support
== 2) {
11570 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
11571 status2
>>= (4*LPFC_EXTRA_RING
);
11575 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
11576 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
11578 fp_irq_rc
= IRQ_NONE
;
11580 /* Return device-level interrupt handling status */
11581 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
11582 } /* lpfc_sli_intr_handler */
11585 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
11586 * @phba: pointer to lpfc hba data structure.
11588 * This routine is invoked by the worker thread to process all the pending
11589 * SLI4 FCP abort XRI events.
11591 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
11593 struct lpfc_cq_event
*cq_event
;
11595 /* First, declare the fcp xri abort event has been handled */
11596 spin_lock_irq(&phba
->hbalock
);
11597 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
11598 spin_unlock_irq(&phba
->hbalock
);
11599 /* Now, handle all the fcp xri abort events */
11600 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
11601 /* Get the first event from the head of the event queue */
11602 spin_lock_irq(&phba
->hbalock
);
11603 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
11604 cq_event
, struct lpfc_cq_event
, list
);
11605 spin_unlock_irq(&phba
->hbalock
);
11606 /* Notify aborted XRI for FCP work queue */
11607 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
11608 /* Free the event processed back to the free pool */
11609 lpfc_sli4_cq_event_release(phba
, cq_event
);
11614 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
11615 * @phba: pointer to lpfc hba data structure.
11617 * This routine is invoked by the worker thread to process all the pending
11618 * SLI4 els abort xri events.
11620 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
11622 struct lpfc_cq_event
*cq_event
;
11624 /* First, declare the els xri abort event has been handled */
11625 spin_lock_irq(&phba
->hbalock
);
11626 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
11627 spin_unlock_irq(&phba
->hbalock
);
11628 /* Now, handle all the els xri abort events */
11629 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
11630 /* Get the first event from the head of the event queue */
11631 spin_lock_irq(&phba
->hbalock
);
11632 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
11633 cq_event
, struct lpfc_cq_event
, list
);
11634 spin_unlock_irq(&phba
->hbalock
);
11635 /* Notify aborted XRI for ELS work queue */
11636 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
11637 /* Free the event processed back to the free pool */
11638 lpfc_sli4_cq_event_release(phba
, cq_event
);
11643 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
11644 * @phba: pointer to lpfc hba data structure
11645 * @pIocbIn: pointer to the rspiocbq
11646 * @pIocbOut: pointer to the cmdiocbq
11647 * @wcqe: pointer to the complete wcqe
11649 * This routine transfers the fields of a command iocbq to a response iocbq
11650 * by copying all the IOCB fields from command iocbq and transferring the
11651 * completion status information from the complete wcqe.
11654 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
11655 struct lpfc_iocbq
*pIocbIn
,
11656 struct lpfc_iocbq
*pIocbOut
,
11657 struct lpfc_wcqe_complete
*wcqe
)
11660 unsigned long iflags
;
11661 uint32_t status
, max_response
;
11662 struct lpfc_dmabuf
*dmabuf
;
11663 struct ulp_bde64
*bpl
, bde
;
11664 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
11666 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
11667 sizeof(struct lpfc_iocbq
) - offset
);
11668 /* Map WCQE parameters into irspiocb parameters */
11669 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
11670 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
11671 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
11672 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
11673 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
11674 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
11675 wcqe
->total_data_placed
;
11677 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11679 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11680 switch (pIocbOut
->iocb
.ulpCommand
) {
11681 case CMD_ELS_REQUEST64_CR
:
11682 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
11683 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
11684 bde
.tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
11685 max_response
= bde
.tus
.f
.bdeSize
;
11687 case CMD_GEN_REQUEST64_CR
:
11689 if (!pIocbOut
->context3
)
11691 numBdes
= pIocbOut
->iocb
.un
.genreq64
.bdl
.bdeSize
/
11692 sizeof(struct ulp_bde64
);
11693 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
11694 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
11695 for (i
= 0; i
< numBdes
; i
++) {
11696 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
11697 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
11698 max_response
+= bde
.tus
.f
.bdeSize
;
11702 max_response
= wcqe
->total_data_placed
;
11705 if (max_response
< wcqe
->total_data_placed
)
11706 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= max_response
;
11708 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
=
11709 wcqe
->total_data_placed
;
11712 /* Convert BG errors for completion status */
11713 if (status
== CQE_STATUS_DI_ERROR
) {
11714 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
11716 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
11717 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
11719 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
11721 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
11722 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
11723 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11724 BGS_GUARD_ERR_MASK
;
11725 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
11726 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11727 BGS_APPTAG_ERR_MASK
;
11728 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
11729 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11730 BGS_REFTAG_ERR_MASK
;
11732 /* Check to see if there was any good data before the error */
11733 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
11734 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11735 BGS_HI_WATER_MARK_PRESENT_MASK
;
11736 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
11737 wcqe
->total_data_placed
;
11741 * Set ALL the error bits to indicate we don't know what
11742 * type of error it is.
11744 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
11745 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11746 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
11747 BGS_GUARD_ERR_MASK
);
11750 /* Pick up HBA exchange busy condition */
11751 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
11752 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11753 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
11754 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11759 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11760 * @phba: Pointer to HBA context object.
11761 * @wcqe: Pointer to work-queue completion queue entry.
11763 * This routine handles an ELS work-queue completion event and construct
11764 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11765 * discovery engine to handle.
11767 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11769 static struct lpfc_iocbq
*
11770 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
11771 struct lpfc_iocbq
*irspiocbq
)
11773 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
11774 struct lpfc_iocbq
*cmdiocbq
;
11775 struct lpfc_wcqe_complete
*wcqe
;
11776 unsigned long iflags
;
11778 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
11779 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11780 pring
->stats
.iocb_event
++;
11781 /* Look up the ELS command IOCB and create pseudo response IOCB */
11782 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11783 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11784 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11786 if (unlikely(!cmdiocbq
)) {
11787 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11788 "0386 ELS complete with no corresponding "
11789 "cmdiocb: iotag (%d)\n",
11790 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11791 lpfc_sli_release_iocbq(phba
, irspiocbq
);
11795 /* Fake the irspiocbq and copy necessary response information */
11796 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
11802 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11803 * @phba: Pointer to HBA context object.
11804 * @cqe: Pointer to mailbox completion queue entry.
11806 * This routine process a mailbox completion queue entry with asynchrous
11809 * Return: true if work posted to worker thread, otherwise false.
11812 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11814 struct lpfc_cq_event
*cq_event
;
11815 unsigned long iflags
;
11817 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11818 "0392 Async Event: word0:x%x, word1:x%x, "
11819 "word2:x%x, word3:x%x\n", mcqe
->word0
,
11820 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
11822 /* Allocate a new internal CQ_EVENT entry */
11823 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11825 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11826 "0394 Failed to allocate CQ_EVENT entry\n");
11830 /* Move the CQE into an asynchronous event entry */
11831 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
11832 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11833 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
11834 /* Set the async event flag */
11835 phba
->hba_flag
|= ASYNC_EVENT
;
11836 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11842 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11843 * @phba: Pointer to HBA context object.
11844 * @cqe: Pointer to mailbox completion queue entry.
11846 * This routine process a mailbox completion queue entry with mailbox
11847 * completion event.
11849 * Return: true if work posted to worker thread, otherwise false.
11852 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11854 uint32_t mcqe_status
;
11855 MAILBOX_t
*mbox
, *pmbox
;
11856 struct lpfc_mqe
*mqe
;
11857 struct lpfc_vport
*vport
;
11858 struct lpfc_nodelist
*ndlp
;
11859 struct lpfc_dmabuf
*mp
;
11860 unsigned long iflags
;
11862 bool workposted
= false;
11865 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11866 if (!bf_get(lpfc_trailer_completed
, mcqe
))
11867 goto out_no_mqe_complete
;
11869 /* Get the reference to the active mbox command */
11870 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11871 pmb
= phba
->sli
.mbox_active
;
11872 if (unlikely(!pmb
)) {
11873 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11874 "1832 No pending MBOX command to handle\n");
11875 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11876 goto out_no_mqe_complete
;
11878 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11880 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11882 vport
= pmb
->vport
;
11884 /* Reset heartbeat timer */
11885 phba
->last_completion_time
= jiffies
;
11886 del_timer(&phba
->sli
.mbox_tmo
);
11888 /* Move mbox data to caller's mailbox region, do endian swapping */
11889 if (pmb
->mbox_cmpl
&& mbox
)
11890 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11893 * For mcqe errors, conditionally move a modified error code to
11894 * the mbox so that the error will not be missed.
11896 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11897 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11898 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11899 bf_set(lpfc_mqe_status
, mqe
,
11900 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11902 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11903 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11904 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11905 "MBOX dflt rpi: status:x%x rpi:x%x",
11907 pmbox
->un
.varWords
[0], 0);
11908 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11909 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11910 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11911 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11912 * RID of the PPI using the same mbox buffer.
11914 lpfc_unreg_login(phba
, vport
->vpi
,
11915 pmbox
->un
.varWords
[0], pmb
);
11916 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11917 pmb
->context1
= mp
;
11918 pmb
->context2
= ndlp
;
11919 pmb
->vport
= vport
;
11920 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11921 if (rc
!= MBX_BUSY
)
11922 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11923 LOG_SLI
, "0385 rc should "
11924 "have been MBX_BUSY\n");
11925 if (rc
!= MBX_NOT_FINISHED
)
11926 goto send_current_mbox
;
11929 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11930 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11931 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11933 /* There is mailbox completion work to do */
11934 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11935 __lpfc_mbox_cmpl_put(phba
, pmb
);
11936 phba
->work_ha
|= HA_MBATT
;
11937 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11941 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11942 /* Release the mailbox command posting token */
11943 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11944 /* Setting active mailbox pointer need to be in sync to flag clear */
11945 phba
->sli
.mbox_active
= NULL
;
11946 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11947 /* Wake up worker thread to post the next pending mailbox command */
11948 lpfc_worker_wake_up(phba
);
11949 out_no_mqe_complete
:
11950 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11951 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
11956 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11957 * @phba: Pointer to HBA context object.
11958 * @cqe: Pointer to mailbox completion queue entry.
11960 * This routine process a mailbox completion queue entry, it invokes the
11961 * proper mailbox complete handling or asynchrous event handling routine
11962 * according to the MCQE's async bit.
11964 * Return: true if work posted to worker thread, otherwise false.
11967 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
11969 struct lpfc_mcqe mcqe
;
11972 /* Copy the mailbox MCQE and convert endian order as needed */
11973 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
11975 /* Invoke the proper event handling routine */
11976 if (!bf_get(lpfc_trailer_async
, &mcqe
))
11977 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
11979 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
11984 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11985 * @phba: Pointer to HBA context object.
11986 * @cq: Pointer to associated CQ
11987 * @wcqe: Pointer to work-queue completion queue entry.
11989 * This routine handles an ELS work-queue completion event.
11991 * Return: true if work posted to worker thread, otherwise false.
11994 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11995 struct lpfc_wcqe_complete
*wcqe
)
11997 struct lpfc_iocbq
*irspiocbq
;
11998 unsigned long iflags
;
11999 struct lpfc_sli_ring
*pring
= cq
->pring
;
12001 int txcmplq_cnt
= 0;
12002 int fcp_txcmplq_cnt
= 0;
12004 /* Get an irspiocbq for later ELS response processing use */
12005 irspiocbq
= lpfc_sli_get_iocbq(phba
);
12007 if (!list_empty(&pring
->txq
))
12009 if (!list_empty(&pring
->txcmplq
))
12011 if (!list_empty(&phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq
))
12013 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12014 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
12015 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
12016 txq_cnt
, phba
->iocb_cnt
,
12022 /* Save off the slow-path queue event for work thread to process */
12023 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
12024 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12025 list_add_tail(&irspiocbq
->cq_event
.list
,
12026 &phba
->sli4_hba
.sp_queue_event
);
12027 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12028 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12034 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
12035 * @phba: Pointer to HBA context object.
12036 * @wcqe: Pointer to work-queue completion queue entry.
12038 * This routine handles slow-path WQ entry comsumed event by invoking the
12039 * proper WQ release routine to the slow-path WQ.
12042 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
12043 struct lpfc_wcqe_release
*wcqe
)
12045 /* sanity check on queue memory */
12046 if (unlikely(!phba
->sli4_hba
.els_wq
))
12048 /* Check for the slow-path ELS work queue */
12049 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
12050 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
12051 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
12053 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12054 "2579 Slow-path wqe consume event carries "
12055 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
12056 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
12057 phba
->sli4_hba
.els_wq
->queue_id
);
12061 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
12062 * @phba: Pointer to HBA context object.
12063 * @cq: Pointer to a WQ completion queue.
12064 * @wcqe: Pointer to work-queue completion queue entry.
12066 * This routine handles an XRI abort event.
12068 * Return: true if work posted to worker thread, otherwise false.
12071 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
12072 struct lpfc_queue
*cq
,
12073 struct sli4_wcqe_xri_aborted
*wcqe
)
12075 bool workposted
= false;
12076 struct lpfc_cq_event
*cq_event
;
12077 unsigned long iflags
;
12079 /* Allocate a new internal CQ_EVENT entry */
12080 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
12082 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12083 "0602 Failed to allocate CQ_EVENT entry\n");
12087 /* Move the CQE into the proper xri abort event list */
12088 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
12089 switch (cq
->subtype
) {
12091 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12092 list_add_tail(&cq_event
->list
,
12093 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
12094 /* Set the fcp xri abort event flag */
12095 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
12096 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12100 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12101 list_add_tail(&cq_event
->list
,
12102 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
12103 /* Set the els xri abort event flag */
12104 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
12105 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12109 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12110 "0603 Invalid work queue CQE subtype (x%x)\n",
12112 workposted
= false;
12119 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
12120 * @phba: Pointer to HBA context object.
12121 * @rcqe: Pointer to receive-queue completion queue entry.
12123 * This routine process a receive-queue completion queue entry.
12125 * Return: true if work posted to worker thread, otherwise false.
12128 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
12130 bool workposted
= false;
12131 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
12132 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
12133 struct hbq_dmabuf
*dma_buf
;
12134 uint32_t status
, rq_id
;
12135 unsigned long iflags
;
12137 /* sanity check on queue memory */
12138 if (unlikely(!hrq
) || unlikely(!drq
))
12141 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
12142 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
12144 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
12145 if (rq_id
!= hrq
->queue_id
)
12148 status
= bf_get(lpfc_rcqe_status
, rcqe
);
12150 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
12151 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12152 "2537 Receive Frame Truncated!!\n");
12153 hrq
->RQ_buf_trunc
++;
12154 case FC_STATUS_RQ_SUCCESS
:
12155 lpfc_sli4_rq_release(hrq
, drq
);
12156 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12157 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
12159 hrq
->RQ_no_buf_found
++;
12160 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12164 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
12165 /* save off the frame for the word thread to process */
12166 list_add_tail(&dma_buf
->cq_event
.list
,
12167 &phba
->sli4_hba
.sp_queue_event
);
12168 /* Frame received */
12169 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
12170 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12173 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
12174 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
12175 hrq
->RQ_no_posted_buf
++;
12176 /* Post more buffers if possible */
12177 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12178 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
12179 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12188 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
12189 * @phba: Pointer to HBA context object.
12190 * @cq: Pointer to the completion queue.
12191 * @wcqe: Pointer to a completion queue entry.
12193 * This routine process a slow-path work-queue or receive queue completion queue
12196 * Return: true if work posted to worker thread, otherwise false.
12199 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12200 struct lpfc_cqe
*cqe
)
12202 struct lpfc_cqe cqevt
;
12203 bool workposted
= false;
12205 /* Copy the work queue CQE and convert endian order if needed */
12206 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
12208 /* Check and process for different type of WCQE and dispatch */
12209 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
12210 case CQE_CODE_COMPL_WQE
:
12211 /* Process the WQ/RQ complete event */
12212 phba
->last_completion_time
= jiffies
;
12213 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
12214 (struct lpfc_wcqe_complete
*)&cqevt
);
12216 case CQE_CODE_RELEASE_WQE
:
12217 /* Process the WQ release event */
12218 lpfc_sli4_sp_handle_rel_wcqe(phba
,
12219 (struct lpfc_wcqe_release
*)&cqevt
);
12221 case CQE_CODE_XRI_ABORTED
:
12222 /* Process the WQ XRI abort event */
12223 phba
->last_completion_time
= jiffies
;
12224 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
12225 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
12227 case CQE_CODE_RECEIVE
:
12228 case CQE_CODE_RECEIVE_V1
:
12229 /* Process the RQ event */
12230 phba
->last_completion_time
= jiffies
;
12231 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
12232 (struct lpfc_rcqe
*)&cqevt
);
12235 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12236 "0388 Not a valid WCQE code: x%x\n",
12237 bf_get(lpfc_cqe_code
, &cqevt
));
12244 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
12245 * @phba: Pointer to HBA context object.
12246 * @eqe: Pointer to fast-path event queue entry.
12248 * This routine process a event queue entry from the slow-path event queue.
12249 * It will check the MajorCode and MinorCode to determine this is for a
12250 * completion event on a completion queue, if not, an error shall be logged
12251 * and just return. Otherwise, it will get to the corresponding completion
12252 * queue and process all the entries on that completion queue, rearm the
12253 * completion queue, and then return.
12257 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
12258 struct lpfc_queue
*speq
)
12260 struct lpfc_queue
*cq
= NULL
, *childq
;
12261 struct lpfc_cqe
*cqe
;
12262 bool workposted
= false;
12266 /* Get the reference to the corresponding CQ */
12267 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12269 list_for_each_entry(childq
, &speq
->child_list
, list
) {
12270 if (childq
->queue_id
== cqid
) {
12275 if (unlikely(!cq
)) {
12276 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12277 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12278 "0365 Slow-path CQ identifier "
12279 "(%d) does not exist\n", cqid
);
12283 /* Process all the entries to the CQ */
12284 switch (cq
->type
) {
12286 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12287 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
12288 if (!(++ecount
% cq
->entry_repost
))
12289 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12294 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12295 if (cq
->subtype
== LPFC_FCP
)
12296 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
12299 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
12301 if (!(++ecount
% cq
->entry_repost
))
12302 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12305 /* Track the max number of CQEs processed in 1 EQ */
12306 if (ecount
> cq
->CQ_max_cqe
)
12307 cq
->CQ_max_cqe
= ecount
;
12310 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12311 "0370 Invalid completion queue type (%d)\n",
12316 /* Catch the no cq entry condition, log an error */
12317 if (unlikely(ecount
== 0))
12318 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12319 "0371 No entry from the CQ: identifier "
12320 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
12322 /* In any case, flash and re-arm the RCQ */
12323 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12325 /* wake up worker thread if there are works to be done */
12327 lpfc_worker_wake_up(phba
);
12331 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
12332 * @phba: Pointer to HBA context object.
12333 * @cq: Pointer to associated CQ
12334 * @wcqe: Pointer to work-queue completion queue entry.
12336 * This routine process a fast-path work queue completion entry from fast-path
12337 * event queue for FCP command response completion.
12340 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12341 struct lpfc_wcqe_complete
*wcqe
)
12343 struct lpfc_sli_ring
*pring
= cq
->pring
;
12344 struct lpfc_iocbq
*cmdiocbq
;
12345 struct lpfc_iocbq irspiocbq
;
12346 unsigned long iflags
;
12348 /* Check for response status */
12349 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
12350 /* If resource errors reported from HBA, reduce queue
12351 * depth of the SCSI device.
12353 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
12354 IOSTAT_LOCAL_REJECT
)) &&
12355 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
12356 IOERR_NO_RESOURCES
))
12357 phba
->lpfc_rampdown_queue_depth(phba
);
12359 /* Log the error status */
12360 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12361 "0373 FCP complete error: status=x%x, "
12362 "hw_status=x%x, total_data_specified=%d, "
12363 "parameter=x%x, word3=x%x\n",
12364 bf_get(lpfc_wcqe_c_status
, wcqe
),
12365 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
12366 wcqe
->total_data_placed
, wcqe
->parameter
,
12370 /* Look up the FCP command IOCB and create pseudo response IOCB */
12371 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
12372 pring
->stats
.iocb_event
++;
12373 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
12374 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12375 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
12376 if (unlikely(!cmdiocbq
)) {
12377 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12378 "0374 FCP complete with no corresponding "
12379 "cmdiocb: iotag (%d)\n",
12380 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12383 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
12384 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12385 "0375 FCP cmdiocb not callback function "
12387 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
12391 /* Fake the irspiocb and copy necessary response information */
12392 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
12394 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
12395 spin_lock_irqsave(&phba
->hbalock
, iflags
);
12396 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
12397 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
12400 /* Pass the cmd_iocb and the rsp state to the upper layer */
12401 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
12405 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
12406 * @phba: Pointer to HBA context object.
12407 * @cq: Pointer to completion queue.
12408 * @wcqe: Pointer to work-queue completion queue entry.
12410 * This routine handles an fast-path WQ entry comsumed event by invoking the
12411 * proper WQ release routine to the slow-path WQ.
12414 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12415 struct lpfc_wcqe_release
*wcqe
)
12417 struct lpfc_queue
*childwq
;
12418 bool wqid_matched
= false;
12421 /* Check for fast-path FCP work queue release */
12422 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
12423 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
12424 if (childwq
->queue_id
== fcp_wqid
) {
12425 lpfc_sli4_wq_release(childwq
,
12426 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
12427 wqid_matched
= true;
12431 /* Report warning log message if no match found */
12432 if (wqid_matched
!= true)
12433 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12434 "2580 Fast-path wqe consume event carries "
12435 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
12439 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
12440 * @cq: Pointer to the completion queue.
12441 * @eqe: Pointer to fast-path completion queue entry.
12443 * This routine process a fast-path work queue completion entry from fast-path
12444 * event queue for FCP command response completion.
12447 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12448 struct lpfc_cqe
*cqe
)
12450 struct lpfc_wcqe_release wcqe
;
12451 bool workposted
= false;
12453 /* Copy the work queue CQE and convert endian order if needed */
12454 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
12456 /* Check and process for different type of WCQE and dispatch */
12457 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
12458 case CQE_CODE_COMPL_WQE
:
12460 /* Process the WQ complete event */
12461 phba
->last_completion_time
= jiffies
;
12462 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
12463 (struct lpfc_wcqe_complete
*)&wcqe
);
12465 case CQE_CODE_RELEASE_WQE
:
12466 cq
->CQ_release_wqe
++;
12467 /* Process the WQ release event */
12468 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
12469 (struct lpfc_wcqe_release
*)&wcqe
);
12471 case CQE_CODE_XRI_ABORTED
:
12472 cq
->CQ_xri_aborted
++;
12473 /* Process the WQ XRI abort event */
12474 phba
->last_completion_time
= jiffies
;
12475 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
12476 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
12479 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12480 "0144 Not a valid WCQE code: x%x\n",
12481 bf_get(lpfc_wcqe_c_code
, &wcqe
));
12488 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
12489 * @phba: Pointer to HBA context object.
12490 * @eqe: Pointer to fast-path event queue entry.
12492 * This routine process a event queue entry from the fast-path event queue.
12493 * It will check the MajorCode and MinorCode to determine this is for a
12494 * completion event on a completion queue, if not, an error shall be logged
12495 * and just return. Otherwise, it will get to the corresponding completion
12496 * queue and process all the entries on the completion queue, rearm the
12497 * completion queue, and then return.
12500 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
12503 struct lpfc_queue
*cq
;
12504 struct lpfc_cqe
*cqe
;
12505 bool workposted
= false;
12509 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
12510 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12511 "0366 Not a valid completion "
12512 "event: majorcode=x%x, minorcode=x%x\n",
12513 bf_get_le32(lpfc_eqe_major_code
, eqe
),
12514 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
12518 /* Get the reference to the corresponding CQ */
12519 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12521 /* Check if this is a Slow path event */
12522 if (unlikely(cqid
!= phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
12523 lpfc_sli4_sp_handle_eqe(phba
, eqe
,
12524 phba
->sli4_hba
.hba_eq
[qidx
]);
12528 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
12529 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12530 "3146 Fast-path completion queues "
12531 "does not exist\n");
12534 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
12535 if (unlikely(!cq
)) {
12536 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12537 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12538 "0367 Fast-path completion queue "
12539 "(%d) does not exist\n", qidx
);
12543 if (unlikely(cqid
!= cq
->queue_id
)) {
12544 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12545 "0368 Miss-matched fast-path completion "
12546 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
12547 cqid
, cq
->queue_id
);
12551 /* Process all the entries to the CQ */
12552 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12553 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
12554 if (!(++ecount
% cq
->entry_repost
))
12555 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12558 /* Track the max number of CQEs processed in 1 EQ */
12559 if (ecount
> cq
->CQ_max_cqe
)
12560 cq
->CQ_max_cqe
= ecount
;
12562 /* Catch the no cq entry condition */
12563 if (unlikely(ecount
== 0))
12564 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12565 "0369 No entry from fast-path completion "
12566 "queue fcpcqid=%d\n", cq
->queue_id
);
12568 /* In any case, flash and re-arm the CQ */
12569 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12571 /* wake up worker thread if there are works to be done */
12573 lpfc_worker_wake_up(phba
);
12577 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12579 struct lpfc_eqe
*eqe
;
12581 /* walk all the EQ entries and drop on the floor */
12582 while ((eqe
= lpfc_sli4_eq_get(eq
)))
12585 /* Clear and re-arm the EQ */
12586 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
12591 * lpfc_sli4_fof_handle_eqe - Process a Flash Optimized Fabric event queue
12593 * @phba: Pointer to HBA context object.
12594 * @eqe: Pointer to fast-path event queue entry.
12596 * This routine process a event queue entry from the Flash Optimized Fabric
12597 * event queue. It will check the MajorCode and MinorCode to determine this
12598 * is for a completion event on a completion queue, if not, an error shall be
12599 * logged and just return. Otherwise, it will get to the corresponding
12600 * completion queue and process all the entries on the completion queue, rearm
12601 * the completion queue, and then return.
12604 lpfc_sli4_fof_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
)
12606 struct lpfc_queue
*cq
;
12607 struct lpfc_cqe
*cqe
;
12608 bool workposted
= false;
12612 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
12613 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12614 "9147 Not a valid completion "
12615 "event: majorcode=x%x, minorcode=x%x\n",
12616 bf_get_le32(lpfc_eqe_major_code
, eqe
),
12617 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
12621 /* Get the reference to the corresponding CQ */
12622 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12624 /* Next check for OAS */
12625 cq
= phba
->sli4_hba
.oas_cq
;
12626 if (unlikely(!cq
)) {
12627 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12628 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12629 "9148 OAS completion queue "
12630 "does not exist\n");
12634 if (unlikely(cqid
!= cq
->queue_id
)) {
12635 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12636 "9149 Miss-matched fast-path compl "
12637 "queue id: eqcqid=%d, fcpcqid=%d\n",
12638 cqid
, cq
->queue_id
);
12642 /* Process all the entries to the OAS CQ */
12643 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12644 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
12645 if (!(++ecount
% cq
->entry_repost
))
12646 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12649 /* Track the max number of CQEs processed in 1 EQ */
12650 if (ecount
> cq
->CQ_max_cqe
)
12651 cq
->CQ_max_cqe
= ecount
;
12653 /* Catch the no cq entry condition */
12654 if (unlikely(ecount
== 0))
12655 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12656 "9153 No entry from fast-path completion "
12657 "queue fcpcqid=%d\n", cq
->queue_id
);
12659 /* In any case, flash and re-arm the CQ */
12660 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12662 /* wake up worker thread if there are works to be done */
12664 lpfc_worker_wake_up(phba
);
12668 * lpfc_sli4_fof_intr_handler - HBA interrupt handler to SLI-4 device
12669 * @irq: Interrupt number.
12670 * @dev_id: The device context pointer.
12672 * This function is directly called from the PCI layer as an interrupt
12673 * service routine when device with SLI-4 interface spec is enabled with
12674 * MSI-X multi-message interrupt mode and there is a Flash Optimized Fabric
12675 * IOCB ring event in the HBA. However, when the device is enabled with either
12676 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12677 * device-level interrupt handler. When the PCI slot is in error recovery
12678 * or the HBA is undergoing initialization, the interrupt handler will not
12679 * process the interrupt. The Flash Optimized Fabric ring event are handled in
12680 * the intrrupt context. This function is called without any lock held.
12681 * It gets the hbalock to access and update SLI data structures. Note that,
12682 * the EQ to CQ are one-to-one map such that the EQ index is
12683 * equal to that of CQ index.
12685 * This function returns IRQ_HANDLED when interrupt is handled else it
12686 * returns IRQ_NONE.
12689 lpfc_sli4_fof_intr_handler(int irq
, void *dev_id
)
12691 struct lpfc_hba
*phba
;
12692 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
12693 struct lpfc_queue
*eq
;
12694 struct lpfc_eqe
*eqe
;
12695 unsigned long iflag
;
12698 /* Get the driver's phba structure from the dev_id */
12699 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
12700 phba
= fcp_eq_hdl
->phba
;
12702 if (unlikely(!phba
))
12705 /* Get to the EQ struct associated with this vector */
12706 eq
= phba
->sli4_hba
.fof_eq
;
12710 /* Check device state for handling interrupt */
12711 if (unlikely(lpfc_intr_state_check(phba
))) {
12713 /* Check again for link_state with lock held */
12714 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12715 if (phba
->link_state
< LPFC_LINK_DOWN
)
12716 /* Flush, clear interrupt, and rearm the EQ */
12717 lpfc_sli4_eq_flush(phba
, eq
);
12718 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12723 * Process all the event on FCP fast-path EQ
12725 while ((eqe
= lpfc_sli4_eq_get(eq
))) {
12726 lpfc_sli4_fof_handle_eqe(phba
, eqe
);
12727 if (!(++ecount
% eq
->entry_repost
))
12728 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_NOARM
);
12729 eq
->EQ_processed
++;
12732 /* Track the max number of EQEs processed in 1 intr */
12733 if (ecount
> eq
->EQ_max_eqe
)
12734 eq
->EQ_max_eqe
= ecount
;
12737 if (unlikely(ecount
== 0)) {
12740 if (phba
->intr_type
== MSIX
)
12741 /* MSI-X treated interrupt served as no EQ share INT */
12742 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12743 "9145 MSI-X interrupt with no EQE\n");
12745 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12746 "9146 ISR interrupt with no EQE\n");
12747 /* Non MSI-X treated on interrupt as EQ share INT */
12751 /* Always clear and re-arm the fast-path EQ */
12752 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
12753 return IRQ_HANDLED
;
12757 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
12758 * @irq: Interrupt number.
12759 * @dev_id: The device context pointer.
12761 * This function is directly called from the PCI layer as an interrupt
12762 * service routine when device with SLI-4 interface spec is enabled with
12763 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12764 * ring event in the HBA. However, when the device is enabled with either
12765 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12766 * device-level interrupt handler. When the PCI slot is in error recovery
12767 * or the HBA is undergoing initialization, the interrupt handler will not
12768 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12769 * the intrrupt context. This function is called without any lock held.
12770 * It gets the hbalock to access and update SLI data structures. Note that,
12771 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
12772 * equal to that of FCP CQ index.
12774 * The link attention and ELS ring attention events are handled
12775 * by the worker thread. The interrupt handler signals the worker thread
12776 * and returns for these events. This function is called without any lock
12777 * held. It gets the hbalock to access and update SLI data structures.
12779 * This function returns IRQ_HANDLED when interrupt is handled else it
12780 * returns IRQ_NONE.
12783 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
12785 struct lpfc_hba
*phba
;
12786 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
12787 struct lpfc_queue
*fpeq
;
12788 struct lpfc_eqe
*eqe
;
12789 unsigned long iflag
;
12793 /* Get the driver's phba structure from the dev_id */
12794 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
12795 phba
= fcp_eq_hdl
->phba
;
12796 fcp_eqidx
= fcp_eq_hdl
->idx
;
12798 if (unlikely(!phba
))
12800 if (unlikely(!phba
->sli4_hba
.hba_eq
))
12803 /* Get to the EQ struct associated with this vector */
12804 fpeq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12805 if (unlikely(!fpeq
))
12808 if (lpfc_fcp_look_ahead
) {
12809 if (atomic_dec_and_test(&fcp_eq_hdl
->fcp_eq_in_use
))
12810 lpfc_sli4_eq_clr_intr(fpeq
);
12812 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12817 /* Check device state for handling interrupt */
12818 if (unlikely(lpfc_intr_state_check(phba
))) {
12819 fpeq
->EQ_badstate
++;
12820 /* Check again for link_state with lock held */
12821 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12822 if (phba
->link_state
< LPFC_LINK_DOWN
)
12823 /* Flush, clear interrupt, and rearm the EQ */
12824 lpfc_sli4_eq_flush(phba
, fpeq
);
12825 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12826 if (lpfc_fcp_look_ahead
)
12827 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12832 * Process all the event on FCP fast-path EQ
12834 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
12838 lpfc_sli4_hba_handle_eqe(phba
, eqe
, fcp_eqidx
);
12839 if (!(++ecount
% fpeq
->entry_repost
))
12840 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
12841 fpeq
->EQ_processed
++;
12844 /* Track the max number of EQEs processed in 1 intr */
12845 if (ecount
> fpeq
->EQ_max_eqe
)
12846 fpeq
->EQ_max_eqe
= ecount
;
12848 /* Always clear and re-arm the fast-path EQ */
12849 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
12851 if (unlikely(ecount
== 0)) {
12852 fpeq
->EQ_no_entry
++;
12854 if (lpfc_fcp_look_ahead
) {
12855 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12859 if (phba
->intr_type
== MSIX
)
12860 /* MSI-X treated interrupt served as no EQ share INT */
12861 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12862 "0358 MSI-X interrupt with no EQE\n");
12864 /* Non MSI-X treated on interrupt as EQ share INT */
12868 if (lpfc_fcp_look_ahead
)
12869 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12870 return IRQ_HANDLED
;
12871 } /* lpfc_sli4_fp_intr_handler */
12874 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
12875 * @irq: Interrupt number.
12876 * @dev_id: The device context pointer.
12878 * This function is the device-level interrupt handler to device with SLI-4
12879 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
12880 * interrupt mode is enabled and there is an event in the HBA which requires
12881 * driver attention. This function invokes the slow-path interrupt attention
12882 * handling function and fast-path interrupt attention handling function in
12883 * turn to process the relevant HBA attention events. This function is called
12884 * without any lock held. It gets the hbalock to access and update SLI data
12887 * This function returns IRQ_HANDLED when interrupt is handled, else it
12888 * returns IRQ_NONE.
12891 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
12893 struct lpfc_hba
*phba
;
12894 irqreturn_t hba_irq_rc
;
12895 bool hba_handled
= false;
12898 /* Get the driver's phba structure from the dev_id */
12899 phba
= (struct lpfc_hba
*)dev_id
;
12901 if (unlikely(!phba
))
12905 * Invoke fast-path host attention interrupt handling as appropriate.
12907 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
12908 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
12909 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
12910 if (hba_irq_rc
== IRQ_HANDLED
)
12911 hba_handled
|= true;
12914 if (phba
->cfg_fof
) {
12915 hba_irq_rc
= lpfc_sli4_fof_intr_handler(irq
,
12916 &phba
->sli4_hba
.fcp_eq_hdl
[0]);
12917 if (hba_irq_rc
== IRQ_HANDLED
)
12918 hba_handled
|= true;
12921 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
12922 } /* lpfc_sli4_intr_handler */
12925 * lpfc_sli4_queue_free - free a queue structure and associated memory
12926 * @queue: The queue structure to free.
12928 * This function frees a queue structure and the DMAable memory used for
12929 * the host resident queue. This function must be called after destroying the
12930 * queue on the HBA.
12933 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
12935 struct lpfc_dmabuf
*dmabuf
;
12940 while (!list_empty(&queue
->page_list
)) {
12941 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
12943 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
12944 dmabuf
->virt
, dmabuf
->phys
);
12952 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12953 * @phba: The HBA that this queue is being created on.
12954 * @entry_size: The size of each queue entry for this queue.
12955 * @entry count: The number of entries that this queue will handle.
12957 * This function allocates a queue structure and the DMAable memory used for
12958 * the host resident queue. This function must be called before creating the
12959 * queue on the HBA.
12961 struct lpfc_queue
*
12962 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
12963 uint32_t entry_count
)
12965 struct lpfc_queue
*queue
;
12966 struct lpfc_dmabuf
*dmabuf
;
12967 int x
, total_qe_count
;
12969 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12971 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12972 hw_page_size
= SLI4_PAGE_SIZE
;
12974 queue
= kzalloc(sizeof(struct lpfc_queue
) +
12975 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
12978 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
12979 hw_page_size
))/hw_page_size
;
12980 INIT_LIST_HEAD(&queue
->list
);
12981 INIT_LIST_HEAD(&queue
->page_list
);
12982 INIT_LIST_HEAD(&queue
->child_list
);
12983 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
12984 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
12987 dmabuf
->virt
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
12988 hw_page_size
, &dmabuf
->phys
,
12990 if (!dmabuf
->virt
) {
12994 dmabuf
->buffer_tag
= x
;
12995 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
12996 /* initialize queue's entry array */
12997 dma_pointer
= dmabuf
->virt
;
12998 for (; total_qe_count
< entry_count
&&
12999 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
13000 total_qe_count
++, dma_pointer
+= entry_size
) {
13001 queue
->qe
[total_qe_count
].address
= dma_pointer
;
13004 queue
->entry_size
= entry_size
;
13005 queue
->entry_count
= entry_count
;
13008 * entry_repost is calculated based on the number of entries in the
13009 * queue. This works out except for RQs. If buffers are NOT initially
13010 * posted for every RQE, entry_repost should be adjusted accordingly.
13012 queue
->entry_repost
= (entry_count
>> 3);
13013 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
13014 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
13015 queue
->phba
= phba
;
13019 lpfc_sli4_queue_free(queue
);
13024 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
13025 * @phba: HBA structure that indicates port to create a queue on.
13026 * @pci_barset: PCI BAR set flag.
13028 * This function shall perform iomap of the specified PCI BAR address to host
13029 * memory address if not already done so and return it. The returned host
13030 * memory address can be NULL.
13032 static void __iomem
*
13033 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
13038 switch (pci_barset
) {
13039 case WQ_PCI_BAR_0_AND_1
:
13040 return phba
->pci_bar0_memmap_p
;
13041 case WQ_PCI_BAR_2_AND_3
:
13042 return phba
->pci_bar2_memmap_p
;
13043 case WQ_PCI_BAR_4_AND_5
:
13044 return phba
->pci_bar4_memmap_p
;
13052 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
13053 * @phba: HBA structure that indicates port to create a queue on.
13054 * @startq: The starting FCP EQ to modify
13056 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
13058 * The @phba struct is used to send mailbox command to HBA. The @startq
13059 * is used to get the starting FCP EQ to change.
13060 * This function is asynchronous and will wait for the mailbox
13061 * command to finish before continuing.
13063 * On success this function will return a zero. If unable to allocate enough
13064 * memory this function will return -ENOMEM. If the queue create mailbox command
13065 * fails this function will return -ENXIO.
13068 lpfc_modify_fcp_eq_delay(struct lpfc_hba
*phba
, uint32_t startq
)
13070 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
13071 LPFC_MBOXQ_t
*mbox
;
13072 struct lpfc_queue
*eq
;
13073 int cnt
, rc
, length
, status
= 0;
13074 uint32_t shdr_status
, shdr_add_status
;
13077 union lpfc_sli4_cfg_shdr
*shdr
;
13080 if (startq
>= phba
->cfg_fcp_io_channel
)
13083 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13086 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
13087 sizeof(struct lpfc_sli4_cfg_mhdr
));
13088 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13089 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
13090 length
, LPFC_SLI4_MBX_EMBED
);
13091 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
13093 /* Calculate delay multiper from maximum interrupt per second */
13094 result
= phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
;
13095 if (result
> LPFC_DMULT_CONST
)
13098 dmult
= LPFC_DMULT_CONST
/result
- 1;
13101 for (fcp_eqidx
= startq
; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
13103 eq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
13106 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
13107 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
13108 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
13110 if (cnt
>= LPFC_MAX_EQ_DELAY
)
13113 eq_delay
->u
.request
.num_eq
= cnt
;
13115 mbox
->vport
= phba
->pport
;
13116 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13117 mbox
->context1
= NULL
;
13118 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13119 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
13120 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13121 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13122 if (shdr_status
|| shdr_add_status
|| rc
) {
13123 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13124 "2512 MODIFY_EQ_DELAY mailbox failed with "
13125 "status x%x add_status x%x, mbx status x%x\n",
13126 shdr_status
, shdr_add_status
, rc
);
13129 mempool_free(mbox
, phba
->mbox_mem_pool
);
13134 * lpfc_eq_create - Create an Event Queue on the HBA
13135 * @phba: HBA structure that indicates port to create a queue on.
13136 * @eq: The queue structure to use to create the event queue.
13137 * @imax: The maximum interrupt per second limit.
13139 * This function creates an event queue, as detailed in @eq, on a port,
13140 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
13142 * The @phba struct is used to send mailbox command to HBA. The @eq struct
13143 * is used to get the entry count and entry size that are necessary to
13144 * determine the number of pages to allocate and use for this queue. This
13145 * function will send the EQ_CREATE mailbox command to the HBA to setup the
13146 * event queue. This function is asynchronous and will wait for the mailbox
13147 * command to finish before continuing.
13149 * On success this function will return a zero. If unable to allocate enough
13150 * memory this function will return -ENOMEM. If the queue create mailbox command
13151 * fails this function will return -ENXIO.
13154 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
13156 struct lpfc_mbx_eq_create
*eq_create
;
13157 LPFC_MBOXQ_t
*mbox
;
13158 int rc
, length
, status
= 0;
13159 struct lpfc_dmabuf
*dmabuf
;
13160 uint32_t shdr_status
, shdr_add_status
;
13161 union lpfc_sli4_cfg_shdr
*shdr
;
13163 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13165 /* sanity check on queue memory */
13168 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13169 hw_page_size
= SLI4_PAGE_SIZE
;
13171 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13174 length
= (sizeof(struct lpfc_mbx_eq_create
) -
13175 sizeof(struct lpfc_sli4_cfg_mhdr
));
13176 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13177 LPFC_MBOX_OPCODE_EQ_CREATE
,
13178 length
, LPFC_SLI4_MBX_EMBED
);
13179 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
13180 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
13182 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
13184 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
13185 /* don't setup delay multiplier using EQ_CREATE */
13187 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
13189 switch (eq
->entry_count
) {
13191 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13192 "0360 Unsupported EQ count. (%d)\n",
13194 if (eq
->entry_count
< 256)
13196 /* otherwise default to smallest count (drop through) */
13198 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13202 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13206 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13210 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13214 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
13218 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
13219 memset(dmabuf
->virt
, 0, hw_page_size
);
13220 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13221 putPaddrLow(dmabuf
->phys
);
13222 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13223 putPaddrHigh(dmabuf
->phys
);
13225 mbox
->vport
= phba
->pport
;
13226 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13227 mbox
->context1
= NULL
;
13228 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13229 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
13230 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13231 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13232 if (shdr_status
|| shdr_add_status
|| rc
) {
13233 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13234 "2500 EQ_CREATE mailbox failed with "
13235 "status x%x add_status x%x, mbx status x%x\n",
13236 shdr_status
, shdr_add_status
, rc
);
13239 eq
->type
= LPFC_EQ
;
13240 eq
->subtype
= LPFC_NONE
;
13241 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
13242 if (eq
->queue_id
== 0xFFFF)
13244 eq
->host_index
= 0;
13247 mempool_free(mbox
, phba
->mbox_mem_pool
);
13252 * lpfc_cq_create - Create a Completion Queue on the HBA
13253 * @phba: HBA structure that indicates port to create a queue on.
13254 * @cq: The queue structure to use to create the completion queue.
13255 * @eq: The event queue to bind this completion queue to.
13257 * This function creates a completion queue, as detailed in @wq, on a port,
13258 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
13260 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13261 * is used to get the entry count and entry size that are necessary to
13262 * determine the number of pages to allocate and use for this queue. The @eq
13263 * is used to indicate which event queue to bind this completion queue to. This
13264 * function will send the CQ_CREATE mailbox command to the HBA to setup the
13265 * completion queue. This function is asynchronous and will wait for the mailbox
13266 * command to finish before continuing.
13268 * On success this function will return a zero. If unable to allocate enough
13269 * memory this function will return -ENOMEM. If the queue create mailbox command
13270 * fails this function will return -ENXIO.
13273 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
13274 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
13276 struct lpfc_mbx_cq_create
*cq_create
;
13277 struct lpfc_dmabuf
*dmabuf
;
13278 LPFC_MBOXQ_t
*mbox
;
13279 int rc
, length
, status
= 0;
13280 uint32_t shdr_status
, shdr_add_status
;
13281 union lpfc_sli4_cfg_shdr
*shdr
;
13282 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13284 /* sanity check on queue memory */
13287 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13288 hw_page_size
= SLI4_PAGE_SIZE
;
13290 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13293 length
= (sizeof(struct lpfc_mbx_cq_create
) -
13294 sizeof(struct lpfc_sli4_cfg_mhdr
));
13295 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13296 LPFC_MBOX_OPCODE_CQ_CREATE
,
13297 length
, LPFC_SLI4_MBX_EMBED
);
13298 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
13299 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
13300 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
13302 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
13303 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
13304 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13305 phba
->sli4_hba
.pc_sli4_params
.cqv
);
13306 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
13307 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
13308 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
13309 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
13312 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
13315 switch (cq
->entry_count
) {
13317 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13318 "0361 Unsupported CQ count. (%d)\n",
13320 if (cq
->entry_count
< 256) {
13324 /* otherwise default to smallest count (drop through) */
13326 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
13330 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
13334 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
13338 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
13339 memset(dmabuf
->virt
, 0, hw_page_size
);
13340 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13341 putPaddrLow(dmabuf
->phys
);
13342 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13343 putPaddrHigh(dmabuf
->phys
);
13345 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13347 /* The IOCTL status is embedded in the mailbox subheader. */
13348 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13349 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13350 if (shdr_status
|| shdr_add_status
|| rc
) {
13351 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13352 "2501 CQ_CREATE mailbox failed with "
13353 "status x%x add_status x%x, mbx status x%x\n",
13354 shdr_status
, shdr_add_status
, rc
);
13358 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
13359 if (cq
->queue_id
== 0xFFFF) {
13363 /* link the cq onto the parent eq child list */
13364 list_add_tail(&cq
->list
, &eq
->child_list
);
13365 /* Set up completion queue's type and subtype */
13367 cq
->subtype
= subtype
;
13368 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
13369 cq
->assoc_qid
= eq
->queue_id
;
13370 cq
->host_index
= 0;
13374 mempool_free(mbox
, phba
->mbox_mem_pool
);
13379 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
13380 * @phba: HBA structure that indicates port to create a queue on.
13381 * @mq: The queue structure to use to create the mailbox queue.
13382 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
13383 * @cq: The completion queue to associate with this cq.
13385 * This function provides failback (fb) functionality when the
13386 * mq_create_ext fails on older FW generations. It's purpose is identical
13387 * to mq_create_ext otherwise.
13389 * This routine cannot fail as all attributes were previously accessed and
13390 * initialized in mq_create_ext.
13393 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
13394 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
13396 struct lpfc_mbx_mq_create
*mq_create
;
13397 struct lpfc_dmabuf
*dmabuf
;
13400 length
= (sizeof(struct lpfc_mbx_mq_create
) -
13401 sizeof(struct lpfc_sli4_cfg_mhdr
));
13402 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13403 LPFC_MBOX_OPCODE_MQ_CREATE
,
13404 length
, LPFC_SLI4_MBX_EMBED
);
13405 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
13406 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
13408 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
13410 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
13411 switch (mq
->entry_count
) {
13413 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13414 LPFC_MQ_RING_SIZE_16
);
13417 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13418 LPFC_MQ_RING_SIZE_32
);
13421 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13422 LPFC_MQ_RING_SIZE_64
);
13425 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
13426 LPFC_MQ_RING_SIZE_128
);
13429 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
13430 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13431 putPaddrLow(dmabuf
->phys
);
13432 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13433 putPaddrHigh(dmabuf
->phys
);
13438 * lpfc_mq_create - Create a mailbox Queue on the HBA
13439 * @phba: HBA structure that indicates port to create a queue on.
13440 * @mq: The queue structure to use to create the mailbox queue.
13441 * @cq: The completion queue to associate with this cq.
13442 * @subtype: The queue's subtype.
13444 * This function creates a mailbox queue, as detailed in @mq, on a port,
13445 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
13447 * The @phba struct is used to send mailbox command to HBA. The @cq struct
13448 * is used to get the entry count and entry size that are necessary to
13449 * determine the number of pages to allocate and use for this queue. This
13450 * function will send the MQ_CREATE mailbox command to the HBA to setup the
13451 * mailbox queue. This function is asynchronous and will wait for the mailbox
13452 * command to finish before continuing.
13454 * On success this function will return a zero. If unable to allocate enough
13455 * memory this function will return -ENOMEM. If the queue create mailbox command
13456 * fails this function will return -ENXIO.
13459 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
13460 struct lpfc_queue
*cq
, uint32_t subtype
)
13462 struct lpfc_mbx_mq_create
*mq_create
;
13463 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
13464 struct lpfc_dmabuf
*dmabuf
;
13465 LPFC_MBOXQ_t
*mbox
;
13466 int rc
, length
, status
= 0;
13467 uint32_t shdr_status
, shdr_add_status
;
13468 union lpfc_sli4_cfg_shdr
*shdr
;
13469 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13471 /* sanity check on queue memory */
13474 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13475 hw_page_size
= SLI4_PAGE_SIZE
;
13477 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13480 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
13481 sizeof(struct lpfc_sli4_cfg_mhdr
));
13482 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13483 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
13484 length
, LPFC_SLI4_MBX_EMBED
);
13486 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
13487 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
13488 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
13489 &mq_create_ext
->u
.request
, mq
->page_count
);
13490 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
13491 &mq_create_ext
->u
.request
, 1);
13492 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
13493 &mq_create_ext
->u
.request
, 1);
13494 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
13495 &mq_create_ext
->u
.request
, 1);
13496 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
13497 &mq_create_ext
->u
.request
, 1);
13498 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
13499 &mq_create_ext
->u
.request
, 1);
13500 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
13501 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13502 phba
->sli4_hba
.pc_sli4_params
.mqv
);
13503 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
13504 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
13507 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
13509 switch (mq
->entry_count
) {
13511 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13512 "0362 Unsupported MQ count. (%d)\n",
13514 if (mq
->entry_count
< 16) {
13518 /* otherwise default to smallest count (drop through) */
13520 bf_set(lpfc_mq_context_ring_size
,
13521 &mq_create_ext
->u
.request
.context
,
13522 LPFC_MQ_RING_SIZE_16
);
13525 bf_set(lpfc_mq_context_ring_size
,
13526 &mq_create_ext
->u
.request
.context
,
13527 LPFC_MQ_RING_SIZE_32
);
13530 bf_set(lpfc_mq_context_ring_size
,
13531 &mq_create_ext
->u
.request
.context
,
13532 LPFC_MQ_RING_SIZE_64
);
13535 bf_set(lpfc_mq_context_ring_size
,
13536 &mq_create_ext
->u
.request
.context
,
13537 LPFC_MQ_RING_SIZE_128
);
13540 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
13541 memset(dmabuf
->virt
, 0, hw_page_size
);
13542 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13543 putPaddrLow(dmabuf
->phys
);
13544 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13545 putPaddrHigh(dmabuf
->phys
);
13547 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13548 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
13549 &mq_create_ext
->u
.response
);
13550 if (rc
!= MBX_SUCCESS
) {
13551 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13552 "2795 MQ_CREATE_EXT failed with "
13553 "status x%x. Failback to MQ_CREATE.\n",
13555 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
13556 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
13557 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13558 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
13559 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
13560 &mq_create
->u
.response
);
13563 /* The IOCTL status is embedded in the mailbox subheader. */
13564 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13565 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13566 if (shdr_status
|| shdr_add_status
|| rc
) {
13567 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13568 "2502 MQ_CREATE mailbox failed with "
13569 "status x%x add_status x%x, mbx status x%x\n",
13570 shdr_status
, shdr_add_status
, rc
);
13574 if (mq
->queue_id
== 0xFFFF) {
13578 mq
->type
= LPFC_MQ
;
13579 mq
->assoc_qid
= cq
->queue_id
;
13580 mq
->subtype
= subtype
;
13581 mq
->host_index
= 0;
13584 /* link the mq onto the parent cq child list */
13585 list_add_tail(&mq
->list
, &cq
->child_list
);
13587 mempool_free(mbox
, phba
->mbox_mem_pool
);
13592 * lpfc_wq_create - Create a Work Queue on the HBA
13593 * @phba: HBA structure that indicates port to create a queue on.
13594 * @wq: The queue structure to use to create the work queue.
13595 * @cq: The completion queue to bind this work queue to.
13596 * @subtype: The subtype of the work queue indicating its functionality.
13598 * This function creates a work queue, as detailed in @wq, on a port, described
13599 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
13601 * The @phba struct is used to send mailbox command to HBA. The @wq struct
13602 * is used to get the entry count and entry size that are necessary to
13603 * determine the number of pages to allocate and use for this queue. The @cq
13604 * is used to indicate which completion queue to bind this work queue to. This
13605 * function will send the WQ_CREATE mailbox command to the HBA to setup the
13606 * work queue. This function is asynchronous and will wait for the mailbox
13607 * command to finish before continuing.
13609 * On success this function will return a zero. If unable to allocate enough
13610 * memory this function will return -ENOMEM. If the queue create mailbox command
13611 * fails this function will return -ENXIO.
13614 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
13615 struct lpfc_queue
*cq
, uint32_t subtype
)
13617 struct lpfc_mbx_wq_create
*wq_create
;
13618 struct lpfc_dmabuf
*dmabuf
;
13619 LPFC_MBOXQ_t
*mbox
;
13620 int rc
, length
, status
= 0;
13621 uint32_t shdr_status
, shdr_add_status
;
13622 union lpfc_sli4_cfg_shdr
*shdr
;
13623 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13624 struct dma_address
*page
;
13625 void __iomem
*bar_memmap_p
;
13626 uint32_t db_offset
;
13627 uint16_t pci_barset
;
13629 /* sanity check on queue memory */
13632 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13633 hw_page_size
= SLI4_PAGE_SIZE
;
13635 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13638 length
= (sizeof(struct lpfc_mbx_wq_create
) -
13639 sizeof(struct lpfc_sli4_cfg_mhdr
));
13640 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13641 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
13642 length
, LPFC_SLI4_MBX_EMBED
);
13643 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
13644 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
13645 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
13647 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
13650 /* wqv is the earliest version supported, NOT the latest */
13651 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13652 phba
->sli4_hba
.pc_sli4_params
.wqv
);
13654 switch (phba
->sli4_hba
.pc_sli4_params
.wqv
) {
13655 case LPFC_Q_CREATE_VERSION_0
:
13656 switch (wq
->entry_size
) {
13659 /* Nothing to do, version 0 ONLY supports 64 byte */
13660 page
= wq_create
->u
.request
.page
;
13663 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
13664 LPFC_WQ_SZ128_SUPPORT
)) {
13668 /* If we get here the HBA MUST also support V1 and
13671 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13672 LPFC_Q_CREATE_VERSION_1
);
13674 bf_set(lpfc_mbx_wq_create_wqe_count
,
13675 &wq_create
->u
.request_1
, wq
->entry_count
);
13676 bf_set(lpfc_mbx_wq_create_wqe_size
,
13677 &wq_create
->u
.request_1
,
13678 LPFC_WQ_WQE_SIZE_128
);
13679 bf_set(lpfc_mbx_wq_create_page_size
,
13680 &wq_create
->u
.request_1
,
13681 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13682 page
= wq_create
->u
.request_1
.page
;
13686 case LPFC_Q_CREATE_VERSION_1
:
13687 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
13689 switch (wq
->entry_size
) {
13692 bf_set(lpfc_mbx_wq_create_wqe_size
,
13693 &wq_create
->u
.request_1
,
13694 LPFC_WQ_WQE_SIZE_64
);
13697 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
13698 LPFC_WQ_SZ128_SUPPORT
)) {
13702 bf_set(lpfc_mbx_wq_create_wqe_size
,
13703 &wq_create
->u
.request_1
,
13704 LPFC_WQ_WQE_SIZE_128
);
13707 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
13708 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13709 page
= wq_create
->u
.request_1
.page
;
13716 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
13717 memset(dmabuf
->virt
, 0, hw_page_size
);
13718 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
13719 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
13722 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13723 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
13725 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13726 /* The IOCTL status is embedded in the mailbox subheader. */
13727 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13728 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13729 if (shdr_status
|| shdr_add_status
|| rc
) {
13730 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13731 "2503 WQ_CREATE mailbox failed with "
13732 "status x%x add_status x%x, mbx status x%x\n",
13733 shdr_status
, shdr_add_status
, rc
);
13737 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
13738 if (wq
->queue_id
== 0xFFFF) {
13742 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
13743 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
13744 &wq_create
->u
.response
);
13745 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
13746 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
13747 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13748 "3265 WQ[%d] doorbell format not "
13749 "supported: x%x\n", wq
->queue_id
,
13754 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
13755 &wq_create
->u
.response
);
13756 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
13757 if (!bar_memmap_p
) {
13758 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13759 "3263 WQ[%d] failed to memmap pci "
13760 "barset:x%x\n", wq
->queue_id
,
13765 db_offset
= wq_create
->u
.response
.doorbell_offset
;
13766 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
13767 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
13768 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13769 "3252 WQ[%d] doorbell offset not "
13770 "supported: x%x\n", wq
->queue_id
,
13775 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
13776 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13777 "3264 WQ[%d]: barset:x%x, offset:x%x, "
13778 "format:x%x\n", wq
->queue_id
, pci_barset
,
13779 db_offset
, wq
->db_format
);
13781 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
13782 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
13784 wq
->type
= LPFC_WQ
;
13785 wq
->assoc_qid
= cq
->queue_id
;
13786 wq
->subtype
= subtype
;
13787 wq
->host_index
= 0;
13789 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
13791 /* link the wq onto the parent cq child list */
13792 list_add_tail(&wq
->list
, &cq
->child_list
);
13794 mempool_free(mbox
, phba
->mbox_mem_pool
);
13799 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
13800 * @phba: HBA structure that indicates port to create a queue on.
13801 * @rq: The queue structure to use for the receive queue.
13802 * @qno: The associated HBQ number
13805 * For SLI4 we need to adjust the RQ repost value based on
13806 * the number of buffers that are initially posted to the RQ.
13809 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
13813 /* sanity check on queue memory */
13816 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
13818 /* Recalc repost for RQs based on buffers initially posted */
13820 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
13821 cnt
= LPFC_QUEUE_MIN_REPOST
;
13823 rq
->entry_repost
= cnt
;
13827 * lpfc_rq_create - Create a Receive Queue on the HBA
13828 * @phba: HBA structure that indicates port to create a queue on.
13829 * @hrq: The queue structure to use to create the header receive queue.
13830 * @drq: The queue structure to use to create the data receive queue.
13831 * @cq: The completion queue to bind this work queue to.
13833 * This function creates a receive buffer queue pair , as detailed in @hrq and
13834 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
13837 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
13838 * struct is used to get the entry count that is necessary to determine the
13839 * number of pages to use for this queue. The @cq is used to indicate which
13840 * completion queue to bind received buffers that are posted to these queues to.
13841 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
13842 * receive queue pair. This function is asynchronous and will wait for the
13843 * mailbox command to finish before continuing.
13845 * On success this function will return a zero. If unable to allocate enough
13846 * memory this function will return -ENOMEM. If the queue create mailbox command
13847 * fails this function will return -ENXIO.
13850 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13851 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
13853 struct lpfc_mbx_rq_create
*rq_create
;
13854 struct lpfc_dmabuf
*dmabuf
;
13855 LPFC_MBOXQ_t
*mbox
;
13856 int rc
, length
, status
= 0;
13857 uint32_t shdr_status
, shdr_add_status
;
13858 union lpfc_sli4_cfg_shdr
*shdr
;
13859 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13860 void __iomem
*bar_memmap_p
;
13861 uint32_t db_offset
;
13862 uint16_t pci_barset
;
13864 /* sanity check on queue memory */
13865 if (!hrq
|| !drq
|| !cq
)
13867 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13868 hw_page_size
= SLI4_PAGE_SIZE
;
13870 if (hrq
->entry_count
!= drq
->entry_count
)
13872 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13875 length
= (sizeof(struct lpfc_mbx_rq_create
) -
13876 sizeof(struct lpfc_sli4_cfg_mhdr
));
13877 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13878 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
13879 length
, LPFC_SLI4_MBX_EMBED
);
13880 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
13881 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13882 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13883 phba
->sli4_hba
.pc_sli4_params
.rqv
);
13884 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
13885 bf_set(lpfc_rq_context_rqe_count_1
,
13886 &rq_create
->u
.request
.context
,
13888 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
13889 bf_set(lpfc_rq_context_rqe_size
,
13890 &rq_create
->u
.request
.context
,
13892 bf_set(lpfc_rq_context_page_size
,
13893 &rq_create
->u
.request
.context
,
13894 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13896 switch (hrq
->entry_count
) {
13898 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13899 "2535 Unsupported RQ count. (%d)\n",
13901 if (hrq
->entry_count
< 512) {
13905 /* otherwise default to smallest count (drop through) */
13907 bf_set(lpfc_rq_context_rqe_count
,
13908 &rq_create
->u
.request
.context
,
13909 LPFC_RQ_RING_SIZE_512
);
13912 bf_set(lpfc_rq_context_rqe_count
,
13913 &rq_create
->u
.request
.context
,
13914 LPFC_RQ_RING_SIZE_1024
);
13917 bf_set(lpfc_rq_context_rqe_count
,
13918 &rq_create
->u
.request
.context
,
13919 LPFC_RQ_RING_SIZE_2048
);
13922 bf_set(lpfc_rq_context_rqe_count
,
13923 &rq_create
->u
.request
.context
,
13924 LPFC_RQ_RING_SIZE_4096
);
13927 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
13928 LPFC_HDR_BUF_SIZE
);
13930 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
13932 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
13934 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
13935 memset(dmabuf
->virt
, 0, hw_page_size
);
13936 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13937 putPaddrLow(dmabuf
->phys
);
13938 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13939 putPaddrHigh(dmabuf
->phys
);
13941 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13942 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
13944 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13945 /* The IOCTL status is embedded in the mailbox subheader. */
13946 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13947 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13948 if (shdr_status
|| shdr_add_status
|| rc
) {
13949 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13950 "2504 RQ_CREATE mailbox failed with "
13951 "status x%x add_status x%x, mbx status x%x\n",
13952 shdr_status
, shdr_add_status
, rc
);
13956 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
13957 if (hrq
->queue_id
== 0xFFFF) {
13962 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
13963 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
13964 &rq_create
->u
.response
);
13965 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
13966 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
13967 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13968 "3262 RQ [%d] doorbell format not "
13969 "supported: x%x\n", hrq
->queue_id
,
13975 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
13976 &rq_create
->u
.response
);
13977 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
13978 if (!bar_memmap_p
) {
13979 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13980 "3269 RQ[%d] failed to memmap pci "
13981 "barset:x%x\n", hrq
->queue_id
,
13987 db_offset
= rq_create
->u
.response
.doorbell_offset
;
13988 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
13989 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
13990 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13991 "3270 RQ[%d] doorbell offset not "
13992 "supported: x%x\n", hrq
->queue_id
,
13997 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
13998 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13999 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
14000 "format:x%x\n", hrq
->queue_id
, pci_barset
,
14001 db_offset
, hrq
->db_format
);
14003 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
14004 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
14006 hrq
->type
= LPFC_HRQ
;
14007 hrq
->assoc_qid
= cq
->queue_id
;
14008 hrq
->subtype
= subtype
;
14009 hrq
->host_index
= 0;
14010 hrq
->hba_index
= 0;
14012 /* now create the data queue */
14013 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14014 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
14015 length
, LPFC_SLI4_MBX_EMBED
);
14016 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
14017 phba
->sli4_hba
.pc_sli4_params
.rqv
);
14018 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
14019 bf_set(lpfc_rq_context_rqe_count_1
,
14020 &rq_create
->u
.request
.context
, hrq
->entry_count
);
14021 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
14022 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
14024 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
14025 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
14027 switch (drq
->entry_count
) {
14029 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14030 "2536 Unsupported RQ count. (%d)\n",
14032 if (drq
->entry_count
< 512) {
14036 /* otherwise default to smallest count (drop through) */
14038 bf_set(lpfc_rq_context_rqe_count
,
14039 &rq_create
->u
.request
.context
,
14040 LPFC_RQ_RING_SIZE_512
);
14043 bf_set(lpfc_rq_context_rqe_count
,
14044 &rq_create
->u
.request
.context
,
14045 LPFC_RQ_RING_SIZE_1024
);
14048 bf_set(lpfc_rq_context_rqe_count
,
14049 &rq_create
->u
.request
.context
,
14050 LPFC_RQ_RING_SIZE_2048
);
14053 bf_set(lpfc_rq_context_rqe_count
,
14054 &rq_create
->u
.request
.context
,
14055 LPFC_RQ_RING_SIZE_4096
);
14058 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
14059 LPFC_DATA_BUF_SIZE
);
14061 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
14063 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
14065 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
14066 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
14067 putPaddrLow(dmabuf
->phys
);
14068 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
14069 putPaddrHigh(dmabuf
->phys
);
14071 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
14072 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
14073 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14074 /* The IOCTL status is embedded in the mailbox subheader. */
14075 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
14076 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14077 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14078 if (shdr_status
|| shdr_add_status
|| rc
) {
14082 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
14083 if (drq
->queue_id
== 0xFFFF) {
14087 drq
->type
= LPFC_DRQ
;
14088 drq
->assoc_qid
= cq
->queue_id
;
14089 drq
->subtype
= subtype
;
14090 drq
->host_index
= 0;
14091 drq
->hba_index
= 0;
14093 /* link the header and data RQs onto the parent cq child list */
14094 list_add_tail(&hrq
->list
, &cq
->child_list
);
14095 list_add_tail(&drq
->list
, &cq
->child_list
);
14098 mempool_free(mbox
, phba
->mbox_mem_pool
);
14103 * lpfc_eq_destroy - Destroy an event Queue on the HBA
14104 * @eq: The queue structure associated with the queue to destroy.
14106 * This function destroys a queue, as detailed in @eq by sending an mailbox
14107 * command, specific to the type of queue, to the HBA.
14109 * The @eq struct is used to get the queue ID of the queue to destroy.
14111 * On success this function will return a zero. If the queue destroy mailbox
14112 * command fails this function will return -ENXIO.
14115 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
14117 LPFC_MBOXQ_t
*mbox
;
14118 int rc
, length
, status
= 0;
14119 uint32_t shdr_status
, shdr_add_status
;
14120 union lpfc_sli4_cfg_shdr
*shdr
;
14122 /* sanity check on queue memory */
14125 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14128 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
14129 sizeof(struct lpfc_sli4_cfg_mhdr
));
14130 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14131 LPFC_MBOX_OPCODE_EQ_DESTROY
,
14132 length
, LPFC_SLI4_MBX_EMBED
);
14133 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
14135 mbox
->vport
= eq
->phba
->pport
;
14136 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14138 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
14139 /* The IOCTL status is embedded in the mailbox subheader. */
14140 shdr
= (union lpfc_sli4_cfg_shdr
*)
14141 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
14142 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14143 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14144 if (shdr_status
|| shdr_add_status
|| rc
) {
14145 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14146 "2505 EQ_DESTROY mailbox failed with "
14147 "status x%x add_status x%x, mbx status x%x\n",
14148 shdr_status
, shdr_add_status
, rc
);
14152 /* Remove eq from any list */
14153 list_del_init(&eq
->list
);
14154 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
14159 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
14160 * @cq: The queue structure associated with the queue to destroy.
14162 * This function destroys a queue, as detailed in @cq by sending an mailbox
14163 * command, specific to the type of queue, to the HBA.
14165 * The @cq struct is used to get the queue ID of the queue to destroy.
14167 * On success this function will return a zero. If the queue destroy mailbox
14168 * command fails this function will return -ENXIO.
14171 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
14173 LPFC_MBOXQ_t
*mbox
;
14174 int rc
, length
, status
= 0;
14175 uint32_t shdr_status
, shdr_add_status
;
14176 union lpfc_sli4_cfg_shdr
*shdr
;
14178 /* sanity check on queue memory */
14181 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14184 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
14185 sizeof(struct lpfc_sli4_cfg_mhdr
));
14186 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14187 LPFC_MBOX_OPCODE_CQ_DESTROY
,
14188 length
, LPFC_SLI4_MBX_EMBED
);
14189 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
14191 mbox
->vport
= cq
->phba
->pport
;
14192 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14193 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
14194 /* The IOCTL status is embedded in the mailbox subheader. */
14195 shdr
= (union lpfc_sli4_cfg_shdr
*)
14196 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
14197 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14198 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14199 if (shdr_status
|| shdr_add_status
|| rc
) {
14200 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14201 "2506 CQ_DESTROY mailbox failed with "
14202 "status x%x add_status x%x, mbx status x%x\n",
14203 shdr_status
, shdr_add_status
, rc
);
14206 /* Remove cq from any list */
14207 list_del_init(&cq
->list
);
14208 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
14213 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
14214 * @qm: The queue structure associated with the queue to destroy.
14216 * This function destroys a queue, as detailed in @mq by sending an mailbox
14217 * command, specific to the type of queue, to the HBA.
14219 * The @mq struct is used to get the queue ID of the queue to destroy.
14221 * On success this function will return a zero. If the queue destroy mailbox
14222 * command fails this function will return -ENXIO.
14225 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
14227 LPFC_MBOXQ_t
*mbox
;
14228 int rc
, length
, status
= 0;
14229 uint32_t shdr_status
, shdr_add_status
;
14230 union lpfc_sli4_cfg_shdr
*shdr
;
14232 /* sanity check on queue memory */
14235 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14238 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
14239 sizeof(struct lpfc_sli4_cfg_mhdr
));
14240 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
14241 LPFC_MBOX_OPCODE_MQ_DESTROY
,
14242 length
, LPFC_SLI4_MBX_EMBED
);
14243 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
14245 mbox
->vport
= mq
->phba
->pport
;
14246 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14247 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
14248 /* The IOCTL status is embedded in the mailbox subheader. */
14249 shdr
= (union lpfc_sli4_cfg_shdr
*)
14250 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
14251 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14252 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14253 if (shdr_status
|| shdr_add_status
|| rc
) {
14254 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14255 "2507 MQ_DESTROY mailbox failed with "
14256 "status x%x add_status x%x, mbx status x%x\n",
14257 shdr_status
, shdr_add_status
, rc
);
14260 /* Remove mq from any list */
14261 list_del_init(&mq
->list
);
14262 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
14267 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
14268 * @wq: The queue structure associated with the queue to destroy.
14270 * This function destroys a queue, as detailed in @wq by sending an mailbox
14271 * command, specific to the type of queue, to the HBA.
14273 * The @wq struct is used to get the queue ID of the queue to destroy.
14275 * On success this function will return a zero. If the queue destroy mailbox
14276 * command fails this function will return -ENXIO.
14279 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
14281 LPFC_MBOXQ_t
*mbox
;
14282 int rc
, length
, status
= 0;
14283 uint32_t shdr_status
, shdr_add_status
;
14284 union lpfc_sli4_cfg_shdr
*shdr
;
14286 /* sanity check on queue memory */
14289 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14292 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
14293 sizeof(struct lpfc_sli4_cfg_mhdr
));
14294 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14295 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
14296 length
, LPFC_SLI4_MBX_EMBED
);
14297 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
14299 mbox
->vport
= wq
->phba
->pport
;
14300 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14301 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
14302 shdr
= (union lpfc_sli4_cfg_shdr
*)
14303 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
14304 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14305 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14306 if (shdr_status
|| shdr_add_status
|| rc
) {
14307 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14308 "2508 WQ_DESTROY mailbox failed with "
14309 "status x%x add_status x%x, mbx status x%x\n",
14310 shdr_status
, shdr_add_status
, rc
);
14313 /* Remove wq from any list */
14314 list_del_init(&wq
->list
);
14315 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
14320 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
14321 * @rq: The queue structure associated with the queue to destroy.
14323 * This function destroys a queue, as detailed in @rq by sending an mailbox
14324 * command, specific to the type of queue, to the HBA.
14326 * The @rq struct is used to get the queue ID of the queue to destroy.
14328 * On success this function will return a zero. If the queue destroy mailbox
14329 * command fails this function will return -ENXIO.
14332 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
14333 struct lpfc_queue
*drq
)
14335 LPFC_MBOXQ_t
*mbox
;
14336 int rc
, length
, status
= 0;
14337 uint32_t shdr_status
, shdr_add_status
;
14338 union lpfc_sli4_cfg_shdr
*shdr
;
14340 /* sanity check on queue memory */
14343 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
14346 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
14347 sizeof(struct lpfc_sli4_cfg_mhdr
));
14348 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14349 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
14350 length
, LPFC_SLI4_MBX_EMBED
);
14351 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
14353 mbox
->vport
= hrq
->phba
->pport
;
14354 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
14355 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
14356 /* The IOCTL status is embedded in the mailbox subheader. */
14357 shdr
= (union lpfc_sli4_cfg_shdr
*)
14358 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
14359 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14360 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14361 if (shdr_status
|| shdr_add_status
|| rc
) {
14362 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14363 "2509 RQ_DESTROY mailbox failed with "
14364 "status x%x add_status x%x, mbx status x%x\n",
14365 shdr_status
, shdr_add_status
, rc
);
14366 if (rc
!= MBX_TIMEOUT
)
14367 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
14370 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
14372 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
14373 shdr
= (union lpfc_sli4_cfg_shdr
*)
14374 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
14375 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14376 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14377 if (shdr_status
|| shdr_add_status
|| rc
) {
14378 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14379 "2510 RQ_DESTROY mailbox failed with "
14380 "status x%x add_status x%x, mbx status x%x\n",
14381 shdr_status
, shdr_add_status
, rc
);
14384 list_del_init(&hrq
->list
);
14385 list_del_init(&drq
->list
);
14386 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
14391 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
14392 * @phba: The virtual port for which this call being executed.
14393 * @pdma_phys_addr0: Physical address of the 1st SGL page.
14394 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
14395 * @xritag: the xritag that ties this io to the SGL pages.
14397 * This routine will post the sgl pages for the IO that has the xritag
14398 * that is in the iocbq structure. The xritag is assigned during iocbq
14399 * creation and persists for as long as the driver is loaded.
14400 * if the caller has fewer than 256 scatter gather segments to map then
14401 * pdma_phys_addr1 should be 0.
14402 * If the caller needs to map more than 256 scatter gather segment then
14403 * pdma_phys_addr1 should be a valid physical address.
14404 * physical address for SGLs must be 64 byte aligned.
14405 * If you are going to map 2 SGL's then the first one must have 256 entries
14406 * the second sgl can have between 1 and 256 entries.
14410 * -ENXIO, -ENOMEM - Failure
14413 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
14414 dma_addr_t pdma_phys_addr0
,
14415 dma_addr_t pdma_phys_addr1
,
14418 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
14419 LPFC_MBOXQ_t
*mbox
;
14421 uint32_t shdr_status
, shdr_add_status
;
14423 union lpfc_sli4_cfg_shdr
*shdr
;
14425 if (xritag
== NO_XRI
) {
14426 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14427 "0364 Invalid param:\n");
14431 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14435 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14436 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
14437 sizeof(struct lpfc_mbx_post_sgl_pages
) -
14438 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
14440 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
14441 &mbox
->u
.mqe
.un
.post_sgl_pages
;
14442 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
14443 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
14445 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
14446 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
14447 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
14448 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
14450 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
14451 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
14452 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
14453 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
14454 if (!phba
->sli4_hba
.intr_enable
)
14455 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14457 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14458 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14460 /* The IOCTL status is embedded in the mailbox subheader. */
14461 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
14462 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14463 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14464 if (rc
!= MBX_TIMEOUT
)
14465 mempool_free(mbox
, phba
->mbox_mem_pool
);
14466 if (shdr_status
|| shdr_add_status
|| rc
) {
14467 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14468 "2511 POST_SGL mailbox failed with "
14469 "status x%x add_status x%x, mbx status x%x\n",
14470 shdr_status
, shdr_add_status
, rc
);
14476 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
14477 * @phba: pointer to lpfc hba data structure.
14479 * This routine is invoked to post rpi header templates to the
14480 * HBA consistent with the SLI-4 interface spec. This routine
14481 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14482 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14485 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14486 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14489 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
14494 * Fetch the next logical xri. Because this index is logical,
14495 * the driver starts at 0 each time.
14497 spin_lock_irq(&phba
->hbalock
);
14498 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
14499 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
14500 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
14501 spin_unlock_irq(&phba
->hbalock
);
14504 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
14505 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
14507 spin_unlock_irq(&phba
->hbalock
);
14512 * lpfc_sli4_free_xri - Release an xri for reuse.
14513 * @phba: pointer to lpfc hba data structure.
14515 * This routine is invoked to release an xri to the pool of
14516 * available rpis maintained by the driver.
14519 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
14521 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
14522 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
14527 * lpfc_sli4_free_xri - Release an xri for reuse.
14528 * @phba: pointer to lpfc hba data structure.
14530 * This routine is invoked to release an xri to the pool of
14531 * available rpis maintained by the driver.
14534 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
14536 spin_lock_irq(&phba
->hbalock
);
14537 __lpfc_sli4_free_xri(phba
, xri
);
14538 spin_unlock_irq(&phba
->hbalock
);
14542 * lpfc_sli4_next_xritag - Get an xritag for the io
14543 * @phba: Pointer to HBA context object.
14545 * This function gets an xritag for the iocb. If there is no unused xritag
14546 * it will return 0xffff.
14547 * The function returns the allocated xritag if successful, else returns zero.
14548 * Zero is not a valid xritag.
14549 * The caller is not required to hold any lock.
14552 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
14554 uint16_t xri_index
;
14556 xri_index
= lpfc_sli4_alloc_xri(phba
);
14557 if (xri_index
== NO_XRI
)
14558 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
14559 "2004 Failed to allocate XRI.last XRITAG is %d"
14560 " Max XRI is %d, Used XRI is %d\n",
14562 phba
->sli4_hba
.max_cfg_param
.max_xri
,
14563 phba
->sli4_hba
.max_cfg_param
.xri_used
);
14568 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
14569 * @phba: pointer to lpfc hba data structure.
14570 * @post_sgl_list: pointer to els sgl entry list.
14571 * @count: number of els sgl entries on the list.
14573 * This routine is invoked to post a block of driver's sgl pages to the
14574 * HBA using non-embedded mailbox command. No Lock is held. This routine
14575 * is only called when the driver is loading and after all IO has been
14579 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
14580 struct list_head
*post_sgl_list
,
14583 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
14584 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
14585 struct sgl_page_pairs
*sgl_pg_pairs
;
14587 LPFC_MBOXQ_t
*mbox
;
14588 uint32_t reqlen
, alloclen
, pg_pairs
;
14590 uint16_t xritag_start
= 0;
14592 uint32_t shdr_status
, shdr_add_status
;
14593 union lpfc_sli4_cfg_shdr
*shdr
;
14595 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
14596 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
14597 if (reqlen
> SLI4_PAGE_SIZE
) {
14598 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
14599 "2559 Block sgl registration required DMA "
14600 "size (%d) great than a page\n", reqlen
);
14603 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14607 /* Allocate DMA memory and set up the non-embedded mailbox command */
14608 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14609 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
14610 LPFC_SLI4_MBX_NEMBED
);
14612 if (alloclen
< reqlen
) {
14613 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14614 "0285 Allocated DMA memory size (%d) is "
14615 "less than the requested DMA memory "
14616 "size (%d)\n", alloclen
, reqlen
);
14617 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14620 /* Set up the SGL pages in the non-embedded DMA pages */
14621 viraddr
= mbox
->sge_array
->addr
[0];
14622 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
14623 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
14626 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
14627 /* Set up the sge entry */
14628 sgl_pg_pairs
->sgl_pg0_addr_lo
=
14629 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
14630 sgl_pg_pairs
->sgl_pg0_addr_hi
=
14631 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
14632 sgl_pg_pairs
->sgl_pg1_addr_lo
=
14633 cpu_to_le32(putPaddrLow(0));
14634 sgl_pg_pairs
->sgl_pg1_addr_hi
=
14635 cpu_to_le32(putPaddrHigh(0));
14637 /* Keep the first xritag on the list */
14639 xritag_start
= sglq_entry
->sli4_xritag
;
14644 /* Complete initialization and perform endian conversion. */
14645 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
14646 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
14647 sgl
->word0
= cpu_to_le32(sgl
->word0
);
14648 if (!phba
->sli4_hba
.intr_enable
)
14649 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14651 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14652 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14654 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
14655 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14656 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14657 if (rc
!= MBX_TIMEOUT
)
14658 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14659 if (shdr_status
|| shdr_add_status
|| rc
) {
14660 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14661 "2513 POST_SGL_BLOCK mailbox command failed "
14662 "status x%x add_status x%x mbx status x%x\n",
14663 shdr_status
, shdr_add_status
, rc
);
14670 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
14671 * @phba: pointer to lpfc hba data structure.
14672 * @sblist: pointer to scsi buffer list.
14673 * @count: number of scsi buffers on the list.
14675 * This routine is invoked to post a block of @count scsi sgl pages from a
14676 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
14681 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
14682 struct list_head
*sblist
,
14685 struct lpfc_scsi_buf
*psb
;
14686 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
14687 struct sgl_page_pairs
*sgl_pg_pairs
;
14689 LPFC_MBOXQ_t
*mbox
;
14690 uint32_t reqlen
, alloclen
, pg_pairs
;
14692 uint16_t xritag_start
= 0;
14694 uint32_t shdr_status
, shdr_add_status
;
14695 dma_addr_t pdma_phys_bpl1
;
14696 union lpfc_sli4_cfg_shdr
*shdr
;
14698 /* Calculate the requested length of the dma memory */
14699 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
14700 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
14701 if (reqlen
> SLI4_PAGE_SIZE
) {
14702 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
14703 "0217 Block sgl registration required DMA "
14704 "size (%d) great than a page\n", reqlen
);
14707 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14709 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14710 "0283 Failed to allocate mbox cmd memory\n");
14714 /* Allocate DMA memory and set up the non-embedded mailbox command */
14715 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14716 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
14717 LPFC_SLI4_MBX_NEMBED
);
14719 if (alloclen
< reqlen
) {
14720 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14721 "2561 Allocated DMA memory size (%d) is "
14722 "less than the requested DMA memory "
14723 "size (%d)\n", alloclen
, reqlen
);
14724 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14728 /* Get the first SGE entry from the non-embedded DMA memory */
14729 viraddr
= mbox
->sge_array
->addr
[0];
14731 /* Set up the SGL pages in the non-embedded DMA pages */
14732 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
14733 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
14736 list_for_each_entry(psb
, sblist
, list
) {
14737 /* Set up the sge entry */
14738 sgl_pg_pairs
->sgl_pg0_addr_lo
=
14739 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
14740 sgl_pg_pairs
->sgl_pg0_addr_hi
=
14741 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
14742 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
14743 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
14745 pdma_phys_bpl1
= 0;
14746 sgl_pg_pairs
->sgl_pg1_addr_lo
=
14747 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
14748 sgl_pg_pairs
->sgl_pg1_addr_hi
=
14749 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
14750 /* Keep the first xritag on the list */
14752 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
14756 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
14757 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
14758 /* Perform endian conversion if necessary */
14759 sgl
->word0
= cpu_to_le32(sgl
->word0
);
14761 if (!phba
->sli4_hba
.intr_enable
)
14762 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14764 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14765 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14767 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
14768 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14769 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14770 if (rc
!= MBX_TIMEOUT
)
14771 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14772 if (shdr_status
|| shdr_add_status
|| rc
) {
14773 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14774 "2564 POST_SGL_BLOCK mailbox command failed "
14775 "status x%x add_status x%x mbx status x%x\n",
14776 shdr_status
, shdr_add_status
, rc
);
14783 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
14784 * @phba: pointer to lpfc_hba struct that the frame was received on
14785 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14787 * This function checks the fields in the @fc_hdr to see if the FC frame is a
14788 * valid type of frame that the LPFC driver will handle. This function will
14789 * return a zero if the frame is a valid frame or a non zero value when the
14790 * frame does not pass the check.
14793 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
14795 /* make rctl_names static to save stack space */
14796 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
14797 char *type_names
[] = FC_TYPE_NAMES_INIT
;
14798 struct fc_vft_header
*fc_vft_hdr
;
14799 uint32_t *header
= (uint32_t *) fc_hdr
;
14801 switch (fc_hdr
->fh_r_ctl
) {
14802 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
14803 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
14804 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
14805 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
14806 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
14807 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
14808 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
14809 case FC_RCTL_DD_CMD_STATUS
: /* command status */
14810 case FC_RCTL_ELS_REQ
: /* extended link services request */
14811 case FC_RCTL_ELS_REP
: /* extended link services reply */
14812 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
14813 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
14814 case FC_RCTL_BA_NOP
: /* basic link service NOP */
14815 case FC_RCTL_BA_ABTS
: /* basic link service abort */
14816 case FC_RCTL_BA_RMC
: /* remove connection */
14817 case FC_RCTL_BA_ACC
: /* basic accept */
14818 case FC_RCTL_BA_RJT
: /* basic reject */
14819 case FC_RCTL_BA_PRMT
:
14820 case FC_RCTL_ACK_1
: /* acknowledge_1 */
14821 case FC_RCTL_ACK_0
: /* acknowledge_0 */
14822 case FC_RCTL_P_RJT
: /* port reject */
14823 case FC_RCTL_F_RJT
: /* fabric reject */
14824 case FC_RCTL_P_BSY
: /* port busy */
14825 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
14826 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
14827 case FC_RCTL_LCR
: /* link credit reset */
14828 case FC_RCTL_END
: /* end */
14830 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
14831 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14832 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
14833 return lpfc_fc_frame_check(phba
, fc_hdr
);
14837 switch (fc_hdr
->fh_type
) {
14849 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14850 "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
14851 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
14852 rctl_names
[fc_hdr
->fh_r_ctl
], fc_hdr
->fh_r_ctl
,
14853 type_names
[fc_hdr
->fh_type
], fc_hdr
->fh_type
,
14854 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
14855 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
14856 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]),
14857 be32_to_cpu(header
[6]));
14860 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14861 "2539 Dropped frame rctl:%s type:%s\n",
14862 rctl_names
[fc_hdr
->fh_r_ctl
],
14863 type_names
[fc_hdr
->fh_type
]);
14868 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
14869 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14871 * This function processes the FC header to retrieve the VFI from the VF
14872 * header, if one exists. This function will return the VFI if one exists
14873 * or 0 if no VSAN Header exists.
14876 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
14878 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14880 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
14882 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
14886 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
14887 * @phba: Pointer to the HBA structure to search for the vport on
14888 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14889 * @fcfi: The FC Fabric ID that the frame came from
14891 * This function searches the @phba for a vport that matches the content of the
14892 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
14893 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
14894 * returns the matching vport pointer or NULL if unable to match frame to a
14897 static struct lpfc_vport
*
14898 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
14901 struct lpfc_vport
**vports
;
14902 struct lpfc_vport
*vport
= NULL
;
14904 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
14905 fc_hdr
->fh_d_id
[1] << 8 |
14906 fc_hdr
->fh_d_id
[2]);
14908 if (did
== Fabric_DID
)
14909 return phba
->pport
;
14910 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
14911 !(phba
->link_state
== LPFC_HBA_READY
))
14912 return phba
->pport
;
14914 vports
= lpfc_create_vport_work_array(phba
);
14915 if (vports
!= NULL
)
14916 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
14917 if (phba
->fcf
.fcfi
== fcfi
&&
14918 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
14919 vports
[i
]->fc_myDID
== did
) {
14924 lpfc_destroy_vport_work_array(phba
, vports
);
14929 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
14930 * @vport: The vport to work on.
14932 * This function updates the receive sequence time stamp for this vport. The
14933 * receive sequence time stamp indicates the time that the last frame of the
14934 * the sequence that has been idle for the longest amount of time was received.
14935 * the driver uses this time stamp to indicate if any received sequences have
14939 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
14941 struct lpfc_dmabuf
*h_buf
;
14942 struct hbq_dmabuf
*dmabuf
= NULL
;
14944 /* get the oldest sequence on the rcv list */
14945 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
14946 struct lpfc_dmabuf
, list
);
14949 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14950 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
14954 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
14955 * @vport: The vport that the received sequences were sent to.
14957 * This function cleans up all outstanding received sequences. This is called
14958 * by the driver when a link event or user action invalidates all the received
14962 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
14964 struct lpfc_dmabuf
*h_buf
, *hnext
;
14965 struct lpfc_dmabuf
*d_buf
, *dnext
;
14966 struct hbq_dmabuf
*dmabuf
= NULL
;
14968 /* start with the oldest sequence on the rcv list */
14969 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
14970 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14971 list_del_init(&dmabuf
->hbuf
.list
);
14972 list_for_each_entry_safe(d_buf
, dnext
,
14973 &dmabuf
->dbuf
.list
, list
) {
14974 list_del_init(&d_buf
->list
);
14975 lpfc_in_buf_free(vport
->phba
, d_buf
);
14977 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
14982 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
14983 * @vport: The vport that the received sequences were sent to.
14985 * This function determines whether any received sequences have timed out by
14986 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
14987 * indicates that there is at least one timed out sequence this routine will
14988 * go through the received sequences one at a time from most inactive to most
14989 * active to determine which ones need to be cleaned up. Once it has determined
14990 * that a sequence needs to be cleaned up it will simply free up the resources
14991 * without sending an abort.
14994 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
14996 struct lpfc_dmabuf
*h_buf
, *hnext
;
14997 struct lpfc_dmabuf
*d_buf
, *dnext
;
14998 struct hbq_dmabuf
*dmabuf
= NULL
;
14999 unsigned long timeout
;
15000 int abort_count
= 0;
15002 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
15003 vport
->rcv_buffer_time_stamp
);
15004 if (list_empty(&vport
->rcv_buffer_list
) ||
15005 time_before(jiffies
, timeout
))
15007 /* start with the oldest sequence on the rcv list */
15008 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
15009 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15010 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
15011 dmabuf
->time_stamp
);
15012 if (time_before(jiffies
, timeout
))
15015 list_del_init(&dmabuf
->hbuf
.list
);
15016 list_for_each_entry_safe(d_buf
, dnext
,
15017 &dmabuf
->dbuf
.list
, list
) {
15018 list_del_init(&d_buf
->list
);
15019 lpfc_in_buf_free(vport
->phba
, d_buf
);
15021 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
15024 lpfc_update_rcv_time_stamp(vport
);
15028 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
15029 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
15031 * This function searches through the existing incomplete sequences that have
15032 * been sent to this @vport. If the frame matches one of the incomplete
15033 * sequences then the dbuf in the @dmabuf is added to the list of frames that
15034 * make up that sequence. If no sequence is found that matches this frame then
15035 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
15036 * This function returns a pointer to the first dmabuf in the sequence list that
15037 * the frame was linked to.
15039 static struct hbq_dmabuf
*
15040 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
15042 struct fc_frame_header
*new_hdr
;
15043 struct fc_frame_header
*temp_hdr
;
15044 struct lpfc_dmabuf
*d_buf
;
15045 struct lpfc_dmabuf
*h_buf
;
15046 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
15047 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
15050 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
15051 dmabuf
->time_stamp
= jiffies
;
15052 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15054 /* Use the hdr_buf to find the sequence that this frame belongs to */
15055 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
15056 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
15057 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
15058 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
15059 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
15061 /* found a pending sequence that matches this frame */
15062 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15067 * This indicates first frame received for this sequence.
15068 * Queue the buffer on the vport's rcv_buffer_list.
15070 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
15071 lpfc_update_rcv_time_stamp(vport
);
15074 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
15075 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
15076 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
15077 list_del_init(&seq_dmabuf
->hbuf
.list
);
15078 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
15079 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
15080 lpfc_update_rcv_time_stamp(vport
);
15083 /* move this sequence to the tail to indicate a young sequence */
15084 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
15085 seq_dmabuf
->time_stamp
= jiffies
;
15086 lpfc_update_rcv_time_stamp(vport
);
15087 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
15088 temp_hdr
= dmabuf
->hbuf
.virt
;
15089 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
15092 /* find the correct place in the sequence to insert this frame */
15093 d_buf
= list_entry(seq_dmabuf
->dbuf
.list
.prev
, typeof(*d_buf
), list
);
15095 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15096 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
15098 * If the frame's sequence count is greater than the frame on
15099 * the list then insert the frame right after this frame
15101 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
15102 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
15103 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
15108 if (&d_buf
->list
== &seq_dmabuf
->dbuf
.list
)
15110 d_buf
= list_entry(d_buf
->list
.prev
, typeof(*d_buf
), list
);
15119 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
15120 * @vport: pointer to a vitural port
15121 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15123 * This function tries to abort from the partially assembed sequence, described
15124 * by the information from basic abbort @dmabuf. It checks to see whether such
15125 * partially assembled sequence held by the driver. If so, it shall free up all
15126 * the frames from the partially assembled sequence.
15129 * true -- if there is matching partially assembled sequence present and all
15130 * the frames freed with the sequence;
15131 * false -- if there is no matching partially assembled sequence present so
15132 * nothing got aborted in the lower layer driver
15135 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
15136 struct hbq_dmabuf
*dmabuf
)
15138 struct fc_frame_header
*new_hdr
;
15139 struct fc_frame_header
*temp_hdr
;
15140 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
15141 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
15143 /* Use the hdr_buf to find the sequence that matches this frame */
15144 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
15145 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
15146 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15147 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
15148 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
15149 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
15150 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
15151 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
15153 /* found a pending sequence that matches this frame */
15154 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
15158 /* Free up all the frames from the partially assembled sequence */
15160 list_for_each_entry_safe(d_buf
, n_buf
,
15161 &seq_dmabuf
->dbuf
.list
, list
) {
15162 list_del_init(&d_buf
->list
);
15163 lpfc_in_buf_free(vport
->phba
, d_buf
);
15171 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
15172 * @vport: pointer to a vitural port
15173 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15175 * This function tries to abort from the assembed sequence from upper level
15176 * protocol, described by the information from basic abbort @dmabuf. It
15177 * checks to see whether such pending context exists at upper level protocol.
15178 * If so, it shall clean up the pending context.
15181 * true -- if there is matching pending context of the sequence cleaned
15183 * false -- if there is no matching pending context of the sequence present
15187 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
15189 struct lpfc_hba
*phba
= vport
->phba
;
15192 /* Accepting abort at ulp with SLI4 only */
15193 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15196 /* Register all caring upper level protocols to attend abort */
15197 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
15205 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
15206 * @phba: Pointer to HBA context object.
15207 * @cmd_iocbq: pointer to the command iocbq structure.
15208 * @rsp_iocbq: pointer to the response iocbq structure.
15210 * This function handles the sequence abort response iocb command complete
15211 * event. It properly releases the memory allocated to the sequence abort
15215 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
15216 struct lpfc_iocbq
*cmd_iocbq
,
15217 struct lpfc_iocbq
*rsp_iocbq
)
15219 struct lpfc_nodelist
*ndlp
;
15222 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
15223 lpfc_nlp_put(ndlp
);
15224 lpfc_nlp_not_used(ndlp
);
15225 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
15228 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
15229 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
15230 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15231 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
15232 rsp_iocbq
->iocb
.ulpStatus
,
15233 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
15237 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
15238 * @phba: Pointer to HBA context object.
15239 * @xri: xri id in transaction.
15241 * This function validates the xri maps to the known range of XRIs allocated an
15242 * used by the driver.
15245 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
15250 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
15251 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
15258 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
15259 * @phba: Pointer to HBA context object.
15260 * @fc_hdr: pointer to a FC frame header.
15262 * This function sends a basic response to a previous unsol sequence abort
15263 * event after aborting the sequence handling.
15266 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
15267 struct fc_frame_header
*fc_hdr
, bool aborted
)
15269 struct lpfc_hba
*phba
= vport
->phba
;
15270 struct lpfc_iocbq
*ctiocb
= NULL
;
15271 struct lpfc_nodelist
*ndlp
;
15272 uint16_t oxid
, rxid
, xri
, lxri
;
15273 uint32_t sid
, fctl
;
15277 if (!lpfc_is_link_up(phba
))
15280 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
15281 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
15282 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
15284 ndlp
= lpfc_findnode_did(vport
, sid
);
15286 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
15288 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
15289 "1268 Failed to allocate ndlp for "
15290 "oxid:x%x SID:x%x\n", oxid
, sid
);
15293 lpfc_nlp_init(vport
, ndlp
, sid
);
15294 /* Put ndlp onto pport node list */
15295 lpfc_enqueue_node(vport
, ndlp
);
15296 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
15297 /* re-setup ndlp without removing from node list */
15298 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
15300 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
15301 "3275 Failed to active ndlp found "
15302 "for oxid:x%x SID:x%x\n", oxid
, sid
);
15307 /* Allocate buffer for rsp iocb */
15308 ctiocb
= lpfc_sli_get_iocbq(phba
);
15312 /* Extract the F_CTL field from FC_HDR */
15313 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
15315 icmd
= &ctiocb
->iocb
;
15316 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
15317 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
15318 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
15319 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
15320 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
15322 /* Fill in the rest of iocb fields */
15323 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
15324 icmd
->ulpBdeCount
= 0;
15326 icmd
->ulpClass
= CLASS3
;
15327 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
15328 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
15330 ctiocb
->iocb_cmpl
= NULL
;
15331 ctiocb
->vport
= phba
->pport
;
15332 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
15333 ctiocb
->sli4_lxritag
= NO_XRI
;
15334 ctiocb
->sli4_xritag
= NO_XRI
;
15336 if (fctl
& FC_FC_EX_CTX
)
15337 /* Exchange responder sent the abort so we
15343 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
15344 if (lxri
!= NO_XRI
)
15345 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
15346 (xri
== oxid
) ? rxid
: oxid
, 0);
15347 /* For BA_ABTS from exchange responder, if the logical xri with
15348 * the oxid maps to the FCP XRI range, the port no longer has
15349 * that exchange context, send a BLS_RJT. Override the IOCB for
15352 if ((fctl
& FC_FC_EX_CTX
) &&
15353 (lxri
> lpfc_sli4_get_els_iocb_cnt(phba
))) {
15354 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
15355 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
15356 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
15357 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
15360 /* If BA_ABTS failed to abort a partially assembled receive sequence,
15361 * the driver no longer has that exchange, send a BLS_RJT. Override
15362 * the IOCB for a BA_RJT.
15364 if (aborted
== false) {
15365 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
15366 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
15367 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
15368 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
15371 if (fctl
& FC_FC_EX_CTX
) {
15372 /* ABTS sent by responder to CT exchange, construction
15373 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
15374 * field and RX_ID from ABTS for RX_ID field.
15376 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
15378 /* ABTS sent by initiator to CT exchange, construction
15379 * of BA_ACC will need to allocate a new XRI as for the
15382 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
15384 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
15385 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
15387 /* Xmit CT abts response on exchange <xid> */
15388 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
15389 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
15390 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
15392 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
15393 if (rc
== IOCB_ERROR
) {
15394 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
15395 "2925 Failed to issue CT ABTS RSP x%x on "
15396 "xri x%x, Data x%x\n",
15397 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
15399 lpfc_nlp_put(ndlp
);
15400 ctiocb
->context1
= NULL
;
15401 lpfc_sli_release_iocbq(phba
, ctiocb
);
15406 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
15407 * @vport: Pointer to the vport on which this sequence was received
15408 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15410 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
15411 * receive sequence is only partially assembed by the driver, it shall abort
15412 * the partially assembled frames for the sequence. Otherwise, if the
15413 * unsolicited receive sequence has been completely assembled and passed to
15414 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
15415 * unsolicited sequence has been aborted. After that, it will issue a basic
15416 * accept to accept the abort.
15419 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
15420 struct hbq_dmabuf
*dmabuf
)
15422 struct lpfc_hba
*phba
= vport
->phba
;
15423 struct fc_frame_header fc_hdr
;
15427 /* Make a copy of fc_hdr before the dmabuf being released */
15428 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
15429 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
15431 if (fctl
& FC_FC_EX_CTX
) {
15432 /* ABTS by responder to exchange, no cleanup needed */
15435 /* ABTS by initiator to exchange, need to do cleanup */
15436 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
15437 if (aborted
== false)
15438 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
15440 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15442 /* Respond with BA_ACC or BA_RJT accordingly */
15443 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
15447 * lpfc_seq_complete - Indicates if a sequence is complete
15448 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15450 * This function checks the sequence, starting with the frame described by
15451 * @dmabuf, to see if all the frames associated with this sequence are present.
15452 * the frames associated with this sequence are linked to the @dmabuf using the
15453 * dbuf list. This function looks for two major things. 1) That the first frame
15454 * has a sequence count of zero. 2) There is a frame with last frame of sequence
15455 * set. 3) That there are no holes in the sequence count. The function will
15456 * return 1 when the sequence is complete, otherwise it will return 0.
15459 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
15461 struct fc_frame_header
*hdr
;
15462 struct lpfc_dmabuf
*d_buf
;
15463 struct hbq_dmabuf
*seq_dmabuf
;
15467 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15468 /* make sure first fame of sequence has a sequence count of zero */
15469 if (hdr
->fh_seq_cnt
!= seq_count
)
15471 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
15472 hdr
->fh_f_ctl
[1] << 8 |
15474 /* If last frame of sequence we can return success. */
15475 if (fctl
& FC_FC_END_SEQ
)
15477 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
15478 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15479 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15480 /* If there is a hole in the sequence count then fail. */
15481 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
15483 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
15484 hdr
->fh_f_ctl
[1] << 8 |
15486 /* If last frame of sequence we can return success. */
15487 if (fctl
& FC_FC_END_SEQ
)
15494 * lpfc_prep_seq - Prep sequence for ULP processing
15495 * @vport: Pointer to the vport on which this sequence was received
15496 * @dmabuf: pointer to a dmabuf that describes the FC sequence
15498 * This function takes a sequence, described by a list of frames, and creates
15499 * a list of iocbq structures to describe the sequence. This iocbq list will be
15500 * used to issue to the generic unsolicited sequence handler. This routine
15501 * returns a pointer to the first iocbq in the list. If the function is unable
15502 * to allocate an iocbq then it throw out the received frames that were not
15503 * able to be described and return a pointer to the first iocbq. If unable to
15504 * allocate any iocbqs (including the first) this function will return NULL.
15506 static struct lpfc_iocbq
*
15507 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
15509 struct hbq_dmabuf
*hbq_buf
;
15510 struct lpfc_dmabuf
*d_buf
, *n_buf
;
15511 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
15512 struct fc_frame_header
*fc_hdr
;
15514 uint32_t len
, tot_len
;
15515 struct ulp_bde64
*pbde
;
15517 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15518 /* remove from receive buffer list */
15519 list_del_init(&seq_dmabuf
->hbuf
.list
);
15520 lpfc_update_rcv_time_stamp(vport
);
15521 /* get the Remote Port's SID */
15522 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
15524 /* Get an iocbq struct to fill in. */
15525 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
15527 /* Initialize the first IOCB. */
15528 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
15529 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
15531 /* Check FC Header to see what TYPE of frame we are rcv'ing */
15532 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
15533 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
15534 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
15535 sli4_did_from_fc_hdr(fc_hdr
);
15536 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
15538 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
15539 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
15540 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
15541 be16_to_cpu(fc_hdr
->fh_ox_id
);
15542 /* iocbq is prepped for internal consumption. Physical vpi. */
15543 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
15544 vport
->phba
->vpi_ids
[vport
->vpi
];
15545 /* put the first buffer into the first IOCBq */
15546 tot_len
= bf_get(lpfc_rcqe_length
,
15547 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15549 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
15550 first_iocbq
->context3
= NULL
;
15551 first_iocbq
->iocb
.ulpBdeCount
= 1;
15552 if (tot_len
> LPFC_DATA_BUF_SIZE
)
15553 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
15554 LPFC_DATA_BUF_SIZE
;
15556 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= tot_len
;
15558 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
15560 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
15562 iocbq
= first_iocbq
;
15564 * Each IOCBq can have two Buffers assigned, so go through the list
15565 * of buffers for this sequence and save two buffers in each IOCBq
15567 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
15569 lpfc_in_buf_free(vport
->phba
, d_buf
);
15572 if (!iocbq
->context3
) {
15573 iocbq
->context3
= d_buf
;
15574 iocbq
->iocb
.ulpBdeCount
++;
15575 /* We need to get the size out of the right CQE */
15576 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15577 len
= bf_get(lpfc_rcqe_length
,
15578 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
15579 pbde
= (struct ulp_bde64
*)
15580 &iocbq
->iocb
.unsli3
.sli3Words
[4];
15581 if (len
> LPFC_DATA_BUF_SIZE
)
15582 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
15584 pbde
->tus
.f
.bdeSize
= len
;
15586 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
15589 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
15592 first_iocbq
->iocb
.ulpStatus
=
15593 IOSTAT_FCP_RSP_ERROR
;
15594 first_iocbq
->iocb
.un
.ulpWord
[4] =
15595 IOERR_NO_RESOURCES
;
15597 lpfc_in_buf_free(vport
->phba
, d_buf
);
15600 /* We need to get the size out of the right CQE */
15601 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
15602 len
= bf_get(lpfc_rcqe_length
,
15603 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
15604 iocbq
->context2
= d_buf
;
15605 iocbq
->context3
= NULL
;
15606 iocbq
->iocb
.ulpBdeCount
= 1;
15607 if (len
> LPFC_DATA_BUF_SIZE
)
15608 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
15609 LPFC_DATA_BUF_SIZE
;
15611 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= len
;
15614 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
15616 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
15617 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
15620 return first_iocbq
;
15624 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
15625 struct hbq_dmabuf
*seq_dmabuf
)
15627 struct fc_frame_header
*fc_hdr
;
15628 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
15629 struct lpfc_hba
*phba
= vport
->phba
;
15631 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15632 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
15634 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15635 "2707 Ring %d handler: Failed to allocate "
15636 "iocb Rctl x%x Type x%x received\n",
15638 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
15641 if (!lpfc_complete_unsol_iocb(phba
,
15642 &phba
->sli
.ring
[LPFC_ELS_RING
],
15643 iocbq
, fc_hdr
->fh_r_ctl
,
15645 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15646 "2540 Ring %d handler: unexpected Rctl "
15647 "x%x Type x%x received\n",
15649 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
15651 /* Free iocb created in lpfc_prep_seq */
15652 list_for_each_entry_safe(curr_iocb
, next_iocb
,
15653 &iocbq
->list
, list
) {
15654 list_del_init(&curr_iocb
->list
);
15655 lpfc_sli_release_iocbq(phba
, curr_iocb
);
15657 lpfc_sli_release_iocbq(phba
, iocbq
);
15661 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
15662 * @phba: Pointer to HBA context object.
15664 * This function is called with no lock held. This function processes all
15665 * the received buffers and gives it to upper layers when a received buffer
15666 * indicates that it is the final frame in the sequence. The interrupt
15667 * service routine processes received buffers at interrupt contexts and adds
15668 * received dma buffers to the rb_pend_list queue and signals the worker thread.
15669 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
15670 * appropriate receive function when the final frame in a sequence is received.
15673 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
15674 struct hbq_dmabuf
*dmabuf
)
15676 struct hbq_dmabuf
*seq_dmabuf
;
15677 struct fc_frame_header
*fc_hdr
;
15678 struct lpfc_vport
*vport
;
15682 /* Process each received buffer */
15683 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15684 /* check to see if this a valid type of frame */
15685 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
15686 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15689 if ((bf_get(lpfc_cqe_code
,
15690 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
15691 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
15692 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15694 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
15695 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15697 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
15699 /* throw out the frame */
15700 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15704 /* d_id this frame is directed to */
15705 did
= sli4_did_from_fc_hdr(fc_hdr
);
15707 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
15708 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
15709 (did
!= Fabric_DID
)) {
15711 * Throw out the frame if we are not pt2pt.
15712 * The pt2pt protocol allows for discovery frames
15713 * to be received without a registered VPI.
15715 if (!(vport
->fc_flag
& FC_PT2PT
) ||
15716 (phba
->link_state
== LPFC_HBA_READY
)) {
15717 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15722 /* Handle the basic abort sequence (BA_ABTS) event */
15723 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
15724 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
15728 /* Link this frame */
15729 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
15731 /* unable to add frame to vport - throw it out */
15732 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15735 /* If not last frame in sequence continue processing frames. */
15736 if (!lpfc_seq_complete(seq_dmabuf
))
15739 /* Send the complete sequence to the upper layer protocol */
15740 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
15744 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
15745 * @phba: pointer to lpfc hba data structure.
15747 * This routine is invoked to post rpi header templates to the
15748 * HBA consistent with the SLI-4 interface spec. This routine
15749 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15750 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15752 * This routine does not require any locks. It's usage is expected
15753 * to be driver load or reset recovery when the driver is
15758 * -EIO - The mailbox failed to complete successfully.
15759 * When this error occurs, the driver is not guaranteed
15760 * to have any rpi regions posted to the device and
15761 * must either attempt to repost the regions or take a
15765 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
15767 struct lpfc_rpi_hdr
*rpi_page
;
15771 /* SLI4 ports that support extents do not require RPI headers. */
15772 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
15774 if (phba
->sli4_hba
.extents_in_use
)
15777 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
15779 * Assign the rpi headers a physical rpi only if the driver
15780 * has not initialized those resources. A port reset only
15781 * needs the headers posted.
15783 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
15785 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15787 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
15788 if (rc
!= MBX_SUCCESS
) {
15789 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15790 "2008 Error %d posting all rpi "
15798 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
15799 LPFC_RPI_RSRC_RDY
);
15804 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
15805 * @phba: pointer to lpfc hba data structure.
15806 * @rpi_page: pointer to the rpi memory region.
15808 * This routine is invoked to post a single rpi header to the
15809 * HBA consistent with the SLI-4 interface spec. This memory region
15810 * maps up to 64 rpi context regions.
15814 * -ENOMEM - No available memory
15815 * -EIO - The mailbox failed to complete successfully.
15818 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
15820 LPFC_MBOXQ_t
*mboxq
;
15821 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
15823 uint32_t shdr_status
, shdr_add_status
;
15824 union lpfc_sli4_cfg_shdr
*shdr
;
15826 /* SLI4 ports that support extents do not require RPI headers. */
15827 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
15829 if (phba
->sli4_hba
.extents_in_use
)
15832 /* The port is notified of the header region via a mailbox command. */
15833 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15835 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15836 "2001 Unable to allocate memory for issuing "
15837 "SLI_CONFIG_SPECIAL mailbox command\n");
15841 /* Post all rpi memory regions to the port. */
15842 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
15843 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15844 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
15845 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
15846 sizeof(struct lpfc_sli4_cfg_mhdr
),
15847 LPFC_SLI4_MBX_EMBED
);
15850 /* Post the physical rpi to the port for this rpi header. */
15851 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
15852 rpi_page
->start_rpi
);
15853 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
15854 hdr_tmpl
, rpi_page
->page_count
);
15856 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
15857 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
15858 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15859 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
15860 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15861 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15862 if (rc
!= MBX_TIMEOUT
)
15863 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15864 if (shdr_status
|| shdr_add_status
|| rc
) {
15865 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15866 "2514 POST_RPI_HDR mailbox failed with "
15867 "status x%x add_status x%x, mbx status x%x\n",
15868 shdr_status
, shdr_add_status
, rc
);
15875 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
15876 * @phba: pointer to lpfc hba data structure.
15878 * This routine is invoked to post rpi header templates to the
15879 * HBA consistent with the SLI-4 interface spec. This routine
15880 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15881 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15884 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
15885 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15888 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
15891 uint16_t max_rpi
, rpi_limit
;
15892 uint16_t rpi_remaining
, lrpi
= 0;
15893 struct lpfc_rpi_hdr
*rpi_hdr
;
15894 unsigned long iflag
;
15897 * Fetch the next logical rpi. Because this index is logical,
15898 * the driver starts at 0 each time.
15900 spin_lock_irqsave(&phba
->hbalock
, iflag
);
15901 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
15902 rpi_limit
= phba
->sli4_hba
.next_rpi
;
15904 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
15905 if (rpi
>= rpi_limit
)
15906 rpi
= LPFC_RPI_ALLOC_ERROR
;
15908 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
15909 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
15910 phba
->sli4_hba
.rpi_count
++;
15912 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
15913 "0001 rpi:%x max:%x lim:%x\n",
15914 (int) rpi
, max_rpi
, rpi_limit
);
15917 * Don't try to allocate more rpi header regions if the device limit
15918 * has been exhausted.
15920 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
15921 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
15922 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15927 * RPI header postings are not required for SLI4 ports capable of
15930 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
15931 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15936 * If the driver is running low on rpi resources, allocate another
15937 * page now. Note that the next_rpi value is used because
15938 * it represents how many are actually in use whereas max_rpi notes
15939 * how many are supported max by the device.
15941 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
15942 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15943 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
15944 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
15946 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15947 "2002 Error Could not grow rpi "
15950 lrpi
= rpi_hdr
->start_rpi
;
15951 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15952 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
15960 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15961 * @phba: pointer to lpfc hba data structure.
15963 * This routine is invoked to release an rpi to the pool of
15964 * available rpis maintained by the driver.
15967 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
15969 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
15970 phba
->sli4_hba
.rpi_count
--;
15971 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
15976 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15977 * @phba: pointer to lpfc hba data structure.
15979 * This routine is invoked to release an rpi to the pool of
15980 * available rpis maintained by the driver.
15983 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
15985 spin_lock_irq(&phba
->hbalock
);
15986 __lpfc_sli4_free_rpi(phba
, rpi
);
15987 spin_unlock_irq(&phba
->hbalock
);
15991 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
15992 * @phba: pointer to lpfc hba data structure.
15994 * This routine is invoked to remove the memory region that
15995 * provided rpi via a bitmask.
15998 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
16000 kfree(phba
->sli4_hba
.rpi_bmask
);
16001 kfree(phba
->sli4_hba
.rpi_ids
);
16002 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
16006 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
16007 * @phba: pointer to lpfc hba data structure.
16009 * This routine is invoked to remove the memory region that
16010 * provided rpi via a bitmask.
16013 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
16014 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
16016 LPFC_MBOXQ_t
*mboxq
;
16017 struct lpfc_hba
*phba
= ndlp
->phba
;
16020 /* The port is notified of the header region via a mailbox command. */
16021 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16025 /* Post all rpi memory regions to the port. */
16026 lpfc_resume_rpi(mboxq
, ndlp
);
16028 mboxq
->mbox_cmpl
= cmpl
;
16029 mboxq
->context1
= arg
;
16030 mboxq
->context2
= ndlp
;
16032 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16033 mboxq
->vport
= ndlp
->vport
;
16034 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16035 if (rc
== MBX_NOT_FINISHED
) {
16036 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16037 "2010 Resume RPI Mailbox failed "
16038 "status %d, mbxStatus x%x\n", rc
,
16039 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
16040 mempool_free(mboxq
, phba
->mbox_mem_pool
);
16047 * lpfc_sli4_init_vpi - Initialize a vpi with the port
16048 * @vport: Pointer to the vport for which the vpi is being initialized
16050 * This routine is invoked to activate a vpi with the port.
16054 * -Evalue otherwise
16057 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
16059 LPFC_MBOXQ_t
*mboxq
;
16061 int retval
= MBX_SUCCESS
;
16063 struct lpfc_hba
*phba
= vport
->phba
;
16064 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16067 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
16068 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
16069 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
16070 if (rc
!= MBX_SUCCESS
) {
16071 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
16072 "2022 INIT VPI Mailbox failed "
16073 "status %d, mbxStatus x%x\n", rc
,
16074 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
16077 if (rc
!= MBX_TIMEOUT
)
16078 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
16084 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
16085 * @phba: pointer to lpfc hba data structure.
16086 * @mboxq: Pointer to mailbox object.
16088 * This routine is invoked to manually add a single FCF record. The caller
16089 * must pass a completely initialized FCF_Record. This routine takes
16090 * care of the nonembedded mailbox operations.
16093 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
16096 union lpfc_sli4_cfg_shdr
*shdr
;
16097 uint32_t shdr_status
, shdr_add_status
;
16099 virt_addr
= mboxq
->sge_array
->addr
[0];
16100 /* The IOCTL status is embedded in the mailbox subheader. */
16101 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
16102 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16103 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16105 if ((shdr_status
|| shdr_add_status
) &&
16106 (shdr_status
!= STATUS_FCF_IN_USE
))
16107 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16108 "2558 ADD_FCF_RECORD mailbox failed with "
16109 "status x%x add_status x%x\n",
16110 shdr_status
, shdr_add_status
);
16112 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16116 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
16117 * @phba: pointer to lpfc hba data structure.
16118 * @fcf_record: pointer to the initialized fcf record to add.
16120 * This routine is invoked to manually add a single FCF record. The caller
16121 * must pass a completely initialized FCF_Record. This routine takes
16122 * care of the nonembedded mailbox operations.
16125 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
16128 LPFC_MBOXQ_t
*mboxq
;
16131 struct lpfc_mbx_sge sge
;
16132 uint32_t alloc_len
, req_len
;
16135 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16137 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16138 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
16142 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
16145 /* Allocate DMA memory and set up the non-embedded mailbox command */
16146 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16147 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
16148 req_len
, LPFC_SLI4_MBX_NEMBED
);
16149 if (alloc_len
< req_len
) {
16150 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16151 "2523 Allocated DMA memory size (x%x) is "
16152 "less than the requested DMA memory "
16153 "size (x%x)\n", alloc_len
, req_len
);
16154 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16159 * Get the first SGE entry from the non-embedded DMA memory. This
16160 * routine only uses a single SGE.
16162 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
16163 virt_addr
= mboxq
->sge_array
->addr
[0];
16165 * Configure the FCF record for FCFI 0. This is the driver's
16166 * hardcoded default and gets used in nonFIP mode.
16168 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
16169 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
16170 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
16173 * Copy the fcf_index and the FCF Record Data. The data starts after
16174 * the FCoE header plus word10. The data copy needs to be endian
16177 bytep
+= sizeof(uint32_t);
16178 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
16179 mboxq
->vport
= phba
->pport
;
16180 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
16181 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16182 if (rc
== MBX_NOT_FINISHED
) {
16183 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16184 "2515 ADD_FCF_RECORD mailbox failed with "
16185 "status 0x%x\n", rc
);
16186 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16195 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
16196 * @phba: pointer to lpfc hba data structure.
16197 * @fcf_record: pointer to the fcf record to write the default data.
16198 * @fcf_index: FCF table entry index.
16200 * This routine is invoked to build the driver's default FCF record. The
16201 * values used are hardcoded. This routine handles memory initialization.
16205 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
16206 struct fcf_record
*fcf_record
,
16207 uint16_t fcf_index
)
16209 memset(fcf_record
, 0, sizeof(struct fcf_record
));
16210 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
16211 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
16212 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
16213 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
16214 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
16215 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
16216 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
16217 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
16218 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
16219 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
16220 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
16221 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
16222 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
16223 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
16224 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
16225 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
16226 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
16227 /* Set the VLAN bit map */
16228 if (phba
->valid_vlan
) {
16229 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
16230 = 1 << (phba
->vlan_id
% 8);
16235 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
16236 * @phba: pointer to lpfc hba data structure.
16237 * @fcf_index: FCF table entry offset.
16239 * This routine is invoked to scan the entire FCF table by reading FCF
16240 * record and processing it one at a time starting from the @fcf_index
16241 * for initial FCF discovery or fast FCF failover rediscovery.
16243 * Return 0 if the mailbox command is submitted successfully, none 0
16247 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16250 LPFC_MBOXQ_t
*mboxq
;
16252 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
16253 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
16254 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16256 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16257 "2000 Failed to allocate mbox for "
16260 goto fail_fcf_scan
;
16262 /* Construct the read FCF record mailbox command */
16263 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
16266 goto fail_fcf_scan
;
16268 /* Issue the mailbox command asynchronously */
16269 mboxq
->vport
= phba
->pport
;
16270 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
16272 spin_lock_irq(&phba
->hbalock
);
16273 phba
->hba_flag
|= FCF_TS_INPROG
;
16274 spin_unlock_irq(&phba
->hbalock
);
16276 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16277 if (rc
== MBX_NOT_FINISHED
)
16280 /* Reset eligible FCF count for new scan */
16281 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
16282 phba
->fcf
.eligible_fcf_cnt
= 0;
16288 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16289 /* FCF scan failed, clear FCF_TS_INPROG flag */
16290 spin_lock_irq(&phba
->hbalock
);
16291 phba
->hba_flag
&= ~FCF_TS_INPROG
;
16292 spin_unlock_irq(&phba
->hbalock
);
16298 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
16299 * @phba: pointer to lpfc hba data structure.
16300 * @fcf_index: FCF table entry offset.
16302 * This routine is invoked to read an FCF record indicated by @fcf_index
16303 * and to use it for FLOGI roundrobin FCF failover.
16305 * Return 0 if the mailbox command is submitted successfully, none 0
16309 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16312 LPFC_MBOXQ_t
*mboxq
;
16314 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16316 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
16317 "2763 Failed to allocate mbox for "
16320 goto fail_fcf_read
;
16322 /* Construct the read FCF record mailbox command */
16323 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
16326 goto fail_fcf_read
;
16328 /* Issue the mailbox command asynchronously */
16329 mboxq
->vport
= phba
->pport
;
16330 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
16331 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16332 if (rc
== MBX_NOT_FINISHED
)
16338 if (error
&& mboxq
)
16339 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16344 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
16345 * @phba: pointer to lpfc hba data structure.
16346 * @fcf_index: FCF table entry offset.
16348 * This routine is invoked to read an FCF record indicated by @fcf_index to
16349 * determine whether it's eligible for FLOGI roundrobin failover list.
16351 * Return 0 if the mailbox command is submitted successfully, none 0
16355 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16358 LPFC_MBOXQ_t
*mboxq
;
16360 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16362 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
16363 "2758 Failed to allocate mbox for "
16366 goto fail_fcf_read
;
16368 /* Construct the read FCF record mailbox command */
16369 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
16372 goto fail_fcf_read
;
16374 /* Issue the mailbox command asynchronously */
16375 mboxq
->vport
= phba
->pport
;
16376 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
16377 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
16378 if (rc
== MBX_NOT_FINISHED
)
16384 if (error
&& mboxq
)
16385 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
16390 * lpfc_check_next_fcf_pri_level
16391 * phba pointer to the lpfc_hba struct for this port.
16392 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
16393 * routine when the rr_bmask is empty. The FCF indecies are put into the
16394 * rr_bmask based on their priority level. Starting from the highest priority
16395 * to the lowest. The most likely FCF candidate will be in the highest
16396 * priority group. When this routine is called it searches the fcf_pri list for
16397 * next lowest priority group and repopulates the rr_bmask with only those
16400 * 1=success 0=failure
16403 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
16405 uint16_t next_fcf_pri
;
16406 uint16_t last_index
;
16407 struct lpfc_fcf_pri
*fcf_pri
;
16411 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
16412 LPFC_SLI4_FCF_TBL_INDX_MAX
);
16413 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16414 "3060 Last IDX %d\n", last_index
);
16416 /* Verify the priority list has 2 or more entries */
16417 spin_lock_irq(&phba
->hbalock
);
16418 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
16419 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
16420 spin_unlock_irq(&phba
->hbalock
);
16421 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16422 "3061 Last IDX %d\n", last_index
);
16423 return 0; /* Empty rr list */
16425 spin_unlock_irq(&phba
->hbalock
);
16429 * Clear the rr_bmask and set all of the bits that are at this
16432 memset(phba
->fcf
.fcf_rr_bmask
, 0,
16433 sizeof(*phba
->fcf
.fcf_rr_bmask
));
16434 spin_lock_irq(&phba
->hbalock
);
16435 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
16436 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
16439 * the 1st priority that has not FLOGI failed
16440 * will be the highest.
16443 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
16444 spin_unlock_irq(&phba
->hbalock
);
16445 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
16446 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
16447 fcf_pri
->fcf_rec
.fcf_index
);
16451 spin_lock_irq(&phba
->hbalock
);
16454 * if next_fcf_pri was not set above and the list is not empty then
16455 * we have failed flogis on all of them. So reset flogi failed
16456 * and start at the beginning.
16458 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
16459 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
16460 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
16462 * the 1st priority that has not FLOGI failed
16463 * will be the highest.
16466 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
16467 spin_unlock_irq(&phba
->hbalock
);
16468 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
16469 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
16470 fcf_pri
->fcf_rec
.fcf_index
);
16474 spin_lock_irq(&phba
->hbalock
);
16478 spin_unlock_irq(&phba
->hbalock
);
16483 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
16484 * @phba: pointer to lpfc hba data structure.
16486 * This routine is to get the next eligible FCF record index in a round
16487 * robin fashion. If the next eligible FCF record index equals to the
16488 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
16489 * shall be returned, otherwise, the next eligible FCF record's index
16490 * shall be returned.
16493 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
16495 uint16_t next_fcf_index
;
16498 /* Search start from next bit of currently registered FCF index */
16499 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
16502 /* Determine the next fcf index to check */
16503 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
16504 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
16505 LPFC_SLI4_FCF_TBL_INDX_MAX
,
16508 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
16509 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
16511 * If we have wrapped then we need to clear the bits that
16512 * have been tested so that we can detect when we should
16513 * change the priority level.
16515 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
16516 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
16520 /* Check roundrobin failover list empty condition */
16521 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
16522 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
16524 * If next fcf index is not found check if there are lower
16525 * Priority level fcf's in the fcf_priority list.
16526 * Set up the rr_bmask with all of the avaiable fcf bits
16527 * at that level and continue the selection process.
16529 if (lpfc_check_next_fcf_pri_level(phba
))
16530 goto initial_priority
;
16531 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
16532 "2844 No roundrobin failover FCF available\n");
16533 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
16534 return LPFC_FCOE_FCF_NEXT_NONE
;
16536 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
16537 "3063 Only FCF available idx %d, flag %x\n",
16539 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
16540 return next_fcf_index
;
16544 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
16545 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
16546 LPFC_FCF_FLOGI_FAILED
) {
16547 if (list_is_singular(&phba
->fcf
.fcf_pri_list
))
16548 return LPFC_FCOE_FCF_NEXT_NONE
;
16550 goto next_priority
;
16553 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16554 "2845 Get next roundrobin failover FCF (x%x)\n",
16557 return next_fcf_index
;
16561 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
16562 * @phba: pointer to lpfc hba data structure.
16564 * This routine sets the FCF record index in to the eligible bmask for
16565 * roundrobin failover search. It checks to make sure that the index
16566 * does not go beyond the range of the driver allocated bmask dimension
16567 * before setting the bit.
16569 * Returns 0 if the index bit successfully set, otherwise, it returns
16573 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16575 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
16576 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16577 "2610 FCF (x%x) reached driver's book "
16578 "keeping dimension:x%x\n",
16579 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
16582 /* Set the eligible FCF record index bmask */
16583 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
16585 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16586 "2790 Set FCF (x%x) to roundrobin FCF failover "
16587 "bmask\n", fcf_index
);
16593 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
16594 * @phba: pointer to lpfc hba data structure.
16596 * This routine clears the FCF record index from the eligible bmask for
16597 * roundrobin failover search. It checks to make sure that the index
16598 * does not go beyond the range of the driver allocated bmask dimension
16599 * before clearing the bit.
16602 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
16604 struct lpfc_fcf_pri
*fcf_pri
, *fcf_pri_next
;
16605 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
16606 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16607 "2762 FCF (x%x) reached driver's book "
16608 "keeping dimension:x%x\n",
16609 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
16612 /* Clear the eligible FCF record index bmask */
16613 spin_lock_irq(&phba
->hbalock
);
16614 list_for_each_entry_safe(fcf_pri
, fcf_pri_next
, &phba
->fcf
.fcf_pri_list
,
16616 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
16617 list_del_init(&fcf_pri
->list
);
16621 spin_unlock_irq(&phba
->hbalock
);
16622 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
16624 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16625 "2791 Clear FCF (x%x) from roundrobin failover "
16626 "bmask\n", fcf_index
);
16630 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
16631 * @phba: pointer to lpfc hba data structure.
16633 * This routine is the completion routine for the rediscover FCF table mailbox
16634 * command. If the mailbox command returned failure, it will try to stop the
16635 * FCF rediscover wait timer.
16638 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
16640 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
16641 uint32_t shdr_status
, shdr_add_status
;
16643 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
16645 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
16646 &redisc_fcf
->header
.cfg_shdr
.response
);
16647 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
16648 &redisc_fcf
->header
.cfg_shdr
.response
);
16649 if (shdr_status
|| shdr_add_status
) {
16650 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16651 "2746 Requesting for FCF rediscovery failed "
16652 "status x%x add_status x%x\n",
16653 shdr_status
, shdr_add_status
);
16654 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
16655 spin_lock_irq(&phba
->hbalock
);
16656 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
16657 spin_unlock_irq(&phba
->hbalock
);
16659 * CVL event triggered FCF rediscover request failed,
16660 * last resort to re-try current registered FCF entry.
16662 lpfc_retry_pport_discovery(phba
);
16664 spin_lock_irq(&phba
->hbalock
);
16665 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
16666 spin_unlock_irq(&phba
->hbalock
);
16668 * DEAD FCF event triggered FCF rediscover request
16669 * failed, last resort to fail over as a link down
16670 * to FCF registration.
16672 lpfc_sli4_fcf_dead_failthrough(phba
);
16675 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16676 "2775 Start FCF rediscover quiescent timer\n");
16678 * Start FCF rediscovery wait timer for pending FCF
16679 * before rescan FCF record table.
16681 lpfc_fcf_redisc_wait_start_timer(phba
);
16684 mempool_free(mbox
, phba
->mbox_mem_pool
);
16688 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
16689 * @phba: pointer to lpfc hba data structure.
16691 * This routine is invoked to request for rediscovery of the entire FCF table
16695 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
16697 LPFC_MBOXQ_t
*mbox
;
16698 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
16701 /* Cancel retry delay timers to all vports before FCF rediscover */
16702 lpfc_cancel_all_vport_retry_delay_timer(phba
);
16704 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16706 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16707 "2745 Failed to allocate mbox for "
16708 "requesting FCF rediscover.\n");
16712 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
16713 sizeof(struct lpfc_sli4_cfg_mhdr
));
16714 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16715 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
16716 length
, LPFC_SLI4_MBX_EMBED
);
16718 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
16719 /* Set count to 0 for invalidating the entire FCF database */
16720 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
16722 /* Issue the mailbox command asynchronously */
16723 mbox
->vport
= phba
->pport
;
16724 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
16725 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
16727 if (rc
== MBX_NOT_FINISHED
) {
16728 mempool_free(mbox
, phba
->mbox_mem_pool
);
16735 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
16736 * @phba: pointer to lpfc hba data structure.
16738 * This function is the failover routine as a last resort to the FCF DEAD
16739 * event when driver failed to perform fast FCF failover.
16742 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
16744 uint32_t link_state
;
16747 * Last resort as FCF DEAD event failover will treat this as
16748 * a link down, but save the link state because we don't want
16749 * it to be changed to Link Down unless it is already down.
16751 link_state
= phba
->link_state
;
16752 lpfc_linkdown(phba
);
16753 phba
->link_state
= link_state
;
16755 /* Unregister FCF if no devices connected to it */
16756 lpfc_unregister_unused_fcf(phba
);
16760 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
16761 * @phba: pointer to lpfc hba data structure.
16762 * @rgn23_data: pointer to configure region 23 data.
16764 * This function gets SLI3 port configure region 23 data through memory dump
16765 * mailbox command. When it successfully retrieves data, the size of the data
16766 * will be returned, otherwise, 0 will be returned.
16769 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
16771 LPFC_MBOXQ_t
*pmb
= NULL
;
16773 uint32_t offset
= 0;
16779 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16781 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16782 "2600 failed to allocate mailbox memory\n");
16788 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
16789 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
16791 if (rc
!= MBX_SUCCESS
) {
16792 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
16793 "2601 failed to read config "
16794 "region 23, rc 0x%x Status 0x%x\n",
16795 rc
, mb
->mbxStatus
);
16796 mb
->un
.varDmp
.word_cnt
= 0;
16799 * dump mem may return a zero when finished or we got a
16800 * mailbox error, either way we are done.
16802 if (mb
->un
.varDmp
.word_cnt
== 0)
16804 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
16805 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
16807 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
16808 rgn23_data
+ offset
,
16809 mb
->un
.varDmp
.word_cnt
);
16810 offset
+= mb
->un
.varDmp
.word_cnt
;
16811 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
16813 mempool_free(pmb
, phba
->mbox_mem_pool
);
16818 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
16819 * @phba: pointer to lpfc hba data structure.
16820 * @rgn23_data: pointer to configure region 23 data.
16822 * This function gets SLI4 port configure region 23 data through memory dump
16823 * mailbox command. When it successfully retrieves data, the size of the data
16824 * will be returned, otherwise, 0 will be returned.
16827 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
16829 LPFC_MBOXQ_t
*mboxq
= NULL
;
16830 struct lpfc_dmabuf
*mp
= NULL
;
16831 struct lpfc_mqe
*mqe
;
16832 uint32_t data_length
= 0;
16838 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16840 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16841 "3105 failed to allocate mailbox memory\n");
16845 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
16847 mqe
= &mboxq
->u
.mqe
;
16848 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
16849 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
16852 data_length
= mqe
->un
.mb_words
[5];
16853 if (data_length
== 0)
16855 if (data_length
> DMP_RGN23_SIZE
) {
16859 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
16861 mempool_free(mboxq
, phba
->mbox_mem_pool
);
16863 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
16866 return data_length
;
16870 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
16871 * @phba: pointer to lpfc hba data structure.
16873 * This function read region 23 and parse TLV for port status to
16874 * decide if the user disaled the port. If the TLV indicates the
16875 * port is disabled, the hba_flag is set accordingly.
16878 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
16880 uint8_t *rgn23_data
= NULL
;
16881 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
16882 uint32_t offset
= 0;
16884 /* Get adapter Region 23 data */
16885 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
16889 if (phba
->sli_rev
< LPFC_SLI_REV4
)
16890 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
16892 if_type
= bf_get(lpfc_sli_intf_if_type
,
16893 &phba
->sli4_hba
.sli_intf
);
16894 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
16896 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
16902 /* Check the region signature first */
16903 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
16904 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16905 "2619 Config region 23 has bad signature\n");
16910 /* Check the data structure version */
16911 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
16912 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16913 "2620 Config region 23 has bad version\n");
16918 /* Parse TLV entries in the region */
16919 while (offset
< data_size
) {
16920 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
16923 * If the TLV is not driver specific TLV or driver id is
16924 * not linux driver id, skip the record.
16926 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
16927 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
16928 (rgn23_data
[offset
+ 3] != 0)) {
16929 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16933 /* Driver found a driver specific TLV in the config region */
16934 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
16939 * Search for configured port state sub-TLV.
16941 while ((offset
< data_size
) &&
16942 (tlv_offset
< sub_tlv_len
)) {
16943 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
16948 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
16949 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16950 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16954 /* This HBA contains PORT_STE configured */
16955 if (!rgn23_data
[offset
+ 2])
16956 phba
->hba_flag
|= LINK_DISABLED
;
16968 * lpfc_wr_object - write an object to the firmware
16969 * @phba: HBA structure that indicates port to create a queue on.
16970 * @dmabuf_list: list of dmabufs to write to the port.
16971 * @size: the total byte value of the objects to write to the port.
16972 * @offset: the current offset to be used to start the transfer.
16974 * This routine will create a wr_object mailbox command to send to the port.
16975 * the mailbox command will be constructed using the dma buffers described in
16976 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
16977 * BDEs that the imbedded mailbox can support. The @offset variable will be
16978 * used to indicate the starting offset of the transfer and will also return
16979 * the offset after the write object mailbox has completed. @size is used to
16980 * determine the end of the object and whether the eof bit should be set.
16982 * Return 0 is successful and offset will contain the the new offset to use
16983 * for the next write.
16984 * Return negative value for error cases.
16987 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
16988 uint32_t size
, uint32_t *offset
)
16990 struct lpfc_mbx_wr_object
*wr_object
;
16991 LPFC_MBOXQ_t
*mbox
;
16993 uint32_t shdr_status
, shdr_add_status
;
16995 union lpfc_sli4_cfg_shdr
*shdr
;
16996 struct lpfc_dmabuf
*dmabuf
;
16997 uint32_t written
= 0;
16999 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
17003 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
17004 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
17005 sizeof(struct lpfc_mbx_wr_object
) -
17006 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
17008 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
17009 wr_object
->u
.request
.write_offset
= *offset
;
17010 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
17011 wr_object
->u
.request
.object_name
[0] =
17012 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
17013 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
17014 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
17015 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
17017 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
17018 wr_object
->u
.request
.bde
[i
].addrHigh
=
17019 putPaddrHigh(dmabuf
->phys
);
17020 if (written
+ SLI4_PAGE_SIZE
>= size
) {
17021 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
17023 written
+= (size
- written
);
17024 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
17026 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
17028 written
+= SLI4_PAGE_SIZE
;
17032 wr_object
->u
.request
.bde_count
= i
;
17033 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
17034 if (!phba
->sli4_hba
.intr_enable
)
17035 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
17037 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
17038 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
17040 /* The IOCTL status is embedded in the mailbox subheader. */
17041 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
17042 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
17043 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
17044 if (rc
!= MBX_TIMEOUT
)
17045 mempool_free(mbox
, phba
->mbox_mem_pool
);
17046 if (shdr_status
|| shdr_add_status
|| rc
) {
17047 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
17048 "3025 Write Object mailbox failed with "
17049 "status x%x add_status x%x, mbx status x%x\n",
17050 shdr_status
, shdr_add_status
, rc
);
17053 *offset
+= wr_object
->u
.response
.actual_write_length
;
17058 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
17059 * @vport: pointer to vport data structure.
17061 * This function iterate through the mailboxq and clean up all REG_LOGIN
17062 * and REG_VPI mailbox commands associated with the vport. This function
17063 * is called when driver want to restart discovery of the vport due to
17064 * a Clear Virtual Link event.
17067 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
17069 struct lpfc_hba
*phba
= vport
->phba
;
17070 LPFC_MBOXQ_t
*mb
, *nextmb
;
17071 struct lpfc_dmabuf
*mp
;
17072 struct lpfc_nodelist
*ndlp
;
17073 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
17074 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
17075 LIST_HEAD(mbox_cmd_list
);
17076 uint8_t restart_loop
;
17078 /* Clean up internally queued mailbox commands with the vport */
17079 spin_lock_irq(&phba
->hbalock
);
17080 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
17081 if (mb
->vport
!= vport
)
17084 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
17085 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
17088 list_del(&mb
->list
);
17089 list_add_tail(&mb
->list
, &mbox_cmd_list
);
17091 /* Clean up active mailbox command with the vport */
17092 mb
= phba
->sli
.mbox_active
;
17093 if (mb
&& (mb
->vport
== vport
)) {
17094 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
17095 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
17096 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17097 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
17098 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
17099 /* Put reference count for delayed processing */
17100 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
17101 /* Unregister the RPI when mailbox complete */
17102 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
17105 /* Cleanup any mailbox completions which are not yet processed */
17108 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
17110 * If this mailox is already processed or it is
17111 * for another vport ignore it.
17113 if ((mb
->vport
!= vport
) ||
17114 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
17117 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
17118 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
17121 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
17122 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
17123 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
17124 /* Unregister the RPI when mailbox complete */
17125 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
17127 spin_unlock_irq(&phba
->hbalock
);
17128 spin_lock(shost
->host_lock
);
17129 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
17130 spin_unlock(shost
->host_lock
);
17131 spin_lock_irq(&phba
->hbalock
);
17135 } while (restart_loop
);
17137 spin_unlock_irq(&phba
->hbalock
);
17139 /* Release the cleaned-up mailbox commands */
17140 while (!list_empty(&mbox_cmd_list
)) {
17141 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
17142 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
17143 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
17145 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
17148 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
17149 mb
->context2
= NULL
;
17151 spin_lock(shost
->host_lock
);
17152 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
17153 spin_unlock(shost
->host_lock
);
17154 lpfc_nlp_put(ndlp
);
17157 mempool_free(mb
, phba
->mbox_mem_pool
);
17160 /* Release the ndlp with the cleaned-up active mailbox command */
17161 if (act_mbx_ndlp
) {
17162 spin_lock(shost
->host_lock
);
17163 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
17164 spin_unlock(shost
->host_lock
);
17165 lpfc_nlp_put(act_mbx_ndlp
);
17170 * lpfc_drain_txq - Drain the txq
17171 * @phba: Pointer to HBA context object.
17173 * This function attempt to submit IOCBs on the txq
17174 * to the adapter. For SLI4 adapters, the txq contains
17175 * ELS IOCBs that have been deferred because the there
17176 * are no SGLs. This congestion can occur with large
17177 * vport counts during node discovery.
17181 lpfc_drain_txq(struct lpfc_hba
*phba
)
17183 LIST_HEAD(completions
);
17184 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
17185 struct lpfc_iocbq
*piocbq
= NULL
;
17186 unsigned long iflags
= 0;
17187 char *fail_msg
= NULL
;
17188 struct lpfc_sglq
*sglq
;
17189 union lpfc_wqe wqe
;
17190 uint32_t txq_cnt
= 0;
17192 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
17193 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
17197 if (txq_cnt
> pring
->txq_max
)
17198 pring
->txq_max
= txq_cnt
;
17200 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17202 while (!list_empty(&pring
->txq
)) {
17203 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
17205 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
17207 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17208 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17209 "2823 txq empty and txq_cnt is %d\n ",
17213 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
17215 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
17216 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17221 /* The xri and iocb resources secured,
17222 * attempt to issue request
17224 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
17225 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
17226 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
17227 fail_msg
= "to convert bpl to sgl";
17228 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
17229 fail_msg
= "to convert iocb to wqe";
17230 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
17231 fail_msg
= " - Wq is full";
17233 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
17236 /* Failed means we can't issue and need to cancel */
17237 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
17238 "2822 IOCB failed %s iotag 0x%x "
17241 piocbq
->iotag
, piocbq
->sli4_xritag
);
17242 list_add_tail(&piocbq
->list
, &completions
);
17244 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
17247 /* Cancel all the IOCBs that cannot be issued */
17248 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
17249 IOERR_SLI_ABORTED
);