1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2013 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>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <linux/aer.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_debugfs.h"
48 #include "lpfc_vport.h"
50 /* There are only four IOCB completion types. */
51 typedef enum _lpfc_iocb_type
{
59 /* Provide function prototypes local to this module. */
60 static int lpfc_sli_issue_mbox_s4(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
62 static int lpfc_sli4_read_rev(struct lpfc_hba
*, LPFC_MBOXQ_t
*,
63 uint8_t *, uint32_t *);
64 static struct lpfc_iocbq
*lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*,
66 static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*,
68 static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*, struct lpfc_queue
*,
70 static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*, struct list_head
*,
72 static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*, struct lpfc_eqe
*,
74 static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
);
75 static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
);
78 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
84 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
85 * @q: The Work Queue to operate on.
86 * @wqe: The work Queue Entry to put on the Work queue.
88 * This routine will copy the contents of @wqe to the next available entry on
89 * the @q. This function will then ring the Work Queue Doorbell to signal the
90 * HBA to start processing the Work Queue Entry. This function returns 0 if
91 * successful. If no entries are available on @q then this function will return
93 * The caller is expected to hold the hbalock when calling this routine.
96 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
98 union lpfc_wqe
*temp_wqe
;
99 struct lpfc_register doorbell
;
103 /* sanity check on queue memory */
106 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
108 /* If the host has not yet processed the next entry then we are done */
109 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
110 if (idx
== q
->hba_index
) {
115 /* set consumption flag every once in a while */
116 if (!((q
->host_index
+ 1) % q
->entry_repost
))
117 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
118 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
119 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
120 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
122 /* Update the host index before invoking device */
123 host_index
= q
->host_index
;
129 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
130 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
131 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
, host_index
);
132 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
133 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
134 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
135 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
139 writel(doorbell
.word0
, q
->db_regaddr
);
145 * lpfc_sli4_wq_release - Updates internal hba index for WQ
146 * @q: The Work Queue to operate on.
147 * @index: The index to advance the hba index to.
149 * This routine will update the HBA index of a queue to reflect consumption of
150 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
151 * an entry the host calls this function to update the queue's internal
152 * pointers. This routine returns the number of entries that were consumed by
156 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
158 uint32_t released
= 0;
160 /* sanity check on queue memory */
164 if (q
->hba_index
== index
)
167 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
169 } while (q
->hba_index
!= index
);
174 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
175 * @q: The Mailbox Queue to operate on.
176 * @wqe: The Mailbox Queue Entry to put on the Work queue.
178 * This routine will copy the contents of @mqe to the next available entry on
179 * the @q. This function will then ring the Work Queue Doorbell to signal the
180 * HBA to start processing the Work Queue Entry. This function returns 0 if
181 * successful. If no entries are available on @q then this function will return
183 * The caller is expected to hold the hbalock when calling this routine.
186 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
188 struct lpfc_mqe
*temp_mqe
;
189 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 host_index
= q
->host_index
;
206 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
210 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
211 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
212 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
217 * lpfc_sli4_mq_release - Updates internal hba index for MQ
218 * @q: The Mailbox Queue to operate on.
220 * This routine will update the HBA index of a queue to reflect consumption of
221 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
222 * an entry the host calls this function to update the queue's internal
223 * pointers. This routine returns the number of entries that were consumed by
227 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
229 /* sanity check on queue memory */
233 /* Clear the mailbox pointer for completion */
234 q
->phba
->mbox
= NULL
;
235 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
240 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
241 * @q: The Event Queue to get the first valid EQE from
243 * This routine will get the first valid Event Queue Entry from @q, update
244 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
245 * the Queue (no more work to do), or the Queue is full of EQEs that have been
246 * processed, but not popped back to the HBA then this routine will return NULL.
248 static struct lpfc_eqe
*
249 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
251 struct lpfc_eqe
*eqe
;
254 /* sanity check on queue memory */
257 eqe
= q
->qe
[q
->hba_index
].eqe
;
259 /* If the next EQE is not valid then we are done */
260 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
262 /* If the host has not yet processed the next entry then we are done */
263 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
264 if (idx
== q
->host_index
)
272 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
273 * @q: The Event Queue to disable interrupts
277 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
279 struct lpfc_register doorbell
;
282 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
283 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
284 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
285 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
286 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
287 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
291 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
292 * @q: The Event Queue that the host has completed processing for.
293 * @arm: Indicates whether the host wants to arms this CQ.
295 * This routine will mark all Event Queue Entries on @q, from the last
296 * known completed entry to the last entry that was processed, as completed
297 * by clearing the valid bit for each completion queue entry. Then it will
298 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
299 * The internal host index in the @q will be updated by this routine to indicate
300 * that the host has finished processing the entries. The @arm parameter
301 * indicates that the queue should be rearmed when ringing the doorbell.
303 * This function will return the number of EQEs that were popped.
306 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
308 uint32_t released
= 0;
309 struct lpfc_eqe
*temp_eqe
;
310 struct lpfc_register doorbell
;
312 /* sanity check on queue memory */
316 /* while there are valid entries */
317 while (q
->hba_index
!= q
->host_index
) {
318 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
319 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
321 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
323 if (unlikely(released
== 0 && !arm
))
326 /* ring doorbell for number popped */
329 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
330 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
332 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
333 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
334 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
335 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
336 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
337 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
338 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
339 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
340 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
345 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
346 * @q: The Completion Queue to get the first valid CQE from
348 * This routine will get the first valid Completion Queue Entry from @q, update
349 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
350 * the Queue (no more work to do), or the Queue is full of CQEs that have been
351 * processed, but not popped back to the HBA then this routine will return NULL.
353 static struct lpfc_cqe
*
354 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
356 struct lpfc_cqe
*cqe
;
359 /* sanity check on queue memory */
363 /* If the next CQE is not valid then we are done */
364 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
366 /* If the host has not yet processed the next entry then we are done */
367 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
368 if (idx
== q
->host_index
)
371 cqe
= q
->qe
[q
->hba_index
].cqe
;
377 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
378 * @q: The Completion Queue that the host has completed processing for.
379 * @arm: Indicates whether the host wants to arms this CQ.
381 * This routine will mark all Completion queue entries on @q, from the last
382 * known completed entry to the last entry that was processed, as completed
383 * by clearing the valid bit for each completion queue entry. Then it will
384 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
385 * The internal host index in the @q will be updated by this routine to indicate
386 * that the host has finished processing the entries. The @arm parameter
387 * indicates that the queue should be rearmed when ringing the doorbell.
389 * This function will return the number of CQEs that were released.
392 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
394 uint32_t released
= 0;
395 struct lpfc_cqe
*temp_qe
;
396 struct lpfc_register doorbell
;
398 /* sanity check on queue memory */
401 /* while there are valid entries */
402 while (q
->hba_index
!= q
->host_index
) {
403 temp_qe
= q
->qe
[q
->host_index
].cqe
;
404 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
406 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
408 if (unlikely(released
== 0 && !arm
))
411 /* ring doorbell for number popped */
414 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
415 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
416 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
417 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
418 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
419 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
420 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
425 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
426 * @q: The Header Receive Queue to operate on.
427 * @wqe: The Receive Queue Entry to put on the Receive queue.
429 * This routine will copy the contents of @wqe to the next available entry on
430 * the @q. This function will then ring the Receive Queue Doorbell to signal the
431 * HBA to start processing the Receive Queue Entry. This function returns the
432 * index that the rqe was copied to if successful. If no entries are available
433 * on @q then this function will return -ENOMEM.
434 * The caller is expected to hold the hbalock when calling this routine.
437 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
438 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
440 struct lpfc_rqe
*temp_hrqe
;
441 struct lpfc_rqe
*temp_drqe
;
442 struct lpfc_register doorbell
;
445 /* sanity check on queue memory */
446 if (unlikely(!hq
) || unlikely(!dq
))
448 put_index
= hq
->host_index
;
449 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
450 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
452 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
454 if (hq
->host_index
!= dq
->host_index
)
456 /* If the host has not yet processed the next entry then we are done */
457 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
459 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
460 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
462 /* Update the host index to point to the next slot */
463 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
464 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
466 /* Ring The Header Receive Queue Doorbell */
467 if (!(hq
->host_index
% hq
->entry_repost
)) {
469 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
470 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
472 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
473 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
474 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
476 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
478 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
482 writel(doorbell
.word0
, hq
->db_regaddr
);
488 * lpfc_sli4_rq_release - Updates internal hba index for RQ
489 * @q: The Header Receive Queue to operate on.
491 * This routine will update the HBA index of a queue to reflect consumption of
492 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
493 * consumed an entry the host calls this function to update the queue's
494 * internal pointers. This routine returns the number of entries that were
495 * consumed by the HBA.
498 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
500 /* sanity check on queue memory */
501 if (unlikely(!hq
) || unlikely(!dq
))
504 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
506 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
507 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
512 * lpfc_cmd_iocb - Get next command iocb entry in the ring
513 * @phba: Pointer to HBA context object.
514 * @pring: Pointer to driver SLI ring object.
516 * This function returns pointer to next command iocb entry
517 * in the command ring. The caller must hold hbalock to prevent
518 * other threads consume the next command iocb.
519 * SLI-2/SLI-3 provide different sized iocbs.
521 static inline IOCB_t
*
522 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
524 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
525 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
529 * lpfc_resp_iocb - Get next response iocb entry in the ring
530 * @phba: Pointer to HBA context object.
531 * @pring: Pointer to driver SLI ring object.
533 * This function returns pointer to next response iocb entry
534 * in the response ring. The caller must hold hbalock to make sure
535 * that no other thread consume the next response iocb.
536 * SLI-2/SLI-3 provide different sized iocbs.
538 static inline IOCB_t
*
539 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
541 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
542 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
546 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
547 * @phba: Pointer to HBA context object.
549 * This function is called with hbalock held. This function
550 * allocates a new driver iocb object from the iocb pool. If the
551 * allocation is successful, it returns pointer to the newly
552 * allocated iocb object else it returns NULL.
555 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
557 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
558 struct lpfc_iocbq
* iocbq
= NULL
;
560 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
563 if (phba
->iocb_cnt
> phba
->iocb_max
)
564 phba
->iocb_max
= phba
->iocb_cnt
;
569 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
570 * @phba: Pointer to HBA context object.
571 * @xritag: XRI value.
573 * This function clears the sglq pointer from the array of acive
574 * sglq's. The xritag that is passed in is used to index into the
575 * array. Before the xritag can be used it needs to be adjusted
576 * by subtracting the xribase.
578 * Returns sglq ponter = success, NULL = Failure.
580 static struct lpfc_sglq
*
581 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
583 struct lpfc_sglq
*sglq
;
585 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
586 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
591 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
592 * @phba: Pointer to HBA context object.
593 * @xritag: XRI value.
595 * This function returns 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.
603 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
605 struct lpfc_sglq
*sglq
;
607 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
612 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
613 * @phba: Pointer to HBA context object.
614 * @xritag: xri used in this exchange.
615 * @rrq: The RRQ to be cleared.
619 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
621 struct lpfc_node_rrq
*rrq
)
623 struct lpfc_nodelist
*ndlp
= NULL
;
625 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
626 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
628 /* The target DID could have been swapped (cable swap)
629 * we should use the ndlp from the findnode if it is
632 if ((!ndlp
) && rrq
->ndlp
)
638 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
)) {
641 rrq
->rrq_stop_time
= 0;
644 mempool_free(rrq
, phba
->rrq_pool
);
648 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
649 * @phba: Pointer to HBA context object.
651 * This function is called with hbalock held. This function
652 * Checks if stop_time (ratov from setting rrq active) has
653 * been reached, if it has and the send_rrq flag is set then
654 * it will call lpfc_send_rrq. If the send_rrq flag is not set
655 * then it will just call the routine to clear the rrq and
656 * free the rrq resource.
657 * The timer is set to the next rrq that is going to expire before
658 * leaving the routine.
662 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
664 struct lpfc_node_rrq
*rrq
;
665 struct lpfc_node_rrq
*nextrrq
;
666 unsigned long next_time
;
667 unsigned long iflags
;
670 spin_lock_irqsave(&phba
->hbalock
, iflags
);
671 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
672 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
673 list_for_each_entry_safe(rrq
, nextrrq
,
674 &phba
->active_rrq_list
, list
) {
675 if (time_after(jiffies
, rrq
->rrq_stop_time
))
676 list_move(&rrq
->list
, &send_rrq
);
677 else if (time_before(rrq
->rrq_stop_time
, next_time
))
678 next_time
= rrq
->rrq_stop_time
;
680 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
681 if (!list_empty(&phba
->active_rrq_list
))
682 mod_timer(&phba
->rrq_tmr
, next_time
);
683 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
684 list_del(&rrq
->list
);
686 /* this call will free the rrq */
687 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
688 else if (lpfc_send_rrq(phba
, rrq
)) {
689 /* if we send the rrq then the completion handler
690 * will clear the bit in the xribitmap.
692 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
699 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
700 * @vport: Pointer to vport context object.
701 * @xri: The xri used in the exchange.
702 * @did: The targets DID for this exchange.
704 * returns NULL = rrq not found in the phba->active_rrq_list.
705 * rrq = rrq for this xri and target.
707 struct lpfc_node_rrq
*
708 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
710 struct lpfc_hba
*phba
= vport
->phba
;
711 struct lpfc_node_rrq
*rrq
;
712 struct lpfc_node_rrq
*nextrrq
;
713 unsigned long iflags
;
715 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
717 spin_lock_irqsave(&phba
->hbalock
, iflags
);
718 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
719 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
720 rrq
->nlp_DID
== did
){
721 list_del(&rrq
->list
);
722 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
726 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
731 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
732 * @vport: Pointer to vport context object.
733 * @ndlp: Pointer to the lpfc_node_list structure.
734 * If ndlp is NULL Remove all active RRQs for this vport from the
735 * phba->active_rrq_list and clear the rrq.
736 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
739 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
742 struct lpfc_hba
*phba
= vport
->phba
;
743 struct lpfc_node_rrq
*rrq
;
744 struct lpfc_node_rrq
*nextrrq
;
745 unsigned long iflags
;
748 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
751 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
752 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
754 spin_lock_irqsave(&phba
->hbalock
, iflags
);
755 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
756 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
757 list_move(&rrq
->list
, &rrq_list
);
758 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
760 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
761 list_del(&rrq
->list
);
762 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
767 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
768 * @phba: Pointer to HBA context object.
770 * Remove all rrqs from the phba->active_rrq_list and free them by
771 * calling __lpfc_clr_active_rrq
775 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
777 struct lpfc_node_rrq
*rrq
;
778 struct lpfc_node_rrq
*nextrrq
;
779 unsigned long next_time
;
780 unsigned long iflags
;
783 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
785 spin_lock_irqsave(&phba
->hbalock
, iflags
);
786 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
787 next_time
= jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2));
788 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
789 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
791 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
792 list_del(&rrq
->list
);
793 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
795 if (!list_empty(&phba
->active_rrq_list
))
796 mod_timer(&phba
->rrq_tmr
, next_time
);
801 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
802 * @phba: Pointer to HBA context object.
803 * @ndlp: Targets nodelist pointer for this exchange.
804 * @xritag the xri in the bitmap to test.
806 * This function is called with hbalock held. This function
807 * returns 0 = rrq not active for this xri
808 * 1 = rrq is valid for this xri.
811 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
816 if (!ndlp
->active_rrqs_xri_bitmap
)
818 if (test_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
825 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
826 * @phba: Pointer to HBA context object.
827 * @ndlp: nodelist pointer for this target.
828 * @xritag: xri used in this exchange.
829 * @rxid: Remote Exchange ID.
830 * @send_rrq: Flag used to determine if we should send rrq els cmd.
832 * This function takes the hbalock.
833 * The active bit is always set in the active rrq xri_bitmap even
834 * if there is no slot avaiable for the other rrq information.
836 * returns 0 rrq actived for this xri
837 * < 0 No memory or invalid ndlp.
840 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
841 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
843 unsigned long iflags
;
844 struct lpfc_node_rrq
*rrq
;
850 if (!phba
->cfg_enable_rrq
)
853 spin_lock_irqsave(&phba
->hbalock
, iflags
);
854 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
855 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
860 * set the active bit even if there is no mem available.
862 if (NLP_CHK_FREE_REQ(ndlp
))
865 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
868 if (!ndlp
->active_rrqs_xri_bitmap
)
871 if (test_and_set_bit(xritag
, ndlp
->active_rrqs_xri_bitmap
))
874 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
875 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
877 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
878 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
879 " DID:0x%x Send:%d\n",
880 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
883 if (phba
->cfg_enable_rrq
== 1)
884 rrq
->send_rrq
= send_rrq
;
887 rrq
->xritag
= xritag
;
888 rrq
->rrq_stop_time
= jiffies
+
889 msecs_to_jiffies(1000 * (phba
->fc_ratov
+ 1));
891 rrq
->nlp_DID
= ndlp
->nlp_DID
;
892 rrq
->vport
= ndlp
->vport
;
894 spin_lock_irqsave(&phba
->hbalock
, iflags
);
895 empty
= list_empty(&phba
->active_rrq_list
);
896 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
897 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
899 lpfc_worker_wake_up(phba
);
900 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
903 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
904 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
905 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
906 " DID:0x%x Send:%d\n",
907 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
912 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
913 * @phba: Pointer to HBA context object.
914 * @piocb: Pointer to the iocbq.
916 * This function is called with hbalock held. This function
917 * gets a new driver sglq object from the sglq list. If the
918 * list is not empty then it is successful, it returns pointer to the newly
919 * allocated sglq object else it returns NULL.
921 static struct lpfc_sglq
*
922 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
924 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
925 struct lpfc_sglq
*sglq
= NULL
;
926 struct lpfc_sglq
*start_sglq
= NULL
;
927 struct lpfc_scsi_buf
*lpfc_cmd
;
928 struct lpfc_nodelist
*ndlp
;
931 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
932 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
933 ndlp
= lpfc_cmd
->rdata
->pnode
;
934 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
935 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
936 ndlp
= piocbq
->context_un
.ndlp
;
937 else if (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
938 ndlp
= piocbq
->context_un
.ndlp
;
940 ndlp
= piocbq
->context1
;
942 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
947 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_lxritag
)) {
948 /* This xri has an rrq outstanding for this DID.
949 * put it back in the list and get another xri.
951 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
953 list_remove_head(lpfc_sgl_list
, sglq
,
954 struct lpfc_sglq
, list
);
955 if (sglq
== start_sglq
) {
963 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
964 sglq
->state
= SGL_ALLOCATED
;
970 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
971 * @phba: Pointer to HBA context object.
973 * This function is called with no lock held. This function
974 * allocates a new driver iocb object from the iocb pool. If the
975 * allocation is successful, it returns pointer to the newly
976 * allocated iocb object else it returns NULL.
979 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
981 struct lpfc_iocbq
* iocbq
= NULL
;
982 unsigned long iflags
;
984 spin_lock_irqsave(&phba
->hbalock
, iflags
);
985 iocbq
= __lpfc_sli_get_iocbq(phba
);
986 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
991 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
992 * @phba: Pointer to HBA context object.
993 * @iocbq: Pointer to driver iocb object.
995 * This function is called with hbalock held to release driver
996 * iocb object to the iocb pool. The iotag in the iocb object
997 * does not change for each use of the iocb object. This function
998 * clears all other fields of the iocb object when it is freed.
999 * The sqlq structure that holds the xritag and phys and virtual
1000 * mappings for the scatter gather list is retrieved from the
1001 * active array of sglq. The get of the sglq pointer also clears
1002 * the entry in the array. If the status of the IO indiactes that
1003 * this IO was aborted then the sglq entry it put on the
1004 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
1005 * IO has good status or fails for any other reason then the sglq
1006 * entry is added to the free list (lpfc_sgl_list).
1009 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1011 struct lpfc_sglq
*sglq
;
1012 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1013 unsigned long iflag
= 0;
1014 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1016 if (iocbq
->sli4_xritag
== NO_XRI
)
1019 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1023 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1024 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1025 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
1027 list_add(&sglq
->list
,
1028 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1029 spin_unlock_irqrestore(
1030 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
1032 sglq
->state
= SGL_FREED
;
1034 list_add_tail(&sglq
->list
,
1035 &phba
->sli4_hba
.lpfc_sgl_list
);
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
);
1071 * Clean all volatile data fields, preserve iotag and node struct.
1073 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1074 iocbq
->sli4_xritag
= NO_XRI
;
1075 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1079 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1080 * @phba: Pointer to HBA context object.
1081 * @iocbq: Pointer to driver iocb object.
1083 * This function is called with hbalock held to release driver
1084 * iocb object to the iocb pool. The iotag in the iocb object
1085 * does not change for each use of the iocb object. This function
1086 * clears all other fields of the iocb object when it is freed.
1089 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1091 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1096 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1097 * @phba: Pointer to HBA context object.
1098 * @iocbq: Pointer to driver iocb object.
1100 * This function is called with no lock held to release the iocb to
1104 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1106 unsigned long iflags
;
1109 * Clean all volatile data fields, preserve iotag and node struct.
1111 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1112 __lpfc_sli_release_iocbq(phba
, iocbq
);
1113 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1117 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1118 * @phba: Pointer to HBA context object.
1119 * @iocblist: List of IOCBs.
1120 * @ulpstatus: ULP status in IOCB command field.
1121 * @ulpWord4: ULP word-4 in IOCB command field.
1123 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1124 * on the list by invoking the complete callback function associated with the
1125 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1129 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1130 uint32_t ulpstatus
, uint32_t ulpWord4
)
1132 struct lpfc_iocbq
*piocb
;
1134 while (!list_empty(iocblist
)) {
1135 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1136 if (!piocb
->iocb_cmpl
)
1137 lpfc_sli_release_iocbq(phba
, piocb
);
1139 piocb
->iocb
.ulpStatus
= ulpstatus
;
1140 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1141 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1148 * lpfc_sli_iocb_cmd_type - Get the iocb type
1149 * @iocb_cmnd: iocb command code.
1151 * This function is called by ring event handler function to get the iocb type.
1152 * This function translates the iocb command to an iocb command type used to
1153 * decide the final disposition of each completed IOCB.
1154 * The function returns
1155 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1156 * LPFC_SOL_IOCB if it is a solicited iocb completion
1157 * LPFC_ABORT_IOCB if it is an abort iocb
1158 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1160 * The caller is not required to hold any lock.
1162 static lpfc_iocb_type
1163 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1165 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1167 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1170 switch (iocb_cmnd
) {
1171 case CMD_XMIT_SEQUENCE_CR
:
1172 case CMD_XMIT_SEQUENCE_CX
:
1173 case CMD_XMIT_BCAST_CN
:
1174 case CMD_XMIT_BCAST_CX
:
1175 case CMD_ELS_REQUEST_CR
:
1176 case CMD_ELS_REQUEST_CX
:
1177 case CMD_CREATE_XRI_CR
:
1178 case CMD_CREATE_XRI_CX
:
1179 case CMD_GET_RPI_CN
:
1180 case CMD_XMIT_ELS_RSP_CX
:
1181 case CMD_GET_RPI_CR
:
1182 case CMD_FCP_IWRITE_CR
:
1183 case CMD_FCP_IWRITE_CX
:
1184 case CMD_FCP_IREAD_CR
:
1185 case CMD_FCP_IREAD_CX
:
1186 case CMD_FCP_ICMND_CR
:
1187 case CMD_FCP_ICMND_CX
:
1188 case CMD_FCP_TSEND_CX
:
1189 case CMD_FCP_TRSP_CX
:
1190 case CMD_FCP_TRECEIVE_CX
:
1191 case CMD_FCP_AUTO_TRSP_CX
:
1192 case CMD_ADAPTER_MSG
:
1193 case CMD_ADAPTER_DUMP
:
1194 case CMD_XMIT_SEQUENCE64_CR
:
1195 case CMD_XMIT_SEQUENCE64_CX
:
1196 case CMD_XMIT_BCAST64_CN
:
1197 case CMD_XMIT_BCAST64_CX
:
1198 case CMD_ELS_REQUEST64_CR
:
1199 case CMD_ELS_REQUEST64_CX
:
1200 case CMD_FCP_IWRITE64_CR
:
1201 case CMD_FCP_IWRITE64_CX
:
1202 case CMD_FCP_IREAD64_CR
:
1203 case CMD_FCP_IREAD64_CX
:
1204 case CMD_FCP_ICMND64_CR
:
1205 case CMD_FCP_ICMND64_CX
:
1206 case CMD_FCP_TSEND64_CX
:
1207 case CMD_FCP_TRSP64_CX
:
1208 case CMD_FCP_TRECEIVE64_CX
:
1209 case CMD_GEN_REQUEST64_CR
:
1210 case CMD_GEN_REQUEST64_CX
:
1211 case CMD_XMIT_ELS_RSP64_CX
:
1212 case DSSCMD_IWRITE64_CR
:
1213 case DSSCMD_IWRITE64_CX
:
1214 case DSSCMD_IREAD64_CR
:
1215 case DSSCMD_IREAD64_CX
:
1216 type
= LPFC_SOL_IOCB
;
1218 case CMD_ABORT_XRI_CN
:
1219 case CMD_ABORT_XRI_CX
:
1220 case CMD_CLOSE_XRI_CN
:
1221 case CMD_CLOSE_XRI_CX
:
1222 case CMD_XRI_ABORTED_CX
:
1223 case CMD_ABORT_MXRI64_CN
:
1224 case CMD_XMIT_BLS_RSP64_CX
:
1225 type
= LPFC_ABORT_IOCB
;
1227 case CMD_RCV_SEQUENCE_CX
:
1228 case CMD_RCV_ELS_REQ_CX
:
1229 case CMD_RCV_SEQUENCE64_CX
:
1230 case CMD_RCV_ELS_REQ64_CX
:
1231 case CMD_ASYNC_STATUS
:
1232 case CMD_IOCB_RCV_SEQ64_CX
:
1233 case CMD_IOCB_RCV_ELS64_CX
:
1234 case CMD_IOCB_RCV_CONT64_CX
:
1235 case CMD_IOCB_RET_XRI64_CX
:
1236 type
= LPFC_UNSOL_IOCB
;
1238 case CMD_IOCB_XMIT_MSEQ64_CR
:
1239 case CMD_IOCB_XMIT_MSEQ64_CX
:
1240 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1241 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1242 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1243 case CMD_IOCB_ABORT_EXTENDED_CN
:
1244 case CMD_IOCB_RET_HBQE64_CN
:
1245 case CMD_IOCB_FCP_IBIDIR64_CR
:
1246 case CMD_IOCB_FCP_IBIDIR64_CX
:
1247 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1248 case CMD_IOCB_LOGENTRY_CN
:
1249 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1250 printk("%s - Unhandled SLI-3 Command x%x\n",
1251 __func__
, iocb_cmnd
);
1252 type
= LPFC_UNKNOWN_IOCB
;
1255 type
= LPFC_UNKNOWN_IOCB
;
1263 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1264 * @phba: Pointer to HBA context object.
1266 * This function is called from SLI initialization code
1267 * to configure every ring of the HBA's SLI interface. The
1268 * caller is not required to hold any lock. This function issues
1269 * a config_ring mailbox command for each ring.
1270 * This function returns zero if successful else returns a negative
1274 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1276 struct lpfc_sli
*psli
= &phba
->sli
;
1281 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1285 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1286 for (i
= 0; i
< psli
->num_rings
; i
++) {
1287 lpfc_config_ring(phba
, i
, pmb
);
1288 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1289 if (rc
!= MBX_SUCCESS
) {
1290 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1291 "0446 Adapter failed to init (%d), "
1292 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1294 rc
, pmbox
->mbxCommand
,
1295 pmbox
->mbxStatus
, i
);
1296 phba
->link_state
= LPFC_HBA_ERROR
;
1301 mempool_free(pmb
, phba
->mbox_mem_pool
);
1306 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1307 * @phba: Pointer to HBA context object.
1308 * @pring: Pointer to driver SLI ring object.
1309 * @piocb: Pointer to the driver iocb object.
1311 * This function is called with hbalock held. The function adds the
1312 * new iocb to txcmplq of the given ring. This function always returns
1313 * 0. If this function is called for ELS ring, this function checks if
1314 * there is a vport associated with the ELS command. This function also
1315 * starts els_tmofunc timer if this is an ELS command.
1318 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1319 struct lpfc_iocbq
*piocb
)
1321 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1322 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1324 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1325 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1326 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1330 mod_timer(&piocb
->vport
->els_tmofunc
,
1332 msecs_to_jiffies(1000 * (phba
->fc_ratov
<< 1)));
1340 * lpfc_sli_ringtx_get - Get first element of the txq
1341 * @phba: Pointer to HBA context object.
1342 * @pring: Pointer to driver SLI ring object.
1344 * This function is called with hbalock held to get next
1345 * iocb in txq of the given ring. If there is any iocb in
1346 * the txq, the function returns first iocb in the list after
1347 * removing the iocb from the list, else it returns NULL.
1350 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1352 struct lpfc_iocbq
*cmd_iocb
;
1354 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1359 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1360 * @phba: Pointer to HBA context object.
1361 * @pring: Pointer to driver SLI ring object.
1363 * This function is called with hbalock held and the caller must post the
1364 * iocb without releasing the lock. If the caller releases the lock,
1365 * iocb slot returned by the function is not guaranteed to be available.
1366 * The function returns pointer to the next available iocb slot if there
1367 * is available slot in the ring, else it returns NULL.
1368 * If the get index of the ring is ahead of the put index, the function
1369 * will post an error attention event to the worker thread to take the
1370 * HBA to offline state.
1373 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1375 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1376 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1377 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1378 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1379 pring
->sli
.sli3
.next_cmdidx
= 0;
1381 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1382 pring
->sli
.sli3
.next_cmdidx
)) {
1384 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1386 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1387 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1388 "0315 Ring %d issue: portCmdGet %d "
1389 "is bigger than cmd ring %d\n",
1391 pring
->sli
.sli3
.local_getidx
,
1394 phba
->link_state
= LPFC_HBA_ERROR
;
1396 * All error attention handlers are posted to
1399 phba
->work_ha
|= HA_ERATT
;
1400 phba
->work_hs
= HS_FFER3
;
1402 lpfc_worker_wake_up(phba
);
1407 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1411 return lpfc_cmd_iocb(phba
, pring
);
1415 * lpfc_sli_next_iotag - Get an iotag for the iocb
1416 * @phba: Pointer to HBA context object.
1417 * @iocbq: Pointer to driver iocb object.
1419 * This function gets an iotag for the iocb. If there is no unused iotag and
1420 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1421 * array and assigns a new iotag.
1422 * The function returns the allocated iotag if successful, else returns zero.
1423 * Zero is not a valid iotag.
1424 * The caller is not required to hold any lock.
1427 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1429 struct lpfc_iocbq
**new_arr
;
1430 struct lpfc_iocbq
**old_arr
;
1432 struct lpfc_sli
*psli
= &phba
->sli
;
1435 spin_lock_irq(&phba
->hbalock
);
1436 iotag
= psli
->last_iotag
;
1437 if(++iotag
< psli
->iocbq_lookup_len
) {
1438 psli
->last_iotag
= iotag
;
1439 psli
->iocbq_lookup
[iotag
] = iocbq
;
1440 spin_unlock_irq(&phba
->hbalock
);
1441 iocbq
->iotag
= iotag
;
1443 } else if (psli
->iocbq_lookup_len
< (0xffff
1444 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1445 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1446 spin_unlock_irq(&phba
->hbalock
);
1447 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1450 spin_lock_irq(&phba
->hbalock
);
1451 old_arr
= psli
->iocbq_lookup
;
1452 if (new_len
<= psli
->iocbq_lookup_len
) {
1453 /* highly unprobable case */
1455 iotag
= psli
->last_iotag
;
1456 if(++iotag
< psli
->iocbq_lookup_len
) {
1457 psli
->last_iotag
= iotag
;
1458 psli
->iocbq_lookup
[iotag
] = iocbq
;
1459 spin_unlock_irq(&phba
->hbalock
);
1460 iocbq
->iotag
= iotag
;
1463 spin_unlock_irq(&phba
->hbalock
);
1466 if (psli
->iocbq_lookup
)
1467 memcpy(new_arr
, old_arr
,
1468 ((psli
->last_iotag
+ 1) *
1469 sizeof (struct lpfc_iocbq
*)));
1470 psli
->iocbq_lookup
= new_arr
;
1471 psli
->iocbq_lookup_len
= new_len
;
1472 psli
->last_iotag
= iotag
;
1473 psli
->iocbq_lookup
[iotag
] = iocbq
;
1474 spin_unlock_irq(&phba
->hbalock
);
1475 iocbq
->iotag
= iotag
;
1480 spin_unlock_irq(&phba
->hbalock
);
1482 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1483 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1490 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1491 * @phba: Pointer to HBA context object.
1492 * @pring: Pointer to driver SLI ring object.
1493 * @iocb: Pointer to iocb slot in the ring.
1494 * @nextiocb: Pointer to driver iocb object which need to be
1495 * posted to firmware.
1497 * This function is called with hbalock held to post a new iocb to
1498 * the firmware. This function copies the new iocb to ring iocb slot and
1499 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1500 * a completion call back for this iocb else the function will free the
1504 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1505 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1510 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1513 if (pring
->ringno
== LPFC_ELS_RING
) {
1514 lpfc_debugfs_slow_ring_trc(phba
,
1515 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1516 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1517 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1518 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1522 * Issue iocb command to adapter
1524 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1526 pring
->stats
.iocb_cmd
++;
1529 * If there is no completion routine to call, we can release the
1530 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1531 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1533 if (nextiocb
->iocb_cmpl
)
1534 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1536 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1539 * Let the HBA know what IOCB slot will be the next one the
1540 * driver will put a command into.
1542 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1543 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1547 * lpfc_sli_update_full_ring - Update the chip attention register
1548 * @phba: Pointer to HBA context object.
1549 * @pring: Pointer to driver SLI ring object.
1551 * The caller is not required to hold any lock for calling this function.
1552 * This function updates the chip attention bits for the ring to inform firmware
1553 * that there are pending work to be done for this ring and requests an
1554 * interrupt when there is space available in the ring. This function is
1555 * called when the driver is unable to post more iocbs to the ring due
1556 * to unavailability of space in the ring.
1559 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1561 int ringno
= pring
->ringno
;
1563 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1568 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1569 * The HBA will tell us when an IOCB entry is available.
1571 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1572 readl(phba
->CAregaddr
); /* flush */
1574 pring
->stats
.iocb_cmd_full
++;
1578 * lpfc_sli_update_ring - Update chip attention register
1579 * @phba: Pointer to HBA context object.
1580 * @pring: Pointer to driver SLI ring object.
1582 * This function updates the chip attention register bit for the
1583 * given ring to inform HBA that there is more work to be done
1584 * in this ring. The caller is not required to hold any lock.
1587 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1589 int ringno
= pring
->ringno
;
1592 * Tell the HBA that there is work to do in this ring.
1594 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1596 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1597 readl(phba
->CAregaddr
); /* flush */
1602 * lpfc_sli_resume_iocb - Process iocbs in the txq
1603 * @phba: Pointer to HBA context object.
1604 * @pring: Pointer to driver SLI ring object.
1606 * This function is called with hbalock held to post pending iocbs
1607 * in the txq to the firmware. This function is called when driver
1608 * detects space available in the ring.
1611 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1614 struct lpfc_iocbq
*nextiocb
;
1618 * (a) there is anything on the txq to send
1620 * (c) link attention events can be processed (fcp ring only)
1621 * (d) IOCB processing is not blocked by the outstanding mbox command.
1624 if (lpfc_is_link_up(phba
) &&
1625 (!list_empty(&pring
->txq
)) &&
1626 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1627 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1629 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1630 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1631 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1634 lpfc_sli_update_ring(phba
, pring
);
1636 lpfc_sli_update_full_ring(phba
, pring
);
1643 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1644 * @phba: Pointer to HBA context object.
1645 * @hbqno: HBQ number.
1647 * This function is called with hbalock held to get the next
1648 * available slot for the given HBQ. If there is free slot
1649 * available for the HBQ it will return pointer to the next available
1650 * HBQ entry else it will return NULL.
1652 static struct lpfc_hbq_entry
*
1653 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1655 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1657 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1658 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1659 hbqp
->next_hbqPutIdx
= 0;
1661 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1662 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1663 uint32_t getidx
= le32_to_cpu(raw_index
);
1665 hbqp
->local_hbqGetIdx
= getidx
;
1667 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1668 lpfc_printf_log(phba
, KERN_ERR
,
1669 LOG_SLI
| LOG_VPORT
,
1670 "1802 HBQ %d: local_hbqGetIdx "
1671 "%u is > than hbqp->entry_count %u\n",
1672 hbqno
, hbqp
->local_hbqGetIdx
,
1675 phba
->link_state
= LPFC_HBA_ERROR
;
1679 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1683 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1688 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1689 * @phba: Pointer to HBA context object.
1691 * This function is called with no lock held to free all the
1692 * hbq buffers while uninitializing the SLI interface. It also
1693 * frees the HBQ buffers returned by the firmware but not yet
1694 * processed by the upper layers.
1697 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1699 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1700 struct hbq_dmabuf
*hbq_buf
;
1701 unsigned long flags
;
1705 hbq_count
= lpfc_sli_hbq_count();
1706 /* Return all memory used by all HBQs */
1707 spin_lock_irqsave(&phba
->hbalock
, flags
);
1708 for (i
= 0; i
< hbq_count
; ++i
) {
1709 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1710 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1711 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1712 list_del(&hbq_buf
->dbuf
.list
);
1713 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1715 phba
->hbqs
[i
].buffer_count
= 0;
1717 /* Return all HBQ buffer that are in-fly */
1718 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1720 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1721 list_del(&hbq_buf
->dbuf
.list
);
1722 if (hbq_buf
->tag
== -1) {
1723 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1726 hbqno
= hbq_buf
->tag
>> 16;
1727 if (hbqno
>= LPFC_MAX_HBQS
)
1728 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1731 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1736 /* Mark the HBQs not in use */
1737 phba
->hbq_in_use
= 0;
1738 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1742 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1743 * @phba: Pointer to HBA context object.
1744 * @hbqno: HBQ number.
1745 * @hbq_buf: Pointer to HBQ buffer.
1747 * This function is called with the hbalock held to post a
1748 * hbq buffer to the firmware. If the function finds an empty
1749 * slot in the HBQ, it will post the buffer. The function will return
1750 * pointer to the hbq entry if it successfully post the buffer
1751 * else it will return NULL.
1754 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1755 struct hbq_dmabuf
*hbq_buf
)
1757 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1761 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1762 * @phba: Pointer to HBA context object.
1763 * @hbqno: HBQ number.
1764 * @hbq_buf: Pointer to HBQ buffer.
1766 * This function is called with the hbalock held to post a hbq buffer to the
1767 * firmware. If the function finds an empty slot in the HBQ, it will post the
1768 * buffer and place it on the hbq_buffer_list. The function will return zero if
1769 * it successfully post the buffer else it will return an error.
1772 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1773 struct hbq_dmabuf
*hbq_buf
)
1775 struct lpfc_hbq_entry
*hbqe
;
1776 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1778 /* Get next HBQ entry slot to use */
1779 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1781 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1783 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1784 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1785 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1786 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1787 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1788 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1790 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1791 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1793 readl(phba
->hbq_put
+ hbqno
);
1794 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1801 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1802 * @phba: Pointer to HBA context object.
1803 * @hbqno: HBQ number.
1804 * @hbq_buf: Pointer to HBQ buffer.
1806 * This function is called with the hbalock held to post an RQE to the SLI4
1807 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1808 * the hbq_buffer_list and return zero, otherwise it will return an error.
1811 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1812 struct hbq_dmabuf
*hbq_buf
)
1815 struct lpfc_rqe hrqe
;
1816 struct lpfc_rqe drqe
;
1818 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1819 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1820 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1821 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1822 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1827 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1831 /* HBQ for ELS and CT traffic. */
1832 static struct lpfc_hbq_init lpfc_els_hbq
= {
1837 .ring_mask
= (1 << LPFC_ELS_RING
),
1843 /* HBQ for the extra ring if needed */
1844 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1849 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1856 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1862 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1863 * @phba: Pointer to HBA context object.
1864 * @hbqno: HBQ number.
1865 * @count: Number of HBQ buffers to be posted.
1867 * This function is called with no lock held to post more hbq buffers to the
1868 * given HBQ. The function returns the number of HBQ buffers successfully
1872 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1874 uint32_t i
, posted
= 0;
1875 unsigned long flags
;
1876 struct hbq_dmabuf
*hbq_buffer
;
1877 LIST_HEAD(hbq_buf_list
);
1878 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1881 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1882 lpfc_hbq_defs
[hbqno
]->entry_count
)
1883 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1884 phba
->hbqs
[hbqno
].buffer_count
;
1887 /* Allocate HBQ entries */
1888 for (i
= 0; i
< count
; i
++) {
1889 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1892 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1894 /* Check whether HBQ is still in use */
1895 spin_lock_irqsave(&phba
->hbalock
, flags
);
1896 if (!phba
->hbq_in_use
)
1898 while (!list_empty(&hbq_buf_list
)) {
1899 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1901 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1903 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1904 phba
->hbqs
[hbqno
].buffer_count
++;
1907 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1909 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1912 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1913 while (!list_empty(&hbq_buf_list
)) {
1914 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1916 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1922 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1923 * @phba: Pointer to HBA context object.
1926 * This function posts more buffers to the HBQ. This function
1927 * is called with no lock held. The function returns the number of HBQ entries
1928 * successfully allocated.
1931 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1933 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1936 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1937 lpfc_hbq_defs
[qno
]->add_count
);
1941 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1942 * @phba: Pointer to HBA context object.
1943 * @qno: HBQ queue number.
1945 * This function is called from SLI initialization code path with
1946 * no lock held to post initial HBQ buffers to firmware. The
1947 * function returns the number of HBQ entries successfully allocated.
1950 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1952 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1953 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1954 lpfc_hbq_defs
[qno
]->entry_count
);
1956 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1957 lpfc_hbq_defs
[qno
]->init_count
);
1961 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1962 * @phba: Pointer to HBA context object.
1963 * @hbqno: HBQ number.
1965 * This function removes the first hbq buffer on an hbq list and returns a
1966 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1968 static struct hbq_dmabuf
*
1969 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1971 struct lpfc_dmabuf
*d_buf
;
1973 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1976 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1980 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1981 * @phba: Pointer to HBA context object.
1982 * @tag: Tag of the hbq buffer.
1984 * This function is called with hbalock held. This function searches
1985 * for the hbq buffer associated with the given tag in the hbq buffer
1986 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1989 static struct hbq_dmabuf
*
1990 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
1992 struct lpfc_dmabuf
*d_buf
;
1993 struct hbq_dmabuf
*hbq_buf
;
1997 if (hbqno
>= LPFC_MAX_HBQS
)
2000 spin_lock_irq(&phba
->hbalock
);
2001 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2002 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2003 if (hbq_buf
->tag
== tag
) {
2004 spin_unlock_irq(&phba
->hbalock
);
2008 spin_unlock_irq(&phba
->hbalock
);
2009 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2010 "1803 Bad hbq tag. Data: x%x x%x\n",
2011 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2016 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2017 * @phba: Pointer to HBA context object.
2018 * @hbq_buffer: Pointer to HBQ buffer.
2020 * This function is called with hbalock. This function gives back
2021 * the hbq buffer to firmware. If the HBQ does not have space to
2022 * post the buffer, it will free the buffer.
2025 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2030 hbqno
= hbq_buffer
->tag
>> 16;
2031 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2032 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2037 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2038 * @mbxCommand: mailbox command code.
2040 * This function is called by the mailbox event handler function to verify
2041 * that the completed mailbox command is a legitimate mailbox command. If the
2042 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2043 * and the mailbox event handler will take the HBA offline.
2046 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2050 switch (mbxCommand
) {
2054 case MBX_WRITE_VPARMS
:
2055 case MBX_RUN_BIU_DIAG
:
2058 case MBX_CONFIG_LINK
:
2059 case MBX_CONFIG_RING
:
2060 case MBX_RESET_RING
:
2061 case MBX_READ_CONFIG
:
2062 case MBX_READ_RCONFIG
:
2063 case MBX_READ_SPARM
:
2064 case MBX_READ_STATUS
:
2068 case MBX_READ_LNK_STAT
:
2070 case MBX_UNREG_LOGIN
:
2072 case MBX_DUMP_MEMORY
:
2073 case MBX_DUMP_CONTEXT
:
2076 case MBX_UPDATE_CFG
:
2078 case MBX_DEL_LD_ENTRY
:
2079 case MBX_RUN_PROGRAM
:
2081 case MBX_SET_VARIABLE
:
2082 case MBX_UNREG_D_ID
:
2083 case MBX_KILL_BOARD
:
2084 case MBX_CONFIG_FARP
:
2087 case MBX_RUN_BIU_DIAG64
:
2088 case MBX_CONFIG_PORT
:
2089 case MBX_READ_SPARM64
:
2090 case MBX_READ_RPI64
:
2091 case MBX_REG_LOGIN64
:
2092 case MBX_READ_TOPOLOGY
:
2095 case MBX_LOAD_EXP_ROM
:
2096 case MBX_ASYNCEVT_ENABLE
:
2100 case MBX_PORT_CAPABILITIES
:
2101 case MBX_PORT_IOV_CONTROL
:
2102 case MBX_SLI4_CONFIG
:
2103 case MBX_SLI4_REQ_FTRS
:
2105 case MBX_UNREG_FCFI
:
2110 case MBX_RESUME_RPI
:
2111 case MBX_READ_EVENT_LOG_STATUS
:
2112 case MBX_READ_EVENT_LOG
:
2113 case MBX_SECURITY_MGMT
:
2115 case MBX_ACCESS_VDATA
:
2126 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2127 * @phba: Pointer to HBA context object.
2128 * @pmboxq: Pointer to mailbox command.
2130 * This is completion handler function for mailbox commands issued from
2131 * lpfc_sli_issue_mbox_wait function. This function is called by the
2132 * mailbox event handler function with no lock held. This function
2133 * will wake up thread waiting on the wait queue pointed by context1
2137 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2139 wait_queue_head_t
*pdone_q
;
2140 unsigned long drvr_flag
;
2143 * If pdone_q is empty, the driver thread gave up waiting and
2144 * continued running.
2146 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2147 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2148 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2150 wake_up_interruptible(pdone_q
);
2151 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2157 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2158 * @phba: Pointer to HBA context object.
2159 * @pmb: Pointer to mailbox object.
2161 * This function is the default mailbox completion handler. It
2162 * frees the memory resources associated with the completed mailbox
2163 * command. If the completed command is a REG_LOGIN mailbox command,
2164 * this function will issue a UREG_LOGIN to re-claim the RPI.
2167 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2169 struct lpfc_vport
*vport
= pmb
->vport
;
2170 struct lpfc_dmabuf
*mp
;
2171 struct lpfc_nodelist
*ndlp
;
2172 struct Scsi_Host
*shost
;
2176 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2179 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2184 * If a REG_LOGIN succeeded after node is destroyed or node
2185 * is in re-discovery driver need to cleanup the RPI.
2187 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2188 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2189 !pmb
->u
.mb
.mbxStatus
) {
2190 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2191 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2192 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2193 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2194 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2195 if (rc
!= MBX_NOT_FINISHED
)
2199 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2200 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2201 !pmb
->u
.mb
.mbxStatus
) {
2202 shost
= lpfc_shost_from_vport(vport
);
2203 spin_lock_irq(shost
->host_lock
);
2204 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2205 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2206 spin_unlock_irq(shost
->host_lock
);
2209 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2210 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2212 pmb
->context2
= NULL
;
2215 /* Check security permission status on INIT_LINK mailbox command */
2216 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2217 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2218 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2219 "2860 SLI authentication is required "
2220 "for INIT_LINK but has not done yet\n");
2222 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2223 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2225 mempool_free(pmb
, phba
->mbox_mem_pool
);
2229 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2230 * @phba: Pointer to HBA context object.
2232 * This function is called with no lock held. This function processes all
2233 * the completed mailbox commands and gives it to upper layers. The interrupt
2234 * service routine processes mailbox completion interrupt and adds completed
2235 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2236 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2237 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2238 * function returns the mailbox commands to the upper layer by calling the
2239 * completion handler function of each mailbox.
2242 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2249 phba
->sli
.slistat
.mbox_event
++;
2251 /* Get all completed mailboxe buffers into the cmplq */
2252 spin_lock_irq(&phba
->hbalock
);
2253 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2254 spin_unlock_irq(&phba
->hbalock
);
2256 /* Get a Mailbox buffer to setup mailbox commands for callback */
2258 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2264 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2266 lpfc_debugfs_disc_trc(pmb
->vport
,
2267 LPFC_DISC_TRC_MBOX_VPORT
,
2268 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2269 (uint32_t)pmbox
->mbxCommand
,
2270 pmbox
->un
.varWords
[0],
2271 pmbox
->un
.varWords
[1]);
2274 lpfc_debugfs_disc_trc(phba
->pport
,
2276 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2277 (uint32_t)pmbox
->mbxCommand
,
2278 pmbox
->un
.varWords
[0],
2279 pmbox
->un
.varWords
[1]);
2284 * It is a fatal error if unknown mbox command completion.
2286 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2288 /* Unknown mailbox command compl */
2289 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2290 "(%d):0323 Unknown Mailbox command "
2291 "x%x (x%x/x%x) Cmpl\n",
2292 pmb
->vport
? pmb
->vport
->vpi
: 0,
2294 lpfc_sli_config_mbox_subsys_get(phba
,
2296 lpfc_sli_config_mbox_opcode_get(phba
,
2298 phba
->link_state
= LPFC_HBA_ERROR
;
2299 phba
->work_hs
= HS_FFER3
;
2300 lpfc_handle_eratt(phba
);
2304 if (pmbox
->mbxStatus
) {
2305 phba
->sli
.slistat
.mbox_stat_err
++;
2306 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2307 /* Mbox cmd cmpl error - RETRYing */
2308 lpfc_printf_log(phba
, KERN_INFO
,
2310 "(%d):0305 Mbox cmd cmpl "
2311 "error - RETRYing Data: x%x "
2312 "(x%x/x%x) x%x x%x x%x\n",
2313 pmb
->vport
? pmb
->vport
->vpi
: 0,
2315 lpfc_sli_config_mbox_subsys_get(phba
,
2317 lpfc_sli_config_mbox_opcode_get(phba
,
2320 pmbox
->un
.varWords
[0],
2321 pmb
->vport
->port_state
);
2322 pmbox
->mbxStatus
= 0;
2323 pmbox
->mbxOwner
= OWN_HOST
;
2324 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2325 if (rc
!= MBX_NOT_FINISHED
)
2330 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2331 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2332 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2333 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
2335 pmb
->vport
? pmb
->vport
->vpi
: 0,
2337 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2338 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2340 *((uint32_t *) pmbox
),
2341 pmbox
->un
.varWords
[0],
2342 pmbox
->un
.varWords
[1],
2343 pmbox
->un
.varWords
[2],
2344 pmbox
->un
.varWords
[3],
2345 pmbox
->un
.varWords
[4],
2346 pmbox
->un
.varWords
[5],
2347 pmbox
->un
.varWords
[6],
2348 pmbox
->un
.varWords
[7],
2349 pmbox
->un
.varWords
[8],
2350 pmbox
->un
.varWords
[9],
2351 pmbox
->un
.varWords
[10]);
2354 pmb
->mbox_cmpl(phba
,pmb
);
2360 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2361 * @phba: Pointer to HBA context object.
2362 * @pring: Pointer to driver SLI ring object.
2365 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2366 * is set in the tag the buffer is posted for a particular exchange,
2367 * the function will return the buffer without replacing the buffer.
2368 * If the buffer is for unsolicited ELS or CT traffic, this function
2369 * returns the buffer and also posts another buffer to the firmware.
2371 static struct lpfc_dmabuf
*
2372 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2373 struct lpfc_sli_ring
*pring
,
2376 struct hbq_dmabuf
*hbq_entry
;
2378 if (tag
& QUE_BUFTAG_BIT
)
2379 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2380 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2383 return &hbq_entry
->dbuf
;
2387 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2388 * @phba: Pointer to HBA context object.
2389 * @pring: Pointer to driver SLI ring object.
2390 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2391 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2392 * @fch_type: the type for the first frame of the sequence.
2394 * This function is called with no lock held. This function uses the r_ctl and
2395 * type of the received sequence to find the correct callback function to call
2396 * to process the sequence.
2399 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2400 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2405 /* unSolicited Responses */
2406 if (pring
->prt
[0].profile
) {
2407 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2408 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2412 /* We must search, based on rctl / type
2413 for the right routine */
2414 for (i
= 0; i
< pring
->num_mask
; i
++) {
2415 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2416 (pring
->prt
[i
].type
== fch_type
)) {
2417 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2418 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2419 (phba
, pring
, saveq
);
2427 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2428 * @phba: Pointer to HBA context object.
2429 * @pring: Pointer to driver SLI ring object.
2430 * @saveq: Pointer to the unsolicited iocb.
2432 * This function is called with no lock held by the ring event handler
2433 * when there is an unsolicited iocb posted to the response ring by the
2434 * firmware. This function gets the buffer associated with the iocbs
2435 * and calls the event handler for the ring. This function handles both
2436 * qring buffers and hbq buffers.
2437 * When the function returns 1 the caller can free the iocb object otherwise
2438 * upper layer functions will free the iocb objects.
2441 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2442 struct lpfc_iocbq
*saveq
)
2446 uint32_t Rctl
, Type
;
2448 struct lpfc_iocbq
*iocbq
;
2449 struct lpfc_dmabuf
*dmzbuf
;
2452 irsp
= &(saveq
->iocb
);
2454 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2455 if (pring
->lpfc_sli_rcv_async_status
)
2456 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2458 lpfc_printf_log(phba
,
2461 "0316 Ring %d handler: unexpected "
2462 "ASYNC_STATUS iocb received evt_code "
2465 irsp
->un
.asyncstat
.evt_code
);
2469 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2470 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2471 if (irsp
->ulpBdeCount
> 0) {
2472 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2473 irsp
->un
.ulpWord
[3]);
2474 lpfc_in_buf_free(phba
, dmzbuf
);
2477 if (irsp
->ulpBdeCount
> 1) {
2478 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2479 irsp
->unsli3
.sli3Words
[3]);
2480 lpfc_in_buf_free(phba
, dmzbuf
);
2483 if (irsp
->ulpBdeCount
> 2) {
2484 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2485 irsp
->unsli3
.sli3Words
[7]);
2486 lpfc_in_buf_free(phba
, dmzbuf
);
2492 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2493 if (irsp
->ulpBdeCount
!= 0) {
2494 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2495 irsp
->un
.ulpWord
[3]);
2496 if (!saveq
->context2
)
2497 lpfc_printf_log(phba
,
2500 "0341 Ring %d Cannot find buffer for "
2501 "an unsolicited iocb. tag 0x%x\n",
2503 irsp
->un
.ulpWord
[3]);
2505 if (irsp
->ulpBdeCount
== 2) {
2506 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2507 irsp
->unsli3
.sli3Words
[7]);
2508 if (!saveq
->context3
)
2509 lpfc_printf_log(phba
,
2512 "0342 Ring %d Cannot find buffer for an"
2513 " unsolicited iocb. tag 0x%x\n",
2515 irsp
->unsli3
.sli3Words
[7]);
2517 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2518 irsp
= &(iocbq
->iocb
);
2519 if (irsp
->ulpBdeCount
!= 0) {
2520 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2521 irsp
->un
.ulpWord
[3]);
2522 if (!iocbq
->context2
)
2523 lpfc_printf_log(phba
,
2526 "0343 Ring %d Cannot find "
2527 "buffer for an unsolicited iocb"
2528 ". tag 0x%x\n", pring
->ringno
,
2529 irsp
->un
.ulpWord
[3]);
2531 if (irsp
->ulpBdeCount
== 2) {
2532 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2533 irsp
->unsli3
.sli3Words
[7]);
2534 if (!iocbq
->context3
)
2535 lpfc_printf_log(phba
,
2538 "0344 Ring %d Cannot find "
2539 "buffer for an unsolicited "
2542 irsp
->unsli3
.sli3Words
[7]);
2546 if (irsp
->ulpBdeCount
!= 0 &&
2547 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2548 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2551 /* search continue save q for same XRI */
2552 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2553 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2554 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2555 list_add_tail(&saveq
->list
, &iocbq
->list
);
2561 list_add_tail(&saveq
->clist
,
2562 &pring
->iocb_continue_saveq
);
2563 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2564 list_del_init(&iocbq
->clist
);
2566 irsp
= &(saveq
->iocb
);
2570 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2571 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2572 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2573 Rctl
= FC_RCTL_ELS_REQ
;
2576 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2577 Rctl
= w5p
->hcsw
.Rctl
;
2578 Type
= w5p
->hcsw
.Type
;
2580 /* Firmware Workaround */
2581 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2582 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2583 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2584 Rctl
= FC_RCTL_ELS_REQ
;
2586 w5p
->hcsw
.Rctl
= Rctl
;
2587 w5p
->hcsw
.Type
= Type
;
2591 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2592 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2593 "0313 Ring %d handler: unexpected Rctl x%x "
2594 "Type x%x received\n",
2595 pring
->ringno
, Rctl
, Type
);
2601 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2602 * @phba: Pointer to HBA context object.
2603 * @pring: Pointer to driver SLI ring object.
2604 * @prspiocb: Pointer to response iocb object.
2606 * This function looks up the iocb_lookup table to get the command iocb
2607 * corresponding to the given response iocb using the iotag of the
2608 * response iocb. This function is called with the hbalock held.
2609 * This function returns the command iocb object if it finds the command
2610 * iocb else returns NULL.
2612 static struct lpfc_iocbq
*
2613 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2614 struct lpfc_sli_ring
*pring
,
2615 struct lpfc_iocbq
*prspiocb
)
2617 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2620 iotag
= prspiocb
->iocb
.ulpIoTag
;
2622 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2623 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2624 list_del_init(&cmd_iocb
->list
);
2625 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2626 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2631 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2632 "0317 iotag x%x is out off "
2633 "range: max iotag x%x wd0 x%x\n",
2634 iotag
, phba
->sli
.last_iotag
,
2635 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2640 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2641 * @phba: Pointer to HBA context object.
2642 * @pring: Pointer to driver SLI ring object.
2645 * This function looks up the iocb_lookup table to get the command iocb
2646 * corresponding to the given iotag. This function is called with the
2648 * This function returns the command iocb object if it finds the command
2649 * iocb else returns NULL.
2651 static struct lpfc_iocbq
*
2652 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2653 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2655 struct lpfc_iocbq
*cmd_iocb
;
2657 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2658 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2659 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2660 /* remove from txcmpl queue list */
2661 list_del_init(&cmd_iocb
->list
);
2662 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2666 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2667 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2668 iotag
, phba
->sli
.last_iotag
);
2673 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2674 * @phba: Pointer to HBA context object.
2675 * @pring: Pointer to driver SLI ring object.
2676 * @saveq: Pointer to the response iocb to be processed.
2678 * This function is called by the ring event handler for non-fcp
2679 * rings when there is a new response iocb in the response ring.
2680 * The caller is not required to hold any locks. This function
2681 * gets the command iocb associated with the response iocb and
2682 * calls the completion handler for the command iocb. If there
2683 * is no completion handler, the function will free the resources
2684 * associated with command iocb. If the response iocb is for
2685 * an already aborted command iocb, the status of the completion
2686 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2687 * This function always returns 1.
2690 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2691 struct lpfc_iocbq
*saveq
)
2693 struct lpfc_iocbq
*cmdiocbp
;
2695 unsigned long iflag
;
2697 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2698 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2699 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2700 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2703 if (cmdiocbp
->iocb_cmpl
) {
2705 * If an ELS command failed send an event to mgmt
2708 if (saveq
->iocb
.ulpStatus
&&
2709 (pring
->ringno
== LPFC_ELS_RING
) &&
2710 (cmdiocbp
->iocb
.ulpCommand
==
2711 CMD_ELS_REQUEST64_CR
))
2712 lpfc_send_els_failure_event(phba
,
2716 * Post all ELS completions to the worker thread.
2717 * All other are passed to the completion callback.
2719 if (pring
->ringno
== LPFC_ELS_RING
) {
2720 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2721 (cmdiocbp
->iocb_flag
&
2722 LPFC_DRIVER_ABORTED
)) {
2723 spin_lock_irqsave(&phba
->hbalock
,
2725 cmdiocbp
->iocb_flag
&=
2726 ~LPFC_DRIVER_ABORTED
;
2727 spin_unlock_irqrestore(&phba
->hbalock
,
2729 saveq
->iocb
.ulpStatus
=
2730 IOSTAT_LOCAL_REJECT
;
2731 saveq
->iocb
.un
.ulpWord
[4] =
2734 /* Firmware could still be in progress
2735 * of DMAing payload, so don't free data
2736 * buffer till after a hbeat.
2738 spin_lock_irqsave(&phba
->hbalock
,
2740 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2741 spin_unlock_irqrestore(&phba
->hbalock
,
2744 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2745 if (saveq
->iocb_flag
&
2746 LPFC_EXCHANGE_BUSY
) {
2747 /* Set cmdiocb flag for the
2748 * exchange busy so sgl (xri)
2749 * will not be released until
2750 * the abort xri is received
2754 &phba
->hbalock
, iflag
);
2755 cmdiocbp
->iocb_flag
|=
2757 spin_unlock_irqrestore(
2758 &phba
->hbalock
, iflag
);
2760 if (cmdiocbp
->iocb_flag
&
2761 LPFC_DRIVER_ABORTED
) {
2763 * Clear LPFC_DRIVER_ABORTED
2764 * bit in case it was driver
2768 &phba
->hbalock
, iflag
);
2769 cmdiocbp
->iocb_flag
&=
2770 ~LPFC_DRIVER_ABORTED
;
2771 spin_unlock_irqrestore(
2772 &phba
->hbalock
, iflag
);
2773 cmdiocbp
->iocb
.ulpStatus
=
2774 IOSTAT_LOCAL_REJECT
;
2775 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2776 IOERR_ABORT_REQUESTED
;
2778 * For SLI4, irsiocb contains
2779 * NO_XRI in sli_xritag, it
2780 * shall not affect releasing
2781 * sgl (xri) process.
2783 saveq
->iocb
.ulpStatus
=
2784 IOSTAT_LOCAL_REJECT
;
2785 saveq
->iocb
.un
.ulpWord
[4] =
2788 &phba
->hbalock
, iflag
);
2790 LPFC_DELAY_MEM_FREE
;
2791 spin_unlock_irqrestore(
2792 &phba
->hbalock
, iflag
);
2796 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2798 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2801 * Unknown initiating command based on the response iotag.
2802 * This could be the case on the ELS ring because of
2805 if (pring
->ringno
!= LPFC_ELS_RING
) {
2807 * Ring <ringno> handler: unexpected completion IoTag
2810 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2811 "0322 Ring %d handler: "
2812 "unexpected completion IoTag x%x "
2813 "Data: x%x x%x x%x x%x\n",
2815 saveq
->iocb
.ulpIoTag
,
2816 saveq
->iocb
.ulpStatus
,
2817 saveq
->iocb
.un
.ulpWord
[4],
2818 saveq
->iocb
.ulpCommand
,
2819 saveq
->iocb
.ulpContext
);
2827 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2828 * @phba: Pointer to HBA context object.
2829 * @pring: Pointer to driver SLI ring object.
2831 * This function is called from the iocb ring event handlers when
2832 * put pointer is ahead of the get pointer for a ring. This function signal
2833 * an error attention condition to the worker thread and the worker
2834 * thread will transition the HBA to offline state.
2837 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2839 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2841 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2842 * rsp ring <portRspMax>
2844 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2845 "0312 Ring %d handler: portRspPut %d "
2846 "is bigger than rsp ring %d\n",
2847 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2848 pring
->sli
.sli3
.numRiocb
);
2850 phba
->link_state
= LPFC_HBA_ERROR
;
2853 * All error attention handlers are posted to
2856 phba
->work_ha
|= HA_ERATT
;
2857 phba
->work_hs
= HS_FFER3
;
2859 lpfc_worker_wake_up(phba
);
2865 * lpfc_poll_eratt - Error attention polling timer timeout handler
2866 * @ptr: Pointer to address of HBA context object.
2868 * This function is invoked by the Error Attention polling timer when the
2869 * timer times out. It will check the SLI Error Attention register for
2870 * possible attention events. If so, it will post an Error Attention event
2871 * and wake up worker thread to process it. Otherwise, it will set up the
2872 * Error Attention polling timer for the next poll.
2874 void lpfc_poll_eratt(unsigned long ptr
)
2876 struct lpfc_hba
*phba
;
2877 uint32_t eratt
= 0, rem
;
2878 uint64_t sli_intr
, cnt
;
2880 phba
= (struct lpfc_hba
*)ptr
;
2882 /* Here we will also keep track of interrupts per sec of the hba */
2883 sli_intr
= phba
->sli
.slistat
.sli_intr
;
2885 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
2886 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
2889 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
2891 /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
2892 rem
= do_div(cnt
, LPFC_ERATT_POLL_INTERVAL
);
2893 phba
->sli
.slistat
.sli_ips
= cnt
;
2895 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
2897 /* Check chip HA register for error event */
2898 eratt
= lpfc_sli_check_eratt(phba
);
2901 /* Tell the worker thread there is work to do */
2902 lpfc_worker_wake_up(phba
);
2904 /* Restart the timer for next eratt poll */
2905 mod_timer(&phba
->eratt_poll
,
2907 msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL
));
2913 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2914 * @phba: Pointer to HBA context object.
2915 * @pring: Pointer to driver SLI ring object.
2916 * @mask: Host attention register mask for this ring.
2918 * This function is called from the interrupt context when there is a ring
2919 * event for the fcp ring. The caller does not hold any lock.
2920 * The function processes each response iocb in the response ring until it
2921 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2922 * LE bit set. The function will call the completion handler of the command iocb
2923 * if the response iocb indicates a completion for a command iocb or it is
2924 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2925 * function if this is an unsolicited iocb.
2926 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2927 * to check it explicitly.
2930 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2931 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2933 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2934 IOCB_t
*irsp
= NULL
;
2935 IOCB_t
*entry
= NULL
;
2936 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2937 struct lpfc_iocbq rspiocbq
;
2939 uint32_t portRspPut
, portRspMax
;
2941 lpfc_iocb_type type
;
2942 unsigned long iflag
;
2943 uint32_t rsp_cmpl
= 0;
2945 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2946 pring
->stats
.iocb_event
++;
2949 * The next available response entry should never exceed the maximum
2950 * entries. If it does, treat it as an adapter hardware error.
2952 portRspMax
= pring
->sli
.sli3
.numRiocb
;
2953 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2954 if (unlikely(portRspPut
>= portRspMax
)) {
2955 lpfc_sli_rsp_pointers_error(phba
, pring
);
2956 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2959 if (phba
->fcp_ring_in_use
) {
2960 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2963 phba
->fcp_ring_in_use
= 1;
2966 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
2968 * Fetch an entry off the ring and copy it into a local data
2969 * structure. The copy involves a byte-swap since the
2970 * network byte order and pci byte orders are different.
2972 entry
= lpfc_resp_iocb(phba
, pring
);
2973 phba
->last_completion_time
= jiffies
;
2975 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
2976 pring
->sli
.sli3
.rspidx
= 0;
2978 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2979 (uint32_t *) &rspiocbq
.iocb
,
2980 phba
->iocb_rsp_size
);
2981 INIT_LIST_HEAD(&(rspiocbq
.list
));
2982 irsp
= &rspiocbq
.iocb
;
2984 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2985 pring
->stats
.iocb_rsp
++;
2988 if (unlikely(irsp
->ulpStatus
)) {
2990 * If resource errors reported from HBA, reduce
2991 * queuedepths of the SCSI device.
2993 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2994 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
2995 IOERR_NO_RESOURCES
)) {
2996 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2997 phba
->lpfc_rampdown_queue_depth(phba
);
2998 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3001 /* Rsp ring <ringno> error: IOCB */
3002 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3003 "0336 Rsp Ring %d error: IOCB Data: "
3004 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3006 irsp
->un
.ulpWord
[0],
3007 irsp
->un
.ulpWord
[1],
3008 irsp
->un
.ulpWord
[2],
3009 irsp
->un
.ulpWord
[3],
3010 irsp
->un
.ulpWord
[4],
3011 irsp
->un
.ulpWord
[5],
3012 *(uint32_t *)&irsp
->un1
,
3013 *((uint32_t *)&irsp
->un1
+ 1));
3017 case LPFC_ABORT_IOCB
:
3020 * Idle exchange closed via ABTS from port. No iocb
3021 * resources need to be recovered.
3023 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3024 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3025 "0333 IOCB cmd 0x%x"
3026 " processed. Skipping"
3032 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3034 if (unlikely(!cmdiocbq
))
3036 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3037 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3038 if (cmdiocbq
->iocb_cmpl
) {
3039 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3040 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3042 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3045 case LPFC_UNSOL_IOCB
:
3046 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3047 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3048 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3051 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3052 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3053 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3054 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3056 dev_warn(&((phba
->pcidev
)->dev
),
3058 phba
->brd_no
, adaptermsg
);
3060 /* Unknown IOCB command */
3061 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3062 "0334 Unknown IOCB command "
3063 "Data: x%x, x%x x%x x%x x%x\n",
3064 type
, irsp
->ulpCommand
,
3073 * The response IOCB has been processed. Update the ring
3074 * pointer in SLIM. If the port response put pointer has not
3075 * been updated, sync the pgp->rspPutInx and fetch the new port
3076 * response put pointer.
3078 writel(pring
->sli
.sli3
.rspidx
,
3079 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3081 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3082 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3085 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3086 pring
->stats
.iocb_rsp_full
++;
3087 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3088 writel(status
, phba
->CAregaddr
);
3089 readl(phba
->CAregaddr
);
3091 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3092 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3093 pring
->stats
.iocb_cmd_empty
++;
3095 /* Force update of the local copy of cmdGetInx */
3096 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3097 lpfc_sli_resume_iocb(phba
, pring
);
3099 if ((pring
->lpfc_sli_cmd_available
))
3100 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3104 phba
->fcp_ring_in_use
= 0;
3105 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3110 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3111 * @phba: Pointer to HBA context object.
3112 * @pring: Pointer to driver SLI ring object.
3113 * @rspiocbp: Pointer to driver response IOCB object.
3115 * This function is called from the worker thread when there is a slow-path
3116 * response IOCB to process. This function chains all the response iocbs until
3117 * seeing the iocb with the LE bit set. The function will call
3118 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3119 * completion of a command iocb. The function will call the
3120 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3121 * The function frees the resources or calls the completion handler if this
3122 * iocb is an abort completion. The function returns NULL when the response
3123 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3124 * this function shall chain the iocb on to the iocb_continueq and return the
3125 * response iocb passed in.
3127 static struct lpfc_iocbq
*
3128 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3129 struct lpfc_iocbq
*rspiocbp
)
3131 struct lpfc_iocbq
*saveq
;
3132 struct lpfc_iocbq
*cmdiocbp
;
3133 struct lpfc_iocbq
*next_iocb
;
3134 IOCB_t
*irsp
= NULL
;
3135 uint32_t free_saveq
;
3136 uint8_t iocb_cmd_type
;
3137 lpfc_iocb_type type
;
3138 unsigned long iflag
;
3141 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3142 /* First add the response iocb to the countinueq list */
3143 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3144 pring
->iocb_continueq_cnt
++;
3146 /* Now, determine whether the list is completed for processing */
3147 irsp
= &rspiocbp
->iocb
;
3150 * By default, the driver expects to free all resources
3151 * associated with this iocb completion.
3154 saveq
= list_get_first(&pring
->iocb_continueq
,
3155 struct lpfc_iocbq
, list
);
3156 irsp
= &(saveq
->iocb
);
3157 list_del_init(&pring
->iocb_continueq
);
3158 pring
->iocb_continueq_cnt
= 0;
3160 pring
->stats
.iocb_rsp
++;
3163 * If resource errors reported from HBA, reduce
3164 * queuedepths of the SCSI device.
3166 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3167 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3168 IOERR_NO_RESOURCES
)) {
3169 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3170 phba
->lpfc_rampdown_queue_depth(phba
);
3171 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3174 if (irsp
->ulpStatus
) {
3175 /* Rsp ring <ringno> error: IOCB */
3176 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3177 "0328 Rsp Ring %d error: "
3182 "x%x x%x x%x x%x\n",
3184 irsp
->un
.ulpWord
[0],
3185 irsp
->un
.ulpWord
[1],
3186 irsp
->un
.ulpWord
[2],
3187 irsp
->un
.ulpWord
[3],
3188 irsp
->un
.ulpWord
[4],
3189 irsp
->un
.ulpWord
[5],
3190 *(((uint32_t *) irsp
) + 6),
3191 *(((uint32_t *) irsp
) + 7),
3192 *(((uint32_t *) irsp
) + 8),
3193 *(((uint32_t *) irsp
) + 9),
3194 *(((uint32_t *) irsp
) + 10),
3195 *(((uint32_t *) irsp
) + 11),
3196 *(((uint32_t *) irsp
) + 12),
3197 *(((uint32_t *) irsp
) + 13),
3198 *(((uint32_t *) irsp
) + 14),
3199 *(((uint32_t *) irsp
) + 15));
3203 * Fetch the IOCB command type and call the correct completion
3204 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3205 * get freed back to the lpfc_iocb_list by the discovery
3208 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3209 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3212 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3213 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3214 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3217 case LPFC_UNSOL_IOCB
:
3218 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3219 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3220 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3225 case LPFC_ABORT_IOCB
:
3227 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3228 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3231 /* Call the specified completion routine */
3232 if (cmdiocbp
->iocb_cmpl
) {
3233 spin_unlock_irqrestore(&phba
->hbalock
,
3235 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3237 spin_lock_irqsave(&phba
->hbalock
,
3240 __lpfc_sli_release_iocbq(phba
,
3245 case LPFC_UNKNOWN_IOCB
:
3246 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3247 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3248 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3249 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3251 dev_warn(&((phba
->pcidev
)->dev
),
3253 phba
->brd_no
, adaptermsg
);
3255 /* Unknown IOCB command */
3256 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3257 "0335 Unknown IOCB "
3258 "command Data: x%x "
3269 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3270 &saveq
->list
, list
) {
3271 list_del_init(&rspiocbp
->list
);
3272 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3274 __lpfc_sli_release_iocbq(phba
, saveq
);
3278 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3283 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3284 * @phba: Pointer to HBA context object.
3285 * @pring: Pointer to driver SLI ring object.
3286 * @mask: Host attention register mask for this ring.
3288 * This routine wraps the actual slow_ring event process routine from the
3289 * API jump table function pointer from the lpfc_hba struct.
3292 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3293 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3295 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3299 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3300 * @phba: Pointer to HBA context object.
3301 * @pring: Pointer to driver SLI ring object.
3302 * @mask: Host attention register mask for this ring.
3304 * This function is called from the worker thread when there is a ring event
3305 * for non-fcp rings. The caller does not hold any lock. The function will
3306 * remove each response iocb in the response ring and calls the handle
3307 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3310 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3311 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3313 struct lpfc_pgp
*pgp
;
3315 IOCB_t
*irsp
= NULL
;
3316 struct lpfc_iocbq
*rspiocbp
= NULL
;
3317 uint32_t portRspPut
, portRspMax
;
3318 unsigned long iflag
;
3321 pgp
= &phba
->port_gp
[pring
->ringno
];
3322 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3323 pring
->stats
.iocb_event
++;
3326 * The next available response entry should never exceed the maximum
3327 * entries. If it does, treat it as an adapter hardware error.
3329 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3330 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3331 if (portRspPut
>= portRspMax
) {
3333 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3334 * rsp ring <portRspMax>
3336 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3337 "0303 Ring %d handler: portRspPut %d "
3338 "is bigger than rsp ring %d\n",
3339 pring
->ringno
, portRspPut
, portRspMax
);
3341 phba
->link_state
= LPFC_HBA_ERROR
;
3342 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3344 phba
->work_hs
= HS_FFER3
;
3345 lpfc_handle_eratt(phba
);
3351 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3353 * Build a completion list and call the appropriate handler.
3354 * The process is to get the next available response iocb, get
3355 * a free iocb from the list, copy the response data into the
3356 * free iocb, insert to the continuation list, and update the
3357 * next response index to slim. This process makes response
3358 * iocb's in the ring available to DMA as fast as possible but
3359 * pays a penalty for a copy operation. Since the iocb is
3360 * only 32 bytes, this penalty is considered small relative to
3361 * the PCI reads for register values and a slim write. When
3362 * the ulpLe field is set, the entire Command has been
3365 entry
= lpfc_resp_iocb(phba
, pring
);
3367 phba
->last_completion_time
= jiffies
;
3368 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3369 if (rspiocbp
== NULL
) {
3370 printk(KERN_ERR
"%s: out of buffers! Failing "
3371 "completion.\n", __func__
);
3375 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3376 phba
->iocb_rsp_size
);
3377 irsp
= &rspiocbp
->iocb
;
3379 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3380 pring
->sli
.sli3
.rspidx
= 0;
3382 if (pring
->ringno
== LPFC_ELS_RING
) {
3383 lpfc_debugfs_slow_ring_trc(phba
,
3384 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3385 *(((uint32_t *) irsp
) + 4),
3386 *(((uint32_t *) irsp
) + 6),
3387 *(((uint32_t *) irsp
) + 7));
3390 writel(pring
->sli
.sli3
.rspidx
,
3391 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3393 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3394 /* Handle the response IOCB */
3395 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3396 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3399 * If the port response put pointer has not been updated, sync
3400 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3401 * response put pointer.
3403 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3404 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3406 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3408 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3409 /* At least one response entry has been freed */
3410 pring
->stats
.iocb_rsp_full
++;
3411 /* SET RxRE_RSP in Chip Att register */
3412 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3413 writel(status
, phba
->CAregaddr
);
3414 readl(phba
->CAregaddr
); /* flush */
3416 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3417 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3418 pring
->stats
.iocb_cmd_empty
++;
3420 /* Force update of the local copy of cmdGetInx */
3421 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3422 lpfc_sli_resume_iocb(phba
, pring
);
3424 if ((pring
->lpfc_sli_cmd_available
))
3425 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3429 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3434 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3435 * @phba: Pointer to HBA context object.
3436 * @pring: Pointer to driver SLI ring object.
3437 * @mask: Host attention register mask for this ring.
3439 * This function is called from the worker thread when there is a pending
3440 * ELS response iocb on the driver internal slow-path response iocb worker
3441 * queue. The caller does not hold any lock. The function will remove each
3442 * response iocb from the response worker queue and calls the handle
3443 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3446 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3447 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3449 struct lpfc_iocbq
*irspiocbq
;
3450 struct hbq_dmabuf
*dmabuf
;
3451 struct lpfc_cq_event
*cq_event
;
3452 unsigned long iflag
;
3454 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3455 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3456 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3457 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3458 /* Get the response iocb from the head of work queue */
3459 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3460 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3461 cq_event
, struct lpfc_cq_event
, list
);
3462 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3464 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3465 case CQE_CODE_COMPL_WQE
:
3466 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3468 /* Translate ELS WCQE to response IOCBQ */
3469 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3472 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3475 case CQE_CODE_RECEIVE
:
3476 case CQE_CODE_RECEIVE_V1
:
3477 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3479 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3488 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3489 * @phba: Pointer to HBA context object.
3490 * @pring: Pointer to driver SLI ring object.
3492 * This function aborts all iocbs in the given ring and frees all the iocb
3493 * objects in txq. This function issues an abort iocb for all the iocb commands
3494 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3495 * the return of this function. The caller is not required to hold any locks.
3498 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3500 LIST_HEAD(completions
);
3501 struct lpfc_iocbq
*iocb
, *next_iocb
;
3503 if (pring
->ringno
== LPFC_ELS_RING
) {
3504 lpfc_fabric_abort_hba(phba
);
3507 /* Error everything on txq and txcmplq
3510 spin_lock_irq(&phba
->hbalock
);
3511 list_splice_init(&pring
->txq
, &completions
);
3513 /* Next issue ABTS for everything on the txcmplq */
3514 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3515 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3517 spin_unlock_irq(&phba
->hbalock
);
3519 /* Cancel all the IOCBs from the completions list */
3520 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3525 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3526 * @phba: Pointer to HBA context object.
3528 * This function flushes all iocbs in the fcp ring and frees all the iocb
3529 * objects in txq and txcmplq. This function will not issue abort iocbs
3530 * for all the iocb commands in txcmplq, they will just be returned with
3531 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3532 * slot has been permanently disabled.
3535 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3539 struct lpfc_sli
*psli
= &phba
->sli
;
3540 struct lpfc_sli_ring
*pring
;
3542 /* Currently, only one fcp ring */
3543 pring
= &psli
->ring
[psli
->fcp_ring
];
3545 spin_lock_irq(&phba
->hbalock
);
3546 /* Retrieve everything on txq */
3547 list_splice_init(&pring
->txq
, &txq
);
3549 /* Retrieve everything on the txcmplq */
3550 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3552 /* Indicate the I/O queues are flushed */
3553 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3554 spin_unlock_irq(&phba
->hbalock
);
3557 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3560 /* Flush the txcmpq */
3561 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3566 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3567 * @phba: Pointer to HBA context object.
3568 * @mask: Bit mask to be checked.
3570 * This function reads the host status register and compares
3571 * with the provided bit mask to check if HBA completed
3572 * the restart. This function will wait in a loop for the
3573 * HBA to complete restart. If the HBA does not restart within
3574 * 15 iterations, the function will reset the HBA again. The
3575 * function returns 1 when HBA fail to restart otherwise returns
3579 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3585 /* Read the HBA Host Status Register */
3586 if (lpfc_readl(phba
->HSregaddr
, &status
))
3590 * Check status register every 100ms for 5 retries, then every
3591 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3592 * every 2.5 sec for 4.
3593 * Break our of the loop if errors occurred during init.
3595 while (((status
& mask
) != mask
) &&
3596 !(status
& HS_FFERM
) &&
3608 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3609 lpfc_sli_brdrestart(phba
);
3611 /* Read the HBA Host Status Register */
3612 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3618 /* Check to see if any errors occurred during init */
3619 if ((status
& HS_FFERM
) || (i
>= 20)) {
3620 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3621 "2751 Adapter failed to restart, "
3622 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3624 readl(phba
->MBslimaddr
+ 0xa8),
3625 readl(phba
->MBslimaddr
+ 0xac));
3626 phba
->link_state
= LPFC_HBA_ERROR
;
3634 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3635 * @phba: Pointer to HBA context object.
3636 * @mask: Bit mask to be checked.
3638 * This function checks the host status register to check if HBA is
3639 * ready. This function will wait in a loop for the HBA to be ready
3640 * If the HBA is not ready , the function will will reset the HBA PCI
3641 * function again. The function returns 1 when HBA fail to be ready
3642 * otherwise returns zero.
3645 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3650 /* Read the HBA Host Status Register */
3651 status
= lpfc_sli4_post_status_check(phba
);
3654 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3655 lpfc_sli_brdrestart(phba
);
3656 status
= lpfc_sli4_post_status_check(phba
);
3659 /* Check to see if any errors occurred during init */
3661 phba
->link_state
= LPFC_HBA_ERROR
;
3664 phba
->sli4_hba
.intr_enable
= 0;
3670 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3671 * @phba: Pointer to HBA context object.
3672 * @mask: Bit mask to be checked.
3674 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3675 * from the API jump table function pointer from the lpfc_hba struct.
3678 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3680 return phba
->lpfc_sli_brdready(phba
, mask
);
3683 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3686 * lpfc_reset_barrier - Make HBA ready for HBA reset
3687 * @phba: Pointer to HBA context object.
3689 * This function is called before resetting an HBA. This function is called
3690 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3692 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3694 uint32_t __iomem
*resp_buf
;
3695 uint32_t __iomem
*mbox_buf
;
3696 volatile uint32_t mbox
;
3697 uint32_t hc_copy
, ha_copy
, resp_data
;
3701 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3702 if (hdrtype
!= 0x80 ||
3703 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3704 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3708 * Tell the other part of the chip to suspend temporarily all
3711 resp_buf
= phba
->MBslimaddr
;
3713 /* Disable the error attention */
3714 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3716 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3717 readl(phba
->HCregaddr
); /* flush */
3718 phba
->link_flag
|= LS_IGNORE_ERATT
;
3720 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3722 if (ha_copy
& HA_ERATT
) {
3723 /* Clear Chip error bit */
3724 writel(HA_ERATT
, phba
->HAregaddr
);
3725 phba
->pport
->stopped
= 1;
3729 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3730 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3732 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3733 mbox_buf
= phba
->MBslimaddr
;
3734 writel(mbox
, mbox_buf
);
3736 for (i
= 0; i
< 50; i
++) {
3737 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3739 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3745 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3747 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3748 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3749 phba
->pport
->stopped
)
3755 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3757 for (i
= 0; i
< 500; i
++) {
3758 if (lpfc_readl(resp_buf
, &resp_data
))
3760 if (resp_data
!= mbox
)
3769 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3771 if (!(ha_copy
& HA_ERATT
))
3777 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3778 writel(HA_ERATT
, phba
->HAregaddr
);
3779 phba
->pport
->stopped
= 1;
3783 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3784 writel(hc_copy
, phba
->HCregaddr
);
3785 readl(phba
->HCregaddr
); /* flush */
3789 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3790 * @phba: Pointer to HBA context object.
3792 * This function issues a kill_board mailbox command and waits for
3793 * the error attention interrupt. This function is called for stopping
3794 * the firmware processing. The caller is not required to hold any
3795 * locks. This function calls lpfc_hba_down_post function to free
3796 * any pending commands after the kill. The function will return 1 when it
3797 * fails to kill the board else will return 0.
3800 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3802 struct lpfc_sli
*psli
;
3812 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3813 "0329 Kill HBA Data: x%x x%x\n",
3814 phba
->pport
->port_state
, psli
->sli_flag
);
3816 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3820 /* Disable the error attention */
3821 spin_lock_irq(&phba
->hbalock
);
3822 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3823 spin_unlock_irq(&phba
->hbalock
);
3824 mempool_free(pmb
, phba
->mbox_mem_pool
);
3827 status
&= ~HC_ERINT_ENA
;
3828 writel(status
, phba
->HCregaddr
);
3829 readl(phba
->HCregaddr
); /* flush */
3830 phba
->link_flag
|= LS_IGNORE_ERATT
;
3831 spin_unlock_irq(&phba
->hbalock
);
3833 lpfc_kill_board(phba
, pmb
);
3834 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3835 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3837 if (retval
!= MBX_SUCCESS
) {
3838 if (retval
!= MBX_BUSY
)
3839 mempool_free(pmb
, phba
->mbox_mem_pool
);
3840 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3841 "2752 KILL_BOARD command failed retval %d\n",
3843 spin_lock_irq(&phba
->hbalock
);
3844 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3845 spin_unlock_irq(&phba
->hbalock
);
3849 spin_lock_irq(&phba
->hbalock
);
3850 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3851 spin_unlock_irq(&phba
->hbalock
);
3853 mempool_free(pmb
, phba
->mbox_mem_pool
);
3855 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3856 * attention every 100ms for 3 seconds. If we don't get ERATT after
3857 * 3 seconds we still set HBA_ERROR state because the status of the
3858 * board is now undefined.
3860 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3862 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3864 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3868 del_timer_sync(&psli
->mbox_tmo
);
3869 if (ha_copy
& HA_ERATT
) {
3870 writel(HA_ERATT
, phba
->HAregaddr
);
3871 phba
->pport
->stopped
= 1;
3873 spin_lock_irq(&phba
->hbalock
);
3874 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3875 psli
->mbox_active
= NULL
;
3876 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3877 spin_unlock_irq(&phba
->hbalock
);
3879 lpfc_hba_down_post(phba
);
3880 phba
->link_state
= LPFC_HBA_ERROR
;
3882 return ha_copy
& HA_ERATT
? 0 : 1;
3886 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3887 * @phba: Pointer to HBA context object.
3889 * This function resets the HBA by writing HC_INITFF to the control
3890 * register. After the HBA resets, this function resets all the iocb ring
3891 * indices. This function disables PCI layer parity checking during
3893 * This function returns 0 always.
3894 * The caller is not required to hold any locks.
3897 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3899 struct lpfc_sli
*psli
;
3900 struct lpfc_sli_ring
*pring
;
3907 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3908 "0325 Reset HBA Data: x%x x%x\n",
3909 phba
->pport
->port_state
, psli
->sli_flag
);
3911 /* perform board reset */
3912 phba
->fc_eventTag
= 0;
3913 phba
->link_events
= 0;
3914 phba
->pport
->fc_myDID
= 0;
3915 phba
->pport
->fc_prevDID
= 0;
3917 /* Turn off parity checking and serr during the physical reset */
3918 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3919 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3921 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3923 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3925 /* Now toggle INITFF bit in the Host Control Register */
3926 writel(HC_INITFF
, phba
->HCregaddr
);
3928 readl(phba
->HCregaddr
); /* flush */
3929 writel(0, phba
->HCregaddr
);
3930 readl(phba
->HCregaddr
); /* flush */
3932 /* Restore PCI cmd register */
3933 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3935 /* Initialize relevant SLI info */
3936 for (i
= 0; i
< psli
->num_rings
; i
++) {
3937 pring
= &psli
->ring
[i
];
3939 pring
->sli
.sli3
.rspidx
= 0;
3940 pring
->sli
.sli3
.next_cmdidx
= 0;
3941 pring
->sli
.sli3
.local_getidx
= 0;
3942 pring
->sli
.sli3
.cmdidx
= 0;
3943 pring
->missbufcnt
= 0;
3946 phba
->link_state
= LPFC_WARM_START
;
3951 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3952 * @phba: Pointer to HBA context object.
3954 * This function resets a SLI4 HBA. This function disables PCI layer parity
3955 * checking during resets the device. The caller is not required to hold
3958 * This function returns 0 always.
3961 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3963 struct lpfc_sli
*psli
= &phba
->sli
;
3968 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3969 "0295 Reset HBA Data: x%x x%x\n",
3970 phba
->pport
->port_state
, psli
->sli_flag
);
3972 /* perform board reset */
3973 phba
->fc_eventTag
= 0;
3974 phba
->link_events
= 0;
3975 phba
->pport
->fc_myDID
= 0;
3976 phba
->pport
->fc_prevDID
= 0;
3978 spin_lock_irq(&phba
->hbalock
);
3979 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3980 phba
->fcf
.fcf_flag
= 0;
3981 spin_unlock_irq(&phba
->hbalock
);
3983 /* Now physically reset the device */
3984 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3985 "0389 Performing PCI function reset!\n");
3987 /* Turn off parity checking and serr during the physical reset */
3988 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3989 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3990 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3992 /* Perform FCoE PCI function reset before freeing queue memory */
3993 rc
= lpfc_pci_function_reset(phba
);
3994 lpfc_sli4_queue_destroy(phba
);
3996 /* Restore PCI cmd register */
3997 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4003 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4004 * @phba: Pointer to HBA context object.
4006 * This function is called in the SLI initialization code path to
4007 * restart the HBA. The caller is not required to hold any lock.
4008 * This function writes MBX_RESTART mailbox command to the SLIM and
4009 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4010 * function to free any pending commands. The function enables
4011 * POST only during the first initialization. The function returns zero.
4012 * The function does not guarantee completion of MBX_RESTART mailbox
4013 * command before the return of this function.
4016 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4019 struct lpfc_sli
*psli
;
4020 volatile uint32_t word0
;
4021 void __iomem
*to_slim
;
4022 uint32_t hba_aer_enabled
;
4024 spin_lock_irq(&phba
->hbalock
);
4026 /* Take PCIe device Advanced Error Reporting (AER) state */
4027 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4032 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4033 "0337 Restart HBA Data: x%x x%x\n",
4034 phba
->pport
->port_state
, psli
->sli_flag
);
4037 mb
= (MAILBOX_t
*) &word0
;
4038 mb
->mbxCommand
= MBX_RESTART
;
4041 lpfc_reset_barrier(phba
);
4043 to_slim
= phba
->MBslimaddr
;
4044 writel(*(uint32_t *) mb
, to_slim
);
4045 readl(to_slim
); /* flush */
4047 /* Only skip post after fc_ffinit is completed */
4048 if (phba
->pport
->port_state
)
4049 word0
= 1; /* This is really setting up word1 */
4051 word0
= 0; /* This is really setting up word1 */
4052 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4053 writel(*(uint32_t *) mb
, to_slim
);
4054 readl(to_slim
); /* flush */
4056 lpfc_sli_brdreset(phba
);
4057 phba
->pport
->stopped
= 0;
4058 phba
->link_state
= LPFC_INIT_START
;
4060 spin_unlock_irq(&phba
->hbalock
);
4062 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4063 psli
->stats_start
= get_seconds();
4065 /* Give the INITFF and Post time to settle. */
4068 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4069 if (hba_aer_enabled
)
4070 pci_disable_pcie_error_reporting(phba
->pcidev
);
4072 lpfc_hba_down_post(phba
);
4078 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4079 * @phba: Pointer to HBA context object.
4081 * This function is called in the SLI initialization code path to restart
4082 * a SLI4 HBA. The caller is not required to hold any lock.
4083 * At the end of the function, it calls lpfc_hba_down_post function to
4084 * free any pending commands.
4087 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4089 struct lpfc_sli
*psli
= &phba
->sli
;
4090 uint32_t hba_aer_enabled
;
4094 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4095 "0296 Restart HBA Data: x%x x%x\n",
4096 phba
->pport
->port_state
, psli
->sli_flag
);
4098 /* Take PCIe device Advanced Error Reporting (AER) state */
4099 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4101 rc
= lpfc_sli4_brdreset(phba
);
4103 spin_lock_irq(&phba
->hbalock
);
4104 phba
->pport
->stopped
= 0;
4105 phba
->link_state
= LPFC_INIT_START
;
4107 spin_unlock_irq(&phba
->hbalock
);
4109 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4110 psli
->stats_start
= get_seconds();
4112 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4113 if (hba_aer_enabled
)
4114 pci_disable_pcie_error_reporting(phba
->pcidev
);
4116 lpfc_hba_down_post(phba
);
4122 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4123 * @phba: Pointer to HBA context object.
4125 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4126 * API jump table function pointer from the lpfc_hba struct.
4129 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4131 return phba
->lpfc_sli_brdrestart(phba
);
4135 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4136 * @phba: Pointer to HBA context object.
4138 * This function is called after a HBA restart to wait for successful
4139 * restart of the HBA. Successful restart of the HBA is indicated by
4140 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4141 * iteration, the function will restart the HBA again. The function returns
4142 * zero if HBA successfully restarted else returns negative error code.
4145 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4147 uint32_t status
, i
= 0;
4149 /* Read the HBA Host Status Register */
4150 if (lpfc_readl(phba
->HSregaddr
, &status
))
4153 /* Check status register to see what current state is */
4155 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4157 /* Check every 10ms for 10 retries, then every 100ms for 90
4158 * retries, then every 1 sec for 50 retires for a total of
4159 * ~60 seconds before reset the board again and check every
4160 * 1 sec for 50 retries. The up to 60 seconds before the
4161 * board ready is required by the Falcon FIPS zeroization
4162 * complete, and any reset the board in between shall cause
4163 * restart of zeroization, further delay the board ready.
4166 /* Adapter failed to init, timeout, status reg
4168 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4169 "0436 Adapter failed to init, "
4170 "timeout, status reg x%x, "
4171 "FW Data: A8 x%x AC x%x\n", status
,
4172 readl(phba
->MBslimaddr
+ 0xa8),
4173 readl(phba
->MBslimaddr
+ 0xac));
4174 phba
->link_state
= LPFC_HBA_ERROR
;
4178 /* Check to see if any errors occurred during init */
4179 if (status
& HS_FFERM
) {
4180 /* ERROR: During chipset initialization */
4181 /* Adapter failed to init, chipset, status reg
4183 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4184 "0437 Adapter failed to init, "
4185 "chipset, status reg x%x, "
4186 "FW Data: A8 x%x AC x%x\n", status
,
4187 readl(phba
->MBslimaddr
+ 0xa8),
4188 readl(phba
->MBslimaddr
+ 0xac));
4189 phba
->link_state
= LPFC_HBA_ERROR
;
4202 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4203 lpfc_sli_brdrestart(phba
);
4205 /* Read the HBA Host Status Register */
4206 if (lpfc_readl(phba
->HSregaddr
, &status
))
4210 /* Check to see if any errors occurred during init */
4211 if (status
& HS_FFERM
) {
4212 /* ERROR: During chipset initialization */
4213 /* Adapter failed to init, chipset, status reg <status> */
4214 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4215 "0438 Adapter failed to init, chipset, "
4217 "FW Data: A8 x%x AC x%x\n", status
,
4218 readl(phba
->MBslimaddr
+ 0xa8),
4219 readl(phba
->MBslimaddr
+ 0xac));
4220 phba
->link_state
= LPFC_HBA_ERROR
;
4224 /* Clear all interrupt enable conditions */
4225 writel(0, phba
->HCregaddr
);
4226 readl(phba
->HCregaddr
); /* flush */
4228 /* setup host attn register */
4229 writel(0xffffffff, phba
->HAregaddr
);
4230 readl(phba
->HAregaddr
); /* flush */
4235 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4237 * This function calculates and returns the number of HBQs required to be
4241 lpfc_sli_hbq_count(void)
4243 return ARRAY_SIZE(lpfc_hbq_defs
);
4247 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4249 * This function adds the number of hbq entries in every HBQ to get
4250 * the total number of hbq entries required for the HBA and returns
4254 lpfc_sli_hbq_entry_count(void)
4256 int hbq_count
= lpfc_sli_hbq_count();
4260 for (i
= 0; i
< hbq_count
; ++i
)
4261 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4266 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4268 * This function calculates amount of memory required for all hbq entries
4269 * to be configured and returns the total memory required.
4272 lpfc_sli_hbq_size(void)
4274 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4278 * lpfc_sli_hbq_setup - configure and initialize HBQs
4279 * @phba: Pointer to HBA context object.
4281 * This function is called during the SLI initialization to configure
4282 * all the HBQs and post buffers to the HBQ. The caller is not
4283 * required to hold any locks. This function will return zero if successful
4284 * else it will return negative error code.
4287 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4289 int hbq_count
= lpfc_sli_hbq_count();
4293 uint32_t hbq_entry_index
;
4295 /* Get a Mailbox buffer to setup mailbox
4296 * commands for HBA initialization
4298 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4305 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4306 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4307 phba
->hbq_in_use
= 1;
4309 hbq_entry_index
= 0;
4310 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4311 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4312 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4313 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4314 phba
->hbqs
[hbqno
].entry_count
=
4315 lpfc_hbq_defs
[hbqno
]->entry_count
;
4316 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4317 hbq_entry_index
, pmb
);
4318 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4320 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4321 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4322 mbxStatus <status>, ring <num> */
4324 lpfc_printf_log(phba
, KERN_ERR
,
4325 LOG_SLI
| LOG_VPORT
,
4326 "1805 Adapter failed to init. "
4327 "Data: x%x x%x x%x\n",
4329 pmbox
->mbxStatus
, hbqno
);
4331 phba
->link_state
= LPFC_HBA_ERROR
;
4332 mempool_free(pmb
, phba
->mbox_mem_pool
);
4336 phba
->hbq_count
= hbq_count
;
4338 mempool_free(pmb
, phba
->mbox_mem_pool
);
4340 /* Initially populate or replenish the HBQs */
4341 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4342 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4347 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4348 * @phba: Pointer to HBA context object.
4350 * This function is called during the SLI initialization to configure
4351 * all the HBQs and post buffers to the HBQ. The caller is not
4352 * required to hold any locks. This function will return zero if successful
4353 * else it will return negative error code.
4356 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4358 phba
->hbq_in_use
= 1;
4359 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4360 phba
->hbq_count
= 1;
4361 /* Initially populate or replenish the HBQs */
4362 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4367 * lpfc_sli_config_port - Issue config port mailbox command
4368 * @phba: Pointer to HBA context object.
4369 * @sli_mode: sli mode - 2/3
4371 * This function is called by the sli intialization code path
4372 * to issue config_port mailbox command. This function restarts the
4373 * HBA firmware and issues a config_port mailbox command to configure
4374 * the SLI interface in the sli mode specified by sli_mode
4375 * variable. The caller is not required to hold any locks.
4376 * The function returns 0 if successful, else returns negative error
4380 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4383 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4385 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4387 phba
->link_state
= LPFC_HBA_ERROR
;
4391 phba
->sli_rev
= sli_mode
;
4392 while (resetcount
< 2 && !done
) {
4393 spin_lock_irq(&phba
->hbalock
);
4394 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4395 spin_unlock_irq(&phba
->hbalock
);
4396 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4397 lpfc_sli_brdrestart(phba
);
4398 rc
= lpfc_sli_chipset_init(phba
);
4402 spin_lock_irq(&phba
->hbalock
);
4403 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4404 spin_unlock_irq(&phba
->hbalock
);
4407 /* Call pre CONFIG_PORT mailbox command initialization. A
4408 * value of 0 means the call was successful. Any other
4409 * nonzero value is a failure, but if ERESTART is returned,
4410 * the driver may reset the HBA and try again.
4412 rc
= lpfc_config_port_prep(phba
);
4413 if (rc
== -ERESTART
) {
4414 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4419 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4420 lpfc_config_port(phba
, pmb
);
4421 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4422 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4423 LPFC_SLI3_HBQ_ENABLED
|
4424 LPFC_SLI3_CRP_ENABLED
|
4425 LPFC_SLI3_BG_ENABLED
|
4426 LPFC_SLI3_DSS_ENABLED
);
4427 if (rc
!= MBX_SUCCESS
) {
4428 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4429 "0442 Adapter failed to init, mbxCmd x%x "
4430 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4431 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4432 spin_lock_irq(&phba
->hbalock
);
4433 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4434 spin_unlock_irq(&phba
->hbalock
);
4437 /* Allow asynchronous mailbox command to go through */
4438 spin_lock_irq(&phba
->hbalock
);
4439 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4440 spin_unlock_irq(&phba
->hbalock
);
4443 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4444 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4445 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4446 "3110 Port did not grant ASABT\n");
4451 goto do_prep_failed
;
4453 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4454 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4456 goto do_prep_failed
;
4458 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4459 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4460 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4461 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4462 phba
->max_vpi
: phba
->max_vports
;
4466 phba
->fips_level
= 0;
4467 phba
->fips_spec_rev
= 0;
4468 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4469 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4470 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4471 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4472 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4473 "2850 Security Crypto Active. FIPS x%d "
4475 phba
->fips_level
, phba
->fips_spec_rev
);
4477 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4478 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4479 "2856 Config Port Security Crypto "
4481 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4483 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4484 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4485 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4486 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4488 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4489 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4491 if (phba
->cfg_enable_bg
) {
4492 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4493 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4495 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4496 "0443 Adapter did not grant "
4500 phba
->hbq_get
= NULL
;
4501 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4505 mempool_free(pmb
, phba
->mbox_mem_pool
);
4511 * lpfc_sli_hba_setup - SLI intialization function
4512 * @phba: Pointer to HBA context object.
4514 * This function is the main SLI intialization function. This function
4515 * is called by the HBA intialization code, HBA reset code and HBA
4516 * error attention handler code. Caller is not required to hold any
4517 * locks. This function issues config_port mailbox command to configure
4518 * the SLI, setup iocb rings and HBQ rings. In the end the function
4519 * calls the config_port_post function to issue init_link mailbox
4520 * command and to start the discovery. The function will return zero
4521 * if successful, else it will return negative error code.
4524 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4530 switch (lpfc_sli_mode
) {
4532 if (phba
->cfg_enable_npiv
) {
4533 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4534 "1824 NPIV enabled: Override lpfc_sli_mode "
4535 "parameter (%d) to auto (0).\n",
4545 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4546 "1819 Unrecognized lpfc_sli_mode "
4547 "parameter: %d.\n", lpfc_sli_mode
);
4552 rc
= lpfc_sli_config_port(phba
, mode
);
4554 if (rc
&& lpfc_sli_mode
== 3)
4555 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4556 "1820 Unable to select SLI-3. "
4557 "Not supported by adapter.\n");
4558 if (rc
&& mode
!= 2)
4559 rc
= lpfc_sli_config_port(phba
, 2);
4561 goto lpfc_sli_hba_setup_error
;
4563 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4564 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4565 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4567 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4568 "2709 This device supports "
4569 "Advanced Error Reporting (AER)\n");
4570 spin_lock_irq(&phba
->hbalock
);
4571 phba
->hba_flag
|= HBA_AER_ENABLED
;
4572 spin_unlock_irq(&phba
->hbalock
);
4574 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4575 "2708 This device does not support "
4576 "Advanced Error Reporting (AER): %d\n",
4578 phba
->cfg_aer_support
= 0;
4582 if (phba
->sli_rev
== 3) {
4583 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4584 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4586 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4587 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4588 phba
->sli3_options
= 0;
4591 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4592 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4593 phba
->sli_rev
, phba
->max_vpi
);
4594 rc
= lpfc_sli_ring_map(phba
);
4597 goto lpfc_sli_hba_setup_error
;
4599 /* Initialize VPIs. */
4600 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4602 * The VPI bitmask and physical ID array are allocated
4603 * and initialized once only - at driver load. A port
4604 * reset doesn't need to reinitialize this memory.
4606 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4607 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4608 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4610 if (!phba
->vpi_bmask
) {
4612 goto lpfc_sli_hba_setup_error
;
4615 phba
->vpi_ids
= kzalloc(
4616 (phba
->max_vpi
+1) * sizeof(uint16_t),
4618 if (!phba
->vpi_ids
) {
4619 kfree(phba
->vpi_bmask
);
4621 goto lpfc_sli_hba_setup_error
;
4623 for (i
= 0; i
< phba
->max_vpi
; i
++)
4624 phba
->vpi_ids
[i
] = i
;
4629 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4630 rc
= lpfc_sli_hbq_setup(phba
);
4632 goto lpfc_sli_hba_setup_error
;
4634 spin_lock_irq(&phba
->hbalock
);
4635 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4636 spin_unlock_irq(&phba
->hbalock
);
4638 rc
= lpfc_config_port_post(phba
);
4640 goto lpfc_sli_hba_setup_error
;
4644 lpfc_sli_hba_setup_error
:
4645 phba
->link_state
= LPFC_HBA_ERROR
;
4646 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4647 "0445 Firmware initialization failed\n");
4652 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4653 * @phba: Pointer to HBA context object.
4654 * @mboxq: mailbox pointer.
4655 * This function issue a dump mailbox command to read config region
4656 * 23 and parse the records in the region and populate driver
4660 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4662 LPFC_MBOXQ_t
*mboxq
;
4663 struct lpfc_dmabuf
*mp
;
4664 struct lpfc_mqe
*mqe
;
4665 uint32_t data_length
;
4668 /* Program the default value of vlan_id and fc_map */
4669 phba
->valid_vlan
= 0;
4670 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4671 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4672 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4674 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4678 mqe
= &mboxq
->u
.mqe
;
4679 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4681 goto out_free_mboxq
;
4684 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4685 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4687 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4688 "(%d):2571 Mailbox cmd x%x Status x%x "
4689 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4690 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4691 "CQ: x%x x%x x%x x%x\n",
4692 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4693 bf_get(lpfc_mqe_command
, mqe
),
4694 bf_get(lpfc_mqe_status
, mqe
),
4695 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4696 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4697 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4698 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4699 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4700 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4701 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4702 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4703 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4705 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4706 mboxq
->mcqe
.trailer
);
4709 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4712 goto out_free_mboxq
;
4714 data_length
= mqe
->un
.mb_words
[5];
4715 if (data_length
> DMP_RGN23_SIZE
) {
4716 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4719 goto out_free_mboxq
;
4722 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4723 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4728 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4733 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4734 * @phba: pointer to lpfc hba data structure.
4735 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4736 * @vpd: pointer to the memory to hold resulting port vpd data.
4737 * @vpd_size: On input, the number of bytes allocated to @vpd.
4738 * On output, the number of data bytes in @vpd.
4740 * This routine executes a READ_REV SLI4 mailbox command. In
4741 * addition, this routine gets the port vpd data.
4745 * -ENOMEM - could not allocated memory.
4748 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4749 uint8_t *vpd
, uint32_t *vpd_size
)
4753 struct lpfc_dmabuf
*dmabuf
;
4754 struct lpfc_mqe
*mqe
;
4756 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4761 * Get a DMA buffer for the vpd data resulting from the READ_REV
4764 dma_size
= *vpd_size
;
4765 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4769 if (!dmabuf
->virt
) {
4773 memset(dmabuf
->virt
, 0, dma_size
);
4776 * The SLI4 implementation of READ_REV conflicts at word1,
4777 * bits 31:16 and SLI4 adds vpd functionality not present
4778 * in SLI3. This code corrects the conflicts.
4780 lpfc_read_rev(phba
, mboxq
);
4781 mqe
= &mboxq
->u
.mqe
;
4782 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4783 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4784 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4785 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4786 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4788 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4790 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4791 dmabuf
->virt
, dmabuf
->phys
);
4797 * The available vpd length cannot be bigger than the
4798 * DMA buffer passed to the port. Catch the less than
4799 * case and update the caller's size.
4801 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4802 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4804 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4806 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4807 dmabuf
->virt
, dmabuf
->phys
);
4813 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4814 * @phba: pointer to lpfc hba data structure.
4816 * This routine retrieves SLI4 device physical port name this PCI function
4821 * otherwise - failed to retrieve physical port name
4824 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4826 LPFC_MBOXQ_t
*mboxq
;
4827 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4828 struct lpfc_controller_attribute
*cntl_attr
;
4829 struct lpfc_mbx_get_port_name
*get_port_name
;
4830 void *virtaddr
= NULL
;
4831 uint32_t alloclen
, reqlen
;
4832 uint32_t shdr_status
, shdr_add_status
;
4833 union lpfc_sli4_cfg_shdr
*shdr
;
4834 char cport_name
= 0;
4837 /* We assume nothing at this point */
4838 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4839 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4841 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4844 /* obtain link type and link number via READ_CONFIG */
4845 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4846 lpfc_sli4_read_config(phba
);
4847 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4848 goto retrieve_ppname
;
4850 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4851 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4852 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4853 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4854 LPFC_SLI4_MBX_NEMBED
);
4855 if (alloclen
< reqlen
) {
4856 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4857 "3084 Allocated DMA memory size (%d) is "
4858 "less than the requested DMA memory size "
4859 "(%d)\n", alloclen
, reqlen
);
4861 goto out_free_mboxq
;
4863 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4864 virtaddr
= mboxq
->sge_array
->addr
[0];
4865 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4866 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4867 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4868 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4869 if (shdr_status
|| shdr_add_status
|| rc
) {
4870 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4871 "3085 Mailbox x%x (x%x/x%x) failed, "
4872 "rc:x%x, status:x%x, add_status:x%x\n",
4873 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4874 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4875 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4876 rc
, shdr_status
, shdr_add_status
);
4878 goto out_free_mboxq
;
4880 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4881 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4882 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4883 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4884 phba
->sli4_hba
.lnk_info
.lnk_no
=
4885 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4886 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4887 "3086 lnk_type:%d, lnk_numb:%d\n",
4888 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4889 phba
->sli4_hba
.lnk_info
.lnk_no
);
4892 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4893 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4894 sizeof(struct lpfc_mbx_get_port_name
) -
4895 sizeof(struct lpfc_sli4_cfg_mhdr
),
4896 LPFC_SLI4_MBX_EMBED
);
4897 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4898 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4899 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4900 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4901 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4902 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4903 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4904 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4905 if (shdr_status
|| shdr_add_status
|| rc
) {
4906 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4907 "3087 Mailbox x%x (x%x/x%x) failed: "
4908 "rc:x%x, status:x%x, add_status:x%x\n",
4909 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4910 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4911 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4912 rc
, shdr_status
, shdr_add_status
);
4914 goto out_free_mboxq
;
4916 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4917 case LPFC_LINK_NUMBER_0
:
4918 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4919 &get_port_name
->u
.response
);
4920 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4922 case LPFC_LINK_NUMBER_1
:
4923 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4924 &get_port_name
->u
.response
);
4925 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4927 case LPFC_LINK_NUMBER_2
:
4928 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4929 &get_port_name
->u
.response
);
4930 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4932 case LPFC_LINK_NUMBER_3
:
4933 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4934 &get_port_name
->u
.response
);
4935 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4941 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4942 phba
->Port
[0] = cport_name
;
4943 phba
->Port
[1] = '\0';
4944 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4945 "3091 SLI get port name: %s\n", phba
->Port
);
4949 if (rc
!= MBX_TIMEOUT
) {
4950 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4951 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4953 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4959 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4960 * @phba: pointer to lpfc hba data structure.
4962 * This routine is called to explicitly arm the SLI4 device's completion and
4966 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4970 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4971 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4973 if (phba
->sli4_hba
.fcp_cq
) {
4975 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4977 } while (++fcp_eqidx
< phba
->cfg_fcp_io_channel
);
4979 if (phba
->sli4_hba
.hba_eq
) {
4980 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
4982 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
4988 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4989 * @phba: Pointer to HBA context object.
4990 * @type: The resource extent type.
4991 * @extnt_count: buffer to hold port available extent count.
4992 * @extnt_size: buffer to hold element count per extent.
4994 * This function calls the port and retrievs the number of available
4995 * extents and their size for a particular extent type.
4997 * Returns: 0 if successful. Nonzero otherwise.
5000 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5001 uint16_t *extnt_count
, uint16_t *extnt_size
)
5006 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5009 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5013 /* Find out how many extents are available for this resource type */
5014 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5015 sizeof(struct lpfc_sli4_cfg_mhdr
));
5016 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5017 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5018 length
, LPFC_SLI4_MBX_EMBED
);
5020 /* Send an extents count of 0 - the GET doesn't use it. */
5021 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5022 LPFC_SLI4_MBX_EMBED
);
5028 if (!phba
->sli4_hba
.intr_enable
)
5029 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5031 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5032 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5039 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5040 if (bf_get(lpfc_mbox_hdr_status
,
5041 &rsrc_info
->header
.cfg_shdr
.response
)) {
5042 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5043 "2930 Failed to get resource extents "
5044 "Status 0x%x Add'l Status 0x%x\n",
5045 bf_get(lpfc_mbox_hdr_status
,
5046 &rsrc_info
->header
.cfg_shdr
.response
),
5047 bf_get(lpfc_mbox_hdr_add_status
,
5048 &rsrc_info
->header
.cfg_shdr
.response
));
5053 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5055 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5058 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5059 "3162 Retrieved extents type-%d from port: count:%d, "
5060 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5063 mempool_free(mbox
, phba
->mbox_mem_pool
);
5068 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5069 * @phba: Pointer to HBA context object.
5070 * @type: The extent type to check.
5072 * This function reads the current available extents from the port and checks
5073 * if the extent count or extent size has changed since the last access.
5074 * Callers use this routine post port reset to understand if there is a
5075 * extent reprovisioning requirement.
5078 * -Error: error indicates problem.
5079 * 1: Extent count or size has changed.
5083 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5085 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5086 uint16_t size_diff
, rsrc_ext_size
;
5088 struct lpfc_rsrc_blks
*rsrc_entry
;
5089 struct list_head
*rsrc_blk_list
= NULL
;
5093 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5100 case LPFC_RSC_TYPE_FCOE_RPI
:
5101 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5103 case LPFC_RSC_TYPE_FCOE_VPI
:
5104 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5106 case LPFC_RSC_TYPE_FCOE_XRI
:
5107 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5109 case LPFC_RSC_TYPE_FCOE_VFI
:
5110 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5116 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5118 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5122 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5129 * lpfc_sli4_cfg_post_extnts -
5130 * @phba: Pointer to HBA context object.
5131 * @extnt_cnt - number of available extents.
5132 * @type - the extent type (rpi, xri, vfi, vpi).
5133 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5134 * @mbox - pointer to the caller's allocated mailbox structure.
5136 * This function executes the extents allocation request. It also
5137 * takes care of the amount of memory needed to allocate or get the
5138 * allocated extents. It is the caller's responsibility to evaluate
5142 * -Error: Error value describes the condition found.
5146 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5147 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5152 uint32_t alloc_len
, mbox_tmo
;
5154 /* Calculate the total requested length of the dma memory */
5155 req_len
= extnt_cnt
* sizeof(uint16_t);
5158 * Calculate the size of an embedded mailbox. The uint32_t
5159 * accounts for extents-specific word.
5161 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5165 * Presume the allocation and response will fit into an embedded
5166 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5168 *emb
= LPFC_SLI4_MBX_EMBED
;
5169 if (req_len
> emb_len
) {
5170 req_len
= extnt_cnt
* sizeof(uint16_t) +
5171 sizeof(union lpfc_sli4_cfg_shdr
) +
5173 *emb
= LPFC_SLI4_MBX_NEMBED
;
5176 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5177 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5179 if (alloc_len
< req_len
) {
5180 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5181 "2982 Allocated DMA memory size (x%x) is "
5182 "less than the requested DMA memory "
5183 "size (x%x)\n", alloc_len
, req_len
);
5186 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5190 if (!phba
->sli4_hba
.intr_enable
)
5191 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5193 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5194 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5203 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5204 * @phba: Pointer to HBA context object.
5205 * @type: The resource extent type to allocate.
5207 * This function allocates the number of elements for the specified
5211 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5214 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5215 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5218 unsigned long longs
;
5219 unsigned long *bmask
;
5220 struct lpfc_rsrc_blks
*rsrc_blks
;
5223 struct lpfc_id_range
*id_array
= NULL
;
5224 void *virtaddr
= NULL
;
5225 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5226 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5227 struct list_head
*ext_blk_list
;
5229 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5235 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5236 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5237 "3009 No available Resource Extents "
5238 "for resource type 0x%x: Count: 0x%x, "
5239 "Size 0x%x\n", type
, rsrc_cnt
,
5244 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5245 "2903 Post resource extents type-0x%x: "
5246 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5248 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5252 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5259 * Figure out where the response is located. Then get local pointers
5260 * to the response data. The port does not guarantee to respond to
5261 * all extents counts request so update the local variable with the
5262 * allocated count from the port.
5264 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5265 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5266 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5267 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5269 virtaddr
= mbox
->sge_array
->addr
[0];
5270 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5271 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5272 id_array
= &n_rsrc
->id
;
5275 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5276 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5279 * Based on the resource size and count, correct the base and max
5282 length
= sizeof(struct lpfc_rsrc_blks
);
5284 case LPFC_RSC_TYPE_FCOE_RPI
:
5285 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5286 sizeof(unsigned long),
5288 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5292 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5295 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5296 kfree(phba
->sli4_hba
.rpi_bmask
);
5302 * The next_rpi was initialized with the maximum available
5303 * count but the port may allocate a smaller number. Catch
5304 * that case and update the next_rpi.
5306 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5308 /* Initialize local ptrs for common extent processing later. */
5309 bmask
= phba
->sli4_hba
.rpi_bmask
;
5310 ids
= phba
->sli4_hba
.rpi_ids
;
5311 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5313 case LPFC_RSC_TYPE_FCOE_VPI
:
5314 phba
->vpi_bmask
= kzalloc(longs
*
5315 sizeof(unsigned long),
5317 if (unlikely(!phba
->vpi_bmask
)) {
5321 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5324 if (unlikely(!phba
->vpi_ids
)) {
5325 kfree(phba
->vpi_bmask
);
5330 /* Initialize local ptrs for common extent processing later. */
5331 bmask
= phba
->vpi_bmask
;
5332 ids
= phba
->vpi_ids
;
5333 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5335 case LPFC_RSC_TYPE_FCOE_XRI
:
5336 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5337 sizeof(unsigned long),
5339 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5343 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5344 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5347 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5348 kfree(phba
->sli4_hba
.xri_bmask
);
5353 /* Initialize local ptrs for common extent processing later. */
5354 bmask
= phba
->sli4_hba
.xri_bmask
;
5355 ids
= phba
->sli4_hba
.xri_ids
;
5356 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5358 case LPFC_RSC_TYPE_FCOE_VFI
:
5359 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5360 sizeof(unsigned long),
5362 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5366 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5369 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5370 kfree(phba
->sli4_hba
.vfi_bmask
);
5375 /* Initialize local ptrs for common extent processing later. */
5376 bmask
= phba
->sli4_hba
.vfi_bmask
;
5377 ids
= phba
->sli4_hba
.vfi_ids
;
5378 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5381 /* Unsupported Opcode. Fail call. */
5385 ext_blk_list
= NULL
;
5390 * Complete initializing the extent configuration with the
5391 * allocated ids assigned to this function. The bitmask serves
5392 * as an index into the array and manages the available ids. The
5393 * array just stores the ids communicated to the port via the wqes.
5395 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5397 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5400 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5403 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5404 if (unlikely(!rsrc_blks
)) {
5410 rsrc_blks
->rsrc_start
= rsrc_id
;
5411 rsrc_blks
->rsrc_size
= rsrc_size
;
5412 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5413 rsrc_start
= rsrc_id
;
5414 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5415 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5416 lpfc_sli4_get_els_iocb_cnt(phba
);
5418 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5423 /* Entire word processed. Get next word.*/
5428 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5433 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5434 * @phba: Pointer to HBA context object.
5435 * @type: the extent's type.
5437 * This function deallocates all extents of a particular resource type.
5438 * SLI4 does not allow for deallocating a particular extent range. It
5439 * is the caller's responsibility to release all kernel memory resources.
5442 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5445 uint32_t length
, mbox_tmo
= 0;
5447 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5448 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5450 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5455 * This function sends an embedded mailbox because it only sends the
5456 * the resource type. All extents of this type are released by the
5459 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5460 sizeof(struct lpfc_sli4_cfg_mhdr
));
5461 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5462 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5463 length
, LPFC_SLI4_MBX_EMBED
);
5465 /* Send an extents count of 0 - the dealloc doesn't use it. */
5466 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5467 LPFC_SLI4_MBX_EMBED
);
5472 if (!phba
->sli4_hba
.intr_enable
)
5473 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5475 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5476 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5483 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5484 if (bf_get(lpfc_mbox_hdr_status
,
5485 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5486 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5487 "2919 Failed to release resource extents "
5488 "for type %d - Status 0x%x Add'l Status 0x%x. "
5489 "Resource memory not released.\n",
5491 bf_get(lpfc_mbox_hdr_status
,
5492 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5493 bf_get(lpfc_mbox_hdr_add_status
,
5494 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5499 /* Release kernel memory resources for the specific type. */
5501 case LPFC_RSC_TYPE_FCOE_VPI
:
5502 kfree(phba
->vpi_bmask
);
5503 kfree(phba
->vpi_ids
);
5504 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5505 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5506 &phba
->lpfc_vpi_blk_list
, list
) {
5507 list_del_init(&rsrc_blk
->list
);
5510 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5512 case LPFC_RSC_TYPE_FCOE_XRI
:
5513 kfree(phba
->sli4_hba
.xri_bmask
);
5514 kfree(phba
->sli4_hba
.xri_ids
);
5515 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5516 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5517 list_del_init(&rsrc_blk
->list
);
5521 case LPFC_RSC_TYPE_FCOE_VFI
:
5522 kfree(phba
->sli4_hba
.vfi_bmask
);
5523 kfree(phba
->sli4_hba
.vfi_ids
);
5524 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5525 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5526 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5527 list_del_init(&rsrc_blk
->list
);
5531 case LPFC_RSC_TYPE_FCOE_RPI
:
5532 /* RPI bitmask and physical id array are cleaned up earlier. */
5533 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5534 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5535 list_del_init(&rsrc_blk
->list
);
5543 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5546 mempool_free(mbox
, phba
->mbox_mem_pool
);
5551 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5552 * @phba: Pointer to HBA context object.
5554 * This function allocates all SLI4 resource identifiers.
5557 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5559 int i
, rc
, error
= 0;
5560 uint16_t count
, base
;
5561 unsigned long longs
;
5563 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5564 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5565 if (phba
->sli4_hba
.extents_in_use
) {
5567 * The port supports resource extents. The XRI, VPI, VFI, RPI
5568 * resource extent count must be read and allocated before
5569 * provisioning the resource id arrays.
5571 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5572 LPFC_IDX_RSRC_RDY
) {
5574 * Extent-based resources are set - the driver could
5575 * be in a port reset. Figure out if any corrective
5576 * actions need to be taken.
5578 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5579 LPFC_RSC_TYPE_FCOE_VFI
);
5582 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5583 LPFC_RSC_TYPE_FCOE_VPI
);
5586 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5587 LPFC_RSC_TYPE_FCOE_XRI
);
5590 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5591 LPFC_RSC_TYPE_FCOE_RPI
);
5596 * It's possible that the number of resources
5597 * provided to this port instance changed between
5598 * resets. Detect this condition and reallocate
5599 * resources. Otherwise, there is no action.
5602 lpfc_printf_log(phba
, KERN_INFO
,
5603 LOG_MBOX
| LOG_INIT
,
5604 "2931 Detected extent resource "
5605 "change. Reallocating all "
5607 rc
= lpfc_sli4_dealloc_extent(phba
,
5608 LPFC_RSC_TYPE_FCOE_VFI
);
5609 rc
= lpfc_sli4_dealloc_extent(phba
,
5610 LPFC_RSC_TYPE_FCOE_VPI
);
5611 rc
= lpfc_sli4_dealloc_extent(phba
,
5612 LPFC_RSC_TYPE_FCOE_XRI
);
5613 rc
= lpfc_sli4_dealloc_extent(phba
,
5614 LPFC_RSC_TYPE_FCOE_RPI
);
5619 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5623 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5627 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5631 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5634 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5639 * The port does not support resource extents. The XRI, VPI,
5640 * VFI, RPI resource ids were determined from READ_CONFIG.
5641 * Just allocate the bitmasks and provision the resource id
5642 * arrays. If a port reset is active, the resources don't
5643 * need any action - just exit.
5645 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5646 LPFC_IDX_RSRC_RDY
) {
5647 lpfc_sli4_dealloc_resource_identifiers(phba
);
5648 lpfc_sli4_remove_rpis(phba
);
5651 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5653 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5654 "3279 Invalid provisioning of "
5659 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5660 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5661 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5662 sizeof(unsigned long),
5664 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5668 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5671 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5673 goto free_rpi_bmask
;
5676 for (i
= 0; i
< count
; i
++)
5677 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5680 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5682 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5683 "3280 Invalid provisioning of "
5688 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5689 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5690 phba
->vpi_bmask
= kzalloc(longs
*
5691 sizeof(unsigned long),
5693 if (unlikely(!phba
->vpi_bmask
)) {
5697 phba
->vpi_ids
= kzalloc(count
*
5700 if (unlikely(!phba
->vpi_ids
)) {
5702 goto free_vpi_bmask
;
5705 for (i
= 0; i
< count
; i
++)
5706 phba
->vpi_ids
[i
] = base
+ i
;
5709 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5711 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5712 "3281 Invalid provisioning of "
5717 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5718 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5719 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5720 sizeof(unsigned long),
5722 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5726 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5727 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5730 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5732 goto free_xri_bmask
;
5735 for (i
= 0; i
< count
; i
++)
5736 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5739 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5741 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5742 "3282 Invalid provisioning of "
5747 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5748 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5749 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5750 sizeof(unsigned long),
5752 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5756 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5759 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5761 goto free_vfi_bmask
;
5764 for (i
= 0; i
< count
; i
++)
5765 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5768 * Mark all resources ready. An HBA reset doesn't need
5769 * to reset the initialization.
5771 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5777 kfree(phba
->sli4_hba
.vfi_bmask
);
5779 kfree(phba
->sli4_hba
.xri_ids
);
5781 kfree(phba
->sli4_hba
.xri_bmask
);
5783 kfree(phba
->vpi_ids
);
5785 kfree(phba
->vpi_bmask
);
5787 kfree(phba
->sli4_hba
.rpi_ids
);
5789 kfree(phba
->sli4_hba
.rpi_bmask
);
5795 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5796 * @phba: Pointer to HBA context object.
5798 * This function allocates the number of elements for the specified
5802 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5804 if (phba
->sli4_hba
.extents_in_use
) {
5805 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5806 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5807 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5808 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5810 kfree(phba
->vpi_bmask
);
5811 phba
->sli4_hba
.max_cfg_param
.vpi_used
= 0;
5812 kfree(phba
->vpi_ids
);
5813 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5814 kfree(phba
->sli4_hba
.xri_bmask
);
5815 kfree(phba
->sli4_hba
.xri_ids
);
5816 kfree(phba
->sli4_hba
.vfi_bmask
);
5817 kfree(phba
->sli4_hba
.vfi_ids
);
5818 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5819 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5826 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5827 * @phba: Pointer to HBA context object.
5828 * @type: The resource extent type.
5829 * @extnt_count: buffer to hold port extent count response
5830 * @extnt_size: buffer to hold port extent size response.
5832 * This function calls the port to read the host allocated extents
5833 * for a particular type.
5836 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5837 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5841 uint16_t curr_blks
= 0;
5842 uint32_t req_len
, emb_len
;
5843 uint32_t alloc_len
, mbox_tmo
;
5844 struct list_head
*blk_list_head
;
5845 struct lpfc_rsrc_blks
*rsrc_blk
;
5847 void *virtaddr
= NULL
;
5848 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5849 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5850 union lpfc_sli4_cfg_shdr
*shdr
;
5853 case LPFC_RSC_TYPE_FCOE_VPI
:
5854 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5856 case LPFC_RSC_TYPE_FCOE_XRI
:
5857 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5859 case LPFC_RSC_TYPE_FCOE_VFI
:
5860 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5862 case LPFC_RSC_TYPE_FCOE_RPI
:
5863 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5869 /* Count the number of extents currently allocatd for this type. */
5870 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5871 if (curr_blks
== 0) {
5873 * The GET_ALLOCATED mailbox does not return the size,
5874 * just the count. The size should be just the size
5875 * stored in the current allocated block and all sizes
5876 * for an extent type are the same so set the return
5879 *extnt_size
= rsrc_blk
->rsrc_size
;
5884 /* Calculate the total requested length of the dma memory. */
5885 req_len
= curr_blks
* sizeof(uint16_t);
5888 * Calculate the size of an embedded mailbox. The uint32_t
5889 * accounts for extents-specific word.
5891 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5895 * Presume the allocation and response will fit into an embedded
5896 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5898 emb
= LPFC_SLI4_MBX_EMBED
;
5900 if (req_len
> emb_len
) {
5901 req_len
= curr_blks
* sizeof(uint16_t) +
5902 sizeof(union lpfc_sli4_cfg_shdr
) +
5904 emb
= LPFC_SLI4_MBX_NEMBED
;
5907 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5910 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5912 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5913 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5915 if (alloc_len
< req_len
) {
5916 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5917 "2983 Allocated DMA memory size (x%x) is "
5918 "less than the requested DMA memory "
5919 "size (x%x)\n", alloc_len
, req_len
);
5923 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5929 if (!phba
->sli4_hba
.intr_enable
)
5930 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5932 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5933 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5942 * Figure out where the response is located. Then get local pointers
5943 * to the response data. The port does not guarantee to respond to
5944 * all extents counts request so update the local variable with the
5945 * allocated count from the port.
5947 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5948 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5949 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5950 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5952 virtaddr
= mbox
->sge_array
->addr
[0];
5953 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5954 shdr
= &n_rsrc
->cfg_shdr
;
5955 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5958 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5959 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5960 "2984 Failed to read allocated resources "
5961 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5963 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5964 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5969 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5974 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
5975 * @phba: pointer to lpfc hba data structure.
5977 * This routine walks the list of els buffers that have been allocated and
5978 * repost them to the port by using SGL block post. This is needed after a
5979 * pci_function_reset/warm_start or start. It attempts to construct blocks
5980 * of els buffer sgls which contains contiguous xris and uses the non-embedded
5981 * SGL block post mailbox commands to post them to the port. For single els
5982 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
5983 * mailbox command for posting.
5985 * Returns: 0 = success, non-zero failure.
5988 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
5990 struct lpfc_sglq
*sglq_entry
= NULL
;
5991 struct lpfc_sglq
*sglq_entry_next
= NULL
;
5992 struct lpfc_sglq
*sglq_entry_first
= NULL
;
5993 int status
, total_cnt
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
5994 int last_xritag
= NO_XRI
;
5995 LIST_HEAD(prep_sgl_list
);
5996 LIST_HEAD(blck_sgl_list
);
5997 LIST_HEAD(allc_sgl_list
);
5998 LIST_HEAD(post_sgl_list
);
5999 LIST_HEAD(free_sgl_list
);
6001 spin_lock_irq(&phba
->hbalock
);
6002 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
6003 spin_unlock_irq(&phba
->hbalock
);
6005 total_cnt
= phba
->sli4_hba
.els_xri_cnt
;
6006 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6007 &allc_sgl_list
, list
) {
6008 list_del_init(&sglq_entry
->list
);
6010 if ((last_xritag
!= NO_XRI
) &&
6011 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6012 /* a hole in xri block, form a sgl posting block */
6013 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6014 post_cnt
= block_cnt
- 1;
6015 /* prepare list for next posting block */
6016 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6019 /* prepare list for next posting block */
6020 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6021 /* enough sgls for non-embed sgl mbox command */
6022 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6023 list_splice_init(&prep_sgl_list
,
6025 post_cnt
= block_cnt
;
6031 /* keep track of last sgl's xritag */
6032 last_xritag
= sglq_entry
->sli4_xritag
;
6034 /* end of repost sgl list condition for els buffers */
6035 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
6036 if (post_cnt
== 0) {
6037 list_splice_init(&prep_sgl_list
,
6039 post_cnt
= block_cnt
;
6040 } else if (block_cnt
== 1) {
6041 status
= lpfc_sli4_post_sgl(phba
,
6042 sglq_entry
->phys
, 0,
6043 sglq_entry
->sli4_xritag
);
6045 /* successful, put sgl to posted list */
6046 list_add_tail(&sglq_entry
->list
,
6049 /* Failure, put sgl to free list */
6050 lpfc_printf_log(phba
, KERN_WARNING
,
6052 "3159 Failed to post els "
6053 "sgl, xritag:x%x\n",
6054 sglq_entry
->sli4_xritag
);
6055 list_add_tail(&sglq_entry
->list
,
6062 /* continue until a nembed page worth of sgls */
6066 /* post the els buffer list sgls as a block */
6067 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
6071 /* success, put sgl list to posted sgl list */
6072 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6074 /* Failure, put sgl list to free sgl list */
6075 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6078 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6079 "3160 Failed to post els sgl-list, "
6081 sglq_entry_first
->sli4_xritag
,
6082 (sglq_entry_first
->sli4_xritag
+
6084 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6085 total_cnt
-= post_cnt
;
6088 /* don't reset xirtag due to hole in xri block */
6090 last_xritag
= NO_XRI
;
6092 /* reset els sgl post count for next round of posting */
6095 /* update the number of XRIs posted for ELS */
6096 phba
->sli4_hba
.els_xri_cnt
= total_cnt
;
6098 /* free the els sgls failed to post */
6099 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6101 /* push els sgls posted to the availble list */
6102 if (!list_empty(&post_sgl_list
)) {
6103 spin_lock_irq(&phba
->hbalock
);
6104 list_splice_init(&post_sgl_list
,
6105 &phba
->sli4_hba
.lpfc_sgl_list
);
6106 spin_unlock_irq(&phba
->hbalock
);
6108 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6109 "3161 Failure to post els sgl to port.\n");
6116 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6117 * @phba: Pointer to HBA context object.
6119 * This function is the main SLI4 device intialization PCI function. This
6120 * function is called by the HBA intialization code, HBA reset code and
6121 * HBA error attention handler code. Caller is not required to hold any
6125 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6128 LPFC_MBOXQ_t
*mboxq
;
6129 struct lpfc_mqe
*mqe
;
6132 uint32_t ftr_rsp
= 0;
6133 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6134 struct lpfc_vport
*vport
= phba
->pport
;
6135 struct lpfc_dmabuf
*mp
;
6137 /* Perform a PCI function reset to start from clean */
6138 rc
= lpfc_pci_function_reset(phba
);
6142 /* Check the HBA Host Status Register for readyness */
6143 rc
= lpfc_sli4_post_status_check(phba
);
6147 spin_lock_irq(&phba
->hbalock
);
6148 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6149 spin_unlock_irq(&phba
->hbalock
);
6153 * Allocate a single mailbox container for initializing the
6156 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6160 /* Issue READ_REV to collect vpd and FW information. */
6161 vpd_size
= SLI4_PAGE_SIZE
;
6162 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6168 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6174 mqe
= &mboxq
->u
.mqe
;
6175 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6176 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
6177 phba
->hba_flag
|= HBA_FCOE_MODE
;
6179 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6181 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6183 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6185 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6187 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6189 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6190 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6191 "0376 READ_REV Error. SLI Level %d "
6192 "FCoE enabled %d\n",
6193 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6200 * Continue initialization with default values even if driver failed
6201 * to read FCoE param config regions, only read parameters if the
6204 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6205 lpfc_sli4_read_fcoe_params(phba
))
6206 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6207 "2570 Failed to read FCoE parameters\n");
6210 * Retrieve sli4 device physical port name, failure of doing it
6211 * is considered as non-fatal.
6213 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6215 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6216 "3080 Successful retrieving SLI4 device "
6217 "physical port name: %s.\n", phba
->Port
);
6220 * Evaluate the read rev and vpd data. Populate the driver
6221 * state with the results. If this routine fails, the failure
6222 * is not fatal as the driver will use generic values.
6224 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6225 if (unlikely(!rc
)) {
6226 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6227 "0377 Error %d parsing vpd. "
6228 "Using defaults.\n", rc
);
6233 /* Save information as VPD data */
6234 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6235 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6236 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6237 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6239 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6241 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6243 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6245 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6246 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6247 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6248 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6249 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6250 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6251 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6252 "(%d):0380 READ_REV Status x%x "
6253 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6254 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6255 bf_get(lpfc_mqe_status
, mqe
),
6256 phba
->vpd
.rev
.opFwName
,
6257 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6258 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6260 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
6261 rc
= (phba
->sli4_hba
.max_cfg_param
.max_xri
>> 3);
6262 if (phba
->pport
->cfg_lun_queue_depth
> rc
) {
6263 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6264 "3362 LUN queue depth changed from %d to %d\n",
6265 phba
->pport
->cfg_lun_queue_depth
, rc
);
6266 phba
->pport
->cfg_lun_queue_depth
= rc
;
6271 * Discover the port's supported feature set and match it against the
6274 lpfc_request_features(phba
, mboxq
);
6275 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6282 * The port must support FCP initiator mode as this is the
6283 * only mode running in the host.
6285 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6286 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6287 "0378 No support for fcpi mode.\n");
6290 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6291 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6293 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6295 * If the port cannot support the host's requested features
6296 * then turn off the global config parameters to disable the
6297 * feature in the driver. This is not a fatal error.
6299 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6300 if (phba
->cfg_enable_bg
) {
6301 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6302 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6307 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6308 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6312 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6313 "0379 Feature Mismatch Data: x%08x %08x "
6314 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6315 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6316 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6317 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6318 phba
->cfg_enable_bg
= 0;
6319 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6320 phba
->cfg_enable_npiv
= 0;
6323 /* These SLI3 features are assumed in SLI4 */
6324 spin_lock_irq(&phba
->hbalock
);
6325 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6326 spin_unlock_irq(&phba
->hbalock
);
6329 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6330 * calls depends on these resources to complete port setup.
6332 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6334 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6335 "2920 Failed to alloc Resource IDs "
6340 /* Read the port's service parameters. */
6341 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6343 phba
->link_state
= LPFC_HBA_ERROR
;
6348 mboxq
->vport
= vport
;
6349 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6350 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6351 if (rc
== MBX_SUCCESS
) {
6352 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6357 * This memory was allocated by the lpfc_read_sparam routine. Release
6358 * it to the mbuf pool.
6360 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6362 mboxq
->context1
= NULL
;
6364 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6365 "0382 READ_SPARAM command failed "
6366 "status %d, mbxStatus x%x\n",
6367 rc
, bf_get(lpfc_mqe_status
, mqe
));
6368 phba
->link_state
= LPFC_HBA_ERROR
;
6373 lpfc_update_vport_wwn(vport
);
6375 /* Update the fc_host data structures with new wwn. */
6376 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6377 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6379 /* update host els and scsi xri-sgl sizes and mappings */
6380 rc
= lpfc_sli4_xri_sgl_update(phba
);
6382 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6383 "1400 Failed to update xri-sgl size and "
6384 "mapping: %d\n", rc
);
6388 /* register the els sgl pool to the port */
6389 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6391 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6392 "0582 Error %d during els sgl post "
6398 /* register the allocated scsi sgl pool to the port */
6399 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6401 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6402 "0383 Error %d during scsi sgl post "
6404 /* Some Scsi buffers were moved to the abort scsi list */
6405 /* A pci function reset will repost them */
6410 /* Post the rpi header region to the device. */
6411 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6413 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6414 "0393 Error %d during rpi post operation\n",
6419 lpfc_sli4_node_prep(phba
);
6421 /* Create all the SLI4 queues */
6422 rc
= lpfc_sli4_queue_create(phba
);
6424 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6425 "3089 Failed to allocate queues\n");
6427 goto out_stop_timers
;
6429 /* Set up all the queues to the device */
6430 rc
= lpfc_sli4_queue_setup(phba
);
6432 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6433 "0381 Error %d during queue setup.\n ", rc
);
6434 goto out_destroy_queue
;
6437 /* Arm the CQs and then EQs on device */
6438 lpfc_sli4_arm_cqeq_intr(phba
);
6440 /* Indicate device interrupt mode */
6441 phba
->sli4_hba
.intr_enable
= 1;
6443 /* Allow asynchronous mailbox command to go through */
6444 spin_lock_irq(&phba
->hbalock
);
6445 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6446 spin_unlock_irq(&phba
->hbalock
);
6448 /* Post receive buffers to the device */
6449 lpfc_sli4_rb_setup(phba
);
6451 /* Reset HBA FCF states after HBA reset */
6452 phba
->fcf
.fcf_flag
= 0;
6453 phba
->fcf
.current_rec
.flag
= 0;
6455 /* Start the ELS watchdog timer */
6456 mod_timer(&vport
->els_tmofunc
,
6457 jiffies
+ msecs_to_jiffies(1000 * (phba
->fc_ratov
* 2)));
6459 /* Start heart beat timer */
6460 mod_timer(&phba
->hb_tmofunc
,
6461 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
6462 phba
->hb_outstanding
= 0;
6463 phba
->last_completion_time
= jiffies
;
6465 /* Start error attention (ERATT) polling timer */
6466 mod_timer(&phba
->eratt_poll
,
6467 jiffies
+ msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL
));
6469 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6470 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6471 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6473 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6474 "2829 This device supports "
6475 "Advanced Error Reporting (AER)\n");
6476 spin_lock_irq(&phba
->hbalock
);
6477 phba
->hba_flag
|= HBA_AER_ENABLED
;
6478 spin_unlock_irq(&phba
->hbalock
);
6480 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6481 "2830 This device does not support "
6482 "Advanced Error Reporting (AER)\n");
6483 phba
->cfg_aer_support
= 0;
6488 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6490 * The FC Port needs to register FCFI (index 0)
6492 lpfc_reg_fcfi(phba
, mboxq
);
6493 mboxq
->vport
= phba
->pport
;
6494 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6495 if (rc
!= MBX_SUCCESS
)
6496 goto out_unset_queue
;
6498 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6499 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6501 /* Check if the port is configured to be disabled */
6502 lpfc_sli_read_link_ste(phba
);
6506 * The port is ready, set the host's link state to LINK_DOWN
6507 * in preparation for link interrupts.
6509 spin_lock_irq(&phba
->hbalock
);
6510 phba
->link_state
= LPFC_LINK_DOWN
;
6511 spin_unlock_irq(&phba
->hbalock
);
6512 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6513 (phba
->hba_flag
& LINK_DISABLED
)) {
6514 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6515 "3103 Adapter Link is disabled.\n");
6516 lpfc_down_link(phba
, mboxq
);
6517 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6518 if (rc
!= MBX_SUCCESS
) {
6519 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6520 "3104 Adapter failed to issue "
6521 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6522 goto out_unset_queue
;
6524 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6525 /* don't perform init_link on SLI4 FC port loopback test */
6526 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6527 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6529 goto out_unset_queue
;
6532 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6535 /* Unset all the queues set up in this routine when error out */
6536 lpfc_sli4_queue_unset(phba
);
6538 lpfc_sli4_queue_destroy(phba
);
6540 lpfc_stop_hba_timers(phba
);
6542 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6547 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6548 * @ptr: context object - pointer to hba structure.
6550 * This is the callback function for mailbox timer. The mailbox
6551 * timer is armed when a new mailbox command is issued and the timer
6552 * is deleted when the mailbox complete. The function is called by
6553 * the kernel timer code when a mailbox does not complete within
6554 * expected time. This function wakes up the worker thread to
6555 * process the mailbox timeout and returns. All the processing is
6556 * done by the worker thread function lpfc_mbox_timeout_handler.
6559 lpfc_mbox_timeout(unsigned long ptr
)
6561 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6562 unsigned long iflag
;
6563 uint32_t tmo_posted
;
6565 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6566 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6568 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6569 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6572 lpfc_worker_wake_up(phba
);
6577 * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
6579 * @phba: Pointer to HBA context object.
6581 * This function checks if any mailbox completions are present on the mailbox
6585 lpfc_sli4_mbox_completions_pending(struct lpfc_hba
*phba
)
6589 struct lpfc_queue
*mcq
;
6590 struct lpfc_mcqe
*mcqe
;
6591 bool pending_completions
= false;
6593 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
6596 /* Check for completions on mailbox completion queue */
6598 mcq
= phba
->sli4_hba
.mbx_cq
;
6599 idx
= mcq
->hba_index
;
6600 while (bf_get_le32(lpfc_cqe_valid
, mcq
->qe
[idx
].cqe
)) {
6601 mcqe
= (struct lpfc_mcqe
*)mcq
->qe
[idx
].cqe
;
6602 if (bf_get_le32(lpfc_trailer_completed
, mcqe
) &&
6603 (!bf_get_le32(lpfc_trailer_async
, mcqe
))) {
6604 pending_completions
= true;
6607 idx
= (idx
+ 1) % mcq
->entry_count
;
6608 if (mcq
->hba_index
== idx
)
6611 return pending_completions
;
6616 * lpfc_sli4_process_missed_mbox_completions - process mbox completions
6618 * @phba: Pointer to HBA context object.
6620 * For sli4, it is possible to miss an interrupt. As such mbox completions
6621 * maybe missed causing erroneous mailbox timeouts to occur. This function
6622 * checks to see if mbox completions are on the mailbox completion queue
6623 * and will process all the completions associated with the eq for the
6624 * mailbox completion queue.
6627 lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba
*phba
)
6631 struct lpfc_queue
*fpeq
= NULL
;
6632 struct lpfc_eqe
*eqe
;
6635 if (unlikely(!phba
) || (phba
->sli_rev
!= LPFC_SLI_REV4
))
6638 /* Find the eq associated with the mcq */
6640 if (phba
->sli4_hba
.hba_eq
)
6641 for (eqidx
= 0; eqidx
< phba
->cfg_fcp_io_channel
; eqidx
++)
6642 if (phba
->sli4_hba
.hba_eq
[eqidx
]->queue_id
==
6643 phba
->sli4_hba
.mbx_cq
->assoc_qid
) {
6644 fpeq
= phba
->sli4_hba
.hba_eq
[eqidx
];
6650 /* Turn off interrupts from this EQ */
6652 lpfc_sli4_eq_clr_intr(fpeq
);
6654 /* Check to see if a mbox completion is pending */
6656 mbox_pending
= lpfc_sli4_mbox_completions_pending(phba
);
6659 * If a mbox completion is pending, process all the events on EQ
6660 * associated with the mbox completion queue (this could include
6661 * mailbox commands, async events, els commands, receive queue data
6666 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
6667 lpfc_sli4_hba_handle_eqe(phba
, eqe
, eqidx
);
6668 fpeq
->EQ_processed
++;
6671 /* Always clear and re-arm the EQ */
6673 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
6675 return mbox_pending
;
6680 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6681 * @phba: Pointer to HBA context object.
6683 * This function is called from worker thread when a mailbox command times out.
6684 * The caller is not required to hold any locks. This function will reset the
6685 * HBA and recover all the pending commands.
6688 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6690 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6691 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6692 struct lpfc_sli
*psli
= &phba
->sli
;
6693 struct lpfc_sli_ring
*pring
;
6695 /* If the mailbox completed, process the completion and return */
6696 if (lpfc_sli4_process_missed_mbox_completions(phba
))
6699 /* Check the pmbox pointer first. There is a race condition
6700 * between the mbox timeout handler getting executed in the
6701 * worklist and the mailbox actually completing. When this
6702 * race condition occurs, the mbox_active will be NULL.
6704 spin_lock_irq(&phba
->hbalock
);
6705 if (pmbox
== NULL
) {
6706 lpfc_printf_log(phba
, KERN_WARNING
,
6708 "0353 Active Mailbox cleared - mailbox timeout "
6710 spin_unlock_irq(&phba
->hbalock
);
6714 /* Mbox cmd <mbxCommand> timeout */
6715 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6716 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6718 phba
->pport
->port_state
,
6720 phba
->sli
.mbox_active
);
6721 spin_unlock_irq(&phba
->hbalock
);
6723 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6724 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6725 * it to fail all outstanding SCSI IO.
6727 spin_lock_irq(&phba
->pport
->work_port_lock
);
6728 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6729 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6730 spin_lock_irq(&phba
->hbalock
);
6731 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6732 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6733 spin_unlock_irq(&phba
->hbalock
);
6735 pring
= &psli
->ring
[psli
->fcp_ring
];
6736 lpfc_sli_abort_iocb_ring(phba
, pring
);
6738 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6739 "0345 Resetting board due to mailbox timeout\n");
6741 /* Reset the HBA device */
6742 lpfc_reset_hba(phba
);
6746 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6747 * @phba: Pointer to HBA context object.
6748 * @pmbox: Pointer to mailbox object.
6749 * @flag: Flag indicating how the mailbox need to be processed.
6751 * This function is called by discovery code and HBA management code
6752 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6753 * function gets the hbalock to protect the data structures.
6754 * The mailbox command can be submitted in polling mode, in which case
6755 * this function will wait in a polling loop for the completion of the
6757 * If the mailbox is submitted in no_wait mode (not polling) the
6758 * function will submit the command and returns immediately without waiting
6759 * for the mailbox completion. The no_wait is supported only when HBA
6760 * is in SLI2/SLI3 mode - interrupts are enabled.
6761 * The SLI interface allows only one mailbox pending at a time. If the
6762 * mailbox is issued in polling mode and there is already a mailbox
6763 * pending, then the function will return an error. If the mailbox is issued
6764 * in NO_WAIT mode and there is a mailbox pending already, the function
6765 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6766 * The sli layer owns the mailbox object until the completion of mailbox
6767 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6768 * return codes the caller owns the mailbox command after the return of
6772 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6776 struct lpfc_sli
*psli
= &phba
->sli
;
6777 uint32_t status
, evtctr
;
6778 uint32_t ha_copy
, hc_copy
;
6780 unsigned long timeout
;
6781 unsigned long drvr_flag
= 0;
6782 uint32_t word0
, ldata
;
6783 void __iomem
*to_slim
;
6784 int processing_queue
= 0;
6786 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6788 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6789 /* processing mbox queue from intr_handler */
6790 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6791 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6794 processing_queue
= 1;
6795 pmbox
= lpfc_mbox_get(phba
);
6797 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6802 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6803 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6805 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6806 lpfc_printf_log(phba
, KERN_ERR
,
6807 LOG_MBOX
| LOG_VPORT
,
6808 "1806 Mbox x%x failed. No vport\n",
6809 pmbox
->u
.mb
.mbxCommand
);
6811 goto out_not_finished
;
6815 /* If the PCI channel is in offline state, do not post mbox. */
6816 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6817 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6818 goto out_not_finished
;
6821 /* If HBA has a deferred error attention, fail the iocb. */
6822 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6823 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6824 goto out_not_finished
;
6830 status
= MBX_SUCCESS
;
6832 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6833 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6835 /* Mbox command <mbxCommand> cannot issue */
6836 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6837 "(%d):0311 Mailbox command x%x cannot "
6838 "issue Data: x%x x%x\n",
6839 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6840 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6841 goto out_not_finished
;
6844 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6845 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6846 !(hc_copy
& HC_MBINT_ENA
)) {
6847 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6848 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6849 "(%d):2528 Mailbox command x%x cannot "
6850 "issue Data: x%x x%x\n",
6851 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6852 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6853 goto out_not_finished
;
6857 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6858 /* Polling for a mbox command when another one is already active
6859 * is not allowed in SLI. Also, the driver must have established
6860 * SLI2 mode to queue and process multiple mbox commands.
6863 if (flag
& MBX_POLL
) {
6864 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6866 /* Mbox command <mbxCommand> cannot issue */
6867 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6868 "(%d):2529 Mailbox command x%x "
6869 "cannot issue Data: x%x x%x\n",
6870 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6871 pmbox
->u
.mb
.mbxCommand
,
6872 psli
->sli_flag
, flag
);
6873 goto out_not_finished
;
6876 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6877 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6878 /* Mbox command <mbxCommand> cannot issue */
6879 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6880 "(%d):2530 Mailbox command x%x "
6881 "cannot issue Data: x%x x%x\n",
6882 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6883 pmbox
->u
.mb
.mbxCommand
,
6884 psli
->sli_flag
, flag
);
6885 goto out_not_finished
;
6888 /* Another mailbox command is still being processed, queue this
6889 * command to be processed later.
6891 lpfc_mbox_put(phba
, pmbox
);
6893 /* Mbox cmd issue - BUSY */
6894 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6895 "(%d):0308 Mbox cmd issue - BUSY Data: "
6896 "x%x x%x x%x x%x\n",
6897 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6898 mbx
->mbxCommand
, phba
->pport
->port_state
,
6899 psli
->sli_flag
, flag
);
6901 psli
->slistat
.mbox_busy
++;
6902 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6905 lpfc_debugfs_disc_trc(pmbox
->vport
,
6906 LPFC_DISC_TRC_MBOX_VPORT
,
6907 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6908 (uint32_t)mbx
->mbxCommand
,
6909 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6912 lpfc_debugfs_disc_trc(phba
->pport
,
6914 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6915 (uint32_t)mbx
->mbxCommand
,
6916 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6922 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6924 /* If we are not polling, we MUST be in SLI2 mode */
6925 if (flag
!= MBX_POLL
) {
6926 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6927 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
6928 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6929 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6930 /* Mbox command <mbxCommand> cannot issue */
6931 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6932 "(%d):2531 Mailbox command x%x "
6933 "cannot issue Data: x%x x%x\n",
6934 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6935 pmbox
->u
.mb
.mbxCommand
,
6936 psli
->sli_flag
, flag
);
6937 goto out_not_finished
;
6939 /* timeout active mbox command */
6940 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6942 mod_timer(&psli
->mbox_tmo
, jiffies
+ timeout
);
6945 /* Mailbox cmd <cmd> issue */
6946 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6947 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6949 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6950 mbx
->mbxCommand
, phba
->pport
->port_state
,
6951 psli
->sli_flag
, flag
);
6953 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
6955 lpfc_debugfs_disc_trc(pmbox
->vport
,
6956 LPFC_DISC_TRC_MBOX_VPORT
,
6957 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6958 (uint32_t)mbx
->mbxCommand
,
6959 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6962 lpfc_debugfs_disc_trc(phba
->pport
,
6964 "MBOX Send: cmd:x%x mb:x%x x%x",
6965 (uint32_t)mbx
->mbxCommand
,
6966 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6970 psli
->slistat
.mbox_cmd
++;
6971 evtctr
= psli
->slistat
.mbox_event
;
6973 /* next set own bit for the adapter and copy over command word */
6974 mbx
->mbxOwner
= OWN_CHIP
;
6976 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6977 /* Populate mbox extension offset word. */
6978 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6979 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
6980 = (uint8_t *)phba
->mbox_ext
6981 - (uint8_t *)phba
->mbox
;
6984 /* Copy the mailbox extension data */
6985 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6986 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6987 (uint8_t *)phba
->mbox_ext
,
6988 pmbox
->in_ext_byte_len
);
6990 /* Copy command data to host SLIM area */
6991 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6993 /* Populate mbox extension offset word. */
6994 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6995 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
6996 = MAILBOX_HBA_EXT_OFFSET
;
6998 /* Copy the mailbox extension data */
6999 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
7000 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
7001 MAILBOX_HBA_EXT_OFFSET
,
7002 pmbox
->context2
, pmbox
->in_ext_byte_len
);
7005 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7006 /* copy command data into host mbox for cmpl */
7007 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
7010 /* First copy mbox command data to HBA SLIM, skip past first
7012 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
7013 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
7014 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
7016 /* Next copy over first word, with mbxOwner set */
7017 ldata
= *((uint32_t *)mbx
);
7018 to_slim
= phba
->MBslimaddr
;
7019 writel(ldata
, to_slim
);
7020 readl(to_slim
); /* flush */
7022 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7023 /* switch over to host mailbox */
7024 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
7032 /* Set up reference to mailbox command */
7033 psli
->mbox_active
= pmbox
;
7034 /* Interrupt board to do it */
7035 writel(CA_MBATT
, phba
->CAregaddr
);
7036 readl(phba
->CAregaddr
); /* flush */
7037 /* Don't wait for it to finish, just return */
7041 /* Set up null reference to mailbox command */
7042 psli
->mbox_active
= NULL
;
7043 /* Interrupt board to do it */
7044 writel(CA_MBATT
, phba
->CAregaddr
);
7045 readl(phba
->CAregaddr
); /* flush */
7047 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7048 /* First read mbox status word */
7049 word0
= *((uint32_t *)phba
->mbox
);
7050 word0
= le32_to_cpu(word0
);
7052 /* First read mbox status word */
7053 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
7054 spin_unlock_irqrestore(&phba
->hbalock
,
7056 goto out_not_finished
;
7060 /* Read the HBA Host Attention Register */
7061 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7062 spin_unlock_irqrestore(&phba
->hbalock
,
7064 goto out_not_finished
;
7066 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
7069 /* Wait for command to complete */
7070 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
7071 (!(ha_copy
& HA_MBATT
) &&
7072 (phba
->link_state
> LPFC_WARM_START
))) {
7073 if (time_after(jiffies
, timeout
)) {
7074 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7075 spin_unlock_irqrestore(&phba
->hbalock
,
7077 goto out_not_finished
;
7080 /* Check if we took a mbox interrupt while we were
7082 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
7083 && (evtctr
!= psli
->slistat
.mbox_event
))
7087 spin_unlock_irqrestore(&phba
->hbalock
,
7090 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
7093 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7094 /* First copy command data */
7095 word0
= *((uint32_t *)phba
->mbox
);
7096 word0
= le32_to_cpu(word0
);
7097 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
7100 /* Check real SLIM for any errors */
7101 slimword0
= readl(phba
->MBslimaddr
);
7102 slimmb
= (MAILBOX_t
*) & slimword0
;
7103 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
7104 && slimmb
->mbxStatus
) {
7111 /* First copy command data */
7112 word0
= readl(phba
->MBslimaddr
);
7114 /* Read the HBA Host Attention Register */
7115 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7116 spin_unlock_irqrestore(&phba
->hbalock
,
7118 goto out_not_finished
;
7122 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7123 /* copy results back to user */
7124 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
, MAILBOX_CMD_SIZE
);
7125 /* Copy the mailbox extension data */
7126 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7127 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7129 pmbox
->out_ext_byte_len
);
7132 /* First copy command data */
7133 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
7135 /* Copy the mailbox extension data */
7136 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7137 lpfc_memcpy_from_slim(pmbox
->context2
,
7139 MAILBOX_HBA_EXT_OFFSET
,
7140 pmbox
->out_ext_byte_len
);
7144 writel(HA_MBATT
, phba
->HAregaddr
);
7145 readl(phba
->HAregaddr
); /* flush */
7147 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7148 status
= mbx
->mbxStatus
;
7151 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7155 if (processing_queue
) {
7156 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7157 lpfc_mbox_cmpl_put(phba
, pmbox
);
7159 return MBX_NOT_FINISHED
;
7163 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7164 * @phba: Pointer to HBA context object.
7166 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7167 * the driver internal pending mailbox queue. It will then try to wait out the
7168 * possible outstanding mailbox command before return.
7171 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7172 * the outstanding mailbox command timed out.
7175 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7177 struct lpfc_sli
*psli
= &phba
->sli
;
7179 unsigned long timeout
= 0;
7181 /* Mark the asynchronous mailbox command posting as blocked */
7182 spin_lock_irq(&phba
->hbalock
);
7183 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7184 /* Determine how long we might wait for the active mailbox
7185 * command to be gracefully completed by firmware.
7187 if (phba
->sli
.mbox_active
)
7188 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7189 phba
->sli
.mbox_active
) *
7191 spin_unlock_irq(&phba
->hbalock
);
7193 /* Make sure the mailbox is really active */
7195 lpfc_sli4_process_missed_mbox_completions(phba
);
7197 /* Wait for the outstnading mailbox command to complete */
7198 while (phba
->sli
.mbox_active
) {
7199 /* Check active mailbox complete status every 2ms */
7201 if (time_after(jiffies
, timeout
)) {
7202 /* Timeout, marked the outstanding cmd not complete */
7208 /* Can not cleanly block async mailbox command, fails it */
7210 spin_lock_irq(&phba
->hbalock
);
7211 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7212 spin_unlock_irq(&phba
->hbalock
);
7218 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7219 * @phba: Pointer to HBA context object.
7221 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7222 * commands from the driver internal pending mailbox queue. It makes sure
7223 * that there is no outstanding mailbox command before resuming posting
7224 * asynchronous mailbox commands. If, for any reason, there is outstanding
7225 * mailbox command, it will try to wait it out before resuming asynchronous
7226 * mailbox command posting.
7229 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7231 struct lpfc_sli
*psli
= &phba
->sli
;
7233 spin_lock_irq(&phba
->hbalock
);
7234 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7235 /* Asynchronous mailbox posting is not blocked, do nothing */
7236 spin_unlock_irq(&phba
->hbalock
);
7240 /* Outstanding synchronous mailbox command is guaranteed to be done,
7241 * successful or timeout, after timing-out the outstanding mailbox
7242 * command shall always be removed, so just unblock posting async
7243 * mailbox command and resume
7245 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7246 spin_unlock_irq(&phba
->hbalock
);
7248 /* wake up worker thread to post asynchronlous mailbox command */
7249 lpfc_worker_wake_up(phba
);
7253 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7254 * @phba: Pointer to HBA context object.
7255 * @mboxq: Pointer to mailbox object.
7257 * The function waits for the bootstrap mailbox register ready bit from
7258 * port for twice the regular mailbox command timeout value.
7260 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7261 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7264 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7267 unsigned long timeout
;
7268 struct lpfc_register bmbx_reg
;
7270 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7274 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7275 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7279 if (time_after(jiffies
, timeout
))
7280 return MBXERR_ERROR
;
7281 } while (!db_ready
);
7287 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7288 * @phba: Pointer to HBA context object.
7289 * @mboxq: Pointer to mailbox object.
7291 * The function posts a mailbox to the port. The mailbox is expected
7292 * to be comletely filled in and ready for the port to operate on it.
7293 * This routine executes a synchronous completion operation on the
7294 * mailbox by polling for its completion.
7296 * The caller must not be holding any locks when calling this routine.
7299 * MBX_SUCCESS - mailbox posted successfully
7300 * Any of the MBX error values.
7303 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7305 int rc
= MBX_SUCCESS
;
7306 unsigned long iflag
;
7307 uint32_t mcqe_status
;
7309 struct lpfc_sli
*psli
= &phba
->sli
;
7310 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7311 struct lpfc_bmbx_create
*mbox_rgn
;
7312 struct dma_address
*dma_address
;
7315 * Only one mailbox can be active to the bootstrap mailbox region
7316 * at a time and there is no queueing provided.
7318 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7319 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7320 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7321 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7322 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7323 "cannot issue Data: x%x x%x\n",
7324 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7325 mboxq
->u
.mb
.mbxCommand
,
7326 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7327 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7328 psli
->sli_flag
, MBX_POLL
);
7329 return MBXERR_ERROR
;
7331 /* The server grabs the token and owns it until release */
7332 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7333 phba
->sli
.mbox_active
= mboxq
;
7334 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7336 /* wait for bootstrap mbox register for readyness */
7337 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7342 * Initialize the bootstrap memory region to avoid stale data areas
7343 * in the mailbox post. Then copy the caller's mailbox contents to
7344 * the bmbx mailbox region.
7346 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7347 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7348 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7349 sizeof(struct lpfc_mqe
));
7351 /* Post the high mailbox dma address to the port and wait for ready. */
7352 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7353 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7355 /* wait for bootstrap mbox register for hi-address write done */
7356 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7360 /* Post the low mailbox dma address to the port. */
7361 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7363 /* wait for bootstrap mbox register for low address write done */
7364 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7369 * Read the CQ to ensure the mailbox has completed.
7370 * If so, update the mailbox status so that the upper layers
7371 * can complete the request normally.
7373 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7374 sizeof(struct lpfc_mqe
));
7375 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7376 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7377 sizeof(struct lpfc_mcqe
));
7378 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7380 * When the CQE status indicates a failure and the mailbox status
7381 * indicates success then copy the CQE status into the mailbox status
7382 * (and prefix it with x4000).
7384 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7385 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7386 bf_set(lpfc_mqe_status
, mb
,
7387 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7390 lpfc_sli4_swap_str(phba
, mboxq
);
7392 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7393 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7394 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7395 " x%x x%x CQ: x%x x%x x%x x%x\n",
7396 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7397 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7398 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7399 bf_get(lpfc_mqe_status
, mb
),
7400 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7401 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7402 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7403 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7404 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7405 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7406 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7407 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7408 mboxq
->mcqe
.trailer
);
7410 /* We are holding the token, no needed for lock when release */
7411 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7412 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7413 phba
->sli
.mbox_active
= NULL
;
7414 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7419 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7420 * @phba: Pointer to HBA context object.
7421 * @pmbox: Pointer to mailbox object.
7422 * @flag: Flag indicating how the mailbox need to be processed.
7424 * This function is called by discovery code and HBA management code to submit
7425 * a mailbox command to firmware with SLI-4 interface spec.
7427 * Return codes the caller owns the mailbox command after the return of the
7431 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7434 struct lpfc_sli
*psli
= &phba
->sli
;
7435 unsigned long iflags
;
7438 /* dump from issue mailbox command if setup */
7439 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7441 rc
= lpfc_mbox_dev_check(phba
);
7443 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7444 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7445 "cannot issue Data: x%x x%x\n",
7446 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7447 mboxq
->u
.mb
.mbxCommand
,
7448 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7449 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7450 psli
->sli_flag
, flag
);
7451 goto out_not_finished
;
7454 /* Detect polling mode and jump to a handler */
7455 if (!phba
->sli4_hba
.intr_enable
) {
7456 if (flag
== MBX_POLL
)
7457 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7460 if (rc
!= MBX_SUCCESS
)
7461 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7462 "(%d):2541 Mailbox command x%x "
7463 "(x%x/x%x) failure: "
7464 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7466 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7467 mboxq
->u
.mb
.mbxCommand
,
7468 lpfc_sli_config_mbox_subsys_get(phba
,
7470 lpfc_sli_config_mbox_opcode_get(phba
,
7472 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7473 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7474 bf_get(lpfc_mcqe_ext_status
,
7476 psli
->sli_flag
, flag
);
7478 } else if (flag
== MBX_POLL
) {
7479 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7480 "(%d):2542 Try to issue mailbox command "
7481 "x%x (x%x/x%x) synchronously ahead of async"
7482 "mailbox command queue: x%x x%x\n",
7483 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7484 mboxq
->u
.mb
.mbxCommand
,
7485 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7486 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7487 psli
->sli_flag
, flag
);
7488 /* Try to block the asynchronous mailbox posting */
7489 rc
= lpfc_sli4_async_mbox_block(phba
);
7491 /* Successfully blocked, now issue sync mbox cmd */
7492 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7493 if (rc
!= MBX_SUCCESS
)
7494 lpfc_printf_log(phba
, KERN_WARNING
,
7496 "(%d):2597 Sync Mailbox command "
7497 "x%x (x%x/x%x) failure: "
7498 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7500 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7501 mboxq
->u
.mb
.mbxCommand
,
7502 lpfc_sli_config_mbox_subsys_get(phba
,
7504 lpfc_sli_config_mbox_opcode_get(phba
,
7506 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7507 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7508 bf_get(lpfc_mcqe_ext_status
,
7510 psli
->sli_flag
, flag
);
7511 /* Unblock the async mailbox posting afterward */
7512 lpfc_sli4_async_mbox_unblock(phba
);
7517 /* Now, interrupt mode asynchrous mailbox command */
7518 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7520 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7521 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7522 "cannot issue Data: x%x x%x\n",
7523 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7524 mboxq
->u
.mb
.mbxCommand
,
7525 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7526 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7527 psli
->sli_flag
, flag
);
7528 goto out_not_finished
;
7531 /* Put the mailbox command to the driver internal FIFO */
7532 psli
->slistat
.mbox_busy
++;
7533 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7534 lpfc_mbox_put(phba
, mboxq
);
7535 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7536 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7537 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7538 "x%x (x%x/x%x) x%x x%x x%x\n",
7539 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7540 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7541 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7542 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7543 phba
->pport
->port_state
,
7544 psli
->sli_flag
, MBX_NOWAIT
);
7545 /* Wake up worker thread to transport mailbox command from head */
7546 lpfc_worker_wake_up(phba
);
7551 return MBX_NOT_FINISHED
;
7555 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7556 * @phba: Pointer to HBA context object.
7558 * This function is called by worker thread to send a mailbox command to
7559 * SLI4 HBA firmware.
7563 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7565 struct lpfc_sli
*psli
= &phba
->sli
;
7566 LPFC_MBOXQ_t
*mboxq
;
7567 int rc
= MBX_SUCCESS
;
7568 unsigned long iflags
;
7569 struct lpfc_mqe
*mqe
;
7572 /* Check interrupt mode before post async mailbox command */
7573 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7574 return MBX_NOT_FINISHED
;
7576 /* Check for mailbox command service token */
7577 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7578 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7579 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7580 return MBX_NOT_FINISHED
;
7582 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7583 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7584 return MBX_NOT_FINISHED
;
7586 if (unlikely(phba
->sli
.mbox_active
)) {
7587 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7588 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7589 "0384 There is pending active mailbox cmd\n");
7590 return MBX_NOT_FINISHED
;
7592 /* Take the mailbox command service token */
7593 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7595 /* Get the next mailbox command from head of queue */
7596 mboxq
= lpfc_mbox_get(phba
);
7598 /* If no more mailbox command waiting for post, we're done */
7600 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7601 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7604 phba
->sli
.mbox_active
= mboxq
;
7605 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7607 /* Check device readiness for posting mailbox command */
7608 rc
= lpfc_mbox_dev_check(phba
);
7610 /* Driver clean routine will clean up pending mailbox */
7611 goto out_not_finished
;
7613 /* Prepare the mbox command to be posted */
7614 mqe
= &mboxq
->u
.mqe
;
7615 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7617 /* Start timer for the mbox_tmo and log some mailbox post messages */
7618 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7619 msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba
, mboxq
))));
7621 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7622 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7624 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7625 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7626 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7627 phba
->pport
->port_state
, psli
->sli_flag
);
7629 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7631 lpfc_debugfs_disc_trc(mboxq
->vport
,
7632 LPFC_DISC_TRC_MBOX_VPORT
,
7633 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7634 mbx_cmnd
, mqe
->un
.mb_words
[0],
7635 mqe
->un
.mb_words
[1]);
7637 lpfc_debugfs_disc_trc(phba
->pport
,
7639 "MBOX Send: cmd:x%x mb:x%x x%x",
7640 mbx_cmnd
, mqe
->un
.mb_words
[0],
7641 mqe
->un
.mb_words
[1]);
7644 psli
->slistat
.mbox_cmd
++;
7646 /* Post the mailbox command to the port */
7647 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7648 if (rc
!= MBX_SUCCESS
) {
7649 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7650 "(%d):2533 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
, MBX_NOWAIT
);
7657 goto out_not_finished
;
7663 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7664 if (phba
->sli
.mbox_active
) {
7665 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7666 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7667 /* Release the token */
7668 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7669 phba
->sli
.mbox_active
= NULL
;
7671 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7673 return MBX_NOT_FINISHED
;
7677 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7678 * @phba: Pointer to HBA context object.
7679 * @pmbox: Pointer to mailbox object.
7680 * @flag: Flag indicating how the mailbox need to be processed.
7682 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7683 * the API jump table function pointer from the lpfc_hba struct.
7685 * Return codes the caller owns the mailbox command after the return of the
7689 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7691 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7695 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7696 * @phba: The hba struct for which this call is being executed.
7697 * @dev_grp: The HBA PCI-Device group number.
7699 * This routine sets up the mbox interface API function jump table in @phba
7701 * Returns: 0 - success, -ENODEV - failure.
7704 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7708 case LPFC_PCI_DEV_LP
:
7709 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7710 phba
->lpfc_sli_handle_slow_ring_event
=
7711 lpfc_sli_handle_slow_ring_event_s3
;
7712 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7713 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7714 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7716 case LPFC_PCI_DEV_OC
:
7717 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7718 phba
->lpfc_sli_handle_slow_ring_event
=
7719 lpfc_sli_handle_slow_ring_event_s4
;
7720 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7721 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7722 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7725 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7726 "1420 Invalid HBA PCI-device group: 0x%x\n",
7735 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7736 * @phba: Pointer to HBA context object.
7737 * @pring: Pointer to driver SLI ring object.
7738 * @piocb: Pointer to address of newly added command iocb.
7740 * This function is called with hbalock held to add a command
7741 * iocb to the txq when SLI layer cannot submit the command iocb
7745 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7746 struct lpfc_iocbq
*piocb
)
7748 /* Insert the caller's iocb in the txq tail for later processing. */
7749 list_add_tail(&piocb
->list
, &pring
->txq
);
7753 * lpfc_sli_next_iocb - Get the next iocb in the txq
7754 * @phba: Pointer to HBA context object.
7755 * @pring: Pointer to driver SLI ring object.
7756 * @piocb: Pointer to address of newly added command iocb.
7758 * This function is called with hbalock held before a new
7759 * iocb is submitted to the firmware. This function checks
7760 * txq to flush the iocbs in txq to Firmware before
7761 * submitting new iocbs to the Firmware.
7762 * If there are iocbs in the txq which need to be submitted
7763 * to firmware, lpfc_sli_next_iocb returns the first element
7764 * of the txq after dequeuing it from txq.
7765 * If there is no iocb in the txq then the function will return
7766 * *piocb and *piocb is set to NULL. Caller needs to check
7767 * *piocb to find if there are more commands in the txq.
7769 static struct lpfc_iocbq
*
7770 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7771 struct lpfc_iocbq
**piocb
)
7773 struct lpfc_iocbq
* nextiocb
;
7775 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7785 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7786 * @phba: Pointer to HBA context object.
7787 * @ring_number: SLI ring number to issue iocb on.
7788 * @piocb: Pointer to command iocb.
7789 * @flag: Flag indicating if this command can be put into txq.
7791 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7792 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7793 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7794 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7795 * this function allows only iocbs for posting buffers. This function finds
7796 * next available slot in the command ring and posts the command to the
7797 * available slot and writes the port attention register to request HBA start
7798 * processing new iocb. If there is no slot available in the ring and
7799 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7800 * the function returns IOCB_BUSY.
7802 * This function is called with hbalock held. The function will return success
7803 * after it successfully submit the iocb to firmware or after adding to the
7807 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7808 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7810 struct lpfc_iocbq
*nextiocb
;
7812 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7814 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7815 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7816 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7817 lpfc_printf_log(phba
, KERN_ERR
,
7818 LOG_SLI
| LOG_VPORT
,
7819 "1807 IOCB x%x failed. No vport\n",
7820 piocb
->iocb
.ulpCommand
);
7826 /* If the PCI channel is in offline state, do not post iocbs. */
7827 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7830 /* If HBA has a deferred error attention, fail the iocb. */
7831 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7835 * We should never get an IOCB if we are in a < LINK_DOWN state
7837 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7841 * Check to see if we are blocking IOCB processing because of a
7842 * outstanding event.
7844 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7847 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7849 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7850 * can be issued if the link is not up.
7852 switch (piocb
->iocb
.ulpCommand
) {
7853 case CMD_GEN_REQUEST64_CR
:
7854 case CMD_GEN_REQUEST64_CX
:
7855 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7856 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7857 FC_RCTL_DD_UNSOL_CMD
) ||
7858 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7859 MENLO_TRANSPORT_TYPE
))
7863 case CMD_QUE_RING_BUF_CN
:
7864 case CMD_QUE_RING_BUF64_CN
:
7866 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7867 * completion, iocb_cmpl MUST be 0.
7869 if (piocb
->iocb_cmpl
)
7870 piocb
->iocb_cmpl
= NULL
;
7872 case CMD_CREATE_XRI_CR
:
7873 case CMD_CLOSE_XRI_CN
:
7874 case CMD_CLOSE_XRI_CX
:
7881 * For FCP commands, we must be in a state where we can process link
7884 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7885 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7889 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7890 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7891 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7894 lpfc_sli_update_ring(phba
, pring
);
7896 lpfc_sli_update_full_ring(phba
, pring
);
7899 return IOCB_SUCCESS
;
7904 pring
->stats
.iocb_cmd_delay
++;
7908 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7909 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7910 return IOCB_SUCCESS
;
7917 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7918 * @phba: Pointer to HBA context object.
7919 * @piocb: Pointer to command iocb.
7920 * @sglq: Pointer to the scatter gather queue object.
7922 * This routine converts the bpl or bde that is in the IOCB
7923 * to a sgl list for the sli4 hardware. The physical address
7924 * of the bpl/bde is converted back to a virtual address.
7925 * If the IOCB contains a BPL then the list of BDE's is
7926 * converted to sli4_sge's. If the IOCB contains a single
7927 * BDE then it is converted to a single sli_sge.
7928 * The IOCB is still in cpu endianess so the contents of
7929 * the bpl can be used without byte swapping.
7931 * Returns valid XRI = Success, NO_XRI = Failure.
7934 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7935 struct lpfc_sglq
*sglq
)
7937 uint16_t xritag
= NO_XRI
;
7938 struct ulp_bde64
*bpl
= NULL
;
7939 struct ulp_bde64 bde
;
7940 struct sli4_sge
*sgl
= NULL
;
7941 struct lpfc_dmabuf
*dmabuf
;
7945 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7946 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7948 if (!piocbq
|| !sglq
)
7951 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7952 icmd
= &piocbq
->iocb
;
7953 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
7954 return sglq
->sli4_xritag
;
7955 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7956 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7957 sizeof(struct ulp_bde64
);
7958 /* The addrHigh and addrLow fields within the IOCB
7959 * have not been byteswapped yet so there is no
7960 * need to swap them back.
7962 if (piocbq
->context3
)
7963 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7967 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7971 for (i
= 0; i
< numBdes
; i
++) {
7972 /* Should already be byte swapped. */
7973 sgl
->addr_hi
= bpl
->addrHigh
;
7974 sgl
->addr_lo
= bpl
->addrLow
;
7976 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7977 if ((i
+1) == numBdes
)
7978 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7980 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7981 /* swap the size field back to the cpu so we
7982 * can assign it to the sgl.
7984 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7985 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7986 /* The offsets in the sgl need to be accumulated
7987 * separately for the request and reply lists.
7988 * The request is always first, the reply follows.
7990 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7991 /* add up the reply sg entries */
7992 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7994 /* first inbound? reset the offset */
7997 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7998 bf_set(lpfc_sli4_sge_type
, sgl
,
7999 LPFC_SGE_TYPE_DATA
);
8000 offset
+= bde
.tus
.f
.bdeSize
;
8002 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8006 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
8007 /* The addrHigh and addrLow fields of the BDE have not
8008 * been byteswapped yet so they need to be swapped
8009 * before putting them in the sgl.
8012 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
8014 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
8015 sgl
->word2
= le32_to_cpu(sgl
->word2
);
8016 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
8017 sgl
->word2
= cpu_to_le32(sgl
->word2
);
8019 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
8021 return sglq
->sli4_xritag
;
8025 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
8026 * @phba: Pointer to HBA context object.
8028 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
8029 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
8032 * Return: index into SLI4 fast-path FCP queue index.
8034 static inline uint32_t
8035 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
8037 struct lpfc_vector_map_info
*cpup
;
8040 if (phba
->cfg_fcp_io_sched
== LPFC_FCP_SCHED_BY_CPU
8041 && phba
->cfg_fcp_io_channel
> 1) {
8042 cpu
= smp_processor_id();
8043 if (cpu
< phba
->sli4_hba
.num_present_cpu
) {
8044 cpup
= phba
->sli4_hba
.cpu_map
;
8046 return cpup
->channel_id
;
8050 chann
= atomic_add_return(1, &phba
->fcp_qidx
);
8051 chann
= (chann
% phba
->cfg_fcp_io_channel
);
8056 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
8057 * @phba: Pointer to HBA context object.
8058 * @piocb: Pointer to command iocb.
8059 * @wqe: Pointer to the work queue entry.
8061 * This routine converts the iocb command to its Work Queue Entry
8062 * equivalent. The wqe pointer should not have any fields set when
8063 * this routine is called because it will memcpy over them.
8064 * This routine does not set the CQ_ID or the WQEC bits in the
8067 * Returns: 0 = Success, IOCB_ERROR = Failure.
8070 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
8071 union lpfc_wqe
*wqe
)
8073 uint32_t xmit_len
= 0, total_len
= 0;
8077 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
8080 uint16_t abrt_iotag
;
8081 struct lpfc_iocbq
*abrtiocbq
;
8082 struct ulp_bde64
*bpl
= NULL
;
8083 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
8085 struct ulp_bde64 bde
;
8086 struct lpfc_nodelist
*ndlp
;
8090 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
8091 /* The fcp commands will set command type */
8092 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
8093 command_type
= FCP_COMMAND
;
8094 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
8095 command_type
= ELS_COMMAND_FIP
;
8097 command_type
= ELS_COMMAND_NON_FIP
;
8099 /* Some of the fields are in the right position already */
8100 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
8101 abort_tag
= (uint32_t) iocbq
->iotag
;
8102 xritag
= iocbq
->sli4_xritag
;
8103 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
8104 /* words0-2 bpl convert bde */
8105 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
8106 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8107 sizeof(struct ulp_bde64
);
8108 bpl
= (struct ulp_bde64
*)
8109 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
8113 /* Should already be byte swapped. */
8114 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
8115 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
8116 /* swap the size field back to the cpu so we
8117 * can assign it to the sgl.
8119 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
8120 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
8122 for (i
= 0; i
< numBdes
; i
++) {
8123 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8124 total_len
+= bde
.tus
.f
.bdeSize
;
8127 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8129 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8130 cmnd
= iocbq
->iocb
.ulpCommand
;
8132 switch (iocbq
->iocb
.ulpCommand
) {
8133 case CMD_ELS_REQUEST64_CR
:
8134 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8135 ndlp
= iocbq
->context_un
.ndlp
;
8137 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8138 if (!iocbq
->iocb
.ulpLe
) {
8139 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8140 "2007 Only Limited Edition cmd Format"
8141 " supported 0x%x\n",
8142 iocbq
->iocb
.ulpCommand
);
8146 wqe
->els_req
.payload_len
= xmit_len
;
8147 /* Els_reguest64 has a TMO */
8148 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8149 iocbq
->iocb
.ulpTimeout
);
8150 /* Need a VF for word 4 set the vf bit*/
8151 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
8152 /* And a VFID for word 12 */
8153 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
8154 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8155 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8156 iocbq
->iocb
.ulpContext
);
8157 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
8158 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
8159 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8160 if (command_type
== ELS_COMMAND_FIP
)
8161 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
8162 >> LPFC_FIP_ELS_ID_SHIFT
);
8163 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8164 iocbq
->context2
)->virt
);
8165 if_type
= bf_get(lpfc_sli_intf_if_type
,
8166 &phba
->sli4_hba
.sli_intf
);
8167 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8168 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
8169 *pcmd
== ELS_CMD_SCR
||
8170 *pcmd
== ELS_CMD_FDISC
||
8171 *pcmd
== ELS_CMD_LOGO
||
8172 *pcmd
== ELS_CMD_PLOGI
)) {
8173 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8174 bf_set(els_req64_sid
, &wqe
->els_req
,
8175 iocbq
->vport
->fc_myDID
);
8176 if ((*pcmd
== ELS_CMD_FLOGI
) &&
8177 !(phba
->fc_topology
==
8178 LPFC_TOPOLOGY_LOOP
))
8179 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
8180 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8181 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8182 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8183 } else if (pcmd
&& iocbq
->context1
) {
8184 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
8185 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8186 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8189 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
8190 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8191 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
8192 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
8193 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8194 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
8195 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8196 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
8197 wqe
->els_req
.max_response_payload_len
= total_len
- xmit_len
;
8199 case CMD_XMIT_SEQUENCE64_CX
:
8200 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
8201 iocbq
->iocb
.un
.ulpWord
[3]);
8202 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
8203 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8204 /* The entire sequence is transmitted for this IOCB */
8205 xmit_len
= total_len
;
8206 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8207 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8208 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8209 case CMD_XMIT_SEQUENCE64_CR
:
8210 /* word3 iocb=io_tag32 wqe=reserved */
8211 wqe
->xmit_sequence
.rsvd3
= 0;
8212 /* word4 relative_offset memcpy */
8213 /* word5 r_ctl/df_ctl memcpy */
8214 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8215 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8216 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8217 LPFC_WQE_IOD_WRITE
);
8218 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8219 LPFC_WQE_LENLOC_WORD12
);
8220 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8221 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8222 command_type
= OTHER_COMMAND
;
8224 case CMD_XMIT_BCAST64_CN
:
8225 /* word3 iocb=iotag32 wqe=seq_payload_len */
8226 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8227 /* word4 iocb=rsvd wqe=rsvd */
8228 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8229 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8230 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8231 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8232 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8233 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8234 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8235 LPFC_WQE_LENLOC_WORD3
);
8236 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8238 case CMD_FCP_IWRITE64_CR
:
8239 command_type
= FCP_COMMAND_DATA_OUT
;
8240 /* word3 iocb=iotag wqe=payload_offset_len */
8241 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8242 bf_set(payload_offset_len
, &wqe
->fcp_iwrite
,
8243 xmit_len
+ sizeof(struct fcp_rsp
));
8244 bf_set(cmd_buff_len
, &wqe
->fcp_iwrite
,
8246 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8247 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8248 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8249 iocbq
->iocb
.ulpFCP2Rcvy
);
8250 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8251 /* Always open the exchange */
8252 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8253 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8254 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8255 LPFC_WQE_LENLOC_WORD4
);
8256 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8257 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8258 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8260 case CMD_FCP_IREAD64_CR
:
8261 /* word3 iocb=iotag wqe=payload_offset_len */
8262 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8263 bf_set(payload_offset_len
, &wqe
->fcp_iread
,
8264 xmit_len
+ sizeof(struct fcp_rsp
));
8265 bf_set(cmd_buff_len
, &wqe
->fcp_iread
,
8267 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8268 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8269 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8270 iocbq
->iocb
.ulpFCP2Rcvy
);
8271 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8272 /* Always open the exchange */
8273 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
8274 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8275 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8276 LPFC_WQE_LENLOC_WORD4
);
8277 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
8278 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8279 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8281 case CMD_FCP_ICMND64_CR
:
8282 /* word3 iocb=iotag wqe=payload_offset_len */
8283 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8284 bf_set(payload_offset_len
, &wqe
->fcp_icmd
,
8285 xmit_len
+ sizeof(struct fcp_rsp
));
8286 bf_set(cmd_buff_len
, &wqe
->fcp_icmd
,
8288 /* word3 iocb=IO_TAG wqe=reserved */
8289 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8290 /* Always open the exchange */
8291 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
8292 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8293 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8294 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8295 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8296 LPFC_WQE_LENLOC_NONE
);
8297 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
8298 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
8299 iocbq
->iocb
.ulpFCP2Rcvy
);
8301 case CMD_GEN_REQUEST64_CR
:
8302 /* For this command calculate the xmit length of the
8306 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8307 sizeof(struct ulp_bde64
);
8308 for (i
= 0; i
< numBdes
; i
++) {
8309 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8310 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8312 xmit_len
+= bde
.tus
.f
.bdeSize
;
8314 /* word3 iocb=IO_TAG wqe=request_payload_len */
8315 wqe
->gen_req
.request_payload_len
= xmit_len
;
8316 /* word4 iocb=parameter wqe=relative_offset memcpy */
8317 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8318 /* word6 context tag copied in memcpy */
8319 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8320 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8321 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8322 "2015 Invalid CT %x command 0x%x\n",
8323 ct
, iocbq
->iocb
.ulpCommand
);
8326 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8327 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8328 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8329 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8330 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8331 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8332 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8333 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8334 wqe
->gen_req
.max_response_payload_len
= total_len
- xmit_len
;
8335 command_type
= OTHER_COMMAND
;
8337 case CMD_XMIT_ELS_RSP64_CX
:
8338 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8339 /* words0-2 BDE memcpy */
8340 /* word3 iocb=iotag32 wqe=response_payload_len */
8341 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8343 wqe
->xmit_els_rsp
.word4
= 0;
8344 /* word5 iocb=rsvd wge=did */
8345 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8346 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
8348 if_type
= bf_get(lpfc_sli_intf_if_type
,
8349 &phba
->sli4_hba
.sli_intf
);
8350 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8351 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
8352 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8353 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8354 iocbq
->vport
->fc_myDID
);
8355 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
8357 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
8361 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8362 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8363 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8364 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8365 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8366 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8367 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8368 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8369 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8370 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8371 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8372 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8373 LPFC_WQE_LENLOC_WORD3
);
8374 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8375 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8376 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8377 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8378 iocbq
->context2
)->virt
);
8379 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8380 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8381 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8382 iocbq
->vport
->fc_myDID
);
8383 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8384 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8385 phba
->vpi_ids
[phba
->pport
->vpi
]);
8387 command_type
= OTHER_COMMAND
;
8389 case CMD_CLOSE_XRI_CN
:
8390 case CMD_ABORT_XRI_CN
:
8391 case CMD_ABORT_XRI_CX
:
8392 /* words 0-2 memcpy should be 0 rserved */
8393 /* port will send abts */
8394 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8395 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8396 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8397 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8401 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8403 * The link is down, or the command was ELS_FIP
8404 * so the fw does not need to send abts
8407 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8409 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8410 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8411 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8412 wqe
->abort_cmd
.rsrvd5
= 0;
8413 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8414 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8415 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8417 * The abort handler will send us CMD_ABORT_XRI_CN or
8418 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8420 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8421 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8422 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8423 LPFC_WQE_LENLOC_NONE
);
8424 cmnd
= CMD_ABORT_XRI_CX
;
8425 command_type
= OTHER_COMMAND
;
8428 case CMD_XMIT_BLS_RSP64_CX
:
8429 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8430 /* As BLS ABTS RSP WQE is very different from other WQEs,
8431 * we re-construct this WQE here based on information in
8432 * iocbq from scratch.
8434 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8435 /* OX_ID is invariable to who sent ABTS to CT exchange */
8436 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8437 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8438 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8439 LPFC_ABTS_UNSOL_INT
) {
8440 /* ABTS sent by initiator to CT exchange, the
8441 * RX_ID field will be filled with the newly
8442 * allocated responder XRI.
8444 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8445 iocbq
->sli4_xritag
);
8447 /* ABTS sent by responder to CT exchange, the
8448 * RX_ID field will be filled with the responder
8451 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8452 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8454 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8455 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8458 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8460 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8461 iocbq
->iocb
.ulpContext
);
8462 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8463 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8464 phba
->vpi_ids
[phba
->pport
->vpi
]);
8465 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8466 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8467 LPFC_WQE_LENLOC_NONE
);
8468 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8469 command_type
= OTHER_COMMAND
;
8470 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8471 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8472 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8473 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8474 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8475 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8476 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8480 case CMD_XRI_ABORTED_CX
:
8481 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8482 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8483 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8484 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8485 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8487 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8488 "2014 Invalid command 0x%x\n",
8489 iocbq
->iocb
.ulpCommand
);
8494 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
8495 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
8496 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
8497 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
8498 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
8499 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
8500 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
8501 LPFC_IO_DIF_INSERT
);
8502 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8503 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8504 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8505 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8506 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8507 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8508 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8513 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8514 * @phba: Pointer to HBA context object.
8515 * @ring_number: SLI ring number to issue iocb on.
8516 * @piocb: Pointer to command iocb.
8517 * @flag: Flag indicating if this command can be put into txq.
8519 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8520 * an iocb command to an HBA with SLI-4 interface spec.
8522 * This function is called with hbalock held. The function will return success
8523 * after it successfully submit the iocb to firmware or after adding to the
8527 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8528 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8530 struct lpfc_sglq
*sglq
;
8532 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8534 if (piocb
->sli4_xritag
== NO_XRI
) {
8535 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8536 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8539 if (!list_empty(&pring
->txq
)) {
8540 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8541 __lpfc_sli_ringtx_put(phba
,
8543 return IOCB_SUCCESS
;
8548 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8550 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8551 __lpfc_sli_ringtx_put(phba
,
8554 return IOCB_SUCCESS
;
8560 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8561 /* These IO's already have an XRI and a mapped sgl. */
8565 * This is a continuation of a commandi,(CX) so this
8566 * sglq is on the active list
8568 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
8574 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8575 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8576 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8580 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8583 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8584 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8585 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8587 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8591 if (unlikely(!phba
->sli4_hba
.els_wq
))
8593 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8596 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8602 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8604 * This routine wraps the actual lockless version for issusing IOCB function
8605 * pointer from the lpfc_hba struct.
8608 * IOCB_ERROR - Error
8609 * IOCB_SUCCESS - Success
8613 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8614 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8616 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8620 * lpfc_sli_api_table_setup - Set up sli api function jump table
8621 * @phba: The hba struct for which this call is being executed.
8622 * @dev_grp: The HBA PCI-Device group number.
8624 * This routine sets up the SLI interface API function jump table in @phba
8626 * Returns: 0 - success, -ENODEV - failure.
8629 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8633 case LPFC_PCI_DEV_LP
:
8634 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8635 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8637 case LPFC_PCI_DEV_OC
:
8638 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8639 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8642 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8643 "1419 Invalid HBA PCI-device group: 0x%x\n",
8648 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8653 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8654 * @phba: Pointer to HBA context object.
8655 * @pring: Pointer to driver SLI ring object.
8656 * @piocb: Pointer to command iocb.
8657 * @flag: Flag indicating if this command can be put into txq.
8659 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8660 * function. This function gets the hbalock and calls
8661 * __lpfc_sli_issue_iocb function and will return the error returned
8662 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8663 * functions which do not hold hbalock.
8666 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8667 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8669 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
8670 struct lpfc_sli_ring
*pring
;
8671 struct lpfc_queue
*fpeq
;
8672 struct lpfc_eqe
*eqe
;
8673 unsigned long iflags
;
8676 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8677 if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8678 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8680 idx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8681 piocb
->fcp_wqidx
= idx
;
8682 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+ idx
;
8684 pring
= &phba
->sli
.ring
[ring_number
];
8685 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8686 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8688 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8690 if (lpfc_fcp_look_ahead
) {
8691 fcp_eq_hdl
= &phba
->sli4_hba
.fcp_eq_hdl
[idx
];
8693 if (atomic_dec_and_test(&fcp_eq_hdl
->
8696 /* Get associated EQ with this index */
8697 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
8699 /* Turn off interrupts from this EQ */
8700 lpfc_sli4_eq_clr_intr(fpeq
);
8703 * Process all the events on FCP EQ
8705 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
8706 lpfc_sli4_hba_handle_eqe(phba
,
8708 fpeq
->EQ_processed
++;
8711 /* Always clear and re-arm the EQ */
8712 lpfc_sli4_eq_release(fpeq
,
8715 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
8718 pring
= &phba
->sli
.ring
[ring_number
];
8719 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8720 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8722 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8726 /* For now, SLI2/3 will still use hbalock */
8727 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8728 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8729 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8735 * lpfc_extra_ring_setup - Extra ring setup function
8736 * @phba: Pointer to HBA context object.
8738 * This function is called while driver attaches with the
8739 * HBA to setup the extra ring. The extra ring is used
8740 * only when driver needs to support target mode functionality
8741 * or IP over FC functionalities.
8743 * This function is called with no lock held.
8746 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8748 struct lpfc_sli
*psli
;
8749 struct lpfc_sli_ring
*pring
;
8753 /* Adjust cmd/rsp ring iocb entries more evenly */
8755 /* Take some away from the FCP ring */
8756 pring
= &psli
->ring
[psli
->fcp_ring
];
8757 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8758 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8759 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8760 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8762 /* and give them to the extra ring */
8763 pring
= &psli
->ring
[psli
->extra_ring
];
8765 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8766 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8767 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8768 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8770 /* Setup default profile for this ring */
8771 pring
->iotag_max
= 4096;
8772 pring
->num_mask
= 1;
8773 pring
->prt
[0].profile
= 0; /* Mask 0 */
8774 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8775 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8776 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8780 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8781 * @phba: Pointer to HBA context object.
8782 * @iocbq: Pointer to iocb object.
8784 * The async_event handler calls this routine when it receives
8785 * an ASYNC_STATUS_CN event from the port. The port generates
8786 * this event when an Abort Sequence request to an rport fails
8787 * twice in succession. The abort could be originated by the
8788 * driver or by the port. The ABTS could have been for an ELS
8789 * or FCP IO. The port only generates this event when an ABTS
8790 * fails to complete after one retry.
8793 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8794 struct lpfc_iocbq
*iocbq
)
8796 struct lpfc_nodelist
*ndlp
= NULL
;
8797 uint16_t rpi
= 0, vpi
= 0;
8798 struct lpfc_vport
*vport
= NULL
;
8800 /* The rpi in the ulpContext is vport-sensitive. */
8801 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8802 rpi
= iocbq
->iocb
.ulpContext
;
8804 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8805 "3092 Port generated ABTS async event "
8806 "on vpi %d rpi %d status 0x%x\n",
8807 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8809 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8812 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8813 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8816 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8817 lpfc_sli_abts_recover_port(vport
, ndlp
);
8821 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8822 "3095 Event Context not found, no "
8823 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8824 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8828 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8829 * @phba: pointer to HBA context object.
8830 * @ndlp: nodelist pointer for the impacted rport.
8831 * @axri: pointer to the wcqe containing the failed exchange.
8833 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8834 * port. The port generates this event when an abort exchange request to an
8835 * rport fails twice in succession with no reply. The abort could be originated
8836 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8839 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8840 struct lpfc_nodelist
*ndlp
,
8841 struct sli4_wcqe_xri_aborted
*axri
)
8843 struct lpfc_vport
*vport
;
8844 uint32_t ext_status
= 0;
8846 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
8847 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8848 "3115 Node Context not found, driver "
8849 "ignoring abts err event\n");
8853 vport
= ndlp
->vport
;
8854 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8855 "3116 Port generated FCP XRI ABORT event on "
8856 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8857 ndlp
->vport
->vpi
, phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
],
8858 bf_get(lpfc_wcqe_xa_xri
, axri
),
8859 bf_get(lpfc_wcqe_xa_status
, axri
),
8863 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8864 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8865 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8867 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
8868 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
8869 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
8870 lpfc_sli_abts_recover_port(vport
, ndlp
);
8874 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8875 * @phba: Pointer to HBA context object.
8876 * @pring: Pointer to driver SLI ring object.
8877 * @iocbq: Pointer to iocb object.
8879 * This function is called by the slow ring event handler
8880 * function when there is an ASYNC event iocb in the ring.
8881 * This function is called with no lock held.
8882 * Currently this function handles only temperature related
8883 * ASYNC events. The function decodes the temperature sensor
8884 * event message and posts events for the management applications.
8887 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8888 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8892 struct temp_event temp_event_data
;
8893 struct Scsi_Host
*shost
;
8896 icmd
= &iocbq
->iocb
;
8897 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8900 case ASYNC_TEMP_WARN
:
8901 case ASYNC_TEMP_SAFE
:
8902 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8903 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8904 if (evt_code
== ASYNC_TEMP_WARN
) {
8905 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8906 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8907 "0347 Adapter is very hot, please take "
8908 "corrective action. temperature : %d Celsius\n",
8909 (uint32_t) icmd
->ulpContext
);
8911 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8912 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8913 "0340 Adapter temperature is OK now. "
8914 "temperature : %d Celsius\n",
8915 (uint32_t) icmd
->ulpContext
);
8918 /* Send temperature change event to applications */
8919 shost
= lpfc_shost_from_vport(phba
->pport
);
8920 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8921 sizeof(temp_event_data
), (char *) &temp_event_data
,
8924 case ASYNC_STATUS_CN
:
8925 lpfc_sli_abts_err_handler(phba
, iocbq
);
8928 iocb_w
= (uint32_t *) icmd
;
8929 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8930 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8932 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8933 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8934 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8935 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8936 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8937 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8938 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8939 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8940 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8948 * lpfc_sli_setup - SLI ring setup function
8949 * @phba: Pointer to HBA context object.
8951 * lpfc_sli_setup sets up rings of the SLI interface with
8952 * number of iocbs per ring and iotags. This function is
8953 * called while driver attach to the HBA and before the
8954 * interrupts are enabled. So there is no need for locking.
8956 * This function always returns 0.
8959 lpfc_sli_setup(struct lpfc_hba
*phba
)
8961 int i
, totiocbsize
= 0;
8962 struct lpfc_sli
*psli
= &phba
->sli
;
8963 struct lpfc_sli_ring
*pring
;
8965 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
8966 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8967 psli
->num_rings
+= phba
->cfg_fcp_io_channel
;
8969 psli
->fcp_ring
= LPFC_FCP_RING
;
8970 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8971 psli
->extra_ring
= LPFC_EXTRA_RING
;
8973 psli
->iocbq_lookup
= NULL
;
8974 psli
->iocbq_lookup_len
= 0;
8975 psli
->last_iotag
= 0;
8977 for (i
= 0; i
< psli
->num_rings
; i
++) {
8978 pring
= &psli
->ring
[i
];
8980 case LPFC_FCP_RING
: /* ring 0 - FCP */
8981 /* numCiocb and numRiocb are used in config_port */
8982 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8983 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8984 pring
->sli
.sli3
.numCiocb
+=
8985 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8986 pring
->sli
.sli3
.numRiocb
+=
8987 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8988 pring
->sli
.sli3
.numCiocb
+=
8989 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8990 pring
->sli
.sli3
.numRiocb
+=
8991 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8992 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8993 SLI3_IOCB_CMD_SIZE
:
8995 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8996 SLI3_IOCB_RSP_SIZE
:
8998 pring
->iotag_ctr
= 0;
9000 (phba
->cfg_hba_queue_depth
* 2);
9001 pring
->fast_iotag
= pring
->iotag_max
;
9002 pring
->num_mask
= 0;
9004 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
9005 /* numCiocb and numRiocb are used in config_port */
9006 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
9007 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
9008 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9009 SLI3_IOCB_CMD_SIZE
:
9011 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9012 SLI3_IOCB_RSP_SIZE
:
9014 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
9015 pring
->num_mask
= 0;
9017 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
9018 /* numCiocb and numRiocb are used in config_port */
9019 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
9020 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
9021 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
9022 SLI3_IOCB_CMD_SIZE
:
9024 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
9025 SLI3_IOCB_RSP_SIZE
:
9027 pring
->fast_iotag
= 0;
9028 pring
->iotag_ctr
= 0;
9029 pring
->iotag_max
= 4096;
9030 pring
->lpfc_sli_rcv_async_status
=
9031 lpfc_sli_async_event_handler
;
9032 pring
->num_mask
= LPFC_MAX_RING_MASK
;
9033 pring
->prt
[0].profile
= 0; /* Mask 0 */
9034 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
9035 pring
->prt
[0].type
= FC_TYPE_ELS
;
9036 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
9037 lpfc_els_unsol_event
;
9038 pring
->prt
[1].profile
= 0; /* Mask 1 */
9039 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
9040 pring
->prt
[1].type
= FC_TYPE_ELS
;
9041 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
9042 lpfc_els_unsol_event
;
9043 pring
->prt
[2].profile
= 0; /* Mask 2 */
9044 /* NameServer Inquiry */
9045 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
9047 pring
->prt
[2].type
= FC_TYPE_CT
;
9048 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
9049 lpfc_ct_unsol_event
;
9050 pring
->prt
[3].profile
= 0; /* Mask 3 */
9051 /* NameServer response */
9052 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
9054 pring
->prt
[3].type
= FC_TYPE_CT
;
9055 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
9056 lpfc_ct_unsol_event
;
9059 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
9060 pring
->sli
.sli3
.sizeCiocb
) +
9061 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
9063 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
9064 /* Too many cmd / rsp ring entries in SLI2 SLIM */
9065 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
9066 "SLI2 SLIM Data: x%x x%lx\n",
9067 phba
->brd_no
, totiocbsize
,
9068 (unsigned long) MAX_SLIM_IOCB_SIZE
);
9070 if (phba
->cfg_multi_ring_support
== 2)
9071 lpfc_extra_ring_setup(phba
);
9077 * lpfc_sli_queue_setup - Queue initialization function
9078 * @phba: Pointer to HBA context object.
9080 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
9081 * ring. This function also initializes ring indices of each ring.
9082 * This function is called during the initialization of the SLI
9083 * interface of an HBA.
9084 * This function is called with no lock held and always returns
9088 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
9090 struct lpfc_sli
*psli
;
9091 struct lpfc_sli_ring
*pring
;
9095 spin_lock_irq(&phba
->hbalock
);
9096 INIT_LIST_HEAD(&psli
->mboxq
);
9097 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
9098 /* Initialize list headers for txq and txcmplq as double linked lists */
9099 for (i
= 0; i
< psli
->num_rings
; i
++) {
9100 pring
= &psli
->ring
[i
];
9102 pring
->sli
.sli3
.next_cmdidx
= 0;
9103 pring
->sli
.sli3
.local_getidx
= 0;
9104 pring
->sli
.sli3
.cmdidx
= 0;
9105 INIT_LIST_HEAD(&pring
->txq
);
9106 INIT_LIST_HEAD(&pring
->txcmplq
);
9107 INIT_LIST_HEAD(&pring
->iocb_continueq
);
9108 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
9109 INIT_LIST_HEAD(&pring
->postbufq
);
9110 spin_lock_init(&pring
->ring_lock
);
9112 spin_unlock_irq(&phba
->hbalock
);
9117 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
9118 * @phba: Pointer to HBA context object.
9120 * This routine flushes the mailbox command subsystem. It will unconditionally
9121 * flush all the mailbox commands in the three possible stages in the mailbox
9122 * command sub-system: pending mailbox command queue; the outstanding mailbox
9123 * command; and completed mailbox command queue. It is caller's responsibility
9124 * to make sure that the driver is in the proper state to flush the mailbox
9125 * command sub-system. Namely, the posting of mailbox commands into the
9126 * pending mailbox command queue from the various clients must be stopped;
9127 * either the HBA is in a state that it will never works on the outstanding
9128 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
9129 * mailbox command has been completed.
9132 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
9134 LIST_HEAD(completions
);
9135 struct lpfc_sli
*psli
= &phba
->sli
;
9137 unsigned long iflag
;
9139 /* Flush all the mailbox commands in the mbox system */
9140 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9141 /* The pending mailbox command queue */
9142 list_splice_init(&phba
->sli
.mboxq
, &completions
);
9143 /* The outstanding active mailbox command */
9144 if (psli
->mbox_active
) {
9145 list_add_tail(&psli
->mbox_active
->list
, &completions
);
9146 psli
->mbox_active
= NULL
;
9147 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9149 /* The completed mailbox command queue */
9150 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
9151 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9153 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
9154 while (!list_empty(&completions
)) {
9155 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
9156 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
9158 pmb
->mbox_cmpl(phba
, pmb
);
9163 * lpfc_sli_host_down - Vport cleanup function
9164 * @vport: Pointer to virtual port object.
9166 * lpfc_sli_host_down is called to clean up the resources
9167 * associated with a vport before destroying virtual
9168 * port data structures.
9169 * This function does following operations:
9170 * - Free discovery resources associated with this virtual
9172 * - Free iocbs associated with this virtual port in
9174 * - Send abort for all iocb commands associated with this
9177 * This function is called with no lock held and always returns 1.
9180 lpfc_sli_host_down(struct lpfc_vport
*vport
)
9182 LIST_HEAD(completions
);
9183 struct lpfc_hba
*phba
= vport
->phba
;
9184 struct lpfc_sli
*psli
= &phba
->sli
;
9185 struct lpfc_sli_ring
*pring
;
9186 struct lpfc_iocbq
*iocb
, *next_iocb
;
9188 unsigned long flags
= 0;
9189 uint16_t prev_pring_flag
;
9191 lpfc_cleanup_discovery_resources(vport
);
9193 spin_lock_irqsave(&phba
->hbalock
, flags
);
9194 for (i
= 0; i
< psli
->num_rings
; i
++) {
9195 pring
= &psli
->ring
[i
];
9196 prev_pring_flag
= pring
->flag
;
9197 /* Only slow rings */
9198 if (pring
->ringno
== LPFC_ELS_RING
) {
9199 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9200 /* Set the lpfc data pending flag */
9201 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9204 * Error everything on the txq since these iocbs have not been
9205 * given to the FW yet.
9207 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
9208 if (iocb
->vport
!= vport
)
9210 list_move_tail(&iocb
->list
, &completions
);
9213 /* Next issue ABTS for everything on the txcmplq */
9214 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
9216 if (iocb
->vport
!= vport
)
9218 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
9221 pring
->flag
= prev_pring_flag
;
9224 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9226 /* Cancel all the IOCBs from the completions list */
9227 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9233 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9234 * @phba: Pointer to HBA context object.
9236 * This function cleans up all iocb, buffers, mailbox commands
9237 * while shutting down the HBA. This function is called with no
9238 * lock held and always returns 1.
9239 * This function does the following to cleanup driver resources:
9240 * - Free discovery resources for each virtual port
9241 * - Cleanup any pending fabric iocbs
9242 * - Iterate through the iocb txq and free each entry
9244 * - Free up any buffer posted to the HBA
9245 * - Free mailbox commands in the mailbox queue.
9248 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
9250 LIST_HEAD(completions
);
9251 struct lpfc_sli
*psli
= &phba
->sli
;
9252 struct lpfc_sli_ring
*pring
;
9253 struct lpfc_dmabuf
*buf_ptr
;
9254 unsigned long flags
= 0;
9257 /* Shutdown the mailbox command sub-system */
9258 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
9260 lpfc_hba_down_prep(phba
);
9262 lpfc_fabric_abort_hba(phba
);
9264 spin_lock_irqsave(&phba
->hbalock
, flags
);
9265 for (i
= 0; i
< psli
->num_rings
; i
++) {
9266 pring
= &psli
->ring
[i
];
9267 /* Only slow rings */
9268 if (pring
->ringno
== LPFC_ELS_RING
) {
9269 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9270 /* Set the lpfc data pending flag */
9271 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9275 * Error everything on the txq since these iocbs have not been
9276 * given to the FW yet.
9278 list_splice_init(&pring
->txq
, &completions
);
9280 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9282 /* Cancel all the IOCBs from the completions list */
9283 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9286 spin_lock_irqsave(&phba
->hbalock
, flags
);
9287 list_splice_init(&phba
->elsbuf
, &completions
);
9288 phba
->elsbuf_cnt
= 0;
9289 phba
->elsbuf_prev_cnt
= 0;
9290 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9292 while (!list_empty(&completions
)) {
9293 list_remove_head(&completions
, buf_ptr
,
9294 struct lpfc_dmabuf
, list
);
9295 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
9299 /* Return any active mbox cmds */
9300 del_timer_sync(&psli
->mbox_tmo
);
9302 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
9303 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9304 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9310 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9311 * @srcp: Source memory pointer.
9312 * @destp: Destination memory pointer.
9313 * @cnt: Number of words required to be copied.
9315 * This function is used for copying data between driver memory
9316 * and the SLI memory. This function also changes the endianness
9317 * of each word if native endianness is different from SLI
9318 * endianness. This function can be called with or without
9322 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9324 uint32_t *src
= srcp
;
9325 uint32_t *dest
= destp
;
9329 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9331 ldata
= le32_to_cpu(ldata
);
9340 * lpfc_sli_bemem_bcopy - SLI memory copy function
9341 * @srcp: Source memory pointer.
9342 * @destp: Destination memory pointer.
9343 * @cnt: Number of words required to be copied.
9345 * This function is used for copying data between a data structure
9346 * with big endian representation to local endianness.
9347 * This function can be called with or without lock.
9350 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9352 uint32_t *src
= srcp
;
9353 uint32_t *dest
= destp
;
9357 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9359 ldata
= be32_to_cpu(ldata
);
9367 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9368 * @phba: Pointer to HBA context object.
9369 * @pring: Pointer to driver SLI ring object.
9370 * @mp: Pointer to driver buffer object.
9372 * This function is called with no lock held.
9373 * It always return zero after adding the buffer to the postbufq
9377 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9378 struct lpfc_dmabuf
*mp
)
9380 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9382 spin_lock_irq(&phba
->hbalock
);
9383 list_add_tail(&mp
->list
, &pring
->postbufq
);
9384 pring
->postbufq_cnt
++;
9385 spin_unlock_irq(&phba
->hbalock
);
9390 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9391 * @phba: Pointer to HBA context object.
9393 * When HBQ is enabled, buffers are searched based on tags. This function
9394 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9395 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9396 * does not conflict with tags of buffer posted for unsolicited events.
9397 * The function returns the allocated tag. The function is called with
9401 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9403 spin_lock_irq(&phba
->hbalock
);
9404 phba
->buffer_tag_count
++;
9406 * Always set the QUE_BUFTAG_BIT to distiguish between
9407 * a tag assigned by HBQ.
9409 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9410 spin_unlock_irq(&phba
->hbalock
);
9411 return phba
->buffer_tag_count
;
9415 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9416 * @phba: Pointer to HBA context object.
9417 * @pring: Pointer to driver SLI ring object.
9420 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9421 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9422 * iocb is posted to the response ring with the tag of the buffer.
9423 * This function searches the pring->postbufq list using the tag
9424 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9425 * iocb. If the buffer is found then lpfc_dmabuf object of the
9426 * buffer is returned to the caller else NULL is returned.
9427 * This function is called with no lock held.
9429 struct lpfc_dmabuf
*
9430 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9433 struct lpfc_dmabuf
*mp
, *next_mp
;
9434 struct list_head
*slp
= &pring
->postbufq
;
9436 /* Search postbufq, from the beginning, looking for a match on tag */
9437 spin_lock_irq(&phba
->hbalock
);
9438 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9439 if (mp
->buffer_tag
== tag
) {
9440 list_del_init(&mp
->list
);
9441 pring
->postbufq_cnt
--;
9442 spin_unlock_irq(&phba
->hbalock
);
9447 spin_unlock_irq(&phba
->hbalock
);
9448 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9449 "0402 Cannot find virtual addr for buffer tag on "
9450 "ring %d Data x%lx x%p x%p x%x\n",
9451 pring
->ringno
, (unsigned long) tag
,
9452 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9458 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9459 * @phba: Pointer to HBA context object.
9460 * @pring: Pointer to driver SLI ring object.
9461 * @phys: DMA address of the buffer.
9463 * This function searches the buffer list using the dma_address
9464 * of unsolicited event to find the driver's lpfc_dmabuf object
9465 * corresponding to the dma_address. The function returns the
9466 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9467 * This function is called by the ct and els unsolicited event
9468 * handlers to get the buffer associated with the unsolicited
9471 * This function is called with no lock held.
9473 struct lpfc_dmabuf
*
9474 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9477 struct lpfc_dmabuf
*mp
, *next_mp
;
9478 struct list_head
*slp
= &pring
->postbufq
;
9480 /* Search postbufq, from the beginning, looking for a match on phys */
9481 spin_lock_irq(&phba
->hbalock
);
9482 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9483 if (mp
->phys
== phys
) {
9484 list_del_init(&mp
->list
);
9485 pring
->postbufq_cnt
--;
9486 spin_unlock_irq(&phba
->hbalock
);
9491 spin_unlock_irq(&phba
->hbalock
);
9492 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9493 "0410 Cannot find virtual addr for mapped buf on "
9494 "ring %d Data x%llx x%p x%p x%x\n",
9495 pring
->ringno
, (unsigned long long)phys
,
9496 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9501 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9502 * @phba: Pointer to HBA context object.
9503 * @cmdiocb: Pointer to driver command iocb object.
9504 * @rspiocb: Pointer to driver response iocb object.
9506 * This function is the completion handler for the abort iocbs for
9507 * ELS commands. This function is called from the ELS ring event
9508 * handler with no lock held. This function frees memory resources
9509 * associated with the abort iocb.
9512 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9513 struct lpfc_iocbq
*rspiocb
)
9515 IOCB_t
*irsp
= &rspiocb
->iocb
;
9516 uint16_t abort_iotag
, abort_context
;
9517 struct lpfc_iocbq
*abort_iocb
= NULL
;
9519 if (irsp
->ulpStatus
) {
9522 * Assume that the port already completed and returned, or
9523 * will return the iocb. Just Log the message.
9525 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9526 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9528 spin_lock_irq(&phba
->hbalock
);
9529 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9530 if (abort_iotag
!= 0 &&
9531 abort_iotag
<= phba
->sli
.last_iotag
)
9533 phba
->sli
.iocbq_lookup
[abort_iotag
];
9535 /* For sli4 the abort_tag is the XRI,
9536 * so the abort routine puts the iotag of the iocb
9537 * being aborted in the context field of the abort
9540 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9542 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9543 "0327 Cannot abort els iocb %p "
9544 "with tag %x context %x, abort status %x, "
9546 abort_iocb
, abort_iotag
, abort_context
,
9547 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9549 spin_unlock_irq(&phba
->hbalock
);
9551 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9556 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9557 * @phba: Pointer to HBA context object.
9558 * @cmdiocb: Pointer to driver command iocb object.
9559 * @rspiocb: Pointer to driver response iocb object.
9561 * The function is called from SLI ring event handler with no
9562 * lock held. This function is the completion handler for ELS commands
9563 * which are aborted. The function frees memory resources used for
9564 * the aborted ELS commands.
9567 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9568 struct lpfc_iocbq
*rspiocb
)
9570 IOCB_t
*irsp
= &rspiocb
->iocb
;
9572 /* ELS cmd tag <ulpIoTag> completes */
9573 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9574 "0139 Ignoring ELS cmd tag x%x completion Data: "
9576 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9577 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9578 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9579 lpfc_ct_free_iocb(phba
, cmdiocb
);
9581 lpfc_els_free_iocb(phba
, cmdiocb
);
9586 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9587 * @phba: Pointer to HBA context object.
9588 * @pring: Pointer to driver SLI ring object.
9589 * @cmdiocb: Pointer to driver command iocb object.
9591 * This function issues an abort iocb for the provided command iocb down to
9592 * the port. Other than the case the outstanding command iocb is an abort
9593 * request, this function issues abort out unconditionally. This function is
9594 * called with hbalock held. The function returns 0 when it fails due to
9595 * memory allocation failure or when the command iocb is an abort request.
9598 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9599 struct lpfc_iocbq
*cmdiocb
)
9601 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9602 struct lpfc_iocbq
*abtsiocbp
;
9603 IOCB_t
*icmd
= NULL
;
9604 IOCB_t
*iabt
= NULL
;
9606 unsigned long iflags
;
9609 * There are certain command types we don't want to abort. And we
9610 * don't want to abort commands that are already in the process of
9613 icmd
= &cmdiocb
->iocb
;
9614 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9615 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9616 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9619 /* issue ABTS for this IOCB based on iotag */
9620 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9621 if (abtsiocbp
== NULL
)
9624 /* This signals the response to set the correct status
9625 * before calling the completion handler
9627 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9629 iabt
= &abtsiocbp
->iocb
;
9630 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9631 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9632 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9633 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9634 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9637 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9639 iabt
->ulpClass
= icmd
->ulpClass
;
9641 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9642 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9643 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9644 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9646 if (phba
->link_state
>= LPFC_LINK_UP
)
9647 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9649 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9651 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9653 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9654 "0339 Abort xri x%x, original iotag x%x, "
9655 "abort cmd iotag x%x\n",
9656 iabt
->un
.acxri
.abortIoTag
,
9657 iabt
->un
.acxri
.abortContextTag
,
9660 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9661 /* Note: both hbalock and ring_lock need to be set here */
9662 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9663 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9665 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9667 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9672 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9675 * Caller to this routine should check for IOCB_ERROR
9676 * and handle it properly. This routine no longer removes
9677 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9683 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9684 * @phba: Pointer to HBA context object.
9685 * @pring: Pointer to driver SLI ring object.
9686 * @cmdiocb: Pointer to driver command iocb object.
9688 * This function issues an abort iocb for the provided command iocb. In case
9689 * of unloading, the abort iocb will not be issued to commands on the ELS
9690 * ring. Instead, the callback function shall be changed to those commands
9691 * so that nothing happens when them finishes. This function is called with
9692 * hbalock held. The function returns 0 when the command iocb is an abort
9696 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9697 struct lpfc_iocbq
*cmdiocb
)
9699 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9700 int retval
= IOCB_ERROR
;
9701 IOCB_t
*icmd
= NULL
;
9704 * There are certain command types we don't want to abort. And we
9705 * don't want to abort commands that are already in the process of
9708 icmd
= &cmdiocb
->iocb
;
9709 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9710 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9711 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9715 * If we're unloading, don't abort iocb on the ELS ring, but change
9716 * the callback so that nothing happens when it finishes.
9718 if ((vport
->load_flag
& FC_UNLOADING
) &&
9719 (pring
->ringno
== LPFC_ELS_RING
)) {
9720 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9721 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9723 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9724 goto abort_iotag_exit
;
9727 /* Now, we try to issue the abort to the cmdiocb out */
9728 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9732 * Caller to this routine should check for IOCB_ERROR
9733 * and handle it properly. This routine no longer removes
9734 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9740 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9741 * @phba: Pointer to HBA context object.
9742 * @pring: Pointer to driver SLI ring object.
9744 * This function aborts all iocbs in the given ring and frees all the iocb
9745 * objects in txq. This function issues abort iocbs unconditionally for all
9746 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9747 * to complete before the return of this function. The caller is not required
9748 * to hold any locks.
9751 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9753 LIST_HEAD(completions
);
9754 struct lpfc_iocbq
*iocb
, *next_iocb
;
9756 if (pring
->ringno
== LPFC_ELS_RING
)
9757 lpfc_fabric_abort_hba(phba
);
9759 spin_lock_irq(&phba
->hbalock
);
9761 /* Take off all the iocbs on txq for cancelling */
9762 list_splice_init(&pring
->txq
, &completions
);
9765 /* Next issue ABTS for everything on the txcmplq */
9766 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9767 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9769 spin_unlock_irq(&phba
->hbalock
);
9771 /* Cancel all the IOCBs from the completions list */
9772 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9777 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9778 * @phba: pointer to lpfc HBA data structure.
9780 * This routine will abort all pending and outstanding iocbs to an HBA.
9783 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9785 struct lpfc_sli
*psli
= &phba
->sli
;
9786 struct lpfc_sli_ring
*pring
;
9789 for (i
= 0; i
< psli
->num_rings
; i
++) {
9790 pring
= &psli
->ring
[i
];
9791 lpfc_sli_iocb_ring_abort(phba
, pring
);
9796 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9797 * @iocbq: Pointer to driver iocb object.
9798 * @vport: Pointer to driver virtual port object.
9799 * @tgt_id: SCSI ID of the target.
9800 * @lun_id: LUN ID of the scsi device.
9801 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9803 * This function acts as an iocb filter for functions which abort or count
9804 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9805 * 0 if the filtering criteria is met for the given iocb and will return
9806 * 1 if the filtering criteria is not met.
9807 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9808 * given iocb is for the SCSI device specified by vport, tgt_id and
9810 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9811 * given iocb is for the SCSI target specified by vport and tgt_id
9813 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9814 * given iocb is for the SCSI host associated with the given vport.
9815 * This function is called with no locks held.
9818 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9819 uint16_t tgt_id
, uint64_t lun_id
,
9820 lpfc_ctx_cmd ctx_cmd
)
9822 struct lpfc_scsi_buf
*lpfc_cmd
;
9825 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9828 if (iocbq
->vport
!= vport
)
9831 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9833 if (lpfc_cmd
->pCmd
== NULL
)
9838 if ((lpfc_cmd
->rdata
->pnode
) &&
9839 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9840 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9844 if ((lpfc_cmd
->rdata
->pnode
) &&
9845 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9852 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9861 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9862 * @vport: Pointer to virtual port.
9863 * @tgt_id: SCSI ID of the target.
9864 * @lun_id: LUN ID of the scsi device.
9865 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9867 * This function returns number of FCP commands pending for the vport.
9868 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9869 * commands pending on the vport associated with SCSI device specified
9870 * by tgt_id and lun_id parameters.
9871 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9872 * commands pending on the vport associated with SCSI target specified
9873 * by tgt_id parameter.
9874 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9875 * commands pending on the vport.
9876 * This function returns the number of iocbs which satisfy the filter.
9877 * This function is called without any lock held.
9880 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9881 lpfc_ctx_cmd ctx_cmd
)
9883 struct lpfc_hba
*phba
= vport
->phba
;
9884 struct lpfc_iocbq
*iocbq
;
9887 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9888 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9890 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9899 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9900 * @phba: Pointer to HBA context object
9901 * @cmdiocb: Pointer to command iocb object.
9902 * @rspiocb: Pointer to response iocb object.
9904 * This function is called when an aborted FCP iocb completes. This
9905 * function is called by the ring event handler with no lock held.
9906 * This function frees the iocb.
9909 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9910 struct lpfc_iocbq
*rspiocb
)
9912 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9913 "3096 ABORT_XRI_CN completing on rpi x%x "
9914 "original iotag x%x, abort cmd iotag x%x "
9915 "status 0x%x, reason 0x%x\n",
9916 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9917 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9918 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9919 rspiocb
->iocb
.un
.ulpWord
[4]);
9920 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9925 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9926 * @vport: Pointer to virtual port.
9927 * @pring: Pointer to driver SLI ring object.
9928 * @tgt_id: SCSI ID of the target.
9929 * @lun_id: LUN ID of the scsi device.
9930 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9932 * This function sends an abort command for every SCSI command
9933 * associated with the given virtual port pending on the ring
9934 * filtered by lpfc_sli_validate_fcp_iocb function.
9935 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9936 * FCP iocbs associated with lun specified by tgt_id and lun_id
9938 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9939 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9940 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9941 * FCP iocbs associated with virtual port.
9942 * This function returns number of iocbs it failed to abort.
9943 * This function is called with no locks held.
9946 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9947 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9949 struct lpfc_hba
*phba
= vport
->phba
;
9950 struct lpfc_iocbq
*iocbq
;
9951 struct lpfc_iocbq
*abtsiocb
;
9953 int errcnt
= 0, ret_val
= 0;
9956 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9957 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9959 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9964 * If the iocbq is already being aborted, don't take a second
9965 * action, but do count it.
9967 if (iocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
9970 /* issue ABTS for this IOCB based on iotag */
9971 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9972 if (abtsiocb
== NULL
) {
9977 /* indicate the IO is being aborted by the driver. */
9978 iocbq
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9981 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9982 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9983 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9984 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9986 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9987 abtsiocb
->iocb
.ulpLe
= 1;
9988 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9989 abtsiocb
->vport
= vport
;
9991 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9992 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9993 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9994 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9996 if (lpfc_is_link_up(phba
))
9997 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9999 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
10001 /* Setup callback routine and issue the command. */
10002 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
10003 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
10005 if (ret_val
== IOCB_ERROR
) {
10006 lpfc_sli_release_iocbq(phba
, abtsiocb
);
10016 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
10017 * @phba: Pointer to HBA context object.
10018 * @cmdiocbq: Pointer to command iocb.
10019 * @rspiocbq: Pointer to response iocb.
10021 * This function is the completion handler for iocbs issued using
10022 * lpfc_sli_issue_iocb_wait function. This function is called by the
10023 * ring event handler function without any lock held. This function
10024 * can be called from both worker thread context and interrupt
10025 * context. This function also can be called from other thread which
10026 * cleans up the SLI layer objects.
10027 * This function copy the contents of the response iocb to the
10028 * response iocb memory object provided by the caller of
10029 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
10030 * sleeps for the iocb completion.
10033 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
10034 struct lpfc_iocbq
*cmdiocbq
,
10035 struct lpfc_iocbq
*rspiocbq
)
10037 wait_queue_head_t
*pdone_q
;
10038 unsigned long iflags
;
10039 struct lpfc_scsi_buf
*lpfc_cmd
;
10041 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10042 if (cmdiocbq
->iocb_flag
& LPFC_IO_WAKE_TMO
) {
10045 * A time out has occurred for the iocb. If a time out
10046 * completion handler has been supplied, call it. Otherwise,
10047 * just free the iocbq.
10050 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10051 cmdiocbq
->iocb_cmpl
= cmdiocbq
->wait_iocb_cmpl
;
10052 cmdiocbq
->wait_iocb_cmpl
= NULL
;
10053 if (cmdiocbq
->iocb_cmpl
)
10054 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, NULL
);
10056 lpfc_sli_release_iocbq(phba
, cmdiocbq
);
10060 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
10061 if (cmdiocbq
->context2
&& rspiocbq
)
10062 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
10063 &rspiocbq
->iocb
, sizeof(IOCB_t
));
10065 /* Set the exchange busy flag for task management commands */
10066 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
10067 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
10068 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
10070 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
10073 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
10076 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10081 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
10082 * @phba: Pointer to HBA context object..
10083 * @piocbq: Pointer to command iocb.
10084 * @flag: Flag to test.
10086 * This routine grabs the hbalock and then test the iocb_flag to
10087 * see if the passed in flag is set.
10089 * 1 if flag is set.
10090 * 0 if flag is not set.
10093 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
10094 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
10096 unsigned long iflags
;
10099 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10100 ret
= piocbq
->iocb_flag
& flag
;
10101 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10107 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
10108 * @phba: Pointer to HBA context object..
10109 * @pring: Pointer to sli ring.
10110 * @piocb: Pointer to command iocb.
10111 * @prspiocbq: Pointer to response iocb.
10112 * @timeout: Timeout in number of seconds.
10114 * This function issues the iocb to firmware and waits for the
10115 * iocb to complete. The iocb_cmpl field of the shall be used
10116 * to handle iocbs which time out. If the field is NULL, the
10117 * function shall free the iocbq structure. If more clean up is
10118 * needed, the caller is expected to provide a completion function
10119 * that will provide the needed clean up. If the iocb command is
10120 * not completed within timeout seconds, the function will either
10121 * free the iocbq structure (if iocb_cmpl == NULL) or execute the
10122 * completion function set in the iocb_cmpl field and then return
10123 * a status of IOCB_TIMEDOUT. The caller should not free the iocb
10124 * resources if this function returns IOCB_TIMEDOUT.
10125 * The function waits for the iocb completion using an
10126 * non-interruptible wait.
10127 * This function will sleep while waiting for iocb completion.
10128 * So, this function should not be called from any context which
10129 * does not allow sleeping. Due to the same reason, this function
10130 * cannot be called with interrupt disabled.
10131 * This function assumes that the iocb completions occur while
10132 * this function sleep. So, this function cannot be called from
10133 * the thread which process iocb completion for this ring.
10134 * This function clears the iocb_flag of the iocb object before
10135 * issuing the iocb and the iocb completion handler sets this
10136 * flag and wakes this thread when the iocb completes.
10137 * The contents of the response iocb will be copied to prspiocbq
10138 * by the completion handler when the command completes.
10139 * This function returns IOCB_SUCCESS when success.
10140 * This function is called with no lock held.
10143 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
10144 uint32_t ring_number
,
10145 struct lpfc_iocbq
*piocb
,
10146 struct lpfc_iocbq
*prspiocbq
,
10149 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10150 long timeleft
, timeout_req
= 0;
10151 int retval
= IOCB_SUCCESS
;
10153 struct lpfc_iocbq
*iocb
;
10155 int txcmplq_cnt
= 0;
10156 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
10157 unsigned long iflags
;
10158 bool iocb_completed
= true;
10161 * If the caller has provided a response iocbq buffer, then context2
10162 * is NULL or its an error.
10165 if (piocb
->context2
)
10167 piocb
->context2
= prspiocbq
;
10170 piocb
->wait_iocb_cmpl
= piocb
->iocb_cmpl
;
10171 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
10172 piocb
->context_un
.wait_queue
= &done_q
;
10173 piocb
->iocb_flag
&= ~(LPFC_IO_WAKE
| LPFC_IO_WAKE_TMO
);
10175 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10176 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10178 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
10179 writel(creg_val
, phba
->HCregaddr
);
10180 readl(phba
->HCregaddr
); /* flush */
10183 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
10184 SLI_IOCB_RET_IOCB
);
10185 if (retval
== IOCB_SUCCESS
) {
10186 timeout_req
= msecs_to_jiffies(timeout
* 1000);
10187 timeleft
= wait_event_timeout(done_q
,
10188 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
10190 spin_lock_irqsave(&phba
->hbalock
, iflags
);
10191 if (!(piocb
->iocb_flag
& LPFC_IO_WAKE
)) {
10194 * IOCB timed out. Inform the wake iocb wait
10195 * completion function and set local status
10198 iocb_completed
= false;
10199 piocb
->iocb_flag
|= LPFC_IO_WAKE_TMO
;
10201 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
10202 if (iocb_completed
) {
10203 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10204 "0331 IOCB wake signaled\n");
10205 /* Note: we are not indicating if the IOCB has a success
10206 * status or not - that's for the caller to check.
10207 * IOCB_SUCCESS means just that the command was sent and
10208 * completed. Not that it completed successfully.
10210 } else if (timeleft
== 0) {
10211 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10212 "0338 IOCB wait timeout error - no "
10213 "wake response Data x%x\n", timeout
);
10214 retval
= IOCB_TIMEDOUT
;
10216 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10217 "0330 IOCB wake NOT set, "
10219 timeout
, (timeleft
/ jiffies
));
10220 retval
= IOCB_TIMEDOUT
;
10222 } else if (retval
== IOCB_BUSY
) {
10223 if (phba
->cfg_log_verbose
& LOG_SLI
) {
10224 list_for_each_entry(iocb
, &pring
->txq
, list
) {
10227 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
10230 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10231 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
10232 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
10236 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10237 "0332 IOCB wait issue failed, Data x%x\n",
10239 retval
= IOCB_ERROR
;
10242 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10243 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10245 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
10246 writel(creg_val
, phba
->HCregaddr
);
10247 readl(phba
->HCregaddr
); /* flush */
10251 piocb
->context2
= NULL
;
10253 piocb
->context_un
.wait_queue
= NULL
;
10254 piocb
->iocb_cmpl
= NULL
;
10259 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
10260 * @phba: Pointer to HBA context object.
10261 * @pmboxq: Pointer to driver mailbox object.
10262 * @timeout: Timeout in number of seconds.
10264 * This function issues the mailbox to firmware and waits for the
10265 * mailbox command to complete. If the mailbox command is not
10266 * completed within timeout seconds, it returns MBX_TIMEOUT.
10267 * The function waits for the mailbox completion using an
10268 * interruptible wait. If the thread is woken up due to a
10269 * signal, MBX_TIMEOUT error is returned to the caller. Caller
10270 * should not free the mailbox resources, if this function returns
10272 * This function will sleep while waiting for mailbox completion.
10273 * So, this function should not be called from any context which
10274 * does not allow sleeping. Due to the same reason, this function
10275 * cannot be called with interrupt disabled.
10276 * This function assumes that the mailbox completion occurs while
10277 * this function sleep. So, this function cannot be called from
10278 * the worker thread which processes mailbox completion.
10279 * This function is called in the context of HBA management
10281 * This function returns MBX_SUCCESS when successful.
10282 * This function is called with no lock held.
10285 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
10288 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10289 MAILBOX_t
*mb
= NULL
;
10291 unsigned long flag
;
10293 /* The caller might set context1 for extended buffer */
10294 if (pmboxq
->context1
)
10295 mb
= (MAILBOX_t
*)pmboxq
->context1
;
10297 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
10298 /* setup wake call as IOCB callback */
10299 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
10300 /* setup context field to pass wait_queue pointer to wake function */
10301 pmboxq
->context1
= &done_q
;
10303 /* now issue the command */
10304 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
10305 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
10306 wait_event_interruptible_timeout(done_q
,
10307 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
10308 msecs_to_jiffies(timeout
* 1000));
10310 spin_lock_irqsave(&phba
->hbalock
, flag
);
10311 /* restore the possible extended buffer for free resource */
10312 pmboxq
->context1
= (uint8_t *)mb
;
10314 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10315 * else do not free the resources.
10317 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
10318 retval
= MBX_SUCCESS
;
10320 retval
= MBX_TIMEOUT
;
10321 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10323 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
10325 /* restore the possible extended buffer for free resource */
10326 pmboxq
->context1
= (uint8_t *)mb
;
10333 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10334 * @phba: Pointer to HBA context.
10336 * This function is called to shutdown the driver's mailbox sub-system.
10337 * It first marks the mailbox sub-system is in a block state to prevent
10338 * the asynchronous mailbox command from issued off the pending mailbox
10339 * command queue. If the mailbox command sub-system shutdown is due to
10340 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10341 * the mailbox sub-system flush routine to forcefully bring down the
10342 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10343 * as with offline or HBA function reset), this routine will wait for the
10344 * outstanding mailbox command to complete before invoking the mailbox
10345 * sub-system flush routine to gracefully bring down mailbox sub-system.
10348 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
10350 struct lpfc_sli
*psli
= &phba
->sli
;
10351 unsigned long timeout
;
10353 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
10354 /* delay 100ms for port state */
10356 lpfc_sli_mbox_sys_flush(phba
);
10359 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
10361 spin_lock_irq(&phba
->hbalock
);
10362 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10364 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
10365 /* Determine how long we might wait for the active mailbox
10366 * command to be gracefully completed by firmware.
10368 if (phba
->sli
.mbox_active
)
10369 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
10370 phba
->sli
.mbox_active
) *
10372 spin_unlock_irq(&phba
->hbalock
);
10374 while (phba
->sli
.mbox_active
) {
10375 /* Check active mailbox complete status every 2ms */
10377 if (time_after(jiffies
, timeout
))
10378 /* Timeout, let the mailbox flush routine to
10379 * forcefully release active mailbox command
10384 spin_unlock_irq(&phba
->hbalock
);
10386 lpfc_sli_mbox_sys_flush(phba
);
10390 * lpfc_sli_eratt_read - read sli-3 error attention events
10391 * @phba: Pointer to HBA context.
10393 * This function is called to read the SLI3 device error attention registers
10394 * for possible error attention events. The caller must hold the hostlock
10395 * with spin_lock_irq().
10397 * This function returns 1 when there is Error Attention in the Host Attention
10398 * Register and returns 0 otherwise.
10401 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10405 /* Read chip Host Attention (HA) register */
10406 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10409 if (ha_copy
& HA_ERATT
) {
10410 /* Read host status register to retrieve error event */
10411 if (lpfc_sli_read_hs(phba
))
10414 /* Check if there is a deferred error condition is active */
10415 if ((HS_FFER1
& phba
->work_hs
) &&
10416 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10417 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10418 phba
->hba_flag
|= DEFER_ERATT
;
10419 /* Clear all interrupt enable conditions */
10420 writel(0, phba
->HCregaddr
);
10421 readl(phba
->HCregaddr
);
10424 /* Set the driver HA work bitmap */
10425 phba
->work_ha
|= HA_ERATT
;
10426 /* Indicate polling handles this ERATT */
10427 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10433 /* Set the driver HS work bitmap */
10434 phba
->work_hs
|= UNPLUG_ERR
;
10435 /* Set the driver HA work bitmap */
10436 phba
->work_ha
|= HA_ERATT
;
10437 /* Indicate polling handles this ERATT */
10438 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10443 * lpfc_sli4_eratt_read - read sli-4 error attention events
10444 * @phba: Pointer to HBA context.
10446 * This function is called to read the SLI4 device error attention registers
10447 * for possible error attention events. The caller must hold the hostlock
10448 * with spin_lock_irq().
10450 * This function returns 1 when there is Error Attention in the Host Attention
10451 * Register and returns 0 otherwise.
10454 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10456 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10457 uint32_t if_type
, portsmphr
;
10458 struct lpfc_register portstat_reg
;
10461 * For now, use the SLI4 device internal unrecoverable error
10462 * registers for error attention. This can be changed later.
10464 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10466 case LPFC_SLI_INTF_IF_TYPE_0
:
10467 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10469 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10471 phba
->work_hs
|= UNPLUG_ERR
;
10472 phba
->work_ha
|= HA_ERATT
;
10473 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10476 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10477 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10478 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10479 "1423 HBA Unrecoverable error: "
10480 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10481 "ue_mask_lo_reg=0x%x, "
10482 "ue_mask_hi_reg=0x%x\n",
10483 uerr_sta_lo
, uerr_sta_hi
,
10484 phba
->sli4_hba
.ue_mask_lo
,
10485 phba
->sli4_hba
.ue_mask_hi
);
10486 phba
->work_status
[0] = uerr_sta_lo
;
10487 phba
->work_status
[1] = uerr_sta_hi
;
10488 phba
->work_ha
|= HA_ERATT
;
10489 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10493 case LPFC_SLI_INTF_IF_TYPE_2
:
10494 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10495 &portstat_reg
.word0
) ||
10496 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10498 phba
->work_hs
|= UNPLUG_ERR
;
10499 phba
->work_ha
|= HA_ERATT
;
10500 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10503 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10504 phba
->work_status
[0] =
10505 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10506 phba
->work_status
[1] =
10507 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10508 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10509 "2885 Port Status Event: "
10510 "port status reg 0x%x, "
10511 "port smphr reg 0x%x, "
10512 "error 1=0x%x, error 2=0x%x\n",
10513 portstat_reg
.word0
,
10515 phba
->work_status
[0],
10516 phba
->work_status
[1]);
10517 phba
->work_ha
|= HA_ERATT
;
10518 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10522 case LPFC_SLI_INTF_IF_TYPE_1
:
10524 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10525 "2886 HBA Error Attention on unsupported "
10526 "if type %d.", if_type
);
10534 * lpfc_sli_check_eratt - check error attention events
10535 * @phba: Pointer to HBA context.
10537 * This function is called from timer soft interrupt context to check HBA's
10538 * error attention register bit for error attention events.
10540 * This function returns 1 when there is Error Attention in the Host Attention
10541 * Register and returns 0 otherwise.
10544 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10548 /* If somebody is waiting to handle an eratt, don't process it
10549 * here. The brdkill function will do this.
10551 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10554 /* Check if interrupt handler handles this ERATT */
10555 spin_lock_irq(&phba
->hbalock
);
10556 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10557 /* Interrupt handler has handled ERATT */
10558 spin_unlock_irq(&phba
->hbalock
);
10563 * If there is deferred error attention, do not check for error
10566 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10567 spin_unlock_irq(&phba
->hbalock
);
10571 /* If PCI channel is offline, don't process it */
10572 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10573 spin_unlock_irq(&phba
->hbalock
);
10577 switch (phba
->sli_rev
) {
10578 case LPFC_SLI_REV2
:
10579 case LPFC_SLI_REV3
:
10580 /* Read chip Host Attention (HA) register */
10581 ha_copy
= lpfc_sli_eratt_read(phba
);
10583 case LPFC_SLI_REV4
:
10584 /* Read device Uncoverable Error (UERR) registers */
10585 ha_copy
= lpfc_sli4_eratt_read(phba
);
10588 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10589 "0299 Invalid SLI revision (%d)\n",
10594 spin_unlock_irq(&phba
->hbalock
);
10600 * lpfc_intr_state_check - Check device state for interrupt handling
10601 * @phba: Pointer to HBA context.
10603 * This inline routine checks whether a device or its PCI slot is in a state
10604 * that the interrupt should be handled.
10606 * This function returns 0 if the device or the PCI slot is in a state that
10607 * interrupt should be handled, otherwise -EIO.
10610 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10612 /* If the pci channel is offline, ignore all the interrupts */
10613 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10616 /* Update device level interrupt statistics */
10617 phba
->sli
.slistat
.sli_intr
++;
10619 /* Ignore all interrupts during initialization. */
10620 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10627 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10628 * @irq: Interrupt number.
10629 * @dev_id: The device context pointer.
10631 * This function is directly called from the PCI layer as an interrupt
10632 * service routine when device with SLI-3 interface spec is enabled with
10633 * MSI-X multi-message interrupt mode and there are slow-path events in
10634 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10635 * interrupt mode, this function is called as part of the device-level
10636 * interrupt handler. When the PCI slot is in error recovery or the HBA
10637 * is undergoing initialization, the interrupt handler will not process
10638 * the interrupt. The link attention and ELS ring attention events are
10639 * handled by the worker thread. The interrupt handler signals the worker
10640 * thread and returns for these events. This function is called without
10641 * any lock held. It gets the hbalock to access and update SLI data
10644 * This function returns IRQ_HANDLED when interrupt is handled else it
10645 * returns IRQ_NONE.
10648 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10650 struct lpfc_hba
*phba
;
10651 uint32_t ha_copy
, hc_copy
;
10652 uint32_t work_ha_copy
;
10653 unsigned long status
;
10654 unsigned long iflag
;
10657 MAILBOX_t
*mbox
, *pmbox
;
10658 struct lpfc_vport
*vport
;
10659 struct lpfc_nodelist
*ndlp
;
10660 struct lpfc_dmabuf
*mp
;
10665 * Get the driver's phba structure from the dev_id and
10666 * assume the HBA is not interrupting.
10668 phba
= (struct lpfc_hba
*)dev_id
;
10670 if (unlikely(!phba
))
10674 * Stuff needs to be attented to when this function is invoked as an
10675 * individual interrupt handler in MSI-X multi-message interrupt mode
10677 if (phba
->intr_type
== MSIX
) {
10678 /* Check device state for handling interrupt */
10679 if (lpfc_intr_state_check(phba
))
10681 /* Need to read HA REG for slow-path events */
10682 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10683 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10685 /* If somebody is waiting to handle an eratt don't process it
10686 * here. The brdkill function will do this.
10688 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10689 ha_copy
&= ~HA_ERATT
;
10690 /* Check the need for handling ERATT in interrupt handler */
10691 if (ha_copy
& HA_ERATT
) {
10692 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10693 /* ERATT polling has handled ERATT */
10694 ha_copy
&= ~HA_ERATT
;
10696 /* Indicate interrupt handler handles ERATT */
10697 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10701 * If there is deferred error attention, do not check for any
10704 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10705 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10709 /* Clear up only attention source related to slow-path */
10710 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10713 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10714 HC_LAINT_ENA
| HC_ERINT_ENA
),
10716 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10718 writel(hc_copy
, phba
->HCregaddr
);
10719 readl(phba
->HAregaddr
); /* flush */
10720 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10722 ha_copy
= phba
->ha_copy
;
10724 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10726 if (work_ha_copy
) {
10727 if (work_ha_copy
& HA_LATT
) {
10728 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10730 * Turn off Link Attention interrupts
10731 * until CLEAR_LA done
10733 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10734 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10735 if (lpfc_readl(phba
->HCregaddr
, &control
))
10737 control
&= ~HC_LAINT_ENA
;
10738 writel(control
, phba
->HCregaddr
);
10739 readl(phba
->HCregaddr
); /* flush */
10740 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10743 work_ha_copy
&= ~HA_LATT
;
10746 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10748 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10749 * the only slow ring.
10751 status
= (work_ha_copy
&
10752 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10753 status
>>= (4*LPFC_ELS_RING
);
10754 if (status
& HA_RXMASK
) {
10755 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10756 if (lpfc_readl(phba
->HCregaddr
, &control
))
10759 lpfc_debugfs_slow_ring_trc(phba
,
10760 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10762 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10764 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10765 lpfc_debugfs_slow_ring_trc(phba
,
10766 "ISR Disable ring:"
10767 "pwork:x%x hawork:x%x wait:x%x",
10768 phba
->work_ha
, work_ha_copy
,
10769 (uint32_t)((unsigned long)
10770 &phba
->work_waitq
));
10773 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10774 writel(control
, phba
->HCregaddr
);
10775 readl(phba
->HCregaddr
); /* flush */
10778 lpfc_debugfs_slow_ring_trc(phba
,
10779 "ISR slow ring: pwork:"
10780 "x%x hawork:x%x wait:x%x",
10781 phba
->work_ha
, work_ha_copy
,
10782 (uint32_t)((unsigned long)
10783 &phba
->work_waitq
));
10785 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10788 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10789 if (work_ha_copy
& HA_ERATT
) {
10790 if (lpfc_sli_read_hs(phba
))
10793 * Check if there is a deferred error condition
10796 if ((HS_FFER1
& phba
->work_hs
) &&
10797 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10798 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10800 phba
->hba_flag
|= DEFER_ERATT
;
10801 /* Clear all interrupt enable conditions */
10802 writel(0, phba
->HCregaddr
);
10803 readl(phba
->HCregaddr
);
10807 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10808 pmb
= phba
->sli
.mbox_active
;
10809 pmbox
= &pmb
->u
.mb
;
10811 vport
= pmb
->vport
;
10813 /* First check out the status word */
10814 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10815 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10816 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10818 * Stray Mailbox Interrupt, mbxCommand <cmd>
10819 * mbxStatus <status>
10821 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10823 "(%d):0304 Stray Mailbox "
10824 "Interrupt mbxCommand x%x "
10826 (vport
? vport
->vpi
: 0),
10829 /* clear mailbox attention bit */
10830 work_ha_copy
&= ~HA_MBATT
;
10832 phba
->sli
.mbox_active
= NULL
;
10833 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10834 phba
->last_completion_time
= jiffies
;
10835 del_timer(&phba
->sli
.mbox_tmo
);
10836 if (pmb
->mbox_cmpl
) {
10837 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10839 if (pmb
->out_ext_byte_len
&&
10841 lpfc_sli_pcimem_bcopy(
10844 pmb
->out_ext_byte_len
);
10846 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10847 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10849 lpfc_debugfs_disc_trc(vport
,
10850 LPFC_DISC_TRC_MBOX_VPORT
,
10851 "MBOX dflt rpi: : "
10852 "status:x%x rpi:x%x",
10853 (uint32_t)pmbox
->mbxStatus
,
10854 pmbox
->un
.varWords
[0], 0);
10856 if (!pmbox
->mbxStatus
) {
10857 mp
= (struct lpfc_dmabuf
*)
10859 ndlp
= (struct lpfc_nodelist
*)
10862 /* Reg_LOGIN of dflt RPI was
10863 * successful. new lets get
10864 * rid of the RPI using the
10865 * same mbox buffer.
10867 lpfc_unreg_login(phba
,
10869 pmbox
->un
.varWords
[0],
10872 lpfc_mbx_cmpl_dflt_rpi
;
10873 pmb
->context1
= mp
;
10874 pmb
->context2
= ndlp
;
10875 pmb
->vport
= vport
;
10876 rc
= lpfc_sli_issue_mbox(phba
,
10879 if (rc
!= MBX_BUSY
)
10880 lpfc_printf_log(phba
,
10882 LOG_MBOX
| LOG_SLI
,
10883 "0350 rc should have"
10884 "been MBX_BUSY\n");
10885 if (rc
!= MBX_NOT_FINISHED
)
10886 goto send_current_mbox
;
10890 &phba
->pport
->work_port_lock
,
10892 phba
->pport
->work_port_events
&=
10894 spin_unlock_irqrestore(
10895 &phba
->pport
->work_port_lock
,
10897 lpfc_mbox_cmpl_put(phba
, pmb
);
10900 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10902 if ((work_ha_copy
& HA_MBATT
) &&
10903 (phba
->sli
.mbox_active
== NULL
)) {
10905 /* Process next mailbox command if there is one */
10907 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10909 } while (rc
== MBX_NOT_FINISHED
);
10910 if (rc
!= MBX_SUCCESS
)
10911 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10912 LOG_SLI
, "0349 rc should be "
10916 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10917 phba
->work_ha
|= work_ha_copy
;
10918 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10919 lpfc_worker_wake_up(phba
);
10921 return IRQ_HANDLED
;
10923 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10924 return IRQ_HANDLED
;
10926 } /* lpfc_sli_sp_intr_handler */
10929 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10930 * @irq: Interrupt number.
10931 * @dev_id: The device context pointer.
10933 * This function is directly called from the PCI layer as an interrupt
10934 * service routine when device with SLI-3 interface spec is enabled with
10935 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10936 * ring event in the HBA. However, when the device is enabled with either
10937 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10938 * device-level interrupt handler. When the PCI slot is in error recovery
10939 * or the HBA is undergoing initialization, the interrupt handler will not
10940 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10941 * the intrrupt context. This function is called without any lock held.
10942 * It gets the hbalock to access and update SLI data structures.
10944 * This function returns IRQ_HANDLED when interrupt is handled else it
10945 * returns IRQ_NONE.
10948 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10950 struct lpfc_hba
*phba
;
10952 unsigned long status
;
10953 unsigned long iflag
;
10955 /* Get the driver's phba structure from the dev_id and
10956 * assume the HBA is not interrupting.
10958 phba
= (struct lpfc_hba
*) dev_id
;
10960 if (unlikely(!phba
))
10964 * Stuff needs to be attented to when this function is invoked as an
10965 * individual interrupt handler in MSI-X multi-message interrupt mode
10967 if (phba
->intr_type
== MSIX
) {
10968 /* Check device state for handling interrupt */
10969 if (lpfc_intr_state_check(phba
))
10971 /* Need to read HA REG for FCP ring and other ring events */
10972 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10973 return IRQ_HANDLED
;
10974 /* Clear up only attention source related to fast-path */
10975 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10977 * If there is deferred error attention, do not check for
10980 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10981 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10984 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10986 readl(phba
->HAregaddr
); /* flush */
10987 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10989 ha_copy
= phba
->ha_copy
;
10992 * Process all events on FCP ring. Take the optimized path for FCP IO.
10994 ha_copy
&= ~(phba
->work_ha_mask
);
10996 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10997 status
>>= (4*LPFC_FCP_RING
);
10998 if (status
& HA_RXMASK
)
10999 lpfc_sli_handle_fast_ring_event(phba
,
11000 &phba
->sli
.ring
[LPFC_FCP_RING
],
11003 if (phba
->cfg_multi_ring_support
== 2) {
11005 * Process all events on extra ring. Take the optimized path
11006 * for extra ring IO.
11008 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
11009 status
>>= (4*LPFC_EXTRA_RING
);
11010 if (status
& HA_RXMASK
) {
11011 lpfc_sli_handle_fast_ring_event(phba
,
11012 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
11016 return IRQ_HANDLED
;
11017 } /* lpfc_sli_fp_intr_handler */
11020 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
11021 * @irq: Interrupt number.
11022 * @dev_id: The device context pointer.
11024 * This function is the HBA device-level interrupt handler to device with
11025 * SLI-3 interface spec, called from the PCI layer when either MSI or
11026 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
11027 * requires driver attention. This function invokes the slow-path interrupt
11028 * attention handling function and fast-path interrupt attention handling
11029 * function in turn to process the relevant HBA attention events. This
11030 * function is called without any lock held. It gets the hbalock to access
11031 * and update SLI data structures.
11033 * This function returns IRQ_HANDLED when interrupt is handled, else it
11034 * returns IRQ_NONE.
11037 lpfc_sli_intr_handler(int irq
, void *dev_id
)
11039 struct lpfc_hba
*phba
;
11040 irqreturn_t sp_irq_rc
, fp_irq_rc
;
11041 unsigned long status1
, status2
;
11045 * Get the driver's phba structure from the dev_id and
11046 * assume the HBA is not interrupting.
11048 phba
= (struct lpfc_hba
*) dev_id
;
11050 if (unlikely(!phba
))
11053 /* Check device state for handling interrupt */
11054 if (lpfc_intr_state_check(phba
))
11057 spin_lock(&phba
->hbalock
);
11058 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
11059 spin_unlock(&phba
->hbalock
);
11060 return IRQ_HANDLED
;
11063 if (unlikely(!phba
->ha_copy
)) {
11064 spin_unlock(&phba
->hbalock
);
11066 } else if (phba
->ha_copy
& HA_ERATT
) {
11067 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
11068 /* ERATT polling has handled ERATT */
11069 phba
->ha_copy
&= ~HA_ERATT
;
11071 /* Indicate interrupt handler handles ERATT */
11072 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
11076 * If there is deferred error attention, do not check for any interrupt.
11078 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
11079 spin_unlock(&phba
->hbalock
);
11083 /* Clear attention sources except link and error attentions */
11084 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
11085 spin_unlock(&phba
->hbalock
);
11086 return IRQ_HANDLED
;
11088 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
11089 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
11091 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
11092 writel(hc_copy
, phba
->HCregaddr
);
11093 readl(phba
->HAregaddr
); /* flush */
11094 spin_unlock(&phba
->hbalock
);
11097 * Invokes slow-path host attention interrupt handling as appropriate.
11100 /* status of events with mailbox and link attention */
11101 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
11103 /* status of events with ELS ring */
11104 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
11105 status2
>>= (4*LPFC_ELS_RING
);
11107 if (status1
|| (status2
& HA_RXMASK
))
11108 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
11110 sp_irq_rc
= IRQ_NONE
;
11113 * Invoke fast-path host attention interrupt handling as appropriate.
11116 /* status of events with FCP ring */
11117 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
11118 status1
>>= (4*LPFC_FCP_RING
);
11120 /* status of events with extra ring */
11121 if (phba
->cfg_multi_ring_support
== 2) {
11122 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
11123 status2
>>= (4*LPFC_EXTRA_RING
);
11127 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
11128 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
11130 fp_irq_rc
= IRQ_NONE
;
11132 /* Return device-level interrupt handling status */
11133 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
11134 } /* lpfc_sli_intr_handler */
11137 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
11138 * @phba: pointer to lpfc hba data structure.
11140 * This routine is invoked by the worker thread to process all the pending
11141 * SLI4 FCP abort XRI events.
11143 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
11145 struct lpfc_cq_event
*cq_event
;
11147 /* First, declare the fcp xri abort event has been handled */
11148 spin_lock_irq(&phba
->hbalock
);
11149 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
11150 spin_unlock_irq(&phba
->hbalock
);
11151 /* Now, handle all the fcp xri abort events */
11152 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
11153 /* Get the first event from the head of the event queue */
11154 spin_lock_irq(&phba
->hbalock
);
11155 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
11156 cq_event
, struct lpfc_cq_event
, list
);
11157 spin_unlock_irq(&phba
->hbalock
);
11158 /* Notify aborted XRI for FCP work queue */
11159 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
11160 /* Free the event processed back to the free pool */
11161 lpfc_sli4_cq_event_release(phba
, cq_event
);
11166 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
11167 * @phba: pointer to lpfc hba data structure.
11169 * This routine is invoked by the worker thread to process all the pending
11170 * SLI4 els abort xri events.
11172 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
11174 struct lpfc_cq_event
*cq_event
;
11176 /* First, declare the els xri abort event has been handled */
11177 spin_lock_irq(&phba
->hbalock
);
11178 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
11179 spin_unlock_irq(&phba
->hbalock
);
11180 /* Now, handle all the els xri abort events */
11181 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
11182 /* Get the first event from the head of the event queue */
11183 spin_lock_irq(&phba
->hbalock
);
11184 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
11185 cq_event
, struct lpfc_cq_event
, list
);
11186 spin_unlock_irq(&phba
->hbalock
);
11187 /* Notify aborted XRI for ELS work queue */
11188 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
11189 /* Free the event processed back to the free pool */
11190 lpfc_sli4_cq_event_release(phba
, cq_event
);
11195 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
11196 * @phba: pointer to lpfc hba data structure
11197 * @pIocbIn: pointer to the rspiocbq
11198 * @pIocbOut: pointer to the cmdiocbq
11199 * @wcqe: pointer to the complete wcqe
11201 * This routine transfers the fields of a command iocbq to a response iocbq
11202 * by copying all the IOCB fields from command iocbq and transferring the
11203 * completion status information from the complete wcqe.
11206 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
11207 struct lpfc_iocbq
*pIocbIn
,
11208 struct lpfc_iocbq
*pIocbOut
,
11209 struct lpfc_wcqe_complete
*wcqe
)
11212 unsigned long iflags
;
11213 uint32_t status
, max_response
;
11214 struct lpfc_dmabuf
*dmabuf
;
11215 struct ulp_bde64
*bpl
, bde
;
11216 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
11218 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
11219 sizeof(struct lpfc_iocbq
) - offset
);
11220 /* Map WCQE parameters into irspiocb parameters */
11221 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
11222 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
11223 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
11224 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
11225 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
11226 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
11227 wcqe
->total_data_placed
;
11229 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11231 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11232 switch (pIocbOut
->iocb
.ulpCommand
) {
11233 case CMD_ELS_REQUEST64_CR
:
11234 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
11235 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
11236 bde
.tus
.w
= le32_to_cpu(bpl
[1].tus
.w
);
11237 max_response
= bde
.tus
.f
.bdeSize
;
11239 case CMD_GEN_REQUEST64_CR
:
11241 if (!pIocbOut
->context3
)
11243 numBdes
= pIocbOut
->iocb
.un
.genreq64
.bdl
.bdeSize
/
11244 sizeof(struct ulp_bde64
);
11245 dmabuf
= (struct lpfc_dmabuf
*)pIocbOut
->context3
;
11246 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
11247 for (i
= 0; i
< numBdes
; i
++) {
11248 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
11249 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
11250 max_response
+= bde
.tus
.f
.bdeSize
;
11254 max_response
= wcqe
->total_data_placed
;
11257 if (max_response
< wcqe
->total_data_placed
)
11258 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= max_response
;
11260 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
=
11261 wcqe
->total_data_placed
;
11264 /* Convert BG errors for completion status */
11265 if (status
== CQE_STATUS_DI_ERROR
) {
11266 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
11268 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
11269 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
11271 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
11273 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
11274 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
11275 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11276 BGS_GUARD_ERR_MASK
;
11277 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
11278 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11279 BGS_APPTAG_ERR_MASK
;
11280 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
11281 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11282 BGS_REFTAG_ERR_MASK
;
11284 /* Check to see if there was any good data before the error */
11285 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
11286 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11287 BGS_HI_WATER_MARK_PRESENT_MASK
;
11288 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
11289 wcqe
->total_data_placed
;
11293 * Set ALL the error bits to indicate we don't know what
11294 * type of error it is.
11296 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
11297 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11298 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
11299 BGS_GUARD_ERR_MASK
);
11302 /* Pick up HBA exchange busy condition */
11303 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
11304 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11305 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
11306 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11311 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11312 * @phba: Pointer to HBA context object.
11313 * @wcqe: Pointer to work-queue completion queue entry.
11315 * This routine handles an ELS work-queue completion event and construct
11316 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11317 * discovery engine to handle.
11319 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11321 static struct lpfc_iocbq
*
11322 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
11323 struct lpfc_iocbq
*irspiocbq
)
11325 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
11326 struct lpfc_iocbq
*cmdiocbq
;
11327 struct lpfc_wcqe_complete
*wcqe
;
11328 unsigned long iflags
;
11330 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
11331 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11332 pring
->stats
.iocb_event
++;
11333 /* Look up the ELS command IOCB and create pseudo response IOCB */
11334 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11335 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11336 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11338 if (unlikely(!cmdiocbq
)) {
11339 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11340 "0386 ELS complete with no corresponding "
11341 "cmdiocb: iotag (%d)\n",
11342 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11343 lpfc_sli_release_iocbq(phba
, irspiocbq
);
11347 /* Fake the irspiocbq and copy necessary response information */
11348 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
11354 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11355 * @phba: Pointer to HBA context object.
11356 * @cqe: Pointer to mailbox completion queue entry.
11358 * This routine process a mailbox completion queue entry with asynchrous
11361 * Return: true if work posted to worker thread, otherwise false.
11364 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11366 struct lpfc_cq_event
*cq_event
;
11367 unsigned long iflags
;
11369 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11370 "0392 Async Event: word0:x%x, word1:x%x, "
11371 "word2:x%x, word3:x%x\n", mcqe
->word0
,
11372 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
11374 /* Allocate a new internal CQ_EVENT entry */
11375 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11377 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11378 "0394 Failed to allocate CQ_EVENT entry\n");
11382 /* Move the CQE into an asynchronous event entry */
11383 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
11384 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11385 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
11386 /* Set the async event flag */
11387 phba
->hba_flag
|= ASYNC_EVENT
;
11388 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11394 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11395 * @phba: Pointer to HBA context object.
11396 * @cqe: Pointer to mailbox completion queue entry.
11398 * This routine process a mailbox completion queue entry with mailbox
11399 * completion event.
11401 * Return: true if work posted to worker thread, otherwise false.
11404 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11406 uint32_t mcqe_status
;
11407 MAILBOX_t
*mbox
, *pmbox
;
11408 struct lpfc_mqe
*mqe
;
11409 struct lpfc_vport
*vport
;
11410 struct lpfc_nodelist
*ndlp
;
11411 struct lpfc_dmabuf
*mp
;
11412 unsigned long iflags
;
11414 bool workposted
= false;
11417 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11418 if (!bf_get(lpfc_trailer_completed
, mcqe
))
11419 goto out_no_mqe_complete
;
11421 /* Get the reference to the active mbox command */
11422 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11423 pmb
= phba
->sli
.mbox_active
;
11424 if (unlikely(!pmb
)) {
11425 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11426 "1832 No pending MBOX command to handle\n");
11427 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11428 goto out_no_mqe_complete
;
11430 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11432 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11434 vport
= pmb
->vport
;
11436 /* Reset heartbeat timer */
11437 phba
->last_completion_time
= jiffies
;
11438 del_timer(&phba
->sli
.mbox_tmo
);
11440 /* Move mbox data to caller's mailbox region, do endian swapping */
11441 if (pmb
->mbox_cmpl
&& mbox
)
11442 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11445 * For mcqe errors, conditionally move a modified error code to
11446 * the mbox so that the error will not be missed.
11448 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11449 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11450 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11451 bf_set(lpfc_mqe_status
, mqe
,
11452 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11454 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11455 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11456 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11457 "MBOX dflt rpi: status:x%x rpi:x%x",
11459 pmbox
->un
.varWords
[0], 0);
11460 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11461 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11462 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11463 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11464 * RID of the PPI using the same mbox buffer.
11466 lpfc_unreg_login(phba
, vport
->vpi
,
11467 pmbox
->un
.varWords
[0], pmb
);
11468 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11469 pmb
->context1
= mp
;
11470 pmb
->context2
= ndlp
;
11471 pmb
->vport
= vport
;
11472 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11473 if (rc
!= MBX_BUSY
)
11474 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11475 LOG_SLI
, "0385 rc should "
11476 "have been MBX_BUSY\n");
11477 if (rc
!= MBX_NOT_FINISHED
)
11478 goto send_current_mbox
;
11481 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11482 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11483 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11485 /* There is mailbox completion work to do */
11486 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11487 __lpfc_mbox_cmpl_put(phba
, pmb
);
11488 phba
->work_ha
|= HA_MBATT
;
11489 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11493 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11494 /* Release the mailbox command posting token */
11495 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11496 /* Setting active mailbox pointer need to be in sync to flag clear */
11497 phba
->sli
.mbox_active
= NULL
;
11498 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11499 /* Wake up worker thread to post the next pending mailbox command */
11500 lpfc_worker_wake_up(phba
);
11501 out_no_mqe_complete
:
11502 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11503 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
11508 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11509 * @phba: Pointer to HBA context object.
11510 * @cqe: Pointer to mailbox completion queue entry.
11512 * This routine process a mailbox completion queue entry, it invokes the
11513 * proper mailbox complete handling or asynchrous event handling routine
11514 * according to the MCQE's async bit.
11516 * Return: true if work posted to worker thread, otherwise false.
11519 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
11521 struct lpfc_mcqe mcqe
;
11524 /* Copy the mailbox MCQE and convert endian order as needed */
11525 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
11527 /* Invoke the proper event handling routine */
11528 if (!bf_get(lpfc_trailer_async
, &mcqe
))
11529 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
11531 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
11536 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11537 * @phba: Pointer to HBA context object.
11538 * @cq: Pointer to associated CQ
11539 * @wcqe: Pointer to work-queue completion queue entry.
11541 * This routine handles an ELS work-queue completion event.
11543 * Return: true if work posted to worker thread, otherwise false.
11546 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11547 struct lpfc_wcqe_complete
*wcqe
)
11549 struct lpfc_iocbq
*irspiocbq
;
11550 unsigned long iflags
;
11551 struct lpfc_sli_ring
*pring
= cq
->pring
;
11553 int txcmplq_cnt
= 0;
11554 int fcp_txcmplq_cnt
= 0;
11556 /* Get an irspiocbq for later ELS response processing use */
11557 irspiocbq
= lpfc_sli_get_iocbq(phba
);
11559 if (!list_empty(&pring
->txq
))
11561 if (!list_empty(&pring
->txcmplq
))
11563 if (!list_empty(&phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq
))
11565 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11566 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11567 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
11568 txq_cnt
, phba
->iocb_cnt
,
11574 /* Save off the slow-path queue event for work thread to process */
11575 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
11576 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11577 list_add_tail(&irspiocbq
->cq_event
.list
,
11578 &phba
->sli4_hba
.sp_queue_event
);
11579 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11580 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11586 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11587 * @phba: Pointer to HBA context object.
11588 * @wcqe: Pointer to work-queue completion queue entry.
11590 * This routine handles slow-path WQ entry comsumed event by invoking the
11591 * proper WQ release routine to the slow-path WQ.
11594 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
11595 struct lpfc_wcqe_release
*wcqe
)
11597 /* sanity check on queue memory */
11598 if (unlikely(!phba
->sli4_hba
.els_wq
))
11600 /* Check for the slow-path ELS work queue */
11601 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
11602 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
11603 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11605 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11606 "2579 Slow-path wqe consume event carries "
11607 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11608 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
11609 phba
->sli4_hba
.els_wq
->queue_id
);
11613 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11614 * @phba: Pointer to HBA context object.
11615 * @cq: Pointer to a WQ completion queue.
11616 * @wcqe: Pointer to work-queue completion queue entry.
11618 * This routine handles an XRI abort event.
11620 * Return: true if work posted to worker thread, otherwise false.
11623 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
11624 struct lpfc_queue
*cq
,
11625 struct sli4_wcqe_xri_aborted
*wcqe
)
11627 bool workposted
= false;
11628 struct lpfc_cq_event
*cq_event
;
11629 unsigned long iflags
;
11631 /* Allocate a new internal CQ_EVENT entry */
11632 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11634 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11635 "0602 Failed to allocate CQ_EVENT entry\n");
11639 /* Move the CQE into the proper xri abort event list */
11640 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11641 switch (cq
->subtype
) {
11643 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11644 list_add_tail(&cq_event
->list
,
11645 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11646 /* Set the fcp xri abort event flag */
11647 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11648 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11652 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11653 list_add_tail(&cq_event
->list
,
11654 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11655 /* Set the els xri abort event flag */
11656 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11657 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11661 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11662 "0603 Invalid work queue CQE subtype (x%x)\n",
11664 workposted
= false;
11671 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11672 * @phba: Pointer to HBA context object.
11673 * @rcqe: Pointer to receive-queue completion queue entry.
11675 * This routine process a receive-queue completion queue entry.
11677 * Return: true if work posted to worker thread, otherwise false.
11680 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11682 bool workposted
= false;
11683 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11684 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11685 struct hbq_dmabuf
*dma_buf
;
11686 uint32_t status
, rq_id
;
11687 unsigned long iflags
;
11689 /* sanity check on queue memory */
11690 if (unlikely(!hrq
) || unlikely(!drq
))
11693 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11694 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11696 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11697 if (rq_id
!= hrq
->queue_id
)
11700 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11702 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11703 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11704 "2537 Receive Frame Truncated!!\n");
11705 hrq
->RQ_buf_trunc
++;
11706 case FC_STATUS_RQ_SUCCESS
:
11707 lpfc_sli4_rq_release(hrq
, drq
);
11708 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11709 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11711 hrq
->RQ_no_buf_found
++;
11712 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11716 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11717 /* save off the frame for the word thread to process */
11718 list_add_tail(&dma_buf
->cq_event
.list
,
11719 &phba
->sli4_hba
.sp_queue_event
);
11720 /* Frame received */
11721 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11722 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11725 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11726 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11727 hrq
->RQ_no_posted_buf
++;
11728 /* Post more buffers if possible */
11729 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11730 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11731 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11740 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11741 * @phba: Pointer to HBA context object.
11742 * @cq: Pointer to the completion queue.
11743 * @wcqe: Pointer to a completion queue entry.
11745 * This routine process a slow-path work-queue or receive queue completion queue
11748 * Return: true if work posted to worker thread, otherwise false.
11751 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11752 struct lpfc_cqe
*cqe
)
11754 struct lpfc_cqe cqevt
;
11755 bool workposted
= false;
11757 /* Copy the work queue CQE and convert endian order if needed */
11758 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11760 /* Check and process for different type of WCQE and dispatch */
11761 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11762 case CQE_CODE_COMPL_WQE
:
11763 /* Process the WQ/RQ complete event */
11764 phba
->last_completion_time
= jiffies
;
11765 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
11766 (struct lpfc_wcqe_complete
*)&cqevt
);
11768 case CQE_CODE_RELEASE_WQE
:
11769 /* Process the WQ release event */
11770 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11771 (struct lpfc_wcqe_release
*)&cqevt
);
11773 case CQE_CODE_XRI_ABORTED
:
11774 /* Process the WQ XRI abort event */
11775 phba
->last_completion_time
= jiffies
;
11776 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11777 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11779 case CQE_CODE_RECEIVE
:
11780 case CQE_CODE_RECEIVE_V1
:
11781 /* Process the RQ event */
11782 phba
->last_completion_time
= jiffies
;
11783 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11784 (struct lpfc_rcqe
*)&cqevt
);
11787 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11788 "0388 Not a valid WCQE code: x%x\n",
11789 bf_get(lpfc_cqe_code
, &cqevt
));
11796 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11797 * @phba: Pointer to HBA context object.
11798 * @eqe: Pointer to fast-path event queue entry.
11800 * This routine process a event queue entry from the slow-path event queue.
11801 * It will check the MajorCode and MinorCode to determine this is for a
11802 * completion event on a completion queue, if not, an error shall be logged
11803 * and just return. Otherwise, it will get to the corresponding completion
11804 * queue and process all the entries on that completion queue, rearm the
11805 * completion queue, and then return.
11809 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11810 struct lpfc_queue
*speq
)
11812 struct lpfc_queue
*cq
= NULL
, *childq
;
11813 struct lpfc_cqe
*cqe
;
11814 bool workposted
= false;
11818 /* Get the reference to the corresponding CQ */
11819 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11821 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11822 if (childq
->queue_id
== cqid
) {
11827 if (unlikely(!cq
)) {
11828 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11829 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11830 "0365 Slow-path CQ identifier "
11831 "(%d) does not exist\n", cqid
);
11835 /* Process all the entries to the CQ */
11836 switch (cq
->type
) {
11838 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11839 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11840 if (!(++ecount
% cq
->entry_repost
))
11841 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11846 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11847 if (cq
->subtype
== LPFC_FCP
)
11848 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11851 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11853 if (!(++ecount
% cq
->entry_repost
))
11854 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11857 /* Track the max number of CQEs processed in 1 EQ */
11858 if (ecount
> cq
->CQ_max_cqe
)
11859 cq
->CQ_max_cqe
= ecount
;
11862 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11863 "0370 Invalid completion queue type (%d)\n",
11868 /* Catch the no cq entry condition, log an error */
11869 if (unlikely(ecount
== 0))
11870 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11871 "0371 No entry from the CQ: identifier "
11872 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11874 /* In any case, flash and re-arm the RCQ */
11875 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11877 /* wake up worker thread if there are works to be done */
11879 lpfc_worker_wake_up(phba
);
11883 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11884 * @phba: Pointer to HBA context object.
11885 * @cq: Pointer to associated CQ
11886 * @wcqe: Pointer to work-queue completion queue entry.
11888 * This routine process a fast-path work queue completion entry from fast-path
11889 * event queue for FCP command response completion.
11892 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11893 struct lpfc_wcqe_complete
*wcqe
)
11895 struct lpfc_sli_ring
*pring
= cq
->pring
;
11896 struct lpfc_iocbq
*cmdiocbq
;
11897 struct lpfc_iocbq irspiocbq
;
11898 unsigned long iflags
;
11900 /* Check for response status */
11901 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11902 /* If resource errors reported from HBA, reduce queue
11903 * depth of the SCSI device.
11905 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11906 IOSTAT_LOCAL_REJECT
)) &&
11907 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
11908 IOERR_NO_RESOURCES
))
11909 phba
->lpfc_rampdown_queue_depth(phba
);
11911 /* Log the error status */
11912 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11913 "0373 FCP complete error: status=x%x, "
11914 "hw_status=x%x, total_data_specified=%d, "
11915 "parameter=x%x, word3=x%x\n",
11916 bf_get(lpfc_wcqe_c_status
, wcqe
),
11917 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11918 wcqe
->total_data_placed
, wcqe
->parameter
,
11922 /* Look up the FCP command IOCB and create pseudo response IOCB */
11923 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11924 pring
->stats
.iocb_event
++;
11925 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11926 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11927 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11928 if (unlikely(!cmdiocbq
)) {
11929 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11930 "0374 FCP complete with no corresponding "
11931 "cmdiocb: iotag (%d)\n",
11932 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11935 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11936 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11937 "0375 FCP cmdiocb not callback function "
11939 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11943 /* Fake the irspiocb and copy necessary response information */
11944 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11946 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11947 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11948 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11949 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11952 /* Pass the cmd_iocb and the rsp state to the upper layer */
11953 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11957 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11958 * @phba: Pointer to HBA context object.
11959 * @cq: Pointer to completion queue.
11960 * @wcqe: Pointer to work-queue completion queue entry.
11962 * This routine handles an fast-path WQ entry comsumed event by invoking the
11963 * proper WQ release routine to the slow-path WQ.
11966 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11967 struct lpfc_wcqe_release
*wcqe
)
11969 struct lpfc_queue
*childwq
;
11970 bool wqid_matched
= false;
11973 /* Check for fast-path FCP work queue release */
11974 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11975 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11976 if (childwq
->queue_id
== fcp_wqid
) {
11977 lpfc_sli4_wq_release(childwq
,
11978 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11979 wqid_matched
= true;
11983 /* Report warning log message if no match found */
11984 if (wqid_matched
!= true)
11985 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11986 "2580 Fast-path wqe consume event carries "
11987 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11991 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11992 * @cq: Pointer to the completion queue.
11993 * @eqe: Pointer to fast-path completion queue entry.
11995 * This routine process a fast-path work queue completion entry from fast-path
11996 * event queue for FCP command response completion.
11999 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12000 struct lpfc_cqe
*cqe
)
12002 struct lpfc_wcqe_release wcqe
;
12003 bool workposted
= false;
12005 /* Copy the work queue CQE and convert endian order if needed */
12006 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
12008 /* Check and process for different type of WCQE and dispatch */
12009 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
12010 case CQE_CODE_COMPL_WQE
:
12012 /* Process the WQ complete event */
12013 phba
->last_completion_time
= jiffies
;
12014 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
12015 (struct lpfc_wcqe_complete
*)&wcqe
);
12017 case CQE_CODE_RELEASE_WQE
:
12018 cq
->CQ_release_wqe
++;
12019 /* Process the WQ release event */
12020 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
12021 (struct lpfc_wcqe_release
*)&wcqe
);
12023 case CQE_CODE_XRI_ABORTED
:
12024 cq
->CQ_xri_aborted
++;
12025 /* Process the WQ XRI abort event */
12026 phba
->last_completion_time
= jiffies
;
12027 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
12028 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
12031 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12032 "0144 Not a valid WCQE code: x%x\n",
12033 bf_get(lpfc_wcqe_c_code
, &wcqe
));
12040 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
12041 * @phba: Pointer to HBA context object.
12042 * @eqe: Pointer to fast-path event queue entry.
12044 * This routine process a event queue entry from the fast-path event queue.
12045 * It will check the MajorCode and MinorCode to determine this is for a
12046 * completion event on a completion queue, if not, an error shall be logged
12047 * and just return. Otherwise, it will get to the corresponding completion
12048 * queue and process all the entries on the completion queue, rearm the
12049 * completion queue, and then return.
12052 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
12055 struct lpfc_queue
*cq
;
12056 struct lpfc_cqe
*cqe
;
12057 bool workposted
= false;
12061 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
12062 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12063 "0366 Not a valid completion "
12064 "event: majorcode=x%x, minorcode=x%x\n",
12065 bf_get_le32(lpfc_eqe_major_code
, eqe
),
12066 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
12070 /* Get the reference to the corresponding CQ */
12071 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
12073 /* Check if this is a Slow path event */
12074 if (unlikely(cqid
!= phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
12075 lpfc_sli4_sp_handle_eqe(phba
, eqe
,
12076 phba
->sli4_hba
.hba_eq
[qidx
]);
12080 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
12081 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12082 "3146 Fast-path completion queues "
12083 "does not exist\n");
12086 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
12087 if (unlikely(!cq
)) {
12088 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
12089 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12090 "0367 Fast-path completion queue "
12091 "(%d) does not exist\n", qidx
);
12095 if (unlikely(cqid
!= cq
->queue_id
)) {
12096 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12097 "0368 Miss-matched fast-path completion "
12098 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
12099 cqid
, cq
->queue_id
);
12103 /* Process all the entries to the CQ */
12104 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
12105 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
12106 if (!(++ecount
% cq
->entry_repost
))
12107 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
12110 /* Track the max number of CQEs processed in 1 EQ */
12111 if (ecount
> cq
->CQ_max_cqe
)
12112 cq
->CQ_max_cqe
= ecount
;
12114 /* Catch the no cq entry condition */
12115 if (unlikely(ecount
== 0))
12116 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12117 "0369 No entry from fast-path completion "
12118 "queue fcpcqid=%d\n", cq
->queue_id
);
12120 /* In any case, flash and re-arm the CQ */
12121 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
12123 /* wake up worker thread if there are works to be done */
12125 lpfc_worker_wake_up(phba
);
12129 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
12131 struct lpfc_eqe
*eqe
;
12133 /* walk all the EQ entries and drop on the floor */
12134 while ((eqe
= lpfc_sli4_eq_get(eq
)))
12137 /* Clear and re-arm the EQ */
12138 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
12142 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
12143 * @irq: Interrupt number.
12144 * @dev_id: The device context pointer.
12146 * This function is directly called from the PCI layer as an interrupt
12147 * service routine when device with SLI-4 interface spec is enabled with
12148 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
12149 * ring event in the HBA. However, when the device is enabled with either
12150 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
12151 * device-level interrupt handler. When the PCI slot is in error recovery
12152 * or the HBA is undergoing initialization, the interrupt handler will not
12153 * process the interrupt. The SCSI FCP fast-path ring event are handled in
12154 * the intrrupt context. This function is called without any lock held.
12155 * It gets the hbalock to access and update SLI data structures. Note that,
12156 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
12157 * equal to that of FCP CQ index.
12159 * The link attention and ELS ring attention events are handled
12160 * by the worker thread. The interrupt handler signals the worker thread
12161 * and returns for these events. This function is called without any lock
12162 * held. It gets the hbalock to access and update SLI data structures.
12164 * This function returns IRQ_HANDLED when interrupt is handled else it
12165 * returns IRQ_NONE.
12168 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
12170 struct lpfc_hba
*phba
;
12171 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
12172 struct lpfc_queue
*fpeq
;
12173 struct lpfc_eqe
*eqe
;
12174 unsigned long iflag
;
12178 /* Get the driver's phba structure from the dev_id */
12179 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
12180 phba
= fcp_eq_hdl
->phba
;
12181 fcp_eqidx
= fcp_eq_hdl
->idx
;
12183 if (unlikely(!phba
))
12185 if (unlikely(!phba
->sli4_hba
.hba_eq
))
12188 /* Get to the EQ struct associated with this vector */
12189 fpeq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12190 if (unlikely(!fpeq
))
12193 if (lpfc_fcp_look_ahead
) {
12194 if (atomic_dec_and_test(&fcp_eq_hdl
->fcp_eq_in_use
))
12195 lpfc_sli4_eq_clr_intr(fpeq
);
12197 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12202 /* Check device state for handling interrupt */
12203 if (unlikely(lpfc_intr_state_check(phba
))) {
12204 fpeq
->EQ_badstate
++;
12205 /* Check again for link_state with lock held */
12206 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12207 if (phba
->link_state
< LPFC_LINK_DOWN
)
12208 /* Flush, clear interrupt, and rearm the EQ */
12209 lpfc_sli4_eq_flush(phba
, fpeq
);
12210 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12211 if (lpfc_fcp_look_ahead
)
12212 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12217 * Process all the event on FCP fast-path EQ
12219 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
12220 lpfc_sli4_hba_handle_eqe(phba
, eqe
, fcp_eqidx
);
12221 if (!(++ecount
% fpeq
->entry_repost
))
12222 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
12223 fpeq
->EQ_processed
++;
12226 /* Track the max number of EQEs processed in 1 intr */
12227 if (ecount
> fpeq
->EQ_max_eqe
)
12228 fpeq
->EQ_max_eqe
= ecount
;
12230 /* Always clear and re-arm the fast-path EQ */
12231 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
12233 if (unlikely(ecount
== 0)) {
12234 fpeq
->EQ_no_entry
++;
12236 if (lpfc_fcp_look_ahead
) {
12237 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12241 if (phba
->intr_type
== MSIX
)
12242 /* MSI-X treated interrupt served as no EQ share INT */
12243 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12244 "0358 MSI-X interrupt with no EQE\n");
12246 /* Non MSI-X treated on interrupt as EQ share INT */
12250 if (lpfc_fcp_look_ahead
)
12251 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12252 return IRQ_HANDLED
;
12253 } /* lpfc_sli4_fp_intr_handler */
12256 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
12257 * @irq: Interrupt number.
12258 * @dev_id: The device context pointer.
12260 * This function is the device-level interrupt handler to device with SLI-4
12261 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
12262 * interrupt mode is enabled and there is an event in the HBA which requires
12263 * driver attention. This function invokes the slow-path interrupt attention
12264 * handling function and fast-path interrupt attention handling function in
12265 * turn to process the relevant HBA attention events. This function is called
12266 * without any lock held. It gets the hbalock to access and update SLI data
12269 * This function returns IRQ_HANDLED when interrupt is handled, else it
12270 * returns IRQ_NONE.
12273 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
12275 struct lpfc_hba
*phba
;
12276 irqreturn_t hba_irq_rc
;
12277 bool hba_handled
= false;
12280 /* Get the driver's phba structure from the dev_id */
12281 phba
= (struct lpfc_hba
*)dev_id
;
12283 if (unlikely(!phba
))
12287 * Invoke fast-path host attention interrupt handling as appropriate.
12289 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
12290 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
12291 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
12292 if (hba_irq_rc
== IRQ_HANDLED
)
12293 hba_handled
|= true;
12296 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
12297 } /* lpfc_sli4_intr_handler */
12300 * lpfc_sli4_queue_free - free a queue structure and associated memory
12301 * @queue: The queue structure to free.
12303 * This function frees a queue structure and the DMAable memory used for
12304 * the host resident queue. This function must be called after destroying the
12305 * queue on the HBA.
12308 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
12310 struct lpfc_dmabuf
*dmabuf
;
12315 while (!list_empty(&queue
->page_list
)) {
12316 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
12318 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
12319 dmabuf
->virt
, dmabuf
->phys
);
12327 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12328 * @phba: The HBA that this queue is being created on.
12329 * @entry_size: The size of each queue entry for this queue.
12330 * @entry count: The number of entries that this queue will handle.
12332 * This function allocates a queue structure and the DMAable memory used for
12333 * the host resident queue. This function must be called before creating the
12334 * queue on the HBA.
12336 struct lpfc_queue
*
12337 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
12338 uint32_t entry_count
)
12340 struct lpfc_queue
*queue
;
12341 struct lpfc_dmabuf
*dmabuf
;
12342 int x
, total_qe_count
;
12344 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12346 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12347 hw_page_size
= SLI4_PAGE_SIZE
;
12349 queue
= kzalloc(sizeof(struct lpfc_queue
) +
12350 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
12353 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
12354 hw_page_size
))/hw_page_size
;
12355 INIT_LIST_HEAD(&queue
->list
);
12356 INIT_LIST_HEAD(&queue
->page_list
);
12357 INIT_LIST_HEAD(&queue
->child_list
);
12358 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
12359 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
12362 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
12363 hw_page_size
, &dmabuf
->phys
,
12365 if (!dmabuf
->virt
) {
12369 memset(dmabuf
->virt
, 0, hw_page_size
);
12370 dmabuf
->buffer_tag
= x
;
12371 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
12372 /* initialize queue's entry array */
12373 dma_pointer
= dmabuf
->virt
;
12374 for (; total_qe_count
< entry_count
&&
12375 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
12376 total_qe_count
++, dma_pointer
+= entry_size
) {
12377 queue
->qe
[total_qe_count
].address
= dma_pointer
;
12380 queue
->entry_size
= entry_size
;
12381 queue
->entry_count
= entry_count
;
12384 * entry_repost is calculated based on the number of entries in the
12385 * queue. This works out except for RQs. If buffers are NOT initially
12386 * posted for every RQE, entry_repost should be adjusted accordingly.
12388 queue
->entry_repost
= (entry_count
>> 3);
12389 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
12390 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
12391 queue
->phba
= phba
;
12395 lpfc_sli4_queue_free(queue
);
12400 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
12401 * @phba: HBA structure that indicates port to create a queue on.
12402 * @pci_barset: PCI BAR set flag.
12404 * This function shall perform iomap of the specified PCI BAR address to host
12405 * memory address if not already done so and return it. The returned host
12406 * memory address can be NULL.
12408 static void __iomem
*
12409 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
12411 struct pci_dev
*pdev
;
12416 pdev
= phba
->pcidev
;
12418 switch (pci_barset
) {
12419 case WQ_PCI_BAR_0_AND_1
:
12420 return phba
->pci_bar0_memmap_p
;
12421 case WQ_PCI_BAR_2_AND_3
:
12422 return phba
->pci_bar2_memmap_p
;
12423 case WQ_PCI_BAR_4_AND_5
:
12424 return phba
->pci_bar4_memmap_p
;
12432 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
12433 * @phba: HBA structure that indicates port to create a queue on.
12434 * @startq: The starting FCP EQ to modify
12436 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
12438 * The @phba struct is used to send mailbox command to HBA. The @startq
12439 * is used to get the starting FCP EQ to change.
12440 * This function is asynchronous and will wait for the mailbox
12441 * command to finish before continuing.
12443 * On success this function will return a zero. If unable to allocate enough
12444 * memory this function will return -ENOMEM. If the queue create mailbox command
12445 * fails this function will return -ENXIO.
12448 lpfc_modify_fcp_eq_delay(struct lpfc_hba
*phba
, uint16_t startq
)
12450 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
12451 LPFC_MBOXQ_t
*mbox
;
12452 struct lpfc_queue
*eq
;
12453 int cnt
, rc
, length
, status
= 0;
12454 uint32_t shdr_status
, shdr_add_status
;
12457 union lpfc_sli4_cfg_shdr
*shdr
;
12460 if (startq
>= phba
->cfg_fcp_io_channel
)
12463 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12466 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
12467 sizeof(struct lpfc_sli4_cfg_mhdr
));
12468 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12469 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
12470 length
, LPFC_SLI4_MBX_EMBED
);
12471 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
12473 /* Calculate delay multiper from maximum interrupt per second */
12474 result
= phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
;
12475 if (result
> LPFC_DMULT_CONST
)
12478 dmult
= LPFC_DMULT_CONST
/result
- 1;
12481 for (fcp_eqidx
= startq
; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
12483 eq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12486 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
12487 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
12488 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
12490 if (cnt
>= LPFC_MAX_EQ_DELAY
)
12493 eq_delay
->u
.request
.num_eq
= cnt
;
12495 mbox
->vport
= phba
->pport
;
12496 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12497 mbox
->context1
= NULL
;
12498 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12499 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
12500 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12501 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12502 if (shdr_status
|| shdr_add_status
|| rc
) {
12503 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12504 "2512 MODIFY_EQ_DELAY mailbox failed with "
12505 "status x%x add_status x%x, mbx status x%x\n",
12506 shdr_status
, shdr_add_status
, rc
);
12509 mempool_free(mbox
, phba
->mbox_mem_pool
);
12514 * lpfc_eq_create - Create an Event Queue on the HBA
12515 * @phba: HBA structure that indicates port to create a queue on.
12516 * @eq: The queue structure to use to create the event queue.
12517 * @imax: The maximum interrupt per second limit.
12519 * This function creates an event queue, as detailed in @eq, on a port,
12520 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12522 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12523 * is used to get the entry count and entry size that are necessary to
12524 * determine the number of pages to allocate and use for this queue. This
12525 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12526 * event queue. This function is asynchronous and will wait for the mailbox
12527 * command to finish before continuing.
12529 * On success this function will return a zero. If unable to allocate enough
12530 * memory this function will return -ENOMEM. If the queue create mailbox command
12531 * fails this function will return -ENXIO.
12534 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
12536 struct lpfc_mbx_eq_create
*eq_create
;
12537 LPFC_MBOXQ_t
*mbox
;
12538 int rc
, length
, status
= 0;
12539 struct lpfc_dmabuf
*dmabuf
;
12540 uint32_t shdr_status
, shdr_add_status
;
12541 union lpfc_sli4_cfg_shdr
*shdr
;
12543 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12545 /* sanity check on queue memory */
12548 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12549 hw_page_size
= SLI4_PAGE_SIZE
;
12551 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12554 length
= (sizeof(struct lpfc_mbx_eq_create
) -
12555 sizeof(struct lpfc_sli4_cfg_mhdr
));
12556 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12557 LPFC_MBOX_OPCODE_EQ_CREATE
,
12558 length
, LPFC_SLI4_MBX_EMBED
);
12559 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
12560 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
12562 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
12564 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
12565 /* Calculate delay multiper from maximum interrupt per second */
12566 if (imax
> LPFC_DMULT_CONST
)
12569 dmult
= LPFC_DMULT_CONST
/imax
- 1;
12570 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
12572 switch (eq
->entry_count
) {
12574 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12575 "0360 Unsupported EQ count. (%d)\n",
12577 if (eq
->entry_count
< 256)
12579 /* otherwise default to smallest count (drop through) */
12581 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12585 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12589 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12593 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12597 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12601 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
12602 memset(dmabuf
->virt
, 0, hw_page_size
);
12603 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12604 putPaddrLow(dmabuf
->phys
);
12605 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12606 putPaddrHigh(dmabuf
->phys
);
12608 mbox
->vport
= phba
->pport
;
12609 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12610 mbox
->context1
= NULL
;
12611 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12612 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
12613 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12614 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12615 if (shdr_status
|| shdr_add_status
|| rc
) {
12616 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12617 "2500 EQ_CREATE mailbox failed with "
12618 "status x%x add_status x%x, mbx status x%x\n",
12619 shdr_status
, shdr_add_status
, rc
);
12622 eq
->type
= LPFC_EQ
;
12623 eq
->subtype
= LPFC_NONE
;
12624 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
12625 if (eq
->queue_id
== 0xFFFF)
12627 eq
->host_index
= 0;
12630 mempool_free(mbox
, phba
->mbox_mem_pool
);
12635 * lpfc_cq_create - Create a Completion Queue on the HBA
12636 * @phba: HBA structure that indicates port to create a queue on.
12637 * @cq: The queue structure to use to create the completion queue.
12638 * @eq: The event queue to bind this completion queue to.
12640 * This function creates a completion queue, as detailed in @wq, on a port,
12641 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
12643 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12644 * is used to get the entry count and entry size that are necessary to
12645 * determine the number of pages to allocate and use for this queue. The @eq
12646 * is used to indicate which event queue to bind this completion queue to. This
12647 * function will send the CQ_CREATE mailbox command to the HBA to setup the
12648 * completion queue. This function is asynchronous and will wait for the mailbox
12649 * command to finish before continuing.
12651 * On success this function will return a zero. If unable to allocate enough
12652 * memory this function will return -ENOMEM. If the queue create mailbox command
12653 * fails this function will return -ENXIO.
12656 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12657 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
12659 struct lpfc_mbx_cq_create
*cq_create
;
12660 struct lpfc_dmabuf
*dmabuf
;
12661 LPFC_MBOXQ_t
*mbox
;
12662 int rc
, length
, status
= 0;
12663 uint32_t shdr_status
, shdr_add_status
;
12664 union lpfc_sli4_cfg_shdr
*shdr
;
12665 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12667 /* sanity check on queue memory */
12670 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12671 hw_page_size
= SLI4_PAGE_SIZE
;
12673 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12676 length
= (sizeof(struct lpfc_mbx_cq_create
) -
12677 sizeof(struct lpfc_sli4_cfg_mhdr
));
12678 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12679 LPFC_MBOX_OPCODE_CQ_CREATE
,
12680 length
, LPFC_SLI4_MBX_EMBED
);
12681 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
12682 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
12683 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
12685 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
12686 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
12687 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12688 phba
->sli4_hba
.pc_sli4_params
.cqv
);
12689 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
12690 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12691 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
12692 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
12695 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
12698 switch (cq
->entry_count
) {
12700 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12701 "0361 Unsupported CQ count. (%d)\n",
12703 if (cq
->entry_count
< 256) {
12707 /* otherwise default to smallest count (drop through) */
12709 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12713 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12717 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12721 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12722 memset(dmabuf
->virt
, 0, hw_page_size
);
12723 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12724 putPaddrLow(dmabuf
->phys
);
12725 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12726 putPaddrHigh(dmabuf
->phys
);
12728 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12730 /* The IOCTL status is embedded in the mailbox subheader. */
12731 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12732 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12733 if (shdr_status
|| shdr_add_status
|| rc
) {
12734 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12735 "2501 CQ_CREATE mailbox failed with "
12736 "status x%x add_status x%x, mbx status x%x\n",
12737 shdr_status
, shdr_add_status
, rc
);
12741 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12742 if (cq
->queue_id
== 0xFFFF) {
12746 /* link the cq onto the parent eq child list */
12747 list_add_tail(&cq
->list
, &eq
->child_list
);
12748 /* Set up completion queue's type and subtype */
12750 cq
->subtype
= subtype
;
12751 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12752 cq
->assoc_qid
= eq
->queue_id
;
12753 cq
->host_index
= 0;
12757 mempool_free(mbox
, phba
->mbox_mem_pool
);
12762 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12763 * @phba: HBA structure that indicates port to create a queue on.
12764 * @mq: The queue structure to use to create the mailbox queue.
12765 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12766 * @cq: The completion queue to associate with this cq.
12768 * This function provides failback (fb) functionality when the
12769 * mq_create_ext fails on older FW generations. It's purpose is identical
12770 * to mq_create_ext otherwise.
12772 * This routine cannot fail as all attributes were previously accessed and
12773 * initialized in mq_create_ext.
12776 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12777 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12779 struct lpfc_mbx_mq_create
*mq_create
;
12780 struct lpfc_dmabuf
*dmabuf
;
12783 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12784 sizeof(struct lpfc_sli4_cfg_mhdr
));
12785 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12786 LPFC_MBOX_OPCODE_MQ_CREATE
,
12787 length
, LPFC_SLI4_MBX_EMBED
);
12788 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12789 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12791 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12793 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12794 switch (mq
->entry_count
) {
12796 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12797 LPFC_MQ_RING_SIZE_16
);
12800 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12801 LPFC_MQ_RING_SIZE_32
);
12804 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12805 LPFC_MQ_RING_SIZE_64
);
12808 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12809 LPFC_MQ_RING_SIZE_128
);
12812 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12813 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12814 putPaddrLow(dmabuf
->phys
);
12815 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12816 putPaddrHigh(dmabuf
->phys
);
12821 * lpfc_mq_create - Create a mailbox Queue on the HBA
12822 * @phba: HBA structure that indicates port to create a queue on.
12823 * @mq: The queue structure to use to create the mailbox queue.
12824 * @cq: The completion queue to associate with this cq.
12825 * @subtype: The queue's subtype.
12827 * This function creates a mailbox queue, as detailed in @mq, on a port,
12828 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12830 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12831 * is used to get the entry count and entry size that are necessary to
12832 * determine the number of pages to allocate and use for this queue. This
12833 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12834 * mailbox queue. This function is asynchronous and will wait for the mailbox
12835 * command to finish before continuing.
12837 * On success this function will return a zero. If unable to allocate enough
12838 * memory this function will return -ENOMEM. If the queue create mailbox command
12839 * fails this function will return -ENXIO.
12842 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12843 struct lpfc_queue
*cq
, uint32_t subtype
)
12845 struct lpfc_mbx_mq_create
*mq_create
;
12846 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12847 struct lpfc_dmabuf
*dmabuf
;
12848 LPFC_MBOXQ_t
*mbox
;
12849 int rc
, length
, status
= 0;
12850 uint32_t shdr_status
, shdr_add_status
;
12851 union lpfc_sli4_cfg_shdr
*shdr
;
12852 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12854 /* sanity check on queue memory */
12857 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12858 hw_page_size
= SLI4_PAGE_SIZE
;
12860 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12863 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12864 sizeof(struct lpfc_sli4_cfg_mhdr
));
12865 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12866 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12867 length
, LPFC_SLI4_MBX_EMBED
);
12869 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12870 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12871 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12872 &mq_create_ext
->u
.request
, mq
->page_count
);
12873 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12874 &mq_create_ext
->u
.request
, 1);
12875 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12876 &mq_create_ext
->u
.request
, 1);
12877 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12878 &mq_create_ext
->u
.request
, 1);
12879 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12880 &mq_create_ext
->u
.request
, 1);
12881 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12882 &mq_create_ext
->u
.request
, 1);
12883 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12884 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12885 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12886 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12887 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12890 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12892 switch (mq
->entry_count
) {
12894 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12895 "0362 Unsupported MQ count. (%d)\n",
12897 if (mq
->entry_count
< 16) {
12901 /* otherwise default to smallest count (drop through) */
12903 bf_set(lpfc_mq_context_ring_size
,
12904 &mq_create_ext
->u
.request
.context
,
12905 LPFC_MQ_RING_SIZE_16
);
12908 bf_set(lpfc_mq_context_ring_size
,
12909 &mq_create_ext
->u
.request
.context
,
12910 LPFC_MQ_RING_SIZE_32
);
12913 bf_set(lpfc_mq_context_ring_size
,
12914 &mq_create_ext
->u
.request
.context
,
12915 LPFC_MQ_RING_SIZE_64
);
12918 bf_set(lpfc_mq_context_ring_size
,
12919 &mq_create_ext
->u
.request
.context
,
12920 LPFC_MQ_RING_SIZE_128
);
12923 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12924 memset(dmabuf
->virt
, 0, hw_page_size
);
12925 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12926 putPaddrLow(dmabuf
->phys
);
12927 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12928 putPaddrHigh(dmabuf
->phys
);
12930 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12931 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12932 &mq_create_ext
->u
.response
);
12933 if (rc
!= MBX_SUCCESS
) {
12934 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12935 "2795 MQ_CREATE_EXT failed with "
12936 "status x%x. Failback to MQ_CREATE.\n",
12938 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12939 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12940 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12941 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12942 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12943 &mq_create
->u
.response
);
12946 /* The IOCTL status is embedded in the mailbox subheader. */
12947 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12948 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12949 if (shdr_status
|| shdr_add_status
|| rc
) {
12950 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12951 "2502 MQ_CREATE mailbox failed with "
12952 "status x%x add_status x%x, mbx status x%x\n",
12953 shdr_status
, shdr_add_status
, rc
);
12957 if (mq
->queue_id
== 0xFFFF) {
12961 mq
->type
= LPFC_MQ
;
12962 mq
->assoc_qid
= cq
->queue_id
;
12963 mq
->subtype
= subtype
;
12964 mq
->host_index
= 0;
12967 /* link the mq onto the parent cq child list */
12968 list_add_tail(&mq
->list
, &cq
->child_list
);
12970 mempool_free(mbox
, phba
->mbox_mem_pool
);
12975 * lpfc_wq_create - Create a Work Queue on the HBA
12976 * @phba: HBA structure that indicates port to create a queue on.
12977 * @wq: The queue structure to use to create the work queue.
12978 * @cq: The completion queue to bind this work queue to.
12979 * @subtype: The subtype of the work queue indicating its functionality.
12981 * This function creates a work queue, as detailed in @wq, on a port, described
12982 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12984 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12985 * is used to get the entry count and entry size that are necessary to
12986 * determine the number of pages to allocate and use for this queue. The @cq
12987 * is used to indicate which completion queue to bind this work queue to. This
12988 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12989 * work queue. This function is asynchronous and will wait for the mailbox
12990 * command to finish before continuing.
12992 * On success this function will return a zero. If unable to allocate enough
12993 * memory this function will return -ENOMEM. If the queue create mailbox command
12994 * fails this function will return -ENXIO.
12997 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12998 struct lpfc_queue
*cq
, uint32_t subtype
)
13000 struct lpfc_mbx_wq_create
*wq_create
;
13001 struct lpfc_dmabuf
*dmabuf
;
13002 LPFC_MBOXQ_t
*mbox
;
13003 int rc
, length
, status
= 0;
13004 uint32_t shdr_status
, shdr_add_status
;
13005 union lpfc_sli4_cfg_shdr
*shdr
;
13006 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13007 struct dma_address
*page
;
13008 void __iomem
*bar_memmap_p
;
13009 uint32_t db_offset
;
13010 uint16_t pci_barset
;
13012 /* sanity check on queue memory */
13015 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13016 hw_page_size
= SLI4_PAGE_SIZE
;
13018 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13021 length
= (sizeof(struct lpfc_mbx_wq_create
) -
13022 sizeof(struct lpfc_sli4_cfg_mhdr
));
13023 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13024 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
13025 length
, LPFC_SLI4_MBX_EMBED
);
13026 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
13027 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
13028 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
13030 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
13033 /* wqv is the earliest version supported, NOT the latest */
13034 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13035 phba
->sli4_hba
.pc_sli4_params
.wqv
);
13037 switch (phba
->sli4_hba
.pc_sli4_params
.wqv
) {
13038 case LPFC_Q_CREATE_VERSION_0
:
13039 switch (wq
->entry_size
) {
13042 /* Nothing to do, version 0 ONLY supports 64 byte */
13043 page
= wq_create
->u
.request
.page
;
13046 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
13047 LPFC_WQ_SZ128_SUPPORT
)) {
13051 /* If we get here the HBA MUST also support V1 and
13054 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13055 LPFC_Q_CREATE_VERSION_1
);
13057 bf_set(lpfc_mbx_wq_create_wqe_count
,
13058 &wq_create
->u
.request_1
, wq
->entry_count
);
13059 bf_set(lpfc_mbx_wq_create_wqe_size
,
13060 &wq_create
->u
.request_1
,
13061 LPFC_WQ_WQE_SIZE_128
);
13062 bf_set(lpfc_mbx_wq_create_page_size
,
13063 &wq_create
->u
.request_1
,
13064 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13065 page
= wq_create
->u
.request_1
.page
;
13069 case LPFC_Q_CREATE_VERSION_1
:
13070 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
13072 switch (wq
->entry_size
) {
13075 bf_set(lpfc_mbx_wq_create_wqe_size
,
13076 &wq_create
->u
.request_1
,
13077 LPFC_WQ_WQE_SIZE_64
);
13080 if (!(phba
->sli4_hba
.pc_sli4_params
.wqsize
&
13081 LPFC_WQ_SZ128_SUPPORT
)) {
13085 bf_set(lpfc_mbx_wq_create_wqe_size
,
13086 &wq_create
->u
.request_1
,
13087 LPFC_WQ_WQE_SIZE_128
);
13090 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
13091 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13092 page
= wq_create
->u
.request_1
.page
;
13099 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
13100 memset(dmabuf
->virt
, 0, hw_page_size
);
13101 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
13102 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
13105 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13106 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
13108 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13109 /* The IOCTL status is embedded in the mailbox subheader. */
13110 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13111 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13112 if (shdr_status
|| shdr_add_status
|| rc
) {
13113 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13114 "2503 WQ_CREATE mailbox failed with "
13115 "status x%x add_status x%x, mbx status x%x\n",
13116 shdr_status
, shdr_add_status
, rc
);
13120 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
13121 if (wq
->queue_id
== 0xFFFF) {
13125 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
13126 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
13127 &wq_create
->u
.response
);
13128 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
13129 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
13130 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13131 "3265 WQ[%d] doorbell format not "
13132 "supported: x%x\n", wq
->queue_id
,
13137 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
13138 &wq_create
->u
.response
);
13139 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
13140 if (!bar_memmap_p
) {
13141 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13142 "3263 WQ[%d] failed to memmap pci "
13143 "barset:x%x\n", wq
->queue_id
,
13148 db_offset
= wq_create
->u
.response
.doorbell_offset
;
13149 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
13150 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
13151 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13152 "3252 WQ[%d] doorbell offset not "
13153 "supported: x%x\n", wq
->queue_id
,
13158 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
13159 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13160 "3264 WQ[%d]: barset:x%x, offset:x%x, "
13161 "format:x%x\n", wq
->queue_id
, pci_barset
,
13162 db_offset
, wq
->db_format
);
13164 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
13165 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
13167 wq
->type
= LPFC_WQ
;
13168 wq
->assoc_qid
= cq
->queue_id
;
13169 wq
->subtype
= subtype
;
13170 wq
->host_index
= 0;
13172 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
13174 /* link the wq onto the parent cq child list */
13175 list_add_tail(&wq
->list
, &cq
->child_list
);
13177 mempool_free(mbox
, phba
->mbox_mem_pool
);
13182 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
13183 * @phba: HBA structure that indicates port to create a queue on.
13184 * @rq: The queue structure to use for the receive queue.
13185 * @qno: The associated HBQ number
13188 * For SLI4 we need to adjust the RQ repost value based on
13189 * the number of buffers that are initially posted to the RQ.
13192 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
13196 /* sanity check on queue memory */
13199 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
13201 /* Recalc repost for RQs based on buffers initially posted */
13203 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
13204 cnt
= LPFC_QUEUE_MIN_REPOST
;
13206 rq
->entry_repost
= cnt
;
13210 * lpfc_rq_create - Create a Receive Queue on the HBA
13211 * @phba: HBA structure that indicates port to create a queue on.
13212 * @hrq: The queue structure to use to create the header receive queue.
13213 * @drq: The queue structure to use to create the data receive queue.
13214 * @cq: The completion queue to bind this work queue to.
13216 * This function creates a receive buffer queue pair , as detailed in @hrq and
13217 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
13220 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
13221 * struct is used to get the entry count that is necessary to determine the
13222 * number of pages to use for this queue. The @cq is used to indicate which
13223 * completion queue to bind received buffers that are posted to these queues to.
13224 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
13225 * receive queue pair. This function is asynchronous and will wait for the
13226 * mailbox command to finish before continuing.
13228 * On success this function will return a zero. If unable to allocate enough
13229 * memory this function will return -ENOMEM. If the queue create mailbox command
13230 * fails this function will return -ENXIO.
13233 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13234 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
13236 struct lpfc_mbx_rq_create
*rq_create
;
13237 struct lpfc_dmabuf
*dmabuf
;
13238 LPFC_MBOXQ_t
*mbox
;
13239 int rc
, length
, status
= 0;
13240 uint32_t shdr_status
, shdr_add_status
;
13241 union lpfc_sli4_cfg_shdr
*shdr
;
13242 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
13243 void __iomem
*bar_memmap_p
;
13244 uint32_t db_offset
;
13245 uint16_t pci_barset
;
13247 /* sanity check on queue memory */
13248 if (!hrq
|| !drq
|| !cq
)
13250 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
13251 hw_page_size
= SLI4_PAGE_SIZE
;
13253 if (hrq
->entry_count
!= drq
->entry_count
)
13255 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13258 length
= (sizeof(struct lpfc_mbx_rq_create
) -
13259 sizeof(struct lpfc_sli4_cfg_mhdr
));
13260 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13261 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
13262 length
, LPFC_SLI4_MBX_EMBED
);
13263 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
13264 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13265 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13266 phba
->sli4_hba
.pc_sli4_params
.rqv
);
13267 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
13268 bf_set(lpfc_rq_context_rqe_count_1
,
13269 &rq_create
->u
.request
.context
,
13271 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
13272 bf_set(lpfc_rq_context_rqe_size
,
13273 &rq_create
->u
.request
.context
,
13275 bf_set(lpfc_rq_context_page_size
,
13276 &rq_create
->u
.request
.context
,
13277 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13279 switch (hrq
->entry_count
) {
13281 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13282 "2535 Unsupported RQ count. (%d)\n",
13284 if (hrq
->entry_count
< 512) {
13288 /* otherwise default to smallest count (drop through) */
13290 bf_set(lpfc_rq_context_rqe_count
,
13291 &rq_create
->u
.request
.context
,
13292 LPFC_RQ_RING_SIZE_512
);
13295 bf_set(lpfc_rq_context_rqe_count
,
13296 &rq_create
->u
.request
.context
,
13297 LPFC_RQ_RING_SIZE_1024
);
13300 bf_set(lpfc_rq_context_rqe_count
,
13301 &rq_create
->u
.request
.context
,
13302 LPFC_RQ_RING_SIZE_2048
);
13305 bf_set(lpfc_rq_context_rqe_count
,
13306 &rq_create
->u
.request
.context
,
13307 LPFC_RQ_RING_SIZE_4096
);
13310 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
13311 LPFC_HDR_BUF_SIZE
);
13313 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
13315 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
13317 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
13318 memset(dmabuf
->virt
, 0, hw_page_size
);
13319 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13320 putPaddrLow(dmabuf
->phys
);
13321 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13322 putPaddrHigh(dmabuf
->phys
);
13324 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13325 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
13327 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13328 /* The IOCTL status is embedded in the mailbox subheader. */
13329 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13330 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13331 if (shdr_status
|| shdr_add_status
|| rc
) {
13332 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13333 "2504 RQ_CREATE mailbox failed with "
13334 "status x%x add_status x%x, mbx status x%x\n",
13335 shdr_status
, shdr_add_status
, rc
);
13339 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
13340 if (hrq
->queue_id
== 0xFFFF) {
13345 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
13346 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
13347 &rq_create
->u
.response
);
13348 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
13349 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
13350 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13351 "3262 RQ [%d] doorbell format not "
13352 "supported: x%x\n", hrq
->queue_id
,
13358 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
13359 &rq_create
->u
.response
);
13360 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
13361 if (!bar_memmap_p
) {
13362 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13363 "3269 RQ[%d] failed to memmap pci "
13364 "barset:x%x\n", hrq
->queue_id
,
13370 db_offset
= rq_create
->u
.response
.doorbell_offset
;
13371 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
13372 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
13373 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13374 "3270 RQ[%d] doorbell offset not "
13375 "supported: x%x\n", hrq
->queue_id
,
13380 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
13381 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13382 "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
13383 "format:x%x\n", hrq
->queue_id
, pci_barset
,
13384 db_offset
, hrq
->db_format
);
13386 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
13387 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
13389 hrq
->type
= LPFC_HRQ
;
13390 hrq
->assoc_qid
= cq
->queue_id
;
13391 hrq
->subtype
= subtype
;
13392 hrq
->host_index
= 0;
13393 hrq
->hba_index
= 0;
13395 /* now create the data queue */
13396 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13397 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
13398 length
, LPFC_SLI4_MBX_EMBED
);
13399 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13400 phba
->sli4_hba
.pc_sli4_params
.rqv
);
13401 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
13402 bf_set(lpfc_rq_context_rqe_count_1
,
13403 &rq_create
->u
.request
.context
, hrq
->entry_count
);
13404 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
13405 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
13407 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
13408 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13410 switch (drq
->entry_count
) {
13412 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13413 "2536 Unsupported RQ count. (%d)\n",
13415 if (drq
->entry_count
< 512) {
13419 /* otherwise default to smallest count (drop through) */
13421 bf_set(lpfc_rq_context_rqe_count
,
13422 &rq_create
->u
.request
.context
,
13423 LPFC_RQ_RING_SIZE_512
);
13426 bf_set(lpfc_rq_context_rqe_count
,
13427 &rq_create
->u
.request
.context
,
13428 LPFC_RQ_RING_SIZE_1024
);
13431 bf_set(lpfc_rq_context_rqe_count
,
13432 &rq_create
->u
.request
.context
,
13433 LPFC_RQ_RING_SIZE_2048
);
13436 bf_set(lpfc_rq_context_rqe_count
,
13437 &rq_create
->u
.request
.context
,
13438 LPFC_RQ_RING_SIZE_4096
);
13441 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
13442 LPFC_DATA_BUF_SIZE
);
13444 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
13446 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
13448 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
13449 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13450 putPaddrLow(dmabuf
->phys
);
13451 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13452 putPaddrHigh(dmabuf
->phys
);
13454 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13455 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
13456 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13457 /* The IOCTL status is embedded in the mailbox subheader. */
13458 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13459 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13460 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13461 if (shdr_status
|| shdr_add_status
|| rc
) {
13465 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
13466 if (drq
->queue_id
== 0xFFFF) {
13470 drq
->type
= LPFC_DRQ
;
13471 drq
->assoc_qid
= cq
->queue_id
;
13472 drq
->subtype
= subtype
;
13473 drq
->host_index
= 0;
13474 drq
->hba_index
= 0;
13476 /* link the header and data RQs onto the parent cq child list */
13477 list_add_tail(&hrq
->list
, &cq
->child_list
);
13478 list_add_tail(&drq
->list
, &cq
->child_list
);
13481 mempool_free(mbox
, phba
->mbox_mem_pool
);
13486 * lpfc_eq_destroy - Destroy an event Queue on the HBA
13487 * @eq: The queue structure associated with the queue to destroy.
13489 * This function destroys a queue, as detailed in @eq by sending an mailbox
13490 * command, specific to the type of queue, to the HBA.
13492 * The @eq struct is used to get the queue ID of the queue to destroy.
13494 * On success this function will return a zero. If the queue destroy mailbox
13495 * command fails this function will return -ENXIO.
13498 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
13500 LPFC_MBOXQ_t
*mbox
;
13501 int rc
, length
, status
= 0;
13502 uint32_t shdr_status
, shdr_add_status
;
13503 union lpfc_sli4_cfg_shdr
*shdr
;
13505 /* sanity check on queue memory */
13508 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13511 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
13512 sizeof(struct lpfc_sli4_cfg_mhdr
));
13513 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13514 LPFC_MBOX_OPCODE_EQ_DESTROY
,
13515 length
, LPFC_SLI4_MBX_EMBED
);
13516 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
13518 mbox
->vport
= eq
->phba
->pport
;
13519 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13521 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
13522 /* The IOCTL status is embedded in the mailbox subheader. */
13523 shdr
= (union lpfc_sli4_cfg_shdr
*)
13524 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
13525 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13526 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13527 if (shdr_status
|| shdr_add_status
|| rc
) {
13528 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13529 "2505 EQ_DESTROY mailbox failed with "
13530 "status x%x add_status x%x, mbx status x%x\n",
13531 shdr_status
, shdr_add_status
, rc
);
13535 /* Remove eq from any list */
13536 list_del_init(&eq
->list
);
13537 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
13542 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
13543 * @cq: The queue structure associated with the queue to destroy.
13545 * This function destroys a queue, as detailed in @cq by sending an mailbox
13546 * command, specific to the type of queue, to the HBA.
13548 * The @cq struct is used to get the queue ID of the queue to destroy.
13550 * On success this function will return a zero. If the queue destroy mailbox
13551 * command fails this function will return -ENXIO.
13554 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
13556 LPFC_MBOXQ_t
*mbox
;
13557 int rc
, length
, status
= 0;
13558 uint32_t shdr_status
, shdr_add_status
;
13559 union lpfc_sli4_cfg_shdr
*shdr
;
13561 /* sanity check on queue memory */
13564 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13567 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
13568 sizeof(struct lpfc_sli4_cfg_mhdr
));
13569 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13570 LPFC_MBOX_OPCODE_CQ_DESTROY
,
13571 length
, LPFC_SLI4_MBX_EMBED
);
13572 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
13574 mbox
->vport
= cq
->phba
->pport
;
13575 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13576 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
13577 /* The IOCTL status is embedded in the mailbox subheader. */
13578 shdr
= (union lpfc_sli4_cfg_shdr
*)
13579 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
13580 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13581 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13582 if (shdr_status
|| shdr_add_status
|| rc
) {
13583 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13584 "2506 CQ_DESTROY mailbox failed with "
13585 "status x%x add_status x%x, mbx status x%x\n",
13586 shdr_status
, shdr_add_status
, rc
);
13589 /* Remove cq from any list */
13590 list_del_init(&cq
->list
);
13591 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
13596 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
13597 * @qm: The queue structure associated with the queue to destroy.
13599 * This function destroys a queue, as detailed in @mq by sending an mailbox
13600 * command, specific to the type of queue, to the HBA.
13602 * The @mq struct is used to get the queue ID of the queue to destroy.
13604 * On success this function will return a zero. If the queue destroy mailbox
13605 * command fails this function will return -ENXIO.
13608 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
13610 LPFC_MBOXQ_t
*mbox
;
13611 int rc
, length
, status
= 0;
13612 uint32_t shdr_status
, shdr_add_status
;
13613 union lpfc_sli4_cfg_shdr
*shdr
;
13615 /* sanity check on queue memory */
13618 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13621 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
13622 sizeof(struct lpfc_sli4_cfg_mhdr
));
13623 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13624 LPFC_MBOX_OPCODE_MQ_DESTROY
,
13625 length
, LPFC_SLI4_MBX_EMBED
);
13626 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
13628 mbox
->vport
= mq
->phba
->pport
;
13629 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13630 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
13631 /* The IOCTL status is embedded in the mailbox subheader. */
13632 shdr
= (union lpfc_sli4_cfg_shdr
*)
13633 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
13634 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13635 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13636 if (shdr_status
|| shdr_add_status
|| rc
) {
13637 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13638 "2507 MQ_DESTROY mailbox failed with "
13639 "status x%x add_status x%x, mbx status x%x\n",
13640 shdr_status
, shdr_add_status
, rc
);
13643 /* Remove mq from any list */
13644 list_del_init(&mq
->list
);
13645 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
13650 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
13651 * @wq: The queue structure associated with the queue to destroy.
13653 * This function destroys a queue, as detailed in @wq by sending an mailbox
13654 * command, specific to the type of queue, to the HBA.
13656 * The @wq struct is used to get the queue ID of the queue to destroy.
13658 * On success this function will return a zero. If the queue destroy mailbox
13659 * command fails this function will return -ENXIO.
13662 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
13664 LPFC_MBOXQ_t
*mbox
;
13665 int rc
, length
, status
= 0;
13666 uint32_t shdr_status
, shdr_add_status
;
13667 union lpfc_sli4_cfg_shdr
*shdr
;
13669 /* sanity check on queue memory */
13672 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13675 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
13676 sizeof(struct lpfc_sli4_cfg_mhdr
));
13677 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13678 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
13679 length
, LPFC_SLI4_MBX_EMBED
);
13680 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
13682 mbox
->vport
= wq
->phba
->pport
;
13683 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13684 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
13685 shdr
= (union lpfc_sli4_cfg_shdr
*)
13686 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
13687 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13688 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13689 if (shdr_status
|| shdr_add_status
|| rc
) {
13690 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13691 "2508 WQ_DESTROY mailbox failed with "
13692 "status x%x add_status x%x, mbx status x%x\n",
13693 shdr_status
, shdr_add_status
, rc
);
13696 /* Remove wq from any list */
13697 list_del_init(&wq
->list
);
13698 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
13703 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
13704 * @rq: The queue structure associated with the queue to destroy.
13706 * This function destroys a queue, as detailed in @rq by sending an mailbox
13707 * command, specific to the type of queue, to the HBA.
13709 * The @rq struct is used to get the queue ID of the queue to destroy.
13711 * On success this function will return a zero. If the queue destroy mailbox
13712 * command fails this function will return -ENXIO.
13715 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13716 struct lpfc_queue
*drq
)
13718 LPFC_MBOXQ_t
*mbox
;
13719 int rc
, length
, status
= 0;
13720 uint32_t shdr_status
, shdr_add_status
;
13721 union lpfc_sli4_cfg_shdr
*shdr
;
13723 /* sanity check on queue memory */
13726 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13729 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
13730 sizeof(struct lpfc_sli4_cfg_mhdr
));
13731 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13732 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
13733 length
, LPFC_SLI4_MBX_EMBED
);
13734 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13736 mbox
->vport
= hrq
->phba
->pport
;
13737 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13738 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
13739 /* The IOCTL status is embedded in the mailbox subheader. */
13740 shdr
= (union lpfc_sli4_cfg_shdr
*)
13741 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13742 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13743 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13744 if (shdr_status
|| shdr_add_status
|| rc
) {
13745 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13746 "2509 RQ_DESTROY mailbox failed with "
13747 "status x%x add_status x%x, mbx status x%x\n",
13748 shdr_status
, shdr_add_status
, rc
);
13749 if (rc
!= MBX_TIMEOUT
)
13750 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13753 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13755 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
13756 shdr
= (union lpfc_sli4_cfg_shdr
*)
13757 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13758 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13759 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13760 if (shdr_status
|| shdr_add_status
|| rc
) {
13761 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13762 "2510 RQ_DESTROY mailbox failed with "
13763 "status x%x add_status x%x, mbx status x%x\n",
13764 shdr_status
, shdr_add_status
, rc
);
13767 list_del_init(&hrq
->list
);
13768 list_del_init(&drq
->list
);
13769 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13774 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
13775 * @phba: The virtual port for which this call being executed.
13776 * @pdma_phys_addr0: Physical address of the 1st SGL page.
13777 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
13778 * @xritag: the xritag that ties this io to the SGL pages.
13780 * This routine will post the sgl pages for the IO that has the xritag
13781 * that is in the iocbq structure. The xritag is assigned during iocbq
13782 * creation and persists for as long as the driver is loaded.
13783 * if the caller has fewer than 256 scatter gather segments to map then
13784 * pdma_phys_addr1 should be 0.
13785 * If the caller needs to map more than 256 scatter gather segment then
13786 * pdma_phys_addr1 should be a valid physical address.
13787 * physical address for SGLs must be 64 byte aligned.
13788 * If you are going to map 2 SGL's then the first one must have 256 entries
13789 * the second sgl can have between 1 and 256 entries.
13793 * -ENXIO, -ENOMEM - Failure
13796 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
13797 dma_addr_t pdma_phys_addr0
,
13798 dma_addr_t pdma_phys_addr1
,
13801 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
13802 LPFC_MBOXQ_t
*mbox
;
13804 uint32_t shdr_status
, shdr_add_status
;
13806 union lpfc_sli4_cfg_shdr
*shdr
;
13808 if (xritag
== NO_XRI
) {
13809 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13810 "0364 Invalid param:\n");
13814 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13818 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13819 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13820 sizeof(struct lpfc_mbx_post_sgl_pages
) -
13821 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
13823 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
13824 &mbox
->u
.mqe
.un
.post_sgl_pages
;
13825 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
13826 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
13828 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
13829 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
13830 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
13831 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
13833 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
13834 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
13835 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
13836 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
13837 if (!phba
->sli4_hba
.intr_enable
)
13838 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13840 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13841 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13843 /* The IOCTL status is embedded in the mailbox subheader. */
13844 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
13845 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13846 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13847 if (rc
!= MBX_TIMEOUT
)
13848 mempool_free(mbox
, phba
->mbox_mem_pool
);
13849 if (shdr_status
|| shdr_add_status
|| rc
) {
13850 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13851 "2511 POST_SGL mailbox failed with "
13852 "status x%x add_status x%x, mbx status x%x\n",
13853 shdr_status
, shdr_add_status
, rc
);
13860 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13861 * @phba: pointer to lpfc hba data structure.
13863 * This routine is invoked to post rpi header templates to the
13864 * HBA consistent with the SLI-4 interface spec. This routine
13865 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13866 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13869 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13870 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13873 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13878 * Fetch the next logical xri. Because this index is logical,
13879 * the driver starts at 0 each time.
13881 spin_lock_irq(&phba
->hbalock
);
13882 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13883 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13884 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13885 spin_unlock_irq(&phba
->hbalock
);
13888 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13889 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13891 spin_unlock_irq(&phba
->hbalock
);
13896 * lpfc_sli4_free_xri - Release an xri for reuse.
13897 * @phba: pointer to lpfc hba data structure.
13899 * This routine is invoked to release an xri to the pool of
13900 * available rpis maintained by the driver.
13903 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13905 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13906 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13911 * lpfc_sli4_free_xri - Release an xri for reuse.
13912 * @phba: pointer to lpfc hba data structure.
13914 * This routine is invoked to release an xri to the pool of
13915 * available rpis maintained by the driver.
13918 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13920 spin_lock_irq(&phba
->hbalock
);
13921 __lpfc_sli4_free_xri(phba
, xri
);
13922 spin_unlock_irq(&phba
->hbalock
);
13926 * lpfc_sli4_next_xritag - Get an xritag for the io
13927 * @phba: Pointer to HBA context object.
13929 * This function gets an xritag for the iocb. If there is no unused xritag
13930 * it will return 0xffff.
13931 * The function returns the allocated xritag if successful, else returns zero.
13932 * Zero is not a valid xritag.
13933 * The caller is not required to hold any lock.
13936 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13938 uint16_t xri_index
;
13940 xri_index
= lpfc_sli4_alloc_xri(phba
);
13941 if (xri_index
== NO_XRI
)
13942 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13943 "2004 Failed to allocate XRI.last XRITAG is %d"
13944 " Max XRI is %d, Used XRI is %d\n",
13946 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13947 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13952 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13953 * @phba: pointer to lpfc hba data structure.
13954 * @post_sgl_list: pointer to els sgl entry list.
13955 * @count: number of els sgl entries on the list.
13957 * This routine is invoked to post a block of driver's sgl pages to the
13958 * HBA using non-embedded mailbox command. No Lock is held. This routine
13959 * is only called when the driver is loading and after all IO has been
13963 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
13964 struct list_head
*post_sgl_list
,
13967 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
13968 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13969 struct sgl_page_pairs
*sgl_pg_pairs
;
13971 LPFC_MBOXQ_t
*mbox
;
13972 uint32_t reqlen
, alloclen
, pg_pairs
;
13974 uint16_t xritag_start
= 0;
13976 uint32_t shdr_status
, shdr_add_status
;
13977 union lpfc_sli4_cfg_shdr
*shdr
;
13979 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13980 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13981 if (reqlen
> SLI4_PAGE_SIZE
) {
13982 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13983 "2559 Block sgl registration required DMA "
13984 "size (%d) great than a page\n", reqlen
);
13987 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13991 /* Allocate DMA memory and set up the non-embedded mailbox command */
13992 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13993 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13994 LPFC_SLI4_MBX_NEMBED
);
13996 if (alloclen
< reqlen
) {
13997 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13998 "0285 Allocated DMA memory size (%d) is "
13999 "less than the requested DMA memory "
14000 "size (%d)\n", alloclen
, reqlen
);
14001 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14004 /* Set up the SGL pages in the non-embedded DMA pages */
14005 viraddr
= mbox
->sge_array
->addr
[0];
14006 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
14007 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
14010 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
14011 /* Set up the sge entry */
14012 sgl_pg_pairs
->sgl_pg0_addr_lo
=
14013 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
14014 sgl_pg_pairs
->sgl_pg0_addr_hi
=
14015 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
14016 sgl_pg_pairs
->sgl_pg1_addr_lo
=
14017 cpu_to_le32(putPaddrLow(0));
14018 sgl_pg_pairs
->sgl_pg1_addr_hi
=
14019 cpu_to_le32(putPaddrHigh(0));
14021 /* Keep the first xritag on the list */
14023 xritag_start
= sglq_entry
->sli4_xritag
;
14028 /* Complete initialization and perform endian conversion. */
14029 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
14030 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
14031 sgl
->word0
= cpu_to_le32(sgl
->word0
);
14032 if (!phba
->sli4_hba
.intr_enable
)
14033 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14035 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14036 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14038 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
14039 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14040 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14041 if (rc
!= MBX_TIMEOUT
)
14042 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14043 if (shdr_status
|| shdr_add_status
|| rc
) {
14044 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14045 "2513 POST_SGL_BLOCK mailbox command failed "
14046 "status x%x add_status x%x mbx status x%x\n",
14047 shdr_status
, shdr_add_status
, rc
);
14054 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
14055 * @phba: pointer to lpfc hba data structure.
14056 * @sblist: pointer to scsi buffer list.
14057 * @count: number of scsi buffers on the list.
14059 * This routine is invoked to post a block of @count scsi sgl pages from a
14060 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
14065 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
14066 struct list_head
*sblist
,
14069 struct lpfc_scsi_buf
*psb
;
14070 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
14071 struct sgl_page_pairs
*sgl_pg_pairs
;
14073 LPFC_MBOXQ_t
*mbox
;
14074 uint32_t reqlen
, alloclen
, pg_pairs
;
14076 uint16_t xritag_start
= 0;
14078 uint32_t shdr_status
, shdr_add_status
;
14079 dma_addr_t pdma_phys_bpl1
;
14080 union lpfc_sli4_cfg_shdr
*shdr
;
14082 /* Calculate the requested length of the dma memory */
14083 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
14084 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
14085 if (reqlen
> SLI4_PAGE_SIZE
) {
14086 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
14087 "0217 Block sgl registration required DMA "
14088 "size (%d) great than a page\n", reqlen
);
14091 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14093 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14094 "0283 Failed to allocate mbox cmd memory\n");
14098 /* Allocate DMA memory and set up the non-embedded mailbox command */
14099 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14100 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
14101 LPFC_SLI4_MBX_NEMBED
);
14103 if (alloclen
< reqlen
) {
14104 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14105 "2561 Allocated DMA memory size (%d) is "
14106 "less than the requested DMA memory "
14107 "size (%d)\n", alloclen
, reqlen
);
14108 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14112 /* Get the first SGE entry from the non-embedded DMA memory */
14113 viraddr
= mbox
->sge_array
->addr
[0];
14115 /* Set up the SGL pages in the non-embedded DMA pages */
14116 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
14117 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
14120 list_for_each_entry(psb
, sblist
, list
) {
14121 /* Set up the sge entry */
14122 sgl_pg_pairs
->sgl_pg0_addr_lo
=
14123 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
14124 sgl_pg_pairs
->sgl_pg0_addr_hi
=
14125 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
14126 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
14127 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
14129 pdma_phys_bpl1
= 0;
14130 sgl_pg_pairs
->sgl_pg1_addr_lo
=
14131 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
14132 sgl_pg_pairs
->sgl_pg1_addr_hi
=
14133 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
14134 /* Keep the first xritag on the list */
14136 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
14140 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
14141 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
14142 /* Perform endian conversion if necessary */
14143 sgl
->word0
= cpu_to_le32(sgl
->word0
);
14145 if (!phba
->sli4_hba
.intr_enable
)
14146 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
14148 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
14149 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
14151 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
14152 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14153 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14154 if (rc
!= MBX_TIMEOUT
)
14155 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
14156 if (shdr_status
|| shdr_add_status
|| rc
) {
14157 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14158 "2564 POST_SGL_BLOCK mailbox command failed "
14159 "status x%x add_status x%x mbx status x%x\n",
14160 shdr_status
, shdr_add_status
, rc
);
14167 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
14168 * @phba: pointer to lpfc_hba struct that the frame was received on
14169 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14171 * This function checks the fields in the @fc_hdr to see if the FC frame is a
14172 * valid type of frame that the LPFC driver will handle. This function will
14173 * return a zero if the frame is a valid frame or a non zero value when the
14174 * frame does not pass the check.
14177 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
14179 /* make rctl_names static to save stack space */
14180 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
14181 char *type_names
[] = FC_TYPE_NAMES_INIT
;
14182 struct fc_vft_header
*fc_vft_hdr
;
14183 uint32_t *header
= (uint32_t *) fc_hdr
;
14185 switch (fc_hdr
->fh_r_ctl
) {
14186 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
14187 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
14188 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
14189 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
14190 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
14191 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
14192 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
14193 case FC_RCTL_DD_CMD_STATUS
: /* command status */
14194 case FC_RCTL_ELS_REQ
: /* extended link services request */
14195 case FC_RCTL_ELS_REP
: /* extended link services reply */
14196 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
14197 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
14198 case FC_RCTL_BA_NOP
: /* basic link service NOP */
14199 case FC_RCTL_BA_ABTS
: /* basic link service abort */
14200 case FC_RCTL_BA_RMC
: /* remove connection */
14201 case FC_RCTL_BA_ACC
: /* basic accept */
14202 case FC_RCTL_BA_RJT
: /* basic reject */
14203 case FC_RCTL_BA_PRMT
:
14204 case FC_RCTL_ACK_1
: /* acknowledge_1 */
14205 case FC_RCTL_ACK_0
: /* acknowledge_0 */
14206 case FC_RCTL_P_RJT
: /* port reject */
14207 case FC_RCTL_F_RJT
: /* fabric reject */
14208 case FC_RCTL_P_BSY
: /* port busy */
14209 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
14210 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
14211 case FC_RCTL_LCR
: /* link credit reset */
14212 case FC_RCTL_END
: /* end */
14214 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
14215 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14216 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
14217 return lpfc_fc_frame_check(phba
, fc_hdr
);
14221 switch (fc_hdr
->fh_type
) {
14233 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
14234 "2538 Received frame rctl:%s (x%x), type:%s (x%x), "
14235 "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
14236 rctl_names
[fc_hdr
->fh_r_ctl
], fc_hdr
->fh_r_ctl
,
14237 type_names
[fc_hdr
->fh_type
], fc_hdr
->fh_type
,
14238 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
14239 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
14240 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]),
14241 be32_to_cpu(header
[6]));
14244 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
14245 "2539 Dropped frame rctl:%s type:%s\n",
14246 rctl_names
[fc_hdr
->fh_r_ctl
],
14247 type_names
[fc_hdr
->fh_type
]);
14252 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
14253 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14255 * This function processes the FC header to retrieve the VFI from the VF
14256 * header, if one exists. This function will return the VFI if one exists
14257 * or 0 if no VSAN Header exists.
14260 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
14262 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14264 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
14266 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
14270 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
14271 * @phba: Pointer to the HBA structure to search for the vport on
14272 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14273 * @fcfi: The FC Fabric ID that the frame came from
14275 * This function searches the @phba for a vport that matches the content of the
14276 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
14277 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
14278 * returns the matching vport pointer or NULL if unable to match frame to a
14281 static struct lpfc_vport
*
14282 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
14285 struct lpfc_vport
**vports
;
14286 struct lpfc_vport
*vport
= NULL
;
14288 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
14289 fc_hdr
->fh_d_id
[1] << 8 |
14290 fc_hdr
->fh_d_id
[2]);
14292 if (did
== Fabric_DID
)
14293 return phba
->pport
;
14294 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
14295 !(phba
->link_state
== LPFC_HBA_READY
))
14296 return phba
->pport
;
14298 vports
= lpfc_create_vport_work_array(phba
);
14299 if (vports
!= NULL
)
14300 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
14301 if (phba
->fcf
.fcfi
== fcfi
&&
14302 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
14303 vports
[i
]->fc_myDID
== did
) {
14308 lpfc_destroy_vport_work_array(phba
, vports
);
14313 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
14314 * @vport: The vport to work on.
14316 * This function updates the receive sequence time stamp for this vport. The
14317 * receive sequence time stamp indicates the time that the last frame of the
14318 * the sequence that has been idle for the longest amount of time was received.
14319 * the driver uses this time stamp to indicate if any received sequences have
14323 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
14325 struct lpfc_dmabuf
*h_buf
;
14326 struct hbq_dmabuf
*dmabuf
= NULL
;
14328 /* get the oldest sequence on the rcv list */
14329 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
14330 struct lpfc_dmabuf
, list
);
14333 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14334 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
14338 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
14339 * @vport: The vport that the received sequences were sent to.
14341 * This function cleans up all outstanding received sequences. This is called
14342 * by the driver when a link event or user action invalidates all the received
14346 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
14348 struct lpfc_dmabuf
*h_buf
, *hnext
;
14349 struct lpfc_dmabuf
*d_buf
, *dnext
;
14350 struct hbq_dmabuf
*dmabuf
= NULL
;
14352 /* start with the oldest sequence on the rcv list */
14353 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
14354 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14355 list_del_init(&dmabuf
->hbuf
.list
);
14356 list_for_each_entry_safe(d_buf
, dnext
,
14357 &dmabuf
->dbuf
.list
, list
) {
14358 list_del_init(&d_buf
->list
);
14359 lpfc_in_buf_free(vport
->phba
, d_buf
);
14361 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
14366 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
14367 * @vport: The vport that the received sequences were sent to.
14369 * This function determines whether any received sequences have timed out by
14370 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
14371 * indicates that there is at least one timed out sequence this routine will
14372 * go through the received sequences one at a time from most inactive to most
14373 * active to determine which ones need to be cleaned up. Once it has determined
14374 * that a sequence needs to be cleaned up it will simply free up the resources
14375 * without sending an abort.
14378 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
14380 struct lpfc_dmabuf
*h_buf
, *hnext
;
14381 struct lpfc_dmabuf
*d_buf
, *dnext
;
14382 struct hbq_dmabuf
*dmabuf
= NULL
;
14383 unsigned long timeout
;
14384 int abort_count
= 0;
14386 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
14387 vport
->rcv_buffer_time_stamp
);
14388 if (list_empty(&vport
->rcv_buffer_list
) ||
14389 time_before(jiffies
, timeout
))
14391 /* start with the oldest sequence on the rcv list */
14392 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
14393 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14394 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
14395 dmabuf
->time_stamp
);
14396 if (time_before(jiffies
, timeout
))
14399 list_del_init(&dmabuf
->hbuf
.list
);
14400 list_for_each_entry_safe(d_buf
, dnext
,
14401 &dmabuf
->dbuf
.list
, list
) {
14402 list_del_init(&d_buf
->list
);
14403 lpfc_in_buf_free(vport
->phba
, d_buf
);
14405 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
14408 lpfc_update_rcv_time_stamp(vport
);
14412 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
14413 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
14415 * This function searches through the existing incomplete sequences that have
14416 * been sent to this @vport. If the frame matches one of the incomplete
14417 * sequences then the dbuf in the @dmabuf is added to the list of frames that
14418 * make up that sequence. If no sequence is found that matches this frame then
14419 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
14420 * This function returns a pointer to the first dmabuf in the sequence list that
14421 * the frame was linked to.
14423 static struct hbq_dmabuf
*
14424 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
14426 struct fc_frame_header
*new_hdr
;
14427 struct fc_frame_header
*temp_hdr
;
14428 struct lpfc_dmabuf
*d_buf
;
14429 struct lpfc_dmabuf
*h_buf
;
14430 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14431 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
14433 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14434 dmabuf
->time_stamp
= jiffies
;
14435 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14436 /* Use the hdr_buf to find the sequence that this frame belongs to */
14437 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14438 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14439 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14440 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14441 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14443 /* found a pending sequence that matches this frame */
14444 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14449 * This indicates first frame received for this sequence.
14450 * Queue the buffer on the vport's rcv_buffer_list.
14452 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14453 lpfc_update_rcv_time_stamp(vport
);
14456 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
14457 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
14458 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14459 list_del_init(&seq_dmabuf
->hbuf
.list
);
14460 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14461 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14462 lpfc_update_rcv_time_stamp(vport
);
14465 /* move this sequence to the tail to indicate a young sequence */
14466 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14467 seq_dmabuf
->time_stamp
= jiffies
;
14468 lpfc_update_rcv_time_stamp(vport
);
14469 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
14470 temp_hdr
= dmabuf
->hbuf
.virt
;
14471 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14474 /* find the correct place in the sequence to insert this frame */
14475 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14476 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14477 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
14479 * If the frame's sequence count is greater than the frame on
14480 * the list then insert the frame right after this frame
14482 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
14483 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14484 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
14492 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
14493 * @vport: pointer to a vitural port
14494 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14496 * This function tries to abort from the partially assembed sequence, described
14497 * by the information from basic abbort @dmabuf. It checks to see whether such
14498 * partially assembled sequence held by the driver. If so, it shall free up all
14499 * the frames from the partially assembled sequence.
14502 * true -- if there is matching partially assembled sequence present and all
14503 * the frames freed with the sequence;
14504 * false -- if there is no matching partially assembled sequence present so
14505 * nothing got aborted in the lower layer driver
14508 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
14509 struct hbq_dmabuf
*dmabuf
)
14511 struct fc_frame_header
*new_hdr
;
14512 struct fc_frame_header
*temp_hdr
;
14513 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
14514 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14516 /* Use the hdr_buf to find the sequence that matches this frame */
14517 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14518 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
14519 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14520 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14521 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14522 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14523 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14524 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14526 /* found a pending sequence that matches this frame */
14527 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14531 /* Free up all the frames from the partially assembled sequence */
14533 list_for_each_entry_safe(d_buf
, n_buf
,
14534 &seq_dmabuf
->dbuf
.list
, list
) {
14535 list_del_init(&d_buf
->list
);
14536 lpfc_in_buf_free(vport
->phba
, d_buf
);
14544 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
14545 * @vport: pointer to a vitural port
14546 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14548 * This function tries to abort from the assembed sequence from upper level
14549 * protocol, described by the information from basic abbort @dmabuf. It
14550 * checks to see whether such pending context exists at upper level protocol.
14551 * If so, it shall clean up the pending context.
14554 * true -- if there is matching pending context of the sequence cleaned
14556 * false -- if there is no matching pending context of the sequence present
14560 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
14562 struct lpfc_hba
*phba
= vport
->phba
;
14565 /* Accepting abort at ulp with SLI4 only */
14566 if (phba
->sli_rev
< LPFC_SLI_REV4
)
14569 /* Register all caring upper level protocols to attend abort */
14570 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
14578 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14579 * @phba: Pointer to HBA context object.
14580 * @cmd_iocbq: pointer to the command iocbq structure.
14581 * @rsp_iocbq: pointer to the response iocbq structure.
14583 * This function handles the sequence abort response iocb command complete
14584 * event. It properly releases the memory allocated to the sequence abort
14588 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
14589 struct lpfc_iocbq
*cmd_iocbq
,
14590 struct lpfc_iocbq
*rsp_iocbq
)
14592 struct lpfc_nodelist
*ndlp
;
14595 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
14596 lpfc_nlp_put(ndlp
);
14597 lpfc_nlp_not_used(ndlp
);
14598 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
14601 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14602 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
14603 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14604 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14605 rsp_iocbq
->iocb
.ulpStatus
,
14606 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
14610 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14611 * @phba: Pointer to HBA context object.
14612 * @xri: xri id in transaction.
14614 * This function validates the xri maps to the known range of XRIs allocated an
14615 * used by the driver.
14618 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
14623 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
14624 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
14631 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14632 * @phba: Pointer to HBA context object.
14633 * @fc_hdr: pointer to a FC frame header.
14635 * This function sends a basic response to a previous unsol sequence abort
14636 * event after aborting the sequence handling.
14639 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
14640 struct fc_frame_header
*fc_hdr
, bool aborted
)
14642 struct lpfc_hba
*phba
= vport
->phba
;
14643 struct lpfc_iocbq
*ctiocb
= NULL
;
14644 struct lpfc_nodelist
*ndlp
;
14645 uint16_t oxid
, rxid
, xri
, lxri
;
14646 uint32_t sid
, fctl
;
14650 if (!lpfc_is_link_up(phba
))
14653 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14654 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
14655 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
14657 ndlp
= lpfc_findnode_did(vport
, sid
);
14659 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
14661 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
14662 "1268 Failed to allocate ndlp for "
14663 "oxid:x%x SID:x%x\n", oxid
, sid
);
14666 lpfc_nlp_init(vport
, ndlp
, sid
);
14667 /* Put ndlp onto pport node list */
14668 lpfc_enqueue_node(vport
, ndlp
);
14669 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
14670 /* re-setup ndlp without removing from node list */
14671 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
14673 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
14674 "3275 Failed to active ndlp found "
14675 "for oxid:x%x SID:x%x\n", oxid
, sid
);
14680 /* Allocate buffer for rsp iocb */
14681 ctiocb
= lpfc_sli_get_iocbq(phba
);
14685 /* Extract the F_CTL field from FC_HDR */
14686 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
14688 icmd
= &ctiocb
->iocb
;
14689 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
14690 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
14691 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
14692 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
14693 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
14695 /* Fill in the rest of iocb fields */
14696 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
14697 icmd
->ulpBdeCount
= 0;
14699 icmd
->ulpClass
= CLASS3
;
14700 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
14701 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
14703 ctiocb
->iocb_cmpl
= NULL
;
14704 ctiocb
->vport
= phba
->pport
;
14705 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
14706 ctiocb
->sli4_lxritag
= NO_XRI
;
14707 ctiocb
->sli4_xritag
= NO_XRI
;
14709 if (fctl
& FC_FC_EX_CTX
)
14710 /* Exchange responder sent the abort so we
14716 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
14717 if (lxri
!= NO_XRI
)
14718 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
14719 (xri
== oxid
) ? rxid
: oxid
, 0);
14720 /* For BA_ABTS from exchange responder, if the logical xri with
14721 * the oxid maps to the FCP XRI range, the port no longer has
14722 * that exchange context, send a BLS_RJT. Override the IOCB for
14725 if ((fctl
& FC_FC_EX_CTX
) &&
14726 (lxri
> lpfc_sli4_get_els_iocb_cnt(phba
))) {
14727 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14728 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14729 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14730 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14733 /* If BA_ABTS failed to abort a partially assembled receive sequence,
14734 * the driver no longer has that exchange, send a BLS_RJT. Override
14735 * the IOCB for a BA_RJT.
14737 if (aborted
== false) {
14738 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14739 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14740 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14741 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14744 if (fctl
& FC_FC_EX_CTX
) {
14745 /* ABTS sent by responder to CT exchange, construction
14746 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14747 * field and RX_ID from ABTS for RX_ID field.
14749 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14751 /* ABTS sent by initiator to CT exchange, construction
14752 * of BA_ACC will need to allocate a new XRI as for the
14755 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14757 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14758 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14760 /* Xmit CT abts response on exchange <xid> */
14761 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
14762 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14763 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14765 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14766 if (rc
== IOCB_ERROR
) {
14767 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
14768 "2925 Failed to issue CT ABTS RSP x%x on "
14769 "xri x%x, Data x%x\n",
14770 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14772 lpfc_nlp_put(ndlp
);
14773 ctiocb
->context1
= NULL
;
14774 lpfc_sli_release_iocbq(phba
, ctiocb
);
14779 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14780 * @vport: Pointer to the vport on which this sequence was received
14781 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14783 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14784 * receive sequence is only partially assembed by the driver, it shall abort
14785 * the partially assembled frames for the sequence. Otherwise, if the
14786 * unsolicited receive sequence has been completely assembled and passed to
14787 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14788 * unsolicited sequence has been aborted. After that, it will issue a basic
14789 * accept to accept the abort.
14792 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14793 struct hbq_dmabuf
*dmabuf
)
14795 struct lpfc_hba
*phba
= vport
->phba
;
14796 struct fc_frame_header fc_hdr
;
14800 /* Make a copy of fc_hdr before the dmabuf being released */
14801 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14802 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14804 if (fctl
& FC_FC_EX_CTX
) {
14805 /* ABTS by responder to exchange, no cleanup needed */
14808 /* ABTS by initiator to exchange, need to do cleanup */
14809 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14810 if (aborted
== false)
14811 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
14813 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14815 /* Respond with BA_ACC or BA_RJT accordingly */
14816 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
14820 * lpfc_seq_complete - Indicates if a sequence is complete
14821 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14823 * This function checks the sequence, starting with the frame described by
14824 * @dmabuf, to see if all the frames associated with this sequence are present.
14825 * the frames associated with this sequence are linked to the @dmabuf using the
14826 * dbuf list. This function looks for two major things. 1) That the first frame
14827 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14828 * set. 3) That there are no holes in the sequence count. The function will
14829 * return 1 when the sequence is complete, otherwise it will return 0.
14832 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14834 struct fc_frame_header
*hdr
;
14835 struct lpfc_dmabuf
*d_buf
;
14836 struct hbq_dmabuf
*seq_dmabuf
;
14840 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14841 /* make sure first fame of sequence has a sequence count of zero */
14842 if (hdr
->fh_seq_cnt
!= seq_count
)
14844 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14845 hdr
->fh_f_ctl
[1] << 8 |
14847 /* If last frame of sequence we can return success. */
14848 if (fctl
& FC_FC_END_SEQ
)
14850 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14851 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14852 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14853 /* If there is a hole in the sequence count then fail. */
14854 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14856 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14857 hdr
->fh_f_ctl
[1] << 8 |
14859 /* If last frame of sequence we can return success. */
14860 if (fctl
& FC_FC_END_SEQ
)
14867 * lpfc_prep_seq - Prep sequence for ULP processing
14868 * @vport: Pointer to the vport on which this sequence was received
14869 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14871 * This function takes a sequence, described by a list of frames, and creates
14872 * a list of iocbq structures to describe the sequence. This iocbq list will be
14873 * used to issue to the generic unsolicited sequence handler. This routine
14874 * returns a pointer to the first iocbq in the list. If the function is unable
14875 * to allocate an iocbq then it throw out the received frames that were not
14876 * able to be described and return a pointer to the first iocbq. If unable to
14877 * allocate any iocbqs (including the first) this function will return NULL.
14879 static struct lpfc_iocbq
*
14880 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14882 struct hbq_dmabuf
*hbq_buf
;
14883 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14884 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14885 struct fc_frame_header
*fc_hdr
;
14887 uint32_t len
, tot_len
;
14888 struct ulp_bde64
*pbde
;
14890 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14891 /* remove from receive buffer list */
14892 list_del_init(&seq_dmabuf
->hbuf
.list
);
14893 lpfc_update_rcv_time_stamp(vport
);
14894 /* get the Remote Port's SID */
14895 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14897 /* Get an iocbq struct to fill in. */
14898 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14900 /* Initialize the first IOCB. */
14901 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14902 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14904 /* Check FC Header to see what TYPE of frame we are rcv'ing */
14905 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
14906 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
14907 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
14908 sli4_did_from_fc_hdr(fc_hdr
);
14909 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
14911 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14912 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14913 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14914 be16_to_cpu(fc_hdr
->fh_ox_id
);
14915 /* iocbq is prepped for internal consumption. Physical vpi. */
14916 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14917 vport
->phba
->vpi_ids
[vport
->vpi
];
14918 /* put the first buffer into the first IOCBq */
14919 tot_len
= bf_get(lpfc_rcqe_length
,
14920 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14922 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14923 first_iocbq
->context3
= NULL
;
14924 first_iocbq
->iocb
.ulpBdeCount
= 1;
14925 if (tot_len
> LPFC_DATA_BUF_SIZE
)
14926 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14927 LPFC_DATA_BUF_SIZE
;
14929 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= tot_len
;
14931 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14933 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14935 iocbq
= first_iocbq
;
14937 * Each IOCBq can have two Buffers assigned, so go through the list
14938 * of buffers for this sequence and save two buffers in each IOCBq
14940 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14942 lpfc_in_buf_free(vport
->phba
, d_buf
);
14945 if (!iocbq
->context3
) {
14946 iocbq
->context3
= d_buf
;
14947 iocbq
->iocb
.ulpBdeCount
++;
14948 /* We need to get the size out of the right CQE */
14949 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14950 len
= bf_get(lpfc_rcqe_length
,
14951 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14952 pbde
= (struct ulp_bde64
*)
14953 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14954 if (len
> LPFC_DATA_BUF_SIZE
)
14955 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14957 pbde
->tus
.f
.bdeSize
= len
;
14959 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14962 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14965 first_iocbq
->iocb
.ulpStatus
=
14966 IOSTAT_FCP_RSP_ERROR
;
14967 first_iocbq
->iocb
.un
.ulpWord
[4] =
14968 IOERR_NO_RESOURCES
;
14970 lpfc_in_buf_free(vport
->phba
, d_buf
);
14973 /* We need to get the size out of the right CQE */
14974 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14975 len
= bf_get(lpfc_rcqe_length
,
14976 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14977 iocbq
->context2
= d_buf
;
14978 iocbq
->context3
= NULL
;
14979 iocbq
->iocb
.ulpBdeCount
= 1;
14980 if (len
> LPFC_DATA_BUF_SIZE
)
14981 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14982 LPFC_DATA_BUF_SIZE
;
14984 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
= len
;
14987 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14989 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14990 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14993 return first_iocbq
;
14997 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14998 struct hbq_dmabuf
*seq_dmabuf
)
15000 struct fc_frame_header
*fc_hdr
;
15001 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
15002 struct lpfc_hba
*phba
= vport
->phba
;
15004 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
15005 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
15007 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15008 "2707 Ring %d handler: Failed to allocate "
15009 "iocb Rctl x%x Type x%x received\n",
15011 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
15014 if (!lpfc_complete_unsol_iocb(phba
,
15015 &phba
->sli
.ring
[LPFC_ELS_RING
],
15016 iocbq
, fc_hdr
->fh_r_ctl
,
15018 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15019 "2540 Ring %d handler: unexpected Rctl "
15020 "x%x Type x%x received\n",
15022 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
15024 /* Free iocb created in lpfc_prep_seq */
15025 list_for_each_entry_safe(curr_iocb
, next_iocb
,
15026 &iocbq
->list
, list
) {
15027 list_del_init(&curr_iocb
->list
);
15028 lpfc_sli_release_iocbq(phba
, curr_iocb
);
15030 lpfc_sli_release_iocbq(phba
, iocbq
);
15034 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
15035 * @phba: Pointer to HBA context object.
15037 * This function is called with no lock held. This function processes all
15038 * the received buffers and gives it to upper layers when a received buffer
15039 * indicates that it is the final frame in the sequence. The interrupt
15040 * service routine processes received buffers at interrupt contexts and adds
15041 * received dma buffers to the rb_pend_list queue and signals the worker thread.
15042 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
15043 * appropriate receive function when the final frame in a sequence is received.
15046 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
15047 struct hbq_dmabuf
*dmabuf
)
15049 struct hbq_dmabuf
*seq_dmabuf
;
15050 struct fc_frame_header
*fc_hdr
;
15051 struct lpfc_vport
*vport
;
15055 /* Process each received buffer */
15056 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
15057 /* check to see if this a valid type of frame */
15058 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
15059 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15062 if ((bf_get(lpfc_cqe_code
,
15063 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
15064 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
15065 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15067 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
15068 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
15070 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
15072 /* throw out the frame */
15073 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15077 /* d_id this frame is directed to */
15078 did
= sli4_did_from_fc_hdr(fc_hdr
);
15080 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
15081 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
15082 (did
!= Fabric_DID
)) {
15084 * Throw out the frame if we are not pt2pt.
15085 * The pt2pt protocol allows for discovery frames
15086 * to be received without a registered VPI.
15088 if (!(vport
->fc_flag
& FC_PT2PT
) ||
15089 (phba
->link_state
== LPFC_HBA_READY
)) {
15090 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15095 /* Handle the basic abort sequence (BA_ABTS) event */
15096 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
15097 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
15101 /* Link this frame */
15102 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
15104 /* unable to add frame to vport - throw it out */
15105 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
15108 /* If not last frame in sequence continue processing frames. */
15109 if (!lpfc_seq_complete(seq_dmabuf
))
15112 /* Send the complete sequence to the upper layer protocol */
15113 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
15117 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
15118 * @phba: pointer to lpfc hba data structure.
15120 * This routine is invoked to post rpi header templates to the
15121 * HBA consistent with the SLI-4 interface spec. This routine
15122 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15123 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15125 * This routine does not require any locks. It's usage is expected
15126 * to be driver load or reset recovery when the driver is
15131 * -EIO - The mailbox failed to complete successfully.
15132 * When this error occurs, the driver is not guaranteed
15133 * to have any rpi regions posted to the device and
15134 * must either attempt to repost the regions or take a
15138 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
15140 struct lpfc_rpi_hdr
*rpi_page
;
15144 /* SLI4 ports that support extents do not require RPI headers. */
15145 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
15147 if (phba
->sli4_hba
.extents_in_use
)
15150 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
15152 * Assign the rpi headers a physical rpi only if the driver
15153 * has not initialized those resources. A port reset only
15154 * needs the headers posted.
15156 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
15158 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15160 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
15161 if (rc
!= MBX_SUCCESS
) {
15162 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15163 "2008 Error %d posting all rpi "
15171 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
15172 LPFC_RPI_RSRC_RDY
);
15177 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
15178 * @phba: pointer to lpfc hba data structure.
15179 * @rpi_page: pointer to the rpi memory region.
15181 * This routine is invoked to post a single rpi header to the
15182 * HBA consistent with the SLI-4 interface spec. This memory region
15183 * maps up to 64 rpi context regions.
15187 * -ENOMEM - No available memory
15188 * -EIO - The mailbox failed to complete successfully.
15191 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
15193 LPFC_MBOXQ_t
*mboxq
;
15194 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
15196 uint32_t shdr_status
, shdr_add_status
;
15197 union lpfc_sli4_cfg_shdr
*shdr
;
15199 /* SLI4 ports that support extents do not require RPI headers. */
15200 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
15202 if (phba
->sli4_hba
.extents_in_use
)
15205 /* The port is notified of the header region via a mailbox command. */
15206 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15208 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15209 "2001 Unable to allocate memory for issuing "
15210 "SLI_CONFIG_SPECIAL mailbox command\n");
15214 /* Post all rpi memory regions to the port. */
15215 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
15216 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15217 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
15218 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
15219 sizeof(struct lpfc_sli4_cfg_mhdr
),
15220 LPFC_SLI4_MBX_EMBED
);
15223 /* Post the physical rpi to the port for this rpi header. */
15224 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
15225 rpi_page
->start_rpi
);
15226 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
15227 hdr_tmpl
, rpi_page
->page_count
);
15229 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
15230 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
15231 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15232 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
15233 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15234 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15235 if (rc
!= MBX_TIMEOUT
)
15236 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15237 if (shdr_status
|| shdr_add_status
|| rc
) {
15238 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15239 "2514 POST_RPI_HDR mailbox failed with "
15240 "status x%x add_status x%x, mbx status x%x\n",
15241 shdr_status
, shdr_add_status
, rc
);
15248 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
15249 * @phba: pointer to lpfc hba data structure.
15251 * This routine is invoked to post rpi header templates to the
15252 * HBA consistent with the SLI-4 interface spec. This routine
15253 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
15254 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
15257 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
15258 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
15261 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
15264 uint16_t max_rpi
, rpi_limit
;
15265 uint16_t rpi_remaining
, lrpi
= 0;
15266 struct lpfc_rpi_hdr
*rpi_hdr
;
15267 unsigned long iflag
;
15269 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
15270 rpi_limit
= phba
->sli4_hba
.next_rpi
;
15273 * Fetch the next logical rpi. Because this index is logical,
15274 * the driver starts at 0 each time.
15276 spin_lock_irqsave(&phba
->hbalock
, iflag
);
15277 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
15278 if (rpi
>= rpi_limit
)
15279 rpi
= LPFC_RPI_ALLOC_ERROR
;
15281 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
15282 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
15283 phba
->sli4_hba
.rpi_count
++;
15287 * Don't try to allocate more rpi header regions if the device limit
15288 * has been exhausted.
15290 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
15291 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
15292 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15297 * RPI header postings are not required for SLI4 ports capable of
15300 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
15301 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15306 * If the driver is running low on rpi resources, allocate another
15307 * page now. Note that the next_rpi value is used because
15308 * it represents how many are actually in use whereas max_rpi notes
15309 * how many are supported max by the device.
15311 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
15312 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
15313 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
15314 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
15316 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15317 "2002 Error Could not grow rpi "
15320 lrpi
= rpi_hdr
->start_rpi
;
15321 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15322 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
15330 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15331 * @phba: pointer to lpfc hba data structure.
15333 * This routine is invoked to release an rpi to the pool of
15334 * available rpis maintained by the driver.
15337 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
15339 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
15340 phba
->sli4_hba
.rpi_count
--;
15341 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
15346 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15347 * @phba: pointer to lpfc hba data structure.
15349 * This routine is invoked to release an rpi to the pool of
15350 * available rpis maintained by the driver.
15353 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
15355 spin_lock_irq(&phba
->hbalock
);
15356 __lpfc_sli4_free_rpi(phba
, rpi
);
15357 spin_unlock_irq(&phba
->hbalock
);
15361 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
15362 * @phba: pointer to lpfc hba data structure.
15364 * This routine is invoked to remove the memory region that
15365 * provided rpi via a bitmask.
15368 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
15370 kfree(phba
->sli4_hba
.rpi_bmask
);
15371 kfree(phba
->sli4_hba
.rpi_ids
);
15372 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
15376 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
15377 * @phba: pointer to lpfc hba data structure.
15379 * This routine is invoked to remove the memory region that
15380 * provided rpi via a bitmask.
15383 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
15384 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
15386 LPFC_MBOXQ_t
*mboxq
;
15387 struct lpfc_hba
*phba
= ndlp
->phba
;
15390 /* The port is notified of the header region via a mailbox command. */
15391 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15395 /* Post all rpi memory regions to the port. */
15396 lpfc_resume_rpi(mboxq
, ndlp
);
15398 mboxq
->mbox_cmpl
= cmpl
;
15399 mboxq
->context1
= arg
;
15400 mboxq
->context2
= ndlp
;
15402 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15403 mboxq
->vport
= ndlp
->vport
;
15404 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15405 if (rc
== MBX_NOT_FINISHED
) {
15406 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15407 "2010 Resume RPI Mailbox failed "
15408 "status %d, mbxStatus x%x\n", rc
,
15409 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
15410 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15417 * lpfc_sli4_init_vpi - Initialize a vpi with the port
15418 * @vport: Pointer to the vport for which the vpi is being initialized
15420 * This routine is invoked to activate a vpi with the port.
15424 * -Evalue otherwise
15427 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
15429 LPFC_MBOXQ_t
*mboxq
;
15431 int retval
= MBX_SUCCESS
;
15433 struct lpfc_hba
*phba
= vport
->phba
;
15434 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15437 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
15438 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
15439 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
15440 if (rc
!= MBX_SUCCESS
) {
15441 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
15442 "2022 INIT VPI Mailbox failed "
15443 "status %d, mbxStatus x%x\n", rc
,
15444 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
15447 if (rc
!= MBX_TIMEOUT
)
15448 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
15454 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
15455 * @phba: pointer to lpfc hba data structure.
15456 * @mboxq: Pointer to mailbox object.
15458 * This routine is invoked to manually add a single FCF record. The caller
15459 * must pass a completely initialized FCF_Record. This routine takes
15460 * care of the nonembedded mailbox operations.
15463 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
15466 union lpfc_sli4_cfg_shdr
*shdr
;
15467 uint32_t shdr_status
, shdr_add_status
;
15469 virt_addr
= mboxq
->sge_array
->addr
[0];
15470 /* The IOCTL status is embedded in the mailbox subheader. */
15471 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
15472 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15473 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15475 if ((shdr_status
|| shdr_add_status
) &&
15476 (shdr_status
!= STATUS_FCF_IN_USE
))
15477 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15478 "2558 ADD_FCF_RECORD mailbox failed with "
15479 "status x%x add_status x%x\n",
15480 shdr_status
, shdr_add_status
);
15482 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15486 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
15487 * @phba: pointer to lpfc hba data structure.
15488 * @fcf_record: pointer to the initialized fcf record to add.
15490 * This routine is invoked to manually add a single FCF record. The caller
15491 * must pass a completely initialized FCF_Record. This routine takes
15492 * care of the nonembedded mailbox operations.
15495 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
15498 LPFC_MBOXQ_t
*mboxq
;
15501 dma_addr_t phys_addr
;
15502 struct lpfc_mbx_sge sge
;
15503 uint32_t alloc_len
, req_len
;
15506 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15508 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15509 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
15513 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
15516 /* Allocate DMA memory and set up the non-embedded mailbox command */
15517 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15518 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
15519 req_len
, LPFC_SLI4_MBX_NEMBED
);
15520 if (alloc_len
< req_len
) {
15521 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15522 "2523 Allocated DMA memory size (x%x) is "
15523 "less than the requested DMA memory "
15524 "size (x%x)\n", alloc_len
, req_len
);
15525 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15530 * Get the first SGE entry from the non-embedded DMA memory. This
15531 * routine only uses a single SGE.
15533 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
15534 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
15535 virt_addr
= mboxq
->sge_array
->addr
[0];
15537 * Configure the FCF record for FCFI 0. This is the driver's
15538 * hardcoded default and gets used in nonFIP mode.
15540 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
15541 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
15542 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
15545 * Copy the fcf_index and the FCF Record Data. The data starts after
15546 * the FCoE header plus word10. The data copy needs to be endian
15549 bytep
+= sizeof(uint32_t);
15550 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
15551 mboxq
->vport
= phba
->pport
;
15552 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
15553 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15554 if (rc
== MBX_NOT_FINISHED
) {
15555 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15556 "2515 ADD_FCF_RECORD mailbox failed with "
15557 "status 0x%x\n", rc
);
15558 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15567 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
15568 * @phba: pointer to lpfc hba data structure.
15569 * @fcf_record: pointer to the fcf record to write the default data.
15570 * @fcf_index: FCF table entry index.
15572 * This routine is invoked to build the driver's default FCF record. The
15573 * values used are hardcoded. This routine handles memory initialization.
15577 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
15578 struct fcf_record
*fcf_record
,
15579 uint16_t fcf_index
)
15581 memset(fcf_record
, 0, sizeof(struct fcf_record
));
15582 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
15583 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
15584 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
15585 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
15586 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
15587 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
15588 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
15589 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
15590 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
15591 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
15592 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
15593 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
15594 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
15595 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
15596 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
15597 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
15598 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
15599 /* Set the VLAN bit map */
15600 if (phba
->valid_vlan
) {
15601 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
15602 = 1 << (phba
->vlan_id
% 8);
15607 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
15608 * @phba: pointer to lpfc hba data structure.
15609 * @fcf_index: FCF table entry offset.
15611 * This routine is invoked to scan the entire FCF table by reading FCF
15612 * record and processing it one at a time starting from the @fcf_index
15613 * for initial FCF discovery or fast FCF failover rediscovery.
15615 * Return 0 if the mailbox command is submitted successfully, none 0
15619 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15622 LPFC_MBOXQ_t
*mboxq
;
15624 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
15625 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
15626 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15628 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15629 "2000 Failed to allocate mbox for "
15632 goto fail_fcf_scan
;
15634 /* Construct the read FCF record mailbox command */
15635 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15638 goto fail_fcf_scan
;
15640 /* Issue the mailbox command asynchronously */
15641 mboxq
->vport
= phba
->pport
;
15642 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
15644 spin_lock_irq(&phba
->hbalock
);
15645 phba
->hba_flag
|= FCF_TS_INPROG
;
15646 spin_unlock_irq(&phba
->hbalock
);
15648 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15649 if (rc
== MBX_NOT_FINISHED
)
15652 /* Reset eligible FCF count for new scan */
15653 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
15654 phba
->fcf
.eligible_fcf_cnt
= 0;
15660 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15661 /* FCF scan failed, clear FCF_TS_INPROG flag */
15662 spin_lock_irq(&phba
->hbalock
);
15663 phba
->hba_flag
&= ~FCF_TS_INPROG
;
15664 spin_unlock_irq(&phba
->hbalock
);
15670 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15671 * @phba: pointer to lpfc hba data structure.
15672 * @fcf_index: FCF table entry offset.
15674 * This routine is invoked to read an FCF record indicated by @fcf_index
15675 * and to use it for FLOGI roundrobin FCF failover.
15677 * Return 0 if the mailbox command is submitted successfully, none 0
15681 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15684 LPFC_MBOXQ_t
*mboxq
;
15686 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15688 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15689 "2763 Failed to allocate mbox for "
15692 goto fail_fcf_read
;
15694 /* Construct the read FCF record mailbox command */
15695 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15698 goto fail_fcf_read
;
15700 /* Issue the mailbox command asynchronously */
15701 mboxq
->vport
= phba
->pport
;
15702 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
15703 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15704 if (rc
== MBX_NOT_FINISHED
)
15710 if (error
&& mboxq
)
15711 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15716 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15717 * @phba: pointer to lpfc hba data structure.
15718 * @fcf_index: FCF table entry offset.
15720 * This routine is invoked to read an FCF record indicated by @fcf_index to
15721 * determine whether it's eligible for FLOGI roundrobin failover list.
15723 * Return 0 if the mailbox command is submitted successfully, none 0
15727 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15730 LPFC_MBOXQ_t
*mboxq
;
15732 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15734 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15735 "2758 Failed to allocate mbox for "
15738 goto fail_fcf_read
;
15740 /* Construct the read FCF record mailbox command */
15741 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15744 goto fail_fcf_read
;
15746 /* Issue the mailbox command asynchronously */
15747 mboxq
->vport
= phba
->pport
;
15748 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
15749 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15750 if (rc
== MBX_NOT_FINISHED
)
15756 if (error
&& mboxq
)
15757 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15762 * lpfc_check_next_fcf_pri
15763 * phba pointer to the lpfc_hba struct for this port.
15764 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15765 * routine when the rr_bmask is empty. The FCF indecies are put into the
15766 * rr_bmask based on their priority level. Starting from the highest priority
15767 * to the lowest. The most likely FCF candidate will be in the highest
15768 * priority group. When this routine is called it searches the fcf_pri list for
15769 * next lowest priority group and repopulates the rr_bmask with only those
15772 * 1=success 0=failure
15775 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15777 uint16_t next_fcf_pri
;
15778 uint16_t last_index
;
15779 struct lpfc_fcf_pri
*fcf_pri
;
15783 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15784 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15785 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15786 "3060 Last IDX %d\n", last_index
);
15788 /* Verify the priority list has 2 or more entries */
15789 spin_lock_irq(&phba
->hbalock
);
15790 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
15791 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
15792 spin_unlock_irq(&phba
->hbalock
);
15793 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15794 "3061 Last IDX %d\n", last_index
);
15795 return 0; /* Empty rr list */
15797 spin_unlock_irq(&phba
->hbalock
);
15801 * Clear the rr_bmask and set all of the bits that are at this
15804 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15805 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15806 spin_lock_irq(&phba
->hbalock
);
15807 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15808 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15811 * the 1st priority that has not FLOGI failed
15812 * will be the highest.
15815 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15816 spin_unlock_irq(&phba
->hbalock
);
15817 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15818 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15819 fcf_pri
->fcf_rec
.fcf_index
);
15823 spin_lock_irq(&phba
->hbalock
);
15826 * if next_fcf_pri was not set above and the list is not empty then
15827 * we have failed flogis on all of them. So reset flogi failed
15828 * and start at the beginning.
15830 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15831 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15832 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15834 * the 1st priority that has not FLOGI failed
15835 * will be the highest.
15838 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15839 spin_unlock_irq(&phba
->hbalock
);
15840 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15841 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15842 fcf_pri
->fcf_rec
.fcf_index
);
15846 spin_lock_irq(&phba
->hbalock
);
15850 spin_unlock_irq(&phba
->hbalock
);
15855 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15856 * @phba: pointer to lpfc hba data structure.
15858 * This routine is to get the next eligible FCF record index in a round
15859 * robin fashion. If the next eligible FCF record index equals to the
15860 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15861 * shall be returned, otherwise, the next eligible FCF record's index
15862 * shall be returned.
15865 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15867 uint16_t next_fcf_index
;
15870 /* Search start from next bit of currently registered FCF index */
15871 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
15874 /* Determine the next fcf index to check */
15875 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
15876 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15877 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15880 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15881 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15883 * If we have wrapped then we need to clear the bits that
15884 * have been tested so that we can detect when we should
15885 * change the priority level.
15887 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15888 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15892 /* Check roundrobin failover list empty condition */
15893 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15894 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15896 * If next fcf index is not found check if there are lower
15897 * Priority level fcf's in the fcf_priority list.
15898 * Set up the rr_bmask with all of the avaiable fcf bits
15899 * at that level and continue the selection process.
15901 if (lpfc_check_next_fcf_pri_level(phba
))
15902 goto initial_priority
;
15903 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15904 "2844 No roundrobin failover FCF available\n");
15905 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15906 return LPFC_FCOE_FCF_NEXT_NONE
;
15908 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15909 "3063 Only FCF available idx %d, flag %x\n",
15911 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15912 return next_fcf_index
;
15916 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15917 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15918 LPFC_FCF_FLOGI_FAILED
)
15919 goto next_priority
;
15921 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15922 "2845 Get next roundrobin failover FCF (x%x)\n",
15925 return next_fcf_index
;
15929 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15930 * @phba: pointer to lpfc hba data structure.
15932 * This routine sets the FCF record index in to the eligible bmask for
15933 * roundrobin failover search. It checks to make sure that the index
15934 * does not go beyond the range of the driver allocated bmask dimension
15935 * before setting the bit.
15937 * Returns 0 if the index bit successfully set, otherwise, it returns
15941 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15943 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15944 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15945 "2610 FCF (x%x) reached driver's book "
15946 "keeping dimension:x%x\n",
15947 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15950 /* Set the eligible FCF record index bmask */
15951 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15953 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15954 "2790 Set FCF (x%x) to roundrobin FCF failover "
15955 "bmask\n", fcf_index
);
15961 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15962 * @phba: pointer to lpfc hba data structure.
15964 * This routine clears the FCF record index from the eligible bmask for
15965 * roundrobin failover search. It checks to make sure that the index
15966 * does not go beyond the range of the driver allocated bmask dimension
15967 * before clearing the bit.
15970 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15972 struct lpfc_fcf_pri
*fcf_pri
, *fcf_pri_next
;
15973 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15974 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15975 "2762 FCF (x%x) reached driver's book "
15976 "keeping dimension:x%x\n",
15977 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15980 /* Clear the eligible FCF record index bmask */
15981 spin_lock_irq(&phba
->hbalock
);
15982 list_for_each_entry_safe(fcf_pri
, fcf_pri_next
, &phba
->fcf
.fcf_pri_list
,
15984 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15985 list_del_init(&fcf_pri
->list
);
15989 spin_unlock_irq(&phba
->hbalock
);
15990 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15992 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15993 "2791 Clear FCF (x%x) from roundrobin failover "
15994 "bmask\n", fcf_index
);
15998 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15999 * @phba: pointer to lpfc hba data structure.
16001 * This routine is the completion routine for the rediscover FCF table mailbox
16002 * command. If the mailbox command returned failure, it will try to stop the
16003 * FCF rediscover wait timer.
16006 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
16008 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
16009 uint32_t shdr_status
, shdr_add_status
;
16011 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
16013 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
16014 &redisc_fcf
->header
.cfg_shdr
.response
);
16015 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
16016 &redisc_fcf
->header
.cfg_shdr
.response
);
16017 if (shdr_status
|| shdr_add_status
) {
16018 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
16019 "2746 Requesting for FCF rediscovery failed "
16020 "status x%x add_status x%x\n",
16021 shdr_status
, shdr_add_status
);
16022 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
16023 spin_lock_irq(&phba
->hbalock
);
16024 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
16025 spin_unlock_irq(&phba
->hbalock
);
16027 * CVL event triggered FCF rediscover request failed,
16028 * last resort to re-try current registered FCF entry.
16030 lpfc_retry_pport_discovery(phba
);
16032 spin_lock_irq(&phba
->hbalock
);
16033 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
16034 spin_unlock_irq(&phba
->hbalock
);
16036 * DEAD FCF event triggered FCF rediscover request
16037 * failed, last resort to fail over as a link down
16038 * to FCF registration.
16040 lpfc_sli4_fcf_dead_failthrough(phba
);
16043 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
16044 "2775 Start FCF rediscover quiescent timer\n");
16046 * Start FCF rediscovery wait timer for pending FCF
16047 * before rescan FCF record table.
16049 lpfc_fcf_redisc_wait_start_timer(phba
);
16052 mempool_free(mbox
, phba
->mbox_mem_pool
);
16056 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
16057 * @phba: pointer to lpfc hba data structure.
16059 * This routine is invoked to request for rediscovery of the entire FCF table
16063 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
16065 LPFC_MBOXQ_t
*mbox
;
16066 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
16069 /* Cancel retry delay timers to all vports before FCF rediscover */
16070 lpfc_cancel_all_vport_retry_delay_timer(phba
);
16072 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16074 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16075 "2745 Failed to allocate mbox for "
16076 "requesting FCF rediscover.\n");
16080 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
16081 sizeof(struct lpfc_sli4_cfg_mhdr
));
16082 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
16083 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
16084 length
, LPFC_SLI4_MBX_EMBED
);
16086 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
16087 /* Set count to 0 for invalidating the entire FCF database */
16088 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
16090 /* Issue the mailbox command asynchronously */
16091 mbox
->vport
= phba
->pport
;
16092 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
16093 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
16095 if (rc
== MBX_NOT_FINISHED
) {
16096 mempool_free(mbox
, phba
->mbox_mem_pool
);
16103 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
16104 * @phba: pointer to lpfc hba data structure.
16106 * This function is the failover routine as a last resort to the FCF DEAD
16107 * event when driver failed to perform fast FCF failover.
16110 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
16112 uint32_t link_state
;
16115 * Last resort as FCF DEAD event failover will treat this as
16116 * a link down, but save the link state because we don't want
16117 * it to be changed to Link Down unless it is already down.
16119 link_state
= phba
->link_state
;
16120 lpfc_linkdown(phba
);
16121 phba
->link_state
= link_state
;
16123 /* Unregister FCF if no devices connected to it */
16124 lpfc_unregister_unused_fcf(phba
);
16128 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
16129 * @phba: pointer to lpfc hba data structure.
16130 * @rgn23_data: pointer to configure region 23 data.
16132 * This function gets SLI3 port configure region 23 data through memory dump
16133 * mailbox command. When it successfully retrieves data, the size of the data
16134 * will be returned, otherwise, 0 will be returned.
16137 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
16139 LPFC_MBOXQ_t
*pmb
= NULL
;
16141 uint32_t offset
= 0;
16147 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16149 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16150 "2600 failed to allocate mailbox memory\n");
16156 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
16157 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
16159 if (rc
!= MBX_SUCCESS
) {
16160 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
16161 "2601 failed to read config "
16162 "region 23, rc 0x%x Status 0x%x\n",
16163 rc
, mb
->mbxStatus
);
16164 mb
->un
.varDmp
.word_cnt
= 0;
16167 * dump mem may return a zero when finished or we got a
16168 * mailbox error, either way we are done.
16170 if (mb
->un
.varDmp
.word_cnt
== 0)
16172 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
16173 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
16175 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
16176 rgn23_data
+ offset
,
16177 mb
->un
.varDmp
.word_cnt
);
16178 offset
+= mb
->un
.varDmp
.word_cnt
;
16179 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
16181 mempool_free(pmb
, phba
->mbox_mem_pool
);
16186 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
16187 * @phba: pointer to lpfc hba data structure.
16188 * @rgn23_data: pointer to configure region 23 data.
16190 * This function gets SLI4 port configure region 23 data through memory dump
16191 * mailbox command. When it successfully retrieves data, the size of the data
16192 * will be returned, otherwise, 0 will be returned.
16195 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
16197 LPFC_MBOXQ_t
*mboxq
= NULL
;
16198 struct lpfc_dmabuf
*mp
= NULL
;
16199 struct lpfc_mqe
*mqe
;
16200 uint32_t data_length
= 0;
16206 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16208 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16209 "3105 failed to allocate mailbox memory\n");
16213 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
16215 mqe
= &mboxq
->u
.mqe
;
16216 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
16217 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
16220 data_length
= mqe
->un
.mb_words
[5];
16221 if (data_length
== 0)
16223 if (data_length
> DMP_RGN23_SIZE
) {
16227 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
16229 mempool_free(mboxq
, phba
->mbox_mem_pool
);
16231 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
16234 return data_length
;
16238 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
16239 * @phba: pointer to lpfc hba data structure.
16241 * This function read region 23 and parse TLV for port status to
16242 * decide if the user disaled the port. If the TLV indicates the
16243 * port is disabled, the hba_flag is set accordingly.
16246 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
16248 uint8_t *rgn23_data
= NULL
;
16249 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
16250 uint32_t offset
= 0;
16252 /* Get adapter Region 23 data */
16253 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
16257 if (phba
->sli_rev
< LPFC_SLI_REV4
)
16258 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
16260 if_type
= bf_get(lpfc_sli_intf_if_type
,
16261 &phba
->sli4_hba
.sli_intf
);
16262 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
16264 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
16270 /* Check the region signature first */
16271 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
16272 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16273 "2619 Config region 23 has bad signature\n");
16278 /* Check the data structure version */
16279 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
16280 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16281 "2620 Config region 23 has bad version\n");
16286 /* Parse TLV entries in the region */
16287 while (offset
< data_size
) {
16288 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
16291 * If the TLV is not driver specific TLV or driver id is
16292 * not linux driver id, skip the record.
16294 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
16295 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
16296 (rgn23_data
[offset
+ 3] != 0)) {
16297 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16301 /* Driver found a driver specific TLV in the config region */
16302 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
16307 * Search for configured port state sub-TLV.
16309 while ((offset
< data_size
) &&
16310 (tlv_offset
< sub_tlv_len
)) {
16311 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
16316 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
16317 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16318 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16322 /* This HBA contains PORT_STE configured */
16323 if (!rgn23_data
[offset
+ 2])
16324 phba
->hba_flag
|= LINK_DISABLED
;
16336 * lpfc_wr_object - write an object to the firmware
16337 * @phba: HBA structure that indicates port to create a queue on.
16338 * @dmabuf_list: list of dmabufs to write to the port.
16339 * @size: the total byte value of the objects to write to the port.
16340 * @offset: the current offset to be used to start the transfer.
16342 * This routine will create a wr_object mailbox command to send to the port.
16343 * the mailbox command will be constructed using the dma buffers described in
16344 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
16345 * BDEs that the imbedded mailbox can support. The @offset variable will be
16346 * used to indicate the starting offset of the transfer and will also return
16347 * the offset after the write object mailbox has completed. @size is used to
16348 * determine the end of the object and whether the eof bit should be set.
16350 * Return 0 is successful and offset will contain the the new offset to use
16351 * for the next write.
16352 * Return negative value for error cases.
16355 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
16356 uint32_t size
, uint32_t *offset
)
16358 struct lpfc_mbx_wr_object
*wr_object
;
16359 LPFC_MBOXQ_t
*mbox
;
16361 uint32_t shdr_status
, shdr_add_status
;
16363 union lpfc_sli4_cfg_shdr
*shdr
;
16364 struct lpfc_dmabuf
*dmabuf
;
16365 uint32_t written
= 0;
16367 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16371 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
16372 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
16373 sizeof(struct lpfc_mbx_wr_object
) -
16374 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
16376 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
16377 wr_object
->u
.request
.write_offset
= *offset
;
16378 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
16379 wr_object
->u
.request
.object_name
[0] =
16380 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
16381 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
16382 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
16383 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
16385 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
16386 wr_object
->u
.request
.bde
[i
].addrHigh
=
16387 putPaddrHigh(dmabuf
->phys
);
16388 if (written
+ SLI4_PAGE_SIZE
>= size
) {
16389 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
16391 written
+= (size
- written
);
16392 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
16394 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
16396 written
+= SLI4_PAGE_SIZE
;
16400 wr_object
->u
.request
.bde_count
= i
;
16401 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
16402 if (!phba
->sli4_hba
.intr_enable
)
16403 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16405 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16406 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16408 /* The IOCTL status is embedded in the mailbox subheader. */
16409 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
16410 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16411 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16412 if (rc
!= MBX_TIMEOUT
)
16413 mempool_free(mbox
, phba
->mbox_mem_pool
);
16414 if (shdr_status
|| shdr_add_status
|| rc
) {
16415 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16416 "3025 Write Object mailbox failed with "
16417 "status x%x add_status x%x, mbx status x%x\n",
16418 shdr_status
, shdr_add_status
, rc
);
16421 *offset
+= wr_object
->u
.response
.actual_write_length
;
16426 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
16427 * @vport: pointer to vport data structure.
16429 * This function iterate through the mailboxq and clean up all REG_LOGIN
16430 * and REG_VPI mailbox commands associated with the vport. This function
16431 * is called when driver want to restart discovery of the vport due to
16432 * a Clear Virtual Link event.
16435 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
16437 struct lpfc_hba
*phba
= vport
->phba
;
16438 LPFC_MBOXQ_t
*mb
, *nextmb
;
16439 struct lpfc_dmabuf
*mp
;
16440 struct lpfc_nodelist
*ndlp
;
16441 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
16442 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
16443 LIST_HEAD(mbox_cmd_list
);
16444 uint8_t restart_loop
;
16446 /* Clean up internally queued mailbox commands with the vport */
16447 spin_lock_irq(&phba
->hbalock
);
16448 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
16449 if (mb
->vport
!= vport
)
16452 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
16453 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
16456 list_del(&mb
->list
);
16457 list_add_tail(&mb
->list
, &mbox_cmd_list
);
16459 /* Clean up active mailbox command with the vport */
16460 mb
= phba
->sli
.mbox_active
;
16461 if (mb
&& (mb
->vport
== vport
)) {
16462 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
16463 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
16464 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16465 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
16466 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
16467 /* Put reference count for delayed processing */
16468 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
16469 /* Unregister the RPI when mailbox complete */
16470 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
16473 /* Cleanup any mailbox completions which are not yet processed */
16476 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
16478 * If this mailox is already processed or it is
16479 * for another vport ignore it.
16481 if ((mb
->vport
!= vport
) ||
16482 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
16485 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
16486 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
16489 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16490 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
16491 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
16492 /* Unregister the RPI when mailbox complete */
16493 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
16495 spin_unlock_irq(&phba
->hbalock
);
16496 spin_lock(shost
->host_lock
);
16497 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
16498 spin_unlock(shost
->host_lock
);
16499 spin_lock_irq(&phba
->hbalock
);
16503 } while (restart_loop
);
16505 spin_unlock_irq(&phba
->hbalock
);
16507 /* Release the cleaned-up mailbox commands */
16508 while (!list_empty(&mbox_cmd_list
)) {
16509 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
16510 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
16511 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
16513 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
16516 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
16517 mb
->context2
= NULL
;
16519 spin_lock(shost
->host_lock
);
16520 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
16521 spin_unlock(shost
->host_lock
);
16522 lpfc_nlp_put(ndlp
);
16525 mempool_free(mb
, phba
->mbox_mem_pool
);
16528 /* Release the ndlp with the cleaned-up active mailbox command */
16529 if (act_mbx_ndlp
) {
16530 spin_lock(shost
->host_lock
);
16531 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
16532 spin_unlock(shost
->host_lock
);
16533 lpfc_nlp_put(act_mbx_ndlp
);
16538 * lpfc_drain_txq - Drain the txq
16539 * @phba: Pointer to HBA context object.
16541 * This function attempt to submit IOCBs on the txq
16542 * to the adapter. For SLI4 adapters, the txq contains
16543 * ELS IOCBs that have been deferred because the there
16544 * are no SGLs. This congestion can occur with large
16545 * vport counts during node discovery.
16549 lpfc_drain_txq(struct lpfc_hba
*phba
)
16551 LIST_HEAD(completions
);
16552 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
16553 struct lpfc_iocbq
*piocbq
= 0;
16554 unsigned long iflags
= 0;
16555 char *fail_msg
= NULL
;
16556 struct lpfc_sglq
*sglq
;
16557 union lpfc_wqe wqe
;
16560 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
16561 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
16565 if (txq_cnt
> pring
->txq_max
)
16566 pring
->txq_max
= txq_cnt
;
16568 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
16570 while (!list_empty(&pring
->txq
)) {
16571 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
16573 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
16575 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
16576 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16577 "2823 txq empty and txq_cnt is %d\n ",
16581 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
16583 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
16584 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
16589 /* The xri and iocb resources secured,
16590 * attempt to issue request
16592 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
16593 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
16594 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
16595 fail_msg
= "to convert bpl to sgl";
16596 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
16597 fail_msg
= "to convert iocb to wqe";
16598 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
16599 fail_msg
= " - Wq is full";
16601 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
16604 /* Failed means we can't issue and need to cancel */
16605 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16606 "2822 IOCB failed %s iotag 0x%x "
16609 piocbq
->iotag
, piocbq
->sli4_xritag
);
16610 list_add_tail(&piocbq
->list
, &completions
);
16612 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
16615 /* Cancel all the IOCBs that cannot be issued */
16616 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
16617 IOERR_SLI_ABORTED
);