1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 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
*,
76 lpfc_get_iocb_from_iocbq(struct lpfc_iocbq
*iocbq
)
82 * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
83 * @q: The Work Queue to operate on.
84 * @wqe: The work Queue Entry to put on the Work queue.
86 * This routine will copy the contents of @wqe to the next available entry on
87 * the @q. This function will then ring the Work Queue Doorbell to signal the
88 * HBA to start processing the Work Queue Entry. This function returns 0 if
89 * successful. If no entries are available on @q then this function will return
91 * The caller is expected to hold the hbalock when calling this routine.
94 lpfc_sli4_wq_put(struct lpfc_queue
*q
, union lpfc_wqe
*wqe
)
96 union lpfc_wqe
*temp_wqe
;
97 struct lpfc_register doorbell
;
101 /* sanity check on queue memory */
104 temp_wqe
= q
->qe
[q
->host_index
].wqe
;
106 /* If the host has not yet processed the next entry then we are done */
107 idx
= ((q
->host_index
+ 1) % q
->entry_count
);
108 if (idx
== q
->hba_index
) {
113 /* set consumption flag every once in a while */
114 if (!((q
->host_index
+ 1) % q
->entry_repost
))
115 bf_set(wqe_wqec
, &wqe
->generic
.wqe_com
, 1);
116 if (q
->phba
->sli3_options
& LPFC_SLI4_PHWQ_ENABLED
)
117 bf_set(wqe_wqid
, &wqe
->generic
.wqe_com
, q
->queue_id
);
118 lpfc_sli_pcimem_bcopy(wqe
, temp_wqe
, q
->entry_size
);
120 /* Update the host index before invoking device */
121 host_index
= q
->host_index
;
127 if (q
->db_format
== LPFC_DB_LIST_FORMAT
) {
128 bf_set(lpfc_wq_db_list_fm_num_posted
, &doorbell
, 1);
129 bf_set(lpfc_wq_db_list_fm_index
, &doorbell
, host_index
);
130 bf_set(lpfc_wq_db_list_fm_id
, &doorbell
, q
->queue_id
);
131 } else if (q
->db_format
== LPFC_DB_RING_FORMAT
) {
132 bf_set(lpfc_wq_db_ring_fm_num_posted
, &doorbell
, 1);
133 bf_set(lpfc_wq_db_ring_fm_id
, &doorbell
, q
->queue_id
);
137 writel(doorbell
.word0
, q
->db_regaddr
);
143 * lpfc_sli4_wq_release - Updates internal hba index for WQ
144 * @q: The Work Queue to operate on.
145 * @index: The index to advance the hba index to.
147 * This routine will update the HBA index of a queue to reflect consumption of
148 * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
149 * an entry the host calls this function to update the queue's internal
150 * pointers. This routine returns the number of entries that were consumed by
154 lpfc_sli4_wq_release(struct lpfc_queue
*q
, uint32_t index
)
156 uint32_t released
= 0;
158 /* sanity check on queue memory */
162 if (q
->hba_index
== index
)
165 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
167 } while (q
->hba_index
!= index
);
172 * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
173 * @q: The Mailbox Queue to operate on.
174 * @wqe: The Mailbox Queue Entry to put on the Work queue.
176 * This routine will copy the contents of @mqe to the next available entry on
177 * the @q. This function will then ring the Work Queue Doorbell to signal the
178 * HBA to start processing the Work Queue Entry. This function returns 0 if
179 * successful. If no entries are available on @q then this function will return
181 * The caller is expected to hold the hbalock when calling this routine.
184 lpfc_sli4_mq_put(struct lpfc_queue
*q
, struct lpfc_mqe
*mqe
)
186 struct lpfc_mqe
*temp_mqe
;
187 struct lpfc_register doorbell
;
190 /* sanity check on queue memory */
193 temp_mqe
= q
->qe
[q
->host_index
].mqe
;
195 /* If the host has not yet processed the next entry then we are done */
196 if (((q
->host_index
+ 1) % q
->entry_count
) == q
->hba_index
)
198 lpfc_sli_pcimem_bcopy(mqe
, temp_mqe
, q
->entry_size
);
199 /* Save off the mailbox pointer for completion */
200 q
->phba
->mbox
= (MAILBOX_t
*)temp_mqe
;
202 /* Update the host index before invoking device */
203 host_index
= q
->host_index
;
204 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
208 bf_set(lpfc_mq_doorbell_num_posted
, &doorbell
, 1);
209 bf_set(lpfc_mq_doorbell_id
, &doorbell
, q
->queue_id
);
210 writel(doorbell
.word0
, q
->phba
->sli4_hba
.MQDBregaddr
);
215 * lpfc_sli4_mq_release - Updates internal hba index for MQ
216 * @q: The Mailbox Queue to operate on.
218 * This routine will update the HBA index of a queue to reflect consumption of
219 * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
220 * an entry the host calls this function to update the queue's internal
221 * pointers. This routine returns the number of entries that were consumed by
225 lpfc_sli4_mq_release(struct lpfc_queue
*q
)
227 /* sanity check on queue memory */
231 /* Clear the mailbox pointer for completion */
232 q
->phba
->mbox
= NULL
;
233 q
->hba_index
= ((q
->hba_index
+ 1) % q
->entry_count
);
238 * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
239 * @q: The Event Queue to get the first valid EQE from
241 * This routine will get the first valid Event Queue Entry from @q, update
242 * the queue's internal hba index, and return the EQE. If no valid EQEs are in
243 * the Queue (no more work to do), or the Queue is full of EQEs that have been
244 * processed, but not popped back to the HBA then this routine will return NULL.
246 static struct lpfc_eqe
*
247 lpfc_sli4_eq_get(struct lpfc_queue
*q
)
249 struct lpfc_eqe
*eqe
;
252 /* sanity check on queue memory */
255 eqe
= q
->qe
[q
->hba_index
].eqe
;
257 /* If the next EQE is not valid then we are done */
258 if (!bf_get_le32(lpfc_eqe_valid
, eqe
))
260 /* If the host has not yet processed the next entry then we are done */
261 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
262 if (idx
== q
->host_index
)
270 * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
271 * @q: The Event Queue to disable interrupts
275 lpfc_sli4_eq_clr_intr(struct lpfc_queue
*q
)
277 struct lpfc_register doorbell
;
280 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
281 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
282 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
283 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
284 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
285 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
289 * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ
290 * @q: The Event Queue that the host has completed processing for.
291 * @arm: Indicates whether the host wants to arms this CQ.
293 * This routine will mark all Event Queue Entries on @q, from the last
294 * known completed entry to the last entry that was processed, as completed
295 * by clearing the valid bit for each completion queue entry. Then it will
296 * notify the HBA, by ringing the doorbell, that the EQEs have been processed.
297 * The internal host index in the @q will be updated by this routine to indicate
298 * that the host has finished processing the entries. The @arm parameter
299 * indicates that the queue should be rearmed when ringing the doorbell.
301 * This function will return the number of EQEs that were popped.
304 lpfc_sli4_eq_release(struct lpfc_queue
*q
, bool arm
)
306 uint32_t released
= 0;
307 struct lpfc_eqe
*temp_eqe
;
308 struct lpfc_register doorbell
;
310 /* sanity check on queue memory */
314 /* while there are valid entries */
315 while (q
->hba_index
!= q
->host_index
) {
316 temp_eqe
= q
->qe
[q
->host_index
].eqe
;
317 bf_set_le32(lpfc_eqe_valid
, temp_eqe
, 0);
319 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
321 if (unlikely(released
== 0 && !arm
))
324 /* ring doorbell for number popped */
327 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
328 bf_set(lpfc_eqcq_doorbell_eqci
, &doorbell
, 1);
330 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
331 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_EVENT
);
332 bf_set(lpfc_eqcq_doorbell_eqid_hi
, &doorbell
,
333 (q
->queue_id
>> LPFC_EQID_HI_FIELD_SHIFT
));
334 bf_set(lpfc_eqcq_doorbell_eqid_lo
, &doorbell
, q
->queue_id
);
335 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
336 /* PCI read to flush PCI pipeline on re-arming for INTx mode */
337 if ((q
->phba
->intr_type
== INTx
) && (arm
== LPFC_QUEUE_REARM
))
338 readl(q
->phba
->sli4_hba
.EQCQDBregaddr
);
343 * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
344 * @q: The Completion Queue to get the first valid CQE from
346 * This routine will get the first valid Completion Queue Entry from @q, update
347 * the queue's internal hba index, and return the CQE. If no valid CQEs are in
348 * the Queue (no more work to do), or the Queue is full of CQEs that have been
349 * processed, but not popped back to the HBA then this routine will return NULL.
351 static struct lpfc_cqe
*
352 lpfc_sli4_cq_get(struct lpfc_queue
*q
)
354 struct lpfc_cqe
*cqe
;
357 /* sanity check on queue memory */
361 /* If the next CQE is not valid then we are done */
362 if (!bf_get_le32(lpfc_cqe_valid
, q
->qe
[q
->hba_index
].cqe
))
364 /* If the host has not yet processed the next entry then we are done */
365 idx
= ((q
->hba_index
+ 1) % q
->entry_count
);
366 if (idx
== q
->host_index
)
369 cqe
= q
->qe
[q
->hba_index
].cqe
;
375 * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ
376 * @q: The Completion Queue that the host has completed processing for.
377 * @arm: Indicates whether the host wants to arms this CQ.
379 * This routine will mark all Completion queue entries on @q, from the last
380 * known completed entry to the last entry that was processed, as completed
381 * by clearing the valid bit for each completion queue entry. Then it will
382 * notify the HBA, by ringing the doorbell, that the CQEs have been processed.
383 * The internal host index in the @q will be updated by this routine to indicate
384 * that the host has finished processing the entries. The @arm parameter
385 * indicates that the queue should be rearmed when ringing the doorbell.
387 * This function will return the number of CQEs that were released.
390 lpfc_sli4_cq_release(struct lpfc_queue
*q
, bool arm
)
392 uint32_t released
= 0;
393 struct lpfc_cqe
*temp_qe
;
394 struct lpfc_register doorbell
;
396 /* sanity check on queue memory */
399 /* while there are valid entries */
400 while (q
->hba_index
!= q
->host_index
) {
401 temp_qe
= q
->qe
[q
->host_index
].cqe
;
402 bf_set_le32(lpfc_cqe_valid
, temp_qe
, 0);
404 q
->host_index
= ((q
->host_index
+ 1) % q
->entry_count
);
406 if (unlikely(released
== 0 && !arm
))
409 /* ring doorbell for number popped */
412 bf_set(lpfc_eqcq_doorbell_arm
, &doorbell
, 1);
413 bf_set(lpfc_eqcq_doorbell_num_released
, &doorbell
, released
);
414 bf_set(lpfc_eqcq_doorbell_qt
, &doorbell
, LPFC_QUEUE_TYPE_COMPLETION
);
415 bf_set(lpfc_eqcq_doorbell_cqid_hi
, &doorbell
,
416 (q
->queue_id
>> LPFC_CQID_HI_FIELD_SHIFT
));
417 bf_set(lpfc_eqcq_doorbell_cqid_lo
, &doorbell
, q
->queue_id
);
418 writel(doorbell
.word0
, q
->phba
->sli4_hba
.EQCQDBregaddr
);
423 * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
424 * @q: The Header Receive Queue to operate on.
425 * @wqe: The Receive Queue Entry to put on the Receive queue.
427 * This routine will copy the contents of @wqe to the next available entry on
428 * the @q. This function will then ring the Receive Queue Doorbell to signal the
429 * HBA to start processing the Receive Queue Entry. This function returns the
430 * index that the rqe was copied to if successful. If no entries are available
431 * on @q then this function will return -ENOMEM.
432 * The caller is expected to hold the hbalock when calling this routine.
435 lpfc_sli4_rq_put(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
,
436 struct lpfc_rqe
*hrqe
, struct lpfc_rqe
*drqe
)
438 struct lpfc_rqe
*temp_hrqe
;
439 struct lpfc_rqe
*temp_drqe
;
440 struct lpfc_register doorbell
;
443 /* sanity check on queue memory */
444 if (unlikely(!hq
) || unlikely(!dq
))
446 put_index
= hq
->host_index
;
447 temp_hrqe
= hq
->qe
[hq
->host_index
].rqe
;
448 temp_drqe
= dq
->qe
[dq
->host_index
].rqe
;
450 if (hq
->type
!= LPFC_HRQ
|| dq
->type
!= LPFC_DRQ
)
452 if (hq
->host_index
!= dq
->host_index
)
454 /* If the host has not yet processed the next entry then we are done */
455 if (((hq
->host_index
+ 1) % hq
->entry_count
) == hq
->hba_index
)
457 lpfc_sli_pcimem_bcopy(hrqe
, temp_hrqe
, hq
->entry_size
);
458 lpfc_sli_pcimem_bcopy(drqe
, temp_drqe
, dq
->entry_size
);
460 /* Update the host index to point to the next slot */
461 hq
->host_index
= ((hq
->host_index
+ 1) % hq
->entry_count
);
462 dq
->host_index
= ((dq
->host_index
+ 1) % dq
->entry_count
);
464 /* Ring The Header Receive Queue Doorbell */
465 if (!(hq
->host_index
% hq
->entry_repost
)) {
467 if (hq
->db_format
== LPFC_DB_RING_FORMAT
) {
468 bf_set(lpfc_rq_db_ring_fm_num_posted
, &doorbell
,
470 bf_set(lpfc_rq_db_ring_fm_id
, &doorbell
, hq
->queue_id
);
471 } else if (hq
->db_format
== LPFC_DB_LIST_FORMAT
) {
472 bf_set(lpfc_rq_db_list_fm_num_posted
, &doorbell
,
474 bf_set(lpfc_rq_db_list_fm_index
, &doorbell
,
476 bf_set(lpfc_rq_db_list_fm_id
, &doorbell
, hq
->queue_id
);
480 writel(doorbell
.word0
, hq
->db_regaddr
);
486 * lpfc_sli4_rq_release - Updates internal hba index for RQ
487 * @q: The Header Receive Queue to operate on.
489 * This routine will update the HBA index of a queue to reflect consumption of
490 * one Receive Queue Entry by the HBA. When the HBA indicates that it has
491 * consumed an entry the host calls this function to update the queue's
492 * internal pointers. This routine returns the number of entries that were
493 * consumed by the HBA.
496 lpfc_sli4_rq_release(struct lpfc_queue
*hq
, struct lpfc_queue
*dq
)
498 /* sanity check on queue memory */
499 if (unlikely(!hq
) || unlikely(!dq
))
502 if ((hq
->type
!= LPFC_HRQ
) || (dq
->type
!= LPFC_DRQ
))
504 hq
->hba_index
= ((hq
->hba_index
+ 1) % hq
->entry_count
);
505 dq
->hba_index
= ((dq
->hba_index
+ 1) % dq
->entry_count
);
510 * lpfc_cmd_iocb - Get next command iocb entry in the ring
511 * @phba: Pointer to HBA context object.
512 * @pring: Pointer to driver SLI ring object.
514 * This function returns pointer to next command iocb entry
515 * in the command ring. The caller must hold hbalock to prevent
516 * other threads consume the next command iocb.
517 * SLI-2/SLI-3 provide different sized iocbs.
519 static inline IOCB_t
*
520 lpfc_cmd_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
522 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.cmdringaddr
) +
523 pring
->sli
.sli3
.cmdidx
* phba
->iocb_cmd_size
);
527 * lpfc_resp_iocb - Get next response iocb entry in the ring
528 * @phba: Pointer to HBA context object.
529 * @pring: Pointer to driver SLI ring object.
531 * This function returns pointer to next response iocb entry
532 * in the response ring. The caller must hold hbalock to make sure
533 * that no other thread consume the next response iocb.
534 * SLI-2/SLI-3 provide different sized iocbs.
536 static inline IOCB_t
*
537 lpfc_resp_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
539 return (IOCB_t
*) (((char *) pring
->sli
.sli3
.rspringaddr
) +
540 pring
->sli
.sli3
.rspidx
* phba
->iocb_rsp_size
);
544 * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
545 * @phba: Pointer to HBA context object.
547 * This function is called with hbalock held. This function
548 * allocates a new driver iocb object from the iocb pool. If the
549 * allocation is successful, it returns pointer to the newly
550 * allocated iocb object else it returns NULL.
553 __lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
555 struct list_head
*lpfc_iocb_list
= &phba
->lpfc_iocb_list
;
556 struct lpfc_iocbq
* iocbq
= NULL
;
558 list_remove_head(lpfc_iocb_list
, iocbq
, struct lpfc_iocbq
, list
);
561 if (phba
->iocb_cnt
> phba
->iocb_max
)
562 phba
->iocb_max
= phba
->iocb_cnt
;
567 * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
568 * @phba: Pointer to HBA context object.
569 * @xritag: XRI value.
571 * This function clears the sglq pointer from the array of acive
572 * sglq's. The xritag that is passed in is used to index into the
573 * array. Before the xritag can be used it needs to be adjusted
574 * by subtracting the xribase.
576 * Returns sglq ponter = success, NULL = Failure.
578 static struct lpfc_sglq
*
579 __lpfc_clear_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
581 struct lpfc_sglq
*sglq
;
583 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
584 phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
] = NULL
;
589 * __lpfc_get_active_sglq - Get the active sglq for this XRI.
590 * @phba: Pointer to HBA context object.
591 * @xritag: XRI value.
593 * This function returns the sglq pointer from the array of acive
594 * sglq's. The xritag that is passed in is used to index into the
595 * array. Before the xritag can be used it needs to be adjusted
596 * by subtracting the xribase.
598 * Returns sglq ponter = success, NULL = Failure.
601 __lpfc_get_active_sglq(struct lpfc_hba
*phba
, uint16_t xritag
)
603 struct lpfc_sglq
*sglq
;
605 sglq
= phba
->sli4_hba
.lpfc_sglq_active_list
[xritag
];
610 * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
611 * @phba: Pointer to HBA context object.
612 * @xritag: xri used in this exchange.
613 * @rrq: The RRQ to be cleared.
617 lpfc_clr_rrq_active(struct lpfc_hba
*phba
,
619 struct lpfc_node_rrq
*rrq
)
621 struct lpfc_nodelist
*ndlp
= NULL
;
623 if ((rrq
->vport
) && NLP_CHK_NODE_ACT(rrq
->ndlp
))
624 ndlp
= lpfc_findnode_did(rrq
->vport
, rrq
->nlp_DID
);
626 /* The target DID could have been swapped (cable swap)
627 * we should use the ndlp from the findnode if it is
630 if ((!ndlp
) && rrq
->ndlp
)
636 if (test_and_clear_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
)) {
639 rrq
->rrq_stop_time
= 0;
642 mempool_free(rrq
, phba
->rrq_pool
);
646 * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
647 * @phba: Pointer to HBA context object.
649 * This function is called with hbalock held. This function
650 * Checks if stop_time (ratov from setting rrq active) has
651 * been reached, if it has and the send_rrq flag is set then
652 * it will call lpfc_send_rrq. If the send_rrq flag is not set
653 * then it will just call the routine to clear the rrq and
654 * free the rrq resource.
655 * The timer is set to the next rrq that is going to expire before
656 * leaving the routine.
660 lpfc_handle_rrq_active(struct lpfc_hba
*phba
)
662 struct lpfc_node_rrq
*rrq
;
663 struct lpfc_node_rrq
*nextrrq
;
664 unsigned long next_time
;
665 unsigned long iflags
;
668 spin_lock_irqsave(&phba
->hbalock
, iflags
);
669 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
670 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
671 list_for_each_entry_safe(rrq
, nextrrq
,
672 &phba
->active_rrq_list
, list
) {
673 if (time_after(jiffies
, rrq
->rrq_stop_time
))
674 list_move(&rrq
->list
, &send_rrq
);
675 else if (time_before(rrq
->rrq_stop_time
, next_time
))
676 next_time
= rrq
->rrq_stop_time
;
678 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
679 if (!list_empty(&phba
->active_rrq_list
))
680 mod_timer(&phba
->rrq_tmr
, next_time
);
681 list_for_each_entry_safe(rrq
, nextrrq
, &send_rrq
, list
) {
682 list_del(&rrq
->list
);
684 /* this call will free the rrq */
685 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
686 else if (lpfc_send_rrq(phba
, rrq
)) {
687 /* if we send the rrq then the completion handler
688 * will clear the bit in the xribitmap.
690 lpfc_clr_rrq_active(phba
, rrq
->xritag
,
697 * lpfc_get_active_rrq - Get the active RRQ for this exchange.
698 * @vport: Pointer to vport context object.
699 * @xri: The xri used in the exchange.
700 * @did: The targets DID for this exchange.
702 * returns NULL = rrq not found in the phba->active_rrq_list.
703 * rrq = rrq for this xri and target.
705 struct lpfc_node_rrq
*
706 lpfc_get_active_rrq(struct lpfc_vport
*vport
, uint16_t xri
, uint32_t did
)
708 struct lpfc_hba
*phba
= vport
->phba
;
709 struct lpfc_node_rrq
*rrq
;
710 struct lpfc_node_rrq
*nextrrq
;
711 unsigned long iflags
;
713 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
715 spin_lock_irqsave(&phba
->hbalock
, iflags
);
716 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
) {
717 if (rrq
->vport
== vport
&& rrq
->xritag
== xri
&&
718 rrq
->nlp_DID
== did
){
719 list_del(&rrq
->list
);
720 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
724 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
729 * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
730 * @vport: Pointer to vport context object.
731 * @ndlp: Pointer to the lpfc_node_list structure.
732 * If ndlp is NULL Remove all active RRQs for this vport from the
733 * phba->active_rrq_list and clear the rrq.
734 * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
737 lpfc_cleanup_vports_rrqs(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
740 struct lpfc_hba
*phba
= vport
->phba
;
741 struct lpfc_node_rrq
*rrq
;
742 struct lpfc_node_rrq
*nextrrq
;
743 unsigned long iflags
;
746 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
749 lpfc_sli4_vport_delete_els_xri_aborted(vport
);
750 lpfc_sli4_vport_delete_fcp_xri_aborted(vport
);
752 spin_lock_irqsave(&phba
->hbalock
, iflags
);
753 list_for_each_entry_safe(rrq
, nextrrq
, &phba
->active_rrq_list
, list
)
754 if ((rrq
->vport
== vport
) && (!ndlp
|| rrq
->ndlp
== ndlp
))
755 list_move(&rrq
->list
, &rrq_list
);
756 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
758 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
759 list_del(&rrq
->list
);
760 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
765 * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list.
766 * @phba: Pointer to HBA context object.
768 * Remove all rrqs from the phba->active_rrq_list and free them by
769 * calling __lpfc_clr_active_rrq
773 lpfc_cleanup_wt_rrqs(struct lpfc_hba
*phba
)
775 struct lpfc_node_rrq
*rrq
;
776 struct lpfc_node_rrq
*nextrrq
;
777 unsigned long next_time
;
778 unsigned long iflags
;
781 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
783 spin_lock_irqsave(&phba
->hbalock
, iflags
);
784 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
785 next_time
= jiffies
+ HZ
* (phba
->fc_ratov
* 2);
786 list_splice_init(&phba
->active_rrq_list
, &rrq_list
);
787 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
789 list_for_each_entry_safe(rrq
, nextrrq
, &rrq_list
, list
) {
790 list_del(&rrq
->list
);
791 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
793 if (!list_empty(&phba
->active_rrq_list
))
794 mod_timer(&phba
->rrq_tmr
, next_time
);
799 * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
800 * @phba: Pointer to HBA context object.
801 * @ndlp: Targets nodelist pointer for this exchange.
802 * @xritag the xri in the bitmap to test.
804 * This function is called with hbalock held. This function
805 * returns 0 = rrq not active for this xri
806 * 1 = rrq is valid for this xri.
809 lpfc_test_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
814 if (test_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
821 * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
822 * @phba: Pointer to HBA context object.
823 * @ndlp: nodelist pointer for this target.
824 * @xritag: xri used in this exchange.
825 * @rxid: Remote Exchange ID.
826 * @send_rrq: Flag used to determine if we should send rrq els cmd.
828 * This function takes the hbalock.
829 * The active bit is always set in the active rrq xri_bitmap even
830 * if there is no slot avaiable for the other rrq information.
832 * returns 0 rrq actived for this xri
833 * < 0 No memory or invalid ndlp.
836 lpfc_set_rrq_active(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
,
837 uint16_t xritag
, uint16_t rxid
, uint16_t send_rrq
)
839 unsigned long iflags
;
840 struct lpfc_node_rrq
*rrq
;
846 if (!phba
->cfg_enable_rrq
)
849 spin_lock_irqsave(&phba
->hbalock
, iflags
);
850 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
851 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
856 * set the active bit even if there is no mem available.
858 if (NLP_CHK_FREE_REQ(ndlp
))
861 if (ndlp
->vport
&& (ndlp
->vport
->load_flag
& FC_UNLOADING
))
864 if (test_and_set_bit(xritag
, ndlp
->active_rrqs
.xri_bitmap
))
867 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
868 rrq
= mempool_alloc(phba
->rrq_pool
, GFP_KERNEL
);
870 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
871 "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
872 " DID:0x%x Send:%d\n",
873 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
876 if (phba
->cfg_enable_rrq
== 1)
877 rrq
->send_rrq
= send_rrq
;
880 rrq
->xritag
= xritag
;
881 rrq
->rrq_stop_time
= jiffies
+ HZ
* (phba
->fc_ratov
+ 1);
883 rrq
->nlp_DID
= ndlp
->nlp_DID
;
884 rrq
->vport
= ndlp
->vport
;
886 spin_lock_irqsave(&phba
->hbalock
, iflags
);
887 empty
= list_empty(&phba
->active_rrq_list
);
888 list_add_tail(&rrq
->list
, &phba
->active_rrq_list
);
889 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
891 lpfc_worker_wake_up(phba
);
892 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
895 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
896 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
897 "2921 Can't set rrq active xri:0x%x rxid:0x%x"
898 " DID:0x%x Send:%d\n",
899 xritag
, rxid
, ndlp
->nlp_DID
, send_rrq
);
904 * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool
905 * @phba: Pointer to HBA context object.
906 * @piocb: Pointer to the iocbq.
908 * This function is called with hbalock held. This function
909 * gets a new driver sglq object from the sglq list. If the
910 * list is not empty then it is successful, it returns pointer to the newly
911 * allocated sglq object else it returns NULL.
913 static struct lpfc_sglq
*
914 __lpfc_sli_get_sglq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
)
916 struct list_head
*lpfc_sgl_list
= &phba
->sli4_hba
.lpfc_sgl_list
;
917 struct lpfc_sglq
*sglq
= NULL
;
918 struct lpfc_sglq
*start_sglq
= NULL
;
919 struct lpfc_scsi_buf
*lpfc_cmd
;
920 struct lpfc_nodelist
*ndlp
;
923 if (piocbq
->iocb_flag
& LPFC_IO_FCP
) {
924 lpfc_cmd
= (struct lpfc_scsi_buf
*) piocbq
->context1
;
925 ndlp
= lpfc_cmd
->rdata
->pnode
;
926 } else if ((piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) &&
927 !(piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
928 ndlp
= piocbq
->context_un
.ndlp
;
929 else if ((piocbq
->iocb
.ulpCommand
== CMD_ELS_REQUEST64_CR
) &&
930 (piocbq
->iocb_flag
& LPFC_IO_LIBDFC
))
931 ndlp
= piocbq
->context_un
.ndlp
;
933 ndlp
= piocbq
->context1
;
935 list_remove_head(lpfc_sgl_list
, sglq
, struct lpfc_sglq
, list
);
940 if (lpfc_test_rrq_active(phba
, ndlp
, sglq
->sli4_lxritag
)) {
941 /* This xri has an rrq outstanding for this DID.
942 * put it back in the list and get another xri.
944 list_add_tail(&sglq
->list
, lpfc_sgl_list
);
946 list_remove_head(lpfc_sgl_list
, sglq
,
947 struct lpfc_sglq
, list
);
948 if (sglq
== start_sglq
) {
956 phba
->sli4_hba
.lpfc_sglq_active_list
[sglq
->sli4_lxritag
] = sglq
;
957 sglq
->state
= SGL_ALLOCATED
;
963 * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
964 * @phba: Pointer to HBA context object.
966 * This function is called with no lock held. This function
967 * allocates a new driver iocb object from the iocb pool. If the
968 * allocation is successful, it returns pointer to the newly
969 * allocated iocb object else it returns NULL.
972 lpfc_sli_get_iocbq(struct lpfc_hba
*phba
)
974 struct lpfc_iocbq
* iocbq
= NULL
;
975 unsigned long iflags
;
977 spin_lock_irqsave(&phba
->hbalock
, iflags
);
978 iocbq
= __lpfc_sli_get_iocbq(phba
);
979 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
984 * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
985 * @phba: Pointer to HBA context object.
986 * @iocbq: Pointer to driver iocb object.
988 * This function is called with hbalock held to release driver
989 * iocb object to the iocb pool. The iotag in the iocb object
990 * does not change for each use of the iocb object. This function
991 * clears all other fields of the iocb object when it is freed.
992 * The sqlq structure that holds the xritag and phys and virtual
993 * mappings for the scatter gather list is retrieved from the
994 * active array of sglq. The get of the sglq pointer also clears
995 * the entry in the array. If the status of the IO indiactes that
996 * this IO was aborted then the sglq entry it put on the
997 * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
998 * IO has good status or fails for any other reason then the sglq
999 * entry is added to the free list (lpfc_sgl_list).
1002 __lpfc_sli_release_iocbq_s4(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1004 struct lpfc_sglq
*sglq
;
1005 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1006 unsigned long iflag
= 0;
1007 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1009 if (iocbq
->sli4_xritag
== NO_XRI
)
1012 sglq
= __lpfc_clear_active_sglq(phba
, iocbq
->sli4_lxritag
);
1015 ** This should have been removed from the txcmplq before calling
1016 ** iocbq_release. The normal completion
1017 ** path should have already done the list_del_init.
1019 if (unlikely(!list_empty(&iocbq
->list
))) {
1020 if (iocbq
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
)
1021 iocbq
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
1022 list_del_init(&iocbq
->list
);
1027 if ((iocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
) &&
1028 (sglq
->state
!= SGL_XRI_ABORTED
)) {
1029 spin_lock_irqsave(&phba
->sli4_hba
.abts_sgl_list_lock
,
1031 list_add(&sglq
->list
,
1032 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
1033 spin_unlock_irqrestore(
1034 &phba
->sli4_hba
.abts_sgl_list_lock
, iflag
);
1036 sglq
->state
= SGL_FREED
;
1038 list_add_tail(&sglq
->list
,
1039 &phba
->sli4_hba
.lpfc_sgl_list
);
1041 /* Check if TXQ queue needs to be serviced */
1042 if (!list_empty(&pring
->txq
))
1043 lpfc_worker_wake_up(phba
);
1049 * Clean all volatile data fields, preserve iotag and node struct.
1051 memset((char *)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1052 iocbq
->sli4_lxritag
= NO_XRI
;
1053 iocbq
->sli4_xritag
= NO_XRI
;
1054 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1059 * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
1060 * @phba: Pointer to HBA context object.
1061 * @iocbq: Pointer to driver iocb object.
1063 * This function is called with hbalock held to release driver
1064 * iocb object to the iocb pool. The iotag in the iocb object
1065 * does not change for each use of the iocb object. This function
1066 * clears all other fields of the iocb object when it is freed.
1069 __lpfc_sli_release_iocbq_s3(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1071 size_t start_clean
= offsetof(struct lpfc_iocbq
, iocb
);
1074 ** This should have been removed from the txcmplq before calling
1075 ** iocbq_release. The normal completion
1076 ** path should have already done the list_del_init.
1078 if (unlikely(!list_empty(&iocbq
->list
)))
1079 list_del_init(&iocbq
->list
);
1082 * Clean all volatile data fields, preserve iotag and node struct.
1084 memset((char*)iocbq
+ start_clean
, 0, sizeof(*iocbq
) - start_clean
);
1085 iocbq
->sli4_xritag
= NO_XRI
;
1086 list_add_tail(&iocbq
->list
, &phba
->lpfc_iocb_list
);
1090 * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
1091 * @phba: Pointer to HBA context object.
1092 * @iocbq: Pointer to driver iocb object.
1094 * This function is called with hbalock held to release driver
1095 * iocb object to the iocb pool. The iotag in the iocb object
1096 * does not change for each use of the iocb object. This function
1097 * clears all other fields of the iocb object when it is freed.
1100 __lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1102 phba
->__lpfc_sli_release_iocbq(phba
, iocbq
);
1107 * lpfc_sli_release_iocbq - Release iocb to the iocb pool
1108 * @phba: Pointer to HBA context object.
1109 * @iocbq: Pointer to driver iocb object.
1111 * This function is called with no lock held to release the iocb to
1115 lpfc_sli_release_iocbq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1117 unsigned long iflags
;
1120 * Clean all volatile data fields, preserve iotag and node struct.
1122 spin_lock_irqsave(&phba
->hbalock
, iflags
);
1123 __lpfc_sli_release_iocbq(phba
, iocbq
);
1124 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
1128 * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
1129 * @phba: Pointer to HBA context object.
1130 * @iocblist: List of IOCBs.
1131 * @ulpstatus: ULP status in IOCB command field.
1132 * @ulpWord4: ULP word-4 in IOCB command field.
1134 * This function is called with a list of IOCBs to cancel. It cancels the IOCB
1135 * on the list by invoking the complete callback function associated with the
1136 * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
1140 lpfc_sli_cancel_iocbs(struct lpfc_hba
*phba
, struct list_head
*iocblist
,
1141 uint32_t ulpstatus
, uint32_t ulpWord4
)
1143 struct lpfc_iocbq
*piocb
;
1145 while (!list_empty(iocblist
)) {
1146 list_remove_head(iocblist
, piocb
, struct lpfc_iocbq
, list
);
1147 if (!piocb
->iocb_cmpl
)
1148 lpfc_sli_release_iocbq(phba
, piocb
);
1150 piocb
->iocb
.ulpStatus
= ulpstatus
;
1151 piocb
->iocb
.un
.ulpWord
[4] = ulpWord4
;
1152 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
1159 * lpfc_sli_iocb_cmd_type - Get the iocb type
1160 * @iocb_cmnd: iocb command code.
1162 * This function is called by ring event handler function to get the iocb type.
1163 * This function translates the iocb command to an iocb command type used to
1164 * decide the final disposition of each completed IOCB.
1165 * The function returns
1166 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
1167 * LPFC_SOL_IOCB if it is a solicited iocb completion
1168 * LPFC_ABORT_IOCB if it is an abort iocb
1169 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
1171 * The caller is not required to hold any lock.
1173 static lpfc_iocb_type
1174 lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd
)
1176 lpfc_iocb_type type
= LPFC_UNKNOWN_IOCB
;
1178 if (iocb_cmnd
> CMD_MAX_IOCB_CMD
)
1181 switch (iocb_cmnd
) {
1182 case CMD_XMIT_SEQUENCE_CR
:
1183 case CMD_XMIT_SEQUENCE_CX
:
1184 case CMD_XMIT_BCAST_CN
:
1185 case CMD_XMIT_BCAST_CX
:
1186 case CMD_ELS_REQUEST_CR
:
1187 case CMD_ELS_REQUEST_CX
:
1188 case CMD_CREATE_XRI_CR
:
1189 case CMD_CREATE_XRI_CX
:
1190 case CMD_GET_RPI_CN
:
1191 case CMD_XMIT_ELS_RSP_CX
:
1192 case CMD_GET_RPI_CR
:
1193 case CMD_FCP_IWRITE_CR
:
1194 case CMD_FCP_IWRITE_CX
:
1195 case CMD_FCP_IREAD_CR
:
1196 case CMD_FCP_IREAD_CX
:
1197 case CMD_FCP_ICMND_CR
:
1198 case CMD_FCP_ICMND_CX
:
1199 case CMD_FCP_TSEND_CX
:
1200 case CMD_FCP_TRSP_CX
:
1201 case CMD_FCP_TRECEIVE_CX
:
1202 case CMD_FCP_AUTO_TRSP_CX
:
1203 case CMD_ADAPTER_MSG
:
1204 case CMD_ADAPTER_DUMP
:
1205 case CMD_XMIT_SEQUENCE64_CR
:
1206 case CMD_XMIT_SEQUENCE64_CX
:
1207 case CMD_XMIT_BCAST64_CN
:
1208 case CMD_XMIT_BCAST64_CX
:
1209 case CMD_ELS_REQUEST64_CR
:
1210 case CMD_ELS_REQUEST64_CX
:
1211 case CMD_FCP_IWRITE64_CR
:
1212 case CMD_FCP_IWRITE64_CX
:
1213 case CMD_FCP_IREAD64_CR
:
1214 case CMD_FCP_IREAD64_CX
:
1215 case CMD_FCP_ICMND64_CR
:
1216 case CMD_FCP_ICMND64_CX
:
1217 case CMD_FCP_TSEND64_CX
:
1218 case CMD_FCP_TRSP64_CX
:
1219 case CMD_FCP_TRECEIVE64_CX
:
1220 case CMD_GEN_REQUEST64_CR
:
1221 case CMD_GEN_REQUEST64_CX
:
1222 case CMD_XMIT_ELS_RSP64_CX
:
1223 case DSSCMD_IWRITE64_CR
:
1224 case DSSCMD_IWRITE64_CX
:
1225 case DSSCMD_IREAD64_CR
:
1226 case DSSCMD_IREAD64_CX
:
1227 type
= LPFC_SOL_IOCB
;
1229 case CMD_ABORT_XRI_CN
:
1230 case CMD_ABORT_XRI_CX
:
1231 case CMD_CLOSE_XRI_CN
:
1232 case CMD_CLOSE_XRI_CX
:
1233 case CMD_XRI_ABORTED_CX
:
1234 case CMD_ABORT_MXRI64_CN
:
1235 case CMD_XMIT_BLS_RSP64_CX
:
1236 type
= LPFC_ABORT_IOCB
;
1238 case CMD_RCV_SEQUENCE_CX
:
1239 case CMD_RCV_ELS_REQ_CX
:
1240 case CMD_RCV_SEQUENCE64_CX
:
1241 case CMD_RCV_ELS_REQ64_CX
:
1242 case CMD_ASYNC_STATUS
:
1243 case CMD_IOCB_RCV_SEQ64_CX
:
1244 case CMD_IOCB_RCV_ELS64_CX
:
1245 case CMD_IOCB_RCV_CONT64_CX
:
1246 case CMD_IOCB_RET_XRI64_CX
:
1247 type
= LPFC_UNSOL_IOCB
;
1249 case CMD_IOCB_XMIT_MSEQ64_CR
:
1250 case CMD_IOCB_XMIT_MSEQ64_CX
:
1251 case CMD_IOCB_RCV_SEQ_LIST64_CX
:
1252 case CMD_IOCB_RCV_ELS_LIST64_CX
:
1253 case CMD_IOCB_CLOSE_EXTENDED_CN
:
1254 case CMD_IOCB_ABORT_EXTENDED_CN
:
1255 case CMD_IOCB_RET_HBQE64_CN
:
1256 case CMD_IOCB_FCP_IBIDIR64_CR
:
1257 case CMD_IOCB_FCP_IBIDIR64_CX
:
1258 case CMD_IOCB_FCP_ITASKMGT64_CX
:
1259 case CMD_IOCB_LOGENTRY_CN
:
1260 case CMD_IOCB_LOGENTRY_ASYNC_CN
:
1261 printk("%s - Unhandled SLI-3 Command x%x\n",
1262 __func__
, iocb_cmnd
);
1263 type
= LPFC_UNKNOWN_IOCB
;
1266 type
= LPFC_UNKNOWN_IOCB
;
1274 * lpfc_sli_ring_map - Issue config_ring mbox for all rings
1275 * @phba: Pointer to HBA context object.
1277 * This function is called from SLI initialization code
1278 * to configure every ring of the HBA's SLI interface. The
1279 * caller is not required to hold any lock. This function issues
1280 * a config_ring mailbox command for each ring.
1281 * This function returns zero if successful else returns a negative
1285 lpfc_sli_ring_map(struct lpfc_hba
*phba
)
1287 struct lpfc_sli
*psli
= &phba
->sli
;
1292 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1296 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
1297 for (i
= 0; i
< psli
->num_rings
; i
++) {
1298 lpfc_config_ring(phba
, i
, pmb
);
1299 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
1300 if (rc
!= MBX_SUCCESS
) {
1301 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1302 "0446 Adapter failed to init (%d), "
1303 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
1305 rc
, pmbox
->mbxCommand
,
1306 pmbox
->mbxStatus
, i
);
1307 phba
->link_state
= LPFC_HBA_ERROR
;
1312 mempool_free(pmb
, phba
->mbox_mem_pool
);
1317 * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
1318 * @phba: Pointer to HBA context object.
1319 * @pring: Pointer to driver SLI ring object.
1320 * @piocb: Pointer to the driver iocb object.
1322 * This function is called with hbalock held. The function adds the
1323 * new iocb to txcmplq of the given ring. This function always returns
1324 * 0. If this function is called for ELS ring, this function checks if
1325 * there is a vport associated with the ELS command. This function also
1326 * starts els_tmofunc timer if this is an ELS command.
1329 lpfc_sli_ringtxcmpl_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1330 struct lpfc_iocbq
*piocb
)
1332 list_add_tail(&piocb
->list
, &pring
->txcmplq
);
1333 piocb
->iocb_flag
|= LPFC_IO_ON_TXCMPLQ
;
1335 if ((unlikely(pring
->ringno
== LPFC_ELS_RING
)) &&
1336 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
1337 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
1341 mod_timer(&piocb
->vport
->els_tmofunc
,
1342 jiffies
+ HZ
* (phba
->fc_ratov
<< 1));
1350 * lpfc_sli_ringtx_get - Get first element of the txq
1351 * @phba: Pointer to HBA context object.
1352 * @pring: Pointer to driver SLI ring object.
1354 * This function is called with hbalock held to get next
1355 * iocb in txq of the given ring. If there is any iocb in
1356 * the txq, the function returns first iocb in the list after
1357 * removing the iocb from the list, else it returns NULL.
1360 lpfc_sli_ringtx_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1362 struct lpfc_iocbq
*cmd_iocb
;
1364 list_remove_head((&pring
->txq
), cmd_iocb
, struct lpfc_iocbq
, list
);
1369 * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
1370 * @phba: Pointer to HBA context object.
1371 * @pring: Pointer to driver SLI ring object.
1373 * This function is called with hbalock held and the caller must post the
1374 * iocb without releasing the lock. If the caller releases the lock,
1375 * iocb slot returned by the function is not guaranteed to be available.
1376 * The function returns pointer to the next available iocb slot if there
1377 * is available slot in the ring, else it returns NULL.
1378 * If the get index of the ring is ahead of the put index, the function
1379 * will post an error attention event to the worker thread to take the
1380 * HBA to offline state.
1383 lpfc_sli_next_iocb_slot (struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1385 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
1386 uint32_t max_cmd_idx
= pring
->sli
.sli3
.numCiocb
;
1387 if ((pring
->sli
.sli3
.next_cmdidx
== pring
->sli
.sli3
.cmdidx
) &&
1388 (++pring
->sli
.sli3
.next_cmdidx
>= max_cmd_idx
))
1389 pring
->sli
.sli3
.next_cmdidx
= 0;
1391 if (unlikely(pring
->sli
.sli3
.local_getidx
==
1392 pring
->sli
.sli3
.next_cmdidx
)) {
1394 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
1396 if (unlikely(pring
->sli
.sli3
.local_getidx
>= max_cmd_idx
)) {
1397 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
1398 "0315 Ring %d issue: portCmdGet %d "
1399 "is bigger than cmd ring %d\n",
1401 pring
->sli
.sli3
.local_getidx
,
1404 phba
->link_state
= LPFC_HBA_ERROR
;
1406 * All error attention handlers are posted to
1409 phba
->work_ha
|= HA_ERATT
;
1410 phba
->work_hs
= HS_FFER3
;
1412 lpfc_worker_wake_up(phba
);
1417 if (pring
->sli
.sli3
.local_getidx
== pring
->sli
.sli3
.next_cmdidx
)
1421 return lpfc_cmd_iocb(phba
, pring
);
1425 * lpfc_sli_next_iotag - Get an iotag for the iocb
1426 * @phba: Pointer to HBA context object.
1427 * @iocbq: Pointer to driver iocb object.
1429 * This function gets an iotag for the iocb. If there is no unused iotag and
1430 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
1431 * array and assigns a new iotag.
1432 * The function returns the allocated iotag if successful, else returns zero.
1433 * Zero is not a valid iotag.
1434 * The caller is not required to hold any lock.
1437 lpfc_sli_next_iotag(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
)
1439 struct lpfc_iocbq
**new_arr
;
1440 struct lpfc_iocbq
**old_arr
;
1442 struct lpfc_sli
*psli
= &phba
->sli
;
1445 spin_lock_irq(&phba
->hbalock
);
1446 iotag
= psli
->last_iotag
;
1447 if(++iotag
< psli
->iocbq_lookup_len
) {
1448 psli
->last_iotag
= iotag
;
1449 psli
->iocbq_lookup
[iotag
] = iocbq
;
1450 spin_unlock_irq(&phba
->hbalock
);
1451 iocbq
->iotag
= iotag
;
1453 } else if (psli
->iocbq_lookup_len
< (0xffff
1454 - LPFC_IOCBQ_LOOKUP_INCREMENT
)) {
1455 new_len
= psli
->iocbq_lookup_len
+ LPFC_IOCBQ_LOOKUP_INCREMENT
;
1456 spin_unlock_irq(&phba
->hbalock
);
1457 new_arr
= kzalloc(new_len
* sizeof (struct lpfc_iocbq
*),
1460 spin_lock_irq(&phba
->hbalock
);
1461 old_arr
= psli
->iocbq_lookup
;
1462 if (new_len
<= psli
->iocbq_lookup_len
) {
1463 /* highly unprobable case */
1465 iotag
= psli
->last_iotag
;
1466 if(++iotag
< psli
->iocbq_lookup_len
) {
1467 psli
->last_iotag
= iotag
;
1468 psli
->iocbq_lookup
[iotag
] = iocbq
;
1469 spin_unlock_irq(&phba
->hbalock
);
1470 iocbq
->iotag
= iotag
;
1473 spin_unlock_irq(&phba
->hbalock
);
1476 if (psli
->iocbq_lookup
)
1477 memcpy(new_arr
, old_arr
,
1478 ((psli
->last_iotag
+ 1) *
1479 sizeof (struct lpfc_iocbq
*)));
1480 psli
->iocbq_lookup
= new_arr
;
1481 psli
->iocbq_lookup_len
= new_len
;
1482 psli
->last_iotag
= iotag
;
1483 psli
->iocbq_lookup
[iotag
] = iocbq
;
1484 spin_unlock_irq(&phba
->hbalock
);
1485 iocbq
->iotag
= iotag
;
1490 spin_unlock_irq(&phba
->hbalock
);
1492 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
1493 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1500 * lpfc_sli_submit_iocb - Submit an iocb to the firmware
1501 * @phba: Pointer to HBA context object.
1502 * @pring: Pointer to driver SLI ring object.
1503 * @iocb: Pointer to iocb slot in the ring.
1504 * @nextiocb: Pointer to driver iocb object which need to be
1505 * posted to firmware.
1507 * This function is called with hbalock held to post a new iocb to
1508 * the firmware. This function copies the new iocb to ring iocb slot and
1509 * updates the ring pointers. It adds the new iocb to txcmplq if there is
1510 * a completion call back for this iocb else the function will free the
1514 lpfc_sli_submit_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
1515 IOCB_t
*iocb
, struct lpfc_iocbq
*nextiocb
)
1520 nextiocb
->iocb
.ulpIoTag
= (nextiocb
->iocb_cmpl
) ? nextiocb
->iotag
: 0;
1523 if (pring
->ringno
== LPFC_ELS_RING
) {
1524 lpfc_debugfs_slow_ring_trc(phba
,
1525 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
1526 *(((uint32_t *) &nextiocb
->iocb
) + 4),
1527 *(((uint32_t *) &nextiocb
->iocb
) + 6),
1528 *(((uint32_t *) &nextiocb
->iocb
) + 7));
1532 * Issue iocb command to adapter
1534 lpfc_sli_pcimem_bcopy(&nextiocb
->iocb
, iocb
, phba
->iocb_cmd_size
);
1536 pring
->stats
.iocb_cmd
++;
1539 * If there is no completion routine to call, we can release the
1540 * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
1541 * that have no rsp ring completion, iocb_cmpl MUST be NULL.
1543 if (nextiocb
->iocb_cmpl
)
1544 lpfc_sli_ringtxcmpl_put(phba
, pring
, nextiocb
);
1546 __lpfc_sli_release_iocbq(phba
, nextiocb
);
1549 * Let the HBA know what IOCB slot will be the next one the
1550 * driver will put a command into.
1552 pring
->sli
.sli3
.cmdidx
= pring
->sli
.sli3
.next_cmdidx
;
1553 writel(pring
->sli
.sli3
.cmdidx
, &phba
->host_gp
[pring
->ringno
].cmdPutInx
);
1557 * lpfc_sli_update_full_ring - Update the chip attention register
1558 * @phba: Pointer to HBA context object.
1559 * @pring: Pointer to driver SLI ring object.
1561 * The caller is not required to hold any lock for calling this function.
1562 * This function updates the chip attention bits for the ring to inform firmware
1563 * that there are pending work to be done for this ring and requests an
1564 * interrupt when there is space available in the ring. This function is
1565 * called when the driver is unable to post more iocbs to the ring due
1566 * to unavailability of space in the ring.
1569 lpfc_sli_update_full_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1571 int ringno
= pring
->ringno
;
1573 pring
->flag
|= LPFC_CALL_RING_AVAILABLE
;
1578 * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
1579 * The HBA will tell us when an IOCB entry is available.
1581 writel((CA_R0ATT
|CA_R0CE_REQ
) << (ringno
*4), phba
->CAregaddr
);
1582 readl(phba
->CAregaddr
); /* flush */
1584 pring
->stats
.iocb_cmd_full
++;
1588 * lpfc_sli_update_ring - Update chip attention register
1589 * @phba: Pointer to HBA context object.
1590 * @pring: Pointer to driver SLI ring object.
1592 * This function updates the chip attention register bit for the
1593 * given ring to inform HBA that there is more work to be done
1594 * in this ring. The caller is not required to hold any lock.
1597 lpfc_sli_update_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1599 int ringno
= pring
->ringno
;
1602 * Tell the HBA that there is work to do in this ring.
1604 if (!(phba
->sli3_options
& LPFC_SLI3_CRP_ENABLED
)) {
1606 writel(CA_R0ATT
<< (ringno
* 4), phba
->CAregaddr
);
1607 readl(phba
->CAregaddr
); /* flush */
1612 * lpfc_sli_resume_iocb - Process iocbs in the txq
1613 * @phba: Pointer to HBA context object.
1614 * @pring: Pointer to driver SLI ring object.
1616 * This function is called with hbalock held to post pending iocbs
1617 * in the txq to the firmware. This function is called when driver
1618 * detects space available in the ring.
1621 lpfc_sli_resume_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
1624 struct lpfc_iocbq
*nextiocb
;
1628 * (a) there is anything on the txq to send
1630 * (c) link attention events can be processed (fcp ring only)
1631 * (d) IOCB processing is not blocked by the outstanding mbox command.
1634 if (lpfc_is_link_up(phba
) &&
1635 (!list_empty(&pring
->txq
)) &&
1636 (pring
->ringno
!= phba
->sli
.fcp_ring
||
1637 phba
->sli
.sli_flag
& LPFC_PROCESS_LA
)) {
1639 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
1640 (nextiocb
= lpfc_sli_ringtx_get(phba
, pring
)))
1641 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
1644 lpfc_sli_update_ring(phba
, pring
);
1646 lpfc_sli_update_full_ring(phba
, pring
);
1653 * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
1654 * @phba: Pointer to HBA context object.
1655 * @hbqno: HBQ number.
1657 * This function is called with hbalock held to get the next
1658 * available slot for the given HBQ. If there is free slot
1659 * available for the HBQ it will return pointer to the next available
1660 * HBQ entry else it will return NULL.
1662 static struct lpfc_hbq_entry
*
1663 lpfc_sli_next_hbq_slot(struct lpfc_hba
*phba
, uint32_t hbqno
)
1665 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1667 if (hbqp
->next_hbqPutIdx
== hbqp
->hbqPutIdx
&&
1668 ++hbqp
->next_hbqPutIdx
>= hbqp
->entry_count
)
1669 hbqp
->next_hbqPutIdx
= 0;
1671 if (unlikely(hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)) {
1672 uint32_t raw_index
= phba
->hbq_get
[hbqno
];
1673 uint32_t getidx
= le32_to_cpu(raw_index
);
1675 hbqp
->local_hbqGetIdx
= getidx
;
1677 if (unlikely(hbqp
->local_hbqGetIdx
>= hbqp
->entry_count
)) {
1678 lpfc_printf_log(phba
, KERN_ERR
,
1679 LOG_SLI
| LOG_VPORT
,
1680 "1802 HBQ %d: local_hbqGetIdx "
1681 "%u is > than hbqp->entry_count %u\n",
1682 hbqno
, hbqp
->local_hbqGetIdx
,
1685 phba
->link_state
= LPFC_HBA_ERROR
;
1689 if (hbqp
->local_hbqGetIdx
== hbqp
->next_hbqPutIdx
)
1693 return (struct lpfc_hbq_entry
*) phba
->hbqs
[hbqno
].hbq_virt
+
1698 * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
1699 * @phba: Pointer to HBA context object.
1701 * This function is called with no lock held to free all the
1702 * hbq buffers while uninitializing the SLI interface. It also
1703 * frees the HBQ buffers returned by the firmware but not yet
1704 * processed by the upper layers.
1707 lpfc_sli_hbqbuf_free_all(struct lpfc_hba
*phba
)
1709 struct lpfc_dmabuf
*dmabuf
, *next_dmabuf
;
1710 struct hbq_dmabuf
*hbq_buf
;
1711 unsigned long flags
;
1715 hbq_count
= lpfc_sli_hbq_count();
1716 /* Return all memory used by all HBQs */
1717 spin_lock_irqsave(&phba
->hbalock
, flags
);
1718 for (i
= 0; i
< hbq_count
; ++i
) {
1719 list_for_each_entry_safe(dmabuf
, next_dmabuf
,
1720 &phba
->hbqs
[i
].hbq_buffer_list
, list
) {
1721 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1722 list_del(&hbq_buf
->dbuf
.list
);
1723 (phba
->hbqs
[i
].hbq_free_buffer
)(phba
, hbq_buf
);
1725 phba
->hbqs
[i
].buffer_count
= 0;
1727 /* Return all HBQ buffer that are in-fly */
1728 list_for_each_entry_safe(dmabuf
, next_dmabuf
, &phba
->rb_pend_list
,
1730 hbq_buf
= container_of(dmabuf
, struct hbq_dmabuf
, dbuf
);
1731 list_del(&hbq_buf
->dbuf
.list
);
1732 if (hbq_buf
->tag
== -1) {
1733 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1736 hbqno
= hbq_buf
->tag
>> 16;
1737 if (hbqno
>= LPFC_MAX_HBQS
)
1738 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
1741 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
,
1746 /* Mark the HBQs not in use */
1747 phba
->hbq_in_use
= 0;
1748 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1752 * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
1753 * @phba: Pointer to HBA context object.
1754 * @hbqno: HBQ number.
1755 * @hbq_buf: Pointer to HBQ buffer.
1757 * This function is called with the hbalock held to post a
1758 * hbq buffer to the firmware. If the function finds an empty
1759 * slot in the HBQ, it will post the buffer. The function will return
1760 * pointer to the hbq entry if it successfully post the buffer
1761 * else it will return NULL.
1764 lpfc_sli_hbq_to_firmware(struct lpfc_hba
*phba
, uint32_t hbqno
,
1765 struct hbq_dmabuf
*hbq_buf
)
1767 return phba
->lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buf
);
1771 * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
1772 * @phba: Pointer to HBA context object.
1773 * @hbqno: HBQ number.
1774 * @hbq_buf: Pointer to HBQ buffer.
1776 * This function is called with the hbalock held to post a hbq buffer to the
1777 * firmware. If the function finds an empty slot in the HBQ, it will post the
1778 * buffer and place it on the hbq_buffer_list. The function will return zero if
1779 * it successfully post the buffer else it will return an error.
1782 lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba
*phba
, uint32_t hbqno
,
1783 struct hbq_dmabuf
*hbq_buf
)
1785 struct lpfc_hbq_entry
*hbqe
;
1786 dma_addr_t physaddr
= hbq_buf
->dbuf
.phys
;
1788 /* Get next HBQ entry slot to use */
1789 hbqe
= lpfc_sli_next_hbq_slot(phba
, hbqno
);
1791 struct hbq_s
*hbqp
= &phba
->hbqs
[hbqno
];
1793 hbqe
->bde
.addrHigh
= le32_to_cpu(putPaddrHigh(physaddr
));
1794 hbqe
->bde
.addrLow
= le32_to_cpu(putPaddrLow(physaddr
));
1795 hbqe
->bde
.tus
.f
.bdeSize
= hbq_buf
->size
;
1796 hbqe
->bde
.tus
.f
.bdeFlags
= 0;
1797 hbqe
->bde
.tus
.w
= le32_to_cpu(hbqe
->bde
.tus
.w
);
1798 hbqe
->buffer_tag
= le32_to_cpu(hbq_buf
->tag
);
1800 hbqp
->hbqPutIdx
= hbqp
->next_hbqPutIdx
;
1801 writel(hbqp
->hbqPutIdx
, phba
->hbq_put
+ hbqno
);
1803 readl(phba
->hbq_put
+ hbqno
);
1804 list_add_tail(&hbq_buf
->dbuf
.list
, &hbqp
->hbq_buffer_list
);
1811 * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
1812 * @phba: Pointer to HBA context object.
1813 * @hbqno: HBQ number.
1814 * @hbq_buf: Pointer to HBQ buffer.
1816 * This function is called with the hbalock held to post an RQE to the SLI4
1817 * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
1818 * the hbq_buffer_list and return zero, otherwise it will return an error.
1821 lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba
*phba
, uint32_t hbqno
,
1822 struct hbq_dmabuf
*hbq_buf
)
1825 struct lpfc_rqe hrqe
;
1826 struct lpfc_rqe drqe
;
1828 hrqe
.address_lo
= putPaddrLow(hbq_buf
->hbuf
.phys
);
1829 hrqe
.address_hi
= putPaddrHigh(hbq_buf
->hbuf
.phys
);
1830 drqe
.address_lo
= putPaddrLow(hbq_buf
->dbuf
.phys
);
1831 drqe
.address_hi
= putPaddrHigh(hbq_buf
->dbuf
.phys
);
1832 rc
= lpfc_sli4_rq_put(phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
1837 list_add_tail(&hbq_buf
->dbuf
.list
, &phba
->hbqs
[hbqno
].hbq_buffer_list
);
1841 /* HBQ for ELS and CT traffic. */
1842 static struct lpfc_hbq_init lpfc_els_hbq
= {
1847 .ring_mask
= (1 << LPFC_ELS_RING
),
1853 /* HBQ for the extra ring if needed */
1854 static struct lpfc_hbq_init lpfc_extra_hbq
= {
1859 .ring_mask
= (1 << LPFC_EXTRA_RING
),
1866 struct lpfc_hbq_init
*lpfc_hbq_defs
[] = {
1872 * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
1873 * @phba: Pointer to HBA context object.
1874 * @hbqno: HBQ number.
1875 * @count: Number of HBQ buffers to be posted.
1877 * This function is called with no lock held to post more hbq buffers to the
1878 * given HBQ. The function returns the number of HBQ buffers successfully
1882 lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba
*phba
, uint32_t hbqno
, uint32_t count
)
1884 uint32_t i
, posted
= 0;
1885 unsigned long flags
;
1886 struct hbq_dmabuf
*hbq_buffer
;
1887 LIST_HEAD(hbq_buf_list
);
1888 if (!phba
->hbqs
[hbqno
].hbq_alloc_buffer
)
1891 if ((phba
->hbqs
[hbqno
].buffer_count
+ count
) >
1892 lpfc_hbq_defs
[hbqno
]->entry_count
)
1893 count
= lpfc_hbq_defs
[hbqno
]->entry_count
-
1894 phba
->hbqs
[hbqno
].buffer_count
;
1897 /* Allocate HBQ entries */
1898 for (i
= 0; i
< count
; i
++) {
1899 hbq_buffer
= (phba
->hbqs
[hbqno
].hbq_alloc_buffer
)(phba
);
1902 list_add_tail(&hbq_buffer
->dbuf
.list
, &hbq_buf_list
);
1904 /* Check whether HBQ is still in use */
1905 spin_lock_irqsave(&phba
->hbalock
, flags
);
1906 if (!phba
->hbq_in_use
)
1908 while (!list_empty(&hbq_buf_list
)) {
1909 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1911 hbq_buffer
->tag
= (phba
->hbqs
[hbqno
].buffer_count
|
1913 if (!lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
)) {
1914 phba
->hbqs
[hbqno
].buffer_count
++;
1917 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1919 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1922 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1923 while (!list_empty(&hbq_buf_list
)) {
1924 list_remove_head(&hbq_buf_list
, hbq_buffer
, struct hbq_dmabuf
,
1926 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
1932 * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
1933 * @phba: Pointer to HBA context object.
1936 * This function posts more buffers to the HBQ. This function
1937 * is called with no lock held. The function returns the number of HBQ entries
1938 * successfully allocated.
1941 lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1943 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1946 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1947 lpfc_hbq_defs
[qno
]->add_count
);
1951 * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
1952 * @phba: Pointer to HBA context object.
1953 * @qno: HBQ queue number.
1955 * This function is called from SLI initialization code path with
1956 * no lock held to post initial HBQ buffers to firmware. The
1957 * function returns the number of HBQ entries successfully allocated.
1960 lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba
*phba
, uint32_t qno
)
1962 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1963 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1964 lpfc_hbq_defs
[qno
]->entry_count
);
1966 return lpfc_sli_hbqbuf_fill_hbqs(phba
, qno
,
1967 lpfc_hbq_defs
[qno
]->init_count
);
1971 * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
1972 * @phba: Pointer to HBA context object.
1973 * @hbqno: HBQ number.
1975 * This function removes the first hbq buffer on an hbq list and returns a
1976 * pointer to that buffer. If it finds no buffers on the list it returns NULL.
1978 static struct hbq_dmabuf
*
1979 lpfc_sli_hbqbuf_get(struct list_head
*rb_list
)
1981 struct lpfc_dmabuf
*d_buf
;
1983 list_remove_head(rb_list
, d_buf
, struct lpfc_dmabuf
, list
);
1986 return container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
1990 * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
1991 * @phba: Pointer to HBA context object.
1992 * @tag: Tag of the hbq buffer.
1994 * This function is called with hbalock held. This function searches
1995 * for the hbq buffer associated with the given tag in the hbq buffer
1996 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
1999 static struct hbq_dmabuf
*
2000 lpfc_sli_hbqbuf_find(struct lpfc_hba
*phba
, uint32_t tag
)
2002 struct lpfc_dmabuf
*d_buf
;
2003 struct hbq_dmabuf
*hbq_buf
;
2007 if (hbqno
>= LPFC_MAX_HBQS
)
2010 spin_lock_irq(&phba
->hbalock
);
2011 list_for_each_entry(d_buf
, &phba
->hbqs
[hbqno
].hbq_buffer_list
, list
) {
2012 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
2013 if (hbq_buf
->tag
== tag
) {
2014 spin_unlock_irq(&phba
->hbalock
);
2018 spin_unlock_irq(&phba
->hbalock
);
2019 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
| LOG_VPORT
,
2020 "1803 Bad hbq tag. Data: x%x x%x\n",
2021 tag
, phba
->hbqs
[tag
>> 16].buffer_count
);
2026 * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
2027 * @phba: Pointer to HBA context object.
2028 * @hbq_buffer: Pointer to HBQ buffer.
2030 * This function is called with hbalock. This function gives back
2031 * the hbq buffer to firmware. If the HBQ does not have space to
2032 * post the buffer, it will free the buffer.
2035 lpfc_sli_free_hbq(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbq_buffer
)
2040 hbqno
= hbq_buffer
->tag
>> 16;
2041 if (lpfc_sli_hbq_to_firmware(phba
, hbqno
, hbq_buffer
))
2042 (phba
->hbqs
[hbqno
].hbq_free_buffer
)(phba
, hbq_buffer
);
2047 * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
2048 * @mbxCommand: mailbox command code.
2050 * This function is called by the mailbox event handler function to verify
2051 * that the completed mailbox command is a legitimate mailbox command. If the
2052 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
2053 * and the mailbox event handler will take the HBA offline.
2056 lpfc_sli_chk_mbx_command(uint8_t mbxCommand
)
2060 switch (mbxCommand
) {
2064 case MBX_WRITE_VPARMS
:
2065 case MBX_RUN_BIU_DIAG
:
2068 case MBX_CONFIG_LINK
:
2069 case MBX_CONFIG_RING
:
2070 case MBX_RESET_RING
:
2071 case MBX_READ_CONFIG
:
2072 case MBX_READ_RCONFIG
:
2073 case MBX_READ_SPARM
:
2074 case MBX_READ_STATUS
:
2078 case MBX_READ_LNK_STAT
:
2080 case MBX_UNREG_LOGIN
:
2082 case MBX_DUMP_MEMORY
:
2083 case MBX_DUMP_CONTEXT
:
2086 case MBX_UPDATE_CFG
:
2088 case MBX_DEL_LD_ENTRY
:
2089 case MBX_RUN_PROGRAM
:
2091 case MBX_SET_VARIABLE
:
2092 case MBX_UNREG_D_ID
:
2093 case MBX_KILL_BOARD
:
2094 case MBX_CONFIG_FARP
:
2097 case MBX_RUN_BIU_DIAG64
:
2098 case MBX_CONFIG_PORT
:
2099 case MBX_READ_SPARM64
:
2100 case MBX_READ_RPI64
:
2101 case MBX_REG_LOGIN64
:
2102 case MBX_READ_TOPOLOGY
:
2105 case MBX_LOAD_EXP_ROM
:
2106 case MBX_ASYNCEVT_ENABLE
:
2110 case MBX_PORT_CAPABILITIES
:
2111 case MBX_PORT_IOV_CONTROL
:
2112 case MBX_SLI4_CONFIG
:
2113 case MBX_SLI4_REQ_FTRS
:
2115 case MBX_UNREG_FCFI
:
2120 case MBX_RESUME_RPI
:
2121 case MBX_READ_EVENT_LOG_STATUS
:
2122 case MBX_READ_EVENT_LOG
:
2123 case MBX_SECURITY_MGMT
:
2125 case MBX_ACCESS_VDATA
:
2136 * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
2137 * @phba: Pointer to HBA context object.
2138 * @pmboxq: Pointer to mailbox command.
2140 * This is completion handler function for mailbox commands issued from
2141 * lpfc_sli_issue_mbox_wait function. This function is called by the
2142 * mailbox event handler function with no lock held. This function
2143 * will wake up thread waiting on the wait queue pointed by context1
2147 lpfc_sli_wake_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
2149 wait_queue_head_t
*pdone_q
;
2150 unsigned long drvr_flag
;
2153 * If pdone_q is empty, the driver thread gave up waiting and
2154 * continued running.
2156 pmboxq
->mbox_flag
|= LPFC_MBX_WAKE
;
2157 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
2158 pdone_q
= (wait_queue_head_t
*) pmboxq
->context1
;
2160 wake_up_interruptible(pdone_q
);
2161 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
2167 * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
2168 * @phba: Pointer to HBA context object.
2169 * @pmb: Pointer to mailbox object.
2171 * This function is the default mailbox completion handler. It
2172 * frees the memory resources associated with the completed mailbox
2173 * command. If the completed command is a REG_LOGIN mailbox command,
2174 * this function will issue a UREG_LOGIN to re-claim the RPI.
2177 lpfc_sli_def_mbox_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2179 struct lpfc_vport
*vport
= pmb
->vport
;
2180 struct lpfc_dmabuf
*mp
;
2181 struct lpfc_nodelist
*ndlp
;
2182 struct Scsi_Host
*shost
;
2186 mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2189 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2194 * If a REG_LOGIN succeeded after node is destroyed or node
2195 * is in re-discovery driver need to cleanup the RPI.
2197 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2198 pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
&&
2199 !pmb
->u
.mb
.mbxStatus
) {
2200 rpi
= pmb
->u
.mb
.un
.varWords
[0];
2201 vpi
= pmb
->u
.mb
.un
.varRegLogin
.vpi
;
2202 lpfc_unreg_login(phba
, vpi
, rpi
, pmb
);
2203 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2204 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2205 if (rc
!= MBX_NOT_FINISHED
)
2209 if ((pmb
->u
.mb
.mbxCommand
== MBX_REG_VPI
) &&
2210 !(phba
->pport
->load_flag
& FC_UNLOADING
) &&
2211 !pmb
->u
.mb
.mbxStatus
) {
2212 shost
= lpfc_shost_from_vport(vport
);
2213 spin_lock_irq(shost
->host_lock
);
2214 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2215 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2216 spin_unlock_irq(shost
->host_lock
);
2219 if (pmb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
2220 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
2222 pmb
->context2
= NULL
;
2225 /* Check security permission status on INIT_LINK mailbox command */
2226 if ((pmb
->u
.mb
.mbxCommand
== MBX_INIT_LINK
) &&
2227 (pmb
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
2228 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2229 "2860 SLI authentication is required "
2230 "for INIT_LINK but has not done yet\n");
2232 if (bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
) == MBX_SLI4_CONFIG
)
2233 lpfc_sli4_mbox_cmd_free(phba
, pmb
);
2235 mempool_free(pmb
, phba
->mbox_mem_pool
);
2239 * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
2240 * @phba: Pointer to HBA context object.
2242 * This function is called with no lock held. This function processes all
2243 * the completed mailbox commands and gives it to upper layers. The interrupt
2244 * service routine processes mailbox completion interrupt and adds completed
2245 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
2246 * Worker thread call lpfc_sli_handle_mb_event, which will return the
2247 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
2248 * function returns the mailbox commands to the upper layer by calling the
2249 * completion handler function of each mailbox.
2252 lpfc_sli_handle_mb_event(struct lpfc_hba
*phba
)
2259 phba
->sli
.slistat
.mbox_event
++;
2261 /* Get all completed mailboxe buffers into the cmplq */
2262 spin_lock_irq(&phba
->hbalock
);
2263 list_splice_init(&phba
->sli
.mboxq_cmpl
, &cmplq
);
2264 spin_unlock_irq(&phba
->hbalock
);
2266 /* Get a Mailbox buffer to setup mailbox commands for callback */
2268 list_remove_head(&cmplq
, pmb
, LPFC_MBOXQ_t
, list
);
2274 if (pmbox
->mbxCommand
!= MBX_HEARTBEAT
) {
2276 lpfc_debugfs_disc_trc(pmb
->vport
,
2277 LPFC_DISC_TRC_MBOX_VPORT
,
2278 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
2279 (uint32_t)pmbox
->mbxCommand
,
2280 pmbox
->un
.varWords
[0],
2281 pmbox
->un
.varWords
[1]);
2284 lpfc_debugfs_disc_trc(phba
->pport
,
2286 "MBOX cmpl: cmd:x%x mb:x%x x%x",
2287 (uint32_t)pmbox
->mbxCommand
,
2288 pmbox
->un
.varWords
[0],
2289 pmbox
->un
.varWords
[1]);
2294 * It is a fatal error if unknown mbox command completion.
2296 if (lpfc_sli_chk_mbx_command(pmbox
->mbxCommand
) ==
2298 /* Unknown mailbox command compl */
2299 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
2300 "(%d):0323 Unknown Mailbox command "
2301 "x%x (x%x/x%x) Cmpl\n",
2302 pmb
->vport
? pmb
->vport
->vpi
: 0,
2304 lpfc_sli_config_mbox_subsys_get(phba
,
2306 lpfc_sli_config_mbox_opcode_get(phba
,
2308 phba
->link_state
= LPFC_HBA_ERROR
;
2309 phba
->work_hs
= HS_FFER3
;
2310 lpfc_handle_eratt(phba
);
2314 if (pmbox
->mbxStatus
) {
2315 phba
->sli
.slistat
.mbox_stat_err
++;
2316 if (pmbox
->mbxStatus
== MBXERR_NO_RESOURCES
) {
2317 /* Mbox cmd cmpl error - RETRYing */
2318 lpfc_printf_log(phba
, KERN_INFO
,
2320 "(%d):0305 Mbox cmd cmpl "
2321 "error - RETRYing Data: x%x "
2322 "(x%x/x%x) x%x x%x x%x\n",
2323 pmb
->vport
? pmb
->vport
->vpi
: 0,
2325 lpfc_sli_config_mbox_subsys_get(phba
,
2327 lpfc_sli_config_mbox_opcode_get(phba
,
2330 pmbox
->un
.varWords
[0],
2331 pmb
->vport
->port_state
);
2332 pmbox
->mbxStatus
= 0;
2333 pmbox
->mbxOwner
= OWN_HOST
;
2334 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
2335 if (rc
!= MBX_NOT_FINISHED
)
2340 /* Mailbox cmd <cmd> Cmpl <cmpl> */
2341 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
2342 "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p "
2343 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
2344 pmb
->vport
? pmb
->vport
->vpi
: 0,
2346 lpfc_sli_config_mbox_subsys_get(phba
, pmb
),
2347 lpfc_sli_config_mbox_opcode_get(phba
, pmb
),
2349 *((uint32_t *) pmbox
),
2350 pmbox
->un
.varWords
[0],
2351 pmbox
->un
.varWords
[1],
2352 pmbox
->un
.varWords
[2],
2353 pmbox
->un
.varWords
[3],
2354 pmbox
->un
.varWords
[4],
2355 pmbox
->un
.varWords
[5],
2356 pmbox
->un
.varWords
[6],
2357 pmbox
->un
.varWords
[7]);
2360 pmb
->mbox_cmpl(phba
,pmb
);
2366 * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
2367 * @phba: Pointer to HBA context object.
2368 * @pring: Pointer to driver SLI ring object.
2371 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
2372 * is set in the tag the buffer is posted for a particular exchange,
2373 * the function will return the buffer without replacing the buffer.
2374 * If the buffer is for unsolicited ELS or CT traffic, this function
2375 * returns the buffer and also posts another buffer to the firmware.
2377 static struct lpfc_dmabuf
*
2378 lpfc_sli_get_buff(struct lpfc_hba
*phba
,
2379 struct lpfc_sli_ring
*pring
,
2382 struct hbq_dmabuf
*hbq_entry
;
2384 if (tag
& QUE_BUFTAG_BIT
)
2385 return lpfc_sli_ring_taggedbuf_get(phba
, pring
, tag
);
2386 hbq_entry
= lpfc_sli_hbqbuf_find(phba
, tag
);
2389 return &hbq_entry
->dbuf
;
2393 * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
2394 * @phba: Pointer to HBA context object.
2395 * @pring: Pointer to driver SLI ring object.
2396 * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
2397 * @fch_r_ctl: the r_ctl for the first frame of the sequence.
2398 * @fch_type: the type for the first frame of the sequence.
2400 * This function is called with no lock held. This function uses the r_ctl and
2401 * type of the received sequence to find the correct callback function to call
2402 * to process the sequence.
2405 lpfc_complete_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2406 struct lpfc_iocbq
*saveq
, uint32_t fch_r_ctl
,
2411 /* unSolicited Responses */
2412 if (pring
->prt
[0].profile
) {
2413 if (pring
->prt
[0].lpfc_sli_rcv_unsol_event
)
2414 (pring
->prt
[0].lpfc_sli_rcv_unsol_event
) (phba
, pring
,
2418 /* We must search, based on rctl / type
2419 for the right routine */
2420 for (i
= 0; i
< pring
->num_mask
; i
++) {
2421 if ((pring
->prt
[i
].rctl
== fch_r_ctl
) &&
2422 (pring
->prt
[i
].type
== fch_type
)) {
2423 if (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2424 (pring
->prt
[i
].lpfc_sli_rcv_unsol_event
)
2425 (phba
, pring
, saveq
);
2433 * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
2434 * @phba: Pointer to HBA context object.
2435 * @pring: Pointer to driver SLI ring object.
2436 * @saveq: Pointer to the unsolicited iocb.
2438 * This function is called with no lock held by the ring event handler
2439 * when there is an unsolicited iocb posted to the response ring by the
2440 * firmware. This function gets the buffer associated with the iocbs
2441 * and calls the event handler for the ring. This function handles both
2442 * qring buffers and hbq buffers.
2443 * When the function returns 1 the caller can free the iocb object otherwise
2444 * upper layer functions will free the iocb objects.
2447 lpfc_sli_process_unsol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2448 struct lpfc_iocbq
*saveq
)
2452 uint32_t Rctl
, Type
;
2454 struct lpfc_iocbq
*iocbq
;
2455 struct lpfc_dmabuf
*dmzbuf
;
2458 irsp
= &(saveq
->iocb
);
2460 if (irsp
->ulpCommand
== CMD_ASYNC_STATUS
) {
2461 if (pring
->lpfc_sli_rcv_async_status
)
2462 pring
->lpfc_sli_rcv_async_status(phba
, pring
, saveq
);
2464 lpfc_printf_log(phba
,
2467 "0316 Ring %d handler: unexpected "
2468 "ASYNC_STATUS iocb received evt_code "
2471 irsp
->un
.asyncstat
.evt_code
);
2475 if ((irsp
->ulpCommand
== CMD_IOCB_RET_XRI64_CX
) &&
2476 (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)) {
2477 if (irsp
->ulpBdeCount
> 0) {
2478 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2479 irsp
->un
.ulpWord
[3]);
2480 lpfc_in_buf_free(phba
, dmzbuf
);
2483 if (irsp
->ulpBdeCount
> 1) {
2484 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2485 irsp
->unsli3
.sli3Words
[3]);
2486 lpfc_in_buf_free(phba
, dmzbuf
);
2489 if (irsp
->ulpBdeCount
> 2) {
2490 dmzbuf
= lpfc_sli_get_buff(phba
, pring
,
2491 irsp
->unsli3
.sli3Words
[7]);
2492 lpfc_in_buf_free(phba
, dmzbuf
);
2498 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
2499 if (irsp
->ulpBdeCount
!= 0) {
2500 saveq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2501 irsp
->un
.ulpWord
[3]);
2502 if (!saveq
->context2
)
2503 lpfc_printf_log(phba
,
2506 "0341 Ring %d Cannot find buffer for "
2507 "an unsolicited iocb. tag 0x%x\n",
2509 irsp
->un
.ulpWord
[3]);
2511 if (irsp
->ulpBdeCount
== 2) {
2512 saveq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2513 irsp
->unsli3
.sli3Words
[7]);
2514 if (!saveq
->context3
)
2515 lpfc_printf_log(phba
,
2518 "0342 Ring %d Cannot find buffer for an"
2519 " unsolicited iocb. tag 0x%x\n",
2521 irsp
->unsli3
.sli3Words
[7]);
2523 list_for_each_entry(iocbq
, &saveq
->list
, list
) {
2524 irsp
= &(iocbq
->iocb
);
2525 if (irsp
->ulpBdeCount
!= 0) {
2526 iocbq
->context2
= lpfc_sli_get_buff(phba
, pring
,
2527 irsp
->un
.ulpWord
[3]);
2528 if (!iocbq
->context2
)
2529 lpfc_printf_log(phba
,
2532 "0343 Ring %d Cannot find "
2533 "buffer for an unsolicited iocb"
2534 ". tag 0x%x\n", pring
->ringno
,
2535 irsp
->un
.ulpWord
[3]);
2537 if (irsp
->ulpBdeCount
== 2) {
2538 iocbq
->context3
= lpfc_sli_get_buff(phba
, pring
,
2539 irsp
->unsli3
.sli3Words
[7]);
2540 if (!iocbq
->context3
)
2541 lpfc_printf_log(phba
,
2544 "0344 Ring %d Cannot find "
2545 "buffer for an unsolicited "
2548 irsp
->unsli3
.sli3Words
[7]);
2552 if (irsp
->ulpBdeCount
!= 0 &&
2553 (irsp
->ulpCommand
== CMD_IOCB_RCV_CONT64_CX
||
2554 irsp
->ulpStatus
== IOSTAT_INTERMED_RSP
)) {
2557 /* search continue save q for same XRI */
2558 list_for_each_entry(iocbq
, &pring
->iocb_continue_saveq
, clist
) {
2559 if (iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
==
2560 saveq
->iocb
.unsli3
.rcvsli3
.ox_id
) {
2561 list_add_tail(&saveq
->list
, &iocbq
->list
);
2567 list_add_tail(&saveq
->clist
,
2568 &pring
->iocb_continue_saveq
);
2569 if (saveq
->iocb
.ulpStatus
!= IOSTAT_INTERMED_RSP
) {
2570 list_del_init(&iocbq
->clist
);
2572 irsp
= &(saveq
->iocb
);
2576 if ((irsp
->ulpCommand
== CMD_RCV_ELS_REQ64_CX
) ||
2577 (irsp
->ulpCommand
== CMD_RCV_ELS_REQ_CX
) ||
2578 (irsp
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
)) {
2579 Rctl
= FC_RCTL_ELS_REQ
;
2582 w5p
= (WORD5
*)&(saveq
->iocb
.un
.ulpWord
[5]);
2583 Rctl
= w5p
->hcsw
.Rctl
;
2584 Type
= w5p
->hcsw
.Type
;
2586 /* Firmware Workaround */
2587 if ((Rctl
== 0) && (pring
->ringno
== LPFC_ELS_RING
) &&
2588 (irsp
->ulpCommand
== CMD_RCV_SEQUENCE64_CX
||
2589 irsp
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
2590 Rctl
= FC_RCTL_ELS_REQ
;
2592 w5p
->hcsw
.Rctl
= Rctl
;
2593 w5p
->hcsw
.Type
= Type
;
2597 if (!lpfc_complete_unsol_iocb(phba
, pring
, saveq
, Rctl
, Type
))
2598 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2599 "0313 Ring %d handler: unexpected Rctl x%x "
2600 "Type x%x received\n",
2601 pring
->ringno
, Rctl
, Type
);
2607 * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
2608 * @phba: Pointer to HBA context object.
2609 * @pring: Pointer to driver SLI ring object.
2610 * @prspiocb: Pointer to response iocb object.
2612 * This function looks up the iocb_lookup table to get the command iocb
2613 * corresponding to the given response iocb using the iotag of the
2614 * response iocb. This function is called with the hbalock held.
2615 * This function returns the command iocb object if it finds the command
2616 * iocb else returns NULL.
2618 static struct lpfc_iocbq
*
2619 lpfc_sli_iocbq_lookup(struct lpfc_hba
*phba
,
2620 struct lpfc_sli_ring
*pring
,
2621 struct lpfc_iocbq
*prspiocb
)
2623 struct lpfc_iocbq
*cmd_iocb
= NULL
;
2626 iotag
= prspiocb
->iocb
.ulpIoTag
;
2628 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2629 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2630 list_del_init(&cmd_iocb
->list
);
2631 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2632 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2637 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2638 "0317 iotag x%x is out off "
2639 "range: max iotag x%x wd0 x%x\n",
2640 iotag
, phba
->sli
.last_iotag
,
2641 *(((uint32_t *) &prspiocb
->iocb
) + 7));
2646 * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
2647 * @phba: Pointer to HBA context object.
2648 * @pring: Pointer to driver SLI ring object.
2651 * This function looks up the iocb_lookup table to get the command iocb
2652 * corresponding to the given iotag. This function is called with the
2654 * This function returns the command iocb object if it finds the command
2655 * iocb else returns NULL.
2657 static struct lpfc_iocbq
*
2658 lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba
*phba
,
2659 struct lpfc_sli_ring
*pring
, uint16_t iotag
)
2661 struct lpfc_iocbq
*cmd_iocb
;
2663 if (iotag
!= 0 && iotag
<= phba
->sli
.last_iotag
) {
2664 cmd_iocb
= phba
->sli
.iocbq_lookup
[iotag
];
2665 if (cmd_iocb
->iocb_flag
& LPFC_IO_ON_TXCMPLQ
) {
2666 /* remove from txcmpl queue list */
2667 list_del_init(&cmd_iocb
->list
);
2668 cmd_iocb
->iocb_flag
&= ~LPFC_IO_ON_TXCMPLQ
;
2672 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2673 "0372 iotag x%x is out off range: max iotag (x%x)\n",
2674 iotag
, phba
->sli
.last_iotag
);
2679 * lpfc_sli_process_sol_iocb - process solicited iocb completion
2680 * @phba: Pointer to HBA context object.
2681 * @pring: Pointer to driver SLI ring object.
2682 * @saveq: Pointer to the response iocb to be processed.
2684 * This function is called by the ring event handler for non-fcp
2685 * rings when there is a new response iocb in the response ring.
2686 * The caller is not required to hold any locks. This function
2687 * gets the command iocb associated with the response iocb and
2688 * calls the completion handler for the command iocb. If there
2689 * is no completion handler, the function will free the resources
2690 * associated with command iocb. If the response iocb is for
2691 * an already aborted command iocb, the status of the completion
2692 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
2693 * This function always returns 1.
2696 lpfc_sli_process_sol_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
2697 struct lpfc_iocbq
*saveq
)
2699 struct lpfc_iocbq
*cmdiocbp
;
2701 unsigned long iflag
;
2703 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
2704 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2705 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
, saveq
);
2706 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2709 if (cmdiocbp
->iocb_cmpl
) {
2711 * If an ELS command failed send an event to mgmt
2714 if (saveq
->iocb
.ulpStatus
&&
2715 (pring
->ringno
== LPFC_ELS_RING
) &&
2716 (cmdiocbp
->iocb
.ulpCommand
==
2717 CMD_ELS_REQUEST64_CR
))
2718 lpfc_send_els_failure_event(phba
,
2722 * Post all ELS completions to the worker thread.
2723 * All other are passed to the completion callback.
2725 if (pring
->ringno
== LPFC_ELS_RING
) {
2726 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
2727 (cmdiocbp
->iocb_flag
&
2728 LPFC_DRIVER_ABORTED
)) {
2729 spin_lock_irqsave(&phba
->hbalock
,
2731 cmdiocbp
->iocb_flag
&=
2732 ~LPFC_DRIVER_ABORTED
;
2733 spin_unlock_irqrestore(&phba
->hbalock
,
2735 saveq
->iocb
.ulpStatus
=
2736 IOSTAT_LOCAL_REJECT
;
2737 saveq
->iocb
.un
.ulpWord
[4] =
2740 /* Firmware could still be in progress
2741 * of DMAing payload, so don't free data
2742 * buffer till after a hbeat.
2744 spin_lock_irqsave(&phba
->hbalock
,
2746 saveq
->iocb_flag
|= LPFC_DELAY_MEM_FREE
;
2747 spin_unlock_irqrestore(&phba
->hbalock
,
2750 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2751 if (saveq
->iocb_flag
&
2752 LPFC_EXCHANGE_BUSY
) {
2753 /* Set cmdiocb flag for the
2754 * exchange busy so sgl (xri)
2755 * will not be released until
2756 * the abort xri is received
2760 &phba
->hbalock
, iflag
);
2761 cmdiocbp
->iocb_flag
|=
2763 spin_unlock_irqrestore(
2764 &phba
->hbalock
, iflag
);
2766 if (cmdiocbp
->iocb_flag
&
2767 LPFC_DRIVER_ABORTED
) {
2769 * Clear LPFC_DRIVER_ABORTED
2770 * bit in case it was driver
2774 &phba
->hbalock
, iflag
);
2775 cmdiocbp
->iocb_flag
&=
2776 ~LPFC_DRIVER_ABORTED
;
2777 spin_unlock_irqrestore(
2778 &phba
->hbalock
, iflag
);
2779 cmdiocbp
->iocb
.ulpStatus
=
2780 IOSTAT_LOCAL_REJECT
;
2781 cmdiocbp
->iocb
.un
.ulpWord
[4] =
2782 IOERR_ABORT_REQUESTED
;
2784 * For SLI4, irsiocb contains
2785 * NO_XRI in sli_xritag, it
2786 * shall not affect releasing
2787 * sgl (xri) process.
2789 saveq
->iocb
.ulpStatus
=
2790 IOSTAT_LOCAL_REJECT
;
2791 saveq
->iocb
.un
.ulpWord
[4] =
2794 &phba
->hbalock
, iflag
);
2796 LPFC_DELAY_MEM_FREE
;
2797 spin_unlock_irqrestore(
2798 &phba
->hbalock
, iflag
);
2802 (cmdiocbp
->iocb_cmpl
) (phba
, cmdiocbp
, saveq
);
2804 lpfc_sli_release_iocbq(phba
, cmdiocbp
);
2807 * Unknown initiating command based on the response iotag.
2808 * This could be the case on the ELS ring because of
2811 if (pring
->ringno
!= LPFC_ELS_RING
) {
2813 * Ring <ringno> handler: unexpected completion IoTag
2816 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
2817 "0322 Ring %d handler: "
2818 "unexpected completion IoTag x%x "
2819 "Data: x%x x%x x%x x%x\n",
2821 saveq
->iocb
.ulpIoTag
,
2822 saveq
->iocb
.ulpStatus
,
2823 saveq
->iocb
.un
.ulpWord
[4],
2824 saveq
->iocb
.ulpCommand
,
2825 saveq
->iocb
.ulpContext
);
2833 * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
2834 * @phba: Pointer to HBA context object.
2835 * @pring: Pointer to driver SLI ring object.
2837 * This function is called from the iocb ring event handlers when
2838 * put pointer is ahead of the get pointer for a ring. This function signal
2839 * an error attention condition to the worker thread and the worker
2840 * thread will transition the HBA to offline state.
2843 lpfc_sli_rsp_pointers_error(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
2845 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2847 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
2848 * rsp ring <portRspMax>
2850 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2851 "0312 Ring %d handler: portRspPut %d "
2852 "is bigger than rsp ring %d\n",
2853 pring
->ringno
, le32_to_cpu(pgp
->rspPutInx
),
2854 pring
->sli
.sli3
.numRiocb
);
2856 phba
->link_state
= LPFC_HBA_ERROR
;
2859 * All error attention handlers are posted to
2862 phba
->work_ha
|= HA_ERATT
;
2863 phba
->work_hs
= HS_FFER3
;
2865 lpfc_worker_wake_up(phba
);
2871 * lpfc_poll_eratt - Error attention polling timer timeout handler
2872 * @ptr: Pointer to address of HBA context object.
2874 * This function is invoked by the Error Attention polling timer when the
2875 * timer times out. It will check the SLI Error Attention register for
2876 * possible attention events. If so, it will post an Error Attention event
2877 * and wake up worker thread to process it. Otherwise, it will set up the
2878 * Error Attention polling timer for the next poll.
2880 void lpfc_poll_eratt(unsigned long ptr
)
2882 struct lpfc_hba
*phba
;
2883 uint32_t eratt
= 0, rem
;
2884 uint64_t sli_intr
, cnt
;
2886 phba
= (struct lpfc_hba
*)ptr
;
2888 /* Here we will also keep track of interrupts per sec of the hba */
2889 sli_intr
= phba
->sli
.slistat
.sli_intr
;
2891 if (phba
->sli
.slistat
.sli_prev_intr
> sli_intr
)
2892 cnt
= (((uint64_t)(-1) - phba
->sli
.slistat
.sli_prev_intr
) +
2895 cnt
= (sli_intr
- phba
->sli
.slistat
.sli_prev_intr
);
2897 /* 64-bit integer division not supporte on 32-bit x86 - use do_div */
2898 rem
= do_div(cnt
, LPFC_ERATT_POLL_INTERVAL
);
2899 phba
->sli
.slistat
.sli_ips
= cnt
;
2901 phba
->sli
.slistat
.sli_prev_intr
= sli_intr
;
2903 /* Check chip HA register for error event */
2904 eratt
= lpfc_sli_check_eratt(phba
);
2907 /* Tell the worker thread there is work to do */
2908 lpfc_worker_wake_up(phba
);
2910 /* Restart the timer for next eratt poll */
2911 mod_timer(&phba
->eratt_poll
, jiffies
+
2912 HZ
* LPFC_ERATT_POLL_INTERVAL
);
2918 * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
2919 * @phba: Pointer to HBA context object.
2920 * @pring: Pointer to driver SLI ring object.
2921 * @mask: Host attention register mask for this ring.
2923 * This function is called from the interrupt context when there is a ring
2924 * event for the fcp ring. The caller does not hold any lock.
2925 * The function processes each response iocb in the response ring until it
2926 * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
2927 * LE bit set. The function will call the completion handler of the command iocb
2928 * if the response iocb indicates a completion for a command iocb or it is
2929 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
2930 * function if this is an unsolicited iocb.
2931 * This routine presumes LPFC_FCP_RING handling and doesn't bother
2932 * to check it explicitly.
2935 lpfc_sli_handle_fast_ring_event(struct lpfc_hba
*phba
,
2936 struct lpfc_sli_ring
*pring
, uint32_t mask
)
2938 struct lpfc_pgp
*pgp
= &phba
->port_gp
[pring
->ringno
];
2939 IOCB_t
*irsp
= NULL
;
2940 IOCB_t
*entry
= NULL
;
2941 struct lpfc_iocbq
*cmdiocbq
= NULL
;
2942 struct lpfc_iocbq rspiocbq
;
2944 uint32_t portRspPut
, portRspMax
;
2946 lpfc_iocb_type type
;
2947 unsigned long iflag
;
2948 uint32_t rsp_cmpl
= 0;
2950 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2951 pring
->stats
.iocb_event
++;
2954 * The next available response entry should never exceed the maximum
2955 * entries. If it does, treat it as an adapter hardware error.
2957 portRspMax
= pring
->sli
.sli3
.numRiocb
;
2958 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
2959 if (unlikely(portRspPut
>= portRspMax
)) {
2960 lpfc_sli_rsp_pointers_error(phba
, pring
);
2961 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2964 if (phba
->fcp_ring_in_use
) {
2965 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2968 phba
->fcp_ring_in_use
= 1;
2971 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
2973 * Fetch an entry off the ring and copy it into a local data
2974 * structure. The copy involves a byte-swap since the
2975 * network byte order and pci byte orders are different.
2977 entry
= lpfc_resp_iocb(phba
, pring
);
2978 phba
->last_completion_time
= jiffies
;
2980 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
2981 pring
->sli
.sli3
.rspidx
= 0;
2983 lpfc_sli_pcimem_bcopy((uint32_t *) entry
,
2984 (uint32_t *) &rspiocbq
.iocb
,
2985 phba
->iocb_rsp_size
);
2986 INIT_LIST_HEAD(&(rspiocbq
.list
));
2987 irsp
= &rspiocbq
.iocb
;
2989 type
= lpfc_sli_iocb_cmd_type(irsp
->ulpCommand
& CMD_IOCB_MASK
);
2990 pring
->stats
.iocb_rsp
++;
2993 if (unlikely(irsp
->ulpStatus
)) {
2995 * If resource errors reported from HBA, reduce
2996 * queuedepths of the SCSI device.
2998 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
2999 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3000 IOERR_NO_RESOURCES
)) {
3001 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3002 phba
->lpfc_rampdown_queue_depth(phba
);
3003 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3006 /* Rsp ring <ringno> error: IOCB */
3007 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3008 "0336 Rsp Ring %d error: IOCB Data: "
3009 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
3011 irsp
->un
.ulpWord
[0],
3012 irsp
->un
.ulpWord
[1],
3013 irsp
->un
.ulpWord
[2],
3014 irsp
->un
.ulpWord
[3],
3015 irsp
->un
.ulpWord
[4],
3016 irsp
->un
.ulpWord
[5],
3017 *(uint32_t *)&irsp
->un1
,
3018 *((uint32_t *)&irsp
->un1
+ 1));
3022 case LPFC_ABORT_IOCB
:
3025 * Idle exchange closed via ABTS from port. No iocb
3026 * resources need to be recovered.
3028 if (unlikely(irsp
->ulpCommand
== CMD_XRI_ABORTED_CX
)) {
3029 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3030 "0333 IOCB cmd 0x%x"
3031 " processed. Skipping"
3037 cmdiocbq
= lpfc_sli_iocbq_lookup(phba
, pring
,
3039 if (unlikely(!cmdiocbq
))
3041 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
)
3042 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
3043 if (cmdiocbq
->iocb_cmpl
) {
3044 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3045 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
,
3047 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3050 case LPFC_UNSOL_IOCB
:
3051 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3052 lpfc_sli_process_unsol_iocb(phba
, pring
, &rspiocbq
);
3053 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3056 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3057 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3058 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3059 memcpy(&adaptermsg
[0], (uint8_t *) irsp
,
3061 dev_warn(&((phba
->pcidev
)->dev
),
3063 phba
->brd_no
, adaptermsg
);
3065 /* Unknown IOCB command */
3066 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3067 "0334 Unknown IOCB command "
3068 "Data: x%x, x%x x%x x%x x%x\n",
3069 type
, irsp
->ulpCommand
,
3078 * The response IOCB has been processed. Update the ring
3079 * pointer in SLIM. If the port response put pointer has not
3080 * been updated, sync the pgp->rspPutInx and fetch the new port
3081 * response put pointer.
3083 writel(pring
->sli
.sli3
.rspidx
,
3084 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3086 if (pring
->sli
.sli3
.rspidx
== portRspPut
)
3087 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3090 if ((rsp_cmpl
> 0) && (mask
& HA_R0RE_REQ
)) {
3091 pring
->stats
.iocb_rsp_full
++;
3092 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3093 writel(status
, phba
->CAregaddr
);
3094 readl(phba
->CAregaddr
);
3096 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3097 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3098 pring
->stats
.iocb_cmd_empty
++;
3100 /* Force update of the local copy of cmdGetInx */
3101 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3102 lpfc_sli_resume_iocb(phba
, pring
);
3104 if ((pring
->lpfc_sli_cmd_available
))
3105 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3109 phba
->fcp_ring_in_use
= 0;
3110 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3115 * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
3116 * @phba: Pointer to HBA context object.
3117 * @pring: Pointer to driver SLI ring object.
3118 * @rspiocbp: Pointer to driver response IOCB object.
3120 * This function is called from the worker thread when there is a slow-path
3121 * response IOCB to process. This function chains all the response iocbs until
3122 * seeing the iocb with the LE bit set. The function will call
3123 * lpfc_sli_process_sol_iocb function if the response iocb indicates a
3124 * completion of a command iocb. The function will call the
3125 * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
3126 * The function frees the resources or calls the completion handler if this
3127 * iocb is an abort completion. The function returns NULL when the response
3128 * iocb has the LE bit set and all the chained iocbs are processed, otherwise
3129 * this function shall chain the iocb on to the iocb_continueq and return the
3130 * response iocb passed in.
3132 static struct lpfc_iocbq
*
3133 lpfc_sli_sp_handle_rspiocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3134 struct lpfc_iocbq
*rspiocbp
)
3136 struct lpfc_iocbq
*saveq
;
3137 struct lpfc_iocbq
*cmdiocbp
;
3138 struct lpfc_iocbq
*next_iocb
;
3139 IOCB_t
*irsp
= NULL
;
3140 uint32_t free_saveq
;
3141 uint8_t iocb_cmd_type
;
3142 lpfc_iocb_type type
;
3143 unsigned long iflag
;
3146 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3147 /* First add the response iocb to the countinueq list */
3148 list_add_tail(&rspiocbp
->list
, &(pring
->iocb_continueq
));
3149 pring
->iocb_continueq_cnt
++;
3151 /* Now, determine whether the list is completed for processing */
3152 irsp
= &rspiocbp
->iocb
;
3155 * By default, the driver expects to free all resources
3156 * associated with this iocb completion.
3159 saveq
= list_get_first(&pring
->iocb_continueq
,
3160 struct lpfc_iocbq
, list
);
3161 irsp
= &(saveq
->iocb
);
3162 list_del_init(&pring
->iocb_continueq
);
3163 pring
->iocb_continueq_cnt
= 0;
3165 pring
->stats
.iocb_rsp
++;
3168 * If resource errors reported from HBA, reduce
3169 * queuedepths of the SCSI device.
3171 if ((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
3172 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
3173 IOERR_NO_RESOURCES
)) {
3174 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3175 phba
->lpfc_rampdown_queue_depth(phba
);
3176 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3179 if (irsp
->ulpStatus
) {
3180 /* Rsp ring <ringno> error: IOCB */
3181 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3182 "0328 Rsp Ring %d error: "
3187 "x%x x%x x%x x%x\n",
3189 irsp
->un
.ulpWord
[0],
3190 irsp
->un
.ulpWord
[1],
3191 irsp
->un
.ulpWord
[2],
3192 irsp
->un
.ulpWord
[3],
3193 irsp
->un
.ulpWord
[4],
3194 irsp
->un
.ulpWord
[5],
3195 *(((uint32_t *) irsp
) + 6),
3196 *(((uint32_t *) irsp
) + 7),
3197 *(((uint32_t *) irsp
) + 8),
3198 *(((uint32_t *) irsp
) + 9),
3199 *(((uint32_t *) irsp
) + 10),
3200 *(((uint32_t *) irsp
) + 11),
3201 *(((uint32_t *) irsp
) + 12),
3202 *(((uint32_t *) irsp
) + 13),
3203 *(((uint32_t *) irsp
) + 14),
3204 *(((uint32_t *) irsp
) + 15));
3208 * Fetch the IOCB command type and call the correct completion
3209 * routine. Solicited and Unsolicited IOCBs on the ELS ring
3210 * get freed back to the lpfc_iocb_list by the discovery
3213 iocb_cmd_type
= irsp
->ulpCommand
& CMD_IOCB_MASK
;
3214 type
= lpfc_sli_iocb_cmd_type(iocb_cmd_type
);
3217 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3218 rc
= lpfc_sli_process_sol_iocb(phba
, pring
, saveq
);
3219 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3222 case LPFC_UNSOL_IOCB
:
3223 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3224 rc
= lpfc_sli_process_unsol_iocb(phba
, pring
, saveq
);
3225 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3230 case LPFC_ABORT_IOCB
:
3232 if (irsp
->ulpCommand
!= CMD_XRI_ABORTED_CX
)
3233 cmdiocbp
= lpfc_sli_iocbq_lookup(phba
, pring
,
3236 /* Call the specified completion routine */
3237 if (cmdiocbp
->iocb_cmpl
) {
3238 spin_unlock_irqrestore(&phba
->hbalock
,
3240 (cmdiocbp
->iocb_cmpl
)(phba
, cmdiocbp
,
3242 spin_lock_irqsave(&phba
->hbalock
,
3245 __lpfc_sli_release_iocbq(phba
,
3250 case LPFC_UNKNOWN_IOCB
:
3251 if (irsp
->ulpCommand
== CMD_ADAPTER_MSG
) {
3252 char adaptermsg
[LPFC_MAX_ADPTMSG
];
3253 memset(adaptermsg
, 0, LPFC_MAX_ADPTMSG
);
3254 memcpy(&adaptermsg
[0], (uint8_t *)irsp
,
3256 dev_warn(&((phba
->pcidev
)->dev
),
3258 phba
->brd_no
, adaptermsg
);
3260 /* Unknown IOCB command */
3261 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3262 "0335 Unknown IOCB "
3263 "command Data: x%x "
3274 list_for_each_entry_safe(rspiocbp
, next_iocb
,
3275 &saveq
->list
, list
) {
3276 list_del(&rspiocbp
->list
);
3277 __lpfc_sli_release_iocbq(phba
, rspiocbp
);
3279 __lpfc_sli_release_iocbq(phba
, saveq
);
3283 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3288 * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
3289 * @phba: Pointer to HBA context object.
3290 * @pring: Pointer to driver SLI ring object.
3291 * @mask: Host attention register mask for this ring.
3293 * This routine wraps the actual slow_ring event process routine from the
3294 * API jump table function pointer from the lpfc_hba struct.
3297 lpfc_sli_handle_slow_ring_event(struct lpfc_hba
*phba
,
3298 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3300 phba
->lpfc_sli_handle_slow_ring_event(phba
, pring
, mask
);
3304 * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
3305 * @phba: Pointer to HBA context object.
3306 * @pring: Pointer to driver SLI ring object.
3307 * @mask: Host attention register mask for this ring.
3309 * This function is called from the worker thread when there is a ring event
3310 * for non-fcp rings. The caller does not hold any lock. The function will
3311 * remove each response iocb in the response ring and calls the handle
3312 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3315 lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba
*phba
,
3316 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3318 struct lpfc_pgp
*pgp
;
3320 IOCB_t
*irsp
= NULL
;
3321 struct lpfc_iocbq
*rspiocbp
= NULL
;
3322 uint32_t portRspPut
, portRspMax
;
3323 unsigned long iflag
;
3326 pgp
= &phba
->port_gp
[pring
->ringno
];
3327 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3328 pring
->stats
.iocb_event
++;
3331 * The next available response entry should never exceed the maximum
3332 * entries. If it does, treat it as an adapter hardware error.
3334 portRspMax
= pring
->sli
.sli3
.numRiocb
;
3335 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3336 if (portRspPut
>= portRspMax
) {
3338 * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
3339 * rsp ring <portRspMax>
3341 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3342 "0303 Ring %d handler: portRspPut %d "
3343 "is bigger than rsp ring %d\n",
3344 pring
->ringno
, portRspPut
, portRspMax
);
3346 phba
->link_state
= LPFC_HBA_ERROR
;
3347 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3349 phba
->work_hs
= HS_FFER3
;
3350 lpfc_handle_eratt(phba
);
3356 while (pring
->sli
.sli3
.rspidx
!= portRspPut
) {
3358 * Build a completion list and call the appropriate handler.
3359 * The process is to get the next available response iocb, get
3360 * a free iocb from the list, copy the response data into the
3361 * free iocb, insert to the continuation list, and update the
3362 * next response index to slim. This process makes response
3363 * iocb's in the ring available to DMA as fast as possible but
3364 * pays a penalty for a copy operation. Since the iocb is
3365 * only 32 bytes, this penalty is considered small relative to
3366 * the PCI reads for register values and a slim write. When
3367 * the ulpLe field is set, the entire Command has been
3370 entry
= lpfc_resp_iocb(phba
, pring
);
3372 phba
->last_completion_time
= jiffies
;
3373 rspiocbp
= __lpfc_sli_get_iocbq(phba
);
3374 if (rspiocbp
== NULL
) {
3375 printk(KERN_ERR
"%s: out of buffers! Failing "
3376 "completion.\n", __func__
);
3380 lpfc_sli_pcimem_bcopy(entry
, &rspiocbp
->iocb
,
3381 phba
->iocb_rsp_size
);
3382 irsp
= &rspiocbp
->iocb
;
3384 if (++pring
->sli
.sli3
.rspidx
>= portRspMax
)
3385 pring
->sli
.sli3
.rspidx
= 0;
3387 if (pring
->ringno
== LPFC_ELS_RING
) {
3388 lpfc_debugfs_slow_ring_trc(phba
,
3389 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
3390 *(((uint32_t *) irsp
) + 4),
3391 *(((uint32_t *) irsp
) + 6),
3392 *(((uint32_t *) irsp
) + 7));
3395 writel(pring
->sli
.sli3
.rspidx
,
3396 &phba
->host_gp
[pring
->ringno
].rspGetInx
);
3398 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3399 /* Handle the response IOCB */
3400 rspiocbp
= lpfc_sli_sp_handle_rspiocb(phba
, pring
, rspiocbp
);
3401 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3404 * If the port response put pointer has not been updated, sync
3405 * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
3406 * response put pointer.
3408 if (pring
->sli
.sli3
.rspidx
== portRspPut
) {
3409 portRspPut
= le32_to_cpu(pgp
->rspPutInx
);
3411 } /* while (pring->sli.sli3.rspidx != portRspPut) */
3413 if ((rspiocbp
!= NULL
) && (mask
& HA_R0RE_REQ
)) {
3414 /* At least one response entry has been freed */
3415 pring
->stats
.iocb_rsp_full
++;
3416 /* SET RxRE_RSP in Chip Att register */
3417 status
= ((CA_R0ATT
| CA_R0RE_RSP
) << (pring
->ringno
* 4));
3418 writel(status
, phba
->CAregaddr
);
3419 readl(phba
->CAregaddr
); /* flush */
3421 if ((mask
& HA_R0CE_RSP
) && (pring
->flag
& LPFC_CALL_RING_AVAILABLE
)) {
3422 pring
->flag
&= ~LPFC_CALL_RING_AVAILABLE
;
3423 pring
->stats
.iocb_cmd_empty
++;
3425 /* Force update of the local copy of cmdGetInx */
3426 pring
->sli
.sli3
.local_getidx
= le32_to_cpu(pgp
->cmdGetInx
);
3427 lpfc_sli_resume_iocb(phba
, pring
);
3429 if ((pring
->lpfc_sli_cmd_available
))
3430 (pring
->lpfc_sli_cmd_available
) (phba
, pring
);
3434 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3439 * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
3440 * @phba: Pointer to HBA context object.
3441 * @pring: Pointer to driver SLI ring object.
3442 * @mask: Host attention register mask for this ring.
3444 * This function is called from the worker thread when there is a pending
3445 * ELS response iocb on the driver internal slow-path response iocb worker
3446 * queue. The caller does not hold any lock. The function will remove each
3447 * response iocb from the response worker queue and calls the handle
3448 * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
3451 lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba
*phba
,
3452 struct lpfc_sli_ring
*pring
, uint32_t mask
)
3454 struct lpfc_iocbq
*irspiocbq
;
3455 struct hbq_dmabuf
*dmabuf
;
3456 struct lpfc_cq_event
*cq_event
;
3457 unsigned long iflag
;
3459 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3460 phba
->hba_flag
&= ~HBA_SP_QUEUE_EVT
;
3461 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3462 while (!list_empty(&phba
->sli4_hba
.sp_queue_event
)) {
3463 /* Get the response iocb from the head of work queue */
3464 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3465 list_remove_head(&phba
->sli4_hba
.sp_queue_event
,
3466 cq_event
, struct lpfc_cq_event
, list
);
3467 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3469 switch (bf_get(lpfc_wcqe_c_code
, &cq_event
->cqe
.wcqe_cmpl
)) {
3470 case CQE_CODE_COMPL_WQE
:
3471 irspiocbq
= container_of(cq_event
, struct lpfc_iocbq
,
3473 /* Translate ELS WCQE to response IOCBQ */
3474 irspiocbq
= lpfc_sli4_els_wcqe_to_rspiocbq(phba
,
3477 lpfc_sli_sp_handle_rspiocb(phba
, pring
,
3480 case CQE_CODE_RECEIVE
:
3481 case CQE_CODE_RECEIVE_V1
:
3482 dmabuf
= container_of(cq_event
, struct hbq_dmabuf
,
3484 lpfc_sli4_handle_received_buffer(phba
, dmabuf
);
3493 * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
3494 * @phba: Pointer to HBA context object.
3495 * @pring: Pointer to driver SLI ring object.
3497 * This function aborts all iocbs in the given ring and frees all the iocb
3498 * objects in txq. This function issues an abort iocb for all the iocb commands
3499 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
3500 * the return of this function. The caller is not required to hold any locks.
3503 lpfc_sli_abort_iocb_ring(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
3505 LIST_HEAD(completions
);
3506 struct lpfc_iocbq
*iocb
, *next_iocb
;
3508 if (pring
->ringno
== LPFC_ELS_RING
) {
3509 lpfc_fabric_abort_hba(phba
);
3512 /* Error everything on txq and txcmplq
3515 spin_lock_irq(&phba
->hbalock
);
3516 list_splice_init(&pring
->txq
, &completions
);
3518 /* Next issue ABTS for everything on the txcmplq */
3519 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
3520 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3522 spin_unlock_irq(&phba
->hbalock
);
3524 /* Cancel all the IOCBs from the completions list */
3525 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3530 * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring
3531 * @phba: Pointer to HBA context object.
3533 * This function flushes all iocbs in the fcp ring and frees all the iocb
3534 * objects in txq and txcmplq. This function will not issue abort iocbs
3535 * for all the iocb commands in txcmplq, they will just be returned with
3536 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
3537 * slot has been permanently disabled.
3540 lpfc_sli_flush_fcp_rings(struct lpfc_hba
*phba
)
3544 struct lpfc_sli
*psli
= &phba
->sli
;
3545 struct lpfc_sli_ring
*pring
;
3547 /* Currently, only one fcp ring */
3548 pring
= &psli
->ring
[psli
->fcp_ring
];
3550 spin_lock_irq(&phba
->hbalock
);
3551 /* Retrieve everything on txq */
3552 list_splice_init(&pring
->txq
, &txq
);
3554 /* Retrieve everything on the txcmplq */
3555 list_splice_init(&pring
->txcmplq
, &txcmplq
);
3557 /* Indicate the I/O queues are flushed */
3558 phba
->hba_flag
|= HBA_FCP_IOQ_FLUSH
;
3559 spin_unlock_irq(&phba
->hbalock
);
3562 lpfc_sli_cancel_iocbs(phba
, &txq
, IOSTAT_LOCAL_REJECT
,
3565 /* Flush the txcmpq */
3566 lpfc_sli_cancel_iocbs(phba
, &txcmplq
, IOSTAT_LOCAL_REJECT
,
3571 * lpfc_sli_brdready_s3 - Check for sli3 host ready status
3572 * @phba: Pointer to HBA context object.
3573 * @mask: Bit mask to be checked.
3575 * This function reads the host status register and compares
3576 * with the provided bit mask to check if HBA completed
3577 * the restart. This function will wait in a loop for the
3578 * HBA to complete restart. If the HBA does not restart within
3579 * 15 iterations, the function will reset the HBA again. The
3580 * function returns 1 when HBA fail to restart otherwise returns
3584 lpfc_sli_brdready_s3(struct lpfc_hba
*phba
, uint32_t mask
)
3590 /* Read the HBA Host Status Register */
3591 if (lpfc_readl(phba
->HSregaddr
, &status
))
3595 * Check status register every 100ms for 5 retries, then every
3596 * 500ms for 5, then every 2.5 sec for 5, then reset board and
3597 * every 2.5 sec for 4.
3598 * Break our of the loop if errors occurred during init.
3600 while (((status
& mask
) != mask
) &&
3601 !(status
& HS_FFERM
) &&
3613 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3614 lpfc_sli_brdrestart(phba
);
3616 /* Read the HBA Host Status Register */
3617 if (lpfc_readl(phba
->HSregaddr
, &status
)) {
3623 /* Check to see if any errors occurred during init */
3624 if ((status
& HS_FFERM
) || (i
>= 20)) {
3625 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3626 "2751 Adapter failed to restart, "
3627 "status reg x%x, FW Data: A8 x%x AC x%x\n",
3629 readl(phba
->MBslimaddr
+ 0xa8),
3630 readl(phba
->MBslimaddr
+ 0xac));
3631 phba
->link_state
= LPFC_HBA_ERROR
;
3639 * lpfc_sli_brdready_s4 - Check for sli4 host ready status
3640 * @phba: Pointer to HBA context object.
3641 * @mask: Bit mask to be checked.
3643 * This function checks the host status register to check if HBA is
3644 * ready. This function will wait in a loop for the HBA to be ready
3645 * If the HBA is not ready , the function will will reset the HBA PCI
3646 * function again. The function returns 1 when HBA fail to be ready
3647 * otherwise returns zero.
3650 lpfc_sli_brdready_s4(struct lpfc_hba
*phba
, uint32_t mask
)
3655 /* Read the HBA Host Status Register */
3656 status
= lpfc_sli4_post_status_check(phba
);
3659 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
3660 lpfc_sli_brdrestart(phba
);
3661 status
= lpfc_sli4_post_status_check(phba
);
3664 /* Check to see if any errors occurred during init */
3666 phba
->link_state
= LPFC_HBA_ERROR
;
3669 phba
->sli4_hba
.intr_enable
= 0;
3675 * lpfc_sli_brdready - Wrapper func for checking the hba readyness
3676 * @phba: Pointer to HBA context object.
3677 * @mask: Bit mask to be checked.
3679 * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
3680 * from the API jump table function pointer from the lpfc_hba struct.
3683 lpfc_sli_brdready(struct lpfc_hba
*phba
, uint32_t mask
)
3685 return phba
->lpfc_sli_brdready(phba
, mask
);
3688 #define BARRIER_TEST_PATTERN (0xdeadbeef)
3691 * lpfc_reset_barrier - Make HBA ready for HBA reset
3692 * @phba: Pointer to HBA context object.
3694 * This function is called before resetting an HBA. This function is called
3695 * with hbalock held and requests HBA to quiesce DMAs before a reset.
3697 void lpfc_reset_barrier(struct lpfc_hba
*phba
)
3699 uint32_t __iomem
*resp_buf
;
3700 uint32_t __iomem
*mbox_buf
;
3701 volatile uint32_t mbox
;
3702 uint32_t hc_copy
, ha_copy
, resp_data
;
3706 pci_read_config_byte(phba
->pcidev
, PCI_HEADER_TYPE
, &hdrtype
);
3707 if (hdrtype
!= 0x80 ||
3708 (FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != HELIOS_JEDEC_ID
&&
3709 FC_JEDEC_ID(phba
->vpd
.rev
.biuRev
) != THOR_JEDEC_ID
))
3713 * Tell the other part of the chip to suspend temporarily all
3716 resp_buf
= phba
->MBslimaddr
;
3718 /* Disable the error attention */
3719 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
3721 writel((hc_copy
& ~HC_ERINT_ENA
), phba
->HCregaddr
);
3722 readl(phba
->HCregaddr
); /* flush */
3723 phba
->link_flag
|= LS_IGNORE_ERATT
;
3725 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3727 if (ha_copy
& HA_ERATT
) {
3728 /* Clear Chip error bit */
3729 writel(HA_ERATT
, phba
->HAregaddr
);
3730 phba
->pport
->stopped
= 1;
3734 ((MAILBOX_t
*)&mbox
)->mbxCommand
= MBX_KILL_BOARD
;
3735 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_CHIP
;
3737 writel(BARRIER_TEST_PATTERN
, (resp_buf
+ 1));
3738 mbox_buf
= phba
->MBslimaddr
;
3739 writel(mbox
, mbox_buf
);
3741 for (i
= 0; i
< 50; i
++) {
3742 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3744 if (resp_data
!= ~(BARRIER_TEST_PATTERN
))
3750 if (lpfc_readl((resp_buf
+ 1), &resp_data
))
3752 if (resp_data
!= ~(BARRIER_TEST_PATTERN
)) {
3753 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
||
3754 phba
->pport
->stopped
)
3760 ((MAILBOX_t
*)&mbox
)->mbxOwner
= OWN_HOST
;
3762 for (i
= 0; i
< 500; i
++) {
3763 if (lpfc_readl(resp_buf
, &resp_data
))
3765 if (resp_data
!= mbox
)
3774 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3776 if (!(ha_copy
& HA_ERATT
))
3782 if (readl(phba
->HAregaddr
) & HA_ERATT
) {
3783 writel(HA_ERATT
, phba
->HAregaddr
);
3784 phba
->pport
->stopped
= 1;
3788 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3789 writel(hc_copy
, phba
->HCregaddr
);
3790 readl(phba
->HCregaddr
); /* flush */
3794 * lpfc_sli_brdkill - Issue a kill_board mailbox command
3795 * @phba: Pointer to HBA context object.
3797 * This function issues a kill_board mailbox command and waits for
3798 * the error attention interrupt. This function is called for stopping
3799 * the firmware processing. The caller is not required to hold any
3800 * locks. This function calls lpfc_hba_down_post function to free
3801 * any pending commands after the kill. The function will return 1 when it
3802 * fails to kill the board else will return 0.
3805 lpfc_sli_brdkill(struct lpfc_hba
*phba
)
3807 struct lpfc_sli
*psli
;
3817 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3818 "0329 Kill HBA Data: x%x x%x\n",
3819 phba
->pport
->port_state
, psli
->sli_flag
);
3821 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3825 /* Disable the error attention */
3826 spin_lock_irq(&phba
->hbalock
);
3827 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
3828 spin_unlock_irq(&phba
->hbalock
);
3829 mempool_free(pmb
, phba
->mbox_mem_pool
);
3832 status
&= ~HC_ERINT_ENA
;
3833 writel(status
, phba
->HCregaddr
);
3834 readl(phba
->HCregaddr
); /* flush */
3835 phba
->link_flag
|= LS_IGNORE_ERATT
;
3836 spin_unlock_irq(&phba
->hbalock
);
3838 lpfc_kill_board(phba
, pmb
);
3839 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3840 retval
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3842 if (retval
!= MBX_SUCCESS
) {
3843 if (retval
!= MBX_BUSY
)
3844 mempool_free(pmb
, phba
->mbox_mem_pool
);
3845 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3846 "2752 KILL_BOARD command failed retval %d\n",
3848 spin_lock_irq(&phba
->hbalock
);
3849 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3850 spin_unlock_irq(&phba
->hbalock
);
3854 spin_lock_irq(&phba
->hbalock
);
3855 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
3856 spin_unlock_irq(&phba
->hbalock
);
3858 mempool_free(pmb
, phba
->mbox_mem_pool
);
3860 /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
3861 * attention every 100ms for 3 seconds. If we don't get ERATT after
3862 * 3 seconds we still set HBA_ERROR state because the status of the
3863 * board is now undefined.
3865 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3867 while ((i
++ < 30) && !(ha_copy
& HA_ERATT
)) {
3869 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
3873 del_timer_sync(&psli
->mbox_tmo
);
3874 if (ha_copy
& HA_ERATT
) {
3875 writel(HA_ERATT
, phba
->HAregaddr
);
3876 phba
->pport
->stopped
= 1;
3878 spin_lock_irq(&phba
->hbalock
);
3879 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
3880 psli
->mbox_active
= NULL
;
3881 phba
->link_flag
&= ~LS_IGNORE_ERATT
;
3882 spin_unlock_irq(&phba
->hbalock
);
3884 lpfc_hba_down_post(phba
);
3885 phba
->link_state
= LPFC_HBA_ERROR
;
3887 return ha_copy
& HA_ERATT
? 0 : 1;
3891 * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
3892 * @phba: Pointer to HBA context object.
3894 * This function resets the HBA by writing HC_INITFF to the control
3895 * register. After the HBA resets, this function resets all the iocb ring
3896 * indices. This function disables PCI layer parity checking during
3898 * This function returns 0 always.
3899 * The caller is not required to hold any locks.
3902 lpfc_sli_brdreset(struct lpfc_hba
*phba
)
3904 struct lpfc_sli
*psli
;
3905 struct lpfc_sli_ring
*pring
;
3912 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3913 "0325 Reset HBA Data: x%x x%x\n",
3914 phba
->pport
->port_state
, psli
->sli_flag
);
3916 /* perform board reset */
3917 phba
->fc_eventTag
= 0;
3918 phba
->link_events
= 0;
3919 phba
->pport
->fc_myDID
= 0;
3920 phba
->pport
->fc_prevDID
= 0;
3922 /* Turn off parity checking and serr during the physical reset */
3923 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3924 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
,
3926 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3928 psli
->sli_flag
&= ~(LPFC_SLI_ACTIVE
| LPFC_PROCESS_LA
);
3930 /* Now toggle INITFF bit in the Host Control Register */
3931 writel(HC_INITFF
, phba
->HCregaddr
);
3933 readl(phba
->HCregaddr
); /* flush */
3934 writel(0, phba
->HCregaddr
);
3935 readl(phba
->HCregaddr
); /* flush */
3937 /* Restore PCI cmd register */
3938 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
3940 /* Initialize relevant SLI info */
3941 for (i
= 0; i
< psli
->num_rings
; i
++) {
3942 pring
= &psli
->ring
[i
];
3944 pring
->sli
.sli3
.rspidx
= 0;
3945 pring
->sli
.sli3
.next_cmdidx
= 0;
3946 pring
->sli
.sli3
.local_getidx
= 0;
3947 pring
->sli
.sli3
.cmdidx
= 0;
3948 pring
->missbufcnt
= 0;
3951 phba
->link_state
= LPFC_WARM_START
;
3956 * lpfc_sli4_brdreset - Reset a sli-4 HBA
3957 * @phba: Pointer to HBA context object.
3959 * This function resets a SLI4 HBA. This function disables PCI layer parity
3960 * checking during resets the device. The caller is not required to hold
3963 * This function returns 0 always.
3966 lpfc_sli4_brdreset(struct lpfc_hba
*phba
)
3968 struct lpfc_sli
*psli
= &phba
->sli
;
3973 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3974 "0295 Reset HBA Data: x%x x%x\n",
3975 phba
->pport
->port_state
, psli
->sli_flag
);
3977 /* perform board reset */
3978 phba
->fc_eventTag
= 0;
3979 phba
->link_events
= 0;
3980 phba
->pport
->fc_myDID
= 0;
3981 phba
->pport
->fc_prevDID
= 0;
3983 spin_lock_irq(&phba
->hbalock
);
3984 psli
->sli_flag
&= ~(LPFC_PROCESS_LA
);
3985 phba
->fcf
.fcf_flag
= 0;
3986 spin_unlock_irq(&phba
->hbalock
);
3988 /* Now physically reset the device */
3989 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3990 "0389 Performing PCI function reset!\n");
3992 /* Turn off parity checking and serr during the physical reset */
3993 pci_read_config_word(phba
->pcidev
, PCI_COMMAND
, &cfg_value
);
3994 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, (cfg_value
&
3995 ~(PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
)));
3997 /* Perform FCoE PCI function reset before freeing queue memory */
3998 rc
= lpfc_pci_function_reset(phba
);
3999 lpfc_sli4_queue_destroy(phba
);
4001 /* Restore PCI cmd register */
4002 pci_write_config_word(phba
->pcidev
, PCI_COMMAND
, cfg_value
);
4008 * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
4009 * @phba: Pointer to HBA context object.
4011 * This function is called in the SLI initialization code path to
4012 * restart the HBA. The caller is not required to hold any lock.
4013 * This function writes MBX_RESTART mailbox command to the SLIM and
4014 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
4015 * function to free any pending commands. The function enables
4016 * POST only during the first initialization. The function returns zero.
4017 * The function does not guarantee completion of MBX_RESTART mailbox
4018 * command before the return of this function.
4021 lpfc_sli_brdrestart_s3(struct lpfc_hba
*phba
)
4024 struct lpfc_sli
*psli
;
4025 volatile uint32_t word0
;
4026 void __iomem
*to_slim
;
4027 uint32_t hba_aer_enabled
;
4029 spin_lock_irq(&phba
->hbalock
);
4031 /* Take PCIe device Advanced Error Reporting (AER) state */
4032 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4037 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4038 "0337 Restart HBA Data: x%x x%x\n",
4039 phba
->pport
->port_state
, psli
->sli_flag
);
4042 mb
= (MAILBOX_t
*) &word0
;
4043 mb
->mbxCommand
= MBX_RESTART
;
4046 lpfc_reset_barrier(phba
);
4048 to_slim
= phba
->MBslimaddr
;
4049 writel(*(uint32_t *) mb
, to_slim
);
4050 readl(to_slim
); /* flush */
4052 /* Only skip post after fc_ffinit is completed */
4053 if (phba
->pport
->port_state
)
4054 word0
= 1; /* This is really setting up word1 */
4056 word0
= 0; /* This is really setting up word1 */
4057 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
4058 writel(*(uint32_t *) mb
, to_slim
);
4059 readl(to_slim
); /* flush */
4061 lpfc_sli_brdreset(phba
);
4062 phba
->pport
->stopped
= 0;
4063 phba
->link_state
= LPFC_INIT_START
;
4065 spin_unlock_irq(&phba
->hbalock
);
4067 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4068 psli
->stats_start
= get_seconds();
4070 /* Give the INITFF and Post time to settle. */
4073 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4074 if (hba_aer_enabled
)
4075 pci_disable_pcie_error_reporting(phba
->pcidev
);
4077 lpfc_hba_down_post(phba
);
4083 * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
4084 * @phba: Pointer to HBA context object.
4086 * This function is called in the SLI initialization code path to restart
4087 * a SLI4 HBA. The caller is not required to hold any lock.
4088 * At the end of the function, it calls lpfc_hba_down_post function to
4089 * free any pending commands.
4092 lpfc_sli_brdrestart_s4(struct lpfc_hba
*phba
)
4094 struct lpfc_sli
*psli
= &phba
->sli
;
4095 uint32_t hba_aer_enabled
;
4099 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4100 "0296 Restart HBA Data: x%x x%x\n",
4101 phba
->pport
->port_state
, psli
->sli_flag
);
4103 /* Take PCIe device Advanced Error Reporting (AER) state */
4104 hba_aer_enabled
= phba
->hba_flag
& HBA_AER_ENABLED
;
4106 rc
= lpfc_sli4_brdreset(phba
);
4108 spin_lock_irq(&phba
->hbalock
);
4109 phba
->pport
->stopped
= 0;
4110 phba
->link_state
= LPFC_INIT_START
;
4112 spin_unlock_irq(&phba
->hbalock
);
4114 memset(&psli
->lnk_stat_offsets
, 0, sizeof(psli
->lnk_stat_offsets
));
4115 psli
->stats_start
= get_seconds();
4117 /* Reset HBA AER if it was enabled, note hba_flag was reset above */
4118 if (hba_aer_enabled
)
4119 pci_disable_pcie_error_reporting(phba
->pcidev
);
4121 lpfc_hba_down_post(phba
);
4127 * lpfc_sli_brdrestart - Wrapper func for restarting hba
4128 * @phba: Pointer to HBA context object.
4130 * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
4131 * API jump table function pointer from the lpfc_hba struct.
4134 lpfc_sli_brdrestart(struct lpfc_hba
*phba
)
4136 return phba
->lpfc_sli_brdrestart(phba
);
4140 * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
4141 * @phba: Pointer to HBA context object.
4143 * This function is called after a HBA restart to wait for successful
4144 * restart of the HBA. Successful restart of the HBA is indicated by
4145 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
4146 * iteration, the function will restart the HBA again. The function returns
4147 * zero if HBA successfully restarted else returns negative error code.
4150 lpfc_sli_chipset_init(struct lpfc_hba
*phba
)
4152 uint32_t status
, i
= 0;
4154 /* Read the HBA Host Status Register */
4155 if (lpfc_readl(phba
->HSregaddr
, &status
))
4158 /* Check status register to see what current state is */
4160 while ((status
& (HS_FFRDY
| HS_MBRDY
)) != (HS_FFRDY
| HS_MBRDY
)) {
4162 /* Check every 10ms for 10 retries, then every 100ms for 90
4163 * retries, then every 1 sec for 50 retires for a total of
4164 * ~60 seconds before reset the board again and check every
4165 * 1 sec for 50 retries. The up to 60 seconds before the
4166 * board ready is required by the Falcon FIPS zeroization
4167 * complete, and any reset the board in between shall cause
4168 * restart of zeroization, further delay the board ready.
4171 /* Adapter failed to init, timeout, status reg
4173 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4174 "0436 Adapter failed to init, "
4175 "timeout, status reg x%x, "
4176 "FW Data: A8 x%x AC x%x\n", status
,
4177 readl(phba
->MBslimaddr
+ 0xa8),
4178 readl(phba
->MBslimaddr
+ 0xac));
4179 phba
->link_state
= LPFC_HBA_ERROR
;
4183 /* Check to see if any errors occurred during init */
4184 if (status
& HS_FFERM
) {
4185 /* ERROR: During chipset initialization */
4186 /* Adapter failed to init, chipset, status reg
4188 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4189 "0437 Adapter failed to init, "
4190 "chipset, status reg x%x, "
4191 "FW Data: A8 x%x AC x%x\n", status
,
4192 readl(phba
->MBslimaddr
+ 0xa8),
4193 readl(phba
->MBslimaddr
+ 0xac));
4194 phba
->link_state
= LPFC_HBA_ERROR
;
4207 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4208 lpfc_sli_brdrestart(phba
);
4210 /* Read the HBA Host Status Register */
4211 if (lpfc_readl(phba
->HSregaddr
, &status
))
4215 /* Check to see if any errors occurred during init */
4216 if (status
& HS_FFERM
) {
4217 /* ERROR: During chipset initialization */
4218 /* Adapter failed to init, chipset, status reg <status> */
4219 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4220 "0438 Adapter failed to init, chipset, "
4222 "FW Data: A8 x%x AC x%x\n", status
,
4223 readl(phba
->MBslimaddr
+ 0xa8),
4224 readl(phba
->MBslimaddr
+ 0xac));
4225 phba
->link_state
= LPFC_HBA_ERROR
;
4229 /* Clear all interrupt enable conditions */
4230 writel(0, phba
->HCregaddr
);
4231 readl(phba
->HCregaddr
); /* flush */
4233 /* setup host attn register */
4234 writel(0xffffffff, phba
->HAregaddr
);
4235 readl(phba
->HAregaddr
); /* flush */
4240 * lpfc_sli_hbq_count - Get the number of HBQs to be configured
4242 * This function calculates and returns the number of HBQs required to be
4246 lpfc_sli_hbq_count(void)
4248 return ARRAY_SIZE(lpfc_hbq_defs
);
4252 * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
4254 * This function adds the number of hbq entries in every HBQ to get
4255 * the total number of hbq entries required for the HBA and returns
4259 lpfc_sli_hbq_entry_count(void)
4261 int hbq_count
= lpfc_sli_hbq_count();
4265 for (i
= 0; i
< hbq_count
; ++i
)
4266 count
+= lpfc_hbq_defs
[i
]->entry_count
;
4271 * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
4273 * This function calculates amount of memory required for all hbq entries
4274 * to be configured and returns the total memory required.
4277 lpfc_sli_hbq_size(void)
4279 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry
);
4283 * lpfc_sli_hbq_setup - configure and initialize HBQs
4284 * @phba: Pointer to HBA context object.
4286 * This function is called during the SLI initialization to configure
4287 * all the HBQs and post buffers to the HBQ. The caller is not
4288 * required to hold any locks. This function will return zero if successful
4289 * else it will return negative error code.
4292 lpfc_sli_hbq_setup(struct lpfc_hba
*phba
)
4294 int hbq_count
= lpfc_sli_hbq_count();
4298 uint32_t hbq_entry_index
;
4300 /* Get a Mailbox buffer to setup mailbox
4301 * commands for HBA initialization
4303 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4310 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
4311 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4312 phba
->hbq_in_use
= 1;
4314 hbq_entry_index
= 0;
4315 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
) {
4316 phba
->hbqs
[hbqno
].next_hbqPutIdx
= 0;
4317 phba
->hbqs
[hbqno
].hbqPutIdx
= 0;
4318 phba
->hbqs
[hbqno
].local_hbqGetIdx
= 0;
4319 phba
->hbqs
[hbqno
].entry_count
=
4320 lpfc_hbq_defs
[hbqno
]->entry_count
;
4321 lpfc_config_hbq(phba
, hbqno
, lpfc_hbq_defs
[hbqno
],
4322 hbq_entry_index
, pmb
);
4323 hbq_entry_index
+= phba
->hbqs
[hbqno
].entry_count
;
4325 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
4326 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
4327 mbxStatus <status>, ring <num> */
4329 lpfc_printf_log(phba
, KERN_ERR
,
4330 LOG_SLI
| LOG_VPORT
,
4331 "1805 Adapter failed to init. "
4332 "Data: x%x x%x x%x\n",
4334 pmbox
->mbxStatus
, hbqno
);
4336 phba
->link_state
= LPFC_HBA_ERROR
;
4337 mempool_free(pmb
, phba
->mbox_mem_pool
);
4341 phba
->hbq_count
= hbq_count
;
4343 mempool_free(pmb
, phba
->mbox_mem_pool
);
4345 /* Initially populate or replenish the HBQs */
4346 for (hbqno
= 0; hbqno
< hbq_count
; ++hbqno
)
4347 lpfc_sli_hbqbuf_init_hbqs(phba
, hbqno
);
4352 * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
4353 * @phba: Pointer to HBA context object.
4355 * This function is called during the SLI initialization to configure
4356 * all the HBQs and post buffers to the HBQ. The caller is not
4357 * required to hold any locks. This function will return zero if successful
4358 * else it will return negative error code.
4361 lpfc_sli4_rb_setup(struct lpfc_hba
*phba
)
4363 phba
->hbq_in_use
= 1;
4364 phba
->hbqs
[0].entry_count
= lpfc_hbq_defs
[0]->entry_count
;
4365 phba
->hbq_count
= 1;
4366 /* Initially populate or replenish the HBQs */
4367 lpfc_sli_hbqbuf_init_hbqs(phba
, 0);
4372 * lpfc_sli_config_port - Issue config port mailbox command
4373 * @phba: Pointer to HBA context object.
4374 * @sli_mode: sli mode - 2/3
4376 * This function is called by the sli intialization code path
4377 * to issue config_port mailbox command. This function restarts the
4378 * HBA firmware and issues a config_port mailbox command to configure
4379 * the SLI interface in the sli mode specified by sli_mode
4380 * variable. The caller is not required to hold any locks.
4381 * The function returns 0 if successful, else returns negative error
4385 lpfc_sli_config_port(struct lpfc_hba
*phba
, int sli_mode
)
4388 uint32_t resetcount
= 0, rc
= 0, done
= 0;
4390 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4392 phba
->link_state
= LPFC_HBA_ERROR
;
4396 phba
->sli_rev
= sli_mode
;
4397 while (resetcount
< 2 && !done
) {
4398 spin_lock_irq(&phba
->hbalock
);
4399 phba
->sli
.sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
4400 spin_unlock_irq(&phba
->hbalock
);
4401 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4402 lpfc_sli_brdrestart(phba
);
4403 rc
= lpfc_sli_chipset_init(phba
);
4407 spin_lock_irq(&phba
->hbalock
);
4408 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
4409 spin_unlock_irq(&phba
->hbalock
);
4412 /* Call pre CONFIG_PORT mailbox command initialization. A
4413 * value of 0 means the call was successful. Any other
4414 * nonzero value is a failure, but if ERESTART is returned,
4415 * the driver may reset the HBA and try again.
4417 rc
= lpfc_config_port_prep(phba
);
4418 if (rc
== -ERESTART
) {
4419 phba
->link_state
= LPFC_LINK_UNKNOWN
;
4424 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
4425 lpfc_config_port(phba
, pmb
);
4426 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4427 phba
->sli3_options
&= ~(LPFC_SLI3_NPIV_ENABLED
|
4428 LPFC_SLI3_HBQ_ENABLED
|
4429 LPFC_SLI3_CRP_ENABLED
|
4430 LPFC_SLI3_BG_ENABLED
|
4431 LPFC_SLI3_DSS_ENABLED
);
4432 if (rc
!= MBX_SUCCESS
) {
4433 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4434 "0442 Adapter failed to init, mbxCmd x%x "
4435 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
4436 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
, 0);
4437 spin_lock_irq(&phba
->hbalock
);
4438 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
4439 spin_unlock_irq(&phba
->hbalock
);
4442 /* Allow asynchronous mailbox command to go through */
4443 spin_lock_irq(&phba
->hbalock
);
4444 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
4445 spin_unlock_irq(&phba
->hbalock
);
4448 if ((pmb
->u
.mb
.un
.varCfgPort
.casabt
== 1) &&
4449 (pmb
->u
.mb
.un
.varCfgPort
.gasabt
== 0))
4450 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4451 "3110 Port did not grant ASABT\n");
4456 goto do_prep_failed
;
4458 if (pmb
->u
.mb
.un
.varCfgPort
.sli_mode
== 3) {
4459 if (!pmb
->u
.mb
.un
.varCfgPort
.cMA
) {
4461 goto do_prep_failed
;
4463 if (phba
->max_vpi
&& pmb
->u
.mb
.un
.varCfgPort
.gmv
) {
4464 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
4465 phba
->max_vpi
= pmb
->u
.mb
.un
.varCfgPort
.max_vpi
;
4466 phba
->max_vports
= (phba
->max_vpi
> phba
->max_vports
) ?
4467 phba
->max_vpi
: phba
->max_vports
;
4471 phba
->fips_level
= 0;
4472 phba
->fips_spec_rev
= 0;
4473 if (pmb
->u
.mb
.un
.varCfgPort
.gdss
) {
4474 phba
->sli3_options
|= LPFC_SLI3_DSS_ENABLED
;
4475 phba
->fips_level
= pmb
->u
.mb
.un
.varCfgPort
.fips_level
;
4476 phba
->fips_spec_rev
= pmb
->u
.mb
.un
.varCfgPort
.fips_rev
;
4477 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4478 "2850 Security Crypto Active. FIPS x%d "
4480 phba
->fips_level
, phba
->fips_spec_rev
);
4482 if (pmb
->u
.mb
.un
.varCfgPort
.sec_err
) {
4483 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4484 "2856 Config Port Security Crypto "
4486 pmb
->u
.mb
.un
.varCfgPort
.sec_err
);
4488 if (pmb
->u
.mb
.un
.varCfgPort
.gerbm
)
4489 phba
->sli3_options
|= LPFC_SLI3_HBQ_ENABLED
;
4490 if (pmb
->u
.mb
.un
.varCfgPort
.gcrp
)
4491 phba
->sli3_options
|= LPFC_SLI3_CRP_ENABLED
;
4493 phba
->hbq_get
= phba
->mbox
->us
.s3_pgp
.hbq_get
;
4494 phba
->port_gp
= phba
->mbox
->us
.s3_pgp
.port
;
4496 if (phba
->cfg_enable_bg
) {
4497 if (pmb
->u
.mb
.un
.varCfgPort
.gbg
)
4498 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
4500 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4501 "0443 Adapter did not grant "
4505 phba
->hbq_get
= NULL
;
4506 phba
->port_gp
= phba
->mbox
->us
.s2
.port
;
4510 mempool_free(pmb
, phba
->mbox_mem_pool
);
4516 * lpfc_sli_hba_setup - SLI intialization function
4517 * @phba: Pointer to HBA context object.
4519 * This function is the main SLI intialization function. This function
4520 * is called by the HBA intialization code, HBA reset code and HBA
4521 * error attention handler code. Caller is not required to hold any
4522 * locks. This function issues config_port mailbox command to configure
4523 * the SLI, setup iocb rings and HBQ rings. In the end the function
4524 * calls the config_port_post function to issue init_link mailbox
4525 * command and to start the discovery. The function will return zero
4526 * if successful, else it will return negative error code.
4529 lpfc_sli_hba_setup(struct lpfc_hba
*phba
)
4535 switch (lpfc_sli_mode
) {
4537 if (phba
->cfg_enable_npiv
) {
4538 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4539 "1824 NPIV enabled: Override lpfc_sli_mode "
4540 "parameter (%d) to auto (0).\n",
4550 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4551 "1819 Unrecognized lpfc_sli_mode "
4552 "parameter: %d.\n", lpfc_sli_mode
);
4557 rc
= lpfc_sli_config_port(phba
, mode
);
4559 if (rc
&& lpfc_sli_mode
== 3)
4560 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_VPORT
,
4561 "1820 Unable to select SLI-3. "
4562 "Not supported by adapter.\n");
4563 if (rc
&& mode
!= 2)
4564 rc
= lpfc_sli_config_port(phba
, 2);
4566 goto lpfc_sli_hba_setup_error
;
4568 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
4569 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
4570 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
4572 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4573 "2709 This device supports "
4574 "Advanced Error Reporting (AER)\n");
4575 spin_lock_irq(&phba
->hbalock
);
4576 phba
->hba_flag
|= HBA_AER_ENABLED
;
4577 spin_unlock_irq(&phba
->hbalock
);
4579 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4580 "2708 This device does not support "
4581 "Advanced Error Reporting (AER)\n");
4582 phba
->cfg_aer_support
= 0;
4586 if (phba
->sli_rev
== 3) {
4587 phba
->iocb_cmd_size
= SLI3_IOCB_CMD_SIZE
;
4588 phba
->iocb_rsp_size
= SLI3_IOCB_RSP_SIZE
;
4590 phba
->iocb_cmd_size
= SLI2_IOCB_CMD_SIZE
;
4591 phba
->iocb_rsp_size
= SLI2_IOCB_RSP_SIZE
;
4592 phba
->sli3_options
= 0;
4595 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4596 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
4597 phba
->sli_rev
, phba
->max_vpi
);
4598 rc
= lpfc_sli_ring_map(phba
);
4601 goto lpfc_sli_hba_setup_error
;
4603 /* Initialize VPIs. */
4604 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
4606 * The VPI bitmask and physical ID array are allocated
4607 * and initialized once only - at driver load. A port
4608 * reset doesn't need to reinitialize this memory.
4610 if ((phba
->vpi_bmask
== NULL
) && (phba
->vpi_ids
== NULL
)) {
4611 longs
= (phba
->max_vpi
+ BITS_PER_LONG
) / BITS_PER_LONG
;
4612 phba
->vpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4614 if (!phba
->vpi_bmask
) {
4616 goto lpfc_sli_hba_setup_error
;
4619 phba
->vpi_ids
= kzalloc(
4620 (phba
->max_vpi
+1) * sizeof(uint16_t),
4622 if (!phba
->vpi_ids
) {
4623 kfree(phba
->vpi_bmask
);
4625 goto lpfc_sli_hba_setup_error
;
4627 for (i
= 0; i
< phba
->max_vpi
; i
++)
4628 phba
->vpi_ids
[i
] = i
;
4633 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4634 rc
= lpfc_sli_hbq_setup(phba
);
4636 goto lpfc_sli_hba_setup_error
;
4638 spin_lock_irq(&phba
->hbalock
);
4639 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4640 spin_unlock_irq(&phba
->hbalock
);
4642 rc
= lpfc_config_port_post(phba
);
4644 goto lpfc_sli_hba_setup_error
;
4648 lpfc_sli_hba_setup_error
:
4649 phba
->link_state
= LPFC_HBA_ERROR
;
4650 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4651 "0445 Firmware initialization failed\n");
4656 * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
4657 * @phba: Pointer to HBA context object.
4658 * @mboxq: mailbox pointer.
4659 * This function issue a dump mailbox command to read config region
4660 * 23 and parse the records in the region and populate driver
4664 lpfc_sli4_read_fcoe_params(struct lpfc_hba
*phba
)
4666 LPFC_MBOXQ_t
*mboxq
;
4667 struct lpfc_dmabuf
*mp
;
4668 struct lpfc_mqe
*mqe
;
4669 uint32_t data_length
;
4672 /* Program the default value of vlan_id and fc_map */
4673 phba
->valid_vlan
= 0;
4674 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4675 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4676 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4678 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4682 mqe
= &mboxq
->u
.mqe
;
4683 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
)) {
4685 goto out_free_mboxq
;
4688 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
4689 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4691 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
4692 "(%d):2571 Mailbox cmd x%x Status x%x "
4693 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4694 "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
4695 "CQ: x%x x%x x%x x%x\n",
4696 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
4697 bf_get(lpfc_mqe_command
, mqe
),
4698 bf_get(lpfc_mqe_status
, mqe
),
4699 mqe
->un
.mb_words
[0], mqe
->un
.mb_words
[1],
4700 mqe
->un
.mb_words
[2], mqe
->un
.mb_words
[3],
4701 mqe
->un
.mb_words
[4], mqe
->un
.mb_words
[5],
4702 mqe
->un
.mb_words
[6], mqe
->un
.mb_words
[7],
4703 mqe
->un
.mb_words
[8], mqe
->un
.mb_words
[9],
4704 mqe
->un
.mb_words
[10], mqe
->un
.mb_words
[11],
4705 mqe
->un
.mb_words
[12], mqe
->un
.mb_words
[13],
4706 mqe
->un
.mb_words
[14], mqe
->un
.mb_words
[15],
4707 mqe
->un
.mb_words
[16], mqe
->un
.mb_words
[50],
4709 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
4710 mboxq
->mcqe
.trailer
);
4713 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4716 goto out_free_mboxq
;
4718 data_length
= mqe
->un
.mb_words
[5];
4719 if (data_length
> DMP_RGN23_SIZE
) {
4720 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4723 goto out_free_mboxq
;
4726 lpfc_parse_fcoe_conf(phba
, mp
->virt
, data_length
);
4727 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4732 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4737 * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
4738 * @phba: pointer to lpfc hba data structure.
4739 * @mboxq: pointer to the LPFC_MBOXQ_t structure.
4740 * @vpd: pointer to the memory to hold resulting port vpd data.
4741 * @vpd_size: On input, the number of bytes allocated to @vpd.
4742 * On output, the number of data bytes in @vpd.
4744 * This routine executes a READ_REV SLI4 mailbox command. In
4745 * addition, this routine gets the port vpd data.
4749 * -ENOMEM - could not allocated memory.
4752 lpfc_sli4_read_rev(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
4753 uint8_t *vpd
, uint32_t *vpd_size
)
4757 struct lpfc_dmabuf
*dmabuf
;
4758 struct lpfc_mqe
*mqe
;
4760 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4765 * Get a DMA buffer for the vpd data resulting from the READ_REV
4768 dma_size
= *vpd_size
;
4769 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4773 if (!dmabuf
->virt
) {
4777 memset(dmabuf
->virt
, 0, dma_size
);
4780 * The SLI4 implementation of READ_REV conflicts at word1,
4781 * bits 31:16 and SLI4 adds vpd functionality not present
4782 * in SLI3. This code corrects the conflicts.
4784 lpfc_read_rev(phba
, mboxq
);
4785 mqe
= &mboxq
->u
.mqe
;
4786 mqe
->un
.read_rev
.vpd_paddr_high
= putPaddrHigh(dmabuf
->phys
);
4787 mqe
->un
.read_rev
.vpd_paddr_low
= putPaddrLow(dmabuf
->phys
);
4788 mqe
->un
.read_rev
.word1
&= 0x0000FFFF;
4789 bf_set(lpfc_mbx_rd_rev_vpd
, &mqe
->un
.read_rev
, 1);
4790 bf_set(lpfc_mbx_rd_rev_avail_len
, &mqe
->un
.read_rev
, dma_size
);
4792 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4794 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4795 dmabuf
->virt
, dmabuf
->phys
);
4801 * The available vpd length cannot be bigger than the
4802 * DMA buffer passed to the port. Catch the less than
4803 * case and update the caller's size.
4805 if (mqe
->un
.read_rev
.avail_vpd_len
< *vpd_size
)
4806 *vpd_size
= mqe
->un
.read_rev
.avail_vpd_len
;
4808 memcpy(vpd
, dmabuf
->virt
, *vpd_size
);
4810 dma_free_coherent(&phba
->pcidev
->dev
, dma_size
,
4811 dmabuf
->virt
, dmabuf
->phys
);
4817 * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
4818 * @phba: pointer to lpfc hba data structure.
4820 * This routine retrieves SLI4 device physical port name this PCI function
4825 * otherwise - failed to retrieve physical port name
4828 lpfc_sli4_retrieve_pport_name(struct lpfc_hba
*phba
)
4830 LPFC_MBOXQ_t
*mboxq
;
4831 struct lpfc_mbx_get_cntl_attributes
*mbx_cntl_attr
;
4832 struct lpfc_controller_attribute
*cntl_attr
;
4833 struct lpfc_mbx_get_port_name
*get_port_name
;
4834 void *virtaddr
= NULL
;
4835 uint32_t alloclen
, reqlen
;
4836 uint32_t shdr_status
, shdr_add_status
;
4837 union lpfc_sli4_cfg_shdr
*shdr
;
4838 char cport_name
= 0;
4841 /* We assume nothing at this point */
4842 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4843 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_NON
;
4845 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4848 /* obtain link type and link number via READ_CONFIG */
4849 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_INVAL
;
4850 lpfc_sli4_read_config(phba
);
4851 if (phba
->sli4_hba
.lnk_info
.lnk_dv
== LPFC_LNK_DAT_VAL
)
4852 goto retrieve_ppname
;
4854 /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
4855 reqlen
= sizeof(struct lpfc_mbx_get_cntl_attributes
);
4856 alloclen
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4857 LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES
, reqlen
,
4858 LPFC_SLI4_MBX_NEMBED
);
4859 if (alloclen
< reqlen
) {
4860 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4861 "3084 Allocated DMA memory size (%d) is "
4862 "less than the requested DMA memory size "
4863 "(%d)\n", alloclen
, reqlen
);
4865 goto out_free_mboxq
;
4867 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4868 virtaddr
= mboxq
->sge_array
->addr
[0];
4869 mbx_cntl_attr
= (struct lpfc_mbx_get_cntl_attributes
*)virtaddr
;
4870 shdr
= &mbx_cntl_attr
->cfg_shdr
;
4871 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4872 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4873 if (shdr_status
|| shdr_add_status
|| rc
) {
4874 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4875 "3085 Mailbox x%x (x%x/x%x) failed, "
4876 "rc:x%x, status:x%x, add_status:x%x\n",
4877 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4878 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4879 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4880 rc
, shdr_status
, shdr_add_status
);
4882 goto out_free_mboxq
;
4884 cntl_attr
= &mbx_cntl_attr
->cntl_attr
;
4885 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
4886 phba
->sli4_hba
.lnk_info
.lnk_tp
=
4887 bf_get(lpfc_cntl_attr_lnk_type
, cntl_attr
);
4888 phba
->sli4_hba
.lnk_info
.lnk_no
=
4889 bf_get(lpfc_cntl_attr_lnk_numb
, cntl_attr
);
4890 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4891 "3086 lnk_type:%d, lnk_numb:%d\n",
4892 phba
->sli4_hba
.lnk_info
.lnk_tp
,
4893 phba
->sli4_hba
.lnk_info
.lnk_no
);
4896 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
4897 LPFC_MBOX_OPCODE_GET_PORT_NAME
,
4898 sizeof(struct lpfc_mbx_get_port_name
) -
4899 sizeof(struct lpfc_sli4_cfg_mhdr
),
4900 LPFC_SLI4_MBX_EMBED
);
4901 get_port_name
= &mboxq
->u
.mqe
.un
.get_port_name
;
4902 shdr
= (union lpfc_sli4_cfg_shdr
*)&get_port_name
->header
.cfg_shdr
;
4903 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
, LPFC_OPCODE_VERSION_1
);
4904 bf_set(lpfc_mbx_get_port_name_lnk_type
, &get_port_name
->u
.request
,
4905 phba
->sli4_hba
.lnk_info
.lnk_tp
);
4906 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4907 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
4908 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
4909 if (shdr_status
|| shdr_add_status
|| rc
) {
4910 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
4911 "3087 Mailbox x%x (x%x/x%x) failed: "
4912 "rc:x%x, status:x%x, add_status:x%x\n",
4913 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
4914 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
4915 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
4916 rc
, shdr_status
, shdr_add_status
);
4918 goto out_free_mboxq
;
4920 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
4921 case LPFC_LINK_NUMBER_0
:
4922 cport_name
= bf_get(lpfc_mbx_get_port_name_name0
,
4923 &get_port_name
->u
.response
);
4924 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4926 case LPFC_LINK_NUMBER_1
:
4927 cport_name
= bf_get(lpfc_mbx_get_port_name_name1
,
4928 &get_port_name
->u
.response
);
4929 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4931 case LPFC_LINK_NUMBER_2
:
4932 cport_name
= bf_get(lpfc_mbx_get_port_name_name2
,
4933 &get_port_name
->u
.response
);
4934 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4936 case LPFC_LINK_NUMBER_3
:
4937 cport_name
= bf_get(lpfc_mbx_get_port_name_name3
,
4938 &get_port_name
->u
.response
);
4939 phba
->sli4_hba
.pport_name_sta
= LPFC_SLI4_PPNAME_GET
;
4945 if (phba
->sli4_hba
.pport_name_sta
== LPFC_SLI4_PPNAME_GET
) {
4946 phba
->Port
[0] = cport_name
;
4947 phba
->Port
[1] = '\0';
4948 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4949 "3091 SLI get port name: %s\n", phba
->Port
);
4953 if (rc
!= MBX_TIMEOUT
) {
4954 if (bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
) == MBX_SLI4_CONFIG
)
4955 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
4957 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4963 * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
4964 * @phba: pointer to lpfc hba data structure.
4966 * This routine is called to explicitly arm the SLI4 device's completion and
4970 lpfc_sli4_arm_cqeq_intr(struct lpfc_hba
*phba
)
4974 lpfc_sli4_cq_release(phba
->sli4_hba
.mbx_cq
, LPFC_QUEUE_REARM
);
4975 lpfc_sli4_cq_release(phba
->sli4_hba
.els_cq
, LPFC_QUEUE_REARM
);
4977 if (phba
->sli4_hba
.fcp_cq
) {
4979 lpfc_sli4_cq_release(phba
->sli4_hba
.fcp_cq
[fcp_eqidx
],
4981 } while (++fcp_eqidx
< phba
->cfg_fcp_io_channel
);
4983 if (phba
->sli4_hba
.hba_eq
) {
4984 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
4986 lpfc_sli4_eq_release(phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
4992 * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
4993 * @phba: Pointer to HBA context object.
4994 * @type: The resource extent type.
4995 * @extnt_count: buffer to hold port available extent count.
4996 * @extnt_size: buffer to hold element count per extent.
4998 * This function calls the port and retrievs the number of available
4999 * extents and their size for a particular extent type.
5001 * Returns: 0 if successful. Nonzero otherwise.
5004 lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
,
5005 uint16_t *extnt_count
, uint16_t *extnt_size
)
5010 struct lpfc_mbx_get_rsrc_extent_info
*rsrc_info
;
5013 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5017 /* Find out how many extents are available for this resource type */
5018 length
= (sizeof(struct lpfc_mbx_get_rsrc_extent_info
) -
5019 sizeof(struct lpfc_sli4_cfg_mhdr
));
5020 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5021 LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
,
5022 length
, LPFC_SLI4_MBX_EMBED
);
5024 /* Send an extents count of 0 - the GET doesn't use it. */
5025 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5026 LPFC_SLI4_MBX_EMBED
);
5032 if (!phba
->sli4_hba
.intr_enable
)
5033 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5035 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5036 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5043 rsrc_info
= &mbox
->u
.mqe
.un
.rsrc_extent_info
;
5044 if (bf_get(lpfc_mbox_hdr_status
,
5045 &rsrc_info
->header
.cfg_shdr
.response
)) {
5046 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5047 "2930 Failed to get resource extents "
5048 "Status 0x%x Add'l Status 0x%x\n",
5049 bf_get(lpfc_mbox_hdr_status
,
5050 &rsrc_info
->header
.cfg_shdr
.response
),
5051 bf_get(lpfc_mbox_hdr_add_status
,
5052 &rsrc_info
->header
.cfg_shdr
.response
));
5057 *extnt_count
= bf_get(lpfc_mbx_get_rsrc_extent_info_cnt
,
5059 *extnt_size
= bf_get(lpfc_mbx_get_rsrc_extent_info_size
,
5062 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5063 "3162 Retrieved extents type-%d from port: count:%d, "
5064 "size:%d\n", type
, *extnt_count
, *extnt_size
);
5067 mempool_free(mbox
, phba
->mbox_mem_pool
);
5072 * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
5073 * @phba: Pointer to HBA context object.
5074 * @type: The extent type to check.
5076 * This function reads the current available extents from the port and checks
5077 * if the extent count or extent size has changed since the last access.
5078 * Callers use this routine post port reset to understand if there is a
5079 * extent reprovisioning requirement.
5082 * -Error: error indicates problem.
5083 * 1: Extent count or size has changed.
5087 lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba
*phba
, uint16_t type
)
5089 uint16_t curr_ext_cnt
, rsrc_ext_cnt
;
5090 uint16_t size_diff
, rsrc_ext_size
;
5092 struct lpfc_rsrc_blks
*rsrc_entry
;
5093 struct list_head
*rsrc_blk_list
= NULL
;
5097 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5104 case LPFC_RSC_TYPE_FCOE_RPI
:
5105 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5107 case LPFC_RSC_TYPE_FCOE_VPI
:
5108 rsrc_blk_list
= &phba
->lpfc_vpi_blk_list
;
5110 case LPFC_RSC_TYPE_FCOE_XRI
:
5111 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5113 case LPFC_RSC_TYPE_FCOE_VFI
:
5114 rsrc_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5120 list_for_each_entry(rsrc_entry
, rsrc_blk_list
, list
) {
5122 if (rsrc_entry
->rsrc_size
!= rsrc_ext_size
)
5126 if (curr_ext_cnt
!= rsrc_ext_cnt
|| size_diff
!= 0)
5133 * lpfc_sli4_cfg_post_extnts -
5134 * @phba: Pointer to HBA context object.
5135 * @extnt_cnt - number of available extents.
5136 * @type - the extent type (rpi, xri, vfi, vpi).
5137 * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation.
5138 * @mbox - pointer to the caller's allocated mailbox structure.
5140 * This function executes the extents allocation request. It also
5141 * takes care of the amount of memory needed to allocate or get the
5142 * allocated extents. It is the caller's responsibility to evaluate
5146 * -Error: Error value describes the condition found.
5150 lpfc_sli4_cfg_post_extnts(struct lpfc_hba
*phba
, uint16_t extnt_cnt
,
5151 uint16_t type
, bool *emb
, LPFC_MBOXQ_t
*mbox
)
5156 uint32_t alloc_len
, mbox_tmo
;
5158 /* Calculate the total requested length of the dma memory */
5159 req_len
= extnt_cnt
* sizeof(uint16_t);
5162 * Calculate the size of an embedded mailbox. The uint32_t
5163 * accounts for extents-specific word.
5165 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5169 * Presume the allocation and response will fit into an embedded
5170 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5172 *emb
= LPFC_SLI4_MBX_EMBED
;
5173 if (req_len
> emb_len
) {
5174 req_len
= extnt_cnt
* sizeof(uint16_t) +
5175 sizeof(union lpfc_sli4_cfg_shdr
) +
5177 *emb
= LPFC_SLI4_MBX_NEMBED
;
5180 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5181 LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
,
5183 if (alloc_len
< req_len
) {
5184 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5185 "2982 Allocated DMA memory size (x%x) is "
5186 "less than the requested DMA memory "
5187 "size (x%x)\n", alloc_len
, req_len
);
5190 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, extnt_cnt
, type
, *emb
);
5194 if (!phba
->sli4_hba
.intr_enable
)
5195 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5197 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5198 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5207 * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
5208 * @phba: Pointer to HBA context object.
5209 * @type: The resource extent type to allocate.
5211 * This function allocates the number of elements for the specified
5215 lpfc_sli4_alloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5218 uint16_t rsrc_id_cnt
, rsrc_cnt
, rsrc_size
;
5219 uint16_t rsrc_id
, rsrc_start
, j
, k
;
5222 unsigned long longs
;
5223 unsigned long *bmask
;
5224 struct lpfc_rsrc_blks
*rsrc_blks
;
5227 struct lpfc_id_range
*id_array
= NULL
;
5228 void *virtaddr
= NULL
;
5229 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5230 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5231 struct list_head
*ext_blk_list
;
5233 rc
= lpfc_sli4_get_avail_extnt_rsrc(phba
, type
,
5239 if ((rsrc_cnt
== 0) || (rsrc_size
== 0)) {
5240 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5241 "3009 No available Resource Extents "
5242 "for resource type 0x%x: Count: 0x%x, "
5243 "Size 0x%x\n", type
, rsrc_cnt
,
5248 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_INIT
| LOG_SLI
,
5249 "2903 Post resource extents type-0x%x: "
5250 "count:%d, size %d\n", type
, rsrc_cnt
, rsrc_size
);
5252 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5256 rc
= lpfc_sli4_cfg_post_extnts(phba
, rsrc_cnt
, type
, &emb
, mbox
);
5263 * Figure out where the response is located. Then get local pointers
5264 * to the response data. The port does not guarantee to respond to
5265 * all extents counts request so update the local variable with the
5266 * allocated count from the port.
5268 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5269 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5270 id_array
= &rsrc_ext
->u
.rsp
.id
[0];
5271 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5273 virtaddr
= mbox
->sge_array
->addr
[0];
5274 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5275 rsrc_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5276 id_array
= &n_rsrc
->id
;
5279 longs
= ((rsrc_cnt
* rsrc_size
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5280 rsrc_id_cnt
= rsrc_cnt
* rsrc_size
;
5283 * Based on the resource size and count, correct the base and max
5286 length
= sizeof(struct lpfc_rsrc_blks
);
5288 case LPFC_RSC_TYPE_FCOE_RPI
:
5289 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5290 sizeof(unsigned long),
5292 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5296 phba
->sli4_hba
.rpi_ids
= kzalloc(rsrc_id_cnt
*
5299 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5300 kfree(phba
->sli4_hba
.rpi_bmask
);
5306 * The next_rpi was initialized with the maximum available
5307 * count but the port may allocate a smaller number. Catch
5308 * that case and update the next_rpi.
5310 phba
->sli4_hba
.next_rpi
= rsrc_id_cnt
;
5312 /* Initialize local ptrs for common extent processing later. */
5313 bmask
= phba
->sli4_hba
.rpi_bmask
;
5314 ids
= phba
->sli4_hba
.rpi_ids
;
5315 ext_blk_list
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5317 case LPFC_RSC_TYPE_FCOE_VPI
:
5318 phba
->vpi_bmask
= kzalloc(longs
*
5319 sizeof(unsigned long),
5321 if (unlikely(!phba
->vpi_bmask
)) {
5325 phba
->vpi_ids
= kzalloc(rsrc_id_cnt
*
5328 if (unlikely(!phba
->vpi_ids
)) {
5329 kfree(phba
->vpi_bmask
);
5334 /* Initialize local ptrs for common extent processing later. */
5335 bmask
= phba
->vpi_bmask
;
5336 ids
= phba
->vpi_ids
;
5337 ext_blk_list
= &phba
->lpfc_vpi_blk_list
;
5339 case LPFC_RSC_TYPE_FCOE_XRI
:
5340 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5341 sizeof(unsigned long),
5343 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5347 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5348 phba
->sli4_hba
.xri_ids
= kzalloc(rsrc_id_cnt
*
5351 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5352 kfree(phba
->sli4_hba
.xri_bmask
);
5357 /* Initialize local ptrs for common extent processing later. */
5358 bmask
= phba
->sli4_hba
.xri_bmask
;
5359 ids
= phba
->sli4_hba
.xri_ids
;
5360 ext_blk_list
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5362 case LPFC_RSC_TYPE_FCOE_VFI
:
5363 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5364 sizeof(unsigned long),
5366 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5370 phba
->sli4_hba
.vfi_ids
= kzalloc(rsrc_id_cnt
*
5373 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5374 kfree(phba
->sli4_hba
.vfi_bmask
);
5379 /* Initialize local ptrs for common extent processing later. */
5380 bmask
= phba
->sli4_hba
.vfi_bmask
;
5381 ids
= phba
->sli4_hba
.vfi_ids
;
5382 ext_blk_list
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5385 /* Unsupported Opcode. Fail call. */
5389 ext_blk_list
= NULL
;
5394 * Complete initializing the extent configuration with the
5395 * allocated ids assigned to this function. The bitmask serves
5396 * as an index into the array and manages the available ids. The
5397 * array just stores the ids communicated to the port via the wqes.
5399 for (i
= 0, j
= 0, k
= 0; i
< rsrc_cnt
; i
++) {
5401 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_0
,
5404 rsrc_id
= bf_get(lpfc_mbx_rsrc_id_word4_1
,
5407 rsrc_blks
= kzalloc(length
, GFP_KERNEL
);
5408 if (unlikely(!rsrc_blks
)) {
5414 rsrc_blks
->rsrc_start
= rsrc_id
;
5415 rsrc_blks
->rsrc_size
= rsrc_size
;
5416 list_add_tail(&rsrc_blks
->list
, ext_blk_list
);
5417 rsrc_start
= rsrc_id
;
5418 if ((type
== LPFC_RSC_TYPE_FCOE_XRI
) && (j
== 0))
5419 phba
->sli4_hba
.scsi_xri_start
= rsrc_start
+
5420 lpfc_sli4_get_els_iocb_cnt(phba
);
5422 while (rsrc_id
< (rsrc_start
+ rsrc_size
)) {
5427 /* Entire word processed. Get next word.*/
5432 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5437 * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
5438 * @phba: Pointer to HBA context object.
5439 * @type: the extent's type.
5441 * This function deallocates all extents of a particular resource type.
5442 * SLI4 does not allow for deallocating a particular extent range. It
5443 * is the caller's responsibility to release all kernel memory resources.
5446 lpfc_sli4_dealloc_extent(struct lpfc_hba
*phba
, uint16_t type
)
5449 uint32_t length
, mbox_tmo
= 0;
5451 struct lpfc_mbx_dealloc_rsrc_extents
*dealloc_rsrc
;
5452 struct lpfc_rsrc_blks
*rsrc_blk
, *rsrc_blk_next
;
5454 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5459 * This function sends an embedded mailbox because it only sends the
5460 * the resource type. All extents of this type are released by the
5463 length
= (sizeof(struct lpfc_mbx_dealloc_rsrc_extents
) -
5464 sizeof(struct lpfc_sli4_cfg_mhdr
));
5465 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5466 LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
,
5467 length
, LPFC_SLI4_MBX_EMBED
);
5469 /* Send an extents count of 0 - the dealloc doesn't use it. */
5470 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, 0, type
,
5471 LPFC_SLI4_MBX_EMBED
);
5476 if (!phba
->sli4_hba
.intr_enable
)
5477 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5479 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5480 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5487 dealloc_rsrc
= &mbox
->u
.mqe
.un
.dealloc_rsrc_extents
;
5488 if (bf_get(lpfc_mbox_hdr_status
,
5489 &dealloc_rsrc
->header
.cfg_shdr
.response
)) {
5490 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5491 "2919 Failed to release resource extents "
5492 "for type %d - Status 0x%x Add'l Status 0x%x. "
5493 "Resource memory not released.\n",
5495 bf_get(lpfc_mbox_hdr_status
,
5496 &dealloc_rsrc
->header
.cfg_shdr
.response
),
5497 bf_get(lpfc_mbox_hdr_add_status
,
5498 &dealloc_rsrc
->header
.cfg_shdr
.response
));
5503 /* Release kernel memory resources for the specific type. */
5505 case LPFC_RSC_TYPE_FCOE_VPI
:
5506 kfree(phba
->vpi_bmask
);
5507 kfree(phba
->vpi_ids
);
5508 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5509 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5510 &phba
->lpfc_vpi_blk_list
, list
) {
5511 list_del_init(&rsrc_blk
->list
);
5515 case LPFC_RSC_TYPE_FCOE_XRI
:
5516 kfree(phba
->sli4_hba
.xri_bmask
);
5517 kfree(phba
->sli4_hba
.xri_ids
);
5518 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5519 &phba
->sli4_hba
.lpfc_xri_blk_list
, list
) {
5520 list_del_init(&rsrc_blk
->list
);
5524 case LPFC_RSC_TYPE_FCOE_VFI
:
5525 kfree(phba
->sli4_hba
.vfi_bmask
);
5526 kfree(phba
->sli4_hba
.vfi_ids
);
5527 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5528 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5529 &phba
->sli4_hba
.lpfc_vfi_blk_list
, list
) {
5530 list_del_init(&rsrc_blk
->list
);
5534 case LPFC_RSC_TYPE_FCOE_RPI
:
5535 /* RPI bitmask and physical id array are cleaned up earlier. */
5536 list_for_each_entry_safe(rsrc_blk
, rsrc_blk_next
,
5537 &phba
->sli4_hba
.lpfc_rpi_blk_list
, list
) {
5538 list_del_init(&rsrc_blk
->list
);
5546 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5549 mempool_free(mbox
, phba
->mbox_mem_pool
);
5554 * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
5555 * @phba: Pointer to HBA context object.
5557 * This function allocates all SLI4 resource identifiers.
5560 lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba
*phba
)
5562 int i
, rc
, error
= 0;
5563 uint16_t count
, base
;
5564 unsigned long longs
;
5566 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5567 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5568 if (phba
->sli4_hba
.extents_in_use
) {
5570 * The port supports resource extents. The XRI, VPI, VFI, RPI
5571 * resource extent count must be read and allocated before
5572 * provisioning the resource id arrays.
5574 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5575 LPFC_IDX_RSRC_RDY
) {
5577 * Extent-based resources are set - the driver could
5578 * be in a port reset. Figure out if any corrective
5579 * actions need to be taken.
5581 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5582 LPFC_RSC_TYPE_FCOE_VFI
);
5585 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5586 LPFC_RSC_TYPE_FCOE_VPI
);
5589 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5590 LPFC_RSC_TYPE_FCOE_XRI
);
5593 rc
= lpfc_sli4_chk_avail_extnt_rsrc(phba
,
5594 LPFC_RSC_TYPE_FCOE_RPI
);
5599 * It's possible that the number of resources
5600 * provided to this port instance changed between
5601 * resets. Detect this condition and reallocate
5602 * resources. Otherwise, there is no action.
5605 lpfc_printf_log(phba
, KERN_INFO
,
5606 LOG_MBOX
| LOG_INIT
,
5607 "2931 Detected extent resource "
5608 "change. Reallocating all "
5610 rc
= lpfc_sli4_dealloc_extent(phba
,
5611 LPFC_RSC_TYPE_FCOE_VFI
);
5612 rc
= lpfc_sli4_dealloc_extent(phba
,
5613 LPFC_RSC_TYPE_FCOE_VPI
);
5614 rc
= lpfc_sli4_dealloc_extent(phba
,
5615 LPFC_RSC_TYPE_FCOE_XRI
);
5616 rc
= lpfc_sli4_dealloc_extent(phba
,
5617 LPFC_RSC_TYPE_FCOE_RPI
);
5622 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5626 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5630 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5634 rc
= lpfc_sli4_alloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5637 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5642 * The port does not support resource extents. The XRI, VPI,
5643 * VFI, RPI resource ids were determined from READ_CONFIG.
5644 * Just allocate the bitmasks and provision the resource id
5645 * arrays. If a port reset is active, the resources don't
5646 * need any action - just exit.
5648 if (bf_get(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) ==
5649 LPFC_IDX_RSRC_RDY
) {
5650 lpfc_sli4_dealloc_resource_identifiers(phba
);
5651 lpfc_sli4_remove_rpis(phba
);
5654 count
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5656 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5657 "3279 Invalid provisioning of "
5662 base
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5663 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5664 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
*
5665 sizeof(unsigned long),
5667 if (unlikely(!phba
->sli4_hba
.rpi_bmask
)) {
5671 phba
->sli4_hba
.rpi_ids
= kzalloc(count
*
5674 if (unlikely(!phba
->sli4_hba
.rpi_ids
)) {
5676 goto free_rpi_bmask
;
5679 for (i
= 0; i
< count
; i
++)
5680 phba
->sli4_hba
.rpi_ids
[i
] = base
+ i
;
5683 count
= phba
->sli4_hba
.max_cfg_param
.max_vpi
;
5685 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5686 "3280 Invalid provisioning of "
5691 base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5692 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5693 phba
->vpi_bmask
= kzalloc(longs
*
5694 sizeof(unsigned long),
5696 if (unlikely(!phba
->vpi_bmask
)) {
5700 phba
->vpi_ids
= kzalloc(count
*
5703 if (unlikely(!phba
->vpi_ids
)) {
5705 goto free_vpi_bmask
;
5708 for (i
= 0; i
< count
; i
++)
5709 phba
->vpi_ids
[i
] = base
+ i
;
5712 count
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5714 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5715 "3281 Invalid provisioning of "
5720 base
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5721 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5722 phba
->sli4_hba
.xri_bmask
= kzalloc(longs
*
5723 sizeof(unsigned long),
5725 if (unlikely(!phba
->sli4_hba
.xri_bmask
)) {
5729 phba
->sli4_hba
.max_cfg_param
.xri_used
= 0;
5730 phba
->sli4_hba
.xri_ids
= kzalloc(count
*
5733 if (unlikely(!phba
->sli4_hba
.xri_ids
)) {
5735 goto free_xri_bmask
;
5738 for (i
= 0; i
< count
; i
++)
5739 phba
->sli4_hba
.xri_ids
[i
] = base
+ i
;
5742 count
= phba
->sli4_hba
.max_cfg_param
.max_vfi
;
5744 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5745 "3282 Invalid provisioning of "
5750 base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5751 longs
= (count
+ BITS_PER_LONG
- 1) / BITS_PER_LONG
;
5752 phba
->sli4_hba
.vfi_bmask
= kzalloc(longs
*
5753 sizeof(unsigned long),
5755 if (unlikely(!phba
->sli4_hba
.vfi_bmask
)) {
5759 phba
->sli4_hba
.vfi_ids
= kzalloc(count
*
5762 if (unlikely(!phba
->sli4_hba
.vfi_ids
)) {
5764 goto free_vfi_bmask
;
5767 for (i
= 0; i
< count
; i
++)
5768 phba
->sli4_hba
.vfi_ids
[i
] = base
+ i
;
5771 * Mark all resources ready. An HBA reset doesn't need
5772 * to reset the initialization.
5774 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
5780 kfree(phba
->sli4_hba
.vfi_bmask
);
5782 kfree(phba
->sli4_hba
.xri_ids
);
5784 kfree(phba
->sli4_hba
.xri_bmask
);
5786 kfree(phba
->vpi_ids
);
5788 kfree(phba
->vpi_bmask
);
5790 kfree(phba
->sli4_hba
.rpi_ids
);
5792 kfree(phba
->sli4_hba
.rpi_bmask
);
5798 * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
5799 * @phba: Pointer to HBA context object.
5801 * This function allocates the number of elements for the specified
5805 lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba
*phba
)
5807 if (phba
->sli4_hba
.extents_in_use
) {
5808 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VPI
);
5809 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_RPI
);
5810 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_XRI
);
5811 lpfc_sli4_dealloc_extent(phba
, LPFC_RSC_TYPE_FCOE_VFI
);
5813 kfree(phba
->vpi_bmask
);
5814 kfree(phba
->vpi_ids
);
5815 bf_set(lpfc_vpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5816 kfree(phba
->sli4_hba
.xri_bmask
);
5817 kfree(phba
->sli4_hba
.xri_ids
);
5818 kfree(phba
->sli4_hba
.vfi_bmask
);
5819 kfree(phba
->sli4_hba
.vfi_ids
);
5820 bf_set(lpfc_vfi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5821 bf_set(lpfc_idx_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
5828 * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
5829 * @phba: Pointer to HBA context object.
5830 * @type: The resource extent type.
5831 * @extnt_count: buffer to hold port extent count response
5832 * @extnt_size: buffer to hold port extent size response.
5834 * This function calls the port to read the host allocated extents
5835 * for a particular type.
5838 lpfc_sli4_get_allocated_extnts(struct lpfc_hba
*phba
, uint16_t type
,
5839 uint16_t *extnt_cnt
, uint16_t *extnt_size
)
5843 uint16_t curr_blks
= 0;
5844 uint32_t req_len
, emb_len
;
5845 uint32_t alloc_len
, mbox_tmo
;
5846 struct list_head
*blk_list_head
;
5847 struct lpfc_rsrc_blks
*rsrc_blk
;
5849 void *virtaddr
= NULL
;
5850 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc
;
5851 struct lpfc_mbx_alloc_rsrc_extents
*rsrc_ext
;
5852 union lpfc_sli4_cfg_shdr
*shdr
;
5855 case LPFC_RSC_TYPE_FCOE_VPI
:
5856 blk_list_head
= &phba
->lpfc_vpi_blk_list
;
5858 case LPFC_RSC_TYPE_FCOE_XRI
:
5859 blk_list_head
= &phba
->sli4_hba
.lpfc_xri_blk_list
;
5861 case LPFC_RSC_TYPE_FCOE_VFI
:
5862 blk_list_head
= &phba
->sli4_hba
.lpfc_vfi_blk_list
;
5864 case LPFC_RSC_TYPE_FCOE_RPI
:
5865 blk_list_head
= &phba
->sli4_hba
.lpfc_rpi_blk_list
;
5871 /* Count the number of extents currently allocatd for this type. */
5872 list_for_each_entry(rsrc_blk
, blk_list_head
, list
) {
5873 if (curr_blks
== 0) {
5875 * The GET_ALLOCATED mailbox does not return the size,
5876 * just the count. The size should be just the size
5877 * stored in the current allocated block and all sizes
5878 * for an extent type are the same so set the return
5881 *extnt_size
= rsrc_blk
->rsrc_size
;
5886 /* Calculate the total requested length of the dma memory. */
5887 req_len
= curr_blks
* sizeof(uint16_t);
5890 * Calculate the size of an embedded mailbox. The uint32_t
5891 * accounts for extents-specific word.
5893 emb_len
= sizeof(MAILBOX_t
) - sizeof(struct mbox_header
) -
5897 * Presume the allocation and response will fit into an embedded
5898 * mailbox. If not true, reconfigure to a non-embedded mailbox.
5900 emb
= LPFC_SLI4_MBX_EMBED
;
5902 if (req_len
> emb_len
) {
5903 req_len
= curr_blks
* sizeof(uint16_t) +
5904 sizeof(union lpfc_sli4_cfg_shdr
) +
5906 emb
= LPFC_SLI4_MBX_NEMBED
;
5909 mbox
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5912 memset(mbox
, 0, sizeof(LPFC_MBOXQ_t
));
5914 alloc_len
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5915 LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
,
5917 if (alloc_len
< req_len
) {
5918 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5919 "2983 Allocated DMA memory size (x%x) is "
5920 "less than the requested DMA memory "
5921 "size (x%x)\n", alloc_len
, req_len
);
5925 rc
= lpfc_sli4_mbox_rsrc_extent(phba
, mbox
, curr_blks
, type
, emb
);
5931 if (!phba
->sli4_hba
.intr_enable
)
5932 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
5934 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
5935 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
5944 * Figure out where the response is located. Then get local pointers
5945 * to the response data. The port does not guarantee to respond to
5946 * all extents counts request so update the local variable with the
5947 * allocated count from the port.
5949 if (emb
== LPFC_SLI4_MBX_EMBED
) {
5950 rsrc_ext
= &mbox
->u
.mqe
.un
.alloc_rsrc_extents
;
5951 shdr
= &rsrc_ext
->header
.cfg_shdr
;
5952 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, &rsrc_ext
->u
.rsp
);
5954 virtaddr
= mbox
->sge_array
->addr
[0];
5955 n_rsrc
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
5956 shdr
= &n_rsrc
->cfg_shdr
;
5957 *extnt_cnt
= bf_get(lpfc_mbx_rsrc_cnt
, n_rsrc
);
5960 if (bf_get(lpfc_mbox_hdr_status
, &shdr
->response
)) {
5961 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_INIT
,
5962 "2984 Failed to read allocated resources "
5963 "for type %d - Status 0x%x Add'l Status 0x%x.\n",
5965 bf_get(lpfc_mbox_hdr_status
, &shdr
->response
),
5966 bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
));
5971 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
5976 * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block
5977 * @phba: pointer to lpfc hba data structure.
5979 * This routine walks the list of els buffers that have been allocated and
5980 * repost them to the port by using SGL block post. This is needed after a
5981 * pci_function_reset/warm_start or start. It attempts to construct blocks
5982 * of els buffer sgls which contains contiguous xris and uses the non-embedded
5983 * SGL block post mailbox commands to post them to the port. For single els
5984 * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
5985 * mailbox command for posting.
5987 * Returns: 0 = success, non-zero failure.
5990 lpfc_sli4_repost_els_sgl_list(struct lpfc_hba
*phba
)
5992 struct lpfc_sglq
*sglq_entry
= NULL
;
5993 struct lpfc_sglq
*sglq_entry_next
= NULL
;
5994 struct lpfc_sglq
*sglq_entry_first
= NULL
;
5995 int status
, post_cnt
= 0, num_posted
= 0, block_cnt
= 0;
5996 int last_xritag
= NO_XRI
;
5997 LIST_HEAD(prep_sgl_list
);
5998 LIST_HEAD(blck_sgl_list
);
5999 LIST_HEAD(allc_sgl_list
);
6000 LIST_HEAD(post_sgl_list
);
6001 LIST_HEAD(free_sgl_list
);
6003 spin_lock_irq(&phba
->hbalock
);
6004 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &allc_sgl_list
);
6005 spin_unlock_irq(&phba
->hbalock
);
6007 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
6008 &allc_sgl_list
, list
) {
6009 list_del_init(&sglq_entry
->list
);
6011 if ((last_xritag
!= NO_XRI
) &&
6012 (sglq_entry
->sli4_xritag
!= last_xritag
+ 1)) {
6013 /* a hole in xri block, form a sgl posting block */
6014 list_splice_init(&prep_sgl_list
, &blck_sgl_list
);
6015 post_cnt
= block_cnt
- 1;
6016 /* prepare list for next posting block */
6017 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6020 /* prepare list for next posting block */
6021 list_add_tail(&sglq_entry
->list
, &prep_sgl_list
);
6022 /* enough sgls for non-embed sgl mbox command */
6023 if (block_cnt
== LPFC_NEMBED_MBOX_SGL_CNT
) {
6024 list_splice_init(&prep_sgl_list
,
6026 post_cnt
= block_cnt
;
6032 /* keep track of last sgl's xritag */
6033 last_xritag
= sglq_entry
->sli4_xritag
;
6035 /* end of repost sgl list condition for els buffers */
6036 if (num_posted
== phba
->sli4_hba
.els_xri_cnt
) {
6037 if (post_cnt
== 0) {
6038 list_splice_init(&prep_sgl_list
,
6040 post_cnt
= block_cnt
;
6041 } else if (block_cnt
== 1) {
6042 status
= lpfc_sli4_post_sgl(phba
,
6043 sglq_entry
->phys
, 0,
6044 sglq_entry
->sli4_xritag
);
6046 /* successful, put sgl to posted list */
6047 list_add_tail(&sglq_entry
->list
,
6050 /* Failure, put sgl to free list */
6051 lpfc_printf_log(phba
, KERN_WARNING
,
6053 "3159 Failed to post els "
6054 "sgl, xritag:x%x\n",
6055 sglq_entry
->sli4_xritag
);
6056 list_add_tail(&sglq_entry
->list
,
6058 spin_lock_irq(&phba
->hbalock
);
6059 phba
->sli4_hba
.els_xri_cnt
--;
6060 spin_unlock_irq(&phba
->hbalock
);
6065 /* continue until a nembed page worth of sgls */
6069 /* post the els buffer list sgls as a block */
6070 status
= lpfc_sli4_post_els_sgl_list(phba
, &blck_sgl_list
,
6074 /* success, put sgl list to posted sgl list */
6075 list_splice_init(&blck_sgl_list
, &post_sgl_list
);
6077 /* Failure, put sgl list to free sgl list */
6078 sglq_entry_first
= list_first_entry(&blck_sgl_list
,
6081 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6082 "3160 Failed to post els sgl-list, "
6084 sglq_entry_first
->sli4_xritag
,
6085 (sglq_entry_first
->sli4_xritag
+
6087 list_splice_init(&blck_sgl_list
, &free_sgl_list
);
6088 spin_lock_irq(&phba
->hbalock
);
6089 phba
->sli4_hba
.els_xri_cnt
-= post_cnt
;
6090 spin_unlock_irq(&phba
->hbalock
);
6093 /* don't reset xirtag due to hole in xri block */
6095 last_xritag
= NO_XRI
;
6097 /* reset els sgl post count for next round of posting */
6101 /* free the els sgls failed to post */
6102 lpfc_free_sgl_list(phba
, &free_sgl_list
);
6104 /* push els sgls posted to the availble list */
6105 if (!list_empty(&post_sgl_list
)) {
6106 spin_lock_irq(&phba
->hbalock
);
6107 list_splice_init(&post_sgl_list
,
6108 &phba
->sli4_hba
.lpfc_sgl_list
);
6109 spin_unlock_irq(&phba
->hbalock
);
6111 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6112 "3161 Failure to post els sgl to port.\n");
6119 * lpfc_sli4_hba_setup - SLI4 device intialization PCI function
6120 * @phba: Pointer to HBA context object.
6122 * This function is the main SLI4 device intialization PCI function. This
6123 * function is called by the HBA intialization code, HBA reset code and
6124 * HBA error attention handler code. Caller is not required to hold any
6128 lpfc_sli4_hba_setup(struct lpfc_hba
*phba
)
6131 LPFC_MBOXQ_t
*mboxq
;
6132 struct lpfc_mqe
*mqe
;
6135 uint32_t ftr_rsp
= 0;
6136 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
6137 struct lpfc_vport
*vport
= phba
->pport
;
6138 struct lpfc_dmabuf
*mp
;
6140 /* Perform a PCI function reset to start from clean */
6141 rc
= lpfc_pci_function_reset(phba
);
6145 /* Check the HBA Host Status Register for readyness */
6146 rc
= lpfc_sli4_post_status_check(phba
);
6150 spin_lock_irq(&phba
->hbalock
);
6151 phba
->sli
.sli_flag
|= LPFC_SLI_ACTIVE
;
6152 spin_unlock_irq(&phba
->hbalock
);
6156 * Allocate a single mailbox container for initializing the
6159 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6163 /* Issue READ_REV to collect vpd and FW information. */
6164 vpd_size
= SLI4_PAGE_SIZE
;
6165 vpd
= kzalloc(vpd_size
, GFP_KERNEL
);
6171 rc
= lpfc_sli4_read_rev(phba
, mboxq
, vpd
, &vpd_size
);
6176 mqe
= &mboxq
->u
.mqe
;
6177 phba
->sli_rev
= bf_get(lpfc_mbx_rd_rev_sli_lvl
, &mqe
->un
.read_rev
);
6178 if (bf_get(lpfc_mbx_rd_rev_fcoe
, &mqe
->un
.read_rev
))
6179 phba
->hba_flag
|= HBA_FCOE_MODE
;
6181 phba
->hba_flag
&= ~HBA_FCOE_MODE
;
6183 if (bf_get(lpfc_mbx_rd_rev_cee_ver
, &mqe
->un
.read_rev
) ==
6185 phba
->hba_flag
|= HBA_FIP_SUPPORT
;
6187 phba
->hba_flag
&= ~HBA_FIP_SUPPORT
;
6189 phba
->hba_flag
&= ~HBA_FCP_IOQ_FLUSH
;
6191 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
6192 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6193 "0376 READ_REV Error. SLI Level %d "
6194 "FCoE enabled %d\n",
6195 phba
->sli_rev
, phba
->hba_flag
& HBA_FCOE_MODE
);
6202 * Continue initialization with default values even if driver failed
6203 * to read FCoE param config regions, only read parameters if the
6206 if (phba
->hba_flag
& HBA_FCOE_MODE
&&
6207 lpfc_sli4_read_fcoe_params(phba
))
6208 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_INIT
,
6209 "2570 Failed to read FCoE parameters\n");
6212 * Retrieve sli4 device physical port name, failure of doing it
6213 * is considered as non-fatal.
6215 rc
= lpfc_sli4_retrieve_pport_name(phba
);
6217 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6218 "3080 Successful retrieving SLI4 device "
6219 "physical port name: %s.\n", phba
->Port
);
6222 * Evaluate the read rev and vpd data. Populate the driver
6223 * state with the results. If this routine fails, the failure
6224 * is not fatal as the driver will use generic values.
6226 rc
= lpfc_parse_vpd(phba
, vpd
, vpd_size
);
6227 if (unlikely(!rc
)) {
6228 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6229 "0377 Error %d parsing vpd. "
6230 "Using defaults.\n", rc
);
6235 /* Save information as VPD data */
6236 phba
->vpd
.rev
.biuRev
= mqe
->un
.read_rev
.first_hw_rev
;
6237 phba
->vpd
.rev
.smRev
= mqe
->un
.read_rev
.second_hw_rev
;
6238 phba
->vpd
.rev
.endecRev
= mqe
->un
.read_rev
.third_hw_rev
;
6239 phba
->vpd
.rev
.fcphHigh
= bf_get(lpfc_mbx_rd_rev_fcph_high
,
6241 phba
->vpd
.rev
.fcphLow
= bf_get(lpfc_mbx_rd_rev_fcph_low
,
6243 phba
->vpd
.rev
.feaLevelHigh
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_high
,
6245 phba
->vpd
.rev
.feaLevelLow
= bf_get(lpfc_mbx_rd_rev_ftr_lvl_low
,
6247 phba
->vpd
.rev
.sli1FwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6248 memcpy(phba
->vpd
.rev
.sli1FwName
, mqe
->un
.read_rev
.fw_name
, 16);
6249 phba
->vpd
.rev
.sli2FwRev
= mqe
->un
.read_rev
.ulp_fw_id_rev
;
6250 memcpy(phba
->vpd
.rev
.sli2FwName
, mqe
->un
.read_rev
.ulp_fw_name
, 16);
6251 phba
->vpd
.rev
.opFwRev
= mqe
->un
.read_rev
.fw_id_rev
;
6252 memcpy(phba
->vpd
.rev
.opFwName
, mqe
->un
.read_rev
.fw_name
, 16);
6253 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6254 "(%d):0380 READ_REV Status x%x "
6255 "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
6256 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
6257 bf_get(lpfc_mqe_status
, mqe
),
6258 phba
->vpd
.rev
.opFwName
,
6259 phba
->vpd
.rev
.fcphHigh
, phba
->vpd
.rev
.fcphLow
,
6260 phba
->vpd
.rev
.feaLevelHigh
, phba
->vpd
.rev
.feaLevelLow
);
6263 * Discover the port's supported feature set and match it against the
6266 lpfc_request_features(phba
, mboxq
);
6267 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6274 * The port must support FCP initiator mode as this is the
6275 * only mode running in the host.
6277 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi
, &mqe
->un
.req_ftrs
))) {
6278 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6279 "0378 No support for fcpi mode.\n");
6282 if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh
, &mqe
->un
.req_ftrs
))
6283 phba
->sli3_options
|= LPFC_SLI4_PERFH_ENABLED
;
6285 phba
->sli3_options
&= ~LPFC_SLI4_PERFH_ENABLED
;
6287 * If the port cannot support the host's requested features
6288 * then turn off the global config parameters to disable the
6289 * feature in the driver. This is not a fatal error.
6291 phba
->sli3_options
&= ~LPFC_SLI3_BG_ENABLED
;
6292 if (phba
->cfg_enable_bg
) {
6293 if (bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
))
6294 phba
->sli3_options
|= LPFC_SLI3_BG_ENABLED
;
6299 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
6300 !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6304 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
6305 "0379 Feature Mismatch Data: x%08x %08x "
6306 "x%x x%x x%x\n", mqe
->un
.req_ftrs
.word2
,
6307 mqe
->un
.req_ftrs
.word3
, phba
->cfg_enable_bg
,
6308 phba
->cfg_enable_npiv
, phba
->max_vpi
);
6309 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif
, &mqe
->un
.req_ftrs
)))
6310 phba
->cfg_enable_bg
= 0;
6311 if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv
, &mqe
->un
.req_ftrs
)))
6312 phba
->cfg_enable_npiv
= 0;
6315 /* These SLI3 features are assumed in SLI4 */
6316 spin_lock_irq(&phba
->hbalock
);
6317 phba
->sli3_options
|= (LPFC_SLI3_NPIV_ENABLED
| LPFC_SLI3_HBQ_ENABLED
);
6318 spin_unlock_irq(&phba
->hbalock
);
6321 * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
6322 * calls depends on these resources to complete port setup.
6324 rc
= lpfc_sli4_alloc_resource_identifiers(phba
);
6326 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6327 "2920 Failed to alloc Resource IDs "
6332 /* Read the port's service parameters. */
6333 rc
= lpfc_read_sparam(phba
, mboxq
, vport
->vpi
);
6335 phba
->link_state
= LPFC_HBA_ERROR
;
6340 mboxq
->vport
= vport
;
6341 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6342 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
6343 if (rc
== MBX_SUCCESS
) {
6344 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof(struct serv_parm
));
6349 * This memory was allocated by the lpfc_read_sparam routine. Release
6350 * it to the mbuf pool.
6352 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
6354 mboxq
->context1
= NULL
;
6356 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6357 "0382 READ_SPARAM command failed "
6358 "status %d, mbxStatus x%x\n",
6359 rc
, bf_get(lpfc_mqe_status
, mqe
));
6360 phba
->link_state
= LPFC_HBA_ERROR
;
6365 lpfc_update_vport_wwn(vport
);
6367 /* Update the fc_host data structures with new wwn. */
6368 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
6369 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
6371 /* update host els and scsi xri-sgl sizes and mappings */
6372 rc
= lpfc_sli4_xri_sgl_update(phba
);
6374 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6375 "1400 Failed to update xri-sgl size and "
6376 "mapping: %d\n", rc
);
6380 /* register the els sgl pool to the port */
6381 rc
= lpfc_sli4_repost_els_sgl_list(phba
);
6383 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6384 "0582 Error %d during els sgl post "
6390 /* register the allocated scsi sgl pool to the port */
6391 rc
= lpfc_sli4_repost_scsi_sgl_list(phba
);
6393 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6394 "0383 Error %d during scsi sgl post "
6396 /* Some Scsi buffers were moved to the abort scsi list */
6397 /* A pci function reset will repost them */
6402 /* Post the rpi header region to the device. */
6403 rc
= lpfc_sli4_post_all_rpi_hdrs(phba
);
6405 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6406 "0393 Error %d during rpi post operation\n",
6411 lpfc_sli4_node_prep(phba
);
6413 /* Create all the SLI4 queues */
6414 rc
= lpfc_sli4_queue_create(phba
);
6416 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6417 "3089 Failed to allocate queues\n");
6419 goto out_stop_timers
;
6421 /* Set up all the queues to the device */
6422 rc
= lpfc_sli4_queue_setup(phba
);
6424 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6425 "0381 Error %d during queue setup.\n ", rc
);
6426 goto out_destroy_queue
;
6429 /* Arm the CQs and then EQs on device */
6430 lpfc_sli4_arm_cqeq_intr(phba
);
6432 /* Indicate device interrupt mode */
6433 phba
->sli4_hba
.intr_enable
= 1;
6435 /* Allow asynchronous mailbox command to go through */
6436 spin_lock_irq(&phba
->hbalock
);
6437 phba
->sli
.sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
6438 spin_unlock_irq(&phba
->hbalock
);
6440 /* Post receive buffers to the device */
6441 lpfc_sli4_rb_setup(phba
);
6443 /* Reset HBA FCF states after HBA reset */
6444 phba
->fcf
.fcf_flag
= 0;
6445 phba
->fcf
.current_rec
.flag
= 0;
6447 /* Start the ELS watchdog timer */
6448 mod_timer(&vport
->els_tmofunc
,
6449 jiffies
+ HZ
* (phba
->fc_ratov
* 2));
6451 /* Start heart beat timer */
6452 mod_timer(&phba
->hb_tmofunc
,
6453 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
6454 phba
->hb_outstanding
= 0;
6455 phba
->last_completion_time
= jiffies
;
6457 /* Start error attention (ERATT) polling timer */
6458 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
6460 /* Enable PCIe device Advanced Error Reporting (AER) if configured */
6461 if (phba
->cfg_aer_support
== 1 && !(phba
->hba_flag
& HBA_AER_ENABLED
)) {
6462 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
6464 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6465 "2829 This device supports "
6466 "Advanced Error Reporting (AER)\n");
6467 spin_lock_irq(&phba
->hbalock
);
6468 phba
->hba_flag
|= HBA_AER_ENABLED
;
6469 spin_unlock_irq(&phba
->hbalock
);
6471 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6472 "2830 This device does not support "
6473 "Advanced Error Reporting (AER)\n");
6474 phba
->cfg_aer_support
= 0;
6479 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
6481 * The FC Port needs to register FCFI (index 0)
6483 lpfc_reg_fcfi(phba
, mboxq
);
6484 mboxq
->vport
= phba
->pport
;
6485 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6486 if (rc
!= MBX_SUCCESS
)
6487 goto out_unset_queue
;
6489 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
,
6490 &mboxq
->u
.mqe
.un
.reg_fcfi
);
6492 /* Check if the port is configured to be disabled */
6493 lpfc_sli_read_link_ste(phba
);
6497 * The port is ready, set the host's link state to LINK_DOWN
6498 * in preparation for link interrupts.
6500 spin_lock_irq(&phba
->hbalock
);
6501 phba
->link_state
= LPFC_LINK_DOWN
;
6502 spin_unlock_irq(&phba
->hbalock
);
6503 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) &&
6504 (phba
->hba_flag
& LINK_DISABLED
)) {
6505 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6506 "3103 Adapter Link is disabled.\n");
6507 lpfc_down_link(phba
, mboxq
);
6508 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6509 if (rc
!= MBX_SUCCESS
) {
6510 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
| LOG_SLI
,
6511 "3104 Adapter failed to issue "
6512 "DOWN_LINK mbox cmd, rc:x%x\n", rc
);
6513 goto out_unset_queue
;
6515 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
6516 /* don't perform init_link on SLI4 FC port loopback test */
6517 if (!(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
6518 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
6520 goto out_unset_queue
;
6523 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6526 /* Unset all the queues set up in this routine when error out */
6527 lpfc_sli4_queue_unset(phba
);
6529 lpfc_sli4_queue_destroy(phba
);
6531 lpfc_stop_hba_timers(phba
);
6533 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6538 * lpfc_mbox_timeout - Timeout call back function for mbox timer
6539 * @ptr: context object - pointer to hba structure.
6541 * This is the callback function for mailbox timer. The mailbox
6542 * timer is armed when a new mailbox command is issued and the timer
6543 * is deleted when the mailbox complete. The function is called by
6544 * the kernel timer code when a mailbox does not complete within
6545 * expected time. This function wakes up the worker thread to
6546 * process the mailbox timeout and returns. All the processing is
6547 * done by the worker thread function lpfc_mbox_timeout_handler.
6550 lpfc_mbox_timeout(unsigned long ptr
)
6552 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
6553 unsigned long iflag
;
6554 uint32_t tmo_posted
;
6556 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
6557 tmo_posted
= phba
->pport
->work_port_events
& WORKER_MBOX_TMO
;
6559 phba
->pport
->work_port_events
|= WORKER_MBOX_TMO
;
6560 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
6563 lpfc_worker_wake_up(phba
);
6569 * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
6570 * @phba: Pointer to HBA context object.
6572 * This function is called from worker thread when a mailbox command times out.
6573 * The caller is not required to hold any locks. This function will reset the
6574 * HBA and recover all the pending commands.
6577 lpfc_mbox_timeout_handler(struct lpfc_hba
*phba
)
6579 LPFC_MBOXQ_t
*pmbox
= phba
->sli
.mbox_active
;
6580 MAILBOX_t
*mb
= &pmbox
->u
.mb
;
6581 struct lpfc_sli
*psli
= &phba
->sli
;
6582 struct lpfc_sli_ring
*pring
;
6584 /* Check the pmbox pointer first. There is a race condition
6585 * between the mbox timeout handler getting executed in the
6586 * worklist and the mailbox actually completing. When this
6587 * race condition occurs, the mbox_active will be NULL.
6589 spin_lock_irq(&phba
->hbalock
);
6590 if (pmbox
== NULL
) {
6591 lpfc_printf_log(phba
, KERN_WARNING
,
6593 "0353 Active Mailbox cleared - mailbox timeout "
6595 spin_unlock_irq(&phba
->hbalock
);
6599 /* Mbox cmd <mbxCommand> timeout */
6600 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6601 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
6603 phba
->pport
->port_state
,
6605 phba
->sli
.mbox_active
);
6606 spin_unlock_irq(&phba
->hbalock
);
6608 /* Setting state unknown so lpfc_sli_abort_iocb_ring
6609 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
6610 * it to fail all outstanding SCSI IO.
6612 spin_lock_irq(&phba
->pport
->work_port_lock
);
6613 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
6614 spin_unlock_irq(&phba
->pport
->work_port_lock
);
6615 spin_lock_irq(&phba
->hbalock
);
6616 phba
->link_state
= LPFC_LINK_UNKNOWN
;
6617 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
6618 spin_unlock_irq(&phba
->hbalock
);
6620 pring
= &psli
->ring
[psli
->fcp_ring
];
6621 lpfc_sli_abort_iocb_ring(phba
, pring
);
6623 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6624 "0345 Resetting board due to mailbox timeout\n");
6626 /* Reset the HBA device */
6627 lpfc_reset_hba(phba
);
6631 * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
6632 * @phba: Pointer to HBA context object.
6633 * @pmbox: Pointer to mailbox object.
6634 * @flag: Flag indicating how the mailbox need to be processed.
6636 * This function is called by discovery code and HBA management code
6637 * to submit a mailbox command to firmware with SLI-3 interface spec. This
6638 * function gets the hbalock to protect the data structures.
6639 * The mailbox command can be submitted in polling mode, in which case
6640 * this function will wait in a polling loop for the completion of the
6642 * If the mailbox is submitted in no_wait mode (not polling) the
6643 * function will submit the command and returns immediately without waiting
6644 * for the mailbox completion. The no_wait is supported only when HBA
6645 * is in SLI2/SLI3 mode - interrupts are enabled.
6646 * The SLI interface allows only one mailbox pending at a time. If the
6647 * mailbox is issued in polling mode and there is already a mailbox
6648 * pending, then the function will return an error. If the mailbox is issued
6649 * in NO_WAIT mode and there is a mailbox pending already, the function
6650 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
6651 * The sli layer owns the mailbox object until the completion of mailbox
6652 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
6653 * return codes the caller owns the mailbox command after the return of
6657 lpfc_sli_issue_mbox_s3(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
,
6661 struct lpfc_sli
*psli
= &phba
->sli
;
6662 uint32_t status
, evtctr
;
6663 uint32_t ha_copy
, hc_copy
;
6665 unsigned long timeout
;
6666 unsigned long drvr_flag
= 0;
6667 uint32_t word0
, ldata
;
6668 void __iomem
*to_slim
;
6669 int processing_queue
= 0;
6671 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6673 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6674 /* processing mbox queue from intr_handler */
6675 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
6676 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6679 processing_queue
= 1;
6680 pmbox
= lpfc_mbox_get(phba
);
6682 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6687 if (pmbox
->mbox_cmpl
&& pmbox
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
6688 pmbox
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
6690 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6691 lpfc_printf_log(phba
, KERN_ERR
,
6692 LOG_MBOX
| LOG_VPORT
,
6693 "1806 Mbox x%x failed. No vport\n",
6694 pmbox
->u
.mb
.mbxCommand
);
6696 goto out_not_finished
;
6700 /* If the PCI channel is in offline state, do not post mbox. */
6701 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
6702 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6703 goto out_not_finished
;
6706 /* If HBA has a deferred error attention, fail the iocb. */
6707 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
6708 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6709 goto out_not_finished
;
6715 status
= MBX_SUCCESS
;
6717 if (phba
->link_state
== LPFC_HBA_ERROR
) {
6718 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6720 /* Mbox command <mbxCommand> cannot issue */
6721 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6722 "(%d):0311 Mailbox command x%x cannot "
6723 "issue Data: x%x x%x\n",
6724 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6725 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6726 goto out_not_finished
;
6729 if (mbx
->mbxCommand
!= MBX_KILL_BOARD
&& flag
& MBX_NOWAIT
) {
6730 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
) ||
6731 !(hc_copy
& HC_MBINT_ENA
)) {
6732 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6733 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6734 "(%d):2528 Mailbox command x%x cannot "
6735 "issue Data: x%x x%x\n",
6736 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6737 pmbox
->u
.mb
.mbxCommand
, psli
->sli_flag
, flag
);
6738 goto out_not_finished
;
6742 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6743 /* Polling for a mbox command when another one is already active
6744 * is not allowed in SLI. Also, the driver must have established
6745 * SLI2 mode to queue and process multiple mbox commands.
6748 if (flag
& MBX_POLL
) {
6749 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6751 /* Mbox command <mbxCommand> cannot issue */
6752 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6753 "(%d):2529 Mailbox command x%x "
6754 "cannot issue Data: x%x x%x\n",
6755 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6756 pmbox
->u
.mb
.mbxCommand
,
6757 psli
->sli_flag
, flag
);
6758 goto out_not_finished
;
6761 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)) {
6762 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6763 /* Mbox command <mbxCommand> cannot issue */
6764 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6765 "(%d):2530 Mailbox command x%x "
6766 "cannot issue Data: x%x x%x\n",
6767 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6768 pmbox
->u
.mb
.mbxCommand
,
6769 psli
->sli_flag
, flag
);
6770 goto out_not_finished
;
6773 /* Another mailbox command is still being processed, queue this
6774 * command to be processed later.
6776 lpfc_mbox_put(phba
, pmbox
);
6778 /* Mbox cmd issue - BUSY */
6779 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6780 "(%d):0308 Mbox cmd issue - BUSY Data: "
6781 "x%x x%x x%x x%x\n",
6782 pmbox
->vport
? pmbox
->vport
->vpi
: 0xffffff,
6783 mbx
->mbxCommand
, phba
->pport
->port_state
,
6784 psli
->sli_flag
, flag
);
6786 psli
->slistat
.mbox_busy
++;
6787 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6790 lpfc_debugfs_disc_trc(pmbox
->vport
,
6791 LPFC_DISC_TRC_MBOX_VPORT
,
6792 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
6793 (uint32_t)mbx
->mbxCommand
,
6794 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6797 lpfc_debugfs_disc_trc(phba
->pport
,
6799 "MBOX Bsy: cmd:x%x mb:x%x x%x",
6800 (uint32_t)mbx
->mbxCommand
,
6801 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6807 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
6809 /* If we are not polling, we MUST be in SLI2 mode */
6810 if (flag
!= MBX_POLL
) {
6811 if (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
) &&
6812 (mbx
->mbxCommand
!= MBX_KILL_BOARD
)) {
6813 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6814 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
6815 /* Mbox command <mbxCommand> cannot issue */
6816 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
6817 "(%d):2531 Mailbox command x%x "
6818 "cannot issue Data: x%x x%x\n",
6819 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6820 pmbox
->u
.mb
.mbxCommand
,
6821 psli
->sli_flag
, flag
);
6822 goto out_not_finished
;
6824 /* timeout active mbox command */
6825 mod_timer(&psli
->mbox_tmo
, (jiffies
+
6826 (HZ
* lpfc_mbox_tmo_val(phba
, pmbox
))));
6829 /* Mailbox cmd <cmd> issue */
6830 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
6831 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
6833 pmbox
->vport
? pmbox
->vport
->vpi
: 0,
6834 mbx
->mbxCommand
, phba
->pport
->port_state
,
6835 psli
->sli_flag
, flag
);
6837 if (mbx
->mbxCommand
!= MBX_HEARTBEAT
) {
6839 lpfc_debugfs_disc_trc(pmbox
->vport
,
6840 LPFC_DISC_TRC_MBOX_VPORT
,
6841 "MBOX Send vport: cmd:x%x mb:x%x x%x",
6842 (uint32_t)mbx
->mbxCommand
,
6843 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6846 lpfc_debugfs_disc_trc(phba
->pport
,
6848 "MBOX Send: cmd:x%x mb:x%x x%x",
6849 (uint32_t)mbx
->mbxCommand
,
6850 mbx
->un
.varWords
[0], mbx
->un
.varWords
[1]);
6854 psli
->slistat
.mbox_cmd
++;
6855 evtctr
= psli
->slistat
.mbox_event
;
6857 /* next set own bit for the adapter and copy over command word */
6858 mbx
->mbxOwner
= OWN_CHIP
;
6860 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6861 /* Populate mbox extension offset word. */
6862 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
) {
6863 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
6864 = (uint8_t *)phba
->mbox_ext
6865 - (uint8_t *)phba
->mbox
;
6868 /* Copy the mailbox extension data */
6869 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6870 lpfc_sli_pcimem_bcopy(pmbox
->context2
,
6871 (uint8_t *)phba
->mbox_ext
,
6872 pmbox
->in_ext_byte_len
);
6874 /* Copy command data to host SLIM area */
6875 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6877 /* Populate mbox extension offset word. */
6878 if (pmbox
->in_ext_byte_len
|| pmbox
->out_ext_byte_len
)
6879 *(((uint32_t *)mbx
) + pmbox
->mbox_offset_word
)
6880 = MAILBOX_HBA_EXT_OFFSET
;
6882 /* Copy the mailbox extension data */
6883 if (pmbox
->in_ext_byte_len
&& pmbox
->context2
) {
6884 lpfc_memcpy_to_slim(phba
->MBslimaddr
+
6885 MAILBOX_HBA_EXT_OFFSET
,
6886 pmbox
->context2
, pmbox
->in_ext_byte_len
);
6889 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
6890 /* copy command data into host mbox for cmpl */
6891 lpfc_sli_pcimem_bcopy(mbx
, phba
->mbox
, MAILBOX_CMD_SIZE
);
6894 /* First copy mbox command data to HBA SLIM, skip past first
6896 to_slim
= phba
->MBslimaddr
+ sizeof (uint32_t);
6897 lpfc_memcpy_to_slim(to_slim
, &mbx
->un
.varWords
[0],
6898 MAILBOX_CMD_SIZE
- sizeof (uint32_t));
6900 /* Next copy over first word, with mbxOwner set */
6901 ldata
= *((uint32_t *)mbx
);
6902 to_slim
= phba
->MBslimaddr
;
6903 writel(ldata
, to_slim
);
6904 readl(to_slim
); /* flush */
6906 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
6907 /* switch over to host mailbox */
6908 psli
->sli_flag
|= LPFC_SLI_ACTIVE
;
6916 /* Set up reference to mailbox command */
6917 psli
->mbox_active
= pmbox
;
6918 /* Interrupt board to do it */
6919 writel(CA_MBATT
, phba
->CAregaddr
);
6920 readl(phba
->CAregaddr
); /* flush */
6921 /* Don't wait for it to finish, just return */
6925 /* Set up null reference to mailbox command */
6926 psli
->mbox_active
= NULL
;
6927 /* Interrupt board to do it */
6928 writel(CA_MBATT
, phba
->CAregaddr
);
6929 readl(phba
->CAregaddr
); /* flush */
6931 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6932 /* First read mbox status word */
6933 word0
= *((uint32_t *)phba
->mbox
);
6934 word0
= le32_to_cpu(word0
);
6936 /* First read mbox status word */
6937 if (lpfc_readl(phba
->MBslimaddr
, &word0
)) {
6938 spin_unlock_irqrestore(&phba
->hbalock
,
6940 goto out_not_finished
;
6944 /* Read the HBA Host Attention Register */
6945 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
6946 spin_unlock_irqrestore(&phba
->hbalock
,
6948 goto out_not_finished
;
6950 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, pmbox
) *
6953 /* Wait for command to complete */
6954 while (((word0
& OWN_CHIP
) == OWN_CHIP
) ||
6955 (!(ha_copy
& HA_MBATT
) &&
6956 (phba
->link_state
> LPFC_WARM_START
))) {
6957 if (time_after(jiffies
, timeout
)) {
6958 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6959 spin_unlock_irqrestore(&phba
->hbalock
,
6961 goto out_not_finished
;
6964 /* Check if we took a mbox interrupt while we were
6966 if (((word0
& OWN_CHIP
) != OWN_CHIP
)
6967 && (evtctr
!= psli
->slistat
.mbox_event
))
6971 spin_unlock_irqrestore(&phba
->hbalock
,
6974 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
6977 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
6978 /* First copy command data */
6979 word0
= *((uint32_t *)phba
->mbox
);
6980 word0
= le32_to_cpu(word0
);
6981 if (mbx
->mbxCommand
== MBX_CONFIG_PORT
) {
6984 /* Check real SLIM for any errors */
6985 slimword0
= readl(phba
->MBslimaddr
);
6986 slimmb
= (MAILBOX_t
*) & slimword0
;
6987 if (((slimword0
& OWN_CHIP
) != OWN_CHIP
)
6988 && slimmb
->mbxStatus
) {
6995 /* First copy command data */
6996 word0
= readl(phba
->MBslimaddr
);
6998 /* Read the HBA Host Attention Register */
6999 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
)) {
7000 spin_unlock_irqrestore(&phba
->hbalock
,
7002 goto out_not_finished
;
7006 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
7007 /* copy results back to user */
7008 lpfc_sli_pcimem_bcopy(phba
->mbox
, mbx
, MAILBOX_CMD_SIZE
);
7009 /* Copy the mailbox extension data */
7010 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7011 lpfc_sli_pcimem_bcopy(phba
->mbox_ext
,
7013 pmbox
->out_ext_byte_len
);
7016 /* First copy command data */
7017 lpfc_memcpy_from_slim(mbx
, phba
->MBslimaddr
,
7019 /* Copy the mailbox extension data */
7020 if (pmbox
->out_ext_byte_len
&& pmbox
->context2
) {
7021 lpfc_memcpy_from_slim(pmbox
->context2
,
7023 MAILBOX_HBA_EXT_OFFSET
,
7024 pmbox
->out_ext_byte_len
);
7028 writel(HA_MBATT
, phba
->HAregaddr
);
7029 readl(phba
->HAregaddr
); /* flush */
7031 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7032 status
= mbx
->mbxStatus
;
7035 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
7039 if (processing_queue
) {
7040 pmbox
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7041 lpfc_mbox_cmpl_put(phba
, pmbox
);
7043 return MBX_NOT_FINISHED
;
7047 * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
7048 * @phba: Pointer to HBA context object.
7050 * The function blocks the posting of SLI4 asynchronous mailbox commands from
7051 * the driver internal pending mailbox queue. It will then try to wait out the
7052 * possible outstanding mailbox command before return.
7055 * 0 - the outstanding mailbox command completed; otherwise, the wait for
7056 * the outstanding mailbox command timed out.
7059 lpfc_sli4_async_mbox_block(struct lpfc_hba
*phba
)
7061 struct lpfc_sli
*psli
= &phba
->sli
;
7063 unsigned long timeout
= 0;
7065 /* Mark the asynchronous mailbox command posting as blocked */
7066 spin_lock_irq(&phba
->hbalock
);
7067 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
7068 /* Determine how long we might wait for the active mailbox
7069 * command to be gracefully completed by firmware.
7071 if (phba
->sli
.mbox_active
)
7072 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
7073 phba
->sli
.mbox_active
) *
7075 spin_unlock_irq(&phba
->hbalock
);
7077 /* Wait for the outstnading mailbox command to complete */
7078 while (phba
->sli
.mbox_active
) {
7079 /* Check active mailbox complete status every 2ms */
7081 if (time_after(jiffies
, timeout
)) {
7082 /* Timeout, marked the outstanding cmd not complete */
7088 /* Can not cleanly block async mailbox command, fails it */
7090 spin_lock_irq(&phba
->hbalock
);
7091 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7092 spin_unlock_irq(&phba
->hbalock
);
7098 * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
7099 * @phba: Pointer to HBA context object.
7101 * The function unblocks and resume posting of SLI4 asynchronous mailbox
7102 * commands from the driver internal pending mailbox queue. It makes sure
7103 * that there is no outstanding mailbox command before resuming posting
7104 * asynchronous mailbox commands. If, for any reason, there is outstanding
7105 * mailbox command, it will try to wait it out before resuming asynchronous
7106 * mailbox command posting.
7109 lpfc_sli4_async_mbox_unblock(struct lpfc_hba
*phba
)
7111 struct lpfc_sli
*psli
= &phba
->sli
;
7113 spin_lock_irq(&phba
->hbalock
);
7114 if (!(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7115 /* Asynchronous mailbox posting is not blocked, do nothing */
7116 spin_unlock_irq(&phba
->hbalock
);
7120 /* Outstanding synchronous mailbox command is guaranteed to be done,
7121 * successful or timeout, after timing-out the outstanding mailbox
7122 * command shall always be removed, so just unblock posting async
7123 * mailbox command and resume
7125 psli
->sli_flag
&= ~LPFC_SLI_ASYNC_MBX_BLK
;
7126 spin_unlock_irq(&phba
->hbalock
);
7128 /* wake up worker thread to post asynchronlous mailbox command */
7129 lpfc_worker_wake_up(phba
);
7133 * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
7134 * @phba: Pointer to HBA context object.
7135 * @mboxq: Pointer to mailbox object.
7137 * The function waits for the bootstrap mailbox register ready bit from
7138 * port for twice the regular mailbox command timeout value.
7140 * 0 - no timeout on waiting for bootstrap mailbox register ready.
7141 * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
7144 lpfc_sli4_wait_bmbx_ready(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7147 unsigned long timeout
;
7148 struct lpfc_register bmbx_reg
;
7150 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, mboxq
)
7154 bmbx_reg
.word0
= readl(phba
->sli4_hba
.BMBXregaddr
);
7155 db_ready
= bf_get(lpfc_bmbx_rdy
, &bmbx_reg
);
7159 if (time_after(jiffies
, timeout
))
7160 return MBXERR_ERROR
;
7161 } while (!db_ready
);
7167 * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
7168 * @phba: Pointer to HBA context object.
7169 * @mboxq: Pointer to mailbox object.
7171 * The function posts a mailbox to the port. The mailbox is expected
7172 * to be comletely filled in and ready for the port to operate on it.
7173 * This routine executes a synchronous completion operation on the
7174 * mailbox by polling for its completion.
7176 * The caller must not be holding any locks when calling this routine.
7179 * MBX_SUCCESS - mailbox posted successfully
7180 * Any of the MBX error values.
7183 lpfc_sli4_post_sync_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
7185 int rc
= MBX_SUCCESS
;
7186 unsigned long iflag
;
7187 uint32_t mcqe_status
;
7189 struct lpfc_sli
*psli
= &phba
->sli
;
7190 struct lpfc_mqe
*mb
= &mboxq
->u
.mqe
;
7191 struct lpfc_bmbx_create
*mbox_rgn
;
7192 struct dma_address
*dma_address
;
7195 * Only one mailbox can be active to the bootstrap mailbox region
7196 * at a time and there is no queueing provided.
7198 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7199 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7200 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7201 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7202 "(%d):2532 Mailbox command x%x (x%x/x%x) "
7203 "cannot issue Data: x%x x%x\n",
7204 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7205 mboxq
->u
.mb
.mbxCommand
,
7206 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7207 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7208 psli
->sli_flag
, MBX_POLL
);
7209 return MBXERR_ERROR
;
7211 /* The server grabs the token and owns it until release */
7212 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7213 phba
->sli
.mbox_active
= mboxq
;
7214 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7216 /* wait for bootstrap mbox register for readyness */
7217 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7222 * Initialize the bootstrap memory region to avoid stale data areas
7223 * in the mailbox post. Then copy the caller's mailbox contents to
7224 * the bmbx mailbox region.
7226 mbx_cmnd
= bf_get(lpfc_mqe_command
, mb
);
7227 memset(phba
->sli4_hba
.bmbx
.avirt
, 0, sizeof(struct lpfc_bmbx_create
));
7228 lpfc_sli_pcimem_bcopy(mb
, phba
->sli4_hba
.bmbx
.avirt
,
7229 sizeof(struct lpfc_mqe
));
7231 /* Post the high mailbox dma address to the port and wait for ready. */
7232 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
7233 writel(dma_address
->addr_hi
, phba
->sli4_hba
.BMBXregaddr
);
7235 /* wait for bootstrap mbox register for hi-address write done */
7236 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7240 /* Post the low mailbox dma address to the port. */
7241 writel(dma_address
->addr_lo
, phba
->sli4_hba
.BMBXregaddr
);
7243 /* wait for bootstrap mbox register for low address write done */
7244 rc
= lpfc_sli4_wait_bmbx_ready(phba
, mboxq
);
7249 * Read the CQ to ensure the mailbox has completed.
7250 * If so, update the mailbox status so that the upper layers
7251 * can complete the request normally.
7253 lpfc_sli_pcimem_bcopy(phba
->sli4_hba
.bmbx
.avirt
, mb
,
7254 sizeof(struct lpfc_mqe
));
7255 mbox_rgn
= (struct lpfc_bmbx_create
*) phba
->sli4_hba
.bmbx
.avirt
;
7256 lpfc_sli_pcimem_bcopy(&mbox_rgn
->mcqe
, &mboxq
->mcqe
,
7257 sizeof(struct lpfc_mcqe
));
7258 mcqe_status
= bf_get(lpfc_mcqe_status
, &mbox_rgn
->mcqe
);
7260 * When the CQE status indicates a failure and the mailbox status
7261 * indicates success then copy the CQE status into the mailbox status
7262 * (and prefix it with x4000).
7264 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
7265 if (bf_get(lpfc_mqe_status
, mb
) == MBX_SUCCESS
)
7266 bf_set(lpfc_mqe_status
, mb
,
7267 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
7270 lpfc_sli4_swap_str(phba
, mboxq
);
7272 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7273 "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
7274 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
7275 " x%x x%x CQ: x%x x%x x%x x%x\n",
7276 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7277 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7278 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7279 bf_get(lpfc_mqe_status
, mb
),
7280 mb
->un
.mb_words
[0], mb
->un
.mb_words
[1],
7281 mb
->un
.mb_words
[2], mb
->un
.mb_words
[3],
7282 mb
->un
.mb_words
[4], mb
->un
.mb_words
[5],
7283 mb
->un
.mb_words
[6], mb
->un
.mb_words
[7],
7284 mb
->un
.mb_words
[8], mb
->un
.mb_words
[9],
7285 mb
->un
.mb_words
[10], mb
->un
.mb_words
[11],
7286 mb
->un
.mb_words
[12], mboxq
->mcqe
.word0
,
7287 mboxq
->mcqe
.mcqe_tag0
, mboxq
->mcqe
.mcqe_tag1
,
7288 mboxq
->mcqe
.trailer
);
7290 /* We are holding the token, no needed for lock when release */
7291 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7292 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7293 phba
->sli
.mbox_active
= NULL
;
7294 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7299 * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
7300 * @phba: Pointer to HBA context object.
7301 * @pmbox: Pointer to mailbox object.
7302 * @flag: Flag indicating how the mailbox need to be processed.
7304 * This function is called by discovery code and HBA management code to submit
7305 * a mailbox command to firmware with SLI-4 interface spec.
7307 * Return codes the caller owns the mailbox command after the return of the
7311 lpfc_sli_issue_mbox_s4(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
7314 struct lpfc_sli
*psli
= &phba
->sli
;
7315 unsigned long iflags
;
7318 /* dump from issue mailbox command if setup */
7319 lpfc_idiag_mbxacc_dump_issue_mbox(phba
, &mboxq
->u
.mb
);
7321 rc
= lpfc_mbox_dev_check(phba
);
7323 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7324 "(%d):2544 Mailbox command x%x (x%x/x%x) "
7325 "cannot issue Data: x%x x%x\n",
7326 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7327 mboxq
->u
.mb
.mbxCommand
,
7328 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7329 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7330 psli
->sli_flag
, flag
);
7331 goto out_not_finished
;
7334 /* Detect polling mode and jump to a handler */
7335 if (!phba
->sli4_hba
.intr_enable
) {
7336 if (flag
== MBX_POLL
)
7337 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7340 if (rc
!= MBX_SUCCESS
)
7341 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7342 "(%d):2541 Mailbox command x%x "
7343 "(x%x/x%x) failure: "
7344 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7346 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7347 mboxq
->u
.mb
.mbxCommand
,
7348 lpfc_sli_config_mbox_subsys_get(phba
,
7350 lpfc_sli_config_mbox_opcode_get(phba
,
7352 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7353 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7354 bf_get(lpfc_mcqe_ext_status
,
7356 psli
->sli_flag
, flag
);
7358 } else if (flag
== MBX_POLL
) {
7359 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_SLI
,
7360 "(%d):2542 Try to issue mailbox command "
7361 "x%x (x%x/x%x) synchronously ahead of async"
7362 "mailbox command queue: x%x x%x\n",
7363 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7364 mboxq
->u
.mb
.mbxCommand
,
7365 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7366 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7367 psli
->sli_flag
, flag
);
7368 /* Try to block the asynchronous mailbox posting */
7369 rc
= lpfc_sli4_async_mbox_block(phba
);
7371 /* Successfully blocked, now issue sync mbox cmd */
7372 rc
= lpfc_sli4_post_sync_mbox(phba
, mboxq
);
7373 if (rc
!= MBX_SUCCESS
)
7374 lpfc_printf_log(phba
, KERN_WARNING
,
7376 "(%d):2597 Sync Mailbox command "
7377 "x%x (x%x/x%x) failure: "
7378 "mqe_sta: x%x mcqe_sta: x%x/x%x "
7380 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7381 mboxq
->u
.mb
.mbxCommand
,
7382 lpfc_sli_config_mbox_subsys_get(phba
,
7384 lpfc_sli_config_mbox_opcode_get(phba
,
7386 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
),
7387 bf_get(lpfc_mcqe_status
, &mboxq
->mcqe
),
7388 bf_get(lpfc_mcqe_ext_status
,
7390 psli
->sli_flag
, flag
);
7391 /* Unblock the async mailbox posting afterward */
7392 lpfc_sli4_async_mbox_unblock(phba
);
7397 /* Now, interrupt mode asynchrous mailbox command */
7398 rc
= lpfc_mbox_cmd_check(phba
, mboxq
);
7400 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7401 "(%d):2543 Mailbox command x%x (x%x/x%x) "
7402 "cannot issue Data: x%x x%x\n",
7403 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7404 mboxq
->u
.mb
.mbxCommand
,
7405 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7406 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7407 psli
->sli_flag
, flag
);
7408 goto out_not_finished
;
7411 /* Put the mailbox command to the driver internal FIFO */
7412 psli
->slistat
.mbox_busy
++;
7413 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7414 lpfc_mbox_put(phba
, mboxq
);
7415 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7416 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7417 "(%d):0354 Mbox cmd issue - Enqueue Data: "
7418 "x%x (x%x/x%x) x%x x%x x%x\n",
7419 mboxq
->vport
? mboxq
->vport
->vpi
: 0xffffff,
7420 bf_get(lpfc_mqe_command
, &mboxq
->u
.mqe
),
7421 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7422 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7423 phba
->pport
->port_state
,
7424 psli
->sli_flag
, MBX_NOWAIT
);
7425 /* Wake up worker thread to transport mailbox command from head */
7426 lpfc_worker_wake_up(phba
);
7431 return MBX_NOT_FINISHED
;
7435 * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
7436 * @phba: Pointer to HBA context object.
7438 * This function is called by worker thread to send a mailbox command to
7439 * SLI4 HBA firmware.
7443 lpfc_sli4_post_async_mbox(struct lpfc_hba
*phba
)
7445 struct lpfc_sli
*psli
= &phba
->sli
;
7446 LPFC_MBOXQ_t
*mboxq
;
7447 int rc
= MBX_SUCCESS
;
7448 unsigned long iflags
;
7449 struct lpfc_mqe
*mqe
;
7452 /* Check interrupt mode before post async mailbox command */
7453 if (unlikely(!phba
->sli4_hba
.intr_enable
))
7454 return MBX_NOT_FINISHED
;
7456 /* Check for mailbox command service token */
7457 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7458 if (unlikely(psli
->sli_flag
& LPFC_SLI_ASYNC_MBX_BLK
)) {
7459 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7460 return MBX_NOT_FINISHED
;
7462 if (psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
7463 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7464 return MBX_NOT_FINISHED
;
7466 if (unlikely(phba
->sli
.mbox_active
)) {
7467 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7468 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7469 "0384 There is pending active mailbox cmd\n");
7470 return MBX_NOT_FINISHED
;
7472 /* Take the mailbox command service token */
7473 psli
->sli_flag
|= LPFC_SLI_MBOX_ACTIVE
;
7475 /* Get the next mailbox command from head of queue */
7476 mboxq
= lpfc_mbox_get(phba
);
7478 /* If no more mailbox command waiting for post, we're done */
7480 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7481 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7484 phba
->sli
.mbox_active
= mboxq
;
7485 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7487 /* Check device readiness for posting mailbox command */
7488 rc
= lpfc_mbox_dev_check(phba
);
7490 /* Driver clean routine will clean up pending mailbox */
7491 goto out_not_finished
;
7493 /* Prepare the mbox command to be posted */
7494 mqe
= &mboxq
->u
.mqe
;
7495 mbx_cmnd
= bf_get(lpfc_mqe_command
, mqe
);
7497 /* Start timer for the mbox_tmo and log some mailbox post messages */
7498 mod_timer(&psli
->mbox_tmo
, (jiffies
+
7499 (HZ
* lpfc_mbox_tmo_val(phba
, mboxq
))));
7501 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
| LOG_SLI
,
7502 "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
7504 mboxq
->vport
? mboxq
->vport
->vpi
: 0, mbx_cmnd
,
7505 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7506 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7507 phba
->pport
->port_state
, psli
->sli_flag
);
7509 if (mbx_cmnd
!= MBX_HEARTBEAT
) {
7511 lpfc_debugfs_disc_trc(mboxq
->vport
,
7512 LPFC_DISC_TRC_MBOX_VPORT
,
7513 "MBOX Send vport: cmd:x%x mb:x%x x%x",
7514 mbx_cmnd
, mqe
->un
.mb_words
[0],
7515 mqe
->un
.mb_words
[1]);
7517 lpfc_debugfs_disc_trc(phba
->pport
,
7519 "MBOX Send: cmd:x%x mb:x%x x%x",
7520 mbx_cmnd
, mqe
->un
.mb_words
[0],
7521 mqe
->un
.mb_words
[1]);
7524 psli
->slistat
.mbox_cmd
++;
7526 /* Post the mailbox command to the port */
7527 rc
= lpfc_sli4_mq_put(phba
->sli4_hba
.mbx_wq
, mqe
);
7528 if (rc
!= MBX_SUCCESS
) {
7529 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
7530 "(%d):2533 Mailbox command x%x (x%x/x%x) "
7531 "cannot issue Data: x%x x%x\n",
7532 mboxq
->vport
? mboxq
->vport
->vpi
: 0,
7533 mboxq
->u
.mb
.mbxCommand
,
7534 lpfc_sli_config_mbox_subsys_get(phba
, mboxq
),
7535 lpfc_sli_config_mbox_opcode_get(phba
, mboxq
),
7536 psli
->sli_flag
, MBX_NOWAIT
);
7537 goto out_not_finished
;
7543 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7544 if (phba
->sli
.mbox_active
) {
7545 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
7546 __lpfc_mbox_cmpl_put(phba
, mboxq
);
7547 /* Release the token */
7548 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
7549 phba
->sli
.mbox_active
= NULL
;
7551 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7553 return MBX_NOT_FINISHED
;
7557 * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
7558 * @phba: Pointer to HBA context object.
7559 * @pmbox: Pointer to mailbox object.
7560 * @flag: Flag indicating how the mailbox need to be processed.
7562 * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
7563 * the API jump table function pointer from the lpfc_hba struct.
7565 * Return codes the caller owns the mailbox command after the return of the
7569 lpfc_sli_issue_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmbox
, uint32_t flag
)
7571 return phba
->lpfc_sli_issue_mbox(phba
, pmbox
, flag
);
7575 * lpfc_mbox_api_table_setup - Set up mbox api function jump table
7576 * @phba: The hba struct for which this call is being executed.
7577 * @dev_grp: The HBA PCI-Device group number.
7579 * This routine sets up the mbox interface API function jump table in @phba
7581 * Returns: 0 - success, -ENODEV - failure.
7584 lpfc_mbox_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
7588 case LPFC_PCI_DEV_LP
:
7589 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s3
;
7590 phba
->lpfc_sli_handle_slow_ring_event
=
7591 lpfc_sli_handle_slow_ring_event_s3
;
7592 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s3
;
7593 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s3
;
7594 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s3
;
7596 case LPFC_PCI_DEV_OC
:
7597 phba
->lpfc_sli_issue_mbox
= lpfc_sli_issue_mbox_s4
;
7598 phba
->lpfc_sli_handle_slow_ring_event
=
7599 lpfc_sli_handle_slow_ring_event_s4
;
7600 phba
->lpfc_sli_hbq_to_firmware
= lpfc_sli_hbq_to_firmware_s4
;
7601 phba
->lpfc_sli_brdrestart
= lpfc_sli_brdrestart_s4
;
7602 phba
->lpfc_sli_brdready
= lpfc_sli_brdready_s4
;
7605 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7606 "1420 Invalid HBA PCI-device group: 0x%x\n",
7615 * __lpfc_sli_ringtx_put - Add an iocb to the txq
7616 * @phba: Pointer to HBA context object.
7617 * @pring: Pointer to driver SLI ring object.
7618 * @piocb: Pointer to address of newly added command iocb.
7620 * This function is called with hbalock held to add a command
7621 * iocb to the txq when SLI layer cannot submit the command iocb
7625 __lpfc_sli_ringtx_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7626 struct lpfc_iocbq
*piocb
)
7628 /* Insert the caller's iocb in the txq tail for later processing. */
7629 list_add_tail(&piocb
->list
, &pring
->txq
);
7633 * lpfc_sli_next_iocb - Get the next iocb in the txq
7634 * @phba: Pointer to HBA context object.
7635 * @pring: Pointer to driver SLI ring object.
7636 * @piocb: Pointer to address of newly added command iocb.
7638 * This function is called with hbalock held before a new
7639 * iocb is submitted to the firmware. This function checks
7640 * txq to flush the iocbs in txq to Firmware before
7641 * submitting new iocbs to the Firmware.
7642 * If there are iocbs in the txq which need to be submitted
7643 * to firmware, lpfc_sli_next_iocb returns the first element
7644 * of the txq after dequeuing it from txq.
7645 * If there is no iocb in the txq then the function will return
7646 * *piocb and *piocb is set to NULL. Caller needs to check
7647 * *piocb to find if there are more commands in the txq.
7649 static struct lpfc_iocbq
*
7650 lpfc_sli_next_iocb(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7651 struct lpfc_iocbq
**piocb
)
7653 struct lpfc_iocbq
* nextiocb
;
7655 nextiocb
= lpfc_sli_ringtx_get(phba
, pring
);
7665 * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
7666 * @phba: Pointer to HBA context object.
7667 * @ring_number: SLI ring number to issue iocb on.
7668 * @piocb: Pointer to command iocb.
7669 * @flag: Flag indicating if this command can be put into txq.
7671 * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
7672 * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
7673 * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
7674 * flag is turned on, the function returns IOCB_ERROR. When the link is down,
7675 * this function allows only iocbs for posting buffers. This function finds
7676 * next available slot in the command ring and posts the command to the
7677 * available slot and writes the port attention register to request HBA start
7678 * processing new iocb. If there is no slot available in the ring and
7679 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
7680 * the function returns IOCB_BUSY.
7682 * This function is called with hbalock held. The function will return success
7683 * after it successfully submit the iocb to firmware or after adding to the
7687 __lpfc_sli_issue_iocb_s3(struct lpfc_hba
*phba
, uint32_t ring_number
,
7688 struct lpfc_iocbq
*piocb
, uint32_t flag
)
7690 struct lpfc_iocbq
*nextiocb
;
7692 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
7694 if (piocb
->iocb_cmpl
&& (!piocb
->vport
) &&
7695 (piocb
->iocb
.ulpCommand
!= CMD_ABORT_XRI_CN
) &&
7696 (piocb
->iocb
.ulpCommand
!= CMD_CLOSE_XRI_CN
)) {
7697 lpfc_printf_log(phba
, KERN_ERR
,
7698 LOG_SLI
| LOG_VPORT
,
7699 "1807 IOCB x%x failed. No vport\n",
7700 piocb
->iocb
.ulpCommand
);
7706 /* If the PCI channel is in offline state, do not post iocbs. */
7707 if (unlikely(pci_channel_offline(phba
->pcidev
)))
7710 /* If HBA has a deferred error attention, fail the iocb. */
7711 if (unlikely(phba
->hba_flag
& DEFER_ERATT
))
7715 * We should never get an IOCB if we are in a < LINK_DOWN state
7717 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
7721 * Check to see if we are blocking IOCB processing because of a
7722 * outstanding event.
7724 if (unlikely(pring
->flag
& LPFC_STOP_IOCB_EVENT
))
7727 if (unlikely(phba
->link_state
== LPFC_LINK_DOWN
)) {
7729 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
7730 * can be issued if the link is not up.
7732 switch (piocb
->iocb
.ulpCommand
) {
7733 case CMD_GEN_REQUEST64_CR
:
7734 case CMD_GEN_REQUEST64_CX
:
7735 if (!(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
) ||
7736 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Rctl
!=
7737 FC_RCTL_DD_UNSOL_CMD
) ||
7738 (piocb
->iocb
.un
.genreq64
.w5
.hcsw
.Type
!=
7739 MENLO_TRANSPORT_TYPE
))
7743 case CMD_QUE_RING_BUF_CN
:
7744 case CMD_QUE_RING_BUF64_CN
:
7746 * For IOCBs, like QUE_RING_BUF, that have no rsp ring
7747 * completion, iocb_cmpl MUST be 0.
7749 if (piocb
->iocb_cmpl
)
7750 piocb
->iocb_cmpl
= NULL
;
7752 case CMD_CREATE_XRI_CR
:
7753 case CMD_CLOSE_XRI_CN
:
7754 case CMD_CLOSE_XRI_CX
:
7761 * For FCP commands, we must be in a state where we can process link
7764 } else if (unlikely(pring
->ringno
== phba
->sli
.fcp_ring
&&
7765 !(phba
->sli
.sli_flag
& LPFC_PROCESS_LA
))) {
7769 while ((iocb
= lpfc_sli_next_iocb_slot(phba
, pring
)) &&
7770 (nextiocb
= lpfc_sli_next_iocb(phba
, pring
, &piocb
)))
7771 lpfc_sli_submit_iocb(phba
, pring
, iocb
, nextiocb
);
7774 lpfc_sli_update_ring(phba
, pring
);
7776 lpfc_sli_update_full_ring(phba
, pring
);
7779 return IOCB_SUCCESS
;
7784 pring
->stats
.iocb_cmd_delay
++;
7788 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
7789 __lpfc_sli_ringtx_put(phba
, pring
, piocb
);
7790 return IOCB_SUCCESS
;
7797 * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl.
7798 * @phba: Pointer to HBA context object.
7799 * @piocb: Pointer to command iocb.
7800 * @sglq: Pointer to the scatter gather queue object.
7802 * This routine converts the bpl or bde that is in the IOCB
7803 * to a sgl list for the sli4 hardware. The physical address
7804 * of the bpl/bde is converted back to a virtual address.
7805 * If the IOCB contains a BPL then the list of BDE's is
7806 * converted to sli4_sge's. If the IOCB contains a single
7807 * BDE then it is converted to a single sli_sge.
7808 * The IOCB is still in cpu endianess so the contents of
7809 * the bpl can be used without byte swapping.
7811 * Returns valid XRI = Success, NO_XRI = Failure.
7814 lpfc_sli4_bpl2sgl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*piocbq
,
7815 struct lpfc_sglq
*sglq
)
7817 uint16_t xritag
= NO_XRI
;
7818 struct ulp_bde64
*bpl
= NULL
;
7819 struct ulp_bde64 bde
;
7820 struct sli4_sge
*sgl
= NULL
;
7821 struct lpfc_dmabuf
*dmabuf
;
7825 uint32_t offset
= 0; /* accumulated offset in the sg request list */
7826 int inbound
= 0; /* number of sg reply entries inbound from firmware */
7828 if (!piocbq
|| !sglq
)
7831 sgl
= (struct sli4_sge
*)sglq
->sgl
;
7832 icmd
= &piocbq
->iocb
;
7833 if (icmd
->ulpCommand
== CMD_XMIT_BLS_RSP64_CX
)
7834 return sglq
->sli4_xritag
;
7835 if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7836 numBdes
= icmd
->un
.genreq64
.bdl
.bdeSize
/
7837 sizeof(struct ulp_bde64
);
7838 /* The addrHigh and addrLow fields within the IOCB
7839 * have not been byteswapped yet so there is no
7840 * need to swap them back.
7842 if (piocbq
->context3
)
7843 dmabuf
= (struct lpfc_dmabuf
*)piocbq
->context3
;
7847 bpl
= (struct ulp_bde64
*)dmabuf
->virt
;
7851 for (i
= 0; i
< numBdes
; i
++) {
7852 /* Should already be byte swapped. */
7853 sgl
->addr_hi
= bpl
->addrHigh
;
7854 sgl
->addr_lo
= bpl
->addrLow
;
7856 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7857 if ((i
+1) == numBdes
)
7858 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7860 bf_set(lpfc_sli4_sge_last
, sgl
, 0);
7861 /* swap the size field back to the cpu so we
7862 * can assign it to the sgl.
7864 bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7865 sgl
->sge_len
= cpu_to_le32(bde
.tus
.f
.bdeSize
);
7866 /* The offsets in the sgl need to be accumulated
7867 * separately for the request and reply lists.
7868 * The request is always first, the reply follows.
7870 if (piocbq
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
) {
7871 /* add up the reply sg entries */
7872 if (bpl
->tus
.f
.bdeFlags
== BUFF_TYPE_BDE_64I
)
7874 /* first inbound? reset the offset */
7877 bf_set(lpfc_sli4_sge_offset
, sgl
, offset
);
7878 bf_set(lpfc_sli4_sge_type
, sgl
,
7879 LPFC_SGE_TYPE_DATA
);
7880 offset
+= bde
.tus
.f
.bdeSize
;
7882 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7886 } else if (icmd
->un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BDE_64
) {
7887 /* The addrHigh and addrLow fields of the BDE have not
7888 * been byteswapped yet so they need to be swapped
7889 * before putting them in the sgl.
7892 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrHigh
);
7894 cpu_to_le32(icmd
->un
.genreq64
.bdl
.addrLow
);
7895 sgl
->word2
= le32_to_cpu(sgl
->word2
);
7896 bf_set(lpfc_sli4_sge_last
, sgl
, 1);
7897 sgl
->word2
= cpu_to_le32(sgl
->word2
);
7899 cpu_to_le32(icmd
->un
.genreq64
.bdl
.bdeSize
);
7901 return sglq
->sli4_xritag
;
7905 * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution
7906 * @phba: Pointer to HBA context object.
7908 * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index
7909 * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock
7912 * Return: index into SLI4 fast-path FCP queue index.
7914 static inline uint32_t
7915 lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba
*phba
)
7919 if (phba
->cfg_fcp_io_sched
== LPFC_FCP_SCHED_BY_CPU
)
7920 i
= smp_processor_id();
7922 i
= atomic_add_return(1, &phba
->fcp_qidx
);
7924 i
= (i
% phba
->cfg_fcp_io_channel
);
7929 * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry.
7930 * @phba: Pointer to HBA context object.
7931 * @piocb: Pointer to command iocb.
7932 * @wqe: Pointer to the work queue entry.
7934 * This routine converts the iocb command to its Work Queue Entry
7935 * equivalent. The wqe pointer should not have any fields set when
7936 * this routine is called because it will memcpy over them.
7937 * This routine does not set the CQ_ID or the WQEC bits in the
7940 * Returns: 0 = Success, IOCB_ERROR = Failure.
7943 lpfc_sli4_iocb2wqe(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocbq
,
7944 union lpfc_wqe
*wqe
)
7946 uint32_t xmit_len
= 0, total_len
= 0;
7950 uint8_t command_type
= ELS_COMMAND_NON_FIP
;
7953 uint16_t abrt_iotag
;
7954 struct lpfc_iocbq
*abrtiocbq
;
7955 struct ulp_bde64
*bpl
= NULL
;
7956 uint32_t els_id
= LPFC_ELS_ID_DEFAULT
;
7958 struct ulp_bde64 bde
;
7959 struct lpfc_nodelist
*ndlp
;
7963 fip
= phba
->hba_flag
& HBA_FIP_SUPPORT
;
7964 /* The fcp commands will set command type */
7965 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
7966 command_type
= FCP_COMMAND
;
7967 else if (fip
&& (iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
))
7968 command_type
= ELS_COMMAND_FIP
;
7970 command_type
= ELS_COMMAND_NON_FIP
;
7972 /* Some of the fields are in the right position already */
7973 memcpy(wqe
, &iocbq
->iocb
, sizeof(union lpfc_wqe
));
7974 abort_tag
= (uint32_t) iocbq
->iotag
;
7975 xritag
= iocbq
->sli4_xritag
;
7976 wqe
->generic
.wqe_com
.word7
= 0; /* The ct field has moved so reset */
7977 /* words0-2 bpl convert bde */
7978 if (iocbq
->iocb
.un
.genreq64
.bdl
.bdeFlags
== BUFF_TYPE_BLP_64
) {
7979 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
7980 sizeof(struct ulp_bde64
);
7981 bpl
= (struct ulp_bde64
*)
7982 ((struct lpfc_dmabuf
*)iocbq
->context3
)->virt
;
7986 /* Should already be byte swapped. */
7987 wqe
->generic
.bde
.addrHigh
= le32_to_cpu(bpl
->addrHigh
);
7988 wqe
->generic
.bde
.addrLow
= le32_to_cpu(bpl
->addrLow
);
7989 /* swap the size field back to the cpu so we
7990 * can assign it to the sgl.
7992 wqe
->generic
.bde
.tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7993 xmit_len
= wqe
->generic
.bde
.tus
.f
.bdeSize
;
7995 for (i
= 0; i
< numBdes
; i
++) {
7996 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
7997 total_len
+= bde
.tus
.f
.bdeSize
;
8000 xmit_len
= iocbq
->iocb
.un
.fcpi64
.bdl
.bdeSize
;
8002 iocbq
->iocb
.ulpIoTag
= iocbq
->iotag
;
8003 cmnd
= iocbq
->iocb
.ulpCommand
;
8005 switch (iocbq
->iocb
.ulpCommand
) {
8006 case CMD_ELS_REQUEST64_CR
:
8007 if (iocbq
->iocb_flag
& LPFC_IO_LIBDFC
)
8008 ndlp
= iocbq
->context_un
.ndlp
;
8010 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8011 if (!iocbq
->iocb
.ulpLe
) {
8012 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8013 "2007 Only Limited Edition cmd Format"
8014 " supported 0x%x\n",
8015 iocbq
->iocb
.ulpCommand
);
8019 wqe
->els_req
.payload_len
= xmit_len
;
8020 /* Els_reguest64 has a TMO */
8021 bf_set(wqe_tmo
, &wqe
->els_req
.wqe_com
,
8022 iocbq
->iocb
.ulpTimeout
);
8023 /* Need a VF for word 4 set the vf bit*/
8024 bf_set(els_req64_vf
, &wqe
->els_req
, 0);
8025 /* And a VFID for word 12 */
8026 bf_set(els_req64_vfid
, &wqe
->els_req
, 0);
8027 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8028 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8029 iocbq
->iocb
.ulpContext
);
8030 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
8031 bf_set(wqe_pu
, &wqe
->els_req
.wqe_com
, 0);
8032 /* CCP CCPE PV PRI in word10 were set in the memcpy */
8033 if (command_type
== ELS_COMMAND_FIP
)
8034 els_id
= ((iocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
)
8035 >> LPFC_FIP_ELS_ID_SHIFT
);
8036 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8037 iocbq
->context2
)->virt
);
8038 if_type
= bf_get(lpfc_sli_intf_if_type
,
8039 &phba
->sli4_hba
.sli_intf
);
8040 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8041 if (pcmd
&& (*pcmd
== ELS_CMD_FLOGI
||
8042 *pcmd
== ELS_CMD_SCR
||
8043 *pcmd
== ELS_CMD_FDISC
||
8044 *pcmd
== ELS_CMD_LOGO
||
8045 *pcmd
== ELS_CMD_PLOGI
)) {
8046 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
8047 bf_set(els_req64_sid
, &wqe
->els_req
,
8048 iocbq
->vport
->fc_myDID
);
8049 if ((*pcmd
== ELS_CMD_FLOGI
) &&
8050 !(phba
->fc_topology
==
8051 LPFC_TOPOLOGY_LOOP
))
8052 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
8053 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 1);
8054 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8055 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8056 } else if (pcmd
&& iocbq
->context1
) {
8057 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, 0);
8058 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
8059 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8062 bf_set(wqe_temp_rpi
, &wqe
->els_req
.wqe_com
,
8063 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8064 bf_set(wqe_els_id
, &wqe
->els_req
.wqe_com
, els_id
);
8065 bf_set(wqe_dbde
, &wqe
->els_req
.wqe_com
, 1);
8066 bf_set(wqe_iod
, &wqe
->els_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8067 bf_set(wqe_qosd
, &wqe
->els_req
.wqe_com
, 1);
8068 bf_set(wqe_lenloc
, &wqe
->els_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8069 bf_set(wqe_ebde_cnt
, &wqe
->els_req
.wqe_com
, 0);
8071 case CMD_XMIT_SEQUENCE64_CX
:
8072 bf_set(wqe_ctxt_tag
, &wqe
->xmit_sequence
.wqe_com
,
8073 iocbq
->iocb
.un
.ulpWord
[3]);
8074 bf_set(wqe_rcvoxid
, &wqe
->xmit_sequence
.wqe_com
,
8075 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8076 /* The entire sequence is transmitted for this IOCB */
8077 xmit_len
= total_len
;
8078 cmnd
= CMD_XMIT_SEQUENCE64_CR
;
8079 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
8080 bf_set(wqe_xo
, &wqe
->xmit_sequence
.wge_ctl
, 1);
8081 case CMD_XMIT_SEQUENCE64_CR
:
8082 /* word3 iocb=io_tag32 wqe=reserved */
8083 wqe
->xmit_sequence
.rsvd3
= 0;
8084 /* word4 relative_offset memcpy */
8085 /* word5 r_ctl/df_ctl memcpy */
8086 bf_set(wqe_pu
, &wqe
->xmit_sequence
.wqe_com
, 0);
8087 bf_set(wqe_dbde
, &wqe
->xmit_sequence
.wqe_com
, 1);
8088 bf_set(wqe_iod
, &wqe
->xmit_sequence
.wqe_com
,
8089 LPFC_WQE_IOD_WRITE
);
8090 bf_set(wqe_lenloc
, &wqe
->xmit_sequence
.wqe_com
,
8091 LPFC_WQE_LENLOC_WORD12
);
8092 bf_set(wqe_ebde_cnt
, &wqe
->xmit_sequence
.wqe_com
, 0);
8093 wqe
->xmit_sequence
.xmit_len
= xmit_len
;
8094 command_type
= OTHER_COMMAND
;
8096 case CMD_XMIT_BCAST64_CN
:
8097 /* word3 iocb=iotag32 wqe=seq_payload_len */
8098 wqe
->xmit_bcast64
.seq_payload_len
= xmit_len
;
8099 /* word4 iocb=rsvd wqe=rsvd */
8100 /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */
8101 /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */
8102 bf_set(wqe_ct
, &wqe
->xmit_bcast64
.wqe_com
,
8103 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8104 bf_set(wqe_dbde
, &wqe
->xmit_bcast64
.wqe_com
, 1);
8105 bf_set(wqe_iod
, &wqe
->xmit_bcast64
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8106 bf_set(wqe_lenloc
, &wqe
->xmit_bcast64
.wqe_com
,
8107 LPFC_WQE_LENLOC_WORD3
);
8108 bf_set(wqe_ebde_cnt
, &wqe
->xmit_bcast64
.wqe_com
, 0);
8110 case CMD_FCP_IWRITE64_CR
:
8111 command_type
= FCP_COMMAND_DATA_OUT
;
8112 /* word3 iocb=iotag wqe=payload_offset_len */
8113 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8114 wqe
->fcp_iwrite
.payload_offset_len
=
8115 xmit_len
+ sizeof(struct fcp_rsp
);
8116 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8117 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8118 bf_set(wqe_erp
, &wqe
->fcp_iwrite
.wqe_com
,
8119 iocbq
->iocb
.ulpFCP2Rcvy
);
8120 bf_set(wqe_lnk
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpXS
);
8121 /* Always open the exchange */
8122 bf_set(wqe_xc
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8123 bf_set(wqe_iod
, &wqe
->fcp_iwrite
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8124 bf_set(wqe_lenloc
, &wqe
->fcp_iwrite
.wqe_com
,
8125 LPFC_WQE_LENLOC_WORD4
);
8126 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iwrite
.wqe_com
, 0);
8127 bf_set(wqe_pu
, &wqe
->fcp_iwrite
.wqe_com
, iocbq
->iocb
.ulpPU
);
8128 bf_set(wqe_dbde
, &wqe
->fcp_iwrite
.wqe_com
, 1);
8130 case CMD_FCP_IREAD64_CR
:
8131 /* word3 iocb=iotag wqe=payload_offset_len */
8132 /* Add the FCP_CMD and FCP_RSP sizes to get the offset */
8133 wqe
->fcp_iread
.payload_offset_len
=
8134 xmit_len
+ sizeof(struct fcp_rsp
);
8135 /* word4 iocb=parameter wqe=total_xfer_length memcpy */
8136 /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */
8137 bf_set(wqe_erp
, &wqe
->fcp_iread
.wqe_com
,
8138 iocbq
->iocb
.ulpFCP2Rcvy
);
8139 bf_set(wqe_lnk
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpXS
);
8140 /* Always open the exchange */
8141 bf_set(wqe_xc
, &wqe
->fcp_iread
.wqe_com
, 0);
8142 bf_set(wqe_iod
, &wqe
->fcp_iread
.wqe_com
, LPFC_WQE_IOD_READ
);
8143 bf_set(wqe_lenloc
, &wqe
->fcp_iread
.wqe_com
,
8144 LPFC_WQE_LENLOC_WORD4
);
8145 bf_set(wqe_ebde_cnt
, &wqe
->fcp_iread
.wqe_com
, 0);
8146 bf_set(wqe_pu
, &wqe
->fcp_iread
.wqe_com
, iocbq
->iocb
.ulpPU
);
8147 bf_set(wqe_dbde
, &wqe
->fcp_iread
.wqe_com
, 1);
8149 case CMD_FCP_ICMND64_CR
:
8150 /* word3 iocb=IO_TAG wqe=reserved */
8151 wqe
->fcp_icmd
.rsrvd3
= 0;
8152 bf_set(wqe_pu
, &wqe
->fcp_icmd
.wqe_com
, 0);
8153 /* Always open the exchange */
8154 bf_set(wqe_xc
, &wqe
->fcp_icmd
.wqe_com
, 0);
8155 bf_set(wqe_dbde
, &wqe
->fcp_icmd
.wqe_com
, 1);
8156 bf_set(wqe_iod
, &wqe
->fcp_icmd
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8157 bf_set(wqe_qosd
, &wqe
->fcp_icmd
.wqe_com
, 1);
8158 bf_set(wqe_lenloc
, &wqe
->fcp_icmd
.wqe_com
,
8159 LPFC_WQE_LENLOC_NONE
);
8160 bf_set(wqe_ebde_cnt
, &wqe
->fcp_icmd
.wqe_com
, 0);
8161 bf_set(wqe_erp
, &wqe
->fcp_icmd
.wqe_com
,
8162 iocbq
->iocb
.ulpFCP2Rcvy
);
8164 case CMD_GEN_REQUEST64_CR
:
8165 /* For this command calculate the xmit length of the
8169 numBdes
= iocbq
->iocb
.un
.genreq64
.bdl
.bdeSize
/
8170 sizeof(struct ulp_bde64
);
8171 for (i
= 0; i
< numBdes
; i
++) {
8172 bde
.tus
.w
= le32_to_cpu(bpl
[i
].tus
.w
);
8173 if (bde
.tus
.f
.bdeFlags
!= BUFF_TYPE_BDE_64
)
8175 xmit_len
+= bde
.tus
.f
.bdeSize
;
8177 /* word3 iocb=IO_TAG wqe=request_payload_len */
8178 wqe
->gen_req
.request_payload_len
= xmit_len
;
8179 /* word4 iocb=parameter wqe=relative_offset memcpy */
8180 /* word5 [rctl, type, df_ctl, la] copied in memcpy */
8181 /* word6 context tag copied in memcpy */
8182 if (iocbq
->iocb
.ulpCt_h
|| iocbq
->iocb
.ulpCt_l
) {
8183 ct
= ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
);
8184 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8185 "2015 Invalid CT %x command 0x%x\n",
8186 ct
, iocbq
->iocb
.ulpCommand
);
8189 bf_set(wqe_ct
, &wqe
->gen_req
.wqe_com
, 0);
8190 bf_set(wqe_tmo
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpTimeout
);
8191 bf_set(wqe_pu
, &wqe
->gen_req
.wqe_com
, iocbq
->iocb
.ulpPU
);
8192 bf_set(wqe_dbde
, &wqe
->gen_req
.wqe_com
, 1);
8193 bf_set(wqe_iod
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_IOD_READ
);
8194 bf_set(wqe_qosd
, &wqe
->gen_req
.wqe_com
, 1);
8195 bf_set(wqe_lenloc
, &wqe
->gen_req
.wqe_com
, LPFC_WQE_LENLOC_NONE
);
8196 bf_set(wqe_ebde_cnt
, &wqe
->gen_req
.wqe_com
, 0);
8197 command_type
= OTHER_COMMAND
;
8199 case CMD_XMIT_ELS_RSP64_CX
:
8200 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8201 /* words0-2 BDE memcpy */
8202 /* word3 iocb=iotag32 wqe=response_payload_len */
8203 wqe
->xmit_els_rsp
.response_payload_len
= xmit_len
;
8205 wqe
->xmit_els_rsp
.word4
= 0;
8206 /* word5 iocb=rsvd wge=did */
8207 bf_set(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
,
8208 iocbq
->iocb
.un
.xseq64
.xmit_els_remoteID
);
8210 if_type
= bf_get(lpfc_sli_intf_if_type
,
8211 &phba
->sli4_hba
.sli_intf
);
8212 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
8213 if (iocbq
->vport
->fc_flag
& FC_PT2PT
) {
8214 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8215 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8216 iocbq
->vport
->fc_myDID
);
8217 if (iocbq
->vport
->fc_myDID
== Fabric_DID
) {
8219 &wqe
->xmit_els_rsp
.wqe_dest
, 0);
8223 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
,
8224 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8225 bf_set(wqe_pu
, &wqe
->xmit_els_rsp
.wqe_com
, iocbq
->iocb
.ulpPU
);
8226 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8227 iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
);
8228 if (!iocbq
->iocb
.ulpCt_h
&& iocbq
->iocb
.ulpCt_l
)
8229 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8230 phba
->vpi_ids
[iocbq
->vport
->vpi
]);
8231 bf_set(wqe_dbde
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8232 bf_set(wqe_iod
, &wqe
->xmit_els_rsp
.wqe_com
, LPFC_WQE_IOD_WRITE
);
8233 bf_set(wqe_qosd
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8234 bf_set(wqe_lenloc
, &wqe
->xmit_els_rsp
.wqe_com
,
8235 LPFC_WQE_LENLOC_WORD3
);
8236 bf_set(wqe_ebde_cnt
, &wqe
->xmit_els_rsp
.wqe_com
, 0);
8237 bf_set(wqe_rsp_temp_rpi
, &wqe
->xmit_els_rsp
,
8238 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
8239 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
8240 iocbq
->context2
)->virt
);
8241 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8242 bf_set(els_rsp64_sp
, &wqe
->xmit_els_rsp
, 1);
8243 bf_set(els_rsp64_sid
, &wqe
->xmit_els_rsp
,
8244 iocbq
->vport
->fc_myDID
);
8245 bf_set(wqe_ct
, &wqe
->xmit_els_rsp
.wqe_com
, 1);
8246 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
8247 phba
->vpi_ids
[phba
->pport
->vpi
]);
8249 command_type
= OTHER_COMMAND
;
8251 case CMD_CLOSE_XRI_CN
:
8252 case CMD_ABORT_XRI_CN
:
8253 case CMD_ABORT_XRI_CX
:
8254 /* words 0-2 memcpy should be 0 rserved */
8255 /* port will send abts */
8256 abrt_iotag
= iocbq
->iocb
.un
.acxri
.abortContextTag
;
8257 if (abrt_iotag
!= 0 && abrt_iotag
<= phba
->sli
.last_iotag
) {
8258 abrtiocbq
= phba
->sli
.iocbq_lookup
[abrt_iotag
];
8259 fip
= abrtiocbq
->iocb_flag
& LPFC_FIP_ELS_ID_MASK
;
8263 if ((iocbq
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
) || fip
)
8265 * The link is down, or the command was ELS_FIP
8266 * so the fw does not need to send abts
8269 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 1);
8271 bf_set(abort_cmd_ia
, &wqe
->abort_cmd
, 0);
8272 bf_set(abort_cmd_criteria
, &wqe
->abort_cmd
, T_XRI_TAG
);
8273 /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */
8274 wqe
->abort_cmd
.rsrvd5
= 0;
8275 bf_set(wqe_ct
, &wqe
->abort_cmd
.wqe_com
,
8276 ((iocbq
->iocb
.ulpCt_h
<< 1) | iocbq
->iocb
.ulpCt_l
));
8277 abort_tag
= iocbq
->iocb
.un
.acxri
.abortIoTag
;
8279 * The abort handler will send us CMD_ABORT_XRI_CN or
8280 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
8282 bf_set(wqe_cmnd
, &wqe
->abort_cmd
.wqe_com
, CMD_ABORT_XRI_CX
);
8283 bf_set(wqe_qosd
, &wqe
->abort_cmd
.wqe_com
, 1);
8284 bf_set(wqe_lenloc
, &wqe
->abort_cmd
.wqe_com
,
8285 LPFC_WQE_LENLOC_NONE
);
8286 cmnd
= CMD_ABORT_XRI_CX
;
8287 command_type
= OTHER_COMMAND
;
8290 case CMD_XMIT_BLS_RSP64_CX
:
8291 ndlp
= (struct lpfc_nodelist
*)iocbq
->context1
;
8292 /* As BLS ABTS RSP WQE is very different from other WQEs,
8293 * we re-construct this WQE here based on information in
8294 * iocbq from scratch.
8296 memset(wqe
, 0, sizeof(union lpfc_wqe
));
8297 /* OX_ID is invariable to who sent ABTS to CT exchange */
8298 bf_set(xmit_bls_rsp64_oxid
, &wqe
->xmit_bls_rsp
,
8299 bf_get(lpfc_abts_oxid
, &iocbq
->iocb
.un
.bls_rsp
));
8300 if (bf_get(lpfc_abts_orig
, &iocbq
->iocb
.un
.bls_rsp
) ==
8301 LPFC_ABTS_UNSOL_INT
) {
8302 /* ABTS sent by initiator to CT exchange, the
8303 * RX_ID field will be filled with the newly
8304 * allocated responder XRI.
8306 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8307 iocbq
->sli4_xritag
);
8309 /* ABTS sent by responder to CT exchange, the
8310 * RX_ID field will be filled with the responder
8313 bf_set(xmit_bls_rsp64_rxid
, &wqe
->xmit_bls_rsp
,
8314 bf_get(lpfc_abts_rxid
, &iocbq
->iocb
.un
.bls_rsp
));
8316 bf_set(xmit_bls_rsp64_seqcnthi
, &wqe
->xmit_bls_rsp
, 0xffff);
8317 bf_set(wqe_xmit_bls_pt
, &wqe
->xmit_bls_rsp
.wqe_dest
, 0x1);
8320 bf_set(wqe_els_did
, &wqe
->xmit_bls_rsp
.wqe_dest
,
8322 bf_set(xmit_bls_rsp64_temprpi
, &wqe
->xmit_bls_rsp
,
8323 iocbq
->iocb
.ulpContext
);
8324 bf_set(wqe_ct
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8325 bf_set(wqe_ctxt_tag
, &wqe
->xmit_bls_rsp
.wqe_com
,
8326 phba
->vpi_ids
[phba
->pport
->vpi
]);
8327 bf_set(wqe_qosd
, &wqe
->xmit_bls_rsp
.wqe_com
, 1);
8328 bf_set(wqe_lenloc
, &wqe
->xmit_bls_rsp
.wqe_com
,
8329 LPFC_WQE_LENLOC_NONE
);
8330 /* Overwrite the pre-set comnd type with OTHER_COMMAND */
8331 command_type
= OTHER_COMMAND
;
8332 if (iocbq
->iocb
.un
.xseq64
.w5
.hcsw
.Rctl
== FC_RCTL_BA_RJT
) {
8333 bf_set(xmit_bls_rsp64_rjt_vspec
, &wqe
->xmit_bls_rsp
,
8334 bf_get(lpfc_vndr_code
, &iocbq
->iocb
.un
.bls_rsp
));
8335 bf_set(xmit_bls_rsp64_rjt_expc
, &wqe
->xmit_bls_rsp
,
8336 bf_get(lpfc_rsn_expln
, &iocbq
->iocb
.un
.bls_rsp
));
8337 bf_set(xmit_bls_rsp64_rjt_rsnc
, &wqe
->xmit_bls_rsp
,
8338 bf_get(lpfc_rsn_code
, &iocbq
->iocb
.un
.bls_rsp
));
8342 case CMD_XRI_ABORTED_CX
:
8343 case CMD_CREATE_XRI_CR
: /* Do we expect to use this? */
8344 case CMD_IOCB_FCP_IBIDIR64_CR
: /* bidirectional xfer */
8345 case CMD_FCP_TSEND64_CX
: /* Target mode send xfer-ready */
8346 case CMD_FCP_TRSP64_CX
: /* Target mode rcv */
8347 case CMD_FCP_AUTO_TRSP_CX
: /* Auto target rsp */
8349 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8350 "2014 Invalid command 0x%x\n",
8351 iocbq
->iocb
.ulpCommand
);
8356 if (iocbq
->iocb_flag
& LPFC_IO_DIF_PASS
)
8357 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_PASSTHRU
);
8358 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_STRIP
)
8359 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_STRIP
);
8360 else if (iocbq
->iocb_flag
& LPFC_IO_DIF_INSERT
)
8361 bf_set(wqe_dif
, &wqe
->generic
.wqe_com
, LPFC_WQE_DIF_INSERT
);
8362 iocbq
->iocb_flag
&= ~(LPFC_IO_DIF_PASS
| LPFC_IO_DIF_STRIP
|
8363 LPFC_IO_DIF_INSERT
);
8364 bf_set(wqe_xri_tag
, &wqe
->generic
.wqe_com
, xritag
);
8365 bf_set(wqe_reqtag
, &wqe
->generic
.wqe_com
, iocbq
->iotag
);
8366 wqe
->generic
.wqe_com
.abort_tag
= abort_tag
;
8367 bf_set(wqe_cmd_type
, &wqe
->generic
.wqe_com
, command_type
);
8368 bf_set(wqe_cmnd
, &wqe
->generic
.wqe_com
, cmnd
);
8369 bf_set(wqe_class
, &wqe
->generic
.wqe_com
, iocbq
->iocb
.ulpClass
);
8370 bf_set(wqe_cqid
, &wqe
->generic
.wqe_com
, LPFC_WQE_CQ_ID_DEFAULT
);
8375 * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
8376 * @phba: Pointer to HBA context object.
8377 * @ring_number: SLI ring number to issue iocb on.
8378 * @piocb: Pointer to command iocb.
8379 * @flag: Flag indicating if this command can be put into txq.
8381 * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
8382 * an iocb command to an HBA with SLI-4 interface spec.
8384 * This function is called with hbalock held. The function will return success
8385 * after it successfully submit the iocb to firmware or after adding to the
8389 __lpfc_sli_issue_iocb_s4(struct lpfc_hba
*phba
, uint32_t ring_number
,
8390 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8392 struct lpfc_sglq
*sglq
;
8394 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[ring_number
];
8396 if (piocb
->sli4_xritag
== NO_XRI
) {
8397 if (piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
8398 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
8401 if (!list_empty(&pring
->txq
)) {
8402 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8403 __lpfc_sli_ringtx_put(phba
,
8405 return IOCB_SUCCESS
;
8410 sglq
= __lpfc_sli_get_sglq(phba
, piocb
);
8412 if (!(flag
& SLI_IOCB_RET_IOCB
)) {
8413 __lpfc_sli_ringtx_put(phba
,
8416 return IOCB_SUCCESS
;
8422 } else if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8423 /* These IO's already have an XRI and a mapped sgl. */
8427 * This is a continuation of a commandi,(CX) so this
8428 * sglq is on the active list
8430 sglq
= __lpfc_get_active_sglq(phba
, piocb
->sli4_lxritag
);
8436 piocb
->sli4_lxritag
= sglq
->sli4_lxritag
;
8437 piocb
->sli4_xritag
= sglq
->sli4_xritag
;
8438 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocb
, sglq
))
8442 if (lpfc_sli4_iocb2wqe(phba
, piocb
, &wqe
))
8445 if ((piocb
->iocb_flag
& LPFC_IO_FCP
) ||
8446 (piocb
->iocb_flag
& LPFC_USE_FCPWQIDX
)) {
8447 if (lpfc_sli4_wq_put(phba
->sli4_hba
.fcp_wq
[piocb
->fcp_wqidx
],
8451 if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
8454 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocb
);
8460 * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
8462 * This routine wraps the actual lockless version for issusing IOCB function
8463 * pointer from the lpfc_hba struct.
8466 * IOCB_ERROR - Error
8467 * IOCB_SUCCESS - Success
8471 __lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8472 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8474 return phba
->__lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8478 * lpfc_sli_api_table_setup - Set up sli api function jump table
8479 * @phba: The hba struct for which this call is being executed.
8480 * @dev_grp: The HBA PCI-Device group number.
8482 * This routine sets up the SLI interface API function jump table in @phba
8484 * Returns: 0 - success, -ENODEV - failure.
8487 lpfc_sli_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
8491 case LPFC_PCI_DEV_LP
:
8492 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s3
;
8493 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s3
;
8495 case LPFC_PCI_DEV_OC
:
8496 phba
->__lpfc_sli_issue_iocb
= __lpfc_sli_issue_iocb_s4
;
8497 phba
->__lpfc_sli_release_iocbq
= __lpfc_sli_release_iocbq_s4
;
8500 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8501 "1419 Invalid HBA PCI-device group: 0x%x\n",
8506 phba
->lpfc_get_iocb_from_iocbq
= lpfc_get_iocb_from_iocbq
;
8511 * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
8512 * @phba: Pointer to HBA context object.
8513 * @pring: Pointer to driver SLI ring object.
8514 * @piocb: Pointer to command iocb.
8515 * @flag: Flag indicating if this command can be put into txq.
8517 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
8518 * function. This function gets the hbalock and calls
8519 * __lpfc_sli_issue_iocb function and will return the error returned
8520 * by __lpfc_sli_issue_iocb function. This wrapper is used by
8521 * functions which do not hold hbalock.
8524 lpfc_sli_issue_iocb(struct lpfc_hba
*phba
, uint32_t ring_number
,
8525 struct lpfc_iocbq
*piocb
, uint32_t flag
)
8527 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
8528 struct lpfc_sli_ring
*pring
;
8529 struct lpfc_queue
*fpeq
;
8530 struct lpfc_eqe
*eqe
;
8531 unsigned long iflags
;
8534 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8535 if (piocb
->iocb_flag
& LPFC_IO_FCP
) {
8536 if (unlikely(!phba
->sli4_hba
.fcp_wq
))
8538 idx
= lpfc_sli4_scmd_to_wqidx_distr(phba
);
8539 piocb
->fcp_wqidx
= idx
;
8540 ring_number
= MAX_SLI3_CONFIGURED_RINGS
+ idx
;
8542 pring
= &phba
->sli
.ring
[ring_number
];
8543 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8544 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8546 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8548 if (lpfc_fcp_look_ahead
) {
8549 fcp_eq_hdl
= &phba
->sli4_hba
.fcp_eq_hdl
[idx
];
8551 if (atomic_dec_and_test(&fcp_eq_hdl
->
8554 /* Get associated EQ with this index */
8555 fpeq
= phba
->sli4_hba
.hba_eq
[idx
];
8557 /* Turn off interrupts from this EQ */
8558 lpfc_sli4_eq_clr_intr(fpeq
);
8561 * Process all the events on FCP EQ
8563 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
8564 lpfc_sli4_hba_handle_eqe(phba
,
8566 fpeq
->EQ_processed
++;
8569 /* Always clear and re-arm the EQ */
8570 lpfc_sli4_eq_release(fpeq
,
8573 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
8576 pring
= &phba
->sli
.ring
[ring_number
];
8577 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
8578 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
8580 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
8584 /* For now, SLI2/3 will still use hbalock */
8585 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8586 rc
= __lpfc_sli_issue_iocb(phba
, ring_number
, piocb
, flag
);
8587 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8593 * lpfc_extra_ring_setup - Extra ring setup function
8594 * @phba: Pointer to HBA context object.
8596 * This function is called while driver attaches with the
8597 * HBA to setup the extra ring. The extra ring is used
8598 * only when driver needs to support target mode functionality
8599 * or IP over FC functionalities.
8601 * This function is called with no lock held.
8604 lpfc_extra_ring_setup( struct lpfc_hba
*phba
)
8606 struct lpfc_sli
*psli
;
8607 struct lpfc_sli_ring
*pring
;
8611 /* Adjust cmd/rsp ring iocb entries more evenly */
8613 /* Take some away from the FCP ring */
8614 pring
= &psli
->ring
[psli
->fcp_ring
];
8615 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8616 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8617 pring
->sli
.sli3
.numCiocb
-= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8618 pring
->sli
.sli3
.numRiocb
-= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8620 /* and give them to the extra ring */
8621 pring
= &psli
->ring
[psli
->extra_ring
];
8623 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8624 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8625 pring
->sli
.sli3
.numCiocb
+= SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8626 pring
->sli
.sli3
.numRiocb
+= SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8628 /* Setup default profile for this ring */
8629 pring
->iotag_max
= 4096;
8630 pring
->num_mask
= 1;
8631 pring
->prt
[0].profile
= 0; /* Mask 0 */
8632 pring
->prt
[0].rctl
= phba
->cfg_multi_ring_rctl
;
8633 pring
->prt
[0].type
= phba
->cfg_multi_ring_type
;
8634 pring
->prt
[0].lpfc_sli_rcv_unsol_event
= NULL
;
8638 /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
8639 * @phba: Pointer to HBA context object.
8640 * @iocbq: Pointer to iocb object.
8642 * The async_event handler calls this routine when it receives
8643 * an ASYNC_STATUS_CN event from the port. The port generates
8644 * this event when an Abort Sequence request to an rport fails
8645 * twice in succession. The abort could be originated by the
8646 * driver or by the port. The ABTS could have been for an ELS
8647 * or FCP IO. The port only generates this event when an ABTS
8648 * fails to complete after one retry.
8651 lpfc_sli_abts_err_handler(struct lpfc_hba
*phba
,
8652 struct lpfc_iocbq
*iocbq
)
8654 struct lpfc_nodelist
*ndlp
= NULL
;
8655 uint16_t rpi
= 0, vpi
= 0;
8656 struct lpfc_vport
*vport
= NULL
;
8658 /* The rpi in the ulpContext is vport-sensitive. */
8659 vpi
= iocbq
->iocb
.un
.asyncstat
.sub_ctxt_tag
;
8660 rpi
= iocbq
->iocb
.ulpContext
;
8662 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8663 "3092 Port generated ABTS async event "
8664 "on vpi %d rpi %d status 0x%x\n",
8665 vpi
, rpi
, iocbq
->iocb
.ulpStatus
);
8667 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
8670 ndlp
= lpfc_findnode_rpi(vport
, rpi
);
8671 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
8674 if (iocbq
->iocb
.ulpStatus
== IOSTAT_LOCAL_REJECT
)
8675 lpfc_sli_abts_recover_port(vport
, ndlp
);
8679 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8680 "3095 Event Context not found, no "
8681 "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
8682 iocbq
->iocb
.ulpContext
, iocbq
->iocb
.ulpStatus
,
8686 /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
8687 * @phba: pointer to HBA context object.
8688 * @ndlp: nodelist pointer for the impacted rport.
8689 * @axri: pointer to the wcqe containing the failed exchange.
8691 * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
8692 * port. The port generates this event when an abort exchange request to an
8693 * rport fails twice in succession with no reply. The abort could be originated
8694 * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
8697 lpfc_sli4_abts_err_handler(struct lpfc_hba
*phba
,
8698 struct lpfc_nodelist
*ndlp
,
8699 struct sli4_wcqe_xri_aborted
*axri
)
8701 struct lpfc_vport
*vport
;
8702 uint32_t ext_status
= 0;
8704 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
8705 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8706 "3115 Node Context not found, driver "
8707 "ignoring abts err event\n");
8711 vport
= ndlp
->vport
;
8712 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
8713 "3116 Port generated FCP XRI ABORT event on "
8714 "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
8715 ndlp
->vport
->vpi
, ndlp
->nlp_rpi
,
8716 bf_get(lpfc_wcqe_xa_xri
, axri
),
8717 bf_get(lpfc_wcqe_xa_status
, axri
),
8721 * Catch the ABTS protocol failure case. Older OCe FW releases returned
8722 * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
8723 * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
8725 ext_status
= axri
->parameter
& IOERR_PARAM_MASK
;
8726 if ((bf_get(lpfc_wcqe_xa_status
, axri
) == IOSTAT_LOCAL_REJECT
) &&
8727 ((ext_status
== IOERR_SEQUENCE_TIMEOUT
) || (ext_status
== 0)))
8728 lpfc_sli_abts_recover_port(vport
, ndlp
);
8732 * lpfc_sli_async_event_handler - ASYNC iocb handler function
8733 * @phba: Pointer to HBA context object.
8734 * @pring: Pointer to driver SLI ring object.
8735 * @iocbq: Pointer to iocb object.
8737 * This function is called by the slow ring event handler
8738 * function when there is an ASYNC event iocb in the ring.
8739 * This function is called with no lock held.
8740 * Currently this function handles only temperature related
8741 * ASYNC events. The function decodes the temperature sensor
8742 * event message and posts events for the management applications.
8745 lpfc_sli_async_event_handler(struct lpfc_hba
* phba
,
8746 struct lpfc_sli_ring
* pring
, struct lpfc_iocbq
* iocbq
)
8750 struct temp_event temp_event_data
;
8751 struct Scsi_Host
*shost
;
8754 icmd
= &iocbq
->iocb
;
8755 evt_code
= icmd
->un
.asyncstat
.evt_code
;
8758 case ASYNC_TEMP_WARN
:
8759 case ASYNC_TEMP_SAFE
:
8760 temp_event_data
.data
= (uint32_t) icmd
->ulpContext
;
8761 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
8762 if (evt_code
== ASYNC_TEMP_WARN
) {
8763 temp_event_data
.event_code
= LPFC_THRESHOLD_TEMP
;
8764 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8765 "0347 Adapter is very hot, please take "
8766 "corrective action. temperature : %d Celsius\n",
8767 (uint32_t) icmd
->ulpContext
);
8769 temp_event_data
.event_code
= LPFC_NORMAL_TEMP
;
8770 lpfc_printf_log(phba
, KERN_ERR
, LOG_TEMP
,
8771 "0340 Adapter temperature is OK now. "
8772 "temperature : %d Celsius\n",
8773 (uint32_t) icmd
->ulpContext
);
8776 /* Send temperature change event to applications */
8777 shost
= lpfc_shost_from_vport(phba
->pport
);
8778 fc_host_post_vendor_event(shost
, fc_get_event_number(),
8779 sizeof(temp_event_data
), (char *) &temp_event_data
,
8782 case ASYNC_STATUS_CN
:
8783 lpfc_sli_abts_err_handler(phba
, iocbq
);
8786 iocb_w
= (uint32_t *) icmd
;
8787 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
8788 "0346 Ring %d handler: unexpected ASYNC_STATUS"
8790 "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
8791 "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
8792 "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
8793 "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
8794 pring
->ringno
, icmd
->un
.asyncstat
.evt_code
,
8795 iocb_w
[0], iocb_w
[1], iocb_w
[2], iocb_w
[3],
8796 iocb_w
[4], iocb_w
[5], iocb_w
[6], iocb_w
[7],
8797 iocb_w
[8], iocb_w
[9], iocb_w
[10], iocb_w
[11],
8798 iocb_w
[12], iocb_w
[13], iocb_w
[14], iocb_w
[15]);
8806 * lpfc_sli_setup - SLI ring setup function
8807 * @phba: Pointer to HBA context object.
8809 * lpfc_sli_setup sets up rings of the SLI interface with
8810 * number of iocbs per ring and iotags. This function is
8811 * called while driver attach to the HBA and before the
8812 * interrupts are enabled. So there is no need for locking.
8814 * This function always returns 0.
8817 lpfc_sli_setup(struct lpfc_hba
*phba
)
8819 int i
, totiocbsize
= 0;
8820 struct lpfc_sli
*psli
= &phba
->sli
;
8821 struct lpfc_sli_ring
*pring
;
8823 psli
->num_rings
= MAX_SLI3_CONFIGURED_RINGS
;
8824 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8825 psli
->num_rings
+= phba
->cfg_fcp_io_channel
;
8827 psli
->fcp_ring
= LPFC_FCP_RING
;
8828 psli
->next_ring
= LPFC_FCP_NEXT_RING
;
8829 psli
->extra_ring
= LPFC_EXTRA_RING
;
8831 psli
->iocbq_lookup
= NULL
;
8832 psli
->iocbq_lookup_len
= 0;
8833 psli
->last_iotag
= 0;
8835 for (i
= 0; i
< psli
->num_rings
; i
++) {
8836 pring
= &psli
->ring
[i
];
8838 case LPFC_FCP_RING
: /* ring 0 - FCP */
8839 /* numCiocb and numRiocb are used in config_port */
8840 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R0_ENTRIES
;
8841 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R0_ENTRIES
;
8842 pring
->sli
.sli3
.numCiocb
+=
8843 SLI2_IOCB_CMD_R1XTRA_ENTRIES
;
8844 pring
->sli
.sli3
.numRiocb
+=
8845 SLI2_IOCB_RSP_R1XTRA_ENTRIES
;
8846 pring
->sli
.sli3
.numCiocb
+=
8847 SLI2_IOCB_CMD_R3XTRA_ENTRIES
;
8848 pring
->sli
.sli3
.numRiocb
+=
8849 SLI2_IOCB_RSP_R3XTRA_ENTRIES
;
8850 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8851 SLI3_IOCB_CMD_SIZE
:
8853 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8854 SLI3_IOCB_RSP_SIZE
:
8856 pring
->iotag_ctr
= 0;
8858 (phba
->cfg_hba_queue_depth
* 2);
8859 pring
->fast_iotag
= pring
->iotag_max
;
8860 pring
->num_mask
= 0;
8862 case LPFC_EXTRA_RING
: /* ring 1 - EXTRA */
8863 /* numCiocb and numRiocb are used in config_port */
8864 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R1_ENTRIES
;
8865 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R1_ENTRIES
;
8866 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8867 SLI3_IOCB_CMD_SIZE
:
8869 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8870 SLI3_IOCB_RSP_SIZE
:
8872 pring
->iotag_max
= phba
->cfg_hba_queue_depth
;
8873 pring
->num_mask
= 0;
8875 case LPFC_ELS_RING
: /* ring 2 - ELS / CT */
8876 /* numCiocb and numRiocb are used in config_port */
8877 pring
->sli
.sli3
.numCiocb
= SLI2_IOCB_CMD_R2_ENTRIES
;
8878 pring
->sli
.sli3
.numRiocb
= SLI2_IOCB_RSP_R2_ENTRIES
;
8879 pring
->sli
.sli3
.sizeCiocb
= (phba
->sli_rev
== 3) ?
8880 SLI3_IOCB_CMD_SIZE
:
8882 pring
->sli
.sli3
.sizeRiocb
= (phba
->sli_rev
== 3) ?
8883 SLI3_IOCB_RSP_SIZE
:
8885 pring
->fast_iotag
= 0;
8886 pring
->iotag_ctr
= 0;
8887 pring
->iotag_max
= 4096;
8888 pring
->lpfc_sli_rcv_async_status
=
8889 lpfc_sli_async_event_handler
;
8890 pring
->num_mask
= LPFC_MAX_RING_MASK
;
8891 pring
->prt
[0].profile
= 0; /* Mask 0 */
8892 pring
->prt
[0].rctl
= FC_RCTL_ELS_REQ
;
8893 pring
->prt
[0].type
= FC_TYPE_ELS
;
8894 pring
->prt
[0].lpfc_sli_rcv_unsol_event
=
8895 lpfc_els_unsol_event
;
8896 pring
->prt
[1].profile
= 0; /* Mask 1 */
8897 pring
->prt
[1].rctl
= FC_RCTL_ELS_REP
;
8898 pring
->prt
[1].type
= FC_TYPE_ELS
;
8899 pring
->prt
[1].lpfc_sli_rcv_unsol_event
=
8900 lpfc_els_unsol_event
;
8901 pring
->prt
[2].profile
= 0; /* Mask 2 */
8902 /* NameServer Inquiry */
8903 pring
->prt
[2].rctl
= FC_RCTL_DD_UNSOL_CTL
;
8905 pring
->prt
[2].type
= FC_TYPE_CT
;
8906 pring
->prt
[2].lpfc_sli_rcv_unsol_event
=
8907 lpfc_ct_unsol_event
;
8908 pring
->prt
[3].profile
= 0; /* Mask 3 */
8909 /* NameServer response */
8910 pring
->prt
[3].rctl
= FC_RCTL_DD_SOL_CTL
;
8912 pring
->prt
[3].type
= FC_TYPE_CT
;
8913 pring
->prt
[3].lpfc_sli_rcv_unsol_event
=
8914 lpfc_ct_unsol_event
;
8917 totiocbsize
+= (pring
->sli
.sli3
.numCiocb
*
8918 pring
->sli
.sli3
.sizeCiocb
) +
8919 (pring
->sli
.sli3
.numRiocb
* pring
->sli
.sli3
.sizeRiocb
);
8921 if (totiocbsize
> MAX_SLIM_IOCB_SIZE
) {
8922 /* Too many cmd / rsp ring entries in SLI2 SLIM */
8923 printk(KERN_ERR
"%d:0462 Too many cmd / rsp ring entries in "
8924 "SLI2 SLIM Data: x%x x%lx\n",
8925 phba
->brd_no
, totiocbsize
,
8926 (unsigned long) MAX_SLIM_IOCB_SIZE
);
8928 if (phba
->cfg_multi_ring_support
== 2)
8929 lpfc_extra_ring_setup(phba
);
8935 * lpfc_sli_queue_setup - Queue initialization function
8936 * @phba: Pointer to HBA context object.
8938 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
8939 * ring. This function also initializes ring indices of each ring.
8940 * This function is called during the initialization of the SLI
8941 * interface of an HBA.
8942 * This function is called with no lock held and always returns
8946 lpfc_sli_queue_setup(struct lpfc_hba
*phba
)
8948 struct lpfc_sli
*psli
;
8949 struct lpfc_sli_ring
*pring
;
8953 spin_lock_irq(&phba
->hbalock
);
8954 INIT_LIST_HEAD(&psli
->mboxq
);
8955 INIT_LIST_HEAD(&psli
->mboxq_cmpl
);
8956 /* Initialize list headers for txq and txcmplq as double linked lists */
8957 for (i
= 0; i
< psli
->num_rings
; i
++) {
8958 pring
= &psli
->ring
[i
];
8960 pring
->sli
.sli3
.next_cmdidx
= 0;
8961 pring
->sli
.sli3
.local_getidx
= 0;
8962 pring
->sli
.sli3
.cmdidx
= 0;
8963 INIT_LIST_HEAD(&pring
->txq
);
8964 INIT_LIST_HEAD(&pring
->txcmplq
);
8965 INIT_LIST_HEAD(&pring
->iocb_continueq
);
8966 INIT_LIST_HEAD(&pring
->iocb_continue_saveq
);
8967 INIT_LIST_HEAD(&pring
->postbufq
);
8968 spin_lock_init(&pring
->ring_lock
);
8970 spin_unlock_irq(&phba
->hbalock
);
8975 * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
8976 * @phba: Pointer to HBA context object.
8978 * This routine flushes the mailbox command subsystem. It will unconditionally
8979 * flush all the mailbox commands in the three possible stages in the mailbox
8980 * command sub-system: pending mailbox command queue; the outstanding mailbox
8981 * command; and completed mailbox command queue. It is caller's responsibility
8982 * to make sure that the driver is in the proper state to flush the mailbox
8983 * command sub-system. Namely, the posting of mailbox commands into the
8984 * pending mailbox command queue from the various clients must be stopped;
8985 * either the HBA is in a state that it will never works on the outstanding
8986 * mailbox command (such as in EEH or ERATT conditions) or the outstanding
8987 * mailbox command has been completed.
8990 lpfc_sli_mbox_sys_flush(struct lpfc_hba
*phba
)
8992 LIST_HEAD(completions
);
8993 struct lpfc_sli
*psli
= &phba
->sli
;
8995 unsigned long iflag
;
8997 /* Flush all the mailbox commands in the mbox system */
8998 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8999 /* The pending mailbox command queue */
9000 list_splice_init(&phba
->sli
.mboxq
, &completions
);
9001 /* The outstanding active mailbox command */
9002 if (psli
->mbox_active
) {
9003 list_add_tail(&psli
->mbox_active
->list
, &completions
);
9004 psli
->mbox_active
= NULL
;
9005 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9007 /* The completed mailbox command queue */
9008 list_splice_init(&phba
->sli
.mboxq_cmpl
, &completions
);
9009 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9011 /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
9012 while (!list_empty(&completions
)) {
9013 list_remove_head(&completions
, pmb
, LPFC_MBOXQ_t
, list
);
9014 pmb
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
9016 pmb
->mbox_cmpl(phba
, pmb
);
9021 * lpfc_sli_host_down - Vport cleanup function
9022 * @vport: Pointer to virtual port object.
9024 * lpfc_sli_host_down is called to clean up the resources
9025 * associated with a vport before destroying virtual
9026 * port data structures.
9027 * This function does following operations:
9028 * - Free discovery resources associated with this virtual
9030 * - Free iocbs associated with this virtual port in
9032 * - Send abort for all iocb commands associated with this
9035 * This function is called with no lock held and always returns 1.
9038 lpfc_sli_host_down(struct lpfc_vport
*vport
)
9040 LIST_HEAD(completions
);
9041 struct lpfc_hba
*phba
= vport
->phba
;
9042 struct lpfc_sli
*psli
= &phba
->sli
;
9043 struct lpfc_sli_ring
*pring
;
9044 struct lpfc_iocbq
*iocb
, *next_iocb
;
9046 unsigned long flags
= 0;
9047 uint16_t prev_pring_flag
;
9049 lpfc_cleanup_discovery_resources(vport
);
9051 spin_lock_irqsave(&phba
->hbalock
, flags
);
9052 for (i
= 0; i
< psli
->num_rings
; i
++) {
9053 pring
= &psli
->ring
[i
];
9054 prev_pring_flag
= pring
->flag
;
9055 /* Only slow rings */
9056 if (pring
->ringno
== LPFC_ELS_RING
) {
9057 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9058 /* Set the lpfc data pending flag */
9059 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9062 * Error everything on the txq since these iocbs have not been
9063 * given to the FW yet.
9065 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
9066 if (iocb
->vport
!= vport
)
9068 list_move_tail(&iocb
->list
, &completions
);
9071 /* Next issue ABTS for everything on the txcmplq */
9072 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
,
9074 if (iocb
->vport
!= vport
)
9076 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
9079 pring
->flag
= prev_pring_flag
;
9082 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9084 /* Cancel all the IOCBs from the completions list */
9085 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9091 * lpfc_sli_hba_down - Resource cleanup function for the HBA
9092 * @phba: Pointer to HBA context object.
9094 * This function cleans up all iocb, buffers, mailbox commands
9095 * while shutting down the HBA. This function is called with no
9096 * lock held and always returns 1.
9097 * This function does the following to cleanup driver resources:
9098 * - Free discovery resources for each virtual port
9099 * - Cleanup any pending fabric iocbs
9100 * - Iterate through the iocb txq and free each entry
9102 * - Free up any buffer posted to the HBA
9103 * - Free mailbox commands in the mailbox queue.
9106 lpfc_sli_hba_down(struct lpfc_hba
*phba
)
9108 LIST_HEAD(completions
);
9109 struct lpfc_sli
*psli
= &phba
->sli
;
9110 struct lpfc_sli_ring
*pring
;
9111 struct lpfc_dmabuf
*buf_ptr
;
9112 unsigned long flags
= 0;
9115 /* Shutdown the mailbox command sub-system */
9116 lpfc_sli_mbox_sys_shutdown(phba
, LPFC_MBX_WAIT
);
9118 lpfc_hba_down_prep(phba
);
9120 lpfc_fabric_abort_hba(phba
);
9122 spin_lock_irqsave(&phba
->hbalock
, flags
);
9123 for (i
= 0; i
< psli
->num_rings
; i
++) {
9124 pring
= &psli
->ring
[i
];
9125 /* Only slow rings */
9126 if (pring
->ringno
== LPFC_ELS_RING
) {
9127 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
9128 /* Set the lpfc data pending flag */
9129 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
9133 * Error everything on the txq since these iocbs have not been
9134 * given to the FW yet.
9136 list_splice_init(&pring
->txq
, &completions
);
9138 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9140 /* Cancel all the IOCBs from the completions list */
9141 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9144 spin_lock_irqsave(&phba
->hbalock
, flags
);
9145 list_splice_init(&phba
->elsbuf
, &completions
);
9146 phba
->elsbuf_cnt
= 0;
9147 phba
->elsbuf_prev_cnt
= 0;
9148 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
9150 while (!list_empty(&completions
)) {
9151 list_remove_head(&completions
, buf_ptr
,
9152 struct lpfc_dmabuf
, list
);
9153 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
9157 /* Return any active mbox cmds */
9158 del_timer_sync(&psli
->mbox_tmo
);
9160 spin_lock_irqsave(&phba
->pport
->work_port_lock
, flags
);
9161 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
9162 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, flags
);
9168 * lpfc_sli_pcimem_bcopy - SLI memory copy function
9169 * @srcp: Source memory pointer.
9170 * @destp: Destination memory pointer.
9171 * @cnt: Number of words required to be copied.
9173 * This function is used for copying data between driver memory
9174 * and the SLI memory. This function also changes the endianness
9175 * of each word if native endianness is different from SLI
9176 * endianness. This function can be called with or without
9180 lpfc_sli_pcimem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9182 uint32_t *src
= srcp
;
9183 uint32_t *dest
= destp
;
9187 for (i
= 0; i
< (int)cnt
; i
+= sizeof (uint32_t)) {
9189 ldata
= le32_to_cpu(ldata
);
9198 * lpfc_sli_bemem_bcopy - SLI memory copy function
9199 * @srcp: Source memory pointer.
9200 * @destp: Destination memory pointer.
9201 * @cnt: Number of words required to be copied.
9203 * This function is used for copying data between a data structure
9204 * with big endian representation to local endianness.
9205 * This function can be called with or without lock.
9208 lpfc_sli_bemem_bcopy(void *srcp
, void *destp
, uint32_t cnt
)
9210 uint32_t *src
= srcp
;
9211 uint32_t *dest
= destp
;
9215 for (i
= 0; i
< (int)cnt
; i
+= sizeof(uint32_t)) {
9217 ldata
= be32_to_cpu(ldata
);
9225 * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
9226 * @phba: Pointer to HBA context object.
9227 * @pring: Pointer to driver SLI ring object.
9228 * @mp: Pointer to driver buffer object.
9230 * This function is called with no lock held.
9231 * It always return zero after adding the buffer to the postbufq
9235 lpfc_sli_ringpostbuf_put(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9236 struct lpfc_dmabuf
*mp
)
9238 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
9240 spin_lock_irq(&phba
->hbalock
);
9241 list_add_tail(&mp
->list
, &pring
->postbufq
);
9242 pring
->postbufq_cnt
++;
9243 spin_unlock_irq(&phba
->hbalock
);
9248 * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
9249 * @phba: Pointer to HBA context object.
9251 * When HBQ is enabled, buffers are searched based on tags. This function
9252 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
9253 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
9254 * does not conflict with tags of buffer posted for unsolicited events.
9255 * The function returns the allocated tag. The function is called with
9259 lpfc_sli_get_buffer_tag(struct lpfc_hba
*phba
)
9261 spin_lock_irq(&phba
->hbalock
);
9262 phba
->buffer_tag_count
++;
9264 * Always set the QUE_BUFTAG_BIT to distiguish between
9265 * a tag assigned by HBQ.
9267 phba
->buffer_tag_count
|= QUE_BUFTAG_BIT
;
9268 spin_unlock_irq(&phba
->hbalock
);
9269 return phba
->buffer_tag_count
;
9273 * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
9274 * @phba: Pointer to HBA context object.
9275 * @pring: Pointer to driver SLI ring object.
9278 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
9279 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
9280 * iocb is posted to the response ring with the tag of the buffer.
9281 * This function searches the pring->postbufq list using the tag
9282 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
9283 * iocb. If the buffer is found then lpfc_dmabuf object of the
9284 * buffer is returned to the caller else NULL is returned.
9285 * This function is called with no lock held.
9287 struct lpfc_dmabuf
*
9288 lpfc_sli_ring_taggedbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9291 struct lpfc_dmabuf
*mp
, *next_mp
;
9292 struct list_head
*slp
= &pring
->postbufq
;
9294 /* Search postbufq, from the beginning, looking for a match on tag */
9295 spin_lock_irq(&phba
->hbalock
);
9296 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9297 if (mp
->buffer_tag
== tag
) {
9298 list_del_init(&mp
->list
);
9299 pring
->postbufq_cnt
--;
9300 spin_unlock_irq(&phba
->hbalock
);
9305 spin_unlock_irq(&phba
->hbalock
);
9306 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9307 "0402 Cannot find virtual addr for buffer tag on "
9308 "ring %d Data x%lx x%p x%p x%x\n",
9309 pring
->ringno
, (unsigned long) tag
,
9310 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9316 * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
9317 * @phba: Pointer to HBA context object.
9318 * @pring: Pointer to driver SLI ring object.
9319 * @phys: DMA address of the buffer.
9321 * This function searches the buffer list using the dma_address
9322 * of unsolicited event to find the driver's lpfc_dmabuf object
9323 * corresponding to the dma_address. The function returns the
9324 * lpfc_dmabuf object if a buffer is found else it returns NULL.
9325 * This function is called by the ct and els unsolicited event
9326 * handlers to get the buffer associated with the unsolicited
9329 * This function is called with no lock held.
9331 struct lpfc_dmabuf
*
9332 lpfc_sli_ringpostbuf_get(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9335 struct lpfc_dmabuf
*mp
, *next_mp
;
9336 struct list_head
*slp
= &pring
->postbufq
;
9338 /* Search postbufq, from the beginning, looking for a match on phys */
9339 spin_lock_irq(&phba
->hbalock
);
9340 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
9341 if (mp
->phys
== phys
) {
9342 list_del_init(&mp
->list
);
9343 pring
->postbufq_cnt
--;
9344 spin_unlock_irq(&phba
->hbalock
);
9349 spin_unlock_irq(&phba
->hbalock
);
9350 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9351 "0410 Cannot find virtual addr for mapped buf on "
9352 "ring %d Data x%llx x%p x%p x%x\n",
9353 pring
->ringno
, (unsigned long long)phys
,
9354 slp
->next
, slp
->prev
, pring
->postbufq_cnt
);
9359 * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
9360 * @phba: Pointer to HBA context object.
9361 * @cmdiocb: Pointer to driver command iocb object.
9362 * @rspiocb: Pointer to driver response iocb object.
9364 * This function is the completion handler for the abort iocbs for
9365 * ELS commands. This function is called from the ELS ring event
9366 * handler with no lock held. This function frees memory resources
9367 * associated with the abort iocb.
9370 lpfc_sli_abort_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9371 struct lpfc_iocbq
*rspiocb
)
9373 IOCB_t
*irsp
= &rspiocb
->iocb
;
9374 uint16_t abort_iotag
, abort_context
;
9375 struct lpfc_iocbq
*abort_iocb
= NULL
;
9377 if (irsp
->ulpStatus
) {
9380 * Assume that the port already completed and returned, or
9381 * will return the iocb. Just Log the message.
9383 abort_context
= cmdiocb
->iocb
.un
.acxri
.abortContextTag
;
9384 abort_iotag
= cmdiocb
->iocb
.un
.acxri
.abortIoTag
;
9386 spin_lock_irq(&phba
->hbalock
);
9387 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
9388 if (abort_iotag
!= 0 &&
9389 abort_iotag
<= phba
->sli
.last_iotag
)
9391 phba
->sli
.iocbq_lookup
[abort_iotag
];
9393 /* For sli4 the abort_tag is the XRI,
9394 * so the abort routine puts the iotag of the iocb
9395 * being aborted in the context field of the abort
9398 abort_iocb
= phba
->sli
.iocbq_lookup
[abort_context
];
9400 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_SLI
,
9401 "0327 Cannot abort els iocb %p "
9402 "with tag %x context %x, abort status %x, "
9404 abort_iocb
, abort_iotag
, abort_context
,
9405 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
9407 spin_unlock_irq(&phba
->hbalock
);
9409 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9414 * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
9415 * @phba: Pointer to HBA context object.
9416 * @cmdiocb: Pointer to driver command iocb object.
9417 * @rspiocb: Pointer to driver response iocb object.
9419 * The function is called from SLI ring event handler with no
9420 * lock held. This function is the completion handler for ELS commands
9421 * which are aborted. The function frees memory resources used for
9422 * the aborted ELS commands.
9425 lpfc_ignore_els_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9426 struct lpfc_iocbq
*rspiocb
)
9428 IOCB_t
*irsp
= &rspiocb
->iocb
;
9430 /* ELS cmd tag <ulpIoTag> completes */
9431 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9432 "0139 Ignoring ELS cmd tag x%x completion Data: "
9434 irsp
->ulpIoTag
, irsp
->ulpStatus
,
9435 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
9436 if (cmdiocb
->iocb
.ulpCommand
== CMD_GEN_REQUEST64_CR
)
9437 lpfc_ct_free_iocb(phba
, cmdiocb
);
9439 lpfc_els_free_iocb(phba
, cmdiocb
);
9444 * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb
9445 * @phba: Pointer to HBA context object.
9446 * @pring: Pointer to driver SLI ring object.
9447 * @cmdiocb: Pointer to driver command iocb object.
9449 * This function issues an abort iocb for the provided command iocb down to
9450 * the port. Other than the case the outstanding command iocb is an abort
9451 * request, this function issues abort out unconditionally. This function is
9452 * called with hbalock held. The function returns 0 when it fails due to
9453 * memory allocation failure or when the command iocb is an abort request.
9456 lpfc_sli_abort_iotag_issue(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9457 struct lpfc_iocbq
*cmdiocb
)
9459 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9460 struct lpfc_iocbq
*abtsiocbp
;
9461 IOCB_t
*icmd
= NULL
;
9462 IOCB_t
*iabt
= NULL
;
9464 unsigned long iflags
;
9467 * There are certain command types we don't want to abort. And we
9468 * don't want to abort commands that are already in the process of
9471 icmd
= &cmdiocb
->iocb
;
9472 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9473 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9474 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9477 /* issue ABTS for this IOCB based on iotag */
9478 abtsiocbp
= __lpfc_sli_get_iocbq(phba
);
9479 if (abtsiocbp
== NULL
)
9482 /* This signals the response to set the correct status
9483 * before calling the completion handler
9485 cmdiocb
->iocb_flag
|= LPFC_DRIVER_ABORTED
;
9487 iabt
= &abtsiocbp
->iocb
;
9488 iabt
->un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9489 iabt
->un
.acxri
.abortContextTag
= icmd
->ulpContext
;
9490 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9491 iabt
->un
.acxri
.abortIoTag
= cmdiocb
->sli4_xritag
;
9492 iabt
->un
.acxri
.abortContextTag
= cmdiocb
->iotag
;
9495 iabt
->un
.acxri
.abortIoTag
= icmd
->ulpIoTag
;
9497 iabt
->ulpClass
= icmd
->ulpClass
;
9499 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9500 abtsiocbp
->fcp_wqidx
= cmdiocb
->fcp_wqidx
;
9501 if (cmdiocb
->iocb_flag
& LPFC_IO_FCP
)
9502 abtsiocbp
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9504 if (phba
->link_state
>= LPFC_LINK_UP
)
9505 iabt
->ulpCommand
= CMD_ABORT_XRI_CN
;
9507 iabt
->ulpCommand
= CMD_CLOSE_XRI_CN
;
9509 abtsiocbp
->iocb_cmpl
= lpfc_sli_abort_els_cmpl
;
9511 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
9512 "0339 Abort xri x%x, original iotag x%x, "
9513 "abort cmd iotag x%x\n",
9514 iabt
->un
.acxri
.abortIoTag
,
9515 iabt
->un
.acxri
.abortContextTag
,
9518 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9519 /* Note: both hbalock and ring_lock need to be set here */
9520 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
9521 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9523 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
9525 retval
= __lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9530 __lpfc_sli_release_iocbq(phba
, abtsiocbp
);
9533 * Caller to this routine should check for IOCB_ERROR
9534 * and handle it properly. This routine no longer removes
9535 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9541 * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
9542 * @phba: Pointer to HBA context object.
9543 * @pring: Pointer to driver SLI ring object.
9544 * @cmdiocb: Pointer to driver command iocb object.
9546 * This function issues an abort iocb for the provided command iocb. In case
9547 * of unloading, the abort iocb will not be issued to commands on the ELS
9548 * ring. Instead, the callback function shall be changed to those commands
9549 * so that nothing happens when them finishes. This function is called with
9550 * hbalock held. The function returns 0 when the command iocb is an abort
9554 lpfc_sli_issue_abort_iotag(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
9555 struct lpfc_iocbq
*cmdiocb
)
9557 struct lpfc_vport
*vport
= cmdiocb
->vport
;
9558 int retval
= IOCB_ERROR
;
9559 IOCB_t
*icmd
= NULL
;
9562 * There are certain command types we don't want to abort. And we
9563 * don't want to abort commands that are already in the process of
9566 icmd
= &cmdiocb
->iocb
;
9567 if (icmd
->ulpCommand
== CMD_ABORT_XRI_CN
||
9568 icmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
9569 (cmdiocb
->iocb_flag
& LPFC_DRIVER_ABORTED
) != 0)
9573 * If we're unloading, don't abort iocb on the ELS ring, but change
9574 * the callback so that nothing happens when it finishes.
9576 if ((vport
->load_flag
& FC_UNLOADING
) &&
9577 (pring
->ringno
== LPFC_ELS_RING
)) {
9578 if (cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
)
9579 cmdiocb
->fabric_iocb_cmpl
= lpfc_ignore_els_cmpl
;
9581 cmdiocb
->iocb_cmpl
= lpfc_ignore_els_cmpl
;
9582 goto abort_iotag_exit
;
9585 /* Now, we try to issue the abort to the cmdiocb out */
9586 retval
= lpfc_sli_abort_iotag_issue(phba
, pring
, cmdiocb
);
9590 * Caller to this routine should check for IOCB_ERROR
9591 * and handle it properly. This routine no longer removes
9592 * iocb off txcmplq and call compl in case of IOCB_ERROR.
9598 * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring
9599 * @phba: Pointer to HBA context object.
9600 * @pring: Pointer to driver SLI ring object.
9602 * This function aborts all iocbs in the given ring and frees all the iocb
9603 * objects in txq. This function issues abort iocbs unconditionally for all
9604 * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed
9605 * to complete before the return of this function. The caller is not required
9606 * to hold any locks.
9609 lpfc_sli_iocb_ring_abort(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
)
9611 LIST_HEAD(completions
);
9612 struct lpfc_iocbq
*iocb
, *next_iocb
;
9614 if (pring
->ringno
== LPFC_ELS_RING
)
9615 lpfc_fabric_abort_hba(phba
);
9617 spin_lock_irq(&phba
->hbalock
);
9619 /* Take off all the iocbs on txq for cancelling */
9620 list_splice_init(&pring
->txq
, &completions
);
9623 /* Next issue ABTS for everything on the txcmplq */
9624 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
)
9625 lpfc_sli_abort_iotag_issue(phba
, pring
, iocb
);
9627 spin_unlock_irq(&phba
->hbalock
);
9629 /* Cancel all the IOCBs from the completions list */
9630 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9635 * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
9636 * @phba: pointer to lpfc HBA data structure.
9638 * This routine will abort all pending and outstanding iocbs to an HBA.
9641 lpfc_sli_hba_iocb_abort(struct lpfc_hba
*phba
)
9643 struct lpfc_sli
*psli
= &phba
->sli
;
9644 struct lpfc_sli_ring
*pring
;
9647 for (i
= 0; i
< psli
->num_rings
; i
++) {
9648 pring
= &psli
->ring
[i
];
9649 lpfc_sli_iocb_ring_abort(phba
, pring
);
9654 * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN
9655 * @iocbq: Pointer to driver iocb object.
9656 * @vport: Pointer to driver virtual port object.
9657 * @tgt_id: SCSI ID of the target.
9658 * @lun_id: LUN ID of the scsi device.
9659 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
9661 * This function acts as an iocb filter for functions which abort or count
9662 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
9663 * 0 if the filtering criteria is met for the given iocb and will return
9664 * 1 if the filtering criteria is not met.
9665 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
9666 * given iocb is for the SCSI device specified by vport, tgt_id and
9668 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
9669 * given iocb is for the SCSI target specified by vport and tgt_id
9671 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
9672 * given iocb is for the SCSI host associated with the given vport.
9673 * This function is called with no locks held.
9676 lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq
*iocbq
, struct lpfc_vport
*vport
,
9677 uint16_t tgt_id
, uint64_t lun_id
,
9678 lpfc_ctx_cmd ctx_cmd
)
9680 struct lpfc_scsi_buf
*lpfc_cmd
;
9683 if (!(iocbq
->iocb_flag
& LPFC_IO_FCP
))
9686 if (iocbq
->vport
!= vport
)
9689 lpfc_cmd
= container_of(iocbq
, struct lpfc_scsi_buf
, cur_iocbq
);
9691 if (lpfc_cmd
->pCmd
== NULL
)
9696 if ((lpfc_cmd
->rdata
->pnode
) &&
9697 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
) &&
9698 (scsilun_to_int(&lpfc_cmd
->fcp_cmnd
->fcp_lun
) == lun_id
))
9702 if ((lpfc_cmd
->rdata
->pnode
) &&
9703 (lpfc_cmd
->rdata
->pnode
->nlp_sid
== tgt_id
))
9710 printk(KERN_ERR
"%s: Unknown context cmd type, value %d\n",
9719 * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
9720 * @vport: Pointer to virtual port.
9721 * @tgt_id: SCSI ID of the target.
9722 * @lun_id: LUN ID of the scsi device.
9723 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9725 * This function returns number of FCP commands pending for the vport.
9726 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
9727 * commands pending on the vport associated with SCSI device specified
9728 * by tgt_id and lun_id parameters.
9729 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
9730 * commands pending on the vport associated with SCSI target specified
9731 * by tgt_id parameter.
9732 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
9733 * commands pending on the vport.
9734 * This function returns the number of iocbs which satisfy the filter.
9735 * This function is called without any lock held.
9738 lpfc_sli_sum_iocb(struct lpfc_vport
*vport
, uint16_t tgt_id
, uint64_t lun_id
,
9739 lpfc_ctx_cmd ctx_cmd
)
9741 struct lpfc_hba
*phba
= vport
->phba
;
9742 struct lpfc_iocbq
*iocbq
;
9745 for (i
= 1, sum
= 0; i
<= phba
->sli
.last_iotag
; i
++) {
9746 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9748 if (lpfc_sli_validate_fcp_iocb (iocbq
, vport
, tgt_id
, lun_id
,
9757 * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
9758 * @phba: Pointer to HBA context object
9759 * @cmdiocb: Pointer to command iocb object.
9760 * @rspiocb: Pointer to response iocb object.
9762 * This function is called when an aborted FCP iocb completes. This
9763 * function is called by the ring event handler with no lock held.
9764 * This function frees the iocb.
9767 lpfc_sli_abort_fcp_cmpl(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9768 struct lpfc_iocbq
*rspiocb
)
9770 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9771 "3096 ABORT_XRI_CN completing on xri x%x "
9772 "original iotag x%x, abort cmd iotag x%x "
9773 "status 0x%x, reason 0x%x\n",
9774 cmdiocb
->iocb
.un
.acxri
.abortContextTag
,
9775 cmdiocb
->iocb
.un
.acxri
.abortIoTag
,
9776 cmdiocb
->iotag
, rspiocb
->iocb
.ulpStatus
,
9777 rspiocb
->iocb
.un
.ulpWord
[4]);
9778 lpfc_sli_release_iocbq(phba
, cmdiocb
);
9783 * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
9784 * @vport: Pointer to virtual port.
9785 * @pring: Pointer to driver SLI ring object.
9786 * @tgt_id: SCSI ID of the target.
9787 * @lun_id: LUN ID of the scsi device.
9788 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
9790 * This function sends an abort command for every SCSI command
9791 * associated with the given virtual port pending on the ring
9792 * filtered by lpfc_sli_validate_fcp_iocb function.
9793 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
9794 * FCP iocbs associated with lun specified by tgt_id and lun_id
9796 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
9797 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
9798 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
9799 * FCP iocbs associated with virtual port.
9800 * This function returns number of iocbs it failed to abort.
9801 * This function is called with no locks held.
9804 lpfc_sli_abort_iocb(struct lpfc_vport
*vport
, struct lpfc_sli_ring
*pring
,
9805 uint16_t tgt_id
, uint64_t lun_id
, lpfc_ctx_cmd abort_cmd
)
9807 struct lpfc_hba
*phba
= vport
->phba
;
9808 struct lpfc_iocbq
*iocbq
;
9809 struct lpfc_iocbq
*abtsiocb
;
9811 int errcnt
= 0, ret_val
= 0;
9814 for (i
= 1; i
<= phba
->sli
.last_iotag
; i
++) {
9815 iocbq
= phba
->sli
.iocbq_lookup
[i
];
9817 if (lpfc_sli_validate_fcp_iocb(iocbq
, vport
, tgt_id
, lun_id
,
9821 /* issue ABTS for this IOCB based on iotag */
9822 abtsiocb
= lpfc_sli_get_iocbq(phba
);
9823 if (abtsiocb
== NULL
) {
9829 abtsiocb
->iocb
.un
.acxri
.abortType
= ABORT_TYPE_ABTS
;
9830 abtsiocb
->iocb
.un
.acxri
.abortContextTag
= cmd
->ulpContext
;
9831 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9832 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= iocbq
->sli4_xritag
;
9834 abtsiocb
->iocb
.un
.acxri
.abortIoTag
= cmd
->ulpIoTag
;
9835 abtsiocb
->iocb
.ulpLe
= 1;
9836 abtsiocb
->iocb
.ulpClass
= cmd
->ulpClass
;
9837 abtsiocb
->vport
= phba
->pport
;
9839 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
9840 abtsiocb
->fcp_wqidx
= iocbq
->fcp_wqidx
;
9841 if (iocbq
->iocb_flag
& LPFC_IO_FCP
)
9842 abtsiocb
->iocb_flag
|= LPFC_USE_FCPWQIDX
;
9844 if (lpfc_is_link_up(phba
))
9845 abtsiocb
->iocb
.ulpCommand
= CMD_ABORT_XRI_CN
;
9847 abtsiocb
->iocb
.ulpCommand
= CMD_CLOSE_XRI_CN
;
9849 /* Setup callback routine and issue the command. */
9850 abtsiocb
->iocb_cmpl
= lpfc_sli_abort_fcp_cmpl
;
9851 ret_val
= lpfc_sli_issue_iocb(phba
, pring
->ringno
,
9853 if (ret_val
== IOCB_ERROR
) {
9854 lpfc_sli_release_iocbq(phba
, abtsiocb
);
9864 * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
9865 * @phba: Pointer to HBA context object.
9866 * @cmdiocbq: Pointer to command iocb.
9867 * @rspiocbq: Pointer to response iocb.
9869 * This function is the completion handler for iocbs issued using
9870 * lpfc_sli_issue_iocb_wait function. This function is called by the
9871 * ring event handler function without any lock held. This function
9872 * can be called from both worker thread context and interrupt
9873 * context. This function also can be called from other thread which
9874 * cleans up the SLI layer objects.
9875 * This function copy the contents of the response iocb to the
9876 * response iocb memory object provided by the caller of
9877 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
9878 * sleeps for the iocb completion.
9881 lpfc_sli_wake_iocb_wait(struct lpfc_hba
*phba
,
9882 struct lpfc_iocbq
*cmdiocbq
,
9883 struct lpfc_iocbq
*rspiocbq
)
9885 wait_queue_head_t
*pdone_q
;
9886 unsigned long iflags
;
9887 struct lpfc_scsi_buf
*lpfc_cmd
;
9889 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9890 cmdiocbq
->iocb_flag
|= LPFC_IO_WAKE
;
9891 if (cmdiocbq
->context2
&& rspiocbq
)
9892 memcpy(&((struct lpfc_iocbq
*)cmdiocbq
->context2
)->iocb
,
9893 &rspiocbq
->iocb
, sizeof(IOCB_t
));
9895 /* Set the exchange busy flag for task management commands */
9896 if ((cmdiocbq
->iocb_flag
& LPFC_IO_FCP
) &&
9897 !(cmdiocbq
->iocb_flag
& LPFC_IO_LIBDFC
)) {
9898 lpfc_cmd
= container_of(cmdiocbq
, struct lpfc_scsi_buf
,
9900 lpfc_cmd
->exch_busy
= rspiocbq
->iocb_flag
& LPFC_EXCHANGE_BUSY
;
9903 pdone_q
= cmdiocbq
->context_un
.wait_queue
;
9906 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9911 * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
9912 * @phba: Pointer to HBA context object..
9913 * @piocbq: Pointer to command iocb.
9914 * @flag: Flag to test.
9916 * This routine grabs the hbalock and then test the iocb_flag to
9917 * see if the passed in flag is set.
9920 * 0 if flag is not set.
9923 lpfc_chk_iocb_flg(struct lpfc_hba
*phba
,
9924 struct lpfc_iocbq
*piocbq
, uint32_t flag
)
9926 unsigned long iflags
;
9929 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9930 ret
= piocbq
->iocb_flag
& flag
;
9931 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9937 * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
9938 * @phba: Pointer to HBA context object..
9939 * @pring: Pointer to sli ring.
9940 * @piocb: Pointer to command iocb.
9941 * @prspiocbq: Pointer to response iocb.
9942 * @timeout: Timeout in number of seconds.
9944 * This function issues the iocb to firmware and waits for the
9945 * iocb to complete. If the iocb command is not
9946 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
9947 * Caller should not free the iocb resources if this function
9948 * returns IOCB_TIMEDOUT.
9949 * The function waits for the iocb completion using an
9950 * non-interruptible wait.
9951 * This function will sleep while waiting for iocb completion.
9952 * So, this function should not be called from any context which
9953 * does not allow sleeping. Due to the same reason, this function
9954 * cannot be called with interrupt disabled.
9955 * This function assumes that the iocb completions occur while
9956 * this function sleep. So, this function cannot be called from
9957 * the thread which process iocb completion for this ring.
9958 * This function clears the iocb_flag of the iocb object before
9959 * issuing the iocb and the iocb completion handler sets this
9960 * flag and wakes this thread when the iocb completes.
9961 * The contents of the response iocb will be copied to prspiocbq
9962 * by the completion handler when the command completes.
9963 * This function returns IOCB_SUCCESS when success.
9964 * This function is called with no lock held.
9967 lpfc_sli_issue_iocb_wait(struct lpfc_hba
*phba
,
9968 uint32_t ring_number
,
9969 struct lpfc_iocbq
*piocb
,
9970 struct lpfc_iocbq
*prspiocbq
,
9973 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
9974 long timeleft
, timeout_req
= 0;
9975 int retval
= IOCB_SUCCESS
;
9977 struct lpfc_iocbq
*iocb
;
9979 int txcmplq_cnt
= 0;
9980 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9982 * If the caller has provided a response iocbq buffer, then context2
9983 * is NULL or its an error.
9986 if (piocb
->context2
)
9988 piocb
->context2
= prspiocbq
;
9991 piocb
->iocb_cmpl
= lpfc_sli_wake_iocb_wait
;
9992 piocb
->context_un
.wait_queue
= &done_q
;
9993 piocb
->iocb_flag
&= ~LPFC_IO_WAKE
;
9995 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
9996 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
9998 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
9999 writel(creg_val
, phba
->HCregaddr
);
10000 readl(phba
->HCregaddr
); /* flush */
10003 retval
= lpfc_sli_issue_iocb(phba
, ring_number
, piocb
,
10004 SLI_IOCB_RET_IOCB
);
10005 if (retval
== IOCB_SUCCESS
) {
10006 timeout_req
= timeout
* HZ
;
10007 timeleft
= wait_event_timeout(done_q
,
10008 lpfc_chk_iocb_flg(phba
, piocb
, LPFC_IO_WAKE
),
10011 if (piocb
->iocb_flag
& LPFC_IO_WAKE
) {
10012 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10013 "0331 IOCB wake signaled\n");
10014 } else if (timeleft
== 0) {
10015 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10016 "0338 IOCB wait timeout error - no "
10017 "wake response Data x%x\n", timeout
);
10018 retval
= IOCB_TIMEDOUT
;
10020 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
10021 "0330 IOCB wake NOT set, "
10023 timeout
, (timeleft
/ jiffies
));
10024 retval
= IOCB_TIMEDOUT
;
10026 } else if (retval
== IOCB_BUSY
) {
10027 if (phba
->cfg_log_verbose
& LOG_SLI
) {
10028 list_for_each_entry(iocb
, &pring
->txq
, list
) {
10031 list_for_each_entry(iocb
, &pring
->txcmplq
, list
) {
10034 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10035 "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
10036 phba
->iocb_cnt
, txq_cnt
, txcmplq_cnt
);
10040 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
10041 "0332 IOCB wait issue failed, Data x%x\n",
10043 retval
= IOCB_ERROR
;
10046 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
10047 if (lpfc_readl(phba
->HCregaddr
, &creg_val
))
10049 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
10050 writel(creg_val
, phba
->HCregaddr
);
10051 readl(phba
->HCregaddr
); /* flush */
10055 piocb
->context2
= NULL
;
10057 piocb
->context_un
.wait_queue
= NULL
;
10058 piocb
->iocb_cmpl
= NULL
;
10063 * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
10064 * @phba: Pointer to HBA context object.
10065 * @pmboxq: Pointer to driver mailbox object.
10066 * @timeout: Timeout in number of seconds.
10068 * This function issues the mailbox to firmware and waits for the
10069 * mailbox command to complete. If the mailbox command is not
10070 * completed within timeout seconds, it returns MBX_TIMEOUT.
10071 * The function waits for the mailbox completion using an
10072 * interruptible wait. If the thread is woken up due to a
10073 * signal, MBX_TIMEOUT error is returned to the caller. Caller
10074 * should not free the mailbox resources, if this function returns
10076 * This function will sleep while waiting for mailbox completion.
10077 * So, this function should not be called from any context which
10078 * does not allow sleeping. Due to the same reason, this function
10079 * cannot be called with interrupt disabled.
10080 * This function assumes that the mailbox completion occurs while
10081 * this function sleep. So, this function cannot be called from
10082 * the worker thread which processes mailbox completion.
10083 * This function is called in the context of HBA management
10085 * This function returns MBX_SUCCESS when successful.
10086 * This function is called with no lock held.
10089 lpfc_sli_issue_mbox_wait(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
,
10092 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q
);
10094 unsigned long flag
;
10096 /* The caller must leave context1 empty. */
10097 if (pmboxq
->context1
)
10098 return MBX_NOT_FINISHED
;
10100 pmboxq
->mbox_flag
&= ~LPFC_MBX_WAKE
;
10101 /* setup wake call as IOCB callback */
10102 pmboxq
->mbox_cmpl
= lpfc_sli_wake_mbox_wait
;
10103 /* setup context field to pass wait_queue pointer to wake function */
10104 pmboxq
->context1
= &done_q
;
10106 /* now issue the command */
10107 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
10108 if (retval
== MBX_BUSY
|| retval
== MBX_SUCCESS
) {
10109 wait_event_interruptible_timeout(done_q
,
10110 pmboxq
->mbox_flag
& LPFC_MBX_WAKE
,
10113 spin_lock_irqsave(&phba
->hbalock
, flag
);
10114 pmboxq
->context1
= NULL
;
10116 * if LPFC_MBX_WAKE flag is set the mailbox is completed
10117 * else do not free the resources.
10119 if (pmboxq
->mbox_flag
& LPFC_MBX_WAKE
) {
10120 retval
= MBX_SUCCESS
;
10121 lpfc_sli4_swap_str(phba
, pmboxq
);
10123 retval
= MBX_TIMEOUT
;
10124 pmboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10126 spin_unlock_irqrestore(&phba
->hbalock
, flag
);
10133 * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
10134 * @phba: Pointer to HBA context.
10136 * This function is called to shutdown the driver's mailbox sub-system.
10137 * It first marks the mailbox sub-system is in a block state to prevent
10138 * the asynchronous mailbox command from issued off the pending mailbox
10139 * command queue. If the mailbox command sub-system shutdown is due to
10140 * HBA error conditions such as EEH or ERATT, this routine shall invoke
10141 * the mailbox sub-system flush routine to forcefully bring down the
10142 * mailbox sub-system. Otherwise, if it is due to normal condition (such
10143 * as with offline or HBA function reset), this routine will wait for the
10144 * outstanding mailbox command to complete before invoking the mailbox
10145 * sub-system flush routine to gracefully bring down mailbox sub-system.
10148 lpfc_sli_mbox_sys_shutdown(struct lpfc_hba
*phba
, int mbx_action
)
10150 struct lpfc_sli
*psli
= &phba
->sli
;
10151 unsigned long timeout
;
10153 if (mbx_action
== LPFC_MBX_NO_WAIT
) {
10154 /* delay 100ms for port state */
10156 lpfc_sli_mbox_sys_flush(phba
);
10159 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
10161 spin_lock_irq(&phba
->hbalock
);
10162 psli
->sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
10164 if (psli
->sli_flag
& LPFC_SLI_ACTIVE
) {
10165 /* Determine how long we might wait for the active mailbox
10166 * command to be gracefully completed by firmware.
10168 if (phba
->sli
.mbox_active
)
10169 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
10170 phba
->sli
.mbox_active
) *
10172 spin_unlock_irq(&phba
->hbalock
);
10174 while (phba
->sli
.mbox_active
) {
10175 /* Check active mailbox complete status every 2ms */
10177 if (time_after(jiffies
, timeout
))
10178 /* Timeout, let the mailbox flush routine to
10179 * forcefully release active mailbox command
10184 spin_unlock_irq(&phba
->hbalock
);
10186 lpfc_sli_mbox_sys_flush(phba
);
10190 * lpfc_sli_eratt_read - read sli-3 error attention events
10191 * @phba: Pointer to HBA context.
10193 * This function is called to read the SLI3 device error attention registers
10194 * for possible error attention events. The caller must hold the hostlock
10195 * with spin_lock_irq().
10197 * This function returns 1 when there is Error Attention in the Host Attention
10198 * Register and returns 0 otherwise.
10201 lpfc_sli_eratt_read(struct lpfc_hba
*phba
)
10205 /* Read chip Host Attention (HA) register */
10206 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10209 if (ha_copy
& HA_ERATT
) {
10210 /* Read host status register to retrieve error event */
10211 if (lpfc_sli_read_hs(phba
))
10214 /* Check if there is a deferred error condition is active */
10215 if ((HS_FFER1
& phba
->work_hs
) &&
10216 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10217 HS_FFER6
| HS_FFER7
| HS_FFER8
) & phba
->work_hs
)) {
10218 phba
->hba_flag
|= DEFER_ERATT
;
10219 /* Clear all interrupt enable conditions */
10220 writel(0, phba
->HCregaddr
);
10221 readl(phba
->HCregaddr
);
10224 /* Set the driver HA work bitmap */
10225 phba
->work_ha
|= HA_ERATT
;
10226 /* Indicate polling handles this ERATT */
10227 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10233 /* Set the driver HS work bitmap */
10234 phba
->work_hs
|= UNPLUG_ERR
;
10235 /* Set the driver HA work bitmap */
10236 phba
->work_ha
|= HA_ERATT
;
10237 /* Indicate polling handles this ERATT */
10238 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10243 * lpfc_sli4_eratt_read - read sli-4 error attention events
10244 * @phba: Pointer to HBA context.
10246 * This function is called to read the SLI4 device error attention registers
10247 * for possible error attention events. The caller must hold the hostlock
10248 * with spin_lock_irq().
10250 * This function returns 1 when there is Error Attention in the Host Attention
10251 * Register and returns 0 otherwise.
10254 lpfc_sli4_eratt_read(struct lpfc_hba
*phba
)
10256 uint32_t uerr_sta_hi
, uerr_sta_lo
;
10257 uint32_t if_type
, portsmphr
;
10258 struct lpfc_register portstat_reg
;
10261 * For now, use the SLI4 device internal unrecoverable error
10262 * registers for error attention. This can be changed later.
10264 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
10266 case LPFC_SLI_INTF_IF_TYPE_0
:
10267 if (lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
10269 lpfc_readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
,
10271 phba
->work_hs
|= UNPLUG_ERR
;
10272 phba
->work_ha
|= HA_ERATT
;
10273 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10276 if ((~phba
->sli4_hba
.ue_mask_lo
& uerr_sta_lo
) ||
10277 (~phba
->sli4_hba
.ue_mask_hi
& uerr_sta_hi
)) {
10278 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10279 "1423 HBA Unrecoverable error: "
10280 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
10281 "ue_mask_lo_reg=0x%x, "
10282 "ue_mask_hi_reg=0x%x\n",
10283 uerr_sta_lo
, uerr_sta_hi
,
10284 phba
->sli4_hba
.ue_mask_lo
,
10285 phba
->sli4_hba
.ue_mask_hi
);
10286 phba
->work_status
[0] = uerr_sta_lo
;
10287 phba
->work_status
[1] = uerr_sta_hi
;
10288 phba
->work_ha
|= HA_ERATT
;
10289 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10293 case LPFC_SLI_INTF_IF_TYPE_2
:
10294 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
10295 &portstat_reg
.word0
) ||
10296 lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
10298 phba
->work_hs
|= UNPLUG_ERR
;
10299 phba
->work_ha
|= HA_ERATT
;
10300 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10303 if (bf_get(lpfc_sliport_status_err
, &portstat_reg
)) {
10304 phba
->work_status
[0] =
10305 readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
10306 phba
->work_status
[1] =
10307 readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
10308 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10309 "2885 Port Status Event: "
10310 "port status reg 0x%x, "
10311 "port smphr reg 0x%x, "
10312 "error 1=0x%x, error 2=0x%x\n",
10313 portstat_reg
.word0
,
10315 phba
->work_status
[0],
10316 phba
->work_status
[1]);
10317 phba
->work_ha
|= HA_ERATT
;
10318 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10322 case LPFC_SLI_INTF_IF_TYPE_1
:
10324 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10325 "2886 HBA Error Attention on unsupported "
10326 "if type %d.", if_type
);
10334 * lpfc_sli_check_eratt - check error attention events
10335 * @phba: Pointer to HBA context.
10337 * This function is called from timer soft interrupt context to check HBA's
10338 * error attention register bit for error attention events.
10340 * This function returns 1 when there is Error Attention in the Host Attention
10341 * Register and returns 0 otherwise.
10344 lpfc_sli_check_eratt(struct lpfc_hba
*phba
)
10348 /* If somebody is waiting to handle an eratt, don't process it
10349 * here. The brdkill function will do this.
10351 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10354 /* Check if interrupt handler handles this ERATT */
10355 spin_lock_irq(&phba
->hbalock
);
10356 if (phba
->hba_flag
& HBA_ERATT_HANDLED
) {
10357 /* Interrupt handler has handled ERATT */
10358 spin_unlock_irq(&phba
->hbalock
);
10363 * If there is deferred error attention, do not check for error
10366 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10367 spin_unlock_irq(&phba
->hbalock
);
10371 /* If PCI channel is offline, don't process it */
10372 if (unlikely(pci_channel_offline(phba
->pcidev
))) {
10373 spin_unlock_irq(&phba
->hbalock
);
10377 switch (phba
->sli_rev
) {
10378 case LPFC_SLI_REV2
:
10379 case LPFC_SLI_REV3
:
10380 /* Read chip Host Attention (HA) register */
10381 ha_copy
= lpfc_sli_eratt_read(phba
);
10383 case LPFC_SLI_REV4
:
10384 /* Read device Uncoverable Error (UERR) registers */
10385 ha_copy
= lpfc_sli4_eratt_read(phba
);
10388 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10389 "0299 Invalid SLI revision (%d)\n",
10394 spin_unlock_irq(&phba
->hbalock
);
10400 * lpfc_intr_state_check - Check device state for interrupt handling
10401 * @phba: Pointer to HBA context.
10403 * This inline routine checks whether a device or its PCI slot is in a state
10404 * that the interrupt should be handled.
10406 * This function returns 0 if the device or the PCI slot is in a state that
10407 * interrupt should be handled, otherwise -EIO.
10410 lpfc_intr_state_check(struct lpfc_hba
*phba
)
10412 /* If the pci channel is offline, ignore all the interrupts */
10413 if (unlikely(pci_channel_offline(phba
->pcidev
)))
10416 /* Update device level interrupt statistics */
10417 phba
->sli
.slistat
.sli_intr
++;
10419 /* Ignore all interrupts during initialization. */
10420 if (unlikely(phba
->link_state
< LPFC_LINK_DOWN
))
10427 * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
10428 * @irq: Interrupt number.
10429 * @dev_id: The device context pointer.
10431 * This function is directly called from the PCI layer as an interrupt
10432 * service routine when device with SLI-3 interface spec is enabled with
10433 * MSI-X multi-message interrupt mode and there are slow-path events in
10434 * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
10435 * interrupt mode, this function is called as part of the device-level
10436 * interrupt handler. When the PCI slot is in error recovery or the HBA
10437 * is undergoing initialization, the interrupt handler will not process
10438 * the interrupt. The link attention and ELS ring attention events are
10439 * handled by the worker thread. The interrupt handler signals the worker
10440 * thread and returns for these events. This function is called without
10441 * any lock held. It gets the hbalock to access and update SLI data
10444 * This function returns IRQ_HANDLED when interrupt is handled else it
10445 * returns IRQ_NONE.
10448 lpfc_sli_sp_intr_handler(int irq
, void *dev_id
)
10450 struct lpfc_hba
*phba
;
10451 uint32_t ha_copy
, hc_copy
;
10452 uint32_t work_ha_copy
;
10453 unsigned long status
;
10454 unsigned long iflag
;
10457 MAILBOX_t
*mbox
, *pmbox
;
10458 struct lpfc_vport
*vport
;
10459 struct lpfc_nodelist
*ndlp
;
10460 struct lpfc_dmabuf
*mp
;
10465 * Get the driver's phba structure from the dev_id and
10466 * assume the HBA is not interrupting.
10468 phba
= (struct lpfc_hba
*)dev_id
;
10470 if (unlikely(!phba
))
10474 * Stuff needs to be attented to when this function is invoked as an
10475 * individual interrupt handler in MSI-X multi-message interrupt mode
10477 if (phba
->intr_type
== MSIX
) {
10478 /* Check device state for handling interrupt */
10479 if (lpfc_intr_state_check(phba
))
10481 /* Need to read HA REG for slow-path events */
10482 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10483 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10485 /* If somebody is waiting to handle an eratt don't process it
10486 * here. The brdkill function will do this.
10488 if (phba
->link_flag
& LS_IGNORE_ERATT
)
10489 ha_copy
&= ~HA_ERATT
;
10490 /* Check the need for handling ERATT in interrupt handler */
10491 if (ha_copy
& HA_ERATT
) {
10492 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10493 /* ERATT polling has handled ERATT */
10494 ha_copy
&= ~HA_ERATT
;
10496 /* Indicate interrupt handler handles ERATT */
10497 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10501 * If there is deferred error attention, do not check for any
10504 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10505 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10509 /* Clear up only attention source related to slow-path */
10510 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
))
10513 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R2INT_ENA
|
10514 HC_LAINT_ENA
| HC_ERINT_ENA
),
10516 writel((ha_copy
& (HA_MBATT
| HA_R2_CLR_MSK
)),
10518 writel(hc_copy
, phba
->HCregaddr
);
10519 readl(phba
->HAregaddr
); /* flush */
10520 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10522 ha_copy
= phba
->ha_copy
;
10524 work_ha_copy
= ha_copy
& phba
->work_ha_mask
;
10526 if (work_ha_copy
) {
10527 if (work_ha_copy
& HA_LATT
) {
10528 if (phba
->sli
.sli_flag
& LPFC_PROCESS_LA
) {
10530 * Turn off Link Attention interrupts
10531 * until CLEAR_LA done
10533 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10534 phba
->sli
.sli_flag
&= ~LPFC_PROCESS_LA
;
10535 if (lpfc_readl(phba
->HCregaddr
, &control
))
10537 control
&= ~HC_LAINT_ENA
;
10538 writel(control
, phba
->HCregaddr
);
10539 readl(phba
->HCregaddr
); /* flush */
10540 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10543 work_ha_copy
&= ~HA_LATT
;
10546 if (work_ha_copy
& ~(HA_ERATT
| HA_MBATT
| HA_LATT
)) {
10548 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
10549 * the only slow ring.
10551 status
= (work_ha_copy
&
10552 (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10553 status
>>= (4*LPFC_ELS_RING
);
10554 if (status
& HA_RXMASK
) {
10555 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10556 if (lpfc_readl(phba
->HCregaddr
, &control
))
10559 lpfc_debugfs_slow_ring_trc(phba
,
10560 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
10562 (uint32_t)phba
->sli
.slistat
.sli_intr
);
10564 if (control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
)) {
10565 lpfc_debugfs_slow_ring_trc(phba
,
10566 "ISR Disable ring:"
10567 "pwork:x%x hawork:x%x wait:x%x",
10568 phba
->work_ha
, work_ha_copy
,
10569 (uint32_t)((unsigned long)
10570 &phba
->work_waitq
));
10573 ~(HC_R0INT_ENA
<< LPFC_ELS_RING
);
10574 writel(control
, phba
->HCregaddr
);
10575 readl(phba
->HCregaddr
); /* flush */
10578 lpfc_debugfs_slow_ring_trc(phba
,
10579 "ISR slow ring: pwork:"
10580 "x%x hawork:x%x wait:x%x",
10581 phba
->work_ha
, work_ha_copy
,
10582 (uint32_t)((unsigned long)
10583 &phba
->work_waitq
));
10585 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10588 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10589 if (work_ha_copy
& HA_ERATT
) {
10590 if (lpfc_sli_read_hs(phba
))
10593 * Check if there is a deferred error condition
10596 if ((HS_FFER1
& phba
->work_hs
) &&
10597 ((HS_FFER2
| HS_FFER3
| HS_FFER4
| HS_FFER5
|
10598 HS_FFER6
| HS_FFER7
| HS_FFER8
) &
10600 phba
->hba_flag
|= DEFER_ERATT
;
10601 /* Clear all interrupt enable conditions */
10602 writel(0, phba
->HCregaddr
);
10603 readl(phba
->HCregaddr
);
10607 if ((work_ha_copy
& HA_MBATT
) && (phba
->sli
.mbox_active
)) {
10608 pmb
= phba
->sli
.mbox_active
;
10609 pmbox
= &pmb
->u
.mb
;
10611 vport
= pmb
->vport
;
10613 /* First check out the status word */
10614 lpfc_sli_pcimem_bcopy(mbox
, pmbox
, sizeof(uint32_t));
10615 if (pmbox
->mbxOwner
!= OWN_HOST
) {
10616 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10618 * Stray Mailbox Interrupt, mbxCommand <cmd>
10619 * mbxStatus <status>
10621 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10623 "(%d):0304 Stray Mailbox "
10624 "Interrupt mbxCommand x%x "
10626 (vport
? vport
->vpi
: 0),
10629 /* clear mailbox attention bit */
10630 work_ha_copy
&= ~HA_MBATT
;
10632 phba
->sli
.mbox_active
= NULL
;
10633 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10634 phba
->last_completion_time
= jiffies
;
10635 del_timer(&phba
->sli
.mbox_tmo
);
10636 if (pmb
->mbox_cmpl
) {
10637 lpfc_sli_pcimem_bcopy(mbox
, pmbox
,
10639 if (pmb
->out_ext_byte_len
&&
10641 lpfc_sli_pcimem_bcopy(
10644 pmb
->out_ext_byte_len
);
10646 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
10647 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
10649 lpfc_debugfs_disc_trc(vport
,
10650 LPFC_DISC_TRC_MBOX_VPORT
,
10651 "MBOX dflt rpi: : "
10652 "status:x%x rpi:x%x",
10653 (uint32_t)pmbox
->mbxStatus
,
10654 pmbox
->un
.varWords
[0], 0);
10656 if (!pmbox
->mbxStatus
) {
10657 mp
= (struct lpfc_dmabuf
*)
10659 ndlp
= (struct lpfc_nodelist
*)
10662 /* Reg_LOGIN of dflt RPI was
10663 * successful. new lets get
10664 * rid of the RPI using the
10665 * same mbox buffer.
10667 lpfc_unreg_login(phba
,
10669 pmbox
->un
.varWords
[0],
10672 lpfc_mbx_cmpl_dflt_rpi
;
10673 pmb
->context1
= mp
;
10674 pmb
->context2
= ndlp
;
10675 pmb
->vport
= vport
;
10676 rc
= lpfc_sli_issue_mbox(phba
,
10679 if (rc
!= MBX_BUSY
)
10680 lpfc_printf_log(phba
,
10682 LOG_MBOX
| LOG_SLI
,
10683 "0350 rc should have"
10684 "been MBX_BUSY\n");
10685 if (rc
!= MBX_NOT_FINISHED
)
10686 goto send_current_mbox
;
10690 &phba
->pport
->work_port_lock
,
10692 phba
->pport
->work_port_events
&=
10694 spin_unlock_irqrestore(
10695 &phba
->pport
->work_port_lock
,
10697 lpfc_mbox_cmpl_put(phba
, pmb
);
10700 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10702 if ((work_ha_copy
& HA_MBATT
) &&
10703 (phba
->sli
.mbox_active
== NULL
)) {
10705 /* Process next mailbox command if there is one */
10707 rc
= lpfc_sli_issue_mbox(phba
, NULL
,
10709 } while (rc
== MBX_NOT_FINISHED
);
10710 if (rc
!= MBX_SUCCESS
)
10711 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
10712 LOG_SLI
, "0349 rc should be "
10716 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10717 phba
->work_ha
|= work_ha_copy
;
10718 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10719 lpfc_worker_wake_up(phba
);
10721 return IRQ_HANDLED
;
10723 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10724 return IRQ_HANDLED
;
10726 } /* lpfc_sli_sp_intr_handler */
10729 * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
10730 * @irq: Interrupt number.
10731 * @dev_id: The device context pointer.
10733 * This function is directly called from the PCI layer as an interrupt
10734 * service routine when device with SLI-3 interface spec is enabled with
10735 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
10736 * ring event in the HBA. However, when the device is enabled with either
10737 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
10738 * device-level interrupt handler. When the PCI slot is in error recovery
10739 * or the HBA is undergoing initialization, the interrupt handler will not
10740 * process the interrupt. The SCSI FCP fast-path ring event are handled in
10741 * the intrrupt context. This function is called without any lock held.
10742 * It gets the hbalock to access and update SLI data structures.
10744 * This function returns IRQ_HANDLED when interrupt is handled else it
10745 * returns IRQ_NONE.
10748 lpfc_sli_fp_intr_handler(int irq
, void *dev_id
)
10750 struct lpfc_hba
*phba
;
10752 unsigned long status
;
10753 unsigned long iflag
;
10755 /* Get the driver's phba structure from the dev_id and
10756 * assume the HBA is not interrupting.
10758 phba
= (struct lpfc_hba
*) dev_id
;
10760 if (unlikely(!phba
))
10764 * Stuff needs to be attented to when this function is invoked as an
10765 * individual interrupt handler in MSI-X multi-message interrupt mode
10767 if (phba
->intr_type
== MSIX
) {
10768 /* Check device state for handling interrupt */
10769 if (lpfc_intr_state_check(phba
))
10771 /* Need to read HA REG for FCP ring and other ring events */
10772 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
10773 return IRQ_HANDLED
;
10774 /* Clear up only attention source related to fast-path */
10775 spin_lock_irqsave(&phba
->hbalock
, iflag
);
10777 * If there is deferred error attention, do not check for
10780 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10781 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10784 writel((ha_copy
& (HA_R0_CLR_MSK
| HA_R1_CLR_MSK
)),
10786 readl(phba
->HAregaddr
); /* flush */
10787 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
10789 ha_copy
= phba
->ha_copy
;
10792 * Process all events on FCP ring. Take the optimized path for FCP IO.
10794 ha_copy
&= ~(phba
->work_ha_mask
);
10796 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10797 status
>>= (4*LPFC_FCP_RING
);
10798 if (status
& HA_RXMASK
)
10799 lpfc_sli_handle_fast_ring_event(phba
,
10800 &phba
->sli
.ring
[LPFC_FCP_RING
],
10803 if (phba
->cfg_multi_ring_support
== 2) {
10805 * Process all events on extra ring. Take the optimized path
10806 * for extra ring IO.
10808 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10809 status
>>= (4*LPFC_EXTRA_RING
);
10810 if (status
& HA_RXMASK
) {
10811 lpfc_sli_handle_fast_ring_event(phba
,
10812 &phba
->sli
.ring
[LPFC_EXTRA_RING
],
10816 return IRQ_HANDLED
;
10817 } /* lpfc_sli_fp_intr_handler */
10820 * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
10821 * @irq: Interrupt number.
10822 * @dev_id: The device context pointer.
10824 * This function is the HBA device-level interrupt handler to device with
10825 * SLI-3 interface spec, called from the PCI layer when either MSI or
10826 * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
10827 * requires driver attention. This function invokes the slow-path interrupt
10828 * attention handling function and fast-path interrupt attention handling
10829 * function in turn to process the relevant HBA attention events. This
10830 * function is called without any lock held. It gets the hbalock to access
10831 * and update SLI data structures.
10833 * This function returns IRQ_HANDLED when interrupt is handled, else it
10834 * returns IRQ_NONE.
10837 lpfc_sli_intr_handler(int irq
, void *dev_id
)
10839 struct lpfc_hba
*phba
;
10840 irqreturn_t sp_irq_rc
, fp_irq_rc
;
10841 unsigned long status1
, status2
;
10845 * Get the driver's phba structure from the dev_id and
10846 * assume the HBA is not interrupting.
10848 phba
= (struct lpfc_hba
*) dev_id
;
10850 if (unlikely(!phba
))
10853 /* Check device state for handling interrupt */
10854 if (lpfc_intr_state_check(phba
))
10857 spin_lock(&phba
->hbalock
);
10858 if (lpfc_readl(phba
->HAregaddr
, &phba
->ha_copy
)) {
10859 spin_unlock(&phba
->hbalock
);
10860 return IRQ_HANDLED
;
10863 if (unlikely(!phba
->ha_copy
)) {
10864 spin_unlock(&phba
->hbalock
);
10866 } else if (phba
->ha_copy
& HA_ERATT
) {
10867 if (phba
->hba_flag
& HBA_ERATT_HANDLED
)
10868 /* ERATT polling has handled ERATT */
10869 phba
->ha_copy
&= ~HA_ERATT
;
10871 /* Indicate interrupt handler handles ERATT */
10872 phba
->hba_flag
|= HBA_ERATT_HANDLED
;
10876 * If there is deferred error attention, do not check for any interrupt.
10878 if (unlikely(phba
->hba_flag
& DEFER_ERATT
)) {
10879 spin_unlock(&phba
->hbalock
);
10883 /* Clear attention sources except link and error attentions */
10884 if (lpfc_readl(phba
->HCregaddr
, &hc_copy
)) {
10885 spin_unlock(&phba
->hbalock
);
10886 return IRQ_HANDLED
;
10888 writel(hc_copy
& ~(HC_MBINT_ENA
| HC_R0INT_ENA
| HC_R1INT_ENA
10889 | HC_R2INT_ENA
| HC_LAINT_ENA
| HC_ERINT_ENA
),
10891 writel((phba
->ha_copy
& ~(HA_LATT
| HA_ERATT
)), phba
->HAregaddr
);
10892 writel(hc_copy
, phba
->HCregaddr
);
10893 readl(phba
->HAregaddr
); /* flush */
10894 spin_unlock(&phba
->hbalock
);
10897 * Invokes slow-path host attention interrupt handling as appropriate.
10900 /* status of events with mailbox and link attention */
10901 status1
= phba
->ha_copy
& (HA_MBATT
| HA_LATT
| HA_ERATT
);
10903 /* status of events with ELS ring */
10904 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
10905 status2
>>= (4*LPFC_ELS_RING
);
10907 if (status1
|| (status2
& HA_RXMASK
))
10908 sp_irq_rc
= lpfc_sli_sp_intr_handler(irq
, dev_id
);
10910 sp_irq_rc
= IRQ_NONE
;
10913 * Invoke fast-path host attention interrupt handling as appropriate.
10916 /* status of events with FCP ring */
10917 status1
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_FCP_RING
)));
10918 status1
>>= (4*LPFC_FCP_RING
);
10920 /* status of events with extra ring */
10921 if (phba
->cfg_multi_ring_support
== 2) {
10922 status2
= (phba
->ha_copy
& (HA_RXMASK
<< (4*LPFC_EXTRA_RING
)));
10923 status2
>>= (4*LPFC_EXTRA_RING
);
10927 if ((status1
& HA_RXMASK
) || (status2
& HA_RXMASK
))
10928 fp_irq_rc
= lpfc_sli_fp_intr_handler(irq
, dev_id
);
10930 fp_irq_rc
= IRQ_NONE
;
10932 /* Return device-level interrupt handling status */
10933 return (sp_irq_rc
== IRQ_HANDLED
) ? sp_irq_rc
: fp_irq_rc
;
10934 } /* lpfc_sli_intr_handler */
10937 * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event
10938 * @phba: pointer to lpfc hba data structure.
10940 * This routine is invoked by the worker thread to process all the pending
10941 * SLI4 FCP abort XRI events.
10943 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba
*phba
)
10945 struct lpfc_cq_event
*cq_event
;
10947 /* First, declare the fcp xri abort event has been handled */
10948 spin_lock_irq(&phba
->hbalock
);
10949 phba
->hba_flag
&= ~FCP_XRI_ABORT_EVENT
;
10950 spin_unlock_irq(&phba
->hbalock
);
10951 /* Now, handle all the fcp xri abort events */
10952 while (!list_empty(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
)) {
10953 /* Get the first event from the head of the event queue */
10954 spin_lock_irq(&phba
->hbalock
);
10955 list_remove_head(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
10956 cq_event
, struct lpfc_cq_event
, list
);
10957 spin_unlock_irq(&phba
->hbalock
);
10958 /* Notify aborted XRI for FCP work queue */
10959 lpfc_sli4_fcp_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10960 /* Free the event processed back to the free pool */
10961 lpfc_sli4_cq_event_release(phba
, cq_event
);
10966 * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
10967 * @phba: pointer to lpfc hba data structure.
10969 * This routine is invoked by the worker thread to process all the pending
10970 * SLI4 els abort xri events.
10972 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba
*phba
)
10974 struct lpfc_cq_event
*cq_event
;
10976 /* First, declare the els xri abort event has been handled */
10977 spin_lock_irq(&phba
->hbalock
);
10978 phba
->hba_flag
&= ~ELS_XRI_ABORT_EVENT
;
10979 spin_unlock_irq(&phba
->hbalock
);
10980 /* Now, handle all the els xri abort events */
10981 while (!list_empty(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
)) {
10982 /* Get the first event from the head of the event queue */
10983 spin_lock_irq(&phba
->hbalock
);
10984 list_remove_head(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
10985 cq_event
, struct lpfc_cq_event
, list
);
10986 spin_unlock_irq(&phba
->hbalock
);
10987 /* Notify aborted XRI for ELS work queue */
10988 lpfc_sli4_els_xri_aborted(phba
, &cq_event
->cqe
.wcqe_axri
);
10989 /* Free the event processed back to the free pool */
10990 lpfc_sli4_cq_event_release(phba
, cq_event
);
10995 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
10996 * @phba: pointer to lpfc hba data structure
10997 * @pIocbIn: pointer to the rspiocbq
10998 * @pIocbOut: pointer to the cmdiocbq
10999 * @wcqe: pointer to the complete wcqe
11001 * This routine transfers the fields of a command iocbq to a response iocbq
11002 * by copying all the IOCB fields from command iocbq and transferring the
11003 * completion status information from the complete wcqe.
11006 lpfc_sli4_iocb_param_transfer(struct lpfc_hba
*phba
,
11007 struct lpfc_iocbq
*pIocbIn
,
11008 struct lpfc_iocbq
*pIocbOut
,
11009 struct lpfc_wcqe_complete
*wcqe
)
11011 unsigned long iflags
;
11013 size_t offset
= offsetof(struct lpfc_iocbq
, iocb
);
11015 memcpy((char *)pIocbIn
+ offset
, (char *)pIocbOut
+ offset
,
11016 sizeof(struct lpfc_iocbq
) - offset
);
11017 /* Map WCQE parameters into irspiocb parameters */
11018 status
= bf_get(lpfc_wcqe_c_status
, wcqe
);
11019 pIocbIn
->iocb
.ulpStatus
= (status
& LPFC_IOCB_STATUS_MASK
);
11020 if (pIocbOut
->iocb_flag
& LPFC_IO_FCP
)
11021 if (pIocbIn
->iocb
.ulpStatus
== IOSTAT_FCP_RSP_ERROR
)
11022 pIocbIn
->iocb
.un
.fcpi
.fcpi_parm
=
11023 pIocbOut
->iocb
.un
.fcpi
.fcpi_parm
-
11024 wcqe
->total_data_placed
;
11026 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11028 pIocbIn
->iocb
.un
.ulpWord
[4] = wcqe
->parameter
;
11029 pIocbIn
->iocb
.un
.genreq64
.bdl
.bdeSize
= wcqe
->total_data_placed
;
11032 /* Convert BG errors for completion status */
11033 if (status
== CQE_STATUS_DI_ERROR
) {
11034 pIocbIn
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
11036 if (bf_get(lpfc_wcqe_c_bg_edir
, wcqe
))
11037 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_RX_DMA_FAILED
;
11039 pIocbIn
->iocb
.un
.ulpWord
[4] = IOERR_TX_DMA_FAILED
;
11041 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
= 0;
11042 if (bf_get(lpfc_wcqe_c_bg_ge
, wcqe
)) /* Guard Check failed */
11043 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11044 BGS_GUARD_ERR_MASK
;
11045 if (bf_get(lpfc_wcqe_c_bg_ae
, wcqe
)) /* App Tag Check failed */
11046 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11047 BGS_APPTAG_ERR_MASK
;
11048 if (bf_get(lpfc_wcqe_c_bg_re
, wcqe
)) /* Ref Tag Check failed */
11049 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11050 BGS_REFTAG_ERR_MASK
;
11052 /* Check to see if there was any good data before the error */
11053 if (bf_get(lpfc_wcqe_c_bg_tdpv
, wcqe
)) {
11054 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11055 BGS_HI_WATER_MARK_PRESENT_MASK
;
11056 pIocbIn
->iocb
.unsli3
.sli3_bg
.bghm
=
11057 wcqe
->total_data_placed
;
11061 * Set ALL the error bits to indicate we don't know what
11062 * type of error it is.
11064 if (!pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
)
11065 pIocbIn
->iocb
.unsli3
.sli3_bg
.bgstat
|=
11066 (BGS_REFTAG_ERR_MASK
| BGS_APPTAG_ERR_MASK
|
11067 BGS_GUARD_ERR_MASK
);
11070 /* Pick up HBA exchange busy condition */
11071 if (bf_get(lpfc_wcqe_c_xb
, wcqe
)) {
11072 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11073 pIocbIn
->iocb_flag
|= LPFC_EXCHANGE_BUSY
;
11074 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11079 * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe
11080 * @phba: Pointer to HBA context object.
11081 * @wcqe: Pointer to work-queue completion queue entry.
11083 * This routine handles an ELS work-queue completion event and construct
11084 * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common
11085 * discovery engine to handle.
11087 * Return: Pointer to the receive IOCBQ, NULL otherwise.
11089 static struct lpfc_iocbq
*
11090 lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba
*phba
,
11091 struct lpfc_iocbq
*irspiocbq
)
11093 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
11094 struct lpfc_iocbq
*cmdiocbq
;
11095 struct lpfc_wcqe_complete
*wcqe
;
11096 unsigned long iflags
;
11098 wcqe
= &irspiocbq
->cq_event
.cqe
.wcqe_cmpl
;
11099 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11100 pring
->stats
.iocb_event
++;
11101 /* Look up the ELS command IOCB and create pseudo response IOCB */
11102 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11103 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11104 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11106 if (unlikely(!cmdiocbq
)) {
11107 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11108 "0386 ELS complete with no corresponding "
11109 "cmdiocb: iotag (%d)\n",
11110 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11111 lpfc_sli_release_iocbq(phba
, irspiocbq
);
11115 /* Fake the irspiocbq and copy necessary response information */
11116 lpfc_sli4_iocb_param_transfer(phba
, irspiocbq
, cmdiocbq
, wcqe
);
11122 * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event
11123 * @phba: Pointer to HBA context object.
11124 * @cqe: Pointer to mailbox completion queue entry.
11126 * This routine process a mailbox completion queue entry with asynchrous
11129 * Return: true if work posted to worker thread, otherwise false.
11132 lpfc_sli4_sp_handle_async_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11134 struct lpfc_cq_event
*cq_event
;
11135 unsigned long iflags
;
11137 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
11138 "0392 Async Event: word0:x%x, word1:x%x, "
11139 "word2:x%x, word3:x%x\n", mcqe
->word0
,
11140 mcqe
->mcqe_tag0
, mcqe
->mcqe_tag1
, mcqe
->trailer
);
11142 /* Allocate a new internal CQ_EVENT entry */
11143 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11145 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11146 "0394 Failed to allocate CQ_EVENT entry\n");
11150 /* Move the CQE into an asynchronous event entry */
11151 memcpy(&cq_event
->cqe
, mcqe
, sizeof(struct lpfc_mcqe
));
11152 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11153 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_asynce_work_queue
);
11154 /* Set the async event flag */
11155 phba
->hba_flag
|= ASYNC_EVENT
;
11156 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11162 * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
11163 * @phba: Pointer to HBA context object.
11164 * @cqe: Pointer to mailbox completion queue entry.
11166 * This routine process a mailbox completion queue entry with mailbox
11167 * completion event.
11169 * Return: true if work posted to worker thread, otherwise false.
11172 lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba
*phba
, struct lpfc_mcqe
*mcqe
)
11174 uint32_t mcqe_status
;
11175 MAILBOX_t
*mbox
, *pmbox
;
11176 struct lpfc_mqe
*mqe
;
11177 struct lpfc_vport
*vport
;
11178 struct lpfc_nodelist
*ndlp
;
11179 struct lpfc_dmabuf
*mp
;
11180 unsigned long iflags
;
11182 bool workposted
= false;
11185 /* If not a mailbox complete MCQE, out by checking mailbox consume */
11186 if (!bf_get(lpfc_trailer_completed
, mcqe
))
11187 goto out_no_mqe_complete
;
11189 /* Get the reference to the active mbox command */
11190 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11191 pmb
= phba
->sli
.mbox_active
;
11192 if (unlikely(!pmb
)) {
11193 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
11194 "1832 No pending MBOX command to handle\n");
11195 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11196 goto out_no_mqe_complete
;
11198 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11200 pmbox
= (MAILBOX_t
*)&pmb
->u
.mqe
;
11202 vport
= pmb
->vport
;
11204 /* Reset heartbeat timer */
11205 phba
->last_completion_time
= jiffies
;
11206 del_timer(&phba
->sli
.mbox_tmo
);
11208 /* Move mbox data to caller's mailbox region, do endian swapping */
11209 if (pmb
->mbox_cmpl
&& mbox
)
11210 lpfc_sli_pcimem_bcopy(mbox
, mqe
, sizeof(struct lpfc_mqe
));
11213 * For mcqe errors, conditionally move a modified error code to
11214 * the mbox so that the error will not be missed.
11216 mcqe_status
= bf_get(lpfc_mcqe_status
, mcqe
);
11217 if (mcqe_status
!= MB_CQE_STATUS_SUCCESS
) {
11218 if (bf_get(lpfc_mqe_status
, mqe
) == MBX_SUCCESS
)
11219 bf_set(lpfc_mqe_status
, mqe
,
11220 (LPFC_MBX_ERROR_RANGE
| mcqe_status
));
11222 if (pmb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) {
11223 pmb
->mbox_flag
&= ~LPFC_MBX_IMED_UNREG
;
11224 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_MBOX_VPORT
,
11225 "MBOX dflt rpi: status:x%x rpi:x%x",
11227 pmbox
->un
.varWords
[0], 0);
11228 if (mcqe_status
== MB_CQE_STATUS_SUCCESS
) {
11229 mp
= (struct lpfc_dmabuf
*)(pmb
->context1
);
11230 ndlp
= (struct lpfc_nodelist
*)pmb
->context2
;
11231 /* Reg_LOGIN of dflt RPI was successful. Now lets get
11232 * RID of the PPI using the same mbox buffer.
11234 lpfc_unreg_login(phba
, vport
->vpi
,
11235 pmbox
->un
.varWords
[0], pmb
);
11236 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
11237 pmb
->context1
= mp
;
11238 pmb
->context2
= ndlp
;
11239 pmb
->vport
= vport
;
11240 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
11241 if (rc
!= MBX_BUSY
)
11242 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
|
11243 LOG_SLI
, "0385 rc should "
11244 "have been MBX_BUSY\n");
11245 if (rc
!= MBX_NOT_FINISHED
)
11246 goto send_current_mbox
;
11249 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11250 phba
->pport
->work_port_events
&= ~WORKER_MBOX_TMO
;
11251 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11253 /* There is mailbox completion work to do */
11254 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11255 __lpfc_mbox_cmpl_put(phba
, pmb
);
11256 phba
->work_ha
|= HA_MBATT
;
11257 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11261 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11262 /* Release the mailbox command posting token */
11263 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
11264 /* Setting active mailbox pointer need to be in sync to flag clear */
11265 phba
->sli
.mbox_active
= NULL
;
11266 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11267 /* Wake up worker thread to post the next pending mailbox command */
11268 lpfc_worker_wake_up(phba
);
11269 out_no_mqe_complete
:
11270 if (bf_get(lpfc_trailer_consumed
, mcqe
))
11271 lpfc_sli4_mq_release(phba
->sli4_hba
.mbx_wq
);
11276 * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
11277 * @phba: Pointer to HBA context object.
11278 * @cqe: Pointer to mailbox completion queue entry.
11280 * This routine process a mailbox completion queue entry, it invokes the
11281 * proper mailbox complete handling or asynchrous event handling routine
11282 * according to the MCQE's async bit.
11284 * Return: true if work posted to worker thread, otherwise false.
11287 lpfc_sli4_sp_handle_mcqe(struct lpfc_hba
*phba
, struct lpfc_cqe
*cqe
)
11289 struct lpfc_mcqe mcqe
;
11292 /* Copy the mailbox MCQE and convert endian order as needed */
11293 lpfc_sli_pcimem_bcopy(cqe
, &mcqe
, sizeof(struct lpfc_mcqe
));
11295 /* Invoke the proper event handling routine */
11296 if (!bf_get(lpfc_trailer_async
, &mcqe
))
11297 workposted
= lpfc_sli4_sp_handle_mbox_event(phba
, &mcqe
);
11299 workposted
= lpfc_sli4_sp_handle_async_event(phba
, &mcqe
);
11304 * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
11305 * @phba: Pointer to HBA context object.
11306 * @cq: Pointer to associated CQ
11307 * @wcqe: Pointer to work-queue completion queue entry.
11309 * This routine handles an ELS work-queue completion event.
11311 * Return: true if work posted to worker thread, otherwise false.
11314 lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11315 struct lpfc_wcqe_complete
*wcqe
)
11317 struct lpfc_iocbq
*irspiocbq
;
11318 unsigned long iflags
;
11319 struct lpfc_sli_ring
*pring
= cq
->pring
;
11321 int txcmplq_cnt
= 0;
11322 int fcp_txcmplq_cnt
= 0;
11324 /* Get an irspiocbq for later ELS response processing use */
11325 irspiocbq
= lpfc_sli_get_iocbq(phba
);
11327 if (!list_empty(&pring
->txq
))
11329 if (!list_empty(&pring
->txcmplq
))
11331 if (!list_empty(&phba
->sli
.ring
[LPFC_FCP_RING
].txcmplq
))
11333 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11334 "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
11335 "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n",
11336 txq_cnt
, phba
->iocb_cnt
,
11342 /* Save off the slow-path queue event for work thread to process */
11343 memcpy(&irspiocbq
->cq_event
.cqe
.wcqe_cmpl
, wcqe
, sizeof(*wcqe
));
11344 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11345 list_add_tail(&irspiocbq
->cq_event
.list
,
11346 &phba
->sli4_hba
.sp_queue_event
);
11347 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11348 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11354 * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
11355 * @phba: Pointer to HBA context object.
11356 * @wcqe: Pointer to work-queue completion queue entry.
11358 * This routine handles slow-path WQ entry comsumed event by invoking the
11359 * proper WQ release routine to the slow-path WQ.
11362 lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba
*phba
,
11363 struct lpfc_wcqe_release
*wcqe
)
11365 /* sanity check on queue memory */
11366 if (unlikely(!phba
->sli4_hba
.els_wq
))
11368 /* Check for the slow-path ELS work queue */
11369 if (bf_get(lpfc_wcqe_r_wq_id
, wcqe
) == phba
->sli4_hba
.els_wq
->queue_id
)
11370 lpfc_sli4_wq_release(phba
->sli4_hba
.els_wq
,
11371 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11373 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11374 "2579 Slow-path wqe consume event carries "
11375 "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
11376 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
),
11377 phba
->sli4_hba
.els_wq
->queue_id
);
11381 * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
11382 * @phba: Pointer to HBA context object.
11383 * @cq: Pointer to a WQ completion queue.
11384 * @wcqe: Pointer to work-queue completion queue entry.
11386 * This routine handles an XRI abort event.
11388 * Return: true if work posted to worker thread, otherwise false.
11391 lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba
*phba
,
11392 struct lpfc_queue
*cq
,
11393 struct sli4_wcqe_xri_aborted
*wcqe
)
11395 bool workposted
= false;
11396 struct lpfc_cq_event
*cq_event
;
11397 unsigned long iflags
;
11399 /* Allocate a new internal CQ_EVENT entry */
11400 cq_event
= lpfc_sli4_cq_event_alloc(phba
);
11402 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11403 "0602 Failed to allocate CQ_EVENT entry\n");
11407 /* Move the CQE into the proper xri abort event list */
11408 memcpy(&cq_event
->cqe
, wcqe
, sizeof(struct sli4_wcqe_xri_aborted
));
11409 switch (cq
->subtype
) {
11411 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11412 list_add_tail(&cq_event
->list
,
11413 &phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
11414 /* Set the fcp xri abort event flag */
11415 phba
->hba_flag
|= FCP_XRI_ABORT_EVENT
;
11416 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11420 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11421 list_add_tail(&cq_event
->list
,
11422 &phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
11423 /* Set the els xri abort event flag */
11424 phba
->hba_flag
|= ELS_XRI_ABORT_EVENT
;
11425 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11429 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11430 "0603 Invalid work queue CQE subtype (x%x)\n",
11432 workposted
= false;
11439 * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
11440 * @phba: Pointer to HBA context object.
11441 * @rcqe: Pointer to receive-queue completion queue entry.
11443 * This routine process a receive-queue completion queue entry.
11445 * Return: true if work posted to worker thread, otherwise false.
11448 lpfc_sli4_sp_handle_rcqe(struct lpfc_hba
*phba
, struct lpfc_rcqe
*rcqe
)
11450 bool workposted
= false;
11451 struct lpfc_queue
*hrq
= phba
->sli4_hba
.hdr_rq
;
11452 struct lpfc_queue
*drq
= phba
->sli4_hba
.dat_rq
;
11453 struct hbq_dmabuf
*dma_buf
;
11454 uint32_t status
, rq_id
;
11455 unsigned long iflags
;
11457 /* sanity check on queue memory */
11458 if (unlikely(!hrq
) || unlikely(!drq
))
11461 if (bf_get(lpfc_cqe_code
, rcqe
) == CQE_CODE_RECEIVE_V1
)
11462 rq_id
= bf_get(lpfc_rcqe_rq_id_v1
, rcqe
);
11464 rq_id
= bf_get(lpfc_rcqe_rq_id
, rcqe
);
11465 if (rq_id
!= hrq
->queue_id
)
11468 status
= bf_get(lpfc_rcqe_status
, rcqe
);
11470 case FC_STATUS_RQ_BUF_LEN_EXCEEDED
:
11471 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11472 "2537 Receive Frame Truncated!!\n");
11473 hrq
->RQ_buf_trunc
++;
11474 case FC_STATUS_RQ_SUCCESS
:
11475 lpfc_sli4_rq_release(hrq
, drq
);
11476 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11477 dma_buf
= lpfc_sli_hbqbuf_get(&phba
->hbqs
[0].hbq_buffer_list
);
11479 hrq
->RQ_no_buf_found
++;
11480 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11484 memcpy(&dma_buf
->cq_event
.cqe
.rcqe_cmpl
, rcqe
, sizeof(*rcqe
));
11485 /* save off the frame for the word thread to process */
11486 list_add_tail(&dma_buf
->cq_event
.list
,
11487 &phba
->sli4_hba
.sp_queue_event
);
11488 /* Frame received */
11489 phba
->hba_flag
|= HBA_SP_QUEUE_EVT
;
11490 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11493 case FC_STATUS_INSUFF_BUF_NEED_BUF
:
11494 case FC_STATUS_INSUFF_BUF_FRM_DISC
:
11495 hrq
->RQ_no_posted_buf
++;
11496 /* Post more buffers if possible */
11497 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11498 phba
->hba_flag
|= HBA_POST_RECEIVE_BUFFER
;
11499 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11508 * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
11509 * @phba: Pointer to HBA context object.
11510 * @cq: Pointer to the completion queue.
11511 * @wcqe: Pointer to a completion queue entry.
11513 * This routine process a slow-path work-queue or receive queue completion queue
11516 * Return: true if work posted to worker thread, otherwise false.
11519 lpfc_sli4_sp_handle_cqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11520 struct lpfc_cqe
*cqe
)
11522 struct lpfc_cqe cqevt
;
11523 bool workposted
= false;
11525 /* Copy the work queue CQE and convert endian order if needed */
11526 lpfc_sli_pcimem_bcopy(cqe
, &cqevt
, sizeof(struct lpfc_cqe
));
11528 /* Check and process for different type of WCQE and dispatch */
11529 switch (bf_get(lpfc_cqe_code
, &cqevt
)) {
11530 case CQE_CODE_COMPL_WQE
:
11531 /* Process the WQ/RQ complete event */
11532 phba
->last_completion_time
= jiffies
;
11533 workposted
= lpfc_sli4_sp_handle_els_wcqe(phba
, cq
,
11534 (struct lpfc_wcqe_complete
*)&cqevt
);
11536 case CQE_CODE_RELEASE_WQE
:
11537 /* Process the WQ release event */
11538 lpfc_sli4_sp_handle_rel_wcqe(phba
,
11539 (struct lpfc_wcqe_release
*)&cqevt
);
11541 case CQE_CODE_XRI_ABORTED
:
11542 /* Process the WQ XRI abort event */
11543 phba
->last_completion_time
= jiffies
;
11544 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11545 (struct sli4_wcqe_xri_aborted
*)&cqevt
);
11547 case CQE_CODE_RECEIVE
:
11548 case CQE_CODE_RECEIVE_V1
:
11549 /* Process the RQ event */
11550 phba
->last_completion_time
= jiffies
;
11551 workposted
= lpfc_sli4_sp_handle_rcqe(phba
,
11552 (struct lpfc_rcqe
*)&cqevt
);
11555 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11556 "0388 Not a valid WCQE code: x%x\n",
11557 bf_get(lpfc_cqe_code
, &cqevt
));
11564 * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
11565 * @phba: Pointer to HBA context object.
11566 * @eqe: Pointer to fast-path event queue entry.
11568 * This routine process a event queue entry from the slow-path event queue.
11569 * It will check the MajorCode and MinorCode to determine this is for a
11570 * completion event on a completion queue, if not, an error shall be logged
11571 * and just return. Otherwise, it will get to the corresponding completion
11572 * queue and process all the entries on that completion queue, rearm the
11573 * completion queue, and then return.
11577 lpfc_sli4_sp_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11578 struct lpfc_queue
*speq
)
11580 struct lpfc_queue
*cq
= NULL
, *childq
;
11581 struct lpfc_cqe
*cqe
;
11582 bool workposted
= false;
11586 /* Get the reference to the corresponding CQ */
11587 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11589 list_for_each_entry(childq
, &speq
->child_list
, list
) {
11590 if (childq
->queue_id
== cqid
) {
11595 if (unlikely(!cq
)) {
11596 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11597 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11598 "0365 Slow-path CQ identifier "
11599 "(%d) does not exist\n", cqid
);
11603 /* Process all the entries to the CQ */
11604 switch (cq
->type
) {
11606 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11607 workposted
|= lpfc_sli4_sp_handle_mcqe(phba
, cqe
);
11608 if (!(++ecount
% cq
->entry_repost
))
11609 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11614 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11615 if (cq
->subtype
== LPFC_FCP
)
11616 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
,
11619 workposted
|= lpfc_sli4_sp_handle_cqe(phba
, cq
,
11621 if (!(++ecount
% cq
->entry_repost
))
11622 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11625 /* Track the max number of CQEs processed in 1 EQ */
11626 if (ecount
> cq
->CQ_max_cqe
)
11627 cq
->CQ_max_cqe
= ecount
;
11630 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11631 "0370 Invalid completion queue type (%d)\n",
11636 /* Catch the no cq entry condition, log an error */
11637 if (unlikely(ecount
== 0))
11638 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11639 "0371 No entry from the CQ: identifier "
11640 "(x%x), type (%d)\n", cq
->queue_id
, cq
->type
);
11642 /* In any case, flash and re-arm the RCQ */
11643 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11645 /* wake up worker thread if there are works to be done */
11647 lpfc_worker_wake_up(phba
);
11651 * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
11652 * @phba: Pointer to HBA context object.
11653 * @cq: Pointer to associated CQ
11654 * @wcqe: Pointer to work-queue completion queue entry.
11656 * This routine process a fast-path work queue completion entry from fast-path
11657 * event queue for FCP command response completion.
11660 lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11661 struct lpfc_wcqe_complete
*wcqe
)
11663 struct lpfc_sli_ring
*pring
= cq
->pring
;
11664 struct lpfc_iocbq
*cmdiocbq
;
11665 struct lpfc_iocbq irspiocbq
;
11666 unsigned long iflags
;
11668 /* Check for response status */
11669 if (unlikely(bf_get(lpfc_wcqe_c_status
, wcqe
))) {
11670 /* If resource errors reported from HBA, reduce queue
11671 * depth of the SCSI device.
11673 if (((bf_get(lpfc_wcqe_c_status
, wcqe
) ==
11674 IOSTAT_LOCAL_REJECT
)) &&
11675 ((wcqe
->parameter
& IOERR_PARAM_MASK
) ==
11676 IOERR_NO_RESOURCES
))
11677 phba
->lpfc_rampdown_queue_depth(phba
);
11679 /* Log the error status */
11680 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11681 "0373 FCP complete error: status=x%x, "
11682 "hw_status=x%x, total_data_specified=%d, "
11683 "parameter=x%x, word3=x%x\n",
11684 bf_get(lpfc_wcqe_c_status
, wcqe
),
11685 bf_get(lpfc_wcqe_c_hw_status
, wcqe
),
11686 wcqe
->total_data_placed
, wcqe
->parameter
,
11690 /* Look up the FCP command IOCB and create pseudo response IOCB */
11691 spin_lock_irqsave(&pring
->ring_lock
, iflags
);
11692 pring
->stats
.iocb_event
++;
11693 cmdiocbq
= lpfc_sli_iocbq_lookup_by_tag(phba
, pring
,
11694 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11695 spin_unlock_irqrestore(&pring
->ring_lock
, iflags
);
11696 if (unlikely(!cmdiocbq
)) {
11697 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11698 "0374 FCP complete with no corresponding "
11699 "cmdiocb: iotag (%d)\n",
11700 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11703 if (unlikely(!cmdiocbq
->iocb_cmpl
)) {
11704 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11705 "0375 FCP cmdiocb not callback function "
11707 bf_get(lpfc_wcqe_c_request_tag
, wcqe
));
11711 /* Fake the irspiocb and copy necessary response information */
11712 lpfc_sli4_iocb_param_transfer(phba
, &irspiocbq
, cmdiocbq
, wcqe
);
11714 if (cmdiocbq
->iocb_flag
& LPFC_DRIVER_ABORTED
) {
11715 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11716 cmdiocbq
->iocb_flag
&= ~LPFC_DRIVER_ABORTED
;
11717 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11720 /* Pass the cmd_iocb and the rsp state to the upper layer */
11721 (cmdiocbq
->iocb_cmpl
)(phba
, cmdiocbq
, &irspiocbq
);
11725 * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
11726 * @phba: Pointer to HBA context object.
11727 * @cq: Pointer to completion queue.
11728 * @wcqe: Pointer to work-queue completion queue entry.
11730 * This routine handles an fast-path WQ entry comsumed event by invoking the
11731 * proper WQ release routine to the slow-path WQ.
11734 lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11735 struct lpfc_wcqe_release
*wcqe
)
11737 struct lpfc_queue
*childwq
;
11738 bool wqid_matched
= false;
11741 /* Check for fast-path FCP work queue release */
11742 fcp_wqid
= bf_get(lpfc_wcqe_r_wq_id
, wcqe
);
11743 list_for_each_entry(childwq
, &cq
->child_list
, list
) {
11744 if (childwq
->queue_id
== fcp_wqid
) {
11745 lpfc_sli4_wq_release(childwq
,
11746 bf_get(lpfc_wcqe_r_wqe_index
, wcqe
));
11747 wqid_matched
= true;
11751 /* Report warning log message if no match found */
11752 if (wqid_matched
!= true)
11753 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11754 "2580 Fast-path wqe consume event carries "
11755 "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid
);
11759 * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry
11760 * @cq: Pointer to the completion queue.
11761 * @eqe: Pointer to fast-path completion queue entry.
11763 * This routine process a fast-path work queue completion entry from fast-path
11764 * event queue for FCP command response completion.
11767 lpfc_sli4_fp_handle_wcqe(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
11768 struct lpfc_cqe
*cqe
)
11770 struct lpfc_wcqe_release wcqe
;
11771 bool workposted
= false;
11773 /* Copy the work queue CQE and convert endian order if needed */
11774 lpfc_sli_pcimem_bcopy(cqe
, &wcqe
, sizeof(struct lpfc_cqe
));
11776 /* Check and process for different type of WCQE and dispatch */
11777 switch (bf_get(lpfc_wcqe_c_code
, &wcqe
)) {
11778 case CQE_CODE_COMPL_WQE
:
11780 /* Process the WQ complete event */
11781 phba
->last_completion_time
= jiffies
;
11782 lpfc_sli4_fp_handle_fcp_wcqe(phba
, cq
,
11783 (struct lpfc_wcqe_complete
*)&wcqe
);
11785 case CQE_CODE_RELEASE_WQE
:
11786 cq
->CQ_release_wqe
++;
11787 /* Process the WQ release event */
11788 lpfc_sli4_fp_handle_rel_wcqe(phba
, cq
,
11789 (struct lpfc_wcqe_release
*)&wcqe
);
11791 case CQE_CODE_XRI_ABORTED
:
11792 cq
->CQ_xri_aborted
++;
11793 /* Process the WQ XRI abort event */
11794 phba
->last_completion_time
= jiffies
;
11795 workposted
= lpfc_sli4_sp_handle_abort_xri_wcqe(phba
, cq
,
11796 (struct sli4_wcqe_xri_aborted
*)&wcqe
);
11799 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11800 "0144 Not a valid WCQE code: x%x\n",
11801 bf_get(lpfc_wcqe_c_code
, &wcqe
));
11808 * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
11809 * @phba: Pointer to HBA context object.
11810 * @eqe: Pointer to fast-path event queue entry.
11812 * This routine process a event queue entry from the fast-path event queue.
11813 * It will check the MajorCode and MinorCode to determine this is for a
11814 * completion event on a completion queue, if not, an error shall be logged
11815 * and just return. Otherwise, it will get to the corresponding completion
11816 * queue and process all the entries on the completion queue, rearm the
11817 * completion queue, and then return.
11820 lpfc_sli4_hba_handle_eqe(struct lpfc_hba
*phba
, struct lpfc_eqe
*eqe
,
11823 struct lpfc_queue
*cq
;
11824 struct lpfc_cqe
*cqe
;
11825 bool workposted
= false;
11829 if (unlikely(bf_get_le32(lpfc_eqe_major_code
, eqe
) != 0)) {
11830 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11831 "0366 Not a valid completion "
11832 "event: majorcode=x%x, minorcode=x%x\n",
11833 bf_get_le32(lpfc_eqe_major_code
, eqe
),
11834 bf_get_le32(lpfc_eqe_minor_code
, eqe
));
11838 /* Get the reference to the corresponding CQ */
11839 cqid
= bf_get_le32(lpfc_eqe_resource_id
, eqe
);
11841 /* Check if this is a Slow path event */
11842 if (unlikely(cqid
!= phba
->sli4_hba
.fcp_cq_map
[qidx
])) {
11843 lpfc_sli4_sp_handle_eqe(phba
, eqe
,
11844 phba
->sli4_hba
.hba_eq
[qidx
]);
11848 if (unlikely(!phba
->sli4_hba
.fcp_cq
)) {
11849 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
11850 "3146 Fast-path completion queues "
11851 "does not exist\n");
11854 cq
= phba
->sli4_hba
.fcp_cq
[qidx
];
11855 if (unlikely(!cq
)) {
11856 if (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)
11857 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11858 "0367 Fast-path completion queue "
11859 "(%d) does not exist\n", qidx
);
11863 if (unlikely(cqid
!= cq
->queue_id
)) {
11864 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11865 "0368 Miss-matched fast-path completion "
11866 "queue identifier: eqcqid=%d, fcpcqid=%d\n",
11867 cqid
, cq
->queue_id
);
11871 /* Process all the entries to the CQ */
11872 while ((cqe
= lpfc_sli4_cq_get(cq
))) {
11873 workposted
|= lpfc_sli4_fp_handle_wcqe(phba
, cq
, cqe
);
11874 if (!(++ecount
% cq
->entry_repost
))
11875 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_NOARM
);
11878 /* Track the max number of CQEs processed in 1 EQ */
11879 if (ecount
> cq
->CQ_max_cqe
)
11880 cq
->CQ_max_cqe
= ecount
;
11882 /* Catch the no cq entry condition */
11883 if (unlikely(ecount
== 0))
11884 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
11885 "0369 No entry from fast-path completion "
11886 "queue fcpcqid=%d\n", cq
->queue_id
);
11888 /* In any case, flash and re-arm the CQ */
11889 lpfc_sli4_cq_release(cq
, LPFC_QUEUE_REARM
);
11891 /* wake up worker thread if there are works to be done */
11893 lpfc_worker_wake_up(phba
);
11897 lpfc_sli4_eq_flush(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
11899 struct lpfc_eqe
*eqe
;
11901 /* walk all the EQ entries and drop on the floor */
11902 while ((eqe
= lpfc_sli4_eq_get(eq
)))
11905 /* Clear and re-arm the EQ */
11906 lpfc_sli4_eq_release(eq
, LPFC_QUEUE_REARM
);
11910 * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
11911 * @irq: Interrupt number.
11912 * @dev_id: The device context pointer.
11914 * This function is directly called from the PCI layer as an interrupt
11915 * service routine when device with SLI-4 interface spec is enabled with
11916 * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
11917 * ring event in the HBA. However, when the device is enabled with either
11918 * MSI or Pin-IRQ interrupt mode, this function is called as part of the
11919 * device-level interrupt handler. When the PCI slot is in error recovery
11920 * or the HBA is undergoing initialization, the interrupt handler will not
11921 * process the interrupt. The SCSI FCP fast-path ring event are handled in
11922 * the intrrupt context. This function is called without any lock held.
11923 * It gets the hbalock to access and update SLI data structures. Note that,
11924 * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
11925 * equal to that of FCP CQ index.
11927 * The link attention and ELS ring attention events are handled
11928 * by the worker thread. The interrupt handler signals the worker thread
11929 * and returns for these events. This function is called without any lock
11930 * held. It gets the hbalock to access and update SLI data structures.
11932 * This function returns IRQ_HANDLED when interrupt is handled else it
11933 * returns IRQ_NONE.
11936 lpfc_sli4_hba_intr_handler(int irq
, void *dev_id
)
11938 struct lpfc_hba
*phba
;
11939 struct lpfc_fcp_eq_hdl
*fcp_eq_hdl
;
11940 struct lpfc_queue
*fpeq
;
11941 struct lpfc_eqe
*eqe
;
11942 unsigned long iflag
;
11946 /* Get the driver's phba structure from the dev_id */
11947 fcp_eq_hdl
= (struct lpfc_fcp_eq_hdl
*)dev_id
;
11948 phba
= fcp_eq_hdl
->phba
;
11949 fcp_eqidx
= fcp_eq_hdl
->idx
;
11951 if (unlikely(!phba
))
11953 if (unlikely(!phba
->sli4_hba
.hba_eq
))
11956 /* Get to the EQ struct associated with this vector */
11957 fpeq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
11958 if (unlikely(!fpeq
))
11961 if (lpfc_fcp_look_ahead
) {
11962 if (atomic_dec_and_test(&fcp_eq_hdl
->fcp_eq_in_use
))
11963 lpfc_sli4_eq_clr_intr(fpeq
);
11965 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
11970 /* Check device state for handling interrupt */
11971 if (unlikely(lpfc_intr_state_check(phba
))) {
11972 fpeq
->EQ_badstate
++;
11973 /* Check again for link_state with lock held */
11974 spin_lock_irqsave(&phba
->hbalock
, iflag
);
11975 if (phba
->link_state
< LPFC_LINK_DOWN
)
11976 /* Flush, clear interrupt, and rearm the EQ */
11977 lpfc_sli4_eq_flush(phba
, fpeq
);
11978 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
11979 if (lpfc_fcp_look_ahead
)
11980 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
11985 * Process all the event on FCP fast-path EQ
11987 while ((eqe
= lpfc_sli4_eq_get(fpeq
))) {
11988 lpfc_sli4_hba_handle_eqe(phba
, eqe
, fcp_eqidx
);
11989 if (!(++ecount
% fpeq
->entry_repost
))
11990 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_NOARM
);
11991 fpeq
->EQ_processed
++;
11994 /* Track the max number of EQEs processed in 1 intr */
11995 if (ecount
> fpeq
->EQ_max_eqe
)
11996 fpeq
->EQ_max_eqe
= ecount
;
11998 /* Always clear and re-arm the fast-path EQ */
11999 lpfc_sli4_eq_release(fpeq
, LPFC_QUEUE_REARM
);
12001 if (unlikely(ecount
== 0)) {
12002 fpeq
->EQ_no_entry
++;
12004 if (lpfc_fcp_look_ahead
) {
12005 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12009 if (phba
->intr_type
== MSIX
)
12010 /* MSI-X treated interrupt served as no EQ share INT */
12011 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
12012 "0358 MSI-X interrupt with no EQE\n");
12014 /* Non MSI-X treated on interrupt as EQ share INT */
12018 if (lpfc_fcp_look_ahead
)
12019 atomic_inc(&fcp_eq_hdl
->fcp_eq_in_use
);
12020 return IRQ_HANDLED
;
12021 } /* lpfc_sli4_fp_intr_handler */
12024 * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
12025 * @irq: Interrupt number.
12026 * @dev_id: The device context pointer.
12028 * This function is the device-level interrupt handler to device with SLI-4
12029 * interface spec, called from the PCI layer when either MSI or Pin-IRQ
12030 * interrupt mode is enabled and there is an event in the HBA which requires
12031 * driver attention. This function invokes the slow-path interrupt attention
12032 * handling function and fast-path interrupt attention handling function in
12033 * turn to process the relevant HBA attention events. This function is called
12034 * without any lock held. It gets the hbalock to access and update SLI data
12037 * This function returns IRQ_HANDLED when interrupt is handled, else it
12038 * returns IRQ_NONE.
12041 lpfc_sli4_intr_handler(int irq
, void *dev_id
)
12043 struct lpfc_hba
*phba
;
12044 irqreturn_t hba_irq_rc
;
12045 bool hba_handled
= false;
12048 /* Get the driver's phba structure from the dev_id */
12049 phba
= (struct lpfc_hba
*)dev_id
;
12051 if (unlikely(!phba
))
12055 * Invoke fast-path host attention interrupt handling as appropriate.
12057 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
12058 hba_irq_rc
= lpfc_sli4_hba_intr_handler(irq
,
12059 &phba
->sli4_hba
.fcp_eq_hdl
[fcp_eqidx
]);
12060 if (hba_irq_rc
== IRQ_HANDLED
)
12061 hba_handled
|= true;
12064 return (hba_handled
== true) ? IRQ_HANDLED
: IRQ_NONE
;
12065 } /* lpfc_sli4_intr_handler */
12068 * lpfc_sli4_queue_free - free a queue structure and associated memory
12069 * @queue: The queue structure to free.
12071 * This function frees a queue structure and the DMAable memory used for
12072 * the host resident queue. This function must be called after destroying the
12073 * queue on the HBA.
12076 lpfc_sli4_queue_free(struct lpfc_queue
*queue
)
12078 struct lpfc_dmabuf
*dmabuf
;
12083 while (!list_empty(&queue
->page_list
)) {
12084 list_remove_head(&queue
->page_list
, dmabuf
, struct lpfc_dmabuf
,
12086 dma_free_coherent(&queue
->phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
12087 dmabuf
->virt
, dmabuf
->phys
);
12095 * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
12096 * @phba: The HBA that this queue is being created on.
12097 * @entry_size: The size of each queue entry for this queue.
12098 * @entry count: The number of entries that this queue will handle.
12100 * This function allocates a queue structure and the DMAable memory used for
12101 * the host resident queue. This function must be called before creating the
12102 * queue on the HBA.
12104 struct lpfc_queue
*
12105 lpfc_sli4_queue_alloc(struct lpfc_hba
*phba
, uint32_t entry_size
,
12106 uint32_t entry_count
)
12108 struct lpfc_queue
*queue
;
12109 struct lpfc_dmabuf
*dmabuf
;
12110 int x
, total_qe_count
;
12112 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12114 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12115 hw_page_size
= SLI4_PAGE_SIZE
;
12117 queue
= kzalloc(sizeof(struct lpfc_queue
) +
12118 (sizeof(union sli4_qe
) * entry_count
), GFP_KERNEL
);
12121 queue
->page_count
= (ALIGN(entry_size
* entry_count
,
12122 hw_page_size
))/hw_page_size
;
12123 INIT_LIST_HEAD(&queue
->list
);
12124 INIT_LIST_HEAD(&queue
->page_list
);
12125 INIT_LIST_HEAD(&queue
->child_list
);
12126 for (x
= 0, total_qe_count
= 0; x
< queue
->page_count
; x
++) {
12127 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
12130 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
12131 hw_page_size
, &dmabuf
->phys
,
12133 if (!dmabuf
->virt
) {
12137 memset(dmabuf
->virt
, 0, hw_page_size
);
12138 dmabuf
->buffer_tag
= x
;
12139 list_add_tail(&dmabuf
->list
, &queue
->page_list
);
12140 /* initialize queue's entry array */
12141 dma_pointer
= dmabuf
->virt
;
12142 for (; total_qe_count
< entry_count
&&
12143 dma_pointer
< (hw_page_size
+ dmabuf
->virt
);
12144 total_qe_count
++, dma_pointer
+= entry_size
) {
12145 queue
->qe
[total_qe_count
].address
= dma_pointer
;
12148 queue
->entry_size
= entry_size
;
12149 queue
->entry_count
= entry_count
;
12152 * entry_repost is calculated based on the number of entries in the
12153 * queue. This works out except for RQs. If buffers are NOT initially
12154 * posted for every RQE, entry_repost should be adjusted accordingly.
12156 queue
->entry_repost
= (entry_count
>> 3);
12157 if (queue
->entry_repost
< LPFC_QUEUE_MIN_REPOST
)
12158 queue
->entry_repost
= LPFC_QUEUE_MIN_REPOST
;
12159 queue
->phba
= phba
;
12163 lpfc_sli4_queue_free(queue
);
12168 * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
12169 * @phba: HBA structure that indicates port to create a queue on.
12170 * @pci_barset: PCI BAR set flag.
12172 * This function shall perform iomap of the specified PCI BAR address to host
12173 * memory address if not already done so and return it. The returned host
12174 * memory address can be NULL.
12176 static void __iomem
*
12177 lpfc_dual_chute_pci_bar_map(struct lpfc_hba
*phba
, uint16_t pci_barset
)
12179 struct pci_dev
*pdev
;
12180 unsigned long bar_map
, bar_map_len
;
12185 pdev
= phba
->pcidev
;
12187 switch (pci_barset
) {
12188 case WQ_PCI_BAR_0_AND_1
:
12189 if (!phba
->pci_bar0_memmap_p
) {
12190 bar_map
= pci_resource_start(pdev
, PCI_64BIT_BAR0
);
12191 bar_map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR0
);
12192 phba
->pci_bar0_memmap_p
= ioremap(bar_map
, bar_map_len
);
12194 return phba
->pci_bar0_memmap_p
;
12195 case WQ_PCI_BAR_2_AND_3
:
12196 if (!phba
->pci_bar2_memmap_p
) {
12197 bar_map
= pci_resource_start(pdev
, PCI_64BIT_BAR2
);
12198 bar_map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR2
);
12199 phba
->pci_bar2_memmap_p
= ioremap(bar_map
, bar_map_len
);
12201 return phba
->pci_bar2_memmap_p
;
12202 case WQ_PCI_BAR_4_AND_5
:
12203 if (!phba
->pci_bar4_memmap_p
) {
12204 bar_map
= pci_resource_start(pdev
, PCI_64BIT_BAR4
);
12205 bar_map_len
= pci_resource_len(pdev
, PCI_64BIT_BAR4
);
12206 phba
->pci_bar4_memmap_p
= ioremap(bar_map
, bar_map_len
);
12208 return phba
->pci_bar4_memmap_p
;
12216 * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs
12217 * @phba: HBA structure that indicates port to create a queue on.
12218 * @startq: The starting FCP EQ to modify
12220 * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA.
12222 * The @phba struct is used to send mailbox command to HBA. The @startq
12223 * is used to get the starting FCP EQ to change.
12224 * This function is asynchronous and will wait for the mailbox
12225 * command to finish before continuing.
12227 * On success this function will return a zero. If unable to allocate enough
12228 * memory this function will return -ENOMEM. If the queue create mailbox command
12229 * fails this function will return -ENXIO.
12232 lpfc_modify_fcp_eq_delay(struct lpfc_hba
*phba
, uint16_t startq
)
12234 struct lpfc_mbx_modify_eq_delay
*eq_delay
;
12235 LPFC_MBOXQ_t
*mbox
;
12236 struct lpfc_queue
*eq
;
12237 int cnt
, rc
, length
, status
= 0;
12238 uint32_t shdr_status
, shdr_add_status
;
12241 union lpfc_sli4_cfg_shdr
*shdr
;
12244 if (startq
>= phba
->cfg_fcp_io_channel
)
12247 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12250 length
= (sizeof(struct lpfc_mbx_modify_eq_delay
) -
12251 sizeof(struct lpfc_sli4_cfg_mhdr
));
12252 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12253 LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY
,
12254 length
, LPFC_SLI4_MBX_EMBED
);
12255 eq_delay
= &mbox
->u
.mqe
.un
.eq_delay
;
12257 /* Calculate delay multiper from maximum interrupt per second */
12258 result
= phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
;
12259 if (result
> LPFC_DMULT_CONST
)
12262 dmult
= LPFC_DMULT_CONST
/result
- 1;
12265 for (fcp_eqidx
= startq
; fcp_eqidx
< phba
->cfg_fcp_io_channel
;
12267 eq
= phba
->sli4_hba
.hba_eq
[fcp_eqidx
];
12270 eq_delay
->u
.request
.eq
[cnt
].eq_id
= eq
->queue_id
;
12271 eq_delay
->u
.request
.eq
[cnt
].phase
= 0;
12272 eq_delay
->u
.request
.eq
[cnt
].delay_multi
= dmult
;
12274 if (cnt
>= LPFC_MAX_EQ_DELAY
)
12277 eq_delay
->u
.request
.num_eq
= cnt
;
12279 mbox
->vport
= phba
->pport
;
12280 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12281 mbox
->context1
= NULL
;
12282 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12283 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_delay
->header
.cfg_shdr
;
12284 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12285 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12286 if (shdr_status
|| shdr_add_status
|| rc
) {
12287 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12288 "2512 MODIFY_EQ_DELAY mailbox failed with "
12289 "status x%x add_status x%x, mbx status x%x\n",
12290 shdr_status
, shdr_add_status
, rc
);
12293 mempool_free(mbox
, phba
->mbox_mem_pool
);
12298 * lpfc_eq_create - Create an Event Queue on the HBA
12299 * @phba: HBA structure that indicates port to create a queue on.
12300 * @eq: The queue structure to use to create the event queue.
12301 * @imax: The maximum interrupt per second limit.
12303 * This function creates an event queue, as detailed in @eq, on a port,
12304 * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
12306 * The @phba struct is used to send mailbox command to HBA. The @eq struct
12307 * is used to get the entry count and entry size that are necessary to
12308 * determine the number of pages to allocate and use for this queue. This
12309 * function will send the EQ_CREATE mailbox command to the HBA to setup the
12310 * event queue. This function is asynchronous and will wait for the mailbox
12311 * command to finish before continuing.
12313 * On success this function will return a zero. If unable to allocate enough
12314 * memory this function will return -ENOMEM. If the queue create mailbox command
12315 * fails this function will return -ENXIO.
12318 lpfc_eq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
, uint32_t imax
)
12320 struct lpfc_mbx_eq_create
*eq_create
;
12321 LPFC_MBOXQ_t
*mbox
;
12322 int rc
, length
, status
= 0;
12323 struct lpfc_dmabuf
*dmabuf
;
12324 uint32_t shdr_status
, shdr_add_status
;
12325 union lpfc_sli4_cfg_shdr
*shdr
;
12327 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12329 /* sanity check on queue memory */
12332 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12333 hw_page_size
= SLI4_PAGE_SIZE
;
12335 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12338 length
= (sizeof(struct lpfc_mbx_eq_create
) -
12339 sizeof(struct lpfc_sli4_cfg_mhdr
));
12340 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12341 LPFC_MBOX_OPCODE_EQ_CREATE
,
12342 length
, LPFC_SLI4_MBX_EMBED
);
12343 eq_create
= &mbox
->u
.mqe
.un
.eq_create
;
12344 bf_set(lpfc_mbx_eq_create_num_pages
, &eq_create
->u
.request
,
12346 bf_set(lpfc_eq_context_size
, &eq_create
->u
.request
.context
,
12348 bf_set(lpfc_eq_context_valid
, &eq_create
->u
.request
.context
, 1);
12349 /* Calculate delay multiper from maximum interrupt per second */
12350 if (imax
> LPFC_DMULT_CONST
)
12353 dmult
= LPFC_DMULT_CONST
/imax
- 1;
12354 bf_set(lpfc_eq_context_delay_multi
, &eq_create
->u
.request
.context
,
12356 switch (eq
->entry_count
) {
12358 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12359 "0360 Unsupported EQ count. (%d)\n",
12361 if (eq
->entry_count
< 256)
12363 /* otherwise default to smallest count (drop through) */
12365 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12369 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12373 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12377 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12381 bf_set(lpfc_eq_context_count
, &eq_create
->u
.request
.context
,
12385 list_for_each_entry(dmabuf
, &eq
->page_list
, list
) {
12386 memset(dmabuf
->virt
, 0, hw_page_size
);
12387 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12388 putPaddrLow(dmabuf
->phys
);
12389 eq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12390 putPaddrHigh(dmabuf
->phys
);
12392 mbox
->vport
= phba
->pport
;
12393 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
12394 mbox
->context1
= NULL
;
12395 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12396 shdr
= (union lpfc_sli4_cfg_shdr
*) &eq_create
->header
.cfg_shdr
;
12397 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12398 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12399 if (shdr_status
|| shdr_add_status
|| rc
) {
12400 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12401 "2500 EQ_CREATE mailbox failed with "
12402 "status x%x add_status x%x, mbx status x%x\n",
12403 shdr_status
, shdr_add_status
, rc
);
12406 eq
->type
= LPFC_EQ
;
12407 eq
->subtype
= LPFC_NONE
;
12408 eq
->queue_id
= bf_get(lpfc_mbx_eq_create_q_id
, &eq_create
->u
.response
);
12409 if (eq
->queue_id
== 0xFFFF)
12411 eq
->host_index
= 0;
12414 mempool_free(mbox
, phba
->mbox_mem_pool
);
12419 * lpfc_cq_create - Create a Completion Queue on the HBA
12420 * @phba: HBA structure that indicates port to create a queue on.
12421 * @cq: The queue structure to use to create the completion queue.
12422 * @eq: The event queue to bind this completion queue to.
12424 * This function creates a completion queue, as detailed in @wq, on a port,
12425 * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
12427 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12428 * is used to get the entry count and entry size that are necessary to
12429 * determine the number of pages to allocate and use for this queue. The @eq
12430 * is used to indicate which event queue to bind this completion queue to. This
12431 * function will send the CQ_CREATE mailbox command to the HBA to setup the
12432 * completion queue. This function is asynchronous and will wait for the mailbox
12433 * command to finish before continuing.
12435 * On success this function will return a zero. If unable to allocate enough
12436 * memory this function will return -ENOMEM. If the queue create mailbox command
12437 * fails this function will return -ENXIO.
12440 lpfc_cq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
,
12441 struct lpfc_queue
*eq
, uint32_t type
, uint32_t subtype
)
12443 struct lpfc_mbx_cq_create
*cq_create
;
12444 struct lpfc_dmabuf
*dmabuf
;
12445 LPFC_MBOXQ_t
*mbox
;
12446 int rc
, length
, status
= 0;
12447 uint32_t shdr_status
, shdr_add_status
;
12448 union lpfc_sli4_cfg_shdr
*shdr
;
12449 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12451 /* sanity check on queue memory */
12454 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12455 hw_page_size
= SLI4_PAGE_SIZE
;
12457 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12460 length
= (sizeof(struct lpfc_mbx_cq_create
) -
12461 sizeof(struct lpfc_sli4_cfg_mhdr
));
12462 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12463 LPFC_MBOX_OPCODE_CQ_CREATE
,
12464 length
, LPFC_SLI4_MBX_EMBED
);
12465 cq_create
= &mbox
->u
.mqe
.un
.cq_create
;
12466 shdr
= (union lpfc_sli4_cfg_shdr
*) &cq_create
->header
.cfg_shdr
;
12467 bf_set(lpfc_mbx_cq_create_num_pages
, &cq_create
->u
.request
,
12469 bf_set(lpfc_cq_context_event
, &cq_create
->u
.request
.context
, 1);
12470 bf_set(lpfc_cq_context_valid
, &cq_create
->u
.request
.context
, 1);
12471 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12472 phba
->sli4_hba
.pc_sli4_params
.cqv
);
12473 if (phba
->sli4_hba
.pc_sli4_params
.cqv
== LPFC_Q_CREATE_VERSION_2
) {
12474 /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */
12475 bf_set(lpfc_mbx_cq_create_page_size
, &cq_create
->u
.request
, 1);
12476 bf_set(lpfc_cq_eq_id_2
, &cq_create
->u
.request
.context
,
12479 bf_set(lpfc_cq_eq_id
, &cq_create
->u
.request
.context
,
12482 switch (cq
->entry_count
) {
12484 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12485 "0361 Unsupported CQ count. (%d)\n",
12487 if (cq
->entry_count
< 256) {
12491 /* otherwise default to smallest count (drop through) */
12493 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12497 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12501 bf_set(lpfc_cq_context_count
, &cq_create
->u
.request
.context
,
12505 list_for_each_entry(dmabuf
, &cq
->page_list
, list
) {
12506 memset(dmabuf
->virt
, 0, hw_page_size
);
12507 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12508 putPaddrLow(dmabuf
->phys
);
12509 cq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12510 putPaddrHigh(dmabuf
->phys
);
12512 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12514 /* The IOCTL status is embedded in the mailbox subheader. */
12515 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12516 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12517 if (shdr_status
|| shdr_add_status
|| rc
) {
12518 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12519 "2501 CQ_CREATE mailbox failed with "
12520 "status x%x add_status x%x, mbx status x%x\n",
12521 shdr_status
, shdr_add_status
, rc
);
12525 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12526 if (cq
->queue_id
== 0xFFFF) {
12530 /* link the cq onto the parent eq child list */
12531 list_add_tail(&cq
->list
, &eq
->child_list
);
12532 /* Set up completion queue's type and subtype */
12534 cq
->subtype
= subtype
;
12535 cq
->queue_id
= bf_get(lpfc_mbx_cq_create_q_id
, &cq_create
->u
.response
);
12536 cq
->assoc_qid
= eq
->queue_id
;
12537 cq
->host_index
= 0;
12541 mempool_free(mbox
, phba
->mbox_mem_pool
);
12546 * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
12547 * @phba: HBA structure that indicates port to create a queue on.
12548 * @mq: The queue structure to use to create the mailbox queue.
12549 * @mbox: An allocated pointer to type LPFC_MBOXQ_t
12550 * @cq: The completion queue to associate with this cq.
12552 * This function provides failback (fb) functionality when the
12553 * mq_create_ext fails on older FW generations. It's purpose is identical
12554 * to mq_create_ext otherwise.
12556 * This routine cannot fail as all attributes were previously accessed and
12557 * initialized in mq_create_ext.
12560 lpfc_mq_create_fb_init(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12561 LPFC_MBOXQ_t
*mbox
, struct lpfc_queue
*cq
)
12563 struct lpfc_mbx_mq_create
*mq_create
;
12564 struct lpfc_dmabuf
*dmabuf
;
12567 length
= (sizeof(struct lpfc_mbx_mq_create
) -
12568 sizeof(struct lpfc_sli4_cfg_mhdr
));
12569 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12570 LPFC_MBOX_OPCODE_MQ_CREATE
,
12571 length
, LPFC_SLI4_MBX_EMBED
);
12572 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12573 bf_set(lpfc_mbx_mq_create_num_pages
, &mq_create
->u
.request
,
12575 bf_set(lpfc_mq_context_cq_id
, &mq_create
->u
.request
.context
,
12577 bf_set(lpfc_mq_context_valid
, &mq_create
->u
.request
.context
, 1);
12578 switch (mq
->entry_count
) {
12580 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12581 LPFC_MQ_RING_SIZE_16
);
12584 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12585 LPFC_MQ_RING_SIZE_32
);
12588 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12589 LPFC_MQ_RING_SIZE_64
);
12592 bf_set(lpfc_mq_context_ring_size
, &mq_create
->u
.request
.context
,
12593 LPFC_MQ_RING_SIZE_128
);
12596 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12597 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12598 putPaddrLow(dmabuf
->phys
);
12599 mq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12600 putPaddrHigh(dmabuf
->phys
);
12605 * lpfc_mq_create - Create a mailbox Queue on the HBA
12606 * @phba: HBA structure that indicates port to create a queue on.
12607 * @mq: The queue structure to use to create the mailbox queue.
12608 * @cq: The completion queue to associate with this cq.
12609 * @subtype: The queue's subtype.
12611 * This function creates a mailbox queue, as detailed in @mq, on a port,
12612 * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
12614 * The @phba struct is used to send mailbox command to HBA. The @cq struct
12615 * is used to get the entry count and entry size that are necessary to
12616 * determine the number of pages to allocate and use for this queue. This
12617 * function will send the MQ_CREATE mailbox command to the HBA to setup the
12618 * mailbox queue. This function is asynchronous and will wait for the mailbox
12619 * command to finish before continuing.
12621 * On success this function will return a zero. If unable to allocate enough
12622 * memory this function will return -ENOMEM. If the queue create mailbox command
12623 * fails this function will return -ENXIO.
12626 lpfc_mq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
,
12627 struct lpfc_queue
*cq
, uint32_t subtype
)
12629 struct lpfc_mbx_mq_create
*mq_create
;
12630 struct lpfc_mbx_mq_create_ext
*mq_create_ext
;
12631 struct lpfc_dmabuf
*dmabuf
;
12632 LPFC_MBOXQ_t
*mbox
;
12633 int rc
, length
, status
= 0;
12634 uint32_t shdr_status
, shdr_add_status
;
12635 union lpfc_sli4_cfg_shdr
*shdr
;
12636 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12638 /* sanity check on queue memory */
12641 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12642 hw_page_size
= SLI4_PAGE_SIZE
;
12644 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12647 length
= (sizeof(struct lpfc_mbx_mq_create_ext
) -
12648 sizeof(struct lpfc_sli4_cfg_mhdr
));
12649 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
12650 LPFC_MBOX_OPCODE_MQ_CREATE_EXT
,
12651 length
, LPFC_SLI4_MBX_EMBED
);
12653 mq_create_ext
= &mbox
->u
.mqe
.un
.mq_create_ext
;
12654 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create_ext
->header
.cfg_shdr
;
12655 bf_set(lpfc_mbx_mq_create_ext_num_pages
,
12656 &mq_create_ext
->u
.request
, mq
->page_count
);
12657 bf_set(lpfc_mbx_mq_create_ext_async_evt_link
,
12658 &mq_create_ext
->u
.request
, 1);
12659 bf_set(lpfc_mbx_mq_create_ext_async_evt_fip
,
12660 &mq_create_ext
->u
.request
, 1);
12661 bf_set(lpfc_mbx_mq_create_ext_async_evt_group5
,
12662 &mq_create_ext
->u
.request
, 1);
12663 bf_set(lpfc_mbx_mq_create_ext_async_evt_fc
,
12664 &mq_create_ext
->u
.request
, 1);
12665 bf_set(lpfc_mbx_mq_create_ext_async_evt_sli
,
12666 &mq_create_ext
->u
.request
, 1);
12667 bf_set(lpfc_mq_context_valid
, &mq_create_ext
->u
.request
.context
, 1);
12668 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12669 phba
->sli4_hba
.pc_sli4_params
.mqv
);
12670 if (phba
->sli4_hba
.pc_sli4_params
.mqv
== LPFC_Q_CREATE_VERSION_1
)
12671 bf_set(lpfc_mbx_mq_create_ext_cq_id
, &mq_create_ext
->u
.request
,
12674 bf_set(lpfc_mq_context_cq_id
, &mq_create_ext
->u
.request
.context
,
12676 switch (mq
->entry_count
) {
12678 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
12679 "0362 Unsupported MQ count. (%d)\n",
12681 if (mq
->entry_count
< 16) {
12685 /* otherwise default to smallest count (drop through) */
12687 bf_set(lpfc_mq_context_ring_size
,
12688 &mq_create_ext
->u
.request
.context
,
12689 LPFC_MQ_RING_SIZE_16
);
12692 bf_set(lpfc_mq_context_ring_size
,
12693 &mq_create_ext
->u
.request
.context
,
12694 LPFC_MQ_RING_SIZE_32
);
12697 bf_set(lpfc_mq_context_ring_size
,
12698 &mq_create_ext
->u
.request
.context
,
12699 LPFC_MQ_RING_SIZE_64
);
12702 bf_set(lpfc_mq_context_ring_size
,
12703 &mq_create_ext
->u
.request
.context
,
12704 LPFC_MQ_RING_SIZE_128
);
12707 list_for_each_entry(dmabuf
, &mq
->page_list
, list
) {
12708 memset(dmabuf
->virt
, 0, hw_page_size
);
12709 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
12710 putPaddrLow(dmabuf
->phys
);
12711 mq_create_ext
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
12712 putPaddrHigh(dmabuf
->phys
);
12714 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12715 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12716 &mq_create_ext
->u
.response
);
12717 if (rc
!= MBX_SUCCESS
) {
12718 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12719 "2795 MQ_CREATE_EXT failed with "
12720 "status x%x. Failback to MQ_CREATE.\n",
12722 lpfc_mq_create_fb_init(phba
, mq
, mbox
, cq
);
12723 mq_create
= &mbox
->u
.mqe
.un
.mq_create
;
12724 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12725 shdr
= (union lpfc_sli4_cfg_shdr
*) &mq_create
->header
.cfg_shdr
;
12726 mq
->queue_id
= bf_get(lpfc_mbx_mq_create_q_id
,
12727 &mq_create
->u
.response
);
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 "2502 MQ_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 if (mq
->queue_id
== 0xFFFF) {
12745 mq
->type
= LPFC_MQ
;
12746 mq
->assoc_qid
= cq
->queue_id
;
12747 mq
->subtype
= subtype
;
12748 mq
->host_index
= 0;
12751 /* link the mq onto the parent cq child list */
12752 list_add_tail(&mq
->list
, &cq
->child_list
);
12754 mempool_free(mbox
, phba
->mbox_mem_pool
);
12759 * lpfc_wq_create - Create a Work Queue on the HBA
12760 * @phba: HBA structure that indicates port to create a queue on.
12761 * @wq: The queue structure to use to create the work queue.
12762 * @cq: The completion queue to bind this work queue to.
12763 * @subtype: The subtype of the work queue indicating its functionality.
12765 * This function creates a work queue, as detailed in @wq, on a port, described
12766 * by @phba by sending a WQ_CREATE mailbox command to the HBA.
12768 * The @phba struct is used to send mailbox command to HBA. The @wq struct
12769 * is used to get the entry count and entry size that are necessary to
12770 * determine the number of pages to allocate and use for this queue. The @cq
12771 * is used to indicate which completion queue to bind this work queue to. This
12772 * function will send the WQ_CREATE mailbox command to the HBA to setup the
12773 * work queue. This function is asynchronous and will wait for the mailbox
12774 * command to finish before continuing.
12776 * On success this function will return a zero. If unable to allocate enough
12777 * memory this function will return -ENOMEM. If the queue create mailbox command
12778 * fails this function will return -ENXIO.
12781 lpfc_wq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
,
12782 struct lpfc_queue
*cq
, uint32_t subtype
)
12784 struct lpfc_mbx_wq_create
*wq_create
;
12785 struct lpfc_dmabuf
*dmabuf
;
12786 LPFC_MBOXQ_t
*mbox
;
12787 int rc
, length
, status
= 0;
12788 uint32_t shdr_status
, shdr_add_status
;
12789 union lpfc_sli4_cfg_shdr
*shdr
;
12790 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12791 struct dma_address
*page
;
12792 void __iomem
*bar_memmap_p
;
12793 uint32_t db_offset
;
12794 uint16_t pci_barset
;
12796 /* sanity check on queue memory */
12799 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12800 hw_page_size
= SLI4_PAGE_SIZE
;
12802 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12805 length
= (sizeof(struct lpfc_mbx_wq_create
) -
12806 sizeof(struct lpfc_sli4_cfg_mhdr
));
12807 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
12808 LPFC_MBOX_OPCODE_FCOE_WQ_CREATE
,
12809 length
, LPFC_SLI4_MBX_EMBED
);
12810 wq_create
= &mbox
->u
.mqe
.un
.wq_create
;
12811 shdr
= (union lpfc_sli4_cfg_shdr
*) &wq_create
->header
.cfg_shdr
;
12812 bf_set(lpfc_mbx_wq_create_num_pages
, &wq_create
->u
.request
,
12814 bf_set(lpfc_mbx_wq_create_cq_id
, &wq_create
->u
.request
,
12816 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
12817 phba
->sli4_hba
.pc_sli4_params
.wqv
);
12819 if (phba
->sli4_hba
.pc_sli4_params
.wqv
== LPFC_Q_CREATE_VERSION_1
) {
12820 bf_set(lpfc_mbx_wq_create_wqe_count
, &wq_create
->u
.request_1
,
12822 switch (wq
->entry_size
) {
12825 bf_set(lpfc_mbx_wq_create_wqe_size
,
12826 &wq_create
->u
.request_1
,
12827 LPFC_WQ_WQE_SIZE_64
);
12830 bf_set(lpfc_mbx_wq_create_wqe_size
,
12831 &wq_create
->u
.request_1
,
12832 LPFC_WQ_WQE_SIZE_128
);
12835 bf_set(lpfc_mbx_wq_create_page_size
, &wq_create
->u
.request_1
,
12836 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
12837 page
= wq_create
->u
.request_1
.page
;
12839 page
= wq_create
->u
.request
.page
;
12841 list_for_each_entry(dmabuf
, &wq
->page_list
, list
) {
12842 memset(dmabuf
->virt
, 0, hw_page_size
);
12843 page
[dmabuf
->buffer_tag
].addr_lo
= putPaddrLow(dmabuf
->phys
);
12844 page
[dmabuf
->buffer_tag
].addr_hi
= putPaddrHigh(dmabuf
->phys
);
12847 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
12848 bf_set(lpfc_mbx_wq_create_dua
, &wq_create
->u
.request
, 1);
12850 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
12851 /* The IOCTL status is embedded in the mailbox subheader. */
12852 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
12853 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
12854 if (shdr_status
|| shdr_add_status
|| rc
) {
12855 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12856 "2503 WQ_CREATE mailbox failed with "
12857 "status x%x add_status x%x, mbx status x%x\n",
12858 shdr_status
, shdr_add_status
, rc
);
12862 wq
->queue_id
= bf_get(lpfc_mbx_wq_create_q_id
, &wq_create
->u
.response
);
12863 if (wq
->queue_id
== 0xFFFF) {
12867 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
12868 wq
->db_format
= bf_get(lpfc_mbx_wq_create_db_format
,
12869 &wq_create
->u
.response
);
12870 if ((wq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
12871 (wq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
12872 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12873 "3265 WQ[%d] doorbell format not "
12874 "supported: x%x\n", wq
->queue_id
,
12879 pci_barset
= bf_get(lpfc_mbx_wq_create_bar_set
,
12880 &wq_create
->u
.response
);
12881 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
12882 if (!bar_memmap_p
) {
12883 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12884 "3263 WQ[%d] failed to memmap pci "
12885 "barset:x%x\n", wq
->queue_id
,
12890 db_offset
= wq_create
->u
.response
.doorbell_offset
;
12891 if ((db_offset
!= LPFC_ULP0_WQ_DOORBELL
) &&
12892 (db_offset
!= LPFC_ULP1_WQ_DOORBELL
)) {
12893 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
12894 "3252 WQ[%d] doorbell offset not "
12895 "supported: x%x\n", wq
->queue_id
,
12900 wq
->db_regaddr
= bar_memmap_p
+ db_offset
;
12901 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
12902 "3264 WQ[%d]: barset:x%x, offset:x%x\n",
12903 wq
->queue_id
, pci_barset
, db_offset
);
12905 wq
->db_format
= LPFC_DB_LIST_FORMAT
;
12906 wq
->db_regaddr
= phba
->sli4_hba
.WQDBregaddr
;
12908 wq
->type
= LPFC_WQ
;
12909 wq
->assoc_qid
= cq
->queue_id
;
12910 wq
->subtype
= subtype
;
12911 wq
->host_index
= 0;
12913 wq
->entry_repost
= LPFC_RELEASE_NOTIFICATION_INTERVAL
;
12915 /* link the wq onto the parent cq child list */
12916 list_add_tail(&wq
->list
, &cq
->child_list
);
12918 mempool_free(mbox
, phba
->mbox_mem_pool
);
12923 * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ
12924 * @phba: HBA structure that indicates port to create a queue on.
12925 * @rq: The queue structure to use for the receive queue.
12926 * @qno: The associated HBQ number
12929 * For SLI4 we need to adjust the RQ repost value based on
12930 * the number of buffers that are initially posted to the RQ.
12933 lpfc_rq_adjust_repost(struct lpfc_hba
*phba
, struct lpfc_queue
*rq
, int qno
)
12937 /* sanity check on queue memory */
12940 cnt
= lpfc_hbq_defs
[qno
]->entry_count
;
12942 /* Recalc repost for RQs based on buffers initially posted */
12944 if (cnt
< LPFC_QUEUE_MIN_REPOST
)
12945 cnt
= LPFC_QUEUE_MIN_REPOST
;
12947 rq
->entry_repost
= cnt
;
12951 * lpfc_rq_create - Create a Receive Queue on the HBA
12952 * @phba: HBA structure that indicates port to create a queue on.
12953 * @hrq: The queue structure to use to create the header receive queue.
12954 * @drq: The queue structure to use to create the data receive queue.
12955 * @cq: The completion queue to bind this work queue to.
12957 * This function creates a receive buffer queue pair , as detailed in @hrq and
12958 * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
12961 * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
12962 * struct is used to get the entry count that is necessary to determine the
12963 * number of pages to use for this queue. The @cq is used to indicate which
12964 * completion queue to bind received buffers that are posted to these queues to.
12965 * This function will send the RQ_CREATE mailbox command to the HBA to setup the
12966 * receive queue pair. This function is asynchronous and will wait for the
12967 * mailbox command to finish before continuing.
12969 * On success this function will return a zero. If unable to allocate enough
12970 * memory this function will return -ENOMEM. If the queue create mailbox command
12971 * fails this function will return -ENXIO.
12974 lpfc_rq_create(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
12975 struct lpfc_queue
*drq
, struct lpfc_queue
*cq
, uint32_t subtype
)
12977 struct lpfc_mbx_rq_create
*rq_create
;
12978 struct lpfc_dmabuf
*dmabuf
;
12979 LPFC_MBOXQ_t
*mbox
;
12980 int rc
, length
, status
= 0;
12981 uint32_t shdr_status
, shdr_add_status
;
12982 union lpfc_sli4_cfg_shdr
*shdr
;
12983 uint32_t hw_page_size
= phba
->sli4_hba
.pc_sli4_params
.if_page_sz
;
12984 void __iomem
*bar_memmap_p
;
12985 uint32_t db_offset
;
12986 uint16_t pci_barset
;
12988 /* sanity check on queue memory */
12989 if (!hrq
|| !drq
|| !cq
)
12991 if (!phba
->sli4_hba
.pc_sli4_params
.supported
)
12992 hw_page_size
= SLI4_PAGE_SIZE
;
12994 if (hrq
->entry_count
!= drq
->entry_count
)
12996 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
12999 length
= (sizeof(struct lpfc_mbx_rq_create
) -
13000 sizeof(struct lpfc_sli4_cfg_mhdr
));
13001 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13002 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
13003 length
, LPFC_SLI4_MBX_EMBED
);
13004 rq_create
= &mbox
->u
.mqe
.un
.rq_create
;
13005 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13006 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13007 phba
->sli4_hba
.pc_sli4_params
.rqv
);
13008 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
13009 bf_set(lpfc_rq_context_rqe_count_1
,
13010 &rq_create
->u
.request
.context
,
13012 rq_create
->u
.request
.context
.buffer_size
= LPFC_HDR_BUF_SIZE
;
13013 bf_set(lpfc_rq_context_rqe_size
,
13014 &rq_create
->u
.request
.context
,
13016 bf_set(lpfc_rq_context_page_size
,
13017 &rq_create
->u
.request
.context
,
13018 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13020 switch (hrq
->entry_count
) {
13022 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13023 "2535 Unsupported RQ count. (%d)\n",
13025 if (hrq
->entry_count
< 512) {
13029 /* otherwise default to smallest count (drop through) */
13031 bf_set(lpfc_rq_context_rqe_count
,
13032 &rq_create
->u
.request
.context
,
13033 LPFC_RQ_RING_SIZE_512
);
13036 bf_set(lpfc_rq_context_rqe_count
,
13037 &rq_create
->u
.request
.context
,
13038 LPFC_RQ_RING_SIZE_1024
);
13041 bf_set(lpfc_rq_context_rqe_count
,
13042 &rq_create
->u
.request
.context
,
13043 LPFC_RQ_RING_SIZE_2048
);
13046 bf_set(lpfc_rq_context_rqe_count
,
13047 &rq_create
->u
.request
.context
,
13048 LPFC_RQ_RING_SIZE_4096
);
13051 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
13052 LPFC_HDR_BUF_SIZE
);
13054 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
13056 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
13058 list_for_each_entry(dmabuf
, &hrq
->page_list
, list
) {
13059 memset(dmabuf
->virt
, 0, hw_page_size
);
13060 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13061 putPaddrLow(dmabuf
->phys
);
13062 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13063 putPaddrHigh(dmabuf
->phys
);
13065 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13066 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
13068 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13069 /* The IOCTL status is embedded in the mailbox subheader. */
13070 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13071 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13072 if (shdr_status
|| shdr_add_status
|| rc
) {
13073 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13074 "2504 RQ_CREATE mailbox failed with "
13075 "status x%x add_status x%x, mbx status x%x\n",
13076 shdr_status
, shdr_add_status
, rc
);
13080 hrq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
13081 if (hrq
->queue_id
== 0xFFFF) {
13086 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
) {
13087 hrq
->db_format
= bf_get(lpfc_mbx_rq_create_db_format
,
13088 &rq_create
->u
.response
);
13089 if ((hrq
->db_format
!= LPFC_DB_LIST_FORMAT
) &&
13090 (hrq
->db_format
!= LPFC_DB_RING_FORMAT
)) {
13091 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13092 "3262 RQ [%d] doorbell format not "
13093 "supported: x%x\n", hrq
->queue_id
,
13099 pci_barset
= bf_get(lpfc_mbx_rq_create_bar_set
,
13100 &rq_create
->u
.response
);
13101 bar_memmap_p
= lpfc_dual_chute_pci_bar_map(phba
, pci_barset
);
13102 if (!bar_memmap_p
) {
13103 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13104 "3269 RQ[%d] failed to memmap pci "
13105 "barset:x%x\n", hrq
->queue_id
,
13111 db_offset
= rq_create
->u
.response
.doorbell_offset
;
13112 if ((db_offset
!= LPFC_ULP0_RQ_DOORBELL
) &&
13113 (db_offset
!= LPFC_ULP1_RQ_DOORBELL
)) {
13114 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13115 "3270 RQ[%d] doorbell offset not "
13116 "supported: x%x\n", hrq
->queue_id
,
13121 hrq
->db_regaddr
= bar_memmap_p
+ db_offset
;
13122 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
13123 "3266 RQ[qid:%d]: barset:x%x, offset:x%x\n",
13124 hrq
->queue_id
, pci_barset
, db_offset
);
13126 hrq
->db_format
= LPFC_DB_RING_FORMAT
;
13127 hrq
->db_regaddr
= phba
->sli4_hba
.RQDBregaddr
;
13129 hrq
->type
= LPFC_HRQ
;
13130 hrq
->assoc_qid
= cq
->queue_id
;
13131 hrq
->subtype
= subtype
;
13132 hrq
->host_index
= 0;
13133 hrq
->hba_index
= 0;
13135 /* now create the data queue */
13136 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13137 LPFC_MBOX_OPCODE_FCOE_RQ_CREATE
,
13138 length
, LPFC_SLI4_MBX_EMBED
);
13139 bf_set(lpfc_mbox_hdr_version
, &shdr
->request
,
13140 phba
->sli4_hba
.pc_sli4_params
.rqv
);
13141 if (phba
->sli4_hba
.pc_sli4_params
.rqv
== LPFC_Q_CREATE_VERSION_1
) {
13142 bf_set(lpfc_rq_context_rqe_count_1
,
13143 &rq_create
->u
.request
.context
, hrq
->entry_count
);
13144 rq_create
->u
.request
.context
.buffer_size
= LPFC_DATA_BUF_SIZE
;
13145 bf_set(lpfc_rq_context_rqe_size
, &rq_create
->u
.request
.context
,
13147 bf_set(lpfc_rq_context_page_size
, &rq_create
->u
.request
.context
,
13148 (PAGE_SIZE
/SLI4_PAGE_SIZE
));
13150 switch (drq
->entry_count
) {
13152 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13153 "2536 Unsupported RQ count. (%d)\n",
13155 if (drq
->entry_count
< 512) {
13159 /* otherwise default to smallest count (drop through) */
13161 bf_set(lpfc_rq_context_rqe_count
,
13162 &rq_create
->u
.request
.context
,
13163 LPFC_RQ_RING_SIZE_512
);
13166 bf_set(lpfc_rq_context_rqe_count
,
13167 &rq_create
->u
.request
.context
,
13168 LPFC_RQ_RING_SIZE_1024
);
13171 bf_set(lpfc_rq_context_rqe_count
,
13172 &rq_create
->u
.request
.context
,
13173 LPFC_RQ_RING_SIZE_2048
);
13176 bf_set(lpfc_rq_context_rqe_count
,
13177 &rq_create
->u
.request
.context
,
13178 LPFC_RQ_RING_SIZE_4096
);
13181 bf_set(lpfc_rq_context_buf_size
, &rq_create
->u
.request
.context
,
13182 LPFC_DATA_BUF_SIZE
);
13184 bf_set(lpfc_rq_context_cq_id
, &rq_create
->u
.request
.context
,
13186 bf_set(lpfc_mbx_rq_create_num_pages
, &rq_create
->u
.request
,
13188 list_for_each_entry(dmabuf
, &drq
->page_list
, list
) {
13189 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_lo
=
13190 putPaddrLow(dmabuf
->phys
);
13191 rq_create
->u
.request
.page
[dmabuf
->buffer_tag
].addr_hi
=
13192 putPaddrHigh(dmabuf
->phys
);
13194 if (phba
->sli4_hba
.fw_func_mode
& LPFC_DUA_MODE
)
13195 bf_set(lpfc_mbx_rq_create_dua
, &rq_create
->u
.request
, 1);
13196 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13197 /* The IOCTL status is embedded in the mailbox subheader. */
13198 shdr
= (union lpfc_sli4_cfg_shdr
*) &rq_create
->header
.cfg_shdr
;
13199 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13200 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13201 if (shdr_status
|| shdr_add_status
|| rc
) {
13205 drq
->queue_id
= bf_get(lpfc_mbx_rq_create_q_id
, &rq_create
->u
.response
);
13206 if (drq
->queue_id
== 0xFFFF) {
13210 drq
->type
= LPFC_DRQ
;
13211 drq
->assoc_qid
= cq
->queue_id
;
13212 drq
->subtype
= subtype
;
13213 drq
->host_index
= 0;
13214 drq
->hba_index
= 0;
13216 /* link the header and data RQs onto the parent cq child list */
13217 list_add_tail(&hrq
->list
, &cq
->child_list
);
13218 list_add_tail(&drq
->list
, &cq
->child_list
);
13221 mempool_free(mbox
, phba
->mbox_mem_pool
);
13226 * lpfc_eq_destroy - Destroy an event Queue on the HBA
13227 * @eq: The queue structure associated with the queue to destroy.
13229 * This function destroys a queue, as detailed in @eq by sending an mailbox
13230 * command, specific to the type of queue, to the HBA.
13232 * The @eq struct is used to get the queue ID of the queue to destroy.
13234 * On success this function will return a zero. If the queue destroy mailbox
13235 * command fails this function will return -ENXIO.
13238 lpfc_eq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*eq
)
13240 LPFC_MBOXQ_t
*mbox
;
13241 int rc
, length
, status
= 0;
13242 uint32_t shdr_status
, shdr_add_status
;
13243 union lpfc_sli4_cfg_shdr
*shdr
;
13245 /* sanity check on queue memory */
13248 mbox
= mempool_alloc(eq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13251 length
= (sizeof(struct lpfc_mbx_eq_destroy
) -
13252 sizeof(struct lpfc_sli4_cfg_mhdr
));
13253 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13254 LPFC_MBOX_OPCODE_EQ_DESTROY
,
13255 length
, LPFC_SLI4_MBX_EMBED
);
13256 bf_set(lpfc_mbx_eq_destroy_q_id
, &mbox
->u
.mqe
.un
.eq_destroy
.u
.request
,
13258 mbox
->vport
= eq
->phba
->pport
;
13259 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13261 rc
= lpfc_sli_issue_mbox(eq
->phba
, mbox
, MBX_POLL
);
13262 /* The IOCTL status is embedded in the mailbox subheader. */
13263 shdr
= (union lpfc_sli4_cfg_shdr
*)
13264 &mbox
->u
.mqe
.un
.eq_destroy
.header
.cfg_shdr
;
13265 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13266 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13267 if (shdr_status
|| shdr_add_status
|| rc
) {
13268 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13269 "2505 EQ_DESTROY mailbox failed with "
13270 "status x%x add_status x%x, mbx status x%x\n",
13271 shdr_status
, shdr_add_status
, rc
);
13275 /* Remove eq from any list */
13276 list_del_init(&eq
->list
);
13277 mempool_free(mbox
, eq
->phba
->mbox_mem_pool
);
13282 * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
13283 * @cq: The queue structure associated with the queue to destroy.
13285 * This function destroys a queue, as detailed in @cq by sending an mailbox
13286 * command, specific to the type of queue, to the HBA.
13288 * The @cq struct is used to get the queue ID of the queue to destroy.
13290 * On success this function will return a zero. If the queue destroy mailbox
13291 * command fails this function will return -ENXIO.
13294 lpfc_cq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*cq
)
13296 LPFC_MBOXQ_t
*mbox
;
13297 int rc
, length
, status
= 0;
13298 uint32_t shdr_status
, shdr_add_status
;
13299 union lpfc_sli4_cfg_shdr
*shdr
;
13301 /* sanity check on queue memory */
13304 mbox
= mempool_alloc(cq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13307 length
= (sizeof(struct lpfc_mbx_cq_destroy
) -
13308 sizeof(struct lpfc_sli4_cfg_mhdr
));
13309 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13310 LPFC_MBOX_OPCODE_CQ_DESTROY
,
13311 length
, LPFC_SLI4_MBX_EMBED
);
13312 bf_set(lpfc_mbx_cq_destroy_q_id
, &mbox
->u
.mqe
.un
.cq_destroy
.u
.request
,
13314 mbox
->vport
= cq
->phba
->pport
;
13315 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13316 rc
= lpfc_sli_issue_mbox(cq
->phba
, mbox
, MBX_POLL
);
13317 /* The IOCTL status is embedded in the mailbox subheader. */
13318 shdr
= (union lpfc_sli4_cfg_shdr
*)
13319 &mbox
->u
.mqe
.un
.wq_create
.header
.cfg_shdr
;
13320 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13321 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13322 if (shdr_status
|| shdr_add_status
|| rc
) {
13323 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13324 "2506 CQ_DESTROY mailbox failed with "
13325 "status x%x add_status x%x, mbx status x%x\n",
13326 shdr_status
, shdr_add_status
, rc
);
13329 /* Remove cq from any list */
13330 list_del_init(&cq
->list
);
13331 mempool_free(mbox
, cq
->phba
->mbox_mem_pool
);
13336 * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
13337 * @qm: The queue structure associated with the queue to destroy.
13339 * This function destroys a queue, as detailed in @mq by sending an mailbox
13340 * command, specific to the type of queue, to the HBA.
13342 * The @mq struct is used to get the queue ID of the queue to destroy.
13344 * On success this function will return a zero. If the queue destroy mailbox
13345 * command fails this function will return -ENXIO.
13348 lpfc_mq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*mq
)
13350 LPFC_MBOXQ_t
*mbox
;
13351 int rc
, length
, status
= 0;
13352 uint32_t shdr_status
, shdr_add_status
;
13353 union lpfc_sli4_cfg_shdr
*shdr
;
13355 /* sanity check on queue memory */
13358 mbox
= mempool_alloc(mq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13361 length
= (sizeof(struct lpfc_mbx_mq_destroy
) -
13362 sizeof(struct lpfc_sli4_cfg_mhdr
));
13363 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
13364 LPFC_MBOX_OPCODE_MQ_DESTROY
,
13365 length
, LPFC_SLI4_MBX_EMBED
);
13366 bf_set(lpfc_mbx_mq_destroy_q_id
, &mbox
->u
.mqe
.un
.mq_destroy
.u
.request
,
13368 mbox
->vport
= mq
->phba
->pport
;
13369 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13370 rc
= lpfc_sli_issue_mbox(mq
->phba
, mbox
, MBX_POLL
);
13371 /* The IOCTL status is embedded in the mailbox subheader. */
13372 shdr
= (union lpfc_sli4_cfg_shdr
*)
13373 &mbox
->u
.mqe
.un
.mq_destroy
.header
.cfg_shdr
;
13374 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13375 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13376 if (shdr_status
|| shdr_add_status
|| rc
) {
13377 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13378 "2507 MQ_DESTROY mailbox failed with "
13379 "status x%x add_status x%x, mbx status x%x\n",
13380 shdr_status
, shdr_add_status
, rc
);
13383 /* Remove mq from any list */
13384 list_del_init(&mq
->list
);
13385 mempool_free(mbox
, mq
->phba
->mbox_mem_pool
);
13390 * lpfc_wq_destroy - Destroy a Work Queue on the HBA
13391 * @wq: The queue structure associated with the queue to destroy.
13393 * This function destroys a queue, as detailed in @wq by sending an mailbox
13394 * command, specific to the type of queue, to the HBA.
13396 * The @wq struct is used to get the queue ID of the queue to destroy.
13398 * On success this function will return a zero. If the queue destroy mailbox
13399 * command fails this function will return -ENXIO.
13402 lpfc_wq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*wq
)
13404 LPFC_MBOXQ_t
*mbox
;
13405 int rc
, length
, status
= 0;
13406 uint32_t shdr_status
, shdr_add_status
;
13407 union lpfc_sli4_cfg_shdr
*shdr
;
13409 /* sanity check on queue memory */
13412 mbox
= mempool_alloc(wq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13415 length
= (sizeof(struct lpfc_mbx_wq_destroy
) -
13416 sizeof(struct lpfc_sli4_cfg_mhdr
));
13417 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13418 LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY
,
13419 length
, LPFC_SLI4_MBX_EMBED
);
13420 bf_set(lpfc_mbx_wq_destroy_q_id
, &mbox
->u
.mqe
.un
.wq_destroy
.u
.request
,
13422 mbox
->vport
= wq
->phba
->pport
;
13423 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13424 rc
= lpfc_sli_issue_mbox(wq
->phba
, mbox
, MBX_POLL
);
13425 shdr
= (union lpfc_sli4_cfg_shdr
*)
13426 &mbox
->u
.mqe
.un
.wq_destroy
.header
.cfg_shdr
;
13427 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13428 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13429 if (shdr_status
|| shdr_add_status
|| rc
) {
13430 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13431 "2508 WQ_DESTROY mailbox failed with "
13432 "status x%x add_status x%x, mbx status x%x\n",
13433 shdr_status
, shdr_add_status
, rc
);
13436 /* Remove wq from any list */
13437 list_del_init(&wq
->list
);
13438 mempool_free(mbox
, wq
->phba
->mbox_mem_pool
);
13443 * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
13444 * @rq: The queue structure associated with the queue to destroy.
13446 * This function destroys a queue, as detailed in @rq by sending an mailbox
13447 * command, specific to the type of queue, to the HBA.
13449 * The @rq struct is used to get the queue ID of the queue to destroy.
13451 * On success this function will return a zero. If the queue destroy mailbox
13452 * command fails this function will return -ENXIO.
13455 lpfc_rq_destroy(struct lpfc_hba
*phba
, struct lpfc_queue
*hrq
,
13456 struct lpfc_queue
*drq
)
13458 LPFC_MBOXQ_t
*mbox
;
13459 int rc
, length
, status
= 0;
13460 uint32_t shdr_status
, shdr_add_status
;
13461 union lpfc_sli4_cfg_shdr
*shdr
;
13463 /* sanity check on queue memory */
13466 mbox
= mempool_alloc(hrq
->phba
->mbox_mem_pool
, GFP_KERNEL
);
13469 length
= (sizeof(struct lpfc_mbx_rq_destroy
) -
13470 sizeof(struct lpfc_sli4_cfg_mhdr
));
13471 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13472 LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY
,
13473 length
, LPFC_SLI4_MBX_EMBED
);
13474 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13476 mbox
->vport
= hrq
->phba
->pport
;
13477 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
13478 rc
= lpfc_sli_issue_mbox(hrq
->phba
, mbox
, MBX_POLL
);
13479 /* The IOCTL status is embedded in the mailbox subheader. */
13480 shdr
= (union lpfc_sli4_cfg_shdr
*)
13481 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13482 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13483 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13484 if (shdr_status
|| shdr_add_status
|| rc
) {
13485 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13486 "2509 RQ_DESTROY mailbox failed with "
13487 "status x%x add_status x%x, mbx status x%x\n",
13488 shdr_status
, shdr_add_status
, rc
);
13489 if (rc
!= MBX_TIMEOUT
)
13490 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13493 bf_set(lpfc_mbx_rq_destroy_q_id
, &mbox
->u
.mqe
.un
.rq_destroy
.u
.request
,
13495 rc
= lpfc_sli_issue_mbox(drq
->phba
, mbox
, MBX_POLL
);
13496 shdr
= (union lpfc_sli4_cfg_shdr
*)
13497 &mbox
->u
.mqe
.un
.rq_destroy
.header
.cfg_shdr
;
13498 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13499 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13500 if (shdr_status
|| shdr_add_status
|| rc
) {
13501 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13502 "2510 RQ_DESTROY mailbox failed with "
13503 "status x%x add_status x%x, mbx status x%x\n",
13504 shdr_status
, shdr_add_status
, rc
);
13507 list_del_init(&hrq
->list
);
13508 list_del_init(&drq
->list
);
13509 mempool_free(mbox
, hrq
->phba
->mbox_mem_pool
);
13514 * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
13515 * @phba: The virtual port for which this call being executed.
13516 * @pdma_phys_addr0: Physical address of the 1st SGL page.
13517 * @pdma_phys_addr1: Physical address of the 2nd SGL page.
13518 * @xritag: the xritag that ties this io to the SGL pages.
13520 * This routine will post the sgl pages for the IO that has the xritag
13521 * that is in the iocbq structure. The xritag is assigned during iocbq
13522 * creation and persists for as long as the driver is loaded.
13523 * if the caller has fewer than 256 scatter gather segments to map then
13524 * pdma_phys_addr1 should be 0.
13525 * If the caller needs to map more than 256 scatter gather segment then
13526 * pdma_phys_addr1 should be a valid physical address.
13527 * physical address for SGLs must be 64 byte aligned.
13528 * If you are going to map 2 SGL's then the first one must have 256 entries
13529 * the second sgl can have between 1 and 256 entries.
13533 * -ENXIO, -ENOMEM - Failure
13536 lpfc_sli4_post_sgl(struct lpfc_hba
*phba
,
13537 dma_addr_t pdma_phys_addr0
,
13538 dma_addr_t pdma_phys_addr1
,
13541 struct lpfc_mbx_post_sgl_pages
*post_sgl_pages
;
13542 LPFC_MBOXQ_t
*mbox
;
13544 uint32_t shdr_status
, shdr_add_status
;
13546 union lpfc_sli4_cfg_shdr
*shdr
;
13548 if (xritag
== NO_XRI
) {
13549 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13550 "0364 Invalid param:\n");
13554 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13558 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13559 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
,
13560 sizeof(struct lpfc_mbx_post_sgl_pages
) -
13561 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
13563 post_sgl_pages
= (struct lpfc_mbx_post_sgl_pages
*)
13564 &mbox
->u
.mqe
.un
.post_sgl_pages
;
13565 bf_set(lpfc_post_sgl_pages_xri
, post_sgl_pages
, xritag
);
13566 bf_set(lpfc_post_sgl_pages_xricnt
, post_sgl_pages
, 1);
13568 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_lo
=
13569 cpu_to_le32(putPaddrLow(pdma_phys_addr0
));
13570 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg0_addr_hi
=
13571 cpu_to_le32(putPaddrHigh(pdma_phys_addr0
));
13573 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_lo
=
13574 cpu_to_le32(putPaddrLow(pdma_phys_addr1
));
13575 post_sgl_pages
->sgl_pg_pairs
[0].sgl_pg1_addr_hi
=
13576 cpu_to_le32(putPaddrHigh(pdma_phys_addr1
));
13577 if (!phba
->sli4_hba
.intr_enable
)
13578 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13580 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13581 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13583 /* The IOCTL status is embedded in the mailbox subheader. */
13584 shdr
= (union lpfc_sli4_cfg_shdr
*) &post_sgl_pages
->header
.cfg_shdr
;
13585 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13586 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13587 if (rc
!= MBX_TIMEOUT
)
13588 mempool_free(mbox
, phba
->mbox_mem_pool
);
13589 if (shdr_status
|| shdr_add_status
|| rc
) {
13590 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13591 "2511 POST_SGL mailbox failed with "
13592 "status x%x add_status x%x, mbx status x%x\n",
13593 shdr_status
, shdr_add_status
, rc
);
13600 * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
13601 * @phba: pointer to lpfc hba data structure.
13603 * This routine is invoked to post rpi header templates to the
13604 * HBA consistent with the SLI-4 interface spec. This routine
13605 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
13606 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
13609 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
13610 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
13613 lpfc_sli4_alloc_xri(struct lpfc_hba
*phba
)
13618 * Fetch the next logical xri. Because this index is logical,
13619 * the driver starts at 0 each time.
13621 spin_lock_irq(&phba
->hbalock
);
13622 xri
= find_next_zero_bit(phba
->sli4_hba
.xri_bmask
,
13623 phba
->sli4_hba
.max_cfg_param
.max_xri
, 0);
13624 if (xri
>= phba
->sli4_hba
.max_cfg_param
.max_xri
) {
13625 spin_unlock_irq(&phba
->hbalock
);
13628 set_bit(xri
, phba
->sli4_hba
.xri_bmask
);
13629 phba
->sli4_hba
.max_cfg_param
.xri_used
++;
13631 spin_unlock_irq(&phba
->hbalock
);
13636 * lpfc_sli4_free_xri - Release an xri for reuse.
13637 * @phba: pointer to lpfc hba data structure.
13639 * This routine is invoked to release an xri to the pool of
13640 * available rpis maintained by the driver.
13643 __lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13645 if (test_and_clear_bit(xri
, phba
->sli4_hba
.xri_bmask
)) {
13646 phba
->sli4_hba
.max_cfg_param
.xri_used
--;
13651 * lpfc_sli4_free_xri - Release an xri for reuse.
13652 * @phba: pointer to lpfc hba data structure.
13654 * This routine is invoked to release an xri to the pool of
13655 * available rpis maintained by the driver.
13658 lpfc_sli4_free_xri(struct lpfc_hba
*phba
, int xri
)
13660 spin_lock_irq(&phba
->hbalock
);
13661 __lpfc_sli4_free_xri(phba
, xri
);
13662 spin_unlock_irq(&phba
->hbalock
);
13666 * lpfc_sli4_next_xritag - Get an xritag for the io
13667 * @phba: Pointer to HBA context object.
13669 * This function gets an xritag for the iocb. If there is no unused xritag
13670 * it will return 0xffff.
13671 * The function returns the allocated xritag if successful, else returns zero.
13672 * Zero is not a valid xritag.
13673 * The caller is not required to hold any lock.
13676 lpfc_sli4_next_xritag(struct lpfc_hba
*phba
)
13678 uint16_t xri_index
;
13680 xri_index
= lpfc_sli4_alloc_xri(phba
);
13681 if (xri_index
== NO_XRI
)
13682 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
13683 "2004 Failed to allocate XRI.last XRITAG is %d"
13684 " Max XRI is %d, Used XRI is %d\n",
13686 phba
->sli4_hba
.max_cfg_param
.max_xri
,
13687 phba
->sli4_hba
.max_cfg_param
.xri_used
);
13692 * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port.
13693 * @phba: pointer to lpfc hba data structure.
13694 * @post_sgl_list: pointer to els sgl entry list.
13695 * @count: number of els sgl entries on the list.
13697 * This routine is invoked to post a block of driver's sgl pages to the
13698 * HBA using non-embedded mailbox command. No Lock is held. This routine
13699 * is only called when the driver is loading and after all IO has been
13703 lpfc_sli4_post_els_sgl_list(struct lpfc_hba
*phba
,
13704 struct list_head
*post_sgl_list
,
13707 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
13708 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13709 struct sgl_page_pairs
*sgl_pg_pairs
;
13711 LPFC_MBOXQ_t
*mbox
;
13712 uint32_t reqlen
, alloclen
, pg_pairs
;
13714 uint16_t xritag_start
= 0;
13716 uint32_t shdr_status
, shdr_add_status
;
13717 union lpfc_sli4_cfg_shdr
*shdr
;
13719 reqlen
= phba
->sli4_hba
.els_xri_cnt
* sizeof(struct sgl_page_pairs
) +
13720 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13721 if (reqlen
> SLI4_PAGE_SIZE
) {
13722 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13723 "2559 Block sgl registration required DMA "
13724 "size (%d) great than a page\n", reqlen
);
13727 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13731 /* Allocate DMA memory and set up the non-embedded mailbox command */
13732 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13733 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13734 LPFC_SLI4_MBX_NEMBED
);
13736 if (alloclen
< reqlen
) {
13737 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13738 "0285 Allocated DMA memory size (%d) is "
13739 "less than the requested DMA memory "
13740 "size (%d)\n", alloclen
, reqlen
);
13741 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13744 /* Set up the SGL pages in the non-embedded DMA pages */
13745 viraddr
= mbox
->sge_array
->addr
[0];
13746 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13747 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13750 list_for_each_entry_safe(sglq_entry
, sglq_next
, post_sgl_list
, list
) {
13751 /* Set up the sge entry */
13752 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13753 cpu_to_le32(putPaddrLow(sglq_entry
->phys
));
13754 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13755 cpu_to_le32(putPaddrHigh(sglq_entry
->phys
));
13756 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13757 cpu_to_le32(putPaddrLow(0));
13758 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13759 cpu_to_le32(putPaddrHigh(0));
13761 /* Keep the first xritag on the list */
13763 xritag_start
= sglq_entry
->sli4_xritag
;
13768 /* Complete initialization and perform endian conversion. */
13769 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13770 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, phba
->sli4_hba
.els_xri_cnt
);
13771 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13772 if (!phba
->sli4_hba
.intr_enable
)
13773 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13775 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13776 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13778 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13779 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13780 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13781 if (rc
!= MBX_TIMEOUT
)
13782 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13783 if (shdr_status
|| shdr_add_status
|| rc
) {
13784 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13785 "2513 POST_SGL_BLOCK mailbox command failed "
13786 "status x%x add_status x%x mbx status x%x\n",
13787 shdr_status
, shdr_add_status
, rc
);
13794 * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware
13795 * @phba: pointer to lpfc hba data structure.
13796 * @sblist: pointer to scsi buffer list.
13797 * @count: number of scsi buffers on the list.
13799 * This routine is invoked to post a block of @count scsi sgl pages from a
13800 * SCSI buffer list @sblist to the HBA using non-embedded mailbox command.
13805 lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba
*phba
,
13806 struct list_head
*sblist
,
13809 struct lpfc_scsi_buf
*psb
;
13810 struct lpfc_mbx_post_uembed_sgl_page1
*sgl
;
13811 struct sgl_page_pairs
*sgl_pg_pairs
;
13813 LPFC_MBOXQ_t
*mbox
;
13814 uint32_t reqlen
, alloclen
, pg_pairs
;
13816 uint16_t xritag_start
= 0;
13818 uint32_t shdr_status
, shdr_add_status
;
13819 dma_addr_t pdma_phys_bpl1
;
13820 union lpfc_sli4_cfg_shdr
*shdr
;
13822 /* Calculate the requested length of the dma memory */
13823 reqlen
= count
* sizeof(struct sgl_page_pairs
) +
13824 sizeof(union lpfc_sli4_cfg_shdr
) + sizeof(uint32_t);
13825 if (reqlen
> SLI4_PAGE_SIZE
) {
13826 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
13827 "0217 Block sgl registration required DMA "
13828 "size (%d) great than a page\n", reqlen
);
13831 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
13833 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13834 "0283 Failed to allocate mbox cmd memory\n");
13838 /* Allocate DMA memory and set up the non-embedded mailbox command */
13839 alloclen
= lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
13840 LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES
, reqlen
,
13841 LPFC_SLI4_MBX_NEMBED
);
13843 if (alloclen
< reqlen
) {
13844 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
13845 "2561 Allocated DMA memory size (%d) is "
13846 "less than the requested DMA memory "
13847 "size (%d)\n", alloclen
, reqlen
);
13848 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13852 /* Get the first SGE entry from the non-embedded DMA memory */
13853 viraddr
= mbox
->sge_array
->addr
[0];
13855 /* Set up the SGL pages in the non-embedded DMA pages */
13856 sgl
= (struct lpfc_mbx_post_uembed_sgl_page1
*)viraddr
;
13857 sgl_pg_pairs
= &sgl
->sgl_pg_pairs
;
13860 list_for_each_entry(psb
, sblist
, list
) {
13861 /* Set up the sge entry */
13862 sgl_pg_pairs
->sgl_pg0_addr_lo
=
13863 cpu_to_le32(putPaddrLow(psb
->dma_phys_bpl
));
13864 sgl_pg_pairs
->sgl_pg0_addr_hi
=
13865 cpu_to_le32(putPaddrHigh(psb
->dma_phys_bpl
));
13866 if (phba
->cfg_sg_dma_buf_size
> SGL_PAGE_SIZE
)
13867 pdma_phys_bpl1
= psb
->dma_phys_bpl
+ SGL_PAGE_SIZE
;
13869 pdma_phys_bpl1
= 0;
13870 sgl_pg_pairs
->sgl_pg1_addr_lo
=
13871 cpu_to_le32(putPaddrLow(pdma_phys_bpl1
));
13872 sgl_pg_pairs
->sgl_pg1_addr_hi
=
13873 cpu_to_le32(putPaddrHigh(pdma_phys_bpl1
));
13874 /* Keep the first xritag on the list */
13876 xritag_start
= psb
->cur_iocbq
.sli4_xritag
;
13880 bf_set(lpfc_post_sgl_pages_xri
, sgl
, xritag_start
);
13881 bf_set(lpfc_post_sgl_pages_xricnt
, sgl
, pg_pairs
);
13882 /* Perform endian conversion if necessary */
13883 sgl
->word0
= cpu_to_le32(sgl
->word0
);
13885 if (!phba
->sli4_hba
.intr_enable
)
13886 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
13888 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
13889 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
13891 shdr
= (union lpfc_sli4_cfg_shdr
*) &sgl
->cfg_shdr
;
13892 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
13893 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
13894 if (rc
!= MBX_TIMEOUT
)
13895 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
13896 if (shdr_status
|| shdr_add_status
|| rc
) {
13897 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
13898 "2564 POST_SGL_BLOCK mailbox command failed "
13899 "status x%x add_status x%x mbx status x%x\n",
13900 shdr_status
, shdr_add_status
, rc
);
13907 * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
13908 * @phba: pointer to lpfc_hba struct that the frame was received on
13909 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13911 * This function checks the fields in the @fc_hdr to see if the FC frame is a
13912 * valid type of frame that the LPFC driver will handle. This function will
13913 * return a zero if the frame is a valid frame or a non zero value when the
13914 * frame does not pass the check.
13917 lpfc_fc_frame_check(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
)
13919 /* make rctl_names static to save stack space */
13920 static char *rctl_names
[] = FC_RCTL_NAMES_INIT
;
13921 char *type_names
[] = FC_TYPE_NAMES_INIT
;
13922 struct fc_vft_header
*fc_vft_hdr
;
13923 uint32_t *header
= (uint32_t *) fc_hdr
;
13925 switch (fc_hdr
->fh_r_ctl
) {
13926 case FC_RCTL_DD_UNCAT
: /* uncategorized information */
13927 case FC_RCTL_DD_SOL_DATA
: /* solicited data */
13928 case FC_RCTL_DD_UNSOL_CTL
: /* unsolicited control */
13929 case FC_RCTL_DD_SOL_CTL
: /* solicited control or reply */
13930 case FC_RCTL_DD_UNSOL_DATA
: /* unsolicited data */
13931 case FC_RCTL_DD_DATA_DESC
: /* data descriptor */
13932 case FC_RCTL_DD_UNSOL_CMD
: /* unsolicited command */
13933 case FC_RCTL_DD_CMD_STATUS
: /* command status */
13934 case FC_RCTL_ELS_REQ
: /* extended link services request */
13935 case FC_RCTL_ELS_REP
: /* extended link services reply */
13936 case FC_RCTL_ELS4_REQ
: /* FC-4 ELS request */
13937 case FC_RCTL_ELS4_REP
: /* FC-4 ELS reply */
13938 case FC_RCTL_BA_NOP
: /* basic link service NOP */
13939 case FC_RCTL_BA_ABTS
: /* basic link service abort */
13940 case FC_RCTL_BA_RMC
: /* remove connection */
13941 case FC_RCTL_BA_ACC
: /* basic accept */
13942 case FC_RCTL_BA_RJT
: /* basic reject */
13943 case FC_RCTL_BA_PRMT
:
13944 case FC_RCTL_ACK_1
: /* acknowledge_1 */
13945 case FC_RCTL_ACK_0
: /* acknowledge_0 */
13946 case FC_RCTL_P_RJT
: /* port reject */
13947 case FC_RCTL_F_RJT
: /* fabric reject */
13948 case FC_RCTL_P_BSY
: /* port busy */
13949 case FC_RCTL_F_BSY
: /* fabric busy to data frame */
13950 case FC_RCTL_F_BSYL
: /* fabric busy to link control frame */
13951 case FC_RCTL_LCR
: /* link credit reset */
13952 case FC_RCTL_END
: /* end */
13954 case FC_RCTL_VFTH
: /* Virtual Fabric tagging Header */
13955 fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
13956 fc_hdr
= &((struct fc_frame_header
*)fc_vft_hdr
)[1];
13957 return lpfc_fc_frame_check(phba
, fc_hdr
);
13961 switch (fc_hdr
->fh_type
) {
13973 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
13974 "2538 Received frame rctl:%s type:%s "
13975 "Frame Data:%08x %08x %08x %08x %08x %08x\n",
13976 rctl_names
[fc_hdr
->fh_r_ctl
],
13977 type_names
[fc_hdr
->fh_type
],
13978 be32_to_cpu(header
[0]), be32_to_cpu(header
[1]),
13979 be32_to_cpu(header
[2]), be32_to_cpu(header
[3]),
13980 be32_to_cpu(header
[4]), be32_to_cpu(header
[5]));
13983 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
13984 "2539 Dropped frame rctl:%s type:%s\n",
13985 rctl_names
[fc_hdr
->fh_r_ctl
],
13986 type_names
[fc_hdr
->fh_type
]);
13991 * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
13992 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
13994 * This function processes the FC header to retrieve the VFI from the VF
13995 * header, if one exists. This function will return the VFI if one exists
13996 * or 0 if no VSAN Header exists.
13999 lpfc_fc_hdr_get_vfi(struct fc_frame_header
*fc_hdr
)
14001 struct fc_vft_header
*fc_vft_hdr
= (struct fc_vft_header
*)fc_hdr
;
14003 if (fc_hdr
->fh_r_ctl
!= FC_RCTL_VFTH
)
14005 return bf_get(fc_vft_hdr_vf_id
, fc_vft_hdr
);
14009 * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
14010 * @phba: Pointer to the HBA structure to search for the vport on
14011 * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
14012 * @fcfi: The FC Fabric ID that the frame came from
14014 * This function searches the @phba for a vport that matches the content of the
14015 * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
14016 * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
14017 * returns the matching vport pointer or NULL if unable to match frame to a
14020 static struct lpfc_vport
*
14021 lpfc_fc_frame_to_vport(struct lpfc_hba
*phba
, struct fc_frame_header
*fc_hdr
,
14024 struct lpfc_vport
**vports
;
14025 struct lpfc_vport
*vport
= NULL
;
14027 uint32_t did
= (fc_hdr
->fh_d_id
[0] << 16 |
14028 fc_hdr
->fh_d_id
[1] << 8 |
14029 fc_hdr
->fh_d_id
[2]);
14031 if (did
== Fabric_DID
)
14032 return phba
->pport
;
14033 if ((phba
->pport
->fc_flag
& FC_PT2PT
) &&
14034 !(phba
->link_state
== LPFC_HBA_READY
))
14035 return phba
->pport
;
14037 vports
= lpfc_create_vport_work_array(phba
);
14038 if (vports
!= NULL
)
14039 for (i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
14040 if (phba
->fcf
.fcfi
== fcfi
&&
14041 vports
[i
]->vfi
== lpfc_fc_hdr_get_vfi(fc_hdr
) &&
14042 vports
[i
]->fc_myDID
== did
) {
14047 lpfc_destroy_vport_work_array(phba
, vports
);
14052 * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
14053 * @vport: The vport to work on.
14055 * This function updates the receive sequence time stamp for this vport. The
14056 * receive sequence time stamp indicates the time that the last frame of the
14057 * the sequence that has been idle for the longest amount of time was received.
14058 * the driver uses this time stamp to indicate if any received sequences have
14062 lpfc_update_rcv_time_stamp(struct lpfc_vport
*vport
)
14064 struct lpfc_dmabuf
*h_buf
;
14065 struct hbq_dmabuf
*dmabuf
= NULL
;
14067 /* get the oldest sequence on the rcv list */
14068 h_buf
= list_get_first(&vport
->rcv_buffer_list
,
14069 struct lpfc_dmabuf
, list
);
14072 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14073 vport
->rcv_buffer_time_stamp
= dmabuf
->time_stamp
;
14077 * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
14078 * @vport: The vport that the received sequences were sent to.
14080 * This function cleans up all outstanding received sequences. This is called
14081 * by the driver when a link event or user action invalidates all the received
14085 lpfc_cleanup_rcv_buffers(struct lpfc_vport
*vport
)
14087 struct lpfc_dmabuf
*h_buf
, *hnext
;
14088 struct lpfc_dmabuf
*d_buf
, *dnext
;
14089 struct hbq_dmabuf
*dmabuf
= NULL
;
14091 /* start with the oldest sequence on the rcv list */
14092 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
14093 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14094 list_del_init(&dmabuf
->hbuf
.list
);
14095 list_for_each_entry_safe(d_buf
, dnext
,
14096 &dmabuf
->dbuf
.list
, list
) {
14097 list_del_init(&d_buf
->list
);
14098 lpfc_in_buf_free(vport
->phba
, d_buf
);
14100 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
14105 * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
14106 * @vport: The vport that the received sequences were sent to.
14108 * This function determines whether any received sequences have timed out by
14109 * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
14110 * indicates that there is at least one timed out sequence this routine will
14111 * go through the received sequences one at a time from most inactive to most
14112 * active to determine which ones need to be cleaned up. Once it has determined
14113 * that a sequence needs to be cleaned up it will simply free up the resources
14114 * without sending an abort.
14117 lpfc_rcv_seq_check_edtov(struct lpfc_vport
*vport
)
14119 struct lpfc_dmabuf
*h_buf
, *hnext
;
14120 struct lpfc_dmabuf
*d_buf
, *dnext
;
14121 struct hbq_dmabuf
*dmabuf
= NULL
;
14122 unsigned long timeout
;
14123 int abort_count
= 0;
14125 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
14126 vport
->rcv_buffer_time_stamp
);
14127 if (list_empty(&vport
->rcv_buffer_list
) ||
14128 time_before(jiffies
, timeout
))
14130 /* start with the oldest sequence on the rcv list */
14131 list_for_each_entry_safe(h_buf
, hnext
, &vport
->rcv_buffer_list
, list
) {
14132 dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14133 timeout
= (msecs_to_jiffies(vport
->phba
->fc_edtov
) +
14134 dmabuf
->time_stamp
);
14135 if (time_before(jiffies
, timeout
))
14138 list_del_init(&dmabuf
->hbuf
.list
);
14139 list_for_each_entry_safe(d_buf
, dnext
,
14140 &dmabuf
->dbuf
.list
, list
) {
14141 list_del_init(&d_buf
->list
);
14142 lpfc_in_buf_free(vport
->phba
, d_buf
);
14144 lpfc_in_buf_free(vport
->phba
, &dmabuf
->dbuf
);
14147 lpfc_update_rcv_time_stamp(vport
);
14151 * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
14152 * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
14154 * This function searches through the existing incomplete sequences that have
14155 * been sent to this @vport. If the frame matches one of the incomplete
14156 * sequences then the dbuf in the @dmabuf is added to the list of frames that
14157 * make up that sequence. If no sequence is found that matches this frame then
14158 * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
14159 * This function returns a pointer to the first dmabuf in the sequence list that
14160 * the frame was linked to.
14162 static struct hbq_dmabuf
*
14163 lpfc_fc_frame_add(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
14165 struct fc_frame_header
*new_hdr
;
14166 struct fc_frame_header
*temp_hdr
;
14167 struct lpfc_dmabuf
*d_buf
;
14168 struct lpfc_dmabuf
*h_buf
;
14169 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14170 struct hbq_dmabuf
*temp_dmabuf
= NULL
;
14172 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14173 dmabuf
->time_stamp
= jiffies
;
14174 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14175 /* Use the hdr_buf to find the sequence that this frame belongs to */
14176 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14177 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14178 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14179 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14180 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14182 /* found a pending sequence that matches this frame */
14183 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14188 * This indicates first frame received for this sequence.
14189 * Queue the buffer on the vport's rcv_buffer_list.
14191 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14192 lpfc_update_rcv_time_stamp(vport
);
14195 temp_hdr
= seq_dmabuf
->hbuf
.virt
;
14196 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) <
14197 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14198 list_del_init(&seq_dmabuf
->hbuf
.list
);
14199 list_add_tail(&dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14200 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14201 lpfc_update_rcv_time_stamp(vport
);
14204 /* move this sequence to the tail to indicate a young sequence */
14205 list_move_tail(&seq_dmabuf
->hbuf
.list
, &vport
->rcv_buffer_list
);
14206 seq_dmabuf
->time_stamp
= jiffies
;
14207 lpfc_update_rcv_time_stamp(vport
);
14208 if (list_empty(&seq_dmabuf
->dbuf
.list
)) {
14209 temp_hdr
= dmabuf
->hbuf
.virt
;
14210 list_add_tail(&dmabuf
->dbuf
.list
, &seq_dmabuf
->dbuf
.list
);
14213 /* find the correct place in the sequence to insert this frame */
14214 list_for_each_entry_reverse(d_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14215 temp_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14216 temp_hdr
= (struct fc_frame_header
*)temp_dmabuf
->hbuf
.virt
;
14218 * If the frame's sequence count is greater than the frame on
14219 * the list then insert the frame right after this frame
14221 if (be16_to_cpu(new_hdr
->fh_seq_cnt
) >
14222 be16_to_cpu(temp_hdr
->fh_seq_cnt
)) {
14223 list_add(&dmabuf
->dbuf
.list
, &temp_dmabuf
->dbuf
.list
);
14231 * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
14232 * @vport: pointer to a vitural port
14233 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14235 * This function tries to abort from the partially assembed sequence, described
14236 * by the information from basic abbort @dmabuf. It checks to see whether such
14237 * partially assembled sequence held by the driver. If so, it shall free up all
14238 * the frames from the partially assembled sequence.
14241 * true -- if there is matching partially assembled sequence present and all
14242 * the frames freed with the sequence;
14243 * false -- if there is no matching partially assembled sequence present so
14244 * nothing got aborted in the lower layer driver
14247 lpfc_sli4_abort_partial_seq(struct lpfc_vport
*vport
,
14248 struct hbq_dmabuf
*dmabuf
)
14250 struct fc_frame_header
*new_hdr
;
14251 struct fc_frame_header
*temp_hdr
;
14252 struct lpfc_dmabuf
*d_buf
, *n_buf
, *h_buf
;
14253 struct hbq_dmabuf
*seq_dmabuf
= NULL
;
14255 /* Use the hdr_buf to find the sequence that matches this frame */
14256 INIT_LIST_HEAD(&dmabuf
->dbuf
.list
);
14257 INIT_LIST_HEAD(&dmabuf
->hbuf
.list
);
14258 new_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14259 list_for_each_entry(h_buf
, &vport
->rcv_buffer_list
, list
) {
14260 temp_hdr
= (struct fc_frame_header
*)h_buf
->virt
;
14261 if ((temp_hdr
->fh_seq_id
!= new_hdr
->fh_seq_id
) ||
14262 (temp_hdr
->fh_ox_id
!= new_hdr
->fh_ox_id
) ||
14263 (memcmp(&temp_hdr
->fh_s_id
, &new_hdr
->fh_s_id
, 3)))
14265 /* found a pending sequence that matches this frame */
14266 seq_dmabuf
= container_of(h_buf
, struct hbq_dmabuf
, hbuf
);
14270 /* Free up all the frames from the partially assembled sequence */
14272 list_for_each_entry_safe(d_buf
, n_buf
,
14273 &seq_dmabuf
->dbuf
.list
, list
) {
14274 list_del_init(&d_buf
->list
);
14275 lpfc_in_buf_free(vport
->phba
, d_buf
);
14283 * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
14284 * @vport: pointer to a vitural port
14285 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14287 * This function tries to abort from the assembed sequence from upper level
14288 * protocol, described by the information from basic abbort @dmabuf. It
14289 * checks to see whether such pending context exists at upper level protocol.
14290 * If so, it shall clean up the pending context.
14293 * true -- if there is matching pending context of the sequence cleaned
14295 * false -- if there is no matching pending context of the sequence present
14299 lpfc_sli4_abort_ulp_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*dmabuf
)
14301 struct lpfc_hba
*phba
= vport
->phba
;
14304 /* Accepting abort at ulp with SLI4 only */
14305 if (phba
->sli_rev
< LPFC_SLI_REV4
)
14308 /* Register all caring upper level protocols to attend abort */
14309 handled
= lpfc_ct_handle_unsol_abort(phba
, dmabuf
);
14317 * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
14318 * @phba: Pointer to HBA context object.
14319 * @cmd_iocbq: pointer to the command iocbq structure.
14320 * @rsp_iocbq: pointer to the response iocbq structure.
14322 * This function handles the sequence abort response iocb command complete
14323 * event. It properly releases the memory allocated to the sequence abort
14327 lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba
*phba
,
14328 struct lpfc_iocbq
*cmd_iocbq
,
14329 struct lpfc_iocbq
*rsp_iocbq
)
14331 struct lpfc_nodelist
*ndlp
;
14334 ndlp
= (struct lpfc_nodelist
*)cmd_iocbq
->context1
;
14335 lpfc_nlp_put(ndlp
);
14336 lpfc_nlp_not_used(ndlp
);
14337 lpfc_sli_release_iocbq(phba
, cmd_iocbq
);
14340 /* Failure means BLS ABORT RSP did not get delivered to remote node*/
14341 if (rsp_iocbq
&& rsp_iocbq
->iocb
.ulpStatus
)
14342 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14343 "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
14344 rsp_iocbq
->iocb
.ulpStatus
,
14345 rsp_iocbq
->iocb
.un
.ulpWord
[4]);
14349 * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
14350 * @phba: Pointer to HBA context object.
14351 * @xri: xri id in transaction.
14353 * This function validates the xri maps to the known range of XRIs allocated an
14354 * used by the driver.
14357 lpfc_sli4_xri_inrange(struct lpfc_hba
*phba
,
14362 for (i
= 0; i
< phba
->sli4_hba
.max_cfg_param
.max_xri
; i
++) {
14363 if (xri
== phba
->sli4_hba
.xri_ids
[i
])
14370 * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
14371 * @phba: Pointer to HBA context object.
14372 * @fc_hdr: pointer to a FC frame header.
14374 * This function sends a basic response to a previous unsol sequence abort
14375 * event after aborting the sequence handling.
14378 lpfc_sli4_seq_abort_rsp(struct lpfc_vport
*vport
,
14379 struct fc_frame_header
*fc_hdr
, bool aborted
)
14381 struct lpfc_hba
*phba
= vport
->phba
;
14382 struct lpfc_iocbq
*ctiocb
= NULL
;
14383 struct lpfc_nodelist
*ndlp
;
14384 uint16_t oxid
, rxid
, xri
, lxri
;
14385 uint32_t sid
, fctl
;
14389 if (!lpfc_is_link_up(phba
))
14392 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14393 oxid
= be16_to_cpu(fc_hdr
->fh_ox_id
);
14394 rxid
= be16_to_cpu(fc_hdr
->fh_rx_id
);
14396 ndlp
= lpfc_findnode_did(vport
, sid
);
14398 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
14400 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
14401 "1268 Failed to allocate ndlp for "
14402 "oxid:x%x SID:x%x\n", oxid
, sid
);
14405 lpfc_nlp_init(vport
, ndlp
, sid
);
14406 /* Put ndlp onto pport node list */
14407 lpfc_enqueue_node(vport
, ndlp
);
14408 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
14409 /* re-setup ndlp without removing from node list */
14410 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
14412 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
14413 "3275 Failed to active ndlp found "
14414 "for oxid:x%x SID:x%x\n", oxid
, sid
);
14419 /* Allocate buffer for rsp iocb */
14420 ctiocb
= lpfc_sli_get_iocbq(phba
);
14424 /* Extract the F_CTL field from FC_HDR */
14425 fctl
= sli4_fctl_from_fc_hdr(fc_hdr
);
14427 icmd
= &ctiocb
->iocb
;
14428 icmd
->un
.xseq64
.bdl
.bdeSize
= 0;
14429 icmd
->un
.xseq64
.bdl
.ulpIoTag32
= 0;
14430 icmd
->un
.xseq64
.w5
.hcsw
.Dfctl
= 0;
14431 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_ACC
;
14432 icmd
->un
.xseq64
.w5
.hcsw
.Type
= FC_TYPE_BLS
;
14434 /* Fill in the rest of iocb fields */
14435 icmd
->ulpCommand
= CMD_XMIT_BLS_RSP64_CX
;
14436 icmd
->ulpBdeCount
= 0;
14438 icmd
->ulpClass
= CLASS3
;
14439 icmd
->ulpContext
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
14440 ctiocb
->context1
= lpfc_nlp_get(ndlp
);
14442 ctiocb
->iocb_cmpl
= NULL
;
14443 ctiocb
->vport
= phba
->pport
;
14444 ctiocb
->iocb_cmpl
= lpfc_sli4_seq_abort_rsp_cmpl
;
14445 ctiocb
->sli4_lxritag
= NO_XRI
;
14446 ctiocb
->sli4_xritag
= NO_XRI
;
14448 if (fctl
& FC_FC_EX_CTX
)
14449 /* Exchange responder sent the abort so we
14455 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
14456 if (lxri
!= NO_XRI
)
14457 lpfc_set_rrq_active(phba
, ndlp
, lxri
,
14458 (xri
== oxid
) ? rxid
: oxid
, 0);
14459 /* For BA_ABTS from exchange responder, if the logical xri with
14460 * the oxid maps to the FCP XRI range, the port no longer has
14461 * that exchange context, send a BLS_RJT. Override the IOCB for
14464 if ((fctl
& FC_FC_EX_CTX
) &&
14465 (lxri
> lpfc_sli4_get_els_iocb_cnt(phba
))) {
14466 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14467 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14468 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14469 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14472 /* If BA_ABTS failed to abort a partially assembled receive sequence,
14473 * the driver no longer has that exchange, send a BLS_RJT. Override
14474 * the IOCB for a BA_RJT.
14476 if (aborted
== false) {
14477 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
= FC_RCTL_BA_RJT
;
14478 bf_set(lpfc_vndr_code
, &icmd
->un
.bls_rsp
, 0);
14479 bf_set(lpfc_rsn_expln
, &icmd
->un
.bls_rsp
, FC_BA_RJT_INV_XID
);
14480 bf_set(lpfc_rsn_code
, &icmd
->un
.bls_rsp
, FC_BA_RJT_UNABLE
);
14483 if (fctl
& FC_FC_EX_CTX
) {
14484 /* ABTS sent by responder to CT exchange, construction
14485 * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
14486 * field and RX_ID from ABTS for RX_ID field.
14488 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_RSP
);
14490 /* ABTS sent by initiator to CT exchange, construction
14491 * of BA_ACC will need to allocate a new XRI as for the
14494 bf_set(lpfc_abts_orig
, &icmd
->un
.bls_rsp
, LPFC_ABTS_UNSOL_INT
);
14496 bf_set(lpfc_abts_rxid
, &icmd
->un
.bls_rsp
, rxid
);
14497 bf_set(lpfc_abts_oxid
, &icmd
->un
.bls_rsp
, oxid
);
14499 /* Xmit CT abts response on exchange <xid> */
14500 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
14501 "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
14502 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
, phba
->link_state
);
14504 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, ctiocb
, 0);
14505 if (rc
== IOCB_ERROR
) {
14506 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
14507 "2925 Failed to issue CT ABTS RSP x%x on "
14508 "xri x%x, Data x%x\n",
14509 icmd
->un
.xseq64
.w5
.hcsw
.Rctl
, oxid
,
14511 lpfc_nlp_put(ndlp
);
14512 ctiocb
->context1
= NULL
;
14513 lpfc_sli_release_iocbq(phba
, ctiocb
);
14518 * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
14519 * @vport: Pointer to the vport on which this sequence was received
14520 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14522 * This function handles an SLI-4 unsolicited abort event. If the unsolicited
14523 * receive sequence is only partially assembed by the driver, it shall abort
14524 * the partially assembled frames for the sequence. Otherwise, if the
14525 * unsolicited receive sequence has been completely assembled and passed to
14526 * the Upper Layer Protocol (UPL), it then mark the per oxid status for the
14527 * unsolicited sequence has been aborted. After that, it will issue a basic
14528 * accept to accept the abort.
14531 lpfc_sli4_handle_unsol_abort(struct lpfc_vport
*vport
,
14532 struct hbq_dmabuf
*dmabuf
)
14534 struct lpfc_hba
*phba
= vport
->phba
;
14535 struct fc_frame_header fc_hdr
;
14539 /* Make a copy of fc_hdr before the dmabuf being released */
14540 memcpy(&fc_hdr
, dmabuf
->hbuf
.virt
, sizeof(struct fc_frame_header
));
14541 fctl
= sli4_fctl_from_fc_hdr(&fc_hdr
);
14543 if (fctl
& FC_FC_EX_CTX
) {
14544 /* ABTS by responder to exchange, no cleanup needed */
14547 /* ABTS by initiator to exchange, need to do cleanup */
14548 aborted
= lpfc_sli4_abort_partial_seq(vport
, dmabuf
);
14549 if (aborted
== false)
14550 aborted
= lpfc_sli4_abort_ulp_seq(vport
, dmabuf
);
14552 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14554 /* Respond with BA_ACC or BA_RJT accordingly */
14555 lpfc_sli4_seq_abort_rsp(vport
, &fc_hdr
, aborted
);
14559 * lpfc_seq_complete - Indicates if a sequence is complete
14560 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14562 * This function checks the sequence, starting with the frame described by
14563 * @dmabuf, to see if all the frames associated with this sequence are present.
14564 * the frames associated with this sequence are linked to the @dmabuf using the
14565 * dbuf list. This function looks for two major things. 1) That the first frame
14566 * has a sequence count of zero. 2) There is a frame with last frame of sequence
14567 * set. 3) That there are no holes in the sequence count. The function will
14568 * return 1 when the sequence is complete, otherwise it will return 0.
14571 lpfc_seq_complete(struct hbq_dmabuf
*dmabuf
)
14573 struct fc_frame_header
*hdr
;
14574 struct lpfc_dmabuf
*d_buf
;
14575 struct hbq_dmabuf
*seq_dmabuf
;
14579 hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14580 /* make sure first fame of sequence has a sequence count of zero */
14581 if (hdr
->fh_seq_cnt
!= seq_count
)
14583 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14584 hdr
->fh_f_ctl
[1] << 8 |
14586 /* If last frame of sequence we can return success. */
14587 if (fctl
& FC_FC_END_SEQ
)
14589 list_for_each_entry(d_buf
, &dmabuf
->dbuf
.list
, list
) {
14590 seq_dmabuf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14591 hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14592 /* If there is a hole in the sequence count then fail. */
14593 if (++seq_count
!= be16_to_cpu(hdr
->fh_seq_cnt
))
14595 fctl
= (hdr
->fh_f_ctl
[0] << 16 |
14596 hdr
->fh_f_ctl
[1] << 8 |
14598 /* If last frame of sequence we can return success. */
14599 if (fctl
& FC_FC_END_SEQ
)
14606 * lpfc_prep_seq - Prep sequence for ULP processing
14607 * @vport: Pointer to the vport on which this sequence was received
14608 * @dmabuf: pointer to a dmabuf that describes the FC sequence
14610 * This function takes a sequence, described by a list of frames, and creates
14611 * a list of iocbq structures to describe the sequence. This iocbq list will be
14612 * used to issue to the generic unsolicited sequence handler. This routine
14613 * returns a pointer to the first iocbq in the list. If the function is unable
14614 * to allocate an iocbq then it throw out the received frames that were not
14615 * able to be described and return a pointer to the first iocbq. If unable to
14616 * allocate any iocbqs (including the first) this function will return NULL.
14618 static struct lpfc_iocbq
*
14619 lpfc_prep_seq(struct lpfc_vport
*vport
, struct hbq_dmabuf
*seq_dmabuf
)
14621 struct hbq_dmabuf
*hbq_buf
;
14622 struct lpfc_dmabuf
*d_buf
, *n_buf
;
14623 struct lpfc_iocbq
*first_iocbq
, *iocbq
;
14624 struct fc_frame_header
*fc_hdr
;
14626 uint32_t len
, tot_len
;
14627 struct ulp_bde64
*pbde
;
14629 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14630 /* remove from receive buffer list */
14631 list_del_init(&seq_dmabuf
->hbuf
.list
);
14632 lpfc_update_rcv_time_stamp(vport
);
14633 /* get the Remote Port's SID */
14634 sid
= sli4_sid_from_fc_hdr(fc_hdr
);
14636 /* Get an iocbq struct to fill in. */
14637 first_iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14639 /* Initialize the first IOCB. */
14640 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= 0;
14641 first_iocbq
->iocb
.ulpStatus
= IOSTAT_SUCCESS
;
14643 /* Check FC Header to see what TYPE of frame we are rcv'ing */
14644 if (sli4_type_from_fc_hdr(fc_hdr
) == FC_TYPE_ELS
) {
14645 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_ELS64_CX
;
14646 first_iocbq
->iocb
.un
.rcvels
.parmRo
=
14647 sli4_did_from_fc_hdr(fc_hdr
);
14648 first_iocbq
->iocb
.ulpPU
= PARM_NPIV_DID
;
14650 first_iocbq
->iocb
.ulpCommand
= CMD_IOCB_RCV_SEQ64_CX
;
14651 first_iocbq
->iocb
.ulpContext
= NO_XRI
;
14652 first_iocbq
->iocb
.unsli3
.rcvsli3
.ox_id
=
14653 be16_to_cpu(fc_hdr
->fh_ox_id
);
14654 /* iocbq is prepped for internal consumption. Physical vpi. */
14655 first_iocbq
->iocb
.unsli3
.rcvsli3
.vpi
=
14656 vport
->phba
->vpi_ids
[vport
->vpi
];
14657 /* put the first buffer into the first IOCBq */
14658 first_iocbq
->context2
= &seq_dmabuf
->dbuf
;
14659 first_iocbq
->context3
= NULL
;
14660 first_iocbq
->iocb
.ulpBdeCount
= 1;
14661 first_iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14662 LPFC_DATA_BUF_SIZE
;
14663 first_iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14664 tot_len
= bf_get(lpfc_rcqe_length
,
14665 &seq_dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14666 first_iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14668 iocbq
= first_iocbq
;
14670 * Each IOCBq can have two Buffers assigned, so go through the list
14671 * of buffers for this sequence and save two buffers in each IOCBq
14673 list_for_each_entry_safe(d_buf
, n_buf
, &seq_dmabuf
->dbuf
.list
, list
) {
14675 lpfc_in_buf_free(vport
->phba
, d_buf
);
14678 if (!iocbq
->context3
) {
14679 iocbq
->context3
= d_buf
;
14680 iocbq
->iocb
.ulpBdeCount
++;
14681 pbde
= (struct ulp_bde64
*)
14682 &iocbq
->iocb
.unsli3
.sli3Words
[4];
14683 pbde
->tus
.f
.bdeSize
= LPFC_DATA_BUF_SIZE
;
14685 /* We need to get the size out of the right CQE */
14686 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14687 len
= bf_get(lpfc_rcqe_length
,
14688 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14689 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
+= len
;
14692 iocbq
= lpfc_sli_get_iocbq(vport
->phba
);
14695 first_iocbq
->iocb
.ulpStatus
=
14696 IOSTAT_FCP_RSP_ERROR
;
14697 first_iocbq
->iocb
.un
.ulpWord
[4] =
14698 IOERR_NO_RESOURCES
;
14700 lpfc_in_buf_free(vport
->phba
, d_buf
);
14703 iocbq
->context2
= d_buf
;
14704 iocbq
->context3
= NULL
;
14705 iocbq
->iocb
.ulpBdeCount
= 1;
14706 iocbq
->iocb
.un
.cont64
[0].tus
.f
.bdeSize
=
14707 LPFC_DATA_BUF_SIZE
;
14709 /* We need to get the size out of the right CQE */
14710 hbq_buf
= container_of(d_buf
, struct hbq_dmabuf
, dbuf
);
14711 len
= bf_get(lpfc_rcqe_length
,
14712 &hbq_buf
->cq_event
.cqe
.rcqe_cmpl
);
14714 iocbq
->iocb
.unsli3
.rcvsli3
.acc_len
= tot_len
;
14716 iocbq
->iocb
.un
.rcvels
.remoteID
= sid
;
14717 list_add_tail(&iocbq
->list
, &first_iocbq
->list
);
14720 return first_iocbq
;
14724 lpfc_sli4_send_seq_to_ulp(struct lpfc_vport
*vport
,
14725 struct hbq_dmabuf
*seq_dmabuf
)
14727 struct fc_frame_header
*fc_hdr
;
14728 struct lpfc_iocbq
*iocbq
, *curr_iocb
, *next_iocb
;
14729 struct lpfc_hba
*phba
= vport
->phba
;
14731 fc_hdr
= (struct fc_frame_header
*)seq_dmabuf
->hbuf
.virt
;
14732 iocbq
= lpfc_prep_seq(vport
, seq_dmabuf
);
14734 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14735 "2707 Ring %d handler: Failed to allocate "
14736 "iocb Rctl x%x Type x%x received\n",
14738 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14741 if (!lpfc_complete_unsol_iocb(phba
,
14742 &phba
->sli
.ring
[LPFC_ELS_RING
],
14743 iocbq
, fc_hdr
->fh_r_ctl
,
14745 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14746 "2540 Ring %d handler: unexpected Rctl "
14747 "x%x Type x%x received\n",
14749 fc_hdr
->fh_r_ctl
, fc_hdr
->fh_type
);
14751 /* Free iocb created in lpfc_prep_seq */
14752 list_for_each_entry_safe(curr_iocb
, next_iocb
,
14753 &iocbq
->list
, list
) {
14754 list_del_init(&curr_iocb
->list
);
14755 lpfc_sli_release_iocbq(phba
, curr_iocb
);
14757 lpfc_sli_release_iocbq(phba
, iocbq
);
14761 * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
14762 * @phba: Pointer to HBA context object.
14764 * This function is called with no lock held. This function processes all
14765 * the received buffers and gives it to upper layers when a received buffer
14766 * indicates that it is the final frame in the sequence. The interrupt
14767 * service routine processes received buffers at interrupt contexts and adds
14768 * received dma buffers to the rb_pend_list queue and signals the worker thread.
14769 * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
14770 * appropriate receive function when the final frame in a sequence is received.
14773 lpfc_sli4_handle_received_buffer(struct lpfc_hba
*phba
,
14774 struct hbq_dmabuf
*dmabuf
)
14776 struct hbq_dmabuf
*seq_dmabuf
;
14777 struct fc_frame_header
*fc_hdr
;
14778 struct lpfc_vport
*vport
;
14782 /* Process each received buffer */
14783 fc_hdr
= (struct fc_frame_header
*)dmabuf
->hbuf
.virt
;
14784 /* check to see if this a valid type of frame */
14785 if (lpfc_fc_frame_check(phba
, fc_hdr
)) {
14786 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14789 if ((bf_get(lpfc_cqe_code
,
14790 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
) == CQE_CODE_RECEIVE_V1
))
14791 fcfi
= bf_get(lpfc_rcqe_fcf_id_v1
,
14792 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14794 fcfi
= bf_get(lpfc_rcqe_fcf_id
,
14795 &dmabuf
->cq_event
.cqe
.rcqe_cmpl
);
14797 vport
= lpfc_fc_frame_to_vport(phba
, fc_hdr
, fcfi
);
14799 /* throw out the frame */
14800 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14804 /* d_id this frame is directed to */
14805 did
= sli4_did_from_fc_hdr(fc_hdr
);
14807 /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
14808 if (!(vport
->vpi_state
& LPFC_VPI_REGISTERED
) &&
14809 (did
!= Fabric_DID
)) {
14811 * Throw out the frame if we are not pt2pt.
14812 * The pt2pt protocol allows for discovery frames
14813 * to be received without a registered VPI.
14815 if (!(vport
->fc_flag
& FC_PT2PT
) ||
14816 (phba
->link_state
== LPFC_HBA_READY
)) {
14817 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14822 /* Handle the basic abort sequence (BA_ABTS) event */
14823 if (fc_hdr
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
14824 lpfc_sli4_handle_unsol_abort(vport
, dmabuf
);
14828 /* Link this frame */
14829 seq_dmabuf
= lpfc_fc_frame_add(vport
, dmabuf
);
14831 /* unable to add frame to vport - throw it out */
14832 lpfc_in_buf_free(phba
, &dmabuf
->dbuf
);
14835 /* If not last frame in sequence continue processing frames. */
14836 if (!lpfc_seq_complete(seq_dmabuf
))
14839 /* Send the complete sequence to the upper layer protocol */
14840 lpfc_sli4_send_seq_to_ulp(vport
, seq_dmabuf
);
14844 * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
14845 * @phba: pointer to lpfc hba data structure.
14847 * This routine is invoked to post rpi header templates to the
14848 * HBA consistent with the SLI-4 interface spec. This routine
14849 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14850 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14852 * This routine does not require any locks. It's usage is expected
14853 * to be driver load or reset recovery when the driver is
14858 * -EIO - The mailbox failed to complete successfully.
14859 * When this error occurs, the driver is not guaranteed
14860 * to have any rpi regions posted to the device and
14861 * must either attempt to repost the regions or take a
14865 lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba
*phba
)
14867 struct lpfc_rpi_hdr
*rpi_page
;
14871 /* SLI4 ports that support extents do not require RPI headers. */
14872 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14874 if (phba
->sli4_hba
.extents_in_use
)
14877 list_for_each_entry(rpi_page
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
14879 * Assign the rpi headers a physical rpi only if the driver
14880 * has not initialized those resources. A port reset only
14881 * needs the headers posted.
14883 if (bf_get(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
) !=
14885 rpi_page
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
14887 rc
= lpfc_sli4_post_rpi_hdr(phba
, rpi_page
);
14888 if (rc
!= MBX_SUCCESS
) {
14889 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14890 "2008 Error %d posting all rpi "
14898 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
,
14899 LPFC_RPI_RSRC_RDY
);
14904 * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
14905 * @phba: pointer to lpfc hba data structure.
14906 * @rpi_page: pointer to the rpi memory region.
14908 * This routine is invoked to post a single rpi header to the
14909 * HBA consistent with the SLI-4 interface spec. This memory region
14910 * maps up to 64 rpi context regions.
14914 * -ENOMEM - No available memory
14915 * -EIO - The mailbox failed to complete successfully.
14918 lpfc_sli4_post_rpi_hdr(struct lpfc_hba
*phba
, struct lpfc_rpi_hdr
*rpi_page
)
14920 LPFC_MBOXQ_t
*mboxq
;
14921 struct lpfc_mbx_post_hdr_tmpl
*hdr_tmpl
;
14923 uint32_t shdr_status
, shdr_add_status
;
14924 union lpfc_sli4_cfg_shdr
*shdr
;
14926 /* SLI4 ports that support extents do not require RPI headers. */
14927 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
14929 if (phba
->sli4_hba
.extents_in_use
)
14932 /* The port is notified of the header region via a mailbox command. */
14933 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
14935 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
14936 "2001 Unable to allocate memory for issuing "
14937 "SLI_CONFIG_SPECIAL mailbox command\n");
14941 /* Post all rpi memory regions to the port. */
14942 hdr_tmpl
= &mboxq
->u
.mqe
.un
.hdr_tmpl
;
14943 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
14944 LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE
,
14945 sizeof(struct lpfc_mbx_post_hdr_tmpl
) -
14946 sizeof(struct lpfc_sli4_cfg_mhdr
),
14947 LPFC_SLI4_MBX_EMBED
);
14950 /* Post the physical rpi to the port for this rpi header. */
14951 bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset
, hdr_tmpl
,
14952 rpi_page
->start_rpi
);
14953 bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt
,
14954 hdr_tmpl
, rpi_page
->page_count
);
14956 hdr_tmpl
->rpi_paddr_lo
= putPaddrLow(rpi_page
->dmabuf
->phys
);
14957 hdr_tmpl
->rpi_paddr_hi
= putPaddrHigh(rpi_page
->dmabuf
->phys
);
14958 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
14959 shdr
= (union lpfc_sli4_cfg_shdr
*) &hdr_tmpl
->header
.cfg_shdr
;
14960 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
14961 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
14962 if (rc
!= MBX_TIMEOUT
)
14963 mempool_free(mboxq
, phba
->mbox_mem_pool
);
14964 if (shdr_status
|| shdr_add_status
|| rc
) {
14965 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
14966 "2514 POST_RPI_HDR mailbox failed with "
14967 "status x%x add_status x%x, mbx status x%x\n",
14968 shdr_status
, shdr_add_status
, rc
);
14975 * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
14976 * @phba: pointer to lpfc hba data structure.
14978 * This routine is invoked to post rpi header templates to the
14979 * HBA consistent with the SLI-4 interface spec. This routine
14980 * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
14981 * SLI4_PAGE_SIZE modulo 64 rpi context headers.
14984 * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
14985 * LPFC_RPI_ALLOC_ERROR if no rpis are available.
14988 lpfc_sli4_alloc_rpi(struct lpfc_hba
*phba
)
14991 uint16_t max_rpi
, rpi_limit
;
14992 uint16_t rpi_remaining
, lrpi
= 0;
14993 struct lpfc_rpi_hdr
*rpi_hdr
;
14995 max_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
14996 rpi_limit
= phba
->sli4_hba
.next_rpi
;
14999 * Fetch the next logical rpi. Because this index is logical,
15000 * the driver starts at 0 each time.
15002 spin_lock_irq(&phba
->hbalock
);
15003 rpi
= find_next_zero_bit(phba
->sli4_hba
.rpi_bmask
, rpi_limit
, 0);
15004 if (rpi
>= rpi_limit
)
15005 rpi
= LPFC_RPI_ALLOC_ERROR
;
15007 set_bit(rpi
, phba
->sli4_hba
.rpi_bmask
);
15008 phba
->sli4_hba
.max_cfg_param
.rpi_used
++;
15009 phba
->sli4_hba
.rpi_count
++;
15013 * Don't try to allocate more rpi header regions if the device limit
15014 * has been exhausted.
15016 if ((rpi
== LPFC_RPI_ALLOC_ERROR
) &&
15017 (phba
->sli4_hba
.rpi_count
>= max_rpi
)) {
15018 spin_unlock_irq(&phba
->hbalock
);
15023 * RPI header postings are not required for SLI4 ports capable of
15026 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
15027 spin_unlock_irq(&phba
->hbalock
);
15032 * If the driver is running low on rpi resources, allocate another
15033 * page now. Note that the next_rpi value is used because
15034 * it represents how many are actually in use whereas max_rpi notes
15035 * how many are supported max by the device.
15037 rpi_remaining
= phba
->sli4_hba
.next_rpi
- phba
->sli4_hba
.rpi_count
;
15038 spin_unlock_irq(&phba
->hbalock
);
15039 if (rpi_remaining
< LPFC_RPI_LOW_WATER_MARK
) {
15040 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
15042 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15043 "2002 Error Could not grow rpi "
15046 lrpi
= rpi_hdr
->start_rpi
;
15047 rpi_hdr
->start_rpi
= phba
->sli4_hba
.rpi_ids
[lrpi
];
15048 lpfc_sli4_post_rpi_hdr(phba
, rpi_hdr
);
15056 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15057 * @phba: pointer to lpfc hba data structure.
15059 * This routine is invoked to release an rpi to the pool of
15060 * available rpis maintained by the driver.
15063 __lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
15065 if (test_and_clear_bit(rpi
, phba
->sli4_hba
.rpi_bmask
)) {
15066 phba
->sli4_hba
.rpi_count
--;
15067 phba
->sli4_hba
.max_cfg_param
.rpi_used
--;
15072 * lpfc_sli4_free_rpi - Release an rpi for reuse.
15073 * @phba: pointer to lpfc hba data structure.
15075 * This routine is invoked to release an rpi to the pool of
15076 * available rpis maintained by the driver.
15079 lpfc_sli4_free_rpi(struct lpfc_hba
*phba
, int rpi
)
15081 spin_lock_irq(&phba
->hbalock
);
15082 __lpfc_sli4_free_rpi(phba
, rpi
);
15083 spin_unlock_irq(&phba
->hbalock
);
15087 * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
15088 * @phba: pointer to lpfc hba data structure.
15090 * This routine is invoked to remove the memory region that
15091 * provided rpi via a bitmask.
15094 lpfc_sli4_remove_rpis(struct lpfc_hba
*phba
)
15096 kfree(phba
->sli4_hba
.rpi_bmask
);
15097 kfree(phba
->sli4_hba
.rpi_ids
);
15098 bf_set(lpfc_rpi_rsrc_rdy
, &phba
->sli4_hba
.sli4_flags
, 0);
15102 * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
15103 * @phba: pointer to lpfc hba data structure.
15105 * This routine is invoked to remove the memory region that
15106 * provided rpi via a bitmask.
15109 lpfc_sli4_resume_rpi(struct lpfc_nodelist
*ndlp
,
15110 void (*cmpl
)(struct lpfc_hba
*, LPFC_MBOXQ_t
*), void *arg
)
15112 LPFC_MBOXQ_t
*mboxq
;
15113 struct lpfc_hba
*phba
= ndlp
->phba
;
15116 /* The port is notified of the header region via a mailbox command. */
15117 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15121 /* Post all rpi memory regions to the port. */
15122 lpfc_resume_rpi(mboxq
, ndlp
);
15124 mboxq
->mbox_cmpl
= cmpl
;
15125 mboxq
->context1
= arg
;
15126 mboxq
->context2
= ndlp
;
15128 mboxq
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
15129 mboxq
->vport
= ndlp
->vport
;
15130 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15131 if (rc
== MBX_NOT_FINISHED
) {
15132 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15133 "2010 Resume RPI Mailbox failed "
15134 "status %d, mbxStatus x%x\n", rc
,
15135 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
15136 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15143 * lpfc_sli4_init_vpi - Initialize a vpi with the port
15144 * @vport: Pointer to the vport for which the vpi is being initialized
15146 * This routine is invoked to activate a vpi with the port.
15150 * -Evalue otherwise
15153 lpfc_sli4_init_vpi(struct lpfc_vport
*vport
)
15155 LPFC_MBOXQ_t
*mboxq
;
15157 int retval
= MBX_SUCCESS
;
15159 struct lpfc_hba
*phba
= vport
->phba
;
15160 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15163 lpfc_init_vpi(phba
, mboxq
, vport
->vpi
);
15164 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
15165 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
15166 if (rc
!= MBX_SUCCESS
) {
15167 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
15168 "2022 INIT VPI Mailbox failed "
15169 "status %d, mbxStatus x%x\n", rc
,
15170 bf_get(lpfc_mqe_status
, &mboxq
->u
.mqe
));
15173 if (rc
!= MBX_TIMEOUT
)
15174 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
15180 * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
15181 * @phba: pointer to lpfc hba data structure.
15182 * @mboxq: Pointer to mailbox object.
15184 * This routine is invoked to manually add a single FCF record. The caller
15185 * must pass a completely initialized FCF_Record. This routine takes
15186 * care of the nonembedded mailbox operations.
15189 lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
15192 union lpfc_sli4_cfg_shdr
*shdr
;
15193 uint32_t shdr_status
, shdr_add_status
;
15195 virt_addr
= mboxq
->sge_array
->addr
[0];
15196 /* The IOCTL status is embedded in the mailbox subheader. */
15197 shdr
= (union lpfc_sli4_cfg_shdr
*) virt_addr
;
15198 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
15199 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
15201 if ((shdr_status
|| shdr_add_status
) &&
15202 (shdr_status
!= STATUS_FCF_IN_USE
))
15203 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15204 "2558 ADD_FCF_RECORD mailbox failed with "
15205 "status x%x add_status x%x\n",
15206 shdr_status
, shdr_add_status
);
15208 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15212 * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
15213 * @phba: pointer to lpfc hba data structure.
15214 * @fcf_record: pointer to the initialized fcf record to add.
15216 * This routine is invoked to manually add a single FCF record. The caller
15217 * must pass a completely initialized FCF_Record. This routine takes
15218 * care of the nonembedded mailbox operations.
15221 lpfc_sli4_add_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*fcf_record
)
15224 LPFC_MBOXQ_t
*mboxq
;
15227 dma_addr_t phys_addr
;
15228 struct lpfc_mbx_sge sge
;
15229 uint32_t alloc_len
, req_len
;
15232 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15234 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15235 "2009 Failed to allocate mbox for ADD_FCF cmd\n");
15239 req_len
= sizeof(struct fcf_record
) + sizeof(union lpfc_sli4_cfg_shdr
) +
15242 /* Allocate DMA memory and set up the non-embedded mailbox command */
15243 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15244 LPFC_MBOX_OPCODE_FCOE_ADD_FCF
,
15245 req_len
, LPFC_SLI4_MBX_NEMBED
);
15246 if (alloc_len
< req_len
) {
15247 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15248 "2523 Allocated DMA memory size (x%x) is "
15249 "less than the requested DMA memory "
15250 "size (x%x)\n", alloc_len
, req_len
);
15251 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15256 * Get the first SGE entry from the non-embedded DMA memory. This
15257 * routine only uses a single SGE.
15259 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
15260 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
15261 virt_addr
= mboxq
->sge_array
->addr
[0];
15263 * Configure the FCF record for FCFI 0. This is the driver's
15264 * hardcoded default and gets used in nonFIP mode.
15266 fcfindex
= bf_get(lpfc_fcf_record_fcf_index
, fcf_record
);
15267 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
15268 lpfc_sli_pcimem_bcopy(&fcfindex
, bytep
, sizeof(uint32_t));
15271 * Copy the fcf_index and the FCF Record Data. The data starts after
15272 * the FCoE header plus word10. The data copy needs to be endian
15275 bytep
+= sizeof(uint32_t);
15276 lpfc_sli_pcimem_bcopy(fcf_record
, bytep
, sizeof(struct fcf_record
));
15277 mboxq
->vport
= phba
->pport
;
15278 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_add_fcf_record
;
15279 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15280 if (rc
== MBX_NOT_FINISHED
) {
15281 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15282 "2515 ADD_FCF_RECORD mailbox failed with "
15283 "status 0x%x\n", rc
);
15284 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15293 * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
15294 * @phba: pointer to lpfc hba data structure.
15295 * @fcf_record: pointer to the fcf record to write the default data.
15296 * @fcf_index: FCF table entry index.
15298 * This routine is invoked to build the driver's default FCF record. The
15299 * values used are hardcoded. This routine handles memory initialization.
15303 lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba
*phba
,
15304 struct fcf_record
*fcf_record
,
15305 uint16_t fcf_index
)
15307 memset(fcf_record
, 0, sizeof(struct fcf_record
));
15308 fcf_record
->max_rcv_size
= LPFC_FCOE_MAX_RCV_SIZE
;
15309 fcf_record
->fka_adv_period
= LPFC_FCOE_FKA_ADV_PER
;
15310 fcf_record
->fip_priority
= LPFC_FCOE_FIP_PRIORITY
;
15311 bf_set(lpfc_fcf_record_mac_0
, fcf_record
, phba
->fc_map
[0]);
15312 bf_set(lpfc_fcf_record_mac_1
, fcf_record
, phba
->fc_map
[1]);
15313 bf_set(lpfc_fcf_record_mac_2
, fcf_record
, phba
->fc_map
[2]);
15314 bf_set(lpfc_fcf_record_mac_3
, fcf_record
, LPFC_FCOE_FCF_MAC3
);
15315 bf_set(lpfc_fcf_record_mac_4
, fcf_record
, LPFC_FCOE_FCF_MAC4
);
15316 bf_set(lpfc_fcf_record_mac_5
, fcf_record
, LPFC_FCOE_FCF_MAC5
);
15317 bf_set(lpfc_fcf_record_fc_map_0
, fcf_record
, phba
->fc_map
[0]);
15318 bf_set(lpfc_fcf_record_fc_map_1
, fcf_record
, phba
->fc_map
[1]);
15319 bf_set(lpfc_fcf_record_fc_map_2
, fcf_record
, phba
->fc_map
[2]);
15320 bf_set(lpfc_fcf_record_fcf_valid
, fcf_record
, 1);
15321 bf_set(lpfc_fcf_record_fcf_avail
, fcf_record
, 1);
15322 bf_set(lpfc_fcf_record_fcf_index
, fcf_record
, fcf_index
);
15323 bf_set(lpfc_fcf_record_mac_addr_prov
, fcf_record
,
15324 LPFC_FCF_FPMA
| LPFC_FCF_SPMA
);
15325 /* Set the VLAN bit map */
15326 if (phba
->valid_vlan
) {
15327 fcf_record
->vlan_bitmap
[phba
->vlan_id
/ 8]
15328 = 1 << (phba
->vlan_id
% 8);
15333 * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
15334 * @phba: pointer to lpfc hba data structure.
15335 * @fcf_index: FCF table entry offset.
15337 * This routine is invoked to scan the entire FCF table by reading FCF
15338 * record and processing it one at a time starting from the @fcf_index
15339 * for initial FCF discovery or fast FCF failover rediscovery.
15341 * Return 0 if the mailbox command is submitted successfully, none 0
15345 lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15348 LPFC_MBOXQ_t
*mboxq
;
15350 phba
->fcoe_eventtag_at_fcf_scan
= phba
->fcoe_eventtag
;
15351 phba
->fcoe_cvl_eventtag_attn
= phba
->fcoe_cvl_eventtag
;
15352 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15354 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15355 "2000 Failed to allocate mbox for "
15358 goto fail_fcf_scan
;
15360 /* Construct the read FCF record mailbox command */
15361 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15364 goto fail_fcf_scan
;
15366 /* Issue the mailbox command asynchronously */
15367 mboxq
->vport
= phba
->pport
;
15368 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_scan_read_fcf_rec
;
15370 spin_lock_irq(&phba
->hbalock
);
15371 phba
->hba_flag
|= FCF_TS_INPROG
;
15372 spin_unlock_irq(&phba
->hbalock
);
15374 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15375 if (rc
== MBX_NOT_FINISHED
)
15378 /* Reset eligible FCF count for new scan */
15379 if (fcf_index
== LPFC_FCOE_FCF_GET_FIRST
)
15380 phba
->fcf
.eligible_fcf_cnt
= 0;
15386 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15387 /* FCF scan failed, clear FCF_TS_INPROG flag */
15388 spin_lock_irq(&phba
->hbalock
);
15389 phba
->hba_flag
&= ~FCF_TS_INPROG
;
15390 spin_unlock_irq(&phba
->hbalock
);
15396 * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
15397 * @phba: pointer to lpfc hba data structure.
15398 * @fcf_index: FCF table entry offset.
15400 * This routine is invoked to read an FCF record indicated by @fcf_index
15401 * and to use it for FLOGI roundrobin FCF failover.
15403 * Return 0 if the mailbox command is submitted successfully, none 0
15407 lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15410 LPFC_MBOXQ_t
*mboxq
;
15412 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15414 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15415 "2763 Failed to allocate mbox for "
15418 goto fail_fcf_read
;
15420 /* Construct the read FCF record mailbox command */
15421 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15424 goto fail_fcf_read
;
15426 /* Issue the mailbox command asynchronously */
15427 mboxq
->vport
= phba
->pport
;
15428 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_fcf_rr_read_fcf_rec
;
15429 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15430 if (rc
== MBX_NOT_FINISHED
)
15436 if (error
&& mboxq
)
15437 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15442 * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
15443 * @phba: pointer to lpfc hba data structure.
15444 * @fcf_index: FCF table entry offset.
15446 * This routine is invoked to read an FCF record indicated by @fcf_index to
15447 * determine whether it's eligible for FLOGI roundrobin failover list.
15449 * Return 0 if the mailbox command is submitted successfully, none 0
15453 lpfc_sli4_read_fcf_rec(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15456 LPFC_MBOXQ_t
*mboxq
;
15458 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15460 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_INIT
,
15461 "2758 Failed to allocate mbox for "
15464 goto fail_fcf_read
;
15466 /* Construct the read FCF record mailbox command */
15467 rc
= lpfc_sli4_mbx_read_fcf_rec(phba
, mboxq
, fcf_index
);
15470 goto fail_fcf_read
;
15472 /* Issue the mailbox command asynchronously */
15473 mboxq
->vport
= phba
->pport
;
15474 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_read_fcf_rec
;
15475 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
15476 if (rc
== MBX_NOT_FINISHED
)
15482 if (error
&& mboxq
)
15483 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
15488 * lpfc_check_next_fcf_pri
15489 * phba pointer to the lpfc_hba struct for this port.
15490 * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
15491 * routine when the rr_bmask is empty. The FCF indecies are put into the
15492 * rr_bmask based on their priority level. Starting from the highest priority
15493 * to the lowest. The most likely FCF candidate will be in the highest
15494 * priority group. When this routine is called it searches the fcf_pri list for
15495 * next lowest priority group and repopulates the rr_bmask with only those
15498 * 1=success 0=failure
15501 lpfc_check_next_fcf_pri_level(struct lpfc_hba
*phba
)
15503 uint16_t next_fcf_pri
;
15504 uint16_t last_index
;
15505 struct lpfc_fcf_pri
*fcf_pri
;
15509 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
15510 LPFC_SLI4_FCF_TBL_INDX_MAX
);
15511 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15512 "3060 Last IDX %d\n", last_index
);
15514 /* Verify the priority list has 2 or more entries */
15515 spin_lock_irq(&phba
->hbalock
);
15516 if (list_empty(&phba
->fcf
.fcf_pri_list
) ||
15517 list_is_singular(&phba
->fcf
.fcf_pri_list
)) {
15518 spin_unlock_irq(&phba
->hbalock
);
15519 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15520 "3061 Last IDX %d\n", last_index
);
15521 return 0; /* Empty rr list */
15523 spin_unlock_irq(&phba
->hbalock
);
15527 * Clear the rr_bmask and set all of the bits that are at this
15530 memset(phba
->fcf
.fcf_rr_bmask
, 0,
15531 sizeof(*phba
->fcf
.fcf_rr_bmask
));
15532 spin_lock_irq(&phba
->hbalock
);
15533 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15534 if (fcf_pri
->fcf_rec
.flag
& LPFC_FCF_FLOGI_FAILED
)
15537 * the 1st priority that has not FLOGI failed
15538 * will be the highest.
15541 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15542 spin_unlock_irq(&phba
->hbalock
);
15543 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15544 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15545 fcf_pri
->fcf_rec
.fcf_index
);
15549 spin_lock_irq(&phba
->hbalock
);
15552 * if next_fcf_pri was not set above and the list is not empty then
15553 * we have failed flogis on all of them. So reset flogi failed
15554 * and start at the beginning.
15556 if (!next_fcf_pri
&& !list_empty(&phba
->fcf
.fcf_pri_list
)) {
15557 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15558 fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_FLOGI_FAILED
;
15560 * the 1st priority that has not FLOGI failed
15561 * will be the highest.
15564 next_fcf_pri
= fcf_pri
->fcf_rec
.priority
;
15565 spin_unlock_irq(&phba
->hbalock
);
15566 if (fcf_pri
->fcf_rec
.priority
== next_fcf_pri
) {
15567 rc
= lpfc_sli4_fcf_rr_index_set(phba
,
15568 fcf_pri
->fcf_rec
.fcf_index
);
15572 spin_lock_irq(&phba
->hbalock
);
15576 spin_unlock_irq(&phba
->hbalock
);
15581 * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
15582 * @phba: pointer to lpfc hba data structure.
15584 * This routine is to get the next eligible FCF record index in a round
15585 * robin fashion. If the next eligible FCF record index equals to the
15586 * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
15587 * shall be returned, otherwise, the next eligible FCF record's index
15588 * shall be returned.
15591 lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba
*phba
)
15593 uint16_t next_fcf_index
;
15596 /* Search start from next bit of currently registered FCF index */
15597 next_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
15600 /* Determine the next fcf index to check */
15601 next_fcf_index
= (next_fcf_index
+ 1) % LPFC_SLI4_FCF_TBL_INDX_MAX
;
15602 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15603 LPFC_SLI4_FCF_TBL_INDX_MAX
,
15606 /* Wrap around condition on phba->fcf.fcf_rr_bmask */
15607 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15609 * If we have wrapped then we need to clear the bits that
15610 * have been tested so that we can detect when we should
15611 * change the priority level.
15613 next_fcf_index
= find_next_bit(phba
->fcf
.fcf_rr_bmask
,
15614 LPFC_SLI4_FCF_TBL_INDX_MAX
, 0);
15618 /* Check roundrobin failover list empty condition */
15619 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
||
15620 next_fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
15622 * If next fcf index is not found check if there are lower
15623 * Priority level fcf's in the fcf_priority list.
15624 * Set up the rr_bmask with all of the avaiable fcf bits
15625 * at that level and continue the selection process.
15627 if (lpfc_check_next_fcf_pri_level(phba
))
15628 goto initial_priority
;
15629 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15630 "2844 No roundrobin failover FCF available\n");
15631 if (next_fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
)
15632 return LPFC_FCOE_FCF_NEXT_NONE
;
15634 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
15635 "3063 Only FCF available idx %d, flag %x\n",
15637 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
);
15638 return next_fcf_index
;
15642 if (next_fcf_index
< LPFC_SLI4_FCF_TBL_INDX_MAX
&&
15643 phba
->fcf
.fcf_pri
[next_fcf_index
].fcf_rec
.flag
&
15644 LPFC_FCF_FLOGI_FAILED
)
15645 goto next_priority
;
15647 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15648 "2845 Get next roundrobin failover FCF (x%x)\n",
15651 return next_fcf_index
;
15655 * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
15656 * @phba: pointer to lpfc hba data structure.
15658 * This routine sets the FCF record index in to the eligible bmask for
15659 * roundrobin failover search. It checks to make sure that the index
15660 * does not go beyond the range of the driver allocated bmask dimension
15661 * before setting the bit.
15663 * Returns 0 if the index bit successfully set, otherwise, it returns
15667 lpfc_sli4_fcf_rr_index_set(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15669 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15670 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15671 "2610 FCF (x%x) reached driver's book "
15672 "keeping dimension:x%x\n",
15673 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15676 /* Set the eligible FCF record index bmask */
15677 set_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15679 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15680 "2790 Set FCF (x%x) to roundrobin FCF failover "
15681 "bmask\n", fcf_index
);
15687 * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
15688 * @phba: pointer to lpfc hba data structure.
15690 * This routine clears the FCF record index from the eligible bmask for
15691 * roundrobin failover search. It checks to make sure that the index
15692 * does not go beyond the range of the driver allocated bmask dimension
15693 * before clearing the bit.
15696 lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba
*phba
, uint16_t fcf_index
)
15698 struct lpfc_fcf_pri
*fcf_pri
;
15699 if (fcf_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
15700 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15701 "2762 FCF (x%x) reached driver's book "
15702 "keeping dimension:x%x\n",
15703 fcf_index
, LPFC_SLI4_FCF_TBL_INDX_MAX
);
15706 /* Clear the eligible FCF record index bmask */
15707 spin_lock_irq(&phba
->hbalock
);
15708 list_for_each_entry(fcf_pri
, &phba
->fcf
.fcf_pri_list
, list
) {
15709 if (fcf_pri
->fcf_rec
.fcf_index
== fcf_index
) {
15710 list_del_init(&fcf_pri
->list
);
15714 spin_unlock_irq(&phba
->hbalock
);
15715 clear_bit(fcf_index
, phba
->fcf
.fcf_rr_bmask
);
15717 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15718 "2791 Clear FCF (x%x) from roundrobin failover "
15719 "bmask\n", fcf_index
);
15723 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
15724 * @phba: pointer to lpfc hba data structure.
15726 * This routine is the completion routine for the rediscover FCF table mailbox
15727 * command. If the mailbox command returned failure, it will try to stop the
15728 * FCF rediscover wait timer.
15731 lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
15733 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15734 uint32_t shdr_status
, shdr_add_status
;
15736 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15738 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
15739 &redisc_fcf
->header
.cfg_shdr
.response
);
15740 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
15741 &redisc_fcf
->header
.cfg_shdr
.response
);
15742 if (shdr_status
|| shdr_add_status
) {
15743 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
15744 "2746 Requesting for FCF rediscovery failed "
15745 "status x%x add_status x%x\n",
15746 shdr_status
, shdr_add_status
);
15747 if (phba
->fcf
.fcf_flag
& FCF_ACVL_DISC
) {
15748 spin_lock_irq(&phba
->hbalock
);
15749 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
15750 spin_unlock_irq(&phba
->hbalock
);
15752 * CVL event triggered FCF rediscover request failed,
15753 * last resort to re-try current registered FCF entry.
15755 lpfc_retry_pport_discovery(phba
);
15757 spin_lock_irq(&phba
->hbalock
);
15758 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
15759 spin_unlock_irq(&phba
->hbalock
);
15761 * DEAD FCF event triggered FCF rediscover request
15762 * failed, last resort to fail over as a link down
15763 * to FCF registration.
15765 lpfc_sli4_fcf_dead_failthrough(phba
);
15768 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
15769 "2775 Start FCF rediscover quiescent timer\n");
15771 * Start FCF rediscovery wait timer for pending FCF
15772 * before rescan FCF record table.
15774 lpfc_fcf_redisc_wait_start_timer(phba
);
15777 mempool_free(mbox
, phba
->mbox_mem_pool
);
15781 * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
15782 * @phba: pointer to lpfc hba data structure.
15784 * This routine is invoked to request for rediscovery of the entire FCF table
15788 lpfc_sli4_redisc_fcf_table(struct lpfc_hba
*phba
)
15790 LPFC_MBOXQ_t
*mbox
;
15791 struct lpfc_mbx_redisc_fcf_tbl
*redisc_fcf
;
15794 /* Cancel retry delay timers to all vports before FCF rediscover */
15795 lpfc_cancel_all_vport_retry_delay_timer(phba
);
15797 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15799 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
15800 "2745 Failed to allocate mbox for "
15801 "requesting FCF rediscover.\n");
15805 length
= (sizeof(struct lpfc_mbx_redisc_fcf_tbl
) -
15806 sizeof(struct lpfc_sli4_cfg_mhdr
));
15807 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_FCOE
,
15808 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF
,
15809 length
, LPFC_SLI4_MBX_EMBED
);
15811 redisc_fcf
= &mbox
->u
.mqe
.un
.redisc_fcf_tbl
;
15812 /* Set count to 0 for invalidating the entire FCF database */
15813 bf_set(lpfc_mbx_redisc_fcf_count
, redisc_fcf
, 0);
15815 /* Issue the mailbox command asynchronously */
15816 mbox
->vport
= phba
->pport
;
15817 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_redisc_fcf_table
;
15818 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
15820 if (rc
== MBX_NOT_FINISHED
) {
15821 mempool_free(mbox
, phba
->mbox_mem_pool
);
15828 * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
15829 * @phba: pointer to lpfc hba data structure.
15831 * This function is the failover routine as a last resort to the FCF DEAD
15832 * event when driver failed to perform fast FCF failover.
15835 lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba
*phba
)
15837 uint32_t link_state
;
15840 * Last resort as FCF DEAD event failover will treat this as
15841 * a link down, but save the link state because we don't want
15842 * it to be changed to Link Down unless it is already down.
15844 link_state
= phba
->link_state
;
15845 lpfc_linkdown(phba
);
15846 phba
->link_state
= link_state
;
15848 /* Unregister FCF if no devices connected to it */
15849 lpfc_unregister_unused_fcf(phba
);
15853 * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
15854 * @phba: pointer to lpfc hba data structure.
15855 * @rgn23_data: pointer to configure region 23 data.
15857 * This function gets SLI3 port configure region 23 data through memory dump
15858 * mailbox command. When it successfully retrieves data, the size of the data
15859 * will be returned, otherwise, 0 will be returned.
15862 lpfc_sli_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15864 LPFC_MBOXQ_t
*pmb
= NULL
;
15866 uint32_t offset
= 0;
15872 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15874 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15875 "2600 failed to allocate mailbox memory\n");
15881 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_23
);
15882 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
15884 if (rc
!= MBX_SUCCESS
) {
15885 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
15886 "2601 failed to read config "
15887 "region 23, rc 0x%x Status 0x%x\n",
15888 rc
, mb
->mbxStatus
);
15889 mb
->un
.varDmp
.word_cnt
= 0;
15892 * dump mem may return a zero when finished or we got a
15893 * mailbox error, either way we are done.
15895 if (mb
->un
.varDmp
.word_cnt
== 0)
15897 if (mb
->un
.varDmp
.word_cnt
> DMP_RGN23_SIZE
- offset
)
15898 mb
->un
.varDmp
.word_cnt
= DMP_RGN23_SIZE
- offset
;
15900 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
15901 rgn23_data
+ offset
,
15902 mb
->un
.varDmp
.word_cnt
);
15903 offset
+= mb
->un
.varDmp
.word_cnt
;
15904 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_RGN23_SIZE
);
15906 mempool_free(pmb
, phba
->mbox_mem_pool
);
15911 * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
15912 * @phba: pointer to lpfc hba data structure.
15913 * @rgn23_data: pointer to configure region 23 data.
15915 * This function gets SLI4 port configure region 23 data through memory dump
15916 * mailbox command. When it successfully retrieves data, the size of the data
15917 * will be returned, otherwise, 0 will be returned.
15920 lpfc_sli4_get_config_region23(struct lpfc_hba
*phba
, char *rgn23_data
)
15922 LPFC_MBOXQ_t
*mboxq
= NULL
;
15923 struct lpfc_dmabuf
*mp
= NULL
;
15924 struct lpfc_mqe
*mqe
;
15925 uint32_t data_length
= 0;
15931 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
15933 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15934 "3105 failed to allocate mailbox memory\n");
15938 if (lpfc_sli4_dump_cfg_rg23(phba
, mboxq
))
15940 mqe
= &mboxq
->u
.mqe
;
15941 mp
= (struct lpfc_dmabuf
*) mboxq
->context1
;
15942 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
15945 data_length
= mqe
->un
.mb_words
[5];
15946 if (data_length
== 0)
15948 if (data_length
> DMP_RGN23_SIZE
) {
15952 lpfc_sli_pcimem_bcopy((char *)mp
->virt
, rgn23_data
, data_length
);
15954 mempool_free(mboxq
, phba
->mbox_mem_pool
);
15956 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
15959 return data_length
;
15963 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
15964 * @phba: pointer to lpfc hba data structure.
15966 * This function read region 23 and parse TLV for port status to
15967 * decide if the user disaled the port. If the TLV indicates the
15968 * port is disabled, the hba_flag is set accordingly.
15971 lpfc_sli_read_link_ste(struct lpfc_hba
*phba
)
15973 uint8_t *rgn23_data
= NULL
;
15974 uint32_t if_type
, data_size
, sub_tlv_len
, tlv_offset
;
15975 uint32_t offset
= 0;
15977 /* Get adapter Region 23 data */
15978 rgn23_data
= kzalloc(DMP_RGN23_SIZE
, GFP_KERNEL
);
15982 if (phba
->sli_rev
< LPFC_SLI_REV4
)
15983 data_size
= lpfc_sli_get_config_region23(phba
, rgn23_data
);
15985 if_type
= bf_get(lpfc_sli_intf_if_type
,
15986 &phba
->sli4_hba
.sli_intf
);
15987 if (if_type
== LPFC_SLI_INTF_IF_TYPE_0
)
15989 data_size
= lpfc_sli4_get_config_region23(phba
, rgn23_data
);
15995 /* Check the region signature first */
15996 if (memcmp(&rgn23_data
[offset
], LPFC_REGION23_SIGNATURE
, 4)) {
15997 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
15998 "2619 Config region 23 has bad signature\n");
16003 /* Check the data structure version */
16004 if (rgn23_data
[offset
] != LPFC_REGION23_VERSION
) {
16005 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16006 "2620 Config region 23 has bad version\n");
16011 /* Parse TLV entries in the region */
16012 while (offset
< data_size
) {
16013 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
)
16016 * If the TLV is not driver specific TLV or driver id is
16017 * not linux driver id, skip the record.
16019 if ((rgn23_data
[offset
] != DRIVER_SPECIFIC_TYPE
) ||
16020 (rgn23_data
[offset
+ 2] != LINUX_DRIVER_ID
) ||
16021 (rgn23_data
[offset
+ 3] != 0)) {
16022 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16026 /* Driver found a driver specific TLV in the config region */
16027 sub_tlv_len
= rgn23_data
[offset
+ 1] * 4;
16032 * Search for configured port state sub-TLV.
16034 while ((offset
< data_size
) &&
16035 (tlv_offset
< sub_tlv_len
)) {
16036 if (rgn23_data
[offset
] == LPFC_REGION23_LAST_REC
) {
16041 if (rgn23_data
[offset
] != PORT_STE_TYPE
) {
16042 offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16043 tlv_offset
+= rgn23_data
[offset
+ 1] * 4 + 4;
16047 /* This HBA contains PORT_STE configured */
16048 if (!rgn23_data
[offset
+ 2])
16049 phba
->hba_flag
|= LINK_DISABLED
;
16061 * lpfc_wr_object - write an object to the firmware
16062 * @phba: HBA structure that indicates port to create a queue on.
16063 * @dmabuf_list: list of dmabufs to write to the port.
16064 * @size: the total byte value of the objects to write to the port.
16065 * @offset: the current offset to be used to start the transfer.
16067 * This routine will create a wr_object mailbox command to send to the port.
16068 * the mailbox command will be constructed using the dma buffers described in
16069 * @dmabuf_list to create a list of BDEs. This routine will fill in as many
16070 * BDEs that the imbedded mailbox can support. The @offset variable will be
16071 * used to indicate the starting offset of the transfer and will also return
16072 * the offset after the write object mailbox has completed. @size is used to
16073 * determine the end of the object and whether the eof bit should be set.
16075 * Return 0 is successful and offset will contain the the new offset to use
16076 * for the next write.
16077 * Return negative value for error cases.
16080 lpfc_wr_object(struct lpfc_hba
*phba
, struct list_head
*dmabuf_list
,
16081 uint32_t size
, uint32_t *offset
)
16083 struct lpfc_mbx_wr_object
*wr_object
;
16084 LPFC_MBOXQ_t
*mbox
;
16086 uint32_t shdr_status
, shdr_add_status
;
16088 union lpfc_sli4_cfg_shdr
*shdr
;
16089 struct lpfc_dmabuf
*dmabuf
;
16090 uint32_t written
= 0;
16092 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
16096 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
16097 LPFC_MBOX_OPCODE_WRITE_OBJECT
,
16098 sizeof(struct lpfc_mbx_wr_object
) -
16099 sizeof(struct lpfc_sli4_cfg_mhdr
), LPFC_SLI4_MBX_EMBED
);
16101 wr_object
= (struct lpfc_mbx_wr_object
*)&mbox
->u
.mqe
.un
.wr_object
;
16102 wr_object
->u
.request
.write_offset
= *offset
;
16103 sprintf((uint8_t *)wr_object
->u
.request
.object_name
, "/");
16104 wr_object
->u
.request
.object_name
[0] =
16105 cpu_to_le32(wr_object
->u
.request
.object_name
[0]);
16106 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 0);
16107 list_for_each_entry(dmabuf
, dmabuf_list
, list
) {
16108 if (i
>= LPFC_MBX_WR_CONFIG_MAX_BDE
|| written
>= size
)
16110 wr_object
->u
.request
.bde
[i
].addrLow
= putPaddrLow(dmabuf
->phys
);
16111 wr_object
->u
.request
.bde
[i
].addrHigh
=
16112 putPaddrHigh(dmabuf
->phys
);
16113 if (written
+ SLI4_PAGE_SIZE
>= size
) {
16114 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
16116 written
+= (size
- written
);
16117 bf_set(lpfc_wr_object_eof
, &wr_object
->u
.request
, 1);
16119 wr_object
->u
.request
.bde
[i
].tus
.f
.bdeSize
=
16121 written
+= SLI4_PAGE_SIZE
;
16125 wr_object
->u
.request
.bde_count
= i
;
16126 bf_set(lpfc_wr_object_write_length
, &wr_object
->u
.request
, written
);
16127 if (!phba
->sli4_hba
.intr_enable
)
16128 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
16130 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mbox
);
16131 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
16133 /* The IOCTL status is embedded in the mailbox subheader. */
16134 shdr
= (union lpfc_sli4_cfg_shdr
*) &wr_object
->header
.cfg_shdr
;
16135 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
16136 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
16137 if (rc
!= MBX_TIMEOUT
)
16138 mempool_free(mbox
, phba
->mbox_mem_pool
);
16139 if (shdr_status
|| shdr_add_status
|| rc
) {
16140 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
16141 "3025 Write Object mailbox failed with "
16142 "status x%x add_status x%x, mbx status x%x\n",
16143 shdr_status
, shdr_add_status
, rc
);
16146 *offset
+= wr_object
->u
.response
.actual_write_length
;
16151 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
16152 * @vport: pointer to vport data structure.
16154 * This function iterate through the mailboxq and clean up all REG_LOGIN
16155 * and REG_VPI mailbox commands associated with the vport. This function
16156 * is called when driver want to restart discovery of the vport due to
16157 * a Clear Virtual Link event.
16160 lpfc_cleanup_pending_mbox(struct lpfc_vport
*vport
)
16162 struct lpfc_hba
*phba
= vport
->phba
;
16163 LPFC_MBOXQ_t
*mb
, *nextmb
;
16164 struct lpfc_dmabuf
*mp
;
16165 struct lpfc_nodelist
*ndlp
;
16166 struct lpfc_nodelist
*act_mbx_ndlp
= NULL
;
16167 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
16168 LIST_HEAD(mbox_cmd_list
);
16169 uint8_t restart_loop
;
16171 /* Clean up internally queued mailbox commands with the vport */
16172 spin_lock_irq(&phba
->hbalock
);
16173 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
16174 if (mb
->vport
!= vport
)
16177 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
16178 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
16181 list_del(&mb
->list
);
16182 list_add_tail(&mb
->list
, &mbox_cmd_list
);
16184 /* Clean up active mailbox command with the vport */
16185 mb
= phba
->sli
.mbox_active
;
16186 if (mb
&& (mb
->vport
== vport
)) {
16187 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) ||
16188 (mb
->u
.mb
.mbxCommand
== MBX_REG_VPI
))
16189 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16190 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
16191 act_mbx_ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
16192 /* Put reference count for delayed processing */
16193 act_mbx_ndlp
= lpfc_nlp_get(act_mbx_ndlp
);
16194 /* Unregister the RPI when mailbox complete */
16195 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
16198 /* Cleanup any mailbox completions which are not yet processed */
16201 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
16203 * If this mailox is already processed or it is
16204 * for another vport ignore it.
16206 if ((mb
->vport
!= vport
) ||
16207 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
))
16210 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) &&
16211 (mb
->u
.mb
.mbxCommand
!= MBX_REG_VPI
))
16214 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
16215 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
16216 ndlp
= (struct lpfc_nodelist
*)mb
->context2
;
16217 /* Unregister the RPI when mailbox complete */
16218 mb
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
16220 spin_unlock_irq(&phba
->hbalock
);
16221 spin_lock(shost
->host_lock
);
16222 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
16223 spin_unlock(shost
->host_lock
);
16224 spin_lock_irq(&phba
->hbalock
);
16228 } while (restart_loop
);
16230 spin_unlock_irq(&phba
->hbalock
);
16232 /* Release the cleaned-up mailbox commands */
16233 while (!list_empty(&mbox_cmd_list
)) {
16234 list_remove_head(&mbox_cmd_list
, mb
, LPFC_MBOXQ_t
, list
);
16235 if (mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) {
16236 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
16238 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
16241 ndlp
= (struct lpfc_nodelist
*) mb
->context2
;
16242 mb
->context2
= NULL
;
16244 spin_lock(shost
->host_lock
);
16245 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
16246 spin_unlock(shost
->host_lock
);
16247 lpfc_nlp_put(ndlp
);
16250 mempool_free(mb
, phba
->mbox_mem_pool
);
16253 /* Release the ndlp with the cleaned-up active mailbox command */
16254 if (act_mbx_ndlp
) {
16255 spin_lock(shost
->host_lock
);
16256 act_mbx_ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
16257 spin_unlock(shost
->host_lock
);
16258 lpfc_nlp_put(act_mbx_ndlp
);
16263 * lpfc_drain_txq - Drain the txq
16264 * @phba: Pointer to HBA context object.
16266 * This function attempt to submit IOCBs on the txq
16267 * to the adapter. For SLI4 adapters, the txq contains
16268 * ELS IOCBs that have been deferred because the there
16269 * are no SGLs. This congestion can occur with large
16270 * vport counts during node discovery.
16274 lpfc_drain_txq(struct lpfc_hba
*phba
)
16276 LIST_HEAD(completions
);
16277 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
16278 struct lpfc_iocbq
*piocbq
= 0;
16279 unsigned long iflags
= 0;
16280 char *fail_msg
= NULL
;
16281 struct lpfc_sglq
*sglq
;
16282 union lpfc_wqe wqe
;
16285 spin_lock_irqsave(&phba
->hbalock
, iflags
);
16286 list_for_each_entry(piocbq
, &pring
->txq
, list
) {
16290 if (txq_cnt
> pring
->txq_max
)
16291 pring
->txq_max
= txq_cnt
;
16293 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16295 while (!list_empty(&pring
->txq
)) {
16296 spin_lock_irqsave(&phba
->hbalock
, iflags
);
16298 piocbq
= lpfc_sli_ringtx_get(phba
, pring
);
16300 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16301 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16302 "2823 txq empty and txq_cnt is %d\n ",
16306 sglq
= __lpfc_sli_get_sglq(phba
, piocbq
);
16308 __lpfc_sli_ringtx_put(phba
, pring
, piocbq
);
16309 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16314 /* The xri and iocb resources secured,
16315 * attempt to issue request
16317 piocbq
->sli4_lxritag
= sglq
->sli4_lxritag
;
16318 piocbq
->sli4_xritag
= sglq
->sli4_xritag
;
16319 if (NO_XRI
== lpfc_sli4_bpl2sgl(phba
, piocbq
, sglq
))
16320 fail_msg
= "to convert bpl to sgl";
16321 else if (lpfc_sli4_iocb2wqe(phba
, piocbq
, &wqe
))
16322 fail_msg
= "to convert iocb to wqe";
16323 else if (lpfc_sli4_wq_put(phba
->sli4_hba
.els_wq
, &wqe
))
16324 fail_msg
= " - Wq is full";
16326 lpfc_sli_ringtxcmpl_put(phba
, pring
, piocbq
);
16329 /* Failed means we can't issue and need to cancel */
16330 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
16331 "2822 IOCB failed %s iotag 0x%x "
16334 piocbq
->iotag
, piocbq
->sli4_xritag
);
16335 list_add_tail(&piocbq
->list
, &completions
);
16337 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
16340 /* Cancel all the IOCBs that cannot be issued */
16341 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
16342 IOERR_SLI_ABORTED
);